@pithyjs/core 0.1.0-beta.19 → 0.1.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -1
- package/dist/compile/binds/bindAfterProjection.d.ts.map +1 -1
- package/dist/compile/binds/bindAfterProjection.js +2 -0
- package/dist/compile/binds/bindAfterProjection.js.map +1 -1
- package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -1
- package/dist/compile/binds/bindClassDirectives.js +2 -1
- package/dist/compile/binds/bindClassDirectives.js.map +1 -1
- package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
- package/dist/compile/binds/bindComponentsTags.js +36 -21
- package/dist/compile/binds/bindComponentsTags.js.map +1 -1
- package/dist/compile/binds/bindErrorBoundary.d.ts +31 -0
- package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
- package/dist/compile/binds/bindErrorBoundary.js +110 -13
- package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
- package/dist/compile/binds/bindTextInterpolations.d.ts.map +1 -1
- package/dist/compile/binds/bindTextInterpolations.js +7 -5
- package/dist/compile/binds/bindTextInterpolations.js.map +1 -1
- package/dist/compile/compileNodes.d.ts.map +1 -1
- package/dist/compile/compileNodes.js +8 -4
- package/dist/compile/compileNodes.js.map +1 -1
- package/dist/compile/compileTemplate.d.ts.map +1 -1
- package/dist/compile/compileTemplate.js +12 -8
- package/dist/compile/compileTemplate.js.map +1 -1
- package/dist/compile/contentProjection.d.ts +2 -2
- package/dist/compile/contentProjection.d.ts.map +1 -1
- package/dist/compile/contentProjection.js +22 -8
- package/dist/compile/contentProjection.js.map +1 -1
- package/dist/compile/evalDiagnostics.d.ts +7 -0
- package/dist/compile/evalDiagnostics.d.ts.map +1 -0
- package/dist/compile/evalDiagnostics.js +8 -0
- package/dist/compile/evalDiagnostics.js.map +1 -0
- package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -1
- package/dist/compile/forLoops/createLoopManager.js +5 -0
- package/dist/compile/forLoops/createLoopManager.js.map +1 -1
- package/dist/compile/nodeExpando.d.ts +2 -0
- package/dist/compile/nodeExpando.d.ts.map +1 -1
- package/dist/compile/nodeExpando.js.map +1 -1
- package/dist/compile/renderBranch.d.ts.map +1 -1
- package/dist/compile/renderBranch.js +7 -2
- package/dist/compile/renderBranch.js.map +1 -1
- package/dist/compile/ssrCrashes.d.ts +64 -36
- package/dist/compile/ssrCrashes.d.ts.map +1 -1
- package/dist/compile/ssrCrashes.js +342 -37
- package/dist/compile/ssrCrashes.js.map +1 -1
- package/dist/runtime/applyBindings.d.ts.map +1 -1
- package/dist/runtime/applyBindings.js +13 -3
- package/dist/runtime/applyBindings.js.map +1 -1
- package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
- package/dist/runtime/bindings/applyComponent.js +19 -17
- package/dist/runtime/bindings/applyComponent.js.map +1 -1
- package/dist/runtime/bindings/applySimple.d.ts +7 -0
- package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
- package/dist/runtime/bindings/applySimple.js +22 -10
- package/dist/runtime/bindings/applySimple.js.map +1 -1
- package/dist/runtime/bindings/applyStructural.d.ts.map +1 -1
- package/dist/runtime/bindings/applyStructural.js +115 -105
- package/dist/runtime/bindings/applyStructural.js.map +1 -1
- package/dist/runtime/bindings/index.d.ts +1 -1
- package/dist/runtime/bindings/index.d.ts.map +1 -1
- package/dist/runtime/bindings/index.js +1 -1
- package/dist/runtime/bindings/index.js.map +1 -1
- package/dist/types/globals.d.ts +6 -0
- package/dist/types/globals.d.ts.map +1 -1
- package/dist/types/globals.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindTextInterpolations.js","sourceRoot":"","sources":["../../../src/compile/binds/bindTextInterpolations.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAA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,aAAa,CAAC;IAC5E,OAAO,CAAC,EAAE,CAAC;QACT,IAAI,CAAC,KAAK,IAAI;YAAE,UAAU,GAAG,KAAK,CAAC;QACnC,IACE,WAAW,CAAC,CAAC,CAAC,CAAC,eAAe;YAC9B,CAAC,UAAU,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC;YAElD,OAAO,IAAI,CAAC;QACd,IACE,CAAC,CAAC,YAAY;YACd,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,EACtD,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC;IACtB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.interpolations\",\n \"title\": \"Text Interpolation Binding System\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { defaultConfig } from '../../config';\nimport { effect, isSignal } from '@pithyjs/signals';\nimport { toTextValue } from '../textValue';\nimport { compileExpression } from '../compileExpression';\nimport { isSSRMode } from '../ssrMode';\nimport { nodeExpando } from '../nodeExpando';\n\nconst INTERPOLATION_RE = /{{\\s*([\\s\\S]*?)\\s*}}/g;\n\n/**\n * Bind all text interpolations (e.g. \"Hello {{name()}}\") under `root`.\n * - Binds only text still as the template parser created it.\n * - Skips nested-loop subtrees (tagged with __pithySkipText) and real @for/data-for hosts.\n * - Skips DOM a component rendered (__pithyComponentDom); the component bound it itself.\n * - Binds per-text-node updates with fine-grained effects.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.interpolations\",\"name\":\"bindTextInterpolations\",\"stability\":\"stable\",\"signature\":\"(root: Element | DocumentFragment, ctx: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindTextInterpolations(\n root: Element | DocumentFragment,\n _ctx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n processChildNodes(root, disposers);\n bindRemainingTextInterpolations(root, disposers);\n}\n\n/* -----------------------------------------------------------------------------\n * Internal: robust child iteration (Element | DocumentFragment)\n * ---------------------------------------------------------------------------*/\nfunction childElementsOf(root: Element | DocumentFragment): Element[] {\n if (root instanceof Element) return Array.from(root.children);\n // DocumentFragment doesn't have .children; filter childNodes to elements\n const out: Element[] = [];\n root.childNodes.forEach(n => {\n if (n.nodeType === Node.ELEMENT_NODE) out.push(n as Element);\n });\n return out;\n}\n\n/**\n * Walk immediate children and process text nodes inside them.\n * We purposely avoid stepping into nested-loop subtrees to prevent compiling\n * expressions like {{ item() }} against the parent context.\n */\nfunction processChildNodes(\n root: Element | DocumentFragment,\n disposers: (() => void)[]\n): void {\n for (const child of childElementsOf(root)) {\n // Fast-path: if the child itself is a loop host, we skip it entirely.\n if (\n child.hasAttribute?.('@for') ||\n nodeExpando(child).__pithySkipText ||\n nodeExpando(child).__pithyComponentDom\n )\n continue;\n\n const walker = document.createTreeWalker(child, NodeFilter.SHOW_TEXT);\n const targets: Text[] = [];\n let textNode: Text | null;\n\n while ((textNode = walker.nextNode() as Text | null)) {\n if (!isTemplateText(textNode)) continue;\n\n // Skip anything inside a nested loop host or explicit @for/data-for\n if (isInsideSkippedZone(textNode, root)) continue;\n\n targets.push(textNode);\n }\n\n // Mutate after collecting to avoid invalidating the walker during traversal.\n for (const node of targets) {\n // An earlier interpolation in this loop can write into a queued node.\n if (!isTemplateText(node)) continue;\n const rawText = node.nodeValue || '';\n const parts = parseTextIntoParts(rawText);\n const parent = node.parentElement;\n const nextSibling = node.nextSibling;\n if (!parent) continue;\n\n // Use the node's own __pithyCtx (set by pithyTreeToDom).\n // Projected slot content carries the *parent* component's context this way,\n // not the context of the component whose template holds the slot.\n // This mirrors the nearestCtx pattern used by bindEventHandlers.\n const nodeCtx = nodeExpando(node).__pithyCtx!;\n\n parent.removeChild(node);\n\n for (const part of parts) {\n if (part.type === 'static') {\n insertStaticTextNode(parent, nextSibling, part.value);\n } else {\n // Determine interpolation mode based on config\n const mode = defaultConfig.textInterpolationMode || 'text-node';\n const isSignal = isSignalExpression(part.value, nodeCtx);\n\n // Choose insertion strategy\n if (mode === 'span') {\n // Always use span wrappers\n insertDynamicSpan(\n parent,\n nextSibling,\n part.value,\n nodeCtx,\n disposers\n );\n } else if (mode === 'text-node') {\n // Always use text nodes with comment anchors\n insertDynamicTextNode(\n parent,\n nextSibling,\n part.value,\n nodeCtx,\n disposers\n );\n } else {\n // 'auto' mode: span for signals if autoWrapSignals is true, text node otherwise\n if (isSignal && defaultConfig.autoWrapSignals) {\n insertDynamicSpan(\n parent,\n nextSibling,\n part.value,\n nodeCtx,\n disposers\n );\n } else {\n insertDynamicTextNode(\n parent,\n nextSibling,\n part.value,\n nodeCtx,\n disposers\n );\n }\n }\n }\n }\n }\n }\n}\n\n/**\n * Second pass: text nodes directly under `root` (e.g., loose text, or nodes\n * not caught by processChildNodes). Also respects skip zones.\n */\nfunction bindRemainingTextInterpolations(\n root: Element | DocumentFragment,\n disposers: (() => void)[]\n): void {\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);\n\n let node: Text | null;\n while ((node = walker.nextNode() as Text | null)) {\n if (!isTemplateText(node)) continue;\n const rawText = node.nodeValue!;\n\n // Robust skip: private flag, @for, or data-for anywhere up the chain.\n if (isInsideSkippedZone(node, root)) continue;\n\n INTERPOLATION_RE.lastIndex = 0;\n const matches = [...rawText.matchAll(INTERPOLATION_RE)];\n if (matches.length === 0) continue;\n\n // Use the node's own __pithyCtx (projected slot content\n // carries the parent component's context via this property).\n const nodeCtx = nodeExpando(node).__pithyCtx!;\n // The node keeps its identity and now holds a value: an outer pass must not read it.\n nodeExpando(node).__pithyCtx = undefined;\n\n const renderFns: (() => unknown)[] = [];\n const matchStrings: string[] = [];\n const expressions: string[] = [];\n\n for (const match of matches) {\n const expr = match[1].trim();\n matchStrings.push(match[0]);\n expressions.push(expr);\n renderFns.push(compileExpression(expr, nodeCtx));\n }\n\n bindTextNodeUpdates(\n node,\n rawText,\n expressions,\n matchStrings,\n renderFns,\n disposers\n );\n }\n}\n\n/* -----------------------------------------------------------------------------\n * Node insertion helpers\n * ---------------------------------------------------------------------------*/\nfunction insertStaticTextNode(\n parent: Element,\n nextSibling: ChildNode | null,\n text: string\n): void {\n const staticNode = document.createTextNode(text);\n parent.insertBefore(staticNode, nextSibling);\n}\n\nfunction insertDynamicSpan(\n parent: Element,\n nextSibling: ChildNode | null,\n expression: string,\n ctx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n const span = document.createElement('span');\n span.className = 'r-pithy';\n span.style.display = 'inline';\n\n const textNode = document.createTextNode('');\n span.appendChild(textNode);\n parent.insertBefore(span, nextSibling);\n\n bindDynamicTextNode(textNode, expression, ctx, disposers, span);\n}\n\nfunction insertDynamicTextNode(\n parent: Element,\n nextSibling: ChildNode | null,\n expression: string,\n ctx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n // Create comment anchors for structural markers (Solid.js approach)\n // This provides better debugging and potential future optimizations\n const startComment = document.createComment('t');\n const textNode = document.createTextNode('');\n const endComment = document.createComment('/t');\n\n // Insert in order: start comment, text node, end comment\n parent.insertBefore(startComment, nextSibling);\n parent.insertBefore(textNode, nextSibling);\n parent.insertBefore(endComment, nextSibling);\n\n bindDynamicTextNode(textNode, expression, ctx, disposers);\n}\n\n/* -----------------------------------------------------------------------------\n * Binding helpers\n * ---------------------------------------------------------------------------*/\nfunction bindTextNodeUpdates(\n node: Text,\n rawText: string,\n expressions: string[],\n matchStrings: string[],\n renderFns: (() => unknown)[],\n disposers: (() => void)[]\n): void {\n function evaluate() {\n let output = rawText;\n\n // Evaluate each {{ expr }} and replace into the original text\n expressions.forEach((_, i) => {\n try {\n const result = renderFns[i](); // compileExpression already closes over ctx\n // Function replacer: never let `$&`, `$$`, `$\\``, `$'`, `$n` in the\n // value be interpreted as String.replace special patterns — the value\n // must be inserted verbatim (e.g. literal code like `str.replace(/a/, '$&')`).\n output = output.replace(matchStrings[i], () => toTextValue(result));\n } catch {\n // On evaluation failure, blank out the interpolation instead of throwing\n output = output.replace(matchStrings[i], '');\n }\n });\n\n return output;\n }\n\n if (isSSRMode()) {\n // SSR mode: evaluate once synchronously, no reactive effects\n node.nodeValue = evaluate();\n } else {\n let lastInterpolatedText: string | undefined;\n\n const stop = effect(() => {\n const output = evaluate();\n\n if (output !== lastInterpolatedText) {\n node.nodeValue = output;\n flashUpdate(node);\n lastInterpolatedText = output;\n }\n });\n\n disposers.push(stop);\n }\n}\n\n/**\n * Bind a single dynamic expression into a text node, with optional highlight target (e.g., wrapper span).\n */\nfunction bindDynamicTextNode(\n textNode: Text,\n expression: string,\n ctx: Record<string, unknown>,\n disposers: (() => void)[],\n highlightTarget?: HTMLElement\n): void {\n try {\n const compiledFn = compileExpression(expression, ctx);\n\n if (isSSRMode()) {\n // SSR mode: evaluate once synchronously, no reactive effects\n try {\n textNode.nodeValue = toTextValue(compiledFn());\n } catch (err) {\n console.error(\n `[bindDynamicTextNode] ❌ Error evaluating '${expression}'`,\n err\n );\n textNode.nodeValue = '';\n }\n } else {\n let lastValue: string | undefined;\n\n const stop = effect(() => {\n try {\n const result = compiledFn(); // re-evaluates reactively\n const next = toTextValue(result); // ensure string\n\n if (next !== lastValue) {\n // only mutate/flash on change\n textNode.nodeValue = next;\n\n if (highlightTarget) {\n flashUpdate(highlightTarget);\n } else {\n flashUpdate(textNode);\n }\n\n lastValue = next;\n }\n } catch (err) {\n console.error(\n `[bindDynamicTextNode] ❌ Error evaluating '${expression}'`,\n err\n );\n textNode.nodeValue = '';\n }\n });\n\n disposers.push(stop);\n }\n } catch (err) {\n console.error(\n `[bindDynamicTextNode] ❌ Failed to compile: ${expression}`,\n err\n );\n }\n}\n\n/* -----------------------------------------------------------------------------\n * Batched flashing (dev only). Reduces style/layout churn vs per-node inline updates.\n *\n * For text nodes, we create temporary positioned overlays at the exact text location\n * to provide visual feedback without adding permanent DOM nodes or flashing parent elements.\n * ---------------------------------------------------------------------------*/\nexport function flashUpdate(node: Text | Element): void {\n const { highlightColor, highlightDuration, devHighlightDomUpdates } =\n defaultConfig;\n if (!import.meta.env?.DEV || !devHighlightDomUpdates) return;\n\n if (node.nodeType === Node.TEXT_NODE) {\n flashTextNode(node as Text, highlightColor || '', highlightDuration || 0.2);\n } else {\n enqueueFlash(\n node as HTMLElement,\n highlightColor || '',\n highlightDuration || 0.2\n );\n }\n}\n\nconst flashQueue = new Set<HTMLElement>();\nlet flashScheduled = false;\n// Pending cleanup timers per element — cancelled on re-flash so a previous\n// flash's timers can't clear the background/transition mid-fade of a newer\n// one (rapidly-updating bindings flash the same element in overlapping\n// windows).\nconst flashTimers = new WeakMap<\n HTMLElement,\n { fade: ReturnType<typeof setTimeout>; clear?: ReturnType<typeof setTimeout> }\n>();\nconst flashOriginals = new WeakMap<\n HTMLElement,\n {\n transition: string;\n backgroundColor: string;\n flashTransition: string;\n flashBackground: string;\n }\n>();\n\nfunction enqueueFlash(el: HTMLElement, color: string, duration: number) {\n flashQueue.add(el);\n if (flashScheduled) return;\n flashScheduled = true;\n\n requestAnimationFrame(() => {\n // Apply highlight to all queued nodes at once\n flashQueue.forEach(t => {\n const pending = flashTimers.get(t);\n if (pending) {\n clearTimeout(pending.fade);\n if (pending.clear !== undefined) clearTimeout(pending.clear);\n }\n const { style } = t;\n let original = flashOriginals.get(t);\n if (!original) {\n original = {\n transition: style.transition,\n backgroundColor: style.backgroundColor,\n flashTransition: '',\n flashBackground: '',\n };\n flashOriginals.set(t, original);\n } else {\n if (style.transition !== original.flashTransition) {\n original.transition = style.transition;\n }\n if (style.backgroundColor !== original.flashBackground) {\n original.backgroundColor = style.backgroundColor;\n }\n }\n const saved = original;\n\n style.transition = `background-color ${duration}s ease-out`;\n style.backgroundColor = color;\n saved.flashTransition = style.transition;\n saved.flashBackground = style.backgroundColor;\n\n const fade = setTimeout(() => {\n // Restore, don't set \"transparent\" — an explicit inline value would\n // permanently override the element's stylesheet background. Runs\n // even for disconnected nodes so a reattached element doesn't keep\n // stale inline highlight styles.\n if (style.backgroundColor === saved.flashBackground) {\n style.backgroundColor = saved.backgroundColor;\n }\n const clear = setTimeout(() => {\n if (style.transition === saved.flashTransition) {\n style.transition = saved.transition;\n }\n flashTimers.delete(t);\n flashOriginals.delete(t);\n }, duration * 1000);\n flashTimers.set(t, { fade, clear });\n }, 80);\n flashTimers.set(t, { fade });\n });\n\n flashQueue.clear();\n flashScheduled = false;\n });\n}\n\n/**\n * Flash a text node update by creating a temporary positioned overlay.\n * This provides visual feedback for text-node mode without permanent DOM nodes.\n */\nfunction flashTextNode(textNode: Text, color: string, duration: number) {\n if (!textNode.parentElement) return;\n\n // Get the exact bounding rect of the text node\n const range = document.createRange();\n range.selectNodeContents(textNode);\n const rect = range.getBoundingClientRect();\n range.detach();\n\n // Skip if text has no dimensions (empty or not rendered)\n if (rect.width === 0 || rect.height === 0) return;\n\n // Create temporary overlay positioned exactly over the text\n const overlay = document.createElement('div');\n overlay.style.cssText = `\n position: fixed;\n left: ${rect.left}px;\n top: ${rect.top}px;\n width: ${rect.width}px;\n height: ${rect.height}px;\n background-color: ${color};\n pointer-events: none;\n z-index: 999999;\n transition: opacity ${duration}s ease-out;\n opacity: 0.6;\n border-radius: 2px;\n `;\n\n document.body.appendChild(overlay);\n\n // Fade out and remove\n requestAnimationFrame(() => {\n overlay.style.opacity = '0';\n\n setTimeout(() => {\n overlay.remove();\n }, duration * 1000);\n });\n}\n\n/* -----------------------------------------------------------------------------\n * Text parsing & expression helpers\n * ---------------------------------------------------------------------------*/\nfunction parseTextIntoParts(\n rawText: string\n): { type: 'static' | 'dynamic'; value: string }[] {\n const parts: { type: 'static' | 'dynamic'; value: string }[] = [];\n\n let lastIndex = 0;\n let match: RegExpExecArray | null;\n\n INTERPOLATION_RE.lastIndex = 0;\n while ((match = INTERPOLATION_RE.exec(rawText)) !== null) {\n if (match.index > lastIndex) {\n parts.push({\n type: 'static',\n value: rawText.slice(lastIndex, match.index),\n });\n }\n parts.push({ type: 'dynamic', value: match[1].trim() });\n lastIndex = match.index + match[0].length;\n }\n\n if (lastIndex < rawText.length) {\n parts.push({ type: 'static', value: rawText.slice(lastIndex) });\n }\n\n return parts;\n}\n\nfunction isTemplateText(node: Text): boolean {\n const { __pithyCtx, __pithyNode } = nodeExpando(node);\n return (\n __pithyCtx !== undefined &&\n __pithyNode?.textContent === node.nodeValue &&\n !!node.nodeValue?.includes('{{')\n );\n}\n\n/**\n * Is the expression a signal call? (e.g., count(), user.tags())\n * We compile the callee (without \"()\") and ask isSignal() on the result.\n */\nfunction isSignalExpression(\n expr: string,\n ctx: Record<string, unknown>\n): boolean {\n // Quick test: must end with \"()\"\n if (!/\\(\\)$/.test(expr)) return false;\n\n try {\n const functionExpr = expr.replace(/\\(\\)$/, '');\n const compiledFn = compileExpression(functionExpr, ctx);\n const signalFunction = compiledFn();\n return isSignal(signalFunction);\n } catch {\n return false;\n }\n}\n\n/**\n * Returns true if `node` is inside any subtree we must not text-bind now:\n * - A nested-loop host we tagged earlier: __pithySkipText\n * - A node a component rendered, or one inside it: __pithyComponentDom\n * - An element that still carries @for or data-for (depending on compiler phase)\n */\nfunction isInsideSkippedZone(\n node: Node,\n root: Element | DocumentFragment\n): boolean {\n if (nodeExpando(node).__pithyComponentDom) return true;\n let insideRoot = true;\n let p: Element | null = node instanceof Element ? node : node.parentElement;\n while (p) {\n if (p === root) insideRoot = false;\n if (\n nodeExpando(p).__pithySkipText ||\n (insideRoot && nodeExpando(p).__pithyComponentDom)\n )\n return true;\n if (\n p.hasAttribute &&\n (p.hasAttribute('@for') || p.hasAttribute('data-for'))\n ) {\n return true;\n }\n p = p.parentElement;\n }\n return false;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bindTextInterpolations.js","sourceRoot":"","sources":["../../../src/compile/binds/bindTextInterpolations.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,QAAQ,EAA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,CAAC,IAAI,CAAC,CAAC,mBAAmB;QAAE,OAAO,IAAI,CAAC;IACvD,IAAI,UAAU,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,GAAmB,IAAI,YAAY,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC;IAC5E,OAAO,CAAC,EAAE,CAAC;QACT,IAAI,CAAC,KAAK,IAAI;YAAE,UAAU,GAAG,KAAK,CAAC;QACnC,IACE,WAAW,CAAC,CAAC,CAAC,CAAC,eAAe;YAC9B,CAAC,UAAU,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC;YAElD,OAAO,IAAI,CAAC;QACd,IACE,CAAC,CAAC,YAAY;YACd,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,EACtD,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC;IACtB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.interpolations\",\n \"title\": \"Text Interpolation Binding System\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { defaultConfig } from '../../config';\nimport { effect, isSignal } from '@pithyjs/signals';\nimport { toTextValue } from '../textValue';\nimport { compileExpression } from '../compileExpression';\nimport { isSSRMode } from '../ssrMode';\nimport { textEvalMessage } from '../evalDiagnostics';\nimport { nodeExpando } from '../nodeExpando';\n\nconst INTERPOLATION_RE = /{{\\s*([\\s\\S]*?)\\s*}}/g;\n\n/**\n * Bind all text interpolations (e.g. \"Hello {{name()}}\") under `root`.\n * - Binds only text still as the template parser created it.\n * - Skips nested-loop subtrees (tagged with __pithySkipText) and real @for/data-for hosts.\n * - Skips DOM a component rendered (__pithyComponentDom); the component bound it itself.\n * - Binds per-text-node updates with fine-grained effects.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.interpolations\",\"name\":\"bindTextInterpolations\",\"stability\":\"stable\",\"signature\":\"(root: Element | DocumentFragment, ctx: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindTextInterpolations(\n root: Element | DocumentFragment,\n _ctx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n processChildNodes(root, disposers);\n bindRemainingTextInterpolations(root, disposers);\n}\n\n/* -----------------------------------------------------------------------------\n * Internal: robust child iteration (Element | DocumentFragment)\n * ---------------------------------------------------------------------------*/\nfunction childElementsOf(root: Element | DocumentFragment): Element[] {\n if (root instanceof Element) return Array.from(root.children);\n // DocumentFragment doesn't have .children; filter childNodes to elements\n const out: Element[] = [];\n root.childNodes.forEach(n => {\n if (n.nodeType === Node.ELEMENT_NODE) out.push(n as Element);\n });\n return out;\n}\n\n/**\n * Walk immediate children and process text nodes inside them.\n * We purposely avoid stepping into nested-loop subtrees to prevent compiling\n * expressions like {{ item() }} against the parent context.\n */\nfunction processChildNodes(\n root: Element | DocumentFragment,\n disposers: (() => void)[]\n): void {\n for (const child of childElementsOf(root)) {\n // Fast-path: if the child itself is a loop host, we skip it entirely.\n if (\n child.hasAttribute?.('@for') ||\n nodeExpando(child).__pithySkipText ||\n nodeExpando(child).__pithyComponentDom\n )\n continue;\n\n const walker = document.createTreeWalker(child, NodeFilter.SHOW_TEXT);\n const targets: Text[] = [];\n let textNode: Text | null;\n\n while ((textNode = walker.nextNode() as Text | null)) {\n if (!isTemplateText(textNode)) continue;\n\n // Skip anything inside a nested loop host or explicit @for/data-for\n if (isInsideSkippedZone(textNode, root)) continue;\n\n targets.push(textNode);\n }\n\n // Mutate after collecting to avoid invalidating the walker during traversal.\n for (const node of targets) {\n // An earlier interpolation in this loop can write into a queued node.\n if (!isTemplateText(node)) continue;\n const rawText = node.nodeValue || '';\n const parts = parseTextIntoParts(rawText);\n const parent = node.parentElement;\n const nextSibling = node.nextSibling;\n if (!parent) continue;\n\n // Use the node's own __pithyCtx (set by pithyTreeToDom).\n // Projected slot content carries the *parent* component's context this way,\n // not the context of the component whose template holds the slot.\n // This mirrors the nearestCtx pattern used by bindEventHandlers.\n const nodeCtx = nodeExpando(node).__pithyCtx!;\n\n parent.removeChild(node);\n\n for (const part of parts) {\n if (part.type === 'static') {\n insertStaticTextNode(parent, nextSibling, part.value);\n } else {\n // Determine interpolation mode based on config\n const mode = defaultConfig.textInterpolationMode || 'text-node';\n const isSignal = isSignalExpression(part.value, nodeCtx);\n\n // Choose insertion strategy\n if (mode === 'span') {\n // Always use span wrappers\n insertDynamicSpan(\n parent,\n nextSibling,\n part.value,\n nodeCtx,\n disposers\n );\n } else if (mode === 'text-node') {\n // Always use text nodes with comment anchors\n insertDynamicTextNode(\n parent,\n nextSibling,\n part.value,\n nodeCtx,\n disposers\n );\n } else {\n // 'auto' mode: span for signals if autoWrapSignals is true, text node otherwise\n if (isSignal && defaultConfig.autoWrapSignals) {\n insertDynamicSpan(\n parent,\n nextSibling,\n part.value,\n nodeCtx,\n disposers\n );\n } else {\n insertDynamicTextNode(\n parent,\n nextSibling,\n part.value,\n nodeCtx,\n disposers\n );\n }\n }\n }\n }\n }\n }\n}\n\n/**\n * Second pass: text nodes directly under `root` (e.g., loose text, or nodes\n * not caught by processChildNodes). Also respects skip zones.\n */\nfunction bindRemainingTextInterpolations(\n root: Element | DocumentFragment,\n disposers: (() => void)[]\n): void {\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);\n\n let node: Text | null;\n while ((node = walker.nextNode() as Text | null)) {\n if (!isTemplateText(node)) continue;\n const rawText = node.nodeValue!;\n\n // Robust skip: private flag, @for, or data-for anywhere up the chain.\n if (isInsideSkippedZone(node, root)) continue;\n\n INTERPOLATION_RE.lastIndex = 0;\n const matches = [...rawText.matchAll(INTERPOLATION_RE)];\n if (matches.length === 0) continue;\n\n // Use the node's own __pithyCtx (projected slot content\n // carries the parent component's context via this property).\n const nodeCtx = nodeExpando(node).__pithyCtx!;\n // The node keeps its identity and now holds a value: an outer pass must not read it.\n nodeExpando(node).__pithyCtx = undefined;\n\n const renderFns: (() => unknown)[] = [];\n const matchStrings: string[] = [];\n const expressions: string[] = [];\n\n for (const match of matches) {\n const expr = match[1].trim();\n matchStrings.push(match[0]);\n expressions.push(expr);\n renderFns.push(compileExpression(expr, nodeCtx));\n }\n\n bindTextNodeUpdates(\n node,\n rawText,\n expressions,\n matchStrings,\n renderFns,\n disposers\n );\n }\n}\n\n/* -----------------------------------------------------------------------------\n * Node insertion helpers\n * ---------------------------------------------------------------------------*/\nfunction insertStaticTextNode(\n parent: Element,\n nextSibling: ChildNode | null,\n text: string\n): void {\n const staticNode = document.createTextNode(text);\n parent.insertBefore(staticNode, nextSibling);\n}\n\nfunction insertDynamicSpan(\n parent: Element,\n nextSibling: ChildNode | null,\n expression: string,\n ctx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n const span = document.createElement('span');\n span.className = 'r-pithy';\n span.style.display = 'inline';\n\n const textNode = document.createTextNode('');\n span.appendChild(textNode);\n parent.insertBefore(span, nextSibling);\n\n bindDynamicTextNode(textNode, expression, ctx, disposers, span);\n}\n\nfunction insertDynamicTextNode(\n parent: Element,\n nextSibling: ChildNode | null,\n expression: string,\n ctx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n // Create comment anchors for structural markers (Solid.js approach)\n // This provides better debugging and potential future optimizations\n const startComment = document.createComment('t');\n const textNode = document.createTextNode('');\n const endComment = document.createComment('/t');\n\n // Insert in order: start comment, text node, end comment\n parent.insertBefore(startComment, nextSibling);\n parent.insertBefore(textNode, nextSibling);\n parent.insertBefore(endComment, nextSibling);\n\n bindDynamicTextNode(textNode, expression, ctx, disposers);\n}\n\n/* -----------------------------------------------------------------------------\n * Binding helpers\n * ---------------------------------------------------------------------------*/\nfunction bindTextNodeUpdates(\n node: Text,\n rawText: string,\n expressions: string[],\n matchStrings: string[],\n renderFns: (() => unknown)[],\n disposers: (() => void)[]\n): void {\n function evaluate() {\n let output = rawText;\n\n // Evaluate each {{ expr }} and replace into the original text\n expressions.forEach((_, i) => {\n try {\n const result = renderFns[i](); // compileExpression already closes over ctx\n // Function replacer: never let `$&`, `$$`, `$\\``, `$'`, `$n` in the\n // value be interpreted as String.replace special patterns — the value\n // must be inserted verbatim (e.g. literal code like `str.replace(/a/, '$&')`).\n output = output.replace(matchStrings[i], () => toTextValue(result));\n } catch (err) {\n console.error(textEvalMessage(expressions[i]), err);\n output = output.replace(matchStrings[i], '');\n }\n });\n\n return output;\n }\n\n if (isSSRMode()) {\n // SSR mode: evaluate once synchronously, no reactive effects\n node.nodeValue = evaluate();\n } else {\n let lastInterpolatedText: string | undefined;\n\n const stop = effect(() => {\n const output = evaluate();\n\n if (output !== lastInterpolatedText) {\n node.nodeValue = output;\n flashUpdate(node);\n lastInterpolatedText = output;\n }\n });\n\n disposers.push(stop);\n }\n}\n\n/**\n * Bind a single dynamic expression into a text node, with optional highlight target (e.g., wrapper span).\n */\nfunction bindDynamicTextNode(\n textNode: Text,\n expression: string,\n ctx: Record<string, unknown>,\n disposers: (() => void)[],\n highlightTarget?: HTMLElement\n): void {\n try {\n const compiledFn = compileExpression(expression, ctx);\n\n if (isSSRMode()) {\n // SSR mode: evaluate once synchronously, no reactive effects\n try {\n textNode.nodeValue = toTextValue(compiledFn());\n } catch (err) {\n console.error(textEvalMessage(expression), err);\n textNode.nodeValue = '';\n }\n } else {\n let lastValue: string | undefined;\n\n const stop = effect(() => {\n try {\n const result = compiledFn(); // re-evaluates reactively\n const next = toTextValue(result); // ensure string\n\n if (next !== lastValue) {\n // only mutate/flash on change\n textNode.nodeValue = next;\n\n if (highlightTarget) {\n flashUpdate(highlightTarget);\n } else {\n flashUpdate(textNode);\n }\n\n lastValue = next;\n }\n } catch (err) {\n console.error(textEvalMessage(expression), err);\n textNode.nodeValue = '';\n lastValue = '';\n }\n });\n\n disposers.push(stop);\n }\n } catch (err) {\n console.error(`[PithyJS] ❌ Failed to compile: ${expression}`, err);\n }\n}\n\n/* -----------------------------------------------------------------------------\n * Batched flashing (dev only). Reduces style/layout churn vs per-node inline updates.\n *\n * For text nodes, we create temporary positioned overlays at the exact text location\n * to provide visual feedback without adding permanent DOM nodes or flashing parent elements.\n * ---------------------------------------------------------------------------*/\nexport function flashUpdate(node: Text | Element): void {\n const { highlightColor, highlightDuration, devHighlightDomUpdates } =\n defaultConfig;\n if (!import.meta.env?.DEV || !devHighlightDomUpdates) return;\n\n if (node.nodeType === Node.TEXT_NODE) {\n flashTextNode(node as Text, highlightColor || '', highlightDuration || 0.2);\n } else {\n enqueueFlash(\n node as HTMLElement,\n highlightColor || '',\n highlightDuration || 0.2\n );\n }\n}\n\nconst flashQueue = new Set<HTMLElement>();\nlet flashScheduled = false;\n// Pending cleanup timers per element — cancelled on re-flash so a previous\n// flash's timers can't clear the background/transition mid-fade of a newer\n// one (rapidly-updating bindings flash the same element in overlapping\n// windows).\nconst flashTimers = new WeakMap<\n HTMLElement,\n { fade: ReturnType<typeof setTimeout>; clear?: ReturnType<typeof setTimeout> }\n>();\nconst flashOriginals = new WeakMap<\n HTMLElement,\n {\n transition: string;\n backgroundColor: string;\n flashTransition: string;\n flashBackground: string;\n }\n>();\n\nfunction enqueueFlash(el: HTMLElement, color: string, duration: number) {\n flashQueue.add(el);\n if (flashScheduled) return;\n flashScheduled = true;\n\n requestAnimationFrame(() => {\n // Apply highlight to all queued nodes at once\n flashQueue.forEach(t => {\n const pending = flashTimers.get(t);\n if (pending) {\n clearTimeout(pending.fade);\n if (pending.clear !== undefined) clearTimeout(pending.clear);\n }\n const { style } = t;\n let original = flashOriginals.get(t);\n if (!original) {\n original = {\n transition: style.transition,\n backgroundColor: style.backgroundColor,\n flashTransition: '',\n flashBackground: '',\n };\n flashOriginals.set(t, original);\n } else {\n if (style.transition !== original.flashTransition) {\n original.transition = style.transition;\n }\n if (style.backgroundColor !== original.flashBackground) {\n original.backgroundColor = style.backgroundColor;\n }\n }\n const saved = original;\n\n style.transition = `background-color ${duration}s ease-out`;\n style.backgroundColor = color;\n saved.flashTransition = style.transition;\n saved.flashBackground = style.backgroundColor;\n\n const fade = setTimeout(() => {\n // Restore, don't set \"transparent\" — an explicit inline value would\n // permanently override the element's stylesheet background. Runs\n // even for disconnected nodes so a reattached element doesn't keep\n // stale inline highlight styles.\n if (style.backgroundColor === saved.flashBackground) {\n style.backgroundColor = saved.backgroundColor;\n }\n const clear = setTimeout(() => {\n if (style.transition === saved.flashTransition) {\n style.transition = saved.transition;\n }\n flashTimers.delete(t);\n flashOriginals.delete(t);\n }, duration * 1000);\n flashTimers.set(t, { fade, clear });\n }, 80);\n flashTimers.set(t, { fade });\n });\n\n flashQueue.clear();\n flashScheduled = false;\n });\n}\n\n/**\n * Flash a text node update by creating a temporary positioned overlay.\n * This provides visual feedback for text-node mode without permanent DOM nodes.\n */\nfunction flashTextNode(textNode: Text, color: string, duration: number) {\n if (!textNode.parentElement) return;\n\n // Get the exact bounding rect of the text node\n const range = document.createRange();\n range.selectNodeContents(textNode);\n const rect = range.getBoundingClientRect();\n range.detach();\n\n // Skip if text has no dimensions (empty or not rendered)\n if (rect.width === 0 || rect.height === 0) return;\n\n // Create temporary overlay positioned exactly over the text\n const overlay = document.createElement('div');\n overlay.style.cssText = `\n position: fixed;\n left: ${rect.left}px;\n top: ${rect.top}px;\n width: ${rect.width}px;\n height: ${rect.height}px;\n background-color: ${color};\n pointer-events: none;\n z-index: 999999;\n transition: opacity ${duration}s ease-out;\n opacity: 0.6;\n border-radius: 2px;\n `;\n\n document.body.appendChild(overlay);\n\n // Fade out and remove\n requestAnimationFrame(() => {\n overlay.style.opacity = '0';\n\n setTimeout(() => {\n overlay.remove();\n }, duration * 1000);\n });\n}\n\n/* -----------------------------------------------------------------------------\n * Text parsing & expression helpers\n * ---------------------------------------------------------------------------*/\nfunction parseTextIntoParts(\n rawText: string\n): { type: 'static' | 'dynamic'; value: string }[] {\n const parts: { type: 'static' | 'dynamic'; value: string }[] = [];\n\n let lastIndex = 0;\n let match: RegExpExecArray | null;\n\n INTERPOLATION_RE.lastIndex = 0;\n while ((match = INTERPOLATION_RE.exec(rawText)) !== null) {\n if (match.index > lastIndex) {\n parts.push({\n type: 'static',\n value: rawText.slice(lastIndex, match.index),\n });\n }\n parts.push({ type: 'dynamic', value: match[1].trim() });\n lastIndex = match.index + match[0].length;\n }\n\n if (lastIndex < rawText.length) {\n parts.push({ type: 'static', value: rawText.slice(lastIndex) });\n }\n\n return parts;\n}\n\nfunction isTemplateText(node: Text): boolean {\n const { __pithyCtx, __pithyNode } = nodeExpando(node);\n return (\n __pithyCtx !== undefined &&\n __pithyNode?.textContent === node.nodeValue &&\n !!node.nodeValue?.includes('{{')\n );\n}\n\n/**\n * Is the expression a signal call? (e.g., count(), user.tags())\n * We compile the callee (without \"()\") and ask isSignal() on the result.\n */\nfunction isSignalExpression(\n expr: string,\n ctx: Record<string, unknown>\n): boolean {\n // Quick test: must end with \"()\"\n if (!/\\(\\)$/.test(expr)) return false;\n\n try {\n const functionExpr = expr.replace(/\\(\\)$/, '');\n const compiledFn = compileExpression(functionExpr, ctx);\n const signalFunction = compiledFn();\n return isSignal(signalFunction);\n } catch {\n return false;\n }\n}\n\n/**\n * Returns true if `node` is inside any subtree we must not text-bind now:\n * - A nested-loop host we tagged earlier: __pithySkipText\n * - A node a component rendered, or one inside it: __pithyComponentDom\n * - An element that still carries @for or data-for (depending on compiler phase)\n */\nfunction isInsideSkippedZone(\n node: Node,\n root: Element | DocumentFragment\n): boolean {\n if (nodeExpando(node).__pithyComponentDom) return true;\n let insideRoot = true;\n let p: Element | null = node instanceof Element ? node : node.parentElement;\n while (p) {\n if (p === root) insideRoot = false;\n if (\n nodeExpando(p).__pithySkipText ||\n (insideRoot && nodeExpando(p).__pithyComponentDom)\n )\n return true;\n if (\n p.hasAttribute &&\n (p.hasAttribute('@for') || p.hasAttribute('data-for'))\n ) {\n return true;\n }\n p = p.parentElement;\n }\n return false;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileNodes.d.ts","sourceRoot":"","sources":["../../src/compile/compileNodes.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"compileNodes.d.ts","sourceRoot":"","sources":["../../src/compile/compileNodes.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAUnD;;;;;;;;;;;;;;;;;GAiBG;AACH,0NAA0N;AAC1N,wBAAgB,YAAY,CAC1B,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B;IAAE,EAAE,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CA+E/C"}
|
|
@@ -9,6 +9,7 @@ import { pithyTreeToDom } from './pithyTreeToDom.js';
|
|
|
9
9
|
import { bindStructuralDirectives, bindTemplateDirectives, } from './compileTemplate.js';
|
|
10
10
|
import { drainDestroyCallbacks } from '../runtime/onDestroy.js';
|
|
11
11
|
import { orderByDocument } from './disposeOrder.js';
|
|
12
|
+
import { withinRender } from './ssrCrashes.js';
|
|
12
13
|
/**
|
|
13
14
|
* Compiles an array of PithyNode AST nodes into live DOM with full binding pipeline.
|
|
14
15
|
*
|
|
@@ -37,10 +38,13 @@ export function compileNodes(nodes, context) {
|
|
|
37
38
|
try {
|
|
38
39
|
// 1. AST → unbound DOM
|
|
39
40
|
fragment = pithyTreeToDom(nodes, context);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const built = fragment;
|
|
42
|
+
withinRender(() => {
|
|
43
|
+
// 2. Structural directives (@switch, @if/@else, @for)
|
|
44
|
+
bindStructuralDirectives(nodes, built, context, disposers);
|
|
45
|
+
// 3. Non-structural bindings (refs, error boundaries, components, text, events, etc.)
|
|
46
|
+
bindTemplateDirectives(built, context, disposers);
|
|
47
|
+
});
|
|
44
48
|
orderByDocument(disposers);
|
|
45
49
|
}
|
|
46
50
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileNodes.js","sourceRoot":"","sources":["../../src/compile/compileNodes.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAGF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"compileNodes.js","sourceRoot":"","sources":["../../src/compile/compileNodes.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAGF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;;;;;;;;;;;;GAiBG;AACH,0NAA0N;AAC1N,MAAM,UAAU,YAAY,CAC1B,KAAkB,EAClB,OAAgC;IAEhC,yEAAyE;IACzE,+DAA+D;IAC/D,MAAM,gBAAgB,GAAG,qBAAqB,EAAE,CAAC;IACjD,MAAM,SAAS,GAAmB,EAAE,CAAC;IAErC,IAAI,QAA0B,CAAC;IAC/B,IAAI,CAAC;QACH,uBAAuB;QACvB,QAAQ,GAAG,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,QAAQ,CAAC;QAEvB,YAAY,CAAC,GAAG,EAAE;YAChB,sDAAsD;YACt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CAAC;IACJ,CAAC;IAED,OAAO;QACL,EAAE,EAAE,QAAQ;QACZ,OAAO;YACL,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC/C,IAAI,CAAC;oBACH,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;gBACjB,CAAC;gBAAC,MAAM,CAAC;oBACP,YAAY;gBACd,CAAC;YACH,CAAC;YACD,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;YACrB,KAAK,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBACtD,IAAI,CAAC;oBACH,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;gBACxB,CAAC;gBAAC,MAAM,CAAC;oBACP,YAAY;gBACd,CAAC;YACH,CAAC;YACD,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.compile-nodes\",\n \"title\": \"AST Node Compiler\",\n \"category\": \"runtime\"\n}\n*/\n\nimport type { PithyNode } from '@pithyjs/compiler';\nimport { pithyTreeToDom } from './pithyTreeToDom';\nimport {\n bindStructuralDirectives,\n bindTemplateDirectives,\n} from './compileTemplate';\nimport { drainDestroyCallbacks } from '../runtime/onDestroy';\nimport { orderByDocument } from './disposeOrder';\nimport { withinRender } from './ssrCrashes';\n\n/**\n * Compiles an array of PithyNode AST nodes into live DOM with full binding pipeline.\n *\n * This is the AST counterpart to `compileTemplate`:\n * - `compileTemplate`: HTML string → parse → AST → DOM → structural → non-structural\n * - `compileNodes`: AST → DOM → structural → non-structural\n *\n * Use when you already have AST nodes (e.g. from `__childAstNodes` in component context)\n * and need the full compilation pipeline including structural directives (@if, @switch, @for).\n *\n * @example\n * ```ts\n * import { compileNodes } from \"@pithyjs/core\";\n * const { el, destroy } = compileNodes(astNodes, context);\n * document.body.appendChild(el);\n * // later: destroy();\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"compileNodes\",\"stability\":\"stable\",\"signature\":\"(nodes: PithyNode[], context: Record<string, unknown>) => { el: DocumentFragment; destroy: () => void }\"} */\nexport function compileNodes(\n nodes: PithyNode[],\n context: Record<string, unknown>\n): { el: DocumentFragment; destroy: () => void } {\n // Drain onDestroy() callbacks — prevents leaks when compileNodes is used\n // as a standalone entry point (renderChildren, ErrorBoundary).\n const destroyCallbacks = drainDestroyCallbacks();\n const disposers: (() => void)[] = [];\n\n let fragment: DocumentFragment;\n try {\n // 1. AST → unbound DOM\n fragment = pithyTreeToDom(nodes, context);\n const built = fragment;\n\n withinRender(() => {\n // 2. Structural directives (@switch, @if/@else, @for)\n bindStructuralDirectives(nodes, built, context, disposers);\n\n // 3. Non-structural bindings (refs, error boundaries, components, text, events, etc.)\n bindTemplateDirectives(built, context, disposers);\n });\n orderByDocument(disposers);\n } catch (err) {\n // Clean up any disposers already registered during partial compilation\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n // Run drained callbacks LIFO before rethrowing so partially-initialized\n // resources are still cleaned up.\n for (let i = destroyCallbacks.length - 1; i >= 0; i--) {\n try {\n destroyCallbacks[i]();\n } catch {\n /* ignore */\n }\n }\n throw err;\n }\n\n // Fast path when no onDestroy was called\n if (destroyCallbacks.length === 0) {\n return {\n el: fragment,\n destroy() {\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n disposers.length = 0;\n },\n };\n }\n\n return {\n el: fragment,\n destroy() {\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n disposers.length = 0;\n for (let i = destroyCallbacks.length - 1; i >= 0; i--) {\n try {\n destroyCallbacks[i]();\n } catch {\n /* ignore */\n }\n }\n destroyCallbacks.length = 0;\n },\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileTemplate.d.ts","sourceRoot":"","sources":["../../src/compile/compileTemplate.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;
|
|
1
|
+
{"version":3,"file":"compileTemplate.d.ts","sourceRoot":"","sources":["../../src/compile/compileTemplate.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAkBF;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,mBAAmB,EAAE,SAAS,EAAE,EAC9C,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAUN;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,+RAA+R;AAC/R,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,EAChB,mBAAmB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAChC;IAAE,EAAE,EAAE,WAAW,GAAG,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CAiD7D;AAED;;;;;;;;;;;;;;;GAeG;AACH,qNAAqN;AACrN,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAsBN"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
}
|
|
7
7
|
*/
|
|
8
8
|
import { parseHtml } from './parseHtml.js';
|
|
9
|
+
import { withinRender } from './ssrCrashes.js';
|
|
9
10
|
import { injectScopedStyle } from './injectScopedStyle.js';
|
|
10
11
|
import { bindConditionals } from './binds/bindConditionals.js';
|
|
11
12
|
import { bindRefDirectives } from './binds/bindRefDirectives.js';
|
|
@@ -60,14 +61,17 @@ export function compileTemplate(html, context, css, scopeId, importedIdentifiers
|
|
|
60
61
|
// Parse into fragment + AST
|
|
61
62
|
const parsed = parseHtml(html, id, context, importedIdentifiers);
|
|
62
63
|
fragment = parsed.fragment;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
const built = fragment;
|
|
65
|
+
withinRender(() => {
|
|
66
|
+
// Structural transforms first (they change the DOM shape and add anchors)
|
|
67
|
+
bindStructuralDirectives(parsed.pithyNodes, built, context, disposers);
|
|
68
|
+
// Scoped CSS after structure is stable
|
|
69
|
+
if (css) {
|
|
70
|
+
injectScopedStyle(css, id);
|
|
71
|
+
}
|
|
72
|
+
// Remaining directives/bindings in carefully chosen order
|
|
73
|
+
bindTemplateDirectives(built, context, disposers);
|
|
74
|
+
});
|
|
71
75
|
orderByDocument(disposers);
|
|
72
76
|
}
|
|
73
77
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileTemplate.js","sourceRoot":"","sources":["../../src/compile/compileTemplate.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,O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iFAAiF;IACjF,kFAAkF;IAClF,yFAAyF;IACzF,MAAM,OAAO,GAAG,CAAC,WAAW,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAE1D,CAAC;IACd,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC3C,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,eAAe,CAAC,QAAQ,EAAE,OAAO,IAAI,IAAI,GAAG,EAAE,EAAE,SAAS,CAAC,CAAC;IAC7D,CAAC;IAED,8EAA8E;IAC9E,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.renderer\",\n \"title\": \"Template Compiler & Renderer\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { parseHtml } from './parseHtml';\nimport { injectScopedStyle } from './injectScopedStyle';\nimport { bindConditionals } from './binds/bindConditionals';\nimport { bindRefDirectives } from './binds/bindRefDirectives';\nimport { bindErrorBoundary } from './binds/bindErrorBoundary';\nimport { bindForLoops } from './forLoops/bindForLoops';\nimport { bindSwitchCases } from './bindSwitchCases';\nimport {\n extractSlotDefs,\n mountProjection,\n type SlotMap,\n} from './contentProjection';\nimport { bindAfterProjection } from './binds/bindAfterProjection';\nimport { orderByDocument } from './disposeOrder';\n\n/**\n * Runs all structural directive bindings on a fragment.\n *\n * Ordering:\n * 1) Switch cases first — they claim their case subtrees before conditionals walk the DOM\n * 2) Conditionals (@if/@else) — each branch binds its own nested switches\n * 3) For loops — skips nodes already processed by switches and conditionals\n */\nexport function bindStructuralDirectives(\n nodes: import('@pithyjs/compiler').PithyNode[],\n fragment: DocumentFragment,\n context: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n const processed = bindSwitchCases(\n nodes,\n fragment,\n context,\n new Set(),\n disposers\n );\n bindConditionals(nodes, fragment, context, processed, disposers);\n bindForLoops(nodes, fragment, context, disposers, processed);\n}\n\n/**\n * Compiles a raw HTML template into live DOM nodes with signal bindings,\n * event handlers, and optional styles.\n *\n * Pipeline overview:\n * 1) parseHtml → returns a DocumentFragment + AST nodes (pithyNodes)\n * 2) structural directives first: @if/@else, @switch, @for (they shape the DOM)\n * 3) inject CSS (scoped)\n * 4) run remaining binders in an order that avoids double-binding and cross-contamination:\n * - refs (so later passes can access refs if needed)\n * - components (instantiate/replace custom tags BEFORE binding into their subtree)\n * - two-way (default model bindings for inputs)\n * - text interpolations\n * - events\n * - classes\n * - bound attributes\n *\n * @param html - Raw HTML template string\n * @param context - Reactive context object (signals, methods, components)\n * @param css - Optional CSS string to scope and inject\n * @param scopeId - Optional scope id for CSS scoping\n * @param importedIdentifiers - Optional set of ids exposed to expressions\n */\n/** @codexApi {\"parent\":\"pithy.runtime.renderer\",\"name\":\"compileTemplate\",\"stability\":\"stable\",\"signature\":\"(html: string, context: Record<string, any>, css?: string, scopeId?: string, importedIdentifiers?: Set<string>) => { el: HTMLElement | DocumentFragment; destroy: () => void }\"} */\nexport function compileTemplate(\n html: string,\n context: Record<string, unknown>,\n css?: string,\n scopeId?: string,\n importedIdentifiers?: Set<string>\n): { el: HTMLElement | DocumentFragment; destroy: () => void } {\n const id = scopeId ?? `pithy-${Math.random().toString(36).slice(2, 8)}`;\n const disposers: (() => void)[] = [];\n\n let fragment: DocumentFragment;\n try {\n // Parse into fragment + AST\n const parsed = parseHtml(html, id, context, importedIdentifiers);\n fragment = parsed.fragment;\n\n // Structural transforms first (they change the DOM shape and add anchors)\n bindStructuralDirectives(parsed.pithyNodes, fragment, context, disposers);\n\n // Scoped CSS after structure is stable\n if (css) {\n injectScopedStyle(css, id);\n }\n\n // Remaining directives/bindings in carefully chosen order\n bindTemplateDirectives(fragment, context, disposers);\n orderByDocument(disposers);\n } catch (err) {\n // Clean up any disposers registered during partial compilation\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n throw err;\n }\n\n return {\n el: fragment,\n destroy() {\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n disposers.length = 0;\n },\n };\n}\n\n/**\n * Applies all non-structural bindings to the compiled fragment.\n *\n * Ordering rationale:\n * - refs: collected early, sometimes needed by subsequent binders\n * - error boundaries: register boundaries before components render (enables error capture)\n * - projection: mount projected content into slot anchors BEFORE component binding,\n * so nested component tags in projected content get processed\n * - components: instantiate/replace custom tags (including those in projected content);\n * prevents parent binders from walking into raw component tags\n * - two-way: attach default v-model-ish behavior on real inputs (not inside components)\n * - text: {{ ... }} bindings (skips nested loops / component subtrees via flags)\n * - events: add listeners (idempotent; supports modifiers; nearest ctx; $event/$el)\n * - classes: dynamic class toggles\n * - attributes: remaining [attr]=\"...\" bindings\n */\n/** @codexApi {\"parent\":\"pithy.runtime.renderer\",\"name\":\"bindTemplateDirectives\",\"stability\":\"stable\",\"signature\":\"(fragment: DocumentFragment, context: Record<string, any>, disposers: (() => void)[]) => void\"} */\nexport function bindTemplateDirectives(\n fragment: DocumentFragment,\n context: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n // 1) refs first — enables grabbing component roots/elements if needed\n bindRefDirectives(fragment, context, disposers);\n\n // 2) error boundaries — register before components so they can catch component errors\n bindErrorBoundary(fragment, context, disposers);\n\n // 3) content projection — mount projected content into slot anchors BEFORE components.\n // Projected content may contain component tags (e.g., nested <Show> inside <Show>).\n // If components ran first, those nested component tags would never be processed.\n // Without a SlotMap (a component called directly) slots still get their fallback.\n // Use 'in' operator to check via Proxy's has() trap without triggering the get() warning\n const slotMap = ('__slotMap' in context ? context.__slotMap : undefined) as\n | SlotMap\n | undefined;\n const slotDefs = extractSlotDefs(fragment);\n if (slotDefs.length > 0) {\n mountProjection(slotDefs, slotMap ?? new Map(), disposers);\n }\n\n // 4-11) components, two-way, text, events, classes, attributes, custom, defer\n bindAfterProjection(fragment, context, disposers);\n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,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC/C,IAAI,CAAC;oBACH,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;gBACjB,CAAC;gBAAC,MAAM,CAAC;oBACP,YAAY;gBACd,CAAC;YACH,CAAC;YACD,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,qNAAqN;AACrN,MAAM,UAAU,sBAAsB,CACpC,QAA0B,EAC1B,OAAgC,EAChC,SAAyB;IAEzB,sEAAsE;IACtE,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAEhD,sFAAsF;IACtF,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAEhD,uFAAuF;IACvF,oFAAoF;IACpF,iFAAiF;IACjF,kFAAkF;IAClF,yFAAyF;IACzF,MAAM,OAAO,GAAG,CAAC,WAAW,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAE1D,CAAC;IACd,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC3C,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,eAAe,CAAC,QAAQ,EAAE,OAAO,IAAI,IAAI,GAAG,EAAE,EAAE,SAAS,CAAC,CAAC;IAC7D,CAAC;IAED,8EAA8E;IAC9E,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.renderer\",\n \"title\": \"Template Compiler & Renderer\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { parseHtml } from './parseHtml';\nimport { withinRender } from './ssrCrashes';\nimport { injectScopedStyle } from './injectScopedStyle';\nimport { bindConditionals } from './binds/bindConditionals';\nimport { bindRefDirectives } from './binds/bindRefDirectives';\nimport { bindErrorBoundary } from './binds/bindErrorBoundary';\nimport { bindForLoops } from './forLoops/bindForLoops';\nimport { bindSwitchCases } from './bindSwitchCases';\nimport {\n extractSlotDefs,\n mountProjection,\n type SlotMap,\n} from './contentProjection';\nimport { bindAfterProjection } from './binds/bindAfterProjection';\nimport { orderByDocument } from './disposeOrder';\n\n/**\n * Runs all structural directive bindings on a fragment.\n *\n * Ordering:\n * 1) Switch cases first — they claim their case subtrees before conditionals walk the DOM\n * 2) Conditionals (@if/@else) — each branch binds its own nested switches\n * 3) For loops — skips nodes already processed by switches and conditionals\n */\nexport function bindStructuralDirectives(\n nodes: import('@pithyjs/compiler').PithyNode[],\n fragment: DocumentFragment,\n context: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n const processed = bindSwitchCases(\n nodes,\n fragment,\n context,\n new Set(),\n disposers\n );\n bindConditionals(nodes, fragment, context, processed, disposers);\n bindForLoops(nodes, fragment, context, disposers, processed);\n}\n\n/**\n * Compiles a raw HTML template into live DOM nodes with signal bindings,\n * event handlers, and optional styles.\n *\n * Pipeline overview:\n * 1) parseHtml → returns a DocumentFragment + AST nodes (pithyNodes)\n * 2) structural directives first: @if/@else, @switch, @for (they shape the DOM)\n * 3) inject CSS (scoped)\n * 4) run remaining binders in an order that avoids double-binding and cross-contamination:\n * - refs (so later passes can access refs if needed)\n * - components (instantiate/replace custom tags BEFORE binding into their subtree)\n * - two-way (default model bindings for inputs)\n * - text interpolations\n * - events\n * - classes\n * - bound attributes\n *\n * @param html - Raw HTML template string\n * @param context - Reactive context object (signals, methods, components)\n * @param css - Optional CSS string to scope and inject\n * @param scopeId - Optional scope id for CSS scoping\n * @param importedIdentifiers - Optional set of ids exposed to expressions\n */\n/** @codexApi {\"parent\":\"pithy.runtime.renderer\",\"name\":\"compileTemplate\",\"stability\":\"stable\",\"signature\":\"(html: string, context: Record<string, any>, css?: string, scopeId?: string, importedIdentifiers?: Set<string>) => { el: HTMLElement | DocumentFragment; destroy: () => void }\"} */\nexport function compileTemplate(\n html: string,\n context: Record<string, unknown>,\n css?: string,\n scopeId?: string,\n importedIdentifiers?: Set<string>\n): { el: HTMLElement | DocumentFragment; destroy: () => void } {\n const id = scopeId ?? `pithy-${Math.random().toString(36).slice(2, 8)}`;\n const disposers: (() => void)[] = [];\n\n let fragment: DocumentFragment;\n try {\n // Parse into fragment + AST\n const parsed = parseHtml(html, id, context, importedIdentifiers);\n fragment = parsed.fragment;\n\n const built = fragment;\n withinRender(() => {\n // Structural transforms first (they change the DOM shape and add anchors)\n bindStructuralDirectives(parsed.pithyNodes, built, context, disposers);\n\n // Scoped CSS after structure is stable\n if (css) {\n injectScopedStyle(css, id);\n }\n\n // Remaining directives/bindings in carefully chosen order\n bindTemplateDirectives(built, context, disposers);\n });\n orderByDocument(disposers);\n } catch (err) {\n // Clean up any disposers registered during partial compilation\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n throw err;\n }\n\n return {\n el: fragment,\n destroy() {\n for (let i = disposers.length - 1; i >= 0; i--) {\n try {\n disposers[i]();\n } catch {\n /* ignore */\n }\n }\n disposers.length = 0;\n },\n };\n}\n\n/**\n * Applies all non-structural bindings to the compiled fragment.\n *\n * Ordering rationale:\n * - refs: collected early, sometimes needed by subsequent binders\n * - error boundaries: register boundaries before components render (enables error capture)\n * - projection: mount projected content into slot anchors BEFORE component binding,\n * so nested component tags in projected content get processed\n * - components: instantiate/replace custom tags (including those in projected content);\n * prevents parent binders from walking into raw component tags\n * - two-way: attach default v-model-ish behavior on real inputs (not inside components)\n * - text: {{ ... }} bindings (skips nested loops / component subtrees via flags)\n * - events: add listeners (idempotent; supports modifiers; nearest ctx; $event/$el)\n * - classes: dynamic class toggles\n * - attributes: remaining [attr]=\"...\" bindings\n */\n/** @codexApi {\"parent\":\"pithy.runtime.renderer\",\"name\":\"bindTemplateDirectives\",\"stability\":\"stable\",\"signature\":\"(fragment: DocumentFragment, context: Record<string, any>, disposers: (() => void)[]) => void\"} */\nexport function bindTemplateDirectives(\n fragment: DocumentFragment,\n context: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n // 1) refs first — enables grabbing component roots/elements if needed\n bindRefDirectives(fragment, context, disposers);\n\n // 2) error boundaries — register before components so they can catch component errors\n bindErrorBoundary(fragment, context, disposers);\n\n // 3) content projection — mount projected content into slot anchors BEFORE components.\n // Projected content may contain component tags (e.g., nested <Show> inside <Show>).\n // If components ran first, those nested component tags would never be processed.\n // Without a SlotMap (a component called directly) slots still get their fallback.\n // Use 'in' operator to check via Proxy's has() trap without triggering the get() warning\n const slotMap = ('__slotMap' in context ? context.__slotMap : undefined) as\n | SlotMap\n | undefined;\n const slotDefs = extractSlotDefs(fragment);\n if (slotDefs.length > 0) {\n mountProjection(slotDefs, slotMap ?? new Map(), disposers);\n }\n\n // 4-11) components, two-way, text, events, classes, attributes, custom, defer\n bindAfterProjection(fragment, context, disposers);\n}\n"]}
|
|
@@ -29,8 +29,8 @@ export declare function outerSlotMap(slotMap: SlotMap | undefined): SlotMap | un
|
|
|
29
29
|
/** Records `ctx`'s slot map as what a `<slot>` among `slotMap`'s children receives. */
|
|
30
30
|
/** @codexApi {"parent":"pithy.feature.content-projection","name":"linkOuterSlotMap","stability":"internal","signature":"(slotMap: SlotMap, ctx: Record<string, unknown>) => void"} */
|
|
31
31
|
export declare function linkOuterSlotMap(slotMap: SlotMap, ctx: Record<string, unknown>): void;
|
|
32
|
-
/** @codexApi {"parent":"pithy.feature.content-projection","name":"collectSlotMap","stability":"stable","signature":"(children: PithyNode[], parentContext: Record<string, any
|
|
33
|
-
export declare function collectSlotMap(children: PithyNode[], parentContext: Record<string, unknown
|
|
32
|
+
/** @codexApi {"parent":"pithy.feature.content-projection","name":"collectSlotMap","stability":"stable","signature":"(children: PithyNode[], parentContext: Record<string, any>, host?: Element) => SlotMap"} */
|
|
33
|
+
export declare function collectSlotMap(children: PithyNode[], parentContext: Record<string, unknown>, host?: Element): SlotMap;
|
|
34
34
|
/** @codexApi {"parent":"pithy.feature.content-projection","name":"extractSlotDefs","stability":"stable","signature":"(fragment: DocumentFragment) => SlotDef[]"} */
|
|
35
35
|
export declare function extractSlotDefs(fragment: DocumentFragment): SlotDef[];
|
|
36
36
|
/** Whether `node` is inside content a `<slot>` projected. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentProjection.d.ts","sourceRoot":"","sources":["../../src/compile/contentProjection.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"contentProjection.d.ts","sourceRoot":"","sources":["../../src/compile/contentProjection.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAc9C;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,GAAG,CACvB,MAAM,EACN,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,IAAI,KAAK,gBAAgB,CAChE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,WAAW,GAAG,gBAAgB,GAAG,SAAS,CAAC;AAE/E,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAqBD;;;GAGG;AACH,+KAA+K;AAC/K,wBAAgB,YAAY,CAC1B,OAAO,EAAE,OAAO,GAAG,SAAS,GAC3B,OAAO,GAAG,SAAS,CAErB;AAED,uFAAuF;AACvF,sLAAsL;AACtL,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,IAAI,CAGN;AAED,gNAAgN;AAChN,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,SAAS,EAAE,EACrB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtC,IAAI,CAAC,EAAE,OAAO,GACb,OAAO,CAiGT;AAED,oKAAoK;AACpK,wBAAgB,eAAe,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,EAAE,CA+BrE;AAED,6DAA6D;AAC7D,uJAAuJ;AACvJ,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAItD;AAQD,qMAAqM;AACrM,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAGN"}
|
|
@@ -8,9 +8,10 @@
|
|
|
8
8
|
import { pithyTreeToDom } from './pithyTreeToDom.js';
|
|
9
9
|
import { bindStructuralDirectives } from './compileTemplate.js';
|
|
10
10
|
import { nodeExpando } from './nodeExpando.js';
|
|
11
|
-
import { bindErrorBoundary, insertBesideHidden, isHiddenByBoundary, } from './binds/bindErrorBoundary.js';
|
|
11
|
+
import { bindErrorBoundary, insertBesideHidden, withSlotBoundary, isHiddenByBoundary, } from './binds/bindErrorBoundary.js';
|
|
12
12
|
import { pithyGlobals } from '../types/globals.js';
|
|
13
13
|
import { trimBlankEdges } from './trimBlankEdges.js';
|
|
14
|
+
import { withinRender } from './ssrCrashes.js';
|
|
14
15
|
function expando(node) {
|
|
15
16
|
return node;
|
|
16
17
|
}
|
|
@@ -33,8 +34,8 @@ export function linkOuterSlotMap(slotMap, ctx) {
|
|
|
33
34
|
if (outer)
|
|
34
35
|
outerSlotMaps.set(slotMap, outer);
|
|
35
36
|
}
|
|
36
|
-
/** @codexApi {"parent":"pithy.feature.content-projection","name":"collectSlotMap","stability":"stable","signature":"(children: PithyNode[], parentContext: Record<string, any
|
|
37
|
-
export function collectSlotMap(children, parentContext) {
|
|
37
|
+
/** @codexApi {"parent":"pithy.feature.content-projection","name":"collectSlotMap","stability":"stable","signature":"(children: PithyNode[], parentContext: Record<string, any>, host?: Element) => SlotMap"} */
|
|
38
|
+
export function collectSlotMap(children, parentContext, host) {
|
|
38
39
|
const slotMap = new Map();
|
|
39
40
|
const slotGroups = new Map();
|
|
40
41
|
linkOuterSlotMap(slotMap, parentContext);
|
|
@@ -78,13 +79,18 @@ export function collectSlotMap(children, parentContext) {
|
|
|
78
79
|
// Capture nodes and context in closure for stable reference
|
|
79
80
|
const capturedNodes = nodes;
|
|
80
81
|
const capturedContext = parentContext;
|
|
81
|
-
const render = (disposers = []) => {
|
|
82
|
+
const render = (disposers = [], at) => {
|
|
82
83
|
if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {
|
|
83
84
|
console.log(`[PithyJS:Projection] Rendering slot "${slotName}" with ${capturedNodes.length} nodes`);
|
|
84
85
|
}
|
|
85
86
|
const fragment = pithyTreeToDom(capturedNodes, capturedContext);
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
// As the AOT renderer does: a branch in the content then finds a boundary
|
|
88
|
+
// the receiver wraps its `<slot>` in.
|
|
89
|
+
withSlotBoundary(at, host, () => withinRender(() => {
|
|
90
|
+
bindStructuralDirectives(capturedNodes, fragment, capturedContext, disposers);
|
|
91
|
+
bindErrorBoundary(fragment, capturedContext, disposers);
|
|
92
|
+
return fragment;
|
|
93
|
+
}));
|
|
88
94
|
// A `<slot>` passed through: the receiving component has already looked for its slots.
|
|
89
95
|
const passed = extractSlotDefs(fragment);
|
|
90
96
|
if (passed.length)
|
|
@@ -144,6 +150,10 @@ function inComponentTag(node) {
|
|
|
144
150
|
}
|
|
145
151
|
/** @codexApi {"parent":"pithy.feature.content-projection","name":"mountProjection","stability":"stable","signature":"(slotDefs: SlotDef[], slotMap: SlotMap, disposers: (() => void)[]) => void"} */
|
|
146
152
|
export function mountProjection(slotDefs, slotMap, disposers) {
|
|
153
|
+
// A slot's content is rendered and then inserted: one render transaction.
|
|
154
|
+
withinRender(() => mountSlots(slotDefs, slotMap, disposers));
|
|
155
|
+
}
|
|
156
|
+
function mountSlots(slotDefs, slotMap, disposers) {
|
|
147
157
|
for (const slotDef of slotDefs) {
|
|
148
158
|
const { name, anchor, fallbackFactory } = slotDef;
|
|
149
159
|
const renderer = slotMap.get(name);
|
|
@@ -179,8 +189,12 @@ export function mountProjection(slotDefs, slotMap, disposers) {
|
|
|
179
189
|
if (contentFragment instanceof DocumentFragment &&
|
|
180
190
|
slotNode?.fallbackChildren) {
|
|
181
191
|
const fallbackCtx = nodeExpando(anchor).__pithyCtx ?? {};
|
|
182
|
-
|
|
183
|
-
|
|
192
|
+
const fallbackFragment = contentFragment;
|
|
193
|
+
const fallbackNodes = slotNode.fallbackChildren;
|
|
194
|
+
withinRender(() => {
|
|
195
|
+
bindStructuralDirectives(fallbackNodes, fallbackFragment, fallbackCtx, disposers);
|
|
196
|
+
bindErrorBoundary(fallbackFragment, fallbackCtx, disposers);
|
|
197
|
+
});
|
|
184
198
|
}
|
|
185
199
|
if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {
|
|
186
200
|
console.log(`[PithyJS:Projection] Mounting fallback content for slot "${name}"`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentProjection.js","sourceRoot":"","sources":["../../src/compile/contentProjection.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAGF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AA6Bl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,CAAC,MAAM,oBAAoB,IAAI,GAAG,CAC7F,CAAC;QACJ,CAAC;IACH,CAAC;IAED,2BAA2B;IAC3B,2EAA2E;IAC3E,yEAAyE;IACzE,6EAA6E;IAC7E,sEAAsE;IACtE,uEAAuE;IACvE,qEAAqE;IACrE,gDAAgD;AAClD,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.feature.content-projection\",\n \"title\": \"Content Projection System\",\n \"category\": \"feature\"\n}\n*/\n\nimport { PithyNode } from '@pithyjs/compiler';\nimport { pithyTreeToDom } from './pithyTreeToDom';\nimport { bindStructuralDirectives } from './compileTemplate';\nimport { nodeExpando } from './nodeExpando';\nimport {\n bindErrorBoundary,\n insertBesideHidden,\n isHiddenByBoundary,\n} from './binds/bindErrorBoundary';\nimport { pithyGlobals } from '../types/globals';\nimport { trimBlankEdges } from './trimBlankEdges';\n\n/**\n * SlotMap contains renderer functions for each slot name.\n * Each entry is a factory that returns a DocumentFragment of the slot's content.\n */\nexport type SlotMap = Map<\n string,\n (disposers?: (() => void)[], anchor?: Node) => DocumentFragment\n>;\n\n/**\n * SlotDef describes a slot anchor and its fallback content\n */\nexport type FallbackFactory = () => HTMLElement | DocumentFragment | undefined;\n\nexport interface SlotDef {\n name: string;\n anchor: Comment;\n fallbackFactory?: FallbackFactory;\n}\n\ninterface ProjectionExpando {\n __slotName?: string;\n __fallbackFactory?: FallbackFactory;\n __projectionProcessed?: boolean;\n __projectedContent?: boolean;\n}\n\nfunction expando(node: Node): ProjectionExpando {\n return node as Node & ProjectionExpando;\n}\n\nconst outerSlotMaps = new WeakMap<SlotMap, SlotMap>();\n\nfunction slotMapOf(ctx: Record<string, unknown>): SlotMap | undefined {\n return ('__slotMap' in ctx ? ctx.__slotMap : undefined) as\n | SlotMap\n | undefined;\n}\n\n/**\n * The slot map of the template the children behind `slotMap` were written in:\n * what a `<slot>` among those children receives.\n */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"outerSlotMap\",\"stability\":\"internal\",\"signature\":\"(slotMap: SlotMap | undefined) => SlotMap | undefined\"} */\nexport function outerSlotMap(\n slotMap: SlotMap | undefined\n): SlotMap | undefined {\n return slotMap && outerSlotMaps.get(slotMap);\n}\n\n/** Records `ctx`'s slot map as what a `<slot>` among `slotMap`'s children receives. */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"linkOuterSlotMap\",\"stability\":\"internal\",\"signature\":\"(slotMap: SlotMap, ctx: Record<string, unknown>) => void\"} */\nexport function linkOuterSlotMap(\n slotMap: SlotMap,\n ctx: Record<string, unknown>\n): void {\n const outer = slotMapOf(ctx);\n if (outer) outerSlotMaps.set(slotMap, outer);\n}\n\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"collectSlotMap\",\"stability\":\"stable\",\"signature\":\"(children: PithyNode[], parentContext: Record<string, any>) => SlotMap\"} */\nexport function collectSlotMap(\n children: PithyNode[],\n parentContext: Record<string, unknown>\n): SlotMap {\n const slotMap: SlotMap = new Map();\n const slotGroups = new Map<string, PithyNode[]>();\n linkOuterSlotMap(slotMap, parentContext);\n const outer = slotMapOf(parentContext);\n\n // Group children by slot attribute\n for (const child of children) {\n const slotName = child.directives?.slot || ''; // default slot if no slot attribute\n\n if (!slotGroups.has(slotName)) {\n slotGroups.set(slotName, []);\n }\n slotGroups.get(slotName)!.push(child);\n }\n const defaultSlot = slotGroups.get('');\n if (defaultSlot) {\n const content = trimBlankEdges(defaultSlot, node =>\n node.type === 'text' ? (node.textContent ?? '') : null\n );\n if (content.length) slotGroups.set('', content);\n else slotGroups.delete('');\n }\n\n // Validate slot usage in DEV mode\n if (import.meta.env?.DEV) {\n const slotNames = Array.from(slotGroups.keys());\n const duplicateSlots = slotNames.filter(\n name => name !== '' && slotGroups.get(name)!.length > 1\n );\n if (duplicateSlots.length > 0) {\n console.warn(\n `[ContentProjection] Multiple content nodes targeting the same slot. This is allowed but may indicate a mistake:`,\n duplicateSlots\n );\n }\n }\n\n // Create renderer functions for each slot group.\n // NOTE: We intentionally do NOT cache or clone DocumentFragments here.\n // Using fragment caching + cloneNode(true) would strip custom JS properties\n // like __pithyCtx that binders rely on to resolve projected content\n // expressions (including interpolation, [class], and [attr] bindings)\n // against the *parent* component's context.\n //\n // This behavior is relied upon by regression tests that exercise projected\n // nodes containing such bindings; changing this to reuse or clone\n // fragments will cause those tests to fail and break content projection.\n // pithyTreeToDom is cheap (just creates DOM nodes), so recreating is fine.\n\n for (const [slotName, nodes] of slotGroups) {\n // Capture nodes and context in closure for stable reference\n const capturedNodes = nodes;\n const capturedContext = parentContext;\n\n const render = (disposers: (() => void)[] = []): DocumentFragment => {\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Rendering slot \"${slotName}\" with ${capturedNodes.length} nodes`\n );\n }\n\n const fragment = pithyTreeToDom(capturedNodes, capturedContext);\n bindStructuralDirectives(\n capturedNodes,\n fragment,\n capturedContext,\n disposers\n );\n bindErrorBoundary(fragment, capturedContext, disposers);\n // A `<slot>` passed through: the receiving component has already looked for its slots.\n const passed = extractSlotDefs(fragment);\n if (passed.length) mountProjection(passed, outer ?? new Map(), disposers);\n nodeExpando(fragment).__pithyCtx = capturedContext;\n return fragment;\n };\n\n slotMap.set(slotName, render);\n }\n\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Collected SlotMap with slots:`,\n Array.from(slotMap.keys())\n );\n }\n return slotMap;\n}\n\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"extractSlotDefs\",\"stability\":\"stable\",\"signature\":\"(fragment: DocumentFragment) => SlotDef[]\"} */\nexport function extractSlotDefs(fragment: DocumentFragment): SlotDef[] {\n const slotDefs: SlotDef[] = [];\n const walker = document.createTreeWalker(fragment, NodeFilter.SHOW_COMMENT, {\n acceptNode: node => {\n const comment = node as Comment;\n return comment.textContent?.startsWith('slot:')\n ? NodeFilter.FILTER_ACCEPT\n : NodeFilter.FILTER_REJECT;\n },\n });\n\n let node: Comment | null;\n while ((node = walker.nextNode() as Comment | null)) {\n // Inside a component tag, the slot is that component's content to place.\n if (inComponentTag(node)) continue;\n const slotName = expando(node).__slotName || '';\n const fallbackFactory = expando(node).__fallbackFactory;\n\n slotDefs.push({\n name: slotName,\n anchor: node,\n fallbackFactory,\n });\n }\n\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Extracted ${slotDefs.length} slot definitions`\n );\n }\n return slotDefs;\n}\n\n/** Whether `node` is inside content a `<slot>` projected. */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"inProjectedContent\",\"stability\":\"internal\",\"signature\":\"(node: Node) => boolean\"} */\nexport function inProjectedContent(node: Node): boolean {\n for (let n: Node | null = node; n; n = n.parentNode)\n if (expando(n).__projectedContent) return true;\n return false;\n}\n\nfunction inComponentTag(node: Node): boolean {\n for (let el = node.parentElement; el; el = el.parentElement)\n if (nodeExpando(el).__pithyNode?.isComponent) return true;\n return false;\n}\n\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"mountProjection\",\"stability\":\"stable\",\"signature\":\"(slotDefs: SlotDef[], slotMap: SlotMap, disposers: (() => void)[]) => void\"} */\nexport function mountProjection(\n slotDefs: SlotDef[],\n slotMap: SlotMap,\n disposers: (() => void)[]\n): void {\n for (const slotDef of slotDefs) {\n const { name, anchor, fallbackFactory } = slotDef;\n const renderer = slotMap.get(name);\n\n // Skip if this slot has already been processed\n if (expando(anchor).__projectionProcessed) {\n continue;\n }\n\n // Mark this slot as processed to prevent multiple passes\n expando(anchor).__projectionProcessed = true;\n\n const parent = anchor.parentNode;\n // A crash in an earlier slot can have hidden this anchor behind a fallback.\n if (!parent && !isHiddenByBoundary(anchor)) {\n if (import.meta.env?.DEV) {\n console.warn(\n `[ContentProjection] Slot anchor \"${name}\" has no parent node - skipping`\n );\n }\n continue;\n }\n\n // Determine which content to render\n let contentFragment: HTMLElement | DocumentFragment | null = null;\n let isProjectedContent = false;\n\n if (renderer) {\n // Use projected content\n contentFragment = renderer(disposers, anchor);\n isProjectedContent = true;\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Mounting projected content for slot \"${name}\"`\n );\n }\n } else if (fallbackFactory) {\n // Use fallback content\n contentFragment = fallbackFactory() ?? null;\n const slotNode = nodeExpando(anchor).__pithyNode;\n if (\n contentFragment instanceof DocumentFragment &&\n slotNode?.fallbackChildren\n ) {\n const fallbackCtx = nodeExpando(anchor).__pithyCtx ?? {};\n bindStructuralDirectives(\n slotNode.fallbackChildren,\n contentFragment,\n fallbackCtx,\n disposers\n );\n bindErrorBoundary(contentFragment, fallbackCtx, disposers);\n }\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Mounting fallback content for slot \"${name}\"`\n );\n }\n } else {\n // No content to mount\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(`[PithyJS:Projection] No content for slot \"${name}\"`);\n }\n continue;\n }\n\n // Validate content\n if (!contentFragment || contentFragment.childNodes.length === 0) {\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Empty content for slot \"${name}\" - skipping`\n );\n }\n continue;\n }\n\n // CRITICAL: Collect nodes BEFORE inserting into DOM (for cleanup tracking)\n // Once inserted, the fragment's childNodes will be empty\n const nodesToInsert: Node[] = Array.from(contentFragment.childNodes);\n\n // Mark nodes for tracking\n for (const node of nodesToInsert) {\n expando(node).__projectedContent = isProjectedContent;\n expando(node).__slotName = name;\n }\n\n // Find and remove any existing content for this slot\n const existingNodes: Node[] = [];\n let current = anchor.nextSibling;\n\n while (current) {\n // Stop if we hit another slot anchor\n if (\n current.nodeType === Node.COMMENT_NODE &&\n (current as Comment).textContent?.startsWith('slot:')\n ) {\n break;\n }\n\n // A sibling no projection marked is the component's own markup.\n const meta = expando(current);\n if (meta.__projectedContent === undefined || meta.__slotName !== name) {\n break;\n }\n existingNodes.push(current);\n\n current = current.nextSibling;\n }\n\n // Simple diffing: only replace if content appears different\n // Compare node count and types as a basic heuristic\n const shouldReplace =\n existingNodes.length !== nodesToInsert.length ||\n existingNodes.some(\n (node, i) => node.nodeType !== nodesToInsert[i]?.nodeType\n );\n\n if (!shouldReplace && existingNodes.length > 0) {\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Content for slot \"${name}\" unchanged - skipping replacement`\n );\n }\n continue;\n }\n\n // Remove existing content\n for (const node of existingNodes) {\n if (node.parentNode) {\n node.parentNode.removeChild(node);\n }\n }\n\n // Insert new content after the anchor comment\n if (!insertBesideHidden(anchor, contentFragment))\n parent?.insertBefore(contentFragment, anchor.nextSibling);\n\n // Track cleanup - remove projected nodes when component unmounts\n disposers.push(() => {\n for (const node of nodesToInsert) {\n if (node.parentNode) {\n node.parentNode.removeChild(node);\n }\n }\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(`[PithyJS:Projection] Cleaned up slot \"${name}\"`);\n }\n });\n\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Successfully mounted ${nodesToInsert.length} nodes for slot \"${name}\"`\n );\n }\n }\n\n // DEV: Validate slot usage\n // NOTE: We intentionally do NOT warn about unmatched projected slots here.\n // When a component uses @if/@else with different <slot> elements in each\n // branch (e.g., Show has <slot> in @if and <slot name=\"fallback\"> in @else),\n // the currently-rendered branch may not include all slot targets. The\n // projected \"fallback\" content is legitimate — it will be mounted when\n // the @else branch activates. Warnings here would be false positives\n // and fire repeatedly on every reactive toggle.\n}\n"]}
|
|
1
|
+
{"version":3,"file":"contentProjection.js","sourceRoot":"","sources":["../../src/compile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\"category\": \"feature\"\n}\n*/\n\nimport { PithyNode } from '@pithyjs/compiler';\nimport { pithyTreeToDom } from './pithyTreeToDom';\nimport { bindStructuralDirectives } from './compileTemplate';\nimport { nodeExpando } from './nodeExpando';\nimport {\n bindErrorBoundary,\n insertBesideHidden,\n withSlotBoundary,\n isHiddenByBoundary,\n} from './binds/bindErrorBoundary';\nimport { pithyGlobals } from '../types/globals';\nimport { trimBlankEdges } from './trimBlankEdges';\nimport { withinRender } from './ssrCrashes';\n\n/**\n * SlotMap contains renderer functions for each slot name.\n * Each entry is a factory that returns a DocumentFragment of the slot's content.\n */\nexport type SlotMap = Map<\n string,\n (disposers?: (() => void)[], anchor?: Node) => DocumentFragment\n>;\n\n/**\n * SlotDef describes a slot anchor and its fallback content\n */\nexport type FallbackFactory = () => HTMLElement | DocumentFragment | undefined;\n\nexport interface SlotDef {\n name: string;\n anchor: Comment;\n fallbackFactory?: FallbackFactory;\n}\n\ninterface ProjectionExpando {\n __slotName?: string;\n __fallbackFactory?: FallbackFactory;\n __projectionProcessed?: boolean;\n __projectedContent?: boolean;\n}\n\nfunction expando(node: Node): ProjectionExpando {\n return node as Node & ProjectionExpando;\n}\n\nconst outerSlotMaps = new WeakMap<SlotMap, SlotMap>();\n\nfunction slotMapOf(ctx: Record<string, unknown>): SlotMap | undefined {\n return ('__slotMap' in ctx ? ctx.__slotMap : undefined) as\n | SlotMap\n | undefined;\n}\n\n/**\n * The slot map of the template the children behind `slotMap` were written in:\n * what a `<slot>` among those children receives.\n */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"outerSlotMap\",\"stability\":\"internal\",\"signature\":\"(slotMap: SlotMap | undefined) => SlotMap | undefined\"} */\nexport function outerSlotMap(\n slotMap: SlotMap | undefined\n): SlotMap | undefined {\n return slotMap && outerSlotMaps.get(slotMap);\n}\n\n/** Records `ctx`'s slot map as what a `<slot>` among `slotMap`'s children receives. */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"linkOuterSlotMap\",\"stability\":\"internal\",\"signature\":\"(slotMap: SlotMap, ctx: Record<string, unknown>) => void\"} */\nexport function linkOuterSlotMap(\n slotMap: SlotMap,\n ctx: Record<string, unknown>\n): void {\n const outer = slotMapOf(ctx);\n if (outer) outerSlotMaps.set(slotMap, outer);\n}\n\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"collectSlotMap\",\"stability\":\"stable\",\"signature\":\"(children: PithyNode[], parentContext: Record<string, any>, host?: Element) => SlotMap\"} */\nexport function collectSlotMap(\n children: PithyNode[],\n parentContext: Record<string, unknown>,\n host?: Element\n): SlotMap {\n const slotMap: SlotMap = new Map();\n const slotGroups = new Map<string, PithyNode[]>();\n linkOuterSlotMap(slotMap, parentContext);\n const outer = slotMapOf(parentContext);\n\n // Group children by slot attribute\n for (const child of children) {\n const slotName = child.directives?.slot || ''; // default slot if no slot attribute\n\n if (!slotGroups.has(slotName)) {\n slotGroups.set(slotName, []);\n }\n slotGroups.get(slotName)!.push(child);\n }\n const defaultSlot = slotGroups.get('');\n if (defaultSlot) {\n const content = trimBlankEdges(defaultSlot, node =>\n node.type === 'text' ? (node.textContent ?? '') : null\n );\n if (content.length) slotGroups.set('', content);\n else slotGroups.delete('');\n }\n\n // Validate slot usage in DEV mode\n if (import.meta.env?.DEV) {\n const slotNames = Array.from(slotGroups.keys());\n const duplicateSlots = slotNames.filter(\n name => name !== '' && slotGroups.get(name)!.length > 1\n );\n if (duplicateSlots.length > 0) {\n console.warn(\n `[ContentProjection] Multiple content nodes targeting the same slot. This is allowed but may indicate a mistake:`,\n duplicateSlots\n );\n }\n }\n\n // Create renderer functions for each slot group.\n // NOTE: We intentionally do NOT cache or clone DocumentFragments here.\n // Using fragment caching + cloneNode(true) would strip custom JS properties\n // like __pithyCtx that binders rely on to resolve projected content\n // expressions (including interpolation, [class], and [attr] bindings)\n // against the *parent* component's context.\n //\n // This behavior is relied upon by regression tests that exercise projected\n // nodes containing such bindings; changing this to reuse or clone\n // fragments will cause those tests to fail and break content projection.\n // pithyTreeToDom is cheap (just creates DOM nodes), so recreating is fine.\n\n for (const [slotName, nodes] of slotGroups) {\n // Capture nodes and context in closure for stable reference\n const capturedNodes = nodes;\n const capturedContext = parentContext;\n\n const render = (\n disposers: (() => void)[] = [],\n at?: Node\n ): DocumentFragment => {\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Rendering slot \"${slotName}\" with ${capturedNodes.length} nodes`\n );\n }\n\n const fragment = pithyTreeToDom(capturedNodes, capturedContext);\n // As the AOT renderer does: a branch in the content then finds a boundary\n // the receiver wraps its `<slot>` in.\n withSlotBoundary(at, host, () =>\n withinRender(() => {\n bindStructuralDirectives(\n capturedNodes,\n fragment,\n capturedContext,\n disposers\n );\n bindErrorBoundary(fragment, capturedContext, disposers);\n return fragment;\n })\n );\n // A `<slot>` passed through: the receiving component has already looked for its slots.\n const passed = extractSlotDefs(fragment);\n if (passed.length) mountProjection(passed, outer ?? new Map(), disposers);\n nodeExpando(fragment).__pithyCtx = capturedContext;\n return fragment;\n };\n\n slotMap.set(slotName, render);\n }\n\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Collected SlotMap with slots:`,\n Array.from(slotMap.keys())\n );\n }\n return slotMap;\n}\n\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"extractSlotDefs\",\"stability\":\"stable\",\"signature\":\"(fragment: DocumentFragment) => SlotDef[]\"} */\nexport function extractSlotDefs(fragment: DocumentFragment): SlotDef[] {\n const slotDefs: SlotDef[] = [];\n const walker = document.createTreeWalker(fragment, NodeFilter.SHOW_COMMENT, {\n acceptNode: node => {\n const comment = node as Comment;\n return comment.textContent?.startsWith('slot:')\n ? NodeFilter.FILTER_ACCEPT\n : NodeFilter.FILTER_REJECT;\n },\n });\n\n let node: Comment | null;\n while ((node = walker.nextNode() as Comment | null)) {\n // Inside a component tag, the slot is that component's content to place.\n if (inComponentTag(node)) continue;\n const slotName = expando(node).__slotName || '';\n const fallbackFactory = expando(node).__fallbackFactory;\n\n slotDefs.push({\n name: slotName,\n anchor: node,\n fallbackFactory,\n });\n }\n\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Extracted ${slotDefs.length} slot definitions`\n );\n }\n return slotDefs;\n}\n\n/** Whether `node` is inside content a `<slot>` projected. */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"inProjectedContent\",\"stability\":\"internal\",\"signature\":\"(node: Node) => boolean\"} */\nexport function inProjectedContent(node: Node): boolean {\n for (let n: Node | null = node; n; n = n.parentNode)\n if (expando(n).__projectedContent) return true;\n return false;\n}\n\nfunction inComponentTag(node: Node): boolean {\n for (let el = node.parentElement; el; el = el.parentElement)\n if (nodeExpando(el).__pithyNode?.isComponent) return true;\n return false;\n}\n\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"mountProjection\",\"stability\":\"stable\",\"signature\":\"(slotDefs: SlotDef[], slotMap: SlotMap, disposers: (() => void)[]) => void\"} */\nexport function mountProjection(\n slotDefs: SlotDef[],\n slotMap: SlotMap,\n disposers: (() => void)[]\n): void {\n // A slot's content is rendered and then inserted: one render transaction.\n withinRender(() => mountSlots(slotDefs, slotMap, disposers));\n}\n\nfunction mountSlots(\n slotDefs: SlotDef[],\n slotMap: SlotMap,\n disposers: (() => void)[]\n): void {\n for (const slotDef of slotDefs) {\n const { name, anchor, fallbackFactory } = slotDef;\n const renderer = slotMap.get(name);\n\n // Skip if this slot has already been processed\n if (expando(anchor).__projectionProcessed) {\n continue;\n }\n\n // Mark this slot as processed to prevent multiple passes\n expando(anchor).__projectionProcessed = true;\n\n const parent = anchor.parentNode;\n // A crash in an earlier slot can have hidden this anchor behind a fallback.\n if (!parent && !isHiddenByBoundary(anchor)) {\n if (import.meta.env?.DEV) {\n console.warn(\n `[ContentProjection] Slot anchor \"${name}\" has no parent node - skipping`\n );\n }\n continue;\n }\n\n // Determine which content to render\n let contentFragment: HTMLElement | DocumentFragment | null = null;\n let isProjectedContent = false;\n\n if (renderer) {\n // Use projected content\n contentFragment = renderer(disposers, anchor);\n isProjectedContent = true;\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Mounting projected content for slot \"${name}\"`\n );\n }\n } else if (fallbackFactory) {\n // Use fallback content\n contentFragment = fallbackFactory() ?? null;\n const slotNode = nodeExpando(anchor).__pithyNode;\n if (\n contentFragment instanceof DocumentFragment &&\n slotNode?.fallbackChildren\n ) {\n const fallbackCtx = nodeExpando(anchor).__pithyCtx ?? {};\n const fallbackFragment = contentFragment;\n const fallbackNodes = slotNode.fallbackChildren;\n withinRender(() => {\n bindStructuralDirectives(\n fallbackNodes,\n fallbackFragment,\n fallbackCtx,\n disposers\n );\n bindErrorBoundary(fallbackFragment, fallbackCtx, disposers);\n });\n }\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Mounting fallback content for slot \"${name}\"`\n );\n }\n } else {\n // No content to mount\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(`[PithyJS:Projection] No content for slot \"${name}\"`);\n }\n continue;\n }\n\n // Validate content\n if (!contentFragment || contentFragment.childNodes.length === 0) {\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Empty content for slot \"${name}\" - skipping`\n );\n }\n continue;\n }\n\n // CRITICAL: Collect nodes BEFORE inserting into DOM (for cleanup tracking)\n // Once inserted, the fragment's childNodes will be empty\n const nodesToInsert: Node[] = Array.from(contentFragment.childNodes);\n\n // Mark nodes for tracking\n for (const node of nodesToInsert) {\n expando(node).__projectedContent = isProjectedContent;\n expando(node).__slotName = name;\n }\n\n // Find and remove any existing content for this slot\n const existingNodes: Node[] = [];\n let current = anchor.nextSibling;\n\n while (current) {\n // Stop if we hit another slot anchor\n if (\n current.nodeType === Node.COMMENT_NODE &&\n (current as Comment).textContent?.startsWith('slot:')\n ) {\n break;\n }\n\n // A sibling no projection marked is the component's own markup.\n const meta = expando(current);\n if (meta.__projectedContent === undefined || meta.__slotName !== name) {\n break;\n }\n existingNodes.push(current);\n\n current = current.nextSibling;\n }\n\n // Simple diffing: only replace if content appears different\n // Compare node count and types as a basic heuristic\n const shouldReplace =\n existingNodes.length !== nodesToInsert.length ||\n existingNodes.some(\n (node, i) => node.nodeType !== nodesToInsert[i]?.nodeType\n );\n\n if (!shouldReplace && existingNodes.length > 0) {\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Content for slot \"${name}\" unchanged - skipping replacement`\n );\n }\n continue;\n }\n\n // Remove existing content\n for (const node of existingNodes) {\n if (node.parentNode) {\n node.parentNode.removeChild(node);\n }\n }\n\n // Insert new content after the anchor comment\n if (!insertBesideHidden(anchor, contentFragment))\n parent?.insertBefore(contentFragment, anchor.nextSibling);\n\n // Track cleanup - remove projected nodes when component unmounts\n disposers.push(() => {\n for (const node of nodesToInsert) {\n if (node.parentNode) {\n node.parentNode.removeChild(node);\n }\n }\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(`[PithyJS:Projection] Cleaned up slot \"${name}\"`);\n }\n });\n\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Successfully mounted ${nodesToInsert.length} nodes for slot \"${name}\"`\n );\n }\n }\n\n // DEV: Validate slot usage\n // NOTE: We intentionally do NOT warn about unmatched projected slots here.\n // When a component uses @if/@else with different <slot> elements in each\n // branch (e.g., Show has <slot> in @if and <slot name=\"fallback\"> in @else),\n // the currently-rendered branch may not include all slot targets. The\n // projected \"fallback\" content is legitimate — it will be mounted when\n // the @else branch activates. Warnings here would be false positives\n // and fire repeatedly on every reactive toggle.\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const textEvalMessage: (expr: string) => string;
|
|
2
|
+
export declare const classesEvalMessage = "[PithyJS] \u26A0\uFE0F Failed to evaluate [classes]:";
|
|
3
|
+
export declare const propEvalMessage: (prop: string, expr: string) => string;
|
|
4
|
+
export declare const invalidRenderMessage: (tag: string) => string;
|
|
5
|
+
/** The error a boundary or an SSR crash record receives. */
|
|
6
|
+
export declare const invalidRenderError: (tag: string) => Error;
|
|
7
|
+
//# sourceMappingURL=evalDiagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evalDiagnostics.d.ts","sourceRoot":"","sources":["../../src/compile/evalDiagnostics.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,WACF,CAAC;AAE3C,eAAO,MAAM,kBAAkB,yDAA+C,CAAC;AAE/E,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,MAAM,MAAM,WACI,CAAC;AAE/D,eAAO,MAAM,oBAAoB,GAAI,KAAK,MAAM,WAC6B,CAAC;AAE9E,4DAA4D;AAC5D,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,UAC8B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Shared by the dev and build binders, so both paths word these the same way.
|
|
2
|
+
export const textEvalMessage = (expr) => `[PithyJS] ❌ Error evaluating '${expr}'`;
|
|
3
|
+
export const classesEvalMessage = '[PithyJS] ⚠️ Failed to evaluate [classes]:';
|
|
4
|
+
export const propEvalMessage = (prop, expr) => `[PithyJS] ⚠️ Failed to evaluate prop "${prop}" = "${expr}"`;
|
|
5
|
+
export const invalidRenderMessage = (tag) => `[PithyJS] ❌ Invalid render result from <${tag}>. Expected { el, destroy }`;
|
|
6
|
+
/** The error a boundary or an SSR crash record receives. */
|
|
7
|
+
export const invalidRenderError = (tag) => new Error(`Invalid render result from <${tag}>; expected { el, destroy }`);
|
|
8
|
+
//# sourceMappingURL=evalDiagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evalDiagnostics.js","sourceRoot":"","sources":["../../src/compile/evalDiagnostics.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAE9E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,EAAE,CAC9C,iCAAiC,IAAI,GAAG,CAAC;AAE3C,MAAM,CAAC,MAAM,kBAAkB,GAAG,4CAA4C,CAAC;AAE/E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,EAAE,CAC5D,yCAAyC,IAAI,QAAQ,IAAI,GAAG,CAAC;AAE/D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAE,EAAE,CAClD,2CAA2C,GAAG,6BAA6B,CAAC;AAE9E,4DAA4D;AAC5D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAE,EAAE,CAChD,IAAI,KAAK,CAAC,+BAA+B,GAAG,6BAA6B,CAAC,CAAC","sourcesContent":["// Shared by the dev and build binders, so both paths word these the same way.\n\nexport const textEvalMessage = (expr: string) =>\n `[PithyJS] ❌ Error evaluating '${expr}'`;\n\nexport const classesEvalMessage = '[PithyJS] ⚠️ Failed to evaluate [classes]:';\n\nexport const propEvalMessage = (prop: string, expr: string) =>\n `[PithyJS] ⚠️ Failed to evaluate prop \"${prop}\" = \"${expr}\"`;\n\nexport const invalidRenderMessage = (tag: string) =>\n `[PithyJS] ❌ Invalid render result from <${tag}>. Expected { el, destroy }`;\n\n/** The error a boundary or an SSR crash record receives. */\nexport const invalidRenderError = (tag: string) =>\n new Error(`Invalid render result from <${tag}>; expected { el, destroy }`);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLoopManager.d.ts","sourceRoot":"","sources":["../../../src/compile/forLoops/createLoopManager.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAQjE,OAAO,EACL,WAAW,EAIZ,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"createLoopManager.d.ts","sourceRoot":"","sources":["../../../src/compile/forLoops/createLoopManager.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAQjE,OAAO,EACL,WAAW,EAIZ,MAAM,eAAe,CAAC;AA2HvB,YAAY,EAAE,YAAY,EAAE,CAAC;AAE7B,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9C,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO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