@puzzle-ui/theme 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -84
- package/dist/cli.cjs +96 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +97 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants.cjs +21 -21
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +8 -8
- package/dist/constants.d.ts +8 -8
- package/dist/constants.js +21 -21
- package/dist/constants.js.map +1 -1
- package/dist/fonts/constants.cjs +3 -3
- package/dist/fonts/constants.cjs.map +1 -1
- package/dist/fonts/constants.js +3 -3
- package/dist/fonts/constants.js.map +1 -1
- package/dist/fonts/create-font-preload-filename.cjs +9 -0
- package/dist/fonts/create-font-preload-filename.cjs.map +1 -0
- package/dist/fonts/create-font-preload-filename.js +9 -0
- package/dist/fonts/create-font-preload-filename.js.map +1 -0
- package/dist/fonts/create-google-font-url.cjs +3 -2
- package/dist/fonts/create-google-font-url.cjs.map +1 -1
- package/dist/fonts/create-google-font-url.js +3 -2
- package/dist/fonts/create-google-font-url.js.map +1 -1
- package/dist/fonts/create-local-font-stylesheet-url.cjs +10 -0
- package/dist/fonts/create-local-font-stylesheet-url.cjs.map +1 -0
- package/dist/fonts/create-local-font-stylesheet-url.js +10 -0
- package/dist/fonts/create-local-font-stylesheet-url.js.map +1 -0
- package/dist/fonts/download-google-fonts.cjs +138 -0
- package/dist/fonts/download-google-fonts.cjs.map +1 -0
- package/dist/fonts/download-google-fonts.js +138 -0
- package/dist/fonts/download-google-fonts.js.map +1 -0
- package/dist/fonts/google-font.cjs +18 -8
- package/dist/fonts/google-font.cjs.map +1 -1
- package/dist/fonts/google-font.d.cts +11 -3
- package/dist/fonts/google-font.d.ts +11 -3
- package/dist/fonts/google-font.js +18 -8
- package/dist/fonts/google-font.js.map +1 -1
- package/dist/fonts/index.d.cts +2 -2
- package/dist/fonts/resolve-font-config.cjs +4 -1
- package/dist/fonts/resolve-font-config.cjs.map +1 -1
- package/dist/fonts/resolve-font-config.js +4 -1
- package/dist/fonts/resolve-font-config.js.map +1 -1
- package/dist/fonts/resolve-font-stylesheets.cjs +7 -1
- package/dist/fonts/resolve-font-stylesheets.cjs.map +1 -1
- package/dist/fonts/resolve-font-stylesheets.js +7 -1
- package/dist/fonts/resolve-font-stylesheets.js.map +1 -1
- package/dist/fonts/types.d.cts +12 -1
- package/dist/fonts/types.d.ts +12 -1
- package/dist/global.css +24 -24
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/theme-scopes.css +3 -3
- package/dist/theme.cjs +26 -4
- package/dist/theme.cjs.map +1 -1
- package/dist/theme.css +16 -16
- package/dist/theme.d.cts +27 -3
- package/dist/theme.d.ts +27 -3
- package/dist/theme.js +26 -4
- package/dist/theme.js.map +1 -1
- package/package.json +11 -4
package/dist/theme.css
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
:root {
|
|
2
2
|
color-scheme: light;
|
|
3
|
-
--puzzle-container-gutter: clamp(
|
|
3
|
+
--puzzle-container-gutter: clamp(2rem, 6vw, 6rem);
|
|
4
4
|
--puzzle-color-background: var(--puzzle-color-scheme-light-background, #f7f4ea);
|
|
5
5
|
--puzzle-color-surface: var(--puzzle-color-scheme-light-surface, #fff);
|
|
6
6
|
--puzzle-color-surface-elevated: var(--puzzle-color-scheme-light-surface-elevated, #fff);
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
--puzzle-color-ring: var(--puzzle-color-scheme-light-ring, #2563eb);
|
|
20
20
|
--puzzle-color-success: var(--puzzle-color-scheme-light-success, #15803d);
|
|
21
21
|
--puzzle-color-success-foreground: var(--puzzle-color-scheme-light-success-foreground, #fff);
|
|
22
|
-
--puzzle-color-warning: var(--puzzle-color-scheme-light-warning, #
|
|
22
|
+
--puzzle-color-warning: var(--puzzle-color-scheme-light-warning, #fabc0a);
|
|
23
23
|
--puzzle-color-warning-foreground: var(--puzzle-color-scheme-light-warning-foreground, #fff);
|
|
24
24
|
--puzzle-color-danger: var(--puzzle-color-scheme-light-danger, #b91c1c);
|
|
25
25
|
--puzzle-color-danger-foreground: var(--puzzle-color-scheme-light-danger-foreground, #fff);
|
|
@@ -85,11 +85,11 @@
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
.puzzle-typography-display1, .puzzle-typography-display2, .puzzle-typography-headline1, .puzzle-typography-headline2, .puzzle-typography-headline3, .puzzle-typography-headline4, .puzzle-typography-subtitle1, .puzzle-typography-subtitle2, .puzzle-typography-body1, .puzzle-typography-body2, .puzzle-typography-button, .puzzle-typography-caption, .puzzle-typography-overline {
|
|
88
|
+
:root .puzzle-typography-display1, :root .puzzle-typography-display2, :root .puzzle-typography-headline1, :root .puzzle-typography-headline2, :root .puzzle-typography-headline3, :root .puzzle-typography-headline4, :root .puzzle-typography-subtitle1, :root .puzzle-typography-subtitle2, :root .puzzle-typography-body1, :root .puzzle-typography-body2, :root .puzzle-typography-button, :root .puzzle-typography-caption, :root .puzzle-typography-overline {
|
|
89
89
|
font-family: var(--puzzle-font-family-body, inherit);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
.puzzle-typography-display1 {
|
|
92
|
+
:root .puzzle-typography-display1 {
|
|
93
93
|
font-family: var(--puzzle-font-family-display1, inherit);
|
|
94
94
|
font-size: var(--puzzle-font-size-display1, inherit);
|
|
95
95
|
font-weight: var(--puzzle-font-weight-display1, inherit);
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
letter-spacing: var(--puzzle-font-letter-spacing-display1, inherit);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
.puzzle-typography-display2 {
|
|
100
|
+
:root .puzzle-typography-display2 {
|
|
101
101
|
font-family: var(--puzzle-font-family-display2, inherit);
|
|
102
102
|
font-size: var(--puzzle-font-size-display2, inherit);
|
|
103
103
|
font-weight: var(--puzzle-font-weight-display2, inherit);
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
letter-spacing: var(--puzzle-font-letter-spacing-display2, inherit);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
.puzzle-typography-headline1 {
|
|
108
|
+
:root .puzzle-typography-headline1 {
|
|
109
109
|
font-family: var(--puzzle-font-family-headline1, inherit);
|
|
110
110
|
font-size: var(--puzzle-font-size-headline1, inherit);
|
|
111
111
|
font-weight: var(--puzzle-font-weight-headline1, inherit);
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
letter-spacing: var(--puzzle-font-letter-spacing-headline1, inherit);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
.puzzle-typography-headline2 {
|
|
116
|
+
:root .puzzle-typography-headline2 {
|
|
117
117
|
font-family: var(--puzzle-font-family-headline2, inherit);
|
|
118
118
|
font-size: var(--puzzle-font-size-headline2, inherit);
|
|
119
119
|
font-weight: var(--puzzle-font-weight-headline2, inherit);
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
letter-spacing: var(--puzzle-font-letter-spacing-headline2, inherit);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
.puzzle-typography-headline3 {
|
|
124
|
+
:root .puzzle-typography-headline3 {
|
|
125
125
|
font-family: var(--puzzle-font-family-headline3, inherit);
|
|
126
126
|
font-size: var(--puzzle-font-size-headline3, inherit);
|
|
127
127
|
font-weight: var(--puzzle-font-weight-headline3, inherit);
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
letter-spacing: var(--puzzle-font-letter-spacing-headline3, inherit);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
.puzzle-typography-headline4 {
|
|
132
|
+
:root .puzzle-typography-headline4 {
|
|
133
133
|
font-family: var(--puzzle-font-family-headline4, inherit);
|
|
134
134
|
font-size: var(--puzzle-font-size-headline4, inherit);
|
|
135
135
|
font-weight: var(--puzzle-font-weight-headline4, inherit);
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
letter-spacing: var(--puzzle-font-letter-spacing-headline4, inherit);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
.puzzle-typography-subtitle1 {
|
|
140
|
+
:root .puzzle-typography-subtitle1 {
|
|
141
141
|
font-family: var(--puzzle-font-family-subtitle1, inherit);
|
|
142
142
|
font-size: var(--puzzle-font-size-subtitle1, inherit);
|
|
143
143
|
font-weight: var(--puzzle-font-weight-subtitle1, inherit);
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
letter-spacing: var(--puzzle-font-letter-spacing-subtitle1, inherit);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
.puzzle-typography-subtitle2 {
|
|
148
|
+
:root .puzzle-typography-subtitle2 {
|
|
149
149
|
font-family: var(--puzzle-font-family-subtitle2, inherit);
|
|
150
150
|
font-size: var(--puzzle-font-size-subtitle2, inherit);
|
|
151
151
|
font-weight: var(--puzzle-font-weight-subtitle2, inherit);
|
|
@@ -153,7 +153,7 @@
|
|
|
153
153
|
letter-spacing: var(--puzzle-font-letter-spacing-subtitle2, inherit);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
.puzzle-typography-body1 {
|
|
156
|
+
:root .puzzle-typography-body1 {
|
|
157
157
|
font-family: var(--puzzle-font-family-body1, inherit);
|
|
158
158
|
font-size: var(--puzzle-font-size-body1, inherit);
|
|
159
159
|
font-weight: var(--puzzle-font-weight-body1, inherit);
|
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
letter-spacing: var(--puzzle-font-letter-spacing-body1, inherit);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
.puzzle-typography-body2 {
|
|
164
|
+
:root .puzzle-typography-body2 {
|
|
165
165
|
font-family: var(--puzzle-font-family-body2, inherit);
|
|
166
166
|
font-size: var(--puzzle-font-size-body2, inherit);
|
|
167
167
|
font-weight: var(--puzzle-font-weight-body2, inherit);
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
letter-spacing: var(--puzzle-font-letter-spacing-body2, inherit);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
.puzzle-typography-button {
|
|
172
|
+
:root .puzzle-typography-button {
|
|
173
173
|
font-family: var(--puzzle-font-family-button, inherit);
|
|
174
174
|
font-size: var(--puzzle-font-size-button, inherit);
|
|
175
175
|
font-weight: var(--puzzle-font-weight-button, inherit);
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
letter-spacing: var(--puzzle-font-letter-spacing-button, inherit);
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
.puzzle-typography-caption {
|
|
180
|
+
:root .puzzle-typography-caption {
|
|
181
181
|
font-family: var(--puzzle-font-family-caption, inherit);
|
|
182
182
|
font-size: var(--puzzle-font-size-caption, inherit);
|
|
183
183
|
font-weight: var(--puzzle-font-weight-caption, inherit);
|
|
@@ -185,7 +185,7 @@
|
|
|
185
185
|
letter-spacing: var(--puzzle-font-letter-spacing-caption, inherit);
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
.puzzle-typography-overline {
|
|
188
|
+
:root .puzzle-typography-overline {
|
|
189
189
|
font-family: var(--puzzle-font-family-overline, inherit);
|
|
190
190
|
font-size: var(--puzzle-font-size-overline, inherit);
|
|
191
191
|
font-weight: var(--puzzle-font-weight-overline, inherit);
|
package/dist/theme.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FontConfig, FontRole } from "./fonts/types.cjs";
|
|
1
|
+
import { FontConfig, FontRole, FontSource } from "./fonts/types.cjs";
|
|
2
2
|
import "./fonts/index.cjs";
|
|
3
3
|
import { ColorThemes, ThemeMode, ThemeTokenOverrides } from "./types.cjs";
|
|
4
4
|
import { ThemeComponents } from "./components.types.cjs";
|
|
@@ -9,10 +9,34 @@ export type ThemeProps = {
|
|
|
9
9
|
theme?: ThemeMode;
|
|
10
10
|
scope?: ThemeScope;
|
|
11
11
|
globalStyles?: boolean;
|
|
12
|
-
fonts?: Partial<Record<FontRole, FontConfig
|
|
12
|
+
fonts?: Partial<Record<FontRole, FontConfig>> | Record<string, unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Determines how configured fonts are loaded.
|
|
15
|
+
*
|
|
16
|
+
* - google: Load stylesheets directly from Google Fonts (default).
|
|
17
|
+
* - local: Load the generated stylesheet from the application's public directory.
|
|
18
|
+
*/
|
|
19
|
+
fontSource?: FontSource;
|
|
20
|
+
/**
|
|
21
|
+
* Public URL directory containing puzzle-fonts.css.
|
|
22
|
+
*
|
|
23
|
+
* Defaults to "/fonts".
|
|
24
|
+
*/
|
|
25
|
+
fontBasePath?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Determines which local font is preloaded.
|
|
28
|
+
*
|
|
29
|
+
* - body: Preload the body font (default).
|
|
30
|
+
* - heading: Preload the heading font.
|
|
31
|
+
* - accent: Preload the accent font.
|
|
32
|
+
* - false: Disable font preloading.
|
|
33
|
+
*
|
|
34
|
+
* Only applies when fontSource="local".
|
|
35
|
+
*/
|
|
36
|
+
fontPreload?: FontRole | false;
|
|
13
37
|
tokens?: ThemeTokenOverrides;
|
|
14
38
|
colorTheme?: ColorThemes;
|
|
15
39
|
components?: ThemeComponents;
|
|
16
40
|
};
|
|
17
|
-
declare const Theme: ({ nonce, fonts, theme, scope, globalStyles, tokens, colorTheme, components, children }: PropsWithChildren<ThemeProps>) => import("react").JSX.Element;
|
|
41
|
+
declare const Theme: ({ nonce, fonts, fontSource, fontBasePath, fontPreload, theme, scope, globalStyles, tokens, colorTheme, components, children }: PropsWithChildren<ThemeProps>) => import("react").JSX.Element;
|
|
18
42
|
export { Theme };
|
package/dist/theme.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FontConfig, FontRole } from "./fonts/types.js";
|
|
1
|
+
import { FontConfig, FontRole, FontSource } from "./fonts/types.js";
|
|
2
2
|
import { ColorThemes, ThemeMode, ThemeTokenOverrides } from "./types.js";
|
|
3
3
|
import { ThemeComponents } from "./components.types.js";
|
|
4
4
|
import { PropsWithChildren } from "react";
|
|
@@ -8,10 +8,34 @@ export type ThemeProps = {
|
|
|
8
8
|
theme?: ThemeMode;
|
|
9
9
|
scope?: ThemeScope;
|
|
10
10
|
globalStyles?: boolean;
|
|
11
|
-
fonts?: Partial<Record<FontRole, FontConfig
|
|
11
|
+
fonts?: Partial<Record<FontRole, FontConfig>> | Record<string, unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Determines how configured fonts are loaded.
|
|
14
|
+
*
|
|
15
|
+
* - google: Load stylesheets directly from Google Fonts (default).
|
|
16
|
+
* - local: Load the generated stylesheet from the application's public directory.
|
|
17
|
+
*/
|
|
18
|
+
fontSource?: FontSource;
|
|
19
|
+
/**
|
|
20
|
+
* Public URL directory containing puzzle-fonts.css.
|
|
21
|
+
*
|
|
22
|
+
* Defaults to "/fonts".
|
|
23
|
+
*/
|
|
24
|
+
fontBasePath?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Determines which local font is preloaded.
|
|
27
|
+
*
|
|
28
|
+
* - body: Preload the body font (default).
|
|
29
|
+
* - heading: Preload the heading font.
|
|
30
|
+
* - accent: Preload the accent font.
|
|
31
|
+
* - false: Disable font preloading.
|
|
32
|
+
*
|
|
33
|
+
* Only applies when fontSource="local".
|
|
34
|
+
*/
|
|
35
|
+
fontPreload?: FontRole | false;
|
|
12
36
|
tokens?: ThemeTokenOverrides;
|
|
13
37
|
colorTheme?: ColorThemes;
|
|
14
38
|
components?: ThemeComponents;
|
|
15
39
|
};
|
|
16
|
-
declare const Theme: ({ nonce, fonts, theme, scope, globalStyles, tokens, colorTheme, components, children }: PropsWithChildren<ThemeProps>) => import("react").JSX.Element;
|
|
40
|
+
declare const Theme: ({ nonce, fonts, fontSource, fontBasePath, fontPreload, theme, scope, globalStyles, tokens, colorTheme, components, children }: PropsWithChildren<ThemeProps>) => import("react").JSX.Element;
|
|
17
41
|
export { Theme };
|
package/dist/theme.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ThemeComponentsProvider } from "./components-context.js";
|
|
2
2
|
import { ThemeScopeProvider } from "./scope-context.js";
|
|
3
3
|
import { resolveFontStylesheets } from "./fonts/resolve-font-stylesheets.js";
|
|
4
|
+
import { createLocalFontStylesheetUrl } from "./fonts/create-local-font-stylesheet-url.js";
|
|
5
|
+
import { createFontPreloadFilename } from "./fonts/create-font-preload-filename.js";
|
|
4
6
|
import { createThemeVariables } from "./create-theme-variables.js";
|
|
5
7
|
import { createThemeCss } from "./create-theme-css.js";
|
|
6
8
|
import "./theme.css";
|
|
@@ -9,9 +11,16 @@ import "./global.css";
|
|
|
9
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
12
|
import { useId } from "react";
|
|
11
13
|
// src/theme.tsx
|
|
12
|
-
const
|
|
14
|
+
const normalizeFontBasePath = (path) => {
|
|
15
|
+
return path.replace(/\/+$/, "");
|
|
16
|
+
};
|
|
17
|
+
const Theme = ({ nonce, fonts, fontSource = "google", fontBasePath = "/fonts", fontPreload = "body", theme = "system", scope = "root", globalStyles, tokens, colorTheme, components, children }) => {
|
|
13
18
|
const scopeId = useId();
|
|
14
19
|
const fontStylesheets = resolveFontStylesheets(fonts);
|
|
20
|
+
const localFontStylesheet = fontSource === "local" && fontStylesheets.length > 0 ? createLocalFontStylesheetUrl(fontBasePath) : null;
|
|
21
|
+
const preloadFont = fontPreload !== false ? fonts?.[fontPreload] : void 0;
|
|
22
|
+
const normalizedFontBasePath = normalizeFontBasePath(fontBasePath);
|
|
23
|
+
const fontPreloadHref = fontSource === "local" && preloadFont?.family ? `${normalizedFontBasePath}/${createFontPreloadFilename(preloadFont.family)}` : null;
|
|
15
24
|
const cssVariables = createThemeVariables(fonts, tokens, theme, colorTheme);
|
|
16
25
|
const css = `${scope === "root" ? ":root" : `[data-puzzle-theme-scope="${scopeId}"]`} {\n${createThemeCss(cssVariables)}\n}`;
|
|
17
26
|
const shouldApplyGlobalStyles = scope === "root" && (globalStyles ?? true);
|
|
@@ -23,8 +32,16 @@ const Theme = ({ nonce, fonts, theme = "system", scope = "root", globalStyles, t
|
|
|
23
32
|
children
|
|
24
33
|
})
|
|
25
34
|
});
|
|
35
|
+
const usesGoogleFonts = fontSource === "google" && fontStylesheets.length > 0;
|
|
26
36
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
27
|
-
|
|
37
|
+
fontPreloadHref ? /* @__PURE__ */ jsx("link", {
|
|
38
|
+
rel: "preload",
|
|
39
|
+
href: fontPreloadHref,
|
|
40
|
+
as: "font",
|
|
41
|
+
type: "font/woff2",
|
|
42
|
+
crossOrigin: "anonymous"
|
|
43
|
+
}) : null,
|
|
44
|
+
usesGoogleFonts ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("link", {
|
|
28
45
|
rel: "preconnect",
|
|
29
46
|
href: "https://fonts.googleapis.com"
|
|
30
47
|
}), /* @__PURE__ */ jsx("link", {
|
|
@@ -32,11 +49,16 @@ const Theme = ({ nonce, fonts, theme = "system", scope = "root", globalStyles, t
|
|
|
32
49
|
href: "https://fonts.gstatic.com",
|
|
33
50
|
crossOrigin: "anonymous"
|
|
34
51
|
})] }) : null,
|
|
35
|
-
fontStylesheets.map(({ href }) => /* @__PURE__ */ jsx("link", {
|
|
52
|
+
fontSource === "google" ? fontStylesheets.map(({ href }) => /* @__PURE__ */ jsx("link", {
|
|
36
53
|
rel: "stylesheet",
|
|
37
54
|
href,
|
|
38
55
|
precedence: "default"
|
|
39
|
-
}, href)),
|
|
56
|
+
}, href)) : null,
|
|
57
|
+
localFontStylesheet ? /* @__PURE__ */ jsx("link", {
|
|
58
|
+
rel: "stylesheet",
|
|
59
|
+
href: localFontStylesheet,
|
|
60
|
+
precedence: "default"
|
|
61
|
+
}, localFontStylesheet) : null,
|
|
40
62
|
shouldApplyGlobalStyles ? /* @__PURE__ */ jsx("style", {
|
|
41
63
|
nonce,
|
|
42
64
|
"data-puzzle-global-styles": ""
|
package/dist/theme.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","names":[],"sources":["../src/theme.tsx"],"sourcesContent":["import { useId, type PropsWithChildren } from \"react\";\n\nimport type { FontRole, FontConfig } from \"./fonts\";\nimport type { ColorThemes, ThemeMode, ThemeTokenOverrides } from \"./types\";\nimport type { ThemeComponents } from \"./components.types\";\n\nimport { ThemeComponentsProvider } from \"./components-context\";\nimport { ThemeScopeProvider } from \"./scope-context\";\n\nimport { resolveFontStylesheets } from \"./fonts/resolve-font-stylesheets\";\nimport { createThemeVariables } from \"./create-theme-variables\";\nimport { createThemeCss } from \"./create-theme-css\";\n\nimport \"./theme.css\";\nimport \"./theme-scopes.css\";\nimport \"./global.css\";\n\nexport type ThemeScope = \"root\" | \"local\";\n\nexport type ThemeProps = {\n nonce?: string;\n theme?: ThemeMode;\n scope?: ThemeScope;\n globalStyles?: boolean;\n fonts?: Partial<Record<FontRole, FontConfig
|
|
1
|
+
{"version":3,"file":"theme.js","names":[],"sources":["../src/theme.tsx"],"sourcesContent":["import { useId, type PropsWithChildren } from \"react\";\n\nimport type { FontRole, FontConfig, FontSource } from \"./fonts\";\n\nimport type { ColorThemes, ThemeMode, ThemeTokenOverrides } from \"./types\";\n\nimport type { ThemeComponents } from \"./components.types\";\n\nimport { ThemeComponentsProvider } from \"./components-context\";\nimport { ThemeScopeProvider } from \"./scope-context\";\n\nimport { resolveFontStylesheets } from \"./fonts/resolve-font-stylesheets\";\nimport { createLocalFontStylesheetUrl } from \"./fonts/create-local-font-stylesheet-url\";\nimport { createFontPreloadFilename } from \"./fonts/create-font-preload-filename\";\n\nimport { createThemeVariables } from \"./create-theme-variables\";\nimport { createThemeCss } from \"./create-theme-css\";\n\nimport \"./theme.css\";\nimport \"./theme-scopes.css\";\nimport \"./global.css\";\n\nexport type ThemeScope = \"root\" | \"local\";\n\nexport type ThemeProps = {\n nonce?: string;\n theme?: ThemeMode;\n scope?: ThemeScope;\n globalStyles?: boolean;\n\n fonts?: Partial<Record<FontRole, FontConfig>> | Record<string, unknown>;\n\n /**\n * Determines how configured fonts are loaded.\n *\n * - google: Load stylesheets directly from Google Fonts (default).\n * - local: Load the generated stylesheet from the application's public directory.\n */\n fontSource?: FontSource;\n\n /**\n * Public URL directory containing puzzle-fonts.css.\n *\n * Defaults to \"/fonts\".\n */\n fontBasePath?: string;\n\n /**\n * Determines which local font is preloaded.\n *\n * - body: Preload the body font (default).\n * - heading: Preload the heading font.\n * - accent: Preload the accent font.\n * - false: Disable font preloading.\n *\n * Only applies when fontSource=\"local\".\n */\n fontPreload?: FontRole | false;\n\n tokens?: ThemeTokenOverrides;\n colorTheme?: ColorThemes;\n components?: ThemeComponents;\n};\n\nconst normalizeFontBasePath = (path: string): string => {\n return path.replace(/\\/+$/, \"\");\n};\n\nconst Theme = ({\n nonce,\n fonts,\n fontSource = \"google\",\n fontBasePath = \"/fonts\",\n fontPreload = \"body\",\n theme = \"system\",\n scope = \"root\",\n globalStyles,\n tokens,\n colorTheme,\n components,\n children,\n}: PropsWithChildren<ThemeProps>) => {\n const scopeId = useId();\n\n const fontStylesheets = resolveFontStylesheets(fonts);\n\n const localFontStylesheet =\n fontSource === \"local\" && fontStylesheets.length > 0\n ? createLocalFontStylesheetUrl(fontBasePath)\n : null;\n\n const preloadFont =\n fontPreload !== false\n ? (fonts?.[fontPreload] as FontConfig | undefined)\n : undefined;\n\n const normalizedFontBasePath = normalizeFontBasePath(fontBasePath);\n\n const fontPreloadHref =\n fontSource === \"local\" && preloadFont?.family\n ? `${normalizedFontBasePath}/${createFontPreloadFilename(preloadFont.family)}`\n : null;\n\n const cssVariables = createThemeVariables(fonts, tokens, theme, colorTheme);\n\n const cssSelector =\n scope === \"root\" ? \":root\" : `[data-puzzle-theme-scope=\"${scopeId}\"]`;\n\n const css = `${cssSelector} {\\n${createThemeCss(cssVariables)}\\n}`;\n\n const shouldApplyGlobalStyles = scope === \"root\" && (globalStyles ?? true);\n\n const content =\n components === undefined ? (\n children\n ) : (\n <ThemeComponentsProvider components={components}>\n {children}\n </ThemeComponentsProvider>\n );\n\n const scopedContent = (\n <ThemeScopeProvider\n scopeId={scope === \"local\" ? scopeId : null}\n theme={theme}\n >\n {content}\n </ThemeScopeProvider>\n );\n\n const usesGoogleFonts = fontSource === \"google\" && fontStylesheets.length > 0;\n\n return (\n <>\n {fontPreloadHref ? (\n <link\n rel=\"preload\"\n href={fontPreloadHref}\n as=\"font\"\n type=\"font/woff2\"\n crossOrigin=\"anonymous\"\n />\n ) : null}\n\n {usesGoogleFonts ? (\n <>\n <link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" />\n\n <link\n rel=\"preconnect\"\n href=\"https://fonts.gstatic.com\"\n crossOrigin=\"anonymous\"\n />\n </>\n ) : null}\n\n {fontSource === \"google\"\n ? fontStylesheets.map(({ href }) => (\n <link\n key={href}\n rel=\"stylesheet\"\n href={href}\n precedence=\"default\"\n />\n ))\n : null}\n\n {localFontStylesheet ? (\n <link\n key={localFontStylesheet}\n rel=\"stylesheet\"\n href={localFontStylesheet}\n precedence=\"default\"\n />\n ) : null}\n\n {shouldApplyGlobalStyles ? (\n <style nonce={nonce} data-puzzle-global-styles=\"\" />\n ) : null}\n\n <style\n nonce={nonce}\n data-theme={theme}\n data-puzzle-theme={scope === \"root\" ? \"true\" : undefined}\n data-puzzle-theme-scope-style={scope === \"local\" ? scopeId : undefined}\n >\n {css}\n </style>\n\n {scopedContent}\n </>\n );\n};\n\nexport { Theme };\n"],"mappings":";;;;;;;;;;;;;AAgEA,MAAM,yBAAyB,SAAyB;CACtD,OAAO,KAAK,QAAQ,QAAQ,EAAE;AAChC;AAEA,MAAM,SAAS,EACb,OACA,OACA,aAAa,UACb,eAAe,UACf,cAAc,QACd,QAAQ,UACR,QAAQ,QACR,cACA,QACA,YACA,YACA,eACmC;CACnC,MAAM,UAAU,MAAM;CAEtB,MAAM,kBAAkB,uBAAuB,KAAK;CAEpD,MAAM,sBACJ,eAAe,WAAW,gBAAgB,SAAS,IAC/C,6BAA6B,YAAY,IACzC;CAEN,MAAM,cACJ,gBAAgB,QACX,QAAQ,eACT,KAAA;CAEN,MAAM,yBAAyB,sBAAsB,YAAY;CAEjE,MAAM,kBACJ,eAAe,WAAW,aAAa,SACnC,GAAG,uBAAuB,GAAG,0BAA0B,YAAY,MAAM,MACzE;CAEN,MAAM,eAAe,qBAAqB,OAAO,QAAQ,OAAO,UAAU;CAK1E,MAAM,MAAM,GAFV,UAAU,SAAS,UAAU,6BAA6B,QAAQ,IAEzC,MAAM,eAAe,YAAY,EAAE;CAE9D,MAAM,0BAA0B,UAAU,WAAW,gBAAgB;CAWrE,MAAM,gBACJ,oBAAC,oBAAD;EACE,SAAS,UAAU,UAAU,UAAU;EAChC;EAXT,UAAA,eAAe,KAAA,IACb,WAEA,oBAAC,yBAAD;GAAqC;GAClC;EACsB,CAAA;CASP,CAAA;CAGtB,MAAM,kBAAkB,eAAe,YAAY,gBAAgB,SAAS;CAE5E,OACE,qBAAA,UAAA,EAAA,UAAA;EACG,kBACC,oBAAC,QAAD;GACE,KAAI;GACJ,MAAM;GACN,IAAG;GACH,MAAK;GACL,aAAY;EACb,CAAA,IACC;EAEH,kBACC,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,QAAD;GAAM,KAAI;GAAa,MAAK;EAAgC,CAAA,GAE5D,oBAAC,QAAD;GACE,KAAI;GACJ,MAAK;GACL,aAAY;EACb,CAAA,CACD,EAAA,CAAA,IACA;EAEH,eAAe,WACZ,gBAAgB,KAAK,EAAE,WACrB,oBAAC,QAAD;GAEE,KAAI;GACE;GACN,YAAW;EACZ,GAJM,IAIN,CACF,IACD;EAEH,sBACC,oBAAC,QAAD;GAEE,KAAI;GACJ,MAAM;GACN,YAAW;EACZ,GAJM,mBAIN,IACC;EAEH,0BACC,oBAAC,SAAD;GAAc;GAAO,6BAA0B;EAAI,CAAA,IACjD;EAEJ,oBAAC,SAAD;GACS;GACP,cAAY;GACZ,qBAAmB,UAAU,SAAS,SAAS,KAAA;GAC/C,iCAA+B,UAAU,UAAU,UAAU,KAAA;GAE5D,UAAA;EACI,CAAA;EAEN;CACD,EAAA,CAAA;AAEN"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@puzzle-ui/theme",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Theme components for Puzzle",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"puzzle-theme": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=20.19"
|
|
12
|
+
},
|
|
6
13
|
"publishConfig": {
|
|
7
14
|
"access": "public",
|
|
8
15
|
"registry": "https://registry.npmjs.org/"
|
|
9
16
|
},
|
|
10
|
-
"type": "module",
|
|
11
17
|
"sideEffects": [
|
|
12
18
|
"**/*.css"
|
|
13
19
|
],
|
|
@@ -51,13 +57,14 @@
|
|
|
51
57
|
],
|
|
52
58
|
"scripts": {
|
|
53
59
|
"build": "tsdown",
|
|
60
|
+
"typecheck": "tsc --noEmit -p .",
|
|
54
61
|
"vitest": "bunx vitest run",
|
|
55
62
|
"vitest:watch": "bunx vitest run --watch --passWithNoTests",
|
|
56
63
|
"clean": "rm -rf dist",
|
|
57
64
|
"prepack": "tsdown"
|
|
58
65
|
},
|
|
59
66
|
"dependencies": {
|
|
60
|
-
"@puzzle-ui/core": "^0.
|
|
67
|
+
"@puzzle-ui/core": "^0.5.0"
|
|
61
68
|
},
|
|
62
69
|
"peerDependencies": {
|
|
63
70
|
"react": "^19.0.0",
|
|
@@ -69,7 +76,7 @@
|
|
|
69
76
|
"@types/react": "^19.0.0",
|
|
70
77
|
"@types/react-dom": "^19.0.0",
|
|
71
78
|
"tsdown": "^0.23.1",
|
|
72
|
-
"typescript": "^
|
|
79
|
+
"typescript": "^7.0.2",
|
|
73
80
|
"vitest": "latest"
|
|
74
81
|
}
|
|
75
82
|
}
|