@cyberalien/svg-utils 1.2.7 → 1.2.8

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.
@@ -3,7 +3,7 @@ import { GeneratedAssetFile } from "../../types/component.js";
3
3
  import { ComponentFactorySource } from "../../types/source.js";
4
4
  import { ComponentFactoryOptions } from "../../types/options.js";
5
5
  import { FactoryComponentImports } from "../imports/types.js";
6
- interface Options extends Pick<ComponentFactoryOptions, 'cssMode' | 'cssPath' | 'doubleDirsForCSS' | 'mergeCSS'> {
6
+ interface Options extends Pick<ComponentFactoryOptions, 'cssMode' | 'cssPath' | 'doubleDirsForCSS' | 'mergeCSS' | 'staticState'> {
7
7
  componentType?: 'svelte';
8
8
  }
9
9
  /**
@@ -59,8 +59,8 @@ function createJSXComponent(data, options) {
59
59
  };
60
60
  let computedFallback = false;
61
61
  if (statefulData) {
62
- const { supportedStates, allStates } = statefulData;
63
- if (supportedStates.size) {
62
+ const { supportedStates, allStates, staticClassname } = statefulData;
63
+ if (supportedStates.size || staticClassname) {
64
64
  const computedStates = [];
65
65
  const computedStateNames = [];
66
66
  let addedStateFunc = false;
@@ -97,6 +97,16 @@ function createJSXComponent(data, options) {
97
97
  }
98
98
  }
99
99
  }
100
+ if (staticClassname) {
101
+ const state = "static";
102
+ props[state] = {
103
+ type: "boolean",
104
+ value: state,
105
+ template: ""
106
+ };
107
+ computedStates.push(`'${state}': ${state}`);
108
+ computedStateNames.push(state);
109
+ }
100
110
  if (computedStates.length) {
101
111
  componentInternalCode.push(`const states = useMemo(() => ({ ${computedStates.join(", ")} }), [${computedStateNames.join(", ")}]);`);
102
112
  if (hasFallback && statefulData.fallback) {
@@ -34,12 +34,14 @@ function prepareComponentFactoryStatefulIcon(icon, options) {
34
34
  supportedStateValues[stateName] = defaultValue;
35
35
  }
36
36
  }
37
+ const staticClassname = Object.keys(icon.animations ?? {}).length > 0 && options?.staticState !== false ? "state-static" : void 0;
37
38
  const statefulData = {
38
39
  allStates,
39
40
  supportedStates,
40
41
  defaultStateValues,
41
42
  supportedStateValues,
42
- context: createStatefulIconSelectorsContext(config, allStates)
43
+ staticClassname,
44
+ context: createStatefulIconSelectorsContext(config, allStates, staticClassname)
43
45
  };
44
46
  if (isStatefulFallback) {
45
47
  let fallbackTemplate = parseIconFallbackTemplate(fallback, allStates);
@@ -44,8 +44,8 @@ function createSolidComponent(data, options) {
44
44
  if (!fallback) props.xmlns = "http://www.w3.org/2000/svg";
45
45
  let computedFallback = false;
46
46
  if (statefulData) {
47
- const { supportedStates, allStates } = statefulData;
48
- if (supportedStates.size) {
47
+ const { supportedStates, allStates, staticClassname } = statefulData;
48
+ if (supportedStates.size || staticClassname) {
49
49
  const computedStates = [];
50
50
  let addedStateFunc = false;
51
51
  for (const state of allStates) if (typeof state === "string") {
@@ -79,6 +79,15 @@ function createSolidComponent(data, options) {
79
79
  }
80
80
  }
81
81
  }
82
+ if (staticClassname) {
83
+ const state = "static";
84
+ props[state] = {
85
+ type: "boolean",
86
+ value: state,
87
+ template: ""
88
+ };
89
+ computedStates.push(`'${state}': local['${state}']`);
90
+ }
82
91
  if (computedStates.length) {
83
92
  componentInternalCode.push(`const states = createMemo(() => ({ ${computedStates.join(", ")} }));`);
84
93
  if (fallback && statefulData.fallback) {
@@ -44,8 +44,8 @@ function createSvelteComponent(data, options) {
44
44
  if (!fallback) props.xmlns = "http://www.w3.org/2000/svg";
45
45
  let computedFallback = false;
46
46
  if (statefulData) {
47
- const { supportedStates, allStates } = statefulData;
48
- if (supportedStates.size) {
47
+ const { supportedStates, allStates, staticClassname } = statefulData;
48
+ if (supportedStates.size || staticClassname) {
49
49
  const computedStates = [];
50
50
  let addedStateFunc = false;
51
51
  for (const state of allStates) if (typeof state === "string") {
@@ -79,6 +79,15 @@ function createSvelteComponent(data, options) {
79
79
  }
80
80
  }
81
81
  }
82
+ if (staticClassname) {
83
+ const state = "static";
84
+ props[state] = {
85
+ type: "boolean",
86
+ value: state,
87
+ template: ""
88
+ };
89
+ computedStates.push(`'${state}': ${state}`);
90
+ }
82
91
  if (computedStates.length) {
83
92
  componentCode.push(`let states = $derived(({ ${computedStates.join(", ")} }));`);
84
93
  if (fallback && statefulData.fallback) {
@@ -25,6 +25,7 @@ interface ComponentFactoryFileSystemOptions {
25
25
  */
26
26
  interface ComponentFactoryStatefulIconRenderingOptions {
27
27
  stateSelectors?: StatefulIconSelectorsConfig;
28
+ staticState?: boolean;
28
29
  }
29
30
  /**
30
31
  * Rendering options for component factory
@@ -10,6 +10,7 @@ interface StatefulComponentFactorySource {
10
10
  fallback?: IconFallbackTemplate;
11
11
  allStates: IconStatesList;
12
12
  supportedStates: Set<string>;
13
+ staticClassname?: string;
13
14
  defaultStateValues: Record<string, string | boolean>;
14
15
  supportedStateValues: Record<string, string | boolean>;
15
16
  context: StatefulIconSelectorsContext;
@@ -42,8 +42,8 @@ function createVueFunctionalComponent(data, options) {
42
42
  if (!fallback) props.xmlns = "http://www.w3.org/2000/svg";
43
43
  let computedFallback = false;
44
44
  if (statefulData) {
45
- const { supportedStates, allStates } = statefulData;
46
- if (supportedStates.size) {
45
+ const { supportedStates, allStates, staticClassname } = statefulData;
46
+ if (supportedStates.size || staticClassname) {
47
47
  const computedStates = [];
48
48
  let addedStateFunc = false;
49
49
  for (const state of allStates) if (typeof state === "string") {
@@ -77,6 +77,15 @@ function createVueFunctionalComponent(data, options) {
77
77
  }
78
78
  }
79
79
  }
80
+ if (staticClassname) {
81
+ const state = "static";
82
+ props[state] = {
83
+ type: "boolean",
84
+ value: state,
85
+ template: ""
86
+ };
87
+ computedStates.push(`'${state}': props['${state}']`);
88
+ }
80
89
  if (computedStates.length) {
81
90
  componentCode.push(`const states = computed(() => ({ ${computedStates.join(", ")} }));`);
82
91
  if (fallback && statefulData.fallback) {
@@ -43,8 +43,8 @@ function createVueComponent(data, options) {
43
43
  if (!fallback) props.xmlns = "http://www.w3.org/2000/svg";
44
44
  let computedFallback = false;
45
45
  if (statefulData) {
46
- const { supportedStates, allStates } = statefulData;
47
- if (supportedStates.size) {
46
+ const { supportedStates, allStates, staticClassname } = statefulData;
47
+ if (supportedStates.size || staticClassname) {
48
48
  const computedStates = [];
49
49
  let addedStateFunc = false;
50
50
  for (const state of allStates) if (typeof state === "string") {
@@ -78,6 +78,15 @@ function createVueComponent(data, options) {
78
78
  }
79
79
  }
80
80
  }
81
+ if (staticClassname) {
82
+ const state = "static";
83
+ props[state] = {
84
+ type: "boolean",
85
+ value: state,
86
+ template: ""
87
+ };
88
+ computedStates.push(`'${state}': props['${state}']`);
89
+ }
81
90
  if (computedStates.length) {
82
91
  componentCode.push(`const states = computed(() => ({ ${computedStates.join(", ")} }));`);
83
92
  if (fallback && statefulData.fallback) {
@@ -18,7 +18,11 @@ function renderStatefulSVGCSSIconStyle(icon, context, commonStylesheet = createE
18
18
  return stylesheets[className];
19
19
  };
20
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]);
21
+ for (const className in icon.animations) {
22
+ const tree = [prefersReduceMotion];
23
+ if (context?.staticClassname) tree.push(`svg:not(.${context.staticClassname})`);
24
+ addGeneratedSelector(getStylesheet(className), [...tree, `.${className}`], icon.animations[className]);
25
+ }
22
26
  for (const keyframeName in icon.keyframes) getStylesheet(keyframeName).keyframes[keyframeName] = icon.keyframes[keyframeName];
23
27
  if (context) for (const className in icon.statefulClasses) {
24
28
  const baseClassName = `.${className}`;
@@ -3,7 +3,7 @@ import { StatefulIconSelectorsConfig, StatefulIconSelectorsContext } from "./typ
3
3
  /**
4
4
  * Create context object from config
5
5
  */
6
- declare function createStatefulIconSelectorsContext(config: StatefulIconSelectorsConfig, states: IconStatesList): StatefulIconSelectorsContext;
6
+ declare function createStatefulIconSelectorsContext(config: StatefulIconSelectorsConfig, states: IconStatesList, staticClassname?: string): StatefulIconSelectorsContext;
7
7
  /**
8
8
  * Get selectors to render state values
9
9
  *
@@ -5,10 +5,11 @@ import { stringifySelectorsForState } from "./stringify.js";
5
5
  /**
6
6
  * Create context object from config
7
7
  */
8
- function createStatefulIconSelectorsContext(config, states) {
8
+ function createStatefulIconSelectorsContext(config, states, staticClassname) {
9
9
  return {
10
10
  config,
11
11
  states,
12
+ staticClassname,
12
13
  data: Object.create(null),
13
14
  parsed: Object.create(null)
14
15
  };
@@ -31,6 +31,7 @@ type StatefulIconSelectorsConfig = Record<string, string | StateSelectorData | R
31
31
  interface StatefulIconSelectorsContext {
32
32
  config: StatefulIconSelectorsConfig;
33
33
  states: IconStatesList;
34
+ staticClassname?: string;
34
35
  data: Record<string, StateSelectorData | null>;
35
36
  parsed: Record<string, string[][] | null>;
36
37
  }
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.2.7",
6
+ "version": "1.2.8",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/cyberalien/svg-utils/issues",
9
9
  "homepage": "https://cyberalien.dev/",
@@ -23,21 +23,16 @@
23
23
  "@iconify/types": "^2.0.0"
24
24
  },
25
25
  "devDependencies": {
26
- "@eslint/eslintrc": "^3.3.5",
27
- "@eslint/js": "^10.0.1",
28
26
  "@iconify-json/ri": "^1.2.10",
29
27
  "@types/jest": "^30.0.0",
30
28
  "@types/node": "^25.5.0",
31
- "@typescript-eslint/eslint-plugin": "^8.57.1",
32
- "@typescript-eslint/parser": "^8.57.1",
33
- "eslint": "^10.0.3",
34
- "globals": "^17.4.0",
29
+ "oxlint": "^1.56.0",
35
30
  "tsdown": "^0.21.4",
36
31
  "typescript": "^5.9.3",
37
32
  "vitest": "^4.1.0"
38
33
  },
39
34
  "scripts": {
40
- "lint": "eslint --fix src/**/*.ts && tsc --noemit",
35
+ "lint": "oxlint --fix src/**/*.ts && tsc --noemit",
41
36
  "prebuild": "pnpm run lint",
42
37
  "build": "tsdown",
43
38
  "test": "vitest"
@@ -1,10 +0,0 @@
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 };
@@ -1,13 +0,0 @@
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
- export { filterFocusState, isFocusState };