svg-icon-baker 2.0.0 → 2.1.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 +12 -17
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +19 -6
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -79,11 +79,11 @@ type BakeResult = {
|
|
|
79
79
|
|
|
80
80
|
## Options
|
|
81
81
|
|
|
82
|
-
| name | type | default
|
|
83
|
-
| ------------- | ----------------- |
|
|
84
|
-
| `optimize` | `boolean` | `true`
|
|
85
|
-
| `svgoOptions` | `SvgoOptions` | `{}`
|
|
86
|
-
| `idPolicy` | `IdPolicyOptions` | `{ rewrite: true, unresolved: 'prefix', idStyle: '
|
|
82
|
+
| name | type | default | description |
|
|
83
|
+
| ------------- | ----------------- | -------------------------------------------------------------------------- | -------------------------------------------- |
|
|
84
|
+
| `optimize` | `boolean` | `true` | Enable the built-in safe SVGO optimization. |
|
|
85
|
+
| `svgoOptions` | `SvgoOptions` | `{}` | Merge custom SVGO options into optimization. |
|
|
86
|
+
| `idPolicy` | `IdPolicyOptions` | `{ rewrite: true, unresolved: 'prefix', idStyle: 'minified', delim: '_' }` | Control local id rewriting for sprite use. |
|
|
87
87
|
|
|
88
88
|
### `idPolicy`
|
|
89
89
|
|
|
@@ -96,12 +96,12 @@ type IdPolicyOptions = {
|
|
|
96
96
|
}
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
| name | type | default
|
|
100
|
-
| ------------ | ----------------------------------- |
|
|
101
|
-
| `rewrite` | `boolean` | `true`
|
|
102
|
-
| `unresolved` | `'prefix' \| 'preserve'` | `'prefix'`
|
|
103
|
-
| `idStyle` | `'named' \| 'minified' \| 'hashed'` | `'
|
|
104
|
-
| `delim` | `'-' \| '_'` | `'_'`
|
|
99
|
+
| name | type | default | description |
|
|
100
|
+
| ------------ | ----------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
101
|
+
| `rewrite` | `boolean` | `true` | Rewrite local ids and local references for sprite safety. |
|
|
102
|
+
| `unresolved` | `'prefix' \| 'preserve'` | `'prefix'` | For unresolved local references, either rewrite them into the icon namespace or keep them unchanged. Both behaviors report an issue. |
|
|
103
|
+
| `idStyle` | `'named' \| 'minified' \| 'hashed'` | `'minified'` | Choose readable ids such as `icon_home`, short ids such as `icon_a`, or hashed ids such as `icon_dgxZM` (base62 characters). |
|
|
104
|
+
| `delim` | `'-' \| '_'` | `'_'` | Separator between the icon name and the generated id part. |
|
|
105
105
|
|
|
106
106
|
## Diagnostics
|
|
107
107
|
|
|
@@ -216,12 +216,7 @@ type BakeIssue = {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
type BakeErrorCode =
|
|
219
|
-
| '
|
|
220
|
-
| 'ValidateNameInvalid'
|
|
221
|
-
| 'ValidateSvgRootInvalid'
|
|
222
|
-
| 'ParseSvgFailed'
|
|
223
|
-
| 'OptimizeSvgFailed'
|
|
224
|
-
| 'ResolveViewBoxFailed'
|
|
219
|
+
'ValidateSourceInvalid' | 'ValidateNameInvalid' | 'ValidateSvgRootInvalid' | 'ParseSvgFailed' | 'OptimizeSvgFailed' | 'ResolveViewBoxFailed'
|
|
225
220
|
|
|
226
221
|
type SvgoOptions = Pick<Config, 'multipass' | 'floatPrecision' | 'js2svg' | 'plugins'>
|
|
227
222
|
|
package/dist/index.d.mts
CHANGED
|
@@ -46,7 +46,7 @@ type Options = {
|
|
|
46
46
|
svgoOptions?: SvgoOptions;
|
|
47
47
|
/**
|
|
48
48
|
* sprite-safe local id rewriting
|
|
49
|
-
* @default { rewrite: true, unresolved: 'prefix', idStyle: '
|
|
49
|
+
* @default { rewrite: true, unresolved: 'prefix', idStyle: 'minified', delim: '_' }
|
|
50
50
|
*/
|
|
51
51
|
idPolicy?: IdPolicyOptions;
|
|
52
52
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ type Options = {
|
|
|
46
46
|
svgoOptions?: SvgoOptions;
|
|
47
47
|
/**
|
|
48
48
|
* sprite-safe local id rewriting
|
|
49
|
-
* @default { rewrite: true, unresolved: 'prefix', idStyle: '
|
|
49
|
+
* @default { rewrite: true, unresolved: 'prefix', idStyle: 'minified', delim: '_' }
|
|
50
50
|
*/
|
|
51
51
|
idPolicy?: IdPolicyOptions;
|
|
52
52
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -455,13 +455,13 @@ function rewriteStyleText(textNode, idMap, prefix, unresolvedIdMap, nextIndex, o
|
|
|
455
455
|
});
|
|
456
456
|
return csstree.generate(cssAst);
|
|
457
457
|
}
|
|
458
|
+
const BASE52_ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
458
459
|
function encodeIndex(index) {
|
|
459
|
-
const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
460
460
|
let current = index;
|
|
461
461
|
let result = "";
|
|
462
462
|
do {
|
|
463
|
-
result =
|
|
464
|
-
current = Math.floor(current /
|
|
463
|
+
result = BASE52_ALPHABET[current % 52] + result;
|
|
464
|
+
current = Math.floor(current / 52) - 1;
|
|
465
465
|
} while (current >= 0);
|
|
466
466
|
return result;
|
|
467
467
|
}
|
|
@@ -477,11 +477,24 @@ function createMappedId(sourceId, prefix, index, options) {
|
|
|
477
477
|
return `${prefix}${delim}${encodeIndex(index)}`;
|
|
478
478
|
}
|
|
479
479
|
function hashId(value) {
|
|
480
|
+
return toBase62(digest_djb2(value));
|
|
481
|
+
}
|
|
482
|
+
function digest_djb2(str) {
|
|
480
483
|
let hash = 5381;
|
|
481
|
-
for (const char of
|
|
484
|
+
for (const char of str) {
|
|
482
485
|
hash = (hash << 5) + hash ^ char.charCodeAt(0);
|
|
483
486
|
}
|
|
484
|
-
return
|
|
487
|
+
return hash >>> 0;
|
|
488
|
+
}
|
|
489
|
+
const BASE62_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
490
|
+
function toBase62(value) {
|
|
491
|
+
let current = value;
|
|
492
|
+
let result = "";
|
|
493
|
+
do {
|
|
494
|
+
result = BASE62_ALPHABET[current % 62] + result;
|
|
495
|
+
current = Math.floor(current / 62);
|
|
496
|
+
} while (current > 0);
|
|
497
|
+
return result;
|
|
485
498
|
}
|
|
486
499
|
function createUnresolvedMappedId(sourceId, prefix, unresolvedIdMap, nextIndex, options) {
|
|
487
500
|
const existing = unresolvedIdMap.get(sourceId);
|
|
@@ -618,7 +631,7 @@ function resolveIdPolicyOptions(idPolicy) {
|
|
|
618
631
|
return {
|
|
619
632
|
rewrite: idPolicy?.rewrite ?? true,
|
|
620
633
|
unresolved: idPolicy?.unresolved ?? "prefix",
|
|
621
|
-
idStyle: idPolicy?.idStyle ?? "
|
|
634
|
+
idStyle: idPolicy?.idStyle ?? "minified",
|
|
622
635
|
delim: idPolicy?.delim ?? "_"
|
|
623
636
|
};
|
|
624
637
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svg-icon-baker",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A delightful toolkit for baking raw SVG icons into delicious SVG symbol sprites",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svg",
|
|
@@ -38,15 +38,16 @@
|
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"css-tree": "^3.2.1",
|
|
41
|
-
"fast-xml-builder": "^1.1
|
|
42
|
-
"fast-xml-parser": "^5.
|
|
41
|
+
"fast-xml-builder": "^1.2.1",
|
|
42
|
+
"fast-xml-parser": "^5.9.3",
|
|
43
43
|
"svgo": "^4.0.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
46
|
+
"@types/node": "^24.13.3",
|
|
47
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
48
|
+
"typescript": "~5.9.3",
|
|
48
49
|
"unbuild": "^3.6.1",
|
|
49
|
-
"vitest": "^4.1.
|
|
50
|
+
"vitest": "^4.1.10"
|
|
50
51
|
},
|
|
51
52
|
"engines": {
|
|
52
53
|
"node": "^18.0.0 || ^20.0.0 || >=22.0.0"
|
|
@@ -56,7 +57,8 @@
|
|
|
56
57
|
"build": "unbuild",
|
|
57
58
|
"test": "vitest run",
|
|
58
59
|
"coverage": "vitest run --coverage",
|
|
59
|
-
"
|
|
60
|
+
"typecheck": "tsc -b",
|
|
61
|
+
"clean": "rimraf dist node_modules/.tmp",
|
|
60
62
|
"release": "commit-and-tag-version --path . -t svg-icon-baker@"
|
|
61
63
|
}
|
|
62
64
|
}
|