gulp-stacksvg 5.0.1 → 6.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.
- package/lib/index.js +18 -38
- package/package.json +51 -53
package/lib/index.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import { createHmac } from "node:crypto"
|
|
2
|
-
import { Transform } from "node:stream"
|
|
3
2
|
import { basename, extname, sep } from "node:path"
|
|
3
|
+
import { Transform } from "node:stream"
|
|
4
4
|
|
|
5
5
|
import { parse } from "node-html-parser"
|
|
6
6
|
import PluginError from "plugin-error"
|
|
7
7
|
import Vinyl from "vinyl"
|
|
8
8
|
|
|
9
|
-
// TODO: Remove this when vinyl-fs removes the deprecated fs.Stats constructor.
|
|
10
|
-
process.emitWarning = (warning, type) => {
|
|
11
|
-
if (type === `DeprecationWarning` && warning === `fs.Stats constructor is deprecated.`) return
|
|
12
|
-
|
|
13
|
-
return process.emitWarning(warning, type)
|
|
14
|
-
}
|
|
15
|
-
// See: https://github.com/gulpjs/vinyl-fs/issues/356
|
|
16
|
-
|
|
17
9
|
let excessAttrs = [
|
|
18
10
|
`enable-background`,
|
|
19
11
|
`height`,
|
|
@@ -47,13 +39,9 @@ export function stacksvg () {
|
|
|
47
39
|
* @param {function} cb - Callback function.
|
|
48
40
|
*/
|
|
49
41
|
function transform (file, _, cb) {
|
|
50
|
-
if (file.isStream())
|
|
51
|
-
return cb(new PluginError(`gulp-stacksvg`, `Streams are not supported!`))
|
|
52
|
-
}
|
|
42
|
+
if (file.isStream()) return cb(new PluginError(`gulp-stacksvg`, `Streams are not supported!`))
|
|
53
43
|
|
|
54
|
-
if (file.isNull() || !parse(file.contents.toString()).querySelector(`svg`))
|
|
55
|
-
return cb()
|
|
56
|
-
}
|
|
44
|
+
if (file.isNull() || !parse(file.contents.toString()).querySelector(`svg`)) return cb()
|
|
57
45
|
|
|
58
46
|
let iconDom = parse(file.contents.toString()).removeWhitespace()
|
|
59
47
|
let iconSvg = iconDom.querySelector(`svg`)
|
|
@@ -65,9 +53,7 @@ export function stacksvg () {
|
|
|
65
53
|
extname(file.relative),
|
|
66
54
|
)
|
|
67
55
|
|
|
68
|
-
if (iconId in ids) {
|
|
69
|
-
return cb(new PluginError(`gulp-stacksvg`, `File name should be unique: ${iconId}`))
|
|
70
|
-
}
|
|
56
|
+
if (iconId in ids) return cb(new PluginError(`gulp-stacksvg`, `File name should be unique: ${iconId}`))
|
|
71
57
|
|
|
72
58
|
ids[iconId] = true
|
|
73
59
|
iconSvg.setAttribute(`id`, iconId)
|
|
@@ -76,9 +62,7 @@ export function stacksvg () {
|
|
|
76
62
|
let widthAttr = iconSvg.getAttribute(`width`)?.replace(/[^0-9]/g, ``)
|
|
77
63
|
let heightAttr = iconSvg.getAttribute(`height`)?.replace(/[^0-9]/g, ``)
|
|
78
64
|
|
|
79
|
-
if (!viewBoxAttr && widthAttr && heightAttr) {
|
|
80
|
-
iconSvg.setAttribute(`viewBox`, `0 0 ${widthAttr} ${heightAttr}`)
|
|
81
|
-
}
|
|
65
|
+
if (!viewBoxAttr && widthAttr && heightAttr) iconSvg.setAttribute(`viewBox`, `0 0 ${widthAttr} ${heightAttr}`)
|
|
82
66
|
|
|
83
67
|
excessAttrs.forEach((attr) => iconSvg.removeAttribute(attr))
|
|
84
68
|
iconSvg.querySelectorAll(`[id]`).forEach(changeInnerId)
|
|
@@ -102,13 +86,13 @@ export function stacksvg () {
|
|
|
102
86
|
* @param {Element} elem - Child element to update.
|
|
103
87
|
*/
|
|
104
88
|
function updateUsingId (elem) {
|
|
105
|
-
if (
|
|
106
|
-
// eslint-disable-next-line guard-for-in
|
|
107
|
-
for (let attr in elem._attrs) {
|
|
108
|
-
let attrValue = elem._attrs[attr].replace(`#${oldId}`, `#${newId}`)
|
|
89
|
+
if (elem.rawAttrs.search(`#${oldId}`) === -1) return
|
|
109
90
|
|
|
110
|
-
|
|
111
|
-
|
|
91
|
+
for (let attr in elem._attrs) {
|
|
92
|
+
if (!Object.hasOwn(elem._attrs, attr)) continue
|
|
93
|
+
|
|
94
|
+
let attrValue = elem._attrs[attr].replace(`#${oldId}`, `#${newId}`)
|
|
95
|
+
elem.setAttribute(attr, attrValue)
|
|
112
96
|
}
|
|
113
97
|
}
|
|
114
98
|
}
|
|
@@ -126,10 +110,12 @@ export function stacksvg () {
|
|
|
126
110
|
newNsAlias = namespaces.get(nsId).slice(6)
|
|
127
111
|
changeNsAlias(iconDom, oldNsAlias, newNsAlias)
|
|
128
112
|
}
|
|
129
|
-
}
|
|
113
|
+
}
|
|
114
|
+
else if (nsId === XLINK) {
|
|
130
115
|
newNsAlias = ``
|
|
131
116
|
changeNsAlias(iconDom, oldNsAlias, newNsAlias)
|
|
132
|
-
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
133
119
|
for (let ns of namespaces.values()) {
|
|
134
120
|
if (ns === attrName) {
|
|
135
121
|
newNsAlias = `${oldNsAlias}${getHash(nsId)}`
|
|
@@ -165,13 +151,9 @@ export function stacksvg () {
|
|
|
165
151
|
* @param {function} cb - Callback function.
|
|
166
152
|
*/
|
|
167
153
|
function flush (cb) {
|
|
168
|
-
if (isEmpty)
|
|
169
|
-
return cb()
|
|
170
|
-
}
|
|
154
|
+
if (isEmpty) return cb()
|
|
171
155
|
|
|
172
|
-
for (let [nsId, nsAttr] of namespaces)
|
|
173
|
-
rootSvg.setAttribute(nsAttr, nsId)
|
|
174
|
-
}
|
|
156
|
+
for (let [nsId, nsAttr] of namespaces) rootSvg.setAttribute(nsAttr, nsId)
|
|
175
157
|
|
|
176
158
|
let file = new Vinyl({ path: `stack.svg`, contents: Buffer.from(stack.toString()) })
|
|
177
159
|
|
|
@@ -197,9 +179,7 @@ function changeNsAlias (iconDom, oldAlias, newAlias) {
|
|
|
197
179
|
iconDom.querySelectorAll(`*`).forEach((elem) => {
|
|
198
180
|
let prefix = newAlias === `` ? `` : `${newAlias}:`
|
|
199
181
|
|
|
200
|
-
if (elem.rawTagName.startsWith(`${oldAlias}:`)) {
|
|
201
|
-
elem.rawTagName = `${prefix}${elem.rawTagName.slice((oldAlias.length + 1))}`
|
|
202
|
-
}
|
|
182
|
+
if (elem.rawTagName.startsWith(`${oldAlias}:`)) elem.rawTagName = `${prefix}${elem.rawTagName.slice((oldAlias.length + 1))}`
|
|
203
183
|
|
|
204
184
|
for (let name of Object.keys(elem._attrs)) {
|
|
205
185
|
if (name.startsWith(`${oldAlias}:`)) {
|
package/package.json
CHANGED
|
@@ -1,54 +1,52 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
}
|
|
2
|
+
"name": "gulp-stacksvg",
|
|
3
|
+
"description": "The gulp plugin to combine svg files into one using the stack method.",
|
|
4
|
+
"version": "6.0.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Sergey Artemov",
|
|
8
|
+
"email": "firefoxic.dev@gmail.com"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/firefoxic/gulp-stacksvg#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/firefoxic/gulp-stacksvg/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git://github.com/firefoxic/gulp-stacksvg.git"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": "./lib/index.js",
|
|
20
|
+
"files": [
|
|
21
|
+
"./lib/"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22.22"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"node-html-parser": "^7.0.2",
|
|
28
|
+
"plugin-error": "^2.0.1",
|
|
29
|
+
"vinyl": "^3.0.1"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"help": "make help",
|
|
33
|
+
"eslint": "eslint"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"gulp": "^5.0.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@firefoxic/eslint-config": "^6.0.1",
|
|
40
|
+
"eslint": "^9.39.2",
|
|
41
|
+
"gulp": "^5.0.1"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"gulp",
|
|
45
|
+
"gulpplugin",
|
|
46
|
+
"svg",
|
|
47
|
+
"icon",
|
|
48
|
+
"sprite",
|
|
49
|
+
"stack",
|
|
50
|
+
"vector"
|
|
51
|
+
]
|
|
52
|
+
}
|