@apotech-os/tokens 0.9.0 → 2.0.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 +39 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -1
- package/dist/index.d.ts +44 -1
- package/dist/index.js +36 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -78,12 +78,12 @@ var defaultTheme = defineTheme({
|
|
|
78
78
|
proSante: "oklch(0.62 0.11 172)"
|
|
79
79
|
},
|
|
80
80
|
status: {
|
|
81
|
-
success: "oklch(0.
|
|
82
|
-
pending: "oklch(0.
|
|
83
|
-
approved: "oklch(0.
|
|
84
|
-
blocked: "oklch(0.
|
|
85
|
-
paused: "oklch(0.
|
|
86
|
-
info: "oklch(0.
|
|
81
|
+
success: "oklch(0.51 0.14 150)",
|
|
82
|
+
pending: "oklch(0.535 0.11 75)",
|
|
83
|
+
approved: "oklch(0.545 0.235 268.1)",
|
|
84
|
+
blocked: "oklch(0.545 0.22 27)",
|
|
85
|
+
paused: "oklch(0.53 0.04 268.1)",
|
|
86
|
+
info: "oklch(0.52 0.105 233)"
|
|
87
87
|
},
|
|
88
88
|
/**
|
|
89
89
|
* Categorical palette: five hues spread from the brand around the wheel, all at
|
|
@@ -125,6 +125,35 @@ var defaultTheme = defineTheme({
|
|
|
125
125
|
}
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
+
// src/primitives.ts
|
|
129
|
+
var TYPE_SCALE = [
|
|
130
|
+
{ key: "xs", size: "0.75rem", lineHeight: "calc(1 / 0.75)", figmaPx: 11 },
|
|
131
|
+
{ key: "sm", size: "0.875rem", lineHeight: "calc(1.25 / 0.875)", figmaPx: 12 },
|
|
132
|
+
{ key: "base", size: "1rem", lineHeight: "calc(1.5 / 1)", figmaPx: 13 },
|
|
133
|
+
{ key: "lg", size: "1.125rem", lineHeight: "calc(1.75 / 1.125)", figmaPx: 18 },
|
|
134
|
+
{ key: "xl", size: "1.25rem", lineHeight: "calc(1.75 / 1.25)", figmaPx: 20 },
|
|
135
|
+
{ key: "2xl", size: "1.5rem", lineHeight: "calc(2 / 1.5)", figmaPx: 22 },
|
|
136
|
+
{ key: "3xl", size: "1.875rem", lineHeight: "calc(2.25 / 1.875)" }
|
|
137
|
+
];
|
|
138
|
+
var SPACING_STEP = "0.25rem";
|
|
139
|
+
var SHADOWS = {
|
|
140
|
+
card: "0 10px 30px -8px oklch(0.2 0.03 268.1 / 0.1)"
|
|
141
|
+
};
|
|
142
|
+
function primitivesToCss() {
|
|
143
|
+
const lines = [
|
|
144
|
+
...TYPE_SCALE.flatMap((step) => [
|
|
145
|
+
`--text-${step.key}: ${step.size};`,
|
|
146
|
+
`--text-${step.key}--line-height: ${step.lineHeight};`
|
|
147
|
+
]),
|
|
148
|
+
`--spacing: ${SPACING_STEP};`,
|
|
149
|
+
...Object.entries(SHADOWS).map(([key, value]) => `--shadow-${key}: ${value};`)
|
|
150
|
+
];
|
|
151
|
+
return `@theme {
|
|
152
|
+
${lines.map((line) => ` ${line}`).join("\n")}
|
|
153
|
+
}
|
|
154
|
+
`;
|
|
155
|
+
}
|
|
156
|
+
|
|
128
157
|
// src/dtcg.ts
|
|
129
158
|
var isToken = (node) => "$value" in node;
|
|
130
159
|
var color = ($value) => ({ $type: "color", $value });
|
|
@@ -166,10 +195,14 @@ ${block(".dark", dtcgToCustomProperties(schemeToDtcg(theme.dark)))}
|
|
|
166
195
|
`;
|
|
167
196
|
}
|
|
168
197
|
|
|
198
|
+
exports.SHADOWS = SHADOWS;
|
|
199
|
+
exports.SPACING_STEP = SPACING_STEP;
|
|
169
200
|
exports.THEME_STYLE_ID = THEME_STYLE_ID;
|
|
201
|
+
exports.TYPE_SCALE = TYPE_SCALE;
|
|
170
202
|
exports.defaultTheme = defaultTheme;
|
|
171
203
|
exports.defineTheme = defineTheme;
|
|
172
204
|
exports.isResolvedTheme = isResolvedTheme;
|
|
205
|
+
exports.primitivesToCss = primitivesToCss;
|
|
173
206
|
exports.themeToCss = themeToCss;
|
|
174
207
|
//# sourceMappingURL=index.cjs.map
|
|
175
208
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +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,CAAA,EAAG;AACtB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,SAAA,EAAY,IAAI,CAAA,kCAAA,CAAoC,CAAA;AAAA,EACtE;AACA,EAAA,OAAO,KAAA;AACT;AAEA,SAAS,YAAA,CAAa,OAAgB,IAAA,EAAoB;AACxD,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA,EAAM;AA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Q,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.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"]}
|
|
1
|
+
{"version":3,"sources":["../src/theme.ts","../src/default-theme.ts","../src/primitives.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,CAAA,EAAG;AACtB,IAAA,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I,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.51 0.14 150)',\n pending: 'oklch(0.535 0.11 75)',\n approved: 'oklch(0.545 0.235 268.1)',\n blocked: 'oklch(0.545 0.22 27)',\n paused: 'oklch(0.53 0.04 268.1)',\n info: 'oklch(0.52 0.105 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 * The primitive scales — type, spacing, elevation.\n *\n * Not part of `ThemeConfig`: an instance restyles the brand, it does not redraw\n * the grid the product is built on. They live here rather than being inherited\n * from Tailwind's defaults so the platform owns them: a Tailwind upgrade cannot\n * move the product's type, and P4's generated catalogue has one place to read.\n *\n * The values are today's, deliberately. Figma's hi-fi frames use a denser scale\n * (11 / 12 / 13 / 18 / 20 / 22 px against 12 / 14 / 16 / 18 / 20 / 24) and the\n * observed figure is recorded on each step — adopting it moves every screen in\n * the product, so it is a decision with a visual audit attached, not a rename.\n * When that decision is made, it is made here.\n */\n\nexport interface TypeStep {\n /** Tailwind's `text-<key>`. */\n key: string;\n size: string;\n /** Paired line height. Tailwind reads it as `--text-<key>--line-height`. */\n lineHeight: string;\n /** What the Figma frames use at this step, for the day the scale is reconciled. */\n figmaPx?: number;\n}\n\nexport const TYPE_SCALE: readonly TypeStep[] = [\n { key: 'xs', size: '0.75rem', lineHeight: 'calc(1 / 0.75)', figmaPx: 11 },\n { key: 'sm', size: '0.875rem', lineHeight: 'calc(1.25 / 0.875)', figmaPx: 12 },\n { key: 'base', size: '1rem', lineHeight: 'calc(1.5 / 1)', figmaPx: 13 },\n { key: 'lg', size: '1.125rem', lineHeight: 'calc(1.75 / 1.125)', figmaPx: 18 },\n { key: 'xl', size: '1.25rem', lineHeight: 'calc(1.75 / 1.25)', figmaPx: 20 },\n { key: '2xl', size: '1.5rem', lineHeight: 'calc(2 / 1.5)', figmaPx: 22 },\n { key: '3xl', size: '1.875rem', lineHeight: 'calc(2.25 / 1.875)' },\n];\n\n/**\n * The step every `p-`, `gap-` and `m-` utility multiplies. Figma's frames sit on\n * the same 4px grid, so this one needs no reconciling.\n */\nexport const SPACING_STEP = '0.25rem';\n\n/**\n * Figma has exactly one card elevation, and it is cool-tinted and wide where\n * Tailwind's defaults are neutral and tight. Offered as its own token rather\n * than by overriding `--shadow-sm`, which would restyle every existing surface.\n */\nexport const SHADOWS: Readonly<Record<string, string>> = {\n card: '0 10px 30px -8px oklch(0.2 0.03 268.1 / 0.1)',\n};\n\n/**\n * The primitives as a Tailwind `@theme` block.\n *\n * `@theme`, not `:root`: these are the vocabulary Tailwind generates utilities\n * from, and unlike the brand layer they are fixed at build time.\n */\nexport function primitivesToCss(): string {\n const lines = [\n ...TYPE_SCALE.flatMap((step) => [\n `--text-${step.key}: ${step.size};`,\n `--text-${step.key}--line-height: ${step.lineHeight};`,\n ]),\n `--spacing: ${SPACING_STEP};`,\n ...Object.entries(SHADOWS).map(([key, value]) => `--shadow-${key}: ${value};`),\n ];\n return `@theme {\\n${lines.map((line) => ` ${line}`).join('\\n')}\\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
CHANGED
|
@@ -83,6 +83,49 @@ declare function defineTheme(config: ThemeConfig): ResolvedTheme;
|
|
|
83
83
|
|
|
84
84
|
declare const defaultTheme: ResolvedTheme;
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* The primitive scales — type, spacing, elevation.
|
|
88
|
+
*
|
|
89
|
+
* Not part of `ThemeConfig`: an instance restyles the brand, it does not redraw
|
|
90
|
+
* the grid the product is built on. They live here rather than being inherited
|
|
91
|
+
* from Tailwind's defaults so the platform owns them: a Tailwind upgrade cannot
|
|
92
|
+
* move the product's type, and P4's generated catalogue has one place to read.
|
|
93
|
+
*
|
|
94
|
+
* The values are today's, deliberately. Figma's hi-fi frames use a denser scale
|
|
95
|
+
* (11 / 12 / 13 / 18 / 20 / 22 px against 12 / 14 / 16 / 18 / 20 / 24) and the
|
|
96
|
+
* observed figure is recorded on each step — adopting it moves every screen in
|
|
97
|
+
* the product, so it is a decision with a visual audit attached, not a rename.
|
|
98
|
+
* When that decision is made, it is made here.
|
|
99
|
+
*/
|
|
100
|
+
interface TypeStep {
|
|
101
|
+
/** Tailwind's `text-<key>`. */
|
|
102
|
+
key: string;
|
|
103
|
+
size: string;
|
|
104
|
+
/** Paired line height. Tailwind reads it as `--text-<key>--line-height`. */
|
|
105
|
+
lineHeight: string;
|
|
106
|
+
/** What the Figma frames use at this step, for the day the scale is reconciled. */
|
|
107
|
+
figmaPx?: number;
|
|
108
|
+
}
|
|
109
|
+
declare const TYPE_SCALE: readonly TypeStep[];
|
|
110
|
+
/**
|
|
111
|
+
* The step every `p-`, `gap-` and `m-` utility multiplies. Figma's frames sit on
|
|
112
|
+
* the same 4px grid, so this one needs no reconciling.
|
|
113
|
+
*/
|
|
114
|
+
declare const SPACING_STEP = "0.25rem";
|
|
115
|
+
/**
|
|
116
|
+
* Figma has exactly one card elevation, and it is cool-tinted and wide where
|
|
117
|
+
* Tailwind's defaults are neutral and tight. Offered as its own token rather
|
|
118
|
+
* than by overriding `--shadow-sm`, which would restyle every existing surface.
|
|
119
|
+
*/
|
|
120
|
+
declare const SHADOWS: Readonly<Record<string, string>>;
|
|
121
|
+
/**
|
|
122
|
+
* The primitives as a Tailwind `@theme` block.
|
|
123
|
+
*
|
|
124
|
+
* `@theme`, not `:root`: these are the vocabulary Tailwind generates utilities
|
|
125
|
+
* from, and unlike the brand layer they are fixed at build time.
|
|
126
|
+
*/
|
|
127
|
+
declare function primitivesToCss(): string;
|
|
128
|
+
|
|
86
129
|
/**
|
|
87
130
|
* The id carried by the `<style>` tag this CSS is inlined into — the handle the
|
|
88
131
|
* live theme is found by (`document.getElementById('apotech-theme')`).
|
|
@@ -100,4 +143,4 @@ declare const THEME_STYLE_ID = "apotech-theme";
|
|
|
100
143
|
*/
|
|
101
144
|
declare function themeToCss(theme: ResolvedTheme): string;
|
|
102
145
|
|
|
103
|
-
export { type ResolvedTheme, THEME_STYLE_ID, type ThemeCharts, type ThemeConfig, type ThemeScheme, type ThemeSpaces, type ThemeStatus, defaultTheme, defineTheme, isResolvedTheme, themeToCss };
|
|
146
|
+
export { type ResolvedTheme, SHADOWS, SPACING_STEP, THEME_STYLE_ID, TYPE_SCALE, type ThemeCharts, type ThemeConfig, type ThemeScheme, type ThemeSpaces, type ThemeStatus, type TypeStep, defaultTheme, defineTheme, isResolvedTheme, primitivesToCss, themeToCss };
|
package/dist/index.d.ts
CHANGED
|
@@ -83,6 +83,49 @@ declare function defineTheme(config: ThemeConfig): ResolvedTheme;
|
|
|
83
83
|
|
|
84
84
|
declare const defaultTheme: ResolvedTheme;
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* The primitive scales — type, spacing, elevation.
|
|
88
|
+
*
|
|
89
|
+
* Not part of `ThemeConfig`: an instance restyles the brand, it does not redraw
|
|
90
|
+
* the grid the product is built on. They live here rather than being inherited
|
|
91
|
+
* from Tailwind's defaults so the platform owns them: a Tailwind upgrade cannot
|
|
92
|
+
* move the product's type, and P4's generated catalogue has one place to read.
|
|
93
|
+
*
|
|
94
|
+
* The values are today's, deliberately. Figma's hi-fi frames use a denser scale
|
|
95
|
+
* (11 / 12 / 13 / 18 / 20 / 22 px against 12 / 14 / 16 / 18 / 20 / 24) and the
|
|
96
|
+
* observed figure is recorded on each step — adopting it moves every screen in
|
|
97
|
+
* the product, so it is a decision with a visual audit attached, not a rename.
|
|
98
|
+
* When that decision is made, it is made here.
|
|
99
|
+
*/
|
|
100
|
+
interface TypeStep {
|
|
101
|
+
/** Tailwind's `text-<key>`. */
|
|
102
|
+
key: string;
|
|
103
|
+
size: string;
|
|
104
|
+
/** Paired line height. Tailwind reads it as `--text-<key>--line-height`. */
|
|
105
|
+
lineHeight: string;
|
|
106
|
+
/** What the Figma frames use at this step, for the day the scale is reconciled. */
|
|
107
|
+
figmaPx?: number;
|
|
108
|
+
}
|
|
109
|
+
declare const TYPE_SCALE: readonly TypeStep[];
|
|
110
|
+
/**
|
|
111
|
+
* The step every `p-`, `gap-` and `m-` utility multiplies. Figma's frames sit on
|
|
112
|
+
* the same 4px grid, so this one needs no reconciling.
|
|
113
|
+
*/
|
|
114
|
+
declare const SPACING_STEP = "0.25rem";
|
|
115
|
+
/**
|
|
116
|
+
* Figma has exactly one card elevation, and it is cool-tinted and wide where
|
|
117
|
+
* Tailwind's defaults are neutral and tight. Offered as its own token rather
|
|
118
|
+
* than by overriding `--shadow-sm`, which would restyle every existing surface.
|
|
119
|
+
*/
|
|
120
|
+
declare const SHADOWS: Readonly<Record<string, string>>;
|
|
121
|
+
/**
|
|
122
|
+
* The primitives as a Tailwind `@theme` block.
|
|
123
|
+
*
|
|
124
|
+
* `@theme`, not `:root`: these are the vocabulary Tailwind generates utilities
|
|
125
|
+
* from, and unlike the brand layer they are fixed at build time.
|
|
126
|
+
*/
|
|
127
|
+
declare function primitivesToCss(): string;
|
|
128
|
+
|
|
86
129
|
/**
|
|
87
130
|
* The id carried by the `<style>` tag this CSS is inlined into — the handle the
|
|
88
131
|
* live theme is found by (`document.getElementById('apotech-theme')`).
|
|
@@ -100,4 +143,4 @@ declare const THEME_STYLE_ID = "apotech-theme";
|
|
|
100
143
|
*/
|
|
101
144
|
declare function themeToCss(theme: ResolvedTheme): string;
|
|
102
145
|
|
|
103
|
-
export { type ResolvedTheme, THEME_STYLE_ID, type ThemeCharts, type ThemeConfig, type ThemeScheme, type ThemeSpaces, type ThemeStatus, defaultTheme, defineTheme, isResolvedTheme, themeToCss };
|
|
146
|
+
export { type ResolvedTheme, SHADOWS, SPACING_STEP, THEME_STYLE_ID, TYPE_SCALE, type ThemeCharts, type ThemeConfig, type ThemeScheme, type ThemeSpaces, type ThemeStatus, type TypeStep, defaultTheme, defineTheme, isResolvedTheme, primitivesToCss, themeToCss };
|
package/dist/index.js
CHANGED
|
@@ -76,12 +76,12 @@ var defaultTheme = defineTheme({
|
|
|
76
76
|
proSante: "oklch(0.62 0.11 172)"
|
|
77
77
|
},
|
|
78
78
|
status: {
|
|
79
|
-
success: "oklch(0.
|
|
80
|
-
pending: "oklch(0.
|
|
81
|
-
approved: "oklch(0.
|
|
82
|
-
blocked: "oklch(0.
|
|
83
|
-
paused: "oklch(0.
|
|
84
|
-
info: "oklch(0.
|
|
79
|
+
success: "oklch(0.51 0.14 150)",
|
|
80
|
+
pending: "oklch(0.535 0.11 75)",
|
|
81
|
+
approved: "oklch(0.545 0.235 268.1)",
|
|
82
|
+
blocked: "oklch(0.545 0.22 27)",
|
|
83
|
+
paused: "oklch(0.53 0.04 268.1)",
|
|
84
|
+
info: "oklch(0.52 0.105 233)"
|
|
85
85
|
},
|
|
86
86
|
/**
|
|
87
87
|
* Categorical palette: five hues spread from the brand around the wheel, all at
|
|
@@ -123,6 +123,35 @@ var defaultTheme = defineTheme({
|
|
|
123
123
|
}
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
+
// src/primitives.ts
|
|
127
|
+
var TYPE_SCALE = [
|
|
128
|
+
{ key: "xs", size: "0.75rem", lineHeight: "calc(1 / 0.75)", figmaPx: 11 },
|
|
129
|
+
{ key: "sm", size: "0.875rem", lineHeight: "calc(1.25 / 0.875)", figmaPx: 12 },
|
|
130
|
+
{ key: "base", size: "1rem", lineHeight: "calc(1.5 / 1)", figmaPx: 13 },
|
|
131
|
+
{ key: "lg", size: "1.125rem", lineHeight: "calc(1.75 / 1.125)", figmaPx: 18 },
|
|
132
|
+
{ key: "xl", size: "1.25rem", lineHeight: "calc(1.75 / 1.25)", figmaPx: 20 },
|
|
133
|
+
{ key: "2xl", size: "1.5rem", lineHeight: "calc(2 / 1.5)", figmaPx: 22 },
|
|
134
|
+
{ key: "3xl", size: "1.875rem", lineHeight: "calc(2.25 / 1.875)" }
|
|
135
|
+
];
|
|
136
|
+
var SPACING_STEP = "0.25rem";
|
|
137
|
+
var SHADOWS = {
|
|
138
|
+
card: "0 10px 30px -8px oklch(0.2 0.03 268.1 / 0.1)"
|
|
139
|
+
};
|
|
140
|
+
function primitivesToCss() {
|
|
141
|
+
const lines = [
|
|
142
|
+
...TYPE_SCALE.flatMap((step) => [
|
|
143
|
+
`--text-${step.key}: ${step.size};`,
|
|
144
|
+
`--text-${step.key}--line-height: ${step.lineHeight};`
|
|
145
|
+
]),
|
|
146
|
+
`--spacing: ${SPACING_STEP};`,
|
|
147
|
+
...Object.entries(SHADOWS).map(([key, value]) => `--shadow-${key}: ${value};`)
|
|
148
|
+
];
|
|
149
|
+
return `@theme {
|
|
150
|
+
${lines.map((line) => ` ${line}`).join("\n")}
|
|
151
|
+
}
|
|
152
|
+
`;
|
|
153
|
+
}
|
|
154
|
+
|
|
126
155
|
// src/dtcg.ts
|
|
127
156
|
var isToken = (node) => "$value" in node;
|
|
128
157
|
var color = ($value) => ({ $type: "color", $value });
|
|
@@ -164,6 +193,6 @@ ${block(".dark", dtcgToCustomProperties(schemeToDtcg(theme.dark)))}
|
|
|
164
193
|
`;
|
|
165
194
|
}
|
|
166
195
|
|
|
167
|
-
export { THEME_STYLE_ID, defaultTheme, defineTheme, isResolvedTheme, themeToCss };
|
|
196
|
+
export { SHADOWS, SPACING_STEP, THEME_STYLE_ID, TYPE_SCALE, defaultTheme, defineTheme, isResolvedTheme, primitivesToCss, themeToCss };
|
|
168
197
|
//# sourceMappingURL=index.js.map
|
|
169
198
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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,CAAA,EAAG;AACtB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,SAAA,EAAY,IAAI,CAAA,kCAAA,CAAoC,CAAA;AAAA,EACtE;AACA,EAAA,OAAO,KAAA;AACT;AAEA,SAAS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A,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"]}
|
|
1
|
+
{"version":3,"sources":["../src/theme.ts","../src/default-theme.ts","../src/primitives.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,o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AAA,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.51 0.14 150)',\n pending: 'oklch(0.535 0.11 75)',\n approved: 'oklch(0.545 0.235 268.1)',\n blocked: 'oklch(0.545 0.22 27)',\n paused: 'oklch(0.53 0.04 268.1)',\n info: 'oklch(0.52 0.105 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 * The primitive scales — type, spacing, elevation.\n *\n * Not part of `ThemeConfig`: an instance restyles the brand, it does not redraw\n * the grid the product is built on. They live here rather than being inherited\n * from Tailwind's defaults so the platform owns them: a Tailwind upgrade cannot\n * move the product's type, and P4's generated catalogue has one place to read.\n *\n * The values are today's, deliberately. Figma's hi-fi frames use a denser scale\n * (11 / 12 / 13 / 18 / 20 / 22 px against 12 / 14 / 16 / 18 / 20 / 24) and the\n * observed figure is recorded on each step — adopting it moves every screen in\n * the product, so it is a decision with a visual audit attached, not a rename.\n * When that decision is made, it is made here.\n */\n\nexport interface TypeStep {\n /** Tailwind's `text-<key>`. */\n key: string;\n size: string;\n /** Paired line height. Tailwind reads it as `--text-<key>--line-height`. */\n lineHeight: string;\n /** What the Figma frames use at this step, for the day the scale is reconciled. */\n figmaPx?: number;\n}\n\nexport const TYPE_SCALE: readonly TypeStep[] = [\n { key: 'xs', size: '0.75rem', lineHeight: 'calc(1 / 0.75)', figmaPx: 11 },\n { key: 'sm', size: '0.875rem', lineHeight: 'calc(1.25 / 0.875)', figmaPx: 12 },\n { key: 'base', size: '1rem', lineHeight: 'calc(1.5 / 1)', figmaPx: 13 },\n { key: 'lg', size: '1.125rem', lineHeight: 'calc(1.75 / 1.125)', figmaPx: 18 },\n { key: 'xl', size: '1.25rem', lineHeight: 'calc(1.75 / 1.25)', figmaPx: 20 },\n { key: '2xl', size: '1.5rem', lineHeight: 'calc(2 / 1.5)', figmaPx: 22 },\n { key: '3xl', size: '1.875rem', lineHeight: 'calc(2.25 / 1.875)' },\n];\n\n/**\n * The step every `p-`, `gap-` and `m-` utility multiplies. Figma's frames sit on\n * the same 4px grid, so this one needs no reconciling.\n */\nexport const SPACING_STEP = '0.25rem';\n\n/**\n * Figma has exactly one card elevation, and it is cool-tinted and wide where\n * Tailwind's defaults are neutral and tight. Offered as its own token rather\n * than by overriding `--shadow-sm`, which would restyle every existing surface.\n */\nexport const SHADOWS: Readonly<Record<string, string>> = {\n card: '0 10px 30px -8px oklch(0.2 0.03 268.1 / 0.1)',\n};\n\n/**\n * The primitives as a Tailwind `@theme` block.\n *\n * `@theme`, not `:root`: these are the vocabulary Tailwind generates utilities\n * from, and unlike the brand layer they are fixed at build time.\n */\nexport function primitivesToCss(): string {\n const lines = [\n ...TYPE_SCALE.flatMap((step) => [\n `--text-${step.key}: ${step.size};`,\n `--text-${step.key}--line-height: ${step.lineHeight};`,\n ]),\n `--spacing: ${SPACING_STEP};`,\n ...Object.entries(SHADOWS).map(([key, value]) => `--shadow-${key}: ${value};`),\n ];\n return `@theme {\\n${lines.map((line) => ` ${line}`).join('\\n')}\\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"]}
|