vite-awesome-svg-loader 1.4.1 → 2.0.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/README.md +48 -8
- package/declarations.d.ts +77 -0
- package/index.d.mts +260 -0
- package/index.d.ts +108 -155
- package/index.js +340 -238
- package/index.mjs +338 -238
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,8 +9,8 @@ A Vite plugin that:
|
|
|
9
9
|
1. Source code base64.
|
|
10
10
|
1. Source code base64 [data URI](https://en.wikipedia.org/wiki/Data_URI_scheme).
|
|
11
11
|
1. Can preserve line width, i.e. make icons and line art have same line width when scaling.
|
|
12
|
-
1. Can replace colors with `currentColor
|
|
13
|
-
1. Will minimize your SVGs using [SVGO](https://github.com/svg/svgo).
|
|
12
|
+
1. Can replace colors with `currentColor` or a custom color via configuration (see `replaceColorsList` option).
|
|
13
|
+
1. Will automatically minimize your SVGs using [SVGO](https://github.com/svg/svgo).
|
|
14
14
|
1. Allows you to create SVG sprites using provided integrations.
|
|
15
15
|
|
|
16
16
|
`vite-awesome-svg-loader` is framework-agnostic. All integrations are done in form of subpath imports (for example, `vite-awesome-svg-loader/vue-integration`). This means that you'll get only what you need in your app bundle. This also means that you can develop your own integration using `vite-awesome-svg-loader/integration-utils` import.
|
|
@@ -103,10 +103,41 @@ viteAwesomeSvgLoader({
|
|
|
103
103
|
skipPreserveLineWidthList: [/line-width-not-preserved\.svg/],
|
|
104
104
|
|
|
105
105
|
// A list of files or directories to preserve color of
|
|
106
|
-
|
|
106
|
+
replaceColorsList: [
|
|
107
|
+
// File names
|
|
108
|
+
"some-file.svg",
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
// Regexes that are checked against whole path and file name with extension
|
|
111
|
+
/config-demo\/set-current-color\//,
|
|
112
|
+
/config-demo\/all\//,
|
|
113
|
+
|
|
114
|
+
// Map of color replacements. Key is an original color, value is its replacement. Both can be any values:
|
|
115
|
+
// HEX, name, rgb() or arbitrary custom values. Applied to all files.
|
|
116
|
+
{
|
|
117
|
+
"#003147": "red",
|
|
118
|
+
"rgb(0, 49, 71)": "#003147",
|
|
119
|
+
"myCustomColor": "var(--some-color-var)",
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
// Map of color replacements per files
|
|
123
|
+
{
|
|
124
|
+
files: ["vars.svg"], // File names or regexes, same format as above
|
|
125
|
+
|
|
126
|
+
// Replacements, same format as above
|
|
127
|
+
replacements: {
|
|
128
|
+
red: "var(--primary-color)",
|
|
129
|
+
green: "var(--secondary-color)",
|
|
130
|
+
blue: "var(--tertiary-color)",
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
// Default value for colors that are not in replacements map. Set an empty string to preserve original colors.
|
|
134
|
+
// Default value is "currentColor",
|
|
135
|
+
default: "currentColor"
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
|
|
139
|
+
// A list of files to skip while replacing colors. Overrides replaceColorsList.
|
|
140
|
+
skipReplaceColorsList: [/colors-not-preserved\.svg/],
|
|
110
141
|
|
|
111
142
|
// A list of files to skip while transforming. File skip-transforms.svg is present in every directory.
|
|
112
143
|
skipTransformsList: [/skip-transforms\.svg/, /ignore-elements-orig\.svg/],
|
|
@@ -126,14 +157,14 @@ viteAwesomeSvgLoader({
|
|
|
126
157
|
},
|
|
127
158
|
],
|
|
128
159
|
|
|
129
|
-
// These
|
|
160
|
+
// These options are not recommended due to architectural and performance reasons (see JSDoc):
|
|
130
161
|
|
|
131
162
|
// A list of selectors to skip while replacing colors. Same format as above.
|
|
132
|
-
|
|
163
|
+
skipReplaceColorsSelectors: ['*[data-original-color="true"], *[data-original-color="true"] *'],
|
|
133
164
|
|
|
134
165
|
// A list of selectors to skip while transforming. Same format as above.
|
|
135
166
|
skipTransformsSelectors: ['*[data-no-transforms="true"], *[data-no-transforms="true"] *'],
|
|
136
|
-
})
|
|
167
|
+
})
|
|
137
168
|
```
|
|
138
169
|
|
|
139
170
|
6. Optional. Use integrations to create sprite sheets. Or [write your own integration](https://github.com/matafokka/vite-awesome-svg-loader/tree/main/#custom-integration).
|
|
@@ -323,6 +354,15 @@ See: https://vitejs.dev/guide/features#glob-import
|
|
|
323
354
|
|
|
324
355
|
**Note**: if you want to support browsers without [ES modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import), use [@vitejs/plugin-legacy](https://www.npmjs.com/package/@vitejs/plugin-legacy) as shown in the demos.
|
|
325
356
|
|
|
357
|
+
### For library authors
|
|
358
|
+
|
|
359
|
+
If your icon set is not extensible, just add `vite-awesome-svg-loader` and build your library.
|
|
360
|
+
|
|
361
|
+
If your icon set is extensible, you'll need to:
|
|
362
|
+
|
|
363
|
+
1. Provide a plugin that wraps `vite-awesome-svg-loader` and sets your settings.
|
|
364
|
+
1. Tell your users to use your plugin, import icons as source code and pass it to your components.
|
|
365
|
+
|
|
326
366
|
### Comparison with other loaders
|
|
327
367
|
|
|
328
368
|
**[vite-svg-loader](https://github.com/jpkleemans/vite-svg-loader)**
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
declare module "*.svg?url" { const src: string; export default src; }
|
|
2
|
+
declare module "*.svg?source" { const src: string; export default src; }
|
|
3
|
+
declare module "*.svg?source-data-uri" { const src: string; export default src; }
|
|
4
|
+
declare module "*.svg?base64" { const src: string; export default src; }
|
|
5
|
+
declare module "*.svg?base64-data-uri" { const src: string; export default src; }
|
|
6
|
+
declare module "*.svg?preserve-line-width" { const src: string; export default src; }
|
|
7
|
+
declare module "*.svg?preserve-line-width=true" { const src: string; export default src; }
|
|
8
|
+
declare module "*.svg?preserve-line-width=false" { const src: string; export default src; }
|
|
9
|
+
declare module "*.svg?url&preserve-line-width" { const src: string; export default src; }
|
|
10
|
+
declare module "*.svg?url&preserve-line-width=true" { const src: string; export default src; }
|
|
11
|
+
declare module "*.svg?url&preserve-line-width=false" { const src: string; export default src; }
|
|
12
|
+
declare module "*.svg?source&preserve-line-width" { const src: string; export default src; }
|
|
13
|
+
declare module "*.svg?source&preserve-line-width=true" { const src: string; export default src; }
|
|
14
|
+
declare module "*.svg?source&preserve-line-width=false" { const src: string; export default src; }
|
|
15
|
+
declare module "*.svg?source-data-uri&preserve-line-width" { const src: string; export default src; }
|
|
16
|
+
declare module "*.svg?source-data-uri&preserve-line-width=true" { const src: string; export default src; }
|
|
17
|
+
declare module "*.svg?source-data-uri&preserve-line-width=false" { const src: string; export default src; }
|
|
18
|
+
declare module "*.svg?base64&preserve-line-width" { const src: string; export default src; }
|
|
19
|
+
declare module "*.svg?base64&preserve-line-width=true" { const src: string; export default src; }
|
|
20
|
+
declare module "*.svg?base64&preserve-line-width=false" { const src: string; export default src; }
|
|
21
|
+
declare module "*.svg?base64-data-uri&preserve-line-width" { const src: string; export default src; }
|
|
22
|
+
declare module "*.svg?base64-data-uri&preserve-line-width=true" { const src: string; export default src; }
|
|
23
|
+
declare module "*.svg?base64-data-uri&preserve-line-width=false" { const src: string; export default src; }
|
|
24
|
+
declare module "*.svg?set-current-color" { const src: string; export default src; }
|
|
25
|
+
declare module "*.svg?set-current-color=true" { const src: string; export default src; }
|
|
26
|
+
declare module "*.svg?set-current-color=false" { const src: string; export default src; }
|
|
27
|
+
declare module "*.svg?url&set-current-color" { const src: string; export default src; }
|
|
28
|
+
declare module "*.svg?url&set-current-color=true" { const src: string; export default src; }
|
|
29
|
+
declare module "*.svg?url&set-current-color=false" { const src: string; export default src; }
|
|
30
|
+
declare module "*.svg?source&set-current-color" { const src: string; export default src; }
|
|
31
|
+
declare module "*.svg?source&set-current-color=true" { const src: string; export default src; }
|
|
32
|
+
declare module "*.svg?source&set-current-color=false" { const src: string; export default src; }
|
|
33
|
+
declare module "*.svg?source-data-uri&set-current-color" { const src: string; export default src; }
|
|
34
|
+
declare module "*.svg?source-data-uri&set-current-color=true" { const src: string; export default src; }
|
|
35
|
+
declare module "*.svg?source-data-uri&set-current-color=false" { const src: string; export default src; }
|
|
36
|
+
declare module "*.svg?base64&set-current-color" { const src: string; export default src; }
|
|
37
|
+
declare module "*.svg?base64&set-current-color=true" { const src: string; export default src; }
|
|
38
|
+
declare module "*.svg?base64&set-current-color=false" { const src: string; export default src; }
|
|
39
|
+
declare module "*.svg?base64-data-uri&set-current-color" { const src: string; export default src; }
|
|
40
|
+
declare module "*.svg?base64-data-uri&set-current-color=true" { const src: string; export default src; }
|
|
41
|
+
declare module "*.svg?base64-data-uri&set-current-color=false" { const src: string; export default src; }
|
|
42
|
+
declare module "*.svg?skip-transforms" { const src: string; export default src; }
|
|
43
|
+
declare module "*.svg?skip-transforms=true" { const src: string; export default src; }
|
|
44
|
+
declare module "*.svg?skip-transforms=false" { const src: string; export default src; }
|
|
45
|
+
declare module "*.svg?url&skip-transforms" { const src: string; export default src; }
|
|
46
|
+
declare module "*.svg?url&skip-transforms=true" { const src: string; export default src; }
|
|
47
|
+
declare module "*.svg?url&skip-transforms=false" { const src: string; export default src; }
|
|
48
|
+
declare module "*.svg?source&skip-transforms" { const src: string; export default src; }
|
|
49
|
+
declare module "*.svg?source&skip-transforms=true" { const src: string; export default src; }
|
|
50
|
+
declare module "*.svg?source&skip-transforms=false" { const src: string; export default src; }
|
|
51
|
+
declare module "*.svg?source-data-uri&skip-transforms" { const src: string; export default src; }
|
|
52
|
+
declare module "*.svg?source-data-uri&skip-transforms=true" { const src: string; export default src; }
|
|
53
|
+
declare module "*.svg?source-data-uri&skip-transforms=false" { const src: string; export default src; }
|
|
54
|
+
declare module "*.svg?base64&skip-transforms" { const src: string; export default src; }
|
|
55
|
+
declare module "*.svg?base64&skip-transforms=true" { const src: string; export default src; }
|
|
56
|
+
declare module "*.svg?base64&skip-transforms=false" { const src: string; export default src; }
|
|
57
|
+
declare module "*.svg?base64-data-uri&skip-transforms" { const src: string; export default src; }
|
|
58
|
+
declare module "*.svg?base64-data-uri&skip-transforms=true" { const src: string; export default src; }
|
|
59
|
+
declare module "*.svg?base64-data-uri&skip-transforms=false" { const src: string; export default src; }
|
|
60
|
+
declare module "*.svg?skip-awesome-svg-loader" { const src: string; export default src; }
|
|
61
|
+
declare module "*.svg?skip-awesome-svg-loader=true" { const src: string; export default src; }
|
|
62
|
+
declare module "*.svg?skip-awesome-svg-loader=false" { const src: string; export default src; }
|
|
63
|
+
declare module "*.svg?url&skip-awesome-svg-loader" { const src: string; export default src; }
|
|
64
|
+
declare module "*.svg?url&skip-awesome-svg-loader=true" { const src: string; export default src; }
|
|
65
|
+
declare module "*.svg?url&skip-awesome-svg-loader=false" { const src: string; export default src; }
|
|
66
|
+
declare module "*.svg?source&skip-awesome-svg-loader" { const src: string; export default src; }
|
|
67
|
+
declare module "*.svg?source&skip-awesome-svg-loader=true" { const src: string; export default src; }
|
|
68
|
+
declare module "*.svg?source&skip-awesome-svg-loader=false" { const src: string; export default src; }
|
|
69
|
+
declare module "*.svg?source-data-uri&skip-awesome-svg-loader" { const src: string; export default src; }
|
|
70
|
+
declare module "*.svg?source-data-uri&skip-awesome-svg-loader=true" { const src: string; export default src; }
|
|
71
|
+
declare module "*.svg?source-data-uri&skip-awesome-svg-loader=false" { const src: string; export default src; }
|
|
72
|
+
declare module "*.svg?base64&skip-awesome-svg-loader" { const src: string; export default src; }
|
|
73
|
+
declare module "*.svg?base64&skip-awesome-svg-loader=true" { const src: string; export default src; }
|
|
74
|
+
declare module "*.svg?base64&skip-awesome-svg-loader=false" { const src: string; export default src; }
|
|
75
|
+
declare module "*.svg?base64-data-uri&skip-awesome-svg-loader" { const src: string; export default src; }
|
|
76
|
+
declare module "*.svg?base64-data-uri&skip-awesome-svg-loader=true" { const src: string; export default src; }
|
|
77
|
+
declare module "*.svg?base64-data-uri&skip-awesome-svg-loader=false" { const src: string; export default src; }
|
package/index.d.mts
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SVG loader options.
|
|
5
|
+
*
|
|
6
|
+
* **Paths**
|
|
7
|
+
*
|
|
8
|
+
* Both file name and its path relative to the project's root with leading slash will be compared.
|
|
9
|
+
*
|
|
10
|
+
* For example, if you have a file `/src/assets/icons/menu.svg` then following strings will be checked:
|
|
11
|
+
*
|
|
12
|
+
* 1. `/assets/icons/menu.svg` - note that it doesn't start with `/src`
|
|
13
|
+
* 2. `menu.svg`
|
|
14
|
+
*
|
|
15
|
+
* To avoid transforming multiple files with the same name, always include path into each entry.
|
|
16
|
+
*
|
|
17
|
+
* Examples:
|
|
18
|
+
*
|
|
19
|
+
* ```js
|
|
20
|
+
* plugins: [
|
|
21
|
+
* viteReBinSvgLoader({
|
|
22
|
+
* preserveLineWidthList: [
|
|
23
|
+
* // Recommended formats:
|
|
24
|
+
* /\/img\/icons/, // Matches all paths containing "/img/line-art/"
|
|
25
|
+
* "/assets/img/logo.svg", // Matches single file "/assets/img/logo.svg".
|
|
26
|
+
*
|
|
27
|
+
* // Not recommended formats:
|
|
28
|
+
* "splash.svg", // Matches all files named "splash.svg"
|
|
29
|
+
* /\/icons\/plus\.svg/, // Matches all paths containing "/icons/plus.svg"
|
|
30
|
+
* ],
|
|
31
|
+
* }),
|
|
32
|
+
* ],
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
interface SvgLoaderOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Temporary directory where SVG files will be stored in dev mode.
|
|
38
|
+
*
|
|
39
|
+
* @default "temp"
|
|
40
|
+
*/
|
|
41
|
+
tempDir?: string;
|
|
42
|
+
/**
|
|
43
|
+
* A list of files or directories to preserve line width of, i.e. to set `vector-effect="non-scaling-stroke"`.
|
|
44
|
+
*
|
|
45
|
+
* This option is primarily for icons and line art.
|
|
46
|
+
*
|
|
47
|
+
* This also can be done in an import: `import imageSrc from "./path/to/image.svg?preserve-line-width"`.
|
|
48
|
+
*/
|
|
49
|
+
preserveLineWidthList?: (string | RegExp)[];
|
|
50
|
+
/**
|
|
51
|
+
* A list of files or directories to disable preserving line width of. Overrides {@link preserveLineWidthList}.
|
|
52
|
+
*/
|
|
53
|
+
skipPreserveLineWidthList?: (string | RegExp)[];
|
|
54
|
+
/**
|
|
55
|
+
* A list of CSS selectors to disable {@link preserveLineWidthList} for. Use it to leave specific elements stroke
|
|
56
|
+
* width as-is.
|
|
57
|
+
*
|
|
58
|
+
* Can be a list of selectors or selectors-per-files specifiers.
|
|
59
|
+
*
|
|
60
|
+
* Unlike {@link skipSetCurrentColorSelectors} and {@link skipTransformsSelectors}, doesn't impact build performance.
|
|
61
|
+
*/
|
|
62
|
+
skipPreserveLineWidthSelectors?: (string | SelectorsPerFiles)[];
|
|
63
|
+
/**
|
|
64
|
+
* A list of files or directories to replace fill, stroke and `<stop>` colors with `currentColor` (default) or other
|
|
65
|
+
* colors (if {@link ColorMapPerFiles} or {@link ColorMap} is specified), i.e.:
|
|
66
|
+
*
|
|
67
|
+
* 1. `fill`, `stroke` and `stop-color` attributes and CSS identifiers will be replaced with `currentColor` or other
|
|
68
|
+
* given color.
|
|
69
|
+
* 2. `none`, `transparent` or `currentColor` values will not be replaced.
|
|
70
|
+
*
|
|
71
|
+
* Opacity (i.e. `rgba()`) won't be preserved.
|
|
72
|
+
* You have to manually set opacity by setting `fill-opacity` and `stroke-opacity` attributes.
|
|
73
|
+
*
|
|
74
|
+
* This is done because opacity may be handled with a stylesheet selector. This case is hard to implement, and it may
|
|
75
|
+
* slow down build process. This behavior might be changed in future, but it shouldn't break your project.
|
|
76
|
+
*
|
|
77
|
+
* Setting `currentColor` can be done with an import: `import imageSrc from "./path/to/image.svg?set-current-color"`.
|
|
78
|
+
*
|
|
79
|
+
* Replacements priority:
|
|
80
|
+
*
|
|
81
|
+
* 1. {@link ColorMapPerFiles}
|
|
82
|
+
* 1. {@link ColorMap}
|
|
83
|
+
* 1. `string | RegExp`
|
|
84
|
+
*/
|
|
85
|
+
replaceColorsList?: (string | RegExp | ColorMap | ColorMapPerFiles)[];
|
|
86
|
+
/**
|
|
87
|
+
* A list of files or directories to disable color replacements of. Overrides {@link replaceColorsList}.
|
|
88
|
+
*/
|
|
89
|
+
skipReplaceColorsList?: (string | RegExp)[];
|
|
90
|
+
/**
|
|
91
|
+
* A list of CSS selectors to disable {@link skipReplaceColorsList} for. Use it to leave specific elements colors
|
|
92
|
+
* as-is.
|
|
93
|
+
*
|
|
94
|
+
* Can be a list of selectors or selectors-per-files specifiers.
|
|
95
|
+
*
|
|
96
|
+
* **You probably don't need this option.** Think of other ways to solve your problem. "Recipes" section
|
|
97
|
+
* in the demos may help you.
|
|
98
|
+
*
|
|
99
|
+
* **Heavy usage may significantly slow down build time.** Limit selectors to specific files to improve performance.
|
|
100
|
+
*/
|
|
101
|
+
skipReplaceColorsSelectors?: (string | SelectorsPerFiles)[];
|
|
102
|
+
/**
|
|
103
|
+
* A list of files to skip while transforming.
|
|
104
|
+
*
|
|
105
|
+
* For example, if you add a directory to {@link preserveLineWidthList} and add a file in that directory to this list,
|
|
106
|
+
* line width of added file won't be preserved.
|
|
107
|
+
*
|
|
108
|
+
* SVGO is still applied to the added files.
|
|
109
|
+
*/
|
|
110
|
+
skipTransformsList?: (string | RegExp)[];
|
|
111
|
+
/**
|
|
112
|
+
* A list of CSS selectors to disable all transforms for. Use it to leave specific elements as-is.
|
|
113
|
+
*
|
|
114
|
+
* Can be a list of selectors or selectors-per-files specifiers.
|
|
115
|
+
*
|
|
116
|
+
* **You probably don't need this option.** Think of other ways to solve your problem. "Recipes" section
|
|
117
|
+
* in the demos may help you.
|
|
118
|
+
*
|
|
119
|
+
* **Heavy usage may significantly slow down build time.** Limit selectors to specific files to improve performance.
|
|
120
|
+
*/
|
|
121
|
+
skipTransformsSelectors?: (string | SelectorsPerFiles)[];
|
|
122
|
+
/**
|
|
123
|
+
* A list of files to skip loading of. Useful for passing original files to another loader.
|
|
124
|
+
*
|
|
125
|
+
* This also can be done in an import: `import imageSrc from "./path/to/image.svg?skip-transforms"`.
|
|
126
|
+
*/
|
|
127
|
+
skipFilesList?: (string | RegExp)[];
|
|
128
|
+
/**
|
|
129
|
+
* Default import type, i.e. what you get without specifying anything in the import URL.
|
|
130
|
+
*
|
|
131
|
+
* This also can be done in an import:
|
|
132
|
+
*
|
|
133
|
+
* ```ts
|
|
134
|
+
* // Source code
|
|
135
|
+
* import imageSrc from "./path/to/image.svg?source";
|
|
136
|
+
*
|
|
137
|
+
* // URL
|
|
138
|
+
* import imageUrl from "./path/to/image.svg?url";
|
|
139
|
+
*
|
|
140
|
+
* // Source code Data URI
|
|
141
|
+
* import imageSrcDataUri from "./path/to/image.svg?source-data-uri";
|
|
142
|
+
*
|
|
143
|
+
* // Base64
|
|
144
|
+
* import imageBase64 from "./path/to/image.svg?base-64";
|
|
145
|
+
*
|
|
146
|
+
* // Base64 data URI
|
|
147
|
+
* import imageBase64DataUri from "./path/to/image.svg?base-64-data-uri";
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @default "source"
|
|
151
|
+
*/
|
|
152
|
+
defaultImport?: ImportType;
|
|
153
|
+
/**
|
|
154
|
+
* A list of files or directories to replace fill, stroke and `<stop>` colors of with `currentColor`.
|
|
155
|
+
*
|
|
156
|
+
* Overrides {@link replaceColorsList}.
|
|
157
|
+
*
|
|
158
|
+
* @deprecated Deprecated in favor of {@link replaceColorsList}
|
|
159
|
+
*/
|
|
160
|
+
setCurrentColorList?: (string | RegExp)[];
|
|
161
|
+
/**
|
|
162
|
+
* A list of files or directories to disable setting current color of. Overrides {@link setCurrentColorList} and
|
|
163
|
+
* {@link replaceColorsList}.
|
|
164
|
+
*
|
|
165
|
+
* @deprecated Deprecated in favor of {@link replaceColorsList}
|
|
166
|
+
*/
|
|
167
|
+
skipSetCurrentColorList?: (string | RegExp)[];
|
|
168
|
+
/**
|
|
169
|
+
* A list of CSS selectors to disable {@link setCurrentColorList} for.Overrides {@link setCurrentColorList},
|
|
170
|
+
* {@link replaceColorsList} and {@link skipReplaceColorsSelectors}.
|
|
171
|
+
*
|
|
172
|
+
* @deprecated Deprecated in favor of {@link skipReplaceColorsSelectors}
|
|
173
|
+
*/
|
|
174
|
+
skipSetCurrentColorSelectors?: (string | SelectorsPerFiles)[];
|
|
175
|
+
}
|
|
176
|
+
type ImportType = "url" | "source" | "source-data-uri" | "base64" | "base64-data-uri";
|
|
177
|
+
/**
|
|
178
|
+
* CSS selector per file or files
|
|
179
|
+
*/
|
|
180
|
+
interface SelectorsPerFiles {
|
|
181
|
+
/**
|
|
182
|
+
* List of filenames and/or paths matchers
|
|
183
|
+
*/
|
|
184
|
+
files: (string | RegExp)[];
|
|
185
|
+
/**
|
|
186
|
+
* List of selectors
|
|
187
|
+
*/
|
|
188
|
+
selectors: string[];
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Maps original SVG colors (case-insensitive) to their replacements
|
|
192
|
+
*/
|
|
193
|
+
type ColorMap = Record<string, string>;
|
|
194
|
+
/**
|
|
195
|
+
* Maps original SVG colors (case-insensitive) to their replacements. Can be applied to specific files via {@link files} property.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
*
|
|
199
|
+
* {
|
|
200
|
+
* // Optional list of files to apply replacements to.
|
|
201
|
+
* files: ["my-file.svg", /icon\-*.\.svg/],
|
|
202
|
+
*
|
|
203
|
+
* // Will replace all colors with "red" value with "var(--primary-color)".
|
|
204
|
+
* // It'll replace only "red". HEX ("#ff0000"), RGB ("rgb(255, 0, 0)") and other values won't be replaced.
|
|
205
|
+
* "red": "var(--primary-color)",
|
|
206
|
+
*
|
|
207
|
+
* // Same as above: this HEX value (case-insensitive) will be replaced with "var(--secondary-color)".
|
|
208
|
+
* // Just "blue" or any other values with the same resulting color won't be replaced.
|
|
209
|
+
* "#0000ff": "var(--secondary-color)",
|
|
210
|
+
*
|
|
211
|
+
* // Again, only this value (case-insensitive) will be replaced with "var(--tertiary-color)". Any other value will be
|
|
212
|
+
* // left as-is.
|
|
213
|
+
* "rgb(0, 255, 0)": "var(--tertiary-color)",
|
|
214
|
+
* }
|
|
215
|
+
*/
|
|
216
|
+
interface ColorMapPerFiles {
|
|
217
|
+
/**
|
|
218
|
+
* A list of files to apply replacements to. If omitted, replacements will be applied to all files
|
|
219
|
+
*/
|
|
220
|
+
files: (string | RegExp)[];
|
|
221
|
+
/**
|
|
222
|
+
* Maps original SVG colors (case-insensitive) to their replacements
|
|
223
|
+
*/
|
|
224
|
+
replacements: ColorMap;
|
|
225
|
+
/**
|
|
226
|
+
* Replacement for other colors. Set to empty string to leave colors as-is.
|
|
227
|
+
*
|
|
228
|
+
* @default "currentColor"
|
|
229
|
+
*/
|
|
230
|
+
default?: string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* A Vite plugin that:
|
|
235
|
+
*
|
|
236
|
+
* 1. Can import SVGs (see also: {@link SvgLoaderOptions.defaultImport}) as:
|
|
237
|
+
* 1. Source code (default import type): `import imageSrc from "./path/to/image.svg"`.
|
|
238
|
+
* 1. URL: `import imageUrl from "./path/to/image.svg?url"`.
|
|
239
|
+
* 1. Source code data URI: `import imageSrcDataUri from "./path/to/image.svg?source-data-uri"`.
|
|
240
|
+
* 1. Source code Base64: `import imageBase64 from "./path/to/image.svg?base64"`.
|
|
241
|
+
* 1. Source code Base64 data URI: `import imageBase64DataUri from "./path/to/image.svg?base64-data-uri"`.
|
|
242
|
+
*
|
|
243
|
+
* 1. Can preserve line width (make icons and line art have same line width when scaling):
|
|
244
|
+
* `import imageSrc from "./path/to/image.svg?preserve-line-width"`.
|
|
245
|
+
* Can be configured via {@link SvgLoaderOptions.preserveLineWidthList}.
|
|
246
|
+
*
|
|
247
|
+
* 1. Can replace colors with `currentColor` (or a custom color via {@link SvgLoaderOptions.replaceColorsList}):
|
|
248
|
+
* `import imageSrc from "./path/to/image.svg?set-current-color"`.
|
|
249
|
+
* Can be configured via {@link SvgLoaderOptions.replaceColorsList}.
|
|
250
|
+
*
|
|
251
|
+
* 1. Will automatically minimize your SVGs using [SVGO](https://github.com/svg/svgo).
|
|
252
|
+
*
|
|
253
|
+
* 1. Allows you to create SVG sprites using provided integrations.
|
|
254
|
+
*
|
|
255
|
+
* @param options Plugin options
|
|
256
|
+
*/
|
|
257
|
+
declare function viteAwesomeSvgLoader(options?: SvgLoaderOptions): Plugin;
|
|
258
|
+
|
|
259
|
+
export { type ColorMap, type ColorMapPerFiles, type ImportType, type SelectorsPerFiles, type SvgLoaderOptions, viteAwesomeSvgLoader };
|
|
260
|
+
import "./declarations";
|