tailwindcss 0.0.0-insiders.df011dc → 0.0.0-insiders.e2d5f21

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 (120) hide show
  1. package/CHANGELOG.md +106 -1
  2. package/README.md +1 -1
  3. package/colors.js +1 -304
  4. package/defaultConfig.js +1 -4
  5. package/defaultTheme.js +1 -4
  6. package/lib/cli-peer-dependencies.js +4 -9
  7. package/lib/cli.js +646 -705
  8. package/lib/constants.js +15 -15
  9. package/lib/corePluginList.js +174 -4
  10. package/lib/corePlugins.js +3637 -2934
  11. package/lib/css/preflight.css +14 -1
  12. package/lib/featureFlags.js +44 -44
  13. package/lib/index.js +25 -24
  14. package/lib/lib/collapseAdjacentRules.js +33 -35
  15. package/lib/lib/collapseDuplicateDeclarations.js +29 -0
  16. package/lib/lib/detectNesting.js +34 -0
  17. package/lib/lib/evaluateTailwindFunctions.js +134 -155
  18. package/lib/lib/expandApplyAtRules.js +183 -200
  19. package/lib/lib/expandTailwindAtRules.js +219 -232
  20. package/lib/lib/generateRules.js +478 -311
  21. package/lib/lib/getModuleDependencies.js +36 -41
  22. package/lib/lib/normalizeTailwindDirectives.js +66 -58
  23. package/lib/lib/resolveDefaultsAtRules.js +110 -90
  24. package/lib/lib/setupContextUtils.js +740 -580
  25. package/lib/lib/setupTrackingContext.js +142 -162
  26. package/lib/lib/setupWatchingContext.js +235 -278
  27. package/lib/lib/sharedState.js +7 -17
  28. package/lib/lib/substituteScreenAtRules.js +22 -26
  29. package/lib/processTailwindFeatures.js +38 -44
  30. package/lib/public/colors.js +329 -0
  31. package/lib/public/create-plugin.js +13 -0
  32. package/lib/public/default-config.js +14 -0
  33. package/lib/public/default-theme.js +14 -0
  34. package/lib/public/resolve-config.js +19 -0
  35. package/lib/util/bigSign.js +3 -5
  36. package/lib/util/buildMediaQuery.js +15 -31
  37. package/lib/util/cloneDeep.js +14 -13
  38. package/lib/util/cloneNodes.js +9 -13
  39. package/lib/util/color.js +69 -59
  40. package/lib/util/configurePlugins.js +13 -14
  41. package/lib/util/createPlugin.js +21 -24
  42. package/lib/util/createUtilityPlugin.js +47 -45
  43. package/lib/util/dataTypes.js +231 -0
  44. package/lib/util/defaults.js +10 -14
  45. package/lib/util/escapeClassName.js +12 -14
  46. package/lib/util/escapeCommas.js +3 -5
  47. package/lib/util/flattenColorPalette.js +14 -10
  48. package/lib/util/formatVariantSelector.js +186 -0
  49. package/lib/util/getAllConfigs.js +23 -16
  50. package/lib/util/hashConfig.js +10 -10
  51. package/lib/util/isKeyframeRule.js +3 -5
  52. package/lib/util/isPlainObject.js +7 -10
  53. package/lib/util/isValidArbitraryValue.js +64 -0
  54. package/lib/util/log.js +39 -30
  55. package/lib/util/nameClass.js +23 -23
  56. package/lib/util/negateValue.js +14 -15
  57. package/lib/util/normalizeConfig.js +208 -0
  58. package/lib/util/normalizeScreens.js +58 -0
  59. package/lib/util/parseAnimationValue.js +82 -53
  60. package/lib/util/parseBoxShadowValue.js +77 -0
  61. package/lib/util/parseDependency.js +49 -60
  62. package/lib/util/parseObjectStyles.js +23 -20
  63. package/lib/util/pluginUtils.js +153 -285
  64. package/lib/util/prefixSelector.js +14 -16
  65. package/lib/util/resolveConfig.js +194 -249
  66. package/lib/util/resolveConfigPath.js +38 -45
  67. package/lib/util/responsive.js +12 -11
  68. package/lib/util/tap.js +4 -6
  69. package/lib/util/toColorValue.js +4 -5
  70. package/lib/util/toPath.js +4 -6
  71. package/lib/util/transformThemeValue.js +57 -26
  72. package/lib/util/withAlphaVariable.js +56 -54
  73. package/package.json +27 -37
  74. package/peers/index.js +73099 -84294
  75. package/plugin.js +1 -3
  76. package/resolveConfig.js +1 -7
  77. package/scripts/create-plugin-list.js +2 -2
  78. package/src/cli.js +27 -18
  79. package/src/corePluginList.js +1 -1
  80. package/src/corePlugins.js +2124 -1968
  81. package/src/css/preflight.css +14 -1
  82. package/src/featureFlags.js +12 -6
  83. package/src/lib/collapseDuplicateDeclarations.js +28 -0
  84. package/src/lib/detectNesting.js +39 -0
  85. package/src/lib/evaluateTailwindFunctions.js +5 -2
  86. package/src/lib/expandTailwindAtRules.js +24 -32
  87. package/src/lib/generateRules.js +230 -20
  88. package/src/lib/normalizeTailwindDirectives.js +3 -2
  89. package/src/lib/resolveDefaultsAtRules.js +46 -30
  90. package/src/lib/setupContextUtils.js +275 -113
  91. package/src/lib/setupTrackingContext.js +9 -8
  92. package/src/lib/setupWatchingContext.js +12 -7
  93. package/src/lib/sharedState.js +1 -4
  94. package/src/lib/substituteScreenAtRules.js +6 -3
  95. package/src/processTailwindFeatures.js +8 -1
  96. package/src/public/colors.js +300 -0
  97. package/src/public/create-plugin.js +2 -0
  98. package/src/public/default-config.js +4 -0
  99. package/src/public/default-theme.js +4 -0
  100. package/src/public/resolve-config.js +7 -0
  101. package/src/util/buildMediaQuery.js +14 -18
  102. package/src/util/createUtilityPlugin.js +2 -11
  103. package/src/util/dataTypes.js +246 -0
  104. package/src/util/formatVariantSelector.js +196 -0
  105. package/src/util/isValidArbitraryValue.js +61 -0
  106. package/src/util/log.js +18 -21
  107. package/src/util/nameClass.js +10 -6
  108. package/src/util/negateValue.js +4 -2
  109. package/src/util/normalizeConfig.js +249 -0
  110. package/src/util/normalizeScreens.js +42 -0
  111. package/src/util/parseAnimationValue.js +7 -1
  112. package/src/util/parseBoxShadowValue.js +71 -0
  113. package/src/util/parseDependency.js +4 -0
  114. package/src/util/pluginUtils.js +101 -204
  115. package/src/util/prefixSelector.js +1 -4
  116. package/src/util/resolveConfig.js +12 -65
  117. package/src/util/transformThemeValue.js +22 -7
  118. package/src/util/withAlphaVariable.js +13 -8
  119. package/stubs/defaultConfig.stub.js +163 -97
  120. package/stubs/simpleConfig.stub.js +0 -1
@@ -0,0 +1,246 @@
1
+ import { parseColor } from './color'
2
+ import { parseBoxShadowValue } from './parseBoxShadowValue'
3
+
4
+ let cssFunctions = ['min', 'max', 'clamp', 'calc']
5
+
6
+ // Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Types
7
+
8
+ let COMMA = /,(?![^(]*\))/g // Comma separator that is not located between brackets. E.g.: `cubiz-bezier(a, b, c)` these don't count.
9
+ let UNDERSCORE = /_(?![^(]*\))/g // Underscore separator that is not located between brackets. E.g.: `rgba(255,_255,_255)_black` these don't count.
10
+
11
+ // This is not a data type, but rather a function that can normalize the
12
+ // correct values.
13
+ export function normalize(value, isRoot = true) {
14
+ // Keep raw strings if it starts with `url(`
15
+ if (value.includes('url(')) {
16
+ return value
17
+ .split(/(url\(.*?\))/g)
18
+ .filter(Boolean)
19
+ .map((part) => {
20
+ if (/^url\(.*?\)$/.test(part)) {
21
+ return part
22
+ }
23
+
24
+ return normalize(part, false)
25
+ })
26
+ .join('')
27
+ }
28
+
29
+ // Convert `_` to ` `, except for escaped underscores `\_`
30
+ value = value
31
+ .replace(
32
+ /([^\\])_+/g,
33
+ (fullMatch, characterBefore) => characterBefore + ' '.repeat(fullMatch.length - 1)
34
+ )
35
+ .replace(/^_/g, ' ')
36
+ .replace(/\\_/g, '_')
37
+
38
+ // Remove leftover whitespace
39
+ if (isRoot) {
40
+ value = value.trim()
41
+ }
42
+
43
+ // Add spaces around operators inside calc() that do not follow an operator
44
+ // or '('.
45
+ return value.replace(
46
+ /(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g,
47
+ '$1 $2 '
48
+ )
49
+ }
50
+
51
+ export function url(value) {
52
+ return value.startsWith('url(')
53
+ }
54
+
55
+ export function number(value) {
56
+ return !isNaN(Number(value)) || cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?`).test(value))
57
+ }
58
+
59
+ export function percentage(value) {
60
+ return /%$/g.test(value) || cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?%`).test(value))
61
+ }
62
+
63
+ let lengthUnits = [
64
+ 'cm',
65
+ 'mm',
66
+ 'Q',
67
+ 'in',
68
+ 'pc',
69
+ 'pt',
70
+ 'px',
71
+ 'em',
72
+ 'ex',
73
+ 'ch',
74
+ 'rem',
75
+ 'lh',
76
+ 'vw',
77
+ 'vh',
78
+ 'vmin',
79
+ 'vmax',
80
+ ]
81
+ let lengthUnitsPattern = `(?:${lengthUnits.join('|')})`
82
+ export function length(value) {
83
+ return (
84
+ value === '0' ||
85
+ new RegExp(`${lengthUnitsPattern}$`).test(value) ||
86
+ cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?${lengthUnitsPattern}`).test(value))
87
+ )
88
+ }
89
+
90
+ let lineWidths = new Set(['thin', 'medium', 'thick'])
91
+ export function lineWidth(value) {
92
+ return lineWidths.has(value)
93
+ }
94
+
95
+ export function shadow(value) {
96
+ let parsedShadows = parseBoxShadowValue(normalize(value))
97
+
98
+ for (let parsedShadow of parsedShadows) {
99
+ if (!parsedShadow.valid) {
100
+ return false
101
+ }
102
+ }
103
+
104
+ return true
105
+ }
106
+
107
+ export function color(value) {
108
+ let colors = 0
109
+
110
+ let result = value.split(UNDERSCORE).every((part) => {
111
+ part = normalize(part)
112
+
113
+ if (part.startsWith('var(')) return true
114
+ if (parseColor(part) !== null) return colors++, true
115
+
116
+ return false
117
+ })
118
+
119
+ if (!result) return false
120
+ return colors > 0
121
+ }
122
+
123
+ export function image(value) {
124
+ let images = 0
125
+ let result = value.split(COMMA).every((part) => {
126
+ part = normalize(part)
127
+
128
+ if (part.startsWith('var(')) return true
129
+ if (
130
+ url(part) ||
131
+ gradient(part) ||
132
+ ['element(', 'image(', 'cross-fade(', 'image-set('].some((fn) => part.startsWith(fn))
133
+ ) {
134
+ images++
135
+ return true
136
+ }
137
+
138
+ return false
139
+ })
140
+
141
+ if (!result) return false
142
+ return images > 0
143
+ }
144
+
145
+ let gradientTypes = new Set([
146
+ 'linear-gradient',
147
+ 'radial-gradient',
148
+ 'repeating-linear-gradient',
149
+ 'repeating-radial-gradient',
150
+ 'conic-gradient',
151
+ ])
152
+ export function gradient(value) {
153
+ value = normalize(value)
154
+
155
+ for (let type of gradientTypes) {
156
+ if (value.startsWith(`${type}(`)) {
157
+ return true
158
+ }
159
+ }
160
+ return false
161
+ }
162
+
163
+ let validPositions = new Set(['center', 'top', 'right', 'bottom', 'left'])
164
+ export function position(value) {
165
+ let positions = 0
166
+ let result = value.split(UNDERSCORE).every((part) => {
167
+ part = normalize(part)
168
+
169
+ if (part.startsWith('var(')) return true
170
+ if (validPositions.has(part) || length(part) || percentage(part)) {
171
+ positions++
172
+ return true
173
+ }
174
+
175
+ return false
176
+ })
177
+
178
+ if (!result) return false
179
+ return positions > 0
180
+ }
181
+
182
+ export function familyName(value) {
183
+ let fonts = 0
184
+ let result = value.split(COMMA).every((part) => {
185
+ part = normalize(part)
186
+
187
+ if (part.startsWith('var(')) return true
188
+
189
+ // If it contains spaces, then it should be quoted
190
+ if (part.includes(' ')) {
191
+ if (!/(['"])([^"']+)\1/g.test(part)) {
192
+ return false
193
+ }
194
+ }
195
+
196
+ // If it starts with a number, it's invalid
197
+ if (/^\d/g.test(part)) {
198
+ return false
199
+ }
200
+
201
+ fonts++
202
+
203
+ return true
204
+ })
205
+
206
+ if (!result) return false
207
+ return fonts > 0
208
+ }
209
+
210
+ let genericNames = new Set([
211
+ 'serif',
212
+ 'sans-serif',
213
+ 'monospace',
214
+ 'cursive',
215
+ 'fantasy',
216
+ 'system-ui',
217
+ 'ui-serif',
218
+ 'ui-sans-serif',
219
+ 'ui-monospace',
220
+ 'ui-rounded',
221
+ 'math',
222
+ 'emoji',
223
+ 'fangsong',
224
+ ])
225
+ export function genericName(value) {
226
+ return genericNames.has(value)
227
+ }
228
+
229
+ let absoluteSizes = new Set([
230
+ 'xx-small',
231
+ 'x-small',
232
+ 'small',
233
+ 'medium',
234
+ 'large',
235
+ 'x-large',
236
+ 'x-large',
237
+ 'xxx-large',
238
+ ])
239
+ export function absoluteSize(value) {
240
+ return absoluteSizes.has(value)
241
+ }
242
+
243
+ let relativeSizes = new Set(['larger', 'smaller'])
244
+ export function relativeSize(value) {
245
+ return relativeSizes.has(value)
246
+ }
@@ -0,0 +1,196 @@
1
+ import selectorParser from 'postcss-selector-parser'
2
+ import unescape from 'postcss-selector-parser/dist/util/unesc'
3
+ import escapeClassName from '../util/escapeClassName'
4
+ import prefixSelector from '../util/prefixSelector'
5
+
6
+ let MERGE = ':merge'
7
+ let PARENT = '&'
8
+
9
+ export let selectorFunctions = new Set([MERGE])
10
+
11
+ export function formatVariantSelector(current, ...others) {
12
+ for (let other of others) {
13
+ let incomingValue = resolveFunctionArgument(other, MERGE)
14
+ if (incomingValue !== null) {
15
+ let existingValue = resolveFunctionArgument(current, MERGE, incomingValue)
16
+ if (existingValue !== null) {
17
+ let existingTarget = `${MERGE}(${incomingValue})`
18
+ let splitIdx = other.indexOf(existingTarget)
19
+ let addition = other.slice(splitIdx + existingTarget.length).split(' ')[0]
20
+
21
+ current = current.replace(existingTarget, existingTarget + addition)
22
+ continue
23
+ }
24
+ }
25
+
26
+ current = other.replace(PARENT, current)
27
+ }
28
+
29
+ return current
30
+ }
31
+
32
+ export function finalizeSelector(format, { selector, candidate, context }) {
33
+ let separator = context?.tailwindConfig?.separator ?? ':'
34
+
35
+ // Split by the separator, but ignore the separator inside square brackets:
36
+ //
37
+ // E.g.: dark:lg:hover:[paint-order:markers]
38
+ // ┬ ┬ ┬ ┬
39
+ // │ │ │ ╰── We will not split here
40
+ // ╰──┴─────┴─────────────── We will split here
41
+ //
42
+ let splitter = new RegExp(`\\${separator}(?![^[]*\\])`)
43
+ let base = candidate.split(splitter).pop()
44
+
45
+ if (context?.tailwindConfig?.prefix) {
46
+ format = prefixSelector(context.tailwindConfig.prefix, format)
47
+ }
48
+
49
+ format = format.replace(PARENT, `.${escapeClassName(candidate)}`)
50
+
51
+ // Normalize escaped classes, e.g.:
52
+ //
53
+ // The idea would be to replace the escaped `base` in the selector with the
54
+ // `format`. However, in css you can escape the same selector in a few
55
+ // different ways. This would result in different strings and therefore we
56
+ // can't replace it properly.
57
+ //
58
+ // base: bg-[rgb(255,0,0)]
59
+ // base in selector: bg-\\[rgb\\(255\\,0\\,0\\)\\]
60
+ // escaped base: bg-\\[rgb\\(255\\2c 0\\2c 0\\)\\]
61
+ //
62
+ selector = selectorParser((selectors) => {
63
+ return selectors.walkClasses((node) => {
64
+ if (node.raws && node.value.includes(base)) {
65
+ node.raws.value = escapeClassName(unescape(node.raws.value))
66
+ }
67
+
68
+ return node
69
+ })
70
+ }).processSync(selector)
71
+
72
+ // We can safely replace the escaped base now, since the `base` section is
73
+ // now in a normalized escaped value.
74
+ selector = selector.replace(`.${escapeClassName(base)}`, format)
75
+
76
+ // Remove unnecessary pseudo selectors that we used as placeholders
77
+ return selectorParser((selectors) => {
78
+ return selectors.map((selector) => {
79
+ selector.walkPseudos((p) => {
80
+ if (selectorFunctions.has(p.value)) {
81
+ p.replaceWith(p.nodes)
82
+ }
83
+
84
+ return p
85
+ })
86
+
87
+ // This will make sure to move pseudo's to the correct spot (the end for
88
+ // pseudo elements) because otherwise the selector will never work
89
+ // anyway.
90
+ //
91
+ // E.g.:
92
+ // - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
93
+ // - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
94
+ //
95
+ // `::before:hover` doesn't work, which means that we can make it work for you by flipping the order.
96
+ function collectPseudoElements(selector) {
97
+ let nodes = []
98
+
99
+ for (let node of selector.nodes) {
100
+ if (isPseudoElement(node)) {
101
+ nodes.push(node)
102
+ selector.removeChild(node)
103
+ }
104
+
105
+ if (node?.nodes) {
106
+ nodes.push(...collectPseudoElements(node))
107
+ }
108
+ }
109
+
110
+ return nodes
111
+ }
112
+
113
+ let pseudoElements = collectPseudoElements(selector)
114
+ if (pseudoElements.length > 0) {
115
+ selector.nodes.push(pseudoElements.sort(sortSelector))
116
+ }
117
+
118
+ return selector
119
+ })
120
+ }).processSync(selector)
121
+ }
122
+
123
+ // Note: As a rule, double colons (::) should be used instead of a single colon
124
+ // (:). This distinguishes pseudo-classes from pseudo-elements. However, since
125
+ // this distinction was not present in older versions of the W3C spec, most
126
+ // browsers support both syntaxes for the original pseudo-elements.
127
+ let pseudoElementsBC = [':before', ':after', ':first-line', ':first-letter']
128
+
129
+ // These pseudo-elements _can_ be combined with other pseudo selectors AND the order does matter.
130
+ let pseudoElementExceptions = ['::file-selector-button']
131
+
132
+ // This will make sure to move pseudo's to the correct spot (the end for
133
+ // pseudo elements) because otherwise the selector will never work
134
+ // anyway.
135
+ //
136
+ // E.g.:
137
+ // - `before:hover:text-center` would result in `.before\:hover\:text-center:hover::before`
138
+ // - `hover:before:text-center` would result in `.hover\:before\:text-center:hover::before`
139
+ //
140
+ // `::before:hover` doesn't work, which means that we can make it work
141
+ // for you by flipping the order.
142
+ function sortSelector(a, z) {
143
+ // Both nodes are non-pseudo's so we can safely ignore them and keep
144
+ // them in the same order.
145
+ if (a.type !== 'pseudo' && z.type !== 'pseudo') {
146
+ return 0
147
+ }
148
+
149
+ // If one of them is a combinator, we need to keep it in the same order
150
+ // because that means it will start a new "section" in the selector.
151
+ if ((a.type === 'combinator') ^ (z.type === 'combinator')) {
152
+ return 0
153
+ }
154
+
155
+ // One of the items is a pseudo and the other one isn't. Let's move
156
+ // the pseudo to the right.
157
+ if ((a.type === 'pseudo') ^ (z.type === 'pseudo')) {
158
+ return (a.type === 'pseudo') - (z.type === 'pseudo')
159
+ }
160
+
161
+ // Both are pseudo's, move the pseudo elements (except for
162
+ // ::file-selector-button) to the right.
163
+ return isPseudoElement(a) - isPseudoElement(z)
164
+ }
165
+
166
+ function isPseudoElement(node) {
167
+ if (node.type !== 'pseudo') return false
168
+ if (pseudoElementExceptions.includes(node.value)) return false
169
+
170
+ return node.value.startsWith('::') || pseudoElementsBC.includes(node.value)
171
+ }
172
+
173
+ function resolveFunctionArgument(haystack, needle, arg) {
174
+ let startIdx = haystack.indexOf(arg ? `${needle}(${arg})` : needle)
175
+ if (startIdx === -1) return null
176
+
177
+ // Start inside the `(`
178
+ startIdx += needle.length + 1
179
+
180
+ let target = ''
181
+ let count = 0
182
+
183
+ for (let char of haystack.slice(startIdx)) {
184
+ if (char !== '(' && char !== ')') {
185
+ target += char
186
+ } else if (char === '(') {
187
+ target += char
188
+ count++
189
+ } else if (char === ')') {
190
+ if (--count < 0) break // unbalanced
191
+ target += char
192
+ }
193
+ }
194
+
195
+ return target
196
+ }
@@ -0,0 +1,61 @@
1
+ let matchingBrackets = new Map([
2
+ ['{', '}'],
3
+ ['[', ']'],
4
+ ['(', ')'],
5
+ ])
6
+ let inverseMatchingBrackets = new Map(
7
+ Array.from(matchingBrackets.entries()).map(([k, v]) => [v, k])
8
+ )
9
+
10
+ let quotes = new Set(['"', "'", '`'])
11
+
12
+ // Arbitrary values must contain balanced brackets (), [] and {}. Escaped
13
+ // values don't count, and brackets inside quotes also don't count.
14
+ //
15
+ // E.g.: w-[this-is]w-[weird-and-invalid]
16
+ // E.g.: w-[this-is\\]w-\\[weird-but-valid]
17
+ // E.g.: content-['this-is-also-valid]-weirdly-enough']
18
+ export default function isValidArbitraryValue(value) {
19
+ let stack = []
20
+ let inQuotes = false
21
+
22
+ for (let i = 0; i < value.length; i++) {
23
+ let char = value[i]
24
+
25
+ if (char === ':' && !inQuotes && stack.length === 0) {
26
+ return false
27
+ }
28
+
29
+ // Non-escaped quotes allow us to "allow" anything in between
30
+ if (quotes.has(char) && value[i - 1] !== '\\') {
31
+ inQuotes = !inQuotes
32
+ }
33
+
34
+ if (inQuotes) continue
35
+ if (value[i - 1] === '\\') continue // Escaped
36
+
37
+ if (matchingBrackets.has(char)) {
38
+ stack.push(char)
39
+ } else if (inverseMatchingBrackets.has(char)) {
40
+ let inverse = inverseMatchingBrackets.get(char)
41
+
42
+ // Nothing to pop from, therefore it is unbalanced
43
+ if (stack.length <= 0) {
44
+ return false
45
+ }
46
+
47
+ // Popped value must match the inverse value, otherwise it is unbalanced
48
+ if (stack.pop() !== inverse) {
49
+ return false
50
+ }
51
+ }
52
+ }
53
+
54
+ // If there is still something on the stack, it is also unbalanced
55
+ if (stack.length > 0) {
56
+ return false
57
+ }
58
+
59
+ // All good, totally balanced!
60
+ return true
61
+ }
package/src/util/log.js CHANGED
@@ -1,28 +1,25 @@
1
1
  import chalk from 'chalk'
2
2
 
3
- export default {
4
- info(messages) {
5
- if (process.env.JEST_WORKER_ID !== undefined) return
3
+ let alreadyShown = new Set()
6
4
 
7
- console.warn('')
8
- messages.forEach((message) => {
9
- console.warn(chalk.bold.cyan('info'), '-', message)
10
- })
11
- },
12
- warn(messages) {
13
- if (process.env.JEST_WORKER_ID !== undefined) return
5
+ function log(chalk, messages, key) {
6
+ if (process.env.JEST_WORKER_ID !== undefined) return
14
7
 
15
- console.warn('')
16
- messages.forEach((message) => {
17
- console.warn(chalk.bold.yellow('warn'), '-', message)
18
- })
19
- },
20
- risk(messages) {
21
- if (process.env.JEST_WORKER_ID !== undefined) return
8
+ if (key && alreadyShown.has(key)) return
9
+ if (key) alreadyShown.add(key)
10
+
11
+ console.warn('')
12
+ messages.forEach((message) => console.warn(chalk, '-', message))
13
+ }
22
14
 
23
- console.warn('')
24
- messages.forEach((message) => {
25
- console.warn(chalk.bold.magenta('risk'), '-', message)
26
- })
15
+ export default {
16
+ info(key, messages) {
17
+ log(chalk.bold.cyan('info'), ...(Array.isArray(key) ? [key] : [messages, key]))
18
+ },
19
+ warn(key, messages) {
20
+ log(chalk.bold.yellow('warn'), ...(Array.isArray(key) ? [key] : [messages, key]))
21
+ },
22
+ risk(key, messages) {
23
+ log(chalk.bold.magenta('risk'), ...(Array.isArray(key) ? [key] : [messages, key]))
27
24
  },
28
25
  }
@@ -1,22 +1,26 @@
1
1
  import escapeClassName from './escapeClassName'
2
2
  import escapeCommas from './escapeCommas'
3
3
 
4
- function asClass(name) {
4
+ export function asClass(name) {
5
5
  return escapeCommas(`.${escapeClassName(name)}`)
6
6
  }
7
7
 
8
8
  export default function nameClass(classPrefix, key) {
9
+ return asClass(formatClass(classPrefix, key))
10
+ }
11
+
12
+ export function formatClass(classPrefix, key) {
9
13
  if (key === 'DEFAULT') {
10
- return asClass(classPrefix)
14
+ return classPrefix
11
15
  }
12
16
 
13
- if (key === '-') {
14
- return asClass(`-${classPrefix}`)
17
+ if (key === '-' || key === '-DEFAULT') {
18
+ return `-${classPrefix}`
15
19
  }
16
20
 
17
21
  if (key.startsWith('-')) {
18
- return asClass(`-${classPrefix}${key}`)
22
+ return `-${classPrefix}${key}`
19
23
  }
20
24
 
21
- return asClass(`${classPrefix}-${key}`)
25
+ return `${classPrefix}-${key}`
22
26
  }
@@ -1,6 +1,10 @@
1
1
  export default function (value) {
2
2
  value = `${value}`
3
3
 
4
+ if (value === '0') {
5
+ return '0'
6
+ }
7
+
4
8
  // Flip sign of numbers
5
9
  if (/^[+-]?(\d+|\d*\.\d+)(e[+-]?\d+)?(%|\w+)?$/.test(value)) {
6
10
  return value.replace(/^[+-]?/, (sign) => (sign === '-' ? '' : '-'))
@@ -9,6 +13,4 @@ export default function (value) {
9
13
  if (value.includes('var(') || value.includes('calc(')) {
10
14
  return `calc(${value} * -1)`
11
15
  }
12
-
13
- return value
14
16
  }