vite-plugin-svg-sprite 0.2.1 → 0.2.4

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/runtime.js CHANGED
@@ -1,35 +1,21 @@
1
- const doc = document;
2
1
  const idSet = window._SVG_SPRITE_IDS_ = window._SVG_SPRITE_IDS_ || [];
3
- let root = null;
4
- let listeners = null;
5
- function domReady(listener) {
6
- const complete = document.readyState === 'complete';
7
- if (complete) {
8
- setTimeout(listener, 0);
9
- return;
10
- }
11
- if (!listeners) {
12
- listeners = [];
13
- document.addEventListener('DOMContentLoaded', () => {
14
- listeners === null || listeners === void 0 ? void 0 : listeners.forEach((fn) => fn());
15
- });
16
- }
17
- listeners.push(listener);
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);
18
8
  }
19
- function getSVGRoot() {
20
- if (!root) {
21
- root = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
22
- root.style.display = 'none';
23
- doc.body.insertBefore(root, doc.body.firstChild);
24
- }
25
- return root;
9
+ if (document.readyState === 'loading') {
10
+ document.addEventListener('DOMContentLoaded', insertRoot);
11
+ }
12
+ else {
13
+ insertRoot();
26
14
  }
27
15
  export default function addSymbol(symbol, id) {
28
- if (idSet.indexOf(id) > -1 || doc.getElementById(id)) {
16
+ if (idSet.indexOf(id) > -1 || document.getElementById(id)) {
29
17
  console.warn(`Icon #${id} was duplicately registered. It must be globally unique.`);
30
18
  }
31
19
  idSet.push(id);
32
- domReady(() => {
33
- getSVGRoot().insertAdjacentHTML('beforeend', symbol);
34
- });
20
+ root.insertAdjacentHTML('beforeend', symbol);
35
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/runtime.js CHANGED
@@ -1,38 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const doc = document;
4
3
  const idSet = window._SVG_SPRITE_IDS_ = window._SVG_SPRITE_IDS_ || [];
5
- let root = null;
6
- let listeners = null;
7
- function domReady(listener) {
8
- const complete = document.readyState === 'complete';
9
- if (complete) {
10
- setTimeout(listener, 0);
11
- return;
12
- }
13
- if (!listeners) {
14
- listeners = [];
15
- document.addEventListener('DOMContentLoaded', () => {
16
- listeners === null || listeners === void 0 ? void 0 : listeners.forEach((fn) => fn());
17
- });
18
- }
19
- listeners.push(listener);
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);
20
10
  }
21
- function getSVGRoot() {
22
- if (!root) {
23
- root = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
24
- root.style.display = 'none';
25
- doc.body.insertBefore(root, doc.body.firstChild);
26
- }
27
- return root;
11
+ if (document.readyState === 'loading') {
12
+ document.addEventListener('DOMContentLoaded', insertRoot);
13
+ }
14
+ else {
15
+ insertRoot();
28
16
  }
29
17
  function addSymbol(symbol, id) {
30
- if (idSet.indexOf(id) > -1 || doc.getElementById(id)) {
18
+ if (idSet.indexOf(id) > -1 || document.getElementById(id)) {
31
19
  console.warn(`Icon #${id} was duplicately registered. It must be globally unique.`);
32
20
  }
33
21
  idSet.push(id);
34
- domReady(() => {
35
- getSVGRoot().insertAdjacentHTML('beforeend', symbol);
36
- });
22
+ root.insertAdjacentHTML('beforeend', symbol);
37
23
  }
38
24
  exports.default = addSymbol;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-svg-sprite",
3
- "version": "0.2.1",
3
+ "version": "0.2.4",
4
4
  "description": "SVG sprite plugin for Vite",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -27,20 +27,20 @@
27
27
  "devDependencies": {
28
28
  "@types/micromatch": "^4.0.1",
29
29
  "@types/node": "^14.14.21",
30
+ "@types/svgo": "^1.3.3",
30
31
  "@typescript-eslint/eslint-plugin": "^4.8.2",
31
32
  "eslint": "^7.14.0",
32
33
  "eslint-config-airbnb-typescript": "^12.0.0",
33
34
  "eslint-plugin-import": "^2.22.1",
34
35
  "typescript": "^4.1.2",
35
- "vite": "^2.0.0-beta.30"
36
+ "vite": "^2.3.6"
36
37
  },
37
38
  "dependencies": {
38
39
  "micromatch": "^4.0.2",
39
40
  "svg-baker": "~1.7.0",
40
- "svgo": "^1.3.2",
41
- "@types/svgo": "^1.3.3"
41
+ "svgo": "^1.3.2"
42
42
  },
43
43
  "peerDependencies": {
44
- "vite": "2"
44
+ "vite": "^2 || ^3"
45
45
  }
46
46
  }
package/src/runtime.ts CHANGED
@@ -1,48 +1,25 @@
1
- const doc = document;
2
-
3
1
  const idSet = (window as any)._SVG_SPRITE_IDS_ = (window as any)._SVG_SPRITE_IDS_ || [];
4
2
 
5
- let root: SVGSVGElement | null = null;
6
-
7
- type ReadyListener = () => void;
8
-
9
- let listeners: ReadyListener[] | null = null;
10
-
11
- function domReady(listener: ReadyListener) {
12
- const complete = document.readyState === 'complete';
13
-
14
- if (complete) {
15
- setTimeout(listener, 0);
16
- return;
17
- }
18
-
19
- if (!listeners) {
20
- listeners = [];
21
- document.addEventListener('DOMContentLoaded', () => {
22
- listeners?.forEach((fn) => fn());
23
- });
24
- }
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';
25
7
 
26
- listeners.push(listener);
8
+ function insertRoot() {
9
+ document.body.insertBefore(root, document.body.firstChild);
27
10
  }
28
11
 
29
- function getSVGRoot() {
30
- if (!root) {
31
- root = document.createElementNS('http://www.w3.org/2000/svg', 'svg') as SVGSVGElement;
32
- root.style.display = 'none';
33
- doc.body.insertBefore(root, doc.body.firstChild);
34
- }
35
-
36
- return root;
12
+ if (document.readyState === 'loading') {
13
+ document.addEventListener('DOMContentLoaded', insertRoot);
14
+ } else {
15
+ insertRoot();
37
16
  }
38
17
 
39
18
  export default function addSymbol(symbol: string, id: string) {
40
- if (idSet.indexOf(id) > -1 || doc.getElementById(id)) {
19
+ if (idSet.indexOf(id) > -1 || document.getElementById(id)) {
41
20
  console.warn(`Icon #${id} was duplicately registered. It must be globally unique.`);
42
21
  }
43
22
  idSet.push(id);
44
23
 
45
- domReady(() => {
46
- getSVGRoot().insertAdjacentHTML('beforeend', symbol);
47
- });
24
+ root.insertAdjacentHTML('beforeend', symbol);
48
25
  }