@react-native-rethemed/core 0.1.0 → 0.1.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/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 +17 -25
- 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
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const require_semantic_colors = require("./semantic-colors.cjs");
|
|
2
|
+
const require_text_tree = require("./text-tree.cjs");
|
|
3
|
+
//#region src/extend-theme.ts
|
|
4
|
+
/**
|
|
5
|
+
* Flat `tokens` categories: a one-level merge (`{ ...a, ...b }`, `b` wins per
|
|
6
|
+
* key) is enough. `semanticTokens.colors` holds groups (merged one level
|
|
7
|
+
* deeper) and top-level colors (replaced whole); `semanticTokens.text` is a tree of any depth — see
|
|
8
|
+
* `mergeTextTree`.
|
|
9
|
+
*
|
|
10
|
+
* Merging is runtime-only: the result is typed as the plain `ThemeConfig`,
|
|
11
|
+
* and exact token names come from the generated `themed.gen.ts`.
|
|
12
|
+
*/
|
|
13
|
+
const FLAT_CATEGORY_KEYS = [
|
|
14
|
+
"colors",
|
|
15
|
+
"radii",
|
|
16
|
+
"spacing",
|
|
17
|
+
"fontSizes",
|
|
18
|
+
"fontWeights",
|
|
19
|
+
"lineHeights",
|
|
20
|
+
"letterSpacings",
|
|
21
|
+
"zIndices",
|
|
22
|
+
"shadows"
|
|
23
|
+
];
|
|
24
|
+
function mergeFlat(a, b) {
|
|
25
|
+
if (!a) return b;
|
|
26
|
+
if (!b) return a;
|
|
27
|
+
return {
|
|
28
|
+
...a,
|
|
29
|
+
...b
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `semanticTokens.colors`: groups are merged, colors replaced whole, so
|
|
34
|
+
* overriding `bg.default` keeps `bg.subtle` and every other group. A
|
|
35
|
+
* top-level color (`primary`) is replaced like a token; when a name is a
|
|
36
|
+
* color on one side and a group on the other, the later side replaces it.
|
|
37
|
+
*/
|
|
38
|
+
function mergeSemanticColors(a, b) {
|
|
39
|
+
if (!a) return b;
|
|
40
|
+
if (!b) return a;
|
|
41
|
+
const result = { ...a };
|
|
42
|
+
for (const [key, next] of Object.entries(b)) {
|
|
43
|
+
const prev = result[key];
|
|
44
|
+
result[key] = prev && !require_semantic_colors.isSchemeColor(prev) && !require_semantic_colors.isSchemeColor(next) ? {
|
|
45
|
+
...prev,
|
|
46
|
+
...next
|
|
47
|
+
} : next;
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* `semanticTokens.text`: groups merge recursively, presets (leaves) are
|
|
53
|
+
* replaced whole. So overriding `display.lg` keeps `display.md` and every
|
|
54
|
+
* other group, at any depth. When a key is a preset on one side and a group
|
|
55
|
+
* on the other, the later side replaces it.
|
|
56
|
+
*/
|
|
57
|
+
function mergeTextTree(a, b) {
|
|
58
|
+
if (!a) return b;
|
|
59
|
+
if (!b) return a;
|
|
60
|
+
const result = { ...a };
|
|
61
|
+
for (const [key, next] of Object.entries(b)) {
|
|
62
|
+
const prev = result[key];
|
|
63
|
+
result[key] = prev && !require_text_tree.isTextPreset(prev) && !require_text_tree.isTextPreset(next) ? mergeTextTree(prev, next) ?? next : next;
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
function mergeTokens(a, b) {
|
|
68
|
+
if (!a) return b;
|
|
69
|
+
if (!b) return a;
|
|
70
|
+
const merged = {};
|
|
71
|
+
for (const key of FLAT_CATEGORY_KEYS) {
|
|
72
|
+
const value = mergeFlat(a[key], b[key]);
|
|
73
|
+
if (value) merged[key] = value;
|
|
74
|
+
}
|
|
75
|
+
return merged;
|
|
76
|
+
}
|
|
77
|
+
function mergeSemanticTokens(a, b) {
|
|
78
|
+
const colors = mergeSemanticColors(a?.colors, b?.colors);
|
|
79
|
+
const text = mergeTextTree(a?.text, b?.text);
|
|
80
|
+
return {
|
|
81
|
+
...colors ? { colors } : {},
|
|
82
|
+
...text ? { text } : {}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function mergeThemeConfig(a, b) {
|
|
86
|
+
const defaults = mergeFlat(a.defaults, b.defaults);
|
|
87
|
+
return {
|
|
88
|
+
tokens: mergeTokens(a.tokens, b.tokens),
|
|
89
|
+
semanticTokens: mergeSemanticTokens(a.semanticTokens, b.semanticTokens),
|
|
90
|
+
...defaults ? { defaults } : {}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Merges N `ThemeConfig`s, folding left-to-right so later themes override
|
|
95
|
+
* earlier ones per key:
|
|
96
|
+
*
|
|
97
|
+
* ```ts
|
|
98
|
+
* const config = extendTheme(materialDesignTheme, chakraUiTheme, {
|
|
99
|
+
* semanticTokens: {
|
|
100
|
+
* text: { display: { lg: { fontSize: 60, lineHeight: 68 } } },
|
|
101
|
+
* },
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
function extendTheme(...themes) {
|
|
106
|
+
return themes.reduce(mergeThemeConfig);
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
exports.extendTheme = extendTheme;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ThemeConfig } from "./types.cjs";
|
|
2
|
+
//#region src/extend-theme.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Merges N `ThemeConfig`s, folding left-to-right so later themes override
|
|
4
5
|
* earlier ones per key:
|
|
@@ -12,3 +13,4 @@ import type { ThemeConfig } from './types.js';
|
|
|
12
13
|
* ```
|
|
13
14
|
*/
|
|
14
15
|
export declare function extendTheme(...themes: [ThemeConfig, ...ThemeConfig[]]): ThemeConfig;
|
|
16
|
+
//#endregion
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ThemeConfig } from "./types.mjs";
|
|
2
|
+
//#region src/extend-theme.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Merges N `ThemeConfig`s, folding left-to-right so later themes override
|
|
4
5
|
* earlier ones per key:
|
|
@@ -12,3 +13,4 @@ import type { ThemeConfig } from './types';
|
|
|
12
13
|
* ```
|
|
13
14
|
*/
|
|
14
15
|
export declare function extendTheme(...themes: [ThemeConfig, ...ThemeConfig[]]): ThemeConfig;
|
|
16
|
+
//#endregion
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { isSchemeColor } from "./semantic-colors.mjs";
|
|
2
|
+
import { isTextPreset } from "./text-tree.mjs";
|
|
3
|
+
//#region src/extend-theme.ts
|
|
4
|
+
/**
|
|
5
|
+
* Flat `tokens` categories: a one-level merge (`{ ...a, ...b }`, `b` wins per
|
|
6
|
+
* key) is enough. `semanticTokens.colors` holds groups (merged one level
|
|
7
|
+
* deeper) and top-level colors (replaced whole); `semanticTokens.text` is a tree of any depth — see
|
|
8
|
+
* `mergeTextTree`.
|
|
9
|
+
*
|
|
10
|
+
* Merging is runtime-only: the result is typed as the plain `ThemeConfig`,
|
|
11
|
+
* and exact token names come from the generated `themed.gen.ts`.
|
|
12
|
+
*/
|
|
13
|
+
const FLAT_CATEGORY_KEYS = [
|
|
14
|
+
"colors",
|
|
15
|
+
"radii",
|
|
16
|
+
"spacing",
|
|
17
|
+
"fontSizes",
|
|
18
|
+
"fontWeights",
|
|
19
|
+
"lineHeights",
|
|
20
|
+
"letterSpacings",
|
|
21
|
+
"zIndices",
|
|
22
|
+
"shadows"
|
|
23
|
+
];
|
|
24
|
+
function mergeFlat(a, b) {
|
|
25
|
+
if (!a) return b;
|
|
26
|
+
if (!b) return a;
|
|
27
|
+
return {
|
|
28
|
+
...a,
|
|
29
|
+
...b
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `semanticTokens.colors`: groups are merged, colors replaced whole, so
|
|
34
|
+
* overriding `bg.default` keeps `bg.subtle` and every other group. A
|
|
35
|
+
* top-level color (`primary`) is replaced like a token; when a name is a
|
|
36
|
+
* color on one side and a group on the other, the later side replaces it.
|
|
37
|
+
*/
|
|
38
|
+
function mergeSemanticColors(a, b) {
|
|
39
|
+
if (!a) return b;
|
|
40
|
+
if (!b) return a;
|
|
41
|
+
const result = { ...a };
|
|
42
|
+
for (const [key, next] of Object.entries(b)) {
|
|
43
|
+
const prev = result[key];
|
|
44
|
+
result[key] = prev && !isSchemeColor(prev) && !isSchemeColor(next) ? {
|
|
45
|
+
...prev,
|
|
46
|
+
...next
|
|
47
|
+
} : next;
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* `semanticTokens.text`: groups merge recursively, presets (leaves) are
|
|
53
|
+
* replaced whole. So overriding `display.lg` keeps `display.md` and every
|
|
54
|
+
* other group, at any depth. When a key is a preset on one side and a group
|
|
55
|
+
* on the other, the later side replaces it.
|
|
56
|
+
*/
|
|
57
|
+
function mergeTextTree(a, b) {
|
|
58
|
+
if (!a) return b;
|
|
59
|
+
if (!b) return a;
|
|
60
|
+
const result = { ...a };
|
|
61
|
+
for (const [key, next] of Object.entries(b)) {
|
|
62
|
+
const prev = result[key];
|
|
63
|
+
result[key] = prev && !isTextPreset(prev) && !isTextPreset(next) ? mergeTextTree(prev, next) ?? next : next;
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
function mergeTokens(a, b) {
|
|
68
|
+
if (!a) return b;
|
|
69
|
+
if (!b) return a;
|
|
70
|
+
const merged = {};
|
|
71
|
+
for (const key of FLAT_CATEGORY_KEYS) {
|
|
72
|
+
const value = mergeFlat(a[key], b[key]);
|
|
73
|
+
if (value) merged[key] = value;
|
|
74
|
+
}
|
|
75
|
+
return merged;
|
|
76
|
+
}
|
|
77
|
+
function mergeSemanticTokens(a, b) {
|
|
78
|
+
const colors = mergeSemanticColors(a?.colors, b?.colors);
|
|
79
|
+
const text = mergeTextTree(a?.text, b?.text);
|
|
80
|
+
return {
|
|
81
|
+
...colors ? { colors } : {},
|
|
82
|
+
...text ? { text } : {}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function mergeThemeConfig(a, b) {
|
|
86
|
+
const defaults = mergeFlat(a.defaults, b.defaults);
|
|
87
|
+
return {
|
|
88
|
+
tokens: mergeTokens(a.tokens, b.tokens),
|
|
89
|
+
semanticTokens: mergeSemanticTokens(a.semanticTokens, b.semanticTokens),
|
|
90
|
+
...defaults ? { defaults } : {}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Merges N `ThemeConfig`s, folding left-to-right so later themes override
|
|
95
|
+
* earlier ones per key:
|
|
96
|
+
*
|
|
97
|
+
* ```ts
|
|
98
|
+
* const config = extendTheme(materialDesignTheme, chakraUiTheme, {
|
|
99
|
+
* semanticTokens: {
|
|
100
|
+
* text: { display: { lg: { fontSize: 60, lineHeight: 68 } } },
|
|
101
|
+
* },
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
function extendTheme(...themes) {
|
|
106
|
+
return themes.reduce(mergeThemeConfig);
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
export { extendTheme };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_define_theme = require("./define-theme.cjs");
|
|
3
|
+
const require_semantic_colors = require("./semantic-colors.cjs");
|
|
4
|
+
const require_text_tree = require("./text-tree.cjs");
|
|
5
|
+
const require_extend_theme = require("./extend-theme.cjs");
|
|
6
|
+
const require_line_height_resolver = require("./resolvers/line-height-resolver.cjs");
|
|
7
|
+
const require_style_props = require("./style-props.cjs");
|
|
8
|
+
const require_create_themed_styles = require("./create-themed-styles.cjs");
|
|
9
|
+
const require_create_themed = require("./create-themed.cjs");
|
|
10
|
+
exports.COLOR_KEYS = require_style_props.COLOR_KEYS;
|
|
11
|
+
exports.FONT_SIZE_KEYS = require_style_props.FONT_SIZE_KEYS;
|
|
12
|
+
exports.FONT_WEIGHT_KEYS = require_style_props.FONT_WEIGHT_KEYS;
|
|
13
|
+
exports.LETTER_SPACING_KEYS = require_style_props.LETTER_SPACING_KEYS;
|
|
14
|
+
exports.LINE_HEIGHT_KEYS = require_style_props.LINE_HEIGHT_KEYS;
|
|
15
|
+
exports.RADIUS_KEYS = require_style_props.RADIUS_KEYS;
|
|
16
|
+
exports.RN_DEFAULT_FONT_SIZE = require_line_height_resolver.RN_DEFAULT_FONT_SIZE;
|
|
17
|
+
exports.SHADOW_STYLE_PROPS = require_style_props.SHADOW_STYLE_PROPS;
|
|
18
|
+
exports.SPACING_KEYS = require_style_props.SPACING_KEYS;
|
|
19
|
+
exports.TEXT_TOKEN_FIELDS = require_text_tree.TEXT_TOKEN_FIELDS;
|
|
20
|
+
exports.Z_INDEX_KEYS = require_style_props.Z_INDEX_KEYS;
|
|
21
|
+
exports.createThemed = require_create_themed.createThemed;
|
|
22
|
+
exports.createThemedStyles = require_create_themed_styles.createThemedStyles;
|
|
23
|
+
exports.defineTheme = require_define_theme.defineTheme;
|
|
24
|
+
exports.extendTheme = require_extend_theme.extendTheme;
|
|
25
|
+
exports.isSchemeColor = require_semantic_colors.isSchemeColor;
|
|
26
|
+
exports.isTextPreset = require_text_tree.isTextPreset;
|
|
27
|
+
exports.resolveBaseFontSize = require_line_height_resolver.resolveBaseFontSize;
|
|
28
|
+
exports.resolveTextColor = require_text_tree.resolveTextColor;
|
|
29
|
+
exports.walkSemanticColors = require_semantic_colors.walkSemanticColors;
|
|
30
|
+
exports.walkTextPresets = require_text_tree.walkTextPresets;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { COLOR_KEYS, FONT_SIZE_KEYS, FONT_WEIGHT_KEYS, LETTER_SPACING_KEYS, LINE_HEIGHT_KEYS, RADIUS_KEYS, SHADOW_STYLE_PROPS, SPACING_KEYS, Z_INDEX_KEYS } from "./style-props.cjs";
|
|
2
|
+
import { LooseSchema, SchemeColor, SemanticColors, ShadowToken, TextColor, TextToken, TextTokenTree, ThemeConfig, ThemedSchema, ThemedStyles, TokenizeStyle } from "./types.cjs";
|
|
3
|
+
import { defineTheme } from "./define-theme.cjs";
|
|
4
|
+
import { extendTheme } from "./extend-theme.cjs";
|
|
5
|
+
import { RN_DEFAULT_FONT_SIZE, resolveBaseFontSize } from "./resolvers/line-height-resolver.cjs";
|
|
6
|
+
import { isSchemeColor, walkSemanticColors } from "./semantic-colors.cjs";
|
|
7
|
+
import { ColorScheme } from "./resolvers/color-resolver.cjs";
|
|
8
|
+
import { TEXT_TOKEN_FIELDS, isTextPreset, resolveTextColor, walkTextPresets } from "./text-tree.cjs";
|
|
9
|
+
import "./config.cjs";
|
|
10
|
+
import { ColorMode, ColorModeStorage } from "./color-mode-store.cjs";
|
|
11
|
+
import { ThemedProviderProps, UseColorModeResult, UseThemedResult, createThemed } from "./create-themed.cjs";
|
|
12
|
+
import { createThemedStyles } from "./create-themed-styles.cjs";
|
|
13
|
+
export { COLOR_KEYS, type ColorMode, type ColorModeStorage, type ColorScheme, FONT_SIZE_KEYS, FONT_WEIGHT_KEYS, LETTER_SPACING_KEYS, LINE_HEIGHT_KEYS, type LooseSchema, RADIUS_KEYS, RN_DEFAULT_FONT_SIZE, SHADOW_STYLE_PROPS, SPACING_KEYS, type SchemeColor, type SemanticColors, type ShadowToken, TEXT_TOKEN_FIELDS, type TextColor, type TextToken, type TextTokenTree, type ThemeConfig, type ThemedProviderProps, type ThemedSchema, type ThemedStyles, type TokenizeStyle, type UseColorModeResult, type UseThemedResult, Z_INDEX_KEYS, createThemed, createThemedStyles, defineTheme, extendTheme, isSchemeColor, isTextPreset, resolveBaseFontSize, resolveTextColor, walkSemanticColors, walkTextPresets };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { COLOR_KEYS, FONT_SIZE_KEYS, FONT_WEIGHT_KEYS, LETTER_SPACING_KEYS, LINE_HEIGHT_KEYS, RADIUS_KEYS, SHADOW_STYLE_PROPS, SPACING_KEYS, Z_INDEX_KEYS } from "./style-props.mjs";
|
|
2
|
+
import { LooseSchema, SchemeColor, SemanticColors, ShadowToken, TextColor, TextToken, TextTokenTree, ThemeConfig, ThemedSchema, ThemedStyles, TokenizeStyle } from "./types.mjs";
|
|
3
|
+
import { defineTheme } from "./define-theme.mjs";
|
|
4
|
+
import { extendTheme } from "./extend-theme.mjs";
|
|
5
|
+
import { RN_DEFAULT_FONT_SIZE, resolveBaseFontSize } from "./resolvers/line-height-resolver.mjs";
|
|
6
|
+
import { isSchemeColor, walkSemanticColors } from "./semantic-colors.mjs";
|
|
7
|
+
import { ColorScheme } from "./resolvers/color-resolver.mjs";
|
|
8
|
+
import { TEXT_TOKEN_FIELDS, isTextPreset, resolveTextColor, walkTextPresets } from "./text-tree.mjs";
|
|
9
|
+
import "./config.mjs";
|
|
10
|
+
import { ColorMode, ColorModeStorage } from "./color-mode-store.mjs";
|
|
11
|
+
import { ThemedProviderProps, UseColorModeResult, UseThemedResult, createThemed } from "./create-themed.mjs";
|
|
12
|
+
import { createThemedStyles } from "./create-themed-styles.mjs";
|
|
13
|
+
export { COLOR_KEYS, type ColorMode, type ColorModeStorage, type ColorScheme, FONT_SIZE_KEYS, FONT_WEIGHT_KEYS, LETTER_SPACING_KEYS, LINE_HEIGHT_KEYS, type LooseSchema, RADIUS_KEYS, RN_DEFAULT_FONT_SIZE, SHADOW_STYLE_PROPS, SPACING_KEYS, type SchemeColor, type SemanticColors, type ShadowToken, TEXT_TOKEN_FIELDS, type TextColor, type TextToken, type TextTokenTree, type ThemeConfig, type ThemedProviderProps, type ThemedSchema, type ThemedStyles, type TokenizeStyle, type UseColorModeResult, type UseThemedResult, Z_INDEX_KEYS, createThemed, createThemedStyles, defineTheme, extendTheme, isSchemeColor, isTextPreset, resolveBaseFontSize, resolveTextColor, walkSemanticColors, walkTextPresets };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineTheme } from "./define-theme.mjs";
|
|
2
|
+
import { isSchemeColor, walkSemanticColors } from "./semantic-colors.mjs";
|
|
3
|
+
import { TEXT_TOKEN_FIELDS, isTextPreset, resolveTextColor, walkTextPresets } from "./text-tree.mjs";
|
|
4
|
+
import { extendTheme } from "./extend-theme.mjs";
|
|
5
|
+
import { RN_DEFAULT_FONT_SIZE, resolveBaseFontSize } from "./resolvers/line-height-resolver.mjs";
|
|
6
|
+
import { COLOR_KEYS, FONT_SIZE_KEYS, FONT_WEIGHT_KEYS, LETTER_SPACING_KEYS, LINE_HEIGHT_KEYS, RADIUS_KEYS, SHADOW_STYLE_PROPS, SPACING_KEYS, Z_INDEX_KEYS } from "./style-props.mjs";
|
|
7
|
+
import { createThemedStyles } from "./create-themed-styles.mjs";
|
|
8
|
+
import { createThemed } from "./create-themed.mjs";
|
|
9
|
+
export { COLOR_KEYS, FONT_SIZE_KEYS, FONT_WEIGHT_KEYS, LETTER_SPACING_KEYS, LINE_HEIGHT_KEYS, RADIUS_KEYS, RN_DEFAULT_FONT_SIZE, SHADOW_STYLE_PROPS, SPACING_KEYS, TEXT_TOKEN_FIELDS, Z_INDEX_KEYS, createThemed, createThemedStyles, defineTheme, extendTheme, isSchemeColor, isTextPreset, resolveBaseFontSize, resolveTextColor, walkSemanticColors, walkTextPresets };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const require_semantic_colors = require("../semantic-colors.cjs");
|
|
2
|
+
//#region src/resolvers/color-resolver.ts
|
|
3
|
+
/**
|
|
4
|
+
* `config.semanticTokens.colors` for one scheme, keeping its shape: groups
|
|
5
|
+
* become group -> token -> string (`{ fg: { default: '#000' } }`) and
|
|
6
|
+
* top-level colors a string (`{ primary: '#171717' }`). Semantic values are
|
|
7
|
+
* already concrete strings in the config, so this only picks
|
|
8
|
+
* `light`/`dark`.
|
|
9
|
+
*/
|
|
10
|
+
function resolveSemanticColors(config, scheme) {
|
|
11
|
+
const result = {};
|
|
12
|
+
require_semantic_colors.walkSemanticColors(config.semanticTokens?.colors, (token, color, group) => {
|
|
13
|
+
if (group === void 0) result[token] = color[scheme];
|
|
14
|
+
else {
|
|
15
|
+
if (result[group] === void 0) result[group] = {};
|
|
16
|
+
const tokens = result[group];
|
|
17
|
+
tokens[token.slice(group.length + 1)] = color[scheme];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.resolveSemanticColors = resolveSemanticColors;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { walkSemanticColors } from "../semantic-colors.mjs";
|
|
2
|
+
//#region src/resolvers/color-resolver.ts
|
|
3
|
+
/**
|
|
4
|
+
* `config.semanticTokens.colors` for one scheme, keeping its shape: groups
|
|
5
|
+
* become group -> token -> string (`{ fg: { default: '#000' } }`) and
|
|
6
|
+
* top-level colors a string (`{ primary: '#171717' }`). Semantic values are
|
|
7
|
+
* already concrete strings in the config, so this only picks
|
|
8
|
+
* `light`/`dark`.
|
|
9
|
+
*/
|
|
10
|
+
function resolveSemanticColors(config, scheme) {
|
|
11
|
+
const result = {};
|
|
12
|
+
walkSemanticColors(config.semanticTokens?.colors, (token, color, group) => {
|
|
13
|
+
if (group === void 0) result[token] = color[scheme];
|
|
14
|
+
else {
|
|
15
|
+
if (result[group] === void 0) result[group] = {};
|
|
16
|
+
const tokens = result[group];
|
|
17
|
+
tokens[token.slice(group.length + 1)] = color[scheme];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { resolveSemanticColors };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/resolvers/line-height-resolver.ts
|
|
2
|
+
/** React Native's own default `fontSize`. */
|
|
3
|
+
const RN_DEFAULT_FONT_SIZE = 14;
|
|
4
|
+
/**
|
|
5
|
+
* `defaults.fontSize` as a number: a `tokens.fontSizes` key is looked up,
|
|
6
|
+
* a raw number is used as-is, anything else falls back to RN's default.
|
|
7
|
+
*/
|
|
8
|
+
function resolveBaseFontSize(config) {
|
|
9
|
+
const base = config.defaults?.fontSize;
|
|
10
|
+
if (typeof base === "number") return base;
|
|
11
|
+
const scale = config.tokens?.fontSizes;
|
|
12
|
+
if (typeof base === "string" && scale && Object.hasOwn(scale, base)) return scale[base];
|
|
13
|
+
return 14;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.RN_DEFAULT_FONT_SIZE = RN_DEFAULT_FONT_SIZE;
|
|
17
|
+
exports.resolveBaseFontSize = resolveBaseFontSize;
|
package/dist/{esm/resolvers/line-height-resolver.d.ts → resolvers/line-height-resolver.d.cts}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ThemeConfig } from "../types.cjs";
|
|
2
|
+
//#region src/resolvers/line-height-resolver.d.ts
|
|
2
3
|
/** React Native's own default `fontSize`. */
|
|
3
4
|
export declare const RN_DEFAULT_FONT_SIZE = 14;
|
|
4
5
|
/**
|
|
@@ -6,3 +7,4 @@ export declare const RN_DEFAULT_FONT_SIZE = 14;
|
|
|
6
7
|
* a raw number is used as-is, anything else falls back to RN's default.
|
|
7
8
|
*/
|
|
8
9
|
export declare function resolveBaseFontSize(config: ThemeConfig): number;
|
|
10
|
+
//#endregion
|
package/dist/{cjs/resolvers/line-height-resolver.d.ts → resolvers/line-height-resolver.d.mts}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ThemeConfig } from "../types.mjs";
|
|
2
|
+
//#region src/resolvers/line-height-resolver.d.ts
|
|
2
3
|
/** React Native's own default `fontSize`. */
|
|
3
4
|
export declare const RN_DEFAULT_FONT_SIZE = 14;
|
|
4
5
|
/**
|
|
@@ -6,3 +7,4 @@ export declare const RN_DEFAULT_FONT_SIZE = 14;
|
|
|
6
7
|
* a raw number is used as-is, anything else falls back to RN's default.
|
|
7
8
|
*/
|
|
8
9
|
export declare function resolveBaseFontSize(config: ThemeConfig): number;
|
|
10
|
+
//#endregion
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/resolvers/line-height-resolver.ts
|
|
2
|
+
/** React Native's own default `fontSize`. */
|
|
3
|
+
const RN_DEFAULT_FONT_SIZE = 14;
|
|
4
|
+
/**
|
|
5
|
+
* `defaults.fontSize` as a number: a `tokens.fontSizes` key is looked up,
|
|
6
|
+
* a raw number is used as-is, anything else falls back to RN's default.
|
|
7
|
+
*/
|
|
8
|
+
function resolveBaseFontSize(config) {
|
|
9
|
+
const base = config.defaults?.fontSize;
|
|
10
|
+
if (typeof base === "number") return base;
|
|
11
|
+
const scale = config.tokens?.fontSizes;
|
|
12
|
+
if (typeof base === "string" && scale && Object.hasOwn(scale, base)) return scale[base];
|
|
13
|
+
return 14;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { RN_DEFAULT_FONT_SIZE, resolveBaseFontSize };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const require_semantic_colors = require("../semantic-colors.cjs");
|
|
2
|
+
const require_line_height_resolver = require("./line-height-resolver.cjs");
|
|
3
|
+
const require_style_props = require("../style-props.cjs");
|
|
4
|
+
//#region src/resolvers/style-resolver.ts
|
|
5
|
+
/** Avoids float noise like `17.600000000000001` without pixel-snapping. */
|
|
6
|
+
const round2 = (value) => Math.round(value * 100) / 100;
|
|
7
|
+
const hasToken = (table, value) => (typeof value === "string" || typeof value === "number") && Object.hasOwn(table, value);
|
|
8
|
+
/**
|
|
9
|
+
* Builds the resolver behind `themed.view()` / `text()` / `image()` for one
|
|
10
|
+
* color scheme.
|
|
11
|
+
*
|
|
12
|
+
* Everything that doesn't depend on the input is done once here: a single
|
|
13
|
+
* **prop → token table** lookup (`backgroundColor` → the primitive
|
|
14
|
+
* `tokens.colors` plus the flattened `'group.token'` semantic colors for this
|
|
15
|
+
* scheme, `padding` → `tokens.spacing`, …).
|
|
16
|
+
* Each call then makes **one pass over the input's own keys** (usually a
|
|
17
|
+
* handful), rather than scanning every token-aware prop name, and copies the
|
|
18
|
+
* input at most once — or not at all when nothing is a token.
|
|
19
|
+
*
|
|
20
|
+
* Two props need the rest of the style, so they are applied after the pass:
|
|
21
|
+
* - `lineHeight` tokens are ratios of the (resolved) `fontSize`, falling back
|
|
22
|
+
* to `defaults.fontSize`;
|
|
23
|
+
* - the virtual `shadow` prop expands last, so a preset wins over explicit
|
|
24
|
+
* `shadow*` props, and the `shadow` key itself is removed.
|
|
25
|
+
*/
|
|
26
|
+
function createStyleResolver(config, scheme) {
|
|
27
|
+
const tokens = config.tokens ?? {};
|
|
28
|
+
const byProp = Object.create(null);
|
|
29
|
+
const register = (props, table) => {
|
|
30
|
+
if (!table) return;
|
|
31
|
+
for (const prop of props) byProp[prop] = table;
|
|
32
|
+
};
|
|
33
|
+
const colors = { ...tokens.colors };
|
|
34
|
+
require_semantic_colors.walkSemanticColors(config.semanticTokens?.colors, (token, color) => {
|
|
35
|
+
colors[token] = color[scheme];
|
|
36
|
+
});
|
|
37
|
+
if (tokens.colors || config.semanticTokens?.colors) register(require_style_props.COLOR_KEYS, colors);
|
|
38
|
+
register(require_style_props.RADIUS_KEYS, tokens.radii);
|
|
39
|
+
register(require_style_props.SPACING_KEYS, tokens.spacing);
|
|
40
|
+
register(require_style_props.FONT_SIZE_KEYS, tokens.fontSizes);
|
|
41
|
+
register(require_style_props.FONT_WEIGHT_KEYS, tokens.fontWeights);
|
|
42
|
+
register(require_style_props.LETTER_SPACING_KEYS, tokens.letterSpacings);
|
|
43
|
+
register(require_style_props.Z_INDEX_KEYS, tokens.zIndices);
|
|
44
|
+
const lineHeights = tokens.lineHeights;
|
|
45
|
+
const shadows = tokens.shadows;
|
|
46
|
+
const baseFontSize = require_line_height_resolver.resolveBaseFontSize(config);
|
|
47
|
+
return function resolveStyle(input) {
|
|
48
|
+
const source = input;
|
|
49
|
+
let result = null;
|
|
50
|
+
let lineHeightRatio;
|
|
51
|
+
let shadowPreset;
|
|
52
|
+
let hasShadow = false;
|
|
53
|
+
for (const key in source) {
|
|
54
|
+
const value = source[key];
|
|
55
|
+
if (key === "lineHeight") {
|
|
56
|
+
if (lineHeights && hasToken(lineHeights, value)) lineHeightRatio = lineHeights[value];
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (key === "shadow") {
|
|
60
|
+
if (shadows) {
|
|
61
|
+
hasShadow = true;
|
|
62
|
+
shadowPreset = hasToken(shadows, value) ? shadows[value] : void 0;
|
|
63
|
+
}
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const table = byProp[key];
|
|
67
|
+
if (table === void 0 || !hasToken(table, value)) continue;
|
|
68
|
+
result ?? (result = { ...source });
|
|
69
|
+
result[key] = table[value];
|
|
70
|
+
}
|
|
71
|
+
if (lineHeightRatio !== void 0) {
|
|
72
|
+
result ?? (result = { ...source });
|
|
73
|
+
const fontSize = typeof result.fontSize === "number" ? result.fontSize : baseFontSize;
|
|
74
|
+
result.lineHeight = round2(fontSize * lineHeightRatio);
|
|
75
|
+
}
|
|
76
|
+
if (hasShadow) {
|
|
77
|
+
const base = result ?? source;
|
|
78
|
+
const expanded = {};
|
|
79
|
+
for (const key in base) if (key !== "shadow") expanded[key] = base[key];
|
|
80
|
+
result = shadowPreset ? Object.assign(expanded, shadowPreset) : expanded;
|
|
81
|
+
}
|
|
82
|
+
return result ?? source;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
exports.createStyleResolver = createStyleResolver;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { walkSemanticColors } from "../semantic-colors.mjs";
|
|
2
|
+
import { resolveBaseFontSize } from "./line-height-resolver.mjs";
|
|
3
|
+
import { COLOR_KEYS, FONT_SIZE_KEYS, FONT_WEIGHT_KEYS, LETTER_SPACING_KEYS, RADIUS_KEYS, SPACING_KEYS, Z_INDEX_KEYS } from "../style-props.mjs";
|
|
4
|
+
//#region src/resolvers/style-resolver.ts
|
|
5
|
+
/** Avoids float noise like `17.600000000000001` without pixel-snapping. */
|
|
6
|
+
const round2 = (value) => Math.round(value * 100) / 100;
|
|
7
|
+
const hasToken = (table, value) => (typeof value === "string" || typeof value === "number") && Object.hasOwn(table, value);
|
|
8
|
+
/**
|
|
9
|
+
* Builds the resolver behind `themed.view()` / `text()` / `image()` for one
|
|
10
|
+
* color scheme.
|
|
11
|
+
*
|
|
12
|
+
* Everything that doesn't depend on the input is done once here: a single
|
|
13
|
+
* **prop → token table** lookup (`backgroundColor` → the primitive
|
|
14
|
+
* `tokens.colors` plus the flattened `'group.token'` semantic colors for this
|
|
15
|
+
* scheme, `padding` → `tokens.spacing`, …).
|
|
16
|
+
* Each call then makes **one pass over the input's own keys** (usually a
|
|
17
|
+
* handful), rather than scanning every token-aware prop name, and copies the
|
|
18
|
+
* input at most once — or not at all when nothing is a token.
|
|
19
|
+
*
|
|
20
|
+
* Two props need the rest of the style, so they are applied after the pass:
|
|
21
|
+
* - `lineHeight` tokens are ratios of the (resolved) `fontSize`, falling back
|
|
22
|
+
* to `defaults.fontSize`;
|
|
23
|
+
* - the virtual `shadow` prop expands last, so a preset wins over explicit
|
|
24
|
+
* `shadow*` props, and the `shadow` key itself is removed.
|
|
25
|
+
*/
|
|
26
|
+
function createStyleResolver(config, scheme) {
|
|
27
|
+
const tokens = config.tokens ?? {};
|
|
28
|
+
const byProp = Object.create(null);
|
|
29
|
+
const register = (props, table) => {
|
|
30
|
+
if (!table) return;
|
|
31
|
+
for (const prop of props) byProp[prop] = table;
|
|
32
|
+
};
|
|
33
|
+
const colors = { ...tokens.colors };
|
|
34
|
+
walkSemanticColors(config.semanticTokens?.colors, (token, color) => {
|
|
35
|
+
colors[token] = color[scheme];
|
|
36
|
+
});
|
|
37
|
+
if (tokens.colors || config.semanticTokens?.colors) register(COLOR_KEYS, colors);
|
|
38
|
+
register(RADIUS_KEYS, tokens.radii);
|
|
39
|
+
register(SPACING_KEYS, tokens.spacing);
|
|
40
|
+
register(FONT_SIZE_KEYS, tokens.fontSizes);
|
|
41
|
+
register(FONT_WEIGHT_KEYS, tokens.fontWeights);
|
|
42
|
+
register(LETTER_SPACING_KEYS, tokens.letterSpacings);
|
|
43
|
+
register(Z_INDEX_KEYS, tokens.zIndices);
|
|
44
|
+
const lineHeights = tokens.lineHeights;
|
|
45
|
+
const shadows = tokens.shadows;
|
|
46
|
+
const baseFontSize = resolveBaseFontSize(config);
|
|
47
|
+
return function resolveStyle(input) {
|
|
48
|
+
const source = input;
|
|
49
|
+
let result = null;
|
|
50
|
+
let lineHeightRatio;
|
|
51
|
+
let shadowPreset;
|
|
52
|
+
let hasShadow = false;
|
|
53
|
+
for (const key in source) {
|
|
54
|
+
const value = source[key];
|
|
55
|
+
if (key === "lineHeight") {
|
|
56
|
+
if (lineHeights && hasToken(lineHeights, value)) lineHeightRatio = lineHeights[value];
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (key === "shadow") {
|
|
60
|
+
if (shadows) {
|
|
61
|
+
hasShadow = true;
|
|
62
|
+
shadowPreset = hasToken(shadows, value) ? shadows[value] : void 0;
|
|
63
|
+
}
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const table = byProp[key];
|
|
67
|
+
if (table === void 0 || !hasToken(table, value)) continue;
|
|
68
|
+
result ?? (result = { ...source });
|
|
69
|
+
result[key] = table[value];
|
|
70
|
+
}
|
|
71
|
+
if (lineHeightRatio !== void 0) {
|
|
72
|
+
result ?? (result = { ...source });
|
|
73
|
+
const fontSize = typeof result.fontSize === "number" ? result.fontSize : baseFontSize;
|
|
74
|
+
result.lineHeight = round2(fontSize * lineHeightRatio);
|
|
75
|
+
}
|
|
76
|
+
if (hasShadow) {
|
|
77
|
+
const base = result ?? source;
|
|
78
|
+
const expanded = {};
|
|
79
|
+
for (const key in base) if (key !== "shadow") expanded[key] = base[key];
|
|
80
|
+
result = shadowPreset ? Object.assign(expanded, shadowPreset) : expanded;
|
|
81
|
+
}
|
|
82
|
+
return result ?? source;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
export { createStyleResolver };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/semantic-colors.ts
|
|
2
|
+
/**
|
|
3
|
+
* A color of `semanticTokens.colors` (as opposed to a group of them): an
|
|
4
|
+
* object whose `light` or `dark` is a string. A group's values are objects,
|
|
5
|
+
* so a group may still name a token `light` or `dark` (Material UI's
|
|
6
|
+
* `primary.light`).
|
|
7
|
+
*/
|
|
8
|
+
function isSchemeColor(node) {
|
|
9
|
+
if (typeof node !== "object" || node === null) return false;
|
|
10
|
+
const { light, dark } = node;
|
|
11
|
+
return typeof light === "string" || typeof dark === "string";
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Visits every semantic color in definition order with its token name:
|
|
15
|
+
* `'group.token'` inside a group, or the bare name for a top-level color
|
|
16
|
+
* (`'primary'`, `'primary-foreground'`).
|
|
17
|
+
*/
|
|
18
|
+
function walkSemanticColors(colors, visit) {
|
|
19
|
+
for (const [key, node] of Object.entries(colors ?? {})) {
|
|
20
|
+
if (isSchemeColor(node)) {
|
|
21
|
+
visit(key, node, void 0);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
for (const [name, color] of Object.entries(node)) visit(`${key}.${name}`, color, key);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.isSchemeColor = isSchemeColor;
|
|
29
|
+
exports.walkSemanticColors = walkSemanticColors;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SchemeColor, SemanticColors } from "./types.cjs";
|
|
2
|
+
//#region src/semantic-colors.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* A color of `semanticTokens.colors` (as opposed to a group of them): an
|
|
4
5
|
* object whose `light` or `dark` is a string. A group's values are objects,
|
|
@@ -12,3 +13,4 @@ export declare function isSchemeColor(node: unknown): node is SchemeColor;
|
|
|
12
13
|
* (`'primary'`, `'primary-foreground'`).
|
|
13
14
|
*/
|
|
14
15
|
export declare function walkSemanticColors(colors: SemanticColors | undefined, visit: (token: string, color: SchemeColor, group: string | undefined) => void): void;
|
|
16
|
+
//#endregion
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SchemeColor, SemanticColors } from "./types.mjs";
|
|
2
|
+
//#region src/semantic-colors.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* A color of `semanticTokens.colors` (as opposed to a group of them): an
|
|
4
5
|
* object whose `light` or `dark` is a string. A group's values are objects,
|
|
@@ -12,3 +13,4 @@ export declare function isSchemeColor(node: unknown): node is SchemeColor;
|
|
|
12
13
|
* (`'primary'`, `'primary-foreground'`).
|
|
13
14
|
*/
|
|
14
15
|
export declare function walkSemanticColors(colors: SemanticColors | undefined, visit: (token: string, color: SchemeColor, group: string | undefined) => void): void;
|
|
16
|
+
//#endregion
|