File size: 2,273 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { clone, mergeWith } from "../utils"
import type { CompositionStyles } from "./composition"
import type {
  GlobalStyleIdentityFn,
  KeyframeIdentityFn,
  SystemStyleIdentityFn,
} from "./css.types"
import type { RecipeIdentityFn, SlotRecipeIdentityFn } from "./recipe.types"
import type {
  ConditionRecord,
  SemanticTokenDefinition,
  SystemConfig,
  TokenDefinition,
} from "./types"

/* -----------------------------------------------------------------------------
 * Core creators
 * -----------------------------------------------------------------------------*/

export const defineConditions = <T extends ConditionRecord>(v: T): T => v

export const defineRecipe: RecipeIdentityFn = (v) => v

export const defineSlotRecipe: SlotRecipeIdentityFn = (v) => v

export const defineKeyframes: KeyframeIdentityFn = (v) => v

export const defineGlobalStyles: GlobalStyleIdentityFn = (v) => v

export const defineStyle: SystemStyleIdentityFn = (v) => v

export const defineTextStyles = (v: CompositionStyles["textStyles"]) => v

export const defineAnimationStyles = (
  v: CompositionStyles["animationStyles"],
) => v

export const defineLayerStyles = (v: CompositionStyles["layerStyles"]) => v

/* -----------------------------------------------------------------------------
 * Token creators
 * -----------------------------------------------------------------------------*/

type ProxyValue<T> = {
  <Value>(definition: Value extends T ? Value : T): Value
} & {
  [K in keyof Required<T>]: <Value>(
    definition: Value extends T[K] ? Value : T[K],
  ) => Value
}

function createProxy<T>(): ProxyValue<T> {
  const identity = (v: unknown) => v
  return new Proxy(identity as any, {
    get() {
      return identity
    },
  })
}

export const defineTokens = /* @__PURE__ */ createProxy<TokenDefinition>()
export const defineSemanticTokens =
  /* @__PURE__ */ createProxy<SemanticTokenDefinition>()

/* -----------------------------------------------------------------------------
 * System creators
 * -----------------------------------------------------------------------------*/

export const defineConfig = (v: SystemConfig) => v

export const mergeConfigs = (...configs: SystemConfig[]): SystemConfig => {
  return mergeWith({}, ...configs.map(clone))
}