@projectwallace/css-analyzer 9.4.0 → 9.6.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-C8lZ1H_5.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,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,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,222 @@
1
+ import { t as KeywordSet } from "./keyword-set-qSyAMR9o.js";
2
+ import { t as endsWith } from "./string-utils-C97yyuqE.js";
3
+ import { DIMENSION, IDENTIFIER, NUMBER } from "@projectwallace/css-parser";
4
+ //#region src/values/colors.ts
5
+ const namedColors = new KeywordSet([
6
+ "white",
7
+ "black",
8
+ "red",
9
+ "gray",
10
+ "silver",
11
+ "grey",
12
+ "green",
13
+ "orange",
14
+ "blue",
15
+ "dimgray",
16
+ "whitesmoke",
17
+ "lightgray",
18
+ "lightgrey",
19
+ "yellow",
20
+ "gold",
21
+ "pink",
22
+ "gainsboro",
23
+ "magenta",
24
+ "purple",
25
+ "darkgray",
26
+ "navy",
27
+ "darkred",
28
+ "teal",
29
+ "maroon",
30
+ "darkgrey",
31
+ "tomato",
32
+ "darkorange",
33
+ "brown",
34
+ "crimson",
35
+ "lightyellow",
36
+ "slategray",
37
+ "salmon",
38
+ "lightgreen",
39
+ "lightblue",
40
+ "orangered",
41
+ "aliceblue",
42
+ "dodgerblue",
43
+ "lime",
44
+ "darkblue",
45
+ "darkgoldenrod",
46
+ "skyblue",
47
+ "royalblue",
48
+ "darkgreen",
49
+ "ivory",
50
+ "olive",
51
+ "aqua",
52
+ "turquoise",
53
+ "cyan",
54
+ "khaki",
55
+ "beige",
56
+ "snow",
57
+ "ghostwhite",
58
+ "limegreen",
59
+ "coral",
60
+ "dimgrey",
61
+ "hotpink",
62
+ "midnightblue",
63
+ "firebrick",
64
+ "indigo",
65
+ "wheat",
66
+ "mediumblue",
67
+ "lightpink",
68
+ "plum",
69
+ "azure",
70
+ "violet",
71
+ "lavender",
72
+ "deepskyblue",
73
+ "darkslategrey",
74
+ "goldenrod",
75
+ "cornflowerblue",
76
+ "lightskyblue",
77
+ "indianred",
78
+ "yellowgreen",
79
+ "saddlebrown",
80
+ "palegreen",
81
+ "bisque",
82
+ "tan",
83
+ "antiquewhite",
84
+ "steelblue",
85
+ "forestgreen",
86
+ "fuchsia",
87
+ "mediumaquamarine",
88
+ "seagreen",
89
+ "sienna",
90
+ "deeppink",
91
+ "mediumseagreen",
92
+ "peru",
93
+ "greenyellow",
94
+ "lightgoldenrodyellow",
95
+ "orchid",
96
+ "cadetblue",
97
+ "navajowhite",
98
+ "lightsteelblue",
99
+ "slategrey",
100
+ "linen",
101
+ "lightseagreen",
102
+ "darkcyan",
103
+ "lightcoral",
104
+ "aquamarine",
105
+ "blueviolet",
106
+ "cornsilk",
107
+ "lightsalmon",
108
+ "chocolate",
109
+ "lightslategray",
110
+ "floralwhite",
111
+ "darkturquoise",
112
+ "darkslategray",
113
+ "rebeccapurple",
114
+ "burlywood",
115
+ "chartreuse",
116
+ "lightcyan",
117
+ "lemonchiffon",
118
+ "palevioletred",
119
+ "darkslateblue",
120
+ "mediumpurple",
121
+ "lawngreen",
122
+ "slateblue",
123
+ "darkseagreen",
124
+ "blanchedalmond",
125
+ "mistyrose",
126
+ "darkolivegreen",
127
+ "seashell",
128
+ "olivedrab",
129
+ "peachpuff",
130
+ "darkviolet",
131
+ "powderblue",
132
+ "darkmagenta",
133
+ "lightslategrey",
134
+ "honeydew",
135
+ "palegoldenrod",
136
+ "darkkhaki",
137
+ "oldlace",
138
+ "mintcream",
139
+ "sandybrown",
140
+ "mediumturquoise",
141
+ "papayawhip",
142
+ "paleturquoise",
143
+ "mediumvioletred",
144
+ "thistle",
145
+ "springgreen",
146
+ "moccasin",
147
+ "rosybrown",
148
+ "lavenderblush",
149
+ "mediumslateblue",
150
+ "darkorchid",
151
+ "mediumorchid",
152
+ "darksalmon",
153
+ "mediumspringgreen"
154
+ ]);
155
+ const systemColors = new KeywordSet([
156
+ "accentcolor",
157
+ "accentcolortext",
158
+ "activetext",
159
+ "buttonborder",
160
+ "buttonface",
161
+ "buttontext",
162
+ "canvas",
163
+ "canvastext",
164
+ "field",
165
+ "fieldtext",
166
+ "graytext",
167
+ "highlight",
168
+ "highlighttext",
169
+ "linktext",
170
+ "mark",
171
+ "marktext",
172
+ "selecteditem",
173
+ "selecteditemtext",
174
+ "visitedtext"
175
+ ]);
176
+ const colorFunctions = new KeywordSet([
177
+ "rgba",
178
+ "rgb",
179
+ "hsla",
180
+ "hsl",
181
+ "oklch",
182
+ "color",
183
+ "hwb",
184
+ "lch",
185
+ "lab",
186
+ "oklab"
187
+ ]);
188
+ const colorKeywords = new KeywordSet(["transparent", "currentcolor"]);
189
+ //#endregion
190
+ //#region src/values/values.ts
191
+ const keywords = new KeywordSet([
192
+ "auto",
193
+ "none",
194
+ "inherit",
195
+ "initial",
196
+ "unset",
197
+ "revert",
198
+ "revert-layer"
199
+ ]);
200
+ /**
201
+ * Test whether a value is a reset (0, 0px, -0.0e0 etc.)
202
+ */
203
+ function isValueReset(node) {
204
+ for (let child of node.children) {
205
+ if (child.type === NUMBER && child.value === 0) continue;
206
+ if (child.type === DIMENSION && child.value === 0) continue;
207
+ return false;
208
+ }
209
+ return true;
210
+ }
211
+ //#endregion
212
+ //#region src/values/browserhacks.ts
213
+ function isIe9Hack(node) {
214
+ let children = node.children;
215
+ if (children) {
216
+ let last = children.at(-1);
217
+ return last && last.type === IDENTIFIER && endsWith("\\9", last.text) ? true : false;
218
+ }
219
+ return false;
220
+ }
221
+ //#endregion
222
+ 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,84 +1,18 @@
1
+ import { n as isSupportsBrowserhack, t as isMediaBrowserhack } from "./atrules-C8lZ1H_5.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-DJb_IpTO.js";
3
+ import { t as KeywordSet } from "./keyword-set-BXSoLQ6m.js";
4
+ import { i as isHack } from "./property-utils-MKX6iGvg.js";
5
+ import { a as namedColors, i as colorKeywords, n as keywords, o as systemColors, r as colorFunctions } from "./values-B5nDaGc_.js";
1
6
  import { CSSNode } from "@projectwallace/css-parser";
2
7
 
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
- //#region src/properties/property-utils.d.ts
63
- /**
64
- * @see https://github.com/csstree/csstree/blob/master/lib/utils/names.js#L69
65
- */
66
- declare function isHack(property: string): boolean;
67
- //#endregion
68
8
  //#region src/values/vendor-prefix.d.ts
69
9
  declare function isValuePrefixed(node: CSSNode, on_value: (value: string) => void): void;
70
10
  //#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
11
  //#region src/vendor-prefix.d.ts
81
- /** Kept for backwards compatibility */
12
+ /**
13
+ * Kept for backwards compatibility
14
+ * @deprecated
15
+ * */
82
16
  declare function hasVendorPrefix(keyword: string): boolean;
83
17
  //#endregion
84
18
  //#region src/index.d.ts
@@ -506,6 +440,18 @@ declare function analyzeInternal<T extends boolean>(css: string, options: Option
506
440
  ratio: number;
507
441
  };
508
442
  };
443
+ shorthands: {
444
+ total: number;
445
+ totalUnique: number;
446
+ unique: Record<string, number>;
447
+ uniquenessRatio: number;
448
+ } & (T extends true ? {
449
+ uniqueWithLocations: UniqueWithLocations;
450
+ } : {
451
+ uniqueWithLocations?: undefined;
452
+ }) & {
453
+ ratio: number;
454
+ };
509
455
  browserhacks: {
510
456
  total: number;
511
457
  totalUnique: number;
@@ -605,6 +551,7 @@ declare function analyzeInternal<T extends boolean>(css: string, options: Option
605
551
  };
606
552
  /**
607
553
  * Compare specificity A to Specificity B
554
+ * @deprecated this one is the inverse of the one exported in /selectors/index.ts; wille be removed in next major version
608
555
  * @returns 0 when a==b, 1 when a<b, -1 when a>b
609
556
  */
610
557
  declare function compareSpecificity(a: Specificity, b: Specificity): number;