essor 0.0.8 → 0.0.10-beta.21

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,5 +1,46 @@
1
1
  'use strict';
2
2
 
3
+ /**
4
+ * essor v0.0.10-beta.20
5
+ * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
6
+ * @license MIT
7
+ **/
8
+
9
+ // src/version.ts
10
+ var essor_version = "0.0.10-beta.20";
11
+
12
+ // ../shared/dist/essor-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 isNil(x) {
19
+ return x === null || x === void 0;
20
+ }
21
+ var isFunction = (val) => typeof val === "function";
22
+ function isFalsy(x) {
23
+ return x === false || x === null || x === void 0;
24
+ }
25
+ function coerceArray(data) {
26
+ return Array.isArray(data) ? data.flat() : [data];
27
+ }
28
+ function startsWith(str, searchString) {
29
+ if (!isString(str)) {
30
+ return false;
31
+ }
32
+ return str.indexOf(searchString) === 0;
33
+ }
34
+ var kebabCase = (string) => {
35
+ return string.replaceAll(/[A-Z]+/g, (match, offset) => {
36
+ return `${offset > 0 ? "-" : ""}${match.toLocaleLowerCase()}`;
37
+ });
38
+ };
39
+ var capitalizeFirstLetter = (inputString) => {
40
+ return inputString.charAt(0).toUpperCase() + inputString.slice(1);
41
+ };
42
+
43
+ // ../signal/dist/signal.dev.esm.js
3
44
  var __defProp = Object.defineProperty;
4
45
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
46
  var __hasOwnProp = Object.prototype.hasOwnProperty;
@@ -16,156 +57,47 @@ var __spreadValues = (a, b) => {
16
57
  }
17
58
  return a;
18
59
  };
19
-
20
- // src/version.ts
21
- var essor_version = "0.0.7";
22
-
23
- // ../shared/dist/essor-shared.js
24
- var isObject = (val) => val !== null && typeof val === "object";
25
- var isArray = Array.isArray;
26
- function isString(val) {
60
+ var isObject2 = (val) => val !== null && typeof val === "object";
61
+ var isArray2 = Array.isArray;
62
+ function isString2(val) {
27
63
  return typeof val === "string";
28
64
  }
29
65
  function isNull(val) {
30
66
  return val === null;
31
67
  }
32
- function isNil(x) {
33
- return x === null || x === void 0;
68
+ function isSet(val) {
69
+ return _toString.call(val) === "[object Set]";
34
70
  }
35
- var isFunction = (val) => typeof val === "function";
36
- function isFalsy(x) {
37
- return x === false || x === null || x === void 0 || x === "";
71
+ function isWeakMap(val) {
72
+ return _toString.call(val) === "[object WeakMap]";
73
+ }
74
+ function isWeakSet(val) {
75
+ return _toString.call(val) === "[object WeakSet]";
38
76
  }
77
+ function isMap(val) {
78
+ return _toString.call(val) === "[object Map]";
79
+ }
80
+ var isFunction2 = (val) => typeof val === "function";
39
81
  var isPrimitive = (val) => ["string", "number", "boolean", "symbol", "undefined"].includes(typeof val) || isNull(val);
40
82
  function isHTMLElement(obj) {
41
83
  if (!obj) return false;
42
84
  return obj && typeof obj === "object" && obj.nodeType === 1 && typeof obj.nodeName === "string";
43
85
  }
44
- function coerceArray(data) {
45
- return Array.isArray(data) ? data.flat() : [data];
46
- }
86
+ var _toString = Object.prototype.toString;
47
87
  var hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue);
48
- var noop = Function.prototype;
49
- function startsWith(str, searchString) {
50
- if (!isString(str)) {
88
+ var noop2 = Function.prototype;
89
+ function startsWith2(str, searchString) {
90
+ if (!isString2(str)) {
51
91
  return false;
52
92
  }
53
93
  return str.indexOf(searchString) === 0;
54
94
  }
55
- function deepClone(obj, hash = /* @__PURE__ */ new WeakMap()) {
56
- if (obj === null || typeof obj !== "object") {
57
- return obj;
58
- }
59
- if (hash.has(obj)) {
60
- return hash.get(obj);
61
- }
62
- if (obj instanceof Date) {
63
- return new Date(obj);
64
- }
65
- if (obj instanceof RegExp) {
66
- return new RegExp(obj);
67
- }
68
- if (obj instanceof Map) {
69
- const mapClone = /* @__PURE__ */ new Map();
70
- hash.set(obj, mapClone);
71
- obj.forEach((value, key) => {
72
- mapClone.set(deepClone(key, hash), deepClone(value, hash));
73
- });
74
- return mapClone;
75
- }
76
- if (obj instanceof Set) {
77
- const setClone = /* @__PURE__ */ new Set();
78
- hash.set(obj, setClone);
79
- obj.forEach((value) => {
80
- setClone.add(deepClone(value, hash));
81
- });
82
- return setClone;
83
- }
84
- const cloneObj = Array.isArray(obj) ? [] : {};
85
- hash.set(obj, cloneObj);
86
- const keys = Object.keys(obj);
87
- for (const key of keys) {
88
- cloneObj[key] = deepClone(obj[key], hash);
89
- }
90
- return cloneObj;
91
- }
92
- function deepEqual(a, b, seen = /* @__PURE__ */ new WeakMap()) {
93
- if (isPrimitive(a) && isPrimitive(b)) {
94
- return a === b;
95
- }
96
- if (a === b) {
97
- return true;
98
- }
99
- if (a == null || b == null || typeof a !== "object" || typeof b !== "object") {
100
- return false;
101
- }
102
- if (a.constructor !== b.constructor) {
103
- return false;
104
- }
105
- if (seen.has(a)) {
106
- return seen.get(a) === b;
107
- }
108
- seen.set(a, b);
109
- if (Array.isArray(a)) {
110
- if (a.length !== b.length) {
111
- return false;
112
- }
113
- for (const [i, element] of a.entries()) {
114
- if (!deepEqual(element, b[i], seen)) {
115
- return false;
116
- }
117
- }
118
- return true;
119
- }
120
- if (a instanceof Map) {
121
- if (a.size !== b.size) {
122
- return false;
123
- }
124
- for (const [key, value] of a) {
125
- if (!b.has(key) || !deepEqual(value, b.get(key), seen)) {
126
- return false;
127
- }
128
- }
129
- return true;
130
- }
131
- if (a instanceof Set) {
132
- if (a.size !== b.size) {
133
- return false;
134
- }
135
- const arrA = Array.from(a).sort();
136
- const arrB = Array.from(b).sort();
137
- for (const [i, element] of arrA.entries()) {
138
- if (!deepEqual(element, arrB[i], seen)) {
139
- return false;
140
- }
141
- }
142
- return true;
143
- }
144
- const keysA = Object.keys(a);
145
- const keysB = new Set(Object.keys(b));
146
- if (keysA.length !== keysB.size) {
147
- return false;
148
- }
149
- for (const key of keysA) {
150
- if (!keysB.has(key) || !deepEqual(a[key], b[key], seen)) {
151
- return false;
152
- }
153
- }
154
- return true;
155
- }
156
95
  function isExclude(key, exclude) {
157
- return Array.isArray(exclude) ? exclude.includes(key) : isFunction(exclude) ? exclude(key) : false;
96
+ return Array.isArray(exclude) ? exclude.includes(key) : isFunction2(exclude) ? exclude(key) : false;
97
+ }
98
+ function warn(msg, ...args) {
99
+ console.warn.apply(console, [`[Essor warn]: ${msg}`].concat(args));
158
100
  }
159
- var kebabCase = (string) => {
160
- return string.replaceAll(/[A-Z]+/g, (match, offset) => {
161
- return `${offset > 0 ? "-" : ""}${match.toLocaleLowerCase()}`;
162
- });
163
- };
164
- var capitalizeFirstLetter = (inputString) => {
165
- return inputString.charAt(0).toUpperCase() + inputString.slice(1);
166
- };
167
-
168
- // src/signal/signal.ts
169
101
  var activeEffect = null;
170
102
  var activeComputed = null;
171
103
  var computedMap = /* @__PURE__ */ new WeakMap();
@@ -216,32 +148,30 @@ function trigger(target, key) {
216
148
  }
217
149
  }
218
150
  var Signal = class {
219
- constructor(value) {
151
+ constructor(value, shallow = false) {
220
152
  this._value = value;
153
+ this._shallow = shallow;
221
154
  }
222
- valueOf() {
223
- track(this, "_sv");
224
- this.__triggerObject();
225
- return this._value;
226
- }
227
- toString() {
228
- track(this, "_sv");
229
- this.__triggerObject();
230
- return String(this._value);
231
- }
232
- toJSON() {
233
- return this._value;
234
- }
155
+ /**
156
+ * Get the current value of the Signal and track its usage.
157
+ */
235
158
  get value() {
236
159
  track(this, "_sv");
237
160
  this.__triggerObject();
238
161
  return this._value;
239
162
  }
163
+ /**
164
+ * Trigger reactivity for non-primitive and non-HTMLElement values.
165
+ * Recursively applies reactivity to nested objects.
166
+ */
240
167
  __triggerObject() {
241
- if (!isPrimitive(this._value) && !isHTMLElement(this._value)) {
168
+ if (!isPrimitive(this._value) && !isHTMLElement(this._value) && !this._shallow) {
242
169
  useReactive(this._value);
243
170
  }
244
171
  }
172
+ /**
173
+ * Set a new value to the Signal and trigger updates if the value has changed.
174
+ */
245
175
  set value(newValue) {
246
176
  if (isSignal(newValue)) {
247
177
  console.warn("Signal cannot be set to another signal, use .peek() instead");
@@ -255,12 +185,12 @@ var Signal = class {
255
185
  trigger(this, "_sv");
256
186
  }
257
187
  }
188
+ /**
189
+ * Peek at the current value of the Signal without tracking it.
190
+ */
258
191
  peek() {
259
192
  return this._value;
260
193
  }
261
- update() {
262
- trigger(this, "_sv");
263
- }
264
194
  };
265
195
  function useSignal(value) {
266
196
  if (isSignal(value)) {
@@ -268,6 +198,9 @@ function useSignal(value) {
268
198
  }
269
199
  return new Signal(value);
270
200
  }
201
+ function shallowSignal(value) {
202
+ return new Signal(value, true);
203
+ }
271
204
  function isSignal(value) {
272
205
  return value instanceof Signal;
273
206
  }
@@ -279,9 +212,15 @@ var Computed = class {
279
212
  this._value = this.fn();
280
213
  activeComputed = prev;
281
214
  }
215
+ /**
216
+ * Get the current computed value without tracking it.
217
+ */
282
218
  peek() {
283
219
  return this._value;
284
220
  }
221
+ /**
222
+ * Run the computed function and update the value if it has changed.
223
+ */
285
224
  run() {
286
225
  const newValue = this.fn();
287
226
  if (hasChanged(newValue, this._value)) {
@@ -289,6 +228,9 @@ var Computed = class {
289
228
  trigger(this, "_cv");
290
229
  }
291
230
  }
231
+ /**
232
+ * Get the current computed value and track its usage.
233
+ */
292
234
  get value() {
293
235
  track(this, "_cv");
294
236
  return this._value;
@@ -326,15 +268,15 @@ function unSignal(signal, exclude) {
326
268
  if (isSignal(signal)) {
327
269
  return signal.peek();
328
270
  }
329
- if (isArray(signal)) {
271
+ if (isArray2(signal)) {
330
272
  return signal.map((value) => unSignal(value, exclude));
331
273
  }
332
- if (isObject(signal)) {
274
+ if (isObject2(signal)) {
333
275
  return Object.entries(signal).reduce((acc, [key, value]) => {
334
276
  if (isExclude(key, exclude)) {
335
277
  acc[key] = value;
336
278
  } else {
337
- acc[key] = isSignal(value) ? value.peek() : value;
279
+ acc[key] = isSignal(value) ? value.peek() : isReactive(value) ? unReactive(value) : value;
338
280
  }
339
281
  return acc;
340
282
  }, {});
@@ -351,8 +293,32 @@ function unReactive(obj) {
351
293
  }
352
294
  return __spreadValues({}, obj);
353
295
  }
296
+ function createArrayProxy(initialValue) {
297
+ arrayMethods.forEach((method) => {
298
+ const originalMethod = Array.prototype[method];
299
+ track(initialValue, "length");
300
+ Object.defineProperty(initialValue, method, {
301
+ value(...args) {
302
+ const result = originalMethod.apply(this, args);
303
+ if (["push", "pop", "shift", "unshift", "splice", "sort", "reverse"].includes(method)) {
304
+ trigger(initialValue, "length");
305
+ }
306
+ return result;
307
+ },
308
+ enumerable: false,
309
+ writable: true,
310
+ configurable: true
311
+ });
312
+ });
313
+ }
354
314
  function useReactive(initialValue, exclude) {
355
- if (!isObject(initialValue)) {
315
+ return reactive(initialValue, exclude, false);
316
+ }
317
+ function shallowReactive(initialValue, exclude) {
318
+ return reactive(initialValue, exclude, true);
319
+ }
320
+ function reactive(initialValue, exclude, shallow = false) {
321
+ if (!isObject2(initialValue)) {
356
322
  return initialValue;
357
323
  }
358
324
  if (isReactive(initialValue)) {
@@ -362,33 +328,21 @@ function useReactive(initialValue, exclude) {
362
328
  return reactiveMap.get(initialValue);
363
329
  }
364
330
  if (Array.isArray(initialValue)) {
365
- arrayMethods.forEach((method) => {
366
- const originalMethod = initialValue[method];
367
- track(initialValue, "length");
368
- Object.defineProperties(initialValue, {
369
- [method]: {
370
- value(...args) {
371
- const result = originalMethod.apply(this, args);
372
- trigger(initialValue, "length");
373
- return result;
374
- },
375
- enumerable: false,
376
- configurable: true,
377
- writable: true
378
- }
379
- });
380
- });
331
+ createArrayProxy(initialValue);
332
+ }
333
+ if (isSet(initialValue) || isMap(initialValue) || isWeakSet(initialValue) || isWeakMap(initialValue)) {
334
+ return initialValue;
381
335
  }
382
336
  const handler = {
383
337
  get(target, key, receiver) {
384
- if (key === REACTIVE_MARKER || startsWith(key, "_")) return true;
338
+ if (key === REACTIVE_MARKER || startsWith2(key, "_")) return true;
385
339
  const getValue = Reflect.get(target, key, receiver);
386
340
  const value = isSignal(getValue) ? getValue.value : getValue;
387
341
  if (isExclude(key, exclude)) {
388
342
  return value;
389
343
  }
390
344
  track(target, key);
391
- if (isObject(value)) {
345
+ if (isObject2(value) && !shallow) {
392
346
  return useReactive(value);
393
347
  }
394
348
  return value;
@@ -424,46 +378,34 @@ function useReactive(initialValue, exclude) {
424
378
  reactiveMap.set(initialValue, proxy);
425
379
  return proxy;
426
380
  }
427
-
428
- // src/warning.ts
429
- function warn(msg, ...args) {
430
- console.warn.apply(console, [`[Essor warn]: ${msg}`].concat(args));
431
- }
432
-
433
- // src/signal/watch.ts
434
381
  function useWatch(source, cb, options) {
435
382
  return doWatch(source, cb, options);
436
383
  }
437
384
  function doWatch(source, cb, options) {
438
385
  let getter;
439
- const deep = options == null ? void 0 : options.deep;
440
386
  if (isSignal(source) || isComputed(source)) {
441
387
  getter = () => source.value;
442
388
  } else if (isReactive(source)) {
443
389
  getter = () => __spreadValues({}, source);
444
- } else if (isArray(source)) {
390
+ } else if (isArray2(source)) {
445
391
  getter = () => source.map((s) => {
446
392
  if (isSignal(s) || isComputed(s)) return s.value;
447
393
  if (isReactive(s)) return __spreadValues({}, s);
448
- if (isFunction(s)) return s();
394
+ if (isFunction2(s)) return s();
449
395
  return warn("Invalid source", s);
450
396
  });
451
- } else if (isFunction(source)) {
397
+ } else if (isFunction2(source)) {
452
398
  getter = source;
453
399
  } else {
454
400
  warn("Invalid source type", source);
455
- getter = noop;
456
- }
457
- if (cb && deep) {
458
- const baseGetter = getter;
459
- getter = () => traverse(baseGetter());
401
+ getter = noop2;
460
402
  }
461
403
  let oldValue;
462
404
  const effectFn = () => {
463
- const newValue = deepClone(getter());
464
- if (!deepEqual(newValue, oldValue)) {
405
+ const newValue = getter();
406
+ if ((options == null ? void 0 : options.deep) || hasChanged(newValue, oldValue)) {
465
407
  cb && cb(newValue, oldValue);
466
- oldValue = isPrimitive(newValue) ? newValue : deepClone(newValue);
408
+ oldValue = newValue;
467
409
  }
468
410
  };
469
411
  const stop = useEffect(effectFn);
@@ -472,35 +414,12 @@ function doWatch(source, cb, options) {
472
414
  }
473
415
  return stop;
474
416
  }
475
- function traverse(value, seen = /* @__PURE__ */ new Set()) {
476
- if (!isObject(value) || seen.has(value)) return value;
477
- seen.add(value);
478
- if (isArray(value)) {
479
- value.forEach((item) => traverse(item, seen));
480
- } else if (value instanceof Map) {
481
- value.forEach((v, k) => {
482
- traverse(k, seen);
483
- traverse(v, seen);
484
- });
485
- } else if (value instanceof Set) {
486
- value.forEach((v) => traverse(v, seen));
487
- } else {
488
- Object.keys(value).forEach((key) => {
489
- traverse(value[key], seen);
490
- });
491
- }
492
- return value;
493
- }
494
-
495
- // src/signal/store.ts
496
417
  var _id = 0;
497
418
  var StoreMap = /* @__PURE__ */ new Map();
498
419
  function createOptionsStore(options) {
499
420
  const { state, getters, actions } = options;
500
421
  const initState = __spreadValues({}, state != null ? state : {});
501
- const reactiveState = useReactive(state != null ? state : {}, (val) => {
502
- return isFunction(val);
503
- });
422
+ const reactiveState = useReactive(state != null ? state : {});
504
423
  const subscriptions = [];
505
424
  const actionCallbacks = [];
506
425
  const default_actions = {
@@ -531,7 +450,9 @@ function createOptionsStore(options) {
531
450
  for (const key in getters) {
532
451
  const getter = getters[key];
533
452
  if (getter) {
534
- store[key] = useComputed(getter.bind(reactiveState, reactiveState));
453
+ useWatch(useComputed(getter.bind(reactiveState, reactiveState)), (value) => {
454
+ store[key] = value;
455
+ });
535
456
  }
536
457
  }
537
458
  for (const key in actions) {
@@ -553,8 +474,8 @@ function createStore(options) {
553
474
  };
554
475
  }
555
476
 
556
- // src/template/component-node.ts
557
- var _ComponentNode = class _ComponentNode {
477
+ // ../template/dist/template.dev.esm.js
478
+ var _ComponentNode = class _ComponentNode2 {
558
479
  constructor(template2, props) {
559
480
  this.template = template2;
560
481
  this.props = props;
@@ -590,10 +511,10 @@ var _ComponentNode = class _ComponentNode {
590
511
  (_a = this.hooks[hook]) == null ? void 0 : _a.add(cb);
591
512
  }
592
513
  getContext(context) {
593
- return _ComponentNode.context[context];
514
+ return _ComponentNode2.context[context];
594
515
  }
595
516
  setContext(context, value) {
596
- _ComponentNode.context[context] = value;
517
+ _ComponentNode2.context[context] = value;
597
518
  }
598
519
  inheritNode(node) {
599
520
  this.context = node.context;
@@ -605,17 +526,6 @@ var _ComponentNode = class _ComponentNode {
605
526
  this.props = node.props;
606
527
  this.patchProps(props);
607
528
  }
608
- unmount() {
609
- var _a;
610
- this.hooks.destroy.forEach((handler) => handler());
611
- Object.values(this.hooks).forEach((set) => set.clear());
612
- (_a = this.rootNode) == null ? void 0 : _a.unmount();
613
- this.rootNode = null;
614
- this.proxyProps = {};
615
- this.mounted = false;
616
- this.emitter.forEach((emitter) => emitter());
617
- _ComponentNode.context = {};
618
- }
619
529
  mount(parent, before) {
620
530
  var _a, _b, _c, _d;
621
531
  if (!isFunction(this.template)) {
@@ -624,15 +534,25 @@ var _ComponentNode = class _ComponentNode {
624
534
  if (this.isConnected) {
625
535
  return (_b = (_a = this.rootNode) == null ? void 0 : _a.mount(parent, before)) != null ? _b : [];
626
536
  }
627
- _ComponentNode.ref = this;
537
+ _ComponentNode2.ref = this;
628
538
  this.rootNode = this.template(useReactive(this.proxyProps, ["children"]));
629
- _ComponentNode.ref = null;
539
+ _ComponentNode2.ref = null;
630
540
  this.mounted = true;
631
541
  const mountedNode = (_d = (_c = this.rootNode) == null ? void 0 : _c.mount(parent, before)) != null ? _d : [];
632
542
  this.hooks.mounted.forEach((handler) => handler());
633
543
  this.patchProps(this.props);
634
544
  return mountedNode;
635
545
  }
546
+ unmount() {
547
+ var _a;
548
+ this.hooks.destroy.forEach((handler) => handler());
549
+ Object.values(this.hooks).forEach((set) => set.clear());
550
+ (_a = this.rootNode) == null ? void 0 : _a.unmount();
551
+ this.rootNode = null;
552
+ this.proxyProps = {};
553
+ this.mounted = false;
554
+ this.emitter.forEach((emitter) => emitter());
555
+ }
636
556
  getNodeTrack(trackKey, suppressCleanupCall) {
637
557
  let track2 = this.trackMap.get(trackKey);
638
558
  if (!track2) {
@@ -675,8 +595,6 @@ var _ComponentNode = class _ComponentNode {
675
595
  _ComponentNode.ref = null;
676
596
  _ComponentNode.context = {};
677
597
  var ComponentNode = _ComponentNode;
678
-
679
- // src/template/template.ts
680
598
  function h(_template, props) {
681
599
  if (isString(_template)) {
682
600
  if (isHtmlTagName(_template)) {
@@ -706,8 +624,8 @@ function template(html) {
706
624
  function Fragment(props) {
707
625
  return props.children;
708
626
  }
709
-
710
- // src/template/utils.ts
627
+ var selfClosingTags = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
628
+ 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";
711
629
  function coerceNode(data) {
712
630
  if (isJsxElement(data) || data instanceof Node) {
713
631
  return data;
@@ -766,43 +684,43 @@ function setAttribute(element, attr, value) {
766
684
  } else if (value === true) {
767
685
  element.setAttribute(attr, "");
768
686
  } else {
769
- element.setAttribute(attr, String(value));
687
+ if (element instanceof HTMLInputElement) {
688
+ element.value = String(value);
689
+ } else {
690
+ element.setAttribute(attr, String(value));
691
+ }
770
692
  }
771
693
  }
772
694
  function binNode(node, setter) {
773
695
  if (node instanceof HTMLInputElement) {
774
- if (node.type === "checkbox") {
775
- return addEventListener(node, "change", () => {
776
- setter(Boolean(node.checked));
777
- });
778
- }
779
- if (node.type === "date") {
780
- return addEventListener(node, "change", () => {
781
- setter(node.value ? node.value : "");
782
- });
783
- }
784
- if (node.type === "file") {
785
- return addEventListener(node, "change", () => {
786
- if (node.files) {
787
- setter(node.files);
788
- }
789
- });
790
- }
791
- if (node.type === "number") {
792
- return addEventListener(node, "input", () => {
793
- const value = Number.parseFloat(node.value);
794
- setter(Number.isNaN(value) ? "" : String(value));
795
- });
796
- }
797
- if (node.type === "radio") {
798
- return addEventListener(node, "change", () => {
799
- setter(node.checked ? node.value : "");
800
- });
801
- }
802
- if (node.type === "text") {
803
- return addEventListener(node, "input", () => {
804
- setter(node.value);
805
- });
696
+ switch (node.type) {
697
+ case "checkbox":
698
+ return addEventListener(node, "change", () => {
699
+ setter(Boolean(node.checked));
700
+ });
701
+ case "date":
702
+ return addEventListener(node, "change", () => {
703
+ setter(node.value ? node.value : "");
704
+ });
705
+ case "file":
706
+ return addEventListener(node, "change", () => {
707
+ if (node.files) {
708
+ setter(node.files);
709
+ }
710
+ });
711
+ case "number":
712
+ return addEventListener(node, "input", () => {
713
+ const value = Number.parseFloat(node.value);
714
+ setter(Number.isNaN(value) ? "" : String(value));
715
+ });
716
+ case "radio":
717
+ return addEventListener(node, "change", () => {
718
+ setter(node.checked ? node.value : "");
719
+ });
720
+ case "text":
721
+ return addEventListener(node, "input", () => {
722
+ setter(node.value);
723
+ });
806
724
  }
807
725
  }
808
726
  if (node instanceof HTMLSelectElement) {
@@ -824,164 +742,8 @@ function addEventListener(node, eventName, handler) {
824
742
  node.addEventListener(eventName, handler);
825
743
  return () => node.removeEventListener(eventName, handler);
826
744
  }
827
- var selfClosingTags = [
828
- "area",
829
- "base",
830
- "br",
831
- "col",
832
- "embed",
833
- "hr",
834
- "img",
835
- "input",
836
- "link",
837
- "meta",
838
- "param",
839
- "source",
840
- "track",
841
- "wbr"
842
- ];
843
- var htmlTags = [
844
- "a",
845
- "abbr",
846
- "acronym",
847
- "address",
848
- "applet",
849
- "area",
850
- "article",
851
- "aside",
852
- "audio",
853
- "b",
854
- "base",
855
- "basefont",
856
- "bdi",
857
- "bdo",
858
- "bgsound",
859
- "big",
860
- "blink",
861
- "blockquote",
862
- "body",
863
- "br",
864
- "button",
865
- "canvas",
866
- "caption",
867
- "center",
868
- "cite",
869
- "code",
870
- "col",
871
- "colgroup",
872
- "command",
873
- "content",
874
- "data",
875
- "datalist",
876
- "dd",
877
- "del",
878
- "details",
879
- "dfn",
880
- "dialog",
881
- "dir",
882
- "div",
883
- "dl",
884
- "dt",
885
- "em",
886
- "embed",
887
- "fieldset",
888
- "figcaption",
889
- "figure",
890
- "font",
891
- "footer",
892
- "form",
893
- "frame",
894
- "frameset",
895
- "h1",
896
- "h2",
897
- "h3",
898
- "h4",
899
- "h5",
900
- "h6",
901
- "head",
902
- "header",
903
- "hgroup",
904
- "hr",
905
- "html",
906
- "i",
907
- "iframe",
908
- "image",
909
- "img",
910
- "input",
911
- "ins",
912
- "kbd",
913
- "keygen",
914
- "label",
915
- "legend",
916
- "li",
917
- "link",
918
- "listing",
919
- "main",
920
- "map",
921
- "mark",
922
- "marquee",
923
- "menu",
924
- "menuitem",
925
- "meta",
926
- "meter",
927
- "nav",
928
- "nobr",
929
- "noframes",
930
- "noscript",
931
- "object",
932
- "ol",
933
- "optgroup",
934
- "option",
935
- "output",
936
- "p",
937
- "param",
938
- "picture",
939
- "plaintext",
940
- "pre",
941
- "progress",
942
- "q",
943
- "rb",
944
- "rp",
945
- "rt",
946
- "rtc",
947
- "ruby",
948
- "s",
949
- "samp",
950
- "script",
951
- "section",
952
- "select",
953
- "shadow",
954
- "small",
955
- "source",
956
- "spacer",
957
- "span",
958
- "strike",
959
- "strong",
960
- "style",
961
- "sub",
962
- "summary",
963
- "sup",
964
- "table",
965
- "tbody",
966
- "td",
967
- "template",
968
- "textarea",
969
- "tfoot",
970
- "th",
971
- "thead",
972
- "time",
973
- "title",
974
- "tr",
975
- "track",
976
- "tt",
977
- "u",
978
- "ul",
979
- "var",
980
- "video",
981
- "wbr",
982
- "xmp"
983
- ];
984
745
  function closeHtmlTags(input) {
746
+ const selfClosingTagList = selfClosingTags.split(",");
985
747
  const tagStack = [];
986
748
  const output = [];
987
749
  const tagPattern = /<\/?([\da-z-]+)([^>]*)>/gi;
@@ -989,7 +751,7 @@ function closeHtmlTags(input) {
989
751
  while (true) {
990
752
  const match = tagPattern.exec(input);
991
753
  if (!match) break;
992
- const [fullMatch, tagName, attributes] = match;
754
+ const [fullMatch, tagName] = match;
993
755
  const isEndTag = fullMatch[1] === "/";
994
756
  output.push(input.slice(lastIndex, match.index));
995
757
  lastIndex = match.index + fullMatch.length;
@@ -1002,16 +764,11 @@ function closeHtmlTags(input) {
1002
764
  }
1003
765
  if (tagStack.length > 0) {
1004
766
  tagStack.pop();
1005
- output.push(fullMatch);
1006
- }
1007
- } else {
1008
- if (selfClosingTags.includes(tagName)) {
1009
- output.push(fullMatch);
1010
- } else {
1011
- tagStack.push(tagName);
1012
- output.push(`<${tagName}${attributes}>`);
1013
767
  }
768
+ } else if (!selfClosingTagList.includes(tagName)) {
769
+ tagStack.push(tagName);
1014
770
  }
771
+ output.push(fullMatch);
1015
772
  }
1016
773
  output.push(input.slice(lastIndex));
1017
774
  while (tagStack.length > 0) {
@@ -1022,18 +779,18 @@ function closeHtmlTags(input) {
1022
779
  }
1023
780
  return output.join("");
1024
781
  }
1025
- function isHtmlTagName(str) {
1026
- return htmlTags.includes(str);
782
+ function isHtmlTagName(tagName) {
783
+ const htmlTagsList = htmlTags.split(",");
784
+ return htmlTagsList.includes(tagName);
1027
785
  }
1028
- function convertToHtmlTag(tag) {
1029
- if (selfClosingTags.includes(tag)) {
1030
- return `<${tag}/>`;
786
+ function convertToHtmlTag(tagName) {
787
+ const selfClosingTagList = selfClosingTags.split(",");
788
+ if (selfClosingTagList.includes(tagName)) {
789
+ return `<${tagName}/>`;
1031
790
  } else {
1032
- return `<${tag}></${tag}>`;
791
+ return `<${tagName}></${tagName}>`;
1033
792
  }
1034
793
  }
1035
-
1036
- // src/template/patch.ts
1037
794
  function patchChildren(parent, childrenMap, nextChildren, before) {
1038
795
  const result = /* @__PURE__ */ new Map();
1039
796
  const children = Array.from(childrenMap.values());
@@ -1131,8 +888,6 @@ function getKey(node, index) {
1131
888
  const result = id === "" ? void 0 : id;
1132
889
  return result != null ? result : `_$${index}$`;
1133
890
  }
1134
-
1135
- // src/template/template-node.ts
1136
891
  var TemplateNode = class _TemplateNode {
1137
892
  constructor(template2, props) {
1138
893
  this.template = template2;
@@ -1326,8 +1081,6 @@ function patchChild(track2, parent, child, before) {
1326
1081
  });
1327
1082
  }
1328
1083
  }
1329
-
1330
- // src/template/hooks.ts
1331
1084
  function onMount(cb) {
1332
1085
  var _a;
1333
1086
  throwIfOutsideComponent("onMounted");
@@ -1356,42 +1109,21 @@ function useInject(key, defaultValue) {
1356
1109
  throwIfOutsideComponent("useInject");
1357
1110
  return ((_a = ComponentNode.ref) == null ? void 0 : _a.getContext(key)) || defaultValue;
1358
1111
  }
1359
- function useRef() {
1360
- let refValue = null;
1361
- return new Proxy({}, {
1362
- get(target, key) {
1363
- if (key === "__is_ref") {
1364
- return true;
1365
- }
1366
- return refValue;
1367
- },
1368
- set(target, prop, value) {
1369
- if (prop === "current") {
1370
- refValue = value;
1371
- return true;
1372
- }
1373
- refValue = value;
1374
- return true;
1375
- }
1376
- });
1377
- }
1378
-
1379
- // src/server/index.ts
1380
- function jsonToAttrs(json) {
1112
+ function convertJsonToAttributes(json) {
1381
1113
  return Object.entries(json).map(([key, value]) => `${key}=${JSON.stringify(escape(String(value)))}`).join(" ");
1382
1114
  }
1383
1115
  function renderTemplate(template2, props) {
1384
1116
  if (isFunction(template2)) {
1385
1117
  return template2(props);
1386
1118
  }
1387
- const templates = Array.isArray(template2) ? template2.reduce((acc, tmpl, index) => {
1119
+ const templateCollection = Array.isArray(template2) ? template2.reduce((acc, tmpl, index) => {
1388
1120
  acc[index + 1] = { template: tmpl };
1389
1121
  return acc;
1390
1122
  }, {}) : template2;
1391
- const childrenMap = {};
1392
- const newTemplate = {};
1393
- if (isObject(templates)) {
1394
- for (const [key, tmpl] of Object.entries(templates)) {
1123
+ const childNodesMap = {};
1124
+ const processedTemplates = {};
1125
+ if (isObject(templateCollection)) {
1126
+ for (const [key, tmpl] of Object.entries(templateCollection)) {
1395
1127
  const prop = props[key];
1396
1128
  if (prop) {
1397
1129
  for (const propKey in prop) {
@@ -1401,30 +1133,30 @@ function renderTemplate(template2, props) {
1401
1133
  }
1402
1134
  if (prop.children) {
1403
1135
  for (const [child, idx] of prop.children) {
1404
- if (!childrenMap[idx]) childrenMap[idx] = [];
1405
- childrenMap[idx].push(child);
1136
+ if (!childNodesMap[idx]) childNodesMap[idx] = [];
1137
+ childNodesMap[idx].push(child);
1406
1138
  }
1407
1139
  delete prop.children;
1408
1140
  }
1409
1141
  }
1410
- newTemplate[key] = { template: tmpl.template, prop };
1142
+ processedTemplates[key] = { template: tmpl.template, props: prop };
1411
1143
  }
1412
1144
  }
1413
- return Object.entries(newTemplate).map(([key, { template: tmpl, prop }]) => {
1414
- let str = tmpl;
1145
+ return Object.entries(processedTemplates).map(([key, { template: tmpl, props: prop }]) => {
1146
+ let renderedString = tmpl;
1415
1147
  if (prop) {
1416
- str += ` ${jsonToAttrs(prop)}`;
1148
+ renderedString += ` ${convertJsonToAttributes(prop)}`;
1417
1149
  }
1418
- if (childrenMap[key]) {
1419
- str += childrenMap[key].map((child) => renderTemplate(child, prop)).join("");
1150
+ if (childNodesMap[key]) {
1151
+ renderedString += childNodesMap[key].map((child) => renderTemplate(child, prop)).join("");
1420
1152
  }
1421
- return str;
1153
+ return renderedString;
1422
1154
  }).join("");
1423
1155
  }
1424
1156
  function renderToString(component, props) {
1425
1157
  return renderTemplate(component, props);
1426
1158
  }
1427
- function ssgRender(component, root, props = {}) {
1159
+ function renderSSG(component, root, props = {}) {
1428
1160
  root.innerHTML = renderTemplate(component, props);
1429
1161
  }
1430
1162
 
@@ -1432,6 +1164,21 @@ function ssgRender(component, root, props = {}) {
1432
1164
  if (globalThis) {
1433
1165
  globalThis.__essor_version__ = essor_version;
1434
1166
  }
1167
+ /**
1168
+ * @estjs/shared v0.0.10-beta.20
1169
+ * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
1170
+ * @license MIT
1171
+ **/
1172
+ /**
1173
+ * @estjs/signal v0.0.10-beta.20
1174
+ * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
1175
+ * @license MIT
1176
+ **/
1177
+ /**
1178
+ * @estjs/template v0.0.10-beta.20
1179
+ * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
1180
+ * @license MIT
1181
+ **/
1435
1182
 
1436
1183
  exports.ComponentNode = ComponentNode;
1437
1184
  exports.Fragment = Fragment;
@@ -1446,10 +1193,12 @@ exports.isSignal = isSignal;
1446
1193
  exports.nextTick = nextTick;
1447
1194
  exports.onDestroy = onDestroy;
1448
1195
  exports.onMount = onMount;
1196
+ exports.renderSSG = renderSSG;
1449
1197
  exports.renderTemplate = renderTemplate;
1450
1198
  exports.renderToString = renderToString;
1199
+ exports.shallowReactive = shallowReactive;
1200
+ exports.shallowSignal = shallowSignal;
1451
1201
  exports.signalObject = signalObject;
1452
- exports.ssgRender = ssgRender;
1453
1202
  exports.template = template;
1454
1203
  exports.unReactive = unReactive;
1455
1204
  exports.unSignal = unSignal;
@@ -1458,6 +1207,5 @@ exports.useEffect = useEffect;
1458
1207
  exports.useInject = useInject;
1459
1208
  exports.useProvide = useProvide;
1460
1209
  exports.useReactive = useReactive;
1461
- exports.useRef = useRef;
1462
1210
  exports.useSignal = useSignal;
1463
1211
  exports.useWatch = useWatch;