@cyberalien/svg-utils 1.1.4 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/lib/components/export/merge.js +3 -1
  2. package/lib/components/helpers/content/stringify.d.ts +2 -2
  3. package/lib/components/helpers/content/stringify.js +4 -10
  4. package/lib/components/helpers/css/generate.d.ts +2 -1
  5. package/lib/components/helpers/css/generate.js +43 -46
  6. package/lib/components/helpers/filenames/css.d.ts +1 -1
  7. package/lib/components/helpers/filenames/css.js +2 -3
  8. package/lib/components/helpers/functions/custom.d.ts +14 -0
  9. package/lib/components/helpers/functions/custom.js +17 -0
  10. package/lib/components/helpers/functions/fallback.d.ts +8 -0
  11. package/lib/components/helpers/functions/fallback.js +53 -0
  12. package/lib/components/helpers/functions/innerhtml.d.ts +8 -0
  13. package/lib/components/helpers/functions/innerhtml.js +35 -0
  14. package/lib/components/helpers/functions/size.js +1 -1
  15. package/lib/components/helpers/imports/create.js +1 -2
  16. package/lib/components/helpers/imports/stringify.js +0 -2
  17. package/lib/components/helpers/imports/types.d.ts +0 -1
  18. package/lib/components/jsx.js +79 -8
  19. package/lib/components/prepare/iconify.d.ts +1 -1
  20. package/lib/components/prepare/iconify.js +6 -4
  21. package/lib/components/prepare/states.d.ts +8 -0
  22. package/lib/components/prepare/states.js +73 -0
  23. package/lib/components/raw.js +10 -7
  24. package/lib/components/svelte.js +73 -14
  25. package/lib/components/types/component.d.ts +2 -1
  26. package/lib/components/types/css.d.ts +1 -2
  27. package/lib/components/types/data.d.ts +0 -3
  28. package/lib/components/types/options.d.ts +9 -2
  29. package/lib/components/types/source.d.ts +21 -6
  30. package/lib/components/vue-func.js +71 -12
  31. package/lib/components/vue.js +70 -13
  32. package/lib/css/find/animations.d.ts +10 -0
  33. package/lib/css/find/animations.js +35 -0
  34. package/lib/css/find/classname.d.ts +5 -0
  35. package/lib/css/find/classname.js +14 -0
  36. package/lib/css/find/prop.d.ts +5 -0
  37. package/lib/css/find/prop.js +12 -0
  38. package/lib/css/minify.d.ts +2 -0
  39. package/lib/css/minify.js +5 -0
  40. package/lib/css/rules.d.ts +10 -0
  41. package/lib/css/rules.js +26 -0
  42. package/lib/css/stringify.d.ts +8 -2
  43. package/lib/css/stringify.js +16 -8
  44. package/lib/css/stylesheet.d.ts +0 -2
  45. package/lib/css/stylesheet.js +3 -3
  46. package/lib/css/types.d.ts +1 -1
  47. package/lib/helpers/data/compact.d.ts +20 -0
  48. package/lib/helpers/data/compact.js +38 -0
  49. package/lib/helpers/data/expand.d.ts +5 -0
  50. package/lib/helpers/data/expand.js +9 -0
  51. package/lib/helpers/reduce-motion.d.ts +2 -0
  52. package/lib/helpers/reduce-motion.js +3 -0
  53. package/lib/index.d.ts +15 -2
  54. package/lib/index.js +11 -2
  55. package/lib/svg-css/icon/css.d.ts +25 -0
  56. package/lib/svg-css/icon/css.js +57 -0
  57. package/lib/svg-css/icon/types.d.ts +45 -0
  58. package/lib/svg-css/icon/types.js +1 -0
  59. package/lib/svg-css/icon-set/add.d.ts +7 -0
  60. package/lib/svg-css/icon-set/add.js +52 -0
  61. package/lib/svg-css/icon-set/create.d.ts +6 -0
  62. package/lib/svg-css/icon-set/create.js +8 -0
  63. package/lib/svg-css/icon-set/get.d.ts +4 -0
  64. package/lib/svg-css/icon-set/get.js +92 -0
  65. package/lib/svg-css/icon-set/minify/expand.d.ts +10 -0
  66. package/lib/svg-css/icon-set/minify/expand.js +35 -0
  67. package/lib/svg-css/icon-set/minify/keys.d.ts +5 -0
  68. package/lib/svg-css/icon-set/minify/keys.js +9 -0
  69. package/lib/svg-css/icon-set/minify/minify.d.ts +19 -0
  70. package/lib/svg-css/icon-set/minify/minify.js +74 -0
  71. package/lib/svg-css/icon-set/types.d.ts +43 -0
  72. package/lib/svg-css/icon-set/types.js +1 -0
  73. package/lib/svg-css/states/cleanup-values.d.ts +6 -0
  74. package/lib/svg-css/states/cleanup-values.js +15 -0
  75. package/lib/svg-css/states/fallback/parse.d.ts +7 -0
  76. package/lib/svg-css/states/fallback/parse.js +46 -0
  77. package/lib/svg-css/states/fallback/stringify.d.ts +6 -0
  78. package/lib/svg-css/states/fallback/stringify.js +9 -0
  79. package/lib/svg-css/states/fallback/test.d.ts +9 -0
  80. package/lib/svg-css/states/fallback/test.js +21 -0
  81. package/lib/svg-css/states/fallback/types.d.ts +20 -0
  82. package/lib/svg-css/states/fallback/types.js +1 -0
  83. package/lib/svg-css/states/focus.d.ts +10 -0
  84. package/lib/svg-css/states/focus.js +14 -0
  85. package/lib/svg-css/states/generator.d.ts +19 -0
  86. package/lib/svg-css/states/generator.js +31 -0
  87. package/lib/svg-css/states/key.d.ts +6 -0
  88. package/lib/svg-css/states/key.js +22 -0
  89. package/lib/svg-css/states/object.d.ts +6 -0
  90. package/lib/svg-css/states/object.js +13 -0
  91. package/lib/svg-css/states/selector/helpers/iterate.d.ts +10 -0
  92. package/lib/svg-css/states/selector/helpers/iterate.js +71 -0
  93. package/lib/svg-css/states/selector/merge.d.ts +6 -0
  94. package/lib/svg-css/states/selector/merge.js +29 -0
  95. package/lib/svg-css/states/selector/parse.d.ts +13 -0
  96. package/lib/svg-css/states/selector/parse.js +74 -0
  97. package/lib/svg-css/states/selector/part/merge.d.ts +10 -0
  98. package/lib/svg-css/states/selector/part/merge.js +37 -0
  99. package/lib/svg-css/states/selector/part/split.d.ts +13 -0
  100. package/lib/svg-css/states/selector/part/split.js +60 -0
  101. package/lib/svg-css/states/selector/part/stringify.d.ts +9 -0
  102. package/lib/svg-css/states/selector/part/stringify.js +32 -0
  103. package/lib/svg-css/states/selector/split.d.ts +6 -0
  104. package/lib/svg-css/states/selector/split.js +29 -0
  105. package/lib/svg-css/states/selector/stringify.d.ts +8 -0
  106. package/lib/svg-css/states/selector/stringify.js +143 -0
  107. package/lib/svg-css/states/selector/sub/merge.d.ts +6 -0
  108. package/lib/svg-css/states/selector/sub/merge.js +36 -0
  109. package/lib/svg-css/states/selector/sub/split.d.ts +10 -0
  110. package/lib/svg-css/states/selector/sub/split.js +61 -0
  111. package/lib/svg-css/states/selector/sub/stringify.d.ts +6 -0
  112. package/lib/svg-css/states/selector/sub/stringify.js +17 -0
  113. package/lib/svg-css/states/selector/types.d.ts +37 -0
  114. package/lib/svg-css/states/selector/types.js +1 -0
  115. package/lib/svg-css/states/types.d.ts +9 -0
  116. package/lib/svg-css/states/types.js +1 -0
  117. package/lib/svg-css/states/validate.d.ts +6 -0
  118. package/lib/svg-css/states/validate.js +55 -0
  119. package/lib/svg-css/states/value.d.ts +10 -0
  120. package/lib/svg-css/states/value.js +15 -0
  121. package/package.json +8 -8
  122. package/lib/components/helpers/css/name.d.ts +0 -7
  123. package/lib/components/helpers/css/name.js +0 -12
@@ -0,0 +1,35 @@
1
+ import { expandItem } from "../../../helpers/data/expand.js";
2
+ import { iconSetMinifySimpleKeys, iconSetMinifyStatefulKeys } from "./keys.js";
3
+
4
+ /**
5
+ * Expand class content from icon set
6
+ */
7
+ function expandSVGCSSIconSetClass(css, classContent) {
8
+ for (const prop of iconSetMinifySimpleKeys) if (css[prop]) expandItem(css[prop], classContent, prop);
9
+ for (const prop of iconSetMinifyStatefulKeys) {
10
+ const value = classContent[prop];
11
+ const list = css[prop];
12
+ if (list && value) for (const state in value) expandItem(list, value, state);
13
+ }
14
+ }
15
+ /**
16
+ * Unminify icon set
17
+ */
18
+ function expandSVGCSSIconSet(iconSet) {
19
+ const { viewBoxes, statesList, css } = iconSet;
20
+ if (viewBoxes || statesList) {
21
+ for (const iconName in iconSet.icons) {
22
+ const icon = iconSet.icons[iconName];
23
+ if (viewBoxes) expandItem(viewBoxes, icon, "viewBox");
24
+ if (statesList) expandItem(statesList, icon, "states");
25
+ }
26
+ delete iconSet.viewBoxes;
27
+ delete iconSet.statesList;
28
+ }
29
+ if (css && iconSet.classes) {
30
+ for (const className in iconSet.classes) expandSVGCSSIconSetClass(css, iconSet.classes[className]);
31
+ delete iconSet.css;
32
+ }
33
+ }
34
+
35
+ export { expandSVGCSSIconSet, expandSVGCSSIconSetClass };
@@ -0,0 +1,5 @@
1
+ import { SVGCSSIconSetClassData } from "../types.js";
2
+ declare const iconSetMinifySimpleKeys: (keyof Pick<SVGCSSIconSetClassData, 'r' | 'a' | 't'>)[];
3
+ declare const iconSetMinifyStatefulKeys: (keyof Pick<SVGCSSIconSetClassData, 'sr' | 'st'>)[];
4
+ declare const iconSetMinifyKeys: (keyof SVGCSSIconSetClassData)[];
5
+ export { iconSetMinifyKeys, iconSetMinifySimpleKeys, iconSetMinifyStatefulKeys };
@@ -0,0 +1,9 @@
1
+ const iconSetMinifySimpleKeys = [
2
+ "r",
3
+ "a",
4
+ "t"
5
+ ];
6
+ const iconSetMinifyStatefulKeys = ["sr", "st"];
7
+ const iconSetMinifyKeys = [...iconSetMinifySimpleKeys, ...iconSetMinifyStatefulKeys];
8
+
9
+ export { iconSetMinifyKeys, iconSetMinifySimpleKeys, iconSetMinifyStatefulKeys };
@@ -0,0 +1,19 @@
1
+ import { IconViewBox } from "../../../svg/viewbox/types.js";
2
+ import { IconStatesList } from "../../states/types.js";
3
+ import { createCompactContext } from "../../../helpers/data/compact.js";
4
+ import { SVGCSSIconSet } from "../types.js";
5
+ import { iconSetMinifyKeys } from "./keys.js";
6
+ type Keys = (typeof iconSetMinifyKeys)[number];
7
+ interface Context extends Record<Keys, ReturnType<typeof createCompactContext<string>>> {
8
+ viewBox: ReturnType<typeof createCompactContext<IconViewBox | string>>;
9
+ states: ReturnType<typeof createCompactContext<IconStatesList>>;
10
+ }
11
+ /**
12
+ * Create context for minification
13
+ */
14
+ declare function createIconSetMinifyContext(): Context;
15
+ /**
16
+ * Minify icon set
17
+ */
18
+ declare function minifySVGCSSIconSet(iconSet: SVGCSSIconSet): void;
19
+ export { createIconSetMinifyContext, minifySVGCSSIconSet };
@@ -0,0 +1,74 @@
1
+ import { iconSetMinifyKeys, iconSetMinifySimpleKeys, iconSetMinifyStatefulKeys } from "./keys.js";
2
+ import { stringifyIconViewBox } from "../../../svg/viewbox/value.js";
3
+ import { compactItem, createCompactContext } from "../../../helpers/data/compact.js";
4
+
5
+ /**
6
+ * Create context for minification
7
+ */
8
+ function createIconSetMinifyContext() {
9
+ const result = Object.create(null);
10
+ for (const key of iconSetMinifyKeys) result[key] = createCompactContext();
11
+ result.viewBox = createCompactContext();
12
+ result.states = createCompactContext();
13
+ return result;
14
+ }
15
+ /**
16
+ * Get key for viewBox
17
+ */
18
+ function viewBoxKey(viewBox) {
19
+ return typeof viewBox === "string" ? viewBox : stringifyIconViewBox(viewBox) + ("cx" in viewBox ? ` ${viewBox.cx}` : "");
20
+ }
21
+ /**
22
+ * Minify icon set
23
+ */
24
+ function minifySVGCSSIconSet(iconSet) {
25
+ const context = createIconSetMinifyContext();
26
+ const viewBoxes = context.viewBox;
27
+ const statesList = context.states;
28
+ if (iconSet.viewBoxes) viewBoxes.data = [...iconSet.viewBoxes];
29
+ viewBoxes.data.forEach((value, index) => {
30
+ const key = viewBoxKey(value);
31
+ viewBoxes.map.set(key, index);
32
+ });
33
+ if (iconSet.statesList) statesList.data = [...iconSet.statesList];
34
+ statesList.data.forEach((value, index) => {
35
+ const key = JSON.stringify(value);
36
+ statesList.map.set(key, index);
37
+ });
38
+ for (const prop of iconSetMinifyKeys) {
39
+ context[prop].data = [...iconSet.css?.[prop] ?? []];
40
+ const { data, map } = context[prop];
41
+ data.forEach((value, index) => {
42
+ map.set(value, index);
43
+ });
44
+ }
45
+ for (const iconName in iconSet.icons) {
46
+ const icon = iconSet.icons[iconName];
47
+ const viewBoxValue = icon.viewBox;
48
+ if (typeof viewBoxValue !== "number") compactItem(viewBoxes, viewBoxKey(viewBoxValue), icon, "viewBox", viewBoxValue);
49
+ const statesValue = icon.states;
50
+ if (typeof statesValue !== "number") compactItem(statesList, JSON.stringify(statesValue), icon, "states", statesValue);
51
+ }
52
+ if (iconSet.classes) for (const className in iconSet.classes) {
53
+ const classContent = iconSet.classes[className];
54
+ for (const prop of iconSetMinifySimpleKeys) if (typeof classContent[prop] === "string") compactItem(context[prop], classContent[prop], classContent, prop);
55
+ for (const prop of iconSetMinifyStatefulKeys) {
56
+ const value = classContent[prop];
57
+ if (value) {
58
+ for (const state in value) if (typeof value[state] === "string") compactItem(context[prop], value[state], value, state);
59
+ }
60
+ }
61
+ }
62
+ iconSet.viewBoxes = viewBoxes.data.length ? viewBoxes.data : void 0;
63
+ iconSet.statesList = statesList.data.length ? statesList.data : void 0;
64
+ delete iconSet.css;
65
+ for (const prop of iconSetMinifyKeys) {
66
+ const data = context[prop].data;
67
+ if (data.length) {
68
+ if (!iconSet.css) iconSet.css = Object.create(null);
69
+ iconSet.css[prop] = data;
70
+ }
71
+ }
72
+ }
73
+
74
+ export { createIconSetMinifyContext, minifySVGCSSIconSet };
@@ -0,0 +1,43 @@
1
+ import { IconViewBox } from "../../svg/viewbox/types.js";
2
+ import { IconStatesList } from "../states/types.js";
3
+ /**
4
+ * Icon entry in an icon set
5
+ */
6
+ interface SVGCSSIconSetIcon {
7
+ content: string;
8
+ viewBox: IconViewBox | string | number;
9
+ fallback?: string;
10
+ states?: IconStatesList | number;
11
+ }
12
+ /**
13
+ * Stateful class data
14
+ */
15
+ interface SVGCSSIconSetClassData {
16
+ r?: string | number;
17
+ a?: string | number;
18
+ sr?: Record<string, string | number>;
19
+ t?: string | number;
20
+ st?: Record<string, string | number>;
21
+ }
22
+ /**
23
+ * Shared data for icons, which can be reused in multiple icons
24
+ */
25
+ interface SVGCSSIconSetSharedData {
26
+ classes?: Record<string, SVGCSSIconSetClassData>;
27
+ keyframes?: Record<string, string>;
28
+ css?: Partial<Record<keyof SVGCSSIconSetClassData, string[]>>;
29
+ viewBoxes?: (IconViewBox | string)[];
30
+ statesList?: IconStatesList[];
31
+ }
32
+ /**
33
+ * Icon set in SVG+CSS format
34
+ *
35
+ * Does not include metadata
36
+ */
37
+ interface SVGCSSIconSet extends SVGCSSIconSetSharedData {
38
+ fallbackPrefix?: string;
39
+ fallbackSuffix?: string;
40
+ icons: Record<string, SVGCSSIconSetIcon>;
41
+ aliases?: Record<string, string>;
42
+ }
43
+ export { SVGCSSIconSet, SVGCSSIconSetClassData, SVGCSSIconSetIcon, SVGCSSIconSetSharedData };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,6 @@
1
+ import { IconStatesList } from "./types.js";
2
+ /**
3
+ * Clean up state values object
4
+ */
5
+ declare function cleanupStateValues(states: IconStatesList, values: Record<string, boolean | string>, clone?: boolean): Record<string, string | boolean>;
6
+ export { cleanupStateValues };
@@ -0,0 +1,15 @@
1
+ import { getStateValue } from "./value.js";
2
+
3
+ /**
4
+ * Clean up state values object
5
+ */
6
+ function cleanupStateValues(states, values, clone = false) {
7
+ const result = clone ? { ...values } : values;
8
+ for (const state of states) {
9
+ const stateName = typeof state === "string" ? state : state[0];
10
+ result[stateName] = getStateValue(state, result[stateName]);
11
+ }
12
+ return result;
13
+ }
14
+
15
+ export { cleanupStateValues };
@@ -0,0 +1,7 @@
1
+ import { IconStatesList } from "../types.js";
2
+ import { IconFallbackTemplate } from "./types.js";
3
+ /**
4
+ * Parse fallback template string into array of strings and states
5
+ */
6
+ declare function parseIconFallbackTemplate(fallback: string, states: IconStatesList): IconFallbackTemplate | undefined;
7
+ export { parseIconFallbackTemplate };
@@ -0,0 +1,46 @@
1
+ function unwrap(value) {
2
+ if (value.startsWith("'") && value.endsWith("'")) return value.slice(1, -1);
3
+ return value;
4
+ }
5
+ /**
6
+ * Parse fallback template string into array of strings and states
7
+ */
8
+ function parseIconFallbackTemplate(fallback, states) {
9
+ const chunks = [];
10
+ let startIndex = 0;
11
+ for (const match of fallback.matchAll(/{[^}]+}/g)) {
12
+ const matchText = match[0];
13
+ const matchIndex = match.index || 0;
14
+ if (matchIndex > startIndex) {
15
+ const prev = fallback.slice(startIndex, matchIndex);
16
+ if (prev) chunks.push(prev);
17
+ }
18
+ startIndex = matchIndex + matchText.length;
19
+ const textMatches = Array.from(matchText.matchAll(/[a-z0-9:'-]+/g));
20
+ if (!textMatches.length) return;
21
+ const separators = Array.from(matchText.matchAll(/[^a-z0-9:'-]/g));
22
+ if (separators.length !== textMatches.length + 1) return;
23
+ const stateName = textMatches[0][0].trim();
24
+ const state = states.find((s) => typeof s === "string" ? s === stateName : s[0] === stateName);
25
+ if (!state) return;
26
+ if (typeof state === "string") {
27
+ if (textMatches.length !== 3) return;
28
+ const trueValue = textMatches[1][0];
29
+ const falseValue = textMatches[2][0];
30
+ const firstSeparator = separators[1][0];
31
+ const secondSeparator = separators[2][0];
32
+ if (firstSeparator !== "?" || secondSeparator !== "|") return;
33
+ chunks.push({
34
+ state,
35
+ values: [unwrap(falseValue), unwrap(trueValue)]
36
+ });
37
+ } else {
38
+ if (textMatches.length > 1) return;
39
+ chunks.push({ state: stateName });
40
+ }
41
+ }
42
+ if (startIndex < fallback.length) chunks.push(fallback.slice(startIndex));
43
+ return chunks;
44
+ }
45
+
46
+ export { parseIconFallbackTemplate };
@@ -0,0 +1,6 @@
1
+ import { IconFallbackTemplate } from "./types.js";
2
+ /**
3
+ * Generate fallback string from template and states
4
+ */
5
+ declare function getIconFallback(template: IconFallbackTemplate, values: Record<string, boolean | string>, defaultValues?: Record<string, boolean | string>): string;
6
+ export { getIconFallback };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Generate fallback string from template and states
3
+ */
4
+ function getIconFallback(template, values, defaultValues) {
5
+ const stateValue = (state) => values[state] ?? defaultValues?.[state];
6
+ return template.map((chunk) => typeof chunk === "string" ? chunk : "values" in chunk ? chunk.values[+!!stateValue(chunk.state)] : stateValue(chunk.state)).join("");
7
+ }
8
+
9
+ export { getIconFallback };
@@ -0,0 +1,9 @@
1
+ import { IconStatesList } from "../types.js";
2
+ import { IconFallbackTemplate } from "./types.js";
3
+ /**
4
+ * Parse and test fallback template string
5
+ *
6
+ * This will make sure template is valid and does not contain invalid characters
7
+ */
8
+ declare function parseAndTestIconFallbackTemplate(fallback: string, states: IconStatesList): IconFallbackTemplate | undefined;
9
+ export { parseAndTestIconFallbackTemplate };
@@ -0,0 +1,21 @@
1
+ import { parseIconFallbackTemplate } from "./parse.js";
2
+
3
+ const match = /^[a-z0-9:-]*$/;
4
+ /**
5
+ * Parse and test fallback template string
6
+ *
7
+ * This will make sure template is valid and does not contain invalid characters
8
+ */
9
+ function parseAndTestIconFallbackTemplate(fallback, states) {
10
+ const template = parseIconFallbackTemplate(fallback, states);
11
+ if (template) {
12
+ for (const chunk of template) if (typeof chunk === "string") {
13
+ if (!chunk.match(match)) return;
14
+ } else if ("values" in chunk) {
15
+ if (!chunk.values.every((v) => v.match(match))) return;
16
+ }
17
+ }
18
+ return template;
19
+ }
20
+
21
+ export { parseAndTestIconFallbackTemplate };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Fallback replacement for boolean state
3
+ */
4
+ interface IconFallbackBooleanState {
5
+ state: string;
6
+ values: [string, string];
7
+ }
8
+ /**
9
+ * Fallback for named state
10
+ *
11
+ * Value should match state values
12
+ */
13
+ interface IconFallbackAdvancedState {
14
+ state: string;
15
+ }
16
+ /**
17
+ * Template for fallback: mix of strings and states
18
+ */
19
+ type IconFallbackTemplate = (string | IconFallbackBooleanState | IconFallbackAdvancedState)[];
20
+ export { IconFallbackAdvancedState, IconFallbackBooleanState, IconFallbackTemplate };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,10 @@
1
+ import { IconStatesList, IconStatesState } from "./types.js";
2
+ /**
3
+ * Check for focus state
4
+ */
5
+ declare function isFocusState(state: IconStatesState | string): boolean;
6
+ /**
7
+ * Filter out focus state from states list
8
+ */
9
+ declare function filterFocusState(states: IconStatesList): IconStatesList;
10
+ export { filterFocusState, isFocusState };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Check for focus state
3
+ */
4
+ function isFocusState(state) {
5
+ return state === "focus";
6
+ }
7
+ /**
8
+ * Filter out focus state from states list
9
+ */
10
+ function filterFocusState(states) {
11
+ return states.filter((state) => !isFocusState(state));
12
+ }
13
+
14
+ export { filterFocusState, isFocusState };
@@ -0,0 +1,19 @@
1
+ import { IconStatesList, IconStatesState } from "./types.js";
2
+ /**
3
+ * Generate code for object from states
4
+ *
5
+ * Does not include starting { and ending }
6
+ * Last entry does not have a comma at the end
7
+ */
8
+ declare function generateObjectFromStates(states: IconStatesList): string;
9
+ /**
10
+ * Generate code for TypeScript interface from state
11
+ */
12
+ declare function getStateInterface(state: IconStatesState, optional?: boolean): string;
13
+ /**
14
+ * Generate code for TypeScript interface from states
15
+ *
16
+ * Does not include starting { and ending }
17
+ */
18
+ declare function generateInterfaceFromStates(states: IconStatesList, optional?: boolean): string;
19
+ export { generateInterfaceFromStates, generateObjectFromStates, getStateInterface };
@@ -0,0 +1,31 @@
1
+ import { getAdvancedStateDefaultValue } from "./value.js";
2
+
3
+ /**
4
+ * Generate code for object from states
5
+ *
6
+ * Does not include starting { and ending }
7
+ * Last entry does not have a comma at the end
8
+ */
9
+ function generateObjectFromStates(states) {
10
+ const lines = [];
11
+ for (const state of states) if (typeof state === "string") lines.push(`'${state}': false`);
12
+ else lines.push(`'${state[0]}': '${getAdvancedStateDefaultValue(state)}'`);
13
+ return lines.join(",\n ");
14
+ }
15
+ /**
16
+ * Generate code for TypeScript interface from state
17
+ */
18
+ function getStateInterface(state, optional = true) {
19
+ const q = optional ? "?" : "";
20
+ return typeof state === "string" ? `'${state}'${q}: boolean;` : `'${state[0]}'${q}: ${state[1].map((value) => `'${value}'`).join(" | ")};`;
21
+ }
22
+ /**
23
+ * Generate code for TypeScript interface from states
24
+ *
25
+ * Does not include starting { and ending }
26
+ */
27
+ function generateInterfaceFromStates(states, optional = true) {
28
+ return states.map((state) => getStateInterface(state, optional)).join("\n ");
29
+ }
30
+
31
+ export { generateInterfaceFromStates, generateObjectFromStates, getStateInterface };
@@ -0,0 +1,6 @@
1
+ import { IconStatesList } from "./types.js";
2
+ /**
3
+ * Get state values from an underscore separated list of state values
4
+ */
5
+ declare function getStatesFromKey(key: string, states: IconStatesList): Record<string, string | boolean>;
6
+ export { getStatesFromKey };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Get state values from an underscore separated list of state values
3
+ */
4
+ function getStatesFromKey(key, states) {
5
+ const obj = Object.create(null);
6
+ const parts = key.split("_");
7
+ for (const state of states) {
8
+ if (typeof state === "string") {
9
+ if (parts.includes(state)) obj[state] = true;
10
+ continue;
11
+ }
12
+ const values = state[1];
13
+ const defaultValue = state[2] || values[0];
14
+ for (const value of values) if (value !== defaultValue && parts.includes(value)) {
15
+ obj[state[0]] = value;
16
+ break;
17
+ }
18
+ }
19
+ return obj;
20
+ }
21
+
22
+ export { getStatesFromKey };
@@ -0,0 +1,6 @@
1
+ import { IconStatesList } from "./types.js";
2
+ /**
3
+ * Create reactive object from states
4
+ */
5
+ declare function getObjectFromStates(states: IconStatesList): Record<string, boolean | string>;
6
+ export { getObjectFromStates };
@@ -0,0 +1,13 @@
1
+ import { getAdvancedStateDefaultValue } from "./value.js";
2
+
3
+ /**
4
+ * Create reactive object from states
5
+ */
6
+ function getObjectFromStates(states) {
7
+ const obj = Object.create(null);
8
+ for (const state of states) if (typeof state === "string") obj[state] = false;
9
+ else obj[state[0]] = getAdvancedStateDefaultValue(state);
10
+ return obj;
11
+ }
12
+
13
+ export { getObjectFromStates };
@@ -0,0 +1,10 @@
1
+ type Callback<T> = (item1: T, item2: T) => T | null;
2
+ /**
3
+ * Merge arrays of items
4
+ */
5
+ declare function mergeArrays<T>(list1: T[], list2: T[], merge: Callback<T>): T[][];
6
+ /**
7
+ * Merge multiple arrays
8
+ */
9
+ declare function mergeMultipleArrays<T>(lists: T[][], merge: Callback<T>): T[][];
10
+ export { mergeArrays, mergeMultipleArrays };
@@ -0,0 +1,71 @@
1
+ function getMergeOrders(total) {
2
+ const orders = [{
3
+ order: "before",
4
+ index: 0
5
+ }];
6
+ for (let index = 0; index < total; index++) {
7
+ orders.push({
8
+ order: "merge",
9
+ index
10
+ });
11
+ orders.push({
12
+ order: "after",
13
+ index
14
+ });
15
+ }
16
+ return orders;
17
+ }
18
+ /**
19
+ * Merge arrays of items
20
+ */
21
+ function mergeArrays(list1, list2, merge) {
22
+ if (!list1.length) return [list2];
23
+ if (!list2.length) return [list1];
24
+ function appendRemaining(queue) {
25
+ return queue.filter((o) => o.order === "merge").map((o) => list1[o.index]);
26
+ }
27
+ function next(before, list2, queue) {
28
+ const prev = [...before];
29
+ const results = [];
30
+ const currentItem = list2[0];
31
+ const nextItems = list2.slice(1);
32
+ for (let i = 0; i < queue.length; i++) {
33
+ const orderItem = queue[i];
34
+ switch (orderItem.order) {
35
+ case "after": if (i > 0) prev.push(list1[orderItem.index]);
36
+ case "before": {
37
+ const newPrev = [...prev, currentItem];
38
+ if (!nextItems.length) results.push([...newPrev, ...appendRemaining(queue.slice(i + 1))]);
39
+ else results.push(...next(newPrev, nextItems, queue.slice(i)));
40
+ break;
41
+ }
42
+ case "merge": {
43
+ const merged = merge(list1[orderItem.index], currentItem);
44
+ if (merged) {
45
+ const newPrev = [...prev, merged];
46
+ if (!nextItems.length) results.push([...newPrev, ...appendRemaining(queue.slice(i + 1))]);
47
+ else results.push(...next(newPrev, nextItems, queue.slice(i + 1)));
48
+ }
49
+ }
50
+ }
51
+ }
52
+ return results;
53
+ }
54
+ return next([], list2, getMergeOrders(list1.length));
55
+ }
56
+ /**
57
+ * Merge multiple arrays
58
+ */
59
+ function mergeMultipleArrays(lists, merge) {
60
+ if (!lists.length) return [];
61
+ let prevLists = [lists[0]];
62
+ for (let i = 1; i < lists.length; i++) {
63
+ const mergeWith = lists[i];
64
+ const newLists = [];
65
+ for (const prevList of prevLists) newLists.push(...mergeArrays(prevList, mergeWith, merge));
66
+ prevLists = newLists;
67
+ }
68
+ return prevLists;
69
+ }
70
+
71
+ export { mergeArrays, mergeMultipleArrays };
@@ -0,0 +1,6 @@
1
+ import { StateSelectorData } from "./types.js";
2
+ /**
3
+ * Merge sets of StateSelectorData into one
4
+ */
5
+ declare function mergeSelectorsForStates(data: StateSelectorData[]): StateSelectorData | null;
6
+ export { mergeSelectorsForStates };
@@ -0,0 +1,29 @@
1
+ import { mergeSelectorParts } from "./part/merge.js";
2
+
3
+ /**
4
+ * Merge sets of StateSelectorData into one
5
+ */
6
+ function mergeSelectorsForStates(data) {
7
+ const groupedResults = Object.create(null);
8
+ const next = (parents, key, index) => {
9
+ if (index >= data.length) {
10
+ const merged = mergeSelectorParts(parents);
11
+ if (!merged) return false;
12
+ if (!groupedResults[key]) groupedResults[key] = [];
13
+ groupedResults[key].push(...merged);
14
+ return true;
15
+ }
16
+ const group = data[index];
17
+ if (!group.length) return false;
18
+ for (let i = 0; i < group.length; i++) {
19
+ const items = group[i];
20
+ const nextKey = `${key}:${i}`;
21
+ for (const item of items) if (!next([...parents, item], nextKey, index + 1)) return false;
22
+ }
23
+ return true;
24
+ };
25
+ if (!next([], "", 0)) return null;
26
+ return Object.values(groupedResults);
27
+ }
28
+
29
+ export { mergeSelectorsForStates };
@@ -0,0 +1,13 @@
1
+ import { IconStatesList } from "../types.js";
2
+ import { StatefulIconSelectorsConfig, StatefulIconSelectorsContext } from "./types.js";
3
+ /**
4
+ * Create context object from config
5
+ */
6
+ declare function createStatefulIconSelectorsContext(config: StatefulIconSelectorsConfig, states: IconStatesList): StatefulIconSelectorsContext;
7
+ /**
8
+ * Get selectors to render state values
9
+ *
10
+ * Does not include shape class name
11
+ */
12
+ declare function getSelectorsForStateValues(context: StatefulIconSelectorsContext, value: string | Record<string, string | boolean>): string[][] | null;
13
+ export { createStatefulIconSelectorsContext, getSelectorsForStateValues };