forked from bitst0rm-st3/a-file-icon
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration for SVG optimization tools
- Loading branch information
Showing
5 changed files
with
188 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json", | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true, | ||
"complexity": { "useLiteralKeys": "off" } | ||
} | ||
}, | ||
"formatter": { | ||
"enabled": false | ||
}, | ||
"organizeImports": { | ||
"enabled": false | ||
}, | ||
"vcs": { | ||
"enabled": true, | ||
"clientKind": "git", | ||
"useIgnoreFile": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const NEWLINE_INDENT_REGEX = /(?:\n(?:\s*))+/g; | ||
|
||
function t(strings, ...values) { | ||
if (typeof strings === 'function') { | ||
return (...args) => t(['', ''], strings(...args)); | ||
} | ||
if (!Array.isArray(strings)) { | ||
return t([strings]); | ||
} | ||
return strings | ||
.reduce((result, string, index) => result + values[index - 1] + string) | ||
.replace(NEWLINE_INDENT_REGEX, ' ') | ||
.trim(); | ||
} | ||
|
||
const SVG_PATH_REGEX = /^m[-mzlhvcsqtae\d,. ]+$/i; | ||
|
||
export default { | ||
rules: { | ||
elm: { | ||
'svg': 1, | ||
'svg > path': 1, | ||
'*': false, | ||
}, | ||
attr: [ | ||
{ | ||
'fill' :'#000', | ||
'fill-rule': 'evenodd', | ||
'viewBox': '0 0 16 16', | ||
'xmlns': 'http://www.w3.org/2000/svg', | ||
'rule::selector': 'svg', | ||
'rule::whitelist': true, | ||
'rule::order': ['xmlns', 'fill', 'fill-rule', 'viewBox'], | ||
}, | ||
{ | ||
'd': SVG_PATH_REGEX, | ||
'rule::selector': 'svg > path', | ||
'rule::whitelist': true, | ||
'rule::order': true, | ||
}, | ||
], | ||
valid: true, | ||
custom: [ | ||
(reporter, $, ast, { filename }) => { | ||
reporter.name = 'no-self-closing-path'; | ||
|
||
// Don't allow explicit '</path>' closing tag | ||
if (!ast.source.includes('</path>')) { | ||
return; | ||
} | ||
|
||
const index = ast.source.indexOf('</path>'); | ||
const message = 'Invalid SVG content format'; | ||
const reason = t` | ||
found a closing "path" tag at index ${index}. | ||
The path should be self-closing, | ||
use "/>" instead of "></path>" | ||
`; | ||
reporter.error(`${message}: ${reason}`); | ||
}, | ||
] | ||
}, | ||
ignore: [ | ||
// TODO: go through these and simplify/remove fill paths; | ||
// I've barely skimmed all svgs so there are probably more | ||
'icons/svg/file_type_fsharp.svg', | ||
'icons/svg/file_type_nix.svg', | ||
'icons/svg/file_type_python.svg', | ||
'icons/svg/file_type_sublime.svg', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
export default { | ||
multipass: true, | ||
js2svg: { | ||
indent: 2, | ||
pretty: true, | ||
}, | ||
plugins: [ | ||
'removeDoctype', | ||
'removeXMLProcInst', | ||
'removeComments', | ||
'removeMetadata', | ||
'removeEditorsNSData', | ||
'cleanupAttrs', | ||
'cleanupIds', | ||
'cleanupNumericValues', | ||
'removeUselessDefs', | ||
'convertColors', | ||
'removeUnknownsAndDefaults', | ||
'removeNonInheritableGroupAttrs', | ||
{ | ||
name: 'removeUselessStrokeAndFill', | ||
params: { | ||
removeNone: true, | ||
}, | ||
}, | ||
'removeDimensions', | ||
'cleanupEnableBackground', | ||
'removeHiddenElems', | ||
'removeEmptyText', | ||
'cleanupListOfValues', | ||
{ | ||
name: 'convertShapeToPath', | ||
params: { | ||
convertArcs: true, | ||
}, | ||
}, | ||
'convertEllipseToCircle', | ||
'moveElemsAttrsToGroup', | ||
'moveGroupAttrsToElems', | ||
'collapseGroups', | ||
{ | ||
name: 'convertPathData', | ||
params: { | ||
floatPrecision: 3, | ||
noSpaceAfterFlags: false, | ||
}, | ||
}, | ||
'convertTransform', | ||
'removeEmptyAttrs', | ||
'removeEmptyContainers', | ||
'removeUnusedNS', | ||
{ | ||
name: 'mergePaths', | ||
params: { | ||
force: true, | ||
noSpaceAfterFlags: true, | ||
}, | ||
}, | ||
{ | ||
name: 'addAttributesToSVGElement', | ||
params: { | ||
attributes: [{ | ||
'fill' :'#000', | ||
'fill-rule': 'evenodd', | ||
'viewBox': '0 0 16 16', | ||
'xmlns': 'http://www.w3.org/2000/svg', | ||
}], | ||
}, | ||
}, | ||
{ | ||
name: 'removeAttrs', | ||
params: { | ||
attrs: [ | ||
'svg:.*(?<!((xmlns)|(fill)|(fill-rule)|(viewBox)))', | ||
'path:(?!d)', | ||
], | ||
}, | ||
}, | ||
'sortAttrs', | ||
'sortDefsChildren', | ||
'removeOffCanvasPaths', | ||
'removeRasterImages', | ||
'removeStyleElement', | ||
'removeScriptElement', | ||
'removeTitle', | ||
'removeDesc', | ||
], | ||
}; |