@zenithbuild/runtime 0.2.1 → 0.5.0-beta.2.4
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.
- package/HYDRATION_CONTRACT.md +98 -0
- package/README.md +3 -0
- package/RUNTIME_CONTRACT.md +183 -0
- package/dist/cleanup.js +88 -0
- package/dist/diagnostics.js +309 -0
- package/dist/effect.js +3 -0
- package/dist/events.js +59 -0
- package/dist/hydrate.js +1596 -0
- package/dist/index.js +4 -505
- package/dist/ref.js +23 -0
- package/dist/runtime.js +57 -0
- package/dist/signal.js +58 -0
- package/dist/state.js +79 -0
- package/dist/template.js +360 -0
- package/dist/zeneffect.js +640 -0
- package/package.json +16 -7
- package/dist/dom-hydration.d.ts +0 -44
- package/dist/dom-hydration.d.ts.map +0 -1
- package/dist/dom-hydration.js +0 -272
- package/dist/dom-hydration.js.map +0 -1
- package/dist/index.d.ts +0 -90
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/thin-runtime.d.ts +0 -24
- package/dist/thin-runtime.d.ts.map +0 -1
- package/dist/thin-runtime.js +0 -159
- package/dist/thin-runtime.js.map +0 -1
- package/src/dom-hydration.ts +0 -297
- package/src/index.ts +0 -488
- package/src/thin-runtime.ts +0 -159
package/dist/events.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// events.js — Zenith Runtime V0
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Event binding system.
|
|
5
|
+
//
|
|
6
|
+
// For: <button data-zx-on-click="1">
|
|
7
|
+
//
|
|
8
|
+
// Algorithm:
|
|
9
|
+
// 1. Extract event name from attribute suffix ("click")
|
|
10
|
+
// 2. Resolve expression at index → must be a function
|
|
11
|
+
// 3. addEventListener directly
|
|
12
|
+
//
|
|
13
|
+
// No synthetic events.
|
|
14
|
+
// No delegation.
|
|
15
|
+
// No wrapping.
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
import { _registerListener } from './cleanup.js';
|
|
19
|
+
import { rethrowZenithRuntimeError, throwZenithRuntimeError } from './diagnostics.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Bind an event listener to a DOM element.
|
|
23
|
+
*
|
|
24
|
+
* @param {Element} element - The DOM element
|
|
25
|
+
* @param {string} eventName - The event name (e.g. "click")
|
|
26
|
+
* @param {() => any} exprFn - Pre-bound expression function that must resolve to a handler
|
|
27
|
+
*/
|
|
28
|
+
export function bindEvent(element, eventName, exprFn) {
|
|
29
|
+
const resolved = exprFn();
|
|
30
|
+
|
|
31
|
+
if (typeof resolved !== 'function') {
|
|
32
|
+
throwZenithRuntimeError({
|
|
33
|
+
phase: 'bind',
|
|
34
|
+
code: 'BINDING_APPLY_FAILED',
|
|
35
|
+
message: `Event binding did not resolve to a function for "${eventName}"`,
|
|
36
|
+
marker: { type: `data-zx-on-${eventName}`, id: '<unknown>' },
|
|
37
|
+
path: `event:${eventName}`,
|
|
38
|
+
hint: 'Bind events to function references.'
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const wrapped = function zenithBoundEvent(event) {
|
|
43
|
+
try {
|
|
44
|
+
return resolved.call(this, event);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
rethrowZenithRuntimeError(error, {
|
|
47
|
+
phase: 'event',
|
|
48
|
+
code: 'EVENT_HANDLER_FAILED',
|
|
49
|
+
message: `Event handler failed for "${eventName}"`,
|
|
50
|
+
marker: { type: `data-zx-on-${eventName}`, id: '<unknown>' },
|
|
51
|
+
path: `event:${eventName}:${resolved.name || '<anonymous>'}`,
|
|
52
|
+
hint: 'Inspect handler logic and referenced state.'
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
element.addEventListener(eventName, wrapped);
|
|
58
|
+
_registerListener(element, eventName, wrapped);
|
|
59
|
+
}
|