gulp-stacksvg 4.0.0 → 5.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/README.md +1 -1
- package/lib/index.js +16 -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,7 @@ import { parse } from "node-html-parser"
|
|
|
6
6
|
import PluginError from "plugin-error"
|
|
7
7
|
import Vinyl from "vinyl"
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
let excessAttrs = [
|
|
10
10
|
`enable-background`,
|
|
11
11
|
`height`,
|
|
12
12
|
`version`,
|
|
@@ -16,7 +16,7 @@ const excessAttrs = [
|
|
|
16
16
|
`y`,
|
|
17
17
|
]
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const XLINK = `http://www.w3.org/1999/xlink`
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Gulp plugin for combining SVG icons into a single file.
|
|
@@ -25,11 +25,11 @@ const xlink = `http://www.w3.org/1999/xlink`
|
|
|
25
25
|
*/
|
|
26
26
|
export function stacksvg () {
|
|
27
27
|
let isEmpty = true
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
let ids = {}
|
|
29
|
+
let namespaces = new Map([[`http://www.w3.org/2000/svg`, `xmlns`]])
|
|
30
|
+
let stack = parse(`<svg><style>:root svg:not(:target){display:none}</style></svg>`)
|
|
31
|
+
let rootSvg = stack.querySelector(`svg`)
|
|
32
|
+
let stream = new Transform({ objectMode: true })
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Transform function for the plugin.
|
|
@@ -47,12 +47,12 @@ export function stacksvg () {
|
|
|
47
47
|
return cb()
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
let iconDom = parse(file.contents.toString()).removeWhitespace()
|
|
51
|
+
let iconSvg = iconDom.querySelector(`svg`)
|
|
52
52
|
|
|
53
53
|
isEmpty = false
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
let iconId = basename(
|
|
56
56
|
file.relative.split(sep).join(`_`).replace(/\s/g, `-`),
|
|
57
57
|
extname(file.relative),
|
|
58
58
|
)
|
|
@@ -64,9 +64,9 @@ export function stacksvg () {
|
|
|
64
64
|
ids[iconId] = true
|
|
65
65
|
iconSvg.setAttribute(`id`, iconId)
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
let viewBoxAttr = iconSvg.getAttribute(`viewBox`)
|
|
68
|
+
let widthAttr = iconSvg.getAttribute(`width`)?.replace(/[^0-9]/g, ``)
|
|
69
|
+
let heightAttr = iconSvg.getAttribute(`height`)?.replace(/[^0-9]/g, ``)
|
|
70
70
|
|
|
71
71
|
if (!viewBoxAttr && widthAttr && heightAttr) {
|
|
72
72
|
iconSvg.setAttribute(`viewBox`, `0 0 ${widthAttr} ${heightAttr}`)
|
|
@@ -105,7 +105,7 @@ export function stacksvg () {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
let attrs = iconSvg._attrs
|
|
109
109
|
|
|
110
110
|
for (let attrName in attrs) {
|
|
111
111
|
if (attrName.startsWith(`xmlns`)) {
|
|
@@ -118,7 +118,7 @@ export function stacksvg () {
|
|
|
118
118
|
newNsAlias = namespaces.get(nsId).slice(6)
|
|
119
119
|
changeNsAlias(iconDom, oldNsAlias, newNsAlias)
|
|
120
120
|
}
|
|
121
|
-
} else if (nsId ===
|
|
121
|
+
} else if (nsId === XLINK) {
|
|
122
122
|
newNsAlias = ``
|
|
123
123
|
changeNsAlias(iconDom, oldNsAlias, newNsAlias)
|
|
124
124
|
} else {
|
|
@@ -165,7 +165,7 @@ export function stacksvg () {
|
|
|
165
165
|
rootSvg.setAttribute(nsAttr, nsId)
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
let file = new Vinyl({ path: `stack.svg`, contents: Buffer.from(stack.toString()) })
|
|
169
169
|
|
|
170
170
|
this.push(file)
|
|
171
171
|
|
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.0",
|
|
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
|
}
|