@pithyjs/core 0.1.0-beta.0

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 (255) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +513 -0
  3. package/dist/a11y/focus-trap.d.ts +109 -0
  4. package/dist/a11y/focus-trap.d.ts.map +1 -0
  5. package/dist/a11y/focus-trap.js +246 -0
  6. package/dist/a11y/focus-trap.js.map +1 -0
  7. package/dist/a11y/index.d.ts +12 -0
  8. package/dist/a11y/index.d.ts.map +1 -0
  9. package/dist/a11y/index.js +16 -0
  10. package/dist/a11y/index.js.map +1 -0
  11. package/dist/a11y/keyboard-utils.d.ts +165 -0
  12. package/dist/a11y/keyboard-utils.d.ts.map +1 -0
  13. package/dist/a11y/keyboard-utils.js +321 -0
  14. package/dist/a11y/keyboard-utils.js.map +1 -0
  15. package/dist/a11y/roving-tabindex.d.ts +118 -0
  16. package/dist/a11y/roving-tabindex.d.ts.map +1 -0
  17. package/dist/a11y/roving-tabindex.js +249 -0
  18. package/dist/a11y/roving-tabindex.js.map +1 -0
  19. package/dist/a11y/skip-link.d.ts +55 -0
  20. package/dist/a11y/skip-link.d.ts.map +1 -0
  21. package/dist/a11y/skip-link.js +164 -0
  22. package/dist/a11y/skip-link.js.map +1 -0
  23. package/dist/compile/bindSwitchCases.d.ts +16 -0
  24. package/dist/compile/bindSwitchCases.d.ts.map +1 -0
  25. package/dist/compile/bindSwitchCases.js +323 -0
  26. package/dist/compile/bindSwitchCases.js.map +1 -0
  27. package/dist/compile/binds/bindBoundAttributes.d.ts +14 -0
  28. package/dist/compile/binds/bindBoundAttributes.d.ts.map +1 -0
  29. package/dist/compile/binds/bindBoundAttributes.js +57 -0
  30. package/dist/compile/binds/bindBoundAttributes.js.map +1 -0
  31. package/dist/compile/binds/bindClassDirectives.d.ts +20 -0
  32. package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -0
  33. package/dist/compile/binds/bindClassDirectives.js +94 -0
  34. package/dist/compile/binds/bindClassDirectives.js.map +1 -0
  35. package/dist/compile/binds/bindComponentsTags.d.ts +17 -0
  36. package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -0
  37. package/dist/compile/binds/bindComponentsTags.js +355 -0
  38. package/dist/compile/binds/bindComponentsTags.js.map +1 -0
  39. package/dist/compile/binds/bindConditionals.d.ts +16 -0
  40. package/dist/compile/binds/bindConditionals.d.ts.map +1 -0
  41. package/dist/compile/binds/bindConditionals.js +102 -0
  42. package/dist/compile/binds/bindConditionals.js.map +1 -0
  43. package/dist/compile/binds/bindDefaultTwoWay.d.ts +35 -0
  44. package/dist/compile/binds/bindDefaultTwoWay.d.ts.map +1 -0
  45. package/dist/compile/binds/bindDefaultTwoWay.js +128 -0
  46. package/dist/compile/binds/bindDefaultTwoWay.js.map +1 -0
  47. package/dist/compile/binds/bindDeferDirectives.d.ts +21 -0
  48. package/dist/compile/binds/bindDeferDirectives.d.ts.map +1 -0
  49. package/dist/compile/binds/bindDeferDirectives.js +465 -0
  50. package/dist/compile/binds/bindDeferDirectives.js.map +1 -0
  51. package/dist/compile/binds/bindErrorBoundary.d.ts +71 -0
  52. package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -0
  53. package/dist/compile/binds/bindErrorBoundary.js +389 -0
  54. package/dist/compile/binds/bindErrorBoundary.js.map +1 -0
  55. package/dist/compile/binds/bindEventHandlers.d.ts +17 -0
  56. package/dist/compile/binds/bindEventHandlers.d.ts.map +1 -0
  57. package/dist/compile/binds/bindEventHandlers.js +174 -0
  58. package/dist/compile/binds/bindEventHandlers.js.map +1 -0
  59. package/dist/compile/binds/bindRefDirectives.d.ts +14 -0
  60. package/dist/compile/binds/bindRefDirectives.d.ts.map +1 -0
  61. package/dist/compile/binds/bindRefDirectives.js +35 -0
  62. package/dist/compile/binds/bindRefDirectives.js.map +1 -0
  63. package/dist/compile/binds/bindTextInterpolations.d.ts +16 -0
  64. package/dist/compile/binds/bindTextInterpolations.d.ts.map +1 -0
  65. package/dist/compile/binds/bindTextInterpolations.js +408 -0
  66. package/dist/compile/binds/bindTextInterpolations.js.map +1 -0
  67. package/dist/compile/binds/directiveRegistry.d.ts +46 -0
  68. package/dist/compile/binds/directiveRegistry.d.ts.map +1 -0
  69. package/dist/compile/binds/directiveRegistry.js +50 -0
  70. package/dist/compile/binds/directiveRegistry.js.map +1 -0
  71. package/dist/compile/compileExpression.d.ts +10 -0
  72. package/dist/compile/compileExpression.d.ts.map +1 -0
  73. package/dist/compile/compileExpression.js +26 -0
  74. package/dist/compile/compileExpression.js.map +1 -0
  75. package/dist/compile/compileNodes.d.ts +32 -0
  76. package/dist/compile/compileNodes.d.ts.map +1 -0
  77. package/dist/compile/compileNodes.js +104 -0
  78. package/dist/compile/compileNodes.js.map +1 -0
  79. package/dist/compile/compileTemplate.d.ts +64 -0
  80. package/dist/compile/compileTemplate.d.ts.map +1 -0
  81. package/dist/compile/compileTemplate.js +157 -0
  82. package/dist/compile/compileTemplate.js.map +1 -0
  83. package/dist/compile/contentProjection.d.ts +29 -0
  84. package/dist/compile/contentProjection.d.ts.map +1 -0
  85. package/dist/compile/contentProjection.js +210 -0
  86. package/dist/compile/contentProjection.js.map +1 -0
  87. package/dist/compile/forLoops/bindForLoops.d.ts +21 -0
  88. package/dist/compile/forLoops/bindForLoops.d.ts.map +1 -0
  89. package/dist/compile/forLoops/bindForLoops.js +151 -0
  90. package/dist/compile/forLoops/bindForLoops.js.map +1 -0
  91. package/dist/compile/forLoops/createLoopManager.d.ts +51 -0
  92. package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -0
  93. package/dist/compile/forLoops/createLoopManager.js +429 -0
  94. package/dist/compile/forLoops/createLoopManager.js.map +1 -0
  95. package/dist/compile/forLoops/index.d.ts +6 -0
  96. package/dist/compile/forLoops/index.d.ts.map +1 -0
  97. package/dist/compile/forLoops/index.js +8 -0
  98. package/dist/compile/forLoops/index.js.map +1 -0
  99. package/dist/compile/forLoops/loopHelpers.d.ts +33 -0
  100. package/dist/compile/forLoops/loopHelpers.d.ts.map +1 -0
  101. package/dist/compile/forLoops/loopHelpers.js +69 -0
  102. package/dist/compile/forLoops/loopHelpers.js.map +1 -0
  103. package/dist/compile/forLoops/loopSignals.d.ts +36 -0
  104. package/dist/compile/forLoops/loopSignals.d.ts.map +1 -0
  105. package/dist/compile/forLoops/loopSignals.js +64 -0
  106. package/dist/compile/forLoops/loopSignals.js.map +1 -0
  107. package/dist/compile/forLoops/loopTraversal.d.ts +18 -0
  108. package/dist/compile/forLoops/loopTraversal.d.ts.map +1 -0
  109. package/dist/compile/forLoops/loopTraversal.js +38 -0
  110. package/dist/compile/forLoops/loopTraversal.js.map +1 -0
  111. package/dist/compile/handleConditionalChain.d.ts +15 -0
  112. package/dist/compile/handleConditionalChain.d.ts.map +1 -0
  113. package/dist/compile/handleConditionalChain.js +181 -0
  114. package/dist/compile/handleConditionalChain.js.map +1 -0
  115. package/dist/compile/index.d.ts +15 -0
  116. package/dist/compile/index.d.ts.map +1 -0
  117. package/dist/compile/index.js +19 -0
  118. package/dist/compile/index.js.map +1 -0
  119. package/dist/compile/injectScopedStyle.d.ts +16 -0
  120. package/dist/compile/injectScopedStyle.d.ts.map +1 -0
  121. package/dist/compile/injectScopedStyle.js +50 -0
  122. package/dist/compile/injectScopedStyle.js.map +1 -0
  123. package/dist/compile/nodeExpando.d.ts +12 -0
  124. package/dist/compile/nodeExpando.d.ts.map +1 -0
  125. package/dist/compile/nodeExpando.js +4 -0
  126. package/dist/compile/nodeExpando.js.map +1 -0
  127. package/dist/compile/parseHtml.d.ts +70 -0
  128. package/dist/compile/parseHtml.d.ts.map +1 -0
  129. package/dist/compile/parseHtml.js +164 -0
  130. package/dist/compile/parseHtml.js.map +1 -0
  131. package/dist/compile/pithyTreeToDom.d.ts +16 -0
  132. package/dist/compile/pithyTreeToDom.d.ts.map +1 -0
  133. package/dist/compile/pithyTreeToDom.js +118 -0
  134. package/dist/compile/pithyTreeToDom.js.map +1 -0
  135. package/dist/compile/renderChildren.d.ts +50 -0
  136. package/dist/compile/renderChildren.d.ts.map +1 -0
  137. package/dist/compile/renderChildren.js +76 -0
  138. package/dist/compile/renderChildren.js.map +1 -0
  139. package/dist/compile/ssrMode.d.ts +17 -0
  140. package/dist/compile/ssrMode.d.ts.map +1 -0
  141. package/dist/compile/ssrMode.js +20 -0
  142. package/dist/compile/ssrMode.js.map +1 -0
  143. package/dist/compile/textValue.d.ts +28 -0
  144. package/dist/compile/textValue.d.ts.map +1 -0
  145. package/dist/compile/textValue.js +30 -0
  146. package/dist/compile/textValue.js.map +1 -0
  147. package/dist/config/index.d.ts +37 -0
  148. package/dist/config/index.d.ts.map +1 -0
  149. package/dist/config/index.js +16 -0
  150. package/dist/config/index.js.map +1 -0
  151. package/dist/index.d.ts +7 -0
  152. package/dist/index.d.ts.map +1 -0
  153. package/dist/index.js +7 -0
  154. package/dist/index.js.map +1 -0
  155. package/dist/interfaces/index.d.ts +3 -0
  156. package/dist/interfaces/index.d.ts.map +1 -0
  157. package/dist/interfaces/index.js +3 -0
  158. package/dist/interfaces/index.js.map +1 -0
  159. package/dist/interfaces/ref-signal.interface.d.ts +6 -0
  160. package/dist/interfaces/ref-signal.interface.d.ts.map +1 -0
  161. package/dist/interfaces/ref-signal.interface.js +2 -0
  162. package/dist/interfaces/ref-signal.interface.js.map +1 -0
  163. package/dist/interfaces/ref.interface.d.ts +5 -0
  164. package/dist/interfaces/ref.interface.d.ts.map +1 -0
  165. package/dist/interfaces/ref.interface.js +2 -0
  166. package/dist/interfaces/ref.interface.js.map +1 -0
  167. package/dist/runtime/applyBindings.d.ts +36 -0
  168. package/dist/runtime/applyBindings.d.ts.map +1 -0
  169. package/dist/runtime/applyBindings.js +165 -0
  170. package/dist/runtime/applyBindings.js.map +1 -0
  171. package/dist/runtime/bindings/applyComponent.d.ts +3 -0
  172. package/dist/runtime/bindings/applyComponent.d.ts.map +1 -0
  173. package/dist/runtime/bindings/applyComponent.js +190 -0
  174. package/dist/runtime/bindings/applyComponent.js.map +1 -0
  175. package/dist/runtime/bindings/applyDefer.d.ts +11 -0
  176. package/dist/runtime/bindings/applyDefer.d.ts.map +1 -0
  177. package/dist/runtime/bindings/applyDefer.js +422 -0
  178. package/dist/runtime/bindings/applyDefer.js.map +1 -0
  179. package/dist/runtime/bindings/applySimple.d.ts +11 -0
  180. package/dist/runtime/bindings/applySimple.d.ts.map +1 -0
  181. package/dist/runtime/bindings/applySimple.js +346 -0
  182. package/dist/runtime/bindings/applySimple.js.map +1 -0
  183. package/dist/runtime/bindings/applyStructural.d.ts +5 -0
  184. package/dist/runtime/bindings/applyStructural.d.ts.map +1 -0
  185. package/dist/runtime/bindings/applyStructural.js +312 -0
  186. package/dist/runtime/bindings/applyStructural.js.map +1 -0
  187. package/dist/runtime/bindings/helpers.d.ts +56 -0
  188. package/dist/runtime/bindings/helpers.d.ts.map +1 -0
  189. package/dist/runtime/bindings/helpers.js +121 -0
  190. package/dist/runtime/bindings/helpers.js.map +1 -0
  191. package/dist/runtime/bindings/index.d.ts +7 -0
  192. package/dist/runtime/bindings/index.d.ts.map +1 -0
  193. package/dist/runtime/bindings/index.js +6 -0
  194. package/dist/runtime/bindings/index.js.map +1 -0
  195. package/dist/runtime/bindings/types.d.ts +105 -0
  196. package/dist/runtime/bindings/types.d.ts.map +1 -0
  197. package/dist/runtime/bindings/types.js +5 -0
  198. package/dist/runtime/bindings/types.js.map +1 -0
  199. package/dist/runtime/bootstrap.d.ts +59 -0
  200. package/dist/runtime/bootstrap.d.ts.map +1 -0
  201. package/dist/runtime/bootstrap.js +82 -0
  202. package/dist/runtime/bootstrap.js.map +1 -0
  203. package/dist/runtime/createContextProxy.d.ts +10 -0
  204. package/dist/runtime/createContextProxy.d.ts.map +1 -0
  205. package/dist/runtime/createContextProxy.js +45 -0
  206. package/dist/runtime/createContextProxy.js.map +1 -0
  207. package/dist/runtime/deferHelpers.d.ts +49 -0
  208. package/dist/runtime/deferHelpers.d.ts.map +1 -0
  209. package/dist/runtime/deferHelpers.js +65 -0
  210. package/dist/runtime/deferHelpers.js.map +1 -0
  211. package/dist/runtime/html.d.ts +23 -0
  212. package/dist/runtime/html.d.ts.map +1 -0
  213. package/dist/runtime/html.js +97 -0
  214. package/dist/runtime/html.js.map +1 -0
  215. package/dist/runtime/index.d.ts +8 -0
  216. package/dist/runtime/index.d.ts.map +1 -0
  217. package/dist/runtime/index.js +21 -0
  218. package/dist/runtime/index.js.map +1 -0
  219. package/dist/runtime/lazy.d.ts +144 -0
  220. package/dist/runtime/lazy.d.ts.map +1 -0
  221. package/dist/runtime/lazy.js +295 -0
  222. package/dist/runtime/lazy.js.map +1 -0
  223. package/dist/runtime/module-cache.d.ts +78 -0
  224. package/dist/runtime/module-cache.d.ts.map +1 -0
  225. package/dist/runtime/module-cache.js +109 -0
  226. package/dist/runtime/module-cache.js.map +1 -0
  227. package/dist/runtime/onDestroy.d.ts +29 -0
  228. package/dist/runtime/onDestroy.d.ts.map +1 -0
  229. package/dist/runtime/onDestroy.js +66 -0
  230. package/dist/runtime/onDestroy.js.map +1 -0
  231. package/dist/runtime/parseIdentifiersFromTemplate.d.ts +17 -0
  232. package/dist/runtime/parseIdentifiersFromTemplate.d.ts.map +1 -0
  233. package/dist/runtime/parseIdentifiersFromTemplate.js +68 -0
  234. package/dist/runtime/parseIdentifiersFromTemplate.js.map +1 -0
  235. package/dist/types/globals.d.ts +18 -0
  236. package/dist/types/globals.d.ts.map +1 -0
  237. package/dist/types/globals.js +4 -0
  238. package/dist/types/globals.js.map +1 -0
  239. package/dist/types/index.d.ts +11 -0
  240. package/dist/types/index.d.ts.map +1 -0
  241. package/dist/types/index.js +2 -0
  242. package/dist/types/index.js.map +1 -0
  243. package/dist/utilities/index.d.ts +3 -0
  244. package/dist/utilities/index.d.ts.map +1 -0
  245. package/dist/utilities/index.js +3 -0
  246. package/dist/utilities/index.js.map +1 -0
  247. package/dist/utilities/ref-signal.utility.d.ts +32 -0
  248. package/dist/utilities/ref-signal.utility.d.ts.map +1 -0
  249. package/dist/utilities/ref-signal.utility.js +46 -0
  250. package/dist/utilities/ref-signal.utility.js.map +1 -0
  251. package/dist/utilities/ref.untility.d.ts +37 -0
  252. package/dist/utilities/ref.untility.d.ts.map +1 -0
  253. package/dist/utilities/ref.untility.js +47 -0
  254. package/dist/utilities/ref.untility.js.map +1 -0
  255. package/package.json +55 -0
@@ -0,0 +1,164 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.compiler.html-parser",
4
+ "title": "HTML Template Parser",
5
+ "category": "compiler"
6
+ }
7
+ */
8
+ import { parse5ToPithyTree, escapeComponentTags, extractOriginalTagNames, extractOriginalAttributeNames, } from '@pithyjs/compiler';
9
+ import { pithyTreeToDom } from './pithyTreeToDom';
10
+ let _parseFragment = null;
11
+ let _loadPromise = null;
12
+ /**
13
+ * Dynamically import parse5 and cache the parseFragment function.
14
+ * Must be called before using html() for runtime template compilation.
15
+ *
16
+ * If all templates are AOT-compiled, this function never needs to be called
17
+ * and parse5 will be completely absent from the production bundle.
18
+ *
19
+ * @returns Promise that resolves when parse5 is ready
20
+ */
21
+ /** @codexApi {"parent":"pithy.compiler.html-parser","name":"loadJITCompiler","stability":"stable","signature":"() => Promise<void>"} */
22
+ export function loadJITCompiler() {
23
+ if (_parseFragment)
24
+ return Promise.resolve(); // Already loaded
25
+ if (_loadPromise)
26
+ return _loadPromise; // Loading in progress — reuse same promise
27
+ _loadPromise = import('parse5')
28
+ .then(mod => {
29
+ _parseFragment = mod.parseFragment;
30
+ _loadPromise = null;
31
+ })
32
+ .catch(err => {
33
+ // Reset so a retry can be attempted (e.g., after installing parse5)
34
+ _loadPromise = null;
35
+ // Manual `.cause` assignment instead of `new Error(msg, { cause })`
36
+ // because the project targets ES2020 which doesn't support Error cause.
37
+ const loadErr = new Error('Failed to load parse5. Install it (`pnpm add parse5`) or enable AOT compilation to avoid the runtime compiler.');
38
+ loadErr.cause = err;
39
+ throw loadErr;
40
+ });
41
+ return _loadPromise;
42
+ }
43
+ /**
44
+ * Check if the JIT compiler (parse5) has been loaded.
45
+ * Used internally by parseHtml to provide a clear error message.
46
+ * @returns `true` if parse5 parseFragment is cached
47
+ */
48
+ /** @codexApi {"parent":"pithy.compiler.html-parser","name":"isJITLoaded","stability":"internal","signature":"() => boolean"} */
49
+ export function isJITLoaded() {
50
+ return _parseFragment !== null;
51
+ }
52
+ /**
53
+ * Get the cached parseFragment function, throwing if not loaded.
54
+ * @internal
55
+ */
56
+ function getParseFragment() {
57
+ if (!_parseFragment) {
58
+ throw new Error('Runtime template compiler not loaded. Enable AOT compilation (recommended) ' +
59
+ 'or call loadJITCompiler() at startup.');
60
+ }
61
+ return _parseFragment;
62
+ }
63
+ /**
64
+ * Reset JIT compiler state. For testing only.
65
+ * @internal
66
+ */
67
+ /** @codexApi {"parent":"pithy.compiler.html-parser","name":"resetJITState","stability":"internal","signature":"() => void"} */
68
+ export function resetJITState() {
69
+ _parseFragment = null;
70
+ _loadPromise = null;
71
+ }
72
+ /**
73
+ * Pre-load parse5 synchronously for environments where it's already available
74
+ * (e.g., Node.js test environments, SSR). This is a convenience for the
75
+ * transition period — production code should use loadJITCompiler().
76
+ * @internal
77
+ */
78
+ /** @codexApi {"parent":"pithy.compiler.html-parser","name":"setParseFragment","stability":"internal","signature":"(fn: ParseFragmentFn) => void"} */
79
+ export function setParseFragment(fn) {
80
+ _parseFragment = fn;
81
+ }
82
+ /**
83
+ * Return the cached parseFragment function (or null if not loaded).
84
+ * Used by parseIdentifiersFromTemplate to reuse the same parse5 instance
85
+ * loaded via loadJITCompiler(), avoiding a separate dynamic import.
86
+ * @internal
87
+ */
88
+ /** @codexApi {"parent":"pithy.compiler.html-parser","name":"getParseFragmentFn","stability":"internal","signature":"() => ParseFragmentFn | null"} */
89
+ export function getParseFragmentFn() {
90
+ return _parseFragment;
91
+ }
92
+ // ─── Main API ────────────────────────────────────────────────────────────────
93
+ /**
94
+ * Parse an HTML template string into a DOM fragment with PithyNode metadata.
95
+ * Requires parse5 to be loaded first via `loadJITCompiler()` or `setParseFragment()`.
96
+ * Throws if the runtime compiler has not been loaded.
97
+ *
98
+ * @param html - Raw HTML template string
99
+ * @param scopeId - Unique scope identifier for style scoping
100
+ * @param context - Reactive context for expression evaluation
101
+ * @param importedIdentifiers - Set of imported component names for self-closing tag handling
102
+ * @returns Object with `fragment` (live DOM) and `pithyNodes` (AST metadata)
103
+ */
104
+ /** @codexApi {"parent":"pithy.compiler.html-parser","name":"parseHtml","stability":"stable","signature":"(html: string, scopeId: string, context: Record<string, unknown>, importedIdentifiers?: Set<string>) => { fragment: DocumentFragment; pithyNodes: PithyNode[] }"} */
105
+ export function parseHtml(html, scopeId, context, importedIdentifiers = new Set()) {
106
+ const parseFragment = getParseFragment();
107
+ // 1. Pre-process HTML to convert self-closing component tags to regular tags
108
+ const processedHtml = preprocessSelfClosingComponents(html, importedIdentifiers);
109
+ // 2. Escape PascalCase component tags so parse5 doesn't enter special
110
+ // insertion modes (e.g., "in select", "in table") that corrupt the tree.
111
+ const escapedHtml = escapeComponentTags(processedHtml);
112
+ // 3. Parse HTML into parse5 tree
113
+ const parsed = parseFragment(escapedHtml, {
114
+ sourceCodeLocationInfo: true,
115
+ });
116
+ // 4. Restore casing and tag type via your parser
117
+ // IMPORTANT: Use escapedHtml (not raw html) because parse5 reports
118
+ // sourceCodeLocation offsets based on escapedHtml. If we used raw html,
119
+ // self-closing tag expansion (e.g. <Foo/> → <Foo></Foo>) and escape
120
+ // prefixing would shift all subsequent offsets, causing casing map
121
+ // lookups to miss for components that appear after other components.
122
+ const tagNameCasingMap = extractOriginalTagNames(escapedHtml);
123
+ const attributeNameCasingMap = extractOriginalAttributeNames(escapedHtml);
124
+ const pithyNodes = parsed.childNodes
125
+ .map((n) => parse5ToPithyTree(n, importedIdentifiers, tagNameCasingMap, undefined, attributeNameCasingMap))
126
+ .filter((n) => n != null);
127
+ // 3. Compile DOM tree from PithyNodes
128
+ const fragment = pithyTreeToDom(pithyNodes, context);
129
+ // 4. Add data-scope attribute to all elements
130
+ fragment.querySelectorAll?.('*').forEach(el => {
131
+ el.setAttribute(`data-scope-${scopeId}`, '');
132
+ });
133
+ return {
134
+ fragment,
135
+ pithyNodes,
136
+ };
137
+ }
138
+ /**
139
+ * Pre-processes HTML to convert self-closing component tags to regular tags.
140
+ * This works around parse5's limitation with self-closing custom elements.
141
+ *
142
+ * @param html - The HTML template string
143
+ * @param importedIdentifiers - Set of imported component names
144
+ * @returns Processed HTML with self-closing components converted to regular tags
145
+ */
146
+ /** @codexApi {"parent":"pithy.compiler.html-parser","name":"preprocessSelfClosingComponents","stability":"stable","signature":"(html: string, importedIdentifiers: Set<string>) => string"} */
147
+ function preprocessSelfClosingComponents(html, importedIdentifiers) {
148
+ let processedHtml = html;
149
+ // Convert each imported component from self-closing to regular tag
150
+ for (const componentName of importedIdentifiers) {
151
+ // Create regex to match self-closing component tags
152
+ // Matches: <ComponentName /> or <ComponentName/>
153
+ // IMPORTANT: Use 'g' flag only (NOT 'gi') - case-sensitive matching is required
154
+ // to avoid converting native elements like <input /> to <Input></Input>
155
+ const selfClosingRegex = new RegExp(`<${componentName}(\\s[^>]*)?\\s*\\/\\s*>`, 'g');
156
+ // Replace with regular opening and closing tags
157
+ processedHtml = processedHtml.replace(selfClosingRegex, (match, attributes) => {
158
+ const attrs = attributes || '';
159
+ return `<${componentName}${attrs}></${componentName}>`;
160
+ });
161
+ }
162
+ return processedHtml;
163
+ }
164
+ //# sourceMappingURL=parseHtml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseHtml.js","sourceRoot":"","sources":["../../src/compile/parseHtml.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,GAE9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAclD,IAAI,cAAc,GAA2B,IAAI,CAAC;AAClD,IAAI,YAAY,GAAyB,IAA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E,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,QAAQ;QACR,UAAU;KACX,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,+LAA+L;AAC/L,SAAS,+BAA+B,CACtC,IAAY,EACZ,mBAAgC;IAEhC,IAAI,aAAa,GAAG,IAAI,CAAC;IAEzB,mEAAmE;IACnE,KAAK,MAAM,aAAa,IAAI,mBAAmB,EAAE,CAAC;QAChD,oDAAoD;QACpD,iDAAiD;QACjD,gFAAgF;QAChF,wEAAwE;QACxE,MAAM,gBAAgB,GAAG,IAAI,MAAM,CACjC,IAAI,aAAa,yBAAyB,EAC1C,GAAG,CACJ,CAAC;QAEF,gDAAgD;QAChD,aAAa,GAAG,aAAa,CAAC,OAAO,CACnC,gBAAgB,EAChB,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;YACpB,MAAM,KAAK,GAAG,UAAU,IAAI,EAAE,CAAC;YAC/B,OAAO,IAAI,aAAa,GAAG,KAAK,MAAM,aAAa,GAAG,CAAC;QACzD,CAAC,CACF,CAAC;IACJ,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.compiler.dom-tree",
4
+ "title": "PithyNode to DOM Tree Converter",
5
+ "category": "compiler"
6
+ }
7
+ */
8
+ import { type PithyNode } from '@pithyjs/compiler';
9
+ /**
10
+ * Converts a list of PithyNodes into a DocumentFragment of real DOM nodes.
11
+ * Component tags (isComponent: true) are rendered as placeholder elements.
12
+ * No bindings or reactivity are applied here — those are handled in bind*() functions.
13
+ */
14
+ /** @codexApi {"parent":"pithy.compiler.dom-tree","name":"pithyTreeToDom","stability":"stable","signature":"(nodes: PithyNode[], context: Record<string, any>) => DocumentFragment"} */
15
+ export declare function pithyTreeToDom(nodes: PithyNode[], context: Record<string, unknown>): DocumentFragment;
16
+ //# sourceMappingURL=pithyTreeToDom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pithyTreeToDom.d.ts","sourceRoot":"","sources":["../../src/compile/pithyTreeToDom.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAC;AAG3B;;;;GAIG;AACH,uLAAuL;AACvL,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,gBAAgB,CAWlB"}
@@ -0,0 +1,118 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.compiler.dom-tree",
4
+ "title": "PithyNode to DOM Tree Converter",
5
+ "category": "compiler"
6
+ }
7
+ */
8
+ import { SVG_TAGS, SVG_NS, forEachDirectiveAttr, } from '@pithyjs/compiler';
9
+ import { nodeExpando } from './nodeExpando';
10
+ /**
11
+ * Converts a list of PithyNodes into a DocumentFragment of real DOM nodes.
12
+ * Component tags (isComponent: true) are rendered as placeholder elements.
13
+ * No bindings or reactivity are applied here — those are handled in bind*() functions.
14
+ */
15
+ /** @codexApi {"parent":"pithy.compiler.dom-tree","name":"pithyTreeToDom","stability":"stable","signature":"(nodes: PithyNode[], context: Record<string, any>) => DocumentFragment"} */
16
+ export function pithyTreeToDom(nodes, context) {
17
+ const fragment = document.createDocumentFragment();
18
+ for (const node of nodes) {
19
+ const domNode = createDomNodeFromPithy(node, context);
20
+ if (domNode) {
21
+ fragment.appendChild(domNode);
22
+ }
23
+ }
24
+ return fragment;
25
+ }
26
+ /** @codexApi {"parent":"pithy.compiler.dom-tree","name":"createDomNodeFromPithy","stability":"stable","signature":"(node: PithyNode, context: Record<string, any>) => Node | null"} */
27
+ function createDomNodeFromPithy(node, context) {
28
+ if (node.type === 'text') {
29
+ const textNode = document.createTextNode(node.textContent ?? '');
30
+ nodeExpando(textNode).__pithyCtx = context;
31
+ return textNode;
32
+ }
33
+ if (node.type === 'slot') {
34
+ // Create comment anchor for slot
35
+ const slotName = node.slotName || '';
36
+ const anchor = document.createComment(`slot:${slotName} pid="${node.nodeId}"`);
37
+ // Store slot metadata for runtime stitching
38
+ nodeExpando(anchor).__pithyCtx = context;
39
+ nodeExpando(anchor).__nodeId = node.nodeId;
40
+ nodeExpando(anchor).__slotName = slotName;
41
+ nodeExpando(anchor).__pithyNode = node;
42
+ // Create fallback fragment factory if fallback content exists
43
+ if (node.fallbackChildren && node.fallbackChildren.length > 0) {
44
+ nodeExpando(anchor).__fallbackFactory = () => {
45
+ return pithyTreeToDom(node.fallbackChildren, context);
46
+ };
47
+ }
48
+ return anchor;
49
+ }
50
+ if (node.type === 'element') {
51
+ // For components, create placeholder element (to be upgraded later)
52
+ const tag = node.originalTagName ?? node.tagName ?? 'div';
53
+ // SVG elements need to be created in the SVG namespace
54
+ const el = SVG_TAGS.has(tag.toLowerCase())
55
+ ? document.createElementNS(SVG_NS, tag)
56
+ : document.createElement(tag);
57
+ nodeExpando(el).__pithyCtx = context;
58
+ // Store the PithyNode data for component binding to access:
59
+ // - isComponent flag (to distinguish native elements from components)
60
+ // - original attribute names (for prop name normalization)
61
+ nodeExpando(el).__pithyNode = node;
62
+ // Set static attributes
63
+ for (const [name, value] of Object.entries(node.attrs ?? {})) {
64
+ if (name.startsWith('@') || name.startsWith('[')) {
65
+ continue; // Skip PithyJS directive attributes — handled in bind* functions
66
+ }
67
+ // Use original attribute name casing (important for SVG attributes like viewBox)
68
+ const originalName = node.originalAttrs?.[name] || name;
69
+ el.setAttribute(originalName, value);
70
+ }
71
+ // @for loop - REPLACE element with anchor
72
+ if (node.directives?.for) {
73
+ // Create a comment node as placeholder
74
+ const placeholder = document.createComment(`Placeholder for loop items pid="${node.nodeId}"`);
75
+ nodeExpando(placeholder).__pithyCtx = context;
76
+ // Store the nodeId on the comment for bindForLoops to find it
77
+ if (node.nodeId) {
78
+ nodeExpando(placeholder).__nodeId = node.nodeId;
79
+ // Loop placeholders are comment nodes — discovered via __nodeId walk, not querySelectorAll (data-pid is for element nodes only)
80
+ }
81
+ // Store the original PithyNode structure for nested processing
82
+ nodeExpando(placeholder).__pithyNode = node;
83
+ return placeholder;
84
+ }
85
+ // Apply directive data-* attributes for runtime binders.
86
+ // Uses the shared mapping from @pithyjs/compiler to stay in sync with AOT codegen.
87
+ if (node.directives) {
88
+ forEachDirectiveAttr(node.directives, (attr, value) => {
89
+ el.setAttribute(attr, value);
90
+ });
91
+ // Preserve `slot` as a standard HTML attribute.
92
+ // forEachDirectiveAttr intentionally skips slot (it's consumed by content
93
+ // projection via directives.slot), but downstream binders like
94
+ // bindDeferDirectives need it as a DOM attribute for querySelector lookups
95
+ // (e.g., '[slot="placeholder"]', '[slot="error"]').
96
+ if (node.directives.slot && !el.hasAttribute('slot')) {
97
+ el.setAttribute('slot', node.directives.slot);
98
+ }
99
+ }
100
+ // Optional: add dev/debug node ID
101
+ if (node.nodeId) {
102
+ el.setAttribute('data-pid', node.nodeId);
103
+ }
104
+ else if (node.attrs?.['data-pid']) {
105
+ // Preserve existing data-pid from the original HTML
106
+ el.setAttribute('data-pid', node.attrs['data-pid']);
107
+ }
108
+ // Recursively process children
109
+ for (const child of node.children ?? []) {
110
+ const childDom = createDomNodeFromPithy(child, context);
111
+ if (childDom)
112
+ el.appendChild(childDom);
113
+ }
114
+ return el;
115
+ }
116
+ return null;
117
+ }
118
+ //# sourceMappingURL=pithyTreeToDom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pithyTreeToDom.js","sourceRoot":"","sources":["../../src/compile/pithyTreeToDom.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EACL,QAAQ,EACR,MAAM,EACN,oBAAoB,GAErB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;GAIG;AACH,uLAAuL;AACvL,MAAM,UAAU,cAAc,CAC5B,KAAkB,EAClB,OAAgC;IAEhC,MAAM,QAAQ,GAAG,QAAQ,CAAC,sBAAsB,EAA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AC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;QACtD,CAAC;QAED,+BAA+B;QAC/B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,IAAI,EAAE,EAAE,CAAC;YACxC,MAAM,QAAQ,GAAG,sBAAsB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACxD,IAAI,QAAQ;gBAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QACzC,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * If the registry renderer has set `globalThis.__pithyProjectedChildren` (a
3
+ * `DocumentFragment` of already-rendered slot children), returns and clears it —
4
+ * single-consume, so the first caller wins. This delivers construction-time
5
+ * children on the registry path. The registry path has no AST fallback, so a
6
+ * second `renderChildren()`/`captureChildren()` call returns an empty fragment.
7
+ *
8
+ * Otherwise compiles child AST nodes from the current component context through
9
+ * the full pipeline (structural + non-structural directives). This enables
10
+ * nested components inside projected content — unlike `<slot>`, which inserts
11
+ * DOM after `bindComponentTags` has already run.
12
+ *
13
+ * Use inside component functions (Stack, Grid, etc.) that need to compile
14
+ * their children without named slots or fallback content.
15
+ */
16
+ /** @codexApi {"parent":"pithy.runtime.compile-nodes","name":"renderChildren","stability":"stable","signature":"() => { el: DocumentFragment; destroy: () => void }"} */
17
+ export declare function renderChildren(): {
18
+ el: DocumentFragment;
19
+ destroy: () => void;
20
+ };
21
+ /**
22
+ * Captures projected children and clears the component context so
23
+ * inner component calls (e.g. `Heading()`, `Text()`) don't consume
24
+ * the outer component's children.
25
+ *
26
+ * After capture, the current component's context on `globalThis` is
27
+ * reset to the value of `__parentComponentContext` if present, or
28
+ * otherwise to `undefined`. In the current core implementation,
29
+ * `__parentComponentContext` is not set by the runtime, so this
30
+ * effectively clears the active component context to prevent child
31
+ * leakage into inner component calls.
32
+ *
33
+ * **Important invariant:** This function must be called exactly once per
34
+ * component, before any inner component function calls. It consumes the
35
+ * current context's children — a second call would return an empty fragment.
36
+ * After this call, the caller must not rely on reading its own context
37
+ * properties from `globalThis.__pithyComponentContext`.
38
+ *
39
+ * For 3+ levels of nesting (e.g., section A → section B → atoms), each
40
+ * level should call `captureChildren()` independently. Any multi-level
41
+ * parent restoration depends on `__parentComponentContext` being managed
42
+ * by external tooling; the core library only performs a best-effort reset
43
+ * from that property when present.
44
+ */
45
+ /** @codexApi {"parent":"pithy.runtime.compile-nodes","name":"captureChildren","stability":"stable","signature":"() => { el: DocumentFragment; destroy: () => void }"} */
46
+ export declare function captureChildren(): {
47
+ el: DocumentFragment;
48
+ destroy: () => void;
49
+ };
50
+ //# sourceMappingURL=renderChildren.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderChildren.d.ts","sourceRoot":"","sources":["../../src/compile/renderChildren.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,wKAAwK;AACxK,wBAAgB,cAAc,IAAI;IAChC,EAAE,EAAE,gBAAgB,CAAC;IACrB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CA8BA;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,yKAAyK;AACzK,wBAAgB,eAAe,IAAI;IACjC,EAAE,EAAE,gBAAgB,CAAC;IACrB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CASA"}
@@ -0,0 +1,76 @@
1
+ import { compileNodes } from './compileNodes';
2
+ import { pithyGlobals } from '../types/globals';
3
+ /**
4
+ * If the registry renderer has set `globalThis.__pithyProjectedChildren` (a
5
+ * `DocumentFragment` of already-rendered slot children), returns and clears it —
6
+ * single-consume, so the first caller wins. This delivers construction-time
7
+ * children on the registry path. The registry path has no AST fallback, so a
8
+ * second `renderChildren()`/`captureChildren()` call returns an empty fragment.
9
+ *
10
+ * Otherwise compiles child AST nodes from the current component context through
11
+ * the full pipeline (structural + non-structural directives). This enables
12
+ * nested components inside projected content — unlike `<slot>`, which inserts
13
+ * DOM after `bindComponentTags` has already run.
14
+ *
15
+ * Use inside component functions (Stack, Grid, etc.) that need to compile
16
+ * their children without named slots or fallback content.
17
+ */
18
+ /** @codexApi {"parent":"pithy.runtime.compile-nodes","name":"renderChildren","stability":"stable","signature":"() => { el: DocumentFragment; destroy: () => void }"} */
19
+ export function renderChildren() {
20
+ const globalScope = globalThis;
21
+ const injected = globalScope.__pithyProjectedChildren;
22
+ if (injected) {
23
+ globalScope.__pithyProjectedChildren = undefined;
24
+ return { el: injected, destroy: () => { } };
25
+ }
26
+ const componentCtx = pithyGlobals().__pithyComponentContext;
27
+ // A parent composing atoms by direct call after captureChildren() cleared its
28
+ // context is still mid-render (`rendering` truthy) — not the misuse this guards
29
+ // against, so a consumed context alone must not trigger the warning.
30
+ const rendering = pithyGlobals().__pithyRenderingComponent;
31
+ if (import.meta.env?.DEV && !componentCtx && !rendering) {
32
+ console.warn('[renderChildren] Called outside component render context');
33
+ }
34
+ const childAstNodes = componentCtx?.__childAstNodes ?? [];
35
+ // Strip internal __ properties, keep parent scope (includes components, signals, etc.)
36
+ const parentCtx = componentCtx
37
+ ? Object.fromEntries(Object.entries(componentCtx).filter(([k]) => !k.startsWith('__')))
38
+ : {};
39
+ return compileNodes(childAstNodes, parentCtx);
40
+ }
41
+ /**
42
+ * Captures projected children and clears the component context so
43
+ * inner component calls (e.g. `Heading()`, `Text()`) don't consume
44
+ * the outer component's children.
45
+ *
46
+ * After capture, the current component's context on `globalThis` is
47
+ * reset to the value of `__parentComponentContext` if present, or
48
+ * otherwise to `undefined`. In the current core implementation,
49
+ * `__parentComponentContext` is not set by the runtime, so this
50
+ * effectively clears the active component context to prevent child
51
+ * leakage into inner component calls.
52
+ *
53
+ * **Important invariant:** This function must be called exactly once per
54
+ * component, before any inner component function calls. It consumes the
55
+ * current context's children — a second call would return an empty fragment.
56
+ * After this call, the caller must not rely on reading its own context
57
+ * properties from `globalThis.__pithyComponentContext`.
58
+ *
59
+ * For 3+ levels of nesting (e.g., section A → section B → atoms), each
60
+ * level should call `captureChildren()` independently. Any multi-level
61
+ * parent restoration depends on `__parentComponentContext` being managed
62
+ * by external tooling; the core library only performs a best-effort reset
63
+ * from that property when present.
64
+ */
65
+ /** @codexApi {"parent":"pithy.runtime.compile-nodes","name":"captureChildren","stability":"stable","signature":"() => { el: DocumentFragment; destroy: () => void }"} */
66
+ export function captureChildren() {
67
+ const g = pithyGlobals();
68
+ const prevCtx = g.__pithyComponentContext;
69
+ const result = renderChildren();
70
+ // Clear context so inner component calls start fresh.
71
+ // If there was a parent context, it will be restored by the parent's
72
+ // own render cycle — we only need to prevent child leakage here.
73
+ g.__pithyComponentContext = prevCtx?.__parentComponentContext ?? undefined;
74
+ return result;
75
+ }
76
+ //# sourceMappingURL=renderChildren.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderChildren.js","sourceRoot":"","sources":["../../src/compile/renderChildren.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;;;;;;;;;;;;;GAcG;AACH,wKAAwK;AACxK,MAAM,UAAU,cAAc;IAI5B,MAAM,WAAW,GAAG,UAEnB,CAAC;IACF,MAAM,QAAQ,GAAG,WAAW,CAAC,wBAAwB,CAAC;IACtD,IAAI,QAAQ,EAAE,CAAC;QACb,WAAW,CAAC,wBAAwB,GAAG,SAAS,CAAC;QACjD,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;IAC7C,CAAC;IAED,MAAM,YAAY,GAAG,YAAY,EAAE,CAAC,uBAAuB,CAAC;IAE5D,8EAA8E;IAC9E,gFAAgF;IAChF,qEAAqE;IACrE,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC,yBAAyB,CAAC;IAC3D,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,YAAY,IAAI,CAAC,SAAS,EAAE,CAAC;QACxD,OAAO,CAAC,IAAI,CAAC,0DAA0D,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,aAAa,GAAgB,YAAY,EAAE,eAAe,IAAI,EAAE,CAAC;IAEvE,uFAAuF;IACvF,MAAM,SAAS,GAA4B,YAAY;QACrD,CAAC,CAAC,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAClE;QACH,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO,YAAY,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,yKAAyK;AACzK,MAAM,UAAU,eAAe;IAI7B,MAAM,CAAC,GAAG,YAAY,EAAE,CAAC;IACzB,MAAM,OAAO,GAAG,CAAC,CAAC,uBAAuB,CAAC;IAC1C,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,sDAAsD;IACtD,qEAAqE;IACrE,iEAAiE;IACjE,CAAC,CAAC,uBAAuB,GAAG,OAAO,EAAE,wBAAwB,IAAI,SAAS,CAAC;IAC3E,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,17 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.runtime.ssr-mode",
4
+ "title": "SSR Mode Detection",
5
+ "category": "runtime"
6
+ }
7
+ */
8
+ /**
9
+ * Checks if the current execution is in SSR (Server-Side Rendering) mode.
10
+ *
11
+ * The SSR package sets `globalThis.__PITHY_SSR__` when the environment is active.
12
+ * Core binding functions check this flag to skip reactive effects and evaluate
13
+ * directives synchronously during SSR.
14
+ */
15
+ /** @codexApi {"parent":"pithy.runtime.ssr-mode","name":"isSSRMode","stability":"stable","signature":"() => boolean"} */
16
+ export declare function isSSRMode(): boolean;
17
+ //# sourceMappingURL=ssrMode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssrMode.d.ts","sourceRoot":"","sources":["../../src/compile/ssrMode.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAIF;;;;;;GAMG;AACH,wHAAwH;AACxH,wBAAgB,SAAS,IAAI,OAAO,CAEnC"}
@@ -0,0 +1,20 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.runtime.ssr-mode",
4
+ "title": "SSR Mode Detection",
5
+ "category": "runtime"
6
+ }
7
+ */
8
+ import { pithyGlobals } from '../types/globals';
9
+ /**
10
+ * Checks if the current execution is in SSR (Server-Side Rendering) mode.
11
+ *
12
+ * The SSR package sets `globalThis.__PITHY_SSR__` when the environment is active.
13
+ * Core binding functions check this flag to skip reactive effects and evaluate
14
+ * directives synchronously during SSR.
15
+ */
16
+ /** @codexApi {"parent":"pithy.runtime.ssr-mode","name":"isSSRMode","stability":"stable","signature":"() => boolean"} */
17
+ export function isSSRMode() {
18
+ return !!pithyGlobals().__PITHY_SSR__;
19
+ }
20
+ //# sourceMappingURL=ssrMode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssrMode.js","sourceRoot":"","sources":["../../src/compile/ssrMode.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;;;;;GAMG;AACH,wHAAwH;AACxH,MAAM,UAAU,SAAS;IACvB,OAAO,CAAC,CAAC,YAAY,EAAE,CAAC,aAAa,CAAC;AACxC,CAAC"}
@@ -0,0 +1,28 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.runtime.dom-safety",
4
+ "title": "DOM Text Safety",
5
+ "category": "runtime"
6
+ }
7
+ */
8
+ /**
9
+ * Coerce an interpolated value to display text for a DOM **text node**
10
+ * (`.nodeValue` / `.textContent`).
11
+ *
12
+ * Text nodes are inherently XSS-safe: the browser stores the string as literal
13
+ * character data and never parses it as markup. So `{{ expr }}` interpolations
14
+ * must NOT be HTML-escaped — escaping turns `>` into `&gt;`, which then renders
15
+ * as the *visible* text `&gt;` (e.g. a TS signature `() => Promise<void>` shows
16
+ * as `() =&gt; Promise&lt;void&gt;`). Assigning the raw string is both correct
17
+ * and safe: `textNode.nodeValue = '<img onerror=…>'` creates a text node, not
18
+ * an element.
19
+ *
20
+ * Internal helper — not part of the public package API (intentionally absent
21
+ * from the barrel / package exports).
22
+ *
23
+ * @param input - Any value being interpolated into a text node
24
+ * @returns The value as a plain string (no HTML escaping)
25
+ */
26
+ /** @codexApi {"parent":"pithy.runtime.dom-safety","name":"toTextValue","stability":"internal","signature":"(input: unknown) => string"} */
27
+ export declare function toTextValue(input: unknown): string;
28
+ //# sourceMappingURL=textValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textValue.d.ts","sourceRoot":"","sources":["../../src/compile/textValue.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,2IAA2I;AAC3I,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAElD"}
@@ -0,0 +1,30 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.runtime.dom-safety",
4
+ "title": "DOM Text Safety",
5
+ "category": "runtime"
6
+ }
7
+ */
8
+ /**
9
+ * Coerce an interpolated value to display text for a DOM **text node**
10
+ * (`.nodeValue` / `.textContent`).
11
+ *
12
+ * Text nodes are inherently XSS-safe: the browser stores the string as literal
13
+ * character data and never parses it as markup. So `{{ expr }}` interpolations
14
+ * must NOT be HTML-escaped — escaping turns `>` into `&gt;`, which then renders
15
+ * as the *visible* text `&gt;` (e.g. a TS signature `() => Promise<void>` shows
16
+ * as `() =&gt; Promise&lt;void&gt;`). Assigning the raw string is both correct
17
+ * and safe: `textNode.nodeValue = '<img onerror=…>'` creates a text node, not
18
+ * an element.
19
+ *
20
+ * Internal helper — not part of the public package API (intentionally absent
21
+ * from the barrel / package exports).
22
+ *
23
+ * @param input - Any value being interpolated into a text node
24
+ * @returns The value as a plain string (no HTML escaping)
25
+ */
26
+ /** @codexApi {"parent":"pithy.runtime.dom-safety","name":"toTextValue","stability":"internal","signature":"(input: unknown) => string"} */
27
+ export function toTextValue(input) {
28
+ return String(input);
29
+ }
30
+ //# sourceMappingURL=textValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textValue.js","sourceRoot":"","sources":["../../src/compile/textValue.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,2IAA2I;AAC3I,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
@@ -0,0 +1,37 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.config.system",
4
+ "title": "Framework Configuration System",
5
+ "category": "runtime"
6
+ }
7
+ */
8
+ export interface PithyConfig {
9
+ /**
10
+ * Enable visual highlighting of DOM updates in development mode.
11
+ * NOTE: Only works with span-wrapped interpolations (textInterpolationMode: 'span' or 'auto').
12
+ * Text nodes cannot be styled, so no visual feedback in 'text-node' mode.
13
+ * @default true
14
+ */
15
+ devHighlightDomUpdates?: boolean;
16
+ /** Color for update highlights @default 'rgba(11, 205, 118, 0.8)' */
17
+ highlightColor?: string;
18
+ /** Duration of highlight animation in seconds @default 0.3 */
19
+ highlightDuration?: number;
20
+ /**
21
+ * Automatically wrap signal expressions in <span> for visual feedback.
22
+ * Only applies when textInterpolationMode is 'auto'.
23
+ * @default false
24
+ */
25
+ autoWrapSignals?: boolean;
26
+ /**
27
+ * How to render text interpolations:
28
+ * - 'text-node': Maximum performance, bare text nodes (no visual feedback)
29
+ * - 'span': Wrapped in spans, visual feedback enabled (extra DOM nodes)
30
+ * - 'auto': Smart mode - respects autoWrapSignals setting
31
+ * @default 'text-node'
32
+ */
33
+ textInterpolationMode?: 'text-node' | 'span' | 'auto';
34
+ }
35
+ /** @codexApi {"parent":"pithy.config.system","name":"defaultConfig","stability":"stable","signature":"PithyConfig"} */
36
+ export declare const defaultConfig: PithyConfig;
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,MAAM,WAAW,WAAW;IAC1B;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC,qEAAqE;IACrE,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,8DAA8D;IAC9D,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;CACvD;AAED,uHAAuH;AACvH,eAAO,MAAM,aAAa,EAAE,WAM3B,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.config.system",
4
+ "title": "Framework Configuration System",
5
+ "category": "runtime"
6
+ }
7
+ */
8
+ /** @codexApi {"parent":"pithy.config.system","name":"defaultConfig","stability":"stable","signature":"PithyConfig"} */
9
+ export const defaultConfig = {
10
+ devHighlightDomUpdates: true,
11
+ highlightColor: 'rgba(11, 205, 118, 0.8)',
12
+ highlightDuration: 0.3,
13
+ autoWrapSignals: false, // Keep false for maximum performance (text nodes only)
14
+ textInterpolationMode: 'text-node', // Use text nodes with comment anchors (Solid.js approach) for best performance
15
+ };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAkCF,uHAAuH;AACvH,MAAM,CAAC,MAAM,aAAa,GAAgB;IACxC,sBAAsB,EAAE,IAAI;IAC5B,cAAc,EAAE,yBAAyB;IACzC,iBAAiB,EAAE,GAAG;IACtB,eAAe,EAAE,KAAK,EAAE,uDAAuD;IAC/E,qBAAqB,EAAE,WAAW,EAAE,+EAA+E;CACpH,CAAC"}