{"version":3,"file":"variants.cjs","sources":["../src/variants.ts"],"sourcesContent":["/**\n * @module @twind/preset-tailwind/variants\n */\n\nimport {\n  AutocompleteProvider,\n  VariantResolver,\n  Variant,\n  AutocompleteItem,\n  arbitrary,\n} from '@twind/core'\nimport type { TailwindTheme } from './types'\n\nimport { DEV } from 'distilt/env'\n\nimport { normalize, withAutocomplete } from '@twind/core'\n\n// indirection wrapper to remove autocomplete functions from production bundles\nfunction withAutocomplete$(\n  rule: VariantResolver<TailwindTheme>,\n  autocomplete: AutocompleteProvider<TailwindTheme> | false,\n): VariantResolver<TailwindTheme> {\n  if (DEV) {\n    return withAutocomplete(rule, autocomplete)\n  }\n\n  return rule\n}\n\nconst variants: Variant<TailwindTheme>[] = [\n  ['sticky', '@supports ((position: -webkit-sticky) or (position:sticky))'],\n  ['motion-reduce', '@media (prefers-reduced-motion:reduce)'],\n  ['motion-safe', '@media (prefers-reduced-motion:no-preference)'],\n  ['print', '@media print'],\n  ['(portrait|landscape)', ({ 1: $1 }) => `@media (orientation:${$1})`],\n  ['contrast-(more|less)', ({ 1: $1 }) => `@media (prefers-contrast:${$1})`],\n\n  ['(first-(letter|line)|placeholder|backdrop|before|after)', ({ 1: $1 }) => `&::${$1}`],\n  ['(marker|selection)', ({ 1: $1 }) => `& *::${$1},&::${$1}`],\n  ['file', '&::file-selector-button'],\n\n  ['(first|last|only)', ({ 1: $1 }) => `&:${$1}-child`],\n  ['even', '&:nth-child(2n)'],\n  ['odd', '&:nth-child(odd)'],\n\n  ['open', '&[open]'],\n\n  // All other pseudo classes are already supported by twind\n\n  [\n    '(aria|data)-',\n    withAutocomplete$(\n      ({ 1: $1 /* aria or data */, $$ /* everything after the dash */ }, context) =>\n        $$ &&\n        `&[${$1}-${\n          // aria-asc or data-checked -> from theme\n          context.theme($1, $$) ||\n          // aria-[...] or data-[...]\n          arbitrary($$, '', context) ||\n          // default handling\n          `${$$}=\"true\"`\n        }]`,\n      DEV &&\n        (({ 1: $1 }, { theme }) =>\n          [\n            ...new Set([\n              ...($1 == 'aria'\n                ? [\n                    'checked',\n                    'disabled',\n                    'expanded',\n                    'hidden',\n                    'pressed',\n                    'readonly',\n                    'required',\n                    'selected',\n                  ]\n                : []),\n              ...Object.keys(theme($1 as 'aria' | 'data') || {}),\n            ]),\n          ]\n            .map(\n              (key): AutocompleteItem => ({\n                suffix: key,\n                label: `&[${$1}-${theme($1, key) || `${key}=\"true\"`}]`,\n                theme: { section: $1, key },\n              }),\n            )\n            .concat([{ suffix: '[', label: `&[${$1}-…]` }])),\n    ),\n  ],\n\n  /* Styling based on parent and peer state */\n  // Groups classes like: group-focus and group-hover\n  // these need to add a marker selector with the pseudo class\n  // => '.group:focus .group-focus:selector'\n  [\n    '((group|peer)(~[^-[]+)?)(-\\\\[(.+)]|[-[].+?)(\\\\/.+)?',\n    withAutocomplete$(\n      ({ 2: type, 3: name = '', 4: $4, 5: $5 = '', 6: label = name }, { e, h, v }) => {\n        const selector = normalize($5) || ($4[0] == '[' ? $4 : (v($4.slice(1)) as string))\n\n        // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n        return `${(selector.includes('&') ? selector : '&' + selector).replace(\n          /&/g,\n          `:merge(.${e(h(type + label))})`,\n        )}${type[0] == 'p' ? '~' : ' '}&`\n      },\n      DEV &&\n        ((_, { variants }) =>\n          Object.entries(variants)\n            .filter(([, selector]) => /^&(\\[|:[^:])/.test(selector))\n            .flatMap(([variant, selector]): AutocompleteItem[] => [\n              {\n                prefix: 'group-',\n                suffix: variant,\n                label: `${selector.replace('&', '.group')} &`,\n                modifiers: [],\n              },\n              {\n                prefix: 'peer-',\n                suffix: variant,\n                label: `${selector.replace('&', '.peer')} &`,\n                modifiers: [],\n              },\n            ])),\n    ),\n  ],\n\n  // direction variants\n  [\n    '(ltr|rtl)',\n    withAutocomplete$(\n      ({ 1: $1 }) => `[dir=\"${$1}\"] &`,\n      DEV && (({ 1: $1 }) => [{ prefix: $1, suffix: '', label: `[dir=\"${$1}\"] &` }]),\n    ),\n  ],\n\n  [\n    'supports-',\n    withAutocomplete$(\n      ({ $$ /* everything after the dash */ }, context) => {\n        $$ &&= (context.theme('supports', $$) || arbitrary($$, '', context)) as string\n\n        if ($$) {\n          if (!$$.includes(':')) {\n            $$ += ':var(--tw)'\n          }\n\n          if (!/^\\w*\\s*\\(/.test($$)) {\n            $$ = `(${$$})`\n          }\n\n          // Chrome has a bug where `(condtion1)or(condition2)` is not valid\n          // But `(condition1) or (condition2)` is supported.\n          return `@supports ${$$.replace(/\\b(and|or|not)\\b/g, ' $1 ').trim()}`\n        }\n      },\n      DEV &&\n        ((_, { theme }) =>\n          Object.keys(theme('supports') || {})\n            .map(\n              (key): AutocompleteItem => ({\n                suffix: key,\n                theme: { section: 'supports', key },\n              }),\n            )\n            .concat([{ suffix: '[', label: `@supports …` }])),\n    ),\n  ],\n\n  [\n    'max-',\n    withAutocomplete$(\n      ({ $$ }, context) => {\n        $$ &&= (context.theme('screens', $$) || arbitrary($$, '', context)) as string\n        if (typeof $$ == 'string') {\n          return `@media not all and (min-width:${$$})`\n        }\n      },\n      DEV &&\n        ((_, { theme }) =>\n          Object.entries(theme('screens') || {})\n            .filter(([, value]) => typeof value == 'string')\n            .map(\n              ([key, value]): AutocompleteItem => ({\n                suffix: key,\n                label: `@media not all and (min-width:${value})`,\n                theme: { section: 'screens', key },\n              }),\n            )\n            .concat([{ suffix: '[', label: `@media not all and (min-width: …)` }])),\n    ),\n  ],\n\n  [\n    'min-',\n    withAutocomplete$(({ $$ }, context) => {\n      $$ &&= arbitrary($$, '', context) as string\n      return $$ && `@media (min-width:${$$})`\n    }, DEV && (() => [{ suffix: '[', label: `@media (min-width: …)` }])),\n  ],\n\n  // Arbitrary variants\n  [/^\\[(.+)]$/, ({ 1: $1 }) => /[&@]/.test($1) && normalize($1).replace(/[}]+$/, '').split('{')],\n]\n\nexport default variants\n"],"names":["variants","$1","$$","context","theme","arbitrary","type","name","$4","$5","label","e","h","v","selector","normalize","slice","includes","replace","test","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