@charcoal-ui/tailwind-config 1.0.1-alpha.1 → 1.0.1-alpha.2
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.
- package/README.md +10 -0
- package/dist/_lib/compat.d.ts +14 -0
- package/dist/_lib/compat.d.ts.map +1 -0
- package/dist/docs/borderRadius/BorderRadius.d.ts +3 -0
- package/dist/docs/borderRadius/BorderRadius.d.ts.map +1 -0
- package/dist/docs/borderRadius/index.d.ts +3 -0
- package/dist/docs/borderRadius/index.d.ts.map +1 -0
- package/dist/docs/colors/Colors.d.ts +3 -0
- package/dist/docs/colors/Colors.d.ts.map +1 -0
- package/dist/docs/colors/TextBgColor.story.d.ts +27 -0
- package/dist/docs/colors/TextBgColor.story.d.ts.map +1 -0
- package/dist/docs/colors/TextColors.d.ts +3 -0
- package/dist/docs/colors/TextColors.d.ts.map +1 -0
- package/dist/docs/colors/index.d.ts +4 -0
- package/dist/docs/colors/index.d.ts.map +1 -0
- package/dist/docs/gradient/Gradients.d.ts +3 -0
- package/dist/docs/gradient/Gradients.d.ts.map +1 -0
- package/dist/docs/gradient/index.d.ts +10 -0
- package/dist/docs/gradient/index.d.ts.map +1 -0
- package/dist/docs/gradient/utils.d.ts +2 -0
- package/dist/docs/gradient/utils.d.ts.map +1 -0
- package/dist/docs/index.d.ts +9 -0
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/screens/Screens.d.ts +3 -0
- package/dist/docs/screens/Screens.d.ts.map +1 -0
- package/dist/docs/screens/index.d.ts +3 -0
- package/dist/docs/screens/index.d.ts.map +1 -0
- package/dist/docs/spacing/Spacing.d.ts +3 -0
- package/dist/docs/spacing/Spacing.d.ts.map +1 -0
- package/dist/docs/spacing/index.d.ts +3 -0
- package/dist/docs/spacing/index.d.ts.map +1 -0
- package/dist/docs/typography/HalfLeading.d.ts +3 -0
- package/dist/docs/typography/HalfLeading.d.ts.map +1 -0
- package/dist/docs/typography/Sizes.d.ts +3 -0
- package/dist/docs/typography/Sizes.d.ts.map +1 -0
- package/dist/docs/typography/index.d.ts +9 -0
- package/dist/docs/typography/index.d.ts.map +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/util.d.ts +32 -0
- package/dist/util.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/_lib/compat.ts +12 -0
- package/src/docs/borderRadius/BorderRadius.tsx +27 -0
- package/src/docs/borderRadius/index.story.mdx +10 -0
- package/src/docs/borderRadius/index.ts +5 -0
- package/src/docs/colors/Colors.tsx +85 -0
- package/src/docs/colors/TextBgColor.story.tsx +41 -0
- package/src/docs/colors/TextColors.tsx +22 -0
- package/src/docs/colors/index.story.mdx +27 -0
- package/src/docs/colors/index.ts +6 -0
- package/src/docs/gradient/Gradients.tsx +67 -0
- package/src/docs/gradient/index.story.mdx +12 -0
- package/src/docs/gradient/index.ts +26 -0
- package/src/docs/gradient/utils.ts +37 -0
- package/src/docs/index.ts +34 -0
- package/src/docs/screens/Screens.tsx +21 -0
- package/src/docs/screens/index.story.mdx +10 -0
- package/src/docs/screens/index.ts +5 -0
- package/src/docs/spacing/Spacing.tsx +17 -0
- package/src/docs/spacing/index.story.mdx +10 -0
- package/src/docs/spacing/index.ts +5 -0
- package/src/docs/typography/HalfLeading.tsx +28 -0
- package/src/docs/typography/Sizes.tsx +22 -0
- package/src/docs/typography/index.story.mdx +26 -0
- package/src/docs/typography/index.ts +26 -0
- package/src/util.ts +32 -0
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.module.js","sources":["../src/foundation.ts","../src/util.ts","../src/colors/utils.ts","../src/colors/toTailwindConfig.ts","../src/colors/plugin.ts","../src/gradient/plugin.ts","../src/typography/plugin.ts","../src/index.ts"],"sourcesContent":["import { Effect } from '@charcoal-ui/foundation'\nimport { CharcoalTheme as Theme } from '@charcoal-ui/theme'\n\nexport const GRID_COUNT = 12\n\nexport function mergeEffect({\n elementEffect,\n effect,\n}: Pick<Theme, 'elementEffect' | 'effect'>): MergedEffect {\n return {\n ...elementEffect,\n ...effect,\n outline: {\n type: 'opacity',\n opacity: 0.32,\n } as Effect,\n }\n}\n\nexport type MergedEffect = Record<string, Effect>\n","import { TailwindConfig } from 'tailwindcss/tailwind-config'\nimport { TailwindVersion, ThemeMap } from './types'\n\n/**\n * the key \"default\" or \"DEFAULT\" has special meaning and dropped from class name\n *\n * @see https://tailwindcss.com/docs/upgrading-to-v2#update-default-theme-keys-to-default\n */\nexport function getDefaultKeyName(version: TailwindVersion) {\n switch (version) {\n case 'v3':\n case 'v2': {\n return 'DEFAULT'\n }\n\n case 'v1': {\n return 'default'\n }\n }\n}\n\nexport function getVariantOption(\n version: TailwindVersion\n): Partial<TailwindConfig> {\n switch (version) {\n case 'v3': {\n // v3 以上では variants は variantOrders に改名された\n // そしてこれは上書きをしたいモチベがない\n // https://v2.tailwindcss.com/docs/configuration#variant-order\n return {}\n }\n\n case 'v2':\n case 'v1': {\n return { variants: {} }\n }\n }\n}\n\nfunction setEquals<T>(a: Set<T>, b: Set<T>) {\n return a.size === b.size && Array.from(a).every((value) => b.has(value))\n}\n\nexport function assertAllThemeHaveSameKeys(themeMap: ThemeMap): void {\n const defaultTheme = themeMap[':root']\n const expectedColorKeys = new Set(Object.keys(defaultTheme.color))\n const expectedEffectKeys = new Set(Object.keys(defaultTheme.effect))\n\n for (const [name, theme] of Object.entries(themeMap)) {\n const colorKeys = new Set(Object.keys(theme.color))\n const effectKeys = new Set(Object.keys(theme.effect))\n\n if (!setEquals(colorKeys, expectedColorKeys)) {\n throw new Error(`:root and ${name} does not have same colors.\n\nExpected( :root ): ${JSON.stringify(Array.from(expectedColorKeys))}\nGot: ${JSON.stringify(Array.from(colorKeys))}`)\n }\n\n if (!setEquals(effectKeys, expectedEffectKeys)) {\n throw new Error(`:root and ${name} does not have same effects.\n\nExpected( :root ): ${JSON.stringify(Array.from(expectedEffectKeys))}\nGot: ${JSON.stringify(Array.from(effectKeys))}`)\n }\n }\n}\n\nexport function mapKeys<V, K extends string>(\n object: Record<string, V>,\n callback: (key: string) => K\n) {\n return Object.fromEntries(\n Object.entries(object).map(([key, value]) => [callback(key), value])\n ) as Record<K, V>\n}\n\nexport function mapObject<\n SourceKey extends string,\n SourceValue,\n DestKey extends string,\n DestValue\n>(\n source: Record<SourceKey, SourceValue>,\n callback: (\n key: SourceKey,\n value: SourceValue\n ) => [DestKey, DestValue] | null | undefined\n) {\n return Object.fromEntries(\n Object.entries(source).flatMap(([key, value]) => {\n const entry = callback(key as SourceKey, value as SourceValue)\n if (entry) {\n return [entry]\n } else {\n return []\n }\n })\n ) as Record<DestKey, DestValue>\n}\n\nexport function flatMapObject<\n SourceKey extends string,\n SourceValue,\n DestKey extends string,\n DestValue\n>(\n source: Record<SourceKey, SourceValue>,\n callback: (key: SourceKey, value: SourceValue) => [DestKey, DestValue][]\n) {\n return Object.fromEntries(\n Object.entries(source).flatMap(([key, value]) => {\n return callback(key as SourceKey, value as SourceValue)\n })\n ) as Record<DestKey, DestValue>\n}\n\nexport function filterObject<Source, Dest extends Source>(\n source: Record<string, Source>,\n fn: (value: Source) => value is Dest\n) {\n return mapObject(source, (key, value) => {\n if (fn(value) === true) {\n return [key, value]\n } else {\n return null\n }\n }) as Record<string, Dest>\n}\n\nexport function camelToKebab(value: string) {\n return value\n .replace(/(?<small>[\\da-z]|(?=[A-Z]))(?<capital>[A-Z])/gu, '$1-$2')\n .toLowerCase()\n}\n","import { GradientMaterial, Material } from '@charcoal-ui/foundation'\n\nexport const COLOR_PREFIX = '--tailwind-color-'\n\nexport function isSingleColor(color: AnyColor): color is Material {\n return typeof color === 'string'\n}\n\ntype AnyColor = Material | GradientMaterial\n\nexport type AnyColorTheme = Record<string, AnyColor>\n","import { Material } from '@charcoal-ui/foundation'\nimport { applyEffect } from '@charcoal-ui/utils'\nimport { TailwindConfig } from 'tailwindcss/tailwind-config'\nimport { MergedEffect } from '../foundation'\n\nimport { TailwindVersion } from '../types'\nimport { filterObject, getDefaultKeyName, mapObject } from '../util'\nimport { AnyColorTheme, COLOR_PREFIX, isSingleColor } from './utils'\n\nexport function colorsToTailwindConfig(\n version: TailwindVersion,\n colors: AnyColorTheme,\n effects: MergedEffect\n): TailwindConfig['theme']['colors'] {\n const targetColors = filterObject(colors, isSingleColor)\n const DEFAULT = getDefaultKeyName(version)\n\n /**\n * こういう感じのを吐き出す\n *\n * ```js\n * {\n * DEFAULT: 'var(--tailwind-color-hoge1, #fff)',\n * hover: 'var(--tailwind-color-hoge1--hover, #eee)',\n * press: 'var(--tailwind-color-hoge1--press, #ddd)',\n * disabled: 'var(--tailwind-color-hoge1--disabled, #eee)',\n * }\n * ```\n */\n function colorsForAllEffects(name: string, color: Material) {\n const varName = `${COLOR_PREFIX}${name}`\n\n return {\n [DEFAULT]: `var(${varName}, ${color})`,\n\n ...mapObject(effects, (effectName, effect) => [\n effectName,\n `var(${varName}--${effectName}, ${applyEffect(color, effect)})`,\n ]),\n }\n }\n\n return mapObject(targetColors, (name, color) => [\n name,\n colorsForAllEffects(name, color),\n ])\n}\n","import { Material } from '@charcoal-ui/foundation'\nimport { CharcoalTheme as Theme } from '@charcoal-ui/theme'\nimport { applyEffect } from '@charcoal-ui/utils'\nimport plugin, { TailwindPlugin } from 'tailwindcss/plugin'\nimport { mergeEffect } from '../foundation'\nimport { CSSVariableName, CSSVariables, Definition, ThemeMap } from '../types'\nimport { filterObject, flatMapObject, mapObject } from '../util'\nimport { COLOR_PREFIX, isSingleColor } from './utils'\n\n/**\n * `:root` 以外のケースで各 CSS Variable がどういう値を取るかを定義する\n */\nexport default function cssVariableColorPlugin({\n ':root': _defaultTheme,\n ...themes\n}: ThemeMap): TailwindPlugin {\n const definitions = defineCssVariables(themes)\n\n return plugin(({ addBase }) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n addBase(definitions)\n })\n}\n\nexport function defineCssVariables(themes: Omit<ThemeMap, ':root'>) {\n return mapObject(themes, (selectorOrMediaQuery, theme) => {\n const css = toCssVariables(theme)\n\n if (selectorOrMediaQuery.startsWith('@media')) {\n return [\n selectorOrMediaQuery,\n {\n ':root': css,\n },\n ]\n } else {\n return [selectorOrMediaQuery, css]\n }\n }) as Definition\n}\n\nfunction toCssVariables(theme: Theme): CSSVariables {\n const colors = filterObject(theme.color, isSingleColor)\n const effects = Object.entries(mergeEffect(theme))\n\n return flatMapObject(colors, (name, color) => {\n const varName: keyof CSSVariables = `${COLOR_PREFIX}${name}`\n\n return [\n [varName, color],\n\n ...effects.map<[CSSVariableName, Material]>(([type, effect]) => [\n `${varName}--${type}`,\n applyEffect(color, effect),\n ]),\n ]\n })\n}\n","import plugin from 'tailwindcss/plugin'\nimport { camelToKebab, flatMapObject, mapKeys, mapObject } from '../util'\nimport { GradientMaterial } from '@charcoal-ui/foundation'\nimport { ThemeColorGradient } from '@charcoal-ui/theme'\nimport {\n applyEffectToGradient,\n gradient,\n GradientDirection,\n} from '@charcoal-ui/utils'\nimport { Values } from '../types'\nimport { MergedEffect } from '../foundation'\n\nconst VAR_PREFIX = '--tailwind-gradient-'\n\nexport default function cssVariableColorPlugin(\n gradients: ThemeColorGradient,\n effects: MergedEffect,\n selectorOrMediaQuery: string\n) {\n const utilities = getUtilities(gradients, effects)\n\n const classRules = mapObject(utilities, (name) => [\n `.bg-${name}`,\n { backgroundImage: `var(${VAR_PREFIX}${name})` },\n ])\n\n return plugin(({ addBase, addUtilities }) => {\n const css = mapKeys(utilities, (name) => `${VAR_PREFIX}${name}`)\n if (selectorOrMediaQuery.startsWith('@media')) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n addBase({\n [selectorOrMediaQuery]: {\n ':root': css,\n },\n })\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n addBase({\n [selectorOrMediaQuery]: css,\n })\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n addUtilities(classRules, {\n variants: ['responsive'],\n })\n })\n}\n\nconst DIRECTIONS = {\n 'to top': 'top',\n 'to bottom': 'bottom',\n 'to left': 'left',\n 'to right': 'right',\n} as const\n\n/**\n * こういう感じのやつ。この時点では `--tailwind-gradient-` のような CSS 変数名になってない\n *\n * ```js\n * {\n * 'hoge1': 'linear-gradient(to top, ...)',\n * ...\n * }\n * ```\n */\ntype Utilities = Record<string, LinearGradient>\n\ntype LinearGradient = `linear-gradient(${string})`\n\nexport function getUtilities(\n gradients: Record<string, GradientMaterial>,\n effect: MergedEffect\n): Utilities {\n const effects = Object.entries(effect)\n const directions = Object.entries(DIRECTIONS) as [\n GradientDirection,\n Values<typeof DIRECTIONS>\n ][]\n\n return flatMapObject(gradients, (name, colors) =>\n directions.flatMap(([direction, className]) => {\n const toLinearGradient = (colors: GradientMaterial) => {\n const style = gradient(direction)(colors)\n\n if (!('backgroundImage' in style)) {\n throw new Error(\n `Could not generate linear-gradient() from ${name} ${direction} ${className}`\n )\n }\n\n // 本当は backgroundColor も同時に生成されるんだけど、使うにはそれ用の CSS 変数も一緒に作らないといけない\n // とりあえず background-image だけで動くのでこっちだけを利用する\n return style.backgroundImage as LinearGradient\n }\n\n return [\n // こういう感じのやつ\n // { 'hoge1': 'linear-gradienr(to top, ...)' }\n [createUtilityName(name, className), toLinearGradient(colors)],\n\n // こういう感じのやつ\n // { 'hoge1--hover': 'linear-gradienr(to top, ...)' }\n ...effects.map<[string, LinearGradient]>(([effectName, effect]) => [\n createUtilityName(name, className, effectName),\n toLinearGradient(applyEffectToGradient(effect)(colors)),\n ]),\n ]\n })\n )\n}\n\nfunction createUtilityName(\n gradientName: string,\n direction: Values<typeof DIRECTIONS>,\n suffix = ''\n) {\n return [camelToKebab(gradientName), direction, suffix]\n .filter(Boolean)\n .join('-')\n}\n","import plugin from 'tailwindcss/plugin'\nimport { TypographyDescriptor, TYPOGRAPHY_SIZE } from '@charcoal-ui/foundation'\nimport { halfLeading } from '@charcoal-ui/utils'\nimport { px } from '@charcoal-ui/utils'\nimport { mapObject } from '../util'\n\nconst leadingCancel = {\n display: 'block',\n width: 0,\n height: 0,\n content: '\"\"',\n}\n\nconst typographyStyle = (style: TypographyDescriptor) => {\n const margin = -halfLeading(style)\n\n return {\n 'font-size': px(style.fontSize),\n 'line-height': px(style.lineHeight),\n\n /**\n * cancel leading\n *\n * @see https://yuyakinoshita.com/blog/2020/01/20/line-height-crop/\n */\n '&::before': {\n ...leadingCancel,\n marginTop: px(margin),\n },\n '&::after': {\n ...leadingCancel,\n marginBottom: px(margin),\n },\n }\n}\n\nconst typographyPlugin = plugin(({ addUtilities }) => {\n const typographyClasses = mapObject(TYPOGRAPHY_SIZE, (fontSize, style) => [\n `.typography-${fontSize}`,\n typographyStyle(style),\n ])\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n addUtilities(\n {\n ...typographyClasses,\n '.preserve-half-leading': {\n '&::before': {\n content: 'none',\n },\n '&::after': {\n content: 'none',\n },\n },\n },\n {\n variants: ['responsive'],\n }\n )\n})\n\nexport default typographyPlugin\n","import { GRID_COUNT, mergeEffect } from './foundation'\n\nimport { TailwindConfig } from 'tailwindcss/tailwind-config'\nimport { TailwindVersion, ThemeMap } from './types'\n\nimport {\n assertAllThemeHaveSameKeys,\n getDefaultKeyName,\n getVariantOption,\n mapObject,\n} from './util'\nimport {\n COLUMN_UNIT,\n GUTTER_UNIT,\n SPACING,\n BORDER_RADIUS,\n} from '@charcoal-ui/foundation'\nimport { light } from '@charcoal-ui/theme'\nimport { px } from '@charcoal-ui/utils'\nimport { colorsToTailwindConfig } from './colors/toTailwindConfig'\n\nimport cssVariableColorPlugin from './colors/plugin'\nimport cssVariableGradientPlugin from './gradient/plugin'\nimport typographyPlugin from './typography/plugin'\n\ninterface Options {\n version?: TailwindVersion\n theme?: ThemeMap\n}\n\nexport function createTailwindConfig({\n theme = { ':root': light },\n version = 'v3',\n}: Options): TailwindConfig {\n assertAllThemeHaveSameKeys(theme)\n\n const defaultTheme = theme[':root']\n const effects = mergeEffect(defaultTheme)\n const DEFAULT = getDefaultKeyName(version)\n\n return {\n theme: {\n screens: {\n screen1: px(0),\n screen2: px(defaultTheme.breakpoint.screen1),\n screen3: px(defaultTheme.breakpoint.screen2),\n screen4: px(defaultTheme.breakpoint.screen3),\n screen5: px(defaultTheme.breakpoint.screen4),\n },\n colors: {\n // @deprecated\n black: '#000',\n\n // @deprecated\n white: '#fff',\n\n transparent: 'transparent',\n current: 'currentColor',\n ...colorsToTailwindConfig(version, defaultTheme.color, effects),\n },\n borderColor: {\n ...colorsToTailwindConfig(\n version,\n mapObject(defaultTheme.border, (k, v) => [k, v.color]),\n effects\n ),\n },\n spacing: mapObject(SPACING, (name, pixel) => [name, px(pixel)]),\n width: {\n full: '100%',\n screen: '100vw',\n auto: 'auto',\n\n /**\n * generates classes like \"w-col-span-1\"\n */\n ...Array.from({ length: GRID_COUNT }, (_, i) => i + 1).reduce(\n (styles, i) => ({\n ...styles,\n [`col-span-${i}`]: px(COLUMN_UNIT * i + GUTTER_UNIT * (i - 1)),\n }),\n {}\n ),\n\n /**\n * generates classes like \"w-1/12\" (except for 12/12, which just equals to w-full)\n */\n ...Array.from({ length: GRID_COUNT - 1 }, (_, i) => i + 1).reduce(\n (styles, i) => ({\n ...styles,\n [`${i}/${GRID_COUNT}`]: `${(i / GRID_COUNT) * 100}%`,\n }),\n {}\n ),\n },\n gap: {\n fixed: px(GUTTER_UNIT),\n },\n borderRadius: mapObject(BORDER_RADIUS, (name, value) => [\n name,\n px(value),\n ]),\n transitionDuration: {\n [DEFAULT]: '0.2s',\n },\n },\n\n ...getVariantOption(version),\n\n corePlugins: {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error 配列にしろと言ってくるが、たぶん @types が間違っている\n lineHeight: false,\n },\n plugins: [\n typographyPlugin,\n cssVariableColorPlugin(theme),\n\n ...Object.entries(theme).map(([selectorOrMediaQuery, theme]) =>\n cssVariableGradientPlugin(\n theme.gradientColor,\n mergeEffect(theme),\n selectorOrMediaQuery\n )\n ),\n ],\n }\n}\n\nexport const config: TailwindConfig = createTailwindConfig({})\n"],"names":["mergeEffect","elementEffect","effect","outline","type","opacity","getDefaultKeyName","version","setEquals","a","b","size","Array","from","every","value","has","mapObject","source","callback","Object","fromEntries","entries","flatMap","entry","flatMapObject","filterObject","fn","key","isSingleColor","color","colorsToTailwindConfig","colors","effects","targetColors","DEFAULT","colorsForAllEffects","name","varName","effectName","applyEffect","cssVariableColorPlugin","_defaultTheme","definitions","selectorOrMediaQuery","theme","css","map","toCssVariables","startsWith","plugin","addBase","DIRECTIONS","createUtilityName","gradientName","direction","suffix","replace","toLowerCase","filter","Boolean","join","leadingCancel","display","width","height","content","typographyStyle","style","margin","halfLeading","px","fontSize","lineHeight","marginTop","marginBottom","typographyPlugin","addUtilities","TYPOGRAPHY_SIZE","variants","createTailwindConfig","light","themeMap","defaultTheme","expectedColorKeys","Set","keys","expectedEffectKeys","colorKeys","effectKeys","Error","JSON","stringify","assertAllThemeHaveSameKeys","screens","screen1","screen2","breakpoint","screen3","screen4","screen5","black","white","transparent","current","borderColor","border","k","v","spacing","SPACING","pixel","full","screen","auto","length","_","i","reduce","styles","COLUMN_UNIT","GUTTER_UNIT","GRID_COUNT","gap","fixed","borderRadius","BORDER_RADIUS","transitionDuration","getVariantOption","corePlugins","plugins","gradients","utilities","directions","className","toLinearGradient","gradient","backgroundImage","applyEffectToGradient","getUtilities","classRules","cssVariableGradientPlugin","gradientColor","config"],"mappings":"4sDAKgBA,KAId,cAHAC,gBACAC,QAKEC,QAAS,CACPC,KAAM,UACNC,QAAS,gBCNCC,EAAkBC,GAChC,OAAQA,GACN,IAAK,KACL,IAAK,KACH,MAAO,UAGT,IAAK,KACH,MAAO,WAuBb,SAASC,EAAaC,EAAWC,GAC/B,OAAOD,EAAEE,OAASD,EAAEC,MAAQC,MAAMC,KAAKJ,GAAGK,MAAM,SAACC,UAAUL,EAAEM,IAAID,cAqCnDE,EAMdC,EACAC,GAKA,OAAOC,OAAOC,YACZ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,SACEtD,EACAnC,EAAuBI,WAEpBzB,OAAOE,QAAQuB,GAAOE,IAAI,gBAAEH,OAAsBC,uBFvGzDsF,EACAlG,EACAW,GAEA,IAAMwF,WAoDND,EACAjI,GAEA,IAAM+B,EAAUb,OAAOE,QAAQpB,GACzBmI,EAAajH,OAAOE,QAAQ8B,GAKlC,OAAO3B,EAAc0G,EAAW,SAAC9F,EAAML,UACrCqG,EAAW9G,QAAQ,gBAAEgC,OAAW+E,OACxBC,EAAmB,SAACvG,GACxB,IAAMoC,EAAQoE,EAASjF,EAATiF,CAAoBxG,GAElC,KAAM,oBAAqBoC,GACzB,UAAUsB,mDACqCrD,MAAQkB,MAAa+E,GAMtE,OAAOlE,EAAMqE,iBAGf,OAGE,CAACpF,EAAkBhB,EAAMiG,GAAYC,EAAiBvG,YAInDC,EAAQc,IAA8B,gBAAc7C,aAAY,CACjEmD,EAAkBhB,EAAMiG,QACxBC,EAAiBG,EAAsBxI,EAAtBwI,CAA8B1G,YAtFrC2G,CAAaR,EAAWlG,GAEpC2G,EAAa3H,EAAUmH,EAAW,SAAC/F,SAAS,QACzCA,EACP,CAAEoG,2CAAqCpG,UAGzC,OAAOa,EAAO,gBJ4Cd/B,MI5CiBgC,IAAAA,QAAS0B,IAAAA,aAClB/B,GJ2CR3B,EI3CiC,SAACkB,SAfjB,uBAe0CA,GJ6CpDjB,OAAOC,YACZD,OAAOE,QI9Ca8G,GJ8CGrF,IAAI,gBAAOhC,aAAW,CAACI,QAAeJ,OI7CzD6B,EAAqBK,WAAW,UAElCE,UACGP,GAAuB,CACtB,QAASE,OAKbK,UACGP,GAAuBE,MAK5B+B,EAAa+D,EAAY,CACvB7D,SAAU,CAAC,kBE2ET8D,CACEhG,EAAMiG,cACN9I,EAAY6C,GACZD,QAOGmG,IAAAA,EAAyB/D,EAAqB"}
|
|
1
|
+
{"version":3,"file":"index.module.js","sources":["../src/foundation.ts","../src/util.ts","../src/colors/utils.ts","../src/colors/toTailwindConfig.ts","../src/colors/plugin.ts","../src/gradient/plugin.ts","../src/typography/plugin.ts","../src/index.ts"],"sourcesContent":["import { Effect } from '@charcoal-ui/foundation'\nimport { CharcoalTheme as Theme } from '@charcoal-ui/theme'\n\nexport const GRID_COUNT = 12\n\nexport function mergeEffect({\n elementEffect,\n effect,\n}: Pick<Theme, 'elementEffect' | 'effect'>): MergedEffect {\n return {\n ...elementEffect,\n ...effect,\n outline: {\n type: 'opacity',\n opacity: 0.32,\n } as Effect,\n }\n}\n\nexport type MergedEffect = Record<string, Effect>\n","import { TailwindConfig } from 'tailwindcss/tailwind-config'\nimport { TailwindVersion, ThemeMap } from './types'\n\n/**\n * the key \"default\" or \"DEFAULT\" has special meaning and dropped from class name\n *\n * @see https://tailwindcss.com/docs/upgrading-to-v2#update-default-theme-keys-to-default\n */\nexport function getDefaultKeyName(version: TailwindVersion) {\n switch (version) {\n case 'v3':\n case 'v2': {\n return 'DEFAULT'\n }\n\n case 'v1': {\n return 'default'\n }\n }\n}\n\nexport function getVariantOption(\n version: TailwindVersion\n): Partial<TailwindConfig> {\n switch (version) {\n case 'v3': {\n // v3 以上では variants は variantOrders に改名された\n // そしてこれは上書きをしたいモチベがない\n // https://v2.tailwindcss.com/docs/configuration#variant-order\n return {}\n }\n\n case 'v2':\n case 'v1': {\n return { variants: {} }\n }\n }\n}\n\nfunction setEquals<T>(a: Set<T>, b: Set<T>) {\n return a.size === b.size && Array.from(a).every((value) => b.has(value))\n}\n\nexport function assertAllThemeHaveSameKeys(themeMap: ThemeMap): void {\n const defaultTheme = themeMap[':root']\n const expectedColorKeys = new Set(Object.keys(defaultTheme.color))\n const expectedEffectKeys = new Set(Object.keys(defaultTheme.effect))\n\n for (const [name, theme] of Object.entries(themeMap)) {\n const colorKeys = new Set(Object.keys(theme.color))\n const effectKeys = new Set(Object.keys(theme.effect))\n\n if (!setEquals(colorKeys, expectedColorKeys)) {\n throw new Error(`:root and ${name} does not have same colors.\n\nExpected( :root ): ${JSON.stringify(Array.from(expectedColorKeys))}\nGot: ${JSON.stringify(Array.from(colorKeys))}`)\n }\n\n if (!setEquals(effectKeys, expectedEffectKeys)) {\n throw new Error(`:root and ${name} does not have same effects.\n\nExpected( :root ): ${JSON.stringify(Array.from(expectedEffectKeys))}\nGot: ${JSON.stringify(Array.from(effectKeys))}`)\n }\n }\n}\n\n/**\n * @example\n * ```js\n * mapKeys({ a: 'aa', b: 'bb' }, (key) => key.toUpperCase()) // => { A: \"aa\", B: \"bb\" }\n * ````\n */\nexport function mapKeys<V, K extends string>(\n object: Record<string, V>,\n callback: (key: string) => K\n) {\n return Object.fromEntries(\n Object.entries(object).map(([key, value]) => [callback(key), value])\n ) as Record<K, V>\n}\n\n/**\n * @example\n * ```js\n * mapObject({ a: 'aa', b: 'bb', c: 'cc' }, (key, value) =>\n * key === 'b' ? undefined : [key + '1', value.toUpperCase()]\n * ) // => { a1: \"AA\", c1: \"CC\" }\n * ```\n */\nexport function mapObject<\n SourceKey extends string,\n SourceValue,\n DestKey extends string,\n DestValue\n>(\n source: Record<SourceKey, SourceValue>,\n callback: (\n key: SourceKey,\n value: SourceValue\n ) => [DestKey, DestValue] | null | undefined\n) {\n return Object.fromEntries(\n Object.entries(source).flatMap(([key, value]) => {\n const entry = callback(key as SourceKey, value as SourceValue)\n if (entry) {\n return [entry]\n } else {\n return []\n }\n })\n ) as Record<DestKey, DestValue>\n}\n\n/**\n * @example\n * ```js\n * flatMapObject({ a: 'aa', b: 'bb' }, (key, value) => [\n * [key + '1', value + '1'],\n * [key + '2', value + '2'],\n * ]) // => { a1: \"aa1\", a2: \"aa2\", b1: \"bb1\", b2: \"bb2\" }\n * ```\n */\nexport function flatMapObject<\n SourceKey extends string,\n SourceValue,\n DestKey extends string,\n DestValue\n>(\n source: Record<SourceKey, SourceValue>,\n callback: (key: SourceKey, value: SourceValue) => [DestKey, DestValue][]\n) {\n return Object.fromEntries(\n Object.entries(source).flatMap(([key, value]) => {\n return callback(key as SourceKey, value as SourceValue)\n })\n ) as Record<DestKey, DestValue>\n}\n\n/**\n * @example\n * ```ts\n * filterObject(\n * { a: 'aa', b: 'bb', c: 'cc' },\n * (value): value is string => value !== 'bb'\n * ) // => { a: \"aa\", c: \"cc\" }\n * ```\n */\nexport function filterObject<Source, Dest extends Source>(\n source: Record<string, Source>,\n fn: (value: Source) => value is Dest\n) {\n return mapObject(source, (key, value) => {\n if (fn(value) === true) {\n return [key, value]\n } else {\n return null\n }\n }) as Record<string, Dest>\n}\n\nexport function camelToKebab(value: string) {\n return value\n .replace(/(?<small>[\\da-z]|(?=[A-Z]))(?<capital>[A-Z])/gu, '$1-$2')\n .toLowerCase()\n}\n","import { GradientMaterial, Material } from '@charcoal-ui/foundation'\n\nexport const COLOR_PREFIX = '--tailwind-color-'\n\nexport function isSingleColor(color: AnyColor): color is Material {\n return typeof color === 'string'\n}\n\ntype AnyColor = Material | GradientMaterial\n\nexport type AnyColorTheme = Record<string, AnyColor>\n","import { Material } from '@charcoal-ui/foundation'\nimport { applyEffect } from '@charcoal-ui/utils'\nimport { TailwindConfig } from 'tailwindcss/tailwind-config'\nimport { MergedEffect } from '../foundation'\n\nimport { TailwindVersion } from '../types'\nimport { filterObject, getDefaultKeyName, mapObject } from '../util'\nimport { AnyColorTheme, COLOR_PREFIX, isSingleColor } from './utils'\n\nexport function colorsToTailwindConfig(\n version: TailwindVersion,\n colors: AnyColorTheme,\n effects: MergedEffect\n): TailwindConfig['theme']['colors'] {\n const targetColors = filterObject(colors, isSingleColor)\n const DEFAULT = getDefaultKeyName(version)\n\n /**\n * こういう感じのを吐き出す\n *\n * ```js\n * {\n * DEFAULT: 'var(--tailwind-color-hoge1, #fff)',\n * hover: 'var(--tailwind-color-hoge1--hover, #eee)',\n * press: 'var(--tailwind-color-hoge1--press, #ddd)',\n * disabled: 'var(--tailwind-color-hoge1--disabled, #eee)',\n * }\n * ```\n */\n function colorsForAllEffects(name: string, color: Material) {\n const varName = `${COLOR_PREFIX}${name}`\n\n return {\n [DEFAULT]: `var(${varName}, ${color})`,\n\n ...mapObject(effects, (effectName, effect) => [\n effectName,\n `var(${varName}--${effectName}, ${applyEffect(color, effect)})`,\n ]),\n }\n }\n\n return mapObject(targetColors, (name, color) => [\n name,\n colorsForAllEffects(name, color),\n ])\n}\n","import { Material } from '@charcoal-ui/foundation'\nimport { CharcoalTheme as Theme } from '@charcoal-ui/theme'\nimport { applyEffect } from '@charcoal-ui/utils'\nimport plugin, { TailwindPlugin } from 'tailwindcss/plugin'\nimport { mergeEffect } from '../foundation'\nimport { CSSVariableName, CSSVariables, Definition, ThemeMap } from '../types'\nimport { filterObject, flatMapObject, mapObject } from '../util'\nimport { COLOR_PREFIX, isSingleColor } from './utils'\n\n/**\n * `:root` 以外のケースで各 CSS Variable がどういう値を取るかを定義する\n */\nexport default function cssVariableColorPlugin({\n ':root': _defaultTheme,\n ...themes\n}: ThemeMap): TailwindPlugin {\n const definitions = defineCssVariables(themes)\n\n return plugin(({ addBase }) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n addBase(definitions)\n })\n}\n\nexport function defineCssVariables(themes: Omit<ThemeMap, ':root'>) {\n return mapObject(themes, (selectorOrMediaQuery, theme) => {\n const css = toCssVariables(theme)\n\n if (selectorOrMediaQuery.startsWith('@media')) {\n return [\n selectorOrMediaQuery,\n {\n ':root': css,\n },\n ]\n } else {\n return [selectorOrMediaQuery, css]\n }\n }) as Definition\n}\n\nfunction toCssVariables(theme: Theme): CSSVariables {\n const colors = filterObject(theme.color, isSingleColor)\n const effects = Object.entries(mergeEffect(theme))\n\n return flatMapObject(colors, (name, color) => {\n const varName: keyof CSSVariables = `${COLOR_PREFIX}${name}`\n\n return [\n [varName, color],\n\n ...effects.map<[CSSVariableName, Material]>(([type, effect]) => [\n `${varName}--${type}`,\n applyEffect(color, effect),\n ]),\n ]\n })\n}\n","import plugin from 'tailwindcss/plugin'\nimport { camelToKebab, flatMapObject, mapKeys, mapObject } from '../util'\nimport { GradientMaterial } from '@charcoal-ui/foundation'\nimport { ThemeColorGradient } from '@charcoal-ui/theme'\nimport {\n applyEffectToGradient,\n gradient,\n GradientDirection,\n} from '@charcoal-ui/utils'\nimport { Values } from '../types'\nimport { MergedEffect } from '../foundation'\n\nconst VAR_PREFIX = '--tailwind-gradient-'\n\nexport default function cssVariableColorPlugin(\n gradients: ThemeColorGradient,\n effects: MergedEffect,\n selectorOrMediaQuery: string\n) {\n const utilities = getUtilities(gradients, effects)\n\n const classRules = mapObject(utilities, (name) => [\n `.bg-${name}`,\n { backgroundImage: `var(${VAR_PREFIX}${name})` },\n ])\n\n return plugin(({ addBase, addUtilities }) => {\n const css = mapKeys(utilities, (name) => `${VAR_PREFIX}${name}`)\n if (selectorOrMediaQuery.startsWith('@media')) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n addBase({\n [selectorOrMediaQuery]: {\n ':root': css,\n },\n })\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n addBase({\n [selectorOrMediaQuery]: css,\n })\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n addUtilities(classRules, {\n variants: ['responsive'],\n })\n })\n}\n\nconst DIRECTIONS = {\n 'to top': 'top',\n 'to bottom': 'bottom',\n 'to left': 'left',\n 'to right': 'right',\n} as const\n\n/**\n * こういう感じのやつ。この時点では `--tailwind-gradient-` のような CSS 変数名になってない\n *\n * ```js\n * {\n * 'hoge1': 'linear-gradient(to top, ...)',\n * ...\n * }\n * ```\n */\ntype Utilities = Record<string, LinearGradient>\n\ntype LinearGradient = `linear-gradient(${string})`\n\nexport function getUtilities(\n gradients: Record<string, GradientMaterial>,\n effect: MergedEffect\n): Utilities {\n const effects = Object.entries(effect)\n const directions = Object.entries(DIRECTIONS) as [\n GradientDirection,\n Values<typeof DIRECTIONS>\n ][]\n\n return flatMapObject(gradients, (name, colors) =>\n directions.flatMap(([direction, className]) => {\n const toLinearGradient = (colors: GradientMaterial) => {\n const style = gradient(direction)(colors)\n\n if (!('backgroundImage' in style)) {\n throw new Error(\n `Could not generate linear-gradient() from ${name} ${direction} ${className}`\n )\n }\n\n // 本当は backgroundColor も同時に生成されるんだけど、使うにはそれ用の CSS 変数も一緒に作らないといけない\n // とりあえず background-image だけで動くのでこっちだけを利用する\n return style.backgroundImage as LinearGradient\n }\n\n return [\n // こういう感じのやつ\n // { 'hoge1': 'linear-gradienr(to top, ...)' }\n [createUtilityName(name, className), toLinearGradient(colors)],\n\n // こういう感じのやつ\n // { 'hoge1--hover': 'linear-gradienr(to top, ...)' }\n ...effects.map<[string, LinearGradient]>(([effectName, effect]) => [\n createUtilityName(name, className, effectName),\n toLinearGradient(applyEffectToGradient(effect)(colors)),\n ]),\n ]\n })\n )\n}\n\nfunction createUtilityName(\n gradientName: string,\n direction: Values<typeof DIRECTIONS>,\n suffix = ''\n) {\n return [camelToKebab(gradientName), direction, suffix]\n .filter(Boolean)\n .join('-')\n}\n","import plugin from 'tailwindcss/plugin'\nimport { TypographyDescriptor, TYPOGRAPHY_SIZE } from '@charcoal-ui/foundation'\nimport { halfLeading } from '@charcoal-ui/utils'\nimport { px } from '@charcoal-ui/utils'\nimport { mapObject } from '../util'\n\nconst leadingCancel = {\n display: 'block',\n width: 0,\n height: 0,\n content: '\"\"',\n}\n\nconst typographyStyle = (style: TypographyDescriptor) => {\n const margin = -halfLeading(style)\n\n return {\n 'font-size': px(style.fontSize),\n 'line-height': px(style.lineHeight),\n\n /**\n * cancel leading\n *\n * @see https://yuyakinoshita.com/blog/2020/01/20/line-height-crop/\n */\n '&::before': {\n ...leadingCancel,\n marginTop: px(margin),\n },\n '&::after': {\n ...leadingCancel,\n marginBottom: px(margin),\n },\n }\n}\n\nconst typographyPlugin = plugin(({ addUtilities }) => {\n const typographyClasses = mapObject(TYPOGRAPHY_SIZE, (fontSize, style) => [\n `.typography-${fontSize}`,\n typographyStyle(style),\n ])\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n addUtilities(\n {\n ...typographyClasses,\n '.preserve-half-leading': {\n '&::before': {\n content: 'none',\n },\n '&::after': {\n content: 'none',\n },\n },\n },\n {\n variants: ['responsive'],\n }\n )\n})\n\nexport default typographyPlugin\n","import { GRID_COUNT, mergeEffect } from './foundation'\n\nimport { TailwindConfig } from 'tailwindcss/tailwind-config'\nimport { TailwindVersion, ThemeMap } from './types'\n\nimport {\n assertAllThemeHaveSameKeys,\n getDefaultKeyName,\n getVariantOption,\n mapObject,\n} from './util'\nimport {\n COLUMN_UNIT,\n GUTTER_UNIT,\n SPACING,\n BORDER_RADIUS,\n} from '@charcoal-ui/foundation'\nimport { light } from '@charcoal-ui/theme'\nimport { px } from '@charcoal-ui/utils'\nimport { colorsToTailwindConfig } from './colors/toTailwindConfig'\n\nimport cssVariableColorPlugin from './colors/plugin'\nimport cssVariableGradientPlugin from './gradient/plugin'\nimport typographyPlugin from './typography/plugin'\n\ninterface Options {\n version?: TailwindVersion\n theme?: ThemeMap\n}\n\nexport function createTailwindConfig({\n theme = { ':root': light },\n version = 'v3',\n}: Options): TailwindConfig {\n assertAllThemeHaveSameKeys(theme)\n\n const defaultTheme = theme[':root']\n const effects = mergeEffect(defaultTheme)\n const DEFAULT = getDefaultKeyName(version)\n\n return {\n theme: {\n screens: {\n screen1: px(0),\n screen2: px(defaultTheme.breakpoint.screen1),\n screen3: px(defaultTheme.breakpoint.screen2),\n screen4: px(defaultTheme.breakpoint.screen3),\n screen5: px(defaultTheme.breakpoint.screen4),\n },\n colors: {\n // @deprecated\n black: '#000',\n\n // @deprecated\n white: '#fff',\n\n transparent: 'transparent',\n current: 'currentColor',\n ...colorsToTailwindConfig(version, defaultTheme.color, effects),\n },\n borderColor: {\n ...colorsToTailwindConfig(\n version,\n mapObject(defaultTheme.border, (k, v) => [k, v.color]),\n effects\n ),\n },\n spacing: mapObject(SPACING, (name, pixel) => [name, px(pixel)]),\n width: {\n full: '100%',\n screen: '100vw',\n auto: 'auto',\n\n /**\n * generates classes like \"w-col-span-1\"\n */\n ...Array.from({ length: GRID_COUNT }, (_, i) => i + 1).reduce(\n (styles, i) => ({\n ...styles,\n [`col-span-${i}`]: px(COLUMN_UNIT * i + GUTTER_UNIT * (i - 1)),\n }),\n {}\n ),\n\n /**\n * generates classes like \"w-1/12\" (except for 12/12, which just equals to w-full)\n */\n ...Array.from({ length: GRID_COUNT - 1 }, (_, i) => i + 1).reduce(\n (styles, i) => ({\n ...styles,\n [`${i}/${GRID_COUNT}`]: `${(i / GRID_COUNT) * 100}%`,\n }),\n {}\n ),\n },\n gap: {\n fixed: px(GUTTER_UNIT),\n },\n borderRadius: mapObject(BORDER_RADIUS, (name, value) => [\n name,\n px(value),\n ]),\n transitionDuration: {\n [DEFAULT]: '0.2s',\n },\n },\n\n ...getVariantOption(version),\n\n corePlugins: {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error 配列にしろと言ってくるが、たぶん @types が間違っている\n lineHeight: false,\n },\n plugins: [\n typographyPlugin,\n cssVariableColorPlugin(theme),\n\n ...Object.entries(theme).map(([selectorOrMediaQuery, theme]) =>\n cssVariableGradientPlugin(\n theme.gradientColor,\n mergeEffect(theme),\n selectorOrMediaQuery\n )\n ),\n ],\n }\n}\n\nexport const config: TailwindConfig = createTailwindConfig({})\n"],"names":["mergeEffect","elementEffect","effect","outline","type","opacity","getDefaultKeyName","version","setEquals","a","b","size","Array","from","every","value","has","mapObject","source","callback","Object","fromEntries","entries","flatMap","entry","flatMapObject","filterObject","fn","key","isSingleColor","color","colorsToTailwindConfig","colors","effects","targetColors","DEFAULT","colorsForAllEffects","name","varName","effectName","applyEffect","cssVariableColorPlugin","_defaultTheme","definitions","selectorOrMediaQuery","theme","css","map","toCssVariables","startsWith","plugin","addBase","DIRECTIONS","createUtilityName","gradientName","direction","suffix","replace","toLowerCase","filter","Boolean","join","leadingCancel","display","width","height","content","typographyStyle","style","margin","halfLeading","px","fontSize","lineHeight","marginTop","marginBottom","typographyPlugin","addUtilities","TYPOGRAPHY_SIZE","variants","createTailwindConfig","light","themeMap","defaultTheme","expectedColorKeys","Set","keys","expectedEffectKeys","colorKeys","effectKeys","Error","JSON","stringify","assertAllThemeHaveSameKeys","screens","screen1","screen2","breakpoint","screen3","screen4","screen5","black","white","transparent","current","borderColor","border","k","v","spacing","SPACING","pixel","full","screen","auto","length","_","i","reduce","styles","COLUMN_UNIT","GUTTER_UNIT","GRID_COUNT","gap","fixed","borderRadius","BORDER_RADIUS","transitionDuration","getVariantOption","corePlugins","plugins","gradients","utilities","directions","className","toLinearGradient","gradient","backgroundImage","applyEffectToGradient","getUtilities","classRules","cssVariableGradientPlugin","gradientColor","config"],"mappings":"4sDAKgBA,KAId,cAHAC,gBACAC,QAKEC,QAAS,CACPC,KAAM,UACNC,QAAS,gBCNCC,EAAkBC,GAChC,OAAQA,GACN,IAAK,KACL,IAAK,KACH,MAAO,UAGT,IAAK,KACH,MAAO,WAuBb,SAASC,EAAaC,EAAWC,GAC/B,OAAOD,EAAEE,OAASD,EAAEC,MAAQC,MAAMC,KAAKJ,GAAGK,MAAM,SAACC,UAAUL,EAAEM,IAAID,cAmDnDE,EAMdC,EACAC,GAKA,OAAOC,OAAOC,YACZD,OAAOE,QAAQJ,GAAQK,QAAQ,gBACvBC,EAAQL,aACd,OAAIK,EACK,CAACA,GAED,eAeCC,EAMdP,EACAC,GAEA,OAAOC,OAAOC,YACZD,OAAOE,QAAQJ,GAAQK,QAAQ,YAC7B,OAAOJ,yBAcGO,EACdR,EACAS,GAEA,OAAOV,EAAUC,EAAQ,SAACU,EAAKb,GAC7B,OAAkB,IAAdY,EAAGZ,GACE,CAACa,EAAKb,mBCvJHc,EAAcC,GAC5B,MAAwB,iBAAVA,WCIAC,EACdxB,EACAyB,EACAC,GAEA,IAAMC,EAAeR,EAAaM,EAAQH,GACpCM,EAAU7B,EAAkBC,GAclC,SAAS6B,EAAoBC,EAAcP,SACnCQ,ED5BkB,oBC4BUD,EAElC,iBACGF,UAAiBG,OAAYR,SAE3Bb,EAAUgB,EAAS,SAACM,EAAYrC,SAAW,CAC5CqC,SACOD,OA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mD,EAAkBhB,EAAMiG,QACxBC,EAAiBG,EAAsBxI,EAAtBwI,CAA8B1G,YAtFrC2G,CAAaR,EAAWlG,GAEpC2G,EAAa3H,EAAUmH,EAAW,SAAC/F,SAAS,QACzCA,EACP,CAAEoG,2CAAqCpG,UAGzC,OAAOa,EAAO,gBJkDd/B,MIlDiBgC,IAAAA,QAAS0B,IAAAA,aAClB/B,GJiDR3B,EIjDiC,SAACkB,SAfjB,uBAe0CA,GJmDpDjB,OAAOC,YACZD,OAAOE,QIpDa8G,GJoDGrF,IAAI,gBAAOhC,aAAW,CAACI,QAAeJ,OInDzD6B,EAAqBK,WAAW,UAElCE,UACGP,GAAuB,CACtB,QAASE,OAKbK,UACGP,GAAuBE,MAK5B+B,EAAa+D,EAAY,CACvB7D,SAAU,CAAC,kBE2ET8D,CACEhG,EAAMiG,cACN9I,EAAY6C,GACZD,QAOGmG,IAAAA,EAAyB/D,EAAqB"}
|
package/dist/util.d.ts
CHANGED
|
@@ -8,9 +8,41 @@ import { TailwindVersion, ThemeMap } from './types';
|
|
|
8
8
|
export declare function getDefaultKeyName(version: TailwindVersion): "DEFAULT" | "default";
|
|
9
9
|
export declare function getVariantOption(version: TailwindVersion): Partial<TailwindConfig>;
|
|
10
10
|
export declare function assertAllThemeHaveSameKeys(themeMap: ThemeMap): void;
|
|
11
|
+
/**
|
|
12
|
+
* @example
|
|
13
|
+
* ```js
|
|
14
|
+
* mapKeys({ a: 'aa', b: 'bb' }, (key) => key.toUpperCase()) // => { A: "aa", B: "bb" }
|
|
15
|
+
* ````
|
|
16
|
+
*/
|
|
11
17
|
export declare function mapKeys<V, K extends string>(object: Record<string, V>, callback: (key: string) => K): Record<K, V>;
|
|
18
|
+
/**
|
|
19
|
+
* @example
|
|
20
|
+
* ```js
|
|
21
|
+
* mapObject({ a: 'aa', b: 'bb', c: 'cc' }, (key, value) =>
|
|
22
|
+
* key === 'b' ? undefined : [key + '1', value.toUpperCase()]
|
|
23
|
+
* ) // => { a1: "AA", c1: "CC" }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
12
26
|
export declare function mapObject<SourceKey extends string, SourceValue, DestKey extends string, DestValue>(source: Record<SourceKey, SourceValue>, callback: (key: SourceKey, value: SourceValue) => [DestKey, DestValue] | null | undefined): Record<DestKey, DestValue>;
|
|
27
|
+
/**
|
|
28
|
+
* @example
|
|
29
|
+
* ```js
|
|
30
|
+
* flatMapObject({ a: 'aa', b: 'bb' }, (key, value) => [
|
|
31
|
+
* [key + '1', value + '1'],
|
|
32
|
+
* [key + '2', value + '2'],
|
|
33
|
+
* ]) // => { a1: "aa1", a2: "aa2", b1: "bb1", b2: "bb2" }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
13
36
|
export declare function flatMapObject<SourceKey extends string, SourceValue, DestKey extends string, DestValue>(source: Record<SourceKey, SourceValue>, callback: (key: SourceKey, value: SourceValue) => [DestKey, DestValue][]): Record<DestKey, DestValue>;
|
|
37
|
+
/**
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* filterObject(
|
|
41
|
+
* { a: 'aa', b: 'bb', c: 'cc' },
|
|
42
|
+
* (value): value is string => value !== 'bb'
|
|
43
|
+
* ) // => { a: "aa", c: "cc" }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
14
46
|
export declare function filterObject<Source, Dest extends Source>(source: Record<string, Source>, fn: (value: Source) => value is Dest): Record<string, Dest>;
|
|
15
47
|
export declare function camelToKebab(value: string): string;
|
|
16
48
|
//# sourceMappingURL=util.d.ts.map
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEnD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO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AM,KAAK,KAAK,IAAI,IAAI,wBASrC;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,UAIzC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@charcoal-ui/tailwind-config",
|
|
3
|
-
"version": "1.0.1-alpha.
|
|
3
|
+
"version": "1.0.1-alpha.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -21,13 +21,14 @@
|
|
|
21
21
|
"microbundle": "^0.14.2",
|
|
22
22
|
"postcss": "^8.4.5",
|
|
23
23
|
"postcss-selector-parser": "^6.0.9",
|
|
24
|
+
"react": "^18.0.0",
|
|
24
25
|
"rimraf": "^3.0.2",
|
|
25
26
|
"tailwindcss": "^3.0.5",
|
|
26
27
|
"typescript": "^4.5.5"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
30
|
"@charcoal-ui/foundation": "^1.0.1-alpha.0",
|
|
30
|
-
"@charcoal-ui/theme": "^2.0.0-alpha.
|
|
31
|
+
"@charcoal-ui/theme": "^2.0.0-alpha.2",
|
|
31
32
|
"@charcoal-ui/utils": "^1.0.1-alpha.0"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
|
@@ -47,5 +48,5 @@
|
|
|
47
48
|
"url": "https://github.com/pixiv/charcoal.git",
|
|
48
49
|
"directory": "packages/tailwind-config"
|
|
49
50
|
},
|
|
50
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "f68b0533a24b68f4726711fd2f5fb23be1ccba93"
|
|
51
52
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* import { Story } from '@storybook/react/types-6-0'
|
|
5
|
+
*
|
|
6
|
+
* をするとstyled-componentsが壊れるので代替品を作った
|
|
7
|
+
*
|
|
8
|
+
* エラー:
|
|
9
|
+
* node_modules/@types/styled-components/ts3.7/index.d.ts
|
|
10
|
+
* `Type alias 'Interpolation' circularly references itself. ts(2456)`
|
|
11
|
+
*/
|
|
12
|
+
export type Story<P> = React.ComponentType<P> & { args?: P }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { borderRadius } from '.'
|
|
3
|
+
|
|
4
|
+
export const BorderRadius: React.FC = () => {
|
|
5
|
+
return (
|
|
6
|
+
<div className="space-y-40">
|
|
7
|
+
{Object.entries(borderRadius).map(([key, value]) => (
|
|
8
|
+
<div key={key}>
|
|
9
|
+
<p className="typography-14 text-text2">rounded-{key}</p>
|
|
10
|
+
<div className="space-x-16 flex">
|
|
11
|
+
<div
|
|
12
|
+
className={`bg-surface4 rounded-${key} h-64`}
|
|
13
|
+
style={{ width: '64px' }}
|
|
14
|
+
></div>
|
|
15
|
+
<div
|
|
16
|
+
className={`bg-surface4 rounded-${key} h-64`}
|
|
17
|
+
style={{ width: '272px' }}
|
|
18
|
+
></div>
|
|
19
|
+
</div>
|
|
20
|
+
<p className="typography-12 text-text3">
|
|
21
|
+
border-radius: <span className="text-text2">{value}</span>
|
|
22
|
+
</p>
|
|
23
|
+
</div>
|
|
24
|
+
))}
|
|
25
|
+
</div>
|
|
26
|
+
)
|
|
27
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { EffectType } from '@charcoal-ui/theme'
|
|
3
|
+
import { colors } from '.'
|
|
4
|
+
|
|
5
|
+
const effectTypes: { [type in EffectType]: null } = {
|
|
6
|
+
hover: null,
|
|
7
|
+
press: null,
|
|
8
|
+
disabled: null,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const ColorBox: React.FC<{
|
|
12
|
+
bgColorClass: string
|
|
13
|
+
label: string
|
|
14
|
+
emphasizeLabelByDefault?: boolean
|
|
15
|
+
}> = ({ bgColorClass, label, emphasizeLabelByDefault = false }) => (
|
|
16
|
+
<div className="group grow basis-0 space-y-8">
|
|
17
|
+
<p
|
|
18
|
+
className={`typography-14 ${
|
|
19
|
+
emphasizeLabelByDefault ? 'text-text2' : 'text-text3'
|
|
20
|
+
} group-hover:text-text2 transition-colors`}
|
|
21
|
+
>
|
|
22
|
+
{label}
|
|
23
|
+
</p>
|
|
24
|
+
<div className="relative h-64 w-full">
|
|
25
|
+
<div
|
|
26
|
+
/**
|
|
27
|
+
* Display checker pattern for visualizing colors with transparency
|
|
28
|
+
*/
|
|
29
|
+
className="absolute top-0 right-0 h-full w-6/12"
|
|
30
|
+
aria-hidden="true"
|
|
31
|
+
style={{
|
|
32
|
+
backgroundImage:
|
|
33
|
+
'linear-gradient(45deg, #ccc 25%, transparent 25%), linear-gradient(135deg, #ccc 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ccc 75%), linear-gradient(135deg, transparent 75%, #ccc 75%)',
|
|
34
|
+
backgroundSize: '12px 12px',
|
|
35
|
+
backgroundPosition: '0 0, 6px 0, 6px -6px, 0 6px',
|
|
36
|
+
}}
|
|
37
|
+
></div>
|
|
38
|
+
<button
|
|
39
|
+
type="button"
|
|
40
|
+
className={`absolute top-0 left-0 h-full w-full border border-r-0 group-last:border-r border-default cursor-pointer ${bgColorClass}`}
|
|
41
|
+
onClick={() => {
|
|
42
|
+
void navigator.clipboard.writeText(bgColorClass)
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
<span className="opacity-0 group-hover:opacity-100 transition-opacity typography-14 text-text2">
|
|
46
|
+
Click to copy the class
|
|
47
|
+
</span>
|
|
48
|
+
</button>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
export const Colors: React.FC = () => {
|
|
54
|
+
return (
|
|
55
|
+
<div className="space-y-24">
|
|
56
|
+
{Object.entries(colors).map(([colorName, values]) => (
|
|
57
|
+
<div className="flex" key={colorName}>
|
|
58
|
+
{typeof values === 'object' && 'DEFAULT' in values ? (
|
|
59
|
+
<>
|
|
60
|
+
<ColorBox
|
|
61
|
+
bgColorClass={`bg-${colorName}`}
|
|
62
|
+
label={colorName}
|
|
63
|
+
emphasizeLabelByDefault
|
|
64
|
+
/>
|
|
65
|
+
{Object.keys(effectTypes).map((modifier) =>
|
|
66
|
+
modifier in values ? (
|
|
67
|
+
<ColorBox
|
|
68
|
+
bgColorClass={`bg-${colorName}-${modifier}`}
|
|
69
|
+
label={`-${modifier}`}
|
|
70
|
+
/>
|
|
71
|
+
) : null
|
|
72
|
+
)}
|
|
73
|
+
</>
|
|
74
|
+
) : (
|
|
75
|
+
<ColorBox
|
|
76
|
+
bgColorClass={`bg-${colorName}`}
|
|
77
|
+
label={colorName}
|
|
78
|
+
emphasizeLabelByDefault
|
|
79
|
+
/>
|
|
80
|
+
)}
|
|
81
|
+
</div>
|
|
82
|
+
))}
|
|
83
|
+
</div>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import type { Story } from '../../_lib/compat'
|
|
3
|
+
|
|
4
|
+
import { colors } from '.'
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'tailwind-config/Colors/Text bg color',
|
|
8
|
+
argTypes: {
|
|
9
|
+
textColorClass: {
|
|
10
|
+
control: {
|
|
11
|
+
type: 'select',
|
|
12
|
+
options: Object.keys(colors).map((color) => `text-${color}`),
|
|
13
|
+
},
|
|
14
|
+
defaultValue: 'text-text1',
|
|
15
|
+
},
|
|
16
|
+
bgColorClass: {
|
|
17
|
+
control: {
|
|
18
|
+
type: 'select',
|
|
19
|
+
options: Object.keys(colors).map((color) => `bg-${color}`),
|
|
20
|
+
},
|
|
21
|
+
defaultValue: 'bg-background1',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type Props = Readonly<{
|
|
27
|
+
textColorClass: string
|
|
28
|
+
bgColorClass: string
|
|
29
|
+
}>
|
|
30
|
+
|
|
31
|
+
export const Playground: Story<Props> = ({ textColorClass, bgColorClass }) => (
|
|
32
|
+
<div className={`${bgColorClass} p-64 max-w-2xl`}>
|
|
33
|
+
<p className={`typography-20 ${textColorClass}`}>
|
|
34
|
+
charcoal はピクシブ株式会社のデザインシステムです。ここでは特に、Web
|
|
35
|
+
フロントエンドの実装に用いる npm パッケージ集のことを言います。Lorem ipsum
|
|
36
|
+
dolor sit amet, consectetur adipiscing elit. Aliquam at odio bibendum nisl
|
|
37
|
+
mollis eleifend et quis turpis. Quisque dignissim porta justo ut
|
|
38
|
+
convallis.dipiscing elit.
|
|
39
|
+
</p>
|
|
40
|
+
</div>
|
|
41
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { colors } from '.'
|
|
3
|
+
|
|
4
|
+
export const TextColors: React.FC = () => (
|
|
5
|
+
<div className="space-y-24">
|
|
6
|
+
{Object.keys(colors).map((colorName) => (
|
|
7
|
+
<div key={colorName}>
|
|
8
|
+
<p className="typography-14 text-text2 mb-4">text-{colorName}</p>
|
|
9
|
+
<div className={`relative z-0`}>
|
|
10
|
+
<div
|
|
11
|
+
className="absolute top-0 right-0 h-full w-6/12 bg-surface8 z-[-1]"
|
|
12
|
+
aria-hidden="true"
|
|
13
|
+
></div>
|
|
14
|
+
<p className={`typography-20 text-${colorName}`}>
|
|
15
|
+
charcoal はピクシブ株式会社のデザインシステムです。ここでは特に、Web
|
|
16
|
+
フロントエンドの実装に用いる npm パッケージ集のことを言います。
|
|
17
|
+
</p>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
))}
|
|
21
|
+
</div>
|
|
22
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Meta, Story } from '@storybook/addon-docs'
|
|
2
|
+
import { Colors, TextColors } from '.'
|
|
3
|
+
|
|
4
|
+
<Meta title="tailwind-config/Colors/Doc" component={[Colors, TextColors]} />
|
|
5
|
+
|
|
6
|
+
# Colors
|
|
7
|
+
|
|
8
|
+
<br />
|
|
9
|
+
|
|
10
|
+
## Bg colors
|
|
11
|
+
|
|
12
|
+
<br />
|
|
13
|
+
|
|
14
|
+
<Story name="Colors">
|
|
15
|
+
<Colors />
|
|
16
|
+
</Story>
|
|
17
|
+
|
|
18
|
+
<br />
|
|
19
|
+
<br />
|
|
20
|
+
|
|
21
|
+
## Text colors
|
|
22
|
+
|
|
23
|
+
<br />
|
|
24
|
+
|
|
25
|
+
<Story name="Text colors">
|
|
26
|
+
<TextColors />
|
|
27
|
+
</Story>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { utilityClasses, directions, effectTypes } from '.'
|
|
3
|
+
import { getUniqueGradientNames } from './utils'
|
|
4
|
+
|
|
5
|
+
const GradientBox: React.FC<{
|
|
6
|
+
gradientClassName: string
|
|
7
|
+
label: string
|
|
8
|
+
emphasizeLabelByDefault?: boolean
|
|
9
|
+
}> = ({ gradientClassName, label, emphasizeLabelByDefault = false }) => (
|
|
10
|
+
<div className="group grow basis-0">
|
|
11
|
+
<p
|
|
12
|
+
className={`typography-14 ${
|
|
13
|
+
emphasizeLabelByDefault ? 'text-text2' : 'text-text3'
|
|
14
|
+
} group-hover:text-text2 transition-colors`}
|
|
15
|
+
>
|
|
16
|
+
{label}
|
|
17
|
+
</p>
|
|
18
|
+
<button
|
|
19
|
+
type="button"
|
|
20
|
+
className={`${gradientClassName} h-64 w-full border-none cursor-pointer`}
|
|
21
|
+
onClick={() => {
|
|
22
|
+
void navigator.clipboard.writeText(gradientClassName)
|
|
23
|
+
}}
|
|
24
|
+
>
|
|
25
|
+
<span className="opacity-0 group-hover:opacity-100 transition-opacity typography-14 text-text2">
|
|
26
|
+
Click to copy the class
|
|
27
|
+
</span>
|
|
28
|
+
</button>
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
export const Gradients: React.FC = () => {
|
|
33
|
+
const utilityClassNames = Object.keys(utilityClasses)
|
|
34
|
+
const uniqueGradientNames = getUniqueGradientNames(utilityClassNames)
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div className="space-y-64">
|
|
38
|
+
{uniqueGradientNames.map((gradientName) => (
|
|
39
|
+
<div className="space-y-24" key={gradientName}>
|
|
40
|
+
{directions.map((direction) => (
|
|
41
|
+
<div className="flex" key={direction}>
|
|
42
|
+
{utilityClassNames.includes(`${gradientName}-${direction}`) && (
|
|
43
|
+
<GradientBox
|
|
44
|
+
gradientClassName={`${gradientName}-${direction}`}
|
|
45
|
+
label={`${gradientName}-${direction}`}
|
|
46
|
+
emphasizeLabelByDefault
|
|
47
|
+
/>
|
|
48
|
+
)}
|
|
49
|
+
{Object.keys(effectTypes).map(
|
|
50
|
+
(effectType) =>
|
|
51
|
+
utilityClassNames.includes(
|
|
52
|
+
`${gradientName}-${direction}-${effectType}`
|
|
53
|
+
) && (
|
|
54
|
+
<GradientBox
|
|
55
|
+
gradientClassName={`${gradientName}-${direction}-${effectType}`}
|
|
56
|
+
label={`-${effectType}`}
|
|
57
|
+
key={effectType}
|
|
58
|
+
/>
|
|
59
|
+
)
|
|
60
|
+
)}
|
|
61
|
+
</div>
|
|
62
|
+
))}
|
|
63
|
+
</div>
|
|
64
|
+
))}
|
|
65
|
+
</div>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EffectType } from '@charcoal-ui/theme'
|
|
2
|
+
import { config } from '../../'
|
|
3
|
+
import { TailwindPlugin, getUtilities } from '../'
|
|
4
|
+
|
|
5
|
+
export { Gradients } from './Gradients'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* TODO:
|
|
9
|
+
* Seek for some better way to find the plugin we need here
|
|
10
|
+
* from `config.plugins` array
|
|
11
|
+
*/
|
|
12
|
+
const gradientPlugin: TailwindPlugin = config.plugins
|
|
13
|
+
? (config.plugins[2] as unknown as TailwindPlugin)
|
|
14
|
+
: { handler: () => void {} }
|
|
15
|
+
|
|
16
|
+
export const utilityClasses = getUtilities(gradientPlugin)
|
|
17
|
+
|
|
18
|
+
export const directions = ['top', 'bottom', 'right', 'left'] as const
|
|
19
|
+
export type Direction = typeof directions[number]
|
|
20
|
+
|
|
21
|
+
export type { EffectType }
|
|
22
|
+
export const effectTypes: { [type in EffectType]: null } = {
|
|
23
|
+
hover: null,
|
|
24
|
+
press: null,
|
|
25
|
+
disabled: null,
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { directions } from '.'
|
|
2
|
+
|
|
3
|
+
export const getUniqueGradientNames = (utilityClasses: string[]): string[] => {
|
|
4
|
+
return Array.from(
|
|
5
|
+
new Set(
|
|
6
|
+
utilityClasses
|
|
7
|
+
.map((className) => {
|
|
8
|
+
/**
|
|
9
|
+
* like `['bg', 'surface5', 'bottom', 'disabled']`
|
|
10
|
+
*/
|
|
11
|
+
const classNameParts = className.split('-')
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* like `bottom`
|
|
15
|
+
*/
|
|
16
|
+
const directionInClassName = directions.find((direction) =>
|
|
17
|
+
classNameParts.includes(direction)
|
|
18
|
+
)
|
|
19
|
+
if (!directionInClassName) return null
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* like `['bg', 'surface5']`
|
|
23
|
+
*/
|
|
24
|
+
const classNameWithoutModifiers = classNameParts.slice(
|
|
25
|
+
0,
|
|
26
|
+
classNameParts.indexOf(directionInClassName)
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* like `bg-surface5`
|
|
31
|
+
*/
|
|
32
|
+
return classNameWithoutModifiers.join('-')
|
|
33
|
+
})
|
|
34
|
+
.filter((value): value is string => typeof value === 'string')
|
|
35
|
+
).values()
|
|
36
|
+
)
|
|
37
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { mapObject } from '../util'
|
|
2
|
+
|
|
3
|
+
export type TailwindPlugin = {
|
|
4
|
+
handler: ({
|
|
5
|
+
addBase,
|
|
6
|
+
addUtilities,
|
|
7
|
+
}: {
|
|
8
|
+
addBase: unknown
|
|
9
|
+
addUtilities: unknown
|
|
10
|
+
}) => void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type UtilityClasses = Record<string, Record<string, unknown>>
|
|
14
|
+
|
|
15
|
+
export const getUtilities = (plugin: TailwindPlugin) => {
|
|
16
|
+
let utilities: UtilityClasses = {}
|
|
17
|
+
|
|
18
|
+
plugin.handler({
|
|
19
|
+
addBase: () => {
|
|
20
|
+
/**
|
|
21
|
+
* We don't need these base styles as they gonna be
|
|
22
|
+
* applied to the `:root` element by Tailwind automatically
|
|
23
|
+
*/
|
|
24
|
+
},
|
|
25
|
+
addUtilities: (args: UtilityClasses) => {
|
|
26
|
+
utilities = { ...utilities, ...args }
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
return mapObject(utilities, (key, value) => [
|
|
31
|
+
key.startsWith('.') ? key.slice(1) : key,
|
|
32
|
+
value,
|
|
33
|
+
])
|
|
34
|
+
}
|