@zenithbuild/compiler 1.0.2

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 (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/dist/build-analyzer.d.ts +44 -0
  4. package/dist/build-analyzer.js +87 -0
  5. package/dist/bundler.d.ts +31 -0
  6. package/dist/bundler.js +86 -0
  7. package/dist/core/components/index.d.ts +9 -0
  8. package/dist/core/components/index.js +13 -0
  9. package/dist/core/config/index.d.ts +11 -0
  10. package/dist/core/config/index.js +10 -0
  11. package/dist/core/config/loader.d.ts +17 -0
  12. package/dist/core/config/loader.js +60 -0
  13. package/dist/core/config/types.d.ts +98 -0
  14. package/dist/core/config/types.js +32 -0
  15. package/dist/core/index.d.ts +7 -0
  16. package/dist/core/index.js +6 -0
  17. package/dist/core/lifecycle/index.d.ts +16 -0
  18. package/dist/core/lifecycle/index.js +19 -0
  19. package/dist/core/lifecycle/zen-mount.d.ts +66 -0
  20. package/dist/core/lifecycle/zen-mount.js +151 -0
  21. package/dist/core/lifecycle/zen-unmount.d.ts +54 -0
  22. package/dist/core/lifecycle/zen-unmount.js +76 -0
  23. package/dist/core/plugins/bridge.d.ts +116 -0
  24. package/dist/core/plugins/bridge.js +121 -0
  25. package/dist/core/plugins/index.d.ts +6 -0
  26. package/dist/core/plugins/index.js +6 -0
  27. package/dist/core/plugins/registry.d.ts +67 -0
  28. package/dist/core/plugins/registry.js +113 -0
  29. package/dist/core/reactivity/index.d.ts +30 -0
  30. package/dist/core/reactivity/index.js +33 -0
  31. package/dist/core/reactivity/tracking.d.ts +74 -0
  32. package/dist/core/reactivity/tracking.js +136 -0
  33. package/dist/core/reactivity/zen-batch.d.ts +45 -0
  34. package/dist/core/reactivity/zen-batch.js +54 -0
  35. package/dist/core/reactivity/zen-effect.d.ts +48 -0
  36. package/dist/core/reactivity/zen-effect.js +98 -0
  37. package/dist/core/reactivity/zen-memo.d.ts +43 -0
  38. package/dist/core/reactivity/zen-memo.js +100 -0
  39. package/dist/core/reactivity/zen-ref.d.ts +44 -0
  40. package/dist/core/reactivity/zen-ref.js +34 -0
  41. package/dist/core/reactivity/zen-signal.d.ts +48 -0
  42. package/dist/core/reactivity/zen-signal.js +84 -0
  43. package/dist/core/reactivity/zen-state.d.ts +35 -0
  44. package/dist/core/reactivity/zen-state.js +147 -0
  45. package/dist/core/reactivity/zen-untrack.d.ts +38 -0
  46. package/dist/core/reactivity/zen-untrack.js +41 -0
  47. package/dist/css/index.d.ts +73 -0
  48. package/dist/css/index.js +246 -0
  49. package/dist/discovery/componentDiscovery.d.ts +42 -0
  50. package/dist/discovery/componentDiscovery.js +56 -0
  51. package/dist/discovery/layouts.d.ts +13 -0
  52. package/dist/discovery/layouts.js +41 -0
  53. package/dist/errors/compilerError.d.ts +31 -0
  54. package/dist/errors/compilerError.js +51 -0
  55. package/dist/finalize/finalizeOutput.d.ts +32 -0
  56. package/dist/finalize/finalizeOutput.js +62 -0
  57. package/dist/finalize/generateFinalBundle.d.ts +24 -0
  58. package/dist/finalize/generateFinalBundle.js +68 -0
  59. package/dist/index.d.ts +36 -0
  60. package/dist/index.js +51 -0
  61. package/dist/ir/types.d.ts +181 -0
  62. package/dist/ir/types.js +8 -0
  63. package/dist/output/types.d.ts +30 -0
  64. package/dist/output/types.js +6 -0
  65. package/dist/parse/detectMapExpressions.d.ts +45 -0
  66. package/dist/parse/detectMapExpressions.js +77 -0
  67. package/dist/parse/parseScript.d.ts +8 -0
  68. package/dist/parse/parseScript.js +36 -0
  69. package/dist/parse/parseTemplate.d.ts +11 -0
  70. package/dist/parse/parseTemplate.js +487 -0
  71. package/dist/parse/parseZenFile.d.ts +11 -0
  72. package/dist/parse/parseZenFile.js +50 -0
  73. package/dist/parse/scriptAnalysis.d.ts +25 -0
  74. package/dist/parse/scriptAnalysis.js +60 -0
  75. package/dist/parse/trackLoopContext.d.ts +20 -0
  76. package/dist/parse/trackLoopContext.js +62 -0
  77. package/dist/parseZenFile.d.ts +10 -0
  78. package/dist/parseZenFile.js +55 -0
  79. package/dist/runtime/analyzeAndEmit.d.ts +20 -0
  80. package/dist/runtime/analyzeAndEmit.js +70 -0
  81. package/dist/runtime/build.d.ts +6 -0
  82. package/dist/runtime/build.js +13 -0
  83. package/dist/runtime/bundle-generator.d.ts +27 -0
  84. package/dist/runtime/bundle-generator.js +1263 -0
  85. package/dist/runtime/client-runtime.d.ts +41 -0
  86. package/dist/runtime/client-runtime.js +397 -0
  87. package/dist/runtime/dataExposure.d.ts +52 -0
  88. package/dist/runtime/dataExposure.js +227 -0
  89. package/dist/runtime/generateDOM.d.ts +21 -0
  90. package/dist/runtime/generateDOM.js +194 -0
  91. package/dist/runtime/generateHydrationBundle.d.ts +15 -0
  92. package/dist/runtime/generateHydrationBundle.js +399 -0
  93. package/dist/runtime/hydration.d.ts +53 -0
  94. package/dist/runtime/hydration.js +271 -0
  95. package/dist/runtime/navigation.d.ts +58 -0
  96. package/dist/runtime/navigation.js +372 -0
  97. package/dist/runtime/serve.d.ts +13 -0
  98. package/dist/runtime/serve.js +76 -0
  99. package/dist/runtime/thinRuntime.d.ts +23 -0
  100. package/dist/runtime/thinRuntime.js +158 -0
  101. package/dist/runtime/transformIR.d.ts +19 -0
  102. package/dist/runtime/transformIR.js +285 -0
  103. package/dist/runtime/wrapExpression.d.ts +24 -0
  104. package/dist/runtime/wrapExpression.js +76 -0
  105. package/dist/runtime/wrapExpressionWithLoop.d.ts +17 -0
  106. package/dist/runtime/wrapExpressionWithLoop.js +75 -0
  107. package/dist/spa-build.d.ts +26 -0
  108. package/dist/spa-build.js +866 -0
  109. package/dist/ssg-build.d.ts +32 -0
  110. package/dist/ssg-build.js +408 -0
  111. package/dist/test/analyze-emit.test.d.ts +1 -0
  112. package/dist/test/analyze-emit.test.js +88 -0
  113. package/dist/test/bundler-contract.test.d.ts +1 -0
  114. package/dist/test/bundler-contract.test.js +137 -0
  115. package/dist/test/compiler-authority.test.d.ts +1 -0
  116. package/dist/test/compiler-authority.test.js +90 -0
  117. package/dist/test/component-instance-test.d.ts +1 -0
  118. package/dist/test/component-instance-test.js +115 -0
  119. package/dist/test/error-native-bridge.test.d.ts +1 -0
  120. package/dist/test/error-native-bridge.test.js +51 -0
  121. package/dist/test/error-serialization.test.d.ts +1 -0
  122. package/dist/test/error-serialization.test.js +38 -0
  123. package/dist/test/macro-inlining.test.d.ts +1 -0
  124. package/dist/test/macro-inlining.test.js +178 -0
  125. package/dist/test/validate-test.d.ts +6 -0
  126. package/dist/test/validate-test.js +95 -0
  127. package/dist/transform/classifyExpression.d.ts +46 -0
  128. package/dist/transform/classifyExpression.js +354 -0
  129. package/dist/transform/componentResolver.d.ts +15 -0
  130. package/dist/transform/componentResolver.js +30 -0
  131. package/dist/transform/expressionTransformer.d.ts +19 -0
  132. package/dist/transform/expressionTransformer.js +333 -0
  133. package/dist/transform/fragmentLowering.d.ts +25 -0
  134. package/dist/transform/fragmentLowering.js +468 -0
  135. package/dist/transform/layoutProcessor.d.ts +5 -0
  136. package/dist/transform/layoutProcessor.js +34 -0
  137. package/dist/transform/transformTemplate.d.ts +11 -0
  138. package/dist/transform/transformTemplate.js +33 -0
  139. package/dist/validate/invariants.d.ts +23 -0
  140. package/dist/validate/invariants.js +55 -0
  141. package/native/compiler-native/compiler-native.node +0 -0
  142. package/native/compiler-native/index.d.ts +113 -0
  143. package/native/compiler-native/index.js +19 -0
  144. package/native/compiler-native/package.json +19 -0
  145. package/package.json +49 -0
@@ -0,0 +1,399 @@
1
+ /**
2
+ * Generate Hydration Bundle
3
+ *
4
+ * Phase 5: Generates the complete runtime bundle including expressions and hydration code
5
+ */
6
+ /**
7
+ * Generate the hydration runtime code as a string
8
+ * This is the browser-side runtime that hydrates DOM placeholders
9
+ */
10
+ export function generateHydrationRuntime() {
11
+ return `
12
+ // Zenith Runtime Hydration Layer (Phase 5)
13
+ (function() {
14
+ 'use strict';
15
+
16
+ // Expression registry - maps expression IDs to their evaluation functions
17
+ if (typeof window !== 'undefined' && !window.__ZENITH_EXPRESSIONS__) {
18
+ window.__ZENITH_EXPRESSIONS__ = new Map();
19
+ }
20
+
21
+ // Binding registry - tracks which DOM nodes are bound to which expressions
22
+ const __zen_bindings = [];
23
+
24
+ /**
25
+ * Update a text binding
26
+ * Phase 6: Accepts explicit data arguments
27
+ */
28
+ function updateTextBinding(node, expressionId, state, loaderData, props, stores) {
29
+ try {
30
+ const expression = window.__ZENITH_EXPRESSIONS__.get(expressionId);
31
+ if (!expression) {
32
+ console.warn('[Zenith] Expression ' + expressionId + ' not found in registry');
33
+ return;
34
+ }
35
+
36
+ // Call expression with appropriate arguments based on function length
37
+ const result = expression.length === 1
38
+ ? expression(state) // Legacy: state only
39
+ : expression(state, loaderData, props, stores); // Phase 6: explicit arguments
40
+
41
+ // Handle different result types
42
+ if (result === null || result === undefined || result === false) {
43
+ node.textContent = '';
44
+ } else if (typeof result === 'string') {
45
+ if (result.trim().startsWith('<')) {
46
+ // Render as HTML
47
+ node.innerHTML = result;
48
+ } else {
49
+ node.textContent = result;
50
+ }
51
+ } else if (typeof result === 'number') {
52
+ node.textContent = String(result);
53
+ } else if (result instanceof Node) {
54
+ // Clear node and append result
55
+ node.innerHTML = '';
56
+ node.appendChild(result);
57
+ } else if (Array.isArray(result)) {
58
+ // Handle array results (for map expressions)
59
+ node.innerHTML = '';
60
+ const fragment = document.createDocumentFragment();
61
+ for (let i = 0; i < result.length; i++) {
62
+ const item = result[i];
63
+ if (item instanceof Node) {
64
+ fragment.appendChild(item);
65
+ } else {
66
+ fragment.appendChild(document.createTextNode(String(item)));
67
+ }
68
+ }
69
+ node.appendChild(fragment);
70
+ } else {
71
+ node.textContent = String(result);
72
+ }
73
+ } catch (error) {
74
+ console.error('[Zenith] Error evaluating expression ' + expressionId + ':', error);
75
+ console.error('Expression ID:', expressionId, 'State:', state);
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Update an attribute binding
81
+ * Phase 6: Accepts explicit data arguments
82
+ */
83
+ function updateAttributeBinding(element, attributeName, expressionId, state, loaderData, props, stores) {
84
+ try {
85
+ const expression = window.__ZENITH_EXPRESSIONS__.get(expressionId);
86
+ if (!expression) {
87
+ console.warn('[Zenith] Expression ' + expressionId + ' not found in registry');
88
+ return;
89
+ }
90
+
91
+ // Call expression with appropriate arguments based on function length
92
+ const result = expression.length === 1
93
+ ? expression(state) // Legacy: state only
94
+ : expression(state, loaderData, props, stores); // Phase 6: explicit arguments
95
+
96
+ // Handle different attribute types
97
+ if (attributeName === 'class' || attributeName === 'className') {
98
+ element.className = String(result != null ? result : '');
99
+ } else if (attributeName === 'style') {
100
+ if (typeof result === 'string') {
101
+ element.setAttribute('style', result);
102
+ } else if (result && typeof result === 'object') {
103
+ // Handle style object
104
+ const styleStr = Object.keys(result).map(function(key) {
105
+ return key + ': ' + result[key];
106
+ }).join('; ');
107
+ element.setAttribute('style', styleStr);
108
+ }
109
+ } else if (attributeName === 'disabled' || attributeName === 'checked' || attributeName === 'readonly') {
110
+ // Boolean attributes
111
+ if (result) {
112
+ element.setAttribute(attributeName, '');
113
+ } else {
114
+ element.removeAttribute(attributeName);
115
+ }
116
+ } else {
117
+ // Regular attributes
118
+ if (result === null || result === undefined || result === false) {
119
+ element.removeAttribute(attributeName);
120
+ } else {
121
+ element.setAttribute(attributeName, String(result));
122
+ }
123
+ }
124
+ } catch (error) {
125
+ console.error('[Zenith] Error updating attribute ' + attributeName + ' with expression ' + expressionId + ':', error);
126
+ console.error('Expression ID:', expressionId, 'State:', state);
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Hydrate static HTML with dynamic expressions
132
+ * Phase 6: Accepts explicit loaderData, props, stores arguments
133
+ */
134
+ function hydrate(state, loaderData, props, stores, container) {
135
+ if (!state) {
136
+ console.warn('[Zenith] hydrate called without state object');
137
+ return;
138
+ }
139
+
140
+ // Handle optional arguments (backwards compatibility)
141
+ if (typeof container === 'undefined' && typeof stores === 'object' && stores && !stores.nodeType) {
142
+ // Called as hydrate(state, loaderData, props, stores, container)
143
+ container = document;
144
+ } else if (typeof props === 'object' && props && !props.nodeType && typeof stores === 'undefined') {
145
+ // Called as hydrate(state, loaderData, props) - container is props
146
+ container = props;
147
+ props = loaderData;
148
+ loaderData = undefined;
149
+ stores = undefined;
150
+ } else if (typeof loaderData === 'object' && loaderData && loaderData.nodeType) {
151
+ // Called as hydrate(state, container) - legacy signature
152
+ container = loaderData;
153
+ loaderData = undefined;
154
+ props = undefined;
155
+ stores = undefined;
156
+ } else {
157
+ container = container || document;
158
+ }
159
+
160
+ // Default empty objects for missing arguments
161
+ loaderData = loaderData || {};
162
+ props = props || {};
163
+ stores = stores || {};
164
+
165
+ // Store state and data globally for event handlers
166
+ if (typeof window !== 'undefined') {
167
+ window.__ZENITH_STATE__ = state;
168
+ window.__ZENITH_LOADER_DATA__ = loaderData;
169
+ window.__ZENITH_PROPS__ = props;
170
+ window.__ZENITH_STORES__ = stores;
171
+ }
172
+
173
+ // Clear existing bindings
174
+ __zen_bindings.length = 0;
175
+
176
+ // Find all text expression placeholders
177
+ const textPlaceholders = container.querySelectorAll('[data-zen-text]');
178
+ for (let i = 0; i < textPlaceholders.length; i++) {
179
+ const node = textPlaceholders[i];
180
+ const expressionId = node.getAttribute('data-zen-text');
181
+ if (!expressionId) continue;
182
+
183
+ __zen_bindings.push({
184
+ node: node,
185
+ type: 'text',
186
+ expressionId: expressionId
187
+ });
188
+
189
+ updateTextBinding(node, expressionId, state, loaderData, props, stores);
190
+ }
191
+
192
+ // Find all attribute expression placeholders
193
+ const attrSelectors = [
194
+ '[data-zen-attr-class]',
195
+ '[data-zen-attr-style]',
196
+ '[data-zen-attr-src]',
197
+ '[data-zen-attr-href]',
198
+ '[data-zen-attr-disabled]',
199
+ '[data-zen-attr-checked]'
200
+ ];
201
+
202
+ for (let s = 0; s < attrSelectors.length; s++) {
203
+ const attrPlaceholders = container.querySelectorAll(attrSelectors[s]);
204
+ for (let i = 0; i < attrPlaceholders.length; i++) {
205
+ const node = attrPlaceholders[i];
206
+ if (!(node instanceof Element)) continue;
207
+
208
+ // Extract attribute name from selector
209
+ const attrMatch = attrSelectors[s].match(/data-zen-attr-(\\w+)/);
210
+ if (!attrMatch) continue;
211
+ const attrName = attrMatch[1];
212
+
213
+ const expressionId = node.getAttribute('data-zen-attr-' + attrName);
214
+ if (!expressionId) continue;
215
+
216
+ __zen_bindings.push({
217
+ node: node,
218
+ type: 'attribute',
219
+ attributeName: attrName,
220
+ expressionId: expressionId
221
+ });
222
+
223
+ updateAttributeBinding(node, attrName, expressionId, state, loaderData, props, stores);
224
+ }
225
+ }
226
+
227
+ // Bind event handlers
228
+ bindEvents(container);
229
+ }
230
+
231
+ /**
232
+ * Bind event handlers to DOM elements
233
+ */
234
+ function bindEvents(container) {
235
+ container = container || document;
236
+ const eventTypes = ['click', 'change', 'input', 'submit', 'focus', 'blur', 'keyup', 'keydown'];
237
+
238
+ for (let e = 0; e < eventTypes.length; e++) {
239
+ const eventType = eventTypes[e];
240
+ const elements = container.querySelectorAll('[data-zen-' + eventType + ']');
241
+
242
+ for (let i = 0; i < elements.length; i++) {
243
+ const element = elements[i];
244
+ if (!(element instanceof Element)) continue;
245
+
246
+ const handlerName = element.getAttribute('data-zen-' + eventType);
247
+ if (!handlerName) continue;
248
+
249
+ // Remove existing listener if any (to avoid duplicates)
250
+ const handlerKey = '__zen_' + eventType + '_handler';
251
+ const existingHandler = element[handlerKey];
252
+ if (existingHandler) {
253
+ element.removeEventListener(eventType, existingHandler);
254
+ }
255
+
256
+ // Create new handler
257
+ const handler = function(event) {
258
+ try {
259
+ // 1. Try to find handler function on window (for named functions)
260
+ let handlerFunc = window[handlerName];
261
+
262
+ // 2. If not found, try the expression registry (for inline expressions)
263
+ if (typeof handlerFunc !== 'function' && window.__ZENITH_EXPRESSIONS__) {
264
+ handlerFunc = window.__ZENITH_EXPRESSIONS__.get(handlerName);
265
+ }
266
+
267
+ if (typeof handlerFunc === 'function') {
268
+ // Call the handler. For expressions, we pass the current state.
269
+ // Note: Phase 6 handles passing loaderData, props, etc. if needed.
270
+ const state = window.__ZENITH_STATE__ || {};
271
+ const loaderData = window.__ZENITH_LOADER_DATA__ || {};
272
+ const props = window.__ZENITH_PROPS__ || {};
273
+ const stores = window.__ZENITH_STORES__ || {};
274
+
275
+ if (handlerFunc.length === 1) {
276
+ // Legacy or simple handler
277
+ handlerFunc(event, element);
278
+ } else {
279
+ // Full context handler
280
+ handlerFunc(event, element, state, loaderData, props, stores);
281
+ }
282
+ } else {
283
+ console.warn('[Zenith] Event handler "' + handlerName + '" not found for ' + eventType + ' event');
284
+ }
285
+ } catch (error) {
286
+ console.error('[Zenith] Error executing event handler "' + handlerName + '":', error);
287
+ }
288
+ };
289
+
290
+ // Store handler reference to allow cleanup
291
+ element[handlerKey] = handler;
292
+
293
+ element.addEventListener(eventType, handler);
294
+ }
295
+ }
296
+ }
297
+
298
+ /**
299
+ * Update all bindings when state changes
300
+ * Phase 6: Accepts explicit data arguments
301
+ */
302
+ function update(state, loaderData, props, stores) {
303
+ if (!state) {
304
+ console.warn('[Zenith] update called without state object');
305
+ return;
306
+ }
307
+
308
+ // Handle optional arguments (backwards compatibility)
309
+ if (typeof loaderData === 'undefined') {
310
+ loaderData = window.__ZENITH_LOADER_DATA__ || {};
311
+ props = window.__ZENITH_PROPS__ || {};
312
+ stores = window.__ZENITH_STORES__ || {};
313
+ } else {
314
+ loaderData = loaderData || {};
315
+ props = props || {};
316
+ stores = stores || {};
317
+ }
318
+
319
+ // Update global state and data
320
+ if (typeof window !== 'undefined') {
321
+ window.__ZENITH_STATE__ = state;
322
+ window.__ZENITH_LOADER_DATA__ = loaderData;
323
+ window.__ZENITH_PROPS__ = props;
324
+ window.__ZENITH_STORES__ = stores;
325
+ }
326
+
327
+ // Update all tracked bindings
328
+ for (let i = 0; i < __zen_bindings.length; i++) {
329
+ const binding = __zen_bindings[i];
330
+ if (binding.type === 'text') {
331
+ updateTextBinding(binding.node, binding.expressionId, state, loaderData, props, stores);
332
+ } else if (binding.type === 'attribute' && binding.attributeName) {
333
+ if (binding.node instanceof Element) {
334
+ updateAttributeBinding(binding.node, binding.attributeName, binding.expressionId, state, loaderData, props, stores);
335
+ }
336
+ }
337
+ }
338
+ }
339
+
340
+ /**
341
+ * Clear all bindings and event listeners
342
+ */
343
+ function cleanup(container) {
344
+ container = container || document;
345
+
346
+ // Remove event listeners
347
+ const eventTypes = ['click', 'change', 'input', 'submit', 'focus', 'blur', 'keyup', 'keydown'];
348
+ for (let e = 0; e < eventTypes.length; e++) {
349
+ const eventType = eventTypes[e];
350
+ const elements = container.querySelectorAll('[data-zen-' + eventType + ']');
351
+ for (let i = 0; i < elements.length; i++) {
352
+ const element = elements[i];
353
+ if (!(element instanceof Element)) continue;
354
+ const handlerKey = '__zen_' + eventType + '_handler';
355
+ const handler = element[handlerKey];
356
+ if (handler) {
357
+ element.removeEventListener(eventType, handler);
358
+ delete element[handlerKey];
359
+ }
360
+ }
361
+ }
362
+
363
+ // Clear bindings
364
+ __zen_bindings.length = 0;
365
+ }
366
+
367
+ // Export functions to window
368
+ if (typeof window !== 'undefined') {
369
+ window.__zenith_hydrate = hydrate;
370
+ window.__zenith_bindEvents = bindEvents;
371
+ window.__zenith_update = update;
372
+ window.__zenith_cleanup = cleanup;
373
+ }
374
+ })();
375
+ `;
376
+ }
377
+ /**
378
+ * Generate expression registry initialization code
379
+ */
380
+ export function generateExpressionRegistry(expressions) {
381
+ if (expressions.length === 0) {
382
+ return `
383
+ // No expressions to register
384
+ if (typeof window !== 'undefined' && window.__ZENITH_EXPRESSIONS__) {
385
+ // Registry already initialized
386
+ }`;
387
+ }
388
+ const registryCode = expressions.map(expr => {
389
+ return ` window.__ZENITH_EXPRESSIONS__.set('${expr.id}', ${expr.id});`;
390
+ }).join('\n');
391
+ return `
392
+ // Initialize expression registry
393
+ if (typeof window !== 'undefined') {
394
+ if (!window.__ZENITH_EXPRESSIONS__) {
395
+ window.__ZENITH_EXPRESSIONS__ = new Map();
396
+ }
397
+ ${registryCode}
398
+ }`;
399
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Runtime Hydration Layer
3
+ *
4
+ * Phase 5: Browser-side runtime that hydrates static HTML with dynamic expressions
5
+ *
6
+ * This runtime:
7
+ * - Locates DOM placeholders (data-zen-text, data-zen-attr-*)
8
+ * - Evaluates precompiled expressions against state
9
+ * - Updates DOM textContent, attributes, and properties
10
+ * - Binds event handlers
11
+ * - Handles reactive state updates
12
+ */
13
+ /**
14
+ * Expression registry - maps expression IDs to their evaluation functions
15
+ * Populated at runtime with compiled expressions
16
+ */
17
+ declare global {
18
+ interface Window {
19
+ __ZENITH_EXPRESSIONS__?: Map<string, (state: any) => any>;
20
+ __ZENITH_STATE__?: any;
21
+ }
22
+ }
23
+ /**
24
+ * Hydrate static HTML with dynamic expressions
25
+ *
26
+ * @param state - The state object to evaluate expressions against
27
+ * @param container - The container element to hydrate (defaults to document)
28
+ */
29
+ export declare function hydrate(state: any, container?: Document | Element): void;
30
+ /**
31
+ * Bind event handlers to DOM elements
32
+ *
33
+ * @param container - The container element to bind events in (defaults to document)
34
+ */
35
+ export declare function bindEvents(container?: Document | Element): void;
36
+ /**
37
+ * Update all bindings when state changes
38
+ *
39
+ * @param state - The new state object
40
+ */
41
+ export declare function update(state: any): void;
42
+ /**
43
+ * Initialize the expression registry
44
+ * Called once when the runtime loads
45
+ *
46
+ * @param expressions - Map of expression IDs to evaluation functions
47
+ */
48
+ export declare function initExpressions(expressions: Map<string, (state: any) => any>): void;
49
+ /**
50
+ * Clear all bindings and event listeners
51
+ * Useful for cleanup when navigating away
52
+ */
53
+ export declare function cleanup(container?: Document | Element): void;