@getkist/action-svg 1.0.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.
- package/LICENSE +21 -0
- package/README.md +329 -0
- package/dist/actions/SvgPackagerAction/SvgPackagerAction.d.ts +122 -0
- package/dist/actions/SvgPackagerAction/SvgPackagerAction.d.ts.map +1 -0
- package/dist/actions/SvgPackagerAction/SvgPackagerAction.js +167 -0
- package/dist/actions/SvgPackagerAction/SvgPackagerAction.js.map +1 -0
- package/dist/actions/SvgPackagerAction/index.d.ts +3 -0
- package/dist/actions/SvgPackagerAction/index.d.ts.map +1 -0
- package/dist/actions/SvgPackagerAction/index.js +5 -0
- package/dist/actions/SvgPackagerAction/index.js.map +1 -0
- package/dist/actions/SvgReaderAction/SvgReaderAction.d.ts +61 -0
- package/dist/actions/SvgReaderAction/SvgReaderAction.d.ts.map +1 -0
- package/dist/actions/SvgReaderAction/SvgReaderAction.js +89 -0
- package/dist/actions/SvgReaderAction/SvgReaderAction.js.map +1 -0
- package/dist/actions/SvgReaderAction/index.d.ts +3 -0
- package/dist/actions/SvgReaderAction/index.d.ts.map +1 -0
- package/dist/actions/SvgReaderAction/index.js +5 -0
- package/dist/actions/SvgReaderAction/index.js.map +1 -0
- package/dist/actions/SvgSpriteAction/SvgSpriteAction.d.ts +71 -0
- package/dist/actions/SvgSpriteAction/SvgSpriteAction.d.ts.map +1 -0
- package/dist/actions/SvgSpriteAction/SvgSpriteAction.js +199 -0
- package/dist/actions/SvgSpriteAction/SvgSpriteAction.js.map +1 -0
- package/dist/actions/SvgSpriteAction/index.d.ts +3 -0
- package/dist/actions/SvgSpriteAction/index.d.ts.map +1 -0
- package/dist/actions/SvgSpriteAction/index.js +5 -0
- package/dist/actions/SvgSpriteAction/index.js.map +1 -0
- package/dist/actions/SvgToPngAction/SvgToPngAction.d.ts +72 -0
- package/dist/actions/SvgToPngAction/SvgToPngAction.d.ts.map +1 -0
- package/dist/actions/SvgToPngAction/SvgToPngAction.js +136 -0
- package/dist/actions/SvgToPngAction/SvgToPngAction.js.map +1 -0
- package/dist/actions/SvgToPngAction/index.d.ts +3 -0
- package/dist/actions/SvgToPngAction/index.d.ts.map +1 -0
- package/dist/actions/SvgToPngAction/index.js +5 -0
- package/dist/actions/SvgToPngAction/index.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/dist/types/Action.d.ts +70 -0
- package/dist/types/Action.d.ts.map +1 -0
- package/dist/types/Action.js +56 -0
- package/dist/types/Action.js.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Action, ActionOptionsType } from "../../types/Action.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for SvgReaderAction
|
|
4
|
+
*/
|
|
5
|
+
export interface SvgReaderActionOptions extends ActionOptionsType {
|
|
6
|
+
/**
|
|
7
|
+
* Path to the SVG file to read
|
|
8
|
+
*/
|
|
9
|
+
filePath: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* SvgReaderAction reads SVG file contents and makes them available
|
|
13
|
+
* for further processing in the pipeline.
|
|
14
|
+
*
|
|
15
|
+
* Features:
|
|
16
|
+
* - Asynchronous file reading
|
|
17
|
+
* - Content caching for pipeline use
|
|
18
|
+
* - Path validation
|
|
19
|
+
* - Detailed error reporting
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```yaml
|
|
23
|
+
* steps:
|
|
24
|
+
* - name: read-svg
|
|
25
|
+
* action: SvgReaderAction
|
|
26
|
+
* options:
|
|
27
|
+
* filePath: ./assets/logo.svg
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare class SvgReaderAction extends Action {
|
|
31
|
+
private svgContent;
|
|
32
|
+
/**
|
|
33
|
+
* Validates the provided options before execution.
|
|
34
|
+
*
|
|
35
|
+
* @param options - The options to validate
|
|
36
|
+
* @returns true if options are valid
|
|
37
|
+
* @throws Error if required options are missing or invalid
|
|
38
|
+
*/
|
|
39
|
+
validateOptions(options: ActionOptionsType): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Executes the SVG reading action.
|
|
42
|
+
*
|
|
43
|
+
* @param options - The options specifying the SVG file path
|
|
44
|
+
* @returns A Promise that resolves when the SVG file is successfully read
|
|
45
|
+
*/
|
|
46
|
+
execute(options: ActionOptionsType): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Reads the content of an SVG file asynchronously.
|
|
49
|
+
*
|
|
50
|
+
* @param filePath - The path to the SVG file
|
|
51
|
+
* @returns A promise that resolves to the SVG file content
|
|
52
|
+
*/
|
|
53
|
+
private readSvg;
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves the last read SVG content.
|
|
56
|
+
*
|
|
57
|
+
* @returns The last read SVG content
|
|
58
|
+
*/
|
|
59
|
+
getSvgContent(): string;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=SvgReaderAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SvgReaderAction.d.ts","sourceRoot":"","sources":["../../../src/actions/SvgReaderAction/SvgReaderAction.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAMlE;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,iBAAiB;IAC/D;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,eAAgB,SAAQ,MAAM;IACzC,OAAO,CAAC,UAAU,CAAc;IAEhC;;;;;;OAMG;IACH,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO;IAcpD;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBxD;;;;;OAKG;YACW,OAAO;IAIrB;;;;OAIG;IACH,aAAa,IAAI,MAAM;CAGxB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Import
|
|
3
|
+
// ============================================================================
|
|
4
|
+
import { promises as fs } from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { Action } from "../../types/Action.js";
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Class
|
|
9
|
+
// ============================================================================
|
|
10
|
+
/**
|
|
11
|
+
* SvgReaderAction reads SVG file contents and makes them available
|
|
12
|
+
* for further processing in the pipeline.
|
|
13
|
+
*
|
|
14
|
+
* Features:
|
|
15
|
+
* - Asynchronous file reading
|
|
16
|
+
* - Content caching for pipeline use
|
|
17
|
+
* - Path validation
|
|
18
|
+
* - Detailed error reporting
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```yaml
|
|
22
|
+
* steps:
|
|
23
|
+
* - name: read-svg
|
|
24
|
+
* action: SvgReaderAction
|
|
25
|
+
* options:
|
|
26
|
+
* filePath: ./assets/logo.svg
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export class SvgReaderAction extends Action {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.svgContent = "";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validates the provided options before execution.
|
|
36
|
+
*
|
|
37
|
+
* @param options - The options to validate
|
|
38
|
+
* @returns true if options are valid
|
|
39
|
+
* @throws Error if required options are missing or invalid
|
|
40
|
+
*/
|
|
41
|
+
validateOptions(options) {
|
|
42
|
+
const opts = options;
|
|
43
|
+
if (!opts.filePath) {
|
|
44
|
+
throw new Error("SvgReaderAction requires 'filePath' option");
|
|
45
|
+
}
|
|
46
|
+
if (typeof opts.filePath !== "string") {
|
|
47
|
+
throw new Error("SvgReaderAction 'filePath' must be a string");
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Executes the SVG reading action.
|
|
53
|
+
*
|
|
54
|
+
* @param options - The options specifying the SVG file path
|
|
55
|
+
* @returns A Promise that resolves when the SVG file is successfully read
|
|
56
|
+
*/
|
|
57
|
+
async execute(options) {
|
|
58
|
+
this.validateOptions(options);
|
|
59
|
+
const opts = options;
|
|
60
|
+
this.logInfo(`Reading SVG file: ${opts.filePath}`);
|
|
61
|
+
try {
|
|
62
|
+
this.svgContent = await this.readSvg(opts.filePath);
|
|
63
|
+
this.logInfo(`Successfully read SVG file: ${opts.filePath}`);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
+
this.logError(`Error reading SVG file: ${opts.filePath}`, error);
|
|
68
|
+
throw new Error(`SVG file reading failed: ${message}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Reads the content of an SVG file asynchronously.
|
|
73
|
+
*
|
|
74
|
+
* @param filePath - The path to the SVG file
|
|
75
|
+
* @returns A promise that resolves to the SVG file content
|
|
76
|
+
*/
|
|
77
|
+
async readSvg(filePath) {
|
|
78
|
+
return fs.readFile(path.resolve(filePath), "utf-8");
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves the last read SVG content.
|
|
82
|
+
*
|
|
83
|
+
* @returns The last read SVG content
|
|
84
|
+
*/
|
|
85
|
+
getSvgContent() {
|
|
86
|
+
return this.svgContent;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=SvgReaderAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SvgReaderAction.js","sourceRoot":"","sources":["../../../src/actions/SvgReaderAction/SvgReaderAction.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OA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,IAAI,KAAK,CAAC,4BAA4B,OAAO,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,OAAO,CAAC,QAAgB;QACpC,OAAO,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAED;;;;OAIG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/actions/SvgReaderAction/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/actions/SvgReaderAction/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import svgSprite from "svg-sprite";
|
|
2
|
+
import { Action, ActionOptionsType } from "../../types/Action.js";
|
|
3
|
+
/**
|
|
4
|
+
* Options for SvgSpriteAction
|
|
5
|
+
*/
|
|
6
|
+
export interface SvgSpriteActionOptions extends ActionOptionsType {
|
|
7
|
+
/**
|
|
8
|
+
* Source directory containing SVG files
|
|
9
|
+
*/
|
|
10
|
+
sourceDir: string;
|
|
11
|
+
/**
|
|
12
|
+
* Output directory for generated sprite
|
|
13
|
+
*/
|
|
14
|
+
outputDir: string;
|
|
15
|
+
/**
|
|
16
|
+
* Optional custom configuration for svg-sprite
|
|
17
|
+
*/
|
|
18
|
+
config?: svgSprite.Config;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* SvgSpriteAction compiles multiple SVG files into a single sprite sheet,
|
|
22
|
+
* making it more efficient to manage and use SVG assets in web applications.
|
|
23
|
+
*
|
|
24
|
+
* Features:
|
|
25
|
+
* - Combines multiple SVG files into sprite sheets
|
|
26
|
+
* - Supports multiple sprite modes (symbol, stack, css, view, defs)
|
|
27
|
+
* - Automatic SVG optimization with SVGO
|
|
28
|
+
* - Customizable sprite configuration
|
|
29
|
+
* - CSS stylesheet generation
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```yaml
|
|
33
|
+
* steps:
|
|
34
|
+
* - name: generate-svg-sprite
|
|
35
|
+
* action: SvgSpriteAction
|
|
36
|
+
* options:
|
|
37
|
+
* sourceDir: ./assets/icons
|
|
38
|
+
* outputDir: ./dist/sprites
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class SvgSpriteAction extends Action {
|
|
42
|
+
private config;
|
|
43
|
+
/**
|
|
44
|
+
* Constructs an instance with merged default and custom configurations.
|
|
45
|
+
*
|
|
46
|
+
* @param customConfig - Optional custom configuration for svg-sprite
|
|
47
|
+
*/
|
|
48
|
+
constructor(customConfig?: svgSprite.Config);
|
|
49
|
+
/**
|
|
50
|
+
* Validates the provided options before execution.
|
|
51
|
+
*
|
|
52
|
+
* @param options - The options to validate
|
|
53
|
+
* @returns true if options are valid
|
|
54
|
+
* @throws Error if required options are missing or invalid
|
|
55
|
+
*/
|
|
56
|
+
validateOptions(options: ActionOptionsType): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Executes the SVG sprite generation process.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Configuration options for sprite generation
|
|
61
|
+
*/
|
|
62
|
+
execute(options: ActionOptionsType): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Generates an SVG sprite from all SVG files in the specified directory.
|
|
65
|
+
*
|
|
66
|
+
* @param sourceDir - Directory containing source SVG files
|
|
67
|
+
* @param outputDir - Directory where the generated sprite will be saved
|
|
68
|
+
*/
|
|
69
|
+
private generateSprite;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=SvgSpriteAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SvgSpriteAction.d.ts","sourceRoot":"","sources":["../../../src/actions/SvgSpriteAction/SvgSpriteAction.ts"],"names":[],"mappings":"AAMA,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAMlE;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,iBAAiB;IAC/D;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC;CAC3B;AAqDD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,eAAgB,SAAQ,MAAM;IACzC,OAAO,CAAC,MAAM,CAAmB;IAEjC;;;;OAIG;gBACS,YAAY,GAAE,SAAS,CAAC,MAAW;IAK/C;;;;;;OAMG;IACH,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO;IA4BpD;;;;OAIG;IACG,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBxD;;;;;OAKG;YACW,cAAc;CAuE7B"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Import
|
|
3
|
+
// ============================================================================
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import svgSprite from "svg-sprite";
|
|
7
|
+
import { Action } from "../../types/Action.js";
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Default Configuration
|
|
10
|
+
// ============================================================================
|
|
11
|
+
const defaultSvgSpriteConfig = {
|
|
12
|
+
dest: "./dist/sprite",
|
|
13
|
+
shape: {
|
|
14
|
+
id: {
|
|
15
|
+
separator: "--",
|
|
16
|
+
generator: "icon-%s",
|
|
17
|
+
pseudo: "~",
|
|
18
|
+
},
|
|
19
|
+
dimension: {
|
|
20
|
+
maxWidth: 2000,
|
|
21
|
+
maxHeight: 2000,
|
|
22
|
+
precision: 2,
|
|
23
|
+
attributes: false,
|
|
24
|
+
},
|
|
25
|
+
spacing: {
|
|
26
|
+
padding: 0,
|
|
27
|
+
box: "content",
|
|
28
|
+
},
|
|
29
|
+
transform: ["svgo"],
|
|
30
|
+
},
|
|
31
|
+
svg: {
|
|
32
|
+
xmlDeclaration: false,
|
|
33
|
+
doctypeDeclaration: true,
|
|
34
|
+
namespaceIDs: true,
|
|
35
|
+
namespaceClassnames: false,
|
|
36
|
+
dimensionAttributes: true,
|
|
37
|
+
},
|
|
38
|
+
variables: {},
|
|
39
|
+
mode: {
|
|
40
|
+
css: {
|
|
41
|
+
render: {
|
|
42
|
+
css: true,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
view: true,
|
|
46
|
+
defs: true,
|
|
47
|
+
symbol: {
|
|
48
|
+
sprite: "icon.sprite.svg",
|
|
49
|
+
},
|
|
50
|
+
stack: true,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
// ============================================================================
|
|
54
|
+
// Class
|
|
55
|
+
// ============================================================================
|
|
56
|
+
/**
|
|
57
|
+
* SvgSpriteAction compiles multiple SVG files into a single sprite sheet,
|
|
58
|
+
* making it more efficient to manage and use SVG assets in web applications.
|
|
59
|
+
*
|
|
60
|
+
* Features:
|
|
61
|
+
* - Combines multiple SVG files into sprite sheets
|
|
62
|
+
* - Supports multiple sprite modes (symbol, stack, css, view, defs)
|
|
63
|
+
* - Automatic SVG optimization with SVGO
|
|
64
|
+
* - Customizable sprite configuration
|
|
65
|
+
* - CSS stylesheet generation
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```yaml
|
|
69
|
+
* steps:
|
|
70
|
+
* - name: generate-svg-sprite
|
|
71
|
+
* action: SvgSpriteAction
|
|
72
|
+
* options:
|
|
73
|
+
* sourceDir: ./assets/icons
|
|
74
|
+
* outputDir: ./dist/sprites
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export class SvgSpriteAction extends Action {
|
|
78
|
+
/**
|
|
79
|
+
* Constructs an instance with merged default and custom configurations.
|
|
80
|
+
*
|
|
81
|
+
* @param customConfig - Optional custom configuration for svg-sprite
|
|
82
|
+
*/
|
|
83
|
+
constructor(customConfig = {}) {
|
|
84
|
+
super();
|
|
85
|
+
this.config = { ...defaultSvgSpriteConfig, ...customConfig };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Validates the provided options before execution.
|
|
89
|
+
*
|
|
90
|
+
* @param options - The options to validate
|
|
91
|
+
* @returns true if options are valid
|
|
92
|
+
* @throws Error if required options are missing or invalid
|
|
93
|
+
*/
|
|
94
|
+
validateOptions(options) {
|
|
95
|
+
const opts = options;
|
|
96
|
+
if (!opts.sourceDir) {
|
|
97
|
+
throw new Error("SvgSpriteAction requires 'sourceDir' option");
|
|
98
|
+
}
|
|
99
|
+
if (!opts.outputDir) {
|
|
100
|
+
throw new Error("SvgSpriteAction requires 'outputDir' option");
|
|
101
|
+
}
|
|
102
|
+
if (typeof opts.sourceDir !== "string") {
|
|
103
|
+
throw new Error("SvgSpriteAction 'sourceDir' must be a string");
|
|
104
|
+
}
|
|
105
|
+
if (typeof opts.outputDir !== "string") {
|
|
106
|
+
throw new Error("SvgSpriteAction 'outputDir' must be a string");
|
|
107
|
+
}
|
|
108
|
+
if (!fs.existsSync(opts.sourceDir)) {
|
|
109
|
+
throw new Error(`SvgSpriteAction source directory does not exist: ${opts.sourceDir}`);
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Executes the SVG sprite generation process.
|
|
115
|
+
*
|
|
116
|
+
* @param options - Configuration options for sprite generation
|
|
117
|
+
*/
|
|
118
|
+
async execute(options) {
|
|
119
|
+
const opts = options;
|
|
120
|
+
// Merge custom config if provided
|
|
121
|
+
if (opts.config) {
|
|
122
|
+
this.config = { ...this.config, ...opts.config };
|
|
123
|
+
}
|
|
124
|
+
this.logInfo(`Generating SVG sprite from: ${opts.sourceDir}`);
|
|
125
|
+
try {
|
|
126
|
+
await this.generateSprite(opts.sourceDir, opts.outputDir);
|
|
127
|
+
this.logInfo(`SVG sprite successfully generated in: ${opts.outputDir}`);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
131
|
+
this.logError(`Error generating SVG sprite: ${message}`, error);
|
|
132
|
+
throw new Error(`SVG sprite generation failed: ${message}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Generates an SVG sprite from all SVG files in the specified directory.
|
|
137
|
+
*
|
|
138
|
+
* @param sourceDir - Directory containing source SVG files
|
|
139
|
+
* @param outputDir - Directory where the generated sprite will be saved
|
|
140
|
+
*/
|
|
141
|
+
async generateSprite(sourceDir, outputDir) {
|
|
142
|
+
return new Promise((resolve, reject) => {
|
|
143
|
+
try {
|
|
144
|
+
const files = fs.readdirSync(sourceDir);
|
|
145
|
+
const sprite = new svgSprite(this.config);
|
|
146
|
+
let svgCount = 0;
|
|
147
|
+
// Add all SVG files to the sprite
|
|
148
|
+
for (const file of files) {
|
|
149
|
+
if (path.extname(file) === ".svg") {
|
|
150
|
+
const svgPath = path.resolve(sourceDir, file);
|
|
151
|
+
const content = fs.readFileSync(svgPath, "utf8");
|
|
152
|
+
sprite.add(svgPath, null, content);
|
|
153
|
+
svgCount++;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (svgCount === 0) {
|
|
157
|
+
this.logWarning(`No SVG files found in source directory: ${sourceDir}`);
|
|
158
|
+
resolve();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this.logDebug(`Found ${svgCount} SVG files to process`);
|
|
162
|
+
// Compile the sprite
|
|
163
|
+
sprite.compile((error, result) => {
|
|
164
|
+
if (error) {
|
|
165
|
+
reject(error);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
// Write all generated files
|
|
170
|
+
for (const mode in result) {
|
|
171
|
+
for (const resource in result[mode]) {
|
|
172
|
+
// svg-sprite may return absolute paths based on source files
|
|
173
|
+
// Extract just the mode/filename portion for consistent output
|
|
174
|
+
const resourcePath = result[mode][resource].path;
|
|
175
|
+
const relativePath = path.isAbsolute(resourcePath)
|
|
176
|
+
? path.join(mode, "svg", path.basename(resourcePath))
|
|
177
|
+
: resourcePath;
|
|
178
|
+
const outputPath = path.join(outputDir, relativePath);
|
|
179
|
+
fs.mkdirSync(path.dirname(outputPath), {
|
|
180
|
+
recursive: true,
|
|
181
|
+
});
|
|
182
|
+
fs.writeFileSync(outputPath, result[mode][resource].contents);
|
|
183
|
+
this.logDebug(`Generated: ${outputPath}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
resolve();
|
|
187
|
+
}
|
|
188
|
+
catch (writeError) {
|
|
189
|
+
reject(writeError);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
reject(error);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=SvgSpriteAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SvgSpriteAction.js","sourceRoot":"","sources":["../../../src/actions/SvgSpriteAction/SvgSpriteAction.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAqB,MAAM,uBAAuB,CAAC;AA0BlE,+EAA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,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/actions/SvgSpriteAction/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/actions/SvgSpriteAction/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Action, ActionOptionsType } from "../../types/Action.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for SvgToPngAction
|
|
4
|
+
*/
|
|
5
|
+
export interface SvgToPngActionOptions extends ActionOptionsType {
|
|
6
|
+
/**
|
|
7
|
+
* SVG content to convert
|
|
8
|
+
*/
|
|
9
|
+
svgContent: string;
|
|
10
|
+
/**
|
|
11
|
+
* Output path for the PNG file
|
|
12
|
+
*/
|
|
13
|
+
outputPath: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional width for the output PNG
|
|
16
|
+
*/
|
|
17
|
+
width?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Optional height for the output PNG
|
|
20
|
+
*/
|
|
21
|
+
height?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* SvgToPngAction converts SVG content to PNG format.
|
|
25
|
+
*
|
|
26
|
+
* Features:
|
|
27
|
+
* - High-quality SVG to PNG conversion
|
|
28
|
+
* - Optional resizing
|
|
29
|
+
* - Automatic dimension detection
|
|
30
|
+
* - Directory creation
|
|
31
|
+
* - Uses canvg for rendering
|
|
32
|
+
*
|
|
33
|
+
* Uses `canvg` for conversion and `jsdom` for SVG element manipulation.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```yaml
|
|
37
|
+
* steps:
|
|
38
|
+
* - name: convert-to-png
|
|
39
|
+
* action: SvgToPngAction
|
|
40
|
+
* options:
|
|
41
|
+
* svgContent: "<svg>...</svg>"
|
|
42
|
+
* outputPath: ./dist/logo.png
|
|
43
|
+
* width: 512
|
|
44
|
+
* height: 512
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare class SvgToPngAction extends Action {
|
|
48
|
+
/**
|
|
49
|
+
* Validates the provided options before execution.
|
|
50
|
+
*
|
|
51
|
+
* @param options - The options to validate
|
|
52
|
+
* @returns true if options are valid
|
|
53
|
+
* @throws Error if required options are missing or invalid
|
|
54
|
+
*/
|
|
55
|
+
validateOptions(options: ActionOptionsType): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Executes the SVG-to-PNG conversion process.
|
|
58
|
+
*
|
|
59
|
+
* @param options - Options including SVG content, output path, width, and height
|
|
60
|
+
*/
|
|
61
|
+
execute(options: ActionOptionsType): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Converts SVG content to a PNG file, optionally resizing the output.
|
|
64
|
+
*
|
|
65
|
+
* @param svgContent - The SVG content to be converted
|
|
66
|
+
* @param outputPath - The filesystem path where the PNG should be saved
|
|
67
|
+
* @param width - Optional width for resizing
|
|
68
|
+
* @param height - Optional height for resizing
|
|
69
|
+
*/
|
|
70
|
+
private convert;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=SvgToPngAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SvgToPngAction.d.ts","sourceRoot":"","sources":["../../../src/actions/SvgToPngAction/SvgToPngAction.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAMlE;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAcD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,cAAe,SAAQ,MAAM;IACxC;;;;;;OAMG;IACH,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO;IA8BpD;;;;OAIG;IACG,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBxD;;;;;;;OAOG;YACW,OAAO;CAkDtB"}
|