@apotech-os/tokens 0.9.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/dist/index.cjs +175 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +103 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +169 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/theme.ts
|
|
4
|
+
function isResolvedTheme(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && "light" in value && "dark" in value && typeof value.radius === "string" && typeof value.fontSans === "string";
|
|
6
|
+
}
|
|
7
|
+
var SPACE_KEYS = ["crm", "experience", "influence", "pilotage", "proSante"];
|
|
8
|
+
var STATUS_KEYS = ["success", "pending", "approved", "blocked", "paused", "info"];
|
|
9
|
+
var CHART_COUNT = 5;
|
|
10
|
+
function requireColor(value, path) {
|
|
11
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
12
|
+
throw new Error(`theme: \`${path}\` must be a non-empty colour string`);
|
|
13
|
+
}
|
|
14
|
+
if (/[<>]/.test(value)) {
|
|
15
|
+
throw new Error(`theme: \`${path}\` must not contain \`<\` or \`>\``);
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function requireGroup(value, path) {
|
|
20
|
+
if (typeof value !== "object" || value === null) {
|
|
21
|
+
throw new Error(`theme: \`${path}\` must be an object`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function resolveGroup(keys, base, overrides, path) {
|
|
25
|
+
requireGroup(base, path);
|
|
26
|
+
if (overrides !== void 0) requireGroup(overrides, path);
|
|
27
|
+
return Object.fromEntries(
|
|
28
|
+
keys.map((key) => [key, requireColor(overrides?.[key] ?? base[key], `${path}.${key}`)])
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
function resolveScheme(base, overrides, path) {
|
|
32
|
+
const spaces = resolveGroup(SPACE_KEYS, base.spaces, overrides?.spaces, `${path}.spaces`);
|
|
33
|
+
const status = resolveGroup(STATUS_KEYS, base.status, overrides?.status, `${path}.status`);
|
|
34
|
+
const charts = overrides?.charts ?? base.charts;
|
|
35
|
+
if (!Array.isArray(charts) || charts.length !== CHART_COUNT) {
|
|
36
|
+
throw new Error(`theme: \`${path}.charts\` must hold exactly ${CHART_COUNT} colours`);
|
|
37
|
+
}
|
|
38
|
+
charts.forEach((value, i) => requireColor(value, `${path}.charts[${i}]`));
|
|
39
|
+
return {
|
|
40
|
+
primary: requireColor(overrides?.primary ?? base.primary, `${path}.primary`),
|
|
41
|
+
spaces,
|
|
42
|
+
status,
|
|
43
|
+
charts
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function defineTheme(config) {
|
|
47
|
+
if (typeof config?.radius !== "string" || config.radius.trim() === "") {
|
|
48
|
+
throw new Error("theme: `radius` must be a non-empty CSS length");
|
|
49
|
+
}
|
|
50
|
+
if (typeof config.fontSans !== "string" || config.fontSans.trim() === "") {
|
|
51
|
+
throw new Error("theme: `fontSans` must be a non-empty font stack");
|
|
52
|
+
}
|
|
53
|
+
if (config.dark !== void 0) requireGroup(config.dark, "dark");
|
|
54
|
+
const light = resolveScheme(config, void 0, "light");
|
|
55
|
+
return {
|
|
56
|
+
radius: config.radius,
|
|
57
|
+
fontSans: config.fontSans,
|
|
58
|
+
light,
|
|
59
|
+
dark: resolveScheme(light, config.dark, "dark")
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/default-theme.ts
|
|
64
|
+
var BRAND = "oklch(0.549 0.231 268.1)";
|
|
65
|
+
var BRAND_DARK = "oklch(0.68 0.16 268.1)";
|
|
66
|
+
var defaultTheme = defineTheme({
|
|
67
|
+
// Figma: 8px corners on inputs and buttons.
|
|
68
|
+
radius: "0.5rem",
|
|
69
|
+
// Inter is the Figma typeface but the platform does not bundle it yet, so this
|
|
70
|
+
// reads as "Inter if the machine has it, system stack otherwise".
|
|
71
|
+
fontSans: "Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif",
|
|
72
|
+
primary: BRAND,
|
|
73
|
+
spaces: {
|
|
74
|
+
crm: "oklch(0.554 0.215 268.1)",
|
|
75
|
+
experience: "oklch(0.62 0.13 233)",
|
|
76
|
+
influence: "oklch(0.64 0.2 350)",
|
|
77
|
+
pilotage: "oklch(0.7 0.16 62)",
|
|
78
|
+
proSante: "oklch(0.62 0.11 172)"
|
|
79
|
+
},
|
|
80
|
+
status: {
|
|
81
|
+
success: "oklch(0.62 0.16 150)",
|
|
82
|
+
pending: "oklch(0.72 0.15 75)",
|
|
83
|
+
approved: "oklch(0.554 0.215 268.1)",
|
|
84
|
+
blocked: "oklch(0.58 0.22 27)",
|
|
85
|
+
paused: "oklch(0.7 0.02 268.1)",
|
|
86
|
+
info: "oklch(0.62 0.13 233)"
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Categorical palette: five hues spread from the brand around the wheel, all at
|
|
90
|
+
* one lightness so no series reads as "louder" than another. Every entry clears
|
|
91
|
+
* 4.5:1 on white — well past the 3:1 WCAG asks of a graphical object.
|
|
92
|
+
*/
|
|
93
|
+
charts: [
|
|
94
|
+
"oklch(0.55 0.2 268.1)",
|
|
95
|
+
"oklch(0.55 0.09 196)",
|
|
96
|
+
"oklch(0.55 0.15 150)",
|
|
97
|
+
"oklch(0.55 0.115 70)",
|
|
98
|
+
"oklch(0.55 0.2 345)"
|
|
99
|
+
],
|
|
100
|
+
dark: {
|
|
101
|
+
primary: BRAND_DARK,
|
|
102
|
+
spaces: {
|
|
103
|
+
crm: "oklch(0.74 0.135 268.1)",
|
|
104
|
+
experience: "oklch(0.74 0.13 233)",
|
|
105
|
+
influence: "oklch(0.74 0.19 350)",
|
|
106
|
+
pilotage: "oklch(0.74 0.16 62)",
|
|
107
|
+
proSante: "oklch(0.74 0.11 172)"
|
|
108
|
+
},
|
|
109
|
+
status: {
|
|
110
|
+
success: "oklch(0.74 0.16 150)",
|
|
111
|
+
pending: "oklch(0.74 0.15 75)",
|
|
112
|
+
approved: "oklch(0.74 0.135 268.1)",
|
|
113
|
+
blocked: "oklch(0.74 0.155 27)",
|
|
114
|
+
paused: "oklch(0.74 0.02 268.1)",
|
|
115
|
+
info: "oklch(0.74 0.13 233)"
|
|
116
|
+
},
|
|
117
|
+
// Same hues, lifted to ~7:1 on the dark card.
|
|
118
|
+
charts: [
|
|
119
|
+
"oklch(0.74 0.13 268.1)",
|
|
120
|
+
"oklch(0.74 0.125 196)",
|
|
121
|
+
"oklch(0.74 0.17 150)",
|
|
122
|
+
"oklch(0.74 0.16 70)",
|
|
123
|
+
"oklch(0.74 0.17 345)"
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// src/dtcg.ts
|
|
129
|
+
var isToken = (node) => "$value" in node;
|
|
130
|
+
var color = ($value) => ({ $type: "color", $value });
|
|
131
|
+
var colorGroup = (keys, group) => Object.fromEntries(keys.map((key) => [key, color(group[key])]));
|
|
132
|
+
function schemeToDtcg(scheme) {
|
|
133
|
+
return {
|
|
134
|
+
primary: color(scheme.primary),
|
|
135
|
+
space: colorGroup(SPACE_KEYS, scheme.spaces),
|
|
136
|
+
status: colorGroup(STATUS_KEYS, scheme.status),
|
|
137
|
+
chart: Object.fromEntries(scheme.charts.map((value, i) => [String(i + 1), color(value)]))
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function invariantsToDtcg(theme) {
|
|
141
|
+
return {
|
|
142
|
+
radius: { $type: "dimension", $value: theme.radius },
|
|
143
|
+
font: { sans: { $type: "fontFamily", $value: theme.fontSans } }
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
var kebab = (segment) => segment.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
147
|
+
function dtcgToCustomProperties(group, path = []) {
|
|
148
|
+
return Object.entries(group).flatMap(([key, node]) => {
|
|
149
|
+
const next = [...path, kebab(key)];
|
|
150
|
+
return isToken(node) ? [`--${next.join("-")}: ${node.$value};`] : dtcgToCustomProperties(node, next);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/theme-to-css.ts
|
|
155
|
+
var THEME_STYLE_ID = "apotech-theme";
|
|
156
|
+
var block = (selector, declarations) => `${selector} {
|
|
157
|
+
${declarations.map((line) => ` ${line}`).join("\n")}
|
|
158
|
+
}`;
|
|
159
|
+
function themeToCss(theme) {
|
|
160
|
+
const root = [
|
|
161
|
+
...dtcgToCustomProperties(invariantsToDtcg(theme)),
|
|
162
|
+
...dtcgToCustomProperties(schemeToDtcg(theme.light))
|
|
163
|
+
];
|
|
164
|
+
return `${block(":root", root)}
|
|
165
|
+
${block(".dark", dtcgToCustomProperties(schemeToDtcg(theme.dark)))}
|
|
166
|
+
`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
exports.THEME_STYLE_ID = THEME_STYLE_ID;
|
|
170
|
+
exports.defaultTheme = defaultTheme;
|
|
171
|
+
exports.defineTheme = defineTheme;
|
|
172
|
+
exports.isResolvedTheme = isResolvedTheme;
|
|
173
|
+
exports.themeToCss = themeToCss;
|
|
174
|
+
//# sourceMappingURL=index.cjs.map
|
|
175
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/theme.ts","../src/default-theme.ts","../src/dtcg.ts","../src/theme-to-css.ts"],"names":[],"mappings":";;;AAgFO,SAAS,gBAAgB,KAAA,EAAwC;AACtE,EAAA,OACE,OAAO,KAAA,KAAU,QAAA,IACjB,KAAA,KAAU,QACV,OAAA,IAAW,KAAA,IACX,MAAA,IAAU,KAAA,IACV,OAAQ,KAAA,CAAwB,MAAA,KAAW,QAAA,IAC3C,OAAQ,MAAwB,QAAA,KAAa,QAAA;AAEjD;AASO,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AAAA,IACX,GAAG,sBAAA,CAAuB,gBAAA,CAAiB,KAAK,CAAC,CAAA;AAAA,IACjD,GAAG,sBAAA,CAAuB,YAAA,CAAa,KAAA,CAAM,KAAK,CAAC;AAAA,GACrD;AACA,EAAA,OAAO,CAAA,EAAG,KAAA,CAAM,OAAA,EAAS,IAAI,CAAC;AAAA,EAAK,KAAA,CAAM,SAAS,sBAAA,CAAuB,YAAA,CAAa,MAAM,IAAI,CAAC,CAAC,CAAC;AAAA,CAAA;AACrG","file":"index.cjs","sourcesContent":["/**\n * The configurable layer of the design system.\n *\n * Two layers exist. *Primitives* — the gray scale, the radius/spacing/type/shadow\n * scales, the neutral surfaces — are fixed by the platform and ship as static CSS.\n * The *brand/semantic* layer below is the only thing an instance may set. A client\n * can restyle the vocabulary; it cannot invent a word.\n */\n\n/** Colours that differ between the light and the dark scheme. */\nexport interface ThemeScheme {\n /**\n * Brand colour. Drives `--primary`, and `--ring` follows it.\n *\n * Its label, `--primary-foreground`, is a primitive and stays put: near-white in\n * the light scheme, near-black in the dark one. A brand that is light in light\n * mode (or dark in dark mode) therefore loses its button labels — until the\n * contract grows a paired foreground, pick a colour that fits those two.\n */\n primary: string;\n /** Per-space accents — the icon rail, space badges. */\n spaces: ThemeSpaces;\n /** Semantic status colours — runs, approvals, automations. */\n status: ThemeStatus;\n /** Categorical chart palette. Exactly five, in plot order. */\n charts: ThemeCharts;\n}\n\nexport interface ThemeSpaces {\n crm: string;\n experience: string;\n influence: string;\n pilotage: string;\n proSante: string;\n}\n\nexport interface ThemeStatus {\n success: string;\n pending: string;\n approved: string;\n blocked: string;\n paused: string;\n info: string;\n}\n\nexport type ThemeCharts = readonly [string, string, string, string, string];\n\nexport interface ThemeConfig extends ThemeScheme {\n /** Corner radius the whole scale is derived from, e.g. `0.5rem`. */\n radius: string;\n /** Body font stack. */\n fontSans: string;\n /**\n * Dark-scheme overrides. Anything left out falls back to the light value —\n * which is a legibility bug more often than a shortcut, so override on purpose.\n * `radius` and `fontSans` are absent here: they do not vary by scheme.\n */\n dark?: {\n primary?: string;\n spaces?: Partial<ThemeSpaces>;\n status?: Partial<ThemeStatus>;\n charts?: ThemeCharts;\n };\n}\n\nexport interface ResolvedTheme {\n radius: string;\n fontSans: string;\n light: ThemeScheme;\n /** Fully resolved — every key of {@link ThemeScheme}, never a partial. */\n dark: ThemeScheme;\n}\n\n/**\n * `defineTheme`'s output, as opposed to the config that still has to go through it.\n *\n * Lives here rather than in each loader: a `theme.config` module may export either\n * shape, and every loader has to tell them apart the same way or dev and prod\n * disagree on what counts as already-validated.\n */\nexport function isResolvedTheme(value: unknown): value is ResolvedTheme {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'light' in value &&\n 'dark' in value &&\n typeof (value as ResolvedTheme).radius === 'string' &&\n typeof (value as ResolvedTheme).fontSans === 'string'\n );\n}\n\n/**\n * The keys of each colour group, in CSS emission order.\n *\n * Single source: validation, resolution and the DTCG generator all read these, so\n * a new token cannot be added to half the pipeline. Internal — `src/index.ts`\n * decides the public API.\n */\nexport const SPACE_KEYS = ['crm', 'experience', 'influence', 'pilotage', 'proSante'] as const;\nexport const STATUS_KEYS = ['success', 'pending', 'approved', 'blocked', 'paused', 'info'] as const;\nconst CHART_COUNT = 5;\n\nfunction requireColor(value: unknown, path: string): string {\n if (typeof value !== 'string' || value.trim() === '') {\n throw new Error(`theme: \\`${path}\\` must be a non-empty colour string`);\n }\n // The generated CSS is inlined into a <style> tag, so a value carrying markup\n // would escape it. No colour needs these characters.\n if (/[<>]/.test(value)) {\n throw new Error(`theme: \\`${path}\\` must not contain \\`<\\` or \\`>\\``);\n }\n return value;\n}\n\nfunction requireGroup(value: unknown, path: string): void {\n if (typeof value !== 'object' || value === null) {\n throw new Error(`theme: \\`${path}\\` must be an object`);\n }\n}\n\n/** One colour group, overrides layered over the base, every key checked. */\nfunction resolveGroup<K extends string>(\n keys: readonly K[],\n base: Record<K, string>,\n overrides: Partial<Record<K, string>> | undefined,\n path: string,\n): Record<K, string> {\n requireGroup(base, path);\n // A non-object override is not a partial override — it is every key silently\n // falling back to light, which is exactly the bug this package exists to stop.\n if (overrides !== undefined) requireGroup(overrides, path);\n return Object.fromEntries(\n keys.map((key) => [key, requireColor(overrides?.[key] ?? base[key], `${path}.${key}`)]),\n ) as Record<K, string>;\n}\n\nfunction resolveScheme(\n base: ThemeScheme,\n overrides: ThemeConfig['dark'],\n path: 'light' | 'dark',\n): ThemeScheme {\n const spaces = resolveGroup(SPACE_KEYS, base.spaces, overrides?.spaces, `${path}.spaces`);\n const status = resolveGroup(STATUS_KEYS, base.status, overrides?.status, `${path}.status`);\n\n const charts = overrides?.charts ?? base.charts;\n if (!Array.isArray(charts) || charts.length !== CHART_COUNT) {\n throw new Error(`theme: \\`${path}.charts\\` must hold exactly ${CHART_COUNT} colours`);\n }\n charts.forEach((value, i) => requireColor(value, `${path}.charts[${i}]`));\n\n return {\n primary: requireColor(overrides?.primary ?? base.primary, `${path}.primary`),\n spaces,\n status,\n charts,\n };\n}\n\n/**\n * Validate a theme and resolve its dark scheme against its light one.\n *\n * The type makes an unknown or missing key a compile error; the checks here make\n * it a loud runtime error too, because `theme.config.ts` is loaded as plain JS by\n * the API and TypeScript is not there to catch it.\n */\nexport function defineTheme(config: ThemeConfig): ResolvedTheme {\n if (typeof config?.radius !== 'string' || config.radius.trim() === '') {\n throw new Error('theme: `radius` must be a non-empty CSS length');\n }\n if (typeof config.fontSans !== 'string' || config.fontSans.trim() === '') {\n throw new Error('theme: `fontSans` must be a non-empty font stack');\n }\n\n if (config.dark !== undefined) requireGroup(config.dark, 'dark');\n\n const light = resolveScheme(config, undefined, 'light');\n return {\n radius: config.radius,\n fontSans: config.fontSans,\n light,\n dark: resolveScheme(light, config.dark, 'dark'),\n };\n}\n","/**\n * The theme the platform ships with — and the fallback compiled into\n * `apps/web/src/index.css`, so a failed runtime injection degrades to \"neutral\n * but usable\", never to unstyled.\n *\n * Colours are OKLCH so lightness is perceptual: the dark scheme is the same hue\n * lifted to a legible lightness, not a different palette.\n */\nimport { defineTheme } from './theme.js';\n\n/**\n * Brand blue, from the Figma source of truth (`#3B5CF5`).\n * Contrast: 4.85:1 on the light background, 4.99:1 for `--primary-foreground` on it.\n */\nconst BRAND = 'oklch(0.549 0.231 268.1)';\n/** Same hue lifted for the dark scheme: 6.07:1 on the dark card, 6.59:1 for its label. */\nconst BRAND_DARK = 'oklch(0.68 0.16 268.1)';\n\nexport const defaultTheme = defineTheme({\n // Figma: 8px corners on inputs and buttons.\n radius: '0.5rem',\n // Inter is the Figma typeface but the platform does not bundle it yet, so this\n // reads as \"Inter if the machine has it, system stack otherwise\".\n fontSans:\n \"Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif\",\n\n primary: BRAND,\n\n spaces: {\n crm: 'oklch(0.554 0.215 268.1)',\n experience: 'oklch(0.62 0.13 233)',\n influence: 'oklch(0.64 0.2 350)',\n pilotage: 'oklch(0.7 0.16 62)',\n proSante: 'oklch(0.62 0.11 172)',\n },\n\n status: {\n success: 'oklch(0.62 0.16 150)',\n pending: 'oklch(0.72 0.15 75)',\n approved: 'oklch(0.554 0.215 268.1)',\n blocked: 'oklch(0.58 0.22 27)',\n paused: 'oklch(0.7 0.02 268.1)',\n info: 'oklch(0.62 0.13 233)',\n },\n\n /**\n * Categorical palette: five hues spread from the brand around the wheel, all at\n * one lightness so no series reads as \"louder\" than another. Every entry clears\n * 4.5:1 on white — well past the 3:1 WCAG asks of a graphical object.\n */\n charts: [\n 'oklch(0.55 0.2 268.1)',\n 'oklch(0.55 0.09 196)',\n 'oklch(0.55 0.15 150)',\n 'oklch(0.55 0.115 70)',\n 'oklch(0.55 0.2 345)',\n ],\n\n dark: {\n primary: BRAND_DARK,\n spaces: {\n crm: 'oklch(0.74 0.135 268.1)',\n experience: 'oklch(0.74 0.13 233)',\n influence: 'oklch(0.74 0.19 350)',\n pilotage: 'oklch(0.74 0.16 62)',\n proSante: 'oklch(0.74 0.11 172)',\n },\n status: {\n success: 'oklch(0.74 0.16 150)',\n pending: 'oklch(0.74 0.15 75)',\n approved: 'oklch(0.74 0.135 268.1)',\n blocked: 'oklch(0.74 0.155 27)',\n paused: 'oklch(0.74 0.02 268.1)',\n info: 'oklch(0.74 0.13 233)',\n },\n // Same hues, lifted to ~7:1 on the dark card.\n charts: [\n 'oklch(0.74 0.13 268.1)',\n 'oklch(0.74 0.125 196)',\n 'oklch(0.74 0.17 150)',\n 'oklch(0.74 0.16 70)',\n 'oklch(0.74 0.17 345)',\n ],\n },\n});\n","/**\n * DTCG (W3C Design Tokens) as the generator's intermediate format.\n *\n * Nothing here is public API — `themeToCss` is. The point of the detour is that a\n * Figma Variables export speaks DTCG: when that lands it plugs in as another\n * producer of these groups instead of a rewrite of the CSS generator.\n *\n * Token path → CSS custom property is mechanical: kebab-case each segment and\n * join with `-`. `space.proSante` → `--space-pro-sante`, `font.sans` →\n * `--font-sans`, `chart.1` → `--chart-1`. That is why the group names below are\n * the CSS prefixes and not prettier words.\n */\nimport { SPACE_KEYS, STATUS_KEYS, type ResolvedTheme, type ThemeScheme } from './theme.js';\n\nexport type DtcgType = 'color' | 'dimension' | 'fontFamily';\n\nexport interface DtcgToken {\n $type: DtcgType;\n $value: string;\n}\n\nexport interface DtcgGroup {\n [key: string]: DtcgToken | DtcgGroup;\n}\n\nconst isToken = (node: DtcgToken | DtcgGroup): node is DtcgToken => '$value' in node;\n\nconst color = ($value: string): DtcgToken => ({ $type: 'color', $value });\n\nconst colorGroup = <K extends string>(keys: readonly K[], group: Record<K, string>): DtcgGroup =>\n Object.fromEntries(keys.map((key) => [key, color(group[key])]));\n\n/** Colour tokens of one scheme — the keys that must exist in both `:root` and `.dark`. */\nexport function schemeToDtcg(scheme: ThemeScheme): DtcgGroup {\n return {\n primary: color(scheme.primary),\n space: colorGroup(SPACE_KEYS, scheme.spaces),\n status: colorGroup(STATUS_KEYS, scheme.status),\n chart: Object.fromEntries(scheme.charts.map((value, i) => [String(i + 1), color(value)])),\n };\n}\n\n/** Tokens that do not vary by scheme, so they are emitted in `:root` only. */\nexport function invariantsToDtcg(theme: ResolvedTheme): DtcgGroup {\n return {\n radius: { $type: 'dimension', $value: theme.radius },\n font: { sans: { $type: 'fontFamily', $value: theme.fontSans } },\n };\n}\n\nconst kebab = (segment: string) => segment.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\n/** `--custom-property: value;` for every token in the group, depth-first. */\nexport function dtcgToCustomProperties(group: DtcgGroup, path: string[] = []): string[] {\n return Object.entries(group).flatMap(([key, node]) => {\n const next = [...path, kebab(key)];\n return isToken(node)\n ? [`--${next.join('-')}: ${node.$value};`]\n : dtcgToCustomProperties(node, next);\n });\n}\n","import { dtcgToCustomProperties, invariantsToDtcg, schemeToDtcg } from './dtcg.js';\nimport type { ResolvedTheme } from './theme.js';\n\n/**\n * The id carried by the `<style>` tag this CSS is inlined into — the handle the\n * live theme is found by (`document.getElementById('apotech-theme')`).\n *\n * It is a cross-process contract: the API inlines the tag in production and the\n * dev Vite plugin inlines it in `pnpm dev`, so both must spell it the same way.\n */\nexport const THEME_STYLE_ID = 'apotech-theme';\n\nconst block = (selector: string, declarations: string[]) =>\n `${selector} {\\n${declarations.map((line) => ` ${line}`).join('\\n')}\\n}`;\n\n/**\n * Render a theme as `:root { … } .dark { … }`.\n *\n * Only *values* are emitted. The `@theme inline` vocabulary that teaches Tailwind\n * about `bg-primary` and friends stays at build time in `index.css` — a client\n * restyles the words, it does not add any.\n */\nexport function themeToCss(theme: ResolvedTheme): string {\n const root = [\n ...dtcgToCustomProperties(invariantsToDtcg(theme)),\n ...dtcgToCustomProperties(schemeToDtcg(theme.light)),\n ];\n return `${block(':root', root)}\\n${block('.dark', dtcgToCustomProperties(schemeToDtcg(theme.dark)))}\\n`;\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The configurable layer of the design system.
|
|
3
|
+
*
|
|
4
|
+
* Two layers exist. *Primitives* — the gray scale, the radius/spacing/type/shadow
|
|
5
|
+
* scales, the neutral surfaces — are fixed by the platform and ship as static CSS.
|
|
6
|
+
* The *brand/semantic* layer below is the only thing an instance may set. A client
|
|
7
|
+
* can restyle the vocabulary; it cannot invent a word.
|
|
8
|
+
*/
|
|
9
|
+
/** Colours that differ between the light and the dark scheme. */
|
|
10
|
+
interface ThemeScheme {
|
|
11
|
+
/**
|
|
12
|
+
* Brand colour. Drives `--primary`, and `--ring` follows it.
|
|
13
|
+
*
|
|
14
|
+
* Its label, `--primary-foreground`, is a primitive and stays put: near-white in
|
|
15
|
+
* the light scheme, near-black in the dark one. A brand that is light in light
|
|
16
|
+
* mode (or dark in dark mode) therefore loses its button labels — until the
|
|
17
|
+
* contract grows a paired foreground, pick a colour that fits those two.
|
|
18
|
+
*/
|
|
19
|
+
primary: string;
|
|
20
|
+
/** Per-space accents — the icon rail, space badges. */
|
|
21
|
+
spaces: ThemeSpaces;
|
|
22
|
+
/** Semantic status colours — runs, approvals, automations. */
|
|
23
|
+
status: ThemeStatus;
|
|
24
|
+
/** Categorical chart palette. Exactly five, in plot order. */
|
|
25
|
+
charts: ThemeCharts;
|
|
26
|
+
}
|
|
27
|
+
interface ThemeSpaces {
|
|
28
|
+
crm: string;
|
|
29
|
+
experience: string;
|
|
30
|
+
influence: string;
|
|
31
|
+
pilotage: string;
|
|
32
|
+
proSante: string;
|
|
33
|
+
}
|
|
34
|
+
interface ThemeStatus {
|
|
35
|
+
success: string;
|
|
36
|
+
pending: string;
|
|
37
|
+
approved: string;
|
|
38
|
+
blocked: string;
|
|
39
|
+
paused: string;
|
|
40
|
+
info: string;
|
|
41
|
+
}
|
|
42
|
+
type ThemeCharts = readonly [string, string, string, string, string];
|
|
43
|
+
interface ThemeConfig extends ThemeScheme {
|
|
44
|
+
/** Corner radius the whole scale is derived from, e.g. `0.5rem`. */
|
|
45
|
+
radius: string;
|
|
46
|
+
/** Body font stack. */
|
|
47
|
+
fontSans: string;
|
|
48
|
+
/**
|
|
49
|
+
* Dark-scheme overrides. Anything left out falls back to the light value —
|
|
50
|
+
* which is a legibility bug more often than a shortcut, so override on purpose.
|
|
51
|
+
* `radius` and `fontSans` are absent here: they do not vary by scheme.
|
|
52
|
+
*/
|
|
53
|
+
dark?: {
|
|
54
|
+
primary?: string;
|
|
55
|
+
spaces?: Partial<ThemeSpaces>;
|
|
56
|
+
status?: Partial<ThemeStatus>;
|
|
57
|
+
charts?: ThemeCharts;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
interface ResolvedTheme {
|
|
61
|
+
radius: string;
|
|
62
|
+
fontSans: string;
|
|
63
|
+
light: ThemeScheme;
|
|
64
|
+
/** Fully resolved — every key of {@link ThemeScheme}, never a partial. */
|
|
65
|
+
dark: ThemeScheme;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* `defineTheme`'s output, as opposed to the config that still has to go through it.
|
|
69
|
+
*
|
|
70
|
+
* Lives here rather than in each loader: a `theme.config` module may export either
|
|
71
|
+
* shape, and every loader has to tell them apart the same way or dev and prod
|
|
72
|
+
* disagree on what counts as already-validated.
|
|
73
|
+
*/
|
|
74
|
+
declare function isResolvedTheme(value: unknown): value is ResolvedTheme;
|
|
75
|
+
/**
|
|
76
|
+
* Validate a theme and resolve its dark scheme against its light one.
|
|
77
|
+
*
|
|
78
|
+
* The type makes an unknown or missing key a compile error; the checks here make
|
|
79
|
+
* it a loud runtime error too, because `theme.config.ts` is loaded as plain JS by
|
|
80
|
+
* the API and TypeScript is not there to catch it.
|
|
81
|
+
*/
|
|
82
|
+
declare function defineTheme(config: ThemeConfig): ResolvedTheme;
|
|
83
|
+
|
|
84
|
+
declare const defaultTheme: ResolvedTheme;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The id carried by the `<style>` tag this CSS is inlined into — the handle the
|
|
88
|
+
* live theme is found by (`document.getElementById('apotech-theme')`).
|
|
89
|
+
*
|
|
90
|
+
* It is a cross-process contract: the API inlines the tag in production and the
|
|
91
|
+
* dev Vite plugin inlines it in `pnpm dev`, so both must spell it the same way.
|
|
92
|
+
*/
|
|
93
|
+
declare const THEME_STYLE_ID = "apotech-theme";
|
|
94
|
+
/**
|
|
95
|
+
* Render a theme as `:root { … } .dark { … }`.
|
|
96
|
+
*
|
|
97
|
+
* Only *values* are emitted. The `@theme inline` vocabulary that teaches Tailwind
|
|
98
|
+
* about `bg-primary` and friends stays at build time in `index.css` — a client
|
|
99
|
+
* restyles the words, it does not add any.
|
|
100
|
+
*/
|
|
101
|
+
declare function themeToCss(theme: ResolvedTheme): string;
|
|
102
|
+
|
|
103
|
+
export { type ResolvedTheme, THEME_STYLE_ID, type ThemeCharts, type ThemeConfig, type ThemeScheme, type ThemeSpaces, type ThemeStatus, defaultTheme, defineTheme, isResolvedTheme, themeToCss };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The configurable layer of the design system.
|
|
3
|
+
*
|
|
4
|
+
* Two layers exist. *Primitives* — the gray scale, the radius/spacing/type/shadow
|
|
5
|
+
* scales, the neutral surfaces — are fixed by the platform and ship as static CSS.
|
|
6
|
+
* The *brand/semantic* layer below is the only thing an instance may set. A client
|
|
7
|
+
* can restyle the vocabulary; it cannot invent a word.
|
|
8
|
+
*/
|
|
9
|
+
/** Colours that differ between the light and the dark scheme. */
|
|
10
|
+
interface ThemeScheme {
|
|
11
|
+
/**
|
|
12
|
+
* Brand colour. Drives `--primary`, and `--ring` follows it.
|
|
13
|
+
*
|
|
14
|
+
* Its label, `--primary-foreground`, is a primitive and stays put: near-white in
|
|
15
|
+
* the light scheme, near-black in the dark one. A brand that is light in light
|
|
16
|
+
* mode (or dark in dark mode) therefore loses its button labels — until the
|
|
17
|
+
* contract grows a paired foreground, pick a colour that fits those two.
|
|
18
|
+
*/
|
|
19
|
+
primary: string;
|
|
20
|
+
/** Per-space accents — the icon rail, space badges. */
|
|
21
|
+
spaces: ThemeSpaces;
|
|
22
|
+
/** Semantic status colours — runs, approvals, automations. */
|
|
23
|
+
status: ThemeStatus;
|
|
24
|
+
/** Categorical chart palette. Exactly five, in plot order. */
|
|
25
|
+
charts: ThemeCharts;
|
|
26
|
+
}
|
|
27
|
+
interface ThemeSpaces {
|
|
28
|
+
crm: string;
|
|
29
|
+
experience: string;
|
|
30
|
+
influence: string;
|
|
31
|
+
pilotage: string;
|
|
32
|
+
proSante: string;
|
|
33
|
+
}
|
|
34
|
+
interface ThemeStatus {
|
|
35
|
+
success: string;
|
|
36
|
+
pending: string;
|
|
37
|
+
approved: string;
|
|
38
|
+
blocked: string;
|
|
39
|
+
paused: string;
|
|
40
|
+
info: string;
|
|
41
|
+
}
|
|
42
|
+
type ThemeCharts = readonly [string, string, string, string, string];
|
|
43
|
+
interface ThemeConfig extends ThemeScheme {
|
|
44
|
+
/** Corner radius the whole scale is derived from, e.g. `0.5rem`. */
|
|
45
|
+
radius: string;
|
|
46
|
+
/** Body font stack. */
|
|
47
|
+
fontSans: string;
|
|
48
|
+
/**
|
|
49
|
+
* Dark-scheme overrides. Anything left out falls back to the light value —
|
|
50
|
+
* which is a legibility bug more often than a shortcut, so override on purpose.
|
|
51
|
+
* `radius` and `fontSans` are absent here: they do not vary by scheme.
|
|
52
|
+
*/
|
|
53
|
+
dark?: {
|
|
54
|
+
primary?: string;
|
|
55
|
+
spaces?: Partial<ThemeSpaces>;
|
|
56
|
+
status?: Partial<ThemeStatus>;
|
|
57
|
+
charts?: ThemeCharts;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
interface ResolvedTheme {
|
|
61
|
+
radius: string;
|
|
62
|
+
fontSans: string;
|
|
63
|
+
light: ThemeScheme;
|
|
64
|
+
/** Fully resolved — every key of {@link ThemeScheme}, never a partial. */
|
|
65
|
+
dark: ThemeScheme;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* `defineTheme`'s output, as opposed to the config that still has to go through it.
|
|
69
|
+
*
|
|
70
|
+
* Lives here rather than in each loader: a `theme.config` module may export either
|
|
71
|
+
* shape, and every loader has to tell them apart the same way or dev and prod
|
|
72
|
+
* disagree on what counts as already-validated.
|
|
73
|
+
*/
|
|
74
|
+
declare function isResolvedTheme(value: unknown): value is ResolvedTheme;
|
|
75
|
+
/**
|
|
76
|
+
* Validate a theme and resolve its dark scheme against its light one.
|
|
77
|
+
*
|
|
78
|
+
* The type makes an unknown or missing key a compile error; the checks here make
|
|
79
|
+
* it a loud runtime error too, because `theme.config.ts` is loaded as plain JS by
|
|
80
|
+
* the API and TypeScript is not there to catch it.
|
|
81
|
+
*/
|
|
82
|
+
declare function defineTheme(config: ThemeConfig): ResolvedTheme;
|
|
83
|
+
|
|
84
|
+
declare const defaultTheme: ResolvedTheme;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The id carried by the `<style>` tag this CSS is inlined into — the handle the
|
|
88
|
+
* live theme is found by (`document.getElementById('apotech-theme')`).
|
|
89
|
+
*
|
|
90
|
+
* It is a cross-process contract: the API inlines the tag in production and the
|
|
91
|
+
* dev Vite plugin inlines it in `pnpm dev`, so both must spell it the same way.
|
|
92
|
+
*/
|
|
93
|
+
declare const THEME_STYLE_ID = "apotech-theme";
|
|
94
|
+
/**
|
|
95
|
+
* Render a theme as `:root { … } .dark { … }`.
|
|
96
|
+
*
|
|
97
|
+
* Only *values* are emitted. The `@theme inline` vocabulary that teaches Tailwind
|
|
98
|
+
* about `bg-primary` and friends stays at build time in `index.css` — a client
|
|
99
|
+
* restyles the words, it does not add any.
|
|
100
|
+
*/
|
|
101
|
+
declare function themeToCss(theme: ResolvedTheme): string;
|
|
102
|
+
|
|
103
|
+
export { type ResolvedTheme, THEME_STYLE_ID, type ThemeCharts, type ThemeConfig, type ThemeScheme, type ThemeSpaces, type ThemeStatus, defaultTheme, defineTheme, isResolvedTheme, themeToCss };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// src/theme.ts
|
|
2
|
+
function isResolvedTheme(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && "light" in value && "dark" in value && typeof value.radius === "string" && typeof value.fontSans === "string";
|
|
4
|
+
}
|
|
5
|
+
var SPACE_KEYS = ["crm", "experience", "influence", "pilotage", "proSante"];
|
|
6
|
+
var STATUS_KEYS = ["success", "pending", "approved", "blocked", "paused", "info"];
|
|
7
|
+
var CHART_COUNT = 5;
|
|
8
|
+
function requireColor(value, path) {
|
|
9
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
10
|
+
throw new Error(`theme: \`${path}\` must be a non-empty colour string`);
|
|
11
|
+
}
|
|
12
|
+
if (/[<>]/.test(value)) {
|
|
13
|
+
throw new Error(`theme: \`${path}\` must not contain \`<\` or \`>\``);
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
function requireGroup(value, path) {
|
|
18
|
+
if (typeof value !== "object" || value === null) {
|
|
19
|
+
throw new Error(`theme: \`${path}\` must be an object`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function resolveGroup(keys, base, overrides, path) {
|
|
23
|
+
requireGroup(base, path);
|
|
24
|
+
if (overrides !== void 0) requireGroup(overrides, path);
|
|
25
|
+
return Object.fromEntries(
|
|
26
|
+
keys.map((key) => [key, requireColor(overrides?.[key] ?? base[key], `${path}.${key}`)])
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
function resolveScheme(base, overrides, path) {
|
|
30
|
+
const spaces = resolveGroup(SPACE_KEYS, base.spaces, overrides?.spaces, `${path}.spaces`);
|
|
31
|
+
const status = resolveGroup(STATUS_KEYS, base.status, overrides?.status, `${path}.status`);
|
|
32
|
+
const charts = overrides?.charts ?? base.charts;
|
|
33
|
+
if (!Array.isArray(charts) || charts.length !== CHART_COUNT) {
|
|
34
|
+
throw new Error(`theme: \`${path}.charts\` must hold exactly ${CHART_COUNT} colours`);
|
|
35
|
+
}
|
|
36
|
+
charts.forEach((value, i) => requireColor(value, `${path}.charts[${i}]`));
|
|
37
|
+
return {
|
|
38
|
+
primary: requireColor(overrides?.primary ?? base.primary, `${path}.primary`),
|
|
39
|
+
spaces,
|
|
40
|
+
status,
|
|
41
|
+
charts
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function defineTheme(config) {
|
|
45
|
+
if (typeof config?.radius !== "string" || config.radius.trim() === "") {
|
|
46
|
+
throw new Error("theme: `radius` must be a non-empty CSS length");
|
|
47
|
+
}
|
|
48
|
+
if (typeof config.fontSans !== "string" || config.fontSans.trim() === "") {
|
|
49
|
+
throw new Error("theme: `fontSans` must be a non-empty font stack");
|
|
50
|
+
}
|
|
51
|
+
if (config.dark !== void 0) requireGroup(config.dark, "dark");
|
|
52
|
+
const light = resolveScheme(config, void 0, "light");
|
|
53
|
+
return {
|
|
54
|
+
radius: config.radius,
|
|
55
|
+
fontSans: config.fontSans,
|
|
56
|
+
light,
|
|
57
|
+
dark: resolveScheme(light, config.dark, "dark")
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/default-theme.ts
|
|
62
|
+
var BRAND = "oklch(0.549 0.231 268.1)";
|
|
63
|
+
var BRAND_DARK = "oklch(0.68 0.16 268.1)";
|
|
64
|
+
var defaultTheme = defineTheme({
|
|
65
|
+
// Figma: 8px corners on inputs and buttons.
|
|
66
|
+
radius: "0.5rem",
|
|
67
|
+
// Inter is the Figma typeface but the platform does not bundle it yet, so this
|
|
68
|
+
// reads as "Inter if the machine has it, system stack otherwise".
|
|
69
|
+
fontSans: "Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif",
|
|
70
|
+
primary: BRAND,
|
|
71
|
+
spaces: {
|
|
72
|
+
crm: "oklch(0.554 0.215 268.1)",
|
|
73
|
+
experience: "oklch(0.62 0.13 233)",
|
|
74
|
+
influence: "oklch(0.64 0.2 350)",
|
|
75
|
+
pilotage: "oklch(0.7 0.16 62)",
|
|
76
|
+
proSante: "oklch(0.62 0.11 172)"
|
|
77
|
+
},
|
|
78
|
+
status: {
|
|
79
|
+
success: "oklch(0.62 0.16 150)",
|
|
80
|
+
pending: "oklch(0.72 0.15 75)",
|
|
81
|
+
approved: "oklch(0.554 0.215 268.1)",
|
|
82
|
+
blocked: "oklch(0.58 0.22 27)",
|
|
83
|
+
paused: "oklch(0.7 0.02 268.1)",
|
|
84
|
+
info: "oklch(0.62 0.13 233)"
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Categorical palette: five hues spread from the brand around the wheel, all at
|
|
88
|
+
* one lightness so no series reads as "louder" than another. Every entry clears
|
|
89
|
+
* 4.5:1 on white — well past the 3:1 WCAG asks of a graphical object.
|
|
90
|
+
*/
|
|
91
|
+
charts: [
|
|
92
|
+
"oklch(0.55 0.2 268.1)",
|
|
93
|
+
"oklch(0.55 0.09 196)",
|
|
94
|
+
"oklch(0.55 0.15 150)",
|
|
95
|
+
"oklch(0.55 0.115 70)",
|
|
96
|
+
"oklch(0.55 0.2 345)"
|
|
97
|
+
],
|
|
98
|
+
dark: {
|
|
99
|
+
primary: BRAND_DARK,
|
|
100
|
+
spaces: {
|
|
101
|
+
crm: "oklch(0.74 0.135 268.1)",
|
|
102
|
+
experience: "oklch(0.74 0.13 233)",
|
|
103
|
+
influence: "oklch(0.74 0.19 350)",
|
|
104
|
+
pilotage: "oklch(0.74 0.16 62)",
|
|
105
|
+
proSante: "oklch(0.74 0.11 172)"
|
|
106
|
+
},
|
|
107
|
+
status: {
|
|
108
|
+
success: "oklch(0.74 0.16 150)",
|
|
109
|
+
pending: "oklch(0.74 0.15 75)",
|
|
110
|
+
approved: "oklch(0.74 0.135 268.1)",
|
|
111
|
+
blocked: "oklch(0.74 0.155 27)",
|
|
112
|
+
paused: "oklch(0.74 0.02 268.1)",
|
|
113
|
+
info: "oklch(0.74 0.13 233)"
|
|
114
|
+
},
|
|
115
|
+
// Same hues, lifted to ~7:1 on the dark card.
|
|
116
|
+
charts: [
|
|
117
|
+
"oklch(0.74 0.13 268.1)",
|
|
118
|
+
"oklch(0.74 0.125 196)",
|
|
119
|
+
"oklch(0.74 0.17 150)",
|
|
120
|
+
"oklch(0.74 0.16 70)",
|
|
121
|
+
"oklch(0.74 0.17 345)"
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// src/dtcg.ts
|
|
127
|
+
var isToken = (node) => "$value" in node;
|
|
128
|
+
var color = ($value) => ({ $type: "color", $value });
|
|
129
|
+
var colorGroup = (keys, group) => Object.fromEntries(keys.map((key) => [key, color(group[key])]));
|
|
130
|
+
function schemeToDtcg(scheme) {
|
|
131
|
+
return {
|
|
132
|
+
primary: color(scheme.primary),
|
|
133
|
+
space: colorGroup(SPACE_KEYS, scheme.spaces),
|
|
134
|
+
status: colorGroup(STATUS_KEYS, scheme.status),
|
|
135
|
+
chart: Object.fromEntries(scheme.charts.map((value, i) => [String(i + 1), color(value)]))
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function invariantsToDtcg(theme) {
|
|
139
|
+
return {
|
|
140
|
+
radius: { $type: "dimension", $value: theme.radius },
|
|
141
|
+
font: { sans: { $type: "fontFamily", $value: theme.fontSans } }
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
var kebab = (segment) => segment.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
145
|
+
function dtcgToCustomProperties(group, path = []) {
|
|
146
|
+
return Object.entries(group).flatMap(([key, node]) => {
|
|
147
|
+
const next = [...path, kebab(key)];
|
|
148
|
+
return isToken(node) ? [`--${next.join("-")}: ${node.$value};`] : dtcgToCustomProperties(node, next);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/theme-to-css.ts
|
|
153
|
+
var THEME_STYLE_ID = "apotech-theme";
|
|
154
|
+
var block = (selector, declarations) => `${selector} {
|
|
155
|
+
${declarations.map((line) => ` ${line}`).join("\n")}
|
|
156
|
+
}`;
|
|
157
|
+
function themeToCss(theme) {
|
|
158
|
+
const root = [
|
|
159
|
+
...dtcgToCustomProperties(invariantsToDtcg(theme)),
|
|
160
|
+
...dtcgToCustomProperties(schemeToDtcg(theme.light))
|
|
161
|
+
];
|
|
162
|
+
return `${block(":root", root)}
|
|
163
|
+
${block(".dark", dtcgToCustomProperties(schemeToDtcg(theme.dark)))}
|
|
164
|
+
`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export { THEME_STYLE_ID, defaultTheme, defineTheme, isResolvedTheme, themeToCss };
|
|
168
|
+
//# sourceMappingURL=index.js.map
|
|
169
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/theme.ts","../src/default-theme.ts","../src/dtcg.ts","../src/theme-to-css.ts"],"names":[],"mappings":";AAgFO,SAAS,gBAAgB,KAAA,EAAwC;AACtE,EAAA,OACE,OAAO,KAAA,KAAU,QAAA,IACjB,KAAA,KAAU,QACV,OAAA,IAAW,KAAA,IACX,MAAA,IAAU,KAAA,IACV,OAAQ,KAAA,CAAwB,MAAA,KAAW,QAAA,IAC3C,OAAQ,MAAwB,QAAA,KAAa,QAAA;AAEjD;AASO,IAAM,aAAa,CAAC,KAAA,EAAO,YAAA,EAAc,WAAA,EAAa,YAAY,UAAU,CAAA;AAC5E,IAAM,cAAc,CAAC,SAAA,EAAW,WAAW,UAAA,EAAY,SAAA,EAAW,UAAU,MAAM,CAAA;AACzF,IAAM,WAAA,GAAc,CAAA;AAEpB,SAAS,YAAA,CAAa,OAAgB,IAAA,EAAsB;AAC1D,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,CAAM,IAAA,OAAW,EAAA,EAAI;AACpD,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,SAAA,EAAY,IAAI,CAAA,oCAAA,CAAsC,CAAA;AAAA,EACxE;AAGA,EAAA,IAAI,MAAA,CAAO,IAAA,CAAK,KAAK,CA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AAA,CAAuB,KAAA,EAAkB,IAAA,GAAiB,EAAC,EAAa;AACtF,EAAA,OAAO,MAAA,CAAO,QAAQ,KAAK,CAAA,CAAE,QAAQ,CAAC,CAAC,GAAA,EAAK,IAAI,CAAA,KAAM;AACpD,IAAA,MAAM,OAAO,CAAC,GAAG,IAAA,EAAM,KAAA,CAAM,GAAG,CAAC,CAAA;AACjC,IAAA,OAAO,QAAQ,IAAI,CAAA,GACf,CAAC,CAAA,EAAA,EAAK,KAAK,IAAA,CAAK,GAAG,CAAC,CAAA,EAAA,EAAK,KAAK,MAAM,CAAA,CAAA,CAAG,CAAA,GACvC,sBAAA,CAAuB,MAAM,IAAI,CAAA;AAAA,EACvC,CAAC,CAAA;AACH;;;AClDO,IAAM,cAAA,GAAiB;AAE9B,IAAM,KAAA,GAAQ,CAAC,QAAA,EAAkB,YAAA,KAC/B,GAAG,QAAQ,CAAA;AAAA,EAAO,YAAA,CAAa,GAAA,CAAI,CAAC,IAAA,KAAS,CAAA,EAAA,EAAK,IAAI,CAAA,CAAE,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC;AAAA,CAAA,CAAA;AAS/D,SAAS,WAAW,KAAA,EAA8B;AACvD,EAAA,MAAM,IAAA,GAAO;AAAA,IACX,GAAG,sBAAA,CAAuB,gBAAA,CAAiB,KAAK,CAAC,CAAA;AAAA,IACjD,GAAG,sBAAA,CAAuB,YAAA,CAAa,KAAA,CAAM,KAAK,CAAC;AAAA,GACrD;AACA,EAAA,OAAO,CAAA,EAAG,KAAA,CAAM,OAAA,EAAS,IAAI,CAAC;AAAA,EAAK,KAAA,CAAM,SAAS,sBAAA,CAAuB,YAAA,CAAa,MAAM,IAAI,CAAC,CAAC,CAAC;AAAA,CAAA;AACrG","file":"index.js","sourcesContent":["/**\n * The configurable layer of the design system.\n *\n * Two layers exist. *Primitives* — the gray scale, the radius/spacing/type/shadow\n * scales, the neutral surfaces — are fixed by the platform and ship as static CSS.\n * The *brand/semantic* layer below is the only thing an instance may set. A client\n * can restyle the vocabulary; it cannot invent a word.\n */\n\n/** Colours that differ between the light and the dark scheme. */\nexport interface ThemeScheme {\n /**\n * Brand colour. Drives `--primary`, and `--ring` follows it.\n *\n * Its label, `--primary-foreground`, is a primitive and stays put: near-white in\n * the light scheme, near-black in the dark one. A brand that is light in light\n * mode (or dark in dark mode) therefore loses its button labels — until the\n * contract grows a paired foreground, pick a colour that fits those two.\n */\n primary: string;\n /** Per-space accents — the icon rail, space badges. */\n spaces: ThemeSpaces;\n /** Semantic status colours — runs, approvals, automations. */\n status: ThemeStatus;\n /** Categorical chart palette. Exactly five, in plot order. */\n charts: ThemeCharts;\n}\n\nexport interface ThemeSpaces {\n crm: string;\n experience: string;\n influence: string;\n pilotage: string;\n proSante: string;\n}\n\nexport interface ThemeStatus {\n success: string;\n pending: string;\n approved: string;\n blocked: string;\n paused: string;\n info: string;\n}\n\nexport type ThemeCharts = readonly [string, string, string, string, string];\n\nexport interface ThemeConfig extends ThemeScheme {\n /** Corner radius the whole scale is derived from, e.g. `0.5rem`. */\n radius: string;\n /** Body font stack. */\n fontSans: string;\n /**\n * Dark-scheme overrides. Anything left out falls back to the light value —\n * which is a legibility bug more often than a shortcut, so override on purpose.\n * `radius` and `fontSans` are absent here: they do not vary by scheme.\n */\n dark?: {\n primary?: string;\n spaces?: Partial<ThemeSpaces>;\n status?: Partial<ThemeStatus>;\n charts?: ThemeCharts;\n };\n}\n\nexport interface ResolvedTheme {\n radius: string;\n fontSans: string;\n light: ThemeScheme;\n /** Fully resolved — every key of {@link ThemeScheme}, never a partial. */\n dark: ThemeScheme;\n}\n\n/**\n * `defineTheme`'s output, as opposed to the config that still has to go through it.\n *\n * Lives here rather than in each loader: a `theme.config` module may export either\n * shape, and every loader has to tell them apart the same way or dev and prod\n * disagree on what counts as already-validated.\n */\nexport function isResolvedTheme(value: unknown): value is ResolvedTheme {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'light' in value &&\n 'dark' in value &&\n typeof (value as ResolvedTheme).radius === 'string' &&\n typeof (value as ResolvedTheme).fontSans === 'string'\n );\n}\n\n/**\n * The keys of each colour group, in CSS emission order.\n *\n * Single source: validation, resolution and the DTCG generator all read these, so\n * a new token cannot be added to half the pipeline. Internal — `src/index.ts`\n * decides the public API.\n */\nexport const SPACE_KEYS = ['crm', 'experience', 'influence', 'pilotage', 'proSante'] as const;\nexport const STATUS_KEYS = ['success', 'pending', 'approved', 'blocked', 'paused', 'info'] as const;\nconst CHART_COUNT = 5;\n\nfunction requireColor(value: unknown, path: string): string {\n if (typeof value !== 'string' || value.trim() === '') {\n throw new Error(`theme: \\`${path}\\` must be a non-empty colour string`);\n }\n // The generated CSS is inlined into a <style> tag, so a value carrying markup\n // would escape it. No colour needs these characters.\n if (/[<>]/.test(value)) {\n throw new Error(`theme: \\`${path}\\` must not contain \\`<\\` or \\`>\\``);\n }\n return value;\n}\n\nfunction requireGroup(value: unknown, path: string): void {\n if (typeof value !== 'object' || value === null) {\n throw new Error(`theme: \\`${path}\\` must be an object`);\n }\n}\n\n/** One colour group, overrides layered over the base, every key checked. */\nfunction resolveGroup<K extends string>(\n keys: readonly K[],\n base: Record<K, string>,\n overrides: Partial<Record<K, string>> | undefined,\n path: string,\n): Record<K, string> {\n requireGroup(base, path);\n // A non-object override is not a partial override — it is every key silently\n // falling back to light, which is exactly the bug this package exists to stop.\n if (overrides !== undefined) requireGroup(overrides, path);\n return Object.fromEntries(\n keys.map((key) => [key, requireColor(overrides?.[key] ?? base[key], `${path}.${key}`)]),\n ) as Record<K, string>;\n}\n\nfunction resolveScheme(\n base: ThemeScheme,\n overrides: ThemeConfig['dark'],\n path: 'light' | 'dark',\n): ThemeScheme {\n const spaces = resolveGroup(SPACE_KEYS, base.spaces, overrides?.spaces, `${path}.spaces`);\n const status = resolveGroup(STATUS_KEYS, base.status, overrides?.status, `${path}.status`);\n\n const charts = overrides?.charts ?? base.charts;\n if (!Array.isArray(charts) || charts.length !== CHART_COUNT) {\n throw new Error(`theme: \\`${path}.charts\\` must hold exactly ${CHART_COUNT} colours`);\n }\n charts.forEach((value, i) => requireColor(value, `${path}.charts[${i}]`));\n\n return {\n primary: requireColor(overrides?.primary ?? base.primary, `${path}.primary`),\n spaces,\n status,\n charts,\n };\n}\n\n/**\n * Validate a theme and resolve its dark scheme against its light one.\n *\n * The type makes an unknown or missing key a compile error; the checks here make\n * it a loud runtime error too, because `theme.config.ts` is loaded as plain JS by\n * the API and TypeScript is not there to catch it.\n */\nexport function defineTheme(config: ThemeConfig): ResolvedTheme {\n if (typeof config?.radius !== 'string' || config.radius.trim() === '') {\n throw new Error('theme: `radius` must be a non-empty CSS length');\n }\n if (typeof config.fontSans !== 'string' || config.fontSans.trim() === '') {\n throw new Error('theme: `fontSans` must be a non-empty font stack');\n }\n\n if (config.dark !== undefined) requireGroup(config.dark, 'dark');\n\n const light = resolveScheme(config, undefined, 'light');\n return {\n radius: config.radius,\n fontSans: config.fontSans,\n light,\n dark: resolveScheme(light, config.dark, 'dark'),\n };\n}\n","/**\n * The theme the platform ships with — and the fallback compiled into\n * `apps/web/src/index.css`, so a failed runtime injection degrades to \"neutral\n * but usable\", never to unstyled.\n *\n * Colours are OKLCH so lightness is perceptual: the dark scheme is the same hue\n * lifted to a legible lightness, not a different palette.\n */\nimport { defineTheme } from './theme.js';\n\n/**\n * Brand blue, from the Figma source of truth (`#3B5CF5`).\n * Contrast: 4.85:1 on the light background, 4.99:1 for `--primary-foreground` on it.\n */\nconst BRAND = 'oklch(0.549 0.231 268.1)';\n/** Same hue lifted for the dark scheme: 6.07:1 on the dark card, 6.59:1 for its label. */\nconst BRAND_DARK = 'oklch(0.68 0.16 268.1)';\n\nexport const defaultTheme = defineTheme({\n // Figma: 8px corners on inputs and buttons.\n radius: '0.5rem',\n // Inter is the Figma typeface but the platform does not bundle it yet, so this\n // reads as \"Inter if the machine has it, system stack otherwise\".\n fontSans:\n \"Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif\",\n\n primary: BRAND,\n\n spaces: {\n crm: 'oklch(0.554 0.215 268.1)',\n experience: 'oklch(0.62 0.13 233)',\n influence: 'oklch(0.64 0.2 350)',\n pilotage: 'oklch(0.7 0.16 62)',\n proSante: 'oklch(0.62 0.11 172)',\n },\n\n status: {\n success: 'oklch(0.62 0.16 150)',\n pending: 'oklch(0.72 0.15 75)',\n approved: 'oklch(0.554 0.215 268.1)',\n blocked: 'oklch(0.58 0.22 27)',\n paused: 'oklch(0.7 0.02 268.1)',\n info: 'oklch(0.62 0.13 233)',\n },\n\n /**\n * Categorical palette: five hues spread from the brand around the wheel, all at\n * one lightness so no series reads as \"louder\" than another. Every entry clears\n * 4.5:1 on white — well past the 3:1 WCAG asks of a graphical object.\n */\n charts: [\n 'oklch(0.55 0.2 268.1)',\n 'oklch(0.55 0.09 196)',\n 'oklch(0.55 0.15 150)',\n 'oklch(0.55 0.115 70)',\n 'oklch(0.55 0.2 345)',\n ],\n\n dark: {\n primary: BRAND_DARK,\n spaces: {\n crm: 'oklch(0.74 0.135 268.1)',\n experience: 'oklch(0.74 0.13 233)',\n influence: 'oklch(0.74 0.19 350)',\n pilotage: 'oklch(0.74 0.16 62)',\n proSante: 'oklch(0.74 0.11 172)',\n },\n status: {\n success: 'oklch(0.74 0.16 150)',\n pending: 'oklch(0.74 0.15 75)',\n approved: 'oklch(0.74 0.135 268.1)',\n blocked: 'oklch(0.74 0.155 27)',\n paused: 'oklch(0.74 0.02 268.1)',\n info: 'oklch(0.74 0.13 233)',\n },\n // Same hues, lifted to ~7:1 on the dark card.\n charts: [\n 'oklch(0.74 0.13 268.1)',\n 'oklch(0.74 0.125 196)',\n 'oklch(0.74 0.17 150)',\n 'oklch(0.74 0.16 70)',\n 'oklch(0.74 0.17 345)',\n ],\n },\n});\n","/**\n * DTCG (W3C Design Tokens) as the generator's intermediate format.\n *\n * Nothing here is public API — `themeToCss` is. The point of the detour is that a\n * Figma Variables export speaks DTCG: when that lands it plugs in as another\n * producer of these groups instead of a rewrite of the CSS generator.\n *\n * Token path → CSS custom property is mechanical: kebab-case each segment and\n * join with `-`. `space.proSante` → `--space-pro-sante`, `font.sans` →\n * `--font-sans`, `chart.1` → `--chart-1`. That is why the group names below are\n * the CSS prefixes and not prettier words.\n */\nimport { SPACE_KEYS, STATUS_KEYS, type ResolvedTheme, type ThemeScheme } from './theme.js';\n\nexport type DtcgType = 'color' | 'dimension' | 'fontFamily';\n\nexport interface DtcgToken {\n $type: DtcgType;\n $value: string;\n}\n\nexport interface DtcgGroup {\n [key: string]: DtcgToken | DtcgGroup;\n}\n\nconst isToken = (node: DtcgToken | DtcgGroup): node is DtcgToken => '$value' in node;\n\nconst color = ($value: string): DtcgToken => ({ $type: 'color', $value });\n\nconst colorGroup = <K extends string>(keys: readonly K[], group: Record<K, string>): DtcgGroup =>\n Object.fromEntries(keys.map((key) => [key, color(group[key])]));\n\n/** Colour tokens of one scheme — the keys that must exist in both `:root` and `.dark`. */\nexport function schemeToDtcg(scheme: ThemeScheme): DtcgGroup {\n return {\n primary: color(scheme.primary),\n space: colorGroup(SPACE_KEYS, scheme.spaces),\n status: colorGroup(STATUS_KEYS, scheme.status),\n chart: Object.fromEntries(scheme.charts.map((value, i) => [String(i + 1), color(value)])),\n };\n}\n\n/** Tokens that do not vary by scheme, so they are emitted in `:root` only. */\nexport function invariantsToDtcg(theme: ResolvedTheme): DtcgGroup {\n return {\n radius: { $type: 'dimension', $value: theme.radius },\n font: { sans: { $type: 'fontFamily', $value: theme.fontSans } },\n };\n}\n\nconst kebab = (segment: string) => segment.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();\n\n/** `--custom-property: value;` for every token in the group, depth-first. */\nexport function dtcgToCustomProperties(group: DtcgGroup, path: string[] = []): string[] {\n return Object.entries(group).flatMap(([key, node]) => {\n const next = [...path, kebab(key)];\n return isToken(node)\n ? [`--${next.join('-')}: ${node.$value};`]\n : dtcgToCustomProperties(node, next);\n });\n}\n","import { dtcgToCustomProperties, invariantsToDtcg, schemeToDtcg } from './dtcg.js';\nimport type { ResolvedTheme } from './theme.js';\n\n/**\n * The id carried by the `<style>` tag this CSS is inlined into — the handle the\n * live theme is found by (`document.getElementById('apotech-theme')`).\n *\n * It is a cross-process contract: the API inlines the tag in production and the\n * dev Vite plugin inlines it in `pnpm dev`, so both must spell it the same way.\n */\nexport const THEME_STYLE_ID = 'apotech-theme';\n\nconst block = (selector: string, declarations: string[]) =>\n `${selector} {\\n${declarations.map((line) => ` ${line}`).join('\\n')}\\n}`;\n\n/**\n * Render a theme as `:root { … } .dark { … }`.\n *\n * Only *values* are emitted. The `@theme inline` vocabulary that teaches Tailwind\n * about `bg-primary` and friends stays at build time in `index.css` — a client\n * restyles the words, it does not add any.\n */\nexport function themeToCss(theme: ResolvedTheme): string {\n const root = [\n ...dtcgToCustomProperties(invariantsToDtcg(theme)),\n ...dtcgToCustomProperties(schemeToDtcg(theme.light)),\n ];\n return `${block(':root', root)}\\n${block('.dark', dtcgToCustomProperties(schemeToDtcg(theme.dark)))}\\n`;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@apotech-os/tokens",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.cts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/apotech-studio/wopilo-os.git"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"tsup": "^8.5.0",
|
|
32
|
+
"typescript": "~5.9.3",
|
|
33
|
+
"vitest": "^4.1.9"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup",
|
|
37
|
+
"dev": "tsup --watch",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"test": "vitest run"
|
|
40
|
+
}
|
|
41
|
+
}
|