@lmvz-ds/components 0.13.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/cjs/assets-CJzJZPzV.js +26 -0
  2. package/dist/cjs/{assets-CB5ikzmP.js → icons-FIfJEo6G.js} +1251 -773
  3. package/dist/cjs/index.cjs.js +3 -3
  4. package/dist/cjs/lmvz-card.cjs.entry.js +3 -3
  5. package/dist/cjs/lmvz-icon.cjs.entry.js +3 -3
  6. package/dist/collection/components/lmvz-card/lmvz-card.js +3 -4
  7. package/dist/collection/components/lmvz-icon/icons.js +2 -2
  8. package/dist/collection/utils/assets.js +9 -6
  9. package/dist/collection/utils/http.js +2 -2
  10. package/dist/collection/utils/http.unit.js +1 -1
  11. package/dist/collection/utils/validation/svg.js +1 -1
  12. package/dist/components/index.js +1 -1
  13. package/dist/components/lmvz-card.js +1 -1
  14. package/dist/components/lmvz-header.js +1 -1
  15. package/dist/components/lmvz-icon.js +1 -1
  16. package/dist/components/p-BsS3QvWn.js +1 -0
  17. package/dist/components/p-CdYWDK7m.js +1 -0
  18. package/dist/esm/assets-BelZNJ1W.js +23 -0
  19. package/dist/esm/{assets-ozES4zSA.js → icons-CM7lsnuO.js} +1249 -708
  20. package/dist/esm/index.js +3 -2
  21. package/dist/esm/lmvz-card.entry.js +3 -3
  22. package/dist/esm/lmvz-icon.entry.js +2 -2
  23. package/dist/lmvz-components/index.esm.js +1 -1
  24. package/dist/lmvz-components/lmvz-components.esm.js +1 -1
  25. package/dist/lmvz-components/p-6e3314ab.entry.js +1 -0
  26. package/dist/lmvz-components/p-BoR31cjC.js +1 -0
  27. package/dist/lmvz-components/p-CVf2C8dL.js +1 -0
  28. package/dist/lmvz-components/p-d9dc29a1.entry.js +1 -0
  29. package/dist/manifest.json +1 -1
  30. package/dist/types/utils/assets.d.ts +1 -8
  31. package/dist/types/utils/http.d.ts +3 -3
  32. package/dist/types/utils/validation/svg.d.ts +2 -2
  33. package/hydrate/index.js +2131 -12411
  34. package/hydrate/index.mjs +2131 -12411
  35. package/package.json +4 -4
  36. package/dist/cjs/icons-DM_TTn48.js +0 -857
  37. package/dist/components/p-BBDH9X49.js +0 -1
  38. package/dist/components/p-Bs6_m7Uw.js +0 -1
  39. package/dist/esm/icons-kpJZ1u9g.js +0 -853
  40. package/dist/lmvz-components/p-4ad8c332.entry.js +0 -1
  41. package/dist/lmvz-components/p-5eee0752.entry.js +0 -1
  42. package/dist/lmvz-components/p-D9lc4ayG.js +0 -1
  43. package/dist/lmvz-components/p-iviTjlUy.js +0 -1
@@ -1,853 +0,0 @@
1
- import { g as getOrThrowWith, d as right, e as left, i as identity, f as isRight, h as getRight, m as match, j as deferredUnsafeMake, k as deferredAwait, n as deferredInterrupt, o as deferredDone, p as exitSucceed, q as dual, u as pipeArguments, N as NodeInspectSymbol, v as toJSON, w as format, x as decode, y as map, z as all, A as merge, B as sync, C as size, D as suspend, E as get, F as succeed$1, G as none, H as has, I as isSome, J as some, K as getOrUndefined, L as set, M as struct, O as flatMap, P as remove$1, Q as empty$1, R as clockWith, S as compareAndSet, T as set$1, U as make$3, V as symbol, W as pipe, X as cached, Y as combine, Z as hash, _ as symbol$1, $ as hasProperty, a0 as equals, a1 as asVoid, a2 as when, a3 as toMillis, a4 as onInterrupt, a5 as zipRight, a6 as exit, a7 as provideContext, a8 as context, a9 as fiberId, aa as TaggedError, ab as gen, ac as tryPromise, ad as try_, ae as infinity, s as syncCreateAssetUrlSafely, af as logWarning } from './assets-ozES4zSA.js';
2
-
3
- /**
4
- * This module provides types and utility functions to create and work with branded types,
5
- * which are TypeScript types with an added type tag to prevent accidental usage of a value in the wrong context.
6
- *
7
- * The `refined` and `nominal` functions are both used to create branded types in TypeScript.
8
- * The main difference between them is that `refined` allows for validation of the data, while `nominal` does not.
9
- *
10
- * The `nominal` function is used to create a new branded type that has the same underlying type as the input, but with a different name.
11
- * This is useful when you want to distinguish between two values of the same type that have different meanings.
12
- * The `nominal` function does not perform any validation of the input data.
13
- *
14
- * On the other hand, the `refined` function is used to create a new branded type that has the same underlying type as the input,
15
- * but with a different name, and it also allows for validation of the input data.
16
- * The `refined` function takes a predicate that is used to validate the input data.
17
- * If the input data fails the validation, a `BrandErrors` is returned, which provides information about the specific validation failure.
18
- *
19
- * @since 2.0.0
20
- */
21
- /**
22
- * @since 2.0.0
23
- * @category symbols
24
- */
25
- const RefinedConstructorsTypeId = /*#__PURE__*/Symbol.for("effect/Brand/Refined");
26
- /**
27
- * Returns a `BrandErrors` that contains a single `RefinementError`.
28
- *
29
- * @since 2.0.0
30
- * @category constructors
31
- */
32
- const error = (message, meta) => [{
33
- message,
34
- meta
35
- }];
36
- function refined(...args) {
37
- const either = args.length === 2 ? unbranded => args[0](unbranded) ? right(unbranded) : left(args[1](unbranded)) : unbranded => {
38
- return match(args[0](unbranded), {
39
- onNone: () => right(unbranded),
40
- onSome: left
41
- });
42
- };
43
- return Object.assign(unbranded => getOrThrowWith(either(unbranded), identity), {
44
- [RefinedConstructorsTypeId]: RefinedConstructorsTypeId,
45
- option: args => getRight(either(args)),
46
- either,
47
- is: args => isRight(either(args))
48
- });
49
- }
50
-
51
- const _await = deferredAwait;
52
- /**
53
- * Exits the `Deferred` with the specified `Exit` value, which will be
54
- * propagated to all fibers waiting on the value of the `Deferred`.
55
- *
56
- * @since 2.0.0
57
- * @category utils
58
- */
59
- const done = deferredDone;
60
- /**
61
- * Completes the `Deferred` with interruption. This will interrupt all fibers
62
- * waiting on the value of the `Deferred` with the `FiberId` of the fiber
63
- * calling this method.
64
- *
65
- * @since 2.0.0
66
- * @category utils
67
- */
68
- const interrupt = deferredInterrupt;
69
- /**
70
- * Unsafely creates a new `Deferred` from the specified `FiberId`.
71
- *
72
- * @since 2.0.0
73
- * @category unsafe
74
- */
75
- const unsafeMake = deferredUnsafeMake;
76
-
77
- /**
78
- * Constructs a new `Exit.Success` containing the specified value of type `A`.
79
- *
80
- * @since 2.0.0
81
- * @category constructors
82
- */
83
- const succeed = exitSucceed;
84
-
85
- /**
86
- * @since 2.0.0
87
- */
88
- const TypeId$1 = /*#__PURE__*/Symbol.for("effect/MutableList");
89
- const MutableListProto = {
90
- [TypeId$1]: TypeId$1,
91
- [Symbol.iterator]() {
92
- let done = false;
93
- let head = this.head;
94
- return {
95
- next() {
96
- if (done) {
97
- return this.return();
98
- }
99
- if (head == null) {
100
- done = true;
101
- return this.return();
102
- }
103
- const value = head.value;
104
- head = head.next;
105
- return {
106
- done,
107
- value
108
- };
109
- },
110
- return(value) {
111
- if (!done) {
112
- done = true;
113
- }
114
- return {
115
- done: true,
116
- value
117
- };
118
- }
119
- };
120
- },
121
- toString() {
122
- return format(this.toJSON());
123
- },
124
- toJSON() {
125
- return {
126
- _id: "MutableList",
127
- values: Array.from(this).map(toJSON)
128
- };
129
- },
130
- [NodeInspectSymbol]() {
131
- return this.toJSON();
132
- },
133
- pipe() {
134
- return pipeArguments(this, arguments);
135
- }
136
- };
137
- /** @internal */
138
- const makeNode = value => ({
139
- value,
140
- removed: false,
141
- prev: undefined,
142
- next: undefined
143
- });
144
- /**
145
- * Creates an empty `MutableList`.
146
- *
147
- * @since 2.0.0
148
- * @category constructors
149
- */
150
- const empty = () => {
151
- const list = Object.create(MutableListProto);
152
- list.head = undefined;
153
- list.tail = undefined;
154
- list._length = 0;
155
- return list;
156
- };
157
- /**
158
- * Returns `true` if the list contains zero elements, `false`, otherwise.
159
- *
160
- * @since 2.0.0
161
- * @category getters
162
- */
163
- const isEmpty = self => length(self) === 0;
164
- /**
165
- * Returns the length of the list.
166
- *
167
- * @since 2.0.0
168
- * @category getters
169
- */
170
- const length = self => self._length;
171
- /**
172
- * Appends the specified element to the end of the `MutableList`.
173
- *
174
- * @category concatenating
175
- * @since 2.0.0
176
- */
177
- const append = /*#__PURE__*/dual(2, (self, value) => {
178
- const node = makeNode(value);
179
- if (self.head === undefined) {
180
- self.head = node;
181
- }
182
- if (self.tail === undefined) {
183
- self.tail = node;
184
- } else {
185
- self.tail.next = node;
186
- node.prev = self.tail;
187
- self.tail = node;
188
- }
189
- self._length += 1;
190
- return self;
191
- });
192
- /**
193
- * Removes the first value from the list and returns it, if it exists.
194
- *
195
- * @since 0.0.1
196
- */
197
- const shift = self => {
198
- const head = self.head;
199
- if (head !== undefined) {
200
- remove(self, head);
201
- return head.value;
202
- }
203
- return undefined;
204
- };
205
- const remove = (self, node) => {
206
- if (node.removed) {
207
- return;
208
- }
209
- node.removed = true;
210
- if (node.prev !== undefined && node.next !== undefined) {
211
- node.prev.next = node.next;
212
- node.next.prev = node.prev;
213
- } else if (node.prev !== undefined) {
214
- self.tail = node.prev;
215
- node.prev.next = undefined;
216
- } else if (node.next !== undefined) {
217
- self.head = node.next;
218
- node.next.prev = undefined;
219
- } else {
220
- self.tail = undefined;
221
- self.head = undefined;
222
- }
223
- if (self._length > 0) {
224
- self._length -= 1;
225
- }
226
- };
227
-
228
- /**
229
- * @since 2.0.0
230
- */
231
- const TypeId = /*#__PURE__*/Symbol.for("effect/MutableQueue");
232
- /**
233
- * @since 2.0.0
234
- * @category symbol
235
- */
236
- const EmptyMutableQueue = /*#__PURE__*/Symbol.for("effect/mutable/MutableQueue/Empty");
237
- const MutableQueueProto = {
238
- [TypeId]: TypeId,
239
- [Symbol.iterator]() {
240
- return Array.from(this.queue)[Symbol.iterator]();
241
- },
242
- toString() {
243
- return format(this.toJSON());
244
- },
245
- toJSON() {
246
- return {
247
- _id: "MutableQueue",
248
- values: Array.from(this).map(toJSON)
249
- };
250
- },
251
- [NodeInspectSymbol]() {
252
- return this.toJSON();
253
- },
254
- pipe() {
255
- return pipeArguments(this, arguments);
256
- }
257
- };
258
- const make$2 = capacity => {
259
- const queue = Object.create(MutableQueueProto);
260
- queue.queue = empty();
261
- queue.capacity = capacity;
262
- return queue;
263
- };
264
- /**
265
- * Creates a new unbounded `MutableQueue`.
266
- *
267
- * @since 2.0.0
268
- * @category constructors
269
- */
270
- const unbounded = () => make$2(undefined);
271
- /**
272
- * Offers an element to the queue.
273
- *
274
- * Returns whether the enqueue was successful or not.
275
- *
276
- * @since 2.0.0
277
- */
278
- const offer = /*#__PURE__*/dual(2, (self, value) => {
279
- const queueLength = length(self.queue);
280
- if (self.capacity !== undefined && queueLength === self.capacity) {
281
- return false;
282
- }
283
- append(value)(self.queue);
284
- return true;
285
- });
286
- /**
287
- * Dequeues an element from the queue.
288
- *
289
- * Returns either an element from the queue, or the `def` param.
290
- *
291
- * **Note**: if there is no meaningful default for your type, you can always
292
- * use `poll(MutableQueue.EmptyMutableQueue)`.
293
- *
294
- * @since 2.0.0
295
- */
296
- const poll = /*#__PURE__*/dual(2, (self, def) => {
297
- if (isEmpty(self.queue)) {
298
- return def;
299
- }
300
- return shift(self.queue);
301
- });
302
-
303
- /** @internal */
304
- const complete = (key, exit, entryStats, timeToLiveMillis) => struct({
305
- _tag: "Complete",
306
- key,
307
- exit,
308
- entryStats,
309
- timeToLiveMillis
310
- });
311
- /** @internal */
312
- const pending = (key, deferred) => struct({
313
- _tag: "Pending",
314
- key,
315
- deferred
316
- });
317
- /** @internal */
318
- const refreshing = (deferred, complete) => struct({
319
- _tag: "Refreshing",
320
- deferred,
321
- complete
322
- });
323
- /** @internal */
324
- const MapKeyTypeId = /*#__PURE__*/Symbol.for("effect/Cache/MapKey");
325
- class MapKeyImpl {
326
- current;
327
- [MapKeyTypeId] = MapKeyTypeId;
328
- previous = undefined;
329
- next = undefined;
330
- constructor(current) {
331
- this.current = current;
332
- }
333
- [symbol]() {
334
- return pipe(hash(this.current), combine(hash(this.previous)), combine(hash(this.next)), cached(this));
335
- }
336
- [symbol$1](that) {
337
- if (this === that) {
338
- return true;
339
- }
340
- return isMapKey(that) && equals(this.current, that.current) && equals(this.previous, that.previous) && equals(this.next, that.next);
341
- }
342
- }
343
- /** @internal */
344
- const makeMapKey = current => new MapKeyImpl(current);
345
- /** @internal */
346
- const isMapKey = u => hasProperty(u, MapKeyTypeId);
347
- class KeySetImpl {
348
- head = undefined;
349
- tail = undefined;
350
- add(key) {
351
- if (key !== this.tail) {
352
- if (this.tail === undefined) {
353
- this.head = key;
354
- this.tail = key;
355
- } else {
356
- const previous = key.previous;
357
- const next = key.next;
358
- if (next !== undefined) {
359
- key.next = undefined;
360
- if (previous !== undefined) {
361
- previous.next = next;
362
- next.previous = previous;
363
- } else {
364
- this.head = next;
365
- this.head.previous = undefined;
366
- }
367
- }
368
- this.tail.next = key;
369
- key.previous = this.tail;
370
- this.tail = key;
371
- }
372
- }
373
- }
374
- remove() {
375
- const key = this.head;
376
- if (key !== undefined) {
377
- const next = key.next;
378
- if (next !== undefined) {
379
- key.next = undefined;
380
- this.head = next;
381
- this.head.previous = undefined;
382
- } else {
383
- this.head = undefined;
384
- this.tail = undefined;
385
- }
386
- }
387
- return key;
388
- }
389
- }
390
- /** @internal */
391
- const makeKeySet = () => new KeySetImpl();
392
- /**
393
- * Constructs a new `CacheState` from the specified values.
394
- *
395
- * @internal
396
- */
397
- const makeCacheState = (map, keys, accesses, updating, hits, misses) => ({
398
- map,
399
- keys,
400
- accesses,
401
- updating,
402
- hits,
403
- misses
404
- });
405
- /**
406
- * Constructs an initial cache state.
407
- *
408
- * @internal
409
- */
410
- const initialCacheState = () => makeCacheState(empty$1(), makeKeySet(), unbounded(), make$3(false), 0, 0);
411
- /** @internal */
412
- const CacheSymbolKey = "effect/Cache";
413
- /** @internal */
414
- const CacheTypeId = /*#__PURE__*/Symbol.for(CacheSymbolKey);
415
- const cacheVariance = {
416
- /* c8 ignore next */
417
- _Key: _ => _,
418
- /* c8 ignore next */
419
- _Error: _ => _,
420
- /* c8 ignore next */
421
- _Value: _ => _
422
- };
423
- /** @internal */
424
- const ConsumerCacheSymbolKey = "effect/ConsumerCache";
425
- /** @internal */
426
- const ConsumerCacheTypeId = /*#__PURE__*/Symbol.for(ConsumerCacheSymbolKey);
427
- const consumerCacheVariance = {
428
- /* c8 ignore next */
429
- _Key: _ => _,
430
- /* c8 ignore next */
431
- _Error: _ => _,
432
- /* c8 ignore next */
433
- _Value: _ => _
434
- };
435
- /** @internal */
436
- const makeCacheStats = options => options;
437
- /** @internal */
438
- const makeEntryStats = loadedMillis => ({
439
- loadedMillis
440
- });
441
- class CacheImpl {
442
- capacity;
443
- context;
444
- fiberId;
445
- lookup;
446
- timeToLive;
447
- [CacheTypeId] = cacheVariance;
448
- [ConsumerCacheTypeId] = consumerCacheVariance;
449
- cacheState;
450
- constructor(capacity, context, fiberId, lookup, timeToLive) {
451
- this.capacity = capacity;
452
- this.context = context;
453
- this.fiberId = fiberId;
454
- this.lookup = lookup;
455
- this.timeToLive = timeToLive;
456
- this.cacheState = initialCacheState();
457
- }
458
- get(key) {
459
- return map(this.getEither(key), merge);
460
- }
461
- get cacheStats() {
462
- return sync(() => makeCacheStats({
463
- hits: this.cacheState.hits,
464
- misses: this.cacheState.misses,
465
- size: size(this.cacheState.map)
466
- }));
467
- }
468
- getOption(key) {
469
- return suspend(() => match(get(this.cacheState.map, key), {
470
- onNone: () => {
471
- const mapKey = makeMapKey(key);
472
- this.trackAccess(mapKey);
473
- this.trackMiss();
474
- return succeed$1(none());
475
- },
476
- onSome: value => this.resolveMapValue(value)
477
- }));
478
- }
479
- getOptionComplete(key) {
480
- return suspend(() => match(get(this.cacheState.map, key), {
481
- onNone: () => {
482
- const mapKey = makeMapKey(key);
483
- this.trackAccess(mapKey);
484
- this.trackMiss();
485
- return succeed$1(none());
486
- },
487
- onSome: value => this.resolveMapValue(value, true)
488
- }));
489
- }
490
- contains(key) {
491
- return sync(() => has(this.cacheState.map, key));
492
- }
493
- entryStats(key) {
494
- return sync(() => {
495
- const option = get(this.cacheState.map, key);
496
- if (isSome(option)) {
497
- switch (option.value._tag) {
498
- case "Complete":
499
- {
500
- const loaded = option.value.entryStats.loadedMillis;
501
- return some(makeEntryStats(loaded));
502
- }
503
- case "Pending":
504
- {
505
- return none();
506
- }
507
- case "Refreshing":
508
- {
509
- const loaded = option.value.complete.entryStats.loadedMillis;
510
- return some(makeEntryStats(loaded));
511
- }
512
- }
513
- }
514
- return none();
515
- });
516
- }
517
- getEither(key) {
518
- return suspend(() => {
519
- const k = key;
520
- let mapKey = undefined;
521
- let deferred = undefined;
522
- let value = getOrUndefined(get(this.cacheState.map, k));
523
- if (value === undefined) {
524
- deferred = unsafeMake(this.fiberId);
525
- mapKey = makeMapKey(k);
526
- if (has(this.cacheState.map, k)) {
527
- value = getOrUndefined(get(this.cacheState.map, k));
528
- } else {
529
- set(this.cacheState.map, k, pending(mapKey, deferred));
530
- }
531
- }
532
- if (value === undefined) {
533
- this.trackAccess(mapKey);
534
- this.trackMiss();
535
- return map(this.lookupValueOf(key, deferred), right);
536
- } else {
537
- return flatMap(this.resolveMapValue(value), match({
538
- onNone: () => this.getEither(key),
539
- onSome: value => succeed$1(left(value))
540
- }));
541
- }
542
- });
543
- }
544
- invalidate(key) {
545
- return sync(() => {
546
- remove$1(this.cacheState.map, key);
547
- });
548
- }
549
- invalidateWhen(key, when) {
550
- return sync(() => {
551
- const value = get(this.cacheState.map, key);
552
- if (isSome(value) && value.value._tag === "Complete") {
553
- if (value.value.exit._tag === "Success") {
554
- if (when(value.value.exit.value)) {
555
- remove$1(this.cacheState.map, key);
556
- }
557
- }
558
- }
559
- });
560
- }
561
- get invalidateAll() {
562
- return sync(() => {
563
- this.cacheState.map = empty$1();
564
- });
565
- }
566
- refresh(key) {
567
- return clockWith(clock => suspend(() => {
568
- const k = key;
569
- const deferred = unsafeMake(this.fiberId);
570
- let value = getOrUndefined(get(this.cacheState.map, k));
571
- if (value === undefined) {
572
- if (has(this.cacheState.map, k)) {
573
- value = getOrUndefined(get(this.cacheState.map, k));
574
- } else {
575
- set(this.cacheState.map, k, pending(makeMapKey(k), deferred));
576
- }
577
- }
578
- if (value === undefined) {
579
- return asVoid(this.lookupValueOf(key, deferred));
580
- } else {
581
- switch (value._tag) {
582
- case "Complete":
583
- {
584
- if (this.hasExpired(clock, value.timeToLiveMillis)) {
585
- const found = getOrUndefined(get(this.cacheState.map, k));
586
- if (equals(found, value)) {
587
- remove$1(this.cacheState.map, k);
588
- }
589
- return asVoid(this.get(key));
590
- }
591
- // Only trigger the lookup if we're still the current value, `completedResult`
592
- return pipe(this.lookupValueOf(key, deferred), when(() => {
593
- const current = getOrUndefined(get(this.cacheState.map, k));
594
- if (equals(current, value)) {
595
- const mapValue = refreshing(deferred, value);
596
- set(this.cacheState.map, k, mapValue);
597
- return true;
598
- }
599
- return false;
600
- }), asVoid);
601
- }
602
- case "Pending":
603
- {
604
- return _await(value.deferred);
605
- }
606
- case "Refreshing":
607
- {
608
- return _await(value.deferred);
609
- }
610
- }
611
- }
612
- }));
613
- }
614
- set(key, value) {
615
- return clockWith(clock => sync(() => {
616
- const now = clock.unsafeCurrentTimeMillis();
617
- const k = key;
618
- const lookupResult = succeed(value);
619
- const mapValue = complete(makeMapKey(k), lookupResult, makeEntryStats(now), now + toMillis(decode(this.timeToLive(lookupResult))));
620
- set(this.cacheState.map, k, mapValue);
621
- }));
622
- }
623
- get size() {
624
- return sync(() => {
625
- return size(this.cacheState.map);
626
- });
627
- }
628
- get values() {
629
- return sync(() => {
630
- const values = [];
631
- for (const entry of this.cacheState.map) {
632
- if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") {
633
- values.push(entry[1].exit.value);
634
- }
635
- }
636
- return values;
637
- });
638
- }
639
- get entries() {
640
- return sync(() => {
641
- const values = [];
642
- for (const entry of this.cacheState.map) {
643
- if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") {
644
- values.push([entry[0], entry[1].exit.value]);
645
- }
646
- }
647
- return values;
648
- });
649
- }
650
- get keys() {
651
- return sync(() => {
652
- const keys = [];
653
- for (const entry of this.cacheState.map) {
654
- if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") {
655
- keys.push(entry[0]);
656
- }
657
- }
658
- return keys;
659
- });
660
- }
661
- resolveMapValue(value, ignorePending = false) {
662
- return clockWith(clock => {
663
- switch (value._tag) {
664
- case "Complete":
665
- {
666
- this.trackAccess(value.key);
667
- if (this.hasExpired(clock, value.timeToLiveMillis)) {
668
- remove$1(this.cacheState.map, value.key.current);
669
- return succeed$1(none());
670
- }
671
- this.trackHit();
672
- return map(value.exit, some);
673
- }
674
- case "Pending":
675
- {
676
- this.trackAccess(value.key);
677
- this.trackHit();
678
- if (ignorePending) {
679
- return succeed$1(none());
680
- }
681
- return map(_await(value.deferred), some);
682
- }
683
- case "Refreshing":
684
- {
685
- this.trackAccess(value.complete.key);
686
- this.trackHit();
687
- if (this.hasExpired(clock, value.complete.timeToLiveMillis)) {
688
- if (ignorePending) {
689
- return succeed$1(none());
690
- }
691
- return map(_await(value.deferred), some);
692
- }
693
- return map(value.complete.exit, some);
694
- }
695
- }
696
- });
697
- }
698
- trackHit() {
699
- this.cacheState.hits = this.cacheState.hits + 1;
700
- }
701
- trackMiss() {
702
- this.cacheState.misses = this.cacheState.misses + 1;
703
- }
704
- trackAccess(key) {
705
- offer(this.cacheState.accesses, key);
706
- if (compareAndSet(this.cacheState.updating, false, true)) {
707
- let loop = true;
708
- while (loop) {
709
- const key = poll(this.cacheState.accesses, EmptyMutableQueue);
710
- if (key === EmptyMutableQueue) {
711
- loop = false;
712
- } else {
713
- this.cacheState.keys.add(key);
714
- }
715
- }
716
- let size$1 = size(this.cacheState.map);
717
- loop = size$1 > this.capacity;
718
- while (loop) {
719
- const key = this.cacheState.keys.remove();
720
- if (key !== undefined) {
721
- if (has(this.cacheState.map, key.current)) {
722
- remove$1(this.cacheState.map, key.current);
723
- size$1 = size$1 - 1;
724
- loop = size$1 > this.capacity;
725
- }
726
- } else {
727
- loop = false;
728
- }
729
- }
730
- set$1(this.cacheState.updating, false);
731
- }
732
- }
733
- hasExpired(clock, timeToLiveMillis) {
734
- return clock.unsafeCurrentTimeMillis() > timeToLiveMillis;
735
- }
736
- lookupValueOf(input, deferred) {
737
- return clockWith(clock => suspend(() => {
738
- const key = input;
739
- return pipe(this.lookup(input), provideContext(this.context), exit, flatMap(exit => {
740
- const now = clock.unsafeCurrentTimeMillis();
741
- const stats = makeEntryStats(now);
742
- const value = complete(makeMapKey(key), exit, stats, now + toMillis(decode(this.timeToLive(exit))));
743
- set(this.cacheState.map, key, value);
744
- return zipRight(done(deferred, exit), exit);
745
- }), onInterrupt(() => zipRight(interrupt(deferred), sync(() => {
746
- remove$1(this.cacheState.map, key);
747
- }))));
748
- }));
749
- }
750
- }
751
- /** @internal */
752
- const make$1 = options => {
753
- const timeToLive = decode(options.timeToLive);
754
- return makeWith({
755
- capacity: options.capacity,
756
- lookup: options.lookup,
757
- timeToLive: () => timeToLive
758
- });
759
- };
760
- /** @internal */
761
- const makeWith = options => map(all([context(), fiberId]), ([context, fiberId]) => new CacheImpl(options.capacity, context, fiberId, options.lookup, exit => decode(options.timeToLive(exit))));
762
-
763
- /**
764
- * Constructs a new cache with the specified capacity, time to live, and
765
- * lookup function.
766
- *
767
- * @since 2.0.0
768
- * @category constructors
769
- */
770
- const make = make$1;
771
-
772
- class FetchError extends TaggedError('FetchError') {
773
- }
774
- class NotFoundError extends TaggedError('NotFoundError') {
775
- }
776
- const httpClient = (input, init) => gen(function* () {
777
- const response = yield* tryPromise({
778
- try: () => fetch(input, init),
779
- catch: error => new FetchError({ cause: error }),
780
- });
781
- if (response.status === 404) {
782
- return yield* new NotFoundError({ url: response.url });
783
- }
784
- return response;
785
- });
786
- class ResponseTextError extends TaggedError('ResponseTextError') {
787
- constructor(error) {
788
- super(new Error(`Failed to read response text`, { cause: error }));
789
- }
790
- }
791
- const responseAsText = (res) => tryPromise({
792
- try: () => res.text(),
793
- catch: error => new ResponseTextError(error),
794
- });
795
-
796
- const SVGString = refined(isValidSVG, () => error('SVG data is malformed'));
797
- class BrandValidationError extends TaggedError('BrandValidationError') {
798
- constructor(error, type) {
799
- super(new Error(`Brand validation failed for type ${type}.`, { cause: error }));
800
- }
801
- }
802
- const createValidSVGString = (svg) => try_({
803
- try: () => SVGString(svg),
804
- catch: error => new BrandValidationError(error, 'SVGString'),
805
- });
806
- function isValidSVG(svg) {
807
- if (typeof svg !== 'string') {
808
- return false;
809
- }
810
- try {
811
- const parser = new DOMParser();
812
- const doc = parser.parseFromString(svg, 'image/svg+xml');
813
- return doc.documentElement.nodeName === 'svg';
814
- }
815
- catch {
816
- return false;
817
- }
818
- }
819
-
820
- const emptyDefaultSvg = () => SVGString(`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"></svg>`);
821
- const createIconCache = () => make({
822
- capacity: 200,
823
- timeToLive: infinity,
824
- lookup: (key) => gen(function* () {
825
- const name = key;
826
- const assetPath = yield* syncCreateAssetUrlSafely(`${name}.svg`, 'icons');
827
- const res = yield* httpClient(assetPath);
828
- const responseString = yield* responseAsText(res);
829
- return yield* createValidSVGString(responseString);
830
- }),
831
- });
832
- let cacheInstance = null;
833
- function fetchIconSvg(name) {
834
- const key = name;
835
- return gen(function* () {
836
- if (!cacheInstance) {
837
- cacheInstance = yield* createIconCache();
838
- }
839
- return yield* cacheInstance.get(key);
840
- });
841
- }
842
- function clearIconCache() {
843
- return gen(function* () {
844
- if (cacheInstance) {
845
- yield* cacheInstance.invalidateAll;
846
- }
847
- else {
848
- logWarning('Attempted to clear icon cache before it was initialized');
849
- }
850
- });
851
- }
852
-
853
- export { clearIconCache as c, emptyDefaultSvg as e, fetchIconSvg as f };