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