@charcoal-ui/styled 1.0.0 → 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/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.map +1 -1
- package/package.json +10 -5
- package/src/util.ts +8 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/util.ts","../src/lib.ts","../src/index.ts"],"sourcesContent":["/**\n * Function used to assert a given code path is unreachable\n */\nexport function unreachable(): never\n/**\n * Function used to assert a given code path is unreachable.\n * Very useful for ensuring switches are exhaustive:\n *\n * ```ts\n * switch (a.type) {\n * case Types.A:\n * case Types.B:\n * break\n * default:\n * unreachable(a) // will cause a build error if there was\n * // a Types.C that was not checked\n * }\n * ```\n *\n * @param value Value to be asserted as unreachable\n */\n// NOTE: Uses separate overloads, _not_ `value?: never`, to not allow `undefined` to be passed\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport function unreachable(value: never): never\nexport function unreachable(value?: never): never {\n throw new Error(\n arguments.length === 0\n ? 'unreachable'\n : `unreachable (${JSON.stringify(value)})`\n )\n}\n\n/**\n * Check whether a value is non-null and non-undefined\n *\n * @param value nullable\n */\nexport const isPresent = <T>(value: T): value is NonNullable<T> => value != null\n\ntype Head<U> = U extends [infer T, ...any[]] ? T : never\n\ntype Tail<U> = U extends [any, any, ...any[]]\n ? ((...args: U) => any) extends (head: any, ...args: infer T) => any\n ? T\n : never\n : never\n// Buggy at ts@4.0.0-dev20200506\n// type Tail<U> = U extends [any, ...infer T] ? T : never\n\ntype RecursiveObjectAssign<T, S extends any[]> = {\n 0: T & Head<S>\n 1: RecursiveObjectAssign<T & Head<S>, Tail<S>>\n}[Tail<S> extends never ? 0 : 1]\n\ntype ObjectAssign<T extends any[]> = RecursiveObjectAssign<\n Record<string, unknown>,\n T\n>\n\nexport function objectAssign<T extends any[]>(...sources: T) {\n return Object.assign({}, ...sources) as ObjectAssign<T>\n}\n\nexport function objectKeys<V, K extends keyof V>(obj: V) {\n return Object.keys(obj) as K[]\n}\n\nexport interface ReadonlyArrayConstructor {\n isArray(value: any): value is readonly any[]\n}\n\nexport function extractNonNullKeys<V, K extends keyof V>(obj: {\n [key in K]: V[key]\n}) {\n return Object.entries(obj)\n .filter(([_, v]) => v !== null)\n .map(([k]) => k) as { [key in K]: V[key] extends null ? never : key }[K][]\n}\n","import { Key } from '@charcoal-ui/theme'\nimport { unreachable } from './util'\n\n/**\n * 配列で指定したプロパティを動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param member オブジェクトに生やすプロパティ一覧\n * @param chain プロパティに格納される値を生成する関数\n *\n * @example\n *\n * const o = factory({}, ['red', 'blue'],\n * color => hex(color)\n * )\n *\n * console.log(o.red) //=> #ff0000\n */\nexport const factory = <TSource, TMember extends readonly Key[], TValue>(\n source: TSource,\n member: TMember,\n chain: (key: TMember[number]) => TValue\n) =>\n Object.defineProperties(\n source,\n Object.fromEntries(\n member.map((key) => [\n key,\n { get: () => chain(key), enumerable: true, configurable: true },\n ])\n )\n ) as TSource & { readonly [key in TMember[number]]: TValue }\n\n/**\n * 配列で指定した名前のメソッドを動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param member オブジェクトに生やすメソッド名一覧\n * @param chain メソッドの戻り値になる値を生成する関数\n *\n * @example\n *\n * const o = argumentedFactory({}, ['red', 'blue'],\n * (color, alpha: number) => hex(color, alpha)\n * )\n *\n * console.log(o.red(0.5)) //=> #ff000077\n */\nexport const argumentedFactory = <\n TSource,\n TMember extends readonly string[],\n TValue,\n TArguments extends unknown[]\n>(\n source: TSource,\n member: TMember,\n chain: (key: TMember[number], ...args: TArguments) => TValue\n) =>\n Object.defineProperties(\n source,\n Object.fromEntries(\n member.map((key) => [\n key,\n {\n value: (...args: TArguments) => chain(key, ...args),\n enumerable: true,\n configurable: true,\n },\n ])\n )\n ) as TSource & {\n readonly [key in TMember[number]]: (...args: TArguments) => TValue\n }\n\n/**\n * オブジェクトで指定したプロパティ名と値を動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param def オブジェクトに生やす定義(プロパティ名と値)\n *\n * @example\n *\n * const o = constFactory({}, {\n * red: '#f00',\n * blue: '#00f',\n * })\n *\n * console.log(o.red) //=> #f00\n */\nexport const constFactory = <TSource, TDef extends { [key: string]: unknown }>(\n source: TSource,\n def: TDef\n) =>\n factory(source, Object.keys(def), (key) => def[key]) as TSource &\n Readonly<TDef>\n\n/**\n * 配列で指定したモディファイア(プロパティ)をチェーン可能な再帰オブジェクトを動的に生やす\n *\n * @param modifiers オブジェクトに生やすモディファイヤ一覧\n * @param source 指定されたモディファイヤの一覧から値を生成する関数\n *\n * @example\n *\n * const o = modifiedArgumentedFactory(['red', 'blue'],\n * modifiers => modifiers.map(color => hex(color)).join(',')\n * )\n *\n * console.log(o.red.blue) => #f00,#00f\n */\nexport const modifiedFactory = <TSource, T extends Key>(\n modifiers: readonly T[],\n source: (applied: readonly T[]) => TSource\n) =>\n (function recursiveModifiedFactory(\n applied: readonly T[]\n ): Modified<TSource, T> {\n const notApplied = modifiers.filter((v) => !applied.includes(v))\n return factory(source(applied), notApplied, (modifier) =>\n notApplied.length === 0\n ? unreachable()\n : recursiveModifiedFactory([...applied, modifier])\n )\n })([])\n\nexport type Modified<TSource, TModifiers extends Key> = TSource & {\n readonly [key in TModifiers]: Modified<TSource, Exclude<TModifiers, key>>\n}\n\n/**\n * 配列で指定したモディファイア(メソッド)をチェーン可能な再帰オブジェクトを動的に生やす\n *\n * @param modifiers オブジェクトに生やすモディファイヤ一覧\n * @param source 指定されたモディファイヤの一覧から値を生成する関数\n * @param _inferPhantom 関数形式のモディファイヤの引数型を推論するためのメタタイプ(引数の個数に合わせてタプルで指定する)\n *\n * @example\n *\n * const o = modifiedArgumentedFactory(['red', 'blue'],\n * modifiers => modifiers.map(([color, alpha]) => hex(color, alpha)).join(',')\n * , {} as [number])\n *\n * console.log(o.red(0.5).blue(1)) => #ff000077,#0000ffff\n */\nexport const modifiedArgumentedFactory = <\n TSource,\n T extends string,\n TArguments extends unknown[]\n>(\n modifiers: readonly T[],\n source: (applied: readonly [T, ...TArguments][]) => TSource,\n ..._inferPhantom: TArguments\n) =>\n (function recursiveModifiedFactory(\n applied: readonly [T, ...TArguments][]\n ): ModifiedArgumented<TSource, T, TArguments> {\n const notApplied = modifiers.filter(\n (v) => !applied.map(([w]) => w).includes(v)\n )\n return argumentedFactory(\n source(applied),\n notApplied,\n (modifier, ...args: TArguments) =>\n notApplied.length === 0\n ? unreachable()\n : recursiveModifiedFactory([...applied, [modifier, ...args]])\n )\n })([])\n\nexport type ModifiedArgumented<\n TSource,\n TModifiers extends string,\n TArguments extends unknown[]\n> = TSource & {\n readonly [key in TModifiers]: (\n ...args: TArguments\n ) => ModifiedArgumented<TSource, Exclude<TModifiers, key>, TArguments>\n}\n","import { CSSObject, ThemedStyledInterface } from 'styled-components'\nimport warning from 'warning'\nimport {\n factory,\n modifiedFactory,\n constFactory,\n modifiedArgumentedFactory,\n} from './lib'\nimport {\n EffectType,\n CharcoalAbstractTheme as Theme,\n Key,\n} from '@charcoal-ui/theme'\nimport {\n objectAssign,\n unreachable,\n ReadonlyArrayConstructor,\n objectKeys,\n isPresent,\n} from './util'\nimport { columnSystem } from '@charcoal-ui/foundation'\nimport {\n halfLeading,\n applyEffect,\n applyEffectToGradient,\n dur,\n gradient,\n GradientDirection,\n notDisabledSelector,\n disabledSelector,\n px,\n} from '@charcoal-ui/utils'\nexport { type Modified, type ModifiedArgumented } from './lib'\n\nconst colorProperties = ['bg', 'font'] as const\ntype ColorProperty = typeof colorProperties[number]\n\nconst spacingProperties = ['margin', 'padding'] as const\nconst spacingDirections = [\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'vertical',\n 'horizontal',\n 'all',\n] as const\ntype SpacingProperty = typeof spacingProperties[number]\ntype SpacingDirection = typeof spacingDirections[number]\n\nconst fixedProperties = ['width', 'height'] as const\ntype FixedProperty = typeof fixedProperties[number]\n\nconst borderDirections = ['top', 'right', 'bottom', 'left'] as const\ntype BorderDirection = typeof borderDirections[number]\n\nconst outlineType = ['focus'] as const\ntype OutlineType = typeof outlineType[number]\n\n/**\n * `theme(o => [...])` の `o` の部分を構築する\n *\n * @param theme テーマオブジェクト\n * @param isPhantom 型推論のためだけに使う場合にランタイムコストをゼロにするフラグ\n */\nfunction builder<T extends Theme>(\n theme: {\n // factoryの第二引数に入れ込むものだけ明示的に型変数を展開しておくことで型の具象化を遅延する\n color: T['color']\n gradientColor: T['gradientColor']\n border: T['border']\n outline: T['outline']\n } & Omit<T, 'color' | 'gradientColor' | 'border' | 'outline'>,\n isPhantom = false\n) {\n if (isPhantom) {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n return {} as never\n }\n const colors = objectKeys(theme.color)\n const effects = objectKeys(theme.effect)\n\n // 色\n const gradientColors = objectKeys(theme.gradientColor)\n const colorCss = createColorCss(theme)\n const gradientColorCss = createGradientColorCss(theme)\n const colorObject = constFactory(\n {},\n {\n bg: objectAssign(\n factory({}, colors, (color) =>\n modifiedFactory(effects, (modifiers) =>\n colorCss('bg', color, modifiers)\n )\n ),\n factory(\n {},\n gradientColors,\n (color) => (direction: GradientDirection) =>\n modifiedFactory(effects, (modifiers) =>\n gradientColorCss(color, modifiers, direction)\n )\n )\n ),\n font: factory({}, colors, (color) =>\n modifiedFactory(effects, (modifiers) =>\n colorCss('font', color, modifiers)\n )\n ),\n }\n )\n\n // タイポグラフィ\n const typographyModifiers = [\n // TODO\n 'monospace',\n 'bold',\n 'preserveHalfLeading',\n ] as const\n const typographyCss = createTypographyCss(theme)\n const typographyObject = factory(\n {},\n ['typography'] as const,\n (_) => (size: keyof T['typography']['size']) =>\n modifiedFactory(typographyModifiers, (modifiers) =>\n typographyCss(size, {\n preserveHalfLeading: modifiers.includes('preserveHalfLeading'),\n monospace: modifiers.includes('monospace'),\n bold: modifiers.includes('bold'),\n })\n )\n )\n\n // スペーシング\n const spacingCss = createSpacingCss(theme)\n const spacingObject = factory({}, spacingProperties, (spacingProperty) =>\n modifiedArgumentedFactory(\n spacingDirections,\n (modifiers) => spacingCss(spacingProperty, modifiers),\n {} as keyof T['spacing'] | 'auto' // 推論のためのメタタイプ\n )\n )\n\n // 大きさ\n const fixedPxCss = createFixedPxCss(theme)\n const fixedColumnCss = createFixedColumnCss(theme)\n const fixedRelativeCss = createFixedRelativeCss(theme)\n const fixedObject = factory({}, fixedProperties, (property) =>\n constFactory(\n {},\n {\n px: (size: keyof T['spacing'] | 'auto') => fixedPxCss(property, size),\n column: (span: number) => fixedColumnCss(property, span),\n auto: fixedRelativeCss(property, 'auto'),\n full: fixedRelativeCss(property, '100%'),\n }\n )\n )\n\n // 要素へのエフェクト (etc: 透過)\n const elementEffectCss = createElementEffectCss(theme)\n const elementEffectObject = modifiedFactory(\n objectKeys(theme.elementEffect),\n (modifiers) => elementEffectCss(modifiers)\n )\n\n // ボーダー\n const borderCss = createBorderCss(theme)\n const borderObject = constFactory(\n {},\n {\n border: factory({}, objectKeys(theme.border), (variant) =>\n modifiedFactory(borderDirections, (modifiers) =>\n borderCss(variant, modifiers)\n )\n ),\n }\n )\n\n // 角丸\n const borderRadiusCss = createBorderRadiusCss(theme)\n const borderRadiusObject = constFactory(\n {},\n {\n borderRadius: (radius: keyof T['borderRadius']) =>\n borderRadiusCss(radius),\n }\n )\n\n // アウトライン\n const outlineCss = createOutlineColorCss(theme)\n const outlineObject = constFactory(\n {},\n {\n outline: factory({}, objectKeys(theme.outline), (variant) =>\n modifiedFactory(outlineType, (modifiers) =>\n outlineCss(variant, modifiers)\n )\n ),\n }\n )\n\n return objectAssign(\n colorObject,\n typographyObject,\n spacingObject,\n fixedObject,\n elementEffectObject,\n borderObject,\n borderRadiusObject,\n outlineObject\n )\n}\n\nfunction targetProperty(target: ColorProperty) {\n return target === 'bg' ? 'background-color' : 'color'\n}\n\nfunction isSupportedEffect(effect: Key): effect is EffectType {\n return ['hover', 'press', 'disabled'].includes(effect as string)\n}\n\nfunction onEffectPseudo(effect: EffectType, css: CSSObject) {\n return effect === 'hover'\n ? { '&:hover': { [notDisabledSelector]: css } }\n : effect === 'press'\n ? { '&:active': { [notDisabledSelector]: css } }\n : // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n effect === 'disabled'\n ? { [disabledSelector]: css }\n : unreachable(effect)\n}\n\nconst createColorCss =\n <T extends Theme>(theme: T) =>\n (\n target: ColorProperty,\n color: keyof T['color'],\n effects: readonly (keyof T['effect'])[] = []\n ): Internal =>\n internal(\n () => ({\n [targetProperty(target)]: theme.color[color],\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n [targetProperty(target)]: applyEffect(\n theme.color[color],\n theme.effect[effect] ?? []\n ),\n }),\n }),\n {}\n ),\n }),\n effects.length > 0\n ? target === 'font'\n ? {\n colorTransition: true,\n }\n : {\n backgroundColorTransition: true,\n }\n : {}\n )\n\n// TODO: deprecate\nconst TRANSITION_DURATION = 0.2\n\nconst createGradientColorCss =\n <T extends Theme>(theme: T) =>\n (\n color: keyof T['gradientColor'],\n effects: readonly (keyof T['effect'])[] = [],\n direction: GradientDirection\n ): Internal => {\n const toLinearGradient = gradient(direction)\n return internal((context) => {\n const optimized = !useHalfLeadingCanceller(context)\n const duration = dur(TRANSITION_DURATION)\n if (optimized && effects.length > 0) {\n return {\n position: 'relative',\n zIndex: 0,\n overflow: 'hidden',\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n '&::before': {\n zIndex: -1,\n ...overlayElement,\n transition: `${duration} background-color`,\n },\n '&::after': {\n zIndex: -2,\n ...overlayElement,\n ...toLinearGradient(theme.gradientColor[color]),\n },\n ...onEffectPseudo(effect, {\n '&::before': {\n backgroundColor: applyEffect(\n null,\n theme.effect[effect] ?? []\n ),\n },\n }),\n }),\n {}\n ),\n }\n } else {\n warning(\n effects.length === 0,\n // eslint-disable-next-line max-len\n `'Transition' will not be applied. You can get around this by specifying 'preserveHalfLeading' or both 'padding' and 'typograpy'.`\n )\n return {\n ...toLinearGradient(theme.gradientColor[color]),\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n ...toLinearGradient(\n applyEffectToGradient(theme.effect[effect] ?? [])(\n theme.gradientColor[color]\n )\n ),\n }),\n }),\n {}\n ),\n }\n }\n })\n }\n\n/**\n * @see https://developer.mozilla.org/ja/docs/Web/CSS/:focus-visible#selectively_showing_the_focus_indicator\n */\nconst onFocus = (css: CSSObject) => ({\n [notDisabledSelector]: {\n '&:focus, &:active': {\n outline: 'none',\n ...css,\n },\n\n '&:focus:not(:focus-visible), &:active:not(:focus-visible)': {\n outline: 'none',\n },\n\n '&:focus-visible': {\n outline: 'none',\n ...css,\n },\n },\n})\n\nconst outlineCss = (weight: number, color: string) => ({\n boxShadow: `0 0 0 ${px(weight)} ${color}`,\n})\n\nconst createOutlineColorCss =\n <T extends Theme>(theme: T) =>\n (\n variant: keyof T['outline'],\n modifiers: readonly OutlineType[]\n ): Internal => {\n const weight = theme.outline[variant].weight\n const color = theme.outline[variant].color\n return internal(\n () =>\n modifiers.includes('focus')\n ? onFocus(outlineCss(weight, color))\n : { '&&': { [notDisabledSelector]: outlineCss(weight, color) } },\n {\n boxShadowTransition: true,\n }\n )\n }\n\nconst overlayElement: CSSObject = {\n content: \"''\",\n display: 'block',\n position: 'absolute',\n width: '100%',\n height: '100%',\n top: 0,\n left: 0,\n}\n\n// half-leadingをキャンセルするとき && 垂直方向のpaddingが無い時\n// -> before/afterを入れる\nconst useHalfLeadingCanceller = ({\n cancelHalfLeadingPx,\n hasVerticalPadding = false,\n}: Context) => cancelHalfLeadingPx !== undefined && !hasVerticalPadding\n\nconst createTypographyCss =\n <T extends Theme>(theme: T) =>\n (\n size: keyof T['typography']['size'],\n options: {\n preserveHalfLeading?: boolean\n monospace?: boolean\n bold?: boolean\n } = {}\n ): Internal => {\n const {\n preserveHalfLeading = false,\n monospace = false,\n bold = false,\n } = options\n const descriptor = theme.typography.size[size]\n const margin = -halfLeading(descriptor)\n\n return internal(\n (context) => ({\n fontSize: px(descriptor.fontSize),\n lineHeight: px(descriptor.lineHeight),\n ...(monospace && {\n fontFamily: 'monospace',\n }),\n ...(bold && {\n fontWeight: 'bold',\n }),\n ...(useHalfLeadingCanceller(context) && {\n // prevent margin collapsing\n display: 'flow-root',\n // cancel half-leading with negative margin\n '&::before': {\n ...leadingCancel,\n marginTop: px(margin),\n },\n '&::after': {\n ...leadingCancel,\n marginBottom: px(margin),\n },\n }),\n }),\n !preserveHalfLeading\n ? {\n cancelHalfLeadingPx: margin,\n }\n : {}\n )\n }\n\nconst leadingCancel: CSSObject = {\n display: 'block',\n width: 0,\n height: 0,\n content: `''`,\n}\n\nfunction spacingProperty(\n property: SpacingProperty,\n direction: 'top' | 'right' | 'bottom' | 'left'\n) {\n return `${property}-${direction}`\n}\n\nconst createSpacingCss =\n <T extends Theme>(theme: { spacing: T['spacing'] }) =>\n (\n property: SpacingProperty,\n modifiers: readonly [SpacingDirection, keyof T['spacing'] | 'auto'][]\n ): Internal => {\n const { top, right, bottom, left } = modifiers.reduce(\n (acc, [direction, size]) => {\n if (direction === 'all') {\n acc.top = size\n acc.right = size\n acc.bottom = size\n acc.left = size\n } else if (direction === 'vertical') {\n acc.top = size\n acc.bottom = size\n } else if (direction === 'horizontal') {\n acc.right = size\n acc.left = size\n } else {\n acc[direction] = size\n }\n return acc\n },\n {} as Partial<\n Record<'top' | 'right' | 'bottom' | 'left', keyof T['spacing'] | 'auto'>\n >\n )\n\n const hasVerticalPadding =\n property === 'padding' &&\n top !== undefined &&\n bottom !== undefined &&\n top !== 'auto' &&\n bottom !== 'auto'\n\n return internal(\n ({ cancelHalfLeadingPx = 0 }) => ({\n ...(top !== undefined && {\n [spacingProperty(property, 'top')]:\n top === 'auto'\n ? 'auto'\n : px(\n theme.spacing[top] +\n (hasVerticalPadding ? cancelHalfLeadingPx : 0)\n ),\n }),\n ...(bottom !== undefined && {\n [spacingProperty(property, 'bottom')]:\n bottom === 'auto'\n ? 'auto'\n : px(\n theme.spacing[bottom] +\n (hasVerticalPadding ? cancelHalfLeadingPx : 0)\n ),\n }),\n ...(right !== undefined && {\n [spacingProperty(property, 'right')]:\n right === 'auto' ? 'auto' : px(theme.spacing[right]),\n }),\n ...(left !== undefined && {\n [spacingProperty(property, 'left')]:\n left === 'auto' ? 'auto' : px(theme.spacing[left]),\n }),\n }),\n hasVerticalPadding ? { hasVerticalPadding: true } : {}\n )\n }\n\nconst createFixedPxCss =\n <T extends Theme>(theme: T) =>\n (property: FixedProperty, size: keyof T['spacing'] | 'auto'): Internal =>\n internal(() => ({\n [property]: size === 'auto' ? 'auto' : px(theme.spacing[size]),\n }))\n\nconst createFixedRelativeCss =\n <T extends Theme>(_theme: T) =>\n (property: FixedProperty, amount: '100%' | 'auto'): Internal =>\n internal(() => ({\n [property]: amount,\n }))\n\nconst createFixedColumnCss =\n <T extends Theme>(theme: T) =>\n (property: FixedProperty, span: number): Internal =>\n internal(() => ({\n [property]: px(\n columnSystem(span, theme.grid.unit.column, theme.grid.unit.gutter)\n ),\n }))\n\nconst createElementEffectCss =\n <T extends Theme, TElementEffect extends T['elementEffect']>(theme: {\n elementEffect: TElementEffect\n }) =>\n (effects: readonly (keyof TElementEffect)[] = []): Internal =>\n internal(() =>\n effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n opacity:\n !(Array as ReadonlyArrayConstructor).isArray(\n theme.elementEffect[effect]\n ) && theme.elementEffect[effect]?.type === 'opacity'\n ? theme.elementEffect[effect]?.opacity\n : unreachable(),\n }),\n }),\n {}\n )\n )\n\nfunction borderProperty(direction: BorderDirection) {\n return `border-${direction}`\n}\n\nfunction borderShorthand(color: string) {\n return `solid 1px ${color}`\n}\n\nconst createBorderCss =\n <T extends Theme>(theme: T) =>\n (\n variant: keyof T['border'],\n directions: readonly BorderDirection[]\n ): Internal => {\n const all = directions.length === 0\n const value = borderShorthand(theme.border[variant].color)\n return internal(() => ({\n ...(all\n ? { border: value }\n : directions.reduce<CSSObject>(\n (acc, direction) => ({\n ...acc,\n [borderProperty(direction)]: value,\n }),\n {}\n )),\n }))\n }\n\nconst createBorderRadiusCss =\n <T extends Theme>(theme: T) =>\n (size: keyof T['borderRadius']): Internal =>\n internal(() => ({\n borderRadius: px(theme.borderRadius[size]),\n }))\n\ninterface Context {\n cancelHalfLeadingPx?: number\n hasVerticalPadding?: boolean\n boxShadowTransition?: boolean\n colorTransition?: boolean\n backgroundColorTransition?: boolean\n}\n\nconst commonSpec = (_theme: unknown): Internal => {\n const duration = dur(TRANSITION_DURATION)\n const transition = (property: string[]) => ({\n transition: property.map((v) => `${duration} ${v}`).join(', '),\n })\n return internal(\n ({\n colorTransition = false,\n backgroundColorTransition = false,\n boxShadowTransition = false,\n }) =>\n transition(\n [\n colorTransition ? 'color' : null,\n backgroundColorTransition ? 'background-color' : null,\n boxShadowTransition ? 'box-shadow' : null,\n ].filter(isPresent)\n )\n )\n}\n\nconst internalSym: unique symbol = Symbol('internal')\n\nfunction internal(\n operation: (context: Context) => CSSObject,\n context: Context = {}\n): Internal {\n return {\n [internalSym]: {\n operation,\n context,\n },\n }\n}\n\nexport interface Internal {\n [internalSym]: {\n operation: (context: Context) => CSSObject\n context: Context\n }\n}\n\ntype Blank = null | undefined | false\n\nconst nonBlank = <T>(value: T): value is T extends Blank ? never : T =>\n isPresent(value) && (value as unknown) !== false\n\n/**\n * `theme(o => [...])` の `theme` ユーティリティを構築する\n *\n * @param _styled styled-componnets の `styled` そのもの (型推論のために用いられる)\n *\n * @example\n *\n * import styled from 'styled-components'\n * const theme = createTheme(styled)\n *\n * @example\n *\n * const theme = createTheme<DefaultTheme>()\n */\nfunction createTheme<T extends Theme>(_styled?: ThemedStyledInterface<T>) {\n // `theme(o => [...])` の `o` の部分の型推論のためだけに使う意味のない変数\n // Tを型変数のまま渡してcreateThemeが呼ばれるまで型の具象化が行われないようにする\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n const _phantomBuilder = builder<T>({} as any, true)\n // ランタイムの `theme(o => [...])` のインターフェースを構築する\n return (\n // ユーザー定義\n spec: (\n o: typeof _phantomBuilder\n ) => Blank | Internal | (Blank | Internal)[]\n ): ThemeProp<T> =>\n ({ theme }) => {\n // styled-componentsのランタイムから受け取ったthemeオブジェクトをbuilderに食わせて`o`をつくる\n // さらに、ユーザー定義にbuilderが構築した`o`を食わせる\n // (`o`を一時変数に入れてしまうと型Tの具象化が行われるので関数合成を優先する)\n const rawSpecDescriptor = spec(builder(theme))\n // ユーザー定義の配列を整形\n const specDescriptor = [\n ...(Array.isArray(rawSpecDescriptor)\n ? rawSpecDescriptor\n : [rawSpecDescriptor]),\n commonSpec(theme),\n ].filter(nonBlank)\n\n // 1パス目\n // 全ユーザー定義を舐めて相互に影響し合う定義をチェックし、その結果(コンテキスト)を取得\n const context = specDescriptor.reduce<Context>(\n (acc, v) => ({ ...acc, ...v[internalSym].context }),\n {}\n )\n // 2パス目\n // コンテキストを見ながら最適化されたCSSを構築\n return specDescriptor.map((v) => v[internalSym].operation(context))\n }\n}\n\nexport default createTheme\n\nexport type ThemeProp<T> = ({ theme }: { theme: T }) => CSSObject | CSSObject[]\n"],"names":["unreachable","value","Error","arguments","length","JSON","stringify","isPresent","objectAssign","Object","assign","objectKeys","obj","keys","factory","source","member","chain","defineProperties","fromEntries","map","key","get","enumerable","configurable","constFactory","def","modifiedFactory","modifiers","recursiveModifiedFactory","applied","notApplied","filter","v","includes","modifier","spacingProperties","spacingDirections","fixedProperties","borderDirections","outlineType","builder","theme","isPhantom","colors","color","effects","effect","gradientColors","gradientColor","colorCss","createColorCss","gradientColorCss","createGradientColorCss","colorObject","bg","direction","font","typographyModifiers","typographyCss","createTypographyCss","typographyObject","_","size","preserveHalfLeading","monospace","bold","spacingCss","createSpacingCss","spacingObject","spacingProperty","argumentedFactory","fixedPxCss","createFixedPxCss","fixedColumnCss","createFixedColumnCss","fixedRelativeCss","createFixedRelativeCss","fixedObject","property","px","column","span","auto","full","elementEffectCss","createElementEffectCss","elementEffectObject","elementEffect","borderCss","createBorderCss","borderObject","border","variant","borderRadiusCss","createBorderRadiusCss","borderRadiusObject","borderRadius","radius","outlineCss","createOutlineColorCss","outline","targetProperty","target","isSupportedEffect","onEffectPseudo","css","notDisabledSelector","disabledSelector","internal","reduce","acc","applyEffect","colorTransition","backgroundColorTransition","toLinearGradient","gradient","context","optimized","useHalfLeadingCanceller","duration","dur","position","zIndex","overflow","overlayElement","transition","backgroundColor","warning","applyEffectToGradient","weight","boxShadow","boxShadowTransition","content","display","width","height","top","left","hasVerticalPadding","undefined","cancelHalfLeadingPx","options","descriptor","typography","margin","halfLeading","fontSize","lineHeight","fontFamily","fontWeight","leadingCancel","marginTop","marginBottom","right","bottom","spacing","_theme","amount","columnSystem","grid","unit","gutter","opacity","Array","isArray","type","_theme$elementEffect$2","directions","all","borderProperty","internalSym","Symbol","operation","nonBlank","_styled","spec","rawSpecDescriptor","specDescriptor","join"],"mappings":"uZAwBgBA,EAAYC,GAC1B,UAAUC,MACa,IAArBC,UAAUC,OACN,8BACgBC,KAAKC,UAAUL,YAS1BM,EAAY,SAAIN,UAA+C,MAATA,YAsBnDO,IACd,OAAOC,OAAOC,aAAPD,QAAc,+CAGPE,EAAiCC,GAC/C,OAAOH,OAAOI,KAAKD,OC9CRE,EAAU,SACrBC,EACAC,EACAC,UAEAR,OAAOS,iBACLH,EACAN,OAAOU,YACLH,EAAOI,IAAI,SAACC,SAAQ,CAClBA,EACA,CAAEC,IAAK,kBAAML,EAAMI,IAAME,YAAY,EAAMC,cAAc,SA6DpDC,EAAe,SAC1BV,EACAW,UAEAZ,EAAQC,EAAQN,OAAOI,KAAKa,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KAcN,IAAMyD,EAAW,SAAI7K,UACnBM,EAAUN,KAAiC,IAAtBA,kBAgBvB,SAAsC8K,GAMpC,OAFwBtI,EAAW,IAAW,YAI1CuI,0BApEExD,EA4EIyD,EAAoBD,EAAKvI,IAJ9BC,QAMKwI,EAAiB,UACjBd,MAAMC,QAAQY,GACdA,EACA,CAACA,KAjFLzD,EAAWC,MAjWS,IAqWnBZ,EACL,oBACEI,oBACAC,8BACAkB,0BAPwC,CAC1CN,WASI,eACoB,QAAU,mBACA,mBAAqB,mBAC3B,aAAe,MACrC9F,OAAOzB,GAbQa,IAAI,SAACa,UAASuF,MAAYvF,IAAKkJ,KAAK,YAiFrDnJ,OAAO8I,GAIHzD,EAAU6D,EAAepE,OAC7B,SAACC,EAAK9E,eAAY8E,EAAQ9E,EAAE0I,GAAatD,UACzC,IAIF,OAAO6D,EAAe9J,IAAI,SAACa,UAAMA,EAAE0I,GAAaE,UAAUxD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/util.ts","../src/lib.ts","../src/index.ts"],"sourcesContent":["/**\n * Function used to assert a given code path is unreachable\n */\nexport function unreachable(): never\n/**\n * Function used to assert a given code path is unreachable.\n * Very useful for ensuring switches are exhaustive:\n *\n * ```ts\n * switch (a.type) {\n * case Types.A:\n * case Types.B:\n * break\n * default:\n * unreachable(a) // will cause a build error if there was\n * // a Types.C that was not checked\n * }\n * ```\n *\n * @param value Value to be asserted as unreachable\n */\n// NOTE: Uses separate overloads, _not_ `value?: never`, to not allow `undefined` to be passed\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport function unreachable(value: never): never\nexport function unreachable(value?: never): never {\n throw new Error(\n arguments.length === 0\n ? 'unreachable'\n : `unreachable (${JSON.stringify(value)})`\n )\n}\n\n/**\n * Check whether a value is non-null and non-undefined\n *\n * @param value nullable\n */\nexport const isPresent = <T>(value: T): value is NonNullable<T> => value != null\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Head<U> = U extends [infer T, ...any[]] ? T : never\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Tail<U> = U extends [any, any, ...any[]]\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ((...args: U) => any) extends (head: any, ...args: infer T) => any\n ? T\n : never\n : never\n// Buggy at ts@4.0.0-dev20200506\n// type Tail<U> = U extends [any, ...infer T] ? T : never\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype RecursiveObjectAssign<T, S extends any[]> = {\n 0: T & Head<S>\n 1: RecursiveObjectAssign<T & Head<S>, Tail<S>>\n}[Tail<S> extends never ? 0 : 1]\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ObjectAssign<T extends any[]> = RecursiveObjectAssign<\n Record<string, unknown>,\n T\n>\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function objectAssign<T extends any[]>(...sources: T) {\n return Object.assign({}, ...sources) as ObjectAssign<T>\n}\n\nexport function objectKeys<V, K extends keyof V>(obj: V) {\n return Object.keys(obj) as K[]\n}\n\nexport interface ReadonlyArrayConstructor {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n isArray(value: any): value is readonly any[]\n}\n\nexport function extractNonNullKeys<V, K extends keyof V>(obj: {\n [key in K]: V[key]\n}) {\n return Object.entries(obj)\n .filter(([_, v]) => v !== null)\n .map(([k]) => k) as { [key in K]: V[key] extends null ? never : key }[K][]\n}\n","import { Key } from '@charcoal-ui/theme'\nimport { unreachable } from './util'\n\n/**\n * 配列で指定したプロパティを動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param member オブジェクトに生やすプロパティ一覧\n * @param chain プロパティに格納される値を生成する関数\n *\n * @example\n *\n * const o = factory({}, ['red', 'blue'],\n * color => hex(color)\n * )\n *\n * console.log(o.red) //=> #ff0000\n */\nexport const factory = <TSource, TMember extends readonly Key[], TValue>(\n source: TSource,\n member: TMember,\n chain: (key: TMember[number]) => TValue\n) =>\n Object.defineProperties(\n source,\n Object.fromEntries(\n member.map((key) => [\n key,\n { get: () => chain(key), enumerable: true, configurable: true },\n ])\n )\n ) as TSource & { readonly [key in TMember[number]]: TValue }\n\n/**\n * 配列で指定した名前のメソッドを動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param member オブジェクトに生やすメソッド名一覧\n * @param chain メソッドの戻り値になる値を生成する関数\n *\n * @example\n *\n * const o = argumentedFactory({}, ['red', 'blue'],\n * (color, alpha: number) => hex(color, alpha)\n * )\n *\n * console.log(o.red(0.5)) //=> #ff000077\n */\nexport const argumentedFactory = <\n TSource,\n TMember extends readonly string[],\n TValue,\n TArguments extends unknown[]\n>(\n source: TSource,\n member: TMember,\n chain: (key: TMember[number], ...args: TArguments) => TValue\n) =>\n Object.defineProperties(\n source,\n Object.fromEntries(\n member.map((key) => [\n key,\n {\n value: (...args: TArguments) => chain(key, ...args),\n enumerable: true,\n configurable: true,\n },\n ])\n )\n ) as TSource & {\n readonly [key in TMember[number]]: (...args: TArguments) => TValue\n }\n\n/**\n * オブジェクトで指定したプロパティ名と値を動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param def オブジェクトに生やす定義(プロパティ名と値)\n *\n * @example\n *\n * const o = constFactory({}, {\n * red: '#f00',\n * blue: '#00f',\n * })\n *\n * console.log(o.red) //=> #f00\n */\nexport const constFactory = <TSource, TDef extends { [key: string]: unknown }>(\n source: TSource,\n def: TDef\n) =>\n factory(source, Object.keys(def), (key) => def[key]) as TSource &\n Readonly<TDef>\n\n/**\n * 配列で指定したモディファイア(プロパティ)をチェーン可能な再帰オブジェクトを動的に生やす\n *\n * @param modifiers オブジェクトに生やすモディファイヤ一覧\n * @param source 指定されたモディファイヤの一覧から値を生成する関数\n *\n * @example\n *\n * const o = modifiedArgumentedFactory(['red', 'blue'],\n * modifiers => modifiers.map(color => hex(color)).join(',')\n * )\n *\n * console.log(o.red.blue) => #f00,#00f\n */\nexport const modifiedFactory = <TSource, T extends Key>(\n modifiers: readonly T[],\n source: (applied: readonly T[]) => TSource\n) =>\n (function recursiveModifiedFactory(\n applied: readonly T[]\n ): Modified<TSource, T> {\n const notApplied = modifiers.filter((v) => !applied.includes(v))\n return factory(source(applied), notApplied, (modifier) =>\n notApplied.length === 0\n ? unreachable()\n : recursiveModifiedFactory([...applied, modifier])\n )\n })([])\n\nexport type Modified<TSource, TModifiers extends Key> = TSource & {\n readonly [key in TModifiers]: Modified<TSource, Exclude<TModifiers, key>>\n}\n\n/**\n * 配列で指定したモディファイア(メソッド)をチェーン可能な再帰オブジェクトを動的に生やす\n *\n * @param modifiers オブジェクトに生やすモディファイヤ一覧\n * @param source 指定されたモディファイヤの一覧から値を生成する関数\n * @param _inferPhantom 関数形式のモディファイヤの引数型を推論するためのメタタイプ(引数の個数に合わせてタプルで指定する)\n *\n * @example\n *\n * const o = modifiedArgumentedFactory(['red', 'blue'],\n * modifiers => modifiers.map(([color, alpha]) => hex(color, alpha)).join(',')\n * , {} as [number])\n *\n * console.log(o.red(0.5).blue(1)) => #ff000077,#0000ffff\n */\nexport const modifiedArgumentedFactory = <\n TSource,\n T extends string,\n TArguments extends unknown[]\n>(\n modifiers: readonly T[],\n source: (applied: readonly [T, ...TArguments][]) => TSource,\n ..._inferPhantom: TArguments\n) =>\n (function recursiveModifiedFactory(\n applied: readonly [T, ...TArguments][]\n ): ModifiedArgumented<TSource, T, TArguments> {\n const notApplied = modifiers.filter(\n (v) => !applied.map(([w]) => w).includes(v)\n )\n return argumentedFactory(\n source(applied),\n notApplied,\n (modifier, ...args: TArguments) =>\n notApplied.length === 0\n ? unreachable()\n : recursiveModifiedFactory([...applied, [modifier, ...args]])\n )\n })([])\n\nexport type ModifiedArgumented<\n TSource,\n TModifiers extends string,\n TArguments extends unknown[]\n> = TSource & {\n readonly [key in TModifiers]: (\n ...args: TArguments\n ) => ModifiedArgumented<TSource, Exclude<TModifiers, key>, TArguments>\n}\n","import { CSSObject, ThemedStyledInterface } from 'styled-components'\nimport warning from 'warning'\nimport {\n factory,\n modifiedFactory,\n constFactory,\n modifiedArgumentedFactory,\n} from './lib'\nimport {\n EffectType,\n CharcoalAbstractTheme as Theme,\n Key,\n} from '@charcoal-ui/theme'\nimport {\n objectAssign,\n unreachable,\n ReadonlyArrayConstructor,\n objectKeys,\n isPresent,\n} from './util'\nimport { columnSystem } from '@charcoal-ui/foundation'\nimport {\n halfLeading,\n applyEffect,\n applyEffectToGradient,\n dur,\n gradient,\n GradientDirection,\n notDisabledSelector,\n disabledSelector,\n px,\n} from '@charcoal-ui/utils'\nexport { type Modified, type ModifiedArgumented } from './lib'\n\nconst colorProperties = ['bg', 'font'] as const\ntype ColorProperty = typeof colorProperties[number]\n\nconst spacingProperties = ['margin', 'padding'] as const\nconst spacingDirections = [\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'vertical',\n 'horizontal',\n 'all',\n] as const\ntype SpacingProperty = typeof spacingProperties[number]\ntype SpacingDirection = typeof spacingDirections[number]\n\nconst fixedProperties = ['width', 'height'] as const\ntype FixedProperty = typeof fixedProperties[number]\n\nconst borderDirections = ['top', 'right', 'bottom', 'left'] as const\ntype BorderDirection = typeof borderDirections[number]\n\nconst outlineType = ['focus'] as const\ntype OutlineType = typeof outlineType[number]\n\n/**\n * `theme(o => [...])` の `o` の部分を構築する\n *\n * @param theme テーマオブジェクト\n * @param isPhantom 型推論のためだけに使う場合にランタイムコストをゼロにするフラグ\n */\nfunction builder<T extends Theme>(\n theme: {\n // factoryの第二引数に入れ込むものだけ明示的に型変数を展開しておくことで型の具象化を遅延する\n color: T['color']\n gradientColor: T['gradientColor']\n border: T['border']\n outline: T['outline']\n } & Omit<T, 'color' | 'gradientColor' | 'border' | 'outline'>,\n isPhantom = false\n) {\n if (isPhantom) {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n return {} as never\n }\n const colors = objectKeys(theme.color)\n const effects = objectKeys(theme.effect)\n\n // 色\n const gradientColors = objectKeys(theme.gradientColor)\n const colorCss = createColorCss(theme)\n const gradientColorCss = createGradientColorCss(theme)\n const colorObject = constFactory(\n {},\n {\n bg: objectAssign(\n factory({}, colors, (color) =>\n modifiedFactory(effects, (modifiers) =>\n colorCss('bg', color, modifiers)\n )\n ),\n factory(\n {},\n gradientColors,\n (color) => (direction: GradientDirection) =>\n modifiedFactory(effects, (modifiers) =>\n gradientColorCss(color, modifiers, direction)\n )\n )\n ),\n font: factory({}, colors, (color) =>\n modifiedFactory(effects, (modifiers) =>\n colorCss('font', color, modifiers)\n )\n ),\n }\n )\n\n // タイポグラフィ\n const typographyModifiers = [\n // TODO\n 'monospace',\n 'bold',\n 'preserveHalfLeading',\n ] as const\n const typographyCss = createTypographyCss(theme)\n const typographyObject = factory(\n {},\n ['typography'] as const,\n (_) => (size: keyof T['typography']['size']) =>\n modifiedFactory(typographyModifiers, (modifiers) =>\n typographyCss(size, {\n preserveHalfLeading: modifiers.includes('preserveHalfLeading'),\n monospace: modifiers.includes('monospace'),\n bold: modifiers.includes('bold'),\n })\n )\n )\n\n // スペーシング\n const spacingCss = createSpacingCss(theme)\n const spacingObject = factory({}, spacingProperties, (spacingProperty) =>\n modifiedArgumentedFactory(\n spacingDirections,\n (modifiers) => spacingCss(spacingProperty, modifiers),\n {} as keyof T['spacing'] | 'auto' // 推論のためのメタタイプ\n )\n )\n\n // 大きさ\n const fixedPxCss = createFixedPxCss(theme)\n const fixedColumnCss = createFixedColumnCss(theme)\n const fixedRelativeCss = createFixedRelativeCss(theme)\n const fixedObject = factory({}, fixedProperties, (property) =>\n constFactory(\n {},\n {\n px: (size: keyof T['spacing'] | 'auto') => fixedPxCss(property, size),\n column: (span: number) => fixedColumnCss(property, span),\n auto: fixedRelativeCss(property, 'auto'),\n full: fixedRelativeCss(property, '100%'),\n }\n )\n )\n\n // 要素へのエフェクト (etc: 透過)\n const elementEffectCss = createElementEffectCss(theme)\n const elementEffectObject = modifiedFactory(\n objectKeys(theme.elementEffect),\n (modifiers) => elementEffectCss(modifiers)\n )\n\n // ボーダー\n const borderCss = createBorderCss(theme)\n const borderObject = constFactory(\n {},\n {\n border: factory({}, objectKeys(theme.border), (variant) =>\n modifiedFactory(borderDirections, (modifiers) =>\n borderCss(variant, modifiers)\n )\n ),\n }\n )\n\n // 角丸\n const borderRadiusCss = createBorderRadiusCss(theme)\n const borderRadiusObject = constFactory(\n {},\n {\n borderRadius: (radius: keyof T['borderRadius']) =>\n borderRadiusCss(radius),\n }\n )\n\n // アウトライン\n const outlineCss = createOutlineColorCss(theme)\n const outlineObject = constFactory(\n {},\n {\n outline: factory({}, objectKeys(theme.outline), (variant) =>\n modifiedFactory(outlineType, (modifiers) =>\n outlineCss(variant, modifiers)\n )\n ),\n }\n )\n\n return objectAssign(\n colorObject,\n typographyObject,\n spacingObject,\n fixedObject,\n elementEffectObject,\n borderObject,\n borderRadiusObject,\n outlineObject\n )\n}\n\nfunction targetProperty(target: ColorProperty) {\n return target === 'bg' ? 'background-color' : 'color'\n}\n\nfunction isSupportedEffect(effect: Key): effect is EffectType {\n return ['hover', 'press', 'disabled'].includes(effect as string)\n}\n\nfunction onEffectPseudo(effect: EffectType, css: CSSObject) {\n return effect === 'hover'\n ? { '&:hover': { [notDisabledSelector]: css } }\n : effect === 'press'\n ? { '&:active': { [notDisabledSelector]: css } }\n : // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n effect === 'disabled'\n ? { [disabledSelector]: css }\n : unreachable(effect)\n}\n\nconst createColorCss =\n <T extends Theme>(theme: T) =>\n (\n target: ColorProperty,\n color: keyof T['color'],\n effects: readonly (keyof T['effect'])[] = []\n ): Internal =>\n internal(\n () => ({\n [targetProperty(target)]: theme.color[color],\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n [targetProperty(target)]: applyEffect(\n theme.color[color],\n theme.effect[effect] ?? []\n ),\n }),\n }),\n {}\n ),\n }),\n effects.length > 0\n ? target === 'font'\n ? {\n colorTransition: true,\n }\n : {\n backgroundColorTransition: true,\n }\n : {}\n )\n\n// TODO: deprecate\nconst TRANSITION_DURATION = 0.2\n\nconst createGradientColorCss =\n <T extends Theme>(theme: T) =>\n (\n color: keyof T['gradientColor'],\n effects: readonly (keyof T['effect'])[] = [],\n direction: GradientDirection\n ): Internal => {\n const toLinearGradient = gradient(direction)\n return internal((context) => {\n const optimized = !useHalfLeadingCanceller(context)\n const duration = dur(TRANSITION_DURATION)\n if (optimized && effects.length > 0) {\n return {\n position: 'relative',\n zIndex: 0,\n overflow: 'hidden',\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n '&::before': {\n zIndex: -1,\n ...overlayElement,\n transition: `${duration} background-color`,\n },\n '&::after': {\n zIndex: -2,\n ...overlayElement,\n ...toLinearGradient(theme.gradientColor[color]),\n },\n ...onEffectPseudo(effect, {\n '&::before': {\n backgroundColor: applyEffect(\n null,\n theme.effect[effect] ?? []\n ),\n },\n }),\n }),\n {}\n ),\n }\n } else {\n warning(\n effects.length === 0,\n // eslint-disable-next-line max-len\n `'Transition' will not be applied. You can get around this by specifying 'preserveHalfLeading' or both 'padding' and 'typograpy'.`\n )\n return {\n ...toLinearGradient(theme.gradientColor[color]),\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n ...toLinearGradient(\n applyEffectToGradient(theme.effect[effect] ?? [])(\n theme.gradientColor[color]\n )\n ),\n }),\n }),\n {}\n ),\n }\n }\n })\n }\n\n/**\n * @see https://developer.mozilla.org/ja/docs/Web/CSS/:focus-visible#selectively_showing_the_focus_indicator\n */\nconst onFocus = (css: CSSObject) => ({\n [notDisabledSelector]: {\n '&:focus, &:active': {\n outline: 'none',\n ...css,\n },\n\n '&:focus:not(:focus-visible), &:active:not(:focus-visible)': {\n outline: 'none',\n },\n\n '&:focus-visible': {\n outline: 'none',\n ...css,\n },\n },\n})\n\nconst outlineCss = (weight: number, color: string) => ({\n boxShadow: `0 0 0 ${px(weight)} ${color}`,\n})\n\nconst createOutlineColorCss =\n <T extends Theme>(theme: T) =>\n (\n variant: keyof T['outline'],\n modifiers: readonly OutlineType[]\n ): Internal => {\n const weight = theme.outline[variant].weight\n const color = theme.outline[variant].color\n return internal(\n () =>\n modifiers.includes('focus')\n ? onFocus(outlineCss(weight, color))\n : { '&&': { [notDisabledSelector]: outlineCss(weight, color) } },\n {\n boxShadowTransition: true,\n }\n )\n }\n\nconst overlayElement: CSSObject = {\n content: \"''\",\n display: 'block',\n position: 'absolute',\n width: '100%',\n height: '100%',\n top: 0,\n left: 0,\n}\n\n// half-leadingをキャンセルするとき && 垂直方向のpaddingが無い時\n// -> before/afterを入れる\nconst useHalfLeadingCanceller = ({\n cancelHalfLeadingPx,\n hasVerticalPadding = false,\n}: Context) => cancelHalfLeadingPx !== undefined && !hasVerticalPadding\n\nconst createTypographyCss =\n <T extends Theme>(theme: T) =>\n (\n size: keyof T['typography']['size'],\n options: {\n preserveHalfLeading?: boolean\n monospace?: boolean\n bold?: boolean\n } = {}\n ): Internal => {\n const {\n preserveHalfLeading = false,\n monospace = false,\n bold = false,\n } = options\n const descriptor = theme.typography.size[size]\n const margin = -halfLeading(descriptor)\n\n return internal(\n (context) => ({\n fontSize: px(descriptor.fontSize),\n lineHeight: px(descriptor.lineHeight),\n ...(monospace && {\n fontFamily: 'monospace',\n }),\n ...(bold && {\n fontWeight: 'bold',\n }),\n ...(useHalfLeadingCanceller(context) && {\n // prevent margin collapsing\n display: 'flow-root',\n // cancel half-leading with negative margin\n '&::before': {\n ...leadingCancel,\n marginTop: px(margin),\n },\n '&::after': {\n ...leadingCancel,\n marginBottom: px(margin),\n },\n }),\n }),\n !preserveHalfLeading\n ? {\n cancelHalfLeadingPx: margin,\n }\n : {}\n )\n }\n\nconst leadingCancel: CSSObject = {\n display: 'block',\n width: 0,\n height: 0,\n content: `''`,\n}\n\nfunction spacingProperty(\n property: SpacingProperty,\n direction: 'top' | 'right' | 'bottom' | 'left'\n) {\n return `${property}-${direction}`\n}\n\nconst createSpacingCss =\n <T extends Theme>(theme: { spacing: T['spacing'] }) =>\n (\n property: SpacingProperty,\n modifiers: readonly [SpacingDirection, keyof T['spacing'] | 'auto'][]\n ): Internal => {\n const { top, right, bottom, left } = modifiers.reduce(\n (acc, [direction, size]) => {\n if (direction === 'all') {\n acc.top = size\n acc.right = size\n acc.bottom = size\n acc.left = size\n } else if (direction === 'vertical') {\n acc.top = size\n acc.bottom = size\n } else if (direction === 'horizontal') {\n acc.right = size\n acc.left = size\n } else {\n acc[direction] = size\n }\n return acc\n },\n {} as Partial<\n Record<'top' | 'right' | 'bottom' | 'left', keyof T['spacing'] | 'auto'>\n >\n )\n\n const hasVerticalPadding =\n property === 'padding' &&\n top !== undefined &&\n bottom !== undefined &&\n top !== 'auto' &&\n bottom !== 'auto'\n\n return internal(\n ({ cancelHalfLeadingPx = 0 }) => ({\n ...(top !== undefined && {\n [spacingProperty(property, 'top')]:\n top === 'auto'\n ? 'auto'\n : px(\n theme.spacing[top] +\n (hasVerticalPadding ? cancelHalfLeadingPx : 0)\n ),\n }),\n ...(bottom !== undefined && {\n [spacingProperty(property, 'bottom')]:\n bottom === 'auto'\n ? 'auto'\n : px(\n theme.spacing[bottom] +\n (hasVerticalPadding ? cancelHalfLeadingPx : 0)\n ),\n }),\n ...(right !== undefined && {\n [spacingProperty(property, 'right')]:\n right === 'auto' ? 'auto' : px(theme.spacing[right]),\n }),\n ...(left !== undefined && {\n [spacingProperty(property, 'left')]:\n left === 'auto' ? 'auto' : px(theme.spacing[left]),\n }),\n }),\n hasVerticalPadding ? { hasVerticalPadding: true } : {}\n )\n }\n\nconst createFixedPxCss =\n <T extends Theme>(theme: T) =>\n (property: FixedProperty, size: keyof T['spacing'] | 'auto'): Internal =>\n internal(() => ({\n [property]: size === 'auto' ? 'auto' : px(theme.spacing[size]),\n }))\n\nconst createFixedRelativeCss =\n <T extends Theme>(_theme: T) =>\n (property: FixedProperty, amount: '100%' | 'auto'): Internal =>\n internal(() => ({\n [property]: amount,\n }))\n\nconst createFixedColumnCss =\n <T extends Theme>(theme: T) =>\n (property: FixedProperty, span: number): Internal =>\n internal(() => ({\n [property]: px(\n columnSystem(span, theme.grid.unit.column, theme.grid.unit.gutter)\n ),\n }))\n\nconst createElementEffectCss =\n <T extends Theme, TElementEffect extends T['elementEffect']>(theme: {\n elementEffect: TElementEffect\n }) =>\n (effects: readonly (keyof TElementEffect)[] = []): Internal =>\n internal(() =>\n effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n opacity:\n !(Array as ReadonlyArrayConstructor).isArray(\n theme.elementEffect[effect]\n ) && theme.elementEffect[effect]?.type === 'opacity'\n ? theme.elementEffect[effect]?.opacity\n : unreachable(),\n }),\n }),\n {}\n )\n )\n\nfunction borderProperty(direction: BorderDirection) {\n return `border-${direction}`\n}\n\nfunction borderShorthand(color: string) {\n return `solid 1px ${color}`\n}\n\nconst createBorderCss =\n <T extends Theme>(theme: T) =>\n (\n variant: keyof T['border'],\n directions: readonly BorderDirection[]\n ): Internal => {\n const all = directions.length === 0\n const value = borderShorthand(theme.border[variant].color)\n return internal(() => ({\n ...(all\n ? { border: value }\n : directions.reduce<CSSObject>(\n (acc, direction) => ({\n ...acc,\n [borderProperty(direction)]: value,\n }),\n {}\n )),\n }))\n }\n\nconst createBorderRadiusCss =\n <T extends Theme>(theme: T) =>\n (size: keyof T['borderRadius']): Internal =>\n internal(() => ({\n borderRadius: px(theme.borderRadius[size]),\n }))\n\ninterface Context {\n cancelHalfLeadingPx?: number\n hasVerticalPadding?: boolean\n boxShadowTransition?: boolean\n colorTransition?: boolean\n backgroundColorTransition?: boolean\n}\n\nconst commonSpec = (_theme: unknown): Internal => {\n const duration = dur(TRANSITION_DURATION)\n const transition = (property: string[]) => ({\n transition: property.map((v) => `${duration} ${v}`).join(', '),\n })\n return internal(\n ({\n colorTransition = false,\n backgroundColorTransition = false,\n boxShadowTransition = false,\n }) =>\n transition(\n [\n colorTransition ? 'color' : null,\n backgroundColorTransition ? 'background-color' : null,\n boxShadowTransition ? 'box-shadow' : null,\n ].filter(isPresent)\n )\n )\n}\n\nconst internalSym: unique symbol = Symbol('internal')\n\nfunction internal(\n operation: (context: Context) => CSSObject,\n context: Context = {}\n): Internal {\n return {\n [internalSym]: {\n operation,\n context,\n },\n }\n}\n\nexport interface Internal {\n [internalSym]: {\n operation: (context: Context) => CSSObject\n context: Context\n }\n}\n\ntype Blank = null | undefined | false\n\nconst nonBlank = <T>(value: T): value is T extends Blank ? never : T =>\n isPresent(value) && (value as unknown) !== false\n\n/**\n * `theme(o => [...])` の `theme` ユーティリティを構築する\n *\n * @param _styled styled-componnets の `styled` そのもの (型推論のために用いられる)\n *\n * @example\n *\n * import styled from 'styled-components'\n * const theme = createTheme(styled)\n *\n * @example\n *\n * const theme = createTheme<DefaultTheme>()\n */\nfunction createTheme<T extends Theme>(_styled?: ThemedStyledInterface<T>) {\n // `theme(o => [...])` の `o` の部分の型推論のためだけに使う意味のない変数\n // Tを型変数のまま渡してcreateThemeが呼ばれるまで型の具象化が行われないようにする\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n const _phantomBuilder = builder<T>({} as any, true)\n // ランタイムの `theme(o => [...])` のインターフェースを構築する\n return (\n // ユーザー定義\n spec: (\n o: typeof _phantomBuilder\n ) => Blank | Internal | (Blank | Internal)[]\n ): ThemeProp<T> =>\n ({ theme }) => {\n // styled-componentsのランタイムから受け取ったthemeオブジェクトをbuilderに食わせて`o`をつくる\n // さらに、ユーザー定義にbuilderが構築した`o`を食わせる\n // (`o`を一時変数に入れてしまうと型Tの具象化が行われるので関数合成を優先する)\n const rawSpecDescriptor = spec(builder(theme))\n // ユーザー定義の配列を整形\n const specDescriptor = [\n ...(Array.isArray(rawSpecDescriptor)\n ? rawSpecDescriptor\n : [rawSpecDescriptor]),\n commonSpec(theme),\n ].filter(nonBlank)\n\n // 1パス目\n // 全ユーザー定義を舐めて相互に影響し合う定義をチェックし、その結果(コンテキスト)を取得\n const context = specDescriptor.reduce<Context>(\n (acc, v) => ({ ...acc, ...v[internalSym].context }),\n {}\n )\n // 2パス目\n // コンテキストを見ながら最適化されたCSSを構築\n return specDescriptor.map((v) => v[internalSym].operation(context))\n }\n}\n\nexport default createTheme\n\nexport type ThemeProp<T> = ({ theme }: { theme: T }) => CSSObject | CSSObject[]\n"],"names":["unreachable","value","Error","arguments","length","JSON","stringify","isPresent","objectAssign","Object","assign","objectKeys","obj","keys","factory","source","member","chain","defineProperties","fromEntries","map","key","get","enumerable","configurable","constFactory","def","modifiedFactory","modifiers","recursiveModifiedFactory","applied","notApplied","filter","v","includes","modifier","spacingProperties","spacingDirections","fixedProperties","borderDirections","outlineType","builder","theme","isPhantom","colors","color","effects","effect","gradientColors","gradientColor","colorCss","createColorCss","gradientColorCss","createGradientColorCss","colorObject","bg","direction","font","typographyModifiers","typographyCss","createTypographyCss","typographyObject","_","size","preserveHalfLeading","monospace","bold","spacingCss","createSpacingCss","spacingObject","spacingProperty","argumentedFactory","fixedPxCss","createFixedPxCss","fixedColumnCss","createFixedColumnCss","fixedRelativeCss","createFixedRelativeCss","fixedObject","property","px","column","span","auto","full","elementEffectCss","createElementEffectCss","elementEffectObject","elementEffect","borderCss","createBorderCss","borderObject","border","variant","borderRadiusCss","createBorderRadiusCss","borderRadiusObject","borderRadius","radius","outlineCss","createOutlineColorCss","outline","targetProperty","target","isSupportedEffect","onEffectPseudo","css","notDisabledSelector","disabledSelector","internal","reduce","acc","applyEffect","colorTransition","backgroundColorTransition","toLinearGradient","gradient","context","optimized","useHalfLeadingCanceller","duration","dur","position","zIndex","overflow","overlayElement","transition","backgroundColor","warning","applyEffectToGradient","weight","boxShadow","boxShadowTransition","content","display","width","height","top","left","hasVerticalPadding","undefined","cancelHalfLeadingPx","options","descriptor","typography","margin","halfLeading","fontSize","lineHeight","fontFamily","fontWeight","leadingCancel","marginTop","marginBottom","right","bottom","spacing","_theme","amount","columnSystem","grid","unit","gutter","opacity","Array","isArray","type","_theme$elementEffect$2","directions","all","borderProperty","internalSym","Symbol","operation","nonBlank","_styled","spec","rawSpecDescriptor","specDescriptor","join"],"mappings":"uZAwBgBA,EAAYC,GAC1B,UAAUC,MACa,IAArBC,UAAUC,OACN,8BACgBC,KAAKC,UAAUL,YAS1BM,EAAY,SAAIN,UAA+C,MAATA,YA4BnDO,IACd,OAAOC,OAAOC,aAAPD,QAAc,+CAGPE,EAAiCC,GAC/C,OAAOH,OAAOI,KAAKD,OCpDRE,EAAU,SACrBC,EACAC,EACAC,UAEAR,OAAOS,iBACLH,EACAN,OAAOU,YACLH,EAAOI,IAAI,SAACC,SAAQ,CAClBA,EACA,CAAEC,IAAK,kBAAML,EAAMI,IAAME,YAAY,EAAMC,cAAc,SA6DpDC,EAAe,SAC1BV,EACAW,UAEAZ,EAAQC,EAAQN,OAAOI,KAAKa,GAAM,SAACL,UAAQK,EAAIL,MAiBpCM,EAAkB,SAC7BC,EACAb,mBAEUc,EACRC,GAEA,IAAMC,EAAaH,EAAUI,OAAO,SAACC,UAAOH,EAAQI,SAASD,KAC7D,OAAOnB,EAAQC,EAAOe,GAAUC,EAAY,SAACI,UACrB,IAAtBJ,EAAW3B,OACPJ,IACA6B,YAA6BC,GAASK,QAE3C,KCtFCC,EAAoB,CAAC,SAAU,WAC/BC,EAAoB,CACxB,MACA,QACA,SACA,OACA,WACA,aACA,OAKIC,EAAkB,CAAC,QAAS,UAG5BC,EAAmB,CAAC,MAAO,QAAS,SAAU,QAG9CC,EAAc,CAAC,SASrB,SAASC,EACPC,EAOAC,GAEA,YAFAA,IAAAA,GAAY,GAERA,EAEF,MAAO,GAET,IAAMC,EAASjC,EAAW+B,EAAMG,OAC1BC,EAAUnC,EAAW+B,EAAMK,QAG3BC,EAAiBrC,EAAW+B,EAAMO,eAClCC,EAAWC,EAAeT,GAC1BU,EAAmBC,EAAuBX,GAC1CY,EAAc7B,EAClB,GACA,CACE8B,GAAI/C,EACFM,EAAQ,GAAI8B,EAAQ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AM8C,cAAczC,WAApBwH,EAA6BJ,YAIvC,QAYFzE,EACJ,SAAkBhD,mBAEhBmD,EACA2E,GAEA,IAAMC,EAA4B,IAAtBD,EAAWpK,OACjBH,eAAwByC,EAAMkD,OAAOC,GAAShD,MACpD,OAAOgE,EAAS,uBACV4D,EACA,CAAE7E,OAAQ3F,GACVuK,EAAW1D,OACT,SAACC,EAAKvD,qBACDuD,UArBjB,SAAwBvD,GACtB,gBAAiBA,EAqBJkH,CAAelH,IAAavD,OAE/B,SAKN8F,EACJ,SAAkBrD,mBACjBqB,UACC8C,EAAS,iBAAO,CACdZ,aAAcjB,KAAGtC,EAAMuD,aAAalC,SAgCpC4G,EAA6BC,OAAO,YAE1C,SAAS/D,EACPgE,EACAxD,SAEA,gBAFAA,IAAAA,EAAmB,WAGhBsD,GAAc,CACbE,UAAAA,EACAxD,QAAAA,KAcN,IAAMyD,EAAW,SAAI7K,UACnBM,EAAUN,KAAiC,IAAtBA,kBAgBvB,SAAsC8K,GAMpC,OAFwBtI,EAAW,IAAW,YAI1CuI,0BApEExD,EA4EIyD,EAAoBD,EAAKvI,IAJ9BC,QAMKwI,EAAiB,UACjBd,MAAMC,QAAQY,GACdA,EACA,CAACA,KAjFLzD,EAAWC,MAjWS,IAqWnBZ,EACL,oBACEI,oBACAC,8BACAkB,0BAPwC,CAC1CN,WASI,eACoB,QAAU,mBACA,mBAAqB,mBAC3B,aAAe,MACrC9F,OAAOzB,GAbQa,IAAI,SAACa,UAASuF,MAAYvF,IAAKkJ,KAAK,YAiFrDnJ,OAAO8I,GAIHzD,EAAU6D,EAAepE,OAC7B,SAACC,EAAK9E,eAAY8E,EAAQ9E,EAAE0I,GAAatD,UACzC,IAIF,OAAO6D,EAAe9J,IAAI,SAACa,UAAMA,EAAE0I,GAAaE,UAAUxD"}
|
package/dist/index.modern.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/util.ts","../src/lib.ts","../src/index.ts"],"sourcesContent":["/**\n * Function used to assert a given code path is unreachable\n */\nexport function unreachable(): never\n/**\n * Function used to assert a given code path is unreachable.\n * Very useful for ensuring switches are exhaustive:\n *\n * ```ts\n * switch (a.type) {\n * case Types.A:\n * case Types.B:\n * break\n * default:\n * unreachable(a) // will cause a build error if there was\n * // a Types.C that was not checked\n * }\n * ```\n *\n * @param value Value to be asserted as unreachable\n */\n// NOTE: Uses separate overloads, _not_ `value?: never`, to not allow `undefined` to be passed\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport function unreachable(value: never): never\nexport function unreachable(value?: never): never {\n throw new Error(\n arguments.length === 0\n ? 'unreachable'\n : `unreachable (${JSON.stringify(value)})`\n )\n}\n\n/**\n * Check whether a value is non-null and non-undefined\n *\n * @param value nullable\n */\nexport const isPresent = <T>(value: T): value is NonNullable<T> => value != null\n\ntype Head<U> = U extends [infer T, ...any[]] ? T : never\n\ntype Tail<U> = U extends [any, any, ...any[]]\n ? ((...args: U) => any) extends (head: any, ...args: infer T) => any\n ? T\n : never\n : never\n// Buggy at ts@4.0.0-dev20200506\n// type Tail<U> = U extends [any, ...infer T] ? T : never\n\ntype RecursiveObjectAssign<T, S extends any[]> = {\n 0: T & Head<S>\n 1: RecursiveObjectAssign<T & Head<S>, Tail<S>>\n}[Tail<S> extends never ? 0 : 1]\n\ntype ObjectAssign<T extends any[]> = RecursiveObjectAssign<\n Record<string, unknown>,\n T\n>\n\nexport function objectAssign<T extends any[]>(...sources: T) {\n return Object.assign({}, ...sources) as ObjectAssign<T>\n}\n\nexport function objectKeys<V, K extends keyof V>(obj: V) {\n return Object.keys(obj) as K[]\n}\n\nexport interface ReadonlyArrayConstructor {\n isArray(value: any): value is readonly any[]\n}\n\nexport function extractNonNullKeys<V, K extends keyof V>(obj: {\n [key in K]: V[key]\n}) {\n return Object.entries(obj)\n .filter(([_, v]) => v !== null)\n .map(([k]) => k) as { [key in K]: V[key] extends null ? never : key }[K][]\n}\n","import { Key } from '@charcoal-ui/theme'\nimport { unreachable } from './util'\n\n/**\n * 配列で指定したプロパティを動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param member オブジェクトに生やすプロパティ一覧\n * @param chain プロパティに格納される値を生成する関数\n *\n * @example\n *\n * const o = factory({}, ['red', 'blue'],\n * color => hex(color)\n * )\n *\n * console.log(o.red) //=> #ff0000\n */\nexport const factory = <TSource, TMember extends readonly Key[], TValue>(\n source: TSource,\n member: TMember,\n chain: (key: TMember[number]) => TValue\n) =>\n Object.defineProperties(\n source,\n Object.fromEntries(\n member.map((key) => [\n key,\n { get: () => chain(key), enumerable: true, configurable: true },\n ])\n )\n ) as TSource & { readonly [key in TMember[number]]: TValue }\n\n/**\n * 配列で指定した名前のメソッドを動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param member オブジェクトに生やすメソッド名一覧\n * @param chain メソッドの戻り値になる値を生成する関数\n *\n * @example\n *\n * const o = argumentedFactory({}, ['red', 'blue'],\n * (color, alpha: number) => hex(color, alpha)\n * )\n *\n * console.log(o.red(0.5)) //=> #ff000077\n */\nexport const argumentedFactory = <\n TSource,\n TMember extends readonly string[],\n TValue,\n TArguments extends unknown[]\n>(\n source: TSource,\n member: TMember,\n chain: (key: TMember[number], ...args: TArguments) => TValue\n) =>\n Object.defineProperties(\n source,\n Object.fromEntries(\n member.map((key) => [\n key,\n {\n value: (...args: TArguments) => chain(key, ...args),\n enumerable: true,\n configurable: true,\n },\n ])\n )\n ) as TSource & {\n readonly [key in TMember[number]]: (...args: TArguments) => TValue\n }\n\n/**\n * オブジェクトで指定したプロパティ名と値を動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param def オブジェクトに生やす定義(プロパティ名と値)\n *\n * @example\n *\n * const o = constFactory({}, {\n * red: '#f00',\n * blue: '#00f',\n * })\n *\n * console.log(o.red) //=> #f00\n */\nexport const constFactory = <TSource, TDef extends { [key: string]: unknown }>(\n source: TSource,\n def: TDef\n) =>\n factory(source, Object.keys(def), (key) => def[key]) as TSource &\n Readonly<TDef>\n\n/**\n * 配列で指定したモディファイア(プロパティ)をチェーン可能な再帰オブジェクトを動的に生やす\n *\n * @param modifiers オブジェクトに生やすモディファイヤ一覧\n * @param source 指定されたモディファイヤの一覧から値を生成する関数\n *\n * @example\n *\n * const o = modifiedArgumentedFactory(['red', 'blue'],\n * modifiers => modifiers.map(color => hex(color)).join(',')\n * )\n *\n * console.log(o.red.blue) => #f00,#00f\n */\nexport const modifiedFactory = <TSource, T extends Key>(\n modifiers: readonly T[],\n source: (applied: readonly T[]) => TSource\n) =>\n (function recursiveModifiedFactory(\n applied: readonly T[]\n ): Modified<TSource, T> {\n const notApplied = modifiers.filter((v) => !applied.includes(v))\n return factory(source(applied), notApplied, (modifier) =>\n notApplied.length === 0\n ? unreachable()\n : recursiveModifiedFactory([...applied, modifier])\n )\n })([])\n\nexport type Modified<TSource, TModifiers extends Key> = TSource & {\n readonly [key in TModifiers]: Modified<TSource, Exclude<TModifiers, key>>\n}\n\n/**\n * 配列で指定したモディファイア(メソッド)をチェーン可能な再帰オブジェクトを動的に生やす\n *\n * @param modifiers オブジェクトに生やすモディファイヤ一覧\n * @param source 指定されたモディファイヤの一覧から値を生成する関数\n * @param _inferPhantom 関数形式のモディファイヤの引数型を推論するためのメタタイプ(引数の個数に合わせてタプルで指定する)\n *\n * @example\n *\n * const o = modifiedArgumentedFactory(['red', 'blue'],\n * modifiers => modifiers.map(([color, alpha]) => hex(color, alpha)).join(',')\n * , {} as [number])\n *\n * console.log(o.red(0.5).blue(1)) => #ff000077,#0000ffff\n */\nexport const modifiedArgumentedFactory = <\n TSource,\n T extends string,\n TArguments extends unknown[]\n>(\n modifiers: readonly T[],\n source: (applied: readonly [T, ...TArguments][]) => TSource,\n ..._inferPhantom: TArguments\n) =>\n (function recursiveModifiedFactory(\n applied: readonly [T, ...TArguments][]\n ): ModifiedArgumented<TSource, T, TArguments> {\n const notApplied = modifiers.filter(\n (v) => !applied.map(([w]) => w).includes(v)\n )\n return argumentedFactory(\n source(applied),\n notApplied,\n (modifier, ...args: TArguments) =>\n notApplied.length === 0\n ? unreachable()\n : recursiveModifiedFactory([...applied, [modifier, ...args]])\n )\n })([])\n\nexport type ModifiedArgumented<\n TSource,\n TModifiers extends string,\n TArguments extends unknown[]\n> = TSource & {\n readonly [key in TModifiers]: (\n ...args: TArguments\n ) => ModifiedArgumented<TSource, Exclude<TModifiers, key>, TArguments>\n}\n","import { CSSObject, ThemedStyledInterface } from 'styled-components'\nimport warning from 'warning'\nimport {\n factory,\n modifiedFactory,\n constFactory,\n modifiedArgumentedFactory,\n} from './lib'\nimport {\n EffectType,\n CharcoalAbstractTheme as Theme,\n Key,\n} from '@charcoal-ui/theme'\nimport {\n objectAssign,\n unreachable,\n ReadonlyArrayConstructor,\n objectKeys,\n isPresent,\n} from './util'\nimport { columnSystem } from '@charcoal-ui/foundation'\nimport {\n halfLeading,\n applyEffect,\n applyEffectToGradient,\n dur,\n gradient,\n GradientDirection,\n notDisabledSelector,\n disabledSelector,\n px,\n} from '@charcoal-ui/utils'\nexport { type Modified, type ModifiedArgumented } from './lib'\n\nconst colorProperties = ['bg', 'font'] as const\ntype ColorProperty = typeof colorProperties[number]\n\nconst spacingProperties = ['margin', 'padding'] as const\nconst spacingDirections = [\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'vertical',\n 'horizontal',\n 'all',\n] as const\ntype SpacingProperty = typeof spacingProperties[number]\ntype SpacingDirection = typeof spacingDirections[number]\n\nconst fixedProperties = ['width', 'height'] as const\ntype FixedProperty = typeof fixedProperties[number]\n\nconst borderDirections = ['top', 'right', 'bottom', 'left'] as const\ntype BorderDirection = typeof borderDirections[number]\n\nconst outlineType = ['focus'] as const\ntype OutlineType = typeof outlineType[number]\n\n/**\n * `theme(o => [...])` の `o` の部分を構築する\n *\n * @param theme テーマオブジェクト\n * @param isPhantom 型推論のためだけに使う場合にランタイムコストをゼロにするフラグ\n */\nfunction builder<T extends Theme>(\n theme: {\n // factoryの第二引数に入れ込むものだけ明示的に型変数を展開しておくことで型の具象化を遅延する\n color: T['color']\n gradientColor: T['gradientColor']\n border: T['border']\n outline: T['outline']\n } & Omit<T, 'color' | 'gradientColor' | 'border' | 'outline'>,\n isPhantom = false\n) {\n if (isPhantom) {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n return {} as never\n }\n const colors = objectKeys(theme.color)\n const effects = objectKeys(theme.effect)\n\n // 色\n const gradientColors = objectKeys(theme.gradientColor)\n const colorCss = createColorCss(theme)\n const gradientColorCss = createGradientColorCss(theme)\n const colorObject = constFactory(\n {},\n {\n bg: objectAssign(\n factory({}, colors, (color) =>\n modifiedFactory(effects, (modifiers) =>\n colorCss('bg', color, modifiers)\n )\n ),\n factory(\n {},\n gradientColors,\n (color) => (direction: GradientDirection) =>\n modifiedFactory(effects, (modifiers) =>\n gradientColorCss(color, modifiers, direction)\n )\n )\n ),\n font: factory({}, colors, (color) =>\n modifiedFactory(effects, (modifiers) =>\n colorCss('font', color, modifiers)\n )\n ),\n }\n )\n\n // タイポグラフィ\n const typographyModifiers = [\n // TODO\n 'monospace',\n 'bold',\n 'preserveHalfLeading',\n ] as const\n const typographyCss = createTypographyCss(theme)\n const typographyObject = factory(\n {},\n ['typography'] as const,\n (_) => (size: keyof T['typography']['size']) =>\n modifiedFactory(typographyModifiers, (modifiers) =>\n typographyCss(size, {\n preserveHalfLeading: modifiers.includes('preserveHalfLeading'),\n monospace: modifiers.includes('monospace'),\n bold: modifiers.includes('bold'),\n })\n )\n )\n\n // スペーシング\n const spacingCss = createSpacingCss(theme)\n const spacingObject = factory({}, spacingProperties, (spacingProperty) =>\n modifiedArgumentedFactory(\n spacingDirections,\n (modifiers) => spacingCss(spacingProperty, modifiers),\n {} as keyof T['spacing'] | 'auto' // 推論のためのメタタイプ\n )\n )\n\n // 大きさ\n const fixedPxCss = createFixedPxCss(theme)\n const fixedColumnCss = createFixedColumnCss(theme)\n const fixedRelativeCss = createFixedRelativeCss(theme)\n const fixedObject = factory({}, fixedProperties, (property) =>\n constFactory(\n {},\n {\n px: (size: keyof T['spacing'] | 'auto') => fixedPxCss(property, size),\n column: (span: number) => fixedColumnCss(property, span),\n auto: fixedRelativeCss(property, 'auto'),\n full: fixedRelativeCss(property, '100%'),\n }\n )\n )\n\n // 要素へのエフェクト (etc: 透過)\n const elementEffectCss = createElementEffectCss(theme)\n const elementEffectObject = modifiedFactory(\n objectKeys(theme.elementEffect),\n (modifiers) => elementEffectCss(modifiers)\n )\n\n // ボーダー\n const borderCss = createBorderCss(theme)\n const borderObject = constFactory(\n {},\n {\n border: factory({}, objectKeys(theme.border), (variant) =>\n modifiedFactory(borderDirections, (modifiers) =>\n borderCss(variant, modifiers)\n )\n ),\n }\n )\n\n // 角丸\n const borderRadiusCss = createBorderRadiusCss(theme)\n const borderRadiusObject = constFactory(\n {},\n {\n borderRadius: (radius: keyof T['borderRadius']) =>\n borderRadiusCss(radius),\n }\n )\n\n // アウトライン\n const outlineCss = createOutlineColorCss(theme)\n const outlineObject = constFactory(\n {},\n {\n outline: factory({}, objectKeys(theme.outline), (variant) =>\n modifiedFactory(outlineType, (modifiers) =>\n outlineCss(variant, modifiers)\n )\n ),\n }\n )\n\n return objectAssign(\n colorObject,\n typographyObject,\n spacingObject,\n fixedObject,\n elementEffectObject,\n borderObject,\n borderRadiusObject,\n outlineObject\n )\n}\n\nfunction targetProperty(target: ColorProperty) {\n return target === 'bg' ? 'background-color' : 'color'\n}\n\nfunction isSupportedEffect(effect: Key): effect is EffectType {\n return ['hover', 'press', 'disabled'].includes(effect as string)\n}\n\nfunction onEffectPseudo(effect: EffectType, css: CSSObject) {\n return effect === 'hover'\n ? { '&:hover': { [notDisabledSelector]: css } }\n : effect === 'press'\n ? { '&:active': { [notDisabledSelector]: css } }\n : // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n effect === 'disabled'\n ? { [disabledSelector]: css }\n : unreachable(effect)\n}\n\nconst createColorCss =\n <T extends Theme>(theme: T) =>\n (\n target: ColorProperty,\n color: keyof T['color'],\n effects: readonly (keyof T['effect'])[] = []\n ): Internal =>\n internal(\n () => ({\n [targetProperty(target)]: theme.color[color],\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n [targetProperty(target)]: applyEffect(\n theme.color[color],\n theme.effect[effect] ?? []\n ),\n }),\n }),\n {}\n ),\n }),\n effects.length > 0\n ? target === 'font'\n ? {\n colorTransition: true,\n }\n : {\n backgroundColorTransition: true,\n }\n : {}\n )\n\n// TODO: deprecate\nconst TRANSITION_DURATION = 0.2\n\nconst createGradientColorCss =\n <T extends Theme>(theme: T) =>\n (\n color: keyof T['gradientColor'],\n effects: readonly (keyof T['effect'])[] = [],\n direction: GradientDirection\n ): Internal => {\n const toLinearGradient = gradient(direction)\n return internal((context) => {\n const optimized = !useHalfLeadingCanceller(context)\n const duration = dur(TRANSITION_DURATION)\n if (optimized && effects.length > 0) {\n return {\n position: 'relative',\n zIndex: 0,\n overflow: 'hidden',\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n '&::before': {\n zIndex: -1,\n ...overlayElement,\n transition: `${duration} background-color`,\n },\n '&::after': {\n zIndex: -2,\n ...overlayElement,\n ...toLinearGradient(theme.gradientColor[color]),\n },\n ...onEffectPseudo(effect, {\n '&::before': {\n backgroundColor: applyEffect(\n null,\n theme.effect[effect] ?? []\n ),\n },\n }),\n }),\n {}\n ),\n }\n } else {\n warning(\n effects.length === 0,\n // eslint-disable-next-line max-len\n `'Transition' will not be applied. You can get around this by specifying 'preserveHalfLeading' or both 'padding' and 'typograpy'.`\n )\n return {\n ...toLinearGradient(theme.gradientColor[color]),\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n ...toLinearGradient(\n applyEffectToGradient(theme.effect[effect] ?? [])(\n theme.gradientColor[color]\n )\n ),\n }),\n }),\n {}\n ),\n }\n }\n })\n }\n\n/**\n * @see https://developer.mozilla.org/ja/docs/Web/CSS/:focus-visible#selectively_showing_the_focus_indicator\n */\nconst onFocus = (css: CSSObject) => ({\n [notDisabledSelector]: {\n '&:focus, &:active': {\n outline: 'none',\n ...css,\n },\n\n '&:focus:not(:focus-visible), &:active:not(:focus-visible)': {\n outline: 'none',\n },\n\n '&:focus-visible': {\n outline: 'none',\n ...css,\n },\n },\n})\n\nconst outlineCss = (weight: number, color: string) => ({\n boxShadow: `0 0 0 ${px(weight)} ${color}`,\n})\n\nconst createOutlineColorCss =\n <T extends Theme>(theme: T) =>\n (\n variant: keyof T['outline'],\n modifiers: readonly OutlineType[]\n ): Internal => {\n const weight = theme.outline[variant].weight\n const color = theme.outline[variant].color\n return internal(\n () =>\n modifiers.includes('focus')\n ? onFocus(outlineCss(weight, color))\n : { '&&': { [notDisabledSelector]: outlineCss(weight, color) } },\n {\n boxShadowTransition: true,\n }\n )\n }\n\nconst overlayElement: CSSObject = {\n content: \"''\",\n display: 'block',\n position: 'absolute',\n width: '100%',\n height: '100%',\n top: 0,\n left: 0,\n}\n\n// half-leadingをキャンセルするとき && 垂直方向のpaddingが無い時\n// -> before/afterを入れる\nconst useHalfLeadingCanceller = ({\n cancelHalfLeadingPx,\n hasVerticalPadding = false,\n}: Context) => cancelHalfLeadingPx !== undefined && !hasVerticalPadding\n\nconst createTypographyCss =\n <T extends Theme>(theme: T) =>\n (\n size: keyof T['typography']['size'],\n options: {\n preserveHalfLeading?: boolean\n monospace?: boolean\n bold?: boolean\n } = {}\n ): Internal => {\n const {\n preserveHalfLeading = false,\n monospace = false,\n bold = false,\n } = options\n const descriptor = theme.typography.size[size]\n const margin = -halfLeading(descriptor)\n\n return internal(\n (context) => ({\n fontSize: px(descriptor.fontSize),\n lineHeight: px(descriptor.lineHeight),\n ...(monospace && {\n fontFamily: 'monospace',\n }),\n ...(bold && {\n fontWeight: 'bold',\n }),\n ...(useHalfLeadingCanceller(context) && {\n // prevent margin collapsing\n display: 'flow-root',\n // cancel half-leading with negative margin\n '&::before': {\n ...leadingCancel,\n marginTop: px(margin),\n },\n '&::after': {\n ...leadingCancel,\n marginBottom: px(margin),\n },\n }),\n }),\n !preserveHalfLeading\n ? {\n cancelHalfLeadingPx: margin,\n }\n : {}\n )\n }\n\nconst leadingCancel: CSSObject = {\n display: 'block',\n width: 0,\n height: 0,\n content: `''`,\n}\n\nfunction spacingProperty(\n property: SpacingProperty,\n direction: 'top' | 'right' | 'bottom' | 'left'\n) {\n return `${property}-${direction}`\n}\n\nconst createSpacingCss =\n <T extends Theme>(theme: { spacing: T['spacing'] }) =>\n (\n property: SpacingProperty,\n modifiers: readonly [SpacingDirection, keyof T['spacing'] | 'auto'][]\n ): Internal => {\n const { top, right, bottom, left } = modifiers.reduce(\n (acc, [direction, size]) => {\n if (direction === 'all') {\n acc.top = size\n acc.right = size\n acc.bottom = size\n acc.left = size\n } else if (direction === 'vertical') {\n acc.top = size\n acc.bottom = size\n } else if (direction === 'horizontal') {\n acc.right = size\n acc.left = size\n } else {\n acc[direction] = size\n }\n return acc\n },\n {} as Partial<\n Record<'top' | 'right' | 'bottom' | 'left', keyof T['spacing'] | 'auto'>\n >\n )\n\n const hasVerticalPadding =\n property === 'padding' &&\n top !== undefined &&\n bottom !== undefined &&\n top !== 'auto' &&\n bottom !== 'auto'\n\n return internal(\n ({ cancelHalfLeadingPx = 0 }) => ({\n ...(top !== undefined && {\n [spacingProperty(property, 'top')]:\n top === 'auto'\n ? 'auto'\n : px(\n theme.spacing[top] +\n (hasVerticalPadding ? cancelHalfLeadingPx : 0)\n ),\n }),\n ...(bottom !== undefined && {\n [spacingProperty(property, 'bottom')]:\n bottom === 'auto'\n ? 'auto'\n : px(\n theme.spacing[bottom] +\n (hasVerticalPadding ? cancelHalfLeadingPx : 0)\n ),\n }),\n ...(right !== undefined && {\n [spacingProperty(property, 'right')]:\n right === 'auto' ? 'auto' : px(theme.spacing[right]),\n }),\n ...(left !== undefined && {\n [spacingProperty(property, 'left')]:\n left === 'auto' ? 'auto' : px(theme.spacing[left]),\n }),\n }),\n hasVerticalPadding ? { hasVerticalPadding: true } : {}\n )\n }\n\nconst createFixedPxCss =\n <T extends Theme>(theme: T) =>\n (property: FixedProperty, size: keyof T['spacing'] | 'auto'): Internal =>\n internal(() => ({\n [property]: size === 'auto' ? 'auto' : px(theme.spacing[size]),\n }))\n\nconst createFixedRelativeCss =\n <T extends Theme>(_theme: T) =>\n (property: FixedProperty, amount: '100%' | 'auto'): Internal =>\n internal(() => ({\n [property]: amount,\n }))\n\nconst createFixedColumnCss =\n <T extends Theme>(theme: T) =>\n (property: FixedProperty, span: number): Internal =>\n internal(() => ({\n [property]: px(\n columnSystem(span, theme.grid.unit.column, theme.grid.unit.gutter)\n ),\n }))\n\nconst createElementEffectCss =\n <T extends Theme, TElementEffect extends T['elementEffect']>(theme: {\n elementEffect: TElementEffect\n }) =>\n (effects: readonly (keyof TElementEffect)[] = []): Internal =>\n internal(() =>\n effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n opacity:\n !(Array as ReadonlyArrayConstructor).isArray(\n theme.elementEffect[effect]\n ) && theme.elementEffect[effect]?.type === 'opacity'\n ? theme.elementEffect[effect]?.opacity\n : unreachable(),\n }),\n }),\n {}\n )\n )\n\nfunction borderProperty(direction: BorderDirection) {\n return `border-${direction}`\n}\n\nfunction borderShorthand(color: string) {\n return `solid 1px ${color}`\n}\n\nconst createBorderCss =\n <T extends Theme>(theme: T) =>\n (\n variant: keyof T['border'],\n directions: readonly BorderDirection[]\n ): Internal => {\n const all = directions.length === 0\n const value = borderShorthand(theme.border[variant].color)\n return internal(() => ({\n ...(all\n ? { border: value }\n : directions.reduce<CSSObject>(\n (acc, direction) => ({\n ...acc,\n [borderProperty(direction)]: value,\n }),\n {}\n )),\n }))\n }\n\nconst createBorderRadiusCss =\n <T extends Theme>(theme: T) =>\n (size: keyof T['borderRadius']): Internal =>\n internal(() => ({\n borderRadius: px(theme.borderRadius[size]),\n }))\n\ninterface Context {\n cancelHalfLeadingPx?: number\n hasVerticalPadding?: boolean\n boxShadowTransition?: boolean\n colorTransition?: boolean\n backgroundColorTransition?: boolean\n}\n\nconst commonSpec = (_theme: unknown): Internal => {\n const duration = dur(TRANSITION_DURATION)\n const transition = (property: string[]) => ({\n transition: property.map((v) => `${duration} ${v}`).join(', '),\n })\n return internal(\n ({\n colorTransition = false,\n backgroundColorTransition = false,\n boxShadowTransition = false,\n }) =>\n transition(\n [\n colorTransition ? 'color' : null,\n backgroundColorTransition ? 'background-color' : null,\n boxShadowTransition ? 'box-shadow' : null,\n ].filter(isPresent)\n )\n )\n}\n\nconst internalSym: unique symbol = Symbol('internal')\n\nfunction internal(\n operation: (context: Context) => CSSObject,\n context: Context = {}\n): Internal {\n return {\n [internalSym]: {\n operation,\n context,\n },\n }\n}\n\nexport interface Internal {\n [internalSym]: {\n operation: (context: Context) => CSSObject\n context: Context\n }\n}\n\ntype Blank = null | undefined | false\n\nconst nonBlank = <T>(value: T): value is T extends Blank ? never : T =>\n isPresent(value) && (value as unknown) !== false\n\n/**\n * `theme(o => [...])` の `theme` ユーティリティを構築する\n *\n * @param _styled styled-componnets の `styled` そのもの (型推論のために用いられる)\n *\n * @example\n *\n * import styled from 'styled-components'\n * const theme = createTheme(styled)\n *\n * @example\n *\n * const theme = createTheme<DefaultTheme>()\n */\nfunction createTheme<T extends Theme>(_styled?: ThemedStyledInterface<T>) {\n // `theme(o => [...])` の `o` の部分の型推論のためだけに使う意味のない変数\n // Tを型変数のまま渡してcreateThemeが呼ばれるまで型の具象化が行われないようにする\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n const _phantomBuilder = builder<T>({} as any, true)\n // ランタイムの `theme(o => [...])` のインターフェースを構築する\n return (\n // ユーザー定義\n spec: (\n o: typeof _phantomBuilder\n ) => Blank | Internal | (Blank | Internal)[]\n ): ThemeProp<T> =>\n ({ theme }) => {\n // styled-componentsのランタイムから受け取ったthemeオブジェクトをbuilderに食わせて`o`をつくる\n // さらに、ユーザー定義にbuilderが構築した`o`を食わせる\n // (`o`を一時変数に入れてしまうと型Tの具象化が行われるので関数合成を優先する)\n const rawSpecDescriptor = spec(builder(theme))\n // ユーザー定義の配列を整形\n const specDescriptor = [\n ...(Array.isArray(rawSpecDescriptor)\n ? rawSpecDescriptor\n : [rawSpecDescriptor]),\n commonSpec(theme),\n ].filter(nonBlank)\n\n // 1パス目\n // 全ユーザー定義を舐めて相互に影響し合う定義をチェックし、その結果(コンテキスト)を取得\n const context = specDescriptor.reduce<Context>(\n (acc, v) => ({ ...acc, ...v[internalSym].context }),\n {}\n )\n // 2パス目\n // コンテキストを見ながら最適化されたCSSを構築\n return specDescriptor.map((v) => v[internalSym].operation(context))\n }\n}\n\nexport default createTheme\n\nexport type ThemeProp<T> = ({ theme }: { theme: T }) => CSSObject | CSSObject[]\n"],"names":["unreachable","value","Error","arguments","length","JSON","stringify","isPresent","objectAssign","sources","Object","assign","objectKeys","obj","keys","factory","source","member","chain","defineProperties","fromEntries","map","key","get","enumerable","configurable","constFactory","def","modifiedFactory","modifiers","recursiveModifiedFactory","applied","notApplied","filter","v","includes","modifier","spacingProperties","spacingDirections","fixedProperties","borderDirections","outlineType","builder","theme","isPhantom","colors","color","effects","effect","gradientColors","gradientColor","colorCss","createColorCss","gradientColorCss","createGradientColorCss","colorObject","bg","direction","font","typographyModifiers","typographyCss","createTypographyCss","typographyObject","_","size","preserveHalfLeading","monospace","bold","spacingCss","createSpacingCss","spacingObject","spacingProperty","modifiedArgumentedFactory","w","args","argumentedFactory","fixedPxCss","createFixedPxCss","fixedColumnCss","createFixedColumnCss","fixedRelativeCss","createFixedRelativeCss","fixedObject","property","px","column","span","auto","full","elementEffectCss","createElementEffectCss","elementEffectObject","elementEffect","borderCss","createBorderCss","borderObject","border","variant","borderRadiusCss","createBorderRadiusCss","borderRadiusObject","borderRadius","radius","outlineCss","createOutlineColorCss","outline","targetProperty","target","isSupportedEffect","onEffectPseudo","css","notDisabledSelector","disabledSelector","internal","reduce","acc","applyEffect","colorTransition","backgroundColorTransition","toLinearGradient","gradient","context","optimized","useHalfLeadingCanceller","duration","dur","position","zIndex","overflow","overlayElement","transition","backgroundColor","warning","applyEffectToGradient","weight","boxShadow","boxShadowTransition","content","display","width","height","top","left","cancelHalfLeadingPx","hasVerticalPadding","undefined","options","descriptor","typography","margin","halfLeading","fontSize","lineHeight","fontFamily","fontWeight","leadingCancel","marginTop","marginBottom","right","bottom","spacing","_theme","amount","columnSystem","grid","unit","gutter","opacity","Array","isArray","type","_theme$elementEffect$2","borderProperty","directions","all","commonSpec","join","internalSym","Symbol","operation","nonBlank","createTheme","_styled","spec","rawSpecDescriptor","specDescriptor"],"mappings":"kdAwBgBA,EAAYC,GAC1B,UAAUC,MACa,IAArBC,UAAUC,OACN,8BACgBC,KAAKC,UAAUL,aAS1BM,EAAgBN,GAA+C,MAATA,WAsBnDO,KAAiCC,GAC/C,OAAOC,OAAOC,OAAO,MAAOF,YAGdG,EAAiCC,GAC/C,OAAOH,OAAOI,KAAKD,SC9CRE,EAAU,CACrBC,EACAC,EACAC,IAEAR,OAAOS,iBACLH,EACAN,OAAOU,YACLH,EAAOI,IAAKC,GAAQ,CAClBA,EACA,CAAEC,IAAK,IAAML,EAAMI,GAAME,YAAY,EAAMC,cAAc,OA6DpDC,EAAe,CAC1BV,EACAW,IAEAZ,EAAQC,EAAQN,OAAOI,KAAKa,GAAOL,GAAQK,EAAIL,IAiBpCM,EAAkB,CAC7BC,EACAb,IAEC,SAASc,EACRC,GAEA,MAAMC,EAAaH,EAAUI,OAAQC,IAAOH,EAAQI,SAASD,IAC7D,OAAOnB,EAAQC,EAAOe,GAAUC,EAAaI,GACrB,IAAtBJ,EAAW5B,OACPJ,IACA8B,EAAyB,IAAIC,EAASK,KAP7C,CASE,ICtFCC,EAAoB,CAAC,SAAU,WAC/BC,EAAoB,CACxB,MACA,QACA,SACA,OACA,WACA,aACA,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AA6BC,GAMpC,OAFwB5I,EAAW,IAAW,GAI1C6I,GAIF,EAAG5I,MAAAA,MAID,MAAM6I,EAAoBD,EAAK7I,EAAQC,IAEjC8I,EAAiB,IACjBjB,MAAMC,QAAQe,GACdA,EACA,CAACA,GACLT,KACA9I,OAAOmJ,GAIH3D,EAAUgE,EAAevE,OAC7B,CAACC,EAAKjF,SAAYiF,EAAQjF,EAAE+I,GAAaxD,SACzC,IAIF,OAAOgE,EAAepK,IAAKa,GAAMA,EAAE+I,GAAaE,UAAU1D"}
|
|
1
|
+
{"version":3,"file":"index.modern.js","sources":["../src/util.ts","../src/lib.ts","../src/index.ts"],"sourcesContent":["/**\n * Function used to assert a given code path is unreachable\n */\nexport function unreachable(): never\n/**\n * Function used to assert a given code path is unreachable.\n * Very useful for ensuring switches are exhaustive:\n *\n * ```ts\n * switch (a.type) {\n * case Types.A:\n * case Types.B:\n * break\n * default:\n * unreachable(a) // will cause a build error if there was\n * // a Types.C that was not checked\n * }\n * ```\n *\n * @param value Value to be asserted as unreachable\n */\n// NOTE: Uses separate overloads, _not_ `value?: never`, to not allow `undefined` to be passed\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport function unreachable(value: never): never\nexport function unreachable(value?: never): never {\n throw new Error(\n arguments.length === 0\n ? 'unreachable'\n : `unreachable (${JSON.stringify(value)})`\n )\n}\n\n/**\n * Check whether a value is non-null and non-undefined\n *\n * @param value nullable\n */\nexport const isPresent = <T>(value: T): value is NonNullable<T> => value != null\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Head<U> = U extends [infer T, ...any[]] ? T : never\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Tail<U> = U extends [any, any, ...any[]]\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ((...args: U) => any) extends (head: any, ...args: infer T) => any\n ? T\n : never\n : never\n// Buggy at ts@4.0.0-dev20200506\n// type Tail<U> = U extends [any, ...infer T] ? T : never\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype RecursiveObjectAssign<T, S extends any[]> = {\n 0: T & Head<S>\n 1: RecursiveObjectAssign<T & Head<S>, Tail<S>>\n}[Tail<S> extends never ? 0 : 1]\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ObjectAssign<T extends any[]> = RecursiveObjectAssign<\n Record<string, unknown>,\n T\n>\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function objectAssign<T extends any[]>(...sources: T) {\n return Object.assign({}, ...sources) as ObjectAssign<T>\n}\n\nexport function objectKeys<V, K extends keyof V>(obj: V) {\n return Object.keys(obj) as K[]\n}\n\nexport interface ReadonlyArrayConstructor {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n isArray(value: any): value is readonly any[]\n}\n\nexport function extractNonNullKeys<V, K extends keyof V>(obj: {\n [key in K]: V[key]\n}) {\n return Object.entries(obj)\n .filter(([_, v]) => v !== null)\n .map(([k]) => k) as { [key in K]: V[key] extends null ? never : key }[K][]\n}\n","import { Key } from '@charcoal-ui/theme'\nimport { unreachable } from './util'\n\n/**\n * 配列で指定したプロパティを動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param member オブジェクトに生やすプロパティ一覧\n * @param chain プロパティに格納される値を生成する関数\n *\n * @example\n *\n * const o = factory({}, ['red', 'blue'],\n * color => hex(color)\n * )\n *\n * console.log(o.red) //=> #ff0000\n */\nexport const factory = <TSource, TMember extends readonly Key[], TValue>(\n source: TSource,\n member: TMember,\n chain: (key: TMember[number]) => TValue\n) =>\n Object.defineProperties(\n source,\n Object.fromEntries(\n member.map((key) => [\n key,\n { get: () => chain(key), enumerable: true, configurable: true },\n ])\n )\n ) as TSource & { readonly [key in TMember[number]]: TValue }\n\n/**\n * 配列で指定した名前のメソッドを動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param member オブジェクトに生やすメソッド名一覧\n * @param chain メソッドの戻り値になる値を生成する関数\n *\n * @example\n *\n * const o = argumentedFactory({}, ['red', 'blue'],\n * (color, alpha: number) => hex(color, alpha)\n * )\n *\n * console.log(o.red(0.5)) //=> #ff000077\n */\nexport const argumentedFactory = <\n TSource,\n TMember extends readonly string[],\n TValue,\n TArguments extends unknown[]\n>(\n source: TSource,\n member: TMember,\n chain: (key: TMember[number], ...args: TArguments) => TValue\n) =>\n Object.defineProperties(\n source,\n Object.fromEntries(\n member.map((key) => [\n key,\n {\n value: (...args: TArguments) => chain(key, ...args),\n enumerable: true,\n configurable: true,\n },\n ])\n )\n ) as TSource & {\n readonly [key in TMember[number]]: (...args: TArguments) => TValue\n }\n\n/**\n * オブジェクトで指定したプロパティ名と値を動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param def オブジェクトに生やす定義(プロパティ名と値)\n *\n * @example\n *\n * const o = constFactory({}, {\n * red: '#f00',\n * blue: '#00f',\n * })\n *\n * console.log(o.red) //=> #f00\n */\nexport const constFactory = <TSource, TDef extends { [key: string]: unknown }>(\n source: TSource,\n def: TDef\n) =>\n factory(source, Object.keys(def), (key) => def[key]) as TSource &\n Readonly<TDef>\n\n/**\n * 配列で指定したモディファイア(プロパティ)をチェーン可能な再帰オブジェクトを動的に生やす\n *\n * @param modifiers オブジェクトに生やすモディファイヤ一覧\n * @param source 指定されたモディファイヤの一覧から値を生成する関数\n *\n * @example\n *\n * const o = modifiedArgumentedFactory(['red', 'blue'],\n * modifiers => modifiers.map(color => hex(color)).join(',')\n * )\n *\n * console.log(o.red.blue) => #f00,#00f\n */\nexport const modifiedFactory = <TSource, T extends Key>(\n modifiers: readonly T[],\n source: (applied: readonly T[]) => TSource\n) =>\n (function recursiveModifiedFactory(\n applied: readonly T[]\n ): Modified<TSource, T> {\n const notApplied = modifiers.filter((v) => !applied.includes(v))\n return factory(source(applied), notApplied, (modifier) =>\n notApplied.length === 0\n ? unreachable()\n : recursiveModifiedFactory([...applied, modifier])\n )\n })([])\n\nexport type Modified<TSource, TModifiers extends Key> = TSource & {\n readonly [key in TModifiers]: Modified<TSource, Exclude<TModifiers, key>>\n}\n\n/**\n * 配列で指定したモディファイア(メソッド)をチェーン可能な再帰オブジェクトを動的に生やす\n *\n * @param modifiers オブジェクトに生やすモディファイヤ一覧\n * @param source 指定されたモディファイヤの一覧から値を生成する関数\n * @param _inferPhantom 関数形式のモディファイヤの引数型を推論するためのメタタイプ(引数の個数に合わせてタプルで指定する)\n *\n * @example\n *\n * const o = modifiedArgumentedFactory(['red', 'blue'],\n * modifiers => modifiers.map(([color, alpha]) => hex(color, alpha)).join(',')\n * , {} as [number])\n *\n * console.log(o.red(0.5).blue(1)) => #ff000077,#0000ffff\n */\nexport const modifiedArgumentedFactory = <\n TSource,\n T extends string,\n TArguments extends unknown[]\n>(\n modifiers: readonly T[],\n source: (applied: readonly [T, ...TArguments][]) => TSource,\n ..._inferPhantom: TArguments\n) =>\n (function recursiveModifiedFactory(\n applied: readonly [T, ...TArguments][]\n ): ModifiedArgumented<TSource, T, TArguments> {\n const notApplied = modifiers.filter(\n (v) => !applied.map(([w]) => w).includes(v)\n )\n return argumentedFactory(\n source(applied),\n notApplied,\n (modifier, ...args: TArguments) =>\n notApplied.length === 0\n ? unreachable()\n : recursiveModifiedFactory([...applied, [modifier, ...args]])\n )\n })([])\n\nexport type ModifiedArgumented<\n TSource,\n TModifiers extends string,\n TArguments extends unknown[]\n> = TSource & {\n readonly [key in TModifiers]: (\n ...args: TArguments\n ) => ModifiedArgumented<TSource, Exclude<TModifiers, key>, TArguments>\n}\n","import { CSSObject, ThemedStyledInterface } from 'styled-components'\nimport warning from 'warning'\nimport {\n factory,\n modifiedFactory,\n constFactory,\n modifiedArgumentedFactory,\n} from './lib'\nimport {\n EffectType,\n CharcoalAbstractTheme as Theme,\n Key,\n} from '@charcoal-ui/theme'\nimport {\n objectAssign,\n unreachable,\n ReadonlyArrayConstructor,\n objectKeys,\n isPresent,\n} from './util'\nimport { columnSystem } from '@charcoal-ui/foundation'\nimport {\n halfLeading,\n applyEffect,\n applyEffectToGradient,\n dur,\n gradient,\n GradientDirection,\n notDisabledSelector,\n disabledSelector,\n px,\n} from '@charcoal-ui/utils'\nexport { type Modified, type ModifiedArgumented } from './lib'\n\nconst colorProperties = ['bg', 'font'] as const\ntype ColorProperty = typeof colorProperties[number]\n\nconst spacingProperties = ['margin', 'padding'] as const\nconst spacingDirections = [\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'vertical',\n 'horizontal',\n 'all',\n] as const\ntype SpacingProperty = typeof spacingProperties[number]\ntype SpacingDirection = typeof spacingDirections[number]\n\nconst fixedProperties = ['width', 'height'] as const\ntype FixedProperty = typeof fixedProperties[number]\n\nconst borderDirections = ['top', 'right', 'bottom', 'left'] as const\ntype BorderDirection = typeof borderDirections[number]\n\nconst outlineType = ['focus'] as const\ntype OutlineType = typeof outlineType[number]\n\n/**\n * `theme(o => [...])` の `o` の部分を構築する\n *\n * @param theme テーマオブジェクト\n * @param isPhantom 型推論のためだけに使う場合にランタイムコストをゼロにするフラグ\n */\nfunction builder<T extends Theme>(\n theme: {\n // factoryの第二引数に入れ込むものだけ明示的に型変数を展開しておくことで型の具象化を遅延する\n color: T['color']\n gradientColor: T['gradientColor']\n border: T['border']\n outline: T['outline']\n } & Omit<T, 'color' | 'gradientColor' | 'border' | 'outline'>,\n isPhantom = false\n) {\n if (isPhantom) {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n return {} as never\n }\n const colors = objectKeys(theme.color)\n const effects = objectKeys(theme.effect)\n\n // 色\n const gradientColors = objectKeys(theme.gradientColor)\n const colorCss = createColorCss(theme)\n const gradientColorCss = createGradientColorCss(theme)\n const colorObject = constFactory(\n {},\n {\n bg: objectAssign(\n factory({}, colors, (color) =>\n modifiedFactory(effects, (modifiers) =>\n colorCss('bg', color, modifiers)\n )\n ),\n factory(\n {},\n gradientColors,\n (color) => (direction: GradientDirection) =>\n modifiedFactory(effects, (modifiers) =>\n gradientColorCss(color, modifiers, direction)\n )\n )\n ),\n font: factory({}, colors, (color) =>\n modifiedFactory(effects, (modifiers) =>\n colorCss('font', color, modifiers)\n )\n ),\n }\n )\n\n // タイポグラフィ\n const typographyModifiers = [\n // TODO\n 'monospace',\n 'bold',\n 'preserveHalfLeading',\n ] as const\n const typographyCss = createTypographyCss(theme)\n const typographyObject = factory(\n {},\n ['typography'] as const,\n (_) => (size: keyof T['typography']['size']) =>\n modifiedFactory(typographyModifiers, (modifiers) =>\n typographyCss(size, {\n preserveHalfLeading: modifiers.includes('preserveHalfLeading'),\n monospace: modifiers.includes('monospace'),\n bold: modifiers.includes('bold'),\n })\n )\n )\n\n // スペーシング\n const spacingCss = createSpacingCss(theme)\n const spacingObject = factory({}, spacingProperties, (spacingProperty) =>\n modifiedArgumentedFactory(\n spacingDirections,\n (modifiers) => spacingCss(spacingProperty, modifiers),\n {} as keyof T['spacing'] | 'auto' // 推論のためのメタタイプ\n )\n )\n\n // 大きさ\n const fixedPxCss = createFixedPxCss(theme)\n const fixedColumnCss = createFixedColumnCss(theme)\n const fixedRelativeCss = createFixedRelativeCss(theme)\n const fixedObject = factory({}, fixedProperties, (property) =>\n constFactory(\n {},\n {\n px: (size: keyof T['spacing'] | 'auto') => fixedPxCss(property, size),\n column: (span: number) => fixedColumnCss(property, span),\n auto: fixedRelativeCss(property, 'auto'),\n full: fixedRelativeCss(property, '100%'),\n }\n )\n )\n\n // 要素へのエフェクト (etc: 透過)\n const elementEffectCss = createElementEffectCss(theme)\n const elementEffectObject = modifiedFactory(\n objectKeys(theme.elementEffect),\n (modifiers) => elementEffectCss(modifiers)\n )\n\n // ボーダー\n const borderCss = createBorderCss(theme)\n const borderObject = constFactory(\n {},\n {\n border: factory({}, objectKeys(theme.border), (variant) =>\n modifiedFactory(borderDirections, (modifiers) =>\n borderCss(variant, modifiers)\n )\n ),\n }\n )\n\n // 角丸\n const borderRadiusCss = createBorderRadiusCss(theme)\n const borderRadiusObject = constFactory(\n {},\n {\n borderRadius: (radius: keyof T['borderRadius']) =>\n borderRadiusCss(radius),\n }\n )\n\n // アウトライン\n const outlineCss = createOutlineColorCss(theme)\n const outlineObject = constFactory(\n {},\n {\n outline: factory({}, objectKeys(theme.outline), (variant) =>\n modifiedFactory(outlineType, (modifiers) =>\n outlineCss(variant, modifiers)\n )\n ),\n }\n )\n\n return objectAssign(\n colorObject,\n typographyObject,\n spacingObject,\n fixedObject,\n elementEffectObject,\n borderObject,\n borderRadiusObject,\n outlineObject\n )\n}\n\nfunction targetProperty(target: ColorProperty) {\n return target === 'bg' ? 'background-color' : 'color'\n}\n\nfunction isSupportedEffect(effect: Key): effect is EffectType {\n return ['hover', 'press', 'disabled'].includes(effect as string)\n}\n\nfunction onEffectPseudo(effect: EffectType, css: CSSObject) {\n return effect === 'hover'\n ? { '&:hover': { [notDisabledSelector]: css } }\n : effect === 'press'\n ? { '&:active': { [notDisabledSelector]: css } }\n : // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n effect === 'disabled'\n ? { [disabledSelector]: css }\n : unreachable(effect)\n}\n\nconst createColorCss =\n <T extends Theme>(theme: T) =>\n (\n target: ColorProperty,\n color: keyof T['color'],\n effects: readonly (keyof T['effect'])[] = []\n ): Internal =>\n internal(\n () => ({\n [targetProperty(target)]: theme.color[color],\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n [targetProperty(target)]: applyEffect(\n theme.color[color],\n theme.effect[effect] ?? []\n ),\n }),\n }),\n {}\n ),\n }),\n effects.length > 0\n ? target === 'font'\n ? {\n colorTransition: true,\n }\n : {\n backgroundColorTransition: true,\n }\n : {}\n )\n\n// TODO: deprecate\nconst TRANSITION_DURATION = 0.2\n\nconst createGradientColorCss =\n <T extends Theme>(theme: T) =>\n (\n color: keyof T['gradientColor'],\n effects: readonly (keyof T['effect'])[] = [],\n direction: GradientDirection\n ): Internal => {\n const toLinearGradient = gradient(direction)\n return internal((context) => {\n const optimized = !useHalfLeadingCanceller(context)\n const duration = dur(TRANSITION_DURATION)\n if (optimized && effects.length > 0) {\n return {\n position: 'relative',\n zIndex: 0,\n overflow: 'hidden',\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n '&::before': {\n zIndex: -1,\n ...overlayElement,\n transition: `${duration} background-color`,\n },\n '&::after': {\n zIndex: -2,\n ...overlayElement,\n ...toLinearGradient(theme.gradientColor[color]),\n },\n ...onEffectPseudo(effect, {\n '&::before': {\n backgroundColor: applyEffect(\n null,\n theme.effect[effect] ?? []\n ),\n },\n }),\n }),\n {}\n ),\n }\n } else {\n warning(\n effects.length === 0,\n // eslint-disable-next-line max-len\n `'Transition' will not be applied. You can get around this by specifying 'preserveHalfLeading' or both 'padding' and 'typograpy'.`\n )\n return {\n ...toLinearGradient(theme.gradientColor[color]),\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n ...toLinearGradient(\n applyEffectToGradient(theme.effect[effect] ?? [])(\n theme.gradientColor[color]\n )\n ),\n }),\n }),\n {}\n ),\n }\n }\n })\n }\n\n/**\n * @see https://developer.mozilla.org/ja/docs/Web/CSS/:focus-visible#selectively_showing_the_focus_indicator\n */\nconst onFocus = (css: CSSObject) => ({\n [notDisabledSelector]: {\n '&:focus, &:active': {\n outline: 'none',\n ...css,\n },\n\n '&:focus:not(:focus-visible), &:active:not(:focus-visible)': {\n outline: 'none',\n },\n\n '&:focus-visible': {\n outline: 'none',\n ...css,\n },\n },\n})\n\nconst outlineCss = (weight: number, color: string) => ({\n boxShadow: `0 0 0 ${px(weight)} ${color}`,\n})\n\nconst createOutlineColorCss =\n <T extends Theme>(theme: T) =>\n (\n variant: keyof T['outline'],\n modifiers: readonly OutlineType[]\n ): Internal => {\n const weight = theme.outline[variant].weight\n const color = theme.outline[variant].color\n return internal(\n () =>\n modifiers.includes('focus')\n ? onFocus(outlineCss(weight, color))\n : { '&&': { [notDisabledSelector]: outlineCss(weight, color) } },\n {\n boxShadowTransition: true,\n }\n )\n }\n\nconst overlayElement: CSSObject = {\n content: \"''\",\n display: 'block',\n position: 'absolute',\n width: '100%',\n height: '100%',\n top: 0,\n left: 0,\n}\n\n// half-leadingをキャンセルするとき && 垂直方向のpaddingが無い時\n// -> before/afterを入れる\nconst useHalfLeadingCanceller = ({\n cancelHalfLeadingPx,\n hasVerticalPadding = false,\n}: Context) => cancelHalfLeadingPx !== undefined && !hasVerticalPadding\n\nconst createTypographyCss =\n <T extends Theme>(theme: T) =>\n (\n size: keyof T['typography']['size'],\n options: {\n preserveHalfLeading?: boolean\n monospace?: boolean\n bold?: boolean\n } = {}\n ): Internal => {\n const {\n preserveHalfLeading = false,\n monospace = false,\n bold = false,\n } = options\n const descriptor = theme.typography.size[size]\n const margin = -halfLeading(descriptor)\n\n return internal(\n (context) => ({\n fontSize: px(descriptor.fontSize),\n lineHeight: px(descriptor.lineHeight),\n ...(monospace && {\n fontFamily: 'monospace',\n }),\n ...(bold && {\n fontWeight: 'bold',\n }),\n ...(useHalfLeadingCanceller(context) && {\n // prevent margin collapsing\n display: 'flow-root',\n // cancel half-leading with negative margin\n '&::before': {\n ...leadingCancel,\n marginTop: px(margin),\n },\n '&::after': {\n ...leadingCancel,\n marginBottom: px(margin),\n },\n }),\n }),\n !preserveHalfLeading\n ? {\n cancelHalfLeadingPx: margin,\n }\n : {}\n )\n }\n\nconst leadingCancel: CSSObject = {\n display: 'block',\n width: 0,\n height: 0,\n content: `''`,\n}\n\nfunction spacingProperty(\n property: SpacingProperty,\n direction: 'top' | 'right' | 'bottom' | 'left'\n) {\n return `${property}-${direction}`\n}\n\nconst createSpacingCss =\n <T extends Theme>(theme: { spacing: T['spacing'] }) =>\n (\n property: SpacingProperty,\n modifiers: readonly [SpacingDirection, keyof T['spacing'] | 'auto'][]\n ): Internal => {\n const { top, right, bottom, left } = modifiers.reduce(\n (acc, [direction, size]) => {\n if (direction === 'all') {\n acc.top = size\n acc.right = size\n acc.bottom = size\n acc.left = size\n } else if (direction === 'vertical') {\n acc.top = size\n acc.bottom = size\n } else if (direction === 'horizontal') {\n acc.right = size\n acc.left = size\n } else {\n acc[direction] = size\n }\n return acc\n },\n {} as Partial<\n Record<'top' | 'right' | 'bottom' | 'left', keyof T['spacing'] | 'auto'>\n >\n )\n\n const hasVerticalPadding =\n property === 'padding' &&\n top !== undefined &&\n bottom !== undefined &&\n top !== 'auto' &&\n bottom !== 'auto'\n\n return internal(\n ({ cancelHalfLeadingPx = 0 }) => ({\n ...(top !== undefined && {\n [spacingProperty(property, 'top')]:\n top === 'auto'\n ? 'auto'\n : px(\n theme.spacing[top] +\n (hasVerticalPadding ? cancelHalfLeadingPx : 0)\n ),\n }),\n ...(bottom !== undefined && {\n [spacingProperty(property, 'bottom')]:\n bottom === 'auto'\n ? 'auto'\n : px(\n theme.spacing[bottom] +\n (hasVerticalPadding ? cancelHalfLeadingPx : 0)\n ),\n }),\n ...(right !== undefined && {\n [spacingProperty(property, 'right')]:\n right === 'auto' ? 'auto' : px(theme.spacing[right]),\n }),\n ...(left !== undefined && {\n [spacingProperty(property, 'left')]:\n left === 'auto' ? 'auto' : px(theme.spacing[left]),\n }),\n }),\n hasVerticalPadding ? { hasVerticalPadding: true } : {}\n )\n }\n\nconst createFixedPxCss =\n <T extends Theme>(theme: T) =>\n (property: FixedProperty, size: keyof T['spacing'] | 'auto'): Internal =>\n internal(() => ({\n [property]: size === 'auto' ? 'auto' : px(theme.spacing[size]),\n }))\n\nconst createFixedRelativeCss =\n <T extends Theme>(_theme: T) =>\n (property: FixedProperty, amount: '100%' | 'auto'): Internal =>\n internal(() => ({\n [property]: amount,\n }))\n\nconst createFixedColumnCss =\n <T extends Theme>(theme: T) =>\n (property: FixedProperty, span: number): Internal =>\n internal(() => ({\n [property]: px(\n columnSystem(span, theme.grid.unit.column, theme.grid.unit.gutter)\n ),\n }))\n\nconst createElementEffectCss =\n <T extends Theme, TElementEffect extends T['elementEffect']>(theme: {\n elementEffect: TElementEffect\n }) =>\n (effects: readonly (keyof TElementEffect)[] = []): Internal =>\n internal(() =>\n effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n opacity:\n !(Array as ReadonlyArrayConstructor).isArray(\n theme.elementEffect[effect]\n ) && theme.elementEffect[effect]?.type === 'opacity'\n ? theme.elementEffect[effect]?.opacity\n : unreachable(),\n }),\n }),\n {}\n )\n )\n\nfunction borderProperty(direction: BorderDirection) {\n return `border-${direction}`\n}\n\nfunction borderShorthand(color: string) {\n return `solid 1px ${color}`\n}\n\nconst createBorderCss =\n <T extends Theme>(theme: T) =>\n (\n variant: keyof T['border'],\n directions: readonly BorderDirection[]\n ): Internal => {\n const all = directions.length === 0\n const value = borderShorthand(theme.border[variant].color)\n return internal(() => ({\n ...(all\n ? { border: value }\n : directions.reduce<CSSObject>(\n (acc, direction) => ({\n ...acc,\n [borderProperty(direction)]: value,\n }),\n {}\n )),\n }))\n }\n\nconst createBorderRadiusCss =\n <T extends Theme>(theme: T) =>\n (size: keyof T['borderRadius']): Internal =>\n internal(() => ({\n borderRadius: px(theme.borderRadius[size]),\n }))\n\ninterface Context {\n cancelHalfLeadingPx?: number\n hasVerticalPadding?: boolean\n boxShadowTransition?: boolean\n colorTransition?: boolean\n backgroundColorTransition?: boolean\n}\n\nconst commonSpec = (_theme: unknown): Internal => {\n const duration = dur(TRANSITION_DURATION)\n const transition = (property: string[]) => ({\n transition: property.map((v) => `${duration} ${v}`).join(', '),\n })\n return internal(\n ({\n colorTransition = false,\n backgroundColorTransition = false,\n boxShadowTransition = false,\n }) =>\n transition(\n [\n colorTransition ? 'color' : null,\n backgroundColorTransition ? 'background-color' : null,\n boxShadowTransition ? 'box-shadow' : null,\n ].filter(isPresent)\n )\n )\n}\n\nconst internalSym: unique symbol = Symbol('internal')\n\nfunction internal(\n operation: (context: Context) => CSSObject,\n context: Context = {}\n): Internal {\n return {\n [internalSym]: {\n operation,\n context,\n },\n }\n}\n\nexport interface Internal {\n [internalSym]: {\n operation: (context: Context) => CSSObject\n context: Context\n }\n}\n\ntype Blank = null | undefined | false\n\nconst nonBlank = <T>(value: T): value is T extends Blank ? never : T =>\n isPresent(value) && (value as unknown) !== false\n\n/**\n * `theme(o => [...])` の `theme` ユーティリティを構築する\n *\n * @param _styled styled-componnets の `styled` そのもの (型推論のために用いられる)\n *\n * @example\n *\n * import styled from 'styled-components'\n * const theme = createTheme(styled)\n *\n * @example\n *\n * const theme = createTheme<DefaultTheme>()\n */\nfunction createTheme<T extends Theme>(_styled?: ThemedStyledInterface<T>) {\n // `theme(o => [...])` の `o` の部分の型推論のためだけに使う意味のない変数\n // Tを型変数のまま渡してcreateThemeが呼ばれるまで型の具象化が行われないようにする\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n const _phantomBuilder = builder<T>({} as any, true)\n // ランタイムの `theme(o => [...])` のインターフェースを構築する\n return (\n // ユーザー定義\n spec: (\n o: typeof _phantomBuilder\n ) => Blank | Internal | (Blank | Internal)[]\n ): ThemeProp<T> =>\n ({ theme }) => {\n // styled-componentsのランタイムから受け取ったthemeオブジェクトをbuilderに食わせて`o`をつくる\n // さらに、ユーザー定義にbuilderが構築した`o`を食わせる\n // (`o`を一時変数に入れてしまうと型Tの具象化が行われるので関数合成を優先する)\n const rawSpecDescriptor = spec(builder(theme))\n // ユーザー定義の配列を整形\n const specDescriptor = [\n ...(Array.isArray(rawSpecDescriptor)\n ? rawSpecDescriptor\n : [rawSpecDescriptor]),\n commonSpec(theme),\n ].filter(nonBlank)\n\n // 1パス目\n // 全ユーザー定義を舐めて相互に影響し合う定義をチェックし、その結果(コンテキスト)を取得\n const context = specDescriptor.reduce<Context>(\n (acc, v) => ({ ...acc, ...v[internalSym].context }),\n {}\n )\n // 2パス目\n // コンテキストを見ながら最適化されたCSSを構築\n return specDescriptor.map((v) => v[internalSym].operation(context))\n }\n}\n\nexport default createTheme\n\nexport type ThemeProp<T> = ({ theme }: { theme: T }) => CSSObject | CSSObject[]\n"],"names":["unreachable","value","Error","arguments","length","JSON","stringify","isPresent","objectAssign","sources","Object","assign","objectKeys","obj","keys","factory","source","member","chain","defineProperties","fromEntries","map","key","get","enumerable","configurable","constFactory","def","modifiedFactory","modifiers","recursiveModifiedFactory","applied","notApplied","filter","v","includes","modifier","spacingProperties","spacingDirections","fixedProperties","borderDirections","outlineType","builder","theme","isPhantom","colors","color","effects","effect","gradientColors","gradientColor","colorCss","createColorCss","gradientColorCss","createGradientColorCss","colorObject","bg","direction","font","typographyModifiers","typographyCss","createTypographyCss","typographyObject","_","size","preserveHalfLeading","monospace","bold","spacingCss","createSpacingCss","spacingObject","spacingProperty","modifiedArgumentedFactory","w","args","argumentedFactory","fixedPxCss","createFixedPxCss","fixedColumnCss","createFixedColumnCss","fixedRelativeCss","createFixedRelativeCss","fixedObject","property","px","column","span","auto","full","elementEffectCss","createElementEffectCss","elementEffectObject","elementEffect","borderCss","createBorderCss","borderObject","border","variant","borderRadiusCss","createBorderRadiusCss","borderRadiusObject","borderRadius","radius","outlineCss","createOutlineColorCss","outline","targetProperty","target","isSupportedEffect","onEffectPseudo","css","notDisabledSelector","disabledSelector","internal","reduce","acc","applyEffect","colorTransition","backgroundColorTransition","toLinearGradient","gradient","context","optimized","useHalfLeadingCanceller","duration","dur","position","zIndex","overflow","overlayElement","transition","backgroundColor","warning","applyEffectToGradient","weight","boxShadow","boxShadowTransition","content","display","width","height","top","left","cancelHalfLeadingPx","hasVerticalPadding","undefined","options","descriptor","typography","margin","halfLeading","fontSize","lineHeight","fontFamily","fontWeight","leadingCancel","marginTop","marginBottom","right","bottom","spacing","_theme","amount","columnSystem","grid","unit","gutter","opacity","Array","isArray","type","_theme$elementEffect$2","borderProperty","directions","all","commonSpec","join","internalSym","Symbol","operation","nonBlank","createTheme","_styled","spec","rawSpecDescriptor","specDescriptor"],"mappings":"kdAwBgBA,EAAYC,GAC1B,UAAUC,MACa,IAArBC,UAAUC,OACN,8BACgBC,KAAKC,UAAUL,aAS1BM,EAAgBN,GAA+C,MAATA,W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,EACA,CAAE9E,OAAQ/F,GACV4K,EAAW3D,OACT,CAACC,EAAK1D,SACD0D,GACH,CAACyD,EAAenH,IAAaxD,IAE/B,OAKNkG,EACcxD,GACjBqB,GACCiD,EAAS,MACPZ,aAAcjB,EAAGzC,EAAM0D,aAAarC,OAWpC+G,EAAcd,IAClB,MAAMrC,EAAWC,EAjWS,IAqW1B,OAAOZ,EACL,EACEI,gBAAAA,GAAkB,EAClBC,0BAAAA,GAA4B,EAC5BkB,oBAAAA,GAAsB,OANxBN,WASI,CACEb,EAAkB,QAAU,KAC5BC,EAA4B,mBAAqB,KACjDkB,EAAsB,aAAe,MACrCvG,OAAO1B,GAbQc,IAAKa,MAAS0F,KAAY1F,KAAK8I,KAAK,UAkBvDC,EAA6BC,OAAO,YAE1C,SAASjE,EACPkE,EACA1D,EAAmB,IAEnB,MAAO,CACLwD,CAACA,GAAc,CACbE,UAAAA,EACA1D,QAAAA,IAcN,MAAM2D,EAAenL,GACnBM,EAAUN,KAAiC,IAAtBA,EAgBvB,SAASoL,EAA6BC,GAMpC,OAFwB5I,EAAW,IAAW,GAI1C6I,GAIF,EAAG5I,MAAAA,MAID,MAAM6I,EAAoBD,EAAK7I,EAAQC,IAEjC8I,EAAiB,IACjBjB,MAAMC,QAAQe,GACdA,EACA,CAACA,GACLT,KACA9I,OAAOmJ,GAIH3D,EAAUgE,EAAevE,OAC7B,CAACC,EAAKjF,SAAYiF,EAAQjF,EAAE+I,GAAaxD,SACzC,IAIF,OAAOgE,EAAepK,IAAKa,GAAMA,EAAE+I,GAAaE,UAAU1D"}
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.module.js","sources":["../src/util.ts","../src/lib.ts","../src/index.ts"],"sourcesContent":["/**\n * Function used to assert a given code path is unreachable\n */\nexport function unreachable(): never\n/**\n * Function used to assert a given code path is unreachable.\n * Very useful for ensuring switches are exhaustive:\n *\n * ```ts\n * switch (a.type) {\n * case Types.A:\n * case Types.B:\n * break\n * default:\n * unreachable(a) // will cause a build error if there was\n * // a Types.C that was not checked\n * }\n * ```\n *\n * @param value Value to be asserted as unreachable\n */\n// NOTE: Uses separate overloads, _not_ `value?: never`, to not allow `undefined` to be passed\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport function unreachable(value: never): never\nexport function unreachable(value?: never): never {\n throw new Error(\n arguments.length === 0\n ? 'unreachable'\n : `unreachable (${JSON.stringify(value)})`\n )\n}\n\n/**\n * Check whether a value is non-null and non-undefined\n *\n * @param value nullable\n */\nexport const isPresent = <T>(value: T): value is NonNullable<T> => value != null\n\ntype Head<U> = U extends [infer T, ...any[]] ? T : never\n\ntype Tail<U> = U extends [any, any, ...any[]]\n ? ((...args: U) => any) extends (head: any, ...args: infer T) => any\n ? T\n : never\n : never\n// Buggy at ts@4.0.0-dev20200506\n// type Tail<U> = U extends [any, ...infer T] ? T : never\n\ntype RecursiveObjectAssign<T, S extends any[]> = {\n 0: T & Head<S>\n 1: RecursiveObjectAssign<T & Head<S>, Tail<S>>\n}[Tail<S> extends never ? 0 : 1]\n\ntype ObjectAssign<T extends any[]> = RecursiveObjectAssign<\n Record<string, unknown>,\n T\n>\n\nexport function objectAssign<T extends any[]>(...sources: T) {\n return Object.assign({}, ...sources) as ObjectAssign<T>\n}\n\nexport function objectKeys<V, K extends keyof V>(obj: V) {\n return Object.keys(obj) as K[]\n}\n\nexport interface ReadonlyArrayConstructor {\n isArray(value: any): value is readonly any[]\n}\n\nexport function extractNonNullKeys<V, K extends keyof V>(obj: {\n [key in K]: V[key]\n}) {\n return Object.entries(obj)\n .filter(([_, v]) => v !== null)\n .map(([k]) => k) as { [key in K]: V[key] extends null ? never : key }[K][]\n}\n","import { Key } from '@charcoal-ui/theme'\nimport { unreachable } from './util'\n\n/**\n * 配列で指定したプロパティを動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param member オブジェクトに生やすプロパティ一覧\n * @param chain プロパティに格納される値を生成する関数\n *\n * @example\n *\n * const o = factory({}, ['red', 'blue'],\n * color => hex(color)\n * )\n *\n * console.log(o.red) //=> #ff0000\n */\nexport const factory = <TSource, TMember extends readonly Key[], TValue>(\n source: TSource,\n member: TMember,\n chain: (key: TMember[number]) => TValue\n) =>\n Object.defineProperties(\n source,\n Object.fromEntries(\n member.map((key) => [\n key,\n { get: () => chain(key), enumerable: true, configurable: true },\n ])\n )\n ) as TSource & { readonly [key in TMember[number]]: TValue }\n\n/**\n * 配列で指定した名前のメソッドを動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param member オブジェクトに生やすメソッド名一覧\n * @param chain メソッドの戻り値になる値を生成する関数\n *\n * @example\n *\n * const o = argumentedFactory({}, ['red', 'blue'],\n * (color, alpha: number) => hex(color, alpha)\n * )\n *\n * console.log(o.red(0.5)) //=> #ff000077\n */\nexport const argumentedFactory = <\n TSource,\n TMember extends readonly string[],\n TValue,\n TArguments extends unknown[]\n>(\n source: TSource,\n member: TMember,\n chain: (key: TMember[number], ...args: TArguments) => TValue\n) =>\n Object.defineProperties(\n source,\n Object.fromEntries(\n member.map((key) => [\n key,\n {\n value: (...args: TArguments) => chain(key, ...args),\n enumerable: true,\n configurable: true,\n },\n ])\n )\n ) as TSource & {\n readonly [key in TMember[number]]: (...args: TArguments) => TValue\n }\n\n/**\n * オブジェクトで指定したプロパティ名と値を動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param def オブジェクトに生やす定義(プロパティ名と値)\n *\n * @example\n *\n * const o = constFactory({}, {\n * red: '#f00',\n * blue: '#00f',\n * })\n *\n * console.log(o.red) //=> #f00\n */\nexport const constFactory = <TSource, TDef extends { [key: string]: unknown }>(\n source: TSource,\n def: TDef\n) =>\n factory(source, Object.keys(def), (key) => def[key]) as TSource &\n Readonly<TDef>\n\n/**\n * 配列で指定したモディファイア(プロパティ)をチェーン可能な再帰オブジェクトを動的に生やす\n *\n * @param modifiers オブジェクトに生やすモディファイヤ一覧\n * @param source 指定されたモディファイヤの一覧から値を生成する関数\n *\n * @example\n *\n * const o = modifiedArgumentedFactory(['red', 'blue'],\n * modifiers => modifiers.map(color => hex(color)).join(',')\n * )\n *\n * console.log(o.red.blue) => #f00,#00f\n */\nexport const modifiedFactory = <TSource, T extends Key>(\n modifiers: readonly T[],\n source: (applied: readonly T[]) => TSource\n) =>\n (function recursiveModifiedFactory(\n applied: readonly T[]\n ): Modified<TSource, T> {\n const notApplied = modifiers.filter((v) => !applied.includes(v))\n return factory(source(applied), notApplied, (modifier) =>\n notApplied.length === 0\n ? unreachable()\n : recursiveModifiedFactory([...applied, modifier])\n )\n })([])\n\nexport type Modified<TSource, TModifiers extends Key> = TSource & {\n readonly [key in TModifiers]: Modified<TSource, Exclude<TModifiers, key>>\n}\n\n/**\n * 配列で指定したモディファイア(メソッド)をチェーン可能な再帰オブジェクトを動的に生やす\n *\n * @param modifiers オブジェクトに生やすモディファイヤ一覧\n * @param source 指定されたモディファイヤの一覧から値を生成する関数\n * @param _inferPhantom 関数形式のモディファイヤの引数型を推論するためのメタタイプ(引数の個数に合わせてタプルで指定する)\n *\n * @example\n *\n * const o = modifiedArgumentedFactory(['red', 'blue'],\n * modifiers => modifiers.map(([color, alpha]) => hex(color, alpha)).join(',')\n * , {} as [number])\n *\n * console.log(o.red(0.5).blue(1)) => #ff000077,#0000ffff\n */\nexport const modifiedArgumentedFactory = <\n TSource,\n T extends string,\n TArguments extends unknown[]\n>(\n modifiers: readonly T[],\n source: (applied: readonly [T, ...TArguments][]) => TSource,\n ..._inferPhantom: TArguments\n) =>\n (function recursiveModifiedFactory(\n applied: readonly [T, ...TArguments][]\n ): ModifiedArgumented<TSource, T, TArguments> {\n const notApplied = modifiers.filter(\n (v) => !applied.map(([w]) => w).includes(v)\n )\n return argumentedFactory(\n source(applied),\n notApplied,\n (modifier, ...args: TArguments) =>\n notApplied.length === 0\n ? unreachable()\n : recursiveModifiedFactory([...applied, [modifier, ...args]])\n )\n })([])\n\nexport type ModifiedArgumented<\n TSource,\n TModifiers extends string,\n TArguments extends unknown[]\n> = TSource & {\n readonly [key in TModifiers]: (\n ...args: TArguments\n ) => ModifiedArgumented<TSource, Exclude<TModifiers, key>, TArguments>\n}\n","import { CSSObject, ThemedStyledInterface } from 'styled-components'\nimport warning from 'warning'\nimport {\n factory,\n modifiedFactory,\n constFactory,\n modifiedArgumentedFactory,\n} from './lib'\nimport {\n EffectType,\n CharcoalAbstractTheme as Theme,\n Key,\n} from '@charcoal-ui/theme'\nimport {\n objectAssign,\n unreachable,\n ReadonlyArrayConstructor,\n objectKeys,\n isPresent,\n} from './util'\nimport { columnSystem } from '@charcoal-ui/foundation'\nimport {\n halfLeading,\n applyEffect,\n applyEffectToGradient,\n dur,\n gradient,\n GradientDirection,\n notDisabledSelector,\n disabledSelector,\n px,\n} from '@charcoal-ui/utils'\nexport { type Modified, type ModifiedArgumented } from './lib'\n\nconst colorProperties = ['bg', 'font'] as const\ntype ColorProperty = typeof colorProperties[number]\n\nconst spacingProperties = ['margin', 'padding'] as const\nconst spacingDirections = [\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'vertical',\n 'horizontal',\n 'all',\n] as const\ntype SpacingProperty = typeof spacingProperties[number]\ntype SpacingDirection = typeof spacingDirections[number]\n\nconst fixedProperties = ['width', 'height'] as const\ntype FixedProperty = typeof fixedProperties[number]\n\nconst borderDirections = ['top', 'right', 'bottom', 'left'] as const\ntype BorderDirection = typeof borderDirections[number]\n\nconst outlineType = ['focus'] as const\ntype OutlineType = typeof outlineType[number]\n\n/**\n * `theme(o => [...])` の `o` の部分を構築する\n *\n * @param theme テーマオブジェクト\n * @param isPhantom 型推論のためだけに使う場合にランタイムコストをゼロにするフラグ\n */\nfunction builder<T extends Theme>(\n theme: {\n // factoryの第二引数に入れ込むものだけ明示的に型変数を展開しておくことで型の具象化を遅延する\n color: T['color']\n gradientColor: T['gradientColor']\n border: T['border']\n outline: T['outline']\n } & Omit<T, 'color' | 'gradientColor' | 'border' | 'outline'>,\n isPhantom = false\n) {\n if (isPhantom) {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n return {} as never\n }\n const colors = objectKeys(theme.color)\n const effects = objectKeys(theme.effect)\n\n // 色\n const gradientColors = objectKeys(theme.gradientColor)\n const colorCss = createColorCss(theme)\n const gradientColorCss = createGradientColorCss(theme)\n const colorObject = constFactory(\n {},\n {\n bg: objectAssign(\n factory({}, colors, (color) =>\n modifiedFactory(effects, (modifiers) =>\n colorCss('bg', color, modifiers)\n )\n ),\n factory(\n {},\n gradientColors,\n (color) => (direction: GradientDirection) =>\n modifiedFactory(effects, (modifiers) =>\n gradientColorCss(color, modifiers, direction)\n )\n )\n ),\n font: factory({}, colors, (color) =>\n modifiedFactory(effects, (modifiers) =>\n colorCss('font', color, modifiers)\n )\n ),\n }\n )\n\n // タイポグラフィ\n const typographyModifiers = [\n // TODO\n 'monospace',\n 'bold',\n 'preserveHalfLeading',\n ] as const\n const typographyCss = createTypographyCss(theme)\n const typographyObject = factory(\n {},\n ['typography'] as const,\n (_) => (size: keyof T['typography']['size']) =>\n modifiedFactory(typographyModifiers, (modifiers) =>\n typographyCss(size, {\n preserveHalfLeading: modifiers.includes('preserveHalfLeading'),\n monospace: modifiers.includes('monospace'),\n bold: modifiers.includes('bold'),\n })\n )\n )\n\n // スペーシング\n const spacingCss = createSpacingCss(theme)\n const spacingObject = factory({}, spacingProperties, (spacingProperty) =>\n modifiedArgumentedFactory(\n spacingDirections,\n (modifiers) => spacingCss(spacingProperty, modifiers),\n {} as keyof T['spacing'] | 'auto' // 推論のためのメタタイプ\n )\n )\n\n // 大きさ\n const fixedPxCss = createFixedPxCss(theme)\n const fixedColumnCss = createFixedColumnCss(theme)\n const fixedRelativeCss = createFixedRelativeCss(theme)\n const fixedObject = factory({}, fixedProperties, (property) =>\n constFactory(\n {},\n {\n px: (size: keyof T['spacing'] | 'auto') => fixedPxCss(property, size),\n column: (span: number) => fixedColumnCss(property, span),\n auto: fixedRelativeCss(property, 'auto'),\n full: fixedRelativeCss(property, '100%'),\n }\n )\n )\n\n // 要素へのエフェクト (etc: 透過)\n const elementEffectCss = createElementEffectCss(theme)\n const elementEffectObject = modifiedFactory(\n objectKeys(theme.elementEffect),\n (modifiers) => elementEffectCss(modifiers)\n )\n\n // ボーダー\n const borderCss = createBorderCss(theme)\n const borderObject = constFactory(\n {},\n {\n border: factory({}, objectKeys(theme.border), (variant) =>\n modifiedFactory(borderDirections, (modifiers) =>\n borderCss(variant, modifiers)\n )\n ),\n }\n )\n\n // 角丸\n const borderRadiusCss = createBorderRadiusCss(theme)\n const borderRadiusObject = constFactory(\n {},\n {\n borderRadius: (radius: keyof T['borderRadius']) =>\n borderRadiusCss(radius),\n }\n )\n\n // アウトライン\n const outlineCss = createOutlineColorCss(theme)\n const outlineObject = constFactory(\n {},\n {\n outline: factory({}, objectKeys(theme.outline), (variant) =>\n modifiedFactory(outlineType, (modifiers) =>\n outlineCss(variant, modifiers)\n )\n ),\n }\n )\n\n return objectAssign(\n colorObject,\n typographyObject,\n spacingObject,\n fixedObject,\n elementEffectObject,\n borderObject,\n borderRadiusObject,\n outlineObject\n )\n}\n\nfunction targetProperty(target: ColorProperty) {\n return target === 'bg' ? 'background-color' : 'color'\n}\n\nfunction isSupportedEffect(effect: Key): effect is EffectType {\n return ['hover', 'press', 'disabled'].includes(effect as string)\n}\n\nfunction onEffectPseudo(effect: EffectType, css: CSSObject) {\n return effect === 'hover'\n ? { '&:hover': { [notDisabledSelector]: css } }\n : effect === 'press'\n ? { '&:active': { [notDisabledSelector]: css } }\n : // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n effect === 'disabled'\n ? { [disabledSelector]: css }\n : unreachable(effect)\n}\n\nconst createColorCss =\n <T extends Theme>(theme: T) =>\n (\n target: ColorProperty,\n color: keyof T['color'],\n effects: readonly (keyof T['effect'])[] = []\n ): Internal =>\n internal(\n () => ({\n [targetProperty(target)]: theme.color[color],\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n [targetProperty(target)]: applyEffect(\n theme.color[color],\n theme.effect[effect] ?? []\n ),\n }),\n }),\n {}\n ),\n }),\n effects.length > 0\n ? target === 'font'\n ? {\n colorTransition: true,\n }\n : {\n backgroundColorTransition: true,\n }\n : {}\n )\n\n// TODO: deprecate\nconst TRANSITION_DURATION = 0.2\n\nconst createGradientColorCss =\n <T extends Theme>(theme: T) =>\n (\n color: keyof T['gradientColor'],\n effects: readonly (keyof T['effect'])[] = [],\n direction: GradientDirection\n ): Internal => {\n const toLinearGradient = gradient(direction)\n return internal((context) => {\n const optimized = !useHalfLeadingCanceller(context)\n const duration = dur(TRANSITION_DURATION)\n if (optimized && effects.length > 0) {\n return {\n position: 'relative',\n zIndex: 0,\n overflow: 'hidden',\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n '&::before': {\n zIndex: -1,\n ...overlayElement,\n transition: `${duration} background-color`,\n },\n '&::after': {\n zIndex: -2,\n ...overlayElement,\n ...toLinearGradient(theme.gradientColor[color]),\n },\n ...onEffectPseudo(effect, {\n '&::before': {\n backgroundColor: applyEffect(\n null,\n theme.effect[effect] ?? []\n ),\n },\n }),\n }),\n {}\n ),\n }\n } else {\n warning(\n effects.length === 0,\n // eslint-disable-next-line max-len\n `'Transition' will not be applied. You can get around this by specifying 'preserveHalfLeading' or both 'padding' and 'typograpy'.`\n )\n return {\n ...toLinearGradient(theme.gradientColor[color]),\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n ...toLinearGradient(\n applyEffectToGradient(theme.effect[effect] ?? [])(\n theme.gradientColor[color]\n )\n ),\n }),\n }),\n {}\n ),\n }\n }\n })\n }\n\n/**\n * @see https://developer.mozilla.org/ja/docs/Web/CSS/:focus-visible#selectively_showing_the_focus_indicator\n */\nconst onFocus = (css: CSSObject) => ({\n [notDisabledSelector]: {\n '&:focus, &:active': {\n outline: 'none',\n ...css,\n },\n\n '&:focus:not(:focus-visible), &:active:not(:focus-visible)': {\n outline: 'none',\n },\n\n '&:focus-visible': {\n outline: 'none',\n ...css,\n },\n },\n})\n\nconst outlineCss = (weight: number, color: string) => ({\n boxShadow: `0 0 0 ${px(weight)} ${color}`,\n})\n\nconst createOutlineColorCss =\n <T extends Theme>(theme: T) =>\n (\n variant: keyof T['outline'],\n modifiers: readonly OutlineType[]\n ): Internal => {\n const weight = theme.outline[variant].weight\n const color = theme.outline[variant].color\n return internal(\n () =>\n modifiers.includes('focus')\n ? onFocus(outlineCss(weight, color))\n : { '&&': { [notDisabledSelector]: outlineCss(weight, color) } },\n {\n boxShadowTransition: true,\n }\n )\n }\n\nconst overlayElement: CSSObject = {\n content: \"''\",\n display: 'block',\n position: 'absolute',\n width: '100%',\n height: '100%',\n top: 0,\n left: 0,\n}\n\n// half-leadingをキャンセルするとき && 垂直方向のpaddingが無い時\n// -> before/afterを入れる\nconst useHalfLeadingCanceller = ({\n cancelHalfLeadingPx,\n hasVerticalPadding = false,\n}: Context) => cancelHalfLeadingPx !== undefined && !hasVerticalPadding\n\nconst createTypographyCss =\n <T extends Theme>(theme: T) =>\n (\n size: keyof T['typography']['size'],\n options: {\n preserveHalfLeading?: boolean\n monospace?: boolean\n bold?: boolean\n } = {}\n ): Internal => {\n const {\n preserveHalfLeading = false,\n monospace = false,\n bold = false,\n } = options\n const descriptor = theme.typography.size[size]\n const margin = -halfLeading(descriptor)\n\n return internal(\n (context) => ({\n fontSize: px(descriptor.fontSize),\n lineHeight: px(descriptor.lineHeight),\n ...(monospace && {\n fontFamily: 'monospace',\n }),\n ...(bold && {\n fontWeight: 'bold',\n }),\n ...(useHalfLeadingCanceller(context) && {\n // prevent margin collapsing\n display: 'flow-root',\n // cancel half-leading with negative margin\n '&::before': {\n ...leadingCancel,\n marginTop: px(margin),\n },\n '&::after': {\n ...leadingCancel,\n marginBottom: px(margin),\n },\n }),\n }),\n !preserveHalfLeading\n ? {\n cancelHalfLeadingPx: margin,\n }\n : {}\n )\n }\n\nconst leadingCancel: CSSObject = {\n display: 'block',\n width: 0,\n height: 0,\n content: `''`,\n}\n\nfunction spacingProperty(\n property: SpacingProperty,\n direction: 'top' | 'right' | 'bottom' | 'left'\n) {\n return `${property}-${direction}`\n}\n\nconst createSpacingCss =\n <T extends Theme>(theme: { spacing: T['spacing'] }) =>\n (\n property: SpacingProperty,\n modifiers: readonly [SpacingDirection, keyof T['spacing'] | 'auto'][]\n ): Internal => {\n const { top, right, bottom, left } = modifiers.reduce(\n (acc, [direction, size]) => {\n if (direction === 'all') {\n acc.top = size\n acc.right = size\n acc.bottom = size\n acc.left = size\n } else if (direction === 'vertical') {\n acc.top = size\n acc.bottom = size\n } else if (direction === 'horizontal') {\n acc.right = size\n acc.left = size\n } else {\n acc[direction] = size\n }\n return acc\n },\n {} as Partial<\n Record<'top' | 'right' | 'bottom' | 'left', keyof T['spacing'] | 'auto'>\n >\n )\n\n const hasVerticalPadding =\n property === 'padding' &&\n top !== undefined &&\n bottom !== undefined &&\n top !== 'auto' &&\n bottom !== 'auto'\n\n return internal(\n ({ cancelHalfLeadingPx = 0 }) => ({\n ...(top !== undefined && {\n [spacingProperty(property, 'top')]:\n top === 'auto'\n ? 'auto'\n : px(\n theme.spacing[top] +\n (hasVerticalPadding ? cancelHalfLeadingPx : 0)\n ),\n }),\n ...(bottom !== undefined && {\n [spacingProperty(property, 'bottom')]:\n bottom === 'auto'\n ? 'auto'\n : px(\n theme.spacing[bottom] +\n (hasVerticalPadding ? cancelHalfLeadingPx : 0)\n ),\n }),\n ...(right !== undefined && {\n [spacingProperty(property, 'right')]:\n right === 'auto' ? 'auto' : px(theme.spacing[right]),\n }),\n ...(left !== undefined && {\n [spacingProperty(property, 'left')]:\n left === 'auto' ? 'auto' : px(theme.spacing[left]),\n }),\n }),\n hasVerticalPadding ? { hasVerticalPadding: true } : {}\n )\n }\n\nconst createFixedPxCss =\n <T extends Theme>(theme: T) =>\n (property: FixedProperty, size: keyof T['spacing'] | 'auto'): Internal =>\n internal(() => ({\n [property]: size === 'auto' ? 'auto' : px(theme.spacing[size]),\n }))\n\nconst createFixedRelativeCss =\n <T extends Theme>(_theme: T) =>\n (property: FixedProperty, amount: '100%' | 'auto'): Internal =>\n internal(() => ({\n [property]: amount,\n }))\n\nconst createFixedColumnCss =\n <T extends Theme>(theme: T) =>\n (property: FixedProperty, span: number): Internal =>\n internal(() => ({\n [property]: px(\n columnSystem(span, theme.grid.unit.column, theme.grid.unit.gutter)\n ),\n }))\n\nconst createElementEffectCss =\n <T extends Theme, TElementEffect extends T['elementEffect']>(theme: {\n elementEffect: TElementEffect\n }) =>\n (effects: readonly (keyof TElementEffect)[] = []): Internal =>\n internal(() =>\n effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n opacity:\n !(Array as ReadonlyArrayConstructor).isArray(\n theme.elementEffect[effect]\n ) && theme.elementEffect[effect]?.type === 'opacity'\n ? theme.elementEffect[effect]?.opacity\n : unreachable(),\n }),\n }),\n {}\n )\n )\n\nfunction borderProperty(direction: BorderDirection) {\n return `border-${direction}`\n}\n\nfunction borderShorthand(color: string) {\n return `solid 1px ${color}`\n}\n\nconst createBorderCss =\n <T extends Theme>(theme: T) =>\n (\n variant: keyof T['border'],\n directions: readonly BorderDirection[]\n ): Internal => {\n const all = directions.length === 0\n const value = borderShorthand(theme.border[variant].color)\n return internal(() => ({\n ...(all\n ? { border: value }\n : directions.reduce<CSSObject>(\n (acc, direction) => ({\n ...acc,\n [borderProperty(direction)]: value,\n }),\n {}\n )),\n }))\n }\n\nconst createBorderRadiusCss =\n <T extends Theme>(theme: T) =>\n (size: keyof T['borderRadius']): Internal =>\n internal(() => ({\n borderRadius: px(theme.borderRadius[size]),\n }))\n\ninterface Context {\n cancelHalfLeadingPx?: number\n hasVerticalPadding?: boolean\n boxShadowTransition?: boolean\n colorTransition?: boolean\n backgroundColorTransition?: boolean\n}\n\nconst commonSpec = (_theme: unknown): Internal => {\n const duration = dur(TRANSITION_DURATION)\n const transition = (property: string[]) => ({\n transition: property.map((v) => `${duration} ${v}`).join(', '),\n })\n return internal(\n ({\n colorTransition = false,\n backgroundColorTransition = false,\n boxShadowTransition = false,\n }) =>\n transition(\n [\n colorTransition ? 'color' : null,\n backgroundColorTransition ? 'background-color' : null,\n boxShadowTransition ? 'box-shadow' : null,\n ].filter(isPresent)\n )\n )\n}\n\nconst internalSym: unique symbol = Symbol('internal')\n\nfunction internal(\n operation: (context: Context) => CSSObject,\n context: Context = {}\n): Internal {\n return {\n [internalSym]: {\n operation,\n context,\n },\n }\n}\n\nexport interface Internal {\n [internalSym]: {\n operation: (context: Context) => CSSObject\n context: Context\n }\n}\n\ntype Blank = null | undefined | false\n\nconst nonBlank = <T>(value: T): value is T extends Blank ? never : T =>\n isPresent(value) && (value as unknown) !== false\n\n/**\n * `theme(o => [...])` の `theme` ユーティリティを構築する\n *\n * @param _styled styled-componnets の `styled` そのもの (型推論のために用いられる)\n *\n * @example\n *\n * import styled from 'styled-components'\n * const theme = createTheme(styled)\n *\n * @example\n *\n * const theme = createTheme<DefaultTheme>()\n */\nfunction createTheme<T extends Theme>(_styled?: ThemedStyledInterface<T>) {\n // `theme(o => [...])` の `o` の部分の型推論のためだけに使う意味のない変数\n // Tを型変数のまま渡してcreateThemeが呼ばれるまで型の具象化が行われないようにする\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n const _phantomBuilder = builder<T>({} as any, true)\n // ランタイムの `theme(o => [...])` のインターフェースを構築する\n return (\n // ユーザー定義\n spec: (\n o: typeof _phantomBuilder\n ) => Blank | Internal | (Blank | Internal)[]\n ): ThemeProp<T> =>\n ({ theme }) => {\n // styled-componentsのランタイムから受け取ったthemeオブジェクトをbuilderに食わせて`o`をつくる\n // さらに、ユーザー定義にbuilderが構築した`o`を食わせる\n // (`o`を一時変数に入れてしまうと型Tの具象化が行われるので関数合成を優先する)\n const rawSpecDescriptor = spec(builder(theme))\n // ユーザー定義の配列を整形\n const specDescriptor = [\n ...(Array.isArray(rawSpecDescriptor)\n ? rawSpecDescriptor\n : [rawSpecDescriptor]),\n commonSpec(theme),\n ].filter(nonBlank)\n\n // 1パス目\n // 全ユーザー定義を舐めて相互に影響し合う定義をチェックし、その結果(コンテキスト)を取得\n const context = specDescriptor.reduce<Context>(\n (acc, v) => ({ ...acc, ...v[internalSym].context }),\n {}\n )\n // 2パス目\n // コンテキストを見ながら最適化されたCSSを構築\n return specDescriptor.map((v) => v[internalSym].operation(context))\n }\n}\n\nexport default createTheme\n\nexport type ThemeProp<T> = ({ theme }: { theme: T }) => CSSObject | CSSObject[]\n"],"names":["unreachable","value","Error","arguments","length","JSON","stringify","isPresent","objectAssign","Object","assign","objectKeys","obj","keys","factory","source","member","chain","defineProperties","fromEntries","map","key","get","enumerable","configurable","constFactory","def","modifiedFactory","modifiers","recursiveModifiedFactory","applied","notApplied","filter","v","includes","modifier","spacingProperties","spacingDirections","fixedProperties","borderDirections","outlineType","builder","theme","isPhantom","colors","color","effects","effect","gradientColors","gradientColor","colorCss","createColorCss","gradientColorCss","createGradientColorCss","colorObject","bg","direction","font","typographyModifiers","typographyCss","createTypographyCss","typographyObject","_","size","preserveHalfLeading","monospace","bold","spacingCss","createSpacingCss","spacingObject","spacingProperty","argumentedFactory","fixedPxCss","createFixedPxCss","fixedColumnCss","createFixedColumnCss","fixedRelativeCss","createFixedRelativeCss","fixedObject","property","px","column","span","auto","full","elementEffectCss","createElementEffectCss","elementEffectObject","elementEffect","borderCss","createBorderCss","borderObject","border","variant","borderRadiusCss","createBorderRadiusCss","borderRadiusObject","borderRadius","radius","outlineCss","createOutlineColorCss","outline","targetProperty","target","isSupportedEffect","onEffectPseudo","css","notDisabledSelector","disabledSelector","internal","reduce","acc","applyEffect","colorTransition","backgroundColorTransition","toLinearGradient","gradient","context","optimized","useHalfLeadingCanceller","duration","dur","position","zIndex","overflow","overlayElement","transition","backgroundColor","warning","applyEffectToGradient","weight","boxShadow","boxShadowTransition","content","display","width","height","top","left","hasVerticalPadding","undefined","cancelHalfLeadingPx","options","descriptor","typography","margin","halfLeading","fontSize","lineHeight","fontFamily","fontWeight","leadingCancel","marginTop","marginBottom","right","bottom","spacing","_theme","amount","columnSystem","grid","unit","gutter","opacity","Array","isArray","type","_theme$elementEffect$2","directions","all","borderProperty","internalSym","Symbol","operation","nonBlank","createTheme","_styled","spec","rawSpecDescriptor","specDescriptor","join"],"mappings":"kdAwBgBA,EAAYC,GAC1B,UAAUC,MACa,IAArBC,UAAUC,OACN,8BACgBC,KAAKC,UAAUL,YAS1BM,EAAY,SAAIN,UAA+C,MAATA,YAsBnDO,IACd,OAAOC,OAAOC,aAAPD,QAAc,+CAGPE,EAAiCC,GAC/C,OAAOH,OAAOI,KAAKD,OC9CRE,EAAU,SACrBC,EACAC,EACAC,UAEAR,OAAOS,iBACLH,EACAN,OAAOU,YACLH,EAAOI,IAAI,SAACC,SAAQ,CAClBA,EACA,CAAEC,IAAK,kBAAML,EAAMI,IAAME,YAAY,EAAMC,cAAc,SA6DpDC,EAAe,SAC1BV,EACAW,UAEAZ,EAAQC,EAAQN,OAAOI,KAAKa,GAAM,SAACL,UAAQK,EAAIL,MAiBpCM,EAAkB,SAC7BC,EACAb,mBAEUc,EACRC,GAEA,IAAMC,EAAaH,EAAUI,OAAO,SAACC,UAAOH,EAAQI,SAASD,KAC7D,OAAOnB,EAAQC,EAAOe,GAAUC,EAAY,SAACI,UACrB,IAAtBJ,EAAW3B,OACPJ,IACA6B,YAA6BC,GAASK,QAE3C,KCtFCC,EAAoB,CAAC,SAAU,WAC/BC,EAAoB,CACxB,MACA,QACA,SACA,OACA,WACA,aACA,OAKIC,EAAkB,CAAC,QAAS,UAG5BC,EAAmB,CAAC,MAAO,QAAS,SAAU,QAG9CC,EAAc,CAAC,SASrB,SAASC,EACPC,EAOAC,GAEA,YAFAA,IAAAA,GAAY,GAERA,EAEF,MAAO,GAET,IAAMC,EAASjC,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E0I,GAAatD,UACzC,IAIF,OAAO8D,EAAe/J,IAAI,SAACa,UAAMA,EAAE0I,GAAaE,UAAUxD"}
|
|
1
|
+
{"version":3,"file":"index.module.js","sources":["../src/util.ts","../src/lib.ts","../src/index.ts"],"sourcesContent":["/**\n * Function used to assert a given code path is unreachable\n */\nexport function unreachable(): never\n/**\n * Function used to assert a given code path is unreachable.\n * Very useful for ensuring switches are exhaustive:\n *\n * ```ts\n * switch (a.type) {\n * case Types.A:\n * case Types.B:\n * break\n * default:\n * unreachable(a) // will cause a build error if there was\n * // a Types.C that was not checked\n * }\n * ```\n *\n * @param value Value to be asserted as unreachable\n */\n// NOTE: Uses separate overloads, _not_ `value?: never`, to not allow `undefined` to be passed\n// eslint-disable-next-line @typescript-eslint/unified-signatures\nexport function unreachable(value: never): never\nexport function unreachable(value?: never): never {\n throw new Error(\n arguments.length === 0\n ? 'unreachable'\n : `unreachable (${JSON.stringify(value)})`\n )\n}\n\n/**\n * Check whether a value is non-null and non-undefined\n *\n * @param value nullable\n */\nexport const isPresent = <T>(value: T): value is NonNullable<T> => value != null\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Head<U> = U extends [infer T, ...any[]] ? T : never\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Tail<U> = U extends [any, any, ...any[]]\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ((...args: U) => any) extends (head: any, ...args: infer T) => any\n ? T\n : never\n : never\n// Buggy at ts@4.0.0-dev20200506\n// type Tail<U> = U extends [any, ...infer T] ? T : never\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype RecursiveObjectAssign<T, S extends any[]> = {\n 0: T & Head<S>\n 1: RecursiveObjectAssign<T & Head<S>, Tail<S>>\n}[Tail<S> extends never ? 0 : 1]\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ObjectAssign<T extends any[]> = RecursiveObjectAssign<\n Record<string, unknown>,\n T\n>\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function objectAssign<T extends any[]>(...sources: T) {\n return Object.assign({}, ...sources) as ObjectAssign<T>\n}\n\nexport function objectKeys<V, K extends keyof V>(obj: V) {\n return Object.keys(obj) as K[]\n}\n\nexport interface ReadonlyArrayConstructor {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n isArray(value: any): value is readonly any[]\n}\n\nexport function extractNonNullKeys<V, K extends keyof V>(obj: {\n [key in K]: V[key]\n}) {\n return Object.entries(obj)\n .filter(([_, v]) => v !== null)\n .map(([k]) => k) as { [key in K]: V[key] extends null ? never : key }[K][]\n}\n","import { Key } from '@charcoal-ui/theme'\nimport { unreachable } from './util'\n\n/**\n * 配列で指定したプロパティを動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param member オブジェクトに生やすプロパティ一覧\n * @param chain プロパティに格納される値を生成する関数\n *\n * @example\n *\n * const o = factory({}, ['red', 'blue'],\n * color => hex(color)\n * )\n *\n * console.log(o.red) //=> #ff0000\n */\nexport const factory = <TSource, TMember extends readonly Key[], TValue>(\n source: TSource,\n member: TMember,\n chain: (key: TMember[number]) => TValue\n) =>\n Object.defineProperties(\n source,\n Object.fromEntries(\n member.map((key) => [\n key,\n { get: () => chain(key), enumerable: true, configurable: true },\n ])\n )\n ) as TSource & { readonly [key in TMember[number]]: TValue }\n\n/**\n * 配列で指定した名前のメソッドを動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param member オブジェクトに生やすメソッド名一覧\n * @param chain メソッドの戻り値になる値を生成する関数\n *\n * @example\n *\n * const o = argumentedFactory({}, ['red', 'blue'],\n * (color, alpha: number) => hex(color, alpha)\n * )\n *\n * console.log(o.red(0.5)) //=> #ff000077\n */\nexport const argumentedFactory = <\n TSource,\n TMember extends readonly string[],\n TValue,\n TArguments extends unknown[]\n>(\n source: TSource,\n member: TMember,\n chain: (key: TMember[number], ...args: TArguments) => TValue\n) =>\n Object.defineProperties(\n source,\n Object.fromEntries(\n member.map((key) => [\n key,\n {\n value: (...args: TArguments) => chain(key, ...args),\n enumerable: true,\n configurable: true,\n },\n ])\n )\n ) as TSource & {\n readonly [key in TMember[number]]: (...args: TArguments) => TValue\n }\n\n/**\n * オブジェクトで指定したプロパティ名と値を動的に生やす\n *\n * @param source 拡張するオブジェクト\n * @param def オブジェクトに生やす定義(プロパティ名と値)\n *\n * @example\n *\n * const o = constFactory({}, {\n * red: '#f00',\n * blue: '#00f',\n * })\n *\n * console.log(o.red) //=> #f00\n */\nexport const constFactory = <TSource, TDef extends { [key: string]: unknown }>(\n source: TSource,\n def: TDef\n) =>\n factory(source, Object.keys(def), (key) => def[key]) as TSource &\n Readonly<TDef>\n\n/**\n * 配列で指定したモディファイア(プロパティ)をチェーン可能な再帰オブジェクトを動的に生やす\n *\n * @param modifiers オブジェクトに生やすモディファイヤ一覧\n * @param source 指定されたモディファイヤの一覧から値を生成する関数\n *\n * @example\n *\n * const o = modifiedArgumentedFactory(['red', 'blue'],\n * modifiers => modifiers.map(color => hex(color)).join(',')\n * )\n *\n * console.log(o.red.blue) => #f00,#00f\n */\nexport const modifiedFactory = <TSource, T extends Key>(\n modifiers: readonly T[],\n source: (applied: readonly T[]) => TSource\n) =>\n (function recursiveModifiedFactory(\n applied: readonly T[]\n ): Modified<TSource, T> {\n const notApplied = modifiers.filter((v) => !applied.includes(v))\n return factory(source(applied), notApplied, (modifier) =>\n notApplied.length === 0\n ? unreachable()\n : recursiveModifiedFactory([...applied, modifier])\n )\n })([])\n\nexport type Modified<TSource, TModifiers extends Key> = TSource & {\n readonly [key in TModifiers]: Modified<TSource, Exclude<TModifiers, key>>\n}\n\n/**\n * 配列で指定したモディファイア(メソッド)をチェーン可能な再帰オブジェクトを動的に生やす\n *\n * @param modifiers オブジェクトに生やすモディファイヤ一覧\n * @param source 指定されたモディファイヤの一覧から値を生成する関数\n * @param _inferPhantom 関数形式のモディファイヤの引数型を推論するためのメタタイプ(引数の個数に合わせてタプルで指定する)\n *\n * @example\n *\n * const o = modifiedArgumentedFactory(['red', 'blue'],\n * modifiers => modifiers.map(([color, alpha]) => hex(color, alpha)).join(',')\n * , {} as [number])\n *\n * console.log(o.red(0.5).blue(1)) => #ff000077,#0000ffff\n */\nexport const modifiedArgumentedFactory = <\n TSource,\n T extends string,\n TArguments extends unknown[]\n>(\n modifiers: readonly T[],\n source: (applied: readonly [T, ...TArguments][]) => TSource,\n ..._inferPhantom: TArguments\n) =>\n (function recursiveModifiedFactory(\n applied: readonly [T, ...TArguments][]\n ): ModifiedArgumented<TSource, T, TArguments> {\n const notApplied = modifiers.filter(\n (v) => !applied.map(([w]) => w).includes(v)\n )\n return argumentedFactory(\n source(applied),\n notApplied,\n (modifier, ...args: TArguments) =>\n notApplied.length === 0\n ? unreachable()\n : recursiveModifiedFactory([...applied, [modifier, ...args]])\n )\n })([])\n\nexport type ModifiedArgumented<\n TSource,\n TModifiers extends string,\n TArguments extends unknown[]\n> = TSource & {\n readonly [key in TModifiers]: (\n ...args: TArguments\n ) => ModifiedArgumented<TSource, Exclude<TModifiers, key>, TArguments>\n}\n","import { CSSObject, ThemedStyledInterface } from 'styled-components'\nimport warning from 'warning'\nimport {\n factory,\n modifiedFactory,\n constFactory,\n modifiedArgumentedFactory,\n} from './lib'\nimport {\n EffectType,\n CharcoalAbstractTheme as Theme,\n Key,\n} from '@charcoal-ui/theme'\nimport {\n objectAssign,\n unreachable,\n ReadonlyArrayConstructor,\n objectKeys,\n isPresent,\n} from './util'\nimport { columnSystem } from '@charcoal-ui/foundation'\nimport {\n halfLeading,\n applyEffect,\n applyEffectToGradient,\n dur,\n gradient,\n GradientDirection,\n notDisabledSelector,\n disabledSelector,\n px,\n} from '@charcoal-ui/utils'\nexport { type Modified, type ModifiedArgumented } from './lib'\n\nconst colorProperties = ['bg', 'font'] as const\ntype ColorProperty = typeof colorProperties[number]\n\nconst spacingProperties = ['margin', 'padding'] as const\nconst spacingDirections = [\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'vertical',\n 'horizontal',\n 'all',\n] as const\ntype SpacingProperty = typeof spacingProperties[number]\ntype SpacingDirection = typeof spacingDirections[number]\n\nconst fixedProperties = ['width', 'height'] as const\ntype FixedProperty = typeof fixedProperties[number]\n\nconst borderDirections = ['top', 'right', 'bottom', 'left'] as const\ntype BorderDirection = typeof borderDirections[number]\n\nconst outlineType = ['focus'] as const\ntype OutlineType = typeof outlineType[number]\n\n/**\n * `theme(o => [...])` の `o` の部分を構築する\n *\n * @param theme テーマオブジェクト\n * @param isPhantom 型推論のためだけに使う場合にランタイムコストをゼロにするフラグ\n */\nfunction builder<T extends Theme>(\n theme: {\n // factoryの第二引数に入れ込むものだけ明示的に型変数を展開しておくことで型の具象化を遅延する\n color: T['color']\n gradientColor: T['gradientColor']\n border: T['border']\n outline: T['outline']\n } & Omit<T, 'color' | 'gradientColor' | 'border' | 'outline'>,\n isPhantom = false\n) {\n if (isPhantom) {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n return {} as never\n }\n const colors = objectKeys(theme.color)\n const effects = objectKeys(theme.effect)\n\n // 色\n const gradientColors = objectKeys(theme.gradientColor)\n const colorCss = createColorCss(theme)\n const gradientColorCss = createGradientColorCss(theme)\n const colorObject = constFactory(\n {},\n {\n bg: objectAssign(\n factory({}, colors, (color) =>\n modifiedFactory(effects, (modifiers) =>\n colorCss('bg', color, modifiers)\n )\n ),\n factory(\n {},\n gradientColors,\n (color) => (direction: GradientDirection) =>\n modifiedFactory(effects, (modifiers) =>\n gradientColorCss(color, modifiers, direction)\n )\n )\n ),\n font: factory({}, colors, (color) =>\n modifiedFactory(effects, (modifiers) =>\n colorCss('font', color, modifiers)\n )\n ),\n }\n )\n\n // タイポグラフィ\n const typographyModifiers = [\n // TODO\n 'monospace',\n 'bold',\n 'preserveHalfLeading',\n ] as const\n const typographyCss = createTypographyCss(theme)\n const typographyObject = factory(\n {},\n ['typography'] as const,\n (_) => (size: keyof T['typography']['size']) =>\n modifiedFactory(typographyModifiers, (modifiers) =>\n typographyCss(size, {\n preserveHalfLeading: modifiers.includes('preserveHalfLeading'),\n monospace: modifiers.includes('monospace'),\n bold: modifiers.includes('bold'),\n })\n )\n )\n\n // スペーシング\n const spacingCss = createSpacingCss(theme)\n const spacingObject = factory({}, spacingProperties, (spacingProperty) =>\n modifiedArgumentedFactory(\n spacingDirections,\n (modifiers) => spacingCss(spacingProperty, modifiers),\n {} as keyof T['spacing'] | 'auto' // 推論のためのメタタイプ\n )\n )\n\n // 大きさ\n const fixedPxCss = createFixedPxCss(theme)\n const fixedColumnCss = createFixedColumnCss(theme)\n const fixedRelativeCss = createFixedRelativeCss(theme)\n const fixedObject = factory({}, fixedProperties, (property) =>\n constFactory(\n {},\n {\n px: (size: keyof T['spacing'] | 'auto') => fixedPxCss(property, size),\n column: (span: number) => fixedColumnCss(property, span),\n auto: fixedRelativeCss(property, 'auto'),\n full: fixedRelativeCss(property, '100%'),\n }\n )\n )\n\n // 要素へのエフェクト (etc: 透過)\n const elementEffectCss = createElementEffectCss(theme)\n const elementEffectObject = modifiedFactory(\n objectKeys(theme.elementEffect),\n (modifiers) => elementEffectCss(modifiers)\n )\n\n // ボーダー\n const borderCss = createBorderCss(theme)\n const borderObject = constFactory(\n {},\n {\n border: factory({}, objectKeys(theme.border), (variant) =>\n modifiedFactory(borderDirections, (modifiers) =>\n borderCss(variant, modifiers)\n )\n ),\n }\n )\n\n // 角丸\n const borderRadiusCss = createBorderRadiusCss(theme)\n const borderRadiusObject = constFactory(\n {},\n {\n borderRadius: (radius: keyof T['borderRadius']) =>\n borderRadiusCss(radius),\n }\n )\n\n // アウトライン\n const outlineCss = createOutlineColorCss(theme)\n const outlineObject = constFactory(\n {},\n {\n outline: factory({}, objectKeys(theme.outline), (variant) =>\n modifiedFactory(outlineType, (modifiers) =>\n outlineCss(variant, modifiers)\n )\n ),\n }\n )\n\n return objectAssign(\n colorObject,\n typographyObject,\n spacingObject,\n fixedObject,\n elementEffectObject,\n borderObject,\n borderRadiusObject,\n outlineObject\n )\n}\n\nfunction targetProperty(target: ColorProperty) {\n return target === 'bg' ? 'background-color' : 'color'\n}\n\nfunction isSupportedEffect(effect: Key): effect is EffectType {\n return ['hover', 'press', 'disabled'].includes(effect as string)\n}\n\nfunction onEffectPseudo(effect: EffectType, css: CSSObject) {\n return effect === 'hover'\n ? { '&:hover': { [notDisabledSelector]: css } }\n : effect === 'press'\n ? { '&:active': { [notDisabledSelector]: css } }\n : // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n effect === 'disabled'\n ? { [disabledSelector]: css }\n : unreachable(effect)\n}\n\nconst createColorCss =\n <T extends Theme>(theme: T) =>\n (\n target: ColorProperty,\n color: keyof T['color'],\n effects: readonly (keyof T['effect'])[] = []\n ): Internal =>\n internal(\n () => ({\n [targetProperty(target)]: theme.color[color],\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n [targetProperty(target)]: applyEffect(\n theme.color[color],\n theme.effect[effect] ?? []\n ),\n }),\n }),\n {}\n ),\n }),\n effects.length > 0\n ? target === 'font'\n ? {\n colorTransition: true,\n }\n : {\n backgroundColorTransition: true,\n }\n : {}\n )\n\n// TODO: deprecate\nconst TRANSITION_DURATION = 0.2\n\nconst createGradientColorCss =\n <T extends Theme>(theme: T) =>\n (\n color: keyof T['gradientColor'],\n effects: readonly (keyof T['effect'])[] = [],\n direction: GradientDirection\n ): Internal => {\n const toLinearGradient = gradient(direction)\n return internal((context) => {\n const optimized = !useHalfLeadingCanceller(context)\n const duration = dur(TRANSITION_DURATION)\n if (optimized && effects.length > 0) {\n return {\n position: 'relative',\n zIndex: 0,\n overflow: 'hidden',\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n '&::before': {\n zIndex: -1,\n ...overlayElement,\n transition: `${duration} background-color`,\n },\n '&::after': {\n zIndex: -2,\n ...overlayElement,\n ...toLinearGradient(theme.gradientColor[color]),\n },\n ...onEffectPseudo(effect, {\n '&::before': {\n backgroundColor: applyEffect(\n null,\n theme.effect[effect] ?? []\n ),\n },\n }),\n }),\n {}\n ),\n }\n } else {\n warning(\n effects.length === 0,\n // eslint-disable-next-line max-len\n `'Transition' will not be applied. You can get around this by specifying 'preserveHalfLeading' or both 'padding' and 'typograpy'.`\n )\n return {\n ...toLinearGradient(theme.gradientColor[color]),\n ...effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n ...toLinearGradient(\n applyEffectToGradient(theme.effect[effect] ?? [])(\n theme.gradientColor[color]\n )\n ),\n }),\n }),\n {}\n ),\n }\n }\n })\n }\n\n/**\n * @see https://developer.mozilla.org/ja/docs/Web/CSS/:focus-visible#selectively_showing_the_focus_indicator\n */\nconst onFocus = (css: CSSObject) => ({\n [notDisabledSelector]: {\n '&:focus, &:active': {\n outline: 'none',\n ...css,\n },\n\n '&:focus:not(:focus-visible), &:active:not(:focus-visible)': {\n outline: 'none',\n },\n\n '&:focus-visible': {\n outline: 'none',\n ...css,\n },\n },\n})\n\nconst outlineCss = (weight: number, color: string) => ({\n boxShadow: `0 0 0 ${px(weight)} ${color}`,\n})\n\nconst createOutlineColorCss =\n <T extends Theme>(theme: T) =>\n (\n variant: keyof T['outline'],\n modifiers: readonly OutlineType[]\n ): Internal => {\n const weight = theme.outline[variant].weight\n const color = theme.outline[variant].color\n return internal(\n () =>\n modifiers.includes('focus')\n ? onFocus(outlineCss(weight, color))\n : { '&&': { [notDisabledSelector]: outlineCss(weight, color) } },\n {\n boxShadowTransition: true,\n }\n )\n }\n\nconst overlayElement: CSSObject = {\n content: \"''\",\n display: 'block',\n position: 'absolute',\n width: '100%',\n height: '100%',\n top: 0,\n left: 0,\n}\n\n// half-leadingをキャンセルするとき && 垂直方向のpaddingが無い時\n// -> before/afterを入れる\nconst useHalfLeadingCanceller = ({\n cancelHalfLeadingPx,\n hasVerticalPadding = false,\n}: Context) => cancelHalfLeadingPx !== undefined && !hasVerticalPadding\n\nconst createTypographyCss =\n <T extends Theme>(theme: T) =>\n (\n size: keyof T['typography']['size'],\n options: {\n preserveHalfLeading?: boolean\n monospace?: boolean\n bold?: boolean\n } = {}\n ): Internal => {\n const {\n preserveHalfLeading = false,\n monospace = false,\n bold = false,\n } = options\n const descriptor = theme.typography.size[size]\n const margin = -halfLeading(descriptor)\n\n return internal(\n (context) => ({\n fontSize: px(descriptor.fontSize),\n lineHeight: px(descriptor.lineHeight),\n ...(monospace && {\n fontFamily: 'monospace',\n }),\n ...(bold && {\n fontWeight: 'bold',\n }),\n ...(useHalfLeadingCanceller(context) && {\n // prevent margin collapsing\n display: 'flow-root',\n // cancel half-leading with negative margin\n '&::before': {\n ...leadingCancel,\n marginTop: px(margin),\n },\n '&::after': {\n ...leadingCancel,\n marginBottom: px(margin),\n },\n }),\n }),\n !preserveHalfLeading\n ? {\n cancelHalfLeadingPx: margin,\n }\n : {}\n )\n }\n\nconst leadingCancel: CSSObject = {\n display: 'block',\n width: 0,\n height: 0,\n content: `''`,\n}\n\nfunction spacingProperty(\n property: SpacingProperty,\n direction: 'top' | 'right' | 'bottom' | 'left'\n) {\n return `${property}-${direction}`\n}\n\nconst createSpacingCss =\n <T extends Theme>(theme: { spacing: T['spacing'] }) =>\n (\n property: SpacingProperty,\n modifiers: readonly [SpacingDirection, keyof T['spacing'] | 'auto'][]\n ): Internal => {\n const { top, right, bottom, left } = modifiers.reduce(\n (acc, [direction, size]) => {\n if (direction === 'all') {\n acc.top = size\n acc.right = size\n acc.bottom = size\n acc.left = size\n } else if (direction === 'vertical') {\n acc.top = size\n acc.bottom = size\n } else if (direction === 'horizontal') {\n acc.right = size\n acc.left = size\n } else {\n acc[direction] = size\n }\n return acc\n },\n {} as Partial<\n Record<'top' | 'right' | 'bottom' | 'left', keyof T['spacing'] | 'auto'>\n >\n )\n\n const hasVerticalPadding =\n property === 'padding' &&\n top !== undefined &&\n bottom !== undefined &&\n top !== 'auto' &&\n bottom !== 'auto'\n\n return internal(\n ({ cancelHalfLeadingPx = 0 }) => ({\n ...(top !== undefined && {\n [spacingProperty(property, 'top')]:\n top === 'auto'\n ? 'auto'\n : px(\n theme.spacing[top] +\n (hasVerticalPadding ? cancelHalfLeadingPx : 0)\n ),\n }),\n ...(bottom !== undefined && {\n [spacingProperty(property, 'bottom')]:\n bottom === 'auto'\n ? 'auto'\n : px(\n theme.spacing[bottom] +\n (hasVerticalPadding ? cancelHalfLeadingPx : 0)\n ),\n }),\n ...(right !== undefined && {\n [spacingProperty(property, 'right')]:\n right === 'auto' ? 'auto' : px(theme.spacing[right]),\n }),\n ...(left !== undefined && {\n [spacingProperty(property, 'left')]:\n left === 'auto' ? 'auto' : px(theme.spacing[left]),\n }),\n }),\n hasVerticalPadding ? { hasVerticalPadding: true } : {}\n )\n }\n\nconst createFixedPxCss =\n <T extends Theme>(theme: T) =>\n (property: FixedProperty, size: keyof T['spacing'] | 'auto'): Internal =>\n internal(() => ({\n [property]: size === 'auto' ? 'auto' : px(theme.spacing[size]),\n }))\n\nconst createFixedRelativeCss =\n <T extends Theme>(_theme: T) =>\n (property: FixedProperty, amount: '100%' | 'auto'): Internal =>\n internal(() => ({\n [property]: amount,\n }))\n\nconst createFixedColumnCss =\n <T extends Theme>(theme: T) =>\n (property: FixedProperty, span: number): Internal =>\n internal(() => ({\n [property]: px(\n columnSystem(span, theme.grid.unit.column, theme.grid.unit.gutter)\n ),\n }))\n\nconst createElementEffectCss =\n <T extends Theme, TElementEffect extends T['elementEffect']>(theme: {\n elementEffect: TElementEffect\n }) =>\n (effects: readonly (keyof TElementEffect)[] = []): Internal =>\n internal(() =>\n effects.filter(isSupportedEffect).reduce<CSSObject>(\n (acc, effect) => ({\n ...acc,\n ...onEffectPseudo(effect, {\n opacity:\n !(Array as ReadonlyArrayConstructor).isArray(\n theme.elementEffect[effect]\n ) && theme.elementEffect[effect]?.type === 'opacity'\n ? theme.elementEffect[effect]?.opacity\n : unreachable(),\n }),\n }),\n {}\n )\n )\n\nfunction borderProperty(direction: BorderDirection) {\n return `border-${direction}`\n}\n\nfunction borderShorthand(color: string) {\n return `solid 1px ${color}`\n}\n\nconst createBorderCss =\n <T extends Theme>(theme: T) =>\n (\n variant: keyof T['border'],\n directions: readonly BorderDirection[]\n ): Internal => {\n const all = directions.length === 0\n const value = borderShorthand(theme.border[variant].color)\n return internal(() => ({\n ...(all\n ? { border: value }\n : directions.reduce<CSSObject>(\n (acc, direction) => ({\n ...acc,\n [borderProperty(direction)]: value,\n }),\n {}\n )),\n }))\n }\n\nconst createBorderRadiusCss =\n <T extends Theme>(theme: T) =>\n (size: keyof T['borderRadius']): Internal =>\n internal(() => ({\n borderRadius: px(theme.borderRadius[size]),\n }))\n\ninterface Context {\n cancelHalfLeadingPx?: number\n hasVerticalPadding?: boolean\n boxShadowTransition?: boolean\n colorTransition?: boolean\n backgroundColorTransition?: boolean\n}\n\nconst commonSpec = (_theme: unknown): Internal => {\n const duration = dur(TRANSITION_DURATION)\n const transition = (property: string[]) => ({\n transition: property.map((v) => `${duration} ${v}`).join(', '),\n })\n return internal(\n ({\n colorTransition = false,\n backgroundColorTransition = false,\n boxShadowTransition = false,\n }) =>\n transition(\n [\n colorTransition ? 'color' : null,\n backgroundColorTransition ? 'background-color' : null,\n boxShadowTransition ? 'box-shadow' : null,\n ].filter(isPresent)\n )\n )\n}\n\nconst internalSym: unique symbol = Symbol('internal')\n\nfunction internal(\n operation: (context: Context) => CSSObject,\n context: Context = {}\n): Internal {\n return {\n [internalSym]: {\n operation,\n context,\n },\n }\n}\n\nexport interface Internal {\n [internalSym]: {\n operation: (context: Context) => CSSObject\n context: Context\n }\n}\n\ntype Blank = null | undefined | false\n\nconst nonBlank = <T>(value: T): value is T extends Blank ? never : T =>\n isPresent(value) && (value as unknown) !== false\n\n/**\n * `theme(o => [...])` の `theme` ユーティリティを構築する\n *\n * @param _styled styled-componnets の `styled` そのもの (型推論のために用いられる)\n *\n * @example\n *\n * import styled from 'styled-components'\n * const theme = createTheme(styled)\n *\n * @example\n *\n * const theme = createTheme<DefaultTheme>()\n */\nfunction createTheme<T extends Theme>(_styled?: ThemedStyledInterface<T>) {\n // `theme(o => [...])` の `o` の部分の型推論のためだけに使う意味のない変数\n // Tを型変数のまま渡してcreateThemeが呼ばれるまで型の具象化が行われないようにする\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n const _phantomBuilder = builder<T>({} as any, true)\n // ランタイムの `theme(o => [...])` のインターフェースを構築する\n return (\n // ユーザー定義\n spec: (\n o: typeof _phantomBuilder\n ) => Blank | Internal | (Blank | Internal)[]\n ): ThemeProp<T> =>\n ({ theme }) => {\n // styled-componentsのランタイムから受け取ったthemeオブジェクトをbuilderに食わせて`o`をつくる\n // さらに、ユーザー定義にbuilderが構築した`o`を食わせる\n // (`o`を一時変数に入れてしまうと型Tの具象化が行われるので関数合成を優先する)\n const rawSpecDescriptor = spec(builder(theme))\n // ユーザー定義の配列を整形\n const specDescriptor = [\n ...(Array.isArray(rawSpecDescriptor)\n ? rawSpecDescriptor\n : [rawSpecDescriptor]),\n commonSpec(theme),\n ].filter(nonBlank)\n\n // 1パス目\n // 全ユーザー定義を舐めて相互に影響し合う定義をチェックし、その結果(コンテキスト)を取得\n const context = specDescriptor.reduce<Context>(\n (acc, v) => ({ ...acc, ...v[internalSym].context }),\n {}\n )\n // 2パス目\n // コンテキストを見ながら最適化されたCSSを構築\n return specDescriptor.map((v) => v[internalSym].operation(context))\n }\n}\n\nexport default createTheme\n\nexport type ThemeProp<T> = ({ theme }: { theme: T }) => CSSObject | CSSObject[]\n"],"names":["unreachable","value","Error","arguments","length","JSON","stringify","isPresent","objectAssign","Object","assign","objectKeys","obj","keys","factory","source","member","chain","defineProperties","fromEntries","map","key","get","enumerable","configurable","constFactory","def","modifiedFactory","modifiers","recursiveModifiedFactory","applied","notApplied","filter","v","includes","modifier","spacingProperties","spacingDirections","fixedProperties","borderDirections","outlineType","builder","theme","isPhantom","colors","color","effects","effect","gradientColors","gradientColor","colorCss","createColorCss","gradientColorCss","createGradientColorCss","colorObject","bg","direction","font","typographyModifiers","typographyCss","createTypographyCss","typographyObject","_","size","preserveHalfLeading","monospace","bold","spacingCss","createSpacingCss","spacingObject","spacingProperty","argumentedFactory","fixedPxCss","createFixedPxCss","fixedColumnCss","createFixedColumnCss","fixedRelativeCss","createFixedRelativeCss","fixedObject","property","px","column","span","auto","full","elementEffectCss","createElementEffectCss","elementEffectObject","elementEffect","borderCss","createBorderCss","borderObject","border","variant","borderRadiusCss","createBorderRadiusCss","borderRadiusObject","borderRadius","radius","outlineCss","createOutlineColorCss","outline","targetProperty","target","isSupportedEffect","onEffectPseudo","css","notDisabledSelector","disabledSelector","internal","reduce","acc","applyEffect","colorTransition","backgroundColorTransition","toLinearGradient","gradient","context","optimized","useHalfLeadingCanceller","duration","dur","position","zIndex","overflow","overlayElement","transition","backgroundColor","warning","applyEffectToGradient","weight","boxShadow","boxShadowTransition","content","display","width","height","top","left","hasVerticalPadding","undefined","cancelHalfLeadingPx","options","descriptor","typography","margin","halfLeading","fontSize","lineHeight","fontFamily","fontWeight","leadingCancel","marginTop","marginBottom","right","bottom","spacing","_theme","amount","columnSystem","grid","unit","gutter","opacity","Array","isArray","type","_theme$elementEffect$2","directions","all","borderProperty","internalSym","Symbol","operation","nonBlank","createTheme","_styled","spec","rawSpecDescriptor","specDescriptor","join"],"mappings":"kdAwBgBA,EAAYC,GAC1B,UAAUC,MACa,IAArBC,UAAUC,OACN,8BACgBC,KAAKC,UAAUL,YAS1BM,EAAY,SAAIN,UAA+C,MAATA,YA4BnDO,IACd,OAAOC,OAAOC,aAAPD,QAAc,+CAGPE,EAAiCC,GAC/C,OAAOH,OAAOI,KAAKD,OCpDRE,EAAU,SACrBC,EACAC,EACAC,UAEAR,OAAOS,iBACLH,EACAN,OAAOU,YACLH,EAAOI,IAAI,SAACC,SAAQ,CAClBA,EACA,CAAEC,IAAK,kBAAML,EAAMI,IAAME,YAAY,EAAMC,cAAc,SA6DpDC,EAAe,SAC1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hBsD,GAAc,CACbE,UAAAA,EACAxD,QAAAA,KAcN,IAAMyD,EAAW,SAAI7K,UACnBM,EAAUN,KAAiC,IAAtBA,GAgBvB,SAAS8K,EAA6BC,GAMpC,OAFwBvI,EAAW,IAAW,YAI1CwI,0BApEEzD,EA4EI0D,EAAoBD,EAAKxI,IAJ9BC,QAMKyI,EAAiB,UACjBf,MAAMC,QAAQa,GACdA,EACA,CAACA,KAjFL1D,EAAWC,EAjWS,IAqWnBZ,EACL,oBACEI,oBACAC,8BACAkB,0BAPwC,CAC1CN,WASI,eACoB,QAAU,mBACA,mBAAqB,mBAC3B,aAAe,MACrC9F,OAAOzB,GAbQa,IAAI,SAACa,UAASuF,MAAYvF,IAAKmJ,KAAK,YAiFrDpJ,OAAO8I,GAIHzD,EAAU8D,EAAerE,OAC7B,SAACC,EAAK9E,eAAY8E,EAAQ9E,EAAE0I,GAAatD,UACzC,IAIF,OAAO8D,EAAe/J,IAAI,SAACa,UAAMA,EAAE0I,GAAaE,UAAUxD"}
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,WAAW,IAAI,KAAK,CAAA;AACpC;;;;;;;;;;;;;;;;GAgBG;AAGH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAA;AAShD;;;;GAIG;AACH,eAAO,MAAM,SAAS,0CAA0D,CAAA;
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,WAAW,IAAI,KAAK,CAAA;AACpC;;;;;;;;;;;;;;;;GAgBG;AAGH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAA;AAShD;;;;GAIG;AACH,eAAO,MAAM,SAAS,0CAA0D,CAAA;AAGhF,aAAK,IAA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AG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC;CACnB,2DAIA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@charcoal-ui/styled",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-alpha.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"typescript": "^4.5.5"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@charcoal-ui/foundation": "^1.0.0",
|
|
33
|
-
"@charcoal-ui/theme": "^
|
|
34
|
-
"@charcoal-ui/utils": "^1.0.0",
|
|
32
|
+
"@charcoal-ui/foundation": "^1.0.1-alpha.0",
|
|
33
|
+
"@charcoal-ui/theme": "^2.0.0-alpha.1",
|
|
34
|
+
"@charcoal-ui/utils": "^1.0.1-alpha.0",
|
|
35
35
|
"warning": "^4.0.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
@@ -45,5 +45,10 @@
|
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "https://github.com/pixiv/charcoal.git",
|
|
51
|
+
"directory": "packages/styled"
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "6740b50cd147f29b8da7c16e93c15b5799900d33"
|
|
49
54
|
}
|
package/src/util.ts
CHANGED
|
@@ -37,26 +37,32 @@ export function unreachable(value?: never): never {
|
|
|
37
37
|
*/
|
|
38
38
|
export const isPresent = <T>(value: T): value is NonNullable<T> => value != null
|
|
39
39
|
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
41
|
type Head<U> = U extends [infer T, ...any[]] ? T : never
|
|
41
42
|
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
44
|
type Tail<U> = U extends [any, any, ...any[]]
|
|
43
|
-
?
|
|
45
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
((...args: U) => any) extends (head: any, ...args: infer T) => any
|
|
44
47
|
? T
|
|
45
48
|
: never
|
|
46
49
|
: never
|
|
47
50
|
// Buggy at ts@4.0.0-dev20200506
|
|
48
51
|
// type Tail<U> = U extends [any, ...infer T] ? T : never
|
|
49
52
|
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
54
|
type RecursiveObjectAssign<T, S extends any[]> = {
|
|
51
55
|
0: T & Head<S>
|
|
52
56
|
1: RecursiveObjectAssign<T & Head<S>, Tail<S>>
|
|
53
57
|
}[Tail<S> extends never ? 0 : 1]
|
|
54
58
|
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
60
|
type ObjectAssign<T extends any[]> = RecursiveObjectAssign<
|
|
56
61
|
Record<string, unknown>,
|
|
57
62
|
T
|
|
58
63
|
>
|
|
59
64
|
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
66
|
export function objectAssign<T extends any[]>(...sources: T) {
|
|
61
67
|
return Object.assign({}, ...sources) as ObjectAssign<T>
|
|
62
68
|
}
|
|
@@ -66,6 +72,7 @@ export function objectKeys<V, K extends keyof V>(obj: V) {
|
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
export interface ReadonlyArrayConstructor {
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
76
|
isArray(value: any): value is readonly any[]
|
|
70
77
|
}
|
|
71
78
|
|