@vuu-ui/vuu-utils 4.0.0-alpha.8 → 4.0.0-beta.1

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.
Files changed (133) hide show
  1. package/package.json +10 -9
  2. package/src/array-utils.js +5 -4
  3. package/src/column-utils.js +33 -20
  4. package/src/component-registry.js +3 -2
  5. package/src/data-utils.js +1 -0
  6. package/src/datasource/BaseDataSource.js +5 -3
  7. package/src/date/EpochTimestamp.js +85 -0
  8. package/src/date/date-utils.js +50 -18
  9. package/src/date/dateTimePattern.js +33 -5
  10. package/src/date/formatter.js +54 -16
  11. package/src/date/index.js +5 -2
  12. package/src/date/temporal.js +131 -0
  13. package/src/date/time-zone.js +56 -0
  14. package/src/event-emitter.js +1 -3
  15. package/src/feature-utils.js +14 -8
  16. package/src/filters/filter-utils.js +13 -7
  17. package/src/filters/filterAsQuery.js +107 -45
  18. package/src/filters/index.js +1 -0
  19. package/src/filters/temporal-cell-filter.js +63 -0
  20. package/src/form-utils.js +44 -6
  21. package/src/formatting-utils.js +46 -25
  22. package/src/html-utils.js +35 -1
  23. package/src/index.js +0 -1
  24. package/src/keyset.js +15 -9
  25. package/src/react-utils.js +8 -2
  26. package/src/table-schema-utils.js +6 -5
  27. package/src/useResizeObserver.js +3 -3
  28. package/src/vendor/@preact/signals-core/dist/signals-core.js +1 -1
  29. package/src/vendor/@preact/signals-core/dist/signals-core.js.map +1 -1
  30. package/types/ThemeProvider.d.ts +1 -1
  31. package/types/array-utils.d.ts +3 -2
  32. package/types/column-utils.d.ts +45 -43
  33. package/types/context-definitions/DataProvider.d.ts +1 -1
  34. package/types/context-definitions/DataSourceProvider.d.ts +1 -1
  35. package/types/datasource/BaseDataSource.d.ts +2 -2
  36. package/types/date/EpochTimestamp.d.ts +66 -0
  37. package/types/date/date-utils.d.ts +34 -9
  38. package/types/date/dateTimePattern.d.ts +20 -2
  39. package/types/date/formatter.d.ts +26 -1
  40. package/types/date/index.d.ts +6 -2
  41. package/types/date/temporal.d.ts +68 -0
  42. package/types/date/time-zone.d.ts +52 -0
  43. package/types/feature-utils.d.ts +34 -30
  44. package/types/filters/filter-utils.d.ts +6 -1
  45. package/types/filters/filterAsQuery.d.ts +41 -0
  46. package/types/filters/index.d.ts +1 -0
  47. package/types/filters/temporal-cell-filter.d.ts +27 -0
  48. package/types/form-utils.d.ts +19 -0
  49. package/types/formatting-utils.d.ts +23 -1
  50. package/types/html-utils.d.ts +16 -0
  51. package/types/index.d.ts +0 -1
  52. package/types/keyset.d.ts +11 -1
  53. package/types/react-utils.d.ts +1 -1
  54. package/types/sort-utils.d.ts +2 -2
  55. package/types/table-schema-utils.d.ts +2 -2
  56. package/types/tree-types.d.ts +2 -0
  57. package/types/src/Clock.d.ts +0 -20
  58. package/types/src/PageVisibilityObserver.d.ts +0 -36
  59. package/types/src/ScaledDecimal.d.ts +0 -12
  60. package/types/src/ShellContext.d.ts +0 -11
  61. package/types/src/ThemeProvider.d.ts +0 -32
  62. package/types/src/array-utils.d.ts +0 -16
  63. package/types/src/box-utils.d.ts +0 -24
  64. package/types/src/broadcast-channel.d.ts +0 -16
  65. package/types/src/column-utils.d.ts +0 -243
  66. package/types/src/common-types.d.ts +0 -6
  67. package/types/src/component-registry.d.ts +0 -65
  68. package/types/src/context-definitions/DataContext.d.ts +0 -21
  69. package/types/src/context-definitions/DataProvider.d.ts +0 -7
  70. package/types/src/context-definitions/DataSourceProvider.d.ts +0 -12
  71. package/types/src/context-definitions/WorkspaceContext.d.ts +0 -17
  72. package/types/src/cookie-utils.d.ts +0 -9
  73. package/types/src/css-utils.d.ts +0 -1
  74. package/types/src/data-utils.d.ts +0 -33
  75. package/types/src/datasource/BaseDataSource.d.ts +0 -63
  76. package/types/src/datasource/datasource-action-utils.d.ts +0 -7
  77. package/types/src/datasource/datasource-filter-utils.d.ts +0 -2
  78. package/types/src/datasource/datasource-utils.d.ts +0 -61
  79. package/types/src/date/date-utils.d.ts +0 -39
  80. package/types/src/date/dateTimePattern.d.ts +0 -8
  81. package/types/src/date/formatter.d.ts +0 -9
  82. package/types/src/date/index.d.ts +0 -4
  83. package/types/src/date/types.d.ts +0 -29
  84. package/types/src/debug-utils.d.ts +0 -9
  85. package/types/src/edit-utils.d.ts +0 -2
  86. package/types/src/errors.d.ts +0 -2
  87. package/types/src/event-emitter.d.ts +0 -21
  88. package/types/src/feature-utils.d.ts +0 -110
  89. package/types/src/filters/filter-utils.d.ts +0 -75
  90. package/types/src/filters/filterAsQuery.d.ts +0 -8
  91. package/types/src/filters/index.d.ts +0 -2
  92. package/types/src/form-utils.d.ts +0 -37
  93. package/types/src/formatting-utils.d.ts +0 -14
  94. package/types/src/getUniqueId.d.ts +0 -1
  95. package/types/src/group-utils.d.ts +0 -10
  96. package/types/src/html-utils.d.ts +0 -21
  97. package/types/src/index.d.ts +0 -76
  98. package/types/src/input-utils.d.ts +0 -2
  99. package/types/src/invariant.d.ts +0 -1
  100. package/types/src/itemToString.d.ts +0 -2
  101. package/types/src/json-types.d.ts +0 -52
  102. package/types/src/json-utils.d.ts +0 -6
  103. package/types/src/keyboard-utils.d.ts +0 -15
  104. package/types/src/keyset.d.ts +0 -16
  105. package/types/src/layout-types.d.ts +0 -22
  106. package/types/src/list-utils.d.ts +0 -2
  107. package/types/src/local-storage-utils.d.ts +0 -4
  108. package/types/src/logging-utils.d.ts +0 -45
  109. package/types/src/module-utils.d.ts +0 -8
  110. package/types/src/nanoid/index.d.ts +0 -1
  111. package/types/src/perf-utils.d.ts +0 -5
  112. package/types/src/promise-utils.d.ts +0 -8
  113. package/types/src/protocol-message-utils.d.ts +0 -43
  114. package/types/src/range-utils.d.ts +0 -29
  115. package/types/src/react-utils.d.ts +0 -15
  116. package/types/src/round-decimal.d.ts +0 -4
  117. package/types/src/row-utils.d.ts +0 -28
  118. package/types/src/selection-utils.d.ts +0 -9
  119. package/types/src/shell-layout-types.d.ts +0 -15
  120. package/types/src/sort-utils.d.ts +0 -11
  121. package/types/src/table-schema-utils.d.ts +0 -5
  122. package/types/src/text-utils.d.ts +0 -10
  123. package/types/src/theme-utils.d.ts +0 -14
  124. package/types/src/tree-types.d.ts +0 -9
  125. package/types/src/tree-utils.d.ts +0 -9
  126. package/types/src/ts-utils.d.ts +0 -20
  127. package/types/src/typeahead-utils.d.ts +0 -1
  128. package/types/src/url-utils.d.ts +0 -3
  129. package/types/src/useId.d.ts +0 -1
  130. package/types/src/useLayoutEffectSkipFirst.d.ts +0 -2
  131. package/types/src/useResizeObserver.d.ts +0 -15
  132. package/types/src/useStateRef.d.ts +0 -2
  133. package/types/src/user-types.d.ts +0 -3
@@ -1,31 +1,51 @@
1
- import { isDateTimeDataValue, isMappedValueTypeRenderer, isNanoTimestampColumn, isTimeDataValue, isTypeDescriptor } from "./column-utils.js";
2
- import { dateTimePattern, formatDate } from "./date/index.js";
1
+ import { isMappedValueTypeRenderer, isTypeDescriptor } from "./column-utils.js";
2
+ import { dateTimePattern, defaultPatternsByType } from "./date/dateTimePattern.js";
3
+ import { isStartOfDay } from "./date/time-zone.js";
4
+ import { EpochTimestamp } from "./date/EpochTimestamp.js";
5
+ import { formatTimestamp } from "./date/formatter.js";
6
+ import { getTemporalInfo } from "./date/temporal.js";
3
7
  import { roundDecimal, roundScaledDecimal } from "./round-decimal.js";
4
8
  import { isNumericType } from "./protocol-message-utils.js";
5
9
  const DEFAULT_NUMERIC_FORMAT = {};
6
10
  const defaultValueFormatter = (value)=>null == value ? "" : "string" == typeof value ? value : value.toString();
7
- const dateFormatter = (column)=>{
8
- if (isNanoTimestampColumn(column)) {
9
- const pattern = dateTimePattern(column.type);
10
- const formatter = formatDate(pattern);
11
- return (value)=>{
12
- if ("string" != typeof value || "" === value) return "";
13
- {
14
- const bigIntValue = BigInt(value);
15
- const dateTimeValue = Number(bigIntValue / 1000000n);
16
- const nanoSeconds = (bigIntValue % 1000000n).toString().padStart(9, "0");
17
- return `${formatter(new Date(dateTimeValue))}.${nanoSeconds}`;
18
- }
19
- };
20
- }
21
- {
22
- const pattern = dateTimePattern(column.type);
23
- const formatter = formatDate(pattern);
24
- return (value)=>{
25
- if ("number" == typeof value && 0 !== value) return formatter(new Date(value));
26
- return "";
27
- };
11
+ const getFractionalSecondDigits = (column, temporalInfo = getTemporalInfo(column))=>{
12
+ if (void 0 === temporalInfo) return 0;
13
+ const pattern = dateTimePattern(column.type, temporalInfo.kind);
14
+ const formatting = isTypeDescriptor(column.type) ? column.type.formatting : void 0;
15
+ return formatting?.fractionalSecondDigits ?? ("hh:mm:ss.ms" === pattern.time ? 3 : "ns" === temporalInfo.precision && pattern.time ? 9 : 0);
16
+ };
17
+ const temporalFormatter = (column, temporalInfo = getTemporalInfo(column))=>{
18
+ if (void 0 === temporalInfo) return defaultValueFormatter;
19
+ const { encoding, kind, timeZone } = temporalInfo;
20
+ const formatting = isTypeDescriptor(column.type) ? column.type.formatting ?? DEFAULT_NUMERIC_FORMAT : DEFAULT_NUMERIC_FORMAT;
21
+ const pattern = dateTimePattern(column.type, kind);
22
+ const fractionalSecondDigits = getFractionalSecondDigits(column, temporalInfo);
23
+ const formatter = formatTimestamp(pattern, {
24
+ fractionalSecondDigits,
25
+ locale: formatting.locale,
26
+ timeZone
27
+ });
28
+ return (value)=>{
29
+ const timestamp = EpochTimestamp.fromWire(value, encoding);
30
+ return timestamp ? formatter(timestamp) : "";
31
+ };
32
+ };
33
+ const timeOfDayPattern = /^\d{2}:\d{2}:\d{2}(\.\d{1,9})?$/;
34
+ const formatTemporalFilterValue = (value, column)=>{
35
+ const temporalInfo = getTemporalInfo(column);
36
+ if ("string" == typeof value && timeOfDayPattern.test(value)) return value;
37
+ if (void 0 === temporalInfo) return defaultValueFormatter(value);
38
+ const timestamp = EpochTimestamp.fromWire(value, temporalInfo.encoding);
39
+ if (void 0 === timestamp) return defaultValueFormatter(value);
40
+ if ("datetime" === temporalInfo.kind && 0 === timestamp.subMilliNanos && isStartOfDay(timestamp.epochMillis, temporalInfo.timeZone)) {
41
+ const { date = defaultPatternsByType.date } = dateTimePattern(column.type, "date");
42
+ return formatTimestamp({
43
+ date
44
+ }, {
45
+ timeZone: temporalInfo.timeZone
46
+ })(timestamp);
28
47
  }
48
+ return temporalFormatter(column, temporalInfo)(value);
29
49
  };
30
50
  const numericFormatter = ({ align = "right", serverDataType, type })=>{
31
51
  if (void 0 === type || "string" == typeof type) return defaultValueFormatter;
@@ -47,7 +67,8 @@ const NumericTypes = [
47
67
  ];
48
68
  const getValueFormatter = (column)=>{
49
69
  const { serverDataType = "string" } = column;
50
- if (isDateTimeDataValue(column) || isTimeDataValue(column)) return dateFormatter(column);
70
+ const temporalInfo = getTemporalInfo(column);
71
+ if (temporalInfo) return temporalFormatter(column, temporalInfo);
51
72
  const { type } = column;
52
73
  if (isTypeDescriptor(type) && isMappedValueTypeRenderer(type?.renderer)) return mapFormatter(type.renderer.map);
53
74
  if (isNumericType(serverDataType) || isTypeDescriptor(type) && NumericTypes.includes(type.name)) return numericFormatter(column);
@@ -55,4 +76,4 @@ const getValueFormatter = (column)=>{
55
76
  return defaultValueFormatter;
56
77
  };
57
78
  const lowerCase = (str)=>str.toLowerCase();
58
- export { defaultValueFormatter, getValueFormatter, lowerCase, numericFormatter };
79
+ export { defaultValueFormatter, formatTemporalFilterValue, getFractionalSecondDigits, getValueFormatter, lowerCase, numericFormatter, temporalFormatter };
package/src/html-utils.js CHANGED
@@ -81,6 +81,40 @@ function getScrollbarSize() {
81
81
  }
82
82
  return size;
83
83
  }
84
+ const DEFAULT_MAX_SCROLL_HEIGHT = 33000000;
85
+ const MAX_PROBE_HEIGHT = 2 ** 26;
86
+ const maxScrollHeightByDevicePixelRatio = new Map();
87
+ function getMaxScrollHeight(doc = globalThis.document) {
88
+ if (doc?.body === void 0 || null === doc.body) return DEFAULT_MAX_SCROLL_HEIGHT;
89
+ const devicePixelRatio = doc.defaultView?.devicePixelRatio ?? 1;
90
+ const cachedValue = maxScrollHeightByDevicePixelRatio.get(devicePixelRatio);
91
+ if (void 0 !== cachedValue) return cachedValue;
92
+ const outer = doc.createElement("div");
93
+ outer.style.cssText = "position:absolute;top:-200px;left:-200px;width:50px;height:50px;overflow:scroll;visibility:hidden;";
94
+ const inner = doc.createElement("div");
95
+ inner.style.width = "1px";
96
+ outer.appendChild(inner);
97
+ doc.body.appendChild(outer);
98
+ const isHonoured = (height)=>{
99
+ inner.style.height = `${height}px`;
100
+ return outer.scrollHeight >= height - 1;
101
+ };
102
+ let lo = 0;
103
+ let hi = MAX_PROBE_HEIGHT;
104
+ while(hi - lo > 1){
105
+ const mid = Math.floor((lo + hi) / 2);
106
+ if (isHonoured(mid)) lo = mid;
107
+ else hi = mid;
108
+ }
109
+ inner.style.height = `${lo}px`;
110
+ const maxScrollHeight = Math.min(lo, outer.scrollHeight);
111
+ outer.remove();
112
+ if (maxScrollHeight > 0) {
113
+ maxScrollHeightByDevicePixelRatio.set(devicePixelRatio, maxScrollHeight);
114
+ return maxScrollHeight;
115
+ }
116
+ return DEFAULT_MAX_SCROLL_HEIGHT;
117
+ }
84
118
  const dispatchMouseEvent = (el, type)=>{
85
119
  const evt = new MouseEvent(type, {
86
120
  view: window,
@@ -105,4 +139,4 @@ const dispatchCustomEvent = (el, type)=>{
105
139
  });
106
140
  el.dispatchEvent(evt);
107
141
  };
108
- export { createEl, dispatchCustomEvent, dispatchKeyboardEvent, dispatchMouseEvent, focusFirstFocusableElement, getClosest, getClosestIndexItem, getElementByDataIndex, getElementDataIndex, getFocusableElement, getScrollbarSize, hasOpenOptionList, isDateInput, isInputElement, isSelectableElement, queryClosest };
142
+ export { DEFAULT_MAX_SCROLL_HEIGHT, createEl, dispatchCustomEvent, dispatchKeyboardEvent, dispatchMouseEvent, focusFirstFocusableElement, getClosest, getClosestIndexItem, getElementByDataIndex, getElementDataIndex, getFocusableElement, getMaxScrollHeight, getScrollbarSize, hasOpenOptionList, isDateInput, isInputElement, isSelectableElement, queryClosest };
package/src/index.js CHANGED
@@ -14,7 +14,6 @@ export * from "./datasource/datasource-utils.js";
14
14
  export * from "./date/index.js";
15
15
  export * from "./debug-utils.js";
16
16
  export * from "./event-emitter.js";
17
- export * from "./errors.js";
18
17
  export * from "./feature-utils.js";
19
18
  export * from "./filters/index.js";
20
19
  export * from "./form-utils.js";
package/src/keyset.js CHANGED
@@ -1,10 +1,14 @@
1
1
  const EMPTY = [];
2
2
  class KeySet {
3
3
  keys = new Map();
4
+ freeKeys = [];
4
5
  nextKeyValue = 0;
5
6
  range;
6
7
  constructor(range){
7
- this.range = range;
8
+ this.range = {
9
+ from: range.from,
10
+ to: range.to
11
+ };
8
12
  this.init(range);
9
13
  }
10
14
  next(free = EMPTY) {
@@ -13,6 +17,7 @@ class KeySet {
13
17
  }
14
18
  init({ from, to }) {
15
19
  this.keys.clear();
20
+ this.freeKeys.length = 0;
16
21
  this.nextKeyValue = 0;
17
22
  for(let rowIndex = from; rowIndex < to; rowIndex++){
18
23
  const nextKeyValue = this.next();
@@ -20,23 +25,24 @@ class KeySet {
20
25
  }
21
26
  return true;
22
27
  }
23
- reset(range) {
24
- const { from, to } = range;
25
- const newSize = to - from;
26
- const currentSize = this.range.to - this.range.from;
27
- this.range = range;
28
- if (currentSize > newSize) return this.init(range);
29
- const freeKeys = [];
28
+ reset({ from, to }) {
29
+ this.range = {
30
+ from,
31
+ to
32
+ };
33
+ const { freeKeys } = this;
30
34
  this.keys.forEach((keyValue, rowIndex)=>{
31
35
  if (rowIndex < from || rowIndex >= to) {
32
36
  freeKeys.push(keyValue);
33
37
  this.keys.delete(rowIndex);
34
38
  }
35
39
  });
40
+ let freeKeyIndex = 0;
36
41
  for(let rowIndex = from; rowIndex < to; rowIndex++)if (!this.keys.has(rowIndex)) {
37
- const nextKeyValue = this.next(freeKeys);
42
+ const nextKeyValue = freeKeyIndex < freeKeys.length ? freeKeys[freeKeyIndex++] : this.nextKeyValue++;
38
43
  this.keys.set(rowIndex, nextKeyValue);
39
44
  }
45
+ if (freeKeyIndex > 0) freeKeys.splice(0, freeKeyIndex);
40
46
  return false;
41
47
  }
42
48
  keyFor(rowIndex) {
@@ -1,8 +1,14 @@
1
1
  import { Children, isValidElement, useEffect, useMemo, useRef } from "react";
2
2
  const EMPTY_ARRAY = [];
3
3
  const asReactElements = (children)=>{
4
- const elements = Children.toArray(children).filter(isValidElement);
5
- return 0 === elements.length ? EMPTY_ARRAY : elements;
4
+ const isArray = Array.isArray(children);
5
+ const count = isArray ? children.length : Children.count(children);
6
+ if (isArray && children.every(isValidElement)) return children;
7
+ if (1 === count && !isArray && isValidElement(children)) return [
8
+ children
9
+ ];
10
+ if (count > 1) return children;
11
+ return EMPTY_ARRAY;
6
12
  };
7
13
  const useIsMounted = (id = "")=>{
8
14
  const isMountedRef = useRef(false);
@@ -1,3 +1,9 @@
1
+ const toSchemaColumn = ({ editable, name, required, serverDataType = "string" })=>({
2
+ editable,
3
+ name,
4
+ required,
5
+ serverDataType
6
+ });
1
7
  const getVuuTable = (schemaTable)=>{
2
8
  if (!schemaTable.session) return schemaTable;
3
9
  {
@@ -8,9 +14,4 @@ const getVuuTable = (schemaTable)=>{
8
14
  };
9
15
  }
10
16
  };
11
- const toSchemaColumn = ({ editable, name, serverDataType = 'string' })=>({
12
- editable: true === editable || 'object' == typeof editable,
13
- name,
14
- serverDataType
15
- });
16
17
  export { getVuuTable, toSchemaColumn };
@@ -29,7 +29,7 @@ const getTargetSize = (element, size, dimension)=>{
29
29
  return 0;
30
30
  }
31
31
  };
32
- const resizeObserver = new ResizeObserver((entries)=>{
32
+ const resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver((entries)=>{
33
33
  for (const entry of entries){
34
34
  const { target, borderBoxSize, contentBoxSize } = entry;
35
35
  const observedTarget = observedMap.get(target);
@@ -81,7 +81,7 @@ function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false)
81
81
  if (observedTarget) {
82
82
  const measurements = measure(target);
83
83
  observedTarget.measurements = measurements;
84
- resizeObserver.observe(target);
84
+ resizeObserver?.observe(target);
85
85
  if (reportInitialSize) onResize(measurements);
86
86
  } else console.log("%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation", "font-weight:bold; color:red;");
87
87
  }
@@ -93,7 +93,7 @@ function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false)
93
93
  }
94
94
  return ()=>{
95
95
  if (target && observedMap.has(target)) {
96
- resizeObserver.unobserve(target);
96
+ resizeObserver?.unobserve(target);
97
97
  observedMap.delete(target);
98
98
  }
99
99
  };
@@ -1 +1 @@
1
- var i=Symbol.for("preact-signals");function t(){if(!(h>1)){var i,t=!1;!function(){var i=c;c=void 0;while(void 0!==i){var t=i.S;if(t.v===i.v)for(var r=t.t;void 0!==r;r=r.x)if(r.i===i.i)r.i=t.i;i=i.o}}();while(void 0!==s){var r=s;s=void 0;v++;while(void 0!==r){var n=r.u;r.u=void 0;r.f&=-3;if(!(8&r.f)&&y(r))try{r.c()}catch(r){if(!t){i=r;t=!0}}r=n}}v=0;h--;if(t)throw i}else h--}function r(i){if(h>0)return i();u=++e;h++;try{return i()}finally{t()}}var n,o=void 0;function f(i){var t=o,r=n;o=void 0;n=void 0;try{return i()}finally{o=t;n=r}}var s=void 0,h=0,v=0,e=0,u=0,c=void 0,d=0;function a(i){if(void 0!==o){var t=i.n;if(void 0===t||t.t!==o){t={i:0,S:i,p:o.s,n:void 0,t:o,e:void 0,x:void 0,r:t};if(void 0!==o.s)o.s.n=t;o.s=t;i.n=t;if(32&o.f)i.S(t);return t}else if(-1===t.i){t.i=0;if(void 0!==t.n){t.n.p=t.p;if(void 0!==t.p)t.p.n=t.n;t.p=o.s;t.n=void 0;o.s.n=t;o.s=t}return t}}}function l(i,t){this.v=i;this.i=0;this.n=void 0;this.t=void 0;this.l=0;this.W=null==t?void 0:t.watched;this.Z=null==t?void 0:t.unwatched;this.name=null==t?void 0:t.name}l.prototype.brand=i;l.prototype.h=function(){return!0};l.prototype.S=function(i){var t=this,r=this.t;if(r!==i&&void 0===i.e){i.x=r;this.t=i;if(void 0!==r)r.e=i;else f(function(){var i;null==(i=t.W)||i.call(t)})}};l.prototype.U=function(i){var t=this;if(void 0!==this.t){var r=i.e,n=i.x;if(void 0!==r){r.x=n;i.e=void 0}if(void 0!==n){n.e=r;i.x=void 0}if(i===this.t){this.t=n;if(void 0===n)f(function(){var i;null==(i=t.Z)||i.call(t)})}}};l.prototype.subscribe=function(i){var t=this;return m(function(){var r=t.value;f(function(){return i(r)})},{name:"sub"})};l.prototype.valueOf=function(){return this.value};l.prototype.toString=function(){return this.value+""};l.prototype.toJSON=function(){return this.value};l.prototype.peek=function(){var i=this;return f(function(){return i.value})};Object.defineProperty(l.prototype,"value",{get:function(){var i=a(this);if(void 0!==i)i.i=this.i;return this.v},set:function(i){if(i!==this.v){if(v>100)throw new Error("Cycle detected");!function(i){if(0!==h&&0===v)if(i.l!==u){i.l=u;c={S:i,v:i.v,i:i.i,o:c}}}(this);this.v=i;this.i++;d++;h++;try{for(var r=this.t;void 0!==r;r=r.x)r.t.N()}finally{t()}}}});function y(i){for(var t=i.s;void 0!==t;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function w(i){for(var t=i.s;void 0!==t;t=t.n){var r=t.S.n;if(void 0!==r)t.r=r;t.S.n=t;t.i=-1;if(void 0===t.n){i.s=t;break}}}function p(i){var t=i.s,r=void 0;while(void 0!==t){var n=t.p;if(-1===t.i){t.S.U(t);if(void 0!==n)n.n=t.n;if(void 0!==t.n)t.n.p=n}else r=t;t.S.n=t.r;if(void 0!==t.r)t.r=void 0;t=n}i.s=r}function x(i,t){l.call(this,void 0,t);this.x=i;this.s=void 0;this.g=d-1;this.f=4}x.prototype=new l;x.prototype.h=function(){this.f&=-3;if(1&this.f)return!1;if(32==(36&this.f))return!0;this.f&=-5;if(this.g===d)return!0;this.g=d;this.f|=1;if(this.i>0&&!y(this)){this.f&=-2;return!0}var i=o;try{w(this);o=this;var t=this.x();if(16&this.f||this.v!==t||0===this.i){this.v=t;this.f&=-17;this.i++}}catch(i){this.v=i;this.f|=16;this.i++}o=i;p(this);this.f&=-2;return!0};x.prototype.S=function(i){if(void 0===this.t){this.f|=36;for(var t=this.s;void 0!==t;t=t.n)t.S.S(t)}l.prototype.S.call(this,i)};x.prototype.U=function(i){if(void 0!==this.t){l.prototype.U.call(this,i);if(void 0===this.t){this.f&=-33;for(var t=this.s;void 0!==t;t=t.n)t.S.U(t)}}};x.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var i=this.t;void 0!==i;i=i.x)i.t.N()}};Object.defineProperty(x.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var i=a(this);this.h();if(void 0!==i)i.i=this.i;if(16&this.f)throw this.v;return this.v}});function _(i){var r=i.m;i.m=void 0;if("function"==typeof r){h++;var n=o;o=void 0;try{r()}catch(t){i.f&=-2;i.f|=8;b(i);throw t}finally{o=n;t()}}}function b(i){for(var t=i.s;void 0!==t;t=t.n)t.S.U(t);i.x=void 0;i.s=void 0;_(i)}function g(i){if(o!==this)throw new Error("Out-of-order effect");p(this);o=i;this.f&=-2;if(8&this.f)b(this);t()}function S(i,t){this.x=i;this.m=void 0;this.s=void 0;this.u=void 0;this.f=32;this.name=null==t?void 0:t.name;if(n)n.push(this)}S.prototype.c=function(){var i=this.S();try{if(8&this.f)return;if(void 0===this.x)return;var t=this.x();if("function"==typeof t)this.m=t}finally{i()}};S.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1;this.f&=-9;_(this);w(this);h++;var i=o;o=this;return g.bind(this,i)};S.prototype.N=function(){if(!(2&this.f)){this.f|=2;this.u=s;s=this}};S.prototype.d=function(){this.f|=8;if(!(1&this.f))b(this)};S.prototype.dispose=function(){this.d()};function m(i,t){var r=new S(i,t);try{r.c()}catch(i){r.d();throw i}var n=r.d.bind(r);n[Symbol.dispose]=n;return n}function E(i){return function(){var t=arguments,n=this;return r(function(){return f(function(){return i.apply(n,[].slice.call(t))})})}}function j(){var i=n;n=[];return function(){var t=n;if(n&&i)i=i.concat(n);n=i;return t}}var C=function(i){for(var t in i){var r=i[t];if("function"==typeof r)i[t]=E(r);else if("object"==typeof r&&null!==r&&!("brand"in r))C(r)}};exports.Computed=x;exports.Effect=S;exports.Signal=l;exports.action=E;exports.batch=r;exports.computed=function(i,t){return new x(i,t)};exports.createModel=function(i){return function(){var t,r,o=j();try{r=i.apply(void 0,[].slice.call(arguments))}catch(i){n=void 0;throw i}finally{t=o()}C(r);r[Symbol.dispose]=E(function(){if(t)for(var i=0;i<t.length;i++)t[i].dispose();t=void 0});return r}};exports.effect=m;exports.signal=function(i,t){return new l(i,t)};exports.untracked=f;//# sourceMappingURL=signals-core.js.map
1
+ var i=Symbol.for("preact-signals");function t(){if(!(h>1)){var i,t=!1;while(void 0!==n){var r=n;n=void 0;s++;while(void 0!==r){var o=r.o;r.o=void 0;r.f&=-3;if(!(8&r.f)&&u(r))try{r.c()}catch(r){if(!t){i=r;t=!0}}r=o}}s=0;h--;if(t)throw i}else h--}var r=void 0;function o(i){var t=r;r=void 0;try{return i()}finally{r=t}}var n=void 0,h=0,s=0,f=0;function v(i){if(void 0!==r){var t=i.n;if(void 0===t||t.t!==r){t={i:0,S:i,p:r.s,n:void 0,t:r,e:void 0,x:void 0,r:t};if(void 0!==r.s)r.s.n=t;r.s=t;i.n=t;if(32&r.f)i.S(t);return t}else if(-1===t.i){t.i=0;if(void 0!==t.n){t.n.p=t.p;if(void 0!==t.p)t.p.n=t.n;t.p=r.s;t.n=void 0;r.s.n=t;r.s=t}return t}}}function e(i,t){this.v=i;this.i=0;this.n=void 0;this.t=void 0;this.W=null==t?void 0:t.watched;this.Z=null==t?void 0:t.unwatched}e.prototype.brand=i;e.prototype.h=function(){return!0};e.prototype.S=function(i){var t=this,r=this.t;if(r!==i&&void 0===i.e){i.x=r;this.t=i;if(void 0!==r)r.e=i;else o(function(){var i;null==(i=t.W)||i.call(t)})}};e.prototype.U=function(i){var t=this;if(void 0!==this.t){var r=i.e,n=i.x;if(void 0!==r){r.x=n;i.e=void 0}if(void 0!==n){n.e=r;i.x=void 0}if(i===this.t){this.t=n;if(void 0===n)o(function(){var i;null==(i=t.Z)||i.call(t)})}}};e.prototype.subscribe=function(i){var t=this;return x(function(){var o=t.value,n=r;r=void 0;try{i(o)}finally{r=n}})};e.prototype.valueOf=function(){return this.value};e.prototype.toString=function(){return this.value+""};e.prototype.toJSON=function(){return this.value};e.prototype.peek=function(){var i=r;r=void 0;try{return this.value}finally{r=i}};Object.defineProperty(e.prototype,"value",{get:function(){var i=v(this);if(void 0!==i)i.i=this.i;return this.v},set:function(i){if(i!==this.v){if(s>100)throw new Error("Cycle detected");this.v=i;this.i++;f++;h++;try{for(var r=this.t;void 0!==r;r=r.x)r.t.N()}finally{t()}}}});function u(i){for(var t=i.s;void 0!==t;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function d(i){for(var t=i.s;void 0!==t;t=t.n){var r=t.S.n;if(void 0!==r)t.r=r;t.S.n=t;t.i=-1;if(void 0===t.n){i.s=t;break}}}function c(i){var t=i.s,r=void 0;while(void 0!==t){var o=t.p;if(-1===t.i){t.S.U(t);if(void 0!==o)o.n=t.n;if(void 0!==t.n)t.n.p=o}else r=t;t.S.n=t.r;if(void 0!==t.r)t.r=void 0;t=o}i.s=r}function a(i,t){e.call(this,void 0);this.x=i;this.s=void 0;this.g=f-1;this.f=4;this.W=null==t?void 0:t.watched;this.Z=null==t?void 0:t.unwatched}a.prototype=new e;a.prototype.h=function(){this.f&=-3;if(1&this.f)return!1;if(32==(36&this.f))return!0;this.f&=-5;if(this.g===f)return!0;this.g=f;this.f|=1;if(this.i>0&&!u(this)){this.f&=-2;return!0}var i=r;try{d(this);r=this;var t=this.x();if(16&this.f||this.v!==t||0===this.i){this.v=t;this.f&=-17;this.i++}}catch(i){this.v=i;this.f|=16;this.i++}r=i;c(this);this.f&=-2;return!0};a.prototype.S=function(i){if(void 0===this.t){this.f|=36;for(var t=this.s;void 0!==t;t=t.n)t.S.S(t)}e.prototype.S.call(this,i)};a.prototype.U=function(i){if(void 0!==this.t){e.prototype.U.call(this,i);if(void 0===this.t){this.f&=-33;for(var t=this.s;void 0!==t;t=t.n)t.S.U(t)}}};a.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var i=this.t;void 0!==i;i=i.x)i.t.N()}};Object.defineProperty(a.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var i=v(this);this.h();if(void 0!==i)i.i=this.i;if(16&this.f)throw this.v;return this.v}});function l(i){var o=i.u;i.u=void 0;if("function"==typeof o){h++;var n=r;r=void 0;try{o()}catch(t){i.f&=-2;i.f|=8;y(i);throw t}finally{r=n;t()}}}function y(i){for(var t=i.s;void 0!==t;t=t.n)t.S.U(t);i.x=void 0;i.s=void 0;l(i)}function w(i){if(r!==this)throw new Error("Out-of-order effect");c(this);r=i;this.f&=-2;if(8&this.f)y(this);t()}function p(i){this.x=i;this.u=void 0;this.s=void 0;this.o=void 0;this.f=32}p.prototype.c=function(){var i=this.S();try{if(8&this.f)return;if(void 0===this.x)return;var t=this.x();if("function"==typeof t)this.u=t}finally{i()}};p.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1;this.f&=-9;l(this);d(this);h++;var i=r;r=this;return w.bind(this,i)};p.prototype.N=function(){if(!(2&this.f)){this.f|=2;this.o=n;n=this}};p.prototype.d=function(){this.f|=8;if(!(1&this.f))y(this)};p.prototype.dispose=function(){this.d()};function x(i){var t=new p(i);try{t.c()}catch(i){t.d();throw i}var r=t.d.bind(t);r[Symbol.dispose]=r;return r}exports.Signal=e;exports.batch=function(i){if(h>0)return i();h++;try{return i()}finally{t()}};exports.computed=function(i,t){return new a(i,t)};exports.effect=x;exports.signal=function(i,t){return new e(i,t)};exports.untracked=o;//# sourceMappingURL=signals-core.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals-core.js","sources":["../src/index.ts"],"sourcesContent":["// An named symbol/brand for detecting Signal instances even when they weren't\n// created using the same signals library version.\nconst BRAND_SYMBOL = Symbol.for(\"preact-signals\");\n\n// Flags for Computed and Effect.\nconst RUNNING = 1 << 0;\nconst NOTIFIED = 1 << 1;\nconst OUTDATED = 1 << 2;\nconst DISPOSED = 1 << 3;\nconst HAS_ERROR = 1 << 4;\nconst TRACKING = 1 << 5;\n\n// A linked list node used to track dependencies (sources) and dependents (targets).\n// Also used to remember the source's last version number that the target saw.\ntype Node = {\n\t// A source whose value the target depends on.\n\t_source: Signal;\n\t_prevSource?: Node;\n\t_nextSource?: Node;\n\n\t// A target that depends on the source and should be notified when the source changes.\n\t_target: Computed | Effect;\n\t_prevTarget?: Node;\n\t_nextTarget?: Node;\n\n\t// The version number of the source that target has last seen. We use version numbers\n\t// instead of storing the source value, because source values can take arbitrary amount\n\t// of memory, and computeds could hang on to them forever because they're lazily evaluated.\n\t// Use the special value -1 to mark potentially unused but recyclable nodes.\n\t_version: number;\n\n\t// Used to remember & roll back the source's previous `._node` value when entering &\n\t// exiting a new evaluation context.\n\t_rollbackNode?: Node;\n};\n\nfunction startBatch() {\n\tbatchDepth++;\n}\n\nfunction endBatch() {\n\tif (batchDepth > 1) {\n\t\tbatchDepth--;\n\t\treturn;\n\t}\n\n\tlet error: unknown;\n\tlet hasError = false;\n\treconcileBatchSnapshots();\n\n\twhile (batchedEffect !== undefined) {\n\t\tlet effect: Effect | undefined = batchedEffect;\n\t\tbatchedEffect = undefined;\n\n\t\tbatchIteration++;\n\n\t\twhile (effect !== undefined) {\n\t\t\tconst next: Effect | undefined = effect._nextBatchedEffect;\n\t\t\teffect._nextBatchedEffect = undefined;\n\t\t\teffect._flags &= ~NOTIFIED;\n\n\t\t\tif (!(effect._flags & DISPOSED) && needsToRecompute(effect)) {\n\t\t\t\ttry {\n\t\t\t\t\teffect._callback();\n\t\t\t\t} catch (err) {\n\t\t\t\t\tif (!hasError) {\n\t\t\t\t\t\terror = err;\n\t\t\t\t\t\thasError = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\teffect = next;\n\t\t}\n\t}\n\tbatchIteration = 0;\n\tbatchDepth--;\n\n\tif (hasError) {\n\t\tthrow error;\n\t}\n}\n\n/**\n * Combine multiple value updates into one \"commit\" at the end of the provided callback.\n *\n * Batches can be nested and changes are only flushed once the outermost batch callback\n * completes.\n *\n * Accessing a signal that has been modified within a batch will reflect its updated\n * value.\n *\n * @param fn The callback function.\n * @returns The value returned by the callback.\n */\nfunction batch<T>(fn: () => T): T {\n\tif (batchDepth > 0) {\n\t\treturn fn();\n\t}\n\tcurrentBatchSnapshotVersion = ++batchSnapshotVersion;\n\t/*@__INLINE__**/ startBatch();\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\tendBatch();\n\t}\n}\n\n// Currently evaluated computed or effect.\nlet evalContext: Computed | Effect | undefined = undefined;\n\n// Effects captured while constructing a model instance.\nlet capturedEffects: Effect[] | undefined;\n\n/**\n * Run a callback function that can access signal values without\n * subscribing to the signal updates.\n *\n * When called inside a `createModel` factory, this also suppresses\n * model-owned effect capture. Effects created inside the callback will not\n * be owned by the surrounding model and must be disposed manually. Nested\n * `createModel` calls inside the callback still capture their own effects.\n *\n * @param fn The callback function.\n * @returns The value returned by the callback.\n */\nfunction untracked<T>(fn: () => T): T {\n\tconst prevContext = evalContext;\n\tconst prevCapturedEffects = capturedEffects;\n\n\tevalContext = undefined;\n\t// Model effect capture is another kind of ambient tracking. Suppress it in\n\t// untracked callbacks while still allowing nested createModel() calls to\n\t// establish their own capture scope.\n\tcapturedEffects = undefined;\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\tevalContext = prevContext;\n\t\tcapturedEffects = prevCapturedEffects;\n\t}\n}\n\n// Effects collected into a batch.\nlet batchedEffect: Effect | undefined = undefined;\nlet batchDepth = 0;\nlet batchIteration = 0;\n\ntype BatchSnapshot = {\n\t_source: Signal;\n\t_value: unknown;\n\t_version: number;\n\t_next?: BatchSnapshot;\n};\n\nlet batchSnapshotVersion = 0;\nlet currentBatchSnapshotVersion = 0;\nlet batchSnapshots: BatchSnapshot | undefined = undefined;\n\n// A global version number for signals, used for fast-pathing repeated\n// computed.peek()/computed.value calls when nothing has changed globally.\nlet globalVersion = 0;\n\nfunction recordBatchSnapshot(source: Signal) {\n\t// Only capture writes during the user-visible batch callback, not during effect flush.\n\tif (batchDepth === 0 || batchIteration !== 0) {\n\t\treturn;\n\t}\n\n\tif (source._batchSnapshotVersion !== currentBatchSnapshotVersion) {\n\t\tsource._batchSnapshotVersion = currentBatchSnapshotVersion;\n\t\tbatchSnapshots = {\n\t\t\t_source: source,\n\t\t\t_value: source._value,\n\t\t\t_version: source._version,\n\t\t\t_next: batchSnapshots,\n\t\t};\n\t}\n}\n\nfunction reconcileBatchSnapshots() {\n\tlet snapshots = batchSnapshots;\n\tbatchSnapshots = undefined;\n\n\twhile (snapshots !== undefined) {\n\t\tconst source = snapshots._source;\n\t\tif (source._value === snapshots._value) {\n\t\t\t// The value was reverted to its pre-batch state. Version numbers must\n\t\t\t// stay monotonic: a lazy computed may have observed an intermediate\n\t\t\t// version during the batch, and rolling the version back would let a\n\t\t\t// future write re-mint that observed number for a different value,\n\t\t\t// making the computed treat it as unchanged forever. Instead,\n\t\t\t// fast-forward subscribers that last saw the pre-batch version so\n\t\t\t// they skip recomputing for the no-op change.\n\t\t\tfor (\n\t\t\t\tlet node = source._targets;\n\t\t\t\tnode !== undefined;\n\t\t\t\tnode = node._nextTarget\n\t\t\t) {\n\t\t\t\tif (node._version === snapshots._version) {\n\t\t\t\t\tnode._version = source._version;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tsnapshots = snapshots._next;\n\t}\n}\n\nfunction addDependency(signal: Signal): Node | undefined {\n\tif (evalContext === undefined) {\n\t\treturn undefined;\n\t}\n\n\tlet node = signal._node;\n\tif (node === undefined || node._target !== evalContext) {\n\t\t/**\n\t\t * `signal` is a new dependency. Create a new dependency node, and set it\n\t\t * as the tail of the current context's dependency list. e.g:\n\t\t *\n\t\t * { A <-> B }\n\t\t * ↑ ↑\n\t\t * tail node (new)\n\t\t * ↓\n\t\t * { A <-> B <-> C }\n\t\t * ↑\n\t\t * tail (evalContext._sources)\n\t\t */\n\t\tnode = {\n\t\t\t_version: 0,\n\t\t\t_source: signal,\n\t\t\t_prevSource: evalContext._sources,\n\t\t\t_nextSource: undefined,\n\t\t\t_target: evalContext,\n\t\t\t_prevTarget: undefined,\n\t\t\t_nextTarget: undefined,\n\t\t\t_rollbackNode: node,\n\t\t};\n\n\t\tif (evalContext._sources !== undefined) {\n\t\t\tevalContext._sources._nextSource = node;\n\t\t}\n\t\tevalContext._sources = node;\n\t\tsignal._node = node;\n\n\t\t// Subscribe to change notifications from this dependency if we're in an effect\n\t\t// OR evaluating a computed signal that in turn has subscribers.\n\t\tif (evalContext._flags & TRACKING) {\n\t\t\tsignal._subscribe(node);\n\t\t}\n\t\treturn node;\n\t} else if (node._version === -1) {\n\t\t// `signal` is an existing dependency from a previous evaluation. Reuse it.\n\t\tnode._version = 0;\n\n\t\t/**\n\t\t * If `node` is not already the current tail of the dependency list (i.e.\n\t\t * there is a next node in the list), then make the `node` the new tail. e.g:\n\t\t *\n\t\t * { A <-> B <-> C <-> D }\n\t\t * ↑ ↑\n\t\t * node ┌─── tail (evalContext._sources)\n\t\t * └─────│─────┐\n\t\t * ↓ ↓\n\t\t * { A <-> C <-> D <-> B }\n\t\t * ↑\n\t\t * tail (evalContext._sources)\n\t\t */\n\t\tif (node._nextSource !== undefined) {\n\t\t\tnode._nextSource._prevSource = node._prevSource;\n\n\t\t\tif (node._prevSource !== undefined) {\n\t\t\t\tnode._prevSource._nextSource = node._nextSource;\n\t\t\t}\n\n\t\t\tnode._prevSource = evalContext._sources;\n\t\t\tnode._nextSource = undefined;\n\n\t\t\tevalContext._sources!._nextSource = node;\n\t\t\tevalContext._sources = node;\n\t\t}\n\n\t\t// We can assume that the currently evaluated effect / computed signal is already\n\t\t// subscribed to change notifications from `signal` if needed.\n\t\treturn node;\n\t}\n\treturn undefined;\n}\n\n//#region Signal\n\n/**\n * The base class for plain and computed signals.\n */\n//\n// A function with the same name is defined later, so we need to ignore TypeScript's\n// warning about a redeclared variable.\n//\n// The class is declared here, but later implemented with ES5-style prototypes.\n// This enables better control of the transpiled output size.\n// @ts-ignore: \"Cannot redeclare exported variable 'Signal'.\"\ndeclare class Signal<T = any> {\n\t/** @internal */\n\t_value: unknown;\n\n\t/**\n\t * @internal\n\t * Version numbers should always be >= 0, because the special value -1 is used\n\t * by Nodes to signify potentially unused but recyclable nodes.\n\t */\n\t_version: number;\n\n\t/** @internal */\n\t_node?: Node;\n\n\t/** @internal */\n\t_targets?: Node;\n\n\t/** @internal */\n\t_batchSnapshotVersion: number;\n\n\tconstructor(value?: T, options?: SignalOptions<T>);\n\n\t/** @internal */\n\t_refresh(): boolean;\n\n\t/** @internal */\n\t_subscribe(node: Node): void;\n\n\t/** @internal */\n\t_unsubscribe(node: Node): void;\n\n\t/** @internal */\n\t_watched?(this: Signal<T>): void;\n\n\t/** @internal */\n\t_unwatched?(this: Signal<T>): void;\n\n\tsubscribe(fn: (value: T) => void): () => void;\n\n\tname?: string;\n\n\tvalueOf(): T;\n\n\ttoString(): string;\n\n\ttoJSON(): T;\n\n\tpeek(): T;\n\n\tbrand: typeof BRAND_SYMBOL;\n\n\tget value(): T;\n\tset value(value: T);\n}\n\nexport interface SignalOptions<T = any> {\n\twatched?: (this: Signal<T>) => void;\n\tunwatched?: (this: Signal<T>) => void;\n\tname?: string;\n}\n\n/** @internal */\n// A class with the same name has already been declared, so we need to ignore\n// TypeScript's warning about a redeclared variable.\n//\n// The previously declared class is implemented here with ES5-style prototypes.\n// This enables better control of the transpiled output size.\n// @ts-ignore: \"Cannot redeclare exported variable 'Signal'.\"\nfunction Signal(this: Signal, value?: unknown, options?: SignalOptions) {\n\tthis._value = value;\n\tthis._version = 0;\n\tthis._node = undefined;\n\tthis._targets = undefined;\n\tthis._batchSnapshotVersion = 0;\n\tthis._watched = options?.watched;\n\tthis._unwatched = options?.unwatched;\n\tthis.name = options?.name;\n}\n\nSignal.prototype.brand = BRAND_SYMBOL;\n\nSignal.prototype._refresh = function () {\n\treturn true;\n};\n\nSignal.prototype._subscribe = function (node) {\n\tconst targets = this._targets;\n\tif (targets !== node && node._prevTarget === undefined) {\n\t\tnode._nextTarget = targets;\n\t\tthis._targets = node;\n\n\t\tif (targets !== undefined) {\n\t\t\ttargets._prevTarget = node;\n\t\t} else {\n\t\t\tuntracked(() => {\n\t\t\t\tthis._watched?.call(this);\n\t\t\t});\n\t\t}\n\t}\n};\n\nSignal.prototype._unsubscribe = function (node) {\n\t// Only run the unsubscribe step if the signal has any subscribers to begin with.\n\tif (this._targets !== undefined) {\n\t\tconst prev = node._prevTarget;\n\t\tconst next = node._nextTarget;\n\t\tif (prev !== undefined) {\n\t\t\tprev._nextTarget = next;\n\t\t\tnode._prevTarget = undefined;\n\t\t}\n\n\t\tif (next !== undefined) {\n\t\t\tnext._prevTarget = prev;\n\t\t\tnode._nextTarget = undefined;\n\t\t}\n\n\t\tif (node === this._targets) {\n\t\t\tthis._targets = next;\n\t\t\tif (next === undefined) {\n\t\t\t\tuntracked(() => {\n\t\t\t\t\tthis._unwatched?.call(this);\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n};\n\nSignal.prototype.subscribe = function (fn) {\n\treturn effect(\n\t\t() => {\n\t\t\tconst value = this.value;\n\t\t\tuntracked(() => fn(value));\n\t\t},\n\t\t{ name: \"sub\" }\n\t);\n};\n\nSignal.prototype.valueOf = function () {\n\treturn this.value;\n};\n\nSignal.prototype.toString = function () {\n\treturn this.value + \"\";\n};\n\nSignal.prototype.toJSON = function () {\n\treturn this.value;\n};\n\nSignal.prototype.peek = function () {\n\treturn untracked(() => this.value);\n};\n\nObject.defineProperty(Signal.prototype, \"value\", {\n\tget(this: Signal) {\n\t\tconst node = addDependency(this);\n\t\tif (node !== undefined) {\n\t\t\tnode._version = this._version;\n\t\t}\n\t\treturn this._value;\n\t},\n\tset(this: Signal, value) {\n\t\tif (value !== this._value) {\n\t\t\tif (batchIteration > 100) {\n\t\t\t\tthrow new Error(\"Cycle detected\");\n\t\t\t}\n\n\t\t\trecordBatchSnapshot(this);\n\t\t\tthis._value = value;\n\t\t\tthis._version++;\n\t\t\tglobalVersion++;\n\n\t\t\t/**@__INLINE__*/ startBatch();\n\t\t\ttry {\n\t\t\t\tfor (\n\t\t\t\t\tlet node = this._targets;\n\t\t\t\t\tnode !== undefined;\n\t\t\t\t\tnode = node._nextTarget\n\t\t\t\t) {\n\t\t\t\t\tnode._target._notify();\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tendBatch();\n\t\t\t}\n\t\t}\n\t},\n});\n\n/**\n * Create a new plain signal.\n *\n * @param value The initial value for the signal.\n * @returns A new signal.\n */\nexport function signal<T>(value: T, options?: SignalOptions<T>): Signal<T>;\nexport function signal<T = undefined>(): Signal<T | undefined>;\nexport function signal<T>(value?: T, options?: SignalOptions<T>): Signal<T> {\n\treturn new Signal(value, options);\n}\n\n//#endregion Signal\n\n//#region Computed\n\nfunction needsToRecompute(target: Computed | Effect): boolean {\n\t// Check the dependencies for changed values. The dependency list is already\n\t// in order of use. Therefore if multiple dependencies have changed values, only\n\t// the first used dependency is re-evaluated at this point.\n\tfor (\n\t\tlet node = target._sources;\n\t\tnode !== undefined;\n\t\tnode = node._nextSource\n\t) {\n\t\tif (\n\t\t\t// If the dependency has definitely been updated since its version number\n\t\t\t// was observed, then we need to recompute. This first check is not strictly\n\t\t\t// necessary for correctness, but allows us to skip the refresh call if the\n\t\t\t// dependency has already been updated.\n\t\t\tnode._source._version !== node._version ||\n\t\t\t// Refresh the dependency. If there's something blocking the refresh (e.g. a\n\t\t\t// dependency cycle), then we need to recompute.\n\t\t\t!node._source._refresh() ||\n\t\t\t// If the dependency got a new version after the refresh, then we need to recompute.\n\t\t\tnode._source._version !== node._version\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t}\n\t// If none of the dependencies have changed values since last recompute then\n\t// there's no need to recompute.\n\treturn false;\n}\n\nfunction prepareSources(target: Computed | Effect) {\n\t/**\n\t * 1. Mark all current sources as re-usable nodes (version: -1)\n\t * 2. Set a rollback node if the current node is being used in a different context\n\t * 3. Point 'target._sources' to the tail of the doubly-linked list, e.g:\n\t *\n\t * { undefined <- A <-> B <-> C -> undefined }\n\t * ↑ ↑\n\t * │ └──────┐\n\t * target._sources = A; (node is head) │\n\t * ↓ │\n\t * target._sources = C; (node is tail) ─┘\n\t */\n\tfor (\n\t\tlet node = target._sources;\n\t\tnode !== undefined;\n\t\tnode = node._nextSource\n\t) {\n\t\tconst rollbackNode = node._source._node;\n\t\tif (rollbackNode !== undefined) {\n\t\t\tnode._rollbackNode = rollbackNode;\n\t\t}\n\t\tnode._source._node = node;\n\t\tnode._version = -1;\n\n\t\tif (node._nextSource === undefined) {\n\t\t\ttarget._sources = node;\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfunction cleanupSources(target: Computed | Effect) {\n\tlet node = target._sources;\n\tlet head: Node | undefined = undefined;\n\n\t/**\n\t * At this point 'target._sources' points to the tail of the doubly-linked list.\n\t * It contains all existing sources + new sources in order of use.\n\t * Iterate backwards until we find the head node while dropping old dependencies.\n\t */\n\twhile (node !== undefined) {\n\t\tconst prev = node._prevSource;\n\n\t\t/**\n\t\t * The node was not re-used, unsubscribe from its change notifications and remove itself\n\t\t * from the doubly-linked list. e.g:\n\t\t *\n\t\t * { A <-> B <-> C }\n\t\t * ↓\n\t\t * { A <-> C }\n\t\t */\n\t\tif (node._version === -1) {\n\t\t\tnode._source._unsubscribe(node);\n\n\t\t\tif (prev !== undefined) {\n\t\t\t\tprev._nextSource = node._nextSource;\n\t\t\t}\n\t\t\tif (node._nextSource !== undefined) {\n\t\t\t\tnode._nextSource._prevSource = prev;\n\t\t\t}\n\t\t} else {\n\t\t\t/**\n\t\t\t * The new head is the last node seen which wasn't removed/unsubscribed\n\t\t\t * from the doubly-linked list. e.g:\n\t\t\t *\n\t\t\t * { A <-> B <-> C }\n\t\t\t * ↑ ↑ ↑\n\t\t\t * │ │ └ head = node\n\t\t\t * │ └ head = node\n\t\t\t * └ head = node\n\t\t\t */\n\t\t\thead = node;\n\t\t}\n\n\t\tnode._source._node = node._rollbackNode;\n\t\tif (node._rollbackNode !== undefined) {\n\t\t\tnode._rollbackNode = undefined;\n\t\t}\n\n\t\tnode = prev;\n\t}\n\n\ttarget._sources = head;\n}\n\n/**\n * The base class for computed signals.\n */\ndeclare class Computed<T = any> extends Signal<T> {\n\t_fn: () => T;\n\t_sources?: Node;\n\t_globalVersion: number;\n\t_flags: number;\n\n\tconstructor(fn: () => T, options?: SignalOptions<T>);\n\n\t_notify(): void;\n\tget value(): T;\n}\n\n/** @internal */\nfunction Computed(this: Computed, fn: () => unknown, options?: SignalOptions) {\n\tSignal.call(this, undefined, options);\n\n\tthis._fn = fn;\n\tthis._sources = undefined;\n\tthis._globalVersion = globalVersion - 1;\n\tthis._flags = OUTDATED;\n}\n\nComputed.prototype = new Signal() as Computed;\n\nComputed.prototype._refresh = function () {\n\tthis._flags &= ~NOTIFIED;\n\n\tif (this._flags & RUNNING) {\n\t\treturn false;\n\t}\n\n\t// If this computed signal has subscribed to updates from its dependencies\n\t// (TRACKING flag set) and none of them have notified about changes (OUTDATED\n\t// flag not set), then the computed value can't have changed.\n\tif ((this._flags & (OUTDATED | TRACKING)) === TRACKING) {\n\t\treturn true;\n\t}\n\tthis._flags &= ~OUTDATED;\n\n\tif (this._globalVersion === globalVersion) {\n\t\treturn true;\n\t}\n\tthis._globalVersion = globalVersion;\n\n\t// Mark this computed signal running before checking the dependencies for value\n\t// changes, so that the RUNNING flag can be used to notice cyclical dependencies.\n\tthis._flags |= RUNNING;\n\tif (this._version > 0 && !needsToRecompute(this)) {\n\t\tthis._flags &= ~RUNNING;\n\t\treturn true;\n\t}\n\n\tconst prevContext = evalContext;\n\ttry {\n\t\tprepareSources(this);\n\t\tevalContext = this;\n\t\tconst value = this._fn();\n\t\tif (\n\t\t\tthis._flags & HAS_ERROR ||\n\t\t\tthis._value !== value ||\n\t\t\tthis._version === 0\n\t\t) {\n\t\t\tthis._value = value;\n\t\t\tthis._flags &= ~HAS_ERROR;\n\t\t\tthis._version++;\n\t\t}\n\t} catch (err) {\n\t\tthis._value = err;\n\t\tthis._flags |= HAS_ERROR;\n\t\tthis._version++;\n\t}\n\tevalContext = prevContext;\n\tcleanupSources(this);\n\tthis._flags &= ~RUNNING;\n\treturn true;\n};\n\nComputed.prototype._subscribe = function (node) {\n\tif (this._targets === undefined) {\n\t\tthis._flags |= OUTDATED | TRACKING;\n\n\t\t// A computed signal subscribes lazily to its dependencies when it\n\t\t// gets its first subscriber.\n\t\tfor (\n\t\t\tlet node = this._sources;\n\t\t\tnode !== undefined;\n\t\t\tnode = node._nextSource\n\t\t) {\n\t\t\tnode._source._subscribe(node);\n\t\t}\n\t}\n\tSignal.prototype._subscribe.call(this, node);\n};\n\nComputed.prototype._unsubscribe = function (node) {\n\t// Only run the unsubscribe step if the computed signal has any subscribers.\n\tif (this._targets !== undefined) {\n\t\tSignal.prototype._unsubscribe.call(this, node);\n\n\t\t// Computed signal unsubscribes from its dependencies when it loses its last subscriber.\n\t\t// This makes it possible for unreferences subgraphs of computed signals to get garbage collected.\n\t\tif (this._targets === undefined) {\n\t\t\tthis._flags &= ~TRACKING;\n\n\t\t\tfor (\n\t\t\t\tlet node = this._sources;\n\t\t\t\tnode !== undefined;\n\t\t\t\tnode = node._nextSource\n\t\t\t) {\n\t\t\t\tnode._source._unsubscribe(node);\n\t\t\t}\n\t\t}\n\t}\n};\n\nComputed.prototype._notify = function () {\n\tif (!(this._flags & NOTIFIED)) {\n\t\tthis._flags |= OUTDATED | NOTIFIED;\n\n\t\tfor (\n\t\t\tlet node = this._targets;\n\t\t\tnode !== undefined;\n\t\t\tnode = node._nextTarget\n\t\t) {\n\t\t\tnode._target._notify();\n\t\t}\n\t}\n};\n\nObject.defineProperty(Computed.prototype, \"value\", {\n\tget(this: Computed) {\n\t\tif (this._flags & RUNNING) {\n\t\t\tthrow new Error(\"Cycle detected\");\n\t\t}\n\t\tconst node = addDependency(this);\n\t\tthis._refresh();\n\t\tif (node !== undefined) {\n\t\t\tnode._version = this._version;\n\t\t}\n\t\tif (this._flags & HAS_ERROR) {\n\t\t\tthrow this._value;\n\t\t}\n\t\treturn this._value;\n\t},\n});\n\n/**\n * An interface for read-only signals.\n */\ninterface ReadonlySignal<T = any> {\n\treadonly value: T;\n\tpeek(): T;\n\n\tsubscribe(fn: (value: T) => void): () => void;\n\tvalueOf(): T;\n\ttoString(): string;\n\ttoJSON(): T;\n\tbrand: typeof BRAND_SYMBOL;\n}\n\n/**\n * Create a new signal that is computed based on the values of other signals.\n *\n * The returned computed signal is read-only, and its value is automatically\n * updated when any signals accessed from within the callback function change.\n *\n * @param fn The effect callback.\n * @returns A new read-only signal.\n */\nfunction computed<T>(\n\tfn: () => T,\n\toptions?: SignalOptions<T>\n): ReadonlySignal<T> {\n\treturn new Computed(fn, options);\n}\n\n//#endregion Computed\n\n//#region Effect\n\nfunction cleanupEffect(effect: Effect) {\n\tconst cleanup = effect._cleanup;\n\teffect._cleanup = undefined;\n\n\tif (typeof cleanup === \"function\") {\n\t\t/*@__INLINE__**/ startBatch();\n\n\t\t// Run cleanup functions always outside of any context.\n\t\tconst prevContext = evalContext;\n\t\tevalContext = undefined;\n\t\ttry {\n\t\t\tcleanup();\n\t\t} catch (err) {\n\t\t\teffect._flags &= ~RUNNING;\n\t\t\teffect._flags |= DISPOSED;\n\t\t\tdisposeEffect(effect);\n\t\t\tthrow err;\n\t\t} finally {\n\t\t\tevalContext = prevContext;\n\t\t\tendBatch();\n\t\t}\n\t}\n}\n\nfunction disposeEffect(effect: Effect) {\n\tfor (\n\t\tlet node = effect._sources;\n\t\tnode !== undefined;\n\t\tnode = node._nextSource\n\t) {\n\t\tnode._source._unsubscribe(node);\n\t}\n\teffect._fn = undefined;\n\teffect._sources = undefined;\n\n\tcleanupEffect(effect);\n}\n\nfunction endEffect(this: Effect, prevContext?: Computed | Effect) {\n\tif (evalContext !== this) {\n\t\tthrow new Error(\"Out-of-order effect\");\n\t}\n\tcleanupSources(this);\n\tevalContext = prevContext;\n\n\tthis._flags &= ~RUNNING;\n\tif (this._flags & DISPOSED) {\n\t\tdisposeEffect(this);\n\t}\n\tendBatch();\n}\n\ntype EffectFn =\n\t| ((this: { dispose: () => void }) => void | (() => void))\n\t| (() => void | (() => void));\n\n// Avoid hard-requiring the ESNext.Disposable lib in consuming tsconfigs.\n// When `Symbol.dispose` is available, this becomes a symbol-keyed disposer type.\ntype DisposeSymbol = typeof Symbol extends { readonly dispose: infer TDispose }\n\t? TDispose\n\t: never;\ntype DisposableLike = {\n\t[K in DisposeSymbol & PropertyKey]: () => void;\n};\ntype DisposeFn = (() => void) & DisposableLike;\n\n/**\n * The base class for reactive effects.\n */\ndeclare class Effect {\n\t_fn?: EffectFn;\n\t_cleanup?: () => void;\n\t_sources?: Node;\n\t_nextBatchedEffect?: Effect;\n\t_flags: number;\n\t_debugCallback?: () => void;\n\tname?: string;\n\n\tconstructor(fn: EffectFn, options?: EffectOptions);\n\n\t_callback(): void;\n\t_start(): () => void;\n\t_notify(): void;\n\t_dispose(): void;\n\tdispose(): void;\n}\n\nexport interface EffectOptions {\n\tname?: string;\n}\n\n/** @internal */\nfunction Effect(this: Effect, fn: EffectFn, options?: EffectOptions) {\n\tthis._fn = fn;\n\tthis._cleanup = undefined;\n\tthis._sources = undefined;\n\tthis._nextBatchedEffect = undefined;\n\tthis._flags = TRACKING;\n\tthis.name = options?.name;\n\n\tif (capturedEffects) {\n\t\tcapturedEffects.push(this);\n\t}\n}\n\nEffect.prototype._callback = function () {\n\tconst finish = this._start();\n\ttry {\n\t\tif (this._flags & DISPOSED) return;\n\t\tif (this._fn === undefined) return;\n\n\t\tconst cleanup = this._fn();\n\t\tif (typeof cleanup === \"function\") {\n\t\t\tthis._cleanup = cleanup;\n\t\t}\n\t} finally {\n\t\tfinish();\n\t}\n};\n\nEffect.prototype._start = function () {\n\tif (this._flags & RUNNING) {\n\t\tthrow new Error(\"Cycle detected\");\n\t}\n\tthis._flags |= RUNNING;\n\tthis._flags &= ~DISPOSED;\n\tcleanupEffect(this);\n\tprepareSources(this);\n\n\t/*@__INLINE__**/ startBatch();\n\tconst prevContext = evalContext;\n\tevalContext = this;\n\treturn endEffect.bind(this, prevContext);\n};\n\nEffect.prototype._notify = function () {\n\tif (!(this._flags & NOTIFIED)) {\n\t\tthis._flags |= NOTIFIED;\n\t\tthis._nextBatchedEffect = batchedEffect;\n\t\tbatchedEffect = this;\n\t}\n};\n\nEffect.prototype._dispose = function () {\n\tthis._flags |= DISPOSED;\n\n\tif (!(this._flags & RUNNING)) {\n\t\tdisposeEffect(this);\n\t}\n};\n\nEffect.prototype.dispose = function () {\n\tthis._dispose();\n};\n/**\n * Create an effect to run arbitrary code in response to signal changes.\n *\n * An effect tracks which signals are accessed within the given callback\n * function `fn`, and re-runs the callback when those signals change.\n *\n * The callback may return a cleanup function. The cleanup function gets\n * run once, either when the callback is next called or when the effect\n * gets disposed, whichever happens first.\n *\n * @param fn The effect callback.\n * @returns A function for disposing the effect.\n */\nfunction effect(fn: EffectFn, options?: EffectOptions): DisposeFn {\n\tconst effect = new Effect(fn, options);\n\ttry {\n\t\teffect._callback();\n\t} catch (err) {\n\t\teffect._dispose();\n\t\tthrow err;\n\t}\n\t// Return a bound function instead of a wrapper like `() => effect._dispose()`,\n\t// because bound functions seem to be just as fast and take up a lot less memory.\n\tconst dispose = effect._dispose.bind(effect);\n\t(dispose as any)[Symbol.dispose] = dispose;\n\treturn dispose as DisposeFn;\n}\n\n//#endregion Effect\n\n//#region Action\n\nfunction action<TArgs extends unknown[], TReturn>(\n\tfn: (...args: TArgs) => TReturn\n): (...args: TArgs) => TReturn {\n\treturn function actionWrapper(this: unknown, ...args: TArgs) {\n\t\treturn batch(() => untracked(() => fn.apply(this, args)));\n\t};\n}\n\n//#endregion Action\n\n//#region createModel\n\n/** Models should only contain signals, actions, and nested objects containing only signals and actions. */\ntype ValidateModel<TModel> = {\n\t[Key in keyof TModel]: TModel[Key] extends ReadonlySignal<unknown>\n\t\t? TModel[Key]\n\t\t: TModel[Key] extends (...args: any[]) => any\n\t\t\t? TModel[Key]\n\t\t\t: TModel[Key] extends object\n\t\t\t\t? ValidateModel<TModel[Key]>\n\t\t\t\t: `Property ${Key extends string ? `'${Key}' ` : \"\"}is not a Signal, Action, or an object that contains only Signals and Actions.`;\n};\n\nexport type Model<TModel> = ValidateModel<TModel> & DisposableLike;\n\nexport type ModelFactory<TModel, TFactoryArgs extends any[] = []> = (\n\t...args: TFactoryArgs\n) => ValidateModel<TModel>;\nexport type ModelConstructor<TModel, TFactoryArgs extends any[] = []> = new (\n\t...args: TFactoryArgs\n) => Model<TModel>;\n\n/**\n * The public types for ModelConstructor require using `new` to help\n * disambiguate the function passed into `createModel` and the returned\n * constructor function. It is easier to say that `createModel` accepts\n * a factory and returns a class, then to say it accepts a factory and\n * returns a factory. In other words, this example:\n *\n * ```ts\n * const PersonModel = createModel((name: string) => ({ ... }));\n * const person = new PersonModel(\"John\");\n * ```\n *\n * is easier to understand than this example:\n *\n * ```ts\n * const createPerson = createModel((name: string) => ({ ... }));\n * const person = createPerson(\"John\");\n * ```\n *\n * However, internally we implement `createModel` to return a function\n * that can be called without `new` for simplicity. To bridge the gap\n * between the public types and the internal implementation, we define\n * this internal interface that extends the public interface but also\n * allows calling without `new`.\n *\n * This pattern is used by the Preact & React adapters to make instantiating\n * a model or a function that returns a model easier.\n *\n * @internal\n */\ninterface InternalModelConstructor<\n\tTModel,\n\tTFactoryArgs extends any[],\n> extends ModelConstructor<TModel, TFactoryArgs> {\n\t(...args: TFactoryArgs): Model<TModel>;\n}\n\nfunction startCapturingEffects(): () => Effect[] | undefined {\n\tlet prevCapturedEffects = capturedEffects;\n\t// Always establish a fresh capture scope, even when `untracked()` has\n\t// temporarily cleared the parent scope. This lets nested models own their\n\t// effects without promoting them to a suppressed outer scope.\n\tcapturedEffects = [];\n\n\treturn function stopCapturingEffects() {\n\t\tlet modelEffects = capturedEffects;\n\t\tif (capturedEffects && prevCapturedEffects) {\n\t\t\tprevCapturedEffects = prevCapturedEffects.concat(capturedEffects);\n\t\t}\n\n\t\tcapturedEffects = prevCapturedEffects;\n\n\t\treturn modelEffects;\n\t};\n}\n\nconst wrapInAction = (value: Record<string, unknown>) => {\n\tfor (const key in value) {\n\t\tconst val = value[key];\n\t\tif (typeof val === \"function\") {\n\t\t\tvalue[key] = action(val as (...args: unknown[]) => unknown);\n\t\t} else if (typeof val === \"object\" && val !== null && !(\"brand\" in val)) {\n\t\t\t// Recursively wrap nested object properties in actions. This allows users to write\n\t\t\t// nested models without worrying about wrapping their functions in `action`.\n\t\t\twrapInAction(val as Record<string, unknown>);\n\t\t}\n\t}\n};\n\nfunction createModel<TModel, TFactoryArgs extends any[] = []>(\n\tmodelFactory: ModelFactory<TModel, TFactoryArgs>\n): ModelConstructor<TModel, TFactoryArgs> {\n\treturn function SignalModel(...args: TFactoryArgs): Model<TModel> {\n\t\tlet modelEffects: Effect[] | undefined;\n\t\tlet model: Model<TModel>;\n\n\t\tconst stopCapturingEffects = startCapturingEffects();\n\t\ttry {\n\t\t\tmodel = modelFactory(...args) as Model<TModel>;\n\t\t} catch (err) {\n\t\t\t// Drop any captured effects on error. Errors from nested models will bubble\n\t\t\t// up here and recursively reset `capturedEffects` to `undefined` preventing\n\t\t\t// any captured effects from leaking\n\t\t\tcapturedEffects = undefined;\n\t\t\tthrow err;\n\t\t} finally {\n\t\t\tmodelEffects = stopCapturingEffects();\n\t\t}\n\n\t\twrapInAction(model);\n\n\t\tmodel[Symbol.dispose] = action(function disposeModel() {\n\t\t\tif (modelEffects) {\n\t\t\t\tfor (let i = 0; i < modelEffects.length; i++) {\n\t\t\t\t\tmodelEffects[i].dispose();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tmodelEffects = undefined;\n\t\t});\n\n\t\treturn model;\n\t} as InternalModelConstructor<TModel, TFactoryArgs>;\n}\n\n//#endregion createModel\n\nexport {\n\tcomputed,\n\teffect,\n\tbatch,\n\tuntracked,\n\taction,\n\tcreateModel,\n\tSignal,\n\tReadonlySignal,\n\tEffect,\n\tComputed,\n};\n"],"names":["BRAND_SYMBOL","Symbol","endBatch","batchDepth","error","hasError","snapshots","batchSnapshots","undefined","source","_source","_value","node","_targets","_nextTarget","_version","_next","reconcileBatchSnapshots","batchedEffect","effect","batchIteration","next","_nextBatchedEffect","_flags","needsToRecompute","_callback","err","batch","fn","currentBatchSnapshotVersion","batchSnapshotVersion","capturedEffects","evalContext","untracked","prevContext","prevCapturedEffects","globalVersion","addDependency","signal","_node","_target","_prevSource","_sources","_nextSource","_prevTarget","_rollbackNode","_subscribe","Signal","value","options","this","_batchSnapshotVersion","_watched","watched","_unwatched","unwatched","name","prototype","brand","_refresh","_this","targets","_this$_watched","call","_unsubscribe","_this2","prev","_this2$_unwatched","subscribe","_this3","valueOf","toString","toJSON","peek","_this4","Object","defineProperty","get","set","Error","recordBatchSnapshot","_notify","target","prepareSources","rollbackNode","cleanupSources","head","Computed","_fn","_globalVersion","OUTDATED","cleanupEffect","cleanup","_cleanup","disposeEffect","endEffect","Effect","push","finish","_start","bind","_dispose","dispose","action","_arguments","arguments","_this5","apply","slice","startCapturingEffects","modelEffects","concat","wrapInAction","key","val","exports","computed","createModel","modelFactory","model","stopCapturingEffects","i","length"],"mappings":"AAEA,IAAMA,EAAeC,OAAU,IAAC,kBAsChC,SAASC,IACR,KAAIC,EAAa,GAAjB,CAKA,IAAIC,EACAC,GAAW,GAoIhB,WACC,IAAIC,EAAYC,EAChBA,OAAiBC,EAEjB,WAAqBA,IAAdF,EAAyB,CAC/B,IAAMG,EAASH,EAAUI,EACzB,GAAID,EAAOE,IAAWL,EAAUK,EAQ/B,IACC,IAAIC,EAAOH,EAAOI,OACTL,IAATI,EACAA,EAAOA,EAAKE,EAEZ,GAAIF,EAAKG,IAAaT,EAAUS,EAC/BH,EAAKG,EAAWN,EAAOM,EAI1BT,EAAYA,EAAUU,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,QAAAE,YAlCA,SACCC,GAEA,kBACC,IAAIR,EACAS,EAEEC,EAAuBX,IAC7B,IACCU,EAAQD,EAAYX,WAAA,EAAA,GAAAC,MAAA7C,KAAA0C,WASrB,CARE,MAAO/E,GAIRK,OAAkBvB,EAClB,MAAMkB,CACP,CAAC,QACAoF,EAAeU,GAChB,CAEAR,EAAaO,GAEbA,EAAMtH,OAAOqG,SAAWC,EAAO,WAC9B,GAAIO,EACH,IAAK,IAAIW,EAAI,EAAGA,EAAIX,EAAaY,OAAQD,IACxCX,EAAaW,GAAGnB,UAIlBQ,OAAetG,CAChB,GAEA,OAAO+G,CACR,CACD,EAAAJ,QAAAhG,OAAAA,EAAAgG,QAAA7E,gBAnnB0BU,EAAWC,GACpC,OAAO,IAAIF,EAAOC,EAAOC,EAC1B,EAinBAkE,QAAAlF,UAAAA"}
1
+ {"version":3,"file":"signals-core.js","sources":["../src/index.ts"],"sourcesContent":["// An named symbol/brand for detecting Signal instances even when they weren't\n// created using the same signals library version.\nconst BRAND_SYMBOL = Symbol.for(\"preact-signals\");\n\n// Flags for Computed and Effect.\nconst RUNNING = 1 << 0;\nconst NOTIFIED = 1 << 1;\nconst OUTDATED = 1 << 2;\nconst DISPOSED = 1 << 3;\nconst HAS_ERROR = 1 << 4;\nconst TRACKING = 1 << 5;\n\n// A linked list node used to track dependencies (sources) and dependents (targets).\n// Also used to remember the source's last version number that the target saw.\ntype Node = {\n\t// A source whose value the target depends on.\n\t_source: Signal;\n\t_prevSource?: Node;\n\t_nextSource?: Node;\n\n\t// A target that depends on the source and should be notified when the source changes.\n\t_target: Computed | Effect;\n\t_prevTarget?: Node;\n\t_nextTarget?: Node;\n\n\t// The version number of the source that target has last seen. We use version numbers\n\t// instead of storing the source value, because source values can take arbitrary amount\n\t// of memory, and computeds could hang on to them forever because they're lazily evaluated.\n\t// Use the special value -1 to mark potentially unused but recyclable nodes.\n\t_version: number;\n\n\t// Used to remember & roll back the source's previous `._node` value when entering &\n\t// exiting a new evaluation context.\n\t_rollbackNode?: Node;\n};\n\nfunction startBatch() {\n\tbatchDepth++;\n}\n\nfunction endBatch() {\n\tif (batchDepth > 1) {\n\t\tbatchDepth--;\n\t\treturn;\n\t}\n\n\tlet error: unknown;\n\tlet hasError = false;\n\n\twhile (batchedEffect !== undefined) {\n\t\tlet effect: Effect | undefined = batchedEffect;\n\t\tbatchedEffect = undefined;\n\n\t\tbatchIteration++;\n\n\t\twhile (effect !== undefined) {\n\t\t\tconst next: Effect | undefined = effect._nextBatchedEffect;\n\t\t\teffect._nextBatchedEffect = undefined;\n\t\t\teffect._flags &= ~NOTIFIED;\n\n\t\t\tif (!(effect._flags & DISPOSED) && needsToRecompute(effect)) {\n\t\t\t\ttry {\n\t\t\t\t\teffect._callback();\n\t\t\t\t} catch (err) {\n\t\t\t\t\tif (!hasError) {\n\t\t\t\t\t\terror = err;\n\t\t\t\t\t\thasError = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\teffect = next;\n\t\t}\n\t}\n\tbatchIteration = 0;\n\tbatchDepth--;\n\n\tif (hasError) {\n\t\tthrow error;\n\t}\n}\n\n/**\n * Combine multiple value updates into one \"commit\" at the end of the provided callback.\n *\n * Batches can be nested and changes are only flushed once the outermost batch callback\n * completes.\n *\n * Accessing a signal that has been modified within a batch will reflect its updated\n * value.\n *\n * @param fn The callback function.\n * @returns The value returned by the callback.\n */\nfunction batch<T>(fn: () => T): T {\n\tif (batchDepth > 0) {\n\t\treturn fn();\n\t}\n\t/*@__INLINE__**/ startBatch();\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\tendBatch();\n\t}\n}\n\n// Currently evaluated computed or effect.\nlet evalContext: Computed | Effect | undefined = undefined;\n\n/**\n * Run a callback function that can access signal values without\n * subscribing to the signal updates.\n *\n * @param fn The callback function.\n * @returns The value returned by the callback.\n */\nfunction untracked<T>(fn: () => T): T {\n\tconst prevContext = evalContext;\n\tevalContext = undefined;\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\tevalContext = prevContext;\n\t}\n}\n\n// Effects collected into a batch.\nlet batchedEffect: Effect | undefined = undefined;\nlet batchDepth = 0;\nlet batchIteration = 0;\n\n// A global version number for signals, used for fast-pathing repeated\n// computed.peek()/computed.value calls when nothing has changed globally.\nlet globalVersion = 0;\n\nfunction addDependency(signal: Signal): Node | undefined {\n\tif (evalContext === undefined) {\n\t\treturn undefined;\n\t}\n\n\tlet node = signal._node;\n\tif (node === undefined || node._target !== evalContext) {\n\t\t/**\n\t\t * `signal` is a new dependency. Create a new dependency node, and set it\n\t\t * as the tail of the current context's dependency list. e.g:\n\t\t *\n\t\t * { A <-> B }\n\t\t * ↑ ↑\n\t\t * tail node (new)\n\t\t * ↓\n\t\t * { A <-> B <-> C }\n\t\t * ↑\n\t\t * tail (evalContext._sources)\n\t\t */\n\t\tnode = {\n\t\t\t_version: 0,\n\t\t\t_source: signal,\n\t\t\t_prevSource: evalContext._sources,\n\t\t\t_nextSource: undefined,\n\t\t\t_target: evalContext,\n\t\t\t_prevTarget: undefined,\n\t\t\t_nextTarget: undefined,\n\t\t\t_rollbackNode: node,\n\t\t};\n\n\t\tif (evalContext._sources !== undefined) {\n\t\t\tevalContext._sources._nextSource = node;\n\t\t}\n\t\tevalContext._sources = node;\n\t\tsignal._node = node;\n\n\t\t// Subscribe to change notifications from this dependency if we're in an effect\n\t\t// OR evaluating a computed signal that in turn has subscribers.\n\t\tif (evalContext._flags & TRACKING) {\n\t\t\tsignal._subscribe(node);\n\t\t}\n\t\treturn node;\n\t} else if (node._version === -1) {\n\t\t// `signal` is an existing dependency from a previous evaluation. Reuse it.\n\t\tnode._version = 0;\n\n\t\t/**\n\t\t * If `node` is not already the current tail of the dependency list (i.e.\n\t\t * there is a next node in the list), then make the `node` the new tail. e.g:\n\t\t *\n\t\t * { A <-> B <-> C <-> D }\n\t\t * ↑ ↑\n\t\t * node ┌─── tail (evalContext._sources)\n\t\t * └─────│─────┐\n\t\t * ↓ ↓\n\t\t * { A <-> C <-> D <-> B }\n\t\t * ↑\n\t\t * tail (evalContext._sources)\n\t\t */\n\t\tif (node._nextSource !== undefined) {\n\t\t\tnode._nextSource._prevSource = node._prevSource;\n\n\t\t\tif (node._prevSource !== undefined) {\n\t\t\t\tnode._prevSource._nextSource = node._nextSource;\n\t\t\t}\n\n\t\t\tnode._prevSource = evalContext._sources;\n\t\t\tnode._nextSource = undefined;\n\n\t\t\tevalContext._sources!._nextSource = node;\n\t\t\tevalContext._sources = node;\n\t\t}\n\n\t\t// We can assume that the currently evaluated effect / computed signal is already\n\t\t// subscribed to change notifications from `signal` if needed.\n\t\treturn node;\n\t}\n\treturn undefined;\n}\n\n/**\n * The base class for plain and computed signals.\n */\n// @ts-ignore: \"Cannot redeclare exported variable 'Signal'.\"\n//\n// A function with the same name is defined later, so we need to ignore TypeScript's\n// warning about a redeclared variable.\n//\n// The class is declared here, but later implemented with ES5-style prototypes.\n// This enables better control of the transpiled output size.\ndeclare class Signal<T = any> {\n\t/** @internal */\n\t_value: unknown;\n\n\t/**\n\t * @internal\n\t * Version numbers should always be >= 0, because the special value -1 is used\n\t * by Nodes to signify potentially unused but recyclable nodes.\n\t */\n\t_version: number;\n\n\t/** @internal */\n\t_node?: Node;\n\n\t/** @internal */\n\t_targets?: Node;\n\n\tconstructor(value?: T, options?: SignalOptions<T>);\n\n\t/** @internal */\n\t_refresh(): boolean;\n\n\t/** @internal */\n\t_subscribe(node: Node): void;\n\n\t/** @internal */\n\t_unsubscribe(node: Node): void;\n\n\t/** @internal */\n\t_watched?(this: Signal<T>): void;\n\n\t/** @internal */\n\t_unwatched?(this: Signal<T>): void;\n\n\tsubscribe(fn: (value: T) => void): () => void;\n\n\tvalueOf(): T;\n\n\ttoString(): string;\n\n\ttoJSON(): T;\n\n\tpeek(): T;\n\n\tbrand: typeof BRAND_SYMBOL;\n\n\tget value(): T;\n\tset value(value: T);\n}\n\nexport interface SignalOptions<T = any> {\n\twatched?: (this: Signal<T>) => void;\n\tunwatched?: (this: Signal<T>) => void;\n}\n\n/** @internal */\n// @ts-ignore: \"Cannot redeclare exported variable 'Signal'.\"\n//\n// A class with the same name has already been declared, so we need to ignore\n// TypeScript's warning about a redeclared variable.\n//\n// The previously declared class is implemented here with ES5-style prototypes.\n// This enables better control of the transpiled output size.\nfunction Signal(this: Signal, value?: unknown, options?: SignalOptions) {\n\tthis._value = value;\n\tthis._version = 0;\n\tthis._node = undefined;\n\tthis._targets = undefined;\n\tthis._watched = options?.watched;\n\tthis._unwatched = options?.unwatched;\n}\n\nSignal.prototype.brand = BRAND_SYMBOL;\n\nSignal.prototype._refresh = function () {\n\treturn true;\n};\n\nSignal.prototype._subscribe = function (node) {\n\tconst targets = this._targets;\n\tif (targets !== node && node._prevTarget === undefined) {\n\t\tnode._nextTarget = targets;\n\t\tthis._targets = node;\n\n\t\tif (targets !== undefined) {\n\t\t\ttargets._prevTarget = node;\n\t\t} else {\n\t\t\tuntracked(() => {\n\t\t\t\tthis._watched?.call(this);\n\t\t\t});\n\t\t}\n\t}\n};\n\nSignal.prototype._unsubscribe = function (node) {\n\t// Only run the unsubscribe step if the signal has any subscribers to begin with.\n\tif (this._targets !== undefined) {\n\t\tconst prev = node._prevTarget;\n\t\tconst next = node._nextTarget;\n\t\tif (prev !== undefined) {\n\t\t\tprev._nextTarget = next;\n\t\t\tnode._prevTarget = undefined;\n\t\t}\n\n\t\tif (next !== undefined) {\n\t\t\tnext._prevTarget = prev;\n\t\t\tnode._nextTarget = undefined;\n\t\t}\n\n\t\tif (node === this._targets) {\n\t\t\tthis._targets = next;\n\t\t\tif (next === undefined) {\n\t\t\t\tuntracked(() => {\n\t\t\t\t\tthis._unwatched?.call(this);\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n};\n\nSignal.prototype.subscribe = function (fn) {\n\treturn effect(() => {\n\t\tconst value = this.value;\n\n\t\tconst prevContext = evalContext;\n\t\tevalContext = undefined;\n\t\ttry {\n\t\t\tfn(value);\n\t\t} finally {\n\t\t\tevalContext = prevContext;\n\t\t}\n\t});\n};\n\nSignal.prototype.valueOf = function () {\n\treturn this.value;\n};\n\nSignal.prototype.toString = function () {\n\treturn this.value + \"\";\n};\n\nSignal.prototype.toJSON = function () {\n\treturn this.value;\n};\n\nSignal.prototype.peek = function () {\n\tconst prevContext = evalContext;\n\tevalContext = undefined;\n\ttry {\n\t\treturn this.value;\n\t} finally {\n\t\tevalContext = prevContext;\n\t}\n};\n\nObject.defineProperty(Signal.prototype, \"value\", {\n\tget(this: Signal) {\n\t\tconst node = addDependency(this);\n\t\tif (node !== undefined) {\n\t\t\tnode._version = this._version;\n\t\t}\n\t\treturn this._value;\n\t},\n\tset(this: Signal, value) {\n\t\tif (value !== this._value) {\n\t\t\tif (batchIteration > 100) {\n\t\t\t\tthrow new Error(\"Cycle detected\");\n\t\t\t}\n\n\t\t\tthis._value = value;\n\t\t\tthis._version++;\n\t\t\tglobalVersion++;\n\n\t\t\t/**@__INLINE__*/ startBatch();\n\t\t\ttry {\n\t\t\t\tfor (\n\t\t\t\t\tlet node = this._targets;\n\t\t\t\t\tnode !== undefined;\n\t\t\t\t\tnode = node._nextTarget\n\t\t\t\t) {\n\t\t\t\t\tnode._target._notify();\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tendBatch();\n\t\t\t}\n\t\t}\n\t},\n});\n\n/**\n * Create a new plain signal.\n *\n * @param value The initial value for the signal.\n * @returns A new signal.\n */\nexport function signal<T>(value: T, options?: SignalOptions<T>): Signal<T>;\nexport function signal<T = undefined>(): Signal<T | undefined>;\nexport function signal<T>(value?: T, options?: SignalOptions<T>): Signal<T> {\n\treturn new Signal(value, options);\n}\n\nfunction needsToRecompute(target: Computed | Effect): boolean {\n\t// Check the dependencies for changed values. The dependency list is already\n\t// in order of use. Therefore if multiple dependencies have changed values, only\n\t// the first used dependency is re-evaluated at this point.\n\tfor (\n\t\tlet node = target._sources;\n\t\tnode !== undefined;\n\t\tnode = node._nextSource\n\t) {\n\t\tif (\n\t\t\t// If the dependency has definitely been updated since its version number\n\t\t\t// was observed, then we need to recompute. This first check is not strictly\n\t\t\t// necessary for correctness, but allows us to skip the refresh call if the\n\t\t\t// dependency has already been updated.\n\t\t\tnode._source._version !== node._version ||\n\t\t\t// Refresh the dependency. If there's something blocking the refresh (e.g. a\n\t\t\t// dependency cycle), then we need to recompute.\n\t\t\t!node._source._refresh() ||\n\t\t\t// If the dependency got a new version after the refresh, then we need to recompute.\n\t\t\tnode._source._version !== node._version\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t}\n\t// If none of the dependencies have changed values since last recompute then\n\t// there's no need to recompute.\n\treturn false;\n}\n\nfunction prepareSources(target: Computed | Effect) {\n\t/**\n\t * 1. Mark all current sources as re-usable nodes (version: -1)\n\t * 2. Set a rollback node if the current node is being used in a different context\n\t * 3. Point 'target._sources' to the tail of the doubly-linked list, e.g:\n\t *\n\t * { undefined <- A <-> B <-> C -> undefined }\n\t * ↑ ↑\n\t * │ └──────┐\n\t * target._sources = A; (node is head) │\n\t * ↓ │\n\t * target._sources = C; (node is tail) ─┘\n\t */\n\tfor (\n\t\tlet node = target._sources;\n\t\tnode !== undefined;\n\t\tnode = node._nextSource\n\t) {\n\t\tconst rollbackNode = node._source._node;\n\t\tif (rollbackNode !== undefined) {\n\t\t\tnode._rollbackNode = rollbackNode;\n\t\t}\n\t\tnode._source._node = node;\n\t\tnode._version = -1;\n\n\t\tif (node._nextSource === undefined) {\n\t\t\ttarget._sources = node;\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nfunction cleanupSources(target: Computed | Effect) {\n\tlet node = target._sources;\n\tlet head: Node | undefined = undefined;\n\n\t/**\n\t * At this point 'target._sources' points to the tail of the doubly-linked list.\n\t * It contains all existing sources + new sources in order of use.\n\t * Iterate backwards until we find the head node while dropping old dependencies.\n\t */\n\twhile (node !== undefined) {\n\t\tconst prev = node._prevSource;\n\n\t\t/**\n\t\t * The node was not re-used, unsubscribe from its change notifications and remove itself\n\t\t * from the doubly-linked list. e.g:\n\t\t *\n\t\t * { A <-> B <-> C }\n\t\t * ↓\n\t\t * { A <-> C }\n\t\t */\n\t\tif (node._version === -1) {\n\t\t\tnode._source._unsubscribe(node);\n\n\t\t\tif (prev !== undefined) {\n\t\t\t\tprev._nextSource = node._nextSource;\n\t\t\t}\n\t\t\tif (node._nextSource !== undefined) {\n\t\t\t\tnode._nextSource._prevSource = prev;\n\t\t\t}\n\t\t} else {\n\t\t\t/**\n\t\t\t * The new head is the last node seen which wasn't removed/unsubscribed\n\t\t\t * from the doubly-linked list. e.g:\n\t\t\t *\n\t\t\t * { A <-> B <-> C }\n\t\t\t * ↑ ↑ ↑\n\t\t\t * │ │ └ head = node\n\t\t\t * │ └ head = node\n\t\t\t * └ head = node\n\t\t\t */\n\t\t\thead = node;\n\t\t}\n\n\t\tnode._source._node = node._rollbackNode;\n\t\tif (node._rollbackNode !== undefined) {\n\t\t\tnode._rollbackNode = undefined;\n\t\t}\n\n\t\tnode = prev;\n\t}\n\n\ttarget._sources = head;\n}\n\ndeclare class Computed<T = any> extends Signal<T> {\n\t_fn: () => T;\n\t_sources?: Node;\n\t_globalVersion: number;\n\t_flags: number;\n\n\tconstructor(fn: () => T, options?: SignalOptions<T>);\n\n\t_notify(): void;\n\tget value(): T;\n}\n\nfunction Computed(this: Computed, fn: () => unknown, options?: SignalOptions) {\n\tSignal.call(this, undefined);\n\n\tthis._fn = fn;\n\tthis._sources = undefined;\n\tthis._globalVersion = globalVersion - 1;\n\tthis._flags = OUTDATED;\n\tthis._watched = options?.watched;\n\tthis._unwatched = options?.unwatched;\n}\n\nComputed.prototype = new Signal() as Computed;\n\nComputed.prototype._refresh = function () {\n\tthis._flags &= ~NOTIFIED;\n\n\tif (this._flags & RUNNING) {\n\t\treturn false;\n\t}\n\n\t// If this computed signal has subscribed to updates from its dependencies\n\t// (TRACKING flag set) and none of them have notified about changes (OUTDATED\n\t// flag not set), then the computed value can't have changed.\n\tif ((this._flags & (OUTDATED | TRACKING)) === TRACKING) {\n\t\treturn true;\n\t}\n\tthis._flags &= ~OUTDATED;\n\n\tif (this._globalVersion === globalVersion) {\n\t\treturn true;\n\t}\n\tthis._globalVersion = globalVersion;\n\n\t// Mark this computed signal running before checking the dependencies for value\n\t// changes, so that the RUNNING flag can be used to notice cyclical dependencies.\n\tthis._flags |= RUNNING;\n\tif (this._version > 0 && !needsToRecompute(this)) {\n\t\tthis._flags &= ~RUNNING;\n\t\treturn true;\n\t}\n\n\tconst prevContext = evalContext;\n\ttry {\n\t\tprepareSources(this);\n\t\tevalContext = this;\n\t\tconst value = this._fn();\n\t\tif (\n\t\t\tthis._flags & HAS_ERROR ||\n\t\t\tthis._value !== value ||\n\t\t\tthis._version === 0\n\t\t) {\n\t\t\tthis._value = value;\n\t\t\tthis._flags &= ~HAS_ERROR;\n\t\t\tthis._version++;\n\t\t}\n\t} catch (err) {\n\t\tthis._value = err;\n\t\tthis._flags |= HAS_ERROR;\n\t\tthis._version++;\n\t}\n\tevalContext = prevContext;\n\tcleanupSources(this);\n\tthis._flags &= ~RUNNING;\n\treturn true;\n};\n\nComputed.prototype._subscribe = function (node) {\n\tif (this._targets === undefined) {\n\t\tthis._flags |= OUTDATED | TRACKING;\n\n\t\t// A computed signal subscribes lazily to its dependencies when it\n\t\t// gets its first subscriber.\n\t\tfor (\n\t\t\tlet node = this._sources;\n\t\t\tnode !== undefined;\n\t\t\tnode = node._nextSource\n\t\t) {\n\t\t\tnode._source._subscribe(node);\n\t\t}\n\t}\n\tSignal.prototype._subscribe.call(this, node);\n};\n\nComputed.prototype._unsubscribe = function (node) {\n\t// Only run the unsubscribe step if the computed signal has any subscribers.\n\tif (this._targets !== undefined) {\n\t\tSignal.prototype._unsubscribe.call(this, node);\n\n\t\t// Computed signal unsubscribes from its dependencies when it loses its last subscriber.\n\t\t// This makes it possible for unreferences subgraphs of computed signals to get garbage collected.\n\t\tif (this._targets === undefined) {\n\t\t\tthis._flags &= ~TRACKING;\n\n\t\t\tfor (\n\t\t\t\tlet node = this._sources;\n\t\t\t\tnode !== undefined;\n\t\t\t\tnode = node._nextSource\n\t\t\t) {\n\t\t\t\tnode._source._unsubscribe(node);\n\t\t\t}\n\t\t}\n\t}\n};\n\nComputed.prototype._notify = function () {\n\tif (!(this._flags & NOTIFIED)) {\n\t\tthis._flags |= OUTDATED | NOTIFIED;\n\n\t\tfor (\n\t\t\tlet node = this._targets;\n\t\t\tnode !== undefined;\n\t\t\tnode = node._nextTarget\n\t\t) {\n\t\t\tnode._target._notify();\n\t\t}\n\t}\n};\n\nObject.defineProperty(Computed.prototype, \"value\", {\n\tget(this: Computed) {\n\t\tif (this._flags & RUNNING) {\n\t\t\tthrow new Error(\"Cycle detected\");\n\t\t}\n\t\tconst node = addDependency(this);\n\t\tthis._refresh();\n\t\tif (node !== undefined) {\n\t\t\tnode._version = this._version;\n\t\t}\n\t\tif (this._flags & HAS_ERROR) {\n\t\t\tthrow this._value;\n\t\t}\n\t\treturn this._value;\n\t},\n});\n\n/**\n * An interface for read-only signals.\n */\ninterface ReadonlySignal<T = any> {\n\treadonly value: T;\n\tpeek(): T;\n\n\tsubscribe(fn: (value: T) => void): () => void;\n\tvalueOf(): T;\n\ttoString(): string;\n\ttoJSON(): T;\n\tbrand: typeof BRAND_SYMBOL;\n}\n\n/**\n * Create a new signal that is computed based on the values of other signals.\n *\n * The returned computed signal is read-only, and its value is automatically\n * updated when any signals accessed from within the callback function change.\n *\n * @param fn The effect callback.\n * @returns A new read-only signal.\n */\nfunction computed<T>(\n\tfn: () => T,\n\toptions?: SignalOptions<T>\n): ReadonlySignal<T> {\n\treturn new Computed(fn, options);\n}\n\nfunction cleanupEffect(effect: Effect) {\n\tconst cleanup = effect._cleanup;\n\teffect._cleanup = undefined;\n\n\tif (typeof cleanup === \"function\") {\n\t\t/*@__INLINE__**/ startBatch();\n\n\t\t// Run cleanup functions always outside of any context.\n\t\tconst prevContext = evalContext;\n\t\tevalContext = undefined;\n\t\ttry {\n\t\t\tcleanup();\n\t\t} catch (err) {\n\t\t\teffect._flags &= ~RUNNING;\n\t\t\teffect._flags |= DISPOSED;\n\t\t\tdisposeEffect(effect);\n\t\t\tthrow err;\n\t\t} finally {\n\t\t\tevalContext = prevContext;\n\t\t\tendBatch();\n\t\t}\n\t}\n}\n\nfunction disposeEffect(effect: Effect) {\n\tfor (\n\t\tlet node = effect._sources;\n\t\tnode !== undefined;\n\t\tnode = node._nextSource\n\t) {\n\t\tnode._source._unsubscribe(node);\n\t}\n\teffect._fn = undefined;\n\teffect._sources = undefined;\n\n\tcleanupEffect(effect);\n}\n\nfunction endEffect(this: Effect, prevContext?: Computed | Effect) {\n\tif (evalContext !== this) {\n\t\tthrow new Error(\"Out-of-order effect\");\n\t}\n\tcleanupSources(this);\n\tevalContext = prevContext;\n\n\tthis._flags &= ~RUNNING;\n\tif (this._flags & DISPOSED) {\n\t\tdisposeEffect(this);\n\t}\n\tendBatch();\n}\n\ntype EffectFn =\n\t| ((this: { dispose: () => void }) => void | (() => void))\n\t| (() => void | (() => void));\n\ndeclare class Effect {\n\t_fn?: EffectFn;\n\t_cleanup?: () => void;\n\t_sources?: Node;\n\t_nextBatchedEffect?: Effect;\n\t_flags: number;\n\n\tconstructor(fn: EffectFn);\n\n\t_callback(): void;\n\t_start(): () => void;\n\t_notify(): void;\n\t_dispose(): void;\n\tdispose(): void;\n}\n\nfunction Effect(this: Effect, fn: EffectFn) {\n\tthis._fn = fn;\n\tthis._cleanup = undefined;\n\tthis._sources = undefined;\n\tthis._nextBatchedEffect = undefined;\n\tthis._flags = TRACKING;\n}\n\nEffect.prototype._callback = function () {\n\tconst finish = this._start();\n\ttry {\n\t\tif (this._flags & DISPOSED) return;\n\t\tif (this._fn === undefined) return;\n\n\t\tconst cleanup = this._fn();\n\t\tif (typeof cleanup === \"function\") {\n\t\t\tthis._cleanup = cleanup;\n\t\t}\n\t} finally {\n\t\tfinish();\n\t}\n};\n\nEffect.prototype._start = function () {\n\tif (this._flags & RUNNING) {\n\t\tthrow new Error(\"Cycle detected\");\n\t}\n\tthis._flags |= RUNNING;\n\tthis._flags &= ~DISPOSED;\n\tcleanupEffect(this);\n\tprepareSources(this);\n\n\t/*@__INLINE__**/ startBatch();\n\tconst prevContext = evalContext;\n\tevalContext = this;\n\treturn endEffect.bind(this, prevContext);\n};\n\nEffect.prototype._notify = function () {\n\tif (!(this._flags & NOTIFIED)) {\n\t\tthis._flags |= NOTIFIED;\n\t\tthis._nextBatchedEffect = batchedEffect;\n\t\tbatchedEffect = this;\n\t}\n};\n\nEffect.prototype._dispose = function () {\n\tthis._flags |= DISPOSED;\n\n\tif (!(this._flags & RUNNING)) {\n\t\tdisposeEffect(this);\n\t}\n};\n\nEffect.prototype.dispose = function () {\n\tthis._dispose();\n};\n/**\n * Create an effect to run arbitrary code in response to signal changes.\n *\n * An effect tracks which signals are accessed within the given callback\n * function `fn`, and re-runs the callback when those signals change.\n *\n * The callback may return a cleanup function. The cleanup function gets\n * run once, either when the callback is next called or when the effect\n * gets disposed, whichever happens first.\n *\n * @param fn The effect callback.\n * @returns A function for disposing the effect.\n */\nfunction effect(fn: EffectFn): { (): void; [Symbol.dispose](): void } {\n\tconst effect = new Effect(fn);\n\ttry {\n\t\teffect._callback();\n\t} catch (err) {\n\t\teffect._dispose();\n\t\tthrow err;\n\t}\n\t// Return a bound function instead of a wrapper like `() => effect._dispose()`,\n\t// because bound functions seem to be just as fast and take up a lot less memory.\n\tconst dispose = effect._dispose.bind(effect);\n\t(dispose as any)[Symbol.dispose] = dispose;\n\treturn dispose as any;\n}\n\nexport { computed, effect, batch, untracked, Signal, ReadonlySignal };\n"],"names":["BRAND_SYMBOL","Symbol","endBatch","batchDepth","error","hasError","undefined","batchedEffect","effect","batchIteration","next","_nextBatchedEffect","_flags","needsToRecompute","_callback","err","evalContext","untracked","fn","prevContext","globalVersion","addDependency","signal","node","_node","_target","_version","_source","_prevSource","_sources","_nextSource","_prevTarget","_nextTarget","_rollbackNode","_subscribe","Signal","value","options","this","_value","_targets","_watched","watched","_unwatched","unwatched","prototype","brand","_refresh","_this","targets","_this$_watched","call","_unsubscribe","_this2","prev","_this2$_unwatched","subscribe","_this3","valueOf","toString","toJSON","peek","Object","defineProperty","get","set","Error","_notify","target","prepareSources","rollbackNode","cleanupSources","head","Computed","_fn","_globalVersion","OUTDATED","cleanupEffect","cleanup","_cleanup","disposeEffect","endEffect","Effect","finish","_start","bind","_dispose","dispose","exports","batch","computed"],"mappings":"AAEA,IAAMA,EAAeC,WAAW,kBAsChC,SAASC,IACR,KAAIC,EAAa,GAAjB,CAKA,IAAIC,EACAC,GAAW,EAEf,WAAyBC,IAAlBC,EAA6B,CACnC,IAAIC,EAA6BD,EACjCA,OAAgBD,EAEhBG,IAEA,WAAkBH,IAAXE,EAAsB,CAC5B,IAAME,EAA2BF,EAAOG,EACxCH,EAAOG,OAAqBL,EAC5BE,EAAOI,IAAU,EAEjB,KApDc,EAoDRJ,EAAOI,IAAsBC,EAAiBL,GACnD,IACCA,EAAOM,GAMR,CALE,MAAOC,GACR,IAAKV,EAAU,CACdD,EAAQW,EACRV,GAAW,CACZ,CACD,CAEDG,EAASE,CACV,CACD,CACAD,EAAiB,EACjBN,IAEA,GAAIE,EACH,MAAMD,CAjCP,MAFCD,GAqCF,CA2BA,IAAIa,OAA6CV,EASjD,SAASW,EAAaC,GACrB,IAAMC,EAAcH,EACpBA,OAAcV,EACd,IACC,OAAOY,GAGR,CAFC,QACAF,EAAcG,CACf,CACD,CAGA,IAAIZ,OAAoCD,EACpCH,EAAa,EACbM,EAAiB,EAIjBW,EAAgB,EAEpB,SAASC,EAAcC,GACtB,QAAoBhB,IAAhBU,EAAJ,CAIA,IAAIO,EAAOD,EAAOE,EAClB,QAAalB,IAATiB,GAAsBA,EAAKE,IAAYT,EAAa,CAavDO,EAAO,CACNG,EAAU,EACVC,EAASL,EACTM,EAAaZ,EAAYa,EACzBC,OAAaxB,EACbmB,EAAST,EACTe,OAAazB,EACb0B,OAAa1B,EACb2B,EAAeV,GAGhB,QAA6BjB,IAAzBU,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AS,IAAI0E,EAAOhE,GAC1B,IACCV,EAAOM,GAIR,CAHE,MAAOC,GACRP,EAAO8E,IACP,MAAMvE,CACP,CAGA,IAAMwE,EAAU/E,EAAO8E,EAASD,KAAK7E,GACpC+E,EAAgBtF,OAAOsF,SAAWA,EACnC,OAAOA,CACR,CAAAC,QAAArD,OAAAA,EAAAqD,QAAAC,MA5wBA,SAAkBvE,GACjB,GAAIf,EAAa,EAChB,OAAOe,IA1DRf,IA6DA,IACC,OAAOe,GAGR,CAFC,QACAhB,GACD,CACD,EAkwBAsF,QAAAE,SAlKA,SACCxE,EACAmB,GAEA,WAAWoC,EAASvD,EAAImB,EACzB,EA6JAmD,QAAAhF,OAAAA,EAAAgF,QAAAlE,OAncgB,SAAUc,EAAWC,GACpC,OAAW,IAAAF,EAAOC,EAAOC,EAC1B,EAicAmD,QAAAvE,UAAAA"}
@@ -25,7 +25,7 @@ interface ThemeProviderProps {
25
25
  theme?: string;
26
26
  themeMode?: ThemeMode;
27
27
  }
28
- export declare function ThemeProvider({ applyThemeClasses, children, theme: themeProp, themeMode: themeModeProp, density: densityProp, }: ThemeProviderProps): import("react").JSX.Element;
28
+ export declare function ThemeProvider({ applyThemeClasses, children, theme: themeProp, themeMode: themeModeProp, density: densityProp, }: ThemeProviderProps): import("react/jsx-runtime").JSX.Element;
29
29
  export declare namespace ThemeProvider {
30
30
  var displayName: string;
31
31
  }
@@ -1,11 +1,12 @@
1
1
  export type PartitionTest<T> = (value: T, index: number) => boolean;
2
+ export type ItemComparator<T> = (firstItem: T, secondItem: T) => boolean;
2
3
  export declare function partition<T>(array: T[], test: PartitionTest<T>, pass?: T[], fail?: T[]): [T[], T[]];
3
4
  export declare function itemsChanged<T = unknown>(currentItems: readonly T[], newItems: readonly T[], identityProperty?: string): boolean;
4
5
  export declare function itemsOrOrderChanged<T = unknown>(currentItems: readonly T[], newItems: readonly T[], identityProperty?: string): boolean;
5
6
  export declare const moveItemDeprecated: <T = unknown>(items: T[], item: T, moveTo: number) => T[];
6
7
  export declare const moveItem: <T = unknown>(items: T[], fromIndex: number, toIndex: number) => T[];
7
- export declare const getAddedItems: <T>(currentItems: undefined | readonly T[], newItems: readonly T[]) => readonly T[];
8
- export declare const getRemovedItems: <T>(currentItems: readonly T[], newItems: undefined | readonly T[]) => readonly T[];
8
+ export declare const getAddedItems: <T>(currentItems: undefined | readonly T[], newItems: readonly T[], compareItems?: ItemComparator<T>) => readonly T[];
9
+ export declare const getRemovedItems: <T>(currentItems: readonly T[], newItems: undefined | readonly T[], compareItems?: ItemComparator<T>) => readonly T[];
9
10
  export declare const containsSubsetOfItems: <T>(allItems: readonly T[], comparedItems: readonly T[]) => boolean;
10
11
  export declare const getMissingItems: <T, I>(sourceItems: readonly T[], items: readonly I[], identity: (s: T) => I) => I[];
11
12
  /**