@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,7 +0,0 @@
1
- import rules from '../config/rules.mjs';
2
-
3
- function isCoreRule(id) {
4
- return Object.hasOwnProperty.call(rules, id);
5
- }
6
-
7
- export { isCoreRule as default };
@@ -1,64 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Minifies an extended config by hoisting shared variables from all modes into `variables`.
5
- * Only variables with identical values across all modes are hoisted.
6
- *
7
- * @param config - The extended config with flattened variable structures
8
- * @returns A new config with deduplicated `variables` and minimized `modes`
9
- */ function minifyExtendedConfig(config) {
10
- const { variables: baseVariables = {}, modes = {}, ...rest } = config;
11
- const modeNames = Object.keys(modes);
12
- const variableNames = new Set();
13
- // Collect all variable keys from all modes
14
- for (const mode of modeNames){
15
- for(const key in modes[mode]){
16
- variableNames.add(key);
17
- }
18
- }
19
- const variables = {
20
- ...baseVariables
21
- };
22
- const newModes = {};
23
- for (const key of variableNames){
24
- let first;
25
- let allSame = true;
26
- for(let i = 0; i < modeNames.length; i++){
27
- const mode = modeNames[i];
28
- const current = modes[mode]?.[key];
29
- if (!current) {
30
- allSame = false;
31
- break;
32
- }
33
- if (i === 0) {
34
- first = current;
35
- } else if (JSON.stringify(current.value) !== JSON.stringify(first.value)) {
36
- allSame = false;
37
- break;
38
- }
39
- }
40
- const already = baseVariables[key];
41
- const valueMatches = already && JSON.stringify(already.value) === JSON.stringify(first?.value);
42
- if (allSame && (!already || valueMatches)) {
43
- if (first) {
44
- variables[key] = first;
45
- }
46
- } else {
47
- for (const mode of modeNames){
48
- if (!newModes[mode]) newModes[mode] = {};
49
- const value = modes[mode]?.[key];
50
- if (value) {
51
- newModes[mode][key] = value;
52
- }
53
- }
54
- }
55
- }
56
- const newConfig = {
57
- ...rest,
58
- variables: Object.keys(variables).length > 0 ? variables : undefined,
59
- modes: Object.keys(newModes).length > 0 ? newModes : undefined
60
- };
61
- return newConfig;
62
- }
63
-
64
- module.exports = minifyExtendedConfig;
@@ -1,9 +0,0 @@
1
- import type { ExtendedConfig } from './extend-config';
2
- /**
3
- * Minifies an extended config by hoisting shared variables from all modes into `variables`.
4
- * Only variables with identical values across all modes are hoisted.
5
- *
6
- * @param config - The extended config with flattened variable structures
7
- * @returns A new config with deduplicated `variables` and minimized `modes`
8
- */
9
- export default function minifyExtendedConfig(config: ExtendedConfig): ExtendedConfig;
@@ -1,62 +0,0 @@
1
- /**
2
- * Minifies an extended config by hoisting shared variables from all modes into `variables`.
3
- * Only variables with identical values across all modes are hoisted.
4
- *
5
- * @param config - The extended config with flattened variable structures
6
- * @returns A new config with deduplicated `variables` and minimized `modes`
7
- */ function minifyExtendedConfig(config) {
8
- const { variables: baseVariables = {}, modes = {}, ...rest } = config;
9
- const modeNames = Object.keys(modes);
10
- const variableNames = new Set();
11
- // Collect all variable keys from all modes
12
- for (const mode of modeNames){
13
- for(const key in modes[mode]){
14
- variableNames.add(key);
15
- }
16
- }
17
- const variables = {
18
- ...baseVariables
19
- };
20
- const newModes = {};
21
- for (const key of variableNames){
22
- let first;
23
- let allSame = true;
24
- for(let i = 0; i < modeNames.length; i++){
25
- const mode = modeNames[i];
26
- const current = modes[mode]?.[key];
27
- if (!current) {
28
- allSame = false;
29
- break;
30
- }
31
- if (i === 0) {
32
- first = current;
33
- } else if (JSON.stringify(current.value) !== JSON.stringify(first.value)) {
34
- allSame = false;
35
- break;
36
- }
37
- }
38
- const already = baseVariables[key];
39
- const valueMatches = already && JSON.stringify(already.value) === JSON.stringify(first?.value);
40
- if (allSame && (!already || valueMatches)) {
41
- if (first) {
42
- variables[key] = first;
43
- }
44
- } else {
45
- for (const mode of modeNames){
46
- if (!newModes[mode]) newModes[mode] = {};
47
- const value = modes[mode]?.[key];
48
- if (value) {
49
- newModes[mode][key] = value;
50
- }
51
- }
52
- }
53
- }
54
- const newConfig = {
55
- ...rest,
56
- variables: Object.keys(variables).length > 0 ? variables : undefined,
57
- modes: Object.keys(newModes).length > 0 ? newModes : undefined
58
- };
59
- return newConfig;
60
- }
61
-
62
- export { minifyExtendedConfig as default };
@@ -1,25 +0,0 @@
1
- 'use strict';
2
-
3
- function nestMetaObject(flat) {
4
- const nested = {};
5
- for (const entry of Object.values(flat)){
6
- const { group, key, value } = entry;
7
- const path = group ? group.split('.') : [];
8
- let current = nested;
9
- for (const segment of path){
10
- if (!(segment in current)) {
11
- current[segment] = {};
12
- } else if (typeof current[segment] !== 'object' || current[segment] === null) {
13
- // Wrap primitive into object: { '': value }
14
- current[segment] = {
15
- '': current[segment]
16
- };
17
- }
18
- current = current[segment];
19
- }
20
- current[key] = value;
21
- }
22
- return nested;
23
- }
24
-
25
- module.exports = nestMetaObject;
@@ -1,7 +0,0 @@
1
- export default function nestMetaObject(flat: Record<string, {
2
- name: string;
3
- value: any;
4
- key: string;
5
- group?: string;
6
- namespace?: string;
7
- }>): Record<string, any>;
@@ -1,23 +0,0 @@
1
- function nestMetaObject(flat) {
2
- const nested = {};
3
- for (const entry of Object.values(flat)){
4
- const { group, key, value } = entry;
5
- const path = group ? group.split('.') : [];
6
- let current = nested;
7
- for (const segment of path){
8
- if (!(segment in current)) {
9
- current[segment] = {};
10
- } else if (typeof current[segment] !== 'object' || current[segment] === null) {
11
- // Wrap primitive into object: { '': value }
12
- current[segment] = {
13
- '': current[segment]
14
- };
15
- }
16
- current = current[segment];
17
- }
18
- current[key] = value;
19
- }
20
- return nested;
21
- }
22
-
23
- export { nestMetaObject as default };
@@ -1,156 +0,0 @@
1
- 'use strict';
2
-
3
- var common = require('../common.cjs');
4
- var parsePair = require('./parse-pair.cjs');
5
- var parseValue = require('./parse-value.cjs');
6
- var replaceCharOutsideQuotes = require('./replace-char-outside-quotes.cjs');
7
- var splitCharOutsideQuotes = require('./split-char-outside-quotes.cjs');
8
-
9
- function parseAt(token, css, isRaw = true) {
10
- let id;
11
- let firstToken;
12
- const resolve = (token)=>{
13
- const regex = /([a-zA-Z0-9-:%|]+|[&|!|,|>|<|=][=]?)/g;
14
- const raws = [
15
- ...token.matchAll(regex)
16
- ].map((match)=>match[0]);
17
- let nodes = [];
18
- const addNode = (node)=>{
19
- let prev = nodes[nodes.length - 1];
20
- if (node.type === 'number' && !node.name) {
21
- if (prev?.type === 'comparison') {
22
- node.operator = prev.value;
23
- if (node.raw && prev.raw) {
24
- node.raw = prev.raw + node.raw;
25
- }
26
- nodes.pop();
27
- prev = nodes[nodes.length - 1];
28
- if (prev?.type === 'string') {
29
- node.name = prev.value;
30
- if (node.raw && prev.raw) {
31
- node.raw = prev.raw + node.raw;
32
- }
33
- nodes.pop();
34
- } else {
35
- node.name = 'width';
36
- }
37
- } else {
38
- node.name = 'width';
39
- node.operator = '>=';
40
- }
41
- }
42
- nodes.push(node);
43
- };
44
- raws.forEach((raw)=>{
45
- if (common.AT_COMPARISON_OPERATORS.includes(raw)) {
46
- const newNode = {
47
- type: 'comparison',
48
- value: raw
49
- };
50
- if (isRaw) newNode.raw = raw;
51
- nodes.push(newNode);
52
- return;
53
- } else if (raw in common.AT_LOGICAL_OPERATORS) {
54
- const newNode = {
55
- type: 'logical',
56
- value: common.AT_LOGICAL_OPERATORS[raw]
57
- };
58
- if (isRaw) newNode.raw = raw;
59
- nodes.push(newNode);
60
- return;
61
- }
62
- const definedAtRule = css.atRules.get(raw);
63
- if (!id && !firstToken) {
64
- firstToken = raw;
65
- if (common.AT_IDENTIFIERS.includes(firstToken)) {
66
- id = firstToken;
67
- return;
68
- } else if (definedAtRule) {
69
- id = definedAtRule.id;
70
- } else if (common.AT_COMPARABLE_FEATURES.includes(firstToken)) {
71
- id = 'media';
72
- } else if (firstToken.charAt(0).match(/[a-zA-Z-]/)) {
73
- id = 'container';
74
- } else {
75
- id = 'media';
76
- }
77
- }
78
- let node = {
79
- type: 'string'
80
- };
81
- if (isRaw) node.raw = raw;
82
- if (definedAtRule) {
83
- if (definedAtRule.nodes.length === 1) {
84
- addNode({
85
- ...definedAtRule.nodes[0],
86
- raw
87
- });
88
- } else if (definedAtRule.nodes.length) {
89
- addNode({
90
- raw,
91
- children: definedAtRule.nodes
92
- });
93
- }
94
- return;
95
- } else {
96
- const [splitedNameOrValue, splitedValue] = splitCharOutsideQuotes(raw, ':');
97
- if (splitedValue) {
98
- node.name = splitedNameOrValue;
99
- node.value = splitedValue;
100
- } else {
101
- node.value = splitedNameOrValue;
102
- }
103
- if (id === 'container' || id === 'media') {
104
- const { token, ...newNode } = parseValue(node.value, 'rem', css.config.rootSize);
105
- Object.assign(node, newNode);
106
- }
107
- addNode(node);
108
- }
109
- });
110
- return nodes;
111
- };
112
- const pair = (token)=>{
113
- const pairedAtNodes = [];
114
- const paired = parsePair(token);
115
- if (paired) {
116
- if (paired.pre) {
117
- pairedAtNodes.push(...pair(paired.pre));
118
- }
119
- if (paired.body) {
120
- if (id === 'supports') {
121
- pairedAtNodes.push({
122
- type: 'group',
123
- children: [
124
- {
125
- type: 'string',
126
- value: replaceCharOutsideQuotes(paired.body, '|', ' ')
127
- }
128
- ]
129
- });
130
- } else {
131
- const children = pair(paired.body);
132
- if (children.length > 1) {
133
- pairedAtNodes.push({
134
- type: 'group',
135
- children: pair(paired.body)
136
- });
137
- } else {
138
- pairedAtNodes.push(...children);
139
- }
140
- }
141
- }
142
- if (paired.post) {
143
- pairedAtNodes.push(...pair(paired.post));
144
- }
145
- } else {
146
- pairedAtNodes.push(...resolve(token));
147
- }
148
- return pairedAtNodes;
149
- };
150
- return {
151
- nodes: pair(token),
152
- id: id || 'media' // should be assigned to here
153
- };
154
- }
155
-
156
- module.exports = parseAt;
@@ -1,39 +0,0 @@
1
- import type MasterCSS from '../core';
2
- import { AtIdentifier } from '../types/config';
3
- export type AtRule = {
4
- id: AtIdentifier;
5
- nodes: AtRuleNode[];
6
- };
7
- export declare type AtRuleNumberNode = {
8
- raw?: string;
9
- name: string;
10
- type: 'number';
11
- value: number;
12
- unit?: string;
13
- operator?: string;
14
- };
15
- export declare type AtRuleStringNode = {
16
- raw?: string;
17
- name: string;
18
- type: 'string';
19
- value: string;
20
- };
21
- export declare type AtRuleValueNode = AtRuleNumberNode | AtRuleStringNode;
22
- export interface AtRuleComparisonOperatorNode {
23
- type: 'comparison';
24
- raw?: string;
25
- value: string;
26
- }
27
- export interface AtRuleLogicalOperatorNode {
28
- type: 'logical';
29
- raw?: string;
30
- value: string;
31
- }
32
- export type AtRuleOperatorNode = AtRuleComparisonOperatorNode | AtRuleLogicalOperatorNode;
33
- export interface AtRuleGroupNode {
34
- type?: 'group';
35
- raw?: string;
36
- children: AtRuleNode[];
37
- }
38
- export type AtRuleNode = AtRuleValueNode | AtRuleComparisonOperatorNode | AtRuleLogicalOperatorNode | AtRuleGroupNode;
39
- export default function parseAt(token: string, css: MasterCSS, isRaw?: boolean): AtRule;
@@ -1,154 +0,0 @@
1
- import { AT_COMPARISON_OPERATORS, AT_LOGICAL_OPERATORS, AT_IDENTIFIERS, AT_COMPARABLE_FEATURES } from '../common.mjs';
2
- import parsePair from './parse-pair.mjs';
3
- import parseValue from './parse-value.mjs';
4
- import replaceCharOutsideQuotes from './replace-char-outside-quotes.mjs';
5
- import splitCharOutsideQuotes from './split-char-outside-quotes.mjs';
6
-
7
- function parseAt(token, css, isRaw = true) {
8
- let id;
9
- let firstToken;
10
- const resolve = (token)=>{
11
- const regex = /([a-zA-Z0-9-:%|]+|[&|!|,|>|<|=][=]?)/g;
12
- const raws = [
13
- ...token.matchAll(regex)
14
- ].map((match)=>match[0]);
15
- let nodes = [];
16
- const addNode = (node)=>{
17
- let prev = nodes[nodes.length - 1];
18
- if (node.type === 'number' && !node.name) {
19
- if (prev?.type === 'comparison') {
20
- node.operator = prev.value;
21
- if (node.raw && prev.raw) {
22
- node.raw = prev.raw + node.raw;
23
- }
24
- nodes.pop();
25
- prev = nodes[nodes.length - 1];
26
- if (prev?.type === 'string') {
27
- node.name = prev.value;
28
- if (node.raw && prev.raw) {
29
- node.raw = prev.raw + node.raw;
30
- }
31
- nodes.pop();
32
- } else {
33
- node.name = 'width';
34
- }
35
- } else {
36
- node.name = 'width';
37
- node.operator = '>=';
38
- }
39
- }
40
- nodes.push(node);
41
- };
42
- raws.forEach((raw)=>{
43
- if (AT_COMPARISON_OPERATORS.includes(raw)) {
44
- const newNode = {
45
- type: 'comparison',
46
- value: raw
47
- };
48
- if (isRaw) newNode.raw = raw;
49
- nodes.push(newNode);
50
- return;
51
- } else if (raw in AT_LOGICAL_OPERATORS) {
52
- const newNode = {
53
- type: 'logical',
54
- value: AT_LOGICAL_OPERATORS[raw]
55
- };
56
- if (isRaw) newNode.raw = raw;
57
- nodes.push(newNode);
58
- return;
59
- }
60
- const definedAtRule = css.atRules.get(raw);
61
- if (!id && !firstToken) {
62
- firstToken = raw;
63
- if (AT_IDENTIFIERS.includes(firstToken)) {
64
- id = firstToken;
65
- return;
66
- } else if (definedAtRule) {
67
- id = definedAtRule.id;
68
- } else if (AT_COMPARABLE_FEATURES.includes(firstToken)) {
69
- id = 'media';
70
- } else if (firstToken.charAt(0).match(/[a-zA-Z-]/)) {
71
- id = 'container';
72
- } else {
73
- id = 'media';
74
- }
75
- }
76
- let node = {
77
- type: 'string'
78
- };
79
- if (isRaw) node.raw = raw;
80
- if (definedAtRule) {
81
- if (definedAtRule.nodes.length === 1) {
82
- addNode({
83
- ...definedAtRule.nodes[0],
84
- raw
85
- });
86
- } else if (definedAtRule.nodes.length) {
87
- addNode({
88
- raw,
89
- children: definedAtRule.nodes
90
- });
91
- }
92
- return;
93
- } else {
94
- const [splitedNameOrValue, splitedValue] = splitCharOutsideQuotes(raw, ':');
95
- if (splitedValue) {
96
- node.name = splitedNameOrValue;
97
- node.value = splitedValue;
98
- } else {
99
- node.value = splitedNameOrValue;
100
- }
101
- if (id === 'container' || id === 'media') {
102
- const { token, ...newNode } = parseValue(node.value, 'rem', css.config.rootSize);
103
- Object.assign(node, newNode);
104
- }
105
- addNode(node);
106
- }
107
- });
108
- return nodes;
109
- };
110
- const pair = (token)=>{
111
- const pairedAtNodes = [];
112
- const paired = parsePair(token);
113
- if (paired) {
114
- if (paired.pre) {
115
- pairedAtNodes.push(...pair(paired.pre));
116
- }
117
- if (paired.body) {
118
- if (id === 'supports') {
119
- pairedAtNodes.push({
120
- type: 'group',
121
- children: [
122
- {
123
- type: 'string',
124
- value: replaceCharOutsideQuotes(paired.body, '|', ' ')
125
- }
126
- ]
127
- });
128
- } else {
129
- const children = pair(paired.body);
130
- if (children.length > 1) {
131
- pairedAtNodes.push({
132
- type: 'group',
133
- children: pair(paired.body)
134
- });
135
- } else {
136
- pairedAtNodes.push(...children);
137
- }
138
- }
139
- }
140
- if (paired.post) {
141
- pairedAtNodes.push(...pair(paired.post));
142
- }
143
- } else {
144
- pairedAtNodes.push(...resolve(token));
145
- }
146
- return pairedAtNodes;
147
- };
148
- return {
149
- nodes: pair(token),
150
- id: id || 'media' // should be assigned to here
151
- };
152
- }
153
-
154
- export { parseAt as default };
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- function parsePair(str, a = '(', b = ')') {
4
- const stack = [];
5
- let result = null;
6
- let inString = null;
7
- for(let i = 0; i < str.length; i++){
8
- const char = str[i];
9
- const prevChar = str[i - 1];
10
- // 處理 escape 字元,例如 \"
11
- if (char === '\\') {
12
- i++; // skip next character
13
- continue;
14
- }
15
- // 處理字串區段進入與離開
16
- if ((char === '"' || char === '\'') && prevChar !== '\\') {
17
- if (inString === char) {
18
- inString = null; // 離開字串
19
- } else if (!inString) {
20
- inString = char; // 進入字串
21
- }
22
- continue;
23
- }
24
- if (inString) continue; // 若在字串中就忽略括號處理
25
- // 開始符號
26
- if (str.startsWith(a, i)) {
27
- stack.push({
28
- start: i
29
- });
30
- i += a.length - 1;
31
- } else if (str.startsWith(b, i)) {
32
- const last = stack.pop();
33
- if (last) {
34
- result = {
35
- start: last.start,
36
- end: i,
37
- pre: str.slice(stack.length > 0 ? stack[stack.length - 1].start + a.length : 0, last.start),
38
- body: str.slice(last.start + a.length, i),
39
- post: str.slice(i + b.length)
40
- };
41
- }
42
- i += b.length - 1;
43
- }
44
- }
45
- return result;
46
- }
47
-
48
- module.exports = parsePair;
@@ -1,8 +0,0 @@
1
- export interface ParsedPair {
2
- start: number;
3
- end: number;
4
- pre: string;
5
- body: string;
6
- post: string;
7
- }
8
- export default function parsePair(str: string, a?: string, b?: string): ParsedPair | null;
@@ -1,46 +0,0 @@
1
- function parsePair(str, a = '(', b = ')') {
2
- const stack = [];
3
- let result = null;
4
- let inString = null;
5
- for(let i = 0; i < str.length; i++){
6
- const char = str[i];
7
- const prevChar = str[i - 1];
8
- // 處理 escape 字元,例如 \"
9
- if (char === '\\') {
10
- i++; // skip next character
11
- continue;
12
- }
13
- // 處理字串區段進入與離開
14
- if ((char === '"' || char === '\'') && prevChar !== '\\') {
15
- if (inString === char) {
16
- inString = null; // 離開字串
17
- } else if (!inString) {
18
- inString = char; // 進入字串
19
- }
20
- continue;
21
- }
22
- if (inString) continue; // 若在字串中就忽略括號處理
23
- // 開始符號
24
- if (str.startsWith(a, i)) {
25
- stack.push({
26
- start: i
27
- });
28
- i += a.length - 1;
29
- } else if (str.startsWith(b, i)) {
30
- const last = stack.pop();
31
- if (last) {
32
- result = {
33
- start: last.start,
34
- end: i,
35
- pre: str.slice(stack.length > 0 ? stack[stack.length - 1].start + a.length : 0, last.start),
36
- body: str.slice(last.start + a.length, i),
37
- post: str.slice(i + b.length)
38
- };
39
- }
40
- i += b.length - 1;
41
- }
42
- }
43
- return result;
44
- }
45
-
46
- export { parsePair as default };