burne-ui 1.5.5 → 1.6.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/README.md CHANGED
@@ -56,18 +56,53 @@ import "burne-ui/styles.css";
56
56
  "use client";
57
57
 
58
58
  import { BurneUIProvider } from "burne-ui";
59
- // import burneTheme from "./burne-theme"; // после Copy config с сайта
59
+ import burneTheme from "./burne-theme";
60
60
 
61
61
  export function AppProviders({ children }: { children: React.ReactNode }) {
62
62
  return (
63
- <BurneUIProvider defaultTheme="system" toast>
63
+ <BurneUIProvider config={burneTheme} defaultTheme="system" toast>
64
64
  {children}
65
65
  </BurneUIProvider>
66
66
  );
67
67
  }
68
68
  ```
69
69
 
70
- На сайте в theme builder: **Copy config** → сохраните как `burne-theme.ts` → `<BurneUIProvider config={burneTheme}>`.
70
+ Scaffold (`create-burne-app` / `burne-ui init`) уже кладёт `burne-theme.ts` с **`tokens`** (shared), **`colors.light` / `colors.dark`** и **`motion`**.
71
+
72
+ Проектные CSS-переменные можно описать в том же конфиге. Они применяются Provider и автоматически
73
+ появляются в `burne-ui-devtools`:
74
+
75
+ ```ts
76
+ const burneTheme = {
77
+ // tokens, colors, motion...
78
+ customTokens: {
79
+ "--app-brand": "#38bdf8",
80
+ "--app-sidebar-width": {
81
+ value: 320,
82
+ unit: "px",
83
+ label: "Sidebar width",
84
+ control: "slider",
85
+ min: 240,
86
+ max: 480,
87
+ step: 4,
88
+ },
89
+ },
90
+ } satisfies BurneThemeConfig;
91
+ ```
92
+
93
+ ### Devtools темы
94
+
95
+ Интерактивный редактор устанавливается отдельно и подключается только в development:
96
+
97
+ ```bash
98
+ npm install -D burne-ui-devtools
99
+ ```
100
+
101
+ Он показывает плавающую кнопку, позволяет менять токены и пресеты в браузере, а затем скопировать
102
+ или скачать готовый `burne-theme.ts`. Полная интеграция для Vite и Next.js описана в
103
+ [`burne-ui-devtools`](https://www.npmjs.com/package/burne-ui-devtools) и
104
+ [docs/SETUP.md](./docs/SETUP.md).
105
+
71
106
 
72
107
  Только переключение `data-theme`: `ThemeProvider` + `useBurneTheme()`. Подробности — [docs/SETUP.md](./docs/SETUP.md).
73
108
 
package/cli/init.js CHANGED
@@ -1,9 +1,44 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
+ import { fileURLToPath, pathToFileURL } from "node:url";
4
5
 
5
6
  import * as prompts from "./prompts.js";
6
7
 
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+
10
+ const THEME_BRIDGE_CSS = `
11
+ /*
12
+ * Tailwind v4 can regenerate theme tokens — bind them back to burne runtime vars.
13
+ */
14
+ @theme {
15
+ --text-base: var(--text-base-size);
16
+ --text-base--line-height: var(--text-base-line-height);
17
+ --text-base--font-weight: var(--text-base-weight);
18
+ --font-sans: var(--font-family-sans);
19
+ --font-mono: var(--font-family-mono);
20
+ }
21
+ `;
22
+
23
+ /**
24
+ * @returns {Promise<string>}
25
+ */
26
+ async function loadDefaultThemeSource() {
27
+ const distEntry = path.join(__dirname, "../dist/index.js");
28
+ if (!fs.existsSync(distEntry)) {
29
+ throw new Error(
30
+ "burne-ui dist missing — reinstall the package (need burne-ui ≥ 1.5.9 with exportDefaultBurneThemeConfigSource).",
31
+ );
32
+ }
33
+ const mod = await import(pathToFileURL(distEntry).href);
34
+ if (typeof mod.exportDefaultBurneThemeConfigSource !== "function") {
35
+ throw new Error(
36
+ "This burne-ui build has no exportDefaultBurneThemeConfigSource — upgrade to ≥ 1.5.9.",
37
+ );
38
+ }
39
+ return mod.exportDefaultBurneThemeConfigSource();
40
+ }
41
+
7
42
  /** @typedef {"npm" | "pnpm" | "bun" | "yarn"} PackageManager */
8
43
  /** @typedef {"system" | "dark" | "light"} ThemeMode */
9
44
  /** @typedef {"next" | "vite" | "unknown"} Framework */
@@ -78,6 +113,7 @@ export function patchCssFile(cssPath) {
78
113
  let css = fs.readFileSync(cssPath, "utf8");
79
114
  const hadBurne = css.includes("burne-ui/styles.css");
80
115
  const hadTailwind = /@import\s+["']tailwindcss["']/.test(css);
116
+ const hadThemeBridge = css.includes("--text-base: var(--text-base-size)");
81
117
 
82
118
  if (!hadBurne) {
83
119
  if (hadTailwind) {
@@ -105,8 +141,18 @@ export function patchCssFile(cssPath) {
105
141
  css += `\n@import "burne-ui/styles.css";\n`;
106
142
  }
107
143
 
144
+ if (!hadThemeBridge) {
145
+ const burneImport = css.match(/@import\s+["']burne-ui\/styles\.css["']\s*;/);
146
+ if (burneImport && burneImport.index != null) {
147
+ const insertAt = burneImport.index + burneImport[0].length;
148
+ css = css.slice(0, insertAt) + "\n" + THEME_BRIDGE_CSS + css.slice(insertAt);
149
+ } else {
150
+ css += "\n" + THEME_BRIDGE_CSS;
151
+ }
152
+ }
153
+
108
154
  fs.writeFileSync(cssPath, css);
109
- return { hadBurne, hadTailwind };
155
+ return { hadBurne, hadTailwind, hadThemeBridge };
110
156
  }
111
157
 
112
158
  /**
@@ -119,13 +165,15 @@ function providerSource(theme, toast) {
119
165
 
120
166
  import { BurneUIProvider } from "burne-ui";
121
167
 
168
+ import burneTheme from "./burne-theme";
169
+
122
170
  /**
123
171
  * Generated by \`burne-ui init\`.
124
- * Optional: Copy config from the docs site → burne-theme.ts → config={burneTheme}.
172
+ * Theme tokens live in \`burne-theme.ts\` (replace via docs site → Copy config).
125
173
  */
126
174
  export function BurneProviders({ children }: { children: React.ReactNode }) {
127
175
  return (
128
- <BurneUIProvider defaultTheme="${theme}"${toastLine}>
176
+ <BurneUIProvider config={burneTheme} defaultTheme="${theme}"${toastLine}>
129
177
  {children}
130
178
  </BurneUIProvider>
131
179
  );
@@ -369,8 +417,9 @@ export async function runInit(argv, cliVersion) {
369
417
  if (cssRel) {
370
418
  const abs = path.resolve(cwd, cssRel);
371
419
  if (!fs.existsSync(abs)) throw new Error(`CSS not found: ${cssRel}`);
372
- const { hadBurne, hadTailwind } = patchCssFile(abs);
420
+ const { hadBurne, hadTailwind, hadThemeBridge } = patchCssFile(abs);
373
421
  console.log(hadBurne ? `CSS OK (already linked): ${cssRel}` : `Patched CSS: ${cssRel}`);
422
+ if (!hadThemeBridge) console.log("Added @theme bridge (text-base / font-sans).");
374
423
  if (!hadTailwind) {
375
424
  console.log('Note: no @import "tailwindcss" — add Tailwind v4 for className utilities.');
376
425
  }
@@ -380,6 +429,23 @@ export async function runInit(argv, cliVersion) {
380
429
 
381
430
  fs.mkdirSync(provider.dir, { recursive: true });
382
431
  const relProvider = path.relative(cwd, provider.file);
432
+ const themeFile = path.join(provider.dir, "burne-theme.ts");
433
+ const relTheme = path.relative(cwd, themeFile);
434
+
435
+ const themeSource = await loadDefaultThemeSource();
436
+ if (fs.existsSync(themeFile) && interactive) {
437
+ const overwriteTheme = await prompts.confirm({
438
+ message: `Overwrite ${relTheme}?`,
439
+ initialValue: false,
440
+ });
441
+ if (overwriteTheme) {
442
+ fs.writeFileSync(themeFile, themeSource);
443
+ console.log(`Wrote ${relTheme}`);
444
+ }
445
+ } else if (!fs.existsSync(themeFile)) {
446
+ fs.writeFileSync(themeFile, themeSource);
447
+ console.log(`Wrote ${relTheme}`);
448
+ }
383
449
 
384
450
  if (fs.existsSync(provider.file) && interactive) {
385
451
  const overwrite = await prompts.confirm({
@@ -394,5 +460,5 @@ export async function runInit(argv, cliVersion) {
394
460
 
395
461
  const snippet = layoutSnippet(fw, provider.importHint);
396
462
  console.log(`\n── Wrap your root layout ──\n\n${snippet}`);
397
- console.log("Optional: docs site → Copy config → burne-theme.ts → config={burneTheme}\n");
463
+ console.log("Theme: edit burne-theme.ts, or replace via docs site → Copy config.\n");
398
464
  }