tailwindcss 3.0.24 → 3.1.0

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 (88) hide show
  1. package/CHANGELOG.md +57 -3
  2. package/colors.d.ts +3 -0
  3. package/defaultConfig.d.ts +3 -0
  4. package/defaultTheme.d.ts +3 -0
  5. package/lib/cli-peer-dependencies.js +8 -3
  6. package/lib/cli.js +118 -77
  7. package/lib/corePluginList.js +1 -0
  8. package/lib/corePlugins.js +146 -117
  9. package/lib/css/preflight.css +1 -8
  10. package/lib/featureFlags.js +8 -6
  11. package/lib/index.js +10 -13
  12. package/lib/lib/cacheInvalidation.js +32 -14
  13. package/lib/lib/collapseAdjacentRules.js +5 -3
  14. package/lib/lib/defaultExtractor.js +191 -32
  15. package/lib/lib/evaluateTailwindFunctions.js +22 -13
  16. package/lib/lib/expandApplyAtRules.js +232 -195
  17. package/lib/lib/expandTailwindAtRules.js +40 -26
  18. package/lib/lib/generateRules.js +106 -42
  19. package/lib/lib/regex.js +52 -0
  20. package/lib/lib/resolveDefaultsAtRules.js +6 -9
  21. package/lib/lib/setupContextUtils.js +131 -79
  22. package/lib/lib/setupTrackingContext.js +7 -9
  23. package/lib/lib/sharedState.js +1 -2
  24. package/lib/lib/substituteScreenAtRules.js +1 -2
  25. package/lib/postcss-plugins/nesting/plugin.js +1 -2
  26. package/lib/util/buildMediaQuery.js +1 -2
  27. package/lib/util/cloneDeep.js +2 -4
  28. package/lib/util/color.js +26 -36
  29. package/lib/util/createPlugin.js +1 -2
  30. package/lib/util/createUtilityPlugin.js +1 -2
  31. package/lib/util/dataTypes.js +14 -12
  32. package/lib/util/flattenColorPalette.js +2 -5
  33. package/lib/util/formatVariantSelector.js +64 -57
  34. package/lib/util/getAllConfigs.js +10 -5
  35. package/lib/util/isValidArbitraryValue.js +1 -2
  36. package/lib/util/log.js +2 -3
  37. package/lib/util/negateValue.js +1 -2
  38. package/lib/util/normalizeConfig.js +33 -23
  39. package/lib/util/normalizeScreens.js +1 -2
  40. package/lib/util/parseAnimationValue.js +1 -2
  41. package/lib/util/parseBoxShadowValue.js +2 -43
  42. package/lib/util/pluginUtils.js +11 -3
  43. package/lib/util/resolveConfig.js +57 -34
  44. package/lib/util/splitAtTopLevelOnly.js +90 -0
  45. package/lib/util/transformThemeValue.js +4 -2
  46. package/lib/util/validateConfig.js +21 -0
  47. package/lib/util/withAlphaVariable.js +5 -5
  48. package/package.json +21 -16
  49. package/peers/index.js +3264 -1330
  50. package/plugin.d.ts +11 -0
  51. package/src/cli-peer-dependencies.js +7 -1
  52. package/src/cli.js +97 -33
  53. package/src/corePluginList.js +1 -1
  54. package/src/corePlugins.js +57 -40
  55. package/src/css/preflight.css +1 -8
  56. package/src/featureFlags.js +2 -2
  57. package/src/index.js +0 -2
  58. package/src/lib/collapseAdjacentRules.js +5 -1
  59. package/src/lib/defaultExtractor.js +177 -35
  60. package/src/lib/evaluateTailwindFunctions.js +20 -4
  61. package/src/lib/expandApplyAtRules.js +247 -188
  62. package/src/lib/expandTailwindAtRules.js +4 -4
  63. package/src/lib/generateRules.js +69 -5
  64. package/src/lib/regex.js +74 -0
  65. package/src/lib/resolveDefaultsAtRules.js +1 -1
  66. package/src/lib/setupContextUtils.js +103 -39
  67. package/src/lib/setupTrackingContext.js +4 -0
  68. package/src/util/color.js +20 -18
  69. package/src/util/dataTypes.js +11 -5
  70. package/src/util/formatVariantSelector.js +79 -62
  71. package/src/util/getAllConfigs.js +7 -0
  72. package/src/util/log.js +1 -1
  73. package/src/util/normalizeConfig.js +0 -8
  74. package/src/util/parseBoxShadowValue.js +3 -50
  75. package/src/util/pluginUtils.js +13 -1
  76. package/src/util/resolveConfig.js +66 -54
  77. package/src/util/splitAtTopLevelOnly.js +71 -0
  78. package/src/util/toPath.js +1 -1
  79. package/src/util/transformThemeValue.js +4 -2
  80. package/src/util/validateConfig.js +13 -0
  81. package/src/util/withAlphaVariable.js +1 -1
  82. package/stubs/defaultConfig.stub.js +2 -3
  83. package/stubs/simpleConfig.stub.js +1 -0
  84. package/types/config.d.ts +325 -0
  85. package/types/generated/.gitkeep +0 -0
  86. package/types/generated/colors.d.ts +276 -0
  87. package/types/generated/corePluginList.d.ts +1 -0
  88. package/types/index.d.ts +1 -0
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ exports.isValidVariantFormatString = isValidVariantFormatString;
6
+ exports.parseVariant = parseVariant;
5
7
  exports.getFileModifiedMap = getFileModifiedMap;
6
8
  exports.createContext = createContext;
7
9
  exports.getContext = getContext;
@@ -10,6 +12,7 @@ var _url = _interopRequireDefault(require("url"));
10
12
  var _postcss = _interopRequireDefault(require("postcss"));
11
13
  var _dlv = _interopRequireDefault(require("dlv"));
12
14
  var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
15
+ var _featureFlagsJs = require("../featureFlags.js");
13
16
  var _transformThemeValue = _interopRequireDefault(require("../util/transformThemeValue"));
14
17
  var _parseObjectStyles = _interopRequireDefault(require("../util/parseObjectStyles"));
15
18
  var _prefixSelector = _interopRequireDefault(require("../util/prefixSelector"));
@@ -31,27 +34,46 @@ function _interopRequireDefault(obj) {
31
34
  default: obj
32
35
  };
33
36
  }
37
+ function _getRequireWildcardCache() {
38
+ if (typeof WeakMap !== "function") return null;
39
+ var cache = new WeakMap();
40
+ _getRequireWildcardCache = function() {
41
+ return cache;
42
+ };
43
+ return cache;
44
+ }
34
45
  function _interopRequireWildcard(obj) {
35
46
  if (obj && obj.__esModule) {
36
47
  return obj;
37
- } else {
38
- var newObj = {};
39
- if (obj != null) {
40
- for(var key in obj){
41
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
42
- var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
43
- if (desc.get || desc.set) {
44
- Object.defineProperty(newObj, key, desc);
45
- } else {
46
- newObj[key] = obj[key];
47
- }
48
- }
48
+ }
49
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
50
+ return {
51
+ default: obj
52
+ };
53
+ }
54
+ var cache = _getRequireWildcardCache();
55
+ if (cache && cache.has(obj)) {
56
+ return cache.get(obj);
57
+ }
58
+ var newObj = {};
59
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
60
+ for(var key in obj){
61
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
62
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
63
+ if (desc && (desc.get || desc.set)) {
64
+ Object.defineProperty(newObj, key, desc);
65
+ } else {
66
+ newObj[key] = obj[key];
49
67
  }
50
68
  }
51
- newObj.default = obj;
52
- return newObj;
53
69
  }
70
+ newObj.default = obj;
71
+ if (cache) {
72
+ cache.set(obj, newObj);
73
+ }
74
+ return newObj;
54
75
  }
76
+ let MATCH_VARIANT = Symbol();
55
77
  function prefix(context, selector) {
56
78
  let prefix1 = context.tailwindConfig.prefix;
57
79
  return typeof prefix1 === "function" ? prefix1(selector) : prefix1 + selector;
@@ -59,8 +81,7 @@ function prefix(context, selector) {
59
81
  function parseVariantFormatString(input) {
60
82
  if (input.includes("{")) {
61
83
  if (!isBalanced(input)) throw new Error(`Your { and } are unbalanced.`);
62
- return input.split(/{(.*)}/gim).flatMap((line)=>parseVariantFormatString(line)
63
- ).filter(Boolean);
84
+ return input.split(/{(.*)}/gim).flatMap((line)=>parseVariantFormatString(line)).filter(Boolean);
64
85
  }
65
86
  return [
66
87
  input.trim()
@@ -147,8 +168,7 @@ function extractCandidates(node, state = {
147
168
  }
148
169
  } else if (node.type === "atrule") {
149
170
  node.walkRules((rule)=>{
150
- for (let classCandidate of rule.selectors.flatMap((selector)=>getClasses(selector)
151
- )){
171
+ for (let classCandidate of rule.selectors.flatMap((selector)=>getClasses(selector))){
152
172
  classes.push(classCandidate);
153
173
  }
154
174
  });
@@ -183,6 +203,27 @@ function withIdentifiers(styles) {
183
203
  });
184
204
  });
185
205
  }
206
+ function isValidVariantFormatString(format) {
207
+ return format.startsWith("@") || format.includes("&");
208
+ }
209
+ function parseVariant(variant) {
210
+ variant = variant.replace(/\n+/g, "").replace(/\s{1,}/g, " ").trim();
211
+ let fns = parseVariantFormatString(variant).map((str)=>{
212
+ if (!str.startsWith("@")) {
213
+ return ({ format })=>format(str);
214
+ }
215
+ let [, name, params] = /@(.*?)( .+|[({].*)/g.exec(str);
216
+ return ({ wrap })=>wrap(_postcss.default.atRule({
217
+ name,
218
+ params: params.trim()
219
+ }));
220
+ }).reverse();
221
+ return (api)=>{
222
+ for (let fn of fns){
223
+ fn(api);
224
+ }
225
+ };
226
+ }
186
227
  function buildPluginApi(tailwindConfig, context, { variantList , variantMap , offsets , classList }) {
187
228
  function getConfigValue(path, defaultValue) {
188
229
  return path ? (0, _dlv).default(tailwindConfig, path, defaultValue) : tailwindConfig;
@@ -199,54 +240,26 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
199
240
  }
200
241
  return context.tailwindConfig.prefix + identifier;
201
242
  }
202
- return {
203
- addVariant (variantName, variantFunctions, options = {}) {
204
- variantFunctions = [].concat(variantFunctions).map((variantFunction)=>{
205
- if (typeof variantFunction !== "string") {
206
- // Safelist public API functions
207
- return ({ modifySelectors , container , separator })=>{
208
- return variantFunction({
209
- modifySelectors,
210
- container,
211
- separator
212
- });
213
- };
214
- }
215
- variantFunction = variantFunction.replace(/\n+/g, "").replace(/\s{1,}/g, " ").trim();
216
- let fns = parseVariantFormatString(variantFunction).map((str)=>{
217
- if (!str.startsWith("@")) {
218
- return ({ format })=>format(str)
219
- ;
220
- }
221
- let [, name, params] = /@(.*?) (.*)/g.exec(str);
222
- return ({ wrap })=>wrap(_postcss.default.atRule({
223
- name,
224
- params
225
- }))
226
- ;
227
- }).reverse();
228
- return (api)=>{
229
- for (let fn of fns){
230
- fn(api);
231
- }
232
- };
233
- });
234
- insertInto(variantList, variantName, options);
235
- variantMap.set(variantName, variantFunctions);
236
- },
243
+ function resolveThemeValue(path, defaultValue, opts = {}) {
244
+ const [pathRoot, ...subPaths] = (0, _toPath).toPath(path);
245
+ const value = getConfigValue([
246
+ "theme",
247
+ pathRoot,
248
+ ...subPaths
249
+ ], defaultValue);
250
+ return (0, _transformThemeValue).default(pathRoot)(value, opts);
251
+ }
252
+ const theme = Object.assign((path, defaultValue = undefined)=>resolveThemeValue(path, defaultValue), {
253
+ withAlpha: (path, opacityValue)=>resolveThemeValue(path, undefined, {
254
+ opacityValue
255
+ })
256
+ });
257
+ let api1 = {
237
258
  postcss: _postcss.default,
238
259
  prefix: applyConfiguredPrefix,
239
260
  e: _escapeClassName.default,
240
261
  config: getConfigValue,
241
- theme (path, defaultValue) {
242
- const [pathRoot, ...subPaths] = (0, _toPath).toPath(path);
243
- const value = getConfigValue([
244
- "theme",
245
- pathRoot,
246
- ...subPaths
247
- ], defaultValue);
248
- return (0, _transformThemeValue).default(pathRoot)(value);
249
- },
262
+ theme,
250
263
  corePlugins: (path)=>{
251
264
  if (Array.isArray(tailwindConfig.corePlugins)) {
252
265
  return tailwindConfig.corePlugins.includes(path);
@@ -373,8 +386,7 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
373
386
  }
374
387
  let ruleSets = [].concat(rule(value)).filter(Boolean).map((declaration)=>({
375
388
  [(0, _nameClass).default(identifier, modifier)]: declaration
376
- })
377
- );
389
+ }));
378
390
  return ruleSets;
379
391
  }
380
392
  let withOffsets = [
@@ -430,8 +442,7 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
430
442
  }
431
443
  let ruleSets = [].concat(rule(value)).filter(Boolean).map((declaration)=>({
432
444
  [(0, _nameClass).default(identifier, modifier)]: declaration
433
- })
434
- );
445
+ }));
435
446
  return ruleSets;
436
447
  }
437
448
  let withOffsets = [
@@ -447,8 +458,55 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
447
458
  }
448
459
  context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets);
449
460
  }
461
+ },
462
+ addVariant (variantName, variantFunctions, options = {}) {
463
+ variantFunctions = [].concat(variantFunctions).map((variantFunction)=>{
464
+ if (typeof variantFunction !== "string") {
465
+ // Safelist public API functions
466
+ return (api)=>{
467
+ let { args , modifySelectors , container , separator , wrap , format } = api;
468
+ let result = variantFunction(Object.assign({
469
+ modifySelectors,
470
+ container,
471
+ separator
472
+ }, variantFunction[MATCH_VARIANT] && {
473
+ args,
474
+ wrap,
475
+ format
476
+ }));
477
+ if (typeof result === "string" && !isValidVariantFormatString(result)) {
478
+ throw new Error(`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`);
479
+ }
480
+ if (Array.isArray(result)) {
481
+ return result.map((variant)=>parseVariant(variant));
482
+ }
483
+ // result may be undefined with legacy variants that use APIs like `modifySelectors`
484
+ return result && parseVariant(result)(api);
485
+ };
486
+ }
487
+ if (!isValidVariantFormatString(variantFunction)) {
488
+ throw new Error(`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`);
489
+ }
490
+ return parseVariant(variantFunction);
491
+ });
492
+ insertInto(variantList, variantName, options);
493
+ variantMap.set(variantName, variantFunctions);
450
494
  }
451
495
  };
496
+ if ((0, _featureFlagsJs).flagEnabled(tailwindConfig, "matchVariant")) {
497
+ api1.matchVariant = function(variants, options) {
498
+ for(let variant in variants){
499
+ var ref;
500
+ for (let [k, v] of Object.entries((ref = options === null || options === void 0 ? void 0 : options.values) !== null && ref !== void 0 ? ref : {})){
501
+ api1.addVariant(`${variant}-${k}`, variants[variant](v));
502
+ }
503
+ api1.addVariant(variant, Object.assign(({ args })=>variants[variant](args), {
504
+ [MATCH_VARIANT]: true
505
+ }), options);
506
+ }
507
+ };
508
+ }
509
+ return api1;
452
510
  }
453
511
  let fileModifiedMapCache = new WeakMap();
454
512
  function getFileModifiedMap(context) {
@@ -561,6 +619,7 @@ function resolvePlugins(context, root) {
561
619
  let afterVariants = [
562
620
  _corePlugins.variantPlugins["directionVariants"],
563
621
  _corePlugins.variantPlugins["reducedMotionVariants"],
622
+ _corePlugins.variantPlugins["prefersContrastVariants"],
564
623
  _corePlugins.variantPlugins["darkVariants"],
565
624
  _corePlugins.variantPlugins["printVariant"],
566
625
  _corePlugins.variantPlugins["screenVariants"],
@@ -600,9 +659,7 @@ function registerPlugins(plugins, context) {
600
659
  plugin === null || plugin === void 0 ? void 0 : plugin(pluginApi);
601
660
  }
602
661
  }
603
- let highestOffset = ((args)=>args.reduce((m, e)=>e > m ? e : m
604
- )
605
- )([
662
+ let highestOffset = ((args)=>args.reduce((m, e)=>e > m ? e : m))([
606
663
  offsets.base,
607
664
  offsets.defaults,
608
665
  offsets.components,
@@ -630,8 +687,7 @@ function registerPlugins(plugins, context) {
630
687
  variant,
631
688
  bits
632
689
  ];
633
- }).sort(([, a], [, z])=>(0, _bigSign).default(a - z)
634
- ));
690
+ }).sort(([, a], [, z])=>(0, _bigSign).default(a - z)));
635
691
  context.minimumScreen = [
636
692
  ...context.variantOrder.values()
637
693
  ].shift();
@@ -641,8 +697,7 @@ function registerPlugins(plugins, context) {
641
697
  context.variantMap.set(variantName, variantFunctions1.map((variantFunction, idx)=>[
642
698
  sort << BigInt(idx),
643
699
  variantFunction
644
- ]
645
- ));
700
+ ]));
646
701
  }
647
702
  var _safelist;
648
703
  let safelist = ((_safelist = context.tailwindConfig.safelist) !== null && _safelist !== void 0 ? _safelist : []).filter(Boolean);
@@ -674,15 +729,13 @@ function registerPlugins(plugins, context) {
674
729
  let [utilName, options] = util;
675
730
  var ref;
676
731
  let values = Object.keys((ref = options === null || options === void 0 ? void 0 : options.values) !== null && ref !== void 0 ? ref : {});
677
- let classes = values.map((value)=>(0, _nameClass).formatClass(utilName, value)
678
- );
732
+ let classes = values.map((value)=>(0, _nameClass).formatClass(utilName, value));
679
733
  if (options === null || options === void 0 ? void 0 : options.supportsNegativeValues) {
680
734
  // This is the normal negated version
681
735
  // e.g. `-inset-1` or `-tw-inset-1`
682
736
  classes = [
683
737
  ...classes,
684
- ...classes.map((cls)=>"-" + cls
685
- )
738
+ ...classes.map((cls)=>"-" + cls)
686
739
  ];
687
740
  // This is the negated version *after* the prefix
688
741
  // e.g. `tw--inset-1`
@@ -690,8 +743,7 @@ function registerPlugins(plugins, context) {
690
743
  // So we add the negative after the prefix
691
744
  classes = [
692
745
  ...classes,
693
- ...classes.map((cls)=>cls.slice(0, prefixLength) + "-" + cls.slice(prefixLength)
694
- ),
746
+ ...classes.map((cls)=>cls.slice(0, prefixLength) + "-" + cls.slice(prefixLength)),
695
747
  ];
696
748
  }
697
749
  return classes;
@@ -15,6 +15,7 @@ var _resolveConfigPath = _interopRequireDefault(require("../util/resolveConfigPa
15
15
  var _sharedState = require("./sharedState");
16
16
  var _setupContextUtils = require("./setupContextUtils");
17
17
  var _parseDependency = _interopRequireDefault(require("../util/parseDependency"));
18
+ var _validateConfigJs = require("../util/validateConfig.js");
18
19
  function setupTrackingContext(configOrPath) {
19
20
  return ({ tailwindDirectives , registerDependency })=>{
20
21
  return (root, result)=>{
@@ -79,9 +80,7 @@ function getCandidateFiles(context, tailwindConfig) {
79
80
  if (candidateFilesCache.has(context)) {
80
81
  return candidateFilesCache.get(context);
81
82
  }
82
- let candidateFiles = tailwindConfig.content.files.filter((item)=>typeof item === "string"
83
- ).map((contentPath)=>(0, _normalizePath).default(contentPath)
84
- );
83
+ let candidateFiles = tailwindConfig.content.files.filter((item)=>typeof item === "string").map((contentPath)=>(0, _normalizePath).default(contentPath));
85
84
  return candidateFilesCache.set(context, candidateFiles).get(context);
86
85
  }
87
86
  // Get the config object based on a path
@@ -89,8 +88,7 @@ function getTailwindConfig(configOrPath) {
89
88
  let userConfigPath = (0, _resolveConfigPath).default(configOrPath);
90
89
  if (userConfigPath !== null) {
91
90
  let [prevConfig, prevConfigHash, prevDeps, prevModified] = configPathCache.get(userConfigPath) || [];
92
- let newDeps = (0, _getModuleDependencies).default(userConfigPath).map((dep)=>dep.file
93
- );
91
+ let newDeps = (0, _getModuleDependencies).default(userConfigPath).map((dep)=>dep.file);
94
92
  let modified = false;
95
93
  let newModified = new Map();
96
94
  for (let file of newDeps){
@@ -114,6 +112,7 @@ function getTailwindConfig(configOrPath) {
114
112
  delete require.cache[file1];
115
113
  }
116
114
  let newConfig = (0, _resolveConfig).default(require(userConfigPath));
115
+ newConfig = (0, _validateConfigJs).validateConfig(newConfig);
117
116
  let newHash = (0, _hashConfig).default(newConfig);
118
117
  configPathCache.set(userConfigPath, [
119
118
  newConfig,
@@ -130,6 +129,7 @@ function getTailwindConfig(configOrPath) {
130
129
  }
131
130
  // It's a plain object, not a path
132
131
  let newConfig = (0, _resolveConfig).default(configOrPath.config === undefined ? configOrPath : configOrPath.config);
132
+ newConfig = (0, _validateConfigJs).validateConfig(newConfig);
133
133
  return [
134
134
  newConfig,
135
135
  null,
@@ -138,12 +138,10 @@ function getTailwindConfig(configOrPath) {
138
138
  ];
139
139
  }
140
140
  function resolvedChangedContent(context, candidateFiles, fileModifiedMap) {
141
- let changedContent = context.tailwindConfig.content.files.filter((item)=>typeof item.raw === "string"
142
- ).map(({ raw , extension ="html" })=>({
141
+ let changedContent = context.tailwindConfig.content.files.filter((item)=>typeof item.raw === "string").map(({ raw , extension ="html" })=>({
143
142
  content: raw,
144
143
  extension
145
- })
146
- );
144
+ }));
147
145
  for (let changedFile of resolveChangedFiles(candidateFiles, fileModifiedMap)){
148
146
  let content = _fs.default.readFileSync(changedFile, "utf8");
149
147
  let extension = _path.default.extname(changedFile).slice(1);
@@ -38,8 +38,7 @@ function resolveDebug(debug) {
38
38
  if (debug === "*") {
39
39
  return true;
40
40
  }
41
- let debuggers = debug.split(",").map((d)=>d.split(":")[0]
42
- );
41
+ let debuggers = debug.split(",").map((d)=>d.split(":")[0]);
43
42
  // Ignoring tailwindcss
44
43
  if (debuggers.includes("-tailwindcss")) {
45
44
  return false;
@@ -15,8 +15,7 @@ function _default({ tailwindConfig: { theme } }) {
15
15
  css.walkAtRules("screen", (atRule)=>{
16
16
  let screen = atRule.params;
17
17
  let screens = (0, _normalizeScreens).normalizeScreens(theme.screens);
18
- let screenDefinition = screens.find(({ name })=>name === screen
19
- );
18
+ let screenDefinition = screens.find(({ name })=>name === screen);
20
19
  if (!screenDefinition) {
21
20
  throw atRule.error(`No \`${screen}\` screen found.`);
22
21
  }
@@ -67,8 +67,7 @@ function nesting(opts = _postcssNested.default) {
67
67
  }
68
68
  // Traverse the tree down to the leaf nodes
69
69
  if (node.nodes) {
70
- node.nodes.forEach((n)=>markDirty(n)
71
- );
70
+ node.nodes.forEach((n)=>markDirty(n));
72
71
  }
73
72
  // If it's a leaf node mark it as dirty
74
73
  // We do this here because marking a node as dirty
@@ -15,6 +15,5 @@ function buildMediaQuery(screens) {
15
15
  screen.min && `(min-width: ${screen.min})`,
16
16
  screen.max && `(max-width: ${screen.max})`,
17
17
  ].filter(Boolean).join(" and ");
18
- })
19
- ).join(", ");
18
+ })).join(", ");
20
19
  }
@@ -5,15 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  exports.cloneDeep = cloneDeep;
6
6
  function cloneDeep(value) {
7
7
  if (Array.isArray(value)) {
8
- return value.map((child)=>cloneDeep(child)
9
- );
8
+ return value.map((child)=>cloneDeep(child));
10
9
  }
11
10
  if (typeof value === "object" && value !== null) {
12
11
  return Object.fromEntries(Object.entries(value).map(([k, v])=>[
13
12
  k,
14
13
  cloneDeep(v)
15
- ]
16
- ));
14
+ ]));
17
15
  }
18
16
  return value;
19
17
  }
package/lib/util/color.js CHANGED
@@ -16,9 +16,10 @@ let VALUE = /(?:\d+|\d*\.\d+)%?/;
16
16
  let SEP = /(?:\s*,\s*|\s+)/;
17
17
  let ALPHA_SEP = /\s*[,/]\s*/;
18
18
  let CUSTOM_PROPERTY = /var\(--(?:[^ )]*?)\)/;
19
- let RGB = new RegExp(`^rgba?\\(\\s*(${VALUE.source}|${CUSTOM_PROPERTY.source})${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source})${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source})(?:${ALPHA_SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?\\s*\\)$`);
20
- let HSL = new RegExp(`^hsla?\\(\\s*((?:${VALUE.source})(?:deg|rad|grad|turn)?|${CUSTOM_PROPERTY.source})${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source})${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source})(?:${ALPHA_SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?\\s*\\)$`);
21
- function parseColor(value) {
19
+ let RGB = new RegExp(`^(rgb)a?\\(\\s*(${VALUE.source}|${CUSTOM_PROPERTY.source})(?:${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?(?:${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?(?:${ALPHA_SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?\\s*\\)$`);
20
+ let HSL = new RegExp(`^(hsl)a?\\(\\s*((?:${VALUE.source})(?:deg|rad|grad|turn)?|${CUSTOM_PROPERTY.source})(?:${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?(?:${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?(?:${ALPHA_SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?\\s*\\)$`);
21
+ function parseColor(value, { loose =false } = {}) {
22
+ var ref, ref1;
22
23
  if (typeof value !== "string") {
23
24
  return null;
24
25
  }
@@ -37,8 +38,7 @@ function parseColor(value) {
37
38
  if (value in _colorName.default) {
38
39
  return {
39
40
  mode: "rgb",
40
- color: _colorName.default[value].map((v)=>v.toString()
41
- )
41
+ color: _colorName.default[value].map((v)=>v.toString())
42
42
  };
43
43
  }
44
44
  let hex = value.replace(SHORT_HEX, (_, r, g, b, a)=>[
@@ -50,8 +50,7 @@ function parseColor(value) {
50
50
  b,
51
51
  b,
52
52
  a ? a + a : ""
53
- ].join("")
54
- ).match(HEX);
53
+ ].join("")).match(HEX);
55
54
  if (hex !== null) {
56
55
  return {
57
56
  mode: "rgb",
@@ -59,40 +58,31 @@ function parseColor(value) {
59
58
  parseInt(hex[1], 16),
60
59
  parseInt(hex[2], 16),
61
60
  parseInt(hex[3], 16)
62
- ].map((v)=>v.toString()
63
- ),
61
+ ].map((v)=>v.toString()),
64
62
  alpha: hex[4] ? (parseInt(hex[4], 16) / 255).toString() : undefined
65
63
  };
66
64
  }
67
- let rgbMatch = value.match(RGB);
68
- if (rgbMatch !== null) {
69
- var ref, ref1;
70
- return {
71
- mode: "rgb",
72
- color: [
73
- rgbMatch[1],
74
- rgbMatch[2],
75
- rgbMatch[3]
76
- ].map((v)=>v.toString()
77
- ),
78
- alpha: (ref = rgbMatch[4]) === null || ref === void 0 ? void 0 : (ref1 = ref.toString) === null || ref1 === void 0 ? void 0 : ref1.call(ref)
79
- };
65
+ var ref2;
66
+ let match = (ref2 = value.match(RGB)) !== null && ref2 !== void 0 ? ref2 : value.match(HSL);
67
+ if (match === null) {
68
+ return null;
80
69
  }
81
- let hslMatch = value.match(HSL);
82
- if (hslMatch !== null) {
83
- var ref2, ref3;
84
- return {
85
- mode: "hsl",
86
- color: [
87
- hslMatch[1],
88
- hslMatch[2],
89
- hslMatch[3]
90
- ].map((v)=>v.toString()
91
- ),
92
- alpha: (ref2 = hslMatch[4]) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.toString) === null || ref3 === void 0 ? void 0 : ref3.call(ref2)
93
- };
70
+ let color = [
71
+ match[2],
72
+ match[3],
73
+ match[4]
74
+ ].filter(Boolean).map((v)=>v.toString());
75
+ if (!loose && color.length !== 3) {
76
+ return null;
94
77
  }
95
- return null;
78
+ if (color.length < 3 && !color.some((part)=>/^var\(.*?\)$/.test(part))) {
79
+ return null;
80
+ }
81
+ return {
82
+ mode: match[1],
83
+ color,
84
+ alpha: (ref = match[5]) === null || ref === void 0 ? void 0 : (ref1 = ref.toString) === null || ref1 === void 0 ? void 0 : ref1.call(ref)
85
+ };
96
86
  }
97
87
  function formatColor({ mode , color , alpha }) {
98
88
  let hasAlpha = alpha !== undefined;
@@ -9,8 +9,7 @@ function createPlugin(plugin, config) {
9
9
  config
10
10
  };
11
11
  }
12
- createPlugin.withOptions = function(pluginFunction, configFunction = ()=>({})
13
- ) {
12
+ createPlugin.withOptions = function(pluginFunction, configFunction = ()=>({})) {
14
13
  const optionsFunction = function(options) {
15
14
  return {
16
15
  __options: options,
@@ -36,8 +36,7 @@ function createUtilityPlugin(themeKey, utilityVariations = [
36
36
  });
37
37
  }, {}), {
38
38
  ...options,
39
- values: filterDefault ? Object.fromEntries(Object.entries((ref = theme(themeKey)) !== null && ref !== void 0 ? ref : {}).filter(([modifier])=>modifier !== "DEFAULT"
40
- )) : theme(themeKey)
39
+ values: filterDefault ? Object.fromEntries(Object.entries((ref = theme(themeKey)) !== null && ref !== void 0 ? ref : {}).filter(([modifier])=>modifier !== "DEFAULT")) : theme(themeKey)
41
40
  });
42
41
  }
43
42
  };
@@ -41,27 +41,29 @@ function normalize(value, isRoot = true) {
41
41
  }).join("");
42
42
  }
43
43
  // Convert `_` to ` `, except for escaped underscores `\_`
44
- value = value.replace(/([^\\])_+/g, (fullMatch, characterBefore)=>characterBefore + " ".repeat(fullMatch.length - 1)
45
- ).replace(/^_/g, " ").replace(/\\_/g, "_");
44
+ value = value.replace(/([^\\])_+/g, (fullMatch, characterBefore)=>characterBefore + " ".repeat(fullMatch.length - 1)).replace(/^_/g, " ").replace(/\\_/g, "_");
46
45
  // Remove leftover whitespace
47
46
  if (isRoot) {
48
47
  value = value.trim();
49
48
  }
50
49
  // Add spaces around operators inside calc() that do not follow an operator
51
50
  // or '('.
52
- return value.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, "$1 $2 ");
51
+ value = value.replace(/calc\(.+\)/g, (match)=>{
52
+ return match.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, "$1 $2 ");
53
+ });
54
+ // Add spaces around some operators not inside calc() that do not follow an operator
55
+ // or '('.
56
+ return value.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([\/])/g, "$1 $2 ");
53
57
  }
54
58
  function url(value) {
55
59
  return value.startsWith("url(");
56
60
  }
57
61
  function number(value) {
58
- return !isNaN(Number(value)) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?`).test(value)
59
- );
62
+ return !isNaN(Number(value)) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?`).test(value));
60
63
  }
61
64
  function percentage(value) {
62
65
  return value.split(UNDERSCORE).every((part)=>{
63
- return /%$/g.test(part) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?%`).test(part)
64
- );
66
+ return /%$/g.test(part) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?%`).test(part));
65
67
  });
66
68
  }
67
69
  let lengthUnits = [
@@ -85,8 +87,7 @@ let lengthUnits = [
85
87
  let lengthUnitsPattern = `(?:${lengthUnits.join("|")})`;
86
88
  function length(value) {
87
89
  return value.split(UNDERSCORE).every((part)=>{
88
- return part === "0" || new RegExp(`${lengthUnitsPattern}$`).test(part) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?${lengthUnitsPattern}`).test(part)
89
- );
90
+ return part === "0" || new RegExp(`${lengthUnitsPattern}$`).test(part) || cssFunctions.some((fn)=>new RegExp(`^${fn}\\(.+?${lengthUnitsPattern}`).test(part));
90
91
  });
91
92
  }
92
93
  let lineWidths = new Set([
@@ -111,7 +112,9 @@ function color(value) {
111
112
  let result = value.split(UNDERSCORE).every((part)=>{
112
113
  part = normalize(part);
113
114
  if (part.startsWith("var(")) return true;
114
- if ((0, _color).parseColor(part) !== null) return colors++, true;
115
+ if ((0, _color).parseColor(part, {
116
+ loose: true
117
+ }) !== null) return colors++, true;
115
118
  return false;
116
119
  });
117
120
  if (!result) return false;
@@ -127,8 +130,7 @@ function image(value) {
127
130
  "image(",
128
131
  "cross-fade(",
129
132
  "image-set("
130
- ].some((fn)=>part.startsWith(fn)
131
- )) {
133
+ ].some((fn)=>part.startsWith(fn))) {
132
134
  images++;
133
135
  return true;
134
136
  }
@@ -5,13 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  exports.default = void 0;
6
6
  const flattenColorPalette = (colors)=>Object.assign({}, ...Object.entries(colors !== null && colors !== void 0 ? colors : {}).flatMap(([color, values])=>typeof values == "object" ? Object.entries(flattenColorPalette(values)).map(([number, hex])=>({
7
7
  [color + (number === "DEFAULT" ? "" : `-${number}`)]: hex
8
- })
9
- ) : [
8
+ })) : [
10
9
  {
11
10
  [`${color}`]: values
12
11
  }
13
- ]
14
- ))
15
- ;
12
+ ]));
16
13
  var _default = flattenColorPalette;
17
14
  exports.default = _default;