@lmvz-ds/components 0.12.5 → 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 (128) hide show
  1. package/dist/cjs/assets-CJzJZPzV.js +26 -0
  2. package/dist/{esm/Effect-BhQLGXPs.js → cjs/icons-FIfJEo6G.js} +1708 -5205
  3. package/dist/cjs/{index-CVw4GUo6.js → index-Bp6Dd2i1.js} +4 -2
  4. package/dist/cjs/{index-9ZJx0550.js → index-D3BMpL5w.js} +0 -3
  5. package/dist/cjs/index.cjs.js +4 -6
  6. package/dist/cjs/lmvz-action.cjs.entry.js +1 -1
  7. package/dist/cjs/lmvz-button.cjs.entry.js +7 -10
  8. package/dist/cjs/lmvz-card.cjs.entry.js +4 -5
  9. package/dist/cjs/lmvz-chip.cjs.entry.js +1 -1
  10. package/dist/cjs/lmvz-components.cjs.js +1 -1
  11. package/dist/cjs/lmvz-header.cjs.entry.js +13 -12
  12. package/dist/cjs/lmvz-icon.cjs.entry.js +8 -10
  13. package/dist/cjs/lmvz-input.cjs.entry.js +8 -11
  14. package/dist/cjs/lmvz-menuitem.cjs.entry.js +5 -7
  15. package/dist/cjs/loader.cjs.js +1 -1
  16. package/dist/cjs/reactive-controller-host-BMDEj1kX.js +168 -0
  17. package/dist/collection/components/lmvz-button/lmvz-button.js +3 -3
  18. package/dist/collection/components/lmvz-card/lmvz-card.js +3 -4
  19. package/dist/collection/components/lmvz-header/lmvz-header.js +11 -8
  20. package/dist/collection/components/lmvz-icon/icons.js +2 -2
  21. package/dist/collection/components/lmvz-icon/lmvz-icon.js +2 -2
  22. package/dist/collection/components/lmvz-icon/test/icons.unit.js +21 -12
  23. package/dist/collection/components/lmvz-input/lmvz-input.css +5 -2
  24. package/dist/collection/components/lmvz-input/lmvz-input.js +3 -3
  25. package/dist/collection/components/lmvz-menuitem/lmvz-menuitem.js +3 -3
  26. package/dist/collection/integration/header-integration.js +3 -1
  27. package/dist/collection/utils/{validation → aria}/aria-validation-controller.js +15 -34
  28. package/dist/collection/utils/{list-keyboard-controller.js → aria/list-keyboard-controller.js} +1 -1
  29. package/dist/collection/utils/assets.js +9 -6
  30. package/dist/collection/utils/http.js +2 -2
  31. package/dist/collection/utils/{http.test.js → http.unit.js} +8 -7
  32. package/dist/collection/utils/validation/svg.js +1 -1
  33. package/dist/components/index.js +1 -1
  34. package/dist/components/lmvz-action.js +1 -1
  35. package/dist/components/lmvz-button.js +1 -1
  36. package/dist/components/lmvz-card.js +1 -1
  37. package/dist/components/lmvz-chip.js +1 -1
  38. package/dist/components/lmvz-header.js +1 -1
  39. package/dist/components/lmvz-icon.js +1 -1
  40. package/dist/components/lmvz-input.js +1 -1
  41. package/dist/components/lmvz-menuitem.js +1 -1
  42. package/dist/components/{p-DMLRPGid.js → p-BfTCfPZ1.js} +1 -1
  43. package/dist/components/p-BsS3QvWn.js +1 -0
  44. package/dist/components/p-CMteT-Yo.js +1 -0
  45. package/dist/components/p-CdYWDK7m.js +1 -0
  46. package/dist/components/p-vi4YzJmv.js +1 -0
  47. package/dist/esm/assets-BelZNJ1W.js +23 -0
  48. package/dist/{cjs/Effect-CNhHt4Xb.js → esm/icons-CM7lsnuO.js} +1751 -5457
  49. package/dist/esm/{index-Bt32KzDW.js → index-BfTCfPZ1.js} +3 -1
  50. package/dist/esm/{index-smGPjoDX.js → index-T5ljELGS.js} +1 -3
  51. package/dist/esm/index.js +4 -5
  52. package/dist/esm/lmvz-action.entry.js +1 -1
  53. package/dist/esm/lmvz-button.entry.js +5 -8
  54. package/dist/esm/lmvz-card.entry.js +4 -5
  55. package/dist/esm/lmvz-chip.entry.js +1 -1
  56. package/dist/esm/lmvz-components.js +2 -2
  57. package/dist/esm/lmvz-header.entry.js +11 -10
  58. package/dist/esm/lmvz-icon.entry.js +5 -7
  59. package/dist/esm/lmvz-input.entry.js +6 -9
  60. package/dist/esm/lmvz-menuitem.entry.js +3 -5
  61. package/dist/esm/loader.js +2 -2
  62. package/dist/esm/reactive-controller-host-CZ3dGAjR.js +165 -0
  63. package/dist/lmvz-components/index.esm.js +1 -1
  64. package/dist/lmvz-components/lmvz-components.esm.js +1 -1
  65. package/dist/lmvz-components/p-16878d4c.entry.js +1 -0
  66. package/dist/lmvz-components/p-6e3314ab.entry.js +1 -0
  67. package/dist/lmvz-components/p-8ea1a349.entry.js +1 -0
  68. package/dist/lmvz-components/{p-d4b68381.entry.js → p-980688a0.entry.js} +1 -1
  69. package/dist/lmvz-components/{p-DMLRPGid.js → p-BfTCfPZ1.js} +1 -1
  70. package/dist/lmvz-components/p-BoR31cjC.js +1 -0
  71. package/dist/lmvz-components/p-CVf2C8dL.js +1 -0
  72. package/dist/lmvz-components/p-CZ3dGAjR.js +1 -0
  73. package/dist/lmvz-components/p-T5ljELGS.js +2 -0
  74. package/dist/lmvz-components/p-a34542fa.entry.js +1 -0
  75. package/dist/lmvz-components/p-d2bf6a3f.entry.js +1 -0
  76. package/dist/lmvz-components/p-d9dc29a1.entry.js +1 -0
  77. package/dist/lmvz-components/{p-9faac8f3.entry.js → p-feda2ec5.entry.js} +1 -1
  78. package/dist/manifest.json +1 -1
  79. package/dist/types/components/lmvz-button/lmvz-button.d.ts +2 -2
  80. package/dist/types/components/lmvz-header/lmvz-header.d.ts +5 -4
  81. package/dist/types/components/lmvz-icon/lmvz-icon.d.ts +1 -1
  82. package/dist/types/components/lmvz-input/lmvz-input.d.ts +1 -1
  83. package/dist/types/components/lmvz-menuitem/lmvz-menuitem.d.ts +2 -2
  84. package/dist/types/utils/{validation → aria}/aria-validation-controller.d.ts +1 -5
  85. package/dist/types/utils/{element-activation-controller.d.ts → aria/element-activation-controller.d.ts} +2 -2
  86. package/dist/types/utils/{list-keyboard-controller.d.ts → aria/list-keyboard-controller.d.ts} +1 -1
  87. package/dist/types/utils/assets.d.ts +1 -8
  88. package/dist/types/utils/http.d.ts +3 -3
  89. package/dist/types/utils/validation/svg.d.ts +2 -2
  90. package/hydrate/index.js +3608 -54447
  91. package/hydrate/index.mjs +3608 -54447
  92. package/package.json +17 -18
  93. package/readme.md +18 -0
  94. package/dist/cjs/MutableQueue-Bk9tBfaK.js +0 -462
  95. package/dist/cjs/_commonjsHelpers-CFO10eej.js +0 -7
  96. package/dist/cjs/aria-validation-controller-B3hMkau3.js +0 -2930
  97. package/dist/cjs/assets-BguFB3wV.js +0 -71
  98. package/dist/cjs/axe-BNqwbBGU.js +0 -32834
  99. package/dist/cjs/icons-7wUEcWEo.js +0 -607
  100. package/dist/components/p-3I3wZmp8.js +0 -1
  101. package/dist/components/p-B85MJLTf.js +0 -1
  102. package/dist/components/p-BaPwpeMs.js +0 -1
  103. package/dist/components/p-CAi33KTt.js +0 -1
  104. package/dist/components/p-CdofjRtQ.js +0 -1
  105. package/dist/components/p-D1HbKFuh.js +0 -12
  106. package/dist/components/p-UwhTS2ue.js +0 -1
  107. package/dist/esm/MutableQueue-CNlEFklh.js +0 -431
  108. package/dist/esm/_commonjsHelpers-B85MJLTf.js +0 -5
  109. package/dist/esm/aria-validation-controller-iA4YWFG-.js +0 -2927
  110. package/dist/esm/assets-Iu8neKuE.js +0 -67
  111. package/dist/esm/axe-cRQ9Ux1I.js +0 -32832
  112. package/dist/esm/icons-Bx1wWPM2.js +0 -603
  113. package/dist/lmvz-components/p-1a10fcbd.entry.js +0 -1
  114. package/dist/lmvz-components/p-274c36df.entry.js +0 -1
  115. package/dist/lmvz-components/p-2ba68483.entry.js +0 -1
  116. package/dist/lmvz-components/p-4XIjw3k8.js +0 -1
  117. package/dist/lmvz-components/p-51Fb_qqD.js +0 -1
  118. package/dist/lmvz-components/p-77e26e71.entry.js +0 -1
  119. package/dist/lmvz-components/p-B85MJLTf.js +0 -1
  120. package/dist/lmvz-components/p-BhQLGXPs.js +0 -1
  121. package/dist/lmvz-components/p-CXWyvf0D.js +0 -1
  122. package/dist/lmvz-components/p-D1HbKFuh.js +0 -12
  123. package/dist/lmvz-components/p-D7I-Bc5i.js +0 -1
  124. package/dist/lmvz-components/p-a5fe62b6.entry.js +0 -1
  125. package/dist/lmvz-components/p-c8b78793.entry.js +0 -1
  126. package/dist/lmvz-components/p-smGPjoDX.js +0 -2
  127. /package/dist/collection/utils/{element-activation-controller.js → aria/element-activation-controller.js} +0 -0
  128. /package/dist/types/utils/{http.test.d.ts → http.unit.d.ts} +0 -0
@@ -1,607 +0,0 @@
1
- 'use strict';
2
-
3
- var Effect = require('./Effect-CNhHt4Xb.js');
4
- var MutableQueue = require('./MutableQueue-Bk9tBfaK.js');
5
- var assets = require('./assets-BguFB3wV.js');
6
-
7
- /**
8
- * This module provides types and utility functions to create and work with branded types,
9
- * which are TypeScript types with an added type tag to prevent accidental usage of a value in the wrong context.
10
- *
11
- * The `refined` and `nominal` functions are both used to create branded types in TypeScript.
12
- * The main difference between them is that `refined` allows for validation of the data, while `nominal` does not.
13
- *
14
- * 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.
15
- * This is useful when you want to distinguish between two values of the same type that have different meanings.
16
- * The `nominal` function does not perform any validation of the input data.
17
- *
18
- * On the other hand, the `refined` function is used to create a new branded type that has the same underlying type as the input,
19
- * but with a different name, and it also allows for validation of the input data.
20
- * The `refined` function takes a predicate that is used to validate the input data.
21
- * If the input data fails the validation, a `BrandErrors` is returned, which provides information about the specific validation failure.
22
- *
23
- * @since 2.0.0
24
- */
25
- /**
26
- * @since 2.0.0
27
- * @category symbols
28
- */
29
- const RefinedConstructorsTypeId = /*#__PURE__*/Symbol.for("effect/Brand/Refined");
30
- /**
31
- * Returns a `BrandErrors` that contains a single `RefinementError`.
32
- *
33
- * @since 2.0.0
34
- * @category constructors
35
- */
36
- const error = (message, meta) => [{
37
- message,
38
- meta
39
- }];
40
- function refined(...args) {
41
- const either = args.length === 2 ? unbranded => args[0](unbranded) ? Effect.right(unbranded) : Effect.left(args[1](unbranded)) : unbranded => {
42
- return Effect.match(args[0](unbranded), {
43
- onNone: () => Effect.right(unbranded),
44
- onSome: Effect.left
45
- });
46
- };
47
- return Object.assign(unbranded => Effect.getOrThrowWith(either(unbranded), Effect.identity), {
48
- [RefinedConstructorsTypeId]: RefinedConstructorsTypeId,
49
- option: args => Effect.getRight(either(args)),
50
- either,
51
- is: args => Effect.isRight(either(args))
52
- });
53
- }
54
-
55
- /** @internal */
56
- const complete = (key, exit, entryStats, timeToLiveMillis) => Effect.struct({
57
- _tag: "Complete",
58
- key,
59
- exit,
60
- entryStats,
61
- timeToLiveMillis
62
- });
63
- /** @internal */
64
- const pending = (key, deferred) => Effect.struct({
65
- _tag: "Pending",
66
- key,
67
- deferred
68
- });
69
- /** @internal */
70
- const refreshing = (deferred, complete) => Effect.struct({
71
- _tag: "Refreshing",
72
- deferred,
73
- complete
74
- });
75
- /** @internal */
76
- const MapKeyTypeId = /*#__PURE__*/Symbol.for("effect/Cache/MapKey");
77
- class MapKeyImpl {
78
- current;
79
- [MapKeyTypeId] = MapKeyTypeId;
80
- previous = undefined;
81
- next = undefined;
82
- constructor(current) {
83
- this.current = current;
84
- }
85
- [Effect.symbol]() {
86
- return Effect.pipe(Effect.hash(this.current), Effect.combine(Effect.hash(this.previous)), Effect.combine(Effect.hash(this.next)), Effect.cached(this));
87
- }
88
- [Effect.symbol$1](that) {
89
- if (this === that) {
90
- return true;
91
- }
92
- return isMapKey(that) && Effect.equals(this.current, that.current) && Effect.equals(this.previous, that.previous) && Effect.equals(this.next, that.next);
93
- }
94
- }
95
- /** @internal */
96
- const makeMapKey = current => new MapKeyImpl(current);
97
- /** @internal */
98
- const isMapKey = u => Effect.hasProperty(u, MapKeyTypeId);
99
- class KeySetImpl {
100
- head = undefined;
101
- tail = undefined;
102
- add(key) {
103
- if (key !== this.tail) {
104
- if (this.tail === undefined) {
105
- this.head = key;
106
- this.tail = key;
107
- } else {
108
- const previous = key.previous;
109
- const next = key.next;
110
- if (next !== undefined) {
111
- key.next = undefined;
112
- if (previous !== undefined) {
113
- previous.next = next;
114
- next.previous = previous;
115
- } else {
116
- this.head = next;
117
- this.head.previous = undefined;
118
- }
119
- }
120
- this.tail.next = key;
121
- key.previous = this.tail;
122
- this.tail = key;
123
- }
124
- }
125
- }
126
- remove() {
127
- const key = this.head;
128
- if (key !== undefined) {
129
- const next = key.next;
130
- if (next !== undefined) {
131
- key.next = undefined;
132
- this.head = next;
133
- this.head.previous = undefined;
134
- } else {
135
- this.head = undefined;
136
- this.tail = undefined;
137
- }
138
- }
139
- return key;
140
- }
141
- }
142
- /** @internal */
143
- const makeKeySet = () => new KeySetImpl();
144
- /**
145
- * Constructs a new `CacheState` from the specified values.
146
- *
147
- * @internal
148
- */
149
- const makeCacheState = (map, keys, accesses, updating, hits, misses) => ({
150
- map,
151
- keys,
152
- accesses,
153
- updating,
154
- hits,
155
- misses
156
- });
157
- /**
158
- * Constructs an initial cache state.
159
- *
160
- * @internal
161
- */
162
- const initialCacheState = () => makeCacheState(Effect.empty(), makeKeySet(), MutableQueue.unbounded(), Effect.make(false), 0, 0);
163
- /** @internal */
164
- const CacheSymbolKey = "effect/Cache";
165
- /** @internal */
166
- const CacheTypeId = /*#__PURE__*/Symbol.for(CacheSymbolKey);
167
- const cacheVariance = {
168
- /* c8 ignore next */
169
- _Key: _ => _,
170
- /* c8 ignore next */
171
- _Error: _ => _,
172
- /* c8 ignore next */
173
- _Value: _ => _
174
- };
175
- /** @internal */
176
- const ConsumerCacheSymbolKey = "effect/ConsumerCache";
177
- /** @internal */
178
- const ConsumerCacheTypeId = /*#__PURE__*/Symbol.for(ConsumerCacheSymbolKey);
179
- const consumerCacheVariance = {
180
- /* c8 ignore next */
181
- _Key: _ => _,
182
- /* c8 ignore next */
183
- _Error: _ => _,
184
- /* c8 ignore next */
185
- _Value: _ => _
186
- };
187
- /** @internal */
188
- const makeCacheStats = options => options;
189
- /** @internal */
190
- const makeEntryStats = loadedMillis => ({
191
- loadedMillis
192
- });
193
- class CacheImpl {
194
- capacity;
195
- context;
196
- fiberId;
197
- lookup;
198
- timeToLive;
199
- [CacheTypeId] = cacheVariance;
200
- [ConsumerCacheTypeId] = consumerCacheVariance;
201
- cacheState;
202
- constructor(capacity, context, fiberId, lookup, timeToLive) {
203
- this.capacity = capacity;
204
- this.context = context;
205
- this.fiberId = fiberId;
206
- this.lookup = lookup;
207
- this.timeToLive = timeToLive;
208
- this.cacheState = initialCacheState();
209
- }
210
- get(key) {
211
- return Effect.map(this.getEither(key), Effect.merge);
212
- }
213
- get cacheStats() {
214
- return Effect.sync(() => makeCacheStats({
215
- hits: this.cacheState.hits,
216
- misses: this.cacheState.misses,
217
- size: Effect.size(this.cacheState.map)
218
- }));
219
- }
220
- getOption(key) {
221
- return Effect.suspend(() => Effect.match(Effect.get(this.cacheState.map, key), {
222
- onNone: () => {
223
- const mapKey = makeMapKey(key);
224
- this.trackAccess(mapKey);
225
- this.trackMiss();
226
- return Effect.succeed$1(Effect.none());
227
- },
228
- onSome: value => this.resolveMapValue(value)
229
- }));
230
- }
231
- getOptionComplete(key) {
232
- return Effect.suspend(() => Effect.match(Effect.get(this.cacheState.map, key), {
233
- onNone: () => {
234
- const mapKey = makeMapKey(key);
235
- this.trackAccess(mapKey);
236
- this.trackMiss();
237
- return Effect.succeed$1(Effect.none());
238
- },
239
- onSome: value => this.resolveMapValue(value, true)
240
- }));
241
- }
242
- contains(key) {
243
- return Effect.sync(() => Effect.has(this.cacheState.map, key));
244
- }
245
- entryStats(key) {
246
- return Effect.sync(() => {
247
- const option = Effect.get(this.cacheState.map, key);
248
- if (Effect.isSome(option)) {
249
- switch (option.value._tag) {
250
- case "Complete":
251
- {
252
- const loaded = option.value.entryStats.loadedMillis;
253
- return Effect.some(makeEntryStats(loaded));
254
- }
255
- case "Pending":
256
- {
257
- return Effect.none();
258
- }
259
- case "Refreshing":
260
- {
261
- const loaded = option.value.complete.entryStats.loadedMillis;
262
- return Effect.some(makeEntryStats(loaded));
263
- }
264
- }
265
- }
266
- return Effect.none();
267
- });
268
- }
269
- getEither(key) {
270
- return Effect.suspend(() => {
271
- const k = key;
272
- let mapKey = undefined;
273
- let deferred = undefined;
274
- let value = Effect.getOrUndefined(Effect.get(this.cacheState.map, k));
275
- if (value === undefined) {
276
- deferred = MutableQueue.unsafeMake(this.fiberId);
277
- mapKey = makeMapKey(k);
278
- if (Effect.has(this.cacheState.map, k)) {
279
- value = Effect.getOrUndefined(Effect.get(this.cacheState.map, k));
280
- } else {
281
- Effect.set(this.cacheState.map, k, pending(mapKey, deferred));
282
- }
283
- }
284
- if (value === undefined) {
285
- this.trackAccess(mapKey);
286
- this.trackMiss();
287
- return Effect.map(this.lookupValueOf(key, deferred), Effect.right);
288
- } else {
289
- return Effect.flatMap(this.resolveMapValue(value), Effect.match({
290
- onNone: () => this.getEither(key),
291
- onSome: value => Effect.succeed$1(Effect.left(value))
292
- }));
293
- }
294
- });
295
- }
296
- invalidate(key) {
297
- return Effect.sync(() => {
298
- Effect.remove(this.cacheState.map, key);
299
- });
300
- }
301
- invalidateWhen(key, when) {
302
- return Effect.sync(() => {
303
- const value = Effect.get(this.cacheState.map, key);
304
- if (Effect.isSome(value) && value.value._tag === "Complete") {
305
- if (value.value.exit._tag === "Success") {
306
- if (when(value.value.exit.value)) {
307
- Effect.remove(this.cacheState.map, key);
308
- }
309
- }
310
- }
311
- });
312
- }
313
- get invalidateAll() {
314
- return Effect.sync(() => {
315
- this.cacheState.map = Effect.empty();
316
- });
317
- }
318
- refresh(key) {
319
- return Effect.clockWith(clock => Effect.suspend(() => {
320
- const k = key;
321
- const deferred = MutableQueue.unsafeMake(this.fiberId);
322
- let value = Effect.getOrUndefined(Effect.get(this.cacheState.map, k));
323
- if (value === undefined) {
324
- if (Effect.has(this.cacheState.map, k)) {
325
- value = Effect.getOrUndefined(Effect.get(this.cacheState.map, k));
326
- } else {
327
- Effect.set(this.cacheState.map, k, pending(makeMapKey(k), deferred));
328
- }
329
- }
330
- if (value === undefined) {
331
- return Effect.asVoid(this.lookupValueOf(key, deferred));
332
- } else {
333
- switch (value._tag) {
334
- case "Complete":
335
- {
336
- if (this.hasExpired(clock, value.timeToLiveMillis)) {
337
- const found = Effect.getOrUndefined(Effect.get(this.cacheState.map, k));
338
- if (Effect.equals(found, value)) {
339
- Effect.remove(this.cacheState.map, k);
340
- }
341
- return Effect.asVoid(this.get(key));
342
- }
343
- // Only trigger the lookup if we're still the current value, `completedResult`
344
- return Effect.pipe(this.lookupValueOf(key, deferred), Effect.when(() => {
345
- const current = Effect.getOrUndefined(Effect.get(this.cacheState.map, k));
346
- if (Effect.equals(current, value)) {
347
- const mapValue = refreshing(deferred, value);
348
- Effect.set(this.cacheState.map, k, mapValue);
349
- return true;
350
- }
351
- return false;
352
- }), Effect.asVoid);
353
- }
354
- case "Pending":
355
- {
356
- return MutableQueue._await(value.deferred);
357
- }
358
- case "Refreshing":
359
- {
360
- return MutableQueue._await(value.deferred);
361
- }
362
- }
363
- }
364
- }));
365
- }
366
- set(key, value) {
367
- return Effect.clockWith(clock => Effect.sync(() => {
368
- const now = clock.unsafeCurrentTimeMillis();
369
- const k = key;
370
- const lookupResult = MutableQueue.succeed(value);
371
- const mapValue = complete(makeMapKey(k), lookupResult, makeEntryStats(now), now + Effect.toMillis(Effect.decode(this.timeToLive(lookupResult))));
372
- Effect.set(this.cacheState.map, k, mapValue);
373
- }));
374
- }
375
- get size() {
376
- return Effect.sync(() => {
377
- return Effect.size(this.cacheState.map);
378
- });
379
- }
380
- get values() {
381
- return Effect.sync(() => {
382
- const values = [];
383
- for (const entry of this.cacheState.map) {
384
- if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") {
385
- values.push(entry[1].exit.value);
386
- }
387
- }
388
- return values;
389
- });
390
- }
391
- get entries() {
392
- return Effect.sync(() => {
393
- const values = [];
394
- for (const entry of this.cacheState.map) {
395
- if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") {
396
- values.push([entry[0], entry[1].exit.value]);
397
- }
398
- }
399
- return values;
400
- });
401
- }
402
- get keys() {
403
- return Effect.sync(() => {
404
- const keys = [];
405
- for (const entry of this.cacheState.map) {
406
- if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") {
407
- keys.push(entry[0]);
408
- }
409
- }
410
- return keys;
411
- });
412
- }
413
- resolveMapValue(value, ignorePending = false) {
414
- return Effect.clockWith(clock => {
415
- switch (value._tag) {
416
- case "Complete":
417
- {
418
- this.trackAccess(value.key);
419
- if (this.hasExpired(clock, value.timeToLiveMillis)) {
420
- Effect.remove(this.cacheState.map, value.key.current);
421
- return Effect.succeed$1(Effect.none());
422
- }
423
- this.trackHit();
424
- return Effect.map(value.exit, Effect.some);
425
- }
426
- case "Pending":
427
- {
428
- this.trackAccess(value.key);
429
- this.trackHit();
430
- if (ignorePending) {
431
- return Effect.succeed$1(Effect.none());
432
- }
433
- return Effect.map(MutableQueue._await(value.deferred), Effect.some);
434
- }
435
- case "Refreshing":
436
- {
437
- this.trackAccess(value.complete.key);
438
- this.trackHit();
439
- if (this.hasExpired(clock, value.complete.timeToLiveMillis)) {
440
- if (ignorePending) {
441
- return Effect.succeed$1(Effect.none());
442
- }
443
- return Effect.map(MutableQueue._await(value.deferred), Effect.some);
444
- }
445
- return Effect.map(value.complete.exit, Effect.some);
446
- }
447
- }
448
- });
449
- }
450
- trackHit() {
451
- this.cacheState.hits = this.cacheState.hits + 1;
452
- }
453
- trackMiss() {
454
- this.cacheState.misses = this.cacheState.misses + 1;
455
- }
456
- trackAccess(key) {
457
- MutableQueue.offer(this.cacheState.accesses, key);
458
- if (Effect.compareAndSet(this.cacheState.updating, false, true)) {
459
- let loop = true;
460
- while (loop) {
461
- const key = MutableQueue.poll(this.cacheState.accesses, MutableQueue.EmptyMutableQueue);
462
- if (key === MutableQueue.EmptyMutableQueue) {
463
- loop = false;
464
- } else {
465
- this.cacheState.keys.add(key);
466
- }
467
- }
468
- let size = Effect.size(this.cacheState.map);
469
- loop = size > this.capacity;
470
- while (loop) {
471
- const key = this.cacheState.keys.remove();
472
- if (key !== undefined) {
473
- if (Effect.has(this.cacheState.map, key.current)) {
474
- Effect.remove(this.cacheState.map, key.current);
475
- size = size - 1;
476
- loop = size > this.capacity;
477
- }
478
- } else {
479
- loop = false;
480
- }
481
- }
482
- Effect.set$1(this.cacheState.updating, false);
483
- }
484
- }
485
- hasExpired(clock, timeToLiveMillis) {
486
- return clock.unsafeCurrentTimeMillis() > timeToLiveMillis;
487
- }
488
- lookupValueOf(input, deferred) {
489
- return Effect.clockWith(clock => Effect.suspend(() => {
490
- const key = input;
491
- return Effect.pipe(this.lookup(input), Effect.provideContext(this.context), Effect.exit, Effect.flatMap(exit => {
492
- const now = clock.unsafeCurrentTimeMillis();
493
- const stats = makeEntryStats(now);
494
- const value = complete(makeMapKey(key), exit, stats, now + Effect.toMillis(Effect.decode(this.timeToLive(exit))));
495
- Effect.set(this.cacheState.map, key, value);
496
- return Effect.zipRight(MutableQueue.done(deferred, exit), exit);
497
- }), Effect.onInterrupt(() => Effect.zipRight(MutableQueue.interrupt(deferred), Effect.sync(() => {
498
- Effect.remove(this.cacheState.map, key);
499
- }))));
500
- }));
501
- }
502
- }
503
- /** @internal */
504
- const make$1 = options => {
505
- const timeToLive = Effect.decode(options.timeToLive);
506
- return makeWith({
507
- capacity: options.capacity,
508
- lookup: options.lookup,
509
- timeToLive: () => timeToLive
510
- });
511
- };
512
- /** @internal */
513
- const makeWith = options => Effect.map(Effect.all([Effect.context(), Effect.fiberId]), ([context, fiberId]) => new CacheImpl(options.capacity, context, fiberId, options.lookup, exit => Effect.decode(options.timeToLive(exit))));
514
-
515
- /**
516
- * Constructs a new cache with the specified capacity, time to live, and
517
- * lookup function.
518
- *
519
- * @since 2.0.0
520
- * @category constructors
521
- */
522
- const make = make$1;
523
-
524
- class FetchError extends assets.TaggedError('FetchError') {
525
- }
526
- class NotFoundError extends assets.TaggedError('NotFoundError') {
527
- }
528
- const httpClient = (input, init) => Effect.gen(function* () {
529
- const response = yield* Effect.tryPromise({
530
- try: () => fetch(input, init),
531
- catch: error => new FetchError({ cause: error }),
532
- });
533
- if (response.status === 404) {
534
- return yield* new NotFoundError({ url: response.url });
535
- }
536
- return response;
537
- });
538
- class ResponseTextError extends assets.TaggedError('ResponseTextError') {
539
- constructor(error) {
540
- super(new Error(`Failed to read response text`, { cause: error }));
541
- }
542
- }
543
- const responseAsText = (res) => Effect.tryPromise({
544
- try: () => res.text(),
545
- catch: error => new ResponseTextError(error),
546
- });
547
-
548
- const SVGString = refined(isValidSVG, () => error('SVG data is malformed'));
549
- class BrandValidationError extends assets.TaggedError('BrandValidationError') {
550
- constructor(error, type) {
551
- super(new Error(`Brand validation failed for type ${type}.`, { cause: error }));
552
- }
553
- }
554
- const createValidSVGString = (svg) => Effect.try_({
555
- try: () => SVGString(svg),
556
- catch: error => new BrandValidationError(error, 'SVGString'),
557
- });
558
- function isValidSVG(svg) {
559
- if (typeof svg !== 'string') {
560
- return false;
561
- }
562
- try {
563
- const parser = new DOMParser();
564
- const doc = parser.parseFromString(svg, 'image/svg+xml');
565
- return doc.documentElement.nodeName === 'svg';
566
- }
567
- catch {
568
- return false;
569
- }
570
- }
571
-
572
- const emptyDefaultSvg = () => SVGString(`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"></svg>`);
573
- const createIconCache = () => make({
574
- capacity: 200,
575
- timeToLive: Effect.infinity,
576
- lookup: (key) => Effect.gen(function* () {
577
- const name = key;
578
- const assetPath = yield* assets.syncCreateAssetUrlSafely(`${name}.svg`, 'icons');
579
- const res = yield* httpClient(assetPath);
580
- const responseString = yield* responseAsText(res);
581
- return yield* createValidSVGString(responseString);
582
- }),
583
- });
584
- let cacheInstance = null;
585
- function fetchIconSvg(name) {
586
- const key = name;
587
- return Effect.gen(function* () {
588
- if (!cacheInstance) {
589
- cacheInstance = yield* createIconCache();
590
- }
591
- return yield* cacheInstance.get(key);
592
- });
593
- }
594
- function clearIconCache() {
595
- return Effect.gen(function* () {
596
- if (cacheInstance) {
597
- yield* cacheInstance.invalidateAll;
598
- }
599
- else {
600
- Effect.logWarning('Attempted to clear icon cache before it was initialized');
601
- }
602
- });
603
- }
604
-
605
- exports.clearIconCache = clearIconCache;
606
- exports.emptyDefaultSvg = emptyDefaultSvg;
607
- exports.fetchIconSvg = fetchIconSvg;