soaring-symbols 0.2.1 → 0.2.3
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/API.md +30 -19
- package/README.md +19 -12
- package/dist/airlines.json +1 -1
- package/dist/assets/air-arabia/icon-mono.svg +1 -1
- package/dist/assets/air-arabia/icon.svg +1 -1
- package/dist/assets/air-berlin/icon-mono.svg +1 -1
- package/dist/assets/air-berlin/icon.svg +1 -1
- package/dist/assets/air-berlin/logo-mono.svg +1 -1
- package/dist/assets/air-berlin/logo.svg +1 -1
- package/dist/assets/airasia-cambodia/logo-mono.svg +1 -0
- package/dist/assets/airasia-cambodia/logo.svg +1 -0
- package/dist/assets/american-airlines/icon.svg +1 -1
- package/dist/assets/american-airlines/logo.svg +1 -1
- package/dist/assets/austrian-airlines/logo.svg +1 -1
- package/dist/assets/avianca-costa-rica/icon-mono.svg +1 -0
- package/dist/assets/avianca-costa-rica/icon.svg +1 -0
- package/dist/assets/avianca-costa-rica/logo-mono.svg +1 -0
- package/dist/assets/avianca-costa-rica/logo.svg +1 -0
- package/dist/assets/avianca-ecuador/icon-mono.svg +1 -0
- package/dist/assets/avianca-ecuador/icon.svg +1 -0
- package/dist/assets/avianca-ecuador/logo-mono.svg +1 -0
- package/dist/assets/avianca-ecuador/logo.svg +1 -0
- package/dist/assets/avianca-el-salvador/icon-mono.svg +1 -0
- package/dist/assets/avianca-el-salvador/icon.svg +1 -0
- package/dist/assets/avianca-el-salvador/logo-mono.svg +1 -0
- package/dist/assets/avianca-el-salvador/logo.svg +1 -0
- package/dist/assets/azul/icon.svg +1 -1
- package/dist/assets/binter/logo-mono.svg +1 -0
- package/dist/assets/binter/logo.svg +1 -0
- package/dist/assets/cebu-pacific/icon.svg +1 -1
- package/dist/assets/cebu-pacific/logo.svg +1 -1
- package/dist/assets/china-airlines/logo.svg +1 -1
- package/dist/assets/china-eastern-airlines/icon.svg +1 -1
- package/dist/assets/china-southern-airlines/tail.svg +1 -1
- package/dist/assets/condor/icon-mono.svg +1 -1
- package/dist/assets/condor/icon.svg +1 -1
- package/dist/assets/condor/logo-mono.svg +1 -1
- package/dist/assets/condor/logo.svg +1 -1
- package/dist/assets/delta-air-lines/icon-mono.svg +1 -1
- package/dist/assets/easyjet/logo-mono.svg +1 -1
- package/dist/assets/easyjet/logo.svg +1 -1
- package/dist/assets/egyptair/icon-mono.svg +1 -1
- package/dist/assets/egyptair/icon.svg +1 -1
- package/dist/assets/flybe/logo-mono.svg +1 -1
- package/dist/assets/flybe/logo.svg +1 -1
- package/dist/assets/frontier-airlines/icon-mono.svg +1 -1
- package/dist/assets/frontier-airlines/icon.svg +1 -1
- package/dist/assets/gol/logo.svg +1 -1
- package/dist/assets/hawaiian-airlines/icon.svg +1 -1
- package/dist/assets/hawaiian-airlines/logo.svg +1 -1
- package/dist/assets/indonesia-airasia/logo-mono.svg +1 -0
- package/dist/assets/indonesia-airasia/logo.svg +1 -0
- package/dist/assets/ita-airways/logo.svg +1 -1
- package/dist/assets/jet2com/icon-mono.svg +1 -1
- package/dist/assets/jet2com/icon.svg +1 -1
- package/dist/assets/jetstar-japan/icon-mono.svg +1 -0
- package/dist/assets/jetstar-japan/icon.svg +1 -0
- package/dist/assets/jetstar-japan/logo-mono.svg +1 -0
- package/dist/assets/jetstar-japan/logo.svg +1 -0
- package/dist/assets/juneyao-air/icon-mono.svg +1 -0
- package/dist/assets/juneyao-air/icon.svg +1 -0
- package/dist/assets/juneyao-air/logo-mono.svg +1 -0
- package/dist/assets/juneyao-air/logo.svg +1 -0
- package/dist/assets/latam-airlines-brasil/icon-mono.svg +1 -0
- package/dist/assets/latam-airlines-brasil/icon.svg +1 -0
- package/dist/assets/latam-airlines-brasil/logo-mono.svg +1 -0
- package/dist/assets/latam-airlines-brasil/logo.svg +1 -0
- package/dist/assets/latam-airlines-colombia/icon-mono.svg +1 -0
- package/dist/assets/latam-airlines-colombia/icon.svg +1 -0
- package/dist/assets/latam-airlines-colombia/logo-mono.svg +1 -0
- package/dist/assets/latam-airlines-colombia/logo.svg +1 -0
- package/dist/assets/latam-airlines-ecuador/icon-mono.svg +1 -0
- package/dist/assets/latam-airlines-ecuador/icon.svg +1 -0
- package/dist/assets/latam-airlines-ecuador/logo-mono.svg +1 -0
- package/dist/assets/latam-airlines-ecuador/logo.svg +1 -0
- package/dist/assets/latam-airlines-paraguay/icon-mono.svg +1 -0
- package/dist/assets/latam-airlines-paraguay/icon.svg +1 -0
- package/dist/assets/latam-airlines-paraguay/logo-mono.svg +1 -0
- package/dist/assets/latam-airlines-paraguay/logo.svg +1 -0
- package/dist/assets/latam-airlines-peru/icon-mono.svg +1 -0
- package/dist/assets/latam-airlines-peru/icon.svg +1 -0
- package/dist/assets/latam-airlines-peru/logo-mono.svg +1 -0
- package/dist/assets/latam-airlines-peru/logo.svg +1 -0
- package/dist/assets/level/icon.svg +1 -0
- package/dist/assets/level/logo.svg +1 -0
- package/dist/assets/lion-air/icon-mono.svg +1 -1
- package/dist/assets/lion-air/icon.svg +1 -1
- package/dist/assets/norwegian-air-shuttle/icon.svg +1 -1
- package/dist/assets/norwegian-air-shuttle/logo-mono.svg +1 -1
- package/dist/assets/norwegian-air-shuttle/logo.svg +1 -1
- package/dist/assets/pegasus-airlines/icon-mono.svg +1 -1
- package/dist/assets/pegasus-airlines/icon.svg +1 -1
- package/dist/assets/philippines-airasia/logo-mono.svg +1 -0
- package/dist/assets/philippines-airasia/logo.svg +1 -0
- package/dist/assets/sas-connect/logo-mono.svg +1 -0
- package/dist/assets/sas-connect/logo.svg +1 -0
- package/dist/assets/spirit-airlines/logo-mono.svg +1 -1
- package/dist/assets/spirit-airlines/logo.svg +1 -1
- package/dist/assets/thai-airasia/logo-mono.svg +1 -0
- package/dist/assets/thai-airasia/logo.svg +1 -0
- package/dist/assets/viva/icon-mono.svg +1 -1
- package/dist/assets/viva/icon.svg +1 -1
- package/dist/assets/volaris/icon.svg +1 -1
- package/dist/assets/vueling/logo.svg +1 -1
- package/dist/assets/winair/logo-mono.svg +1 -0
- package/dist/assets/winair/logo.svg +1 -0
- package/dist/assets/wizz-air-abu-dhabi/logo-mono.svg +1 -0
- package/dist/assets/wizz-air-abu-dhabi/logo.svg +1 -0
- package/dist/assets/wizz-air-uk/logo-mono.svg +1 -0
- package/dist/assets/wizz-air-uk/logo.svg +1 -0
- package/dist/index.d.cts +7 -11
- package/dist/index.d.ts +7 -11
- package/dist/svg-validator.cjs +382 -5
- package/dist/svg-validator.d.cts +12 -0
- package/dist/svg-validator.d.ts +12 -0
- package/dist/svg-validator.js +382 -5
- package/package.json +4 -3
- package/AIRLINES.md +0 -144
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg role="img" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg" fill="#c6007e"><title>Wizz Air UK</title><path d="M47.0309 27.7145h6.1822l-7.322 9.5786H39.706Zm-.4653-.9356-7.783 10.1849a.7623.7623 0 0 0-.0805.8212c.1316.2682.4099.4422.7047.4422h6.9481l7.8463-10.2625a.7513.7513 0 0 0 .074-.7802.7393.7393 0 0 0-.6687-.4056Zm-22.2271-4.9784a.2287.2287 0 0 1 .197-.1122H28.59l.5825-3.3475a.2193.2193 0 0 1 .2193-.1769l3.7948-.0029c.0697 0 .1258.0208.166.0662a.2409.2409 0 0 1 .0526.1819l-.3775 2.166 17.8398.013c.0963 0 .1654.0582.1992.1143.0208.0417.0489.1258-.0093.2049l-1.6108 2.1034 13.2216-.0036c.077 0 .1316.049.154.0913a.1431.1431 0 0 1-.0015.1554L51.8317 37.6412c-.1251.1567-.1194.5551-.0323.7248.0906.1712.4041.4157.6004.4157l7.729.0086a.2165.2165 0 0 1 .2165.2495l-.5875 3.3619a.2193.2193 0 0 1-.2193.1762H30.1317l-.4833-.003a2.7384 2.7384 0 0 1-2.6895 3.254 2.7391 2.7391 0 1 1 0-5.476 2.747 2.747 0 0 1 2.4033 1.418L41.347 26.0584c.1927-.4056.0964-.5508-.0072-.7903-.077-.1805-.366-.366-.6817-.3624h-8.3892l-2.1437 12.2408a.2165.2165 0 0 1-.2157.1632h-3.797a.2208.2208 0 0 1-.1675-.0755.21.21 0 0 1-.049-.1754l2.3286-13.2864-9.4708 18.5676a.484.484 0 0 1-.4207.2452l-3.226.0158c-.115 0-.21-.082-.22-.1805l-.8895-13.4877-6.997 13.41a.4854.4854 0 0 1-.4185.2438l-3.272-.0022a.215.215 0 0 1-.2172-.189L.96 21.922a.233.233 0 0 1 .0554-.1704.2287.2287 0 0 1 .1654-.0619h4.398a.223.223 0 0 1 .2209.2258l.6594 13.3569 6.4677-13.4676a.2193.2193 0 0 1 .1956-.115l4.009-.0173c.1108 0 .21.0841.2165.1819l.6516 13.4597zm4.8662-4.5743c-.453 0-.8377.3236-.919.7723l-.4833 2.7528h-3.41c-.348 0-.6594.1877-.8363.5127l-4.8009 10.2402-.476-9.8993a.9363.9363 0 0 0-.9313-.8529h-4.365c-.3488 0-.6702.1942-.8363.5149l-4.936 10.2783-.4869-9.8605a.9349.9349 0 0 0-.9334-.9327H.9348a.942.942 0 0 0-.6896.2912c-.1726.1899-.2603.4538-.243.7285l2.1767 20.9097a.9334.9334 0 0 0 .9298.8306l3.6093.0014c.443 0 .8464-.2416 1.055-.6342l5.512-10.5603.6795 10.3632a.9349.9349 0 0 0 .9277.8306l3.5826.0014c.4408 0 .8486-.2445 1.0564-.6393l6.6985-13.1332-1.2972 7.4076c-.049.2726.0273.5501.2027.7659a.9349.9349 0 0 0 .7149.3322h4.2456c.4408 0 .8162-.307.9147-.75l2.0423-11.657h7.294l-11.0219 14.425a3.674 3.674 0 0 0-2.358-.853 3.6876 3.6876 0 0 0-3.6818 3.6805 3.6876 3.6876 0 0 0 3.6818 3.6811c1.8625 0 3.4475-1.4231 3.6618-3.2604l29.0983-.0014c.458 0 .8435-.3258.9183-.7738l.6659-3.7883a.9406.9406 0 0 0-.2071-.7608.9277.9277 0 0 0-.714-.3294l-7.5465-.0072L63.846 23.4545c.187-.279.2042-.6156.0489-.9054a.8824.8824 0 0 0-.7846-.4768H51.3377l.7464-.9751a.9205.9205 0 0 0 .0504-.9593.9399.9399 0 0 0-.8227-.499H34.1386l.2351-1.3204a.9615.9615 0 0 0-.2171-.7687.904.904 0 0 0-.707-.3236z"/></svg>
|
package/dist/index.d.cts
CHANGED
|
@@ -19,16 +19,6 @@ export interface AirlineBranding {
|
|
|
19
19
|
readonly guidelines?: string
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/** An airline listed under a parent airline; it has no assets of its own. */
|
|
23
|
-
export interface Subsidiary {
|
|
24
|
-
readonly name: string
|
|
25
|
-
readonly iata: string
|
|
26
|
-
readonly icao: string
|
|
27
|
-
/** ISO 3166-1 alpha-2 code (e.g. "VN"). */
|
|
28
|
-
readonly country: string
|
|
29
|
-
readonly flag_carrier?: boolean
|
|
30
|
-
}
|
|
31
|
-
|
|
32
22
|
export interface Airline {
|
|
33
23
|
readonly name: string
|
|
34
24
|
/** 2-character IATA code (e.g. "VN"). */
|
|
@@ -44,6 +34,13 @@ export interface Airline {
|
|
|
44
34
|
readonly flag_carrier?: boolean
|
|
45
35
|
/** e.g. "oneworld", "SkyTeam", "Star Alliance". */
|
|
46
36
|
readonly alliance?: string
|
|
37
|
+
/** Slug of the airline that owns this one (e.g. "airasia"). */
|
|
38
|
+
readonly parent?: string
|
|
39
|
+
/**
|
|
40
|
+
* Slug of the airline whose marks this one uses (e.g. "airasia"). Its
|
|
41
|
+
* files are still published under this airline's own slug.
|
|
42
|
+
*/
|
|
43
|
+
readonly marks?: string
|
|
47
44
|
/** IATA codes of its hub airports (e.g. ["HAN", "SGN"]). */
|
|
48
45
|
readonly hubs?: readonly string[]
|
|
49
46
|
/** Year founded, counting from the predecessor its history starts with. */
|
|
@@ -54,7 +51,6 @@ export interface Airline {
|
|
|
54
51
|
readonly vectorized?: boolean
|
|
55
52
|
readonly branding?: AirlineBranding
|
|
56
53
|
readonly assets: Readonly<Partial<Record<AssetType, AssetInfo>>>
|
|
57
|
-
readonly subsidiaries?: readonly Subsidiary[]
|
|
58
54
|
}
|
|
59
55
|
|
|
60
56
|
export interface AssetPathOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -19,16 +19,6 @@ export interface AirlineBranding {
|
|
|
19
19
|
readonly guidelines?: string
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/** An airline listed under a parent airline; it has no assets of its own. */
|
|
23
|
-
export interface Subsidiary {
|
|
24
|
-
readonly name: string
|
|
25
|
-
readonly iata: string
|
|
26
|
-
readonly icao: string
|
|
27
|
-
/** ISO 3166-1 alpha-2 code (e.g. "VN"). */
|
|
28
|
-
readonly country: string
|
|
29
|
-
readonly flag_carrier?: boolean
|
|
30
|
-
}
|
|
31
|
-
|
|
32
22
|
export interface Airline {
|
|
33
23
|
readonly name: string
|
|
34
24
|
/** 2-character IATA code (e.g. "VN"). */
|
|
@@ -44,6 +34,13 @@ export interface Airline {
|
|
|
44
34
|
readonly flag_carrier?: boolean
|
|
45
35
|
/** e.g. "oneworld", "SkyTeam", "Star Alliance". */
|
|
46
36
|
readonly alliance?: string
|
|
37
|
+
/** Slug of the airline that owns this one (e.g. "airasia"). */
|
|
38
|
+
readonly parent?: string
|
|
39
|
+
/**
|
|
40
|
+
* Slug of the airline whose marks this one uses (e.g. "airasia"). Its
|
|
41
|
+
* files are still published under this airline's own slug.
|
|
42
|
+
*/
|
|
43
|
+
readonly marks?: string
|
|
47
44
|
/** IATA codes of its hub airports (e.g. ["HAN", "SGN"]). */
|
|
48
45
|
readonly hubs?: readonly string[]
|
|
49
46
|
/** Year founded, counting from the predecessor its history starts with. */
|
|
@@ -54,7 +51,6 @@ export interface Airline {
|
|
|
54
51
|
readonly vectorized?: boolean
|
|
55
52
|
readonly branding?: AirlineBranding
|
|
56
53
|
readonly assets: Readonly<Partial<Record<AssetType, AssetInfo>>>
|
|
57
|
-
readonly subsidiaries?: readonly Subsidiary[]
|
|
58
54
|
}
|
|
59
55
|
|
|
60
56
|
export interface AssetPathOptions {
|
package/dist/svg-validator.cjs
CHANGED
|
@@ -4,6 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
const r = (n) => Math.round(n * 1000) / 1000
|
|
6
6
|
|
|
7
|
+
// Top-level constants are inlined by the build like the functions; only
|
|
8
|
+
// functions may be exported (see scripts/build.js)
|
|
9
|
+
const HEX = /^#(?:[0-9A-F]{3}){1,2}$/i
|
|
10
|
+
// Paint keywords that are not colors to check or move
|
|
11
|
+
const PAINT_KEYWORDS = /^(none|currentColor|transparent|inherit)$/i
|
|
12
|
+
|
|
13
|
+
// Whether a file is a monochrome variant, drawn in currentColor
|
|
14
|
+
function isMonoFile(name) {
|
|
15
|
+
return name.toLowerCase().endsWith('-mono.svg')
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
// Check: <title> exists and has non-empty text content
|
|
8
19
|
function validateTitle(svg) {
|
|
9
20
|
const title = svg.querySelector('title')
|
|
@@ -83,6 +94,17 @@ function validateNoTransforms(svg) {
|
|
|
83
94
|
return { pass, detail }
|
|
84
95
|
}
|
|
85
96
|
|
|
97
|
+
// Check: no <g> inside another <g> (a single level is fine for shared attributes)
|
|
98
|
+
function validateNoNestedGroups(svg) {
|
|
99
|
+
const nested = svg.querySelectorAll('g g').length
|
|
100
|
+
const pass = nested === 0
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
pass,
|
|
104
|
+
detail: pass ? 'clean' : `${nested} nested <g> found`,
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
86
108
|
// Check: geometry — fills viewBox, fits within it, and is centered.
|
|
87
109
|
// Requires a pre-computed bbox (e.g. from getBBox() in the browser).
|
|
88
110
|
// Returns an array of SvgValidation-shaped objects (may be 1–3 items).
|
|
@@ -151,13 +173,368 @@ function validateGeometry(type, bbox) {
|
|
|
151
173
|
return results
|
|
152
174
|
}
|
|
153
175
|
|
|
176
|
+
// Check: <title> is the first element inside <svg>, so screen readers and
|
|
177
|
+
// the catalog read it before anything else
|
|
178
|
+
function validateTitleFirst(svg) {
|
|
179
|
+
const title = svg.querySelector('title')
|
|
180
|
+
const first = svg.firstElementChild
|
|
181
|
+
const pass = !!title && first === title
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
pass,
|
|
185
|
+
detail: pass
|
|
186
|
+
? 'first child'
|
|
187
|
+
: title
|
|
188
|
+
? `<${first.tagName.toLowerCase()}> comes before <title>`
|
|
189
|
+
: 'missing',
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Check: no width or height on the root <svg>; the viewBox sets the size, so
|
|
194
|
+
// the marks scale to whatever box they are placed in
|
|
195
|
+
function validateNoDimensions(svg) {
|
|
196
|
+
const attrs = ['width', 'height'].filter((a) => svg.hasAttribute(a))
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
pass: attrs.length === 0,
|
|
200
|
+
detail: attrs.length
|
|
201
|
+
? attrs.map((a) => `${a}="${svg.getAttribute(a)}"`).join(' ')
|
|
202
|
+
: 'clean',
|
|
203
|
+
attrs,
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Check: no comments, <metadata> or design-tool namespaces and attributes
|
|
208
|
+
// (Inkscape, Sketch, Illustrator…) inside <svg>
|
|
209
|
+
function validateNoEditorData(svg) {
|
|
210
|
+
const editorPrefix = /^(inkscape|sodipodi|sketch|serif|i|x|graph|a):/
|
|
211
|
+
const editorNs = /^xmlns:(?!xlink$)/
|
|
212
|
+
const walker = svg.ownerDocument.createTreeWalker(svg, 128) // comments
|
|
213
|
+
const comments = []
|
|
214
|
+
while (walker.nextNode()) comments.push(walker.currentNode)
|
|
215
|
+
|
|
216
|
+
const leftovers = new Set()
|
|
217
|
+
for (const el of [svg, ...svg.querySelectorAll('*')]) {
|
|
218
|
+
if (
|
|
219
|
+
el.tagName.toLowerCase() === 'metadata' ||
|
|
220
|
+
editorPrefix.test(el.tagName)
|
|
221
|
+
) {
|
|
222
|
+
leftovers.add(`<${el.tagName}>`)
|
|
223
|
+
}
|
|
224
|
+
for (const { name } of el.attributes) {
|
|
225
|
+
if (editorPrefix.test(name) || editorNs.test(name)) {
|
|
226
|
+
leftovers.add(name)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const list = [...leftovers]
|
|
231
|
+
const found = comments.length ? ['comments', ...list] : list
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
pass: found.length === 0,
|
|
235
|
+
detail: found.length ? found.join(', ') : 'clean',
|
|
236
|
+
comments,
|
|
237
|
+
leftovers: list,
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Check: path data is written the way SVGO writes it: at most five decimals,
|
|
242
|
+
// no negative zero and no leading zero (".5", not "0.5"). `paths` lists what
|
|
243
|
+
// each <path> breaks, with `trimmed` the d without leading zeros.
|
|
244
|
+
function validateNumberFormat(svg) {
|
|
245
|
+
const maxDecimals = 5
|
|
246
|
+
const paths = []
|
|
247
|
+
for (const el of svg.querySelectorAll('path[d]')) {
|
|
248
|
+
const d = el.getAttribute('d')
|
|
249
|
+
const long = d.match(new RegExp(`\\.\\d{${maxDecimals + 1},}`))
|
|
250
|
+
const negativeZero = /-0(?![\d.])/.test(d)
|
|
251
|
+
// "0.5" -> ".5" and "-0.5" -> "-.5": the same numbers, written shorter
|
|
252
|
+
const trimmed = d.replace(/(?<![\d.])0\.(?=\d)/g, '.')
|
|
253
|
+
if (long || negativeZero || trimmed !== d) {
|
|
254
|
+
paths.push({
|
|
255
|
+
el,
|
|
256
|
+
long: long?.[0] ?? null,
|
|
257
|
+
negativeZero,
|
|
258
|
+
trimmed: trimmed !== d ? trimmed : null,
|
|
259
|
+
})
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const problems = [
|
|
263
|
+
paths.some((p) => p.long) &&
|
|
264
|
+
`more than ${maxDecimals} decimals ("${paths.find((p) => p.long).long}")`,
|
|
265
|
+
paths.some((p) => p.negativeZero) && 'negative zero',
|
|
266
|
+
paths.some((p) => p.trimmed) && 'leading zeros ("0.5" → ".5")',
|
|
267
|
+
].filter(Boolean)
|
|
268
|
+
|
|
269
|
+
return {
|
|
270
|
+
pass: paths.length === 0,
|
|
271
|
+
detail: problems.length ? problems.join(' · ') : 'clean',
|
|
272
|
+
maxDecimals,
|
|
273
|
+
paths,
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// The six-digit lowercase form of a hex color: #F60 -> #ff6600
|
|
278
|
+
function toFullHex(hex) {
|
|
279
|
+
return (
|
|
280
|
+
hex.length === 4
|
|
281
|
+
? '#' + [...hex.slice(1)].map((c) => c + c).join('')
|
|
282
|
+
: hex
|
|
283
|
+
).toLowerCase()
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Check: colors in fill, stroke and stop-color are six-digit lowercase hex.
|
|
287
|
+
// `invalid` holds values that aren't hex at all (color names, rgb()), `short`
|
|
288
|
+
// hex that only needs rewriting.
|
|
289
|
+
function validateHexColors(svg) {
|
|
290
|
+
const invalid = []
|
|
291
|
+
const short = []
|
|
292
|
+
for (const attr of ['fill', 'stroke', 'stop-color']) {
|
|
293
|
+
const els = [svg, ...svg.querySelectorAll(`[${attr}]`)]
|
|
294
|
+
for (const el of els.filter((e) => e.hasAttribute(attr))) {
|
|
295
|
+
const value = el.getAttribute(attr).trim()
|
|
296
|
+
if (PAINT_KEYWORDS.test(value) || /^url\(.*\)$/.test(value))
|
|
297
|
+
continue
|
|
298
|
+
if (!HEX.test(value)) {
|
|
299
|
+
invalid.push({ el, attr, value })
|
|
300
|
+
continue
|
|
301
|
+
}
|
|
302
|
+
const full = toFullHex(value)
|
|
303
|
+
if (value !== full) short.push({ el, attr, value, full })
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const problems = [
|
|
307
|
+
...invalid.map((c) => `${c.attr}="${c.value}" is not hex`),
|
|
308
|
+
...short.map((c) => `"${c.value}" should be "${c.full}"`),
|
|
309
|
+
]
|
|
310
|
+
|
|
311
|
+
return {
|
|
312
|
+
pass: problems.length === 0,
|
|
313
|
+
detail: problems.length ? problems.join(' · ') : 'clean',
|
|
314
|
+
invalid,
|
|
315
|
+
short,
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Check: a single-color SVG sets its fill once, on the root <svg>
|
|
320
|
+
// (currentColor for a -mono file), and none of its children has one; a
|
|
321
|
+
// multi-color SVG has no fill on the root. Gradients and non-hex fills are
|
|
322
|
+
// left alone (`skipped`): validateHexColors reports the latter.
|
|
323
|
+
// `rootFill` is the fill the root should have (null for none), `rootOk`
|
|
324
|
+
// whether it has it, and `redundant` the children whose fill should go.
|
|
325
|
+
function validateFillPlacement(svg, isMono = false) {
|
|
326
|
+
// The root counts: a single-color SVG keeps its fill there
|
|
327
|
+
const withFill = [svg, ...svg.querySelectorAll('[fill]')].filter((el) =>
|
|
328
|
+
el.hasAttribute('fill'),
|
|
329
|
+
)
|
|
330
|
+
const fills = withFill.map((el) => el.getAttribute('fill').trim())
|
|
331
|
+
const result = (pass, detail, rest) => ({
|
|
332
|
+
pass,
|
|
333
|
+
detail,
|
|
334
|
+
skipped: false,
|
|
335
|
+
rootFill: null,
|
|
336
|
+
rootOk: true,
|
|
337
|
+
redundant: [],
|
|
338
|
+
...rest,
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
if (fills.some((f) => !HEX.test(f) && !PAINT_KEYWORDS.test(f))) {
|
|
342
|
+
return result(true, 'skipped: gradient or non-hex fill', {
|
|
343
|
+
skipped: true,
|
|
344
|
+
})
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const colors = new Set(
|
|
348
|
+
fills.filter((f) => HEX.test(f)).map((f) => f.toLowerCase()),
|
|
349
|
+
)
|
|
350
|
+
const existing = svg.getAttribute('fill')
|
|
351
|
+
|
|
352
|
+
if (colors.size > 1) {
|
|
353
|
+
const rootOk = existing === null
|
|
354
|
+
|
|
355
|
+
return result(
|
|
356
|
+
rootOk,
|
|
357
|
+
rootOk
|
|
358
|
+
? `${colors.size} colors, no root fill`
|
|
359
|
+
: 'root <svg> should have no fill in a multi-color SVG',
|
|
360
|
+
{ rootOk },
|
|
361
|
+
)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const rootFill = isMono ? 'currentColor' : [...colors][0] || 'currentColor'
|
|
365
|
+
const rootOk = isMono
|
|
366
|
+
? existing === rootFill
|
|
367
|
+
: existing?.toLowerCase() === rootFill
|
|
368
|
+
const redundant = withFill.filter((el) => el !== svg)
|
|
369
|
+
const problems = [
|
|
370
|
+
!rootOk && `root <svg> should have fill="${rootFill}"`,
|
|
371
|
+
redundant.length &&
|
|
372
|
+
`remove fill from ${redundant.length} child element${redundant.length > 1 ? 's' : ''}`,
|
|
373
|
+
].filter(Boolean)
|
|
374
|
+
|
|
375
|
+
return result(
|
|
376
|
+
problems.length === 0,
|
|
377
|
+
problems.length ? problems.join(' · ') : `fill="${rootFill}"`,
|
|
378
|
+
{ rootFill, rootOk, redundant },
|
|
379
|
+
)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Check (warning): a single-color SVG draws everything in one <path>
|
|
383
|
+
function validateSinglePath(svg, isMono = false) {
|
|
384
|
+
const hexFill = /#[0-9a-f]{3}(?:[0-9a-f]{3})?\b/gi
|
|
385
|
+
const markup = svg.outerHTML
|
|
386
|
+
const usesPaint = /url\(#|stroke=|stroke:|<(clipPath|mask)\b/i.test(markup)
|
|
387
|
+
const fills = new Set(
|
|
388
|
+
[...svg.querySelectorAll('[fill], [style]')].flatMap((el) =>
|
|
389
|
+
(
|
|
390
|
+
`${el.getAttribute('fill') || ''} ${el.getAttribute('style') || ''}`.match(
|
|
391
|
+
hexFill,
|
|
392
|
+
) || []
|
|
393
|
+
).map((c) => c.toLowerCase()),
|
|
394
|
+
),
|
|
395
|
+
)
|
|
396
|
+
if (!isMono && (usesPaint || fills.size > 1)) {
|
|
397
|
+
return { pass: true, detail: 'multi-color', count: 0 }
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const count = [
|
|
401
|
+
...svg.querySelectorAll(
|
|
402
|
+
'path, circle, rect, ellipse, polygon, polyline, line',
|
|
403
|
+
),
|
|
404
|
+
].filter((el) => !el.closest('defs, clipPath, mask')).length
|
|
405
|
+
|
|
406
|
+
return {
|
|
407
|
+
pass: count <= 1,
|
|
408
|
+
detail: count <= 1 ? 'one shape' : `${count} shapes`,
|
|
409
|
+
count,
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// The file with anything before <svg> (XML declaration, DOCTYPE, comment)
|
|
414
|
+
// removed
|
|
415
|
+
function stripProlog(source) {
|
|
416
|
+
const start = source.indexOf('<svg')
|
|
417
|
+
|
|
418
|
+
return start > 0 ? source.slice(start) : source
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// The file with fill before d on every <path>
|
|
422
|
+
function orderPathAttrs(source) {
|
|
423
|
+
return source.replace(
|
|
424
|
+
/<path([^>]*?) (d="[^"]*?")([^>]*?) (fill="[^"]*?")/g,
|
|
425
|
+
(match, before, dAttr, after, fillAttr) =>
|
|
426
|
+
`<path${before} ${fillAttr} ${dAttr}${after}`,
|
|
427
|
+
)
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// The file with the root <svg> attributes ordered role, viewBox, xmlns, fill,
|
|
431
|
+
// then the rest
|
|
432
|
+
function orderSvgAttrs(source) {
|
|
433
|
+
const first = ['role', 'viewBox', 'xmlns', 'fill']
|
|
434
|
+
const svgTag = source.match(/<svg([^>]*)>/)
|
|
435
|
+
if (!svgTag) return source
|
|
436
|
+
|
|
437
|
+
const attributes = {}
|
|
438
|
+
const attrRegex = /([a-zA-Z0-9:-]+)="([^"]*)"/g
|
|
439
|
+
let match
|
|
440
|
+
while ((match = attrRegex.exec(svgTag[1])) !== null) {
|
|
441
|
+
attributes[match[1]] = match[2]
|
|
442
|
+
}
|
|
443
|
+
const ordered = [
|
|
444
|
+
...first.filter((k) => k in attributes),
|
|
445
|
+
...Object.keys(attributes).filter((k) => !first.includes(k)),
|
|
446
|
+
]
|
|
447
|
+
.map((k) => `${k}="${attributes[k]}"`)
|
|
448
|
+
.join(' ')
|
|
449
|
+
if (ordered.replace(/\s+/g, '') === svgTag[1].trim().replace(/\s+/g, '')) {
|
|
450
|
+
return source
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return source.replace(svgTag[0], `<svg ${ordered}>`)
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// Check: the file starts with <svg>, with nothing before it
|
|
457
|
+
function validateNoProlog(source) {
|
|
458
|
+
const pass = stripProlog(source) === source
|
|
459
|
+
|
|
460
|
+
return {
|
|
461
|
+
pass,
|
|
462
|
+
detail: pass ? 'clean' : 'content before <svg>',
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// Check: root <svg> attributes come as role, viewBox, xmlns, fill, then the
|
|
467
|
+
// rest, and fill comes before d on <path>
|
|
468
|
+
function validateAttrOrder(source) {
|
|
469
|
+
const svgOk = orderSvgAttrs(source) === source
|
|
470
|
+
const pathOk = orderPathAttrs(source) === source
|
|
471
|
+
const problems = [
|
|
472
|
+
!svgOk && 'root <svg>: role, viewBox, xmlns, fill first',
|
|
473
|
+
!pathOk && '<path>: fill before d',
|
|
474
|
+
].filter(Boolean)
|
|
475
|
+
|
|
476
|
+
return {
|
|
477
|
+
pass: problems.length === 0,
|
|
478
|
+
detail: problems.length ? problems.join(' · ') : 'clean',
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
// The same checks as `scripts/lint-svg.js`, in the browser. `fileName` tells
|
|
484
|
+
// a -mono.svg apart (its fill is currentColor); `source`, the file's text,
|
|
485
|
+
// adds the check that needs it (nothing before <svg>) and is what the
|
|
486
|
+
// attribute order is read from, falling back to the parsed element as the
|
|
487
|
+
// CLI does.
|
|
488
|
+
function runSvgValidations(svg, type, bbox = null, options = {}) {
|
|
489
|
+
const { fileName = '', source = null } = options
|
|
490
|
+
const isMono = isMonoFile(fileName)
|
|
491
|
+
const row = (group, label, result, level = 'error') => ({
|
|
492
|
+
group,
|
|
493
|
+
label,
|
|
494
|
+
level,
|
|
495
|
+
pass: result.pass,
|
|
496
|
+
detail: result.detail,
|
|
497
|
+
})
|
|
154
498
|
|
|
155
|
-
function runSvgValidations(svg, type, bbox = null) {
|
|
156
499
|
return [
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
500
|
+
row(
|
|
501
|
+
'Structure',
|
|
502
|
+
'Required attributes',
|
|
503
|
+
validateRequiredAttrs(svg, type),
|
|
504
|
+
),
|
|
505
|
+
row('Structure', 'Title first', validateTitleFirst(svg)),
|
|
506
|
+
row('Structure', 'No embedded scripts', validateNoScripts(svg)),
|
|
507
|
+
row('Structure', 'No transforms', validateNoTransforms(svg)),
|
|
508
|
+
row(
|
|
509
|
+
'Structure',
|
|
510
|
+
'No nested groups',
|
|
511
|
+
validateNoNestedGroups(svg),
|
|
512
|
+
'warning',
|
|
513
|
+
),
|
|
514
|
+
row(
|
|
515
|
+
'Structure',
|
|
516
|
+
'Single path',
|
|
517
|
+
validateSinglePath(svg, isMono),
|
|
518
|
+
'warning',
|
|
519
|
+
),
|
|
520
|
+
row('Format', 'No width or height', validateNoDimensions(svg)),
|
|
521
|
+
row('Format', 'No editor data', validateNoEditorData(svg)),
|
|
522
|
+
row('Format', 'Number format', validateNumberFormat(svg)),
|
|
523
|
+
...(source === null
|
|
524
|
+
? []
|
|
525
|
+
: [row('Format', 'Starts with <svg>', validateNoProlog(source))]),
|
|
526
|
+
row(
|
|
527
|
+
'Format',
|
|
528
|
+
'Attribute order',
|
|
529
|
+
validateAttrOrder(source ?? svg.outerHTML),
|
|
530
|
+
),
|
|
531
|
+
row('Style', 'Hex colors', validateHexColors(svg)),
|
|
532
|
+
row('Style', 'Fill placement', validateFillPlacement(svg, isMono)),
|
|
533
|
+
...validateGeometry(type, bbox).map((check) => ({
|
|
534
|
+
group: 'Geometry',
|
|
535
|
+
level: 'error',
|
|
536
|
+
...check,
|
|
537
|
+
})),
|
|
161
538
|
]
|
|
162
539
|
}
|
|
163
540
|
|
package/dist/svg-validator.d.cts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
export interface SvgValidation {
|
|
2
|
+
/** Section the check belongs to. */
|
|
3
|
+
group: 'Structure' | 'Format' | 'Style' | 'Geometry'
|
|
2
4
|
label: string
|
|
5
|
+
/** `warning` checks are advice: `lint-svg.js --check` never fails on them. */
|
|
6
|
+
level: 'error' | 'warning'
|
|
3
7
|
pass: boolean
|
|
4
8
|
detail: string
|
|
5
9
|
}
|
|
6
10
|
|
|
11
|
+
export interface SvgValidationOptions {
|
|
12
|
+
/** The file name, so a `-mono.svg` is expected to use `fill="currentColor"`. */
|
|
13
|
+
fileName?: string
|
|
14
|
+
/** The file's text: adds the check for anything before `<svg>`, and the attribute order is read from it rather than the parsed element. */
|
|
15
|
+
source?: string | null
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
export function runSvgValidations(
|
|
8
19
|
svg: SVGSVGElement,
|
|
9
20
|
type: 'logo' | 'icon',
|
|
10
21
|
bbox?: DOMRect | null,
|
|
22
|
+
options?: SvgValidationOptions,
|
|
11
23
|
): SvgValidation[]
|
package/dist/svg-validator.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
export interface SvgValidation {
|
|
2
|
+
/** Section the check belongs to. */
|
|
3
|
+
group: 'Structure' | 'Format' | 'Style' | 'Geometry'
|
|
2
4
|
label: string
|
|
5
|
+
/** `warning` checks are advice: `lint-svg.js --check` never fails on them. */
|
|
6
|
+
level: 'error' | 'warning'
|
|
3
7
|
pass: boolean
|
|
4
8
|
detail: string
|
|
5
9
|
}
|
|
6
10
|
|
|
11
|
+
export interface SvgValidationOptions {
|
|
12
|
+
/** The file name, so a `-mono.svg` is expected to use `fill="currentColor"`. */
|
|
13
|
+
fileName?: string
|
|
14
|
+
/** The file's text: adds the check for anything before `<svg>`, and the attribute order is read from it rather than the parsed element. */
|
|
15
|
+
source?: string | null
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
export function runSvgValidations(
|
|
8
19
|
svg: SVGSVGElement,
|
|
9
20
|
type: 'logo' | 'icon',
|
|
10
21
|
bbox?: DOMRect | null,
|
|
22
|
+
options?: SvgValidationOptions,
|
|
11
23
|
): SvgValidation[]
|