@cyberalien/svg-utils 0.0.17 → 0.1.1

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 (126) hide show
  1. package/lib/css/stringify.d.ts +6 -2
  2. package/lib/css/stringify.js +21 -1
  3. package/lib/css/types.d.ts +12 -1
  4. package/lib/helpers/misc/strings.js +2 -4
  5. package/lib/iconify/icon/nornalise.d.ts +7 -0
  6. package/lib/iconify/icon/nornalise.js +63 -0
  7. package/lib/iconify/icon/types.d.ts +6 -0
  8. package/lib/iconify/icon/types.js +1 -0
  9. package/lib/iconify/icon-set/defaults.d.ts +6 -0
  10. package/lib/iconify/icon-set/defaults.js +19 -0
  11. package/lib/iconify/icon-set/icon.d.ts +6 -0
  12. package/lib/iconify/icon-set/icon.js +24 -0
  13. package/lib/iconify/icon-set/parse.d.ts +7 -0
  14. package/lib/iconify/icon-set/parse.js +31 -0
  15. package/lib/iconify/icon-set/types.d.ts +6 -0
  16. package/lib/index.d.ts +2 -2
  17. package/lib/index.js +2 -2
  18. package/lib/svg/content/defs.d.ts +20 -0
  19. package/lib/svg/content/defs.js +44 -0
  20. package/lib/svg/ids/duplicate.js +1 -4
  21. package/lib/svg/ids/unused.js +1 -2
  22. package/lib/svg/props/size.d.ts +8 -0
  23. package/lib/svg/props/size.js +34 -0
  24. package/lib/svg/props/stringify.d.ts +5 -0
  25. package/lib/svg/props/stringify.js +8 -0
  26. package/lib/svg/viewbox/minify.d.ts +6 -0
  27. package/lib/svg/viewbox/minify.js +15 -0
  28. package/lib/svg/viewbox/parse.d.ts +6 -0
  29. package/lib/svg/viewbox/parse.js +17 -0
  30. package/lib/svg/viewbox/square.d.ts +6 -0
  31. package/lib/svg/viewbox/square.js +24 -0
  32. package/lib/svg-css/convert/content.d.ts +2 -5
  33. package/lib/svg-css/convert/types.d.ts +5 -0
  34. package/lib/svg-css/convert/types.js +1 -0
  35. package/lib/svg-css/factory/code/iconify.d.ts +11 -0
  36. package/lib/svg-css/factory/code/iconify.js +20 -0
  37. package/lib/svg-css/factory/code/stringify.d.ts +5 -0
  38. package/lib/svg-css/factory/code/stringify.js +9 -0
  39. package/lib/svg-css/factory/code/template.d.ts +6 -0
  40. package/lib/svg-css/factory/code/template.js +15 -0
  41. package/lib/svg-css/factory/components/raw.d.ts +8 -0
  42. package/lib/svg-css/factory/components/raw.js +41 -0
  43. package/lib/svg-css/factory/components/shared/size.js +79 -0
  44. package/lib/svg-css/factory/components/vue/types.js +27 -0
  45. package/lib/svg-css/factory/components/vue-func.d.ts +8 -0
  46. package/lib/svg-css/factory/components/vue-func.js +99 -0
  47. package/lib/svg-css/factory/components/vue.d.ts +11 -0
  48. package/lib/svg-css/factory/components/vue.js +96 -0
  49. package/lib/svg-css/factory/content/size.d.ts +11 -0
  50. package/lib/svg-css/factory/content/size.js +22 -0
  51. package/lib/svg-css/factory/content/stringify.d.ts +7 -0
  52. package/lib/svg-css/factory/content/stringify.js +17 -0
  53. package/lib/svg-css/factory/css/generate.d.ts +11 -0
  54. package/lib/svg-css/factory/css/generate.js +45 -0
  55. package/lib/svg-css/factory/css/name.d.ts +7 -0
  56. package/lib/svg-css/factory/css/name.js +12 -0
  57. package/lib/svg-css/factory/export/exports.d.ts +11 -0
  58. package/lib/svg-css/factory/export/exports.js +14 -0
  59. package/lib/svg-css/factory/export/file.d.ts +6 -0
  60. package/lib/svg-css/factory/export/file.js +12 -0
  61. package/lib/svg-css/factory/export/fs.d.ts +2 -2
  62. package/lib/svg-css/factory/export/merge.d.ts +7 -0
  63. package/lib/svg-css/factory/export/merge.js +23 -0
  64. package/lib/svg-css/factory/filenames/asset.d.ts +11 -0
  65. package/lib/svg-css/factory/filenames/asset.js +16 -0
  66. package/lib/svg-css/factory/filenames/component.d.ts +12 -0
  67. package/lib/svg-css/factory/filenames/component.js +15 -0
  68. package/lib/svg-css/factory/filenames/css.d.ts +7 -0
  69. package/lib/svg-css/factory/filenames/css.js +14 -0
  70. package/lib/svg-css/factory/filenames/options.d.ts +6 -0
  71. package/lib/svg-css/factory/filenames/options.js +27 -0
  72. package/lib/svg-css/factory/filenames/path.d.ts +11 -0
  73. package/lib/svg-css/factory/filenames/path.js +18 -0
  74. package/lib/svg-css/factory/filenames/types.d.ts +8 -0
  75. package/lib/svg-css/factory/filenames/types.js +14 -0
  76. package/lib/svg-css/factory/imports/add.d.ts +10 -0
  77. package/lib/svg-css/factory/imports/add.js +18 -0
  78. package/lib/svg-css/factory/imports/create.d.ts +6 -0
  79. package/lib/svg-css/factory/imports/create.js +15 -0
  80. package/lib/svg-css/factory/imports/stringify.d.ts +6 -0
  81. package/lib/svg-css/factory/imports/stringify.js +47 -0
  82. package/lib/svg-css/factory/props/object.d.ts +6 -0
  83. package/lib/svg-css/factory/props/object.js +10 -0
  84. package/lib/svg-css/factory/props/stringify.d.ts +10 -0
  85. package/lib/svg-css/factory/props/stringify.js +21 -0
  86. package/lib/svg-css/factory/props/types.d.ts +10 -0
  87. package/lib/svg-css/factory/props/types.js +27 -0
  88. package/lib/svg-css/factory/types/asset.d.ts +8 -0
  89. package/lib/svg-css/factory/types/asset.js +1 -0
  90. package/lib/svg-css/factory/types/component.d.ts +39 -0
  91. package/lib/svg-css/factory/types/component.js +1 -0
  92. package/lib/svg-css/factory/types/css.d.ts +5 -0
  93. package/lib/svg-css/factory/types/css.js +1 -0
  94. package/lib/svg-css/factory/types/data.d.ts +13 -0
  95. package/lib/svg-css/factory/types/data.js +1 -0
  96. package/lib/svg-css/factory/types/file.d.ts +14 -0
  97. package/lib/svg-css/factory/types/file.js +1 -0
  98. package/lib/svg-css/factory/types/options.d.ts +26 -0
  99. package/lib/svg-css/factory/types/options.js +1 -0
  100. package/lib/svg-css/factory/types/props.d.ts +14 -0
  101. package/lib/svg-css/factory/types/props.js +1 -0
  102. package/lib/svg-css/factory/types/source.d.ts +10 -0
  103. package/lib/svg-css/factory/types/source.js +1 -0
  104. package/lib/svg-css/types.d.ts +2 -1
  105. package/lib/xml/parse.js +2 -4
  106. package/package.json +11 -9
  107. package/lib/svg-css/factory/helpers/add-css.d.ts +0 -8
  108. package/lib/svg-css/factory/helpers/add-css.js +0 -32
  109. package/lib/svg-css/factory/helpers/component-name.d.ts +0 -9
  110. package/lib/svg-css/factory/helpers/component-name.js +0 -17
  111. package/lib/svg-css/factory/helpers/component-path.d.ts +0 -5
  112. package/lib/svg-css/factory/helpers/component-path.js +0 -9
  113. package/lib/svg-css/factory/helpers/css-filename.d.ts +0 -5
  114. package/lib/svg-css/factory/helpers/css-filename.js +0 -10
  115. package/lib/svg-css/factory/helpers/exports.d.ts +0 -6
  116. package/lib/svg-css/factory/helpers/exports.js +0 -10
  117. package/lib/svg-css/factory/helpers/merge.d.ts +0 -6
  118. package/lib/svg-css/factory/helpers/merge.js +0 -19
  119. package/lib/svg-css/factory/helpers/options.d.ts +0 -6
  120. package/lib/svg-css/factory/helpers/options.js +0 -12
  121. package/lib/svg-css/factory/helpers/prefix.d.ts +0 -6
  122. package/lib/svg-css/factory/helpers/prefix.js +0 -8
  123. package/lib/svg-css/factory/iconify/vue.d.ts +0 -6
  124. package/lib/svg-css/factory/iconify/vue.js +0 -72
  125. package/lib/svg-css/factory/types.d.ts +0 -48
  126. /package/lib/{svg-css/factory → iconify/icon-set}/types.js +0 -0
@@ -1,4 +1,4 @@
1
- import { CSSRules } from "./types.js";
1
+ import { CSSKeyframes, CSSRules } from "./types.js";
2
2
  /**
3
3
  * Stringify CSS rules
4
4
  */
@@ -7,4 +7,8 @@ declare function stringifyCSSRules(rules: CSSRules, depth?: number): string;
7
7
  * Stringify CSS selector with rules
8
8
  */
9
9
  declare function stringifyCSSSelector(selector: string, rules: string | CSSRules, depth?: number): string;
10
- export { stringifyCSSRules, stringifyCSSSelector };
10
+ /**
11
+ * Stringify CSS keyframes
12
+ */
13
+ declare function stringifyCSSKeyframes(animationName: string, keyframes: CSSKeyframes, depth?: number): string;
14
+ export { stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector };
@@ -22,5 +22,25 @@ function stringifyCSSSelector(selector, rules, depth = 0) {
22
22
  const tab = indent(depth);
23
23
  return `${tab}${selector} {\n${content}${tab}}\n`;
24
24
  }
25
+ /**
26
+ * Stringify CSS keyframes
27
+ */
28
+ function stringifyCSSKeyframes(animationName, keyframes, depth = 0) {
29
+ const prop = keyframes.prop;
30
+ const values = /* @__PURE__ */ new Map();
31
+ keyframes.frames.forEach((frame) => {
32
+ const css = `${indent(depth + 2)}${prop}: ${frame.value};\n`;
33
+ const item = values.get(css);
34
+ if (item) item.push(frame.time);
35
+ else values.set(css, [frame.time]);
36
+ });
37
+ const lines = [];
38
+ lines.push(`${indent(depth)}@keyframes ${animationName} {\n`);
39
+ values.forEach((times, css) => {
40
+ lines.push(`${indent(depth + 1)}${times.map((time) => `${(time * 100).toFixed(2).replace(/\.?0+$/, "")}%`).join(", ")} {\n${css}${indent(depth + 1)}}\n`);
41
+ });
42
+ lines.push("}\n");
43
+ return lines.join("");
44
+ }
25
45
 
26
- export { stringifyCSSRules, stringifyCSSSelector };
46
+ export { stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector };
@@ -2,4 +2,15 @@
2
2
  * CSS rules
3
3
  */
4
4
  type CSSRules = Record<string, string>;
5
- export { CSSRules };
5
+ /**
6
+ * Animation keyframes
7
+ */
8
+ interface CSSKeyframe {
9
+ time: number;
10
+ value: string;
11
+ }
12
+ interface CSSKeyframes {
13
+ prop: string;
14
+ frames: CSSKeyframe[];
15
+ }
16
+ export { CSSKeyframe, CSSKeyframes, CSSRules };
@@ -15,15 +15,13 @@ function pascalize(str) {
15
15
  * Convert camelCase string to kebab-case
16
16
  */
17
17
  function camelToKebab(key) {
18
- const result = key.replace(/:/g, "-").replace(/([A-Z])/g, " $1").trim();
19
- return result.split(/\s+/g).join("-").toLowerCase();
18
+ return key.replace(/:/g, "-").replace(/([A-Z])/g, " $1").trim().split(/\s+/g).join("-").toLowerCase();
20
19
  }
21
20
  /**
22
21
  * Convert camelCase string to snake-case
23
22
  */
24
23
  function snakelize(str) {
25
- const kebab = camelToKebab(str);
26
- return kebab.replace(/-/g, "_");
24
+ return camelToKebab(str).replace(/-/g, "_");
27
25
  }
28
26
 
29
27
  export { camelToKebab, camelize, pascalize, snakelize };
@@ -0,0 +1,7 @@
1
+ import { ParsedIconifyIcon } from "./types.js";
2
+ import { IconifyIcon } from "@iconify/types";
3
+ /**
4
+ * Normalise icon: apply transformations
5
+ */
6
+ declare function normaliseIconifyIcon(data: IconifyIcon): ParsedIconifyIcon;
7
+ export { normaliseIconifyIcon };
@@ -0,0 +1,63 @@
1
+ import { wrapSVGContent } from "../../svg/content/defs.js";
2
+
3
+ /**
4
+ * Normalise icon: apply transformations
5
+ */
6
+ function normaliseIconifyIcon(data) {
7
+ const viewBox = {
8
+ left: data.left ?? 0,
9
+ top: data.top ?? 0,
10
+ width: data.width ?? 16,
11
+ height: data.height ?? 16
12
+ };
13
+ let body = data.body;
14
+ const transformations = [];
15
+ let rotation = data.rotate ?? 0;
16
+ if (data.hFlip) if (data.vFlip) rotation += 2;
17
+ else {
18
+ transformations.push("translate(" + (viewBox.width + viewBox.left).toString() + " " + (0 - viewBox.top).toString() + ")");
19
+ transformations.push("scale(-1 1)");
20
+ viewBox.top = viewBox.left = 0;
21
+ }
22
+ else if (data.vFlip) {
23
+ transformations.push("translate(" + (0 - viewBox.left).toString() + " " + (viewBox.height + viewBox.top).toString() + ")");
24
+ transformations.push("scale(1 -1)");
25
+ viewBox.top = viewBox.left = 0;
26
+ }
27
+ if (rotation < 0) rotation -= Math.floor(rotation / 4) * 4;
28
+ rotation = rotation % 4;
29
+ switch (rotation) {
30
+ case 1: {
31
+ const value = viewBox.height / 2 + viewBox.top;
32
+ transformations.unshift(`rotate(90 ${value} ${value})`);
33
+ break;
34
+ }
35
+ case 2:
36
+ transformations.unshift(`rotate(180 ${viewBox.width / 2 + viewBox.left} ${viewBox.height / 2 + viewBox.top})`);
37
+ break;
38
+ case 3: {
39
+ const value = viewBox.width / 2 + viewBox.left;
40
+ transformations.unshift(`rotate(-90 ${value} ${value})`);
41
+ break;
42
+ }
43
+ }
44
+ if (rotation % 2 === 1) {
45
+ if (viewBox.left !== viewBox.top) {
46
+ const tempValue = viewBox.left;
47
+ viewBox.left = viewBox.top;
48
+ viewBox.top = tempValue;
49
+ }
50
+ if (viewBox.width !== viewBox.height) {
51
+ const tempValue = viewBox.width;
52
+ viewBox.width = viewBox.height;
53
+ viewBox.height = tempValue;
54
+ }
55
+ }
56
+ if (transformations.length) body = wrapSVGContent(body, "<g transform=\"" + transformations.join(" ") + "\">", "</g>");
57
+ return {
58
+ body,
59
+ viewBox
60
+ };
61
+ }
62
+
63
+ export { normaliseIconifyIcon };
@@ -0,0 +1,6 @@
1
+ import { IconViewBox } from "../../svg/viewbox/types.js";
2
+ interface ParsedIconifyIcon {
3
+ body: string;
4
+ viewBox: IconViewBox;
5
+ }
6
+ export { ParsedIconifyIcon };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,6 @@
1
+ import { IconifyJSON } from "@iconify/types";
2
+ /**
3
+ * Get default properties from icon set
4
+ */
5
+ declare function getIconifyIconSetDefaults(data: IconifyJSON): Partial<Record<"width" | "height" | "left" | "top", number>>;
6
+ export { getIconifyIconSetDefaults };
@@ -0,0 +1,19 @@
1
+ const defaultProps = [
2
+ "width",
3
+ "height",
4
+ "left",
5
+ "top"
6
+ ];
7
+ /**
8
+ * Get default properties from icon set
9
+ */
10
+ function getIconifyIconSetDefaults(data) {
11
+ const defaultValues = {};
12
+ for (const prop of defaultProps) {
13
+ const defaultValue = data[prop];
14
+ if (defaultValue) defaultValues[prop] = defaultValue;
15
+ }
16
+ return defaultValues;
17
+ }
18
+
19
+ export { getIconifyIconSetDefaults };
@@ -0,0 +1,6 @@
1
+ import { IconifyIcon, IconifyJSON } from "@iconify/types";
2
+ /**
3
+ * Get icon data from Iconify icon set
4
+ */
5
+ declare function getIconifyIconSetIcon(data: IconifyJSON, name: string): IconifyIcon | null | undefined;
6
+ export { getIconifyIconSetIcon };
@@ -0,0 +1,24 @@
1
+ import { getIconifyIconSetDefaults } from "./defaults.js";
2
+
3
+ /**
4
+ * Get icon data from Iconify icon set
5
+ */
6
+ function getIconifyIconSetIcon(data, name) {
7
+ if (data.not_found?.includes(name)) return null;
8
+ const icon = data.icons[name];
9
+ if (icon) return {
10
+ ...getIconifyIconSetDefaults(data),
11
+ ...icon
12
+ };
13
+ const alias = data.aliases?.[name];
14
+ if (alias) {
15
+ const parentIcon = data.icons?.[alias.parent];
16
+ return parentIcon ? {
17
+ ...getIconifyIconSetDefaults(data),
18
+ ...parentIcon,
19
+ ...alias
20
+ } : null;
21
+ }
22
+ }
23
+
24
+ export { getIconifyIconSetIcon };
@@ -0,0 +1,7 @@
1
+ import { ParseIconifyIconSetCallback } from "./types.js";
2
+ import { IconifyJSON } from "@iconify/types";
3
+ /**
4
+ * Parse Iconify icon set and call callback for each icon
5
+ */
6
+ declare function parseIconifyIconSet(data: IconifyJSON, callback: ParseIconifyIconSetCallback): void;
7
+ export { parseIconifyIconSet };
@@ -0,0 +1,31 @@
1
+ import { getIconifyIconSetDefaults } from "./defaults.js";
2
+
3
+ /**
4
+ * Parse Iconify icon set and call callback for each icon
5
+ */
6
+ function parseIconifyIconSet(data, callback) {
7
+ const defaultValues = getIconifyIconSetDefaults(data);
8
+ for (const name in data.icons) {
9
+ const item = data.icons[name];
10
+ callback(name, {
11
+ ...defaultValues,
12
+ ...item
13
+ });
14
+ }
15
+ if (data.aliases) for (const name in data.aliases) {
16
+ const item = data.aliases[name];
17
+ const parentIcon = data.icons[item.parent];
18
+ if (!parentIcon) {
19
+ callback(name, null);
20
+ continue;
21
+ }
22
+ callback(name, {
23
+ ...defaultValues,
24
+ ...parentIcon,
25
+ ...item
26
+ });
27
+ }
28
+ if (data.not_found) for (const name of data.not_found) callback(name, null);
29
+ }
30
+
31
+ export { parseIconifyIconSet };
@@ -0,0 +1,6 @@
1
+ import { IconifyIcon } from "@iconify/types";
2
+ /**
3
+ * Callback for each icon in icon set
4
+ */
5
+ type ParseIconifyIconSetCallback = (name: string, data: IconifyIcon | null) => void;
6
+ export { ParseIconifyIconSetCallback };
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ClassProp, classProps, defaultClassProp } from "./classname/const.js";
2
2
  import { splitClassName, toggleClassName } from "./classname/toggle.js";
3
3
  import { createCSSClassName } from "./css/hash.js";
4
- import { stringifyCSSRules, stringifyCSSSelector } from "./css/stringify.js";
4
+ import { stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector } from "./css/stringify.js";
5
5
  import { hashString } from "./helpers/hash/hash.js";
6
6
  import { hashToString } from "./helpers/hash/stringify.js";
7
7
  import { UniqueHashOptions } from "./helpers/hash/types.js";
@@ -24,4 +24,4 @@ import { convertSVGPropertyToCSS } from "./svg-css/props/prop.js";
24
24
  import { extractSVGTagPropertiesForCSS } from "./svg-css/props/props.js";
25
25
  import { convertSVGRootToCSS } from "./svg-css/convert/root.js";
26
26
  import { convertSVGContentToCSSRules } from "./svg-css/convert/content.js";
27
- export { ChangeIDResult, ClassProp, ConvertedSVGContent, ParsedXMLNode, ParsedXMLTagElement, ParsedXMLTextElement, SVGConvertedToCSSProperties, SVGPropertyType, StringifyXMLOptions, UniqueHashOptions, changeIDInString, changeSVGIDs, classProps, cloneObject, compareSets, compareValues, convertSVGContentToCSSRules, convertSVGPropertyToCSS, convertSVGRootToCSS, createCSSClassName, createUniqueIDs, defaultClassProp, extractSVGTagPropertiesForCSS, getUniqueHash, hashString, hashToString, iterateXMLContent, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitClassName, stringifyCSSRules, stringifyCSSSelector, stringifyXMLContent, toggleClassName };
27
+ export { ChangeIDResult, ClassProp, ConvertedSVGContent, ParsedXMLNode, ParsedXMLTagElement, ParsedXMLTextElement, SVGConvertedToCSSProperties, SVGPropertyType, StringifyXMLOptions, UniqueHashOptions, changeIDInString, changeSVGIDs, classProps, cloneObject, compareSets, compareValues, convertSVGContentToCSSRules, convertSVGPropertyToCSS, convertSVGRootToCSS, createCSSClassName, createUniqueIDs, defaultClassProp, extractSVGTagPropertiesForCSS, getUniqueHash, hashString, hashToString, iterateXMLContent, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitClassName, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector, stringifyXMLContent, toggleClassName };
package/lib/index.js CHANGED
@@ -8,7 +8,7 @@ import { iterateXMLContent } from "./xml/iterate.js";
8
8
  import { parseXMLContent } from "./xml/parse.js";
9
9
  import { stringifyXMLContent } from "./xml/stringify.js";
10
10
  import { createCSSClassName } from "./css/hash.js";
11
- import { stringifyCSSRules, stringifyCSSSelector } from "./css/stringify.js";
11
+ import { stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector } from "./css/stringify.js";
12
12
  import { classProps, defaultClassProp } from "./classname/const.js";
13
13
  import { splitClassName, toggleClassName } from "./classname/toggle.js";
14
14
  import { changeIDInString } from "./svg/ids/string.js";
@@ -21,4 +21,4 @@ import { extractSVGTagPropertiesForCSS } from "./svg-css/props/props.js";
21
21
  import { convertSVGRootToCSS } from "./svg-css/convert/root.js";
22
22
  import { convertSVGContentToCSSRules } from "./svg-css/convert/content.js";
23
23
 
24
- export { changeIDInString, changeSVGIDs, classProps, cloneObject, compareSets, compareValues, convertSVGContentToCSSRules, convertSVGPropertyToCSS, convertSVGRootToCSS, createCSSClassName, createUniqueIDs, defaultClassProp, extractSVGTagPropertiesForCSS, getUniqueHash, hashString, hashToString, iterateXMLContent, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitClassName, stringifyCSSRules, stringifyCSSSelector, stringifyXMLContent, toggleClassName };
24
+ export { changeIDInString, changeSVGIDs, classProps, cloneObject, compareSets, compareValues, convertSVGContentToCSSRules, convertSVGPropertyToCSS, convertSVGRootToCSS, createCSSClassName, createUniqueIDs, defaultClassProp, extractSVGTagPropertiesForCSS, getUniqueHash, hashString, hashToString, iterateXMLContent, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitClassName, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector, stringifyXMLContent, toggleClassName };
@@ -0,0 +1,20 @@
1
+ interface SplitSVGDefsResult {
2
+ defs: string;
3
+ content: string;
4
+ }
5
+ /**
6
+ * Extract definitions from SVG
7
+ *
8
+ * Can be used with other tags, but name kept for backwards compatibility.
9
+ * Should be used only with tags that cannot be nested, such as masks, clip paths, etc.
10
+ */
11
+ declare function splitSVGDefs(content: string, tag?: string): SplitSVGDefsResult;
12
+ /**
13
+ * Merge defs and content
14
+ */
15
+ declare function mergeDefsAndContent(defs: string, content: string): string;
16
+ /**
17
+ * Wrap SVG content, without wrapping definitions
18
+ */
19
+ declare function wrapSVGContent(body: string, start: string, end: string): string;
20
+ export { mergeDefsAndContent, splitSVGDefs, wrapSVGContent };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Extract definitions from SVG
3
+ *
4
+ * Can be used with other tags, but name kept for backwards compatibility.
5
+ * Should be used only with tags that cannot be nested, such as masks, clip paths, etc.
6
+ */
7
+ function splitSVGDefs(content, tag = "defs") {
8
+ let defs = "";
9
+ let index;
10
+ while ((index = content.indexOf("<" + tag)) !== -1) {
11
+ const start = content.indexOf(">", index);
12
+ if (start === -1) break;
13
+ const prevContent = content.slice(0, index).trim();
14
+ if (content[start - 1] === "/") {
15
+ content = prevContent + content.slice(start + 1);
16
+ continue;
17
+ }
18
+ const end = content.indexOf("</" + tag);
19
+ if (end === -1) break;
20
+ const endEnd = content.indexOf(">", end);
21
+ if (endEnd === -1) break;
22
+ defs += content.slice(start + 1, end).trim();
23
+ content = prevContent + content.slice(endEnd + 1);
24
+ }
25
+ return {
26
+ defs,
27
+ content
28
+ };
29
+ }
30
+ /**
31
+ * Merge defs and content
32
+ */
33
+ function mergeDefsAndContent(defs, content) {
34
+ return defs ? `<defs>${defs}</defs>${content}` : content;
35
+ }
36
+ /**
37
+ * Wrap SVG content, without wrapping definitions
38
+ */
39
+ function wrapSVGContent(body, start, end) {
40
+ const split = splitSVGDefs(body);
41
+ return mergeDefsAndContent(split.defs, start + split.content + end);
42
+ }
43
+
44
+ export { mergeDefsAndContent, splitSVGDefs, wrapSVGContent };
@@ -5,10 +5,7 @@ import { iterateXMLContent } from "../../xml/iterate.js";
5
5
  */
6
6
  function removeDuplicateIDs(root, data) {
7
7
  const remove = /* @__PURE__ */ new Set();
8
- for (const id in data.map) {
9
- const nodes = data.map[id];
10
- if (nodes.length > 1) remove.add(id);
11
- }
8
+ for (const id in data.map) if (data.map[id].length > 1) remove.add(id);
12
9
  if (remove.size) {
13
10
  const removing = /* @__PURE__ */ new Set();
14
11
  return iterateXMLContent(root, (node) => {
@@ -15,8 +15,7 @@ function removeUnusedIDs(root, data) {
15
15
  case "clipPath":
16
16
  case "symbol": return "remove";
17
17
  }
18
- const parentNode = stack[stack.length - 1];
19
- if (parentNode?.tag === "defs") return "remove";
18
+ if (stack[stack.length - 1]?.tag === "defs") return "remove";
20
19
  delete node.attribs.id;
21
20
  });
22
21
  return root;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Calculate second dimension when only 1 dimension is set
3
+ *
4
+ * If you are calculating width, ratio should be width/height
5
+ * If you are calculating height, ratio should be height/width
6
+ */
7
+ declare function calculateSize<T extends string | number>(size: T, ratio: number, precision?: number): T;
8
+ export { calculateSize };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Regular expressions for calculating dimensions
3
+ */
4
+ const unitsSplit = /(-?[0-9.]*[0-9]+[0-9.]*)/g;
5
+ const unitsTest = /^-?[0-9.]*[0-9]+[0-9.]*$/g;
6
+ /**
7
+ * Calculate second dimension when only 1 dimension is set
8
+ *
9
+ * If you are calculating width, ratio should be width/height
10
+ * If you are calculating height, ratio should be height/width
11
+ */
12
+ function calculateSize(size, ratio, precision) {
13
+ if (ratio === 1) return size;
14
+ precision = precision || 100;
15
+ if (typeof size === "number") return Math.ceil(size * ratio * precision) / precision;
16
+ if (typeof size !== "string") return size;
17
+ const oldParts = size.split(unitsSplit);
18
+ if (oldParts === null || !oldParts.length) return size;
19
+ const newParts = [];
20
+ let code = oldParts.shift();
21
+ let isNumber = unitsTest.test(code);
22
+ while (true) {
23
+ if (isNumber) {
24
+ const num = parseFloat(code);
25
+ if (isNaN(num)) newParts.push(code);
26
+ else newParts.push(Math.ceil(num * ratio * precision) / precision);
27
+ } else newParts.push(code);
28
+ code = oldParts.shift();
29
+ if (code === void 0) return newParts.join("");
30
+ isNumber = !isNumber;
31
+ }
32
+ }
33
+
34
+ export { calculateSize };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Stringify properties
3
+ */
4
+ declare function stringifyProps(props: Record<string, string>): string;
5
+ export { stringifyProps };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Stringify properties
3
+ */
4
+ function stringifyProps(props) {
5
+ return Object.entries(props).map(([key, value]) => `${key}="${value}"`).join(" ");
6
+ }
7
+
8
+ export { stringifyProps };
@@ -0,0 +1,6 @@
1
+ import { IconViewBox } from "./types.js";
2
+ /**
3
+ * Minify viewBox by removing default values
4
+ */
5
+ declare function minifyViewBox(viewBox: IconViewBox): IconViewBox;
6
+ export { minifyViewBox };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Minify viewBox by removing default values
3
+ */
4
+ function minifyViewBox(viewBox) {
5
+ const result = {
6
+ width: viewBox.width,
7
+ height: viewBox.height
8
+ };
9
+ if (viewBox.left) result.left = viewBox.left;
10
+ if (viewBox.top) result.top = viewBox.top;
11
+ if (viewBox.cx && viewBox.cx * 2 !== viewBox.width) result.cx = viewBox.cx;
12
+ return result;
13
+ }
14
+
15
+ export { minifyViewBox };
@@ -0,0 +1,6 @@
1
+ import { IconViewBox } from "./types.js";
2
+ /**
3
+ * Parse viewBox string to IconViewBox
4
+ */
5
+ declare function parseViewBox(value: string): IconViewBox | undefined;
6
+ export { parseViewBox };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Parse viewBox string to IconViewBox
3
+ */
4
+ function parseViewBox(value) {
5
+ const parts = value.split(/[\s,]+/).map((item) => item.trim());
6
+ if (parts.length !== 4) return;
7
+ const nums = parts.map((part) => Number(part));
8
+ if (nums.some((num) => isNaN(num))) return;
9
+ return {
10
+ left: nums[0],
11
+ top: nums[1],
12
+ width: nums[2],
13
+ height: nums[3]
14
+ };
15
+ }
16
+
17
+ export { parseViewBox };
@@ -0,0 +1,6 @@
1
+ import { IconViewBox } from "./types.js";
2
+ /**
3
+ * Make viewBox square
4
+ */
5
+ declare function makeSquareViewBox(viewBox: IconViewBox): IconViewBox;
6
+ export { makeSquareViewBox };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Make viewBox square
3
+ */
4
+ function makeSquareViewBox(viewBox) {
5
+ const { width, height } = viewBox;
6
+ if (width === height) return { ...viewBox };
7
+ if (width >= height) {
8
+ const diff = (width - height) / 2;
9
+ return {
10
+ left: viewBox.left,
11
+ top: (viewBox.top ?? 0) - diff,
12
+ width,
13
+ height: width
14
+ };
15
+ }
16
+ return {
17
+ left: (viewBox.cx ?? width / 2 + (viewBox.left ?? 0)) - height / 2,
18
+ top: viewBox.top,
19
+ width: height,
20
+ height
21
+ };
22
+ }
23
+
24
+ export { makeSquareViewBox };
@@ -1,10 +1,7 @@
1
- import { StringifyXMLOptions } from "../../xml/types.js";
2
1
  import { ConvertedSVGContent } from "../types.js";
3
- interface Options extends StringifyXMLOptions {
4
- classNamePrefix?: string;
5
- }
2
+ import { ConvertSVGContentOptions } from "./types.js";
6
3
  /**
7
4
  * Convert SVG content string to SVG+CSS
8
5
  */
9
- declare function convertSVGContentToCSSRules(content: string, options?: Options): ConvertedSVGContent;
6
+ declare function convertSVGContentToCSSRules(content: string, options?: ConvertSVGContentOptions): ConvertedSVGContent;
10
7
  export { convertSVGContentToCSSRules };
@@ -0,0 +1,5 @@
1
+ import { StringifyXMLOptions } from "../../xml/types.js";
2
+ interface ConvertSVGContentOptions extends StringifyXMLOptions {
3
+ classNamePrefix?: string;
4
+ }
5
+ export { ConvertSVGContentOptions };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,11 @@
1
+ import { ConvertSVGContentOptions } from "../../convert/types.js";
2
+ import { FactoryIconData } from "../types/data.js";
3
+ import { IconifyIcon } from "@iconify/types";
4
+ interface Options extends ConvertSVGContentOptions {
5
+ fallback?: string | boolean;
6
+ }
7
+ /**
8
+ * Convert IconifyIcon data to FactoryIconData
9
+ */
10
+ declare function convertIconifyIconToFactoryContent(icon: IconifyIcon, prefix: string, name: string, options?: Options): FactoryIconData;
11
+ export { convertIconifyIconToFactoryContent };
@@ -0,0 +1,20 @@
1
+ import { convertSVGContentToCSSRules } from "../../convert/content.js";
2
+ import { normaliseIconifyIcon } from "../../../iconify/icon/nornalise.js";
3
+
4
+ /**
5
+ * Convert IconifyIcon data to FactoryIconData
6
+ */
7
+ function convertIconifyIconToFactoryContent(icon, prefix, name, options) {
8
+ const { body, viewBox } = normaliseIconifyIcon(icon);
9
+ const fallbackOption = options?.fallback ?? true;
10
+ const fallback = typeof fallbackOption === "string" ? fallbackOption : fallbackOption ? `${prefix}:${name}` : void 0;
11
+ return {
12
+ prefix,
13
+ name,
14
+ viewBox,
15
+ icon: convertSVGContentToCSSRules(body, options),
16
+ fallback
17
+ };
18
+ }
19
+
20
+ export { convertIconifyIconToFactoryContent };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Merge lines into a string with padding
3
+ */
4
+ declare function stringifyFactoryIconCodeLines(lines: string[], padding?: number): string;
5
+ export { stringifyFactoryIconCodeLines };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Merge lines into a string with padding
3
+ */
4
+ function stringifyFactoryIconCodeLines(lines, padding = 0) {
5
+ const pad = " ".repeat(padding);
6
+ return lines.map((line) => pad + line).join("\n");
7
+ }
8
+
9
+ export { stringifyFactoryIconCodeLines };
@@ -0,0 +1,6 @@
1
+ import { FactoryComponentTemplate } from "../types/component.js";
2
+ /**
3
+ * Create empty code object
4
+ */
5
+ declare function createFactoryCodeTemplate(): FactoryComponentTemplate;
6
+ export { createFactoryCodeTemplate };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Create empty code object
3
+ */
4
+ function createFactoryCodeTemplate() {
5
+ return {
6
+ tag: "",
7
+ hardcoded: Object.create(null),
8
+ vars: Object.create(null),
9
+ spread: [],
10
+ propTypes: Object.create(null),
11
+ optionalProps: []
12
+ };
13
+ }
14
+
15
+ export { createFactoryCodeTemplate };
@@ -0,0 +1,8 @@
1
+ import { FactoryIconData } from "../types/data.js";
2
+ import { FactoryGeneratedComponent } from "../types/component.js";
3
+ import { ComponentFactoryOptions } from "../types/options.js";
4
+ /**
5
+ * Create raw component code
6
+ */
7
+ declare function createRawComponent(data: FactoryIconData, options: ComponentFactoryOptions): FactoryGeneratedComponent;
8
+ export { createRawComponent };