@iconify/tools 1.3.17 → 2.0.0-dev.2
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/.editorconfig +13 -0
- package/.eslintignore +2 -0
- package/lib/colors/attribs.d.ts +16 -0
- package/lib/colors/attribs.js +26 -0
- package/lib/colors/attribs.mjs +28 -0
- package/lib/colors/parse.d.ts +37 -0
- package/lib/colors/parse.js +261 -0
- package/lib/colors/parse.mjs +212 -0
- package/lib/css/parse.d.ts +4 -0
- package/lib/css/parse.js +23 -0
- package/lib/css/parse.mjs +20 -0
- package/lib/css/parser/error.d.ts +11 -0
- package/lib/css/parser/error.js +27 -0
- package/lib/css/parser/error.mjs +23 -0
- package/lib/css/parser/export.d.ts +5 -0
- package/lib/css/parser/export.js +69 -0
- package/lib/css/parser/export.mjs +46 -0
- package/lib/css/parser/strings.d.ts +13 -0
- package/lib/css/parser/strings.js +93 -0
- package/lib/css/parser/strings.mjs +74 -0
- package/lib/css/parser/text.d.ts +17 -0
- package/lib/css/parser/text.js +174 -0
- package/lib/css/parser/text.mjs +133 -0
- package/lib/css/parser/tokens.d.ts +6 -0
- package/lib/css/parser/tokens.js +200 -0
- package/lib/css/parser/tokens.mjs +186 -0
- package/lib/css/parser/tree.d.ts +5 -0
- package/lib/css/parser/tree.js +44 -0
- package/lib/css/parser/tree.mjs +40 -0
- package/lib/css/parser/types.d.ts +51 -0
- package/lib/css/parser/types.js +2 -0
- package/lib/css/parser/types.mjs +0 -0
- package/lib/icon-set/index.d.ts +134 -0
- package/lib/icon-set/index.js +776 -0
- package/lib/icon-set/index.mjs +617 -0
- package/lib/icon-set/match.d.ts +6 -0
- package/lib/icon-set/match.js +66 -0
- package/lib/icon-set/match.mjs +55 -0
- package/lib/icon-set/merge.d.ts +5 -0
- package/lib/icon-set/merge.js +91 -0
- package/lib/icon-set/merge.mjs +75 -0
- package/lib/icon-set/props.d.ts +10 -0
- package/lib/icon-set/props.js +33 -0
- package/lib/icon-set/props.mjs +25 -0
- package/lib/icon-set/types.d.ts +68 -0
- package/lib/icon-set/types.js +2 -0
- package/lib/icon-set/types.mjs +0 -0
- package/lib/import/directory.d.ts +35 -0
- package/lib/import/directory.js +59 -0
- package/lib/import/directory.mjs +47 -0
- package/lib/misc/keyword.d.ts +4 -0
- package/lib/misc/keyword.js +31 -0
- package/lib/misc/keyword.mjs +17 -0
- package/lib/misc/scan.d.ts +24 -0
- package/lib/misc/scan.js +48 -0
- package/lib/misc/scan.mjs +43 -0
- package/lib/optimise/flags.d.ts +5 -0
- package/lib/optimise/flags.js +303 -0
- package/lib/optimise/flags.mjs +241 -0
- package/lib/optimise/scale.d.ts +5 -0
- package/lib/optimise/scale.js +42 -0
- package/lib/optimise/scale.mjs +22 -0
- package/lib/optimise/svgo.d.ts +27 -0
- package/lib/optimise/svgo.js +88 -0
- package/lib/optimise/svgo.mjs +75 -0
- package/lib/svg/cleanup/attribs.d.ts +5 -0
- package/lib/svg/cleanup/attribs.js +43 -0
- package/lib/svg/cleanup/attribs.mjs +36 -0
- package/lib/svg/cleanup/bad-tags.d.ts +5 -0
- package/lib/svg/cleanup/bad-tags.js +69 -0
- package/lib/svg/cleanup/bad-tags.mjs +68 -0
- package/lib/svg/cleanup/inline-style.d.ts +5 -0
- package/lib/svg/cleanup/inline-style.js +77 -0
- package/lib/svg/cleanup/inline-style.mjs +65 -0
- package/lib/svg/cleanup/root-svg.d.ts +5 -0
- package/lib/svg/cleanup/root-svg.js +106 -0
- package/lib/svg/cleanup/root-svg.mjs +88 -0
- package/lib/svg/cleanup/svgo-style.d.ts +5 -0
- package/lib/svg/cleanup/svgo-style.js +35 -0
- package/lib/svg/cleanup/svgo-style.mjs +29 -0
- package/lib/svg/cleanup.d.ts +5 -0
- package/lib/svg/cleanup.js +24 -0
- package/lib/svg/cleanup.mjs +16 -0
- package/lib/svg/data/attributes.d.ts +71 -0
- package/lib/svg/data/attributes.js +403 -0
- package/lib/svg/data/attributes.mjs +352 -0
- package/lib/svg/data/tags.d.ts +89 -0
- package/lib/svg/data/tags.js +185 -0
- package/lib/svg/data/tags.mjs +136 -0
- package/lib/svg/index.d.ts +33 -0
- package/lib/svg/index.js +122 -0
- package/lib/svg/index.mjs +85 -0
- package/lib/svg/parse-style.d.ts +40 -0
- package/lib/svg/parse-style.js +131 -0
- package/lib/svg/parse-style.mjs +109 -0
- package/lib/svg/parse.d.ts +30 -0
- package/lib/svg/parse.js +49 -0
- package/lib/svg/parse.mjs +40 -0
- package/package.json +167 -13
- package/README.md +0 -576
- package/license.txt +0 -21
- package/sample/parse.js +0 -74
- package/sample/source/icon-close.svg +0 -15
- package/sample/source/icon-confirm.svg +0 -14
- package/sample/source/icon-search.svg +0 -16
- package/src/collection.js +0 -641
- package/src/colors/change_palette.js +0 -227
- package/src/colors/get_palette.js +0 -143
- package/src/colors/opacify.js +0 -195
- package/src/export/component.js +0 -482
- package/src/export/dir.js +0 -109
- package/src/export/json.js +0 -329
- package/src/export/phantomjs.js +0 -76
- package/src/export/phantomjs_script.js +0 -125
- package/src/export/png.js +0 -193
- package/src/export/svg.js +0 -55
- package/src/export/templates/component.md +0 -79
- package/src/export/templates/info.md +0 -3
- package/src/export/templates/sample-react-1.md +0 -21
- package/src/export/templates/sample-react-2.md +0 -15
- package/src/export/templates/sample-react.md +0 -11
- package/src/export/templates/sample-svelte.md +0 -11
- package/src/export/templates/sample-svelte1.md +0 -22
- package/src/export/templates/sample-svelte2.md +0 -13
- package/src/export/templates/sample-vue-0.md +0 -30
- package/src/export/templates/sample-vue-1.md +0 -25
- package/src/export/templates/sample-vue-2.md +0 -27
- package/src/export/templates/sample-vue.md +0 -28
- package/src/helpers.js +0 -43
- package/src/import/dir.js +0 -234
- package/src/import/font.js +0 -402
- package/src/import/json.js +0 -200
- package/src/import/svg.js +0 -60
- package/src/import/web_icons.js +0 -248
- package/src/modules.js +0 -50
- package/src/optimize/crop.js +0 -554
- package/src/optimize/crop_script.js +0 -525
- package/src/optimize/flags.js +0 -430
- package/src/optimize/scale.js +0 -72
- package/src/optimize/svgo.js +0 -161
- package/src/optimize/tags.js +0 -522
- package/src/shapes/convert.js +0 -264
- package/src/shapes/index.js +0 -135
- package/src/shapes/length.js +0 -707
- package/src/shapes/length_script.js +0 -105
- package/src/shapes/options.js +0 -60
- package/src/svg.js +0 -162
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// src/svg/cleanup/root-svg.ts
|
|
2
|
+
import {
|
|
3
|
+
badAttributes,
|
|
4
|
+
badAttributePrefixes,
|
|
5
|
+
badSoftwareAttributes,
|
|
6
|
+
commonAttributes,
|
|
7
|
+
junkSVGAttributes,
|
|
8
|
+
stylingAttributes,
|
|
9
|
+
tagSpecificNonPresentationalAttributes,
|
|
10
|
+
tagSpecificPresentationalAttributes
|
|
11
|
+
} from "../data/attributes.mjs";
|
|
12
|
+
import { maskAndSymbolTags } from "../data/tags.mjs";
|
|
13
|
+
async function cleanupSVGRoot(svg) {
|
|
14
|
+
const cheerio = svg.$svg;
|
|
15
|
+
const $root = svg.$svg(":root");
|
|
16
|
+
const root = $root.get(0);
|
|
17
|
+
const tagName = "svg";
|
|
18
|
+
if (root.tagName !== tagName) {
|
|
19
|
+
throw new Error(`Unexpected root tag <${root.tagName}>`);
|
|
20
|
+
}
|
|
21
|
+
const attribs = root.attribs;
|
|
22
|
+
const moveToChildren = {};
|
|
23
|
+
Object.keys(attribs).forEach((attr) => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
const value = attribs[attr];
|
|
26
|
+
if (commonAttributes.has(attr) || badAttributes.has(attr) || junkSVGAttributes.has(attr) || badSoftwareAttributes.has(attr) || badAttributePrefixes.has(attr.split("-").shift()) || attr.split(":").length > 1) {
|
|
27
|
+
$root.removeAttr(attr);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
switch (attr) {
|
|
31
|
+
case "width":
|
|
32
|
+
case "height":
|
|
33
|
+
if (value.slice(-2) === "px") {
|
|
34
|
+
const num = value.replace("px", "");
|
|
35
|
+
if (parseFloat(num) + "" === num) {
|
|
36
|
+
$root.attr(attr, num);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if ((_a = tagSpecificNonPresentationalAttributes[tagName]) == null ? void 0 : _a.has(attr)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (((_b = tagSpecificPresentationalAttributes[tagName]) == null ? void 0 : _b.has(attr)) && tagSpecificPresentationalAttributes.g.has(attr)) {
|
|
45
|
+
moveToChildren[attr] = value;
|
|
46
|
+
$root.removeAttr(attr);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (stylingAttributes.has(attr)) {
|
|
50
|
+
switch (attr) {
|
|
51
|
+
case "style":
|
|
52
|
+
return;
|
|
53
|
+
case "class":
|
|
54
|
+
$root.removeAttr(attr);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
throw new Error(`Unexpected attribute "${attr}" on <${tagName}>`);
|
|
58
|
+
}
|
|
59
|
+
if (attr.slice(0, 2) === "on" || attr.slice(0, 5) === "aria-" || attr.slice(0, 6) === "xmlns:") {
|
|
60
|
+
$root.removeAttr(attr);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
console.log(`Removing unexpected attribute on SVG: ${attr}`);
|
|
64
|
+
$root.removeAttr(attr);
|
|
65
|
+
});
|
|
66
|
+
if (Object.keys(moveToChildren).length) {
|
|
67
|
+
const $wrapper = cheerio("<g />");
|
|
68
|
+
for (const key in moveToChildren) {
|
|
69
|
+
$wrapper.attr(key, moveToChildren[key]);
|
|
70
|
+
}
|
|
71
|
+
$root.children().each((index, child) => {
|
|
72
|
+
const $child = cheerio(child);
|
|
73
|
+
if (child.type !== "tag") {
|
|
74
|
+
$child.appendTo($wrapper);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const tagName2 = child.tagName;
|
|
78
|
+
if (tagName2 === "style" || maskAndSymbolTags.has(tagName2)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
$child.appendTo($wrapper);
|
|
82
|
+
});
|
|
83
|
+
$wrapper.appendTo($root);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
cleanupSVGRoot
|
|
88
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertStyleToAttrs = void 0;
|
|
4
|
+
const attributes_1 = require("../data/attributes");
|
|
5
|
+
const parse_style_1 = require("../parse-style");
|
|
6
|
+
const svgo_1 = require("../../optimise/svgo");
|
|
7
|
+
/**
|
|
8
|
+
* Expand inline style
|
|
9
|
+
*/
|
|
10
|
+
async function convertStyleToAttrs(svg) {
|
|
11
|
+
let hasStyle = false;
|
|
12
|
+
// Clean up style, removing useless junk
|
|
13
|
+
await (0, parse_style_1.parseSVGStyle)(svg, (item) => {
|
|
14
|
+
const prop = item.prop;
|
|
15
|
+
if (
|
|
16
|
+
// Attributes / properties now allowed
|
|
17
|
+
attributes_1.badAttributes.has(prop) ||
|
|
18
|
+
attributes_1.badSoftwareAttributes.has(prop) ||
|
|
19
|
+
attributes_1.badAttributePrefixes.has(prop.split('-').shift())) {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
hasStyle = true;
|
|
23
|
+
return item.value;
|
|
24
|
+
});
|
|
25
|
+
// Nothing to check?
|
|
26
|
+
if (!hasStyle) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// Run SVGO
|
|
30
|
+
await (0, svgo_1.runSVGO)(svg, {
|
|
31
|
+
plugins: ['convertStyleToAttrs', 'inlineStyles'],
|
|
32
|
+
multipass: true,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.convertStyleToAttrs = convertStyleToAttrs;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/svg/cleanup/svgo-style.ts
|
|
2
|
+
import {
|
|
3
|
+
badAttributes,
|
|
4
|
+
badAttributePrefixes,
|
|
5
|
+
badSoftwareAttributes
|
|
6
|
+
} from "../data/attributes.mjs";
|
|
7
|
+
import { parseSVGStyle } from "../parse-style.mjs";
|
|
8
|
+
import { runSVGO } from "../../optimise/svgo.mjs";
|
|
9
|
+
async function convertStyleToAttrs(svg) {
|
|
10
|
+
let hasStyle = false;
|
|
11
|
+
await parseSVGStyle(svg, (item) => {
|
|
12
|
+
const prop = item.prop;
|
|
13
|
+
if (badAttributes.has(prop) || badSoftwareAttributes.has(prop) || badAttributePrefixes.has(prop.split("-").shift())) {
|
|
14
|
+
return void 0;
|
|
15
|
+
}
|
|
16
|
+
hasStyle = true;
|
|
17
|
+
return item.value;
|
|
18
|
+
});
|
|
19
|
+
if (!hasStyle) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
await runSVGO(svg, {
|
|
23
|
+
plugins: ["convertStyleToAttrs", "inlineStyles"],
|
|
24
|
+
multipass: true
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
convertStyleToAttrs
|
|
29
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cleanupSVG = void 0;
|
|
4
|
+
const attribs_1 = require("./cleanup/attribs");
|
|
5
|
+
const bad_tags_1 = require("./cleanup/bad-tags");
|
|
6
|
+
const inline_style_1 = require("./cleanup/inline-style");
|
|
7
|
+
const root_svg_1 = require("./cleanup/root-svg");
|
|
8
|
+
const svgo_style_1 = require("./cleanup/svgo-style");
|
|
9
|
+
/**
|
|
10
|
+
* Clean up SVG before parsing/optimising it
|
|
11
|
+
*/
|
|
12
|
+
async function cleanupSVG(svg) {
|
|
13
|
+
// Remove junk from style
|
|
14
|
+
await (0, inline_style_1.cleanupInlineStyle)(svg);
|
|
15
|
+
// Expand style
|
|
16
|
+
await (0, svgo_style_1.convertStyleToAttrs)(svg);
|
|
17
|
+
// Cleanup <svg> element
|
|
18
|
+
await (0, root_svg_1.cleanupSVGRoot)(svg);
|
|
19
|
+
// Check for bad tags
|
|
20
|
+
await (0, bad_tags_1.checkBadTags)(svg);
|
|
21
|
+
// Remove attributes
|
|
22
|
+
await (0, attribs_1.removeBadAttributes)(svg);
|
|
23
|
+
}
|
|
24
|
+
exports.cleanupSVG = cleanupSVG;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/svg/cleanup.ts
|
|
2
|
+
import { removeBadAttributes } from "./cleanup/attribs.mjs";
|
|
3
|
+
import { checkBadTags } from "./cleanup/bad-tags.mjs";
|
|
4
|
+
import { cleanupInlineStyle } from "./cleanup/inline-style.mjs";
|
|
5
|
+
import { cleanupSVGRoot } from "./cleanup/root-svg.mjs";
|
|
6
|
+
import { convertStyleToAttrs } from "./cleanup/svgo-style.mjs";
|
|
7
|
+
async function cleanupSVG(svg) {
|
|
8
|
+
await cleanupInlineStyle(svg);
|
|
9
|
+
await convertStyleToAttrs(svg);
|
|
10
|
+
await cleanupSVGRoot(svg);
|
|
11
|
+
await checkBadTags(svg);
|
|
12
|
+
await removeBadAttributes(svg);
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
cleanupSVG
|
|
16
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This list is highly opinionated. It is designed to handle icons that can be safely embedded in HTML and linked as external source.
|
|
3
|
+
* Icons cannot have anything that requires external resources, anything that renders inconsistently.
|
|
4
|
+
*/
|
|
5
|
+
/***** Attributes that are not part of tag specific stuff *****/
|
|
6
|
+
/**
|
|
7
|
+
* Attributes that icons should not mess with or that are irrelevant. They should be removed
|
|
8
|
+
*/
|
|
9
|
+
export declare const badAttributes: Set<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Attributes for SVG element that should be removed
|
|
12
|
+
*/
|
|
13
|
+
export declare const junkSVGAttributes: Set<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Attributes and styles often added by bad software to wrong tags, such as Adobe Illustrator and Inkscape
|
|
16
|
+
*/
|
|
17
|
+
export declare const badSoftwareAttributes: Set<string>;
|
|
18
|
+
export declare const badAttributePrefixes: Set<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Common attributes that can exist on any element
|
|
21
|
+
*/
|
|
22
|
+
export declare const commonAttributes: Set<string>;
|
|
23
|
+
export declare const stylingAttributes: Set<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Attributes that exist only on child elements of <clipPath>
|
|
26
|
+
*/
|
|
27
|
+
export declare const insideClipPathAttributes: Set<string>;
|
|
28
|
+
/***** Other attributes, added to tagSpecificAttributes variable below *****/
|
|
29
|
+
/**
|
|
30
|
+
* Presentational attributes
|
|
31
|
+
*/
|
|
32
|
+
export declare const fillPresentationalAttributes: Set<string>;
|
|
33
|
+
export declare const strokePresentationalAttributes: Set<string>;
|
|
34
|
+
export declare const urlPresentationalAttributes: Set<string>;
|
|
35
|
+
export declare const visibilityPresentationalAttributes: Set<string>;
|
|
36
|
+
export declare const commonColorPresentationalAttributes: Set<string>;
|
|
37
|
+
export declare const otherPresentationalAttributes: Set<string>;
|
|
38
|
+
export declare const presentationalAttributes: Set<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Markers
|
|
41
|
+
*
|
|
42
|
+
* Presentational attributes
|
|
43
|
+
*/
|
|
44
|
+
export declare const markerAttributes: Set<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Shapes
|
|
47
|
+
*
|
|
48
|
+
* Not presentational
|
|
49
|
+
*/
|
|
50
|
+
export declare const otherShapeAttributes: Set<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Animations
|
|
53
|
+
*/
|
|
54
|
+
export declare const animationTimingAttributes: Set<string>;
|
|
55
|
+
export declare const animationValueAttributes: Set<string>;
|
|
56
|
+
export declare const otherAnimationAttributes: Set<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Gradients
|
|
59
|
+
*/
|
|
60
|
+
export declare const commonGradientAttributes: Set<string>;
|
|
61
|
+
/**
|
|
62
|
+
* Filters
|
|
63
|
+
*/
|
|
64
|
+
export declare const commonFeAttributes: Set<string>;
|
|
65
|
+
export declare const feFuncAttributes: Set<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Tag specific attributes
|
|
68
|
+
*/
|
|
69
|
+
export declare const tagSpecificAnimatedAttributes: Record<string, Set<string>>;
|
|
70
|
+
export declare const tagSpecificPresentationalAttributes: Record<string, Set<string>>;
|
|
71
|
+
export declare const tagSpecificNonPresentationalAttributes: Record<string, Set<string>>;
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This list is highly opinionated. It is designed to handle icons that can be safely embedded in HTML and linked as external source.
|
|
4
|
+
* Icons cannot have anything that requires external resources, anything that renders inconsistently.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.tagSpecificNonPresentationalAttributes = exports.tagSpecificPresentationalAttributes = exports.tagSpecificAnimatedAttributes = exports.feFuncAttributes = exports.commonFeAttributes = exports.commonGradientAttributes = exports.otherAnimationAttributes = exports.animationValueAttributes = exports.animationTimingAttributes = exports.otherShapeAttributes = exports.markerAttributes = exports.presentationalAttributes = exports.otherPresentationalAttributes = exports.commonColorPresentationalAttributes = exports.visibilityPresentationalAttributes = exports.urlPresentationalAttributes = exports.strokePresentationalAttributes = exports.fillPresentationalAttributes = exports.insideClipPathAttributes = exports.stylingAttributes = exports.commonAttributes = exports.badAttributePrefixes = exports.badSoftwareAttributes = exports.junkSVGAttributes = exports.badAttributes = void 0;
|
|
8
|
+
const tags_1 = require("./tags");
|
|
9
|
+
/***** Attributes that are not part of tag specific stuff *****/
|
|
10
|
+
/**
|
|
11
|
+
* Attributes that icons should not mess with or that are irrelevant. They should be removed
|
|
12
|
+
*/
|
|
13
|
+
exports.badAttributes = new Set([
|
|
14
|
+
'cursor',
|
|
15
|
+
'pointer-events',
|
|
16
|
+
'shape-rendering',
|
|
17
|
+
'tabindex',
|
|
18
|
+
'requiredExtensions',
|
|
19
|
+
'requiredFeatures',
|
|
20
|
+
'systemLanguage',
|
|
21
|
+
'role',
|
|
22
|
+
'title',
|
|
23
|
+
]);
|
|
24
|
+
/**
|
|
25
|
+
* Attributes for SVG element that should be removed
|
|
26
|
+
*/
|
|
27
|
+
exports.junkSVGAttributes = new Set([
|
|
28
|
+
'xmlns:xlink',
|
|
29
|
+
'baseProfile',
|
|
30
|
+
'contentScriptType',
|
|
31
|
+
'contentStyleType',
|
|
32
|
+
'version',
|
|
33
|
+
'x',
|
|
34
|
+
'y',
|
|
35
|
+
'zoomAndPan',
|
|
36
|
+
]);
|
|
37
|
+
/**
|
|
38
|
+
* Attributes and styles often added by bad software to wrong tags, such as Adobe Illustrator and Inkscape
|
|
39
|
+
*/
|
|
40
|
+
exports.badSoftwareAttributes = new Set([
|
|
41
|
+
'color-interpolation-filters',
|
|
42
|
+
'isolation',
|
|
43
|
+
'enable-background',
|
|
44
|
+
'overflow',
|
|
45
|
+
'marker',
|
|
46
|
+
'white-space',
|
|
47
|
+
// Font stuff
|
|
48
|
+
'direction',
|
|
49
|
+
]);
|
|
50
|
+
// Prefixes. First part of attribute before '-', where all possible attributes that start with prefix are invalid
|
|
51
|
+
exports.badAttributePrefixes = new Set([
|
|
52
|
+
'image',
|
|
53
|
+
'mix',
|
|
54
|
+
'block',
|
|
55
|
+
'data',
|
|
56
|
+
'aria',
|
|
57
|
+
// Font stuff
|
|
58
|
+
'text',
|
|
59
|
+
'font',
|
|
60
|
+
'letter',
|
|
61
|
+
'baseline',
|
|
62
|
+
'word',
|
|
63
|
+
'line',
|
|
64
|
+
'writing',
|
|
65
|
+
// Prefix for browser specific stuff
|
|
66
|
+
'',
|
|
67
|
+
]);
|
|
68
|
+
/**
|
|
69
|
+
* Common attributes that can exist on any element
|
|
70
|
+
*/
|
|
71
|
+
exports.commonAttributes = new Set(['id']);
|
|
72
|
+
exports.stylingAttributes = new Set(['class', 'style']);
|
|
73
|
+
/**
|
|
74
|
+
* Attributes that exist only on child elements of <clipPath>
|
|
75
|
+
*/
|
|
76
|
+
exports.insideClipPathAttributes = new Set(['clip-rule']);
|
|
77
|
+
/***** Other attributes, added to tagSpecificAttributes variable below *****/
|
|
78
|
+
/**
|
|
79
|
+
* Presentational attributes
|
|
80
|
+
*/
|
|
81
|
+
// Attributes used for shapes with fill to change fill style
|
|
82
|
+
exports.fillPresentationalAttributes = new Set([
|
|
83
|
+
'fill-opacity',
|
|
84
|
+
'fill-rule',
|
|
85
|
+
]);
|
|
86
|
+
// Attributes used for shapes with stroke to change stroke style
|
|
87
|
+
exports.strokePresentationalAttributes = new Set([
|
|
88
|
+
'stroke-dasharray',
|
|
89
|
+
'stroke-dashoffset',
|
|
90
|
+
'stroke-linecap',
|
|
91
|
+
'stroke-linejoin',
|
|
92
|
+
'stroke-miterlimit',
|
|
93
|
+
'stroke-opacity',
|
|
94
|
+
'stroke-width',
|
|
95
|
+
]);
|
|
96
|
+
// Attributes where value is an url()
|
|
97
|
+
exports.urlPresentationalAttributes = new Set([
|
|
98
|
+
'clip-path',
|
|
99
|
+
'filter',
|
|
100
|
+
'mask',
|
|
101
|
+
]);
|
|
102
|
+
// Visibility
|
|
103
|
+
exports.visibilityPresentationalAttributes = new Set([
|
|
104
|
+
'display',
|
|
105
|
+
'opacity',
|
|
106
|
+
'visibility',
|
|
107
|
+
]);
|
|
108
|
+
// Color values
|
|
109
|
+
exports.commonColorPresentationalAttributes = new Set([
|
|
110
|
+
'color',
|
|
111
|
+
'fill',
|
|
112
|
+
'stroke',
|
|
113
|
+
]);
|
|
114
|
+
// Other presentational attributes
|
|
115
|
+
exports.otherPresentationalAttributes = new Set([
|
|
116
|
+
'color-interpolation',
|
|
117
|
+
'color-rendering',
|
|
118
|
+
'transform',
|
|
119
|
+
'vector-effect',
|
|
120
|
+
]);
|
|
121
|
+
// All presentational attributes
|
|
122
|
+
exports.presentationalAttributes = new Set([
|
|
123
|
+
...exports.fillPresentationalAttributes,
|
|
124
|
+
...exports.strokePresentationalAttributes,
|
|
125
|
+
...exports.urlPresentationalAttributes,
|
|
126
|
+
...exports.visibilityPresentationalAttributes,
|
|
127
|
+
...exports.commonColorPresentationalAttributes,
|
|
128
|
+
...exports.otherPresentationalAttributes,
|
|
129
|
+
]);
|
|
130
|
+
/**
|
|
131
|
+
* Markers
|
|
132
|
+
*
|
|
133
|
+
* Presentational attributes
|
|
134
|
+
*/
|
|
135
|
+
exports.markerAttributes = new Set([
|
|
136
|
+
'marker-start',
|
|
137
|
+
'marker-mid',
|
|
138
|
+
'marker-end',
|
|
139
|
+
]);
|
|
140
|
+
/**
|
|
141
|
+
* Shapes
|
|
142
|
+
*
|
|
143
|
+
* Not presentational
|
|
144
|
+
*/
|
|
145
|
+
exports.otherShapeAttributes = new Set(['pathLength']);
|
|
146
|
+
/**
|
|
147
|
+
* Animations
|
|
148
|
+
*/
|
|
149
|
+
exports.animationTimingAttributes = new Set([
|
|
150
|
+
'begin',
|
|
151
|
+
'dur',
|
|
152
|
+
'end',
|
|
153
|
+
'min',
|
|
154
|
+
'max',
|
|
155
|
+
'restart',
|
|
156
|
+
'repeatCount',
|
|
157
|
+
'repeatDur',
|
|
158
|
+
'fill',
|
|
159
|
+
]);
|
|
160
|
+
exports.animationValueAttributes = new Set([
|
|
161
|
+
'calcMode',
|
|
162
|
+
'values',
|
|
163
|
+
'keyTimes',
|
|
164
|
+
'keySplines',
|
|
165
|
+
'from',
|
|
166
|
+
'to',
|
|
167
|
+
'by',
|
|
168
|
+
]);
|
|
169
|
+
exports.otherAnimationAttributes = new Set([
|
|
170
|
+
'attributeName',
|
|
171
|
+
'additive',
|
|
172
|
+
'accumulate',
|
|
173
|
+
]);
|
|
174
|
+
/**
|
|
175
|
+
* Gradients
|
|
176
|
+
*/
|
|
177
|
+
exports.commonGradientAttributes = new Set([
|
|
178
|
+
'gradientUnits',
|
|
179
|
+
'gradientTransform',
|
|
180
|
+
'href',
|
|
181
|
+
'spreadMethod',
|
|
182
|
+
]);
|
|
183
|
+
/**
|
|
184
|
+
* Filters
|
|
185
|
+
*/
|
|
186
|
+
// Presentational, supported by most filters
|
|
187
|
+
exports.commonFeAttributes = new Set([
|
|
188
|
+
'x',
|
|
189
|
+
'y',
|
|
190
|
+
'width',
|
|
191
|
+
'height',
|
|
192
|
+
'color-interpolation-filters',
|
|
193
|
+
]);
|
|
194
|
+
exports.feFuncAttributes = new Set([
|
|
195
|
+
'type',
|
|
196
|
+
'tableValues',
|
|
197
|
+
'slope',
|
|
198
|
+
'intercept',
|
|
199
|
+
'amplitude',
|
|
200
|
+
'exponent',
|
|
201
|
+
'offset',
|
|
202
|
+
...exports.commonFeAttributes,
|
|
203
|
+
]);
|
|
204
|
+
/**
|
|
205
|
+
* Tag specific attributes
|
|
206
|
+
*/
|
|
207
|
+
// Attributes, can be used in animations
|
|
208
|
+
// Most attributes can also be used in style
|
|
209
|
+
exports.tagSpecificAnimatedAttributes = {
|
|
210
|
+
circle: new Set(['cx', 'cy', 'r']),
|
|
211
|
+
ellipse: new Set(['cx', 'cy', 'rx', 'ry']),
|
|
212
|
+
line: new Set(['x1', 'x2', 'y1', 'y2']),
|
|
213
|
+
path: new Set(['d']),
|
|
214
|
+
polygon: new Set(['points']),
|
|
215
|
+
polyline: new Set(['points']),
|
|
216
|
+
rect: new Set(['x', 'y', 'width', 'height', 'rx', 'ry']),
|
|
217
|
+
};
|
|
218
|
+
// Presentational attributes supported by tags
|
|
219
|
+
exports.tagSpecificPresentationalAttributes = {
|
|
220
|
+
// SVG
|
|
221
|
+
svg: new Set(['width', 'height', ...exports.presentationalAttributes]),
|
|
222
|
+
// Defnitions, containers and masks
|
|
223
|
+
clipPath: new Set([...exports.presentationalAttributes]),
|
|
224
|
+
defs: new Set([...exports.presentationalAttributes]),
|
|
225
|
+
g: new Set([...exports.presentationalAttributes]),
|
|
226
|
+
mask: new Set(['x', 'y', 'width', 'height', ...exports.presentationalAttributes]),
|
|
227
|
+
symbol: new Set(['x', 'y', 'width', 'height', ...exports.presentationalAttributes]),
|
|
228
|
+
// Use
|
|
229
|
+
use: new Set([
|
|
230
|
+
'x',
|
|
231
|
+
'y',
|
|
232
|
+
'width',
|
|
233
|
+
'height',
|
|
234
|
+
'refX',
|
|
235
|
+
'refY',
|
|
236
|
+
...exports.presentationalAttributes,
|
|
237
|
+
]),
|
|
238
|
+
// Marker
|
|
239
|
+
marker: new Set([...exports.presentationalAttributes]),
|
|
240
|
+
// Gradients
|
|
241
|
+
linearGradient: new Set([
|
|
242
|
+
'x1',
|
|
243
|
+
'x2',
|
|
244
|
+
'y1',
|
|
245
|
+
'y2',
|
|
246
|
+
...exports.presentationalAttributes,
|
|
247
|
+
]),
|
|
248
|
+
radialGradient: new Set([
|
|
249
|
+
'cx',
|
|
250
|
+
'cy',
|
|
251
|
+
'fr',
|
|
252
|
+
'fx',
|
|
253
|
+
'fy',
|
|
254
|
+
'r',
|
|
255
|
+
...exports.presentationalAttributes,
|
|
256
|
+
]),
|
|
257
|
+
stop: new Set(['offset', 'stop-color', 'stop-opacity']),
|
|
258
|
+
// Filters
|
|
259
|
+
feFlood: new Set(['flood-color', 'flood-opacity']),
|
|
260
|
+
feDropShadow: new Set(['flood-color', 'flood-opacity']),
|
|
261
|
+
};
|
|
262
|
+
tags_1.shapeTags.forEach((tag) => {
|
|
263
|
+
exports.tagSpecificPresentationalAttributes[tag] = new Set([
|
|
264
|
+
...exports.presentationalAttributes,
|
|
265
|
+
...exports.markerAttributes,
|
|
266
|
+
...(exports.tagSpecificPresentationalAttributes[tag] || []),
|
|
267
|
+
]);
|
|
268
|
+
});
|
|
269
|
+
tags_1.filterChildTags.forEach((tag) => {
|
|
270
|
+
exports.tagSpecificPresentationalAttributes[tag] = new Set([
|
|
271
|
+
...exports.commonFeAttributes,
|
|
272
|
+
...(exports.tagSpecificPresentationalAttributes[tag] || []),
|
|
273
|
+
]);
|
|
274
|
+
});
|
|
275
|
+
// Non-presentational attributes supported by tags
|
|
276
|
+
exports.tagSpecificNonPresentationalAttributes = {
|
|
277
|
+
// SVG
|
|
278
|
+
svg: new Set(['xmlns', 'viewBox', 'preserveAspectRatio']),
|
|
279
|
+
// Defnitions, containers and masks
|
|
280
|
+
clipPath: new Set(['clipPathUnits']),
|
|
281
|
+
mask: new Set(['maskContentUnits', 'maskUnits']),
|
|
282
|
+
symbol: new Set(['viewBox', 'preserveAspectRatio']),
|
|
283
|
+
// Shapes
|
|
284
|
+
circle: new Set([...exports.otherShapeAttributes]),
|
|
285
|
+
ellipse: new Set([...exports.otherShapeAttributes]),
|
|
286
|
+
line: new Set([...exports.otherShapeAttributes]),
|
|
287
|
+
path: new Set([...exports.otherShapeAttributes]),
|
|
288
|
+
polygon: new Set([...exports.otherShapeAttributes]),
|
|
289
|
+
polyline: new Set([...exports.otherShapeAttributes]),
|
|
290
|
+
rect: new Set([...exports.otherShapeAttributes]),
|
|
291
|
+
// Use
|
|
292
|
+
use: new Set(['href']),
|
|
293
|
+
// Marker
|
|
294
|
+
marker: new Set([
|
|
295
|
+
'markerHeight',
|
|
296
|
+
'markerUnits',
|
|
297
|
+
'markerWidth',
|
|
298
|
+
'orient',
|
|
299
|
+
'preserveAspectRatio',
|
|
300
|
+
'refX',
|
|
301
|
+
'refY',
|
|
302
|
+
'viewBox',
|
|
303
|
+
]),
|
|
304
|
+
// Animations
|
|
305
|
+
animate: new Set([
|
|
306
|
+
...exports.animationTimingAttributes,
|
|
307
|
+
...exports.animationValueAttributes,
|
|
308
|
+
...exports.otherAnimationAttributes,
|
|
309
|
+
]),
|
|
310
|
+
animateMotion: new Set([
|
|
311
|
+
'keyPoints',
|
|
312
|
+
'path',
|
|
313
|
+
'rotate',
|
|
314
|
+
...exports.animationTimingAttributes,
|
|
315
|
+
...exports.animationValueAttributes,
|
|
316
|
+
...exports.otherAnimationAttributes,
|
|
317
|
+
]),
|
|
318
|
+
animateTransform: new Set([
|
|
319
|
+
'by',
|
|
320
|
+
'from',
|
|
321
|
+
'to',
|
|
322
|
+
'type',
|
|
323
|
+
...exports.animationTimingAttributes,
|
|
324
|
+
...exports.animationValueAttributes,
|
|
325
|
+
...exports.otherAnimationAttributes,
|
|
326
|
+
]),
|
|
327
|
+
discard: new Set(['begin', 'href']),
|
|
328
|
+
set: new Set([
|
|
329
|
+
'to',
|
|
330
|
+
...exports.animationTimingAttributes,
|
|
331
|
+
...exports.otherAnimationAttributes,
|
|
332
|
+
]),
|
|
333
|
+
mpath: new Set(['href']),
|
|
334
|
+
// Gradients
|
|
335
|
+
linearGradient: new Set([...exports.commonGradientAttributes]),
|
|
336
|
+
radialGradient: new Set([...exports.commonGradientAttributes]),
|
|
337
|
+
// Filters
|
|
338
|
+
feSpotLight: new Set([
|
|
339
|
+
'x',
|
|
340
|
+
'y',
|
|
341
|
+
'z',
|
|
342
|
+
'pointsAtX',
|
|
343
|
+
'pointsAtY',
|
|
344
|
+
'pointsAtZ',
|
|
345
|
+
'specularExponent',
|
|
346
|
+
'limitingConeAngle',
|
|
347
|
+
]),
|
|
348
|
+
feBlend: new Set(['in', 'in2', 'mode']),
|
|
349
|
+
feColorMatrix: new Set(['in', 'type', 'values']),
|
|
350
|
+
feComponentTransfer: new Set(['in']),
|
|
351
|
+
feComposite: new Set(['in', 'in2', 'operator', 'k1', 'k2', 'k3', 'k4']),
|
|
352
|
+
feConvolveMatrix: new Set([
|
|
353
|
+
'in',
|
|
354
|
+
'order',
|
|
355
|
+
'kernelMatrix',
|
|
356
|
+
'divisor',
|
|
357
|
+
'bias',
|
|
358
|
+
'targetX',
|
|
359
|
+
'targetY',
|
|
360
|
+
'edgeMode',
|
|
361
|
+
'kernelUnitLength',
|
|
362
|
+
'preserveAlpha',
|
|
363
|
+
]),
|
|
364
|
+
feDiffuseLighting: new Set([
|
|
365
|
+
'in',
|
|
366
|
+
'surfaceScale',
|
|
367
|
+
'diffuseConstant',
|
|
368
|
+
'kernelUnitLength',
|
|
369
|
+
]),
|
|
370
|
+
feDisplacementMap: new Set([
|
|
371
|
+
'in',
|
|
372
|
+
'in2',
|
|
373
|
+
'scale',
|
|
374
|
+
'xChannelSelector',
|
|
375
|
+
'yChannelSelector',
|
|
376
|
+
]),
|
|
377
|
+
feDistantLight: new Set(['azimuth', 'elevation']),
|
|
378
|
+
feDropShadow: new Set(['dx', 'dy', 'stdDeviation']),
|
|
379
|
+
feGaussianBlur: new Set(['in', 'stdDeviation', 'edgeMode']),
|
|
380
|
+
feFuncA: exports.feFuncAttributes,
|
|
381
|
+
feFuncR: exports.feFuncAttributes,
|
|
382
|
+
feFuncG: exports.feFuncAttributes,
|
|
383
|
+
feFuncB: exports.feFuncAttributes,
|
|
384
|
+
feMergeNode: new Set(['in']),
|
|
385
|
+
feMorphology: new Set(['in', 'operator', 'radius']),
|
|
386
|
+
feOffset: new Set(['in', 'dx', 'dy']),
|
|
387
|
+
fePointLight: new Set(['x', 'y', 'z']),
|
|
388
|
+
feSpecularLighting: new Set([
|
|
389
|
+
'in',
|
|
390
|
+
'surfaceScale',
|
|
391
|
+
'specularConstant',
|
|
392
|
+
'specularExponent',
|
|
393
|
+
'kernelUnitLength',
|
|
394
|
+
]),
|
|
395
|
+
feTile: new Set(['in']),
|
|
396
|
+
feTurbulence: new Set([
|
|
397
|
+
'baseFrequency',
|
|
398
|
+
'numOctaves',
|
|
399
|
+
'seed',
|
|
400
|
+
'stitchTiles',
|
|
401
|
+
'type',
|
|
402
|
+
]),
|
|
403
|
+
};
|