@weasel-js/hud 1.11.0 → 1.12.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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u, u as d } from "./tool-B5AjewKP.js";
1
+ import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u, u as d } from "./tool-DfJuN7jP.js";
2
2
  import { createViewportLayer as f, pathFromD as p, screenToWorld as m, textCommandFromRuns as h, viewToTransform as g } from "@weasel-js/core";
3
3
  import { clamp as _, identity as v, mat3 as y, multiply as b, pathFromD as x, rotateAboutPoint as S, roundRectPath as C, scale as w, translate as T } from "@weasel-js/geom";
4
4
  import { expandVars as E, parseBoxShadow as D, resolveCurrentColor as O, tokenPx as k } from "@weasel-js/theme";
@@ -10,7 +10,7 @@ import { releaseImageSource as se } from "@weasel-js/core/renderer";
10
10
  import { createLoupeModel as ce, loupeInnerView as le, loupeInnerView as F } from "@weasel-js/loupe";
11
11
  //#region src/menu/accessibleMenu.ts
12
12
  function ue(e, t) {
13
- return t.kind === "number" ? `${t.label}: ${ee(e.numberValue(t), t)}` : t.kind === "color" ? `${t.label}: ${t.value ?? "—"}` : t.label;
13
+ return t.kind === "number" ? `${t.label}: ${ee(e.numberValue(t), t)}` : t.kind === "color" ? `${t.label}: ${t.value ?? "—"}` : t.kind === "text" ? `${t.label}: ${e.textValue(t) ?? "—"}` : t.label;
14
14
  }
15
15
  function I(e, t) {
16
16
  let n = e.stack(), r = t === n.length - 1;
@@ -26,7 +26,7 @@ function I(e, t) {
26
26
  label: ue(e, i),
27
27
  ...r && n[t] === a ? { active: !0 } : {},
28
28
  ...i.kind === "item" && i.checked !== void 0 ? { checked: i.checked } : {},
29
- ...i.disabled || i.kind === "color" ? { disabled: !0 } : {},
29
+ ...i.disabled || i.kind === "color" || i.kind === "text" ? { disabled: !0 } : {},
30
30
  ...i.kind === "submenu" ? { expanded: s } : {},
31
31
  ...s ? { children: [{
32
32
  role: "menu",
@@ -314,6 +314,7 @@ function Ce(e, t, n) {
314
314
  function we(e, t, n) {
315
315
  if (e.kind === "number") return t.padX + K(0, t).width;
316
316
  if (e.kind === "color") return Math.max(t.rowHeight, t.padX + n(e.value ?? "—", t.fontSize));
317
+ if (e.kind === "text") return t.padX + n(e.value ?? "—", t.fontSize);
317
318
  }
318
319
  var q = (e) => ({ paint: {
319
320
  kind: "solid",
@@ -345,6 +346,15 @@ function Te(e, t, n, r, i, a) {
345
346
  ];
346
347
  }
347
348
  function Ee(e, t, n, r, i) {
349
+ return [h(e.x + r.padX, e.y + t.y, [{
350
+ text: n ?? "—",
351
+ fill: q(i.muted)
352
+ }], {
353
+ ...i.font,
354
+ align: "right"
355
+ }, void 0, t.h, "center", void 0, e.w - r.padX * 2)];
356
+ }
357
+ function De(e, t, n, r, i) {
348
358
  let a = [];
349
359
  if (n.value !== void 0) {
350
360
  let o = e.x + r.padX + (r.rowHeight - 12) / 2, s = e.y + t.y + (t.h - 12) / 2;
@@ -395,13 +405,13 @@ function X(e, t) {
395
405
  return n += r, i;
396
406
  });
397
407
  }
398
- var De = (e) => e.kind === "item" ? ae(e.shortcut) : void 0;
399
- function Oe(e, t, n) {
408
+ var Oe = (e) => e.kind === "item" ? ae(e.shortcut) : void 0;
409
+ function ke(e, t, n) {
400
410
  let r = X(e, t).at(-1), i = Math.max(0, ...e.map((e) => {
401
411
  if (e.kind === "separator") return 0;
402
412
  let r = we(e, t, n);
403
413
  if (r !== void 0) return n(e.label, t.fontSize) + r;
404
- let i = De(e);
414
+ let i = Oe(e);
405
415
  return n(e.label, t.fontSize) + Math.max(t.rowHeight, i ? t.padX + n(i, t.fontSize) : 0);
406
416
  }));
407
417
  return {
@@ -412,7 +422,7 @@ function Oe(e, t, n) {
412
422
  var Z = (e) => ({ paint: {
413
423
  kind: "solid",
414
424
  color: e
415
- } }), ke = (e, t, n, r, i) => ({
425
+ } }), Ae = (e, t, n, r, i) => ({
416
426
  kind: "path",
417
427
  path: {
418
428
  kind: "rect",
@@ -423,7 +433,7 @@ var Z = (e) => ({ paint: {
423
433
  },
424
434
  fill: Z(i)
425
435
  });
426
- function Ae(e, t, n) {
436
+ function je(e, t, n) {
427
437
  return {
428
438
  kind: "path",
429
439
  path: p(`M ${e - 3 / 2} ${t - 3} L ${e + 3 / 2} ${t} L ${e - 3 / 2} ${t + 3}`),
@@ -437,7 +447,7 @@ function Ae(e, t, n) {
437
447
  }
438
448
  };
439
449
  }
440
- function je(e, t, n) {
450
+ function Me(e, t, n) {
441
451
  return {
442
452
  kind: "path",
443
453
  path: p(`M ${e - 4} ${t} L ${e - 1.5} ${t + 2.5} L ${e + 4} ${t - 3}`),
@@ -452,12 +462,12 @@ function je(e, t, n) {
452
462
  }
453
463
  };
454
464
  }
455
- var Q = 16, Me = "var(--wzl-bevel-raised, 0 8px 24px var(--wzl-shadow))";
456
- function Ne(e, t, n, r, i, a, o = (e) => e.value) {
465
+ var Q = 16, Ne = "var(--wzl-bevel-raised, 0 8px 24px var(--wzl-shadow))";
466
+ function Pe(e, t, n, r, i, a, o = (e) => e.value) {
457
467
  let s = e.tokens, c = s["--wzl-fg"], l = O(s["--wzl-fg-muted"], c), u = k("--wzl-radius-md", s), d = {
458
468
  fontFamily: e.defaultFont,
459
469
  fontSize: i.fontSize
460
- }, f = z(t, u, D(E(Me, s)), c, {
470
+ }, f = z(t, u, D(E(Ne, s)), c, {
461
471
  x: t.x + 1,
462
472
  y: t.y + 1,
463
473
  w: t.w - 2,
@@ -481,23 +491,23 @@ function Ne(e, t, n, r, i, a, o = (e) => e.value) {
481
491
  return n.forEach((e, n) => {
482
492
  let u = m[n];
483
493
  if (e.kind === "separator") {
484
- p.push(ke(t.x + i.padX, t.y + u.y + Math.floor(u.h / 2), t.w - i.padX * 2, 1, s["--wzl-border"]));
494
+ p.push(Ae(t.x + i.padX, t.y + u.y + Math.floor(u.h / 2), t.w - i.padX * 2, 1, s["--wzl-border"]));
485
495
  return;
486
496
  }
487
- n === r && p.push(ke(t.x + 2, t.y + u.y, t.w - 4, u.h, s["--wzl-surface-hover"]));
488
- let f = e.disabled || e.kind === "color" ? l : c;
497
+ n === r && p.push(Ae(t.x + 2, t.y + u.y, t.w - 4, u.h, s["--wzl-surface-hover"]));
498
+ let f = e.disabled || e.kind === "color" || e.kind === "text" ? l : c;
489
499
  p.push(h(t.x + i.padX + i.rowHeight, t.y + u.y, [{
490
500
  text: e.label,
491
501
  fill: Z(f)
492
502
  }], d, void 0, u.h, "center"));
493
503
  let g = t.x + i.padX + i.rowHeight / 2, _ = t.y + u.y + u.h / 2, v = e.kind !== "color" && typeof e.icon == "string" ? oe(e.icon) : void 0, y = v ? a?.get(v) : void 0;
494
- e.kind === "item" && e.checked ? p.push(je(g, _, f)) : y && p.push(...G(y, {
504
+ e.kind === "item" && e.checked ? p.push(Me(g, _, f)) : y && p.push(...G(y, {
495
505
  x: g - Q / 2,
496
506
  y: _ - Q / 2,
497
507
  size: Q,
498
508
  color: f
499
509
  }));
500
- let b = De(e);
510
+ let b = Oe(e);
501
511
  b && p.push(h(t.x + i.padX, t.y + u.y, [{
502
512
  text: b,
503
513
  fill: Z(l)
@@ -511,21 +521,21 @@ function Ne(e, t, n, r, i, a, o = (e) => e.value) {
511
521
  border: s["--wzl-border"],
512
522
  font: d
513
523
  };
514
- e.kind === "number" && p.push(...Te(t, u, e, o(e), i, x)), e.kind === "color" && p.push(...Ee(t, u, e, i, x)), e.kind === "submenu" && p.push(Ae(t.x + t.w - i.padX - i.rowHeight / 2, t.y + u.y + u.h / 2, f));
524
+ e.kind === "number" && p.push(...Te(t, u, e, o(e), i, x)), e.kind === "color" && p.push(...De(t, u, e, i, x)), e.kind === "text" && p.push(...Ee(t, u, e.value, i, x)), e.kind === "submenu" && p.push(je(t.x + t.w - i.padX - i.rowHeight / 2, t.y + u.y + u.h / 2, f));
515
525
  }), p;
516
526
  }
517
- function Pe(e, t, n) {
527
+ function Fe(e, t, n) {
518
528
  let r = X(e, t).findIndex((e) => n >= e.y && n < e.y + e.h);
519
529
  return r < 0 ? null : r;
520
530
  }
521
531
  //#endregion
522
532
  //#region src/menu/measureLabel.ts
523
- function Fe(e, t) {
533
+ function Ie(e, t) {
524
534
  return e.length * t * .55;
525
535
  }
526
- function Ie(e, t, n) {
536
+ function Le(e, t, n) {
527
537
  let r = j(M(n, 400, "normal"));
528
- if (!r) return Fe(e, t);
538
+ if (!r) return Ie(e, t);
529
539
  let i = 0, a = null;
530
540
  for (let t of e) {
531
541
  let e = t.codePointAt(0);
@@ -535,7 +545,7 @@ function Ie(e, t, n) {
535
545
  }
536
546
  //#endregion
537
547
  //#region src/menu/placePanels.ts
538
- function Le(e) {
548
+ function Re(e) {
539
549
  let t = [], n = null;
540
550
  return (r, i) => {
541
551
  let a = A();
@@ -556,7 +566,7 @@ function Le(e) {
556
566
  continue;
557
567
  }
558
568
  f = !1;
559
- let p = Oe(a, l, (t, n) => i === null ? Fe(t, n) : e.measure(t, n, i)), m;
569
+ let p = ke(a, l, (t, n) => i === null ? Ie(t, n) : e.measure(t, n, i)), m;
560
570
  if (n === 0) m = e.under ? ne(p, e.under, c) : te(p, e.anchor, c);
561
571
  else {
562
572
  let e = d[n - 1].rect, t = X(r.entriesAt(n - 1), l)[o];
@@ -584,14 +594,14 @@ function Le(e) {
584
594
  }
585
595
  //#endregion
586
596
  //#region src/menu/menuWidget.ts
587
- var Re = [
597
+ var ze = [
588
598
  "pointer",
589
599
  "doubleClick",
590
600
  "contextMenu",
591
601
  "longPress",
592
602
  "wheel"
593
603
  ];
594
- function ze(e, t) {
604
+ function Be(e, t) {
595
605
  let n = t({
596
606
  x: e.x,
597
607
  y: e.y
@@ -606,16 +616,16 @@ function ze(e, t) {
606
616
  h: r.y - n.y
607
617
  };
608
618
  }
609
- function Be(e) {
619
+ function Ve(e) {
610
620
  let t = e.metrics ?? Y, r = n(e.onChange), i = N({
611
621
  entries: ie(e.open.entries, (e) => window.location.assign(e)),
612
622
  highlightFirst: e.open.source === "keyboard",
613
623
  onClose: e.close
614
- }), a = Le({
624
+ }), a = Re({
615
625
  anchor: e.toCanvas(e.open.client),
616
- ...e.open.under ? { under: ze(e.open.under, e.toCanvas) } : {},
626
+ ...e.open.under ? { under: Be(e.open.under, e.toCanvas) } : {},
617
627
  canvasSize: e.canvasSize,
618
- measure: e.measure ?? Ie,
628
+ measure: e.measure ?? Le,
619
629
  metrics: t
620
630
  }), o = null, s = a(i, o), c = !1, l = !1, u = null;
621
631
  i.subscribe(() => {
@@ -653,7 +663,7 @@ function Be(e) {
653
663
  if (e.type !== "hovermove" && e.type !== "move" && e.type !== "up") return;
654
664
  let n = d(e.x, e.y), r = e.type === "up" && l;
655
665
  if (e.type === "up" && (l = !1), r || p(n < 0 ? null : n), n < 0) return;
656
- let a = i.entriesAt(n), o = Pe(a, t, e.y - s[n].y);
666
+ let a = i.entriesAt(n), o = Fe(a, t, e.y - s[n].y);
657
667
  if (!r) i.hover(n, o, {
658
668
  x: e.x,
659
669
  y: e.y
@@ -676,7 +686,7 @@ function Be(e) {
676
686
  get disposed() {
677
687
  return c;
678
688
  },
679
- claims: Re,
689
+ claims: ze,
680
690
  focusable: !0,
681
691
  focusRing: !1,
682
692
  accessibleName: "Context menu",
@@ -687,7 +697,7 @@ function Be(e) {
687
697
  A(),
688
698
  e.icons?.getVersion()
689
699
  ],
690
- draw: (n) => (o = n.defaultFont, s = a(i, o), s.flatMap((r, a) => Ne(n, r, i.entriesAt(a), i.stack()[a] ?? null, t, e.icons, i.numberValue))),
700
+ draw: (n) => (o = n.defaultFont, s = a(i, o), s.flatMap((r, a) => Pe(n, r, i.entriesAt(a), i.stack()[a] ?? null, t, e.icons, i.numberValue))),
691
701
  hitTest: (e, t) => d(e, t) >= 0,
692
702
  cursorAt: () => "default",
693
703
  onPointer: m,
@@ -699,7 +709,7 @@ function Be(e) {
699
709
  }
700
710
  //#endregion
701
711
  //#region src/menu/attachMenuHost.ts
702
- function Ve(e, t, n) {
712
+ function He(e, t, n) {
703
713
  let r = null, i = {
704
714
  widget: null,
705
715
  visible: !1
@@ -723,7 +733,7 @@ function Ve(e, t, n) {
723
733
  c && o();
724
734
  return;
725
735
  }
726
- let l = Be({
736
+ let l = Ve({
727
737
  ...n,
728
738
  open: s,
729
739
  close: () => {
@@ -753,7 +763,7 @@ function Ve(e, t, n) {
753
763
  }
754
764
  //#endregion
755
765
  //#region src/loupe/contentWatch.ts
756
- function He(e) {
766
+ function Ue(e) {
757
767
  let t = "", n = null;
758
768
  return {
759
769
  drew(e) {
@@ -770,12 +780,12 @@ function He(e) {
770
780
  }
771
781
  //#endregion
772
782
  //#region src/loupe/pointerAim.ts
773
- var Ue = [
783
+ var We = [
774
784
  "pointerup",
775
785
  "pointercancel",
776
786
  "lostpointercapture"
777
787
  ];
778
- function We(e, t) {
788
+ function Ge(e, t) {
779
789
  let n = !1, r = (t) => {
780
790
  let n = e.getBoundingClientRect();
781
791
  return {
@@ -790,15 +800,15 @@ function We(e, t) {
790
800
  n = !1;
791
801
  };
792
802
  e.addEventListener("pointermove", i), e.addEventListener("pointerdown", a);
793
- for (let t of Ue) e.addEventListener(t, o);
803
+ for (let t of We) e.addEventListener(t, o);
794
804
  return () => {
795
805
  e.removeEventListener("pointermove", i), e.removeEventListener("pointerdown", a);
796
- for (let t of Ue) e.removeEventListener(t, o);
806
+ for (let t of We) e.removeEventListener(t, o);
797
807
  };
798
808
  }
799
809
  //#endregion
800
810
  //#region src/loupe/readback.ts
801
- function Ge(e, t, n, r, i, a, o) {
811
+ function Ke(e, t, n, r, i, a, o) {
802
812
  let s = n.x + Math.round(r.x * i), c = n.y + Math.round(r.y * i), l = _(s - Math.floor(a / 2), n.x, n.x + Math.max(0, n.width - a)), u = t - _(c - Math.floor(o / 2), n.y, n.y + Math.max(0, n.height - o)) - o, d = new Uint8Array(a * o * 4);
803
813
  e.readPixels(l, u, a, o, e.RGBA, e.UNSIGNED_BYTE, d);
804
814
  let f = new Uint8ClampedArray(a * o * 4), p = a * 4;
@@ -810,7 +820,7 @@ function Ge(e, t, n, r, i, a, o) {
810
820
  }
811
821
  //#endregion
812
822
  //#region src/loupe/createLoupe.ts
813
- var Ke = (e, t) => ({
823
+ var qe = (e, t) => ({
814
824
  kind: "path",
815
825
  path: {
816
826
  kind: "rect",
@@ -823,13 +833,13 @@ var Ke = (e, t) => ({
823
833
  kind: "solid",
824
834
  color: t
825
835
  } }
826
- }), $ = "weasel-loupe:lens", qe = {
836
+ }), $ = "weasel-loupe:lens", Je = {
827
837
  x: 0,
828
838
  y: 0,
829
839
  w: 0,
830
840
  h: 0
831
841
  };
832
- function Je(e, t, n, r, i) {
842
+ function Ye(e, t, n, r, i) {
833
843
  if (t && t.id !== null) {
834
844
  let n = {
835
845
  x: (e.x - t.rect.x) / t.view.scale.x + t.view.x,
@@ -843,7 +853,7 @@ function Je(e, t, n, r, i) {
843
853
  y: a[1]
844
854
  }, n, r, i);
845
855
  }
846
- function Ye(e) {
856
+ function Xe(e) {
847
857
  let { hud: t, canvas: n, requestRedraw: r } = e, i = e.views, a = i !== void 0 && e.interactive === !0, o = e.input ?? n, s = null, c = null, l = () => {
848
858
  c &&= (se(c), c.close(), null);
849
859
  }, u = !1, d = !1, p = !1, m = !1, h = e.bounds ?? {
@@ -851,7 +861,7 @@ function Ye(e) {
851
861
  y: 24,
852
862
  w: 220,
853
863
  h: 200
854
- }, g = He(e.contentVersion ?? i?.getPaintedVersion), _ = !1, v = (e) => (g.drew(e.view), j.mode === "vector" ? S(e) : C(e)), y = (t) => e.background ?? t.tokens["--wzl-surface"], b = (e) => Ke(e, y(e)), x = (e, t) => Je(j.aim, i?.viewAt?.(j.aim, { except: $ }) ?? null, e, t, j.factor), S = (t) => i ? s ? [b(t), ...s.draw(t.data, t.view, t.dims)] : [b(t)] : f({
864
+ }, g = Ue(e.contentVersion ?? i?.getPaintedVersion), _ = !1, v = (e) => (g.drew(e.view), j.mode === "vector" ? S(e) : C(e)), y = (t) => e.background ?? t.tokens["--wzl-surface"], b = (e) => qe(e, y(e)), x = (e, t) => Ye(j.aim, i?.viewAt?.(j.aim, { except: $ }) ?? null, e, t, j.factor), S = (t) => i ? s ? [b(t), ...s.draw(t.data, t.view, t.dims)] : [b(t)] : f({
855
865
  id: `${O.id}:lens`,
856
866
  label: "Loupe content",
857
867
  source: e.source ?? [],
@@ -888,7 +898,7 @@ function Ye(e) {
888
898
  width: n.width,
889
899
  height: n.height
890
900
  };
891
- return Ge(o, n.height, u, t, c, r(c), a(c));
901
+ return Ke(o, n.height, u, t, c, r(c), a(c));
892
902
  }, E = () => {
893
903
  if (p || j.mode !== "pixel") return;
894
904
  let e = O.contentRect, t = T(j.aim, (t) => Math.max(1, Math.round(e.w * t / j.factor)), (t) => Math.max(1, Math.round(e.h * t / j.factor)));
@@ -948,13 +958,13 @@ function Ye(e) {
948
958
  i && (s = i.addView({
949
959
  id: $,
950
960
  label: "Loupe",
951
- bounds: () => O.hidden ? qe : O.contentRect,
961
+ bounds: () => O.hidden ? Je : O.contentRect,
952
962
  view: (e) => x(e, O.contentRect),
953
963
  paint: !1,
954
964
  interactive: a,
955
965
  ...e.source ? { layers: () => e.source } : {}
956
966
  }));
957
- let M = We(o, {
967
+ let M = Ge(o, {
958
968
  aimAt: (e) => j.aimAt(e),
959
969
  holds: (e) => a && k.covers(e)
960
970
  }), N = () => {
@@ -987,6 +997,6 @@ function Ye(e) {
987
997
  };
988
998
  }
989
999
  //#endregion
990
- export { i as DEFAULT_FONT_FAMILY, Y as DEFAULT_MENU_METRICS, a as DEFAULT_WIDGET_CLAIMS, l as DEFAULT_WINDOW_METRICS, u as HUD_AFFORDANCE_KIND, c as attachHud, Ve as attachMenuHost, z as boxShadowCommands, d as claimsOf, s as createHud, o as createHudContribution, Ye as createLoupe, Be as createMenuWidget, t as cursorForZone, G as glyphCommands, r as isFocusable, le as loupeInnerView, Ie as measureLabel, e as registerDefaultFont };
1000
+ export { i as DEFAULT_FONT_FAMILY, Y as DEFAULT_MENU_METRICS, a as DEFAULT_WIDGET_CLAIMS, l as DEFAULT_WINDOW_METRICS, u as HUD_AFFORDANCE_KIND, c as attachHud, He as attachMenuHost, z as boxShadowCommands, d as claimsOf, s as createHud, o as createHudContribution, Xe as createLoupe, Ve as createMenuWidget, t as cursorForZone, G as glyphCommands, r as isFocusable, le as loupeInnerView, Le as measureLabel, e as registerDefaultFont };
991
1001
 
992
1002
  //# sourceMappingURL=index.js.map