@poolse/theme 0.0.0-stage → 3.5.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/CHANGELOG.md +28 -0
- package/LICENSE +206 -0
- package/README.md +98 -2
- package/dist/index.cjs +746 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +306 -0
- package/dist/index.d.ts +306 -0
- package/dist/index.js +723 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
type ColorScheme = 'light' | 'dark';
|
|
2
|
+
/** What a provider takes: a fixed scheme, or follow the OS. */
|
|
3
|
+
type ColorSchemePreference = ColorScheme | 'system';
|
|
4
|
+
/**
|
|
5
|
+
* Every colour is a hex string: `#rrggbb`, or `#rrggbbaa` where
|
|
6
|
+
* transparency matters (`overlay`).
|
|
7
|
+
*/
|
|
8
|
+
interface ThemeColors {
|
|
9
|
+
/** Page / chat-pane background. */
|
|
10
|
+
background: string;
|
|
11
|
+
/** Cards, panels, inputs on top of `background`. */
|
|
12
|
+
surface: string;
|
|
13
|
+
/** Insets, fields, hover fills. */
|
|
14
|
+
surfaceAlt: string;
|
|
15
|
+
/** Primary text. */
|
|
16
|
+
text: string;
|
|
17
|
+
/** Secondary text (timestamps, previews). */
|
|
18
|
+
textMuted: string;
|
|
19
|
+
/** Hints and placeholders — decorative, not for text that must be read. */
|
|
20
|
+
textSubtle: string;
|
|
21
|
+
border: string;
|
|
22
|
+
/** Primary action fill (buttons, badges, the unread pill). */
|
|
23
|
+
accent: string;
|
|
24
|
+
/** Foreground on `accent`. */
|
|
25
|
+
accentText: string;
|
|
26
|
+
/** Tinted fills: selected rows, highlights. */
|
|
27
|
+
accentSoft: string;
|
|
28
|
+
/** Accent as text on `background` / `surface`. */
|
|
29
|
+
accentStrong: string;
|
|
30
|
+
/** Links in message bodies. */
|
|
31
|
+
link: string;
|
|
32
|
+
/** App sidebar / rail (the workspace apps; the chat UI doesn't draw one). */
|
|
33
|
+
sidebar: string;
|
|
34
|
+
sidebarText: string;
|
|
35
|
+
/** Selected sidebar item fill. */
|
|
36
|
+
sidebarActive: string;
|
|
37
|
+
sidebarActiveText: string;
|
|
38
|
+
/** Unread-count badges. */
|
|
39
|
+
badge: string;
|
|
40
|
+
badgeText: string;
|
|
41
|
+
/** Background of an @-mention chip and of a message that mentions the viewer. */
|
|
42
|
+
mention: string;
|
|
43
|
+
mentionText: string;
|
|
44
|
+
danger: string;
|
|
45
|
+
warning: string;
|
|
46
|
+
success: string;
|
|
47
|
+
info: string;
|
|
48
|
+
/** Online dot. */
|
|
49
|
+
presence: string;
|
|
50
|
+
ownBubble: string;
|
|
51
|
+
ownBubbleText: string;
|
|
52
|
+
otherBubble: string;
|
|
53
|
+
otherBubbleText: string;
|
|
54
|
+
/** Scrim behind sheets, lightboxes and drop targets. */
|
|
55
|
+
overlay: string;
|
|
56
|
+
}
|
|
57
|
+
interface ThemeFonts {
|
|
58
|
+
/** CSS font-family list on the web; the first family is what React Native uses. */
|
|
59
|
+
body: string;
|
|
60
|
+
display: string;
|
|
61
|
+
mono: string;
|
|
62
|
+
/** Font sizes in px. `sizeMd` is the message body. */
|
|
63
|
+
sizeXs: number;
|
|
64
|
+
sizeSm: number;
|
|
65
|
+
sizeMd: number;
|
|
66
|
+
sizeLg: number;
|
|
67
|
+
sizeXl: number;
|
|
68
|
+
/** Unitless line-height multiplier for body text. */
|
|
69
|
+
lineHeight: number;
|
|
70
|
+
}
|
|
71
|
+
/** Corner radii in px. */
|
|
72
|
+
interface ThemeRadii {
|
|
73
|
+
sm: number;
|
|
74
|
+
md: number;
|
|
75
|
+
lg: number;
|
|
76
|
+
xl: number;
|
|
77
|
+
pill: number;
|
|
78
|
+
/** Chat bubbles. */
|
|
79
|
+
bubble: number;
|
|
80
|
+
}
|
|
81
|
+
/** Spacing steps in px. */
|
|
82
|
+
interface ThemeSpacing {
|
|
83
|
+
xs: number;
|
|
84
|
+
sm: number;
|
|
85
|
+
md: number;
|
|
86
|
+
lg: number;
|
|
87
|
+
xl: number;
|
|
88
|
+
}
|
|
89
|
+
interface ShadowLayer {
|
|
90
|
+
x: number;
|
|
91
|
+
y: number;
|
|
92
|
+
blur: number;
|
|
93
|
+
spread: number;
|
|
94
|
+
/** `#rrggbb`. */
|
|
95
|
+
color: string;
|
|
96
|
+
/** 0–1. */
|
|
97
|
+
opacity: number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The web draws every layer; React Native draws the last one (the
|
|
101
|
+
* largest, by convention) and uses `elevation` on Android.
|
|
102
|
+
*/
|
|
103
|
+
interface ShadowToken {
|
|
104
|
+
layers: ShadowLayer[];
|
|
105
|
+
elevation: number;
|
|
106
|
+
}
|
|
107
|
+
interface ThemeShadows {
|
|
108
|
+
sm: ShadowToken;
|
|
109
|
+
md: ShadowToken;
|
|
110
|
+
lg: ShadowToken;
|
|
111
|
+
}
|
|
112
|
+
/** One colour scheme's worth of tokens. */
|
|
113
|
+
interface ThemeTokens {
|
|
114
|
+
colors: ThemeColors;
|
|
115
|
+
fonts: ThemeFonts;
|
|
116
|
+
radii: ThemeRadii;
|
|
117
|
+
spacing: ThemeSpacing;
|
|
118
|
+
shadows: ThemeShadows;
|
|
119
|
+
}
|
|
120
|
+
type BuiltInThemeId = 'coral' | 'ocean' | 'forest' | 'grape' | 'slate' | 'sunset' | 'rose' | 'mono';
|
|
121
|
+
interface Theme {
|
|
122
|
+
/** Lowercase letters, digits and dashes. */
|
|
123
|
+
id: string;
|
|
124
|
+
name: string;
|
|
125
|
+
/** The built-in theme this one was made from — what `encodeTheme` diffs against. */
|
|
126
|
+
extends?: BuiltInThemeId;
|
|
127
|
+
light: ThemeTokens;
|
|
128
|
+
dark: ThemeTokens;
|
|
129
|
+
}
|
|
130
|
+
/** What the `theme` prop takes: a built-in theme's id, or a whole theme. */
|
|
131
|
+
type ThemeInput = BuiltInThemeId | Theme;
|
|
132
|
+
/** A theme's tokens for one scheme, with the theme's identity. */
|
|
133
|
+
interface ResolvedTheme extends ThemeTokens {
|
|
134
|
+
id: string;
|
|
135
|
+
name: string;
|
|
136
|
+
scheme: ColorScheme;
|
|
137
|
+
}
|
|
138
|
+
/** Only the tokens you set replace the base theme's. */
|
|
139
|
+
interface ThemeTokenOverrides {
|
|
140
|
+
colors?: Partial<ThemeColors>;
|
|
141
|
+
fonts?: Partial<ThemeFonts>;
|
|
142
|
+
radii?: Partial<ThemeRadii>;
|
|
143
|
+
spacing?: Partial<ThemeSpacing>;
|
|
144
|
+
shadows?: Partial<ThemeShadows>;
|
|
145
|
+
}
|
|
146
|
+
/** A React Native shadow style. */
|
|
147
|
+
interface NativeShadow {
|
|
148
|
+
shadowColor: string;
|
|
149
|
+
shadowOpacity: number;
|
|
150
|
+
shadowOffset: {
|
|
151
|
+
width: number;
|
|
152
|
+
height: number;
|
|
153
|
+
};
|
|
154
|
+
shadowRadius: number;
|
|
155
|
+
elevation: number;
|
|
156
|
+
}
|
|
157
|
+
/** A resolved theme as React Native style values. */
|
|
158
|
+
interface NativeTheme {
|
|
159
|
+
id: string;
|
|
160
|
+
name: string;
|
|
161
|
+
scheme: ColorScheme;
|
|
162
|
+
colors: ThemeColors;
|
|
163
|
+
fonts: {
|
|
164
|
+
/** A single family name (React Native takes no fallback list). */
|
|
165
|
+
body: string;
|
|
166
|
+
display: string;
|
|
167
|
+
mono: string;
|
|
168
|
+
sizeXs: number;
|
|
169
|
+
sizeSm: number;
|
|
170
|
+
sizeMd: number;
|
|
171
|
+
sizeLg: number;
|
|
172
|
+
sizeXl: number;
|
|
173
|
+
/** Body line height in px. */
|
|
174
|
+
lineHeight: number;
|
|
175
|
+
};
|
|
176
|
+
radii: ThemeRadii;
|
|
177
|
+
spacing: ThemeSpacing;
|
|
178
|
+
shadows: {
|
|
179
|
+
sm: NativeShadow;
|
|
180
|
+
md: NativeShadow;
|
|
181
|
+
lg: NativeShadow;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
declare const BUILT_IN_THEMES: Readonly<Record<BuiltInThemeId, Theme>>;
|
|
186
|
+
/** In the order a theme picker should list them; `coral` first. */
|
|
187
|
+
declare const BUILT_IN_THEME_IDS: readonly BuiltInThemeId[];
|
|
188
|
+
declare const DEFAULT_THEME_ID: BuiltInThemeId;
|
|
189
|
+
declare function isBuiltInThemeId(value: unknown): value is BuiltInThemeId;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The theme a `theme` prop names. An unknown id falls back to the
|
|
193
|
+
* default theme rather than throwing — a stale saved preference must
|
|
194
|
+
* not take the UI down.
|
|
195
|
+
*/
|
|
196
|
+
declare function getTheme(input: ThemeInput | null | undefined): Theme;
|
|
197
|
+
/** One scheme of a theme, with the theme's id and name. */
|
|
198
|
+
declare function resolveTheme(input: ThemeInput | null | undefined, scheme: ColorScheme): ResolvedTheme;
|
|
199
|
+
/** `base` with `overrides` laid over it, group by group. */
|
|
200
|
+
declare function mergeTokens(base: ThemeTokens, overrides?: ThemeTokenOverrides): ThemeTokens;
|
|
201
|
+
interface CreateThemeOptions {
|
|
202
|
+
id: string;
|
|
203
|
+
name: string;
|
|
204
|
+
/** Built-in theme to start from. Defaults to `coral`. */
|
|
205
|
+
extends?: BuiltInThemeId;
|
|
206
|
+
/** Overrides for both schemes, applied before `light` / `dark`. */
|
|
207
|
+
tokens?: ThemeTokenOverrides;
|
|
208
|
+
light?: ThemeTokenOverrides;
|
|
209
|
+
dark?: ThemeTokenOverrides;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* A custom theme: a built-in one with some tokens replaced.
|
|
213
|
+
*
|
|
214
|
+
* createTheme({ id: 'acme', name: 'Acme', extends: 'ocean',
|
|
215
|
+
* tokens: { colors: { accent: '#0a7d5a' } } })
|
|
216
|
+
*/
|
|
217
|
+
declare function createTheme(options: CreateThemeOptions): Theme;
|
|
218
|
+
|
|
219
|
+
interface CssVariableOptions {
|
|
220
|
+
/**
|
|
221
|
+
* Also set the stylesheet's original variable names. Defaults to
|
|
222
|
+
* `true`; turn it off only if nothing on the page reads them.
|
|
223
|
+
*/
|
|
224
|
+
legacy?: boolean;
|
|
225
|
+
}
|
|
226
|
+
/** A shadow token as a `box-shadow` value. */
|
|
227
|
+
declare function cssShadow(token: ShadowToken): string;
|
|
228
|
+
/** Tokens → variables, without resolving a theme first. */
|
|
229
|
+
declare function tokensToCssVariables(t: ThemeTokens, options?: CssVariableOptions): Record<string, string>;
|
|
230
|
+
/**
|
|
231
|
+
* A theme's variables for one scheme, as an object — spread it into a
|
|
232
|
+
* React `style` prop or set each with `style.setProperty`.
|
|
233
|
+
*/
|
|
234
|
+
declare function toCssVariables(theme: ThemeInput, scheme: ColorScheme, options?: CssVariableOptions): Record<string, string>;
|
|
235
|
+
/**
|
|
236
|
+
* The same variables as a CSS rule, for a `<style>` tag or a
|
|
237
|
+
* server-rendered stylesheet:
|
|
238
|
+
*
|
|
239
|
+
* toCssText('ocean', 'dark', '[data-theme="dark"]')
|
|
240
|
+
*/
|
|
241
|
+
declare function toCssText(theme: ThemeInput, scheme: ColorScheme, selector?: string, options?: CssVariableOptions): string;
|
|
242
|
+
|
|
243
|
+
interface NativeThemeOptions {
|
|
244
|
+
/**
|
|
245
|
+
* Font families to use. The theme's fonts are web font stacks, and
|
|
246
|
+
* React Native fails on a family the app hasn't loaded, so by
|
|
247
|
+
* default the platform fonts are used (`System`, and `Menlo` for
|
|
248
|
+
* code). Pass the names you registered with expo-font to use your own.
|
|
249
|
+
*/
|
|
250
|
+
fonts?: Partial<Pick<NativeTheme['fonts'], 'body' | 'display' | 'mono'>>;
|
|
251
|
+
}
|
|
252
|
+
/** Tokens → React Native values, without resolving a theme first. */
|
|
253
|
+
declare function tokensToNative(t: ThemeTokens, identity: {
|
|
254
|
+
id: string;
|
|
255
|
+
name: string;
|
|
256
|
+
scheme: ColorScheme;
|
|
257
|
+
}, options?: NativeThemeOptions): NativeTheme;
|
|
258
|
+
/** A theme's tokens for one scheme as a plain React Native object. */
|
|
259
|
+
declare function toNativeTheme(theme: ThemeInput, scheme: ColorScheme, options?: NativeThemeOptions): NativeTheme;
|
|
260
|
+
|
|
261
|
+
declare class ThemeCodeError extends Error {
|
|
262
|
+
constructor(message: string);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* A theme as a shareable code. Built-in themes encode to just their
|
|
266
|
+
* id and name; custom ones to their differences from the built-in
|
|
267
|
+
* theme they extend (`theme.extends`, else `coral`).
|
|
268
|
+
*/
|
|
269
|
+
declare function encodeTheme(theme: Theme): string;
|
|
270
|
+
/**
|
|
271
|
+
* The theme a code describes. Throws `ThemeCodeError` with a reason
|
|
272
|
+
* when the code is malformed, from an unknown format version, or holds
|
|
273
|
+
* a value outside what a theme allows.
|
|
274
|
+
*/
|
|
275
|
+
declare function decodeTheme(code: string): Theme;
|
|
276
|
+
|
|
277
|
+
/** Parse `#rgb`, `#rrggbb` or `#rrggbbaa` into 0–255 channels (alpha 0–1). */
|
|
278
|
+
declare function parseHex(hex: string): {
|
|
279
|
+
r: number;
|
|
280
|
+
g: number;
|
|
281
|
+
b: number;
|
|
282
|
+
a: number;
|
|
283
|
+
} | null;
|
|
284
|
+
/** WCAG relative luminance of an opaque colour (alpha is ignored). */
|
|
285
|
+
declare function relativeLuminance(hex: string): number;
|
|
286
|
+
/** WCAG contrast ratio between two colours, 1–21. */
|
|
287
|
+
declare function contrastRatio(a: string, b: string): number;
|
|
288
|
+
/**
|
|
289
|
+
* The foreground/background pairs that carry text, each of which must
|
|
290
|
+
* reach WCAG AA for body text (4.5:1).
|
|
291
|
+
*/
|
|
292
|
+
declare const CONTRAST_PAIRS: ReadonlyArray<readonly [keyof ThemeColors, keyof ThemeColors]>;
|
|
293
|
+
interface ContrastIssue {
|
|
294
|
+
scheme: ColorScheme;
|
|
295
|
+
foreground: keyof ThemeColors;
|
|
296
|
+
background: keyof ThemeColors;
|
|
297
|
+
ratio: number;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Every pair in `CONTRAST_PAIRS` below `min` (default 4.5), in both
|
|
301
|
+
* schemes. Empty means the theme passes — use it to warn someone
|
|
302
|
+
* building a custom theme.
|
|
303
|
+
*/
|
|
304
|
+
declare function contrastIssues(theme: Theme, min?: number): ContrastIssue[];
|
|
305
|
+
|
|
306
|
+
export { BUILT_IN_THEMES, BUILT_IN_THEME_IDS, type BuiltInThemeId, CONTRAST_PAIRS, type ColorScheme, type ColorSchemePreference, type ContrastIssue, type CreateThemeOptions, type CssVariableOptions, DEFAULT_THEME_ID, type NativeShadow, type NativeTheme, type NativeThemeOptions, type ResolvedTheme, type ShadowLayer, type ShadowToken, type Theme, ThemeCodeError, type ThemeColors, type ThemeFonts, type ThemeInput, type ThemeRadii, type ThemeShadows, type ThemeSpacing, type ThemeTokenOverrides, type ThemeTokens, contrastIssues, contrastRatio, createTheme, cssShadow, decodeTheme, encodeTheme, getTheme, isBuiltInThemeId, mergeTokens, parseHex, relativeLuminance, resolveTheme, toCssText, toCssVariables, toNativeTheme, tokensToCssVariables, tokensToNative };
|