tailwindcss 0.0.0-insiders.e361b3a → 0.0.0-insiders.e41bf3d

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 (38) hide show
  1. package/CHANGELOG.md +41 -14
  2. package/lib/cli-peer-dependencies.js +4 -3
  3. package/lib/cli.js +34 -17
  4. package/lib/corePlugins.js +6 -0
  5. package/lib/css/preflight.css +1 -8
  6. package/lib/lib/collapseAdjacentRules.js +4 -1
  7. package/lib/lib/defaultExtractor.js +159 -32
  8. package/lib/lib/expandApplyAtRules.js +238 -186
  9. package/lib/lib/expandTailwindAtRules.js +4 -4
  10. package/lib/lib/generateRules.js +18 -2
  11. package/lib/lib/regex.js +53 -0
  12. package/lib/lib/setupContextUtils.js +22 -18
  13. package/lib/postcss-plugins/nesting/README.md +2 -2
  14. package/lib/util/color.js +25 -30
  15. package/lib/util/dataTypes.js +13 -4
  16. package/lib/util/formatVariantSelector.js +54 -44
  17. package/lib/util/parseBoxShadowValue.js +2 -43
  18. package/lib/util/splitAtTopLevelOnly.js +72 -0
  19. package/package.json +14 -14
  20. package/peers/index.js +2478 -1753
  21. package/src/cli-peer-dependencies.js +3 -1
  22. package/src/cli.js +26 -6
  23. package/src/corePlugins.js +2 -0
  24. package/src/css/preflight.css +1 -8
  25. package/src/lib/collapseAdjacentRules.js +5 -1
  26. package/src/lib/defaultExtractor.js +162 -35
  27. package/src/lib/expandApplyAtRules.js +247 -188
  28. package/src/lib/expandTailwindAtRules.js +4 -4
  29. package/src/lib/generateRules.js +19 -2
  30. package/src/lib/regex.js +74 -0
  31. package/src/lib/setupContextUtils.js +25 -21
  32. package/src/postcss-plugins/nesting/README.md +2 -2
  33. package/src/util/color.js +20 -18
  34. package/src/util/dataTypes.js +14 -6
  35. package/src/util/formatVariantSelector.js +61 -50
  36. package/src/util/parseBoxShadowValue.js +3 -50
  37. package/src/util/splitAtTopLevelOnly.js +71 -0
  38. package/types/config.d.ts +15 -15
package/CHANGELOG.md CHANGED
@@ -9,6 +9,43 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Fixed
11
11
 
12
+ - Types: allow for arbitrary theme values (for 3rd party plugins) ([#7926](https://github.com/tailwindlabs/tailwindcss/pull/7926))
13
+ - Don’t split vars with numbers in them inside arbitrary values ([#8091](https://github.com/tailwindlabs/tailwindcss/pull/8091))
14
+ - Require matching prefix when detecting negatives ([#8121](https://github.com/tailwindlabs/tailwindcss/pull/8121))
15
+ - Handle duplicate At Rules without children ([#8122](https://github.com/tailwindlabs/tailwindcss/pull/8122))
16
+ - Allow arbitrary values with commas in `@apply` ([#8125](https://github.com/tailwindlabs/tailwindcss/pull/8125))
17
+ - Fix intellisense for plugins with multiple `@apply` rules ([#8213](https://github.com/tailwindlabs/tailwindcss/pull/8213))
18
+ - Improve type detection for arbitrary color values ([#8201](https://github.com/tailwindlabs/tailwindcss/pull/8201))
19
+ - Support PostCSS config options in config file in CLI ([#8226](https://github.com/tailwindlabs/tailwindcss/pull/8226))
20
+ - Remove default `[hidden]` style in preflight ([#8248](https://github.com/tailwindlabs/tailwindcss/pull/8248))
21
+ - Only check selectors containing base apply candidates for circular dependencies ([#8222](https://github.com/tailwindlabs/tailwindcss/pull/8222))
22
+ - Rewrite default class extractor ([#8204](https://github.com/tailwindlabs/tailwindcss/pull/8204))
23
+ - Move `important` selector to the front when `@apply`-ing selector-modifying variants in custom utilities ([#8313](https://github.com/tailwindlabs/tailwindcss/pull/8313))
24
+
25
+ ### Changed
26
+
27
+ - Try using local `postcss` installation first in the CLI ([#8270](https://github.com/tailwindlabs/tailwindcss/pull/8270))
28
+
29
+ ### Added
30
+
31
+ - Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
32
+ - Add `rgb` and `hsl` color helpers for CSS variables ([#7665](https://github.com/tailwindlabs/tailwindcss/pull/7665))
33
+ - Support PostCSS `Document` nodes ([#7291](https://github.com/tailwindlabs/tailwindcss/pull/7291))
34
+ - Add `text-start` and `text-end` utilities ([#6656](https://github.com/tailwindlabs/tailwindcss/pull/6656))
35
+ - Support customizing class name when using `darkMode: 'class'` ([#5800](https://github.com/tailwindlabs/tailwindcss/pull/5800))
36
+ - Add `--poll` option to the CLI ([#7725](https://github.com/tailwindlabs/tailwindcss/pull/7725))
37
+ - Add new `border-spacing` utilities ([#7102](https://github.com/tailwindlabs/tailwindcss/pull/7102))
38
+ - Add `enabled` variant ([#7905](https://github.com/tailwindlabs/tailwindcss/pull/7905))
39
+ - Add TypeScript types for the `tailwind.config.js` file ([#7891](https://github.com/tailwindlabs/tailwindcss/pull/7891))
40
+ - Add `backdrop` variant ([#7924](https://github.com/tailwindlabs/tailwindcss/pull/7924))
41
+ - Add `grid-flow-dense` utility ([#8193](https://github.com/tailwindlabs/tailwindcss/pull/8193))
42
+ - Add `mix-blend-plus-lighter` utility ([#8288](https://github.com/tailwindlabs/tailwindcss/pull/8288))
43
+ - Add arbitrary variants ([#8299](https://github.com/tailwindlabs/tailwindcss/pull/8299))
44
+
45
+ ## [3.0.24] - 2022-04-12
46
+
47
+ ### Fixed
48
+
12
49
  - Prevent nesting plugin from breaking other plugins ([#7563](https://github.com/tailwindlabs/tailwindcss/pull/7563))
13
50
  - Recursively collapse adjacent rules ([#7565](https://github.com/tailwindlabs/tailwindcss/pull/7565))
14
51
  - Preserve source maps for generated CSS ([#7588](https://github.com/tailwindlabs/tailwindcss/pull/7588))
@@ -22,6 +59,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
22
59
  - Fix generation of `div:not(.foo)` if `.foo` is never defined ([#7815](https://github.com/tailwindlabs/tailwindcss/pull/7815))
23
60
  - Allow for custom properties in `rgb`, `rgba`, `hsl` and `hsla` colors ([#7933](https://github.com/tailwindlabs/tailwindcss/pull/7933))
24
61
  - Remove autoprefixer as explicit peer-dependency to avoid invalid warnings in situations where it isn't actually needed ([#7949](https://github.com/tailwindlabs/tailwindcss/pull/7949))
62
+ - Ensure the `percentage` data type is validated correctly ([#8015](https://github.com/tailwindlabs/tailwindcss/pull/8015))
63
+ - Make sure `font-weight` is inherited by form controls in all browsers ([#8078](https://github.com/tailwindlabs/tailwindcss/pull/8078))
25
64
 
26
65
  ### Changed
27
66
 
@@ -29,19 +68,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
29
68
  - Replace `cosmiconfig` with `lilconfig` ([#6039](https://github.com/tailwindlabs/tailwindcss/pull/6038))
30
69
  - Update `cssnano` to avoid removing empty variables when minifying ([#7818](https://github.com/tailwindlabs/tailwindcss/pull/7818))
31
70
 
32
- ### Added
33
-
34
- - Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
35
- - Add `rgb` and `hsl` color helpers for CSS variables ([#7665](https://github.com/tailwindlabs/tailwindcss/pull/7665))
36
- - Support PostCSS `Document` nodes ([#7291](https://github.com/tailwindlabs/tailwindcss/pull/7291))
37
- - Add `text-start` and `text-end` utilities ([#6656](https://github.com/tailwindlabs/tailwindcss/pull/6656))
38
- - Support customizing class name when using `darkMode: 'class'` ([#5800](https://github.com/tailwindlabs/tailwindcss/pull/5800))
39
- - Add `--poll` option to the CLI ([#7725](https://github.com/tailwindlabs/tailwindcss/pull/7725))
40
- - Add new `border-spacing` utilities ([#7102](https://github.com/tailwindlabs/tailwindcss/pull/7102))
41
- - Add `enabled` variant ([#7905](https://github.com/tailwindlabs/tailwindcss/pull/7905))
42
- - Add TypeScript types for the `tailwind.config.js` file ([#7891](https://github.com/tailwindlabs/tailwindcss/pull/7891))
43
- - Add `backdrop` variant ([#7924](https://github.com/tailwindlabs/tailwindcss/pull/7924))
44
-
45
71
  ## [3.0.23] - 2022-02-16
46
72
 
47
73
  ### Fixed
@@ -1907,7 +1933,8 @@ No release notes
1907
1933
 
1908
1934
  - Everything!
1909
1935
 
1910
- [unreleased]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.23...HEAD
1936
+ [unreleased]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.24...HEAD
1937
+ [3.0.24]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.23...v3.0.24
1911
1938
  [3.0.23]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.22...v3.0.23
1912
1939
  [3.0.22]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.21...v3.0.22
1913
1940
  [3.0.21]: https://github.com/tailwindlabs/tailwindcss/compare/v3.0.20...v3.0.21
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ exports.lazyPostcss = lazyPostcss;
5
6
  exports.lazyAutoprefixer = lazyAutoprefixer;
6
7
  exports.lazyCssnano = lazyCssnano;
7
- exports.postcss = void 0;
8
- let postcss = require("postcss");
9
- exports.postcss = postcss;
8
+ function lazyPostcss() {
9
+ return require("postcss");
10
+ }
10
11
  function lazyAutoprefixer() {
11
12
  return require("autoprefixer");
12
13
  }
package/lib/cli.js CHANGED
@@ -9,6 +9,8 @@ var _postcssLoadConfig = _interopRequireDefault(require("postcss-load-config"));
9
9
  var _lilconfig = require("lilconfig");
10
10
  var _plugins // Little bit scary, looking at private/internal API
11
11
  = _interopRequireDefault(require("postcss-load-config/src/plugins"));
12
+ var _options // Little bit scary, looking at private/internal API
13
+ = _interopRequireDefault(require("postcss-load-config/src/options"));
12
14
  var _processTailwindFeatures = _interopRequireDefault(require("./processTailwindFeatures"));
13
15
  var _resolveConfig = _interopRequireDefault(require("../resolveConfig"));
14
16
  var _fastGlob = _interopRequireDefault(require("fast-glob"));
@@ -128,6 +130,13 @@ function oneOf(...options) {
128
130
  manualParsing: true
129
131
  });
130
132
  }
133
+ function loadPostcss() {
134
+ // Try to load a local `postcss` version first
135
+ try {
136
+ return require("postcss");
137
+ } catch {}
138
+ return (0, _indexJs).lazyPostcss();
139
+ }
131
140
  let commands = {
132
141
  init: {
133
142
  run: init,
@@ -384,7 +393,7 @@ async function build() {
384
393
  )(_path.default.resolve("./tailwind.config.js"));
385
394
  async function loadPostCssPlugins() {
386
395
  let customPostCssPath = typeof args["--postcss"] === "string" ? args["--postcss"] : undefined;
387
- let { plugins: configPlugins } = customPostCssPath ? await (async ()=>{
396
+ let config1 = customPostCssPath ? await (async ()=>{
388
397
  let file = _path.default.resolve(customPostCssPath);
389
398
  // Implementation, see: https://unpkg.com/browse/postcss-load-config@3.1.0/src/index.js
390
399
  let { config ={} } = await (0, _lilconfig).lilconfig("postcss").load(file);
@@ -397,9 +406,12 @@ async function build() {
397
406
  config.plugins = [];
398
407
  }
399
408
  return {
400
- plugins: (0, _plugins).default(config, file)
409
+ file,
410
+ plugins: (0, _plugins).default(config, file),
411
+ options: (0, _options).default(config, file)
401
412
  };
402
413
  })() : await (0, _postcssLoadConfig).default();
414
+ let configPlugins = config1.plugins;
403
415
  let configPluginTailwindIdx = configPlugins.findIndex((plugin)=>{
404
416
  if (typeof plugin === "function" && plugin.name === "tailwindcss") {
405
417
  return true;
@@ -413,7 +425,8 @@ async function build() {
413
425
  let afterPlugins = configPluginTailwindIdx === -1 ? configPlugins : configPlugins.slice(configPluginTailwindIdx + 1);
414
426
  return [
415
427
  beforePlugins,
416
- afterPlugins
428
+ afterPlugins,
429
+ config1.options
417
430
  ];
418
431
  }
419
432
  function resolveConfig() {
@@ -489,9 +502,10 @@ async function build() {
489
502
  };
490
503
  };
491
504
  tailwindPlugin.postcss = true;
492
- let [beforePlugins, afterPlugins] = includePostCss ? await loadPostCssPlugins() : [
505
+ let [beforePlugins, afterPlugins, postcssOptions] = includePostCss ? await loadPostCssPlugins() : [
493
506
  [],
494
- []
507
+ [],
508
+ {}
495
509
  ];
496
510
  let plugins = [
497
511
  ...beforePlugins,
@@ -521,13 +535,15 @@ async function build() {
521
535
  return (0, _indexJs).lazyCssnano()(options);
522
536
  })(),
523
537
  ].filter(Boolean);
524
- let processor = (0, _indexJs).postcss(plugins);
538
+ let postcss = loadPostcss();
539
+ let processor = postcss(plugins);
525
540
  function processCSS(css) {
526
541
  let start = process.hrtime.bigint();
527
542
  return Promise.resolve().then(()=>output ? _fs.default.promises.mkdir(_path.default.dirname(output), {
528
543
  recursive: true
529
544
  }) : null
530
545
  ).then(()=>processor.process(css, {
546
+ ...postcssOptions,
531
547
  from: input,
532
548
  to: output
533
549
  })
@@ -641,7 +657,8 @@ async function build() {
641
657
  let tailwindPluginIdx = plugins.indexOf("__TAILWIND_PLUGIN_POSITION__");
642
658
  let copy = plugins.slice();
643
659
  copy.splice(tailwindPluginIdx, 1, tailwindPlugin);
644
- let processor = (0, _indexJs).postcss(copy);
660
+ let postcss = loadPostcss();
661
+ let processor = postcss(copy);
645
662
  function processCSS(css) {
646
663
  let start = process.hrtime.bigint();
647
664
  return Promise.resolve().then(()=>output ? _fs.default.promises.mkdir(_path.default.dirname(output), {
@@ -694,13 +711,13 @@ async function build() {
694
711
  env.DEBUG && console.timeEnd("Finished in");
695
712
  return result1;
696
713
  }
697
- let config1 = refreshConfig(configPath);
714
+ let config2 = refreshConfig(configPath);
698
715
  if (input) {
699
716
  contextDependencies.add(_path.default.resolve(input));
700
717
  }
701
718
  watcher = _chokidar.default.watch([
702
719
  ...contextDependencies,
703
- ...extractFileGlobs(config1)
720
+ ...extractFileGlobs(config2)
704
721
  ], {
705
722
  usePolling: shouldPoll,
706
723
  interval: shouldPoll ? pollInterval : undefined,
@@ -715,16 +732,16 @@ async function build() {
715
732
  if (contextDependencies.has(file)) {
716
733
  env.DEBUG && console.time("Resolve config");
717
734
  context = null;
718
- config1 = refreshConfig(configPath);
735
+ config2 = refreshConfig(configPath);
719
736
  env.DEBUG && console.timeEnd("Resolve config");
720
737
  env.DEBUG && console.time("Watch new files");
721
- let globs = extractFileGlobs(config1);
738
+ let globs = extractFileGlobs(config2);
722
739
  watcher.add(configDependencies);
723
740
  watcher.add(globs);
724
741
  env.DEBUG && console.timeEnd("Watch new files");
725
742
  chain = chain.then(async ()=>{
726
- changedContent.push(...getChangedContent(config1));
727
- await rebuild(config1);
743
+ changedContent.push(...getChangedContent(config2));
744
+ await rebuild(config2);
728
745
  });
729
746
  } else {
730
747
  chain = chain.then(async ()=>{
@@ -732,7 +749,7 @@ async function build() {
732
749
  content: _fs.default.readFileSync(_path.default.resolve(file), "utf8"),
733
750
  extension: _path.default.extname(file).slice(1)
734
751
  });
735
- await rebuild(config1);
752
+ await rebuild(config2);
736
753
  });
737
754
  }
738
755
  });
@@ -742,12 +759,12 @@ async function build() {
742
759
  content: _fs.default.readFileSync(_path.default.resolve(file), "utf8"),
743
760
  extension: _path.default.extname(file).slice(1)
744
761
  });
745
- await rebuild(config1);
762
+ await rebuild(config2);
746
763
  });
747
764
  });
748
765
  chain = chain.then(()=>{
749
- changedContent.push(...getChangedContent(config1));
750
- return rebuild(config1);
766
+ changedContent.push(...getChangedContent(config2));
767
+ return rebuild(config2);
751
768
  });
752
769
  }
753
770
  if (shouldWatch) {
@@ -1420,6 +1420,9 @@ let corePlugins = {
1420
1420
  ".grid-flow-col": {
1421
1421
  gridAutoFlow: "column"
1422
1422
  },
1423
+ ".grid-flow-dense": {
1424
+ gridAutoFlow: "dense"
1425
+ },
1423
1426
  ".grid-flow-row-dense": {
1424
1427
  gridAutoFlow: "row dense"
1425
1428
  },
@@ -3065,6 +3068,9 @@ let corePlugins = {
3065
3068
  },
3066
3069
  ".mix-blend-luminosity": {
3067
3070
  "mix-blend-mode": "luminosity"
3071
+ },
3072
+ ".mix-blend-plus-lighter": {
3073
+ "mix-blend-mode": "plus-lighter"
3068
3074
  }
3069
3075
  });
3070
3076
  },
@@ -160,6 +160,7 @@ select,
160
160
  textarea {
161
161
  font-family: inherit; /* 1 */
162
162
  font-size: 100%; /* 1 */
163
+ font-weight: inherit; /* 1 */
163
164
  line-height: inherit; /* 1 */
164
165
  color: inherit; /* 1 */
165
166
  margin: 0; /* 2 */
@@ -357,11 +358,3 @@ video {
357
358
  max-width: 100%;
358
359
  height: auto;
359
360
  }
360
-
361
- /*
362
- Ensure the default browser behavior of the `hidden` attribute.
363
- */
364
-
365
- [hidden] {
366
- display: none;
367
- }
@@ -21,7 +21,10 @@ function collapseAdjacentRules() {
21
21
  currentRule = node;
22
22
  } else if (properties.every((property)=>((_property = node[property]) !== null && _property !== void 0 ? _property : "").replace(/\s+/g, " ") === ((_property1 = currentRule[property]) !== null && _property1 !== void 0 ? _property1 : "").replace(/\s+/g, " ")
23
23
  )) {
24
- currentRule.append(node.nodes);
24
+ // An AtRule may not have children (for example if we encounter duplicate @import url(…) rules)
25
+ if (node.nodes) {
26
+ currentRule.append(node.nodes);
27
+ }
25
28
  node.remove();
26
29
  } else {
27
30
  currentRule = node;
@@ -3,38 +3,165 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  exports.defaultExtractor = defaultExtractor;
6
- const PATTERNS = [
7
- /(?:\['([^'\s]+[^<>"'`\s:\\])')/.source,
8
- /(?:\["([^"\s]+[^<>"'`\s:\\])")/.source,
9
- /(?:\[`([^`\s]+[^<>"'`\s:\\])`)/.source,
10
- /([^${(<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source,
11
- /([^${(<>"'`\s]*\[\w*"[^'`\s]*"?\])/.source,
12
- /([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source,
13
- /([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source,
14
- /([^<>"'`\s]*\[\w*\('[^"`\s]*'\)\])/.source,
15
- /([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source,
16
- /([^<>"'`\s]*\[[^<>"'`\s]*\('[^"`\s]*'\)+\])/.source,
17
- /([^<>"'`\s]*\[[^<>"'`\s]*\("[^'`\s]*"\)+\])/.source,
18
- /([^${(<>"'`\s]*\['[^"'`\s]*'\])/.source,
19
- /([^${(<>"'`\s]*\["[^"'`\s]*"\])/.source,
20
- /([^<>"'`\s]*\[[^<>"'`\s]*:[^\]\s]*\])/.source,
21
- /([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source,
22
- /([^<>"'`\s]*\[[^<>"'`\s]*:"[^"'`\s]*"\])/.source,
23
- /([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source,
24
- /([^"'`\s]*[^<>"'`\s:\\])/.source,
25
- /([^<>"'`\s]*[^"'`\s:\\])/.source,
26
- ].join("|");
27
- const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, "g");
28
- const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g;
29
- function defaultExtractor(content) {
30
- let broadMatches = content.matchAll(BROAD_MATCH_GLOBAL_REGEXP);
31
- let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || [];
32
- let results = [
33
- ...broadMatches,
34
- ...innerMatches
35
- ].flat().filter((v)=>v !== undefined
36
- );
37
- return results;
6
+ var regex = _interopRequireWildcard(require("./regex"));
7
+ function _interopRequireWildcard(obj) {
8
+ if (obj && obj.__esModule) {
9
+ return obj;
10
+ } else {
11
+ var newObj = {};
12
+ if (obj != null) {
13
+ for(var key in obj){
14
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
15
+ var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
16
+ if (desc.get || desc.set) {
17
+ Object.defineProperty(newObj, key, desc);
18
+ } else {
19
+ newObj[key] = obj[key];
20
+ }
21
+ }
22
+ }
23
+ }
24
+ newObj.default = obj;
25
+ return newObj;
26
+ }
27
+ }
28
+ function defaultExtractor(context) {
29
+ let patterns = Array.from(buildRegExps(context));
30
+ /**
31
+ * @param {string} content
32
+ */ return (content)=>{
33
+ /** @type {(string|string)[]} */ let results = [];
34
+ for (let pattern of patterns){
35
+ var ref;
36
+ results.push(...(ref = content.match(pattern)) !== null && ref !== void 0 ? ref : []);
37
+ }
38
+ return results.filter((v)=>v !== undefined
39
+ ).map(clipAtBalancedParens);
40
+ };
41
+ }
42
+ function* buildRegExps(context) {
43
+ let separator = context.tailwindConfig.separator;
44
+ yield regex.pattern([
45
+ // Variants
46
+ "((?=((",
47
+ regex.any([
48
+ regex.pattern([
49
+ /\[[^\s"'\\]+\]/,
50
+ separator
51
+ ]),
52
+ regex.pattern([
53
+ /[^\s"'\[\\]+/,
54
+ separator
55
+ ])
56
+ ], true),
57
+ ")+))\\2)?",
58
+ // Important (optional)
59
+ /!?/,
60
+ regex.any([
61
+ // Arbitrary properties
62
+ /\[[^\s:'"]+:[^\s\]]+\]/,
63
+ // Utilities
64
+ regex.pattern([
65
+ // Utility Name / Group Name
66
+ /-?(?:\w+)/,
67
+ // Normal/Arbitrary values
68
+ regex.optional(regex.any([
69
+ regex.pattern([
70
+ // Arbitrary values
71
+ /-\[[^\s:]+\]/,
72
+ // Not immediately followed by an `{[(`
73
+ /(?![{([]])/,
74
+ // optionally followed by an opacity modifier
75
+ /(?:\/[^\s'"\\$]*)?/,
76
+ ]),
77
+ regex.pattern([
78
+ // Arbitrary values
79
+ /-\[[^\s]+\]/,
80
+ // Not immediately followed by an `{[(`
81
+ /(?![{([]])/,
82
+ // optionally followed by an opacity modifier
83
+ /(?:\/[^\s'"\\$]*)?/,
84
+ ]),
85
+ // Normal values w/o quotes — may include an opacity modifier
86
+ /[-\/][^\s'"\\$={]*/,
87
+ ])),
88
+ ]),
89
+ ]),
90
+ ]);
91
+ // 5. Inner matches
92
+ // yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
93
+ }
94
+ // We want to capture any "special" characters
95
+ // AND the characters immediately following them (if there is one)
96
+ let SPECIALS = /([\[\]'"`])([^\[\]'"`])?/g;
97
+ let ALLOWED_CLASS_CHARACTERS = /[^"'`\s<>\]]+/;
98
+ /**
99
+ * Clips a string ensuring that parentheses, quotes, etc… are balanced
100
+ * Used for arbitrary values only
101
+ *
102
+ * We will go past the end of the balanced parens until we find a non-class character
103
+ *
104
+ * Depth matching behavior:
105
+ * w-[calc(100%-theme('spacing[some_key][1.5]'))]']
106
+ * ┬ ┬ ┬┬ ┬ ┬┬ ┬┬┬┬┬┬┬
107
+ * 1 2 3 4 34 3 210 END
108
+ * ╰────┴──────────┴────────┴────────┴┴───┴─┴┴┴
109
+ *
110
+ * @param {string} input
111
+ */ function clipAtBalancedParens(input) {
112
+ // We are care about this for arbitrary values
113
+ if (!input.includes("-[")) {
114
+ return input;
115
+ }
116
+ let depth = 0;
117
+ let openStringTypes = [];
118
+ // Find all parens, brackets, quotes, etc
119
+ // Stop when we end at a balanced pair
120
+ // This is naive and will treat mismatched parens as balanced
121
+ // This shouldn't be a problem in practice though
122
+ let matches = input.matchAll(SPECIALS);
123
+ // We can't use lookbehind assertions because we have to support Safari
124
+ // So, instead, we've emulated it using capture groups and we'll re-work the matches to accommodate
125
+ matches = Array.from(matches).flatMap((match)=>{
126
+ const [, ...groups] = match;
127
+ return groups.map((group, idx)=>Object.assign([], match, {
128
+ index: match.index + idx,
129
+ 0: group
130
+ })
131
+ );
132
+ });
133
+ for (let match1 of matches){
134
+ let char = match1[0];
135
+ let inStringType = openStringTypes[openStringTypes.length - 1];
136
+ if (char === inStringType) {
137
+ openStringTypes.pop();
138
+ } else if (char === "'" || char === '"' || char === "`") {
139
+ openStringTypes.push(char);
140
+ }
141
+ if (inStringType) {
142
+ continue;
143
+ } else if (char === "[") {
144
+ depth++;
145
+ continue;
146
+ } else if (char === "]") {
147
+ depth--;
148
+ continue;
149
+ }
150
+ // We've gone one character past the point where we should stop
151
+ // This means that there was an extra closing `]`
152
+ // We'll clip to just before it
153
+ if (depth < 0) {
154
+ return input.substring(0, match1.index);
155
+ }
156
+ // We've finished balancing the brackets but there still may be characters that can be included
157
+ // For example in the class `text-[#336699]/[.35]`
158
+ // The depth goes to `0` at the closing `]` but goes up again at the `[`
159
+ // If we're at zero and encounter a non-class character then we clip the class there
160
+ if (depth === 0 && !ALLOWED_CLASS_CHARACTERS.test(char)) {
161
+ return input.substring(0, match1.index);
162
+ }
163
+ }
164
+ return input;
38
165
  } // Regular utilities
39
166
  // {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
40
167
  // Arbitrary values