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

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 (79) hide show
  1. package/README.md +13 -1
  2. package/dist/a11y/focus-trap.d.ts +11 -3
  3. package/dist/a11y/focus-trap.d.ts.map +1 -1
  4. package/dist/a11y/focus-trap.js +53 -10
  5. package/dist/a11y/focus-trap.js.map +1 -1
  6. package/dist/compile/bindSwitchCases.d.ts.map +1 -1
  7. package/dist/compile/bindSwitchCases.js +28 -7
  8. package/dist/compile/bindSwitchCases.js.map +1 -1
  9. package/dist/compile/binds/bindAfterComponents.d.ts +4 -0
  10. package/dist/compile/binds/bindAfterComponents.d.ts.map +1 -0
  11. package/dist/compile/binds/bindAfterComponents.js +26 -0
  12. package/dist/compile/binds/bindAfterComponents.js.map +1 -0
  13. package/dist/compile/binds/bindAfterProjection.d.ts +7 -0
  14. package/dist/compile/binds/bindAfterProjection.d.ts.map +1 -0
  15. package/dist/compile/binds/bindAfterProjection.js +13 -0
  16. package/dist/compile/binds/bindAfterProjection.js.map +1 -0
  17. package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
  18. package/dist/compile/binds/bindComponentsTags.js +41 -11
  19. package/dist/compile/binds/bindComponentsTags.js.map +1 -1
  20. package/dist/compile/binds/bindErrorBoundary.d.ts +11 -1
  21. package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
  22. package/dist/compile/binds/bindErrorBoundary.js +44 -9
  23. package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
  24. package/dist/compile/compileNodes.d.ts.map +1 -1
  25. package/dist/compile/compileNodes.js +2 -0
  26. package/dist/compile/compileNodes.js.map +1 -1
  27. package/dist/compile/compileTemplate.d.ts.map +1 -1
  28. package/dist/compile/compileTemplate.js +5 -24
  29. package/dist/compile/compileTemplate.js.map +1 -1
  30. package/dist/compile/contentProjection.d.ts +12 -0
  31. package/dist/compile/contentProjection.d.ts.map +1 -1
  32. package/dist/compile/contentProjection.js +42 -0
  33. package/dist/compile/contentProjection.js.map +1 -1
  34. package/dist/compile/disposeOrder.d.ts +35 -0
  35. package/dist/compile/disposeOrder.d.ts.map +1 -0
  36. package/dist/compile/disposeOrder.js +81 -0
  37. package/dist/compile/disposeOrder.js.map +1 -0
  38. package/dist/compile/forLoops/bindForLoops.d.ts +1 -1
  39. package/dist/compile/forLoops/bindForLoops.d.ts.map +1 -1
  40. package/dist/compile/forLoops/bindForLoops.js +10 -3
  41. package/dist/compile/forLoops/bindForLoops.js.map +1 -1
  42. package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -1
  43. package/dist/compile/forLoops/createLoopManager.js +19 -2
  44. package/dist/compile/forLoops/createLoopManager.js.map +1 -1
  45. package/dist/compile/handleConditionalChain.d.ts.map +1 -1
  46. package/dist/compile/handleConditionalChain.js +2 -3
  47. package/dist/compile/handleConditionalChain.js.map +1 -1
  48. package/dist/compile/renderBranch.d.ts +1 -1
  49. package/dist/compile/renderBranch.d.ts.map +1 -1
  50. package/dist/compile/renderBranch.js +6 -4
  51. package/dist/compile/renderBranch.js.map +1 -1
  52. package/dist/compile/renderChildren.d.ts +3 -1
  53. package/dist/compile/renderChildren.d.ts.map +1 -1
  54. package/dist/compile/renderChildren.js +8 -1
  55. package/dist/compile/renderChildren.js.map +1 -1
  56. package/dist/runtime/applyBindings.d.ts +6 -2
  57. package/dist/runtime/applyBindings.d.ts.map +1 -1
  58. package/dist/runtime/applyBindings.js +43 -22
  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 +12 -7
  62. package/dist/runtime/bindings/applyComponent.js.map +1 -1
  63. package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
  64. package/dist/runtime/bindings/applySimple.js +4 -3
  65. package/dist/runtime/bindings/applySimple.js.map +1 -1
  66. package/dist/runtime/bindings/applyStructural.d.ts.map +1 -1
  67. package/dist/runtime/bindings/applyStructural.js +11 -13
  68. package/dist/runtime/bindings/applyStructural.js.map +1 -1
  69. package/dist/runtime/bindings/helpers.d.ts +7 -0
  70. package/dist/runtime/bindings/helpers.d.ts.map +1 -1
  71. package/dist/runtime/bindings/helpers.js +33 -1
  72. package/dist/runtime/bindings/helpers.js.map +1 -1
  73. package/dist/runtime/html.d.ts.map +1 -1
  74. package/dist/runtime/html.js +2 -3
  75. package/dist/runtime/html.js.map +1 -1
  76. package/dist/types/globals.d.ts +2 -0
  77. package/dist/types/globals.d.ts.map +1 -1
  78. package/dist/types/globals.js.map +1 -1
  79. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/runtime/bindings/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAYF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,iFAAiF;AAEjF;;;;GAIG;AACH,0KAA0K;AAC1K,MAAM,UAAU,WAAW,CAAC,QAA0B;IACpD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAmB,CAAC;IACvC,MAAM,MAAM,GAAG,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;IAC5E,IAAI,IAAoB,CAAC;IACzB,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,QAAQ,EAAoB,CAAC,EAAE,CAAC;QACpD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QAC1C,IAAI,GAAG;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,8KAA8K;AAC9K,MAAM,UAAU,eAAe,CAC7B,QAA0B;IAE1B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAmB,CAAC;IACvC,MAAM,MAAM,GAAG,QAAQ,C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C,CAAC;QACnE,CAAC;QACD,OAAO,CAAC,GAAU,EAAE,GAAY,EAAE,EAAE,CAAC,SAAS,CAAC;IACjD,CAAC;AACH,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.binding-helpers\",\n \"title\": \"AOT Binding Helpers\",\n \"category\": \"runtime\"\n}\n*/\n\n/**\n * Shared helper utilities for AOT binding application.\n *\n * Provides DOM lookup maps, context merging, and expression compilation\n * used by both the JIT path (`html.ts`) and the AOT path (`applyBindings.ts`).\n *\n * @module runtime/bindings/helpers\n */\n\nimport type { BindingContext } from './types';\nimport { pithyGlobals } from '../../types/globals';\n\n// ─── Helpers ──────────────────────────────────────────────────────────────────\n\n/**\n * Build a map of pid → Element from data-pid attributes in the fragment.\n * @param fragment - The DOM fragment to scan\n * @returns Map from pid string to the corresponding Element\n */\n/** @codexApi {\"parent\":\"pithy.runtime.binding-helpers\",\"name\":\"buildPidMap\",\"stability\":\"internal\",\"signature\":\"(fragment: DocumentFragment) => Map<string, Element>\"} */\nexport function buildPidMap(fragment: DocumentFragment): Map<string, Element> {\n const map = new Map<string, Element>();\n const walker = document.createTreeWalker(fragment, NodeFilter.SHOW_ELEMENT);\n let node: Element | null;\n while ((node = walker.nextNode() as Element | null)) {\n const pid = node.getAttribute('data-pid');\n if (pid) map.set(pid, node);\n }\n return map;\n}\n\n/**\n * Build a map of comment anchor id → Comment for structural directives.\n * @param fragment - The DOM fragment to scan\n * @returns Map from comment text (e.g. \"if:r0\") to the Comment node\n */\n/** @codexApi {\"parent\":\"pithy.runtime.binding-helpers\",\"name\":\"buildCommentMap\",\"stability\":\"internal\",\"signature\":\"(fragment: DocumentFragment) => Map<string, Comment>\"} */\nexport function buildCommentMap(\n fragment: DocumentFragment\n): Map<string, Comment> {\n const map = new Map<string, Comment>();\n const walker = document.createTreeWalker(fragment, NodeFilter.SHOW_COMMENT);\n let node: Comment | null;\n while ((node = walker.nextNode() as Comment | null)) {\n const text = node.textContent ?? '';\n // Structural anchors: \"if:pid\", \"for:pid\", \"slot:name\"\n const colonIdx = text.indexOf(':');\n if (colonIdx > 0) {\n map.set(text, node);\n }\n }\n return map;\n}\n\n/**\n * Walk up the DOM to find the nearest local PithyJS context.\n * Falls back to the provided root context.\n * @param el - Starting DOM node\n * @param rootCtx - Fallback context if no local context is found\n * @returns The nearest context object\n */\n/** @codexApi {\"parent\":\"pithy.runtime.binding-helpers\",\"name\":\"nearestCtx\",\"stability\":\"internal\",\"signature\":\"(el: Node, rootCtx: BindingContext) => BindingContext\"} */\nexport function nearestCtx(el: Node, rootCtx: BindingContext): BindingContext {\n // Walk parentNode (not parentElement) so context is found on Text/Comment\n // nodes — needed when JIT-projected content is slotted into AOT components.\n // NOTE: In @for loops, only Element nodes receive loop-item __pithyCtx\n // (see applyStructural.ts / createLoopManager.ts). Text nodes inside loop\n // items inherit context from their parent Element, which works correctly\n // because AOT text nodes don't have __pithyCtx set (factories use raw\n // createTextNode), and JIT text nodes are children of tagged Elements.\n let n: Node | null = el;\n while (n) {\n const local = (n as Node & { __pithyCtx?: BindingContext }).__pithyCtx;\n if (local) return local;\n n = n.parentNode;\n }\n return rootCtx;\n}\n\n/**\n * Merge parent component and async (SSR) contexts into the explicit context.\n * Single source of truth used by both `html.ts` and `applyBindings.ts`.\n * @param context - The explicit context from the call site\n * @returns Merged context with parent component and async contexts\n */\n/** @codexApi {\"parent\":\"pithy.runtime.binding-helpers\",\"name\":\"mergeContexts\",\"stability\":\"internal\",\"signature\":\"(context: BindingContext) => BindingContext\"} */\nexport function mergeContexts(context: BindingContext): BindingContext {\n const g = pithyGlobals();\n const getContextFn = g.__getComponentContext;\n const asyncContext =\n typeof getContextFn === 'function' ? getContextFn() : undefined;\n const parentComponentContext = g.__pithyComponentContext;\n\n let parentData: BindingContext | undefined;\n if (parentComponentContext && typeof parentComponentContext === 'object') {\n parentData = {};\n for (const key of Object.keys(parentComponentContext)) {\n if (\n key.startsWith('__') ||\n typeof parentComponentContext[key] === 'function'\n ) {\n parentData[key] = parentComponentContext[key];\n }\n }\n if (Object.keys(parentData).length === 0) parentData = undefined;\n }\n\n if (asyncContext || parentData) {\n return { ...(parentData || {}), ...(asyncContext || {}), ...context };\n }\n return context;\n}\n\n/**\n * Compile expression with $event and $el support for event handlers.\n * @param expr - The expression string to compile\n * @param ctx - The reactive context for variable resolution\n * @returns A function that accepts (event, element) and evaluates the expression\n */\n/** @codexApi {\"parent\":\"pithy.runtime.binding-helpers\",\"name\":\"compileWithEvent\",\"stability\":\"internal\",\"signature\":\"(expr: string, ctx: BindingContext) => (ev: Event, el: Element) => unknown\"} */\nexport function compileWithEvent(\n expr: string,\n ctx: BindingContext\n): (ev: Event, el: Element) => unknown {\n try {\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: BindingContext, 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(`[AOT bindEvent] Failed to compile \"${expr}\"`, err);\n }\n return (_ev: Event, _el: Element) => undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/runtime/bindings/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAYF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,iFAAiF;AAEjF;;;;GAIG;AACH,0KAA0K;AAC1K,MAAM,UAAU,WAAW,CAAC,QAA0B;IACpD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAmB,CAAC;IACvC,MAAM,MAAM,GAAG,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;IAC5E,IAAI,IAAoB,CAAC;IACzB,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,QAAQ,EAAoB,CAAC,EAAE,CAAC;QACpD,MAAM,GAAG,GAAG,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AI,CAAC,sCAAsC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,CAAC,GAAU,EAAE,GAAY,EAAE,EAAE,CAAC,SAAS,CAAC;IACjD,CAAC;AACH,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.binding-helpers\",\n \"title\": \"AOT Binding Helpers\",\n \"category\": \"runtime\"\n}\n*/\n\n/**\n * Shared helper utilities for AOT binding application.\n *\n * Provides DOM lookup maps, context merging, and expression compilation\n * used by both the JIT path (`html.ts`) and the AOT path (`applyBindings.ts`).\n *\n * @module runtime/bindings/helpers\n */\n\nimport type { BindingContext } from './types';\nimport { pithyGlobals } from '../../types/globals';\n\n// ─── Helpers ──────────────────────────────────────────────────────────────────\n\n/**\n * Build a map of pid → Element from data-pid attributes in the fragment.\n * @param fragment - The DOM fragment to scan\n * @returns Map from pid string to the corresponding Element\n */\n/** @codexApi {\"parent\":\"pithy.runtime.binding-helpers\",\"name\":\"buildPidMap\",\"stability\":\"internal\",\"signature\":\"(fragment: DocumentFragment) => Map<string, Element>\"} */\nexport function buildPidMap(fragment: DocumentFragment): Map<string, Element> {\n const map = new Map<string, Element>();\n const walker = document.createTreeWalker(fragment, NodeFilter.SHOW_ELEMENT);\n let node: Element | null;\n while ((node = walker.nextNode() as Element | null)) {\n const pid = node.getAttribute('data-pid');\n if (pid) map.set(pid, node);\n }\n return map;\n}\n\n/**\n * Build a map of comment anchor id → Comment for structural directives.\n * @param fragment - The DOM fragment to scan\n * @returns Map from comment text (e.g. \"if:r0\") to the Comment node\n */\n/** @codexApi {\"parent\":\"pithy.runtime.binding-helpers\",\"name\":\"buildCommentMap\",\"stability\":\"internal\",\"signature\":\"(fragment: DocumentFragment) => Map<string, Comment>\"} */\nexport function buildCommentMap(\n fragment: DocumentFragment\n): Map<string, Comment> {\n const map = new Map<string, Comment>();\n const walker = document.createTreeWalker(fragment, NodeFilter.SHOW_COMMENT);\n let node: Comment | null;\n while ((node = walker.nextNode() as Comment | null)) {\n const text = node.textContent ?? '';\n // Structural anchors: \"if:pid\", \"for:pid\", \"slot:name\"\n const colonIdx = text.indexOf(':');\n if (colonIdx > 0) {\n map.set(text, node);\n }\n }\n return map;\n}\n\n/**\n * Walk up the DOM to find the nearest local PithyJS context.\n * Falls back to the provided root context.\n * @param el - Starting DOM node\n * @param rootCtx - Fallback context if no local context is found\n * @returns The nearest context object\n */\n/** @codexApi {\"parent\":\"pithy.runtime.binding-helpers\",\"name\":\"nearestCtx\",\"stability\":\"internal\",\"signature\":\"(el: Node, rootCtx: BindingContext) => BindingContext\"} */\nexport function nearestCtx(el: Node, rootCtx: BindingContext): BindingContext {\n // Walk parentNode (not parentElement) so context is found on Text/Comment\n // nodes — needed when JIT-projected content is slotted into AOT components.\n // NOTE: In @for loops, only Element nodes receive loop-item __pithyCtx\n // (see applyStructural.ts / createLoopManager.ts). Text nodes inside loop\n // items inherit context from their parent Element, which works correctly\n // because AOT text nodes don't have __pithyCtx set (factories use raw\n // createTextNode), and JIT text nodes are children of tagged Elements.\n let n: Node | null = el;\n while (n) {\n const local = (n as Node & { __pithyCtx?: BindingContext }).__pithyCtx;\n if (local) return local;\n n = n.parentNode;\n }\n return rootCtx;\n}\n\n/**\n * `{ ...a, ...b }` that copies a getter as a getter: a spread reads it once\n * and stores the value, so the template would never see it change. Every\n * read goes through the source, so `this` and a Proxy's `get` trap apply.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.binding-helpers\",\"name\":\"spreadLive\",\"stability\":\"internal\",\"signature\":\"(...sources: (BindingContext | undefined)[]) => BindingContext\"} */\nexport function spreadLive(\n ...sources: (BindingContext | undefined)[]\n): BindingContext {\n const out: BindingContext = {};\n for (const source of sources) {\n if (!source) continue;\n for (const key of Reflect.ownKeys(source)) {\n const desc = Object.getOwnPropertyDescriptor(source, key);\n if (!desc?.enumerable) continue;\n Object.defineProperty(\n out,\n key,\n 'value' in desc\n ? {\n value: Reflect.get(source, key),\n writable: true,\n enumerable: true,\n configurable: true,\n }\n : {\n get: () => Reflect.get(source, key),\n set: desc.set && ((v: unknown) => Reflect.set(source, key, v)),\n enumerable: true,\n configurable: true,\n }\n );\n }\n }\n return out;\n}\n\n/**\n * Merge parent component and async (SSR) contexts into the explicit context.\n * Single source of truth used by both `html.ts` and `applyBindings.ts`.\n * @param context - The explicit context from the call site\n * @returns Merged context with parent component and async contexts\n */\n/** @codexApi {\"parent\":\"pithy.runtime.binding-helpers\",\"name\":\"mergeContexts\",\"stability\":\"internal\",\"signature\":\"(context: BindingContext) => BindingContext\"} */\nexport function mergeContexts(context: BindingContext): BindingContext {\n const g = pithyGlobals();\n const getContextFn = g.__getComponentContext;\n const asyncContext =\n typeof getContextFn === 'function' ? getContextFn() : undefined;\n const parentComponentContext = g.__pithyComponentContext;\n\n let parentData: BindingContext | undefined;\n if (parentComponentContext && typeof parentComponentContext === 'object') {\n parentData = {};\n for (const key of Object.keys(parentComponentContext)) {\n if (\n key.startsWith('__') ||\n typeof parentComponentContext[key] === 'function'\n ) {\n parentData[key] = parentComponentContext[key];\n }\n }\n if (Object.keys(parentData).length === 0) parentData = undefined;\n }\n\n if (asyncContext || parentData) {\n return spreadLive(parentData, asyncContext, context);\n }\n return context;\n}\n\n/**\n * Compile expression with $event and $el support for event handlers.\n * @param expr - The expression string to compile\n * @param ctx - The reactive context for variable resolution\n * @returns A function that accepts (event, element) and evaluates the expression\n */\n/** @codexApi {\"parent\":\"pithy.runtime.binding-helpers\",\"name\":\"compileWithEvent\",\"stability\":\"internal\",\"signature\":\"(expr: string, ctx: BindingContext) => (ev: Event, el: Element) => unknown\"} */\nexport function compileWithEvent(\n expr: string,\n ctx: BindingContext\n): (ev: Event, el: Element) => unknown {\n try {\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: BindingContext, 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(`[AOT bindEvent] Failed to compile \"${expr}\"`, err);\n }\n return (_ev: Event, _el: Element) => undefined;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/runtime/html.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAQF;;;;;;;;;GASG;AACH,wRAAwR;AACxR,wBAAgB,IAAI,CAClB,QAAQ,EAAE,oBAAoB,GAAG,MAAM,EACvC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAC/C,kBAAkB,CAAC,EAAE,MAAM,GAC1B;IAAE,EAAE,EAAE,WAAW,GAAG,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CAyF7D"}
1
+ {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/runtime/html.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAQF;;;;;;;;;GASG;AACH,wRAAwR;AACxR,wBAAgB,IAAI,CAClB,QAAQ,EAAE,oBAAoB,GAAG,MAAM,EACvC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAC/C,kBAAkB,CAAC,EAAE,MAAM,GAC1B;IAAE,EAAE,EAAE,WAAW,GAAG,gBAAgB,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CAwF7D"}
@@ -8,7 +8,7 @@
8
8
  import { compileTemplate } from '../compile/compileTemplate.js';
9
9
  import { createContextProxy } from './createContextProxy.js';
10
10
  import { parseIdentifiersFromTemplate } from './parseIdentifiersFromTemplate.js';
11
- import { mergeContexts } from './bindings/helpers.js';
11
+ import { mergeContexts, spreadLive } from './bindings/helpers.js';
12
12
  import { drainDestroyCallbacks } from './onDestroy.js';
13
13
  /**
14
14
  * Tagged template function for creating reactive DOM from HTML strings.
@@ -49,8 +49,7 @@ export function html(template, contextOrCss, cssIfContextPassed) {
49
49
  }
50
50
  // Extract imported identifiers from context if provided by Babel plugin
51
51
  const importedIdentifiers = context.__importedIdentifiers;
52
- // Remove the special property from context before creating proxy
53
- const cleanContext = { ...context };
52
+ const cleanContext = spreadLive(context);
54
53
  delete cleanContext.__importedIdentifiers;
55
54
  const proxiedContext = createContextProxy([cleanContext]);
56
55
  let result;
@@ -1 +1 @@
1
- {"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/runtime/html.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;;;;GASG;AACH,wRAAwR;AACxR,MAAM,UAAU,IAAI,CAClB,QAAuC,EACvC,YAA+C,EAC/C,kBAA2B;IAE3B,wEAAwE;IACxE,gFAAgF;IAChF,MAAM,gBAAgB,GAAG,qBAAqB,EAAE,CAAC;IAEjD,MAAM,OAAO,GACX,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEjE,IAAI,OAAO,GAA4B,EAAE,CAAC;IAC1C,IAAI,GAAuB,CAAC;IAE5B,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,GAAG,YAAY,CAAC;QACvB,GAAG,GAAG,kBAAkB,CAAC;IAC3B,CAAC;SAAM,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QAC5C,GAAG,GAAG,YAAY,CAAC;IACrB,CAAC;IAED,wEAAwE;IACxE,qEAAqE;I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AM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC;IAEjD,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,OAAO;YACL,IAAI,CAAC;gBACH,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,CAAC;YAAC,MAAM,CAAC;gBACP,4BAA4B;YAC9B,CAAC;YACD,0CAA0C;YAC1C,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,4BAA4B;gBAC9B,CAAC;YACH,CAAC;YACD,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.html\",\n \"title\": \"HTML Template Helper\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { compileTemplate } from '../compile/compileTemplate';\nimport { createContextProxy } from './createContextProxy';\nimport { parseIdentifiersFromTemplate } from './parseIdentifiersFromTemplate';\nimport { mergeContexts } from './bindings/helpers';\nimport { drainDestroyCallbacks } from './onDestroy';\n\n/**\n * Tagged template function for creating reactive DOM from HTML strings.\n * Parses the template, binds reactive directives, and returns a live DOM fragment.\n * Requires `loadJITCompiler()` to be called first (to load parse5 dynamically).\n *\n * @param template - Template literal or raw HTML string\n * @param contextOrCss - Reactive context object or CSS string\n * @param cssIfContextPassed - CSS string when context is the second argument\n * @returns Object with `el` (live DOM) and `destroy` (cleanup function)\n */\n/** @codexApi {\"parent\":\"pithy.runtime.html\",\"name\":\"html\",\"stability\":\"stable\",\"signature\":\"(template: TemplateStringsArray | string, contextOrCss?: Record<string, unknown> | string, cssIfContextPassed?: string) => { el: HTMLElement | DocumentFragment; destroy: () => void }\"} */\nexport function html(\n template: TemplateStringsArray | string,\n contextOrCss?: Record<string, unknown> | string,\n cssIfContextPassed?: string\n): { el: HTMLElement | DocumentFragment; destroy: () => void } {\n // Drain onDestroy() callbacks BEFORE compileTemplate — child components\n // instantiated during compilation will drain their own callbacks independently.\n const destroyCallbacks = drainDestroyCallbacks();\n\n const rawHtml =\n typeof template === 'string' ? template : String.raw(template);\n\n let context: Record<string, unknown> = {};\n let css: string | undefined;\n\n if (typeof contextOrCss === 'object') {\n context = contextOrCss;\n css = cssIfContextPassed;\n } else if (typeof contextOrCss === 'string') {\n css = contextOrCss;\n }\n\n // Merge with component context if available (for content projection and\n // nested component resolution). Uses the shared mergeContexts helper\n // (single source of truth with applyBindings.ts).\n context = mergeContexts(context);\n\n // Dev fallback\n if (import.meta.env?.DEV && Object.keys(context).length === 0) {\n const identifiers = parseIdentifiersFromTemplate(rawHtml);\n identifiers.forEach(name => {\n context[name] = undefined;\n console.warn(\n `[PithyJS html()] Dev fallback: '${name}' will be undefined unless injected by plugin.`\n );\n });\n }\n\n // Extract imported identifiers from context if provided by Babel plugin\n const importedIdentifiers = context.__importedIdentifiers as\n | Set<string>\n | undefined;\n\n // Remove the special property from context before creating proxy\n const cleanContext = { ...context };\n delete cleanContext.__importedIdentifiers;\n\n const proxiedContext = createContextProxy([cleanContext]);\n\n let result: { el: HTMLElement | DocumentFragment; destroy: () => void };\n try {\n result = compileTemplate(\n rawHtml,\n proxiedContext,\n css,\n undefined,\n importedIdentifiers\n );\n } catch (err) {\n // Run drained callbacks LIFO before rethrowing so partially-initialized\n // resources (effects, event listeners) 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 // Zero-overhead fast path when no onDestroy was called\n if (destroyCallbacks.length === 0) return result;\n\n return {\n el: result.el,\n destroy() {\n try {\n result.destroy();\n } catch {\n /* ignore disposal errors */\n }\n // LIFO order — last-registered runs first\n for (let i = destroyCallbacks.length - 1; i >= 0; i--) {\n try {\n destroyCallbacks[i]();\n } catch {\n /* ignore disposal errors */\n }\n }\n destroyCallbacks.length = 0;\n },\n };\n}\n"]}
1
+ {"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/runtime/html.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;;;;GASG;AACH,wRAAwR;AACxR,MAAM,UAAU,IAAI,CAClB,QAAuC,EACvC,YAA+C,EAC/C,kBAA2B;IAE3B,wEAAwE;IACxE,gFAAgF;IAChF,MAAM,gBAAgB,GAAG,qBAAqB,EAAE,CAAC;IAEjD,MAAM,OAAO,GACX,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEjE,IAAI,OAAO,GAA4B,EAAE,CAAC;IAC1C,IAAI,GAAuB,CAAC;IAE5B,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,GAAG,YAAY,CAAC;QACvB,GAAG,GAAG,kBAAkB,CAAC;IAC3B,CAAC;SAAM,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QAC5C,GAAG,GAAG,YAAY,CAAC;IACrB,CAAC;IAED,wEAAwE;IACxE,qEAAqE;IACrE,kDAAkD;IAClD,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IAEjC,eAAe;IACf,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,MAAM,CAAC,I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C;YAAC,MAAM,CAAC;gBACP,4BAA4B;YAC9B,CAAC;YACD,0CAA0C;YAC1C,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,4BAA4B;gBAC9B,CAAC;YACH,CAAC;YACD,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.html\",\n \"title\": \"HTML Template Helper\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { compileTemplate } from '../compile/compileTemplate';\nimport { createContextProxy } from './createContextProxy';\nimport { parseIdentifiersFromTemplate } from './parseIdentifiersFromTemplate';\nimport { mergeContexts, spreadLive } from './bindings/helpers';\nimport { drainDestroyCallbacks } from './onDestroy';\n\n/**\n * Tagged template function for creating reactive DOM from HTML strings.\n * Parses the template, binds reactive directives, and returns a live DOM fragment.\n * Requires `loadJITCompiler()` to be called first (to load parse5 dynamically).\n *\n * @param template - Template literal or raw HTML string\n * @param contextOrCss - Reactive context object or CSS string\n * @param cssIfContextPassed - CSS string when context is the second argument\n * @returns Object with `el` (live DOM) and `destroy` (cleanup function)\n */\n/** @codexApi {\"parent\":\"pithy.runtime.html\",\"name\":\"html\",\"stability\":\"stable\",\"signature\":\"(template: TemplateStringsArray | string, contextOrCss?: Record<string, unknown> | string, cssIfContextPassed?: string) => { el: HTMLElement | DocumentFragment; destroy: () => void }\"} */\nexport function html(\n template: TemplateStringsArray | string,\n contextOrCss?: Record<string, unknown> | string,\n cssIfContextPassed?: string\n): { el: HTMLElement | DocumentFragment; destroy: () => void } {\n // Drain onDestroy() callbacks BEFORE compileTemplate — child components\n // instantiated during compilation will drain their own callbacks independently.\n const destroyCallbacks = drainDestroyCallbacks();\n\n const rawHtml =\n typeof template === 'string' ? template : String.raw(template);\n\n let context: Record<string, unknown> = {};\n let css: string | undefined;\n\n if (typeof contextOrCss === 'object') {\n context = contextOrCss;\n css = cssIfContextPassed;\n } else if (typeof contextOrCss === 'string') {\n css = contextOrCss;\n }\n\n // Merge with component context if available (for content projection and\n // nested component resolution). Uses the shared mergeContexts helper\n // (single source of truth with applyBindings.ts).\n context = mergeContexts(context);\n\n // Dev fallback\n if (import.meta.env?.DEV && Object.keys(context).length === 0) {\n const identifiers = parseIdentifiersFromTemplate(rawHtml);\n identifiers.forEach(name => {\n context[name] = undefined;\n console.warn(\n `[PithyJS html()] Dev fallback: '${name}' will be undefined unless injected by plugin.`\n );\n });\n }\n\n // Extract imported identifiers from context if provided by Babel plugin\n const importedIdentifiers = context.__importedIdentifiers as\n | Set<string>\n | undefined;\n\n const cleanContext = spreadLive(context);\n delete cleanContext.__importedIdentifiers;\n\n const proxiedContext = createContextProxy([cleanContext]);\n\n let result: { el: HTMLElement | DocumentFragment; destroy: () => void };\n try {\n result = compileTemplate(\n rawHtml,\n proxiedContext,\n css,\n undefined,\n importedIdentifiers\n );\n } catch (err) {\n // Run drained callbacks LIFO before rethrowing so partially-initialized\n // resources (effects, event listeners) 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 // Zero-overhead fast path when no onDestroy was called\n if (destroyCallbacks.length === 0) return result;\n\n return {\n el: result.el,\n destroy() {\n try {\n result.destroy();\n } catch {\n /* ignore disposal errors */\n }\n // LIFO order — last-registered runs first\n for (let i = destroyCallbacks.length - 1; i >= 0; i--) {\n try {\n destroyCallbacks[i]();\n } catch {\n /* ignore disposal errors */\n }\n }\n destroyCallbacks.length = 0;\n },\n };\n}\n"]}
@@ -6,6 +6,8 @@ export interface PithyComponentContext extends Record<string, unknown> {
6
6
  __slotMap?: SlotMap;
7
7
  __childAstNodes?: PithyNode[];
8
8
  __childFactory?: ChildFactory;
9
+ /** The component placeholder this context renders, while it is in the tree. */
10
+ __slotHost?: Element;
9
11
  }
10
12
  export interface PithyGlobals {
11
13
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../../src/types/globals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,MAAM,WAAW,qBAAsB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACpE,wBAAwB,CAAC,EAAE,qBAAqB,CAAC;IACjD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,eAAe,CAAC,EAAE,SAAS,EAAE,CAAC;IAC9B,cAAc,CAAC,EAAE,YAAY,CAAC;CAC/B;AAED,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1C,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,qBAAqB,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAClE,uBAAuB,CAAC,EAAE,qBAAqB,CAAC;IAChD,wBAAwB,CAAC,EAAE,gBAAgB,CAAC;IAC5C,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,0BAA0B,CAAC,EAAE,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC;IAC9D,0BAA0B,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC;CAC5D;AAED,wBAAgB,YAAY,IAAI,OAAO,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"","sources":["../../src/types/globals.ts"],"names":[],"mappings":"AA4BA,MAAM,UAAU,YAAY;IAC1B,OAAO,UAA8C,CAAC;AACxD,CAAC","sourcesContent":["import type { SlotMap } from '../compile/contentProjection';\nimport type { PithyNode } from '@pithyjs/compiler';\nimport type { ChildFactory } from '../runtime/bindings/types';\n\nexport interface PithyComponentContext extends Record<string, unknown> {\n __parentComponentContext?: PithyComponentContext;\n __slotMap?: SlotMap;\n __childAstNodes?: PithyNode[];\n __childFactory?: ChildFactory;\n}\n\nexport interface PithyGlobals {\n /**\n * SSR component-crash registry. Lives on `globalThis` rather than in a module\n * so that an app and `@pithyjs/ssr` resolving two physical copies of\n * `@pithyjs/core` still share one — see `compile/ssrCrashes.ts`.\n */\n __pithySSRCrashes?: Map<Element, unknown>;\n PITHY_DEBUG_PROJECTION?: boolean;\n __PITHY_SSR__?: boolean;\n __getComponentContext?: () => Record<string, unknown> | undefined;\n __pithyComponentContext?: PithyComponentContext;\n __pithyProjectedChildren?: DocumentFragment;\n __pithyRenderingComponent?: boolean;\n __pithyGetDestroyCallbacks?: () => (() => void)[] | undefined;\n __pithySetDestroyCallbacks?: (cbs: (() => void)[]) => void;\n}\n\nexport function pithyGlobals(): typeof globalThis & PithyGlobals {\n return globalThis as typeof globalThis & PithyGlobals;\n}\n"]}
1
+ {"version":3,"file":"globals.js","sourceRoot":"","sources":["../../src/types/globals.ts"],"names":[],"mappings":"AA8BA,MAAM,UAAU,YAAY;IAC1B,OAAO,UAA8C,CAAC;AACxD,CAAC","sourcesContent":["import type { SlotMap } from '../compile/contentProjection';\nimport type { PithyNode } from '@pithyjs/compiler';\nimport type { ChildFactory } from '../runtime/bindings/types';\n\nexport interface PithyComponentContext extends Record<string, unknown> {\n __parentComponentContext?: PithyComponentContext;\n __slotMap?: SlotMap;\n __childAstNodes?: PithyNode[];\n __childFactory?: ChildFactory;\n /** The component placeholder this context renders, while it is in the tree. */\n __slotHost?: Element;\n}\n\nexport interface PithyGlobals {\n /**\n * SSR component-crash registry. Lives on `globalThis` rather than in a module\n * so that an app and `@pithyjs/ssr` resolving two physical copies of\n * `@pithyjs/core` still share one — see `compile/ssrCrashes.ts`.\n */\n __pithySSRCrashes?: Map<Element, unknown>;\n PITHY_DEBUG_PROJECTION?: boolean;\n __PITHY_SSR__?: boolean;\n __getComponentContext?: () => Record<string, unknown> | undefined;\n __pithyComponentContext?: PithyComponentContext;\n __pithyProjectedChildren?: DocumentFragment;\n __pithyRenderingComponent?: boolean;\n __pithyGetDestroyCallbacks?: () => (() => void)[] | undefined;\n __pithySetDestroyCallbacks?: (cbs: (() => void)[]) => void;\n}\n\nexport function pithyGlobals(): typeof globalThis & PithyGlobals {\n return globalThis as typeof globalThis & PithyGlobals;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pithyjs/core",
3
- "version": "0.1.0-beta.13",
3
+ "version": "0.1.0-beta.15",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/PithyJS/pithyjs.git",
@@ -24,10 +24,10 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "@pithyjs/shared": "0.1.0-beta.3",
27
+ "@pithyjs/shared": "0.1.0-beta.4",
28
28
  "@pithyjs/signals": "0.1.0-beta.2",
29
- "@pithyjs/compiler": "0.1.0-beta.4",
30
- "@pithyjs/design-system": "0.1.0-beta.7"
29
+ "@pithyjs/compiler": "0.1.0-beta.6",
30
+ "@pithyjs/design-system": "0.1.0-beta.9"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "parse5": ">=7.0.0"
@@ -54,7 +54,7 @@
54
54
  "dist"
55
55
  ],
56
56
  "scripts": {
57
- "build": "tsc -p tsconfig.json && node ../../scripts/add-js-extensions.mjs dist",
57
+ "build": "node ../../scripts/check-dist.mjs --unstamp $$ && tsc -p tsconfig.json && node ../../scripts/add-js-extensions.mjs dist && node ../../scripts/check-dist.mjs --stamp $$",
58
58
  "test": "vitest"
59
59
  }
60
60
  }