@projectwallace/css-analyzer 9.5.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.
@@ -1,2 +1,2 @@
1
- import { n as isSupportsBrowserhack, t as isMediaBrowserhack } from "../atrules-CvzPtm16.js";
1
+ import { n as isSupportsBrowserhack, t as isMediaBrowserhack } from "../atrules-C8lZ1H_5.js";
2
2
  export { isMediaBrowserhack, isSupportsBrowserhack };
@@ -1,4 +1,5 @@
1
- import { r as KeywordSet, t as endsWith } from "./string-utils-olNNcOlY.js";
1
+ import { t as KeywordSet } from "./keyword-set-qSyAMR9o.js";
2
+ import { t as endsWith } from "./string-utils-C97yyuqE.js";
2
3
  import { DIMENSION, IDENTIFIER, NUMBER } from "@projectwallace/css-parser";
3
4
  //#region src/values/colors.ts
4
5
  const namedColors = new KeywordSet([
package/dist/index.d.ts CHANGED
@@ -1,19 +1,18 @@
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
+ 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";
4
6
  import { CSSNode } from "@projectwallace/css-parser";
5
7
 
6
- //#region src/properties/property-utils.d.ts
7
- /**
8
- * @see https://github.com/csstree/csstree/blob/master/lib/utils/names.js#L69
9
- */
10
- declare function isHack(property: string): boolean;
11
- //#endregion
12
8
  //#region src/values/vendor-prefix.d.ts
13
9
  declare function isValuePrefixed(node: CSSNode, on_value: (value: string) => void): void;
14
10
  //#endregion
15
11
  //#region src/vendor-prefix.d.ts
16
- /** Kept for backwards compatibility */
12
+ /**
13
+ * Kept for backwards compatibility
14
+ * @deprecated
15
+ * */
17
16
  declare function hasVendorPrefix(keyword: string): boolean;
18
17
  //#endregion
19
18
  //#region src/index.d.ts
@@ -441,6 +440,18 @@ declare function analyzeInternal<T extends boolean>(css: string, options: Option
441
440
  ratio: number;
442
441
  };
443
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
+ };
444
455
  browserhacks: {
445
456
  total: number;
446
457
  totalUnique: number;
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { n as isSupportsBrowserhack, t as isMediaBrowserhack } from "./atrules-CskmpIdJ.js";
2
- import { n as unquote, r as KeywordSet, t as endsWith } from "./string-utils-olNNcOlY.js";
3
- import { a as getComplexity, i as getCombinators, n as calculateForAST, o as isAccessibility, s as isPrefixed, t as calculate } from "./specificity-svLpcKkT.js";
4
- import { a as colorKeywords, i as colorFunctions, n as isValueReset, o as namedColors, r as keywords, s as systemColors, t as isIe9Hack } from "./browserhacks-eP_e1D5u.js";
2
+ import { t as KeywordSet } from "./keyword-set-qSyAMR9o.js";
3
+ import { n as unquote, t as endsWith } from "./string-utils-C97yyuqE.js";
4
+ import { a as getComplexity, i as getCombinators, n as calculateForAST, o as isAccessibility, s as isPrefixed, t as calculate } from "./specificity-BKdu6JZr.js";
5
+ import { a as colorKeywords, i as colorFunctions, n as isValueReset, o as namedColors, r as keywords, s as systemColors, t as isIe9Hack } from "./browserhacks-Ckz2JiOQ.js";
6
+ import { a as shorthand_properties, i as isHack, n as basename, r as border_radius_properties, t as SPACING_RESET_PROPERTIES } from "./property-utils-B3n9KkA9.js";
5
7
  import { ATTRIBUTE_SELECTOR, AT_RULE, BLOCK, CONTAINER_QUERY, DECLARATION, DIMENSION, FUNCTION, HASH, IDENTIFIER, LAYER_NAME, MEDIA_FEATURE, NUMBER, OPERATOR, PSEUDO_CLASS_SELECTOR, PSEUDO_ELEMENT_SELECTOR, SELECTOR, SELECTOR_LIST, SKIP, STYLE_RULE, SUPPORTS_QUERY, TYPE_SELECTOR, URL, is_custom, is_vendor_prefixed, parse, str_starts_with, walk } from "@projectwallace/css-parser";
6
8
  //#region src/values/destructure-font-shorthand.ts
7
9
  const SYSTEM_FONTS = new KeywordSet([
@@ -315,63 +317,11 @@ function getEmbedType(embed) {
315
317
  return embed.substring(start, semicolon);
316
318
  }
317
319
  //#endregion
318
- //#region src/properties/property-utils.ts
319
- const SPACING_RESET_PROPERTIES = new Set([
320
- "margin",
321
- "margin-block",
322
- "margin-inline",
323
- "margin-top",
324
- "margin-block-start",
325
- "margin-block-end",
326
- "margin-inline-end",
327
- "margin-inline-end",
328
- "margin-right",
329
- "margin-bottom",
330
- "margin-left",
331
- "padding",
332
- "padding-block",
333
- "padding-inline",
334
- "padding-top",
335
- "padding-right",
336
- "padding-bottom",
337
- "padding-left",
338
- "padding-block-start",
339
- "padding-block-end",
340
- "padding-inline-start",
341
- "padding-inline-end"
342
- ]);
343
- const border_radius_properties = new KeywordSet([
344
- "border-radius",
345
- "border-top-left-radius",
346
- "border-top-right-radius",
347
- "border-bottom-right-radius",
348
- "border-bottom-left-radius",
349
- "border-start-start-radius",
350
- "border-start-end-radius",
351
- "border-end-end-radius",
352
- "border-end-start-radius"
353
- ]);
354
- /**
355
- * @see https://github.com/csstree/csstree/blob/master/lib/utils/names.js#L69
356
- */
357
- function isHack(property) {
358
- if (is_custom(property) || is_vendor_prefixed(property)) return false;
359
- let code = property.charCodeAt(0);
360
- return code === 47 || code === 42 || code === 95 || code === 43 || code === 38 || code === 36 || code === 35;
361
- }
362
- /**
363
- * Get the normalized basename for a property with a vendor prefix
364
- * @returns The property name without vendor prefix
365
- */
366
- function basename(property) {
367
- if (is_custom(property)) return property;
368
- if (is_vendor_prefixed(property)) return property.slice(property.indexOf("-", 2) + 1).toLowerCase();
369
- if (isHack(property)) return property.slice(1).toLowerCase();
370
- return property.toLowerCase();
371
- }
372
- //#endregion
373
320
  //#region src/vendor-prefix.ts
374
- /** Kept for backwards compatibility */
321
+ /**
322
+ * Kept for backwards compatibility
323
+ * @deprecated
324
+ * */
375
325
  function hasVendorPrefix(keyword) {
376
326
  return is_vendor_prefixed(keyword);
377
327
  }
@@ -466,6 +416,7 @@ function analyzeInternal(css, options, useLocations) {
466
416
  let propertyHacks = new Collection(useLocations);
467
417
  let propertyVendorPrefixes = new Collection(useLocations);
468
418
  let customProperties = new Collection(useLocations);
419
+ let shorthands = new Collection(useLocations);
469
420
  let propertyComplexities = new AggregateCollection();
470
421
  let valueComplexities = new AggregateCollection();
471
422
  let vendorPrefixedValues = new Collection(useLocations);
@@ -656,6 +607,7 @@ function analyzeInternal(css, options, useLocations) {
656
607
  propertyHacks.p(property.charAt(0), propertyLoc);
657
608
  propertyComplexities.push(2);
658
609
  } else propertyComplexities.push(1);
610
+ if (shorthand_properties.has(normalizedProperty)) shorthands.p(property, propertyLoc);
659
611
  {
660
612
  let value = node.value;
661
613
  let { text } = value;
@@ -962,6 +914,7 @@ function analyzeInternal(css, options, useLocations) {
962
914
  ratio: ratio(customProperties.size(), properties.size()),
963
915
  importants: assign(importantCustomProperties.c(), { ratio: ratio(importantCustomProperties.size(), customProperties.size()) })
964
916
  }),
917
+ shorthands: assign(shorthands.c(), { ratio: ratio(shorthands.size(), properties.size()) }),
965
918
  browserhacks: assign(propertyHacks.c(), { ratio: ratio(propertyHacks.size(), properties.size()) }),
966
919
  complexity: propertyComplexity
967
920
  }),
@@ -0,0 +1,11 @@
1
+ //#region src/keyword-set.d.ts
2
+ /**
3
+ * @description A Set-like construct to search CSS keywords in a case-insensitive way
4
+ */
5
+ declare class KeywordSet {
6
+ set: Set<string>;
7
+ constructor(items: Lowercase<string>[]);
8
+ has(item: string): boolean;
9
+ }
10
+ //#endregion
11
+ export { KeywordSet as t };
@@ -0,0 +1,16 @@
1
+ //#region src/keyword-set.ts
2
+ /**
3
+ * @description A Set-like construct to search CSS keywords in a case-insensitive way
4
+ */
5
+ var KeywordSet = class {
6
+ set;
7
+ constructor(items) {
8
+ /** @type {Set<string>} */
9
+ this.set = new Set(items);
10
+ }
11
+ has(item) {
12
+ return this.set.has(item.toLowerCase());
13
+ }
14
+ };
15
+ //#endregion
16
+ export { KeywordSet as t };
@@ -0,0 +1,2 @@
1
+ import { a as shorthand_properties, i as isHack, n as basename, r as border_radius_properties, t as SPACING_RESET_PROPERTIES } from "../property-utils-MKX6iGvg.js";
2
+ export { basename, border_radius_properties, isHack as is_property_hack, shorthand_properties, SPACING_RESET_PROPERTIES as spacing_reset_properties };
@@ -0,0 +1,2 @@
1
+ import { a as shorthand_properties, i as isHack, n as basename, r as border_radius_properties, t as SPACING_RESET_PROPERTIES } from "../property-utils-B3n9KkA9.js";
2
+ export { basename, border_radius_properties, isHack as is_property_hack, shorthand_properties, SPACING_RESET_PROPERTIES as spacing_reset_properties };
@@ -0,0 +1,107 @@
1
+ import { t as KeywordSet } from "./keyword-set-qSyAMR9o.js";
2
+ import { is_custom, is_vendor_prefixed } from "@projectwallace/css-parser";
3
+ //#region src/properties/property-utils.ts
4
+ const shorthand_properties = new Set([
5
+ "all",
6
+ "animation",
7
+ "background",
8
+ "border",
9
+ "border-block-end",
10
+ "border-block-start",
11
+ "border-bottom",
12
+ "border-color",
13
+ "border-image",
14
+ "border-inline-end",
15
+ "border-inline-start",
16
+ "border-left",
17
+ "border-radius",
18
+ "border-right",
19
+ "border-style",
20
+ "border-top",
21
+ "border-width",
22
+ "column-rule",
23
+ "columns",
24
+ "contain-intrinsic-size",
25
+ "flex",
26
+ "flex-flow",
27
+ "font",
28
+ "gap",
29
+ "grid",
30
+ "grid-area",
31
+ "grid-column",
32
+ "grid-row",
33
+ "grid-template",
34
+ "inset",
35
+ "list-style",
36
+ "margin",
37
+ "mask",
38
+ "offset",
39
+ "outline",
40
+ "overflow",
41
+ "padding",
42
+ "place-content",
43
+ "place-items",
44
+ "place-self",
45
+ "scroll-margin",
46
+ "scroll-padding",
47
+ "scroll-timeline",
48
+ "text-decoration",
49
+ "text-emphasis",
50
+ "transition",
51
+ "vertical-align"
52
+ ]);
53
+ const SPACING_RESET_PROPERTIES = new Set([
54
+ "margin",
55
+ "margin-block",
56
+ "margin-inline",
57
+ "margin-top",
58
+ "margin-block-start",
59
+ "margin-block-end",
60
+ "margin-inline-end",
61
+ "margin-inline-end",
62
+ "margin-right",
63
+ "margin-bottom",
64
+ "margin-left",
65
+ "padding",
66
+ "padding-block",
67
+ "padding-inline",
68
+ "padding-top",
69
+ "padding-right",
70
+ "padding-bottom",
71
+ "padding-left",
72
+ "padding-block-start",
73
+ "padding-block-end",
74
+ "padding-inline-start",
75
+ "padding-inline-end"
76
+ ]);
77
+ const border_radius_properties = new KeywordSet([
78
+ "border-radius",
79
+ "border-top-left-radius",
80
+ "border-top-right-radius",
81
+ "border-bottom-right-radius",
82
+ "border-bottom-left-radius",
83
+ "border-start-start-radius",
84
+ "border-start-end-radius",
85
+ "border-end-end-radius",
86
+ "border-end-start-radius"
87
+ ]);
88
+ /**
89
+ * @see https://github.com/csstree/csstree/blob/master/lib/utils/names.js#L69
90
+ */
91
+ function isHack(property) {
92
+ if (is_custom(property) || is_vendor_prefixed(property)) return false;
93
+ let code = property.charCodeAt(0);
94
+ return code === 47 || code === 42 || code === 95 || code === 43 || code === 38 || code === 36 || code === 35;
95
+ }
96
+ /**
97
+ * Get the normalized basename for a property with a vendor prefix
98
+ * @returns The property name without vendor prefix
99
+ */
100
+ function basename(property) {
101
+ if (is_custom(property)) return property;
102
+ if (is_vendor_prefixed(property)) return property.slice(property.indexOf("-", 2) + 1).toLowerCase();
103
+ if (isHack(property)) return property.slice(1).toLowerCase();
104
+ return property.toLowerCase();
105
+ }
106
+ //#endregion
107
+ export { shorthand_properties as a, isHack as i, basename as n, border_radius_properties as r, SPACING_RESET_PROPERTIES as t };
@@ -0,0 +1,17 @@
1
+ import { t as KeywordSet } from "./keyword-set-BXSoLQ6m.js";
2
+
3
+ //#region src/properties/property-utils.d.ts
4
+ declare const shorthand_properties: Set<string>;
5
+ declare const SPACING_RESET_PROPERTIES: Set<string>;
6
+ declare const border_radius_properties: KeywordSet;
7
+ /**
8
+ * @see https://github.com/csstree/csstree/blob/master/lib/utils/names.js#L69
9
+ */
10
+ declare function isHack(property: string): boolean;
11
+ /**
12
+ * Get the normalized basename for a property with a vendor prefix
13
+ * @returns The property name without vendor prefix
14
+ */
15
+ declare function basename(property: string): string;
16
+ //#endregion
17
+ export { shorthand_properties as a, isHack as i, basename as n, border_radius_properties as r, SPACING_RESET_PROPERTIES as t };
@@ -1,2 +1,2 @@
1
- import { a as calculate, i as isPrefixed, n as getComplexity, o as calculateForAST, r as isAccessibility, s as compare, t as getCombinators } from "../utils-BUeYqEL1.js";
1
+ import { a as calculate, i as isPrefixed, n as getComplexity, o as calculateForAST, r as isAccessibility, s as compare, t as getCombinators } from "../utils-DJb_IpTO.js";
2
2
  export { compare as compareSpecificity, getCombinators, getComplexity, calculate as getSpecificity, calculateForAST as getSpecificityForAST, isAccessibility, isPrefixed };
@@ -1,3 +1,3 @@
1
- import "../string-utils-olNNcOlY.js";
2
- import { a as getComplexity, i as getCombinators, n as calculateForAST, o as isAccessibility, r as compare, s as isPrefixed, t as calculate } from "../specificity-svLpcKkT.js";
1
+ import "../string-utils-C97yyuqE.js";
2
+ import { a as getComplexity, i as getCombinators, n as calculateForAST, o as isAccessibility, r as compare, s as isPrefixed, t as calculate } from "../specificity-BKdu6JZr.js";
3
3
  export { compare as compareSpecificity, getCombinators, getComplexity, calculate as getSpecificity, calculateForAST as getSpecificityForAST, isAccessibility, isPrefixed };
@@ -1,4 +1,5 @@
1
- import { n as unquote, r as KeywordSet } from "./string-utils-olNNcOlY.js";
1
+ import { t as KeywordSet } from "./keyword-set-qSyAMR9o.js";
2
+ import { n as unquote } from "./string-utils-C97yyuqE.js";
2
3
  import { ATTRIBUTE_SELECTOR, CLASS_SELECTOR, COMBINATOR, ID_SELECTOR, NTH_OF_SELECTOR, NTH_SELECTOR, PSEUDO_CLASS_SELECTOR, PSEUDO_ELEMENT_SELECTOR, SELECTOR, SELECTOR_LIST, SKIP, TYPE_SELECTOR, str_equals, str_starts_with, walk } from "@projectwallace/css-parser";
3
4
  import { parse_selector } from "@projectwallace/css-parser/parse-selector";
4
5
  //#region src/selectors/utils.ts
@@ -1,19 +1,4 @@
1
1
  import "@projectwallace/css-parser";
2
- //#region src/keyword-set.ts
3
- /**
4
- * @description A Set-like construct to search CSS keywords in a case-insensitive way
5
- */
6
- var KeywordSet = class {
7
- set;
8
- constructor(items) {
9
- /** @type {Set<string>} */
10
- this.set = new Set(items);
11
- }
12
- has(item) {
13
- return this.set.has(item.toLowerCase());
14
- }
15
- };
16
- //#endregion
17
2
  //#region src/string-utils.ts
18
3
  function unquote(str) {
19
4
  return str.replaceAll(/(?:^['"])|(?:['"]$)/g, "");
@@ -46,4 +31,4 @@ function endsWith(base, maybe) {
46
31
  return true;
47
32
  }
48
33
  //#endregion
49
- export { unquote as n, KeywordSet as r, endsWith as t };
34
+ export { unquote as n, endsWith as t };
@@ -1,4 +1,4 @@
1
- import { a as namedColors, i as colorKeywords, n as keywords, o as systemColors, r as colorFunctions, t as isValueReset } from "../values-Dw53soqy.js";
1
+ import { a as namedColors, i as colorKeywords, n as keywords, o as systemColors, r as colorFunctions, t as isValueReset } from "../values-B5nDaGc_.js";
2
2
  import { CSSNode } from "@projectwallace/css-parser";
3
3
 
4
4
  //#region src/values/browserhacks.d.ts
@@ -1,3 +1,3 @@
1
- import "../string-utils-olNNcOlY.js";
2
- import { a as colorKeywords, i as colorFunctions, n as isValueReset, o as namedColors, r as keywords, s as systemColors, t as isIe9Hack } from "../browserhacks-eP_e1D5u.js";
1
+ import "../string-utils-C97yyuqE.js";
2
+ import { a as colorKeywords, i as colorFunctions, n as isValueReset, o as namedColors, r as keywords, s as systemColors, t as isIe9Hack } from "../browserhacks-Ckz2JiOQ.js";
3
3
  export { colorFunctions, colorKeywords, isIe9Hack, isValueReset, keywords, namedColors, systemColors };
@@ -1,15 +1,6 @@
1
+ import { t as KeywordSet } from "./keyword-set-BXSoLQ6m.js";
1
2
  import { CSSNode } from "@projectwallace/css-parser";
2
3
 
3
- //#region src/keyword-set.d.ts
4
- /**
5
- * @description A Set-like construct to search CSS keywords in a case-insensitive way
6
- */
7
- declare class KeywordSet {
8
- set: Set<string>;
9
- constructor(items: Lowercase<string>[]);
10
- has(item: string): boolean;
11
- }
12
- //#endregion
13
4
  //#region src/values/colors.d.ts
14
5
  declare const namedColors: KeywordSet;
15
6
  declare const systemColors: KeywordSet;
@@ -23,4 +14,4 @@ declare const keywords: KeywordSet;
23
14
  */
24
15
  declare function isValueReset(node: CSSNode): boolean;
25
16
  //#endregion
26
- export { namedColors as a, colorKeywords as i, keywords as n, systemColors as o, colorFunctions as r, KeywordSet as s, isValueReset as t };
17
+ export { namedColors as a, colorKeywords as i, keywords as n, systemColors as o, colorFunctions as r, isValueReset as t };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@projectwallace/css-analyzer",
3
3
  "description": "The best CSS analyzer out there. Check design tokens, complexity, specificity, performance and more.",
4
- "version": "9.5.0",
4
+ "version": "9.6.0",
5
5
  "author": "Bart Veneman",
6
6
  "repository": {
7
7
  "type": "git",
@@ -32,6 +32,10 @@
32
32
  "./values": {
33
33
  "types": "./dist/values/index.d.ts",
34
34
  "default": "./dist/values/index.js"
35
+ },
36
+ "./properties": {
37
+ "types": "./dist/properties/index.d.ts",
38
+ "default": "./dist/properties/index.js"
35
39
  }
36
40
  },
37
41
  "engines": {