{
  "version": 3,
  "sources": ["../../../../../node_modules/eventemitter3/index.mjs", "../../src/utils/performanceTracker.ts", "../../src/document/models/CanvasTree/traits/utils/checkTreeForCycles.ts", "../../src/document/serialization/validate-document.ts", "../../src/document/models/CanvasTree/TreeRepair.ts"],
  "sourcesContent": ["import EventEmitter from './index.js'\n\nexport { EventEmitter }\nexport default EventEmitter\n", "import { environment } from \"environment/index.ts\"\nimport { EventEmitter } from \"eventemitter3\"\nimport { performanceMark } from \"./userTiming.ts\"\n\ndeclare global {\n\tinterface Window {\n\t\t\"__perf-start-time\"?: number\n\t}\n}\n\nfunction getStartTimeFromWindow() {\n\tif (typeof window === \"undefined\" || !window[\"__perf-start-time\"]) return performance.now()\n\n\treturn window[\"__perf-start-time\"]\n}\n\nexport const loadingStartTime = getStartTimeFromWindow()\nconst getDuration = () => performance.now() - loadingStartTime\n\n// when adding new mark, consider updating `document_global_loader_done`\n// in events/src/types.ts and LoadingIndicator code that records the event\nexport type Mark =\n\t| \"init\"\n\t// -- data --\n\t| \"dataLoad\"\n\t| \"documentBytesReady\"\n\t| \"buildStore\"\n\t| \"addedRows\"\n\t| \"wsConnection\"\n\t| \"wsTreeInitMessages\"\n\t// -- parsing --\n\t| \"parsingInit\"\n\t| \"parsingRootNode\"\n\t| \"parsingReplicasExpansion\"\n\t| \"parsingFirstPage\"\n\t| \"parsingResume\"\n\t// -- sandbox --\n\t| \"sandboxLoad\"\n\t| \"sandboxReady\"\n\t| \"sandboxServicesReady\"\n\t| \"sandboxCanvasFirstRender\"\n\t| \"sandboxFramerDefaultModulesLoad\"\n\t| \"sandboxFirstModulesLoad\"\n\t// -- loading --\n\t| \"modulesStorageStart\"\n\t| \"modulesStorageInit\"\n\t| \"modulesStorageFirstPublish\"\n\t| \"fontsLoad\"\n\t| \"modulesLoad\"\n\t// -- between Canvas First Render and UI Shown --\n\t| \"sandboxModulesListReceived\"\n\t| \"sandboxFirstBatchEvaluated\"\n\t| \"sandboxEvaluateModulesEnd\"\n\t| \"sandboxExternalModulesIdle\"\n\t| \"sandboxRenderingPhaseNormal\"\n\t| \"sandboxTrackerIdle\"\n\t| \"sandboxScopeLoadingDebounceEnter\"\n\t| \"editorIsLoadingModulesIdle\"\n\t// final state we send all marks when UI was shown\n\t| \"showUI\"\n\n// Human readable labels for UI\nexport const MARK_LABELS = {\n\tinit: \"Init\",\n\tdataLoad: \"Data Load\",\n\tdocumentBytesReady: \"Document Bytes Ready\",\n\tbuildStore: \"Build Store\",\n\taddedRows: \"Added Rows\",\n\twsConnection: \"WS Connection\",\n\twsTreeInitMessages: \"WS Tree Init\",\n\tparsingInit: \"Parsing Init\",\n\tparsingRootNode: \"Parsing Root Node\",\n\tparsingReplicasExpansion: \"Parsing Replicas\",\n\tparsingFirstPage: \"Parsing First Page\",\n\tparsingResume: \"Parsing Resume\",\n\tsandboxLoad: \"Canvas Sandbox\",\n\tsandboxReady: \"Canvas Resources\",\n\tsandboxServicesReady: \"Sandbox Services\",\n\tsandboxCanvasFirstRender: \"Canvas First Render\",\n\tsandboxFramerDefaultModulesLoad: \"Framer Default Modules\",\n\tsandboxFirstModulesLoad: \"First Modules Load\",\n\tfontsLoad: \"Web Fonts\",\n\tmodulesLoad: \"Modules\",\n\tmodulesStorageStart: \"Modules Storage Start\",\n\tmodulesStorageInit: \"Modules Storage Init\",\n\tmodulesStorageFirstPublish: \"Modules Storage First Publish\",\n\tsandboxModulesListReceived: \"Sandbox Modules List Received\",\n\tsandboxFirstBatchEvaluated: \"Sandbox First Batch Evaluated\",\n\tsandboxEvaluateModulesEnd: \"Sandbox Evaluate Modules End\",\n\tsandboxExternalModulesIdle: \"Sandbox External Modules Idle\",\n\tsandboxRenderingPhaseNormal: \"Sandbox Rendering Phase Normal\",\n\tsandboxTrackerIdle: \"Sandbox Tracker Idle\",\n\tsandboxScopeLoadingDebounceEnter: \"Sandbox Scope Loading Debounce Enter\",\n\teditorIsLoadingModulesIdle: \"Editor isLoadingModules = false\",\n\tshowUI: \"UI Shown\",\n} satisfies Record<Mark, string>\n\nexport type LoadingSource = \"prefetch-sync\" | \"prefetch-tree\" | \"sync\" | \"tree-download\" | \"loaded-data\"\n\nexport interface LoadingInfo {\n\tformat: \"crdt\" | \"json\"\n\tstrategy: \"incremental\" | \"snapshot\" | \"up-to-date\" | \"full-load\"\n\tsources: LoadingSource[]\n\tsnapshotBytes: number\n\tsnapshotSource: \"cached\" | \"downloaded\"\n\tcacheBackend?: string\n\tcachedRows: number\n\tcachedRowBytes: number\n\tdownloadedRows: number\n\tdownloadedRowBytes: number\n}\n\n/** Initial module work observed inside the canvas sandbox runtime before module loading became idle. */\nexport interface InitialModuleLoadStats {\n\tlocalEvaluatedModulesCount: number\n\texternalEvaluatedModulesCount: number\n\tmoduleNetworkRequestCount: number\n\tmoduleNetworkBytes: number\n\t/** Resources downloaded during the initial-module window that the loader did not register (images, fonts, fetches from app code, etc.). */\n\tnonModuleNetworkRequestCount: number\n\tnonModuleNetworkBytes: number\n}\n\ninterface Events {\n\t\"performance:mark\": <K extends Mark>(mark: K, value: number) => void\n\t\"performance:dynamicMark\": (mark: DynamicMark) => void\n\t\"loading:info\": (info: LoadingInfo) => void\n\t\"ws:init\": (count: number) => void\n}\n\ntype Marks = {\n\t[K in Mark]?: number\n}\n\n/** Marks not part of the {@link Mark} union \u2014 used for unbounded sequences (e.g. one per batch).\n * Only surfaced in the in-UI debug loader, never reported in telemetry. */\nexport interface DynamicMark {\n\tname: string\n\tlabel: string\n\tvalue: number\n}\n\nclass MarksStore {\n\tmarks: Marks = {}\n\tdynamicMarks: DynamicMark[] = []\n\tisComplete: boolean = false\n\n\thandlePerformanceMark(mark: Mark, value: number) {\n\t\tif (mark in this.marks) {\n\t\t\tif (environment.isDebugBuild) {\n\t\t\t\t// biome-ignore lint/suspicious/noConsole: <explanation>\n\t\t\t\tconsole.warn(\"Performance mark already exists\", mark)\n\t\t\t}\n\n\t\t\treturn\n\t\t}\n\n\t\tthis.marks[mark] = value\n\n\t\tif (mark === \"showUI\") {\n\t\t\tthis.isComplete = true\n\t\t}\n\t}\n\n\thandleDynamicMark(mark: DynamicMark) {\n\t\tthis.dynamicMarks.push(mark)\n\t}\n}\n\nclass PerformanceEmitter extends EventEmitter<Events> {\n\tprivate marksStore = new MarksStore()\n\tprivate loadingInfoValue: LoadingInfo | undefined\n\n\tconstructor() {\n\t\tsuper()\n\t\tthis.on(\"performance:mark\", this.marksStore.handlePerformanceMark.bind(this.marksStore))\n\t\tthis.on(\"performance:dynamicMark\", this.marksStore.handleDynamicMark.bind(this.marksStore))\n\t}\n\n\tcurrentMarks() {\n\t\treturn { ...this.marksStore.marks }\n\t}\n\n\tcurrentDynamicMarks(): DynamicMark[] {\n\t\treturn [...this.marksStore.dynamicMarks]\n\t}\n\n\tisComplete() {\n\t\treturn this.marksStore.isComplete\n\t}\n\n\tsetLoadingInfo(info: LoadingInfo) {\n\t\tthis.loadingInfoValue = info\n\t\tthis.emit(\"loading:info\", info)\n\t}\n\n\tgetLoadingInfo(): LoadingInfo | undefined {\n\t\treturn this.loadingInfoValue\n\t}\n\n\tprivate wsInitialUpdatesValue: number | undefined\n\n\tsetWsInitialUpdates(count: number) {\n\t\tthis.wsInitialUpdatesValue = count\n\t\tthis.emit(\"ws:init\", count)\n\t}\n\n\tprivate initialModuleLoadStatsValue: InitialModuleLoadStats | undefined\n\n\tsetInitialModuleLoadStats(stats: InitialModuleLoadStats) {\n\t\tthis.initialModuleLoadStatsValue = stats\n\t}\n\n\tgetInitialModuleLoadStats(): InitialModuleLoadStats | undefined {\n\t\treturn this.initialModuleLoadStatsValue\n\t}\n\n\tprivate ttfbValue: number | undefined\n\tprivate ttfbResolved = false\n\n\t/** TTFB from the Navigation Timing API (`responseStart - startTime`), computed once and cached. */\n\tgetTtfb(): number | undefined {\n\t\tif (this.ttfbResolved) return this.ttfbValue\n\t\tthis.ttfbResolved = true\n\t\tconst navigation = performance.getEntriesByType(\"navigation\")[0]\n\t\tif (navigation instanceof PerformanceNavigationTiming) {\n\t\t\tthis.ttfbValue = Math.round(navigation.responseStart - navigation.startTime)\n\t\t}\n\t\treturn this.ttfbValue\n\t}\n}\n\nconst isDisabled = environment.isTest || environment.isAutomation || environment.isE2E\nexport const perfEmitter: PerformanceEmitter | null = isDisabled ? null : new PerformanceEmitter()\n\nfunction checkForReadiness() {\n\tif (isDisabled) return false\n\tif (!perfEmitter && environment.isDebugBuild) {\n\t\t// biome-ignore lint/suspicious/noConsole: <explanation>\n\t\tconsole.error(\"PerformanceEmitter not initialized\")\n\t\treturn false\n\t}\n\treturn true\n}\n\n/**\n * Marks the loading-related performance by creating a performance mark.\n * This function records a performance mark based on the provided mark.\n *\n * @param {Mark} mark - The performance mark mark to record. It is expected to be of the generic type `Mark`.\n * @param {number} value - [only for special cases, like data preloading]\n * @return {void} No return value.\n */\nexport function markLoadingPerf<K extends Mark>(mark: K, value = getDuration()): void {\n\tif (!checkForReadiness()) return\n\n\t// Create a performance mark using the browser's Performance API\n\tperformanceMark(`framer-loading-${mark}`)\n\n\tperfEmitter?.emit(\"performance:mark\", mark, value)\n}\n\n/**\n * Records a dynamic (string-named) loading perf mark. Unlike {@link markLoadingPerf}, these are\n * not part of the {@link Mark} union, so callers can emit an unbounded number of them (e.g. one\n * per module-evaluation batch). They are surfaced in the in-UI debug loader timeline, but are\n * not reported in `document_global_loader_done` telemetry.\n */\nexport function markLoadingPerfDynamic(name: string, label: string, value = getDuration()): void {\n\tif (!checkForReadiness()) return\n\n\tperformanceMark(`framer-loading-dynamic-${name}`)\n\n\tperfEmitter?.emit(\"performance:dynamicMark\", { name, label, value })\n}\n\nexport function setLoadingInfo(info: LoadingInfo): void {\n\tif (!checkForReadiness()) return\n\tperfEmitter?.setLoadingInfo(info)\n}\n\nexport function setWsInitialUpdates(count: number): void {\n\tif (!checkForReadiness()) return\n\tperfEmitter?.setWsInitialUpdates(count)\n}\n\nexport function setInitialModuleLoadStats(stats: InitialModuleLoadStats): void {\n\tif (!checkForReadiness()) return\n\tperfEmitter?.setInitialModuleLoadStats(stats)\n}\n", "import type { SlotControlItem } from \"document/models/controlProps/ControlProp.ts\"\nimport { ControlType } from \"library/render/types/PropertyControls.ts\"\nimport { isArray, isObject, isString } from \"utils/typeChecks.ts\"\nimport type { CanvasTree } from \"../../CanvasTree.ts\"\nimport type { CanvasNode } from \"../../nodes/CanvasNode.ts\"\nimport { isCodeComponentNode } from \"../../nodes/utils/nodeCheck.ts\"\n\nexport type DetectedCycles = { id: string; stack: string[] }[]\nexport function checkTreeForCycles(tree: CanvasTree, cycles?: DetectedCycles): boolean {\n\tlet seenCycle = false\n\n\tfunction hasCycle(current: CanvasNode | null | undefined, stack: string[], set: Set<string>): void {\n\t\tif (!current) return\n\n\t\tconst id = current.id\n\t\tif (set.has(id)) {\n\t\t\tseenCycle = true\n\t\t\tif (cycles) {\n\t\t\t\tcycles.push({ id, stack: stack.slice() })\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\tset.add(id)\n\t\tstack.push(id)\n\n\t\tif (isCodeComponentNode(current)) {\n\t\t\tconst rawControlProps = current.getRawControlProps()\n\t\t\tconst controlPropKeys = Object.keys(rawControlProps)\n\n\t\t\tfor (const controlPropKey of controlPropKeys) {\n\t\t\t\tconst rawControlProp = rawControlProps[controlPropKey]\n\t\t\t\tif (!rawControlProp) continue\n\n\t\t\t\tif (rawControlProp.type === ControlType.Slot && isArray(rawControlProp.value)) {\n\t\t\t\t\tfor (const item of rawControlProp.value) {\n\t\t\t\t\t\tif (!isObject(item)) continue\n\n\t\t\t\t\t\tconst referenceKey: keyof SlotControlItem = \"reference\"\n\t\t\t\t\t\tconst reference = item[referenceKey]\n\t\t\t\t\t\tif (!isString(reference)) continue\n\n\t\t\t\t\t\tconst slot = tree.get(reference)\n\t\t\t\t\t\thasCycle(slot, stack, set)\n\t\t\t\t\t}\n\t\t\t\t} else if (rawControlProp.type === ControlType.ComponentInstance && isString(rawControlProp.value)) {\n\t\t\t\t\tconst slot = tree.get(rawControlProp.value)\n\t\t\t\t\thasCycle(slot, stack, set)\n\t\t\t\t} else if (isArray(rawControlProp.value)) {\n\t\t\t\t\tfor (const arrayValue of rawControlProp.value) {\n\t\t\t\t\t\tif (!isObject(arrayValue)) continue\n\t\t\t\t\t\tif (arrayValue.type !== ControlType.ComponentInstance) continue\n\n\t\t\t\t\t\tconst slotId = arrayValue.value\n\t\t\t\t\t\tif (!isString(slotId)) continue\n\n\t\t\t\t\t\tconst slot = tree.get(slotId)\n\t\t\t\t\t\thasCycle(slot, stack, set)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst children = current.children\n\t\tif (children) {\n\t\t\tfor (const child of children) {\n\t\t\t\thasCycle(child, stack, set)\n\t\t\t}\n\t\t}\n\n\t\tset.delete(id)\n\t\tstack.pop()\n\t}\n\n\tconst set = new Set<string>()\n\tconst stack: string[] = []\n\thasCycle(tree.root, stack, set)\n\treturn seenCycle\n}\n", "import { isTree } from \"@framerjs/document-migrations\"\nimport type { AnyTreeNode } from \"@framerjs/document-migrations/src/types/index.ts\"\nimport { CanvasTreeVersion } from \"document/models/CanvasTree/CanvasTreeVersion.ts\"\nimport { CanvasTree } from \"document/models/CanvasTree/index.ts\"\nimport { isNumber } from \"utils/typeChecks.ts\"\n\nclass VersionTooLowError extends Error {\n\tconstructor(actual: number, expected: number) {\n\t\tsuper(`Document version is too low. Expected ${expected}, got ${actual}.`)\n\t}\n}\n\nclass VersionTooHighError extends Error {\n\tconstructor(actual: number, expected: number) {\n\t\tsuper(`Document version is too high. Expected ${expected}, got ${actual}.`)\n\t}\n}\n\n/**\n * Validates the document for correctness before migrating to the latest version\n * If the document is not valid we throw an Error exception\n * @param json\n * @throws on errors that cannot be repaired\n */\nexport function validateDocumentStructure(json: unknown) {\n\tif (!isTree(json) || json === null) throw Error(\"Invalid document.\")\n\n\tif (!isNumber(json.version)) {\n\t\tthrow Error(\"Unable to read document.version\")\n\t}\n\n\tif (!json.root) {\n\t\tthrow Error(\"Unable to read document.root\")\n\t}\n\n\tif (json.version < CanvasTree.minimumLegacySerializationVersion) {\n\t\tthrow new VersionTooLowError(json.version, CanvasTree.minimumLegacySerializationVersion)\n\t}\n\n\tif (json.version > CanvasTreeVersion) {\n\t\tthrow new VersionTooHighError(json.version, CanvasTreeVersion)\n\t}\n}\n\ninterface AnyTree {\n\tversion: number\n\troot: AnyTreeNode\n}\n\nexport function isValidDocumentStructure(json: unknown): json is AnyTree {\n\tif (!isTree(json) || json === null) return false\n\tif (!isNumber(json.version)) return false\n\n\tif (!json.root) return false\n\tif (json.version < CanvasTree.minimumLegacySerializationVersion) return false\n\tif (json.version > CanvasTreeVersion) return false\n\n\treturn true\n}\n", "import { getFallbackPageId, migrateDocument } from \"@framerjs/document-migrations\"\nimport type { ComponentLoader } from \"@framerjs/framer-runtime\"\nimport { assert, isEmptyObject } from \"@framerjs/shared\"\nimport { CanvasTree } from \"document/models/CanvasTree/CanvasTree.ts\"\nimport type { CanvasNode, NodeID } from \"document/models/CanvasTree/index.ts\"\nimport { isScopeNode } from \"document/models/CanvasTree/index.ts\"\nimport type CodeComponentNode from \"document/models/CanvasTree/nodes/CodeComponentNode.ts\"\nimport type { MaybeNodeID } from \"document/models/CanvasTree/nodes/NodeID.ts\"\nimport { NullID, randomID } from \"document/models/CanvasTree/nodes/NodeID.ts\"\nimport { TemplateHelper } from \"document/models/CanvasTree/nodes/TemplateHelper.ts\"\nimport type { IsMaster, IsReplica } from \"document/models/CanvasTree/traits/WithTemplate.ts\"\nimport {\n\tisHiddenMaster,\n\tisMaster,\n\tisReplica,\n\tisReplicaChild,\n\twithTemplate,\n} from \"document/models/CanvasTree/traits/WithTemplate.ts\"\nimport { validateDocumentStructure } from \"document/serialization/validate-document.ts\"\nimport { ControlType } from \"library/render/types/PropertyControls.ts\"\nimport type { Mutable } from \"utils/Mutable.ts\"\nimport { isArray, isObject, isString } from \"utils/typeChecks.ts\"\nimport type { ArrayValue, ControlProps, SlotControlItem } from \"../controlProps/ControlProp.ts\"\nimport { isRawControlProp } from \"../controlProps/RawControlProp.ts\"\nimport { prefixControlProps } from \"../controlProps/controlPropKey.ts\"\nimport { CanvasPageNode } from \"./nodes/CanvasPageNode.ts\"\nimport { isLocalModulesListNode } from \"./nodes/LocalModuleNode.ts\"\nimport type { RootNode } from \"./nodes/RootNode.ts\"\nimport type { WebPageNode } from \"./nodes/WebPageNode.ts\"\nimport { BranchesNode } from \"./nodes/branches/BranchesNode.ts\"\nimport { canvasNodeFromValue } from \"./nodes/canvasNodeFromValue.ts\"\nimport {\n\tisBranchesNode,\n\tisBranchNode,\n\tisCanvasPageNode,\n\tisCodeComponentNode,\n\tisColorStyleTokenListNode,\n\tisEntityRootNode,\n\tisErrorListNode,\n\tisExternalModulesListNode,\n\tisPresetsListNode,\n\tisRouteSegmentRootNode,\n\tisRoutesNode,\n\tisWebPageNode,\n} from \"./nodes/utils/nodeCheck.ts\"\nimport type { DetectedCycles } from \"./traits/utils/checkTreeForCycles.ts\"\nimport { checkTreeForCycles } from \"./traits/utils/checkTreeForCycles.ts\"\n\ntype SimpleTree = Map<NodeID, CanvasNode>\n\n/**\n * Load a document from json resulting in a {@link CanvasTree}, will repair errors and collect them in the #errors array.\n *\n * @param json - object representing a vekter document\n * @param errors - by reference array that will be filled with repaired errors\n * @returns a CanvasTree\n * @throws on errors that cannot be repaired\n */\nexport function safeLoadDocument(json: unknown, componentLoader: ComponentLoader, errors: string[]): CanvasTree {\n\tvalidateDocumentStructure(json)\n\n\t// This throws if the document version is higher than the latest known version.\n\tconst documentJSON = migrateDocument(json)\n\tconst root = canvasNodeFromValue(documentJSON.root, null, {\n\t\textraChecksAndFixes: true,\n\t\terrors,\n\t\twarnings: errors, // Also let warnings be pushed into errors. To retain the original behavior.\n\t}) as RootNode | null\n\tif (!root) {\n\t\tthrow Error(\"Unable to create load document\")\n\t}\n\n\trepairCanvasPages(root, errors)\n\tconst tree: SimpleTree = new Map<NodeID, CanvasNode>()\n\tbuildSimpleTree(tree, errors, root, NullID)\n\trepairTree(tree, root, errors)\n\tlet canvasTree = CanvasTree.createByAdoptingRoot(root)\n\t// we explicitly verify the tree here, because production builds don't verify automatically\n\tcanvasTree.verify()\n\tcanvasTree = TemplateHelper.treeDidLoad(canvasTree, componentLoader, errors).didNonLinearMove(componentLoader)\n\n\t// after all replica's have been created, check again for cycles via replica's\n\tconst cycles: DetectedCycles = []\n\tif (checkTreeForCycles(canvasTree, cycles)) {\n\t\tcycles.forEach(cycle => {\n\t\t\terrors.push(`${cycle.id}: code component links itself via ${cycle.stack}`)\n\t\t\trepairCycleInNode(canvasTree, cycle.id, cycle.stack)\n\t\t})\n\t\tcanvasTree = canvasTree.commit(componentLoader)\n\t}\n\treturn canvasTree\n}\n\nexport function repairRootNode(root: RootNode, errors: string[]) {\n\trepairCanvasPages(root, errors)\n\tconst tree: SimpleTree = new Map<NodeID, CanvasNode>()\n\tbuildSimpleTree(tree, errors, root, NullID)\n\trepairTree(tree, root, errors)\n}\n\nexport function repairPage(pageNode: CanvasNode, errors: string[]) {\n\tconst tree: SimpleTree = new Map<NodeID, CanvasNode>()\n\tbuildSimpleTree(tree, errors, pageNode, pageNode.parentid)\n\t// When repairing a page, we cannot repair master or code links, as they might point outside of\n\t// the page. But we can repair inherits from or stray originalids.\n\trepairTreeInheritsFrom(tree, pageNode, errors)\n}\n\nfunction isCanvasPageOrWebPage(node: CanvasNode): node is CanvasPageNode | WebPageNode {\n\treturn isCanvasPageNode(node) || isWebPageNode(node)\n}\n\nfunction repairCanvasPages(root: RootNode, errors: string[] = []) {\n\tconst children = root.children\n\tlet firstPage = children.find(isCanvasPageOrWebPage)\n\n\tif (firstPage === undefined) {\n\t\terrors.push(`${root.id}: Root does not contain a page`)\n\n\t\tfirstPage = new CanvasPageNode({\n\t\t\tid: getFallbackPageId(root),\n\t\t})\n\n\t\tchildren.push(firstPage)\n\t}\n\n\tfor (let index = 0; index < children.length; index++) {\n\t\tconst node = children.at(index)\n\t\tif (!node) continue\n\n\t\tif (isScopeNode(node)) continue\n\t\tif (isHiddenMaster(node)) continue\n\t\tif (isExternalModulesListNode(node)) continue\n\t\tif (isLocalModulesListNode(node)) continue\n\t\tif (isPresetsListNode(node)) continue\n\t\tif (isRoutesNode(node)) continue\n\t\tif (isColorStyleTokenListNode(node)) continue\n\t\tif (isRouteSegmentRootNode(node)) continue\n\t\tif (isEntityRootNode(node)) continue\n\t\tif (isErrorListNode(node)) continue\n\t\tif (isBranchesNode(node)) continue\n\t\tif (isBranchNode(node)) {\n\t\t\terrors.push(`${node.id}: BranchNode is not under BranchesNode`)\n\t\t\tchildren.splice(index--, 1)\n\t\t\tlet branchesNode = root.children.find(isBranchesNode) // create if missing, like getFallbackPageId does for the page\n\t\t\tif (!branchesNode) {\n\t\t\t\tbranchesNode = new BranchesNode()\n\t\t\t\troot.children.push(branchesNode)\n\t\t\t}\n\t\t\tbranchesNode.children.push(node)\n\t\t\tnode.parentid = branchesNode.id\n\t\t\tcontinue\n\t\t}\n\n\t\terrors.push(`${node.id}: Ground node is not on a page`)\n\n\t\t// We need to decrease the index after splicing\n\t\tchildren.splice(index--, 1)\n\t\tfirstPage.children.push(node)\n\t\tnode.parentid = firstPage.id\n\t}\n}\n\nexport function repairCycleInNode(tree: CanvasTree, errorId: NodeID, stack: NodeID[]): void {\n\tconst node = tree.get(stack[stack.length - 1])\n\tif (!isCodeComponentNode(node)) return\n\n\tconst rawControlProps = node.getRawControlProps()\n\tconst update: Mutable<ControlProps> = {}\n\n\tfor (const key in rawControlProps) {\n\t\tconst rawControlProp = rawControlProps[key]\n\t\tif (!rawControlProp) continue\n\n\t\tconst { type, value } = rawControlProp\n\t\tif (type === ControlType.Slot && isArray(value)) {\n\t\t\tconst filteredItems = value.filter(item => {\n\t\t\t\tif (!isObject(item)) return true\n\t\t\t\tconst referenceKey: keyof SlotControlItem = \"reference\"\n\t\t\t\tconst reference = item[referenceKey]\n\t\t\t\treturn reference !== errorId\n\t\t\t})\n\t\t\tif (filteredItems.length !== value.length) {\n\t\t\t\tupdate[key] = {\n\t\t\t\t\ttype: ControlType.Slot,\n\t\t\t\t\tvalue: filteredItems as SlotControlItem[],\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (type === ControlType.ComponentInstance && value === errorId) {\n\t\t\tupdate[key] = {\n\t\t\t\ttype: ControlType.Slot,\n\t\t\t\tvalue: [],\n\t\t\t}\n\t\t} else if (isArray(value)) {\n\t\t\tconst newValue = value.filter(entry => {\n\t\t\t\tif (!isObject(entry)) return true\n\t\t\t\tif (entry.type !== ControlType.ComponentInstance) return true\n\t\t\t\treturn entry.value !== errorId\n\t\t\t})\n\t\t\tif (newValue.length !== value.length) {\n\t\t\t\tupdate[key] = {\n\t\t\t\t\ttype: ControlType.Array,\n\t\t\t\t\tvalue: newValue as ArrayValue[],\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (isEmptyObject(update)) return\n\n\tconst nodeUpdate = prefixControlProps(update)\n\tnode.set(nodeUpdate)\n}\n\n// fill the hashmap of the simple tree, at the same time, track and repair duplicate id's\nfunction buildSimpleTree(tree: SimpleTree, errors: string[], node: CanvasNode, parentid: MaybeNodeID) {\n\tnode.parentid = parentid\n\twhile (tree.has(node.id)) {\n\t\terrors.push(`${node.id}: duplicate id in document`)\n\t\t// @ts-expect-error ID is readonly property here\n\t\tnode.id = randomID()\n\t}\n\ttree.set(node.id, node)\n\n\tconst children = node.children\n\tif (!children) return\n\n\tfor (const child of children) {\n\t\tbuildSimpleTree(tree, errors, child, node.id)\n\t}\n}\n\nfunction repairTree(tree: SimpleTree, root: CanvasNode, errors: string[]) {\n\t// code component can not have children that ultimately routes back to itself\n\t// masters cannot have have their own replica as child\n\t//\n\t// To do this deterministically, we walk the tree, and per node, walk any side-links.\n\t// If side-links ultimately circle back, we break the circle at that last step.\n\tfor (const node of root.walk()) {\n\t\tassert(node.isMutable())\n\t\tif (isCodeComponentNode(node)) {\n\t\t\trepairComponentLinks(tree, node.id, new Set([node.id]), node, errors)\n\t\t}\n\t\tif (isMaster(node)) {\n\t\t\trepairMasterLinks(tree, node, node, errors)\n\t\t}\n\t\tif (isReplica(node)) {\n\t\t\trepairReplica(tree, node, errors)\n\t\t\trepairInheritsFrom(tree, node, errors)\n\t\t}\n\t\tif (isReplicaChild(node)) {\n\t\t\trepairReplicaChild(node, errors)\n\t\t}\n\t}\n}\n\nfunction repairTreeInheritsFrom(tree: SimpleTree, root: CanvasNode, errors: string[]): void {\n\tfor (const node of root.walk()) {\n\t\tassert(node.isMutable())\n\t\tif (isReplica(node)) {\n\t\t\trepairInheritsFrom(tree, node, errors)\n\t\t} else if (isReplicaChild(node)) {\n\t\t\trepairReplicaChild(node, errors)\n\t\t}\n\t}\n}\n\nfunction repairComponentLinks(\n\ttree: SimpleTree,\n\tstart: NodeID,\n\tseen: Set<NodeID>,\n\tat: CodeComponentNode,\n\terrors: string[],\n) {\n\tfunction isCircular(slotId: NodeID): boolean {\n\t\tif (!isString(slotId)) return false\n\n\t\tif (seen.has(slotId)) {\n\t\t\terrors.push(`${start}: code component links itself via ${at.id}`)\n\t\t\treturn true\n\t\t}\n\n\t\tconst link = tree.get(slotId)\n\t\tif (!link) {\n\t\t\terrors.push(`${at.id}: code component has bad link at ${slotId}`)\n\t\t\treturn true\n\t\t}\n\n\t\tlet foundError = false\n\t\tfor (const node of link.walk()) {\n\t\t\tif (seen.has(node.id)) {\n\t\t\t\terrors.push(`${start}: code component links itself via ${at.id} via ${slotId}`)\n\t\t\t\tfoundError = true\n\t\t\t} else if (isCodeComponentNode(node)) {\n\t\t\t\trepairComponentLinks(tree, start, new Set([...seen, node.id]), node, errors)\n\t\t\t}\n\t\t}\n\t\treturn foundError\n\t}\n\n\tconst rawControlProps = at.getRawControlProps()\n\tconst controlPropKeys = Object.keys(rawControlProps)\n\n\tfor (const key of controlPropKeys) {\n\t\tconst controlProp = rawControlProps[key]\n\t\tif (!isRawControlProp(controlProp)) continue\n\n\t\tif (controlProp.type === ControlType.Slot && isArray(controlProp.value)) {\n\t\t\tconst errorIndexes: number[] = []\n\n\t\t\tfor (let index = 0; index < controlProp.value.length; index++) {\n\t\t\t\tconst slotItem = controlProp.value[index]\n\t\t\t\tif (!isObject(slotItem)) continue\n\t\t\t\tconst referenceKey: keyof SlotControlItem = \"reference\"\n\t\t\t\tconst reference = slotItem[referenceKey]\n\t\t\t\tif (!isString(reference)) continue\n\t\t\t\tif (!isCircular(reference)) continue\n\t\t\t\terrorIndexes.push(index)\n\t\t\t}\n\n\t\t\t// remove error indexes from array\n\t\t\twhile (errorIndexes.length > 0) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: bounds already checked above\n\t\t\t\tcontrolProp.value.splice(errorIndexes.pop()!, 1)\n\t\t\t}\n\n\t\t\tcontinue\n\t\t}\n\n\t\tif (controlProp.type === ControlType.ComponentInstance && isString(controlProp.value)) {\n\t\t\tif (!isCircular(controlProp.value)) continue\n\t\t\tcontrolProp.value = undefined\n\t\t\tcontinue\n\t\t}\n\n\t\tconst array = controlProp.value\n\t\tif (!Array.isArray(array)) continue\n\n\t\tconst errorIndexes: number[] = []\n\n\t\tfor (let i = 0, il = array.length; i < il; i++) {\n\t\t\tconst arrayValue = array[i]\n\t\t\tif (!isRawControlProp(arrayValue)) continue\n\t\t\tif (arrayValue.type !== ControlType.ComponentInstance) continue\n\t\t\tif (!isString(arrayValue.value)) continue\n\t\t\tif (!isCircular(arrayValue.value)) continue\n\t\t\terrorIndexes.push(i)\n\t\t}\n\n\t\t// remove error indexes from array\n\t\twhile (errorIndexes.length > 0) {\n\t\t\t// biome-ignore lint/style/noNonNullAssertion: bounds already checked above\n\t\t\tarray.splice(errorIndexes.pop()!, 1)\n\t\t}\n\t}\n}\n\nfunction detachReplica(node: CanvasNode) {\n\tnode.originalid = null\n\tnode.replicaInfo = null\n}\n\nfunction repairMasterLinks(\n\ttree: SimpleTree,\n\tstart: CanvasNode & IsMaster,\n\tat: CanvasNode & IsMaster,\n\terrors: string[],\n) {\n\tfor (const node of at.walk()) {\n\t\tif (node === at) continue\n\t\tif (!withTemplate(node)) continue\n\n\t\tif (isReplica(node)) {\n\t\t\tconst master = repairReplica(tree, node, errors)\n\t\t\tif (!master) continue\n\n\t\t\tif (start === master) {\n\t\t\t\terrors.push(`${start.id}: template component links itself via ${at.id}`)\n\t\t\t\tdetachReplica(node)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\trepairMasterLinks(tree, start, master, errors)\n\t\t}\n\t}\n}\n\nfunction repairReplica(\n\ttree: SimpleTree,\n\tnode: CanvasNode & IsReplica,\n\terrors: string[],\n): (CanvasNode & IsMaster) | null {\n\tconst masterid = node.replicaInfo.master\n\tconst master = tree.get(masterid)\n\tif (!master) {\n\t\terrors.push(`${node.id}: template references a master that doesn't exist: ${masterid}`)\n\t\tdetachReplica(node)\n\t\treturn null\n\t}\n\tif (!isMaster(master)) {\n\t\terrors.push(`${node.id}: template references a node that is not a master: ${masterid}`)\n\t\tdetachReplica(node)\n\t\treturn null\n\t}\n\tif (node.originalid !== masterid) {\n\t\terrors.push(`${node.id}: template originalid doesn't point to master id: ${node.originalid}`)\n\t\tnode.originalid = masterid\n\t}\n\treturn master\n}\n\nfunction repairInheritsFrom(tree: SimpleTree, node: CanvasNode, errors: string[]): void {\n\tif (!node.replicaInfo) return\n\tconst inherited = node.replicaInfo.inheritsFrom\n\tif (!inherited) return\n\n\tconst inherit = tree.get(inherited)\n\tif (!inherit) {\n\t\terrors.push(`${node.id}: template references an inherit that doesn't exist: ${inherited}`)\n\t\tnode.replicaInfo.inheritsFrom = undefined\n\t} else if (!isMaster(inherit) && !isReplica(inherit)) {\n\t\terrors.push(`${node.id}: template references an inherit that isn't a master or a replica: ${inherited}`)\n\t\tnode.replicaInfo.inheritsFrom = undefined\n\t}\n}\n\nfunction repairReplicaChild(node: CanvasNode, errors: string[]) {\n\tif (node.originalid) {\n\t\tnode.originalid = null\n\t\terrors.push(`${node.id}: removing original id from orphan replica child`)\n\t}\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;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