@reactloom/theme 0.0.0-stage → 1.0.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.
Files changed (43) hide show
  1. package/README.md +15 -2
  2. package/dist/LICENSE +21 -0
  3. package/dist/contrast.d.ts +7 -0
  4. package/dist/contrast.d.ts.map +1 -0
  5. package/dist/contrast.js +33 -0
  6. package/dist/contrast.js.map +1 -0
  7. package/dist/create-theme.d.ts +37 -0
  8. package/dist/create-theme.d.ts.map +1 -0
  9. package/dist/create-theme.js +51 -0
  10. package/dist/create-theme.js.map +1 -0
  11. package/dist/css.d.ts +17 -0
  12. package/dist/css.d.ts.map +1 -0
  13. package/dist/css.js +125 -0
  14. package/dist/css.js.map +1 -0
  15. package/dist/index.d.ts +10 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +10 -0
  18. package/dist/prefix.d.ts +12 -0
  19. package/dist/prefix.d.ts.map +1 -0
  20. package/dist/prefix.js +19 -0
  21. package/dist/prefix.js.map +1 -0
  22. package/dist/theme-provider.d.ts +39 -0
  23. package/dist/theme-provider.d.ts.map +1 -0
  24. package/dist/theme-provider.js +92 -0
  25. package/dist/theme-provider.js.map +1 -0
  26. package/dist/theme.css +460 -0
  27. package/dist/themes.d.ts +58 -0
  28. package/dist/themes.d.ts.map +1 -0
  29. package/dist/themes.js +328 -0
  30. package/dist/themes.js.map +1 -0
  31. package/dist/tokens/palette.d.ts +28 -0
  32. package/dist/tokens/palette.d.ts.map +1 -0
  33. package/dist/tokens/palette.js +97 -0
  34. package/dist/tokens/palette.js.map +1 -0
  35. package/dist/tokens/scales.d.ts +97 -0
  36. package/dist/tokens/scales.d.ts.map +1 -0
  37. package/dist/tokens/scales.js +99 -0
  38. package/dist/tokens/scales.js.map +1 -0
  39. package/dist/tokens/semantic.d.ts +21 -0
  40. package/dist/tokens/semantic.d.ts.map +1 -0
  41. package/dist/tokens/semantic.js +182 -0
  42. package/dist/tokens/semantic.js.map +1 -0
  43. package/package.json +81 -3
package/README.md CHANGED
@@ -1,3 +1,16 @@
1
- # Temporary Holding Version
1
+ # @reactloom/theme
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Design tokens, built-in themes (light, dark, high-contrast, system), `createTheme()`,
4
+ `checkThemeContrast()` and a scoped `ThemeProvider` for ReactLoom UI.
5
+
6
+ ```tsx
7
+ import '@reactloom/theme/theme.css';
8
+ import { ThemeProvider, createTheme } from '@reactloom/theme';
9
+
10
+ const brand = createTheme({ name: 'brand', palettes: { accent: myScale } });
11
+ <ThemeProvider theme={brand}>…</ThemeProvider>
12
+ ```
13
+
14
+ All CSS custom properties are prefixed `--pl-` and live in `@layer pl.theme`.
15
+
16
+ Theming guide and token reference: <https://www.reactloom.dev/docs/theming> · <https://www.reactloom.dev/docs/tokens>
package/dist/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ReactLoom UI contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ /** WCAG 2.x relative-luminance contrast utilities (sRGB, hex input). */
2
+ /** Parses `#RGB` or `#RRGGBB`. Returns `null` for anything else (e.g. `rgb()` with alpha). */
3
+ export declare function parseHex(hex: string): [number, number, number] | null;
4
+ export declare function relativeLuminance(hex: string): number;
5
+ /** Contrast ratio between two hex colours, from 1 to 21. */
6
+ export declare function contrastRatio(foreground: string, background: string): number;
7
+ //# sourceMappingURL=contrast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contrast.d.ts","sourceRoot":"","sources":["../src/contrast.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAOxE,8FAA8F;AAC9F,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAKrE;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKrD;AAED,4DAA4D;AAC5D,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAK5E"}
@@ -0,0 +1,33 @@
1
+ // src/contrast.ts
2
+ /** WCAG 2.x relative-luminance contrast utilities (sRGB, hex input). */
3
+ function channel(value) {
4
+ const c = value / 255;
5
+ return c <= .04045 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
6
+ }
7
+ /** Parses `#RGB` or `#RRGGBB`. Returns `null` for anything else (e.g. `rgb()` with alpha). */
8
+ function parseHex(hex) {
9
+ const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
10
+ if (!m?.[1]) return null;
11
+ const h = m[1].length === 3 ? [...m[1]].map((c) => c + c).join("") : m[1];
12
+ return [
13
+ 0,
14
+ 2,
15
+ 4
16
+ ].map((i) => Number.parseInt(h.slice(i, i + 2), 16));
17
+ }
18
+ function relativeLuminance(hex) {
19
+ const rgb = parseHex(hex);
20
+ if (!rgb) throw new Error(`[reactloom] Cannot compute luminance of "${hex}" (hex colours only).`);
21
+ const [r, g, b] = rgb.map(channel);
22
+ return .2126 * r + .7152 * g + .0722 * b;
23
+ }
24
+ /** Contrast ratio between two hex colours, from 1 to 21. */
25
+ function contrastRatio(foreground, background) {
26
+ const a = relativeLuminance(foreground);
27
+ const b = relativeLuminance(background);
28
+ const [hi, lo] = a > b ? [a, b] : [b, a];
29
+ return (hi + .05) / (lo + .05);
30
+ }
31
+ export { contrastRatio, parseHex, relativeLuminance };
32
+
33
+ //# sourceMappingURL=contrast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contrast.js","names":[],"sources":["../src/contrast.ts"],"sourcesContent":["/** WCAG 2.x relative-luminance contrast utilities (sRGB, hex input). */\n\nfunction channel(value: number): number {\n const c = value / 255;\n return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n}\n\n/** Parses `#RGB` or `#RRGGBB`. Returns `null` for anything else (e.g. `rgb()` with alpha). */\nexport function parseHex(hex: string): [number, number, number] | null {\n const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());\n if (!m?.[1]) return null;\n const h = m[1].length === 3 ? [...m[1]].map((c) => c + c).join('') : m[1];\n return [0, 2, 4].map((i) => Number.parseInt(h.slice(i, i + 2), 16)) as [number, number, number];\n}\n\nexport function relativeLuminance(hex: string): number {\n const rgb = parseHex(hex);\n if (!rgb) throw new Error(`[reactloom] Cannot compute luminance of \"${hex}\" (hex colours only).`);\n const [r, g, b] = rgb.map(channel) as [number, number, number];\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n}\n\n/** Contrast ratio between two hex colours, from 1 to 21. */\nexport function contrastRatio(foreground: string, background: string): number {\n const a = relativeLuminance(foreground);\n const b = relativeLuminance(background);\n const [hi, lo] = a > b ? [a, b] : [b, a];\n return (hi + 0.05) / (lo + 0.05);\n}\n"],"mappings":";;AAEA,SAAS,QAAQ,OAAuB;CACtC,MAAM,IAAI,QAAQ;CAClB,OAAO,KAAK,SAAU,IAAI,UAAU,IAAI,QAAS,UAAU;AAC7D;;AAGA,SAAgB,SAAS,KAA8C;CACrE,MAAM,IAAI,gCAAgC,KAAK,IAAI,KAAK,CAAC;CACzD,IAAI,CAAC,IAAI,IAAI,OAAO;CACpB,MAAM,IAAI,EAAE,EAAE,CAAC,WAAW,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE;CACvE,OAAO;EAAC;EAAG;EAAG;CAAC,CAAC,CAAC,KAAK,MAAM,OAAO,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AACpE;AAEA,SAAgB,kBAAkB,KAAqB;CACrD,MAAM,MAAM,SAAS,GAAG;CACxB,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,4CAA4C,IAAI,sBAAsB;CAChG,MAAM,CAAC,GAAG,GAAG,KAAK,IAAI,IAAI,OAAO;CACjC,OAAO,QAAS,IAAI,QAAS,IAAI,QAAS;AAC5C;;AAGA,SAAgB,cAAc,YAAoB,YAA4B;CAC5E,MAAM,IAAI,kBAAkB,UAAU;CACtC,MAAM,IAAI,kBAAkB,UAAU;CACtC,MAAM,CAAC,IAAI,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;CACvC,QAAQ,KAAK,QAAS,KAAK;AAC7B"}
@@ -0,0 +1,37 @@
1
+ import { type BuiltInThemeName, type RadiusName, type ShadowName, type ThemeDefinition } from './themes.js';
2
+ import { type ThemePalettes } from './tokens/palette.js';
3
+ import type { SemanticColorName } from './tokens/semantic.js';
4
+ export interface CreateThemeOptions {
5
+ /** Unique, human-readable theme name (e.g. `"acme-dark"`). */
6
+ name: string;
7
+ /** Built-in theme to derive from. Defaults to `"light"`. */
8
+ base?: BuiltInThemeName;
9
+ /**
10
+ * Replace whole palettes (11-step scales). Semantic colours are re-derived from them with the
11
+ * base theme's mapping, so a new `accent` scale re-colours buttons, links, focus rings, etc.
12
+ */
13
+ palettes?: Partial<ThemePalettes>;
14
+ /** Override individual semantic colours after palette derivation. */
15
+ colors?: Partial<Record<SemanticColorName, string>>;
16
+ radius?: Partial<Record<RadiusName, string>>;
17
+ shadows?: Partial<Record<ShadowName, string>>;
18
+ fontFamily?: Partial<{
19
+ sans: string;
20
+ mono: string;
21
+ }>;
22
+ focusRing?: Partial<{
23
+ color: string;
24
+ width: string;
25
+ offset: string;
26
+ }>;
27
+ controlBorderWidth?: string;
28
+ }
29
+ /**
30
+ * Creates a custom theme. The result can be passed to `<ThemeProvider theme={...}>`.
31
+ *
32
+ * ```ts
33
+ * const acme = createTheme({ name: 'acme', palettes: { accent: acmeTeal }, radius: { md: '4px' } });
34
+ * ```
35
+ */
36
+ export declare function createTheme(options: CreateThemeOptions): ThemeDefinition;
37
+ //# sourceMappingURL=create-theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-theme.d.ts","sourceRoot":"","sources":["../src/create-theme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9H,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,WAAW,kBAAkB;IACjC,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAClC,qEAAqE;IACrE,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9C,UAAU,CAAC,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrD,SAAS,CAAC,EAAE,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtE,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,eAAe,CAkBxE"}
@@ -0,0 +1,51 @@
1
+ import { buildThemeTokens } from "./themes.js";
2
+ import { defaultPalettes } from "./tokens/palette.js";
3
+ // src/create-theme.ts
4
+ /**
5
+ * Creates a custom theme. The result can be passed to `<ThemeProvider theme={...}>`.
6
+ *
7
+ * ```ts
8
+ * const acme = createTheme({ name: 'acme', palettes: { accent: acmeTeal }, radius: { md: '4px' } });
9
+ * ```
10
+ */
11
+ function createTheme(options) {
12
+ const base = options.base ?? "light";
13
+ const palettes = {
14
+ ...defaultPalettes,
15
+ ...options.palettes
16
+ };
17
+ const derived = buildThemeTokens(base, palettes);
18
+ const colors = {
19
+ ...derived.colors,
20
+ ...options.colors
21
+ };
22
+ return {
23
+ name: options.name,
24
+ base,
25
+ colorScheme: base === "dark" ? "dark" : "light",
26
+ tokens: {
27
+ colors,
28
+ shadows: {
29
+ ...derived.shadows,
30
+ ...options.shadows
31
+ },
32
+ radius: {
33
+ ...derived.radius,
34
+ ...options.radius
35
+ },
36
+ fontFamily: {
37
+ ...derived.fontFamily,
38
+ ...options.fontFamily
39
+ },
40
+ focusRing: {
41
+ ...derived.focusRing,
42
+ color: colors["border-focus"],
43
+ ...options.focusRing
44
+ },
45
+ controlBorderWidth: options.controlBorderWidth ?? derived.controlBorderWidth
46
+ }
47
+ };
48
+ }
49
+ export { createTheme };
50
+
51
+ //# sourceMappingURL=create-theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-theme.js","names":[],"sources":["../src/create-theme.ts"],"sourcesContent":["import { buildThemeTokens, type BuiltInThemeName, type RadiusName, type ShadowName, type ThemeDefinition } from './themes.js';\nimport { defaultPalettes, type ThemePalettes } from './tokens/palette.js';\nimport type { SemanticColorName } from './tokens/semantic.js';\n\nexport interface CreateThemeOptions {\n /** Unique, human-readable theme name (e.g. `\"acme-dark\"`). */\n name: string;\n /** Built-in theme to derive from. Defaults to `\"light\"`. */\n base?: BuiltInThemeName;\n /**\n * Replace whole palettes (11-step scales). Semantic colours are re-derived from them with the\n * base theme's mapping, so a new `accent` scale re-colours buttons, links, focus rings, etc.\n */\n palettes?: Partial<ThemePalettes>;\n /** Override individual semantic colours after palette derivation. */\n colors?: Partial<Record<SemanticColorName, string>>;\n radius?: Partial<Record<RadiusName, string>>;\n shadows?: Partial<Record<ShadowName, string>>;\n fontFamily?: Partial<{ sans: string; mono: string }>;\n focusRing?: Partial<{ color: string; width: string; offset: string }>;\n controlBorderWidth?: string;\n}\n\n/**\n * Creates a custom theme. The result can be passed to `<ThemeProvider theme={...}>`.\n *\n * ```ts\n * const acme = createTheme({ name: 'acme', palettes: { accent: acmeTeal }, radius: { md: '4px' } });\n * ```\n */\nexport function createTheme(options: CreateThemeOptions): ThemeDefinition {\n const base = options.base ?? 'light';\n const palettes: ThemePalettes = { ...defaultPalettes, ...options.palettes };\n const derived = buildThemeTokens(base, palettes);\n const colors = { ...derived.colors, ...options.colors };\n return {\n name: options.name,\n base,\n colorScheme: base === 'dark' ? 'dark' : 'light',\n tokens: {\n colors,\n shadows: { ...derived.shadows, ...options.shadows },\n radius: { ...derived.radius, ...options.radius },\n fontFamily: { ...derived.fontFamily, ...options.fontFamily },\n focusRing: { ...derived.focusRing, color: colors['border-focus'], ...options.focusRing },\n controlBorderWidth: options.controlBorderWidth ?? derived.controlBorderWidth,\n },\n };\n}\n"],"mappings":";;;;;;;;;;AA8BA,SAAgB,YAAY,SAA8C;CACxE,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,WAA0B;EAAE,GAAG;EAAiB,GAAG,QAAQ;CAAS;CAC1E,MAAM,UAAU,iBAAiB,MAAM,QAAQ;CAC/C,MAAM,SAAS;EAAE,GAAG,QAAQ;EAAQ,GAAG,QAAQ;CAAO;CACtD,OAAO;EACL,MAAM,QAAQ;EACd;EACA,aAAa,SAAS,SAAS,SAAS;EACxC,QAAQ;GACN;GACA,SAAS;IAAE,GAAG,QAAQ;IAAS,GAAG,QAAQ;GAAQ;GAClD,QAAQ;IAAE,GAAG,QAAQ;IAAQ,GAAG,QAAQ;GAAO;GAC/C,YAAY;IAAE,GAAG,QAAQ;IAAY,GAAG,QAAQ;GAAW;GAC3D,WAAW;IAAE,GAAG,QAAQ;IAAW,OAAO,OAAO;IAAiB,GAAG,QAAQ;GAAU;GACvF,oBAAoB,QAAQ,sBAAsB,QAAQ;EAC5D;CACF;AACF"}
package/dist/css.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { type ThemeDefinition, type ThemeTokens } from './themes.js';
2
+ export type CssVars = Record<`--${string}`, string>;
3
+ /** Theme-dependent custom properties for a theme definition. */
4
+ export declare function themeVars(tokens: ThemeTokens): CssVars;
5
+ /** Theme-independent custom properties (scales, motion, layering, raw palettes). */
6
+ export declare function globalVars(): CssVars;
7
+ /**
8
+ * Only the variables in which `theme` differs from its built-in base.
9
+ * Used by `ThemeProvider` to keep inline styles for custom themes minimal.
10
+ */
11
+ export declare function themeOverrideVars(theme: ThemeDefinition): CssVars;
12
+ /**
13
+ * Generates `theme.css`. Everything is wrapped in the `pl.theme` cascade layer, so any
14
+ * un-layered consumer CSS wins without `!important`.
15
+ */
16
+ export declare function renderThemeCss(): string;
17
+ //# sourceMappingURL=css.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../src/css.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAepF,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC;AAMpD,gEAAgE;AAChE,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAWtD;AAED,oFAAoF;AACpF,wBAAgB,UAAU,IAAI,OAAO,CAgBpC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAQjE;AAWD;;;GAGG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAkEvC"}
package/dist/css.js ADDED
@@ -0,0 +1,125 @@
1
+ import { DENSITY_ATTRIBUTE, THEME_ATTRIBUTE, cssVarName } from "./prefix.js";
2
+ import { builtInThemes } from "./themes.js";
3
+ import { colorSteps, palettes } from "./tokens/palette.js";
4
+ import { borderWidth, controlHeight, duration, easing, fontSize, fontWeight, lineHeight, opacity, space, zIndex } from "./tokens/scales.js";
5
+ // src/css.ts
6
+ function group(prefix, values, into) {
7
+ for (const [key, value] of Object.entries(values)) into[cssVarName(`${prefix}-${key}`)] = value;
8
+ }
9
+ /** Theme-dependent custom properties for a theme definition. */
10
+ function themeVars(tokens) {
11
+ const vars = {};
12
+ group("color", tokens.colors, vars);
13
+ group("shadow", tokens.shadows, vars);
14
+ group("radius", tokens.radius, vars);
15
+ group("font-family", tokens.fontFamily, vars);
16
+ vars[cssVarName("focus-ring-color")] = tokens.focusRing.color;
17
+ vars[cssVarName("focus-ring-width")] = tokens.focusRing.width;
18
+ vars[cssVarName("focus-ring-offset")] = tokens.focusRing.offset;
19
+ vars[cssVarName("control-border-width")] = tokens.controlBorderWidth;
20
+ return vars;
21
+ }
22
+ /** Theme-independent custom properties (scales, motion, layering, raw palettes). */
23
+ function globalVars() {
24
+ const vars = {};
25
+ group("space", space, vars);
26
+ group("font-size", fontSize, vars);
27
+ group("line-height", lineHeight, vars);
28
+ group("font-weight", fontWeight, vars);
29
+ group("border-width", borderWidth, vars);
30
+ group("control-height", controlHeight, vars);
31
+ group("duration", duration, vars);
32
+ group("easing", easing, vars);
33
+ group("z", zIndex, vars);
34
+ group("opacity", opacity, vars);
35
+ for (const [name, scale] of Object.entries(palettes)) for (const step of colorSteps) vars[cssVarName(`palette-${name}-${step}`)] = scale[step];
36
+ return vars;
37
+ }
38
+ /**
39
+ * Only the variables in which `theme` differs from its built-in base.
40
+ * Used by `ThemeProvider` to keep inline styles for custom themes minimal.
41
+ */
42
+ function themeOverrideVars(theme) {
43
+ const base = themeVars(builtInThemes[theme.base].tokens);
44
+ const own = themeVars(theme.tokens);
45
+ const diff = {};
46
+ for (const [key, value] of Object.entries(own)) if (base[key] !== value) diff[key] = value;
47
+ return diff;
48
+ }
49
+ function block(selector, vars, extra = "") {
50
+ return ` ${selector} {\n${extra}${Object.entries(vars).map(([k, v]) => ` ${k}: ${v};`).join("\n")}\n }`;
51
+ }
52
+ var sel = (name) => `[${THEME_ATTRIBUTE}="${name}"]`;
53
+ /**
54
+ * Generates `theme.css`. Everything is wrapped in the `pl.theme` cascade layer, so any
55
+ * un-layered consumer CSS wins without `!important`.
56
+ */
57
+ function renderThemeCss() {
58
+ const light = themeVars(builtInThemes.light.tokens);
59
+ const dark = themeVars(builtInThemes.dark.tokens);
60
+ const hc = themeVars(builtInThemes["high-contrast"].tokens);
61
+ const root = `[data-pl-root]`;
62
+ const dens = (d) => `[${DENSITY_ATTRIBUTE}="${d}"]`;
63
+ const ch = (k) => cssVarName(`control-height-${k}`);
64
+ const dur = (k) => cssVarName(`duration-${k}`);
65
+ return `/* ReactLoom theme — generated by @reactloom/theme. Do not edit. */
66
+ @layer pl.theme, pl.components;
67
+
68
+ @layer pl.theme {
69
+ ${block(":root, :host", globalVars())}
70
+
71
+ /* Writing direction as a sign (1 / -1) for horizontal transforms. Inheritance resolves the
72
+ nearest dir attribute, like :dir(), but no CSS minifier rewrites it (:dir() is downlevelled
73
+ to a :lang() list for pre-2024 targets). */
74
+ [dir='ltr'] { --pl-dir: 1; }
75
+ [dir='rtl'] { --pl-dir: -1; }
76
+
77
+ ${block(`:root, :host, ${sel("light")}, ${sel("system")}`, light, " color-scheme: light;\n")}
78
+
79
+ ${block(sel("dark"), dark, " color-scheme: dark;\n")}
80
+
81
+ ${block(sel("high-contrast"), hc, " color-scheme: light;\n")}
82
+
83
+ @media (prefers-color-scheme: dark) {
84
+ ${block(sel("system"), dark, " color-scheme: dark;\n")}
85
+ }
86
+
87
+ ${dens("compact")} {
88
+ ${ch("sm")}: 1.5rem;
89
+ ${ch("md")}: 1.75rem;
90
+ ${ch("lg")}: 2.25rem;
91
+ }
92
+
93
+ ${dens("comfortable")} {
94
+ ${ch("sm")}: 2rem;
95
+ ${ch("md")}: 2.25rem;
96
+ ${ch("lg")}: 2.75rem;
97
+ }
98
+
99
+ @media (prefers-reduced-motion: reduce) {
100
+ :root, :host, [${THEME_ATTRIBUTE}] {
101
+ ${dur("fast")}: 0ms;
102
+ ${dur("normal")}: 0ms;
103
+ ${dur("slow")}: 0ms;
104
+ }
105
+ }
106
+
107
+ ${root} {
108
+ color: var(${cssVarName("color-fg-default")});
109
+ background-color: var(${cssVarName("color-bg-canvas")});
110
+ font-family: var(${cssVarName("font-family-sans")});
111
+ font-size: var(${cssVarName("font-size-md")});
112
+ line-height: var(${cssVarName("line-height-normal")});
113
+ -webkit-font-smoothing: antialiased;
114
+ -moz-osx-font-smoothing: grayscale;
115
+ }
116
+
117
+ ${root}[data-pl-transparent] {
118
+ background-color: transparent;
119
+ }
120
+ }
121
+ `;
122
+ }
123
+ export { globalVars, renderThemeCss, themeOverrideVars, themeVars };
124
+
125
+ //# sourceMappingURL=css.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css.js","names":[],"sources":["../src/css.ts"],"sourcesContent":["import { cssVarName, DENSITY_ATTRIBUTE, PREFIX, THEME_ATTRIBUTE } from './prefix.js';\nimport { builtInThemes, type ThemeDefinition, type ThemeTokens } from './themes.js';\nimport { colorSteps, palettes } from './tokens/palette.js';\nimport {\n borderWidth,\n controlHeight,\n duration,\n easing,\n fontSize,\n fontWeight,\n lineHeight,\n opacity,\n space,\n zIndex,\n} from './tokens/scales.js';\n\nexport type CssVars = Record<`--${string}`, string>;\n\nfunction group(prefix: string, values: Readonly<Record<string, string>>, into: CssVars): void {\n for (const [key, value] of Object.entries(values)) into[cssVarName(`${prefix}-${key}`)] = value;\n}\n\n/** Theme-dependent custom properties for a theme definition. */\nexport function themeVars(tokens: ThemeTokens): CssVars {\n const vars: CssVars = {};\n group('color', tokens.colors, vars);\n group('shadow', tokens.shadows, vars);\n group('radius', tokens.radius, vars);\n group('font-family', tokens.fontFamily, vars);\n vars[cssVarName('focus-ring-color')] = tokens.focusRing.color;\n vars[cssVarName('focus-ring-width')] = tokens.focusRing.width;\n vars[cssVarName('focus-ring-offset')] = tokens.focusRing.offset;\n vars[cssVarName('control-border-width')] = tokens.controlBorderWidth;\n return vars;\n}\n\n/** Theme-independent custom properties (scales, motion, layering, raw palettes). */\nexport function globalVars(): CssVars {\n const vars: CssVars = {};\n group('space', space, vars);\n group('font-size', fontSize, vars);\n group('line-height', lineHeight, vars);\n group('font-weight', fontWeight, vars);\n group('border-width', borderWidth, vars);\n group('control-height', controlHeight, vars);\n group('duration', duration, vars);\n group('easing', easing, vars);\n group('z', zIndex, vars);\n group('opacity', opacity, vars);\n for (const [name, scale] of Object.entries(palettes)) {\n for (const step of colorSteps) vars[cssVarName(`palette-${name}-${step}`)] = scale[step];\n }\n return vars;\n}\n\n/**\n * Only the variables in which `theme` differs from its built-in base.\n * Used by `ThemeProvider` to keep inline styles for custom themes minimal.\n */\nexport function themeOverrideVars(theme: ThemeDefinition): CssVars {\n const base = themeVars(builtInThemes[theme.base].tokens);\n const own = themeVars(theme.tokens);\n const diff: CssVars = {};\n for (const [key, value] of Object.entries(own) as Array<[`--${string}`, string]>) {\n if (base[key] !== value) diff[key] = value;\n }\n return diff;\n}\n\nfunction block(selector: string, vars: CssVars, extra = ''): string {\n const body = Object.entries(vars)\n .map(([k, v]) => ` ${k}: ${v};`)\n .join('\\n');\n return ` ${selector} {\\n${extra}${body}\\n }`;\n}\n\nconst sel = (name: string) => `[${THEME_ATTRIBUTE}=\"${name}\"]`;\n\n/**\n * Generates `theme.css`. Everything is wrapped in the `pl.theme` cascade layer, so any\n * un-layered consumer CSS wins without `!important`.\n */\nexport function renderThemeCss(): string {\n const light = themeVars(builtInThemes.light.tokens);\n const dark = themeVars(builtInThemes.dark.tokens);\n const hc = themeVars(builtInThemes['high-contrast'].tokens);\n const root = `[data-${PREFIX}-root]`;\n const dens = (d: string) => `[${DENSITY_ATTRIBUTE}=\"${d}\"]`;\n const ch = (k: string) => cssVarName(`control-height-${k}`);\n const dur = (k: string) => cssVarName(`duration-${k}`);\n\n return `/* ReactLoom theme — generated by @reactloom/theme. Do not edit. */\n@layer ${PREFIX}.theme, ${PREFIX}.components;\n\n@layer ${PREFIX}.theme {\n${block(':root, :host', globalVars())}\n\n /* Writing direction as a sign (1 / -1) for horizontal transforms. Inheritance resolves the\n nearest dir attribute, like :dir(), but no CSS minifier rewrites it (:dir() is downlevelled\n to a :lang() list for pre-2024 targets). */\n [dir='ltr'] { --${PREFIX}-dir: 1; }\n [dir='rtl'] { --${PREFIX}-dir: -1; }\n\n${block(`:root, :host, ${sel('light')}, ${sel('system')}`, light, ' color-scheme: light;\\n')}\n\n${block(sel('dark'), dark, ' color-scheme: dark;\\n')}\n\n${block(sel('high-contrast'), hc, ' color-scheme: light;\\n')}\n\n @media (prefers-color-scheme: dark) {\n ${block(sel('system'), dark, ' color-scheme: dark;\\n')}\n }\n\n ${dens('compact')} {\n ${ch('sm')}: 1.5rem;\n ${ch('md')}: 1.75rem;\n ${ch('lg')}: 2.25rem;\n }\n\n ${dens('comfortable')} {\n ${ch('sm')}: 2rem;\n ${ch('md')}: 2.25rem;\n ${ch('lg')}: 2.75rem;\n }\n\n @media (prefers-reduced-motion: reduce) {\n :root, :host, [${THEME_ATTRIBUTE}] {\n ${dur('fast')}: 0ms;\n ${dur('normal')}: 0ms;\n ${dur('slow')}: 0ms;\n }\n }\n\n ${root} {\n color: var(${cssVarName('color-fg-default')});\n background-color: var(${cssVarName('color-bg-canvas')});\n font-family: var(${cssVarName('font-family-sans')});\n font-size: var(${cssVarName('font-size-md')});\n line-height: var(${cssVarName('line-height-normal')});\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n }\n\n ${root}[data-${PREFIX}-transparent] {\n background-color: transparent;\n }\n}\n`;\n}\n"],"mappings":"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"}
@@ -0,0 +1,10 @@
1
+ export { PREFIX, THEME_ATTRIBUTE, DENSITY_ATTRIBUTE, cssVar, cssVarName } from './prefix.js';
2
+ export { ThemeProvider, useTheme, usePrefersDark, type ThemeProviderProps, type ThemeContextValue, type ThemeInput, type Density, } from './theme-provider.js';
3
+ export { createTheme, type CreateThemeOptions } from './create-theme.js';
4
+ export { lightTheme, darkTheme, highContrastTheme, builtInThemes, checkThemeContrast, contrastRequirements, type ThemeDefinition, type ThemeTokens, type BuiltInThemeName, type ColorScheme, type RadiusName, type ShadowName, type ContrastIssue, } from './themes.js';
5
+ export { contrastRatio, relativeLuminance } from './contrast.js';
6
+ export { renderThemeCss, themeVars, globalVars, themeOverrideVars, type CssVars } from './css.js';
7
+ export { palettes, defaultPalettes, colorSteps, type ColorScale, type ColorStep, type PaletteName, type ThemePalettes, } from './tokens/palette.js';
8
+ export { space, radius, fontFamily, fontSize, lineHeight, fontWeight, borderWidth, controlHeight, duration, easing, zIndex, opacity, breakpoints, type Breakpoint, } from './tokens/scales.js';
9
+ export { statuses, chartColorNames, type Status, type SemanticColorName, type SemanticColors, type ChartColorName } from './tokens/semantic.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,EACL,aAAa,EACb,QAAQ,EACR,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,OAAO,GACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACL,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,aAAa,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,iBAAiB,EAAE,KAAK,OAAO,EAAE,MAAM,UAAU,CAAC;AAClG,OAAO,EACL,QAAQ,EACR,eAAe,EACf,UAAU,EACV,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,aAAa,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,KAAK,EACL,MAAM,EACN,UAAU,EACV,QAAQ,EACR,UAAU,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,QAAQ,EACR,MAAM,EACN,MAAM,EACN,OAAO,EACP,WAAW,EACX,KAAK,UAAU,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,KAAK,MAAM,EAAE,KAAK,iBAAiB,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import { DENSITY_ATTRIBUTE, PREFIX, THEME_ATTRIBUTE, cssVar, cssVarName } from "./prefix.js";
2
+ import { ThemeProvider, usePrefersDark, useTheme } from "./theme-provider.js";
3
+ import { createTheme } from "./create-theme.js";
4
+ import { builtInThemes, checkThemeContrast, contrastRequirements, darkTheme, highContrastTheme, lightTheme } from "./themes.js";
5
+ import { contrastRatio, relativeLuminance } from "./contrast.js";
6
+ import { globalVars, renderThemeCss, themeOverrideVars, themeVars } from "./css.js";
7
+ import { colorSteps, defaultPalettes, palettes } from "./tokens/palette.js";
8
+ import { borderWidth, breakpoints, controlHeight, duration, easing, fontFamily, fontSize, fontWeight, lineHeight, opacity, radius, space, zIndex } from "./tokens/scales.js";
9
+ import { chartColorNames, statuses } from "./tokens/semantic.js";
10
+ export { DENSITY_ATTRIBUTE, PREFIX, THEME_ATTRIBUTE, ThemeProvider, borderWidth, breakpoints, builtInThemes, chartColorNames, checkThemeContrast, colorSteps, contrastRatio, contrastRequirements, controlHeight, createTheme, cssVar, cssVarName, darkTheme, defaultPalettes, duration, easing, fontFamily, fontSize, fontWeight, globalVars, highContrastTheme, lightTheme, lineHeight, opacity, palettes, radius, relativeLuminance, renderThemeCss, space, statuses, themeOverrideVars, themeVars, usePrefersDark, useTheme, zIndex };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Namespace for every CSS custom property, class name and data attribute the library emits.
3
+ * Changing the project name only requires changing this constant (see ADR-0004).
4
+ */
5
+ export declare const PREFIX = "pl";
6
+ /** `cssVarName('color-bg-surface')` → `--pl-color-bg-surface` */
7
+ export declare function cssVarName(token: string): `--${string}`;
8
+ /** `cssVar('color-bg-surface')` → `var(--pl-color-bg-surface)` */
9
+ export declare function cssVar(token: string, fallback?: string): string;
10
+ export declare const THEME_ATTRIBUTE: "data-pl-theme";
11
+ export declare const DENSITY_ATTRIBUTE: "data-pl-density";
12
+ //# sourceMappingURL=prefix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefix.d.ts","sourceRoot":"","sources":["../src/prefix.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,MAAM,OAAO,CAAC;AAE3B,iEAAiE;AACjE,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE,CAEvD;AAED,kEAAkE;AAClE,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAI/D;AAED,eAAO,MAAM,eAAe,iBAAkC,CAAC;AAC/D,eAAO,MAAM,iBAAiB,mBAAoC,CAAC"}
package/dist/prefix.js ADDED
@@ -0,0 +1,19 @@
1
+ // src/prefix.ts
2
+ /**
3
+ * Namespace for every CSS custom property, class name and data attribute the library emits.
4
+ * Changing the project name only requires changing this constant (see ADR-0004).
5
+ */
6
+ var PREFIX = "pl";
7
+ /** `cssVarName('color-bg-surface')` → `--pl-color-bg-surface` */
8
+ function cssVarName(token) {
9
+ return `--pl-${token}`;
10
+ }
11
+ /** `cssVar('color-bg-surface')` → `var(--pl-color-bg-surface)` */
12
+ function cssVar(token, fallback) {
13
+ return fallback === void 0 ? `var(${cssVarName(token)})` : `var(${cssVarName(token)}, ${fallback})`;
14
+ }
15
+ var THEME_ATTRIBUTE = `data-pl-theme`;
16
+ var DENSITY_ATTRIBUTE = `data-pl-density`;
17
+ export { DENSITY_ATTRIBUTE, PREFIX, THEME_ATTRIBUTE, cssVar, cssVarName };
18
+
19
+ //# sourceMappingURL=prefix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefix.js","names":[],"sources":["../src/prefix.ts"],"sourcesContent":["/**\n * Namespace for every CSS custom property, class name and data attribute the library emits.\n * Changing the project name only requires changing this constant (see ADR-0004).\n */\nexport const PREFIX = 'pl';\n\n/** `cssVarName('color-bg-surface')` → `--pl-color-bg-surface` */\nexport function cssVarName(token: string): `--${string}` {\n return `--${PREFIX}-${token}`;\n}\n\n/** `cssVar('color-bg-surface')` → `var(--pl-color-bg-surface)` */\nexport function cssVar(token: string, fallback?: string): string {\n return fallback === undefined\n ? `var(${cssVarName(token)})`\n : `var(${cssVarName(token)}, ${fallback})`;\n}\n\nexport const THEME_ATTRIBUTE = `data-${PREFIX}-theme` as const;\nexport const DENSITY_ATTRIBUTE = `data-${PREFIX}-density` as const;\n"],"mappings":";;;;;AAIA,IAAa,SAAS;;AAGtB,SAAgB,WAAW,OAA8B;CACvD,OAAO,QAAe;AACxB;;AAGA,SAAgB,OAAO,OAAe,UAA2B;CAC/D,OAAO,aAAa,KAAA,IAChB,OAAO,WAAW,KAAK,EAAE,KACzB,OAAO,WAAW,KAAK,EAAE,IAAI,SAAS;AAC5C;AAEA,IAAa,kBAAkB;AAC/B,IAAa,oBAAoB"}
@@ -0,0 +1,39 @@
1
+ import { type HTMLAttributes, type ReactNode } from 'react';
2
+ import { type BuiltInThemeName, type ColorScheme, type ThemeDefinition } from './themes.js';
3
+ /** A built-in theme name, `"system"` (follows the OS), or a `createTheme()` result. */
4
+ export type ThemeInput = BuiltInThemeName | 'system' | ThemeDefinition;
5
+ export type Density = 'compact' | 'default' | 'comfortable';
6
+ export interface ThemeContextValue {
7
+ /** The active theme input (name or definition). */
8
+ theme: ThemeInput;
9
+ /** Resolved theme definition (`system` resolves using the current colour-scheme preference). */
10
+ definition: ThemeDefinition;
11
+ /** Effective colour scheme. On the server, `system` resolves to `"light"`. */
12
+ colorScheme: ColorScheme;
13
+ /** Changes the theme. Calls `onThemeChange`; in uncontrolled mode also updates internal state. */
14
+ setTheme: (theme: ThemeInput) => void;
15
+ density: Density;
16
+ }
17
+ /** Returns `true` when the OS prefers a dark colour scheme (always `false` during SSR). */
18
+ export declare function usePrefersDark(): boolean;
19
+ export interface ThemeProviderProps extends HTMLAttributes<HTMLDivElement> {
20
+ /** Controlled theme. */
21
+ theme?: ThemeInput;
22
+ /** Initial theme when uncontrolled. Defaults to `"light"`. */
23
+ defaultTheme?: ThemeInput;
24
+ /** Called when `setTheme` is invoked. Persist the value here if you need to. */
25
+ onThemeChange?: (theme: ThemeInput) => void;
26
+ /** Control density. Shifts control heights for every component in the scope. */
27
+ density?: Density;
28
+ /** Do not paint the canvas background on the scope element (useful for nested islands). */
29
+ transparent?: boolean;
30
+ children?: ReactNode;
31
+ }
32
+ /**
33
+ * Scopes a theme to its subtree by rendering a wrapper element with `data-pl-theme`.
34
+ * Providers can be nested; they never touch `<html>` or other applications on the page.
35
+ */
36
+ export declare const ThemeProvider: import("react").ForwardRefExoticComponent<ThemeProviderProps & import("react").RefAttributes<HTMLDivElement>>;
37
+ /** Reads the nearest theme scope. Without a provider, returns the light theme with a no-op setter. */
38
+ export declare function useTheme(): ThemeContextValue;
39
+ //# sourceMappingURL=theme-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-provider.d.ts","sourceRoot":"","sources":["../src/theme-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAGf,OAAO,EAAiB,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAE3G,uFAAuF;AACvF,MAAM,MAAM,UAAU,GAAG,gBAAgB,GAAG,QAAQ,GAAG,eAAe,CAAC;AACvE,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,aAAa,CAAC;AAE5D,MAAM,WAAW,iBAAiB;IAChC,mDAAmD;IACnD,KAAK,EAAE,UAAU,CAAC;IAClB,gGAAgG;IAChG,UAAU,EAAE,eAAe,CAAC;IAC5B,8EAA8E;IAC9E,WAAW,EAAE,WAAW,CAAC;IACzB,kGAAkG;IAClG,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IACtC,OAAO,EAAE,OAAO,CAAC;CAClB;AAyBD,2FAA2F;AAC3F,wBAAgB,cAAc,IAAI,OAAO,CAExC;AAeD,MAAM,WAAW,kBAAmB,SAAQ,cAAc,CAAC,cAAc,CAAC;IACxE,wBAAwB;IACxB,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,gFAAgF;IAChF,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAC5C,gFAAgF;IAChF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,2FAA2F;IAC3F,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,+GA6DxB,CAAC;AAEH,sGAAsG;AACtG,wBAAgB,QAAQ,IAAI,iBAAiB,CAE5C"}
@@ -0,0 +1,92 @@
1
+ "use client";
2
+ import { themeOverrideVars } from "./css.js";
3
+ import { DENSITY_ATTRIBUTE, THEME_ATTRIBUTE } from "./prefix.js";
4
+ import { builtInThemes } from "./themes.js";
5
+ import { createContext, forwardRef, useCallback, useContext, useMemo, useState, useSyncExternalStore } from "react";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/theme-provider.tsx
8
+ var noop = () => {};
9
+ var ThemeContext = /*#__PURE__*/ createContext({
10
+ theme: "light",
11
+ definition: builtInThemes.light,
12
+ colorScheme: "light",
13
+ setTheme: noop,
14
+ density: "default"
15
+ });
16
+ var DARK_QUERY = "(prefers-color-scheme: dark)";
17
+ function subscribeToScheme(callback) {
18
+ if (typeof window === "undefined" || !window.matchMedia) return noop;
19
+ const mql = window.matchMedia(DARK_QUERY);
20
+ mql.addEventListener("change", callback);
21
+ return () => mql.removeEventListener("change", callback);
22
+ }
23
+ var getSchemeSnapshot = () => typeof window !== "undefined" && !!window.matchMedia && window.matchMedia(DARK_QUERY).matches;
24
+ var getServerSchemeSnapshot = () => false;
25
+ /** Returns `true` when the OS prefers a dark colour scheme (always `false` during SSR). */
26
+ function usePrefersDark() {
27
+ return useSyncExternalStore(subscribeToScheme, getSchemeSnapshot, getServerSchemeSnapshot);
28
+ }
29
+ function resolve(theme, prefersDark) {
30
+ if (typeof theme === "object") return theme;
31
+ if (theme === "system") return prefersDark ? builtInThemes.dark : builtInThemes.light;
32
+ return builtInThemes[theme];
33
+ }
34
+ /** Converts a custom-property map into a React style object. */
35
+ function varsToStyle(vars) {
36
+ return vars;
37
+ }
38
+ /**
39
+ * Scopes a theme to its subtree by rendering a wrapper element with `data-pl-theme`.
40
+ * Providers can be nested; they never touch `<html>` or other applications on the page.
41
+ */
42
+ var ThemeProvider = /*#__PURE__*/ forwardRef(function ThemeProvider({ theme: themeProp, defaultTheme = "light", onThemeChange, density = "default", transparent = false, style, children, ...rest }, ref) {
43
+ const [uncontrolled, setUncontrolled] = useState(defaultTheme);
44
+ const controlled = themeProp !== void 0;
45
+ const theme = controlled ? themeProp : uncontrolled;
46
+ const definition = resolve(theme, usePrefersDark());
47
+ const setTheme = useCallback((next) => {
48
+ if (!controlled) setUncontrolled(next);
49
+ onThemeChange?.(next);
50
+ }, [controlled, onThemeChange]);
51
+ const overrides = useMemo(() => typeof theme === "object" ? themeOverrideVars(theme) : void 0, [theme]);
52
+ const value = useMemo(() => ({
53
+ theme,
54
+ definition,
55
+ colorScheme: definition.colorScheme,
56
+ setTheme,
57
+ density
58
+ }), [
59
+ theme,
60
+ definition,
61
+ setTheme,
62
+ density
63
+ ]);
64
+ const attributeTheme = typeof theme === "object" ? theme.base : theme;
65
+ const attrs = {
66
+ [THEME_ATTRIBUTE]: attributeTheme,
67
+ [`data-pl-root`]: "",
68
+ [`data-pl-theme-name`]: typeof theme === "object" ? theme.name : void 0,
69
+ [DENSITY_ATTRIBUTE]: density === "default" ? void 0 : density,
70
+ [`data-pl-transparent`]: transparent ? "" : void 0
71
+ };
72
+ return /* @__PURE__ */ jsx(ThemeContext.Provider, {
73
+ value,
74
+ children: /* @__PURE__ */ jsx("div", {
75
+ ref,
76
+ ...attrs,
77
+ ...rest,
78
+ style: overrides ? {
79
+ ...varsToStyle(overrides),
80
+ ...style
81
+ } : style,
82
+ children
83
+ })
84
+ });
85
+ });
86
+ /** Reads the nearest theme scope. Without a provider, returns the light theme with a no-op setter. */
87
+ function useTheme() {
88
+ return useContext(ThemeContext);
89
+ }
90
+ export { ThemeProvider, usePrefersDark, useTheme };
91
+
92
+ //# sourceMappingURL=theme-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-provider.js","names":[],"sources":["../src/theme-provider.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n forwardRef,\n useCallback,\n useContext,\n useMemo,\n useState,\n useSyncExternalStore,\n type CSSProperties,\n type HTMLAttributes,\n type ReactNode,\n} from 'react';\nimport { themeOverrideVars, type CssVars } from './css.js';\nimport { DENSITY_ATTRIBUTE, PREFIX, THEME_ATTRIBUTE } from './prefix.js';\nimport { builtInThemes, type BuiltInThemeName, type ColorScheme, type ThemeDefinition } from './themes.js';\n\n/** A built-in theme name, `\"system\"` (follows the OS), or a `createTheme()` result. */\nexport type ThemeInput = BuiltInThemeName | 'system' | ThemeDefinition;\nexport type Density = 'compact' | 'default' | 'comfortable';\n\nexport interface ThemeContextValue {\n /** The active theme input (name or definition). */\n theme: ThemeInput;\n /** Resolved theme definition (`system` resolves using the current colour-scheme preference). */\n definition: ThemeDefinition;\n /** Effective colour scheme. On the server, `system` resolves to `\"light\"`. */\n colorScheme: ColorScheme;\n /** Changes the theme. Calls `onThemeChange`; in uncontrolled mode also updates internal state. */\n setTheme: (theme: ThemeInput) => void;\n density: Density;\n}\n\nconst noop = () => {};\n\nconst ThemeContext = /*#__PURE__*/ createContext<ThemeContextValue>({\n theme: 'light',\n definition: builtInThemes.light,\n colorScheme: 'light',\n setTheme: noop,\n density: 'default',\n});\n\nconst DARK_QUERY = '(prefers-color-scheme: dark)';\n\nfunction subscribeToScheme(callback: () => void): () => void {\n if (typeof window === 'undefined' || !window.matchMedia) return noop;\n const mql = window.matchMedia(DARK_QUERY);\n mql.addEventListener('change', callback);\n return () => mql.removeEventListener('change', callback);\n}\n\nconst getSchemeSnapshot = (): boolean =>\n typeof window !== 'undefined' && !!window.matchMedia && window.matchMedia(DARK_QUERY).matches;\nconst getServerSchemeSnapshot = (): boolean => false;\n\n/** Returns `true` when the OS prefers a dark colour scheme (always `false` during SSR). */\nexport function usePrefersDark(): boolean {\n return useSyncExternalStore(subscribeToScheme, getSchemeSnapshot, getServerSchemeSnapshot);\n}\n\nfunction resolve(theme: ThemeInput, prefersDark: boolean): ThemeDefinition {\n if (typeof theme === 'object') return theme;\n if (theme === 'system') return prefersDark ? builtInThemes.dark : builtInThemes.light;\n return builtInThemes[theme];\n}\n\n/** Converts a custom-property map into a React style object. */\nfunction varsToStyle(vars: CssVars): CSSProperties {\n // React's CSSProperties type has no index signature for custom properties; the runtime\n // supports them natively. This is the single, intentional widening point.\n return vars as CSSProperties;\n}\n\nexport interface ThemeProviderProps extends HTMLAttributes<HTMLDivElement> {\n /** Controlled theme. */\n theme?: ThemeInput;\n /** Initial theme when uncontrolled. Defaults to `\"light\"`. */\n defaultTheme?: ThemeInput;\n /** Called when `setTheme` is invoked. Persist the value here if you need to. */\n onThemeChange?: (theme: ThemeInput) => void;\n /** Control density. Shifts control heights for every component in the scope. */\n density?: Density;\n /** Do not paint the canvas background on the scope element (useful for nested islands). */\n transparent?: boolean;\n children?: ReactNode;\n}\n\n/**\n * Scopes a theme to its subtree by rendering a wrapper element with `data-pl-theme`.\n * Providers can be nested; they never touch `<html>` or other applications on the page.\n */\nexport const ThemeProvider = /*#__PURE__*/ forwardRef<HTMLDivElement, ThemeProviderProps>(function ThemeProvider(\n {\n theme: themeProp,\n defaultTheme = 'light',\n onThemeChange,\n density = 'default',\n transparent = false,\n style,\n children,\n ...rest\n },\n ref,\n) {\n const [uncontrolled, setUncontrolled] = useState<ThemeInput>(defaultTheme);\n const controlled = themeProp !== undefined;\n const theme = controlled ? themeProp : uncontrolled;\n const prefersDark = usePrefersDark();\n const definition = resolve(theme, prefersDark);\n\n const setTheme = useCallback(\n (next: ThemeInput) => {\n if (!controlled) setUncontrolled(next);\n onThemeChange?.(next);\n },\n [controlled, onThemeChange],\n );\n\n const overrides = useMemo(\n () => (typeof theme === 'object' ? themeOverrideVars(theme) : undefined),\n [theme],\n );\n\n const value = useMemo<ThemeContextValue>(\n () => ({ theme, definition, colorScheme: definition.colorScheme, setTheme, density }),\n [theme, definition, setTheme, density],\n );\n\n // `system` stays as an attribute so the CSS media query (not JS) decides on first paint:\n // server and client markup are identical, so there is no hydration mismatch.\n const attributeTheme = typeof theme === 'object' ? theme.base : theme;\n\n const attrs: Record<string, string | undefined> = {\n [THEME_ATTRIBUTE]: attributeTheme,\n [`data-${PREFIX}-root`]: '',\n [`data-${PREFIX}-theme-name`]: typeof theme === 'object' ? theme.name : undefined,\n [DENSITY_ATTRIBUTE]: density === 'default' ? undefined : density,\n [`data-${PREFIX}-transparent`]: transparent ? '' : undefined,\n };\n\n return (\n <ThemeContext.Provider value={value}>\n <div\n ref={ref}\n {...attrs}\n {...rest}\n style={overrides ? { ...varsToStyle(overrides), ...style } : style}\n >\n {children}\n </div>\n </ThemeContext.Provider>\n );\n});\n\n/** Reads the nearest theme scope. Without a provider, returns the light theme with a no-op setter. */\nexport function useTheme(): ThemeContextValue {\n return useContext(ThemeContext);\n}\n"],"mappings":";;;;;;;AAkCA,IAAM,aAAa,CAAC;AAEpB,IAAM,eAA6B,4BAAiC;CAClE,OAAO;CACP,YAAY,cAAc;CAC1B,aAAa;CACb,UAAU;CACV,SAAS;AACX,CAAC;AAED,IAAM,aAAa;AAEnB,SAAS,kBAAkB,UAAkC;CAC3D,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,YAAY,OAAO;CAChE,MAAM,MAAM,OAAO,WAAW,UAAU;CACxC,IAAI,iBAAiB,UAAU,QAAQ;CACvC,aAAa,IAAI,oBAAoB,UAAU,QAAQ;AACzD;AAEA,IAAM,0BACJ,OAAO,WAAW,eAAe,CAAC,CAAC,OAAO,cAAc,OAAO,WAAW,UAAU,CAAC,CAAC;AACxF,IAAM,gCAAyC;;AAG/C,SAAgB,iBAA0B;CACxC,OAAO,qBAAqB,mBAAmB,mBAAmB,uBAAuB;AAC3F;AAEA,SAAS,QAAQ,OAAmB,aAAuC;CACzE,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,UAAU,UAAU,OAAO,cAAc,cAAc,OAAO,cAAc;CAChF,OAAO,cAAc;AACvB;;AAGA,SAAS,YAAY,MAA8B;CAGjD,OAAO;AACT;;;;;AAoBA,IAAa,gBAA8B,yBAA+C,SAAS,cACjG,EACE,OAAO,WACP,eAAe,SACf,eACA,UAAU,WACV,cAAc,OACd,OACA,UACA,GAAG,QAEL,KACA;CACA,MAAM,CAAC,cAAc,mBAAmB,SAAqB,YAAY;CACzE,MAAM,aAAa,cAAc,KAAA;CACjC,MAAM,QAAQ,aAAa,YAAY;CAEvC,MAAM,aAAa,QAAQ,OADP,eACc,CAAW;CAE7C,MAAM,WAAW,aACd,SAAqB;EACpB,IAAI,CAAC,YAAY,gBAAgB,IAAI;EACrC,gBAAgB,IAAI;CACtB,GACA,CAAC,YAAY,aAAa,CAC5B;CAEA,MAAM,YAAY,cACT,OAAO,UAAU,WAAW,kBAAkB,KAAK,IAAI,KAAA,GAC9D,CAAC,KAAK,CACR;CAEA,MAAM,QAAQ,eACL;EAAE;EAAO;EAAY,aAAa,WAAW;EAAa;EAAU;CAAQ,IACnF;EAAC;EAAO;EAAY;EAAU;CAAO,CACvC;CAIA,MAAM,iBAAiB,OAAO,UAAU,WAAW,MAAM,OAAO;CAEhE,MAAM,QAA4C;GAC/C,kBAAkB;GAClB,iBAAwB;GACxB,uBAA8B,OAAO,UAAU,WAAW,MAAM,OAAO,KAAA;GACvE,oBAAoB,YAAY,YAAY,KAAA,IAAY;GACxD,wBAA+B,cAAc,KAAK,KAAA;CACrD;CAEA,OACE,oBAAC,aAAa,UAAd;EAA8B;EAC5B,UAAA,oBAAC,OAAD;GACO;GACL,GAAI;GACJ,GAAI;GACJ,OAAO,YAAY;IAAE,GAAG,YAAY,SAAS;IAAG,GAAG;GAAM,IAAI;GAE5D;EACE,CAAA;CACgB,CAAA;AAE3B,CAAC;;AAGD,SAAgB,WAA8B;CAC5C,OAAO,WAAW,YAAY;AAChC"}