@weasel-js/hud 1.4.4 → 1.5.1

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.
@@ -353,19 +353,19 @@ function _(e) {
353
353
  //#region src/widgets/window/window.ts
354
354
  var v = 3;
355
355
  function y(n) {
356
- let r = n.titlebar ?? !0, a = {
356
+ let r = n.titlebar ?? !0, a = n.interior === "pass", o = {
357
357
  ...p,
358
358
  ...n.metrics
359
- }, o = r ? a : {
360
- ...a,
361
- titleH: a.edge
362
- }, s = n.minW ?? 80, c = n.minH ?? o.titleH + o.edge + 40, l = (e) => ({
359
+ }, s = r ? o : {
360
+ ...o,
361
+ titleH: o.edge
362
+ }, c = n.minW ?? 80, l = n.minH ?? s.titleH + s.edge + 40, u = (e) => ({
363
363
  x: e.x,
364
364
  y: e.y,
365
- w: Math.max(s, e.w),
366
- h: Math.max(c, e.h)
367
- }), u = null, d = (e) => {
368
- if (!u) return e;
365
+ w: Math.max(c, e.w),
366
+ h: Math.max(l, e.h)
367
+ }), d = null, f = (e) => {
368
+ if (!d) return e;
369
369
  let t = i({
370
370
  x: e.x,
371
371
  y: e.y,
@@ -374,84 +374,84 @@ function y(n) {
374
374
  }, {
375
375
  x: 0,
376
376
  y: 0,
377
- width: u.width,
378
- height: u.height
377
+ width: d.width,
378
+ height: d.height
379
379
  });
380
380
  return {
381
381
  ...e,
382
382
  x: t.x,
383
383
  y: t.y
384
384
  };
385
- }, f = !1, y = !1, b = n.title, x = l({
385
+ }, y = !1, b = !1, x = n.title, S = u({
386
386
  x: n.x,
387
387
  y: n.y,
388
388
  w: n.w,
389
389
  h: n.h
390
- }), S = null, C = x, w = {
390
+ }), C = null, w = S, T = {
391
391
  x: 0,
392
392
  y: 0
393
- }, T = null, E = !1, D = () => {
394
- if (f) throw Error("weasel-hud: cannot mutate a disposed widget.");
395
- }, O = (e) => !r && e === "content" ? "title" : e, k = () => ({
396
- x: x.x + x.w - o.edge - o.closeSize,
397
- y: x.y + (o.titleH - o.closeSize) / 2,
398
- w: o.closeSize,
399
- h: o.closeSize
393
+ }, E = null, D = !1, O = () => {
394
+ if (y) throw Error("weasel-hud: cannot mutate a disposed widget.");
395
+ }, k = (e) => !r && !a && e === "content" ? "title" : e, A = () => ({
396
+ x: S.x + S.w - s.edge - s.closeSize,
397
+ y: S.y + (s.titleH - s.closeSize) / 2,
398
+ w: s.closeSize,
399
+ h: s.closeSize
400
400
  });
401
401
  return {
402
402
  id: n.id,
403
403
  get bounds() {
404
- return x;
404
+ return S;
405
405
  },
406
406
  get hidden() {
407
- return y;
407
+ return b;
408
408
  },
409
409
  get disposed() {
410
- return f;
410
+ return y;
411
411
  },
412
412
  get contentRect() {
413
- return h(x, o);
413
+ return h(S, s);
414
414
  },
415
415
  cursorAt(e, t) {
416
- let n = O(m(x, o, e, t));
416
+ let n = k(m(S, s, e, t));
417
417
  return n ? _(n) : "default";
418
418
  },
419
419
  content: n.content,
420
420
  setBounds(e) {
421
- D(), x = d(l(e)), S = null, T = null, n.onChange?.();
421
+ O(), S = f(u(e)), C = null, E = null, n.onChange?.();
422
422
  },
423
423
  setHidden(e) {
424
- D(), y = e, n.onChange?.();
424
+ O(), b = e, n.onChange?.();
425
425
  },
426
426
  setTitle(e) {
427
- D(), b = e, n.onChange?.();
427
+ O(), x = e, n.onChange?.();
428
428
  },
429
429
  draw(n) {
430
- u = n.dims;
431
- let { x: i, y: a, w: s, h: c } = x, l = [], d = n.tokens["--wzl-surface-raised"], f = a + o.titleH, p = c - o.titleH, m = [
430
+ d = n.dims;
431
+ let { x: i, y: a, w: o, h: c } = S, l = [], u = n.tokens["--wzl-surface-raised"], f = a + s.titleH, p = c - s.titleH, m = [
432
432
  {
433
433
  x: i,
434
434
  y: a,
435
- width: s,
436
- height: o.titleH
435
+ width: o,
436
+ height: s.titleH
437
437
  },
438
438
  {
439
439
  x: i,
440
440
  y: f,
441
- width: o.edge,
441
+ width: s.edge,
442
442
  height: p
443
443
  },
444
444
  {
445
- x: i + s - o.edge,
445
+ x: i + o - s.edge,
446
446
  y: f,
447
- width: o.edge,
447
+ width: s.edge,
448
448
  height: p
449
449
  },
450
450
  {
451
- x: i + o.edge,
452
- y: a + c - o.edge,
453
- width: s - o.edge * 2,
454
- height: o.edge
451
+ x: i + s.edge,
452
+ y: a + c - s.edge,
453
+ width: o - s.edge * 2,
454
+ height: s.edge
455
455
  }
456
456
  ];
457
457
  for (let e of m) l.push({
@@ -462,7 +462,7 @@ function y(n) {
462
462
  },
463
463
  fill: {
464
464
  fill: "solid",
465
- color: d
465
+ color: u
466
466
  }
467
467
  });
468
468
  let h = {
@@ -471,7 +471,7 @@ function y(n) {
471
471
  kind: "rect",
472
472
  x: i,
473
473
  y: a,
474
- width: s,
474
+ width: o,
475
475
  height: c
476
476
  },
477
477
  stroke: {
@@ -483,8 +483,8 @@ function y(n) {
483
483
  }
484
484
  };
485
485
  if (l.push(h), !r) return l;
486
- l.push(t(i + o.edge + 2, a, [{
487
- text: b,
486
+ l.push(t(i + s.edge + 2, a, [{
487
+ text: x,
488
488
  fill: {
489
489
  fill: "solid",
490
490
  color: n.tokens["--wzl-fg-muted"]
@@ -492,11 +492,11 @@ function y(n) {
492
492
  }], {
493
493
  fontFamily: n.defaultFont,
494
494
  fontSize: 12
495
- }, s - o.edge * 2 - o.closeSize - 4, o.titleH, "center"));
496
- let g = k(), _ = g.x + 3, v = g.y + 3, y = g.x + g.w - 3, S = g.y + g.h - 3;
495
+ }, o - s.edge * 2 - s.closeSize - 4, s.titleH, "center"));
496
+ let g = A(), _ = g.x + 3, v = g.y + 3, y = g.x + g.w - 3, b = g.y + g.h - 3;
497
497
  return l.push({
498
498
  kind: "path",
499
- path: e(`M ${_} ${v} L ${y} ${S} M ${y} ${v} L ${_} ${S}`),
499
+ path: e(`M ${_} ${v} L ${y} ${b} M ${y} ${v} L ${_} ${b}`),
500
500
  stroke: {
501
501
  paint: {
502
502
  fill: "solid",
@@ -508,37 +508,42 @@ function y(n) {
508
508
  }), l;
509
509
  },
510
510
  hitTest(e, t) {
511
- return y ? !1 : m(x, o, e, t) !== null;
511
+ if (b) return !1;
512
+ let n = m(S, s, e, t);
513
+ return n !== null && !(a && n === "content");
514
+ },
515
+ passes(e, t) {
516
+ return a && !b && m(S, s, e, t) === "content";
512
517
  },
513
518
  onPointer(e) {
514
519
  switch (e.type) {
515
520
  case "down":
516
- T = m(x, o, e.x, e.y), E = !1, S = O(T), C = x, w = {
521
+ E = m(S, s, e.x, e.y), D = !1, C = k(E), w = S, T = {
517
522
  x: e.x,
518
523
  y: e.y
519
524
  };
520
525
  break;
521
526
  case "move": {
522
- if (!S) break;
523
- Math.hypot(e.x - w.x, e.y - w.y) > v && (E = !0);
524
- let t = g(C, S, e.x - w.x, e.y - w.y, s, c), r = S === "title" ? d(t) : t;
525
- (r.x !== x.x || r.y !== x.y || r.w !== x.w || r.h !== x.h) && (x = r, (S === "title" ? n.onMove : n.onResize)?.(x), n.onChange?.());
527
+ if (!C) break;
528
+ Math.hypot(e.x - T.x, e.y - T.y) > v && (D = !0);
529
+ let t = g(w, C, e.x - T.x, e.y - T.y, c, l), r = C === "title" ? f(t) : t;
530
+ (r.x !== S.x || r.y !== S.y || r.w !== S.w || r.h !== S.h) && (S = r, (C === "title" ? n.onMove : n.onResize)?.(S), n.onChange?.());
526
531
  break;
527
532
  }
528
533
  case "up":
529
- S === "close" && m(x, o, e.x, e.y) === "close" ? n.onClose?.() : T === "content" && !E && n.onContentClick?.({
534
+ C === "close" && m(S, s, e.x, e.y) === "close" ? n.onClose?.() : E === "content" && !D && n.onContentClick?.({
530
535
  x: e.x,
531
536
  y: e.y
532
- }), S = null, T = null;
537
+ }), C = null, E = null;
533
538
  break;
534
539
  case "cancel":
535
- S && (x = C, S = null, n.onChange?.()), T = null;
540
+ C && (S = w, C = null, n.onChange?.()), E = null;
536
541
  break;
537
542
  default: break;
538
543
  }
539
544
  },
540
545
  dispose() {
541
- f || (f = !0, n.removeFromHud?.());
546
+ y || (y = !0, n.removeFromHud?.());
542
547
  }
543
548
  };
544
549
  }
@@ -673,7 +678,7 @@ function T(e, t, n) {
673
678
  //#endregion
674
679
  //#region src/attach.ts
675
680
  function E(e, t, i = {}) {
676
- let a = i.theme ?? o(s, s.defaultMode);
681
+ let a = i.theme ?? o(s);
677
682
  if (t.attached) throw Error("weasel-hud: this HUD is already attached to a canvas.");
678
683
  let c = i.font, l = typeof c == "string" ? c : x;
679
684
  typeof c != "string" && S(c).then(() => e.requestRedraw()).catch((e) => {
@@ -683,6 +688,7 @@ function E(e, t, i = {}) {
683
688
  let r = t.widgets();
684
689
  for (let t = r.length - 1; t >= 0; t--) {
685
690
  let i = r[t];
691
+ if (!i.hidden && i.passes?.(e, n)) return null;
686
692
  if (w(i).length !== 0 && !i.hidden && i.hitTest(e, n)) return i;
687
693
  }
688
694
  return null;
@@ -990,4 +996,4 @@ function R() {
990
996
  //#endregion
991
997
  export { w as a, b as c, C as i, p as l, R as n, x as o, E as r, S as s, D as t, _ as u };
992
998
 
993
- //# sourceMappingURL=tool-ahNtvOfu.js.map
999
+ //# sourceMappingURL=tool-D-WiQSIl.js.map