@react-native-rethemed/core 0.1.0 → 0.1.1
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 +2 -0
- package/dist/color-mode-store.cjs +57 -0
- package/dist/color-mode-store.d.cts +11 -0
- package/dist/color-mode-store.d.mts +11 -0
- package/dist/color-mode-store.mjs +56 -0
- package/dist/config.cjs +26 -0
- package/dist/config.d.cts +8 -0
- package/dist/config.d.mts +8 -0
- package/dist/config.mjs +7 -0
- package/dist/create-themed-styles.cjs +31 -0
- package/dist/{esm/create-themed-styles.d.ts → create-themed-styles.d.cts} +4 -2
- package/dist/{cjs/create-themed-styles.d.ts → create-themed-styles.d.mts} +4 -2
- package/dist/create-themed-styles.mjs +31 -0
- package/dist/create-themed.cjs +93 -0
- package/dist/create-themed.d.cts +48 -0
- package/dist/create-themed.d.mts +48 -0
- package/dist/create-themed.mjs +93 -0
- package/dist/define-theme.cjs +15 -0
- package/dist/{esm/define-theme.d.ts → define-theme.d.cts} +3 -1
- package/dist/{cjs/define-theme.d.ts → define-theme.d.mts} +3 -1
- package/dist/define-theme.mjs +15 -0
- package/dist/extend-theme.cjs +109 -0
- package/dist/{esm/extend-theme.d.ts → extend-theme.d.cts} +3 -1
- package/dist/{cjs/extend-theme.d.ts → extend-theme.d.mts} +3 -1
- package/dist/extend-theme.mjs +109 -0
- package/dist/index.cjs +30 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.mjs +9 -0
- package/dist/resolvers/color-resolver.cjs +23 -0
- package/dist/resolvers/color-resolver.d.cts +4 -0
- package/dist/resolvers/color-resolver.d.mts +4 -0
- package/dist/resolvers/color-resolver.mjs +23 -0
- package/dist/resolvers/line-height-resolver.cjs +17 -0
- package/dist/{esm/resolvers/line-height-resolver.d.ts → resolvers/line-height-resolver.d.cts} +3 -1
- package/dist/{cjs/resolvers/line-height-resolver.d.ts → resolvers/line-height-resolver.d.mts} +3 -1
- package/dist/resolvers/line-height-resolver.mjs +16 -0
- package/dist/resolvers/style-resolver.cjs +86 -0
- package/dist/resolvers/style-resolver.mjs +86 -0
- package/dist/semantic-colors.cjs +29 -0
- package/dist/{esm/semantic-colors.d.ts → semantic-colors.d.cts} +3 -1
- package/dist/{cjs/semantic-colors.d.ts → semantic-colors.d.mts} +3 -1
- package/dist/semantic-colors.mjs +28 -0
- package/dist/style-props.cjs +103 -0
- package/dist/{cjs/style-props.d.ts → style-props.d.cts} +2 -1
- package/dist/{esm/style-props.d.ts → style-props.d.mts} +2 -1
- package/dist/style-props.mjs +95 -0
- package/dist/text-tree.cjs +70 -0
- package/dist/{cjs/text-tree.d.ts → text-tree.d.cts} +4 -8
- package/dist/{esm/text-tree.d.ts → text-tree.d.mts} +4 -8
- package/dist/text-tree.mjs +66 -0
- package/dist/text-variants.cjs +25 -0
- package/dist/text-variants.mjs +25 -0
- package/dist/types.d.cts +280 -0
- package/dist/types.d.mts +280 -0
- package/package.json +16 -24
- package/dist/cjs/color-mode-store.d.ts +0 -32
- package/dist/cjs/color-mode-store.js +0 -64
- package/dist/cjs/config.d.ts +0 -14
- package/dist/cjs/config.js +0 -35
- package/dist/cjs/create-themed-styles.js +0 -37
- package/dist/cjs/create-themed.d.ts +0 -46
- package/dist/cjs/create-themed.js +0 -118
- package/dist/cjs/define-theme.js +0 -15
- package/dist/cjs/extend-theme.js +0 -118
- package/dist/cjs/index.d.ts +0 -4
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/resolvers/color-resolver.d.ts +0 -10
- package/dist/cjs/resolvers/color-resolver.js +0 -26
- package/dist/cjs/resolvers/line-height-resolver.js +0 -20
- package/dist/cjs/resolvers/style-resolver.d.ts +0 -21
- package/dist/cjs/resolvers/style-resolver.js +0 -104
- package/dist/cjs/semantic-colors.js +0 -32
- package/dist/cjs/style-props.js +0 -95
- package/dist/cjs/text-tree.js +0 -79
- package/dist/cjs/text-variants.d.ts +0 -22
- package/dist/cjs/text-variants.js +0 -29
- package/dist/cjs/types.d.ts +0 -281
- package/dist/cjs/types.js +0 -2
- package/dist/esm/color-mode-store.d.ts +0 -32
- package/dist/esm/color-mode-store.js +0 -59
- package/dist/esm/config.d.ts +0 -14
- package/dist/esm/config.js +0 -13
- package/dist/esm/create-themed-styles.js +0 -34
- package/dist/esm/create-themed.d.ts +0 -46
- package/dist/esm/create-themed.js +0 -115
- package/dist/esm/define-theme.js +0 -12
- package/dist/esm/extend-theme.js +0 -115
- package/dist/esm/index.d.ts +0 -4
- package/dist/esm/index.js +0 -3
- package/dist/esm/package.json +0 -1
- package/dist/esm/resolvers/color-resolver.d.ts +0 -10
- package/dist/esm/resolvers/color-resolver.js +0 -23
- package/dist/esm/resolvers/line-height-resolver.js +0 -16
- package/dist/esm/resolvers/style-resolver.d.ts +0 -21
- package/dist/esm/resolvers/style-resolver.js +0 -101
- package/dist/esm/semantic-colors.js +0 -28
- package/dist/esm/style-props.js +0 -92
- package/dist/esm/text-tree.js +0 -72
- package/dist/esm/text-variants.d.ts +0 -22
- package/dist/esm/text-variants.js +0 -26
- package/dist/esm/types.d.ts +0 -281
- package/dist/esm/types.js +0 -1
package/dist/esm/style-props.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The RN style property names each token category resolves, grouped by
|
|
3
|
-
* category. Kept as `const` arrays (not just types) because the resolvers
|
|
4
|
-
* need to iterate them at runtime.
|
|
5
|
-
*/
|
|
6
|
-
export const COLOR_KEYS = [
|
|
7
|
-
'color',
|
|
8
|
-
'backgroundColor',
|
|
9
|
-
'borderColor',
|
|
10
|
-
'borderTopColor',
|
|
11
|
-
'borderBottomColor',
|
|
12
|
-
'borderLeftColor',
|
|
13
|
-
'borderRightColor',
|
|
14
|
-
'borderStartColor',
|
|
15
|
-
'borderEndColor',
|
|
16
|
-
'borderBlockColor',
|
|
17
|
-
'borderBlockStartColor',
|
|
18
|
-
'borderBlockEndColor',
|
|
19
|
-
'tintColor',
|
|
20
|
-
'overlayColor',
|
|
21
|
-
'shadowColor',
|
|
22
|
-
'outlineColor',
|
|
23
|
-
'textShadowColor',
|
|
24
|
-
'textDecorationColor',
|
|
25
|
-
];
|
|
26
|
-
export const RADIUS_KEYS = [
|
|
27
|
-
'borderRadius',
|
|
28
|
-
'borderTopLeftRadius',
|
|
29
|
-
'borderTopRightRadius',
|
|
30
|
-
'borderTopStartRadius',
|
|
31
|
-
'borderTopEndRadius',
|
|
32
|
-
'borderBottomLeftRadius',
|
|
33
|
-
'borderBottomRightRadius',
|
|
34
|
-
'borderBottomStartRadius',
|
|
35
|
-
'borderBottomEndRadius',
|
|
36
|
-
'borderStartStartRadius',
|
|
37
|
-
'borderStartEndRadius',
|
|
38
|
-
'borderEndStartRadius',
|
|
39
|
-
'borderEndEndRadius',
|
|
40
|
-
];
|
|
41
|
-
export const SPACING_KEYS = [
|
|
42
|
-
'padding',
|
|
43
|
-
'paddingTop',
|
|
44
|
-
'paddingBottom',
|
|
45
|
-
'paddingLeft',
|
|
46
|
-
'paddingRight',
|
|
47
|
-
'paddingHorizontal',
|
|
48
|
-
'paddingVertical',
|
|
49
|
-
'paddingStart',
|
|
50
|
-
'paddingEnd',
|
|
51
|
-
'paddingBlock',
|
|
52
|
-
'paddingBlockStart',
|
|
53
|
-
'paddingBlockEnd',
|
|
54
|
-
'paddingInline',
|
|
55
|
-
'paddingInlineStart',
|
|
56
|
-
'paddingInlineEnd',
|
|
57
|
-
'margin',
|
|
58
|
-
'marginTop',
|
|
59
|
-
'marginBottom',
|
|
60
|
-
'marginLeft',
|
|
61
|
-
'marginRight',
|
|
62
|
-
'marginHorizontal',
|
|
63
|
-
'marginVertical',
|
|
64
|
-
'marginStart',
|
|
65
|
-
'marginEnd',
|
|
66
|
-
'marginBlock',
|
|
67
|
-
'marginBlockStart',
|
|
68
|
-
'marginBlockEnd',
|
|
69
|
-
'marginInline',
|
|
70
|
-
'marginInlineStart',
|
|
71
|
-
'marginInlineEnd',
|
|
72
|
-
'gap',
|
|
73
|
-
'rowGap',
|
|
74
|
-
'columnGap',
|
|
75
|
-
];
|
|
76
|
-
export const FONT_SIZE_KEYS = ['fontSize'];
|
|
77
|
-
export const FONT_WEIGHT_KEYS = ['fontWeight'];
|
|
78
|
-
export const LINE_HEIGHT_KEYS = ['lineHeight'];
|
|
79
|
-
export const LETTER_SPACING_KEYS = ['letterSpacing'];
|
|
80
|
-
/** Token or raw number, like the typography props. */
|
|
81
|
-
export const Z_INDEX_KEYS = ['zIndex'];
|
|
82
|
-
/**
|
|
83
|
-
* The real RN style properties the virtual `shadow` prop expands into.
|
|
84
|
-
* Not resolved as a scale category itself — see `resolvers/style-resolver.ts`.
|
|
85
|
-
*/
|
|
86
|
-
export const SHADOW_STYLE_PROPS = [
|
|
87
|
-
'shadowColor',
|
|
88
|
-
'shadowOffset',
|
|
89
|
-
'shadowOpacity',
|
|
90
|
-
'shadowRadius',
|
|
91
|
-
'elevation',
|
|
92
|
-
];
|
package/dist/esm/text-tree.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/** The fields a `semanticTokens.text` preset (leaf) may have. */
|
|
2
|
-
export const TEXT_TOKEN_FIELDS = [
|
|
3
|
-
'fontSize',
|
|
4
|
-
'lineHeight',
|
|
5
|
-
'letterSpacing',
|
|
6
|
-
'fontWeight',
|
|
7
|
-
'textTransform',
|
|
8
|
-
'color',
|
|
9
|
-
];
|
|
10
|
-
const isPrimitive = (value) => typeof value === 'string' || typeof value === 'number';
|
|
11
|
-
const isPresetField = (key) => TEXT_TOKEN_FIELDS.includes(key);
|
|
12
|
-
/**
|
|
13
|
-
* A node of `semanticTokens.text` is a **preset** (leaf) when it has any
|
|
14
|
-
* preset field (`fontSize`, …, `color`) or when every value is a primitive,
|
|
15
|
-
* and a **group** otherwise (`{ md: {...}, sm: {...} }`). The field check
|
|
16
|
-
* matters because `color` may itself be an object (`{ light, dark }`), so
|
|
17
|
-
* "all primitives" alone can't tell a preset from a group; preset field
|
|
18
|
-
* names are therefore reserved and can't name a group or preset. Mixed
|
|
19
|
-
* nodes are rejected by `@react-native-rethemed/cli codegen`.
|
|
20
|
-
*/
|
|
21
|
-
export function isTextPreset(node) {
|
|
22
|
-
const keys = Object.keys(node);
|
|
23
|
-
return keys.some(isPresetField) || Object.values(node).every(isPrimitive);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* A preset `color` for one scheme: a string applies to both, an object picks
|
|
27
|
-
* `light` / `dark`, and a missing scheme yields `undefined` (no color).
|
|
28
|
-
*/
|
|
29
|
-
export function resolveTextColor(color, scheme) {
|
|
30
|
-
return typeof color === 'object' && color !== null ? color[scheme] : color;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* The text tree with every preset `color` resolved for `scheme`; a preset
|
|
34
|
-
* whose color doesn't cover the scheme loses its `color` key. Presets
|
|
35
|
-
* without `color` are returned as-is (same object).
|
|
36
|
-
*/
|
|
37
|
-
export function resolveTextTree(tree, scheme) {
|
|
38
|
-
const result = {};
|
|
39
|
-
for (const [key, node] of Object.entries(tree ?? {})) {
|
|
40
|
-
if (typeof node !== 'object' || node === null)
|
|
41
|
-
continue;
|
|
42
|
-
if (!isTextPreset(node)) {
|
|
43
|
-
result[key] = resolveTextTree(node, scheme);
|
|
44
|
-
}
|
|
45
|
-
else if (node.color === undefined) {
|
|
46
|
-
result[key] = node;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
const { color, ...rest } = node;
|
|
50
|
-
const resolved = resolveTextColor(color, scheme);
|
|
51
|
-
result[key] =
|
|
52
|
-
resolved === undefined ? rest : { ...rest, color: resolved };
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Visits every preset in a text tree, depth-first in definition order,
|
|
59
|
-
* with its path (`['heading', 'display', 'lg']`).
|
|
60
|
-
*/
|
|
61
|
-
export function walkTextPresets(tree, visit, path = []) {
|
|
62
|
-
for (const [key, node] of Object.entries(tree ?? {})) {
|
|
63
|
-
if (typeof node !== 'object' || node === null)
|
|
64
|
-
continue;
|
|
65
|
-
if (isTextPreset(node)) {
|
|
66
|
-
visit([...path, key], node);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
walkTextPresets(node, visit, [...path, key]);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { TextStyle } from 'react-native';
|
|
2
|
-
import type { TextTokenTree } from './types.js';
|
|
3
|
-
type TextVariant = (override?: object) => TextStyle;
|
|
4
|
-
type TextVariantTree = {
|
|
5
|
-
[key: string]: TextVariant | TextVariantTree;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Builds `themed.text.<path>(override?)` by walking whatever tree
|
|
9
|
-
* `config.semanticTokens.text` defines, at any depth — no hand-written
|
|
10
|
-
* per-variant code. Each preset merges with the caller's override (preset
|
|
11
|
-
* first, override wins) and runs through the same `resolve` as
|
|
12
|
-
* `themed.text()` itself, so presets referencing scale keys (e.g.
|
|
13
|
-
* `fontSize: 'lg'`) resolve exactly like caller-passed tokens.
|
|
14
|
-
*
|
|
15
|
-
* `tree` must already have its preset colors resolved for the scheme (see
|
|
16
|
-
* `resolveTextTree`), so a call only merges and resolves tokens.
|
|
17
|
-
*
|
|
18
|
-
* Typed loosely on purpose; the exact tree shape comes from the generated
|
|
19
|
-
* `themed.gen.ts`.
|
|
20
|
-
*/
|
|
21
|
-
export declare function createTextVariants(tree: TextTokenTree, resolve: (input: object) => TextStyle): TextVariantTree;
|
|
22
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { isTextPreset } from './text-tree.js';
|
|
2
|
-
/**
|
|
3
|
-
* Builds `themed.text.<path>(override?)` by walking whatever tree
|
|
4
|
-
* `config.semanticTokens.text` defines, at any depth — no hand-written
|
|
5
|
-
* per-variant code. Each preset merges with the caller's override (preset
|
|
6
|
-
* first, override wins) and runs through the same `resolve` as
|
|
7
|
-
* `themed.text()` itself, so presets referencing scale keys (e.g.
|
|
8
|
-
* `fontSize: 'lg'`) resolve exactly like caller-passed tokens.
|
|
9
|
-
*
|
|
10
|
-
* `tree` must already have its preset colors resolved for the scheme (see
|
|
11
|
-
* `resolveTextTree`), so a call only merges and resolves tokens.
|
|
12
|
-
*
|
|
13
|
-
* Typed loosely on purpose; the exact tree shape comes from the generated
|
|
14
|
-
* `themed.gen.ts`.
|
|
15
|
-
*/
|
|
16
|
-
export function createTextVariants(tree, resolve) {
|
|
17
|
-
const build = (tree) => Object.fromEntries(Object.entries(tree)
|
|
18
|
-
.filter(([, node]) => typeof node === 'object' && node !== null)
|
|
19
|
-
.map(([key, node]) => [
|
|
20
|
-
key,
|
|
21
|
-
isTextPreset(node)
|
|
22
|
-
? (override) => resolve({ ...node, ...override })
|
|
23
|
-
: build(node),
|
|
24
|
-
]));
|
|
25
|
-
return build(tree);
|
|
26
|
-
}
|
package/dist/esm/types.d.ts
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import type { ImageStyle, TextStyle, ViewStyle } from 'react-native';
|
|
2
|
-
import type { ColorKeys, FontSizeKeys, FontWeightKeys, LetterSpacingKeys, LineHeightKeys, RadiusKeys, SpacingKeys, ZIndexKeys } from './style-props.js';
|
|
3
|
-
/** One shadow preset — expands into these real RN style props. */
|
|
4
|
-
export type ShadowToken = Pick<ViewStyle, 'shadowColor' | 'shadowOffset' | 'shadowOpacity' | 'shadowRadius' | 'elevation'>;
|
|
5
|
-
/**
|
|
6
|
-
* One `role`/`size` entry in `semanticTokens.text` (Material Design 3
|
|
7
|
-
* type-scale shape). Each field is either a key of the matching primitive
|
|
8
|
-
* scale in `tokens` (e.g. `fontSize: 'lg'`) or a raw value. References are
|
|
9
|
-
* validated by `@react-native-rethemed/cli codegen` against the final config,
|
|
10
|
-
* since a partial theme may reference keys supplied by another theme it is
|
|
11
|
-
* later merged with.
|
|
12
|
-
*
|
|
13
|
-
* `color` is optional: type-scale packages (Material Design) leave it out,
|
|
14
|
-
* while an app's own presets (`caption`, `link`, …) may set it.
|
|
15
|
-
*/
|
|
16
|
-
export type TextToken = {
|
|
17
|
-
/** A `tokens.fontSizes` key (`'lg'`) or a raw size (`18`). */
|
|
18
|
-
fontSize?: string | number;
|
|
19
|
-
/**
|
|
20
|
-
* A `tokens.lineHeights` key (`'short'` — a ratio of `fontSize`) or a raw,
|
|
21
|
-
* absolute line height (`24`).
|
|
22
|
-
*/
|
|
23
|
-
lineHeight?: string | number;
|
|
24
|
-
/** A `tokens.letterSpacings` key (`'wide'`) or a raw value (`0.15`). */
|
|
25
|
-
letterSpacing?: string | number;
|
|
26
|
-
/** A `tokens.fontWeights` key (`'semibold'`) or a raw RN weight (`'600'`). */
|
|
27
|
-
fontWeight?: string | TextStyle['fontWeight'];
|
|
28
|
-
/**
|
|
29
|
-
* Optional case transform, passed through as-is (no token scale), e.g.
|
|
30
|
-
* Material UI's `button` and `overline` styles.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* button: { fontSize: 14, fontWeight: '500', textTransform: 'uppercase' }
|
|
34
|
-
*/
|
|
35
|
-
textTransform?: TextStyle['textTransform'];
|
|
36
|
-
/**
|
|
37
|
-
* A raw color, the same in light and dark (`colors['gray.500']`), or
|
|
38
|
-
* one per scheme. A scheme left out gets no color from the preset, so the
|
|
39
|
-
* surrounding style (or React Native's default) applies there.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* color: { light: colors['gray.950'], dark: colors.white }
|
|
43
|
-
* color: { dark: colors.white } // light: no color from the preset
|
|
44
|
-
*/
|
|
45
|
-
color?: TextColor;
|
|
46
|
-
};
|
|
47
|
-
/** One semantic color: its value in each scheme. */
|
|
48
|
-
export type SchemeColor = {
|
|
49
|
-
light: string;
|
|
50
|
-
dark: string;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* `semanticTokens.colors`: groups of colors (`bg.default`) and top-level
|
|
54
|
-
* colors (`primary`), in any mix. See `isSchemeColor` for how they are told
|
|
55
|
-
* apart.
|
|
56
|
-
*/
|
|
57
|
-
export type SemanticColors = Record<string, SchemeColor | Record<string, SchemeColor>>;
|
|
58
|
-
/** `TextToken['color']`: one raw color, or one per scheme. */
|
|
59
|
-
export type TextColor = string | {
|
|
60
|
-
light?: string;
|
|
61
|
-
dark?: string;
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* `semanticTokens.text`: groups of any depth whose leaves are presets.
|
|
65
|
-
* See `isTextPreset` for how leaves and groups are told apart.
|
|
66
|
-
*/
|
|
67
|
-
export type TextTokenTree = {
|
|
68
|
-
[key: string]: TextToken | TextTokenTree;
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* The shape a theme package (or an app's local override) must satisfy.
|
|
72
|
-
* `tokens` holds primitive values (the smallest design-system units);
|
|
73
|
-
* `semanticTokens` holds role-named values built on top of them — the
|
|
74
|
-
* scheme-dependent `colors` and the `text` type scale — mirroring Chakra
|
|
75
|
-
* UI's `tokens` vs `semanticTokens` distinction.
|
|
76
|
-
*/
|
|
77
|
-
export type ThemeConfig = {
|
|
78
|
-
/**
|
|
79
|
-
* Primitive, scheme-independent values. Keys are the token names used in
|
|
80
|
-
* styles (`themed.view({ padding: 4 })`).
|
|
81
|
-
*/
|
|
82
|
-
tokens?: {
|
|
83
|
-
/**
|
|
84
|
-
* Fixed colors, the same in light and dark. Color style props accept
|
|
85
|
-
* them by name (`themed.view({ backgroundColor: 'red.500' })`) alongside
|
|
86
|
-
* `semanticTokens.colors`; when both define a name, the semantic color
|
|
87
|
-
* wins. Prefer semantic colors for anything that should follow the color
|
|
88
|
-
* scheme. Also readable via `useThemed().tokens.colors`.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* colors: { white: '#ffffff', 'gray.50': '#fafafa', 'gray.950': '#111111' }
|
|
92
|
-
*/
|
|
93
|
-
colors?: Record<string, string>;
|
|
94
|
-
/**
|
|
95
|
-
* For `borderRadius` and every corner-radius variant.
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* radii: { none: 0, sm: 4, md: 6, lg: 8, full: 9999 }
|
|
99
|
-
*/
|
|
100
|
-
radii?: Record<string, number>;
|
|
101
|
-
/**
|
|
102
|
-
* For `padding*`, `margin*`, `gap`, `rowGap` and `columnGap`. Numeric
|
|
103
|
-
* keys are used as numbers: `themed.view({ padding: 4 })`.
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* spacing: { px: 1, 0: 0, 0.5: 2, 1: 4, 2: 8, 4: 16 }
|
|
107
|
-
*/
|
|
108
|
-
spacing?: Record<string, number>;
|
|
109
|
-
/**
|
|
110
|
-
* For `fontSize`.
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* fontSizes: { sm: 14, md: 16, lg: 18, xl: 20 }
|
|
114
|
-
*/
|
|
115
|
-
fontSizes?: Record<string, number>;
|
|
116
|
-
/**
|
|
117
|
-
* For `fontWeight`.
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* fontWeights: { normal: '400', medium: '500', semibold: '600', bold: '700' }
|
|
121
|
-
*/
|
|
122
|
-
fontWeights?: Record<string, TextStyle['fontWeight']>;
|
|
123
|
-
/**
|
|
124
|
-
* For `lineHeight`, as **ratios of `fontSize`** (like CSS unitless
|
|
125
|
-
* line-height). A token resolves to `fontSize × ratio`, using the
|
|
126
|
-
* `fontSize` in the same style or else `defaults.fontSize`. A raw number
|
|
127
|
-
* passed to `lineHeight` stays an absolute value, as in React Native.
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* lineHeights: { shorter: 1.25, short: 1.375, moderate: 1.5, tall: 1.625 }
|
|
131
|
-
* // themed.text({ fontSize: 'lg', lineHeight: 'short' })
|
|
132
|
-
* // → { fontSize: 18, lineHeight: 24.75 }
|
|
133
|
-
*/
|
|
134
|
-
lineHeights?: Record<string, number>;
|
|
135
|
-
/**
|
|
136
|
-
* For `letterSpacing`, in points.
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* letterSpacings: { tight: -0.4, normal: 0, wide: 0.4 }
|
|
140
|
-
*/
|
|
141
|
-
letterSpacings?: Record<string, number>;
|
|
142
|
-
/**
|
|
143
|
-
* For `zIndex`, which also accepts a raw number.
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* zIndices: { base: 0, dropdown: 1000, modal: 1400, toast: 1700 }
|
|
147
|
-
* // themed.view({ zIndex: 'modal' }) → { zIndex: 1400 }
|
|
148
|
-
*/
|
|
149
|
-
zIndices?: Record<string, number>;
|
|
150
|
-
/**
|
|
151
|
-
* Presets for the virtual `shadow` prop, which expands to these RN props.
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* shadows: {
|
|
155
|
-
* sm: {
|
|
156
|
-
* shadowColor: '#000000',
|
|
157
|
-
* shadowOffset: { width: 0, height: 1 },
|
|
158
|
-
* shadowOpacity: 0.1,
|
|
159
|
-
* shadowRadius: 2,
|
|
160
|
-
* elevation: 2,
|
|
161
|
-
* },
|
|
162
|
-
* }
|
|
163
|
-
*/
|
|
164
|
-
shadows?: Record<string, ShadowToken>;
|
|
165
|
-
};
|
|
166
|
-
/** Role-named values built on top of `tokens`. */
|
|
167
|
-
semanticTokens?: {
|
|
168
|
-
/**
|
|
169
|
-
* group -> token -> scheme, used in styles as `'group.token'`
|
|
170
|
-
* (`themed.view({ backgroundColor: 'bg.subtle' })`), or token -> scheme
|
|
171
|
-
* at the top level, used by its bare name (`'primary-foreground'`, as in
|
|
172
|
-
* shadcn/ui). Switched with the current light/dark scheme. Takes
|
|
173
|
-
* precedence over a `tokens.colors` entry with the same name.
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* colors: {
|
|
177
|
-
* bg: {
|
|
178
|
-
* default: { light: '#ffffff', dark: '#111111' },
|
|
179
|
-
* subtle: { light: '#fafafa', dark: '#18181b' },
|
|
180
|
-
* },
|
|
181
|
-
* fg: {
|
|
182
|
-
* default: { light: '#111111', dark: '#fafafa' },
|
|
183
|
-
* },
|
|
184
|
-
* // top level: themed.view({ backgroundColor: 'primary' })
|
|
185
|
-
* primary: { light: '#171717', dark: '#e5e5e5' },
|
|
186
|
-
* }
|
|
187
|
-
*/
|
|
188
|
-
colors?: SemanticColors;
|
|
189
|
-
/**
|
|
190
|
-
* Typography presets, as a tree of any depth. A node whose values are
|
|
191
|
-
* all primitives is a **preset** (`TextToken`); a node of objects is a
|
|
192
|
-
* **group**. Each preset is called by its path:
|
|
193
|
-
* `themed.text.<path>(override?)`. Fields reference `tokens` keys or
|
|
194
|
-
* take raw values (see `TextToken`).
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* text: {
|
|
198
|
-
* // role -> size (Material Design 3 style)
|
|
199
|
-
* title: {
|
|
200
|
-
* md: { fontSize: 'md', lineHeight: 'moderate', fontWeight: 'semibold' },
|
|
201
|
-
* sm: { fontSize: 14, lineHeight: 20, fontWeight: '500' },
|
|
202
|
-
* },
|
|
203
|
-
* // flat: themed.text.caption()
|
|
204
|
-
* caption: { fontSize: 'xs', lineHeight: 'short' },
|
|
205
|
-
* // deeper: themed.text.heading.display.lg()
|
|
206
|
-
* heading: { display: { lg: { fontSize: '4xl', fontWeight: 'bold' } } },
|
|
207
|
-
* }
|
|
208
|
-
*/
|
|
209
|
-
text?: TextTokenTree;
|
|
210
|
-
};
|
|
211
|
-
/** Theme-wide defaults. */
|
|
212
|
-
defaults?: {
|
|
213
|
-
/**
|
|
214
|
-
* The base font size: a `tokens.fontSizes` key or a raw size. Used to
|
|
215
|
-
* resolve a `lineHeight` token when the style has no `fontSize` of its
|
|
216
|
-
* own. Falls back to 14 (React Native's default) when unset.
|
|
217
|
-
*
|
|
218
|
-
* @example
|
|
219
|
-
* defaults: { fontSize: 'md' }
|
|
220
|
-
* // with fontSizes.md = 16:
|
|
221
|
-
* // themed.text({ lineHeight: 'short' }) → { lineHeight: 22 } (16 × 1.375)
|
|
222
|
-
*/
|
|
223
|
-
fontSize?: string | number;
|
|
224
|
-
};
|
|
225
|
-
};
|
|
226
|
-
/**
|
|
227
|
-
* Exact token types for one theme. Written by
|
|
228
|
-
* `@react-native-rethemed/cli codegen` from the evaluated config, never by
|
|
229
|
-
* hand, so core never has to infer token names from literal types.
|
|
230
|
-
*/
|
|
231
|
-
export type ThemedSchema = {
|
|
232
|
-
/**
|
|
233
|
-
* Every token-aware style prop (plus the virtual `shadow`). Each primitive
|
|
234
|
-
* only picks the props its RN style type actually has — see `TokenizeStyle`.
|
|
235
|
-
*/
|
|
236
|
-
style: object;
|
|
237
|
-
/** `themed.text.<role>.<size>(override?)` */
|
|
238
|
-
textVariants: object;
|
|
239
|
-
/** `useThemed().tokens` */
|
|
240
|
-
tokens: object;
|
|
241
|
-
/** `useThemed().semanticTokens`, colors resolved for the current scheme. */
|
|
242
|
-
semanticTokens: object;
|
|
243
|
-
};
|
|
244
|
-
/**
|
|
245
|
-
* Swaps `Base`'s token-bearing props for the token-aware ones in `P`.
|
|
246
|
-
* `Omit` + `Pick` only — one level, no recursion. `Pick` is homomorphic, so
|
|
247
|
-
* the generated JSDoc (token tables) survives into editor hovers.
|
|
248
|
-
*
|
|
249
|
-
* Only props `Base` actually has are picked (e.g. no `color` on `View`); the
|
|
250
|
-
* virtual `shadow` prop is kept when `Base` has real shadow props.
|
|
251
|
-
*/
|
|
252
|
-
export type TokenizeStyle<Base, P> = Omit<Base, keyof P> & Pick<P, Extract<keyof P, keyof Base | ('shadowColor' extends keyof Base ? 'shadow' : never)>>;
|
|
253
|
-
export type ThemedStyles<S extends ThemedSchema> = {
|
|
254
|
-
/** Resolves token values in a `View` style. */
|
|
255
|
-
view: (style: TokenizeStyle<ViewStyle, S['style']>) => ViewStyle;
|
|
256
|
-
/** Resolves token values in an `Image` style. */
|
|
257
|
-
image: (style: TokenizeStyle<ImageStyle, S['style']>) => ImageStyle;
|
|
258
|
-
/**
|
|
259
|
-
* Resolves token values in a `Text` style. Typography presets are
|
|
260
|
-
* available as `themed.text.<role>.<size>(override?)`.
|
|
261
|
-
*/
|
|
262
|
-
text: ((style?: TokenizeStyle<TextStyle, S['style']>) => TextStyle) & S['textVariants'];
|
|
263
|
-
};
|
|
264
|
-
type LooseTokenKeys = ColorKeys | RadiusKeys | SpacingKeys | FontSizeKeys | FontWeightKeys | LineHeightKeys | LetterSpacingKeys | ZIndexKeys | 'shadow';
|
|
265
|
-
type LooseStyle = {
|
|
266
|
-
[K in LooseTokenKeys]?: string | number;
|
|
267
|
-
};
|
|
268
|
-
/** Any path under `themed.text`, callable at the leaves. */
|
|
269
|
-
type LooseTextVariants = {
|
|
270
|
-
[key: string]: ((override?: TokenizeStyle<TextStyle, LooseStyle>) => TextStyle) & LooseTextVariants;
|
|
271
|
-
};
|
|
272
|
-
export type LooseSchema = {
|
|
273
|
-
style: LooseStyle;
|
|
274
|
-
textVariants: LooseTextVariants;
|
|
275
|
-
tokens: NonNullable<ThemeConfig['tokens']>;
|
|
276
|
-
semanticTokens: {
|
|
277
|
-
colors: Record<string, string | Record<string, string>>;
|
|
278
|
-
text: NonNullable<NonNullable<ThemeConfig['semanticTokens']>['text']>;
|
|
279
|
-
};
|
|
280
|
-
};
|
|
281
|
-
export {};
|
package/dist/esm/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|