@tamagui/web 1.33.4 → 1.34.0
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/cjs/createTamagui.js +19 -4
- package/dist/cjs/createTamagui.js.map +1 -1
- package/dist/cjs/createVariable.js +1 -1
- package/dist/cjs/createVariable.js.map +1 -1
- package/dist/cjs/helpers/createPropMapper.js +51 -37
- package/dist/cjs/helpers/createPropMapper.js.map +2 -2
- package/dist/cjs/helpers/registerCSSVariable.js +1 -1
- package/dist/cjs/helpers/registerCSSVariable.js.map +1 -1
- package/dist/esm/createTamagui.js +20 -8
- package/dist/esm/createTamagui.js.map +1 -1
- package/dist/esm/createVariable.js +1 -1
- package/dist/esm/createVariable.js.map +1 -1
- package/dist/esm/helpers/createPropMapper.js +51 -37
- package/dist/esm/helpers/createPropMapper.js.map +2 -2
- package/dist/esm/helpers/registerCSSVariable.js +2 -2
- package/dist/esm/helpers/registerCSSVariable.js.map +1 -1
- package/package.json +9 -9
- package/src/createTamagui.ts +24 -8
- package/src/createTokens.ts +29 -24
- package/src/createVariable.ts +1 -1
- package/src/helpers/createPropMapper.ts +55 -53
- package/src/helpers/registerCSSVariable.ts +4 -3
- package/src/types.tsx +42 -19
- package/types/createTamagui.d.ts.map +1 -1
- package/types/createTokens.d.ts +17 -22
- package/types/createTokens.d.ts.map +1 -1
- package/types/helpers/createPropMapper.d.ts.map +1 -1
- package/types/helpers/registerCSSVariable.d.ts +2 -1
- package/types/helpers/registerCSSVariable.d.ts.map +1 -1
- package/types/types.d.ts +17 -21
- package/types/types.d.ts.map +1 -1
package/src/createTamagui.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isRSC, isWeb } from '@tamagui/constants'
|
|
2
2
|
|
|
3
3
|
import { configListeners, setConfig } from './config'
|
|
4
|
+
import { Variable, getVariableValue } from './createVariable'
|
|
4
5
|
import { createVariables } from './createVariables'
|
|
5
6
|
import { getThemeCSSRules } from './helpers/getThemeCSSRules'
|
|
6
7
|
import {
|
|
@@ -8,11 +9,7 @@ import {
|
|
|
8
9
|
listenForSheetChanges,
|
|
9
10
|
scanAllSheets,
|
|
10
11
|
} from './helpers/insertStyleRule'
|
|
11
|
-
import {
|
|
12
|
-
registerCSSVariable,
|
|
13
|
-
tokensValueToVariable,
|
|
14
|
-
variableToCSS,
|
|
15
|
-
} from './helpers/registerCSSVariable'
|
|
12
|
+
import { registerCSSVariable, variableToCSS } from './helpers/registerCSSVariable'
|
|
16
13
|
import { ensureThemeVariable, proxyThemeToParents } from './helpers/themes'
|
|
17
14
|
import { configureMedia } from './hooks/useMedia'
|
|
18
15
|
import { parseFont, registerFontVariables } from './insertFont'
|
|
@@ -71,6 +68,8 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
71
68
|
return res!
|
|
72
69
|
})()
|
|
73
70
|
|
|
71
|
+
const specificTokens = {}
|
|
72
|
+
|
|
74
73
|
const themeConfig = (() => {
|
|
75
74
|
const themes = { ...configIn.themes }
|
|
76
75
|
const cssRuleSets: string[] = []
|
|
@@ -84,9 +83,25 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
84
83
|
|
|
85
84
|
for (const key in configIn.tokens) {
|
|
86
85
|
for (const skey in configIn.tokens[key]) {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
const variable = configIn.tokens[key][skey] as Variable
|
|
87
|
+
|
|
88
|
+
// set specific tokens (like $size.sm)
|
|
89
|
+
specificTokens[`$${key}.${skey}`] = variable
|
|
90
|
+
|
|
91
|
+
if (process.env.NODE_ENV === 'development') {
|
|
92
|
+
if (typeof variable === 'undefined') {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`No value for tokens.${key}.${skey}:\n${JSON.stringify(
|
|
95
|
+
variable,
|
|
96
|
+
null,
|
|
97
|
+
2
|
|
98
|
+
)}`
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
registerCSSVariable(variable)
|
|
104
|
+
declarations.push(variableToCSS(variable, key === 'zIndex'))
|
|
90
105
|
}
|
|
91
106
|
}
|
|
92
107
|
|
|
@@ -268,6 +283,7 @@ ${runtimeStyles}`
|
|
|
268
283
|
getCSS,
|
|
269
284
|
defaultFont,
|
|
270
285
|
fontSizeTokens: fontSizeTokens || new Set(),
|
|
286
|
+
specificTokens,
|
|
271
287
|
// const tokens = [...getToken(tokens.size[0])]
|
|
272
288
|
// .spacer-sm + ._dsp_contents._dsp-sm-hidden { margin-left: -var(--${}) }
|
|
273
289
|
}
|
package/src/createTokens.ts
CHANGED
|
@@ -7,33 +7,34 @@ export function createTokens<T extends CreateTokens>(tokens: T): MakeTokens<T> {
|
|
|
7
7
|
return createVariables(tokens) as any
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
type NormalizeTokens<A, Type = A[keyof A]> = {
|
|
11
|
+
// removes $ prefix allowing for defining either as $1: or 1:,
|
|
12
|
+
// which is important because Chrome re-orders numerical-seeming keys :/
|
|
13
|
+
[Key in keyof A extends `$${infer X}` ? X : keyof A]: Variable<Type>
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
// verbose but gives us nice types...
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
// removes $ prefix allowing for defining either as $1: or 1:,
|
|
18
|
+
// which is important because Chrome re-orders numerical-seeming keys :/
|
|
19
|
+
type MakeTokens<T extends CreateTokens> = T extends {
|
|
20
|
+
color?: infer E
|
|
21
|
+
space?: infer F
|
|
22
|
+
size?: infer G
|
|
23
|
+
radius?: infer H
|
|
24
|
+
zIndex?: infer J
|
|
17
25
|
}
|
|
18
26
|
? {
|
|
19
|
-
color:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
radius: {
|
|
31
|
-
[Key in keyof H extends `$${infer X}` ? X : keyof H]: Variable<number>
|
|
32
|
-
}
|
|
33
|
-
zIndex: {
|
|
34
|
-
[Key in keyof J extends `$${infer X}` ? X : keyof J]: Variable<number>
|
|
35
|
-
}
|
|
36
|
-
}
|
|
27
|
+
color: NormalizeTokens<E, string>
|
|
28
|
+
space: NormalizeTokens<F, number>
|
|
29
|
+
size: NormalizeTokens<G, number>
|
|
30
|
+
radius: NormalizeTokens<H, number>
|
|
31
|
+
zIndex: NormalizeTokens<J, number>
|
|
32
|
+
} & Omit<
|
|
33
|
+
{
|
|
34
|
+
[key in keyof T]: NormalizeTokens<T[key]>
|
|
35
|
+
},
|
|
36
|
+
'color' | 'space' | 'size' | 'radius' | 'zIndex'
|
|
37
|
+
>
|
|
37
38
|
: never
|
|
38
39
|
|
|
39
40
|
// // test
|
|
@@ -44,4 +45,8 @@ type MakeTokens<T> = T extends {
|
|
|
44
45
|
// radius: { 0: 1 },
|
|
45
46
|
// zIndex: { 0: 1 },
|
|
46
47
|
// color: { 0: 'hi' },
|
|
48
|
+
// arbitrary: { abc: '123' },
|
|
47
49
|
// })
|
|
50
|
+
|
|
51
|
+
// tokens.arbitrary.abc
|
|
52
|
+
// tokens.size['0']
|
package/src/createVariable.ts
CHANGED
|
@@ -85,7 +85,7 @@ export function getVariableVariable(v: Variable | any) {
|
|
|
85
85
|
export const createCSSVariable = (nameProp: string, includeVar = true) => {
|
|
86
86
|
if (process.env.NODE_ENV === 'development') {
|
|
87
87
|
if (!nameProp || typeof nameProp !== 'string') {
|
|
88
|
-
throw new Error(`createCSSVariable expected string: ${nameProp}`)
|
|
88
|
+
throw new Error(`createCSSVariable expected string, got: ${nameProp}`)
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
const name = simpleHash(nameProp, 60)
|
|
@@ -5,9 +5,7 @@ import { isDevTools } from '../constants/isDevTools'
|
|
|
5
5
|
import { Variable, getVariableValue, isVariable } from '../createVariable'
|
|
6
6
|
import type {
|
|
7
7
|
DebugProp,
|
|
8
|
-
GenericVariantDefinitions,
|
|
9
8
|
PropMapper,
|
|
10
|
-
SplitStyleState,
|
|
11
9
|
StaticConfigParsed,
|
|
12
10
|
StyleResolver,
|
|
13
11
|
TamaguiInternalConfig,
|
|
@@ -19,6 +17,7 @@ import { expandStyles } from './expandStyles'
|
|
|
19
17
|
import { getFontsForLanguage, getVariantExtras } from './getVariantExtras'
|
|
20
18
|
import { isObj } from './isObj'
|
|
21
19
|
import { mergeProps } from './mergeProps'
|
|
20
|
+
import { pseudoDescriptors } from './pseudoDescriptors'
|
|
22
21
|
|
|
23
22
|
export type ResolveVariableTypes =
|
|
24
23
|
| 'auto'
|
|
@@ -161,15 +160,15 @@ const resolveVariants: StyleResolver = (
|
|
|
161
160
|
if (!variantValue) {
|
|
162
161
|
// variant at key exists, but no matching variant
|
|
163
162
|
// disabling warnings, its fine to pass through, could re-enable later somehoiw
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
163
|
+
if (process.env.TAMAGUI_WARN_ON_MISSING_VARIANT === '1') {
|
|
164
|
+
// don't warn on missing booleans
|
|
165
|
+
if (typeof value !== 'boolean') {
|
|
166
|
+
const name = staticConfig.componentName || '[UnnamedComponent]'
|
|
167
|
+
console.warn(
|
|
168
|
+
`No variant found: ${name} has variant "${key}", but no matching value "${value}"`
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
173
172
|
return
|
|
174
173
|
}
|
|
175
174
|
|
|
@@ -321,18 +320,16 @@ const resolveTokensAndVariants: StyleResolver<Object> = (
|
|
|
321
320
|
debug
|
|
322
321
|
)
|
|
323
322
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
res[key] ??= {}
|
|
335
|
-
Object.assign(res[key], subs[key])
|
|
323
|
+
// apply, merging sub-styles
|
|
324
|
+
if (variantOut) {
|
|
325
|
+
for (const [key, val] of variantOut) {
|
|
326
|
+
if (val == null) continue
|
|
327
|
+
if (key in pseudoDescriptors) {
|
|
328
|
+
res[key] ??= {}
|
|
329
|
+
Object.assign(res[key], val)
|
|
330
|
+
} else {
|
|
331
|
+
res[key] = val
|
|
332
|
+
}
|
|
336
333
|
}
|
|
337
334
|
}
|
|
338
335
|
}
|
|
@@ -459,44 +456,49 @@ const getToken = (
|
|
|
459
456
|
valOrVar = theme[value]
|
|
460
457
|
hasSet = true
|
|
461
458
|
} else {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
hasSet = true
|
|
469
|
-
break
|
|
470
|
-
}
|
|
471
|
-
case 'fontSize':
|
|
472
|
-
case 'lineHeight':
|
|
473
|
-
case 'letterSpacing':
|
|
474
|
-
case 'fontWeight': {
|
|
475
|
-
if (fontFamily) {
|
|
459
|
+
if (value in conf.specificTokens) {
|
|
460
|
+
hasSet = true
|
|
461
|
+
valOrVar = conf.specificTokens[value]
|
|
462
|
+
} else {
|
|
463
|
+
switch (key) {
|
|
464
|
+
case 'fontFamily': {
|
|
476
465
|
const fontsParsed = languageContext
|
|
477
466
|
? getFontsForLanguage(conf.fontsParsed, languageContext)
|
|
478
467
|
: conf.fontsParsed
|
|
479
|
-
valOrVar =
|
|
480
|
-
fontsParsed[fontFamily]?.[fontShorthand[key] || key]?.[value] || value
|
|
468
|
+
valOrVar = fontsParsed[value]?.family || value
|
|
481
469
|
hasSet = true
|
|
470
|
+
break
|
|
471
|
+
}
|
|
472
|
+
case 'fontSize':
|
|
473
|
+
case 'lineHeight':
|
|
474
|
+
case 'letterSpacing':
|
|
475
|
+
case 'fontWeight': {
|
|
476
|
+
if (fontFamily) {
|
|
477
|
+
const fontsParsed = languageContext
|
|
478
|
+
? getFontsForLanguage(conf.fontsParsed, languageContext)
|
|
479
|
+
: conf.fontsParsed
|
|
480
|
+
valOrVar =
|
|
481
|
+
fontsParsed[fontFamily]?.[fontShorthand[key] || key]?.[value] || value
|
|
482
|
+
hasSet = true
|
|
483
|
+
}
|
|
484
|
+
break
|
|
482
485
|
}
|
|
483
|
-
break
|
|
484
486
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
487
|
+
for (const cat in tokenCategories) {
|
|
488
|
+
if (key in tokenCategories[cat]) {
|
|
489
|
+
const res = tokensParsed[cat][value]
|
|
490
|
+
if (res) {
|
|
491
|
+
valOrVar = res
|
|
492
|
+
hasSet = true
|
|
493
|
+
}
|
|
492
494
|
}
|
|
493
495
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
496
|
+
if (!hasSet) {
|
|
497
|
+
const spaceVar = tokensParsed.space[value]
|
|
498
|
+
if (spaceVar) {
|
|
499
|
+
valOrVar = spaceVar
|
|
500
|
+
hasSet = true
|
|
501
|
+
}
|
|
500
502
|
}
|
|
501
503
|
}
|
|
502
504
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Variable, createCSSVariable } from '../createVariable'
|
|
1
|
+
import { Variable, createCSSVariable, getVariableValue } from '../createVariable'
|
|
2
|
+
import { VariableVal } from '../types'
|
|
2
3
|
|
|
3
|
-
export const registerCSSVariable = (v: Variable) => {
|
|
4
|
-
tokensValueToVariable.set(v
|
|
4
|
+
export const registerCSSVariable = (v: Variable | VariableVal) => {
|
|
5
|
+
tokensValueToVariable.set(getVariableValue(v), v)
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
export const variableToCSS = (v: Variable, unitless = false) => {
|
package/src/types.tsx
CHANGED
|
@@ -185,7 +185,10 @@ export type VariableColorVal = string | Variable
|
|
|
185
185
|
|
|
186
186
|
type GenericKey = string
|
|
187
187
|
|
|
188
|
-
export
|
|
188
|
+
export type CreateTokens<Val extends VariableVal = VariableVal> = Record<
|
|
189
|
+
string,
|
|
190
|
+
{ [key: GenericKey]: Val }
|
|
191
|
+
> & {
|
|
189
192
|
color: { [key: GenericKey]: Val }
|
|
190
193
|
space: { [key: GenericKey]: Val }
|
|
191
194
|
size: { [key: GenericKey]: Val }
|
|
@@ -193,7 +196,12 @@ export interface CreateTokens<Val extends VariableVal = VariableVal> {
|
|
|
193
196
|
zIndex: { [key: GenericKey]: Val }
|
|
194
197
|
}
|
|
195
198
|
|
|
196
|
-
type Tokenify<A extends GenericTokens> =
|
|
199
|
+
type Tokenify<A extends GenericTokens> = Omit<
|
|
200
|
+
{
|
|
201
|
+
[Key in keyof A]: TokenifyRecord<A[Key]>
|
|
202
|
+
},
|
|
203
|
+
'color' | 'space' | 'size' | 'radius' | 'zIndex'
|
|
204
|
+
> & {
|
|
197
205
|
color: TokenifyRecord<A['color']>
|
|
198
206
|
space: TokenifyRecord<A['space']>
|
|
199
207
|
size: TokenifyRecord<A['size']>
|
|
@@ -393,11 +401,7 @@ export type ThemeParsed = {
|
|
|
393
401
|
export type Tokens = TamaguiConfig['tokens']
|
|
394
402
|
|
|
395
403
|
export type TokensParsed = {
|
|
396
|
-
|
|
397
|
-
color: TokenPrefixed<Tokens['color']>
|
|
398
|
-
radius: TokenPrefixed<Tokens['radius']>
|
|
399
|
-
zIndex: TokenPrefixed<Tokens['zIndex']>
|
|
400
|
-
space: TokenPrefixed<Tokens['space']>
|
|
404
|
+
[Key in keyof Tokens]: TokenPrefixed<Tokens[Key]>
|
|
401
405
|
}
|
|
402
406
|
|
|
403
407
|
type TokenPrefixed<A extends { [key: string]: any }> = {
|
|
@@ -410,13 +414,7 @@ type Ensure$Prefix<A extends string | number | symbol> = A extends string
|
|
|
410
414
|
: `$${A}`
|
|
411
415
|
: never
|
|
412
416
|
|
|
413
|
-
export type TokensMerged =
|
|
414
|
-
size: TokensParsed['size'] & Tokens['size']
|
|
415
|
-
color: TokensParsed['color'] & Tokens['color']
|
|
416
|
-
radius: TokensParsed['radius'] & Tokens['radius']
|
|
417
|
-
zIndex: TokensParsed['zIndex'] & Tokens['zIndex']
|
|
418
|
-
space: TokensParsed['space'] & Tokens['space']
|
|
419
|
-
}
|
|
417
|
+
export type TokensMerged = TokensParsed & Tokens
|
|
420
418
|
|
|
421
419
|
export type Shorthands = TamaguiConfig['shorthands']
|
|
422
420
|
export type Media = TamaguiConfig['media']
|
|
@@ -577,6 +575,7 @@ export type TamaguiInternalConfig<
|
|
|
577
575
|
reactNative?: any
|
|
578
576
|
defaultFont?: H
|
|
579
577
|
fontSizeTokens: Set<string>
|
|
578
|
+
specificTokens: Record<string, Variable>
|
|
580
579
|
}
|
|
581
580
|
|
|
582
581
|
export type GetAnimationKeys<A extends GenericTamaguiConfig> = keyof A['animations']
|
|
@@ -681,16 +680,37 @@ type GetTokenFontKeysFor<
|
|
|
681
680
|
|
|
682
681
|
type GetTokenString<A> = A extends string | number ? `$${A}` : `$${string}`
|
|
683
682
|
|
|
683
|
+
// export type SpecificTokens<K extends keyof Tokens = keyof Tokens> =
|
|
684
|
+
// `${K}.${keyof Tokens[K] extends string ? keyof Tokens[K] : never}`
|
|
685
|
+
|
|
686
|
+
export type SpecificTokens<
|
|
687
|
+
Record = Tokens,
|
|
688
|
+
RK extends keyof Record = keyof Record
|
|
689
|
+
> = RK extends string
|
|
690
|
+
? `$${RK}.${keyof Record[RK] extends string | number ? keyof Record[RK] : never}`
|
|
691
|
+
: never
|
|
692
|
+
|
|
684
693
|
// base tokens
|
|
685
|
-
export type SizeTokens = GetTokenString<keyof Tokens['size']> | number
|
|
686
|
-
export type SpaceTokens =
|
|
694
|
+
export type SizeTokens = SpecificTokens | GetTokenString<keyof Tokens['size']> | number
|
|
695
|
+
export type SpaceTokens =
|
|
696
|
+
| SpecificTokens
|
|
697
|
+
| GetTokenString<keyof Tokens['space']>
|
|
698
|
+
| number
|
|
699
|
+
| boolean
|
|
687
700
|
|
|
688
701
|
export type ColorTokens =
|
|
702
|
+
| SpecificTokens
|
|
689
703
|
| GetTokenString<keyof Tokens['color']>
|
|
690
704
|
| GetTokenString<keyof ThemeParsed>
|
|
691
705
|
| CSSColorNames
|
|
692
|
-
export type ZIndexTokens =
|
|
693
|
-
|
|
706
|
+
export type ZIndexTokens =
|
|
707
|
+
| SpecificTokens
|
|
708
|
+
| GetTokenString<keyof Tokens['zIndex']>
|
|
709
|
+
| number
|
|
710
|
+
export type RadiusTokens =
|
|
711
|
+
| SpecificTokens
|
|
712
|
+
| GetTokenString<keyof Tokens['radius']>
|
|
713
|
+
| number
|
|
694
714
|
|
|
695
715
|
// fonts
|
|
696
716
|
type DefaultFont = TamaguiConfig['defaultFont']
|
|
@@ -750,7 +770,10 @@ export type ThemeValueByCategory<K extends string | number | symbol> = K extends
|
|
|
750
770
|
? FontWeightTokens
|
|
751
771
|
: K extends 'letterSpacing'
|
|
752
772
|
? FontLetterSpacingTokens
|
|
753
|
-
:
|
|
773
|
+
: K extends keyof Tokens
|
|
774
|
+
? // fallback to user-defined tokens
|
|
775
|
+
GetTokenString<Tokens[K]>
|
|
776
|
+
: never
|
|
754
777
|
|
|
755
778
|
type FontKeys = 'fontFamily'
|
|
756
779
|
type FontSizeKeys = 'fontSize'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTamagui.d.ts","sourceRoot":"","sources":["../src/createTamagui.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createTamagui.d.ts","sourceRoot":"","sources":["../src/createTamagui.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,kBAAkB,EAElB,kBAAkB,EAGnB,MAAM,SAAS,CAAA;AAKhB,wBAAgB,aAAa,CAAC,IAAI,SAAS,kBAAkB,EAC3D,QAAQ,EAAE,IAAI,GACb,kBAAkB,CAAC,IAAI,CAAC,CA0R1B"}
|
package/types/createTokens.d.ts
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
import { Variable } from './createVariable';
|
|
2
2
|
import { CreateTokens } from './types';
|
|
3
3
|
export declare function createTokens<T extends CreateTokens>(tokens: T): MakeTokens<T>;
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
type NormalizeTokens<A, Type = A[keyof A]> = {
|
|
5
|
+
[Key in keyof A extends `$${infer X}` ? X : keyof A]: Variable<Type>;
|
|
6
|
+
};
|
|
7
|
+
type MakeTokens<T extends CreateTokens> = T extends {
|
|
8
|
+
color?: infer E;
|
|
9
|
+
space?: infer F;
|
|
10
|
+
size?: infer G;
|
|
11
|
+
radius?: infer H;
|
|
12
|
+
zIndex?: infer J;
|
|
10
13
|
} ? {
|
|
11
|
-
color:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
radius: {
|
|
21
|
-
[Key in keyof H extends `$${infer X}` ? X : keyof H]: Variable<number>;
|
|
22
|
-
};
|
|
23
|
-
zIndex: {
|
|
24
|
-
[Key in keyof J extends `$${infer X}` ? X : keyof J]: Variable<number>;
|
|
25
|
-
};
|
|
26
|
-
} : never;
|
|
14
|
+
color: NormalizeTokens<E, string>;
|
|
15
|
+
space: NormalizeTokens<F, number>;
|
|
16
|
+
size: NormalizeTokens<G, number>;
|
|
17
|
+
radius: NormalizeTokens<H, number>;
|
|
18
|
+
zIndex: NormalizeTokens<J, number>;
|
|
19
|
+
} & Omit<{
|
|
20
|
+
[key in keyof T]: NormalizeTokens<T[key]>;
|
|
21
|
+
}, 'color' | 'space' | 'size' | 'radius' | 'zIndex'> : never;
|
|
27
22
|
export {};
|
|
28
23
|
//# sourceMappingURL=createTokens.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTokens.d.ts","sourceRoot":"","sources":["../src/createTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAGtC,wBAAgB,YAAY,CAAC,CAAC,SAAS,YAAY,EAAE,MAAM,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAE7E;
|
|
1
|
+
{"version":3,"file":"createTokens.d.ts","sourceRoot":"","sources":["../src/createTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAGtC,wBAAgB,YAAY,CAAC,CAAC,SAAS,YAAY,EAAE,MAAM,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAE7E;AAED,KAAK,eAAe,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI;KAG1C,GAAG,IAAI,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC;CACrE,CAAA;AAKD,KAAK,UAAU,CAAC,CAAC,SAAS,YAAY,IAAI,CAAC,SAAS;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAC,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,CAAA;CACjB,GACG;IACE,KAAK,EAAE,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;IACjC,KAAK,EAAE,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;IACjC,IAAI,EAAE,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;IAChC,MAAM,EAAE,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;IAClC,MAAM,EAAE,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;CACnC,GAAG,IAAI,CACN;KACG,GAAG,IAAI,MAAM,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CAC1C,EACD,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CACjD,GACD,KAAK,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPropMapper.d.ts","sourceRoot":"","sources":["../../src/helpers/createPropMapper.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"createPropMapper.d.ts","sourceRoot":"","sources":["../../src/helpers/createPropMapper.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,UAAU,EACV,kBAAkB,EAElB,qBAAqB,EAEtB,MAAM,UAAU,CAAA;AASjB,MAAM,MAAM,oBAAoB,GAC5B,MAAM,GACN,OAAO,GACP,UAAU,GACV,MAAM,GACN,iBAAiB,CAAA;AAErB,eAAO,MAAM,gBAAgB,iBAAkB,kBAAkB,eAsGhE,CAAA;AA+GD,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,qBAAqB,sBA2BtF;AAMD,eAAO,MAAM,uBAAuB,cAAe,GAAG,QAErD,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Variable } from '../createVariable';
|
|
2
|
-
|
|
2
|
+
import { VariableVal } from '../types';
|
|
3
|
+
export declare const registerCSSVariable: (v: Variable | VariableVal) => void;
|
|
3
4
|
export declare const variableToCSS: (v: Variable, unitless?: boolean) => string;
|
|
4
5
|
export declare const tokensValueToVariable: Map<any, any>;
|
|
5
6
|
//# sourceMappingURL=registerCSSVariable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerCSSVariable.d.ts","sourceRoot":"","sources":["../../src/helpers/registerCSSVariable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"registerCSSVariable.d.ts","sourceRoot":"","sources":["../../src/helpers/registerCSSVariable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAuC,MAAM,mBAAmB,CAAA;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtC,eAAO,MAAM,mBAAmB,MAAO,QAAQ,GAAG,WAAW,SAE5D,CAAA;AAED,eAAO,MAAM,aAAa,MAAO,QAAQ,+BAIxC,CAAA;AAED,eAAO,MAAM,qBAAqB,eAAsB,CAAA"}
|
package/types/types.d.ts
CHANGED
|
@@ -72,7 +72,9 @@ export type ConfigListener = (conf: TamaguiInternalConfig) => void;
|
|
|
72
72
|
export type VariableVal = number | string | Variable;
|
|
73
73
|
export type VariableColorVal = string | Variable;
|
|
74
74
|
type GenericKey = string;
|
|
75
|
-
export
|
|
75
|
+
export type CreateTokens<Val extends VariableVal = VariableVal> = Record<string, {
|
|
76
|
+
[key: GenericKey]: Val;
|
|
77
|
+
}> & {
|
|
76
78
|
color: {
|
|
77
79
|
[key: GenericKey]: Val;
|
|
78
80
|
};
|
|
@@ -88,8 +90,10 @@ export interface CreateTokens<Val extends VariableVal = VariableVal> {
|
|
|
88
90
|
zIndex: {
|
|
89
91
|
[key: GenericKey]: Val;
|
|
90
92
|
};
|
|
91
|
-
}
|
|
92
|
-
type Tokenify<A extends GenericTokens> = {
|
|
93
|
+
};
|
|
94
|
+
type Tokenify<A extends GenericTokens> = Omit<{
|
|
95
|
+
[Key in keyof A]: TokenifyRecord<A[Key]>;
|
|
96
|
+
}, 'color' | 'space' | 'size' | 'radius' | 'zIndex'> & {
|
|
93
97
|
color: TokenifyRecord<A['color']>;
|
|
94
98
|
space: TokenifyRecord<A['space']>;
|
|
95
99
|
size: TokenifyRecord<A['size']>;
|
|
@@ -187,11 +191,7 @@ export type ThemeParsed = {
|
|
|
187
191
|
};
|
|
188
192
|
export type Tokens = TamaguiConfig['tokens'];
|
|
189
193
|
export type TokensParsed = {
|
|
190
|
-
|
|
191
|
-
color: TokenPrefixed<Tokens['color']>;
|
|
192
|
-
radius: TokenPrefixed<Tokens['radius']>;
|
|
193
|
-
zIndex: TokenPrefixed<Tokens['zIndex']>;
|
|
194
|
-
space: TokenPrefixed<Tokens['space']>;
|
|
194
|
+
[Key in keyof Tokens]: TokenPrefixed<Tokens[Key]>;
|
|
195
195
|
};
|
|
196
196
|
type TokenPrefixed<A extends {
|
|
197
197
|
[key: string]: any;
|
|
@@ -199,13 +199,7 @@ type TokenPrefixed<A extends {
|
|
|
199
199
|
[key in Ensure$Prefix<keyof A>]: A[keyof A];
|
|
200
200
|
};
|
|
201
201
|
type Ensure$Prefix<A extends string | number | symbol> = A extends string ? A extends `$${string}` ? A : `$${A}` : never;
|
|
202
|
-
export type TokensMerged =
|
|
203
|
-
size: TokensParsed['size'] & Tokens['size'];
|
|
204
|
-
color: TokensParsed['color'] & Tokens['color'];
|
|
205
|
-
radius: TokensParsed['radius'] & Tokens['radius'];
|
|
206
|
-
zIndex: TokensParsed['zIndex'] & Tokens['zIndex'];
|
|
207
|
-
space: TokensParsed['space'] & Tokens['space'];
|
|
208
|
-
};
|
|
202
|
+
export type TokensMerged = TokensParsed & Tokens;
|
|
209
203
|
export type Shorthands = TamaguiConfig['shorthands'];
|
|
210
204
|
export type Media = TamaguiConfig['media'];
|
|
211
205
|
export type Themes = TamaguiConfig['themes'];
|
|
@@ -307,6 +301,7 @@ export type TamaguiInternalConfig<A extends GenericTokens = GenericTokens, B ext
|
|
|
307
301
|
reactNative?: any;
|
|
308
302
|
defaultFont?: H;
|
|
309
303
|
fontSizeTokens: Set<string>;
|
|
304
|
+
specificTokens: Record<string, Variable>;
|
|
310
305
|
};
|
|
311
306
|
export type GetAnimationKeys<A extends GenericTamaguiConfig> = keyof A['animations'];
|
|
312
307
|
export type UnionableString = string & {};
|
|
@@ -393,11 +388,12 @@ export type AnimationProp = AnimationKeys | {
|
|
|
393
388
|
];
|
|
394
389
|
type GetTokenFontKeysFor<A extends 'size' | 'weight' | 'letterSpacing' | 'family' | 'lineHeight' | 'transform' | 'style' | 'color'> = keyof TamaguiConfig['fonts']['body'][A];
|
|
395
390
|
type GetTokenString<A> = A extends string | number ? `$${A}` : `$${string}`;
|
|
396
|
-
export type
|
|
397
|
-
export type
|
|
398
|
-
export type
|
|
399
|
-
export type
|
|
400
|
-
export type
|
|
391
|
+
export type SpecificTokens<Record = Tokens, RK extends keyof Record = keyof Record> = RK extends string ? `$${RK}.${keyof Record[RK] extends string | number ? keyof Record[RK] : never}` : never;
|
|
392
|
+
export type SizeTokens = SpecificTokens | GetTokenString<keyof Tokens['size']> | number;
|
|
393
|
+
export type SpaceTokens = SpecificTokens | GetTokenString<keyof Tokens['space']> | number | boolean;
|
|
394
|
+
export type ColorTokens = SpecificTokens | GetTokenString<keyof Tokens['color']> | GetTokenString<keyof ThemeParsed> | CSSColorNames;
|
|
395
|
+
export type ZIndexTokens = SpecificTokens | GetTokenString<keyof Tokens['zIndex']> | number;
|
|
396
|
+
export type RadiusTokens = SpecificTokens | GetTokenString<keyof Tokens['radius']> | number;
|
|
401
397
|
type DefaultFont = TamaguiConfig['defaultFont'];
|
|
402
398
|
export type Fonts = DefaultFont extends string ? TamaguiConfig['fonts'][DefaultFont] : never;
|
|
403
399
|
export type Font = ParseFont<Fonts>;
|
|
@@ -423,7 +419,7 @@ type ParseFont<A extends GenericFont> = {
|
|
|
423
419
|
face: TokenPrefixedIfExists<A['face']>;
|
|
424
420
|
};
|
|
425
421
|
type TokenPrefixedIfExists<A> = A extends Object ? TokenPrefixed<A> : {};
|
|
426
|
-
export type ThemeValueByCategory<K extends string | number | symbol> = K extends 'theme' ? ThemeTokens : K extends 'size' ? SizeTokens : K extends 'font' ? FontTokens : K extends 'fontSize' ? FontSizeTokens : K extends 'space' ? SpaceTokens : K extends 'color' ? ColorTokens : K extends 'zIndex' ? ZIndexTokens : K extends 'lineHeight' ? FontLineHeightTokens : K extends 'fontWeight' ? FontWeightTokens : K extends 'letterSpacing' ? FontLetterSpacingTokens :
|
|
422
|
+
export type ThemeValueByCategory<K extends string | number | symbol> = K extends 'theme' ? ThemeTokens : K extends 'size' ? SizeTokens : K extends 'font' ? FontTokens : K extends 'fontSize' ? FontSizeTokens : K extends 'space' ? SpaceTokens : K extends 'color' ? ColorTokens : K extends 'zIndex' ? ZIndexTokens : K extends 'lineHeight' ? FontLineHeightTokens : K extends 'fontWeight' ? FontWeightTokens : K extends 'letterSpacing' ? FontLetterSpacingTokens : K extends keyof Tokens ? GetTokenString<Tokens[K]> : never;
|
|
427
423
|
type FontKeys = 'fontFamily';
|
|
428
424
|
type FontSizeKeys = 'fontSize';
|
|
429
425
|
type FontWeightKeys = 'fontWeight';
|