-
-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathtransform.ts
More file actions
29 lines (25 loc) · 844 Bytes
/
Copy pathtransform.ts
File metadata and controls
29 lines (25 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { ComponentValue } from "@csstools/css-parser-algorithms";
import { isTokenNode, isWhiteSpaceOrCommentNode, stringify } from "@csstools/css-parser-algorithms";
import { isTokenString } from "@csstools/css-tokenizer";
export function transform(parts: Array<Array<ComponentValue>>, stripAltText?: boolean): string {
const firstPart = parts[0];
if (!firstPart.length) {
return '';
}
if (stripAltText) {
return stringify([firstPart]);
}
const relevantComponentValues = parts[1].filter((x) => !isWhiteSpaceOrCommentNode(x));
if (
relevantComponentValues.length === 1 &&
isTokenNode(relevantComponentValues[0]) &&
isTokenString(relevantComponentValues[0].value) &&
relevantComponentValues[0].value[4].value === ''
) {
return stringify([firstPart]);
}
return stringify([[
...firstPart,
...parts[1],
]]);
}