@sparkwire/system 0.0.0-stage → 0.2.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.
@@ -0,0 +1,179 @@
1
+ import { ThemeColors, BaseTheme, DeepPartial, Theme as Theme$1 } from '@sparkwire/styles';
2
+ import react, { ReactNode } from 'react';
3
+
4
+ interface BreakpointsOptions {
5
+ values?: {
6
+ xs?: number;
7
+ sm?: number;
8
+ md?: number;
9
+ lg?: number;
10
+ xl?: number;
11
+ };
12
+ }
13
+ declare function createBreakpoints(breakpoints?: BreakpointsOptions): {
14
+ values: {
15
+ xs: number;
16
+ sm: number;
17
+ md: number;
18
+ lg: number;
19
+ xl: number;
20
+ };
21
+ up: (key: "xs" | "sm" | "md" | "lg" | "xl") => string;
22
+ down: (key: "xs" | "sm" | "md" | "lg" | "xl") => string;
23
+ };
24
+
25
+ interface PaletteOptions {
26
+ brand?: ThemeColors['primary']['brand'];
27
+ error?: ThemeColors['primary']['error'];
28
+ warning?: ThemeColors['primary']['warning'];
29
+ success?: ThemeColors['primary']['success'];
30
+ }
31
+ declare function createPalette(palette?: PaletteOptions): {
32
+ brand: string | {
33
+ '25': string;
34
+ '50': string;
35
+ '100': string;
36
+ '200': string;
37
+ '300': string;
38
+ '400': string;
39
+ '500': string;
40
+ '600': string;
41
+ '700': string;
42
+ '800': string;
43
+ '900': string;
44
+ };
45
+ error: string | {
46
+ '25': string;
47
+ '50': string;
48
+ '100': string;
49
+ '200': string;
50
+ '300': string;
51
+ '400': string;
52
+ '500': string;
53
+ '600': string;
54
+ '700': string;
55
+ '800': string;
56
+ '900': string;
57
+ };
58
+ warning: string | {
59
+ '25': string;
60
+ '50': string;
61
+ '100': string;
62
+ '200': string;
63
+ '300': string;
64
+ '400': string;
65
+ '500': string;
66
+ '600': string;
67
+ '700': string;
68
+ '800': string;
69
+ '900': string;
70
+ };
71
+ success: string | {
72
+ '25': string;
73
+ '50': string;
74
+ '100': string;
75
+ '200': string;
76
+ '300': string;
77
+ '400': string;
78
+ '500': string;
79
+ '600': string;
80
+ '700': string;
81
+ '800': string;
82
+ '900': string;
83
+ };
84
+ };
85
+
86
+ interface ShadowsOptions {
87
+ shadow1?: string;
88
+ shadow2?: string;
89
+ shadow3?: string;
90
+ shadow4?: string;
91
+ shadow5?: string;
92
+ }
93
+ declare function createShadows(shadows?: ShadowsOptions): {
94
+ shadow1: string;
95
+ shadow2: string;
96
+ shadow3: string;
97
+ shadow4: string;
98
+ shadow5: string;
99
+ };
100
+
101
+ interface SpacingOptions {
102
+ unit?: number;
103
+ }
104
+ declare function createSpacing(spacing?: SpacingOptions): (factor: number) => string;
105
+
106
+ interface TypographyOptions {
107
+ fontFamily?: string;
108
+ fontSize?: string;
109
+ fontWeightLight?: number;
110
+ fontWeightRegular?: number;
111
+ fontWeightMedium?: number;
112
+ fontWeightBold?: number;
113
+ }
114
+ declare function createTypography(typography?: TypographyOptions): {
115
+ fontFamily: string;
116
+ fontSize: string;
117
+ fontWeightLight: number;
118
+ fontWeightRegular: number;
119
+ fontWeightMedium: number;
120
+ fontWeightBold: number;
121
+ };
122
+
123
+ interface ThemeOptions {
124
+ palette?: PaletteOptions;
125
+ typography?: TypographyOptions;
126
+ spacing?: SpacingOptions;
127
+ breakpoints?: BreakpointsOptions;
128
+ shadows?: ShadowsOptions;
129
+ }
130
+ interface Theme {
131
+ palette: ReturnType<typeof createPalette>;
132
+ typography: ReturnType<typeof createTypography>;
133
+ spacing: ReturnType<typeof createSpacing>;
134
+ breakpoints: ReturnType<typeof createBreakpoints>;
135
+ shadows: ReturnType<typeof createShadows>;
136
+ }
137
+ declare function export_default(options?: ThemeOptions): Theme;
138
+
139
+ type SparkMode = 'dark' | 'light' | 'system';
140
+ interface ThemeContextProps {
141
+ /** The resolved theme as JS values, for charts, canvas and other non-CSS uses. */
142
+ theme: BaseTheme;
143
+ mode: SparkMode;
144
+ resolvedMode: 'dark' | 'light';
145
+ setMode: (mode: SparkMode) => void;
146
+ toggleTheme: () => void;
147
+ }
148
+ /**
149
+ * Read the current theme values and mode. Works without a ThemeProvider
150
+ * (returns the default dark Live Wire theme).
151
+ */
152
+ declare const useTheme: () => ThemeContextProps;
153
+
154
+ interface ThemeProviderProps {
155
+ children: ReactNode;
156
+ /**
157
+ * Colour mode. `system` follows the operating system. Components read
158
+ * CSS variables, so this works without the provider too: set
159
+ * `data-spark-theme="light"` on any element (e.g. `<html>`).
160
+ */
161
+ mode?: SparkMode;
162
+ /** Start in this mode but let `setMode` change it (uncontrolled). */
163
+ defaultMode?: SparkMode;
164
+ /** Change only the tokens you need; the rest keep their Live Wire values. */
165
+ theme?: DeepPartial<Theme$1>;
166
+ /** @deprecated Pass `theme` instead. A full theme object is still accepted. */
167
+ initialTheme?: BaseTheme;
168
+ /** Wrapper element's class, e.g. for a font or background. */
169
+ className?: string;
170
+ }
171
+ /**
172
+ * Optional. Spark UI components are styled by `@sparkwire/core/styles.css`
173
+ * and its CSS variables, so they render correctly without any provider
174
+ * (including in React Server Components). Use the provider to switch modes
175
+ * at runtime, or to apply token overrides to a part of the page.
176
+ */
177
+ declare const ThemeProvider: react.FC<ThemeProviderProps>;
178
+
179
+ export { type BreakpointsOptions, type PaletteOptions, type ShadowsOptions, type SpacingOptions, type SparkMode, type Theme, type ThemeOptions, ThemeProvider, type ThemeProviderProps, type TypographyOptions, createBreakpoints, createPalette, createShadows, createSpacing, export_default as createTheme, createTypography, useTheme };
@@ -0,0 +1,179 @@
1
+ import { ThemeColors, BaseTheme, DeepPartial, Theme as Theme$1 } from '@sparkwire/styles';
2
+ import react, { ReactNode } from 'react';
3
+
4
+ interface BreakpointsOptions {
5
+ values?: {
6
+ xs?: number;
7
+ sm?: number;
8
+ md?: number;
9
+ lg?: number;
10
+ xl?: number;
11
+ };
12
+ }
13
+ declare function createBreakpoints(breakpoints?: BreakpointsOptions): {
14
+ values: {
15
+ xs: number;
16
+ sm: number;
17
+ md: number;
18
+ lg: number;
19
+ xl: number;
20
+ };
21
+ up: (key: "xs" | "sm" | "md" | "lg" | "xl") => string;
22
+ down: (key: "xs" | "sm" | "md" | "lg" | "xl") => string;
23
+ };
24
+
25
+ interface PaletteOptions {
26
+ brand?: ThemeColors['primary']['brand'];
27
+ error?: ThemeColors['primary']['error'];
28
+ warning?: ThemeColors['primary']['warning'];
29
+ success?: ThemeColors['primary']['success'];
30
+ }
31
+ declare function createPalette(palette?: PaletteOptions): {
32
+ brand: string | {
33
+ '25': string;
34
+ '50': string;
35
+ '100': string;
36
+ '200': string;
37
+ '300': string;
38
+ '400': string;
39
+ '500': string;
40
+ '600': string;
41
+ '700': string;
42
+ '800': string;
43
+ '900': string;
44
+ };
45
+ error: string | {
46
+ '25': string;
47
+ '50': string;
48
+ '100': string;
49
+ '200': string;
50
+ '300': string;
51
+ '400': string;
52
+ '500': string;
53
+ '600': string;
54
+ '700': string;
55
+ '800': string;
56
+ '900': string;
57
+ };
58
+ warning: string | {
59
+ '25': string;
60
+ '50': string;
61
+ '100': string;
62
+ '200': string;
63
+ '300': string;
64
+ '400': string;
65
+ '500': string;
66
+ '600': string;
67
+ '700': string;
68
+ '800': string;
69
+ '900': string;
70
+ };
71
+ success: string | {
72
+ '25': string;
73
+ '50': string;
74
+ '100': string;
75
+ '200': string;
76
+ '300': string;
77
+ '400': string;
78
+ '500': string;
79
+ '600': string;
80
+ '700': string;
81
+ '800': string;
82
+ '900': string;
83
+ };
84
+ };
85
+
86
+ interface ShadowsOptions {
87
+ shadow1?: string;
88
+ shadow2?: string;
89
+ shadow3?: string;
90
+ shadow4?: string;
91
+ shadow5?: string;
92
+ }
93
+ declare function createShadows(shadows?: ShadowsOptions): {
94
+ shadow1: string;
95
+ shadow2: string;
96
+ shadow3: string;
97
+ shadow4: string;
98
+ shadow5: string;
99
+ };
100
+
101
+ interface SpacingOptions {
102
+ unit?: number;
103
+ }
104
+ declare function createSpacing(spacing?: SpacingOptions): (factor: number) => string;
105
+
106
+ interface TypographyOptions {
107
+ fontFamily?: string;
108
+ fontSize?: string;
109
+ fontWeightLight?: number;
110
+ fontWeightRegular?: number;
111
+ fontWeightMedium?: number;
112
+ fontWeightBold?: number;
113
+ }
114
+ declare function createTypography(typography?: TypographyOptions): {
115
+ fontFamily: string;
116
+ fontSize: string;
117
+ fontWeightLight: number;
118
+ fontWeightRegular: number;
119
+ fontWeightMedium: number;
120
+ fontWeightBold: number;
121
+ };
122
+
123
+ interface ThemeOptions {
124
+ palette?: PaletteOptions;
125
+ typography?: TypographyOptions;
126
+ spacing?: SpacingOptions;
127
+ breakpoints?: BreakpointsOptions;
128
+ shadows?: ShadowsOptions;
129
+ }
130
+ interface Theme {
131
+ palette: ReturnType<typeof createPalette>;
132
+ typography: ReturnType<typeof createTypography>;
133
+ spacing: ReturnType<typeof createSpacing>;
134
+ breakpoints: ReturnType<typeof createBreakpoints>;
135
+ shadows: ReturnType<typeof createShadows>;
136
+ }
137
+ declare function export_default(options?: ThemeOptions): Theme;
138
+
139
+ type SparkMode = 'dark' | 'light' | 'system';
140
+ interface ThemeContextProps {
141
+ /** The resolved theme as JS values, for charts, canvas and other non-CSS uses. */
142
+ theme: BaseTheme;
143
+ mode: SparkMode;
144
+ resolvedMode: 'dark' | 'light';
145
+ setMode: (mode: SparkMode) => void;
146
+ toggleTheme: () => void;
147
+ }
148
+ /**
149
+ * Read the current theme values and mode. Works without a ThemeProvider
150
+ * (returns the default dark Live Wire theme).
151
+ */
152
+ declare const useTheme: () => ThemeContextProps;
153
+
154
+ interface ThemeProviderProps {
155
+ children: ReactNode;
156
+ /**
157
+ * Colour mode. `system` follows the operating system. Components read
158
+ * CSS variables, so this works without the provider too: set
159
+ * `data-spark-theme="light"` on any element (e.g. `<html>`).
160
+ */
161
+ mode?: SparkMode;
162
+ /** Start in this mode but let `setMode` change it (uncontrolled). */
163
+ defaultMode?: SparkMode;
164
+ /** Change only the tokens you need; the rest keep their Live Wire values. */
165
+ theme?: DeepPartial<Theme$1>;
166
+ /** @deprecated Pass `theme` instead. A full theme object is still accepted. */
167
+ initialTheme?: BaseTheme;
168
+ /** Wrapper element's class, e.g. for a font or background. */
169
+ className?: string;
170
+ }
171
+ /**
172
+ * Optional. Spark UI components are styled by `@sparkwire/core/styles.css`
173
+ * and its CSS variables, so they render correctly without any provider
174
+ * (including in React Server Components). Use the provider to switch modes
175
+ * at runtime, or to apply token overrides to a part of the page.
176
+ */
177
+ declare const ThemeProvider: react.FC<ThemeProviderProps>;
178
+
179
+ export { type BreakpointsOptions, type PaletteOptions, type ShadowsOptions, type SpacingOptions, type SparkMode, type Theme, type ThemeOptions, ThemeProvider, type ThemeProviderProps, type TypographyOptions, createBreakpoints, createPalette, createShadows, createSpacing, export_default as createTheme, createTypography, useTheme };
package/dist/index.js ADDED
@@ -0,0 +1,190 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ ThemeProvider: () => ThemeProvider,
25
+ createBreakpoints: () => createBreakpoints,
26
+ createPalette: () => createPalette,
27
+ createShadows: () => createShadows,
28
+ createSpacing: () => createSpacing,
29
+ createTheme: () => createTheme_default,
30
+ createTypography: () => createTypography,
31
+ useTheme: () => useTheme
32
+ });
33
+ module.exports = __toCommonJS(src_exports);
34
+
35
+ // src/createTheme/createTheme.ts
36
+ function createTheme_default(options = {}) {
37
+ const palette = createPalette(options.palette);
38
+ const typography = createTypography(options.typography);
39
+ const spacing = createSpacing(options.spacing);
40
+ const breakpoints = createBreakpoints(options.breakpoints);
41
+ const shadows = createShadows(options.shadows);
42
+ return {
43
+ palette,
44
+ typography,
45
+ spacing,
46
+ breakpoints,
47
+ shadows
48
+ };
49
+ }
50
+
51
+ // src/createTheme/breakpoints.ts
52
+ function createBreakpoints(breakpoints = {}) {
53
+ const defaultValues = {
54
+ xs: 0,
55
+ sm: 600,
56
+ md: 960,
57
+ lg: 1280,
58
+ xl: 1920
59
+ };
60
+ const values = { ...defaultValues, ...breakpoints.values };
61
+ return {
62
+ values,
63
+ up: (key) => `@media (min-width:${values[key]}px)`,
64
+ down: (key) => `@media (max-width:${values[key]}px)`
65
+ };
66
+ }
67
+
68
+ // src/createTheme/palette.ts
69
+ function createPalette(palette = {}) {
70
+ var _a, _b, _c, _d;
71
+ return {
72
+ brand: (_a = palette.brand) != null ? _a : "#1976d2",
73
+ error: (_b = palette.error) != null ? _b : "#f44336",
74
+ warning: (_c = palette.warning) != null ? _c : "#ff9800",
75
+ success: (_d = palette.success) != null ? _d : "#4caf50"
76
+ };
77
+ }
78
+
79
+ // src/createTheme/shadows.ts
80
+ function createShadows(shadows = {}) {
81
+ var _a, _b, _c, _d, _e;
82
+ return {
83
+ shadow1: (_a = shadows.shadow1) != null ? _a : "0px 1px 3px rgba(0, 0, 0, 0.2), 0px 1px 1px rgba(0, 0, 0, 0.14), 0px 2px 1px -1px rgba(0, 0, 0, 0.12)",
84
+ shadow2: (_b = shadows.shadow2) != null ? _b : "0px 1px 5px rgba(0, 0, 0, 0.2), 0px 2px 2px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)",
85
+ shadow3: (_c = shadows.shadow3) != null ? _c : "0px 1px 8px rgba(0, 0, 0, 0.2), 0px 3px 4px rgba(0, 0, 0, 0.14), 0px 3px 3px -2px rgba(0, 0, 0, 0.12)",
86
+ shadow4: (_d = shadows.shadow4) != null ? _d : "0px 2px 4px -1px rgba(0, 0, 0, 0.2), 0px 4px 5px rgba(0, 0, 0, 0.14), 0px 1px 10px rgba(0, 0, 0, 0.12)",
87
+ shadow5: (_e = shadows.shadow5) != null ? _e : "0px 3px 5px -1px rgba(0, 0, 0, 0.2), 0px 5px 8px rgba(0, 0, 0, 0.14), 0px 1px 14px rgba(0, 0, 0, 0.12)"
88
+ };
89
+ }
90
+
91
+ // src/createTheme/spacing.ts
92
+ function createSpacing(spacing = {}) {
93
+ var _a;
94
+ const unit = (_a = spacing.unit) != null ? _a : 8;
95
+ return (factor) => `${unit * factor}px`;
96
+ }
97
+
98
+ // src/createTheme/typography.ts
99
+ function createTypography(typography = {}) {
100
+ var _a, _b, _c, _d, _e, _f;
101
+ return {
102
+ fontFamily: (_a = typography.fontFamily) != null ? _a : '"Roboto", "Helvetica", "Arial", sans-serif',
103
+ fontSize: (_b = typography.fontSize) != null ? _b : "14px",
104
+ fontWeightLight: (_c = typography.fontWeightLight) != null ? _c : 300,
105
+ fontWeightRegular: (_d = typography.fontWeightRegular) != null ? _d : 400,
106
+ fontWeightMedium: (_e = typography.fontWeightMedium) != null ? _e : 500,
107
+ fontWeightBold: (_f = typography.fontWeightBold) != null ? _f : 700
108
+ };
109
+ }
110
+
111
+ // src/ThemeProvider/ThemeContext.tsx
112
+ var import_react = require("react");
113
+ var import_styles = require("@sparkwire/styles");
114
+ var fallback = {
115
+ theme: import_styles.defaultTheme,
116
+ mode: "dark",
117
+ resolvedMode: "dark",
118
+ setMode: () => {
119
+ },
120
+ toggleTheme: () => {
121
+ }
122
+ };
123
+ var ThemeContext = (0, import_react.createContext)(fallback);
124
+ var useTheme = () => (0, import_react.useContext)(ThemeContext);
125
+ var ThemeContext_default = ThemeContext;
126
+
127
+ // src/ThemeProvider/ThemeProvider.tsx
128
+ var import_react2 = require("react");
129
+ var import_styles2 = require("@sparkwire/styles");
130
+ var import_jsx_runtime = require("react/jsx-runtime");
131
+ var usePrefersLight = () => {
132
+ const [light, setLight] = (0, import_react2.useState)(false);
133
+ (0, import_react2.useEffect)(() => {
134
+ var _a;
135
+ if (typeof window === "undefined" || !window.matchMedia) return;
136
+ const mq = window.matchMedia("(prefers-color-scheme: light)");
137
+ const update = () => setLight(mq.matches);
138
+ update();
139
+ (_a = mq.addEventListener) == null ? void 0 : _a.call(mq, "change", update);
140
+ return () => {
141
+ var _a2;
142
+ return (_a2 = mq.removeEventListener) == null ? void 0 : _a2.call(mq, "change", update);
143
+ };
144
+ }, []);
145
+ return light;
146
+ };
147
+ var ThemeProvider = ({
148
+ children,
149
+ mode,
150
+ defaultMode = "dark",
151
+ theme: overrides,
152
+ initialTheme,
153
+ className
154
+ }) => {
155
+ const [innerMode, setInnerMode] = (0, import_react2.useState)(defaultMode);
156
+ const activeMode = mode != null ? mode : innerMode;
157
+ const prefersLight = usePrefersLight();
158
+ const resolved = activeMode === "system" ? prefersLight ? "light" : "dark" : activeMode;
159
+ const theme = (0, import_react2.useMemo)(() => {
160
+ if (initialTheme && !overrides) return initialTheme;
161
+ return (0, import_styles2.createTheme)(overrides, resolved);
162
+ }, [initialTheme, overrides, resolved]);
163
+ const style = (0, import_react2.useMemo)(() => {
164
+ if (!overrides && !initialTheme) return void 0;
165
+ return { ...(0, import_styles2.themeToCssVars)(theme), display: "contents" };
166
+ }, [overrides, initialTheme, theme]);
167
+ const value = (0, import_react2.useMemo)(
168
+ () => ({
169
+ theme,
170
+ mode: activeMode,
171
+ resolvedMode: resolved,
172
+ setMode: setInnerMode,
173
+ toggleTheme: () => setInnerMode((m) => m === "light" ? "dark" : "light")
174
+ }),
175
+ [theme, activeMode, resolved]
176
+ );
177
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ThemeContext_default.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "data-spark-theme": activeMode, className, style: style != null ? style : { display: "contents" }, children }) });
178
+ };
179
+ // Annotate the CommonJS export names for ESM import in node:
180
+ 0 && (module.exports = {
181
+ ThemeProvider,
182
+ createBreakpoints,
183
+ createPalette,
184
+ createShadows,
185
+ createSpacing,
186
+ createTheme,
187
+ createTypography,
188
+ useTheme
189
+ });
190
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/createTheme/createTheme.ts","../src/createTheme/breakpoints.ts","../src/createTheme/palette.ts","../src/createTheme/shadows.ts","../src/createTheme/spacing.ts","../src/createTheme/typography.ts","../src/ThemeProvider/ThemeContext.tsx","../src/ThemeProvider/ThemeProvider.tsx"],"sourcesContent":["export * from './createTheme';\nexport * from './ThemeProvider';","import {\n PaletteOptions,\n TypographyOptions,\n SpacingOptions,\n BreakpointsOptions,\n ShadowsOptions,\n createPalette,\n createTypography,\n createSpacing,\n createBreakpoints,\n createShadows,\n} from '.';\n\nexport interface ThemeOptions {\n palette?: PaletteOptions;\n typography?: TypographyOptions;\n spacing?: SpacingOptions;\n breakpoints?: BreakpointsOptions;\n shadows?: ShadowsOptions;\n}\n\nexport interface Theme {\n palette: ReturnType<typeof createPalette>;\n typography: ReturnType<typeof createTypography>;\n spacing: ReturnType<typeof createSpacing>;\n breakpoints: ReturnType<typeof createBreakpoints>;\n shadows: ReturnType<typeof createShadows>;\n}\n\nexport default function (options: ThemeOptions = {}): Theme {\n const palette = createPalette(options.palette);\n const typography = createTypography(options.typography);\n const spacing = createSpacing(options.spacing);\n const breakpoints = createBreakpoints(options.breakpoints);\n const shadows = createShadows(options.shadows);\n\n return {\n palette,\n typography,\n spacing,\n breakpoints,\n shadows,\n };\n}\n","export interface BreakpointsOptions {\n values?: {\n xs?: number;\n sm?: number;\n md?: number;\n lg?: number;\n xl?: number;\n };\n}\n\nexport function createBreakpoints(breakpoints: BreakpointsOptions = {}) {\n const defaultValues = {\n xs: 0,\n sm: 600,\n md: 960,\n lg: 1280,\n xl: 1920,\n };\n\n const values = { ...defaultValues, ...breakpoints.values };\n\n return {\n values,\n up: (key: keyof typeof values) => `@media (min-width:${values[key]}px)`,\n down: (key: keyof typeof values) => `@media (max-width:${values[key]}px)`,\n };\n}\n","import { ThemeColors } from \"@sparkwire/styles\";\n\nexport interface PaletteOptions {\n brand?: ThemeColors['primary']['brand'];\n error?: ThemeColors['primary']['error'];\n warning?: ThemeColors['primary']['warning'];\n success?: ThemeColors['primary']['success'];\n}\n\nexport function createPalette(palette: PaletteOptions = {}) {\n return {\n brand: palette.brand ?? '#1976d2',\n error: palette.error ?? '#f44336',\n warning: palette.warning ?? '#ff9800',\n success: palette.success ?? '#4caf50',\n };\n}\n","export interface ShadowsOptions {\n shadow1?: string;\n shadow2?: string;\n shadow3?: string;\n shadow4?: string;\n shadow5?: string;\n}\n\nexport function createShadows(shadows: ShadowsOptions = {}) {\n return {\n shadow1: shadows.shadow1 ?? '0px 1px 3px rgba(0, 0, 0, 0.2), 0px 1px 1px rgba(0, 0, 0, 0.14), 0px 2px 1px -1px rgba(0, 0, 0, 0.12)',\n shadow2: shadows.shadow2 ?? '0px 1px 5px rgba(0, 0, 0, 0.2), 0px 2px 2px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)',\n shadow3: shadows.shadow3 ?? '0px 1px 8px rgba(0, 0, 0, 0.2), 0px 3px 4px rgba(0, 0, 0, 0.14), 0px 3px 3px -2px rgba(0, 0, 0, 0.12)',\n shadow4: shadows.shadow4 ?? '0px 2px 4px -1px rgba(0, 0, 0, 0.2), 0px 4px 5px rgba(0, 0, 0, 0.14), 0px 1px 10px rgba(0, 0, 0, 0.12)',\n shadow5: shadows.shadow5 ?? '0px 3px 5px -1px rgba(0, 0, 0, 0.2), 0px 5px 8px rgba(0, 0, 0, 0.14), 0px 1px 14px rgba(0, 0, 0, 0.12)',\n };\n}\n","export interface SpacingOptions {\n unit?: number;\n}\n\nexport function createSpacing(spacing: SpacingOptions = {}) {\n const unit = spacing.unit ?? 8;\n\n return (factor: number) => `${unit * factor}px`;\n}\n","export interface TypographyOptions {\n fontFamily?: string;\n fontSize?: string;\n fontWeightLight?: number;\n fontWeightRegular?: number;\n fontWeightMedium?: number;\n fontWeightBold?: number;\n}\n\nexport function createTypography(typography: TypographyOptions = {}) {\n return {\n fontFamily: typography.fontFamily ?? '\"Roboto\", \"Helvetica\", \"Arial\", sans-serif',\n fontSize: typography.fontSize ?? '14px',\n fontWeightLight: typography.fontWeightLight ?? 300,\n fontWeightRegular: typography.fontWeightRegular ?? 400,\n fontWeightMedium: typography.fontWeightMedium ?? 500,\n fontWeightBold: typography.fontWeightBold ?? 700,\n };\n}\n","import { createContext, useContext } from 'react';\nimport { BaseTheme, defaultTheme } from '@sparkwire/styles';\n\nexport type SparkMode = 'dark' | 'light' | 'system';\n\ninterface ThemeContextProps {\n /** The resolved theme as JS values, for charts, canvas and other non-CSS uses. */\n theme: BaseTheme;\n mode: SparkMode;\n resolvedMode: 'dark' | 'light';\n setMode: (mode: SparkMode) => void;\n toggleTheme: () => void;\n}\n\nconst fallback: ThemeContextProps = {\n theme: defaultTheme as BaseTheme,\n mode: 'dark',\n resolvedMode: 'dark',\n setMode: () => {},\n toggleTheme: () => {},\n};\n\nconst ThemeContext = createContext<ThemeContextProps>(fallback);\n\n/**\n * Read the current theme values and mode. Works without a ThemeProvider\n * (returns the default dark Live Wire theme).\n */\nexport const useTheme = (): ThemeContextProps => useContext(ThemeContext);\n\nexport default ThemeContext;\n","import React, { ReactNode, useEffect, useMemo, useState } from 'react';\nimport ThemeContext, { SparkMode } from './ThemeContext';\nimport { BaseTheme, DeepPartial, Theme, createTheme, defaultTheme, lightTheme, themeToCssVars } from '@sparkwire/styles';\n\nexport interface ThemeProviderProps {\n children: ReactNode;\n /**\n * Colour mode. `system` follows the operating system. Components read\n * CSS variables, so this works without the provider too: set\n * `data-spark-theme=\"light\"` on any element (e.g. `<html>`).\n */\n mode?: SparkMode;\n /** Start in this mode but let `setMode` change it (uncontrolled). */\n defaultMode?: SparkMode;\n /** Change only the tokens you need; the rest keep their Live Wire values. */\n theme?: DeepPartial<Theme>;\n /** @deprecated Pass `theme` instead. A full theme object is still accepted. */\n initialTheme?: BaseTheme;\n /** Wrapper element's class, e.g. for a font or background. */\n className?: string;\n}\n\nconst usePrefersLight = () => {\n const [light, setLight] = useState(false);\n useEffect(() => {\n if (typeof window === 'undefined' || !window.matchMedia) return;\n const mq = window.matchMedia('(prefers-color-scheme: light)');\n const update = () => setLight(mq.matches);\n update();\n mq.addEventListener?.('change', update);\n return () => mq.removeEventListener?.('change', update);\n }, []);\n return light;\n};\n\n/**\n * Optional. Spark UI components are styled by `@sparkwire/core/styles.css`\n * and its CSS variables, so they render correctly without any provider\n * (including in React Server Components). Use the provider to switch modes\n * at runtime, or to apply token overrides to a part of the page.\n */\nexport const ThemeProvider: React.FC<ThemeProviderProps> = ({\n children,\n mode,\n defaultMode = 'dark',\n theme: overrides,\n initialTheme,\n className,\n}) => {\n const [innerMode, setInnerMode] = useState<SparkMode>(defaultMode);\n const activeMode = mode ?? innerMode;\n const prefersLight = usePrefersLight();\n const resolved: Theme['mode'] =\n activeMode === 'system' ? (prefersLight ? 'light' : 'dark') : activeMode;\n\n const theme = useMemo<BaseTheme>(() => {\n if (initialTheme && !overrides) return initialTheme;\n return createTheme(overrides, resolved) as BaseTheme;\n }, [initialTheme, overrides, resolved]);\n\n // Only emit inline variables when the app overrides tokens.\n const style = useMemo(() => {\n if (!overrides && !initialTheme) return undefined;\n return { ...themeToCssVars(theme), display: 'contents' } as React.CSSProperties;\n }, [overrides, initialTheme, theme]);\n\n const value = useMemo(\n () => ({\n theme,\n mode: activeMode,\n resolvedMode: resolved,\n setMode: setInnerMode,\n toggleTheme: () => setInnerMode((m) => (m === 'light' ? 'dark' : 'light')),\n }),\n [theme, activeMode, resolved],\n );\n\n return (\n <ThemeContext.Provider value={value}>\n <div data-spark-theme={activeMode} className={className} style={style ?? { display: 'contents' }}>\n {children}\n </div>\n </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AA8BiB,cAAAA,MAAA,GAAG,wBAAH,gBAAAA,IAAA,SAAyB,UAAU;AAAA;AAAA,EAClD,GAAG,CAAC,CAAC;AACL,SAAO;AACT;AAQO,IAAM,gBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,OAAO;AAAA,EACP;AAAA,EACA;AACF,MAAM;AACJ,QAAM,CAAC,WAAW,YAAY,QAAI,wBAAoB,WAAW;AACjE,QAAM,aAAa,sBAAQ;AAC3B,QAAM,eAAe,gBAAgB;AACrC,QAAM,WACJ,eAAe,WAAY,eAAe,UAAU,SAAU;AAEhE,QAAM,YAAQ,uBAAmB,MAAM;AACrC,QAAI,gBAAgB,CAAC,UAAW,QAAO;AACvC,eAAO,4BAAY,WAAW,QAAQ;AAAA,EACxC,GAAG,CAAC,cAAc,WAAW,QAAQ,CAAC;AAGtC,QAAM,YAAQ,uBAAQ,MAAM;AAC1B,QAAI,CAAC,aAAa,CAAC,aAAc,QAAO;AACxC,WAAO,EAAE,OAAG,+BAAe,KAAK,GAAG,SAAS,WAAW;AAAA,EACzD,GAAG,CAAC,WAAW,cAAc,KAAK,CAAC;AAEnC,QAAM,YAAQ;AAAA,IACZ,OAAO;AAAA,MACL;AAAA,MACA,MAAM;AAAA,MACN,cAAc;AAAA,MACd,SAAS;AAAA,MACT,aAAa,MAAM,aAAa,CAAC,MAAO,MAAM,UAAU,SAAS,OAAQ;AAAA,IAC3E;AAAA,IACA,CAAC,OAAO,YAAY,QAAQ;AAAA,EAC9B;AAEA,SACE,4CAAC,qBAAa,UAAb,EAAsB,OACrB,sDAAC,SAAI,oBAAkB,YAAY,WAAsB,OAAO,wBAAS,EAAE,SAAS,WAAW,GAC5F,UACH,GACF;AAEJ;","names":["import_react","import_styles","_a"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,157 @@
1
+ "use client";
2
+
3
+ // src/createTheme/createTheme.ts
4
+ function createTheme_default(options = {}) {
5
+ const palette = createPalette(options.palette);
6
+ const typography = createTypography(options.typography);
7
+ const spacing = createSpacing(options.spacing);
8
+ const breakpoints = createBreakpoints(options.breakpoints);
9
+ const shadows = createShadows(options.shadows);
10
+ return {
11
+ palette,
12
+ typography,
13
+ spacing,
14
+ breakpoints,
15
+ shadows
16
+ };
17
+ }
18
+
19
+ // src/createTheme/breakpoints.ts
20
+ function createBreakpoints(breakpoints = {}) {
21
+ const defaultValues = {
22
+ xs: 0,
23
+ sm: 600,
24
+ md: 960,
25
+ lg: 1280,
26
+ xl: 1920
27
+ };
28
+ const values = { ...defaultValues, ...breakpoints.values };
29
+ return {
30
+ values,
31
+ up: (key) => `@media (min-width:${values[key]}px)`,
32
+ down: (key) => `@media (max-width:${values[key]}px)`
33
+ };
34
+ }
35
+
36
+ // src/createTheme/palette.ts
37
+ function createPalette(palette = {}) {
38
+ var _a, _b, _c, _d;
39
+ return {
40
+ brand: (_a = palette.brand) != null ? _a : "#1976d2",
41
+ error: (_b = palette.error) != null ? _b : "#f44336",
42
+ warning: (_c = palette.warning) != null ? _c : "#ff9800",
43
+ success: (_d = palette.success) != null ? _d : "#4caf50"
44
+ };
45
+ }
46
+
47
+ // src/createTheme/shadows.ts
48
+ function createShadows(shadows = {}) {
49
+ var _a, _b, _c, _d, _e;
50
+ return {
51
+ shadow1: (_a = shadows.shadow1) != null ? _a : "0px 1px 3px rgba(0, 0, 0, 0.2), 0px 1px 1px rgba(0, 0, 0, 0.14), 0px 2px 1px -1px rgba(0, 0, 0, 0.12)",
52
+ shadow2: (_b = shadows.shadow2) != null ? _b : "0px 1px 5px rgba(0, 0, 0, 0.2), 0px 2px 2px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)",
53
+ shadow3: (_c = shadows.shadow3) != null ? _c : "0px 1px 8px rgba(0, 0, 0, 0.2), 0px 3px 4px rgba(0, 0, 0, 0.14), 0px 3px 3px -2px rgba(0, 0, 0, 0.12)",
54
+ shadow4: (_d = shadows.shadow4) != null ? _d : "0px 2px 4px -1px rgba(0, 0, 0, 0.2), 0px 4px 5px rgba(0, 0, 0, 0.14), 0px 1px 10px rgba(0, 0, 0, 0.12)",
55
+ shadow5: (_e = shadows.shadow5) != null ? _e : "0px 3px 5px -1px rgba(0, 0, 0, 0.2), 0px 5px 8px rgba(0, 0, 0, 0.14), 0px 1px 14px rgba(0, 0, 0, 0.12)"
56
+ };
57
+ }
58
+
59
+ // src/createTheme/spacing.ts
60
+ function createSpacing(spacing = {}) {
61
+ var _a;
62
+ const unit = (_a = spacing.unit) != null ? _a : 8;
63
+ return (factor) => `${unit * factor}px`;
64
+ }
65
+
66
+ // src/createTheme/typography.ts
67
+ function createTypography(typography = {}) {
68
+ var _a, _b, _c, _d, _e, _f;
69
+ return {
70
+ fontFamily: (_a = typography.fontFamily) != null ? _a : '"Roboto", "Helvetica", "Arial", sans-serif',
71
+ fontSize: (_b = typography.fontSize) != null ? _b : "14px",
72
+ fontWeightLight: (_c = typography.fontWeightLight) != null ? _c : 300,
73
+ fontWeightRegular: (_d = typography.fontWeightRegular) != null ? _d : 400,
74
+ fontWeightMedium: (_e = typography.fontWeightMedium) != null ? _e : 500,
75
+ fontWeightBold: (_f = typography.fontWeightBold) != null ? _f : 700
76
+ };
77
+ }
78
+
79
+ // src/ThemeProvider/ThemeContext.tsx
80
+ import { createContext, useContext } from "react";
81
+ import { defaultTheme } from "@sparkwire/styles";
82
+ var fallback = {
83
+ theme: defaultTheme,
84
+ mode: "dark",
85
+ resolvedMode: "dark",
86
+ setMode: () => {
87
+ },
88
+ toggleTheme: () => {
89
+ }
90
+ };
91
+ var ThemeContext = createContext(fallback);
92
+ var useTheme = () => useContext(ThemeContext);
93
+ var ThemeContext_default = ThemeContext;
94
+
95
+ // src/ThemeProvider/ThemeProvider.tsx
96
+ import { useEffect, useMemo, useState } from "react";
97
+ import { createTheme, defaultTheme as defaultTheme2, lightTheme, themeToCssVars } from "@sparkwire/styles";
98
+ import { jsx } from "react/jsx-runtime";
99
+ var usePrefersLight = () => {
100
+ const [light, setLight] = useState(false);
101
+ useEffect(() => {
102
+ var _a;
103
+ if (typeof window === "undefined" || !window.matchMedia) return;
104
+ const mq = window.matchMedia("(prefers-color-scheme: light)");
105
+ const update = () => setLight(mq.matches);
106
+ update();
107
+ (_a = mq.addEventListener) == null ? void 0 : _a.call(mq, "change", update);
108
+ return () => {
109
+ var _a2;
110
+ return (_a2 = mq.removeEventListener) == null ? void 0 : _a2.call(mq, "change", update);
111
+ };
112
+ }, []);
113
+ return light;
114
+ };
115
+ var ThemeProvider = ({
116
+ children,
117
+ mode,
118
+ defaultMode = "dark",
119
+ theme: overrides,
120
+ initialTheme,
121
+ className
122
+ }) => {
123
+ const [innerMode, setInnerMode] = useState(defaultMode);
124
+ const activeMode = mode != null ? mode : innerMode;
125
+ const prefersLight = usePrefersLight();
126
+ const resolved = activeMode === "system" ? prefersLight ? "light" : "dark" : activeMode;
127
+ const theme = useMemo(() => {
128
+ if (initialTheme && !overrides) return initialTheme;
129
+ return createTheme(overrides, resolved);
130
+ }, [initialTheme, overrides, resolved]);
131
+ const style = useMemo(() => {
132
+ if (!overrides && !initialTheme) return void 0;
133
+ return { ...themeToCssVars(theme), display: "contents" };
134
+ }, [overrides, initialTheme, theme]);
135
+ const value = useMemo(
136
+ () => ({
137
+ theme,
138
+ mode: activeMode,
139
+ resolvedMode: resolved,
140
+ setMode: setInnerMode,
141
+ toggleTheme: () => setInnerMode((m) => m === "light" ? "dark" : "light")
142
+ }),
143
+ [theme, activeMode, resolved]
144
+ );
145
+ return /* @__PURE__ */ jsx(ThemeContext_default.Provider, { value, children: /* @__PURE__ */ jsx("div", { "data-spark-theme": activeMode, className, style: style != null ? style : { display: "contents" }, children }) });
146
+ };
147
+ export {
148
+ ThemeProvider,
149
+ createBreakpoints,
150
+ createPalette,
151
+ createShadows,
152
+ createSpacing,
153
+ createTheme_default as createTheme,
154
+ createTypography,
155
+ useTheme
156
+ };
157
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/createTheme/createTheme.ts","../src/createTheme/breakpoints.ts","../src/createTheme/palette.ts","../src/createTheme/shadows.ts","../src/createTheme/spacing.ts","../src/createTheme/typography.ts","../src/ThemeProvider/ThemeContext.tsx","../src/ThemeProvider/ThemeProvider.tsx"],"sourcesContent":["import {\n PaletteOptions,\n TypographyOptions,\n SpacingOptions,\n BreakpointsOptions,\n ShadowsOptions,\n createPalette,\n createTypography,\n createSpacing,\n createBreakpoints,\n createShadows,\n} from '.';\n\nexport interface ThemeOptions {\n palette?: PaletteOptions;\n typography?: TypographyOptions;\n spacing?: SpacingOptions;\n breakpoints?: BreakpointsOptions;\n shadows?: ShadowsOptions;\n}\n\nexport interface Theme {\n palette: ReturnType<typeof createPalette>;\n typography: ReturnType<typeof createTypography>;\n spacing: ReturnType<typeof createSpacing>;\n breakpoints: ReturnType<typeof createBreakpoints>;\n shadows: ReturnType<typeof createShadows>;\n}\n\nexport default function (options: ThemeOptions = {}): Theme {\n const palette = createPalette(options.palette);\n const typography = createTypography(options.typography);\n const spacing = createSpacing(options.spacing);\n const breakpoints = createBreakpoints(options.breakpoints);\n const shadows = createShadows(options.shadows);\n\n return {\n palette,\n typography,\n spacing,\n breakpoints,\n shadows,\n };\n}\n","export interface BreakpointsOptions {\n values?: {\n xs?: number;\n sm?: number;\n md?: number;\n lg?: number;\n xl?: number;\n };\n}\n\nexport function createBreakpoints(breakpoints: BreakpointsOptions = {}) {\n const defaultValues = {\n xs: 0,\n sm: 600,\n md: 960,\n lg: 1280,\n xl: 1920,\n };\n\n const values = { ...defaultValues, ...breakpoints.values };\n\n return {\n values,\n up: (key: keyof typeof values) => `@media (min-width:${values[key]}px)`,\n down: (key: keyof typeof values) => `@media (max-width:${values[key]}px)`,\n };\n}\n","import { ThemeColors } from \"@sparkwire/styles\";\n\nexport interface PaletteOptions {\n brand?: ThemeColors['primary']['brand'];\n error?: ThemeColors['primary']['error'];\n warning?: ThemeColors['primary']['warning'];\n success?: ThemeColors['primary']['success'];\n}\n\nexport function createPalette(palette: PaletteOptions = {}) {\n return {\n brand: palette.brand ?? '#1976d2',\n error: palette.error ?? '#f44336',\n warning: palette.warning ?? '#ff9800',\n success: palette.success ?? '#4caf50',\n };\n}\n","export interface ShadowsOptions {\n shadow1?: string;\n shadow2?: string;\n shadow3?: string;\n shadow4?: string;\n shadow5?: string;\n}\n\nexport function createShadows(shadows: ShadowsOptions = {}) {\n return {\n shadow1: shadows.shadow1 ?? '0px 1px 3px rgba(0, 0, 0, 0.2), 0px 1px 1px rgba(0, 0, 0, 0.14), 0px 2px 1px -1px rgba(0, 0, 0, 0.12)',\n shadow2: shadows.shadow2 ?? '0px 1px 5px rgba(0, 0, 0, 0.2), 0px 2px 2px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)',\n shadow3: shadows.shadow3 ?? '0px 1px 8px rgba(0, 0, 0, 0.2), 0px 3px 4px rgba(0, 0, 0, 0.14), 0px 3px 3px -2px rgba(0, 0, 0, 0.12)',\n shadow4: shadows.shadow4 ?? '0px 2px 4px -1px rgba(0, 0, 0, 0.2), 0px 4px 5px rgba(0, 0, 0, 0.14), 0px 1px 10px rgba(0, 0, 0, 0.12)',\n shadow5: shadows.shadow5 ?? '0px 3px 5px -1px rgba(0, 0, 0, 0.2), 0px 5px 8px rgba(0, 0, 0, 0.14), 0px 1px 14px rgba(0, 0, 0, 0.12)',\n };\n}\n","export interface SpacingOptions {\n unit?: number;\n}\n\nexport function createSpacing(spacing: SpacingOptions = {}) {\n const unit = spacing.unit ?? 8;\n\n return (factor: number) => `${unit * factor}px`;\n}\n","export interface TypographyOptions {\n fontFamily?: string;\n fontSize?: string;\n fontWeightLight?: number;\n fontWeightRegular?: number;\n fontWeightMedium?: number;\n fontWeightBold?: number;\n}\n\nexport function createTypography(typography: TypographyOptions = {}) {\n return {\n fontFamily: typography.fontFamily ?? '\"Roboto\", \"Helvetica\", \"Arial\", sans-serif',\n fontSize: typography.fontSize ?? '14px',\n fontWeightLight: typography.fontWeightLight ?? 300,\n fontWeightRegular: typography.fontWeightRegular ?? 400,\n fontWeightMedium: typography.fontWeightMedium ?? 500,\n fontWeightBold: typography.fontWeightBold ?? 700,\n };\n}\n","import { createContext, useContext } from 'react';\nimport { BaseTheme, defaultTheme } from '@sparkwire/styles';\n\nexport type SparkMode = 'dark' | 'light' | 'system';\n\ninterface ThemeContextProps {\n /** The resolved theme as JS values, for charts, canvas and other non-CSS uses. */\n theme: BaseTheme;\n mode: SparkMode;\n resolvedMode: 'dark' | 'light';\n setMode: (mode: SparkMode) => void;\n toggleTheme: () => void;\n}\n\nconst fallback: ThemeContextProps = {\n theme: defaultTheme as BaseTheme,\n mode: 'dark',\n resolvedMode: 'dark',\n setMode: () => {},\n toggleTheme: () => {},\n};\n\nconst ThemeContext = createContext<ThemeContextProps>(fallback);\n\n/**\n * Read the current theme values and mode. Works without a ThemeProvider\n * (returns the default dark Live Wire theme).\n */\nexport const useTheme = (): ThemeContextProps => useContext(ThemeContext);\n\nexport default ThemeContext;\n","import React, { ReactNode, useEffect, useMemo, useState } from 'react';\nimport ThemeContext, { SparkMode } from './ThemeContext';\nimport { BaseTheme, DeepPartial, Theme, createTheme, defaultTheme, lightTheme, themeToCssVars } from '@sparkwire/styles';\n\nexport interface ThemeProviderProps {\n children: ReactNode;\n /**\n * Colour mode. `system` follows the operating system. Components read\n * CSS variables, so this works without the provider too: set\n * `data-spark-theme=\"light\"` on any element (e.g. `<html>`).\n */\n mode?: SparkMode;\n /** Start in this mode but let `setMode` change it (uncontrolled). */\n defaultMode?: SparkMode;\n /** Change only the tokens you need; the rest keep their Live Wire values. */\n theme?: DeepPartial<Theme>;\n /** @deprecated Pass `theme` instead. A full theme object is still accepted. */\n initialTheme?: BaseTheme;\n /** Wrapper element's class, e.g. for a font or background. */\n className?: string;\n}\n\nconst usePrefersLight = () => {\n const [light, setLight] = useState(false);\n useEffect(() => {\n if (typeof window === 'undefined' || !window.matchMedia) return;\n const mq = window.matchMedia('(prefers-color-scheme: light)');\n const update = () => setLight(mq.matches);\n update();\n mq.addEventListener?.('change', update);\n return () => mq.removeEventListener?.('change', update);\n }, []);\n return light;\n};\n\n/**\n * Optional. Spark UI components are styled by `@sparkwire/core/styles.css`\n * and its CSS variables, so they render correctly without any provider\n * (including in React Server Components). Use the provider to switch modes\n * at runtime, or to apply token overrides to a part of the page.\n */\nexport const ThemeProvider: React.FC<ThemeProviderProps> = ({\n children,\n mode,\n defaultMode = 'dark',\n theme: overrides,\n initialTheme,\n className,\n}) => {\n const [innerMode, setInnerMode] = useState<SparkMode>(defaultMode);\n const activeMode = mode ?? innerMode;\n const prefersLight = usePrefersLight();\n const resolved: Theme['mode'] =\n activeMode === 'system' ? (prefersLight ? 'light' : 'dark') : activeMode;\n\n const theme = useMemo<BaseTheme>(() => {\n if (initialTheme && !overrides) return initialTheme;\n return createTheme(overrides, resolved) as BaseTheme;\n }, [initialTheme, overrides, resolved]);\n\n // Only emit inline variables when the app overrides tokens.\n const style = useMemo(() => {\n if (!overrides && !initialTheme) return undefined;\n return { ...themeToCssVars(theme), display: 'contents' } as React.CSSProperties;\n }, [overrides, initialTheme, theme]);\n\n const value = useMemo(\n () => ({\n theme,\n mode: activeMode,\n resolvedMode: resolved,\n setMode: setInnerMode,\n toggleTheme: () => setInnerMode((m) => (m === 'light' ? 'dark' : 'light')),\n }),\n [theme, activeMode, resolved],\n );\n\n return (\n <ThemeContext.Provider value={value}>\n <div data-spark-theme={activeMode} className={className} style={style ?? { display: 'contents' }}>\n {children}\n </div>\n </ThemeContext.Provider>\n );\n};\n\nexport { defaultTheme, lightTheme };\n"],"mappings":";;;AA6Be,SAAR,oBAAkB,UAAwB,CAAC,GAAU;AAC1D,QAAM,UAAU,cAAc,QAAQ,OAAO;AAC7C,QAAM,aAAa,iBAAiB,QAAQ,UAAU;AACtD,QAAM,UAAU,cAAc,QAAQ,OAAO;AAC7C,QAAM,cAAc,kBAAkB,QAAQ,WAAW;AACzD,QA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C3B,QAAM,eAAe,gBAAgB;AACrC,QAAM,WACJ,eAAe,WAAY,eAAe,UAAU,SAAU;AAEhE,QAAM,QAAQ,QAAmB,MAAM;AACrC,QAAI,gBAAgB,CAAC,UAAW,QAAO;AACvC,WAAO,YAAY,WAAW,QAAQ;AAAA,EACxC,GAAG,CAAC,cAAc,WAAW,QAAQ,CAAC;AAGtC,QAAM,QAAQ,QAAQ,MAAM;AAC1B,QAAI,CAAC,aAAa,CAAC,aAAc,QAAO;AACxC,WAAO,EAAE,GAAG,eAAe,KAAK,GAAG,SAAS,WAAW;AAAA,EACzD,GAAG,CAAC,WAAW,cAAc,KAAK,CAAC;AAEnC,QAAM,QAAQ;AAAA,IACZ,OAAO;AAAA,MACL;AAAA,MACA,MAAM;AAAA,MACN,cAAc;AAAA,MACd,SAAS;AAAA,MACT,aAAa,MAAM,aAAa,CAAC,MAAO,MAAM,UAAU,SAAS,OAAQ;AAAA,IAC3E;AAAA,IACA,CAAC,OAAO,YAAY,QAAQ;AAAA,EAC9B;AAEA,SACE,oBAAC,qBAAa,UAAb,EAAsB,OACrB,8BAAC,SAAI,oBAAkB,YAAY,WAAsB,OAAO,wBAAS,EAAE,SAAS,WAAW,GAC5F,UACH,GACF;AAEJ;","names":["defaultTheme","_a"]}
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@sparkwire/system",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "A styling engine for the Spark UI library.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsup",
13
+ "clean": "rimraf dist",
14
+ "prepare": "npm run clean && npm run build",
15
+ "test": "echo \"No tests specified\" && exit 0"
16
+ },
17
+ "dependencies": {
18
+ "@sparkwire/styles": "0.2.0"
19
+ },
20
+ "devDependencies": {
21
+ "typescript": "^5.0.0",
22
+ "rimraf": "^3.0.2",
23
+ "@types/node": "^20.0.0",
24
+ "@types/react": "^18.0.0"
25
+ },
26
+ "peerDependencies": {
27
+ "react": "^18.2.0 || ^19.0.0",
28
+ "react-dom": "^18.2.0 || ^19.0.0"
29
+ },
30
+ "license": "MIT",
31
+ "keywords": [
32
+ "spark-ui",
33
+ "styling",
34
+ "theme",
35
+ "design-system"
36
+ ],
37
+ "exports": {
38
+ ".": {
39
+ "types": "./dist/index.d.ts",
40
+ "import": "./dist/index.mjs",
41
+ "require": "./dist/index.js"
42
+ },
43
+ "./package.json": "./package.json"
44
+ },
45
+ "sideEffects": false,
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/phoenix-am/spark-ui.git",
49
+ "directory": "packages/system"
50
+ },
51
+ "homepage": "https://github.com/phoenix-am/spark-ui#readme",
52
+ "publishConfig": {
53
+ "access": "public",
54
+ "provenance": true
55
+ }
56
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
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.