@rootnative/core 0.0.0-alpha.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/LICENSE +21 -0
- package/README.md +185 -0
- package/dist/chunk-DC35U5WG.mjs +328 -0
- package/dist/create-theme/index.d.mts +87 -0
- package/dist/create-theme/index.mjs +207 -0
- package/dist/index.d.mts +186 -0
- package/dist/index.mjs +273 -0
- package/dist/types-GiXhVyob.d.mts +209 -0
- package/llms.txt +234 -0
- package/package.json +83 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyRoundness,
|
|
3
|
+
defaultTopAppBarTokens,
|
|
4
|
+
defaultTypography,
|
|
5
|
+
lightTheme
|
|
6
|
+
} from "../chunk-DC35U5WG.mjs";
|
|
7
|
+
|
|
8
|
+
// src/theme/createMaterialTheme.ts
|
|
9
|
+
import {
|
|
10
|
+
argbFromHex,
|
|
11
|
+
hexFromArgb,
|
|
12
|
+
Hct,
|
|
13
|
+
SchemeContent,
|
|
14
|
+
SchemeExpressive,
|
|
15
|
+
SchemeFidelity,
|
|
16
|
+
SchemeFruitSalad,
|
|
17
|
+
SchemeMonochrome,
|
|
18
|
+
SchemeNeutral,
|
|
19
|
+
SchemeRainbow,
|
|
20
|
+
SchemeTonalSpot,
|
|
21
|
+
SchemeVibrant,
|
|
22
|
+
MaterialDynamicColors,
|
|
23
|
+
DynamicScheme,
|
|
24
|
+
TonalPalette,
|
|
25
|
+
Variant
|
|
26
|
+
} from "@material/material-color-utilities";
|
|
27
|
+
var CONTRAST_VALUES = {
|
|
28
|
+
standard: 0,
|
|
29
|
+
medium: 0.5,
|
|
30
|
+
high: 1
|
|
31
|
+
};
|
|
32
|
+
var VARIANT_ENUM = {
|
|
33
|
+
tonalSpot: Variant.TONAL_SPOT,
|
|
34
|
+
neutral: Variant.NEUTRAL,
|
|
35
|
+
vibrant: Variant.VIBRANT,
|
|
36
|
+
expressive: Variant.EXPRESSIVE,
|
|
37
|
+
fidelity: Variant.FIDELITY,
|
|
38
|
+
content: Variant.CONTENT,
|
|
39
|
+
monochrome: Variant.MONOCHROME,
|
|
40
|
+
rainbow: Variant.RAINBOW,
|
|
41
|
+
fruitSalad: Variant.FRUIT_SALAD
|
|
42
|
+
};
|
|
43
|
+
function buildBaseScheme(variant, sourceHct, isDark, contrast) {
|
|
44
|
+
switch (variant) {
|
|
45
|
+
case "tonalSpot":
|
|
46
|
+
return new SchemeTonalSpot(sourceHct, isDark, contrast);
|
|
47
|
+
case "neutral":
|
|
48
|
+
return new SchemeNeutral(sourceHct, isDark, contrast);
|
|
49
|
+
case "vibrant":
|
|
50
|
+
return new SchemeVibrant(sourceHct, isDark, contrast);
|
|
51
|
+
case "expressive":
|
|
52
|
+
return new SchemeExpressive(sourceHct, isDark, contrast);
|
|
53
|
+
case "fidelity":
|
|
54
|
+
return new SchemeFidelity(sourceHct, isDark, contrast);
|
|
55
|
+
case "content":
|
|
56
|
+
return new SchemeContent(sourceHct, isDark, contrast);
|
|
57
|
+
case "monochrome":
|
|
58
|
+
return new SchemeMonochrome(sourceHct, isDark, contrast);
|
|
59
|
+
case "rainbow":
|
|
60
|
+
return new SchemeRainbow(sourceHct, isDark, contrast);
|
|
61
|
+
case "fruitSalad":
|
|
62
|
+
return new SchemeFruitSalad(sourceHct, isDark, contrast);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function buildScheme(variant, sourceHct, isDark, contrast, surfaceTone, seedAdjustments) {
|
|
66
|
+
const base = buildBaseScheme(variant, sourceHct, isDark, contrast);
|
|
67
|
+
const primaryChroma = seedAdjustments == null ? void 0 : seedAdjustments.primary;
|
|
68
|
+
const secondaryChroma = seedAdjustments == null ? void 0 : seedAdjustments.secondary;
|
|
69
|
+
const flattenNeutrals = surfaceTone === "neutral";
|
|
70
|
+
if (primaryChroma == null && secondaryChroma == null && !flattenNeutrals) {
|
|
71
|
+
return base;
|
|
72
|
+
}
|
|
73
|
+
const primaryPalette = primaryChroma != null ? TonalPalette.fromHueAndChroma(base.primaryPalette.hue, primaryChroma) : base.primaryPalette;
|
|
74
|
+
const secondaryPalette = secondaryChroma != null ? TonalPalette.fromHueAndChroma(
|
|
75
|
+
base.secondaryPalette.hue,
|
|
76
|
+
secondaryChroma
|
|
77
|
+
) : base.secondaryPalette;
|
|
78
|
+
const neutralPalette = flattenNeutrals ? TonalPalette.fromHueAndChroma(base.neutralPalette.hue, 0) : base.neutralPalette;
|
|
79
|
+
const neutralVariantPalette = flattenNeutrals ? TonalPalette.fromHueAndChroma(base.neutralVariantPalette.hue, 0) : base.neutralVariantPalette;
|
|
80
|
+
return new DynamicScheme({
|
|
81
|
+
sourceColorHct: sourceHct,
|
|
82
|
+
variant: VARIANT_ENUM[variant],
|
|
83
|
+
contrastLevel: contrast,
|
|
84
|
+
isDark,
|
|
85
|
+
primaryPalette,
|
|
86
|
+
secondaryPalette,
|
|
87
|
+
tertiaryPalette: base.tertiaryPalette,
|
|
88
|
+
neutralPalette,
|
|
89
|
+
neutralVariantPalette,
|
|
90
|
+
errorPalette: base.errorPalette
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function extractColors(scheme) {
|
|
94
|
+
const c = new MaterialDynamicColors();
|
|
95
|
+
return {
|
|
96
|
+
primary: hexFromArgb(c.primary().getArgb(scheme)),
|
|
97
|
+
onPrimary: hexFromArgb(c.onPrimary().getArgb(scheme)),
|
|
98
|
+
primaryContainer: hexFromArgb(c.primaryContainer().getArgb(scheme)),
|
|
99
|
+
onPrimaryContainer: hexFromArgb(c.onPrimaryContainer().getArgb(scheme)),
|
|
100
|
+
primaryFixed: hexFromArgb(c.primaryFixed().getArgb(scheme)),
|
|
101
|
+
onPrimaryFixed: hexFromArgb(c.onPrimaryFixed().getArgb(scheme)),
|
|
102
|
+
primaryFixedDim: hexFromArgb(c.primaryFixedDim().getArgb(scheme)),
|
|
103
|
+
onPrimaryFixedVariant: hexFromArgb(
|
|
104
|
+
c.onPrimaryFixedVariant().getArgb(scheme)
|
|
105
|
+
),
|
|
106
|
+
secondary: hexFromArgb(c.secondary().getArgb(scheme)),
|
|
107
|
+
onSecondary: hexFromArgb(c.onSecondary().getArgb(scheme)),
|
|
108
|
+
secondaryContainer: hexFromArgb(c.secondaryContainer().getArgb(scheme)),
|
|
109
|
+
onSecondaryContainer: hexFromArgb(c.onSecondaryContainer().getArgb(scheme)),
|
|
110
|
+
secondaryFixed: hexFromArgb(c.secondaryFixed().getArgb(scheme)),
|
|
111
|
+
onSecondaryFixed: hexFromArgb(c.onSecondaryFixed().getArgb(scheme)),
|
|
112
|
+
secondaryFixedDim: hexFromArgb(c.secondaryFixedDim().getArgb(scheme)),
|
|
113
|
+
onSecondaryFixedVariant: hexFromArgb(
|
|
114
|
+
c.onSecondaryFixedVariant().getArgb(scheme)
|
|
115
|
+
),
|
|
116
|
+
tertiary: hexFromArgb(c.tertiary().getArgb(scheme)),
|
|
117
|
+
onTertiary: hexFromArgb(c.onTertiary().getArgb(scheme)),
|
|
118
|
+
tertiaryContainer: hexFromArgb(c.tertiaryContainer().getArgb(scheme)),
|
|
119
|
+
onTertiaryContainer: hexFromArgb(c.onTertiaryContainer().getArgb(scheme)),
|
|
120
|
+
tertiaryFixed: hexFromArgb(c.tertiaryFixed().getArgb(scheme)),
|
|
121
|
+
onTertiaryFixed: hexFromArgb(c.onTertiaryFixed().getArgb(scheme)),
|
|
122
|
+
tertiaryFixedDim: hexFromArgb(c.tertiaryFixedDim().getArgb(scheme)),
|
|
123
|
+
onTertiaryFixedVariant: hexFromArgb(
|
|
124
|
+
c.onTertiaryFixedVariant().getArgb(scheme)
|
|
125
|
+
),
|
|
126
|
+
error: hexFromArgb(c.error().getArgb(scheme)),
|
|
127
|
+
onError: hexFromArgb(c.onError().getArgb(scheme)),
|
|
128
|
+
errorContainer: hexFromArgb(c.errorContainer().getArgb(scheme)),
|
|
129
|
+
onErrorContainer: hexFromArgb(c.onErrorContainer().getArgb(scheme)),
|
|
130
|
+
background: hexFromArgb(c.background().getArgb(scheme)),
|
|
131
|
+
onBackground: hexFromArgb(c.onBackground().getArgb(scheme)),
|
|
132
|
+
surface: hexFromArgb(c.surface().getArgb(scheme)),
|
|
133
|
+
surfaceDim: hexFromArgb(c.surfaceDim().getArgb(scheme)),
|
|
134
|
+
surfaceBright: hexFromArgb(c.surfaceBright().getArgb(scheme)),
|
|
135
|
+
surfaceContainerLowest: hexFromArgb(
|
|
136
|
+
c.surfaceContainerLowest().getArgb(scheme)
|
|
137
|
+
),
|
|
138
|
+
surfaceContainerLow: hexFromArgb(c.surfaceContainerLow().getArgb(scheme)),
|
|
139
|
+
surfaceContainer: hexFromArgb(c.surfaceContainer().getArgb(scheme)),
|
|
140
|
+
surfaceContainerHigh: hexFromArgb(c.surfaceContainerHigh().getArgb(scheme)),
|
|
141
|
+
surfaceContainerHighest: hexFromArgb(
|
|
142
|
+
c.surfaceContainerHighest().getArgb(scheme)
|
|
143
|
+
),
|
|
144
|
+
onSurface: hexFromArgb(c.onSurface().getArgb(scheme)),
|
|
145
|
+
surfaceVariant: hexFromArgb(c.surfaceVariant().getArgb(scheme)),
|
|
146
|
+
onSurfaceVariant: hexFromArgb(c.onSurfaceVariant().getArgb(scheme)),
|
|
147
|
+
outline: hexFromArgb(c.outline().getArgb(scheme)),
|
|
148
|
+
outlineVariant: hexFromArgb(c.outlineVariant().getArgb(scheme)),
|
|
149
|
+
surfaceTint: hexFromArgb(c.surfaceTint().getArgb(scheme)),
|
|
150
|
+
shadow: hexFromArgb(c.shadow().getArgb(scheme)),
|
|
151
|
+
scrim: hexFromArgb(c.scrim().getArgb(scheme)),
|
|
152
|
+
inverseSurface: hexFromArgb(c.inverseSurface().getArgb(scheme)),
|
|
153
|
+
inverseOnSurface: hexFromArgb(c.inverseOnSurface().getArgb(scheme)),
|
|
154
|
+
inversePrimary: hexFromArgb(c.inversePrimary().getArgb(scheme))
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function createMaterialTheme(seedColor, options) {
|
|
158
|
+
const sourceHct = Hct.fromInt(argbFromHex(seedColor));
|
|
159
|
+
const {
|
|
160
|
+
variant = "tonalSpot",
|
|
161
|
+
fontFamily,
|
|
162
|
+
roundness = 1,
|
|
163
|
+
contrastLevel = "standard",
|
|
164
|
+
surfaceTone = "spec",
|
|
165
|
+
seedAdjustments
|
|
166
|
+
} = options != null ? options : {};
|
|
167
|
+
const contrast = CONTRAST_VALUES[contrastLevel];
|
|
168
|
+
const lightScheme = buildScheme(
|
|
169
|
+
variant,
|
|
170
|
+
sourceHct,
|
|
171
|
+
false,
|
|
172
|
+
contrast,
|
|
173
|
+
surfaceTone,
|
|
174
|
+
seedAdjustments
|
|
175
|
+
);
|
|
176
|
+
const darkScheme = buildScheme(
|
|
177
|
+
variant,
|
|
178
|
+
sourceHct,
|
|
179
|
+
true,
|
|
180
|
+
contrast,
|
|
181
|
+
surfaceTone,
|
|
182
|
+
seedAdjustments
|
|
183
|
+
);
|
|
184
|
+
const shape = roundness === 1 ? lightTheme.shape : applyRoundness(roundness);
|
|
185
|
+
const typography = fontFamily ? Object.fromEntries(
|
|
186
|
+
Object.entries(defaultTypography).map(([key, style]) => [
|
|
187
|
+
key,
|
|
188
|
+
{ ...style, fontFamily }
|
|
189
|
+
])
|
|
190
|
+
) : defaultTypography;
|
|
191
|
+
const shared = {
|
|
192
|
+
typography,
|
|
193
|
+
shape,
|
|
194
|
+
spacing: lightTheme.spacing,
|
|
195
|
+
topAppBar: defaultTopAppBarTokens,
|
|
196
|
+
stateLayer: lightTheme.stateLayer,
|
|
197
|
+
elevation: lightTheme.elevation,
|
|
198
|
+
motion: lightTheme.motion
|
|
199
|
+
};
|
|
200
|
+
return {
|
|
201
|
+
lightTheme: { colors: extractColors(lightScheme), ...shared },
|
|
202
|
+
darkTheme: { colors: extractColors(darkScheme), ...shared }
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
export {
|
|
206
|
+
createMaterialTheme
|
|
207
|
+
};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { T as Theme, a as TopAppBarTokens, B as BaseTheme, S as Shape } from './types-GiXhVyob.mjs';
|
|
2
|
+
export { C as Colors, E as Elevation, b as ElevationLevel, F as FontWeight, M as MaterialTheme, c as Motion, d as ShadowOffset, e as Spacing, f as StateLayer, g as TextStyle, h as Typography } from './types-GiXhVyob.mjs';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
|
|
6
|
+
declare const lightTheme: Theme;
|
|
7
|
+
|
|
8
|
+
declare const darkTheme: Theme;
|
|
9
|
+
|
|
10
|
+
declare const defaultTopAppBarTokens: TopAppBarTokens;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Identity function that validates a custom theme object against `BaseTheme`.
|
|
14
|
+
* Provides type-checking and autocompletion when creating themes for custom design systems.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const myTheme = defineTheme({
|
|
18
|
+
* colors: { brand: '#FF6B00', background: '#FFFFFF', text: '#1A1A1A' },
|
|
19
|
+
* typography: { heading: { fontFamily: 'Inter', fontSize: 24, fontWeight: '700', lineHeight: 32, letterSpacing: 0 } },
|
|
20
|
+
* shape: { roundness: 1, cornerNone: 0, cornerExtraSmall: 4, cornerSmall: 8, cornerMedium: 12, cornerLarge: 16, cornerExtraLarge: 28, cornerFull: 999 },
|
|
21
|
+
* spacing: { xs: 4, sm: 8, md: 16, lg: 24, xl: 32 },
|
|
22
|
+
* stateLayer: { pressedOpacity: 0.1, focusedOpacity: 0.1, hoveredOpacity: 0.08, draggedOpacity: 0.16, disabledOpacity: 0.38, disabledContainerOpacity: 0.12 },
|
|
23
|
+
* elevation: { ... },
|
|
24
|
+
* motion: { ... },
|
|
25
|
+
* })
|
|
26
|
+
*/
|
|
27
|
+
declare function defineTheme<T extends BaseTheme>(theme: T): T;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Scales the intermediate corner radius tokens by a `roundness` multiplier.
|
|
31
|
+
* `cornerNone` always stays `0` and `cornerFull` always stays `999`.
|
|
32
|
+
*
|
|
33
|
+
* @param roundness - Multiplier: `0` = sharp corners, `1` = default MD3, `2` = double rounding.
|
|
34
|
+
* @returns A complete `Shape` object with scaled corner values.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* applyRoundness(0) // all corners 0 except cornerFull (999)
|
|
38
|
+
* applyRoundness(1) // default MD3 values
|
|
39
|
+
* applyRoundness(1.5) // 50% rounder than MD3
|
|
40
|
+
*/
|
|
41
|
+
declare function applyRoundness(roundness: number): Shape;
|
|
42
|
+
|
|
43
|
+
/** Sizing/coloring information passed to icon resolvers and render functions. */
|
|
44
|
+
interface IconRenderProps {
|
|
45
|
+
size: number;
|
|
46
|
+
/**
|
|
47
|
+
* Resolved icon color. May be `undefined` when the component inherits
|
|
48
|
+
* color from a parent text style — handle that case by deferring to the
|
|
49
|
+
* icon library's own default.
|
|
50
|
+
*/
|
|
51
|
+
color?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Maps a string icon name to a rendered icon node. Configured at the
|
|
55
|
+
* provider level so consumers can plug in SF Symbols, Lucide, custom SVGs,
|
|
56
|
+
* etc. without forking components.
|
|
57
|
+
*/
|
|
58
|
+
type IconResolver = (name: string, props: IconRenderProps) => React.ReactNode;
|
|
59
|
+
declare const IconResolverContext: React.Context<IconResolver | null>;
|
|
60
|
+
|
|
61
|
+
interface ThemeProviderProps {
|
|
62
|
+
/**
|
|
63
|
+
* Theme object to provide to all child components via context.
|
|
64
|
+
* Accepts any theme extending `BaseTheme` — Material, Apple, or custom.
|
|
65
|
+
* @default lightTheme (Material Design 3)
|
|
66
|
+
*/
|
|
67
|
+
theme?: BaseTheme;
|
|
68
|
+
/**
|
|
69
|
+
* Resolves string icon names (e.g. `leadingIcon="check"`) to icon nodes.
|
|
70
|
+
* Set this once at the app root to use SF Symbols, Lucide, custom SVGs,
|
|
71
|
+
* etc. instead of the default `MaterialCommunityIcons`.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* import { Check, ArrowRight } from 'lucide-react-native'
|
|
75
|
+
*
|
|
76
|
+
* const icons = { check: Check, 'arrow-right': ArrowRight }
|
|
77
|
+
*
|
|
78
|
+
* <ThemeProvider iconResolver={(name, { size, color }) => {
|
|
79
|
+
* const Icon = icons[name]
|
|
80
|
+
* return Icon ? <Icon size={size} color={color} /> : null
|
|
81
|
+
* }}>
|
|
82
|
+
* <App />
|
|
83
|
+
* </ThemeProvider>
|
|
84
|
+
*/
|
|
85
|
+
iconResolver?: IconResolver;
|
|
86
|
+
/** Tree of components that will have access to the theme via `useTheme()`. */
|
|
87
|
+
children: React.ReactNode;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Provides a theme to all child components via context.
|
|
91
|
+
* Works with any design system — Material Design 3 or custom themes.
|
|
92
|
+
* Defaults to the Material Design 3 light theme when no theme is provided.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* // Material Design 3 (default)
|
|
96
|
+
* import { ThemeProvider } from '@rootnative/core'
|
|
97
|
+
*
|
|
98
|
+
* <ThemeProvider>
|
|
99
|
+
* <App />
|
|
100
|
+
* </ThemeProvider>
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* // Custom or Apple theme
|
|
104
|
+
* import { ThemeProvider } from '@rootnative/core'
|
|
105
|
+
*
|
|
106
|
+
* <ThemeProvider theme={myTheme}>
|
|
107
|
+
* <App />
|
|
108
|
+
* </ThemeProvider>
|
|
109
|
+
*/
|
|
110
|
+
declare function ThemeProvider({ theme, iconResolver, children, }: ThemeProviderProps): react_jsx_runtime.JSX.Element;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Returns the current theme from the nearest `ThemeProvider`.
|
|
114
|
+
*
|
|
115
|
+
* Without a type parameter, returns the Material Design 3 `Theme`.
|
|
116
|
+
* Pass a custom theme type to get typed access to your design system's tokens.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* // Material Design 3 (default)
|
|
120
|
+
* const theme = useTheme()
|
|
121
|
+
* theme.colors.primary // ✓ typed
|
|
122
|
+
*
|
|
123
|
+
* // Custom design system
|
|
124
|
+
* const theme = useTheme<MyTheme>()
|
|
125
|
+
* theme.colors.brand // ✓ typed
|
|
126
|
+
*/
|
|
127
|
+
declare function useTheme<T extends BaseTheme = Theme>(): T;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Returns the icon resolver registered on the nearest `ThemeProvider`,
|
|
131
|
+
* or `null` if none was provided. Components fall back to
|
|
132
|
+
* `@expo/vector-icons/MaterialCommunityIcons` when no resolver is set.
|
|
133
|
+
*/
|
|
134
|
+
declare function useIconResolver(): IconResolver | null;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Material Design 3 window size classes.
|
|
138
|
+
* @see https://m3.material.io/foundations/layout/applying-layout/window-size-classes
|
|
139
|
+
*/
|
|
140
|
+
type Breakpoint = 'compact' | 'medium' | 'expanded' | 'large' | 'extraLarge';
|
|
141
|
+
declare const breakpoints: {
|
|
142
|
+
readonly compact: 0;
|
|
143
|
+
readonly medium: 600;
|
|
144
|
+
readonly expanded: 840;
|
|
145
|
+
readonly large: 1200;
|
|
146
|
+
readonly extraLarge: 1600;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Returns the current Material Design 3 window size class based on viewport width.
|
|
150
|
+
* Reactively updates when the window is resized.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* const breakpoint = useBreakpoint()
|
|
154
|
+
* const columns = breakpoint === 'compact' ? 2 : 4
|
|
155
|
+
*/
|
|
156
|
+
declare function useBreakpoint(): Breakpoint;
|
|
157
|
+
|
|
158
|
+
/** A partial map from breakpoint names to values. Unset breakpoints fall back to the nearest smaller one. */
|
|
159
|
+
type BreakpointValues<T> = Partial<Record<Breakpoint, T>> & Record<'compact', T>;
|
|
160
|
+
/**
|
|
161
|
+
* Returns a value based on the current breakpoint, cascading down to the
|
|
162
|
+
* nearest smaller breakpoint when no exact match is set.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* const columns = useBreakpointValue({ compact: 1, medium: 2, expanded: 4 })
|
|
166
|
+
* // compact → 1, medium → 2, expanded/large/extraLarge → 4
|
|
167
|
+
*/
|
|
168
|
+
declare function useBreakpointValue<T>(values: BreakpointValues<T>): T;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Material Design 3 preset — groups all MD3-specific theme values.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* import { material } from '@rootnative/core'
|
|
175
|
+
*
|
|
176
|
+
* <ThemeProvider theme={material.darkTheme}>
|
|
177
|
+
* <App />
|
|
178
|
+
* </ThemeProvider>
|
|
179
|
+
*/
|
|
180
|
+
declare const material: {
|
|
181
|
+
readonly lightTheme: Theme;
|
|
182
|
+
readonly darkTheme: Theme;
|
|
183
|
+
readonly defaultTopAppBarTokens: TopAppBarTokens;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export { BaseTheme, type Breakpoint, type BreakpointValues, type IconRenderProps, type IconResolver, IconResolverContext, Shape, Theme, ThemeProvider, type ThemeProviderProps, TopAppBarTokens, applyRoundness, breakpoints, darkTheme, defaultTopAppBarTokens, defineTheme, lightTheme, material, useBreakpoint, useBreakpointValue, useIconResolver, useTheme };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyRoundness,
|
|
3
|
+
defaultTopAppBarTokens,
|
|
4
|
+
defaultTypography,
|
|
5
|
+
lightTheme
|
|
6
|
+
} from "./chunk-DC35U5WG.mjs";
|
|
7
|
+
|
|
8
|
+
// src/theme/dark.ts
|
|
9
|
+
var darkTheme = {
|
|
10
|
+
colors: {
|
|
11
|
+
primary: "#D0BCFF",
|
|
12
|
+
onPrimary: "#381E72",
|
|
13
|
+
primaryContainer: "#4F378B",
|
|
14
|
+
onPrimaryContainer: "#EADDFF",
|
|
15
|
+
primaryFixed: "#EADDFF",
|
|
16
|
+
onPrimaryFixed: "#21005D",
|
|
17
|
+
primaryFixedDim: "#D0BCFF",
|
|
18
|
+
onPrimaryFixedVariant: "#4F378B",
|
|
19
|
+
secondary: "#CCC2DC",
|
|
20
|
+
onSecondary: "#332D41",
|
|
21
|
+
secondaryContainer: "#4A4458",
|
|
22
|
+
onSecondaryContainer: "#E8DEF8",
|
|
23
|
+
secondaryFixed: "#E8DEF8",
|
|
24
|
+
onSecondaryFixed: "#1D192B",
|
|
25
|
+
secondaryFixedDim: "#CCC2DC",
|
|
26
|
+
onSecondaryFixedVariant: "#4A4458",
|
|
27
|
+
tertiary: "#EFB8C8",
|
|
28
|
+
onTertiary: "#492532",
|
|
29
|
+
tertiaryContainer: "#633B48",
|
|
30
|
+
onTertiaryContainer: "#FFD8E4",
|
|
31
|
+
tertiaryFixed: "#FFD8E4",
|
|
32
|
+
onTertiaryFixed: "#31111D",
|
|
33
|
+
tertiaryFixedDim: "#EFB8C8",
|
|
34
|
+
onTertiaryFixedVariant: "#633B48",
|
|
35
|
+
error: "#F2B8B5",
|
|
36
|
+
onError: "#601410",
|
|
37
|
+
errorContainer: "#8C1D18",
|
|
38
|
+
onErrorContainer: "#F9DEDC",
|
|
39
|
+
background: "#141218",
|
|
40
|
+
onBackground: "#E6E0E9",
|
|
41
|
+
surface: "#141218",
|
|
42
|
+
surfaceDim: "#141218",
|
|
43
|
+
surfaceBright: "#3B383E",
|
|
44
|
+
surfaceContainerLowest: "#0F0D13",
|
|
45
|
+
surfaceContainerLow: "#1D1B20",
|
|
46
|
+
surfaceContainer: "#211F26",
|
|
47
|
+
surfaceContainerHigh: "#2B2930",
|
|
48
|
+
surfaceContainerHighest: "#36343B",
|
|
49
|
+
onSurface: "#E6E0E9",
|
|
50
|
+
surfaceVariant: "#49454F",
|
|
51
|
+
onSurfaceVariant: "#CAC4D0",
|
|
52
|
+
outline: "#938F99",
|
|
53
|
+
outlineVariant: "#49454F",
|
|
54
|
+
surfaceTint: "#D0BCFF",
|
|
55
|
+
shadow: "#000000",
|
|
56
|
+
scrim: "#000000",
|
|
57
|
+
inverseSurface: "#E6E0E9",
|
|
58
|
+
inverseOnSurface: "#322F35",
|
|
59
|
+
inversePrimary: "#6750A4"
|
|
60
|
+
},
|
|
61
|
+
typography: defaultTypography,
|
|
62
|
+
shape: {
|
|
63
|
+
roundness: 1,
|
|
64
|
+
cornerNone: 0,
|
|
65
|
+
cornerExtraSmall: 4,
|
|
66
|
+
cornerSmall: 8,
|
|
67
|
+
cornerMedium: 12,
|
|
68
|
+
cornerLarge: 16,
|
|
69
|
+
cornerExtraLarge: 28,
|
|
70
|
+
cornerFull: 999
|
|
71
|
+
},
|
|
72
|
+
spacing: {
|
|
73
|
+
xs: 4,
|
|
74
|
+
sm: 8,
|
|
75
|
+
md: 16,
|
|
76
|
+
lg: 24,
|
|
77
|
+
xl: 32
|
|
78
|
+
},
|
|
79
|
+
topAppBar: defaultTopAppBarTokens,
|
|
80
|
+
stateLayer: {
|
|
81
|
+
pressedOpacity: 0.1,
|
|
82
|
+
focusedOpacity: 0.1,
|
|
83
|
+
hoveredOpacity: 0.08,
|
|
84
|
+
draggedOpacity: 0.16,
|
|
85
|
+
disabledOpacity: 0.38,
|
|
86
|
+
disabledContainerOpacity: 0.12
|
|
87
|
+
},
|
|
88
|
+
elevation: {
|
|
89
|
+
level0: {
|
|
90
|
+
shadowColor: "#000000",
|
|
91
|
+
shadowOffset: {
|
|
92
|
+
width: 0,
|
|
93
|
+
height: 0
|
|
94
|
+
},
|
|
95
|
+
shadowOpacity: 0,
|
|
96
|
+
shadowRadius: 0,
|
|
97
|
+
elevation: 0
|
|
98
|
+
},
|
|
99
|
+
level1: {
|
|
100
|
+
shadowColor: "#000000",
|
|
101
|
+
shadowOffset: {
|
|
102
|
+
width: 0,
|
|
103
|
+
height: 1
|
|
104
|
+
},
|
|
105
|
+
shadowOpacity: 0.16,
|
|
106
|
+
shadowRadius: 2,
|
|
107
|
+
elevation: 1
|
|
108
|
+
},
|
|
109
|
+
level2: {
|
|
110
|
+
shadowColor: "#000000",
|
|
111
|
+
shadowOffset: {
|
|
112
|
+
width: 0,
|
|
113
|
+
height: 2
|
|
114
|
+
},
|
|
115
|
+
shadowOpacity: 0.2,
|
|
116
|
+
shadowRadius: 4,
|
|
117
|
+
elevation: 3
|
|
118
|
+
},
|
|
119
|
+
level3: {
|
|
120
|
+
shadowColor: "#000000",
|
|
121
|
+
shadowOffset: {
|
|
122
|
+
width: 0,
|
|
123
|
+
height: 4
|
|
124
|
+
},
|
|
125
|
+
shadowOpacity: 0.24,
|
|
126
|
+
shadowRadius: 8,
|
|
127
|
+
elevation: 6
|
|
128
|
+
},
|
|
129
|
+
level4: {
|
|
130
|
+
shadowColor: "#000000",
|
|
131
|
+
shadowOffset: {
|
|
132
|
+
width: 0,
|
|
133
|
+
height: 6
|
|
134
|
+
},
|
|
135
|
+
shadowOpacity: 0.26,
|
|
136
|
+
shadowRadius: 10,
|
|
137
|
+
elevation: 8
|
|
138
|
+
},
|
|
139
|
+
level5: {
|
|
140
|
+
shadowColor: "#000000",
|
|
141
|
+
shadowOffset: {
|
|
142
|
+
width: 0,
|
|
143
|
+
height: 8
|
|
144
|
+
},
|
|
145
|
+
shadowOpacity: 0.28,
|
|
146
|
+
shadowRadius: 12,
|
|
147
|
+
elevation: 12
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
motion: {
|
|
151
|
+
durationShort1: 50,
|
|
152
|
+
durationShort2: 100,
|
|
153
|
+
durationShort3: 150,
|
|
154
|
+
durationShort4: 200,
|
|
155
|
+
durationMedium1: 250,
|
|
156
|
+
durationMedium2: 300,
|
|
157
|
+
durationMedium3: 350,
|
|
158
|
+
durationMedium4: 400,
|
|
159
|
+
durationLong1: 450,
|
|
160
|
+
durationLong2: 500,
|
|
161
|
+
durationLong3: 550,
|
|
162
|
+
durationLong4: 600,
|
|
163
|
+
durationExtraLong1: 700,
|
|
164
|
+
durationExtraLong2: 800,
|
|
165
|
+
durationExtraLong3: 900,
|
|
166
|
+
durationExtraLong4: 1e3,
|
|
167
|
+
easingLinear: "cubic-bezier(0, 0, 1, 1)",
|
|
168
|
+
easingStandard: "cubic-bezier(0.2, 0, 0, 1)",
|
|
169
|
+
easingStandardAccelerate: "cubic-bezier(0.3, 0, 1, 1)",
|
|
170
|
+
easingStandardDecelerate: "cubic-bezier(0, 0, 0, 1)",
|
|
171
|
+
easingEmphasized: "cubic-bezier(0.2, 0, 0, 1)",
|
|
172
|
+
easingEmphasizedAccelerate: "cubic-bezier(0.3, 0, 0.8, 0.15)",
|
|
173
|
+
easingEmphasizedDecelerate: "cubic-bezier(0.05, 0.7, 0.1, 1)"
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// src/theme/defineTheme.ts
|
|
178
|
+
function defineTheme(theme) {
|
|
179
|
+
return theme;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/provider/IconResolverContext.ts
|
|
183
|
+
import * as React from "react";
|
|
184
|
+
var IconResolverContext = React.createContext(
|
|
185
|
+
null
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
// src/provider/ThemeContext.ts
|
|
189
|
+
import * as React2 from "react";
|
|
190
|
+
var ThemeContext = React2.createContext(lightTheme);
|
|
191
|
+
|
|
192
|
+
// src/provider/ThemeProvider.tsx
|
|
193
|
+
import { jsx } from "react/jsx-runtime";
|
|
194
|
+
function ThemeProvider({
|
|
195
|
+
theme,
|
|
196
|
+
iconResolver,
|
|
197
|
+
children
|
|
198
|
+
}) {
|
|
199
|
+
return /* @__PURE__ */ jsx(ThemeContext.Provider, { value: theme != null ? theme : lightTheme, children: /* @__PURE__ */ jsx(IconResolverContext.Provider, { value: iconResolver != null ? iconResolver : null, children }) });
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/provider/useTheme.ts
|
|
203
|
+
import { useContext } from "react";
|
|
204
|
+
function useTheme() {
|
|
205
|
+
return useContext(ThemeContext);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/provider/useIconResolver.ts
|
|
209
|
+
import { useContext as useContext2 } from "react";
|
|
210
|
+
function useIconResolver() {
|
|
211
|
+
return useContext2(IconResolverContext);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/responsive/useBreakpoint.ts
|
|
215
|
+
import { useWindowDimensions } from "react-native";
|
|
216
|
+
var breakpoints = {
|
|
217
|
+
compact: 0,
|
|
218
|
+
medium: 600,
|
|
219
|
+
expanded: 840,
|
|
220
|
+
large: 1200,
|
|
221
|
+
extraLarge: 1600
|
|
222
|
+
};
|
|
223
|
+
function getBreakpoint(width) {
|
|
224
|
+
if (width >= breakpoints.extraLarge) return "extraLarge";
|
|
225
|
+
if (width >= breakpoints.large) return "large";
|
|
226
|
+
if (width >= breakpoints.expanded) return "expanded";
|
|
227
|
+
if (width >= breakpoints.medium) return "medium";
|
|
228
|
+
return "compact";
|
|
229
|
+
}
|
|
230
|
+
function useBreakpoint() {
|
|
231
|
+
const { width } = useWindowDimensions();
|
|
232
|
+
return getBreakpoint(width);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/responsive/useBreakpointValue.ts
|
|
236
|
+
var order = [
|
|
237
|
+
"compact",
|
|
238
|
+
"medium",
|
|
239
|
+
"expanded",
|
|
240
|
+
"large",
|
|
241
|
+
"extraLarge"
|
|
242
|
+
];
|
|
243
|
+
function useBreakpointValue(values) {
|
|
244
|
+
const breakpoint = useBreakpoint();
|
|
245
|
+
const idx = order.indexOf(breakpoint);
|
|
246
|
+
for (let i = idx; i >= 0; i--) {
|
|
247
|
+
const key = order[i];
|
|
248
|
+
if (key in values) return values[key];
|
|
249
|
+
}
|
|
250
|
+
return values.compact;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/presets/material.ts
|
|
254
|
+
var material = {
|
|
255
|
+
lightTheme,
|
|
256
|
+
darkTheme,
|
|
257
|
+
defaultTopAppBarTokens
|
|
258
|
+
};
|
|
259
|
+
export {
|
|
260
|
+
IconResolverContext,
|
|
261
|
+
ThemeProvider,
|
|
262
|
+
applyRoundness,
|
|
263
|
+
breakpoints,
|
|
264
|
+
darkTheme,
|
|
265
|
+
defaultTopAppBarTokens,
|
|
266
|
+
defineTheme,
|
|
267
|
+
lightTheme,
|
|
268
|
+
material,
|
|
269
|
+
useBreakpoint,
|
|
270
|
+
useBreakpointValue,
|
|
271
|
+
useIconResolver,
|
|
272
|
+
useTheme
|
|
273
|
+
};
|