zyzz 0.0.2 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -19
- package/dist/Config.d.ts +16 -167
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +7 -246
- package/dist/Config.js.map +1 -1
- package/dist/Style.d.ts +19 -13
- package/dist/Style.d.ts.map +1 -1
- package/dist/Style.js +73 -7
- package/dist/Style.js.map +1 -1
- package/dist/Vars.d.ts +114 -0
- package/dist/Vars.d.ts.map +1 -0
- package/dist/Vars.js +42 -0
- package/dist/Vars.js.map +1 -0
- package/dist/compiler/Graph.js +11 -8
- package/dist/compiler/Graph.js.map +1 -1
- package/dist/compiler/Native.d.ts +5 -5
- package/dist/compiler/Native.d.ts.map +1 -1
- package/dist/compiler/Native.js +21 -21
- package/dist/compiler/Native.js.map +1 -1
- package/dist/compiler/Source.d.ts +10 -6
- package/dist/compiler/Source.d.ts.map +1 -1
- package/dist/compiler/Source.js +66 -11
- package/dist/compiler/Source.js.map +1 -1
- package/dist/compiler/Transform.d.ts +1 -1
- package/dist/compiler/Transform.d.ts.map +1 -1
- package/dist/compiler/Transform.js +59 -21
- package/dist/compiler/Transform.js.map +1 -1
- package/dist/compiler/internal/Compositions.d.ts +5 -0
- package/dist/compiler/internal/Compositions.d.ts.map +1 -1
- package/dist/compiler/internal/Compositions.js +22 -3
- package/dist/compiler/internal/Compositions.js.map +1 -1
- package/dist/compiler/internal/Configurations.d.ts.map +1 -1
- package/dist/compiler/internal/Configurations.js +73 -12
- package/dist/compiler/internal/Configurations.js.map +1 -1
- package/dist/compiler/internal/Contract.d.ts +1 -1
- package/dist/compiler/internal/Contract.d.ts.map +1 -1
- package/dist/compiler/internal/Contract.js +162 -13
- package/dist/compiler/internal/Contract.js.map +1 -1
- package/dist/compiler/internal/Contributions.js +1 -1
- package/dist/compiler/internal/Contributions.js.map +1 -1
- package/dist/compiler/internal/Dynamic.js +1 -1
- package/dist/compiler/internal/Dynamic.js.map +1 -1
- package/dist/compiler/internal/Expression.d.ts +3 -0
- package/dist/compiler/internal/Expression.d.ts.map +1 -1
- package/dist/compiler/internal/Expression.js +21 -0
- package/dist/compiler/internal/Expression.js.map +1 -1
- package/dist/compiler/internal/Identifiers.d.ts +1 -1
- package/dist/compiler/internal/Identifiers.d.ts.map +1 -1
- package/dist/compiler/internal/Identifiers.js +2 -2
- package/dist/compiler/internal/Identifiers.js.map +1 -1
- package/dist/compiler/internal/NativeBindings.d.ts +1 -1
- package/dist/compiler/internal/NativeBindings.d.ts.map +1 -1
- package/dist/compiler/internal/NativeBindings.js +3 -3
- package/dist/compiler/internal/NativeBindings.js.map +1 -1
- package/dist/compiler/internal/PackedStyles.d.ts +1 -1
- package/dist/compiler/internal/PackedStyles.d.ts.map +1 -1
- package/dist/compiler/internal/PackedStyles.js +15 -25
- package/dist/compiler/internal/PackedStyles.js.map +1 -1
- package/dist/compiler/internal/Recipes.js +1 -1
- package/dist/compiler/internal/Recipes.js.map +1 -1
- package/dist/compiler/internal/Selectors.js +1 -1
- package/dist/compiler/internal/Selectors.js.map +1 -1
- package/dist/compiler/internal/Themes.d.ts +12 -3
- package/dist/compiler/internal/Themes.d.ts.map +1 -1
- package/dist/compiler/internal/Themes.js +192 -52
- package/dist/compiler/internal/Themes.js.map +1 -1
- package/dist/compiler/internal/{Variables.d.ts → Vars.d.ts} +1 -1
- package/dist/compiler/internal/Vars.d.ts.map +1 -0
- package/dist/compiler/internal/{Variables.js → Vars.js} +3 -3
- package/dist/compiler/internal/Vars.js.map +1 -0
- package/dist/default.d.ts +451 -1649
- package/dist/default.d.ts.map +1 -1
- package/dist/default.js +389 -80
- package/dist/default.js.map +2 -2
- package/dist/default.js.zyzz.json +1 -1
- package/dist/esbuild/index.d.ts +3 -0
- package/dist/esbuild/index.d.ts.map +1 -0
- package/dist/esbuild/index.js +5 -0
- package/dist/esbuild/index.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/internal/Authoring.d.ts +1 -1
- package/dist/internal/Authoring.d.ts.map +1 -1
- package/dist/internal/Authoring.js +4 -4
- package/dist/internal/Authoring.js.map +1 -1
- package/dist/internal/Binding.d.ts +1 -1
- package/dist/internal/Binding.d.ts.map +1 -1
- package/dist/internal/Completion.d.ts +19 -0
- package/dist/internal/Completion.d.ts.map +1 -0
- package/dist/internal/Completion.js +2 -0
- package/dist/internal/Completion.js.map +1 -0
- package/dist/internal/Condition.d.ts +3 -1
- package/dist/internal/Condition.d.ts.map +1 -1
- package/dist/internal/Condition.js.map +1 -1
- package/dist/internal/Configuration.d.ts +248 -0
- package/dist/internal/Configuration.d.ts.map +1 -0
- package/dist/internal/Configuration.js +343 -0
- package/dist/internal/Configuration.js.map +1 -0
- package/dist/internal/Shorthands.d.ts +1 -1
- package/dist/internal/Shorthands.d.ts.map +1 -1
- package/dist/internal/Shorthands.js +1 -0
- package/dist/internal/Shorthands.js.map +1 -1
- package/dist/{Theme.d.ts → internal/Theme.d.ts} +24 -19
- package/dist/internal/Theme.d.ts.map +1 -0
- package/dist/{Theme.js → internal/Theme.js} +57 -14
- package/dist/internal/Theme.js.map +1 -0
- package/dist/internal/Token.d.ts +46 -16
- package/dist/internal/Token.d.ts.map +1 -1
- package/dist/internal/Token.js +89 -5
- package/dist/internal/Token.js.map +1 -1
- package/dist/internal/Typography.d.ts +31 -0
- package/dist/internal/Typography.d.ts.map +1 -0
- package/dist/internal/Typography.js +54 -0
- package/dist/internal/Typography.js.map +1 -0
- package/dist/internal/Value.d.ts +6 -1
- package/dist/internal/Value.d.ts.map +1 -1
- package/dist/internal/Value.js.map +1 -1
- package/dist/internal/VariableSets.d.ts +20 -0
- package/dist/internal/VariableSets.d.ts.map +1 -0
- package/dist/internal/VariableSets.js +317 -0
- package/dist/internal/VariableSets.js.map +1 -0
- package/dist/next/loader.js +15 -5
- package/dist/next/loader.js.map +1 -1
- package/dist/node/Host.d.ts.map +1 -1
- package/dist/node/Host.js +1 -1
- package/dist/node/Host.js.map +1 -1
- package/dist/react-native/Host.d.ts +2 -2
- package/dist/react-native/Host.d.ts.map +1 -1
- package/dist/react-native/Host.js +4 -4
- package/dist/react-native/Host.js.map +1 -1
- package/dist/react-native/StyleSheet.d.ts +9 -8
- package/dist/react-native/StyleSheet.d.ts.map +1 -1
- package/dist/react-native/StyleSheet.js +29 -23
- package/dist/react-native/StyleSheet.js.map +1 -1
- package/dist/react-native/Variants.d.ts +3 -3
- package/dist/react-native/Variants.d.ts.map +1 -1
- package/dist/react-native/Variants.js +2 -2
- package/dist/react-native/react.d.ts +1 -1
- package/dist/react-native/react.d.ts.map +1 -1
- package/dist/react-native/react.js +5 -5
- package/dist/react-native/react.js.map +1 -1
- package/dist/rollup/index.d.ts +3 -0
- package/dist/rollup/index.d.ts.map +1 -0
- package/dist/rollup/index.js +5 -0
- package/dist/rollup/index.js.map +1 -0
- package/dist/runtime/Appearance.d.ts +7 -7
- package/dist/runtime/Appearance.d.ts.map +1 -1
- package/dist/runtime/Appearance.js +15 -15
- package/dist/runtime/Appearance.js.map +1 -1
- package/dist/runtime/Dynamic.d.ts.map +1 -1
- package/dist/runtime/Dynamic.js +4 -1
- package/dist/runtime/Dynamic.js.map +1 -1
- package/dist/runtime/NativeContext.d.ts +4 -4
- package/dist/runtime/NativeContext.d.ts.map +1 -1
- package/dist/runtime/NativeContext.js +5 -5
- package/dist/runtime/NativeContext.js.map +1 -1
- package/dist/runtime/NativeDynamic.d.ts +1 -1
- package/dist/runtime/NativeDynamic.d.ts.map +1 -1
- package/dist/runtime/NativeDynamic.js.map +1 -1
- package/dist/runtime/Props.d.ts +1 -1
- package/dist/runtime/Props.js +3 -3
- package/dist/runtime/Props.js.map +1 -1
- package/dist/runtime/Selection.d.ts +14 -10
- package/dist/runtime/Selection.d.ts.map +1 -1
- package/dist/runtime/Selection.js +19 -18
- package/dist/runtime/Selection.js.map +1 -1
- package/dist/styleFunction.d.ts +14 -14
- package/dist/styleFunction.d.ts.map +1 -1
- package/dist/styleFunction.js.map +1 -1
- package/dist/unplugin/index.d.ts +20 -0
- package/dist/unplugin/index.d.ts.map +1 -0
- package/dist/unplugin/index.js +498 -0
- package/dist/unplugin/index.js.map +1 -0
- package/dist/variants.d.ts +3 -3
- package/dist/variants.d.ts.map +1 -1
- package/dist/variants.js.map +1 -1
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +6 -3
- package/dist/vite/index.js.map +1 -1
- package/dist/web/Css.d.ts +4 -3
- package/dist/web/Css.d.ts.map +1 -1
- package/dist/web/Css.js +4 -4
- package/dist/web/Css.js.map +1 -1
- package/dist/web/internal/Themes.d.ts +3 -2
- package/dist/web/internal/Themes.d.ts.map +1 -1
- package/dist/web/internal/Themes.js +42 -6
- package/dist/web/internal/Themes.js.map +1 -1
- package/dist/webpack/index.d.ts +3 -0
- package/dist/webpack/index.d.ts.map +1 -0
- package/dist/webpack/index.js +5 -0
- package/dist/webpack/index.js.map +1 -0
- package/package.json +23 -2
- package/src/Config.ts +43 -684
- package/src/Style.ts +167 -40
- package/src/Vars.ts +299 -0
- package/src/compiler/Graph.ts +14 -9
- package/src/compiler/Native.ts +29 -32
- package/src/compiler/Source.ts +85 -18
- package/src/compiler/Transform.ts +78 -22
- package/src/compiler/internal/Compositions.ts +36 -3
- package/src/compiler/internal/Configurations.ts +83 -11
- package/src/compiler/internal/Contract.ts +223 -17
- package/src/compiler/internal/Contributions.ts +1 -1
- package/src/compiler/internal/Dynamic.ts +1 -1
- package/src/compiler/internal/Expression.ts +26 -0
- package/src/compiler/internal/Identifiers.ts +2 -1
- package/src/compiler/internal/NativeBindings.ts +3 -3
- package/src/compiler/internal/PackedStyles.ts +22 -26
- package/src/compiler/internal/Recipes.ts +1 -1
- package/src/compiler/internal/Selectors.ts +1 -1
- package/src/compiler/internal/Themes.ts +266 -57
- package/src/compiler/internal/{Variables.ts → Vars.ts} +2 -2
- package/src/default.ts +868 -156
- package/src/esbuild/index.ts +5 -0
- package/src/index.ts +4 -4
- package/src/internal/Authoring.ts +5 -7
- package/src/internal/Binding.ts +1 -1
- package/src/internal/Completion.ts +42 -0
- package/src/internal/Condition.ts +31 -1
- package/src/internal/Configuration.ts +970 -0
- package/src/internal/Shorthands.ts +2 -0
- package/src/{Theme.ts → internal/Theme.ts} +174 -48
- package/src/internal/Token.ts +258 -85
- package/src/internal/Typography.ts +106 -0
- package/src/internal/Value.ts +45 -26
- package/src/internal/VariableSets.ts +458 -0
- package/src/next/loader.ts +19 -5
- package/src/node/Host.ts +1 -2
- package/src/react-native/Host.ts +6 -6
- package/src/react-native/StyleSheet.ts +49 -42
- package/src/react-native/Variants.ts +3 -3
- package/src/react-native/react.ts +6 -6
- package/src/rollup/index.ts +5 -0
- package/src/runtime/Appearance.ts +20 -20
- package/src/runtime/Dynamic.ts +4 -1
- package/src/runtime/NativeContext.ts +8 -8
- package/src/runtime/NativeDynamic.ts +2 -4
- package/src/runtime/Props.ts +3 -3
- package/src/runtime/Selection.ts +44 -33
- package/src/styleFunction.ts +22 -19
- package/src/unplugin/index.ts +600 -0
- package/src/variants.ts +7 -5
- package/src/vite/index.ts +5 -4
- package/src/web/Css.ts +10 -7
- package/src/web/internal/Themes.ts +52 -9
- package/src/webpack/index.ts +5 -0
- package/dist/Theme.d.ts.map +0 -1
- package/dist/Theme.js.map +0 -1
- package/dist/compiler/internal/Variables.d.ts.map +0 -1
- package/dist/compiler/internal/Variables.js.map +0 -1
|
@@ -34,6 +34,7 @@ export function read(value: unknown): Map {
|
|
|
34
34
|
'style',
|
|
35
35
|
'theme',
|
|
36
36
|
'themes',
|
|
37
|
+
'typography',
|
|
37
38
|
'script',
|
|
38
39
|
'variants',
|
|
39
40
|
'__proto__',
|
|
@@ -98,6 +99,7 @@ export type Validated<mappings extends Map> = {
|
|
|
98
99
|
| 'style'
|
|
99
100
|
| 'theme'
|
|
100
101
|
| 'themes'
|
|
102
|
+
| 'typography'
|
|
101
103
|
| 'script'
|
|
102
104
|
| 'variants'
|
|
103
105
|
| '__proto__'
|
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
* Defines typed token contracts and compatible immutable theme overrides.
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
|
-
import { MissingTransformError, style } from '
|
|
6
|
-
import * as Authoring from './
|
|
7
|
-
import * as Identity from './
|
|
8
|
-
import { variants } from '
|
|
9
|
-
import type * as Binding from './
|
|
10
|
-
import type * as Literal from './
|
|
11
|
-
import * as Query from './
|
|
12
|
-
import * as Token from './
|
|
13
|
-
import
|
|
14
|
-
import type * as
|
|
5
|
+
import { MissingTransformError, style } from '../styleFunction.js'
|
|
6
|
+
import * as Authoring from './Authoring.js'
|
|
7
|
+
import * as Identity from './Identity.js'
|
|
8
|
+
import { variants } from '../variants.js'
|
|
9
|
+
import type * as Binding from './Binding.js'
|
|
10
|
+
import type * as Literal from './Literal.js'
|
|
11
|
+
import * as Query from './Query.js'
|
|
12
|
+
import * as Token from './Token.js'
|
|
13
|
+
import * as Typography from './Typography.js'
|
|
14
|
+
import type * as Value from './Value.js'
|
|
15
|
+
import type * as Style from '../Style.js'
|
|
16
|
+
import * as Condition from './Condition.js'
|
|
15
17
|
|
|
16
18
|
/** Complete color-scheme pair or a shared color. */
|
|
17
19
|
export type Color =
|
|
@@ -51,7 +53,7 @@ export type StyleFactory<tokens extends Tokens> = {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
|
-
* Defines scalar tokens without
|
|
56
|
+
* Defines scalar tokens and typography sets without defaults or environment access.
|
|
55
57
|
* Colors currently use the supported literal color grammar; spacing and radius
|
|
56
58
|
* values use nonnegative literal lengths or zero. Nested palettes are supported.
|
|
57
59
|
* @throws {InvalidError} If groups, paths, values, or data records are invalid.
|
|
@@ -95,7 +97,7 @@ export type Definition<
|
|
|
95
97
|
/** Token-aware single-element recipe authoring. */
|
|
96
98
|
readonly variants: boundVariants
|
|
97
99
|
/** Web variable references; source templates retain their identity and fallback. */
|
|
98
|
-
readonly vars: Token.
|
|
100
|
+
readonly vars: Token.Vars<References<tokens>>
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
/**
|
|
@@ -127,6 +129,8 @@ export function extend<
|
|
|
127
129
|
data.contract,
|
|
128
130
|
data.values,
|
|
129
131
|
data.queries,
|
|
132
|
+
undefined,
|
|
133
|
+
data.paths,
|
|
130
134
|
) as unknown as Definition<tokens, boundStyle, boundVariants>
|
|
131
135
|
}
|
|
132
136
|
|
|
@@ -166,7 +170,16 @@ type OverrideTree<tree, group> = tree extends string | number
|
|
|
166
170
|
? Scalar<group>
|
|
167
171
|
: tree extends { readonly dark: string; readonly light: string }
|
|
168
172
|
? Color
|
|
169
|
-
: {
|
|
173
|
+
: {
|
|
174
|
+
readonly [key in keyof tree]?: OverrideTree<
|
|
175
|
+
tree[key],
|
|
176
|
+
group extends 'typography'
|
|
177
|
+
? key extends Typography.Property
|
|
178
|
+
? key
|
|
179
|
+
: group
|
|
180
|
+
: group
|
|
181
|
+
>
|
|
182
|
+
}
|
|
170
183
|
|
|
171
184
|
/** Nested palette or scale data. */
|
|
172
185
|
export type Palette<leaf> = { readonly [key: string]: leaf | Palette<leaf> }
|
|
@@ -177,22 +190,38 @@ export type Reference<group extends Token.Group = Token.Group> =
|
|
|
177
190
|
|
|
178
191
|
/** The inferred tree replaces scalar values and scheme pairs with references. */
|
|
179
192
|
export type References<tokens> = {
|
|
180
|
-
readonly [group in keyof tokens as group extends Token.Group
|
|
193
|
+
readonly [group in keyof tokens as group extends Token.Group | 'typography'
|
|
181
194
|
? group
|
|
182
|
-
: never]: ReferenceTree<
|
|
195
|
+
: never]: ReferenceTree<
|
|
196
|
+
tokens[group],
|
|
197
|
+
Extract<group, Token.Group | 'typography'>
|
|
198
|
+
>
|
|
183
199
|
}
|
|
184
200
|
|
|
185
|
-
type ReferenceTree<
|
|
201
|
+
type ReferenceTree<
|
|
202
|
+
tree,
|
|
203
|
+
group extends Token.Group | 'typography',
|
|
204
|
+
> = tree extends
|
|
186
205
|
| string
|
|
187
206
|
| number
|
|
188
207
|
| { readonly dark: string; readonly light: string }
|
|
189
|
-
? Reference<group
|
|
190
|
-
: {
|
|
208
|
+
? Reference<Extract<group, Token.Group>>
|
|
209
|
+
: {
|
|
210
|
+
readonly [key in keyof tree]: ReferenceTree<
|
|
211
|
+
tree[key],
|
|
212
|
+
group extends 'typography'
|
|
213
|
+
? key extends Typography.Property
|
|
214
|
+
? key
|
|
215
|
+
: group
|
|
216
|
+
: group
|
|
217
|
+
>
|
|
218
|
+
}
|
|
191
219
|
|
|
192
220
|
/** Supported scalar groups; composite presets and query metadata follow separately. */
|
|
193
221
|
type Scalar<group> = group extends
|
|
194
222
|
| 'spacing'
|
|
195
223
|
| 'borderRadius'
|
|
224
|
+
| 'borderWidth'
|
|
196
225
|
| 'margin'
|
|
197
226
|
| 'padding'
|
|
198
227
|
? Literal.Length
|
|
@@ -217,6 +246,10 @@ export type Tokens = {
|
|
|
217
246
|
readonly borderColor?: Palette<Color> | undefined
|
|
218
247
|
/** Nonnegative corner radii. */
|
|
219
248
|
readonly borderRadius?: Palette<Literal.Length> | undefined
|
|
249
|
+
/** Nonnegative widths for physical and logical border declarations. */
|
|
250
|
+
readonly borderWidth?:
|
|
251
|
+
| Palette<Exclude<Literal.Length, `${number}%`>>
|
|
252
|
+
| undefined
|
|
220
253
|
/** Compile-time viewport width thresholds. */
|
|
221
254
|
readonly breakpoints?: Readonly<Record<string, Query.Length>> | undefined
|
|
222
255
|
/** Shared colors available to every supported color property. */
|
|
@@ -253,6 +286,8 @@ export type Tokens = {
|
|
|
253
286
|
readonly spacing?: Palette<Literal.Length> | undefined
|
|
254
287
|
/** Colors available to text declarations. */
|
|
255
288
|
readonly textColor?: Palette<Color> | undefined
|
|
289
|
+
/** Named sets of font family, size, weight, letter spacing, and line height. */
|
|
290
|
+
readonly typography?: Typography.Sets | undefined
|
|
256
291
|
}
|
|
257
292
|
|
|
258
293
|
function build(
|
|
@@ -261,6 +296,7 @@ function build(
|
|
|
261
296
|
base?: Readonly<Record<string, Token.Value>>,
|
|
262
297
|
baseQueries?: Query.Metadata,
|
|
263
298
|
scope?: string,
|
|
299
|
+
basePaths?: Readonly<Record<string, readonly string[]>>,
|
|
264
300
|
) {
|
|
265
301
|
const values: Record<string, Token.Value> = Object.assign(
|
|
266
302
|
Object.create(null),
|
|
@@ -279,12 +315,26 @@ function build(
|
|
|
279
315
|
) as Record<string, string>,
|
|
280
316
|
}
|
|
281
317
|
|
|
318
|
+
const paths: Record<string, readonly string[]> = { ...basePaths }
|
|
319
|
+
const conditions: (readonly string[])[] = []
|
|
320
|
+
|
|
282
321
|
let hasQueries = !!baseQueries
|
|
283
322
|
const active = new Set<object>()
|
|
284
323
|
|
|
285
|
-
function visit(
|
|
324
|
+
function visit(
|
|
325
|
+
value: unknown,
|
|
326
|
+
group: Token.Group | 'typography',
|
|
327
|
+
path: readonly string[],
|
|
328
|
+
) {
|
|
286
329
|
const key = path.join('.')
|
|
330
|
+
if (path.some((part) => part.startsWith('@')))
|
|
331
|
+
paths[key] = Object.freeze([...path])
|
|
287
332
|
const scalar = typeof value === 'string' || typeof value === 'number'
|
|
333
|
+
if (group === 'typography' && scalar)
|
|
334
|
+
throw new InvalidError(
|
|
335
|
+
path,
|
|
336
|
+
'Expected a typography set or a nested set group.',
|
|
337
|
+
)
|
|
288
338
|
const entries = scalar ? undefined : record(value, path)
|
|
289
339
|
const pair =
|
|
290
340
|
['color', 'backgroundColor', 'borderColor', 'textColor'].includes(
|
|
@@ -338,6 +388,24 @@ function build(
|
|
|
338
388
|
|
|
339
389
|
for (const [name, child] of entries!) {
|
|
340
390
|
const next = [...path, name]
|
|
391
|
+
if (group === 'typography' && name.startsWith('@')) {
|
|
392
|
+
if (!Typography.condition(name))
|
|
393
|
+
throw new InvalidError(
|
|
394
|
+
next,
|
|
395
|
+
'Typography conditions must be media or container queries.',
|
|
396
|
+
)
|
|
397
|
+
conditions.push(next)
|
|
398
|
+
}
|
|
399
|
+
if (
|
|
400
|
+
group === 'typography' &&
|
|
401
|
+
path.some((part) => part.startsWith('@')) &&
|
|
402
|
+
!Typography.condition(name) &&
|
|
403
|
+
!Typography.properties.includes(name as Typography.Property)
|
|
404
|
+
)
|
|
405
|
+
throw new InvalidError(
|
|
406
|
+
next,
|
|
407
|
+
'Typography query blocks accept only typography fields and queries.',
|
|
408
|
+
)
|
|
341
409
|
if (
|
|
342
410
|
base &&
|
|
343
411
|
!Object.keys(base).some(
|
|
@@ -347,7 +415,18 @@ function build(
|
|
|
347
415
|
)
|
|
348
416
|
throw new InvalidError(next, 'Extensions cannot add token paths.')
|
|
349
417
|
|
|
350
|
-
|
|
418
|
+
const property =
|
|
419
|
+
group === 'typography' &&
|
|
420
|
+
Typography.properties.includes(name as Typography.Property)
|
|
421
|
+
? (name as Typography.Property)
|
|
422
|
+
: undefined
|
|
423
|
+
if (property && typeof child !== 'string' && typeof child !== 'number')
|
|
424
|
+
throw new InvalidError(
|
|
425
|
+
next,
|
|
426
|
+
'Typography properties require scalar values.',
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
visit(child, property ?? group, next)
|
|
351
430
|
}
|
|
352
431
|
|
|
353
432
|
active.delete(value as object)
|
|
@@ -435,6 +514,7 @@ function build(
|
|
|
435
514
|
'backgroundColor',
|
|
436
515
|
'borderColor',
|
|
437
516
|
'borderRadius',
|
|
517
|
+
'borderWidth',
|
|
438
518
|
'color',
|
|
439
519
|
'margin',
|
|
440
520
|
'padding',
|
|
@@ -445,6 +525,7 @@ function build(
|
|
|
445
525
|
'letterSpacing',
|
|
446
526
|
'lineHeight',
|
|
447
527
|
'textColor',
|
|
528
|
+
'typography',
|
|
448
529
|
].includes(group)
|
|
449
530
|
)
|
|
450
531
|
throw new InvalidError([group], 'Unsupported token group.')
|
|
@@ -459,8 +540,26 @@ function build(
|
|
|
459
540
|
if (!entries.length && !base)
|
|
460
541
|
throw new InvalidError([group], 'Token palettes cannot be empty.')
|
|
461
542
|
|
|
462
|
-
for (const [name, value] of entries)
|
|
463
|
-
|
|
543
|
+
for (const [name, value] of entries) {
|
|
544
|
+
if (
|
|
545
|
+
group === 'typography' &&
|
|
546
|
+
(Typography.properties.includes(name as Typography.Property) ||
|
|
547
|
+
name.startsWith('@'))
|
|
548
|
+
)
|
|
549
|
+
throw new InvalidError(
|
|
550
|
+
[group, name],
|
|
551
|
+
'Typography properties require a named set.',
|
|
552
|
+
)
|
|
553
|
+
visit(value, group as Token.Group | 'typography', [group, name])
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
for (const path of conditions) {
|
|
558
|
+
try {
|
|
559
|
+
Condition.normalize(Query.resolve(path.at(-1)!, queries))
|
|
560
|
+
} catch (error) {
|
|
561
|
+
throw new InvalidError(path, (error as Error).message)
|
|
562
|
+
}
|
|
464
563
|
}
|
|
465
564
|
|
|
466
565
|
type Tree = { [key: string]: Tree | Token.Reference }
|
|
@@ -468,7 +567,7 @@ function build(
|
|
|
468
567
|
const tokens: Tree = Object.create(null)
|
|
469
568
|
|
|
470
569
|
for (const [path, value] of Object.entries(values)) {
|
|
471
|
-
const parts = path.split('.')
|
|
570
|
+
const parts = paths[path] ?? path.split('.')
|
|
472
571
|
let tree = tokens
|
|
473
572
|
|
|
474
573
|
for (const part of parts.slice(0, -1))
|
|
@@ -476,7 +575,9 @@ function build(
|
|
|
476
575
|
|
|
477
576
|
tree[parts.at(-1)!] = Token.create({
|
|
478
577
|
contract,
|
|
479
|
-
group: parts[0]
|
|
578
|
+
group: (parts[0] === 'typography'
|
|
579
|
+
? parts.at(-1)
|
|
580
|
+
: parts[0]) as Token.Group,
|
|
480
581
|
path,
|
|
481
582
|
value,
|
|
482
583
|
})
|
|
@@ -518,6 +619,7 @@ function build(
|
|
|
518
619
|
{
|
|
519
620
|
value: Object.freeze({
|
|
520
621
|
contract,
|
|
622
|
+
...(Object.keys(paths).length ? { paths: Object.freeze(paths) } : {}),
|
|
521
623
|
values: Object.freeze(values),
|
|
522
624
|
...(hasQueries
|
|
523
625
|
? {
|
|
@@ -568,7 +670,8 @@ function record(
|
|
|
568
670
|
if (
|
|
569
671
|
typeof key !== 'string' ||
|
|
570
672
|
!key ||
|
|
571
|
-
key.includes('.')
|
|
673
|
+
(key.includes('.') &&
|
|
674
|
+
!(path[0] === 'typography' && Typography.condition(key))) ||
|
|
572
675
|
!descriptor.enumerable ||
|
|
573
676
|
!('value' in descriptor)
|
|
574
677
|
)
|
|
@@ -634,7 +737,11 @@ type ValidPalette<palette, group> = palette extends undefined
|
|
|
634
737
|
: {
|
|
635
738
|
[key in keyof palette]: key extends `${string}!${string}`
|
|
636
739
|
? never
|
|
637
|
-
:
|
|
740
|
+
: group extends 'typography'
|
|
741
|
+
? key extends Typography.Property | `@${string}`
|
|
742
|
+
? never
|
|
743
|
+
: ValidTree<palette[key], group>
|
|
744
|
+
: ValidTree<palette[key], group>
|
|
638
745
|
}
|
|
639
746
|
|
|
640
747
|
type WeightDigits<
|
|
@@ -671,27 +778,29 @@ type Weight<value> = value extends number
|
|
|
671
778
|
: value
|
|
672
779
|
|
|
673
780
|
type ValidTree<tree, group> = tree extends string | number
|
|
674
|
-
?
|
|
675
|
-
?
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
?
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
781
|
+
? group extends 'typography'
|
|
782
|
+
? never
|
|
783
|
+
: tree extends Scalar<group>
|
|
784
|
+
? group extends 'breakpoints' | 'containers'
|
|
785
|
+
? tree extends `-${string}`
|
|
786
|
+
? never
|
|
787
|
+
: Literal.Checked<tree>
|
|
788
|
+
: group extends keyof Literal.Properties
|
|
789
|
+
? Literal.Checked<tree> &
|
|
790
|
+
Value.Checked<Record<group, tree>>[group] &
|
|
791
|
+
(group extends 'fontWeight' ? Weight<tree> : unknown) &
|
|
792
|
+
(tree extends string
|
|
793
|
+
? Lowercase<tree> extends
|
|
794
|
+
| 'inherit'
|
|
795
|
+
| 'initial'
|
|
796
|
+
| 'unset'
|
|
797
|
+
| 'revert'
|
|
798
|
+
| 'revert-layer'
|
|
799
|
+
? never
|
|
800
|
+
: unknown
|
|
801
|
+
: unknown)
|
|
802
|
+
: Literal.Checked<tree>
|
|
803
|
+
: never
|
|
695
804
|
: Extract<
|
|
696
805
|
keyof tree,
|
|
697
806
|
group extends 'color' | 'backgroundColor' | 'borderColor' | 'textColor'
|
|
@@ -701,7 +810,24 @@ type ValidTree<tree, group> = tree extends string | number
|
|
|
701
810
|
? {
|
|
702
811
|
[key in keyof tree]: key extends `${string}!${string}`
|
|
703
812
|
? never
|
|
704
|
-
:
|
|
813
|
+
: group extends 'typography'
|
|
814
|
+
? key extends `@${string}`
|
|
815
|
+
? key extends Typography.Condition
|
|
816
|
+
? ValidTree<tree[key], group> &
|
|
817
|
+
Record<
|
|
818
|
+
Exclude<
|
|
819
|
+
keyof tree[key],
|
|
820
|
+
Typography.Property | Typography.Condition
|
|
821
|
+
>,
|
|
822
|
+
never
|
|
823
|
+
>
|
|
824
|
+
: never
|
|
825
|
+
: key extends Typography.Property
|
|
826
|
+
? tree[key] extends string | number
|
|
827
|
+
? ValidTree<tree[key], key>
|
|
828
|
+
: never
|
|
829
|
+
: ValidTree<tree[key], group>
|
|
830
|
+
: ValidTree<tree[key], group>
|
|
705
831
|
}
|
|
706
832
|
: group extends 'color' | 'backgroundColor' | 'borderColor' | 'textColor'
|
|
707
833
|
? {
|