@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
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generate fallback string from template and states
|
|
3
3
|
*/
|
|
4
|
-
function getIconFallback(template, values) {
|
|
5
|
-
|
|
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("");
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
export { getIconFallback };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const reservedStateNames = new Set([
|
|
2
|
+
"constructor",
|
|
3
|
+
"class",
|
|
4
|
+
"in",
|
|
5
|
+
"of",
|
|
6
|
+
"if",
|
|
7
|
+
"for",
|
|
8
|
+
"while",
|
|
9
|
+
"switch",
|
|
10
|
+
"case",
|
|
11
|
+
"break",
|
|
12
|
+
"continue",
|
|
13
|
+
"default",
|
|
14
|
+
"do",
|
|
15
|
+
"else",
|
|
16
|
+
"finally",
|
|
17
|
+
"return",
|
|
18
|
+
"throw",
|
|
19
|
+
"try",
|
|
20
|
+
"catch",
|
|
21
|
+
"with",
|
|
22
|
+
"yield",
|
|
23
|
+
"async",
|
|
24
|
+
"await",
|
|
25
|
+
"static",
|
|
26
|
+
"using",
|
|
27
|
+
"function",
|
|
28
|
+
"var",
|
|
29
|
+
"let",
|
|
30
|
+
"const",
|
|
31
|
+
"this",
|
|
32
|
+
"import",
|
|
33
|
+
"export",
|
|
34
|
+
"props",
|
|
35
|
+
"classname",
|
|
36
|
+
"viewbox",
|
|
37
|
+
"fallback",
|
|
38
|
+
"states",
|
|
39
|
+
"width",
|
|
40
|
+
"height",
|
|
41
|
+
"size",
|
|
42
|
+
"square"
|
|
43
|
+
]);
|
|
44
|
+
/**
|
|
45
|
+
* Validates states list to avoid issues when generating icons
|
|
46
|
+
*/
|
|
47
|
+
function assertValidStatesList(list) {
|
|
48
|
+
for (const state of list) {
|
|
49
|
+
const stateName = typeof state === "string" ? state : state[0];
|
|
50
|
+
if (!stateName.match(/^[a-z$]+$/)) throw new Error(`Invalid state name "${stateName}".`);
|
|
51
|
+
if (reservedStateNames.has(stateName)) throw new Error(`State name "${stateName}" is reserved to avoid conflicts and cannot be used.`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { assertValidStatesList };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "Common functions for working with SVG used by various packages.",
|
|
5
5
|
"author": "Vjacheslav Trushkin",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.2.0",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bugs": "https://github.com/cyberalien/svg-utils/issues",
|
|
9
9
|
"homepage": "https://cyberalien.dev/",
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
"@iconify/types": "^2.0.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@eslint/eslintrc": "^3.3.
|
|
27
|
-
"@eslint/js": "^9.39.
|
|
26
|
+
"@eslint/eslintrc": "^3.3.4",
|
|
27
|
+
"@eslint/js": "^9.39.3",
|
|
28
28
|
"@iconify-json/ri": "^1.2.10",
|
|
29
29
|
"@types/jest": "^30.0.0",
|
|
30
|
-
"@types/node": "^25.
|
|
31
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
32
|
-
"@typescript-eslint/parser": "^8.
|
|
33
|
-
"eslint": "^9.39.
|
|
34
|
-
"globals": "^17.
|
|
30
|
+
"@types/node": "^25.3.3",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
32
|
+
"@typescript-eslint/parser": "^8.56.1",
|
|
33
|
+
"eslint": "^9.39.3",
|
|
34
|
+
"globals": "^17.4.0",
|
|
35
35
|
"tsdown": "^0.20.3",
|
|
36
36
|
"typescript": "^5.9.3",
|
|
37
37
|
"vitest": "^4.0.18"
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { camelize } from "../../../helpers/misc/strings.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Generate import name for CSS module
|
|
5
|
-
*
|
|
6
|
-
* Should be cleaned up because dashes are not allowed
|
|
7
|
-
*/
|
|
8
|
-
function generateCSSDefaultImportName(className) {
|
|
9
|
-
return camelize("css-" + className);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { generateCSSDefaultImportName };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { CSSGeneratedStylesheet } from "../../../css/types.js";
|
|
2
|
-
import { SVGCSSIcon } from "../types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Add styles for icon to stylesheet
|
|
5
|
-
*
|
|
6
|
-
* If commonStylesheet is an object, all styles will be added to it and result
|
|
7
|
-
* will contain the same stylesheet for all classes.
|
|
8
|
-
*
|
|
9
|
-
* If commonStylesheet is not an object, styles will be separated into different
|
|
10
|
-
* stylesheets for classes and keyframes, which can be reused across icons.
|
|
11
|
-
*/
|
|
12
|
-
declare function renderSVGCSSIconStyle(icon: SVGCSSIcon, commonStylesheet?: CSSGeneratedStylesheet | ((selector: string) => CSSGeneratedStylesheet)): Record<string, CSSGeneratedStylesheet>;
|
|
13
|
-
export { renderSVGCSSIconStyle };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { addGeneratedSelector, createEmptyStylesheet } from "../../../css/stylesheet.js";
|
|
2
|
-
import { prefersReduceMotion } from "../../../helpers/reduce-motion.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Add styles for icon to stylesheet
|
|
6
|
-
*
|
|
7
|
-
* If commonStylesheet is an object, all styles will be added to it and result
|
|
8
|
-
* will contain the same stylesheet for all classes.
|
|
9
|
-
*
|
|
10
|
-
* If commonStylesheet is not an object, styles will be separated into different
|
|
11
|
-
* stylesheets for classes and keyframes, which can be reused across icons.
|
|
12
|
-
*/
|
|
13
|
-
function renderSVGCSSIconStyle(icon, commonStylesheet = createEmptyStylesheet) {
|
|
14
|
-
const stylesheets = Object.create(null);
|
|
15
|
-
const getStylesheet = (className) => {
|
|
16
|
-
if (typeof commonStylesheet === "object") return commonStylesheet;
|
|
17
|
-
if (!stylesheets[className]) stylesheets[className] = commonStylesheet(className);
|
|
18
|
-
return stylesheets[className];
|
|
19
|
-
};
|
|
20
|
-
for (const className in icon.classes) addGeneratedSelector(getStylesheet(className), [`.${className}`], icon.classes[className]);
|
|
21
|
-
for (const className in icon.animations) addGeneratedSelector(getStylesheet(className), [prefersReduceMotion, `.${className}`], icon.animations[className]);
|
|
22
|
-
for (const keyframeName in icon.keyframes) getStylesheet(keyframeName).keyframes[keyframeName] = icon.keyframes[keyframeName];
|
|
23
|
-
return stylesheets;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export { renderSVGCSSIconStyle };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { CSSGeneratedStylesheet } from "../../../css/types.js";
|
|
2
|
-
import { SVGCSSStatefulIcon } from "../types.js";
|
|
3
|
-
import { StatefulIconSelectorsContext } from "../../states/selector/types.js";
|
|
4
|
-
/**
|
|
5
|
-
* Add styles for stateful icon to stylesheet
|
|
6
|
-
*
|
|
7
|
-
* If commonStylesheet is an object, all styles will be added to it and result
|
|
8
|
-
* will contain the same stylesheet for all classes.
|
|
9
|
-
*
|
|
10
|
-
* If commonStylesheet is not an object, styles will be separated into different
|
|
11
|
-
* stylesheets for classes and keyframes, which can be reused across icons.
|
|
12
|
-
*/
|
|
13
|
-
declare function renderStatefulSVGCSSIconStyle(icon: SVGCSSStatefulIcon, context: StatefulIconSelectorsContext, commonStylesheet?: CSSGeneratedStylesheet | ((selector: string) => CSSGeneratedStylesheet)): Record<string, CSSGeneratedStylesheet>;
|
|
14
|
-
export { renderStatefulSVGCSSIconStyle };
|