@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.
- package/lib/css/stringify.d.ts +6 -2
- package/lib/css/stringify.js +21 -1
- package/lib/css/types.d.ts +12 -1
- package/lib/helpers/misc/strings.js +2 -4
- package/lib/iconify/icon/nornalise.d.ts +7 -0
- package/lib/iconify/icon/nornalise.js +63 -0
- package/lib/iconify/icon/types.d.ts +6 -0
- package/lib/iconify/icon/types.js +1 -0
- package/lib/iconify/icon-set/defaults.d.ts +6 -0
- package/lib/iconify/icon-set/defaults.js +19 -0
- package/lib/iconify/icon-set/icon.d.ts +6 -0
- package/lib/iconify/icon-set/icon.js +24 -0
- package/lib/iconify/icon-set/parse.d.ts +7 -0
- package/lib/iconify/icon-set/parse.js +31 -0
- package/lib/iconify/icon-set/types.d.ts +6 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/svg/content/defs.d.ts +20 -0
- package/lib/svg/content/defs.js +44 -0
- package/lib/svg/ids/duplicate.js +1 -4
- package/lib/svg/ids/unused.js +1 -2
- package/lib/svg/props/size.d.ts +8 -0
- package/lib/svg/props/size.js +34 -0
- package/lib/svg/props/stringify.d.ts +5 -0
- package/lib/svg/props/stringify.js +8 -0
- package/lib/svg/viewbox/minify.d.ts +6 -0
- package/lib/svg/viewbox/minify.js +15 -0
- package/lib/svg/viewbox/parse.d.ts +6 -0
- package/lib/svg/viewbox/parse.js +17 -0
- package/lib/svg/viewbox/square.d.ts +6 -0
- package/lib/svg/viewbox/square.js +24 -0
- package/lib/svg-css/convert/content.d.ts +2 -5
- package/lib/svg-css/convert/types.d.ts +5 -0
- package/lib/svg-css/convert/types.js +1 -0
- package/lib/svg-css/factory/code/iconify.d.ts +11 -0
- package/lib/svg-css/factory/code/iconify.js +20 -0
- package/lib/svg-css/factory/code/stringify.d.ts +5 -0
- package/lib/svg-css/factory/code/stringify.js +9 -0
- package/lib/svg-css/factory/code/template.d.ts +6 -0
- package/lib/svg-css/factory/code/template.js +15 -0
- package/lib/svg-css/factory/components/raw.d.ts +8 -0
- package/lib/svg-css/factory/components/raw.js +41 -0
- package/lib/svg-css/factory/components/shared/size.js +79 -0
- package/lib/svg-css/factory/components/vue/types.js +27 -0
- package/lib/svg-css/factory/components/vue-func.d.ts +8 -0
- package/lib/svg-css/factory/components/vue-func.js +99 -0
- package/lib/svg-css/factory/components/vue.d.ts +11 -0
- package/lib/svg-css/factory/components/vue.js +96 -0
- package/lib/svg-css/factory/content/size.d.ts +11 -0
- package/lib/svg-css/factory/content/size.js +22 -0
- package/lib/svg-css/factory/content/stringify.d.ts +7 -0
- package/lib/svg-css/factory/content/stringify.js +17 -0
- package/lib/svg-css/factory/css/generate.d.ts +11 -0
- package/lib/svg-css/factory/css/generate.js +45 -0
- package/lib/svg-css/factory/css/name.d.ts +7 -0
- package/lib/svg-css/factory/css/name.js +12 -0
- package/lib/svg-css/factory/export/exports.d.ts +11 -0
- package/lib/svg-css/factory/export/exports.js +14 -0
- package/lib/svg-css/factory/export/file.d.ts +6 -0
- package/lib/svg-css/factory/export/file.js +12 -0
- package/lib/svg-css/factory/export/fs.d.ts +2 -2
- package/lib/svg-css/factory/export/merge.d.ts +7 -0
- package/lib/svg-css/factory/export/merge.js +23 -0
- package/lib/svg-css/factory/filenames/asset.d.ts +11 -0
- package/lib/svg-css/factory/filenames/asset.js +16 -0
- package/lib/svg-css/factory/filenames/component.d.ts +12 -0
- package/lib/svg-css/factory/filenames/component.js +15 -0
- package/lib/svg-css/factory/filenames/css.d.ts +7 -0
- package/lib/svg-css/factory/filenames/css.js +14 -0
- package/lib/svg-css/factory/filenames/options.d.ts +6 -0
- package/lib/svg-css/factory/filenames/options.js +27 -0
- package/lib/svg-css/factory/filenames/path.d.ts +11 -0
- package/lib/svg-css/factory/filenames/path.js +18 -0
- package/lib/svg-css/factory/filenames/types.d.ts +8 -0
- package/lib/svg-css/factory/filenames/types.js +14 -0
- package/lib/svg-css/factory/imports/add.d.ts +10 -0
- package/lib/svg-css/factory/imports/add.js +18 -0
- package/lib/svg-css/factory/imports/create.d.ts +6 -0
- package/lib/svg-css/factory/imports/create.js +15 -0
- package/lib/svg-css/factory/imports/stringify.d.ts +6 -0
- package/lib/svg-css/factory/imports/stringify.js +47 -0
- package/lib/svg-css/factory/props/object.d.ts +6 -0
- package/lib/svg-css/factory/props/object.js +10 -0
- package/lib/svg-css/factory/props/stringify.d.ts +10 -0
- package/lib/svg-css/factory/props/stringify.js +21 -0
- package/lib/svg-css/factory/props/types.d.ts +10 -0
- package/lib/svg-css/factory/props/types.js +27 -0
- package/lib/svg-css/factory/types/asset.d.ts +8 -0
- package/lib/svg-css/factory/types/asset.js +1 -0
- package/lib/svg-css/factory/types/component.d.ts +39 -0
- package/lib/svg-css/factory/types/component.js +1 -0
- package/lib/svg-css/factory/types/css.d.ts +5 -0
- package/lib/svg-css/factory/types/css.js +1 -0
- package/lib/svg-css/factory/types/data.d.ts +13 -0
- package/lib/svg-css/factory/types/data.js +1 -0
- package/lib/svg-css/factory/types/file.d.ts +14 -0
- package/lib/svg-css/factory/types/file.js +1 -0
- package/lib/svg-css/factory/types/options.d.ts +26 -0
- package/lib/svg-css/factory/types/options.js +1 -0
- package/lib/svg-css/factory/types/props.d.ts +14 -0
- package/lib/svg-css/factory/types/props.js +1 -0
- package/lib/svg-css/factory/types/source.d.ts +10 -0
- package/lib/svg-css/factory/types/source.js +1 -0
- package/lib/svg-css/types.d.ts +2 -1
- package/lib/xml/parse.js +2 -4
- package/package.json +11 -9
- package/lib/svg-css/factory/helpers/add-css.d.ts +0 -8
- package/lib/svg-css/factory/helpers/add-css.js +0 -32
- package/lib/svg-css/factory/helpers/component-name.d.ts +0 -9
- package/lib/svg-css/factory/helpers/component-name.js +0 -17
- package/lib/svg-css/factory/helpers/component-path.d.ts +0 -5
- package/lib/svg-css/factory/helpers/component-path.js +0 -9
- package/lib/svg-css/factory/helpers/css-filename.d.ts +0 -5
- package/lib/svg-css/factory/helpers/css-filename.js +0 -10
- package/lib/svg-css/factory/helpers/exports.d.ts +0 -6
- package/lib/svg-css/factory/helpers/exports.js +0 -10
- package/lib/svg-css/factory/helpers/merge.d.ts +0 -6
- package/lib/svg-css/factory/helpers/merge.js +0 -19
- package/lib/svg-css/factory/helpers/options.d.ts +0 -6
- package/lib/svg-css/factory/helpers/options.js +0 -12
- package/lib/svg-css/factory/helpers/prefix.d.ts +0 -6
- package/lib/svg-css/factory/helpers/prefix.js +0 -8
- package/lib/svg-css/factory/iconify/vue.d.ts +0 -6
- package/lib/svg-css/factory/iconify/vue.js +0 -72
- package/lib/svg-css/factory/types.d.ts +0 -48
- /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,27 @@
|
|
|
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
|
+
const filename = getGeneratedComponentTypesFilename(data, options);
|
|
10
|
+
assets.push({
|
|
11
|
+
...filename,
|
|
12
|
+
content: `import { DefineSetupFnComponent, PublicProps } from 'vue';
|
|
13
|
+
|
|
14
|
+
interface IconProps {
|
|
15
|
+
${propTypes}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare const Component: DefineSetupFnComponent<IconProps, {}, {}, IconProps & {}, PublicProps>;
|
|
19
|
+
|
|
20
|
+
export { type IconProps };
|
|
21
|
+
export default Component;
|
|
22
|
+
`
|
|
23
|
+
});
|
|
24
|
+
return filename.filename;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
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 functional Vue component code
|
|
6
|
+
*/
|
|
7
|
+
declare function createVueFunctionalComponent(data: FactoryIconData, options: ComponentFactoryOptions): FactoryGeneratedComponent;
|
|
8
|
+
export { createVueFunctionalComponent };
|
|
@@ -0,0 +1,99 @@
|
|
|
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 { getUsedFactoryProps } from "../props/types.js";
|
|
9
|
+
import { addVueComponentTypes } from "./vue/types.js";
|
|
10
|
+
import { addSizeFunctionAsset } from "./shared/size.js";
|
|
11
|
+
import { stringifyFactoryPropsAsJSON } from "../props/object.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create functional Vue component code
|
|
15
|
+
*/
|
|
16
|
+
function createVueFunctionalComponent(data, options) {
|
|
17
|
+
const assets = [];
|
|
18
|
+
const imports = createFactoryImports();
|
|
19
|
+
const hasFallback = !!data.fallback;
|
|
20
|
+
if (hasFallback) imports.named["@iconify/css-vue"] = new Set(["Icon"]);
|
|
21
|
+
const vueNamedImports = new Set(["defineComponent", "h"]);
|
|
22
|
+
imports.named["vue"] = vueNamedImports;
|
|
23
|
+
generateCSSFilesForComponent(data.icon, imports, assets, options);
|
|
24
|
+
const componentCode = [];
|
|
25
|
+
const sizeProps = getComponentSizeValues(options, data.viewBox);
|
|
26
|
+
const props = {};
|
|
27
|
+
if (!hasFallback) props.xmlns = "http://www.w3.org/2000/svg";
|
|
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 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
|
+
};
|
|
44
|
+
} else {
|
|
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
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (options.square) props.square = { type: "boolean" };
|
|
60
|
+
const getViewBox = (viewBox$1) => hasFallback ? JSON.stringify(viewBox$1) : `'${getIconViewBox(viewBox$1)}'`;
|
|
61
|
+
const viewBoxValue = getViewBox(viewBox);
|
|
62
|
+
if (isDynanicViewBox) {
|
|
63
|
+
componentCode.unshift(`const baseViewBox = ${viewBoxValue};`, `const squareViewBox = ${getViewBox(makeSquareViewBox(viewBox))};`, `const viewBox = computed(() => props.square ? squareViewBox : baseViewBox);`);
|
|
64
|
+
props.viewBox = {
|
|
65
|
+
value: "viewBox",
|
|
66
|
+
template: "viewBox: viewBox.value,"
|
|
67
|
+
};
|
|
68
|
+
} else {
|
|
69
|
+
componentCode.unshift(`const viewBox = ${viewBoxValue};`);
|
|
70
|
+
props.viewBox = {
|
|
71
|
+
value: "viewBox",
|
|
72
|
+
template: "viewBox,"
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
props[hasFallback ? "content" : "innerHTML"] = { value: stringifyFactoryIconContent(data.icon, options) };
|
|
76
|
+
if (data.fallback) props.fallback = data.fallback;
|
|
77
|
+
const types = addVueComponentTypes(data, options, assets, props);
|
|
78
|
+
componentCode.push(`return () => h(${hasFallback ? "Icon" : "'svg'"}, {
|
|
79
|
+
${stringifyFactoryPropsAsJSON(props, "\n ")}
|
|
80
|
+
});`);
|
|
81
|
+
const usedProps = getUsedFactoryProps(props);
|
|
82
|
+
const componentFunction = `const Component = defineComponent(
|
|
83
|
+
(${usedProps.length ? "props" : ""}) => {
|
|
84
|
+
${componentCode.join("\n ")}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
props: ${JSON.stringify(usedProps)}
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
`;
|
|
91
|
+
const content = `${stringifyFactoryImports(imports)}\n${componentFunction}\nexport default Component;\n`;
|
|
92
|
+
return {
|
|
93
|
+
assets,
|
|
94
|
+
content,
|
|
95
|
+
types
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { createVueFunctionalComponent };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FactoryIconData } from "../types/data.js";
|
|
2
|
+
import { FactoryGeneratedComponent } from "../types/component.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 { 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 { stringifyFactoryProps } from "../props/stringify.js";
|
|
9
|
+
import { getUsedFactoryProps, stringifyFactoryPropTypes } from "../props/types.js";
|
|
10
|
+
import { addVueComponentTypes } from "./vue/types.js";
|
|
11
|
+
import { addSizeFunctionAsset } from "./shared/size.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 };
|
|
@@ -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,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,11 @@
|
|
|
1
|
+
import { FactoryComponent } from "../types/component.js";
|
|
2
|
+
type Types = string | Record<string, string>;
|
|
3
|
+
interface Options {
|
|
4
|
+
ext?: string;
|
|
5
|
+
data?: Record<string, Types>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Add exports for main files to object
|
|
9
|
+
*/
|
|
10
|
+
declare function createExportsForMainFiles(data: FactoryComponent[], options?: Options): Record<string, Types>;
|
|
11
|
+
export { createExportsForMainFiles };
|
|
@@ -0,0 +1,14 @@
|
|
|
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, types } of data) result[`./${icon}${ext}`] = types ? {
|
|
8
|
+
types: `./${types}`,
|
|
9
|
+
default: `./${filename}`
|
|
10
|
+
} : `./${filename}`;
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
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 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GeneratedComponentFile } from "../types/file.js";
|
|
2
2
|
/**
|
|
3
3
|
* Save exported files to filesystem
|
|
4
4
|
*/
|
|
5
|
-
declare function saveExportedFilesToFS(files:
|
|
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,15 @@
|
|
|
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
|
+
const { prefixDirsForComponents } = options;
|
|
12
|
+
return (prefixDirsForComponents ? `${typeof prefixDirsForComponents === "string" ? prefixDirsForComponents : prefix}/` : "") + (options.doubleDirsForComponents ? `${name.slice(0, 1).toLowerCase()}/` : "") + name + componentExtension;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { getGeneratedComponentFilename };
|