essor 0.0.12-beta.1 → 0.0.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/dist/essor.cjs.js CHANGED
@@ -1,1421 +1,58 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * essor v0.0.12-beta.1
4
+ * essor v0.0.12
5
5
  * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
6
6
  * @license MIT
7
7
  **/
8
-
9
- // src/version.ts
10
- var essor_version = "0.0.12-beta.1";
11
-
12
- // ../shared/dist/shared.js
13
- var isObject = (val) => val !== null && typeof val === "object";
14
- var isArray = Array.isArray;
15
- function isString(val) {
16
- return typeof val === "string";
17
- }
18
- function isSymbol(val) {
19
- return typeof val === "symbol";
20
- }
21
- function isNil(x) {
22
- return x === null || x === void 0;
23
- }
24
- var isFunction = (val) => typeof val === "function";
25
- function isFalsy(x) {
26
- return x === false || x === null || x === void 0;
27
- }
28
- function coerceArray(data) {
29
- return Array.isArray(data) ? data.flat() : [data];
30
- }
31
- function startsWith(str, searchString) {
32
- if (!isString(str)) {
33
- return false;
34
- }
35
- return str.indexOf(searchString) === 0;
36
- }
37
- function escape(str) {
38
- return str.replaceAll(/["&'<>]/g, (char) => {
39
- switch (char) {
40
- case "&":
41
- return "&amp;";
42
- case "<":
43
- return "&lt;";
44
- case ">":
45
- return "&gt;";
46
- case '"':
47
- return "&quot;";
48
- case "'":
49
- return "&#039;";
50
- default:
51
- return char;
52
- }
53
- });
54
- }
55
- var kebabCase = (string) => {
56
- return string.replaceAll(/[A-Z]+/g, (match, offset) => {
57
- return `${offset > 0 ? "-" : ""}${match.toLocaleLowerCase()}`;
58
- });
59
- };
60
- var capitalizeFirstLetter = (inputString) => {
61
- return inputString.charAt(0).toUpperCase() + inputString.slice(1);
62
- };
63
-
64
- // ../signal/dist/signal.dev.esm.js
65
- var __defProp = Object.defineProperty;
66
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
67
- var __hasOwnProp = Object.prototype.hasOwnProperty;
68
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
69
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
70
- var __spreadValues = (a, b) => {
71
- for (var prop in b || (b = {}))
72
- if (__hasOwnProp.call(b, prop))
73
- __defNormalProp(a, prop, b[prop]);
74
- if (__getOwnPropSymbols)
75
- for (var prop of __getOwnPropSymbols(b)) {
76
- if (__propIsEnum.call(b, prop))
77
- __defNormalProp(a, prop, b[prop]);
78
- }
79
- return a;
80
- };
81
- var isObject2 = (val) => val !== null && typeof val === "object";
82
- var isArray2 = Array.isArray;
83
- function isString2(val) {
84
- return typeof val === "string";
85
- }
86
- function isNull(val) {
87
- return val === null;
88
- }
89
- function isSet(val) {
90
- return _toString.call(val) === "[object Set]";
91
- }
92
- function isWeakMap(val) {
93
- return _toString.call(val) === "[object WeakMap]";
94
- }
95
- function isWeakSet(val) {
96
- return _toString.call(val) === "[object WeakSet]";
97
- }
98
- function isMap(val) {
99
- return _toString.call(val) === "[object Map]";
100
- }
101
- var isFunction2 = (val) => typeof val === "function";
102
- var isPrimitive = (val) => ["string", "number", "boolean", "symbol", "undefined"].includes(typeof val) || isNull(val);
103
- function isHTMLElement(obj) {
104
- if (!obj) return false;
105
- return obj && typeof obj === "object" && obj.nodeType === 1 && typeof obj.nodeName === "string";
106
- }
107
- var _toString = Object.prototype.toString;
108
- var hasOwnProperty = Object.prototype.hasOwnProperty;
109
- var hasOwn = (val, key) => hasOwnProperty.call(val, key);
110
- var hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue);
111
- var noop2 = Function.prototype;
112
- function startsWith2(str, searchString) {
113
- if (!isString2(str)) {
114
- return false;
115
- }
116
- return str.indexOf(searchString) === 0;
117
- }
118
- function isExclude(key, exclude) {
119
- return Array.isArray(exclude) ? exclude.includes(key) : isFunction2(exclude) ? exclude(key) : false;
120
- }
121
- function warn(msg, ...args) {
122
- console.warn.apply(console, [`[Essor warn]: ${msg}`].concat(args));
123
- }
124
- var queue = [];
125
- var activePreFlushCbs = [];
126
- var p = Promise.resolve();
127
- var isFlushPending = false;
128
- function nextTick(fn) {
129
- return fn ? p.then(fn) : p;
130
- }
131
- function queueJob(job) {
132
- if (!queue.includes(job)) {
133
- queue.push(job);
134
- queueFlush();
135
- }
136
- }
137
- function queueFlush() {
138
- if (isFlushPending) {
139
- return;
140
- }
141
- isFlushPending = true;
142
- nextTick(flushJobs);
143
- }
144
- function queuePreFlushCb(cb) {
145
- queueCb(cb, activePreFlushCbs);
146
- }
147
- function queueCb(cb, activeQueue) {
148
- if (!activeQueue.includes(cb)) {
149
- activeQueue.push(cb);
150
- queueFlush();
151
- }
152
- }
153
- function flushJobs() {
154
- isFlushPending = false;
155
- flushPreFlushCbs();
156
- let job;
157
- while (job = queue.shift()) {
158
- if (job) {
159
- job();
160
- }
161
- }
162
- }
163
- function flushPreFlushCbs() {
164
- while (activePreFlushCbs.length > 0) {
165
- const cb = activePreFlushCbs.shift();
166
- if (cb) {
167
- cb();
168
- }
169
- }
170
- }
171
- var activeEffect = null;
172
- var activeComputed = null;
173
- var computedMap = /* @__PURE__ */ new WeakMap();
174
- var signalMap = /* @__PURE__ */ new WeakMap();
175
- var effectDeps = /* @__PURE__ */ new Set();
176
- var reactiveMap = /* @__PURE__ */ new WeakMap();
177
- var arrayMethods = ["push", "pop", "shift", "unshift", "splice", "sort", "reverse"];
178
- function track(target, key) {
179
- if (!activeEffect && !activeComputed) return;
180
- let depsMap = signalMap.get(target);
181
- if (!depsMap) {
182
- depsMap = /* @__PURE__ */ new Map();
183
- signalMap.set(target, depsMap);
184
- }
185
- let dep = depsMap.get(key);
186
- if (!dep) {
187
- dep = /* @__PURE__ */ new Set();
188
- depsMap.set(key, dep);
189
- }
190
- if (activeEffect) dep.add(activeEffect);
191
- let computedDepsMap = computedMap.get(target);
192
- if (!computedDepsMap) {
193
- computedDepsMap = /* @__PURE__ */ new Map();
194
- computedMap.set(target, computedDepsMap);
195
- }
196
- let computedDeps = computedDepsMap.get(key);
197
- if (!computedDeps) {
198
- computedDeps = /* @__PURE__ */ new Set();
199
- computedDepsMap.set(key, computedDeps);
200
- }
201
- if (activeComputed) {
202
- computedDeps.add(activeComputed);
203
- }
204
- }
205
- function trigger(target, key) {
206
- const depsMap = signalMap.get(target);
207
- if (!depsMap) return;
208
- const dep = depsMap.get(key);
209
- if (dep) {
210
- dep.forEach((effect) => effectDeps.has(effect) && effect());
211
- }
212
- const computedDepsMap = computedMap.get(target);
213
- if (computedDepsMap) {
214
- const computeds = computedDepsMap.get(key);
215
- if (computeds) {
216
- computeds.forEach((computed) => computed.run());
217
- }
218
- }
219
- }
220
- var Signal = class {
221
- constructor(value, shallow = false) {
222
- this._value = value;
223
- this._shallow = shallow;
224
- }
225
- /**
226
- * Get the current value of the Signal and track its usage.
227
- */
228
- get value() {
229
- track(this, "_sv");
230
- this.__triggerObject();
231
- return this._value;
232
- }
233
- /**
234
- * Trigger reactivity for non-primitive and non-HTMLElement values.
235
- * Recursively applies reactivity to nested objects.
236
- */
237
- __triggerObject() {
238
- if (!isPrimitive(this._value) && !isHTMLElement(this._value) && !this._shallow) {
239
- useReactive(this._value);
240
- }
241
- }
242
- /**
243
- * Set a new value to the Signal and trigger updates if the value has changed.
244
- */
245
- set value(newValue) {
246
- if (isSignal(newValue)) {
247
- {
248
- console.warn(
249
- "Do not set the signal as a signal, the original value of the signal will be used!"
250
- );
251
- }
252
- newValue = newValue.peek();
253
- }
254
- if (hasChanged(newValue, this._value)) {
255
- this._value = newValue;
256
- if (!isPrimitive(this._value) && !isHTMLElement(this._value)) {
257
- this.__triggerObject();
258
- }
259
- trigger(this, "_sv");
260
- }
261
- }
262
- /**
263
- * Peek at the current value of the Signal without tracking it.
264
- */
265
- peek() {
266
- return this._value;
267
- }
268
- };
269
- function useSignal(value) {
270
- if (isSignal(value)) {
271
- return value;
272
- }
273
- return new Signal(value);
274
- }
275
- function shallowSignal(value) {
276
- return new Signal(value, true);
277
- }
278
- function isSignal(value) {
279
- return value instanceof Signal;
280
- }
281
- var Computed = class {
282
- constructor(fn) {
283
- this.fn = fn;
284
- const prev = activeComputed;
285
- activeComputed = this;
286
- this._value = this.fn();
287
- activeComputed = prev;
288
- }
289
- /**
290
- * Get the current computed value without tracking it.
291
- */
292
- peek() {
293
- return this._value;
294
- }
295
- /**
296
- * Run the computed function and update the value if it has changed.
297
- */
298
- run() {
299
- const newValue = this.fn();
300
- if (hasChanged(newValue, this._value)) {
301
- this._value = newValue;
302
- trigger(this, "_cv");
303
- }
304
- }
305
- /**
306
- * Get the current computed value and track its usage.
307
- */
308
- get value() {
309
- track(this, "_cv");
310
- return this._value;
311
- }
312
- };
313
- function useComputed(fn) {
314
- return new Computed(fn);
315
- }
316
- function isComputed(value) {
317
- return value instanceof Computed;
318
- }
319
- function useEffect(fn, options = {}) {
320
- const { flush = "pre", onTrack, onTrigger } = options;
321
- function effectFn() {
322
- const prev = activeEffect;
323
- activeEffect = effectFn.init ? effectFn : effectFn.effect;
324
- fn();
325
- onTrigger && onTrigger();
326
- activeEffect = prev;
327
- }
328
- const scheduler = flush === "sync" ? () => {
329
- queueJob(effectFn);
330
- } : flush === "pre" ? () => {
331
- queuePreFlushCb(effectFn);
332
- } : () => {
333
- nextTick(() => {
334
- queueJob(effectFn);
335
- });
336
- };
337
- effectFn.effect = scheduler;
338
- effectFn.init = true;
339
- onTrack && onTrack();
340
- effectFn();
341
- effectDeps.add(effectFn);
342
- return () => {
343
- effectDeps.delete(effectFn);
344
- activeEffect = null;
345
- };
346
- }
347
- function signalObject(initialValues, exclude) {
348
- if (!initialValues || !isObject2(initialValues)) {
349
- {
350
- warn("initialValues must be an object,will return initial value!", initialValues);
351
- }
352
- return initialValues;
353
- }
354
- const signals = Object.entries(initialValues).reduce((acc, [key, value]) => {
355
- acc[key] = isExclude(key, exclude) || isSignal(value) ? value : useSignal(value);
356
- return acc;
357
- }, {});
358
- return signals;
359
- }
360
- function unSignal(signal, exclude) {
361
- if (!signal) return {};
362
- if (isSignal(signal)) {
363
- return signal.peek();
364
- }
365
- if (isArray2(signal)) {
366
- return signal.map((value) => unSignal(value, exclude));
367
- }
368
- if (isObject2(signal)) {
369
- return Object.entries(signal).reduce((acc, [key, value]) => {
370
- if (isExclude(key, exclude)) {
371
- acc[key] = value;
372
- } else {
373
- acc[key] = isSignal(value) ? value.peek() : isReactive(value) ? unReactive(value) : value;
374
- }
375
- return acc;
376
- }, {});
377
- }
378
- return signal;
379
- }
380
- var REACTIVE_MARKER = Symbol("useReactive");
381
- function isReactive(obj) {
382
- return obj && obj[REACTIVE_MARKER] === true;
383
- }
384
- function createArrayProxy(initialValue) {
385
- arrayMethods.forEach((method) => {
386
- const originalMethod = Array.prototype[method];
387
- track(initialValue, "length");
388
- Object.defineProperty(initialValue, method, {
389
- value(...args) {
390
- const result = originalMethod.apply(this, args);
391
- if (["push", "pop", "shift", "unshift", "splice", "sort", "reverse"].includes(method)) {
392
- trigger(initialValue, "length");
393
- }
394
- return result;
395
- },
396
- enumerable: false,
397
- writable: true,
398
- configurable: true
399
- });
400
- });
401
- }
402
- function useReactive(initialValue, exclude) {
403
- return reactive(initialValue, exclude, false);
404
- }
405
- function shallowReactive(initialValue, exclude) {
406
- return reactive(initialValue, exclude, true);
407
- }
408
- function unReactive(target) {
409
- if (!isObject2(target)) {
410
- return target;
411
- }
412
- if (!isReactive(target)) {
413
- return target;
414
- }
415
- const unReactiveObj = Array.isArray(target) ? [] : {};
416
- for (const key in target) {
417
- if (hasOwn(target, key)) {
418
- const value = target[key];
419
- if (isReactive(value)) {
420
- unReactiveObj[key] = unReactive(value);
421
- } else if (isSignal(value)) {
422
- unReactiveObj[key] = value.peek();
423
- } else {
424
- unReactiveObj[key] = value;
425
- }
426
- }
427
- }
428
- return unReactiveObj;
429
- }
430
- function reactive(initialValue, exclude, shallow = false) {
431
- if (!isObject2(initialValue)) {
432
- return initialValue;
433
- }
434
- if (isReactive(initialValue)) {
435
- return initialValue;
436
- }
437
- if (reactiveMap.has(initialValue)) {
438
- return reactiveMap.get(initialValue);
439
- }
440
- if (Array.isArray(initialValue)) {
441
- createArrayProxy(initialValue);
442
- }
443
- if (isSet(initialValue) || isMap(initialValue) || isWeakSet(initialValue) || isWeakMap(initialValue)) {
444
- return initialValue;
445
- }
446
- const handler = {
447
- get(target, key, receiver) {
448
- if (key === REACTIVE_MARKER || startsWith2(key, "_")) return true;
449
- const getValue = Reflect.get(target, key, receiver);
450
- const value = isSignal(getValue) ? getValue.value : getValue;
451
- if (isExclude(key, exclude)) {
452
- return value;
453
- }
454
- track(target, key);
455
- if (isObject2(value) && !shallow) {
456
- return useReactive(value);
457
- }
458
- return value;
459
- },
460
- set(target, key, value, receiver) {
461
- if (isExclude(key, exclude)) {
462
- Reflect.set(target, key, value, receiver);
463
- return true;
464
- }
465
- let oldValue = Reflect.get(target, key, receiver);
466
- if (isSignal(oldValue)) {
467
- oldValue = oldValue.value;
468
- }
469
- if (isSignal(value)) {
470
- value = value.value;
471
- }
472
- const obj = Reflect.set(target, key, value, receiver);
473
- if (hasChanged(value, oldValue)) {
474
- trigger(target, key);
475
- }
476
- return obj;
477
- },
478
- deleteProperty(target, key) {
479
- const oldValue = Reflect.get(target, key);
480
- const result = Reflect.deleteProperty(target, key);
481
- if (oldValue !== void 0) {
482
- trigger(target, key);
483
- }
484
- return result;
485
- }
486
- };
487
- const proxy = new Proxy(initialValue, handler);
488
- reactiveMap.set(initialValue, proxy);
489
- return proxy;
490
- }
491
- function useWatch(source, cb, options) {
492
- return doWatch(source, cb, options);
493
- }
494
- function doWatch(source, cb, options) {
495
- let getter;
496
- if (isSignal(source) || isComputed(source)) {
497
- getter = () => source.value;
498
- } else if (isReactive(source)) {
499
- getter = () => __spreadValues({}, source);
500
- } else if (isArray2(source)) {
501
- getter = () => source.map((s) => {
502
- if (isSignal(s) || isComputed(s)) return s.value;
503
- if (isReactive(s)) return __spreadValues({}, s);
504
- if (isFunction2(s)) return s();
505
- return warn("Invalid source", s);
506
- });
507
- } else if (isFunction2(source)) {
508
- getter = source;
509
- } else {
510
- warn("Invalid source type", source);
511
- getter = noop2;
512
- }
513
- let oldValue;
514
- const effectFn = () => {
515
- const newValue = getter();
516
- if ((options == null ? void 0 : options.deep) || hasChanged(newValue, oldValue)) {
517
- cb && cb(newValue, oldValue);
518
- oldValue = newValue;
519
- }
520
- };
521
- const stop = useEffect(effectFn);
522
- if (options == null ? void 0 : options.immediate) {
523
- effectFn();
524
- }
525
- return stop;
526
- }
527
- var _id = 0;
528
- var StoreMap = /* @__PURE__ */ new Map();
529
- function createOptionsStore(options) {
530
- const { state, getters, actions } = options;
531
- const initState = __spreadValues({}, state != null ? state : {});
532
- const reactiveState = useReactive(state != null ? state : {});
533
- const subscriptions = [];
534
- const actionCallbacks = [];
535
- const default_actions = {
536
- patch$(payload) {
537
- Object.assign(reactiveState, payload);
538
- subscriptions.forEach((callback) => callback(reactiveState));
539
- actionCallbacks.forEach((callback) => callback(reactiveState));
540
- },
541
- subscribe$(callback) {
542
- subscriptions.push(callback);
543
- },
544
- unsubscribe$(callback) {
545
- const index = subscriptions.indexOf(callback);
546
- if (index !== -1) {
547
- subscriptions.splice(index, 1);
548
- }
549
- },
550
- onAction$(callback) {
551
- actionCallbacks.push(callback);
552
- },
553
- reset$() {
554
- Object.assign(reactiveState, initState);
555
- }
556
- };
557
- const store = __spreadValues({
558
- state: reactiveState
559
- }, default_actions);
560
- for (const key in getters) {
561
- const getter = getters[key];
562
- if (getter) {
563
- useWatch(useComputed(getter.bind(reactiveState, reactiveState)), (value) => {
564
- store[key] = value;
565
- });
566
- }
567
- }
568
- for (const key in actions) {
569
- const action = actions[key];
570
- if (action) {
571
- store[key] = action.bind(reactiveState);
572
- }
573
- }
574
- StoreMap.set(_id, store);
575
- ++_id;
576
- return store;
577
- }
578
- function createStore(options) {
579
- return function() {
580
- if (StoreMap.has(_id)) {
581
- return StoreMap.get(_id);
582
- }
583
- return createOptionsStore(options);
584
- };
585
- }
586
-
587
- // ../template/dist/template.dev.esm.js
588
- var __defProp2 = Object.defineProperty;
589
- var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
590
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
591
- var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
592
- var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
593
- var __spreadValues2 = (a, b) => {
594
- for (var prop in b || (b = {}))
595
- if (__hasOwnProp2.call(b, prop))
596
- __defNormalProp2(a, prop, b[prop]);
597
- if (__getOwnPropSymbols2)
598
- for (var prop of __getOwnPropSymbols2(b)) {
599
- if (__propIsEnum2.call(b, prop))
600
- __defNormalProp2(a, prop, b[prop]);
601
- }
602
- return a;
603
- };
604
- var _Hooks = class _Hooks2 {
605
- constructor() {
606
- this.hooks = {
607
- mounted: /* @__PURE__ */ new Set(),
608
- destroy: /* @__PURE__ */ new Set()
609
- };
610
- }
611
- addEventListener() {
612
- }
613
- removeEventListener() {
614
- }
615
- addHook(hook, cb) {
616
- var _a;
617
- (_a = this.hooks[hook]) == null ? void 0 : _a.add(cb);
618
- }
619
- getContext(context) {
620
- return _Hooks2.context[context];
621
- }
622
- setContext(context, value) {
623
- _Hooks2.context[context] = value;
624
- }
625
- initRef() {
626
- _Hooks2.ref = this;
627
- }
628
- removeRef() {
629
- _Hooks2.ref = null;
630
- }
631
- };
632
- _Hooks.ref = null;
633
- _Hooks.context = {};
634
- var Hooks = _Hooks;
635
- var ComponentNode = class extends Hooks {
636
- constructor(template2, props, key) {
637
- super();
638
- this.template = template2;
639
- this.props = props;
640
- this.key = key;
641
- this.proxyProps = {};
642
- this.emitter = /* @__PURE__ */ new Set();
643
- this.mounted = false;
644
- this.rootNode = null;
645
- this.context = {};
646
- this.trackMap = /* @__PURE__ */ new Map();
647
- this.proxyProps = signalObject(
648
- props,
649
- (key2) => startsWith(key2, "on") || startsWith(key2, "update")
650
- );
651
- this.key = this.key || props.key;
652
- }
653
- get firstChild() {
654
- var _a, _b;
655
- return (_b = (_a = this.rootNode) == null ? void 0 : _a.firstChild) != null ? _b : null;
656
- }
657
- get isConnected() {
658
- var _a, _b;
659
- return (_b = (_a = this.rootNode) == null ? void 0 : _a.isConnected) != null ? _b : false;
660
- }
661
- inheritNode(node) {
662
- this.context = node.context;
663
- this.hooks = node.hooks;
664
- Object.assign(this.proxyProps, node.proxyProps);
665
- this.rootNode = node.rootNode;
666
- this.trackMap = node.trackMap;
667
- const props = this.props;
668
- this.props = node.props;
669
- this.patchProps(props);
670
- }
671
- mount(parent, before) {
672
- var _a, _b, _c, _d;
673
- if (!isFunction(this.template)) {
674
- throw new Error("Template must be a function");
675
- }
676
- if (this.isConnected) {
677
- return (_b = (_a = this.rootNode) == null ? void 0 : _a.mount(parent, before)) != null ? _b : [];
678
- }
679
- this.initRef();
680
- this.rootNode = this.template(useReactive(this.proxyProps, ["children"]));
681
- this.removeRef();
682
- this.mounted = true;
683
- const mountedNode = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
684
- this.hooks.mounted.forEach((handler) => handler());
685
- this.patchProps(this.props);
686
- return mountedNode;
687
- }
688
- unmount() {
689
- var _a;
690
- this.hooks.destroy.forEach((handler) => handler());
691
- Object.values(this.hooks).forEach((set) => set.clear());
692
- (_a = this.rootNode) == null ? void 0 : _a.unmount();
693
- this.rootNode = null;
694
- this.proxyProps = {};
695
- this.mounted = false;
696
- this.emitter.forEach((emitter) => emitter());
697
- }
698
- getNodeTrack(trackKey, suppressCleanupCall) {
699
- let track2 = this.trackMap.get(trackKey);
700
- if (!track2) {
701
- track2 = { cleanup: () => {
702
- } };
703
- this.trackMap.set(trackKey, track2);
704
- }
705
- if (!suppressCleanupCall) {
706
- track2.cleanup();
707
- }
708
- return track2;
709
- }
710
- patchProps(props) {
711
- var _a, _b, _c, _d;
712
- for (const [key, prop] of Object.entries(props)) {
713
- if (startsWith(key, "on") && ((_a = this.rootNode) == null ? void 0 : _a.nodes)) {
714
- const event = key.slice(2).toLowerCase();
715
- const listener = prop;
716
- const cleanup = addEventListener(this.rootNode.nodes[0], event, listener);
717
- this.emitter.add(cleanup);
718
- } else if (key === "ref") {
719
- props[key].value = (_b = this.rootNode) == null ? void 0 : _b.nodes[0];
720
- } else if (startsWith(key, "update")) {
721
- props[key] = isSignal(prop) ? prop.value : prop;
722
- } else if (key !== "children") {
723
- const newValue = (_d = (_c = this.proxyProps)[key]) != null ? _d : _c[key] = useSignal(prop);
724
- const track2 = this.getNodeTrack(key);
725
- track2.cleanup = useEffect(() => {
726
- newValue.value = isFunction(prop) ? prop() : prop;
727
- });
728
- }
729
- }
730
- this.props = props;
731
- }
732
- };
733
- function h(_template, props, key) {
734
- if (isString(_template)) {
735
- if (isHtmlTagName(_template)) {
736
- _template = convertToHtmlTag(_template);
737
- props = {
738
- 1: props
739
- };
740
- }
741
- if (_template === "") {
742
- props = {
743
- 0: props
744
- };
745
- }
746
- _template = template(_template);
747
- }
748
- return isFunction(_template) ? new ComponentNode(_template, props, key) : new TemplateNode(_template, props, key);
749
- }
750
- function isComponent(node) {
751
- return node instanceof ComponentNode;
752
- }
753
- function isJsxElement(node) {
754
- return node instanceof ComponentNode || node instanceof TemplateNode;
755
- }
756
- function template(html) {
757
- const template2 = document.createElement("template");
758
- template2.innerHTML = closeHtmlTags(html);
759
- return template2;
760
- }
761
- function Fragment(props) {
762
- return props.children;
763
- }
764
- var selfClosingTags = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
765
- 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";
766
- function coerceNode(data) {
767
- if (isJsxElement(data) || data instanceof Node) {
768
- return data;
769
- }
770
- const text = isFalsy(data) ? "" : String(data);
771
- return document.createTextNode(text);
772
- }
773
- function insertChild(parent, child, before = null) {
774
- const beforeNode = isJsxElement(before) ? before.firstChild : before;
775
- if (isJsxElement(child)) {
776
- child.mount(parent, beforeNode);
777
- } else if (beforeNode) {
778
- beforeNode.before(child);
779
- } else {
780
- parent.append(child);
781
- }
782
- }
783
- function removeChild(child) {
784
- if (isJsxElement(child)) {
785
- child.unmount();
786
- } else {
787
- const parent = child.parentNode;
788
- if (parent) {
789
- child.remove();
790
- }
791
- }
792
- }
793
- function replaceChild(parent, node, child) {
794
- insertChild(parent, node, child);
795
- removeChild(child);
796
- }
797
- function setAttribute(element, attr, value) {
798
- if (attr === "class") {
799
- if (typeof value === "string") {
800
- element.className = value;
801
- } else if (Array.isArray(value)) {
802
- element.className = value.join(" ");
803
- } else if (value && typeof value === "object") {
804
- element.className = Object.entries(value).reduce((acc, [key, value2]) => acc + (value2 ? ` ${key}` : ""), "").trim();
805
- }
806
- return;
807
- }
808
- if (attr === "style") {
809
- if (typeof value === "string") {
810
- element.style.cssText = value;
811
- } else if (value && typeof value === "object") {
812
- const obj = value;
813
- Object.keys(obj).forEach((key) => {
814
- element.style.setProperty(kebabCase(key), String(obj[key]));
815
- });
816
- }
817
- return;
818
- }
819
- if (isFalsy(value)) {
820
- element.removeAttribute(attr);
821
- } else if (value === true) {
822
- element.setAttribute(attr, "");
823
- } else {
824
- if (element instanceof HTMLInputElement) {
825
- element.value = String(value);
826
- } else {
827
- element.setAttribute(attr, String(value));
828
- }
829
- }
830
- }
831
- function binNode(node, setter) {
832
- if (node instanceof HTMLInputElement) {
833
- switch (node.type) {
834
- case "checkbox":
835
- return addEventListener(node, "change", () => {
836
- setter(Boolean(node.checked));
837
- });
838
- case "date":
839
- return addEventListener(node, "change", () => {
840
- setter(node.value ? node.value : "");
841
- });
842
- case "file":
843
- return addEventListener(node, "change", () => {
844
- if (node.files) {
845
- setter(node.files);
846
- }
847
- });
848
- case "number":
849
- return addEventListener(node, "input", () => {
850
- const value = Number.parseFloat(node.value);
851
- setter(Number.isNaN(value) ? "" : String(value));
852
- });
853
- case "radio":
854
- return addEventListener(node, "change", () => {
855
- setter(node.checked ? node.value : "");
856
- });
857
- case "text":
858
- return addEventListener(node, "input", () => {
859
- setter(node.value);
860
- });
861
- }
862
- }
863
- if (node instanceof HTMLSelectElement) {
864
- return addEventListener(node, "change", () => {
865
- setter(node.value);
866
- });
867
- }
868
- if (node instanceof HTMLTextAreaElement) {
869
- return addEventListener(node, "input", () => {
870
- setter(node.value);
871
- });
872
- }
873
- }
874
- var p2 = Promise.resolve();
875
- function nextTick2(fn) {
876
- return fn ? p2.then(fn) : p2;
877
- }
878
- function addEventListener(node, eventName, handler) {
879
- node.addEventListener(eventName, handler);
880
- return () => node.removeEventListener(eventName, handler);
881
- }
882
- function closeHtmlTags(input) {
883
- const selfClosingTagList = selfClosingTags.split(",");
884
- const tagStack = [];
885
- const output = [];
886
- const tagPattern = /<\/?([\da-z-]+)([^>]*)>/gi;
887
- let lastIndex = 0;
888
- while (true) {
889
- const match = tagPattern.exec(input);
890
- if (!match) break;
891
- const [fullMatch, tagName] = match;
892
- const isEndTag = fullMatch[1] === "/";
893
- output.push(input.slice(lastIndex, match.index));
894
- lastIndex = match.index + fullMatch.length;
895
- if (isEndTag) {
896
- while (tagStack.length > 0 && tagStack[tagStack.length - 1] !== tagName) {
897
- const unclosedTag = tagStack.pop();
898
- if (unclosedTag) {
899
- output.push(`</${unclosedTag}>`);
900
- }
901
- }
902
- if (tagStack.length > 0) {
903
- tagStack.pop();
904
- }
905
- } else if (!selfClosingTagList.includes(tagName)) {
906
- tagStack.push(tagName);
907
- }
908
- output.push(fullMatch);
909
- }
910
- output.push(input.slice(lastIndex));
911
- while (tagStack.length > 0) {
912
- const unclosedTag = tagStack.pop();
913
- if (unclosedTag) {
914
- output.push(`</${unclosedTag}>`);
915
- }
916
- }
917
- return output.join("");
918
- }
919
- function isHtmlTagName(tagName) {
920
- const htmlTagsList = htmlTags.split(",");
921
- return htmlTagsList.includes(tagName);
922
- }
923
- function convertToHtmlTag(tagName) {
924
- const selfClosingTagList = selfClosingTags.split(",");
925
- if (selfClosingTagList.includes(tagName)) {
926
- return `<${tagName}/>`;
927
- } else {
928
- return `<${tagName}></${tagName}>`;
929
- }
930
- }
931
- function patchChildren(parent, childrenMap, nextChildren, before) {
932
- const result = /* @__PURE__ */ new Map();
933
- const children = Array.from(childrenMap.values());
934
- const childrenLength = children.length;
935
- if (childrenMap.size > 0 && nextChildren.length === 0) {
936
- if (parent.childNodes.length === childrenLength + (before ? 1 : 0)) {
937
- parent.innerHTML = "";
938
- if (before) {
939
- insertChild(parent, before);
940
- }
941
- } else {
942
- const range = document.createRange();
943
- const child = children[0];
944
- const start = isJsxElement(child) ? child.firstChild : child;
945
- range.setStartBefore(start);
946
- if (before) {
947
- range.setEndBefore(before);
948
- } else {
949
- range.setEndAfter(parent);
950
- }
951
- range.deleteContents();
952
- }
953
- children.forEach((node) => {
954
- if (isJsxElement(node)) {
955
- node.unmount();
956
- }
957
- });
958
- return result;
959
- }
960
- const replaces = [];
961
- const nextChildrenMap = mapKeys(nextChildren);
962
- let childIndex = 0;
963
- for (let [i, child] of nextChildren.entries()) {
964
- let currChild = children[childIndex];
965
- let currKey = getKey(currChild, i);
966
- while (currChild && !nextChildrenMap.has(currKey)) {
967
- removeChild(currChild);
968
- childrenMap.delete(currKey);
969
- currChild = children[++childIndex];
970
- currKey = getKey(currChild, i);
971
- }
972
- const key = getKey(child, i);
973
- const origChild = childrenMap.get(key);
974
- if (origChild) {
975
- child = patch(parent, origChild, child);
976
- }
977
- if (currChild) {
978
- if (currChild === origChild) {
979
- childIndex++;
980
- } else {
981
- const placeholder = document.createComment("");
982
- insertChild(parent, placeholder, currChild);
983
- replaces.push([placeholder, child]);
984
- }
985
- } else {
986
- insertChild(parent, child, before);
987
- }
988
- result.set(key, child);
989
- }
990
- replaces.forEach(([placeholder, child]) => replaceChild(parent, child, placeholder));
991
- childrenMap.forEach((child, key) => {
992
- if (child.isConnected && !result.has(key)) {
993
- removeChild(child);
994
- }
995
- });
996
- return result;
997
- }
998
- function patch(parent, node, next) {
999
- if (node === next) {
1000
- return node;
1001
- }
1002
- if (isJsxElement(node) && isJsxElement(next) && node.template === next.template) {
1003
- next.inheritNode(node);
1004
- return next;
1005
- }
1006
- if (node instanceof Text && next instanceof Text) {
1007
- if (node.textContent !== next.textContent) {
1008
- node.textContent = next.textContent;
1009
- }
1010
- return node;
1011
- }
1012
- replaceChild(parent, next, node);
1013
- return next;
1014
- }
1015
- function mapKeys(children) {
1016
- const result = /* @__PURE__ */ new Map();
1017
- for (const [i, child] of children.entries()) {
1018
- const key = getKey(child, i);
1019
- result.set(key, child);
1020
- }
1021
- return result;
1022
- }
1023
- function getKey(node, index) {
1024
- if (isJsxElement(node)) {
1025
- const jsxKey = node.key;
1026
- if (jsxKey !== void 0 && jsxKey !== null) {
1027
- return String(jsxKey);
1028
- }
1029
- }
1030
- return `_$${index}$`;
1031
- }
1032
- var TemplateNode = class _TemplateNode {
1033
- constructor(template2, props, key) {
1034
- this.template = template2;
1035
- this.props = props;
1036
- this.key = key;
1037
- this.treeMap = /* @__PURE__ */ new Map();
1038
- this.mounted = false;
1039
- this.nodes = [];
1040
- this.provides = {};
1041
- this.trackMap = /* @__PURE__ */ new Map();
1042
- this.parent = null;
1043
- this.key = this.key || props.key;
1044
- }
1045
- get firstChild() {
1046
- var _a;
1047
- return (_a = this.nodes[0]) != null ? _a : null;
1048
- }
1049
- get isConnected() {
1050
- return this.mounted;
1051
- }
1052
- addEventListener() {
1053
- }
1054
- removeEventListener() {
1055
- }
1056
- mount(parent, before) {
1057
- var _a;
1058
- this.parent = parent;
1059
- if (this.isConnected) {
1060
- this.nodes.forEach((node) => insertChild(parent, node, before));
1061
- return this.nodes;
1062
- }
1063
- const cloneNode = this.template.content.cloneNode(true);
1064
- const firstChild = cloneNode.firstChild;
1065
- if ((_a = firstChild == null ? void 0 : firstChild.hasAttribute) == null ? void 0 : _a.call(firstChild, "_svg_")) {
1066
- firstChild.remove();
1067
- firstChild == null ? void 0 : firstChild.childNodes.forEach((node) => {
1068
- cloneNode.append(node);
1069
- });
1070
- }
1071
- this.nodes = Array.from(cloneNode.childNodes);
1072
- this.mapNodeTree(parent, cloneNode);
1073
- insertChild(parent, cloneNode, before);
1074
- this.patchNodes(this.props);
1075
- this.mounted = true;
1076
- return this.nodes;
1077
- }
1078
- unmount() {
1079
- this.trackMap.forEach((track2) => {
1080
- var _a, _b;
1081
- (_a = track2.cleanup) == null ? void 0 : _a.call(track2);
1082
- (_b = track2.lastNodes) == null ? void 0 : _b.forEach((node) => {
1083
- if (track2.isRoot) {
1084
- removeChild(node);
1085
- } else if (node instanceof _TemplateNode) {
1086
- node.unmount();
1087
- }
1088
- });
1089
- });
1090
- this.trackMap.clear();
1091
- this.treeMap.clear();
1092
- this.nodes.forEach((node) => removeChild(node));
1093
- this.nodes = [];
1094
- this.mounted = false;
1095
- }
1096
- mapNodeTree(parent, tree) {
1097
- let index = 1;
1098
- this.treeMap.set(0, parent);
1099
- const walk = (node) => {
1100
- if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
1101
- this.treeMap.set(index++, node);
1102
- }
1103
- let child = node.firstChild;
1104
- while (child) {
1105
- walk(child);
1106
- child = child.nextSibling;
1107
- }
1108
- };
1109
- walk(tree);
1110
- }
1111
- patchNodes(props) {
1112
- for (const key in props) {
1113
- const index = Number(key);
1114
- const node = this.treeMap.get(index);
1115
- if (node) {
1116
- const value = this.props[key];
1117
- this.patchNode(key, node, value, index === 0);
1118
- }
1119
- }
1120
- this.props = props;
1121
- }
1122
- getNodeTrack(trackKey, trackLastNodes, isRoot) {
1123
- var _a;
1124
- let track2 = this.trackMap.get(trackKey);
1125
- if (!track2) {
1126
- track2 = { cleanup: () => {
1127
- } };
1128
- if (trackLastNodes) {
1129
- track2.lastNodes = /* @__PURE__ */ new Map();
1130
- }
1131
- if (isRoot) {
1132
- track2.isRoot = true;
1133
- }
1134
- this.trackMap.set(trackKey, track2);
1135
- }
1136
- (_a = track2.cleanup) == null ? void 0 : _a.call(track2);
1137
- return track2;
1138
- }
1139
- inheritNode(node) {
1140
- this.mounted = node.mounted;
1141
- this.nodes = node.nodes;
1142
- this.trackMap = node.trackMap;
1143
- this.treeMap = node.treeMap;
1144
- const props = this.props;
1145
- this.props = node.props;
1146
- this.patchNodes(props);
1147
- }
1148
- patchNode(key, node, props, isRoot) {
1149
- for (const attr in props) {
1150
- if (attr === "children" && props.children) {
1151
- if (!isArray(props.children)) {
1152
- const trackKey = `${key}:${attr}:${0}`;
1153
- const track2 = this.getNodeTrack(trackKey, true, isRoot);
1154
- patchChild(track2, node, props.children, null);
1155
- } else {
1156
- props.children.filter(Boolean).forEach((item, index) => {
1157
- var _a;
1158
- const [child, path] = isArray(item) ? item : [item, null];
1159
- const before = isNil(path) ? null : (_a = this.treeMap.get(path)) != null ? _a : null;
1160
- const trackKey = `${key}:${attr}:${index}`;
1161
- const track2 = this.getNodeTrack(trackKey, true, isRoot);
1162
- patchChild(track2, node, child, before);
1163
- });
1164
- }
1165
- } else if (attr === "ref") {
1166
- props[attr].value = node;
1167
- } else if (startsWith(attr, "on")) {
1168
- const eventName = attr.slice(2).toLocaleLowerCase();
1169
- const track2 = this.getNodeTrack(`${key}:${attr}`);
1170
- const listener = props[attr];
1171
- track2.cleanup = addEventListener(node, eventName, listener);
1172
- } else if (!startsWith(attr, "update")) {
1173
- const track2 = this.getNodeTrack(`${key}:${attr}`);
1174
- const val = props[attr];
1175
- const triggerValue = isSignal(val) ? val : useSignal(val);
1176
- patchAttribute(track2, node, attr, triggerValue.value);
1177
- const cleanup = useEffect(() => {
1178
- triggerValue.value = isSignal(val) ? val.value : val;
1179
- patchAttribute(track2, node, attr, triggerValue.value);
1180
- });
1181
- let cleanupBind;
1182
- const updateKey = `update${capitalizeFirstLetter(attr)}`;
1183
- if (props[updateKey]) {
1184
- cleanupBind = binNode(node, (value) => {
1185
- props[updateKey](value);
1186
- });
1187
- }
1188
- track2.cleanup = () => {
1189
- cleanup && cleanup();
1190
- cleanupBind && cleanupBind();
1191
- };
1192
- }
1193
- }
1194
- }
1195
- };
1196
- function patchAttribute(track2, node, attr, data) {
1197
- const element = node;
1198
- if (!element.setAttribute) {
1199
- return;
1200
- }
1201
- if (isFunction(data)) {
1202
- track2.cleanup = useEffect(() => {
1203
- setAttribute(element, attr, data());
1204
- });
1205
- } else {
1206
- setAttribute(element, attr, data);
1207
- }
1208
- }
1209
- function patchChild(track2, parent, child, before) {
1210
- if (isFunction(child)) {
1211
- track2.cleanup = useEffect(() => {
1212
- const nextNodes = coerceArray(child()).map(coerceNode);
1213
- track2.lastNodes = patchChildren(parent, track2.lastNodes, nextNodes, before);
1214
- });
1215
- } else {
1216
- coerceArray(child).forEach((node, i) => {
1217
- const newNode = coerceNode(node);
1218
- track2.lastNodes.set(String(i), newNode);
1219
- insertChild(parent, newNode, before);
1220
- });
1221
- }
1222
- }
1223
- function onMount(cb) {
1224
- var _a;
1225
- throwIfOutsideComponent("onMounted");
1226
- (_a = Hooks.ref) == null ? void 0 : _a.addHook("mounted", cb);
1227
- }
1228
- function onDestroy(cb) {
1229
- var _a;
1230
- throwIfOutsideComponent("onDestroy");
1231
- (_a = Hooks.ref) == null ? void 0 : _a.addHook("destroy", cb);
1232
- }
1233
- function throwIfOutsideComponent(hook, key) {
1234
- if (!Hooks.ref) {
1235
- console.error(
1236
- `"${hook}"(key: ${isSymbol(key) ? key.toString() : key}) can only be called within the component function body
1237
- and cannot be used in asynchronous or deferred calls.`
1238
- );
1239
- }
1240
- }
1241
- function useProvide(key, value) {
1242
- var _a;
1243
- throwIfOutsideComponent("useProvide", key);
1244
- (_a = Hooks.ref) == null ? void 0 : _a.setContext(key, value);
1245
- }
1246
- function useInject(key, defaultValue) {
1247
- var _a;
1248
- throwIfOutsideComponent("useInject", key);
1249
- return ((_a = Hooks.ref) == null ? void 0 : _a.getContext(key)) || defaultValue;
1250
- }
1251
- function useRef() {
1252
- const ref = shallowSignal(null);
1253
- return ref;
1254
- }
1255
- function generateAttributes(props) {
1256
- return Object.entries(props).map(([key, value]) => {
1257
- if (key === "children" || isFunction(value)) return "";
1258
- return `${key}="${escape(String(value))}"`;
1259
- }).filter(Boolean).join(" ");
1260
- }
1261
- function normalizeProps(props) {
1262
- Object.keys(props).forEach((propKey) => {
1263
- if (isFunction(props[propKey])) {
1264
- delete props[propKey];
1265
- }
1266
- if (isSignal(props[propKey])) {
1267
- props[propKey] = props[propKey].value;
1268
- }
1269
- });
1270
- }
1271
- function handleChildResult(result, prop, key, tmpl, childNodesMap, path) {
1272
- if (isSignal(result)) {
1273
- tmpl.template += result.value;
1274
- } else if (result instanceof ServerNode) {
1275
- const mapKey = path ? String(path) : `${key}`;
1276
- if (!childNodesMap[mapKey]) childNodesMap[mapKey] = [];
1277
- const childResult = result.mount();
1278
- childNodesMap[mapKey].push(
1279
- isFunction(childResult) ? childResult(prop) : isSignal(childResult) ? childResult.value : childResult
1280
- );
1281
- } else {
1282
- tmpl.template += isFunction(result) ? result(prop) : String(result);
1283
- }
1284
- }
1285
- var ServerNode = class _ServerNode extends Hooks {
1286
- constructor(template2, props = {}, key) {
1287
- super();
1288
- this.template = template2;
1289
- this.props = props;
1290
- this.key = key;
1291
- this.childNodesMap = {};
1292
- this.processedTemplates = {};
1293
- }
1294
- /**
1295
- * Mount and render the component
1296
- */
1297
- mount() {
1298
- this.initRef();
1299
- const output = this.render();
1300
- this.removeRef();
1301
- return output;
1302
- }
1303
- /**
1304
- * Initialize template entries and props
1305
- */
1306
- initTemplates() {
1307
- const templateCollection = Array.isArray(this.template) ? this.template.reduce((acc, tmpl, index) => {
1308
- acc[index + 1] = { template: tmpl };
1309
- return acc;
1310
- }, {}) : this.template;
1311
- if (isObject(templateCollection)) {
1312
- Object.entries(templateCollection).forEach(([key, tmpl]) => {
1313
- const prop = __spreadValues2({}, this.props[key]);
1314
- normalizeProps(prop);
1315
- if (prop.children) {
1316
- prop.children.forEach((item) => {
1317
- const [child, path] = isArray(item) ? item : [item, null];
1318
- if (isFunction(child)) {
1319
- const result = child(prop);
1320
- handleChildResult(result, prop, key, tmpl, this.childNodesMap, path);
1321
- } else {
1322
- tmpl.template += isSignal(child) ? child.value : String(child);
1323
- }
1324
- });
1325
- }
1326
- this.processedTemplates[key] = {
1327
- template: tmpl.template,
1328
- props: prop
1329
- };
1330
- });
1331
- }
1332
- }
1333
- /**
1334
- * Render component and its children into a string
1335
- */
1336
- render() {
1337
- if (isFunction(this.template)) {
1338
- const root = this.template(this.props);
1339
- return root instanceof _ServerNode ? root.mount() : String(root);
1340
- }
1341
- if (this.template instanceof _ServerNode) {
1342
- return this.template.mount();
1343
- }
1344
- this.initTemplates();
1345
- return Object.entries(this.processedTemplates).map(([key, { template: template2, props }]) => {
1346
- let content = template2;
1347
- if (props && Object.keys(props).length > 0) {
1348
- content += ` ${generateAttributes(props)}`;
1349
- }
1350
- if (this.childNodesMap[key]) {
1351
- content = content.replace("<!>", this.renderChildren(this.childNodesMap[key]));
1352
- }
1353
- return content;
1354
- }).join("");
1355
- }
1356
- /**
1357
- * Render child nodes into a string
1358
- */
1359
- renderChildren(children) {
1360
- return coerceArray(children).map(String).join("");
1361
- }
1362
- };
1363
- function ssg(component, props) {
1364
- return new ServerNode(component, props);
1365
- }
1366
- function renderToString(component, props) {
1367
- return ssg(component, props).mount();
1368
- }
1369
-
1370
- // src/index.ts
1371
- if (globalThis) {
1372
- globalThis.__essor_version__ = essor_version;
1373
- }
1374
- /**
1375
- * @estjs/shared v0.0.12-beta.1
8
+ var bt="0.0.12";var yt=t=>t!==null&&typeof t=="object";var q=Array.isArray;function X(t){return typeof t=="string"}function Nt(t){return typeof t=="symbol"}function St(t){return t==null}var b=t=>typeof t=="function";function Y(t){return t===!1||t===null||t===void 0}function z(t){return Array.isArray(t)?t.flat():[t]}function w(t,e){return X(t)?t.indexOf(e)===0:!1}function _t(t){return t.replaceAll(/["&'<>]/g,e=>{switch(e){case"&":return "&amp;";case"<":return "&lt;";case">":return "&gt;";case'"':return "&quot;";case"'":return "&#039;";default:return e}})}var wt=t=>t.replaceAll(/[A-Z]+/g,(e,r)=>`${r>0?"-":""}${e.toLocaleLowerCase()}`);var Ct=t=>t.charAt(0).toUpperCase()+t.slice(1);var re=Object.defineProperty,Et=Object.getOwnPropertySymbols,ne=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable,Mt=(t,e,r)=>e in t?re(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,D=(t,e)=>{for(var r in e||(e={}))ne.call(e,r)&&Mt(t,r,e[r]);if(Et)for(var r of Et(e))se.call(e,r)&&Mt(t,r,e[r]);return t},_=t=>t!==null&&typeof t=="object",k=Array.isArray;function ie(t){return typeof t=="string"}function ct(t){return R.call(t)==="[object Set]"}function $t(t){return R.call(t)==="[object WeakMap]"}function Lt(t){return R.call(t)==="[object WeakSet]"}function at(t){return R.call(t)==="[object Map]"}var ut=t=>typeof t=="function",It=t=>R.call(t)==="[object Object]";function Tt(t){return ie(t)?!Number.isNaN(Number(t)):!1}var R=Object.prototype.toString,oe=Object.prototype.hasOwnProperty,lt=(t,e)=>oe.call(t,e),$=(t,e)=>t!==e&&(t===t||e===e),Wt=Function.prototype;function A(t,e){return Array.isArray(e)?e.includes(t):ut(e)?e(t):!1}function x(t,...e){console.warn.apply(console,[`[Essor warn]: ${t}`].concat(e));}var tt=[],et=[],Ot=Promise.resolve(),rt=!1;function ft(t){return t?Ot.then(t):Ot}function ce(t){tt.includes(t)||(tt.push(t),Ht());}function Ht(){rt||(rt=!0,ft(le));}function ae(t){ue(t,et);}function ue(t,e){e.includes(t)||(e.push(t),Ht());}function le(){rt=!1,fe();let t;for(;t=tt.shift();)t&&t();}function fe(){for(;et.length>0;){let t=et.shift();t&&t();}}var y=null,he=null,nt=new WeakMap,V=new WeakMap,L=Symbol("ReactiveSymbol"),I=Symbol("__raw"),Pt=Symbol("SignalValueKey"),jt=Symbol("ComputedValueKey"),st=Symbol("ReactiveArrayKey"),g=Symbol("ReactiveCollectionKey"),M=Symbol("ReactiveWeakCollectionKey"),it=!1,B=new Set;function f(t,e){if(!y&&!he)return;let r=nt.get(t);r||(r=new Map,nt.set(t,r));let n=r.get(e);n||(n=new Set,r.set(e,n)),y&&n.add(y);}function v(t,e){let r=nt.get(t);if(!r)return;let n=r.get(e);n&&n.forEach(s=>{if(lt(s,"active")&&!s.active){n.delete(s);return}it?B.add(s):s();});}var Ft=class{constructor(t,e=!1){this.__signal=!0,this._shallow=e,this._value=t;}get value(){return f(this,Pt),_(this._value)&&!this._shallow?W(this._value):this._value}set value(t){p(t)&&(t=t.peek()),$(t,this._value)&&(this._value=t,v(this,Pt));}peek(){return this._value}};function J(t){return p(t)?t:new Ft(t)}function Kt(t){return new Ft(t,!0)}function p(t){return !!(t&&(t!=null&&t.__signal))}var pe=class{constructor(t){this.fn=t,this.__computed=!0;let e=y;y=this.run.bind(this),this._value=this.fn(),y=e;}peek(){return this._value}run(){let t=this.fn();$(t,this._value)&&(this._value=t,v(this,jt));}get value(){return f(this,jt),this._value}};function de(t){return new pe(t)}function qt(t){return !!(t&&t.__computed)}function me(t,e){return e==="sync"?()=>t():e==="pre"?()=>ae(t):()=>{ft(()=>ce(t));}}function T(t,e={}){let{flush:r="pre",onTrack:n,onTrigger:s}=e;function i(){let a=y;y=i.init?i:i.scheduler,t(),s&&s(),y=a;}let o=me(i,r);return i.scheduler=o,i.init=!0,i.active=!0,n&&n(),i(),()=>{i.active=!1,y=null;}}function zt(t,e){return !t||!_(t)?(x("initialValues must be an object,will return initial value!",t),t):Object.entries(t).reduce((n,[s,i])=>(n[s]=A(s,e)||p(i)?i:J(i),n),{})}function ge(t,e){return t?p(t)?t.peek():k(t)?t.map(r=>ge(r,e)):It(t)?Object.entries(t).reduce((r,[n,s])=>(A(n,e)?r[n]=s:r[n]=p(s)?s.peek():O(s)?h(s):s,r),{}):t:{}}function O(t){return !!(t&&typeof t=="object"&&t[L])}function W(t,e){return ht(t,!1,e)}function Xe(t,e){return ht(t,!0,e)}function h(t){return !_(t)||!O(t)?t:t[I]}var ve=(t,e)=>({get(r,n,s){if(n===L)return !0;if(n===I)return r;let i=Reflect.get(r,n,s),o=p(i)?i.value:i;return A(n,e)?o:(f(r,n),_(o)&&!t?W(o):o)},set(r,n,s,i){if(A(n,e))return Reflect.set(r,n,s,i),!0;let o=Reflect.get(r,n,i);p(o)&&(o=o.value),p(s)&&(s=s.value);let a=Reflect.set(r,n,s,i);return $(s,o)&&v(r,n),a},deleteProperty(r,n){let s=Reflect.get(r,n),i=Reflect.deleteProperty(r,n);return s!==void 0&&v(r,n),i}}),At=be();function be(){let t={};return ["includes","indexOf","lastIndexOf"].forEach(e=>{t[e]=function(...r){let n=this;for(let i=0,o=this.length;i<o;i++)f(n,`${i}`);let s=n[e](...r);return s===-1||s===!1?n[e](...r):s};}),["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].forEach(e=>{t[e]=function(...r){let n=h(this),s=n[e].apply(this,r);return v(n,st),s};}),["forEach","map","filter","reduce","reduceRight","some","every","find","findIndex","findLast","findLastIndex","entries","keys","values"].forEach(e=>{t[e]=function(...r){let n=h(this);return f(n,st),n[e].apply(this,r)};}),t}var ye=(t,e)=>({get(r,n,s){if(n===L)return !0;if(n===I)return r;if(At.hasOwnProperty(n))return Reflect.get(At,n,s);let i=Reflect.get(r,n,s);return A(n,e)?i:(Tt(n)&&f(r,n),f(r,"length"),_(i)&&!t?ht(i):i)},set(r,n,s,i){let o=Reflect.get(r,n,i),a=Reflect.set(r,n,s,i);return $(s,o)&&(Tt(n)&&v(r,n),n==="length"&&v(r,"length")),a}}),Ne={get(t,e){return e===L?!0:e===I?t:((e===Symbol.iterator||e==="size")&&f(t,g),Reflect.get(lt(xt,e)&&e in t?xt:t,e,t))}},Se={get(t,e){return e===L?!0:e===I?t:Reflect.get(lt(kt,e)&&e in t?kt:t,e,t)}},xt={get(t){let e=h(this);return f(e,g),e.get(t)},set(t,e){let r=h(this),n=r.set(t,e);return v(r,g),n},add(t){let e=h(this),r=e.add(t);return v(e,g),r},has(t){let e=h(this);return f(e,g),e.has(t)},delete(t){let e=h(this),r=e.has(t),n=e.delete(t);return r&&v(e,g),n},clear(){let t=h(this),e=t.size>0,r=t.clear();return e&&v(t,g),r},forEach(t,e){let r=h(this);f(r,g),r.forEach((n,s)=>{t.call(e,n,s,r);});},get size(){let t=h(this);return f(t,g),t.size},keys(){let t=h(this);return f(t,g),t.keys()},values(){let t=h(this);return f(t,g),t.values()},entries(){let t=h(this);return f(t,g),t.entries()},[Symbol.iterator](){let t=h(this);return f(t,g),t[Symbol.iterator]()}},kt={get(t){let e=h(this);return f(e,M),e.get(t)},set(t,e){let r=h(this),n=r.set(t,e);return v(r,M),n},add(t){let e=h(this),r=e.add(t);return v(e,M),r},has(t){let e=h(this);return f(e,M),e.has(t)},delete(t){let e=h(this),r=e.delete(t);return v(e,M),r}};function ht(t,e=!1,r){if(!_(t)||O(t))return t;if(V.has(t))return V.get(t);let n;k(t)?(f(t,st),n=ye(e,r)):ct(t)||at(t)?(f(t,g),n=Ne):Lt(t)||$t(t)?(f(t,M),n=Se):n=ve(e,r);let s=new Proxy(t,n);return V.set(t,s),s}function Ye(t){if(!O(t)){x("clearReactive: argument must be a reactive object");return}if($t(t)||Lt(t)){x("clearReactive: WeakMap and WeakSet are not clearable");return}_e(()=>{k(t)?t.length=0:ct(t)||at(t)?t.clear():_(t)&&Object.keys(t).forEach(e=>{delete t[e];});});}function _e(t){try{it=!0,t();}finally{it=!1,we();}}function we(){B.size>0&&(B.forEach(t=>t()),B.clear());}function Ve(t,e,r){return Me(t,e,r)}var Rt=void 0,U,ot=!1;function Ce(t){U=t,ot||(ot=!0,ft(Ee));}function Ee(){U==null||U(),U=null,ot=!1;}function Me(t,e,{deep:r,immediate:n}={}){let s,i=k(t);if(p(t)||qt(t))s=()=>t.value;else if(O(t))s=()=>D({},t);else if(i)s=()=>t.map(c=>Te(c));else if(ut(t))s=t;else return x("Invalid source type",t),Wt;if(e&&r){let c=s,u=r===!0?1/0:r;s=()=>j(c(),u);}let o=i?Array.from({length:t.length}).fill(Rt):Rt,a=!1,l=()=>{let c=s();$(c,o)&&(n&&e&&(e(c,o),o=c),a&&e&&Ce(()=>{e(c,o),o=c;}),!a&&(o=c));},d=T(l,{flush:"sync"});return a=!0,n&&l(),d}function Te(t){return p(t)||qt(t)?t.value:O(t)?D({},t):ut(t)?t():(x("Invalid source",t),Wt)}function j(t,e=1/0,r){if(e<=0||!_(t)||(r=r||new Set,r.has(t)))return t;if(r.add(t),e--,p(t))j(t.value,e,r);else if(k(t))for(let n of t)j(n,e,r);else if(ct(t)||at(t))t.forEach(n=>{j(n,e,r);});else if(It(t))for(let n in t)j(t[n],e,r);return t}function Oe(t){let{state:e,getters:r,actions:n}=t,s=D({},e!=null?e:{}),i=W(e!=null?e:{}),o=[],a=[],d=D({state:i},{patch$(c){Object.assign(i,c),o.forEach(u=>u(i)),a.forEach(u=>u(i));},subscribe$(c){o.push(c);},unsubscribe$(c){let u=o.indexOf(c);u!==-1&&o.splice(u,1);},onAction$(c){a.push(c);},reset$(){Object.assign(i,s);}});for(let c in r){let u=r[c];u&&Object.defineProperty(d,c,{get(){return de(u.bind(i,i)).value},enumerable:!0,configurable:!0});}for(let c in n){let u=n[c];u&&(d[c]=u.bind(i));}return d}function tr(t){return function(){return Oe(t)}}var Pe=Object.defineProperty,Bt=Object.getOwnPropertySymbols,je=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable,Ut=(t,e,r)=>e in t?Pe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xe=(t,e)=>{for(var r in e||(e={}))je.call(e,r)&&Ut(t,r,e[r]);if(Bt)for(var r of Bt(e))Ae.call(e,r)&&Ut(t,r,e[r]);return t},dt=class H{constructor(){this.hooks={mounted:new Set,destroy:new Set};}addEventListener(){}removeEventListener(){}addHook(e,r){var n;(n=this.hooks[e])==null||n.add(r);}getContext(e){return H.context[e]}setContext(e,r){H.context[e]=r;}initRef(){H.ref=this;}removeRef(){H.ref=null;}};dt.ref=null;dt.context={};var E=dt,mt=class extends E{constructor(t,e,r){super(),this.template=t,this.props=e,this.key=r,this.proxyProps={},this.emitter=new Set,this.mounted=!1,this.rootNode=null,this.context={},this.trackMap=new Map,this.proxyProps=zt(e,n=>w(n,"on")||w(n,"update")),this.key=this.key||e.key;}get firstChild(){var t,e;return (e=(t=this.rootNode)==null?void 0:t.firstChild)!=null?e:null}get isConnected(){var t,e;return (e=(t=this.rootNode)==null?void 0:t.isConnected)!=null?e:!1}inheritNode(t){this.context=t.context,this.hooks=t.hooks,Object.assign(this.proxyProps,t.proxyProps),this.rootNode=t.rootNode,this.trackMap=t.trackMap;let e=this.props;this.props=t.props,this.patchProps(e);}mount(t,e){var r,n,s,i;if(!b(this.template))throw new Error("Template must be a function");if(this.isConnected)return (n=(r=this.rootNode)==null?void 0:r.mount(t,e))!=null?n:[];this.initRef(),this.rootNode=this.template(W(this.proxyProps,["children"])),this.removeRef(),this.mounted=!0;let o=(i=(s=this.rootNode)==null?void 0:s.mount(t,e))!=null?i:[];return this.hooks.mounted.forEach(a=>a()),this.patchProps(this.props),o}unmount(){var t;this.hooks.destroy.forEach(e=>e()),Object.values(this.hooks).forEach(e=>e.clear()),(t=this.rootNode)==null||t.unmount(),this.rootNode=null,this.proxyProps={},this.mounted=!1,this.emitter.forEach(e=>e());}getNodeTrack(t,e){let r=this.trackMap.get(t);return r||(r={cleanup:()=>{}},this.trackMap.set(t,r)),e||r.cleanup(),r}patchProps(t){var e,r,n,s;for(let[i,o]of Object.entries(t))if(w(i,"on")&&((e=this.rootNode)!=null&&e.nodes)){let a=i.slice(2).toLowerCase(),l=o,d=N(this.rootNode.nodes[0],a,l);this.emitter.add(d);}else if(i==="ref")t[i].value=(r=this.rootNode)==null?void 0:r.nodes[0];else if(w(i,"update"))t[i]=p(o)?o.value:o;else if(i!=="children"){let a=(s=(n=this.proxyProps)[i])!=null?s:n[i]=J(o),l=this.getNodeTrack(i);l.cleanup=T(()=>{a.value=b(o)?o():o;});}this.props=t;}};function cr(t,e,r){return X(t)&&(Ie(t)&&(t=We(t),e={1:e}),t===""&&(e={0:e}),t=ke(t)),b(t)?new mt(t,e,r):new Vt(t,e,r)}function ar(t){return t instanceof mt}function S(t){return t instanceof mt||t instanceof Vt}function ke(t){let e=document.createElement("template");return e.innerHTML=Le(t),e}function ur(t){return t.children}var Xt="area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr",Re="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";function Dt(t){if(S(t)||t instanceof Node)return t;let e=Y(t)?"":String(t);return document.createTextNode(e)}function C(t,e,r=null){let n=S(r)?r.firstChild:r;S(e)?e.mount(t,n):n?n.before(e):t.append(e);}function F(t){S(t)?t.unmount():t.parentNode&&t.remove();}function Yt(t,e,r){C(t,e,r),F(r);}function Jt(t,e,r){if(e==="class"){typeof r=="string"?t.className=r:Array.isArray(r)?t.className=r.join(" "):r&&typeof r=="object"&&(t.className=Object.entries(r).reduce((n,[s,i])=>n+(i?` ${s}`:""),"").trim());return}if(e==="style"){if(typeof r=="string")t.style.cssText=r;else if(r&&typeof r=="object"){let n=r;Object.keys(n).forEach(s=>{t.style.setProperty(wt(s),String(n[s]));});}return}Y(r)?t.removeAttribute(e):r===!0?t.setAttribute(e,""):t instanceof HTMLInputElement?t.value=String(r):t.setAttribute(e,String(r));}function $e(t,e){if(t instanceof HTMLInputElement)switch(t.type){case"checkbox":return N(t,"change",()=>{e(!!t.checked);});case"date":return N(t,"change",()=>{e(t.value?t.value:"");});case"file":return N(t,"change",()=>{t.files&&e(t.files);});case"number":return N(t,"input",()=>{let r=Number.parseFloat(t.value);e(Number.isNaN(r)?"":String(r));});case"radio":return N(t,"change",()=>{e(t.checked?t.value:"");});case"text":return N(t,"input",()=>{e(t.value);})}if(t instanceof HTMLSelectElement)return N(t,"change",()=>{e(t.value);});if(t instanceof HTMLTextAreaElement)return N(t,"input",()=>{e(t.value);})}var Gt=Promise.resolve();function lr(t){return t?Gt.then(t):Gt}function N(t,e,r){return t.addEventListener(e,r),()=>t.removeEventListener(e,r)}function Le(t){let e=Xt.split(","),r=[],n=[],s=/<\/?([\da-z-]+)([^>]*)>/gi,i=0;for(;;){let o=s.exec(t);if(!o)break;let[a,l]=o,d=a[1]==="/";if(n.push(t.slice(i,o.index)),i=o.index+a.length,d){for(;r.length>0&&r[r.length-1]!==l;){let c=r.pop();c&&n.push(`</${c}>`);}r.length>0&&r.pop();}else e.includes(l)||r.push(l);n.push(a);}for(n.push(t.slice(i));r.length>0;){let o=r.pop();o&&n.push(`</${o}>`);}return n.join("")}function Ie(t){return Re.split(",").includes(t)}function We(t){return Xt.split(",").includes(t)?`<${t}/>`:`<${t}></${t}>`}function He(t,e,r,n){let s=new Map,i=Array.from(e.values()),o=i.length;if(e.size>0&&r.length===0){if(t.childNodes.length===o+(n?1:0))t.innerHTML="",n&&C(t,n);else {let c=document.createRange(),u=i[0],m=S(u)?u.firstChild:u;c.setStartBefore(m),n?c.setEndBefore(n):c.setEndAfter(t),c.deleteContents();}return i.forEach(c=>{S(c)&&c.unmount();}),s}let a=[],l=Ke(r),d=0;for(let[c,u]of r.entries()){let m=i[d],P=G(m,c);for(;m&&!l.has(P);)F(m),e.delete(P),m=i[++d],P=G(m,c);let gt=G(u,c),Q=e.get(gt);if(Q&&(u=Fe(t,Q,u)),m)if(m===Q)d++;else {let vt=document.createComment("");C(t,vt,m),a.push([vt,u]);}else C(t,u,n);s.set(gt,u);}return a.forEach(([c,u])=>Yt(t,u,c)),e.forEach((c,u)=>{c.isConnected&&!s.has(u)&&F(c);}),s}function Fe(t,e,r){return e===r?e:S(e)&&S(r)&&e.template===r.template?(r.inheritNode(e),r):e instanceof Text&&r instanceof Text?(e.textContent!==r.textContent&&(e.textContent=r.textContent),e):(Yt(t,r,e),r)}function Ke(t){let e=new Map;for(let[r,n]of t.entries()){let s=G(n,r);e.set(s,n);}return e}function G(t,e){if(S(t)){let r=t.key;if(r!=null)return String(r)}return `_$${e}$`}var Vt=class te{constructor(e,r,n){this.template=e,this.props=r,this.key=n,this.treeMap=new Map,this.mounted=!1,this.nodes=[],this.provides={},this.trackMap=new Map,this.parent=null,this.key=this.key||r.key;}get firstChild(){var e;return (e=this.nodes[0])!=null?e:null}get isConnected(){return this.mounted}addEventListener(){}removeEventListener(){}mount(e,r){var n;if(this.parent=e,this.isConnected)return this.nodes.forEach(o=>C(e,o,r)),this.nodes;let s=this.template.content.cloneNode(!0),i=s.firstChild;return (n=i==null?void 0:i.hasAttribute)!=null&&n.call(i,"_svg_")&&(i.remove(),i==null||i.childNodes.forEach(o=>{s.append(o);})),this.nodes=Array.from(s.childNodes),this.mapNodeTree(e,s),C(e,s,r),this.patchNodes(this.props),this.mounted=!0,this.nodes}unmount(){this.trackMap.forEach(e=>{var r,n;(r=e.cleanup)==null||r.call(e),(n=e.lastNodes)==null||n.forEach(s=>{e.isRoot?F(s):s instanceof te&&s.unmount();});}),this.trackMap.clear(),this.treeMap.clear(),this.nodes.forEach(e=>F(e)),this.nodes=[],this.mounted=!1;}mapNodeTree(e,r){let n=1;this.treeMap.set(0,e);let s=i=>{i.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&this.treeMap.set(n++,i);let o=i.firstChild;for(;o;)s(o),o=o.nextSibling;};s(r);}patchNodes(e){for(let r in e){let n=Number(r),s=this.treeMap.get(n);if(s){let i=this.props[r];this.patchNode(r,s,i,n===0);}}this.props=e;}getNodeTrack(e,r,n){var s;let i=this.trackMap.get(e);return i||(i={cleanup:()=>{}},r&&(i.lastNodes=new Map),n&&(i.isRoot=!0),this.trackMap.set(e,i)),(s=i.cleanup)==null||s.call(i),i}inheritNode(e){this.mounted=e.mounted,this.nodes=e.nodes,this.trackMap=e.trackMap,this.treeMap=e.treeMap;let r=this.props;this.props=e.props,this.patchNodes(r);}patchNode(e,r,n,s){for(let i in n)if(i==="children"&&n.children)if(q(n.children))n.children.filter(Boolean).forEach((o,a)=>{var l;let[d,c]=q(o)?o:[o,null],u=St(c)?null:(l=this.treeMap.get(c))!=null?l:null,m=`${e}:${i}:${a}`,P=this.getNodeTrack(m,!0,s);Qt(P,r,d,u);});else {let o=`${e}:${i}:0`,a=this.getNodeTrack(o,!0,s);Qt(a,r,n.children,null);}else if(i==="ref")n[i].value=r;else if(w(i,"on")){let o=i.slice(2).toLocaleLowerCase(),a=this.getNodeTrack(`${e}:${i}`),l=n[i];a.cleanup=N(r,o,l);}else if(!w(i,"update")){let o=this.getNodeTrack(`${e}:${i}`),a=n[i],l=p(a)?a:J(a);Zt(o,r,i,l.value);let d=T(()=>{l.value=p(a)?a.value:a,Zt(o,r,i,l.value);}),c,u=`update${Ct(i)}`;n[u]&&(c=$e(r,m=>{n[u](m);})),o.cleanup=()=>{d&&d(),c&&c();};}}};function Zt(t,e,r,n){let s=e;s.setAttribute&&(b(n)?t.cleanup=T(()=>{Jt(s,r,n());}):Jt(s,r,n));}function Qt(t,e,r,n){b(r)?t.cleanup=T(()=>{let s=z(r()).map(Dt);t.lastNodes=He(e,t.lastNodes,s,n);}):z(r).forEach((s,i)=>{let o=Dt(s);t.lastNodes.set(String(i),o),C(e,o,n);});}function fr(t){var e;Z("onMounted"),(e=E.ref)==null||e.addHook("mounted",t);}function hr(t){var e;Z("onDestroy"),(e=E.ref)==null||e.addHook("destroy",t);}function Z(t,e){E.ref||console.error(`"${t}"(key: ${Nt(e)?e.toString():e}) can only be called within the component function body
9
+ and cannot be used in asynchronous or deferred calls.`);}function pr(t,e){var r;Z("useProvide",t),(r=E.ref)==null||r.setContext(t,e);}function dr(t,e){var r;return Z("useInject",t),((r=E.ref)==null?void 0:r.getContext(t))||e}function mr(){return Kt(null)}function qe(t){return Object.entries(t).map(([e,r])=>e==="children"||b(r)?"":`${e}="${_t(String(r))}"`).filter(Boolean).join(" ")}function ze(t){Object.keys(t).forEach(e=>{b(t[e])&&delete t[e],p(t[e])&&(t[e]=t[e].value);});}function Be(t,e,r,n,s,i){if(p(t))n.template+=t.value;else if(t instanceof ee){let o=i?String(i):`${r}`;s[o]||(s[o]=[]);let a=t.mount();s[o].push(b(a)?a(e):p(a)?a.value:a);}else n.template+=b(t)?t(e):String(t);}var ee=class pt extends E{constructor(e,r={},n){super(),this.template=e,this.props=r,this.key=n,this.childNodesMap={},this.processedTemplates={};}mount(){this.initRef();let e=this.render();return this.removeRef(),e}initTemplates(){let e=Array.isArray(this.template)?this.template.reduce((r,n,s)=>(r[s+1]={template:n},r),{}):this.template;yt(e)&&Object.entries(e).forEach(([r,n])=>{let s=xe({},this.props[r]);ze(s),s.children&&s.children.forEach(i=>{let[o,a]=q(i)?i:[i,null];if(b(o)){let l=o(s);Be(l,s,r,n,this.childNodesMap,a);}else n.template+=p(o)?o.value:String(o);}),this.processedTemplates[r]={template:n.template,props:s};});}render(){if(b(this.template)){let e=this.template(this.props);return e instanceof pt?e.mount():String(e)}return this.template instanceof pt?this.template.mount():(this.initTemplates(),Object.entries(this.processedTemplates).map(([e,{template:r,props:n}])=>{let s=r;return n&&Object.keys(n).length>0&&(s+=` ${qe(n)}`),this.childNodesMap[e]&&(s=s.replace("<!>",this.renderChildren(this.childNodesMap[e]))),s}).join(""))}renderChildren(e){return z(e).map(String).join("")}};function Ue(t,e){return new ee(t,e)}function gr(t,e){return Ue(t,e).mount()}globalThis&&(globalThis.__essor_version__=bt);/**
10
+ * @estjs/shared v0.0.12
1376
11
  * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
1377
12
  * @license MIT
1378
13
  **/
1379
14
  /**
1380
- * @estjs/signal v0.0.12-beta.1
15
+ * @estjs/signal v0.0.12
1381
16
  * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
1382
17
  * @license MIT
1383
18
  **/
1384
19
  /**
1385
- * @estjs/template v0.0.12-beta.1
20
+ * @estjs/template v0.0.12
1386
21
  * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
1387
22
  * @license MIT
1388
23
  **/
1389
24
 
1390
- exports.ComponentNode = ComponentNode;
1391
- exports.Fragment = Fragment;
1392
- exports.TemplateNode = TemplateNode;
1393
- exports.createStore = createStore;
1394
- exports.essor_version = essor_version;
1395
- exports.h = h;
1396
- exports.isComponent = isComponent;
1397
- exports.isComputed = isComputed;
1398
- exports.isJsxElement = isJsxElement;
1399
- exports.isReactive = isReactive;
1400
- exports.isSignal = isSignal;
1401
- exports.nextTick = nextTick2;
1402
- exports.onDestroy = onDestroy;
1403
- exports.onMount = onMount;
1404
- exports.renderToString = renderToString;
1405
- exports.shallowReactive = shallowReactive;
1406
- exports.shallowSignal = shallowSignal;
1407
- exports.signalObject = signalObject;
1408
- exports.ssg = ssg;
1409
- exports.template = template;
1410
- exports.unReactive = unReactive;
1411
- exports.unSignal = unSignal;
1412
- exports.useComputed = useComputed;
1413
- exports.useEffect = useEffect;
1414
- exports.useInject = useInject;
1415
- exports.useProvide = useProvide;
1416
- exports.useReactive = useReactive;
1417
- exports.useRef = useRef;
1418
- exports.useSignal = useSignal;
1419
- exports.useWatch = useWatch;
25
+ exports.ComponentNode = mt;
26
+ exports.Fragment = ur;
27
+ exports.TemplateNode = Vt;
28
+ exports.clearReactive = Ye;
29
+ exports.createStore = tr;
30
+ exports.essor_version = bt;
31
+ exports.h = cr;
32
+ exports.isComponent = ar;
33
+ exports.isComputed = qt;
34
+ exports.isJsxElement = S;
35
+ exports.isReactive = O;
36
+ exports.isSignal = p;
37
+ exports.nextTick = lr;
38
+ exports.onDestroy = hr;
39
+ exports.onMount = fr;
40
+ exports.renderToString = gr;
41
+ exports.shallowReactive = Xe;
42
+ exports.shallowSignal = Kt;
43
+ exports.signalObject = zt;
44
+ exports.ssg = Ue;
45
+ exports.template = ke;
46
+ exports.unReactive = h;
47
+ exports.unSignal = ge;
48
+ exports.useBatch = _e;
49
+ exports.useComputed = de;
50
+ exports.useEffect = T;
51
+ exports.useInject = dr;
52
+ exports.useProvide = pr;
53
+ exports.useReactive = W;
54
+ exports.useRef = mr;
55
+ exports.useSignal = J;
56
+ exports.useWatch = Ve;
1420
57
  //# sourceMappingURL=essor.cjs.js.map
1421
58
  //# sourceMappingURL=essor.cjs.js.map