@recanica/tokens 0.0.0-stage → 0.2.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.
@@ -0,0 +1,57 @@
1
+ // GENERATED by @recanica/tokens (scripts/build.mjs) from tokens/*.json. Do not edit.
2
+ // Tailwind CSS v3 preset. Also import "@recanica/tokens/variables.css" in your global CSS.
3
+ /** @type {import('tailwindcss').Config} */
4
+ module.exports = {
5
+ darkMode: "class",
6
+ theme: {
7
+ extend: {
8
+ colors: {
9
+ "background": "var(--background)",
10
+ "foreground": "var(--foreground)",
11
+ "surface": "var(--surface)",
12
+ "panel": "var(--panel)",
13
+ "card": "var(--card)",
14
+ "card-foreground": "var(--card-foreground)",
15
+ "popover": "var(--popover)",
16
+ "popover-foreground": "var(--popover-foreground)",
17
+ "primary": "var(--primary)",
18
+ "primary-foreground": "var(--primary-foreground)",
19
+ "secondary": "var(--secondary)",
20
+ "secondary-foreground": "var(--secondary-foreground)",
21
+ "muted": "var(--muted)",
22
+ "muted-foreground": "var(--muted-foreground)",
23
+ "accent": "var(--accent)",
24
+ "accent-foreground": "var(--accent-foreground)",
25
+ "brand": "var(--brand)",
26
+ "brand-foreground": "var(--brand-foreground)",
27
+ "destructive": "var(--destructive)",
28
+ "destructive-foreground": "var(--destructive-foreground)",
29
+ "success": "var(--success)",
30
+ "warning": "var(--warning)",
31
+ "border": "var(--border)",
32
+ "input": "var(--input)",
33
+ "ring": "var(--ring)",
34
+ "sidebar": "var(--sidebar)",
35
+ "sidebar-foreground": "var(--sidebar-foreground)",
36
+ "sidebar-accent": "var(--sidebar-accent)",
37
+ "sidebar-border": "var(--sidebar-border)",
38
+ "sidebar-primary": "var(--sidebar-primary)",
39
+ "sidebar-primary-foreground": "var(--sidebar-primary-foreground)",
40
+ "sidebar-accent-foreground": "var(--sidebar-accent-foreground)",
41
+ "sidebar-ring": "var(--sidebar-ring)",
42
+ "chart-1": "var(--chart-1)",
43
+ "chart-2": "var(--chart-2)",
44
+ "chart-3": "var(--chart-3)",
45
+ "chart-4": "var(--chart-4)",
46
+ "chart-5": "var(--chart-5)"
47
+ },
48
+ borderRadius: {"sm":"calc(var(--radius) - 4px)","md":"calc(var(--radius) - 2px)","lg":"var(--radius)","xl":"calc(var(--radius) + 4px)","2xl":"calc(var(--radius) + 8px)"},
49
+ fontFamily: { sans: ["Geist","ui-sans-serif","system-ui","sans-serif"], mono: ["Geist Mono","ui-monospace","monospace"] },
50
+ spacing: {"gutter":"clamp(1rem, 3vw, 2.5rem)","section":"clamp(4rem, 10vw, 8rem)","section-sm":"clamp(3rem, 6vw, 5rem)","panel":"1.75rem","stack":"2.5rem","sidebar":"15rem","flow":"1.25rem","group":"0.75rem","inset-sm":"1rem","inset":"1.25rem"},
51
+ maxWidth: {"content":"72rem","narrow":"48rem","copy":"40rem"},
52
+ fontSize: {"heading":["clamp(1.25rem, 1.1464rem + 0.442vw, 1.5rem)",{"lineHeight":"1.25","letterSpacing":"-0.015em"}],"title":["clamp(1.625rem, 1.5214rem + 0.442vw, 1.875rem)",{"lineHeight":"1.2","letterSpacing":"-0.02em"}],"metric":["2.5rem",{"lineHeight":"1","letterSpacing":"-0.03em"}],"display-sm":["clamp(1.75rem, 1.5428rem + 0.884vw, 2.25rem)",{"lineHeight":"1.1"}],"display-md":["clamp(2.125rem, 1.7624rem + 1.547vw, 3rem)",{"lineHeight":"1.05"}],"display-lg":["clamp(2.5rem, 1.8785rem + 2.6519vw, 4rem)",{"lineHeight":"1","letterSpacing":"-0.035em"}]},
53
+ boxShadow: {"soft":"0 1px 2px 0 #0000000a, 0 4px 16px -4px #00000014","float":"0 2px 4px 0 #0000000a, 0 16px 40px -8px #00000029"},
54
+ transitionTimingFunction: {"out-soft":"cubic-bezier(0.22, 1, 0.36, 1)"},
55
+ },
56
+ },
57
+ };
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@recanica/tokens",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Recanica design tokens (W3C Design Tokens format) with outputs for CSS, Tailwind v3/v4, JS/TS, Flutter, SwiftUI, Jetpack Compose and Figma (Tokens Studio).",
5
+ "license": "MIT",
6
+ "author": "Aturanica Labs",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/booyen/recanica.git",
10
+ "directory": "packages/tokens"
11
+ },
12
+ "keywords": [
13
+ "design-tokens",
14
+ "design-system",
15
+ "tailwindcss",
16
+ "flutter",
17
+ "swiftui",
18
+ "jetpack-compose",
19
+ "recanica"
20
+ ],
21
+ "type": "module",
22
+ "sideEffects": [
23
+ "*.css"
24
+ ],
25
+ "exports": {
26
+ "./theme.css": "./theme.css",
27
+ "./variables.css": "./generated/css/variables.css",
28
+ "./tailwind-theme.css": "./generated/css/tailwind-theme.css",
29
+ "./tailwind-preset": "./generated/tailwind/preset.cjs",
30
+ ".": {
31
+ "types": "./generated/js/tokens.d.ts",
32
+ "import": "./generated/js/tokens.mjs",
33
+ "require": "./generated/js/tokens.cjs"
34
+ },
35
+ "./tokens.json": "./generated/json/tokens.json",
36
+ "./figma/tokens-studio.json": "./generated/figma/tokens-studio.json",
37
+ "./flutter/*": "./generated/flutter/*",
38
+ "./ios/*": "./generated/ios/*",
39
+ "./android/*": "./generated/android/*",
40
+ "./source/*": "./tokens/*"
41
+ },
42
+ "files": [
43
+ "theme.css",
44
+ "generated",
45
+ "tokens",
46
+ "scripts",
47
+ "README.md"
48
+ ],
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "scripts": {
53
+ "build": "node scripts/build.mjs",
54
+ "check": "node scripts/build.mjs --check"
55
+ }
6
56
  }
@@ -0,0 +1,344 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Recanica token build.
4
+ * Source of truth: tokens/*.json (W3C Design Tokens format).
5
+ * Output: generated/ — CSS, Tailwind v4 theme, Tailwind v3 preset, JS/TS, JSON,
6
+ * Flutter, SwiftUI, Jetpack Compose, Tokens Studio (Figma).
7
+ *
8
+ * node scripts/build.mjs write outputs
9
+ * node scripts/build.mjs --check fail if outputs are out of date (CI)
10
+ */
11
+ import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
12
+ import { dirname, join } from "node:path";
13
+
14
+ const root = join(import.meta.dirname, "..");
15
+ const out = join(root, "generated");
16
+ const CHECK = process.argv.includes("--check");
17
+ const HEADER = "GENERATED by @recanica/tokens (scripts/build.mjs) from tokens/*.json. Do not edit.";
18
+
19
+ /* ---------- load ---------- */
20
+ const files = readdirSync(join(root, "tokens")).filter((f) => f.endsWith(".json")).sort();
21
+ const T = Object.assign({}, ...files.map((f) => JSON.parse(readFileSync(join(root, "tokens", f), "utf8"))));
22
+ const ext = (t) => t?.$extensions?.["com.recanica"] ?? {};
23
+ const get = (path) => path.split(".").reduce((o, k) => o?.[k], T);
24
+ const refPath = (v) => (typeof v === "string" && /^\{.+\}$/.test(v) ? v.slice(1, -1) : null);
25
+ const resolve = (v) => { const p = refPath(v); return p ? resolve(get(p).$value) : v; };
26
+
27
+ /* ---------- colors ---------- */
28
+ // W3C groups may carry $description / $type metadata: never treat those keys as tokens.
29
+ const entries = (o) => Object.entries(o).filter(([k]) => !k.startsWith("$"));
30
+ const primitives = entries(T.rc).flatMap(([fam, steps]) =>
31
+ entries(steps).map(([step, t]) => ({ name: `rc-${fam}-${step}`, key: `${fam}-${step}`, hex: t.$value, oklch: ext(t).oklch }))
32
+ );
33
+ const semantic = entries(T.color).map(([name, t]) => {
34
+ const darkRef = ext(t).dark ?? t.$value;
35
+ return { name, lightRef: t.$value, darkRef, light: resolve(t.$value), dark: resolve(darkRef), hasDark: !!ext(t).dark };
36
+ });
37
+ const cssRef = (v) => { const p = refPath(v); return p ? `var(--${p.replace(/\./g, "-")})` : v; };
38
+ const camel = (s) => s.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
39
+ const pascal = (s) => camel(s).replace(/^./, (c) => c.toUpperCase());
40
+ const px = (v) => parseFloat(v);
41
+ const rem = (v) => `${+(px(v) / 16).toFixed(4)}rem`;
42
+
43
+ /* ---------- scales ---------- */
44
+ const radius = entries(T.radius).map(([k, t]) => ({ k, px: px(t.$value), css: ext(t).css ?? t.$value }));
45
+ const spacing = entries(T.spacing).map(([k, t]) => ({ k, px: px(t.$value), css: ext(t).css ?? t.$value, desc: t.$description }));
46
+ const containers = entries(T.container).map(([k, t]) => ({ k, px: px(t.$value), css: ext(t).css ?? t.$value }));
47
+ const text = entries(T.text).map(([k, t]) => ({ k, size: px(t.$value.fontSize), min: t.$extensions?.["com.recanica"]?.fluidMin ? px(t.$extensions["com.recanica"].fluidMin) : null, lh: t.$value.lineHeight, ls: t.$value.letterSpacing ? parseFloat(t.$value.letterSpacing) : 0 }));
48
+ // Fluid type for CSS: scales linearly from `min` at a 375px viewport to `size` at 1280px, in rem so browser zoom still works.
49
+ // Native platforms (Flutter, SwiftUI, Compose) get the fixed `size`.
50
+ const cssSize = (t) => {
51
+ if (!t.min) return rem(t.size + "px");
52
+ const slope = (t.size - t.min) / (1280 - 375);
53
+ const base = (t.min - slope * 375) / 16;
54
+ return `clamp(${+(t.min / 16).toFixed(4)}rem, ${+base.toFixed(4)}rem + ${+(slope * 100).toFixed(4)}vw, ${+(t.size / 16).toFixed(4)}rem)`;
55
+ };
56
+ const weights = Object.fromEntries(entries(T.font.weight).map(([k, t]) => [k, t.$value]));
57
+ const fonts = Object.fromEntries(entries(T.font.family).map(([k, t]) => [k, { stack: t.$value, css: ext(t).css ?? t.$value.join(", ") }]));
58
+ const durations = entries(T.duration).map(([k, t]) => ({ k, ms: parseFloat(t.$value) }));
59
+ const easings = entries(T.easing).map(([k, t]) => ({ k, v: t.$value }));
60
+ const shadowCss = (t) => t.$value.map((s) => `${s.offsetX} ${s.offsetY} ${s.blur} ${s.spread} ${s.color}`.replace(/(^| )0px/g, "$10")).join(", ");
61
+ const shadows = entries(T.shadow).map(([k, t]) => ({ k, css: shadowCss(t) }));
62
+ const productText = new Set(["heading", "title", "metric", "display-sm", "display-md", "display-lg"]);
63
+
64
+ /* ---------- outputs ---------- */
65
+ const outputs = {};
66
+
67
+ outputs["css/variables.css"] = `/* ${HEADER}
68
+ * Plain CSS variables: works with or without Tailwind.
69
+ * Semantic colors switch with the .dark class on an ancestor (usually <html>). */
70
+ :root {
71
+ ${primitives.map((p) => ` --${p.name}: ${p.oklch ?? p.hex};`).join("\n")}
72
+
73
+ --radius: ${ext(T.radius.base).css};
74
+ ${radius.filter((r) => r.k !== "base").map((r) => ` --rc-radius-${r.k}: ${r.css};`).join("\n")}
75
+ ${spacing.map((s) => ` --rc-space-${s.k}: ${s.css};`).join("\n")}
76
+ ${containers.map((c) => ` --rc-container-${c.k}: ${c.css};`).join("\n")}
77
+ ${Object.entries(fonts).map(([k, f]) => ` --rc-font-${k}: ${f.css};`).join("\n")}
78
+ ${text.map((t) => ` --rc-text-${t.k}: ${cssSize(t)};`).join("\n")}
79
+ ${durations.map((d) => ` --rc-duration-${d.k}: ${d.ms}ms;`).join("\n")}
80
+ ${easings.map((e) => ` --rc-ease-${e.k}: cubic-bezier(${e.v.join(", ")});`).join("\n")}
81
+ ${shadows.map((s) => ` --rc-shadow-${s.k}: ${s.css};`).join("\n")}
82
+ }
83
+
84
+ /* Semantic: light */
85
+ :root {
86
+ ${semantic.map((s) => ` --${s.name}: ${cssRef(s.lightRef)};`).join("\n")}
87
+ }
88
+
89
+ /* Semantic: dark */
90
+ .dark {
91
+ ${semantic.filter((s) => s.hasDark).map((s) => ` --${s.name}: ${cssRef(s.darkRef)};`).join("\n")}
92
+ }
93
+ `;
94
+
95
+ outputs["css/tailwind-theme.css"] = `/* ${HEADER}
96
+ * Tailwind v4 scale (imported by theme.css). */
97
+ @theme inline {
98
+ ${radius.filter((r) => !["base", "full"].includes(r.k)).map((r) => ` --radius-${r.k}: ${r.css};`).join("\n")}
99
+
100
+ ${Object.entries(fonts).map(([k, f]) => ` --font-${k}: ${f.css};`).join("\n")}
101
+
102
+ ${spacing.filter((s) => s.k !== "unit").map((s) => ` --spacing-${s.k}: ${s.css};`).join("\n")}
103
+ ${containers.map((c) => ` --container-${c.k}: ${c.css};`).join("\n")}
104
+
105
+ ${text.filter((t) => productText.has(t.k)).map((t) => [
106
+ ` --text-${t.k}: ${cssSize(t)};`,
107
+ ` --text-${t.k}--line-height: ${t.lh};`,
108
+ ...(t.ls ? [` --text-${t.k}--letter-spacing: ${t.ls}em;`] : []),
109
+ ].join("\n")).join("\n")}
110
+
111
+ ${shadows.map((s) => ` --shadow-${s.k}: ${s.css};`).join("\n")}
112
+ ${easings.map((e) => ` --ease-${e.k}: cubic-bezier(${e.v.join(", ")});`).join("\n")}
113
+ }
114
+ `;
115
+
116
+ const jsTokens = {
117
+ color: {
118
+ light: Object.fromEntries(semantic.map((s) => [camel(s.name), s.light])),
119
+ dark: Object.fromEntries(semantic.map((s) => [camel(s.name), s.dark])),
120
+ },
121
+ primitive: Object.fromEntries(primitives.map((p) => [p.key, p.hex])),
122
+ radius: Object.fromEntries(radius.map((r) => [r.k, r.px])),
123
+ spacing: Object.fromEntries(spacing.map((s) => [camel(s.k), s.px])),
124
+ container: Object.fromEntries(containers.map((c) => [c.k, c.px])),
125
+ font: { sans: fonts.sans.stack, mono: fonts.mono.stack, weight: weights },
126
+ text: Object.fromEntries(text.map((t) => [camel(t.k), { fontSize: t.size, lineHeight: t.lh, letterSpacing: t.ls }])),
127
+ duration: Object.fromEntries(durations.map((d) => [d.k, d.ms])),
128
+ easing: Object.fromEntries(easings.map((e) => [camel(e.k), e.v])),
129
+ shadow: Object.fromEntries(shadows.map((s) => [s.k, s.css])),
130
+ };
131
+ outputs["js/tokens.mjs"] = `// ${HEADER}\nexport const tokens = ${JSON.stringify(jsTokens, null, 2)};\nexport default tokens;\n`;
132
+ outputs["js/tokens.cjs"] = `// ${HEADER}\nconst tokens = ${JSON.stringify(jsTokens, null, 2)};\nmodule.exports = tokens;\nmodule.exports.tokens = tokens;\nmodule.exports.default = tokens;\n`;
133
+ outputs["js/tokens.d.ts"] = `// ${HEADER}\nexport declare const tokens: ${JSON.stringify(jsTokens, null, 2)};\nexport default tokens;\n`;
134
+ outputs["json/tokens.json"] = JSON.stringify(jsTokens, null, 2) + "\n";
135
+
136
+ outputs["tailwind/preset.cjs"] = `// ${HEADER}
137
+ // Tailwind CSS v3 preset. Also import "@recanica/tokens/variables.css" in your global CSS.
138
+ /** @type {import('tailwindcss').Config} */
139
+ module.exports = {
140
+ darkMode: "class",
141
+ theme: {
142
+ extend: {
143
+ colors: ${JSON.stringify(Object.fromEntries(semantic.map((s) => [s.name, `var(--${s.name})`])), null, 6).replace(/\n}/, "\n }")},
144
+ borderRadius: ${JSON.stringify(Object.fromEntries(radius.filter((r) => !["base", "full"].includes(r.k)).map((r) => [r.k, r.css])))},
145
+ fontFamily: { sans: ${JSON.stringify(fonts.sans.stack)}, mono: ${JSON.stringify(fonts.mono.stack)} },
146
+ spacing: ${JSON.stringify(Object.fromEntries(spacing.filter((s) => s.k !== "unit").map((s) => [s.k, s.css])))},
147
+ maxWidth: ${JSON.stringify(Object.fromEntries(containers.map((c) => [c.k, c.css])))},
148
+ fontSize: ${JSON.stringify(Object.fromEntries(text.filter((t) => productText.has(t.k)).map((t) => [t.k, [cssSize(t), { lineHeight: String(t.lh), ...(t.ls ? { letterSpacing: `${t.ls}em` } : {}) }]])))},
149
+ boxShadow: ${JSON.stringify(Object.fromEntries(shadows.map((s) => [s.k, s.css])))},
150
+ transitionTimingFunction: ${JSON.stringify(Object.fromEntries(easings.map((e) => [e.k, `cubic-bezier(${e.v.join(", ")})`])))},
151
+ },
152
+ },
153
+ };
154
+ `;
155
+
156
+ const argb = (hex) => `0xFF${hex.slice(1).toUpperCase()}`;
157
+ const weightName = { 300: "w300", 400: "w400", 500: "w500" };
158
+ const textWeight = (k) => (k === "metric" ? 300 : 400);
159
+
160
+ outputs["flutter/recanica_tokens.dart"] = `// ${HEADER}
161
+ // Usage: MaterialApp(theme: recanicaTheme(Brightness.light), darkTheme: recanicaTheme(Brightness.dark))
162
+ import 'package:flutter/material.dart';
163
+
164
+ @immutable
165
+ class RecanicaColors {
166
+ const RecanicaColors({
167
+ ${semantic.map((s) => ` required this.${camel(s.name)},`).join("\n")}
168
+ });
169
+ ${semantic.map((s) => ` final Color ${camel(s.name)};`).join("\n")}
170
+
171
+ static const light = RecanicaColors(
172
+ ${semantic.map((s) => ` ${camel(s.name)}: Color(${argb(s.light)}),`).join("\n")}
173
+ );
174
+ static const dark = RecanicaColors(
175
+ ${semantic.map((s) => ` ${camel(s.name)}: Color(${argb(s.dark)}),`).join("\n")}
176
+ );
177
+ }
178
+
179
+ class RecanicaRadius {
180
+ ${radius.map((r) => ` static const double ${camel(r.k === "2xl" ? "xxl" : r.k)} = ${r.px};`).join("\n")}
181
+ }
182
+
183
+ class RecanicaSpacing {
184
+ ${spacing.map((s) => ` static const double ${camel(s.k)} = ${s.px};${s.desc ? ` // ${s.desc}` : ""}`).join("\n")}
185
+ }
186
+
187
+ class RecanicaText {
188
+ static const String family = 'Geist';
189
+ static const String monoFamily = 'Geist Mono';
190
+ ${text.map((t) => ` static const TextStyle ${camel(t.k.replace(/^(\d)/, "x$1"))} = TextStyle(fontFamily: family, fontSize: ${t.size}, height: ${t.lh}, letterSpacing: ${+(t.ls * t.size).toFixed(2)}, fontWeight: FontWeight.${weightName[textWeight(t.k)]});`).join("\n")}
191
+ }
192
+
193
+ class RecanicaMotion {
194
+ ${durations.map((d) => ` static const Duration ${d.k} = Duration(milliseconds: ${d.ms});`).join("\n")}
195
+ ${easings.map((e) => ` static const Curve ${camel(e.k)} = Cubic(${e.v.join(", ")});`).join("\n")}
196
+ }
197
+
198
+ ThemeData recanicaTheme(Brightness brightness) {
199
+ final c = brightness == Brightness.dark ? RecanicaColors.dark : RecanicaColors.light;
200
+ final pill = const StadiumBorder();
201
+ return ThemeData(
202
+ useMaterial3: true,
203
+ brightness: brightness,
204
+ fontFamily: RecanicaText.family,
205
+ scaffoldBackgroundColor: c.background,
206
+ dividerColor: c.border,
207
+ colorScheme: ColorScheme(
208
+ brightness: brightness,
209
+ primary: c.primary, onPrimary: c.primaryForeground,
210
+ secondary: c.secondary, onSecondary: c.secondaryForeground,
211
+ error: c.destructive, onError: c.destructiveForeground,
212
+ surface: c.card, onSurface: c.foreground,
213
+ outline: c.border, surfaceContainerHighest: c.muted,
214
+ ),
215
+ cardTheme: CardThemeData(
216
+ color: c.card, elevation: 0, margin: EdgeInsets.zero,
217
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(RecanicaRadius.xxl), side: BorderSide(color: c.border)),
218
+ ),
219
+ filledButtonTheme: FilledButtonThemeData(style: FilledButton.styleFrom(shape: pill, backgroundColor: c.primary, foregroundColor: c.primaryForeground)),
220
+ outlinedButtonTheme: OutlinedButtonThemeData(style: OutlinedButton.styleFrom(shape: pill, side: BorderSide(color: c.border), foregroundColor: c.foreground)),
221
+ inputDecorationTheme: InputDecorationTheme(
222
+ border: OutlineInputBorder(borderRadius: BorderRadius.circular(RecanicaRadius.lg), borderSide: BorderSide(color: c.input)),
223
+ enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(RecanicaRadius.lg), borderSide: BorderSide(color: c.input)),
224
+ focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(RecanicaRadius.lg), borderSide: BorderSide(color: c.ring, width: 1.5)),
225
+ ),
226
+ );
227
+ }
228
+ `;
229
+
230
+ outputs["ios/RecanicaTokens.swift"] = `// ${HEADER}
231
+ // SwiftUI. Colors adapt to light/dark automatically.
232
+ import SwiftUI
233
+ import UIKit
234
+
235
+ public enum Recanica {
236
+ public enum Colors {
237
+ ${semantic.map((s) => ` public static let ${camel(s.name)} = Color(light: ${s.light.replace("#", "0x")}, dark: ${s.dark.replace("#", "0x")})`).join("\n")}
238
+ }
239
+ public enum Radius {
240
+ ${radius.map((r) => ` public static let ${camel(r.k === "2xl" ? "xxl" : r.k)}: CGFloat = ${r.px}`).join("\n")}
241
+ }
242
+ public enum Spacing {
243
+ ${spacing.map((s) => ` public static let ${camel(s.k)}: CGFloat = ${s.px}`).join("\n")}
244
+ }
245
+ public enum Typography {
246
+ ${text.map((t) => ` public static let ${camel(t.k.replace(/^(\d)/, "x$1"))} = Font.custom("Geist", size: ${t.size}).weight(.${textWeight(t.k) === 300 ? "light" : "regular"})`).join("\n")}
247
+ }
248
+ public enum Motion {
249
+ ${durations.map((d) => ` public static let ${d.k}: Double = ${d.ms / 1000}`).join("\n")}
250
+ ${easings.map((e) => ` public static let ${camel(e.k)} = Animation.timingCurve(${e.v.join(", ")}, duration: ${durations.find((d) => d.k === "slow").ms / 1000})`).join("\n")}
251
+ }
252
+ }
253
+
254
+ extension Color {
255
+ init(light: UInt32, dark: UInt32) {
256
+ func ui(_ hex: UInt32) -> UIColor {
257
+ UIColor(red: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: 1)
258
+ }
259
+ self.init(uiColor: UIColor { $0.userInterfaceStyle == .dark ? ui(dark) : ui(light) })
260
+ }
261
+ }
262
+ `;
263
+
264
+ outputs["android/RecanicaTokens.kt"] = `// ${HEADER}
265
+ // Jetpack Compose. Usage: MaterialTheme(colorScheme = recanicaColorScheme(isSystemInDarkTheme())) { … }
266
+ package com.aturanica.recanica
267
+
268
+ import androidx.compose.material3.ColorScheme
269
+ import androidx.compose.material3.darkColorScheme
270
+ import androidx.compose.material3.lightColorScheme
271
+ import androidx.compose.ui.graphics.Color
272
+ import androidx.compose.ui.unit.dp
273
+ import androidx.compose.ui.unit.sp
274
+
275
+ object RecanicaColors {
276
+ object Light {
277
+ ${semantic.map((s) => ` val ${pascal(s.name)} = Color(${argb(s.light)})`).join("\n")}
278
+ }
279
+ object Dark {
280
+ ${semantic.map((s) => ` val ${pascal(s.name)} = Color(${argb(s.dark)})`).join("\n")}
281
+ }
282
+ }
283
+
284
+ object RecanicaRadius {
285
+ ${radius.map((r) => ` val ${pascal(r.k === "2xl" ? "xxl" : r.k)} = ${r.px}.dp`).join("\n")}
286
+ }
287
+
288
+ object RecanicaSpacing {
289
+ ${spacing.map((s) => ` val ${pascal(s.k)} = ${s.px}.dp`).join("\n")}
290
+ }
291
+
292
+ object RecanicaTextSize {
293
+ ${text.map((t) => ` val ${pascal(t.k.replace(/^(\d)/, "x$1"))} = ${t.size}.sp`).join("\n")}
294
+ }
295
+
296
+ fun recanicaColorScheme(dark: Boolean): ColorScheme = if (dark) {
297
+ darkColorScheme(
298
+ primary = RecanicaColors.Dark.Primary, onPrimary = RecanicaColors.Dark.PrimaryForeground,
299
+ secondary = RecanicaColors.Dark.Secondary, onSecondary = RecanicaColors.Dark.SecondaryForeground,
300
+ background = RecanicaColors.Dark.Background, onBackground = RecanicaColors.Dark.Foreground,
301
+ surface = RecanicaColors.Dark.Card, onSurface = RecanicaColors.Dark.Foreground,
302
+ error = RecanicaColors.Dark.Destructive, onError = RecanicaColors.Dark.DestructiveForeground,
303
+ outline = RecanicaColors.Dark.Border,
304
+ )
305
+ } else {
306
+ lightColorScheme(
307
+ primary = RecanicaColors.Light.Primary, onPrimary = RecanicaColors.Light.PrimaryForeground,
308
+ secondary = RecanicaColors.Light.Secondary, onSecondary = RecanicaColors.Light.SecondaryForeground,
309
+ background = RecanicaColors.Light.Background, onBackground = RecanicaColors.Light.Foreground,
310
+ surface = RecanicaColors.Light.Card, onSurface = RecanicaColors.Light.Foreground,
311
+ error = RecanicaColors.Light.Destructive, onError = RecanicaColors.Light.DestructiveForeground,
312
+ outline = RecanicaColors.Light.Border,
313
+ )
314
+ }
315
+ `;
316
+
317
+ outputs["figma/tokens-studio.json"] = JSON.stringify({
318
+ primitive: { rc: T.rc },
319
+ light: { color: Object.fromEntries(semantic.map((s) => [s.name, { $type: "color", $value: s.lightRef }])) },
320
+ dark: { color: Object.fromEntries(semantic.map((s) => [s.name, { $type: "color", $value: s.darkRef }])) },
321
+ dimension: { radius: T.radius, spacing: T.spacing, container: T.container },
322
+ $themes: [
323
+ { id: "light", name: "Light", selectedTokenSets: { primitive: "source", dimension: "source", light: "enabled" } },
324
+ { id: "dark", name: "Dark", selectedTokenSets: { primitive: "source", dimension: "source", dark: "enabled" } },
325
+ ],
326
+ $metadata: { tokenSetOrder: ["primitive", "dimension", "light", "dark"] },
327
+ }, null, 2) + "\n";
328
+
329
+ /* ---------- write / check ---------- */
330
+ let stale = [];
331
+ for (const [rel, content] of Object.entries(outputs)) {
332
+ const file = join(out, rel);
333
+ if (CHECK) {
334
+ if (!existsSync(file) || readFileSync(file, "utf8") !== content) stale.push(rel);
335
+ continue;
336
+ }
337
+ mkdirSync(dirname(file), { recursive: true });
338
+ writeFileSync(file, content);
339
+ }
340
+ if (CHECK && stale.length) {
341
+ console.error(`Tokens out of date. Run: pnpm --filter @recanica/tokens build\n ${stale.join("\n ")}`);
342
+ process.exit(1);
343
+ }
344
+ console.log(`${CHECK ? "checked" : "built"} ${Object.keys(outputs).length} outputs · ${primitives.length} primitives · ${semantic.length} semantic colors`);
package/theme.css ADDED
@@ -0,0 +1,126 @@
1
+ /*
2
+ * Recanica · Tailwind v4 entry
3
+ * ------------------------------------------------------------------
4
+ * Values come from tokens/*.json (W3C Design Tokens) via scripts/build.mjs:
5
+ * generated/css/variables.css primitives + semantic light/dark (plain CSS vars)
6
+ * generated/css/tailwind-theme.css radius, fonts, spacing, containers, type, shadow, easing
7
+ * This file only wires them into Tailwind and adds base styles.
8
+ *
9
+ * Tiers:
10
+ * 1. Primitives --rc-* raw scales (never used in components)
11
+ * 2. Semantic --background ... meaning-based, swapped per theme
12
+ * 3. Tailwind @theme inline exposes semantic tokens as utilities
13
+ */
14
+
15
+ @import "./generated/css/variables.css";
16
+ @import "./generated/css/tailwind-theme.css";
17
+
18
+ @custom-variant dark (&:is(.dark *));
19
+
20
+ /* ---------- 3. Tailwind bridge ---------- */
21
+ @theme inline {
22
+ --color-background: var(--background);
23
+ --color-foreground: var(--foreground);
24
+ --color-surface: var(--surface);
25
+ --color-panel: var(--panel);
26
+ --color-card: var(--card);
27
+ --color-card-foreground: var(--card-foreground);
28
+ --color-popover: var(--popover);
29
+ --color-popover-foreground: var(--popover-foreground);
30
+ --color-primary: var(--primary);
31
+ --color-primary-foreground: var(--primary-foreground);
32
+ --color-secondary: var(--secondary);
33
+ --color-secondary-foreground: var(--secondary-foreground);
34
+ --color-muted: var(--muted);
35
+ --color-muted-foreground: var(--muted-foreground);
36
+ --color-accent: var(--accent);
37
+ --color-accent-foreground: var(--accent-foreground);
38
+ --color-brand: var(--brand);
39
+ --color-brand-foreground: var(--brand-foreground);
40
+ --color-destructive: var(--destructive);
41
+ --color-destructive-foreground: var(--destructive-foreground);
42
+ --color-success: var(--success);
43
+ --color-warning: var(--warning);
44
+ --color-border: var(--border);
45
+ --color-input: var(--input);
46
+ --color-ring: var(--ring);
47
+ --color-sidebar: var(--sidebar);
48
+ --color-sidebar-foreground: var(--sidebar-foreground);
49
+ --color-sidebar-accent: var(--sidebar-accent);
50
+ --color-sidebar-border: var(--sidebar-border);
51
+ --color-sidebar-primary: var(--sidebar-primary);
52
+ --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
53
+ --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
54
+ --color-sidebar-ring: var(--sidebar-ring);
55
+ --color-chart-1: var(--chart-1);
56
+ --color-chart-2: var(--chart-2);
57
+ --color-chart-3: var(--chart-3);
58
+ --color-chart-4: var(--chart-4);
59
+ --color-chart-5: var(--chart-5);
60
+ }
61
+
62
+ @layer base {
63
+ * { border-color: var(--color-border); }
64
+ html { color-scheme: light; }
65
+ html.dark { color-scheme: dark; }
66
+ body {
67
+ background-color: var(--color-background);
68
+ color: var(--color-foreground);
69
+ font-family: var(--font-sans);
70
+ -webkit-font-smoothing: antialiased;
71
+ }
72
+ :focus-visible { outline: 2px solid var(--color-ring); outline-offset: 2px; }
73
+ /* No lone last words: headings balance their lines, paragraphs avoid a one-word last line. */
74
+ h1, h2, h3, h4 { text-wrap: balance; }
75
+ p, li, dd, summary { text-wrap: pretty; }
76
+ }
77
+
78
+
79
+ /* ---------- Loader animations (used by @recanica/ui Loader) ----------
80
+ * Monochrome, transform/opacity only. All stop under prefers-reduced-motion (see .rc-loader rules below). */
81
+ @theme {
82
+ --animate-loader-pulse: loader-pulse 1.4s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1)) infinite;
83
+ --animate-loader-breathe: loader-breathe 2s ease-in-out infinite;
84
+ --animate-loader-spin: loader-spin 1.6s linear infinite;
85
+ --animate-loader-orbit: loader-spin 1.2s linear infinite;
86
+ --animate-loader-bounce: loader-bounce 1s cubic-bezier(0.22, 1, 0.36, 1) infinite;
87
+ --animate-loader-flip: loader-flip 1.8s ease-in-out infinite;
88
+ --animate-loader-reveal: loader-reveal 1.6s ease-in-out infinite;
89
+ --animate-loader-ring: loader-ring 1.4s ease-in-out infinite;
90
+ --animate-loader-ripple: loader-ripple 1.6s cubic-bezier(0.22, 1, 0.36, 1) infinite;
91
+ --animate-loader-sway: loader-sway 1.6s ease-in-out infinite;
92
+ --animate-loader-wave: loader-wave 1.2s ease-in-out infinite;
93
+
94
+ @keyframes loader-pulse { 0%, 100% { transform: scale(1); opacity: 1 } 50% { transform: scale(0.86); opacity: 0.55 } }
95
+ @keyframes loader-breathe { 0%, 100% { opacity: 0.25 } 50% { opacity: 1 } }
96
+ @keyframes loader-spin { to { transform: rotate(360deg) } }
97
+ @keyframes loader-bounce { 0%, 100% { transform: translateY(0) } 40% { transform: translateY(-22%) } 60% { transform: translateY(0) } 75% { transform: translateY(-6%) } }
98
+ @keyframes loader-flip { 0% { transform: perspective(200px) rotateY(0) } 50% { transform: perspective(200px) rotateY(180deg) } 100% { transform: perspective(200px) rotateY(360deg) } }
99
+ @keyframes loader-reveal { 0% { clip-path: inset(0 100% 0 0) } 45%, 55% { clip-path: inset(0 0 0 0) } 100% { clip-path: inset(0 0 0 100%) } }
100
+ @keyframes loader-ring { 0% { stroke-dashoffset: 100 } 50% { stroke-dashoffset: 25 } 100% { stroke-dashoffset: -100 } }
101
+ @keyframes loader-ripple { 0% { transform: scale(0.5); opacity: 0.6 } 100% { transform: scale(1); opacity: 0 } }
102
+ @keyframes loader-sway { 0%, 100% { transform: rotate(-8deg) } 50% { transform: rotate(8deg) } }
103
+ @keyframes loader-wave { 0%, 100% { transform: translateY(0); opacity: 0.35 } 40% { transform: translateY(-40%); opacity: 1 } }
104
+ }
105
+
106
+ @media (prefers-reduced-motion: reduce) {
107
+ [data-slot=loader] *, [data-slot=loader] { animation-duration: 0s !important; animation-iteration-count: 1 !important; }
108
+ [data-slot=loader] [data-loader-motion] { opacity: 0.6; }
109
+ }
110
+
111
+ /* ---------- Layout primitives: ONE source for column rhythm and reading width ----------
112
+ * .flow the container owns the vertical spacing between its blocks: --spacing-flow between blocks,
113
+ * --spacing-stack before a heading. Blocks carry no outer margin of their own; any they do carry is overridden.
114
+ * .reading a reading column (≈ 85 characters at 16px); everything inside shares one right edge.
115
+ * Unlayered on purpose, so the container wins over any margin utility on a child. */
116
+ .flow > * { margin-bottom: 0; }
117
+ .flow > * + * { margin-top: var(--spacing-flow, 1.25rem); }
118
+ .flow > * + :is(h2, h3, section, [data-slot=section]) { margin-top: var(--spacing-stack, 2.5rem); }
119
+ .flow > :is(h2, h3, [data-slot=section-header]) + * { margin-top: var(--spacing-group, 0.75rem); }
120
+ .flow > [data-slot=page-header] + * { margin-top: var(--spacing-stack, 2.5rem); }
121
+ .reading { width: 100%; max-width: 48rem; }
122
+
123
+ /* Docs/code highlighting (shiki dual theme) */
124
+ .shiki, .shiki span { color: var(--shiki-light); background-color: transparent !important; }
125
+ .dark .shiki, .dark .shiki span { color: var(--shiki-dark); }
126
+