@weasel-js/hud 1.5.0 → 1.5.2
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, i as n, l as r, n as i, o as a, r as o, s, t as c, u as l } from "./tool-
|
|
1
|
+
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c, u as l } from "./tool-D-WiQSIl.js";
|
|
2
2
|
import { createViewportLayer as u, screenToWorld as d, viewToTransform as f } from "@weasel-js/core";
|
|
3
3
|
import { createLoupeModel as p, loupeInnerView as m, loupeInnerView as h } from "@weasel-js/loupe";
|
|
4
4
|
//#region src/loupe/readback.ts
|
package/dist/react/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { c as e, n as t, r as n } from "../tool-
|
|
1
|
+
import { c as e, n as t, r as n } from "../tool-D-WiQSIl.js";
|
|
2
2
|
import { resolveTheme as r, weaselTheme as i } from "@weasel-js/theme";
|
|
3
3
|
import { useEffect as a, useMemo as o, useState as s } from "react";
|
|
4
4
|
import { useThemeOptional as c } from "@weasel-js/theme/react";
|
|
5
5
|
//#region src/react/useHud.ts
|
|
6
6
|
function l(t, l = {}) {
|
|
7
|
-
let [u] = s(() => e()), d = c(), f = o(() => d?.resolved ?? r(i
|
|
7
|
+
let [u] = s(() => e()), d = c(), f = o(() => d?.resolved ?? r(i), [d]), p = l.font;
|
|
8
8
|
return a(() => {
|
|
9
9
|
let e = t.current;
|
|
10
10
|
if (!e) return;
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/react/useHud.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react';\nimport { useThemeOptional } from '@weasel-js/theme/react';\nimport { resolveTheme, weaselTheme } from '@weasel-js/theme';\nimport { createHud, type Hud } from '../hud';\nimport { attachHud, type AttachHudOptions } from '../attach';\nimport type { CanvasExtensionApi, Contribution } from '@weasel-js/core';\nimport { createHudContribution } 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 *\n * An app that has already registered a bitmap family should say so —\n * `useHud(ref, { font: 'sans-serif' })` — or the HUD fetches its own copy of\n * the same atlas.\n */\nexport function useHud(\n canvasRef: { current: CanvasExtensionApi | null },\n options: Pick<AttachHudOptions, 'font'> = {},\n): Hud {\n const [hud] = useState(() => createHud());\n\n // Follow the app's theme when there is one. Widgets are drawn into the\n // canvas, so they can't inherit the cascade — handing them the resolved\n // record is what keeps HUD chrome in step with a mode switch.\n const provided = useThemeOptional();\n const theme = useMemo(\n () => provided?.resolved ?? resolveTheme(weaselTheme
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/react/useHud.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react';\nimport { useThemeOptional } from '@weasel-js/theme/react';\nimport { resolveTheme, weaselTheme } from '@weasel-js/theme';\nimport { createHud, type Hud } from '../hud';\nimport { attachHud, type AttachHudOptions } from '../attach';\nimport type { CanvasExtensionApi, Contribution } from '@weasel-js/core';\nimport { createHudContribution } 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 *\n * An app that has already registered a bitmap family should say so —\n * `useHud(ref, { font: 'sans-serif' })` — or the HUD fetches its own copy of\n * the same atlas.\n */\nexport function useHud(\n canvasRef: { current: CanvasExtensionApi | null },\n options: Pick<AttachHudOptions, 'font'> = {},\n): Hud {\n const [hud] = useState(() => createHud());\n\n // Follow the app's theme when there is one. Widgets are drawn into the\n // canvas, so they can't inherit the cascade — handing them the resolved\n // record is what keeps HUD chrome in step with a mode switch.\n const provided = useThemeOptional();\n const theme = useMemo(\n () => provided?.resolved ?? resolveTheme(weaselTheme),\n [provided],\n );\n\n const font = options.font;\n useEffect(() => {\n const api = canvasRef.current;\n if (!api) return;\n const detach = attachHud(api, hud, { theme, ...(font !== undefined ? { font } : {}) });\n api.requestRedraw();\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, theme, font]);\n\n return hud;\n}\n\n/**\n * Memoize the HUD's input contribution — see {@link createHudContribution}\n * for how the routing works.\n *\n * It 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 useHudContribution(): Contribution {\n return useMemo(() => createHudContribution(), []);\n}\n"],"mappings":";;;;;AAuBA,SAAgB,EACd,GACA,IAA0C,EAAE,EACvC;CACL,IAAM,CAAC,KAAO,QAAe,GAAW,CAAC,EAKnC,IAAW,GAAkB,EAC7B,IAAQ,QACN,GAAU,YAAY,EAAa,EAAY,EACrD,CAAC,EAAS,CACX,EAEK,IAAO,EAAQ;AAarB,QAZA,QAAgB;EACd,IAAM,IAAM,EAAU;AACtB,MAAI,CAAC,EAAK;EACV,IAAM,IAAS,EAAU,GAAK,GAAK;GAAE;GAAO,GAAI,MAAS,KAAA,IAAuB,EAAE,GAAb,EAAE,SAAM;GAAQ,CAAC;AAEtF,SADA,EAAI,eAAe,EACZ;IAKN;EAAC;EAAK;EAAO;EAAK,CAAC,EAEf;;AAUT,SAAgB,IAAmC;AACjD,QAAO,QAAc,GAAuB,EAAE,EAAE,CAAC"}
|
|
@@ -678,7 +678,7 @@ function T(e, t, n) {
|
|
|
678
678
|
//#endregion
|
|
679
679
|
//#region src/attach.ts
|
|
680
680
|
function E(e, t, i = {}) {
|
|
681
|
-
let a = i.theme ?? o(s
|
|
681
|
+
let a = i.theme ?? o(s);
|
|
682
682
|
if (t.attached) throw Error("weasel-hud: this HUD is already attached to a canvas.");
|
|
683
683
|
let c = i.font, l = typeof c == "string" ? c : x;
|
|
684
684
|
typeof c != "string" && S(c).then(() => e.requestRedraw()).catch((e) => {
|
|
@@ -996,4 +996,4 @@ function R() {
|
|
|
996
996
|
//#endregion
|
|
997
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 };
|
|
998
998
|
|
|
999
|
-
//# sourceMappingURL=tool-
|
|
999
|
+
//# sourceMappingURL=tool-D-WiQSIl.js.map
|