@utrecht/web-component-library-stencil 1.0.0-alpha.124 → 1.0.0-alpha.128
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/dist/cjs/{index-06c6c66f.js → index-8cef21e1.js} +67 -58
- package/dist/cjs/loader.cjs.js +3 -3
- package/dist/cjs/utrecht-article.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-backdrop.cjs.entry.js +21 -0
- package/dist/cjs/utrecht-badge-counter.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-badge-data.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-badge-status.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-breadcrumb.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-button_2.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-checkbox.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-contact-card-template.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-custom-checkbox.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-digid-button.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-document.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-eherkenning-logo.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-eidas-logo.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-form-field-checkbox.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-form-field-description.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-form-field-textarea.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-form-field-textbox.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-form-toggle.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-heading-1.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-heading-2_3.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-heading-4.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-heading-5.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-heading-6.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-heading.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-html-content.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-afval.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-arrow.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-checkmark.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-cross.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-error.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-facebook.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-filter.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-information.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-instagram.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-linkedin.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-list.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-loupe.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-melding.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-paspoort.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-rijbewijs.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-toeslag.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-trouwen.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-twitter.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-verhuizen.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-warning.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-whatsapp.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-zoomin.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-icon-zoomout.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-logo-button.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-logo.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-page-content.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-page-footer.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-page-header.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-page.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-pagination.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-separator.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-sidenav.cjs.entry.js +1 -1
- package/dist/cjs/utrecht-textbox.cjs.entry.js +1 -1
- package/dist/cjs/utrecht.cjs.js +3 -3
- package/dist/collection/backdrop/bem.js +12 -0
- package/dist/collection/backdrop/checkerboard.js +20 -0
- package/dist/collection/backdrop/stencil.css +33 -0
- package/dist/collection/backdrop/stencil.js +40 -0
- package/dist/collection/collection-manifest.json +3 -2
- package/dist/collection/node_modules/svgo/dist/svgo.browser.js +1 -1
- package/dist/collection/node_modules/svgo/lib/stringifier.js +326 -0
- package/dist/collection/node_modules/svgo/lib/svgo/coa.js +23 -21
- package/dist/collection/node_modules/svgo/lib/svgo/plugins.js +16 -0
- package/dist/collection/node_modules/svgo/lib/svgo-node.js +21 -14
- package/dist/collection/node_modules/svgo/lib/svgo.js +2 -5
- package/dist/collection/node_modules/svgo/plugins/inlineStyles.js +334 -259
- package/dist/collection/node_modules/svgo/plugins/prefixIds.js +9 -8
- package/dist/collection/node_modules/svgo/plugins/removeEmptyAttrs.js +19 -19
- package/dist/collection/node_modules/svgo/plugins/removeXMLNS.js +1 -0
- package/dist/custom-elements/index.d.ts +6 -0
- package/dist/custom-elements/index.js +121 -104
- package/dist/esm/{index-d3aa9623.js → index-dbad55a3.js} +67 -58
- package/dist/esm/loader.js +3 -3
- package/dist/esm/utrecht-article.entry.js +1 -1
- package/dist/esm/utrecht-backdrop.entry.js +17 -0
- package/dist/esm/utrecht-badge-counter.entry.js +1 -1
- package/dist/esm/utrecht-badge-data.entry.js +1 -1
- package/dist/esm/utrecht-badge-status.entry.js +1 -1
- package/dist/esm/utrecht-breadcrumb.entry.js +1 -1
- package/dist/esm/utrecht-button_2.entry.js +1 -1
- package/dist/esm/utrecht-checkbox.entry.js +1 -1
- package/dist/esm/utrecht-contact-card-template.entry.js +1 -1
- package/dist/esm/utrecht-custom-checkbox.entry.js +1 -1
- package/dist/esm/utrecht-digid-button.entry.js +1 -1
- package/dist/esm/utrecht-document.entry.js +1 -1
- package/dist/esm/utrecht-eherkenning-logo.entry.js +1 -1
- package/dist/esm/utrecht-eidas-logo.entry.js +1 -1
- package/dist/esm/utrecht-form-field-checkbox.entry.js +1 -1
- package/dist/esm/utrecht-form-field-description.entry.js +1 -1
- package/dist/esm/utrecht-form-field-textarea.entry.js +1 -1
- package/dist/esm/utrecht-form-field-textbox.entry.js +1 -1
- package/dist/esm/utrecht-form-toggle.entry.js +1 -1
- package/dist/esm/utrecht-heading-1.entry.js +1 -1
- package/dist/esm/utrecht-heading-2_3.entry.js +1 -1
- package/dist/esm/utrecht-heading-4.entry.js +1 -1
- package/dist/esm/utrecht-heading-5.entry.js +1 -1
- package/dist/esm/utrecht-heading-6.entry.js +1 -1
- package/dist/esm/utrecht-heading.entry.js +1 -1
- package/dist/esm/utrecht-html-content.entry.js +1 -1
- package/dist/esm/utrecht-icon-afval.entry.js +1 -1
- package/dist/esm/utrecht-icon-arrow.entry.js +1 -1
- package/dist/esm/utrecht-icon-checkmark.entry.js +1 -1
- package/dist/esm/utrecht-icon-cross.entry.js +1 -1
- package/dist/esm/utrecht-icon-error.entry.js +1 -1
- package/dist/esm/utrecht-icon-facebook.entry.js +1 -1
- package/dist/esm/utrecht-icon-filter.entry.js +1 -1
- package/dist/esm/utrecht-icon-information.entry.js +1 -1
- package/dist/esm/utrecht-icon-instagram.entry.js +1 -1
- package/dist/esm/utrecht-icon-linkedin.entry.js +1 -1
- package/dist/esm/utrecht-icon-list.entry.js +1 -1
- package/dist/esm/utrecht-icon-loupe.entry.js +1 -1
- package/dist/esm/utrecht-icon-melding.entry.js +1 -1
- package/dist/esm/utrecht-icon-paspoort.entry.js +1 -1
- package/dist/esm/utrecht-icon-rijbewijs.entry.js +1 -1
- package/dist/esm/utrecht-icon-toeslag.entry.js +1 -1
- package/dist/esm/utrecht-icon-trouwen.entry.js +1 -1
- package/dist/esm/utrecht-icon-twitter.entry.js +1 -1
- package/dist/esm/utrecht-icon-verhuizen.entry.js +1 -1
- package/dist/esm/utrecht-icon-warning.entry.js +1 -1
- package/dist/esm/utrecht-icon-whatsapp.entry.js +1 -1
- package/dist/esm/utrecht-icon-zoomin.entry.js +1 -1
- package/dist/esm/utrecht-icon-zoomout.entry.js +1 -1
- package/dist/esm/utrecht-logo-button.entry.js +1 -1
- package/dist/esm/utrecht-logo.entry.js +1 -1
- package/dist/esm/utrecht-page-content.entry.js +1 -1
- package/dist/esm/utrecht-page-footer.entry.js +1 -1
- package/dist/esm/utrecht-page-header.entry.js +1 -1
- package/dist/esm/utrecht-page.entry.js +1 -1
- package/dist/esm/utrecht-pagination.entry.js +1 -1
- package/dist/esm/utrecht-separator.entry.js +1 -1
- package/dist/esm/utrecht-sidenav.entry.js +1 -1
- package/dist/esm/utrecht-textbox.entry.js +1 -1
- package/dist/esm/utrecht.js +3 -3
- package/dist/types/backdrop/stencil.d.ts +4 -0
- package/dist/types/components.d.ts +15 -0
- package/dist/utrecht/{p-80bf3205.entry.js → p-06d4e8da.entry.js} +1 -1
- package/dist/utrecht/{p-354528c0.entry.js → p-0e908b3b.entry.js} +1 -1
- package/dist/utrecht/{p-b9c4ab78.entry.js → p-12d3555b.entry.js} +1 -1
- package/dist/utrecht/{p-47c389d4.entry.js → p-180ccec7.entry.js} +1 -1
- package/dist/utrecht/{p-65f6e516.entry.js → p-19697551.entry.js} +1 -1
- package/dist/utrecht/{p-9c64026a.entry.js → p-19bb7aea.entry.js} +1 -1
- package/dist/utrecht/{p-4518d0f3.entry.js → p-1b369d6f.entry.js} +1 -1
- package/dist/utrecht/{p-09027cac.entry.js → p-2038f779.entry.js} +1 -1
- package/dist/utrecht/{p-2df1e2ae.entry.js → p-21b832ea.entry.js} +1 -1
- package/dist/utrecht/{p-1e7c7239.entry.js → p-29a17a39.entry.js} +1 -1
- package/dist/utrecht/{p-9703f352.entry.js → p-2be490d7.entry.js} +1 -1
- package/dist/utrecht/{p-5638a44d.entry.js → p-2ff6bfbb.entry.js} +1 -1
- package/dist/utrecht/{p-c856c9ea.entry.js → p-3672cbd0.entry.js} +1 -1
- package/dist/utrecht/{p-e1ff4f2f.entry.js → p-3bda190e.entry.js} +1 -1
- package/dist/utrecht/{p-0fb968c5.entry.js → p-401d2b63.entry.js} +1 -1
- package/dist/utrecht/{p-2be17af5.entry.js → p-45db7b13.entry.js} +1 -1
- package/dist/utrecht/{p-5e75593e.entry.js → p-49a2e309.entry.js} +1 -1
- package/dist/utrecht/{p-dad4cd1d.entry.js → p-585963b2.entry.js} +1 -1
- package/dist/utrecht/{p-8020e5d3.entry.js → p-5eec66c0.entry.js} +1 -1
- package/dist/utrecht/{p-8944aac6.entry.js → p-5f114e24.entry.js} +1 -1
- package/dist/utrecht/{p-09b6b28b.entry.js → p-60321853.entry.js} +1 -1
- package/dist/utrecht/{p-cd249af1.entry.js → p-673512bf.entry.js} +1 -1
- package/dist/utrecht/{p-a73c6a4a.entry.js → p-6922d6e5.entry.js} +1 -1
- package/dist/utrecht/{p-1332795f.entry.js → p-6a07112a.entry.js} +1 -1
- package/dist/utrecht/{p-a4bc0835.entry.js → p-6aec0d5e.entry.js} +1 -1
- package/dist/utrecht/{p-2d57d061.entry.js → p-72670926.entry.js} +1 -1
- package/dist/utrecht/{p-5961e7e7.entry.js → p-7468ce00.entry.js} +1 -1
- package/dist/utrecht/{p-ad1609ac.entry.js → p-8075a496.entry.js} +1 -1
- package/dist/utrecht/{p-dfe6f633.entry.js → p-84481a4b.entry.js} +1 -1
- package/dist/utrecht/{p-3f06bf41.entry.js → p-8856bd84.entry.js} +1 -1
- package/dist/utrecht/{p-28bc1d4c.entry.js → p-88e09f6e.entry.js} +1 -1
- package/dist/utrecht/{p-177f47d2.entry.js → p-99d68ed5.entry.js} +1 -1
- package/dist/utrecht/{p-a5f53756.entry.js → p-9a7712ee.entry.js} +1 -1
- package/dist/utrecht/{p-bb949c54.entry.js → p-9bde6988.entry.js} +1 -1
- package/dist/utrecht/p-a41d30a7.js +1 -0
- package/dist/utrecht/{p-74336ae3.entry.js → p-a62dbf0b.entry.js} +1 -1
- package/dist/utrecht/{p-c1dd8bb0.entry.js → p-a82cf768.entry.js} +1 -1
- package/dist/utrecht/{p-0d99e925.entry.js → p-b0860b62.entry.js} +1 -1
- package/dist/utrecht/{p-7d89d47a.entry.js → p-b3aa468d.entry.js} +1 -1
- package/dist/utrecht/{p-7af4fa6d.entry.js → p-bedc995b.entry.js} +1 -1
- package/dist/utrecht/{p-31dcf33f.entry.js → p-c22f500b.entry.js} +1 -1
- package/dist/utrecht/{p-57a8d82c.entry.js → p-c314b6c1.entry.js} +1 -1
- package/dist/utrecht/{p-8bf10ece.entry.js → p-c7f7af31.entry.js} +1 -1
- package/dist/utrecht/{p-b20e7333.entry.js → p-c948bdeb.entry.js} +1 -1
- package/dist/utrecht/{p-40e0a9ed.entry.js → p-ccd0835e.entry.js} +1 -1
- package/dist/utrecht/{p-d8c61464.entry.js → p-d21af965.entry.js} +1 -1
- package/dist/utrecht/{p-42f7a543.entry.js → p-d24e72f1.entry.js} +1 -1
- package/dist/utrecht/{p-4ae308fc.entry.js → p-d5cec830.entry.js} +1 -1
- package/dist/utrecht/{p-2b3fe7c2.entry.js → p-e094341c.entry.js} +1 -1
- package/dist/utrecht/{p-685733e4.entry.js → p-e1ab41a2.entry.js} +1 -1
- package/dist/utrecht/{p-df7db7e9.entry.js → p-e8d0b7bf.entry.js} +1 -1
- package/dist/utrecht/{p-2ffbac3c.entry.js → p-e8f6c846.entry.js} +1 -1
- package/dist/utrecht/{p-9455dd17.entry.js → p-e9ae2a68.entry.js} +1 -1
- package/dist/utrecht/{p-d74b5f06.entry.js → p-ea6f5e30.entry.js} +1 -1
- package/dist/utrecht/{p-afa2eae0.entry.js → p-f0cea495.entry.js} +1 -1
- package/dist/utrecht/{p-bcc63ada.entry.js → p-f1f0a2c6.entry.js} +1 -1
- package/dist/utrecht/{p-82698d3b.entry.js → p-f2792d17.entry.js} +1 -1
- package/dist/utrecht/{p-faefee5f.entry.js → p-f47ed55e.entry.js} +1 -1
- package/dist/utrecht/p-f9337bd7.entry.js +1 -0
- package/dist/utrecht/{p-bea27e6e.entry.js → p-fb80f09f.entry.js} +1 -1
- package/dist/utrecht/utrecht.esm.js +1 -1
- package/package.json +4 -4
- package/dist/collection/node_modules/svgo/lib/svgo/js2svg.js +0 -337
- package/dist/utrecht/p-821ca495.js +0 -1
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import('./types').XastParent} XastParent
|
|
5
|
+
* @typedef {import('./types').XastRoot} XastRoot
|
|
6
|
+
* @typedef {import('./types').XastElement} XastElement
|
|
7
|
+
* @typedef {import('./types').XastInstruction} XastInstruction
|
|
8
|
+
* @typedef {import('./types').XastDoctype} XastDoctype
|
|
9
|
+
* @typedef {import('./types').XastText} XastText
|
|
10
|
+
* @typedef {import('./types').XastCdata} XastCdata
|
|
11
|
+
* @typedef {import('./types').XastComment} XastComment
|
|
12
|
+
* @typedef {import('./types').StringifyOptions} StringifyOptions
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const { textElems } = require('../plugins/_collections.js');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {{
|
|
19
|
+
* width: void | string,
|
|
20
|
+
* height: void | string,
|
|
21
|
+
* indent: string,
|
|
22
|
+
* textContext: null | XastElement,
|
|
23
|
+
* indentLevel: number,
|
|
24
|
+
* }} State
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {Required<StringifyOptions>} Options
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @type {(char: string) => string}
|
|
33
|
+
*/
|
|
34
|
+
const encodeEntity = (char) => {
|
|
35
|
+
return entities[char];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @type {Options}
|
|
40
|
+
*/
|
|
41
|
+
const defaults = {
|
|
42
|
+
doctypeStart: '<!DOCTYPE',
|
|
43
|
+
doctypeEnd: '>',
|
|
44
|
+
procInstStart: '<?',
|
|
45
|
+
procInstEnd: '?>',
|
|
46
|
+
tagOpenStart: '<',
|
|
47
|
+
tagOpenEnd: '>',
|
|
48
|
+
tagCloseStart: '</',
|
|
49
|
+
tagCloseEnd: '>',
|
|
50
|
+
tagShortStart: '<',
|
|
51
|
+
tagShortEnd: '/>',
|
|
52
|
+
attrStart: '="',
|
|
53
|
+
attrEnd: '"',
|
|
54
|
+
commentStart: '<!--',
|
|
55
|
+
commentEnd: '-->',
|
|
56
|
+
cdataStart: '<![CDATA[',
|
|
57
|
+
cdataEnd: ']]>',
|
|
58
|
+
textStart: '',
|
|
59
|
+
textEnd: '',
|
|
60
|
+
indent: 4,
|
|
61
|
+
regEntities: /[&'"<>]/g,
|
|
62
|
+
regValEntities: /[&"<>]/g,
|
|
63
|
+
encodeEntity: encodeEntity,
|
|
64
|
+
pretty: false,
|
|
65
|
+
useShortTags: true,
|
|
66
|
+
eol: 'lf',
|
|
67
|
+
finalNewline: false,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @type {Record<string, string>}
|
|
72
|
+
*/
|
|
73
|
+
const entities = {
|
|
74
|
+
'&': '&',
|
|
75
|
+
"'": ''',
|
|
76
|
+
'"': '"',
|
|
77
|
+
'>': '>',
|
|
78
|
+
'<': '<',
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* convert XAST to SVG string
|
|
83
|
+
*
|
|
84
|
+
* @type {(data: XastRoot, config: StringifyOptions) => {
|
|
85
|
+
* data: string,
|
|
86
|
+
* info: {
|
|
87
|
+
* width: void | string,
|
|
88
|
+
* height: void | string
|
|
89
|
+
* }
|
|
90
|
+
* }}
|
|
91
|
+
*/
|
|
92
|
+
const stringifySvg = (data, userOptions = {}) => {
|
|
93
|
+
/**
|
|
94
|
+
* @type {Options}
|
|
95
|
+
*/
|
|
96
|
+
const config = { ...defaults, ...userOptions };
|
|
97
|
+
const indent = config.indent;
|
|
98
|
+
let newIndent = ' ';
|
|
99
|
+
if (typeof indent === 'number' && Number.isNaN(indent) === false) {
|
|
100
|
+
newIndent = indent < 0 ? '\t' : ' '.repeat(indent);
|
|
101
|
+
} else if (typeof indent === 'string') {
|
|
102
|
+
newIndent = indent;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @type {State}
|
|
106
|
+
*/
|
|
107
|
+
const state = {
|
|
108
|
+
// TODO remove width and height in v3
|
|
109
|
+
width: undefined,
|
|
110
|
+
height: undefined,
|
|
111
|
+
indent: newIndent,
|
|
112
|
+
textContext: null,
|
|
113
|
+
indentLevel: 0,
|
|
114
|
+
};
|
|
115
|
+
const eol = config.eol === 'crlf' ? '\r\n' : '\n';
|
|
116
|
+
if (config.pretty) {
|
|
117
|
+
config.doctypeEnd += eol;
|
|
118
|
+
config.procInstEnd += eol;
|
|
119
|
+
config.commentEnd += eol;
|
|
120
|
+
config.cdataEnd += eol;
|
|
121
|
+
config.tagShortEnd += eol;
|
|
122
|
+
config.tagOpenEnd += eol;
|
|
123
|
+
config.tagCloseEnd += eol;
|
|
124
|
+
config.textEnd += eol;
|
|
125
|
+
}
|
|
126
|
+
let svg = stringifyNode(data, config, state);
|
|
127
|
+
if (config.finalNewline && svg.length > 0 && svg[svg.length - 1] !== '\n') {
|
|
128
|
+
svg += eol;
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
data: svg,
|
|
132
|
+
info: {
|
|
133
|
+
width: state.width,
|
|
134
|
+
height: state.height,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
exports.stringifySvg = stringifySvg;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @type {(node: XastParent, config: Options, state: State) => string}
|
|
142
|
+
*/
|
|
143
|
+
const stringifyNode = (data, config, state) => {
|
|
144
|
+
let svg = '';
|
|
145
|
+
state.indentLevel += 1;
|
|
146
|
+
for (const item of data.children) {
|
|
147
|
+
if (item.type === 'element') {
|
|
148
|
+
svg += stringifyElement(item, config, state);
|
|
149
|
+
}
|
|
150
|
+
if (item.type === 'text') {
|
|
151
|
+
svg += stringifyText(item, config, state);
|
|
152
|
+
}
|
|
153
|
+
if (item.type === 'doctype') {
|
|
154
|
+
svg += stringifyDoctype(item, config);
|
|
155
|
+
}
|
|
156
|
+
if (item.type === 'instruction') {
|
|
157
|
+
svg += stringifyInstruction(item, config);
|
|
158
|
+
}
|
|
159
|
+
if (item.type === 'comment') {
|
|
160
|
+
svg += stringifyComment(item, config);
|
|
161
|
+
}
|
|
162
|
+
if (item.type === 'cdata') {
|
|
163
|
+
svg += stringifyCdata(item, config, state);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
state.indentLevel -= 1;
|
|
167
|
+
return svg;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* create indent string in accordance with the current node level.
|
|
172
|
+
*
|
|
173
|
+
* @type {(config: Options, state: State) => string}
|
|
174
|
+
*/
|
|
175
|
+
const createIndent = (config, state) => {
|
|
176
|
+
let indent = '';
|
|
177
|
+
if (config.pretty && state.textContext == null) {
|
|
178
|
+
indent = state.indent.repeat(state.indentLevel - 1);
|
|
179
|
+
}
|
|
180
|
+
return indent;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @type {(node: XastDoctype, config: Options) => string}
|
|
185
|
+
*/
|
|
186
|
+
const stringifyDoctype = (node, config) => {
|
|
187
|
+
return config.doctypeStart + node.data.doctype + config.doctypeEnd;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @type {(node: XastInstruction, config: Options) => string}
|
|
192
|
+
*/
|
|
193
|
+
const stringifyInstruction = (node, config) => {
|
|
194
|
+
return (
|
|
195
|
+
config.procInstStart + node.name + ' ' + node.value + config.procInstEnd
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @type {(node: XastComment, config: Options) => string}
|
|
201
|
+
*/
|
|
202
|
+
const stringifyComment = (node, config) => {
|
|
203
|
+
return config.commentStart + node.value + config.commentEnd;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @type {(node: XastCdata, config: Options, state: State) => string}
|
|
208
|
+
*/
|
|
209
|
+
const stringifyCdata = (node, config, state) => {
|
|
210
|
+
return (
|
|
211
|
+
createIndent(config, state) +
|
|
212
|
+
config.cdataStart +
|
|
213
|
+
node.value +
|
|
214
|
+
config.cdataEnd
|
|
215
|
+
);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @type {(node: XastElement, config: Options, state: State) => string}
|
|
220
|
+
*/
|
|
221
|
+
const stringifyElement = (node, config, state) => {
|
|
222
|
+
// beautiful injection for obtaining SVG information :)
|
|
223
|
+
if (
|
|
224
|
+
node.name === 'svg' &&
|
|
225
|
+
node.attributes.width != null &&
|
|
226
|
+
node.attributes.height != null
|
|
227
|
+
) {
|
|
228
|
+
state.width = node.attributes.width;
|
|
229
|
+
state.height = node.attributes.height;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// empty element and short tag
|
|
233
|
+
if (node.children.length === 0) {
|
|
234
|
+
if (config.useShortTags) {
|
|
235
|
+
return (
|
|
236
|
+
createIndent(config, state) +
|
|
237
|
+
config.tagShortStart +
|
|
238
|
+
node.name +
|
|
239
|
+
stringifyAttributes(node, config) +
|
|
240
|
+
config.tagShortEnd
|
|
241
|
+
);
|
|
242
|
+
} else {
|
|
243
|
+
return (
|
|
244
|
+
createIndent(config, state) +
|
|
245
|
+
config.tagShortStart +
|
|
246
|
+
node.name +
|
|
247
|
+
stringifyAttributes(node, config) +
|
|
248
|
+
config.tagOpenEnd +
|
|
249
|
+
config.tagCloseStart +
|
|
250
|
+
node.name +
|
|
251
|
+
config.tagCloseEnd
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
// non-empty element
|
|
255
|
+
} else {
|
|
256
|
+
let tagOpenStart = config.tagOpenStart;
|
|
257
|
+
let tagOpenEnd = config.tagOpenEnd;
|
|
258
|
+
let tagCloseStart = config.tagCloseStart;
|
|
259
|
+
let tagCloseEnd = config.tagCloseEnd;
|
|
260
|
+
let openIndent = createIndent(config, state);
|
|
261
|
+
let closeIndent = createIndent(config, state);
|
|
262
|
+
|
|
263
|
+
if (state.textContext) {
|
|
264
|
+
tagOpenStart = defaults.tagOpenStart;
|
|
265
|
+
tagOpenEnd = defaults.tagOpenEnd;
|
|
266
|
+
tagCloseStart = defaults.tagCloseStart;
|
|
267
|
+
tagCloseEnd = defaults.tagCloseEnd;
|
|
268
|
+
openIndent = '';
|
|
269
|
+
} else if (textElems.includes(node.name)) {
|
|
270
|
+
tagOpenEnd = defaults.tagOpenEnd;
|
|
271
|
+
tagCloseStart = defaults.tagCloseStart;
|
|
272
|
+
closeIndent = '';
|
|
273
|
+
state.textContext = node;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const children = stringifyNode(node, config, state);
|
|
277
|
+
|
|
278
|
+
if (state.textContext === node) {
|
|
279
|
+
state.textContext = null;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return (
|
|
283
|
+
openIndent +
|
|
284
|
+
tagOpenStart +
|
|
285
|
+
node.name +
|
|
286
|
+
stringifyAttributes(node, config) +
|
|
287
|
+
tagOpenEnd +
|
|
288
|
+
children +
|
|
289
|
+
closeIndent +
|
|
290
|
+
tagCloseStart +
|
|
291
|
+
node.name +
|
|
292
|
+
tagCloseEnd
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* @type {(node: XastElement, config: Options) => string}
|
|
299
|
+
*/
|
|
300
|
+
const stringifyAttributes = (node, config) => {
|
|
301
|
+
let attrs = '';
|
|
302
|
+
for (const [name, value] of Object.entries(node.attributes)) {
|
|
303
|
+
// TODO remove attributes without values support in v3
|
|
304
|
+
if (value !== undefined) {
|
|
305
|
+
const encodedValue = value
|
|
306
|
+
.toString()
|
|
307
|
+
.replace(config.regValEntities, config.encodeEntity);
|
|
308
|
+
attrs += ' ' + name + config.attrStart + encodedValue + config.attrEnd;
|
|
309
|
+
} else {
|
|
310
|
+
attrs += ' ' + name;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return attrs;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* @type {(node: XastText, config: Options, state: State) => string}
|
|
318
|
+
*/
|
|
319
|
+
const stringifyText = (node, config, state) => {
|
|
320
|
+
return (
|
|
321
|
+
createIndent(config, state) +
|
|
322
|
+
config.textStart +
|
|
323
|
+
node.value.replace(config.regEntities, config.encodeEntity) +
|
|
324
|
+
(state.textContext ? '' : config.textEnd)
|
|
325
|
+
);
|
|
326
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const colors = require('picocolors');
|
|
6
6
|
const { loadConfig, optimize } = require('../svgo-node.js');
|
|
7
7
|
const pluginsMap = require('../../plugins/plugins.js');
|
|
8
8
|
const PKG = require('../../package.json');
|
|
@@ -16,7 +16,7 @@ const regSVGFile = /\.svg$/i;
|
|
|
16
16
|
*/
|
|
17
17
|
function checkIsDir(path) {
|
|
18
18
|
try {
|
|
19
|
-
return
|
|
19
|
+
return fs.lstatSync(path).isDirectory();
|
|
20
20
|
} catch (e) {
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
@@ -73,6 +73,8 @@ module.exports = function makeProgram(program) {
|
|
|
73
73
|
'Only output error messages, not regular status messages'
|
|
74
74
|
)
|
|
75
75
|
.option('--show-plugins', 'Show available plugins and exit')
|
|
76
|
+
// used by picocolors internally
|
|
77
|
+
.option('--no-color', 'Output plain text without color')
|
|
76
78
|
.action(action);
|
|
77
79
|
};
|
|
78
80
|
|
|
@@ -218,7 +220,7 @@ async function action(args, opts, command) {
|
|
|
218
220
|
for (var i = 0; i < input.length; i++) {
|
|
219
221
|
output[i] = checkIsDir(input[i])
|
|
220
222
|
? input[i]
|
|
221
|
-
:
|
|
223
|
+
: path.resolve(dir, path.basename(input[i]));
|
|
222
224
|
}
|
|
223
225
|
} else if (output.length < input.length) {
|
|
224
226
|
output = output.concat(input.slice(output.length));
|
|
@@ -283,7 +285,7 @@ function optimizeFolder(config, dir, output) {
|
|
|
283
285
|
if (!config.quiet) {
|
|
284
286
|
console.log(`Processing directory '${dir}':\n`);
|
|
285
287
|
}
|
|
286
|
-
return
|
|
288
|
+
return fs.promises
|
|
287
289
|
.readdir(dir)
|
|
288
290
|
.then((files) => processDirectory(config, dir, files, output));
|
|
289
291
|
}
|
|
@@ -331,19 +333,19 @@ function getFilesDescriptions(config, dir, files, output) {
|
|
|
331
333
|
!config.exclude.some((regExclude) => regExclude.test(name))
|
|
332
334
|
)
|
|
333
335
|
.map((name) => ({
|
|
334
|
-
inputPath:
|
|
335
|
-
outputPath:
|
|
336
|
+
inputPath: path.resolve(dir, name),
|
|
337
|
+
outputPath: path.resolve(output, name),
|
|
336
338
|
}));
|
|
337
339
|
|
|
338
340
|
return config.recursive
|
|
339
341
|
? [].concat(
|
|
340
342
|
filesInThisFolder,
|
|
341
343
|
files
|
|
342
|
-
.filter((name) => checkIsDir(
|
|
344
|
+
.filter((name) => checkIsDir(path.resolve(dir, name)))
|
|
343
345
|
.map((subFolderName) => {
|
|
344
|
-
const subFolderPath =
|
|
345
|
-
const subFolderFiles =
|
|
346
|
-
const subFolderOutput =
|
|
346
|
+
const subFolderPath = path.resolve(dir, subFolderName);
|
|
347
|
+
const subFolderFiles = fs.readdirSync(subFolderPath);
|
|
348
|
+
const subFolderOutput = path.resolve(output, subFolderName);
|
|
347
349
|
return getFilesDescriptions(
|
|
348
350
|
config,
|
|
349
351
|
subFolderPath,
|
|
@@ -364,7 +366,7 @@ function getFilesDescriptions(config, dir, files, output) {
|
|
|
364
366
|
* @return {Promise}
|
|
365
367
|
*/
|
|
366
368
|
function optimizeFile(config, file, output) {
|
|
367
|
-
return
|
|
369
|
+
return fs.promises.readFile(file, 'utf8').then(
|
|
368
370
|
(data) =>
|
|
369
371
|
processSVGData(config, { input: 'file', path: file }, data, output, file),
|
|
370
372
|
(error) => checkOptimizeFileError(config, file, output, error)
|
|
@@ -385,7 +387,7 @@ function processSVGData(config, info, data, output, input) {
|
|
|
385
387
|
|
|
386
388
|
const result = optimize(data, { ...config, ...info });
|
|
387
389
|
if (result.modernError) {
|
|
388
|
-
console.error(red(result.modernError.toString()));
|
|
390
|
+
console.error(colors.red(result.modernError.toString()));
|
|
389
391
|
process.exit(1);
|
|
390
392
|
}
|
|
391
393
|
if (config.datauri) {
|
|
@@ -398,7 +400,7 @@ function processSVGData(config, info, data, output, input) {
|
|
|
398
400
|
function () {
|
|
399
401
|
if (!config.quiet && output != '-') {
|
|
400
402
|
if (input) {
|
|
401
|
-
console.log(`\n${
|
|
403
|
+
console.log(`\n${path.basename(input)}:`);
|
|
402
404
|
}
|
|
403
405
|
printTimeInfo(processingTime);
|
|
404
406
|
printProfitInfo(prevFileSize, resultFileSize);
|
|
@@ -428,9 +430,9 @@ function writeOutput(input, output, data) {
|
|
|
428
430
|
return Promise.resolve();
|
|
429
431
|
}
|
|
430
432
|
|
|
431
|
-
|
|
433
|
+
fs.mkdirSync(path.dirname(output), { recursive: true });
|
|
432
434
|
|
|
433
|
-
return
|
|
435
|
+
return fs.promises
|
|
434
436
|
.writeFile(output, data, 'utf8')
|
|
435
437
|
.catch((error) => checkWriteFileError(input, output, data, error));
|
|
436
438
|
}
|
|
@@ -455,7 +457,7 @@ function printProfitInfo(inBytes, outBytes) {
|
|
|
455
457
|
Math.round((inBytes / 1024) * 1000) / 1000 +
|
|
456
458
|
' KiB' +
|
|
457
459
|
(profitPercents < 0 ? ' + ' : ' - ') +
|
|
458
|
-
green(Math.abs(Math.round(profitPercents * 10) / 10) + '%') +
|
|
460
|
+
colors.green(Math.abs(Math.round(profitPercents * 10) / 10) + '%') +
|
|
459
461
|
' = ' +
|
|
460
462
|
Math.round((outBytes / 1024) * 1000) / 1000 +
|
|
461
463
|
' KiB'
|
|
@@ -491,8 +493,8 @@ function checkOptimizeFileError(config, input, output, error) {
|
|
|
491
493
|
*/
|
|
492
494
|
function checkWriteFileError(input, output, data, error) {
|
|
493
495
|
if (error.code == 'EISDIR' && input) {
|
|
494
|
-
return
|
|
495
|
-
|
|
496
|
+
return fs.promises.writeFile(
|
|
497
|
+
path.resolve(output, path.basename(input)),
|
|
496
498
|
data,
|
|
497
499
|
'utf8'
|
|
498
500
|
);
|
|
@@ -507,7 +509,7 @@ function checkWriteFileError(input, output, data, error) {
|
|
|
507
509
|
function showAvailablePlugins() {
|
|
508
510
|
const list = Object.entries(pluginsMap)
|
|
509
511
|
.sort(([a], [b]) => a.localeCompare(b))
|
|
510
|
-
.map(([name, plugin]) => ` [ ${green(name)} ] ${plugin.description}`)
|
|
512
|
+
.map(([name, plugin]) => ` [ ${colors.green(name)} ] ${plugin.description}`)
|
|
511
513
|
.join('\n');
|
|
512
514
|
console.log('Currently available plugins:\n' + list);
|
|
513
515
|
}
|
|
@@ -86,6 +86,22 @@ const createPreset = ({ name, plugins }) => {
|
|
|
86
86
|
if (floatPrecision != null) {
|
|
87
87
|
globalOverrides.floatPrecision = floatPrecision;
|
|
88
88
|
}
|
|
89
|
+
if (overrides) {
|
|
90
|
+
for (const [pluginName, override] of Object.entries(overrides)) {
|
|
91
|
+
if (override === true) {
|
|
92
|
+
console.warn(
|
|
93
|
+
`You are trying to enable ${pluginName} which is not part of preset.\n` +
|
|
94
|
+
`Try to put it before or after preset, for example\n\n` +
|
|
95
|
+
`plugins: [\n` +
|
|
96
|
+
` {\n` +
|
|
97
|
+
` name: 'preset-default',\n` +
|
|
98
|
+
` },\n` +
|
|
99
|
+
` 'cleanupListOfValues'\n` +
|
|
100
|
+
`]\n`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
89
105
|
return invokePlugins(ast, info, plugins, overrides, globalOverrides);
|
|
90
106
|
},
|
|
91
107
|
};
|
|
@@ -15,21 +15,28 @@ exports.createContentItem = createContentItem;
|
|
|
15
15
|
|
|
16
16
|
const importConfig = async (configFile) => {
|
|
17
17
|
let config;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
config =
|
|
23
|
-
}
|
|
24
|
-
// TODO remove require in v3
|
|
18
|
+
// at the moment dynamic import may randomly fail with segfault
|
|
19
|
+
// to workaround this for some users .cjs extension is loaded
|
|
20
|
+
// exclusively with require
|
|
21
|
+
if (configFile.endsWith('.cjs')) {
|
|
22
|
+
config = require(configFile);
|
|
23
|
+
} else {
|
|
25
24
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
// dynamic import expects file url instead of path and may fail
|
|
26
|
+
// when windows path is provided
|
|
27
|
+
const { default: imported } = await import(pathToFileURL(configFile));
|
|
28
|
+
config = imported;
|
|
29
|
+
} catch (importError) {
|
|
30
|
+
// TODO remove require in v3
|
|
31
|
+
try {
|
|
32
|
+
config = require(configFile);
|
|
33
|
+
} catch (requireError) {
|
|
34
|
+
// throw original error if es module is detected
|
|
35
|
+
if (requireError.code === 'ERR_REQUIRE_ESM') {
|
|
36
|
+
throw importError;
|
|
37
|
+
} else {
|
|
38
|
+
throw requireError;
|
|
39
|
+
}
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
}
|
|
@@ -6,7 +6,7 @@ const {
|
|
|
6
6
|
extendDefaultPlugins,
|
|
7
7
|
} = require('./svgo/config.js');
|
|
8
8
|
const { parseSvg } = require('./parser.js');
|
|
9
|
-
const
|
|
9
|
+
const { stringifySvg } = require('./stringifier.js');
|
|
10
10
|
const { invokePlugins } = require('./svgo/plugins.js');
|
|
11
11
|
const JSAPI = require('./svgo/jsAPI.js');
|
|
12
12
|
const { encodeSVGDatauri } = require('./svgo/tools.js');
|
|
@@ -53,10 +53,7 @@ const optimize = (input, config) => {
|
|
|
53
53
|
globalOverrides.floatPrecision = config.floatPrecision;
|
|
54
54
|
}
|
|
55
55
|
svgjs = invokePlugins(svgjs, info, resolvedPlugins, null, globalOverrides);
|
|
56
|
-
svgjs =
|
|
57
|
-
if (svgjs.error) {
|
|
58
|
-
throw Error(svgjs.error);
|
|
59
|
-
}
|
|
56
|
+
svgjs = stringifySvg(svgjs, config.js2svg);
|
|
60
57
|
if (svgjs.data.length < prevResultSize) {
|
|
61
58
|
input = svgjs.data;
|
|
62
59
|
prevResultSize = svgjs.data.length;
|