{"version":3,"file":"tailwind-preset.config.mjs","names":[],"sources":["../../src/tailwind-preset.config.js"],"sourcesContent":["/*!\n *\n *  Copyright (c) \"Neo4j\"\n *  Neo4j Sweden AB [http://neo4j.com]\n *\n *  This file is part of Neo4j.\n *\n *  Neo4j is free software: you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation, either version 3 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\nimport { tailwindTheme } from './tailwindTheme.mjs';\nimport { tokens } from './tokens/js/tokens-esm';\n\nfunction escapeRegex(value) {\n  return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\n/**\n * The `dark`/`light` theme scopes and the semantic prefixes (`neutral`,\n * `primary`, `danger`, ...). Because `neutral` is also a palette, the\n * `neutral-*` palette shades are included too.\n */\nconst SEMANTIC_COLOR_GROUPS = `(${[\n  'dark',\n  'light',\n  ...Object.keys(tokens.theme.light.color),\n]\n  .map(escapeRegex)\n  .join('|')})`;\n\n/**\n * Builds the safelist that keeps every semantic color utility\n * (`text-*`, `bg-*`, `border-*` and their `hover:`/`active:` variants)\n * in the generated CSS, regardless of whether a scanned source file uses it.\n *\n * The safelist is only needed when you build color class names dynamically\n * (for example `` `bg-${color}` ``), which Tailwind can't find by scanning.\n * Needle's own components ship prebuilt CSS and don't depend on it.\n *\n * The patterns are matched against the final class name, so they need to\n * include whatever `prefix` the consuming Tailwind config sets. The preset\n * ships without a prefix; pass your own prefix if you override it:\n *\n * ```js\n * const { tailwindConfig, createTailwindSafelist } = require('@neo4j-ndl/base');\n * module.exports = {\n *   presets: [tailwindConfig],\n *   prefix: 'tw-',\n *   safelist: createTailwindSafelist('tw-'),\n * };\n * ```\n *\n * @param {string} [prefix=''] - The Tailwind `prefix` option in use.\n * @returns {import('tailwindcss').Config['safelist']}\n */\nexport function createTailwindSafelist(prefix = '') {\n  const escapedPrefix = escapeRegex(prefix);\n  return [\n    {\n      pattern: new RegExp(\n        `^(hover:)?${escapedPrefix}text-${SEMANTIC_COLOR_GROUPS}-`,\n      ),\n      variants: ['hover'],\n    },\n    {\n      pattern: new RegExp(\n        `^(hover:)?${escapedPrefix}bg-${SEMANTIC_COLOR_GROUPS}-`,\n      ),\n      variants: ['hover'],\n    },\n    {\n      // For clicked classes\n      pattern: new RegExp(\n        `^(active:)?${escapedPrefix}bg-${SEMANTIC_COLOR_GROUPS}-`,\n      ),\n      variants: ['active'],\n    },\n    {\n      pattern: new RegExp(\n        `^(hover:)?${escapedPrefix}border-${SEMANTIC_COLOR_GROUPS}-`,\n      ),\n      variants: ['hover'],\n    },\n  ];\n}\n\n/** Flattened color keys, the way Tailwind names them (`baltic-40`, `light-neutral-bg-weak`). */\nfunction flattenColorKeys(colors, path = []) {\n  return Object.entries(colors).flatMap(([key, value]) => {\n    const nextPath = key === 'DEFAULT' ? path : [...path, key];\n    return typeof value === 'object' && value !== null\n      ? flattenColorKeys(value, nextPath)\n      : [nextPath.join('-')];\n  });\n}\n\n/**\n * The Tailwind CSS v4 counterpart of `createTailwindSafelist()`. Tailwind v4\n * has no `safelist` option, so this returns `@source inline()` rules that keep\n * the same semantic color utilities (`bg-*` with `hover:`/`active:`, `text-*`\n * and `border-*` with `hover:`) in your CSS.\n *\n * `@neo4j-ndl/base/lib/tailwind/safelist.css` is this output without a\n * prefix. If you import Tailwind with `prefix(...)`, write the output for your\n * prefix to a CSS file at build time and import that instead:\n *\n * ```js\n * // scripts/needle-safelist.mjs, run before your build\n * import { writeFileSync } from 'node:fs';\n * import { createTailwindV4Safelist } from '@neo4j-ndl/base';\n * writeFileSync('src/needle-safelist.css', createTailwindV4Safelist('tw'));\n * ```\n *\n * ```css\n * @import 'tailwindcss/theme.css' layer(theme) prefix(tw);\n * ...\n * @import './needle-safelist.css';\n * ```\n *\n * @param {string} [prefix=''] - The name passed to Tailwind's `prefix()`, for\n * example `tw` for `prefix(tw)`. Tailwind v4 only accepts lowercase letters.\n * @returns {string} One `@source inline()` rule per line.\n */\nexport function createTailwindV4Safelist(prefix = '') {\n  if (prefix !== '' && !/^[a-z]+$/.test(prefix)) {\n    throw new Error(\n      `Tailwind v4 prefixes may only contain lowercase letters, got \"${prefix}\"`,\n    );\n  }\n  const classPrefix = prefix === '' ? '' : `${prefix}:`;\n  const colorKeys = flattenColorKeys(tailwindTheme.colors);\n  const rules = ['dark', 'light', ...Object.keys(tokens.theme.light.color)]\n    .flatMap((group) => {\n      const shades = colorKeys\n        .filter((key) => key.startsWith(`${group}-`))\n        .map((key) => key.slice(group.length + 1));\n      if (shades.length === 0) {\n        return [];\n      }\n      const colorExpansion = `${group}-{${shades.join(',')}}`;\n      return ['{hover:,active:,}bg-', '{hover:,}text-', '{hover:,}border-'].map(\n        (utility) =>\n          `@source inline(\"${classPrefix}${utility}${colorExpansion}\");`,\n      );\n    })\n    .join('\\n');\n  return `${rules}\\n`;\n}\n\n/**\n * Tailwind CSS Configuration\n * containing all configurations we need\n * for our components\n *\n * The preset does not set a `prefix`, so utilities are generated with\n * their plain Tailwind names (`flex`, `text-neutral-text-weak`, ...).\n * Consumers who still want a prefix can set `prefix` in their own config\n * and pair it with `createTailwindSafelist(prefix)`.\n *\n * The preset does not set `content` either: which files to scan depends on\n * the consuming app, so set it in your own config.\n */\n/** @type {Omit<import('tailwindcss').Config, 'content'>} */\nexport const tailwindConfig = {\n  // remove classes like `text-opacity` but leave all color utilities\n  // eventually we should generate components in a more\n  // \"tailwind\" way to avoid safelisting like below\n  safelist: createTailwindSafelist(),\n  theme: {\n    ...tailwindTheme,\n    extend: {\n      colors: {\n        transparent: 'transparent',\n        current: 'currentColor',\n        inherit: 'inherit',\n      },\n      zIndex: {\n        ...tokens.zIndex,\n      },\n      spacing: {\n        // Use spacing tokens, but avoid overriding Tailwind's default spacing\n        // as many products will break\n        ...Object.keys(tokens.space).reduce(\n          (accumulator, currentValue) => ({\n            ...accumulator,\n            [`token-${currentValue}`]: tokens.space[currentValue],\n          }),\n          {},\n        ),\n        0: '0px',\n        px: '1px',\n        0.5: '2px',\n        1: '4px',\n        1.5: '6px',\n        2: '8px',\n        2.5: '10px',\n        3: '12px',\n        3.5: '14px',\n        4: '16px',\n        5: '20px',\n        6: '24px',\n        7: '28px',\n        8: '32px',\n        9: '36px',\n        10: '40px',\n        11: '44px',\n        12: '48px',\n        14: '56px',\n        16: '64px',\n        // TODO v6: should be 80px to follow the 4px scale (and match the v4 theme).\n        // Fixing it changes every `*-20` utility for consumers, so it waits for a major.\n        20: '20px',\n        24: '96px',\n        28: '112px',\n        32: '128px',\n        36: '144px',\n        40: '160px',\n        44: '176px',\n        48: '192px',\n        52: '208px',\n        56: '224px',\n        60: '240px',\n        64: '256px',\n        72: '288px',\n        80: '320px',\n        96: '384px',\n      },\n    },\n  },\n  // Enable only necessary plugins\n  // https://tailwindcss.com/docs/configuration#core-plugins\n  plugins: [\n    function ({ addUtilities }) {\n      // Complete transition utilities\n      const motionTransitions = {\n        '.transition-quick': {\n          transition: tokens.motion.transition.quick,\n        },\n        '.transition-slow': {\n          transition: tokens.motion.transition.slow,\n        },\n        '.transition-delayed': {\n          transition: tokens.motion.transition.delayed,\n        },\n      };\n\n      // Individual duration utilities\n      const durationUtilities = {\n        '.duration-quick': {\n          transitionDuration: tokens.motion.duration.quick,\n        },\n        '.duration-slow': {\n          transitionDuration: tokens.motion.duration.slow,\n        },\n      };\n\n      // Individual easing utilities\n      const easingUtilities = {\n        '.ease-standard': {\n          transitionTimingFunction: tokens.motion.easing.standard,\n        },\n      };\n\n      addUtilities({\n        ...motionTransitions,\n        ...durationUtilities,\n        ...easingUtilities,\n      });\n    },\n  ],\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAS,Y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