@ox-content/vite-plugin 3.0.0-alpha.13 → 3.0.0-alpha.14
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/dist/index.cjs +172 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -15
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +74 -15
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +171 -16
- package/dist/index.mjs.map +1 -1
- package/dist/markdown-tables.cjs.map +1 -1
- package/dist/markdown-tables.mjs.map +1 -1
- package/dist/styles/core.css +16 -16
- package/dist/styles/markdown-tables.css +3 -1
- package/dist/styles/social.css +68 -15
- package/dist/styles/tabs.css +15 -15
- package/dist/theme-tokens.cjs +95 -0
- package/dist/theme-tokens.cjs.map +1 -0
- package/dist/theme-tokens.d.cts +75 -0
- package/dist/theme-tokens.d.cts.map +1 -0
- package/dist/theme-tokens.d.mts +75 -0
- package/dist/theme-tokens.d.mts.map +1 -0
- package/dist/theme-tokens.mjs +91 -0
- package/dist/theme-tokens.mjs.map +1 -0
- package/dist/vitepress.cjs +2 -31
- package/dist/vitepress.cjs.map +1 -1
- package/dist/vitepress.mjs +2 -31
- package/dist/vitepress.mjs.map +1 -1
- package/package.json +13 -3
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//#region src/theme-tokens.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Free-form `--octc-*` custom properties for themes that need more than the
|
|
4
|
+
* typed `colors` / `fonts` / `layout` fields.
|
|
5
|
+
*
|
|
6
|
+
* Keys are written **without** the `--octc-` prefix, so `"surface-glass"`
|
|
7
|
+
* becomes `--octc-surface-glass`. This is the seam that keeps the two theme
|
|
8
|
+
* axes independent: a color package can restyle code-block line markers, brand
|
|
9
|
+
* accents, and surface textures purely through tokens, while a skin package
|
|
10
|
+
* lays out geometry against those same tokens without knowing any color.
|
|
11
|
+
*/
|
|
12
|
+
type ThemeTokens = Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* The token-bearing shape of a theme.
|
|
15
|
+
*
|
|
16
|
+
* Declared structurally instead of importing `ThemeConfig` so this module keeps
|
|
17
|
+
* an empty import graph: `@ox-content/vite-plugin/theme-tokens` has to be
|
|
18
|
+
* loadable by a bare (`ssg.bare: true`) or custom host that never pulls in the
|
|
19
|
+
* Vite plugin, the SSG, the native binding, or a filesystem API. Every
|
|
20
|
+
* `ThemeConfig` — including the published `@ox-content/theme-color-*` and
|
|
21
|
+
* `@ox-content/theme-*` packages — satisfies it.
|
|
22
|
+
*/
|
|
23
|
+
interface ThemeTokenSource {
|
|
24
|
+
tokens?: ThemeTokens;
|
|
25
|
+
darkTokens?: ThemeTokens;
|
|
26
|
+
extends?: ThemeTokenSource;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Options for {@link renderThemeTokenCss}.
|
|
30
|
+
*/
|
|
31
|
+
interface RenderThemeTokenCssOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Keeps only the tokens whose name passes the predicate. Names arrive without
|
|
34
|
+
* the `--octc-` prefix, so `(name) => name.startsWith("syntax-")` reuses a
|
|
35
|
+
* color scheme's highlighter palette without adopting its page colors,
|
|
36
|
+
* typography, or layout policy.
|
|
37
|
+
*
|
|
38
|
+
* Filtering runs per layer, before merging, so a token a later layer would
|
|
39
|
+
* have overridden is dropped along with the override.
|
|
40
|
+
*/
|
|
41
|
+
include?: (name: string) => boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Renders a theme's `--octc-*` tokens as a standalone stylesheet.
|
|
45
|
+
*
|
|
46
|
+
* The built-in SSG emits these declarations itself, but `ssg.bare: true` and
|
|
47
|
+
* custom hosts render their own document — this is how they get the same
|
|
48
|
+
* tokens. The built-in highlighter emits `var(--octc-syntax-*)` references, so
|
|
49
|
+
* a bare host that wants only the highlighter palette can ask for it:
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { renderThemeTokenCss } from "@ox-content/vite-plugin/theme-tokens";
|
|
53
|
+
* import { kanagawa } from "@ox-content/theme-color-kanagawa";
|
|
54
|
+
*
|
|
55
|
+
* const css = renderThemeTokenCss(kanagawa, {
|
|
56
|
+
* include: (name) => name.startsWith("syntax-"),
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* Layers compose left to right and each layer's `extends` chain is flattened
|
|
61
|
+
* base-first, matching how `resolveTheme()` stacks a skin and a color scheme.
|
|
62
|
+
*/
|
|
63
|
+
declare function renderThemeTokenCss(theme: ThemeTokenSource | ThemeTokenSource[], options?: RenderThemeTokenCssOptions): string;
|
|
64
|
+
/**
|
|
65
|
+
* Renders light and dark token records as the three selectors the SSG runtime
|
|
66
|
+
* switches between: an explicit `[data-theme="dark"]` opt-in, the OS
|
|
67
|
+
* `prefers-color-scheme` fallback, and the `:root` base.
|
|
68
|
+
*
|
|
69
|
+
* Emitted after the typed color variables and before the theme's own `css`, so
|
|
70
|
+
* a token can override a typed color and raw `css` can override a token.
|
|
71
|
+
*/
|
|
72
|
+
declare function tokensToCss(light: ThemeTokens, dark: ThemeTokens): string;
|
|
73
|
+
//#endregion
|
|
74
|
+
export { RenderThemeTokenCssOptions, ThemeTokenSource, ThemeTokens, renderThemeTokenCss, tokensToCss };
|
|
75
|
+
//# sourceMappingURL=theme-tokens.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-tokens.d.mts","names":[],"sources":["../src/theme-tokens.ts"],"mappings":";;;;;;;;;;;KAUY,cAAc;;;;;;;;;;;UAeT;EACf,SAAS;EACT,aAAa;EACb,UAAU;;;;;UAMK;;;;;;;;;;EAUf,WAAW;;;;;;;;;;;;;;;;;;;;;;iBAuBG,oBACd,OAAO,mBAAmB,oBAC1B,UAAS;;;;;;;;;iBAiBK,YAAY,OAAO,aAAa,MAAM"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const TOKEN_PREFIX = "--octc-";
|
|
2
|
+
const TOKEN_NAME_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
3
|
+
/**
|
|
4
|
+
* Renders a theme's `--octc-*` tokens as a standalone stylesheet.
|
|
5
|
+
*
|
|
6
|
+
* The built-in SSG emits these declarations itself, but `ssg.bare: true` and
|
|
7
|
+
* custom hosts render their own document — this is how they get the same
|
|
8
|
+
* tokens. The built-in highlighter emits `var(--octc-syntax-*)` references, so
|
|
9
|
+
* a bare host that wants only the highlighter palette can ask for it:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { renderThemeTokenCss } from "@ox-content/vite-plugin/theme-tokens";
|
|
13
|
+
* import { kanagawa } from "@ox-content/theme-color-kanagawa";
|
|
14
|
+
*
|
|
15
|
+
* const css = renderThemeTokenCss(kanagawa, {
|
|
16
|
+
* include: (name) => name.startsWith("syntax-"),
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Layers compose left to right and each layer's `extends` chain is flattened
|
|
21
|
+
* base-first, matching how `resolveTheme()` stacks a skin and a color scheme.
|
|
22
|
+
*/
|
|
23
|
+
export function renderThemeTokenCss(theme, options = {}) {
|
|
24
|
+
const layers = (Array.isArray(theme) ? theme : [theme]).flatMap(expandExtendsChain);
|
|
25
|
+
return tokensToCss(mergeTokens(layers, "tokens", options.include), mergeTokens(layers, "darkTokens", options.include));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Renders light and dark token records as the three selectors the SSG runtime
|
|
29
|
+
* switches between: an explicit `[data-theme="dark"]` opt-in, the OS
|
|
30
|
+
* `prefers-color-scheme` fallback, and the `:root` base.
|
|
31
|
+
*
|
|
32
|
+
* Emitted after the typed color variables and before the theme's own `css`, so
|
|
33
|
+
* a token can override a typed color and raw `css` can override a token.
|
|
34
|
+
*/
|
|
35
|
+
export function tokensToCss(light, dark) {
|
|
36
|
+
const lightBody = declarations(light, " ");
|
|
37
|
+
const darkBody = declarations(dark, " ");
|
|
38
|
+
const blocks = [];
|
|
39
|
+
if (lightBody) {
|
|
40
|
+
blocks.push(`:root {\n${lightBody}\n}`);
|
|
41
|
+
}
|
|
42
|
+
if (darkBody) {
|
|
43
|
+
blocks.push(`[data-theme="dark"] {\n${darkBody}\n}`);
|
|
44
|
+
blocks.push(`@media (prefers-color-scheme: dark) {\n :root:not([data-theme="light"]) {\n${declarations(dark, " ")}\n }\n}`);
|
|
45
|
+
}
|
|
46
|
+
return blocks.join("\n");
|
|
47
|
+
}
|
|
48
|
+
function declarations(tokens, indent) {
|
|
49
|
+
return Object.entries(tokens)
|
|
50
|
+
.filter(([, value]) => value !== undefined && value !== "")
|
|
51
|
+
.map(([name, value]) => `${indent}${TOKEN_PREFIX}${assertTokenName(name)}: ${value};`)
|
|
52
|
+
.join("\n");
|
|
53
|
+
}
|
|
54
|
+
function assertTokenName(name) {
|
|
55
|
+
// Token names land verbatim inside a declaration block, so a stray `:` or `}`
|
|
56
|
+
// would silently break every rule after it. Fail the build with the offending
|
|
57
|
+
// key instead of shipping a corrupt stylesheet.
|
|
58
|
+
if (!TOKEN_NAME_PATTERN.test(name)) {
|
|
59
|
+
throw new Error(`Invalid theme token name: ${JSON.stringify(name)}. ` +
|
|
60
|
+
`Token names are lowercase kebab-case without the "${TOKEN_PREFIX}" prefix (e.g. "surface-glass").`);
|
|
61
|
+
}
|
|
62
|
+
return name;
|
|
63
|
+
}
|
|
64
|
+
function mergeTokens(layers, field, include) {
|
|
65
|
+
const merged = {};
|
|
66
|
+
for (const layer of layers) {
|
|
67
|
+
for (const [name, value] of Object.entries(layer[field] ?? {})) {
|
|
68
|
+
if (!include || include(name)) {
|
|
69
|
+
merged[name] = value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return merged;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Flattens one layer's `extends` chain into base-first order, mirroring the
|
|
77
|
+
* SSG's own resolution. The `seen` guard keeps a theme that extends itself (or
|
|
78
|
+
* forms a cycle across two packages) from hanging the caller.
|
|
79
|
+
*/
|
|
80
|
+
function expandExtendsChain(theme) {
|
|
81
|
+
const chain = [];
|
|
82
|
+
const seen = new Set();
|
|
83
|
+
let current = theme;
|
|
84
|
+
while (current && !seen.has(current)) {
|
|
85
|
+
seen.add(current);
|
|
86
|
+
chain.unshift(current);
|
|
87
|
+
current = current.extends;
|
|
88
|
+
}
|
|
89
|
+
return chain;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=theme-tokens.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-tokens.mjs","sourceRoot":"","sources":["../../../../home/runner/work/ox-content/ox-content/npm/vite-plugin-ox-content/src/theme-tokens.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * Free-form `--octc-*` custom properties for themes that need more than the\n * typed `colors` / `fonts` / `layout` fields.\n *\n * Keys are written **without** the `--octc-` prefix, so `\"surface-glass\"`\n * becomes `--octc-surface-glass`. This is the seam that keeps the two theme\n * axes independent: a color package can restyle code-block line markers, brand\n * accents, and surface textures purely through tokens, while a skin package\n * lays out geometry against those same tokens without knowing any color.\n */\nexport type ThemeTokens = Record<string, string>;\n\nconst TOKEN_PREFIX = \"--octc-\";\nconst TOKEN_NAME_PATTERN = /^[a-z][a-z0-9-]*$/;\n\n/**\n * The token-bearing shape of a theme.\n *\n * Declared structurally instead of importing `ThemeConfig` so this module keeps\n * an empty import graph: `@ox-content/vite-plugin/theme-tokens` has to be\n * loadable by a bare (`ssg.bare: true`) or custom host that never pulls in the\n * Vite plugin, the SSG, the native binding, or a filesystem API. Every\n * `ThemeConfig` — including the published `@ox-content/theme-color-*` and\n * `@ox-content/theme-*` packages — satisfies it.\n */\nexport interface ThemeTokenSource {\n tokens?: ThemeTokens;\n darkTokens?: ThemeTokens;\n extends?: ThemeTokenSource;\n}\n\n/**\n * Options for {@link renderThemeTokenCss}.\n */\nexport interface RenderThemeTokenCssOptions {\n /**\n * Keeps only the tokens whose name passes the predicate. Names arrive without\n * the `--octc-` prefix, so `(name) => name.startsWith(\"syntax-\")` reuses a\n * color scheme's highlighter palette without adopting its page colors,\n * typography, or layout policy.\n *\n * Filtering runs per layer, before merging, so a token a later layer would\n * have overridden is dropped along with the override.\n */\n include?: (name: string) => boolean;\n}\n\n/**\n * Renders a theme's `--octc-*` tokens as a standalone stylesheet.\n *\n * The built-in SSG emits these declarations itself, but `ssg.bare: true` and\n * custom hosts render their own document — this is how they get the same\n * tokens. The built-in highlighter emits `var(--octc-syntax-*)` references, so\n * a bare host that wants only the highlighter palette can ask for it:\n *\n * ```ts\n * import { renderThemeTokenCss } from \"@ox-content/vite-plugin/theme-tokens\";\n * import { kanagawa } from \"@ox-content/theme-color-kanagawa\";\n *\n * const css = renderThemeTokenCss(kanagawa, {\n * include: (name) => name.startsWith(\"syntax-\"),\n * });\n * ```\n *\n * Layers compose left to right and each layer's `extends` chain is flattened\n * base-first, matching how `resolveTheme()` stacks a skin and a color scheme.\n */\nexport function renderThemeTokenCss(\n theme: ThemeTokenSource | ThemeTokenSource[],\n options: RenderThemeTokenCssOptions = {},\n): string {\n const layers = (Array.isArray(theme) ? theme : [theme]).flatMap(expandExtendsChain);\n return tokensToCss(\n mergeTokens(layers, \"tokens\", options.include),\n mergeTokens(layers, \"darkTokens\", options.include),\n );\n}\n\n/**\n * Renders light and dark token records as the three selectors the SSG runtime\n * switches between: an explicit `[data-theme=\"dark\"]` opt-in, the OS\n * `prefers-color-scheme` fallback, and the `:root` base.\n *\n * Emitted after the typed color variables and before the theme's own `css`, so\n * a token can override a typed color and raw `css` can override a token.\n */\nexport function tokensToCss(light: ThemeTokens, dark: ThemeTokens): string {\n const lightBody = declarations(light, \" \");\n const darkBody = declarations(dark, \" \");\n const blocks: string[] = [];\n\n if (lightBody) {\n blocks.push(`:root {\\n${lightBody}\\n}`);\n }\n if (darkBody) {\n blocks.push(`[data-theme=\"dark\"] {\\n${darkBody}\\n}`);\n blocks.push(\n `@media (prefers-color-scheme: dark) {\\n :root:not([data-theme=\"light\"]) {\\n${declarations(dark, \" \")}\\n }\\n}`,\n );\n }\n\n return blocks.join(\"\\n\");\n}\n\nfunction declarations(tokens: ThemeTokens, indent: string): string {\n return Object.entries(tokens)\n .filter(([, value]) => value !== undefined && value !== \"\")\n .map(([name, value]) => `${indent}${TOKEN_PREFIX}${assertTokenName(name)}: ${value};`)\n .join(\"\\n\");\n}\n\nfunction assertTokenName(name: string): string {\n // Token names land verbatim inside a declaration block, so a stray `:` or `}`\n // would silently break every rule after it. Fail the build with the offending\n // key instead of shipping a corrupt stylesheet.\n if (!TOKEN_NAME_PATTERN.test(name)) {\n throw new Error(\n `Invalid theme token name: ${JSON.stringify(name)}. ` +\n `Token names are lowercase kebab-case without the \"${TOKEN_PREFIX}\" prefix (e.g. \"surface-glass\").`,\n );\n }\n return name;\n}\n\nfunction mergeTokens(\n layers: ThemeTokenSource[],\n field: \"tokens\" | \"darkTokens\",\n include?: (name: string) => boolean,\n): ThemeTokens {\n const merged: ThemeTokens = {};\n\n for (const layer of layers) {\n for (const [name, value] of Object.entries(layer[field] ?? {})) {\n if (!include || include(name)) {\n merged[name] = value;\n }\n }\n }\n\n return merged;\n}\n\n/**\n * Flattens one layer's `extends` chain into base-first order, mirroring the\n * SSG's own resolution. The `seen` guard keeps a theme that extends itself (or\n * forms a cycle across two packages) from hanging the caller.\n */\nfunction expandExtendsChain(theme: ThemeTokenSource): ThemeTokenSource[] {\n const chain: ThemeTokenSource[] = [];\n const seen = new Set<ThemeTokenSource>();\n let current: ThemeTokenSource | undefined = theme;\n\n while (current && !seen.has(current)) {\n seen.add(current);\n chain.unshift(current);\n current = current.extends;\n }\n\n return chain;\n}\n"]}
|
package/dist/vitepress.cjs
CHANGED
|
@@ -38,6 +38,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
38
38
|
}) : target, mod));
|
|
39
39
|
var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
40
|
//#endregion
|
|
41
|
+
const require_theme_tokens = require("./theme-tokens.cjs");
|
|
41
42
|
let node_module = require("node:module");
|
|
42
43
|
let node_fs = require("node:fs");
|
|
43
44
|
let node_path = require("node:path");
|
|
@@ -700,36 +701,6 @@ function resolveHeaderNavItems(items, locale, defaultLocale) {
|
|
|
700
701
|
}));
|
|
701
702
|
}
|
|
702
703
|
//#endregion
|
|
703
|
-
//#region src/theme-tokens.ts
|
|
704
|
-
const TOKEN_PREFIX = "--octc-";
|
|
705
|
-
const TOKEN_NAME_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
706
|
-
/**
|
|
707
|
-
* Renders light and dark token records as the three selectors the SSG runtime
|
|
708
|
-
* switches between: an explicit `[data-theme="dark"]` opt-in, the OS
|
|
709
|
-
* `prefers-color-scheme` fallback, and the `:root` base.
|
|
710
|
-
*
|
|
711
|
-
* Emitted after the typed color variables and before the theme's own `css`, so
|
|
712
|
-
* a token can override a typed color and raw `css` can override a token.
|
|
713
|
-
*/
|
|
714
|
-
function tokensToCss(light, dark) {
|
|
715
|
-
const lightBody = declarations(light, " ");
|
|
716
|
-
const darkBody = declarations(dark, " ");
|
|
717
|
-
const blocks = [];
|
|
718
|
-
if (lightBody) blocks.push(`:root {\n${lightBody}\n}`);
|
|
719
|
-
if (darkBody) {
|
|
720
|
-
blocks.push(`[data-theme="dark"] {\n${darkBody}\n}`);
|
|
721
|
-
blocks.push(`@media (prefers-color-scheme: dark) {\n :root:not([data-theme="light"]) {\n${declarations(dark, " ")}\n }\n}`);
|
|
722
|
-
}
|
|
723
|
-
return blocks.join("\n");
|
|
724
|
-
}
|
|
725
|
-
function declarations(tokens, indent) {
|
|
726
|
-
return Object.entries(tokens).filter(([, value]) => value !== void 0 && value !== "").map(([name, value]) => `${indent}${TOKEN_PREFIX}${assertTokenName(name)}: ${value};`).join("\n");
|
|
727
|
-
}
|
|
728
|
-
function assertTokenName(name) {
|
|
729
|
-
if (!TOKEN_NAME_PATTERN.test(name)) throw new Error(`Invalid theme token name: ${JSON.stringify(name)}. Token names are lowercase kebab-case without the "${TOKEN_PREFIX}" prefix (e.g. "surface-glass").`);
|
|
730
|
-
return name;
|
|
731
|
-
}
|
|
732
|
-
//#endregion
|
|
733
704
|
//#region src/theme.ts
|
|
734
705
|
/**
|
|
735
706
|
* Default theme configuration.
|
|
@@ -997,7 +968,7 @@ function themeToNapi(theme, locale, base, iconsEnabled = false) {
|
|
|
997
968
|
* land after the typed color variables the Rust renderer emits.
|
|
998
969
|
*/
|
|
999
970
|
function themeCss(theme) {
|
|
1000
|
-
const prefix = [
|
|
971
|
+
const prefix = [require_theme_tokens.renderThemeTokenCss(theme), namedFontVarsCss(theme.fonts)].filter(Boolean).join("\n");
|
|
1001
972
|
if (!prefix) return theme.css;
|
|
1002
973
|
return theme.css ? `${prefix}\n${theme.css}` : prefix;
|
|
1003
974
|
}
|