@puzzle-ui/theme 0.4.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 +58 -4
- 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 +10 -4
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
|
],
|
|
@@ -58,7 +64,7 @@
|
|
|
58
64
|
"prepack": "tsdown"
|
|
59
65
|
},
|
|
60
66
|
"dependencies": {
|
|
61
|
-
"@puzzle-ui/core": "^0.
|
|
67
|
+
"@puzzle-ui/core": "^0.5.0"
|
|
62
68
|
},
|
|
63
69
|
"peerDependencies": {
|
|
64
70
|
"react": "^19.0.0",
|
|
@@ -70,7 +76,7 @@
|
|
|
70
76
|
"@types/react": "^19.0.0",
|
|
71
77
|
"@types/react-dom": "^19.0.0",
|
|
72
78
|
"tsdown": "^0.23.1",
|
|
73
|
-
"typescript": "^
|
|
79
|
+
"typescript": "^7.0.2",
|
|
74
80
|
"vitest": "latest"
|
|
75
81
|
}
|
|
76
82
|
}
|