@panomc/theme-core 1.0.0-dev.50 → 1.0.0-dev.52

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/bin/ui.js CHANGED
@@ -4,29 +4,56 @@
4
4
  * Wraps @clack/prompts + picocolors so every command speaks the same visual
5
5
  * language (styled intro/outro, spinners, prompts) and shares the TTY/CI
6
6
  * detection that keeps sync/check/package safe to run non-interactively.
7
+ *
8
+ * Both packages are OPTIONAL at runtime: a consumer whose installer skipped
9
+ * the engine's transitive dependencies (bun does this for file:-linked
10
+ * submodule setups with a stale lockfile) must still be able to run
11
+ * sync/check/package — they just get plain, unstyled output. Only the
12
+ * interactive wizard genuinely needs @clack and says so when it's missing.
7
13
  */
8
14
  import { readFileSync } from "node:fs";
9
15
  import { join, dirname } from "node:path";
10
16
  import { fileURLToPath } from "node:url";
11
- import * as clack from "@clack/prompts";
12
- import pc from "picocolors";
17
+
18
+ let clack;
19
+ try {
20
+ // computed specifier: keeps bun from resolving the import eagerly at load
21
+ clack = await import("@clack/" + "prompts");
22
+ } catch {
23
+ const line = (msg = "") => console.log(msg);
24
+ const missing = () => {
25
+ console.error(
26
+ "the interactive wizard needs @clack/prompts (run bun install in the theme, or pass arguments instead)",
27
+ );
28
+ process.exit(1);
29
+ };
30
+ clack = {
31
+ intro: line,
32
+ outro: line,
33
+ note: (msg, title) => line(title ? `\n${title}\n${msg}` : msg),
34
+ log: { info: line, warn: line, error: line, success: line, step: line, message: line },
35
+ cancel: line,
36
+ isCancel: () => false,
37
+ spinner: () => ({ start: line, stop: line, message: line }),
38
+ text: missing,
39
+ confirm: missing,
40
+ select: missing,
41
+ };
42
+ }
43
+
44
+ let pc;
45
+ try {
46
+ pc = (await import("pico" + "colors")).default;
47
+ } catch {
48
+ pc = new Proxy({}, { get: () => (s) => String(s) });
49
+ }
13
50
 
14
51
  export { clack, pc };
15
52
 
16
53
  // Re-export the clack primitives the commands reach for, so callers import
17
54
  // 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;
55
+ export const { intro, outro, text, confirm, select, spinner, cancel, isCancel, note, log } =
56
+ clack;
30
57
 
31
58
  const binDir = dirname(fileURLToPath(import.meta.url));
32
59
  export const corePkg = JSON.parse(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panomc/theme-core",
3
- "version": "1.0.0-dev.50",
3
+ "version": "1.0.0-dev.52",
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",
@@ -22,7 +22,8 @@
22
22
  class="list-group list-group-flush text-center bg-transparent position-relative z-1">
23
23
  <li class="list-group-item border-0 py-2 bg-transparent">
24
24
  <button
25
- class="btn btn-link {playCardIpColor} border-0 shadow-none text-decoration-none w-100 focus-ring fs-3"
25
+ class="btn btn-link {playCardIpColor} border-0 shadow-none text-decoration-none w-100 focus-ring play-card-ip"
26
+ style="--ip-len: {playCardIpLength}; --ip-max: 28px;"
26
27
  type="button"
27
28
  on:click={onCopyCommandTextClick}
28
29
  use:tooltip={[
@@ -31,7 +32,7 @@
31
32
  : $_("sidebars.home.copy"),
32
33
  { placement: "top", hideOnClick: false },
33
34
  ]}>
34
- <b class="d-block text-truncate">{playCardIpText}</b>
35
+ <b class="d-block" bind:this={ipEl}>{playCardIpText}</b>
35
36
  </button>
36
37
  </li>
37
38
  {#if showPlayCardStatusBadge}
@@ -69,7 +70,8 @@
69
70
  <div
70
71
  class="card-header {playCardHeaderClass} p-0 rounded-top border-bottom border-5 {playCardBorderColor}">
71
72
  <button
72
- class="btn btn-{playCardBtnColor} border-0 shadow-none text-decoration-none w-100 focus-ring fs-4 py-2"
73
+ class="btn btn-{playCardBtnColor} border-0 shadow-none text-decoration-none w-100 focus-ring py-2 play-card-ip"
74
+ style="--ip-len: {playCardIpLength}; --ip-max: 24px;"
73
75
  type="button"
74
76
  on:click={onCopyCommandTextClick}
75
77
  use:tooltip={[
@@ -78,7 +80,7 @@
78
80
  : $_("sidebars.home.copy"),
79
81
  { placement: "top", hideOnClick: false },
80
82
  ]}>
81
- <b class="d-block text-truncate">{playCardIpText}</b>
83
+ <b class="d-block" bind:this={ipEl}>{playCardIpText}</b>
82
84
  </button>
83
85
  </div>
84
86
  <div
@@ -214,7 +216,7 @@
214
216
  </script>
215
217
 
216
218
  <script>
217
- import { getContext } from "svelte";
219
+ import { getContext, onMount } from "svelte";
218
220
  import { _ } from "svelte-i18n";
219
221
  import copy from "copy-to-clipboard";
220
222
  import tooltip from "$pano/lib/tooltip.util";
@@ -310,12 +312,96 @@
310
312
  : themeSettings.playCardBorderColor;
311
313
 
312
314
  $: playCardIpText = themeSettings.playCardIpText || $data.ipAddress;
315
+ // Feeds the no-JS estimate in the stylesheet; 1 keeps that division safe
316
+ // before the address has loaded.
317
+ $: playCardIpLength = String(playCardIpText || "").length || 1;
318
+
313
319
  $: showPlayCardStatusBadge = themeSettings.playCardStatusBadge ?? true;
314
320
  $: showPlayCardPlayerCount = themeSettings.playCardPlayerCount ?? true;
315
321
  $: showPlayCardVersionInfo = themeSettings.playCardVersionInfo ?? true;
322
+
323
+ /* Address fit — see the stylesheet for why the CSS alone is not enough.
324
+ Measuring beats guessing at per-character width: reset to the maximum,
325
+ compare what the text wants against what the button gives it, and scale by
326
+ that ratio. Runs on mount, whenever the address changes, once webfonts have
327
+ settled (metrics shift under the fallback face), and on resize. */
328
+ const IP_MIN_PX = 13.6; // 0.85rem — matches the clamp floor
329
+
330
+ let ipEl;
331
+
332
+ function fitIpText() {
333
+ const el = ipEl;
334
+ if (!el) return;
335
+
336
+ const max = parseFloat(getComputedStyle(el).getPropertyValue("--ip-max")) || 28;
337
+
338
+ el.style.whiteSpace = "";
339
+ el.style.fontSize = `${max}px`;
340
+
341
+ const available = el.clientWidth;
342
+ if (!available) return;
343
+
344
+ // Two passes: scaling by the first ratio overshoots slightly because
345
+ // letter-spacing does not scale with the font, so re-measure and correct.
346
+ let size = max;
347
+ for (let pass = 0; pass < 2 && el.scrollWidth > available; pass++) {
348
+ size = Math.max(IP_MIN_PX, (size * available) / el.scrollWidth);
349
+ el.style.fontSize = `${size}px`;
350
+ }
351
+
352
+ // An address long enough to hit the legibility floor wraps onto a second
353
+ // line — still the whole address, which cutting it off would not be.
354
+ el.style.whiteSpace = el.scrollWidth > available ? "normal" : "";
355
+ }
356
+
357
+ // Re-fit when the address changes; ipEl is undefined until mounted and on the
358
+ // server, so this is a no-op there.
359
+ $: playCardIpText, ipEl && fitIpText();
360
+
361
+ onMount(() => {
362
+ fitIpText();
363
+
364
+ const observer = new ResizeObserver(fitIpText);
365
+ if (ipEl?.parentElement) observer.observe(ipEl.parentElement);
366
+
367
+ document.fonts?.ready.then(fitIpText).catch(() => {});
368
+
369
+ return () => observer.disconnect();
370
+ });
316
371
  </script>
317
372
 
318
373
  <style>
374
+ /* The server address is site-supplied and routinely longer than a stock
375
+ "play.example.com", so the old fixed .fs-3 overflowed the card and got cut
376
+ off by .text-truncate — an ellipsised address is worse than useless, since
377
+ the whole point of the card is that you can read and copy it. It now
378
+ shrinks to fit instead.
379
+
380
+ This rule is the server-rendered / no-JS baseline: the button is a size
381
+ container, so 100cqi is exactly the width the address has to live in, and
382
+ 0.72em is a deliberately pessimistic per-character advance — themes ship
383
+ very different faces (a wide serif costs far more per character than a
384
+ narrow sans), so this errs small rather than risk clipping. fitIpText()
385
+ then measures the real text on mount and hands back whatever headroom the
386
+ estimate gave away, which is why --ip-max is in px: it is read from here. */
387
+ .play-card-ip {
388
+ container-type: inline-size;
389
+ }
390
+
391
+ .play-card-ip b {
392
+ font-size: clamp(
393
+ 0.85rem,
394
+ calc(100cqi / (var(--ip-len, 16) * 0.72)),
395
+ var(--ip-max, 28px)
396
+ );
397
+ line-height: 1.25;
398
+ white-space: nowrap;
399
+ overflow: hidden;
400
+ /* inert while nowrap holds; it only matters once fitIpText() lets an
401
+ over-long address wrap, and an address has no spaces to break at. */
402
+ overflow-wrap: anywhere;
403
+ }
404
+
319
405
  @media (min-width: 992px) {
320
406
  .square-card-desktop {
321
407
  aspect-ratio: 1 / 1;