tailwindcss 0.0.0-insiders.ebc1c7a → 0.0.0-insiders.ec0049a

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 (165) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +18 -11
  3. package/dist/chunk-AZANAYY2.mjs +1 -0
  4. package/dist/chunk-CH45MXZF.mjs +10 -0
  5. package/dist/chunk-V2K3XTS4.mjs +1 -0
  6. package/dist/colors-b_6i0Oi7.d.ts +295 -0
  7. package/dist/colors.d.mts +295 -0
  8. package/dist/colors.d.ts +5 -0
  9. package/dist/colors.js +1 -0
  10. package/dist/colors.mjs +1 -0
  11. package/dist/default-theme.d.mts +1147 -0
  12. package/dist/default-theme.d.ts +1147 -0
  13. package/dist/default-theme.js +1 -0
  14. package/dist/default-theme.mjs +1 -0
  15. package/dist/flatten-color-palette.d.mts +6 -0
  16. package/dist/flatten-color-palette.d.ts +6 -0
  17. package/dist/flatten-color-palette.js +1 -0
  18. package/dist/flatten-color-palette.mjs +1 -0
  19. package/dist/lib.d.mts +260 -0
  20. package/dist/lib.d.ts +3 -0
  21. package/dist/lib.js +33 -0
  22. package/dist/lib.mjs +24 -0
  23. package/dist/plugin.d.mts +11 -0
  24. package/dist/plugin.d.ts +104 -0
  25. package/dist/plugin.js +1 -0
  26. package/dist/plugin.mjs +1 -0
  27. package/dist/resolve-config-BIFUA2FY.d.ts +29 -0
  28. package/dist/resolve-config-QUZ9b-Gn.d.mts +190 -0
  29. package/dist/types-B254mqw1.d.mts +98 -0
  30. package/index.css +865 -0
  31. package/package.json +73 -110
  32. package/preflight.css +383 -0
  33. package/theme.css +453 -0
  34. package/CHANGELOG.md +0 -1742
  35. package/base.css +0 -1
  36. package/colors.js +0 -304
  37. package/components.css +0 -1
  38. package/defaultConfig.js +0 -4
  39. package/defaultTheme.js +0 -4
  40. package/lib/cli-peer-dependencies.js +0 -20
  41. package/lib/cli.js +0 -765
  42. package/lib/constants.js +0 -37
  43. package/lib/corePluginList.js +0 -8
  44. package/lib/corePlugins.js +0 -2977
  45. package/lib/css/LICENSE +0 -25
  46. package/lib/css/preflight.css +0 -354
  47. package/lib/featureFlags.js +0 -60
  48. package/lib/index.js +0 -31
  49. package/lib/lib/collapseAdjacentRules.js +0 -43
  50. package/lib/lib/evaluateTailwindFunctions.js +0 -192
  51. package/lib/lib/expandApplyAtRules.js +0 -245
  52. package/lib/lib/expandTailwindAtRules.js +0 -260
  53. package/lib/lib/generateRules.js +0 -362
  54. package/lib/lib/getModuleDependencies.js +0 -53
  55. package/lib/lib/normalizeTailwindDirectives.js +0 -68
  56. package/lib/lib/resolveDefaultsAtRules.js +0 -105
  57. package/lib/lib/setupContextUtils.js +0 -643
  58. package/lib/lib/setupTrackingContext.js +0 -190
  59. package/lib/lib/setupWatchingContext.js +0 -331
  60. package/lib/lib/sharedState.js +0 -29
  61. package/lib/lib/substituteScreenAtRules.js +0 -31
  62. package/lib/processTailwindFeatures.js +0 -57
  63. package/lib/util/bigSign.js +0 -10
  64. package/lib/util/buildMediaQuery.js +0 -36
  65. package/lib/util/cloneDeep.js +0 -18
  66. package/lib/util/cloneNodes.js +0 -18
  67. package/lib/util/color.js +0 -74
  68. package/lib/util/configurePlugins.js +0 -19
  69. package/lib/util/createPlugin.js +0 -33
  70. package/lib/util/createUtilityPlugin.js +0 -51
  71. package/lib/util/defaults.js +0 -20
  72. package/lib/util/escapeClassName.js +0 -21
  73. package/lib/util/escapeCommas.js +0 -10
  74. package/lib/util/flattenColorPalette.js +0 -15
  75. package/lib/util/getAllConfigs.js +0 -22
  76. package/lib/util/hashConfig.js +0 -16
  77. package/lib/util/isKeyframeRule.js +0 -10
  78. package/lib/util/isPlainObject.js +0 -15
  79. package/lib/util/log.js +0 -38
  80. package/lib/util/nameClass.js +0 -32
  81. package/lib/util/negateValue.js +0 -20
  82. package/lib/util/parseAnimationValue.js +0 -60
  83. package/lib/util/parseDependency.js +0 -74
  84. package/lib/util/parseObjectStyles.js +0 -28
  85. package/lib/util/pluginUtils.js +0 -318
  86. package/lib/util/prefixSelector.js +0 -23
  87. package/lib/util/resolveConfig.js +0 -289
  88. package/lib/util/resolveConfigPath.js +0 -59
  89. package/lib/util/responsive.js +0 -18
  90. package/lib/util/tap.js +0 -11
  91. package/lib/util/toColorValue.js +0 -10
  92. package/lib/util/toPath.js +0 -11
  93. package/lib/util/transformThemeValue.js +0 -32
  94. package/lib/util/withAlphaVariable.js +0 -65
  95. package/nesting/README.md +0 -42
  96. package/nesting/index.js +0 -12
  97. package/nesting/plugin.js +0 -41
  98. package/peers/index.js +0 -87302
  99. package/plugin.js +0 -3
  100. package/prettier.config.js +0 -19
  101. package/resolveConfig.js +0 -7
  102. package/screens.css +0 -1
  103. package/scripts/create-plugin-list.js +0 -10
  104. package/scripts/install-integrations.js +0 -27
  105. package/scripts/rebuildFixtures.js +0 -68
  106. package/src/cli-peer-dependencies.js +0 -9
  107. package/src/cli.js +0 -759
  108. package/src/constants.js +0 -17
  109. package/src/corePluginList.js +0 -1
  110. package/src/corePlugins.js +0 -2228
  111. package/src/css/LICENSE +0 -25
  112. package/src/css/preflight.css +0 -354
  113. package/src/featureFlags.js +0 -48
  114. package/src/index.js +0 -34
  115. package/src/lib/collapseAdjacentRules.js +0 -39
  116. package/src/lib/evaluateTailwindFunctions.js +0 -195
  117. package/src/lib/expandApplyAtRules.js +0 -251
  118. package/src/lib/expandTailwindAtRules.js +0 -262
  119. package/src/lib/generateRules.js +0 -319
  120. package/src/lib/getModuleDependencies.js +0 -39
  121. package/src/lib/normalizeTailwindDirectives.js +0 -77
  122. package/src/lib/resolveDefaultsAtRules.js +0 -105
  123. package/src/lib/setupContextUtils.js +0 -639
  124. package/src/lib/setupTrackingContext.js +0 -181
  125. package/src/lib/setupWatchingContext.js +0 -306
  126. package/src/lib/sharedState.js +0 -13
  127. package/src/lib/substituteScreenAtRules.js +0 -16
  128. package/src/processTailwindFeatures.js +0 -41
  129. package/src/util/bigSign.js +0 -3
  130. package/src/util/buildMediaQuery.js +0 -24
  131. package/src/util/cloneDeep.js +0 -11
  132. package/src/util/cloneNodes.js +0 -11
  133. package/src/util/color.js +0 -56
  134. package/src/util/configurePlugins.js +0 -23
  135. package/src/util/createPlugin.js +0 -27
  136. package/src/util/createUtilityPlugin.js +0 -46
  137. package/src/util/defaults.js +0 -11
  138. package/src/util/escapeClassName.js +0 -8
  139. package/src/util/escapeCommas.js +0 -3
  140. package/src/util/flattenColorPalette.js +0 -13
  141. package/src/util/getAllConfigs.js +0 -19
  142. package/src/util/hashConfig.js +0 -5
  143. package/src/util/isKeyframeRule.js +0 -3
  144. package/src/util/isPlainObject.js +0 -8
  145. package/src/util/log.js +0 -28
  146. package/src/util/nameClass.js +0 -22
  147. package/src/util/negateValue.js +0 -14
  148. package/src/util/parseAnimationValue.js +0 -62
  149. package/src/util/parseDependency.js +0 -45
  150. package/src/util/parseObjectStyles.js +0 -19
  151. package/src/util/pluginUtils.js +0 -295
  152. package/src/util/prefixSelector.js +0 -15
  153. package/src/util/resolveConfig.js +0 -282
  154. package/src/util/resolveConfigPath.js +0 -55
  155. package/src/util/responsive.js +0 -10
  156. package/src/util/tap.js +0 -4
  157. package/src/util/toColorValue.js +0 -3
  158. package/src/util/toPath.js +0 -4
  159. package/src/util/transformThemeValue.js +0 -37
  160. package/src/util/withAlphaVariable.js +0 -44
  161. package/stubs/defaultConfig.stub.js +0 -884
  162. package/stubs/defaultPostCssConfig.stub.js +0 -6
  163. package/stubs/simpleConfig.stub.js +0 -8
  164. package/tailwind.css +0 -5
  165. package/variants.css +0 -1
@@ -1,27 +0,0 @@
1
- function createPlugin(plugin, config) {
2
- return {
3
- handler: plugin,
4
- config,
5
- }
6
- }
7
-
8
- createPlugin.withOptions = function (pluginFunction, configFunction = () => ({})) {
9
- const optionsFunction = function (options) {
10
- return {
11
- __options: options,
12
- handler: pluginFunction(options),
13
- config: configFunction(options),
14
- }
15
- }
16
-
17
- optionsFunction.__isOptionsFunction = true
18
-
19
- // Expose plugin dependencies so that `object-hash` returns a different
20
- // value if anything here changes, to ensure a rebuild is triggered.
21
- optionsFunction.__pluginFunction = pluginFunction
22
- optionsFunction.__configFunction = configFunction
23
-
24
- return optionsFunction
25
- }
26
-
27
- export default createPlugin
@@ -1,46 +0,0 @@
1
- import transformThemeValue from './transformThemeValue'
2
- import { asValue, asColor, asAngle, asLength, asLookupValue } from '../util/pluginUtils'
3
-
4
- let asMap = new Map([
5
- [asValue, 'any'],
6
- [asColor, 'color'],
7
- [asAngle, 'angle'],
8
- [asLength, 'length'],
9
- [asLookupValue, 'lookup'],
10
- ])
11
-
12
- export default function createUtilityPlugin(
13
- themeKey,
14
- utilityVariations = [[themeKey, [themeKey]]],
15
- { filterDefault = false, resolveArbitraryValue = asValue } = {}
16
- ) {
17
- let transformValue = transformThemeValue(themeKey)
18
- return function ({ matchUtilities, theme }) {
19
- for (let utilityVariation of utilityVariations) {
20
- let group = Array.isArray(utilityVariation[0]) ? utilityVariation : [utilityVariation]
21
-
22
- matchUtilities(
23
- group.reduce((obj, [classPrefix, properties]) => {
24
- return Object.assign(obj, {
25
- [classPrefix]: (value) => {
26
- return properties.reduce((obj, name) => {
27
- if (Array.isArray(name)) {
28
- return Object.assign(obj, { [name[0]]: name[1] })
29
- }
30
- return Object.assign(obj, { [name]: transformValue(value) })
31
- }, {})
32
- },
33
- })
34
- }, {}),
35
- {
36
- values: filterDefault
37
- ? Object.fromEntries(
38
- Object.entries(theme(themeKey) ?? {}).filter(([modifier]) => modifier !== 'DEFAULT')
39
- )
40
- : theme(themeKey),
41
- type: asMap.get(resolveArbitraryValue) ?? 'any',
42
- }
43
- )
44
- }
45
- }
46
- }
@@ -1,11 +0,0 @@
1
- export function defaults(target, ...sources) {
2
- for (let source of sources) {
3
- for (let k in source) {
4
- if (!target?.hasOwnProperty?.(k)) {
5
- target[k] = source[k]
6
- }
7
- }
8
- }
9
-
10
- return target
11
- }
@@ -1,8 +0,0 @@
1
- import parser from 'postcss-selector-parser'
2
- import escapeCommas from './escapeCommas'
3
-
4
- export default function escapeClassName(className) {
5
- let node = parser.className()
6
- node.value = className
7
- return escapeCommas(node?.raws?.value ?? node.value)
8
- }
@@ -1,3 +0,0 @@
1
- export default function escapeCommas(className) {
2
- return className.replace(/\\,/g, '\\2c ')
3
- }
@@ -1,13 +0,0 @@
1
- const flattenColorPalette = (colors) =>
2
- Object.assign(
3
- {},
4
- ...Object.entries(colors ?? {}).flatMap(([color, values]) =>
5
- typeof values == 'object'
6
- ? Object.entries(flattenColorPalette(values)).map(([number, hex]) => ({
7
- [color + (number === 'DEFAULT' ? '' : `-${number}`)]: hex,
8
- }))
9
- : [{ [`${color}`]: values }]
10
- )
11
- )
12
-
13
- export default flattenColorPalette
@@ -1,19 +0,0 @@
1
- import defaultConfig from '../../stubs/defaultConfig.stub.js'
2
- import { flagEnabled } from '../featureFlags'
3
-
4
- export default function getAllConfigs(config) {
5
- const configs = (config?.presets ?? [defaultConfig])
6
- .slice()
7
- .reverse()
8
- .flatMap((preset) => getAllConfigs(preset instanceof Function ? preset() : preset))
9
-
10
- const features = {
11
- // Add experimental configs here...
12
- }
13
-
14
- const experimentals = Object.keys(features)
15
- .filter((feature) => flagEnabled(config, feature))
16
- .map((feature) => features[feature])
17
-
18
- return [config, ...experimentals, ...configs]
19
- }
@@ -1,5 +0,0 @@
1
- import hash from 'object-hash'
2
-
3
- export default function hashConfig(config) {
4
- return hash(config, { ignoreUnknown: true })
5
- }
@@ -1,3 +0,0 @@
1
- export default function isKeyframeRule(rule) {
2
- return rule.parent && rule.parent.type === 'atrule' && /keyframes$/.test(rule.parent.name)
3
- }
@@ -1,8 +0,0 @@
1
- export default function isPlainObject(value) {
2
- if (Object.prototype.toString.call(value) !== '[object Object]') {
3
- return false
4
- }
5
-
6
- const prototype = Object.getPrototypeOf(value)
7
- return prototype === null || prototype === Object.prototype
8
- }
package/src/util/log.js DELETED
@@ -1,28 +0,0 @@
1
- import chalk from 'chalk'
2
-
3
- export default {
4
- info(messages) {
5
- if (process.env.JEST_WORKER_ID !== undefined) return
6
-
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
14
-
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
22
-
23
- console.warn('')
24
- messages.forEach((message) => {
25
- console.warn(chalk.bold.magenta('risk'), '-', message)
26
- })
27
- },
28
- }
@@ -1,22 +0,0 @@
1
- import escapeClassName from './escapeClassName'
2
- import escapeCommas from './escapeCommas'
3
-
4
- function asClass(name) {
5
- return escapeCommas(`.${escapeClassName(name)}`)
6
- }
7
-
8
- export default function nameClass(classPrefix, key) {
9
- if (key === 'DEFAULT') {
10
- return asClass(classPrefix)
11
- }
12
-
13
- if (key === '-') {
14
- return asClass(`-${classPrefix}`)
15
- }
16
-
17
- if (key.startsWith('-')) {
18
- return asClass(`-${classPrefix}${key}`)
19
- }
20
-
21
- return asClass(`${classPrefix}-${key}`)
22
- }
@@ -1,14 +0,0 @@
1
- export default function (value) {
2
- value = `${value}`
3
-
4
- // Flip sign of numbers
5
- if (/^[+-]?(\d+|\d*\.\d+)(e[+-]?\d+)?(%|\w+)?$/.test(value)) {
6
- return value.replace(/^[+-]?/, (sign) => (sign === '-' ? '' : '-'))
7
- }
8
-
9
- if (value.includes('var(') || value.includes('calc(')) {
10
- return `calc(${value} * -1)`
11
- }
12
-
13
- return value
14
- }
@@ -1,62 +0,0 @@
1
- const DIRECTIONS = new Set(['normal', 'reverse', 'alternate', 'alternate-reverse'])
2
- const PLAY_STATES = new Set(['running', 'paused'])
3
- const FILL_MODES = new Set(['none', 'forwards', 'backwards', 'both'])
4
- const ITERATION_COUNTS = new Set(['infinite'])
5
- const TIMINGS = new Set([
6
- 'linear',
7
- 'ease',
8
- 'ease-in',
9
- 'ease-out',
10
- 'ease-in-out',
11
- 'step-start',
12
- 'step-end',
13
- ])
14
- const TIMING_FNS = ['cubic-bezier', 'steps']
15
-
16
- const COMMA = /\,(?![^(]*\))/g // Comma separator that is not located between brackets. E.g.: `cubiz-bezier(a, b, c)` these don't count.
17
- const SPACE = /\ +(?![^(]*\))/g // Similar to the one above, but with spaces instead.
18
- const TIME = /^(-?[\d.]+m?s)$/
19
- const DIGIT = /^(\d+)$/
20
-
21
- export default function parseAnimationValue(input) {
22
- let animations = input.split(COMMA)
23
- return animations.map((animation) => {
24
- let value = animation.trim()
25
- let result = { value }
26
- let parts = value.split(SPACE)
27
- let seen = new Set()
28
-
29
- for (let part of parts) {
30
- if (!seen.has('DIRECTIONS') && DIRECTIONS.has(part)) {
31
- result.direction = part
32
- seen.add('DIRECTIONS')
33
- } else if (!seen.has('PLAY_STATES') && PLAY_STATES.has(part)) {
34
- result.playState = part
35
- seen.add('PLAY_STATES')
36
- } else if (!seen.has('FILL_MODES') && FILL_MODES.has(part)) {
37
- result.fillMode = part
38
- seen.add('FILL_MODES')
39
- } else if (
40
- !seen.has('ITERATION_COUNTS') &&
41
- (ITERATION_COUNTS.has(part) || DIGIT.test(part))
42
- ) {
43
- result.iterationCount = part
44
- seen.add('ITERATION_COUNTS')
45
- } else if (!seen.has('TIMING_FUNCTION') && TIMINGS.has(part)) {
46
- result.timingFunction = part
47
- seen.add('TIMING_FUNCTION')
48
- } else if (!seen.has('TIMING_FUNCTION') && TIMING_FNS.some((f) => part.startsWith(`${f}(`))) {
49
- result.timingFunction = part
50
- seen.add('TIMING_FUNCTION')
51
- } else if (!seen.has('DURATION') && TIME.test(part)) {
52
- result.duration = part
53
- seen.add('DURATION')
54
- } else if (!seen.has('DELAY') && TIME.test(part)) {
55
- result.delay = part
56
- seen.add('DELAY')
57
- } else result.name = part
58
- }
59
-
60
- return result
61
- })
62
- }
@@ -1,45 +0,0 @@
1
- import isGlob from 'is-glob'
2
- import globParent from 'glob-parent'
3
- import path from 'path'
4
-
5
- // Based on `glob-base`
6
- // https://github.com/micromatch/glob-base/blob/master/index.js
7
- function parseGlob(pattern) {
8
- let glob = pattern
9
- let base = globParent(pattern)
10
-
11
- if (base !== '.') {
12
- glob = pattern.substr(base.length)
13
- if (glob.charAt(0) === '/') {
14
- glob = glob.substr(1)
15
- }
16
- }
17
-
18
- if (glob.substr(0, 2) === './') {
19
- glob = glob.substr(2)
20
- }
21
- if (glob.charAt(0) === '/') {
22
- glob = glob.substr(1)
23
- }
24
-
25
- return { base, glob }
26
- }
27
-
28
- export default function parseDependency(normalizedFileOrGlob) {
29
- let message
30
-
31
- if (isGlob(normalizedFileOrGlob)) {
32
- let { base, glob } = parseGlob(normalizedFileOrGlob)
33
- message = { type: 'dir-dependency', dir: path.resolve(base), glob }
34
- } else {
35
- message = { type: 'dependency', file: path.resolve(normalizedFileOrGlob) }
36
- }
37
-
38
- // rollup-plugin-postcss does not support dir-dependency messages
39
- // but directories can be watched in the same way as files
40
- if (message.type === 'dir-dependency' && process.env.ROLLUP_WATCH === 'true') {
41
- message = { type: 'dependency', file: message.dir }
42
- }
43
-
44
- return message
45
- }
@@ -1,19 +0,0 @@
1
- import postcss from 'postcss'
2
- import postcssNested from 'postcss-nested'
3
- import postcssJs from 'postcss-js'
4
-
5
- export default function parseObjectStyles(styles) {
6
- if (!Array.isArray(styles)) {
7
- return parseObjectStyles([styles])
8
- }
9
-
10
- return styles.flatMap((style) => {
11
- return postcss([
12
- postcssNested({
13
- bubble: ['screen'],
14
- }),
15
- ]).process(style, {
16
- parser: postcssJs,
17
- }).root.nodes
18
- })
19
- }
@@ -1,295 +0,0 @@
1
- import selectorParser from 'postcss-selector-parser'
2
- import escapeCommas from './escapeCommas'
3
- import { withAlphaValue } from './withAlphaVariable'
4
- import isKeyframeRule from './isKeyframeRule'
5
- import { parseColor } from './color'
6
-
7
- export function applyPseudoToMarker(selector, marker, state, join) {
8
- let states = [state]
9
-
10
- let markerIdx = selector.indexOf(marker + ':')
11
-
12
- if (markerIdx !== -1) {
13
- let existingMarker = selector.slice(markerIdx, selector.indexOf(' ', markerIdx))
14
-
15
- states = states.concat(
16
- selector.slice(markerIdx + marker.length + 1, existingMarker.length).split(':')
17
- )
18
-
19
- selector = selector.replace(existingMarker, '')
20
- }
21
-
22
- return join(`${[marker, ...states].join(':')}`, selector)
23
- }
24
-
25
- export function updateAllClasses(selectors, updateClass) {
26
- let parser = selectorParser((selectors) => {
27
- selectors.walkClasses((sel) => {
28
- let updatedClass = updateClass(sel.value, {
29
- withPseudo(className, pseudo) {
30
- sel.parent.insertAfter(sel, selectorParser.pseudo({ value: `${pseudo}` }))
31
- return className
32
- },
33
- })
34
- sel.value = updatedClass
35
- if (sel.raws && sel.raws.value) {
36
- sel.raws.value = escapeCommas(sel.raws.value)
37
- }
38
- })
39
- })
40
-
41
- let result = parser.processSync(selectors)
42
-
43
- return result
44
- }
45
-
46
- export function updateLastClasses(selectors, updateClass) {
47
- let parser = selectorParser((selectors) => {
48
- selectors.each((sel) => {
49
- let lastClass = sel.filter(({ type }) => type === 'class').pop()
50
-
51
- if (lastClass === undefined) {
52
- return
53
- }
54
-
55
- let updatedClass = updateClass(lastClass.value, {
56
- withPseudo(className, pseudo) {
57
- lastClass.parent.insertAfter(lastClass, selectorParser.pseudo({ value: `${pseudo}` }))
58
- return className
59
- },
60
- })
61
- lastClass.value = updatedClass
62
- if (lastClass.raws && lastClass.raws.value) {
63
- lastClass.raws.value = escapeCommas(lastClass.raws.value)
64
- }
65
- })
66
- })
67
- let result = parser.processSync(selectors)
68
-
69
- return result
70
- }
71
-
72
- function splitByNotEscapedCommas(str) {
73
- let chunks = []
74
- let currentChunk = ''
75
- for (let i = 0; i < str.length; i++) {
76
- if (str[i] === ',' && str[i - 1] !== '\\') {
77
- chunks.push(currentChunk)
78
- currentChunk = ''
79
- } else {
80
- currentChunk += str[i]
81
- }
82
- }
83
- chunks.push(currentChunk)
84
- return chunks
85
- }
86
-
87
- export function transformAllSelectors(transformSelector, { wrap, withRule } = {}) {
88
- return ({ container }) => {
89
- container.walkRules((rule) => {
90
- if (isKeyframeRule(rule)) {
91
- return rule
92
- }
93
- let transformed = splitByNotEscapedCommas(rule.selector).map(transformSelector).join(',')
94
- rule.selector = transformed
95
- if (withRule) {
96
- withRule(rule)
97
- }
98
- return rule
99
- })
100
-
101
- if (wrap) {
102
- let wrapper = wrap()
103
- let nodes = container.nodes
104
- container.removeAll()
105
- wrapper.append(nodes)
106
- container.append(wrapper)
107
- }
108
- }
109
- }
110
-
111
- export function transformAllClasses(transformClass, { wrap, withRule } = {}) {
112
- return ({ container }) => {
113
- container.walkRules((rule) => {
114
- let selector = rule.selector
115
- let variantSelector = updateAllClasses(selector, transformClass)
116
- rule.selector = variantSelector
117
- if (withRule) {
118
- withRule(rule)
119
- }
120
- return rule
121
- })
122
-
123
- if (wrap) {
124
- let wrapper = wrap()
125
- let nodes = container.nodes
126
- container.removeAll()
127
- wrapper.append(nodes)
128
- container.append(wrapper)
129
- }
130
- }
131
- }
132
-
133
- export function transformLastClasses(transformClass, { wrap, withRule } = {}) {
134
- return ({ container }) => {
135
- container.walkRules((rule) => {
136
- let selector = rule.selector
137
- let variantSelector = updateLastClasses(selector, transformClass)
138
- rule.selector = variantSelector
139
- if (withRule) {
140
- withRule(rule)
141
- }
142
- return rule
143
- })
144
-
145
- if (wrap) {
146
- let wrapper = wrap()
147
- let nodes = container.nodes
148
- container.removeAll()
149
- wrapper.append(nodes)
150
- container.append(wrapper)
151
- }
152
- }
153
- }
154
-
155
- export function asValue(modifier, lookup = {}, { validate = () => true } = {}) {
156
- let value = lookup[modifier]
157
-
158
- if (value !== undefined) {
159
- return value
160
- }
161
-
162
- if (modifier[0] !== '[' || modifier[modifier.length - 1] !== ']') {
163
- return undefined
164
- }
165
-
166
- value = modifier.slice(1, -1)
167
-
168
- if (!validate(value)) {
169
- return undefined
170
- }
171
-
172
- // convert `_` to ` `, escept for escaped underscores `\_`
173
- value = value
174
- .replace(/([^\\])_/g, '$1 ')
175
- .replace(/^_/g, ' ')
176
- .replace(/\\_/g, '_')
177
-
178
- // add spaces around operators inside calc() that do not follow an operator or (
179
- return value.replace(
180
- /(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g,
181
- '$1 $2 '
182
- )
183
- }
184
-
185
- export function asUnit(modifier, units, lookup = {}) {
186
- return asValue(modifier, lookup, {
187
- validate: (value) => {
188
- let unitsPattern = `(?:${units.join('|')})`
189
- return (
190
- new RegExp(`${unitsPattern}$`).test(value) ||
191
- new RegExp(`^calc\\(.+?${unitsPattern}`).test(value)
192
- )
193
- },
194
- })
195
- }
196
-
197
- function isArbitraryValue(input) {
198
- return input.startsWith('[') && input.endsWith(']')
199
- }
200
-
201
- function splitAlpha(modifier) {
202
- let slashIdx = modifier.lastIndexOf('/')
203
-
204
- if (slashIdx === -1 || slashIdx === modifier.length - 1) {
205
- return [modifier]
206
- }
207
-
208
- return [modifier.slice(0, slashIdx), modifier.slice(slashIdx + 1)]
209
- }
210
-
211
- export function asColor(modifier, lookup = {}, tailwindConfig = {}) {
212
- if (lookup[modifier] !== undefined) {
213
- return lookup[modifier]
214
- }
215
-
216
- let [color, alpha] = splitAlpha(modifier)
217
-
218
- if (lookup[color] !== undefined) {
219
- if (isArbitraryValue(alpha)) {
220
- return withAlphaValue(lookup[color], alpha.slice(1, -1))
221
- }
222
-
223
- if (tailwindConfig.theme?.opacity?.[alpha] === undefined) {
224
- return undefined
225
- }
226
-
227
- return withAlphaValue(lookup[color], tailwindConfig.theme.opacity[alpha])
228
- }
229
-
230
- return asValue(modifier, lookup, {
231
- validate: (value) => parseColor(value) !== null,
232
- })
233
- }
234
-
235
- export function asAngle(modifier, lookup = {}) {
236
- return asUnit(modifier, ['deg', 'grad', 'rad', 'turn'], lookup)
237
- }
238
-
239
- export function asLength(modifier, lookup = {}) {
240
- return asUnit(
241
- modifier,
242
- [
243
- 'cm',
244
- 'mm',
245
- 'Q',
246
- 'in',
247
- 'pc',
248
- 'pt',
249
- 'px',
250
- 'em',
251
- 'ex',
252
- 'ch',
253
- 'rem',
254
- 'lh',
255
- 'vw',
256
- 'vh',
257
- 'vmin',
258
- 'vmax',
259
- '%',
260
- ],
261
- lookup
262
- )
263
- }
264
-
265
- export function asLookupValue(modifier, lookup = {}) {
266
- return lookup[modifier]
267
- }
268
-
269
- let typeMap = {
270
- any: asValue,
271
- color: asColor,
272
- angle: asAngle,
273
- length: asLength,
274
- lookup: asLookupValue,
275
- }
276
-
277
- function splitAtFirst(input, delim) {
278
- return (([first, ...rest]) => [first, rest.join(delim)])(input.split(delim))
279
- }
280
-
281
- export function coerceValue(type, modifier, values, tailwindConfig) {
282
- let [scaleType, arbitraryType = scaleType] = [].concat(type)
283
-
284
- if (isArbitraryValue(modifier)) {
285
- let [explicitType, value] = splitAtFirst(modifier.slice(1, -1), ':')
286
-
287
- if (value.length > 0 && Object.keys(typeMap).includes(explicitType)) {
288
- return [asValue(`[${value}]`, values, tailwindConfig), explicitType]
289
- }
290
-
291
- return [typeMap[arbitraryType](modifier, values, tailwindConfig), arbitraryType]
292
- }
293
-
294
- return [typeMap[scaleType](modifier, values, tailwindConfig), scaleType]
295
- }
@@ -1,15 +0,0 @@
1
- import parser from 'postcss-selector-parser'
2
- import { tap } from './tap'
3
-
4
- export default function (prefix, selector) {
5
- const getPrefix =
6
- typeof prefix === 'function' ? prefix : () => (prefix === undefined ? '' : prefix)
7
-
8
- return parser((selectors) => {
9
- selectors.walkClasses((classSelector) => {
10
- tap(classSelector.value, (baseClass) => {
11
- classSelector.value = `${getPrefix('.' + baseClass)}${baseClass}`
12
- })
13
- })
14
- }).processSync(selector)
15
- }