{"version":3,"names":["Node","YogaNode","createRenderer","createTermNode","type","yogaNode","props","children","parent","screenRect","scrollTop","dirty","_cachedText","markDirty","node","current","render","effect","memo","createComponent","createElement","createTextNode","insert","insertNode","spread","setProp","mergeProps","ref","value","content","createSlotNode","isTextNode","replaceText","ancestor","measureFunc","setProperty","key","anchor","idx","indexOf","splice","push","yogaIndex","c","insertChild","removeNode","removeChild","getParentNode","undefined","getFirstChild","getNextSibling"],"sources":["term-node.ts"],"sourcesContent":["import { Node as YogaNode } from \"../core/yoga.ts\";\nimport { createRenderer } from \"./index.ts\";\n\n/** Screen-space rectangle cached during paint for hit-testing. */\nexport interface ScreenRect {\n\tbottom: number;\n\tleft: number;\n\tright: number;\n\ttop: number;\n}\n\nexport interface TermNode {\n\t/** Cached collectText() result — cleared on markDirty. */\n\t_cachedText: string | null;\n\tchildren: TermNode[];\n\tdirty: boolean;\n\tparent: TermNode | null;\n\tprops: Record<string, unknown>;\n\t/** Screen-space bounds, updated each paint pass. */\n\tscreenRect: ScreenRect | null;\n\t/** Scroll offset for overflow=\"scroll\" containers. */\n\tscrollTop: number;\n\ttype: string;\n\tyogaNode: YogaNode | null;\n}\n\nfunction createTermNode(type: string): TermNode {\n\tconst yogaNode = type === \"_text\" || type === \"_slot\" ? null : new YogaNode();\n\treturn {\n\t\ttype,\n\t\tprops: {},\n\t\tchildren: [],\n\t\tparent: null,\n\t\tyogaNode,\n\t\tscreenRect: null,\n\t\tscrollTop: 0,\n\t\tdirty: true,\n\t\t_cachedText: null,\n\t};\n}\n\nfunction markDirty(node: TermNode) {\n\tnode.dirty = true;\n\tnode._cachedText = null;\n\tlet current = node.parent;\n\twhile (current && !current.dirty) {\n\t\tcurrent.dirty = true;\n\t\tcurrent._cachedText = null;\n\t\tcurrent = current.parent;\n\t}\n}\n\nexport const {\n\trender,\n\teffect,\n\tmemo,\n\tcreateComponent,\n\tcreateElement,\n\tcreateTextNode,\n\tinsert,\n\tinsertNode,\n\tspread,\n\tsetProp,\n\tmergeProps,\n\tref,\n} = createRenderer<TermNode>({\n\tcreateElement(type: string) {\n\t\treturn createTermNode(type);\n\t},\n\n\tcreateTextNode(value: string) {\n\t\tconst node = createTermNode(\"_text\");\n\t\tnode.props.content = value;\n\t\treturn node;\n\t},\n\n\tcreateSlotNode() {\n\t\treturn createTermNode(\"_slot\");\n\t},\n\n\tisTextNode(node: TermNode) {\n\t\treturn node.type === \"_text\";\n\t},\n\n\treplaceText(node: TermNode, value: string) {\n\t\tnode.props.content = value;\n\t\t// Walk up to the nearest ancestor with a measure function and mark its\n\t\t// yoga node dirty so layout re-measures the text height. Without this,\n\t\t// yoga caches the old measurement and content-driven scrolling breaks.\n\t\tlet ancestor: TermNode | null = node.parent;\n\t\twhile (ancestor) {\n\t\t\tif (ancestor.yogaNode?.measureFunc) {\n\t\t\t\tancestor.yogaNode.markDirty();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tancestor = ancestor.parent;\n\t\t}\n\t\tmarkDirty(node);\n\t},\n\n\tsetProperty<T>(node: TermNode, key: string, value: T) {\n\t\tnode.props[key] = value;\n\t\t// Mark yoga dirty so measure functions re-run (e.g. input value changes height)\n\t\tif (node.yogaNode?.measureFunc) {\n\t\t\tnode.yogaNode.markDirty();\n\t\t}\n\t\tmarkDirty(node);\n\t},\n\n\tinsertNode(parent: TermNode, node: TermNode, anchor?: TermNode) {\n\t\tif (anchor) {\n\t\t\tconst idx = parent.children.indexOf(anchor);\n\t\t\tparent.children.splice(idx, 0, node);\n\t\t} else {\n\t\t\tparent.children.push(node);\n\t\t}\n\t\tnode.parent = parent;\n\n\t\t// Attach yoga child if both have yoga nodes\n\t\tif (parent.yogaNode && node.yogaNode) {\n\t\t\tlet yogaIndex = 0;\n\t\t\tfor (const c of parent.children) {\n\t\t\t\tif (c === node) break;\n\t\t\t\tif (c.yogaNode) yogaIndex++;\n\t\t\t}\n\t\t\tparent.yogaNode.insertChild(node.yogaNode, yogaIndex);\n\t\t}\n\n\t\tmarkDirty(parent);\n\t},\n\n\tremoveNode(parent: TermNode, node: TermNode) {\n\t\tconst idx = parent.children.indexOf(node);\n\t\tif (idx >= 0) parent.children.splice(idx, 1);\n\n\t\tif (parent.yogaNode && node.yogaNode) {\n\t\t\tparent.yogaNode.removeChild(node.yogaNode);\n\t\t}\n\n\t\tnode.parent = null;\n\t\tmarkDirty(parent);\n\t},\n\n\tgetParentNode(node: TermNode) {\n\t\treturn node.parent ?? undefined;\n\t},\n\n\tgetFirstChild(node: TermNode) {\n\t\treturn node.children[0];\n\t},\n\n\tgetNextSibling(node: TermNode) {\n\t\tif (!node.parent) return undefined;\n\t\tconst idx = node.parent.children.indexOf(node);\n\t\treturn node.parent.children[idx + 1];\n\t},\n});\n"],"mappings":"AAAA,SAASA,IAAI,IAAIC,QAAQ,QAAQ,iBAAiB;AAClD,SAASC,cAAc,QAAQ,YAAY;;AAE3C;;AAuBA,SAASC,cAAcA,CAACC,IAAY,EAAY;EAC/C,MAAMC,QAAQ,GAAGD,IAAI,KAAK,OAAO,IAAIA,IAAI,KAAK,OAAO,GAAG,IAAI,GAAG,IAAIH,QAAQ,CAAC,CAAC;EAC7E,OAAO;IACNG,IAAI;IACJE,KAAK,EAAE,CAAC,CAAC;IACTC,QAAQ,EAAE,EAAE;IACZC,MAAM,EAAE,IAAI;IACZH,QAAQ;IACRI,UAAU,EAAE,IAAI;IAChBC,SAAS,EAAE,CAAC;IACZC,KAAK,EAAE,IAAI;IACXC,WAAW,EAAE;EACd,CAAC;AACF;AAEA,SAASC,SAASA,CAACC,IAAc,EAAE;EAClCA,IAAI,CAACH,KAAK,GAAG,IAAI;EACjBG,IAAI,CAACF,WAAW,GAAG,IAAI;EACvB,IAAIG,OAAO,GAAGD,IAAI,CAACN,MAAM;EACzB,OAAOO,OAAO,IAAI,CAACA,OAAO,CAACJ,KAAK,EAAE;IACjCI,OAAO,CAACJ,KAAK,GAAG,IAAI;IACpBI,OAAO,CAACH,WAAW,GAAG,IAAI;IAC1BG,OAAO,GAAGA,O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