@pithyjs/core 0.1.0-beta.0 → 0.1.0-beta.10

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 (226) hide show
  1. package/README.md +37 -6
  2. package/dist/a11y/focus-trap.d.ts.map +1 -1
  3. package/dist/a11y/focus-trap.js +2 -0
  4. package/dist/a11y/focus-trap.js.map +1 -1
  5. package/dist/a11y/index.d.ts +4 -4
  6. package/dist/a11y/index.js +4 -4
  7. package/dist/a11y/index.js.map +1 -1
  8. package/dist/a11y/keyboard-utils.js.map +1 -1
  9. package/dist/a11y/roving-tabindex.js.map +1 -1
  10. package/dist/a11y/skip-link.js.map +1 -1
  11. package/dist/compile/bindSwitchCases.d.ts +8 -3
  12. package/dist/compile/bindSwitchCases.d.ts.map +1 -1
  13. package/dist/compile/bindSwitchCases.js +113 -177
  14. package/dist/compile/bindSwitchCases.js.map +1 -1
  15. package/dist/compile/binds/bindBoundAttributes.d.ts +1 -0
  16. package/dist/compile/binds/bindBoundAttributes.d.ts.map +1 -1
  17. package/dist/compile/binds/bindBoundAttributes.js +24 -2
  18. package/dist/compile/binds/bindBoundAttributes.js.map +1 -1
  19. package/dist/compile/binds/bindClassDirectives.d.ts +3 -0
  20. package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -1
  21. package/dist/compile/binds/bindClassDirectives.js +59 -21
  22. package/dist/compile/binds/bindClassDirectives.js.map +1 -1
  23. package/dist/compile/binds/bindComponentsTags.d.ts +2 -0
  24. package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
  25. package/dist/compile/binds/bindComponentsTags.js +171 -74
  26. package/dist/compile/binds/bindComponentsTags.js.map +1 -1
  27. package/dist/compile/binds/bindConditionals.d.ts +2 -2
  28. package/dist/compile/binds/bindConditionals.d.ts.map +1 -1
  29. package/dist/compile/binds/bindConditionals.js +22 -5
  30. package/dist/compile/binds/bindConditionals.js.map +1 -1
  31. package/dist/compile/binds/bindDefaultTwoWay.d.ts.map +1 -1
  32. package/dist/compile/binds/bindDefaultTwoWay.js +2 -1
  33. package/dist/compile/binds/bindDefaultTwoWay.js.map +1 -1
  34. package/dist/compile/binds/bindDeferDirectives.d.ts.map +1 -1
  35. package/dist/compile/binds/bindDeferDirectives.js +45 -15
  36. package/dist/compile/binds/bindDeferDirectives.js.map +1 -1
  37. package/dist/compile/binds/bindErrorBoundary.d.ts +13 -2
  38. package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
  39. package/dist/compile/binds/bindErrorBoundary.js +25 -10
  40. package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
  41. package/dist/compile/binds/bindEventHandlers.js +2 -2
  42. package/dist/compile/binds/bindEventHandlers.js.map +1 -1
  43. package/dist/compile/binds/bindRefDirectives.js.map +1 -1
  44. package/dist/compile/binds/bindStyleDirectives.d.ts +17 -0
  45. package/dist/compile/binds/bindStyleDirectives.d.ts.map +1 -0
  46. package/dist/compile/binds/bindStyleDirectives.js +47 -0
  47. package/dist/compile/binds/bindStyleDirectives.js.map +1 -0
  48. package/dist/compile/binds/bindTextInterpolations.d.ts +2 -1
  49. package/dist/compile/binds/bindTextInterpolations.d.ts.map +1 -1
  50. package/dist/compile/binds/bindTextInterpolations.js +55 -17
  51. package/dist/compile/binds/bindTextInterpolations.js.map +1 -1
  52. package/dist/compile/binds/directiveRegistry.js.map +1 -1
  53. package/dist/compile/binds/forwardedAttrs.d.ts +22 -0
  54. package/dist/compile/binds/forwardedAttrs.d.ts.map +1 -0
  55. package/dist/compile/binds/forwardedAttrs.js +66 -0
  56. package/dist/compile/binds/forwardedAttrs.js.map +1 -0
  57. package/dist/compile/binds/propNames.d.ts +14 -0
  58. package/dist/compile/binds/propNames.d.ts.map +1 -0
  59. package/dist/compile/binds/propNames.js +116 -0
  60. package/dist/compile/binds/propNames.js.map +1 -0
  61. package/dist/compile/compileExpression.js.map +1 -1
  62. package/dist/compile/compileNodes.d.ts.map +1 -1
  63. package/dist/compile/compileNodes.js +6 -3
  64. package/dist/compile/compileNodes.js.map +1 -1
  65. package/dist/compile/compileTemplate.d.ts +3 -4
  66. package/dist/compile/compileTemplate.d.ts.map +1 -1
  67. package/dist/compile/compileTemplate.js +28 -31
  68. package/dist/compile/compileTemplate.js.map +1 -1
  69. package/dist/compile/componentResult.d.ts +100 -0
  70. package/dist/compile/componentResult.d.ts.map +1 -0
  71. package/dist/compile/componentResult.js +138 -0
  72. package/dist/compile/componentResult.js.map +1 -0
  73. package/dist/compile/contentProjection.d.ts +1 -1
  74. package/dist/compile/contentProjection.d.ts.map +1 -1
  75. package/dist/compile/contentProjection.js +32 -15
  76. package/dist/compile/contentProjection.js.map +1 -1
  77. package/dist/compile/forLoops/bindForLoops.d.ts +2 -2
  78. package/dist/compile/forLoops/bindForLoops.d.ts.map +1 -1
  79. package/dist/compile/forLoops/bindForLoops.js +9 -22
  80. package/dist/compile/forLoops/bindForLoops.js.map +1 -1
  81. package/dist/compile/forLoops/createLoopManager.d.ts +6 -3
  82. package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -1
  83. package/dist/compile/forLoops/createLoopManager.js +144 -114
  84. package/dist/compile/forLoops/createLoopManager.js.map +1 -1
  85. package/dist/compile/forLoops/index.d.ts +5 -5
  86. package/dist/compile/forLoops/index.js +5 -5
  87. package/dist/compile/forLoops/index.js.map +1 -1
  88. package/dist/compile/forLoops/loopHelpers.d.ts +6 -0
  89. package/dist/compile/forLoops/loopHelpers.d.ts.map +1 -1
  90. package/dist/compile/forLoops/loopHelpers.js +17 -0
  91. package/dist/compile/forLoops/loopHelpers.js.map +1 -1
  92. package/dist/compile/forLoops/loopSignals.js +2 -2
  93. package/dist/compile/forLoops/loopSignals.js.map +1 -1
  94. package/dist/compile/forLoops/loopTraversal.js +2 -2
  95. package/dist/compile/forLoops/loopTraversal.js.map +1 -1
  96. package/dist/compile/handleConditionalChain.d.ts +2 -2
  97. package/dist/compile/handleConditionalChain.d.ts.map +1 -1
  98. package/dist/compile/handleConditionalChain.js +21 -83
  99. package/dist/compile/handleConditionalChain.js.map +1 -1
  100. package/dist/compile/index.d.ts +17 -14
  101. package/dist/compile/index.d.ts.map +1 -1
  102. package/dist/compile/index.js +28 -12
  103. package/dist/compile/index.js.map +1 -1
  104. package/dist/compile/injectScopedStyle.js.map +1 -1
  105. package/dist/compile/nodeExpando.d.ts +6 -0
  106. package/dist/compile/nodeExpando.d.ts.map +1 -1
  107. package/dist/compile/nodeExpando.js.map +1 -1
  108. package/dist/compile/parseHtml.d.ts.map +1 -1
  109. package/dist/compile/parseHtml.js +2 -2
  110. package/dist/compile/parseHtml.js.map +1 -1
  111. package/dist/compile/pithyTreeToDom.js +1 -1
  112. package/dist/compile/pithyTreeToDom.js.map +1 -1
  113. package/dist/compile/renderBranch.d.ts +13 -0
  114. package/dist/compile/renderBranch.d.ts.map +1 -0
  115. package/dist/compile/renderBranch.js +65 -0
  116. package/dist/compile/renderBranch.js.map +1 -0
  117. package/dist/compile/renderChildren.d.ts +17 -0
  118. package/dist/compile/renderChildren.d.ts.map +1 -1
  119. package/dist/compile/renderChildren.js +22 -3
  120. package/dist/compile/renderChildren.js.map +1 -1
  121. package/dist/compile/ssrCrashes.d.ts +116 -0
  122. package/dist/compile/ssrCrashes.d.ts.map +1 -0
  123. package/dist/compile/ssrCrashes.js +173 -0
  124. package/dist/compile/ssrCrashes.js.map +1 -0
  125. package/dist/compile/ssrMode.js +1 -1
  126. package/dist/compile/ssrMode.js.map +1 -1
  127. package/dist/compile/textValue.js.map +1 -1
  128. package/dist/compile/trimBlankEdges.d.ts +2 -0
  129. package/dist/compile/trimBlankEdges.d.ts.map +1 -0
  130. package/dist/compile/trimBlankEdges.js +15 -0
  131. package/dist/compile/trimBlankEdges.js.map +1 -0
  132. package/dist/config/index.js.map +1 -1
  133. package/dist/index.d.ts +6 -6
  134. package/dist/index.js +6 -6
  135. package/dist/index.js.map +1 -1
  136. package/dist/interfaces/index.d.ts +2 -2
  137. package/dist/interfaces/index.js +2 -2
  138. package/dist/interfaces/index.js.map +1 -1
  139. package/dist/interfaces/ref-signal.interface.js.map +1 -1
  140. package/dist/interfaces/ref.interface.js.map +1 -1
  141. package/dist/runtime/applyBindings.d.ts +5 -5
  142. package/dist/runtime/applyBindings.d.ts.map +1 -1
  143. package/dist/runtime/applyBindings.js +97 -21
  144. package/dist/runtime/applyBindings.js.map +1 -1
  145. package/dist/runtime/bindings/applyComponent.d.ts +2 -2
  146. package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
  147. package/dist/runtime/bindings/applyComponent.js +137 -39
  148. package/dist/runtime/bindings/applyComponent.js.map +1 -1
  149. package/dist/runtime/bindings/applyDefer.d.ts +1 -1
  150. package/dist/runtime/bindings/applyDefer.d.ts.map +1 -1
  151. package/dist/runtime/bindings/applyDefer.js +46 -18
  152. package/dist/runtime/bindings/applyDefer.js.map +1 -1
  153. package/dist/runtime/bindings/applySimple.d.ts +2 -1
  154. package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
  155. package/dist/runtime/bindings/applySimple.js +70 -14
  156. package/dist/runtime/bindings/applySimple.js.map +1 -1
  157. package/dist/runtime/bindings/applyStructural.d.ts +1 -1
  158. package/dist/runtime/bindings/applyStructural.d.ts.map +1 -1
  159. package/dist/runtime/bindings/applyStructural.js +58 -68
  160. package/dist/runtime/bindings/applyStructural.js.map +1 -1
  161. package/dist/runtime/bindings/helpers.d.ts +1 -1
  162. package/dist/runtime/bindings/helpers.js +1 -1
  163. package/dist/runtime/bindings/helpers.js.map +1 -1
  164. package/dist/runtime/bindings/index.d.ts +6 -6
  165. package/dist/runtime/bindings/index.d.ts.map +1 -1
  166. package/dist/runtime/bindings/index.js +5 -5
  167. package/dist/runtime/bindings/index.js.map +1 -1
  168. package/dist/runtime/bindings/types.d.ts +12 -1
  169. package/dist/runtime/bindings/types.d.ts.map +1 -1
  170. package/dist/runtime/bindings/types.js.map +1 -1
  171. package/dist/runtime/bootstrap.d.ts +1 -1
  172. package/dist/runtime/bootstrap.js +1 -1
  173. package/dist/runtime/bootstrap.js.map +1 -1
  174. package/dist/runtime/createContextProxy.js.map +1 -1
  175. package/dist/runtime/deferHelpers.d.ts +1 -1
  176. package/dist/runtime/deferHelpers.js.map +1 -1
  177. package/dist/runtime/html.d.ts.map +1 -1
  178. package/dist/runtime/html.js +6 -5
  179. package/dist/runtime/html.js.map +1 -1
  180. package/dist/runtime/index.d.ts +6 -5
  181. package/dist/runtime/index.d.ts.map +1 -1
  182. package/dist/runtime/index.js +7 -5
  183. package/dist/runtime/index.js.map +1 -1
  184. package/dist/runtime/lazy.js +1 -1
  185. package/dist/runtime/lazy.js.map +1 -1
  186. package/dist/runtime/module-cache.js.map +1 -1
  187. package/dist/runtime/onDestroy.d.ts +7 -0
  188. package/dist/runtime/onDestroy.d.ts.map +1 -1
  189. package/dist/runtime/onDestroy.js +16 -1
  190. package/dist/runtime/onDestroy.js.map +1 -1
  191. package/dist/runtime/parseIdentifiersFromTemplate.js +1 -1
  192. package/dist/runtime/parseIdentifiersFromTemplate.js.map +1 -1
  193. package/dist/runtime/resource/createAction.d.ts +44 -0
  194. package/dist/runtime/resource/createAction.d.ts.map +1 -0
  195. package/dist/runtime/resource/createAction.js +102 -0
  196. package/dist/runtime/resource/createAction.js.map +1 -0
  197. package/dist/runtime/resource/createResource.d.ts +56 -0
  198. package/dist/runtime/resource/createResource.d.ts.map +1 -0
  199. package/dist/runtime/resource/createResource.js +102 -0
  200. package/dist/runtime/resource/createResource.js.map +1 -0
  201. package/dist/runtime/resource/engine.d.ts +136 -0
  202. package/dist/runtime/resource/engine.d.ts.map +1 -0
  203. package/dist/runtime/resource/engine.js +363 -0
  204. package/dist/runtime/resource/engine.js.map +1 -0
  205. package/dist/runtime/resource/index.d.ts +19 -0
  206. package/dist/runtime/resource/index.d.ts.map +1 -0
  207. package/dist/runtime/resource/index.js +18 -0
  208. package/dist/runtime/resource/index.js.map +1 -0
  209. package/dist/runtime/resource/types.d.ts +240 -0
  210. package/dist/runtime/resource/types.d.ts.map +1 -0
  211. package/dist/runtime/resource/types.js +9 -0
  212. package/dist/runtime/resource/types.js.map +1 -0
  213. package/dist/types/globals.d.ts +10 -1
  214. package/dist/types/globals.d.ts.map +1 -1
  215. package/dist/types/globals.js.map +1 -1
  216. package/dist/types/index.d.ts +15 -1
  217. package/dist/types/index.d.ts.map +1 -1
  218. package/dist/types/index.js.map +1 -1
  219. package/dist/utilities/index.d.ts +2 -2
  220. package/dist/utilities/index.js +2 -2
  221. package/dist/utilities/index.js.map +1 -1
  222. package/dist/utilities/ref-signal.utility.d.ts +1 -1
  223. package/dist/utilities/ref-signal.utility.js.map +1 -1
  224. package/dist/utilities/ref.untility.d.ts +1 -1
  225. package/dist/utilities/ref.untility.js.map +1 -1
  226. package/package.json +14 -9
@@ -6,13 +6,16 @@
6
6
  }
7
7
  */
8
8
  import { effect } from '@pithyjs/signals';
9
- import { compileExpression } from '../compileExpression';
10
- import { nodeExpando } from '../nodeExpando';
9
+ import { compileExpression } from '../compileExpression.js';
10
+ import { nodeExpando } from '../nodeExpando.js';
11
+ import { bindStyleProperties, declaredName } from './bindStyleDirectives.js';
12
+ const TOGGLE_PREFIX = 'data-class-toggle-';
11
13
  /**
12
14
  * Binds class directives like:
13
15
  * • [class.active]="isActive"
14
16
  * • [classes]="{ active: isActive() }"
15
17
  * • [classes]="['a', 'b']"
18
+ * • [classes]="'a b'"
16
19
  *
17
20
  * @param root - The root node to search for class bindings
18
21
  * @param ctx - Context object containing reactive variables and functions
@@ -24,11 +27,18 @@ export function bindClassDirectives(root, ctx, disposers) {
24
27
  // Use element's own __pithyCtx when available (projected slot content
25
28
  // carries the parent component's context via this property).
26
29
  const elCtx = nodeExpando(el).__pithyCtx || ctx;
27
- // Handle [class.someName] → data-class-toggle-someName
30
+ let declared;
28
31
  for (const attr of Array.from(el.attributes)) {
29
- if (!attr.name.startsWith('data-class-toggle-'))
32
+ if (!attr.name.startsWith(TOGGLE_PREFIX))
33
+ continue;
34
+ const expando = nodeExpando(el);
35
+ declared ?? (declared = [
36
+ ...(expando.__classToggles ?? []),
37
+ ...Object.keys(expando.__pithyNode?.directives?.classMap ?? {}),
38
+ ]);
39
+ const className = declaredName(attr.name.slice(TOGGLE_PREFIX.length), declared);
40
+ if (!className)
30
41
  continue;
31
- const className = attr.name.slice('data-class-toggle-'.length);
32
42
  const expression = attr.value;
33
43
  // Remove directive attribute after capturing to prevent double-processing
34
44
  // when component subtrees are inserted into an outer DOM that re-runs binders
@@ -52,7 +62,6 @@ export function bindClassDirectives(root, ctx, disposers) {
52
62
  });
53
63
  disposers.push(stop);
54
64
  }
55
- // Handle [classes]="{ active: isActive() }" or [classes]="['a', 'b']"
56
65
  const classGroupExpr = el.getAttribute('data-classes');
57
66
  if (classGroupExpr) {
58
67
  // Remove directive attribute after capturing to prevent double-processing
@@ -65,23 +74,10 @@ export function bindClassDirectives(root, ctx, disposers) {
65
74
  console.warn(`[PithyJS] ⚠️ Failed to compile [classes]="${classGroupExpr}"`, err);
66
75
  return;
67
76
  }
77
+ const owned = new Set();
68
78
  const stop = effect(() => {
69
79
  try {
70
- const result = evaluate();
71
- if (Array.isArray(result)) {
72
- for (const cls of result) {
73
- if (typeof cls === 'string')
74
- el.classList.add(cls);
75
- }
76
- }
77
- else if (result && typeof result === 'object') {
78
- for (const [cls, on] of Object.entries(result)) {
79
- for (const c of cls.split(/\s+/)) {
80
- if (c)
81
- el.classList.toggle(c, !!on);
82
- }
83
- }
84
- }
80
+ applyClassGroup(el, evaluate(), owned);
85
81
  }
86
82
  catch (err) {
87
83
  console.warn('[PithyJS] ⚠️ Failed to evaluate [classes]:', err);
@@ -89,6 +85,48 @@ export function bindClassDirectives(root, ctx, disposers) {
89
85
  });
90
86
  disposers.push(stop);
91
87
  }
88
+ // After the classes, so the attributes serialise in the build's order.
89
+ bindStyleProperties(el, elCtx, disposers);
92
90
  });
93
91
  }
92
+ /** @codexApi {"parent":"pithy.runtime.classes","name":"applyClassGroup","stability":"internal","signature":"(el: Element, result: unknown, owned: Set<string>) => void"} */
93
+ export function applyClassGroup(el, result, owned) {
94
+ const named = new Map();
95
+ const name = (classes, on) => {
96
+ for (const c of classes.split(/[\t\n\f\r ]+/))
97
+ if (c)
98
+ named.set(c, on);
99
+ };
100
+ if (typeof result === 'string') {
101
+ name(result, true);
102
+ }
103
+ else if (Array.isArray(result)) {
104
+ for (const cls of result)
105
+ if (typeof cls === 'string')
106
+ name(cls, true);
107
+ }
108
+ else if (result && typeof result === 'object') {
109
+ for (const [cls, on] of Object.entries(result))
110
+ name(cls, !!on);
111
+ }
112
+ else if (import.meta.env?.DEV && result) {
113
+ console.warn(`[PithyJS] ⚠️ [classes] expects a string, an array or an object, got ${typeof result}; the classes it added are removed.`);
114
+ }
115
+ // `owned` is this binding's own record, not the element's: a component's
116
+ // root `[classes]` and one forwarded from its tag share the element, and
117
+ // each may only remove the classes it added.
118
+ const previous = new Set(owned);
119
+ owned.clear();
120
+ for (const [c, on] of named) {
121
+ if (!on)
122
+ el.classList.remove(c);
123
+ else if (previous.has(c) || !el.classList.contains(c)) {
124
+ el.classList.add(c);
125
+ owned.add(c);
126
+ }
127
+ }
128
+ for (const c of previous)
129
+ if (!named.has(c))
130
+ el.classList.remove(c);
131
+ }
94
132
  //# sourceMappingURL=bindClassDirectives.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bindClassDirectives.js","sourceRoot":"","sources":["../../../src/compile/binds/bindClassDirectives.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;;;;GASG;AACH,uNAAuN;AACvN,MAAM,UAAU,mBAAmB,CACjC,IAAgC,EAChC,GAA4B,EAC5B,SAAyB;IAEzB,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAA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AK,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAClE,CAAC;SAAM,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,MAAM,EAAE,CAAC;QAC1C,OAAO,CAAC,IAAI,CACV,uEAAuE,OAAO,MAAM,qCAAqC,CAC1H,CAAC;IACJ,CAAC;IAED,yEAAyE;IACzE,yEAAyE;IACzE,6CAA6C;IAC7C,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IAChC,KAAK,CAAC,KAAK,EAAE,CAAC;IACd,KAAK,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;QAC5B,IAAI,CAAC,EAAE;YAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;aAC3B,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;YACtD,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACpB,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACf,CAAC;IACH,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,QAAQ;QAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.classes\",\n \"title\": \"Class Directive Binding System\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { effect } from '@pithyjs/signals';\nimport { compileExpression } from '../compileExpression';\nimport { nodeExpando } from '../nodeExpando';\nimport { bindStyleProperties, declaredName } from './bindStyleDirectives';\n\nconst TOGGLE_PREFIX = 'data-class-toggle-';\n\n/**\n * Binds class directives like:\n * • [class.active]=\"isActive\"\n * • [classes]=\"{ active: isActive() }\"\n * • [classes]=\"['a', 'b']\"\n * • [classes]=\"'a b'\"\n *\n * @param root - The root node to search for class bindings\n * @param ctx - Context object containing reactive variables and functions\n * @param disposers - Cleanup functions to remove subscriptions\n */\n/** @codexApi {\"parent\":\"pithy.runtime.classes\",\"name\":\"bindClassDirectives\",\"stability\":\"stable\",\"signature\":\"(root: Element | DocumentFragment, ctx: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindClassDirectives(\n root: Element | DocumentFragment,\n ctx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n root.querySelectorAll('*').forEach(el => {\n // Use element's own __pithyCtx when available (projected slot content\n // carries the parent component's context via this property).\n const elCtx = nodeExpando(el).__pithyCtx || ctx;\n\n let declared: string[] | undefined;\n for (const attr of Array.from(el.attributes)) {\n if (!attr.name.startsWith(TOGGLE_PREFIX)) continue;\n const expando = nodeExpando(el);\n declared ??= [\n ...(expando.__classToggles ?? []),\n ...Object.keys(expando.__pithyNode?.directives?.classMap ?? {}),\n ];\n const className = declaredName(\n attr.name.slice(TOGGLE_PREFIX.length),\n declared\n );\n if (!className) continue;\n const expression = attr.value;\n\n // Remove directive attribute after capturing to prevent double-processing\n // when component subtrees are inserted into an outer DOM that re-runs binders\n el.removeAttribute(attr.name);\n\n let evaluate: () => unknown;\n\n try {\n evaluate = compileExpression(expression, elCtx);\n } catch (err) {\n console.warn(\n `[PithyJS] ⚠️ Failed to compile [class.${className}]=\"${expression}\"`,\n err\n );\n return;\n }\n\n const stop = effect(() => {\n try {\n const result = evaluate();\n el.classList.toggle(className, !!result);\n } catch {\n /* ignore */\n }\n });\n\n disposers.push(stop);\n }\n\n const classGroupExpr = el.getAttribute('data-classes');\n if (classGroupExpr) {\n // Remove directive attribute after capturing to prevent double-processing\n el.removeAttribute('data-classes');\n\n let evaluate: () => unknown;\n\n try {\n evaluate = compileExpression(classGroupExpr, elCtx);\n } catch (err) {\n console.warn(\n `[PithyJS] ⚠️ Failed to compile [classes]=\"${classGroupExpr}\"`,\n err\n );\n return;\n }\n\n const owned = new Set<string>();\n const stop = effect(() => {\n try {\n applyClassGroup(el, evaluate(), owned);\n } catch (err) {\n console.warn('[PithyJS] ⚠️ Failed to evaluate [classes]:', err);\n }\n });\n\n disposers.push(stop);\n }\n\n // After the classes, so the attributes serialise in the build's order.\n bindStyleProperties(el, elCtx, disposers);\n });\n}\n\n/** @codexApi {\"parent\":\"pithy.runtime.classes\",\"name\":\"applyClassGroup\",\"stability\":\"internal\",\"signature\":\"(el: Element, result: unknown, owned: Set<string>) => void\"} */\nexport function applyClassGroup(\n el: Element,\n result: unknown,\n owned: Set<string>\n): void {\n const named = new Map<string, boolean>();\n const name = (classes: string, on: boolean) => {\n for (const c of classes.split(/[\\t\\n\\f\\r ]+/)) if (c) named.set(c, on);\n };\n if (typeof result === 'string') {\n name(result, true);\n } else if (Array.isArray(result)) {\n for (const cls of result) if (typeof cls === 'string') name(cls, true);\n } else if (result && typeof result === 'object') {\n for (const [cls, on] of Object.entries(result)) name(cls, !!on);\n } else if (import.meta.env?.DEV && result) {\n console.warn(\n `[PithyJS] ⚠️ [classes] expects a string, an array or an object, got ${typeof result}; the classes it added are removed.`\n );\n }\n\n // `owned` is this binding's own record, not the element's: a component's\n // root `[classes]` and one forwarded from its tag share the element, and\n // each may only remove the classes it added.\n const previous = new Set(owned);\n owned.clear();\n for (const [c, on] of named) {\n if (!on) el.classList.remove(c);\n else if (previous.has(c) || !el.classList.contains(c)) {\n el.classList.add(c);\n owned.add(c);\n }\n }\n for (const c of previous) if (!named.has(c)) el.classList.remove(c);\n}\n"]}
@@ -5,6 +5,8 @@
5
5
  "category": "runtime"
6
6
  }
7
7
  */
8
+ /** Test-only: forget which tags were warned about, so each render warns as a fresh process would. */
9
+ export declare function __resetComponentTagWarnings(): void;
8
10
  /**
9
11
  * Replace custom component tags (<Counter/>, <NestedComponent/>) with rendered output.
10
12
  * - Skips anything under a pending nested loop host (bind after loop expansion)
@@ -1 +1 @@
1
- {"version":3,"file":"bindComponentsTags.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindComponentsTags.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AA0JF;;;;;;GAMG;AACH,4NAA4N;AAC5N,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAmQN"}
1
+ {"version":3,"file":"bindComponentsTags.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindComponentsTags.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AA+BF,qGAAqG;AACrG,wBAAgB,2BAA2B,IAAI,IAAI,CAElD;AAsJD;;;;;;GAMG;AACH,4NAA4N;AAC5N,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAkWN"}
@@ -5,12 +5,18 @@
5
5
  "category": "runtime"
6
6
  }
7
7
  */
8
- import { compileExpression } from '../compileExpression';
9
- import { boundaryForElement, runWithBoundary, setBoundaryError, } from './bindErrorBoundary';
10
- import { collectSlotMap } from '../contentProjection';
8
+ import { compileExpression } from '../compileExpression.js';
9
+ import { boundaryForElement, runWithBoundary } from './bindErrorBoundary.js';
10
+ import { collectSlotMap } from '../contentProjection.js';
11
11
  import { nativeTags } from '@pithyjs/compiler';
12
- import { nodeExpando } from '../nodeExpando';
13
- import { pithyGlobals } from '../../types/globals';
12
+ import { collectForwardedAttrs, applyForwardedAttrs } from './forwardedAttrs.js';
13
+ import { createRoot, untrack } from '@pithyjs/signals';
14
+ import { nodeExpando } from '../nodeExpando.js';
15
+ import { pithyGlobals } from '../../types/globals.js';
16
+ import { isSSRMode } from '../ssrMode.js';
17
+ import { clearSSRRenderCrash, reportComponentFailure } from '../ssrCrashes.js';
18
+ import { isRenderableComponentEl } from '../componentResult.js';
19
+ import { parsePropNames } from './propNames.js';
14
20
  /**
15
21
  * Find the closest element-scoped context we attach in createLoopItem().
16
22
  * This is what exposes item(), gIdx(), count(), etc.
@@ -19,6 +25,10 @@ import { pithyGlobals } from '../../types/globals';
19
25
  // (e.g. a panel importing Button while using a native <button>), and
20
26
  // repeating the warning drowns out real ones.
21
27
  const warnedComponentTags = new Set();
28
+ /** Test-only: forget which tags were warned about, so each render warns as a fresh process would. */
29
+ export function __resetComponentTagWarnings() {
30
+ warnedComponentTags.clear();
31
+ }
22
32
  function nearestCtx(el, rootCtx) {
23
33
  let n = el;
24
34
  while (n) {
@@ -72,37 +82,52 @@ function evalInCtx(expr, ctx) {
72
82
  return fn(...vals);
73
83
  }
74
84
  const propNameCache = new WeakMap();
75
- /** Extract destructured prop names from `function Comp({ a, b = 1 }: Props) {}` */
76
- function extractExpectedPropNames(componentFn) {
77
- const cached = propNameCache.get(componentFn);
78
- if (cached)
79
- return cached;
80
- let result;
81
- try {
82
- const src = componentFn.toString();
83
- const m = src.match(/\(\s*\{\s*([^}]*)\s*\}/);
84
- if (!m) {
85
- result = [];
85
+ function readPropNames(componentFn) {
86
+ let cached = propNameCache.get(componentFn);
87
+ if (!cached) {
88
+ try {
89
+ cached = parsePropNames(componentFn.toString());
86
90
  }
87
- else {
88
- result = m[1]
89
- .split(',')
90
- .map(s => s.trim())
91
- .filter(Boolean)
92
- .filter(s => !s.startsWith('...'))
93
- .map(s => s.split(/[:=]/)[0].trim());
91
+ catch {
92
+ cached = { names: [], fromParam: false, exhaustive: false };
94
93
  }
94
+ propNameCache.set(componentFn, cached);
95
95
  }
96
- catch {
97
- result = [];
96
+ return cached;
97
+ }
98
+ function extractExpectedPropNames(componentFn) {
99
+ return readPropNames(componentFn).names;
100
+ }
101
+ const warnedBoundProps = new Set();
102
+ const GLOBAL_ATTRS = new Set([
103
+ 'id',
104
+ 'class',
105
+ 'style',
106
+ 'title',
107
+ 'role',
108
+ 'tabindex',
109
+ 'hidden',
110
+ ]);
111
+ function warnBoundProps(componentFn, el, componentName) {
112
+ const expected = extractExpectedPropNames(componentFn);
113
+ for (const attr of Array.from(el.attributes)) {
114
+ if (!attr.name.startsWith('data-bind-'))
115
+ continue;
116
+ const bound = attr.name.slice('data-bind-'.length);
117
+ if (GLOBAL_ATTRS.has(bound))
118
+ continue;
119
+ const prop = expected.find(p => p.toLowerCase() === bound);
120
+ const key = `${componentName} ${bound}`;
121
+ if (!prop || warnedBoundProps.has(key))
122
+ continue;
123
+ warnedBoundProps.add(key);
124
+ console.warn(`[PithyJS] <${componentName}> [${bound}] sets an attribute on the rendered root, not the \`${prop}\` prop. Write ${prop}="…" without brackets to set the prop; for a live value pass a signal or () => … if the prop accepts one.`);
98
125
  }
99
- propNameCache.set(componentFn, result);
100
- return result;
101
126
  }
102
127
  /** Dev warnings for unexpected props (only if destructuring is present). */
103
128
  function validateComponentProps(componentFn, props, componentName) {
104
- const allNames = extractExpectedPropNames(componentFn);
105
- if (allNames.length === 0)
129
+ const { names: allNames, exhaustive } = readPropNames(componentFn);
130
+ if (!exhaustive || allNames.length === 0)
106
131
  return;
107
132
  const passed = Object.keys(props);
108
133
  const expectedSet = new Set(allNames);
@@ -118,10 +143,11 @@ function validateComponentProps(componentFn, props, componentName) {
118
143
  }
119
144
  /** Map lowercased DOM attr name to expected prop name (case-insensitive). */
120
145
  function normalizePropName(authoredName, expectedProps) {
121
- if (expectedProps.length === 0)
146
+ if (expectedProps.includes(authoredName))
122
147
  return authoredName;
123
- const map = new Map(expectedProps.map(p => [p.toLowerCase(), p]));
124
- return map.get(authoredName.toLowerCase()) ?? authoredName;
148
+ const lower = authoredName.toLowerCase();
149
+ const matches = expectedProps.filter(p => p.toLowerCase() === lower);
150
+ return matches.length === 1 ? matches[0] : authoredName;
125
151
  }
126
152
  /**
127
153
  * Replace custom component tags (<Counter/>, <NestedComponent/>) with rendered output.
@@ -137,12 +163,31 @@ export function bindComponentTags(root, rootCtx, disposers) {
137
163
  const scope = root instanceof Element ? root : root;
138
164
  const elements = Array.from(scope.querySelectorAll('*'));
139
165
  for (const el of elements) {
140
- // Skip elements removed from the tree by a parent component's render
141
- if (!scope.contains(el))
166
+ // Skip elements removed from the tree by a parent component's render, or
167
+ // hidden by an `@error-boundary` that has since activated.
168
+ if (!scope.contains(el)) {
169
+ // An element that has left the tree contributes nothing to the output, so
170
+ // a crash recorded for it on an earlier DETACHED pass is stale. Leaving it
171
+ // fails a route that rendered correctly: with two crashing components
172
+ // under one boundary inside an `@if`, the detached pass records both, the
173
+ // retry lets the boundary accept the first, and accepting synchronously
174
+ // hides the second — which then never gets a retry to retract it.
175
+ if (isSSRMode())
176
+ clearSSRRenderCrash(el);
142
177
  continue;
178
+ }
143
179
  // Defer components inside not-yet-expanded loops
144
180
  if (isInsidePendingLoopZone(el))
145
181
  continue;
182
+ // A build's placeholder carries no AST: its children are DOM, which only
183
+ // the AOT binder reads.
184
+ const aotMount = nodeExpando(el).__pithyAotMount;
185
+ if (aotMount) {
186
+ // Marked as below, so the text pass skips what the component rendered.
187
+ for (const node of aotMount(disposers))
188
+ nodeExpando(node).__pithyComponentDom = true;
189
+ continue;
190
+ }
146
191
  const tag = el.tagName.toLowerCase();
147
192
  // Check if the parser marked this element as a component
148
193
  // This is the authoritative source - it checks originalTagName starts with uppercase
@@ -196,7 +241,8 @@ export function bindComponentTags(root, rootCtx, disposers) {
196
241
  const localCtx = nearestCtx(el, rootCtx); // crucial for item(), gIdx(), etc.
197
242
  // Extract expected props for validation (DEV) and prop name normalization (always)
198
243
  // This ensures case-insensitive matching works even when originalAttrs is unavailable
199
- const expectedProps = extractExpectedPropNames(componentFn);
244
+ const { names, fromParam } = readPropNames(componentFn);
245
+ const expectedProps = fromParam ? names : [];
200
246
  // Preserve originally-authored attribute names/casing from the parsed template
201
247
  // (pithyNode already extracted above for isComponent check)
202
248
  const originalAttrs = pithyNode?.originalAttrs;
@@ -214,7 +260,7 @@ export function bindComponentTags(root, rootCtx, disposers) {
214
260
  const authored = originalAttrs?.[name] ?? name;
215
261
  const propName = normalizePropName(authored, expectedProps);
216
262
  try {
217
- const value = evalInCtx(raw, localCtx);
263
+ const value = untrack(() => evalInCtx(raw, localCtx));
218
264
  props[propName] = value; // only set when evaluation succeeds
219
265
  }
220
266
  catch (err) {
@@ -230,6 +276,7 @@ export function bindComponentTags(root, rootCtx, disposers) {
230
276
  if (import.meta.env?.DEV) {
231
277
  const displayTag = pithyNode?.originalTagName || tag;
232
278
  validateComponentProps(componentFn, props, displayTag);
279
+ warnBoundProps(componentFn, el, displayTag);
233
280
  }
234
281
  // Collect content projection SlotMap from component children
235
282
  const pithyChildren = pithyNode?.children || [];
@@ -239,12 +286,14 @@ export function bindComponentTags(root, rootCtx, disposers) {
239
286
  ...localCtx,
240
287
  __slotMap: slotMap,
241
288
  __childAstNodes: pithyChildren,
289
+ __childFactory: undefined,
242
290
  };
243
291
  // Find nearest error boundary for this component
244
292
  const boundaryEl = el.closest('[data-error]');
245
293
  const boundary = boundaryForElement(boundaryEl);
246
294
  // Invoke component under boundary context; expect { el, destroy }
247
295
  let out;
296
+ let disposeSetup;
248
297
  try {
249
298
  out = runWithBoundary(boundary, () => {
250
299
  // Store the enhanced context globally for the component's html() calls to access.
@@ -264,7 +313,10 @@ export function bindComponentTags(root, rootCtx, disposers) {
264
313
  // native elements used in component implementations (e.g., <button> in Button)
265
314
  g.__pithyRenderingComponent = true;
266
315
  try {
267
- const result = componentFn(props);
316
+ const result = createRoot(disposeRoot => {
317
+ disposeSetup = disposeRoot;
318
+ return componentFn(props);
319
+ });
268
320
  return result;
269
321
  }
270
322
  finally {
@@ -278,62 +330,100 @@ export function bindComponentTags(root, rootCtx, disposers) {
278
330
  // Route sync render errors to the nearest boundary with escalation
279
331
  if (boundary) {
280
332
  const error = err instanceof Error ? err : new Error(String(err));
281
- setBoundaryError(boundary, error);
333
+ // A boundary being in scope does not mean it accepted the error: an
334
+ // already-active boundary with no free ancestor drops it (React's
335
+ // first-error-wins). A component inside that boundary's `@fallback` is
336
+ // the everyday case, and the fallback is what the user actually sees.
337
+ const accepted = reportComponentFailure(el, tag, error, boundary);
282
338
  if (import.meta.env?.DEV) {
283
- console.log(`[ErrorBoundary] Captured sync render error in <${tag}>:`, error.message);
339
+ // Say which of the two actually happened. "Captured" on a rejected
340
+ // error reports the opposite of the truth, and this branch exists
341
+ // precisely because the two are not the same.
342
+ console.log(accepted
343
+ ? `[ErrorBoundary] Captured sync render error in <${tag}>:`
344
+ : `[ErrorBoundary] Boundary already active — error from <${tag}> was NOT captured:`, error.message);
284
345
  }
285
346
  continue;
286
347
  }
287
- else {
288
- console.error(`❌ Component <${tag}> crashed during render:`, err);
289
- continue;
290
- }
348
+ // No boundary in scope *yet*. Degrading is still the right call here in
349
+ // both modes: throwing would pre-empt the retry pass that gives an
350
+ // `@error-boundary` its only chance to claim a crash raised while the
351
+ // subtree was detached.
352
+ //
353
+ // A static/server render additionally records the crash. Nobody reads a
354
+ // console during `pithy-ssg`, so this used to leave the raw <${tag}> in
355
+ // the emitted HTML while the route still counted as rendered and the CLI
356
+ // exited 0 (BUG-018). Anything still recorded when the render finishes
357
+ // makes the SSR renderer throw, and the per-route catch in `vite-ssg.ts`
358
+ // fails that route.
359
+ reportComponentFailure(el, tag, err instanceof Error ? err : new Error(String(err)), null);
360
+ console.error(`❌ Component <${tag}> crashed during render:`, err);
361
+ continue;
291
362
  }
292
- if (!out || typeof out !== 'object' || !('el' in out)) {
363
+ if (!out ||
364
+ typeof out !== 'object' ||
365
+ !('el' in out) ||
366
+ !isRenderableComponentEl(out.el, el)) {
293
367
  console.warn(`❌ Invalid render result from <${tag}>. Expected { el, destroy }`);
368
+ // Not a throw, but the same outcome as one: the raw <${tag}> is left in
369
+ // the document and the subtree never renders. Under SSR that is content
370
+ // silently missing from the emitted HTML, so it is recorded exactly like
371
+ // a crash (BUG-018). Recorded rather than merely left in place, because
372
+ // this attempt may also be retracting an earlier attempt's record.
373
+ // Same funnel as a throw: a boundary above this component gets the
374
+ // chance to claim it and render its fallback, and only an unclaimed
375
+ // failure is recorded. Bypassing this meant a component under
376
+ // `@error-boundary` that returned garbage failed the route with the
377
+ // boundary signal still null.
378
+ reportComponentFailure(el, tag, new Error(`Invalid render result from <${tag}>; expected { el, destroy }`), boundary);
379
+ disposeSetup?.();
294
380
  continue;
295
381
  }
296
382
  const { el: renderedEl, destroy } = out;
297
- // Capture class and directive attributes for forwarding to rendered root.
298
- // Directive prefixes: data-on-* (events), data-bind-* (bound attrs like
299
- // [aria-expanded]), data-class-toggle-* ([class.foo]), data-classes,
300
- // data-style-* (inline style bindings).
383
+ // Capture class and data-* attributes for forwarding to rendered root:
384
+ // directive bindings (data-on-*, data-bind-*, data-class-toggle-*,
385
+ // data-classes, data-style-*) plus any author-written data-* attribute.
301
386
  const forwardedClass = el.getAttribute('class');
302
- const directiveAttrs = [];
303
- for (const attr of Array.from(el.attributes)) {
304
- if (attr.name.startsWith('data-on-') ||
305
- attr.name.startsWith('data-bind-') ||
306
- attr.name.startsWith('data-class-toggle-') ||
307
- attr.name === 'data-classes' ||
308
- attr.name.startsWith('data-style-')) {
309
- directiveAttrs.push([attr.name, attr.value]);
310
- }
311
- }
387
+ const forwardedAttrs = collectForwardedAttrs(el);
388
+ const isFragment = renderedEl.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
312
389
  let forwardTarget = null;
313
- const hasForwardables = !!(forwardedClass || directiveAttrs.length > 0);
390
+ const hasForwardables = !!(forwardedClass || forwardedAttrs.length > 0);
314
391
  if (hasForwardables) {
315
- if (renderedEl instanceof DocumentFragment) {
316
- forwardTarget = renderedEl.firstElementChild;
392
+ if (isFragment) {
393
+ forwardTarget = renderedEl
394
+ .firstElementChild;
317
395
  if (import.meta.env?.DEV && !forwardTarget) {
318
396
  const displayTag = pithyNode?.originalTagName || tag;
319
- console.warn(`[PithyJS] <${displayTag}> has class or directive attributes but returns a fragment with no element children — forwarding skipped.`);
397
+ console.warn(`[PithyJS] <${displayTag}> has class or data-* attributes but returns a fragment with no element children — forwarding skipped.`);
320
398
  }
321
399
  }
322
- else if (renderedEl instanceof HTMLElement) {
400
+ else if (renderedEl.nodeType === Node.ELEMENT_NODE) {
323
401
  forwardTarget = renderedEl;
324
402
  }
325
403
  }
404
+ const renderedNodes = isFragment
405
+ ? Array.from(renderedEl.childNodes)
406
+ : [renderedEl];
407
+ for (const node of renderedNodes)
408
+ nodeExpando(node).__pithyComponentDom = true;
409
+ let replaced = true;
326
410
  try {
327
- if (renderedEl instanceof DocumentFragment) {
328
- el.replaceWith(...Array.from(renderedEl.childNodes));
329
- }
330
- else {
331
- el.replaceWith(renderedEl);
332
- }
411
+ el.replaceWith(...renderedNodes);
333
412
  }
334
413
  catch (err) {
414
+ // A failed replacement leaves the raw <${tag}> exactly where a crash
415
+ // would have, so it is the same content loss and is recorded the same way.
416
+ replaced = false;
417
+ reportComponentFailure(el, tag, err instanceof Error ? err : new Error(String(err)), boundary);
335
418
  console.error(`❌ Failed to replace <${tag}> with rendered DOM:`, err);
336
419
  }
420
+ // Retracted only here, and in the boundary catch above — never eagerly at
421
+ // the top of an attempt, where any early `continue` added later would
422
+ // silently drop a real record. This is the point at which the component is
423
+ // known to have produced a usable node AND to have reached the document, so
424
+ // an earlier detached attempt's crash is genuinely no longer the outcome.
425
+ if (isSSRMode() && replaced)
426
+ clearSSRRenderCrash(el);
337
427
  // Forward class from component tag onto the rendered root element
338
428
  if (forwardedClass && forwardTarget) {
339
429
  for (const cls of forwardedClass.split(/\s+/)) {
@@ -341,11 +431,18 @@ export function bindComponentTags(root, rootCtx, disposers) {
341
431
  forwardTarget.classList.add(cls);
342
432
  }
343
433
  }
344
- // Forward directive attributes so subsequent binders can attach them
345
- if (directiveAttrs.length > 0 && forwardTarget) {
346
- for (const [name, value] of directiveAttrs) {
347
- forwardTarget.setAttribute(name, value);
348
- }
434
+ // Forward captured attributes so subsequent binders can attach the bindings
435
+ if (forwardedAttrs.length > 0 && forwardTarget) {
436
+ applyForwardedAttrs(forwardTarget, forwardedAttrs, tag);
437
+ const styleProps = Object.keys(pithyNode?.directives?.styleMap ?? {});
438
+ if (styleProps.length)
439
+ nodeExpando(forwardTarget).__styleProps = styleProps;
440
+ const classToggles = Object.keys(pithyNode?.directives?.classMap ?? {});
441
+ if (classToggles.length)
442
+ nodeExpando(forwardTarget).__classToggles = classToggles;
443
+ }
444
+ if (disposeSetup) {
445
+ disposers.push(disposeSetup);
349
446
  }
350
447
  if (typeof destroy === 'function') {
351
448
  disposers.push(destroy);