atom.io 0.14.0 → 0.14.2

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/data/dist/index.cjs +1421 -52
  2. package/data/dist/index.cjs.map +1 -1
  3. package/data/dist/index.d.cts +317 -16
  4. package/data/dist/index.js +10 -267
  5. package/data/dist/index.js.map +1 -1
  6. package/data/package.json +5 -5
  7. package/data/src/join.ts +3 -3
  8. package/dist/chunk-C4YZZNRH.js +67 -0
  9. package/dist/chunk-C4YZZNRH.js.map +1 -0
  10. package/dist/chunk-CWKKQKVQ.js +68 -0
  11. package/dist/chunk-CWKKQKVQ.js.map +1 -0
  12. package/dist/chunk-GMN5KH6A.js +309 -0
  13. package/dist/chunk-GMN5KH6A.js.map +1 -0
  14. package/dist/chunk-N7ADBQJG.js +176 -0
  15. package/dist/chunk-N7ADBQJG.js.map +1 -0
  16. package/dist/chunk-NYCVSXQB.js +181 -0
  17. package/dist/chunk-NYCVSXQB.js.map +1 -0
  18. package/dist/chunk-PURABO5G.js +2581 -0
  19. package/dist/chunk-PURABO5G.js.map +1 -0
  20. package/dist/index.cjs +2330 -55
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +272 -22
  23. package/dist/index.js +1 -152
  24. package/dist/index.js.map +1 -1
  25. package/dist/metafile-cjs.json +1 -1
  26. package/internal/dist/index.cjs +299 -106
  27. package/internal/dist/index.cjs.map +1 -1
  28. package/internal/dist/index.d.cts +231 -30
  29. package/internal/dist/index.js +1 -2240
  30. package/internal/dist/index.js.map +1 -1
  31. package/internal/package.json +5 -5
  32. package/internal/src/atom/create-atom.ts +3 -1
  33. package/internal/src/families/create-atom-family.ts +3 -4
  34. package/internal/src/mutable/get-update-family.ts +23 -0
  35. package/internal/src/mutable/index.ts +1 -4
  36. package/internal/src/mutable/is-mutable.ts +44 -0
  37. package/internal/src/mutable/tracker.ts +9 -2
  38. package/internal/src/subject.ts +2 -1
  39. package/internal/src/timeline/add-atom-to-timeline.ts +10 -1
  40. package/internal/src/timeline/create-timeline.ts +44 -16
  41. package/introspection/dist/index.cjs +1566 -46
  42. package/introspection/dist/index.cjs.map +1 -1
  43. package/introspection/dist/index.d.cts +376 -4
  44. package/introspection/dist/index.js +2 -316
  45. package/introspection/dist/index.js.map +1 -1
  46. package/introspection/package.json +5 -5
  47. package/json/dist/index.cjs +1505 -8
  48. package/json/dist/index.cjs.map +1 -1
  49. package/json/dist/index.d.cts +373 -7
  50. package/json/dist/index.js +1 -76
  51. package/json/dist/index.js.map +1 -1
  52. package/json/package.json +5 -5
  53. package/package.json +5 -4
  54. package/react/dist/index.cjs +1549 -14
  55. package/react/dist/index.cjs.map +1 -1
  56. package/react/dist/index.d.cts +377 -4
  57. package/react/dist/index.js +2 -68
  58. package/react/dist/index.js.map +1 -1
  59. package/react/package.json +5 -5
  60. package/react-devtools/dist/index.cjs +2216 -198
  61. package/react-devtools/dist/index.cjs.map +1 -1
  62. package/react-devtools/dist/index.css +2 -2
  63. package/react-devtools/dist/index.d.cts +150 -24
  64. package/react-devtools/dist/index.js +57 -297
  65. package/react-devtools/dist/index.js.map +1 -1
  66. package/react-devtools/package.json +5 -5
  67. package/realtime-client/dist/index.cjs +1530 -35
  68. package/realtime-client/dist/index.cjs.map +1 -1
  69. package/realtime-client/dist/index.d.cts +384 -12
  70. package/realtime-client/dist/index.js +2 -165
  71. package/realtime-client/dist/index.js.map +1 -1
  72. package/realtime-client/package.json +5 -5
  73. package/realtime-react/dist/index.cjs +1727 -35
  74. package/realtime-react/dist/index.cjs.map +1 -1
  75. package/realtime-react/dist/index.d.cts +49 -9
  76. package/realtime-react/dist/index.js +4 -66
  77. package/realtime-react/dist/index.js.map +1 -1
  78. package/realtime-react/package.json +5 -5
  79. package/realtime-server/dist/index.cjs +1549 -58
  80. package/realtime-server/dist/index.cjs.map +1 -1
  81. package/realtime-server/dist/index.d.cts +394 -11
  82. package/realtime-server/dist/index.js +27 -21
  83. package/realtime-server/dist/index.js.map +1 -1
  84. package/realtime-server/package.json +6 -6
  85. package/realtime-testing/dist/index.cjs +2377 -16
  86. package/realtime-testing/dist/index.cjs.map +1 -1
  87. package/realtime-testing/dist/index.d.cts +489 -3
  88. package/realtime-testing/dist/index.js +10 -31
  89. package/realtime-testing/dist/index.js.map +1 -1
  90. package/realtime-testing/package.json +5 -5
  91. package/src/atom.ts +3 -1
  92. package/transceivers/set-rtx/dist/index.cjs +32 -10
  93. package/transceivers/set-rtx/dist/index.cjs.map +1 -1
  94. package/transceivers/set-rtx/dist/index.d.cts +29 -3
  95. package/transceivers/set-rtx/dist/index.js +2 -3
  96. package/transceivers/set-rtx/dist/index.js.map +1 -1
  97. package/transceivers/set-rtx/package.json +6 -6
  98. package/data/dist/index.d.ts +0 -158
  99. package/data/dist/metafile-cjs.json +0 -1
  100. package/data/dist/metafile-esm.json +0 -1
  101. package/dist/index.d.ts +0 -243
  102. package/dist/metafile-esm.json +0 -1
  103. package/internal/dist/index.d.ts +0 -421
  104. package/internal/dist/metafile-cjs.json +0 -1
  105. package/internal/dist/metafile-esm.json +0 -1
  106. package/internal/src/mutable/is-atom-token-mutable.ts +0 -7
  107. package/introspection/dist/index.d.ts +0 -24
  108. package/introspection/dist/metafile-cjs.json +0 -1
  109. package/introspection/dist/metafile-esm.json +0 -1
  110. package/json/dist/index.d.ts +0 -51
  111. package/json/dist/metafile-cjs.json +0 -1
  112. package/json/dist/metafile-esm.json +0 -1
  113. package/react/dist/index.d.ts +0 -23
  114. package/react/dist/metafile-cjs.json +0 -1
  115. package/react/dist/metafile-esm.json +0 -1
  116. package/react-devtools/dist/index.d.ts +0 -341
  117. package/react-devtools/dist/metafile-cjs.json +0 -1
  118. package/react-devtools/dist/metafile-esm.json +0 -1
  119. package/realtime-client/dist/index.d.ts +0 -22
  120. package/realtime-client/dist/metafile-cjs.json +0 -1
  121. package/realtime-client/dist/metafile-esm.json +0 -1
  122. package/realtime-react/dist/index.d.ts +0 -27
  123. package/realtime-react/dist/metafile-cjs.json +0 -1
  124. package/realtime-react/dist/metafile-esm.json +0 -1
  125. package/realtime-server/dist/index.d.ts +0 -25
  126. package/realtime-server/dist/metafile-cjs.json +0 -1
  127. package/realtime-server/dist/metafile-esm.json +0 -1
  128. package/realtime-testing/dist/index.d.ts +0 -49
  129. package/realtime-testing/dist/metafile-cjs.json +0 -1
  130. package/realtime-testing/dist/metafile-esm.json +0 -1
  131. package/transceivers/set-rtx/dist/index.d.ts +0 -40
  132. package/transceivers/set-rtx/dist/metafile-cjs.json +0 -1
  133. package/transceivers/set-rtx/dist/metafile-esm.json +0 -1
@@ -1,67 +1,2097 @@
1
1
  'use strict';
2
2
 
3
- var atom_io = require('atom.io');
4
- var introspection = require('atom.io/introspection');
5
- var react = require('atom.io/react');
6
- var framerMotion = require('framer-motion');
7
- var React = require('react');
3
+ var React2 = require('react');
8
4
  var jsxRuntime = require('react/jsx-runtime');
9
- var react$1 = require('@floating-ui/react');
5
+ var framerMotion = require('framer-motion');
6
+ var react = require('@floating-ui/react');
7
+
8
+ function _interopNamespace(e) {
9
+ if (e && e.__esModule) return e;
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n.default = e;
23
+ return Object.freeze(n);
24
+ }
25
+
26
+ var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
27
+
28
+ var __defProp = Object.defineProperty;
29
+ var __defProps = Object.defineProperties;
30
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
31
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
32
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
33
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
34
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
35
+ var __spreadValues = (a2, b2) => {
36
+ for (var prop in b2 || (b2 = {}))
37
+ if (__hasOwnProp.call(b2, prop))
38
+ __defNormalProp(a2, prop, b2[prop]);
39
+ if (__getOwnPropSymbols)
40
+ for (var prop of __getOwnPropSymbols(b2)) {
41
+ if (__propIsEnum.call(b2, prop))
42
+ __defNormalProp(a2, prop, b2[prop]);
43
+ }
44
+ return a2;
45
+ };
46
+ var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
47
+ var __restKey = (key) => typeof key === "symbol" ? key : key + "";
48
+ var __objRest = (source, exclude) => {
49
+ var target = {};
50
+ for (var prop in source)
51
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
52
+ target[prop] = source[prop];
53
+ if (source != null && __getOwnPropSymbols)
54
+ for (var prop of __getOwnPropSymbols(source)) {
55
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
56
+ target[prop] = source[prop];
57
+ }
58
+ return target;
59
+ };
60
+
61
+ // internal/src/future.ts
62
+ var Future = class extends Promise {
63
+ constructor(executor) {
64
+ super((resolve, reject) => {
65
+ const pass2 = (value) => this.isCanceled ? reject(`canceled`) : resolve(value);
66
+ const fail = (reason) => this.isCanceled ? reject(`canceled`) : reject(reason);
67
+ if (typeof executor === `function`) {
68
+ executor(pass2, fail);
69
+ } else {
70
+ executor.then(pass2, fail);
71
+ }
72
+ });
73
+ this.isCanceled = false;
74
+ }
75
+ cancel() {
76
+ this.isCanceled = true;
77
+ }
78
+ };
79
+
80
+ // internal/src/lineage.ts
81
+ function newest(scion) {
82
+ while (scion.child !== null) {
83
+ scion = scion.child;
84
+ }
85
+ return scion;
86
+ }
87
+
88
+ // internal/src/caching.ts
89
+ function cacheValue(key, value, subject, store) {
90
+ const target = newest(store);
91
+ const currentValue = target.valueMap.get(key);
92
+ if (currentValue instanceof Future) {
93
+ currentValue.cancel();
94
+ }
95
+ if (value instanceof Promise) {
96
+ const future = new Future(value);
97
+ newest(store).valueMap.set(key, future);
98
+ future.then((resolved) => {
99
+ if (future.isCanceled) {
100
+ return;
101
+ }
102
+ cacheValue(key, resolved, subject, store);
103
+ subject.next({ newValue: resolved, oldValue: future });
104
+ }).catch((thrown) => {
105
+ if (thrown !== `canceled`) {
106
+ store.logger.error(`\u{1F4A5}`, `state`, key, `rejected:`, thrown);
107
+ }
108
+ });
109
+ return future;
110
+ }
111
+ target.valueMap.set(key, value);
112
+ return value;
113
+ }
114
+ var readCachedValue = (key, store) => {
115
+ return newest(store).valueMap.get(key);
116
+ };
117
+ var isValueCached = (key, store) => {
118
+ return newest(store).valueMap.has(key);
119
+ };
120
+ var evictCachedValue = (key, store) => {
121
+ const core = newest(store);
122
+ const currentValue = core.valueMap.get(key);
123
+ if (currentValue instanceof Future) {
124
+ currentValue.cancel();
125
+ }
126
+ if (core.operation.open) {
127
+ core.operation.prev.set(key, currentValue);
128
+ }
129
+ core.valueMap.delete(key);
130
+ store.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
131
+ };
132
+
133
+ // ../anvl/src/json/index.ts
134
+ var parseJson = (str) => JSON.parse(str);
135
+ var stringifyJson = (json) => JSON.stringify(json);
136
+ var JSON_TYPE_NAMES = [
137
+ `array`,
138
+ `boolean`,
139
+ `null`,
140
+ `number`,
141
+ `object`,
142
+ `string`
143
+ ];
144
+ var JSON_DEFAULTS = {
145
+ array: [],
146
+ boolean: false,
147
+ null: null,
148
+ number: 0,
149
+ object: {},
150
+ string: ``
151
+ };
152
+
153
+ // ../anvl/src/primitive/index.ts
154
+ var isString = (input) => {
155
+ return typeof input === `string`;
156
+ };
157
+ var isNumber = (input) => {
158
+ return typeof input === `number`;
159
+ };
160
+ var isBoolean = (input) => {
161
+ return typeof input === `boolean`;
162
+ };
163
+
164
+ // json/src/select-json.ts
165
+ var selectJson = (atom2, transform, store = IMPLICIT.STORE) => {
166
+ return createSelector(
167
+ {
168
+ key: `${atom2.key}:JSON`,
169
+ get: ({ get }) => transform.toJson(get(atom2)),
170
+ set: ({ set }, newValue) => set(atom2, transform.fromJson(newValue))
171
+ },
172
+ void 0,
173
+ store
174
+ );
175
+ };
176
+
177
+ // json/src/select-json-family.ts
178
+ var selectJsonFamily = (atomFamily2, transform, store = IMPLICIT.STORE) => {
179
+ const jsonFamily = createSelectorFamily(
180
+ {
181
+ key: `${atomFamily2.key}:JSON`,
182
+ get: (key) => ({ get }) => transform.toJson(get(atomFamily2(key))),
183
+ set: (key) => ({ set }, newValue) => set(atomFamily2(key), transform.fromJson(newValue))
184
+ },
185
+ store
186
+ );
187
+ atomFamily2.subject.subscribe(
188
+ `store=${store.config.name}::json-selector-family`,
189
+ (token) => {
190
+ if (token.family) {
191
+ jsonFamily(parseJson(token.family.subKey));
192
+ }
193
+ }
194
+ );
195
+ return jsonFamily;
196
+ };
197
+
198
+ // internal/src/read-or-compute-value.ts
199
+ var readOrComputeValue = (state, store) => {
200
+ if (isValueCached(state.key, store)) {
201
+ store.logger.info(`\u{1F4D6}`, state.type, state.key, `reading cached value`);
202
+ return readCachedValue(state.key, store);
203
+ }
204
+ if (state.type !== `atom`) {
205
+ store.logger.info(`\u{1F9EE}`, state.type, state.key, `computing value`);
206
+ return state.get();
207
+ }
208
+ const fallback2 = state.default instanceof Function ? state.default() : state.default;
209
+ store.logger.info(
210
+ `\u{1F481}`,
211
+ `atom`,
212
+ state.key,
213
+ `could not find cached value; using default`,
214
+ fallback2
215
+ );
216
+ return state.default instanceof Function ? state.default() : state.default;
217
+ };
218
+
219
+ // internal/src/operation.ts
220
+ var openOperation = (token, store) => {
221
+ const target = newest(store);
222
+ if (target.operation.open) {
223
+ store.logger.error(
224
+ `\u274C`,
225
+ token.type,
226
+ token.key,
227
+ `failed to setState during a setState for "${target.operation.token.key}"`
228
+ );
229
+ return `rejection`;
230
+ }
231
+ target.operation = {
232
+ open: true,
233
+ done: /* @__PURE__ */ new Set(),
234
+ prev: /* @__PURE__ */ new Map(),
235
+ time: Date.now(),
236
+ token
237
+ };
238
+ store.logger.info(
239
+ `\u2B55`,
240
+ token.type,
241
+ token.key,
242
+ `operation start in store "${store.config.name}"${target.transactionMeta === null ? `` : ` ${target.transactionMeta.phase} "${target.transactionMeta.update.key}"`}`
243
+ );
244
+ };
245
+ var closeOperation = (store) => {
246
+ const target = newest(store);
247
+ if (target.operation.open) {
248
+ store.logger.info(
249
+ `\u{1F534}`,
250
+ target.operation.token.type,
251
+ target.operation.token.key,
252
+ `operation done in store "${store.config.name}"`
253
+ );
254
+ }
255
+ target.operation = { open: false };
256
+ store.subject.operationStatus.next(target.operation);
257
+ };
258
+ var isDone = (key, store) => {
259
+ const target = newest(store);
260
+ if (!target.operation.open) {
261
+ store.logger.warn(
262
+ `\u{1F41E}`,
263
+ `unknown`,
264
+ key,
265
+ `isDone called outside of an operation. This is probably a bug.`
266
+ );
267
+ return true;
268
+ }
269
+ return target.operation.done.has(key);
270
+ };
271
+ var markDone = (key, store) => {
272
+ const target = newest(store);
273
+ if (!target.operation.open) {
274
+ store.logger.warn(
275
+ `\u{1F41E}`,
276
+ `unknown`,
277
+ key,
278
+ `markDone called outside of an operation. This is probably a bug.`
279
+ );
280
+ return;
281
+ }
282
+ target.operation.done.add(key);
283
+ };
284
+
285
+ // internal/src/set-state/become.ts
286
+ var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
287
+ originalThing instanceof Function ? originalThing() : originalThing
288
+ ) : nextVersionOfThing;
289
+
290
+ // internal/src/subject.ts
291
+ var Subject = class {
292
+ constructor() {
293
+ this.subscribers = /* @__PURE__ */ new Map();
294
+ }
295
+ subscribe(key, subscriber) {
296
+ this.subscribers.set(key, subscriber);
297
+ const unsubscribe = () => this.unsubscribe(key);
298
+ return unsubscribe;
299
+ }
300
+ unsubscribe(key) {
301
+ this.subscribers.delete(key);
302
+ }
303
+ next(value) {
304
+ const subscribers = this.subscribers.values();
305
+ for (const subscriber of subscribers) {
306
+ subscriber(value);
307
+ }
308
+ }
309
+ };
310
+ var StatefulSubject = class extends Subject {
311
+ constructor(initialState) {
312
+ super();
313
+ this.state = initialState;
314
+ }
315
+ next(value) {
316
+ this.state = value;
317
+ super.next(value);
318
+ }
319
+ };
320
+
321
+ // internal/src/set-state/copy-mutable-if-needed.ts
322
+ function copyMutableIfNeeded(atom2, transform, origin, target) {
323
+ const originValue = origin.valueMap.get(atom2.key);
324
+ const targetValue = target.valueMap.get(atom2.key);
325
+ if (originValue === targetValue) {
326
+ origin.logger.info(`\u{1F4C3}`, `atom`, `${atom2.key}`, `copying`);
327
+ const jsonValue = transform.toJson(originValue);
328
+ const copiedValue = transform.fromJson(jsonValue);
329
+ target.valueMap.set(atom2.key, copiedValue);
330
+ new Tracker(atom2, origin);
331
+ return copiedValue;
332
+ }
333
+ return targetValue;
334
+ }
335
+
336
+ // internal/src/set-state/copy-mutable-in-transaction.ts
337
+ function copyMutableIfWithinTransaction(oldValue, atom2, store) {
338
+ const target = newest(store);
339
+ const parent = target.parent;
340
+ if (parent !== null) {
341
+ if (`toJson` in atom2 && `fromJson` in atom2) {
342
+ const copiedValue = copyMutableIfNeeded(atom2, atom2, parent, target);
343
+ return copiedValue;
344
+ }
345
+ if (`family` in atom2) {
346
+ const family = parent.families.get(atom2.family.key);
347
+ if (family && family.type === `atom_family`) {
348
+ const result = copyMutableFamilyMemberWithinTransaction(
349
+ atom2,
350
+ family,
351
+ parent,
352
+ target
353
+ );
354
+ if (result) {
355
+ return result;
356
+ }
357
+ }
358
+ }
359
+ }
360
+ return oldValue;
361
+ }
362
+ function copyMutableFamilyMemberWithinTransaction(atom2, family, origin, target) {
363
+ if (`toJson` in family && `fromJson` in family) {
364
+ const copyCreated = copyMutableIfNeeded(atom2, family, origin, target);
365
+ return copyCreated;
366
+ }
367
+ return null;
368
+ }
369
+
370
+ // internal/src/set-state/emit-update.ts
371
+ var emitUpdate = (state, update, store) => {
372
+ store.logger.info(
373
+ `\u{1F4E2}`,
374
+ state.type,
375
+ state.key,
376
+ `went (`,
377
+ update.oldValue,
378
+ `->`,
379
+ update.newValue,
380
+ `) subscribers:`,
381
+ state.subject.subscribers
382
+ );
383
+ state.subject.next(update);
384
+ };
385
+
386
+ // internal/src/set-state/evict-downstream.ts
387
+ var evictDownStream = (atom2, store) => {
388
+ const target = newest(store);
389
+ const downstreamKeys = target.selectorAtoms.getRelatedKeys(atom2.key);
390
+ store.logger.info(
391
+ `\u{1F9F9}`,
392
+ atom2.type,
393
+ atom2.key,
394
+ downstreamKeys ? `evicting ${downstreamKeys.size} states downstream:` : `no downstream states`,
395
+ downstreamKeys != null ? downstreamKeys : `to evict`
396
+ );
397
+ if (downstreamKeys) {
398
+ if (target.operation.open) {
399
+ store.logger.info(
400
+ `\u{1F9F9}`,
401
+ atom2.type,
402
+ atom2.key,
403
+ `[ ${[...target.operation.done].join(`, `)} ] already done`
404
+ );
405
+ }
406
+ for (const key of downstreamKeys) {
407
+ if (isDone(key, store)) {
408
+ continue;
409
+ }
410
+ evictCachedValue(key, store);
411
+ markDone(key, store);
412
+ }
413
+ }
414
+ };
415
+
416
+ // internal/src/set-state/stow-update.ts
417
+ function shouldUpdateBeStowed(key, update) {
418
+ if (isTransceiver(update.newValue)) {
419
+ return false;
420
+ }
421
+ if (key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
422
+ return false;
423
+ }
424
+ return true;
425
+ }
426
+ var stowUpdate = (state, update, store) => {
427
+ const { key } = state;
428
+ const target = newest(store);
429
+ if (target.transactionMeta === null || target.transactionMeta.phase !== `building`) {
430
+ store.logger.error(
431
+ `\u{1F41E}`,
432
+ `atom`,
433
+ key,
434
+ `stowUpdate called outside of a transaction. This is probably a bug.`
435
+ );
436
+ return;
437
+ }
438
+ const shouldStow = shouldUpdateBeStowed(key, update);
439
+ if (!shouldStow) {
440
+ return;
441
+ }
442
+ const atomUpdate = __spreadValues({ key }, update);
443
+ if (state.family) {
444
+ atomUpdate.family = state.family;
445
+ }
446
+ target.transactionMeta.update.updates.push(atomUpdate);
447
+ store.logger.info(
448
+ `\u{1F4C1}`,
449
+ `atom`,
450
+ key,
451
+ `stowed (`,
452
+ update.oldValue,
453
+ `->`,
454
+ update.newValue,
455
+ `)`
456
+ );
457
+ };
458
+
459
+ // internal/src/set-state/set-atom.ts
460
+ var setAtom = (atom2, next, store) => {
461
+ const target = newest(store);
462
+ const oldValue = readOrComputeValue(atom2, store);
463
+ let newValue = copyMutableIfWithinTransaction(oldValue, atom2, store);
464
+ newValue = become(next)(newValue);
465
+ store.logger.info(`\u{1F4DD}`, `atom`, atom2.key, `set to`, newValue);
466
+ newValue = cacheValue(atom2.key, newValue, atom2.subject, store);
467
+ if (isAtomDefault(atom2.key, store)) {
468
+ markAtomAsNotDefault(atom2.key, store);
469
+ }
470
+ markDone(atom2.key, store);
471
+ evictDownStream(atom2, store);
472
+ const update = { oldValue, newValue };
473
+ if (target.transactionMeta === null || target.transactionMeta.phase === `applying`) {
474
+ emitUpdate(atom2, update, store);
475
+ } else {
476
+ stowUpdate(atom2, update, store);
477
+ }
478
+ };
479
+
480
+ // internal/src/set-state/set-atom-or-selector.ts
481
+ var setAtomOrSelector = (state, value, store) => {
482
+ if (state.type === `selector`) {
483
+ state.set(value);
484
+ } else {
485
+ setAtom(state, value, store);
486
+ }
487
+ };
488
+
489
+ // internal/src/store/deposit.ts
490
+ function deposit(state) {
491
+ const token = {
492
+ key: state.key,
493
+ type: state.type
494
+ };
495
+ if (`family` in state) {
496
+ token.family = state.family;
497
+ }
498
+ return token;
499
+ }
500
+
501
+ // ../rel8/junction/src/junction.ts
502
+ var Junction = class {
503
+ constructor(data, config) {
504
+ this.relations = /* @__PURE__ */ new Map();
505
+ this.contents = /* @__PURE__ */ new Map();
506
+ this.makeContentKey = (a2, b2) => `${a2}:${b2}`;
507
+ var _a2, _b, _c, _d;
508
+ this.a = data.between[0];
509
+ this.b = data.between[1];
510
+ this.cardinality = data.cardinality;
511
+ if (!(config == null ? void 0 : config.externalStore)) {
512
+ this.relations = new Map((_a2 = data.relations) == null ? void 0 : _a2.map(([a2, b2]) => [a2, new Set(b2)]));
513
+ this.contents = new Map(data.contents);
514
+ }
515
+ this.isContent = (_b = config == null ? void 0 : config.isContent) != null ? _b : null;
516
+ if (config == null ? void 0 : config.makeContentKey) {
517
+ this.makeContentKey = config.makeContentKey;
518
+ }
519
+ if (config == null ? void 0 : config.externalStore) {
520
+ const externalStore = config.externalStore;
521
+ this.has = (a2, b2) => externalStore.has(a2, b2);
522
+ this.addRelation = (a2, b2) => {
523
+ externalStore.addRelation(a2, b2);
524
+ };
525
+ this.deleteRelation = (a2, b2) => {
526
+ externalStore.deleteRelation(a2, b2);
527
+ };
528
+ this.replaceRelationsSafely = (a2, bs) => {
529
+ externalStore.replaceRelationsSafely(a2, bs);
530
+ };
531
+ this.replaceRelationsUnsafely = (a2, bs) => {
532
+ externalStore.replaceRelationsUnsafely(a2, bs);
533
+ };
534
+ this.getRelatedKeys = (key) => externalStore.getRelatedKeys(key);
535
+ if (externalStore.getContent) {
536
+ this.getContentInternal = (contentKey) => {
537
+ return externalStore.getContent(contentKey);
538
+ };
539
+ this.setContent = (contentKey, content) => {
540
+ externalStore.setContent(contentKey, content);
541
+ };
542
+ this.deleteContent = (contentKey) => {
543
+ externalStore.deleteContent(contentKey);
544
+ };
545
+ }
546
+ for (const [x, ys] of (_c = data.relations) != null ? _c : []) {
547
+ for (const y of ys)
548
+ this.addRelation(x, y);
549
+ }
550
+ for (const [contentKey, content] of (_d = data.contents) != null ? _d : []) {
551
+ this.setContent(contentKey, content);
552
+ }
553
+ }
554
+ }
555
+ getRelatedKeys(key) {
556
+ return this.relations.get(key);
557
+ }
558
+ addRelation(a2, b2) {
559
+ let aRelations = this.relations.get(a2);
560
+ let bRelations = this.relations.get(b2);
561
+ if (aRelations) {
562
+ aRelations.add(b2);
563
+ } else {
564
+ aRelations = /* @__PURE__ */ new Set([b2]);
565
+ this.relations.set(a2, aRelations);
566
+ }
567
+ if (bRelations) {
568
+ bRelations.add(a2);
569
+ } else {
570
+ bRelations = /* @__PURE__ */ new Set([a2]);
571
+ this.relations.set(b2, bRelations);
572
+ }
573
+ }
574
+ deleteRelation(a2, b2) {
575
+ const aRelations = this.relations.get(a2);
576
+ if (aRelations) {
577
+ aRelations.delete(b2);
578
+ if (aRelations.size === 0) {
579
+ this.relations.delete(a2);
580
+ }
581
+ const bRelations = this.relations.get(b2);
582
+ if (bRelations) {
583
+ bRelations.delete(a2);
584
+ if (bRelations.size === 0) {
585
+ this.relations.delete(b2);
586
+ }
587
+ }
588
+ }
589
+ }
590
+ replaceRelationsUnsafely(a2, bs) {
591
+ this.relations.set(a2, new Set(bs));
592
+ for (const b2 of bs) {
593
+ const bRelations = /* @__PURE__ */ new Set([a2]);
594
+ this.relations.set(b2, bRelations);
595
+ }
596
+ }
597
+ replaceRelationsSafely(a2, bs) {
598
+ const aRelationsPrev = this.relations.get(a2);
599
+ if (aRelationsPrev) {
600
+ for (const b2 of aRelationsPrev) {
601
+ const bRelations = this.relations.get(b2);
602
+ if (bRelations) {
603
+ if (bRelations.size === 1) {
604
+ this.relations.delete(b2);
605
+ } else {
606
+ bRelations.delete(a2);
607
+ }
608
+ this.contents.delete(this.makeContentKey(a2, b2));
609
+ }
610
+ }
611
+ }
612
+ this.relations.set(a2, new Set(bs));
613
+ for (const b2 of bs) {
614
+ let bRelations = this.relations.get(b2);
615
+ if (bRelations) {
616
+ bRelations.add(a2);
617
+ } else {
618
+ bRelations = /* @__PURE__ */ new Set([a2]);
619
+ this.relations.set(b2, bRelations);
620
+ }
621
+ }
622
+ }
623
+ getContentInternal(contentKey) {
624
+ return this.contents.get(contentKey);
625
+ }
626
+ setContent(contentKey, content) {
627
+ this.contents.set(contentKey, content);
628
+ }
629
+ deleteContent(contentKey) {
630
+ this.contents.delete(contentKey);
631
+ }
632
+ toJSON() {
633
+ return {
634
+ between: [this.a, this.b],
635
+ cardinality: this.cardinality,
636
+ relations: [...this.relations.entries()].map(([a2, b2]) => [a2, [...b2]]),
637
+ contents: [...this.contents.entries()]
638
+ };
639
+ }
640
+ set(a2, ...rest) {
641
+ var _a2;
642
+ const b2 = typeof rest[0] === `string` ? rest[0] : a2[this.b];
643
+ const content = ((_a2 = rest[1]) != null ? _a2 : typeof rest[0] === `string`) ? void 0 : rest[0];
644
+ a2 = typeof a2 === `string` ? a2 : a2[this.a];
645
+ switch (this.cardinality) {
646
+ case `1:1`: {
647
+ const bPrev = this.getRelatedKey(a2);
648
+ if (bPrev && bPrev !== b2)
649
+ this.delete(bPrev, a2);
650
+ }
651
+ case `1:n`: {
652
+ const aPrev = this.getRelatedKey(b2);
653
+ if (aPrev && aPrev !== a2)
654
+ this.delete(aPrev, b2);
655
+ }
656
+ }
657
+ if (content) {
658
+ const contentKey = this.makeContentKey(a2, b2);
659
+ this.setContent(contentKey, content);
660
+ }
661
+ this.addRelation(a2, b2);
662
+ return this;
663
+ }
664
+ delete(x, b2) {
665
+ b2 = typeof b2 === `string` ? b2 : x[this.b];
666
+ const a2 = typeof x === `string` ? x : x[this.a];
667
+ if (a2 === void 0 && typeof b2 === `string`) {
668
+ const bRelations = this.getRelatedKeys(b2);
669
+ if (bRelations) {
670
+ for (const a3 of bRelations) {
671
+ this.delete(a3, b2);
672
+ }
673
+ }
674
+ }
675
+ if (typeof a2 === `string` && b2 === void 0) {
676
+ const aRelations = this.getRelatedKeys(a2);
677
+ if (aRelations) {
678
+ for (const b3 of aRelations) {
679
+ this.delete(a2, b3);
680
+ }
681
+ }
682
+ }
683
+ if (typeof a2 === `string` && typeof b2 === `string`) {
684
+ this.deleteRelation(a2, b2);
685
+ const contentKey = this.makeContentKey(a2, b2);
686
+ this.deleteContent(contentKey);
687
+ }
688
+ return this;
689
+ }
690
+ getRelatedKey(key) {
691
+ const relations = this.getRelatedKeys(key);
692
+ if (relations) {
693
+ if (relations.size > 1) {
694
+ console.warn(
695
+ `${relations.size} related keys were found for key "${key}": (${[
696
+ ...relations
697
+ ].map((k) => `"${k}"`).join(`, `)}). Only one related key was expected.`
698
+ );
699
+ }
700
+ for (const relation of relations) {
701
+ return relation;
702
+ }
703
+ }
704
+ }
705
+ replaceRelations(a2, relations, config) {
706
+ const hasContent = !Array.isArray(relations);
707
+ const bs = hasContent ? Object.keys(relations) : relations;
708
+ if (config == null ? void 0 : config.reckless) {
709
+ this.replaceRelationsUnsafely(a2, bs);
710
+ } else {
711
+ this.replaceRelationsSafely(a2, bs);
712
+ }
713
+ if (hasContent) {
714
+ for (const b2 of bs) {
715
+ const contentKey = this.makeContentKey(a2, b2);
716
+ const content = relations[b2];
717
+ this.setContent(contentKey, content);
718
+ }
719
+ }
720
+ return this;
721
+ }
722
+ getContent(a2, b2) {
723
+ const contentKey = this.makeContentKey(a2, b2);
724
+ return this.getContentInternal(contentKey);
725
+ }
726
+ getRelationEntries(input) {
727
+ const a2 = input[this.a];
728
+ const b2 = input[this.b];
729
+ if (a2 !== void 0 && b2 === void 0) {
730
+ const aRelations = this.getRelatedKeys(a2);
731
+ if (aRelations) {
732
+ return [...aRelations].map((b3) => {
733
+ var _a2;
734
+ return [b3, (_a2 = this.getContent(a2, b3)) != null ? _a2 : null];
735
+ });
736
+ }
737
+ }
738
+ if (a2 === void 0 && b2 !== void 0) {
739
+ const bRelations = this.getRelatedKeys(b2);
740
+ if (bRelations) {
741
+ return [...bRelations].map((a3) => {
742
+ var _a2;
743
+ return [a3, (_a2 = this.getContent(a3, b2)) != null ? _a2 : null];
744
+ });
745
+ }
746
+ }
747
+ return [];
748
+ }
749
+ has(a2, b2) {
750
+ var _a2;
751
+ if (b2) {
752
+ const setA = this.getRelatedKeys(a2);
753
+ return (_a2 = setA == null ? void 0 : setA.has(b2)) != null ? _a2 : false;
754
+ }
755
+ return this.relations.has(a2);
756
+ }
757
+ };
758
+
759
+ // internal/src/store/store.ts
760
+ var Store = class {
761
+ constructor(name, store = null) {
762
+ this.parent = null;
763
+ this.child = null;
764
+ this.valueMap = /* @__PURE__ */ new Map();
765
+ this.atoms = /* @__PURE__ */ new Map();
766
+ this.selectors = /* @__PURE__ */ new Map();
767
+ this.readonlySelectors = /* @__PURE__ */ new Map();
768
+ this.trackers = /* @__PURE__ */ new Map();
769
+ this.families = /* @__PURE__ */ new Map();
770
+ this.timelines = /* @__PURE__ */ new Map();
771
+ this.transactions = /* @__PURE__ */ new Map();
772
+ this.atomsThatAreDefault = /* @__PURE__ */ new Set();
773
+ this.timelineAtoms = new Junction({
774
+ between: [`timelineKey`, `atomKey`],
775
+ cardinality: `1:n`
776
+ });
777
+ this.selectorAtoms = new Junction({
778
+ between: [`selectorKey`, `atomKey`],
779
+ cardinality: `n:n`
780
+ });
781
+ this.selectorGraph = new Junction(
782
+ {
783
+ between: [`upstreamSelectorKey`, `downstreamSelectorKey`],
784
+ cardinality: `n:n`
785
+ },
786
+ {
787
+ makeContentKey: (...keys) => keys.sort().join(`:`)
788
+ }
789
+ );
790
+ this.subject = {
791
+ atomCreation: new Subject(),
792
+ selectorCreation: new Subject(),
793
+ transactionCreation: new Subject(),
794
+ timelineCreation: new Subject(),
795
+ transactionApplying: new StatefulSubject(null),
796
+ operationStatus: new Subject()
797
+ };
798
+ this.operation = { open: false };
799
+ this.transactionMeta = null;
800
+ this.config = {
801
+ name: `IMPLICIT_STORE`
802
+ };
803
+ this.loggers = [
804
+ new AtomIOLogger(`warn`, (_, __, key) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`))
805
+ ];
806
+ this.logger = {
807
+ error: (...messages) => {
808
+ for (const logger of this.loggers)
809
+ logger.error(...messages);
810
+ },
811
+ info: (...messages) => {
812
+ for (const logger of this.loggers)
813
+ logger.info(...messages);
814
+ },
815
+ warn: (...messages) => {
816
+ for (const logger of this.loggers)
817
+ logger.warn(...messages);
818
+ }
819
+ };
820
+ if (store !== null) {
821
+ this.valueMap = new Map(store == null ? void 0 : store.valueMap);
822
+ this.operation = __spreadValues({}, store == null ? void 0 : store.operation);
823
+ this.transactionMeta = (store == null ? void 0 : store.transactionMeta) ? __spreadValues({}, store == null ? void 0 : store.transactionMeta) : null;
824
+ this.config = __spreadProps(__spreadValues({}, store == null ? void 0 : store.config), {
825
+ name
826
+ });
827
+ for (const [, atom2] of store.atoms) {
828
+ atom2.install(this);
829
+ }
830
+ for (const [, selector] of store.readonlySelectors) {
831
+ selector.install(this);
832
+ }
833
+ for (const [, selector] of store.selectors) {
834
+ selector.install(this);
835
+ }
836
+ for (const [, tx] of store.transactions) {
837
+ tx.install(this);
838
+ }
839
+ for (const [, timeline] of store.timelines) {
840
+ timeline.install(this);
841
+ }
842
+ }
843
+ }
844
+ };
845
+ var IMPLICIT = {
846
+ STORE_INTERNAL: void 0,
847
+ get STORE() {
848
+ var _a2;
849
+ return (_a2 = this.STORE_INTERNAL) != null ? _a2 : this.STORE_INTERNAL = new Store(`IMPLICIT_STORE`);
850
+ }
851
+ };
852
+
853
+ // internal/src/store/withdraw.ts
854
+ function withdraw(token, store) {
855
+ var _a2, _b, _c, _d;
856
+ const target = newest(store);
857
+ const state = (_d = (_c = (_b = (_a2 = target.atoms.get(token.key)) != null ? _a2 : target.selectors.get(token.key)) != null ? _b : target.readonlySelectors.get(token.key)) != null ? _c : target.transactions.get(token.key)) != null ? _d : target.timelines.get(token.key);
858
+ if (state) {
859
+ return state;
860
+ }
861
+ return void 0;
862
+ }
863
+
864
+ // internal/src/store/withdraw-new-family-member.ts
865
+ function withdrawNewFamilyMember(token, store) {
866
+ if (token.family) {
867
+ store.logger.info(
868
+ `\u{1F46A}`,
869
+ token.type,
870
+ token.key,
871
+ `creating new family member in store "${store.config.name}"`
872
+ );
873
+ const target = newest(store);
874
+ const family = target.families.get(token.family.key);
875
+ if (family) {
876
+ const jsonSubKey = JSON.parse(token.family.subKey);
877
+ family(jsonSubKey);
878
+ const state = withdraw(token, store);
879
+ return state;
880
+ }
881
+ }
882
+ return void 0;
883
+ }
884
+
885
+ // internal/src/keys.ts
886
+ var isAtomKey = (key, store) => newest(store).atoms.has(key);
887
+ var isSelectorKey = (key, store) => newest(store).selectors.has(key);
888
+ var isReadonlySelectorKey = (key, store) => newest(store).readonlySelectors.has(key);
889
+ var isStateKey = (key, store) => isAtomKey(key, store) || isSelectorKey(key, store) || isReadonlySelectorKey(key, store);
890
+
891
+ // internal/src/selector/get-selector-dependency-keys.ts
892
+ var getSelectorDependencyKeys = (key, store) => {
893
+ const sources = newest(store).selectorGraph.getRelationEntries({ downstreamSelectorKey: key }).filter(([_, { source }]) => source !== key).map(([_, { source }]) => source).filter((source) => isStateKey(source, store));
894
+ return sources;
895
+ };
896
+
897
+ // internal/src/selector/trace-selector-atoms.ts
898
+ var traceSelectorAtoms = (selectorKey, directDependencyKey, store) => {
899
+ const rootKeys = [];
900
+ const indirectDependencyKeys = getSelectorDependencyKeys(
901
+ directDependencyKey,
902
+ store
903
+ );
904
+ let depth = 0;
905
+ while (indirectDependencyKeys.length > 0) {
906
+ const indirectDependencyKey = indirectDependencyKeys.shift();
907
+ ++depth;
908
+ if (depth > 99999) {
909
+ throw new Error(
910
+ `Maximum selector dependency depth exceeded (> 99999) in selector "${selectorKey}". This is likely due to a circular dependency.`
911
+ );
912
+ }
913
+ if (!isAtomKey(indirectDependencyKey, store)) {
914
+ indirectDependencyKeys.push(
915
+ ...getSelectorDependencyKeys(indirectDependencyKey, store)
916
+ );
917
+ } else if (!rootKeys.includes(indirectDependencyKey)) {
918
+ rootKeys.push(indirectDependencyKey);
919
+ }
920
+ }
921
+ return rootKeys;
922
+ };
923
+ var traceAllSelectorAtoms = (selectorKey, store) => {
924
+ const directDependencyKeys = getSelectorDependencyKeys(selectorKey, store);
925
+ return directDependencyKeys.flatMap(
926
+ (depKey) => isAtomKey(depKey, store) ? depKey : traceSelectorAtoms(selectorKey, depKey, store)
927
+ );
928
+ };
929
+
930
+ // internal/src/selector/update-selector-atoms.ts
931
+ var updateSelectorAtoms = (selectorKey, dependency, store) => {
932
+ const target = newest(store);
933
+ if (dependency.type === `atom`) {
934
+ target.selectorAtoms.set({
935
+ selectorKey,
936
+ atomKey: dependency.key
937
+ });
938
+ store.logger.info(
939
+ `\u{1F50D}`,
940
+ `selector`,
941
+ selectorKey,
942
+ `discovers root atom "${dependency.key}"`
943
+ );
944
+ } else {
945
+ const rootKeys = traceSelectorAtoms(selectorKey, dependency.key, store);
946
+ store.logger.info(
947
+ `\u{1F50D}`,
948
+ `selector`,
949
+ selectorKey,
950
+ `discovers root atoms: [ ${rootKeys.map((key) => `"${key}"`).join(`, `)} ]`
951
+ );
952
+ for (const atomKey of rootKeys) {
953
+ target.selectorAtoms = target.selectorAtoms.set({
954
+ selectorKey,
955
+ atomKey
956
+ });
957
+ }
958
+ }
959
+ };
960
+
961
+ // internal/src/selector/register-selector.ts
962
+ var registerSelector = (selectorKey, store) => ({
963
+ get: (dependency) => {
964
+ const target = newest(store);
965
+ const alreadyRegistered = target.selectorGraph.getRelationEntries({ downstreamSelectorKey: selectorKey }).some(([_, { source }]) => source === dependency.key);
966
+ const dependencyState = withdraw(dependency, store);
967
+ if (dependencyState === void 0) {
968
+ throw new Error(
969
+ `State "${dependency.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
970
+ );
971
+ }
972
+ const dependencyValue = readOrComputeValue(dependencyState, store);
973
+ store.logger.info(
974
+ `\u{1F50C}`,
975
+ `selector`,
976
+ selectorKey,
977
+ `registers dependency ( "${dependency.key}" =`,
978
+ dependencyValue,
979
+ `)`
980
+ );
981
+ if (!alreadyRegistered) {
982
+ target.selectorGraph.set(
983
+ {
984
+ upstreamSelectorKey: dependency.key,
985
+ downstreamSelectorKey: selectorKey
986
+ },
987
+ {
988
+ source: dependency.key
989
+ }
990
+ );
991
+ }
992
+ updateSelectorAtoms(selectorKey, dependency, store);
993
+ return dependencyValue;
994
+ },
995
+ set: (stateToken, newValue) => {
996
+ const state = withdraw(stateToken, store);
997
+ if (state === void 0) {
998
+ throw new Error(
999
+ `State "${stateToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
1000
+ );
1001
+ }
1002
+ setAtomOrSelector(state, newValue, store);
1003
+ }
1004
+ });
1005
+
1006
+ // internal/src/selector/create-read-write-selector.ts
1007
+ var createReadWriteSelector = (options, family, store) => {
1008
+ const target = newest(store);
1009
+ const subject = new Subject();
1010
+ const { get, set } = registerSelector(options.key, store);
1011
+ const getSelf = () => {
1012
+ const value = options.get({ get });
1013
+ cacheValue(options.key, value, subject, store);
1014
+ return value;
1015
+ };
1016
+ const setSelf = (next) => {
1017
+ const oldValue = getSelf();
1018
+ const newValue = become(next)(oldValue);
1019
+ store.logger.info(
1020
+ `\u{1F4DD}`,
1021
+ `selector`,
1022
+ options.key,
1023
+ `set (`,
1024
+ oldValue,
1025
+ `->`,
1026
+ newValue,
1027
+ `)`
1028
+ );
1029
+ cacheValue(options.key, newValue, subject, store);
1030
+ markDone(options.key, store);
1031
+ if (target.transactionMeta === null) {
1032
+ subject.next({ newValue, oldValue });
1033
+ }
1034
+ options.set({ get, set }, newValue);
1035
+ };
1036
+ const mySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
1037
+ subject,
1038
+ install: (s) => createSelector(options, family, s),
1039
+ get: getSelf,
1040
+ set: setSelf,
1041
+ type: `selector`
1042
+ }), family && { family });
1043
+ target.selectors.set(options.key, mySelector);
1044
+ const initialValue = getSelf();
1045
+ store.logger.info(`\u2728`, mySelector.type, mySelector.key, `=`, initialValue);
1046
+ const token = {
1047
+ key: options.key,
1048
+ type: `selector`
1049
+ };
1050
+ if (family) {
1051
+ token.family = family;
1052
+ }
1053
+ store.subject.selectorCreation.next(token);
1054
+ return token;
1055
+ };
1056
+
1057
+ // internal/src/selector/create-readonly-selector.ts
1058
+ var createReadonlySelector = (options, family, store) => {
1059
+ const target = newest(store);
1060
+ const subject = new Subject();
1061
+ const { get } = registerSelector(options.key, store);
1062
+ const getSelf = () => {
1063
+ const value = options.get({ get });
1064
+ cacheValue(options.key, value, subject, store);
1065
+ return value;
1066
+ };
1067
+ const readonlySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
1068
+ subject,
1069
+ install: (s) => createSelector(options, family, s),
1070
+ get: getSelf,
1071
+ type: `readonly_selector`
1072
+ }), family && { family });
1073
+ target.readonlySelectors.set(options.key, readonlySelector);
1074
+ const initialValue = getSelf();
1075
+ store.logger.info(
1076
+ `\u2728`,
1077
+ readonlySelector.type,
1078
+ readonlySelector.key,
1079
+ `=`,
1080
+ initialValue
1081
+ );
1082
+ const token = {
1083
+ key: options.key,
1084
+ type: `readonly_selector`
1085
+ };
1086
+ if (family) {
1087
+ token.family = family;
1088
+ }
1089
+ store.subject.selectorCreation.next(token);
1090
+ return token;
1091
+ };
1092
+
1093
+ // internal/src/selector/create-selector.ts
1094
+ function createSelector(options, family, store) {
1095
+ const target = newest(store);
1096
+ const existingWritable = target.selectors.get(options.key);
1097
+ const existingReadonly = target.readonlySelectors.get(options.key);
1098
+ if (existingWritable || existingReadonly) {
1099
+ store.logger.error(
1100
+ `\u274C`,
1101
+ existingReadonly ? `readonly_selector` : `selector`,
1102
+ options.key,
1103
+ `Tried to create selector, but it already exists in the store. (Ignore if you are in development using hot module replacement.)`
1104
+ );
1105
+ }
1106
+ if (`set` in options) {
1107
+ return createReadWriteSelector(options, family, store);
1108
+ }
1109
+ return createReadonlySelector(options, family, store);
1110
+ }
1111
+
1112
+ // internal/src/subscribe/recall-state.ts
1113
+ var recallState = (state, store) => {
1114
+ const target = newest(store);
1115
+ if (!target.operation.open) {
1116
+ return target.valueMap.get(state.key);
1117
+ }
1118
+ return target.operation.prev.get(state.key);
1119
+ };
1120
+
1121
+ // internal/src/subscribe/subscribe-to-root-atoms.ts
1122
+ var subscribeToRootAtoms = (state, store) => {
1123
+ const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomKey) => {
1124
+ const atom2 = store.atoms.get(atomKey);
1125
+ if (atom2 === void 0) {
1126
+ throw new Error(
1127
+ `Atom "${atomKey}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
1128
+ );
1129
+ }
1130
+ return atom2.subject.subscribe(
1131
+ `${state.type}:${state.key}`,
1132
+ (atomChange) => {
1133
+ store.logger.info(
1134
+ `\u{1F4E2}`,
1135
+ state.type,
1136
+ state.key,
1137
+ `root`,
1138
+ atomKey,
1139
+ `went`,
1140
+ atomChange.oldValue,
1141
+ `->`,
1142
+ atomChange.newValue
1143
+ );
1144
+ const oldValue = recallState(state, store);
1145
+ const newValue = readOrComputeValue(state, store);
1146
+ store.logger.info(
1147
+ `\u2728`,
1148
+ state.type,
1149
+ state.key,
1150
+ `went`,
1151
+ oldValue,
1152
+ `->`,
1153
+ newValue
1154
+ );
1155
+ state.subject.next({ newValue, oldValue });
1156
+ }
1157
+ );
1158
+ });
1159
+ return dependencySubscriptions;
1160
+ };
1161
+
1162
+ // internal/src/subscribe/subscribe-to-state.ts
1163
+ function subscribeToState(token, handleUpdate, key, store) {
1164
+ const state = withdraw(token, store);
1165
+ if (state === void 0) {
1166
+ throw new Error(
1167
+ `State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
1168
+ );
1169
+ }
1170
+ const unsubFunction = state.subject.subscribe(key, handleUpdate);
1171
+ store.logger.info(`\u{1F440}`, state.type, state.key, `Adding subscription "${key}"`);
1172
+ const dependencyUnsubFunctions = state.type !== `atom` ? subscribeToRootAtoms(state, store) : null;
1173
+ const unsubscribe = dependencyUnsubFunctions === null ? () => {
1174
+ store.logger.info(
1175
+ `\u{1F648}`,
1176
+ state.type,
1177
+ state.key,
1178
+ `Removing subscription "${key}"`
1179
+ );
1180
+ unsubFunction();
1181
+ } : () => {
1182
+ store.logger.info(
1183
+ `\u{1F648}`,
1184
+ state.type,
1185
+ state.key,
1186
+ `Removing subscription "${key}"`
1187
+ );
1188
+ unsubFunction();
1189
+ for (const unsubFromDependency of dependencyUnsubFunctions) {
1190
+ unsubFromDependency();
1191
+ }
1192
+ };
1193
+ return unsubscribe;
1194
+ }
1195
+
1196
+ // internal/src/subscribe/subscribe-to-timeline.ts
1197
+ var subscribeToTimeline = (token, handleUpdate, key, store) => {
1198
+ const tl = withdraw(token, store);
1199
+ if (tl === void 0) {
1200
+ throw new Error(
1201
+ `Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
1202
+ );
1203
+ }
1204
+ store.logger.info(`\u{1F440}`, `timeline`, token.key, `Adding subscription "${key}"`);
1205
+ const unsubscribe = tl.subject.subscribe(key, handleUpdate);
1206
+ return () => {
1207
+ store.logger.info(
1208
+ `\u{1F648}`,
1209
+ `timeline`,
1210
+ token.key,
1211
+ `Removing subscription "${key}" from timeline`
1212
+ );
1213
+ unsubscribe();
1214
+ };
1215
+ };
1216
+
1217
+ // internal/src/mutable/tracker.ts
1218
+ var Tracker = class {
1219
+ constructor(mutableState, store) {
1220
+ this.unsubscribeFromInnerValue = null;
1221
+ this.mutableState = mutableState;
1222
+ const target = newest(store);
1223
+ this.latestUpdateState = this.initializeState(mutableState, target);
1224
+ this.observeCore(mutableState, this.latestUpdateState, target);
1225
+ this.updateCore(mutableState, this.latestUpdateState, target);
1226
+ target.trackers.set(mutableState.key, this);
1227
+ }
1228
+ initializeState(mutableState, store) {
1229
+ const latestUpdateStateKey = `*${mutableState.key}`;
1230
+ store.atoms.delete(latestUpdateStateKey);
1231
+ store.valueMap.delete(latestUpdateStateKey);
1232
+ const familyMetaData = mutableState.family ? {
1233
+ key: `*${mutableState.family.key}`,
1234
+ subKey: mutableState.family.subKey
1235
+ } : void 0;
1236
+ const latestUpdateState = createAtom(
1237
+ {
1238
+ key: latestUpdateStateKey,
1239
+ default: null
1240
+ },
1241
+ familyMetaData,
1242
+ store
1243
+ );
1244
+ if (store.parent) {
1245
+ const parentValue = store.parent.valueMap.get(latestUpdateStateKey);
1246
+ store.valueMap.set(latestUpdateStateKey, parentValue);
1247
+ }
1248
+ return latestUpdateState;
1249
+ }
1250
+ observeCore(mutableState, latestUpdateState, store) {
1251
+ const originalInnerValue = getState(mutableState, store);
1252
+ const target = newest(store);
1253
+ this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
1254
+ `tracker:${store.config.name}:${target.transactionMeta === null ? `main` : target.transactionMeta.update.key}`,
1255
+ (update) => {
1256
+ const unsubscribe = store.subject.operationStatus.subscribe(
1257
+ mutableState.key,
1258
+ () => {
1259
+ unsubscribe();
1260
+ setState(latestUpdateState, update, store);
1261
+ }
1262
+ );
1263
+ }
1264
+ );
1265
+ subscribeToState(
1266
+ mutableState,
1267
+ (update) => {
1268
+ var _a2;
1269
+ if (update.newValue !== update.oldValue) {
1270
+ (_a2 = this.unsubscribeFromInnerValue) == null ? void 0 : _a2.call(this);
1271
+ const target2 = newest(store);
1272
+ this.unsubscribeFromInnerValue = update.newValue.subscribe(
1273
+ `tracker:${store.config.name}:${target2.transactionMeta === null ? `main` : target2.transactionMeta.update.key}`,
1274
+ (update2) => {
1275
+ const unsubscribe = store.subject.operationStatus.subscribe(
1276
+ mutableState.key,
1277
+ () => {
1278
+ unsubscribe();
1279
+ setState(latestUpdateState, update2, store);
1280
+ }
1281
+ );
1282
+ }
1283
+ );
1284
+ }
1285
+ },
1286
+ `${store.config.name}: tracker observing inner value`,
1287
+ store
1288
+ );
1289
+ }
1290
+ updateCore(mutableState, latestUpdateState, store) {
1291
+ subscribeToState(
1292
+ latestUpdateState,
1293
+ ({ newValue, oldValue }) => {
1294
+ const timelineId = store.timelineAtoms.getRelatedKey(
1295
+ latestUpdateState.key
1296
+ );
1297
+ if (timelineId) {
1298
+ const timelineData = store.timelines.get(timelineId);
1299
+ if (timelineData == null ? void 0 : timelineData.timeTraveling) {
1300
+ const unsubscribe2 = subscribeToTimeline(
1301
+ { key: timelineId, type: `timeline` },
1302
+ (update) => {
1303
+ unsubscribe2();
1304
+ setState(
1305
+ mutableState,
1306
+ (transceiver) => {
1307
+ if (update === `redo` && newValue) {
1308
+ transceiver.do(newValue);
1309
+ } else if (update === `undo` && oldValue) {
1310
+ transceiver.undo(oldValue);
1311
+ }
1312
+ return transceiver;
1313
+ },
1314
+ store
1315
+ );
1316
+ },
1317
+ `${mutableState.key}: tracker observing timeline`,
1318
+ store
1319
+ );
1320
+ return;
1321
+ }
1322
+ }
1323
+ const unsubscribe = store.subject.operationStatus.subscribe(
1324
+ latestUpdateState.key,
1325
+ () => {
1326
+ unsubscribe();
1327
+ const mutable = getState(mutableState, store);
1328
+ const updateNumber = newValue === null ? -1 : mutable.getUpdateNumber(newValue);
1329
+ const eventOffset = updateNumber - mutable.cacheUpdateNumber;
1330
+ if (newValue && eventOffset === 1) {
1331
+ setState(
1332
+ mutableState,
1333
+ (transceiver) => (transceiver.do(newValue), transceiver),
1334
+ store
1335
+ );
1336
+ }
1337
+ }
1338
+ );
1339
+ },
1340
+ `${store.config.name}: tracker observing latest update`,
1341
+ store
1342
+ );
1343
+ }
1344
+ };
1345
+
1346
+ // internal/src/mutable/create-mutable-atom.ts
1347
+ function createMutableAtom(options, store) {
1348
+ store.logger.info(
1349
+ `\u{1F527}`,
1350
+ `atom`,
1351
+ options.key,
1352
+ `creating in store "${store.config.name}"`
1353
+ );
1354
+ const coreState = createAtom(options, void 0, store);
1355
+ new Tracker(coreState, store);
1356
+ const jsonState = selectJson(coreState, options, store);
1357
+ const target = newest(store);
1358
+ subscribeToState(
1359
+ jsonState,
1360
+ () => {
1361
+ const trackerHasBeenInitialized = newest(store).trackers.has(coreState.key);
1362
+ if (!trackerHasBeenInitialized) {
1363
+ new Tracker(coreState, store);
1364
+ }
1365
+ },
1366
+ `tracker-initializer:${store == null ? void 0 : store.config.name}:${target.transactionMeta === null ? `main` : `${target.transactionMeta.update.key}`}`,
1367
+ store
1368
+ );
1369
+ return coreState;
1370
+ }
1371
+
1372
+ // internal/src/families/create-atom-family.ts
1373
+ function createAtomFamily(options, store) {
1374
+ const subject = new Subject();
1375
+ const atomFamily2 = Object.assign(
1376
+ (key) => {
1377
+ const subKey = stringifyJson(key);
1378
+ const family = { key: options.key, subKey };
1379
+ const fullKey = `${options.key}(${subKey})`;
1380
+ const existing = withdraw({ key: fullKey, type: `atom` }, store);
1381
+ let token;
1382
+ if (existing) {
1383
+ token = deposit(existing);
1384
+ } else {
1385
+ const individualOptions = {
1386
+ key: fullKey,
1387
+ default: options.default instanceof Function ? options.default(key) : options.default
1388
+ };
1389
+ if (options.effects) {
1390
+ individualOptions.effects = options.effects(key);
1391
+ }
1392
+ token = createAtom(individualOptions, family, store);
1393
+ subject.next(token);
1394
+ }
1395
+ return token;
1396
+ },
1397
+ {
1398
+ key: options.key,
1399
+ type: `atom_family`,
1400
+ subject
1401
+ }
1402
+ );
1403
+ if (`mutable` in options && typeof options.mutable === `boolean`) {
1404
+ Object.assign(atomFamily2, { mutable: options.mutable });
1405
+ }
1406
+ const target = newest(store);
1407
+ target.families.set(options.key, atomFamily2);
1408
+ return atomFamily2;
1409
+ }
1410
+
1411
+ // internal/src/families/create-readonly-selector-family.ts
1412
+ function createReadonlySelectorFamily(options, store) {
1413
+ const subject = new Subject();
1414
+ return Object.assign(
1415
+ (key) => {
1416
+ const target = newest(store);
1417
+ const subKey = stringifyJson(key);
1418
+ const family = { key: options.key, subKey };
1419
+ const fullKey = `${options.key}(${subKey})`;
1420
+ const existing = target.readonlySelectors.get(fullKey);
1421
+ if (existing) {
1422
+ return deposit(existing);
1423
+ }
1424
+ return createSelector(
1425
+ {
1426
+ key: fullKey,
1427
+ get: options.get(key)
1428
+ },
1429
+ family,
1430
+ store
1431
+ );
1432
+ },
1433
+ {
1434
+ key: options.key,
1435
+ type: `readonly_selector_family`,
1436
+ subject
1437
+ }
1438
+ );
1439
+ }
10
1440
 
11
- function _interopNamespace(e) {
12
- if (e && e.__esModule) return e;
13
- var n = Object.create(null);
14
- if (e) {
15
- Object.keys(e).forEach(function (k) {
16
- if (k !== 'default') {
17
- var d = Object.getOwnPropertyDescriptor(e, k);
18
- Object.defineProperty(n, k, d.get ? d : {
19
- enumerable: true,
20
- get: function () { return e[k]; }
21
- });
1441
+ // internal/src/families/create-selector-family.ts
1442
+ function createSelectorFamily(options, store) {
1443
+ const isReadonly = !(`set` in options);
1444
+ if (isReadonly) {
1445
+ return createReadonlySelectorFamily(options, store);
1446
+ }
1447
+ const target = newest(store);
1448
+ const subject = new Subject();
1449
+ const selectorFamily2 = Object.assign(
1450
+ (key) => {
1451
+ const subKey = stringifyJson(key);
1452
+ const family = { key: options.key, subKey };
1453
+ const fullKey = `${options.key}(${subKey})`;
1454
+ const existing = target.selectors.get(fullKey);
1455
+ if (existing) {
1456
+ return deposit(existing);
22
1457
  }
23
- });
1458
+ const token = createSelector(
1459
+ {
1460
+ key: fullKey,
1461
+ get: options.get(key),
1462
+ set: options.set(key)
1463
+ },
1464
+ family,
1465
+ store
1466
+ );
1467
+ subject.next(token);
1468
+ return token;
1469
+ },
1470
+ {
1471
+ key: options.key,
1472
+ type: `selector_family`
1473
+ }
1474
+ );
1475
+ target.families.set(options.key, selectorFamily2);
1476
+ return selectorFamily2;
1477
+ }
1478
+
1479
+ // internal/src/mutable/tracker-family.ts
1480
+ var FamilyTracker = class {
1481
+ constructor(findMutableState, store) {
1482
+ this.findLatestUpdateState = createAtomFamily(
1483
+ {
1484
+ key: `*${findMutableState.key}`,
1485
+ default: null
1486
+ },
1487
+ store
1488
+ );
1489
+ this.findMutableState = findMutableState;
1490
+ this.findMutableState.subject.subscribe(
1491
+ `store=${store.config.name}::tracker-atom-family`,
1492
+ (atomToken) => {
1493
+ if (atomToken.family) {
1494
+ const key = parseJson(atomToken.family.subKey);
1495
+ this.findLatestUpdateState(key);
1496
+ new Tracker(atomToken, store);
1497
+ }
1498
+ }
1499
+ );
1500
+ this.findLatestUpdateState.subject.subscribe(
1501
+ `store=${store.config.name}::tracker-atom-family`,
1502
+ (atomToken) => {
1503
+ if (atomToken.family) {
1504
+ const key = parseJson(atomToken.family.subKey);
1505
+ const mutableAtomToken = this.findMutableState(key);
1506
+ new Tracker(mutableAtomToken, store);
1507
+ }
1508
+ }
1509
+ );
24
1510
  }
25
- n.default = e;
26
- return Object.freeze(n);
1511
+ };
1512
+
1513
+ // internal/src/mutable/create-mutable-atom-family.ts
1514
+ function createMutableAtomFamily(options, store) {
1515
+ const coreFamily = Object.assign(
1516
+ createAtomFamily(options, store),
1517
+ options
1518
+ );
1519
+ selectJsonFamily(coreFamily, options);
1520
+ new FamilyTracker(coreFamily, store);
1521
+ return coreFamily;
27
1522
  }
28
1523
 
29
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
1524
+ // internal/src/mutable/transceiver.ts
1525
+ function isTransceiver(value) {
1526
+ return typeof value === `object` && value !== null && `do` in value && `undo` in value && `subscribe` in value;
1527
+ }
30
1528
 
31
- var __defProp = Object.defineProperty;
32
- var __defProps = Object.defineProperties;
33
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
34
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
35
- var __hasOwnProp = Object.prototype.hasOwnProperty;
36
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
37
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
38
- var __spreadValues = (a2, b2) => {
39
- for (var prop in b2 || (b2 = {}))
40
- if (__hasOwnProp.call(b2, prop))
41
- __defNormalProp(a2, prop, b2[prop]);
42
- if (__getOwnPropSymbols)
43
- for (var prop of __getOwnPropSymbols(b2)) {
44
- if (__propIsEnum.call(b2, prop))
45
- __defNormalProp(a2, prop, b2[prop]);
1529
+ // internal/src/atom/is-default.ts
1530
+ var isAtomDefault = (key, store) => {
1531
+ const core = newest(store);
1532
+ return core.atomsThatAreDefault.has(key);
1533
+ };
1534
+ var markAtomAsDefault = (key, store) => {
1535
+ const core = newest(store);
1536
+ core.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key);
1537
+ };
1538
+ var markAtomAsNotDefault = (key, store) => {
1539
+ const core = newest(store);
1540
+ core.atomsThatAreDefault = new Set(newest(store).atomsThatAreDefault);
1541
+ core.atomsThatAreDefault.delete(key);
1542
+ };
1543
+
1544
+ // internal/src/atom/create-atom.ts
1545
+ function createAtom(options, family, store) {
1546
+ store.logger.info(
1547
+ `\u{1F528}`,
1548
+ `atom`,
1549
+ options.key,
1550
+ `creating in store "${store.config.name}"`
1551
+ );
1552
+ const target = newest(store);
1553
+ const existing = target.atoms.get(options.key);
1554
+ if (existing) {
1555
+ store.logger.error(
1556
+ `\u274C`,
1557
+ `atom`,
1558
+ options.key,
1559
+ `Tried to create atom, but it already exists in the store.`,
1560
+ `(Ignore if you are in development using hot module replacement.)`
1561
+ );
1562
+ return deposit(existing);
1563
+ }
1564
+ const subject = new Subject();
1565
+ const newAtom = __spreadValues(__spreadProps(__spreadValues({}, options), {
1566
+ type: `atom`,
1567
+ install: (store2) => {
1568
+ store2.logger.info(
1569
+ `\u{1F6E0}\uFE0F`,
1570
+ `atom`,
1571
+ options.key,
1572
+ `installing in store "${store2.config.name}"`
1573
+ );
1574
+ return `mutable` in options ? createMutableAtom(options, store2) : createAtom(options, void 0, store2);
1575
+ },
1576
+ subject
1577
+ }), family && { family });
1578
+ let initialValue = options.default;
1579
+ if (options.default instanceof Function) {
1580
+ initialValue = options.default();
1581
+ }
1582
+ target.atoms.set(newAtom.key, newAtom);
1583
+ markAtomAsDefault(options.key, store);
1584
+ cacheValue(options.key, initialValue, subject, store);
1585
+ const token = deposit(newAtom);
1586
+ if (options.effects) {
1587
+ let effectIndex = 0;
1588
+ const cleanupFunctions = [];
1589
+ for (const effect of options.effects) {
1590
+ const cleanup = effect({
1591
+ setSelf: (next) => setState(token, next, store),
1592
+ onSet: (handle) => subscribeToState(token, handle, `effect[${effectIndex}]`, store)
1593
+ });
1594
+ if (cleanup) {
1595
+ cleanupFunctions.push(cleanup);
1596
+ }
1597
+ ++effectIndex;
46
1598
  }
47
- return a2;
1599
+ newAtom.cleanup = () => {
1600
+ for (const cleanup of cleanupFunctions) {
1601
+ cleanup();
1602
+ }
1603
+ };
1604
+ }
1605
+ store.subject.atomCreation.next(token);
1606
+ return token;
1607
+ }
1608
+
1609
+ // internal/src/not-found-error.ts
1610
+ var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
1611
+ function prettyPrintTokenType(token) {
1612
+ if (token.type === `readonly_selector`) {
1613
+ return `Readonly Selector`;
1614
+ }
1615
+ return capitalize(token.type);
1616
+ }
1617
+ var NotFoundError = class extends Error {
1618
+ constructor(token, store) {
1619
+ super(
1620
+ `${prettyPrintTokenType(token)} "${token.key}" not found in store "${store.config.name}".`
1621
+ );
1622
+ }
48
1623
  };
49
- var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
50
- var __restKey = (key) => typeof key === "symbol" ? key : key + "";
51
- var __objRest = (source, exclude) => {
52
- var target = {};
53
- for (var prop in source)
54
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
55
- target[prop] = source[prop];
56
- if (source != null && __getOwnPropSymbols)
57
- for (var prop of __getOwnPropSymbols(source)) {
58
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
59
- target[prop] = source[prop];
1624
+
1625
+ // internal/src/timeline/time-travel.ts
1626
+ var timeTravel = (direction, token, store) => {
1627
+ const action = direction === `forward` ? `redo` : `undo`;
1628
+ store.logger.info(
1629
+ direction === `forward` ? `\u23E9` : `\u23EA`,
1630
+ `timeline`,
1631
+ token.key,
1632
+ action
1633
+ );
1634
+ const timelineData = store.timelines.get(token.key);
1635
+ if (!timelineData) {
1636
+ store.logger.error(
1637
+ `\u{1F41E}`,
1638
+ `timeline`,
1639
+ token.key,
1640
+ `Failed to ${action}. This timeline has not been initialized.`
1641
+ );
1642
+ return;
1643
+ }
1644
+ if (direction === `forward` && timelineData.at === timelineData.history.length || direction === `backward` && timelineData.at === 0) {
1645
+ store.logger.warn(
1646
+ `\u{1F481}`,
1647
+ `timeline`,
1648
+ token.key,
1649
+ `Failed to ${action} at the ${direction === `forward` ? `end` : `beginning`} of timeline "${token.key}". There is nothing to ${action}.`
1650
+ );
1651
+ return;
1652
+ }
1653
+ timelineData.timeTraveling = direction === `forward` ? `into_future` : `into_past`;
1654
+ if (direction === `backward`) {
1655
+ --timelineData.at;
1656
+ }
1657
+ const update = timelineData.history[timelineData.at];
1658
+ const updateValues = (atomUpdate) => {
1659
+ const { key, newValue, oldValue } = atomUpdate;
1660
+ const value = direction === `forward` ? newValue : oldValue;
1661
+ setState({ key, type: `atom` }, value, store);
1662
+ };
1663
+ const updateValuesFromTransactionUpdate = (transactionUpdate) => {
1664
+ const updates = direction === `forward` ? transactionUpdate.updates : [...transactionUpdate.updates].reverse();
1665
+ for (const updateFromTransaction of updates) {
1666
+ if (`newValue` in updateFromTransaction) {
1667
+ updateValues(updateFromTransaction);
1668
+ } else {
1669
+ updateValuesFromTransactionUpdate(updateFromTransaction);
1670
+ }
60
1671
  }
61
- return target;
1672
+ };
1673
+ switch (update.type) {
1674
+ case `atom_update`: {
1675
+ updateValues(update);
1676
+ break;
1677
+ }
1678
+ case `selector_update`: {
1679
+ const updates = direction === `forward` ? update.atomUpdates : [...update.atomUpdates].reverse();
1680
+ for (const atomUpdate of updates) {
1681
+ updateValues(atomUpdate);
1682
+ }
1683
+ break;
1684
+ }
1685
+ case `transaction_update`: {
1686
+ updateValuesFromTransactionUpdate(update);
1687
+ break;
1688
+ }
1689
+ }
1690
+ if (direction === `forward`) {
1691
+ ++timelineData.at;
1692
+ }
1693
+ timelineData.subject.next(action);
1694
+ timelineData.timeTraveling = null;
1695
+ store.logger.info(
1696
+ `\u23F9\uFE0F`,
1697
+ `timeline`,
1698
+ token.key,
1699
+ `"${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
1700
+ );
1701
+ };
1702
+
1703
+ // src/atom.ts
1704
+ function atom(options) {
1705
+ if (`mutable` in options) {
1706
+ return createMutableAtom(options, IMPLICIT.STORE);
1707
+ }
1708
+ return createAtom(options, void 0, IMPLICIT.STORE);
1709
+ }
1710
+ function atomFamily(options) {
1711
+ if (`mutable` in options) {
1712
+ return createMutableAtomFamily(options, IMPLICIT.STORE);
1713
+ }
1714
+ return createAtomFamily(options, IMPLICIT.STORE);
1715
+ }
1716
+
1717
+ // src/get-state.ts
1718
+ function getState(token, store = IMPLICIT.STORE) {
1719
+ var _a2;
1720
+ const state = (_a2 = withdraw(token, store)) != null ? _a2 : withdrawNewFamilyMember(token, store);
1721
+ if (state === void 0) {
1722
+ throw new NotFoundError(token, store);
1723
+ }
1724
+ return readOrComputeValue(state, store);
1725
+ }
1726
+
1727
+ // src/logger.ts
1728
+ var simpleLog = (logLevel) => (icon, tokenType, tokenKey, message, ...rest) => {
1729
+ console[logLevel](`${icon} ${tokenType} "${tokenKey}" ${message}`, ...rest);
1730
+ };
1731
+ var simpleLogger = {
1732
+ error: simpleLog(`error`),
1733
+ info: simpleLog(`info`),
1734
+ warn: simpleLog(`warn`)
1735
+ };
1736
+ var AtomIOLogger = class {
1737
+ constructor(logLevel, filter, logger = simpleLogger) {
1738
+ this.logLevel = logLevel;
1739
+ this.filter = filter;
1740
+ this.logger = logger;
1741
+ this.error = (...args) => {
1742
+ var _a2, _b;
1743
+ if (((_b = (_a2 = this.filter) == null ? void 0 : _a2.call(this, ...args)) != null ? _b : true) && this.logLevel !== null) {
1744
+ this.logger.error(...args);
1745
+ }
1746
+ };
1747
+ this.info = (...args) => {
1748
+ var _a2, _b;
1749
+ if (((_b = (_a2 = this.filter) == null ? void 0 : _a2.call(this, ...args)) != null ? _b : true) && this.logLevel === `info`) {
1750
+ this.logger.info(...args);
1751
+ }
1752
+ };
1753
+ this.warn = (...args) => {
1754
+ var _a2, _b;
1755
+ if (((_b = (_a2 = this.filter) == null ? void 0 : _a2.call(this, ...args)) != null ? _b : true) && this.logLevel !== `error` && this.logLevel !== null) {
1756
+ this.logger.warn(...args);
1757
+ }
1758
+ };
1759
+ }
1760
+ };
1761
+
1762
+ // src/selector.ts
1763
+ function selectorFamily(options) {
1764
+ return createSelectorFamily(options, IMPLICIT.STORE);
1765
+ }
1766
+
1767
+ // src/set-state.ts
1768
+ function setState(token, value, store = IMPLICIT.STORE) {
1769
+ var _a2;
1770
+ const rejection = openOperation(token, store);
1771
+ if (rejection) {
1772
+ return;
1773
+ }
1774
+ const state = (_a2 = withdraw(token, store)) != null ? _a2 : withdrawNewFamilyMember(token, store);
1775
+ if (state === void 0) {
1776
+ throw new NotFoundError(token, store);
1777
+ }
1778
+ setAtomOrSelector(state, value, store);
1779
+ closeOperation(store);
1780
+ }
1781
+
1782
+ // src/timeline.ts
1783
+ var redo = (timeline) => {
1784
+ timeTravel(`forward`, timeline, IMPLICIT.STORE);
1785
+ };
1786
+ var undo = (timeline) => {
1787
+ timeTravel(`backward`, timeline, IMPLICIT.STORE);
1788
+ };
1789
+
1790
+ // introspection/src/attach-atom-index.ts
1791
+ var attachAtomIndex = (store = IMPLICIT.STORE) => {
1792
+ const atomTokenIndexState__INTERNAL = createAtom(
1793
+ {
1794
+ key: `\u{1F441}\u200D\u{1F5E8} Atom Token Index (Internal)`,
1795
+ default: () => {
1796
+ const defaultAtomIndex = [...store.atoms].filter(([key]) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`)).reduce((acc, [key]) => {
1797
+ acc[key] = { key, type: `atom` };
1798
+ return acc;
1799
+ }, {});
1800
+ return defaultAtomIndex;
1801
+ },
1802
+ effects: [
1803
+ ({ setSelf }) => {
1804
+ store.subject.atomCreation.subscribe(`introspection`, (atomToken) => {
1805
+ if (atomToken.key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
1806
+ return;
1807
+ }
1808
+ const set = () => setSelf((state) => {
1809
+ const { key, family } = atomToken;
1810
+ if (family) {
1811
+ const { key: familyKey, subKey } = family;
1812
+ const current = state[familyKey];
1813
+ if (current === void 0 || `familyMembers` in current) {
1814
+ const familyKeyState = current || {
1815
+ key: familyKey,
1816
+ familyMembers: {}
1817
+ };
1818
+ return __spreadProps(__spreadValues({}, state), {
1819
+ [familyKey]: __spreadProps(__spreadValues({}, familyKeyState), {
1820
+ familyMembers: __spreadProps(__spreadValues({}, familyKeyState.familyMembers), {
1821
+ [subKey]: atomToken
1822
+ })
1823
+ })
1824
+ });
1825
+ }
1826
+ }
1827
+ return __spreadProps(__spreadValues({}, state), {
1828
+ [key]: atomToken
1829
+ });
1830
+ });
1831
+ if (newest(store).operation.open) {
1832
+ const unsubscribe = store.subject.operationStatus.subscribe(
1833
+ `introspection: waiting to update atom index`,
1834
+ () => {
1835
+ unsubscribe();
1836
+ set();
1837
+ }
1838
+ );
1839
+ } else {
1840
+ set();
1841
+ }
1842
+ });
1843
+ }
1844
+ ]
1845
+ },
1846
+ void 0,
1847
+ store
1848
+ );
1849
+ return createSelector(
1850
+ {
1851
+ key: `\u{1F441}\u200D\u{1F5E8} Atom Token Index`,
1852
+ get: ({ get }) => get(atomTokenIndexState__INTERNAL)
1853
+ },
1854
+ void 0,
1855
+ store
1856
+ );
1857
+ };
1858
+
1859
+ // introspection/src/attach-selector-index.ts
1860
+ var attachSelectorIndex = (store = IMPLICIT.STORE) => {
1861
+ const readonlySelectorTokenIndexState__INTERNAL = createAtom(
1862
+ {
1863
+ key: `\u{1F441}\u200D\u{1F5E8} Selector Token Index (Internal)`,
1864
+ default: () => Object.assign(
1865
+ [...store.readonlySelectors].filter(([key]) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`)).reduce((acc, [key]) => {
1866
+ acc[key] = { key, type: `readonly_selector` };
1867
+ return acc;
1868
+ }, {}),
1869
+ [...store.selectors].reduce((acc, [key]) => {
1870
+ acc[key] = { key, type: `selector` };
1871
+ return acc;
1872
+ }, {})
1873
+ ),
1874
+ effects: [
1875
+ ({ setSelf }) => {
1876
+ store.subject.selectorCreation.subscribe(
1877
+ `introspection`,
1878
+ (selectorToken) => {
1879
+ if (selectorToken.key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
1880
+ return;
1881
+ }
1882
+ const set = () => setSelf((state) => {
1883
+ const { key, family } = selectorToken;
1884
+ if (family) {
1885
+ const { key: familyKey, subKey } = family;
1886
+ const current = state[familyKey];
1887
+ if (current === void 0 || `familyMembers` in current) {
1888
+ const familyKeyState = current || {
1889
+ key: familyKey,
1890
+ familyMembers: {}
1891
+ };
1892
+ return __spreadProps(__spreadValues({}, state), {
1893
+ [familyKey]: __spreadProps(__spreadValues({}, familyKeyState), {
1894
+ familyMembers: __spreadProps(__spreadValues({}, familyKeyState.familyMembers), {
1895
+ [subKey]: selectorToken
1896
+ })
1897
+ })
1898
+ });
1899
+ }
1900
+ }
1901
+ return __spreadProps(__spreadValues({}, state), {
1902
+ [key]: selectorToken
1903
+ });
1904
+ });
1905
+ if (newest(store).operation.open) {
1906
+ const unsubscribe = store.subject.operationStatus.subscribe(
1907
+ `introspection: waiting to update selector index`,
1908
+ () => {
1909
+ unsubscribe();
1910
+ set();
1911
+ }
1912
+ );
1913
+ } else {
1914
+ set();
1915
+ }
1916
+ }
1917
+ );
1918
+ }
1919
+ ]
1920
+ },
1921
+ void 0,
1922
+ store
1923
+ );
1924
+ return createSelector(
1925
+ {
1926
+ key: `\u{1F441}\u200D\u{1F5E8} Selector Token Index`,
1927
+ get: ({ get }) => get(readonlySelectorTokenIndexState__INTERNAL)
1928
+ },
1929
+ void 0,
1930
+ IMPLICIT.STORE
1931
+ );
1932
+ };
1933
+
1934
+ // introspection/src/attach-timeline-family.ts
1935
+ var attachTimelineFamily = (store = IMPLICIT.STORE) => {
1936
+ const findTimelineLogState__INTERNAL = createAtomFamily(
1937
+ {
1938
+ key: `\u{1F441}\u200D\u{1F5E8} Timeline Update Log (Internal)`,
1939
+ default: (key) => {
1940
+ var _a2;
1941
+ return (_a2 = store.timelines.get(key)) != null ? _a2 : {
1942
+ type: `timeline`,
1943
+ key: ``,
1944
+ at: 0,
1945
+ timeTraveling: null,
1946
+ history: [],
1947
+ selectorTime: null,
1948
+ transactionKey: null,
1949
+ install: () => {
1950
+ },
1951
+ subject: new Subject()
1952
+ };
1953
+ },
1954
+ effects: (key) => [
1955
+ ({ setSelf }) => {
1956
+ const tl = store.timelines.get(key);
1957
+ tl == null ? void 0 : tl.subject.subscribe(`introspection`, (_) => {
1958
+ if (store.operation.open === true) {
1959
+ const unsubscribe = store.subject.operationStatus.subscribe(
1960
+ `introspection`,
1961
+ (operationStatus) => {
1962
+ if (operationStatus.open === false) {
1963
+ unsubscribe();
1964
+ setSelf(__spreadValues({}, tl));
1965
+ }
1966
+ }
1967
+ );
1968
+ } else {
1969
+ setSelf(__spreadValues({}, tl));
1970
+ }
1971
+ });
1972
+ }
1973
+ ]
1974
+ },
1975
+ store
1976
+ );
1977
+ const findTimelineLogState = createSelectorFamily(
1978
+ {
1979
+ key: `\u{1F441}\u200D\u{1F5E8} Timeline Update Log`,
1980
+ get: (key) => ({ get }) => get(findTimelineLogState__INTERNAL(key))
1981
+ },
1982
+ store
1983
+ );
1984
+ return findTimelineLogState;
1985
+ };
1986
+
1987
+ // introspection/src/attach-timeline-index.ts
1988
+ var attachTimelineIndex = (store = IMPLICIT.STORE) => {
1989
+ const timelineTokenIndexState__INTERNAL = createAtom(
1990
+ {
1991
+ key: `\u{1F441}\u200D\u{1F5E8} Timeline Token Index (Internal)`,
1992
+ default: () => [...store.timelines].map(([key]) => {
1993
+ return { key, type: `timeline` };
1994
+ }),
1995
+ effects: [
1996
+ ({ setSelf }) => {
1997
+ store.subject.timelineCreation.subscribe(
1998
+ `introspection`,
1999
+ (timelineToken) => {
2000
+ setSelf((state) => [...state, timelineToken]);
2001
+ }
2002
+ );
2003
+ }
2004
+ ]
2005
+ },
2006
+ void 0,
2007
+ store
2008
+ );
2009
+ const timelineTokenIndex = createSelector(
2010
+ {
2011
+ key: `\u{1F441}\u200D\u{1F5E8} Timeline Token Index`,
2012
+ get: ({ get }) => get(timelineTokenIndexState__INTERNAL)
2013
+ },
2014
+ void 0,
2015
+ store
2016
+ );
2017
+ return timelineTokenIndex;
2018
+ };
2019
+
2020
+ // introspection/src/attach-transaction-index.ts
2021
+ var attachTransactionIndex = (store = IMPLICIT.STORE) => {
2022
+ const transactionTokenIndexState__INTERNAL = createAtom(
2023
+ {
2024
+ key: `\u{1F441}\u200D\u{1F5E8} Transaction Token Index (Internal)`,
2025
+ default: () => [...store.transactions].map(([key]) => {
2026
+ return { key, type: `transaction` };
2027
+ }),
2028
+ effects: [
2029
+ ({ setSelf }) => {
2030
+ store.subject.transactionCreation.subscribe(
2031
+ `introspection`,
2032
+ (transactionToken) => {
2033
+ setSelf((state) => [...state, transactionToken]);
2034
+ }
2035
+ );
2036
+ }
2037
+ ]
2038
+ },
2039
+ void 0,
2040
+ store
2041
+ );
2042
+ const transactionTokenIndex = createSelector(
2043
+ {
2044
+ key: `\u{1F441}\u200D\u{1F5E8} Transaction Token Index`,
2045
+ get: ({ get }) => get(transactionTokenIndexState__INTERNAL)
2046
+ },
2047
+ void 0,
2048
+ store
2049
+ );
2050
+ return transactionTokenIndex;
62
2051
  };
63
2052
 
64
- // ../__unstable__/web-effects/src/storage.ts
2053
+ // introspection/src/attach-transaction-logs.ts
2054
+ var attachTransactionLogs = (store = IMPLICIT.STORE) => {
2055
+ const findTransactionUpdateLog = createAtomFamily(
2056
+ {
2057
+ key: `\u{1F441}\u200D\u{1F5E8} Transaction Update Log (Internal)`,
2058
+ default: () => [],
2059
+ effects: (key) => [
2060
+ ({ setSelf }) => {
2061
+ const tx = store.transactions.get(key);
2062
+ tx == null ? void 0 : tx.subject.subscribe(`introspection`, (transactionUpdate) => {
2063
+ if (transactionUpdate.key === key) {
2064
+ setSelf((state) => [...state, transactionUpdate]);
2065
+ }
2066
+ });
2067
+ }
2068
+ ]
2069
+ },
2070
+ store
2071
+ );
2072
+ const findTransactionUpdateLogState = createSelectorFamily(
2073
+ {
2074
+ key: `\u{1F441}\u200D\u{1F5E8} Transaction Update Log`,
2075
+ get: (key) => ({ get }) => get(findTransactionUpdateLog(key))
2076
+ },
2077
+ store
2078
+ );
2079
+ return findTransactionUpdateLogState;
2080
+ };
2081
+
2082
+ // introspection/src/attach-introspection-states.ts
2083
+ var attachIntrospectionStates = (store = IMPLICIT.STORE) => {
2084
+ return {
2085
+ atomIndex: attachAtomIndex(store),
2086
+ selectorIndex: attachSelectorIndex(store),
2087
+ transactionIndex: attachTransactionIndex(store),
2088
+ findTransactionLogState: attachTransactionLogs(store),
2089
+ timelineIndex: attachTimelineIndex(store),
2090
+ findTimelineState: attachTimelineFamily(store)
2091
+ };
2092
+ };
2093
+
2094
+ // __unstable__/web-effects/src/storage.ts
65
2095
  var persistAtom = (storage) => ({ stringify, parse }) => (key) => ({ setSelf, onSet }) => {
66
2096
  const savedValue = storage.getItem(key);
67
2097
  if (savedValue != null)
@@ -76,7 +2106,7 @@ var persistAtom = (storage) => ({ stringify, parse }) => (key) => ({ setSelf, on
76
2106
  };
77
2107
  var lazyLocalStorageEffect = persistAtom(localStorage)(JSON);
78
2108
 
79
- // ../../anvl/src/function/pipe.ts
2109
+ // ../anvl/src/function/pipe.ts
80
2110
  function pipe(a2, ab, bc, cd, de, ef, fg, gh, hi) {
81
2111
  switch (arguments.length) {
82
2112
  case 1:
@@ -107,9 +2137,9 @@ function pipe(a2, ab, bc, cd, de, ef, fg, gh, hi) {
107
2137
  }
108
2138
  }
109
2139
 
110
- // ../../anvl/src/function/index.ts
2140
+ // ../anvl/src/function/index.ts
111
2141
  var doNothing = () => void 0;
112
- var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
2142
+ var become2 = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
113
2143
  originalThing instanceof Function ? originalThing() : originalThing
114
2144
  ) : nextVersionOfThing;
115
2145
  var isModifier = (validate) => (sample) => {
@@ -136,7 +2166,7 @@ var fallback = (fn, fallbackValue) => {
136
2166
  }
137
2167
  };
138
2168
 
139
- // ../../anvl/src/array/venn.ts
2169
+ // ../anvl/src/array/venn.ts
140
2170
  var includesAll = (items) => (array) => {
141
2171
  for (const item of items) {
142
2172
  if (!array.includes(item))
@@ -146,7 +2176,7 @@ var includesAll = (items) => (array) => {
146
2176
  };
147
2177
  var comprises = (items) => (array) => includesAll(items)(array) && includesAll(array)(items);
148
2178
 
149
- // ../../anvl/src/array/index.ts
2179
+ // ../anvl/src/array/index.ts
150
2180
  var isArray = (isType) => (input) => Array.isArray(input) && input.every((item) => isType(item));
151
2181
  var map = (f) => (a2) => a2.map(f);
152
2182
  var every = (f = Boolean) => (a2) => a2.every(f);
@@ -155,21 +2185,21 @@ var addTo = (a2) => (x) => a2.includes(x) ? a2 : [...a2, x];
155
2185
  var isEmptyArray = (input) => Array.isArray(input) && input.length === 0;
156
2186
  var isOneOf = (...args) => (input) => args.includes(input);
157
2187
 
158
- // ../../anvl/src/nullish/index.ts
2188
+ // ../anvl/src/nullish/index.ts
159
2189
  var isUndefined = (input) => input === void 0;
160
2190
  var ifDefined = (validate) => (input) => isUndefined(input) || validate(input);
161
2191
  var ifNullish = (alt) => (input) => input != null ? input : alt;
162
2192
 
163
- // ../../anvl/src/object/access.ts
2193
+ // ../anvl/src/object/access.ts
164
2194
  var access = (k) => Object.assign((obj) => obj[k], {
165
2195
  in: (obj) => obj[k]
166
2196
  });
167
2197
 
168
- // ../../anvl/src/object/entries.ts
2198
+ // ../anvl/src/object/entries.ts
169
2199
  var recordToEntries = (obj) => Object.entries(obj);
170
2200
  var entriesToRecord = (entries) => Object.fromEntries(entries);
171
2201
 
172
- // ../../anvl/src/object/mapObject.ts
2202
+ // ../anvl/src/object/mapObject.ts
173
2203
  var mapObject = (obj, fn) => pipe(
174
2204
  obj,
175
2205
  recordToEntries,
@@ -178,7 +2208,7 @@ var mapObject = (obj, fn) => pipe(
178
2208
  );
179
2209
  var mob = (fn) => (obj) => mapObject(obj, fn);
180
2210
 
181
- // ../../anvl/src/object/refinement.ts
2211
+ // ../anvl/src/object/refinement.ts
182
2212
  var isNonNullObject = (input) => typeof input === `object` && input !== null;
183
2213
  var isPlainObject = (input) => isNonNullObject(input) && Object.getPrototypeOf(input) === Object.prototype;
184
2214
  var isEmptyObject = (input) => isPlainObject(input) && Object.keys(input).length === 0;
@@ -213,7 +2243,7 @@ var doesExtend = (isValue) => hasProperties(isValue, ALLOW_EXTENSION);
213
2243
  var DO_NOT_ALLOW_EXTENSION = { allowExtraProperties: false };
214
2244
  var hasExactProperties = (isValue) => hasProperties(isValue, DO_NOT_ALLOW_EXTENSION);
215
2245
 
216
- // ../../anvl/src/object/sprawl.ts
2246
+ // ../anvl/src/object/sprawl.ts
217
2247
  var sprawl = (tree, inspector) => {
218
2248
  const walk = (path, node) => {
219
2249
  const inspect = (path2, node2) => {
@@ -238,7 +2268,7 @@ var sprawl = (tree, inspector) => {
238
2268
  walk([], tree);
239
2269
  };
240
2270
 
241
- // ../../anvl/src/object/index.ts
2271
+ // ../anvl/src/object/index.ts
242
2272
  var treeShake = (shouldDiscard = isUndefined) => (obj) => {
243
2273
  const newObj = {};
244
2274
  const entries = Object.entries(obj);
@@ -254,7 +2284,7 @@ var delve = (obj, path) => {
254
2284
  return found === void 0 ? new Error(`Not found`) : { found };
255
2285
  };
256
2286
 
257
- // ../../anvl/src/refinement/refinery.ts
2287
+ // ../anvl/src/refinement/refinery.ts
258
2288
  var Refinery = class {
259
2289
  constructor(supported) {
260
2290
  this.supported = supported;
@@ -299,7 +2329,7 @@ var discoverType = (input) => {
299
2329
  return Object.getPrototypeOf(input).constructor.name;
300
2330
  };
301
2331
 
302
- // ../../anvl/src/tree/differ.ts
2332
+ // ../anvl/src/tree/differ.ts
303
2333
  function diffNumber(a2, b2) {
304
2334
  const sign = a2 < b2 ? `+` : `-`;
305
2335
  return {
@@ -416,38 +2446,26 @@ var Differ = class {
416
2446
  };
417
2447
  }
418
2448
  };
2449
+ var StoreContext = React2__namespace.createContext(IMPLICIT.STORE);
2450
+ function useI(token) {
2451
+ const store = React2__namespace.useContext(StoreContext);
2452
+ const setter = React2__namespace.useRef(null);
2453
+ if (setter.current === null) {
2454
+ setter.current = (next) => setState(token, next, store);
2455
+ }
2456
+ return setter.current;
2457
+ }
2458
+ function useO(token) {
2459
+ const store = React2__namespace.useContext(StoreContext);
2460
+ const id = React2__namespace.useId();
2461
+ return React2__namespace.useSyncExternalStore(
2462
+ (dispatch) => subscribeToState(token, dispatch, `use-o:${id}`, store),
2463
+ () => getState(token, store),
2464
+ () => getState(token, store)
2465
+ );
2466
+ }
419
2467
 
420
- // ../../anvl/src/json/index.ts
421
- var stringifyJson = (json) => JSON.stringify(json);
422
- var JSON_TYPE_NAMES = [
423
- `array`,
424
- `boolean`,
425
- `null`,
426
- `number`,
427
- `object`,
428
- `string`
429
- ];
430
- var JSON_DEFAULTS = {
431
- array: [],
432
- boolean: false,
433
- null: null,
434
- number: 0,
435
- object: {},
436
- string: ``
437
- };
438
-
439
- // ../../anvl/src/primitive/index.ts
440
- var isString = (input) => {
441
- return typeof input === `string`;
442
- };
443
- var isNumber = (input) => {
444
- return typeof input === `number`;
445
- };
446
- var isBoolean = (input) => {
447
- return typeof input === `boolean`;
448
- };
449
-
450
- // ../../anvl/src/refinement/refine-json.ts
2468
+ // ../anvl/src/refinement/refine-json.ts
451
2469
  var JSON_PROTOTYPES = [
452
2470
  `Array`,
453
2471
  `Boolean`,
@@ -484,13 +2502,13 @@ var button = {
484
2502
  OpenClose
485
2503
  };
486
2504
 
487
- // ../../anvl/src/refinement/can-exist.ts
2505
+ // ../anvl/src/refinement/can-exist.ts
488
2506
  var canExist = (_) => true;
489
2507
 
490
- // ../../anvl/src/refinement/cannot-exist.ts
2508
+ // ../anvl/src/refinement/cannot-exist.ts
491
2509
  var cannotExist = (_) => false;
492
2510
 
493
- // ../../anvl/src/refinement/is-union.ts
2511
+ // ../anvl/src/refinement/is-union.ts
494
2512
  var mustSatisfyOneOfTheFollowing = (isTypeA, logging = false, refinements = [isTypeA]) => {
495
2513
  const name = `(${refinements.map((r) => (r == null ? void 0 : r.name) || `anon`).join(` | `)})`;
496
2514
  const _ = {
@@ -514,7 +2532,7 @@ var mustSatisfyOneOfTheFollowing = (isTypeA, logging = false, refinements = [isT
514
2532
  };
515
2533
  var isUnion = mustSatisfyOneOfTheFollowing(cannotExist);
516
2534
 
517
- // ../../anvl/src/refinement/is-intersection.ts
2535
+ // ../anvl/src/refinement/is-intersection.ts
518
2536
  function mustSatisfyAllOfTheFollowing(isTypeA, logging = false, refinements = [isTypeA]) {
519
2537
  const name = `(${refinements.map((r) => (r == null ? void 0 : r.name) || `anon`).join(` & `)})`;
520
2538
  const _ = {
@@ -538,11 +2556,11 @@ function mustSatisfyAllOfTheFollowing(isTypeA, logging = false, refinements = [i
538
2556
  }
539
2557
  var isIntersection = mustSatisfyAllOfTheFollowing(canExist);
540
2558
 
541
- // ../../anvl/src/refinement/index.ts
2559
+ // ../anvl/src/refinement/index.ts
542
2560
  var isLiteral = (value) => (input) => input === value;
543
2561
  var isWithin = (args) => (input) => args.includes(input);
544
2562
 
545
- // ../../anvl/src/join/core-relation-data.ts
2563
+ // ../anvl/src/join/core-relation-data.ts
546
2564
  var RELATION_TYPES = [`1:1`, `1:n`, `n:n`];
547
2565
  var isRelationType = (x) => RELATION_TYPES.includes(x);
548
2566
  var EMPTY_RELATION_DATA = {
@@ -566,7 +2584,7 @@ var isRelationData = ({
566
2584
  })(input);
567
2585
  };
568
2586
 
569
- // ../../anvl/src/join/get-related-ids.ts
2587
+ // ../anvl/src/join/get-related-ids.ts
570
2588
  var getRelatedIds = (relationMap, id) => {
571
2589
  var _a2;
572
2590
  return (_a2 = relationMap.relations[id]) != null ? _a2 : [];
@@ -581,7 +2599,7 @@ var getRelatedId = (relationMap, id) => {
581
2599
  return relations[0];
582
2600
  };
583
2601
 
584
- // ../../anvl/src/join/make-json-interface.ts
2602
+ // ../anvl/src/join/make-json-interface.ts
585
2603
  var makeJsonInterface = (join, ...params) => {
586
2604
  const isContent = params[0];
587
2605
  const { a: a2, b: b2 } = join;
@@ -596,17 +2614,17 @@ var makeJsonInterface = (join, ...params) => {
596
2614
  };
597
2615
  };
598
2616
 
599
- // ../../anvl/src/join/relation-record.ts
2617
+ // ../anvl/src/join/relation-record.ts
600
2618
  var getRelationEntries = (relationMap, idA) => getRelatedIds(relationMap, idA).map((idB) => [
601
2619
  idB,
602
2620
  getContent(relationMap, idA, idB)
603
2621
  ]);
604
2622
  var getRelationRecord = (relationMap, id) => Object.fromEntries(getRelationEntries(relationMap, id));
605
2623
 
606
- // ../../anvl/src/string/split.ts
2624
+ // ../anvl/src/string/split.ts
607
2625
  var split = (separator) => (str) => str.split(separator);
608
2626
 
609
- // ../../anvl/src/join/remove-relation.ts
2627
+ // ../anvl/src/join/remove-relation.ts
610
2628
  var removeSpecific = (current, idA, idB) => {
611
2629
  const isIdForRemoval = isOneOf(idA, idB);
612
2630
  return __spreadProps(__spreadValues({}, current), {
@@ -655,7 +2673,7 @@ var removeRelation = (current, relation) => {
655
2673
  return idB ? removeSpecific(current, idA, idB) : removeAll(current, idA);
656
2674
  };
657
2675
 
658
- // ../../anvl/src/join/set-relation.ts
2676
+ // ../anvl/src/join/set-relation.ts
659
2677
  var setManyToMany = (map2, idA, idB, ...rest) => {
660
2678
  var _a2, _b;
661
2679
  const next = __spreadProps(__spreadValues({}, map2), {
@@ -709,7 +2727,7 @@ var setRelationWithContent = (current, relation, ...rest) => {
709
2727
  }
710
2728
  };
711
2729
 
712
- // ../../anvl/src/join/relation-contents.ts
2730
+ // ../anvl/src/join/relation-contents.ts
713
2731
  var makeContentId = (idA, idB) => [idA, idB].sort().join(`/`);
714
2732
  var getContent = (relationMap, idA, idB) => relationMap.contents[makeContentId(idA, idB)];
715
2733
  var setContent = (map2, idA, idB, content) => __spreadProps(__spreadValues({}, map2), {
@@ -767,7 +2785,7 @@ var setRelations = (current, subject, relations) => {
767
2785
  );
768
2786
  };
769
2787
 
770
- // ../../anvl/src/join/index.ts
2788
+ // ../anvl/src/join/index.ts
771
2789
  var Join = class _Join {
772
2790
  constructor(json) {
773
2791
  this.a = `from`;
@@ -836,12 +2854,12 @@ var Join = class _Join {
836
2854
  );
837
2855
  }
838
2856
  };
839
- var ElasticInput = React.forwardRef(function ElasticInputFC(props, ref) {
2857
+ var ElasticInput = React2.forwardRef(function ElasticInputFC(props, ref) {
840
2858
  var _a2, _b, _c, _d;
841
- const inputRef = React.useRef(null);
842
- const spanRef = React.useRef(null);
843
- const [inputWidth, setInputWidth] = React.useState(`auto`);
844
- React.useImperativeHandle(
2859
+ const inputRef = React2.useRef(null);
2860
+ const spanRef = React2.useRef(null);
2861
+ const [inputWidth, setInputWidth] = React2.useState(`auto`);
2862
+ React2.useImperativeHandle(
845
2863
  ref,
846
2864
  () => ({
847
2865
  focus: () => {
@@ -851,7 +2869,7 @@ var ElasticInput = React.forwardRef(function ElasticInputFC(props, ref) {
851
2869
  })
852
2870
  );
853
2871
  const extraWidth = props.type === `number` ? 15 : 0;
854
- React.useLayoutEffect(() => {
2872
+ React2.useLayoutEffect(() => {
855
2873
  if (spanRef.current) {
856
2874
  setInputWidth(`${spanRef.current.offsetWidth + extraWidth}px`);
857
2875
  const interval = setInterval(() => {
@@ -896,10 +2914,10 @@ var ElasticInput = React.forwardRef(function ElasticInputFC(props, ref) {
896
2914
  ] });
897
2915
  });
898
2916
 
899
- // ../../anvl/src/number/clamp.ts
2917
+ // ../anvl/src/number/clamp.ts
900
2918
  var clampInto = (min, max) => (value) => value < min ? min : value > max ? max : value;
901
2919
 
902
- // ../../anvl/src/number/wrap.ts
2920
+ // ../anvl/src/number/wrap.ts
903
2921
  var wrapInto = (min, max) => (value) => value < min ? max - (min - value) % (max - min) : min + (value - min) % (max - min);
904
2922
  function round(value, decimalPlaces) {
905
2923
  if (decimalPlaces === void 0)
@@ -961,9 +2979,9 @@ var NumberInput = ({
961
2979
  testId,
962
2980
  value = null
963
2981
  }) => {
964
- const id = React.useId();
965
- const [temporaryEntry, setTemporaryEntry] = React.useState(null);
966
- const userHasMadeDeliberateChange = React.useRef(false);
2982
+ const id = React2.useId();
2983
+ const [temporaryEntry, setTemporaryEntry] = React2.useState(null);
2984
+ const userHasMadeDeliberateChange = React2.useRef(false);
967
2985
  const refine = initRefinery({ max, min, decimalPlaces, nullable: true });
968
2986
  const allowDecimal = decimalPlaces === void 0 || decimalPlaces > 0;
969
2987
  const handleBlur = () => {
@@ -1133,11 +3151,11 @@ var JsonEditor_INTERNAL = ({
1133
3151
  ] }) });
1134
3152
  };
1135
3153
 
1136
- // ../../hamr/src/react-json-editor/editors-by-type/utilities/array-elements.ts
3154
+ // ../hamr/src/react-json-editor/editors-by-type/utilities/array-elements.ts
1137
3155
  var makeElementSetters = (data, set) => data.map(
1138
3156
  (value, index) => (newValue) => set(() => {
1139
3157
  const newData = [...data];
1140
- newData[index] = become(newValue)(value);
3158
+ newData[index] = become2(newValue)(value);
1141
3159
  return newData;
1142
3160
  })
1143
3161
  );
@@ -1167,7 +3185,7 @@ var ArrayEditor = ({
1167
3185
  }) });
1168
3186
  };
1169
3187
 
1170
- // ../../anvl/src/json-schema/integer.ts
3188
+ // ../anvl/src/json-schema/integer.ts
1171
3189
  var isInteger = (input) => Number.isInteger(input);
1172
3190
  var parseInteger = (input) => {
1173
3191
  if (isInteger(input))
@@ -1228,7 +3246,7 @@ asNumber(new Fraction(1, 2));
1228
3246
  asNumber([new Fraction(1, 2)]);
1229
3247
  asNumber({ a: new Fraction(1, 2) });
1230
3248
 
1231
- // ../../anvl/src/json-schema/refs.ts
3249
+ // ../anvl/src/json-schema/refs.ts
1232
3250
  function isJsonSchemaRef(input) {
1233
3251
  return doesExtend({
1234
3252
  $ref: isString
@@ -1281,7 +3299,7 @@ var retrieveRef = ({
1281
3299
  throw new TypeError(`The refNode is not a JsonSchema`);
1282
3300
  };
1283
3301
 
1284
- // ../../anvl/src/json-schema/string-formats.ts
3302
+ // ../anvl/src/json-schema/string-formats.ts
1285
3303
  var JSON_SCHEMA_STRING_FORMATS = [
1286
3304
  `date-time`,
1287
3305
  `date`,
@@ -1297,7 +3315,7 @@ var JSON_SCHEMA_STRING_FORMATS = [
1297
3315
  `uuid`
1298
3316
  ];
1299
3317
 
1300
- // ../../anvl/src/json-schema/json-schema.ts
3318
+ // ../anvl/src/json-schema/json-schema.ts
1301
3319
  var JSON_SCHEMA_TYPE_NAMES = [...JSON_TYPE_NAMES, `integer`];
1302
3320
  [
1303
3321
  ...JSON_SCHEMA_TYPE_NAMES,
@@ -1420,7 +3438,7 @@ function isJsonSchema(input) {
1420
3438
  return mustSatisfyOneOfTheFollowing(isBoolean).or(isJsonSchemaObject).or(isJsonSchemaRef)(input);
1421
3439
  }
1422
3440
 
1423
- // ../../anvl/src/json-schema/path-into.ts
3441
+ // ../anvl/src/json-schema/path-into.ts
1424
3442
  var expandPathForSchema = (path) => {
1425
3443
  try {
1426
3444
  return path.flatMap((key) => {
@@ -1448,7 +3466,7 @@ var expandPathForSchema = (path) => {
1448
3466
  }
1449
3467
  };
1450
3468
 
1451
- // ../../anvl/src/json-schema/find-sub-schema.ts
3469
+ // ../anvl/src/json-schema/find-sub-schema.ts
1452
3470
  var findSubSchema = (schema) => {
1453
3471
  if (typeof schema === `boolean`) {
1454
3472
  throw new Error(`The schema does not contain subSchemas`);
@@ -1479,7 +3497,7 @@ var findSubSchema = (schema) => {
1479
3497
  };
1480
3498
  };
1481
3499
 
1482
- // ../../anvl/src/json/cast-json.ts
3500
+ // ../anvl/src/json/cast-json.ts
1483
3501
  var stringToBoolean = (str) => str === `true`;
1484
3502
  var stringToNumber = (str) => Number(str);
1485
3503
  var stringToArray = (str) => str.split(`,`);
@@ -1525,7 +3543,7 @@ var nullToBoolean = () => false;
1525
3543
  var nullToArray = () => [];
1526
3544
  var nullToObject = () => ({});
1527
3545
 
1528
- // ../../anvl/src/refinement/smart-cast-json.ts
3546
+ // ../anvl/src/refinement/smart-cast-json.ts
1529
3547
  var castToJson = (input) => {
1530
3548
  const json = refineJsonType(input);
1531
3549
  return {
@@ -1615,10 +3633,10 @@ var castToJson = (input) => {
1615
3633
  };
1616
3634
  };
1617
3635
 
1618
- // ../../hamr/src/react-json-editor/editors-by-type/utilities/object-properties.ts
3636
+ // ../hamr/src/react-json-editor/editors-by-type/utilities/object-properties.ts
1619
3637
  var makePropertySetters = (data, set) => mapObject(
1620
3638
  data,
1621
- (value, key) => (newValue) => set(__spreadProps(__spreadValues({}, data), { [key]: become(newValue)(value[key]) }))
3639
+ (value, key) => (newValue) => set(__spreadProps(__spreadValues({}, data), { [key]: become2(newValue)(value[key]) }))
1622
3640
  );
1623
3641
  var makePropertyRenamers = (data, set, stableKeyMapRef) => mapObject(
1624
3642
  data,
@@ -1677,7 +3695,7 @@ var ObjectEditor = ({
1677
3695
  }) => {
1678
3696
  var _a2;
1679
3697
  const disabled = isReadonly(path);
1680
- const stableKeyMap = React.useRef(
3698
+ const stableKeyMap = React2.useRef(
1681
3699
  Object.keys(data).reduce(
1682
3700
  (acc, key) => {
1683
3701
  acc[key] = key;
@@ -1843,7 +3861,7 @@ var DefaultFallback = ({ error, errorInfo }) => {
1843
3861
  }
1844
3862
  );
1845
3863
  };
1846
- var ErrorBoundary = class extends React.Component {
3864
+ var ErrorBoundary = class extends React2.Component {
1847
3865
  constructor(props) {
1848
3866
  super(props);
1849
3867
  this.state = {};
@@ -1941,7 +3959,7 @@ var JsonEditor = ({
1941
3959
  );
1942
3960
  };
1943
3961
 
1944
- // ../../hamr/src/react-json-editor/index.ts
3962
+ // ../hamr/src/react-json-editor/index.ts
1945
3963
  var SubEditors = {
1946
3964
  array: ArrayEditor,
1947
3965
  boolean: BooleanEditor,
@@ -1951,7 +3969,7 @@ var SubEditors = {
1951
3969
  string: StringEditor
1952
3970
  };
1953
3971
 
1954
- // ../../anvl/src/string/string-to-color.ts
3972
+ // ../anvl/src/string/string-to-color.ts
1955
3973
  function stringToColor(input) {
1956
3974
  let hash = 0;
1957
3975
  for (let i = 0; i < input.length; i++) {
@@ -1966,20 +3984,20 @@ function stringToColor(input) {
1966
3984
  return `#${hexColor}`;
1967
3985
  }
1968
3986
 
1969
- // ../../luum/src/constants/index.ts
3987
+ // ../luum/src/constants/index.ts
1970
3988
  var CHANNEL_SPECIFIC_LUM = {
1971
3989
  R: 0.3,
1972
3990
  G: 0.5,
1973
3991
  B: 0.2
1974
3992
  };
1975
3993
 
1976
- // ../../luum/src/constants/filters.ts
3994
+ // ../luum/src/constants/filters.ts
1977
3995
  var unfiltered = [
1978
3996
  { sat: 255, hue: 0 },
1979
3997
  { sat: 255, hue: 360 }
1980
3998
  ];
1981
3999
 
1982
- // ../../luum/src/export/channelsToHex.ts
4000
+ // ../luum/src/export/channelsToHex.ts
1983
4001
  var channelsToHex = (channels) => `#${Object.values(channels).map((channel) => {
1984
4002
  let channelHex = channel.toString(16);
1985
4003
  if (channelHex.length === 1)
@@ -1988,7 +4006,7 @@ var channelsToHex = (channels) => `#${Object.values(channels).map((channel) => {
1988
4006
  }).join(``)}`;
1989
4007
  var channelsToHex_default = channelsToHex;
1990
4008
 
1991
- // ../../luum/src/import/hueToRelativeChannels.ts
4009
+ // ../luum/src/import/hueToRelativeChannels.ts
1992
4010
  var hueToRelativeChannels_default = (hue) => {
1993
4011
  const hueWrapped = wrapInto(0, 360)(hue);
1994
4012
  const hueReduced = hueWrapped / 60;
@@ -2014,7 +4032,7 @@ var hueToRelativeChannels_default = (hue) => {
2014
4032
  }
2015
4033
  };
2016
4034
 
2017
- // ../../luum/src/solveFor/hueFromChannels.ts
4035
+ // ../luum/src/solveFor/hueFromChannels.ts
2018
4036
  var hueFromChannels = ({ R, G, B }) => {
2019
4037
  let hue = 0;
2020
4038
  if (R > G && G >= B)
@@ -2033,14 +4051,14 @@ var hueFromChannels = ({ R, G, B }) => {
2033
4051
  };
2034
4052
  var hueFromChannels_default = hueFromChannels;
2035
4053
 
2036
- // ../../luum/src/solveFor/lumFromChannels.ts
4054
+ // ../luum/src/solveFor/lumFromChannels.ts
2037
4055
  var lumFromChannels = ({ R, G, B }) => {
2038
4056
  const lum = CHANNEL_SPECIFIC_LUM.R * R / 255 + CHANNEL_SPECIFIC_LUM.G * G / 255 + CHANNEL_SPECIFIC_LUM.B * B / 255;
2039
4057
  return lum;
2040
4058
  };
2041
4059
  var lumFromChannels_default = lumFromChannels;
2042
4060
 
2043
- // ../../luum/src/solveFor/maxSatForHueInFilter.ts
4061
+ // ../luum/src/solveFor/maxSatForHueInFilter.ts
2044
4062
  var maxSatForHueInFilter_default = (hue, filter) => {
2045
4063
  let maxSat = 255;
2046
4064
  const hueWrapped = wrapInto(0, 360)(hue);
@@ -2063,14 +4081,14 @@ var maxSatForHueInFilter_default = (hue, filter) => {
2063
4081
  return maxSat;
2064
4082
  };
2065
4083
 
2066
- // ../../luum/src/solveFor/satFromChannels.ts
4084
+ // ../luum/src/solveFor/satFromChannels.ts
2067
4085
  var satFromChannels = ({ R, G, B }) => {
2068
4086
  const sat = Math.max(R, G, B) - Math.min(R, G, B);
2069
4087
  return sat;
2070
4088
  };
2071
4089
  var satFromChannels_default = satFromChannels;
2072
4090
 
2073
- // ../../luum/src/solveFor/specificLumFromHue.ts
4091
+ // ../luum/src/solveFor/specificLumFromHue.ts
2074
4092
  var specificLumFromHue_default = (hue) => {
2075
4093
  const [factorR, factorG, factorB] = hueToRelativeChannels_default(hue);
2076
4094
  const lumR = CHANNEL_SPECIFIC_LUM.R * factorR;
@@ -2080,7 +4098,7 @@ var specificLumFromHue_default = (hue) => {
2080
4098
  return specificLum;
2081
4099
  };
2082
4100
 
2083
- // ../../luum/src/export/specToChannelsFixLimit.ts
4101
+ // ../luum/src/export/specToChannelsFixLimit.ts
2084
4102
  var minChannelsForSaturationFromHue = (hue) => {
2085
4103
  const relativeChannels = hueToRelativeChannels_default(hue);
2086
4104
  const channelSpreader = (trueSaturation) => {
@@ -2164,7 +4182,7 @@ var specToChannelsFixLimit = ({ hue, sat, lum, prefer = `lum` }, filter = unfilt
2164
4182
  };
2165
4183
  var specToChannelsFixLimit_default = specToChannelsFixLimit;
2166
4184
 
2167
- // ../../luum/src/export/specToHexFixLimit.ts
4185
+ // ../luum/src/export/specToHexFixLimit.ts
2168
4186
  var specToHexFixLimit = ({ hue, sat, lum, prefer }, filter) => {
2169
4187
  const { channels, fix, limit } = specToChannelsFixLimit_default(
2170
4188
  {
@@ -2181,14 +4199,14 @@ var specToHexFixLimit = ({ hue, sat, lum, prefer }, filter) => {
2181
4199
  };
2182
4200
  var specToHexFixLimit_default = specToHexFixLimit;
2183
4201
 
2184
- // ../../luum/src/export/specToHex.ts
4202
+ // ../luum/src/export/specToHex.ts
2185
4203
  var specToHex = ({ hue, sat, lum, prefer }, filter) => {
2186
4204
  const { hex } = specToHexFixLimit_default({ hue, sat, lum, prefer }, filter);
2187
4205
  return hex;
2188
4206
  };
2189
4207
  var specToHex_default = specToHex;
2190
4208
 
2191
- // ../../luum/src/import/channelsToSpec.ts
4209
+ // ../luum/src/import/channelsToSpec.ts
2192
4210
  var channelsToSpec = ({ R, G, B }) => {
2193
4211
  const hue = hueFromChannels_default({ R, G, B });
2194
4212
  const sat = satFromChannels_default({ R, G, B });
@@ -2197,7 +4215,7 @@ var channelsToSpec = ({ R, G, B }) => {
2197
4215
  };
2198
4216
  var channelsToSpec_default = channelsToSpec;
2199
4217
 
2200
- // ../../luum/src/import/normalizeHex.ts
4218
+ // ../luum/src/import/normalizeHex.ts
2201
4219
  var BASE_16_CHAR_SET = `[a-fA-F0-9]+`;
2202
4220
  var miniHexToHex = (miniHex) => {
2203
4221
  const miniHexArray = miniHex.split(``);
@@ -2219,7 +4237,7 @@ var normalizeHex = (maybeHex) => {
2219
4237
  };
2220
4238
  var normalizeHex_default = normalizeHex;
2221
4239
 
2222
- // ../../luum/src/import/hexToChannels.ts
4240
+ // ../luum/src/import/hexToChannels.ts
2223
4241
  var hexToChannels_default = (maybeHex) => {
2224
4242
  const hex = normalizeHex_default(maybeHex);
2225
4243
  return {
@@ -2229,7 +4247,7 @@ var hexToChannels_default = (maybeHex) => {
2229
4247
  };
2230
4248
  };
2231
4249
 
2232
- // ../../luum/src/import/hexToSpec.ts
4250
+ // ../luum/src/import/hexToSpec.ts
2233
4251
  var hexToSpec = (hex) => {
2234
4252
  const { R, G, B } = hexToChannels_default(hex);
2235
4253
  const { hue, sat, lum } = channelsToSpec_default({ R, G, B });
@@ -2237,7 +4255,7 @@ var hexToSpec = (hex) => {
2237
4255
  };
2238
4256
  var hexToSpec_default = hexToSpec;
2239
4257
 
2240
- // ../../luum/src/mixers/contrast.ts
4258
+ // ../luum/src/mixers/contrast.ts
2241
4259
  var contrastMax = (color) => __spreadProps(__spreadValues({}, color), {
2242
4260
  lum: color.lum > 0.666 ? 0 : 1
2243
4261
  });
@@ -2245,7 +4263,7 @@ var offset = (offsetAmount) => (color) => __spreadProps(__spreadValues({}, color
2245
4263
  lum: color.lum > 0.666 ? color.lum - offsetAmount : color.lum + offsetAmount
2246
4264
  });
2247
4265
 
2248
- // ../../luum/src/constants/luum-spec.ts
4266
+ // ../luum/src/constants/luum-spec.ts
2249
4267
  var defaultSpec = {
2250
4268
  hue: 0,
2251
4269
  lum: 0,
@@ -2253,7 +4271,7 @@ var defaultSpec = {
2253
4271
  prefer: `lum`
2254
4272
  };
2255
4273
 
2256
- // ../../luum/src/scheme/index.ts
4274
+ // ../luum/src/scheme/index.ts
2257
4275
  var isLuumSpec = (input) => typeof input === `object` && input !== null && typeof input.hue === `number` && typeof input.sat === `number` && typeof input.lum === `number` && [`sat`, `lum`].includes(input.prefer);
2258
4276
  isModifier(isLuumSpec)(defaultSpec);
2259
4277
  var WAYFORGE_CORE_COLOR_NAMES = [
@@ -2283,14 +4301,14 @@ WAYFORGE_CORE_COLOR_NAMES.reduce(
2283
4301
  {}
2284
4302
  );
2285
4303
  var Id = ({ id }) => {
2286
- const [isOpen, setIsOpen] = React__namespace.useState(false);
2287
- const { refs, floatingStyles, context } = react$1.useFloating({
4304
+ const [isOpen, setIsOpen] = React2__namespace.useState(false);
4305
+ const { refs, floatingStyles, context } = react.useFloating({
2288
4306
  open: isOpen,
2289
4307
  onOpenChange: setIsOpen,
2290
4308
  placement: `bottom-start`
2291
4309
  });
2292
- const click = react$1.useClick(context);
2293
- const { getReferenceProps, getFloatingProps } = react$1.useInteractions([click]);
4310
+ const click = react.useClick(context);
4311
+ const { getReferenceProps, getFloatingProps } = react.useInteractions([click]);
2294
4312
  const bgColor = stringToColor(id);
2295
4313
  const contrastColor = pipe(bgColor, hexToSpec_default, contrastMax, specToHex_default);
2296
4314
  const offsetColor = pipe(bgColor, hexToSpec_default, offset(0.25), specToHex_default);
@@ -2318,7 +4336,7 @@ var Id = ({ id }) => {
2318
4336
  children: id.substring(0, 3)
2319
4337
  })
2320
4338
  ),
2321
- isOpen && /* @__PURE__ */ jsxRuntime.jsx(react$1.FloatingPortal, { children: /* @__PURE__ */ jsxRuntime.jsx(
4339
+ isOpen && /* @__PURE__ */ jsxRuntime.jsx(react.FloatingPortal, { children: /* @__PURE__ */ jsxRuntime.jsx(
2322
4340
  "span",
2323
4341
  __spreadProps(__spreadValues({
2324
4342
  role: "popup",
@@ -2336,7 +4354,7 @@ var Id = ({ id }) => {
2336
4354
  ] });
2337
4355
  };
2338
4356
 
2339
- // ../../hamr/src/react-data-designer/RelationEditor.module.scss
4357
+ // ../hamr/src/react-data-designer/RelationEditor.module.scss
2340
4358
  var RelationEditor_module_default = {};
2341
4359
  var RelationEditor = (props) => {
2342
4360
  const seen = /* @__PURE__ */ new Set();
@@ -2356,8 +4374,8 @@ var RelationEditor = (props) => {
2356
4374
  ] })) });
2357
4375
  };
2358
4376
  var StateEditor = ({ token }) => {
2359
- const set = react.useI(token);
2360
- const data = react.useO(token);
4377
+ const set = useI(token);
4378
+ const data = useO(token);
2361
4379
  return isJson(data) ? /* @__PURE__ */ jsxRuntime.jsx(JsonEditor, { data, set, schema: true }) : data instanceof Join ? /* @__PURE__ */ jsxRuntime.jsx(RelationEditor, { data, set }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "json_editor", children: /* @__PURE__ */ jsxRuntime.jsx(
2362
4380
  ElasticInput,
2363
4381
  {
@@ -2367,7 +4385,7 @@ var StateEditor = ({ token }) => {
2367
4385
  ) });
2368
4386
  };
2369
4387
  var ReadonlySelectorViewer = ({ token }) => {
2370
- const data = react.useO(token);
4388
+ const data = useO(token);
2371
4389
  return isJson(data) ? /* @__PURE__ */ jsxRuntime.jsx(
2372
4390
  JsonEditor,
2373
4391
  {
@@ -2390,7 +4408,7 @@ var StoreEditor = ({ token }) => {
2390
4408
  }
2391
4409
  return /* @__PURE__ */ jsxRuntime.jsx(StateEditor, { token });
2392
4410
  };
2393
- var findStateTypeState = atom_io.selectorFamily({
4411
+ var findStateTypeState = selectorFamily({
2394
4412
  key: `\u{1F441}\u200D\u{1F5E8} State Type`,
2395
4413
  get: (token) => ({ get }) => {
2396
4414
  let state;
@@ -2408,10 +4426,10 @@ var findStateTypeState = atom_io.selectorFamily({
2408
4426
  });
2409
4427
  var StateIndexLeafNode = ({ node, isOpenState, typeState }) => {
2410
4428
  var _a2, _b;
2411
- const setIsOpen = react.useI(isOpenState);
2412
- const isOpen = react.useO(isOpenState);
2413
- const state = react.useO(node);
2414
- const stateType = react.useO(typeState);
4429
+ const setIsOpen = useI(isOpenState);
4430
+ const isOpen = useO(isOpenState);
4431
+ const state = useO(node);
4432
+ const stateType = useO(typeState);
2415
4433
  const isPrimitive = Boolean(primitiveRefinery.refine(state));
2416
4434
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2417
4435
  /* @__PURE__ */ jsxRuntime.jsxs("header", { children: [
@@ -2426,8 +4444,8 @@ var StateIndexLeafNode = ({ node, isOpenState, typeState }) => {
2426
4444
  /* @__PURE__ */ jsxRuntime.jsxs(
2427
4445
  "label",
2428
4446
  {
2429
- onClick: () => console.log(node, atom_io.getState(node)),
2430
- onKeyUp: () => console.log(node, atom_io.getState(node)),
4447
+ onClick: () => console.log(node, getState(node)),
4448
+ onKeyUp: () => console.log(node, getState(node)),
2431
4449
  children: [
2432
4450
  /* @__PURE__ */ jsxRuntime.jsx("h2", { children: (_b = (_a2 = node.family) == null ? void 0 : _a2.subKey) != null ? _b : node.key }),
2433
4451
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "type detail", children: [
@@ -2444,8 +4462,8 @@ var StateIndexLeafNode = ({ node, isOpenState, typeState }) => {
2444
4462
  ] });
2445
4463
  };
2446
4464
  var StateIndexTreeNode = ({ node, isOpenState }) => {
2447
- const setIsOpen = react.useI(isOpenState);
2448
- const isOpen = react.useO(isOpenState);
4465
+ const setIsOpen = useI(isOpenState);
4466
+ const isOpen = useO(isOpenState);
2449
4467
  for (const [key, childNode] of recordToEntries(node.familyMembers)) {
2450
4468
  findViewIsOpenState(key);
2451
4469
  findStateTypeState(childNode);
@@ -2483,7 +4501,7 @@ var StateIndexNode = ({ node, isOpenState, typeState }) => {
2483
4501
  ) : /* @__PURE__ */ jsxRuntime.jsx(StateIndexTreeNode, { node, isOpenState }) });
2484
4502
  };
2485
4503
  var StateIndex = ({ tokenIndex }) => {
2486
- const tokenIds = react.useO(tokenIndex);
4504
+ const tokenIds = useO(tokenIndex);
2487
4505
  return /* @__PURE__ */ jsxRuntime.jsx("article", { className: "index state_index", children: Object.entries(tokenIds).filter(([key]) => !key.startsWith(`\u{1F441}\u200D\u{1F5E8}`)).sort().map(([key, node]) => {
2488
4506
  return /* @__PURE__ */ jsxRuntime.jsx(
2489
4507
  StateIndexNode,
@@ -2623,9 +4641,9 @@ var YouAreHere = () => {
2623
4641
  return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "you_are_here", children: "you are here" });
2624
4642
  };
2625
4643
  var TimelineLog = ({ token, isOpenState, timelineState }) => {
2626
- const timeline = react.useO(timelineState);
2627
- const isOpen = react.useO(isOpenState);
2628
- const setIsOpen = react.useI(isOpenState);
4644
+ const timeline = useO(timelineState);
4645
+ const isOpen = useO(isOpenState);
4646
+ const setIsOpen = useI(isOpenState);
2629
4647
  return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "node timeline_log", children: [
2630
4648
  /* @__PURE__ */ jsxRuntime.jsxs("header", { children: [
2631
4649
  /* @__PURE__ */ jsxRuntime.jsx(button.OpenClose, { isOpen, setIsOpen }),
@@ -2644,7 +4662,7 @@ var TimelineLog = ({ token, isOpenState, timelineState }) => {
2644
4662
  "button",
2645
4663
  {
2646
4664
  type: "button",
2647
- onClick: () => atom_io.undo(token),
4665
+ onClick: () => undo(token),
2648
4666
  disabled: timeline.at === 0,
2649
4667
  children: "undo"
2650
4668
  }
@@ -2653,7 +4671,7 @@ var TimelineLog = ({ token, isOpenState, timelineState }) => {
2653
4671
  "button",
2654
4672
  {
2655
4673
  type: "button",
2656
- onClick: () => atom_io.redo(token),
4674
+ onClick: () => redo(token),
2657
4675
  disabled: timeline.at === timeline.history.length,
2658
4676
  children: "redo"
2659
4677
  }
@@ -2661,7 +4679,7 @@ var TimelineLog = ({ token, isOpenState, timelineState }) => {
2661
4679
  ] })
2662
4680
  ] })
2663
4681
  ] }),
2664
- isOpen ? /* @__PURE__ */ jsxRuntime.jsx("main", { children: timeline.history.map((update, index) => /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
4682
+ isOpen ? /* @__PURE__ */ jsxRuntime.jsx("main", { children: timeline.history.map((update, index) => /* @__PURE__ */ jsxRuntime.jsxs(React2.Fragment, { children: [
2665
4683
  index === timeline.at ? /* @__PURE__ */ jsxRuntime.jsx(YouAreHere, {}) : null,
2666
4684
  /* @__PURE__ */ jsxRuntime.jsx(article.TimelineUpdate, { timelineUpdate: update }),
2667
4685
  index === timeline.history.length - 1 && timeline.at === timeline.history.length ? /* @__PURE__ */ jsxRuntime.jsx(YouAreHere, {}) : null
@@ -2669,7 +4687,7 @@ var TimelineLog = ({ token, isOpenState, timelineState }) => {
2669
4687
  ] });
2670
4688
  };
2671
4689
  var TimelineIndex = () => {
2672
- const tokenIds = react.useO(timelineIndex);
4690
+ const tokenIds = useO(timelineIndex);
2673
4691
  return /* @__PURE__ */ jsxRuntime.jsx("article", { className: "index timeline_index", children: tokenIds.filter((token) => !token.key.startsWith(`\u{1F441}\u200D\u{1F5E8}`)).map((token) => {
2674
4692
  return /* @__PURE__ */ jsxRuntime.jsx(
2675
4693
  TimelineLog,
@@ -2683,9 +4701,9 @@ var TimelineIndex = () => {
2683
4701
  }) });
2684
4702
  };
2685
4703
  var TransactionLog = ({ token, isOpenState, logState }) => {
2686
- const log = react.useO(logState);
2687
- const isOpen = react.useO(isOpenState);
2688
- const setIsOpen = react.useI(isOpenState);
4704
+ const log = useO(logState);
4705
+ const isOpen = useO(isOpenState);
4706
+ const setIsOpen = useI(isOpenState);
2689
4707
  return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "node transaction_log", children: [
2690
4708
  /* @__PURE__ */ jsxRuntime.jsxs("header", { children: [
2691
4709
  /* @__PURE__ */ jsxRuntime.jsx(button.OpenClose, { isOpen, setIsOpen }),
@@ -2709,7 +4727,7 @@ var TransactionLog = ({ token, isOpenState, logState }) => {
2709
4727
  ] });
2710
4728
  };
2711
4729
  var TransactionIndex = () => {
2712
- const tokenIds = react.useO(transactionIndex);
4730
+ const tokenIds = useO(transactionIndex);
2713
4731
  return /* @__PURE__ */ jsxRuntime.jsx("article", { className: "index transaction_index", children: tokenIds.filter((token) => !token.key.startsWith(`\u{1F441}\u200D\u{1F5E8}`)).map((token) => {
2714
4732
  return /* @__PURE__ */ jsxRuntime.jsx(
2715
4733
  TransactionLog,
@@ -2723,13 +4741,13 @@ var TransactionIndex = () => {
2723
4741
  }) });
2724
4742
  };
2725
4743
  var AtomIODevtools = () => {
2726
- const constraintsRef = React.useRef(null);
2727
- const setDevtoolsAreOpen = react.useI(devtoolsAreOpenState);
2728
- const devtoolsAreOpen = react.useO(devtoolsAreOpenState);
2729
- const setDevtoolsView = react.useI(devtoolsViewSelectionState);
2730
- const devtoolsView = react.useO(devtoolsViewSelectionState);
2731
- const devtoolsViewOptions = react.useO(devtoolsViewOptionsState);
2732
- const mouseHasMoved = React.useRef(false);
4744
+ const constraintsRef = React2.useRef(null);
4745
+ const setDevtoolsAreOpen = useI(devtoolsAreOpenState);
4746
+ const devtoolsAreOpen = useO(devtoolsAreOpenState);
4747
+ const setDevtoolsView = useI(devtoolsViewSelectionState);
4748
+ const devtoolsView = useO(devtoolsViewSelectionState);
4749
+ const devtoolsViewOptions = useO(devtoolsViewOptionsState);
4750
+ const mouseHasMoved = React2.useRef(false);
2733
4751
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2734
4752
  /* @__PURE__ */ jsxRuntime.jsx(
2735
4753
  framerMotion.motion.span,
@@ -2797,7 +4815,7 @@ var AtomIODevtools = () => {
2797
4815
  ] });
2798
4816
  };
2799
4817
 
2800
- // src/index.ts
4818
+ // react-devtools/src/index.ts
2801
4819
  var {
2802
4820
  atomIndex,
2803
4821
  selectorIndex,
@@ -2805,23 +4823,23 @@ var {
2805
4823
  findTransactionLogState,
2806
4824
  timelineIndex,
2807
4825
  findTimelineState
2808
- } = introspection.attachIntrospectionStates();
2809
- var devtoolsAreOpenState = atom_io.atom({
4826
+ } = attachIntrospectionStates();
4827
+ var devtoolsAreOpenState = atom({
2810
4828
  key: `\u{1F441}\u200D\u{1F5E8} Devtools Are Open`,
2811
4829
  default: true,
2812
4830
  effects: [lazyLocalStorageEffect(`\u{1F441}\u200D\u{1F5E8} Devtools Are Open`)]
2813
4831
  });
2814
- var devtoolsViewSelectionState = atom_io.atom({
4832
+ var devtoolsViewSelectionState = atom({
2815
4833
  key: `\u{1F441}\u200D\u{1F5E8} Devtools View Selection`,
2816
4834
  default: `atoms`,
2817
4835
  effects: [lazyLocalStorageEffect(`\u{1F441}\u200D\u{1F5E8} Devtools View`)]
2818
4836
  });
2819
- var devtoolsViewOptionsState = atom_io.atom({
4837
+ var devtoolsViewOptionsState = atom({
2820
4838
  key: `\u{1F441}\u200D\u{1F5E8} Devtools View Options`,
2821
4839
  default: [`atoms`, `selectors`, `transactions`, `timelines`],
2822
4840
  effects: [lazyLocalStorageEffect(`\u{1F441}\u200D\u{1F5E8} Devtools View Options`)]
2823
4841
  });
2824
- var findViewIsOpenState = atom_io.atomFamily({
4842
+ var findViewIsOpenState = atomFamily({
2825
4843
  key: `\u{1F441}\u200D\u{1F5E8} Devtools View Is Open`,
2826
4844
  default: false,
2827
4845
  effects: (key) => [lazyLocalStorageEffect(key + `:view-is-open`)]