@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,346 @@
1
+ import { effect, isSignal } from '@pithyjs/signals';
2
+ import { compileExpression } from '../../compile/compileExpression';
3
+ import { toTextValue } from '../../compile/textValue';
4
+ import { isSSRMode } from '../../compile/ssrMode';
5
+ import { registerBoundary, boundaryForElement, setBoundaryError, } from '../../compile/binds/bindErrorBoundary';
6
+ import { mountProjection } from '../../compile/contentProjection';
7
+ import { nearestCtx, compileWithEvent } from './helpers';
8
+ // ─── Individual binding handlers ──────────────────────────────────────────────
9
+ export function applyRef(d, el, ctx, disposers) {
10
+ const ref = ctx[d.name];
11
+ if (ref && typeof ref.set === 'function') {
12
+ ref.set(el);
13
+ disposers.push(() => ref.set(null));
14
+ }
15
+ }
16
+ export function applyError(d, el, ctx, disposers) {
17
+ // Ensure data-error attribute is set from descriptor (source of truth)
18
+ // so registerBoundary can find the signal name, even if AOT codegen
19
+ // stops emitting the transitional data-error attribute in the future.
20
+ if (d.expr && !el.getAttribute('data-error')) {
21
+ el.setAttribute('data-error', d.expr);
22
+ }
23
+ // Register el itself as an error boundary. We use registerBoundary (not
24
+ // bindErrorBoundary) because bindErrorBoundary uses querySelectorAll which
25
+ // only searches children — it would miss el itself.
26
+ registerBoundary(el, ctx, disposers);
27
+ }
28
+ export function applyProjection(d, commentMap, ctx, disposers) {
29
+ const anchor = commentMap.get(`slot:${d.name}`);
30
+ if (!anchor)
31
+ return;
32
+ const fallback = d.fallback;
33
+ const anchorExpando = anchor;
34
+ // Set expando properties that extractSlotDefs expects
35
+ anchorExpando.__slotName = d.name;
36
+ if (fallback) {
37
+ anchorExpando.__fallbackFactory = (factoryCtx) => {
38
+ const result = fallback(factoryCtx || ctx);
39
+ if (result && typeof result.destroy === 'function') {
40
+ disposers.push(result.destroy);
41
+ }
42
+ return result?.el;
43
+ };
44
+ }
45
+ // Check for SlotMap in context
46
+ const slotMap = ('__slotMap' in ctx ? ctx.__slotMap : undefined);
47
+ if (slotMap) {
48
+ const slotDefs = [
49
+ {
50
+ name: d.name,
51
+ anchor,
52
+ fallbackFactory: anchorExpando.__fallbackFactory,
53
+ },
54
+ ];
55
+ mountProjection(slotDefs, slotMap, disposers);
56
+ }
57
+ else if (fallback) {
58
+ // No projected content — mount fallback
59
+ const fallbackResult = fallback(ctx);
60
+ const parent = anchor.parentNode;
61
+ if (parent && fallbackResult?.el) {
62
+ // Capture nodes for cleanup (fragment empties itself on insert)
63
+ const nodes = fallbackResult.el instanceof DocumentFragment
64
+ ? Array.from(fallbackResult.el.childNodes)
65
+ : [fallbackResult.el];
66
+ // Insert directly — fragment preserves child order; single node is trivial
67
+ parent.insertBefore(fallbackResult.el, anchor.nextSibling);
68
+ if (typeof fallbackResult.destroy === 'function') {
69
+ disposers.push(fallbackResult.destroy);
70
+ }
71
+ disposers.push(() => {
72
+ for (const node of nodes) {
73
+ if (node.parentNode)
74
+ node.parentNode.removeChild(node);
75
+ }
76
+ });
77
+ }
78
+ }
79
+ }
80
+ export function applyBind(d, el, ctx, disposers) {
81
+ if (!(el instanceof HTMLElement))
82
+ return;
83
+ const sig = ctx[d.expr];
84
+ if (!isSignal(sig) || typeof sig.set !== 'function') {
85
+ if (import.meta.env?.DEV) {
86
+ console.warn(`[AOT @bind] "${d.expr}" must refer to a writable signal`);
87
+ }
88
+ return;
89
+ }
90
+ const prop = inferBindableProperty(el);
91
+ const target = el;
92
+ const stop = effect(() => {
93
+ const value = sig();
94
+ if (target[prop] !== value)
95
+ target[prop] = value;
96
+ });
97
+ const event = prop === 'checked' ? 'change' : 'input';
98
+ const handler = () => {
99
+ sig.set(extractBindableValue(el, prop));
100
+ };
101
+ el.addEventListener(event, handler);
102
+ disposers.push(() => {
103
+ el.removeEventListener(event, handler);
104
+ stop();
105
+ });
106
+ }
107
+ function inferBindableProperty(el) {
108
+ const tag = el.tagName.toLowerCase();
109
+ if (tag === 'input') {
110
+ const type = el.type;
111
+ if (type === 'checkbox' || type === 'radio')
112
+ return 'checked';
113
+ }
114
+ return 'value';
115
+ }
116
+ /** Extract value from element with type coercion for number inputs. */
117
+ function extractBindableValue(el, prop) {
118
+ if (prop === 'checked')
119
+ return el.checked;
120
+ const tag = el.tagName.toLowerCase();
121
+ if (tag === 'input') {
122
+ const inputEl = el;
123
+ if (inputEl.type === 'number') {
124
+ const numValue = Number(inputEl.value);
125
+ return isNaN(numValue) ? inputEl.value : numValue;
126
+ }
127
+ return inputEl.value;
128
+ }
129
+ return el[prop];
130
+ }
131
+ export function applyInterpolation(d, el, ctx, disposers) {
132
+ // Find text nodes within el that contain {{ }} markers
133
+ const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
134
+ let textNode;
135
+ const targets = [];
136
+ while ((textNode = walker.nextNode())) {
137
+ const val = textNode.nodeValue ?? '';
138
+ if (val.includes('{{'))
139
+ targets.push(textNode);
140
+ }
141
+ if (targets.length === 0 && import.meta.env?.DEV) {
142
+ console.warn(`[AOT interp] No text node with {{ }} markers found in element pid="${d.pid}"`);
143
+ }
144
+ // Process each target text node matching this interpolation descriptor
145
+ for (const node of targets) {
146
+ const localCtx = nearestCtx(node, ctx);
147
+ const parent = node.parentNode;
148
+ if (!parent)
149
+ continue;
150
+ const nextSibling = node.nextSibling;
151
+ parent.removeChild(node);
152
+ for (const part of d.parts) {
153
+ if ('s' in part) {
154
+ // Static text
155
+ parent.insertBefore(document.createTextNode(part.s), nextSibling);
156
+ }
157
+ else {
158
+ // Dynamic expression
159
+ const expr = part.e;
160
+ const startComment = document.createComment('t');
161
+ const dynText = document.createTextNode('');
162
+ const endComment = document.createComment('/t');
163
+ parent.insertBefore(startComment, nextSibling);
164
+ parent.insertBefore(dynText, nextSibling);
165
+ parent.insertBefore(endComment, nextSibling);
166
+ try {
167
+ const compiledFn = compileExpression(expr, localCtx);
168
+ if (isSSRMode()) {
169
+ try {
170
+ dynText.nodeValue = toTextValue(compiledFn());
171
+ }
172
+ catch {
173
+ dynText.nodeValue = '';
174
+ }
175
+ }
176
+ else {
177
+ let lastValue;
178
+ const stop = effect(() => {
179
+ try {
180
+ const next = toTextValue(compiledFn());
181
+ if (next !== lastValue) {
182
+ dynText.nodeValue = next;
183
+ lastValue = next;
184
+ }
185
+ }
186
+ catch {
187
+ dynText.nodeValue = '';
188
+ }
189
+ });
190
+ disposers.push(stop);
191
+ }
192
+ }
193
+ catch {
194
+ dynText.nodeValue = '';
195
+ }
196
+ }
197
+ }
198
+ // Only process the first matching text node per interpolation descriptor
199
+ break;
200
+ }
201
+ }
202
+ /** Per-element, per-event idempotency guard (mirrors JIT's BOUND_KEY symbol). */
203
+ const AOT_BOUND_KEY = Symbol('pithy:aot-bound');
204
+ function getAotBoundSet(el, eventName) {
205
+ const host = el;
206
+ const store = host[AOT_BOUND_KEY] ??
207
+ (host[AOT_BOUND_KEY] = Object.create(null));
208
+ return (store[eventName] ?? (store[eventName] = new Set()));
209
+ }
210
+ export function applyEvent(d, el, ctx, disposers) {
211
+ // Idempotency: skip if this exact event+expr combo was already bound
212
+ const boundSet = getAotBoundSet(el, d.event);
213
+ const boundKey = `${d.event}${d.mods ? '.' + d.mods.join('.') : ''}=${d.expr}`;
214
+ if (boundSet.has(boundKey))
215
+ return;
216
+ const localCtx = nearestCtx(el, ctx);
217
+ const mods = parseMods(d.mods);
218
+ const handlerExpr = d.expr;
219
+ const isSimpleIdentifier = /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(handlerExpr);
220
+ const directFn = isSimpleIdentifier && typeof localCtx[handlerExpr] === 'function'
221
+ ? localCtx[handlerExpr]
222
+ : null;
223
+ const runWithEvt = directFn ? null : compileWithEvent(handlerExpr, localCtx);
224
+ const listener = (ev) => {
225
+ if (mods.self && ev.target !== el)
226
+ return;
227
+ if (mods.prevent)
228
+ ev.preventDefault();
229
+ if (mods.stop)
230
+ ev.stopPropagation();
231
+ try {
232
+ if (directFn) {
233
+ return directFn.call(localCtx, ev);
234
+ }
235
+ else if (runWithEvt) {
236
+ const out = runWithEvt(ev, el);
237
+ if (typeof out === 'function')
238
+ return out.call(localCtx, ev);
239
+ return out;
240
+ }
241
+ }
242
+ catch (error) {
243
+ const boundaryEl = el.closest('[data-error]');
244
+ const boundary = boundaryForElement(boundaryEl);
245
+ if (boundary) {
246
+ setBoundaryError(boundary, error instanceof Error ? error : new Error(String(error)));
247
+ }
248
+ else {
249
+ throw error;
250
+ }
251
+ }
252
+ };
253
+ const options = {
254
+ capture: !!mods.capture,
255
+ passive: !!mods.passive,
256
+ once: !!mods.once,
257
+ };
258
+ el.addEventListener(d.event, listener, options);
259
+ boundSet.add(boundKey);
260
+ disposers.push(() => {
261
+ el.removeEventListener(d.event, listener, { capture: !!mods.capture });
262
+ boundSet.delete(boundKey);
263
+ });
264
+ }
265
+ function parseMods(mods) {
266
+ if (!mods)
267
+ return {};
268
+ const m = {};
269
+ for (const mod of mods)
270
+ m[mod] = true;
271
+ return m;
272
+ }
273
+ export function applyClass(d, el, ctx, disposers) {
274
+ const localCtx = nearestCtx(el, ctx);
275
+ try {
276
+ const evaluate = compileExpression(d.expr, localCtx);
277
+ const stop = effect(() => {
278
+ try {
279
+ el.classList.toggle(d.name, !!evaluate());
280
+ }
281
+ catch {
282
+ /* ignore */
283
+ }
284
+ });
285
+ disposers.push(stop);
286
+ }
287
+ catch {
288
+ /* ignore */
289
+ }
290
+ }
291
+ /** Convert camelCase to kebab-case for CSS property names. */
292
+ function toKebabCase(prop) {
293
+ return prop.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
294
+ }
295
+ export function applyStyle(d, el, ctx, disposers) {
296
+ if (!(el instanceof HTMLElement))
297
+ return;
298
+ const localCtx = nearestCtx(el, ctx);
299
+ // setProperty requires kebab-case; codegen may emit camelCase (e.g. fontSize)
300
+ const cssProp = d.prop.includes('-') ? d.prop : toKebabCase(d.prop);
301
+ try {
302
+ const evaluate = compileExpression(d.expr, localCtx);
303
+ const stop = effect(() => {
304
+ try {
305
+ const value = evaluate();
306
+ el.style.setProperty(cssProp, String(value ?? ''));
307
+ }
308
+ catch {
309
+ /* ignore */
310
+ }
311
+ });
312
+ disposers.push(stop);
313
+ }
314
+ catch {
315
+ /* ignore */
316
+ }
317
+ }
318
+ export function applyBound(d, el, ctx, disposers) {
319
+ const localCtx = nearestCtx(el, ctx);
320
+ // Compile once outside effect via compileExpression (consistent with applyClass/applyStyle).
321
+ try {
322
+ const evaluate = compileExpression(d.expr, localCtx);
323
+ const stop = effect(() => {
324
+ try {
325
+ const value = evaluate();
326
+ if (typeof value === 'boolean') {
327
+ if (value)
328
+ el.setAttribute(d.attr, '');
329
+ else
330
+ el.removeAttribute(d.attr);
331
+ }
332
+ else {
333
+ el.setAttribute(d.attr, String(value ?? ''));
334
+ }
335
+ }
336
+ catch {
337
+ /* ignore */
338
+ }
339
+ });
340
+ disposers.push(stop);
341
+ }
342
+ catch {
343
+ /* ignore invalid expression */
344
+ }
345
+ }
346
+ //# sourceMappingURL=applySimple.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applySimple.js","sourceRoot":"","sources":["../../../src/runtime/bindings/applySimple.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAgB,MAAM,iCAAiC,CAAC;AAahF,OAAO,EAAE,UAAU,EAAE,gBAAgB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export declare function applyIf(d: IfDesc, commentMap: Map<string, Comment>, ctx: BindingContext, disposers: (() => void)[]): void;
3
+ export declare function applyFor(d: ForDesc, commentMap: Map<string, Comment>, ctx: BindingContext, disposers: (() => void)[]): void;
4
+ export declare function applySwitch(d: SwitchDesc, pidMap: Map<string, Element>, ctx: BindingContext, disposers: (() => void)[]): void;
5
+ //# sourceMappingURL=applyStructural.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyStructural.d.ts","sourceRoot":"","sources":["../../../src/runtime/bindings/applyStructural.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI3E,wBAAgB,OAAO,CACrB,CAAC,EAAE,MAAM,EACT,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAgHN;AAED,wBAAgB,QAAQ,CACtB,CAAC,EAAE,OAAO,EACV,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CA0GN;AAuBD,wBAAgB,WAAW,CACzB,CAAC,EAAE,UAAU,EACb,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CA0GN"}
@@ -0,0 +1,312 @@
1
+ import { effect } from '@pithyjs/signals';
2
+ import { compileExpression } from '../../compile/compileExpression';
3
+ import { isSSRMode } from '../../compile/ssrMode';
4
+ // ─── Structural directive handlers ────────────────────────────────────────────
5
+ export function applyIf(d, commentMap, ctx, disposers) {
6
+ const anchor = commentMap.get(`if:${d.pid}`);
7
+ if (!anchor)
8
+ return;
9
+ let currentNodes = [];
10
+ let currentDisposers = [];
11
+ function clearCurrent() {
12
+ for (const fn of currentDisposers) {
13
+ try {
14
+ fn();
15
+ }
16
+ catch {
17
+ /* ignore */
18
+ }
19
+ }
20
+ currentDisposers = [];
21
+ for (const node of currentNodes) {
22
+ if (node.parentNode)
23
+ node.parentNode.removeChild(node);
24
+ }
25
+ currentNodes = [];
26
+ }
27
+ if (isSSRMode()) {
28
+ // SSR: evaluate once synchronously
29
+ let matchIndex = -1;
30
+ for (let i = 0; i < d.branches.length; i++) {
31
+ const b = d.branches[i];
32
+ if (b.expr === undefined) {
33
+ matchIndex = i;
34
+ break;
35
+ }
36
+ const fn = compileExpression(b.expr, ctx, false);
37
+ if (fn()) {
38
+ matchIndex = i;
39
+ break;
40
+ }
41
+ }
42
+ if (matchIndex >= 0) {
43
+ try {
44
+ const result = d.branches[matchIndex].factory(ctx);
45
+ if (result?.el) {
46
+ const nodes = result.el instanceof DocumentFragment
47
+ ? Array.from(result.el.childNodes)
48
+ : [result.el];
49
+ const parent = anchor.parentNode;
50
+ if (parent) {
51
+ const insertRef = anchor.nextSibling;
52
+ for (const node of nodes)
53
+ parent.insertBefore(node, insertRef);
54
+ }
55
+ if (typeof result.destroy === 'function')
56
+ disposers.push(result.destroy);
57
+ }
58
+ }
59
+ catch (err) {
60
+ if (import.meta.env?.DEV)
61
+ console.error(`[AOT @if] Factory error:`, err);
62
+ }
63
+ }
64
+ return;
65
+ }
66
+ // Pre-compile branch expressions once outside effect
67
+ const branchEvaluators = d.branches.map(b => b.expr !== undefined ? compileExpression(b.expr, ctx, false) : null);
68
+ let previousMatchIndex = -1;
69
+ const stopEffect = effect(() => {
70
+ let matchIndex = -1;
71
+ for (let i = 0; i < d.branches.length; i++) {
72
+ if (branchEvaluators[i] === null) {
73
+ matchIndex = i;
74
+ break;
75
+ }
76
+ if (branchEvaluators[i]()) {
77
+ matchIndex = i;
78
+ break;
79
+ }
80
+ }
81
+ if (matchIndex === previousMatchIndex)
82
+ return;
83
+ previousMatchIndex = matchIndex;
84
+ clearCurrent();
85
+ if (matchIndex >= 0) {
86
+ try {
87
+ const result = d.branches[matchIndex].factory(ctx);
88
+ if (result?.el) {
89
+ const nodes = result.el instanceof DocumentFragment
90
+ ? Array.from(result.el.childNodes)
91
+ : [result.el];
92
+ const parent = anchor.parentNode;
93
+ if (parent) {
94
+ const insertRef = anchor.nextSibling;
95
+ for (const node of nodes)
96
+ parent.insertBefore(node, insertRef);
97
+ }
98
+ currentNodes = nodes;
99
+ if (typeof result.destroy === 'function')
100
+ currentDisposers.push(result.destroy);
101
+ }
102
+ }
103
+ catch (err) {
104
+ if (import.meta.env?.DEV)
105
+ console.error(`[AOT @if] Factory error:`, err);
106
+ }
107
+ }
108
+ });
109
+ disposers.push(clearCurrent);
110
+ disposers.push(stopEffect);
111
+ }
112
+ export function applyFor(d, commentMap, ctx, disposers) {
113
+ const anchor = commentMap.get(`for:${d.pid}`);
114
+ if (!anchor)
115
+ return;
116
+ if (import.meta.env?.DEV && d.trackBy) {
117
+ console.warn(`[AOT @for] trackBy="${d.trackBy}" is not yet implemented — falling back to full re-render`);
118
+ }
119
+ // Track rendered items
120
+ let itemEntries = [];
121
+ function clearAll() {
122
+ for (const entry of itemEntries) {
123
+ entry.destroy();
124
+ for (const node of entry.nodes) {
125
+ if (node.parentNode)
126
+ node.parentNode.removeChild(node);
127
+ }
128
+ }
129
+ itemEntries = [];
130
+ }
131
+ if (isSSRMode()) {
132
+ const collFn = compileExpression(d.expr, ctx, []);
133
+ const collection = collFn() ?? [];
134
+ const parent = anchor.parentNode;
135
+ if (!parent)
136
+ return;
137
+ const insertBefore = anchor.nextSibling;
138
+ for (let i = 0; i < collection.length; i++) {
139
+ const itemCtx = buildItemContext(ctx, d, collection[i], i, collection.length);
140
+ try {
141
+ const result = d.factory(itemCtx);
142
+ if (result?.el) {
143
+ const nodes = result.el instanceof DocumentFragment
144
+ ? Array.from(result.el.childNodes)
145
+ : [result.el];
146
+ for (const node of nodes)
147
+ parent.insertBefore(node, insertBefore);
148
+ if (typeof result.destroy === 'function')
149
+ disposers.push(result.destroy);
150
+ }
151
+ }
152
+ catch (err) {
153
+ if (import.meta.env?.DEV)
154
+ console.error(`[AOT @for] Factory error at index ${i}:`, err);
155
+ }
156
+ }
157
+ return;
158
+ }
159
+ // Pre-compile collection expression once outside effect
160
+ const collFn = compileExpression(d.expr, ctx, []);
161
+ const stopEffect = effect(() => {
162
+ const collection = collFn() ?? [];
163
+ clearAll();
164
+ const parent = anchor.parentNode;
165
+ if (!parent)
166
+ return;
167
+ const insertBefore = anchor.nextSibling;
168
+ for (let i = 0; i < collection.length; i++) {
169
+ const itemCtx = buildItemContext(ctx, d, collection[i], i, collection.length);
170
+ try {
171
+ const result = d.factory(itemCtx);
172
+ if (!result?.el)
173
+ continue;
174
+ const nodes = result.el instanceof DocumentFragment
175
+ ? Array.from(result.el.childNodes)
176
+ : [result.el];
177
+ // Set __pithyCtx on root elements for nearestCtx resolution
178
+ for (const node of nodes) {
179
+ if (node instanceof Element)
180
+ node.__pithyCtx =
181
+ itemCtx;
182
+ parent.insertBefore(node, insertBefore);
183
+ }
184
+ const destroy = typeof result.destroy === 'function' ? result.destroy : () => { };
185
+ itemEntries.push({ nodes, destroy });
186
+ }
187
+ catch (err) {
188
+ if (import.meta.env?.DEV)
189
+ console.error(`[AOT @for] Factory error at index ${i}:`, err);
190
+ }
191
+ }
192
+ });
193
+ disposers.push(clearAll);
194
+ disposers.push(stopEffect);
195
+ }
196
+ function buildItemContext(parentCtx, d, item, index, length) {
197
+ const itemCtx = { ...parentCtx };
198
+ // Expose item as a getter function (signal-like API)
199
+ itemCtx[d.item] = () => item;
200
+ if (d.index)
201
+ itemCtx[d.index] = () => index;
202
+ // Standard loop metadata
203
+ itemCtx.$index = () => index;
204
+ itemCtx.$count = () => length;
205
+ itemCtx.$first = () => index === 0;
206
+ itemCtx.$last = () => index === length - 1;
207
+ itemCtx.$even = () => index % 2 === 0;
208
+ itemCtx.$odd = () => index % 2 !== 0;
209
+ return itemCtx;
210
+ }
211
+ export function applySwitch(d, pidMap, ctx, disposers) {
212
+ const containerEl = pidMap.get(d.pid);
213
+ if (!containerEl)
214
+ return;
215
+ let currentNodes = [];
216
+ let currentDisposers = [];
217
+ function clearCurrent() {
218
+ for (const fn of currentDisposers) {
219
+ try {
220
+ fn();
221
+ }
222
+ catch {
223
+ /* ignore */
224
+ }
225
+ }
226
+ currentDisposers = [];
227
+ for (const node of currentNodes) {
228
+ if (node.parentNode)
229
+ node.parentNode.removeChild(node);
230
+ }
231
+ currentNodes = [];
232
+ }
233
+ if (isSSRMode()) {
234
+ const switchVal = compileExpression(d.expr, ctx)();
235
+ let matchIndex = -1;
236
+ for (let i = 0; i < d.cases.length; i++) {
237
+ const c = d.cases[i];
238
+ if (c.val === undefined) {
239
+ matchIndex = i;
240
+ break;
241
+ }
242
+ const caseVal = compileExpression(c.val, ctx)();
243
+ if (caseVal === switchVal) {
244
+ matchIndex = i;
245
+ break;
246
+ }
247
+ }
248
+ if (matchIndex >= 0) {
249
+ try {
250
+ const result = d.cases[matchIndex].factory(ctx);
251
+ if (result?.el) {
252
+ const nodes = result.el instanceof DocumentFragment
253
+ ? Array.from(result.el.childNodes)
254
+ : [result.el];
255
+ for (const node of nodes)
256
+ containerEl.appendChild(node);
257
+ if (typeof result.destroy === 'function')
258
+ disposers.push(result.destroy);
259
+ }
260
+ }
261
+ catch (err) {
262
+ if (import.meta.env?.DEV)
263
+ console.error(`[AOT @switch] Factory error:`, err);
264
+ }
265
+ }
266
+ return;
267
+ }
268
+ // Pre-compile switch expression and case values once outside effect
269
+ const switchEval = compileExpression(d.expr, ctx);
270
+ const caseEvals = d.cases.map(c => c.val !== undefined ? compileExpression(c.val, ctx) : null);
271
+ let previousMatchIndex = -1;
272
+ const stopEffect = effect(() => {
273
+ const switchVal = switchEval();
274
+ let matchIndex = -1;
275
+ for (let i = 0; i < d.cases.length; i++) {
276
+ if (caseEvals[i] === null) {
277
+ matchIndex = i;
278
+ break;
279
+ }
280
+ if (caseEvals[i]() === switchVal) {
281
+ matchIndex = i;
282
+ break;
283
+ }
284
+ }
285
+ if (matchIndex === previousMatchIndex)
286
+ return;
287
+ previousMatchIndex = matchIndex;
288
+ clearCurrent();
289
+ if (matchIndex >= 0) {
290
+ try {
291
+ const result = d.cases[matchIndex].factory(ctx);
292
+ if (result?.el) {
293
+ const nodes = result.el instanceof DocumentFragment
294
+ ? Array.from(result.el.childNodes)
295
+ : [result.el];
296
+ for (const node of nodes)
297
+ containerEl.appendChild(node);
298
+ currentNodes = nodes;
299
+ if (typeof result.destroy === 'function')
300
+ currentDisposers.push(result.destroy);
301
+ }
302
+ }
303
+ catch (err) {
304
+ if (import.meta.env?.DEV)
305
+ console.error(`[AOT @switch] Factory error:`, err);
306
+ }
307
+ }
308
+ });
309
+ disposers.push(clearCurrent);
310
+ disposers.push(stopEffect);
311
+ }
312
+ //# sourceMappingURL=applyStructural.js.map