@panomc/theme-core 1.0.0-dev.45 → 1.0.0-dev.47

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.
Binary file
Binary file
@@ -0,0 +1,3 @@
1
+ <svg width="128" height="256" viewBox="0 0 128 256" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <rect width="128" height="256" rx="4.8" fill="#72C076"/>
3
+ </svg>
@@ -0,0 +1,8 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 186.05 279.07">
2
+ <defs>
3
+ <style>.a,.b{fill:#fff;}.a{opacity:0.7;}</style>
4
+ </defs>
5
+ <path class="a" d="M0,232.56v16.51a30,30,0,0,0,30,30H63a30,30,0,0,0,30-30V186H46.51S0,186,0,232.56Z"/>
6
+ <path class="b"
7
+ d="M156,0H30A30,30,0,0,0,0,30V232.56C0,186,46.51,186,46.51,186H156a30,30,0,0,0,30-30V30A30,30,0,0,0,156,0Z"/>
8
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <rect width="128" height="128" rx="4.8" fill="#E9573F"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg width="256" height="128" viewBox="0 0 256 128" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <rect width="256" height="128" rx="4.8" fill="#F6BB42"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ # https://www.robotstxt.org/robotstxt.html
2
+ User-agent: *
3
+ Disallow:
package/bin/check.js CHANGED
@@ -19,6 +19,7 @@
19
19
  import { existsSync, readFileSync, readdirSync } from "node:fs";
20
20
  import { join, dirname } from "node:path";
21
21
  import { fileURLToPath, pathToFileURL } from "node:url";
22
+ import { pc } from "./ui.js";
22
23
 
23
24
  const pkgDir = join(dirname(fileURLToPath(import.meta.url)), "..");
24
25
  const themeDir = process.cwd();
@@ -245,9 +246,18 @@ if (existsSync(viewsDir) && existsSync(mergedLangPath)) {
245
246
  scan(viewsDir);
246
247
  }
247
248
 
248
- for (const w of warnings) console.log(`[check] warn: ${w}`);
249
+ console.log(pc.dim(`theme-core check — validating against core ${corePkg.version}`));
250
+
251
+ for (const w of warnings) console.log(` ${pc.yellow("▲")} ${w}`);
249
252
  if (problems.length) {
250
- for (const p of problems) console.error(`[check] FAIL: ${p}`);
253
+ for (const p of problems) console.error(` ${pc.red("✗")} ${p}`);
254
+ console.error(
255
+ pc.red(
256
+ `\n${problems.length} problem${problems.length === 1 ? "" : "s"} must be fixed before this theme ships.`,
257
+ ),
258
+ );
251
259
  process.exit(1);
252
260
  }
253
- console.log(`[check] OK — ${registered.length} view overrides validated against core ${corePkg.version}`);
261
+ console.log(
262
+ ` ${pc.green("✓")} ${pc.bold("OK")} — ${registered.length} view override${registered.length === 1 ? "" : "s"} validated against core ${corePkg.version}`,
263
+ );
package/bin/new.js CHANGED
@@ -2,6 +2,7 @@
2
2
  /**
3
3
  * theme-core new — scaffold a working Pano theme.
4
4
  *
5
+ * bunx @panomc/theme-core new interactive wizard (TTY only)
5
6
  * bunx @panomc/theme-core new my-theme npm-published core (default)
6
7
  * bunx @panomc/theme-core new my-theme --local file: links into a local theme-core
7
8
  * checkout (this workspace)
@@ -12,9 +13,22 @@
12
13
  * theme and it carries repo-specific baggage — this scaffolder is the entry.
13
14
  */
14
15
  import { existsSync, mkdirSync, writeFileSync, readFileSync, copyFileSync } from "node:fs";
15
- import { join, dirname, resolve } from "node:path";
16
+ import { spawnSync } from "node:child_process";
17
+ import { join, dirname, resolve, basename } from "node:path";
16
18
  import { fileURLToPath } from "node:url";
17
19
  import { createRequire } from "node:module";
20
+ import {
21
+ pc,
22
+ isInteractive,
23
+ cancelGuard,
24
+ brandIntro,
25
+ text,
26
+ confirm,
27
+ spinner,
28
+ outro,
29
+ note,
30
+ DOCS_URL,
31
+ } from "./ui.js";
18
32
 
19
33
  const binDir = dirname(fileURLToPath(import.meta.url));
20
34
  const corePkgDir = join(binDir, "..");
@@ -22,26 +36,93 @@ const corePkg = JSON.parse(readFileSync(join(corePkgDir, "package.json"), "utf-8
22
36
  const require = createRequire(import.meta.url);
23
37
 
24
38
  const args = process.argv.slice(2);
25
- const name = args.find((a) => !a.startsWith("-"));
39
+ const nameArg = args.find((a) => !a.startsWith("-"));
26
40
  const local = args.includes("--local") || corePkg.version === "0.0.0-development";
27
41
 
28
- if (!name || !/^[a-z][a-z0-9-]*$/.test(name)) {
29
- console.error("usage: bunx @panomc/theme-core new <kebab-case-name> [--local]");
30
- process.exit(1);
31
- }
32
-
33
- const dir = resolve(process.cwd(), name);
34
- if (existsSync(dir)) {
35
- console.error(`[theme-core] ${dir} already exists — refusing to overwrite`);
36
- process.exit(1);
42
+ const KEBAB = /^[a-z][a-z0-9-]*$/;
43
+ const titleFrom = (name) =>
44
+ name
45
+ .split("-")
46
+ .map((w) => w[0].toUpperCase() + w.slice(1))
47
+ .join(" ");
48
+
49
+ // ---- resolve inputs ---------------------------------------------------------
50
+ // Prompt for EVERYTHING before a single file is written, so a Ctrl+C never
51
+ // leaves a half-created theme on disk.
52
+ let name, dir, title, author, doInstall;
53
+ const interactive = isInteractive() && !nameArg;
54
+
55
+ if (interactive) {
56
+ brandIntro();
57
+
58
+ const where = cancelGuard(
59
+ await text({
60
+ message: "Where should we create your theme?",
61
+ placeholder: "./my-theme",
62
+ defaultValue: "./my-theme",
63
+ validate(value) {
64
+ const v = (value || "./my-theme").trim();
65
+ const base = basename(resolve(process.cwd(), v));
66
+ if (!KEBAB.test(base))
67
+ return "The folder name must be kebab-case (a-z, 0-9, dashes).";
68
+ if (existsSync(resolve(process.cwd(), v)))
69
+ return `${v} already exists — pick a path that doesn't exist yet.`;
70
+ },
71
+ }),
72
+ );
73
+ const rel = (where || "./my-theme").trim();
74
+ dir = resolve(process.cwd(), rel);
75
+ name = basename(dir);
76
+
77
+ title = cancelGuard(
78
+ await text({
79
+ message: "Theme title?",
80
+ placeholder: titleFrom(name),
81
+ defaultValue: titleFrom(name),
82
+ }),
83
+ );
84
+ title = (title || titleFrom(name)).trim();
85
+
86
+ author = cancelGuard(
87
+ await text({
88
+ message: "Author?",
89
+ placeholder: "CHANGE-ME",
90
+ defaultValue: "CHANGE-ME",
91
+ }),
92
+ );
93
+ author = (author || "CHANGE-ME").trim() || "CHANGE-ME";
94
+
95
+ doInstall = cancelGuard(
96
+ await confirm({
97
+ message: "Install dependencies with bun now?",
98
+ initialValue: true,
99
+ }),
100
+ );
101
+ } else {
102
+ // Non-interactive: a name argument is mandatory. No prompts, no install.
103
+ if (!nameArg || !KEBAB.test(nameArg)) {
104
+ if (!nameArg && !process.stdout.isTTY) {
105
+ console.error(
106
+ `${pc.red("✗")} a theme name is required in non-interactive mode\n usage: ${pc.cyan("bunx @panomc/theme-core new <kebab-case-name> [--local]")}\n ${pc.dim("(run it in a terminal with no name for the interactive wizard)")}`,
107
+ );
108
+ } else {
109
+ console.error(
110
+ `${pc.red("✗")} usage: ${pc.cyan("bunx @panomc/theme-core new <kebab-case-name> [--local]")}`,
111
+ );
112
+ }
113
+ process.exit(1);
114
+ }
115
+ name = nameArg;
116
+ dir = resolve(process.cwd(), name);
117
+ if (existsSync(dir)) {
118
+ console.error(`${pc.red("✗")} ${dir} already exists — refusing to overwrite`);
119
+ process.exit(1);
120
+ }
121
+ title = titleFrom(name);
122
+ author = "CHANGE-ME";
123
+ doInstall = false;
37
124
  }
38
125
 
39
- const title = name
40
- .split("-")
41
- .map((w) => w[0].toUpperCase() + w.slice(1))
42
- .join(" ");
43
-
44
-
45
126
  // ---- dependency sources -----------------------------------------------------
46
127
  // Local mode links straight into the workspace checkout so the scaffold works
47
128
  // before the packages exist on npm; published mode uses semver ranges.
@@ -90,7 +171,7 @@ const FILES = {
90
171
  id: name,
91
172
  title,
92
173
  version: "1.0.0",
93
- author: "CHANGE-ME",
174
+ author,
94
175
  description: `${title} theme for Pano`,
95
176
  panoVersion: "1.0.0",
96
177
  screenshots: [],
@@ -184,6 +265,7 @@ build/
184
265
  plugins/
185
266
  static/runtime/
186
267
  static/lib/
268
+ static/assets/
187
269
  src/lib/server/license-constants.generated.js
188
270
  `,
189
271
 
@@ -247,9 +329,8 @@ ${collectTokens()}`,
247
329
  A Pano theme built on [@panomc/theme-core](https://github.com/PanoMC/sdk).
248
330
 
249
331
  \`\`\`sh
250
- bun install
251
- bun run sync # generate routes / lang / lib bridges
252
- bun run dev # against a local Pano backend (VITE_API_URL in .env)
332
+ bun install # also generates routes / lang / lib bridges
333
+ bun run dev:ui # against a local Pano backend (VITE_API_URL in .env)
253
334
  bun run check # contract lint
254
335
  bun run build && bun run package
255
336
  \`\`\`
@@ -259,23 +340,73 @@ bun run build && bun run package
259
340
  `,
260
341
  };
261
342
 
262
-
263
- for (const [rel, content] of Object.entries(FILES)) {
264
- const target = join(dir, rel);
265
- mkdirSync(dirname(target), { recursive: true });
266
- writeFileSync(target, content);
343
+ // ---- scaffold ---------------------------------------------------------------
344
+ function scaffold() {
345
+ for (const [rel, content] of Object.entries(FILES)) {
346
+ const target = join(dir, rel);
347
+ mkdirSync(dirname(target), { recursive: true });
348
+ writeFileSync(target, content);
349
+ }
350
+ copyFileSync(join(binDir, "templates", "app.html"), join(dir, "src", "app.html"));
351
+ return Object.keys(FILES).length + 1;
267
352
  }
268
- copyFileSync(join(binDir, "templates", "app.html"), join(dir, "src", "app.html"));
269
-
270
- console.log(`[theme-core] scaffolded ${name}/ (${Object.keys(FILES).length + 1} files, ${local ? "local workspace links" : `core ^${corePkg.version}`})
271
353
 
272
- Next steps:
273
- cd ${name}
274
- bun install # if it hangs at "Resolving": bun install --backend=copyfile
275
- bun run sync # generates src/routes, src/lib bridges, lang/
276
- bun run dev # needs a Pano backend (VITE_API_URL in .env)
354
+ const depLabel = local ? "local workspace links" : `core ^${corePkg.version}`;
355
+
356
+ if (interactive) {
357
+ const s = spinner();
358
+ s.start(`Scaffolding ${name}…`);
359
+ const count = scaffold();
360
+ s.stop(`Scaffolded ${count} files ${pc.dim(`(${depLabel})`)}`);
361
+
362
+ if (doInstall) {
363
+ const s2 = spinner();
364
+ s2.start("Installing dependencies (bun install)…");
365
+ const r = spawnSync("bun", ["install", "--backend=copyfile"], {
366
+ cwd: dir,
367
+ stdio: "ignore",
368
+ });
369
+ if (r.status === 0) {
370
+ s2.stop("Installed dependencies");
371
+ } else {
372
+ s2.stop(`${pc.yellow("▲")} bun install did not complete — run it yourself`);
373
+ note(
374
+ `${pc.dim("cd")} ${name}\n${pc.dim("run")} ${pc.cyan("bun install --backend=copyfile")}`,
375
+ "Finish setup manually",
376
+ );
377
+ }
378
+ }
277
379
 
278
- Make it yours:
279
- src/styles/tokens.scss colors / fonts / radius (Tier 1)
280
- bunx @panomc/theme-core list-views what you can override
281
- bunx @panomc/theme-core eject-view HomeView own a page's markup (Tier 2)`);
380
+ outro(
381
+ [
382
+ pc.bold("Your theme is ready!"),
383
+ "",
384
+ "Next steps:",
385
+ ` ${pc.cyan(`cd ${name}`)}`,
386
+ doInstall ? null : ` ${pc.cyan("bun install --backend=copyfile")}`,
387
+ ` ${pc.cyan("bun run dev:ui")}`,
388
+ "",
389
+ `Then browse through your Pano's address ${pc.dim("(e.g. http://localhost:8088)")}.`,
390
+ `Docs: ${pc.cyan(DOCS_URL)}`,
391
+ ]
392
+ .filter((l) => l !== null)
393
+ .join("\n"),
394
+ );
395
+ } else {
396
+ const count = scaffold();
397
+ console.log(
398
+ [
399
+ `${pc.green("✓")} scaffolded ${pc.bold(`${name}/`)} ${pc.dim(`(${count} files, ${depLabel})`)}`,
400
+ "",
401
+ pc.bold("Next steps:"),
402
+ ` ${pc.cyan(`cd ${name}`)}`,
403
+ ` ${pc.cyan("bun install")} ${pc.dim('# also generates routes/lang/bridges; if it hangs: bun install --backend=copyfile')}`,
404
+ ` ${pc.cyan("bun run dev:ui")} ${pc.dim("# needs a Pano backend (VITE_API_URL in .env)")}`,
405
+ "",
406
+ pc.bold("Make it yours:"),
407
+ ` ${pc.cyan("src/styles/tokens.scss")} ${pc.dim("colors / fonts / radius (Tier 1)")}`,
408
+ ` ${pc.cyan("bunx @panomc/theme-core list-views")} ${pc.dim("what you can override")}`,
409
+ ` ${pc.cyan("bunx @panomc/theme-core eject-view HomeView")} ${pc.dim("own a page's markup (Tier 2)")}`,
410
+ ].join("\n"),
411
+ );
412
+ }
@@ -13,6 +13,7 @@
13
13
  import { execFileSync } from "node:child_process";
14
14
  import { existsSync, readFileSync, rmSync, utimesSync, readdirSync, statSync } from "node:fs";
15
15
  import { join, resolve } from "node:path";
16
+ import { pc } from "./ui.js";
16
17
 
17
18
  const ROOT = process.cwd();
18
19
 
@@ -53,5 +54,7 @@ execFileSync("zip", ["-X", "-q", out, "-@"], {
53
54
  });
54
55
 
55
56
  const hash = execFileSync("sha256sum", [out]).toString().split(" ")[0];
56
- console.log(`[theme-core] ${out}`);
57
- console.log(`[theme-core] ${files.length} entries, sha256 ${hash} (this hash is the premium license identity)`);
57
+ console.log(`${pc.green("✓")} ${pc.bold("packaged")} ${pc.cyan(out)}`);
58
+ console.log(
59
+ ` ${pc.dim(`${files.length} entries, sha256`)} ${hash}\n ${pc.dim("(this hash is the premium license identity)")}`,
60
+ );
package/bin/sync.js CHANGED
@@ -13,10 +13,11 @@
13
13
  *
14
14
  * Run from the THEME's root: bun node_modules/@panomc/theme-core/bin/sync.js
15
15
  */
16
- import { mkdirSync, writeFileSync, readFileSync, existsSync, readdirSync, statSync, rmSync } from "node:fs";
16
+ import { mkdirSync, writeFileSync, readFileSync, existsSync, readdirSync, statSync, rmSync, copyFileSync } from "node:fs";
17
17
  import { join, dirname } from "node:path";
18
18
  import { fileURLToPath } from "node:url";
19
19
  import { createRequire } from "node:module";
20
+ import { pc } from "./ui.js";
20
21
 
21
22
  const EJECT_MARKER = "@theme-core-eject";
22
23
  const HEADER_JS = "// AUTO-GENERATED by theme-core sync — do not edit.\n// To take ownership of this file, add an eject comment (see theme-core docs).\n";
@@ -332,6 +333,56 @@ function backfillTokens() {
332
333
  console.log("theme-core sync: filled in the token menu in src/styles/tokens.scss");
333
334
  }
334
335
 
336
+ /**
337
+ * Static assets the engine's components and SCSS reference by absolute URL
338
+ * (/assets/img/logo.svg, quicksand fonts, FontAwesome webfonts). A thin theme
339
+ * doesn't carry them in git — they're synced into static/assets/ here.
340
+ * Existing files are NEVER overwritten, so a theme can brand its own
341
+ * logo.svg (or any other asset) by simply replacing the file.
342
+ */
343
+ function syncStaticAssets() {
344
+ const themeRequire = createRequire(join(process.cwd(), "package.json"));
345
+ const staticDir = join(process.cwd(), "static");
346
+ let copied = 0;
347
+
348
+ const copyTree = (fromDir, toDir) => {
349
+ if (!existsSync(fromDir)) return;
350
+ mkdirSync(toDir, { recursive: true });
351
+ for (const entry of readdirSync(fromDir)) {
352
+ const from = join(fromDir, entry);
353
+ const to = join(toDir, entry);
354
+ if (statSync(from).isDirectory()) {
355
+ copyTree(from, to);
356
+ } else if (!existsSync(to)) {
357
+ copyFileSync(from, to);
358
+ copied++;
359
+ }
360
+ }
361
+ };
362
+
363
+ const engineAssets = join(dirname(fileURLToPath(import.meta.url)), "..", "assets");
364
+ copyTree(join(engineAssets, "img"), join(staticDir, "assets", "img"));
365
+ if (existsSync(join(engineAssets, "robots.txt")) && !existsSync(join(staticDir, "robots.txt"))) {
366
+ copyFileSync(join(engineAssets, "robots.txt"), join(staticDir, "robots.txt"));
367
+ copied++;
368
+ }
369
+
370
+ try {
371
+ const sdkDir = dirname(themeRequire.resolve("@panomc/sdk/package.json"));
372
+ copyTree(join(sdkDir, "core", "fonts"), join(staticDir, "assets", "fonts"));
373
+ } catch {
374
+ /* sdk not installed yet — next sync run picks the fonts up */
375
+ }
376
+ try {
377
+ const faDir = dirname(themeRequire.resolve("@fortawesome/fontawesome-free/package.json"));
378
+ copyTree(join(faDir, "webfonts"), join(staticDir, "assets", "webfonts"));
379
+ } catch {
380
+ /* fontawesome not installed yet — next sync run picks the webfonts up */
381
+ }
382
+
383
+ return copied;
384
+ }
385
+
335
386
  const routesDir = join(process.cwd(), "src", "routes");
336
387
  let written = 0;
337
388
  let ejected = 0;
@@ -384,7 +435,8 @@ sweep(routesDir);
384
435
 
385
436
  const langMerged = syncLang();
386
437
  backfillTokens();
438
+ const assetsCopied = syncStaticAssets();
387
439
 
388
440
  console.log(
389
- `theme-core sync: ${written} shims written, ${ejected} ejected (kept), ${removed} stale removed, ${langMerged} lang files merged`,
441
+ `${pc.green("✓")} ${pc.bold("theme-core sync")} — ${written} shims written, ${ejected} ejected (kept), ${removed} stale removed, ${langMerged} lang files merged, ${assetsCopied} assets copied`,
390
442
  );
package/bin/theme-core.js CHANGED
@@ -2,20 +2,21 @@
2
2
  /**
3
3
  * theme-core CLI — the theme author's single entry point.
4
4
  *
5
+ * bunx @panomc/theme-core new [name] scaffold a working Pano theme
5
6
  * bunx @panomc/theme-core sync regenerate route shims + host-provides stubs
7
+ * bunx @panomc/theme-core check contract lint (view registry, svelte pin, …)
8
+ * bunx @panomc/theme-core list-views list the overridable core views
6
9
  * bunx @panomc/theme-core eject-view <ViewName>
7
10
  * copy a core default view into src/views/ and
8
11
  * register it in theme.config.js
9
- * bunx @panomc/theme-core check contract lint (view registry, svelte pin,
10
- * settings keys, mandatory slots)
11
12
  * bunx @panomc/theme-core package reproducible zip of build/ (the zip sha256
12
13
  * is the premium license identity)
13
- *
14
14
  */
15
15
  import { spawnSync } from "node:child_process";
16
16
  import { existsSync, readFileSync, writeFileSync, copyFileSync, mkdirSync } from "node:fs";
17
17
  import { join, dirname } from "node:path";
18
18
  import { fileURLToPath } from "node:url";
19
+ import { pc, version, DOCS_URL, brandIntro, outro, note } from "./ui.js";
19
20
 
20
21
  const binDir = dirname(fileURLToPath(import.meta.url));
21
22
  const [cmd, ...args] = process.argv.slice(2);
@@ -28,51 +29,160 @@ function run(script, extra = []) {
28
29
  process.exit(r.status ?? 0);
29
30
  }
30
31
 
32
+ /** name → one-line description, in help-display order. */
33
+ const COMMANDS = {
34
+ new: "scaffold a working Pano theme (interactive when run with no name)",
35
+ sync: "regenerate route shims + host-provides stubs + merged lang",
36
+ check: "contract lint — view registry, svelte pin, slots, settings",
37
+ "list-views": "list the core views you can override",
38
+ "eject-view": "copy a default view into src/views/ and register it",
39
+ package: "reproducible zip of build/ (its sha256 is the license identity)",
40
+ };
41
+
42
+ function printHelp() {
43
+ const pad = Math.max(...Object.keys(COMMANDS).map((k) => k.length));
44
+ const lines = [
45
+ `${pc.bgCyan(pc.black(" pano "))} ${pc.bold("theme-core")} ${pc.dim(`v${version}`)}`,
46
+ "",
47
+ pc.dim("The Pano theme engine CLI."),
48
+ "",
49
+ pc.bold("Usage"),
50
+ ` ${pc.cyan("bunx @panomc/theme-core")} ${pc.yellow("<command>")} ${pc.dim("[options]")}`,
51
+ "",
52
+ pc.bold("Commands"),
53
+ ];
54
+ for (const [name, desc] of Object.entries(COMMANDS)) {
55
+ const arg = name === "eject-view" ? pc.dim(" <View>") : "";
56
+ lines.push(` ${pc.yellow(name.padEnd(pad))}${arg} ${pc.dim(desc)}`);
57
+ }
58
+ lines.push(
59
+ "",
60
+ pc.bold("Examples"),
61
+ ` ${pc.cyan("bunx @panomc/theme-core new")} ${pc.dim("interactive scaffolder")}`,
62
+ ` ${pc.cyan("bunx @panomc/theme-core new my-theme")} ${pc.dim("scaffold immediately")}`,
63
+ ` ${pc.cyan("bunx @panomc/theme-core eject-view LoginView")}`,
64
+ "",
65
+ `${pc.bold("Docs")} ${pc.cyan(DOCS_URL)}`,
66
+ "",
67
+ );
68
+ console.log(lines.join("\n"));
69
+ }
70
+
71
+ /** Cheap edit distance for the "did you mean" hint on an unknown command. */
72
+ function levenshtein(a, b) {
73
+ const dp = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
74
+ for (let j = 0; j <= b.length; j++) dp[0][j] = j;
75
+ for (let i = 1; i <= a.length; i++) {
76
+ for (let j = 1; j <= b.length; j++) {
77
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
78
+ dp[i][j] = Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost);
79
+ }
80
+ }
81
+ return dp[a.length][b.length];
82
+ }
83
+
84
+ function suggest(input) {
85
+ const names = Object.keys(COMMANDS);
86
+ // Prefix match first, then closest edit distance within a small threshold.
87
+ const prefix = names.find((n) => n.startsWith(input));
88
+ if (prefix) return prefix;
89
+ let best = null;
90
+ let bestD = Infinity;
91
+ for (const n of names) {
92
+ const d = levenshtein(input, n);
93
+ if (d < bestD) {
94
+ bestD = d;
95
+ best = n;
96
+ }
97
+ }
98
+ return bestD <= 3 ? best : null;
99
+ }
100
+
31
101
  switch (cmd) {
102
+ case undefined:
103
+ case "help":
104
+ case "--help":
105
+ case "-h":
106
+ printHelp();
107
+ break;
108
+
109
+ case "--version":
110
+ case "-v":
111
+ console.log(version);
112
+ break;
113
+
32
114
  case "new":
33
115
  run("new.js", args);
34
116
  break;
35
117
  case "sync":
36
118
  run("sync.js");
37
119
  break;
120
+ case "check":
121
+ run("check.js", args);
122
+ break;
123
+ case "package":
124
+ run("package-zip.js", args);
125
+ break;
126
+
38
127
  case "list-views": {
39
128
  const contract = JSON.parse(
40
129
  readFileSync(join(binDir, "..", "skin-contract.json"), "utf-8"),
41
130
  );
42
- console.log("Overridable views (theme.config.js → views):\n");
131
+ console.log(
132
+ `\n${pc.bgCyan(pc.black(" pano "))} ${pc.bold("theme-core")} ${pc.dim(`v${version}`)}`,
133
+ );
134
+ // Wrap the (sometimes long) props list under an indented tree so the
135
+ // output stays readable instead of running one giant line per view.
136
+ const width = Math.min(process.stdout.columns || 80, 100);
137
+ const indent = " ";
138
+ const wrap = (items) => {
139
+ const lines = [];
140
+ let line = "";
141
+ for (const item of items) {
142
+ const chunk = line ? `${line}, ${item}` : item;
143
+ if (indent.length + chunk.length > width && line) {
144
+ lines.push(indent + line + ",");
145
+ line = item;
146
+ } else {
147
+ line = chunk;
148
+ }
149
+ }
150
+ if (line) lines.push(indent + line);
151
+ return lines;
152
+ };
153
+ console.log(pc.bold("\n Overridable views ") + pc.dim("(theme.config.js → views)\n"));
43
154
  for (const [name, def] of Object.entries(contract.views)) {
44
155
  const props = Object.keys(def.props ?? {});
45
- console.log(` ${name.padEnd(26)} props: ${props.join(", ") || "—"}`);
156
+ console.log(` ${pc.cyan("●")} ${pc.bold(name)}`);
157
+ if (props.length) for (const l of wrap(props)) console.log(pc.dim(l));
158
+ else console.log(indent + pc.dim("(no props)"));
46
159
  }
160
+ console.log(pc.bold("\n Registry components ") + pc.dim("(chrome + plugin-facing)"));
161
+ for (const l of wrap(contract.registry_components)) console.log(pc.dim(l));
47
162
  console.log(
48
- `\nRegistry components (chrome + plugin-facing):\n ${contract.registry_components.join(", ")}`,
49
- );
50
- console.log(
51
- "\nEject one with: bunx @panomc/theme-core eject-view <ViewName>\n(the file's header documents every prop in detail)",
163
+ `\n Eject one with ${pc.cyan("bunx @panomc/theme-core eject-view <ViewName>")}` +
164
+ `\n ${pc.dim("(the file's header documents every prop in detail)")}\n`,
52
165
  );
53
166
  break;
54
167
  }
55
- case "check":
56
- run("check.js", args);
57
- break;
58
- case "package":
59
- run("package-zip.js", args);
60
- break;
168
+
61
169
  case "eject-view": {
62
170
  const name = args[0];
63
171
  if (!name || !/^[A-Z][A-Za-z0-9]*View$/.test(name)) {
64
- console.error("usage: bunx @panomc/theme-core eject-view <ViewName> (e.g. LoginView)");
172
+ console.error(
173
+ `${pc.red("✗")} usage: ${pc.cyan("bunx @panomc/theme-core eject-view <ViewName>")} ${pc.dim("(e.g. LoginView)")}`,
174
+ );
65
175
  process.exit(1);
66
176
  }
67
177
  const source = join(binDir, "..", "src", "lib", "views", `${name}.svelte`);
68
178
  if (!existsSync(source)) {
69
- console.error(`[theme-core] no default view named '${name}' in this core version`);
179
+ console.error(`${pc.red("✗")} no default view named ${pc.bold(name)} in this core version`);
70
180
  process.exit(1);
71
181
  }
72
182
  const targetDir = join(process.cwd(), "src", "views");
73
183
  const target = join(targetDir, `${name}.svelte`);
74
184
  if (existsSync(target)) {
75
- console.error(`[theme-core] ${target} already exists — refusing to overwrite`);
185
+ console.error(`${pc.red("✗")} ${target} already exists — refusing to overwrite`);
76
186
  process.exit(1);
77
187
  }
78
188
  mkdirSync(targetDir, { recursive: true });
@@ -80,6 +190,7 @@ switch (cmd) {
80
190
 
81
191
  // Register in theme.config.js (idempotent, text-level).
82
192
  const configPath = join(process.cwd(), "theme.config.js");
193
+ let registered = false;
83
194
  if (existsSync(configPath)) {
84
195
  let cfg = readFileSync(configPath, "utf-8");
85
196
  if (!cfg.includes(`${name}:`)) {
@@ -89,14 +200,34 @@ switch (cmd) {
89
200
  );
90
201
  writeFileSync(configPath, cfg);
91
202
  }
92
- } else {
93
- console.warn("[theme-core] no theme.config.js found — register the view manually");
203
+ registered = true;
94
204
  }
95
- console.log(`[theme-core] ejected ${name} → src/views/${name}.svelte (registered in theme.config.js)`);
96
- console.log(`[theme-core] the props contract is documented at the top of the file; 'theme-core check' validates it on every build`);
205
+
206
+ brandIntro();
207
+ note(
208
+ [
209
+ `${pc.green("✓")} copied to ${pc.cyan(`src/views/${name}.svelte`)}`,
210
+ registered
211
+ ? `${pc.green("✓")} registered in ${pc.cyan("theme.config.js")}`
212
+ : `${pc.yellow("▲")} no theme.config.js found — register the view manually`,
213
+ ].join("\n"),
214
+ `Ejected ${name}`,
215
+ );
216
+ outro(
217
+ [
218
+ "Next steps:",
219
+ ` ${pc.dim("edit")} ${pc.cyan(`src/views/${name}.svelte`)} ${pc.dim("(props are documented in its header)")}`,
220
+ ` ${pc.dim("run")} ${pc.cyan("bun run check")} ${pc.dim("to validate the override contract")}`,
221
+ ].join("\n"),
222
+ );
97
223
  break;
98
224
  }
99
- default:
100
- console.error("usage: bunx @panomc/theme-core <new|sync|check|list-views|eject-view|package>");
225
+
226
+ default: {
227
+ const hint = suggest(cmd);
228
+ console.error(`${pc.red("✗")} unknown command ${pc.bold(cmd)}`);
229
+ if (hint) console.error(` did you mean ${pc.cyan(hint)}?`);
230
+ console.error(` run ${pc.cyan("theme-core help")} to see all commands`);
101
231
  process.exit(1);
232
+ }
102
233
  }
package/bin/ui.js ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * ui.js — shared CLI presentation layer for the theme-core commands.
3
+ *
4
+ * Wraps @clack/prompts + picocolors so every command speaks the same visual
5
+ * language (styled intro/outro, spinners, prompts) and shares the TTY/CI
6
+ * detection that keeps sync/check/package safe to run non-interactively.
7
+ */
8
+ import { readFileSync } from "node:fs";
9
+ import { join, dirname } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ import * as clack from "@clack/prompts";
12
+ import pc from "picocolors";
13
+
14
+ export { clack, pc };
15
+
16
+ // Re-export the clack primitives the commands reach for, so callers import
17
+ // from one place instead of poking at the namespace.
18
+ export const {
19
+ intro,
20
+ outro,
21
+ text,
22
+ confirm,
23
+ select,
24
+ spinner,
25
+ cancel,
26
+ isCancel,
27
+ note,
28
+ log,
29
+ } = clack;
30
+
31
+ const binDir = dirname(fileURLToPath(import.meta.url));
32
+ export const corePkg = JSON.parse(
33
+ readFileSync(join(binDir, "..", "package.json"), "utf-8"),
34
+ );
35
+ export const version = corePkg.version;
36
+
37
+ /**
38
+ * Interactive when we own a real TTY and are not inside CI. Every command that
39
+ * might prompt gates on this — a non-interactive invocation (scripts, CI,
40
+ * postinstall, piped stdin) must never block waiting for input.
41
+ */
42
+ export function isInteractive() {
43
+ return Boolean(process.stdout.isTTY) && !process.env.CI;
44
+ }
45
+
46
+ /**
47
+ * Unwrap a clack prompt result, honoring Ctrl+C: on cancel we print the
48
+ * standard cancel line and exit non-zero so nothing half-completes.
49
+ */
50
+ export function cancelGuard(value) {
51
+ if (isCancel(value)) {
52
+ cancel("Operation cancelled.");
53
+ process.exit(1);
54
+ }
55
+ return value;
56
+ }
57
+
58
+ /** Styled brand header: "pano theme-core vX.Y.Z". */
59
+ export function brandIntro() {
60
+ intro(
61
+ `${pc.bgCyan(pc.black(" pano "))} ${pc.bold("theme-core")} ${pc.dim(`v${version}`)}`,
62
+ );
63
+ }
64
+
65
+ /** Docs entry point, referenced by help/new/eject next-steps. */
66
+ export const DOCS_URL = "https://panocms.com/docs/theme/getting-started/";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panomc/theme-core",
3
- "version": "1.0.0-dev.45",
3
+ "version": "1.0.0-dev.47",
4
4
  "description": "The Pano theme engine: hooks factories, plugin engine, headless page controllers, default views and the theme CLI. Themes depend on this package instead of forking vanilla-theme.",
5
5
  "author": "PanoMC",
6
6
  "license": "MIT",
@@ -41,12 +41,15 @@
41
41
  "src",
42
42
  "bin",
43
43
  "lang",
44
+ "assets",
44
45
  "skin-contract.json"
45
46
  ],
46
47
  "publishConfig": {
47
48
  "access": "public"
48
49
  },
49
50
  "dependencies": {
51
+ "@clack/prompts": "^0.11.0",
52
+ "picocolors": "^1.1.0",
50
53
  "svelte": "5.55.4",
51
54
  "mime-types": "^3.0.2",
52
55
  "date-fns": "^4.1.0",