@estjs/signals 0.0.15-beta.1 → 0.0.15-beta.11

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,10 +1,5 @@
1
- import { isFunction, isObject, warn, error, isPlainObject, info, hasChanged, isArray, isSet, isMap, isWeakMap, isWeakSet, isStringNumber, hasOwn } from '@estjs/shared';
1
+ import { isFunction, isObject, warn, error, isPlainObject, hasChanged, isArray, isSet, isMap, isWeakMap, isWeakSet, hasOwn, isStringNumber } from '@estjs/shared';
2
2
 
3
- /**
4
- * @estjs/signals v0.0.15-beta.1
5
- * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
6
- * @license MIT
7
- **/
8
3
  var __defProp = Object.defineProperty;
9
4
  var __defProps = Object.defineProperties;
10
5
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -32,11 +27,11 @@ var TriggerOpTypes = {
32
27
  DELETE: "DELETE",
33
28
  CLEAR: "CLEAR"
34
29
  };
35
- var SIGNAL_KEY = Symbol("Signal_Key" );
36
- var ARRAY_KEY = Symbol("Array_Key" );
37
- var COLLECTION_KEY = Symbol("Collection_Key" );
38
- var WEAK_COLLECTION_KEY = Symbol("WeakCollection_Key" );
39
- var ARRAY_ITERATE_KEY = Symbol("Array_Iterate_Key" );
30
+ var SIGNAL_KEY = /* @__PURE__ */ Symbol("Signal_Key" );
31
+ var ARRAY_KEY = /* @__PURE__ */ Symbol("Array_Key" );
32
+ var COLLECTION_KEY = /* @__PURE__ */ Symbol("Collection_Key" );
33
+ var WEAK_COLLECTION_KEY = /* @__PURE__ */ Symbol("WeakCollection_Key" );
34
+ var ARRAY_ITERATE_KEY = /* @__PURE__ */ Symbol("Array_Iterate_Key" );
40
35
 
41
36
  // src/propagation.ts
42
37
  function propagate(link) {
@@ -373,9 +368,9 @@ function trigger(target, type, key, newValue) {
373
368
  }
374
369
  }
375
370
  if (type === "ADD" || type === "DELETE" || type === "CLEAR") {
376
- const ITERATE_KEY2 = Symbol("iterate");
377
- const ARRAY_ITERATE_KEY2 = Symbol("arrayIterate");
378
- const iterationKey = Array.isArray(target) ? ARRAY_ITERATE_KEY2 : ITERATE_KEY2;
371
+ const ITERATE_KEY = /* @__PURE__ */ Symbol("iterate");
372
+ const ARRAY_ITERATE_KEY2 = /* @__PURE__ */ Symbol("arrayIterate");
373
+ const iterationKey = Array.isArray(target) ? ARRAY_ITERATE_KEY2 : ITERATE_KEY;
379
374
  const iterationDep = depsMap.get(iterationKey);
380
375
  if (iterationDep) {
381
376
  iterationDep.forEach((effect2) => effects.add(effect2));
@@ -882,44 +877,18 @@ function isReactive(target) {
882
877
  }
883
878
  function reactive(target) {
884
879
  if (isReactive(target)) {
885
- {
886
- warn(
887
- "[Reactive] Target is already reactive. Returning existing reactive proxy to avoid double wrapping."
888
- );
889
- }
890
880
  return target;
891
881
  }
892
882
  if (isSignal(target)) {
893
- {
894
- warn(
895
- "[Reactive] Creating a reactive proxy from a signal is not recommended. Use the signal directly or access its value property."
896
- );
897
- }
898
883
  return target;
899
884
  }
900
885
  return reactiveImpl(target);
901
886
  }
902
887
  function shallowReactive(target) {
903
888
  if (isReactive(target)) {
904
- {
905
- if (isShallow(target)) {
906
- warn(
907
- "[ShallowReactive] Target is already a shallow reactive proxy. Returning existing proxy to avoid double wrapping."
908
- );
909
- } else {
910
- warn(
911
- "[ShallowReactive] Target is already a deep reactive proxy. Cannot convert deep reactive to shallow reactive. Returning existing proxy."
912
- );
913
- }
914
- }
915
889
  return target;
916
890
  }
917
891
  if (isSignal(target)) {
918
- {
919
- warn(
920
- "[ShallowReactive] Creating a reactive proxy from a signal is not recommended. Use the signal directly or access its value property."
921
- );
922
- }
923
892
  return target;
924
893
  }
925
894
  return reactiveImpl(target, true);
@@ -945,7 +914,7 @@ var SignalImpl = class {
945
914
  // Mark whether it's shallow reactive
946
915
  // @ts-ignore
947
916
  this[_a] = true;
948
- this._oldValue = this._rawValue = value;
917
+ this._rawValue = value;
949
918
  if (shallow) {
950
919
  this._value = isObject(value) ? shallowReactive(value) : value;
951
920
  } else {
@@ -962,7 +931,8 @@ var SignalImpl = class {
962
931
  if (sub) {
963
932
  linkReactiveNode(this, sub);
964
933
  }
965
- if (this.flag & 16 /* DIRTY */ && this.shouldUpdate()) {
934
+ const flags = this.flag;
935
+ if (flags & 16 /* DIRTY */ && this.shouldUpdate()) {
966
936
  const subs = this.subLink;
967
937
  if (subs) {
968
938
  shallowPropagate2(subs);
@@ -984,7 +954,11 @@ var SignalImpl = class {
984
954
  if (!hasChanged(this._rawValue, value)) {
985
955
  return;
986
956
  }
987
- this.flag |= 16 /* DIRTY */;
957
+ if (!("_oldValue" in this)) {
958
+ this._oldValue = this._rawValue;
959
+ }
960
+ const flags = this.flag;
961
+ this.flag = flags | 16 /* DIRTY */;
988
962
  this._rawValue = value;
989
963
  const shallow = this["_IS_SHALLOW" /* IS_SHALLOW */];
990
964
  if (shallow) {
@@ -1000,7 +974,12 @@ var SignalImpl = class {
1000
974
  // Check if the value should be update
1001
975
  shouldUpdate() {
1002
976
  this.flag &= -17 /* DIRTY */;
1003
- return hasChanged(this._oldValue, this._oldValue = this._rawValue);
977
+ if (!("_oldValue" in this)) {
978
+ return true;
979
+ }
980
+ const changed = hasChanged(this._oldValue, this._rawValue);
981
+ this._oldValue = this._rawValue;
982
+ return changed;
1004
983
  }
1005
984
  // Get current value without triggering dependency tracking
1006
985
  peek() {
@@ -1038,11 +1017,6 @@ function signal(value) {
1038
1017
  }
1039
1018
  function shallowSignal(value) {
1040
1019
  if (isSignal(value)) {
1041
- {
1042
- warn(
1043
- "Creating a shallow signal with another signal is not recommended. The value will be unwrapped."
1044
- );
1045
- }
1046
1020
  value = value.peek();
1047
1021
  }
1048
1022
  return new SignalImpl(value, true);
@@ -1061,8 +1035,8 @@ function nextTick(fn) {
1061
1035
  try {
1062
1036
  fn();
1063
1037
  resolve();
1064
- } catch (error6) {
1065
- reject(error6);
1038
+ } catch (error5) {
1039
+ reject(error5);
1066
1040
  }
1067
1041
  });
1068
1042
  });
@@ -1145,17 +1119,13 @@ function startBatch() {
1145
1119
  function endBatch() {
1146
1120
  if (batchDepth === 0) {
1147
1121
  warn(
1148
- "[Batch] endBatch() called without matching startBatch(). This may indicate unbalanced batch calls in your code."
1122
+ "[Batch] endBatch() called without matching startBatch(). This indicates unbalanced batch calls in your code. Make sure every startBatch() has a corresponding endBatch(), or use the batch() function which handles this automatically."
1149
1123
  );
1150
1124
  return;
1151
1125
  }
1152
- if (--batchDepth === 0) {
1126
+ batchDepth--;
1127
+ if (batchDepth === 0) {
1153
1128
  flushJobs();
1154
- if (batchDepth !== 0) {
1155
- error(
1156
- `[Batch] Batch depth is not zero after endBatch(). Current depth: ${batchDepth}. This indicates a bug in batch management.`
1157
- );
1158
- }
1159
1129
  }
1160
1130
  }
1161
1131
  function isBatching() {
@@ -1179,7 +1149,7 @@ var EffectImpl = class {
1179
1149
  this.flag = 2 /* WATCHING */ | 16 /* DIRTY */;
1180
1150
  // @ts-ignore
1181
1151
  this[_a2] = true;
1182
- // ===== State management =====
1152
+ // State management
1183
1153
  this._active = true;
1184
1154
  this.fn = fn;
1185
1155
  if (options) {
@@ -1297,9 +1267,9 @@ var EffectImpl = class {
1297
1267
  const prevSub = startTracking(this);
1298
1268
  try {
1299
1269
  return this.fn();
1300
- } catch (error6) {
1270
+ } catch (error5) {
1301
1271
  this.flag |= 16 /* DIRTY */;
1302
- throw error6;
1272
+ throw error5;
1303
1273
  } finally {
1304
1274
  this.flag &= -1025 /* STOP */;
1305
1275
  endTracking(this, prevSub);
@@ -1425,7 +1395,7 @@ function memoEffect(fn, initialState, options) {
1425
1395
  };
1426
1396
  return effect(effectFn, options);
1427
1397
  }
1428
- var NO_VALUE = Symbol("computed-no-value");
1398
+ var NO_VALUE = /* @__PURE__ */ Symbol("computed-no-value");
1429
1399
  var _a3;
1430
1400
  _a3 = "_IS_COMPUTED" /* IS_COMPUTED */;
1431
1401
  var ComputedImpl = class {
@@ -1441,7 +1411,7 @@ var ComputedImpl = class {
1441
1411
  this.flag = 1 /* MUTABLE */ | 16 /* DIRTY */;
1442
1412
  //@ts-ignore
1443
1413
  this[_a3] = true;
1444
- // ===== Cache =====
1414
+ // Cache
1445
1415
  // Use symbol sentinel to distinguish "no value" from undefined/null values
1446
1416
  this._value = NO_VALUE;
1447
1417
  this.getter = getter;
@@ -1515,6 +1485,7 @@ var ComputedImpl = class {
1515
1485
  try {
1516
1486
  const newValue = this.getter();
1517
1487
  const flags = this.flag;
1488
+ const subs = this.subLink;
1518
1489
  const clearMask = ~(16 /* DIRTY */ | 32 /* PENDING */);
1519
1490
  const valueChanged = !hadValue || hasChanged(oldValue, newValue);
1520
1491
  if (valueChanged) {
@@ -1529,17 +1500,19 @@ var ComputedImpl = class {
1529
1500
  newValue
1530
1501
  });
1531
1502
  }
1532
- if (this.subLink) {
1533
- shallowPropagate(this.subLink);
1503
+ if (subs) {
1504
+ shallowPropagate(subs);
1534
1505
  }
1535
1506
  } else {
1536
1507
  this.flag = flags & clearMask;
1537
1508
  }
1538
1509
  } catch (_error) {
1539
- this.flag &= -49;
1510
+ const clearMask = -49;
1511
+ this.flag &= clearMask;
1512
+ this.flag |= 16 /* DIRTY */;
1540
1513
  {
1541
1514
  error(
1542
- "[Computed] Error occurred while computing value. Check your getter function for errors.",
1515
+ "[Computed] Error occurred while computing value.\nThe computed will retry on next access.\nCommon causes:\n - Accessing undefined properties\n - Circular dependencies\n - Exceptions in getter function\nCheck your getter function for errors.",
1543
1516
  _error
1544
1517
  );
1545
1518
  }
@@ -1615,6 +1588,10 @@ function createOptionsStore(options) {
1615
1588
  const reactiveState = reactive(state);
1616
1589
  const subscriptions = /* @__PURE__ */ new Set();
1617
1590
  const actionCallbacks = /* @__PURE__ */ new Set();
1591
+ const notifySubscribers = (state2) => {
1592
+ subscriptions.forEach((callback) => callback(state2));
1593
+ actionCallbacks.forEach((callback) => callback(state2));
1594
+ };
1618
1595
  const defaultActions = {
1619
1596
  patch$(payload) {
1620
1597
  if (!payload) {
@@ -1624,8 +1601,7 @@ function createOptionsStore(options) {
1624
1601
  batch(() => {
1625
1602
  Object.assign(reactiveState, payload);
1626
1603
  });
1627
- subscriptions.forEach((callback) => callback(reactiveState));
1628
- actionCallbacks.forEach((callback) => callback(reactiveState));
1604
+ notifySubscribers(reactiveState);
1629
1605
  },
1630
1606
  subscribe$(callback) {
1631
1607
  if (!callback) {
@@ -1648,8 +1624,7 @@ function createOptionsStore(options) {
1648
1624
  batch(() => {
1649
1625
  Object.assign(reactiveState, initState);
1650
1626
  });
1651
- subscriptions.forEach((callback) => callback(reactiveState));
1652
- actionCallbacks.forEach((callback) => callback(reactiveState));
1627
+ notifySubscribers(reactiveState);
1653
1628
  }
1654
1629
  };
1655
1630
  const store = __spreadValues(__spreadProps(__spreadValues({}, reactiveState), {
@@ -1659,8 +1634,21 @@ function createOptionsStore(options) {
1659
1634
  for (const key in getters) {
1660
1635
  const getter = getters[key];
1661
1636
  if (getter) {
1637
+ let accessCount = 0;
1638
+ let lastWarnTime = 0;
1662
1639
  Object.defineProperty(store, key, {
1663
1640
  get() {
1641
+ {
1642
+ accessCount++;
1643
+ const now = Date.now();
1644
+ if (accessCount > 100 && now - lastWarnTime > 1e3) {
1645
+ warn(
1646
+ `Getter '${key}' has been accessed ${accessCount} times. Consider caching the result if the value is used frequently. Note: Getters are computed properties that recalculate on every access.`
1647
+ );
1648
+ lastWarnTime = now;
1649
+ accessCount = 0;
1650
+ }
1651
+ }
1664
1652
  return computed(() => getter.call(store, reactiveState)).value;
1665
1653
  },
1666
1654
  enumerable: true,
@@ -1694,11 +1682,11 @@ function createClassStore(StoreClass) {
1694
1682
  Object.getOwnPropertyNames(StoreClass.prototype).forEach((key) => {
1695
1683
  const descriptor = Object.getOwnPropertyDescriptor(StoreClass.prototype, key);
1696
1684
  if (descriptor) {
1697
- if (typeof descriptor.get === "function") {
1685
+ if (isFunction(descriptor.get)) {
1698
1686
  getters[key] = function() {
1699
1687
  return descriptor.get.call(this);
1700
1688
  };
1701
- } else if (typeof descriptor.value === "function" && key !== "constructor") {
1689
+ } else if (isFunction(descriptor.value) && key !== "constructor") {
1702
1690
  actions[key] = function(...args) {
1703
1691
  return descriptor.value.apply(this, args);
1704
1692
  };
@@ -1718,13 +1706,13 @@ function createStore(storeDefinition) {
1718
1706
  }
1719
1707
  return () => {
1720
1708
  let options;
1721
- if (typeof storeDefinition === "function") {
1709
+ if (isFunction(storeDefinition)) {
1722
1710
  options = createClassStore(storeDefinition);
1723
1711
  } else {
1724
1712
  options = storeDefinition;
1725
1713
  }
1726
1714
  const store = createOptionsStore(options);
1727
- if (typeof storeDefinition === "function") {
1715
+ if (isFunction(storeDefinition)) {
1728
1716
  Object.keys(options.actions || {}).forEach((key) => {
1729
1717
  store[key] = options.actions[key].bind(store);
1730
1718
  });
@@ -1766,15 +1754,9 @@ var RefImpl = class extends (_b = SignalImpl, _a4 = "_IS_REF" /* IS_REF */, _b)
1766
1754
  };
1767
1755
  function ref(value = void 0) {
1768
1756
  if (isRef(value)) {
1769
- {
1770
- info("Creating a ref with another ref is not recommended. The value will be unwrapped.");
1771
- }
1772
1757
  return value;
1773
1758
  }
1774
1759
  if (isSignal(value)) {
1775
- {
1776
- info("Creating a ref with a signal is not recommended. The value will be unwrapped.");
1777
- }
1778
1760
  return new RefImpl(value.peek());
1779
1761
  }
1780
1762
  return new RefImpl(value);
@@ -1,10 +1,5 @@
1
- import {isObject,isFunction,isPlainObject,hasChanged,isArray,isSet,isMap,isWeakMap,isWeakSet,isStringNumber,hasOwn}from'@estjs/shared';/**
2
- * @estjs/signals v0.0.15-beta.1
3
- * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
4
- * @license MIT
5
- **/
6
- var Be=Object.defineProperty,He=Object.defineProperties;var $e=Object.getOwnPropertyDescriptors;var de=Object.getOwnPropertySymbols;var Je=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable;var he=(e,t,n)=>t in e?Be(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,Y=(e,t)=>{for(var n in t||(t={}))Je.call(t,n)&&he(e,n,t[n]);if(de)for(var n of de(t))Qe.call(t,n)&&he(e,n,t[n]);return e},Te=(e,t)=>He(e,$e(t));var E={SET:"SET",ADD:"ADD",DELETE:"DELETE",CLEAR:"CLEAR"};var te=Symbol(""),C=Symbol(""),_=Symbol(""),R=Symbol(""),w=Symbol("");function O(e){let t=e.nextSubLink,n;e:do{let r=e.subNode,i=r.flag&64,o=r.flag&2,a=r.flag&-65;if(a&60?a&48||(a&12?a&4?!(a&48)&&ge(e,r)?(r.flag=i|o|(a|8|32),a&=1):(a=0,r.flag=i|o):r.flag=i|o|(a&-9|32):(a=0,r.flag=i|o)):r.flag=i|o|a|32,r.flag&2&&Ee(r),a&1){let s=r.subLink;if(s){let g=(e=s).nextSubLink;g&&(n={value:t,prev:n},t=g);continue}}if(t){e=t,t=e.nextSubLink;continue}for(;n;)if(e=n.value,n=n.prev,e){t=e.nextSubLink;continue e}break}while(true)}function ne(e){for(;e;){let t=e.subNode,n=t.flag&64,r=t.flag&-65;if(!(r&16)&&r&33){let i=n|r&-33|16;t.flag=i,i&2&&Ee(t),r&1&&t.subLink&&ne(t.subLink);}e=e.nextSubLink;}}function Ee(e){e.active&&e.notify();}var M=0,b,N=false;function j(e,t){if(N)return;let n=t.depLinkTail;if(n&&n.depNode===e)return n;let r=n?n.nextDepLink:t.depLink;if(r&&r.depNode===e)return r.version=M,t.depLinkTail=r,r;let i=e.subLinkTail;if(i&&i.version===M&&i.subNode===t)return t.depLinkTail=i,i;let o={version:M,depNode:e,subNode:t,prevSubLink:i,nextSubLink:void 0,prevDepLink:n,nextDepLink:r};return r&&(r.prevDepLink=o),n?n.nextDepLink=o:t.depLink=o,i?i.nextSubLink=o:e.subLink=o,e.subLinkTail=o,t.depLinkTail=o,o}function V(e,t=e.subNode){let n=e.depNode,r=e.prevSubLink,i=e.nextSubLink,o=e.prevDepLink,a=e.nextDepLink;if(a?a.prevDepLink=o:t.depLinkTail=o,o?o.nextDepLink=a:t.depLink=a,i?i.prevSubLink=r:n.subLinkTail=r,r)r.nextSubLink=i;else if(n.subLink=i,i===void 0){let s=n.depLink;for(;s;)s=V(s,n);n.depLinkTail=void 0,n.flag|=16;}return e.depNode=void 0,e.subNode=void 0,e.prevSubLink=void 0,e.nextSubLink=void 0,e.prevDepLink=void 0,e.nextDepLink=void 0,a}function K(e,t){let n=[{link:e,owner:t}],r=[];for(;n.length>0;){let i=n.pop(),o=i.link,a=i.owner;for(;o;){let s=o.depNode,g=s.flag;if(a.flag&16)return true;if((g&17)===17){let d=s.subLink;d&&d.nextSubLink&&P(d);for(let u of r)u.flag&32&&(u.flag=u.flag&-33|16);return true}(g&33)===33?s.depLink?(r.push(s),n.push({link:s.depLink,owner:s})):s.flag&=-33:g&32&&(s.flag&=-33),o=o.nextDepLink;}}for(let i of r)i.flag&=-33;return t.flag&32&&(t.flag&=-33),false}function P(e){for(;e;){let t=e.subNode,n=t.flag&64,r=t.flag&-65;(r&48)===32&&(t.flag=n|r|16),e=e.nextSubLink;}}function re(e){let t=b;return b=e,t}function W(e){return M++,e.depLinkTail=void 0,e.flag=e.flag&-57|4,re(e)}function F(e,t){b=t;let n=e.depLinkTail,r=n?n.nextDepLink:e.depLink;for(;r;)r=V(r,e);e.flag&=-5;}function ze(e){let t=re(void 0),n=N;N=true;try{return e()}finally{N=n,re(t);}}function ge(e,t){let n=t.depLinkTail;for(;n;){if(n===e)return true;n=n.prevDepLink;}return false}var ie=new WeakMap;function f(e,t){if(!b||N)return;let n=ie.get(e);n||(n=new Map,ie.set(e,n));let r=n.get(t);r||(r=new Set,n.set(t,r)),r.has(b)||r.add(b);}function p(e,t,n,r){let i=ie.get(e);if(!i)return;let o=new Set;if(n!==void 0)if(Array.isArray(n))n.forEach(a=>{let s=i.get(a);s&&s.forEach(g=>o.add(g));});else {let a=i.get(n);a&&a.forEach(s=>o.add(s));}if(t==="ADD"||t==="DELETE"||t==="CLEAR"){let a=Symbol("iterate"),s=Symbol("arrayIterate"),g=Array.isArray(e)?s:a,d=i.get(g);d&&d.forEach(u=>o.add(u));}o.forEach(a=>{var s;a.flag&2?(s=a.notify)==null||s.call(a):a.flag&1&&(a.flag|=16,a.subLink&&O(a.subLink));});}var _e=new WeakMap;function c(e){if(!e||!isObject(e))return e;let t=e._RAW;return t?c(t):T(e)?c(e.peek()):e}var me=it();function it(){let e={};return ["includes","indexOf","lastIndexOf"].forEach(t=>{e[t]=function(...n){let r=c(this);f(r,w);let i=r[t](...n);if((i===-1||i===false)&&n.length>0){let o=n.map(a=>c(a));i=r[t](...o);}return i};}),["find","findIndex","findLast","findLastIndex"].forEach(t=>{e[t]=function(...n){let r=c(this),i=k(this);f(r,w);let o=r[t](...n);return (t==="find"||t==="findLast")&&isObject(o)&&!i?h(o):o};}),["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].forEach(t=>{e[t]=function(...n){let r=c(this),i=Array.prototype[t].apply(r,n);return p(r,E.SET,C),p(r,E.SET,w),i};}),["toReversed","toSorted","toSpliced"].forEach(t=>{e[t]=function(...n){let r=c(this),i=k(this);if(f(r,w),t==="toSpliced")for(let a=0,s=r.length;a<s;a++)f(r,`${a}`);let o=Array.prototype[t].apply(r,n);return Array.isArray(o)?o.map(a=>isObject(a)?h(a,i):a):o};}),["concat","slice","filter","map","flatMap","flat"].forEach(t=>{e[t]=function(...n){let r=c(this);return f(r,w),Array.prototype[t].apply(r,n)};}),["join","toString","toLocaleString"].forEach(t=>{e[t]=function(...n){let r=c(this);return f(r,w),Array.prototype[t].apply(r,n)};}),["values","keys","entries",Symbol.iterator].forEach(t=>{e[t]=function(){let n=c(this),r=k(this);f(n,C);let i=t===Symbol.iterator?n[Symbol.iterator]():n[t]();return {next(){let{value:o,done:a}=i.next();return a?{value:o,done:a}:Array.isArray(o)?{value:o.map(s=>isObject(s)?h(s,r):s),done:a}:{value:isObject(o)?h(o,r):o,done:a}},[Symbol.iterator](){return this}}};}),e}var ke=e=>({get:(t,n,r)=>{if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;if(hasOwn(me,n))return me[n];let i=Reflect.get(t,n,r);return isStringNumber(n)&&f(t,n),f(t,C),isObject(i)&&!e?h(i):i},set:(t,n,r,i)=>{let o=Reflect.get(t,n,i),a=Reflect.set(t,n,r,i);return hasChanged(r,o)&&(isStringNumber(n)?p(t,E.SET,[n,w,C]):p(t,E.SET,n)),a}}),ot=ke(true),at=ke(false),st={get(e,t){return t==="_IS_REACTIVE"?true:t==="_RAW"?e:Reflect.get(hasOwn(ye,t)?ye:e,t,e)}},ct={get(e,t){return t==="_IS_REACTIVE"?true:t==="_RAW"?e:Reflect.get(hasOwn(be,t)&&t in e?be:e,t,e)}},ye={get(e){let t=c(this);f(t,_);let n=t.get(e);return isObject(n)&&!k(this)?h(n):n},set(e,t){let n=c(this),r=n.has(e),i=n.get(e),o=c(t);return n.set(e,o),(!r||hasChanged(i,o))&&p(n,E.SET,_),this},add(e){let t=c(this),n=c(e),r=t.has(n);return t.add(n),r?p(t,E.SET,_):p(t,E.ADD,_),this},has(e){let t=c(this);f(t,_);let n=t.has(e);return !n&&isObject(e)?t.has(c(e)):n},delete(e){let t=c(this),n=t.has(e),r=t.delete(e);return !r&&isObject(e)&&(r=t.delete(c(e))),(n||r)&&p(t,E.DELETE,_),r},clear(){let e=c(this),t=e.size>0,n=e.clear();return t&&p(e,E.CLEAR,_),n},forEach(e,t){let n=c(this),r=k(this);f(n,_),n.forEach((i,o)=>{let a=r||!isObject(i)?i:h(i),s=r||!isObject(o)?o:h(o);e.call(t,a,s,this);});},[Symbol.iterator](){let e=c(this),t=k(this);f(e,_);let n=e[Symbol.iterator]();return {next(){let{value:r,done:i}=n.next();return i?{value:r,done:i}:t?{value:r,done:i}:Array.isArray(r)?{value:r.map(o=>isObject(o)?h(o):o),done:i}:{value:isObject(r)?h(r):r,done:i}},[Symbol.iterator](){return this}}},get size(){let e=c(this);return f(e,_),e.size},keys(){let e=c(this),t=k(this);f(e,_);let n=e.keys();return {next(){let{value:r,done:i}=n.next();return i?{value:r,done:i}:{value:t||!isObject(r)?r:h(r),done:i}},[Symbol.iterator](){return this}}},values(){let e=c(this),t=k(this);f(e,_);let n=e.values();return {next(){let{value:r,done:i}=n.next();return i?{value:r,done:i}:{value:t||!isObject(r)?r:h(r),done:i}},[Symbol.iterator](){return this}}},entries(){let e=c(this),t=k(this);f(e,_);let n=e.entries();return {next(){let{value:r,done:i}=n.next();return i?{value:r,done:i}:t?{value:r,done:i}:{value:r.map(o=>isObject(o)?h(o):o),done:i}},[Symbol.iterator](){return this}}}},be={get(e){let t=c(this);f(t,R);let n=t.get(e);return n===void 0&&v(e)&&(n=t.get(c(e))),isObject(n)&&!k(this)?h(n):n},set(e,t){let n=c(this),r=c(e),i=n.has(r),o=n.get(r),a=c(t);return n.set(r,a),(!i||hasChanged(o,a))&&p(n,E.SET,R),this},add(e){let t=c(this),n=c(e),r=t.has(n);return t.add(n),r||p(t,E.ADD,R),this},has(e){let t=c(this);f(t,R);let n=t.has(e);return !n&&v(e)&&(n=t.has(c(e))),n},delete(e){let t=c(this),n=c(e),r=t.has(n),i=t.delete(n);return (r||i)&&p(t,E.DELETE,R),i}},ut=e=>({get(t,n,r){if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;let i=Reflect.get(t,n,r),o=T(i)?i.value:i;return f(t,n),isObject(o)&&!e?h(o):o},set:(t,n,r,i)=>{let o=Reflect.get(t,n,i),a=Reflect.set(t,n,c(r),i);return hasChanged(r,o)&&p(t,E.SET,n),a},deleteProperty:(t,n)=>{let r=hasOwn(t,n),i=Reflect.deleteProperty(t,n);return r&&i&&p(t,E.DELETE,n),i}});function h(e,t=false){if(!isObject(e)||v(e))return e;let n=_e.get(e);if(n)return n;let r;isArray(e)?r=t?ot:at:isSet(e)||isMap(e)?r=st:isWeakMap(e)||isWeakSet(e)?r=ct:r=ut(t);let i=new Proxy(e,r);return _e.set(e,i),i}function v(e){return !!(e&&e._IS_REACTIVE)}function D(e){return v(e)||T(e)?e:h(e)}function H(e){return v(e)||T(e)?e:h(e,true)}function k(e){return !!(e&&e._IS_SHALLOW)}var ft=e=>isObject(e)?D(e):e;var we;we="_IS_SIGNAL";var I=class{constructor(t,n=false){this.flag=1;this[we]=true;this._oldValue=this._rawValue=t,n?this._value=isObject(t)?H(t):t:this._value=isObject(t)?D(t):t,this._IS_SHALLOW=n;}get dep(){return this}get value(){let t=b;if(t&&j(this,t),this.flag&16&&this.shouldUpdate()){let n=this.subLink;n&&P(n);}return this._value}set value(t){if(T(t)&&(t=t.peek()),t=c(t),!hasChanged(this._rawValue,t))return;this.flag|=16,this._rawValue=t,this._IS_SHALLOW?this._value=isObject(t)?H(t):t:this._value=isObject(t)?D(t):t;let r=this.subLink;r&&O(r);}shouldUpdate(){return this.flag&=-17,hasChanged(this._oldValue,this._oldValue=this._rawValue)}peek(){return this._value}set(t){this.value=t;}update(t){let n=t(this.peek());T(n)?this.value=n.peek():this.value=n;}};function lt(e){return T(e)?e:new I(e)}function pt(e){return T(e)&&(e=e.peek()),new I(e,true)}function T(e){return !!e&&!!e._IS_SIGNAL}var J=new Set,oe=new Set,dt=Promise.resolve(),ae=false;function Le(e){return e?new Promise((t,n)=>{queueMicrotask(()=>{try{e(),t();}catch(r){n(r);}});}):dt}function x(e){J.add(e),De();}function De(){ae||(ae=true,Le(se));}function xe(e){oe.add(e),De();}function se(){for(ae=false,ht();J.size>0;){let e=Array.from(J);J.clear();for(let t of e)try{t();}catch(n){}}}function ht(){let e=Array.from(oe);oe.clear();for(let t of e)try{t();}catch(n){}}function Re(e,t){switch(t){case "sync":return ()=>e();case "pre":return ()=>xe(e);case "post":return ()=>x(e);default:return ()=>x(e)}}var Q=0;function z(e){Ie();try{return e()}finally{Ae();}}function Ie(){Q++;}function Ae(){--Q===0&&se();}function ce(){return Q>0}function Tt(){return Q}var Ce;Ce="_IS_EFFECT";var ue=class{constructor(t,n){this.flag=18;this[Ce]=true;this._active=true;this.fn=t,n&&(this.scheduler=n.flush||n.scheduler,this.onStop=n.onStop,this.onTrack=n.onTrack,this.onTrigger=n.onTrigger);}get active(){return this._active}get dirty(){let t=this.flag;if(t&16)return true;if(t&32){if(this.depLink&&K(this.depLink,this))return this.flag=t&-33|16,true;this.flag=t&-33;}return false}pause(){this.flag|=256;}resume(){let n=this.flag&-257;this.flag=n;let r=(n&16)!==0,i=(n&32)!==0;(r||i)&&this.notify();}run(){if(!this._active)return this.fn();let t=this.flag;this.flag=t&-17|1024;let n=W(this);try{return this.fn()}catch(r){throw this.flag|=16,r}finally{this.flag&=-1025,F(this,n);}}getJob(){return this._job||(this._job=()=>this.run()),this._job}notify(){let t=this.flag;!this._active||t&1296||(this.flag=t|16,this.scheduler?isFunction(this.scheduler)?this.scheduler(this):Re(()=>this.run(),this.scheduler)():ce()?x(this.getJob()):this.run());}stop(){if(!this._active)return;this._active=false;let t=this.depLink;for(;t;)t=V(t,this);let n=this.subLink;for(;n;)n=V(n);this._job=void 0,this.depLinkTail=void 0,this.subLinkTail=void 0,this.onStop&&this.onStop();}};function X(e,t){let n=new ue(e,t);try{n.run();}catch(i){throw n.stop(),i}let r=()=>n.run();return r.effect=n,r.stop=()=>n.stop(),r}function gt(e){e.effect.stop();}function St(e){return !!(e&&e._IS_EFFECT)}function _t(e,t,n){let r=t;return X(()=>{r=e(r);},n)}var G=Symbol("computed-no-value"),Pe;Pe="_IS_COMPUTED";var Z=class{constructor(t,n,r,i){this.flag=17;this[Pe]=true;this._value=G;this.getter=t,this.setter=n,this.onTrack=r,this.onTrigger=i,this.flag|=16;}get value(){b&&j(this,b);let t=this.flag,n=this._value!==G;return n&&!(t&48)?this._value:!n||t&16?(this.recompute(),this._value):(t&32&&(this.depLink&&K(this.depLink,this)?this.recompute():this.flag=t&-33),this._value)}set value(t){this.setter&&this.setter(t);}peek(){return this._value===G&&this.recompute(),this._value}recompute(){let t=this._value,n=t!==G,r=W(this);try{let i=this.getter(),o=this.flag,a=-49;!n||hasChanged(t,i)?(this._value=i,this.flag=o&a,this.subLink&&ne(this.subLink)):this.flag=o&a;}catch(i){throw this.flag&=-49,i}finally{F(this,r);}}shouldUpdate(){let t=this._value!==G,n=this._value;return this.recompute(),t?hasChanged(this._value,n):true}};function fe(e){if(U(e))return e;if(!e)throw new Error("[Computed] Invalid argument: computed() requires a getter function or options object.");if(isFunction(e))return new Z(e);if(isPlainObject(e)){let{get:t,set:n,onTrack:r,onTrigger:i}=e;if(!t)throw new Error(`[Computed] Invalid options: getter function is required.
1
+ import {isObject,isFunction,isPlainObject,hasChanged,isArray,isSet,isMap,isWeakMap,isWeakSet,hasOwn,isStringNumber}from'@estjs/shared';var $e=Object.defineProperty,Je=Object.defineProperties;var Qe=Object.getOwnPropertyDescriptors;var Se=Object.getOwnPropertySymbols;var ze=Object.prototype.hasOwnProperty,Xe=Object.prototype.propertyIsEnumerable;var me=(e,t,n)=>t in e?$e(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,M=(e,t)=>{for(var n in t||(t={}))ze.call(t,n)&&me(e,n,t[n]);if(Se)for(var n of Se(t))Xe.call(t,n)&&me(e,n,t[n]);return e},_e=(e,t)=>Je(e,Qe(t));var g={SET:"SET",ADD:"ADD",DELETE:"DELETE",CLEAR:"CLEAR"};var re=Symbol(""),N=Symbol(""),m=Symbol(""),I=Symbol("");var L=Symbol("");function j(e){let t=e.nextSubLink,n;e:do{let r=e.subNode,i=r.flag&64,o=r.flag&2,s=r.flag&-65;if(s&60?s&48||(s&12?s&4?!(s&48)&&ye(e,r)?(r.flag=i|o|(s|8|32),s&=1):(s=0,r.flag=i|o):r.flag=i|o|(s&-9|32):(s=0,r.flag=i|o)):r.flag=i|o|s|32,r.flag&2&&be(r),s&1){let a=r.subLink;if(a){let h=(e=a).nextSubLink;h&&(n={value:t,prev:n},t=h);continue}}if(t){e=t,t=e.nextSubLink;continue}for(;n;)if(e=n.value,n=n.prev,e){t=e.nextSubLink;continue e}break}while(true)}function ie(e){for(;e;){let t=e.subNode,n=t.flag&64,r=t.flag&-65;if(!(r&16)&&r&33){let i=n|r&-33|16;t.flag=i,i&2&&be(t),r&1&&t.subLink&&ie(t.subLink);}e=e.nextSubLink;}}function be(e){e.active&&e.notify();}var K=0,y,V=false;function W(e,t){if(V)return;let n=t.depLinkTail;if(n&&n.depNode===e)return n;let r=n?n.nextDepLink:t.depLink;if(r&&r.depNode===e)return r.version=K,t.depLinkTail=r,r;let i=e.subLinkTail;if(i&&i.version===K&&i.subNode===t)return t.depLinkTail=i,i;let o={version:K,depNode:e,subNode:t,prevSubLink:i,nextSubLink:void 0,prevDepLink:n,nextDepLink:r};return r&&(r.prevDepLink=o),n?n.nextDepLink=o:t.depLink=o,i?i.nextSubLink=o:e.subLink=o,e.subLinkTail=o,t.depLinkTail=o,o}function P(e,t=e.subNode){let n=e.depNode,r=e.prevSubLink,i=e.nextSubLink,o=e.prevDepLink,s=e.nextDepLink;if(s?s.prevDepLink=o:t.depLinkTail=o,o?o.nextDepLink=s:t.depLink=s,i?i.prevSubLink=r:n.subLinkTail=r,r)r.nextSubLink=i;else if(n.subLink=i,i===void 0){let a=n.depLink;for(;a;)a=P(a,n);n.depLinkTail=void 0,n.flag|=16;}return e.depNode=void 0,e.subNode=void 0,e.prevSubLink=void 0,e.nextSubLink=void 0,e.prevDepLink=void 0,e.nextDepLink=void 0,s}function F(e,t){let n=[{link:e,owner:t}],r=[];for(;n.length>0;){let i=n.pop(),o=i.link,s=i.owner;for(;o;){let a=o.depNode,h=a.flag;if(s.flag&16)return true;if((h&17)===17){let S=a.subLink;S&&S.nextSubLink&&G(S);for(let p of r)p.flag&32&&(p.flag=p.flag&-33|16);return true}(h&33)===33?a.depLink?(r.push(a),n.push({link:a.depLink,owner:a})):a.flag&=-33:h&32&&(a.flag&=-33),o=o.nextDepLink;}}for(let i of r)i.flag&=-33;return t.flag&32&&(t.flag&=-33),false}function G(e){for(;e;){let t=e.subNode,n=t.flag&64,r=t.flag&-65;(r&48)===32&&(t.flag=n|r|16),e=e.nextSubLink;}}function oe(e){let t=y;return y=e,t}function q(e){return K++,e.depLinkTail=void 0,e.flag=e.flag&-57|4,oe(e)}function B(e,t){y=t;let n=e.depLinkTail,r=n?n.nextDepLink:e.depLink;for(;r;)r=P(r,e);e.flag&=-5;}function Ze(e){let t=oe(void 0),n=V;V=true;try{return e()}finally{V=n,oe(t);}}function ye(e,t){let n=t.depLinkTail;for(;n;){if(n===e)return true;n=n.prevDepLink;}return false}var se=new WeakMap;function u(e,t){if(!y||V)return;let n=se.get(e);n||(n=new Map,se.set(e,n));let r=n.get(t);r||(r=new Set,n.set(t,r)),r.has(y)||r.add(y);}function d(e,t,n,r){let i=se.get(e);if(!i)return;let o=new Set;if(n!==void 0)if(Array.isArray(n))n.forEach(s=>{let a=i.get(s);a&&a.forEach(h=>o.add(h));});else {let s=i.get(n);s&&s.forEach(a=>o.add(a));}if(t==="ADD"||t==="DELETE"||t==="CLEAR"){let s=Symbol("iterate"),a=Symbol("arrayIterate"),h=Array.isArray(e)?a:s,S=i.get(h);S&&S.forEach(p=>o.add(p));}o.forEach(s=>{var a;s.flag&2?(a=s.notify)==null||a.call(s):s.flag&1&&(s.flag|=16,s.subLink&&j(s.subLink));});}var ve=new WeakMap;function c(e){if(!e||!isObject(e))return e;let t=e._RAW;return t?c(t):E(e)?c(e.peek()):e}var we=st();function st(){let e={};return ["includes","indexOf","lastIndexOf"].forEach(t=>{e[t]=function(...n){let r=c(this);u(r,L);let i=r[t](...n);if((i===-1||i===false)&&n.length>0){let o=n.map(s=>c(s));i=r[t](...o);}return i};}),["find","findIndex","findLast","findLastIndex"].forEach(t=>{e[t]=function(...n){let r=c(this),i=k(this);u(r,L);let o=r[t](...n);return (t==="find"||t==="findLast")&&isObject(o)&&!i?T(o):o};}),["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].forEach(t=>{e[t]=function(...n){let r=c(this),i=Array.prototype[t].apply(r,n);return d(r,g.SET,N),d(r,g.SET,L),i};}),["toReversed","toSorted","toSpliced"].forEach(t=>{e[t]=function(...n){let r=c(this),i=k(this);if(u(r,L),t==="toSpliced")for(let s=0,a=r.length;s<a;s++)u(r,`${s}`);let o=Array.prototype[t].apply(r,n);return Array.isArray(o)?o.map(s=>isObject(s)?T(s,i):s):o};}),["concat","slice","filter","map","flatMap","flat"].forEach(t=>{e[t]=function(...n){let r=c(this);return u(r,L),Array.prototype[t].apply(r,n)};}),["join","toString","toLocaleString"].forEach(t=>{e[t]=function(...n){let r=c(this);return u(r,L),Array.prototype[t].apply(r,n)};}),["values","keys","entries",Symbol.iterator].forEach(t=>{e[t]=function(){let n=c(this),r=k(this);u(n,N);let i=t===Symbol.iterator?n[Symbol.iterator]():n[t]();return {next(){let{value:o,done:s}=i.next();return s?{value:o,done:s}:Array.isArray(o)?{value:o.map(a=>isObject(a)?T(a,r):a),done:s}:{value:isObject(o)?T(o,r):o,done:s}},[Symbol.iterator](){return this}}};}),e}var De=e=>({get:(t,n,r)=>{if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;if(hasOwn(we,n))return we[n];let i=Reflect.get(t,n,r);return isStringNumber(n)&&u(t,n),u(t,N),isObject(i)&&!e?T(i):i},set:(t,n,r,i)=>{let o=Reflect.get(t,n,i),s=Reflect.set(t,n,r,i);return hasChanged(r,o)&&(isStringNumber(n)?d(t,g.SET,[n,L,N]):d(t,g.SET,n)),s}}),at=De(true),ct=De(false),ut={get(e,t){return t==="_IS_REACTIVE"?true:t==="_RAW"?e:Reflect.get(hasOwn(Le,t)?Le:e,t,e)}},ft={get(e,t){return t==="_IS_REACTIVE"?true:t==="_RAW"?e:Reflect.get(hasOwn(xe,t)&&t in e?xe:e,t,e)}},Le={get(e){let t=c(this);u(t,m);let n=t.get(e);return isObject(n)&&!k(this)?T(n):n},set(e,t){let n=c(this),r=n.has(e),i=n.get(e),o=c(t);return n.set(e,o),(!r||hasChanged(i,o))&&d(n,g.SET,m),this},add(e){let t=c(this),n=c(e),r=t.has(n);return t.add(n),r?d(t,g.SET,m):d(t,g.ADD,m),this},has(e){let t=c(this);u(t,m);let n=t.has(e);return !n&&isObject(e)?t.has(c(e)):n},delete(e){let t=c(this),n=t.has(e),r=t.delete(e);return !r&&isObject(e)&&(r=t.delete(c(e))),(n||r)&&d(t,g.DELETE,m),r},clear(){let e=c(this),t=e.size>0,n=e.clear();return t&&d(e,g.CLEAR,m),n},forEach(e,t){let n=c(this),r=k(this);u(n,m),n.forEach((i,o)=>{let s=r||!isObject(i)?i:T(i),a=r||!isObject(o)?o:T(o);e.call(t,s,a,this);});},[Symbol.iterator](){let e=c(this),t=k(this);u(e,m);let n=e[Symbol.iterator]();return {next(){let{value:r,done:i}=n.next();return i?{value:r,done:i}:t?{value:r,done:i}:Array.isArray(r)?{value:r.map(o=>isObject(o)?T(o):o),done:i}:{value:isObject(r)?T(r):r,done:i}},[Symbol.iterator](){return this}}},get size(){let e=c(this);return u(e,m),e.size},keys(){let e=c(this),t=k(this);u(e,m);let n=e.keys();return {next(){let{value:r,done:i}=n.next();return i?{value:r,done:i}:{value:t||!isObject(r)?r:T(r),done:i}},[Symbol.iterator](){return this}}},values(){let e=c(this),t=k(this);u(e,m);let n=e.values();return {next(){let{value:r,done:i}=n.next();return i?{value:r,done:i}:{value:t||!isObject(r)?r:T(r),done:i}},[Symbol.iterator](){return this}}},entries(){let e=c(this),t=k(this);u(e,m);let n=e.entries();return {next(){let{value:r,done:i}=n.next();return i?{value:r,done:i}:t?{value:r,done:i}:{value:r.map(o=>isObject(o)?T(o):o),done:i}},[Symbol.iterator](){return this}}}},xe={get(e){let t=c(this);u(t,I);let n=t.get(e);return n===void 0&&w(e)&&(n=t.get(c(e))),isObject(n)&&!k(this)?T(n):n},set(e,t){let n=c(this),r=c(e),i=n.has(r),o=n.get(r),s=c(t);return n.set(r,s),(!i||hasChanged(o,s))&&d(n,g.SET,I),this},add(e){let t=c(this),n=c(e),r=t.has(n);return t.add(n),r||d(t,g.ADD,I),this},has(e){let t=c(this);u(t,I);let n=t.has(e);return !n&&w(e)&&(n=t.has(c(e))),n},delete(e){let t=c(this),n=c(e),r=t.has(n),i=t.delete(n);return (r||i)&&d(t,g.DELETE,I),i}},lt=e=>({get(t,n,r){if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;let i=Reflect.get(t,n,r),o=E(i)?i.value:i;return u(t,n),isObject(o)&&!e?T(o):o},set:(t,n,r,i)=>{let o=Reflect.get(t,n,i),s=Reflect.set(t,n,c(r),i);return hasChanged(r,o)&&d(t,g.SET,n),s},deleteProperty:(t,n)=>{let r=hasOwn(t,n),i=Reflect.deleteProperty(t,n);return r&&i&&d(t,g.DELETE,n),i}});function T(e,t=false){if(!isObject(e)||w(e))return e;let n=ve.get(e);if(n)return n;let r;isArray(e)?r=t?at:ct:isSet(e)||isMap(e)?r=ut:isWeakMap(e)||isWeakSet(e)?r=ft:r=lt(t);let i=new Proxy(e,r);return ve.set(e,i),i}function w(e){return !!(e&&e._IS_REACTIVE)}function D(e){return w(e)||E(e)?e:T(e)}function J(e){return w(e)||E(e)?e:T(e,true)}function k(e){return !!(e&&e._IS_SHALLOW)}var pt=e=>isObject(e)?D(e):e;var Ie;Ie="_IS_SIGNAL";var A=class{constructor(t,n=false){this.flag=1;this[Ie]=true;this._rawValue=t,n?this._value=isObject(t)?J(t):t:this._value=isObject(t)?D(t):t,this._IS_SHALLOW=n;}get dep(){return this}get value(){let t=y;if(t&&W(this,t),this.flag&16&&this.shouldUpdate()){let r=this.subLink;r&&G(r);}return this._value}set value(t){if(E(t)&&(t=t.peek()),t=c(t),!hasChanged(this._rawValue,t))return;"_oldValue"in this||(this._oldValue=this._rawValue);let n=this.flag;this.flag=n|16,this._rawValue=t,this._IS_SHALLOW?this._value=isObject(t)?J(t):t:this._value=isObject(t)?D(t):t;let i=this.subLink;i&&j(i);}shouldUpdate(){if(this.flag&=-17,!("_oldValue"in this))return true;let t=hasChanged(this._oldValue,this._rawValue);return this._oldValue=this._rawValue,t}peek(){return this._value}set(t){this.value=t;}update(t){let n=t(this.peek());E(n)?this.value=n.peek():this.value=n;}};function dt(e){return E(e)?e:new A(e)}function ht(e){return E(e)&&(e=e.peek()),new A(e,true)}function E(e){return !!e&&!!e._IS_SIGNAL}var z=new Set,ae=new Set,Tt=Promise.resolve(),ce=false;function Ae(e){return e?new Promise((t,n)=>{queueMicrotask(()=>{try{e(),t();}catch(r){n(r);}});}):Tt}function R(e){z.add(e),Ce();}function Ce(){ce||(ce=true,Ae(ue));}function Ne(e){ae.add(e),Ce();}function ue(){for(ce=false,Et();z.size>0;){let e=Array.from(z);z.clear();for(let t of e)try{t();}catch(n){}}}function Et(){let e=Array.from(ae);ae.clear();for(let t of e)try{t();}catch(n){}}function Ve(e,t){switch(t){case "sync":return ()=>e();case "pre":return ()=>Ne(e);case "post":return ()=>R(e);default:return ()=>R(e)}}var Y=0;function X(e){Pe();try{return e()}finally{Ge();}}function Pe(){Y++;}function Ge(){Y--,Y===0&&ue();}function fe(){return Y>0}function gt(){return Y}var Ye;Ye="_IS_EFFECT";var le=class{constructor(t,n){this.flag=18;this[Ye]=true;this._active=true;this.fn=t,n&&(this.scheduler=n.flush||n.scheduler,this.onStop=n.onStop,this.onTrack=n.onTrack,this.onTrigger=n.onTrigger);}get active(){return this._active}get dirty(){let t=this.flag;if(t&16)return true;if(t&32){if(this.depLink&&F(this.depLink,this))return this.flag=t&-33|16,true;this.flag=t&-33;}return false}pause(){this.flag|=256;}resume(){let n=this.flag&-257;this.flag=n;let r=(n&16)!==0,i=(n&32)!==0;(r||i)&&this.notify();}run(){if(!this._active)return this.fn();let t=this.flag;this.flag=t&-17|1024;let n=q(this);try{return this.fn()}catch(r){throw this.flag|=16,r}finally{this.flag&=-1025,B(this,n);}}getJob(){return this._job||(this._job=()=>this.run()),this._job}notify(){let t=this.flag;!this._active||t&1296||(this.flag=t|16,this.scheduler?isFunction(this.scheduler)?this.scheduler(this):Ve(()=>this.run(),this.scheduler)():fe()?R(this.getJob()):this.run());}stop(){if(!this._active)return;this._active=false;let t=this.depLink;for(;t;)t=P(t,this);let n=this.subLink;for(;n;)n=P(n);this._job=void 0,this.depLinkTail=void 0,this.subLinkTail=void 0,this.onStop&&this.onStop();}};function Z(e,t){let n=new le(e,t);try{n.run();}catch(i){throw n.stop(),i}let r=()=>n.run();return r.effect=n,r.stop=()=>n.stop(),r}function mt(e){e.effect.stop();}function _t(e){return !!(e&&e._IS_EFFECT)}function bt(e,t,n){let r=t;return Z(()=>{r=e(r);},n)}var O=Symbol("computed-no-value"),Me;Me="_IS_COMPUTED";var ee=class{constructor(t,n,r,i){this.flag=17;this[Me]=true;this._value=O;this.getter=t,this.setter=n,this.onTrack=r,this.onTrigger=i,this.flag|=16;}get value(){y&&W(this,y);let t=this.flag,n=this._value!==O;return n&&!(t&48)?this._value:!n||t&16?(this.recompute(),this._value):(t&32&&(this.depLink&&F(this.depLink,this)?this.recompute():this.flag=t&-33),this._value)}set value(t){this.setter&&this.setter(t);}peek(){return this._value===O&&this.recompute(),this._value}recompute(){let t=this._value,n=t!==O,r=q(this);try{let i=this.getter(),o=this.flag,s=this.subLink,a=-49;!n||hasChanged(t,i)?(this._value=i,this.flag=o&a,s&&ie(s)):this.flag=o&a;}catch(i){let o=-49;throw this.flag&=o,this.flag|=16,i}finally{B(this,r);}}shouldUpdate(){let t=this._value!==O,n=this._value;return this.recompute(),t?hasChanged(this._value,n):true}};function pe(e){if(U(e))return e;if(!e)throw new Error("[Computed] Invalid argument: computed() requires a getter function or options object.");if(isFunction(e))return new ee(e);if(isPlainObject(e)){let{get:t,set:n,onTrack:r,onTrigger:i}=e;if(!t)throw new Error(`[Computed] Invalid options: getter function is required.
7
2
  Usage: computed({ get: () => value, set: (v) => { ... } })`);if(!isFunction(t))throw new TypeError(`[Computed] Invalid options: getter must be a function.
8
- Received: ${typeof t}`);return new Z(t,n,r,i)}throw new Error(`[Computed] Invalid argument: expected a function or options object.
9
- Received: ${typeof e}`)}function U(e){return !!e&&!!e._IS_COMPUTED}function yt(e){let{state:t,getters:n,actions:r}=e,i=Y({},t),o=D(t),a=new Set,s=new Set,g={patch$(u){z(()=>{Object.assign(o,u);}),a.forEach(S=>S(o)),s.forEach(S=>S(o));},subscribe$(u){a.add(u);},unsubscribe$(u){a.delete(u);},onAction$(u){s.add(u);},reset$(){z(()=>{Object.assign(o,i);}),a.forEach(u=>u(o)),s.forEach(u=>u(o));}},d=Y(Te(Y({},o),{state:o}),g);if(n)for(let u in n){let S=n[u];S&&Object.defineProperty(d,u,{get(){return fe(()=>S.call(d,o)).value},enumerable:true,configurable:true});}if(r)for(let u in r){let S=r[u];S&&(d[u]=(...We)=>{let Fe=S.apply(o,We);return s.forEach(qe=>qe(o)),Fe});}return d}function bt(e){let t=new e,n=Object.create(null),r={},i={};return Object.getOwnPropertyNames(t).forEach(o=>{n[o]=t[o];}),Object.getOwnPropertyNames(e.prototype).forEach(o=>{let a=Object.getOwnPropertyDescriptor(e.prototype,o);a&&(typeof a.get=="function"?r[o]=function(){return a.get.call(this)}:typeof a.value=="function"&&o!=="constructor"&&(i[o]=function(...s){return a.value.apply(this,s)}));}),{state:n,getters:r,actions:i}}function kt(e){return ()=>{let t;typeof e=="function"?t=bt(e):t=e;let n=yt(t);return typeof e=="function"&&Object.keys(t.actions||{}).forEach(r=>{n[r]=t.actions[r].bind(n);}),n}}var Ge,Ue,ee=class extends(Ue=I,Ge="_IS_REF",Ue){constructor(n){super(n,true);this[Ge]=true;}get value(){return f(this,te),this._value}set value(n){T(n)&&(n=n.value),le(n)&&(n=n.value),hasChanged(this._value,n)&&(this._value=n,this.subLink&&P(this.subLink),p(this,"SET",te));}};function wt(e=void 0){return le(e)?e:T(e)?new ee(e.peek()):new ee(e)}function le(e){return !!e&&!!e._IS_REF}var Oe={},Me=new WeakMap;function L(e,t=new Set){if(!isObject(e)||t.has(e))return e;if(t.add(e),T(e)||U(e))return L(e.value,t);if(Array.isArray(e))for(let n of e)L(n,t);else isMap(e)?(e.forEach(n=>{L(n,t);}),e.keys(),e.values()):isSet(e)?(e.forEach(n=>{L(n,t);}),e.values()):Object.keys(e).forEach(n=>{L(e[n],t);});return e}function A(e){if(!isObject(e))return e;if(Array.isArray(e))return e.map(n=>A(n));if(isMap(e)){let n=new Map;return e.forEach((r,i)=>{n.set(i,A(r));}),n}if(isSet(e)){let n=new Set;return e.forEach(r=>{n.add(A(r));}),n}let t={};for(let n of Object.keys(e))t[n]=A(e[n]);return t}function Dt(e){return Array.isArray(e)?()=>e.map(t=>T(t)||U(t)?t.value:v(t)?L(t):isFunction(t)?t():t):isFunction(e)?e:T(e)?()=>e.value:isObject(e)&&"value"in e?()=>e.value:v(e)?()=>L(e):()=>e}function xt(e,t,n={}){let {immediate:r=false,deep:i=false}=n,o=Oe,s=Dt(e),g=()=>{let u=d.effect;if(!u.run)return;let S=u.run();hasChanged(S,o)&&(t(S,o===Oe?void 0:o),o=A(S));},d=X(()=>{let u=s();return i&&L(u),u},{scheduler:()=>x(g)});return r?g():o=A(d.effect.run()),()=>{d.stop();let u=Me.get(d.effect);u&&(u.forEach(S=>S()),Me.delete(d.effect));}}export{E as TriggerOpTypes,z as batch,fe as computed,kt as createStore,X as effect,Ae as endBatch,Tt as getBatchDepth,ce as isBatching,U as isComputed,St as isEffect,v as isReactive,le as isRef,k as isShallow,T as isSignal,_t as memoEffect,Le as nextTick,x as queueJob,xe as queuePreFlushCb,D as reactive,wt as ref,H as shallowReactive,pt as shallowSignal,lt as signal,Ie as startBatch,gt as stop,c as toRaw,ft as toReactive,p as trigger,ze as untrack,xt as watch};//# sourceMappingURL=signals.esm.js.map
3
+ Received: ${typeof t}`);return new ee(t,n,r,i)}throw new Error(`[Computed] Invalid argument: expected a function or options object.
4
+ Received: ${typeof e}`)}function U(e){return !!e&&!!e._IS_COMPUTED}function kt(e){let{state:t,getters:n,actions:r}=e,i=M({},t),o=D(t),s=new Set,a=new Set,h=f=>{s.forEach(v=>v(f)),a.forEach(v=>v(f));},S={patch$(f){X(()=>{Object.assign(o,f);}),h(o);},subscribe$(f){s.add(f);},unsubscribe$(f){s.delete(f);},onAction$(f){a.add(f);},reset$(){X(()=>{Object.assign(o,i);}),h(o);}},p=M(_e(M({},o),{state:o}),S);if(n)for(let f in n){let v=n[f];if(v){Object.defineProperty(p,f,{get(){return pe(()=>v.call(p,o)).value},enumerable:true,configurable:true});}}if(r)for(let f in r){let v=r[f];v&&(p[f]=(...Te)=>{let Ee=v.apply(o,Te);return a.forEach(ge=>ge(o)),Ee});}return p}function vt(e){let t=new e,n=Object.create(null),r={},i={};return Object.getOwnPropertyNames(t).forEach(o=>{n[o]=t[o];}),Object.getOwnPropertyNames(e.prototype).forEach(o=>{let s=Object.getOwnPropertyDescriptor(e.prototype,o);s&&(isFunction(s.get)?r[o]=function(){return s.get.call(this)}:isFunction(s.value)&&o!=="constructor"&&(i[o]=function(...a){return s.value.apply(this,a)}));}),{state:n,getters:r,actions:i}}function wt(e){return ()=>{let t;isFunction(e)?t=vt(e):t=e;let n=kt(t);return isFunction(e)&&Object.keys(t.actions||{}).forEach(r=>{n[r]=t.actions[r].bind(n);}),n}}var je,Ke,ne=class extends(Ke=A,je="_IS_REF",Ke){constructor(n){super(n,true);this[je]=true;}get value(){return u(this,re),this._value}set value(n){E(n)&&(n=n.value),de(n)&&(n=n.value),hasChanged(this._value,n)&&(this._value=n,this.subLink&&G(this.subLink),d(this,"SET",re));}};function xt(e=void 0){return de(e)?e:E(e)?new ne(e.peek()):new ne(e)}function de(e){return !!e&&!!e._IS_REF}var Fe={},qe=new WeakMap;function x(e,t=new Set){if(!isObject(e)||t.has(e))return e;if(t.add(e),E(e)||U(e))return x(e.value,t);if(Array.isArray(e))for(let n of e)x(n,t);else isMap(e)?(e.forEach(n=>{x(n,t);}),e.keys(),e.values()):isSet(e)?(e.forEach(n=>{x(n,t);}),e.values()):Object.keys(e).forEach(n=>{x(e[n],t);});return e}function C(e){if(!isObject(e))return e;if(Array.isArray(e))return e.map(n=>C(n));if(isMap(e)){let n=new Map;return e.forEach((r,i)=>{n.set(i,C(r));}),n}if(isSet(e)){let n=new Set;return e.forEach(r=>{n.add(C(r));}),n}let t={};for(let n of Object.keys(e))t[n]=C(e[n]);return t}function Rt(e){return Array.isArray(e)?()=>e.map(t=>E(t)||U(t)?t.value:w(t)?x(t):isFunction(t)?t():t):isFunction(e)?e:E(e)?()=>e.value:isObject(e)&&"value"in e?()=>e.value:w(e)?()=>x(e):()=>e}function It(e,t,n={}){let {immediate:r=false,deep:i=false}=n,o=Fe,a=Rt(e),h=()=>{let p=S.effect;if(!p.run)return;let f=p.run();hasChanged(f,o)&&(t(f,o===Fe?void 0:o),o=C(f));},S=Z(()=>{let p=a();return i&&x(p),p},{scheduler:()=>R(h)});return r?h():o=C(S.effect.run()),()=>{S.stop();let p=qe.get(S.effect);p&&(p.forEach(f=>f()),qe.delete(S.effect));}}export{g as TriggerOpTypes,X as batch,pe as computed,wt as createStore,Z as effect,Ge as endBatch,gt as getBatchDepth,fe as isBatching,U as isComputed,_t as isEffect,w as isReactive,de as isRef,k as isShallow,E as isSignal,bt as memoEffect,Ae as nextTick,R as queueJob,Ne as queuePreFlushCb,D as reactive,xt as ref,J as shallowReactive,ht as shallowSignal,dt as signal,Pe as startBatch,mt as stop,c as toRaw,pt as toReactive,d as trigger,Ze as untrack,It as watch};//# sourceMappingURL=signals.esm.js.map
10
5
  //# sourceMappingURL=signals.esm.js.map