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