-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathpseudo-elements.ts
More file actions
54 lines (45 loc) · 1.4 KB
/
pseudo-elements.ts
File metadata and controls
54 lines (45 loc) · 1.4 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { isStyleFunction } from "../utilities";
import type { StyleDeclaration, StyleRule } from "./compiler.types";
export function modifyRuleForSelection(rule: StyleRule): StyleRule | undefined {
if (!rule.d) {
return;
}
rule.d = rule.d.flatMap((declaration): StyleDeclaration[] => {
return modifyStyleDeclaration(declaration, "color", "selectionColor");
});
return rule;
}
export function modifyRuleForPlaceholder(
rule: StyleRule,
): StyleRule | undefined {
if (!rule.d) {
return;
}
rule.d = rule.d.flatMap((declaration): StyleDeclaration[] => {
return modifyStyleDeclaration(declaration, "color", "placeholderTextColor");
});
return rule;
}
function modifyStyleDeclaration(
declaration: StyleDeclaration,
from: string,
to: string,
): StyleDeclaration[] {
if (Array.isArray(declaration)) {
if (isStyleFunction(declaration) && declaration[2] === from) {
declaration = [...declaration] as StyleDeclaration;
declaration[2] = [to];
return [declaration];
} else if (declaration[1] === from) {
declaration = [...declaration] as StyleDeclaration;
declaration[1] = [to];
return [declaration];
}
} else if (typeof declaration === "object") {
const { color: selectionColor, ...rest } = declaration;
if (selectionColor) {
return [rest, [selectionColor, [to]]] as StyleDeclaration[];
}
}
return [declaration];
}