vite-plugin-svg-sprite 0.4.0 → 0.5.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/cjs/index.d.ts CHANGED
@@ -6,5 +6,5 @@ export interface SvgSpriteOptions {
6
6
  symbolId?: string;
7
7
  svgo?: boolean | SvgoOptimizeOptions;
8
8
  }
9
- declare const _default: (options?: SvgSpriteOptions) => Plugin;
9
+ declare const _default: (options?: SvgSpriteOptions) => Plugin<any>;
10
10
  export default _default;
package/cjs/runtime.d.ts CHANGED
@@ -1 +1,2 @@
1
- export default function addSymbol(symbol: string, id: string): void;
1
+ declare const _default: (symbol: string, id: string) => void;
2
+ export default _default;
package/cjs/runtime.js CHANGED
@@ -1,24 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const idSet = window._SVG_SPRITE_IDS_ = window._SVG_SPRITE_IDS_ || [];
4
- const root = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
5
- root.style.position = 'absolute';
6
- root.style.width = '0';
7
- root.style.height = '0';
8
- function insertRoot() {
9
- document.body.insertBefore(root, document.body.firstChild);
10
- }
11
- if (document.readyState === 'loading') {
12
- document.addEventListener('DOMContentLoaded', insertRoot);
13
- }
14
- else {
15
- insertRoot();
16
- }
17
- function addSymbol(symbol, id) {
18
- if (idSet.indexOf(id) > -1 || document.getElementById(id)) {
19
- console.warn(`Icon #${id} was duplicately registered. It must be globally unique.`);
3
+ function createAddSymbol() {
4
+ if (typeof window === 'undefined' || typeof document === 'undefined') {
5
+ return () => { };
6
+ }
7
+ const idSet = window._SVG_SPRITE_IDS_ = window._SVG_SPRITE_IDS_ || [];
8
+ const root = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
9
+ root.style.position = 'absolute';
10
+ root.style.width = '0';
11
+ root.style.height = '0';
12
+ function insertRoot() {
13
+ document.body.insertBefore(root, document.body.firstChild);
14
+ }
15
+ if (document.readyState === 'loading') {
16
+ document.addEventListener('DOMContentLoaded', insertRoot);
17
+ }
18
+ else {
19
+ insertRoot();
20
20
  }
21
- idSet.push(id);
22
- root.insertAdjacentHTML('beforeend', symbol);
21
+ return function addSymbol(symbol, id) {
22
+ if (idSet.indexOf(id) > -1 || document.getElementById(id)) {
23
+ console.warn(`Icon #${id} was duplicately registered. It must be globally unique.`);
24
+ }
25
+ idSet.push(id);
26
+ root.insertAdjacentHTML('beforeend', symbol);
27
+ };
23
28
  }
24
- exports.default = addSymbol;
29
+ exports.default = createAddSymbol();
package/esm/index.d.ts CHANGED
@@ -6,5 +6,5 @@ export interface SvgSpriteOptions {
6
6
  symbolId?: string;
7
7
  svgo?: boolean | SvgoOptimizeOptions;
8
8
  }
9
- declare const _default: (options?: SvgSpriteOptions) => Plugin;
9
+ declare const _default: (options?: SvgSpriteOptions) => Plugin<any>;
10
10
  export default _default;
package/esm/runtime.d.ts CHANGED
@@ -1 +1,2 @@
1
- export default function addSymbol(symbol: string, id: string): void;
1
+ declare const _default: (symbol: string, id: string) => void;
2
+ export default _default;
package/esm/runtime.js CHANGED
@@ -1,21 +1,27 @@
1
- const idSet = window._SVG_SPRITE_IDS_ = window._SVG_SPRITE_IDS_ || [];
2
- const root = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
3
- root.style.position = 'absolute';
4
- root.style.width = '0';
5
- root.style.height = '0';
6
- function insertRoot() {
7
- document.body.insertBefore(root, document.body.firstChild);
8
- }
9
- if (document.readyState === 'loading') {
10
- document.addEventListener('DOMContentLoaded', insertRoot);
11
- }
12
- else {
13
- insertRoot();
14
- }
15
- export default function addSymbol(symbol, id) {
16
- if (idSet.indexOf(id) > -1 || document.getElementById(id)) {
17
- console.warn(`Icon #${id} was duplicately registered. It must be globally unique.`);
1
+ function createAddSymbol() {
2
+ if (typeof window === 'undefined' || typeof document === 'undefined') {
3
+ return () => { };
4
+ }
5
+ const idSet = window._SVG_SPRITE_IDS_ = window._SVG_SPRITE_IDS_ || [];
6
+ const root = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
7
+ root.style.position = 'absolute';
8
+ root.style.width = '0';
9
+ root.style.height = '0';
10
+ function insertRoot() {
11
+ document.body.insertBefore(root, document.body.firstChild);
12
+ }
13
+ if (document.readyState === 'loading') {
14
+ document.addEventListener('DOMContentLoaded', insertRoot);
15
+ }
16
+ else {
17
+ insertRoot();
18
18
  }
19
- idSet.push(id);
20
- root.insertAdjacentHTML('beforeend', symbol);
19
+ return function addSymbol(symbol, id) {
20
+ if (idSet.indexOf(id) > -1 || document.getElementById(id)) {
21
+ console.warn(`Icon #${id} was duplicately registered. It must be globally unique.`);
22
+ }
23
+ idSet.push(id);
24
+ root.insertAdjacentHTML('beforeend', symbol);
25
+ };
21
26
  }
27
+ export default createAddSymbol();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-svg-sprite",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "SVG sprite plugin for Vite",
5
5
  "type": "module",
6
6
  "exports": {
@@ -41,7 +41,7 @@
41
41
  "scripts": {
42
42
  "lint": "eslint src",
43
43
  "build": "rm -rf cjs esm && tsc && npx tsc -m commonjs --outDir cjs && cp ./package-cjs.json cjs/package.json",
44
- "prepublish": "npm run build"
44
+ "prepublishOnly": "npm run build"
45
45
  },
46
46
  "keywords": [
47
47
  "vite",
@@ -74,6 +74,6 @@
74
74
  "svgo": "^3.0.2"
75
75
  },
76
76
  "peerDependencies": {
77
- "vite": "^2 || ^3 || ^4"
77
+ "vite": "^2 || ^3 || ^4 || ^5"
78
78
  }
79
79
  }
package/src/runtime.ts CHANGED
@@ -1,25 +1,33 @@
1
- const idSet = (window as any)._SVG_SPRITE_IDS_ = (window as any)._SVG_SPRITE_IDS_ || [];
1
+ function createAddSymbol() {
2
+ if (typeof window === 'undefined' || typeof document === 'undefined') {
3
+ return () => {};
4
+ }
2
5
 
3
- const root = document.createElementNS('http://www.w3.org/2000/svg', 'svg') as SVGSVGElement;
4
- root.style.position = 'absolute';
5
- root.style.width = '0';
6
- root.style.height = '0';
6
+ const idSet = (window as any)._SVG_SPRITE_IDS_ = (window as any)._SVG_SPRITE_IDS_ || [];
7
7
 
8
- function insertRoot() {
9
- document.body.insertBefore(root, document.body.firstChild);
10
- }
8
+ const root = document.createElementNS('http://www.w3.org/2000/svg', 'svg') as SVGSVGElement;
9
+ root.style.position = 'absolute';
10
+ root.style.width = '0';
11
+ root.style.height = '0';
11
12
 
12
- if (document.readyState === 'loading') {
13
- document.addEventListener('DOMContentLoaded', insertRoot);
14
- } else {
15
- insertRoot();
16
- }
13
+ function insertRoot() {
14
+ document.body.insertBefore(root, document.body.firstChild);
15
+ }
17
16
 
18
- export default function addSymbol(symbol: string, id: string) {
19
- if (idSet.indexOf(id) > -1 || document.getElementById(id)) {
20
- console.warn(`Icon #${id} was duplicately registered. It must be globally unique.`);
17
+ if (document.readyState === 'loading') {
18
+ document.addEventListener('DOMContentLoaded', insertRoot);
19
+ } else {
20
+ insertRoot();
21
21
  }
22
- idSet.push(id);
23
22
 
24
- root.insertAdjacentHTML('beforeend', symbol);
23
+ return function addSymbol(symbol: string, id: string) {
24
+ if (idSet.indexOf(id) > -1 || document.getElementById(id)) {
25
+ console.warn(`Icon #${id} was duplicately registered. It must be globally unique.`);
26
+ }
27
+ idSet.push(id);
28
+
29
+ root.insertAdjacentHTML('beforeend', symbol);
30
+ };
25
31
  }
32
+
33
+ export default createAddSymbol();