@zenithbuild/runtime 0.2.1 → 0.5.0-beta.2.12
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 +112 -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 +1641 -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 +17 -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/index.js
CHANGED
|
@@ -1,505 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let cS = [];
|
|
6
|
-
let bD = 0;
|
|
7
|
-
let isFlushing = false;
|
|
8
|
-
let flushScheduled = false;
|
|
9
|
-
const pE = new Set();
|
|
10
|
-
// Lifecycle State
|
|
11
|
-
let isMounted = false;
|
|
12
|
-
const unmountCallbacks = new Set();
|
|
13
|
-
// Public Reactivity Utilities
|
|
14
|
-
export const trackDependency = (s) => { if (cE) {
|
|
15
|
-
s.add(cE);
|
|
16
|
-
cE.dependencies.add(s);
|
|
17
|
-
} };
|
|
18
|
-
export const notifySubscribers = (s) => {
|
|
19
|
-
if (!s)
|
|
20
|
-
return;
|
|
21
|
-
const es = Array.from(s);
|
|
22
|
-
for (const e of es) {
|
|
23
|
-
if (e.isRunning)
|
|
24
|
-
continue;
|
|
25
|
-
if (bD > 0 || isFlushing)
|
|
26
|
-
pE.add(e);
|
|
27
|
-
else
|
|
28
|
-
e.run();
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
export const getCurrentContext = () => cE;
|
|
32
|
-
export const pushContext = (e) => { cS.push(cE); cE = e; };
|
|
33
|
-
export const popContext = () => { cE = cS.pop(); };
|
|
34
|
-
export const cleanupContext = (e) => { for (const d of e.dependencies)
|
|
35
|
-
d.delete(e); e.dependencies.clear(); };
|
|
36
|
-
export const startBatch = () => { bD++; };
|
|
37
|
-
export const endBatch = () => { bD--; if (bD === 0)
|
|
38
|
-
flushEffects(); };
|
|
39
|
-
export const isBatching = () => bD > 0;
|
|
40
|
-
export const runUntracked = (fn) => {
|
|
41
|
-
pushContext(null);
|
|
42
|
-
try {
|
|
43
|
-
return fn();
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
popContext();
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
// Public Lifecycle Utilities
|
|
50
|
-
export const triggerMount = () => { isMounted = true; };
|
|
51
|
-
export const triggerUnmount = () => {
|
|
52
|
-
isMounted = false;
|
|
53
|
-
executeUnmountCallbacks();
|
|
54
|
-
};
|
|
55
|
-
export const executeUnmountCallbacks = () => {
|
|
56
|
-
for (const cb of unmountCallbacks) {
|
|
57
|
-
try {
|
|
58
|
-
cb();
|
|
59
|
-
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
console.error('Error in unmount callback:', e);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
unmountCallbacks.clear();
|
|
65
|
-
};
|
|
66
|
-
export const getIsMounted = () => isMounted;
|
|
67
|
-
export const getUnmountCallbackCount = () => unmountCallbacks.size;
|
|
68
|
-
export const resetMountState = () => { isMounted = false; };
|
|
69
|
-
export const resetUnmountState = () => { unmountCallbacks.clear(); };
|
|
70
|
-
if (typeof window !== 'undefined') {
|
|
71
|
-
window.__ZENITH_EXPRESSIONS__ = new Map();
|
|
72
|
-
window.__ZENITH_SCOPES__ = {};
|
|
73
|
-
}
|
|
74
|
-
// Phase A3: Post-Mount Execution Hook
|
|
75
|
-
const mountedScopes = new Set();
|
|
76
|
-
export function mountComponent(scopeId) {
|
|
77
|
-
if (mountedScopes.has(scopeId))
|
|
78
|
-
return;
|
|
79
|
-
mountedScopes.add(scopeId);
|
|
80
|
-
const scope = window.__ZENITH_SCOPES__[scopeId];
|
|
81
|
-
if (!scope)
|
|
82
|
-
return;
|
|
83
|
-
if (typeof scope.__run === 'function') {
|
|
84
|
-
scope.__run();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// Internal shorthand helpers (matching original compiled code requirements if any)
|
|
88
|
-
const pC = pushContext;
|
|
89
|
-
const oC = popContext;
|
|
90
|
-
const tD = trackDependency;
|
|
91
|
-
const nS = notifySubscribers;
|
|
92
|
-
const cEf = cleanupContext;
|
|
93
|
-
export function zenRoute() {
|
|
94
|
-
if (typeof window === 'undefined')
|
|
95
|
-
return { path: '/', slugs: [] };
|
|
96
|
-
const path = window.location.pathname;
|
|
97
|
-
return {
|
|
98
|
-
path: path,
|
|
99
|
-
slugs: path.split('/').filter(Boolean)
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function scheduleFlush() {
|
|
103
|
-
if (flushScheduled)
|
|
104
|
-
return;
|
|
105
|
-
flushScheduled = true;
|
|
106
|
-
queueMicrotask(() => {
|
|
107
|
-
flushScheduled = false;
|
|
108
|
-
flushEffects();
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
function flushEffects() {
|
|
112
|
-
if (isFlushing || bD > 0)
|
|
113
|
-
return;
|
|
114
|
-
isFlushing = true;
|
|
115
|
-
try {
|
|
116
|
-
while (pE.size > 0) {
|
|
117
|
-
const efs = Array.from(pE);
|
|
118
|
-
pE.clear();
|
|
119
|
-
for (const e of efs) {
|
|
120
|
-
if (!e.isRunning)
|
|
121
|
-
e.run();
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
finally {
|
|
126
|
-
isFlushing = false;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
export const signal = function (v) {
|
|
130
|
-
const s = new Set();
|
|
131
|
-
function sig(nV) {
|
|
132
|
-
if (arguments.length === 0) {
|
|
133
|
-
tD(s);
|
|
134
|
-
return v;
|
|
135
|
-
}
|
|
136
|
-
if (nV !== v) {
|
|
137
|
-
v = nV;
|
|
138
|
-
nS(s);
|
|
139
|
-
scheduleFlush();
|
|
140
|
-
}
|
|
141
|
-
return v;
|
|
142
|
-
}
|
|
143
|
-
sig._isSignal = true;
|
|
144
|
-
sig.toString = () => String(v);
|
|
145
|
-
sig.valueOf = () => v;
|
|
146
|
-
return sig;
|
|
147
|
-
};
|
|
148
|
-
export const state = function (o) {
|
|
149
|
-
const subs = new Map();
|
|
150
|
-
function gS(p) { if (!subs.has(p))
|
|
151
|
-
subs.set(p, new Set()); return subs.get(p); }
|
|
152
|
-
function notify(p) { nS(gS(p)); scheduleFlush(); }
|
|
153
|
-
function subscribe(p, ef) { gS(p).add(ef); ef.dependencies.add(gS(p)); }
|
|
154
|
-
function cP(obj, pPath = '') {
|
|
155
|
-
if (obj === null || typeof obj !== 'object' || obj._isSignal)
|
|
156
|
-
return obj;
|
|
157
|
-
return new Proxy(obj, {
|
|
158
|
-
get(t, p) {
|
|
159
|
-
if (p === Symbol.for('zenith_notify'))
|
|
160
|
-
return notify;
|
|
161
|
-
if (p === Symbol.for('zenith_subscribe'))
|
|
162
|
-
return subscribe;
|
|
163
|
-
if (typeof p === 'symbol')
|
|
164
|
-
return t[p];
|
|
165
|
-
const path = pPath ? `${pPath}.${String(p)}` : String(p);
|
|
166
|
-
tD(gS(path));
|
|
167
|
-
const v = t[p];
|
|
168
|
-
if (v !== null && typeof v === 'object' && !v._isSignal)
|
|
169
|
-
return cP(v, path);
|
|
170
|
-
return v;
|
|
171
|
-
},
|
|
172
|
-
set(t, p, nV) {
|
|
173
|
-
if (typeof p === 'symbol') {
|
|
174
|
-
t[p] = nV;
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
const path = pPath ? `${pPath}.${String(p)}` : String(p);
|
|
178
|
-
const oV = t[p];
|
|
179
|
-
if (oV && typeof oV === 'function' && oV._isSignal)
|
|
180
|
-
oV(nV);
|
|
181
|
-
else if (oV !== nV) {
|
|
182
|
-
t[p] = nV;
|
|
183
|
-
nS(gS(path));
|
|
184
|
-
const pts = path.split('.');
|
|
185
|
-
for (let i = pts.length - 1; i >= 0; i--) {
|
|
186
|
-
const pp = pts.slice(0, i).join('.');
|
|
187
|
-
if (pp)
|
|
188
|
-
nS(gS(pp));
|
|
189
|
-
}
|
|
190
|
-
scheduleFlush();
|
|
191
|
-
}
|
|
192
|
-
return true;
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
return cP(o);
|
|
197
|
-
};
|
|
198
|
-
export const effect = function (fn, opts = {}) {
|
|
199
|
-
let cl, tm;
|
|
200
|
-
const ef = {
|
|
201
|
-
dependencies: new Set(),
|
|
202
|
-
isRunning: false,
|
|
203
|
-
run: () => {
|
|
204
|
-
if (ef.isRunning)
|
|
205
|
-
return;
|
|
206
|
-
const schedule = opts.scheduler || ((f) => f());
|
|
207
|
-
if (opts.debounce) {
|
|
208
|
-
if (tm)
|
|
209
|
-
clearTimeout(tm);
|
|
210
|
-
tm = setTimeout(() => schedule(ex), opts.debounce);
|
|
211
|
-
}
|
|
212
|
-
else
|
|
213
|
-
schedule(ex);
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
function ex() {
|
|
217
|
-
if (ef.isRunning)
|
|
218
|
-
return;
|
|
219
|
-
ef.isRunning = true;
|
|
220
|
-
cEf(ef);
|
|
221
|
-
pC(ef);
|
|
222
|
-
try {
|
|
223
|
-
if (cl)
|
|
224
|
-
cl();
|
|
225
|
-
cl = fn();
|
|
226
|
-
}
|
|
227
|
-
finally {
|
|
228
|
-
oC();
|
|
229
|
-
ef.isRunning = false;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
if (!opts.defer)
|
|
233
|
-
ex();
|
|
234
|
-
return () => { cEf(ef); if (cl)
|
|
235
|
-
cl(); };
|
|
236
|
-
};
|
|
237
|
-
export const memo = function (fn) {
|
|
238
|
-
const sig = signal(undefined);
|
|
239
|
-
effect(() => sig(fn()));
|
|
240
|
-
const m = () => sig();
|
|
241
|
-
m._isSignal = true;
|
|
242
|
-
return m;
|
|
243
|
-
};
|
|
244
|
-
export const batch = function (fn) {
|
|
245
|
-
startBatch();
|
|
246
|
-
try {
|
|
247
|
-
fn();
|
|
248
|
-
}
|
|
249
|
-
finally {
|
|
250
|
-
endBatch();
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
export const untrack = function (fn) {
|
|
254
|
-
return runUntracked(fn);
|
|
255
|
-
};
|
|
256
|
-
export const ref = (i) => ({ current: i || null });
|
|
257
|
-
export const onMount = (cb) => {
|
|
258
|
-
if (typeof window !== 'undefined' && window.__zenith && window.__zenith.activeInstance) {
|
|
259
|
-
window.__zenith.activeInstance.mountHooks.push(cb);
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
// Fallback for non-component context or SSR
|
|
263
|
-
if (isMounted)
|
|
264
|
-
cb();
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
export const onUnmount = (cb) => {
|
|
268
|
-
unmountCallbacks.add(cb);
|
|
269
|
-
};
|
|
270
|
-
// DOM Helper (hC)
|
|
271
|
-
function hC(parent, child) {
|
|
272
|
-
if (child == null || child === false)
|
|
273
|
-
return;
|
|
274
|
-
let fn = child;
|
|
275
|
-
let id = null;
|
|
276
|
-
if (typeof child === 'object' && child.fn) {
|
|
277
|
-
fn = child.fn;
|
|
278
|
-
id = child.id;
|
|
279
|
-
}
|
|
280
|
-
const isTitle = parent && parent.tagName && parent.tagName.toLowerCase() === 'title';
|
|
281
|
-
if (typeof fn === 'function') {
|
|
282
|
-
if (isTitle) {
|
|
283
|
-
const val = fn();
|
|
284
|
-
if (val != null && val !== false) {
|
|
285
|
-
const text = String(val);
|
|
286
|
-
parent.appendChild(document.createTextNode(text));
|
|
287
|
-
document.title = text;
|
|
288
|
-
}
|
|
289
|
-
effect(() => {
|
|
290
|
-
const newVal = fn();
|
|
291
|
-
if (newVal != null && newVal !== false) {
|
|
292
|
-
const newText = String(newVal);
|
|
293
|
-
if (document.title !== newText) {
|
|
294
|
-
parent.textContent = newText;
|
|
295
|
-
document.title = newText;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}, { id: id ? `title-${id}` : 'title-sync' });
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
const ph = document.createComment('expr' + (id ? ':' + id : ''));
|
|
302
|
-
parent.appendChild(ph);
|
|
303
|
-
let curNodes = [];
|
|
304
|
-
effect(() => {
|
|
305
|
-
const r = fn();
|
|
306
|
-
curNodes.forEach(n => { if (n.parentNode)
|
|
307
|
-
n.parentNode.removeChild(n); });
|
|
308
|
-
curNodes = [];
|
|
309
|
-
if (r == null || r === false)
|
|
310
|
-
return;
|
|
311
|
-
const items = Array.isArray(r) ? r.flat(Infinity) : [r];
|
|
312
|
-
items.forEach(item => {
|
|
313
|
-
if (item == null || item === false)
|
|
314
|
-
return;
|
|
315
|
-
const node = item instanceof Node ? item : document.createTextNode(String(item));
|
|
316
|
-
if (ph.parentNode) {
|
|
317
|
-
ph.parentNode.insertBefore(node, ph);
|
|
318
|
-
curNodes.push(node);
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
}, { id });
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
else if (Array.isArray(child)) {
|
|
325
|
-
child.flat(Infinity).forEach(c => hC(parent, c));
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
parent.appendChild(child instanceof Node ? child : document.createTextNode(String(child)));
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
// Global Hydration
|
|
332
|
-
export function hydrate(state, container = document, locals = {}) {
|
|
333
|
-
const ir = window.canonicalIR;
|
|
334
|
-
if (!ir)
|
|
335
|
-
return;
|
|
336
|
-
window.__ZENITH_STATE__ = state;
|
|
337
|
-
const rootScope = { state, props: {}, locals: locals };
|
|
338
|
-
const nodes = ir(rootScope);
|
|
339
|
-
function findTag(items, tag) {
|
|
340
|
-
const list = Array.isArray(items) ? items : [items];
|
|
341
|
-
for (const item of list) {
|
|
342
|
-
if (item instanceof Element && item.tagName.toLowerCase() === tag)
|
|
343
|
-
return item;
|
|
344
|
-
if (item instanceof DocumentFragment) {
|
|
345
|
-
const found = findTag(Array.from(item.childNodes), tag);
|
|
346
|
-
if (found)
|
|
347
|
-
return found;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return null;
|
|
351
|
-
}
|
|
352
|
-
const headNode = findTag(nodes, 'head');
|
|
353
|
-
const bodyNode = findTag(nodes, 'body');
|
|
354
|
-
if (headNode) {
|
|
355
|
-
const headMount = document.head;
|
|
356
|
-
const newTitle = headNode.querySelector('title');
|
|
357
|
-
if (newTitle) {
|
|
358
|
-
let oldTitle = headMount.querySelector('title');
|
|
359
|
-
if (!oldTitle) {
|
|
360
|
-
oldTitle = document.createElement('title');
|
|
361
|
-
headMount.appendChild(oldTitle);
|
|
362
|
-
}
|
|
363
|
-
const titleContent = newTitle.childNodes.length > 0
|
|
364
|
-
? Array.from(newTitle.childNodes).map((n) => n.textContent).join('')
|
|
365
|
-
: '';
|
|
366
|
-
oldTitle.textContent = titleContent;
|
|
367
|
-
document.title = titleContent;
|
|
368
|
-
effect(() => {
|
|
369
|
-
const text = oldTitle.textContent?.trim();
|
|
370
|
-
if (text && document.title !== text) {
|
|
371
|
-
document.title = text;
|
|
372
|
-
}
|
|
373
|
-
}, { id: 'title-sync' });
|
|
374
|
-
}
|
|
375
|
-
headNode.querySelectorAll('meta').forEach((newMeta) => {
|
|
376
|
-
const name = newMeta.getAttribute('name');
|
|
377
|
-
if (name) {
|
|
378
|
-
const oldMeta = headMount.querySelector(`meta[name="${name}"]`);
|
|
379
|
-
if (oldMeta)
|
|
380
|
-
oldMeta.setAttribute('content', newMeta.getAttribute('content'));
|
|
381
|
-
else
|
|
382
|
-
headMount.appendChild(newMeta.cloneNode(true));
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
headNode.childNodes.forEach((n) => {
|
|
386
|
-
if (n.tagName === 'TITLE' || n.tagName === 'META')
|
|
387
|
-
return;
|
|
388
|
-
headMount.appendChild(n.cloneNode(true));
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
const bodyMount = container === document ? document.body : container;
|
|
392
|
-
if (bodyNode) {
|
|
393
|
-
bodyMount.innerHTML = '';
|
|
394
|
-
Array.from(bodyNode.childNodes).forEach(n => hC(bodyMount, n));
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
bodyMount.innerHTML = '';
|
|
398
|
-
const items = Array.isArray(nodes) ? nodes : [nodes];
|
|
399
|
-
items.forEach(n => hC(bodyMount, n));
|
|
400
|
-
}
|
|
401
|
-
for (const scopeId in window.__ZENITH_SCOPES__) {
|
|
402
|
-
mountComponent(scopeId);
|
|
403
|
-
}
|
|
404
|
-
queueMicrotask(() => {
|
|
405
|
-
flushEffects();
|
|
406
|
-
const titleEl = document.querySelector('title');
|
|
407
|
-
if (titleEl && titleEl.textContent) {
|
|
408
|
-
const text = titleEl.textContent.trim();
|
|
409
|
-
if (text && document.title !== text) {
|
|
410
|
-
document.title = text;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
// Ordered Effects
|
|
416
|
-
export function order(fn) {
|
|
417
|
-
if (typeof fn === 'function')
|
|
418
|
-
fn();
|
|
419
|
-
}
|
|
420
|
-
// Hyperscript
|
|
421
|
-
let currentNamespace = null;
|
|
422
|
-
export function h(tag, props, children) {
|
|
423
|
-
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
424
|
-
const SVG_TAGS = new Set(['svg', 'path', 'circle', 'ellipse', 'line', 'polygon', 'polyline', 'rect', 'g', 'defs', 'clipPath', 'mask', 'use', 'symbol', 'text', 'tspan', 'textPath', 'image', 'foreignObject', 'switch', 'desc', 'title', 'metadata', 'linearGradient', 'radialGradient', 'stop', 'pattern', 'filter', 'feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feFlood', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'feSpecularLighting', 'feTile', 'feTurbulence', 'animate', 'animateMotion', 'animateTransform', 'set', 'marker']);
|
|
425
|
-
const isSvgTag = SVG_TAGS.has(tag) || SVG_TAGS.has(tag.toLowerCase());
|
|
426
|
-
const useSvgNamespace = isSvgTag || currentNamespace === SVG_NS;
|
|
427
|
-
const el = useSvgNamespace ? document.createElementNS(SVG_NS, tag) : document.createElement(tag);
|
|
428
|
-
const previousNamespace = currentNamespace;
|
|
429
|
-
if (tag === 'svg' || tag === 'SVG') {
|
|
430
|
-
currentNamespace = SVG_NS;
|
|
431
|
-
}
|
|
432
|
-
if (props) {
|
|
433
|
-
const setClass = (element, value) => {
|
|
434
|
-
if (useSvgNamespace && 'className' in element && typeof element.className === 'object') {
|
|
435
|
-
element.className.baseVal = String(value || '');
|
|
436
|
-
}
|
|
437
|
-
else {
|
|
438
|
-
element.className = String(value || '');
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
for (const [k, v] of Object.entries(props)) {
|
|
442
|
-
if (k === 'ref') {
|
|
443
|
-
if (v && typeof v === 'object' && 'current' in v)
|
|
444
|
-
v.current = el;
|
|
445
|
-
else if (typeof v === 'string') {
|
|
446
|
-
const s = window.__ZENITH_STATE__;
|
|
447
|
-
if (s && s[v] && typeof s[v] === 'object' && 'current' in s[v])
|
|
448
|
-
s[v].current = el;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
else if (k.startsWith('on')) {
|
|
452
|
-
let fn = v;
|
|
453
|
-
if (v && typeof v === 'object' && v.fn)
|
|
454
|
-
fn = v.fn;
|
|
455
|
-
if (typeof fn === 'function') {
|
|
456
|
-
el.addEventListener(k.slice(2).toLowerCase(), (e) => {
|
|
457
|
-
const h = fn.call(el, e, el);
|
|
458
|
-
if (typeof h === 'function')
|
|
459
|
-
h.call(el, e, el);
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
else {
|
|
464
|
-
let fn = v;
|
|
465
|
-
let id = null;
|
|
466
|
-
if (typeof v === 'object' && v.fn) {
|
|
467
|
-
fn = v.fn;
|
|
468
|
-
id = v.id;
|
|
469
|
-
}
|
|
470
|
-
if (typeof fn === 'function') {
|
|
471
|
-
effect(() => {
|
|
472
|
-
const val = fn();
|
|
473
|
-
if (k === 'class' || k === 'className')
|
|
474
|
-
setClass(el, val);
|
|
475
|
-
else if (val == null || val === false)
|
|
476
|
-
el.removeAttribute(k);
|
|
477
|
-
else if (el.setAttribute)
|
|
478
|
-
el.setAttribute(k, String(val));
|
|
479
|
-
}, { id });
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
if (k === 'class' || k === 'className')
|
|
483
|
-
setClass(el, v);
|
|
484
|
-
else if (el.setAttribute)
|
|
485
|
-
el.setAttribute(k, String(v));
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
if (children) {
|
|
491
|
-
const items = Array.isArray(children) ? children : [children];
|
|
492
|
-
items.forEach(c => hC(el, c));
|
|
493
|
-
}
|
|
494
|
-
currentNamespace = previousNamespace;
|
|
495
|
-
return el;
|
|
496
|
-
}
|
|
497
|
-
export function fragment(c) {
|
|
498
|
-
const f = document.createDocumentFragment();
|
|
499
|
-
const items = Array.isArray(c) ? c : [c];
|
|
500
|
-
items.forEach(i => hC(f, i));
|
|
501
|
-
return f;
|
|
502
|
-
}
|
|
503
|
-
export * from './dom-hydration.js';
|
|
504
|
-
export * from './thin-runtime.js';
|
|
505
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { signal } from './signal.js';
|
|
2
|
+
export { state } from './state.js';
|
|
3
|
+
export { zeneffect } from './zeneffect.js';
|
|
4
|
+
export { hydrate } from './hydrate.js';
|
package/dist/ref.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// ref.js — Zenith Runtime ref primitive
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// A structural DOM pointer. NOT reactive.
|
|
5
|
+
// ref.current is a plain property — no tracking, no proxies, no subscriptions.
|
|
6
|
+
//
|
|
7
|
+
// Contract:
|
|
8
|
+
// - ref() returns { current: null }
|
|
9
|
+
// - ref(initialValue) returns { current: initialValue }
|
|
10
|
+
// - .current is assigned by runtime at mount, before zenMount callbacks run
|
|
11
|
+
// - .current is set to null on component disposal
|
|
12
|
+
// - Reading .current does NOT register a dependency in zenEffect
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create a deterministic ref for structural DOM binding.
|
|
16
|
+
*
|
|
17
|
+
* @template T
|
|
18
|
+
* @param {T} [initialValue]
|
|
19
|
+
* @returns {{ current: T | null }}
|
|
20
|
+
*/
|
|
21
|
+
export function ref(initialValue) {
|
|
22
|
+
return { current: initialValue ?? null };
|
|
23
|
+
}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// runtime.js — Zenith Runtime V0
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Backward-compatible mount wrapper around explicit hydrate(payload).
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
import { hydrate } from './hydrate.js';
|
|
8
|
+
import { cleanup } from './cleanup.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Mount a page module that already contains deterministic binding tables.
|
|
12
|
+
*
|
|
13
|
+
* @param {HTMLElement} container
|
|
14
|
+
* @param {object | function} pageModule
|
|
15
|
+
* @returns {() => void}
|
|
16
|
+
*/
|
|
17
|
+
export function mount(container, pageModule) {
|
|
18
|
+
if (!container || typeof container.querySelectorAll !== 'function') {
|
|
19
|
+
throw new Error('[Zenith Runtime] mount(container, pageModule) requires a DOM container');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const pageFactory = _resolvePageFactory(pageModule);
|
|
23
|
+
if (!pageFactory) {
|
|
24
|
+
throw new Error('[Zenith Runtime] mount(container, pageModule) requires default() or __zenith_page()');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const page = pageFactory();
|
|
28
|
+
if (!page || typeof page.html !== 'string') {
|
|
29
|
+
throw new Error('[Zenith Runtime] __zenith_page() must return an object with html');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
container.innerHTML = page.html;
|
|
33
|
+
|
|
34
|
+
hydrate({
|
|
35
|
+
root: container,
|
|
36
|
+
ir_version: page.ir_version,
|
|
37
|
+
expressions: Array.isArray(page.expressions) ? page.expressions : [],
|
|
38
|
+
markers: Array.isArray(page.markers) ? page.markers : [],
|
|
39
|
+
events: Array.isArray(page.events) ? page.events : [],
|
|
40
|
+
state_values: Array.isArray(page.state_values) ? page.state_values : [],
|
|
41
|
+
signals: Array.isArray(page.signals) ? page.signals : [],
|
|
42
|
+
components: Array.isArray(page.components) ? page.components : []
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return function unmount() {
|
|
46
|
+
cleanup();
|
|
47
|
+
container.innerHTML = '';
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function _resolvePageFactory(pageModule) {
|
|
52
|
+
if (typeof pageModule === 'function') return pageModule;
|
|
53
|
+
if (!pageModule || typeof pageModule !== 'object') return null;
|
|
54
|
+
if (typeof pageModule.default === 'function') return pageModule.default;
|
|
55
|
+
if (typeof pageModule.__zenith_page === 'function') return pageModule.__zenith_page;
|
|
56
|
+
return null;
|
|
57
|
+
}
|
package/dist/signal.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// signal.js — Zenith Runtime V0
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Minimal explicit signal primitive.
|
|
5
|
+
//
|
|
6
|
+
// API:
|
|
7
|
+
// const count = signal(0);
|
|
8
|
+
// count.get();
|
|
9
|
+
// count.set(1);
|
|
10
|
+
// const unsubscribe = count.subscribe((value) => { ... });
|
|
11
|
+
//
|
|
12
|
+
// Constraints:
|
|
13
|
+
// - No proxy
|
|
14
|
+
// - No implicit dependency tracking
|
|
15
|
+
// - No scheduler
|
|
16
|
+
// - No async queue
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create a deterministic signal with explicit subscription semantics.
|
|
21
|
+
*
|
|
22
|
+
* @param {*} initialValue
|
|
23
|
+
* @returns {{ get: () => *, set: (next: *) => *, subscribe: (fn: (value: *) => void) => () => void }}
|
|
24
|
+
*/
|
|
25
|
+
export function signal(initialValue) {
|
|
26
|
+
let value = initialValue;
|
|
27
|
+
const subscribers = new Set();
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
get() {
|
|
31
|
+
return value;
|
|
32
|
+
},
|
|
33
|
+
set(nextValue) {
|
|
34
|
+
if (Object.is(value, nextValue)) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
value = nextValue;
|
|
39
|
+
|
|
40
|
+
const snapshot = [...subscribers];
|
|
41
|
+
for (let i = 0; i < snapshot.length; i++) {
|
|
42
|
+
snapshot[i](value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return value;
|
|
46
|
+
},
|
|
47
|
+
subscribe(fn) {
|
|
48
|
+
if (typeof fn !== 'function') {
|
|
49
|
+
throw new Error('[Zenith Runtime] signal.subscribe(fn) requires a function');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
subscribers.add(fn);
|
|
53
|
+
return function unsubscribe() {
|
|
54
|
+
subscribers.delete(fn);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|