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