@projectwallace/css-analyzer 9.4.0 → 9.5.0

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.
@@ -0,0 +1,2 @@
1
+ import { n as isSupportsBrowserhack, t as isMediaBrowserhack } from "../atrules-CvzPtm16.js";
2
+ export { isMediaBrowserhack, isSupportsBrowserhack };
@@ -0,0 +1,2 @@
1
+ import { n as isSupportsBrowserhack, t as isMediaBrowserhack } from "../atrules-CskmpIdJ.js";
2
+ export { isMediaBrowserhack, isSupportsBrowserhack };
@@ -0,0 +1,76 @@
1
+ import { BREAK, DIMENSION, IDENTIFIER, MEDIA_FEATURE, MEDIA_TYPE, NUMBER, SUPPORTS_QUERY, str_equals, walk } from "@projectwallace/css-parser";
2
+ //#region src/atrules/atrules.ts
3
+ /**
4
+ * Check if an @supports atRule is a browserhack (Wallace parser version)
5
+ * @param node - The Atrule CSSNode from Wallace parser
6
+ */
7
+ function isSupportsBrowserhack(node, on_hack) {
8
+ walk(node, function(n) {
9
+ if (n.type === SUPPORTS_QUERY) {
10
+ const normalizedPrelude = (n.prelude || n.value || "").toString().toLowerCase().replaceAll(/\s+/g, "");
11
+ if (normalizedPrelude.includes("-webkit-appearance:none")) {
12
+ on_hack("-webkit-appearance: none");
13
+ return BREAK;
14
+ }
15
+ if (normalizedPrelude.includes("-moz-appearance:meterbar")) {
16
+ on_hack("-moz-appearance: meterbar");
17
+ return BREAK;
18
+ }
19
+ }
20
+ });
21
+ }
22
+ /**
23
+ * Check if a @media atRule is a browserhack (Wallace parser version)
24
+ * @param node - The Atrule CSSNode from Wallace parser
25
+ * @returns true if the atrule is a browserhack
26
+ */
27
+ function isMediaBrowserhack(node, on_hack) {
28
+ walk(node, function(n) {
29
+ if (n.type === MEDIA_TYPE) {
30
+ const text = n.text || "";
31
+ if (text.startsWith("\\0")) {
32
+ on_hack("\\0");
33
+ return BREAK;
34
+ }
35
+ if (text.includes("\\9")) {
36
+ on_hack("\\9");
37
+ return BREAK;
38
+ }
39
+ }
40
+ if (n.type === MEDIA_FEATURE) {
41
+ const name = n.property || "";
42
+ if (str_equals("-moz-images-in-menus", name)) {
43
+ on_hack("-moz-images-in-menus");
44
+ return BREAK;
45
+ }
46
+ if (str_equals("min--moz-device-pixel-ratio", name)) {
47
+ on_hack("min--moz-device-pixel-ratio");
48
+ return BREAK;
49
+ }
50
+ if (str_equals("-ms-high-contrast", name)) {
51
+ on_hack("-ms-high-contrast");
52
+ return BREAK;
53
+ }
54
+ if (str_equals("min-resolution", name) && n.has_children) {
55
+ for (const child of n) if (child.type === DIMENSION && child.value === .001 && str_equals("dpcm", child.unit || "")) {
56
+ on_hack("min-resolution: .001dpcm");
57
+ return BREAK;
58
+ }
59
+ }
60
+ if (str_equals("-webkit-min-device-pixel-ratio", name) && n.has_children) {
61
+ for (const child of n) if (child.type === NUMBER && (child.value === 0 || child.value === 1e4)) {
62
+ on_hack("-webkit-min-device-pixel-ratio");
63
+ return BREAK;
64
+ }
65
+ }
66
+ if (n.has_children) {
67
+ for (const child of n) if (child.type === IDENTIFIER && child.text === "\\0") {
68
+ on_hack("\\0");
69
+ return BREAK;
70
+ }
71
+ }
72
+ }
73
+ });
74
+ }
75
+ //#endregion
76
+ export { isSupportsBrowserhack as n, isMediaBrowserhack as t };
@@ -0,0 +1,16 @@
1
+ import { CSSNode } from "@projectwallace/css-parser";
2
+
3
+ //#region src/atrules/atrules.d.ts
4
+ /**
5
+ * Check if an @supports atRule is a browserhack (Wallace parser version)
6
+ * @param node - The Atrule CSSNode from Wallace parser
7
+ */
8
+ declare function isSupportsBrowserhack(node: CSSNode, on_hack: (hack: string) => void): void;
9
+ /**
10
+ * Check if a @media atRule is a browserhack (Wallace parser version)
11
+ * @param node - The Atrule CSSNode from Wallace parser
12
+ * @returns true if the atrule is a browserhack
13
+ */
14
+ declare function isMediaBrowserhack(node: CSSNode, on_hack: (hack: string) => void): void;
15
+ //#endregion
16
+ export { isSupportsBrowserhack as n, isMediaBrowserhack as t };
@@ -0,0 +1,221 @@
1
+ import { r as KeywordSet, t as endsWith } from "./string-utils-olNNcOlY.js";
2
+ import { DIMENSION, IDENTIFIER, NUMBER } from "@projectwallace/css-parser";
3
+ //#region src/values/colors.ts
4
+ const namedColors = new KeywordSet([
5
+ "white",
6
+ "black",
7
+ "red",
8
+ "gray",
9
+ "silver",
10
+ "grey",
11
+ "green",
12
+ "orange",
13
+ "blue",
14
+ "dimgray",
15
+ "whitesmoke",
16
+ "lightgray",
17
+ "lightgrey",
18
+ "yellow",
19
+ "gold",
20
+ "pink",
21
+ "gainsboro",
22
+ "magenta",
23
+ "purple",
24
+ "darkgray",
25
+ "navy",
26
+ "darkred",
27
+ "teal",
28
+ "maroon",
29
+ "darkgrey",
30
+ "tomato",
31
+ "darkorange",
32
+ "brown",
33
+ "crimson",
34
+ "lightyellow",
35
+ "slategray",
36
+ "salmon",
37
+ "lightgreen",
38
+ "lightblue",
39
+ "orangered",
40
+ "aliceblue",
41
+ "dodgerblue",
42
+ "lime",
43
+ "darkblue",
44
+ "darkgoldenrod",
45
+ "skyblue",
46
+ "royalblue",
47
+ "darkgreen",
48
+ "ivory",
49
+ "olive",
50
+ "aqua",
51
+ "turquoise",
52
+ "cyan",
53
+ "khaki",
54
+ "beige",
55
+ "snow",
56
+ "ghostwhite",
57
+ "limegreen",
58
+ "coral",
59
+ "dimgrey",
60
+ "hotpink",
61
+ "midnightblue",
62
+ "firebrick",
63
+ "indigo",
64
+ "wheat",
65
+ "mediumblue",
66
+ "lightpink",
67
+ "plum",
68
+ "azure",
69
+ "violet",
70
+ "lavender",
71
+ "deepskyblue",
72
+ "darkslategrey",
73
+ "goldenrod",
74
+ "cornflowerblue",
75
+ "lightskyblue",
76
+ "indianred",
77
+ "yellowgreen",
78
+ "saddlebrown",
79
+ "palegreen",
80
+ "bisque",
81
+ "tan",
82
+ "antiquewhite",
83
+ "steelblue",
84
+ "forestgreen",
85
+ "fuchsia",
86
+ "mediumaquamarine",
87
+ "seagreen",
88
+ "sienna",
89
+ "deeppink",
90
+ "mediumseagreen",
91
+ "peru",
92
+ "greenyellow",
93
+ "lightgoldenrodyellow",
94
+ "orchid",
95
+ "cadetblue",
96
+ "navajowhite",
97
+ "lightsteelblue",
98
+ "slategrey",
99
+ "linen",
100
+ "lightseagreen",
101
+ "darkcyan",
102
+ "lightcoral",
103
+ "aquamarine",
104
+ "blueviolet",
105
+ "cornsilk",
106
+ "lightsalmon",
107
+ "chocolate",
108
+ "lightslategray",
109
+ "floralwhite",
110
+ "darkturquoise",
111
+ "darkslategray",
112
+ "rebeccapurple",
113
+ "burlywood",
114
+ "chartreuse",
115
+ "lightcyan",
116
+ "lemonchiffon",
117
+ "palevioletred",
118
+ "darkslateblue",
119
+ "mediumpurple",
120
+ "lawngreen",
121
+ "slateblue",
122
+ "darkseagreen",
123
+ "blanchedalmond",
124
+ "mistyrose",
125
+ "darkolivegreen",
126
+ "seashell",
127
+ "olivedrab",
128
+ "peachpuff",
129
+ "darkviolet",
130
+ "powderblue",
131
+ "darkmagenta",
132
+ "lightslategrey",
133
+ "honeydew",
134
+ "palegoldenrod",
135
+ "darkkhaki",
136
+ "oldlace",
137
+ "mintcream",
138
+ "sandybrown",
139
+ "mediumturquoise",
140
+ "papayawhip",
141
+ "paleturquoise",
142
+ "mediumvioletred",
143
+ "thistle",
144
+ "springgreen",
145
+ "moccasin",
146
+ "rosybrown",
147
+ "lavenderblush",
148
+ "mediumslateblue",
149
+ "darkorchid",
150
+ "mediumorchid",
151
+ "darksalmon",
152
+ "mediumspringgreen"
153
+ ]);
154
+ const systemColors = new KeywordSet([
155
+ "accentcolor",
156
+ "accentcolortext",
157
+ "activetext",
158
+ "buttonborder",
159
+ "buttonface",
160
+ "buttontext",
161
+ "canvas",
162
+ "canvastext",
163
+ "field",
164
+ "fieldtext",
165
+ "graytext",
166
+ "highlight",
167
+ "highlighttext",
168
+ "linktext",
169
+ "mark",
170
+ "marktext",
171
+ "selecteditem",
172
+ "selecteditemtext",
173
+ "visitedtext"
174
+ ]);
175
+ const colorFunctions = new KeywordSet([
176
+ "rgba",
177
+ "rgb",
178
+ "hsla",
179
+ "hsl",
180
+ "oklch",
181
+ "color",
182
+ "hwb",
183
+ "lch",
184
+ "lab",
185
+ "oklab"
186
+ ]);
187
+ const colorKeywords = new KeywordSet(["transparent", "currentcolor"]);
188
+ //#endregion
189
+ //#region src/values/values.ts
190
+ const keywords = new KeywordSet([
191
+ "auto",
192
+ "none",
193
+ "inherit",
194
+ "initial",
195
+ "unset",
196
+ "revert",
197
+ "revert-layer"
198
+ ]);
199
+ /**
200
+ * Test whether a value is a reset (0, 0px, -0.0e0 etc.)
201
+ */
202
+ function isValueReset(node) {
203
+ for (let child of node.children) {
204
+ if (child.type === NUMBER && child.value === 0) continue;
205
+ if (child.type === DIMENSION && child.value === 0) continue;
206
+ return false;
207
+ }
208
+ return true;
209
+ }
210
+ //#endregion
211
+ //#region src/values/browserhacks.ts
212
+ function isIe9Hack(node) {
213
+ let children = node.children;
214
+ if (children) {
215
+ let last = children.at(-1);
216
+ return last && last.type === IDENTIFIER && endsWith("\\9", last.text) ? true : false;
217
+ }
218
+ return false;
219
+ }
220
+ //#endregion
221
+ export { colorKeywords as a, colorFunctions as i, isValueReset as n, namedColors as o, keywords as r, systemColors as s, isIe9Hack as t };
package/dist/index.d.ts CHANGED
@@ -1,64 +1,8 @@
1
+ import { n as isSupportsBrowserhack, t as isMediaBrowserhack } from "./atrules-CvzPtm16.js";
2
+ import { a as calculate, c as CollectionCount, i as isPrefixed, l as Location, n as getComplexity, r as isAccessibility, u as UniqueWithLocations } from "./utils-BUeYqEL1.js";
3
+ import { a as namedColors, i as colorKeywords, n as keywords, o as systemColors, r as colorFunctions, s as KeywordSet } from "./values-Dw53soqy.js";
1
4
  import { CSSNode } from "@projectwallace/css-parser";
2
5
 
3
- //#region src/collection.d.ts
4
- type Location = {
5
- line: number;
6
- column: number;
7
- offset: number;
8
- length: number;
9
- };
10
- type UniqueWithLocations = Record<string, Location[]>;
11
- type CollectionCount<WithLocations extends boolean = false> = {
12
- total: number;
13
- totalUnique: number;
14
- unique: Record<string, number>;
15
- uniquenessRatio: number;
16
- } & (WithLocations extends true ? {
17
- uniqueWithLocations: UniqueWithLocations;
18
- } : {
19
- uniqueWithLocations?: undefined;
20
- });
21
- //#endregion
22
- //#region src/selectors/specificity.d.ts
23
- type Specificity$1 = [number, number, number];
24
- declare const calculate: (selector: string | CSSNode) => Specificity$1[];
25
- //#endregion
26
- //#region src/selectors/utils.d.ts
27
- declare function isPrefixed(selector: CSSNode, on_selector: (prefix: string) => void): void;
28
- /**
29
- * Check if a Wallace selector is an accessibility selector (has aria-* or role attribute)
30
- */
31
- declare function isAccessibility(selector: CSSNode, on_selector: (a11y_selector: string) => void): void;
32
- /**
33
- * Get the Complexity for a Wallace Selector Node
34
- * @param selector - Wallace CSSNode for a Selector
35
- * @return The numeric complexity of the Selector
36
- */
37
- declare function getComplexity(selector: CSSNode): number;
38
- //#endregion
39
- //#region src/atrules/atrules.d.ts
40
- /**
41
- * Check if an @supports atRule is a browserhack (Wallace parser version)
42
- * @param node - The Atrule CSSNode from Wallace parser
43
- */
44
- declare function isSupportsBrowserhack(node: CSSNode, on_hack: (hack: string) => void): void;
45
- /**
46
- * Check if a @media atRule is a browserhack (Wallace parser version)
47
- * @param node - The Atrule CSSNode from Wallace parser
48
- * @returns true if the atrule is a browserhack
49
- */
50
- declare function isMediaBrowserhack(node: CSSNode, on_hack: (hack: string) => void): void;
51
- //#endregion
52
- //#region src/keyword-set.d.ts
53
- /**
54
- * @description A Set-like construct to search CSS keywords in a case-insensitive way
55
- */
56
- declare class KeywordSet {
57
- set: Set<string>;
58
- constructor(items: Lowercase<string>[]);
59
- has(item: string): boolean;
60
- }
61
- //#endregion
62
6
  //#region src/properties/property-utils.d.ts
63
7
  /**
64
8
  * @see https://github.com/csstree/csstree/blob/master/lib/utils/names.js#L69
@@ -68,15 +12,6 @@ declare function isHack(property: string): boolean;
68
12
  //#region src/values/vendor-prefix.d.ts
69
13
  declare function isValuePrefixed(node: CSSNode, on_value: (value: string) => void): void;
70
14
  //#endregion
71
- //#region src/values/colors.d.ts
72
- declare const namedColors: KeywordSet;
73
- declare const systemColors: KeywordSet;
74
- declare const colorFunctions: KeywordSet;
75
- declare const colorKeywords: KeywordSet;
76
- //#endregion
77
- //#region src/values/values.d.ts
78
- declare const keywords: KeywordSet;
79
- //#endregion
80
15
  //#region src/vendor-prefix.d.ts
81
16
  /** Kept for backwards compatibility */
82
17
  declare function hasVendorPrefix(keyword: string): boolean;
@@ -605,6 +540,7 @@ declare function analyzeInternal<T extends boolean>(css: string, options: Option
605
540
  };
606
541
  /**
607
542
  * Compare specificity A to Specificity B
543
+ * @deprecated this one is the inverse of the one exported in /selectors/index.ts; wille be removed in next major version
608
544
  * @returns 0 when a==b, 1 when a<b, -1 when a>b
609
545
  */
610
546
  declare function compareSpecificity(a: Specificity, b: Specificity): number;