@unseenco/theatre-dataverse 0.1.5 → 0.1.6
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.
- package/dist/index.js +299 -89
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +1759 -0
- package/dist/index.mjs.map +7 -0
- package/package.json +11 -2
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1759 @@
|
|
|
1
|
+
// ../../node_modules/lodash-es/isArray.js
|
|
2
|
+
var isArray = Array.isArray;
|
|
3
|
+
var isArray_default = isArray;
|
|
4
|
+
|
|
5
|
+
// ../../node_modules/lodash-es/_freeGlobal.js
|
|
6
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
7
|
+
var freeGlobal_default = freeGlobal;
|
|
8
|
+
|
|
9
|
+
// ../../node_modules/lodash-es/_root.js
|
|
10
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
11
|
+
var root = freeGlobal_default || freeSelf || Function("return this")();
|
|
12
|
+
var root_default = root;
|
|
13
|
+
|
|
14
|
+
// ../../node_modules/lodash-es/_Symbol.js
|
|
15
|
+
var Symbol2 = root_default.Symbol;
|
|
16
|
+
var Symbol_default = Symbol2;
|
|
17
|
+
|
|
18
|
+
// ../../node_modules/lodash-es/_getRawTag.js
|
|
19
|
+
var objectProto = Object.prototype;
|
|
20
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
21
|
+
var nativeObjectToString = objectProto.toString;
|
|
22
|
+
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
23
|
+
function getRawTag(value) {
|
|
24
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
25
|
+
try {
|
|
26
|
+
value[symToStringTag] = void 0;
|
|
27
|
+
var unmasked = true;
|
|
28
|
+
} catch (e) {
|
|
29
|
+
}
|
|
30
|
+
var result = nativeObjectToString.call(value);
|
|
31
|
+
if (unmasked) {
|
|
32
|
+
if (isOwn) {
|
|
33
|
+
value[symToStringTag] = tag;
|
|
34
|
+
} else {
|
|
35
|
+
delete value[symToStringTag];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
var getRawTag_default = getRawTag;
|
|
41
|
+
|
|
42
|
+
// ../../node_modules/lodash-es/_objectToString.js
|
|
43
|
+
var objectProto2 = Object.prototype;
|
|
44
|
+
var nativeObjectToString2 = objectProto2.toString;
|
|
45
|
+
function objectToString(value) {
|
|
46
|
+
return nativeObjectToString2.call(value);
|
|
47
|
+
}
|
|
48
|
+
var objectToString_default = objectToString;
|
|
49
|
+
|
|
50
|
+
// ../../node_modules/lodash-es/_baseGetTag.js
|
|
51
|
+
var nullTag = "[object Null]";
|
|
52
|
+
var undefinedTag = "[object Undefined]";
|
|
53
|
+
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
54
|
+
function baseGetTag(value) {
|
|
55
|
+
if (value == null) {
|
|
56
|
+
return value === void 0 ? undefinedTag : nullTag;
|
|
57
|
+
}
|
|
58
|
+
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
|
|
59
|
+
}
|
|
60
|
+
var baseGetTag_default = baseGetTag;
|
|
61
|
+
|
|
62
|
+
// ../../node_modules/lodash-es/isObjectLike.js
|
|
63
|
+
function isObjectLike(value) {
|
|
64
|
+
return value != null && typeof value == "object";
|
|
65
|
+
}
|
|
66
|
+
var isObjectLike_default = isObjectLike;
|
|
67
|
+
|
|
68
|
+
// ../../node_modules/lodash-es/isSymbol.js
|
|
69
|
+
var symbolTag = "[object Symbol]";
|
|
70
|
+
function isSymbol(value) {
|
|
71
|
+
return typeof value == "symbol" || isObjectLike_default(value) && baseGetTag_default(value) == symbolTag;
|
|
72
|
+
}
|
|
73
|
+
var isSymbol_default = isSymbol;
|
|
74
|
+
|
|
75
|
+
// ../../node_modules/lodash-es/_isKey.js
|
|
76
|
+
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
|
|
77
|
+
var reIsPlainProp = /^\w*$/;
|
|
78
|
+
function isKey(value, object) {
|
|
79
|
+
if (isArray_default(value)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
var type = typeof value;
|
|
83
|
+
if (type == "number" || type == "symbol" || type == "boolean" || value == null || isSymbol_default(value)) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
|
|
87
|
+
}
|
|
88
|
+
var isKey_default = isKey;
|
|
89
|
+
|
|
90
|
+
// ../../node_modules/lodash-es/isObject.js
|
|
91
|
+
function isObject(value) {
|
|
92
|
+
var type = typeof value;
|
|
93
|
+
return value != null && (type == "object" || type == "function");
|
|
94
|
+
}
|
|
95
|
+
var isObject_default = isObject;
|
|
96
|
+
|
|
97
|
+
// ../../node_modules/lodash-es/isFunction.js
|
|
98
|
+
var asyncTag = "[object AsyncFunction]";
|
|
99
|
+
var funcTag = "[object Function]";
|
|
100
|
+
var genTag = "[object GeneratorFunction]";
|
|
101
|
+
var proxyTag = "[object Proxy]";
|
|
102
|
+
function isFunction(value) {
|
|
103
|
+
if (!isObject_default(value)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
var tag = baseGetTag_default(value);
|
|
107
|
+
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
108
|
+
}
|
|
109
|
+
var isFunction_default = isFunction;
|
|
110
|
+
|
|
111
|
+
// ../../node_modules/lodash-es/_coreJsData.js
|
|
112
|
+
var coreJsData = root_default["__core-js_shared__"];
|
|
113
|
+
var coreJsData_default = coreJsData;
|
|
114
|
+
|
|
115
|
+
// ../../node_modules/lodash-es/_isMasked.js
|
|
116
|
+
var maskSrcKey = function() {
|
|
117
|
+
var uid = /[^.]+$/.exec(coreJsData_default && coreJsData_default.keys && coreJsData_default.keys.IE_PROTO || "");
|
|
118
|
+
return uid ? "Symbol(src)_1." + uid : "";
|
|
119
|
+
}();
|
|
120
|
+
function isMasked(func) {
|
|
121
|
+
return !!maskSrcKey && maskSrcKey in func;
|
|
122
|
+
}
|
|
123
|
+
var isMasked_default = isMasked;
|
|
124
|
+
|
|
125
|
+
// ../../node_modules/lodash-es/_toSource.js
|
|
126
|
+
var funcProto = Function.prototype;
|
|
127
|
+
var funcToString = funcProto.toString;
|
|
128
|
+
function toSource(func) {
|
|
129
|
+
if (func != null) {
|
|
130
|
+
try {
|
|
131
|
+
return funcToString.call(func);
|
|
132
|
+
} catch (e) {
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
return func + "";
|
|
136
|
+
} catch (e) {
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return "";
|
|
140
|
+
}
|
|
141
|
+
var toSource_default = toSource;
|
|
142
|
+
|
|
143
|
+
// ../../node_modules/lodash-es/_baseIsNative.js
|
|
144
|
+
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
145
|
+
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
146
|
+
var funcProto2 = Function.prototype;
|
|
147
|
+
var objectProto3 = Object.prototype;
|
|
148
|
+
var funcToString2 = funcProto2.toString;
|
|
149
|
+
var hasOwnProperty2 = objectProto3.hasOwnProperty;
|
|
150
|
+
var reIsNative = RegExp(
|
|
151
|
+
"^" + funcToString2.call(hasOwnProperty2).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
|
|
152
|
+
);
|
|
153
|
+
function baseIsNative(value) {
|
|
154
|
+
if (!isObject_default(value) || isMasked_default(value)) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
var pattern = isFunction_default(value) ? reIsNative : reIsHostCtor;
|
|
158
|
+
return pattern.test(toSource_default(value));
|
|
159
|
+
}
|
|
160
|
+
var baseIsNative_default = baseIsNative;
|
|
161
|
+
|
|
162
|
+
// ../../node_modules/lodash-es/_getValue.js
|
|
163
|
+
function getValue(object, key) {
|
|
164
|
+
return object == null ? void 0 : object[key];
|
|
165
|
+
}
|
|
166
|
+
var getValue_default = getValue;
|
|
167
|
+
|
|
168
|
+
// ../../node_modules/lodash-es/_getNative.js
|
|
169
|
+
function getNative(object, key) {
|
|
170
|
+
var value = getValue_default(object, key);
|
|
171
|
+
return baseIsNative_default(value) ? value : void 0;
|
|
172
|
+
}
|
|
173
|
+
var getNative_default = getNative;
|
|
174
|
+
|
|
175
|
+
// ../../node_modules/lodash-es/_nativeCreate.js
|
|
176
|
+
var nativeCreate = getNative_default(Object, "create");
|
|
177
|
+
var nativeCreate_default = nativeCreate;
|
|
178
|
+
|
|
179
|
+
// ../../node_modules/lodash-es/_hashClear.js
|
|
180
|
+
function hashClear() {
|
|
181
|
+
this.__data__ = nativeCreate_default ? nativeCreate_default(null) : {};
|
|
182
|
+
this.size = 0;
|
|
183
|
+
}
|
|
184
|
+
var hashClear_default = hashClear;
|
|
185
|
+
|
|
186
|
+
// ../../node_modules/lodash-es/_hashDelete.js
|
|
187
|
+
function hashDelete(key) {
|
|
188
|
+
var result = this.has(key) && delete this.__data__[key];
|
|
189
|
+
this.size -= result ? 1 : 0;
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
var hashDelete_default = hashDelete;
|
|
193
|
+
|
|
194
|
+
// ../../node_modules/lodash-es/_hashGet.js
|
|
195
|
+
var HASH_UNDEFINED = "__lodash_hash_undefined__";
|
|
196
|
+
var objectProto4 = Object.prototype;
|
|
197
|
+
var hasOwnProperty3 = objectProto4.hasOwnProperty;
|
|
198
|
+
function hashGet(key) {
|
|
199
|
+
var data = this.__data__;
|
|
200
|
+
if (nativeCreate_default) {
|
|
201
|
+
var result = data[key];
|
|
202
|
+
return result === HASH_UNDEFINED ? void 0 : result;
|
|
203
|
+
}
|
|
204
|
+
return hasOwnProperty3.call(data, key) ? data[key] : void 0;
|
|
205
|
+
}
|
|
206
|
+
var hashGet_default = hashGet;
|
|
207
|
+
|
|
208
|
+
// ../../node_modules/lodash-es/_hashHas.js
|
|
209
|
+
var objectProto5 = Object.prototype;
|
|
210
|
+
var hasOwnProperty4 = objectProto5.hasOwnProperty;
|
|
211
|
+
function hashHas(key) {
|
|
212
|
+
var data = this.__data__;
|
|
213
|
+
return nativeCreate_default ? data[key] !== void 0 : hasOwnProperty4.call(data, key);
|
|
214
|
+
}
|
|
215
|
+
var hashHas_default = hashHas;
|
|
216
|
+
|
|
217
|
+
// ../../node_modules/lodash-es/_hashSet.js
|
|
218
|
+
var HASH_UNDEFINED2 = "__lodash_hash_undefined__";
|
|
219
|
+
function hashSet(key, value) {
|
|
220
|
+
var data = this.__data__;
|
|
221
|
+
this.size += this.has(key) ? 0 : 1;
|
|
222
|
+
data[key] = nativeCreate_default && value === void 0 ? HASH_UNDEFINED2 : value;
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
var hashSet_default = hashSet;
|
|
226
|
+
|
|
227
|
+
// ../../node_modules/lodash-es/_Hash.js
|
|
228
|
+
function Hash(entries) {
|
|
229
|
+
var index = -1, length = entries == null ? 0 : entries.length;
|
|
230
|
+
this.clear();
|
|
231
|
+
while (++index < length) {
|
|
232
|
+
var entry = entries[index];
|
|
233
|
+
this.set(entry[0], entry[1]);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
Hash.prototype.clear = hashClear_default;
|
|
237
|
+
Hash.prototype["delete"] = hashDelete_default;
|
|
238
|
+
Hash.prototype.get = hashGet_default;
|
|
239
|
+
Hash.prototype.has = hashHas_default;
|
|
240
|
+
Hash.prototype.set = hashSet_default;
|
|
241
|
+
var Hash_default = Hash;
|
|
242
|
+
|
|
243
|
+
// ../../node_modules/lodash-es/_listCacheClear.js
|
|
244
|
+
function listCacheClear() {
|
|
245
|
+
this.__data__ = [];
|
|
246
|
+
this.size = 0;
|
|
247
|
+
}
|
|
248
|
+
var listCacheClear_default = listCacheClear;
|
|
249
|
+
|
|
250
|
+
// ../../node_modules/lodash-es/eq.js
|
|
251
|
+
function eq(value, other) {
|
|
252
|
+
return value === other || value !== value && other !== other;
|
|
253
|
+
}
|
|
254
|
+
var eq_default = eq;
|
|
255
|
+
|
|
256
|
+
// ../../node_modules/lodash-es/_assocIndexOf.js
|
|
257
|
+
function assocIndexOf(array, key) {
|
|
258
|
+
var length = array.length;
|
|
259
|
+
while (length--) {
|
|
260
|
+
if (eq_default(array[length][0], key)) {
|
|
261
|
+
return length;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return -1;
|
|
265
|
+
}
|
|
266
|
+
var assocIndexOf_default = assocIndexOf;
|
|
267
|
+
|
|
268
|
+
// ../../node_modules/lodash-es/_listCacheDelete.js
|
|
269
|
+
var arrayProto = Array.prototype;
|
|
270
|
+
var splice = arrayProto.splice;
|
|
271
|
+
function listCacheDelete(key) {
|
|
272
|
+
var data = this.__data__, index = assocIndexOf_default(data, key);
|
|
273
|
+
if (index < 0) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
var lastIndex = data.length - 1;
|
|
277
|
+
if (index == lastIndex) {
|
|
278
|
+
data.pop();
|
|
279
|
+
} else {
|
|
280
|
+
splice.call(data, index, 1);
|
|
281
|
+
}
|
|
282
|
+
--this.size;
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
var listCacheDelete_default = listCacheDelete;
|
|
286
|
+
|
|
287
|
+
// ../../node_modules/lodash-es/_listCacheGet.js
|
|
288
|
+
function listCacheGet(key) {
|
|
289
|
+
var data = this.__data__, index = assocIndexOf_default(data, key);
|
|
290
|
+
return index < 0 ? void 0 : data[index][1];
|
|
291
|
+
}
|
|
292
|
+
var listCacheGet_default = listCacheGet;
|
|
293
|
+
|
|
294
|
+
// ../../node_modules/lodash-es/_listCacheHas.js
|
|
295
|
+
function listCacheHas(key) {
|
|
296
|
+
return assocIndexOf_default(this.__data__, key) > -1;
|
|
297
|
+
}
|
|
298
|
+
var listCacheHas_default = listCacheHas;
|
|
299
|
+
|
|
300
|
+
// ../../node_modules/lodash-es/_listCacheSet.js
|
|
301
|
+
function listCacheSet(key, value) {
|
|
302
|
+
var data = this.__data__, index = assocIndexOf_default(data, key);
|
|
303
|
+
if (index < 0) {
|
|
304
|
+
++this.size;
|
|
305
|
+
data.push([key, value]);
|
|
306
|
+
} else {
|
|
307
|
+
data[index][1] = value;
|
|
308
|
+
}
|
|
309
|
+
return this;
|
|
310
|
+
}
|
|
311
|
+
var listCacheSet_default = listCacheSet;
|
|
312
|
+
|
|
313
|
+
// ../../node_modules/lodash-es/_ListCache.js
|
|
314
|
+
function ListCache(entries) {
|
|
315
|
+
var index = -1, length = entries == null ? 0 : entries.length;
|
|
316
|
+
this.clear();
|
|
317
|
+
while (++index < length) {
|
|
318
|
+
var entry = entries[index];
|
|
319
|
+
this.set(entry[0], entry[1]);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
ListCache.prototype.clear = listCacheClear_default;
|
|
323
|
+
ListCache.prototype["delete"] = listCacheDelete_default;
|
|
324
|
+
ListCache.prototype.get = listCacheGet_default;
|
|
325
|
+
ListCache.prototype.has = listCacheHas_default;
|
|
326
|
+
ListCache.prototype.set = listCacheSet_default;
|
|
327
|
+
var ListCache_default = ListCache;
|
|
328
|
+
|
|
329
|
+
// ../../node_modules/lodash-es/_Map.js
|
|
330
|
+
var Map2 = getNative_default(root_default, "Map");
|
|
331
|
+
var Map_default = Map2;
|
|
332
|
+
|
|
333
|
+
// ../../node_modules/lodash-es/_mapCacheClear.js
|
|
334
|
+
function mapCacheClear() {
|
|
335
|
+
this.size = 0;
|
|
336
|
+
this.__data__ = {
|
|
337
|
+
"hash": new Hash_default(),
|
|
338
|
+
"map": new (Map_default || ListCache_default)(),
|
|
339
|
+
"string": new Hash_default()
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
var mapCacheClear_default = mapCacheClear;
|
|
343
|
+
|
|
344
|
+
// ../../node_modules/lodash-es/_isKeyable.js
|
|
345
|
+
function isKeyable(value) {
|
|
346
|
+
var type = typeof value;
|
|
347
|
+
return type == "string" || type == "number" || type == "symbol" || type == "boolean" ? value !== "__proto__" : value === null;
|
|
348
|
+
}
|
|
349
|
+
var isKeyable_default = isKeyable;
|
|
350
|
+
|
|
351
|
+
// ../../node_modules/lodash-es/_getMapData.js
|
|
352
|
+
function getMapData(map, key) {
|
|
353
|
+
var data = map.__data__;
|
|
354
|
+
return isKeyable_default(key) ? data[typeof key == "string" ? "string" : "hash"] : data.map;
|
|
355
|
+
}
|
|
356
|
+
var getMapData_default = getMapData;
|
|
357
|
+
|
|
358
|
+
// ../../node_modules/lodash-es/_mapCacheDelete.js
|
|
359
|
+
function mapCacheDelete(key) {
|
|
360
|
+
var result = getMapData_default(this, key)["delete"](key);
|
|
361
|
+
this.size -= result ? 1 : 0;
|
|
362
|
+
return result;
|
|
363
|
+
}
|
|
364
|
+
var mapCacheDelete_default = mapCacheDelete;
|
|
365
|
+
|
|
366
|
+
// ../../node_modules/lodash-es/_mapCacheGet.js
|
|
367
|
+
function mapCacheGet(key) {
|
|
368
|
+
return getMapData_default(this, key).get(key);
|
|
369
|
+
}
|
|
370
|
+
var mapCacheGet_default = mapCacheGet;
|
|
371
|
+
|
|
372
|
+
// ../../node_modules/lodash-es/_mapCacheHas.js
|
|
373
|
+
function mapCacheHas(key) {
|
|
374
|
+
return getMapData_default(this, key).has(key);
|
|
375
|
+
}
|
|
376
|
+
var mapCacheHas_default = mapCacheHas;
|
|
377
|
+
|
|
378
|
+
// ../../node_modules/lodash-es/_mapCacheSet.js
|
|
379
|
+
function mapCacheSet(key, value) {
|
|
380
|
+
var data = getMapData_default(this, key), size = data.size;
|
|
381
|
+
data.set(key, value);
|
|
382
|
+
this.size += data.size == size ? 0 : 1;
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
385
|
+
var mapCacheSet_default = mapCacheSet;
|
|
386
|
+
|
|
387
|
+
// ../../node_modules/lodash-es/_MapCache.js
|
|
388
|
+
function MapCache(entries) {
|
|
389
|
+
var index = -1, length = entries == null ? 0 : entries.length;
|
|
390
|
+
this.clear();
|
|
391
|
+
while (++index < length) {
|
|
392
|
+
var entry = entries[index];
|
|
393
|
+
this.set(entry[0], entry[1]);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
MapCache.prototype.clear = mapCacheClear_default;
|
|
397
|
+
MapCache.prototype["delete"] = mapCacheDelete_default;
|
|
398
|
+
MapCache.prototype.get = mapCacheGet_default;
|
|
399
|
+
MapCache.prototype.has = mapCacheHas_default;
|
|
400
|
+
MapCache.prototype.set = mapCacheSet_default;
|
|
401
|
+
var MapCache_default = MapCache;
|
|
402
|
+
|
|
403
|
+
// ../../node_modules/lodash-es/memoize.js
|
|
404
|
+
var FUNC_ERROR_TEXT = "Expected a function";
|
|
405
|
+
function memoize(func, resolver) {
|
|
406
|
+
if (typeof func != "function" || resolver != null && typeof resolver != "function") {
|
|
407
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
|
408
|
+
}
|
|
409
|
+
var memoized = function() {
|
|
410
|
+
var args = arguments, key = resolver ? resolver.apply(this, args) : args[0], cache = memoized.cache;
|
|
411
|
+
if (cache.has(key)) {
|
|
412
|
+
return cache.get(key);
|
|
413
|
+
}
|
|
414
|
+
var result = func.apply(this, args);
|
|
415
|
+
memoized.cache = cache.set(key, result) || cache;
|
|
416
|
+
return result;
|
|
417
|
+
};
|
|
418
|
+
memoized.cache = new (memoize.Cache || MapCache_default)();
|
|
419
|
+
return memoized;
|
|
420
|
+
}
|
|
421
|
+
memoize.Cache = MapCache_default;
|
|
422
|
+
var memoize_default = memoize;
|
|
423
|
+
|
|
424
|
+
// ../../node_modules/lodash-es/_memoizeCapped.js
|
|
425
|
+
var MAX_MEMOIZE_SIZE = 500;
|
|
426
|
+
function memoizeCapped(func) {
|
|
427
|
+
var result = memoize_default(func, function(key) {
|
|
428
|
+
if (cache.size === MAX_MEMOIZE_SIZE) {
|
|
429
|
+
cache.clear();
|
|
430
|
+
}
|
|
431
|
+
return key;
|
|
432
|
+
});
|
|
433
|
+
var cache = result.cache;
|
|
434
|
+
return result;
|
|
435
|
+
}
|
|
436
|
+
var memoizeCapped_default = memoizeCapped;
|
|
437
|
+
|
|
438
|
+
// ../../node_modules/lodash-es/_stringToPath.js
|
|
439
|
+
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
|
440
|
+
var reEscapeChar = /\\(\\)?/g;
|
|
441
|
+
var stringToPath = memoizeCapped_default(function(string) {
|
|
442
|
+
var result = [];
|
|
443
|
+
if (string.charCodeAt(0) === 46) {
|
|
444
|
+
result.push("");
|
|
445
|
+
}
|
|
446
|
+
string.replace(rePropName, function(match, number, quote, subString) {
|
|
447
|
+
result.push(quote ? subString.replace(reEscapeChar, "$1") : number || match);
|
|
448
|
+
});
|
|
449
|
+
return result;
|
|
450
|
+
});
|
|
451
|
+
var stringToPath_default = stringToPath;
|
|
452
|
+
|
|
453
|
+
// ../../node_modules/lodash-es/_arrayMap.js
|
|
454
|
+
function arrayMap(array, iteratee) {
|
|
455
|
+
var index = -1, length = array == null ? 0 : array.length, result = Array(length);
|
|
456
|
+
while (++index < length) {
|
|
457
|
+
result[index] = iteratee(array[index], index, array);
|
|
458
|
+
}
|
|
459
|
+
return result;
|
|
460
|
+
}
|
|
461
|
+
var arrayMap_default = arrayMap;
|
|
462
|
+
|
|
463
|
+
// ../../node_modules/lodash-es/_baseToString.js
|
|
464
|
+
var INFINITY = 1 / 0;
|
|
465
|
+
var symbolProto = Symbol_default ? Symbol_default.prototype : void 0;
|
|
466
|
+
var symbolToString = symbolProto ? symbolProto.toString : void 0;
|
|
467
|
+
function baseToString(value) {
|
|
468
|
+
if (typeof value == "string") {
|
|
469
|
+
return value;
|
|
470
|
+
}
|
|
471
|
+
if (isArray_default(value)) {
|
|
472
|
+
return arrayMap_default(value, baseToString) + "";
|
|
473
|
+
}
|
|
474
|
+
if (isSymbol_default(value)) {
|
|
475
|
+
return symbolToString ? symbolToString.call(value) : "";
|
|
476
|
+
}
|
|
477
|
+
var result = value + "";
|
|
478
|
+
return result == "0" && 1 / value == -INFINITY ? "-0" : result;
|
|
479
|
+
}
|
|
480
|
+
var baseToString_default = baseToString;
|
|
481
|
+
|
|
482
|
+
// ../../node_modules/lodash-es/toString.js
|
|
483
|
+
function toString(value) {
|
|
484
|
+
return value == null ? "" : baseToString_default(value);
|
|
485
|
+
}
|
|
486
|
+
var toString_default = toString;
|
|
487
|
+
|
|
488
|
+
// ../../node_modules/lodash-es/_castPath.js
|
|
489
|
+
function castPath(value, object) {
|
|
490
|
+
if (isArray_default(value)) {
|
|
491
|
+
return value;
|
|
492
|
+
}
|
|
493
|
+
return isKey_default(value, object) ? [value] : stringToPath_default(toString_default(value));
|
|
494
|
+
}
|
|
495
|
+
var castPath_default = castPath;
|
|
496
|
+
|
|
497
|
+
// ../../node_modules/lodash-es/_toKey.js
|
|
498
|
+
var INFINITY2 = 1 / 0;
|
|
499
|
+
function toKey(value) {
|
|
500
|
+
if (typeof value == "string" || isSymbol_default(value)) {
|
|
501
|
+
return value;
|
|
502
|
+
}
|
|
503
|
+
var result = value + "";
|
|
504
|
+
return result == "0" && 1 / value == -INFINITY2 ? "-0" : result;
|
|
505
|
+
}
|
|
506
|
+
var toKey_default = toKey;
|
|
507
|
+
|
|
508
|
+
// ../../node_modules/lodash-es/_baseGet.js
|
|
509
|
+
function baseGet(object, path) {
|
|
510
|
+
path = castPath_default(path, object);
|
|
511
|
+
var index = 0, length = path.length;
|
|
512
|
+
while (object != null && index < length) {
|
|
513
|
+
object = object[toKey_default(path[index++])];
|
|
514
|
+
}
|
|
515
|
+
return index && index == length ? object : void 0;
|
|
516
|
+
}
|
|
517
|
+
var baseGet_default = baseGet;
|
|
518
|
+
|
|
519
|
+
// ../../node_modules/lodash-es/get.js
|
|
520
|
+
function get(object, path, defaultValue) {
|
|
521
|
+
var result = object == null ? void 0 : baseGet_default(object, path);
|
|
522
|
+
return result === void 0 ? defaultValue : result;
|
|
523
|
+
}
|
|
524
|
+
var get_default = get;
|
|
525
|
+
|
|
526
|
+
// ../../node_modules/lodash-es/_overArg.js
|
|
527
|
+
function overArg(func, transform) {
|
|
528
|
+
return function(arg) {
|
|
529
|
+
return func(transform(arg));
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
var overArg_default = overArg;
|
|
533
|
+
|
|
534
|
+
// ../../node_modules/lodash-es/_getPrototype.js
|
|
535
|
+
var getPrototype = overArg_default(Object.getPrototypeOf, Object);
|
|
536
|
+
var getPrototype_default = getPrototype;
|
|
537
|
+
|
|
538
|
+
// ../../node_modules/lodash-es/isPlainObject.js
|
|
539
|
+
var objectTag = "[object Object]";
|
|
540
|
+
var funcProto3 = Function.prototype;
|
|
541
|
+
var objectProto6 = Object.prototype;
|
|
542
|
+
var funcToString3 = funcProto3.toString;
|
|
543
|
+
var hasOwnProperty5 = objectProto6.hasOwnProperty;
|
|
544
|
+
var objectCtorString = funcToString3.call(Object);
|
|
545
|
+
function isPlainObject(value) {
|
|
546
|
+
if (!isObjectLike_default(value) || baseGetTag_default(value) != objectTag) {
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
var proto = getPrototype_default(value);
|
|
550
|
+
if (proto === null) {
|
|
551
|
+
return true;
|
|
552
|
+
}
|
|
553
|
+
var Ctor = hasOwnProperty5.call(proto, "constructor") && proto.constructor;
|
|
554
|
+
return typeof Ctor == "function" && Ctor instanceof Ctor && funcToString3.call(Ctor) == objectCtorString;
|
|
555
|
+
}
|
|
556
|
+
var isPlainObject_default = isPlainObject;
|
|
557
|
+
|
|
558
|
+
// ../../node_modules/lodash-es/last.js
|
|
559
|
+
function last(array) {
|
|
560
|
+
var length = array == null ? 0 : array.length;
|
|
561
|
+
return length ? array[length - 1] : void 0;
|
|
562
|
+
}
|
|
563
|
+
var last_default = last;
|
|
564
|
+
|
|
565
|
+
// src/pointer.ts
|
|
566
|
+
var pointerMetaWeakMap = /* @__PURE__ */ new WeakMap();
|
|
567
|
+
var cachedSubPathPointersWeakMap = /* @__PURE__ */ new WeakMap();
|
|
568
|
+
var pointerMetaSymbol = Symbol("pointerMeta");
|
|
569
|
+
var proxyHandler = {
|
|
570
|
+
get(pointerKey, prop) {
|
|
571
|
+
if (prop === pointerMetaSymbol)
|
|
572
|
+
return pointerMetaWeakMap.get(pointerKey);
|
|
573
|
+
let subPathPointers = cachedSubPathPointersWeakMap.get(pointerKey);
|
|
574
|
+
if (!subPathPointers) {
|
|
575
|
+
subPathPointers = /* @__PURE__ */ new Map();
|
|
576
|
+
cachedSubPathPointersWeakMap.set(pointerKey, subPathPointers);
|
|
577
|
+
}
|
|
578
|
+
const existing = subPathPointers.get(prop);
|
|
579
|
+
if (existing !== void 0)
|
|
580
|
+
return existing;
|
|
581
|
+
const meta = pointerMetaWeakMap.get(pointerKey);
|
|
582
|
+
const subPointer = pointer({ root: meta.root, path: [...meta.path, prop] });
|
|
583
|
+
subPathPointers.set(prop, subPointer);
|
|
584
|
+
return subPointer;
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
var getPointerMeta = (p) => {
|
|
588
|
+
const meta = p[pointerMetaSymbol];
|
|
589
|
+
return meta;
|
|
590
|
+
};
|
|
591
|
+
var getPointerParts = (p) => {
|
|
592
|
+
const { root: root2, path } = getPointerMeta(p);
|
|
593
|
+
return { root: root2, path };
|
|
594
|
+
};
|
|
595
|
+
function pointer(args) {
|
|
596
|
+
const meta = {
|
|
597
|
+
root: args.root,
|
|
598
|
+
path: args.path ?? []
|
|
599
|
+
};
|
|
600
|
+
const pointerKey = {};
|
|
601
|
+
pointerMetaWeakMap.set(pointerKey, meta);
|
|
602
|
+
return new Proxy(pointerKey, proxyHandler);
|
|
603
|
+
}
|
|
604
|
+
var pointer_default = pointer;
|
|
605
|
+
var isPointer = (p) => {
|
|
606
|
+
return p && !!getPointerMeta(p);
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
// src/utils/updateDeep.ts
|
|
610
|
+
function updateDeep(state2, path, reducer) {
|
|
611
|
+
if (path.length === 0)
|
|
612
|
+
return reducer(state2);
|
|
613
|
+
return hoop(state2, path, reducer);
|
|
614
|
+
}
|
|
615
|
+
var hoop = (s, path, reducer) => {
|
|
616
|
+
if (path.length === 0) {
|
|
617
|
+
return reducer(s);
|
|
618
|
+
}
|
|
619
|
+
if (Array.isArray(s)) {
|
|
620
|
+
let [index, ...restOfPath] = path;
|
|
621
|
+
index = parseInt(String(index), 10);
|
|
622
|
+
if (isNaN(index))
|
|
623
|
+
index = 0;
|
|
624
|
+
const oldVal = s[index];
|
|
625
|
+
const newVal = hoop(oldVal, restOfPath, reducer);
|
|
626
|
+
if (oldVal === newVal)
|
|
627
|
+
return s;
|
|
628
|
+
const newS = [...s];
|
|
629
|
+
newS.splice(index, 1, newVal);
|
|
630
|
+
return newS;
|
|
631
|
+
} else if (typeof s === "object" && s !== null) {
|
|
632
|
+
const [key, ...restOfPath] = path;
|
|
633
|
+
const oldVal = s[key];
|
|
634
|
+
const newVal = hoop(oldVal, restOfPath, reducer);
|
|
635
|
+
if (oldVal === newVal)
|
|
636
|
+
return s;
|
|
637
|
+
const newS = { ...s, [key]: newVal };
|
|
638
|
+
return newS;
|
|
639
|
+
} else {
|
|
640
|
+
const [key, ...restOfPath] = path;
|
|
641
|
+
return { [key]: hoop(void 0, restOfPath, reducer) };
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
// src/utils/Stack.ts
|
|
646
|
+
var Stack = class {
|
|
647
|
+
constructor() {
|
|
648
|
+
this._head = void 0;
|
|
649
|
+
}
|
|
650
|
+
peek() {
|
|
651
|
+
return this._head && this._head.data;
|
|
652
|
+
}
|
|
653
|
+
pop() {
|
|
654
|
+
const head = this._head;
|
|
655
|
+
if (!head) {
|
|
656
|
+
return void 0;
|
|
657
|
+
}
|
|
658
|
+
this._head = head.next;
|
|
659
|
+
return head.data;
|
|
660
|
+
}
|
|
661
|
+
push(data) {
|
|
662
|
+
const node = { next: this._head, data };
|
|
663
|
+
this._head = node;
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
// src/prism/Interface.ts
|
|
668
|
+
function isPrism(d) {
|
|
669
|
+
return !!(d && d.isPrism && d.isPrism === true);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// src/prism/discoveryMechanism.ts
|
|
673
|
+
function createMechanism() {
|
|
674
|
+
const noop = () => {
|
|
675
|
+
};
|
|
676
|
+
const stack = new Stack();
|
|
677
|
+
const noopCollector = noop;
|
|
678
|
+
const pushCollector2 = (collector) => {
|
|
679
|
+
stack.push(collector);
|
|
680
|
+
};
|
|
681
|
+
const popCollector2 = (collector) => {
|
|
682
|
+
const existing = stack.peek();
|
|
683
|
+
if (existing !== collector) {
|
|
684
|
+
throw new Error(`Popped collector is not on top of the stack`);
|
|
685
|
+
}
|
|
686
|
+
stack.pop();
|
|
687
|
+
};
|
|
688
|
+
const startIgnoringDependencies2 = () => {
|
|
689
|
+
stack.push(noopCollector);
|
|
690
|
+
};
|
|
691
|
+
const stopIgnoringDependencies2 = () => {
|
|
692
|
+
if (stack.peek() !== noopCollector) {
|
|
693
|
+
if (process.env.NODE_ENV === "development") {
|
|
694
|
+
console.warn("This should never happen");
|
|
695
|
+
}
|
|
696
|
+
} else {
|
|
697
|
+
stack.pop();
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
const reportResolutionStart2 = (d) => {
|
|
701
|
+
const possibleCollector = stack.peek();
|
|
702
|
+
if (possibleCollector) {
|
|
703
|
+
possibleCollector(d);
|
|
704
|
+
}
|
|
705
|
+
stack.push(noopCollector);
|
|
706
|
+
};
|
|
707
|
+
const reportResolutionEnd2 = (_d) => {
|
|
708
|
+
stack.pop();
|
|
709
|
+
};
|
|
710
|
+
return {
|
|
711
|
+
type: "Dataverse_discoveryMechanism",
|
|
712
|
+
startIgnoringDependencies: startIgnoringDependencies2,
|
|
713
|
+
stopIgnoringDependencies: stopIgnoringDependencies2,
|
|
714
|
+
reportResolutionStart: reportResolutionStart2,
|
|
715
|
+
reportResolutionEnd: reportResolutionEnd2,
|
|
716
|
+
pushCollector: pushCollector2,
|
|
717
|
+
popCollector: popCollector2
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
function getSharedMechanism() {
|
|
721
|
+
const varName = "__dataverse_discoveryMechanism_sharedStack";
|
|
722
|
+
const root2 = typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {};
|
|
723
|
+
if (root2) {
|
|
724
|
+
const existingMechanism = (
|
|
725
|
+
// @ts-ignore ignore
|
|
726
|
+
root2[varName]
|
|
727
|
+
);
|
|
728
|
+
if (existingMechanism && typeof existingMechanism === "object" && existingMechanism.type === "Dataverse_discoveryMechanism") {
|
|
729
|
+
return existingMechanism;
|
|
730
|
+
} else {
|
|
731
|
+
const mechanism = createMechanism();
|
|
732
|
+
root2[varName] = mechanism;
|
|
733
|
+
return mechanism;
|
|
734
|
+
}
|
|
735
|
+
} else {
|
|
736
|
+
return createMechanism();
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
var {
|
|
740
|
+
startIgnoringDependencies,
|
|
741
|
+
stopIgnoringDependencies,
|
|
742
|
+
reportResolutionEnd,
|
|
743
|
+
reportResolutionStart,
|
|
744
|
+
pushCollector,
|
|
745
|
+
popCollector
|
|
746
|
+
} = getSharedMechanism();
|
|
747
|
+
|
|
748
|
+
// src/prism/prism.ts
|
|
749
|
+
var voidFn = () => {
|
|
750
|
+
};
|
|
751
|
+
var HotHandle = class {
|
|
752
|
+
constructor(_fn, _prismInstance) {
|
|
753
|
+
this._fn = _fn;
|
|
754
|
+
this._prismInstance = _prismInstance;
|
|
755
|
+
this._didMarkDependentsAsStale = false;
|
|
756
|
+
this._isFresh = false;
|
|
757
|
+
this._cacheOfDendencyValues = /* @__PURE__ */ new Map();
|
|
758
|
+
/**
|
|
759
|
+
* @internal
|
|
760
|
+
*/
|
|
761
|
+
this._dependents = /* @__PURE__ */ new Set();
|
|
762
|
+
/**
|
|
763
|
+
* @internal
|
|
764
|
+
*/
|
|
765
|
+
this._dependencies = /* @__PURE__ */ new Set();
|
|
766
|
+
this._possiblyStaleDeps = /* @__PURE__ */ new Set();
|
|
767
|
+
this._scope = new HotScope(
|
|
768
|
+
this
|
|
769
|
+
);
|
|
770
|
+
/**
|
|
771
|
+
* @internal
|
|
772
|
+
*/
|
|
773
|
+
this._lastValue = void 0;
|
|
774
|
+
/**
|
|
775
|
+
* If true, the prism is stale even though its dependencies aren't
|
|
776
|
+
* marked as such. This is used by `prism.source()` and `prism.state()`
|
|
777
|
+
* to mark the prism as stale.
|
|
778
|
+
*/
|
|
779
|
+
this._forciblySetToStale = false;
|
|
780
|
+
this._reactToDependencyGoingStale = (which) => {
|
|
781
|
+
this._possiblyStaleDeps.add(which);
|
|
782
|
+
this._markAsStale();
|
|
783
|
+
};
|
|
784
|
+
for (const d of this._dependencies) {
|
|
785
|
+
d._addDependent(this._reactToDependencyGoingStale);
|
|
786
|
+
}
|
|
787
|
+
startIgnoringDependencies();
|
|
788
|
+
this.getValue();
|
|
789
|
+
stopIgnoringDependencies();
|
|
790
|
+
}
|
|
791
|
+
get hasDependents() {
|
|
792
|
+
return this._dependents.size > 0;
|
|
793
|
+
}
|
|
794
|
+
removeDependent(d) {
|
|
795
|
+
this._dependents.delete(d);
|
|
796
|
+
}
|
|
797
|
+
addDependent(d) {
|
|
798
|
+
this._dependents.add(d);
|
|
799
|
+
}
|
|
800
|
+
destroy() {
|
|
801
|
+
for (const d of this._dependencies) {
|
|
802
|
+
d._removeDependent(this._reactToDependencyGoingStale);
|
|
803
|
+
}
|
|
804
|
+
cleanupScopeStack(this._scope);
|
|
805
|
+
}
|
|
806
|
+
getValue() {
|
|
807
|
+
if (!this._isFresh) {
|
|
808
|
+
const newValue = this._recalculate();
|
|
809
|
+
this._lastValue = newValue;
|
|
810
|
+
this._isFresh = true;
|
|
811
|
+
this._didMarkDependentsAsStale = false;
|
|
812
|
+
this._forciblySetToStale = false;
|
|
813
|
+
}
|
|
814
|
+
return this._lastValue;
|
|
815
|
+
}
|
|
816
|
+
_recalculate() {
|
|
817
|
+
let value;
|
|
818
|
+
if (!this._forciblySetToStale) {
|
|
819
|
+
if (this._possiblyStaleDeps.size > 0) {
|
|
820
|
+
let anActuallyStaleDepWasFound = false;
|
|
821
|
+
startIgnoringDependencies();
|
|
822
|
+
for (const dep of this._possiblyStaleDeps) {
|
|
823
|
+
if (this._cacheOfDendencyValues.get(dep) !== dep.getValue()) {
|
|
824
|
+
anActuallyStaleDepWasFound = true;
|
|
825
|
+
break;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
stopIgnoringDependencies();
|
|
829
|
+
this._possiblyStaleDeps.clear();
|
|
830
|
+
if (!anActuallyStaleDepWasFound) {
|
|
831
|
+
return this._lastValue;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
const newDeps = /* @__PURE__ */ new Set();
|
|
836
|
+
this._cacheOfDendencyValues.clear();
|
|
837
|
+
const collector = (observedDep) => {
|
|
838
|
+
newDeps.add(observedDep);
|
|
839
|
+
this._addDependency(observedDep);
|
|
840
|
+
};
|
|
841
|
+
pushCollector(collector);
|
|
842
|
+
hookScopeStack.push(this._scope);
|
|
843
|
+
try {
|
|
844
|
+
value = this._fn();
|
|
845
|
+
} catch (error) {
|
|
846
|
+
console.error(error);
|
|
847
|
+
} finally {
|
|
848
|
+
const topOfTheStack = hookScopeStack.pop();
|
|
849
|
+
if (topOfTheStack !== this._scope) {
|
|
850
|
+
console.warn(
|
|
851
|
+
// @todo guide the user to report the bug in an issue
|
|
852
|
+
`The Prism hook stack has slipped. This is a bug.`
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
popCollector(collector);
|
|
857
|
+
for (const dep of this._dependencies) {
|
|
858
|
+
if (!newDeps.has(dep)) {
|
|
859
|
+
this._removeDependency(dep);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
this._dependencies = newDeps;
|
|
863
|
+
startIgnoringDependencies();
|
|
864
|
+
for (const dep of newDeps) {
|
|
865
|
+
this._cacheOfDendencyValues.set(dep, dep.getValue());
|
|
866
|
+
}
|
|
867
|
+
stopIgnoringDependencies();
|
|
868
|
+
return value;
|
|
869
|
+
}
|
|
870
|
+
forceStale() {
|
|
871
|
+
this._forciblySetToStale = true;
|
|
872
|
+
this._markAsStale();
|
|
873
|
+
}
|
|
874
|
+
_markAsStale() {
|
|
875
|
+
if (this._didMarkDependentsAsStale)
|
|
876
|
+
return;
|
|
877
|
+
this._didMarkDependentsAsStale = true;
|
|
878
|
+
this._isFresh = false;
|
|
879
|
+
for (const dependent of this._dependents) {
|
|
880
|
+
dependent(this._prismInstance);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* @internal
|
|
885
|
+
*/
|
|
886
|
+
_addDependency(d) {
|
|
887
|
+
if (this._dependencies.has(d))
|
|
888
|
+
return;
|
|
889
|
+
this._dependencies.add(d);
|
|
890
|
+
d._addDependent(this._reactToDependencyGoingStale);
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* @internal
|
|
894
|
+
*/
|
|
895
|
+
_removeDependency(d) {
|
|
896
|
+
if (!this._dependencies.has(d))
|
|
897
|
+
return;
|
|
898
|
+
this._dependencies.delete(d);
|
|
899
|
+
d._removeDependent(this._reactToDependencyGoingStale);
|
|
900
|
+
}
|
|
901
|
+
};
|
|
902
|
+
var emptyObject = {};
|
|
903
|
+
var PrismInstance = class {
|
|
904
|
+
constructor(_fn) {
|
|
905
|
+
this._fn = _fn;
|
|
906
|
+
/**
|
|
907
|
+
* Whether the object is a prism.
|
|
908
|
+
*/
|
|
909
|
+
this.isPrism = true;
|
|
910
|
+
this._state = {
|
|
911
|
+
hot: false,
|
|
912
|
+
handle: void 0
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Whether the prism is hot.
|
|
917
|
+
*/
|
|
918
|
+
get isHot() {
|
|
919
|
+
return this._state.hot;
|
|
920
|
+
}
|
|
921
|
+
onChange(ticker, listener, immediate = false) {
|
|
922
|
+
const dependent = () => {
|
|
923
|
+
ticker.onThisOrNextTick(refresh);
|
|
924
|
+
};
|
|
925
|
+
let lastValue = (
|
|
926
|
+
// use an empty object as the initial value so that the listener is called on the first tick.
|
|
927
|
+
// if we were to use, say, undefined, and this.getValue() also returned undefined, the listener
|
|
928
|
+
// would never be called.
|
|
929
|
+
emptyObject
|
|
930
|
+
);
|
|
931
|
+
const refresh = () => {
|
|
932
|
+
const newValue = this.getValue();
|
|
933
|
+
if (newValue === lastValue)
|
|
934
|
+
return;
|
|
935
|
+
lastValue = newValue;
|
|
936
|
+
listener(newValue);
|
|
937
|
+
};
|
|
938
|
+
this._addDependent(dependent);
|
|
939
|
+
if (immediate) {
|
|
940
|
+
lastValue = this.getValue();
|
|
941
|
+
listener(lastValue);
|
|
942
|
+
}
|
|
943
|
+
const unsubscribe = () => {
|
|
944
|
+
this._removeDependent(dependent);
|
|
945
|
+
ticker.offThisOrNextTick(refresh);
|
|
946
|
+
ticker.offNextTick(refresh);
|
|
947
|
+
};
|
|
948
|
+
return unsubscribe;
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Calls `callback` every time the prism's state goes from `fresh-\>stale.` Returns an `unsubscribe()` function.
|
|
952
|
+
*/
|
|
953
|
+
onStale(callback) {
|
|
954
|
+
const untap = () => {
|
|
955
|
+
this._removeDependent(fn);
|
|
956
|
+
};
|
|
957
|
+
const fn = () => callback();
|
|
958
|
+
this._addDependent(fn);
|
|
959
|
+
return untap;
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Keep the prism hot, even if there are no tappers (subscribers).
|
|
963
|
+
*/
|
|
964
|
+
keepHot() {
|
|
965
|
+
return this.onStale(() => {
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Add a prism as a dependent of this prism.
|
|
970
|
+
*
|
|
971
|
+
* @param d - The prism to be made a dependent of this prism.
|
|
972
|
+
*
|
|
973
|
+
* @see _removeDependent
|
|
974
|
+
*/
|
|
975
|
+
_addDependent(d) {
|
|
976
|
+
if (!this._state.hot) {
|
|
977
|
+
this._goHot();
|
|
978
|
+
}
|
|
979
|
+
this._state.handle.addDependent(d);
|
|
980
|
+
}
|
|
981
|
+
_goHot() {
|
|
982
|
+
const hotHandle = new HotHandle(this._fn, this);
|
|
983
|
+
this._state = {
|
|
984
|
+
hot: true,
|
|
985
|
+
handle: hotHandle
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Remove a prism as a dependent of this prism.
|
|
990
|
+
*
|
|
991
|
+
* @param d - The prism to be removed from as a dependent of this prism.
|
|
992
|
+
*
|
|
993
|
+
* @see _addDependent
|
|
994
|
+
*/
|
|
995
|
+
_removeDependent(d) {
|
|
996
|
+
const state2 = this._state;
|
|
997
|
+
if (!state2.hot) {
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
const handle = state2.handle;
|
|
1001
|
+
handle.removeDependent(d);
|
|
1002
|
+
if (!handle.hasDependents) {
|
|
1003
|
+
this._state = { hot: false, handle: void 0 };
|
|
1004
|
+
handle.destroy();
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Gets the current value of the prism. If the value is stale, it causes the prism to freshen.
|
|
1009
|
+
*/
|
|
1010
|
+
getValue() {
|
|
1011
|
+
reportResolutionStart(this);
|
|
1012
|
+
const state2 = this._state;
|
|
1013
|
+
let val2;
|
|
1014
|
+
if (state2.hot) {
|
|
1015
|
+
val2 = state2.handle.getValue();
|
|
1016
|
+
} else {
|
|
1017
|
+
val2 = calculateColdPrism(this._fn);
|
|
1018
|
+
}
|
|
1019
|
+
reportResolutionEnd(this);
|
|
1020
|
+
return val2;
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
var HotScope = class _HotScope {
|
|
1024
|
+
constructor(_hotHandle) {
|
|
1025
|
+
this._hotHandle = _hotHandle;
|
|
1026
|
+
this._refs = /* @__PURE__ */ new Map();
|
|
1027
|
+
this.isPrismScope = true;
|
|
1028
|
+
// NOTE probably not a great idea to eager-allocate all of these objects/maps for every scope,
|
|
1029
|
+
// especially because most wouldn't get used in the majority of cases. However, back when these
|
|
1030
|
+
// were stored on weakmaps, they were uncomfortable to inspect in the debugger.
|
|
1031
|
+
this.subs = {};
|
|
1032
|
+
this.effects = /* @__PURE__ */ new Map();
|
|
1033
|
+
this.memos = /* @__PURE__ */ new Map();
|
|
1034
|
+
}
|
|
1035
|
+
ref(key, initialValue) {
|
|
1036
|
+
let ref2 = this._refs.get(key);
|
|
1037
|
+
if (ref2 !== void 0) {
|
|
1038
|
+
return ref2;
|
|
1039
|
+
} else {
|
|
1040
|
+
const ref3 = {
|
|
1041
|
+
current: initialValue
|
|
1042
|
+
};
|
|
1043
|
+
this._refs.set(key, ref3);
|
|
1044
|
+
return ref3;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
effect(key, cb, deps) {
|
|
1048
|
+
let effect2 = this.effects.get(key);
|
|
1049
|
+
if (effect2 === void 0) {
|
|
1050
|
+
effect2 = {
|
|
1051
|
+
cleanup: voidFn,
|
|
1052
|
+
deps: void 0
|
|
1053
|
+
};
|
|
1054
|
+
this.effects.set(key, effect2);
|
|
1055
|
+
}
|
|
1056
|
+
if (depsHaveChanged(effect2.deps, deps)) {
|
|
1057
|
+
effect2.cleanup();
|
|
1058
|
+
startIgnoringDependencies();
|
|
1059
|
+
effect2.cleanup = safelyRun(cb, voidFn).value;
|
|
1060
|
+
stopIgnoringDependencies();
|
|
1061
|
+
effect2.deps = deps;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
memo(key, fn, deps) {
|
|
1065
|
+
let memo2 = this.memos.get(key);
|
|
1066
|
+
if (memo2 === void 0) {
|
|
1067
|
+
memo2 = {
|
|
1068
|
+
cachedValue: null,
|
|
1069
|
+
// undefined will always indicate "deps have changed", so we set its initial value as such
|
|
1070
|
+
deps: void 0
|
|
1071
|
+
};
|
|
1072
|
+
this.memos.set(key, memo2);
|
|
1073
|
+
}
|
|
1074
|
+
if (depsHaveChanged(memo2.deps, deps)) {
|
|
1075
|
+
startIgnoringDependencies();
|
|
1076
|
+
memo2.cachedValue = safelyRun(fn, void 0).value;
|
|
1077
|
+
stopIgnoringDependencies();
|
|
1078
|
+
memo2.deps = deps;
|
|
1079
|
+
}
|
|
1080
|
+
return memo2.cachedValue;
|
|
1081
|
+
}
|
|
1082
|
+
state(key, initialValue) {
|
|
1083
|
+
const { value, setValue } = this.memo(
|
|
1084
|
+
"state/" + key,
|
|
1085
|
+
() => {
|
|
1086
|
+
const value2 = { current: initialValue };
|
|
1087
|
+
const setValue2 = (newValue) => {
|
|
1088
|
+
value2.current = newValue;
|
|
1089
|
+
this._hotHandle.forceStale();
|
|
1090
|
+
};
|
|
1091
|
+
return { value: value2, setValue: setValue2 };
|
|
1092
|
+
},
|
|
1093
|
+
[]
|
|
1094
|
+
);
|
|
1095
|
+
return [value.current, setValue];
|
|
1096
|
+
}
|
|
1097
|
+
sub(key) {
|
|
1098
|
+
if (!this.subs[key]) {
|
|
1099
|
+
this.subs[key] = new _HotScope(this._hotHandle);
|
|
1100
|
+
}
|
|
1101
|
+
return this.subs[key];
|
|
1102
|
+
}
|
|
1103
|
+
cleanupEffects() {
|
|
1104
|
+
for (const effect2 of this.effects.values()) {
|
|
1105
|
+
safelyRun(effect2.cleanup, void 0);
|
|
1106
|
+
}
|
|
1107
|
+
this.effects.clear();
|
|
1108
|
+
}
|
|
1109
|
+
source(subscribe, getValue2) {
|
|
1110
|
+
const sourceKey = "$$source/blah";
|
|
1111
|
+
this.effect(
|
|
1112
|
+
sourceKey,
|
|
1113
|
+
() => {
|
|
1114
|
+
const unsub = subscribe(() => {
|
|
1115
|
+
this._hotHandle.forceStale();
|
|
1116
|
+
});
|
|
1117
|
+
return unsub;
|
|
1118
|
+
},
|
|
1119
|
+
[subscribe]
|
|
1120
|
+
);
|
|
1121
|
+
return getValue2();
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1124
|
+
function cleanupScopeStack(scope2) {
|
|
1125
|
+
for (const sub2 of Object.values(scope2.subs)) {
|
|
1126
|
+
cleanupScopeStack(sub2);
|
|
1127
|
+
}
|
|
1128
|
+
scope2.cleanupEffects();
|
|
1129
|
+
}
|
|
1130
|
+
function safelyRun(fn, returnValueInCaseOfError) {
|
|
1131
|
+
try {
|
|
1132
|
+
return { value: fn(), ok: true };
|
|
1133
|
+
} catch (error) {
|
|
1134
|
+
setTimeout(function PrismReportThrow() {
|
|
1135
|
+
throw error;
|
|
1136
|
+
});
|
|
1137
|
+
return { value: returnValueInCaseOfError, ok: false };
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
var hookScopeStack = new Stack();
|
|
1141
|
+
function ref(key, initialValue) {
|
|
1142
|
+
const scope2 = hookScopeStack.peek();
|
|
1143
|
+
if (!scope2) {
|
|
1144
|
+
throw new Error(`prism.ref() is called outside of a prism() call.`);
|
|
1145
|
+
}
|
|
1146
|
+
return scope2.ref(key, initialValue);
|
|
1147
|
+
}
|
|
1148
|
+
function effect(key, cb, deps) {
|
|
1149
|
+
const scope2 = hookScopeStack.peek();
|
|
1150
|
+
if (!scope2) {
|
|
1151
|
+
throw new Error(`prism.effect() is called outside of a prism() call.`);
|
|
1152
|
+
}
|
|
1153
|
+
return scope2.effect(key, cb, deps);
|
|
1154
|
+
}
|
|
1155
|
+
function depsHaveChanged(oldDeps, newDeps) {
|
|
1156
|
+
if (oldDeps === void 0 || newDeps === void 0) {
|
|
1157
|
+
return true;
|
|
1158
|
+
}
|
|
1159
|
+
const len = oldDeps.length;
|
|
1160
|
+
if (len !== newDeps.length)
|
|
1161
|
+
return true;
|
|
1162
|
+
for (let i = 0; i < len; i++) {
|
|
1163
|
+
if (oldDeps[i] !== newDeps[i])
|
|
1164
|
+
return true;
|
|
1165
|
+
}
|
|
1166
|
+
return false;
|
|
1167
|
+
}
|
|
1168
|
+
function memo(key, fn, deps) {
|
|
1169
|
+
const scope2 = hookScopeStack.peek();
|
|
1170
|
+
if (!scope2) {
|
|
1171
|
+
throw new Error(`prism.memo() is called outside of a prism() call.`);
|
|
1172
|
+
}
|
|
1173
|
+
return scope2.memo(key, fn, deps);
|
|
1174
|
+
}
|
|
1175
|
+
function state(key, initialValue) {
|
|
1176
|
+
const scope2 = hookScopeStack.peek();
|
|
1177
|
+
if (!scope2) {
|
|
1178
|
+
throw new Error(`prism.state() is called outside of a prism() call.`);
|
|
1179
|
+
}
|
|
1180
|
+
return scope2.state(key, initialValue);
|
|
1181
|
+
}
|
|
1182
|
+
function ensurePrism() {
|
|
1183
|
+
const scope2 = hookScopeStack.peek();
|
|
1184
|
+
if (!scope2) {
|
|
1185
|
+
throw new Error(`The parent function is called outside of a prism() call.`);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
function scope(key, fn) {
|
|
1189
|
+
const parentScope = hookScopeStack.peek();
|
|
1190
|
+
if (!parentScope) {
|
|
1191
|
+
throw new Error(`prism.scope() is called outside of a prism() call.`);
|
|
1192
|
+
}
|
|
1193
|
+
const subScope = parentScope.sub(key);
|
|
1194
|
+
hookScopeStack.push(subScope);
|
|
1195
|
+
const ret = safelyRun(fn, void 0).value;
|
|
1196
|
+
hookScopeStack.pop();
|
|
1197
|
+
return ret;
|
|
1198
|
+
}
|
|
1199
|
+
function sub(key, fn, deps) {
|
|
1200
|
+
return memo(key, () => prism(fn), deps).getValue();
|
|
1201
|
+
}
|
|
1202
|
+
function inPrism() {
|
|
1203
|
+
return !!hookScopeStack.peek();
|
|
1204
|
+
}
|
|
1205
|
+
function source(subscribe, getValue2) {
|
|
1206
|
+
const scope2 = hookScopeStack.peek();
|
|
1207
|
+
if (!scope2) {
|
|
1208
|
+
throw new Error(`prism.source() is called outside of a prism() call.`);
|
|
1209
|
+
}
|
|
1210
|
+
return scope2.source(subscribe, getValue2);
|
|
1211
|
+
}
|
|
1212
|
+
var prism = (fn) => {
|
|
1213
|
+
return new PrismInstance(fn);
|
|
1214
|
+
};
|
|
1215
|
+
var ColdScope = class _ColdScope {
|
|
1216
|
+
effect(key, cb, deps) {
|
|
1217
|
+
console.warn(`prism.effect() does not run in cold prisms`);
|
|
1218
|
+
}
|
|
1219
|
+
memo(key, fn, deps) {
|
|
1220
|
+
return fn();
|
|
1221
|
+
}
|
|
1222
|
+
state(key, initialValue) {
|
|
1223
|
+
return [initialValue, () => {
|
|
1224
|
+
}];
|
|
1225
|
+
}
|
|
1226
|
+
ref(key, initialValue) {
|
|
1227
|
+
return { current: initialValue };
|
|
1228
|
+
}
|
|
1229
|
+
sub(key) {
|
|
1230
|
+
return new _ColdScope();
|
|
1231
|
+
}
|
|
1232
|
+
source(subscribe, getValue2) {
|
|
1233
|
+
return getValue2();
|
|
1234
|
+
}
|
|
1235
|
+
};
|
|
1236
|
+
function calculateColdPrism(fn) {
|
|
1237
|
+
const scope2 = new ColdScope();
|
|
1238
|
+
hookScopeStack.push(scope2);
|
|
1239
|
+
let value;
|
|
1240
|
+
try {
|
|
1241
|
+
value = fn();
|
|
1242
|
+
} catch (error) {
|
|
1243
|
+
console.error(error);
|
|
1244
|
+
} finally {
|
|
1245
|
+
const topOfTheStack = hookScopeStack.pop();
|
|
1246
|
+
if (topOfTheStack !== scope2) {
|
|
1247
|
+
console.warn(
|
|
1248
|
+
// @todo guide the user to report the bug in an issue
|
|
1249
|
+
`The Prism hook stack has slipped. This is a bug.`
|
|
1250
|
+
);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
return value;
|
|
1254
|
+
}
|
|
1255
|
+
prism.ref = ref;
|
|
1256
|
+
prism.effect = effect;
|
|
1257
|
+
prism.memo = memo;
|
|
1258
|
+
prism.ensurePrism = ensurePrism;
|
|
1259
|
+
prism.state = state;
|
|
1260
|
+
prism.scope = scope;
|
|
1261
|
+
prism.sub = sub;
|
|
1262
|
+
prism.inPrism = inPrism;
|
|
1263
|
+
prism.source = source;
|
|
1264
|
+
var prism_default = prism;
|
|
1265
|
+
|
|
1266
|
+
// src/Atom.ts
|
|
1267
|
+
var getTypeOfValue = (v) => {
|
|
1268
|
+
if (Array.isArray(v))
|
|
1269
|
+
return 1 /* Array */;
|
|
1270
|
+
if (isPlainObject_default(v))
|
|
1271
|
+
return 0 /* Dict */;
|
|
1272
|
+
return 2 /* Other */;
|
|
1273
|
+
};
|
|
1274
|
+
var getKeyOfValue = (v, key, vType = getTypeOfValue(v)) => {
|
|
1275
|
+
if (vType === 0 /* Dict */ && typeof key === "string") {
|
|
1276
|
+
return v[key];
|
|
1277
|
+
} else if (vType === 1 /* Array */ && isValidArrayIndex(key)) {
|
|
1278
|
+
return v[key];
|
|
1279
|
+
} else {
|
|
1280
|
+
return void 0;
|
|
1281
|
+
}
|
|
1282
|
+
};
|
|
1283
|
+
var isValidArrayIndex = (key) => {
|
|
1284
|
+
const inNumber = typeof key === "number" ? key : parseInt(key, 10);
|
|
1285
|
+
return !isNaN(inNumber) && inNumber >= 0 && inNumber < Infinity && (inNumber | 0) === inNumber;
|
|
1286
|
+
};
|
|
1287
|
+
var Scope = class _Scope {
|
|
1288
|
+
constructor(_parent, _path) {
|
|
1289
|
+
this._parent = _parent;
|
|
1290
|
+
this._path = _path;
|
|
1291
|
+
this.children = /* @__PURE__ */ new Map();
|
|
1292
|
+
this.identityChangeListeners = /* @__PURE__ */ new Set();
|
|
1293
|
+
}
|
|
1294
|
+
addIdentityChangeListener(cb) {
|
|
1295
|
+
this.identityChangeListeners.add(cb);
|
|
1296
|
+
}
|
|
1297
|
+
removeIdentityChangeListener(cb) {
|
|
1298
|
+
this.identityChangeListeners.delete(cb);
|
|
1299
|
+
this._checkForGC();
|
|
1300
|
+
}
|
|
1301
|
+
removeChild(key) {
|
|
1302
|
+
this.children.delete(key);
|
|
1303
|
+
this._checkForGC();
|
|
1304
|
+
}
|
|
1305
|
+
getChild(key) {
|
|
1306
|
+
return this.children.get(key);
|
|
1307
|
+
}
|
|
1308
|
+
getOrCreateChild(key) {
|
|
1309
|
+
let child = this.children.get(key);
|
|
1310
|
+
if (!child) {
|
|
1311
|
+
child = child = new _Scope(this, this._path.concat([key]));
|
|
1312
|
+
this.children.set(key, child);
|
|
1313
|
+
}
|
|
1314
|
+
return child;
|
|
1315
|
+
}
|
|
1316
|
+
_checkForGC() {
|
|
1317
|
+
if (this.identityChangeListeners.size > 0)
|
|
1318
|
+
return;
|
|
1319
|
+
if (this.children.size > 0)
|
|
1320
|
+
return;
|
|
1321
|
+
if (this._parent) {
|
|
1322
|
+
this._parent.removeChild(last_default(this._path));
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
var Atom = class {
|
|
1327
|
+
constructor(initialState) {
|
|
1328
|
+
/**
|
|
1329
|
+
* @internal
|
|
1330
|
+
*/
|
|
1331
|
+
this.$$isPointerToPrismProvider = true;
|
|
1332
|
+
/**
|
|
1333
|
+
* Convenience property that gives you a pointer to the root of the atom.
|
|
1334
|
+
*
|
|
1335
|
+
* @remarks
|
|
1336
|
+
* Equivalent to `pointer({ root: thisAtom, path: [] })`.
|
|
1337
|
+
*/
|
|
1338
|
+
this.pointer = pointer_default({ root: this, path: [] });
|
|
1339
|
+
this.prism = this.pointerToPrism(
|
|
1340
|
+
this.pointer
|
|
1341
|
+
);
|
|
1342
|
+
this._onPointerValueChange = (pointer2, cb) => {
|
|
1343
|
+
const { path } = getPointerParts(pointer2);
|
|
1344
|
+
const scope2 = this._getOrCreateScopeForPath(path);
|
|
1345
|
+
scope2.identityChangeListeners.add(cb);
|
|
1346
|
+
const unsubscribe = () => {
|
|
1347
|
+
scope2.identityChangeListeners.delete(cb);
|
|
1348
|
+
};
|
|
1349
|
+
return unsubscribe;
|
|
1350
|
+
};
|
|
1351
|
+
this._currentState = initialState;
|
|
1352
|
+
this._rootScope = new Scope(void 0, []);
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* Sets the state of the atom.
|
|
1356
|
+
*
|
|
1357
|
+
* @param newState - The new state of the atom.
|
|
1358
|
+
*/
|
|
1359
|
+
set(newState) {
|
|
1360
|
+
const oldState = this._currentState;
|
|
1361
|
+
this._currentState = newState;
|
|
1362
|
+
this._checkUpdates(this._rootScope, oldState, newState);
|
|
1363
|
+
}
|
|
1364
|
+
get() {
|
|
1365
|
+
return this._currentState;
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Returns the value at the given pointer
|
|
1369
|
+
*
|
|
1370
|
+
* @param pointerOrFn - A pointer to the desired path. Could also be a function returning a pointer
|
|
1371
|
+
*
|
|
1372
|
+
* Example
|
|
1373
|
+
* ```ts
|
|
1374
|
+
* const atom = atom({ a: { b: 1 } })
|
|
1375
|
+
* atom.getByPointer(atom.pointer.a.b) // 1
|
|
1376
|
+
* atom.getByPointer((p) => p.a.b) // 1
|
|
1377
|
+
* ```
|
|
1378
|
+
*/
|
|
1379
|
+
getByPointer(pointerOrFn) {
|
|
1380
|
+
const pointer2 = isPointer(pointerOrFn) ? pointerOrFn : pointerOrFn(this.pointer);
|
|
1381
|
+
const path = getPointerParts(pointer2).path;
|
|
1382
|
+
return this._getIn(path);
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Gets the state of the atom at `path`.
|
|
1386
|
+
*/
|
|
1387
|
+
_getIn(path) {
|
|
1388
|
+
return path.length === 0 ? this.get() : get_default(this.get(), path);
|
|
1389
|
+
}
|
|
1390
|
+
reduce(fn) {
|
|
1391
|
+
this.set(fn(this.get()));
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Reduces the value at the given pointer
|
|
1395
|
+
*
|
|
1396
|
+
* @param pointerOrFn - A pointer to the desired path. Could also be a function returning a pointer
|
|
1397
|
+
*
|
|
1398
|
+
* Example
|
|
1399
|
+
* ```ts
|
|
1400
|
+
* const atom = atom({ a: { b: 1 } })
|
|
1401
|
+
* atom.reduceByPointer(atom.pointer.a.b, (b) => b + 1) // atom.get().a.b === 2
|
|
1402
|
+
* atom.reduceByPointer((p) => p.a.b, (b) => b + 1) // atom.get().a.b === 2
|
|
1403
|
+
* ```
|
|
1404
|
+
*/
|
|
1405
|
+
reduceByPointer(pointerOrFn, reducer) {
|
|
1406
|
+
const pointer2 = isPointer(pointerOrFn) ? pointerOrFn : pointerOrFn(this.pointer);
|
|
1407
|
+
const path = getPointerParts(pointer2).path;
|
|
1408
|
+
const newState = updateDeep(this.get(), path, reducer);
|
|
1409
|
+
this.set(newState);
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Sets the value at the given pointer
|
|
1413
|
+
*
|
|
1414
|
+
* @param pointerOrFn - A pointer to the desired path. Could also be a function returning a pointer
|
|
1415
|
+
*
|
|
1416
|
+
* Example
|
|
1417
|
+
* ```ts
|
|
1418
|
+
* const atom = atom({ a: { b: 1 } })
|
|
1419
|
+
* atom.setByPointer(atom.pointer.a.b, 2) // atom.get().a.b === 2
|
|
1420
|
+
* atom.setByPointer((p) => p.a.b, 2) // atom.get().a.b === 2
|
|
1421
|
+
* ```
|
|
1422
|
+
*/
|
|
1423
|
+
setByPointer(pointerOrFn, val2) {
|
|
1424
|
+
this.reduceByPointer(pointerOrFn, () => val2);
|
|
1425
|
+
}
|
|
1426
|
+
_checkUpdates(scope2, oldState, newState) {
|
|
1427
|
+
if (oldState === newState)
|
|
1428
|
+
return;
|
|
1429
|
+
for (const cb of scope2.identityChangeListeners) {
|
|
1430
|
+
cb(newState);
|
|
1431
|
+
}
|
|
1432
|
+
if (scope2.children.size === 0)
|
|
1433
|
+
return;
|
|
1434
|
+
const oldValueType = getTypeOfValue(oldState);
|
|
1435
|
+
const newValueType = getTypeOfValue(newState);
|
|
1436
|
+
if (oldValueType === 2 /* Other */ && oldValueType === newValueType)
|
|
1437
|
+
return;
|
|
1438
|
+
for (const [childKey, childScope] of scope2.children) {
|
|
1439
|
+
const oldChildVal = getKeyOfValue(oldState, childKey, oldValueType);
|
|
1440
|
+
const newChildVal = getKeyOfValue(newState, childKey, newValueType);
|
|
1441
|
+
this._checkUpdates(childScope, oldChildVal, newChildVal);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
_getOrCreateScopeForPath(path) {
|
|
1445
|
+
let curScope = this._rootScope;
|
|
1446
|
+
for (const pathEl of path) {
|
|
1447
|
+
curScope = curScope.getOrCreateChild(pathEl);
|
|
1448
|
+
}
|
|
1449
|
+
return curScope;
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* Returns a new prism of the value at the provided path.
|
|
1453
|
+
*
|
|
1454
|
+
* @param pointer - The path to create the prism at.
|
|
1455
|
+
*
|
|
1456
|
+
* ```ts
|
|
1457
|
+
* const pr = atom({ a: { b: 1 } }).pointerToPrism(atom.pointer.a.b)
|
|
1458
|
+
* pr.getValue() // 1
|
|
1459
|
+
* ```
|
|
1460
|
+
*/
|
|
1461
|
+
pointerToPrism(pointer2) {
|
|
1462
|
+
const { path } = getPointerParts(pointer2);
|
|
1463
|
+
const subscribe = (listener) => this._onPointerValueChange(pointer2, listener);
|
|
1464
|
+
const getValue2 = () => this._getIn(path);
|
|
1465
|
+
return prism_default(() => {
|
|
1466
|
+
return prism_default.source(subscribe, getValue2);
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
|
|
1471
|
+
// src/pointerToPrism.ts
|
|
1472
|
+
var identifyPrismWeakMap = /* @__PURE__ */ new WeakMap();
|
|
1473
|
+
function isPointerToPrismProvider(val2) {
|
|
1474
|
+
return typeof val2 === "object" && val2 !== null && val2["$$isPointerToPrismProvider"] === true;
|
|
1475
|
+
}
|
|
1476
|
+
var pointerToPrism = (pointer2) => {
|
|
1477
|
+
const meta = getPointerMeta(pointer2);
|
|
1478
|
+
let prismInstance = identifyPrismWeakMap.get(meta);
|
|
1479
|
+
if (!prismInstance) {
|
|
1480
|
+
const root2 = meta.root;
|
|
1481
|
+
if (!isPointerToPrismProvider(root2)) {
|
|
1482
|
+
throw new Error(
|
|
1483
|
+
`Cannot run pointerToPrism() on a pointer whose root is not an PointerToPrismProvider`
|
|
1484
|
+
);
|
|
1485
|
+
}
|
|
1486
|
+
prismInstance = root2.pointerToPrism(pointer2);
|
|
1487
|
+
identifyPrismWeakMap.set(meta, prismInstance);
|
|
1488
|
+
}
|
|
1489
|
+
return prismInstance;
|
|
1490
|
+
};
|
|
1491
|
+
|
|
1492
|
+
// src/val.ts
|
|
1493
|
+
var val = (input) => {
|
|
1494
|
+
if (isPointer(input)) {
|
|
1495
|
+
return pointerToPrism(input).getValue();
|
|
1496
|
+
} else if (isPrism(input)) {
|
|
1497
|
+
return input.getValue();
|
|
1498
|
+
} else {
|
|
1499
|
+
return input;
|
|
1500
|
+
}
|
|
1501
|
+
};
|
|
1502
|
+
|
|
1503
|
+
// src/prism/iterateAndCountTicks.ts
|
|
1504
|
+
function* iterateAndCountTicks(pointerOrPrism) {
|
|
1505
|
+
let d;
|
|
1506
|
+
if (isPointer(pointerOrPrism)) {
|
|
1507
|
+
d = pointerToPrism(pointerOrPrism);
|
|
1508
|
+
} else if (isPrism(pointerOrPrism)) {
|
|
1509
|
+
d = pointerOrPrism;
|
|
1510
|
+
} else {
|
|
1511
|
+
throw new Error(`Only pointers and prisms are supported`);
|
|
1512
|
+
}
|
|
1513
|
+
let ticksCountedSinceLastYield = 0;
|
|
1514
|
+
const untap = d.onStale(() => {
|
|
1515
|
+
ticksCountedSinceLastYield++;
|
|
1516
|
+
});
|
|
1517
|
+
try {
|
|
1518
|
+
while (true) {
|
|
1519
|
+
const ticks = ticksCountedSinceLastYield;
|
|
1520
|
+
ticksCountedSinceLastYield = 0;
|
|
1521
|
+
yield { value: d.getValue(), ticks };
|
|
1522
|
+
}
|
|
1523
|
+
} finally {
|
|
1524
|
+
untap();
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
// src/Ticker.ts
|
|
1529
|
+
var EMPTY_TICKS_BEFORE_GOING_DORMANT = 60 * 3;
|
|
1530
|
+
var Ticker = class _Ticker {
|
|
1531
|
+
constructor(_conf) {
|
|
1532
|
+
this._conf = _conf;
|
|
1533
|
+
this._ticking = false;
|
|
1534
|
+
/**
|
|
1535
|
+
* Whether the Ticker is dormant
|
|
1536
|
+
*/
|
|
1537
|
+
this._dormant = true;
|
|
1538
|
+
this._numberOfDormantTicks = 0;
|
|
1539
|
+
/**
|
|
1540
|
+
* Counts up for every tick executed.
|
|
1541
|
+
* Internally, this is used to measure ticks per second.
|
|
1542
|
+
*
|
|
1543
|
+
* This is "public" to TypeScript, because it's a tool for performance measurements.
|
|
1544
|
+
* Consider this as experimental, and do not rely on it always being here in future releases.
|
|
1545
|
+
*/
|
|
1546
|
+
this.__ticks = 0;
|
|
1547
|
+
this._scheduledForThisOrNextTick = /* @__PURE__ */ new Set();
|
|
1548
|
+
this._scheduledForNextTick = /* @__PURE__ */ new Set();
|
|
1549
|
+
this._timeAtCurrentTick = 0;
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* Whether the Ticker is dormant
|
|
1553
|
+
*/
|
|
1554
|
+
get dormant() {
|
|
1555
|
+
return this._dormant;
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Registers for fn to be called either on this tick or the next tick.
|
|
1559
|
+
*
|
|
1560
|
+
* If `onThisOrNextTick()` is called while `Ticker.tick()` is running, the
|
|
1561
|
+
* side effect _will_ be called within the running tick. If you don't want this
|
|
1562
|
+
* behavior, you can use `onNextTick()`.
|
|
1563
|
+
*
|
|
1564
|
+
* Note that `fn` will be added to a `Set()`. Which means, if you call `onThisOrNextTick(fn)`
|
|
1565
|
+
* with the same fn twice in a single tick, it'll only run once.
|
|
1566
|
+
*
|
|
1567
|
+
* @param fn - The function to be registered.
|
|
1568
|
+
*
|
|
1569
|
+
* @see offThisOrNextTick
|
|
1570
|
+
*/
|
|
1571
|
+
onThisOrNextTick(fn) {
|
|
1572
|
+
this._scheduledForThisOrNextTick.add(fn);
|
|
1573
|
+
if (this._dormant) {
|
|
1574
|
+
this._goActive();
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
/**
|
|
1578
|
+
* Registers a side effect to be called on the next tick.
|
|
1579
|
+
*
|
|
1580
|
+
* @param fn - The function to be registered.
|
|
1581
|
+
*
|
|
1582
|
+
* @see onThisOrNextTick
|
|
1583
|
+
* @see offNextTick
|
|
1584
|
+
*/
|
|
1585
|
+
onNextTick(fn) {
|
|
1586
|
+
this._scheduledForNextTick.add(fn);
|
|
1587
|
+
if (this._dormant) {
|
|
1588
|
+
this._goActive();
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* De-registers a fn to be called either on this tick or the next tick.
|
|
1593
|
+
*
|
|
1594
|
+
* @param fn - The function to be de-registered.
|
|
1595
|
+
*
|
|
1596
|
+
* @see onThisOrNextTick
|
|
1597
|
+
*/
|
|
1598
|
+
offThisOrNextTick(fn) {
|
|
1599
|
+
this._scheduledForThisOrNextTick.delete(fn);
|
|
1600
|
+
}
|
|
1601
|
+
/**
|
|
1602
|
+
* De-registers a fn to be called on the next tick.
|
|
1603
|
+
*
|
|
1604
|
+
* @param fn - The function to be de-registered.
|
|
1605
|
+
*
|
|
1606
|
+
* @see onNextTick
|
|
1607
|
+
*/
|
|
1608
|
+
offNextTick(fn) {
|
|
1609
|
+
this._scheduledForNextTick.delete(fn);
|
|
1610
|
+
}
|
|
1611
|
+
/**
|
|
1612
|
+
* The time at the start of the current tick if there is a tick in progress, otherwise defaults to
|
|
1613
|
+
* `performance.now()`.
|
|
1614
|
+
*/
|
|
1615
|
+
get time() {
|
|
1616
|
+
if (this._ticking) {
|
|
1617
|
+
return this._timeAtCurrentTick;
|
|
1618
|
+
} else
|
|
1619
|
+
return performance.now();
|
|
1620
|
+
}
|
|
1621
|
+
_goActive() {
|
|
1622
|
+
if (!this._dormant)
|
|
1623
|
+
return;
|
|
1624
|
+
this._dormant = false;
|
|
1625
|
+
this._conf?.onActive?.();
|
|
1626
|
+
}
|
|
1627
|
+
_goDormant() {
|
|
1628
|
+
if (this._dormant)
|
|
1629
|
+
return;
|
|
1630
|
+
this._dormant = true;
|
|
1631
|
+
this._numberOfDormantTicks = 0;
|
|
1632
|
+
this._conf?.onDormant?.();
|
|
1633
|
+
}
|
|
1634
|
+
/**
|
|
1635
|
+
* Triggers a tick which starts executing the callbacks scheduled for this tick.
|
|
1636
|
+
*
|
|
1637
|
+
* @param t - The time at the tick.
|
|
1638
|
+
*
|
|
1639
|
+
* @see onThisOrNextTick
|
|
1640
|
+
* @see onNextTick
|
|
1641
|
+
*/
|
|
1642
|
+
tick(t = performance.now()) {
|
|
1643
|
+
if (process.env.NODE_ENV === "development") {
|
|
1644
|
+
if (!(this instanceof _Ticker)) {
|
|
1645
|
+
throw new Error(
|
|
1646
|
+
'ticker.tick must be called while bound to the ticker. As in, "ticker.tick(time)" or "requestAnimationFrame((t) => ticker.tick(t))" for performance.'
|
|
1647
|
+
);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
this.__ticks++;
|
|
1651
|
+
if (!this._dormant) {
|
|
1652
|
+
if (this._scheduledForNextTick.size === 0 && this._scheduledForThisOrNextTick.size === 0) {
|
|
1653
|
+
this._numberOfDormantTicks++;
|
|
1654
|
+
if (this._numberOfDormantTicks >= EMPTY_TICKS_BEFORE_GOING_DORMANT) {
|
|
1655
|
+
this._goDormant();
|
|
1656
|
+
return;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
this._ticking = true;
|
|
1661
|
+
this._timeAtCurrentTick = t;
|
|
1662
|
+
for (const v of this._scheduledForNextTick) {
|
|
1663
|
+
this._scheduledForThisOrNextTick.add(v);
|
|
1664
|
+
}
|
|
1665
|
+
this._scheduledForNextTick.clear();
|
|
1666
|
+
this._tick(0);
|
|
1667
|
+
this._ticking = false;
|
|
1668
|
+
}
|
|
1669
|
+
_tick(iterationNumber) {
|
|
1670
|
+
const time = this.time;
|
|
1671
|
+
if (iterationNumber > 10) {
|
|
1672
|
+
console.warn("_tick() recursing for 10 times");
|
|
1673
|
+
}
|
|
1674
|
+
if (iterationNumber > 100) {
|
|
1675
|
+
throw new Error(`Maximum recursion limit for _tick()`);
|
|
1676
|
+
}
|
|
1677
|
+
const oldSet = this._scheduledForThisOrNextTick;
|
|
1678
|
+
this._scheduledForThisOrNextTick = /* @__PURE__ */ new Set();
|
|
1679
|
+
for (const fn of oldSet) {
|
|
1680
|
+
fn(time);
|
|
1681
|
+
}
|
|
1682
|
+
if (this._scheduledForThisOrNextTick.size > 0) {
|
|
1683
|
+
return this._tick(iterationNumber + 1);
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
};
|
|
1687
|
+
|
|
1688
|
+
// src/prism/iterateOver.ts
|
|
1689
|
+
function* iterateOver(pointerOrPrism) {
|
|
1690
|
+
let d;
|
|
1691
|
+
if (isPointer(pointerOrPrism)) {
|
|
1692
|
+
d = pointerToPrism(pointerOrPrism);
|
|
1693
|
+
} else if (isPrism(pointerOrPrism)) {
|
|
1694
|
+
d = pointerOrPrism;
|
|
1695
|
+
} else {
|
|
1696
|
+
throw new Error(`Only pointers and prisms are supported`);
|
|
1697
|
+
}
|
|
1698
|
+
const ticker = new Ticker();
|
|
1699
|
+
const untap = d.onChange(ticker, (v) => {
|
|
1700
|
+
});
|
|
1701
|
+
try {
|
|
1702
|
+
while (true) {
|
|
1703
|
+
ticker.tick();
|
|
1704
|
+
yield d.getValue();
|
|
1705
|
+
}
|
|
1706
|
+
} finally {
|
|
1707
|
+
untap();
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
// src/PointerProxy.ts
|
|
1712
|
+
var PointerProxy = class {
|
|
1713
|
+
constructor(currentPointer) {
|
|
1714
|
+
/**
|
|
1715
|
+
* @internal
|
|
1716
|
+
*/
|
|
1717
|
+
this.$$isPointerToPrismProvider = true;
|
|
1718
|
+
this._currentPointerBox = new Atom(currentPointer);
|
|
1719
|
+
this.pointer = pointer_default({ root: this, path: [] });
|
|
1720
|
+
}
|
|
1721
|
+
/**
|
|
1722
|
+
* Sets the underlying pointer.
|
|
1723
|
+
* @param p - The pointer to be proxied.
|
|
1724
|
+
*/
|
|
1725
|
+
setPointer(p) {
|
|
1726
|
+
this._currentPointerBox.set(p);
|
|
1727
|
+
}
|
|
1728
|
+
/**
|
|
1729
|
+
* Returns a prism of the value at the provided sub-path of the proxied pointer.
|
|
1730
|
+
*
|
|
1731
|
+
* @param path - The path to create the prism at.
|
|
1732
|
+
*/
|
|
1733
|
+
pointerToPrism(pointer2) {
|
|
1734
|
+
const { path } = getPointerMeta(pointer2);
|
|
1735
|
+
return prism_default(() => {
|
|
1736
|
+
const currentPointer = this._currentPointerBox.prism.getValue();
|
|
1737
|
+
const subPointer = path.reduce(
|
|
1738
|
+
(pointerSoFar, pathItem) => pointerSoFar[pathItem],
|
|
1739
|
+
currentPointer
|
|
1740
|
+
);
|
|
1741
|
+
return val(subPointer);
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
};
|
|
1745
|
+
export {
|
|
1746
|
+
Atom,
|
|
1747
|
+
PointerProxy,
|
|
1748
|
+
Ticker,
|
|
1749
|
+
getPointerParts,
|
|
1750
|
+
isPointer,
|
|
1751
|
+
isPrism,
|
|
1752
|
+
iterateAndCountTicks,
|
|
1753
|
+
iterateOver,
|
|
1754
|
+
pointer_default as pointer,
|
|
1755
|
+
pointerToPrism,
|
|
1756
|
+
prism_default as prism,
|
|
1757
|
+
val
|
|
1758
|
+
};
|
|
1759
|
+
//# sourceMappingURL=index.mjs.map
|