@cyberalien/svg-utils 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/helpers/content/stringify.d.ts +1 -1
- package/lib/components/helpers/content/stringify.js +2 -2
- package/lib/components/helpers/css/generate.d.ts +1 -1
- package/lib/components/helpers/css/generate.js +19 -1
- package/lib/components/helpers/filenames/types.d.ts +1 -1
- package/lib/components/helpers/filenames/types.js +10 -1
- package/lib/components/helpers/vue/types.js +7 -7
- package/lib/components/prepare/options.js +2 -1
- package/lib/components/raw.js +3 -2
- package/lib/components/types/options.d.ts +2 -0
- package/package.json +1 -1
|
@@ -3,5 +3,5 @@ import { ComponentFactoryRenderingOptions } from "../../types/options.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Convert icon content to a string literal
|
|
5
5
|
*/
|
|
6
|
-
declare function stringifyFactoryIconContent(icon: ComponentFactorySource, options: Pick<ComponentFactoryRenderingOptions, 'cssMode'>): string;
|
|
6
|
+
declare function stringifyFactoryIconContent(icon: ComponentFactorySource, options: Pick<ComponentFactoryRenderingOptions, 'cssMode' | 'mergeCSS'>): string;
|
|
7
7
|
export { stringifyFactoryIconContent };
|
|
@@ -4,12 +4,12 @@ import { generateCSSDefaultImportName } from "../css/name.js";
|
|
|
4
4
|
* Convert icon content to a string literal
|
|
5
5
|
*/
|
|
6
6
|
function stringifyFactoryIconContent(icon, options) {
|
|
7
|
-
const { cssMode } = options;
|
|
7
|
+
const { cssMode, mergeCSS } = options;
|
|
8
8
|
let content = "`" + icon.content.replace(/`/g, "\\`") + "`";
|
|
9
9
|
switch (cssMode) {
|
|
10
10
|
case "import": return content;
|
|
11
11
|
case "module":
|
|
12
|
-
for (const className in icon.classes) content = content.replace(new RegExp("([\" ])(" + className + ")([\" ])", "g"), `$1\${${generateCSSDefaultImportName(className)}['${className}']}$3`);
|
|
12
|
+
for (const className in icon.classes) content = content.replace(new RegExp("([\" ])(" + className + ")([\" ])", "g"), `$1\${${mergeCSS ? "css" : generateCSSDefaultImportName(className)}['${className}']}$3`);
|
|
13
13
|
return content;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -7,5 +7,5 @@ import { FactoryComponentImports } from "../imports/types.js";
|
|
|
7
7
|
*
|
|
8
8
|
* Adds imports to imports object, adds assets
|
|
9
9
|
*/
|
|
10
|
-
declare function generateCSSFilesForComponent(content: ComponentFactorySource, imports: FactoryComponentImports, assets: GeneratedAssetFile[], options: Pick<ComponentFactoryOptions, 'cssMode' | 'cssPath' | 'doubleDirsForCSS'>): void;
|
|
10
|
+
declare function generateCSSFilesForComponent(content: ComponentFactorySource, imports: FactoryComponentImports, assets: GeneratedAssetFile[], options: Pick<ComponentFactoryOptions, 'cssMode' | 'cssPath' | 'doubleDirsForCSS' | 'mergeCSS'>): void;
|
|
11
11
|
export { generateCSSFilesForComponent };
|
|
@@ -11,7 +11,9 @@ function generateCSSFilesForComponent(content, imports, assets, options) {
|
|
|
11
11
|
const { classes, keyframes } = content;
|
|
12
12
|
if (!classes) return;
|
|
13
13
|
const isModule = options.cssMode === "module";
|
|
14
|
-
const
|
|
14
|
+
const mergeCSS = options.mergeCSS ?? false;
|
|
15
|
+
const embedAnimations = isModule && !mergeCSS;
|
|
16
|
+
const mergedContent = [];
|
|
15
17
|
for (const className in classes) {
|
|
16
18
|
const baseContent = stringifyCSSSelector(`.${className}`, classes[className]);
|
|
17
19
|
let content$1 = baseContent;
|
|
@@ -21,6 +23,10 @@ function generateCSSFilesForComponent(content, imports, assets, options) {
|
|
|
21
23
|
content$1 += "\n" + (typeof value === "string" ? value : stringifyCSSKeyframes(animationName, value));
|
|
22
24
|
}
|
|
23
25
|
}
|
|
26
|
+
if (mergeCSS) {
|
|
27
|
+
mergedContent.push(content$1);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
24
30
|
const filename = getGeneratedCSSFilename(className, options);
|
|
25
31
|
assets.push({
|
|
26
32
|
...filename,
|
|
@@ -32,6 +38,10 @@ function generateCSSFilesForComponent(content, imports, assets, options) {
|
|
|
32
38
|
if (!embedAnimations && keyframes) for (const animationName in keyframes) {
|
|
33
39
|
const value = keyframes[animationName];
|
|
34
40
|
const content$1 = typeof value === "string" ? value : stringifyCSSKeyframes(animationName, value);
|
|
41
|
+
if (mergeCSS) {
|
|
42
|
+
mergedContent.push(content$1);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
35
45
|
const filename = getGeneratedCSSFilename(animationName, options);
|
|
36
46
|
assets.push({
|
|
37
47
|
...filename,
|
|
@@ -40,6 +50,14 @@ function generateCSSFilesForComponent(content, imports, assets, options) {
|
|
|
40
50
|
if (isModule) imports.modules[filename.import] = generateCSSDefaultImportName(animationName);
|
|
41
51
|
else imports.css.add(filename.import);
|
|
42
52
|
}
|
|
53
|
+
if (mergeCSS && mergedContent.length) {
|
|
54
|
+
assets.push({
|
|
55
|
+
...mergeCSS,
|
|
56
|
+
content: mergedContent.join("\n\n")
|
|
57
|
+
});
|
|
58
|
+
if (isModule) imports.modules[mergeCSS.import] = "css";
|
|
59
|
+
else imports.css.add(mergeCSS.import);
|
|
60
|
+
}
|
|
43
61
|
}
|
|
44
62
|
|
|
45
63
|
export { generateCSSFilesForComponent };
|
|
@@ -3,5 +3,5 @@ import { ComponentFactoryFileSystemOptions, GeneratedAssetPath } from "../../typ
|
|
|
3
3
|
/**
|
|
4
4
|
* Generate component types filename based on options
|
|
5
5
|
*/
|
|
6
|
-
declare function getGeneratedComponentTypesFilename(icon: Pick<FactoryIconData, 'name' | 'prefix'>, options: Pick<ComponentFactoryFileSystemOptions, 'doubleDirsForComponents' | 'prefixDirsForComponents'>): GeneratedAssetPath;
|
|
6
|
+
declare function getGeneratedComponentTypesFilename(icon: Pick<FactoryIconData, 'name' | 'prefix'>, content: string, options: Pick<ComponentFactoryFileSystemOptions, 'rootPath' | 'doubleDirsForComponents' | 'prefixDirsForComponents' | 'sharedTypes'>): GeneratedAssetPath;
|
|
7
7
|
export { getGeneratedComponentTypesFilename };
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import { getUniqueHash } from "../../../helpers/hash/unique.js";
|
|
1
2
|
import { getGeneratedComponentFilename } from "../../export/filename.js";
|
|
3
|
+
import { getGeneratedAssetFilename } from "./asset.js";
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Generate component types filename based on options
|
|
5
7
|
*/
|
|
6
|
-
function getGeneratedComponentTypesFilename(icon, options) {
|
|
8
|
+
function getGeneratedComponentTypesFilename(icon, content, options) {
|
|
9
|
+
if (options.sharedTypes) {
|
|
10
|
+
const hash = getUniqueHash(content, {
|
|
11
|
+
css: true,
|
|
12
|
+
length: 8
|
|
13
|
+
});
|
|
14
|
+
return getGeneratedAssetFilename(`types/${hash}.d.ts`, options.rootPath);
|
|
15
|
+
}
|
|
7
16
|
const filename = getGeneratedComponentFilename(icon, ".d.ts", options);
|
|
8
17
|
return {
|
|
9
18
|
filename,
|
|
@@ -5,21 +5,21 @@ import { stringifyFactoryPropTypes } from "../props/ts.js";
|
|
|
5
5
|
* Add Vue component types
|
|
6
6
|
*/
|
|
7
7
|
function addVueComponentTypes(data, options, assets, props) {
|
|
8
|
-
const
|
|
9
|
-
const filename = getGeneratedComponentTypesFilename(data, options);
|
|
10
|
-
assets.push({
|
|
11
|
-
...filename,
|
|
12
|
-
content: `import { DefineSetupFnComponent, PublicProps } from 'vue';
|
|
8
|
+
const content = `import { DefineSetupFnComponent, PublicProps } from 'vue';
|
|
13
9
|
|
|
14
10
|
interface IconProps {
|
|
15
|
-
${
|
|
11
|
+
${stringifyFactoryPropTypes(props)}
|
|
16
12
|
}
|
|
17
13
|
|
|
18
14
|
declare const Component: DefineSetupFnComponent<IconProps, {}, {}, IconProps & {}, PublicProps>;
|
|
19
15
|
|
|
20
16
|
export { type IconProps };
|
|
21
17
|
export default Component;
|
|
22
|
-
|
|
18
|
+
`;
|
|
19
|
+
const filename = getGeneratedComponentTypesFilename(data, content, options);
|
|
20
|
+
assets.push({
|
|
21
|
+
...filename,
|
|
22
|
+
content
|
|
23
23
|
});
|
|
24
24
|
return filename.filename;
|
|
25
25
|
}
|
package/lib/components/raw.js
CHANGED
|
@@ -28,9 +28,10 @@ function createRawComponent(data, options) {
|
|
|
28
28
|
codeLines.push("export default icon;\n");
|
|
29
29
|
const importsCode = stringifyFactoryImports(imports);
|
|
30
30
|
if (importsCode) codeLines.unshift(importsCode);
|
|
31
|
+
const typesContent = `const icon: string;\nexport default icon;\n`;
|
|
31
32
|
assets.push({
|
|
32
|
-
...getGeneratedComponentTypesFilename(data, options),
|
|
33
|
-
content:
|
|
33
|
+
...getGeneratedComponentTypesFilename(data, typesContent, options),
|
|
34
|
+
content: typesContent
|
|
34
35
|
});
|
|
35
36
|
return {
|
|
36
37
|
assets,
|
|
@@ -15,6 +15,7 @@ interface ComponentFactoryFileSystemOptions {
|
|
|
15
15
|
doubleDirsForComponents: boolean;
|
|
16
16
|
rootPath: GeneratedAssetPath;
|
|
17
17
|
cssPath: GeneratedAssetPath;
|
|
18
|
+
sharedTypes?: boolean;
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* Rendering options for component factory
|
|
@@ -22,6 +23,7 @@ interface ComponentFactoryFileSystemOptions {
|
|
|
22
23
|
interface ComponentFactoryRenderingOptions {
|
|
23
24
|
square?: boolean;
|
|
24
25
|
cssMode: CSSExportMode;
|
|
26
|
+
mergeCSS?: GeneratedAssetPath;
|
|
25
27
|
width?: string;
|
|
26
28
|
height?: string;
|
|
27
29
|
}
|
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.
|
|
6
|
+
"version": "0.1.5",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bugs": "https://github.com/cyberalien/svg-utils/issues",
|
|
9
9
|
"homepage": "https://cyberalien.dev/",
|