svg-toolbox 1.1.7 → 1.1.8

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/common.d.ts CHANGED
@@ -64,12 +64,12 @@ export declare function cloneSVGElement(element: Element): Element;
64
64
  */
65
65
  export declare function mergeSVGElements(elements: Element[]): Element;
66
66
  /**
67
- * Converts an SVG element to a Base64-encoded string.
67
+ * Converts an SVG element or SVG string to a Base64-encoded string.
68
68
  *
69
- * This function serializes the SVG element to a string and then encodes it to Base64.
69
+ * This function serializes the SVG element or SVG string to a string and then encodes it to Base64.
70
70
  * The resulting string can be used as a data URI for embedding SVG content in HTML or CSS.
71
71
  *
72
- * @param {Element} svgElement - The SVG element to convert.
72
+ * @param {Element | string} svgContent - The SVG element or SVG string to convert.
73
73
  * @returns {string} - The Base64-encoded string representation of the SVG element.
74
74
  *
75
75
  * @example
@@ -80,7 +80,7 @@ export declare function mergeSVGElements(elements: Element[]): Element;
80
80
  * @see https://developer.mozilla.org/en-US/docs/Web/API/XMLSerializer - XMLSerializer documentation
81
81
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Buffer - Buffer documentation
82
82
  */
83
- export declare function convertSVGToBase64(svgElement: Element): string;
83
+ export declare function convertSVGToBase64(svgContent: Element | string): string;
84
84
  /**
85
85
  * Converts a Base64-encoded string to an SVG string.
86
86
  *
package/es/common.js CHANGED
@@ -6,9 +6,11 @@
6
6
  * @author pipi
7
7
  */
8
8
  import { JSDOM } from 'jsdom';
9
+ import { isValidSvgElement, isValidSvgString } from './validate';
9
10
  // Create a virtual DOM environment
10
11
  const dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`);
11
- const { document } = dom.window;
12
+ const fakeWindow = dom.window;
13
+ const { document } = fakeWindow;
12
14
  /**
13
15
  * Creates an SVG element from a given element.
14
16
  *
@@ -30,7 +32,7 @@ const { document } = dom.window;
30
32
  * @returns
31
33
  */
32
34
  export function createSVGElement(svgContent) {
33
- const svgElement = new dom.window.DOMParser().parseFromString(svgContent, 'image/svg+xml').documentElement;
35
+ const svgElement = new fakeWindow.DOMParser().parseFromString(svgContent, 'image/svg+xml').documentElement;
34
36
  return svgElement;
35
37
  }
36
38
  /**
@@ -51,9 +53,9 @@ export function createSVGElement(svgContent) {
51
53
  * @see https://developer.mozilla.org/en-US/docs/Web/API/XMLSerializer - XMLSerializer documentation
52
54
  */
53
55
  export function cloneSVGElement(element) {
54
- const serializer = new dom.window.XMLSerializer();
56
+ const serializer = new fakeWindow.XMLSerializer();
55
57
  const sourceCode = serializer.serializeToString(element);
56
- const parser = new dom.window.DOMParser();
58
+ const parser = new fakeWindow.DOMParser();
57
59
  const doc = parser.parseFromString(sourceCode, 'image/svg+xml');
58
60
  return doc.documentElement;
59
61
  }
@@ -83,12 +85,12 @@ export function mergeSVGElements(elements) {
83
85
  return mergedSVG;
84
86
  }
85
87
  /**
86
- * Converts an SVG element to a Base64-encoded string.
88
+ * Converts an SVG element or SVG string to a Base64-encoded string.
87
89
  *
88
- * This function serializes the SVG element to a string and then encodes it to Base64.
90
+ * This function serializes the SVG element or SVG string to a string and then encodes it to Base64.
89
91
  * The resulting string can be used as a data URI for embedding SVG content in HTML or CSS.
90
92
  *
91
- * @param {Element} svgElement - The SVG element to convert.
93
+ * @param {Element | string} svgContent - The SVG element or SVG string to convert.
92
94
  * @returns {string} - The Base64-encoded string representation of the SVG element.
93
95
  *
94
96
  * @example
@@ -99,9 +101,18 @@ export function mergeSVGElements(elements) {
99
101
  * @see https://developer.mozilla.org/en-US/docs/Web/API/XMLSerializer - XMLSerializer documentation
100
102
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Buffer - Buffer documentation
101
103
  */
102
- export function convertSVGToBase64(svgElement) {
103
- const serializer = new dom.window.XMLSerializer();
104
- const svgString = serializer.serializeToString(svgElement);
104
+ export function convertSVGToBase64(svgContent) {
105
+ let svgString;
106
+ if (isValidSvgString(svgContent)) {
107
+ svgString = svgContent;
108
+ }
109
+ else if (isValidSvgElement(svgContent)) {
110
+ const serializer = new fakeWindow.XMLSerializer();
111
+ svgString = serializer.serializeToString(svgContent);
112
+ }
113
+ else {
114
+ throw new Error('The provided content is not a valid SVG string or SVG element.');
115
+ }
105
116
  return `data:image/svg+xml;base64,${Buffer.from(svgString).toString('base64')}`;
106
117
  }
107
118
  /**
@@ -122,7 +133,12 @@ export function convertSVGToBase64(svgElement) {
122
133
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Buffer - Buffer documentation
123
134
  */
124
135
  export function convertBase64ToSVG(base64String) {
125
- const svgString = Buffer.from(base64String.split(',')[1], 'base64').toString('utf-8');
126
- return svgString;
136
+ try {
137
+ const svgString = Buffer.from(base64String.split(',')[1], 'base64').toString('utf-8');
138
+ return svgString;
139
+ }
140
+ catch (error) {
141
+ throw new Error('Invalid Base64 string.');
142
+ }
127
143
  }
128
144
  //# sourceMappingURL=common.js.map
package/es/common.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,mCAAmC;AACnC,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;AACnE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAkB;IACjD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,eAAe,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,eAAe,CAAC;IAC3G,OAAO,UAAU,CAAA;AACnB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,aAAa,EAAE,CAA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,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAA4B;IAC7D,IAAI,SAAiB,CAAC;IACtB,IAAI,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;QACjC,SAAS,GAAG,UAAoB,CAAC;IACnC,CAAC;SAAM,IAAI,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC;QACzC,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,aAAa,EAAE,CAAC;QAClD,SAAS,GAAG,UAAU,CAAC,iBAAiB,CAAC,UAAqB,CAAC,CAAC;IAClE,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IACpF,CAAC;IACD,OAAO,6BAA6B,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;AAClF,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB,CAAC,YAAoB;IACrD,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACtF,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @file validate.ts
3
+ * @description This module provides functions to validate SVG content.
4
+ * @module validate
5
+ * @author pipi
6
+ */
7
+ /**
8
+ * Validates whether the provided content is a valid SVG string.
9
+ *
10
+ * @param content - The content to be validated (could be a string or another type).
11
+ * @returns True if the content is a valid SVG string, false otherwise.
12
+ */
13
+ export declare function isValidSvgString(content: any): boolean;
14
+ /**
15
+ * Validates whether the provided content is a valid SVG element.
16
+ *
17
+ * @param content - The content to be validated (could be an Element or another type).
18
+ * @returns True if the content is a valid SVG element, false otherwise.
19
+ */
20
+ export declare function isValidSvgElement(content: any): boolean;
package/es/validate.js ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @file validate.ts
3
+ * @description This module provides functions to validate SVG content.
4
+ * @module validate
5
+ * @author pipi
6
+ */
7
+ /**
8
+ * Validates whether the provided content is a valid SVG string.
9
+ *
10
+ * @param content - The content to be validated (could be a string or another type).
11
+ * @returns True if the content is a valid SVG string, false otherwise.
12
+ */
13
+ export function isValidSvgString(content) {
14
+ // Check if the content is of type string. If not, it cannot be a valid SVG string.
15
+ if (typeof content !== 'string') {
16
+ return false;
17
+ }
18
+ // Regular expression to find the <svg> opening tag in the string.
19
+ const svgRegExp = /<svg(\s+[^>]*)?>/i;
20
+ const startTag = content.match(svgRegExp);
21
+ // Check if a matching <svg> tag was found and it's in lowercase (case-insensitive check).
22
+ return !!(startTag && startTag[0].toLowerCase().includes('<svg'));
23
+ }
24
+ /**
25
+ * Validates whether the provided content is a valid SVG element.
26
+ *
27
+ * @param content - The content to be validated (could be an Element or another type).
28
+ * @returns True if the content is a valid SVG element, false otherwise.
29
+ */
30
+ export function isValidSvgElement(content) {
31
+ // Check if the content is an instance of Element and its tag name is 'svg'
32
+ return (content &&
33
+ typeof content === 'object' &&
34
+ content.tagName.toLowerCase() === 'svg' &&
35
+ content.namespaceURI === 'http://www.w3.org/2000/svg' // SVG namespace URI
36
+ );
37
+ }
38
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAY;IAC3C,mFAAmF;IACnF,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,kEAAkE;IAClE,MAAM,SAAS,GAAG,mBAAmB,CAAC;IACtC,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE1C,0FAA0F;IAC1F,OAAO,CAAC,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACpE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAY;IAC5C,2EAA2E;IAC3E,OAAO,CACL,OAAO;QACP,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,KAAK;QACvC,OAAO,CAAC,YAAY,KAAK,4BAA4B,CAAC,oBAAoB;KAC3E,CAAC;AACJ,CAAC"}
package/lib/common.d.ts CHANGED
@@ -64,12 +64,12 @@ export declare function cloneSVGElement(element: Element): Element;
64
64
  */
65
65
  export declare function mergeSVGElements(elements: Element[]): Element;
66
66
  /**
67
- * Converts an SVG element to a Base64-encoded string.
67
+ * Converts an SVG element or SVG string to a Base64-encoded string.
68
68
  *
69
- * This function serializes the SVG element to a string and then encodes it to Base64.
69
+ * This function serializes the SVG element or SVG string to a string and then encodes it to Base64.
70
70
  * The resulting string can be used as a data URI for embedding SVG content in HTML or CSS.
71
71
  *
72
- * @param {Element} svgElement - The SVG element to convert.
72
+ * @param {Element | string} svgContent - The SVG element or SVG string to convert.
73
73
  * @returns {string} - The Base64-encoded string representation of the SVG element.
74
74
  *
75
75
  * @example
@@ -80,7 +80,7 @@ export declare function mergeSVGElements(elements: Element[]): Element;
80
80
  * @see https://developer.mozilla.org/en-US/docs/Web/API/XMLSerializer - XMLSerializer documentation
81
81
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Buffer - Buffer documentation
82
82
  */
83
- export declare function convertSVGToBase64(svgElement: Element): string;
83
+ export declare function convertSVGToBase64(svgContent: Element | string): string;
84
84
  /**
85
85
  * Converts a Base64-encoded string to an SVG string.
86
86
  *
package/lib/common.js CHANGED
@@ -13,9 +13,11 @@ exports.mergeSVGElements = mergeSVGElements;
13
13
  exports.convertSVGToBase64 = convertSVGToBase64;
14
14
  exports.convertBase64ToSVG = convertBase64ToSVG;
15
15
  var jsdom_1 = require("jsdom");
16
+ var validate_1 = require("./validate");
16
17
  // Create a virtual DOM environment
17
18
  var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><body></body></html>");
18
- var document = dom.window.document;
19
+ var fakeWindow = dom.window;
20
+ var document = fakeWindow.document;
19
21
  /**
20
22
  * Creates an SVG element from a given element.
21
23
  *
@@ -37,7 +39,7 @@ var document = dom.window.document;
37
39
  * @returns
38
40
  */
39
41
  function createSVGElement(svgContent) {
40
- var svgElement = new dom.window.DOMParser().parseFromString(svgContent, 'image/svg+xml').documentElement;
42
+ var svgElement = new fakeWindow.DOMParser().parseFromString(svgContent, 'image/svg+xml').documentElement;
41
43
  return svgElement;
42
44
  }
43
45
  /**
@@ -58,9 +60,9 @@ function createSVGElement(svgContent) {
58
60
  * @see https://developer.mozilla.org/en-US/docs/Web/API/XMLSerializer - XMLSerializer documentation
59
61
  */
60
62
  function cloneSVGElement(element) {
61
- var serializer = new dom.window.XMLSerializer();
63
+ var serializer = new fakeWindow.XMLSerializer();
62
64
  var sourceCode = serializer.serializeToString(element);
63
- var parser = new dom.window.DOMParser();
65
+ var parser = new fakeWindow.DOMParser();
64
66
  var doc = parser.parseFromString(sourceCode, 'image/svg+xml');
65
67
  return doc.documentElement;
66
68
  }
@@ -90,12 +92,12 @@ function mergeSVGElements(elements) {
90
92
  return mergedSVG;
91
93
  }
92
94
  /**
93
- * Converts an SVG element to a Base64-encoded string.
95
+ * Converts an SVG element or SVG string to a Base64-encoded string.
94
96
  *
95
- * This function serializes the SVG element to a string and then encodes it to Base64.
97
+ * This function serializes the SVG element or SVG string to a string and then encodes it to Base64.
96
98
  * The resulting string can be used as a data URI for embedding SVG content in HTML or CSS.
97
99
  *
98
- * @param {Element} svgElement - The SVG element to convert.
100
+ * @param {Element | string} svgContent - The SVG element or SVG string to convert.
99
101
  * @returns {string} - The Base64-encoded string representation of the SVG element.
100
102
  *
101
103
  * @example
@@ -106,9 +108,18 @@ function mergeSVGElements(elements) {
106
108
  * @see https://developer.mozilla.org/en-US/docs/Web/API/XMLSerializer - XMLSerializer documentation
107
109
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Buffer - Buffer documentation
108
110
  */
109
- function convertSVGToBase64(svgElement) {
110
- var serializer = new dom.window.XMLSerializer();
111
- var svgString = serializer.serializeToString(svgElement);
111
+ function convertSVGToBase64(svgContent) {
112
+ var svgString;
113
+ if ((0, validate_1.isValidSvgString)(svgContent)) {
114
+ svgString = svgContent;
115
+ }
116
+ else if ((0, validate_1.isValidSvgElement)(svgContent)) {
117
+ var serializer = new fakeWindow.XMLSerializer();
118
+ svgString = serializer.serializeToString(svgContent);
119
+ }
120
+ else {
121
+ throw new Error('The provided content is not a valid SVG string or SVG element.');
122
+ }
112
123
  return "data:image/svg+xml;base64,".concat(Buffer.from(svgString).toString('base64'));
113
124
  }
114
125
  /**
@@ -129,7 +140,12 @@ function convertSVGToBase64(svgElement) {
129
140
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Buffer - Buffer documentation
130
141
  */
131
142
  function convertBase64ToSVG(base64String) {
132
- var svgString = Buffer.from(base64String.split(',')[1], 'base64').toString('utf-8');
133
- return svgString;
143
+ try {
144
+ var svgString = Buffer.from(base64String.split(',')[1], 'base64').toString('utf-8');
145
+ return svgString;
146
+ }
147
+ catch (error) {
148
+ throw new Error('Invalid Base64 string.');
149
+ }
134
150
  }
135
151
  //# sourceMappingURL=common.js.map
package/lib/common.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AA4BH,4CAGC;AAmBD,0CA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CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACtF,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @file validate.ts
3
+ * @description This module provides functions to validate SVG content.
4
+ * @module validate
5
+ * @author pipi
6
+ */
7
+ /**
8
+ * Validates whether the provided content is a valid SVG string.
9
+ *
10
+ * @param content - The content to be validated (could be a string or another type).
11
+ * @returns True if the content is a valid SVG string, false otherwise.
12
+ */
13
+ export declare function isValidSvgString(content: any): boolean;
14
+ /**
15
+ * Validates whether the provided content is a valid SVG element.
16
+ *
17
+ * @param content - The content to be validated (could be an Element or another type).
18
+ * @returns True if the content is a valid SVG element, false otherwise.
19
+ */
20
+ export declare function isValidSvgElement(content: any): boolean;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /**
3
+ * @file validate.ts
4
+ * @description This module provides functions to validate SVG content.
5
+ * @module validate
6
+ * @author pipi
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.isValidSvgString = isValidSvgString;
10
+ exports.isValidSvgElement = isValidSvgElement;
11
+ /**
12
+ * Validates whether the provided content is a valid SVG string.
13
+ *
14
+ * @param content - The content to be validated (could be a string or another type).
15
+ * @returns True if the content is a valid SVG string, false otherwise.
16
+ */
17
+ function isValidSvgString(content) {
18
+ // Check if the content is of type string. If not, it cannot be a valid SVG string.
19
+ if (typeof content !== 'string') {
20
+ return false;
21
+ }
22
+ // Regular expression to find the <svg> opening tag in the string.
23
+ var svgRegExp = /<svg(\s+[^>]*)?>/i;
24
+ var startTag = content.match(svgRegExp);
25
+ // Check if a matching <svg> tag was found and it's in lowercase (case-insensitive check).
26
+ return !!(startTag && startTag[0].toLowerCase().includes('<svg'));
27
+ }
28
+ /**
29
+ * Validates whether the provided content is a valid SVG element.
30
+ *
31
+ * @param content - The content to be validated (could be an Element or another type).
32
+ * @returns True if the content is a valid SVG element, false otherwise.
33
+ */
34
+ function isValidSvgElement(content) {
35
+ // Check if the content is an instance of Element and its tag name is 'svg'
36
+ return (content &&
37
+ typeof content === 'object' &&
38
+ content.tagName.toLowerCase() === 'svg' &&
39
+ content.namespaceURI === 'http://www.w3.org/2000/svg' // SVG namespace URI
40
+ );
41
+ }
42
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAQH,4CAYC;AAQD,8CAQC;AAlCD;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,OAAY;IAC3C,mFAAmF;IACnF,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,kEAAkE;IAClE,IAAM,SAAS,GAAG,mBAAmB,CAAC;IACtC,IAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE1C,0FAA0F;IAC1F,OAAO,CAAC,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACpE,CAAC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,OAAY;IAC5C,2EAA2E;IAC3E,OAAO,CACL,OAAO;QACP,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,KAAK;QACvC,OAAO,CAAC,YAAY,KAAK,4BAA4B,CAAC,oBAAoB;KAC3E,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svg-toolbox",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "This library provides some SVG-related tools",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",