tailwindcss 0.0.0-insiders.7c337f2 → 0.0.0-insiders.7d8eb21

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 (161) hide show
  1. package/CHANGELOG.md +246 -6
  2. package/README.md +13 -9
  3. package/defaultTheme.d.ts +2 -1
  4. package/lib/cli/build/deps.js +54 -0
  5. package/lib/cli/build/index.js +48 -0
  6. package/lib/cli/build/plugin.js +362 -0
  7. package/lib/cli/build/utils.js +78 -0
  8. package/lib/cli/build/watching.js +178 -0
  9. package/lib/cli/help/index.js +71 -0
  10. package/lib/cli/index.js +18 -0
  11. package/lib/cli/init/index.js +46 -0
  12. package/lib/cli/shared.js +12 -0
  13. package/lib/cli-peer-dependencies.js +18 -5
  14. package/lib/cli.js +62 -592
  15. package/lib/constants.js +19 -12
  16. package/lib/corePluginList.js +5 -3
  17. package/lib/corePlugins.js +619 -347
  18. package/lib/css/preflight.css +7 -0
  19. package/lib/featureFlags.js +34 -22
  20. package/lib/index.js +16 -9
  21. package/lib/lib/cacheInvalidation.js +42 -21
  22. package/lib/lib/collapseAdjacentRules.js +16 -14
  23. package/lib/lib/collapseDuplicateDeclarations.js +13 -10
  24. package/lib/lib/content.js +177 -0
  25. package/lib/lib/defaultExtractor.js +230 -33
  26. package/lib/lib/detectNesting.js +13 -4
  27. package/lib/lib/evaluateTailwindFunctions.js +105 -42
  28. package/lib/lib/expandApplyAtRules.js +151 -92
  29. package/lib/lib/expandTailwindAtRules.js +134 -149
  30. package/lib/lib/findAtConfigPath.js +44 -0
  31. package/lib/lib/generateRules.js +404 -185
  32. package/lib/lib/getModuleDependencies.js +21 -18
  33. package/lib/lib/normalizeTailwindDirectives.js +11 -8
  34. package/lib/lib/offsets.js +285 -0
  35. package/lib/lib/partitionApplyAtRules.js +14 -11
  36. package/lib/lib/regex.js +60 -0
  37. package/lib/lib/remap-bitfield.js +87 -0
  38. package/lib/lib/resolveDefaultsAtRules.js +97 -79
  39. package/lib/lib/setupContextUtils.js +567 -242
  40. package/lib/lib/setupTrackingContext.js +77 -106
  41. package/lib/lib/sharedState.js +18 -10
  42. package/lib/lib/substituteScreenAtRules.js +9 -7
  43. package/lib/postcss-plugins/nesting/index.js +7 -5
  44. package/lib/postcss-plugins/nesting/plugin.js +10 -8
  45. package/lib/processTailwindFeatures.js +34 -31
  46. package/lib/public/colors.js +7 -5
  47. package/lib/public/create-plugin.js +6 -4
  48. package/lib/public/default-config.js +7 -5
  49. package/lib/public/default-theme.js +7 -5
  50. package/lib/public/resolve-config.js +13 -10
  51. package/lib/util/bigSign.js +4 -1
  52. package/lib/util/buildMediaQuery.js +10 -5
  53. package/lib/util/cloneDeep.js +6 -5
  54. package/lib/util/cloneNodes.js +9 -2
  55. package/lib/util/color.js +20 -17
  56. package/lib/util/configurePlugins.js +5 -2
  57. package/lib/util/createPlugin.js +6 -5
  58. package/lib/util/createUtilityPlugin.js +15 -13
  59. package/lib/util/dataTypes.js +75 -51
  60. package/lib/util/defaults.js +8 -5
  61. package/lib/util/escapeClassName.js +13 -10
  62. package/lib/util/escapeCommas.js +4 -1
  63. package/lib/util/flattenColorPalette.js +7 -8
  64. package/lib/util/formatVariantSelector.js +270 -103
  65. package/lib/util/getAllConfigs.js +34 -15
  66. package/lib/util/hashConfig.js +10 -7
  67. package/lib/util/isKeyframeRule.js +4 -1
  68. package/lib/util/isPlainObject.js +4 -1
  69. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +34 -26
  70. package/lib/util/log.js +14 -8
  71. package/lib/util/nameClass.js +19 -8
  72. package/lib/util/negateValue.js +20 -5
  73. package/lib/util/normalizeConfig.js +94 -53
  74. package/lib/util/normalizeScreens.js +115 -4
  75. package/lib/util/parseAnimationValue.js +43 -41
  76. package/lib/util/parseBoxShadowValue.js +12 -45
  77. package/lib/util/parseDependency.js +37 -55
  78. package/lib/util/parseGlob.js +34 -0
  79. package/lib/util/parseObjectStyles.js +15 -12
  80. package/lib/util/pluginUtils.js +146 -42
  81. package/lib/util/prefixSelector.js +26 -9
  82. package/lib/util/removeAlphaVariables.js +29 -0
  83. package/lib/util/resolveConfig.js +104 -105
  84. package/lib/util/resolveConfigPath.js +20 -17
  85. package/lib/util/responsive.js +12 -9
  86. package/lib/util/splitAtTopLevelOnly.js +43 -0
  87. package/lib/util/tap.js +4 -1
  88. package/lib/util/toColorValue.js +4 -1
  89. package/lib/util/toPath.js +18 -2
  90. package/lib/util/transformThemeValue.js +23 -11
  91. package/lib/util/validateConfig.js +24 -0
  92. package/lib/util/validateFormalSyntax.js +24 -0
  93. package/lib/util/withAlphaVariable.js +32 -24
  94. package/package.json +32 -29
  95. package/peers/index.js +6693 -3036
  96. package/plugin.d.ts +10 -5
  97. package/resolveConfig.d.ts +12 -0
  98. package/scripts/generate-types.js +53 -0
  99. package/scripts/release-channel.js +18 -0
  100. package/scripts/release-notes.js +21 -0
  101. package/scripts/type-utils.js +27 -0
  102. package/src/cli/build/deps.js +56 -0
  103. package/src/cli/build/index.js +49 -0
  104. package/src/cli/build/plugin.js +434 -0
  105. package/src/cli/build/utils.js +76 -0
  106. package/src/cli/build/watching.js +227 -0
  107. package/src/cli/help/index.js +70 -0
  108. package/src/cli/index.js +3 -0
  109. package/src/cli/init/index.js +50 -0
  110. package/src/cli/shared.js +5 -0
  111. package/src/cli-peer-dependencies.js +7 -1
  112. package/src/cli.js +46 -659
  113. package/src/corePlugins.js +346 -79
  114. package/src/css/preflight.css +7 -0
  115. package/src/featureFlags.js +12 -2
  116. package/src/index.js +5 -0
  117. package/src/lib/content.js +213 -0
  118. package/src/lib/defaultExtractor.js +202 -35
  119. package/src/lib/detectNesting.js +9 -1
  120. package/src/lib/evaluateTailwindFunctions.js +78 -7
  121. package/src/lib/expandApplyAtRules.js +129 -34
  122. package/src/lib/expandTailwindAtRules.js +12 -50
  123. package/src/lib/findAtConfigPath.js +48 -0
  124. package/src/lib/generateRules.js +379 -126
  125. package/src/lib/offsets.js +351 -0
  126. package/src/lib/regex.js +74 -0
  127. package/src/lib/remap-bitfield.js +82 -0
  128. package/src/lib/resolveDefaultsAtRules.js +53 -36
  129. package/src/lib/setupContextUtils.js +510 -120
  130. package/src/lib/setupTrackingContext.js +8 -45
  131. package/src/lib/sharedState.js +2 -0
  132. package/src/util/buildMediaQuery.js +5 -3
  133. package/src/util/cloneNodes.js +5 -1
  134. package/src/util/dataTypes.js +51 -26
  135. package/src/util/formatVariantSelector.js +317 -101
  136. package/src/util/getAllConfigs.js +19 -0
  137. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  138. package/src/util/log.js +1 -1
  139. package/src/util/nameClass.js +4 -0
  140. package/src/util/negateValue.js +10 -2
  141. package/src/util/normalizeConfig.js +40 -10
  142. package/src/util/normalizeScreens.js +99 -4
  143. package/src/util/parseBoxShadowValue.js +3 -50
  144. package/src/util/parseDependency.js +37 -42
  145. package/src/util/parseGlob.js +24 -0
  146. package/src/util/pluginUtils.js +132 -10
  147. package/src/util/prefixSelector.js +28 -10
  148. package/src/util/removeAlphaVariables.js +24 -0
  149. package/src/util/resolveConfig.js +70 -62
  150. package/src/util/splitAtTopLevelOnly.js +45 -0
  151. package/src/util/toPath.js +1 -1
  152. package/src/util/transformThemeValue.js +13 -3
  153. package/src/util/validateConfig.js +13 -0
  154. package/src/util/validateFormalSyntax.js +34 -0
  155. package/src/util/withAlphaVariable.js +1 -1
  156. package/stubs/defaultConfig.stub.js +165 -164
  157. package/stubs/simpleConfig.stub.js +1 -0
  158. package/types/config.d.ts +77 -37
  159. package/types/generated/default-theme.d.ts +342 -0
  160. package/types/index.d.ts +7 -1
  161. package/types.d.ts +0 -1
@@ -2,11 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- exports.default = getModuleDependencies;
6
- var _fs = _interopRequireDefault(require("fs"));
7
- var _path = _interopRequireDefault(require("path"));
8
- var _resolve = _interopRequireDefault(require("resolve"));
9
- var _detective = _interopRequireDefault(require("detective"));
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>getModuleDependencies
8
+ });
9
+ const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
10
+ const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
11
+ const _resolve = /*#__PURE__*/ _interopRequireDefault(require("resolve"));
12
+ const _detective = /*#__PURE__*/ _interopRequireDefault(require("detective"));
13
+ function _interopRequireDefault(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ function createModule(file) {
19
+ const source = _fs.default.readFileSync(file, "utf-8");
20
+ const requires = (0, _detective.default)(source);
21
+ return {
22
+ file,
23
+ requires
24
+ };
25
+ }
10
26
  function getModuleDependencies(entryFile) {
11
27
  const rootModule = createModule(entryFile);
12
28
  const modules = [
@@ -33,16 +49,3 @@ function getModuleDependencies(entryFile) {
33
49
  }
34
50
  return modules;
35
51
  }
36
- function _interopRequireDefault(obj) {
37
- return obj && obj.__esModule ? obj : {
38
- default: obj
39
- };
40
- }
41
- function createModule(file) {
42
- const source = _fs.default.readFileSync(file, "utf-8");
43
- const requires = (0, _detective).default(source);
44
- return {
45
- file,
46
- requires
47
- };
48
- }
@@ -2,8 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- exports.default = normalizeTailwindDirectives;
6
- var _log = _interopRequireDefault(require("../util/log"));
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>normalizeTailwindDirectives
8
+ });
9
+ const _log = /*#__PURE__*/ _interopRequireDefault(require("../util/log"));
10
+ function _interopRequireDefault(obj) {
11
+ return obj && obj.__esModule ? obj : {
12
+ default: obj
13
+ };
14
+ }
7
15
  function normalizeTailwindDirectives(root) {
8
16
  let tailwindDirectives = new Set();
9
17
  let layerDirectives = new Set();
@@ -45,7 +53,7 @@ function normalizeTailwindDirectives(root) {
45
53
  _log.default.warn(`${atRule.name}-at-rule-deprecated`, [
46
54
  `The \`@${atRule.name}\` directive has been deprecated in Tailwind CSS v3.0.`,
47
55
  `Use \`@layer utilities\` or \`@layer components\` instead.`,
48
- "https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer",
56
+ "https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer"
49
57
  ]);
50
58
  }
51
59
  layerDirectives.add(atRule);
@@ -77,8 +85,3 @@ function normalizeTailwindDirectives(root) {
77
85
  applyDirectives
78
86
  };
79
87
  }
80
- function _interopRequireDefault(obj) {
81
- return obj && obj.__esModule ? obj : {
82
- default: obj
83
- };
84
- }
@@ -0,0 +1,285 @@
1
+ // @ts-check
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Offsets", {
7
+ enumerable: true,
8
+ get: ()=>Offsets
9
+ });
10
+ const _bigSign = /*#__PURE__*/ _interopRequireDefault(require("../util/bigSign"));
11
+ const _remapBitfieldJs = require("./remap-bitfield.js");
12
+ function _interopRequireDefault(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ class Offsets {
18
+ constructor(){
19
+ /**
20
+ * Offsets for the next rule in a given layer
21
+ *
22
+ * @type {Record<Layer, bigint>}
23
+ */ this.offsets = {
24
+ defaults: 0n,
25
+ base: 0n,
26
+ components: 0n,
27
+ utilities: 0n,
28
+ variants: 0n,
29
+ user: 0n
30
+ };
31
+ /**
32
+ * Positions for a given layer
33
+ *
34
+ * @type {Record<Layer, bigint>}
35
+ */ this.layerPositions = {
36
+ defaults: 0n,
37
+ base: 1n,
38
+ components: 2n,
39
+ utilities: 3n,
40
+ // There isn't technically a "user" layer, but we need to give it a position
41
+ // Because it's used for ordering user-css from @apply
42
+ user: 4n,
43
+ variants: 5n
44
+ };
45
+ /**
46
+ * The total number of functions currently registered across all variants (including arbitrary variants)
47
+ *
48
+ * @type {bigint}
49
+ */ this.reservedVariantBits = 0n;
50
+ /**
51
+ * Positions for a given variant
52
+ *
53
+ * @type {Map<string, bigint>}
54
+ */ this.variantOffsets = new Map();
55
+ }
56
+ /**
57
+ * @param {Layer} layer
58
+ * @returns {RuleOffset}
59
+ */ create(layer) {
60
+ return {
61
+ layer,
62
+ parentLayer: layer,
63
+ arbitrary: 0n,
64
+ variants: 0n,
65
+ parallelIndex: 0n,
66
+ index: this.offsets[layer]++,
67
+ options: []
68
+ };
69
+ }
70
+ /**
71
+ * @returns {RuleOffset}
72
+ */ arbitraryProperty() {
73
+ return {
74
+ ...this.create("utilities"),
75
+ arbitrary: 1n
76
+ };
77
+ }
78
+ /**
79
+ * Get the offset for a variant
80
+ *
81
+ * @param {string} variant
82
+ * @param {number} index
83
+ * @returns {RuleOffset}
84
+ */ forVariant(variant, index = 0) {
85
+ let offset = this.variantOffsets.get(variant);
86
+ if (offset === undefined) {
87
+ throw new Error(`Cannot find offset for unknown variant ${variant}`);
88
+ }
89
+ return {
90
+ ...this.create("variants"),
91
+ variants: offset << BigInt(index)
92
+ };
93
+ }
94
+ /**
95
+ * @param {RuleOffset} rule
96
+ * @param {RuleOffset} variant
97
+ * @param {VariantOption} options
98
+ * @returns {RuleOffset}
99
+ */ applyVariantOffset(rule, variant, options) {
100
+ return {
101
+ ...rule,
102
+ layer: "variants",
103
+ parentLayer: rule.layer === "variants" ? rule.parentLayer : rule.layer,
104
+ variants: rule.variants | variant.variants,
105
+ options: options.sort ? [].concat(options, rule.options) : rule.options,
106
+ // TODO: Technically this is wrong. We should be handling parallel index on a per variant basis.
107
+ // We'll take the max of all the parallel indexes for now.
108
+ // @ts-ignore
109
+ parallelIndex: max([
110
+ rule.parallelIndex,
111
+ variant.parallelIndex
112
+ ])
113
+ };
114
+ }
115
+ /**
116
+ * @param {RuleOffset} offset
117
+ * @param {number} parallelIndex
118
+ * @returns {RuleOffset}
119
+ */ applyParallelOffset(offset, parallelIndex) {
120
+ return {
121
+ ...offset,
122
+ parallelIndex: BigInt(parallelIndex)
123
+ };
124
+ }
125
+ /**
126
+ * Each variant gets 1 bit per function / rule registered.
127
+ * This is because multiple variants can be applied to a single rule and we need to know which ones are present and which ones are not.
128
+ * Additionally, every unique group of variants is grouped together in the stylesheet.
129
+ *
130
+ * This grouping is order-independent. For instance, we do not differentiate between `hover:focus` and `focus:hover`.
131
+ *
132
+ * @param {string[]} variants
133
+ * @param {(name: string) => number} getLength
134
+ */ recordVariants(variants, getLength) {
135
+ for (let variant of variants){
136
+ this.recordVariant(variant, getLength(variant));
137
+ }
138
+ }
139
+ /**
140
+ * The same as `recordVariants` but for a single arbitrary variant at runtime.
141
+ * @param {string} variant
142
+ * @param {number} fnCount
143
+ *
144
+ * @returns {RuleOffset} The highest offset for this variant
145
+ */ recordVariant(variant, fnCount = 1) {
146
+ this.variantOffsets.set(variant, 1n << this.reservedVariantBits);
147
+ // Ensure space is reserved for each "function" in the parallel variant
148
+ // by offsetting the next variant by the number of parallel variants
149
+ // in the one we just added.
150
+ // Single functions that return parallel variants are NOT handled separately here
151
+ // They're offset by 1 (or the number of functions) as usual
152
+ // And each rule returned is tracked separately since the functions are evaluated lazily.
153
+ // @see `RuleOffset.parallelIndex`
154
+ this.reservedVariantBits += BigInt(fnCount);
155
+ return {
156
+ ...this.create("variants"),
157
+ variants: this.variantOffsets.get(variant)
158
+ };
159
+ }
160
+ /**
161
+ * @param {RuleOffset} a
162
+ * @param {RuleOffset} b
163
+ * @returns {bigint}
164
+ */ compare(a, b) {
165
+ // Sort layers together
166
+ if (a.layer !== b.layer) {
167
+ return this.layerPositions[a.layer] - this.layerPositions[b.layer];
168
+ }
169
+ // Sort based on the sorting function
170
+ for (let aOptions of a.options){
171
+ for (let bOptions of b.options){
172
+ if (aOptions.id !== bOptions.id) continue;
173
+ if (!aOptions.sort || !bOptions.sort) continue;
174
+ let result = aOptions.sort({
175
+ value: aOptions.value,
176
+ modifier: aOptions.modifier
177
+ }, {
178
+ value: bOptions.value,
179
+ modifier: bOptions.modifier
180
+ });
181
+ if (result !== 0) return result;
182
+ }
183
+ }
184
+ // Sort variants in the order they were registered
185
+ if (a.variants !== b.variants) {
186
+ return a.variants - b.variants;
187
+ }
188
+ // Make sure each rule returned by a parallel variant is sorted in ascending order
189
+ if (a.parallelIndex !== b.parallelIndex) {
190
+ return a.parallelIndex - b.parallelIndex;
191
+ }
192
+ // Always sort arbitrary properties after other utilities
193
+ if (a.arbitrary !== b.arbitrary) {
194
+ return a.arbitrary - b.arbitrary;
195
+ }
196
+ // Sort utilities, components, etc… in the order they were registered
197
+ return a.index - b.index;
198
+ }
199
+ /**
200
+ * Arbitrary variants are recorded in the order they're encountered.
201
+ * This means that the order is not stable between environments and sets of content files.
202
+ *
203
+ * In order to make the order stable, we need to remap the arbitrary variant offsets to
204
+ * be in alphabetical order starting from the offset of the first arbitrary variant.
205
+ */ recalculateVariantOffsets() {
206
+ // Sort the variants by their name
207
+ let variants = Array.from(this.variantOffsets.entries()).filter(([v])=>v.startsWith("[")).sort(([a], [z])=>fastCompare(a, z));
208
+ // Sort the list of offsets
209
+ // This is not necessarily a discrete range of numbers which is why
210
+ // we're using sort instead of creating a range from min/max
211
+ let newOffsets = variants.map(([, offset])=>offset).sort((a, z)=>(0, _bigSign.default)(a - z));
212
+ // Create a map from the old offsets to the new offsets in the new sort order
213
+ /** @type {[bigint, bigint][]} */ let mapping = variants.map(([, oldOffset], i)=>[
214
+ oldOffset,
215
+ newOffsets[i]
216
+ ]);
217
+ // Remove any variants that will not move letting us skip
218
+ // remapping if everything happens to be in order
219
+ return mapping.filter(([a, z])=>a !== z);
220
+ }
221
+ /**
222
+ * @template T
223
+ * @param {[RuleOffset, T][]} list
224
+ * @returns {[RuleOffset, T][]}
225
+ */ remapArbitraryVariantOffsets(list) {
226
+ let mapping = this.recalculateVariantOffsets();
227
+ // No arbitrary variants? Nothing to do.
228
+ // Everyhing already in order? Nothing to do.
229
+ if (mapping.length === 0) {
230
+ return list;
231
+ }
232
+ // Remap every variant offset in the list
233
+ return list.map((item)=>{
234
+ let [offset, rule] = item;
235
+ offset = {
236
+ ...offset,
237
+ variants: (0, _remapBitfieldJs.remapBitfield)(offset.variants, mapping)
238
+ };
239
+ return [
240
+ offset,
241
+ rule
242
+ ];
243
+ });
244
+ }
245
+ /**
246
+ * @template T
247
+ * @param {[RuleOffset, T][]} list
248
+ * @returns {[RuleOffset, T][]}
249
+ */ sort(list) {
250
+ list = this.remapArbitraryVariantOffsets(list);
251
+ return list.sort(([a], [b])=>(0, _bigSign.default)(this.compare(a, b)));
252
+ }
253
+ }
254
+ /**
255
+ *
256
+ * @param {bigint[]} nums
257
+ * @returns {bigint|null}
258
+ */ function max(nums) {
259
+ let max = null;
260
+ for (const num of nums){
261
+ max = max !== null && max !== void 0 ? max : num;
262
+ max = max > num ? max : num;
263
+ }
264
+ return max;
265
+ }
266
+ /**
267
+ * A fast ASCII order string comparison function.
268
+ *
269
+ * Using `.sort()` without a custom compare function is faster
270
+ * But you can only use that if you're sorting an array of
271
+ * only strings. If you're sorting strings inside objects
272
+ * or arrays, you need must use a custom compare function.
273
+ *
274
+ * @param {string} a
275
+ * @param {string} b
276
+ */ function fastCompare(a, b) {
277
+ let aLen = a.length;
278
+ let bLen = b.length;
279
+ let minLen = aLen < bLen ? aLen : bLen;
280
+ for(let i = 0; i < minLen; i++){
281
+ let cmp = a.charCodeAt(i) - b.charCodeAt(i);
282
+ if (cmp !== 0) return cmp;
283
+ }
284
+ return aLen - bLen;
285
+ }
@@ -2,12 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- exports.default = expandApplyAtRules;
6
- function expandApplyAtRules() {
7
- return (root)=>{
8
- partitionRules(root);
9
- };
10
- }
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>expandApplyAtRules
8
+ });
11
9
  function partitionRules(root) {
12
10
  if (!root.walkAtRules) return;
13
11
  let applyParents = new Set();
@@ -17,10 +15,10 @@ function partitionRules(root) {
17
15
  if (applyParents.size === 0) {
18
16
  return;
19
17
  }
20
- for (let rule1 of applyParents){
18
+ for (let rule of applyParents){
21
19
  let nodeGroups = [];
22
20
  let lastGroup = [];
23
- for (let node of rule1.nodes){
21
+ for (let node of rule.nodes){
24
22
  if (node.type === "atrule" && node.name === "apply") {
25
23
  if (lastGroup.length > 0) {
26
24
  nodeGroups.push(lastGroup);
@@ -42,12 +40,17 @@ function partitionRules(root) {
42
40
  for (let group of [
43
41
  ...nodeGroups
44
42
  ].reverse()){
45
- let clone = rule1.clone({
43
+ let clone = rule.clone({
46
44
  nodes: []
47
45
  });
48
46
  clone.append(group);
49
- rule1.after(clone);
47
+ rule.after(clone);
50
48
  }
51
- rule1.remove();
49
+ rule.remove();
52
50
  }
53
51
  }
52
+ function expandApplyAtRules() {
53
+ return (root)=>{
54
+ partitionRules(root);
55
+ };
56
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ pattern: ()=>pattern,
13
+ withoutCapturing: ()=>withoutCapturing,
14
+ any: ()=>any,
15
+ optional: ()=>optional,
16
+ zeroOrMore: ()=>zeroOrMore,
17
+ nestedBrackets: ()=>nestedBrackets,
18
+ escape: ()=>escape
19
+ });
20
+ const REGEX_SPECIAL = /[\\^$.*+?()[\]{}|]/g;
21
+ const REGEX_HAS_SPECIAL = RegExp(REGEX_SPECIAL.source);
22
+ /**
23
+ * @param {string|RegExp|Array<string|RegExp>} source
24
+ */ function toSource(source) {
25
+ source = Array.isArray(source) ? source : [
26
+ source
27
+ ];
28
+ source = source.map((item)=>item instanceof RegExp ? item.source : item);
29
+ return source.join("");
30
+ }
31
+ function pattern(source) {
32
+ return new RegExp(toSource(source), "g");
33
+ }
34
+ function withoutCapturing(source) {
35
+ return new RegExp(`(?:${toSource(source)})`, "g");
36
+ }
37
+ function any(sources) {
38
+ return `(?:${sources.map(toSource).join("|")})`;
39
+ }
40
+ function optional(source) {
41
+ return `(?:${toSource(source)})?`;
42
+ }
43
+ function zeroOrMore(source) {
44
+ return `(?:${toSource(source)})*`;
45
+ }
46
+ function nestedBrackets(open, close, depth = 1) {
47
+ return withoutCapturing([
48
+ escape(open),
49
+ /[^\s]*/,
50
+ depth === 1 ? `[^${escape(open)}${escape(close)}\s]*` : any([
51
+ `[^${escape(open)}${escape(close)}\s]*`,
52
+ nestedBrackets(open, close, depth - 1)
53
+ ]),
54
+ /[^\s]*/,
55
+ escape(close)
56
+ ]);
57
+ }
58
+ function escape(string) {
59
+ return string && REGEX_HAS_SPECIAL.test(string) ? string.replace(REGEX_SPECIAL, "\\$&") : string || "";
60
+ }
@@ -0,0 +1,87 @@
1
+ // @ts-check
2
+ /**
3
+ * We must remap all the old bits to new bits for each set variant
4
+ * Only arbitrary variants are considered as those are the only
5
+ * ones that need to be re-sorted at this time
6
+ *
7
+ * An iterated process that removes and sets individual bits simultaneously
8
+ * will not work because we may have a new bit that is also a later old bit
9
+ * This means that we would be removing a previously set bit which we don't
10
+ * want to do
11
+ *
12
+ * For example (assume `bN` = `1<<N`)
13
+ * Given the "total" mapping `[[b1, b3], [b2, b4], [b3, b1], [b4, b2]]`
14
+ * The mapping is "total" because:
15
+ * 1. Every input and output is accounted for
16
+ * 2. All combinations are unique
17
+ * 3. No one input maps to multiple outputs and vice versa
18
+ * And, given an offset with all bits set:
19
+ * V = b1 | b2 | b3 | b4
20
+ *
21
+ * Let's explore the issue with removing and setting bits simultaneously:
22
+ * V & ~b1 | b3 = b2 | b3 | b4
23
+ * V & ~b2 | b4 = b3 | b4
24
+ * V & ~b3 | b1 = b1 | b4
25
+ * V & ~b4 | b2 = b1 | b2
26
+ *
27
+ * As you can see, we end up with the wrong result.
28
+ * This is because we're removing a bit that was previously set.
29
+ * And, thus the final result is missing b3 and b4.
30
+ *
31
+ * Now, let's explore the issue with removing the bits first:
32
+ * V & ~b1 = b2 | b3 | b4
33
+ * V & ~b2 = b3 | b4
34
+ * V & ~b3 = b4
35
+ * V & ~b4 = 0
36
+ *
37
+ * And then setting the bits:
38
+ * V | b3 = b3
39
+ * V | b4 = b3 | b4
40
+ * V | b1 = b1 | b3 | b4
41
+ * V | b2 = b1 | b2 | b3 | b4
42
+ *
43
+ * We get the correct result because we're not removing any bits that were
44
+ * previously set thus properly remapping the bits to the new order
45
+ *
46
+ * To collect this into a single operation that can be done simultaneously
47
+ * we must first create a mask for the old bits that are set and a mask for
48
+ * the new bits that are set. Then we can remove the old bits and set the new
49
+ * bits simultaneously in a "single" operation like so:
50
+ * OldMask = b1 | b2 | b3 | b4
51
+ * NewMask = b3 | b4 | b1 | b2
52
+ *
53
+ * So this:
54
+ * V & ~oldMask | newMask
55
+ *
56
+ * Expands to this:
57
+ * V & ~b1 & ~b2 & ~b3 & ~b4 | b3 | b4 | b1 | b2
58
+ *
59
+ * Which becomes this:
60
+ * b1 | b2 | b3 | b4
61
+ *
62
+ * Which is the correct result!
63
+ *
64
+ * @param {bigint} num
65
+ * @param {[bigint, bigint][]} mapping
66
+ */ "use strict";
67
+ Object.defineProperty(exports, "__esModule", {
68
+ value: true
69
+ });
70
+ Object.defineProperty(exports, "remapBitfield", {
71
+ enumerable: true,
72
+ get: ()=>remapBitfield
73
+ });
74
+ function remapBitfield(num, mapping) {
75
+ // Create masks for the old and new bits that are set
76
+ let oldMask = 0n;
77
+ let newMask = 0n;
78
+ for (let [oldBit, newBit] of mapping){
79
+ if (num & oldBit) {
80
+ oldMask = oldMask | oldBit;
81
+ newMask = newMask | newBit;
82
+ }
83
+ }
84
+ // Remove all old bits
85
+ // Set all new bits
86
+ return num & ~oldMask | newMask;
87
+ }