@master/css 2.0.0-rc.69 → 2.0.0-rc.70

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.
Files changed (200) hide show
  1. package/README.md +6 -8
  2. package/dist/index.d.ts +2 -40
  3. package/dist/index.mjs +1 -42
  4. package/package.json +1 -1
  5. package/src/base.css +1 -0
  6. package/src/index.css +1 -0
  7. package/src/theme.css +1 -0
  8. package/src/utilities.css +1 -0
  9. package/src/variants.css +1 -0
  10. package/dist/_virtual/_commonjsHelpers.cjs +0 -10
  11. package/dist/_virtual/_commonjsHelpers.mjs +0 -7
  12. package/dist/_virtual/css-escape.cjs +0 -5
  13. package/dist/_virtual/css-escape.mjs +0 -3
  14. package/dist/animation-rule.cjs +0 -24
  15. package/dist/animation-rule.d.ts +0 -11
  16. package/dist/animation-rule.mjs +0 -22
  17. package/dist/bin/index.cjs +0 -11
  18. package/dist/bin/index.d.ts +0 -1
  19. package/dist/bin/index.mjs +0 -9
  20. package/dist/common.cjs +0 -208
  21. package/dist/common.d.ts +0 -40
  22. package/dist/common.mjs +0 -180
  23. package/dist/config/animations.cjs +0 -113
  24. package/dist/config/animations.d.ts +0 -110
  25. package/dist/config/animations.mjs +0 -111
  26. package/dist/config/at.cjs +0 -19
  27. package/dist/config/at.d.ts +0 -16
  28. package/dist/config/at.mjs +0 -17
  29. package/dist/config/functions.cjs +0 -141
  30. package/dist/config/functions.d.ts +0 -138
  31. package/dist/config/functions.mjs +0 -139
  32. package/dist/config/index.cjs +0 -40
  33. package/dist/config/index.d.ts +0 -12
  34. package/dist/config/index.mjs +0 -29
  35. package/dist/config/modes.cjs +0 -312
  36. package/dist/config/modes.d.ts +0 -309
  37. package/dist/config/modes.mjs +0 -310
  38. package/dist/config/rules.cjs +0 -2277
  39. package/dist/config/rules.d.ts +0 -1485
  40. package/dist/config/rules.mjs +0 -2275
  41. package/dist/config/screens.cjs +0 -17
  42. package/dist/config/screens.d.ts +0 -14
  43. package/dist/config/screens.mjs +0 -15
  44. package/dist/config/selectors.cjs +0 -25
  45. package/dist/config/selectors.d.ts +0 -22
  46. package/dist/config/selectors.mjs +0 -23
  47. package/dist/config/utilities.cjs +0 -446
  48. package/dist/config/utilities.d.ts +0 -443
  49. package/dist/config/utilities.mjs +0 -444
  50. package/dist/config/variables.cjs +0 -99
  51. package/dist/config/variables.d.ts +0 -423
  52. package/dist/config/variables.mjs +0 -97
  53. package/dist/core.cjs +0 -674
  54. package/dist/core.d.ts +0 -128
  55. package/dist/core.mjs +0 -672
  56. package/dist/create.cjs +0 -10
  57. package/dist/create.d.ts +0 -3
  58. package/dist/create.mjs +0 -8
  59. package/dist/declarers/core.group.cjs +0 -99
  60. package/dist/declarers/core.group.d.ts +0 -2
  61. package/dist/declarers/core.group.mjs +0 -97
  62. package/dist/declarers/core.variable.cjs +0 -9
  63. package/dist/declarers/core.variable.d.ts +0 -4
  64. package/dist/declarers/core.variable.mjs +0 -7
  65. package/dist/declarers/index.cjs +0 -13
  66. package/dist/declarers/index.d.ts +0 -10
  67. package/dist/declarers/index.mjs +0 -11
  68. package/dist/declarers/pair.cjs +0 -12
  69. package/dist/declarers/pair.d.ts +0 -4
  70. package/dist/declarers/pair.mjs +0 -10
  71. package/dist/factories/with-syntax-layer.cjs +0 -83
  72. package/dist/factories/with-syntax-layer.d.ts +0 -26
  73. package/dist/factories/with-syntax-layer.mjs +0 -81
  74. package/dist/function-transformers/core.calc.cjs +0 -225
  75. package/dist/function-transformers/core.calc.d.ts +0 -2
  76. package/dist/function-transformers/core.calc.mjs +0 -223
  77. package/dist/function-transformers/core.variable.cjs +0 -23
  78. package/dist/function-transformers/core.variable.d.ts +0 -7
  79. package/dist/function-transformers/core.variable.mjs +0 -21
  80. package/dist/function-transformers/index.cjs +0 -11
  81. package/dist/function-transformers/index.d.ts +0 -8
  82. package/dist/function-transformers/index.mjs +0 -9
  83. package/dist/index.cjs +0 -118
  84. package/dist/layer.cjs +0 -52
  85. package/dist/layer.d.ts +0 -16
  86. package/dist/layer.mjs +0 -50
  87. package/dist/non-layer.cjs +0 -55
  88. package/dist/non-layer.d.ts +0 -12
  89. package/dist/non-layer.mjs +0 -53
  90. package/dist/polyfills/css-escape.cjs +0 -9
  91. package/dist/polyfills/css-escape.d.ts +0 -0
  92. package/dist/polyfills/css-escape.mjs +0 -7
  93. package/dist/polyfills/css-escape2.cjs +0 -76
  94. package/dist/polyfills/css-escape2.mjs +0 -74
  95. package/dist/register-global.cjs +0 -7
  96. package/dist/register-global.d.ts +0 -5
  97. package/dist/register-global.mjs +0 -5
  98. package/dist/rule.cjs +0 -16
  99. package/dist/rule.d.ts +0 -7
  100. package/dist/rule.mjs +0 -14
  101. package/dist/shared/utils/css-escape.cjs +0 -56
  102. package/dist/shared/utils/css-escape.mjs +0 -54
  103. package/dist/shared/utils/find-native-css-rule-index.cjs +0 -12
  104. package/dist/shared/utils/find-native-css-rule-index.mjs +0 -10
  105. package/dist/syntax-layer.cjs +0 -8
  106. package/dist/syntax-layer.d.ts +0 -18
  107. package/dist/syntax-layer.mjs +0 -6
  108. package/dist/syntax-rule-type.cjs +0 -27
  109. package/dist/syntax-rule-type.d.ts +0 -28
  110. package/dist/syntax-rule-type.mjs +0 -25
  111. package/dist/syntax-rule.cjs +0 -506
  112. package/dist/syntax-rule.d.ts +0 -44
  113. package/dist/syntax-rule.mjs +0 -504
  114. package/dist/transformers/auto-fill-solid.cjs +0 -31
  115. package/dist/transformers/auto-fill-solid.d.ts +0 -2
  116. package/dist/transformers/auto-fill-solid.mjs +0 -29
  117. package/dist/transformers/index.cjs +0 -9
  118. package/dist/transformers/index.d.ts +0 -6
  119. package/dist/transformers/index.mjs +0 -7
  120. package/dist/types/common.cjs +0 -2
  121. package/dist/types/common.d.ts +0 -1
  122. package/dist/types/common.mjs +0 -1
  123. package/dist/types/config.cjs +0 -2
  124. package/dist/types/config.d.ts +0 -79
  125. package/dist/types/config.mjs +0 -1
  126. package/dist/types/syntax.cjs +0 -2
  127. package/dist/types/syntax.d.ts +0 -89
  128. package/dist/types/syntax.mjs +0 -1
  129. package/dist/utils/compare-rule-priority.cjs +0 -143
  130. package/dist/utils/compare-rule-priority.d.ts +0 -7
  131. package/dist/utils/compare-rule-priority.mjs +0 -138
  132. package/dist/utils/equal-at-rules.cjs +0 -22
  133. package/dist/utils/equal-at-rules.d.ts +0 -2
  134. package/dist/utils/equal-at-rules.mjs +0 -20
  135. package/dist/utils/equal-declarations.cjs +0 -10
  136. package/dist/utils/equal-declarations.d.ts +0 -2
  137. package/dist/utils/equal-declarations.mjs +0 -8
  138. package/dist/utils/equal-selectors.cjs +0 -69
  139. package/dist/utils/equal-selectors.d.ts +0 -2
  140. package/dist/utils/equal-selectors.mjs +0 -67
  141. package/dist/utils/equal-variants.cjs +0 -10
  142. package/dist/utils/equal-variants.d.ts +0 -2
  143. package/dist/utils/equal-variants.mjs +0 -8
  144. package/dist/utils/extend-config.cjs +0 -97
  145. package/dist/utils/extend-config.d.ts +0 -11
  146. package/dist/utils/extend-config.mjs +0 -95
  147. package/dist/utils/flatten-meta-object.cjs +0 -38
  148. package/dist/utils/flatten-meta-object.d.ts +0 -13
  149. package/dist/utils/flatten-meta-object.mjs +0 -36
  150. package/dist/utils/flatten-object.cjs +0 -19
  151. package/dist/utils/flatten-object.d.ts +0 -1
  152. package/dist/utils/flatten-object.mjs +0 -17
  153. package/dist/utils/generate-at.cjs +0 -30
  154. package/dist/utils/generate-at.d.ts +0 -2
  155. package/dist/utils/generate-at.mjs +0 -28
  156. package/dist/utils/generate-css.cjs +0 -13
  157. package/dist/utils/generate-css.d.ts +0 -1
  158. package/dist/utils/generate-css.mjs +0 -11
  159. package/dist/utils/generate-selector.cjs +0 -50
  160. package/dist/utils/generate-selector.d.ts +0 -2
  161. package/dist/utils/generate-selector.mjs +0 -48
  162. package/dist/utils/get-single-at-number-rule-node.cjs +0 -9
  163. package/dist/utils/get-single-at-number-rule-node.d.ts +0 -2
  164. package/dist/utils/get-single-at-number-rule-node.mjs +0 -7
  165. package/dist/utils/hex-to-rgb.cjs +0 -30
  166. package/dist/utils/hex-to-rgb.d.ts +0 -1
  167. package/dist/utils/hex-to-rgb.mjs +0 -28
  168. package/dist/utils/is-core-rule.cjs +0 -9
  169. package/dist/utils/is-core-rule.d.ts +0 -1
  170. package/dist/utils/is-core-rule.mjs +0 -7
  171. package/dist/utils/minify-extended-config.cjs +0 -64
  172. package/dist/utils/minify-extended-config.d.ts +0 -9
  173. package/dist/utils/minify-extended-config.mjs +0 -62
  174. package/dist/utils/nest-meta-object.cjs +0 -25
  175. package/dist/utils/nest-meta-object.d.ts +0 -7
  176. package/dist/utils/nest-meta-object.mjs +0 -23
  177. package/dist/utils/parse-at.cjs +0 -156
  178. package/dist/utils/parse-at.d.ts +0 -39
  179. package/dist/utils/parse-at.mjs +0 -154
  180. package/dist/utils/parse-pair.cjs +0 -48
  181. package/dist/utils/parse-pair.d.ts +0 -8
  182. package/dist/utils/parse-pair.mjs +0 -46
  183. package/dist/utils/parse-selector.cjs +0 -114
  184. package/dist/utils/parse-selector.d.ts +0 -19
  185. package/dist/utils/parse-selector.mjs +0 -112
  186. package/dist/utils/parse-value.cjs +0 -39
  187. package/dist/utils/parse-value.d.ts +0 -2
  188. package/dist/utils/parse-value.mjs +0 -37
  189. package/dist/utils/replace-char-outside-quotes.cjs +0 -21
  190. package/dist/utils/replace-char-outside-quotes.d.ts +0 -1
  191. package/dist/utils/replace-char-outside-quotes.mjs +0 -19
  192. package/dist/utils/sort-readable-classes.cjs +0 -86
  193. package/dist/utils/sort-readable-classes.d.ts +0 -7
  194. package/dist/utils/sort-readable-classes.mjs +0 -84
  195. package/dist/utils/split-char-outside-quotes.cjs +0 -29
  196. package/dist/utils/split-char-outside-quotes.d.ts +0 -1
  197. package/dist/utils/split-char-outside-quotes.mjs +0 -27
  198. package/dist/variable-rule.cjs +0 -92
  199. package/dist/variable-rule.d.ts +0 -33
  200. package/dist/variable-rule.mjs +0 -87
@@ -1,79 +0,0 @@
1
- import type { PropertiesHyphen } from 'csstype';
2
- import type { rules, utilities } from '../config';
3
- import { AT_IDENTIFIERS } from '../common';
4
- import { DeclarerNames } from '../declarers';
5
- import { TransformerNames } from '../transformers';
6
- import { FunctionTransformerNames } from '../function-transformers';
7
- import SyntaxRuleType from '../syntax-rule-type';
8
- export interface SyntaxRuleDefinition {
9
- type?: SyntaxRuleType;
10
- matcher?: RegExp | string;
11
- sign?: string;
12
- key?: string;
13
- subkey?: string;
14
- aliasGroups?: string[];
15
- values?: string[];
16
- kind?: 'number' | 'color' | 'image';
17
- namespaces?: string[];
18
- separators?: string[];
19
- unit?: any;
20
- declarations?: PropertiesHyphen | Record<string, string | undefined | (string | undefined)[]> | (keyof PropertiesHyphen)[];
21
- includeAnimations?: boolean;
22
- declarer?: DeclarerNames | [DeclarerNames, any];
23
- transformer?: TransformerNames | [TransformerNames, any];
24
- }
25
- export type VariableValue = number | string | false | (number | string)[];
26
- export type VariableDefinition = {
27
- [key in '' | string]?: VariableValue | VariableDefinition;
28
- } | VariableValue;
29
- export type CSSKeyframes = Record<'from' | 'to' | string, PropertiesHyphen>;
30
- export type AnimationDefinitions = Record<string, CSSKeyframes>;
31
- export type SelectorDefinitions = Record<string, string>;
32
- export type AtIdentifier = typeof AT_IDENTIFIERS[number];
33
- export type AtDefinition = number | string;
34
- export interface AtDefinitions {
35
- [key: string]: AtDefinition | AtDefinitions;
36
- }
37
- export interface ComponentDefinitions {
38
- [key: string]: string | ComponentDefinitions;
39
- }
40
- export type ScreenDefinitions = Record<string, number>;
41
- export type SyntaxRuleDefinitions = Partial<Record<keyof typeof rules | string, SyntaxRuleDefinition>>;
42
- export type VariableDefinitions = {
43
- [key in keyof typeof rules]?: VariableDefinition;
44
- } & Record<string, VariableDefinition>;
45
- export type UtilityDefinitions = {
46
- [key in keyof typeof utilities]?: PropertiesHyphen;
47
- } & Record<string, PropertiesHyphen>;
48
- export type ModeDefinitions = Record<string, VariableDefinitions>;
49
- export interface FunctionDefinition {
50
- unit?: string;
51
- transformer?: FunctionTransformerNames | [FunctionTransformerNames, any];
52
- }
53
- export type FunctionDefinitions = Record<string, FunctionDefinition>;
54
- export interface Config {
55
- extends?: (Config | any)[];
56
- components?: ComponentDefinitions;
57
- at?: AtDefinitions;
58
- selectors?: SelectorDefinitions;
59
- utilities?: UtilityDefinitions;
60
- variables?: VariableDefinitions;
61
- rules?: SyntaxRuleDefinitions;
62
- screens?: ScreenDefinitions;
63
- rootSize?: number;
64
- baseUnit?: number;
65
- defaultMode?: 'light' | 'dark' | string | false;
66
- scope?: string;
67
- important?: boolean;
68
- functions?: FunctionDefinitions;
69
- animations?: AnimationDefinitions;
70
- modes?: ModeDefinitions;
71
- modeTrigger?: 'class' | 'media' | 'host';
72
- }
73
- declare module 'csstype' {
74
- interface PropertiesHyphen {
75
- '-webkit-user-drag'?: 'auto' | 'element' | 'none' | 'inherit';
76
- 'user-drag'?: 'auto' | 'element' | 'none' | 'inherit';
77
- '-webkit-text-decoration'?: string;
78
- }
79
- }
@@ -1 +0,0 @@
1
-
@@ -1,2 +0,0 @@
1
- 'use strict';
2
-
@@ -1,89 +0,0 @@
1
- import { SyntaxRuleDefinition } from './config';
2
- export type ValueComponent = StringValueComponent | NumberValueComponent | FunctionValueComponent | VariableValueComponent | SeparatorValueComponent;
3
- export interface StringValueComponent {
4
- text?: string;
5
- token: string;
6
- type: 'string';
7
- value: string;
8
- }
9
- export interface NumberValueComponent {
10
- text?: string;
11
- token: string;
12
- type: 'number';
13
- value: number;
14
- unit?: string;
15
- }
16
- export interface FunctionValueComponent {
17
- text?: string;
18
- token: string;
19
- type: 'function';
20
- name: string;
21
- symbol: string;
22
- children: ValueComponent[];
23
- bypassTransform?: boolean;
24
- }
25
- export interface VariableValueComponent {
26
- text?: string;
27
- token: string;
28
- type: 'variable';
29
- name: string;
30
- alpha?: number;
31
- fallback?: string;
32
- variable?: Variable;
33
- }
34
- export interface SeparatorValueComponent {
35
- text?: string;
36
- token: string;
37
- type: 'separator';
38
- value: string;
39
- }
40
- export interface DefinedRule {
41
- id: string;
42
- key?: string;
43
- keys: string[];
44
- matchers: {
45
- key?: RegExp;
46
- variable?: RegExp;
47
- value?: RegExp;
48
- arbitrary?: RegExp;
49
- };
50
- variables?: Map<string, Variable>;
51
- order: number;
52
- definition: SyntaxRuleDefinition;
53
- }
54
- export type MediaFeatureComponent = {
55
- type: string;
56
- tokenType?: string;
57
- operator?: string;
58
- value: number;
59
- unit: string;
60
- };
61
- export interface MediaQuery {
62
- token: string;
63
- features: Record<string, MediaFeatureComponent>;
64
- type?: string;
65
- }
66
- type VariableCommon = {
67
- namespace?: string;
68
- group?: string;
69
- name: string;
70
- key: string;
71
- modes?: Record<string, LiteralVariable>;
72
- };
73
- export type StringVariable = {
74
- type: 'string';
75
- value: string;
76
- };
77
- export type NumberVariable = {
78
- type: 'number';
79
- value: number;
80
- };
81
- export type ColorVariable = {
82
- type: 'color';
83
- value: string;
84
- space: 'rgb' | 'hsl';
85
- alpha?: number;
86
- };
87
- export type LiteralVariable = StringVariable | NumberVariable | ColorVariable;
88
- export type Variable = LiteralVariable & VariableCommon;
89
- export {};
@@ -1 +0,0 @@
1
-
@@ -1,143 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- // ✅ Pseudo-class priority (lower = weaker)
6
- const selectorPriority = {
7
- hover: 1,
8
- focus: 2,
9
- active: 3,
10
- disabled: 4
11
- };
12
- function extractSelectorPriority(nodes = []) {
13
- let priority = 0;
14
- for (const node of nodes){
15
- if ('value' in node && typeof node.value === 'string') {
16
- priority += selectorPriority[node.value] ?? 0;
17
- }
18
- if ('children' in node && Array.isArray(node.children)) {
19
- priority += extractSelectorPriority(node.children);
20
- }
21
- }
22
- return priority;
23
- }
24
- const NOT_COMPARISON_OPERATORS = {
25
- '>=': '<',
26
- '<=': '>',
27
- '>': '<=',
28
- '<': '>='
29
- };
30
- function getAtRuleEntries(nestNodes) {
31
- const featureMap = new Map();
32
- const walk = (list, isOutsideNot = false)=>{
33
- (list ?? []).forEach((node, i, arr)=>{
34
- const prev = arr[i - 1];
35
- if ('operator' in node) {
36
- const entry = featureMap.get(node.name) ?? {};
37
- let operator = node.operator;
38
- if (isOutsideNot) operator = NOT_COMPARISON_OPERATORS[operator];
39
- if (prev?.type === 'logical' && prev.value === 'not') operator = NOT_COMPARISON_OPERATORS[operator];
40
- switch(operator){
41
- case '>':
42
- entry.min = node.value + 0.02;
43
- break;
44
- case '>=':
45
- entry.min = node.value;
46
- break;
47
- case '<':
48
- entry.max = node.value - 0.02;
49
- break;
50
- case '<=':
51
- entry.max = node.value;
52
- break;
53
- }
54
- featureMap.set(node.name, entry);
55
- }
56
- if ('children' in node && Array.isArray(node.children)) {
57
- walk(node.children, prev?.type === 'logical' && prev.value === 'not');
58
- }
59
- });
60
- };
61
- walk(nestNodes);
62
- return featureMap;
63
- }
64
- // ✅ Calculate RulePriority from AST
65
- function calcRulePriority(rule) {
66
- const features = [];
67
- const extractFeatures = (nodes)=>{
68
- const featureMap = getAtRuleEntries(nodes);
69
- for (const [name, entry] of featureMap.entries()){
70
- const max = entry.max ?? Number.MAX_SAFE_INTEGER;
71
- const min = entry.min ?? 0;
72
- features.push([
73
- name,
74
- min,
75
- max
76
- ]);
77
- }
78
- };
79
- if (rule.atRules?.media) extractFeatures(rule.atRules.media);
80
- if (rule.atRules?.container) extractFeatures(rule.atRules.container);
81
- features.sort(([a], [b])=>a.localeCompare(b, undefined, {
82
- numeric: true
83
- }));
84
- const selector = extractSelectorPriority(rule.selectorNodes ?? []);
85
- return {
86
- features,
87
- selector
88
- };
89
- }
90
- function compareFeatureTuples(a, b) {
91
- const len = Math.max(a.length, b.length);
92
- for(let i = 0; i < len; i++){
93
- const aa = a[i];
94
- const bb = b[i];
95
- if (!aa) return -1;
96
- if (!bb) return 1;
97
- const [nameA, minA, maxA] = aa;
98
- const [nameB, minB, maxB] = bb;
99
- const nameCmp = nameA.localeCompare(nameB, undefined, {
100
- numeric: true
101
- });
102
- if (nameCmp !== 0) return nameCmp;
103
- const rangeA = maxA - minA;
104
- const rangeB = maxB - minB;
105
- if (rangeA !== rangeB) return rangeB - rangeA;
106
- if (minA !== minB) return minB - minA;
107
- if (maxA !== maxB) return maxB - maxA;
108
- }
109
- return 0;
110
- }
111
- // ✅ Compare function
112
- function compareRulePriority(a, b) {
113
- const getTier = (rule)=>{
114
- const hasSelector = rule.selectorNodes?.length;
115
- const hasAtRules = !!rule.atRules;
116
- const hasMode = !!rule.mode;
117
- if (hasAtRules) return 3;
118
- if (hasMode) return 2;
119
- if (hasSelector) return 1;
120
- return 0;
121
- };
122
- const aTier = getTier(a);
123
- const bTier = getTier(b);
124
- if (aTier !== bTier) return aTier - bTier;
125
- // 1. features
126
- const fa = a.priority.features || [];
127
- const fb = b.priority.features || [];
128
- const featureCmp = compareFeatureTuples(fa, fb);
129
- if (featureCmp !== 0) return featureCmp;
130
- // 2. selector
131
- const selectorCmp = a.priority.selector - b.priority.selector;
132
- if (selectorCmp !== 0) return selectorCmp;
133
- // 3. rule.type
134
- const typeCmp = a.type - b.type;
135
- if (typeCmp !== 0) return typeCmp;
136
- // 4. fallback: name
137
- return a.key.localeCompare(b.key, undefined, {
138
- numeric: true
139
- });
140
- }
141
-
142
- exports.calcRulePriority = calcRulePriority;
143
- exports.default = compareRulePriority;
@@ -1,7 +0,0 @@
1
- import { SyntaxRule } from '../syntax-rule';
2
- export type RulePriority = {
3
- features?: [string, number, number][];
4
- selector: number;
5
- };
6
- export declare function calcRulePriority(rule: SyntaxRule): RulePriority;
7
- export default function compareRulePriority(a: SyntaxRule, b: SyntaxRule): number;
@@ -1,138 +0,0 @@
1
- // ✅ Pseudo-class priority (lower = weaker)
2
- const selectorPriority = {
3
- hover: 1,
4
- focus: 2,
5
- active: 3,
6
- disabled: 4
7
- };
8
- function extractSelectorPriority(nodes = []) {
9
- let priority = 0;
10
- for (const node of nodes){
11
- if ('value' in node && typeof node.value === 'string') {
12
- priority += selectorPriority[node.value] ?? 0;
13
- }
14
- if ('children' in node && Array.isArray(node.children)) {
15
- priority += extractSelectorPriority(node.children);
16
- }
17
- }
18
- return priority;
19
- }
20
- const NOT_COMPARISON_OPERATORS = {
21
- '>=': '<',
22
- '<=': '>',
23
- '>': '<=',
24
- '<': '>='
25
- };
26
- function getAtRuleEntries(nestNodes) {
27
- const featureMap = new Map();
28
- const walk = (list, isOutsideNot = false)=>{
29
- (list ?? []).forEach((node, i, arr)=>{
30
- const prev = arr[i - 1];
31
- if ('operator' in node) {
32
- const entry = featureMap.get(node.name) ?? {};
33
- let operator = node.operator;
34
- if (isOutsideNot) operator = NOT_COMPARISON_OPERATORS[operator];
35
- if (prev?.type === 'logical' && prev.value === 'not') operator = NOT_COMPARISON_OPERATORS[operator];
36
- switch(operator){
37
- case '>':
38
- entry.min = node.value + 0.02;
39
- break;
40
- case '>=':
41
- entry.min = node.value;
42
- break;
43
- case '<':
44
- entry.max = node.value - 0.02;
45
- break;
46
- case '<=':
47
- entry.max = node.value;
48
- break;
49
- }
50
- featureMap.set(node.name, entry);
51
- }
52
- if ('children' in node && Array.isArray(node.children)) {
53
- walk(node.children, prev?.type === 'logical' && prev.value === 'not');
54
- }
55
- });
56
- };
57
- walk(nestNodes);
58
- return featureMap;
59
- }
60
- // ✅ Calculate RulePriority from AST
61
- function calcRulePriority(rule) {
62
- const features = [];
63
- const extractFeatures = (nodes)=>{
64
- const featureMap = getAtRuleEntries(nodes);
65
- for (const [name, entry] of featureMap.entries()){
66
- const max = entry.max ?? Number.MAX_SAFE_INTEGER;
67
- const min = entry.min ?? 0;
68
- features.push([
69
- name,
70
- min,
71
- max
72
- ]);
73
- }
74
- };
75
- if (rule.atRules?.media) extractFeatures(rule.atRules.media);
76
- if (rule.atRules?.container) extractFeatures(rule.atRules.container);
77
- features.sort(([a], [b])=>a.localeCompare(b, undefined, {
78
- numeric: true
79
- }));
80
- const selector = extractSelectorPriority(rule.selectorNodes ?? []);
81
- return {
82
- features,
83
- selector
84
- };
85
- }
86
- function compareFeatureTuples(a, b) {
87
- const len = Math.max(a.length, b.length);
88
- for(let i = 0; i < len; i++){
89
- const aa = a[i];
90
- const bb = b[i];
91
- if (!aa) return -1;
92
- if (!bb) return 1;
93
- const [nameA, minA, maxA] = aa;
94
- const [nameB, minB, maxB] = bb;
95
- const nameCmp = nameA.localeCompare(nameB, undefined, {
96
- numeric: true
97
- });
98
- if (nameCmp !== 0) return nameCmp;
99
- const rangeA = maxA - minA;
100
- const rangeB = maxB - minB;
101
- if (rangeA !== rangeB) return rangeB - rangeA;
102
- if (minA !== minB) return minB - minA;
103
- if (maxA !== maxB) return maxB - maxA;
104
- }
105
- return 0;
106
- }
107
- // ✅ Compare function
108
- function compareRulePriority(a, b) {
109
- const getTier = (rule)=>{
110
- const hasSelector = rule.selectorNodes?.length;
111
- const hasAtRules = !!rule.atRules;
112
- const hasMode = !!rule.mode;
113
- if (hasAtRules) return 3;
114
- if (hasMode) return 2;
115
- if (hasSelector) return 1;
116
- return 0;
117
- };
118
- const aTier = getTier(a);
119
- const bTier = getTier(b);
120
- if (aTier !== bTier) return aTier - bTier;
121
- // 1. features
122
- const fa = a.priority.features || [];
123
- const fb = b.priority.features || [];
124
- const featureCmp = compareFeatureTuples(fa, fb);
125
- if (featureCmp !== 0) return featureCmp;
126
- // 2. selector
127
- const selectorCmp = a.priority.selector - b.priority.selector;
128
- if (selectorCmp !== 0) return selectorCmp;
129
- // 3. rule.type
130
- const typeCmp = a.type - b.type;
131
- if (typeCmp !== 0) return typeCmp;
132
- // 4. fallback: name
133
- return a.key.localeCompare(b.key, undefined, {
134
- numeric: true
135
- });
136
- }
137
-
138
- export { calcRulePriority, compareRulePriority as default };
@@ -1,22 +0,0 @@
1
- 'use strict';
2
-
3
- var common = require('../common.cjs');
4
-
5
- function areNodesEqual(a, b) {
6
- return a.type === b.type && a.value === b.value && a.unit === b.unit && a.name === b.name && a.operator === b.operator && areNodeArraysEqual(a.children ?? [], b.children ?? []);
7
- }
8
- function areNodeArraysEqual(aNodes, bNodes) {
9
- if (aNodes.length !== bNodes.length) return false;
10
- const matched = new Array(bNodes.length).fill(false);
11
- for (const aNode of aNodes){
12
- const index = bNodes.findIndex((bNode, i)=>!matched[i] && areNodesEqual(aNode, bNode));
13
- if (index === -1) return false;
14
- matched[index] = true;
15
- }
16
- return true;
17
- }
18
- function equalAtRules(a, b) {
19
- return common.AT_IDENTIFIERS.every((key)=>areNodeArraysEqual(a?.[key] ?? [], b?.[key] ?? []));
20
- }
21
-
22
- module.exports = equalAtRules;
@@ -1,2 +0,0 @@
1
- import type { SyntaxRule } from '../syntax-rule';
2
- export default function equalAtRules(a: SyntaxRule['atRules'], b: SyntaxRule['atRules']): boolean;
@@ -1,20 +0,0 @@
1
- import { AT_IDENTIFIERS } from '../common.mjs';
2
-
3
- function areNodesEqual(a, b) {
4
- return a.type === b.type && a.value === b.value && a.unit === b.unit && a.name === b.name && a.operator === b.operator && areNodeArraysEqual(a.children ?? [], b.children ?? []);
5
- }
6
- function areNodeArraysEqual(aNodes, bNodes) {
7
- if (aNodes.length !== bNodes.length) return false;
8
- const matched = new Array(bNodes.length).fill(false);
9
- for (const aNode of aNodes){
10
- const index = bNodes.findIndex((bNode, i)=>!matched[i] && areNodesEqual(aNode, bNode));
11
- if (index === -1) return false;
12
- matched[index] = true;
13
- }
14
- return true;
15
- }
16
- function equalAtRules(a, b) {
17
- return AT_IDENTIFIERS.every((key)=>areNodeArraysEqual(a?.[key] ?? [], b?.[key] ?? []));
18
- }
19
-
20
- export { equalAtRules as default };
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- function equalDeclarations(a = {}, b = {}) {
4
- if (Object.keys(a).length !== Object.keys(b).length) {
5
- return false;
6
- }
7
- return Object.keys(a).every((key)=>key in b);
8
- }
9
-
10
- module.exports = equalDeclarations;
@@ -1,2 +0,0 @@
1
- import { SyntaxRule } from '../syntax-rule';
2
- export default function equalDeclarations(a?: SyntaxRule['declarations'], b?: SyntaxRule['declarations']): boolean;
@@ -1,8 +0,0 @@
1
- function equalDeclarations(a = {}, b = {}) {
2
- if (Object.keys(a).length !== Object.keys(b).length) {
3
- return false;
4
- }
5
- return Object.keys(a).every((key)=>key in b);
6
- }
7
-
8
- export { equalDeclarations as default };
@@ -1,69 +0,0 @@
1
- 'use strict';
2
-
3
- function isCombinator(node) {
4
- return node.type === 'combinator';
5
- }
6
- function areSelectorNodesEqual(a, b) {
7
- if (a.type !== b.type) return false;
8
- if (a.value !== b.value) return false;
9
- const aChildren = a.children ?? [];
10
- const bChildren = b.children ?? [];
11
- if (aChildren.length !== bChildren.length) return false;
12
- return equalUnorderedSelectorNodes(aChildren, bChildren);
13
- }
14
- function equalUnorderedSelectorNodes(a, b) {
15
- if (a.length !== b.length) return false;
16
- const unmatchedB = new Set(b);
17
- for (const nodeA of a){
18
- let matched = false;
19
- for (const nodeB of unmatchedB){
20
- if (areSelectorNodesEqual(nodeA, nodeB)) {
21
- unmatchedB.delete(nodeB);
22
- matched = true;
23
- break;
24
- }
25
- }
26
- if (!matched) return false;
27
- }
28
- return true;
29
- }
30
- function splitByCombinators(nodes) {
31
- const parts = [];
32
- let buffer = [];
33
- for (const node of nodes){
34
- if (isCombinator(node)) {
35
- if (buffer.length > 0) {
36
- parts.push(buffer);
37
- buffer = [];
38
- }
39
- parts.push(node); // push combinator as-is
40
- } else {
41
- buffer.push(node);
42
- }
43
- }
44
- if (buffer.length > 0) {
45
- parts.push(buffer);
46
- }
47
- return parts;
48
- }
49
- function equalSelectors(a = [], b = []) {
50
- const aParts = splitByCombinators(a);
51
- const bParts = splitByCombinators(b);
52
- if (aParts.length !== bParts.length) return false;
53
- for(let i = 0; i < aParts.length; i++){
54
- const partA = aParts[i];
55
- const partB = bParts[i];
56
- if (Array.isArray(partA) && Array.isArray(partB)) {
57
- if (!equalUnorderedSelectorNodes(partA, partB)) return false;
58
- } else if (!Array.isArray(partA) && !Array.isArray(partB)) {
59
- // both are combinators
60
- if (!areSelectorNodesEqual(partA, partB)) return false;
61
- } else {
62
- return false // mismatch between combinator vs non-combinator
63
- ;
64
- }
65
- }
66
- return true;
67
- }
68
-
69
- module.exports = equalSelectors;
@@ -1,2 +0,0 @@
1
- import type { SelectorNode } from './parse-selector';
2
- export default function equalSelectors(a?: SelectorNode[], b?: SelectorNode[]): boolean;
@@ -1,67 +0,0 @@
1
- function isCombinator(node) {
2
- return node.type === 'combinator';
3
- }
4
- function areSelectorNodesEqual(a, b) {
5
- if (a.type !== b.type) return false;
6
- if (a.value !== b.value) return false;
7
- const aChildren = a.children ?? [];
8
- const bChildren = b.children ?? [];
9
- if (aChildren.length !== bChildren.length) return false;
10
- return equalUnorderedSelectorNodes(aChildren, bChildren);
11
- }
12
- function equalUnorderedSelectorNodes(a, b) {
13
- if (a.length !== b.length) return false;
14
- const unmatchedB = new Set(b);
15
- for (const nodeA of a){
16
- let matched = false;
17
- for (const nodeB of unmatchedB){
18
- if (areSelectorNodesEqual(nodeA, nodeB)) {
19
- unmatchedB.delete(nodeB);
20
- matched = true;
21
- break;
22
- }
23
- }
24
- if (!matched) return false;
25
- }
26
- return true;
27
- }
28
- function splitByCombinators(nodes) {
29
- const parts = [];
30
- let buffer = [];
31
- for (const node of nodes){
32
- if (isCombinator(node)) {
33
- if (buffer.length > 0) {
34
- parts.push(buffer);
35
- buffer = [];
36
- }
37
- parts.push(node); // push combinator as-is
38
- } else {
39
- buffer.push(node);
40
- }
41
- }
42
- if (buffer.length > 0) {
43
- parts.push(buffer);
44
- }
45
- return parts;
46
- }
47
- function equalSelectors(a = [], b = []) {
48
- const aParts = splitByCombinators(a);
49
- const bParts = splitByCombinators(b);
50
- if (aParts.length !== bParts.length) return false;
51
- for(let i = 0; i < aParts.length; i++){
52
- const partA = aParts[i];
53
- const partB = bParts[i];
54
- if (Array.isArray(partA) && Array.isArray(partB)) {
55
- if (!equalUnorderedSelectorNodes(partA, partB)) return false;
56
- } else if (!Array.isArray(partA) && !Array.isArray(partB)) {
57
- // both are combinators
58
- if (!areSelectorNodesEqual(partA, partB)) return false;
59
- } else {
60
- return false // mismatch between combinator vs non-combinator
61
- ;
62
- }
63
- }
64
- return true;
65
- }
66
-
67
- export { equalSelectors as default };