@abcagency/hc-ui-components 1.3.81 → 1.3.83
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/components/HireControlMap.js +1 -1
- package/dist/components/containers/filter/commute-container.js +1 -1
- package/dist/components/containers/maps/map-container.js +1 -1
- package/dist/components/containers/maps/map-marker-container.js +1 -1
- package/dist/components/modules/accordions/default.js +2 -2
- package/dist/components/modules/buttons/button-group-apply.js +1 -1
- package/dist/components/modules/buttons/default.js +2 -2
- package/dist/components/modules/cards/default.js +2 -2
- package/dist/components/modules/dialogs/apply-dialog.js +1 -1
- package/dist/components/modules/filter/commute.js +2 -2
- package/dist/components/modules/filter/sort.js +2 -2
- package/dist/components/modules/grid.js +1 -1
- package/dist/components/modules/icon.js +1 -1
- package/dist/components/modules/list/header.js +1 -1
- package/dist/components/modules/list/item-expand-card/index.js +1 -1
- package/dist/components/modules/maps/map-marker.js +1 -1
- package/dist/components/modules/maps/map.js +1 -1
- package/dist/components/modules/maps/place-marker.js +1 -1
- package/dist/components/modules/maps/tabs.js +70 -12
- package/dist/components/modules/maps/tabs.js.map +1 -1
- package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.js +802 -0
- package/dist/node_modules/@floating-ui/core/dist/floating-ui.core.js.map +1 -0
- package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.js +679 -0
- package/dist/node_modules/@floating-ui/dom/dist/floating-ui.dom.js.map +1 -0
- package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js +343 -0
- package/dist/node_modules/@floating-ui/react-dom/dist/floating-ui.react-dom.js.map +1 -0
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js +140 -0
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js.map +1 -0
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +137 -0
- package/dist/node_modules/@floating-ui/utils/dist/floating-ui.utils.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/components/combobox/combobox.js +33 -0
- package/dist/node_modules/@headlessui/react/dist/components/combobox/combobox.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/components/keyboard.js +4 -0
- package/dist/node_modules/@headlessui/react/dist/components/keyboard.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/components/transitions/transition.js +19 -0
- package/dist/node_modules/@headlessui/react/dist/components/transitions/transition.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/components/transitions/utils/transition.js +8 -0
- package/dist/node_modules/@headlessui/react/dist/components/transitions/utils/transition.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-computed.js +8 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-computed.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-controllable.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-controllable.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-disposables.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-disposables.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-document-event.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-document-event.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-event.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-event.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-flags.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-flags.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-id.js +9 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-id.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-is-mounted.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-is-mounted.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-iso-morphic-effect.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-iso-morphic-effect.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-latest-value.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-latest-value.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-outside-click.js +10 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-outside-click.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-owner.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-owner.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-resolve-button-type.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-resolve-button-type.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-server-handoff-complete.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-server-handoff-complete.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-sync-refs.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-sync-refs.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-tracked-pointer.js +6 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-tracked-pointer.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-transition.js +11 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-transition.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-tree-walker.js +8 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-tree-walker.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-watch.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-watch.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-window-event.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/hooks/use-window-event.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/internal/hidden.js +6 -0
- package/dist/node_modules/@headlessui/react/dist/internal/hidden.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/internal/open-closed.js +6 -0
- package/dist/node_modules/@headlessui/react/dist/internal/open-closed.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/active-element-history.js +6 -0
- package/dist/node_modules/@headlessui/react/dist/utils/active-element-history.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/bugs.js +4 -0
- package/dist/node_modules/@headlessui/react/dist/utils/bugs.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/calculate-active-index.js +4 -0
- package/dist/node_modules/@headlessui/react/dist/utils/calculate-active-index.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/class-names.js +4 -0
- package/dist/node_modules/@headlessui/react/dist/utils/class-names.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/disposables.js +6 -0
- package/dist/node_modules/@headlessui/react/dist/utils/disposables.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/document-ready.js +4 -0
- package/dist/node_modules/@headlessui/react/dist/utils/document-ready.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/env.js +4 -0
- package/dist/node_modules/@headlessui/react/dist/utils/env.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/focus-management.js +7 -0
- package/dist/node_modules/@headlessui/react/dist/utils/focus-management.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/form.js +4 -0
- package/dist/node_modules/@headlessui/react/dist/utils/form.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/match.js +4 -0
- package/dist/node_modules/@headlessui/react/dist/utils/match.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/micro-task.js +4 -0
- package/dist/node_modules/@headlessui/react/dist/utils/micro-task.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/once.js +4 -0
- package/dist/node_modules/@headlessui/react/dist/utils/once.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/owner.js +6 -0
- package/dist/node_modules/@headlessui/react/dist/utils/owner.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/platform.js +4 -0
- package/dist/node_modules/@headlessui/react/dist/utils/platform.js.map +1 -0
- package/dist/node_modules/@headlessui/react/dist/utils/render.js +11 -0
- package/dist/node_modules/@headlessui/react/dist/utils/render.js.map +1 -0
- package/dist/node_modules/@iconify/react/dist/iconify.js +1928 -0
- package/dist/node_modules/@iconify/react/dist/iconify.js.map +1 -0
- package/dist/node_modules/@radix-ui/number/dist/index.js +7 -0
- package/dist/node_modules/@radix-ui/number/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/primitive/dist/index.js +12 -0
- package/dist/node_modules/@radix-ui/primitive/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-accordion/dist/index.js +304 -0
- package/dist/node_modules/@radix-ui/react-accordion/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-arrow/dist/index.js +26 -0
- package/dist/node_modules/@radix-ui/react-arrow/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-collapsible/dist/index.js +145 -0
- package/dist/node_modules/@radix-ui/react-collapsible/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-collection/dist/index.js +69 -0
- package/dist/node_modules/@radix-ui/react-collection/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.js +19 -0
- package/dist/node_modules/@radix-ui/react-compose-refs/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-context/dist/index.js +80 -0
- package/dist/node_modules/@radix-ui/react-context/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-dialog/dist/index.js +320 -0
- package/dist/node_modules/@radix-ui/react-dialog/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-direction/dist/index.js +12 -0
- package/dist/node_modules/@radix-ui/react-direction/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.js +212 -0
- package/dist/node_modules/@radix-ui/react-dismissable-layer/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.js +27 -0
- package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.js +208 -0
- package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-id/dist/index.js +16 -0
- package/dist/node_modules/@radix-ui/react-id/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-popper/dist/index.js +279 -0
- package/dist/node_modules/@radix-ui/react-popper/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-portal/dist/index.js +18 -0
- package/dist/node_modules/@radix-ui/react-portal/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-presence/dist/index.js +120 -0
- package/dist/node_modules/@radix-ui/react-presence/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-primitive/dist/index.js +42 -0
- package/dist/node_modules/@radix-ui/react-primitive/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.js +221 -0
- package/dist/node_modules/@radix-ui/react-roving-focus/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-select/dist/index.js +1109 -0
- package/dist/node_modules/@radix-ui/react-select/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-slot/dist/index.js +82 -0
- package/dist/node_modules/@radix-ui/react-slot/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-tabs/dist/index.js +187 -0
- package/dist/node_modules/@radix-ui/react-tabs/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.js +13 -0
- package/dist/node_modules/@radix-ui/react-use-callback-ref/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.js +47 -0
- package/dist/node_modules/@radix-ui/react-use-controllable-state/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.js +19 -0
- package/dist/node_modules/@radix-ui/react-use-escape-keydown/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.js +8 -0
- package/dist/node_modules/@radix-ui/react-use-layout-effect/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-use-previous/dist/index.js +16 -0
- package/dist/node_modules/@radix-ui/react-use-previous/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-use-size/dist/index.js +41 -0
- package/dist/node_modules/@radix-ui/react-use-size/dist/index.js.map +1 -0
- package/dist/node_modules/@radix-ui/react-visually-hidden/dist/index.js +35 -0
- package/dist/node_modules/@radix-ui/react-visually-hidden/dist/index.js.map +1 -0
- package/dist/node_modules/@react-google-maps/api/dist/esm.js +8515 -0
- package/dist/node_modules/@react-google-maps/api/dist/esm.js.map +1 -0
- package/dist/node_modules/@remix-run/router/dist/router.js +271 -0
- package/dist/node_modules/@remix-run/router/dist/router.js.map +1 -0
- package/dist/node_modules/@tanstack/react-virtual/dist/esm/index.js +43 -0
- package/dist/node_modules/@tanstack/react-virtual/dist/esm/index.js.map +1 -0
- package/dist/node_modules/@tanstack/virtual-core/dist/esm/index.js +669 -0
- package/dist/node_modules/@tanstack/virtual-core/dist/esm/index.js.map +1 -0
- package/dist/node_modules/@tanstack/virtual-core/dist/esm/utils.js +61 -0
- package/dist/node_modules/@tanstack/virtual-core/dist/esm/utils.js.map +1 -0
- package/dist/node_modules/aria-hidden/dist/es2015/index.js +137 -0
- package/dist/node_modules/aria-hidden/dist/es2015/index.js.map +1 -0
- package/dist/node_modules/fuse.js/dist/fuse.js +1779 -0
- package/dist/node_modules/fuse.js/dist/fuse.js.map +1 -0
- package/dist/node_modules/get-nonce/dist/es2015/index.js +9 -0
- package/dist/node_modules/get-nonce/dist/es2015/index.js.map +1 -0
- package/dist/node_modules/react/cjs/react-jsx-runtime.production.min.js +17 -0
- package/dist/node_modules/react/cjs/react-jsx-runtime.production.min.js.map +1 -0
- package/dist/node_modules/react/jsx-runtime.js +12 -0
- package/dist/node_modules/react/jsx-runtime.js.map +1 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.js +10 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/Combination.js.map +1 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.js +161 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.js.map +1 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/UI.js +39 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/UI.js.map +1 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.js +22 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.js.map +1 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.js +107 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/handleScroll.js.map +1 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/medium.js +6 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/medium.js.map +1 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.js +8 -0
- package/dist/node_modules/react-remove-scroll/dist/es2015/sidecar.js.map +1 -0
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.js +57 -0
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/component.js.map +1 -0
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.js +11 -0
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/constants.js.map +1 -0
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.js +32 -0
- package/dist/node_modules/react-remove-scroll-bar/dist/es2015/utils.js.map +1 -0
- package/dist/node_modules/react-router/dist/index.js +280 -0
- package/dist/node_modules/react-router/dist/index.js.map +1 -0
- package/dist/node_modules/react-router-dom/dist/index.js +201 -0
- package/dist/node_modules/react-router-dom/dist/index.js.map +1 -0
- package/dist/node_modules/react-style-singleton/dist/es2015/component.js +20 -0
- package/dist/node_modules/react-style-singleton/dist/es2015/component.js.map +1 -0
- package/dist/node_modules/react-style-singleton/dist/es2015/hook.js +26 -0
- package/dist/node_modules/react-style-singleton/dist/es2015/hook.js.map +1 -0
- package/dist/node_modules/react-style-singleton/dist/es2015/singleton.js +52 -0
- package/dist/node_modules/react-style-singleton/dist/es2015/singleton.js.map +1 -0
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js +2530 -0
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js.map +1 -0
- package/dist/node_modules/tslib/tslib.es6.js +57 -0
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -0
- package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.js +25 -0
- package/dist/node_modules/use-callback-ref/dist/es2015/assignRef.js.map +1 -0
- package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.js +49 -0
- package/dist/node_modules/use-callback-ref/dist/es2015/useMergeRef.js.map +1 -0
- package/dist/node_modules/use-callback-ref/dist/es2015/useRef.js +43 -0
- package/dist/node_modules/use-callback-ref/dist/es2015/useRef.js.map +1 -0
- package/dist/node_modules/use-places-autocomplete/dist/index.esm.js +243 -0
- package/dist/node_modules/use-places-autocomplete/dist/index.esm.js.map +1 -0
- package/dist/node_modules/use-sidecar/dist/es2015/exports.js +22 -0
- package/dist/node_modules/use-sidecar/dist/es2015/exports.js.map +1 -0
- package/dist/node_modules/use-sidecar/dist/es2015/medium.js +78 -0
- package/dist/node_modules/use-sidecar/dist/es2015/medium.js.map +1 -0
- package/dist/styles/index.css +1 -1
- package/dist/util/filterUtil.js +1 -1
- package/package.json +1 -1
- package/src/components/modules/maps/tabs.js +85 -20
|
@@ -0,0 +1,1928 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
|
|
3
|
+
const matchIconName = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
4
|
+
const stringToIcon = (value, validate, allowSimpleName, provider = "") => {
|
|
5
|
+
const colonSeparated = value.split(":");
|
|
6
|
+
if (value.slice(0, 1) === "@") {
|
|
7
|
+
if (colonSeparated.length < 2 || colonSeparated.length > 3) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
provider = colonSeparated.shift().slice(1);
|
|
11
|
+
}
|
|
12
|
+
if (colonSeparated.length > 3 || !colonSeparated.length) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
if (colonSeparated.length > 1) {
|
|
16
|
+
const name2 = colonSeparated.pop();
|
|
17
|
+
const prefix = colonSeparated.pop();
|
|
18
|
+
const result = {
|
|
19
|
+
// Allow provider without '@': "provider:prefix:name"
|
|
20
|
+
provider: colonSeparated.length > 0 ? colonSeparated[0] : provider,
|
|
21
|
+
prefix,
|
|
22
|
+
name: name2
|
|
23
|
+
};
|
|
24
|
+
return validate && !validateIconName(result) ? null : result;
|
|
25
|
+
}
|
|
26
|
+
const name = colonSeparated[0];
|
|
27
|
+
const dashSeparated = name.split("-");
|
|
28
|
+
if (dashSeparated.length > 1) {
|
|
29
|
+
const result = {
|
|
30
|
+
provider,
|
|
31
|
+
prefix: dashSeparated.shift(),
|
|
32
|
+
name: dashSeparated.join("-")
|
|
33
|
+
};
|
|
34
|
+
return validate && !validateIconName(result) ? null : result;
|
|
35
|
+
}
|
|
36
|
+
if (allowSimpleName && provider === "") {
|
|
37
|
+
const result = {
|
|
38
|
+
provider,
|
|
39
|
+
prefix: "",
|
|
40
|
+
name
|
|
41
|
+
};
|
|
42
|
+
return validate && !validateIconName(result, allowSimpleName) ? null : result;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
46
|
+
const validateIconName = (icon, allowSimpleName) => {
|
|
47
|
+
if (!icon) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return !!((icon.provider === "" || icon.provider.match(matchIconName)) && (allowSimpleName && icon.prefix === "" || icon.prefix.match(matchIconName)) && icon.name.match(matchIconName));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const defaultIconDimensions = Object.freeze(
|
|
54
|
+
{
|
|
55
|
+
left: 0,
|
|
56
|
+
top: 0,
|
|
57
|
+
width: 16,
|
|
58
|
+
height: 16
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
const defaultIconTransformations = Object.freeze({
|
|
62
|
+
rotate: 0,
|
|
63
|
+
vFlip: false,
|
|
64
|
+
hFlip: false
|
|
65
|
+
});
|
|
66
|
+
const defaultIconProps = Object.freeze({
|
|
67
|
+
...defaultIconDimensions,
|
|
68
|
+
...defaultIconTransformations
|
|
69
|
+
});
|
|
70
|
+
const defaultExtendedIconProps = Object.freeze({
|
|
71
|
+
...defaultIconProps,
|
|
72
|
+
body: "",
|
|
73
|
+
hidden: false
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
function mergeIconTransformations(obj1, obj2) {
|
|
77
|
+
const result = {};
|
|
78
|
+
if (!obj1.hFlip !== !obj2.hFlip) {
|
|
79
|
+
result.hFlip = true;
|
|
80
|
+
}
|
|
81
|
+
if (!obj1.vFlip !== !obj2.vFlip) {
|
|
82
|
+
result.vFlip = true;
|
|
83
|
+
}
|
|
84
|
+
const rotate = ((obj1.rotate || 0) + (obj2.rotate || 0)) % 4;
|
|
85
|
+
if (rotate) {
|
|
86
|
+
result.rotate = rotate;
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function mergeIconData(parent, child) {
|
|
92
|
+
const result = mergeIconTransformations(parent, child);
|
|
93
|
+
for (const key in defaultExtendedIconProps) {
|
|
94
|
+
if (key in defaultIconTransformations) {
|
|
95
|
+
if (key in parent && !(key in result)) {
|
|
96
|
+
result[key] = defaultIconTransformations[key];
|
|
97
|
+
}
|
|
98
|
+
} else if (key in child) {
|
|
99
|
+
result[key] = child[key];
|
|
100
|
+
} else if (key in parent) {
|
|
101
|
+
result[key] = parent[key];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function getIconsTree(data, names) {
|
|
108
|
+
const icons = data.icons;
|
|
109
|
+
const aliases = data.aliases || /* @__PURE__ */ Object.create(null);
|
|
110
|
+
const resolved = /* @__PURE__ */ Object.create(null);
|
|
111
|
+
function resolve(name) {
|
|
112
|
+
if (icons[name]) {
|
|
113
|
+
return resolved[name] = [];
|
|
114
|
+
}
|
|
115
|
+
if (!(name in resolved)) {
|
|
116
|
+
resolved[name] = null;
|
|
117
|
+
const parent = aliases[name] && aliases[name].parent;
|
|
118
|
+
const value = parent && resolve(parent);
|
|
119
|
+
if (value) {
|
|
120
|
+
resolved[name] = [parent].concat(value);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return resolved[name];
|
|
124
|
+
}
|
|
125
|
+
(Object.keys(icons).concat(Object.keys(aliases))).forEach(resolve);
|
|
126
|
+
return resolved;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function internalGetIconData(data, name, tree) {
|
|
130
|
+
const icons = data.icons;
|
|
131
|
+
const aliases = data.aliases || /* @__PURE__ */ Object.create(null);
|
|
132
|
+
let currentProps = {};
|
|
133
|
+
function parse(name2) {
|
|
134
|
+
currentProps = mergeIconData(
|
|
135
|
+
icons[name2] || aliases[name2],
|
|
136
|
+
currentProps
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
parse(name);
|
|
140
|
+
tree.forEach(parse);
|
|
141
|
+
return mergeIconData(data, currentProps);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function parseIconSet(data, callback) {
|
|
145
|
+
const names = [];
|
|
146
|
+
if (typeof data !== "object" || typeof data.icons !== "object") {
|
|
147
|
+
return names;
|
|
148
|
+
}
|
|
149
|
+
if (data.not_found instanceof Array) {
|
|
150
|
+
data.not_found.forEach((name) => {
|
|
151
|
+
callback(name, null);
|
|
152
|
+
names.push(name);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
const tree = getIconsTree(data);
|
|
156
|
+
for (const name in tree) {
|
|
157
|
+
const item = tree[name];
|
|
158
|
+
if (item) {
|
|
159
|
+
callback(name, internalGetIconData(data, name, item));
|
|
160
|
+
names.push(name);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return names;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const optionalPropertyDefaults = {
|
|
167
|
+
provider: "",
|
|
168
|
+
aliases: {},
|
|
169
|
+
not_found: {},
|
|
170
|
+
...defaultIconDimensions
|
|
171
|
+
};
|
|
172
|
+
function checkOptionalProps(item, defaults) {
|
|
173
|
+
for (const prop in defaults) {
|
|
174
|
+
if (prop in item && typeof item[prop] !== typeof defaults[prop]) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
function quicklyValidateIconSet(obj) {
|
|
181
|
+
if (typeof obj !== "object" || obj === null) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
const data = obj;
|
|
185
|
+
if (typeof data.prefix !== "string" || !obj.icons || typeof obj.icons !== "object") {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
if (!checkOptionalProps(obj, optionalPropertyDefaults)) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
const icons = data.icons;
|
|
192
|
+
for (const name in icons) {
|
|
193
|
+
const icon = icons[name];
|
|
194
|
+
if (!name.match(matchIconName) || typeof icon.body !== "string" || !checkOptionalProps(
|
|
195
|
+
icon,
|
|
196
|
+
defaultExtendedIconProps
|
|
197
|
+
)) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const aliases = data.aliases || /* @__PURE__ */ Object.create(null);
|
|
202
|
+
for (const name in aliases) {
|
|
203
|
+
const icon = aliases[name];
|
|
204
|
+
const parent = icon.parent;
|
|
205
|
+
if (!name.match(matchIconName) || typeof parent !== "string" || !icons[parent] && !aliases[parent] || !checkOptionalProps(
|
|
206
|
+
icon,
|
|
207
|
+
defaultExtendedIconProps
|
|
208
|
+
)) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return data;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const dataStorage = /* @__PURE__ */ Object.create(null);
|
|
216
|
+
function newStorage(provider, prefix) {
|
|
217
|
+
return {
|
|
218
|
+
provider,
|
|
219
|
+
prefix,
|
|
220
|
+
icons: /* @__PURE__ */ Object.create(null),
|
|
221
|
+
missing: /* @__PURE__ */ new Set()
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function getStorage(provider, prefix) {
|
|
225
|
+
const providerStorage = dataStorage[provider] || (dataStorage[provider] = /* @__PURE__ */ Object.create(null));
|
|
226
|
+
return providerStorage[prefix] || (providerStorage[prefix] = newStorage(provider, prefix));
|
|
227
|
+
}
|
|
228
|
+
function addIconSet(storage, data) {
|
|
229
|
+
if (!quicklyValidateIconSet(data)) {
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
return parseIconSet(data, (name, icon) => {
|
|
233
|
+
if (icon) {
|
|
234
|
+
storage.icons[name] = icon;
|
|
235
|
+
} else {
|
|
236
|
+
storage.missing.add(name);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
function addIconToStorage(storage, name, icon) {
|
|
241
|
+
try {
|
|
242
|
+
if (typeof icon.body === "string") {
|
|
243
|
+
storage.icons[name] = { ...icon };
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
} catch (err) {
|
|
247
|
+
}
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
let simpleNames = false;
|
|
252
|
+
function allowSimpleNames(allow) {
|
|
253
|
+
if (typeof allow === "boolean") {
|
|
254
|
+
simpleNames = allow;
|
|
255
|
+
}
|
|
256
|
+
return simpleNames;
|
|
257
|
+
}
|
|
258
|
+
function getIconData(name) {
|
|
259
|
+
const icon = typeof name === "string" ? stringToIcon(name, true, simpleNames) : name;
|
|
260
|
+
if (icon) {
|
|
261
|
+
const storage = getStorage(icon.provider, icon.prefix);
|
|
262
|
+
const iconName = icon.name;
|
|
263
|
+
return storage.icons[iconName] || (storage.missing.has(iconName) ? null : void 0);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function addIcon(name, data) {
|
|
267
|
+
const icon = stringToIcon(name, true, simpleNames);
|
|
268
|
+
if (!icon) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
const storage = getStorage(icon.provider, icon.prefix);
|
|
272
|
+
return addIconToStorage(storage, icon.name, data);
|
|
273
|
+
}
|
|
274
|
+
function addCollection(data, provider) {
|
|
275
|
+
if (typeof data !== "object") {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
if (typeof provider !== "string") {
|
|
279
|
+
provider = data.provider || "";
|
|
280
|
+
}
|
|
281
|
+
if (simpleNames && !provider && !data.prefix) {
|
|
282
|
+
let added = false;
|
|
283
|
+
if (quicklyValidateIconSet(data)) {
|
|
284
|
+
data.prefix = "";
|
|
285
|
+
parseIconSet(data, (name, icon) => {
|
|
286
|
+
if (icon && addIcon(name, icon)) {
|
|
287
|
+
added = true;
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
return added;
|
|
292
|
+
}
|
|
293
|
+
const prefix = data.prefix;
|
|
294
|
+
if (!validateIconName({
|
|
295
|
+
provider,
|
|
296
|
+
prefix,
|
|
297
|
+
name: "a"
|
|
298
|
+
})) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
const storage = getStorage(provider, prefix);
|
|
302
|
+
return !!addIconSet(storage, data);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const defaultIconSizeCustomisations = Object.freeze({
|
|
306
|
+
width: null,
|
|
307
|
+
height: null
|
|
308
|
+
});
|
|
309
|
+
const defaultIconCustomisations = Object.freeze({
|
|
310
|
+
// Dimensions
|
|
311
|
+
...defaultIconSizeCustomisations,
|
|
312
|
+
// Transformations
|
|
313
|
+
...defaultIconTransformations
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
const unitsSplit = /(-?[0-9.]*[0-9]+[0-9.]*)/g;
|
|
317
|
+
const unitsTest = /^-?[0-9.]*[0-9]+[0-9.]*$/g;
|
|
318
|
+
function calculateSize(size, ratio, precision) {
|
|
319
|
+
if (ratio === 1) {
|
|
320
|
+
return size;
|
|
321
|
+
}
|
|
322
|
+
precision = precision || 100;
|
|
323
|
+
if (typeof size === "number") {
|
|
324
|
+
return Math.ceil(size * ratio * precision) / precision;
|
|
325
|
+
}
|
|
326
|
+
if (typeof size !== "string") {
|
|
327
|
+
return size;
|
|
328
|
+
}
|
|
329
|
+
const oldParts = size.split(unitsSplit);
|
|
330
|
+
if (oldParts === null || !oldParts.length) {
|
|
331
|
+
return size;
|
|
332
|
+
}
|
|
333
|
+
const newParts = [];
|
|
334
|
+
let code = oldParts.shift();
|
|
335
|
+
let isNumber = unitsTest.test(code);
|
|
336
|
+
while (true) {
|
|
337
|
+
if (isNumber) {
|
|
338
|
+
const num = parseFloat(code);
|
|
339
|
+
if (isNaN(num)) {
|
|
340
|
+
newParts.push(code);
|
|
341
|
+
} else {
|
|
342
|
+
newParts.push(Math.ceil(num * ratio * precision) / precision);
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
newParts.push(code);
|
|
346
|
+
}
|
|
347
|
+
code = oldParts.shift();
|
|
348
|
+
if (code === void 0) {
|
|
349
|
+
return newParts.join("");
|
|
350
|
+
}
|
|
351
|
+
isNumber = !isNumber;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const isUnsetKeyword = (value) => value === "unset" || value === "undefined" || value === "none";
|
|
356
|
+
function iconToSVG(icon, customisations) {
|
|
357
|
+
const fullIcon = {
|
|
358
|
+
...defaultIconProps,
|
|
359
|
+
...icon
|
|
360
|
+
};
|
|
361
|
+
const fullCustomisations = {
|
|
362
|
+
...defaultIconCustomisations,
|
|
363
|
+
...customisations
|
|
364
|
+
};
|
|
365
|
+
const box = {
|
|
366
|
+
left: fullIcon.left,
|
|
367
|
+
top: fullIcon.top,
|
|
368
|
+
width: fullIcon.width,
|
|
369
|
+
height: fullIcon.height
|
|
370
|
+
};
|
|
371
|
+
let body = fullIcon.body;
|
|
372
|
+
[fullIcon, fullCustomisations].forEach((props) => {
|
|
373
|
+
const transformations = [];
|
|
374
|
+
const hFlip = props.hFlip;
|
|
375
|
+
const vFlip = props.vFlip;
|
|
376
|
+
let rotation = props.rotate;
|
|
377
|
+
if (hFlip) {
|
|
378
|
+
if (vFlip) {
|
|
379
|
+
rotation += 2;
|
|
380
|
+
} else {
|
|
381
|
+
transformations.push(
|
|
382
|
+
"translate(" + (box.width + box.left).toString() + " " + (0 - box.top).toString() + ")"
|
|
383
|
+
);
|
|
384
|
+
transformations.push("scale(-1 1)");
|
|
385
|
+
box.top = box.left = 0;
|
|
386
|
+
}
|
|
387
|
+
} else if (vFlip) {
|
|
388
|
+
transformations.push(
|
|
389
|
+
"translate(" + (0 - box.left).toString() + " " + (box.height + box.top).toString() + ")"
|
|
390
|
+
);
|
|
391
|
+
transformations.push("scale(1 -1)");
|
|
392
|
+
box.top = box.left = 0;
|
|
393
|
+
}
|
|
394
|
+
let tempValue;
|
|
395
|
+
if (rotation < 0) {
|
|
396
|
+
rotation -= Math.floor(rotation / 4) * 4;
|
|
397
|
+
}
|
|
398
|
+
rotation = rotation % 4;
|
|
399
|
+
switch (rotation) {
|
|
400
|
+
case 1:
|
|
401
|
+
tempValue = box.height / 2 + box.top;
|
|
402
|
+
transformations.unshift(
|
|
403
|
+
"rotate(90 " + tempValue.toString() + " " + tempValue.toString() + ")"
|
|
404
|
+
);
|
|
405
|
+
break;
|
|
406
|
+
case 2:
|
|
407
|
+
transformations.unshift(
|
|
408
|
+
"rotate(180 " + (box.width / 2 + box.left).toString() + " " + (box.height / 2 + box.top).toString() + ")"
|
|
409
|
+
);
|
|
410
|
+
break;
|
|
411
|
+
case 3:
|
|
412
|
+
tempValue = box.width / 2 + box.left;
|
|
413
|
+
transformations.unshift(
|
|
414
|
+
"rotate(-90 " + tempValue.toString() + " " + tempValue.toString() + ")"
|
|
415
|
+
);
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
if (rotation % 2 === 1) {
|
|
419
|
+
if (box.left !== box.top) {
|
|
420
|
+
tempValue = box.left;
|
|
421
|
+
box.left = box.top;
|
|
422
|
+
box.top = tempValue;
|
|
423
|
+
}
|
|
424
|
+
if (box.width !== box.height) {
|
|
425
|
+
tempValue = box.width;
|
|
426
|
+
box.width = box.height;
|
|
427
|
+
box.height = tempValue;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (transformations.length) {
|
|
431
|
+
body = '<g transform="' + transformations.join(" ") + '">' + body + "</g>";
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
const customisationsWidth = fullCustomisations.width;
|
|
435
|
+
const customisationsHeight = fullCustomisations.height;
|
|
436
|
+
const boxWidth = box.width;
|
|
437
|
+
const boxHeight = box.height;
|
|
438
|
+
let width;
|
|
439
|
+
let height;
|
|
440
|
+
if (customisationsWidth === null) {
|
|
441
|
+
height = customisationsHeight === null ? "1em" : customisationsHeight === "auto" ? boxHeight : customisationsHeight;
|
|
442
|
+
width = calculateSize(height, boxWidth / boxHeight);
|
|
443
|
+
} else {
|
|
444
|
+
width = customisationsWidth === "auto" ? boxWidth : customisationsWidth;
|
|
445
|
+
height = customisationsHeight === null ? calculateSize(width, boxHeight / boxWidth) : customisationsHeight === "auto" ? boxHeight : customisationsHeight;
|
|
446
|
+
}
|
|
447
|
+
const attributes = {};
|
|
448
|
+
const setAttr = (prop, value) => {
|
|
449
|
+
if (!isUnsetKeyword(value)) {
|
|
450
|
+
attributes[prop] = value.toString();
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
setAttr("width", width);
|
|
454
|
+
setAttr("height", height);
|
|
455
|
+
attributes.viewBox = box.left.toString() + " " + box.top.toString() + " " + boxWidth.toString() + " " + boxHeight.toString();
|
|
456
|
+
return {
|
|
457
|
+
attributes,
|
|
458
|
+
body
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const regex = /\sid="(\S+)"/g;
|
|
463
|
+
const randomPrefix = "IconifyId" + Date.now().toString(16) + (Math.random() * 16777216 | 0).toString(16);
|
|
464
|
+
let counter = 0;
|
|
465
|
+
function replaceIDs(body, prefix = randomPrefix) {
|
|
466
|
+
const ids = [];
|
|
467
|
+
let match;
|
|
468
|
+
while (match = regex.exec(body)) {
|
|
469
|
+
ids.push(match[1]);
|
|
470
|
+
}
|
|
471
|
+
if (!ids.length) {
|
|
472
|
+
return body;
|
|
473
|
+
}
|
|
474
|
+
const suffix = "suffix" + (Math.random() * 16777216 | Date.now()).toString(16);
|
|
475
|
+
ids.forEach((id) => {
|
|
476
|
+
const newID = typeof prefix === "function" ? prefix(id) : prefix + (counter++).toString();
|
|
477
|
+
const escapedID = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
478
|
+
body = body.replace(
|
|
479
|
+
// Allowed characters before id: [#;"]
|
|
480
|
+
// Allowed characters after id: [)"], .[a-z]
|
|
481
|
+
new RegExp('([#;"])(' + escapedID + ')([")]|\\.[a-z])', "g"),
|
|
482
|
+
"$1" + newID + suffix + "$3"
|
|
483
|
+
);
|
|
484
|
+
});
|
|
485
|
+
body = body.replace(new RegExp(suffix, "g"), "");
|
|
486
|
+
return body;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const storage = /* @__PURE__ */ Object.create(null);
|
|
490
|
+
function setAPIModule(provider, item) {
|
|
491
|
+
storage[provider] = item;
|
|
492
|
+
}
|
|
493
|
+
function getAPIModule(provider) {
|
|
494
|
+
return storage[provider] || storage[""];
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function createAPIConfig(source) {
|
|
498
|
+
let resources;
|
|
499
|
+
if (typeof source.resources === "string") {
|
|
500
|
+
resources = [source.resources];
|
|
501
|
+
} else {
|
|
502
|
+
resources = source.resources;
|
|
503
|
+
if (!(resources instanceof Array) || !resources.length) {
|
|
504
|
+
return null;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
const result = {
|
|
508
|
+
// API hosts
|
|
509
|
+
resources,
|
|
510
|
+
// Root path
|
|
511
|
+
path: source.path || "/",
|
|
512
|
+
// URL length limit
|
|
513
|
+
maxURL: source.maxURL || 500,
|
|
514
|
+
// Timeout before next host is used.
|
|
515
|
+
rotate: source.rotate || 750,
|
|
516
|
+
// Timeout before failing query.
|
|
517
|
+
timeout: source.timeout || 5e3,
|
|
518
|
+
// Randomise default API end point.
|
|
519
|
+
random: source.random === true,
|
|
520
|
+
// Start index
|
|
521
|
+
index: source.index || 0,
|
|
522
|
+
// Receive data after time out (used if time out kicks in first, then API module sends data anyway).
|
|
523
|
+
dataAfterTimeout: source.dataAfterTimeout !== false
|
|
524
|
+
};
|
|
525
|
+
return result;
|
|
526
|
+
}
|
|
527
|
+
const configStorage = /* @__PURE__ */ Object.create(null);
|
|
528
|
+
const fallBackAPISources = [
|
|
529
|
+
"https://api.simplesvg.com",
|
|
530
|
+
"https://api.unisvg.com"
|
|
531
|
+
];
|
|
532
|
+
const fallBackAPI = [];
|
|
533
|
+
while (fallBackAPISources.length > 0) {
|
|
534
|
+
if (fallBackAPISources.length === 1) {
|
|
535
|
+
fallBackAPI.push(fallBackAPISources.shift());
|
|
536
|
+
} else {
|
|
537
|
+
if (Math.random() > 0.5) {
|
|
538
|
+
fallBackAPI.push(fallBackAPISources.shift());
|
|
539
|
+
} else {
|
|
540
|
+
fallBackAPI.push(fallBackAPISources.pop());
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
configStorage[""] = createAPIConfig({
|
|
545
|
+
resources: ["https://api.iconify.design"].concat(fallBackAPI)
|
|
546
|
+
});
|
|
547
|
+
function addAPIProvider(provider, customConfig) {
|
|
548
|
+
const config = createAPIConfig(customConfig);
|
|
549
|
+
if (config === null) {
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
configStorage[provider] = config;
|
|
553
|
+
return true;
|
|
554
|
+
}
|
|
555
|
+
function getAPIConfig(provider) {
|
|
556
|
+
return configStorage[provider];
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
const detectFetch = () => {
|
|
560
|
+
let callback;
|
|
561
|
+
try {
|
|
562
|
+
callback = fetch;
|
|
563
|
+
if (typeof callback === "function") {
|
|
564
|
+
return callback;
|
|
565
|
+
}
|
|
566
|
+
} catch (err) {
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
let fetchModule = detectFetch();
|
|
570
|
+
function calculateMaxLength(provider, prefix) {
|
|
571
|
+
const config = getAPIConfig(provider);
|
|
572
|
+
if (!config) {
|
|
573
|
+
return 0;
|
|
574
|
+
}
|
|
575
|
+
let result;
|
|
576
|
+
if (!config.maxURL) {
|
|
577
|
+
result = 0;
|
|
578
|
+
} else {
|
|
579
|
+
let maxHostLength = 0;
|
|
580
|
+
config.resources.forEach((item) => {
|
|
581
|
+
const host = item;
|
|
582
|
+
maxHostLength = Math.max(maxHostLength, host.length);
|
|
583
|
+
});
|
|
584
|
+
const url = prefix + ".json?icons=";
|
|
585
|
+
result = config.maxURL - maxHostLength - config.path.length - url.length;
|
|
586
|
+
}
|
|
587
|
+
return result;
|
|
588
|
+
}
|
|
589
|
+
function shouldAbort(status) {
|
|
590
|
+
return status === 404;
|
|
591
|
+
}
|
|
592
|
+
const prepare = (provider, prefix, icons) => {
|
|
593
|
+
const results = [];
|
|
594
|
+
const maxLength = calculateMaxLength(provider, prefix);
|
|
595
|
+
const type = "icons";
|
|
596
|
+
let item = {
|
|
597
|
+
type,
|
|
598
|
+
provider,
|
|
599
|
+
prefix,
|
|
600
|
+
icons: []
|
|
601
|
+
};
|
|
602
|
+
let length = 0;
|
|
603
|
+
icons.forEach((name, index) => {
|
|
604
|
+
length += name.length + 1;
|
|
605
|
+
if (length >= maxLength && index > 0) {
|
|
606
|
+
results.push(item);
|
|
607
|
+
item = {
|
|
608
|
+
type,
|
|
609
|
+
provider,
|
|
610
|
+
prefix,
|
|
611
|
+
icons: []
|
|
612
|
+
};
|
|
613
|
+
length = name.length;
|
|
614
|
+
}
|
|
615
|
+
item.icons.push(name);
|
|
616
|
+
});
|
|
617
|
+
results.push(item);
|
|
618
|
+
return results;
|
|
619
|
+
};
|
|
620
|
+
function getPath(provider) {
|
|
621
|
+
if (typeof provider === "string") {
|
|
622
|
+
const config = getAPIConfig(provider);
|
|
623
|
+
if (config) {
|
|
624
|
+
return config.path;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
return "/";
|
|
628
|
+
}
|
|
629
|
+
const send = (host, params, callback) => {
|
|
630
|
+
if (!fetchModule) {
|
|
631
|
+
callback("abort", 424);
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
let path = getPath(params.provider);
|
|
635
|
+
switch (params.type) {
|
|
636
|
+
case "icons": {
|
|
637
|
+
const prefix = params.prefix;
|
|
638
|
+
const icons = params.icons;
|
|
639
|
+
const iconsList = icons.join(",");
|
|
640
|
+
const urlParams = new URLSearchParams({
|
|
641
|
+
icons: iconsList
|
|
642
|
+
});
|
|
643
|
+
path += prefix + ".json?" + urlParams.toString();
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
case "custom": {
|
|
647
|
+
const uri = params.uri;
|
|
648
|
+
path += uri.slice(0, 1) === "/" ? uri.slice(1) : uri;
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
default:
|
|
652
|
+
callback("abort", 400);
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
let defaultError = 503;
|
|
656
|
+
fetchModule(host + path).then((response) => {
|
|
657
|
+
const status = response.status;
|
|
658
|
+
if (status !== 200) {
|
|
659
|
+
setTimeout(() => {
|
|
660
|
+
callback(shouldAbort(status) ? "abort" : "next", status);
|
|
661
|
+
});
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
defaultError = 501;
|
|
665
|
+
return response.json();
|
|
666
|
+
}).then((data) => {
|
|
667
|
+
if (typeof data !== "object" || data === null) {
|
|
668
|
+
setTimeout(() => {
|
|
669
|
+
if (data === 404) {
|
|
670
|
+
callback("abort", data);
|
|
671
|
+
} else {
|
|
672
|
+
callback("next", defaultError);
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
setTimeout(() => {
|
|
678
|
+
callback("success", data);
|
|
679
|
+
});
|
|
680
|
+
}).catch(() => {
|
|
681
|
+
callback("next", defaultError);
|
|
682
|
+
});
|
|
683
|
+
};
|
|
684
|
+
const fetchAPIModule = {
|
|
685
|
+
prepare,
|
|
686
|
+
send
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
function sortIcons(icons) {
|
|
690
|
+
const result = {
|
|
691
|
+
loaded: [],
|
|
692
|
+
missing: [],
|
|
693
|
+
pending: []
|
|
694
|
+
};
|
|
695
|
+
const storage = /* @__PURE__ */ Object.create(null);
|
|
696
|
+
icons.sort((a, b) => {
|
|
697
|
+
if (a.provider !== b.provider) {
|
|
698
|
+
return a.provider.localeCompare(b.provider);
|
|
699
|
+
}
|
|
700
|
+
if (a.prefix !== b.prefix) {
|
|
701
|
+
return a.prefix.localeCompare(b.prefix);
|
|
702
|
+
}
|
|
703
|
+
return a.name.localeCompare(b.name);
|
|
704
|
+
});
|
|
705
|
+
let lastIcon = {
|
|
706
|
+
provider: "",
|
|
707
|
+
prefix: "",
|
|
708
|
+
name: ""
|
|
709
|
+
};
|
|
710
|
+
icons.forEach((icon) => {
|
|
711
|
+
if (lastIcon.name === icon.name && lastIcon.prefix === icon.prefix && lastIcon.provider === icon.provider) {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
lastIcon = icon;
|
|
715
|
+
const provider = icon.provider;
|
|
716
|
+
const prefix = icon.prefix;
|
|
717
|
+
const name = icon.name;
|
|
718
|
+
const providerStorage = storage[provider] || (storage[provider] = /* @__PURE__ */ Object.create(null));
|
|
719
|
+
const localStorage = providerStorage[prefix] || (providerStorage[prefix] = getStorage(provider, prefix));
|
|
720
|
+
let list;
|
|
721
|
+
if (name in localStorage.icons) {
|
|
722
|
+
list = result.loaded;
|
|
723
|
+
} else if (prefix === "" || localStorage.missing.has(name)) {
|
|
724
|
+
list = result.missing;
|
|
725
|
+
} else {
|
|
726
|
+
list = result.pending;
|
|
727
|
+
}
|
|
728
|
+
const item = {
|
|
729
|
+
provider,
|
|
730
|
+
prefix,
|
|
731
|
+
name
|
|
732
|
+
};
|
|
733
|
+
list.push(item);
|
|
734
|
+
});
|
|
735
|
+
return result;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
function removeCallback(storages, id) {
|
|
739
|
+
storages.forEach((storage) => {
|
|
740
|
+
const items = storage.loaderCallbacks;
|
|
741
|
+
if (items) {
|
|
742
|
+
storage.loaderCallbacks = items.filter((row) => row.id !== id);
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
function updateCallbacks(storage) {
|
|
747
|
+
if (!storage.pendingCallbacksFlag) {
|
|
748
|
+
storage.pendingCallbacksFlag = true;
|
|
749
|
+
setTimeout(() => {
|
|
750
|
+
storage.pendingCallbacksFlag = false;
|
|
751
|
+
const items = storage.loaderCallbacks ? storage.loaderCallbacks.slice(0) : [];
|
|
752
|
+
if (!items.length) {
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
let hasPending = false;
|
|
756
|
+
const provider = storage.provider;
|
|
757
|
+
const prefix = storage.prefix;
|
|
758
|
+
items.forEach((item) => {
|
|
759
|
+
const icons = item.icons;
|
|
760
|
+
const oldLength = icons.pending.length;
|
|
761
|
+
icons.pending = icons.pending.filter((icon) => {
|
|
762
|
+
if (icon.prefix !== prefix) {
|
|
763
|
+
return true;
|
|
764
|
+
}
|
|
765
|
+
const name = icon.name;
|
|
766
|
+
if (storage.icons[name]) {
|
|
767
|
+
icons.loaded.push({
|
|
768
|
+
provider,
|
|
769
|
+
prefix,
|
|
770
|
+
name
|
|
771
|
+
});
|
|
772
|
+
} else if (storage.missing.has(name)) {
|
|
773
|
+
icons.missing.push({
|
|
774
|
+
provider,
|
|
775
|
+
prefix,
|
|
776
|
+
name
|
|
777
|
+
});
|
|
778
|
+
} else {
|
|
779
|
+
hasPending = true;
|
|
780
|
+
return true;
|
|
781
|
+
}
|
|
782
|
+
return false;
|
|
783
|
+
});
|
|
784
|
+
if (icons.pending.length !== oldLength) {
|
|
785
|
+
if (!hasPending) {
|
|
786
|
+
removeCallback([storage], item.id);
|
|
787
|
+
}
|
|
788
|
+
item.callback(
|
|
789
|
+
icons.loaded.slice(0),
|
|
790
|
+
icons.missing.slice(0),
|
|
791
|
+
icons.pending.slice(0),
|
|
792
|
+
item.abort
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
let idCounter = 0;
|
|
800
|
+
function storeCallback(callback, icons, pendingSources) {
|
|
801
|
+
const id = idCounter++;
|
|
802
|
+
const abort = removeCallback.bind(null, pendingSources, id);
|
|
803
|
+
if (!icons.pending.length) {
|
|
804
|
+
return abort;
|
|
805
|
+
}
|
|
806
|
+
const item = {
|
|
807
|
+
id,
|
|
808
|
+
icons,
|
|
809
|
+
callback,
|
|
810
|
+
abort
|
|
811
|
+
};
|
|
812
|
+
pendingSources.forEach((storage) => {
|
|
813
|
+
(storage.loaderCallbacks || (storage.loaderCallbacks = [])).push(item);
|
|
814
|
+
});
|
|
815
|
+
return abort;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
function listToIcons(list, validate = true, simpleNames = false) {
|
|
819
|
+
const result = [];
|
|
820
|
+
list.forEach((item) => {
|
|
821
|
+
const icon = typeof item === "string" ? stringToIcon(item, validate, simpleNames) : item;
|
|
822
|
+
if (icon) {
|
|
823
|
+
result.push(icon);
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
return result;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// src/config.ts
|
|
830
|
+
var defaultConfig = {
|
|
831
|
+
resources: [],
|
|
832
|
+
index: 0,
|
|
833
|
+
timeout: 2e3,
|
|
834
|
+
rotate: 750,
|
|
835
|
+
random: false,
|
|
836
|
+
dataAfterTimeout: false
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
// src/query.ts
|
|
840
|
+
function sendQuery(config, payload, query, done) {
|
|
841
|
+
const resourcesCount = config.resources.length;
|
|
842
|
+
const startIndex = config.random ? Math.floor(Math.random() * resourcesCount) : config.index;
|
|
843
|
+
let resources;
|
|
844
|
+
if (config.random) {
|
|
845
|
+
let list = config.resources.slice(0);
|
|
846
|
+
resources = [];
|
|
847
|
+
while (list.length > 1) {
|
|
848
|
+
const nextIndex = Math.floor(Math.random() * list.length);
|
|
849
|
+
resources.push(list[nextIndex]);
|
|
850
|
+
list = list.slice(0, nextIndex).concat(list.slice(nextIndex + 1));
|
|
851
|
+
}
|
|
852
|
+
resources = resources.concat(list);
|
|
853
|
+
} else {
|
|
854
|
+
resources = config.resources.slice(startIndex).concat(config.resources.slice(0, startIndex));
|
|
855
|
+
}
|
|
856
|
+
const startTime = Date.now();
|
|
857
|
+
let status = "pending";
|
|
858
|
+
let queriesSent = 0;
|
|
859
|
+
let lastError;
|
|
860
|
+
let timer = null;
|
|
861
|
+
let queue = [];
|
|
862
|
+
let doneCallbacks = [];
|
|
863
|
+
if (typeof done === "function") {
|
|
864
|
+
doneCallbacks.push(done);
|
|
865
|
+
}
|
|
866
|
+
function resetTimer() {
|
|
867
|
+
if (timer) {
|
|
868
|
+
clearTimeout(timer);
|
|
869
|
+
timer = null;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
function abort() {
|
|
873
|
+
if (status === "pending") {
|
|
874
|
+
status = "aborted";
|
|
875
|
+
}
|
|
876
|
+
resetTimer();
|
|
877
|
+
queue.forEach((item) => {
|
|
878
|
+
if (item.status === "pending") {
|
|
879
|
+
item.status = "aborted";
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
queue = [];
|
|
883
|
+
}
|
|
884
|
+
function subscribe(callback, overwrite) {
|
|
885
|
+
if (overwrite) {
|
|
886
|
+
doneCallbacks = [];
|
|
887
|
+
}
|
|
888
|
+
if (typeof callback === "function") {
|
|
889
|
+
doneCallbacks.push(callback);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
function getQueryStatus() {
|
|
893
|
+
return {
|
|
894
|
+
startTime,
|
|
895
|
+
payload,
|
|
896
|
+
status,
|
|
897
|
+
queriesSent,
|
|
898
|
+
queriesPending: queue.length,
|
|
899
|
+
subscribe,
|
|
900
|
+
abort
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
function failQuery() {
|
|
904
|
+
status = "failed";
|
|
905
|
+
doneCallbacks.forEach((callback) => {
|
|
906
|
+
callback(void 0, lastError);
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
function clearQueue() {
|
|
910
|
+
queue.forEach((item) => {
|
|
911
|
+
if (item.status === "pending") {
|
|
912
|
+
item.status = "aborted";
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
queue = [];
|
|
916
|
+
}
|
|
917
|
+
function moduleResponse(item, response, data) {
|
|
918
|
+
const isError = response !== "success";
|
|
919
|
+
queue = queue.filter((queued) => queued !== item);
|
|
920
|
+
switch (status) {
|
|
921
|
+
case "pending":
|
|
922
|
+
break;
|
|
923
|
+
case "failed":
|
|
924
|
+
if (isError || !config.dataAfterTimeout) {
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
break;
|
|
928
|
+
default:
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
if (response === "abort") {
|
|
932
|
+
lastError = data;
|
|
933
|
+
failQuery();
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
if (isError) {
|
|
937
|
+
lastError = data;
|
|
938
|
+
if (!queue.length) {
|
|
939
|
+
if (!resources.length) {
|
|
940
|
+
failQuery();
|
|
941
|
+
} else {
|
|
942
|
+
execNext();
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
resetTimer();
|
|
948
|
+
clearQueue();
|
|
949
|
+
if (!config.random) {
|
|
950
|
+
const index = config.resources.indexOf(item.resource);
|
|
951
|
+
if (index !== -1 && index !== config.index) {
|
|
952
|
+
config.index = index;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
status = "completed";
|
|
956
|
+
doneCallbacks.forEach((callback) => {
|
|
957
|
+
callback(data);
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
function execNext() {
|
|
961
|
+
if (status !== "pending") {
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
resetTimer();
|
|
965
|
+
const resource = resources.shift();
|
|
966
|
+
if (resource === void 0) {
|
|
967
|
+
if (queue.length) {
|
|
968
|
+
timer = setTimeout(() => {
|
|
969
|
+
resetTimer();
|
|
970
|
+
if (status === "pending") {
|
|
971
|
+
clearQueue();
|
|
972
|
+
failQuery();
|
|
973
|
+
}
|
|
974
|
+
}, config.timeout);
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
failQuery();
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
const item = {
|
|
981
|
+
status: "pending",
|
|
982
|
+
resource,
|
|
983
|
+
callback: (status2, data) => {
|
|
984
|
+
moduleResponse(item, status2, data);
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
queue.push(item);
|
|
988
|
+
queriesSent++;
|
|
989
|
+
timer = setTimeout(execNext, config.rotate);
|
|
990
|
+
query(resource, payload, item.callback);
|
|
991
|
+
}
|
|
992
|
+
setTimeout(execNext);
|
|
993
|
+
return getQueryStatus;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// src/index.ts
|
|
997
|
+
function initRedundancy(cfg) {
|
|
998
|
+
const config = {
|
|
999
|
+
...defaultConfig,
|
|
1000
|
+
...cfg
|
|
1001
|
+
};
|
|
1002
|
+
let queries = [];
|
|
1003
|
+
function cleanup() {
|
|
1004
|
+
queries = queries.filter((item) => item().status === "pending");
|
|
1005
|
+
}
|
|
1006
|
+
function query(payload, queryCallback, doneCallback) {
|
|
1007
|
+
const query2 = sendQuery(
|
|
1008
|
+
config,
|
|
1009
|
+
payload,
|
|
1010
|
+
queryCallback,
|
|
1011
|
+
(data, error) => {
|
|
1012
|
+
cleanup();
|
|
1013
|
+
if (doneCallback) {
|
|
1014
|
+
doneCallback(data, error);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
);
|
|
1018
|
+
queries.push(query2);
|
|
1019
|
+
return query2;
|
|
1020
|
+
}
|
|
1021
|
+
function find(callback) {
|
|
1022
|
+
return queries.find((value) => {
|
|
1023
|
+
return callback(value);
|
|
1024
|
+
}) || null;
|
|
1025
|
+
}
|
|
1026
|
+
const instance = {
|
|
1027
|
+
query,
|
|
1028
|
+
find,
|
|
1029
|
+
setIndex: (index) => {
|
|
1030
|
+
config.index = index;
|
|
1031
|
+
},
|
|
1032
|
+
getIndex: () => config.index,
|
|
1033
|
+
cleanup
|
|
1034
|
+
};
|
|
1035
|
+
return instance;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
function emptyCallback$1() {
|
|
1039
|
+
}
|
|
1040
|
+
const redundancyCache = /* @__PURE__ */ Object.create(null);
|
|
1041
|
+
function getRedundancyCache(provider) {
|
|
1042
|
+
if (!redundancyCache[provider]) {
|
|
1043
|
+
const config = getAPIConfig(provider);
|
|
1044
|
+
if (!config) {
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
const redundancy = initRedundancy(config);
|
|
1048
|
+
const cachedReundancy = {
|
|
1049
|
+
config,
|
|
1050
|
+
redundancy
|
|
1051
|
+
};
|
|
1052
|
+
redundancyCache[provider] = cachedReundancy;
|
|
1053
|
+
}
|
|
1054
|
+
return redundancyCache[provider];
|
|
1055
|
+
}
|
|
1056
|
+
function sendAPIQuery(target, query, callback) {
|
|
1057
|
+
let redundancy;
|
|
1058
|
+
let send;
|
|
1059
|
+
if (typeof target === "string") {
|
|
1060
|
+
const api = getAPIModule(target);
|
|
1061
|
+
if (!api) {
|
|
1062
|
+
callback(void 0, 424);
|
|
1063
|
+
return emptyCallback$1;
|
|
1064
|
+
}
|
|
1065
|
+
send = api.send;
|
|
1066
|
+
const cached = getRedundancyCache(target);
|
|
1067
|
+
if (cached) {
|
|
1068
|
+
redundancy = cached.redundancy;
|
|
1069
|
+
}
|
|
1070
|
+
} else {
|
|
1071
|
+
const config = createAPIConfig(target);
|
|
1072
|
+
if (config) {
|
|
1073
|
+
redundancy = initRedundancy(config);
|
|
1074
|
+
const moduleKey = target.resources ? target.resources[0] : "";
|
|
1075
|
+
const api = getAPIModule(moduleKey);
|
|
1076
|
+
if (api) {
|
|
1077
|
+
send = api.send;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
if (!redundancy || !send) {
|
|
1082
|
+
callback(void 0, 424);
|
|
1083
|
+
return emptyCallback$1;
|
|
1084
|
+
}
|
|
1085
|
+
return redundancy.query(query, send, callback)().abort;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
const browserCacheVersion = "iconify2";
|
|
1089
|
+
const browserCachePrefix = "iconify";
|
|
1090
|
+
const browserCacheCountKey = browserCachePrefix + "-count";
|
|
1091
|
+
const browserCacheVersionKey = browserCachePrefix + "-version";
|
|
1092
|
+
const browserStorageHour = 36e5;
|
|
1093
|
+
const browserStorageCacheExpiration = 168;
|
|
1094
|
+
|
|
1095
|
+
function getStoredItem(func, key) {
|
|
1096
|
+
try {
|
|
1097
|
+
return func.getItem(key);
|
|
1098
|
+
} catch (err) {
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
function setStoredItem(func, key, value) {
|
|
1102
|
+
try {
|
|
1103
|
+
func.setItem(key, value);
|
|
1104
|
+
return true;
|
|
1105
|
+
} catch (err) {
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
function removeStoredItem(func, key) {
|
|
1109
|
+
try {
|
|
1110
|
+
func.removeItem(key);
|
|
1111
|
+
} catch (err) {
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
function setBrowserStorageItemsCount(storage, value) {
|
|
1116
|
+
return setStoredItem(storage, browserCacheCountKey, value.toString());
|
|
1117
|
+
}
|
|
1118
|
+
function getBrowserStorageItemsCount(storage) {
|
|
1119
|
+
return parseInt(getStoredItem(storage, browserCacheCountKey)) || 0;
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
const browserStorageConfig = {
|
|
1123
|
+
local: true,
|
|
1124
|
+
session: true
|
|
1125
|
+
};
|
|
1126
|
+
const browserStorageEmptyItems = {
|
|
1127
|
+
local: /* @__PURE__ */ new Set(),
|
|
1128
|
+
session: /* @__PURE__ */ new Set()
|
|
1129
|
+
};
|
|
1130
|
+
let browserStorageStatus = false;
|
|
1131
|
+
function setBrowserStorageStatus(status) {
|
|
1132
|
+
browserStorageStatus = status;
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
let _window = typeof window === "undefined" ? {} : window;
|
|
1136
|
+
function getBrowserStorage(key) {
|
|
1137
|
+
const attr = key + "Storage";
|
|
1138
|
+
try {
|
|
1139
|
+
if (_window && _window[attr] && typeof _window[attr].length === "number") {
|
|
1140
|
+
return _window[attr];
|
|
1141
|
+
}
|
|
1142
|
+
} catch (err) {
|
|
1143
|
+
}
|
|
1144
|
+
browserStorageConfig[key] = false;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
function iterateBrowserStorage(key, callback) {
|
|
1148
|
+
const func = getBrowserStorage(key);
|
|
1149
|
+
if (!func) {
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
const version = getStoredItem(func, browserCacheVersionKey);
|
|
1153
|
+
if (version !== browserCacheVersion) {
|
|
1154
|
+
if (version) {
|
|
1155
|
+
const total2 = getBrowserStorageItemsCount(func);
|
|
1156
|
+
for (let i = 0; i < total2; i++) {
|
|
1157
|
+
removeStoredItem(func, browserCachePrefix + i.toString());
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
setStoredItem(func, browserCacheVersionKey, browserCacheVersion);
|
|
1161
|
+
setBrowserStorageItemsCount(func, 0);
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
const minTime = Math.floor(Date.now() / browserStorageHour) - browserStorageCacheExpiration;
|
|
1165
|
+
const parseItem = (index) => {
|
|
1166
|
+
const name = browserCachePrefix + index.toString();
|
|
1167
|
+
const item = getStoredItem(func, name);
|
|
1168
|
+
if (typeof item !== "string") {
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
try {
|
|
1172
|
+
const data = JSON.parse(item);
|
|
1173
|
+
if (typeof data === "object" && typeof data.cached === "number" && data.cached > minTime && typeof data.provider === "string" && typeof data.data === "object" && typeof data.data.prefix === "string" && // Valid item: run callback
|
|
1174
|
+
callback(data, index)) {
|
|
1175
|
+
return true;
|
|
1176
|
+
}
|
|
1177
|
+
} catch (err) {
|
|
1178
|
+
}
|
|
1179
|
+
removeStoredItem(func, name);
|
|
1180
|
+
};
|
|
1181
|
+
let total = getBrowserStorageItemsCount(func);
|
|
1182
|
+
for (let i = total - 1; i >= 0; i--) {
|
|
1183
|
+
if (!parseItem(i)) {
|
|
1184
|
+
if (i === total - 1) {
|
|
1185
|
+
total--;
|
|
1186
|
+
setBrowserStorageItemsCount(func, total);
|
|
1187
|
+
} else {
|
|
1188
|
+
browserStorageEmptyItems[key].add(i);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
function initBrowserStorage() {
|
|
1195
|
+
if (browserStorageStatus) {
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
setBrowserStorageStatus(true);
|
|
1199
|
+
for (const key in browserStorageConfig) {
|
|
1200
|
+
iterateBrowserStorage(key, (item) => {
|
|
1201
|
+
const iconSet = item.data;
|
|
1202
|
+
const provider = item.provider;
|
|
1203
|
+
const prefix = iconSet.prefix;
|
|
1204
|
+
const storage = getStorage(
|
|
1205
|
+
provider,
|
|
1206
|
+
prefix
|
|
1207
|
+
);
|
|
1208
|
+
if (!addIconSet(storage, iconSet).length) {
|
|
1209
|
+
return false;
|
|
1210
|
+
}
|
|
1211
|
+
const lastModified = iconSet.lastModified || -1;
|
|
1212
|
+
storage.lastModifiedCached = storage.lastModifiedCached ? Math.min(storage.lastModifiedCached, lastModified) : lastModified;
|
|
1213
|
+
return true;
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
function updateLastModified(storage, lastModified) {
|
|
1219
|
+
const lastValue = storage.lastModifiedCached;
|
|
1220
|
+
if (
|
|
1221
|
+
// Matches or newer
|
|
1222
|
+
lastValue && lastValue >= lastModified
|
|
1223
|
+
) {
|
|
1224
|
+
return lastValue === lastModified;
|
|
1225
|
+
}
|
|
1226
|
+
storage.lastModifiedCached = lastModified;
|
|
1227
|
+
if (lastValue) {
|
|
1228
|
+
for (const key in browserStorageConfig) {
|
|
1229
|
+
iterateBrowserStorage(key, (item) => {
|
|
1230
|
+
const iconSet = item.data;
|
|
1231
|
+
return item.provider !== storage.provider || iconSet.prefix !== storage.prefix || iconSet.lastModified === lastModified;
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
return true;
|
|
1236
|
+
}
|
|
1237
|
+
function storeInBrowserStorage(storage, data) {
|
|
1238
|
+
if (!browserStorageStatus) {
|
|
1239
|
+
initBrowserStorage();
|
|
1240
|
+
}
|
|
1241
|
+
function store(key) {
|
|
1242
|
+
let func;
|
|
1243
|
+
if (!browserStorageConfig[key] || !(func = getBrowserStorage(key))) {
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
const set = browserStorageEmptyItems[key];
|
|
1247
|
+
let index;
|
|
1248
|
+
if (set.size) {
|
|
1249
|
+
set.delete(index = Array.from(set).shift());
|
|
1250
|
+
} else {
|
|
1251
|
+
index = getBrowserStorageItemsCount(func);
|
|
1252
|
+
if (!setBrowserStorageItemsCount(func, index + 1)) {
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
const item = {
|
|
1257
|
+
cached: Math.floor(Date.now() / browserStorageHour),
|
|
1258
|
+
provider: storage.provider,
|
|
1259
|
+
data
|
|
1260
|
+
};
|
|
1261
|
+
return setStoredItem(
|
|
1262
|
+
func,
|
|
1263
|
+
browserCachePrefix + index.toString(),
|
|
1264
|
+
JSON.stringify(item)
|
|
1265
|
+
);
|
|
1266
|
+
}
|
|
1267
|
+
if (data.lastModified && !updateLastModified(storage, data.lastModified)) {
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1270
|
+
if (!Object.keys(data.icons).length) {
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
if (data.not_found) {
|
|
1274
|
+
data = Object.assign({}, data);
|
|
1275
|
+
delete data.not_found;
|
|
1276
|
+
}
|
|
1277
|
+
if (!store("local")) {
|
|
1278
|
+
store("session");
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
function emptyCallback() {
|
|
1283
|
+
}
|
|
1284
|
+
function loadedNewIcons(storage) {
|
|
1285
|
+
if (!storage.iconsLoaderFlag) {
|
|
1286
|
+
storage.iconsLoaderFlag = true;
|
|
1287
|
+
setTimeout(() => {
|
|
1288
|
+
storage.iconsLoaderFlag = false;
|
|
1289
|
+
updateCallbacks(storage);
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
function loadNewIcons(storage, icons) {
|
|
1294
|
+
if (!storage.iconsToLoad) {
|
|
1295
|
+
storage.iconsToLoad = icons;
|
|
1296
|
+
} else {
|
|
1297
|
+
storage.iconsToLoad = storage.iconsToLoad.concat(icons).sort();
|
|
1298
|
+
}
|
|
1299
|
+
if (!storage.iconsQueueFlag) {
|
|
1300
|
+
storage.iconsQueueFlag = true;
|
|
1301
|
+
setTimeout(() => {
|
|
1302
|
+
storage.iconsQueueFlag = false;
|
|
1303
|
+
const { provider, prefix } = storage;
|
|
1304
|
+
const icons2 = storage.iconsToLoad;
|
|
1305
|
+
delete storage.iconsToLoad;
|
|
1306
|
+
let api;
|
|
1307
|
+
if (!icons2 || !(api = getAPIModule(provider))) {
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
const params = api.prepare(provider, prefix, icons2);
|
|
1311
|
+
params.forEach((item) => {
|
|
1312
|
+
sendAPIQuery(provider, item, (data) => {
|
|
1313
|
+
if (typeof data !== "object") {
|
|
1314
|
+
item.icons.forEach((name) => {
|
|
1315
|
+
storage.missing.add(name);
|
|
1316
|
+
});
|
|
1317
|
+
} else {
|
|
1318
|
+
try {
|
|
1319
|
+
const parsed = addIconSet(
|
|
1320
|
+
storage,
|
|
1321
|
+
data
|
|
1322
|
+
);
|
|
1323
|
+
if (!parsed.length) {
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
const pending = storage.pendingIcons;
|
|
1327
|
+
if (pending) {
|
|
1328
|
+
parsed.forEach((name) => {
|
|
1329
|
+
pending.delete(name);
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
storeInBrowserStorage(storage, data);
|
|
1333
|
+
} catch (err) {
|
|
1334
|
+
console.error(err);
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
loadedNewIcons(storage);
|
|
1338
|
+
});
|
|
1339
|
+
});
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
const loadIcons = (icons, callback) => {
|
|
1344
|
+
const cleanedIcons = listToIcons(icons, true, allowSimpleNames());
|
|
1345
|
+
const sortedIcons = sortIcons(cleanedIcons);
|
|
1346
|
+
if (!sortedIcons.pending.length) {
|
|
1347
|
+
let callCallback = true;
|
|
1348
|
+
if (callback) {
|
|
1349
|
+
setTimeout(() => {
|
|
1350
|
+
if (callCallback) {
|
|
1351
|
+
callback(
|
|
1352
|
+
sortedIcons.loaded,
|
|
1353
|
+
sortedIcons.missing,
|
|
1354
|
+
sortedIcons.pending,
|
|
1355
|
+
emptyCallback
|
|
1356
|
+
);
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
return () => {
|
|
1361
|
+
callCallback = false;
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
const newIcons = /* @__PURE__ */ Object.create(null);
|
|
1365
|
+
const sources = [];
|
|
1366
|
+
let lastProvider, lastPrefix;
|
|
1367
|
+
sortedIcons.pending.forEach((icon) => {
|
|
1368
|
+
const { provider, prefix } = icon;
|
|
1369
|
+
if (prefix === lastPrefix && provider === lastProvider) {
|
|
1370
|
+
return;
|
|
1371
|
+
}
|
|
1372
|
+
lastProvider = provider;
|
|
1373
|
+
lastPrefix = prefix;
|
|
1374
|
+
sources.push(getStorage(provider, prefix));
|
|
1375
|
+
const providerNewIcons = newIcons[provider] || (newIcons[provider] = /* @__PURE__ */ Object.create(null));
|
|
1376
|
+
if (!providerNewIcons[prefix]) {
|
|
1377
|
+
providerNewIcons[prefix] = [];
|
|
1378
|
+
}
|
|
1379
|
+
});
|
|
1380
|
+
sortedIcons.pending.forEach((icon) => {
|
|
1381
|
+
const { provider, prefix, name } = icon;
|
|
1382
|
+
const storage = getStorage(provider, prefix);
|
|
1383
|
+
const pendingQueue = storage.pendingIcons || (storage.pendingIcons = /* @__PURE__ */ new Set());
|
|
1384
|
+
if (!pendingQueue.has(name)) {
|
|
1385
|
+
pendingQueue.add(name);
|
|
1386
|
+
newIcons[provider][prefix].push(name);
|
|
1387
|
+
}
|
|
1388
|
+
});
|
|
1389
|
+
sources.forEach((storage) => {
|
|
1390
|
+
const { provider, prefix } = storage;
|
|
1391
|
+
if (newIcons[provider][prefix].length) {
|
|
1392
|
+
loadNewIcons(storage, newIcons[provider][prefix]);
|
|
1393
|
+
}
|
|
1394
|
+
});
|
|
1395
|
+
return callback ? storeCallback(callback, sortedIcons, sources) : emptyCallback;
|
|
1396
|
+
};
|
|
1397
|
+
|
|
1398
|
+
function mergeCustomisations(defaults, item) {
|
|
1399
|
+
const result = {
|
|
1400
|
+
...defaults
|
|
1401
|
+
};
|
|
1402
|
+
for (const key in item) {
|
|
1403
|
+
const value = item[key];
|
|
1404
|
+
const valueType = typeof value;
|
|
1405
|
+
if (key in defaultIconSizeCustomisations) {
|
|
1406
|
+
if (value === null || value && (valueType === "string" || valueType === "number")) {
|
|
1407
|
+
result[key] = value;
|
|
1408
|
+
}
|
|
1409
|
+
} else if (valueType === typeof result[key]) {
|
|
1410
|
+
result[key] = key === "rotate" ? value % 4 : value;
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
return result;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
const separator = /[\s,]+/;
|
|
1417
|
+
function flipFromString(custom, flip) {
|
|
1418
|
+
flip.split(separator).forEach((str) => {
|
|
1419
|
+
const value = str.trim();
|
|
1420
|
+
switch (value) {
|
|
1421
|
+
case "horizontal":
|
|
1422
|
+
custom.hFlip = true;
|
|
1423
|
+
break;
|
|
1424
|
+
case "vertical":
|
|
1425
|
+
custom.vFlip = true;
|
|
1426
|
+
break;
|
|
1427
|
+
}
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
function rotateFromString(value, defaultValue = 0) {
|
|
1432
|
+
const units = value.replace(/^-?[0-9.]*/, "");
|
|
1433
|
+
function cleanup(value2) {
|
|
1434
|
+
while (value2 < 0) {
|
|
1435
|
+
value2 += 4;
|
|
1436
|
+
}
|
|
1437
|
+
return value2 % 4;
|
|
1438
|
+
}
|
|
1439
|
+
if (units === "") {
|
|
1440
|
+
const num = parseInt(value);
|
|
1441
|
+
return isNaN(num) ? 0 : cleanup(num);
|
|
1442
|
+
} else if (units !== value) {
|
|
1443
|
+
let split = 0;
|
|
1444
|
+
switch (units) {
|
|
1445
|
+
case "%":
|
|
1446
|
+
split = 25;
|
|
1447
|
+
break;
|
|
1448
|
+
case "deg":
|
|
1449
|
+
split = 90;
|
|
1450
|
+
}
|
|
1451
|
+
if (split) {
|
|
1452
|
+
let num = parseFloat(value.slice(0, value.length - units.length));
|
|
1453
|
+
if (isNaN(num)) {
|
|
1454
|
+
return 0;
|
|
1455
|
+
}
|
|
1456
|
+
num = num / split;
|
|
1457
|
+
return num % 1 === 0 ? cleanup(num) : 0;
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
return defaultValue;
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
function iconToHTML(body, attributes) {
|
|
1464
|
+
let renderAttribsHTML = body.indexOf("xlink:") === -1 ? "" : ' xmlns:xlink="http://www.w3.org/1999/xlink"';
|
|
1465
|
+
for (const attr in attributes) {
|
|
1466
|
+
renderAttribsHTML += " " + attr + '="' + attributes[attr] + '"';
|
|
1467
|
+
}
|
|
1468
|
+
return '<svg xmlns="http://www.w3.org/2000/svg"' + renderAttribsHTML + ">" + body + "</svg>";
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
function encodeSVGforURL(svg) {
|
|
1472
|
+
return svg.replace(/"/g, "'").replace(/%/g, "%25").replace(/#/g, "%23").replace(/</g, "%3C").replace(/>/g, "%3E").replace(/\s+/g, " ");
|
|
1473
|
+
}
|
|
1474
|
+
function svgToData(svg) {
|
|
1475
|
+
return "data:image/svg+xml," + encodeSVGforURL(svg);
|
|
1476
|
+
}
|
|
1477
|
+
function svgToURL(svg) {
|
|
1478
|
+
return 'url("' + svgToData(svg) + '")';
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
let policy;
|
|
1482
|
+
function createPolicy() {
|
|
1483
|
+
try {
|
|
1484
|
+
policy = window.trustedTypes.createPolicy("iconify", {
|
|
1485
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
1486
|
+
createHTML: (s) => s
|
|
1487
|
+
});
|
|
1488
|
+
} catch (err) {
|
|
1489
|
+
policy = null;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
function cleanUpInnerHTML(html) {
|
|
1493
|
+
if (policy === void 0) {
|
|
1494
|
+
createPolicy();
|
|
1495
|
+
}
|
|
1496
|
+
return policy ? policy.createHTML(html) : html;
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
const defaultExtendedIconCustomisations = {
|
|
1500
|
+
...defaultIconCustomisations,
|
|
1501
|
+
inline: false,
|
|
1502
|
+
};
|
|
1503
|
+
|
|
1504
|
+
/**
|
|
1505
|
+
* Default SVG attributes
|
|
1506
|
+
*/
|
|
1507
|
+
const svgDefaults = {
|
|
1508
|
+
'xmlns': 'http://www.w3.org/2000/svg',
|
|
1509
|
+
'xmlnsXlink': 'http://www.w3.org/1999/xlink',
|
|
1510
|
+
'aria-hidden': true,
|
|
1511
|
+
'role': 'img',
|
|
1512
|
+
};
|
|
1513
|
+
/**
|
|
1514
|
+
* Style modes
|
|
1515
|
+
*/
|
|
1516
|
+
const commonProps = {
|
|
1517
|
+
display: 'inline-block',
|
|
1518
|
+
};
|
|
1519
|
+
const monotoneProps = {
|
|
1520
|
+
backgroundColor: 'currentColor',
|
|
1521
|
+
};
|
|
1522
|
+
const coloredProps = {
|
|
1523
|
+
backgroundColor: 'transparent',
|
|
1524
|
+
};
|
|
1525
|
+
// Dynamically add common props to variables above
|
|
1526
|
+
const propsToAdd = {
|
|
1527
|
+
Image: 'var(--svg)',
|
|
1528
|
+
Repeat: 'no-repeat',
|
|
1529
|
+
Size: '100% 100%',
|
|
1530
|
+
};
|
|
1531
|
+
const propsToAddTo = {
|
|
1532
|
+
WebkitMask: monotoneProps,
|
|
1533
|
+
mask: monotoneProps,
|
|
1534
|
+
background: coloredProps,
|
|
1535
|
+
};
|
|
1536
|
+
for (const prefix in propsToAddTo) {
|
|
1537
|
+
const list = propsToAddTo[prefix];
|
|
1538
|
+
for (const prop in propsToAdd) {
|
|
1539
|
+
list[prefix + prop] = propsToAdd[prop];
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
/**
|
|
1543
|
+
* Default values for customisations for inline icon
|
|
1544
|
+
*/
|
|
1545
|
+
const inlineDefaults = {
|
|
1546
|
+
...defaultExtendedIconCustomisations,
|
|
1547
|
+
inline: true,
|
|
1548
|
+
};
|
|
1549
|
+
/**
|
|
1550
|
+
* Fix size: add 'px' to numbers
|
|
1551
|
+
*/
|
|
1552
|
+
function fixSize(value) {
|
|
1553
|
+
return value + (value.match(/^[-0-9.]+$/) ? 'px' : '');
|
|
1554
|
+
}
|
|
1555
|
+
/**
|
|
1556
|
+
* Render icon
|
|
1557
|
+
*/
|
|
1558
|
+
const render = (
|
|
1559
|
+
// Icon must be validated before calling this function
|
|
1560
|
+
icon,
|
|
1561
|
+
// Partial properties
|
|
1562
|
+
props,
|
|
1563
|
+
// True if icon should have vertical-align added
|
|
1564
|
+
inline,
|
|
1565
|
+
// Optional reference for SVG/SPAN, extracted by React.forwardRef()
|
|
1566
|
+
ref) => {
|
|
1567
|
+
// Get default properties
|
|
1568
|
+
const defaultProps = inline
|
|
1569
|
+
? inlineDefaults
|
|
1570
|
+
: defaultExtendedIconCustomisations;
|
|
1571
|
+
// Get all customisations
|
|
1572
|
+
const customisations = mergeCustomisations(defaultProps, props);
|
|
1573
|
+
// Check mode
|
|
1574
|
+
const mode = props.mode || 'svg';
|
|
1575
|
+
// Create style
|
|
1576
|
+
const style = {};
|
|
1577
|
+
const customStyle = props.style || {};
|
|
1578
|
+
// Create SVG component properties
|
|
1579
|
+
const componentProps = {
|
|
1580
|
+
...(mode === 'svg' ? svgDefaults : {}),
|
|
1581
|
+
ref,
|
|
1582
|
+
};
|
|
1583
|
+
// Get element properties
|
|
1584
|
+
for (let key in props) {
|
|
1585
|
+
const value = props[key];
|
|
1586
|
+
if (value === void 0) {
|
|
1587
|
+
continue;
|
|
1588
|
+
}
|
|
1589
|
+
switch (key) {
|
|
1590
|
+
// Properties to ignore
|
|
1591
|
+
case 'icon':
|
|
1592
|
+
case 'style':
|
|
1593
|
+
case 'children':
|
|
1594
|
+
case 'onLoad':
|
|
1595
|
+
case 'mode':
|
|
1596
|
+
case '_ref':
|
|
1597
|
+
case '_inline':
|
|
1598
|
+
break;
|
|
1599
|
+
// Boolean attributes
|
|
1600
|
+
case 'inline':
|
|
1601
|
+
case 'hFlip':
|
|
1602
|
+
case 'vFlip':
|
|
1603
|
+
customisations[key] =
|
|
1604
|
+
value === true || value === 'true' || value === 1;
|
|
1605
|
+
break;
|
|
1606
|
+
// Flip as string: 'horizontal,vertical'
|
|
1607
|
+
case 'flip':
|
|
1608
|
+
if (typeof value === 'string') {
|
|
1609
|
+
flipFromString(customisations, value);
|
|
1610
|
+
}
|
|
1611
|
+
break;
|
|
1612
|
+
// Color: copy to style
|
|
1613
|
+
case 'color':
|
|
1614
|
+
style.color = value;
|
|
1615
|
+
break;
|
|
1616
|
+
// Rotation as string
|
|
1617
|
+
case 'rotate':
|
|
1618
|
+
if (typeof value === 'string') {
|
|
1619
|
+
customisations[key] = rotateFromString(value);
|
|
1620
|
+
}
|
|
1621
|
+
else if (typeof value === 'number') {
|
|
1622
|
+
customisations[key] = value;
|
|
1623
|
+
}
|
|
1624
|
+
break;
|
|
1625
|
+
// Remove aria-hidden
|
|
1626
|
+
case 'ariaHidden':
|
|
1627
|
+
case 'aria-hidden':
|
|
1628
|
+
if (value !== true && value !== 'true') {
|
|
1629
|
+
delete componentProps['aria-hidden'];
|
|
1630
|
+
}
|
|
1631
|
+
break;
|
|
1632
|
+
// Copy missing property if it does not exist in customisations
|
|
1633
|
+
default:
|
|
1634
|
+
if (defaultProps[key] === void 0) {
|
|
1635
|
+
componentProps[key] = value;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
// Generate icon
|
|
1640
|
+
const item = iconToSVG(icon, customisations);
|
|
1641
|
+
const renderAttribs = item.attributes;
|
|
1642
|
+
// Inline display
|
|
1643
|
+
if (customisations.inline) {
|
|
1644
|
+
style.verticalAlign = '-0.125em';
|
|
1645
|
+
}
|
|
1646
|
+
if (mode === 'svg') {
|
|
1647
|
+
// Add style
|
|
1648
|
+
componentProps.style = {
|
|
1649
|
+
...style,
|
|
1650
|
+
...customStyle,
|
|
1651
|
+
};
|
|
1652
|
+
// Add icon stuff
|
|
1653
|
+
Object.assign(componentProps, renderAttribs);
|
|
1654
|
+
// Counter for ids based on "id" property to render icons consistently on server and client
|
|
1655
|
+
let localCounter = 0;
|
|
1656
|
+
let id = props.id;
|
|
1657
|
+
if (typeof id === 'string') {
|
|
1658
|
+
// Convert '-' to '_' to avoid errors in animations
|
|
1659
|
+
id = id.replace(/-/g, '_');
|
|
1660
|
+
}
|
|
1661
|
+
// Add icon stuff
|
|
1662
|
+
componentProps.dangerouslySetInnerHTML = {
|
|
1663
|
+
__html: cleanUpInnerHTML(replaceIDs(item.body, id ? () => id + 'ID' + localCounter++ : 'iconifyReact')),
|
|
1664
|
+
};
|
|
1665
|
+
return React__default.createElement('svg', componentProps);
|
|
1666
|
+
}
|
|
1667
|
+
// Render <span> with style
|
|
1668
|
+
const { body, width, height } = icon;
|
|
1669
|
+
const useMask = mode === 'mask' ||
|
|
1670
|
+
(mode === 'bg' ? false : body.indexOf('currentColor') !== -1);
|
|
1671
|
+
// Generate SVG
|
|
1672
|
+
const html = iconToHTML(body, {
|
|
1673
|
+
...renderAttribs,
|
|
1674
|
+
width: width + '',
|
|
1675
|
+
height: height + '',
|
|
1676
|
+
});
|
|
1677
|
+
// Generate style
|
|
1678
|
+
componentProps.style = {
|
|
1679
|
+
...style,
|
|
1680
|
+
'--svg': svgToURL(html),
|
|
1681
|
+
'width': fixSize(renderAttribs.width),
|
|
1682
|
+
'height': fixSize(renderAttribs.height),
|
|
1683
|
+
...commonProps,
|
|
1684
|
+
...(useMask ? monotoneProps : coloredProps),
|
|
1685
|
+
...customStyle,
|
|
1686
|
+
};
|
|
1687
|
+
return React__default.createElement('span', componentProps);
|
|
1688
|
+
};
|
|
1689
|
+
/**
|
|
1690
|
+
* Initialise stuff
|
|
1691
|
+
*/
|
|
1692
|
+
// Enable short names
|
|
1693
|
+
allowSimpleNames(true);
|
|
1694
|
+
// Set API module
|
|
1695
|
+
setAPIModule('', fetchAPIModule);
|
|
1696
|
+
/**
|
|
1697
|
+
* Browser stuff
|
|
1698
|
+
*/
|
|
1699
|
+
if (typeof document !== 'undefined' && typeof window !== 'undefined') {
|
|
1700
|
+
// Set cache and load existing cache
|
|
1701
|
+
initBrowserStorage();
|
|
1702
|
+
const _window = window;
|
|
1703
|
+
// Load icons from global "IconifyPreload"
|
|
1704
|
+
if (_window.IconifyPreload !== void 0) {
|
|
1705
|
+
const preload = _window.IconifyPreload;
|
|
1706
|
+
const err = 'Invalid IconifyPreload syntax.';
|
|
1707
|
+
if (typeof preload === 'object' && preload !== null) {
|
|
1708
|
+
(preload instanceof Array ? preload : [preload]).forEach((item) => {
|
|
1709
|
+
try {
|
|
1710
|
+
if (
|
|
1711
|
+
// Check if item is an object and not null/array
|
|
1712
|
+
typeof item !== 'object' ||
|
|
1713
|
+
item === null ||
|
|
1714
|
+
item instanceof Array ||
|
|
1715
|
+
// Check for 'icons' and 'prefix'
|
|
1716
|
+
typeof item.icons !== 'object' ||
|
|
1717
|
+
typeof item.prefix !== 'string' ||
|
|
1718
|
+
// Add icon set
|
|
1719
|
+
!addCollection(item)) {
|
|
1720
|
+
console.error(err);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
catch (e) {
|
|
1724
|
+
console.error(err);
|
|
1725
|
+
}
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
// Set API from global "IconifyProviders"
|
|
1730
|
+
if (_window.IconifyProviders !== void 0) {
|
|
1731
|
+
const providers = _window.IconifyProviders;
|
|
1732
|
+
if (typeof providers === 'object' && providers !== null) {
|
|
1733
|
+
for (let key in providers) {
|
|
1734
|
+
const err = 'IconifyProviders[' + key + '] is invalid.';
|
|
1735
|
+
try {
|
|
1736
|
+
const value = providers[key];
|
|
1737
|
+
if (typeof value !== 'object' ||
|
|
1738
|
+
!value ||
|
|
1739
|
+
value.resources === void 0) {
|
|
1740
|
+
continue;
|
|
1741
|
+
}
|
|
1742
|
+
if (!addAPIProvider(key, value)) {
|
|
1743
|
+
console.error(err);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
catch (e) {
|
|
1747
|
+
console.error(err);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
class IconComponent extends React__default.Component {
|
|
1754
|
+
constructor(props) {
|
|
1755
|
+
super(props);
|
|
1756
|
+
this.state = {
|
|
1757
|
+
// Render placeholder before component is mounted
|
|
1758
|
+
icon: null,
|
|
1759
|
+
};
|
|
1760
|
+
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Abort loading icon
|
|
1763
|
+
*/
|
|
1764
|
+
_abortLoading() {
|
|
1765
|
+
if (this._loading) {
|
|
1766
|
+
this._loading.abort();
|
|
1767
|
+
this._loading = null;
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
/**
|
|
1771
|
+
* Update state
|
|
1772
|
+
*/
|
|
1773
|
+
_setData(icon) {
|
|
1774
|
+
if (this.state.icon !== icon) {
|
|
1775
|
+
this.setState({
|
|
1776
|
+
icon,
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* Check if icon should be loaded
|
|
1782
|
+
*/
|
|
1783
|
+
_checkIcon(changed) {
|
|
1784
|
+
const state = this.state;
|
|
1785
|
+
const icon = this.props.icon;
|
|
1786
|
+
// Icon is an object
|
|
1787
|
+
if (typeof icon === 'object' &&
|
|
1788
|
+
icon !== null &&
|
|
1789
|
+
typeof icon.body === 'string') {
|
|
1790
|
+
// Stop loading
|
|
1791
|
+
this._icon = '';
|
|
1792
|
+
this._abortLoading();
|
|
1793
|
+
if (changed || state.icon === null) {
|
|
1794
|
+
// Set data if it was changed
|
|
1795
|
+
this._setData({
|
|
1796
|
+
data: icon,
|
|
1797
|
+
});
|
|
1798
|
+
}
|
|
1799
|
+
return;
|
|
1800
|
+
}
|
|
1801
|
+
// Invalid icon?
|
|
1802
|
+
let iconName;
|
|
1803
|
+
if (typeof icon !== 'string' ||
|
|
1804
|
+
(iconName = stringToIcon(icon, false, true)) === null) {
|
|
1805
|
+
this._abortLoading();
|
|
1806
|
+
this._setData(null);
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
// Load icon
|
|
1810
|
+
const data = getIconData(iconName);
|
|
1811
|
+
if (!data) {
|
|
1812
|
+
// Icon data is not available
|
|
1813
|
+
if (!this._loading || this._loading.name !== icon) {
|
|
1814
|
+
// New icon to load
|
|
1815
|
+
this._abortLoading();
|
|
1816
|
+
this._icon = '';
|
|
1817
|
+
this._setData(null);
|
|
1818
|
+
if (data !== null) {
|
|
1819
|
+
// Icon was not loaded
|
|
1820
|
+
this._loading = {
|
|
1821
|
+
name: icon,
|
|
1822
|
+
abort: loadIcons([iconName], this._checkIcon.bind(this, false)),
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
return;
|
|
1827
|
+
}
|
|
1828
|
+
// Icon data is available
|
|
1829
|
+
if (this._icon !== icon || state.icon === null) {
|
|
1830
|
+
// New icon or icon has been loaded
|
|
1831
|
+
this._abortLoading();
|
|
1832
|
+
this._icon = icon;
|
|
1833
|
+
// Add classes
|
|
1834
|
+
const classes = ['iconify'];
|
|
1835
|
+
if (iconName.prefix !== '') {
|
|
1836
|
+
classes.push('iconify--' + iconName.prefix);
|
|
1837
|
+
}
|
|
1838
|
+
if (iconName.provider !== '') {
|
|
1839
|
+
classes.push('iconify--' + iconName.provider);
|
|
1840
|
+
}
|
|
1841
|
+
// Set data
|
|
1842
|
+
this._setData({
|
|
1843
|
+
data,
|
|
1844
|
+
classes,
|
|
1845
|
+
});
|
|
1846
|
+
if (this.props.onLoad) {
|
|
1847
|
+
this.props.onLoad(icon);
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
/**
|
|
1852
|
+
* Component mounted
|
|
1853
|
+
*/
|
|
1854
|
+
componentDidMount() {
|
|
1855
|
+
this._checkIcon(false);
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* Component updated
|
|
1859
|
+
*/
|
|
1860
|
+
componentDidUpdate(oldProps) {
|
|
1861
|
+
if (oldProps.icon !== this.props.icon) {
|
|
1862
|
+
this._checkIcon(true);
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
/**
|
|
1866
|
+
* Abort loading
|
|
1867
|
+
*/
|
|
1868
|
+
componentWillUnmount() {
|
|
1869
|
+
this._abortLoading();
|
|
1870
|
+
}
|
|
1871
|
+
/**
|
|
1872
|
+
* Render
|
|
1873
|
+
*/
|
|
1874
|
+
render() {
|
|
1875
|
+
const props = this.props;
|
|
1876
|
+
const icon = this.state.icon;
|
|
1877
|
+
if (icon === null) {
|
|
1878
|
+
// Render placeholder
|
|
1879
|
+
return props.children
|
|
1880
|
+
? props.children
|
|
1881
|
+
: React__default.createElement('span', {});
|
|
1882
|
+
}
|
|
1883
|
+
// Add classes
|
|
1884
|
+
let newProps = props;
|
|
1885
|
+
if (icon.classes) {
|
|
1886
|
+
newProps = {
|
|
1887
|
+
...props,
|
|
1888
|
+
className: (typeof props.className === 'string'
|
|
1889
|
+
? props.className + ' '
|
|
1890
|
+
: '') + icon.classes.join(' '),
|
|
1891
|
+
};
|
|
1892
|
+
}
|
|
1893
|
+
// Render icon
|
|
1894
|
+
return render({
|
|
1895
|
+
...defaultIconProps,
|
|
1896
|
+
...icon.data,
|
|
1897
|
+
}, newProps, props._inline, props._ref);
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
/**
|
|
1901
|
+
* Block icon
|
|
1902
|
+
*
|
|
1903
|
+
* @param props - Component properties
|
|
1904
|
+
*/
|
|
1905
|
+
const Icon = React__default.forwardRef(function Icon(props, ref) {
|
|
1906
|
+
const newProps = {
|
|
1907
|
+
...props,
|
|
1908
|
+
_ref: ref,
|
|
1909
|
+
_inline: false,
|
|
1910
|
+
};
|
|
1911
|
+
return React__default.createElement(IconComponent, newProps);
|
|
1912
|
+
});
|
|
1913
|
+
/**
|
|
1914
|
+
* Inline icon (has negative verticalAlign that makes it behave like icon font)
|
|
1915
|
+
*
|
|
1916
|
+
* @param props - Component properties
|
|
1917
|
+
*/
|
|
1918
|
+
React__default.forwardRef(function InlineIcon(props, ref) {
|
|
1919
|
+
const newProps = {
|
|
1920
|
+
...props,
|
|
1921
|
+
_ref: ref,
|
|
1922
|
+
_inline: true,
|
|
1923
|
+
};
|
|
1924
|
+
return React__default.createElement(IconComponent, newProps);
|
|
1925
|
+
});
|
|
1926
|
+
|
|
1927
|
+
export { Icon, addAPIProvider, addCollection, addIcon, iconToSVG as buildIcon, calculateSize, loadIcons, replaceIDs };
|
|
1928
|
+
//# sourceMappingURL=iconify.js.map
|