@cyberalien/svg-utils 1.1.5 → 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.
- package/lib/components/export/merge.js +3 -1
- package/lib/components/helpers/content/stringify.d.ts +2 -2
- package/lib/components/helpers/content/stringify.js +4 -10
- package/lib/components/helpers/css/generate.d.ts +2 -1
- package/lib/components/helpers/css/generate.js +43 -46
- package/lib/components/helpers/filenames/css.d.ts +1 -1
- package/lib/components/helpers/filenames/css.js +2 -3
- package/lib/components/helpers/functions/custom.d.ts +14 -0
- package/lib/components/helpers/functions/custom.js +17 -0
- package/lib/components/helpers/functions/fallback.d.ts +8 -0
- package/lib/components/helpers/functions/fallback.js +53 -0
- package/lib/components/helpers/functions/innerhtml.d.ts +8 -0
- package/lib/components/helpers/functions/innerhtml.js +35 -0
- package/lib/components/helpers/functions/size.js +1 -1
- package/lib/components/helpers/imports/create.js +1 -2
- package/lib/components/helpers/imports/stringify.js +0 -2
- package/lib/components/helpers/imports/types.d.ts +0 -1
- package/lib/components/jsx.js +79 -8
- package/lib/components/prepare/iconify.d.ts +1 -1
- package/lib/components/prepare/iconify.js +6 -4
- package/lib/components/prepare/states.d.ts +8 -0
- package/lib/components/prepare/states.js +73 -0
- package/lib/components/raw.js +10 -7
- package/lib/components/svelte.js +73 -14
- package/lib/components/types/component.d.ts +2 -1
- package/lib/components/types/css.d.ts +1 -2
- package/lib/components/types/data.d.ts +0 -3
- package/lib/components/types/options.d.ts +9 -2
- package/lib/components/types/source.d.ts +21 -6
- package/lib/components/vue-func.js +71 -12
- package/lib/components/vue.js +70 -13
- package/lib/css/find/animations.d.ts +10 -0
- package/lib/css/find/animations.js +35 -0
- package/lib/css/find/classname.d.ts +5 -0
- package/lib/css/find/classname.js +14 -0
- package/lib/css/find/prop.d.ts +5 -0
- package/lib/css/find/prop.js +12 -0
- package/lib/css/minify.d.ts +2 -0
- package/lib/css/minify.js +5 -0
- package/lib/helpers/data/compact.d.ts +20 -0
- package/lib/helpers/data/compact.js +38 -0
- package/lib/helpers/data/expand.d.ts +5 -0
- package/lib/helpers/data/expand.js +9 -0
- package/lib/index.d.ts +9 -4
- package/lib/index.js +5 -1
- package/lib/svg-css/icon/css.d.ts +25 -0
- package/lib/svg-css/icon/{css/stateful.js → css.js} +17 -5
- package/lib/svg-css/icon/types.d.ts +3 -3
- package/lib/svg-css/icon-set/add.d.ts +7 -0
- package/lib/svg-css/icon-set/add.js +52 -0
- package/lib/svg-css/icon-set/create.d.ts +6 -0
- package/lib/svg-css/icon-set/create.js +8 -0
- package/lib/svg-css/icon-set/get.d.ts +4 -0
- package/lib/svg-css/icon-set/get.js +92 -0
- package/lib/svg-css/icon-set/minify/expand.d.ts +10 -0
- package/lib/svg-css/icon-set/minify/expand.js +35 -0
- package/lib/svg-css/icon-set/minify/keys.d.ts +5 -0
- package/lib/svg-css/icon-set/minify/keys.js +9 -0
- package/lib/svg-css/icon-set/minify/minify.d.ts +19 -0
- package/lib/svg-css/icon-set/minify/minify.js +74 -0
- package/lib/svg-css/icon-set/types.d.ts +43 -0
- package/lib/svg-css/icon-set/types.js +1 -0
- package/lib/svg-css/states/fallback/parse.d.ts +1 -1
- package/lib/svg-css/states/fallback/stringify.d.ts +1 -1
- package/lib/svg-css/states/fallback/stringify.js +3 -2
- package/lib/svg-css/states/fallback/test.d.ts +1 -1
- package/lib/svg-css/states/validate.d.ts +6 -0
- package/lib/svg-css/states/validate.js +55 -0
- package/package.json +8 -8
- package/lib/components/helpers/css/name.d.ts +0 -7
- package/lib/components/helpers/css/name.js +0 -12
- package/lib/svg-css/icon/css/basic.d.ts +0 -13
- package/lib/svg-css/icon/css/basic.js +0 -26
- package/lib/svg-css/icon/css/stateful.d.ts +0 -14
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find all values of a CSS property in content
|
|
3
|
+
*/
|
|
4
|
+
function findCSSPropertyValues(content, property) {
|
|
5
|
+
const values = [];
|
|
6
|
+
content.matchAll(new RegExp(`${property}\\s*:\\s*([^;]+);`, "g")).forEach((match) => {
|
|
7
|
+
values.push(...match[1].split(",").map((part) => part.trim()));
|
|
8
|
+
});
|
|
9
|
+
return values;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { findCSSPropertyValues };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface ContextItemData<T> {
|
|
2
|
+
parent: Record<string, unknown>;
|
|
3
|
+
key: string;
|
|
4
|
+
actualValue?: T;
|
|
5
|
+
}
|
|
6
|
+
interface ContextItem<T> {
|
|
7
|
+
map: Map<string, ContextItemData<T> | number>;
|
|
8
|
+
data: T[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create context item for minification
|
|
12
|
+
*/
|
|
13
|
+
declare function createCompactContext<T>(): ContextItem<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Minify item
|
|
16
|
+
*
|
|
17
|
+
* If value is not a string, set it in `actualValue` and string `value` for comparison
|
|
18
|
+
*/
|
|
19
|
+
declare function compactItem<T>(context: ContextItem<T>, stringifiedValue: string, parent: Record<string, unknown>, key: string, actualValue?: T): void;
|
|
20
|
+
export { compactItem, createCompactContext };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create context item for minification
|
|
3
|
+
*/
|
|
4
|
+
function createCompactContext() {
|
|
5
|
+
return {
|
|
6
|
+
map: /* @__PURE__ */ new Map(),
|
|
7
|
+
data: []
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Minify item
|
|
12
|
+
*
|
|
13
|
+
* If value is not a string, set it in `actualValue` and string `value` for comparison
|
|
14
|
+
*/
|
|
15
|
+
function compactItem(context, stringifiedValue, parent, key, actualValue) {
|
|
16
|
+
const { map, data } = context;
|
|
17
|
+
const existing = map.get(stringifiedValue);
|
|
18
|
+
if (typeof existing === "number") {
|
|
19
|
+
parent[key] = existing;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const value = actualValue ?? stringifiedValue;
|
|
23
|
+
if (existing) {
|
|
24
|
+
const index = data.length;
|
|
25
|
+
data.push(value);
|
|
26
|
+
map.set(stringifiedValue, index);
|
|
27
|
+
parent[key] = index;
|
|
28
|
+
existing.parent[existing.key] = index;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
map.set(stringifiedValue, {
|
|
32
|
+
parent,
|
|
33
|
+
key
|
|
34
|
+
});
|
|
35
|
+
parent[key] = value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { compactItem, createCompactContext };
|
package/lib/index.d.ts
CHANGED
|
@@ -2,9 +2,13 @@ import { ClassProp, classProps, defaultClassProp } from "./classname/const.js";
|
|
|
2
2
|
import { splitClassName, toggleClassName } from "./classname/toggle.js";
|
|
3
3
|
import { HashContext, UniqueHashOptions, UniqueHashPartialOptions } from "./helpers/hash/types.js";
|
|
4
4
|
import { CSSGeneratedSelector, CSSGeneratedSelectors, CSSGeneratedStylesheet, CSSHashOptions, CSSKeyframe, CSSKeyframes, CSSRules } from "./css/types.js";
|
|
5
|
+
import { IconStatesAdvancedState, IconStatesAdvancedStateValues, IconStatesList, IconStatesSimpleState, IconStatesState } from "./svg-css/states/types.js";
|
|
6
|
+
import { ExtendedSVGCSSIconClass, SVGCSSIcon, SVGCSSIconRules, SVGCSSStatefulIcon, SVGCSSStatefulIconRules } from "./svg-css/icon/types.js";
|
|
7
|
+
import { IconFallbackAdvancedState, IconFallbackBooleanState, IconFallbackTemplate } from "./svg-css/states/fallback/types.js";
|
|
5
8
|
import { ParsedXMLNode, ParsedXMLTagElement, ParsedXMLTextElement, StringifyXMLOptions } from "./xml/types.js";
|
|
6
9
|
import { BaseConvertSVGContentOptions, ConvertSVGContentOptions, ConvertedSVGContent } from "./svg-css/types.js";
|
|
7
10
|
import { createCSSClassName } from "./css/hash.js";
|
|
11
|
+
import { minifyCSS } from "./css/minify.js";
|
|
8
12
|
import { mergeCSSRules, splitCSSRules } from "./css/rules.js";
|
|
9
13
|
import { stringifyCSSAnimationFrames, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector } from "./css/stringify.js";
|
|
10
14
|
import { addGeneratedSelector, createEmptyStylesheet, stringifyStylesheet } from "./css/stylesheet.js";
|
|
@@ -28,11 +32,12 @@ import { changeSVGIDs } from "./svg/ids/change.js";
|
|
|
28
32
|
import { createUniqueIDs } from "./svg/ids/unique.js";
|
|
29
33
|
import { convertSVGRootToCSS } from "./svg-css/root.js";
|
|
30
34
|
import { convertSVGContentToCSSRules } from "./svg-css/content.js";
|
|
31
|
-
import { IconFallbackAdvancedState, IconFallbackBooleanState, IconFallbackTemplate } from "./svg-css/states/fallback/types.js";
|
|
32
35
|
import { getIconFallback } from "./svg-css/states/fallback/stringify.js";
|
|
33
|
-
import { IconStatesAdvancedState, IconStatesAdvancedStateValues, IconStatesList, IconStatesSimpleState, IconStatesState } from "./svg-css/states/types.js";
|
|
34
36
|
import { getStatesFromKey } from "./svg-css/states/key.js";
|
|
35
37
|
import { getObjectFromStates } from "./svg-css/states/object.js";
|
|
36
38
|
import { getAdvancedStateDefaultValue, getStateValue } from "./svg-css/states/value.js";
|
|
37
|
-
import {
|
|
38
|
-
|
|
39
|
+
import { SVGCSSIconSet, SVGCSSIconSetClassData, SVGCSSIconSetIcon, SVGCSSIconSetSharedData } from "./svg-css/icon-set/types.js";
|
|
40
|
+
import { getSVGCSSIconFromIconSet } from "./svg-css/icon-set/get.js";
|
|
41
|
+
import { addIconToSVGCSSIconSet } from "./svg-css/icon-set/add.js";
|
|
42
|
+
import { createEmptySVGCSSIconSet } from "./svg-css/icon-set/create.js";
|
|
43
|
+
export { BaseConvertSVGContentOptions, CSSGeneratedSelector, CSSGeneratedSelectors, CSSGeneratedStylesheet, CSSHashOptions, CSSKeyframe, CSSKeyframes, CSSRules, ChangeIDResult, ClassProp, ComparisonKey, ConvertSVGContentOptions, ConvertedSVGContent, ExtendedSVGCSSIconClass, HashContext, IconFallbackAdvancedState, IconFallbackBooleanState, IconFallbackTemplate, IconStatesAdvancedState, IconStatesAdvancedStateValues, IconStatesList, IconStatesSimpleState, IconStatesState, ParsedXMLNode, ParsedXMLTagElement, ParsedXMLTextElement, SVGCSSIcon, SVGCSSIconRules, SVGCSSIconSet, SVGCSSIconSetClassData, SVGCSSIconSetIcon, SVGCSSIconSetSharedData, SVGCSSStatefulIcon, SVGCSSStatefulIconRules, StringifyXMLOptions, UniqueHashOptions, UniqueHashPartialOptions, UniqueIDOptions, addGeneratedSelector, addIconToSVGCSSIconSet, changeIDInString, changeSVGIDs, classProps, cloneObject, compareKeys, compareSets, compareValues, convertSVGContentToCSSRules, convertSVGRootToCSS, createCSSClassName, createEmptySVGCSSIconSet, createEmptyStylesheet, createUniqueHashContext, createUniqueIDs, defaultClassProp, getAdvancedStateDefaultValue, getIconFallback, getObjectFromStates, getSVGCSSIconFromIconSet, getStateValue, getStatesFromKey, getUniqueHash, hashString, hashToString, iterateXMLContent, mergeCSSRules, minifyCSS, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitCSSRules, splitClassName, stringifyCSSAnimationFrames, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector, stringifyStylesheet, stringifyXMLContent, toggleClassName, uniquePromise };
|
package/lib/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import { stringifyXMLContent } from "./xml/stringify.js";
|
|
|
13
13
|
import { createCSSClassName } from "./css/hash.js";
|
|
14
14
|
import { stringifyCSSAnimationFrames, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector } from "./css/stringify.js";
|
|
15
15
|
import { mergeCSSRules, splitCSSRules } from "./css/rules.js";
|
|
16
|
+
import { minifyCSS } from "./css/minify.js";
|
|
16
17
|
import { addGeneratedSelector, createEmptyStylesheet, stringifyStylesheet } from "./css/stylesheet.js";
|
|
17
18
|
import { classProps, defaultClassProp } from "./classname/const.js";
|
|
18
19
|
import { splitClassName, toggleClassName } from "./classname/toggle.js";
|
|
@@ -27,5 +28,8 @@ import { getIconFallback } from "./svg-css/states/fallback/stringify.js";
|
|
|
27
28
|
import { getStatesFromKey } from "./svg-css/states/key.js";
|
|
28
29
|
import { getAdvancedStateDefaultValue, getStateValue } from "./svg-css/states/value.js";
|
|
29
30
|
import { getObjectFromStates } from "./svg-css/states/object.js";
|
|
31
|
+
import { getSVGCSSIconFromIconSet } from "./svg-css/icon-set/get.js";
|
|
32
|
+
import { addIconToSVGCSSIconSet } from "./svg-css/icon-set/add.js";
|
|
33
|
+
import { createEmptySVGCSSIconSet } from "./svg-css/icon-set/create.js";
|
|
30
34
|
|
|
31
|
-
export { addGeneratedSelector, changeIDInString, changeSVGIDs, classProps, cloneObject, compareKeys, compareSets, compareValues, convertSVGContentToCSSRules, convertSVGRootToCSS, createCSSClassName, createEmptyStylesheet, createUniqueHashContext, createUniqueIDs, defaultClassProp, getAdvancedStateDefaultValue, getIconFallback, getObjectFromStates, getStateValue, getStatesFromKey, getUniqueHash, hashString, hashToString, iterateXMLContent, mergeCSSRules, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitCSSRules, splitClassName, stringifyCSSAnimationFrames, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector, stringifyStylesheet, stringifyXMLContent, toggleClassName, uniquePromise };
|
|
35
|
+
export { addGeneratedSelector, addIconToSVGCSSIconSet, changeIDInString, changeSVGIDs, classProps, cloneObject, compareKeys, compareSets, compareValues, convertSVGContentToCSSRules, convertSVGRootToCSS, createCSSClassName, createEmptySVGCSSIconSet, createEmptyStylesheet, createUniqueHashContext, createUniqueIDs, defaultClassProp, getAdvancedStateDefaultValue, getIconFallback, getObjectFromStates, getSVGCSSIconFromIconSet, getStateValue, getStatesFromKey, getUniqueHash, hashString, hashToString, iterateXMLContent, mergeCSSRules, minifyCSS, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitCSSRules, splitClassName, stringifyCSSAnimationFrames, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector, stringifyStylesheet, stringifyXMLContent, toggleClassName, uniquePromise };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CSSGeneratedStylesheet } from "../../css/types.js";
|
|
2
|
+
import { SVGCSSIconRules, SVGCSSStatefulIconRules } from "./types.js";
|
|
3
|
+
import { StatefulIconSelectorsContext } from "../states/selector/types.js";
|
|
4
|
+
type StylesheetParam = CSSGeneratedStylesheet | ((selector: string) => CSSGeneratedStylesheet);
|
|
5
|
+
/**
|
|
6
|
+
* Add styles for stateful icon to stylesheet
|
|
7
|
+
*
|
|
8
|
+
* If commonStylesheet is an object, all styles will be added to it and result
|
|
9
|
+
* will contain the same stylesheet for all classes.
|
|
10
|
+
*
|
|
11
|
+
* If commonStylesheet is not an object, styles will be separated into different
|
|
12
|
+
* stylesheets for classes and keyframes, which can be reused across icons.
|
|
13
|
+
*/
|
|
14
|
+
declare function renderStatefulSVGCSSIconStyle(icon: SVGCSSStatefulIconRules, context: StatefulIconSelectorsContext | null, commonStylesheet?: StylesheetParam): Record<string, CSSGeneratedStylesheet>;
|
|
15
|
+
/**
|
|
16
|
+
* Add styles for icon to stylesheet
|
|
17
|
+
*
|
|
18
|
+
* If commonStylesheet is an object, all styles will be added to it and result
|
|
19
|
+
* will contain the same stylesheet for all classes.
|
|
20
|
+
*
|
|
21
|
+
* If commonStylesheet is not an object, styles will be separated into different
|
|
22
|
+
* stylesheets for classes and keyframes, which can be reused across icons.
|
|
23
|
+
*/
|
|
24
|
+
declare function renderSVGCSSIconStyle(icon: SVGCSSIconRules, commonStylesheet?: StylesheetParam): Record<string, CSSGeneratedStylesheet>;
|
|
25
|
+
export { renderSVGCSSIconStyle, renderStatefulSVGCSSIconStyle };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { addGeneratedSelector, createEmptyStylesheet } from "
|
|
2
|
-
import { prefersReduceMotion } from "
|
|
3
|
-
import { getSelectorsForStateValues } from "
|
|
1
|
+
import { addGeneratedSelector, createEmptyStylesheet } from "../../css/stylesheet.js";
|
|
2
|
+
import { prefersReduceMotion } from "../../helpers/reduce-motion.js";
|
|
3
|
+
import { getSelectorsForStateValues } from "../states/selector/parse.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Add styles for stateful icon to stylesheet
|
|
@@ -21,7 +21,7 @@ function renderStatefulSVGCSSIconStyle(icon, context, commonStylesheet = createE
|
|
|
21
21
|
for (const className in icon.classes) addGeneratedSelector(getStylesheet(className), [`.${className}`], icon.classes[className]);
|
|
22
22
|
for (const className in icon.animations) addGeneratedSelector(getStylesheet(className), [prefersReduceMotion, `.${className}`], icon.animations[className]);
|
|
23
23
|
for (const keyframeName in icon.keyframes) getStylesheet(keyframeName).keyframes[keyframeName] = icon.keyframes[keyframeName];
|
|
24
|
-
for (const className in icon.statefulClasses) {
|
|
24
|
+
if (context) for (const className in icon.statefulClasses) {
|
|
25
25
|
const baseClassName = `.${className}`;
|
|
26
26
|
const stylesheet = getStylesheet(className);
|
|
27
27
|
const classData = icon.statefulClasses[className];
|
|
@@ -41,5 +41,17 @@ function renderStatefulSVGCSSIconStyle(icon, context, commonStylesheet = createE
|
|
|
41
41
|
}
|
|
42
42
|
return stylesheets;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Add styles for icon to stylesheet
|
|
46
|
+
*
|
|
47
|
+
* If commonStylesheet is an object, all styles will be added to it and result
|
|
48
|
+
* will contain the same stylesheet for all classes.
|
|
49
|
+
*
|
|
50
|
+
* If commonStylesheet is not an object, styles will be separated into different
|
|
51
|
+
* stylesheets for classes and keyframes, which can be reused across icons.
|
|
52
|
+
*/
|
|
53
|
+
function renderSVGCSSIconStyle(icon, commonStylesheet) {
|
|
54
|
+
return renderStatefulSVGCSSIconStyle(icon, null, commonStylesheet);
|
|
55
|
+
}
|
|
44
56
|
|
|
45
|
-
export { renderStatefulSVGCSSIconStyle };
|
|
57
|
+
export { renderSVGCSSIconStyle, renderStatefulSVGCSSIconStyle };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IconViewBox } from "../../svg/viewbox/types.js";
|
|
2
1
|
import { CSSKeyframes, CSSRules } from "../../css/types.js";
|
|
2
|
+
import { IconViewBox } from "../../svg/viewbox/types.js";
|
|
3
3
|
import { IconStatesList } from "../states/types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Main properties
|
|
@@ -10,7 +10,7 @@ interface MainProps {
|
|
|
10
10
|
content: string;
|
|
11
11
|
}
|
|
12
12
|
interface StatefulMainProps extends MainProps {
|
|
13
|
-
states
|
|
13
|
+
states?: IconStatesList;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* CSS data
|
|
@@ -42,4 +42,4 @@ interface SVGCSSIcon extends MainProps, SVGCSSIconRules {}
|
|
|
42
42
|
* Icon with states
|
|
43
43
|
*/
|
|
44
44
|
interface SVGCSSStatefulIcon extends StatefulMainProps, SVGCSSStatefulIconRules {}
|
|
45
|
-
export { SVGCSSIcon, SVGCSSIconRules, SVGCSSStatefulIcon, SVGCSSStatefulIconRules };
|
|
45
|
+
export { ExtendedSVGCSSIconClass, SVGCSSIcon, SVGCSSIconRules, SVGCSSStatefulIcon, SVGCSSStatefulIconRules };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SVGCSSIcon, SVGCSSStatefulIcon } from "../icon/types.js";
|
|
2
|
+
import { SVGCSSIconSet } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Add icon to an icon set
|
|
5
|
+
*/
|
|
6
|
+
declare function addIconToSVGCSSIconSet(iconSet: SVGCSSIconSet, iconName: string, icon: SVGCSSIcon | SVGCSSStatefulIcon): void;
|
|
7
|
+
export { addIconToSVGCSSIconSet };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { stringifyCSSAnimationFrames, stringifyCSSRules } from "../../css/stringify.js";
|
|
2
|
+
import { minifyCSS } from "../../css/minify.js";
|
|
3
|
+
|
|
4
|
+
function minifyRules(value) {
|
|
5
|
+
return (value ? minifyCSS(typeof value === "string" ? value : stringifyCSSRules(value)) : void 0) || void 0;
|
|
6
|
+
}
|
|
7
|
+
function stringifyObject(data) {
|
|
8
|
+
if (data) {
|
|
9
|
+
const result = Object.create(null);
|
|
10
|
+
for (const key in data) result[key] = minifyCSS(typeof data[key] === "string" ? data[key] : stringifyCSSRules(data[key]));
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Add icon to an icon set
|
|
16
|
+
*/
|
|
17
|
+
function addIconToSVGCSSIconSet(iconSet, iconName, icon) {
|
|
18
|
+
iconSet.icons[iconName] = {
|
|
19
|
+
content: icon.content,
|
|
20
|
+
fallback: icon.fallback,
|
|
21
|
+
states: icon.states,
|
|
22
|
+
viewBox: icon.viewBox
|
|
23
|
+
};
|
|
24
|
+
const { classes, animations, statefulClasses, keyframes } = icon;
|
|
25
|
+
const classNames = new Set([...Object.keys(classes || {}), ...Object.keys(statefulClasses || {})]);
|
|
26
|
+
for (const className of classNames) if (!iconSet.classes?.[className]) {
|
|
27
|
+
const classData = {};
|
|
28
|
+
iconSet.classes = iconSet.classes || Object.create(null);
|
|
29
|
+
iconSet.classes[className] = classData;
|
|
30
|
+
const r = classes?.[className];
|
|
31
|
+
if (r) classData.r = minifyRules(r);
|
|
32
|
+
const a = animations?.[className];
|
|
33
|
+
if (a) classData.a = minifyRules(a);
|
|
34
|
+
const statefulClass = statefulClasses?.[className];
|
|
35
|
+
if (statefulClass) {
|
|
36
|
+
const { stateRules, transition, stateTransition } = statefulClass;
|
|
37
|
+
if (stateRules) classData.sr = stringifyObject(stateRules);
|
|
38
|
+
if (transition) classData.t = minifyRules(transition);
|
|
39
|
+
if (stateTransition) classData.st = stringifyObject(stateTransition);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (keyframes) {
|
|
43
|
+
iconSet.keyframes = iconSet.keyframes || Object.create(null);
|
|
44
|
+
const iconSetKeyframes = iconSet.keyframes;
|
|
45
|
+
for (const keyframeName in keyframes) if (!iconSetKeyframes[keyframeName]) {
|
|
46
|
+
const value = keyframes[keyframeName];
|
|
47
|
+
iconSetKeyframes[keyframeName] = typeof value === "string" ? value : minifyCSS(stringifyCSSAnimationFrames(value));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { addIconToSVGCSSIconSet };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SVGCSSIcon, SVGCSSStatefulIcon } from "../icon/types.js";
|
|
2
|
+
import { SVGCSSIconSet } from "./types.js";
|
|
3
|
+
declare function getSVGCSSIconFromIconSet(iconSet: SVGCSSIconSet, name: string): SVGCSSIcon | SVGCSSStatefulIcon | undefined;
|
|
4
|
+
export { getSVGCSSIconFromIconSet };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { findUsedKeyframes } from "../../css/find/animations.js";
|
|
2
|
+
import { findUsedClassNames } from "../../css/find/classname.js";
|
|
3
|
+
import { expandSVGCSSIconSetClass } from "./minify/expand.js";
|
|
4
|
+
|
|
5
|
+
function getSVGCSSIconFromIconSet(iconSet, name) {
|
|
6
|
+
const fullName = iconSet.aliases?.[name] || name;
|
|
7
|
+
const data = iconSet.icons[fullName];
|
|
8
|
+
if (!data) return;
|
|
9
|
+
const { viewBoxes, css, fallbackPrefix = "", fallbackSuffix = "" } = iconSet;
|
|
10
|
+
let viewBox = data.viewBox;
|
|
11
|
+
if (typeof viewBox === "number") viewBox = viewBoxes?.[viewBox];
|
|
12
|
+
if (!viewBox) return;
|
|
13
|
+
let states = data.states;
|
|
14
|
+
if (typeof states === "number") states = iconSet.statesList?.[states];
|
|
15
|
+
const content = data.content;
|
|
16
|
+
const classNames = findUsedClassNames(content);
|
|
17
|
+
const classes = Object.create(null);
|
|
18
|
+
const animations = Object.create(null);
|
|
19
|
+
const statefulClasses = Object.create(null);
|
|
20
|
+
const cssLines = [];
|
|
21
|
+
classNames.forEach((className) => {
|
|
22
|
+
const classContent = iconSet.classes?.[className];
|
|
23
|
+
if (classContent) {
|
|
24
|
+
if (css) expandSVGCSSIconSetClass(css, classContent);
|
|
25
|
+
const { r, a, t, sr, st } = classContent;
|
|
26
|
+
const statefulClass = Object.create(null);
|
|
27
|
+
if (r) {
|
|
28
|
+
classes[className] = r;
|
|
29
|
+
cssLines.push(r);
|
|
30
|
+
}
|
|
31
|
+
if (a) {
|
|
32
|
+
animations[className] = a;
|
|
33
|
+
cssLines.push(a);
|
|
34
|
+
}
|
|
35
|
+
if (sr) {
|
|
36
|
+
const stateRules = Object.create(null);
|
|
37
|
+
statefulClass.stateRules = stateRules;
|
|
38
|
+
for (const state in sr) {
|
|
39
|
+
stateRules[state] = sr[state];
|
|
40
|
+
cssLines.push(sr[state]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (t) {
|
|
44
|
+
statefulClass.transition = t;
|
|
45
|
+
cssLines.push(t);
|
|
46
|
+
}
|
|
47
|
+
if (st) {
|
|
48
|
+
const stateTransition = Object.create(null);
|
|
49
|
+
statefulClass.stateTransition = stateTransition;
|
|
50
|
+
for (const state in st) {
|
|
51
|
+
stateTransition[state] = st[state];
|
|
52
|
+
cssLines.push(st[state]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (const key in statefulClass) {
|
|
56
|
+
statefulClasses[className] = statefulClass;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
const keyframes = Object.create(null);
|
|
62
|
+
if (iconSet.keyframes) findUsedKeyframes(cssLines.join(";")).forEach((animationName) => {
|
|
63
|
+
const keyframeContent = iconSet.keyframes[animationName];
|
|
64
|
+
if (keyframeContent) keyframes[animationName] = keyframeContent;
|
|
65
|
+
});
|
|
66
|
+
const result = {
|
|
67
|
+
content,
|
|
68
|
+
viewBox,
|
|
69
|
+
states,
|
|
70
|
+
fallback: typeof data.fallback === "string" ? `${fallbackPrefix}${data.fallback}${fallbackSuffix}` : void 0
|
|
71
|
+
};
|
|
72
|
+
let _key;
|
|
73
|
+
for (_key in classes) {
|
|
74
|
+
result.classes = classes;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
for (_key in animations) {
|
|
78
|
+
result.animations = animations;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
for (_key in keyframes) {
|
|
82
|
+
result.keyframes = keyframes;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
for (_key in statefulClasses) {
|
|
86
|
+
result.statefulClasses = statefulClasses;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { getSVGCSSIconFromIconSet };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SVGCSSIconSet, SVGCSSIconSetClassData } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Expand class content from icon set
|
|
4
|
+
*/
|
|
5
|
+
declare function expandSVGCSSIconSetClass(css: Required<SVGCSSIconSet>['css'], classContent: SVGCSSIconSetClassData): void;
|
|
6
|
+
/**
|
|
7
|
+
* Unminify icon set
|
|
8
|
+
*/
|
|
9
|
+
declare function expandSVGCSSIconSet(iconSet: SVGCSSIconSet): void;
|
|
10
|
+
export { expandSVGCSSIconSet, expandSVGCSSIconSetClass };
|
|
@@ -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 { };
|
|
@@ -2,5 +2,5 @@ import { IconFallbackTemplate } from "./types.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Generate fallback string from template and states
|
|
4
4
|
*/
|
|
5
|
-
declare function getIconFallback(template: IconFallbackTemplate, values: Record<string, boolean | string>): string;
|
|
5
|
+
declare function getIconFallback(template: IconFallbackTemplate, values: Record<string, boolean | string>, defaultValues?: Record<string, boolean | string>): string;
|
|
6
6
|
export { getIconFallback };
|