@jcsoftdev/ui 0.2.1 → 0.2.2
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/CHANGELOG.md +10 -0
- package/bin/ui-theme.mjs +6 -3
- package/package.json +6 -1
- package/scripts/build-theme.d.ts +18 -0
- package/scripts/build-theme.mjs +17 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.2 (2026-10-13)
|
|
4
|
+
|
|
5
|
+
### Fixes
|
|
6
|
+
|
|
7
|
+
- **`ui-theme build --no-kotlin` no longer builds Kotlin.** It used to generate `Theme.kt` and discard it, so `var(...)` and `oklch(...)` colors still threw "Unsupported color for Kotlin". Without the flag, the error now names the token and suggests `--no-kotlin`.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **`@jcsoftdev/ui/theme-builder`** exports `buildTheme`, `buildTokensCss`, `buildThemeCss`, `buildFontsCss` and `buildThemeKt`, typed. `buildTheme` takes `kotlin: false` to skip `Theme.kt`.
|
|
12
|
+
|
|
3
13
|
## 0.2.1 (2026-10-13)
|
|
4
14
|
|
|
5
15
|
### Fixes
|
package/bin/ui-theme.mjs
CHANGED
|
@@ -7,7 +7,8 @@ import { buildTheme } from "../scripts/build-theme.mjs";
|
|
|
7
7
|
const USAGE = `Usage: ui-theme build [tokens.json] --out <dir> [--kotlin-package <pkg>] [--no-kotlin]
|
|
8
8
|
|
|
9
9
|
Generates tokens.css, theme.css, fonts.css and Theme.kt from a tokens file.
|
|
10
|
-
Without a tokens file the bundled default theme is used
|
|
10
|
+
Without a tokens file the bundled default theme is used.
|
|
11
|
+
--no-kotlin skips Theme.kt, so tokens with var() or oklch() colors build.`;
|
|
11
12
|
|
|
12
13
|
const args = process.argv.slice(2);
|
|
13
14
|
const flag = (name) => {
|
|
@@ -35,11 +36,13 @@ if (command !== "build" || !out) {
|
|
|
35
36
|
|
|
36
37
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
37
38
|
const file = resolve(tokensFlag ?? positional ?? join(here, "../tokens/default.json"));
|
|
38
|
-
const files = buildTheme(JSON.parse(readFileSync(file, "utf8")), {
|
|
39
|
+
const files = buildTheme(JSON.parse(readFileSync(file, "utf8")), {
|
|
40
|
+
kotlinPackage,
|
|
41
|
+
kotlin: !noKotlin,
|
|
42
|
+
});
|
|
39
43
|
|
|
40
44
|
mkdirSync(resolve(out), { recursive: true });
|
|
41
45
|
for (const [name, content] of Object.entries(files)) {
|
|
42
|
-
if (noKotlin && name.endsWith(".kt")) continue;
|
|
43
46
|
writeFileSync(join(resolve(out), name), content);
|
|
44
47
|
console.log(`wrote ${join(out, name)}`);
|
|
45
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jcsoftdev/ui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Token-driven React component library: React 19, Tailwind v4.",
|
|
5
5
|
"author": "jcsoftdev",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"bin",
|
|
46
46
|
"icons",
|
|
47
47
|
"scripts/build-theme.mjs",
|
|
48
|
+
"scripts/build-theme.d.ts",
|
|
48
49
|
"README.md",
|
|
49
50
|
"CHANGELOG.md",
|
|
50
51
|
"THIRD_PARTY_NOTICES.md",
|
|
@@ -54,6 +55,10 @@
|
|
|
54
55
|
"./styles/*": "./styles/*",
|
|
55
56
|
"./tokens/*": "./tokens/*",
|
|
56
57
|
"./package.json": "./package.json",
|
|
58
|
+
"./theme-builder": {
|
|
59
|
+
"types": "./scripts/build-theme.d.ts",
|
|
60
|
+
"import": "./scripts/build-theme.mjs"
|
|
61
|
+
},
|
|
57
62
|
"./rich-text": {
|
|
58
63
|
"types": "./dist/rich-text/index.d.ts",
|
|
59
64
|
"source": "./src/rich-text/index.ts",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ThemeTokens {
|
|
2
|
+
name: string;
|
|
3
|
+
[group: string]: unknown;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface BuildThemeOptions {
|
|
7
|
+
kotlin?: boolean;
|
|
8
|
+
kotlinPackage?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function buildTokensCss(tokens: ThemeTokens): string;
|
|
12
|
+
export function buildThemeCss(tokens: ThemeTokens): string;
|
|
13
|
+
export function buildFontsCss(tokens: ThemeTokens): string;
|
|
14
|
+
export function buildThemeKt(tokens: ThemeTokens, pkg?: string): string;
|
|
15
|
+
export function buildTheme(
|
|
16
|
+
tokens: ThemeTokens,
|
|
17
|
+
options?: BuildThemeOptions,
|
|
18
|
+
): Record<string, string>;
|
package/scripts/build-theme.mjs
CHANGED
|
@@ -341,6 +341,17 @@ export function toKotlinColor(css) {
|
|
|
341
341
|
throw new Error(`Unsupported color for Kotlin: ${css}`);
|
|
342
342
|
}
|
|
343
343
|
|
|
344
|
+
const kotlinColorOf = (token, theme, base) => {
|
|
345
|
+
const value = valueFor(token, theme, base);
|
|
346
|
+
try {
|
|
347
|
+
return toKotlinColor(value);
|
|
348
|
+
} catch {
|
|
349
|
+
throw new Error(
|
|
350
|
+
`Token "${token.name}" (${theme}) has a color Kotlin cannot represent: ${value}. Use hex or rgb(a) values, or pass --no-kotlin.`,
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
344
355
|
const px = (value) => `${Number.parseFloat(value)}.dp`;
|
|
345
356
|
|
|
346
357
|
export function buildThemeKt(tokens, pkg = "com.jcsoftdev.ui.theme") {
|
|
@@ -368,7 +379,7 @@ export function buildThemeKt(tokens, pkg = "com.jcsoftdev.ui.theme") {
|
|
|
368
379
|
for (const theme of themes) {
|
|
369
380
|
out.push(` val ${pascal(theme)} = ThemeColors(`);
|
|
370
381
|
for (const t of colors) {
|
|
371
|
-
out.push(` ${camel(t.name)} = ${
|
|
382
|
+
out.push(` ${camel(t.name)} = ${kotlinColorOf(t, theme, base)},`);
|
|
372
383
|
}
|
|
373
384
|
out.push(" )");
|
|
374
385
|
}
|
|
@@ -387,7 +398,7 @@ export function buildThemeKt(tokens, pkg = "com.jcsoftdev.ui.theme") {
|
|
|
387
398
|
const byName = new Map(tokens.color.tokens.map((t) => [t.name, t]));
|
|
388
399
|
const args = Object.entries(PALETTE_ROLES).map(([role]) => {
|
|
389
400
|
const tok = byName.get(roles[role]);
|
|
390
|
-
return tok ?
|
|
401
|
+
return tok ? kotlinColorOf(tok, theme, base) : "Color.Unspecified";
|
|
391
402
|
});
|
|
392
403
|
out.push(` "${id}" to AccentPalette(${args.join(", ")}),`);
|
|
393
404
|
}
|
|
@@ -427,11 +438,12 @@ export function buildThemeKt(tokens, pkg = "com.jcsoftdev.ui.theme") {
|
|
|
427
438
|
return out.join("\n");
|
|
428
439
|
}
|
|
429
440
|
|
|
430
|
-
export function buildTheme(tokens, { kotlinPackage } = {}) {
|
|
431
|
-
|
|
441
|
+
export function buildTheme(tokens, { kotlinPackage, kotlin = true } = {}) {
|
|
442
|
+
const css = {
|
|
432
443
|
"tokens.css": buildTokensCss(tokens),
|
|
433
444
|
"theme.css": buildThemeCss(tokens),
|
|
434
445
|
"fonts.css": buildFontsCss(tokens),
|
|
435
|
-
"Theme.kt": buildThemeKt(tokens, kotlinPackage),
|
|
436
446
|
};
|
|
447
|
+
if (!kotlin) return css;
|
|
448
|
+
return { ...css, "Theme.kt": buildThemeKt(tokens, kotlinPackage) };
|
|
437
449
|
}
|