gulp-stacksvg 4.0.0 → 5.0.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/README.md +1 -1
- package/lib/index.js +24 -16
- package/package.json +8 -9
package/README.md
CHANGED
|
@@ -149,4 +149,4 @@ For an icon inserted via `mask`, simply change the `background`. Moreover, u
|
|
|
149
149
|
[npm-image]: https://badge.fury.io/js/gulp-stacksvg.svg
|
|
150
150
|
|
|
151
151
|
[test-url]: https://github.com/firefoxic/gulp-stacksvg/actions
|
|
152
|
-
[test-image]: https://github.com/firefoxic/gulp-stacksvg/actions/workflows/test.
|
|
152
|
+
[test-image]: https://github.com/firefoxic/gulp-stacksvg/actions/workflows/test.yaml/badge.svg?branch=main
|
package/lib/index.js
CHANGED
|
@@ -6,7 +6,15 @@ import { parse } from "node-html-parser"
|
|
|
6
6
|
import PluginError from "plugin-error"
|
|
7
7
|
import Vinyl from "vinyl"
|
|
8
8
|
|
|
9
|
-
|
|
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
|
+
let excessAttrs = [
|
|
10
18
|
`enable-background`,
|
|
11
19
|
`height`,
|
|
12
20
|
`version`,
|
|
@@ -16,7 +24,7 @@ const excessAttrs = [
|
|
|
16
24
|
`y`,
|
|
17
25
|
]
|
|
18
26
|
|
|
19
|
-
const
|
|
27
|
+
const XLINK = `http://www.w3.org/1999/xlink`
|
|
20
28
|
|
|
21
29
|
/**
|
|
22
30
|
* Gulp plugin for combining SVG icons into a single file.
|
|
@@ -25,11 +33,11 @@ const xlink = `http://www.w3.org/1999/xlink`
|
|
|
25
33
|
*/
|
|
26
34
|
export function stacksvg () {
|
|
27
35
|
let isEmpty = true
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
let ids = {}
|
|
37
|
+
let namespaces = new Map([[`http://www.w3.org/2000/svg`, `xmlns`]])
|
|
38
|
+
let stack = parse(`<svg><style>:root svg:not(:target){display:none}</style></svg>`)
|
|
39
|
+
let rootSvg = stack.querySelector(`svg`)
|
|
40
|
+
let stream = new Transform({ objectMode: true })
|
|
33
41
|
|
|
34
42
|
/**
|
|
35
43
|
* Transform function for the plugin.
|
|
@@ -47,12 +55,12 @@ export function stacksvg () {
|
|
|
47
55
|
return cb()
|
|
48
56
|
}
|
|
49
57
|
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
let iconDom = parse(file.contents.toString()).removeWhitespace()
|
|
59
|
+
let iconSvg = iconDom.querySelector(`svg`)
|
|
52
60
|
|
|
53
61
|
isEmpty = false
|
|
54
62
|
|
|
55
|
-
|
|
63
|
+
let iconId = basename(
|
|
56
64
|
file.relative.split(sep).join(`_`).replace(/\s/g, `-`),
|
|
57
65
|
extname(file.relative),
|
|
58
66
|
)
|
|
@@ -64,9 +72,9 @@ export function stacksvg () {
|
|
|
64
72
|
ids[iconId] = true
|
|
65
73
|
iconSvg.setAttribute(`id`, iconId)
|
|
66
74
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
let viewBoxAttr = iconSvg.getAttribute(`viewBox`)
|
|
76
|
+
let widthAttr = iconSvg.getAttribute(`width`)?.replace(/[^0-9]/g, ``)
|
|
77
|
+
let heightAttr = iconSvg.getAttribute(`height`)?.replace(/[^0-9]/g, ``)
|
|
70
78
|
|
|
71
79
|
if (!viewBoxAttr && widthAttr && heightAttr) {
|
|
72
80
|
iconSvg.setAttribute(`viewBox`, `0 0 ${widthAttr} ${heightAttr}`)
|
|
@@ -105,7 +113,7 @@ export function stacksvg () {
|
|
|
105
113
|
}
|
|
106
114
|
}
|
|
107
115
|
|
|
108
|
-
|
|
116
|
+
let attrs = iconSvg._attrs
|
|
109
117
|
|
|
110
118
|
for (let attrName in attrs) {
|
|
111
119
|
if (attrName.startsWith(`xmlns`)) {
|
|
@@ -118,7 +126,7 @@ export function stacksvg () {
|
|
|
118
126
|
newNsAlias = namespaces.get(nsId).slice(6)
|
|
119
127
|
changeNsAlias(iconDom, oldNsAlias, newNsAlias)
|
|
120
128
|
}
|
|
121
|
-
} else if (nsId ===
|
|
129
|
+
} else if (nsId === XLINK) {
|
|
122
130
|
newNsAlias = ``
|
|
123
131
|
changeNsAlias(iconDom, oldNsAlias, newNsAlias)
|
|
124
132
|
} else {
|
|
@@ -165,7 +173,7 @@ export function stacksvg () {
|
|
|
165
173
|
rootSvg.setAttribute(nsAttr, nsId)
|
|
166
174
|
}
|
|
167
175
|
|
|
168
|
-
|
|
176
|
+
let file = new Vinyl({ path: `stack.svg`, contents: Buffer.from(stack.toString()) })
|
|
169
177
|
|
|
170
178
|
this.push(file)
|
|
171
179
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gulp-stacksvg",
|
|
3
3
|
"description": "The gulp plugin to combine svg files into one using the stack method.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Sergey Artemov",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"./lib/"
|
|
22
22
|
],
|
|
23
23
|
"engines": {
|
|
24
|
-
"node": "^
|
|
24
|
+
"node": "^20.12 || >=22.11"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"node-html-parser": "^6.1.13",
|
|
@@ -29,11 +29,10 @@
|
|
|
29
29
|
"vinyl": "^3.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@firefoxic/eslint-config": "^
|
|
33
|
-
"@firefoxic/update-changelog": "^
|
|
34
|
-
"eslint": "^9.
|
|
35
|
-
"gulp": "^5.0.0"
|
|
36
|
-
"husky": "^9.0.11"
|
|
32
|
+
"@firefoxic/eslint-config": "^4.0.0",
|
|
33
|
+
"@firefoxic/update-changelog": "^1.0.0",
|
|
34
|
+
"eslint": "^9.13.0",
|
|
35
|
+
"gulp": "^5.0.0"
|
|
37
36
|
},
|
|
38
37
|
"keywords": [
|
|
39
38
|
"gulp",
|
|
@@ -49,7 +48,7 @@
|
|
|
49
48
|
"test": "node --test",
|
|
50
49
|
"pretest": "pnpm lint",
|
|
51
50
|
"preversion": "pnpm test",
|
|
52
|
-
"version": "update-changelog
|
|
53
|
-
"postversion": "pnpm publish"
|
|
51
|
+
"version": "update-changelog",
|
|
52
|
+
"postversion": "pnpm publish --provenance --access public --no-git-checks"
|
|
54
53
|
}
|
|
55
54
|
}
|