@pithyjs/core 0.1.0-beta.15 → 0.1.0-beta.17

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.
Files changed (77) hide show
  1. package/README.md +4 -0
  2. package/dist/compile/binds/bindBoundAttributes.d.ts +4 -0
  3. package/dist/compile/binds/bindBoundAttributes.d.ts.map +1 -1
  4. package/dist/compile/binds/bindBoundAttributes.js +63 -3
  5. package/dist/compile/binds/bindBoundAttributes.js.map +1 -1
  6. package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -1
  7. package/dist/compile/binds/bindClassDirectives.js +3 -2
  8. package/dist/compile/binds/bindClassDirectives.js.map +1 -1
  9. package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
  10. package/dist/compile/binds/bindComponentsTags.js +15 -1
  11. package/dist/compile/binds/bindComponentsTags.js.map +1 -1
  12. package/dist/compile/binds/bindDefaultTwoWay.d.ts.map +1 -1
  13. package/dist/compile/binds/bindDefaultTwoWay.js +2 -1
  14. package/dist/compile/binds/bindDefaultTwoWay.js.map +1 -1
  15. package/dist/compile/binds/bindDeferDirectives.d.ts.map +1 -1
  16. package/dist/compile/binds/bindDeferDirectives.js +17 -15
  17. package/dist/compile/binds/bindDeferDirectives.js.map +1 -1
  18. package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
  19. package/dist/compile/binds/bindErrorBoundary.js +6 -4
  20. package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
  21. package/dist/compile/binds/bindEventHandlers.d.ts.map +1 -1
  22. package/dist/compile/binds/bindEventHandlers.js +2 -1
  23. package/dist/compile/binds/bindEventHandlers.js.map +1 -1
  24. package/dist/compile/binds/bindRefDirectives.d.ts.map +1 -1
  25. package/dist/compile/binds/bindRefDirectives.js +2 -1
  26. package/dist/compile/binds/bindRefDirectives.js.map +1 -1
  27. package/dist/compile/binds/bindStyleDirectives.d.ts.map +1 -1
  28. package/dist/compile/binds/bindStyleDirectives.js +2 -1
  29. package/dist/compile/binds/bindStyleDirectives.js.map +1 -1
  30. package/dist/compile/binds/bindTextInterpolations.d.ts +2 -1
  31. package/dist/compile/binds/bindTextInterpolations.d.ts.map +1 -1
  32. package/dist/compile/binds/bindTextInterpolations.js +25 -14
  33. package/dist/compile/binds/bindTextInterpolations.js.map +1 -1
  34. package/dist/compile/binds/declaredDirective.d.ts +12 -0
  35. package/dist/compile/binds/declaredDirective.d.ts.map +1 -0
  36. package/dist/compile/binds/declaredDirective.js +42 -0
  37. package/dist/compile/binds/declaredDirective.js.map +1 -0
  38. package/dist/compile/binds/forwardedAttrs.d.ts +4 -2
  39. package/dist/compile/binds/forwardedAttrs.d.ts.map +1 -1
  40. package/dist/compile/binds/forwardedAttrs.js +10 -2
  41. package/dist/compile/binds/forwardedAttrs.js.map +1 -1
  42. package/dist/compile/binds/staleRowProps.d.ts +9 -0
  43. package/dist/compile/binds/staleRowProps.d.ts.map +1 -0
  44. package/dist/compile/binds/staleRowProps.js +86 -0
  45. package/dist/compile/binds/staleRowProps.js.map +1 -0
  46. package/dist/compile/forLoops/loopSignals.d.ts.map +1 -1
  47. package/dist/compile/forLoops/loopSignals.js +15 -1
  48. package/dist/compile/forLoops/loopSignals.js.map +1 -1
  49. package/dist/compile/nodeExpando.d.ts +6 -0
  50. package/dist/compile/nodeExpando.d.ts.map +1 -1
  51. package/dist/compile/nodeExpando.js.map +1 -1
  52. package/dist/compile/pithyTreeToDom.js +1 -0
  53. package/dist/compile/pithyTreeToDom.js.map +1 -1
  54. package/dist/compile/renderChildren.d.ts.map +1 -1
  55. package/dist/compile/renderChildren.js +1 -1
  56. package/dist/compile/renderChildren.js.map +1 -1
  57. package/dist/runtime/applyBindings.d.ts.map +1 -1
  58. package/dist/runtime/applyBindings.js +3 -1
  59. package/dist/runtime/applyBindings.js.map +1 -1
  60. package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
  61. package/dist/runtime/bindings/applyComponent.js +9 -0
  62. package/dist/runtime/bindings/applyComponent.js.map +1 -1
  63. package/dist/runtime/bindings/applyDefer.d.ts.map +1 -1
  64. package/dist/runtime/bindings/applyDefer.js +10 -9
  65. package/dist/runtime/bindings/applyDefer.js.map +1 -1
  66. package/dist/runtime/bindings/applySimple.d.ts +2 -0
  67. package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
  68. package/dist/runtime/bindings/applySimple.js +48 -8
  69. package/dist/runtime/bindings/applySimple.js.map +1 -1
  70. package/dist/runtime/bindings/helpers.d.ts.map +1 -1
  71. package/dist/runtime/bindings/helpers.js +2 -0
  72. package/dist/runtime/bindings/helpers.js.map +1 -1
  73. package/dist/runtime/bindings/index.d.ts +1 -1
  74. package/dist/runtime/bindings/index.d.ts.map +1 -1
  75. package/dist/runtime/bindings/index.js +1 -1
  76. package/dist/runtime/bindings/index.js.map +1 -1
  77. package/package.json +2 -2
@@ -5,6 +5,7 @@
5
5
  "category": "runtime"
6
6
  }
7
7
  */
8
+ import { isDeclaredDirective } from './declaredDirective.js';
8
9
  import { boundaryForElement, setBoundaryError } from './bindErrorBoundary.js';
9
10
  import { nodeExpando } from '../nodeExpando.js';
10
11
  /**
@@ -97,7 +98,7 @@ export function bindEventHandlers(root, rootCtx, disposers) {
97
98
  forEachElement(root, el => {
98
99
  // Iterate attributes once; bind any data-on-* handlers
99
100
  for (const attr of Array.from(el.attributes)) {
100
- if (!attr.name.startsWith('data-on-'))
101
+ if (!attr.name.startsWith('data-on-') || !isDeclaredDirective(attr))
101
102
  continue;
102
103
  const { type: eventName, mods } = parseEventAttr(attr.name);
103
104
  const handlerExpr = attr.value.trim();
@@ -1 +1 @@
1
- {"version":3,"file":"bindEventHandlers.js","sourceRoot":"","sources":["../../../src/compile/binds/bindEventHandlers.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;GAGG;A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AG,CAAC,CAAC;oBAClC,CAAC;yBAAM,CAAC;wBACN,4DAA4D;wBAC5D,MAAM,KAAK,CAAC;oBACd,CAAC;gBACH,CAAC;YACH,CAAC,CAAC;YAEF,kCAAkC;YAClC,MAAM,OAAO,GAAG;gBACd,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO;gBACvB,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO;gBACvB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI;aACS,CAAC;YAE7B,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YAElD,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACvB,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE;gBAClB,yFAAyF;gBACzF,EAAE,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,EAAE;oBAC1C,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO;iBACxB,CAAC,CAAC;gBACH,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.events\",\n \"title\": \"Event Handler Binding System\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { boundaryForElement, setBoundaryError } from './bindErrorBoundary';\nimport { nodeExpando } from '../nodeExpando';\n\n/**\n * Walk up the DOM to find the nearest local PithyJS context attached by loops/components.\n * Falls back to the provided root context.\n */\nfunction nearestCtx(\n el: Element,\n rootCtx: Record<string, unknown>\n): Record<string, unknown> {\n let n: Element | null = el;\n while (n) {\n const local = nodeExpando(n).__pithyCtx;\n if (local) return local;\n n = n.parentElement;\n }\n return rootCtx;\n}\n\ntype Mods = {\n once?: boolean;\n prevent?: boolean;\n stop?: boolean;\n self?: boolean;\n capture?: boolean;\n passive?: boolean;\n};\n\nfunction parseEventAttr(name: string): { type: string; mods: Mods } {\n // \"data-on-click\" or \"data-on-click.once.prevent\"\n const raw = name.slice('data-on-'.length);\n const parts = raw.split('.');\n const type = parts[0];\n const mods: Mods = {};\n for (let i = 1; i < parts.length; i++) {\n const p = parts[i];\n if (p === 'once') mods.once = true;\n else if (p === 'prevent') mods.prevent = true;\n else if (p === 'stop') mods.stop = true;\n else if (p === 'self') mods.self = true;\n else if (p === 'capture') mods.capture = true;\n else if (p === 'passive') mods.passive = true;\n }\n return { type, mods };\n}\n\n/**\n * Per-element, per-event registry of bound expressions,\n * so we don't double-attach listeners when DOM is moved or reprocessed.\n */\nconst BOUND_KEY: unique symbol = Symbol('pithy:bound');\n\nfunction getBoundSet(el: Element, type: string) {\n const host = el as Element & { [BOUND_KEY]?: Record<string, Set<string>> };\n const store =\n host[BOUND_KEY] ??\n (host[BOUND_KEY] = Object.create(null) as Record<string, Set<string>>);\n return (store[type] ??= new Set<string>());\n}\n\n/**\n * Compile an expression so it can see ctx + $event + $el.\n * We intentionally do not use compileExpression here so we can inject $event/$el.\n */\nfunction compileWithEvent(\n expr: string,\n ctx: Record<string, unknown>\n): (ev: Event, el: Element) => unknown {\n try {\n // Build a function that accepts (ctx, $event, $el) and returns the expression result.\n // `with(ctx)` makes identifiers resolve against the provided context object.\n // eslint-disable-next-line no-new-func -- JIT event-handler expression evaluation is a core framework feature\n const fn = new Function(\n 'ctx',\n '$event',\n '$el',\n `with (ctx) { return (${expr}); }`\n ) as (ctx: Record<string, unknown>, ev: Event, el: Element) => unknown;\n return (ev: Event, el: Element) => fn(ctx, ev, el);\n } catch (err) {\n if (import.meta.env?.DEV) {\n console.warn(`[bindEventHandlers] ❌ Failed to compile \"${expr}\"`, err);\n }\n // Return a noop runner\n return (_ev: Event, _el: Element) => undefined;\n }\n}\n\n/**\n * Traverse all elements under `root` (Element or DocumentFragment) using a TreeWalker.\n */\nfunction forEachElement(\n root: Element | DocumentFragment,\n cb: (el: Element) => void\n) {\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);\n let node: Node | null;\n while ((node = walker.nextNode())) {\n cb(node as Element);\n }\n}\n\n/**\n * Binds DOM event handlers within `root`.\n * - Uses nearest element context (e.g., loop item ctx) when present.\n * - Idempotent: won't re-bind the same element/event/expression+modifiers combo.\n * - Supports modifiers: .once .prevent .stop .self .capture .passive\n * - Injects `$event` and `$el` for expression handlers (e.g., @click=\"doThing($event)\")\n */\n/** @codexApi {\"parent\":\"pithy.runtime.events\",\"name\":\"bindEventHandlers\",\"stability\":\"stable\",\"signature\":\"(root: Element | DocumentFragment, rootCtx: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindEventHandlers(\n root: Element | DocumentFragment,\n rootCtx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n forEachElement(root, el => {\n // Iterate attributes once; bind any data-on-* handlers\n for (const attr of Array.from(el.attributes)) {\n if (!attr.name.startsWith('data-on-')) continue;\n\n const { type: eventName, mods } = parseEventAttr(attr.name);\n const handlerExpr = attr.value.trim();\n if (!handlerExpr) continue;\n\n // Idempotency key includes attr name (mods) + expression\n const boundSet = getBoundSet(el, eventName);\n const boundKey = `${attr.name}=${handlerExpr}`;\n if (boundSet.has(boundKey)) continue;\n\n const ctx = nearestCtx(el, rootCtx);\n const isSimpleIdentifier = /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(handlerExpr);\n\n // If the expression is a bare identifier and resolves to a function on ctx,\n // we'll call it directly (browser passes the event), preserving 'this' as ctx.\n const directFn =\n isSimpleIdentifier && typeof ctx[handlerExpr] === 'function'\n ? (ctx[handlerExpr] as EventListener)\n : null;\n\n // Otherwise, compile an event-aware evaluator that can see `$event` & `$el`.\n const runWithEvent = directFn ? null : compileWithEvent(handlerExpr, ctx);\n\n // Final listener with modifiers + $event/$el support + error boundary capture\n const listener: EventListener = (ev: Event) => {\n if (mods.self && ev.target !== el) return;\n if (mods.prevent) ev.preventDefault();\n if (mods.stop) ev.stopPropagation();\n\n try {\n if (directFn) {\n // Call the function from ctx with ctx as 'this'\n return directFn.call(ctx, ev);\n } else if (runWithEvent) {\n const out = runWithEvent(ev, el);\n // If expression returns a function, treat that as a handler and pass the event\n if (typeof out === 'function') {\n return (out as (e: Event) => unknown).call(ctx, ev);\n }\n return out;\n }\n } catch (error) {\n // Find the nearest error boundary and set its error signal with escalation\n const boundaryEl = el.closest('[data-error]') as Element | null;\n const boundary = boundaryForElement(boundaryEl);\n if (boundary) {\n const err =\n error instanceof Error ? error : new Error(String(error));\n setBoundaryError(boundary, err);\n } else {\n // No boundary found, re-throw to maintain original behavior\n throw error;\n }\n }\n };\n\n // Attach with appropriate options\n const options = {\n capture: !!mods.capture,\n passive: !!mods.passive,\n once: !!mods.once,\n } as AddEventListenerOptions;\n\n el.addEventListener(eventName, listener, options);\n\n boundSet.add(boundKey);\n disposers.push(() => {\n // Note: removeEventListener only considers `capture`; `once`/`passive` are ignored here.\n el.removeEventListener(eventName, listener, {\n capture: !!mods.capture,\n });\n boundSet.delete(boundKey);\n });\n }\n });\n}\n"]}
1
+ {"version":3,"file":"bindEventHandlers.js","sourceRoot":"","sources":["../../../src/compile/binds/bindEventHandlers.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;GAGG;AACH,SAAS,UAAU,CACjB,EAAW,EACX,OAAgC;IAEhC,IAAI,CAAC,GAAmB,EAAE,CAAC;IAC3B,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;QACxC,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;QACxB,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC;IACtB,CAAC;IACD,OAAO,OAAO,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AC,OAAO;gBACvB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI;aACS,CAAC;YAE7B,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YAElD,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACvB,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE;gBAClB,yFAAyF;gBACzF,EAAE,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,EAAE;oBAC1C,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO;iBACxB,CAAC,CAAC;gBACH,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.events\",\n \"title\": \"Event Handler Binding System\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { isDeclaredDirective } from './declaredDirective';\nimport { boundaryForElement, setBoundaryError } from './bindErrorBoundary';\nimport { nodeExpando } from '../nodeExpando';\n\n/**\n * Walk up the DOM to find the nearest local PithyJS context attached by loops/components.\n * Falls back to the provided root context.\n */\nfunction nearestCtx(\n el: Element,\n rootCtx: Record<string, unknown>\n): Record<string, unknown> {\n let n: Element | null = el;\n while (n) {\n const local = nodeExpando(n).__pithyCtx;\n if (local) return local;\n n = n.parentElement;\n }\n return rootCtx;\n}\n\ntype Mods = {\n once?: boolean;\n prevent?: boolean;\n stop?: boolean;\n self?: boolean;\n capture?: boolean;\n passive?: boolean;\n};\n\nfunction parseEventAttr(name: string): { type: string; mods: Mods } {\n // \"data-on-click\" or \"data-on-click.once.prevent\"\n const raw = name.slice('data-on-'.length);\n const parts = raw.split('.');\n const type = parts[0];\n const mods: Mods = {};\n for (let i = 1; i < parts.length; i++) {\n const p = parts[i];\n if (p === 'once') mods.once = true;\n else if (p === 'prevent') mods.prevent = true;\n else if (p === 'stop') mods.stop = true;\n else if (p === 'self') mods.self = true;\n else if (p === 'capture') mods.capture = true;\n else if (p === 'passive') mods.passive = true;\n }\n return { type, mods };\n}\n\n/**\n * Per-element, per-event registry of bound expressions,\n * so we don't double-attach listeners when DOM is moved or reprocessed.\n */\nconst BOUND_KEY: unique symbol = Symbol('pithy:bound');\n\nfunction getBoundSet(el: Element, type: string) {\n const host = el as Element & { [BOUND_KEY]?: Record<string, Set<string>> };\n const store =\n host[BOUND_KEY] ??\n (host[BOUND_KEY] = Object.create(null) as Record<string, Set<string>>);\n return (store[type] ??= new Set<string>());\n}\n\n/**\n * Compile an expression so it can see ctx + $event + $el.\n * We intentionally do not use compileExpression here so we can inject $event/$el.\n */\nfunction compileWithEvent(\n expr: string,\n ctx: Record<string, unknown>\n): (ev: Event, el: Element) => unknown {\n try {\n // Build a function that accepts (ctx, $event, $el) and returns the expression result.\n // `with(ctx)` makes identifiers resolve against the provided context object.\n // eslint-disable-next-line no-new-func -- JIT event-handler expression evaluation is a core framework feature\n const fn = new Function(\n 'ctx',\n '$event',\n '$el',\n `with (ctx) { return (${expr}); }`\n ) as (ctx: Record<string, unknown>, ev: Event, el: Element) => unknown;\n return (ev: Event, el: Element) => fn(ctx, ev, el);\n } catch (err) {\n if (import.meta.env?.DEV) {\n console.warn(`[bindEventHandlers] ❌ Failed to compile \"${expr}\"`, err);\n }\n // Return a noop runner\n return (_ev: Event, _el: Element) => undefined;\n }\n}\n\n/**\n * Traverse all elements under `root` (Element or DocumentFragment) using a TreeWalker.\n */\nfunction forEachElement(\n root: Element | DocumentFragment,\n cb: (el: Element) => void\n) {\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);\n let node: Node | null;\n while ((node = walker.nextNode())) {\n cb(node as Element);\n }\n}\n\n/**\n * Binds DOM event handlers within `root`.\n * - Uses nearest element context (e.g., loop item ctx) when present.\n * - Idempotent: won't re-bind the same element/event/expression+modifiers combo.\n * - Supports modifiers: .once .prevent .stop .self .capture .passive\n * - Injects `$event` and `$el` for expression handlers (e.g., @click=\"doThing($event)\")\n */\n/** @codexApi {\"parent\":\"pithy.runtime.events\",\"name\":\"bindEventHandlers\",\"stability\":\"stable\",\"signature\":\"(root: Element | DocumentFragment, rootCtx: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindEventHandlers(\n root: Element | DocumentFragment,\n rootCtx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n forEachElement(root, el => {\n // Iterate attributes once; bind any data-on-* handlers\n for (const attr of Array.from(el.attributes)) {\n if (!attr.name.startsWith('data-on-') || !isDeclaredDirective(attr))\n continue;\n\n const { type: eventName, mods } = parseEventAttr(attr.name);\n const handlerExpr = attr.value.trim();\n if (!handlerExpr) continue;\n\n // Idempotency key includes attr name (mods) + expression\n const boundSet = getBoundSet(el, eventName);\n const boundKey = `${attr.name}=${handlerExpr}`;\n if (boundSet.has(boundKey)) continue;\n\n const ctx = nearestCtx(el, rootCtx);\n const isSimpleIdentifier = /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(handlerExpr);\n\n // If the expression is a bare identifier and resolves to a function on ctx,\n // we'll call it directly (browser passes the event), preserving 'this' as ctx.\n const directFn =\n isSimpleIdentifier && typeof ctx[handlerExpr] === 'function'\n ? (ctx[handlerExpr] as EventListener)\n : null;\n\n // Otherwise, compile an event-aware evaluator that can see `$event` & `$el`.\n const runWithEvent = directFn ? null : compileWithEvent(handlerExpr, ctx);\n\n // Final listener with modifiers + $event/$el support + error boundary capture\n const listener: EventListener = (ev: Event) => {\n if (mods.self && ev.target !== el) return;\n if (mods.prevent) ev.preventDefault();\n if (mods.stop) ev.stopPropagation();\n\n try {\n if (directFn) {\n // Call the function from ctx with ctx as 'this'\n return directFn.call(ctx, ev);\n } else if (runWithEvent) {\n const out = runWithEvent(ev, el);\n // If expression returns a function, treat that as a handler and pass the event\n if (typeof out === 'function') {\n return (out as (e: Event) => unknown).call(ctx, ev);\n }\n return out;\n }\n } catch (error) {\n // Find the nearest error boundary and set its error signal with escalation\n const boundaryEl = el.closest('[data-error]') as Element | null;\n const boundary = boundaryForElement(boundaryEl);\n if (boundary) {\n const err =\n error instanceof Error ? error : new Error(String(error));\n setBoundaryError(boundary, err);\n } else {\n // No boundary found, re-throw to maintain original behavior\n throw error;\n }\n }\n };\n\n // Attach with appropriate options\n const options = {\n capture: !!mods.capture,\n passive: !!mods.passive,\n once: !!mods.once,\n } as AddEventListenerOptions;\n\n el.addEventListener(eventName, listener, options);\n\n boundSet.add(boundKey);\n disposers.push(() => {\n // Note: removeEventListener only considers `capture`; `once`/`passive` are ignored here.\n el.removeEventListener(eventName, listener, {\n capture: !!mods.capture,\n });\n boundSet.delete(boundKey);\n });\n }\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"bindRefDirectives.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindRefDirectives.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,0NAA0N;AAC1N,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,OAAO,GAAG,gBAAgB,EACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAyBN"}
1
+ {"version":3,"file":"bindRefDirectives.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindRefDirectives.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AAEH,0NAA0N;AAC1N,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,OAAO,GAAG,gBAAgB,EACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CA0BN"}
@@ -1,3 +1,4 @@
1
+ import { isDeclaredDirective } from './declaredDirective.js';
1
2
  /**
2
3
  * Binds ref directives to DOM elements using [data-ref] attributes.
3
4
  *
@@ -13,7 +14,7 @@
13
14
  export function bindRefDirectives(fragment, context, disposers) {
14
15
  fragment.querySelectorAll('[data-ref]').forEach(el => {
15
16
  Array.from(el.attributes).forEach(attr => {
16
- if (!attr.name.startsWith('data-ref'))
17
+ if (!attr.name.startsWith('data-ref') || !isDeclaredDirective(attr))
17
18
  return;
18
19
  const refName = attr.value;
19
20
  // Skip empty refs
@@ -1 +1 @@
1
- {"version":3,"file":"bindRefDirectives.js","sourceRoot":"","sources":["../../../src/compile/binds/bindRefDirectives.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,0NAA0N;AAC1N,MAAM,UAAU,iBAAiB,CAC/B,QAAoC,EACpC,OAAgC,EAChC,SAAyB;IAEzB,QAAQ,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QACnD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACvC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;gBAAE,OAAO;YAE9C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC;YAE3B,kBAAkB;YAClB,IAAI,CAAC,OAAO;gBAAE,OAAO;YAErB,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAmB,CAAC;YAE/C,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;gBACzC,gCAAgC;gBAChC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBAEZ,qEAAqE;gBACrE,mEAAmE;gBACnE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAE9B,qCAAqC;gBACrC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;YACtC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Ref } from '../../interfaces/ref.interface';\n\n/**\n * Binds ref directives to DOM elements using [data-ref] attributes.\n *\n * This function handles element references by binding elements with [data-ref]\n * attributes to their corresponding Ref objects in the context. It automatically\n * sets up cleanup when elements are removed.\n *\n * @param fragment - The root DOM node to search for ref directives\n * @param context - Context object containing Ref objects for element references\n * @param disposers - Array to collect cleanup functions that clear references\n */\n\n/** @codexApi {\"parent\":\"pithy.feature.refs\",\"name\":\"bindRefDirectives\",\"stability\":\"stable\",\"signature\":\"(fragment: Element | DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindRefDirectives(\n fragment: Element | DocumentFragment,\n context: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n fragment.querySelectorAll('[data-ref]').forEach(el => {\n Array.from(el.attributes).forEach(attr => {\n if (!attr.name.startsWith('data-ref')) return;\n\n const refName = attr.value;\n\n // Skip empty refs\n if (!refName) return;\n\n const ref = context[refName] as Ref<typeof el>;\n\n if (ref && typeof ref.set === 'function') {\n // Set the reference immediately\n ref.set(el);\n\n // Consume the attribute so a re-scan from an ancestor pipeline can't\n // re-bind this element against another component's same-named ref.\n el.removeAttribute(attr.name);\n\n // Add cleanup to the disposers array\n disposers.push(() => ref.set(null));\n }\n });\n });\n}\n"]}
1
+ {"version":3,"file":"bindRefDirectives.js","sourceRoot":"","sources":["../../../src/compile/binds/bindRefDirectives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D;;;;;;;;;;GAUG;AAEH,0NAA0N;AAC1N,MAAM,UAAU,iBAAiB,CAC/B,QAAoC,EACpC,OAAgC,EAChC,SAAyB;IAEzB,QAAQ,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QACnD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACvC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC;gBACjE,OAAO;YAET,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC;YAE3B,kBAAkB;YAClB,IAAI,CAAC,OAAO;gBAAE,OAAO;YAErB,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAmB,CAAC;YAE/C,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;gBACzC,gCAAgC;gBAChC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBAEZ,qEAAqE;gBACrE,mEAAmE;gBACnE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAE9B,qCAAqC;gBACrC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;YACtC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { isDeclaredDirective } from './declaredDirective';\nimport type { Ref } from '../../interfaces/ref.interface';\n\n/**\n * Binds ref directives to DOM elements using [data-ref] attributes.\n *\n * This function handles element references by binding elements with [data-ref]\n * attributes to their corresponding Ref objects in the context. It automatically\n * sets up cleanup when elements are removed.\n *\n * @param fragment - The root DOM node to search for ref directives\n * @param context - Context object containing Ref objects for element references\n * @param disposers - Array to collect cleanup functions that clear references\n */\n\n/** @codexApi {\"parent\":\"pithy.feature.refs\",\"name\":\"bindRefDirectives\",\"stability\":\"stable\",\"signature\":\"(fragment: Element | DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindRefDirectives(\n fragment: Element | DocumentFragment,\n context: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n fragment.querySelectorAll('[data-ref]').forEach(el => {\n Array.from(el.attributes).forEach(attr => {\n if (!attr.name.startsWith('data-ref') || !isDeclaredDirective(attr))\n return;\n\n const refName = attr.value;\n\n // Skip empty refs\n if (!refName) return;\n\n const ref = context[refName] as Ref<typeof el>;\n\n if (ref && typeof ref.set === 'function') {\n // Set the reference immediately\n ref.set(el);\n\n // Consume the attribute so a re-scan from an ancestor pipeline can't\n // re-bind this element against another component's same-named ref.\n el.removeAttribute(attr.name);\n\n // Add cleanup to the disposers array\n disposers.push(() => ref.set(null));\n }\n });\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"bindStyleDirectives.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindStyleDirectives.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAOF,mMAAmM;AACnM;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,OAAO,EACX,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAwBN;AAMD,0KAA0K;AAC1K,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAAE,GACjB,MAAM,GAAG,SAAS,CAGpB"}
1
+ {"version":3,"file":"bindStyleDirectives.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindStyleDirectives.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAQF,mMAAmM;AACnM;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,OAAO,EACX,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAwBN;AAMD,0KAA0K;AAC1K,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAAE,GACjB,MAAM,GAAG,SAAS,CAGpB"}
@@ -5,6 +5,7 @@
5
5
  "category": "runtime"
6
6
  }
7
7
  */
8
+ import { isDeclaredDirective } from './declaredDirective.js';
8
9
  import { applyStyle } from '../../runtime/bindings/applySimple.js';
9
10
  import { nodeExpando } from '../nodeExpando.js';
10
11
  const PREFIX = 'data-style-';
@@ -25,7 +26,7 @@ export function bindStyleProperties(el, ctx, disposers) {
25
26
  ...Object.keys(expando.__pithyNode?.directives?.styleMap ?? {}),
26
27
  ]);
27
28
  const prop = declaredName(attr.name.slice(PREFIX.length), declared);
28
- if (!prop)
29
+ if (!prop || !isDeclaredDirective(attr))
29
30
  continue;
30
31
  el.removeAttribute(attr.name);
31
32
  applyStyle({
@@ -1 +1 @@
1
- {"version":3,"file":"bindStyleDirectives.js","sourceRoot":"","sources":["../../../src/compile/binds/bindStyleDirectives.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,MAAM,GAAG,aAAa,CAAC;AAE7B,mMAAmM;AACnM;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,EAAW,EACX,GAA4B,EAC5B,SAAyB;IAEzB,IAAI,QAA8B,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;YAAE,SAAS;QAC5C,MAAM,OAAO,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;QAChC,QAAQ,KAAR,QAAQ,GAAK;YACX,GAAG,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;YAC/B,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,EAAE,QAAQ,IAAI,EAAE,CAAC;SAChE,EAAC;QACF,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC;QACpE,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9B,UAAU,CACR;YACE,CAAC,EAAE,OAAO;YACV,GAAG,EAAE,EAAE;YACP,IAAI;YACJ,IAAI,EAAE,IAAI,CAAC,KAAK;SACjB,EACD,EAAE,EACF,GAAG,EACH,SAAS,CACV,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAE5E,0EAA0E;AAC1E,+DAA+D;AAC/D,0KAA0K;AAC1K,MAAM,UAAU,YAAY,CAC1B,QAAgB,EAChB,QAAkB;IAElB,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IACnC,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC;AACrD,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.styles\",\n \"title\": \"Style Directive Binding\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { applyStyle } from '../../runtime/bindings/applySimple';\nimport { nodeExpando } from '../nodeExpando';\n\nconst PREFIX = 'data-style-';\n\n/** @codexApi {\"parent\":\"pithy.runtime.styles\",\"name\":\"bindStyleProperties\",\"stability\":\"internal\",\"signature\":\"(el: Element, ctx: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\n/**\n * Binds `[style.prop]=\"expr\"`, which the parser emits as `data-style-prop`,\n * through the same `applyStyle` a build uses. Only names the element declared\n * are bound; an author's own `data-style-*` attribute is left alone.\n */\nexport function bindStyleProperties(\n el: Element,\n ctx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n let declared: string[] | undefined;\n for (const attr of Array.from(el.attributes)) {\n if (!attr.name.startsWith(PREFIX)) continue;\n const expando = nodeExpando(el);\n declared ??= [\n ...(expando.__styleProps ?? []),\n ...Object.keys(expando.__pithyNode?.directives?.styleMap ?? {}),\n ];\n const prop = declaredName(attr.name.slice(PREFIX.length), declared);\n if (!prop) continue;\n el.removeAttribute(attr.name);\n applyStyle(\n {\n t: 'style',\n pid: '',\n prop,\n expr: attr.value,\n },\n el,\n ctx,\n disposers\n );\n }\n}\n\nconst asciiLower = (s: string) => s.replace(/[A-Z]/g, c => c.toLowerCase());\n\n// HTML lowercases an attribute name and SVG keeps it, both ASCII only, so\n// match the same way: toLowerCase() would merge `Öl` and `öl`.\n/** @codexApi {\"parent\":\"pithy.runtime.styles\",\"name\":\"declaredName\",\"stability\":\"internal\",\"signature\":\"(attrName: string, declared: string[]) => string | undefined\"} */\nexport function declaredName(\n attrName: string,\n declared: string[]\n): string | undefined {\n const lower = asciiLower(attrName);\n return declared.find(d => asciiLower(d) === lower);\n}\n"]}
1
+ {"version":3,"file":"bindStyleDirectives.js","sourceRoot":"","sources":["../../../src/compile/binds/bindStyleDirectives.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,MAAM,GAAG,aAAa,CAAC;AAE7B,mMAAmM;AACnM;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,EAAW,EACX,GAA4B,EAC5B,SAAyB;IAEzB,IAAI,QAA8B,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7C,IAAI,CAAC,IAAI,CAAC,I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n \"category\": \"runtime\"\n}\n*/\n\nimport { isDeclaredDirective } from './declaredDirective';\nimport { applyStyle } from '../../runtime/bindings/applySimple';\nimport { nodeExpando } from '../nodeExpando';\n\nconst PREFIX = 'data-style-';\n\n/** @codexApi {\"parent\":\"pithy.runtime.styles\",\"name\":\"bindStyleProperties\",\"stability\":\"internal\",\"signature\":\"(el: Element, ctx: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\n/**\n * Binds `[style.prop]=\"expr\"`, which the parser emits as `data-style-prop`,\n * through the same `applyStyle` a build uses. Only names the element declared\n * are bound; an author's own `data-style-*` attribute is left alone.\n */\nexport function bindStyleProperties(\n el: Element,\n ctx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n let declared: string[] | undefined;\n for (const attr of Array.from(el.attributes)) {\n if (!attr.name.startsWith(PREFIX)) continue;\n const expando = nodeExpando(el);\n declared ??= [\n ...(expando.__styleProps ?? []),\n ...Object.keys(expando.__pithyNode?.directives?.styleMap ?? {}),\n ];\n const prop = declaredName(attr.name.slice(PREFIX.length), declared);\n if (!prop || !isDeclaredDirective(attr)) continue;\n el.removeAttribute(attr.name);\n applyStyle(\n {\n t: 'style',\n pid: '',\n prop,\n expr: attr.value,\n },\n el,\n ctx,\n disposers\n );\n }\n}\n\nconst asciiLower = (s: string) => s.replace(/[A-Z]/g, c => c.toLowerCase());\n\n// HTML lowercases an attribute name and SVG keeps it, both ASCII only, so\n// match the same way: toLowerCase() would merge `Öl` and `öl`.\n/** @codexApi {\"parent\":\"pithy.runtime.styles\",\"name\":\"declaredName\",\"stability\":\"internal\",\"signature\":\"(attrName: string, declared: string[]) => string | undefined\"} */\nexport function declaredName(\n attrName: string,\n declared: string[]\n): string | undefined {\n const lower = asciiLower(attrName);\n return declared.find(d => asciiLower(d) === lower);\n}\n"]}
@@ -7,11 +7,12 @@
7
7
  */
8
8
  /**
9
9
  * Bind all text interpolations (e.g. "Hello {{name()}}") under `root`.
10
+ * - Binds only text still as the template parser created it.
10
11
  * - Skips nested-loop subtrees (tagged with __pithySkipText) and real @for/data-for hosts.
11
12
  * - Skips DOM a component rendered (__pithyComponentDom); the component bound it itself.
12
13
  * - Binds per-text-node updates with fine-grained effects.
13
14
  */
14
15
  /** @codexApi {"parent":"pithy.runtime.interpolations","name":"bindTextInterpolations","stability":"stable","signature":"(root: Element | DocumentFragment, ctx: Record<string, unknown>, disposers: (() => void)[]) => void"} */
15
- export declare function bindTextInterpolations(root: Element | DocumentFragment, ctx: Record<string, unknown>, disposers: (() => void)[]): void;
16
+ export declare function bindTextInterpolations(root: Element | DocumentFragment, _ctx: Record<string, unknown>, disposers: (() => void)[]): void;
16
17
  export declare function flashUpdate(node: Text | Element): void;
17
18
  //# sourceMappingURL=bindTextInterpolations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bindTextInterpolations.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindTextInterpolations.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAWF;;;;;GAKG;AACH,iOAAiO;AACjO,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAChC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAGN;AAiVD,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,GAAG,IAAI,CActD"}
1
+ {"version":3,"file":"bindTextInterpolations.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindTextInterpolations.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAWF;;;;;;GAMG;AACH,iOAAiO;AACjO,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAGN;AAkVD,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,GAAG,IAAI,CActD"}
@@ -14,14 +14,15 @@ import { nodeExpando } from '../nodeExpando.js';
14
14
  const INTERPOLATION_RE = /{{\s*([\s\S]*?)\s*}}/g;
15
15
  /**
16
16
  * Bind all text interpolations (e.g. "Hello {{name()}}") under `root`.
17
+ * - Binds only text still as the template parser created it.
17
18
  * - Skips nested-loop subtrees (tagged with __pithySkipText) and real @for/data-for hosts.
18
19
  * - Skips DOM a component rendered (__pithyComponentDom); the component bound it itself.
19
20
  * - Binds per-text-node updates with fine-grained effects.
20
21
  */
21
22
  /** @codexApi {"parent":"pithy.runtime.interpolations","name":"bindTextInterpolations","stability":"stable","signature":"(root: Element | DocumentFragment, ctx: Record<string, unknown>, disposers: (() => void)[]) => void"} */
22
- export function bindTextInterpolations(root, ctx, disposers) {
23
- processChildNodes(root, ctx, disposers);
24
- bindRemainingTextInterpolations(root, ctx, disposers);
23
+ export function bindTextInterpolations(root, _ctx, disposers) {
24
+ processChildNodes(root, disposers);
25
+ bindRemainingTextInterpolations(root, disposers);
25
26
  }
26
27
  /* -----------------------------------------------------------------------------
27
28
  * Internal: robust child iteration (Element | DocumentFragment)
@@ -42,7 +43,7 @@ function childElementsOf(root) {
42
43
  * We purposely avoid stepping into nested-loop subtrees to prevent compiling
43
44
  * expressions like {{ item() }} against the parent context.
44
45
  */
45
- function processChildNodes(root, ctx, disposers) {
46
+ function processChildNodes(root, disposers) {
46
47
  for (const child of childElementsOf(root)) {
47
48
  // Fast-path: if the child itself is a loop host, we skip it entirely.
48
49
  if (child.hasAttribute?.('@for') ||
@@ -53,8 +54,7 @@ function processChildNodes(root, ctx, disposers) {
53
54
  const targets = [];
54
55
  let textNode;
55
56
  while ((textNode = walker.nextNode())) {
56
- const rawText = textNode?.nodeValue || '';
57
- if (!rawText.includes('{{'))
57
+ if (!isTemplateText(textNode))
58
58
  continue;
59
59
  // Skip anything inside a nested loop host or explicit @for/data-for
60
60
  if (isInsideSkippedZone(textNode, root))
@@ -63,17 +63,20 @@ function processChildNodes(root, ctx, disposers) {
63
63
  }
64
64
  // Mutate after collecting to avoid invalidating the walker during traversal.
65
65
  for (const node of targets) {
66
+ // An earlier interpolation in this loop can write into a queued node.
67
+ if (!isTemplateText(node))
68
+ continue;
66
69
  const rawText = node.nodeValue || '';
67
70
  const parts = parseTextIntoParts(rawText);
68
71
  const parent = node.parentElement;
69
72
  const nextSibling = node.nextSibling;
70
73
  if (!parent)
71
74
  continue;
72
- // Use the node's own __pithyCtx when available (set by pithyTreeToDom).
75
+ // Use the node's own __pithyCtx (set by pithyTreeToDom).
73
76
  // Projected slot content carries the *parent* component's context this way,
74
- // while the passed `ctx` is the *child* component's context.
77
+ // not the context of the component whose template holds the slot.
75
78
  // This mirrors the nearestCtx pattern used by bindEventHandlers.
76
- const nodeCtx = nodeExpando(node).__pithyCtx || ctx;
79
+ const nodeCtx = nodeExpando(node).__pithyCtx;
77
80
  parent.removeChild(node);
78
81
  for (const part of parts) {
79
82
  if (part.type === 'static') {
@@ -110,13 +113,13 @@ function processChildNodes(root, ctx, disposers) {
110
113
  * Second pass: text nodes directly under `root` (e.g., loose text, or nodes
111
114
  * not caught by processChildNodes). Also respects skip zones.
112
115
  */
113
- function bindRemainingTextInterpolations(root, ctx, disposers) {
116
+ function bindRemainingTextInterpolations(root, disposers) {
114
117
  const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
115
118
  let node;
116
119
  while ((node = walker.nextNode())) {
117
- const rawText = node?.nodeValue;
118
- if (!rawText || !rawText.includes('{{'))
120
+ if (!isTemplateText(node))
119
121
  continue;
122
+ const rawText = node.nodeValue;
120
123
  // Robust skip: private flag, @for, or data-for anywhere up the chain.
121
124
  if (isInsideSkippedZone(node, root))
122
125
  continue;
@@ -124,9 +127,11 @@ function bindRemainingTextInterpolations(root, ctx, disposers) {
124
127
  const matches = [...rawText.matchAll(INTERPOLATION_RE)];
125
128
  if (matches.length === 0)
126
129
  continue;
127
- // Use the node's own __pithyCtx when available (projected slot content
130
+ // Use the node's own __pithyCtx (projected slot content
128
131
  // carries the parent component's context via this property).
129
- const nodeCtx = nodeExpando(node).__pithyCtx || ctx;
132
+ const nodeCtx = nodeExpando(node).__pithyCtx;
133
+ // The node keeps its identity and now holds a value: an outer pass must not read it.
134
+ nodeExpando(node).__pithyCtx = undefined;
130
135
  const renderFns = [];
131
136
  const matchStrings = [];
132
137
  const expressions = [];
@@ -400,6 +405,12 @@ function parseTextIntoParts(rawText) {
400
405
  }
401
406
  return parts;
402
407
  }
408
+ function isTemplateText(node) {
409
+ const { __pithyCtx, __pithyNode } = nodeExpando(node);
410
+ return (__pithyCtx !== undefined &&
411
+ __pithyNode?.textContent === node.nodeValue &&
412
+ !!node.nodeValue?.includes('{{'));
413
+ }
403
414
  /**
404
415
  * Is the expression a signal call? (e.g., count(), user.tags())
405
416
  * We compile the callee (without "()") and ask isSignal() on the result.
@@ -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,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAEjD;;;;;GAKG;AACH,iOAAiO;AACjO,MAAM,UAAU,sBAAsB,CACpC,IAAgC,EAChC,GAA4B,EAC5B,SAAyB;IAEzB,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;IACxC,+BAA+B,CAAC,IA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,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAC/C,MAAM,UAAU,GAAG,iBAAiB,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;QACxD,MAAM,cAAc,GAAG,UAAU,EAAE,CAAC;QACpC,OAAO,QAAQ,CAAC,cAAc,CAAC,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB,CAC1B,IAAU,EACV,IAAgC;IAEhC,IAAI,WAAW,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 { 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 * - 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, ctx, disposers);\n bindRemainingTextInterpolations(root, ctx, 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 ctx: Record<string, unknown>,\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 const rawText = textNode?.nodeValue || '';\n if (!rawText.includes('{{')) 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 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 when available (set by pithyTreeToDom).\n // Projected slot content carries the *parent* component's context this way,\n // while the passed `ctx` is the *child* component's context.\n // This mirrors the nearestCtx pattern used by bindEventHandlers.\n const nodeCtx = nodeExpando(node).__pithyCtx || ctx;\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 ctx: Record<string, unknown>,\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 const rawText = node?.nodeValue;\n if (!rawText || !rawText.includes('{{')) continue;\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 when available (projected slot content\n // carries the parent component's context via this property).\n const nodeCtx = nodeExpando(node).__pithyCtx || ctx;\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\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,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAEjD;;;;;;GAMG;AACH,iOAAiO;AACjO,MAAM,UAAU,sBAAsB,CACpC,IAAgC,EAChC,IAA6B,EAC7B,SAAyB;IAEzB,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACnC,+BAA+B,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AACnD,CAAC;AAED;;gFAEgF;AAChF,SAAS,eAAe,CAAC,IAAgC;IACvD,IAAI,IAAI,YAAY,OAAO;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9D,yEAAyE;IACzE,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QAC1B,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY;YAAE,GAAG,CAAC,IAAI,CAAC,CAAY,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IACH,OAAO,GAAG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,CAAC,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB,CAC1B,IAAU,EACV,IAAgC;IAEhC,IAAI,WAAW,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 { 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"]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Whether a directive attribute holds what a template wrote. A binder may
3
+ * compile the value only then: `[data-on-click]` or a component can put data
4
+ * into the same attribute, and a nested pass sees it. The value is compared
5
+ * as well as the name, since such a write can replace a declared directive.
6
+ */
7
+ export declare function isDeclaredDirective(attr: Attr): boolean;
8
+ /** Whether a template wrote this attribute as a plain, unbound attribute. */
9
+ export declare function isTemplateAttr({ name, value, ownerElement }: Attr): boolean;
10
+ /** The value of `name` on `el`, if a template wrote it. */
11
+ export declare function declaredValue(el: Element, name: string): string | undefined;
12
+ //# sourceMappingURL=declaredDirective.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaredDirective.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/declaredDirective.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAgBvD;AAED,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,IAAI,GAAG,OAAO,CAG3E;AAED,2DAA2D;AAC3D,wBAAgB,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG3E"}
@@ -0,0 +1,42 @@
1
+ import { forEachDirectiveAttr } from '@pithyjs/compiler';
2
+ import { nodeExpando } from '../nodeExpando.js';
3
+ const asciiLower = (s) => s.replace(/[A-Z]/g, c => c.toLowerCase());
4
+ /**
5
+ * Whether a directive attribute holds what a template wrote. A binder may
6
+ * compile the value only then: `[data-on-click]` or a component can put data
7
+ * into the same attribute, and a nested pass sees it. The value is compared
8
+ * as well as the name, since such a write can replace a declared directive.
9
+ */
10
+ export function isDeclaredDirective(attr) {
11
+ const { name, value, ownerElement: el } = attr;
12
+ if (!el)
13
+ return false;
14
+ const expando = nodeExpando(el);
15
+ if (expando.__forwardedDirectives?.get(name) === value)
16
+ return true;
17
+ const node = expando.__pithyNode;
18
+ if (!node)
19
+ return false;
20
+ if (isTemplateAttr(attr))
21
+ return true;
22
+ let declared = false;
23
+ if (node.directives) {
24
+ const lower = asciiLower(name);
25
+ forEachDirectiveAttr(node.directives, (attrName, expr) => {
26
+ if (expr === value && asciiLower(attrName) === lower)
27
+ declared = true;
28
+ });
29
+ }
30
+ return declared;
31
+ }
32
+ /** Whether a template wrote this attribute as a plain, unbound attribute. */
33
+ export function isTemplateAttr({ name, value, ownerElement }) {
34
+ const attrs = ownerElement && nodeExpando(ownerElement).__pithyNode?.attrs;
35
+ return attrs?.[name] === value || attrs?.[asciiLower(name)] === value;
36
+ }
37
+ /** The value of `name` on `el`, if a template wrote it. */
38
+ export function declaredValue(el, name) {
39
+ const attr = el.getAttributeNode(name);
40
+ return attr && isDeclaredDirective(attr) ? attr.value : undefined;
41
+ }
42
+ //# sourceMappingURL=declaredDirective.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declaredDirective.js","sourceRoot":"","sources":["../../../src/compile/binds/declaredDirective.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAE5E;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAU;IAC5C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC;IAC/C,IAAI,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CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACpE,CAAC","sourcesContent":["import { forEachDirectiveAttr } from '@pithyjs/compiler';\nimport { nodeExpando } from '../nodeExpando';\n\nconst asciiLower = (s: string) => s.replace(/[A-Z]/g, c => c.toLowerCase());\n\n/**\n * Whether a directive attribute holds what a template wrote. A binder may\n * compile the value only then: `[data-on-click]` or a component can put data\n * into the same attribute, and a nested pass sees it. The value is compared\n * as well as the name, since such a write can replace a declared directive.\n */\nexport function isDeclaredDirective(attr: Attr): boolean {\n const { name, value, ownerElement: el } = attr;\n if (!el) return false;\n const expando = nodeExpando(el);\n if (expando.__forwardedDirectives?.get(name) === value) return true;\n const node = expando.__pithyNode;\n if (!node) return false;\n if (isTemplateAttr(attr)) return true;\n let declared = false;\n if (node.directives) {\n const lower = asciiLower(name);\n forEachDirectiveAttr(node.directives, (attrName, expr) => {\n if (expr === value && asciiLower(attrName) === lower) declared = true;\n });\n }\n return declared;\n}\n\n/** Whether a template wrote this attribute as a plain, unbound attribute. */\nexport function isTemplateAttr({ name, value, ownerElement }: Attr): boolean {\n const attrs = ownerElement && nodeExpando(ownerElement).__pithyNode?.attrs;\n return attrs?.[name] === value || attrs?.[asciiLower(name)] === value;\n}\n\n/** The value of `name` on `el`, if a template wrote it. */\nexport function declaredValue(el: Element, name: string): string | undefined {\n const attr = el.getAttributeNode(name);\n return attr && isDeclaredDirective(attr) ? attr.value : undefined;\n}\n"]}
@@ -6,7 +6,9 @@
6
6
  }
7
7
  */
8
8
  /** Collect the `data-*` attributes to carry from a component tag to its rendered root. */
9
- export declare function collectForwardedAttrs(el: Element): Array<[string, string]>;
9
+ export declare function collectForwardedAttrs(el: Element): ForwardedAttr[];
10
+ /** Name, value, and whether the tag's template wrote that value. */
11
+ export type ForwardedAttr = [name: string, value: string, declared: boolean];
10
12
  /**
11
13
  * Write collected attributes onto the rendered root.
12
14
  *
@@ -18,5 +20,5 @@ export declare function collectForwardedAttrs(el: Element): Array<[string, strin
18
20
  *
19
21
  * Shared by both binders so the two paths cannot drift.
20
22
  */
21
- export declare function applyForwardedAttrs(target: Element, forwarded: Array<[string, string]>, tag: string): void;
23
+ export declare function applyForwardedAttrs(target: Element, forwarded: ForwardedAttr[], tag: string): void;
22
24
  //# sourceMappingURL=forwardedAttrs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"forwardedAttrs.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/forwardedAttrs.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AA6BF,0FAA0F;AAC1F,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAQ1E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAClC,GAAG,EAAE,MAAM,GACV,IAAI,CAaN"}
1
+ {"version":3,"file":"forwardedAttrs.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/forwardedAttrs.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AA+BF,0FAA0F;AAC1F,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,OAAO,GAAG,aAAa,EAAE,CAQlE;AAED,oEAAoE;AACpE,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAE7E;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,aAAa,EAAE,EAC1B,GAAG,EAAE,MAAM,GACV,IAAI,CAgBN"}
@@ -6,6 +6,8 @@
6
6
  }
7
7
  */
8
8
  import { DIRECTIVE_ATTR_PREFIXES, isDirectiveAttr } from '@pithyjs/compiler';
9
+ import { nodeExpando } from '../nodeExpando.js';
10
+ import { isDeclaredDirective } from './declaredDirective.js';
9
11
  const FORWARDED_DIRECTIVE_ATTRS = new Set(['data-classes']);
10
12
  // Runtime-owned attributes: forwarding them would give the rendered root the
11
13
  // component tag's node identity, its parent's style scope, or its loop/defer state.
@@ -37,7 +39,7 @@ export function collectForwardedAttrs(el) {
37
39
  const forwarded = [];
38
40
  for (const attr of Array.from(el.attributes)) {
39
41
  if (isForwardableAttr(attr.name)) {
40
- forwarded.push([attr.name, attr.value]);
42
+ forwarded.push([attr.name, attr.value, isDeclaredDirective(attr)]);
41
43
  }
42
44
  }
43
45
  return forwarded;
@@ -54,13 +56,19 @@ export function collectForwardedAttrs(el) {
54
56
  * Shared by both binders so the two paths cannot drift.
55
57
  */
56
58
  export function applyForwardedAttrs(target, forwarded, tag) {
57
- for (const [name, value] of forwarded) {
59
+ var _a;
60
+ for (const [name, value, declared] of forwarded) {
58
61
  if (import.meta.env?.DEV &&
59
62
  target.hasAttribute(name) &&
60
63
  target.getAttribute(name) !== value) {
61
64
  console.warn(`[PithyJS] <${tag}> forwarded ${name}="${value}" over the component's own "${target.getAttribute(name)}".`);
62
65
  }
63
66
  target.setAttribute(name, value);
67
+ const records = ((_a = nodeExpando(target)).__forwardedDirectives ?? (_a.__forwardedDirectives = new Map()));
68
+ if (declared)
69
+ records.set(name, value);
70
+ else
71
+ records.delete(name);
64
72
  }
65
73
  }
66
74
  //# sourceMappingURL=forwardedAttrs.js.map