@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PithyJS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,513 @@
1
+ # @pithyjs/core
2
+
3
+ **Main runtime package** for PithyJS - a next-generation web framework centered on fine-grained reactivity and direct DOM updates.
4
+
5
+ ## Overview
6
+
7
+ `@pithyjs/core` combines reactive signals, template compilation, and directive binding into a unified runtime. It provides:
8
+
9
+ - **Fine-grained reactivity** via `@pithyjs/signals`
10
+ - **Template compilation** with HTML parsing and directive binding
11
+ - **Structural directives** (@if, @for, @switch)
12
+ - **Event handling** with automatic cleanup
13
+ - **Component system** with scoped styles
14
+ - **Zero virtual DOM** - only signal-bound nodes update
15
+
16
+ **Key Principle:** Components never re-render. When a signal changes, only the specific DOM nodes bound to that signal update (O(1) operation).
17
+
18
+ ## Installation
19
+
20
+ <!-- @codex:auto install="@pithyjs/core" -->
21
+ ```bash
22
+ npm install @pithyjs/core
23
+ ```
24
+
25
+ ```bash
26
+ pnpm add @pithyjs/core
27
+ ```
28
+
29
+ ```bash
30
+ yarn add @pithyjs/core
31
+ ```
32
+ <!-- @codex:end -->
33
+
34
+ ## Quick Start
35
+
36
+ ```typescript
37
+ import { html, signal } from '@pithyjs/core';
38
+
39
+ const count = signal(0);
40
+ const increment = () => count.set(count() + 1);
41
+
42
+ const app = html`
43
+ <div>
44
+ <h1>Counter: {{ count() }}</h1>
45
+ <button @click="increment()">Increment</button>
46
+ </div>
47
+ `;
48
+
49
+ document.body.appendChild(app);
50
+ ```
51
+
52
+ ## Core Features
53
+
54
+ ### Reactive Signals
55
+
56
+ ```typescript
57
+ import { signal, computed, effect } from '@pithyjs/core';
58
+
59
+ const name = signal('Alice');
60
+ const greeting = computed(() => `Hello, ${name()}!`);
61
+
62
+ effect(() => {
63
+ console.log(greeting()); // Logs: "Hello, Alice!"
64
+ });
65
+
66
+ name.set('Bob'); // Logs: "Hello, Bob!"
67
+ ```
68
+
69
+ ### Template Interpolations
70
+
71
+ ```typescript
72
+ const user = signal({ name: 'Alice', age: 30 });
73
+
74
+ html`
75
+ <div>
76
+ <h1>{{ user().name }}</h1>
77
+ <p>Age: {{ user().age }}</p>
78
+ </div>
79
+ `;
80
+ ```
81
+
82
+ ### Event Handlers
83
+
84
+ ```typescript
85
+ const handleClick = () => console.log('Clicked!');
86
+ const handleInput = (e) => console.log(e.target.value);
87
+
88
+ html`
89
+ <button @click="handleClick()">Click me</button>
90
+ <input @input="handleInput($event)" />
91
+ `;
92
+ ```
93
+
94
+ ### Conditionals
95
+
96
+ ```typescript
97
+ const isLoggedIn = signal(false);
98
+
99
+ html`
100
+ <div @if="isLoggedIn()">
101
+ <h1>Welcome back!</h1>
102
+ </div>
103
+ <div @else>
104
+ <h1>Please log in</h1>
105
+ </div>
106
+ `;
107
+ ```
108
+
109
+ ### For Loops
110
+
111
+ ```typescript
112
+ const todos = signal([
113
+ { id: 1, text: 'Buy milk', done: false },
114
+ { id: 2, text: 'Walk dog', done: true }
115
+ ]);
116
+
117
+ html`
118
+ <ul>
119
+ <li @for="(todo, i) of todos()" track="todo.id">
120
+ {{ i() + 1 }}. {{ todo().text }}
121
+ <span @if="todo().done">✓</span>
122
+ </li>
123
+ </ul>
124
+ `;
125
+ ```
126
+
127
+ **Complete documentation**: [src/compile/forLoops/README.md](./src/compile/forLoops/README.md)
128
+
129
+ ### Switch/Case
130
+
131
+ ```typescript
132
+ const status = signal('loading');
133
+
134
+ html`
135
+ <div @switch="status()">
136
+ <div @case="'loading'">Loading...</div>
137
+ <div @case="'success'">Success!</div>
138
+ <div @case="'error'">Error occurred</div>
139
+ <div @default>Unknown status</div>
140
+ </div>
141
+ `;
142
+ ```
143
+
144
+ ### Lazy Loading
145
+
146
+ Load components on-demand to improve initial page load performance.
147
+
148
+ ```typescript
149
+ import { lazy, preloadLazy } from '@pithyjs/core';
150
+
151
+ // Create a lazy-loaded component
152
+ const HeavyChart = lazy(() => import('./HeavyChart.pithy'));
153
+
154
+ // Use in template with @defer directive
155
+ html`
156
+ <div @defer="visible" @load="HeavyChart">
157
+ <div slot="placeholder">Loading chart...</div>
158
+ <div slot="error">Failed to load</div>
159
+ </div>
160
+ `;
161
+
162
+ // Preload on hover for faster perceived load
163
+ button.addEventListener('mouseenter', () => preloadLazy(HeavyChart));
164
+ ```
165
+
166
+ **Trigger modes:**
167
+
168
+ - `@defer="visible"` - Load when element scrolls into viewport
169
+ - `@defer="when" @when="condition()"` - Load when condition becomes true
170
+
171
+ **Complete documentation**: [src/runtime/README.md](./src/runtime/README.md)
172
+
173
+ ### Class Directives
174
+
175
+ ```typescript
176
+ const isActive = signal(true);
177
+ const isDisabled = signal(false);
178
+
179
+ html`
180
+ <button
181
+ [class.active]="isActive()"
182
+ [class.disabled]="isDisabled()"
183
+ >
184
+ Toggle
185
+ </button>
186
+ `;
187
+ ```
188
+
189
+ ### Style Directives
190
+
191
+ ```typescript
192
+ const color = signal('red');
193
+ const size = signal(16);
194
+
195
+ html`
196
+ <div
197
+ [style.color]="color()"
198
+ [style.font-size]="size() + 'px'"
199
+ >
200
+ Styled text
201
+ </div>
202
+ `;
203
+ ```
204
+
205
+ ## Architecture
206
+
207
+ ```text
208
+ @pithyjs/core
209
+ ├── runtime/
210
+ │ ├── html.ts # html`` template tag
211
+ │ ├── applyBindings.ts # AOT binding applicator (Phase 5 stub)
212
+ │ ├── lazy.ts # Lazy loading (lazy(), preloadLazy())
213
+ │ ├── module-cache.ts # Module caching for lazy components
214
+ │ └── README.md # Runtime documentation
215
+ ├── compile/
216
+ │ ├── compileTemplate.ts # Main compilation entry
217
+ │ ├── parseHtml.ts # HTML parser
218
+ │ ├── forLoops/ # For loop system
219
+ │ │ └── README.md # Complete @for documentation
220
+ │ └── binds/ # Directive implementations
221
+ │ ├── bindTextInterpolations.ts
222
+ │ ├── bindEventHandlers.ts
223
+ │ ├── bindClassDirectives.ts
224
+ │ └── bindConditionals.ts
225
+ └── index.ts # Public API
226
+ ```
227
+
228
+ ### Template Compilation System
229
+
230
+ The compilation system transforms templates into reactive DOM:
231
+
232
+ 1. **Parse HTML** into AST
233
+ 2. **Bind structural directives** (creates contexts):
234
+ - @if/@else-if/@else chains
235
+ - @switch/@case statements
236
+ - @for loops
237
+ 3. **Bind non-structural directives** (uses contexts):
238
+ - Text interpolations {{ }}
239
+ - Event listeners @event
240
+ - Class/style directives
241
+
242
+ **Complete documentation**: [src/compile/README.md](./src/compile/README.md)
243
+
244
+ ### For Loops System
245
+
246
+ The `@for` directive provides keyed, reactive list rendering with:
247
+
248
+ - **O(1) signal updates** when items change
249
+ - **Minimal DOM moves** using LIS algorithm for reordering
250
+ - **Range-based architecture** with comment anchors
251
+ - **Deep nesting support** (loops in loops, loops in conditionals)
252
+ - **Automatic cleanup** on unmount
253
+
254
+ **Complete documentation**: [src/compile/forLoops/README.md](./src/compile/forLoops/README.md)
255
+
256
+ ## Performance Characteristics
257
+
258
+ | Operation | Complexity | Notes |
259
+ |-----------|------------|-------|
260
+ | Signal read | O(1) | Direct value access |
261
+ | Signal write | O(1) | Updates only subscribers |
262
+ | Text interpolation update | O(1) | Only bound text node updates |
263
+ | Event binding | O(1) | Direct listener attachment |
264
+ | Loop item add | O(1) | Keyed insertion |
265
+ | Loop item remove | O(1) | Range detachment |
266
+ | Loop item update | O(1) | Signal update, no re-render |
267
+ | Loop reorder | O(n log n) | LIS algorithm |
268
+ | Conditional toggle | O(m) | m = branch nodes |
269
+
270
+ **Target**: Sub-1KB core runtime (min+gzip)
271
+
272
+ ## API Reference
273
+
274
+ ### Runtime APIs
275
+
276
+ > **Note:** This table is auto-generated from codex annotations. APIs marked `internal` are not exported from the `@pithyjs/core` public barrel — they are used internally or via direct subpath imports (e.g., `@pithyjs/core/runtime/applyBindings`).
277
+
278
+ <!-- @codex:auto api="pithy.runtime.**" format="table" -->
279
+ | API | Component | Signature | Stability | Description |
280
+ | --- | --- | --- | --- | --- |
281
+ | compileNodes | compile-nodes | `(nodes: PithyNode[], context: Record<string, unknown>) => { el: DocumentFragment; destroy: () => void }` | stable | - |
282
+ | compileTemplate | renderer | `(html: string, context: Record<string, any>, css?: string, scopeId?: string, importedIdentifiers?: Set<string>) => { el: HTMLElement | DocumentFragment; destroy: () => void }` | stable | - |
283
+ | bindTemplateDirectives | renderer | `(fragment: DocumentFragment, context: Record<string, any>, disposers: (() => void)[]) => void` | stable | - |
284
+ | isSSRMode | ssr-mode | `() => boolean` | stable | - |
285
+ | toTextValue | dom-safety | `(input: unknown) => string` | internal | - |
286
+ | __applyBindings | apply-bindings | `(fragment: DocumentFragment, bindings: Desc[], context: Record<string, unknown>) => { el: DocumentFragment; destroy: () => void }` | experimental | - |
287
+ | bootstrap | bootstrap | `(options: BootstrapOptions) => Promise<void>` | stable | - |
288
+ | createContextProxy | context | `(contexts: Record<string, unknown>[]) => Record<string, unknown>` | stable | - |
289
+ | loadWithTimeout | defer-helpers | `<T>(handle: LazyHandle<T>, timeoutMs: number) => Promise<T>` | internal | - |
290
+ | scheduleByPriority | defer-helpers | `(callback: () => void, priority: LoadingPriority | undefined) => number | void` | internal | - |
291
+ | html | html | `(template: TemplateStringsArray | string, contextOrCss?: Record<string, unknown> | string, cssIfContextPassed?: string) => { el: HTMLElement | DocumentFragment; destroy: () => void }` | stable | - |
292
+ | onDestroy | onDestroy | `(fn: () => void) => void` | stable | - |
293
+ | bindBoundAttributes | attributes | `(root: Element | DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]) => void` | stable | - |
294
+ | bindClassDirectives | classes | `(root: Element | DocumentFragment, ctx: Record<string, unknown>, disposers: (() => void)[]) => void` | stable | - |
295
+ | bindComponentTags | components | `(root: Element | DocumentFragment, rootCtx: Record<string, unknown>, disposers: (() => void)[]) => void` | stable | - |
296
+ | bindDefaultTwoWay | two-way-binding | `(fragment: Element | DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]) => void` | stable | - |
297
+ | bindEventHandlers | events | `(root: Element | DocumentFragment, rootCtx: Record<string, unknown>, disposers: (() => void)[]) => void` | stable | - |
298
+ | bindTextInterpolations | interpolations | `(root: Element | DocumentFragment, ctx: Record<string, unknown>, disposers: (() => void)[]) => void` | stable | - |
299
+ | buildPidMap | binding-helpers | `(fragment: DocumentFragment) => Map<string, Element>` | internal | - |
300
+ | buildCommentMap | binding-helpers | `(fragment: DocumentFragment) => Map<string, Comment>` | internal | - |
301
+ | nearestCtx | binding-helpers | `(el: Node, rootCtx: BindingContext) => BindingContext` | internal | - |
302
+ | mergeContexts | binding-helpers | `(context: BindingContext) => BindingContext` | internal | - |
303
+ | compileWithEvent | binding-helpers | `(expr: string, ctx: BindingContext) => (ev: Event, el: Element) => unknown` | internal | - |
304
+ <!-- @codex:end -->
305
+
306
+ ### Directive APIs
307
+
308
+ <!-- @codex:auto api="pithy.directive.**" format="table" -->
309
+ | API | Component | Signature | Stability | Description |
310
+ | --- | --- | --- | --- | --- |
311
+ | bindSwitchCases | switch | `(nodes: PithyNode[], rootEl: HTMLElement | DocumentFragment, ctx: Record<string, unknown>, processedNodeIds?: Set<string>, disposers?: (() => void)[]) => void` | stable | - |
312
+ | handleConditionalChain | conditional-chain | `(domChain: HTMLElement[], astChain: PithyNode[], ctx: Record<string, unknown>, processedNodeIds?: Set<string>, disposers?: (() => void)[]) => Set<string>` | stable | - |
313
+ | bindConditionals | if | `(nodes: PithyNode[], rootEl: HTMLElement | DocumentFragment, ctx: Record<string, unknown>, processedNodeIds?: Set<string>, disposers?: (() => void)[]) => Set<string>` | stable | - |
314
+ | bindForLoops | for | `(nodes: PithyNode[], rootEl: HTMLElement | DocumentFragment, ctx: Record<string, unknown>, disposers?: (() => void)[], processedNodeIds?: Set<string>) => void` | stable | - |
315
+ | createLoopManager | loop-manager | `<T>(options: LoopManagerOptions<T>) => LoopManager<T>` | stable | - |
316
+ | safeInsertBefore | loop-helpers | `(parent: Node, newNode: Node, referenceNode: Node | null) => void` | stable | Safely inserts a node before a reference node, with fallback to appendChild |
317
+ | markElementsAsLoopGenerated | loop-helpers | `(fragment: DocumentFragment, node: { nodeId?: string }) => void` | stable | Marks all elements in a fragment as loop-generated for safe cleanup Optimized to use targeted selectors when possible |
318
+ | createItemRange | loop-helpers | `(key: string) => { start: Comment; end: Comment }` | stable | - |
319
+ | wrapInRange | loop-helpers | `(start: Comment, content: DocumentFragment | HTMLElement, end: Comment) => DocumentFragment` | stable | - |
320
+ | detachRange | loop-helpers | `(start: Comment, end: Comment) => void` | stable | - |
321
+ | createLoopSignals | loop-signals | `<T>(item: T, idx: number, total: number) => LoopSignals` | stable | Creates all the reactive signals needed for a loop item |
322
+ | updateLoopSignals | loop-signals | `(signals: LoopSignals, idx: number, total: number) => void` | stable | Updates all positional signals for a loop item (idx, first, last, even, odd, count) Uses batch() for optimal performance |
323
+ | createLoopContext | loop-signals | `(parentCtx: Record<string, unknown>, signals: LoopSignals, itemVar: string, indexVar?: string, countVar?: string, firstVar?: string, lastVar?: string, evenVar?: string, oddVar?: string) => Record<string, unknown>` | stable | Creates the context object for a loop item with all necessary signals. Helper signal names (count, first, last, even, odd) can be aliased to avoid shadowing in nested loops. |
324
+ | findAllNestedLoopNodes | loop-traversal | `(node: PithyNode) => PithyNode[]` | stable | Recursively finds all nested loop nodes within a given node Used to process nested loops before binding to preserve data-pid references |
325
+ <!-- @codex:end -->
326
+
327
+ ### Lazy Loading APIs
328
+
329
+ <!-- @codex:auto api="pithy.core.lazy" format="table" -->
330
+ | API | Signature | Stability | Description |
331
+ | --- | --- | --- | --- |
332
+ | LazyState | `type LazyState = 'idle' | 'loading' | 'loaded' | 'error'` | stable | Possible states for a lazy component |
333
+ | LazyOptions | `interface LazyOptions` | stable | Options for configuring lazy loading behavior |
334
+ | LazyHandle | `interface LazyHandle<T>` | stable | Handle returned by lazy() for controlling lazy component loading |
335
+ | lazy | `<T>(loader: () => Promise<T>, options?: LazyOptions) => LazyHandle<T>` | stable | - |
336
+ | isLazyHandle | `(value: unknown) => value is LazyHandle<unknown>` | stable | - |
337
+ | preloadLazy | `<T>(handle: LazyHandle<T>) => Promise<T>` | stable | - |
338
+ <!-- @codex:end -->
339
+
340
+ ### Accessibility APIs
341
+
342
+ <!-- @codex:auto api="pithy.a11y.**" format="table" -->
343
+ | API | Component | Signature | Stability | Description |
344
+ | --- | --- | --- | --- | --- |
345
+ | FocusTrap | focus-trap | `class FocusTrap` | stable | Focus Trap Instance Manages focus containment within an element for accessible modals/dialogs |
346
+ | activate | focus-trap | `activate(): void` | stable | - |
347
+ | deactivate | focus-trap | `deactivate(): void` | stable | - |
348
+ | updateFocusableElements | focus-trap | `updateFocusableElements(): void` | stable | - |
349
+ | isActivated | focus-trap | `isActivated(): boolean` | stable | - |
350
+ | destroy | focus-trap | `destroy(): void` | stable | - |
351
+ | createFocusTrap | focus-trap | `(element: HTMLElement, options?: FocusTrapOptions) => FocusTrap` | stable | Create a focus trap for an element Convenience function for creating and activating a focus trap |
352
+ | isKey | keyboard-utils | `(event: KeyboardEvent, key: string) => boolean` | stable | Check if a keyboard event matches a specific key |
353
+ | isActivationKey | keyboard-utils | `(event: KeyboardEvent) => boolean` | stable | Check if keyboard event is an activation key (Enter or Space) Used for custom interactive elements (buttons, links, etc.) |
354
+ | onEscape | keyboard-utils | `(handler: KeyboardHandler, options?: KeyboardHandlerOptions) => () => void` | stable | Handle Escape key press Commonly used to close modals, dropdowns, tooltips, etc. |
355
+ | onEnter | keyboard-utils | `(element: HTMLElement, handler: KeyboardHandler, options?: KeyboardHandlerOptions) => () => void` | stable | Handle Enter key press |
356
+ | onSpace | keyboard-utils | `(element: HTMLElement, handler: KeyboardHandler, options?: KeyboardHandlerOptions) => () => void` | stable | Handle Space key press Note: Space typically triggers on keydown for consistency with Enter |
357
+ | onActivation | keyboard-utils | `(element: HTMLElement, handler: KeyboardHandler, options?: KeyboardHandlerOptions) => () => void` | stable | Handle activation keys (Enter or Space) Used for custom buttons, links, and other interactive elements |
358
+ | onArrowKeys | keyboard-utils | `(element: HTMLElement, handlers: ArrowKeyHandlers, options?: KeyboardHandlerOptions) => () => void` | stable | Handle arrow key navigation |
359
+ | hasModifierKeys | keyboard-utils | `(event: KeyboardEvent) => boolean` | stable | Check if modifier keys are pressed Modifier keys: Ctrl, Alt, Shift, Meta (Command/Windows key) |
360
+ | onKeyboardShortcut | keyboard-utils | `(shortcut: string, handler: KeyboardHandler, options?: KeyboardHandlerOptions) => () => void` | stable | Create a keyboard shortcut handler Supports combinations like "Ctrl+S", "Cmd+K", "Escape", etc. |
361
+ | makeKeyboardAccessible | keyboard-utils | `(element: HTMLElement, handler: KeyboardHandler) => () => void` | stable | Make an element keyboard-accessible by adding Enter/Space key handlers Useful for making divs/spans behave like buttons |
362
+ | RovingTabindex | roving-tabindex | `class RovingTabindex` | stable | Roving Tabindex Manager Implements the roving tabindex pattern for keyboard navigation in custom widgets Used for tabs, menus, toolbars, listboxes, etc. |
363
+ | focusItem | roving-tabindex | `focusItem(index: number): void` | stable | - |
364
+ | updateItems | roving-tabindex | `updateItems(items: HTMLElement[] | NodeListOf<HTMLElement>): void` | stable | - |
365
+ | getCurrentIndex | roving-tabindex | `getCurrentIndex(): number` | stable | - |
366
+ | getCurrentItem | roving-tabindex | `getCurrentItem(): HTMLElement | null` | stable | - |
367
+ | destroy | roving-tabindex | `destroy(): void` | stable | - |
368
+ | createRovingTabindex | roving-tabindex | `(items: HTMLElement[] | NodeListOf<HTMLElement>, options?: RovingTabindexOptions) => RovingTabindex` | stable | Create a roving tabindex manager Convenience function for creating a roving tabindex |
369
+ | SkipLink | skip-link | `(options?: SkipLinkOptions) => SkipLinkResult` | stable | Skip Link Component Provides a keyboard-accessible way to bypass repeated content Meets WCAG 2.4.1 Level A requirement |
370
+ | SkipLinks | skip-link | `(links: SkipLinkOptions[]) => SkipLinkResult` | stable | Create multiple skip links for different page sections |
371
+ <!-- @codex:end -->
372
+
373
+ ### Template Syntax
374
+
375
+ | Syntax | Purpose | Example |
376
+ |--------|---------|---------|
377
+ | `{{ expr }}` | Text interpolation | `{{ count() }}` |
378
+ | `@event` | Event binding | `@click="handler()"` |
379
+ | `@if` / `@else-if` / `@else` | Conditional rendering | `@if="show()"` |
380
+ | `@for` | Loop rendering | `@for="(item, i) of items()" track="item.id"` |
381
+ | `@switch` / `@case` / `@default` | Multi-way branch | `@switch="value()"` |
382
+ | `@defer` / `@load` | Lazy loading | `@defer="visible" @load="LazyComponent"` |
383
+ | `[class.name]` | Class toggle | `[class.active]="isActive()"` |
384
+ | `[style.prop]` | Style binding | `[style.color]="color()"` |
385
+ | `@error` / `@fallback` | Error boundary | `@error="errorSig"` |
386
+
387
+ ## Development
388
+
389
+ ```bash
390
+ pnpm build # Build package
391
+ pnpm test # Run tests
392
+ pnpm test -- --watch # Watch mode
393
+ ```
394
+
395
+ ## Testing
396
+
397
+ <!-- @codex:auto testing="pithy.runtime.**" format="table" -->
398
+ | Feature | Unit | Integration | E2E | Status |
399
+ | --- | --- | --- | --- | --- |
400
+ | compileNodes | - | - | - | Missing unit, integration, e2e |
401
+ | compileTemplate | - | - | - | Missing unit, integration, e2e |
402
+ | bindTemplateDirectives | - | - | - | Missing unit, integration, e2e |
403
+ | isSSRMode | - | - | - | Missing unit, integration, e2e |
404
+ | toTextValue | - | - | - | Missing unit, integration, e2e |
405
+ | __applyBindings | - | - | - | Missing unit, integration, e2e |
406
+ | bootstrap | ✓ | - | - | Missing integration, e2e |
407
+ | createContextProxy | - | - | - | Missing unit, integration, e2e |
408
+ | loadWithTimeout | - | - | - | Missing unit, integration, e2e |
409
+ | scheduleByPriority | - | - | - | Missing unit, integration, e2e |
410
+ | html | - | - | - | Missing unit, integration, e2e |
411
+ | onDestroy | ✓ | - | - | Missing integration, e2e |
412
+ | bindBoundAttributes | - | - | - | Missing unit, integration, e2e |
413
+ | bindClassDirectives | - | - | - | Missing unit, integration, e2e |
414
+ | bindComponentTags | - | - | - | Missing unit, integration, e2e |
415
+ | bindDefaultTwoWay | - | - | - | Missing unit, integration, e2e |
416
+ | bindEventHandlers | - | - | - | Missing unit, integration, e2e |
417
+ | bindTextInterpolations | - | - | - | Missing unit, integration, e2e |
418
+ | buildPidMap | - | - | - | Missing unit, integration, e2e |
419
+ | buildCommentMap | - | - | - | Missing unit, integration, e2e |
420
+ | nearestCtx | - | - | - | Missing unit, integration, e2e |
421
+ | mergeContexts | - | - | - | Missing unit, integration, e2e |
422
+ | compileWithEvent | - | - | - | Missing unit, integration, e2e |
423
+ <!-- @codex:end -->
424
+
425
+ <!-- @codex:auto testing="pithy.directive.**" format="table" -->
426
+ | Feature | Unit | Integration | E2E | Status |
427
+ | --- | --- | --- | --- | --- |
428
+ | bindSwitchCases | - | - | - | Missing unit, integration |
429
+ | handleConditionalChain | - | - | - | Missing unit, integration |
430
+ | bindConditionals | - | - | - | Missing unit, integration |
431
+ | bindForLoops | - | - | - | Missing unit, integration |
432
+ | createLoopManager | - | - | - | Missing unit, integration |
433
+ | safeInsertBefore | - | - | - | Missing unit, integration |
434
+ | markElementsAsLoopGenerated | - | - | - | Missing unit, integration |
435
+ | createItemRange | - | - | - | Missing unit, integration |
436
+ | wrapInRange | - | - | - | Missing unit, integration |
437
+ | detachRange | - | - | - | Missing unit, integration |
438
+ | createLoopSignals | - | - | - | Missing unit, integration |
439
+ | updateLoopSignals | - | - | - | Missing unit, integration |
440
+ | createLoopContext | - | - | - | Missing unit, integration |
441
+ | findAllNestedLoopNodes | - | - | - | Missing unit, integration |
442
+ <!-- @codex:end -->
443
+
444
+ <!-- @codex:auto testing="pithy.core.**" format="table" -->
445
+ | Feature | Unit | Integration | E2E | Status |
446
+ | --- | --- | --- | --- | --- |
447
+ | LazyState | - | - | - | Missing unit, integration, e2e |
448
+ | LazyOptions | - | - | - | Missing unit, integration, e2e |
449
+ | LazyHandle | ✓ | - | - | Missing integration, e2e |
450
+ | lazy | ✓ | - | - | Missing integration, e2e |
451
+ | isLazyHandle | ✓ | - | - | Missing integration, e2e |
452
+ | preloadLazy | ✓ | - | - | Missing integration, e2e |
453
+ | ModuleRecord | ✓ | - | - | Missing integration, e2e |
454
+ | loadModule | ✓ | - | - | Missing integration, e2e |
455
+ | getModuleRecord | ✓ | - | - | Missing integration, e2e |
456
+ | invalidateModule | ✓ | - | - | Missing integration, e2e |
457
+ | getResolvedModuleKeys | ✓ | - | - | Missing integration, e2e |
458
+ | clearModuleCache | ✓ | - | - | Missing integration, e2e |
459
+ | bindDeferDirectives | ✓ | - | - | Missing integration |
460
+ | registerDirectiveBinder | ✓ | - | - | Missing integration, e2e |
461
+ | unregisterDirectiveBinder | ✓ | - | - | Missing integration, e2e |
462
+ | executeCustomDirectiveBinders | ✓ | - | - | Missing integration, e2e |
463
+ <!-- @codex:end -->
464
+
465
+ <!-- @codex:auto testing="pithy.a11y.**" format="table" -->
466
+ | Feature | Unit | Integration | E2E | Status |
467
+ | --- | --- | --- | --- | --- |
468
+ | FocusTrap | ✓ | - | - | Missing integration |
469
+ | activate | ✓ | - | - | Missing integration |
470
+ | deactivate | ✓ | - | - | Missing integration |
471
+ | updateFocusableElements | ✓ | - | - | Missing integration |
472
+ | isActivated | ✓ | - | - | Missing integration |
473
+ | destroy | ✓ | - | - | Missing integration |
474
+ | createFocusTrap | ✓ | - | - | Missing integration |
475
+ | isKey | ✓ | - | - | Missing integration |
476
+ | isActivationKey | ✓ | - | - | Missing integration |
477
+ | onEscape | ✓ | - | - | Missing integration |
478
+ | onEnter | ✓ | - | - | Missing integration |
479
+ | onSpace | ✓ | - | - | Missing integration |
480
+ | onActivation | ✓ | - | - | Missing integration |
481
+ | onArrowKeys | ✓ | - | - | Missing integration |
482
+ | hasModifierKeys | ✓ | - | - | Missing integration |
483
+ | onKeyboardShortcut | ✓ | - | - | Missing integration |
484
+ | makeKeyboardAccessible | ✓ | - | - | Missing integration |
485
+ | RovingTabindex | ✓ | - | - | Missing integration |
486
+ | focusItem | ✓ | - | - | Missing integration |
487
+ | updateItems | ✓ | - | - | Missing integration |
488
+ | getCurrentIndex | ✓ | - | - | Missing integration |
489
+ | getCurrentItem | ✓ | - | - | Missing integration |
490
+ | destroy | ✓ | - | - | Missing integration |
491
+ | createRovingTabindex | ✓ | - | - | Missing integration |
492
+ | SkipLink | ✓ | - | - | Missing integration |
493
+ | SkipLinks | ✓ | - | - | Missing integration |
494
+ <!-- @codex:end -->
495
+
496
+ ## Related Packages
497
+
498
+ - **[@pithyjs/signals](../signals/README.md)** - Standalone reactive signal system
499
+ - **[@pithyjs/router](../router/README.md)** - File-based client-side router
500
+ - **[@pithyjs/compiler](../compiler/)** - .pithy file parser
501
+ - **[@pithyjs/vite-plugin](../vitePlugins/)** - Vite integration
502
+
503
+ ## Documentation
504
+
505
+ - **[Runtime System](./src/runtime/README.md)** - Lazy loading, module caching, and runtime utilities
506
+ - **[Compilation System](./src/compile/README.md)** - Template compilation and directive binding
507
+ - **[For Loops](./src/compile/forLoops/README.md)** - @for directive documentation
508
+ - **[Project Overview](../../docs/PROJECT.md)** - Vision, philosophy, and architecture
509
+ - **[Development Guide](../../docs/DEVELOPMENT.md)** - Setup, workflows, and best practices
510
+
511
+ ## License
512
+
513
+ MIT
@@ -0,0 +1,109 @@
1
+ /** @codex
2
+ {
3
+ "id": "pithy.a11y.focus-trap",
4
+ "title": "Focus Trap Utility - Accessible Modal/Dialog Support",
5
+ "category": "feature"
6
+ }
7
+ */
8
+ /**
9
+ * Focus Trap Configuration
10
+ */
11
+ export interface FocusTrapOptions {
12
+ /** Element to receive focus when trap is activated (defaults to first focusable element) */
13
+ initialFocus?: HTMLElement | string;
14
+ /** Element to receive focus when trap is deactivated (defaults to previously focused element) */
15
+ returnFocus?: HTMLElement | string;
16
+ /** Allow clicking outside to deactivate (default: false) */
17
+ clickOutsideDeactivates?: boolean;
18
+ /** Allow escape key to deactivate (default: true) */
19
+ escapeDeactivates?: boolean;
20
+ /** Callback when trap is activated */
21
+ onActivate?: () => void;
22
+ /** Callback when trap is deactivated */
23
+ onDeactivate?: () => void;
24
+ /** Whether to prevent scroll on body when trap is active (default: true) */
25
+ preventScroll?: boolean;
26
+ }
27
+ /** @codexApi {"parent":"pithy.a11y.focus-trap","name":"FocusTrap","stability":"stable","signature":"class FocusTrap"} */
28
+ /**
29
+ * Focus Trap Instance
30
+ * Manages focus containment within an element for accessible modals/dialogs
31
+ */
32
+ export declare class FocusTrap {
33
+ private element;
34
+ private options;
35
+ private isActive;
36
+ private previouslyFocusedElement;
37
+ private focusableElements;
38
+ private keydownHandler;
39
+ private clickHandler;
40
+ /**
41
+ * Selector for focusable elements
42
+ * Based on what browsers consider naturally focusable
43
+ */
44
+ private static readonly FOCUSABLE_SELECTOR;
45
+ constructor(element: HTMLElement, options?: FocusTrapOptions);
46
+ /** @codexApi {"parent":"pithy.a11y.focus-trap","name":"activate","stability":"stable","signature":"activate(): void"} */
47
+ /**
48
+ * Activate the focus trap
49
+ * Traps keyboard focus within the element
50
+ */
51
+ activate(): void;
52
+ /** @codexApi {"parent":"pithy.a11y.focus-trap","name":"deactivate","stability":"stable","signature":"deactivate(): void"} */
53
+ /**
54
+ * Deactivate the focus trap
55
+ * Returns focus to the previously focused element
56
+ */
57
+ deactivate(): void;
58
+ /** @codexApi {"parent":"pithy.a11y.focus-trap","name":"updateFocusableElements","stability":"stable","signature":"updateFocusableElements(): void"} */
59
+ /**
60
+ * Update the list of focusable elements
61
+ * Call this if the DOM within the trap changes
62
+ */
63
+ updateFocusableElements(): void;
64
+ /**
65
+ * Get the first focusable element in the trap
66
+ */
67
+ private getFirstFocusableElement;
68
+ /**
69
+ * Get the last focusable element in the trap
70
+ */
71
+ private getLastFocusableElement;
72
+ /**
73
+ * Focus the initial element based on options
74
+ */
75
+ private focusInitialElement;
76
+ /**
77
+ * Get the element to return focus to
78
+ */
79
+ private getReturnFocusTarget;
80
+ /**
81
+ * Handle keydown events for focus trapping
82
+ */
83
+ private handleKeydown;
84
+ /**
85
+ * Handle Tab key for focus cycling
86
+ */
87
+ private handleTabKey;
88
+ /**
89
+ * Handle clicks outside the trapped element
90
+ */
91
+ private handleClickOutside;
92
+ /** @codexApi {"parent":"pithy.a11y.focus-trap","name":"isActivated","stability":"stable","signature":"isActivated(): boolean"} */
93
+ /**
94
+ * Check if the trap is currently active
95
+ */
96
+ isActivated(): boolean;
97
+ /** @codexApi {"parent":"pithy.a11y.focus-trap","name":"destroy","stability":"stable","signature":"destroy(): void"} */
98
+ /**
99
+ * Destroy the focus trap and clean up resources
100
+ */
101
+ destroy(): void;
102
+ }
103
+ /** @codexApi {"parent":"pithy.a11y.focus-trap","name":"createFocusTrap","stability":"stable","signature":"(element: HTMLElement, options?: FocusTrapOptions) => FocusTrap"} */
104
+ /**
105
+ * Create a focus trap for an element
106
+ * Convenience function for creating and activating a focus trap
107
+ */
108
+ export declare function createFocusTrap(element: HTMLElement, options?: FocusTrapOptions): FocusTrap;
109
+ //# sourceMappingURL=focus-trap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus-trap.d.ts","sourceRoot":"","sources":["../../src/a11y/focus-trap.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4FAA4F;IAC5F,YAAY,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IACpC,iGAAiG;IACjG,WAAW,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IACnC,4DAA4D;IAC5D,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,qDAAqD;IACrD,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,sCAAsC;IACtC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,wCAAwC;IACxC,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,4EAA4E;IAC5E,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,yHAAyH;AACzH;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,wBAAwB,CAA4B;IAC5D,OAAO,CAAC,iBAAiB,CAAqB;IAG9C,OAAO,CAAC,cAAc,CAA6C;IACnE,OAAO,CAAC,YAAY,CAA0C;IAE9D;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAY9B;gBAEA,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE,gBAAqB;IAahE,yHAAyH;IACzH;;;OAGG;IACH,QAAQ,IAAI,IAAI;IA+BhB,6HAA6H;IAC7H;;;OAGG;IACH,UAAU,IAAI,IAAI;IA4BlB,uJAAuJ;IACvJ;;;OAGG;IACH,uBAAuB,IAAI,IAAI;IAgB/B;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAIhC;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAI/B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA8B3B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAU5B;;OAEG;IACH,OAAO,CAAC,aAAa;IAerB;;OAEG;IACH,OAAO,CAAC,YAAY;IAyBpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAM1B,kIAAkI;IAClI;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB,uHAAuH;IACvH;;OAEG;IACH,OAAO,IAAI,IAAI;CAKhB;AAED,+KAA+K;AAC/K;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,gBAAgB,GACzB,SAAS,CAEX"}