@weasel-js/hud 0.6.0 → 0.7.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.
@@ -1 +1 @@
1
- {"version":3,"file":"attach.d.ts","sourceRoot":"","sources":["../src/attach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,KAAK,EAAE,kBAAkB,EAAqD,MAAM,iBAAiB,CAAC;AAY7G,wBAAgB,SAAS,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM,IAAI,CA+GvE"}
1
+ {"version":3,"file":"attach.d.ts","sourceRoot":"","sources":["../src/attach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,KAAK,EAAE,kBAAkB,EAAwC,MAAM,iBAAiB,CAAC;AAShG,wBAAgB,SAAS,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM,IAAI,CAyFvE"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { createHud, type Hud } from './hud';
2
2
  export { attachHud } from './attach';
3
+ export { createHudTool, HUD_AFFORDANCE_KIND, type HudHitPayload } from './tool';
3
4
  export type { Widget, WidgetBounds, HudDrawCtx, HudPointerEvent, PointerClaim, } from './widget';
4
5
  export type { HudHost } from './host';
5
6
  export { DEFAULT_FONT_FAMILY, registerDefaultFont } from './fonts/registerDefaultFont';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,YAAY,EACV,MAAM,EACN,YAAY,EACZ,UAAU,EACV,eAAe,EACf,YAA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,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACjE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e, i as t, n, r, t as i } from "./attach-VLoZGx-n.js";
2
- export { r as DEFAULT_FONT_FAMILY, i as attachHud, e as createHud, n as readTokens, t as registerDefaultFont };
1
+ import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./tool-D2HHqsdo.js";
2
+ export { e as DEFAULT_FONT_FAMILY, o as HUD_AFFORDANCE_KIND, i as attachHud, a as createHud, n as createHudTool, t as readTokens, r as registerDefaultFont };
@@ -1,2 +1,2 @@
1
- export { useHud } from './useHud';
1
+ export { useHud, useHudTool } from './useHud';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
@@ -1,14 +1,17 @@
1
- import { a as e, t } from "../attach-VLoZGx-n.js";
2
- import { useEffect as n, useState as r } from "react";
1
+ import { n as e, r as t, s as n } from "../tool-D2HHqsdo.js";
2
+ import { useEffect as r, useMemo as i, useState as a } from "react";
3
3
  //#region src/react/useHud.ts
4
- function i(i) {
5
- let [a] = r(() => e());
6
- return n(() => {
7
- let e = i.current;
8
- if (e) return t(e, a);
9
- }, [a]), a;
4
+ function o(e) {
5
+ let [i] = a(() => n());
6
+ return r(() => {
7
+ let n = e.current;
8
+ if (n) return t(n, i);
9
+ }, [i]), i;
10
+ }
11
+ function s() {
12
+ return i(() => e(), []);
10
13
  }
11
14
  //#endregion
12
- export { i as useHud };
15
+ export { o as useHud, s as useHudTool };
13
16
 
14
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/react/useHud.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { createHud, type Hud } from '../hud';\nimport { attachHud } from '../attach';\nimport type { CanvasExtensionApi } from '@weasel-js/core';\n\n/**\n * Create a HUD and attach it to a Canvas via its imperative ref handle.\n * Returns the Hud immediately (unbound); attaches in an effect after the\n * canvas ref populates. Cleans up on unmount.\n *\n * Usage:\n * const ref = useRef<CanvasExtensionApi>(null);\n * const hud = useHud(ref);\n * // ... later\n * const btn = hud.button({ ... });\n */\nexport function useHud(canvasRef: { current: CanvasExtensionApi | null }): Hud {\n const [hud] = useState(() => createHud());\n\n useEffect(() => {\n const api = canvasRef.current;\n if (!api) return;\n const detach = attachHud(api, hud);\n return detach;\n // canvasRef.current changing during component lifetime is unusual for\n // canvas refs; treat as effectively-stable in v1. The dep on `hud` is\n // also stable (it comes from useState's initializer, never changes).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [hud]);\n\n return hud;\n}\n"],"mappings":";;;AAgBA,SAAgB,EAAO,GAAwD;CAC7E,IAAM,CAAC,KAAO,QAAe,GAAW,CAAC;AAazC,QAXA,QAAgB;EACd,IAAM,IAAM,EAAU;AACjB,QAEL,QADe,EAAU,GAAK,EACvB;IAKN,CAAC,EAAI,CAAC,EAEF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/react/useHud.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react';\nimport { createHud, type Hud } from '../hud';\nimport { attachHud } from '../attach';\nimport type { CanvasExtensionApi, Tool } from '@weasel-js/core';\nimport { createHudTool } from '../tool';\n\n/**\n * Create a HUD and attach it to a Canvas via its imperative ref handle.\n * Returns the Hud immediately (unbound); attaches in an effect after the\n * canvas ref populates. Cleans up on unmount.\n *\n * Usage:\n * const ref = useRef<CanvasExtensionApi>(null);\n * const hud = useHud(ref);\n * // ... later\n * const btn = hud.button({ ... });\n */\nexport function useHud(canvasRef: { current: CanvasExtensionApi | null }): Hud {\n const [hud] = useState(() => createHud());\n\n useEffect(() => {\n const api = canvasRef.current;\n if (!api) return;\n const detach = attachHud(api, hud);\n return detach;\n // canvasRef.current changing during component lifetime is unusual for\n // canvas refs; treat as effectively-stable in v1. The dep on `hud` is\n // also stable (it comes from useState's initializer, never changes).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [hud]);\n\n return hud;\n}\n\n/**\n * Memoize the HUD's input tool. Pass the result to the canvas as an ambient\n * tool — see {@link createHudTool} for why ambient and how the routing works.\n *\n * The tool is stateless (its actions resolve the hit widget from the gesture's\n * affordance payload), so one instance serves any number of HUDs on the page.\n */\nexport function useHudTool(): Tool<null> {\n return useMemo(() => createHudTool(), []);\n}\n"],"mappings":";;;AAiBA,SAAgB,EAAO,GAAwD;CAC7E,IAAM,CAAC,KAAO,QAAe,GAAW,CAAC;AAazC,QAXA,QAAgB;EACd,IAAM,IAAM,EAAU;AACjB,QAEL,QADe,EAAU,GAAK,EACvB;IAKN,CAAC,EAAI,CAAC,EAEF;;AAUT,SAAgB,IAAyB;AACvC,QAAO,QAAc,GAAe,EAAE,EAAE,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { type Hud } from '../hud';
2
- import type { CanvasExtensionApi } from '@weasel-js/core';
2
+ import type { CanvasExtensionApi, Tool } from '@weasel-js/core';
3
3
  /**
4
4
  * Create a HUD and attach it to a Canvas via its imperative ref handle.
5
5
  * Returns the Hud immediately (unbound); attaches in an effect after the
@@ -14,4 +14,12 @@ import type { CanvasExtensionApi } from '@weasel-js/core';
14
14
  export declare function useHud(canvasRef: {
15
15
  current: CanvasExtensionApi | null;
16
16
  }): Hud;
17
+ /**
18
+ * Memoize the HUD's input tool. Pass the result to the canvas as an ambient
19
+ * tool — see {@link createHudTool} for why ambient and how the routing works.
20
+ *
21
+ * The tool is stateless (its actions resolve the hit widget from the gesture's
22
+ * affordance payload), so one instance serves any number of HUDs on the page.
23
+ */
24
+ export declare function useHudTool(): Tool<null>;
17
25
  //# sourceMappingURL=useHud.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useHud.d.ts","sourceRoot":"","sources":["../../src/react/useHud.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE;IAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAAA;CAAE,GAAG,GAAG,CAe7E"}
1
+ {"version":3,"file":"useHud.d.ts","sourceRoot":"","sources":["../../src/react/useHud.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAGhE;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE;IAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAAA;CAAE,GAAG,GAAG,CAe7E;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,CAEvC"}
@@ -1,5 +1,5 @@
1
1
  import { textCommand as e, viewToTransform as t, worldToScreen as n } from "@weasel-js/core";
2
- import { registerFont as r } from "@weasel-js/core/renderer";
2
+ import { registerFont as r } from "@weasel-js/font";
3
3
  import { DEFAULT_TOKENS as i } from "@weasel-js/theme";
4
4
  //#region src/widgets/rect.ts
5
5
  function a(e) {
@@ -410,44 +410,7 @@ function _(e, r) {
410
410
  },
411
411
  hitTest: (e, r, i, o, s) => {
412
412
  let [c, l] = n(e, r, t(o)), u = a(c, l);
413
- return u ? {
414
- drag: {
415
- onStart: (e, r) => {
416
- let [i, a] = n(r.worldX, r.worldY, t(r.view));
417
- return r.scratch.widget.onPointer({
418
- type: "down",
419
- x: i,
420
- y: a,
421
- native: e
422
- }), "claim";
423
- },
424
- onMove: (e, r) => {
425
- let [i, a] = n(r.worldX, r.worldY, t(r.view));
426
- return r.scratch.widget.onPointer({
427
- type: "move",
428
- x: i,
429
- y: a,
430
- native: e
431
- }), "claim";
432
- },
433
- onEnd: (e, r) => {
434
- let [i, a] = n(r.worldX, r.worldY, t(r.view));
435
- return r.scratch.widget.onPointer({
436
- type: "up",
437
- x: i,
438
- y: a,
439
- native: e
440
- }), "claim";
441
- },
442
- onCancel: (e) => {
443
- e.scratch.widget.onPointer({
444
- type: "cancel",
445
- native: new Event("pointercancel")
446
- });
447
- }
448
- },
449
- initialScratch: { widget: u }
450
- } : null;
413
+ return u ? { initialScratch: { widget: u } } : null;
451
414
  },
452
415
  onUncapturedMove: (r, o, s, c) => {
453
416
  let [l, u] = n(r, o, t(c)), d = a(l, u);
@@ -476,6 +439,142 @@ function _(e, r) {
476
439
  };
477
440
  }
478
441
  //#endregion
479
- export { u as a, m as i, g as n, p as r, _ as t };
442
+ //#region src/tool.ts
443
+ var v = "layer:weasel-hud", y = {
444
+ shift: "optional",
445
+ alt: "optional",
446
+ meta: "optional",
447
+ ctrl: "optional"
448
+ };
449
+ function b(e) {
450
+ return e?.kind === v;
451
+ }
452
+ function x(e) {
453
+ return e?.payload?.widget ?? null;
454
+ }
455
+ function S(e, r, i) {
456
+ let a = e.view?.get();
457
+ return a ? n(r, i, t(a)) : [r, i];
458
+ }
459
+ function C() {
460
+ return {
461
+ id: "hud.press",
462
+ label: "HUD — press widget",
463
+ requires: ["view"],
464
+ invoker: {
465
+ timing: "immediate",
466
+ run: (e, t) => {
467
+ let n = t, r = x(n?.affordance);
468
+ if (!r || n?.worldX === void 0 || n.worldY === void 0) return;
469
+ let [i, a] = S(e, n.worldX, n.worldY);
470
+ r.onPointer({
471
+ type: "down",
472
+ x: i,
473
+ y: a,
474
+ native: null
475
+ });
476
+ }
477
+ }
478
+ };
479
+ }
480
+ function w() {
481
+ return {
482
+ id: "hud.release",
483
+ label: "HUD — release widget",
484
+ requires: ["view"],
485
+ invoker: {
486
+ timing: "immediate",
487
+ run: (e, t) => {
488
+ let n = t, r = x(n?.affordance);
489
+ if (!r || n?.worldX === void 0 || n.worldY === void 0) return;
490
+ let [i, a] = S(e, n.worldX, n.worldY);
491
+ r.onPointer({
492
+ type: "up",
493
+ x: i,
494
+ y: a,
495
+ native: null
496
+ });
497
+ }
498
+ }
499
+ };
500
+ }
501
+ function T() {
502
+ return {
503
+ id: "hud.drag",
504
+ label: "HUD — drag widget",
505
+ requires: ["view"],
506
+ invoker: {
507
+ timing: "ongoing",
508
+ start: (e) => {
509
+ let t = x(e.drag?.affordance);
510
+ return t ? {
511
+ onMove: (e) => {
512
+ let [n, r] = S(e.deps, e.world.x, e.world.y);
513
+ t.onPointer({
514
+ type: "move",
515
+ x: n,
516
+ y: r,
517
+ native: null
518
+ });
519
+ },
520
+ onEnd: (e, n) => {
521
+ if (n === "cancel") {
522
+ t.onPointer({
523
+ type: "cancel",
524
+ native: null
525
+ });
526
+ return;
527
+ }
528
+ let [r, i] = S(e.deps, e.world.x, e.world.y);
529
+ t.onPointer({
530
+ type: "up",
531
+ x: r,
532
+ y: i,
533
+ native: null
534
+ });
535
+ }
536
+ } : {};
537
+ }
538
+ }
539
+ };
540
+ }
541
+ function E() {
542
+ return {
543
+ id: "weasel-hud",
544
+ actions: [
545
+ C(),
546
+ w(),
547
+ T()
548
+ ],
549
+ bindings: [
550
+ {
551
+ spec: {
552
+ kind: "pointerDown",
553
+ target: { kindOf: b },
554
+ mods: y
555
+ },
556
+ actionId: "hud.press"
557
+ },
558
+ {
559
+ spec: {
560
+ kind: "click",
561
+ target: { kindOf: b },
562
+ mods: y
563
+ },
564
+ actionId: "hud.release"
565
+ },
566
+ {
567
+ spec: {
568
+ kind: "drag",
569
+ target: { kindOf: b },
570
+ mods: y
571
+ },
572
+ actionId: "hud.drag"
573
+ }
574
+ ]
575
+ };
576
+ }
577
+ //#endregion
578
+ export { p as a, g as i, E as n, m as o, _ as r, u as s, v as t };
480
579
 
481
- //# sourceMappingURL=attach-VLoZGx-n.js.map
580
+ //# sourceMappingURL=tool-D2HHqsdo.js.map