@cyberalien/svg-utils 0.0.17 → 0.1.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 (124) 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 +25 -0
  45. package/lib/svg-css/factory/components/vue.d.ts +8 -0
  46. package/lib/svg-css/factory/components/vue.js +103 -0
  47. package/lib/svg-css/factory/content/size.d.ts +11 -0
  48. package/lib/svg-css/factory/content/size.js +22 -0
  49. package/lib/svg-css/factory/content/stringify.d.ts +7 -0
  50. package/lib/svg-css/factory/content/stringify.js +17 -0
  51. package/lib/svg-css/factory/css/generate.d.ts +11 -0
  52. package/lib/svg-css/factory/css/generate.js +45 -0
  53. package/lib/svg-css/factory/css/name.d.ts +7 -0
  54. package/lib/svg-css/factory/css/name.js +12 -0
  55. package/lib/svg-css/factory/export/exports.d.ts +10 -0
  56. package/lib/svg-css/factory/export/exports.js +11 -0
  57. package/lib/svg-css/factory/export/file.d.ts +6 -0
  58. package/lib/svg-css/factory/export/file.js +12 -0
  59. package/lib/svg-css/factory/export/fs.d.ts +2 -2
  60. package/lib/svg-css/factory/export/merge.d.ts +7 -0
  61. package/lib/svg-css/factory/export/merge.js +23 -0
  62. package/lib/svg-css/factory/filenames/asset.d.ts +11 -0
  63. package/lib/svg-css/factory/filenames/asset.js +16 -0
  64. package/lib/svg-css/factory/filenames/component.d.ts +12 -0
  65. package/lib/svg-css/factory/filenames/component.js +14 -0
  66. package/lib/svg-css/factory/filenames/css.d.ts +7 -0
  67. package/lib/svg-css/factory/filenames/css.js +14 -0
  68. package/lib/svg-css/factory/filenames/options.d.ts +6 -0
  69. package/lib/svg-css/factory/filenames/options.js +27 -0
  70. package/lib/svg-css/factory/filenames/path.d.ts +11 -0
  71. package/lib/svg-css/factory/filenames/path.js +15 -0
  72. package/lib/svg-css/factory/filenames/types.d.ts +8 -0
  73. package/lib/svg-css/factory/filenames/types.js +14 -0
  74. package/lib/svg-css/factory/imports/add.d.ts +10 -0
  75. package/lib/svg-css/factory/imports/add.js +18 -0
  76. package/lib/svg-css/factory/imports/create.d.ts +6 -0
  77. package/lib/svg-css/factory/imports/create.js +15 -0
  78. package/lib/svg-css/factory/imports/stringify.d.ts +6 -0
  79. package/lib/svg-css/factory/imports/stringify.js +47 -0
  80. package/lib/svg-css/factory/props/object.d.ts +6 -0
  81. package/lib/svg-css/factory/props/object.js +10 -0
  82. package/lib/svg-css/factory/props/stringify.d.ts +10 -0
  83. package/lib/svg-css/factory/props/stringify.js +21 -0
  84. package/lib/svg-css/factory/props/types.d.ts +6 -0
  85. package/lib/svg-css/factory/props/types.js +16 -0
  86. package/lib/svg-css/factory/types/asset.d.ts +8 -0
  87. package/lib/svg-css/factory/types/asset.js +1 -0
  88. package/lib/svg-css/factory/types/component.d.ts +38 -0
  89. package/lib/svg-css/factory/types/component.js +1 -0
  90. package/lib/svg-css/factory/types/css.d.ts +5 -0
  91. package/lib/svg-css/factory/types/css.js +1 -0
  92. package/lib/svg-css/factory/types/data.d.ts +13 -0
  93. package/lib/svg-css/factory/types/data.js +1 -0
  94. package/lib/svg-css/factory/types/file.d.ts +14 -0
  95. package/lib/svg-css/factory/types/file.js +1 -0
  96. package/lib/svg-css/factory/types/options.d.ts +26 -0
  97. package/lib/svg-css/factory/types/options.js +1 -0
  98. package/lib/svg-css/factory/types/props.d.ts +14 -0
  99. package/lib/svg-css/factory/types/props.js +1 -0
  100. package/lib/svg-css/factory/types/source.d.ts +10 -0
  101. package/lib/svg-css/factory/types/source.js +1 -0
  102. package/lib/svg-css/types.d.ts +2 -1
  103. package/lib/xml/parse.js +2 -4
  104. package/package.json +11 -9
  105. package/lib/svg-css/factory/helpers/add-css.d.ts +0 -8
  106. package/lib/svg-css/factory/helpers/add-css.js +0 -32
  107. package/lib/svg-css/factory/helpers/component-name.d.ts +0 -9
  108. package/lib/svg-css/factory/helpers/component-name.js +0 -17
  109. package/lib/svg-css/factory/helpers/component-path.d.ts +0 -5
  110. package/lib/svg-css/factory/helpers/component-path.js +0 -9
  111. package/lib/svg-css/factory/helpers/css-filename.d.ts +0 -5
  112. package/lib/svg-css/factory/helpers/css-filename.js +0 -10
  113. package/lib/svg-css/factory/helpers/exports.d.ts +0 -6
  114. package/lib/svg-css/factory/helpers/exports.js +0 -10
  115. package/lib/svg-css/factory/helpers/merge.d.ts +0 -6
  116. package/lib/svg-css/factory/helpers/merge.js +0 -19
  117. package/lib/svg-css/factory/helpers/options.d.ts +0 -6
  118. package/lib/svg-css/factory/helpers/options.js +0 -12
  119. package/lib/svg-css/factory/helpers/prefix.d.ts +0 -6
  120. package/lib/svg-css/factory/helpers/prefix.js +0 -8
  121. package/lib/svg-css/factory/iconify/vue.d.ts +0 -6
  122. package/lib/svg-css/factory/iconify/vue.js +0 -72
  123. package/lib/svg-css/factory/types.d.ts +0 -48
  124. /package/lib/{svg-css/factory → iconify/icon-set}/types.js +0 -0
@@ -0,0 +1,41 @@
1
+ import { getIconViewBox } from "../../../svg/viewbox/value.js";
2
+ import { getComponentSizeValues } from "../content/size.js";
3
+ import { stringifyFactoryIconContent } from "../content/stringify.js";
4
+ import { getGeneratedComponentTypesFilename } from "../filenames/types.js";
5
+ import { createFactoryImports } from "../imports/create.js";
6
+ import { generateCSSFilesForComponent } from "../css/generate.js";
7
+ import { stringifyFactoryImports } from "../imports/stringify.js";
8
+ import { factoryPropTemplate, stringifyFactoryProps } from "../props/stringify.js";
9
+
10
+ /**
11
+ * Create raw component code
12
+ */
13
+ function createRawComponent(data, options) {
14
+ const assets = [];
15
+ const imports = createFactoryImports();
16
+ const codeLines = [];
17
+ generateCSSFilesForComponent(data.icon, imports, assets, options);
18
+ const props = {
19
+ xmlns: "http://www.w3.org/2000/svg",
20
+ ...getComponentSizeValues(options, data.viewBox),
21
+ viewBox: getIconViewBox(data.viewBox)
22
+ };
23
+ const icon = {
24
+ ...data.icon,
25
+ content: `<svg ${stringifyFactoryProps(props, factoryPropTemplate)}>${data.icon.content}</svg>`
26
+ };
27
+ codeLines.push(`const icon = ${stringifyFactoryIconContent(icon, options)};\n`);
28
+ codeLines.push("export default icon;\n");
29
+ const importsCode = stringifyFactoryImports(imports);
30
+ if (importsCode) codeLines.unshift(importsCode);
31
+ assets.push({
32
+ ...getGeneratedComponentTypesFilename(data, options),
33
+ content: `const icon: string;\nexport default icon;\n`
34
+ });
35
+ return {
36
+ assets,
37
+ content: codeLines.join("\n")
38
+ };
39
+ }
40
+
41
+ export { createRawComponent };
@@ -0,0 +1,79 @@
1
+ import { getGeneratedAssetFilename } from "../../filenames/asset.js";
2
+
3
+ const functionName = "getSizeProps";
4
+ const functionContent = `
5
+ const unitsSplit = /(-?[0-9.]*[0-9]+[0-9.]*)/g;
6
+ const unitsTest = /^-?[0-9.]*[0-9]+[0-9.]*$/g;
7
+
8
+ const precision = 100;
9
+
10
+ function calculateSize(size, ratio) {
11
+ if (ratio === 1) {
12
+ return value;
13
+ }
14
+
15
+ const oldParts = size.split(unitsSplit);
16
+ if (oldParts === null || !oldParts.length) {
17
+ return size;
18
+ }
19
+
20
+ const newParts = [];
21
+ let code = oldParts.shift();
22
+ let isNumber = unitsTest.test(code);
23
+
24
+ while (true) {
25
+ if (isNumber) {
26
+ const num = parseFloat(code);
27
+ if (isNaN(num)) {
28
+ newParts.push(code);
29
+ } else {
30
+ newParts.push(Math.ceil(num * ratio * precision) / precision);
31
+ }
32
+ } else {
33
+ newParts.push(code);
34
+ }
35
+
36
+ code = oldParts.shift();
37
+ if (code === undefined) {
38
+ return newParts.join('');
39
+ }
40
+
41
+ isNumber = !isNumber;
42
+ }
43
+ }
44
+
45
+ function ${functionName}(width, height, ratio) {
46
+ if (width && height) {
47
+ return { width, height };
48
+ }
49
+ if (height) {
50
+ return {
51
+ width: calculateSize(height, ratio),
52
+ height,
53
+ };
54
+ }
55
+ if (width) {
56
+ return {
57
+ width,
58
+ height: calculateSize(width, 1 / ratio),
59
+ };
60
+ }
61
+ return {};
62
+ }
63
+
64
+ export { ${functionName} };
65
+ `;
66
+ /**
67
+ * Adds getSizeProps() function to assets
68
+ */
69
+ function addSizeFunctionAsset(imports, assets, options) {
70
+ const filename = getGeneratedAssetFilename("size.js", options);
71
+ imports.named[filename.import] = new Set([functionName]);
72
+ assets.push({
73
+ ...filename,
74
+ content: functionContent
75
+ });
76
+ return functionName;
77
+ }
78
+
79
+ export { addSizeFunctionAsset };
@@ -0,0 +1,25 @@
1
+ import { getGeneratedComponentTypesFilename } from "../../filenames/types.js";
2
+ import { stringifyFactoryPropTypes } from "../../props/types.js";
3
+
4
+ /**
5
+ * Add Vue component types
6
+ */
7
+ function addVueComponentTypes(data, options, assets, props) {
8
+ const propTypes = stringifyFactoryPropTypes(props);
9
+ assets.push({
10
+ ...getGeneratedComponentTypesFilename(data, options),
11
+ content: `import { DefineSetupFnComponent, PublicProps } from 'vue';
12
+
13
+ interface IconProps {
14
+ ${propTypes}
15
+ }
16
+
17
+ declare const Component: DefineSetupFnComponent<IconProps, {}, {}, IconProps & {}, PublicProps>;
18
+
19
+ export { type IconProps };
20
+ export default Component;
21
+ `
22
+ });
23
+ }
24
+
25
+ export { addVueComponentTypes };
@@ -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 Vue component code
6
+ */
7
+ declare function createVueComponent(data: FactoryIconData, options: ComponentFactoryOptions): FactoryGeneratedComponent;
8
+ export { createVueComponent };
@@ -0,0 +1,103 @@
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";
11
+
12
+ /**
13
+ * Create Vue component code
14
+ */
15
+ function createVueComponent(data, options) {
16
+ const assets = [];
17
+ const imports = createFactoryImports();
18
+ const hasFallback = !!data.fallback;
19
+ if (hasFallback) imports.named["@iconify/css-vue"] = new Set(["Icon"]);
20
+ const vueNamedImports = new Set(["defineComponent", "h"]);
21
+ imports.named["vue"] = vueNamedImports;
22
+ generateCSSFilesForComponent(data.icon, imports, assets, options);
23
+ const componentCode = [];
24
+ const sizeProps = getComponentSizeValues(options, data.viewBox);
25
+ const props = {};
26
+ if (!hasFallback) props.xmlns = "http://www.w3.org/2000/svg";
27
+ const usedProps = [];
28
+ const viewBox = data.viewBox;
29
+ const isDynanicViewBox = !sizeProps && options.square && viewBox.width !== viewBox.height;
30
+ if (sizeProps) {
31
+ props.width = sizeProps.width;
32
+ props.height = sizeProps.height;
33
+ } 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" };
65
+ }
66
+ const getViewBox = (viewBox$1) => hasFallback ? JSON.stringify(viewBox$1) : `'${getIconViewBox(viewBox$1)}'`;
67
+ const viewBoxValue = getViewBox(viewBox);
68
+ if (isDynanicViewBox) {
69
+ componentCode.unshift(`const baseViewBox = ${viewBoxValue};`, `const squareViewBox = ${getViewBox(makeSquareViewBox(viewBox))};`, `const viewBox = computed(() => props.square ? squareViewBox : baseViewBox);`);
70
+ props.viewBox = {
71
+ value: "viewBox",
72
+ template: "viewBox: viewBox.value,"
73
+ };
74
+ } else {
75
+ componentCode.unshift(`const viewBox = ${viewBoxValue};`);
76
+ props.viewBox = {
77
+ value: "viewBox",
78
+ template: "viewBox,"
79
+ };
80
+ }
81
+ props[hasFallback ? "content" : "innerHTML"] = { value: stringifyFactoryIconContent(data.icon, options) };
82
+ if (data.fallback) props.fallback = data.fallback;
83
+ addVueComponentTypes(data, options, assets, props);
84
+ componentCode.push(`return () => h(${hasFallback ? "Icon" : "'svg'"}, {
85
+ ${stringifyFactoryPropsAsJSON(props, "\n ")}
86
+ });`);
87
+ const componentFunction = `const Component = defineComponent(
88
+ (${usedProps.length ? "props" : ""}) => {
89
+ ${componentCode.join("\n ")}
90
+ },
91
+ {
92
+ props: ${JSON.stringify(usedProps)}
93
+ }
94
+ );
95
+ `;
96
+ const content = `${stringifyFactoryImports(imports)}\n${componentFunction}\nexport default Component;\n`;
97
+ return {
98
+ assets,
99
+ content
100
+ };
101
+ }
102
+
103
+ export { createVueComponent };
@@ -0,0 +1,11 @@
1
+ import { IconViewBox } from "../../../svg/viewbox/types.js";
2
+ import { ComponentFactoryRenderingOptions } from "../types/options.js";
3
+ interface SizeResult {
4
+ width: string;
5
+ height: string;
6
+ }
7
+ /**
8
+ * Get size values for component
9
+ */
10
+ declare function getComponentSizeValues(options: Pick<ComponentFactoryRenderingOptions, 'width' | 'height' | 'square'>, viewBox: IconViewBox): SizeResult | undefined;
11
+ export { getComponentSizeValues };
@@ -0,0 +1,22 @@
1
+ import { calculateSize } from "../../../svg/props/size.js";
2
+
3
+ /**
4
+ * Get size values for component
5
+ */
6
+ function getComponentSizeValues(options, viewBox) {
7
+ const { width, height, square } = options;
8
+ if (width && height) return {
9
+ width,
10
+ height
11
+ };
12
+ if (height) return {
13
+ width: square ? height : calculateSize(height, viewBox.width / viewBox.height),
14
+ height
15
+ };
16
+ if (width) return {
17
+ width,
18
+ height: square ? width : calculateSize(width, viewBox.height / viewBox.width)
19
+ };
20
+ }
21
+
22
+ export { getComponentSizeValues };
@@ -0,0 +1,7 @@
1
+ import { ComponentFactorySource } from "../types/source.js";
2
+ import { ComponentFactoryRenderingOptions } from "../types/options.js";
3
+ /**
4
+ * Convert icon content to a string literal
5
+ */
6
+ declare function stringifyFactoryIconContent(icon: ComponentFactorySource, options: Pick<ComponentFactoryRenderingOptions, 'cssMode'>): string;
7
+ export { stringifyFactoryIconContent };
@@ -0,0 +1,17 @@
1
+ import { generateCSSDefaultImportName } from "../css/name.js";
2
+
3
+ /**
4
+ * Convert icon content to a string literal
5
+ */
6
+ function stringifyFactoryIconContent(icon, options) {
7
+ const { cssMode } = options;
8
+ let content = "`" + icon.content.replace(/`/g, "\\`") + "`";
9
+ switch (cssMode) {
10
+ case "import": return content;
11
+ case "module":
12
+ for (const className in icon.classes) content = content.replace(new RegExp("([\" ])(" + className + ")([\" ])", "g"), `$1\${${generateCSSDefaultImportName(className)}['${className}']}$3`);
13
+ return content;
14
+ }
15
+ }
16
+
17
+ export { stringifyFactoryIconContent };
@@ -0,0 +1,11 @@
1
+ import { ComponentFactorySource } from "../types/source.js";
2
+ import { GeneratedAssetFile } from "../types/file.js";
3
+ import { FactoryComponentImports } from "../types/component.js";
4
+ import { ComponentFactoryOptions } from "../types/options.js";
5
+ /**
6
+ * Generate CSS files for component
7
+ *
8
+ * Adds imports to imports object, adds assets
9
+ */
10
+ declare function generateCSSFilesForComponent(content: ComponentFactorySource, imports: FactoryComponentImports, assets: GeneratedAssetFile[], options: Pick<ComponentFactoryOptions, 'cssMode' | 'cssPath' | 'doubleDirsForCSS'>): void;
11
+ export { generateCSSFilesForComponent };
@@ -0,0 +1,45 @@
1
+ import { stringifyCSSKeyframes, stringifyCSSSelector } from "../../../css/stringify.js";
2
+ import { generateCSSDefaultImportName } from "./name.js";
3
+ import { getGeneratedCSSFilename } from "../filenames/css.js";
4
+
5
+ /**
6
+ * Generate CSS files for component
7
+ *
8
+ * Adds imports to imports object, adds assets
9
+ */
10
+ function generateCSSFilesForComponent(content, imports, assets, options) {
11
+ const { classes, keyframes } = content;
12
+ if (!classes) return;
13
+ const isModule = options.cssMode === "module";
14
+ const embedAnimations = isModule;
15
+ for (const className in classes) {
16
+ const baseContent = stringifyCSSSelector(`.${className}`, classes[className]);
17
+ let content$1 = baseContent;
18
+ if (embedAnimations && keyframes) {
19
+ for (const animationName in keyframes) if (baseContent.includes(animationName)) {
20
+ const value = keyframes[animationName];
21
+ content$1 += "\n" + (typeof value === "string" ? value : stringifyCSSKeyframes(animationName, value));
22
+ }
23
+ }
24
+ const filename = getGeneratedCSSFilename(className, options);
25
+ assets.push({
26
+ ...filename,
27
+ content: content$1
28
+ });
29
+ if (isModule) imports.modules[filename.import] = generateCSSDefaultImportName(className);
30
+ else imports.css.add(filename.import);
31
+ }
32
+ if (!embedAnimations && keyframes) for (const animationName in keyframes) {
33
+ const value = keyframes[animationName];
34
+ const content$1 = typeof value === "string" ? value : stringifyCSSKeyframes(animationName, value);
35
+ const filename = getGeneratedCSSFilename(animationName, options);
36
+ assets.push({
37
+ ...filename,
38
+ content: content$1
39
+ });
40
+ if (isModule) imports.modules[filename.import] = generateCSSDefaultImportName(animationName);
41
+ else imports.css.add(filename.import);
42
+ }
43
+ }
44
+
45
+ export { generateCSSFilesForComponent };
@@ -0,0 +1,7 @@
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 };
@@ -0,0 +1,12 @@
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 };
@@ -0,0 +1,10 @@
1
+ import { FactoryComponent } from "../types/component.js";
2
+ interface Options {
3
+ ext?: string;
4
+ data?: Record<string, string>;
5
+ }
6
+ /**
7
+ * Add exports for main files to object
8
+ */
9
+ declare function createExportsForMainFiles(data: FactoryComponent[], options?: Options): Record<string, string>;
10
+ export { createExportsForMainFiles };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Add exports for main files to object
3
+ */
4
+ function createExportsForMainFiles(data, options = {}) {
5
+ const result = options?.data || Object.create(null);
6
+ const ext = options.ext || "";
7
+ for (const { icon, filename } of data) result[`./${icon}${ext}`] = `./${filename}`;
8
+ return result;
9
+ }
10
+
11
+ export { createExportsForMainFiles };
@@ -0,0 +1,6 @@
1
+ import { FactoryComponent, FactoryGeneratedComponent } from "../types/component.js";
2
+ /**
3
+ * Add icon and filename to generated component
4
+ */
5
+ declare function convertGeneratedComponentToFile(icon: string, filename: string, item: FactoryGeneratedComponent): FactoryComponent;
6
+ export { convertGeneratedComponentToFile };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Add icon and filename to generated component
3
+ */
4
+ function convertGeneratedComponentToFile(icon, filename, item) {
5
+ return {
6
+ icon,
7
+ filename,
8
+ ...item
9
+ };
10
+ }
11
+
12
+ export { convertGeneratedComponentToFile };
@@ -1,6 +1,6 @@
1
- import { ExportedComponentFile } from "../types.js";
1
+ import { GeneratedComponentFile } from "../types/file.js";
2
2
  /**
3
3
  * Save exported files to filesystem
4
4
  */
5
- declare function saveExportedFilesToFS(files: ExportedComponentFile[], dir: string): Promise<number>;
5
+ declare function saveExportedFilesToFS(files: GeneratedComponentFile[], dir: string): Promise<number>;
6
6
  export { saveExportedFilesToFS };
@@ -0,0 +1,7 @@
1
+ import { GeneratedComponentFile } from "../types/file.js";
2
+ import { FactoryComponent } from "../types/component.js";
3
+ /**
4
+ * Merge exported component files into single array
5
+ */
6
+ declare function mergeExportedComponentFiles(items: FactoryComponent[], files?: GeneratedComponentFile[]): GeneratedComponentFile[];
7
+ export { mergeExportedComponentFiles };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Merge exported component files into single array
3
+ */
4
+ function mergeExportedComponentFiles(items, files) {
5
+ const added = new Set(files?.map((item) => item.filename));
6
+ files = files ?? [];
7
+ const add = ({ filename, content }) => {
8
+ if (!added.has(filename)) {
9
+ added.add(filename);
10
+ files.push({
11
+ filename,
12
+ content
13
+ });
14
+ }
15
+ };
16
+ for (const item of items) {
17
+ for (const asset of item.assets) add(asset);
18
+ add(item);
19
+ }
20
+ return files;
21
+ }
22
+
23
+ export { mergeExportedComponentFiles };
@@ -0,0 +1,11 @@
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 };
@@ -0,0 +1,16 @@
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 };
@@ -0,0 +1,12 @@
1
+ import { FactoryIconData } from "../types/data.js";
2
+ import { ComponentFactoryFileSystemOptions } from "../types/options.js";
3
+ /**
4
+ * Generate component filename based on options
5
+ *
6
+ * @param icon Icon data (name and prefix)
7
+ * @param componentExtension Component file extension (e.g. '.tsx')
8
+ * @param options Factory options
9
+ * @returns Generated filename
10
+ */
11
+ declare function getGeneratedComponentFilename(icon: Pick<FactoryIconData, 'name' | 'prefix'>, componentExtension: string, options: Pick<ComponentFactoryFileSystemOptions, 'doubleDirsForComponents' | 'prefixDirsForComponents'>): string;
12
+ export { getGeneratedComponentFilename };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Generate component filename based on options
3
+ *
4
+ * @param icon Icon data (name and prefix)
5
+ * @param componentExtension Component file extension (e.g. '.tsx')
6
+ * @param options Factory options
7
+ * @returns Generated filename
8
+ */
9
+ function getGeneratedComponentFilename(icon, componentExtension, options) {
10
+ const { name, prefix } = icon;
11
+ return (options.prefixDirsForComponents ? `${prefix}/` : "") + (options.doubleDirsForComponents ? `${name.slice(0, 1).toLowerCase()}/` : "") + name + componentExtension;
12
+ }
13
+
14
+ export { getGeneratedComponentFilename };
@@ -0,0 +1,7 @@
1
+ import { GeneratedAssetPath } from "../types/asset.js";
2
+ import { ComponentFactoryOptions } from "../types/options.js";
3
+ /**
4
+ * Generate CSS filename based on options
5
+ */
6
+ declare function getGeneratedCSSFilename(name: string, options: Pick<ComponentFactoryOptions, 'cssMode' | 'cssPath' | 'doubleDirsForCSS'>): GeneratedAssetPath;
7
+ export { getGeneratedCSSFilename };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Generate CSS filename based on options
3
+ */
4
+ function getGeneratedCSSFilename(name, options) {
5
+ const { cssPath, doubleDirsForCSS, cssMode } = options;
6
+ const baseName = doubleDirsForCSS ? `${name.slice(0, 1).toLowerCase()}/${name}` : name;
7
+ const filename = cssMode === "module" ? `${baseName}.module.css` : `${baseName}.css`;
8
+ return {
9
+ import: `${cssPath.import}/${filename}`,
10
+ filename: `${cssPath.filename}/${filename}`
11
+ };
12
+ }
13
+
14
+ export { getGeneratedCSSFilename };
@@ -0,0 +1,6 @@
1
+ import { ComponentFactoryFileSystemOptions } from "../types/options.js";
2
+ /**
3
+ * Generate file system options
4
+ */
5
+ declare function componentFactoryFileSystemOptions(base: Partial<ComponentFactoryFileSystemOptions>): ComponentFactoryFileSystemOptions;
6
+ export { componentFactoryFileSystemOptions };
@@ -0,0 +1,27 @@
1
+ import { getFactoryRelativeAssetPath } from "./path.js";
2
+
3
+ /**
4
+ * Generate file system options
5
+ */
6
+ function componentFactoryFileSystemOptions(base) {
7
+ const doubleDirsForCSS = base.doubleDirsForCSS ?? true;
8
+ const prefixDirsForComponents = base.prefixDirsForComponents ?? false;
9
+ const doubleDirsForComponents = base.doubleDirsForComponents ?? true;
10
+ const chunksPath = base.chunksPath ?? getFactoryRelativeAssetPath("assets", {
11
+ doubleDirsForComponents,
12
+ prefixDirsForComponents
13
+ });
14
+ const cssPath = base.cssPath ?? getFactoryRelativeAssetPath("css", {
15
+ doubleDirsForComponents,
16
+ prefixDirsForComponents
17
+ });
18
+ return {
19
+ doubleDirsForCSS,
20
+ prefixDirsForComponents,
21
+ doubleDirsForComponents,
22
+ chunksPath,
23
+ cssPath
24
+ };
25
+ }
26
+
27
+ export { componentFactoryFileSystemOptions };
@@ -0,0 +1,11 @@
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 };
@@ -0,0 +1,15 @@
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 };
@@ -0,0 +1,8 @@
1
+ import { FactoryIconData } from "../types/data.js";
2
+ import { GeneratedAssetPath } from "../types/asset.js";
3
+ import { ComponentFactoryFileSystemOptions } from "../types/options.js";
4
+ /**
5
+ * Generate component types filename based on options
6
+ */
7
+ declare function getGeneratedComponentTypesFilename(icon: Pick<FactoryIconData, 'name' | 'prefix'>, options: Pick<ComponentFactoryFileSystemOptions, 'doubleDirsForComponents' | 'prefixDirsForComponents'>): GeneratedAssetPath;
8
+ export { getGeneratedComponentTypesFilename };