@cyberalien/svg-utils 1.2.3 → 1.2.5

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.
@@ -6,5 +6,5 @@ declare function addComponentDependencies(component: FactoryGeneratedComponent,
6
6
  /**
7
7
  * Create dependencies list for package.json
8
8
  */
9
- declare function createDependenciesForPackage(dependencies: Set<string>): Record<string, string> | undefined;
9
+ declare function createDependenciesForPackage(dependencies: Set<string>, customVersions?: Record<string, string>): Record<string, string> | undefined;
10
10
  export { addComponentDependencies, createDependenciesForPackage };
@@ -1,4 +1,3 @@
1
- const latestVersions = {};
2
1
  /**
3
2
  * Add component dependencies to set
4
3
  */
@@ -8,10 +7,10 @@ function addComponentDependencies(component, dependencies) {
8
7
  /**
9
8
  * Create dependencies list for package.json
10
9
  */
11
- function createDependenciesForPackage(dependencies) {
10
+ function createDependenciesForPackage(dependencies, customVersions) {
12
11
  if (dependencies.size) {
13
12
  const result = Object.create(null);
14
- for (const dependency of dependencies) result[dependency] = latestVersions[dependency] || "latest";
13
+ for (const dependency of dependencies) result[dependency] = customVersions?.[dependency] ?? "latest";
15
14
  return result;
16
15
  }
17
16
  }
@@ -175,9 +175,11 @@ function createJSXComponent(data, options) {
175
175
  \t\t${stringifyFactoryPropsAsJSON(props, "\n ")}
176
176
  \t});`);
177
177
  const beforeFunction = componentExternalCode.length ? componentExternalCode.join("\n") + "\n\n" : "";
178
+ const propTypes = stringifyFactoryPropTypes(props);
179
+ const typesCode = useTS ? `interface Props {\n${propTypes}\n};\n\n` : propTypes ? `/** @type {{${propTypes.replace(/\s*\n\s*/g, " ").trim()}}} */\n` : "";
178
180
  const usedProps = getUsedFactoryProps(props);
179
181
  const propsDestricturing = usedProps.length ? `{${[...usedProps, "...props"].join(", ")}}` : "props";
180
- const componentFunction = `function Component${useTS ? `<{\n${stringifyFactoryPropTypes(props)}\n}>` : ""}(${propsDestricturing}) {
182
+ const componentFunction = `${typesCode}function Component${useTS ? `<Props>` : ""}(${propsDestricturing}) {
181
183
  \t${componentInternalCode.join("\n ")}
182
184
  }
183
185
  `;
@@ -29,7 +29,7 @@ function prepareComponentFactoryStatefulIcon(icon, options) {
29
29
  defaultStateValues[stateName] = defaultValue;
30
30
  if (customConfig?.[stateName]) config[stateName] = customConfig[stateName];
31
31
  else {
32
- if (state === "focus") config[stateName] = ".svg-focus-anchor:focus-within, .svg-hover-anchor:hover, &.state-focus";
32
+ if (state === "focus") config[stateName] = `input:not(:disabled):focus-visible, input:not(:disabled):hover, button:not(:disabled):focus-visible, button:not(:disabled):hover, &.state-${stateName}`;
33
33
  else config[stateName] = `&.state-{state}`;
34
34
  supportedStates.add(stateName);
35
35
  supportedStateValues[stateName] = defaultValue;
@@ -16,28 +16,21 @@ function splitSelectorToSubParts(selector) {
16
16
  result.combinator = firstChar;
17
17
  selector = selector.slice(1).trim();
18
18
  }
19
- const pseudoSelectors = selector.split(":");
20
- while (pseudoSelectors.length > 1) {
19
+ const pseudoMatches = selector.matchAll(/:[a-z-]+(\(:[a-z-]+\))*/g);
20
+ for (const match of pseudoMatches) {
21
+ const value = match[0];
22
+ selector = selector.replace(value, "");
21
23
  const list = result.pseudo || /* @__PURE__ */ new Set();
22
24
  if (!result.pseudo) result.pseudo = list;
23
- list.add(":" + pseudoSelectors.pop());
25
+ list.add(value);
24
26
  }
25
- selector = pseudoSelectors[0];
26
- let attrStart = selector.indexOf("[");
27
- while (attrStart !== -1) {
28
- const attrEnd = selector.indexOf("]", attrStart);
29
- let attrValue;
30
- if (attrEnd === -1) {
31
- attrValue = selector.slice(attrStart);
32
- selector = selector.slice(0, attrStart);
33
- } else {
34
- attrValue = selector.slice(attrStart, attrEnd + 1);
35
- selector = selector.slice(0, attrStart) + selector.slice(attrEnd + 1);
36
- }
27
+ const attrMatches = selector.matchAll(/\[[^\]]+\]/g);
28
+ for (const match of attrMatches) {
29
+ const value = match[0];
30
+ selector = selector.replace(value, "");
37
31
  const list = result.attr || /* @__PURE__ */ new Set();
38
32
  if (!result.attr) result.attr = list;
39
- list.add(attrValue);
40
- attrStart = selector.indexOf("[");
33
+ list.add(value);
41
34
  }
42
35
  const tagMatch = selector.match(/^[a-zA-Z][a-zA-Z0-9-]*/);
43
36
  if (tagMatch) {
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.3",
6
+ "version": "1.2.5",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/cyberalien/svg-utils/issues",
9
9
  "homepage": "https://cyberalien.dev/",