tailwindcss 3.1.8 → 3.2.1

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 (101) hide show
  1. package/CHANGELOG.md +64 -3
  2. package/README.md +6 -5
  3. package/lib/cli/build/deps.js +54 -0
  4. package/lib/cli/build/index.js +44 -0
  5. package/lib/cli/build/plugin.js +351 -0
  6. package/lib/cli/build/utils.js +78 -0
  7. package/lib/cli/build/watching.js +113 -0
  8. package/lib/cli/help/index.js +71 -0
  9. package/lib/cli/index.js +18 -0
  10. package/lib/cli/init/index.js +46 -0
  11. package/lib/cli/shared.js +12 -0
  12. package/lib/cli.js +11 -590
  13. package/lib/corePlugins.js +332 -108
  14. package/lib/css/preflight.css +5 -0
  15. package/lib/featureFlags.js +7 -4
  16. package/lib/index.js +6 -1
  17. package/lib/lib/content.js +167 -0
  18. package/lib/lib/defaultExtractor.js +15 -10
  19. package/lib/lib/detectNesting.js +2 -2
  20. package/lib/lib/evaluateTailwindFunctions.js +17 -1
  21. package/lib/lib/expandApplyAtRules.js +66 -37
  22. package/lib/lib/expandTailwindAtRules.js +10 -42
  23. package/lib/lib/findAtConfigPath.js +44 -0
  24. package/lib/lib/generateRules.js +180 -93
  25. package/lib/lib/normalizeTailwindDirectives.js +1 -1
  26. package/lib/lib/offsets.js +217 -0
  27. package/lib/lib/regex.js +1 -1
  28. package/lib/lib/setupContextUtils.js +339 -100
  29. package/lib/lib/setupTrackingContext.js +5 -39
  30. package/lib/lib/sharedState.js +2 -0
  31. package/lib/public/colors.js +1 -1
  32. package/lib/util/buildMediaQuery.js +6 -3
  33. package/lib/util/configurePlugins.js +1 -1
  34. package/lib/util/dataTypes.js +15 -19
  35. package/lib/util/formatVariantSelector.js +92 -8
  36. package/lib/util/getAllConfigs.js +14 -3
  37. package/lib/util/isValidArbitraryValue.js +1 -1
  38. package/lib/util/nameClass.js +3 -0
  39. package/lib/util/negateValue.js +15 -2
  40. package/lib/util/normalizeConfig.js +17 -3
  41. package/lib/util/normalizeScreens.js +100 -3
  42. package/lib/util/parseAnimationValue.js +1 -1
  43. package/lib/util/parseBoxShadowValue.js +1 -1
  44. package/lib/util/parseDependency.js +33 -54
  45. package/lib/util/parseGlob.js +34 -0
  46. package/lib/util/parseObjectStyles.js +1 -1
  47. package/lib/util/pluginUtils.js +87 -17
  48. package/lib/util/resolveConfig.js +2 -2
  49. package/lib/util/splitAtTopLevelOnly.js +31 -81
  50. package/lib/util/transformThemeValue.js +9 -2
  51. package/lib/util/validateConfig.js +1 -1
  52. package/lib/util/validateFormalSyntax.js +24 -0
  53. package/package.json +14 -13
  54. package/peers/index.js +3263 -1887
  55. package/plugin.d.ts +3 -3
  56. package/scripts/release-channel.js +18 -0
  57. package/scripts/release-notes.js +21 -0
  58. package/src/cli/build/deps.js +56 -0
  59. package/src/cli/build/index.js +45 -0
  60. package/src/cli/build/plugin.js +417 -0
  61. package/src/cli/build/utils.js +76 -0
  62. package/src/cli/build/watching.js +134 -0
  63. package/src/cli/help/index.js +70 -0
  64. package/src/cli/index.js +3 -0
  65. package/src/cli/init/index.js +50 -0
  66. package/src/cli/shared.js +5 -0
  67. package/src/cli.js +4 -696
  68. package/src/corePlugins.js +262 -39
  69. package/src/css/preflight.css +5 -0
  70. package/src/featureFlags.js +12 -2
  71. package/src/index.js +5 -0
  72. package/src/lib/content.js +205 -0
  73. package/src/lib/defaultExtractor.js +3 -0
  74. package/src/lib/evaluateTailwindFunctions.js +22 -1
  75. package/src/lib/expandApplyAtRules.js +70 -29
  76. package/src/lib/expandTailwindAtRules.js +8 -46
  77. package/src/lib/findAtConfigPath.js +48 -0
  78. package/src/lib/generateRules.js +223 -101
  79. package/src/lib/offsets.js +270 -0
  80. package/src/lib/setupContextUtils.js +376 -89
  81. package/src/lib/setupTrackingContext.js +4 -45
  82. package/src/lib/sharedState.js +2 -0
  83. package/src/util/buildMediaQuery.js +5 -3
  84. package/src/util/dataTypes.js +15 -17
  85. package/src/util/formatVariantSelector.js +113 -9
  86. package/src/util/getAllConfigs.js +14 -2
  87. package/src/util/nameClass.js +4 -0
  88. package/src/util/negateValue.js +10 -2
  89. package/src/util/normalizeConfig.js +22 -2
  90. package/src/util/normalizeScreens.js +99 -4
  91. package/src/util/parseBoxShadowValue.js +1 -1
  92. package/src/util/parseDependency.js +37 -42
  93. package/src/util/parseGlob.js +24 -0
  94. package/src/util/pluginUtils.js +96 -14
  95. package/src/util/resolveConfig.js +1 -1
  96. package/src/util/splitAtTopLevelOnly.js +23 -49
  97. package/src/util/transformThemeValue.js +9 -1
  98. package/src/util/validateFormalSyntax.js +34 -0
  99. package/stubs/defaultConfig.stub.js +20 -3
  100. package/types/config.d.ts +48 -13
  101. package/types/generated/default-theme.d.ts +11 -0
@@ -9,6 +9,7 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
+ getClassNameFromSelector: ()=>getClassNameFromSelector,
12
13
  resolveMatches: ()=>resolveMatches,
13
14
  generateRules: ()=>generateRules
14
15
  });
@@ -88,14 +89,22 @@ function* candidatePermutations(candidate) {
88
89
  let lastIndex = Infinity;
89
90
  while(lastIndex >= 0){
90
91
  let dashIdx;
92
+ let wasSlash = false;
91
93
  if (lastIndex === Infinity && candidate.endsWith("]")) {
92
94
  let bracketIdx = candidate.indexOf("[");
93
95
  // If character before `[` isn't a dash or a slash, this isn't a dynamic class
94
96
  // eg. string[]
95
- dashIdx = [
96
- "-",
97
- "/"
98
- ].includes(candidate[bracketIdx - 1]) ? bracketIdx - 1 : -1;
97
+ if (candidate[bracketIdx - 1] === "-") {
98
+ dashIdx = bracketIdx - 1;
99
+ } else if (candidate[bracketIdx - 1] === "/") {
100
+ dashIdx = bracketIdx - 1;
101
+ wasSlash = true;
102
+ } else {
103
+ dashIdx = -1;
104
+ }
105
+ } else if (lastIndex === Infinity && candidate.includes("/")) {
106
+ dashIdx = candidate.lastIndexOf("/");
107
+ wasSlash = true;
99
108
  } else {
100
109
  dashIdx = candidate.lastIndexOf("-", lastIndex);
101
110
  }
@@ -103,12 +112,16 @@ function* candidatePermutations(candidate) {
103
112
  break;
104
113
  }
105
114
  let prefix = candidate.slice(0, dashIdx);
106
- let modifier = candidate.slice(dashIdx + 1);
115
+ let modifier = candidate.slice(wasSlash ? dashIdx : dashIdx + 1);
116
+ lastIndex = dashIdx - 1;
117
+ // TODO: This feels a bit hacky
118
+ if (prefix === "" || modifier === "/") {
119
+ continue;
120
+ }
107
121
  yield [
108
122
  prefix,
109
123
  modifier
110
124
  ];
111
- lastIndex = dashIdx - 1;
112
125
  }
113
126
  }
114
127
  function applyPrefix(matches, context) {
@@ -179,11 +192,40 @@ function applyVariant(variant, matches, context) {
179
192
  if (matches.length === 0) {
180
193
  return matches;
181
194
  }
182
- let args;
183
- // Find partial arbitrary variants
195
+ /** @type {{modifier: string | null, value: string | null}} */ let args = {
196
+ modifier: null,
197
+ value: _sharedState.NONE
198
+ };
199
+ // Retrieve "modifier"
200
+ {
201
+ let match = /(.*)\/(.*)$/g.exec(variant);
202
+ if (match) {
203
+ variant = match[1];
204
+ args.modifier = match[2];
205
+ if (!(0, _featureFlags.flagEnabled)(context.tailwindConfig, "generalizedModifiers")) {
206
+ return [];
207
+ }
208
+ }
209
+ }
210
+ // Retrieve "arbitrary value"
184
211
  if (variant.endsWith("]") && !variant.startsWith("[")) {
185
- args = variant.slice(variant.lastIndexOf("[") + 1, -1);
186
- variant = variant.slice(0, variant.indexOf(args) - 1 /* - */ - 1 /* [ */ );
212
+ // We either have:
213
+ // @[200px]
214
+ // group-[:hover]
215
+ //
216
+ // But we don't want:
217
+ // @-[200px] (`-` is incorrect)
218
+ // group[:hover] (`-` is missing)
219
+ let match1 = /(.)(-?)\[(.*)\]/g.exec(variant);
220
+ if (match1) {
221
+ let [, char, seperator, value] = match1;
222
+ // @-[200px] case
223
+ if (char === "@" && seperator === "-") return [];
224
+ // group[:hover] case
225
+ if (char !== "@" && seperator === "") return [];
226
+ variant = variant.replace(`${seperator}[${value}]`, "");
227
+ args.value = value;
228
+ }
187
229
  }
188
230
  // Register arbitrary variants
189
231
  if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
@@ -192,14 +234,13 @@ function applyVariant(variant, matches, context) {
192
234
  return [];
193
235
  }
194
236
  let fn = (0, _setupContextUtils.parseVariant)(selector);
195
- let sort = Array.from(context.variantOrder.values()).pop() << 1n;
237
+ let sort = context.offsets.recordVariant(variant);
196
238
  context.variantMap.set(variant, [
197
239
  [
198
240
  sort,
199
241
  fn
200
242
  ]
201
243
  ]);
202
- context.variantOrder.set(variant, sort);
203
244
  }
204
245
  if (context.variantMap.has(variant)) {
205
246
  let variantFunctionTuples = context.variantMap.get(variant).slice();
@@ -271,15 +312,11 @@ function applyVariant(variant, matches, context) {
271
312
  // where you keep handling jobs until everything is done and each job can queue more
272
313
  // jobs if needed.
273
314
  variantFunctionTuples.push([
274
- // TODO: This could have potential bugs if we shift the sort order from variant A far
275
- // enough into the sort space of variant B. The chances are low, but if this happens
276
- // then this might be the place too look at. One potential solution to this problem is
277
- // reserving additional X places for these 'unknown' variants in between.
278
- variantSort | BigInt(idx << ruleWithVariant.length),
315
+ context.offsets.applyParallelOffset(variantSort, idx),
279
316
  variantFunction1,
280
317
  // If the clone has been modified we have to pass that back
281
318
  // though so each rule can use the modified container
282
- clone.clone(),
319
+ clone.clone()
283
320
  ]);
284
321
  }
285
322
  continue;
@@ -337,11 +374,11 @@ function applyVariant(variant, matches, context) {
337
374
  let withOffset = [
338
375
  {
339
376
  ...meta,
340
- sort: variantSort | meta.sort,
377
+ sort: context.offsets.applyVariantOffset(meta.sort, variantSort, Object.assign(args, context.variantOptions.get(variant))),
341
378
  collectedFormats: ((_collectedFormats = meta.collectedFormats) !== null && _collectedFormats !== void 0 ? _collectedFormats : []).concat(collectedFormats),
342
379
  isArbitraryVariant: isArbitraryValue(variant)
343
380
  },
344
- clone.nodes[0],
381
+ clone.nodes[0]
345
382
  ];
346
383
  result.push(withOffset);
347
384
  }
@@ -434,18 +471,19 @@ function extractArbitraryProperty(classCandidate, context) {
434
471
  if (!isParsableCssValue(property, normalized)) {
435
472
  return null;
436
473
  }
474
+ let sort = context.offsets.arbitraryProperty();
437
475
  return [
438
476
  [
439
477
  {
440
- sort: context.arbitraryPropertiesSort,
478
+ sort,
441
479
  layer: "utilities"
442
480
  },
443
481
  ()=>({
444
482
  [(0, _nameClass.asClass)(classCandidate)]: {
445
483
  [property]: normalized
446
484
  }
447
- }),
448
- ],
485
+ })
486
+ ]
449
487
  ];
450
488
  }
451
489
  function* resolveMatchedPlugins(classCandidate, context) {
@@ -493,7 +531,7 @@ function splitWithSeparator(input, separator) {
493
531
  _sharedState.NOT_ON_DEMAND
494
532
  ];
495
533
  }
496
- return Array.from((0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(input, separator));
534
+ return (0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(input, separator);
497
535
  }
498
536
  function* recordCandidates(matches, classCandidate) {
499
537
  for (const match of matches){
@@ -577,48 +615,91 @@ function* resolveMatches(candidate, context, original = candidate) {
577
615
  }
578
616
  if (matchesPerPlugin.length > 0) {
579
617
  var ref;
580
- typesByMatches.set(matchesPerPlugin, (ref = sort.options) === null || ref === void 0 ? void 0 : ref.type);
618
+ var ref1, _options;
619
+ let matchingTypes = Array.from((0, _pluginUtils.getMatchingTypes)((ref1 = (ref = sort.options) === null || ref === void 0 ? void 0 : ref.types) !== null && ref1 !== void 0 ? ref1 : [], modifier, (_options = sort.options) !== null && _options !== void 0 ? _options : {}, context.tailwindConfig)).map(([_, type])=>type);
620
+ if (matchingTypes.length > 0) {
621
+ typesByMatches.set(matchesPerPlugin, matchingTypes);
622
+ }
581
623
  matches.push(matchesPerPlugin);
582
624
  }
583
625
  }
584
626
  if (isArbitraryValue(modifier)) {
585
- // When generated arbitrary values are ambiguous, we can't know
586
- // which to pick so don't generate any utilities for them
587
627
  if (matches.length > 1) {
588
- var ref1;
589
- let typesPerPlugin = matches.map((match)=>new Set([
590
- ...(ref1 = typesByMatches.get(match)) !== null && ref1 !== void 0 ? ref1 : []
591
- ]));
592
- // Remove duplicates, so that we can detect proper unique types for each plugin.
593
- for (let pluginTypes of typesPerPlugin){
594
- for (let type of pluginTypes){
595
- let removeFromOwnGroup = false;
596
- for (let otherGroup of typesPerPlugin){
597
- if (pluginTypes === otherGroup) continue;
598
- if (otherGroup.has(type)) {
599
- otherGroup.delete(type);
600
- removeFromOwnGroup = true;
628
+ // Partition plugins in 2 categories so that we can start searching in the plugins that
629
+ // don't have `any` as a type first.
630
+ let [withAny, withoutAny] = matches.reduce((group, plugin)=>{
631
+ let hasAnyType = plugin.some(([{ options }])=>options.types.some(({ type })=>type === "any"));
632
+ if (hasAnyType) {
633
+ group[0].push(plugin);
634
+ } else {
635
+ group[1].push(plugin);
636
+ }
637
+ return group;
638
+ }, [
639
+ [],
640
+ []
641
+ ]);
642
+ function findFallback(matches) {
643
+ // If only a single plugin matches, let's take that one
644
+ if (matches.length === 1) {
645
+ return matches[0];
646
+ }
647
+ // Otherwise, find the plugin that creates a valid rule given the arbitrary value, and
648
+ // also has the correct type which preferOnConflicts the plugin in case of clashes.
649
+ return matches.find((rules)=>{
650
+ let matchingTypes = typesByMatches.get(rules);
651
+ return rules.some(([{ options }, rule])=>{
652
+ if (!isParsableNode(rule)) {
653
+ return false;
654
+ }
655
+ return options.types.some(({ type , preferOnConflict })=>matchingTypes.includes(type) && preferOnConflict);
656
+ });
657
+ });
658
+ }
659
+ var ref2;
660
+ // Try to find a fallback plugin, because we already know that multiple plugins matched for
661
+ // the given arbitrary value.
662
+ let fallback = (ref2 = findFallback(withoutAny)) !== null && ref2 !== void 0 ? ref2 : findFallback(withAny);
663
+ if (fallback) {
664
+ matches = [
665
+ fallback
666
+ ];
667
+ } else {
668
+ var ref3;
669
+ let typesPerPlugin = matches.map((match)=>new Set([
670
+ ...(ref3 = typesByMatches.get(match)) !== null && ref3 !== void 0 ? ref3 : []
671
+ ]));
672
+ // Remove duplicates, so that we can detect proper unique types for each plugin.
673
+ for (let pluginTypes of typesPerPlugin){
674
+ for (let type of pluginTypes){
675
+ let removeFromOwnGroup = false;
676
+ for (let otherGroup of typesPerPlugin){
677
+ if (pluginTypes === otherGroup) continue;
678
+ if (otherGroup.has(type)) {
679
+ otherGroup.delete(type);
680
+ removeFromOwnGroup = true;
681
+ }
601
682
  }
683
+ if (removeFromOwnGroup) pluginTypes.delete(type);
602
684
  }
603
- if (removeFromOwnGroup) pluginTypes.delete(type);
604
685
  }
605
- }
606
- let messages = [];
607
- for (let [idx, group] of typesPerPlugin.entries()){
608
- for (let type1 of group){
609
- let rules2 = matches[idx].map(([, rule])=>rule).flat().map((rule)=>rule.toString().split("\n").slice(1, -1) // Remove selector and closing '}'
610
- .map((line)=>line.trim()).map((x)=>` ${x}`) // Re-indent
611
- .join("\n")).join("\n\n");
612
- messages.push(` Use \`${candidate.replace("[", `[${type1}:`)}\` for \`${rules2.trim()}\``);
613
- break;
686
+ let messages = [];
687
+ for (let [idx, group] of typesPerPlugin.entries()){
688
+ for (let type1 of group){
689
+ let rules2 = matches[idx].map(([, rule])=>rule).flat().map((rule)=>rule.toString().split("\n").slice(1, -1) // Remove selector and closing '}'
690
+ .map((line)=>line.trim()).map((x)=>` ${x}`) // Re-indent
691
+ .join("\n")).join("\n\n");
692
+ messages.push(` Use \`${candidate.replace("[", `[${type1}:`)}\` for \`${rules2.trim()}\``);
693
+ break;
694
+ }
614
695
  }
696
+ _log.default.warn([
697
+ `The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
698
+ ...messages,
699
+ `If this is content and not a class, replace it with \`${candidate.replace("[", "&lsqb;").replace("]", "&rsqb;")}\` to silence this warning.`
700
+ ]);
701
+ continue;
615
702
  }
616
- _log.default.warn([
617
- `The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
618
- ...messages,
619
- `If this is content and not a class, replace it with \`${candidate.replace("[", "&lsqb;").replace("]", "&rsqb;")}\` to silence this warning.`,
620
- ]);
621
- continue;
622
703
  }
623
704
  matches = matches.map((list)=>list.filter((match)=>isParsableNode(match[1])));
624
705
  }
@@ -665,14 +746,39 @@ function* resolveMatches(candidate, context, original = candidate) {
665
746
  function inKeyframes(rule) {
666
747
  return rule.parent && rule.parent.type === "atrule" && rule.parent.name === "keyframes";
667
748
  }
749
+ function getImportantStrategy(important) {
750
+ if (important === true) {
751
+ return (rule)=>{
752
+ if (inKeyframes(rule)) {
753
+ return;
754
+ }
755
+ rule.walkDecls((d)=>{
756
+ if (d.parent.type === "rule" && !inKeyframes(d.parent)) {
757
+ d.important = true;
758
+ }
759
+ });
760
+ };
761
+ }
762
+ if (typeof important === "string") {
763
+ return (rule)=>{
764
+ if (inKeyframes(rule)) {
765
+ return;
766
+ }
767
+ rule.selectors = rule.selectors.map((selector)=>{
768
+ return `${important} ${selector}`;
769
+ });
770
+ };
771
+ }
772
+ }
668
773
  function generateRules(candidates, context) {
669
774
  let allRules = [];
775
+ let strategy = getImportantStrategy(context.tailwindConfig.important);
670
776
  for (let candidate of candidates){
671
777
  if (context.notClassCache.has(candidate)) {
672
778
  continue;
673
779
  }
674
- if (context.classCache.has(candidate)) {
675
- allRules.push(context.classCache.get(candidate));
780
+ if (context.candidateRuleCache.has(candidate)) {
781
+ allRules = allRules.concat(Array.from(context.candidateRuleCache.get(candidate)));
676
782
  continue;
677
783
  }
678
784
  let matches = Array.from(resolveMatches(candidate, context));
@@ -681,49 +787,30 @@ function generateRules(candidates, context) {
681
787
  continue;
682
788
  }
683
789
  context.classCache.set(candidate, matches);
684
- allRules.push(matches);
685
- }
686
- // Strategy based on `tailwindConfig.important`
687
- let strategy = ((important)=>{
688
- if (important === true) {
689
- return (rule)=>{
690
- rule.walkDecls((d)=>{
691
- if (d.parent.type === "rule" && !inKeyframes(d.parent)) {
692
- d.important = true;
693
- }
694
- });
695
- };
696
- }
697
- if (typeof important === "string") {
698
- return (rule)=>{
699
- rule.selectors = rule.selectors.map((selector)=>{
700
- return `${important} ${selector}`;
701
- });
702
- };
703
- }
704
- })(context.tailwindConfig.important);
705
- return allRules.flat(1).map(([{ sort , layer , options }, rule])=>{
706
- if (options.respectImportant) {
707
- if (strategy) {
790
+ var ref;
791
+ let rules = (ref = context.candidateRuleCache.get(candidate)) !== null && ref !== void 0 ? ref : new Set();
792
+ context.candidateRuleCache.set(candidate, rules);
793
+ for (const match of matches){
794
+ let [{ sort , options }, rule] = match;
795
+ if (options.respectImportant && strategy) {
708
796
  let container = _postcss.default.root({
709
797
  nodes: [
710
798
  rule.clone()
711
799
  ]
712
800
  });
713
- container.walkRules((r)=>{
714
- if (inKeyframes(r)) {
715
- return;
716
- }
717
- strategy(r);
718
- });
801
+ container.walkRules(strategy);
719
802
  rule = container.nodes[0];
720
803
  }
804
+ let newEntry = [
805
+ sort,
806
+ rule
807
+ ];
808
+ rules.add(newEntry);
809
+ context.ruleCache.add(newEntry);
810
+ allRules.push(newEntry);
721
811
  }
722
- return [
723
- sort | context.layerOrder[layer],
724
- rule
725
- ];
726
- });
812
+ }
813
+ return allRules;
727
814
  }
728
815
  function isArbitraryValue(input) {
729
816
  return input.startsWith("[") && input.endsWith("]");
@@ -53,7 +53,7 @@ function normalizeTailwindDirectives(root) {
53
53
  _log.default.warn(`${atRule.name}-at-rule-deprecated`, [
54
54
  `The \`@${atRule.name}\` directive has been deprecated in Tailwind CSS v3.0.`,
55
55
  `Use \`@layer utilities\` or \`@layer components\` instead.`,
56
- "https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer",
56
+ "https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer"
57
57
  ]);
58
58
  }
59
59
  layerDirectives.add(atRule);
@@ -0,0 +1,217 @@
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
+ function _interopRequireDefault(obj) {
12
+ return obj && obj.__esModule ? obj : {
13
+ default: obj
14
+ };
15
+ }
16
+ class Offsets {
17
+ constructor(){
18
+ /**
19
+ * Offsets for the next rule in a given layer
20
+ *
21
+ * @type {Record<Layer, bigint>}
22
+ */ this.offsets = {
23
+ defaults: 0n,
24
+ base: 0n,
25
+ components: 0n,
26
+ utilities: 0n,
27
+ variants: 0n,
28
+ user: 0n
29
+ };
30
+ /**
31
+ * Positions for a given layer
32
+ *
33
+ * @type {Record<Layer, bigint>}
34
+ */ this.layerPositions = {
35
+ defaults: 0n,
36
+ base: 1n,
37
+ components: 2n,
38
+ utilities: 3n,
39
+ // There isn't technically a "user" layer, but we need to give it a position
40
+ // Because it's used for ordering user-css from @apply
41
+ user: 4n,
42
+ variants: 5n
43
+ };
44
+ /**
45
+ * The total number of functions currently registered across all variants (including arbitrary variants)
46
+ *
47
+ * @type {bigint}
48
+ */ this.reservedVariantBits = 0n;
49
+ /**
50
+ * Positions for a given variant
51
+ *
52
+ * @type {Map<string, bigint>}
53
+ */ this.variantOffsets = new Map();
54
+ }
55
+ /**
56
+ * @param {Layer} layer
57
+ * @returns {RuleOffset}
58
+ */ create(layer) {
59
+ return {
60
+ layer,
61
+ parentLayer: layer,
62
+ arbitrary: 0n,
63
+ variants: 0n,
64
+ parallelIndex: 0n,
65
+ index: this.offsets[layer]++,
66
+ options: []
67
+ };
68
+ }
69
+ /**
70
+ * @returns {RuleOffset}
71
+ */ arbitraryProperty() {
72
+ return {
73
+ ...this.create("utilities"),
74
+ arbitrary: 1n
75
+ };
76
+ }
77
+ /**
78
+ * Get the offset for a variant
79
+ *
80
+ * @param {string} variant
81
+ * @param {number} index
82
+ * @returns {RuleOffset}
83
+ */ forVariant(variant, index = 0) {
84
+ let offset = this.variantOffsets.get(variant);
85
+ if (offset === undefined) {
86
+ throw new Error(`Cannot find offset for unknown variant ${variant}`);
87
+ }
88
+ return {
89
+ ...this.create("variants"),
90
+ variants: offset << BigInt(index)
91
+ };
92
+ }
93
+ /**
94
+ * @param {RuleOffset} rule
95
+ * @param {RuleOffset} variant
96
+ * @param {VariantOption} options
97
+ * @returns {RuleOffset}
98
+ */ applyVariantOffset(rule, variant, options) {
99
+ return {
100
+ ...rule,
101
+ layer: "variants",
102
+ parentLayer: rule.layer === "variants" ? rule.parentLayer : rule.layer,
103
+ variants: rule.variants | variant.variants,
104
+ options: options.sort ? [].concat(options, rule.options) : rule.options,
105
+ // TODO: Technically this is wrong. We should be handling parallel index on a per variant basis.
106
+ // We'll take the max of all the parallel indexes for now.
107
+ // @ts-ignore
108
+ parallelIndex: max([
109
+ rule.parallelIndex,
110
+ variant.parallelIndex
111
+ ])
112
+ };
113
+ }
114
+ /**
115
+ * @param {RuleOffset} offset
116
+ * @param {number} parallelIndex
117
+ * @returns {RuleOffset}
118
+ */ applyParallelOffset(offset, parallelIndex) {
119
+ return {
120
+ ...offset,
121
+ parallelIndex: BigInt(parallelIndex)
122
+ };
123
+ }
124
+ /**
125
+ * Each variant gets 1 bit per function / rule registered.
126
+ * 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.
127
+ * Additionally, every unique group of variants is grouped together in the stylesheet.
128
+ *
129
+ * This grouping is order-independent. For instance, we do not differentiate between `hover:focus` and `focus:hover`.
130
+ *
131
+ * @param {string[]} variants
132
+ * @param {(name: string) => number} getLength
133
+ */ recordVariants(variants, getLength) {
134
+ for (let variant of variants){
135
+ this.recordVariant(variant, getLength(variant));
136
+ }
137
+ }
138
+ /**
139
+ * The same as `recordVariants` but for a single arbitrary variant at runtime.
140
+ * @param {string} variant
141
+ * @param {number} fnCount
142
+ *
143
+ * @returns {RuleOffset} The highest offset for this variant
144
+ */ recordVariant(variant, fnCount = 1) {
145
+ this.variantOffsets.set(variant, 1n << this.reservedVariantBits);
146
+ // Ensure space is reserved for each "function" in the parallel variant
147
+ // by offsetting the next variant by the number of parallel variants
148
+ // in the one we just added.
149
+ // Single functions that return parallel variants are NOT handled separately here
150
+ // They're offset by 1 (or the number of functions) as usual
151
+ // And each rule returned is tracked separately since the functions are evaluated lazily.
152
+ // @see `RuleOffset.parallelIndex`
153
+ this.reservedVariantBits += BigInt(fnCount);
154
+ return {
155
+ ...this.create("variants"),
156
+ variants: 1n << this.reservedVariantBits
157
+ };
158
+ }
159
+ /**
160
+ * @param {RuleOffset} a
161
+ * @param {RuleOffset} b
162
+ * @returns {bigint}
163
+ */ compare(a, b) {
164
+ // Sort layers together
165
+ if (a.layer !== b.layer) {
166
+ return this.layerPositions[a.layer] - this.layerPositions[b.layer];
167
+ }
168
+ // Sort based on the sorting function
169
+ for (let aOptions of a.options){
170
+ for (let bOptions of b.options){
171
+ if (aOptions.id !== bOptions.id) continue;
172
+ if (!aOptions.sort || !bOptions.sort) continue;
173
+ let result = aOptions.sort({
174
+ value: aOptions.value,
175
+ modifier: aOptions.modifier
176
+ }, {
177
+ value: bOptions.value,
178
+ modifier: bOptions.modifier
179
+ });
180
+ if (result !== 0) return result;
181
+ }
182
+ }
183
+ // Sort variants in the order they were registered
184
+ if (a.variants !== b.variants) {
185
+ return a.variants - b.variants;
186
+ }
187
+ // Make sure each rule returned by a parallel variant is sorted in ascending order
188
+ if (a.parallelIndex !== b.parallelIndex) {
189
+ return a.parallelIndex - b.parallelIndex;
190
+ }
191
+ // Always sort arbitrary properties after other utilities
192
+ if (a.arbitrary !== b.arbitrary) {
193
+ return a.arbitrary - b.arbitrary;
194
+ }
195
+ // Sort utilities, components, etc… in the order they were registered
196
+ return a.index - b.index;
197
+ }
198
+ /**
199
+ * @template T
200
+ * @param {[RuleOffset, T][]} list
201
+ * @returns {[RuleOffset, T][]}
202
+ */ sort(list) {
203
+ return list.sort(([a], [b])=>(0, _bigSign.default)(this.compare(a, b)));
204
+ }
205
+ }
206
+ /**
207
+ *
208
+ * @param {bigint[]} nums
209
+ * @returns {bigint|null}
210
+ */ function max(nums) {
211
+ let max = null;
212
+ for (const num of nums){
213
+ max = max !== null && max !== void 0 ? max : num;
214
+ max = max > num ? max : num;
215
+ }
216
+ return max;
217
+ }
package/lib/lib/regex.js CHANGED
@@ -52,7 +52,7 @@ function nestedBrackets(open, close, depth = 1) {
52
52
  nestedBrackets(open, close, depth - 1)
53
53
  ]),
54
54
  /[^\s]*/,
55
- escape(close),
55
+ escape(close)
56
56
  ]);
57
57
  }
58
58
  function escape(string) {