essor 0.0.13-beta.7 → 0.0.13

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.
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * essor v0.0.13-beta.7
4
+ * essor v0.0.13
5
5
  * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
6
6
  * @license MIT
7
7
  **/
8
8
 
9
9
  // src/version.ts
10
- var essor_version = "0.0.13-beta.7";
10
+ var essor_version = "0.0.13";
11
11
 
12
12
  // ../shared/dist/shared.js
13
13
  var isObject = (val) => val !== null && typeof val === "object";
@@ -33,12 +33,12 @@ function isWeakSet(val) {
33
33
  function isMap(val) {
34
34
  return _toString.call(val) === "[object Map]";
35
35
  }
36
- function isNil(x2) {
37
- return x2 === null || x2 === void 0;
36
+ function isNil(x) {
37
+ return x === null || x === void 0;
38
38
  }
39
39
  var isFunction = (val) => typeof val === "function";
40
- function isFalsy(x2) {
41
- return x2 === false || x2 === null || x2 === void 0;
40
+ function isFalsy(x) {
41
+ return x === false || x === null || x === void 0;
42
42
  }
43
43
  var isPrimitive = (val) => ["string", "number", "boolean", "symbol", "undefined"].includes(typeof val) || isNull(val);
44
44
  var isPlainObject = (val) => _toString.call(val) === "[object Object]";
@@ -95,401 +95,855 @@ function warn(msg, ...args) {
95
95
  console.warn.apply(console, [`[Essor warn]: ${msg}`].concat(args));
96
96
  }
97
97
 
98
- // ../signal/dist/signal.esm.js
99
- var ye = Object.defineProperty;
100
- var U = Object.getOwnPropertySymbols;
101
- var Se = Object.prototype.hasOwnProperty;
102
- var me = Object.prototype.propertyIsEnumerable;
103
- var Q = (e, t, n) => t in e ? ye(e, t, { enumerable: true, configurable: true, writable: true, value: n }) : e[t] = n;
104
- var y = (e, t) => {
105
- for (var n in t || (t = {})) Se.call(t, n) && Q(e, n, t[n]);
106
- if (U) for (var n of U(t)) me.call(t, n) && Q(e, n, t[n]);
107
- return e;
98
+ // ../signal/dist/signal.dev.esm.js
99
+ var __defProp = Object.defineProperty;
100
+ var __defProps = Object.defineProperties;
101
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
102
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
103
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
104
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
105
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
106
+ var __spreadValues = (a, b) => {
107
+ for (var prop in b || (b = {}))
108
+ if (__hasOwnProp.call(b, prop))
109
+ __defNormalProp(a, prop, b[prop]);
110
+ if (__getOwnPropSymbols)
111
+ for (var prop of __getOwnPropSymbols(b)) {
112
+ if (__propIsEnum.call(b, prop))
113
+ __defNormalProp(a, prop, b[prop]);
114
+ }
115
+ return a;
108
116
  };
109
- var M = [];
110
- var F = [];
111
- var X = Promise.resolve();
112
- var K = false;
113
- function E(e) {
114
- return e ? X.then(e) : X;
115
- }
116
- function ge(e) {
117
- M.includes(e) || (M.push(e), Y());
118
- }
119
- function Y() {
120
- K || (K = true, E(we));
117
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
118
+ var queue = [];
119
+ var activePreFlushCbs = [];
120
+ var p = Promise.resolve();
121
+ var isFlushPending = false;
122
+ function nextTick(fn) {
123
+ return fn ? p.then(fn) : p;
124
+ }
125
+ function queueJob(job) {
126
+ if (!queue.includes(job)) {
127
+ queue.push(job);
128
+ queueFlush();
129
+ }
130
+ }
131
+ function queueFlush() {
132
+ if (isFlushPending) {
133
+ return;
134
+ }
135
+ isFlushPending = true;
136
+ nextTick(flushJobs);
121
137
  }
122
- function _e(e) {
123
- xe(e, F);
138
+ function queuePreFlushCb(cb) {
139
+ queueCb(cb, activePreFlushCbs);
124
140
  }
125
- function xe(e, t) {
126
- t.includes(e) || (t.push(e), Y());
141
+ function queueCb(cb, activeQueue) {
142
+ if (!activeQueue.includes(cb)) {
143
+ activeQueue.push(cb);
144
+ queueFlush();
145
+ }
127
146
  }
128
- function we() {
129
- K = false, ve();
130
- let e;
131
- for (; e = M.shift(); ) e && e();
147
+ function flushJobs() {
148
+ isFlushPending = false;
149
+ flushPreFlushCbs();
150
+ let job;
151
+ while (job = queue.shift()) {
152
+ if (job) {
153
+ job();
154
+ }
155
+ }
132
156
  }
133
- function ve() {
134
- for (; F.length > 0; ) {
135
- let e = F.shift();
136
- e && e();
157
+ function flushPreFlushCbs() {
158
+ while (activePreFlushCbs.length > 0) {
159
+ const cb = activePreFlushCbs.shift();
160
+ if (cb) {
161
+ cb();
162
+ }
137
163
  }
138
164
  }
139
- function Z(e, t) {
140
- return t === "sync" ? () => e() : t === "pre" ? () => _e(e) : () => {
141
- E(() => ge(e));
142
- };
165
+ function createScheduler(effect, flush) {
166
+ if (flush === "sync") {
167
+ return () => effect();
168
+ } else if (flush === "pre") {
169
+ return () => queuePreFlushCb(effect);
170
+ } else {
171
+ return () => {
172
+ nextTick(() => queueJob(effect));
173
+ };
174
+ }
143
175
  }
144
- var T = null;
145
- var G = /* @__PURE__ */ new WeakMap();
146
- var H = /* @__PURE__ */ new WeakMap();
147
- var x = Symbol("");
148
- var w = Symbol("");
149
- var te = Symbol("");
150
- var ne = Symbol("");
151
- var $ = Symbol("");
152
- var f = Symbol("");
153
- var S = Symbol("");
154
- var D = false;
155
- var P = /* @__PURE__ */ new Set();
156
- function u(e, t) {
157
- if (!T) return;
158
- let n = G.get(e);
159
- n || (n = /* @__PURE__ */ new Map(), G.set(e, n));
160
- let o = n.get(t);
161
- o || (o = /* @__PURE__ */ new Set(), n.set(t, o)), T && o.add(T);
162
- }
163
- function p(e, t) {
164
- let n = G.get(e);
165
- if (!n) return;
166
- let o = n.get(t);
167
- o && o.forEach((r) => {
168
- if (hasOwn(r, "active") && !r.active) {
169
- o.delete(r);
170
- return;
171
- }
172
- D ? P.add(r) : r();
173
- });
176
+ var activeEffect = null;
177
+ var triggerMap = /* @__PURE__ */ new WeakMap();
178
+ var reactiveMap = /* @__PURE__ */ new WeakMap();
179
+ var ReactiveSymbol = Symbol("ReactiveSymbol");
180
+ var ReactivePeekSymbol = Symbol("__raw");
181
+ var SignalValueKey = Symbol("SignalValueKey");
182
+ var ComputedValueKey = Symbol("ComputedValueKey");
183
+ var reactiveArrayKey = Symbol("ReactiveArrayKey");
184
+ var ReactiveCollectionKey = Symbol("ReactiveCollectionKey");
185
+ var ReactiveWeakCollectionKey = Symbol("ReactiveWeakCollectionKey");
186
+ var inBatch = false;
187
+ var batchQueue = /* @__PURE__ */ new Set();
188
+ function track(target, key) {
189
+ if (!activeEffect) return;
190
+ let depsMap = triggerMap.get(target);
191
+ if (!depsMap) {
192
+ depsMap = /* @__PURE__ */ new Map();
193
+ triggerMap.set(target, depsMap);
194
+ }
195
+ let dep = depsMap.get(key);
196
+ if (!dep) {
197
+ dep = /* @__PURE__ */ new Set();
198
+ depsMap.set(key, dep);
199
+ }
200
+ dep.add(activeEffect);
201
+ }
202
+ function trigger(target, key) {
203
+ const depsMap = triggerMap.get(target);
204
+ if (!depsMap) return;
205
+ const dep = depsMap.get(key);
206
+ if (dep) {
207
+ dep.forEach((effect) => {
208
+ if (hasOwn(effect, "active") && !effect.active) {
209
+ dep.delete(effect);
210
+ return;
211
+ }
212
+ inBatch ? batchQueue.add(effect) : effect();
213
+ });
214
+ }
174
215
  }
175
- var _ = class {
176
- constructor(t, n = false) {
216
+ var Signal = class {
217
+ /**
218
+ * Creates a new Signal instance.
219
+ * @param {T} value - The initial value of the Signal.
220
+ * @param {boolean} [shallow] - Whether to create a shallow Signal.
221
+ */
222
+ constructor(value, shallow = false) {
177
223
  this.__signal = true;
178
- this.__shallow = n, this.__value = t;
224
+ this.__shallow = shallow;
225
+ this.__value = value;
179
226
  }
227
+ /**
228
+ * Gets the current value of the Signal.
229
+ * @returns {T} The current value.
230
+ */
180
231
  get value() {
181
- return u(this, te), isObject(this.__value) && !this.__shallow ? v(this.__value) : this.__value;
232
+ track(this, SignalValueKey);
233
+ if (isObject(this.__value) && !this.__shallow) {
234
+ return reactive(this.__value);
235
+ }
236
+ return this.__value;
182
237
  }
183
- set value(t) {
184
- h(t) && (t = t.peek()), hasChanged(t, this.__value) && (this.__value = t, p(this, te));
238
+ /**
239
+ * Sets a new value for the Signal.
240
+ * @param {T} newValue - The new value to set.
241
+ */
242
+ set value(newValue) {
243
+ if (isSignal(newValue)) {
244
+ newValue = newValue.peek();
245
+ }
246
+ if (hasChanged(newValue, this.__value)) {
247
+ this.__value = newValue;
248
+ trigger(this, SignalValueKey);
249
+ }
185
250
  }
251
+ /**
252
+ * Returns the current value without triggering reactivity.
253
+ * @returns {T} The current value.
254
+ */
186
255
  peek() {
187
256
  return this.__value;
188
257
  }
189
258
  };
190
- function le(e) {
191
- return h(e) ? e : new _(e);
259
+ function useSignal(value) {
260
+ if (isSignal(value)) {
261
+ return value;
262
+ }
263
+ return new Signal(value);
192
264
  }
193
- function Re(e) {
194
- return new _(e, true);
265
+ function useShallowSignal(value) {
266
+ return new Signal(value, true);
195
267
  }
196
- function We(e) {
197
- return new _(e, true);
268
+ function shallowSignal(value) {
269
+ return new Signal(value, true);
198
270
  }
199
- function h(e) {
200
- return !!(e && (e != null && e.__signal));
271
+ function isSignal(value) {
272
+ return !!(value && (value == null ? void 0 : value.__signal));
201
273
  }
202
- var V = class {
203
- constructor(t) {
204
- this.fn = t;
274
+ var Computed = class {
275
+ constructor(fn) {
276
+ this.fn = fn;
205
277
  this.__computed = true;
206
- let n = T;
207
- T = this.run.bind(this), this.__value = this.fn(), T = n;
278
+ const prev = activeEffect;
279
+ activeEffect = this.run.bind(this);
280
+ this.__value = this.fn();
281
+ activeEffect = prev;
208
282
  }
283
+ /**
284
+ * Get the current computed value without tracking it.
285
+ */
209
286
  peek() {
210
287
  return this.__value;
211
288
  }
289
+ /**
290
+ * Run the computed function and update the value if it has changed.
291
+ */
212
292
  run() {
213
- let t = this.fn();
214
- hasChanged(t, this.__value) && (this.__value = t, p(this, ne));
293
+ const newValue = this.fn();
294
+ if (hasChanged(newValue, this.__value)) {
295
+ this.__value = newValue;
296
+ trigger(this, ComputedValueKey);
297
+ }
215
298
  }
299
+ /**
300
+ * Get the current computed value and track its usage.
301
+ */
216
302
  get value() {
217
- return u(this, ne), this.__value;
303
+ track(this, ComputedValueKey);
304
+ return this.__value;
218
305
  }
219
306
  };
220
- function z(e) {
221
- return new V(e);
307
+ function useComputed(fn) {
308
+ return new Computed(fn);
309
+ }
310
+ function isComputed(value) {
311
+ return !!(value && value.__computed);
312
+ }
313
+ function useEffect(fn, options = {}) {
314
+ const { flush = "pre", onTrack, onTrigger } = options;
315
+ function effectFn() {
316
+ const prev = activeEffect;
317
+ activeEffect = effectFn.init ? effectFn : effectFn.scheduler;
318
+ fn();
319
+ onTrigger && onTrigger();
320
+ activeEffect = prev;
321
+ }
322
+ const scheduler = createScheduler(effectFn, flush);
323
+ effectFn.scheduler = scheduler;
324
+ effectFn.init = true;
325
+ effectFn.active = true;
326
+ onTrack && onTrack();
327
+ effectFn();
328
+ return () => {
329
+ effectFn.active = false;
330
+ activeEffect = null;
331
+ };
222
332
  }
223
- function I(e) {
224
- return !!(e && e.__computed);
333
+ function signalObject(initialValues, exclude) {
334
+ if (!initialValues || !isObject(initialValues)) {
335
+ {
336
+ warn("initialValues must be an object,will return initial value!", initialValues);
337
+ }
338
+ return initialValues;
339
+ }
340
+ const signals = Object.entries(initialValues).reduce((acc, [key, value]) => {
341
+ acc[key] = isExclude(key, exclude) || isSignal(value) ? value : useSignal(value);
342
+ return acc;
343
+ }, {});
344
+ return signals;
225
345
  }
226
- function B(e, t = {}) {
227
- let { flush: n = "pre", onTrack: o, onTrigger: r } = t;
228
- function s() {
229
- let d = T;
230
- T = s.init ? s : s.scheduler, e(), r && r(), T = d;
346
+ function toRaw(value) {
347
+ if (!value) return value;
348
+ if (isReactive(value)) {
349
+ return value[ReactivePeekSymbol];
231
350
  }
232
- let i = Z(s, n);
233
- return s.scheduler = i, s.init = true, s.active = true, o && o(), s(), () => {
234
- s.active = false, T = null;
235
- };
351
+ if (isSignal(value)) {
352
+ return value.peek();
353
+ }
354
+ if (isArray(value)) {
355
+ return value.map((value2) => toRaw(value2));
356
+ }
357
+ if (isPlainObject(value)) {
358
+ return Object.fromEntries(
359
+ Object.entries(value).map(([key, value2]) => [key, toRaw(value2)])
360
+ );
361
+ }
362
+ return value;
363
+ }
364
+ function isReactive(obj) {
365
+ return !!(obj && typeof obj === "object" && obj[ReactiveSymbol]);
366
+ }
367
+ function useReactive(initialValue, exclude) {
368
+ return reactive(initialValue, false, exclude);
369
+ }
370
+ function shallowReactive(initialValue, exclude) {
371
+ return reactive(initialValue, true, exclude);
236
372
  }
237
- function Ce(e, t) {
238
- return !e || !isObject(e) ? e : Object.entries(e).reduce((o, [r, s]) => (o[r] = isExclude(r, t) || h(s) ? s : le(s), o), {});
239
- }
240
- function c(e) {
241
- return e && (b(e) ? e[w] : h(e) ? e.peek() : isArray(e) ? e.map((t) => c(t)) : isPlainObject(e) ? Object.fromEntries(Object.entries(e).map(([t, n]) => [t, c(n)])) : e);
242
- }
243
- function b(e) {
244
- return !!(e && typeof e == "object" && e[x]);
245
- }
246
- function L(e, t) {
247
- return v(e, false, t);
248
- }
249
- function Ee(e, t) {
250
- return v(e, true, t);
251
- }
252
- var Pe = (e, t) => ({ get(n, o, r) {
253
- if (o === x) return true;
254
- if (o === w) return n;
255
- let s = Reflect.get(n, o, r), i = h(s) ? s.value : s;
256
- return isExclude(o, t) ? i : (u(n, o), isObject(i) && !e ? v(i) : i);
257
- }, set(n, o, r, s) {
258
- if (isExclude(o, t)) return Reflect.set(n, o, r, s), true;
259
- let i = Reflect.get(n, o, s);
260
- h(i) && (i = i.value), h(r) && (r = r.value);
261
- let d = Reflect.set(n, o, r, s);
262
- return hasChanged(r, i) && p(n, o), d;
263
- }, deleteProperty(n, o) {
264
- let r = Reflect.get(n, o), s = Reflect.deleteProperty(n, o);
265
- return r !== void 0 && p(n, o), s;
266
- } });
267
- var oe = je();
268
- function je() {
269
- let e = {};
270
- return ["includes", "indexOf", "lastIndexOf"].forEach((t) => {
271
- e[t] = function(...n) {
272
- let o = c(this);
273
- for (let s = 0, i = this.length; s < i; s++) u(o, `${s}`);
274
- let r = o[t](...n);
275
- return r === -1 || r === false ? o[t](...n) : r;
373
+ var basicHandler = (shallow, exclude) => {
374
+ return {
375
+ get(target, key, receiver) {
376
+ if (key === ReactiveSymbol) return true;
377
+ if (key === ReactivePeekSymbol) return target;
378
+ const getValue = Reflect.get(target, key, receiver);
379
+ const value = isSignal(getValue) ? getValue.value : getValue;
380
+ if (isExclude(key, exclude)) {
381
+ return value;
382
+ }
383
+ track(target, key);
384
+ if (isObject(value) && !shallow) {
385
+ return reactive(value);
386
+ }
387
+ return value;
388
+ },
389
+ set(target, key, value, receiver) {
390
+ if (isExclude(key, exclude)) {
391
+ Reflect.set(target, key, value, receiver);
392
+ return true;
393
+ }
394
+ let oldValue = Reflect.get(target, key, receiver);
395
+ if (isSignal(oldValue)) {
396
+ oldValue = oldValue.value;
397
+ }
398
+ if (isSignal(value)) {
399
+ value = value.value;
400
+ }
401
+ const obj = Reflect.set(target, key, value, receiver);
402
+ if (hasChanged(value, oldValue)) {
403
+ trigger(target, key);
404
+ }
405
+ return obj;
406
+ },
407
+ // handle delete
408
+ deleteProperty(target, key) {
409
+ const oldValue = Reflect.get(target, key);
410
+ const result = Reflect.deleteProperty(target, key);
411
+ if (oldValue !== void 0) {
412
+ trigger(target, key);
413
+ }
414
+ return result;
415
+ }
416
+ };
417
+ };
418
+ var arrayInstrumentations = createArrayInstrumentations();
419
+ function createArrayInstrumentations() {
420
+ const instrumentations2 = {};
421
+ ["includes", "indexOf", "lastIndexOf"].forEach((key) => {
422
+ instrumentations2[key] = function(...args) {
423
+ const arr = toRaw(this);
424
+ for (let i = 0, l = this.length; i < l; i++) {
425
+ track(arr, `${i}`);
426
+ }
427
+ const res = arr[key](...args);
428
+ if (res === -1 || res === false) {
429
+ return arr[key](...args);
430
+ }
431
+ return res;
276
432
  };
277
- }), ["push", "pop", "shift", "unshift", "splice", "sort", "reverse"].forEach((t) => {
278
- e[t] = function(...n) {
279
- let o = c(this), r = o[t].apply(this, n);
280
- return p(o, $), r;
433
+ });
434
+ ["push", "pop", "shift", "unshift", "splice", "sort", "reverse"].forEach((key) => {
435
+ instrumentations2[key] = function(...args) {
436
+ const arr = toRaw(this);
437
+ const res = arr[key].apply(this, args);
438
+ trigger(arr, reactiveArrayKey);
439
+ return res;
281
440
  };
282
- }), ["forEach", "map", "filter", "reduce", "reduceRight", "some", "every", "find", "findIndex", "findLast", "findLastIndex", "entries", "keys", "values"].forEach((t) => {
283
- e[t] = function(...n) {
284
- let o = c(this);
285
- return u(o, $), o[t].apply(this, n);
441
+ });
442
+ [
443
+ "forEach",
444
+ "map",
445
+ "filter",
446
+ "reduce",
447
+ "reduceRight",
448
+ "some",
449
+ "every",
450
+ "find",
451
+ "findIndex",
452
+ "findLast",
453
+ "findLastIndex",
454
+ "entries",
455
+ "keys",
456
+ "values"
457
+ ].forEach((key) => {
458
+ instrumentations2[key] = function(...args) {
459
+ const arr = toRaw(this);
460
+ track(arr, reactiveArrayKey);
461
+ return arr[key].apply(this, args);
286
462
  };
287
- }), e;
288
- }
289
- var Ae = (e, t) => ({ get(n, o, r) {
290
- if (o === x) return true;
291
- if (o === w) return n;
292
- if (oe.hasOwnProperty(o)) return Reflect.get(oe, o, r);
293
- let s = Reflect.get(n, o, r);
294
- return isExclude(o, t) ? s : (isStringNumber(o) && u(n, o), u(n, "length"), isObject(s) && !e ? v(s) : s);
295
- }, set(n, o, r, s) {
296
- let i = Reflect.get(n, o, s), d = Reflect.set(n, o, r, s);
297
- return hasChanged(r, i) && (isStringNumber(o) && p(n, o), (o === "length" || !i) && p(n, "length")), d;
298
- } });
299
- var Ie = { get(e, t) {
300
- return t === x ? true : t === w ? e : ((t === Symbol.iterator || t === "size") && u(e, f), Reflect.get(hasOwn(re, t) && t in e ? re : e, t, e));
301
- } };
302
- var Oe = { get(e, t) {
303
- return t === x ? true : t === w ? e : Reflect.get(hasOwn(se, t) && t in e ? se : e, t, e);
304
- } };
305
- var re = { get(e) {
306
- let t = c(this);
307
- return u(t, f), t.get(e);
308
- }, set(e, t) {
309
- let n = c(this), o = n.set(e, t);
310
- return p(n, f), o;
311
- }, add(e) {
312
- let t = c(this), n = t.add(e);
313
- return p(t, f), n;
314
- }, has(e) {
315
- let t = c(this);
316
- return u(t, f), t.has(e);
317
- }, delete(e) {
318
- let t = c(this), n = t.has(e), o = t.delete(e);
319
- return n && p(t, f), o;
320
- }, clear() {
321
- let e = c(this), t = e.size > 0, n = e.clear();
322
- return t && p(e, f), n;
323
- }, forEach(e, t) {
324
- let n = c(this);
325
- u(n, f), n.forEach((o, r) => {
326
- e.call(t, o, r, n);
327
463
  });
328
- }, get size() {
329
- let e = c(this);
330
- return u(e, f), e.size;
331
- }, keys() {
332
- let e = c(this);
333
- return u(e, f), e.keys();
334
- }, values() {
335
- let e = c(this);
336
- return u(e, f), e.values();
337
- }, entries() {
338
- let e = c(this);
339
- return u(e, f), e.entries();
340
- }, [Symbol.iterator]() {
341
- let e = c(this);
342
- return u(e, f), e[Symbol.iterator]();
343
- } };
344
- var se = { get(e) {
345
- let t = c(this);
346
- return u(t, S), t.get(e);
347
- }, set(e, t) {
348
- let n = c(this), o = n.set(e, t);
349
- return p(n, S), o;
350
- }, add(e) {
351
- let t = c(this), n = t.add(e);
352
- return p(t, S), n;
353
- }, has(e) {
354
- let t = c(this);
355
- return u(t, S), t.has(e);
356
- }, delete(e) {
357
- let t = c(this), n = t.delete(e);
358
- return p(t, S), n;
359
- } };
360
- function v(e, t = false, n) {
361
- if (!isObject(e) || b(e)) return e;
362
- if (H.has(e)) return H.get(e);
363
- let o;
364
- isArray(e) ? (u(e, $), o = Ae(t, n)) : isSet(e) || isMap(e) ? (u(e, f), o = Ie) : isWeakSet(e) || isWeakMap(e) ? (u(e, S), o = Oe) : o = Pe(t, n);
365
- let r = new Proxy(e, o);
366
- return H.set(e, r), r;
367
- }
368
- function Me(e) {
369
- b(e) && (isWeakMap(e) || isWeakSet(e) || fe(() => {
370
- isArray(e) ? e.length = 0 : isSet(e) || isMap(e) ? e.clear() : isObject(e) && Object.keys(e).forEach((t) => {
371
- delete e[t];
464
+ return instrumentations2;
465
+ }
466
+ var ArrayHandler = (shallow, exclude) => {
467
+ return {
468
+ get(target, key, receiver) {
469
+ if (key === ReactiveSymbol) return true;
470
+ if (key === ReactivePeekSymbol) return target;
471
+ if (arrayInstrumentations.hasOwnProperty(key)) {
472
+ return Reflect.get(arrayInstrumentations, key, receiver);
473
+ }
474
+ const value = Reflect.get(target, key, receiver);
475
+ if (isExclude(key, exclude)) {
476
+ return value;
477
+ }
478
+ if (isStringNumber(key)) {
479
+ track(target, key);
480
+ }
481
+ track(target, "length");
482
+ if (isObject(value) && !shallow) {
483
+ return reactive(value);
484
+ }
485
+ return value;
486
+ },
487
+ set(target, key, value, receiver) {
488
+ const oldValue = Reflect.get(target, key, receiver);
489
+ const result = Reflect.set(target, key, value, receiver);
490
+ if (hasChanged(value, oldValue)) {
491
+ if (isStringNumber(key)) {
492
+ trigger(target, key);
493
+ }
494
+ if (key === "length" || !oldValue) {
495
+ trigger(target, "length");
496
+ }
497
+ }
498
+ return result;
499
+ }
500
+ };
501
+ };
502
+ var collectionHandlers = {
503
+ get(target, key) {
504
+ if (key === ReactiveSymbol) return true;
505
+ if (key === ReactivePeekSymbol) return target;
506
+ if (key === Symbol.iterator || key === "size") {
507
+ track(target, ReactiveCollectionKey);
508
+ }
509
+ return Reflect.get(
510
+ hasOwn(instrumentations, key) && key in target ? instrumentations : target,
511
+ key,
512
+ target
513
+ );
514
+ }
515
+ };
516
+ var weakCollectionHandlers = {
517
+ get(target, key) {
518
+ if (key === ReactiveSymbol) return true;
519
+ if (key === ReactivePeekSymbol) return target;
520
+ return Reflect.get(
521
+ hasOwn(weakInstrumentations, key) && key in target ? weakInstrumentations : target,
522
+ key,
523
+ target
524
+ );
525
+ }
526
+ };
527
+ var instrumentations = {
528
+ get(key) {
529
+ const target = toRaw(this);
530
+ track(target, ReactiveCollectionKey);
531
+ return target.get(key);
532
+ },
533
+ set(key, value) {
534
+ const target = toRaw(this);
535
+ const result = target.set(key, value);
536
+ trigger(target, ReactiveCollectionKey);
537
+ return result;
538
+ },
539
+ add(value) {
540
+ const target = toRaw(this);
541
+ const result = target.add(value);
542
+ trigger(target, ReactiveCollectionKey);
543
+ return result;
544
+ },
545
+ has(key) {
546
+ const target = toRaw(this);
547
+ track(target, ReactiveCollectionKey);
548
+ return target.has(key);
549
+ },
550
+ delete(key) {
551
+ const target = toRaw(this);
552
+ const hadKey = target.has(key);
553
+ const result = target.delete(key);
554
+ if (hadKey) {
555
+ trigger(target, ReactiveCollectionKey);
556
+ }
557
+ return result;
558
+ },
559
+ clear() {
560
+ const target = toRaw(this);
561
+ const hadItems = target.size > 0;
562
+ const result = target.clear();
563
+ if (hadItems) {
564
+ trigger(target, ReactiveCollectionKey);
565
+ }
566
+ return result;
567
+ },
568
+ forEach(callback, thisArg) {
569
+ const target = toRaw(this);
570
+ track(target, ReactiveCollectionKey);
571
+ target.forEach((value, key) => {
572
+ callback.call(thisArg, value, key, target);
372
573
  });
373
- }));
574
+ },
575
+ get size() {
576
+ const target = toRaw(this);
577
+ track(target, ReactiveCollectionKey);
578
+ return target.size;
579
+ },
580
+ keys() {
581
+ const target = toRaw(this);
582
+ track(target, ReactiveCollectionKey);
583
+ return target.keys();
584
+ },
585
+ values() {
586
+ const target = toRaw(this);
587
+ track(target, ReactiveCollectionKey);
588
+ return target.values();
589
+ },
590
+ entries() {
591
+ const target = toRaw(this);
592
+ track(target, ReactiveCollectionKey);
593
+ return target.entries();
594
+ },
595
+ [Symbol.iterator]() {
596
+ const target = toRaw(this);
597
+ track(target, ReactiveCollectionKey);
598
+ return target[Symbol.iterator]();
599
+ }
600
+ };
601
+ var weakInstrumentations = {
602
+ get(key) {
603
+ const target = toRaw(this);
604
+ track(target, ReactiveWeakCollectionKey);
605
+ return target.get(key);
606
+ },
607
+ set(key, value) {
608
+ const target = toRaw(this);
609
+ const result = target.set(key, value);
610
+ trigger(target, ReactiveWeakCollectionKey);
611
+ return result;
612
+ },
613
+ add(value) {
614
+ const target = toRaw(this);
615
+ const result = target.add(value);
616
+ trigger(target, ReactiveWeakCollectionKey);
617
+ return result;
618
+ },
619
+ has(key) {
620
+ const target = toRaw(this);
621
+ track(target, ReactiveWeakCollectionKey);
622
+ return target.has(key);
623
+ },
624
+ delete(key) {
625
+ const target = toRaw(this);
626
+ const result = target.delete(key);
627
+ trigger(target, ReactiveWeakCollectionKey);
628
+ return result;
629
+ }
630
+ };
631
+ function reactive(initialValue, shallow = false, exclude) {
632
+ if (!isObject(initialValue)) {
633
+ return initialValue;
634
+ }
635
+ if (isReactive(initialValue)) {
636
+ return initialValue;
637
+ }
638
+ if (reactiveMap.has(initialValue)) {
639
+ return reactiveMap.get(initialValue);
640
+ }
641
+ let handler;
642
+ if (isArray(initialValue)) {
643
+ track(initialValue, reactiveArrayKey);
644
+ handler = ArrayHandler(shallow, exclude);
645
+ } else if (isSet(initialValue) || isMap(initialValue)) {
646
+ track(initialValue, ReactiveCollectionKey);
647
+ handler = collectionHandlers;
648
+ } else if (isWeakSet(initialValue) || isWeakMap(initialValue)) {
649
+ track(initialValue, ReactiveWeakCollectionKey);
650
+ handler = weakCollectionHandlers;
651
+ } else {
652
+ handler = basicHandler(shallow, exclude);
653
+ }
654
+ const proxy = new Proxy(initialValue, handler);
655
+ reactiveMap.set(initialValue, proxy);
656
+ return proxy;
657
+ }
658
+ function clearReactive(reactiveObj) {
659
+ if (!isReactive(reactiveObj)) {
660
+ {
661
+ warn("clearReactive: argument must be a reactive object");
662
+ }
663
+ return;
664
+ }
665
+ if (isWeakMap(reactiveObj) || isWeakSet(reactiveObj)) {
666
+ {
667
+ warn("clearReactive: WeakMap and WeakSet are not clearable");
668
+ }
669
+ return;
670
+ }
671
+ useBatch(() => {
672
+ if (isArray(reactiveObj)) {
673
+ reactiveObj.length = 0;
674
+ } else if (isSet(reactiveObj) || isMap(reactiveObj)) {
675
+ reactiveObj.clear();
676
+ } else if (isObject(reactiveObj)) {
677
+ Object.keys(reactiveObj).forEach((key) => {
678
+ delete reactiveObj[key];
679
+ });
680
+ }
681
+ });
374
682
  }
375
- function fe(e) {
683
+ function useBatch(fn) {
376
684
  try {
377
- D = true, e();
685
+ inBatch = true;
686
+ fn();
378
687
  } finally {
379
- D = false, Fe();
380
- }
381
- }
382
- function Fe() {
383
- P.size > 0 && (P.forEach((e) => e()), P.clear());
384
- }
385
- function Ve(e, t, n) {
386
- return ze(e, t, n);
387
- }
388
- var pe = void 0;
389
- var k;
390
- var N = false;
391
- function qe(e) {
392
- k = e, N || (N = true, E(Je));
393
- }
394
- function Je() {
395
- k == null || k(), k = null, N = false;
396
- }
397
- function ze(e, t, { deep: n, immediate: o } = {}) {
398
- let r, s = isArray(e);
399
- if (h(e) || I(e)) r = () => e.value;
400
- else if (b(e)) r = () => y({}, e);
401
- else if (s) r = () => e.map((a) => Be(a));
402
- else if (isFunction(e)) r = e;
403
- else return warn("Invalid source type", e), noop;
404
- if (t && n) {
405
- let a = r, l = n === true ? 1 / 0 : n;
406
- r = () => R(a(), l);
407
- }
408
- let i = s ? Array.from({ length: e.length }).fill(pe) : pe, d = false, O = () => {
409
- let a = r();
410
- hasChanged(a, i) && (o && t && (t(a, i), i = a), d && t && qe(() => {
411
- t(a, i), i = a;
412
- }), !d && (i = a));
413
- }, g = B(O, { flush: "sync" });
414
- return d = true, o && O(), g;
415
- }
416
- function Be(e) {
417
- return h(e) || I(e) ? e.value : b(e) ? y({}, e) : isFunction(e) ? e() : (warn("Invalid source", e), noop);
418
- }
419
- function R(e, t = 1 / 0, n) {
420
- if (t <= 0 || !isObject(e) || (n = n || /* @__PURE__ */ new Set(), n.has(e))) return e;
421
- if (n.add(e), t--, h(e)) R(e.value, t, n);
422
- else if (isArray(e)) for (let o of e) R(o, t, n);
423
- else if (isSet(e) || isMap(e)) e.forEach((o) => {
424
- R(o, t, n);
425
- });
426
- else if (isPlainObject(e)) for (let o in e) R(e[o], t, n);
427
- return e;
428
- }
429
- function Le(e) {
430
- let { state: t, getters: n, actions: o } = e, r = y({}, t != null ? t : {}), s = L(t != null ? t : {}), i = [], d = [], g = y({ state: s }, { patch$(a) {
431
- Object.assign(s, a), i.forEach((l) => l(s)), d.forEach((l) => l(s));
432
- }, subscribe$(a) {
433
- i.push(a);
434
- }, unsubscribe$(a) {
435
- let l = i.indexOf(a);
436
- l !== -1 && i.splice(l, 1);
437
- }, onAction$(a) {
438
- d.push(a);
439
- }, reset$() {
440
- Object.assign(s, r);
441
- } });
442
- for (let a in n) {
443
- let l = n[a];
444
- l && Object.defineProperty(g, a, { get() {
445
- return z(l.bind(s, s)).value;
446
- }, enumerable: true, configurable: true });
447
- }
448
- for (let a in o) {
449
- let l = o[a];
450
- l && (g[a] = l.bind(s));
451
- }
452
- return g;
453
- }
454
- function Ne(e) {
688
+ inBatch = false;
689
+ runBatch();
690
+ }
691
+ }
692
+ function runBatch() {
693
+ if (batchQueue.size > 0) {
694
+ batchQueue.forEach((effect) => effect());
695
+ batchQueue.clear();
696
+ }
697
+ }
698
+ function useWatch(source, cb, options) {
699
+ return doWatch(source, cb, options);
700
+ }
701
+ var INITIAL_WATCHER_VALUE = void 0;
702
+ var watcher;
703
+ var flushing = false;
704
+ function queueWatcher(fn) {
705
+ watcher = fn;
706
+ if (!flushing) {
707
+ flushing = true;
708
+ nextTick(flushWatchers);
709
+ }
710
+ }
711
+ function flushWatchers() {
712
+ watcher == null ? void 0 : watcher();
713
+ watcher = null;
714
+ flushing = false;
715
+ }
716
+ function doWatch(source, cb, { deep, immediate } = {}) {
717
+ let getter;
718
+ const isMultiSource = isArray(source);
719
+ if (isSignal(source) || isComputed(source)) {
720
+ getter = () => source.value;
721
+ } else if (isReactive(source)) {
722
+ getter = () => __spreadValues({}, source);
723
+ } else if (isMultiSource) {
724
+ getter = () => source.map((s) => resolveSource(s));
725
+ } else if (isFunction(source)) {
726
+ getter = source;
727
+ } else {
728
+ warn("Invalid source type", source);
729
+ return noop;
730
+ }
731
+ if (cb && deep) {
732
+ const baseGetter = getter;
733
+ const depth = deep === true ? Infinity : deep;
734
+ getter = () => traverse(baseGetter(), depth);
735
+ }
736
+ let oldValue = isMultiSource ? Array.from({ length: source.length }).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
737
+ let runCb = false;
738
+ const effectFn = () => {
739
+ const newValue = getter();
740
+ if (hasChanged(newValue, oldValue)) {
741
+ if (immediate && cb) {
742
+ cb(newValue, oldValue);
743
+ oldValue = newValue;
744
+ }
745
+ if (runCb && cb) {
746
+ queueWatcher(() => {
747
+ cb(newValue, oldValue);
748
+ oldValue = newValue;
749
+ });
750
+ }
751
+ !runCb && (oldValue = newValue);
752
+ }
753
+ };
754
+ const stop = useEffect(effectFn, { flush: "sync" });
755
+ runCb = true;
756
+ if (immediate) {
757
+ effectFn();
758
+ }
759
+ return stop;
760
+ }
761
+ function resolveSource(s) {
762
+ if (isSignal(s) || isComputed(s)) return s.value;
763
+ if (isReactive(s)) return __spreadValues({}, s);
764
+ if (isFunction(s)) return s();
765
+ warn("Invalid source", s);
766
+ return noop;
767
+ }
768
+ function traverse(value, depth = Infinity, seen) {
769
+ if (depth <= 0 || !isObject(value)) {
770
+ return value;
771
+ }
772
+ seen = seen || /* @__PURE__ */ new Set();
773
+ if (seen.has(value)) {
774
+ return value;
775
+ }
776
+ seen.add(value);
777
+ depth--;
778
+ if (isSignal(value)) {
779
+ traverse(value.value, depth, seen);
780
+ } else if (isArray(value)) {
781
+ for (const element of value) {
782
+ traverse(element, depth, seen);
783
+ }
784
+ } else if (isSet(value) || isMap(value)) {
785
+ value.forEach((v) => {
786
+ traverse(v, depth, seen);
787
+ });
788
+ } else if (isPlainObject(value)) {
789
+ for (const key in value) {
790
+ traverse(value[key], depth, seen);
791
+ }
792
+ }
793
+ return value;
794
+ }
795
+ function createOptionsStore(options) {
796
+ const { state, getters, actions } = options;
797
+ const initState = __spreadValues({}, state);
798
+ const reactiveState = useReactive(state);
799
+ const subscriptions = [];
800
+ const actionCallbacks = [];
801
+ const default_actions = {
802
+ patch$(payload) {
803
+ Object.assign(reactiveState, payload);
804
+ subscriptions.forEach((callback) => callback(reactiveState));
805
+ actionCallbacks.forEach((callback) => callback(reactiveState));
806
+ },
807
+ subscribe$(callback) {
808
+ subscriptions.push(callback);
809
+ },
810
+ unsubscribe$(callback) {
811
+ const index = subscriptions.indexOf(callback);
812
+ if (index !== -1) {
813
+ subscriptions.splice(index, 1);
814
+ }
815
+ },
816
+ onAction$(callback) {
817
+ actionCallbacks.push(callback);
818
+ },
819
+ reset$() {
820
+ Object.assign(reactiveState, initState);
821
+ }
822
+ };
823
+ const store = __spreadValues(__spreadProps(__spreadValues({}, reactiveState), {
824
+ state: reactiveState
825
+ }), default_actions);
826
+ if (getters) {
827
+ for (const key in getters) {
828
+ const getter = getters[key];
829
+ if (getter) {
830
+ Object.defineProperty(store, key, {
831
+ get() {
832
+ return useComputed(() => getter.call(store, reactiveState)).value;
833
+ },
834
+ enumerable: true,
835
+ configurable: true
836
+ });
837
+ }
838
+ }
839
+ }
840
+ if (actions) {
841
+ for (const key in actions) {
842
+ const action = actions[key];
843
+ if (action) {
844
+ store[key] = function(...args) {
845
+ const result = action.apply(reactiveState, args);
846
+ actionCallbacks.forEach((callback) => callback(reactiveState));
847
+ return result;
848
+ };
849
+ }
850
+ }
851
+ }
852
+ return store;
853
+ }
854
+ function createStore(storeDefinition) {
455
855
  return function() {
456
- return Le(e);
856
+ let options;
857
+ if (typeof storeDefinition === "function") {
858
+ options = createClassStore(storeDefinition);
859
+ } else {
860
+ options = storeDefinition;
861
+ }
862
+ const store = createOptionsStore(options);
863
+ if (typeof storeDefinition === "function") {
864
+ Object.keys(options.actions || {}).forEach((key) => {
865
+ store[key] = options.actions[key].bind(store);
866
+ });
867
+ }
868
+ return store;
869
+ };
870
+ }
871
+ function createClassStore(StoreClass) {
872
+ const instance = new StoreClass();
873
+ const state = /* @__PURE__ */ Object.create(null);
874
+ const getters = {};
875
+ const actions = {};
876
+ Object.getOwnPropertyNames(instance).forEach((key) => {
877
+ state[key] = instance[key];
878
+ });
879
+ Object.getOwnPropertyNames(StoreClass.prototype).forEach((key) => {
880
+ const descriptor = Object.getOwnPropertyDescriptor(StoreClass.prototype, key);
881
+ if (descriptor) {
882
+ if (typeof descriptor.get === "function") {
883
+ getters[key] = function() {
884
+ return descriptor.get.call(this);
885
+ };
886
+ } else if (typeof descriptor.value === "function" && key !== "constructor") {
887
+ actions[key] = function(...args) {
888
+ return descriptor.value.apply(this, args);
889
+ };
890
+ }
891
+ }
892
+ });
893
+ return {
894
+ state,
895
+ getters,
896
+ actions
457
897
  };
458
898
  }
459
899
 
460
900
  // ../template/dist/template.dev.esm.js
461
- var componentMap = /* @__PURE__ */ new Map();
901
+ var EVENT_PREFIX = "on";
902
+ var UPDATE_PREFIX = "update";
903
+ var CHILDREN_PROP = "children";
904
+ var EMPTY_TEMPLATE = "";
905
+ var FRAGMENT_PROP_KEY = "0";
906
+ var SINGLE_PROP_KEY = "1";
907
+ var PLACEHOLDER = " __PLACEHOLDER__ ";
462
908
  var RenderContext = class {
463
909
  constructor() {
464
910
  this.renderMode = 0;
465
911
  }
912
+ // Getter to check if the current mode is SSG
466
913
  get isSSG() {
467
914
  return this.renderMode === 1;
468
915
  }
916
+ // Getter to check if the current mode is SSR
469
917
  get isSSR() {
470
918
  return this.renderMode === 2;
471
919
  }
920
+ // Getter to check if the current mode is Client
472
921
  get isClient() {
473
922
  return this.renderMode === 0;
474
923
  }
924
+ // Set render mode to SSR
475
925
  setSSR() {
476
926
  this.renderMode = 2;
477
927
  }
928
+ // Set render mode to SSG
478
929
  setSSG() {
479
930
  this.renderMode = 1;
480
931
  }
932
+ // Set render mode to Client
481
933
  setClient() {
482
934
  this.renderMode = 0;
483
935
  }
484
936
  };
485
937
  var renderContext = new RenderContext();
938
+ var componentMap = /* @__PURE__ */ new Map();
486
939
  function enterComponent(temp, index) {
487
940
  componentMap.set(temp, {
488
941
  index
489
942
  });
490
943
  }
491
944
  function getComponentIndex(temp) {
492
- return componentMap.get(temp).index;
945
+ var _a;
946
+ return (_a = componentMap.get(temp)) == null ? void 0 : _a.index;
493
947
  }
494
948
  var _LifecycleContext = class _LifecycleContext2 {
495
949
  constructor() {
@@ -502,22 +956,28 @@ var _LifecycleContext = class _LifecycleContext2 {
502
956
  }
503
957
  removeEventListener() {
504
958
  }
959
+ // Add a hook for a specific lifecycle stage
505
960
  addHook(hook, cb) {
506
961
  var _a;
507
962
  (_a = this.hooks[hook]) == null ? void 0 : _a.add(cb);
508
963
  }
964
+ // Get a value from the static context
509
965
  getContext(context) {
510
966
  return _LifecycleContext2.context[context];
511
967
  }
968
+ // Set a value in the static context
512
969
  setContext(context, value) {
513
970
  _LifecycleContext2.context[context] = value;
514
971
  }
972
+ // Initialize the static reference
515
973
  initRef() {
516
974
  _LifecycleContext2.ref = this;
517
975
  }
976
+ // Remove the static reference
518
977
  removeRef() {
519
978
  _LifecycleContext2.ref = null;
520
979
  }
980
+ // Clear all hooks
521
981
  clearHooks() {
522
982
  Object.values(this.hooks).forEach((set) => set.clear());
523
983
  }
@@ -536,29 +996,39 @@ var SSGNode = class extends LifecycleContext {
536
996
  this.props = props;
537
997
  this.key = key;
538
998
  enterComponent(template, componentIndex);
999
+ this.templates = this.processTemplate();
1000
+ }
1001
+ // Process the template and return an array of processed strings
1002
+ processTemplate() {
539
1003
  if (isArray(this.template)) {
540
- const PLACEHOLDER = " __PLACEHOLDER__ ";
541
1004
  const htmlString = this.template.join(PLACEHOLDER);
542
- const processedString = htmlString.replaceAll(/(<[^>]+>)|([^<]+)/g, (match, p1, p2) => {
543
- if (p1) {
544
- if (p1.includes("data-ci")) return match;
545
- return p1.replace(/<\s*([\da-z]+)(\s[^>]*)?>/i, (_2, tagName, attrs) => {
546
- return `<${tagName} data-ci="${componentIndex}"${attrs || ""}>`;
547
- });
548
- } else if (p2 && p2.replace(PLACEHOLDER, "").trim()) {
549
- return `<!--${0}-${componentIndex}-->${p2}<!$>`;
550
- }
551
- return match;
552
- });
553
- this.template = processedString.split(PLACEHOLDER);
1005
+ const processedString = this.processHtmlString(htmlString);
1006
+ return processedString.split(PLACEHOLDER);
554
1007
  }
1008
+ return [];
1009
+ }
1010
+ // Process HTML string by adding component index and handling text nodes
1011
+ processHtmlString(htmlString) {
1012
+ return htmlString.replaceAll(/(<[^>]+>)|([^<]+)/g, (match, p1, p2) => {
1013
+ if (p1) {
1014
+ if (p1.includes("data-ci")) return match;
1015
+ return p1.replace(/<\s*([\da-z]+)(\s[^>]*)?>/i, (_, tagName, attrs) => {
1016
+ return `<${tagName} data-ci="${componentIndex}"${attrs || ""}>`;
1017
+ });
1018
+ } else if (p2 && p2.replace(PLACEHOLDER, "").trim()) {
1019
+ return `<!--${0}-${componentIndex}-->${p2}<!$>`;
1020
+ }
1021
+ return match;
1022
+ });
555
1023
  }
1024
+ // Mount the SSGNode and return the rendered string
556
1025
  mount() {
557
1026
  this.initRef();
558
1027
  const output = this.render();
559
1028
  this.removeRef();
560
1029
  return output;
561
1030
  }
1031
+ // Render the SSGNode
562
1032
  render() {
563
1033
  if (isFunction(this.template)) {
564
1034
  const root = this.template(this.props);
@@ -568,55 +1038,64 @@ var SSGNode = class extends LifecycleContext {
568
1038
  return String(root);
569
1039
  }
570
1040
  }
571
- const template = this.template;
572
- Object.keys(this.props).forEach((key) => {
573
- const cur = this.props[key];
574
- const childrens = cur.children;
575
- normalizeProp(cur);
576
- const findIndex = template.findIndex((t) => t.includes(`data-hk="${key}"`));
577
- if (childrens) {
578
- childrens.forEach(([child]) => {
579
- componentIndex++;
580
- const children = renderChildren(child, cur);
581
- this.template[findIndex] += children;
582
- });
1041
+ return this.renderTemplate();
1042
+ }
1043
+ // Render the template by processing props and children
1044
+ renderTemplate() {
1045
+ Object.entries(this.props).forEach(([key, cur]) => {
1046
+ const children = cur.children;
1047
+ this.normalizeProps(cur);
1048
+ const findIndex = this.templates.findIndex((t) => t.includes(`data-hk="${key}"`));
1049
+ if (children) {
1050
+ this.renderChildren(children, findIndex);
583
1051
  }
584
- this.template[findIndex].replaceAll(
1052
+ this.templates[findIndex] = this.templates[findIndex].replace(
585
1053
  `data-hk="${key}"`,
586
- `data-hk="${key}" ${generateAttributes(cur)}`
1054
+ `data-hk="${key}" ${this.generateAttributes(cur)}`
587
1055
  );
588
1056
  });
589
- return template.join("");
1057
+ return this.templates.join("");
590
1058
  }
591
- };
592
- function normalizeProp(props) {
593
- Object.entries(props).forEach(([key, value]) => {
594
- if (key === "children") {
595
- delete props[key];
596
- } else if (isFunction(value)) {
597
- delete props[key];
598
- } else if (h(value)) {
599
- props[key] = value.value;
1059
+ // Normalize props by removing children and handling signals
1060
+ normalizeProps(props) {
1061
+ Object.entries(props).forEach(([key, value]) => {
1062
+ if (key === "children") {
1063
+ delete props[key];
1064
+ } else if (isFunction(value)) {
1065
+ delete props[key];
1066
+ } else if (isSignal(value)) {
1067
+ props[key] = value.value;
1068
+ }
1069
+ });
1070
+ }
1071
+ // Generate HTML attributes string from props
1072
+ generateAttributes(props) {
1073
+ return Object.entries(props).filter(([key, value]) => key !== "children" && !isFunction(value)).map(([key, value]) => `${key}="${escape(String(value))}"`).join(" ");
1074
+ }
1075
+ // Render children and append them to the template
1076
+ renderChildren(children, findIndex) {
1077
+ children.forEach(([child]) => {
1078
+ componentIndex++;
1079
+ const renderedChild = this.renderChild(child);
1080
+ this.templates[findIndex] += renderedChild;
1081
+ });
1082
+ }
1083
+ // Render a single child node
1084
+ renderChild(child) {
1085
+ if (isFunction(child)) {
1086
+ return this.renderChild(child(this.props));
1087
+ } else if (isSignal(child)) {
1088
+ return `<!--${1}-${componentIndex}-->${child.value}<!$>`;
1089
+ } else if (isSSGNode(child)) {
1090
+ const childResult = child.mount();
1091
+ return isFunction(childResult) ? childResult(this.props) : extractSignal(childResult);
1092
+ } else {
1093
+ return `<!--${1}-${componentIndex}-->${child}<!$>`;
600
1094
  }
601
- });
602
- }
603
- function generateAttributes(props) {
604
- return Object.entries(props).filter(([key, value]) => key !== "children" && !isFunction(value)).map(([key, value]) => `${key}="${escape(String(value))}"`).join(" ");
605
- }
606
- function renderChildren(children, prop) {
607
- if (isFunction(children)) {
608
- return renderChildren(children(prop), prop);
609
- } else if (h(children)) {
610
- return `<!--${1}-${componentIndex}-->${children.value}<!$>`;
611
- } else if (isSSGNode(children)) {
612
- const childResult = children.mount();
613
- return isFunction(childResult) ? childResult(prop) : extractSignal(childResult);
614
- } else {
615
- return `<!--${1}-${componentIndex}-->${children}<!$>`;
616
1095
  }
617
- }
618
- var selfClosingTags = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr".split(",");
619
- var htmlTags = "a,abbr,acronym,address,applet,area,article,aside,audio,b,base,basefont,bdi,bdo,bgsound,big,blink,blockquote,body,br,button,canvas,caption,center,cite,code,col,colgroup,command,content,data,datalist,dd,del,details,dfn,dialog,dir,div,dl,dt,em,embed,fieldset,figcaption,figure,font,footer,form,frame,frameset,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,image,img,input,ins,kbd,keygen,label,legend,li,link,listing,main,map,mark,marquee,menu,menuitem,meta,meter,nav,nobr,noframes,noscript,object,ol,optgroup,option,output,p,param,picture,plaintext,pre,progress,q,rb,rp,rt,rtc,ruby,s,samp,script,section,select,shadow,small,source,spacer,span,strike,strong,style,sub,summary,sup,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,tt,u,ul,var,video,wbr,xmp".split(
1096
+ };
1097
+ var SELF_CLOSING_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr".split(",");
1098
+ var HTML_TAGS = "a,abbr,acronym,address,applet,area,article,aside,audio,b,base,basefont,bdi,bdo,bgsound,big,blink,blockquote,body,br,button,canvas,caption,center,cite,code,col,colgroup,command,content,data,datalist,dd,del,details,dfn,dialog,dir,div,dl,dt,em,embed,fieldset,figcaption,figure,font,footer,form,frame,frameset,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,image,img,input,ins,kbd,keygen,label,legend,li,link,listing,main,map,mark,marquee,menu,menuitem,meta,meter,nav,nobr,noframes,noscript,object,ol,optgroup,option,output,p,param,picture,plaintext,pre,progress,q,rb,rp,rt,rtc,ruby,s,samp,script,section,select,shadow,small,source,spacer,span,strike,strong,style,sub,summary,sup,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,tt,u,ul,var,video,wbr,xmp".split(
620
1099
  ","
621
1100
  );
622
1101
  function coerceNode(data) {
@@ -653,26 +1132,33 @@ function replaceChild(parent, node, child) {
653
1132
  }
654
1133
  function setAttribute(element, attr, value) {
655
1134
  if (attr === "class") {
656
- if (typeof value === "string") {
657
- element.className = value;
658
- } else if (isArray(value)) {
659
- element.className = value.join(" ");
660
- } else if (value && typeof value === "object") {
661
- element.className = Object.entries(value).reduce((acc, [key, value2]) => acc + (value2 ? ` ${key}` : ""), "").trim();
662
- }
663
- return;
1135
+ setClassAttribute(element, value);
1136
+ } else if (attr === "style") {
1137
+ setStyleAttribute(element, value);
1138
+ } else {
1139
+ setGenericAttribute(element, attr, value);
664
1140
  }
665
- if (attr === "style") {
666
- if (typeof value === "string") {
667
- element.style.cssText = value;
668
- } else if (value && typeof value === "object") {
669
- const obj = value;
670
- Object.keys(obj).forEach((key) => {
671
- element.style.setProperty(kebabCase(key), String(obj[key]));
672
- });
673
- }
674
- return;
1141
+ }
1142
+ function setClassAttribute(element, value) {
1143
+ if (typeof value === "string") {
1144
+ element.className = value;
1145
+ } else if (isArray(value)) {
1146
+ element.className = value.join(" ");
1147
+ } else if (value && typeof value === "object") {
1148
+ element.className = Object.entries(value).reduce((acc, [key, value2]) => acc + (value2 ? ` ${key}` : ""), "").trim();
1149
+ }
1150
+ }
1151
+ function setStyleAttribute(element, value) {
1152
+ if (typeof value === "string") {
1153
+ element.style.cssText = value;
1154
+ } else if (value && typeof value === "object") {
1155
+ const obj = value;
1156
+ Object.entries(obj).forEach(([key, value2]) => {
1157
+ element.style.setProperty(kebabCase(key), String(value2));
1158
+ });
675
1159
  }
1160
+ }
1161
+ function setGenericAttribute(element, attr, value) {
676
1162
  if (isFalsy(value)) {
677
1163
  element.removeAttribute(attr);
678
1164
  } else if (value === true) {
@@ -755,7 +1241,7 @@ function closeHtmlTags(input) {
755
1241
  if (tagStack.length > 0) {
756
1242
  tagStack.pop();
757
1243
  }
758
- } else if (!selfClosingTags.includes(tagName)) {
1244
+ } else if (!SELF_CLOSING_TAGS.includes(tagName)) {
759
1245
  tagStack.push(tagName);
760
1246
  }
761
1247
  output.push(fullMatch);
@@ -770,17 +1256,13 @@ function closeHtmlTags(input) {
770
1256
  return output.join("");
771
1257
  }
772
1258
  function isHtmlTagName(tagName) {
773
- return htmlTags.includes(tagName);
1259
+ return HTML_TAGS.includes(tagName);
774
1260
  }
775
1261
  function convertToHtmlTag(tagName) {
776
- if (selfClosingTags.includes(tagName)) {
777
- return `<${tagName}/>`;
778
- } else {
779
- return `<${tagName}></${tagName}>`;
780
- }
1262
+ return SELF_CLOSING_TAGS.includes(tagName) ? `<${tagName}/>` : `<${tagName}></${tagName}>`;
781
1263
  }
782
1264
  function extractSignal(signal) {
783
- if (h(signal)) {
1265
+ if (isSignal(signal)) {
784
1266
  return signal.value;
785
1267
  } else {
786
1268
  return signal;
@@ -795,19 +1277,28 @@ var ComponentNode = class extends LifecycleContext {
795
1277
  this.emitter = /* @__PURE__ */ new Set();
796
1278
  this.rootNode = null;
797
1279
  this.trackMap = /* @__PURE__ */ new Map();
798
- this.proxyProps = props ? L(
1280
+ this.key || (this.key = props == null ? void 0 : props.key);
1281
+ this.proxyProps = this.createProxyProps(props);
1282
+ }
1283
+ // Create reactive props
1284
+ createProxyProps(props) {
1285
+ if (!props) return {};
1286
+ return useReactive(
799
1287
  props,
800
- (key2) => startsWith(key2, "on") || startsWith(key2, "update") || key2 === "children"
801
- ) : {};
1288
+ (key) => startsWith(key, EVENT_PREFIX) || startsWith(key, UPDATE_PREFIX) || key === CHILDREN_PROP
1289
+ );
802
1290
  }
1291
+ // Getter for the first child node
803
1292
  get firstChild() {
804
1293
  var _a, _b;
805
1294
  return (_b = (_a = this.rootNode) == null ? void 0 : _a.firstChild) != null ? _b : null;
806
1295
  }
1296
+ // Getter to check if the node is connected to the DOM
807
1297
  get isConnected() {
808
1298
  var _a, _b;
809
1299
  return (_b = (_a = this.rootNode) == null ? void 0 : _a.isConnected) != null ? _b : false;
810
1300
  }
1301
+ // Method to mount the component to the DOM
811
1302
  mount(parent, before) {
812
1303
  var _a, _b, _c, _d;
813
1304
  if (!isFunction(this.template)) {
@@ -819,32 +1310,37 @@ var ComponentNode = class extends LifecycleContext {
819
1310
  this.initRef();
820
1311
  this.rootNode = this.template(this.proxyProps);
821
1312
  const mountedNode = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
822
- this.hooks.mounted.forEach((handler) => handler());
1313
+ this.callMountHooks();
823
1314
  this.patchProps(this.props);
824
1315
  this.removeRef();
825
1316
  return mountedNode;
826
1317
  }
1318
+ // Method to unmount the component from the DOM
827
1319
  unmount() {
828
1320
  var _a;
829
- this.hooks.destroy.forEach((handler) => handler());
1321
+ this.callDestroyHooks();
830
1322
  this.clearHooks();
831
1323
  (_a = this.rootNode) == null ? void 0 : _a.unmount();
832
1324
  this.rootNode = null;
833
1325
  this.proxyProps = {};
1326
+ this.clearEmitter();
1327
+ }
1328
+ // Private method to call mount hooks
1329
+ callMountHooks() {
1330
+ this.hooks.mounted.forEach((handler) => handler());
1331
+ }
1332
+ // Private method to call destroy hooks
1333
+ callDestroyHooks() {
1334
+ this.hooks.destroy.forEach((handler) => handler());
1335
+ }
1336
+ // Private method to clear the event emitter
1337
+ clearEmitter() {
834
1338
  for (const cleanup of this.emitter) {
835
1339
  cleanup();
836
1340
  }
837
1341
  this.emitter.clear();
838
1342
  }
839
- /**
840
- * Inherit props and state from another ComponentNode.
841
- * It will:
842
- * 1. Copy props from the node to this proxyProps.
843
- * 2. Copy the rootNode, trackMap and hooks from the node.
844
- * 3. Copy the props from the node to this.
845
- * 4. Patch props from the props passed in the constructor.
846
- * @param node The node to inherit from.
847
- */
1343
+ // Method to inherit properties from another ComponentNode
848
1344
  inheritNode(node) {
849
1345
  Object.assign(this.proxyProps, node.proxyProps);
850
1346
  this.rootNode = node.rootNode;
@@ -854,55 +1350,58 @@ var ComponentNode = class extends LifecycleContext {
854
1350
  this.props = node.props;
855
1351
  this.patchProps(props);
856
1352
  }
857
- /**
858
- * Get a NodeTrack from the trackMap. If the track is not in the trackMap, create a new one.
859
- * Then, call the cleanup function to remove any previously registered hooks.
860
- * @param trackKey the key of the node track to get.
861
- * @returns the NodeTrack, cleaned up and ready to use.
862
- */
1353
+ // Private method to get or create a NodeTrack
863
1354
  getNodeTrack(trackKey) {
864
- let track = this.trackMap.get(trackKey);
865
- if (!track) {
866
- track = { cleanup: () => {
1355
+ let track2 = this.trackMap.get(trackKey);
1356
+ if (!track2) {
1357
+ track2 = { cleanup: () => {
867
1358
  } };
868
- this.trackMap.set(trackKey, track);
1359
+ this.trackMap.set(trackKey, track2);
869
1360
  }
870
- track.cleanup();
871
- return track;
1361
+ track2.cleanup();
1362
+ return track2;
872
1363
  }
873
- /**
874
- * Patch the props of this node.
875
- * It will:
876
- * 1. Iterate the props and patch it.
877
- * 2. If the prop is a event handler, add a event listener to the first child of the node.
878
- * 3. If the prop is a ref, set the first child of the node to the ref.
879
- * 4. If the prop is a update handler, update the prop in the node's props.
880
- * 5. If the prop is a normal prop, create a signal for it and then patch it.
881
- * @param props The props to patch.
882
- */
1364
+ // Method to patch props onto the component
883
1365
  patchProps(props) {
884
- var _a, _b;
1366
+ var _a;
885
1367
  if (!props) {
886
1368
  return;
887
1369
  }
888
1370
  for (const [key, prop] of Object.entries(props)) {
889
- if (startsWith(key, "on") && ((_a = this.rootNode) == null ? void 0 : _a.firstChild)) {
890
- const event = key.slice(2).toLowerCase();
891
- const cleanup = addEventListener(this.rootNode.nodes[0], event, prop);
892
- this.emitter.add(cleanup);
1371
+ if (startsWith(key, EVENT_PREFIX) && ((_a = this.rootNode) == null ? void 0 : _a.firstChild)) {
1372
+ this.patchEventListener(key, prop);
893
1373
  } else if (key === "ref") {
894
- prop.value = (_b = this.rootNode) == null ? void 0 : _b.firstChild;
895
- } else if (startsWith(key, "update")) {
896
- this.props[key] = extractSignal(prop);
897
- } else if (key !== "children") {
898
- const track = this.getNodeTrack(key);
899
- track.cleanup = B(() => {
900
- this.proxyProps[key] = isFunction(prop) ? prop() : prop;
901
- });
1374
+ this.patchRef(prop);
1375
+ } else if (startsWith(key, UPDATE_PREFIX)) {
1376
+ this.patchUpdateHandler(key, prop);
1377
+ } else if (key !== CHILDREN_PROP) {
1378
+ this.patchNormalProp(key, prop);
902
1379
  }
903
1380
  }
904
1381
  this.props = props;
905
1382
  }
1383
+ // Private method to patch event listeners
1384
+ patchEventListener(key, prop) {
1385
+ const event = key.slice(2).toLowerCase();
1386
+ const cleanup = addEventListener(this.rootNode.nodes[0], event, prop);
1387
+ this.emitter.add(cleanup);
1388
+ }
1389
+ // Private method to patch ref
1390
+ patchRef(prop) {
1391
+ var _a, _b;
1392
+ prop.value = (_b = (_a = this.rootNode) == null ? void 0 : _a.firstChild) != null ? _b : null;
1393
+ }
1394
+ // Private method to patch update handlers
1395
+ patchUpdateHandler(key, prop) {
1396
+ this.props[key] = extractSignal(prop);
1397
+ }
1398
+ // Private method to patch normal props
1399
+ patchNormalProp(key, prop) {
1400
+ const track2 = this.getNodeTrack(key);
1401
+ track2.cleanup = useEffect(() => {
1402
+ this.proxyProps[key] = isFunction(prop) ? prop() : prop;
1403
+ });
1404
+ }
906
1405
  };
907
1406
  function patchChildren(parent, childrenMap, nextChildren, before) {
908
1407
  const result = /* @__PURE__ */ new Map();
@@ -1025,18 +1524,21 @@ var TemplateNode = class {
1025
1524
  this.componentIndex = getComponentIndex(this.template);
1026
1525
  }
1027
1526
  }
1028
- addEventListener() {
1029
- }
1030
- removeEventListener() {
1031
- }
1527
+ // Getter for the first child node
1032
1528
  get firstChild() {
1033
1529
  var _a;
1034
1530
  return (_a = this.nodes[0]) != null ? _a : null;
1035
1531
  }
1036
- // is mounted
1532
+ // Getter to check if the node is connected to the DOM
1037
1533
  get isConnected() {
1038
1534
  return this.mounted;
1039
1535
  }
1536
+ // Placeholder methods for event handling
1537
+ addEventListener() {
1538
+ }
1539
+ removeEventListener() {
1540
+ }
1541
+ // Method to mount the node to the DOM
1040
1542
  mount(parent, before) {
1041
1543
  var _a;
1042
1544
  this.parent = parent;
@@ -1066,44 +1568,45 @@ var TemplateNode = class {
1066
1568
  this.mounted = true;
1067
1569
  return this.nodes;
1068
1570
  }
1571
+ // Method to unmount the node from the DOM
1069
1572
  unmount() {
1070
1573
  var _a, _b;
1071
- this.trackMap.forEach((track) => {
1574
+ this.trackMap.forEach((track2) => {
1072
1575
  var _a2;
1073
- (_a2 = track.cleanup) == null ? void 0 : _a2.call(track);
1576
+ (_a2 = track2.cleanup) == null ? void 0 : _a2.call(track2);
1074
1577
  });
1075
1578
  this.trackMap.clear();
1076
1579
  this.treeMap.clear();
1077
1580
  this.nodes.forEach((node) => removeChild(node));
1078
1581
  if (!this.template.innerHTML && !this.nodes.length) {
1079
- ((_b = (_a = this.props) == null ? void 0 : _a[0]) == null ? void 0 : _b.children) && this.props[0].children.forEach((i) => {
1080
- var _a2;
1081
- if (isPrimitive(i)) {
1082
- (_a2 = this.parent) == null ? void 0 : _a2.childNodes.forEach((node) => {
1083
- var _a3;
1084
- if (node.nodeType === Node.TEXT_NODE && node.textContent === `${i}`) {
1085
- (_a3 = this.parent) == null ? void 0 : _a3.removeChild(node);
1086
- }
1582
+ const children = (_b = (_a = this.props) == null ? void 0 : _a[FRAGMENT_PROP_KEY]) == null ? void 0 : _b.children;
1583
+ if (children) {
1584
+ if (isArray(children)) {
1585
+ children.forEach((child) => {
1586
+ this.deleteFragmentTextNode(child);
1087
1587
  });
1088
1588
  } else {
1089
- removeChild(i);
1589
+ this.deleteFragmentTextNode(children);
1090
1590
  }
1091
- });
1591
+ }
1092
1592
  }
1093
1593
  this.nodes = [];
1094
1594
  this.mounted = false;
1095
1595
  }
1096
- patchProps(props) {
1097
- if (!props) return;
1098
- Object.entries(props).forEach(([key, value]) => {
1099
- const index = Number(key);
1100
- const node = this.treeMap.get(index);
1101
- if (node) {
1102
- this.patchProp(key, node, value, index === 0);
1103
- }
1104
- });
1105
- this.props = props;
1596
+ deleteFragmentTextNode(child) {
1597
+ var _a;
1598
+ if (isPrimitive(child)) {
1599
+ (_a = this.parent) == null ? void 0 : _a.childNodes.forEach((node) => {
1600
+ var _a2;
1601
+ if (node.nodeType === Node.TEXT_NODE && node.textContent === `${child}`) {
1602
+ (_a2 = this.parent) == null ? void 0 : _a2.removeChild(node);
1603
+ }
1604
+ });
1605
+ } else {
1606
+ removeChild(child);
1607
+ }
1106
1608
  }
1609
+ // Method to inherit properties from another TemplateNode
1107
1610
  inheritNode(node) {
1108
1611
  this.mounted = node.mounted;
1109
1612
  this.nodes = node.nodes;
@@ -1113,194 +1616,205 @@ var TemplateNode = class {
1113
1616
  this.props = node.props;
1114
1617
  this.patchProps(props);
1115
1618
  }
1619
+ // Private method to map SSG node tree
1116
1620
  mapSSGNodeTree(parent) {
1117
1621
  this.treeMap.set(0, parent);
1118
- const walk = (node) => {
1119
- var _a;
1120
- if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
1121
- if (node.nodeType === Node.COMMENT_NODE) {
1122
- const [type, index] = ((_a = node.textContent) == null ? void 0 : _a.split("-")) || "";
1123
- if (0 === +type && +index === this.componentIndex) {
1124
- const textNode = node.nextSibling;
1125
- this.treeMap.set(+index, textNode);
1126
- }
1127
- } else if (node.nodeType !== Node.TEXT_NODE) {
1128
- const { ci = "-1", hk } = (node == null ? void 0 : node.dataset) || {};
1129
- if (hk && +ci === this.componentIndex) {
1130
- this.treeMap.set(+hk, node);
1131
- }
1132
- }
1133
- }
1134
- let child = node.firstChild;
1135
- while (child) {
1136
- walk(child);
1137
- child = child.nextSibling;
1138
- }
1139
- };
1140
- walk(parent);
1622
+ this.walkNodeTree(parent, this.handleSSGNode.bind(this));
1141
1623
  }
1624
+ // Private method to map node tree
1142
1625
  mapNodeTree(parent, tree) {
1143
1626
  let index = 1;
1144
1627
  this.treeMap.set(0, parent);
1145
- const walk = (node) => {
1628
+ const handleNode = (node) => {
1146
1629
  if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
1147
1630
  this.treeMap.set(index++, node);
1148
1631
  }
1149
- let child = node.firstChild;
1150
- while (child) {
1151
- walk(child);
1152
- child = child.nextSibling;
1153
- }
1154
1632
  };
1155
- walk(tree);
1633
+ this.walkNodeTree(tree, handleNode);
1156
1634
  }
1157
- /**
1158
- * Get a NodeTrack from the trackMap. If the track is not in the trackMap, create a new one.
1159
- * Then, call the cleanup function to remove any previously registered hooks.
1160
- * @param trackKey the key of the node track to get.
1161
- * @param trackLastNodes if true, the track will record the last nodes it has rendered.
1162
- * @param isRoot if true, the track will be treated as a root track.
1163
- * @returns the NodeTrack, cleaned up and ready to use.
1164
- */
1165
- getNodeTrack(trackKey, trackLastNodes, isRoot) {
1635
+ // Private method to walk through the node tree
1636
+ walkNodeTree(node, handler) {
1637
+ if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
1638
+ handler(node);
1639
+ }
1640
+ let child = node.firstChild;
1641
+ while (child) {
1642
+ this.walkNodeTree(child, handler);
1643
+ child = child.nextSibling;
1644
+ }
1645
+ }
1646
+ // Private method to handle SSG nodes
1647
+ handleSSGNode(node) {
1166
1648
  var _a;
1167
- let track = this.trackMap.get(trackKey);
1168
- if (!track) {
1169
- track = { cleanup: () => {
1170
- } };
1171
- if (trackLastNodes) {
1172
- track.lastNodes = /* @__PURE__ */ new Map();
1649
+ if (node.nodeType === Node.COMMENT_NODE) {
1650
+ const [type, index] = ((_a = node.textContent) == null ? void 0 : _a.split("-")) || [];
1651
+ if (0 === +type && +index === this.componentIndex) {
1652
+ const textNode = node.nextSibling;
1653
+ this.treeMap.set(+index, textNode);
1173
1654
  }
1174
- if (isRoot) {
1175
- track.isRoot = true;
1655
+ } else if (node.nodeType !== Node.TEXT_NODE) {
1656
+ const { ci = "-1", hk } = (node == null ? void 0 : node.dataset) || {};
1657
+ if (hk && +ci === this.componentIndex) {
1658
+ this.treeMap.set(+hk, node);
1176
1659
  }
1177
- this.trackMap.set(trackKey, track);
1178
1660
  }
1179
- (_a = track.cleanup) == null ? void 0 : _a.call(track);
1180
- return track;
1181
1661
  }
1662
+ // Method to patch props onto the node
1663
+ patchProps(props) {
1664
+ if (!props) return;
1665
+ Object.entries(props).forEach(([key, value]) => {
1666
+ const index = Number(key);
1667
+ const node = this.treeMap.get(index);
1668
+ if (node) {
1669
+ this.patchProp(key, node, value, index === 0);
1670
+ }
1671
+ });
1672
+ this.props = props;
1673
+ }
1674
+ // Private method to patch a single prop
1182
1675
  patchProp(key, node, props, isRoot) {
1183
- for (const attr in props) {
1184
- if (attr === "children" && props.children) {
1185
- if (!isArray(props.children)) {
1186
- const trackKey = `${key}:${attr}:${0}`;
1187
- const track = this.getNodeTrack(trackKey, true, isRoot);
1188
- patchChild(track, node, props.children, null);
1189
- } else {
1190
- props.children.filter(Boolean).forEach((item, index) => {
1191
- var _a;
1192
- const [child, path] = isArray(item) ? item : [item, null];
1193
- const before = isNil(path) ? null : (_a = this.treeMap.get(path)) != null ? _a : null;
1194
- const trackKey = `${key}:${attr}:${index}`;
1195
- const track = this.getNodeTrack(trackKey, true, isRoot);
1196
- patchChild(track, node, child, before);
1197
- });
1198
- }
1676
+ if (!props) return;
1677
+ Object.entries(props).forEach(([attr, value]) => {
1678
+ if (attr === CHILDREN_PROP && value) {
1679
+ this.patchChildren(key, node, value, isRoot);
1199
1680
  } else if (attr === "ref") {
1200
1681
  props[attr].value = node;
1201
1682
  } else if (startsWith(attr, "on")) {
1202
- const eventName = attr.slice(2).toLocaleLowerCase();
1203
- const track = this.getNodeTrack(`${key}:${attr}`);
1204
- const listener = props[attr];
1205
- track.cleanup = addEventListener(node, eventName, listener);
1683
+ this.patchEventListener(key, node, attr, value);
1206
1684
  } else {
1207
- const updateKey = `update${capitalizeFirstLetter(attr)}`;
1208
- if (this.bindValueKeys.includes(attr)) {
1209
- break;
1210
- }
1211
- if (props[updateKey]) {
1212
- this.bindValueKeys.push(updateKey);
1213
- }
1214
- const track = this.getNodeTrack(`${key}:${attr}`);
1215
- const val = props[attr];
1216
- const triggerValue = h(val) ? val : le(val);
1217
- patchAttribute(track, node, attr, triggerValue.value);
1218
- const cleanup = B(() => {
1219
- triggerValue.value = h(val) ? val.value : val;
1220
- patchAttribute(track, node, attr, triggerValue.value);
1221
- });
1222
- let cleanupBind;
1223
- if (props[updateKey] && !isComponent(attr)) {
1224
- cleanupBind = bindNode(node, (value) => {
1225
- props[updateKey](value);
1226
- });
1227
- }
1228
- track.cleanup = () => {
1229
- cleanup && cleanup();
1230
- cleanupBind && cleanupBind();
1231
- };
1685
+ this.patchAttribute(key, node, attr, value);
1232
1686
  }
1687
+ });
1688
+ }
1689
+ // Private method to patch children
1690
+ patchChildren(key, node, children, isRoot) {
1691
+ if (!isArray(children)) {
1692
+ const trackKey = `${key}:${CHILDREN_PROP}:0`;
1693
+ const track2 = this.getNodeTrack(trackKey, true, isRoot);
1694
+ this.patchChild(track2, node, children, null);
1695
+ } else {
1696
+ children.filter(Boolean).forEach((item, index) => {
1697
+ var _a;
1698
+ const [child, path] = isArray(item) ? item : [item, null];
1699
+ const before = isNil(path) ? null : (_a = this.treeMap.get(path)) != null ? _a : null;
1700
+ const trackKey = `${key}:${CHILDREN_PROP}:${index}`;
1701
+ const track2 = this.getNodeTrack(trackKey, true, isRoot);
1702
+ this.patchChild(track2, node, child, before);
1703
+ });
1233
1704
  }
1234
1705
  }
1235
- };
1236
- function patchChild(track, parent, child, before) {
1237
- if (isFunction(child)) {
1238
- track.cleanup = B(() => {
1239
- const nextNodes = coerceArray(child()).map(coerceNode);
1240
- if (renderContext.isSSR) {
1241
- track.lastNodes = reconcileChildren(parent, nextNodes, before);
1242
- } else {
1243
- track.lastNodes = patchChildren(parent, track.lastNodes, nextNodes, before);
1244
- }
1245
- });
1246
- } else {
1247
- coerceArray(child).forEach((node, index) => {
1248
- const newNode = coerceNode(node);
1249
- const key = getKey(newNode, index);
1250
- if (renderContext.isSSR) {
1251
- track.lastNodes = reconcileChildren(parent, [newNode], before);
1252
- } else {
1253
- track.lastNodes.set(key, newNode);
1254
- insertChild(parent, newNode, before);
1255
- }
1706
+ // Private method to patch event listeners
1707
+ patchEventListener(key, node, attr, listener) {
1708
+ const eventName = attr.slice(2).toLowerCase();
1709
+ const track2 = this.getNodeTrack(`${key}:${attr}`);
1710
+ track2.cleanup = addEventListener(node, eventName, listener);
1711
+ }
1712
+ // Private method to patch attributes
1713
+ patchAttribute(key, element, attr, value) {
1714
+ var _a, _b;
1715
+ const updateKey = `update${capitalizeFirstLetter(attr)}`;
1716
+ if (this.bindValueKeys.includes(attr)) {
1717
+ return;
1718
+ }
1719
+ if ((_a = this.props) == null ? void 0 : _a[updateKey]) {
1720
+ this.bindValueKeys.push(updateKey);
1721
+ }
1722
+ const track2 = this.getNodeTrack(`${key}:${attr}`);
1723
+ const triggerValue = isSignal(value) ? value : useSignal(value);
1724
+ setAttribute(element, attr, triggerValue.value);
1725
+ const cleanup = useEffect(() => {
1726
+ triggerValue.value = isSignal(value) ? value.value : value;
1727
+ setAttribute(element, attr, triggerValue.value);
1256
1728
  });
1729
+ let cleanupBind;
1730
+ if (((_b = this.props) == null ? void 0 : _b[updateKey]) && !isComponent(attr)) {
1731
+ cleanupBind = bindNode(element, (value2) => {
1732
+ var _a2;
1733
+ (_a2 = this.props) == null ? void 0 : _a2[updateKey](value2);
1734
+ });
1735
+ }
1736
+ track2.cleanup = () => {
1737
+ cleanup && cleanup();
1738
+ cleanupBind && cleanupBind();
1739
+ };
1257
1740
  }
1258
- }
1259
- function reconcileChildren(parent, nextNodes, before) {
1260
- const result = /* @__PURE__ */ new Map();
1261
- const textNodes = Array.from(parent.childNodes).filter(
1262
- (node) => {
1263
- var _a, _b;
1264
- return node.nodeType === Node.TEXT_NODE && ((_a = node.previousSibling) == null ? void 0 : _a.nodeType) === Node.COMMENT_NODE && ((_b = node.nextSibling) == null ? void 0 : _b.nodeType) === Node.COMMENT_NODE;
1265
- }
1266
- );
1267
- nextNodes.forEach((node, index) => {
1268
- const key = getKey(node, index);
1269
- if (node.nodeType === Node.TEXT_NODE) {
1270
- textNodes.forEach((ne2) => {
1271
- if (node.textContent === ne2.textContent) {
1272
- parent.replaceChild(node, ne2);
1741
+ // Private method to get or create a NodeTrack
1742
+ getNodeTrack(trackKey, trackLastNodes, isRoot) {
1743
+ var _a;
1744
+ let track2 = this.trackMap.get(trackKey);
1745
+ if (!track2) {
1746
+ track2 = { cleanup: () => {
1747
+ } };
1748
+ if (trackLastNodes) {
1749
+ track2.lastNodes = /* @__PURE__ */ new Map();
1750
+ }
1751
+ if (isRoot) {
1752
+ track2.isRoot = true;
1753
+ }
1754
+ this.trackMap.set(trackKey, track2);
1755
+ }
1756
+ (_a = track2.cleanup) == null ? void 0 : _a.call(track2);
1757
+ return track2;
1758
+ }
1759
+ // Private method to patch a child node
1760
+ patchChild(track2, parent, child, before) {
1761
+ if (isFunction(child)) {
1762
+ track2.cleanup = useEffect(() => {
1763
+ const nextNodes = coerceArray(child()).map(coerceNode);
1764
+ if (renderContext.isSSR) {
1765
+ track2.lastNodes = this.reconcileChildren(parent, nextNodes, before);
1766
+ } else {
1767
+ track2.lastNodes = patchChildren(parent, track2.lastNodes, nextNodes, before);
1273
1768
  }
1274
1769
  });
1275
1770
  } else {
1276
- insertChild(parent, node, before);
1771
+ coerceArray(child).forEach((node, index) => {
1772
+ const newNode = coerceNode(node);
1773
+ const key = getKey(newNode, index);
1774
+ if (renderContext.isSSR) {
1775
+ track2.lastNodes = this.reconcileChildren(parent, [newNode], before);
1776
+ } else {
1777
+ track2.lastNodes.set(key, newNode);
1778
+ insertChild(parent, newNode, before);
1779
+ }
1780
+ });
1277
1781
  }
1278
- result.set(key, node);
1279
- });
1280
- return result;
1281
- }
1282
- function patchAttribute(track, node, attr, data) {
1283
- const element = node;
1284
- if (!element.setAttribute) {
1285
- return;
1286
1782
  }
1287
- if (isFunction(data)) {
1288
- track.cleanup = B(() => {
1289
- setAttribute(element, attr, data());
1783
+ // Private method to reconcile children nodes
1784
+ reconcileChildren(parent, nextNodes, before) {
1785
+ const result = /* @__PURE__ */ new Map();
1786
+ const textNodes = Array.from(parent.childNodes).filter(
1787
+ (node) => {
1788
+ var _a, _b;
1789
+ return node.nodeType === Node.TEXT_NODE && ((_a = node.previousSibling) == null ? void 0 : _a.nodeType) === Node.COMMENT_NODE && ((_b = node.nextSibling) == null ? void 0 : _b.nodeType) === Node.COMMENT_NODE;
1790
+ }
1791
+ );
1792
+ nextNodes.forEach((node, index) => {
1793
+ const key = getKey(node, index);
1794
+ if (node.nodeType === Node.TEXT_NODE) {
1795
+ textNodes.forEach((ne) => {
1796
+ if (node.textContent === ne.textContent) {
1797
+ parent.replaceChild(node, ne);
1798
+ }
1799
+ });
1800
+ } else {
1801
+ insertChild(parent, node, before);
1802
+ }
1803
+ result.set(key, node);
1290
1804
  });
1291
- } else {
1292
- setAttribute(element, attr, data);
1805
+ return result;
1293
1806
  }
1294
- }
1295
- function h2(template, props, key) {
1807
+ };
1808
+ function h(template, props, key) {
1296
1809
  if (isString(template)) {
1297
1810
  if (isHtmlTagName(template)) {
1298
- template = convertToHtmlTag(template);
1299
- props = { "1": props };
1300
- } else if (template === "") {
1301
- props = { "0": props };
1811
+ const htmlTemplate = convertToHtmlTag(template);
1812
+ props = { [SINGLE_PROP_KEY]: props };
1813
+ return new TemplateNode(createTemplate(htmlTemplate), props, key);
1814
+ } else if (template === EMPTY_TEMPLATE) {
1815
+ props = { [FRAGMENT_PROP_KEY]: props };
1816
+ return new TemplateNode(createTemplate(EMPTY_TEMPLATE), props, key);
1302
1817
  }
1303
- template = createTemplate(template);
1304
1818
  }
1305
1819
  return isFunction(template) ? new ComponentNode(template, props, key) : new TemplateNode(template, props, key);
1306
1820
  }
@@ -1316,19 +1830,17 @@ function createTemplate(html) {
1316
1830
  return template;
1317
1831
  }
1318
1832
  function Fragment(props) {
1319
- return h2("", {
1320
- children: Array.isArray(props.children) ? props.children.filter(Boolean) : [props.children]
1833
+ return h(EMPTY_TEMPLATE, {
1834
+ children: isArray(props.children) ? props.children.filter(Boolean) : [props.children]
1321
1835
  });
1322
1836
  }
1323
1837
  function onMount(cb) {
1324
- var _a;
1325
1838
  assertInsideComponent("onMounted");
1326
- (_a = LifecycleContext.ref) == null ? void 0 : _a.addHook("mounted", cb);
1839
+ LifecycleContext.ref && LifecycleContext.ref.addHook("mounted", cb);
1327
1840
  }
1328
1841
  function onDestroy(cb) {
1329
- var _a;
1330
1842
  assertInsideComponent("onDestroy");
1331
- (_a = LifecycleContext.ref) == null ? void 0 : _a.addHook("destroy", cb);
1843
+ LifecycleContext.ref && LifecycleContext.ref.addHook("destroy", cb);
1332
1844
  }
1333
1845
  function assertInsideComponent(hookName, key) {
1334
1846
  if (!LifecycleContext.ref && true) {
@@ -1339,18 +1851,16 @@ function assertInsideComponent(hookName, key) {
1339
1851
  }
1340
1852
  }
1341
1853
  function useProvide(key, value) {
1342
- var _a;
1343
1854
  assertInsideComponent("useProvide", key);
1344
- (_a = LifecycleContext.ref) == null ? void 0 : _a.setContext(key, value);
1855
+ LifecycleContext.ref && LifecycleContext.ref.setContext(key, value);
1345
1856
  }
1346
1857
  function useInject(key, defaultValue) {
1347
1858
  var _a;
1348
1859
  assertInsideComponent("useInject", key);
1349
- return ((_a = LifecycleContext.ref) == null ? void 0 : _a.getContext(key)) || defaultValue;
1860
+ return (_a = LifecycleContext.ref && LifecycleContext.ref.getContext(key)) != null ? _a : defaultValue;
1350
1861
  }
1351
1862
  function useRef() {
1352
- const ref = We(null);
1353
- return ref;
1863
+ return shallowSignal(null);
1354
1864
  }
1355
1865
  function renderToString(component, props) {
1356
1866
  renderContext.setSSG();
@@ -1365,14 +1875,14 @@ function hydrate(component, container) {
1365
1875
  throw new Error(`Could not find container: ${container}`);
1366
1876
  }
1367
1877
  renderContext.setSSR();
1368
- h2(component).mount(rootElement);
1878
+ h(component).mount(rootElement);
1369
1879
  renderContext.setClient();
1370
1880
  }
1371
1881
  function ssg(component, props) {
1372
1882
  if (renderContext.isSSG) {
1373
1883
  return new SSGNode(component, props);
1374
1884
  }
1375
- return h2(component, props);
1885
+ return h(component, props);
1376
1886
  }
1377
1887
 
1378
1888
  // src/index.ts
@@ -1380,43 +1890,43 @@ if (globalThis) {
1380
1890
  globalThis.__essor_version__ = essor_version;
1381
1891
  }
1382
1892
  /**
1383
- * @estjs/signal v0.0.13-beta.7
1893
+ * @estjs/signal v0.0.13
1384
1894
  * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
1385
1895
  * @license MIT
1386
1896
  **/
1387
1897
  /**
1388
- * @estjs/template v0.0.13-beta.7
1898
+ * @estjs/template v0.0.13
1389
1899
  * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
1390
1900
  * @license MIT
1391
1901
  **/
1392
1902
 
1393
1903
  exports.Fragment = Fragment;
1394
- exports.clearReactive = Me;
1395
- exports.createStore = Ne;
1904
+ exports.clearReactive = clearReactive;
1905
+ exports.createStore = createStore;
1396
1906
  exports.essor_version = essor_version;
1397
- exports.h = h2;
1907
+ exports.h = h;
1398
1908
  exports.hydrate = hydrate;
1399
1909
  exports.isComponent = isComponent;
1400
- exports.isComputed = I;
1910
+ exports.isComputed = isComputed;
1401
1911
  exports.isJsxElement = isJsxElement;
1402
- exports.isReactive = b;
1403
- exports.isSignal = h;
1912
+ exports.isReactive = isReactive;
1913
+ exports.isSignal = isSignal;
1404
1914
  exports.onDestroy = onDestroy;
1405
1915
  exports.onMount = onMount;
1406
1916
  exports.renderToString = renderToString;
1407
- exports.shallowReactive = Ee;
1408
- exports.shallowSignal = We;
1409
- exports.signalObject = Ce;
1917
+ exports.shallowReactive = shallowReactive;
1918
+ exports.shallowSignal = shallowSignal;
1919
+ exports.signalObject = signalObject;
1410
1920
  exports.ssg = ssg;
1411
1921
  exports.template = createTemplate;
1412
- exports.toRaw = c;
1413
- exports.useBatch = fe;
1414
- exports.useComputed = z;
1415
- exports.useEffect = B;
1922
+ exports.toRaw = toRaw;
1923
+ exports.useBatch = useBatch;
1924
+ exports.useComputed = useComputed;
1925
+ exports.useEffect = useEffect;
1416
1926
  exports.useInject = useInject;
1417
1927
  exports.useProvide = useProvide;
1418
- exports.useReactive = L;
1928
+ exports.useReactive = useReactive;
1419
1929
  exports.useRef = useRef;
1420
- exports.useShallowSignal = Re;
1421
- exports.useSignal = le;
1422
- exports.useWatch = Ve;
1930
+ exports.useShallowSignal = useShallowSignal;
1931
+ exports.useSignal = useSignal;
1932
+ exports.useWatch = useWatch;