@cyberalien/svg-utils 0.1.0 → 0.1.2

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 (100) hide show
  1. package/lib/{svg-css/factory → components}/export/exports.d.ts +3 -2
  2. package/lib/{svg-css/factory → components}/export/exports.js +4 -1
  3. package/lib/{svg-css/factory/filenames/component.js → components/export/filename.js} +2 -1
  4. package/lib/{svg-css/factory → components}/export/fs.d.ts +1 -1
  5. package/lib/{svg-css/factory → components}/export/merge.d.ts +1 -2
  6. package/lib/{svg-css/factory → components/helpers}/content/size.d.ts +1 -1
  7. package/lib/{svg-css/factory → components/helpers}/content/stringify.d.ts +2 -2
  8. package/lib/{svg-css/factory → components/helpers}/css/generate.d.ts +4 -4
  9. package/lib/components/helpers/filenames/asset.d.ts +10 -0
  10. package/lib/components/helpers/filenames/asset.js +16 -0
  11. package/lib/{svg-css/factory → components/helpers}/filenames/css.d.ts +1 -2
  12. package/lib/{svg-css/factory → components/helpers}/filenames/css.js +3 -4
  13. package/lib/components/helpers/filenames/path.d.ts +9 -0
  14. package/lib/components/helpers/filenames/path.js +17 -0
  15. package/lib/{svg-css/factory → components/helpers}/filenames/types.d.ts +2 -3
  16. package/lib/{svg-css/factory → components/helpers}/filenames/types.js +1 -1
  17. package/lib/components/helpers/functions/size.d.ts +8 -0
  18. package/lib/{svg-css/factory/components/shared → components/helpers/functions}/size.js +2 -2
  19. package/lib/{svg-css/factory → components/helpers}/imports/add.d.ts +1 -1
  20. package/lib/{svg-css/factory → components/helpers}/imports/create.d.ts +1 -1
  21. package/lib/{svg-css/factory → components/helpers}/imports/stringify.d.ts +1 -1
  22. package/lib/{svg-css/factory → components/helpers}/imports/stringify.js +2 -2
  23. package/lib/components/helpers/imports/types.d.ts +12 -0
  24. package/lib/{svg-css/factory → components/helpers}/props/object.d.ts +1 -1
  25. package/lib/{svg-css/factory → components/helpers}/props/stringify.d.ts +1 -1
  26. package/lib/components/helpers/props/ts.d.ts +10 -0
  27. package/lib/components/helpers/props/ts.js +27 -0
  28. package/lib/components/helpers/vue/types.d.ts +9 -0
  29. package/lib/{svg-css/factory/components → components/helpers}/vue/types.js +5 -3
  30. package/lib/components/prepare/iconify.d.ts +17 -0
  31. package/lib/components/prepare/iconify.js +38 -0
  32. package/lib/{svg-css/factory/filenames → components/prepare}/options.js +5 -7
  33. package/lib/components/raw.d.ts +8 -0
  34. package/lib/{svg-css/factory/components → components}/raw.js +8 -8
  35. package/lib/components/types/component.d.ts +29 -0
  36. package/lib/{svg-css/factory → components}/types/data.d.ts +1 -1
  37. package/lib/{svg-css/factory → components}/types/options.d.ts +10 -4
  38. package/lib/{svg-css/factory → components}/types/source.d.ts +2 -2
  39. package/lib/components/vue-func.d.ts +8 -0
  40. package/lib/{svg-css/factory/components/vue.js → components/vue-func.js} +43 -47
  41. package/lib/components/vue.d.ts +11 -0
  42. package/lib/components/vue.js +96 -0
  43. package/lib/index.d.ts +5 -7
  44. package/lib/index.js +3 -5
  45. package/lib/svg-css/animations/tags.d.ts +17 -0
  46. package/lib/svg-css/animations/tags.js +26 -0
  47. package/lib/svg-css/{convert/content.d.ts → content.d.ts} +1 -2
  48. package/lib/svg-css/{convert/content.js → content.js} +2 -2
  49. package/lib/svg-css/props/prop.js +9 -0
  50. package/lib/svg-css/props/props.d.ts +1 -1
  51. package/lib/svg-css/props/props.js +3 -7
  52. package/lib/svg-css/props/types.d.ts +9 -0
  53. package/lib/svg-css/{convert/root.d.ts → root.d.ts} +2 -2
  54. package/lib/svg-css/{convert/root.js → root.js} +4 -4
  55. package/lib/svg-css/types.d.ts +5 -9
  56. package/package.json +1 -1
  57. package/lib/svg-css/convert/types.d.ts +0 -5
  58. package/lib/svg-css/factory/code/iconify.d.ts +0 -11
  59. package/lib/svg-css/factory/code/iconify.js +0 -20
  60. package/lib/svg-css/factory/code/template.d.ts +0 -6
  61. package/lib/svg-css/factory/code/template.js +0 -15
  62. package/lib/svg-css/factory/components/raw.d.ts +0 -8
  63. package/lib/svg-css/factory/components/vue.d.ts +0 -8
  64. package/lib/svg-css/factory/filenames/asset.d.ts +0 -11
  65. package/lib/svg-css/factory/filenames/asset.js +0 -16
  66. package/lib/svg-css/factory/filenames/path.d.ts +0 -11
  67. package/lib/svg-css/factory/filenames/path.js +0 -15
  68. package/lib/svg-css/factory/props/types.d.ts +0 -6
  69. package/lib/svg-css/factory/props/types.js +0 -16
  70. package/lib/svg-css/factory/types/asset.d.ts +0 -8
  71. package/lib/svg-css/factory/types/component.d.ts +0 -38
  72. package/lib/svg-css/factory/types/file.d.ts +0 -14
  73. package/lib/svg-css/factory/types/props.js +0 -1
  74. /package/lib/{svg-css/factory → components}/export/file.d.ts +0 -0
  75. /package/lib/{svg-css/factory → components}/export/file.js +0 -0
  76. /package/lib/{svg-css/factory/filenames/component.d.ts → components/export/filename.d.ts} +0 -0
  77. /package/lib/{svg-css/factory → components}/export/fs.js +0 -0
  78. /package/lib/{svg-css/factory → components}/export/merge.js +0 -0
  79. /package/lib/{svg-css/factory/code/stringify.d.ts → components/helpers/code/lines.d.ts} +0 -0
  80. /package/lib/{svg-css/factory/code/stringify.js → components/helpers/code/lines.js} +0 -0
  81. /package/lib/{svg-css/factory → components/helpers}/content/size.js +0 -0
  82. /package/lib/{svg-css/factory → components/helpers}/content/stringify.js +0 -0
  83. /package/lib/{svg-css/factory → components/helpers}/css/generate.js +0 -0
  84. /package/lib/{svg-css/factory → components/helpers}/css/name.d.ts +0 -0
  85. /package/lib/{svg-css/factory → components/helpers}/css/name.js +0 -0
  86. /package/lib/{svg-css/factory → components/helpers}/imports/add.js +0 -0
  87. /package/lib/{svg-css/factory → components/helpers}/imports/create.js +0 -0
  88. /package/lib/{svg-css/convert → components/helpers/imports}/types.js +0 -0
  89. /package/lib/{svg-css/factory → components/helpers}/props/object.js +0 -0
  90. /package/lib/{svg-css/factory → components/helpers}/props/stringify.js +0 -0
  91. /package/lib/{svg-css/factory/types/props.d.ts → components/helpers/props/types.d.ts} +0 -0
  92. /package/lib/{svg-css/factory/types/asset.js → components/helpers/props/types.js} +0 -0
  93. /package/lib/{svg-css/factory/filenames → components/prepare}/options.d.ts +0 -0
  94. /package/lib/{svg-css/factory → components}/types/component.js +0 -0
  95. /package/lib/{svg-css/factory → components}/types/css.d.ts +0 -0
  96. /package/lib/{svg-css/factory → components}/types/css.js +0 -0
  97. /package/lib/{svg-css/factory → components}/types/data.js +0 -0
  98. /package/lib/{svg-css/factory → components}/types/options.js +0 -0
  99. /package/lib/{svg-css/factory → components}/types/source.js +0 -0
  100. /package/lib/svg-css/{factory/types/file.js → props/types.js} +0 -0
@@ -1,18 +1,19 @@
1
- import { makeSquareViewBox } from "../../../svg/viewbox/square.js";
2
- import { getIconViewBox } from "../../../svg/viewbox/value.js";
3
- import { getComponentSizeValues } from "../content/size.js";
4
- import { stringifyFactoryIconContent } from "../content/stringify.js";
5
- import { createFactoryImports } from "../imports/create.js";
6
- import { generateCSSFilesForComponent } from "../css/generate.js";
7
- import { stringifyFactoryImports } from "../imports/stringify.js";
8
- import { addVueComponentTypes } from "./vue/types.js";
9
- import { addSizeFunctionAsset } from "./shared/size.js";
10
- import { stringifyFactoryPropsAsJSON } from "../props/object.js";
1
+ import { getComponentSizeValues } from "./helpers/content/size.js";
2
+ import { stringifyFactoryIconContent } from "./helpers/content/stringify.js";
3
+ import { getIconViewBox } from "../svg/viewbox/value.js";
4
+ import { createFactoryImports } from "./helpers/imports/create.js";
5
+ import { generateCSSFilesForComponent } from "./helpers/css/generate.js";
6
+ import { stringifyFactoryImports } from "./helpers/imports/stringify.js";
7
+ import { getUsedFactoryProps } from "./helpers/props/ts.js";
8
+ import { addVueComponentTypes } from "./helpers/vue/types.js";
9
+ import { addSizeFunctionAsset } from "./helpers/functions/size.js";
10
+ import { stringifyFactoryPropsAsJSON } from "./helpers/props/object.js";
11
+ import { makeSquareViewBox } from "../svg/viewbox/square.js";
11
12
 
12
13
  /**
13
- * Create Vue component code
14
+ * Create functional Vue component code
14
15
  */
15
- function createVueComponent(data, options) {
16
+ function createVueFunctionalComponent(data, options) {
16
17
  const assets = [];
17
18
  const imports = createFactoryImports();
18
19
  const hasFallback = !!data.fallback;
@@ -24,45 +25,38 @@ function createVueComponent(data, options) {
24
25
  const sizeProps = getComponentSizeValues(options, data.viewBox);
25
26
  const props = {};
26
27
  if (!hasFallback) props.xmlns = "http://www.w3.org/2000/svg";
27
- const usedProps = [];
28
28
  const viewBox = data.viewBox;
29
29
  const isDynanicViewBox = !sizeProps && options.square && viewBox.width !== viewBox.height;
30
30
  if (sizeProps) {
31
31
  props.width = sizeProps.width;
32
32
  props.height = sizeProps.height;
33
+ } else if (hasFallback) {
34
+ props.width = {
35
+ type: "string",
36
+ value: "width",
37
+ template: "width: props.width,"
38
+ };
39
+ props.height = {
40
+ type: "string",
41
+ value: "height",
42
+ template: "height: props.height,"
43
+ };
33
44
  } else {
34
- usedProps.push("width", "height");
35
- if (hasFallback) {
36
- props.width = {
37
- type: "string",
38
- value: "width",
39
- template: "width: props.width,"
40
- };
41
- props.height = {
42
- type: "string",
43
- value: "height",
44
- template: "height: props.height,"
45
- };
46
- } else {
47
- const getSizeProps = addSizeFunctionAsset(imports, assets, options);
48
- componentCode.push(`const size = computed(() => ${getSizeProps}(props.width, props.height, viewBox${isDynanicViewBox ? ".value" : ""}));`);
49
- vueNamedImports.add("computed");
50
- props.width = {
51
- type: "string",
52
- value: "width",
53
- template: "...size.value,"
54
- };
55
- props.height = {
56
- type: "string",
57
- value: "height",
58
- template: ""
59
- };
60
- }
61
- }
62
- if (options.square) {
63
- usedProps.push("square");
64
- props.square = { type: "boolean" };
45
+ const getSizeProps = addSizeFunctionAsset(imports, assets, options);
46
+ componentCode.push(`const size = computed(() => ${getSizeProps}(props.width, props.height, viewBox${isDynanicViewBox ? ".value" : ""}));`);
47
+ vueNamedImports.add("computed");
48
+ props.width = {
49
+ type: "string",
50
+ value: "width",
51
+ template: "...size.value,"
52
+ };
53
+ props.height = {
54
+ type: "string",
55
+ value: "height",
56
+ template: ""
57
+ };
65
58
  }
59
+ if (options.square) props.square = { type: "boolean" };
66
60
  const getViewBox = (viewBox$1) => hasFallback ? JSON.stringify(viewBox$1) : `'${getIconViewBox(viewBox$1)}'`;
67
61
  const viewBoxValue = getViewBox(viewBox);
68
62
  if (isDynanicViewBox) {
@@ -80,10 +74,11 @@ function createVueComponent(data, options) {
80
74
  }
81
75
  props[hasFallback ? "content" : "innerHTML"] = { value: stringifyFactoryIconContent(data.icon, options) };
82
76
  if (data.fallback) props.fallback = data.fallback;
83
- addVueComponentTypes(data, options, assets, props);
77
+ const types = addVueComponentTypes(data, options, assets, props);
84
78
  componentCode.push(`return () => h(${hasFallback ? "Icon" : "'svg'"}, {
85
79
  ${stringifyFactoryPropsAsJSON(props, "\n ")}
86
80
  });`);
81
+ const usedProps = getUsedFactoryProps(props);
87
82
  const componentFunction = `const Component = defineComponent(
88
83
  (${usedProps.length ? "props" : ""}) => {
89
84
  ${componentCode.join("\n ")}
@@ -96,8 +91,9 @@ function createVueComponent(data, options) {
96
91
  const content = `${stringifyFactoryImports(imports)}\n${componentFunction}\nexport default Component;\n`;
97
92
  return {
98
93
  assets,
99
- content
94
+ content,
95
+ types
100
96
  };
101
97
  }
102
98
 
103
- export { createVueComponent };
99
+ export { createVueFunctionalComponent };
@@ -0,0 +1,11 @@
1
+ import { FactoryGeneratedComponent } from "./types/component.js";
2
+ import { FactoryIconData } from "./types/data.js";
3
+ import { ComponentFactoryOptions } from "./types/options.js";
4
+ interface VueOptions extends ComponentFactoryOptions {
5
+ ts?: boolean;
6
+ }
7
+ /**
8
+ * Create Vue component code
9
+ */
10
+ declare function createVueComponent(data: FactoryIconData, options: VueOptions): FactoryGeneratedComponent;
11
+ export { createVueComponent };
@@ -0,0 +1,96 @@
1
+ import { getComponentSizeValues } from "./helpers/content/size.js";
2
+ import { stringifyFactoryIconContent } from "./helpers/content/stringify.js";
3
+ import { getIconViewBox } from "../svg/viewbox/value.js";
4
+ import { createFactoryImports } from "./helpers/imports/create.js";
5
+ import { generateCSSFilesForComponent } from "./helpers/css/generate.js";
6
+ import { stringifyFactoryImports } from "./helpers/imports/stringify.js";
7
+ import { stringifyFactoryProps } from "./helpers/props/stringify.js";
8
+ import { getUsedFactoryProps, stringifyFactoryPropTypes } from "./helpers/props/ts.js";
9
+ import { addVueComponentTypes } from "./helpers/vue/types.js";
10
+ import { addSizeFunctionAsset } from "./helpers/functions/size.js";
11
+ import { makeSquareViewBox } from "../svg/viewbox/square.js";
12
+
13
+ /**
14
+ * Create Vue component code
15
+ */
16
+ function createVueComponent(data, options) {
17
+ const useTS = options.ts ?? false;
18
+ const assets = [];
19
+ const imports = createFactoryImports();
20
+ const hasFallback = !!data.fallback;
21
+ if (hasFallback) imports.named["@iconify/css-vue"] = new Set(["Icon"]);
22
+ const vueNamedImports = /* @__PURE__ */ new Set();
23
+ imports.named["vue"] = vueNamedImports;
24
+ generateCSSFilesForComponent(data.icon, imports, assets, options);
25
+ const componentCode = [];
26
+ const sizeProps = getComponentSizeValues(options, data.viewBox);
27
+ const props = {};
28
+ if (!hasFallback) props.xmlns = "http://www.w3.org/2000/svg";
29
+ const viewBox = data.viewBox;
30
+ const isDynanicViewBox = !sizeProps && options.square && viewBox.width !== viewBox.height;
31
+ if (sizeProps) {
32
+ props.width = sizeProps.width;
33
+ props.height = sizeProps.height;
34
+ } else if (hasFallback) {
35
+ props.width = {
36
+ type: "string",
37
+ value: "width",
38
+ template: ":width"
39
+ };
40
+ props.height = {
41
+ type: "string",
42
+ value: "height",
43
+ template: ":height"
44
+ };
45
+ } else {
46
+ const getSizeProps = addSizeFunctionAsset(imports, assets, options);
47
+ componentCode.push(`const size = computed(() => ${getSizeProps}(props.width, props.height, viewBox${isDynanicViewBox ? ".value" : ""}));`);
48
+ vueNamedImports.add("computed");
49
+ props.width = {
50
+ type: "string",
51
+ value: "width",
52
+ template: "v-bind=\"size\""
53
+ };
54
+ props.height = {
55
+ type: "string",
56
+ value: "height",
57
+ template: ""
58
+ };
59
+ }
60
+ if (options.square) props.square = { type: "boolean" };
61
+ const getViewBox = (viewBox$1) => hasFallback ? JSON.stringify(viewBox$1) : `'${getIconViewBox(viewBox$1)}'`;
62
+ const viewBoxValue = getViewBox(viewBox);
63
+ if (isDynanicViewBox) componentCode.unshift(`const baseViewBox = ${viewBoxValue};`, `const squareViewBox = ${getViewBox(makeSquareViewBox(viewBox))};`, `const viewBox = computed(() => props.square ? squareViewBox : baseViewBox);`);
64
+ else componentCode.unshift(`const viewBox = ${viewBoxValue};`);
65
+ props.viewBox = {
66
+ value: "viewBox",
67
+ template: ":viewBox=\"viewBox\""
68
+ };
69
+ componentCode.push(`const content = ${stringifyFactoryIconContent(data.icon, options)};`);
70
+ props.content = {
71
+ value: "content",
72
+ template: hasFallback ? `:content fallback="${data.fallback}"` : "v-html=\"content\""
73
+ };
74
+ const usedProps = getUsedFactoryProps(props);
75
+ if (usedProps.length) {
76
+ const tsCode = useTS ? `<{
77
+ ${stringifyFactoryPropTypes(props)}
78
+ }>` : "";
79
+ componentCode.unshift(`const props = defineProps${tsCode}(${JSON.stringify(usedProps)});\n`);
80
+ }
81
+ const template = `<template><${hasFallback ? "Icon" : "svg"} ${stringifyFactoryProps(props, ":{prop}=\"{value}\"")} /></template>`;
82
+ const content = `<script setup${useTS ? " lang=\"ts\"" : ""}>
83
+ ${stringifyFactoryImports(imports)}
84
+ ${componentCode.join("\n")}
85
+ <\/script>
86
+ ${template}
87
+ `;
88
+ const types = addVueComponentTypes(data, options, assets, props);
89
+ return {
90
+ assets,
91
+ content,
92
+ types
93
+ };
94
+ }
95
+
96
+ export { createVueComponent };
package/lib/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { ClassProp, classProps, defaultClassProp } from "./classname/const.js";
2
2
  import { splitClassName, toggleClassName } from "./classname/toggle.js";
3
+ import { ParsedXMLNode, ParsedXMLTagElement, ParsedXMLTextElement, StringifyXMLOptions } from "./xml/types.js";
4
+ import { ConvertSVGContentOptions, ConvertedSVGContent } from "./svg-css/types.js";
3
5
  import { createCSSClassName } from "./css/hash.js";
4
6
  import { stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector } from "./css/stringify.js";
5
7
  import { hashString } from "./helpers/hash/hash.js";
@@ -9,7 +11,6 @@ import { getUniqueHash } from "./helpers/hash/unique.js";
9
11
  import { cloneObject } from "./helpers/misc/clone.js";
10
12
  import { compareSets, compareValues } from "./helpers/misc/compare.js";
11
13
  import { sortObject } from "./helpers/misc/sort-object.js";
12
- import { ParsedXMLNode, ParsedXMLTagElement, ParsedXMLTextElement, StringifyXMLOptions } from "./xml/types.js";
13
14
  import { iterateXMLContent } from "./xml/iterate.js";
14
15
  import { parseXMLContent } from "./xml/parse.js";
15
16
  import { stringifyXMLContent } from "./xml/stringify.js";
@@ -19,9 +20,6 @@ import { removeDuplicateIDs } from "./svg/ids/duplicate.js";
19
20
  import { removeUnusedIDs } from "./svg/ids/unused.js";
20
21
  import { changeSVGIDs } from "./svg/ids/change.js";
21
22
  import { createUniqueIDs } from "./svg/ids/unique.js";
22
- import { ConvertedSVGContent, SVGConvertedToCSSProperties, SVGPropertyType } from "./svg-css/types.js";
23
- import { convertSVGPropertyToCSS } from "./svg-css/props/prop.js";
24
- import { extractSVGTagPropertiesForCSS } from "./svg-css/props/props.js";
25
- import { convertSVGRootToCSS } from "./svg-css/convert/root.js";
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, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector, stringifyXMLContent, toggleClassName };
23
+ import { convertSVGRootToCSS } from "./svg-css/root.js";
24
+ import { convertSVGContentToCSSRules } from "./svg-css/content.js";
25
+ export { ChangeIDResult, ClassProp, ConvertSVGContentOptions, ConvertedSVGContent, ParsedXMLNode, ParsedXMLTagElement, ParsedXMLTextElement, StringifyXMLOptions, UniqueHashOptions, changeIDInString, changeSVGIDs, classProps, cloneObject, compareSets, compareValues, convertSVGContentToCSSRules, convertSVGRootToCSS, createCSSClassName, createUniqueIDs, defaultClassProp, getUniqueHash, hashString, hashToString, iterateXMLContent, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitClassName, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector, stringifyXMLContent, toggleClassName };
package/lib/index.js CHANGED
@@ -16,9 +16,7 @@ import { removeDuplicateIDs } from "./svg/ids/duplicate.js";
16
16
  import { removeUnusedIDs } from "./svg/ids/unused.js";
17
17
  import { changeSVGIDs } from "./svg/ids/change.js";
18
18
  import { createUniqueIDs } from "./svg/ids/unique.js";
19
- import { convertSVGPropertyToCSS } from "./svg-css/props/prop.js";
20
- import { extractSVGTagPropertiesForCSS } from "./svg-css/props/props.js";
21
- import { convertSVGRootToCSS } from "./svg-css/convert/root.js";
22
- import { convertSVGContentToCSSRules } from "./svg-css/convert/content.js";
19
+ import { convertSVGRootToCSS } from "./svg-css/root.js";
20
+ import { convertSVGContentToCSSRules } from "./svg-css/content.js";
23
21
 
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 };
22
+ export { changeIDInString, changeSVGIDs, classProps, cloneObject, compareSets, compareValues, convertSVGContentToCSSRules, convertSVGRootToCSS, createCSSClassName, createUniqueIDs, defaultClassProp, getUniqueHash, hashString, hashToString, iterateXMLContent, parseXMLContent, removeDuplicateIDs, removeUnusedIDs, sortObject, splitClassName, stringifyCSSKeyframes, stringifyCSSRules, stringifyCSSSelector, stringifyXMLContent, toggleClassName };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Tags for animating one attribute in SVG
3
+ */
4
+ declare const svgSimpleAnimationTags: string[];
5
+ /**
6
+ * Tag for animating transformations in SVG
7
+ */
8
+ declare const svgAnimateTransformTag = "animateTransform";
9
+ /**
10
+ * Tag for animating motion in SVG
11
+ */
12
+ declare const svgAnimateMotionTag = "animateMotion";
13
+ /**
14
+ * All tags for animating SVG
15
+ */
16
+ declare const svgAnimationTags: string[];
17
+ export { svgAnimateMotionTag, svgAnimateTransformTag, svgAnimationTags, svgSimpleAnimationTags };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Tags for animating one attribute in SVG
3
+ */
4
+ const svgSimpleAnimationTags = [
5
+ "animate",
6
+ "set",
7
+ "discard"
8
+ ];
9
+ /**
10
+ * Tag for animating transformations in SVG
11
+ */
12
+ const svgAnimateTransformTag = "animateTransform";
13
+ /**
14
+ * Tag for animating motion in SVG
15
+ */
16
+ const svgAnimateMotionTag = "animateMotion";
17
+ /**
18
+ * All tags for animating SVG
19
+ */
20
+ const svgAnimationTags = [
21
+ ...svgSimpleAnimationTags,
22
+ svgAnimateTransformTag,
23
+ svgAnimateMotionTag
24
+ ];
25
+
26
+ export { svgAnimateMotionTag, svgAnimateTransformTag, svgAnimationTags, svgSimpleAnimationTags };
@@ -1,5 +1,4 @@
1
- import { ConvertedSVGContent } from "../types.js";
2
- import { ConvertSVGContentOptions } from "./types.js";
1
+ import { ConvertSVGContentOptions, ConvertedSVGContent } from "./types.js";
3
2
  /**
4
3
  * Convert SVG content string to SVG+CSS
5
4
  */
@@ -1,5 +1,5 @@
1
- import { parseXMLContent } from "../../xml/parse.js";
2
- import { stringifyXMLContent } from "../../xml/stringify.js";
1
+ import { parseXMLContent } from "../xml/parse.js";
2
+ import { stringifyXMLContent } from "../xml/stringify.js";
3
3
  import { convertSVGRootToCSS } from "./root.js";
4
4
 
5
5
  /**
@@ -1,8 +1,14 @@
1
+ /**
2
+ * SVG property types
3
+ */
1
4
  const propTypes = [
2
5
  "path",
3
6
  "px",
4
7
  "raw"
5
8
  ];
9
+ /**
10
+ * Props shared between multiple shapes
11
+ */
6
12
  const commonShapes = { px: [
7
13
  "width",
8
14
  "height",
@@ -14,6 +20,9 @@ const commonShapes = { px: [
14
20
  "rx",
15
21
  "ry"
16
22
  ] };
23
+ /**
24
+ * Shape specific properties that can be converted to CSS
25
+ */
17
26
  const props = {
18
27
  "*": {
19
28
  px: ["stroke-width"],
@@ -1,5 +1,5 @@
1
1
  import { ParsedXMLTagElement } from "../../xml/types.js";
2
- import { SVGConvertedToCSSProperties } from "../types.js";
2
+ import { SVGConvertedToCSSProperties } from "./types.js";
3
3
  /**
4
4
  * Extract SVG tag properties that can be converted to CSS
5
5
  *
@@ -1,11 +1,7 @@
1
1
  import { iterateXMLContent } from "../../xml/iterate.js";
2
2
  import { convertSVGPropertyToCSS } from "./prop.js";
3
+ import { svgAnimateTransformTag, svgSimpleAnimationTags } from "../animations/tags.js";
3
4
 
4
- const animationTags = [
5
- "animate",
6
- "set",
7
- "discard"
8
- ];
9
5
  /**
10
6
  * Extract SVG tag properties that can be converted to CSS
11
7
  *
@@ -19,11 +15,11 @@ function extractSVGTagPropertiesForCSS(tag) {
19
15
  const animatedProps = /* @__PURE__ */ new Set();
20
16
  iterateXMLContent(tag.children, (node) => {
21
17
  if (node.type === "tag") {
22
- if (animationTags.includes(node.tag)) {
18
+ if (svgSimpleAnimationTags.includes(node.tag)) {
23
19
  const prop = node.attribs.attributeName;
24
20
  if (typeof prop === "string") animatedProps.add(prop);
25
21
  }
26
- if (node.tag === "animateTransform") animatedProps.add("transform");
22
+ if (node.tag === svgAnimateTransformTag) animatedProps.add("transform");
27
23
  }
28
24
  });
29
25
  for (const prop in tag.attribs) if (!animatedProps.has(prop)) {
@@ -0,0 +1,9 @@
1
+ import { CSSRules } from "../../css/types.js";
2
+ /**
3
+ * Result of converting SVG properties to CSS
4
+ */
5
+ interface SVGConvertedToCSSProperties {
6
+ props: string[];
7
+ rules: CSSRules;
8
+ }
9
+ export { SVGConvertedToCSSProperties };
@@ -1,5 +1,5 @@
1
- import { CSSRules } from "../../css/types.js";
2
- import { ParsedXMLTagElement } from "../../xml/types.js";
1
+ import { CSSRules } from "../css/types.js";
2
+ import { ParsedXMLTagElement } from "../xml/types.js";
3
3
  /**
4
4
  * Convert SVG tags tree to SVG+CSS
5
5
  *
@@ -1,7 +1,7 @@
1
- import { iterateXMLContent } from "../../xml/iterate.js";
2
- import { createCSSClassName } from "../../css/hash.js";
3
- import { toggleClassName } from "../../classname/toggle.js";
4
- import { extractSVGTagPropertiesForCSS } from "../props/props.js";
1
+ import { iterateXMLContent } from "../xml/iterate.js";
2
+ import { createCSSClassName } from "../css/hash.js";
3
+ import { toggleClassName } from "../classname/toggle.js";
4
+ import { extractSVGTagPropertiesForCSS } from "./props/props.js";
5
5
 
6
6
  /**
7
7
  * Convert SVG tags tree to SVG+CSS
@@ -1,14 +1,10 @@
1
1
  import { CSSKeyframes, CSSRules } from "../css/types.js";
2
+ import { StringifyXMLOptions } from "../xml/types.js";
2
3
  /**
3
- * SVG property types
4
+ * Options for converting SVG content to SVG+CSS
4
5
  */
5
- type SVGPropertyType = 'path' | 'px' | 'raw';
6
- /**
7
- * Result of converting SVG properties to CSS
8
- */
9
- interface SVGConvertedToCSSProperties {
10
- props: string[];
11
- rules: CSSRules;
6
+ interface ConvertSVGContentOptions extends StringifyXMLOptions {
7
+ classNamePrefix?: string;
12
8
  }
13
9
  /**
14
10
  * Result of converting SVG content to SVG+CSS
@@ -18,4 +14,4 @@ interface ConvertedSVGContent {
18
14
  classes?: Record<string, CSSRules>;
19
15
  keyframes?: Record<string, CSSKeyframes>;
20
16
  }
21
- export { ConvertedSVGContent, SVGConvertedToCSSProperties, SVGPropertyType };
17
+ export { ConvertSVGContentOptions, ConvertedSVGContent };
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": "0.1.0",
6
+ "version": "0.1.2",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/cyberalien/svg-utils/issues",
9
9
  "homepage": "https://cyberalien.dev/",
@@ -1,5 +0,0 @@
1
- import { StringifyXMLOptions } from "../../xml/types.js";
2
- interface ConvertSVGContentOptions extends StringifyXMLOptions {
3
- classNamePrefix?: string;
4
- }
5
- export { ConvertSVGContentOptions };
@@ -1,11 +0,0 @@
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 };
@@ -1,20 +0,0 @@
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 };
@@ -1,6 +0,0 @@
1
- import { FactoryComponentTemplate } from "../types/component.js";
2
- /**
3
- * Create empty code object
4
- */
5
- declare function createFactoryCodeTemplate(): FactoryComponentTemplate;
6
- export { createFactoryCodeTemplate };
@@ -1,15 +0,0 @@
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 };
@@ -1,8 +0,0 @@
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 };
@@ -1,8 +0,0 @@
1
- import { FactoryIconData } from "../types/data.js";
2
- import { FactoryGeneratedComponent } from "../types/component.js";
3
- import { ComponentFactoryOptions } from "../types/options.js";
4
- /**
5
- * Create Vue component code
6
- */
7
- declare function createVueComponent(data: FactoryIconData, options: ComponentFactoryOptions): FactoryGeneratedComponent;
8
- export { createVueComponent };
@@ -1,11 +0,0 @@
1
- import { GeneratedAssetPath } from "../types/asset.js";
2
- import { ComponentFactoryFileSystemOptions } from "../types/options.js";
3
- /**
4
- * Generate asset filename based on options
5
- *
6
- * @param filename - Filename without path
7
- * @param options - Options to generate path
8
- * @returns Asset path
9
- */
10
- declare function getGeneratedAssetFilename(filename: string, options: Pick<ComponentFactoryFileSystemOptions, 'chunksPath'>): GeneratedAssetPath;
11
- export { getGeneratedAssetFilename };
@@ -1,16 +0,0 @@
1
- /**
2
- * Generate asset filename based on options
3
- *
4
- * @param filename - Filename without path
5
- * @param options - Options to generate path
6
- * @returns Asset path
7
- */
8
- function getGeneratedAssetFilename(filename, options) {
9
- const { chunksPath } = options;
10
- return {
11
- import: `${chunksPath.import}/${filename}`,
12
- filename: `${chunksPath.filename}/${filename}`
13
- };
14
- }
15
-
16
- export { getGeneratedAssetFilename };
@@ -1,11 +0,0 @@
1
- import { GeneratedAssetPath } from "../types/asset.js";
2
- import { ComponentFactoryFileSystemOptions } from "../types/options.js";
3
- /**
4
- * Get relative path to asset from component
5
- *
6
- * @param path Path to asset, without trailing slash
7
- * @param options Factory options
8
- * @returns Asset path
9
- */
10
- declare function getFactoryRelativeAssetPath(path: string, options: Pick<ComponentFactoryFileSystemOptions, 'doubleDirsForComponents' | 'prefixDirsForComponents'>): GeneratedAssetPath;
11
- export { getFactoryRelativeAssetPath };
@@ -1,15 +0,0 @@
1
- /**
2
- * Get relative path to asset from component
3
- *
4
- * @param path Path to asset, without trailing slash
5
- * @param options Factory options
6
- * @returns Asset path
7
- */
8
- function getFactoryRelativeAssetPath(path, options) {
9
- return {
10
- import: `../${options.prefixDirsForComponents ? "../" : ""}${options.doubleDirsForComponents ? "../" : ""}${path}`,
11
- filename: path
12
- };
13
- }
14
-
15
- export { getFactoryRelativeAssetPath };
@@ -1,6 +0,0 @@
1
- import { FactoryComponentProps } from "../types/props.js";
2
- /**
3
- * Stringify properties for component
4
- */
5
- declare function stringifyFactoryPropTypes(props: FactoryComponentProps): string;
6
- export { stringifyFactoryPropTypes };
@@ -1,16 +0,0 @@
1
- /**
2
- * Stringify properties for component
3
- */
4
- function stringifyFactoryPropTypes(props) {
5
- const result = [];
6
- for (const key in props) {
7
- const value = props[key];
8
- if (typeof value !== "string") {
9
- const type = value.type;
10
- if (type) result.push(`\t${key}${value.required ? "" : "?"}: ${type};`);
11
- }
12
- }
13
- return result.join("\n");
14
- }
15
-
16
- export { stringifyFactoryPropTypes };