@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.
Files changed (74) 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/helpers/data/compact.d.ts +20 -0
  41. package/lib/helpers/data/compact.js +38 -0
  42. package/lib/helpers/data/expand.d.ts +5 -0
  43. package/lib/helpers/data/expand.js +9 -0
  44. package/lib/index.d.ts +9 -4
  45. package/lib/index.js +5 -1
  46. package/lib/svg-css/icon/css.d.ts +25 -0
  47. package/lib/svg-css/icon/{css/stateful.js → css.js} +17 -5
  48. package/lib/svg-css/icon/types.d.ts +3 -3
  49. package/lib/svg-css/icon-set/add.d.ts +7 -0
  50. package/lib/svg-css/icon-set/add.js +52 -0
  51. package/lib/svg-css/icon-set/create.d.ts +6 -0
  52. package/lib/svg-css/icon-set/create.js +8 -0
  53. package/lib/svg-css/icon-set/get.d.ts +4 -0
  54. package/lib/svg-css/icon-set/get.js +92 -0
  55. package/lib/svg-css/icon-set/minify/expand.d.ts +10 -0
  56. package/lib/svg-css/icon-set/minify/expand.js +35 -0
  57. package/lib/svg-css/icon-set/minify/keys.d.ts +5 -0
  58. package/lib/svg-css/icon-set/minify/keys.js +9 -0
  59. package/lib/svg-css/icon-set/minify/minify.d.ts +19 -0
  60. package/lib/svg-css/icon-set/minify/minify.js +74 -0
  61. package/lib/svg-css/icon-set/types.d.ts +43 -0
  62. package/lib/svg-css/icon-set/types.js +1 -0
  63. package/lib/svg-css/states/fallback/parse.d.ts +1 -1
  64. package/lib/svg-css/states/fallback/stringify.d.ts +1 -1
  65. package/lib/svg-css/states/fallback/stringify.js +3 -2
  66. package/lib/svg-css/states/fallback/test.d.ts +1 -1
  67. package/lib/svg-css/states/validate.d.ts +6 -0
  68. package/lib/svg-css/states/validate.js +55 -0
  69. package/package.json +8 -8
  70. package/lib/components/helpers/css/name.d.ts +0 -7
  71. package/lib/components/helpers/css/name.js +0 -12
  72. package/lib/svg-css/icon/css/basic.d.ts +0 -13
  73. package/lib/svg-css/icon/css/basic.js +0 -26
  74. 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
- return template.map((chunk) => typeof chunk === "string" ? chunk : "values" in chunk ? chunk.values[+!!values[chunk.state]] : values[chunk.state]).join("");
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 };
@@ -1,5 +1,5 @@
1
- import { IconFallbackTemplate } from "./types.js";
2
1
  import { IconStatesList } from "../types.js";
2
+ import { IconFallbackTemplate } from "./types.js";
3
3
  /**
4
4
  * Parse and test fallback template string
5
5
  *
@@ -0,0 +1,6 @@
1
+ import { IconStatesList } from "./types.js";
2
+ /**
3
+ * Validates states list to avoid issues when generating icons
4
+ */
5
+ declare function assertValidStatesList(list: IconStatesList): void;
6
+ export { assertValidStatesList };
@@ -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.1.5",
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.3",
27
- "@eslint/js": "^9.39.2",
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.2.3",
31
- "@typescript-eslint/eslint-plugin": "^8.55.0",
32
- "@typescript-eslint/parser": "^8.55.0",
33
- "eslint": "^9.39.2",
34
- "globals": "^17.3.0",
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,7 +0,0 @@
1
- /**
2
- * Generate import name for CSS module
3
- *
4
- * Should be cleaned up because dashes are not allowed
5
- */
6
- declare function generateCSSDefaultImportName(className: string): string;
7
- export { generateCSSDefaultImportName };
@@ -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 };