vite-awesome-svg-loader 3.0.3 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +11 -6
  2. package/chunk.cjs +34 -0
  3. package/dist.cjs +120 -0
  4. package/dist.js +82 -0
  5. package/integration-utils.cjs +8 -0
  6. package/integration-utils.d.cts +20 -0
  7. package/integration-utils.d.ts +20 -0
  8. package/integration-utils.js +3 -0
  9. package/loader.cjs +326 -0
  10. package/loader.d.cts +406 -0
  11. package/loader.d.ts +406 -0
  12. package/loader.js +322 -0
  13. package/package.json +71 -38
  14. package/react-integration.cjs +61 -0
  15. package/react-integration.d.cts +23 -0
  16. package/react-integration.d.ts +23 -0
  17. package/react-integration.js +59 -0
  18. package/{integration-utils/index.d.ts → svg-symbols.d.cts} +18 -15
  19. package/svg-symbols.d.ts +41 -0
  20. package/types.d.cts +58 -0
  21. package/types.d.ts +58 -0
  22. package/vanilla-integration.cjs +231 -0
  23. package/vanilla-integration.d.cts +259 -0
  24. package/vanilla-integration.d.ts +259 -0
  25. package/vanilla-integration.js +227 -0
  26. package/vue-integration.cjs +60 -0
  27. package/vue-integration.d.cts +10 -0
  28. package/vue-integration.d.ts +10 -0
  29. package/vue-integration.js +58 -0
  30. package/index.d.mts +0 -402
  31. package/index.d.ts +0 -402
  32. package/index.js +0 -576
  33. package/index.mjs +0 -542
  34. package/integration-utils/index.js +0 -1
  35. package/integration-utils/index.js.map +0 -1
  36. package/integration-utils/index.mjs +0 -1
  37. package/integration-utils/index.mjs.map +0 -1
  38. package/react-integration/index.cjs +0 -3
  39. package/react-integration/index.cjs.map +0 -1
  40. package/react-integration/index.d.ts +0 -72
  41. package/react-integration/index.js +0 -182
  42. package/react-integration/index.js.map +0 -1
  43. package/vanilla-integration/index.cjs +0 -3
  44. package/vanilla-integration/index.cjs.map +0 -1
  45. package/vanilla-integration/index.d.ts +0 -268
  46. package/vanilla-integration/index.js +0 -379
  47. package/vanilla-integration/index.js.map +0 -1
  48. package/vue-integration/index.cjs +0 -3
  49. package/vue-integration/index.cjs.map +0 -1
  50. package/vue-integration/index.d.ts +0 -67
  51. package/vue-integration/index.js +0 -194
  52. package/vue-integration/index.js.map +0 -1
  53. /package/{integration-utils/styles.css → integration-utils-styles.css} +0 -0
package/README.md CHANGED
@@ -13,11 +13,16 @@ A Vite plugin that:
13
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
- `vite-awesome-svg-loader` is framework-agnostic. All integrations are done as subpath imports
17
- (for example, `vite-awesome-svg-loader/vue-integration`). This means that you'll get only what you need in your
18
- app bundle. This also means that you can
19
- [develop your own integration](https://matafokka.github.io/vite-awesome-svg-loader/guides/custom-integrations)
20
- using `vite-awesome-svg-loader/integration-utils` import.
16
+ `vite-awesome-svg-loader` is framework-agnostic.
17
+
18
+ However, to create SVG symbols, some boilerplate code in form of components is required. These components are provided
19
+ in the integrations.
20
+
21
+ All integrations are provided as ES modules in separate subpath imports
22
+ (for example, `vite-awesome-svg-loader/vue-integration`), so your app will contain only required code.
23
+
24
+ You can integrate `vite-awesome-svg-loader` with [any framework](https://matafokka.github.io/vite-awesome-svg-loader/other-frameworks/quick-start)
25
+ using `vite-awesome-svg-loader/integration-utils` package.
21
26
 
22
27
  ## Installation
23
28
 
@@ -40,4 +45,4 @@ npm i vite-awesome-svg-loader
40
45
  - [React](https://matafokka.github.io/vite-awesome-svg-loader/react/quick-start/)
41
46
  - [Vue](https://matafokka.github.io/vite-awesome-svg-loader/vue/quick-start/)
42
47
  - [Vanilla JS](https://matafokka.github.io/vite-awesome-svg-loader/vanilla-js/quick-start/)
43
- - [Custom framework](https://matafokka.github.io/vite-awesome-svg-loader/guides/custom-integrations/)
48
+ - [Other frameworks](https://matafokka.github.io/vite-awesome-svg-loader/other-frameworks/quick-start/)
package/chunk.cjs ADDED
@@ -0,0 +1,34 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ Object.defineProperty(exports, '__toESM', {
30
+ enumerable: true,
31
+ get: function () {
32
+ return __toESM;
33
+ }
34
+ });
package/dist.cjs ADDED
@@ -0,0 +1,120 @@
1
+ const require_chunk = require('./chunk.cjs');
2
+ let debounce = require("debounce");
3
+ debounce = require_chunk.__toESM(debounce);
4
+ let imurmurhash = require("imurmurhash");
5
+ imurmurhash = require_chunk.__toESM(imurmurhash);
6
+
7
+ //#region ../integration-utils/dist/index.mjs
8
+ const g = "svg-symbols", m = "svg-", d = "data-count";
9
+ function b(t, e) {
10
+ if (typeof window > "u" || t === e) return {};
11
+ let n = document.getElementById(g);
12
+ if (n || (n = document.createElementNS("http://www.w3.org/2000/svg", "svg"), n.id = g, n.setAttribute("aria-hidden", "true"), n.setAttribute("style", "position:fixed;top:-99999px;left:-99999px;z-index:0;opacity:0;"), document.body.appendChild(n)), t) {
13
+ const s = m + new imurmurhash.default(t).result();
14
+ w(document.getElementById(s));
15
+ }
16
+ const i = m + new imurmurhash.default(e).result(), u = document.getElementById(i);
17
+ if (u) return u.setAttribute(d, l(u) + 1 + ""), {
18
+ id: i,
19
+ attrs: h(u)
20
+ };
21
+ const o = new DOMParser().parseFromString(e, "application/xml").firstElementChild;
22
+ if (o?.querySelector("parsererror")) return console.error("Provided source code is not a valid SVG: " + e), { id: i };
23
+ if (!o) return console.error("Missing child in SVG: " + e), { id: i };
24
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "symbol");
25
+ for (let s = 0; s < o.attributes.length; s++) {
26
+ const a = o.attributes[s];
27
+ r.setAttribute(a.name, a.value);
28
+ }
29
+ for (r.id = i, r.setAttribute(d, "1"); o.children.length;) r.appendChild(o.children[0]);
30
+ return n.appendChild(r), {
31
+ id: i,
32
+ attrs: h(r)
33
+ };
34
+ }
35
+ function x(t) {
36
+ !t || typeof window > "u" || w(typeof t == "string" ? document.getElementById(t) : t);
37
+ }
38
+ function w(t) {
39
+ if (!t) return;
40
+ const e = l(t, 1) - 1;
41
+ t.setAttribute(d, e + ""), e <= 0 && (c.push(t), v());
42
+ }
43
+ const c = [], v = (0, debounce.default)(() => {
44
+ for (let t = c.length - 1; t >= 0; t--) {
45
+ const e = c[t];
46
+ e.parentElement && l(e) <= 0 && e.parentElement.removeChild(e), c.pop();
47
+ }
48
+ }, 5e3);
49
+ function l(t, e = 0) {
50
+ if (!t) return e;
51
+ const n = parseInt(t.getAttribute(d) || "1");
52
+ return isNaN(n) ? e : n;
53
+ }
54
+ function h(t) {
55
+ let e = t.getAttribute("viewBox") || "";
56
+ if (!e) for (const n of [
57
+ "x",
58
+ "y",
59
+ "width",
60
+ "height"
61
+ ]) {
62
+ const i = t.getAttribute(n);
63
+ e += (i || "0") + " ";
64
+ }
65
+ return {
66
+ viewBox: e,
67
+ width: "100%",
68
+ height: "100%"
69
+ };
70
+ }
71
+ function A(t) {
72
+ const e = {};
73
+ if (t.size && t.size !== "unset") for (const n of [
74
+ "width",
75
+ "minWidth",
76
+ "maxWidth",
77
+ "height",
78
+ "minHeight",
79
+ "maxHeight"
80
+ ]) e[n] = t.size;
81
+ return t.color && (e["--icon-color"] = t.color), e["--icon-transition"] = t.colorTransition || "0.3s linear", e;
82
+ }
83
+
84
+ //#endregion
85
+ Object.defineProperty(exports, 'A', {
86
+ enumerable: true,
87
+ get: function () {
88
+ return A;
89
+ }
90
+ });
91
+ Object.defineProperty(exports, 'b', {
92
+ enumerable: true,
93
+ get: function () {
94
+ return b;
95
+ }
96
+ });
97
+ Object.defineProperty(exports, 'd', {
98
+ enumerable: true,
99
+ get: function () {
100
+ return d;
101
+ }
102
+ });
103
+ Object.defineProperty(exports, 'g', {
104
+ enumerable: true,
105
+ get: function () {
106
+ return g;
107
+ }
108
+ });
109
+ Object.defineProperty(exports, 'm', {
110
+ enumerable: true,
111
+ get: function () {
112
+ return m;
113
+ }
114
+ });
115
+ Object.defineProperty(exports, 'x', {
116
+ enumerable: true,
117
+ get: function () {
118
+ return x;
119
+ }
120
+ });
package/dist.js ADDED
@@ -0,0 +1,82 @@
1
+ import p from "debounce";
2
+ import pe from "imurmurhash";
3
+
4
+ //#region ../integration-utils/dist/index.mjs
5
+ const g = "svg-symbols", m = "svg-", d = "data-count";
6
+ function b(t, e) {
7
+ if (typeof window > "u" || t === e) return {};
8
+ let n = document.getElementById(g);
9
+ if (n || (n = document.createElementNS("http://www.w3.org/2000/svg", "svg"), n.id = g, n.setAttribute("aria-hidden", "true"), n.setAttribute("style", "position:fixed;top:-99999px;left:-99999px;z-index:0;opacity:0;"), document.body.appendChild(n)), t) {
10
+ const s = m + new pe(t).result();
11
+ w(document.getElementById(s));
12
+ }
13
+ const i = m + new pe(e).result(), u = document.getElementById(i);
14
+ if (u) return u.setAttribute(d, l(u) + 1 + ""), {
15
+ id: i,
16
+ attrs: h(u)
17
+ };
18
+ const o = new DOMParser().parseFromString(e, "application/xml").firstElementChild;
19
+ if (o?.querySelector("parsererror")) return console.error("Provided source code is not a valid SVG: " + e), { id: i };
20
+ if (!o) return console.error("Missing child in SVG: " + e), { id: i };
21
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "symbol");
22
+ for (let s = 0; s < o.attributes.length; s++) {
23
+ const a = o.attributes[s];
24
+ r.setAttribute(a.name, a.value);
25
+ }
26
+ for (r.id = i, r.setAttribute(d, "1"); o.children.length;) r.appendChild(o.children[0]);
27
+ return n.appendChild(r), {
28
+ id: i,
29
+ attrs: h(r)
30
+ };
31
+ }
32
+ function x(t) {
33
+ !t || typeof window > "u" || w(typeof t == "string" ? document.getElementById(t) : t);
34
+ }
35
+ function w(t) {
36
+ if (!t) return;
37
+ const e = l(t, 1) - 1;
38
+ t.setAttribute(d, e + ""), e <= 0 && (c.push(t), v());
39
+ }
40
+ const c = [], v = p(() => {
41
+ for (let t = c.length - 1; t >= 0; t--) {
42
+ const e = c[t];
43
+ e.parentElement && l(e) <= 0 && e.parentElement.removeChild(e), c.pop();
44
+ }
45
+ }, 5e3);
46
+ function l(t, e = 0) {
47
+ if (!t) return e;
48
+ const n = parseInt(t.getAttribute(d) || "1");
49
+ return isNaN(n) ? e : n;
50
+ }
51
+ function h(t) {
52
+ let e = t.getAttribute("viewBox") || "";
53
+ if (!e) for (const n of [
54
+ "x",
55
+ "y",
56
+ "width",
57
+ "height"
58
+ ]) {
59
+ const i = t.getAttribute(n);
60
+ e += (i || "0") + " ";
61
+ }
62
+ return {
63
+ viewBox: e,
64
+ width: "100%",
65
+ height: "100%"
66
+ };
67
+ }
68
+ function A(t) {
69
+ const e = {};
70
+ if (t.size && t.size !== "unset") for (const n of [
71
+ "width",
72
+ "minWidth",
73
+ "maxWidth",
74
+ "height",
75
+ "minHeight",
76
+ "maxHeight"
77
+ ]) e[n] = t.size;
78
+ return t.color && (e["--icon-color"] = t.color), e["--icon-transition"] = t.colorTransition || "0.3s linear", e;
79
+ }
80
+
81
+ //#endregion
82
+ export { A, b, d, g, m, x };
@@ -0,0 +1,8 @@
1
+ const require_dist = require('./dist.cjs');
2
+
3
+ exports.SVG_ID = require_dist.g;
4
+ exports.SYMBOL_ID_PREFIX = require_dist.m;
5
+ exports.USAGES_COUNT_ATTR = require_dist.d;
6
+ exports.getSvgIconStyle = require_dist.A;
7
+ exports.onSrcUpdate = require_dist.b;
8
+ exports.onUnmount = require_dist.x;
@@ -0,0 +1,20 @@
1
+ import { SvgIconProps, SvgIconStyleProps, SvgImageProps } from "./types.cjs";
2
+ import { SVG_ID, SYMBOL_ID_PREFIX, USAGES_COUNT_ATTR, onSrcUpdate, onUnmount } from "./svg-symbols.cjs";
3
+
4
+ //#region ../integration-utils/dist/svg-icon.d.ts
5
+
6
+ /**
7
+ * Converts `SvgIcon` props into a key-value pairs that should be passed to the element's `style` attribute.
8
+ *
9
+ * Keys format:
10
+ *
11
+ * 1. CSS variables are in snake case: `--var-name`.
12
+ * 1. CSS properties are in camel case: `minWidth`.
13
+ *
14
+ * @param props `SvgIcon` props
15
+ * @param options Conversion options
16
+ * @returns Style map
17
+ */
18
+ declare function getSvgIconStyle(props: SvgIconStyleProps): Record<string, string>;
19
+ //#endregion
20
+ export { SVG_ID, SYMBOL_ID_PREFIX, SvgIconProps, SvgIconStyleProps, SvgImageProps, USAGES_COUNT_ATTR, getSvgIconStyle, onSrcUpdate, onUnmount };
@@ -0,0 +1,20 @@
1
+ import { SvgIconProps, SvgIconStyleProps, SvgImageProps } from "./types.js";
2
+ import { SVG_ID, SYMBOL_ID_PREFIX, USAGES_COUNT_ATTR, onSrcUpdate, onUnmount } from "./svg-symbols.js";
3
+
4
+ //#region ../integration-utils/dist/svg-icon.d.ts
5
+
6
+ /**
7
+ * Converts `SvgIcon` props into a key-value pairs that should be passed to the element's `style` attribute.
8
+ *
9
+ * Keys format:
10
+ *
11
+ * 1. CSS variables are in snake case: `--var-name`.
12
+ * 1. CSS properties are in camel case: `minWidth`.
13
+ *
14
+ * @param props `SvgIcon` props
15
+ * @param options Conversion options
16
+ * @returns Style map
17
+ */
18
+ declare function getSvgIconStyle(props: SvgIconStyleProps): Record<string, string>;
19
+ //#endregion
20
+ export { SVG_ID, SYMBOL_ID_PREFIX, SvgIconProps, SvgIconStyleProps, SvgImageProps, USAGES_COUNT_ATTR, getSvgIconStyle, onSrcUpdate, onUnmount };
@@ -0,0 +1,3 @@
1
+ import { A, b, d, g, m, x } from "./dist.js";
2
+
3
+ export { g as SVG_ID, m as SYMBOL_ID_PREFIX, d as USAGES_COUNT_ATTR, A as getSvgIconStyle, b as onSrcUpdate, x as onUnmount };
package/loader.cjs ADDED
@@ -0,0 +1,326 @@
1
+ const require_chunk = require('./chunk.cjs');
2
+ let imurmurhash = require("imurmurhash");
3
+ imurmurhash = require_chunk.__toESM(imurmurhash);
4
+ let node_fs_promises = require("node:fs/promises");
5
+ let path = require("path");
6
+ path = require_chunk.__toESM(path);
7
+ let svgo = require("svgo");
8
+ let svgo_lib_xast_js = require("svgo/lib/xast.js");
9
+ let css_tree = require("css-tree");
10
+ css_tree = require_chunk.__toESM(css_tree);
11
+
12
+ //#region ../loader/dist/index.mjs
13
+ function H(e) {
14
+ return e = e.replaceAll("\\", "/"), e.endsWith("/") && (e = e.substring(0, e.length - 1)), e;
15
+ }
16
+ function Q(e) {
17
+ const t = String.fromCodePoint(...new TextEncoder().encode(e));
18
+ return btoa(t);
19
+ }
20
+ function J(e) {
21
+ return e.replaceAll("`", "\\`");
22
+ }
23
+ function E(e, t, i) {
24
+ return Z(t) || $(e, i);
25
+ }
26
+ function Z(e) {
27
+ return !!e && e.toLowerCase() !== "false";
28
+ }
29
+ function $(e, t) {
30
+ const a = [path.default.basename(e), e];
31
+ for (const o of t) {
32
+ const u = o instanceof RegExp;
33
+ for (const n of a) if (u ? o.test(n) : n === o) return !0;
34
+ }
35
+ return !1;
36
+ }
37
+ function Y(e) {
38
+ return e.replaceAll(/\s+/g, " ").trim();
39
+ }
40
+ function A(e, t, i) {
41
+ const a = [];
42
+ if (i) return a;
43
+ for (const o of t) {
44
+ if (typeof o == "string") {
45
+ a.push(Y(o));
46
+ continue;
47
+ }
48
+ if ($(e, o.files)) for (const u of o.selectors) a.push(Y(u));
49
+ }
50
+ return a;
51
+ }
52
+ const ee = svgo_lib_xast_js.matches;
53
+ function W(e, t) {
54
+ for (const i of t) if (ee(e, i)) return !0;
55
+ return !1;
56
+ }
57
+ function F(e, t) {
58
+ return e ? t.replacements[e.toLowerCase()] || t.default || e : t.default || "";
59
+ }
60
+ const me = {
61
+ circle: !0,
62
+ ellipse: !0,
63
+ foreignObject: !0,
64
+ image: !0,
65
+ line: !0,
66
+ path: !0,
67
+ polygon: !0,
68
+ polyline: !0,
69
+ rect: !0,
70
+ text: !0,
71
+ textPath: !0,
72
+ tspan: !0,
73
+ use: !0
74
+ };
75
+ function he(e, t) {
76
+ if (!me[e.name]) return;
77
+ const i = e.attributes["vector-effect"];
78
+ i && i !== "non-scaling-stroke" ? console.warn(`"${t}": Element "${e.name}" already contains "vector-effect" property. Please remove it, so it can scale correctly. This element will not be transformed.`) : e.attributes["vector-effect"] = "non-scaling-stroke";
79
+ }
80
+ const te = {
81
+ fill: !0,
82
+ stroke: !0,
83
+ "stop-color": !0
84
+ }, M = {
85
+ none: !0,
86
+ transparent: !0,
87
+ currentColor: !0
88
+ }, de = [
89
+ "url",
90
+ "source",
91
+ "source-data-uri",
92
+ "base64",
93
+ "base64-data-uri"
94
+ ];
95
+ function X(e, t, i, a = !1) {
96
+ if (!e || typeof e != "string") return "";
97
+ let o = "stylesheet";
98
+ a && (e = `{${e}}`, o = "block");
99
+ const u = !a && i.length;
100
+ let n = [], f = [], L = !1;
101
+ const y = css_tree.parse(e, { context: o });
102
+ return css_tree.walk(y, {
103
+ visit: u ? void 0 : "Declaration",
104
+ enter: function(p) {
105
+ if (p.__SKIP_SVG_LOADER__ || this.rule?.__SKIP_SVG_LOADER__) return;
106
+ if (u) {
107
+ if (p.type === "SelectorList") {
108
+ n = [], f = [], L = !1;
109
+ return;
110
+ }
111
+ if (p.type === "Selector") {
112
+ const c = css_tree.generate(p);
113
+ let h = !1;
114
+ for (const s of i) if (ee(s, c)) {
115
+ h = !0, p.__ORIG_COLOR__ = !0;
116
+ break;
117
+ }
118
+ (h ? n : f).push(c);
119
+ return;
120
+ }
121
+ }
122
+ if (p.type !== "Declaration" || !te[p.property]) return;
123
+ const R = p.value?.children?.first, l = R?.value || R?.name;
124
+ if (!(!l || M[l])) {
125
+ if (u && !L && this.rule?.prelude.type === "SelectorList") {
126
+ const c = css_tree.clone(this.rule);
127
+ c.__SKIP_SVG_LOADER__ = !0;
128
+ const h = new css_tree.List(), s = this.rule.prelude.children;
129
+ s.forEach((m, d) => {
130
+ m.__ORIG_COLOR__ && (s.remove(d), h.push(m));
131
+ }), c.prelude.children = h;
132
+ const O = this.atrule?.block?.children || this.stylesheet?.children;
133
+ let k;
134
+ O?.some((m, d) => m === this.rule ? (k = d, !0) : !1), k ? O?.insertData(c, k) : O?.push(c), L = !0;
135
+ }
136
+ p.value = css_tree.parse(F(css_tree.generate(p.value), t), { context: "value" });
137
+ }
138
+ }
139
+ }), css_tree.generate(y);
140
+ }
141
+ const _e = {
142
+ circle: !0,
143
+ ellipse: !0,
144
+ path: !0,
145
+ polygon: !0,
146
+ polyline: !0,
147
+ rect: !0,
148
+ text: !0,
149
+ textPath: !0,
150
+ tref: !0,
151
+ tspan: !0
152
+ }, re = { ...te };
153
+ delete re.fill;
154
+ function Se(e, t, i, a) {
155
+ if (e.name === "style") {
156
+ const n = e.children[0], f = X(n?.value, i, a, !1);
157
+ f && (n.value = f);
158
+ } else {
159
+ const n = X(e.attributes.style, i, a, !0);
160
+ n && (e.attributes.style = n);
161
+ }
162
+ const o = e.name === "svg", u = e.attributes.fill;
163
+ o && u && (t = !0), (o && t || !o && !t && _e[e.name]) && !M[u] && (e.attributes.fill = F(u, i));
164
+ for (const n in re) {
165
+ const f = e.attributes[n];
166
+ f && !M[f] && (e.attributes[n] = F(f, i));
167
+ }
168
+ return t;
169
+ }
170
+ const Ce = {
171
+ tempDir: ".temp",
172
+ preserveLineWidthList: [],
173
+ skipPreserveLineWidthList: [],
174
+ skipPreserveLineWidthSelectors: [],
175
+ setCurrentColorList: [],
176
+ skipSetCurrentColorList: [],
177
+ skipSetCurrentColorSelectors: [],
178
+ replaceColorsList: [],
179
+ skipReplaceColorsList: [],
180
+ skipReplaceColorsSelectors: [],
181
+ skipTransformsList: [],
182
+ skipTransformsSelectors: [],
183
+ skipFilesList: [],
184
+ defaultImport: "source",
185
+ urlImportsInLibraryMode: "source-data-uri"
186
+ };
187
+ function ke(e = {}) {
188
+ const t = {
189
+ ...Ce,
190
+ ...e
191
+ };
192
+ if (t.tempDir = t.tempDir.replaceAll("\\", "/"), t.tempDir.startsWith("/") || t.tempDir.startsWith("./") || t.tempDir.indexOf(":/") !== -1) throw new Error(`"tempDir" option must be in format "path/to/temp/dir",i.e. it shouldn't be an absolute path, or start with "./".It'll be resolved to the project's root by the plugin.`);
193
+ t.tempDir.endsWith("/") && (t.tempDir = t.tempDir.substring(0, t.tempDir.length - 1)), t.tempDir = "/" + t.tempDir;
194
+ let i = !1, a = !1, o = "", u = "";
195
+ const n = e.setCurrentColorList || t.replaceColorsList, f = [], L = [], y = {
196
+ files: [/.*/],
197
+ replacements: {},
198
+ default: ""
199
+ };
200
+ let p = !1;
201
+ for (const l of n) {
202
+ if (typeof l == "string" || l instanceof RegExp) {
203
+ L.push({
204
+ files: [l],
205
+ replacements: {},
206
+ default: "currentColor"
207
+ });
208
+ continue;
209
+ }
210
+ if (l.files instanceof Array) {
211
+ f.push(l);
212
+ continue;
213
+ }
214
+ for (const c in l) p = !0, y.replacements[c] = l[c];
215
+ }
216
+ const R = [...f, ...L];
217
+ return p && R.push(y), {
218
+ name: "vite-awesome-svg-loader",
219
+ enforce: "pre",
220
+ config(l, { command: c }) {
221
+ i = c === "build";
222
+ },
223
+ configResolved(l) {
224
+ a = !!l.build.lib, o = H(l.root), u = H(l.base);
225
+ },
226
+ configureServer(l) {
227
+ l.httpServer?.on("close", async () => {
228
+ i || await (0, node_fs_promises.rm)(o + t.tempDir, {
229
+ force: !0,
230
+ recursive: !0
231
+ });
232
+ });
233
+ },
234
+ async load(l) {
235
+ const h = l.indexOf(".svg");
236
+ if (h === -1) return null;
237
+ let s = l.substring(0, h + 4).replaceAll("\\", "/");
238
+ s.startsWith(o) && (s = s.substring(o.length)), s.startsWith("/") || (s = "/" + s);
239
+ const k = (l.split("?", 2)[1] || "").split("&"), m = {};
240
+ for (const r of k) {
241
+ const [b, D] = r.split("=");
242
+ m[b.toLowerCase()] = D || "1";
243
+ }
244
+ if (E(s, m["skip-awesome-svg-loader"], t.skipFilesList)) return null;
245
+ const d = E(s, m["skip-transforms"], t.skipTransformsList), I = !d && E(s, m["preserve-line-width"], t.preserveLineWidthList) && !E(s, void 0, t.skipPreserveLineWidthList), G = A(s, t.skipPreserveLineWidthSelectors, !I);
246
+ let g = !1;
247
+ const C = {
248
+ replacements: {},
249
+ default: void 0
250
+ };
251
+ if (!d && !E(s, void 0, e.skipSetCurrentColorList || t.skipReplaceColorsList)) {
252
+ if (Z(m["set-current-color"])) C.default = "currentColor", g = !0;
253
+ else for (const r of R) if ($(s, r.files)) {
254
+ g = !0, C.default === void 0 && r.default !== void 0 && (C.default = r.default);
255
+ for (const b in r.replacements) C.replacements[b] ||= r.replacements[b];
256
+ }
257
+ }
258
+ C.default ??= "currentColor";
259
+ const P = A(s, e.skipSetCurrentColorSelectors || t.skipReplaceColorsSelectors, !g), w = A(s, t.skipTransformsSelectors, d), x = [s];
260
+ for (const r of [
261
+ G,
262
+ P,
263
+ w
264
+ ]) x.push(r.join(","));
265
+ for (const r of [
266
+ d,
267
+ I,
268
+ g
269
+ ]) x.push(r ? "1" : "0");
270
+ g && x.push(JSON.stringify(C));
271
+ const se = new imurmurhash.default(x.join("__")).result(), V = `${path.default.basename(s).split(".")[0]}-${se}`, j = V + ".svg", oe = path.default.dirname(s) + "/" + j, B = o + s;
272
+ let _ = (await (0, node_fs_promises.readFile)(B)).toString(), q = !1;
273
+ const z = [], K = V + "__";
274
+ let U = !1;
275
+ _ = (0, svgo.optimize)(_, {
276
+ multipass: !0,
277
+ plugins: [{
278
+ name: "prefixIds",
279
+ params: {
280
+ prefixIds: !0,
281
+ prefixClassNames: !0,
282
+ prefix: K,
283
+ delim: ""
284
+ }
285
+ }, {
286
+ name: "awesome-svg-loader",
287
+ fn: () => U ? null : (U = !0, {
288
+ root: { enter: (r) => {
289
+ for (const b of [P, w]) for (const D of b) z.push(...(0, svgo_lib_xast_js.querySelectorAll)(r, D));
290
+ } },
291
+ element: { enter: (r) => {
292
+ W(r, w) || (I && !W(r, G) && he(r, B), g && !W(r, P) && (q = Se(r, q, C, z)));
293
+ } }
294
+ })
295
+ }]
296
+ }).data;
297
+ let T = t.defaultImport;
298
+ for (const r of de) m[r] && (T = r);
299
+ a && T === "url" && t.urlImportsInLibraryMode !== "emit-files" && (T = t.urlImportsInLibraryMode);
300
+ const v = (r) => [
301
+ `export const src = ${r};`,
302
+ `export const prefix = "${K}"`,
303
+ "export default src"
304
+ ].join(`
305
+ `);
306
+ switch (T) {
307
+ case "source": return v("`" + J(_) + "`");
308
+ case "source-data-uri": return v("`data:image/svg+xml," + encodeURIComponent(_) + "`");
309
+ case "base64": return v("`" + J(Q(_)) + "`");
310
+ case "base64-data-uri": return v("`data:image/svg+xml;base64," + encodeURIComponent(Q(_)) + "`");
311
+ }
312
+ if (!i) {
313
+ const r = t.tempDir + oe;
314
+ return await (0, node_fs_promises.writeFile)(o + r, _), v(`"${u + r}"`);
315
+ }
316
+ return v(`"__VITE_ASSET__${this.emitFile({
317
+ type: "asset",
318
+ name: j,
319
+ source: _
320
+ })}__"`);
321
+ }
322
+ };
323
+ }
324
+
325
+ //#endregion
326
+ exports.viteAwesomeSvgLoader = ke;