vite-plugin-svg-sprite 0.2.2 → 0.2.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/es/index.d.ts CHANGED
@@ -5,5 +5,5 @@ export interface SvgSpriteOptions {
5
5
  symbolId?: string;
6
6
  svgo?: boolean | SvgoOptions;
7
7
  }
8
- declare const _default: (options?: SvgSpriteOptions | undefined) => Plugin;
8
+ declare const _default: (options?: SvgSpriteOptions) => Plugin;
9
9
  export default _default;
package/es/index.js CHANGED
@@ -42,7 +42,7 @@ export default (options) => {
42
42
  path: filepath,
43
43
  });
44
44
  return `
45
- import addSymbol from 'vite-plugin-svg-sprite/es/runtime';
45
+ import addSymbol from 'vite-plugin-svg-sprite/runtime';
46
46
  addSymbol(${stringify(symbol.render())}, ${stringify(id)});
47
47
  export default ${stringify(id)};
48
48
  `;
package/es/runtime.js CHANGED
@@ -1,23 +1,21 @@
1
- import domReady from 'domready';
2
- const doc = document;
3
1
  const idSet = window._SVG_SPRITE_IDS_ = window._SVG_SPRITE_IDS_ || [];
4
- let root = null;
5
- function getSVGRoot() {
6
- if (!root) {
7
- root = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
8
- root.style.position = 'absolute';
9
- root.style.width = '0';
10
- root.style.height = '0';
11
- doc.body.insertBefore(root, doc.body.firstChild);
12
- }
13
- return root;
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
14
  }
15
15
  export default function addSymbol(symbol, id) {
16
- if (idSet.indexOf(id) > -1 || doc.getElementById(id)) {
16
+ if (idSet.indexOf(id) > -1 || document.getElementById(id)) {
17
17
  console.warn(`Icon #${id} was duplicately registered. It must be globally unique.`);
18
18
  }
19
19
  idSet.push(id);
20
- domReady(() => {
21
- getSVGRoot().insertAdjacentHTML('beforeend', symbol);
22
- });
20
+ root.insertAdjacentHTML('beforeend', symbol);
23
21
  }
package/lib/index.d.ts CHANGED
@@ -5,5 +5,5 @@ export interface SvgSpriteOptions {
5
5
  symbolId?: string;
6
6
  svgo?: boolean | SvgoOptions;
7
7
  }
8
- declare const _default: (options?: SvgSpriteOptions | undefined) => Plugin;
8
+ declare const _default: (options?: SvgSpriteOptions) => Plugin;
9
9
  export default _default;
package/lib/index.js CHANGED
@@ -47,7 +47,7 @@ exports.default = (options) => {
47
47
  path: filepath,
48
48
  });
49
49
  return `
50
- import addSymbol from 'vite-plugin-svg-sprite/es/runtime';
50
+ import addSymbol from 'vite-plugin-svg-sprite/runtime';
51
51
  addSymbol(${stringify(symbol.render())}, ${stringify(id)});
52
52
  export default ${stringify(id)};
53
53
  `;
package/lib/runtime.js CHANGED
@@ -1,29 +1,24 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const domready_1 = __importDefault(require("domready"));
7
- const doc = document;
8
3
  const idSet = window._SVG_SPRITE_IDS_ = window._SVG_SPRITE_IDS_ || [];
9
- let root = null;
10
- function getSVGRoot() {
11
- if (!root) {
12
- root = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
13
- root.style.position = 'absolute';
14
- root.style.width = '0';
15
- root.style.height = '0';
16
- doc.body.insertBefore(root, doc.body.firstChild);
17
- }
18
- return root;
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();
19
16
  }
20
17
  function addSymbol(symbol, id) {
21
- if (idSet.indexOf(id) > -1 || doc.getElementById(id)) {
18
+ if (idSet.indexOf(id) > -1 || document.getElementById(id)) {
22
19
  console.warn(`Icon #${id} was duplicately registered. It must be globally unique.`);
23
20
  }
24
21
  idSet.push(id);
25
- domready_1.default(() => {
26
- getSVGRoot().insertAdjacentHTML('beforeend', symbol);
27
- });
22
+ root.insertAdjacentHTML('beforeend', symbol);
28
23
  }
29
24
  exports.default = addSymbol;
package/package.json CHANGED
@@ -1,8 +1,19 @@
1
1
  {
2
2
  "name": "vite-plugin-svg-sprite",
3
- "version": "0.2.2",
3
+ "version": "0.2.5",
4
4
  "description": "SVG sprite plugin for Vite",
5
5
  "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./es/index.js",
10
+ "require": "./lib/index.js"
11
+ },
12
+ "./runtime": {
13
+ "import": "./es/runtime.js",
14
+ "require": "./lib/runtime.js"
15
+ }
16
+ },
6
17
  "files": [
7
18
  "lib",
8
19
  "es",
@@ -27,21 +38,20 @@
27
38
  "devDependencies": {
28
39
  "@types/micromatch": "^4.0.1",
29
40
  "@types/node": "^14.14.21",
41
+ "@types/svgo": "^1.3.3",
30
42
  "@typescript-eslint/eslint-plugin": "^4.8.2",
31
43
  "eslint": "^7.14.0",
32
44
  "eslint-config-airbnb-typescript": "^12.0.0",
33
45
  "eslint-plugin-import": "^2.22.1",
34
46
  "typescript": "^4.1.2",
35
- "vite": "^2.0.0-beta.30"
47
+ "vite": "^2.3.6"
36
48
  },
37
49
  "dependencies": {
38
- "@types/svgo": "^1.3.3",
39
- "domready": "^1.0.8",
40
50
  "micromatch": "^4.0.2",
41
51
  "svg-baker": "~1.7.0",
42
52
  "svgo": "^1.3.2"
43
53
  },
44
54
  "peerDependencies": {
45
- "vite": "2"
55
+ "vite": "^2 || ^3"
46
56
  }
47
57
  }
package/src/index.ts CHANGED
@@ -59,7 +59,7 @@ export default (options?: SvgSpriteOptions) => {
59
59
  });
60
60
 
61
61
  return `
62
- import addSymbol from 'vite-plugin-svg-sprite/es/runtime';
62
+ import addSymbol from 'vite-plugin-svg-sprite/runtime';
63
63
  addSymbol(${stringify(symbol.render())}, ${stringify(id)});
64
64
  export default ${stringify(id)};
65
65
  `;
package/src/runtime.ts CHANGED
@@ -1,30 +1,25 @@
1
- import domReady from 'domready';
2
-
3
- const doc = document;
4
-
5
1
  const idSet = (window as any)._SVG_SPRITE_IDS_ = (window as any)._SVG_SPRITE_IDS_ || [];
6
2
 
7
- let root: SVGSVGElement | null = null;
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';
8
7
 
9
- function getSVGRoot() {
10
- if (!root) {
11
- root = document.createElementNS('http://www.w3.org/2000/svg', 'svg') as SVGSVGElement;
12
- root.style.position = 'absolute';
13
- root.style.width = '0';
14
- root.style.height = '0';
15
- doc.body.insertBefore(root, doc.body.firstChild);
16
- }
8
+ function insertRoot() {
9
+ document.body.insertBefore(root, document.body.firstChild);
10
+ }
17
11
 
18
- return root;
12
+ if (document.readyState === 'loading') {
13
+ document.addEventListener('DOMContentLoaded', insertRoot);
14
+ } else {
15
+ insertRoot();
19
16
  }
20
17
 
21
18
  export default function addSymbol(symbol: string, id: string) {
22
- if (idSet.indexOf(id) > -1 || doc.getElementById(id)) {
19
+ if (idSet.indexOf(id) > -1 || document.getElementById(id)) {
23
20
  console.warn(`Icon #${id} was duplicately registered. It must be globally unique.`);
24
21
  }
25
22
  idSet.push(id);
26
23
 
27
- domReady(() => {
28
- getSVGRoot().insertAdjacentHTML('beforeend', symbol);
29
- });
24
+ root.insertAdjacentHTML('beforeend', symbol);
30
25
  }
package/es/dom-ready.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare type Listener = () => void;
2
- export default function ready(listener: Listener): void;
3
- export {};
package/es/dom-ready.js DELETED
@@ -1,15 +0,0 @@
1
- let listeners = null;
2
- export default function ready(listener) {
3
- const complete = document.readyState === 'complete';
4
- if (complete) {
5
- setTimeout(listener, 0);
6
- return;
7
- }
8
- if (!listeners) {
9
- listeners = [];
10
- document.addEventListener('DOMContentLoaded', () => {
11
- listeners === null || listeners === void 0 ? void 0 : listeners.forEach((fn) => fn());
12
- });
13
- }
14
- listeners.push(listener);
15
- }
package/es/ready.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare type Listener = () => void;
2
- export default function ready(listener: Listener): void;
3
- export {};
package/es/ready.js DELETED
@@ -1,15 +0,0 @@
1
- let listeners = null;
2
- export default function ready(listener) {
3
- const complete = document.readyState === 'complete';
4
- if (complete) {
5
- setTimeout(listener, 0);
6
- return;
7
- }
8
- if (!listeners) {
9
- listeners = [];
10
- document.addEventListener('DOMContentLoaded', () => {
11
- listeners === null || listeners === void 0 ? void 0 : listeners.forEach(fn => fn());
12
- });
13
- }
14
- listeners.push(listener);
15
- }
@@ -1,3 +0,0 @@
1
- declare type Listener = () => void;
2
- export default function ready(listener: Listener): void;
3
- export {};
package/lib/dom-ready.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- let listeners = null;
4
- function ready(listener) {
5
- const complete = document.readyState === 'complete';
6
- if (complete) {
7
- setTimeout(listener, 0);
8
- return;
9
- }
10
- if (!listeners) {
11
- listeners = [];
12
- document.addEventListener('DOMContentLoaded', () => {
13
- listeners === null || listeners === void 0 ? void 0 : listeners.forEach((fn) => fn());
14
- });
15
- }
16
- listeners.push(listener);
17
- }
18
- exports.default = ready;
package/lib/ready.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare type Listener = () => void;
2
- export default function ready(listener: Listener): void;
3
- export {};
package/lib/ready.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- let listeners = null;
4
- function ready(listener) {
5
- const complete = document.readyState === 'complete';
6
- if (complete) {
7
- setTimeout(listener, 0);
8
- return;
9
- }
10
- if (!listeners) {
11
- listeners = [];
12
- document.addEventListener('DOMContentLoaded', () => {
13
- listeners === null || listeners === void 0 ? void 0 : listeners.forEach(fn => fn());
14
- });
15
- }
16
- listeners.push(listener);
17
- }
18
- exports.default = ready;