@weasel-js/hud 1.6.0 → 1.6.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.
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-C2amOWae.js";
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-DThNTu9f.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
@@ -133,7 +133,7 @@ function y(e) {
133
133
  },
134
134
  subscribeFrame: t.subscribeFrame
135
135
  }, P = t.subscribeFrame(() => {
136
- b = !0, !(!_ || m) && (_ = !1, A());
136
+ b = !0, _ && !m && (_ = !1, A());
137
137
  }), F = p({
138
138
  surface: N,
139
139
  ...e.mode ? { mode: e.mode } : {},
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/loupe/readback.ts","../src/loupe/createLoupe.ts"],"sourcesContent":["/**\n * Read a `rw × rh` device-pixel region of the drawing buffer centered on\n * `pointer`, returned top-down. `pointer` is in CSS px relative to `target`,\n * the rect of the buffer the canvas paints into (device px, top-left origin),\n * and the read is clamped to stay inside that rect.\n *\n * GL reports rows bottom-up; every consumer here wants top-down, so both the\n * read origin and the returned rows are flipped.\n */\nexport function readbackRegion(\n gl: WebGL2RenderingContext,\n bufferHeight: number,\n target: { x: number; y: number; width: number; height: number },\n pointer: { x: number; y: number },\n dpr: number,\n rw: number,\n rh: number,\n): ImageData {\n const cx = target.x + Math.round(pointer.x * dpr);\n const cy = target.y + Math.round(pointer.y * dpr);\n const gx = clamp(cx - Math.floor(rw / 2), target.x, target.x + Math.max(0, target.width - rw));\n const gyTop = clamp(cy - Math.floor(rh / 2), target.y, target.y + Math.max(0, target.height - rh));\n const gy = bufferHeight - gyTop - rh;\n\n const raw = new Uint8Array(rw * rh * 4);\n gl.readPixels(gx, gy, rw, rh, gl.RGBA, gl.UNSIGNED_BYTE, raw);\n\n const flipped = new Uint8ClampedArray(rw * rh * 4);\n const stride = rw * 4;\n for (let row = 0; row < rh; row++) {\n const src = (rh - 1 - row) * stride;\n flipped.set(raw.subarray(src, src + stride), row * stride);\n }\n return new ImageData(flipped, rw, rh);\n}\n\nfunction clamp(v: number, lo: number, hi: number): number {\n return v < lo ? lo : v > hi ? hi : v;\n}\n","import {\n createViewportLayer, screenToWorld, viewToTransform,\n type CanvasViewHandle, type RenderLayer, type SceneCanvasApi, type View,\n} from '@weasel-js/core';\nimport type { DrawCommand } from '@weasel-js/core/renderer';\nimport {\n createLoupeModel, loupeInnerView,\n type LoupeMode, type LoupeModel, type LoupeSurface,\n} from '@weasel-js/loupe';\nimport type { Hud } from '../hud';\nimport type { WindowWidget } from '../widgets/window/window';\nimport type { HudContentCtx, WidgetBounds } from '../widget';\nimport { readbackRegion } from './readback';\n\nexport type { LoupeMode };\n\n/** Options for `createLoupe` shared by a plain lens and an interactive one. */\nexport interface LoupeBaseOptions {\n hud: Hud;\n /** The canvas pixel mode reads back from. Supplies the GL context and the\n * drawing-buffer dimensions. */\n canvas: HTMLCanvasElement;\n /** Where the aim comes from: the element pointer events are taken from and\n * the rect client coords are measured against. Defaults to `canvas`, which\n * is right whenever the canvas is also the thing under the pointer. */\n input?: HTMLElement;\n /** The rect of `canvas` the magnified picture occupies, in its CSS px — the\n * one the aim is relative to. Pass `CanvasExtensionApi.getSurfaceRect` for\n * a pane painted into a shared canvas. Defaults to `views.getSurfaceRect`\n * when the lens is a view, and to the whole canvas otherwise. */\n region?: () => { x: number; y: number; width: number; height: number };\n requestRedraw: () => void;\n mode?: LoupeMode;\n factor?: number;\n bounds?: WidgetBounds;\n title?: string;\n /** Draw the window's titlebar and close box. Default `true`. Pass `false`\n * for a bare lens; the interior then doubles as the move handle. */\n titlebar?: boolean;\n /** Called with the hex color under the aim point whenever it changes.\n * Sampled from the framebuffer in both modes — vector content is a\n * re-render whose edge colors differ from the screen's, so reading the\n * color off it would report something the user cannot see. */\n onColorChange?: (hex: string) => void;\n /** Fired when a click inside the lens picks a color — an eyedropper on the\n * magnified surface. Where the color goes is the consumer's: the loupe\n * reports the pick and nothing else. An `interactive` lens gives its clicks\n * to the canvas, so only `pick()` reaches this. */\n onPick?: (hex: string) => void;\n /** Fired by the window's close box. The window does not hide itself —\n * whoever owns the loupe's visibility decides what closing means. */\n onClose?: () => void;\n /** Backdrop painted behind the magnified content in both modes, so the\n * outer canvas does not show through where the lens is empty. Defaults to\n * the theme's surface color. */\n background?: string;\n}\n\n/** Options for `createLoupe`. */\nexport type LoupeOptions = LoupeBaseOptions & (\n | {\n /** Layers re-rendered through the magnified inner view in vector mode. */\n source: RenderLayer<unknown>[];\n views?: undefined;\n interactive?: false;\n }\n | {\n /**\n * The canvas, as a host for views. The lens becomes a view on it: vector\n * mode paints the canvas's own stack — scene and selection chrome — and\n * the lens can take input. It magnifies the canvas's own camera; aimed\n * over another view, it shows the canvas's world, not that view's.\n */\n views: Pick<SceneCanvasApi, 'addView' | 'getSurfaceRect'>;\n /** Narrows what vector mode paints. Defaults to the canvas's stack. */\n source?: RenderLayer<unknown>[];\n /**\n * Route input inside the lens to what it shows: a press selects the node\n * magnified under the pointer, and a drag moves it by the pointer travel\n * divided by the magnification. Default `false` — the window keeps its\n * interior, and a click there picks a color.\n */\n interactive?: boolean;\n }\n);\n\n/** Where an interactive lens routes while its window is hidden: nowhere. */\nconst NO_RECT = { x: 0, y: 0, w: 0, h: 0 };\n\n/** Control surface for a live loupe: where it is aimed, how it magnifies,\n * what color it is over, and the window it lives in. */\nexport interface LoupeHandle {\n readonly window: WindowWidget;\n readonly mode: LoupeMode;\n readonly factor: number;\n /** Last aimed point, in screen-space CSS px relative to the canvas. */\n readonly aim: { x: number; y: number };\n /** Hex color under the aim point, read off the framebuffer on the first\n * frame to land after the aim. `null` until then, or when the GL context\n * is unavailable. */\n readonly color: string | null;\n setMode(mode: LoupeMode): void;\n setFactor(factor: number): void;\n /** Aim at a screen point. Ignored while the point is over the window —\n * that is the freeze rule that makes the borders reachable. */\n aimAt(p: { x: number; y: number }): void;\n /** Sample the color the lens is showing at `p` — a screen point inside the\n * lens — and report it to `onPick`. Omit `p` to pick at the aim point.\n * Returns the hex, or `null` when the framebuffer cannot answer for that\n * point, including before any frame has landed. Leaves the aim, and\n * `color`, alone. */\n pick(p?: { x: number; y: number }): string | null;\n dispose(): void;\n}\n\n/**\n * Build a magnifier: a HUD window whose interior shows the canvas around an\n * aim point, enlarged. Adds the window to the HUD and starts following the\n * pointer; `dispose` removes it again.\n */\nexport function createLoupe(opts: LoupeOptions): LoupeHandle {\n const { hud, canvas: element, requestRedraw } = opts;\n const host = opts.views;\n const interactive = host !== undefined && opts.interactive === true;\n const input = opts.input ?? element;\n let lens: CanvasViewHandle | null = null;\n // Set while a gesture that began over the window is held: the lens camera\n // follows the aim, so re-aiming mid-drag would move the world under it.\n let holding = false;\n let pixels: ImageBitmap | null = null;\n let pixelsPending = false;\n let refreshWanted = false;\n let disposed = false;\n // Until a paint lands, the context on a shared canvas may not exist yet, and\n // opening it here would give every tenant one with no stencil buffer.\n let landed = false;\n\n const b = opts.bounds ?? { x: 24, y: 24, w: 220, h: 200 };\n\n const content = (ctx: HudContentCtx): DrawCommand[] =>\n model.mode === 'vector' ? drawVector(ctx) : drawPixels(ctx);\n\n const backdropColor = (ctx: HudContentCtx): string =>\n opts.background ?? ctx.tokens['--wzl-surface'];\n\n const backdrop = (ctx: HudContentCtx): DrawCommand => ({\n kind: 'path',\n path: { kind: 'rect', x: ctx.rect.x, y: ctx.rect.y, width: ctx.rect.w, height: ctx.rect.h },\n fill: { fill: 'solid', color: backdropColor(ctx) },\n });\n\n const innerView = (outer: View, rect: WidgetBounds): View => {\n const world = screenToWorld(model.aim.x, model.aim.y, viewToTransform(outer));\n return loupeInnerView({ x: world[0], y: world[1] }, outer, rect, model.factor);\n };\n\n const drawVector = (ctx: HudContentCtx): DrawCommand[] => {\n if (host) return lens ? [backdrop(ctx), ...lens.draw(ctx.data, ctx.view, ctx.dims)] : [backdrop(ctx)];\n // A fresh lens per frame: CreateViewportLayerOpts.view is static, and the\n // inner view moves with the pointer.\n const picture = createViewportLayer<unknown>({\n id: `${win.id}:lens`,\n label: 'Loupe content',\n source: opts.source ?? [],\n view: innerView(ctx.view, ctx.rect),\n bounds: () => ctx.rect,\n background: backdropColor(ctx),\n });\n return picture.draw(ctx.data, ctx.view, ctx.dims);\n };\n\n const drawPixels = (ctx: HudContentCtx): DrawCommand[] => {\n // The backdrop paints even with a bitmap in hand: a readback of a\n // transparent framebuffer is transparent, and before the first one\n // settles there is nothing at all, either of which leaves the lens a\n // hole onto the unmagnified canvas.\n const out: DrawCommand[] = [backdrop(ctx)];\n if (pixels) {\n out.push({\n kind: 'image',\n image: pixels,\n x: ctx.rect.x, y: ctx.rect.y, w: ctx.rect.w, h: ctx.rect.h,\n sampling: 'nearest',\n });\n }\n return out;\n };\n\n // `gl.readPixels` outside a landed paint returns the *previous* frame, so an\n // aim only marks the lens dirty; the read itself happens in the frame\n // subscriber below, on the frame that painted.\n const scheduleRefresh = () => {\n if (disposed || model.mode !== 'pixel') return;\n refreshWanted = true;\n };\n\n /** Read device px of the loupe's region around `at`, sized for the\n * canvas's pixel ratio, or `null` when the framebuffer cannot answer. */\n const read = (\n at: { x: number; y: number },\n rw: (dpr: number) => number,\n rh: (dpr: number) => number,\n ): ImageData | null => {\n if (!landed) return null;\n const gl = element.getContext('webgl2');\n if (!gl) return null;\n const cssRect = element.getBoundingClientRect();\n if (cssRect.width === 0) return null;\n const dpr = element.width / cssRect.width;\n // A view-backed lens knows its canvas, so over a detached pane it reads\n // that pane's pixels without being told where the pane is.\n const r = (opts.region ?? host?.getSurfaceRect)?.();\n const target = r\n ? {\n x: Math.round(r.x * dpr), y: Math.round(r.y * dpr),\n width: Math.round(r.width * dpr), height: Math.round(r.height * dpr),\n }\n : { x: 0, y: 0, width: element.width, height: element.height };\n return readbackRegion(gl, element.height, target, at, dpr, rw(dpr), rh(dpr));\n };\n\n const refreshPixels = () => {\n if (disposed || model.mode !== 'pixel') return;\n const rect = win.contentRect;\n const data = read(\n model.aim,\n (dpr) => Math.max(1, Math.round((rect.w * dpr) / model.factor)),\n (dpr) => Math.max(1, Math.round((rect.h * dpr) / model.factor)),\n );\n if (!data) return;\n pixelsPending = true;\n createImageBitmap(data)\n .then((bmp) => {\n if (disposed) { bmp.close(); return; }\n pixels?.close();\n pixels = bmp;\n pixelsPending = false;\n requestRedraw();\n })\n .catch(() => {\n pixelsPending = false;\n requestRedraw();\n });\n };\n\n const readHex = (at: { x: number; y: number }): string | null => {\n const px = read(at, () => 1, () => 1);\n if (!px) return null;\n return '#' + [px.data[0], px.data[1], px.data[2]]\n .map((c) => c.toString(16).padStart(2, '0')).join('');\n };\n\n const win = hud.window({\n id: 'weasel-loupe',\n x: b.x, y: b.y, w: b.w, h: b.h,\n title: opts.title ?? 'Loupe',\n titlebar: opts.titlebar,\n content,\n interior: interactive ? 'pass' : 'claim',\n onResize: () => { scheduleRefresh(); },\n ...(interactive ? {} : { onContentClick: (p: { x: number; y: number }) => { model.pick(p); } }),\n ...(opts.onClose ? { onClose: opts.onClose } : {}),\n });\n\n const surface: LoupeSurface = {\n lens: () => win.contentRect,\n covers: (p) => win.hitTest(p.x, p.y) || (win.passes?.(p.x, p.y) ?? false),\n sample: readHex,\n hidden: () => win.hidden,\n gone: () => win.disposed === true,\n changed: () => { scheduleRefresh(); requestRedraw(); },\n subscribeFrame: hud.subscribeFrame,\n };\n\n // Subscribed ahead of the model, so the frame that lands first is already\n // readable by the time the model samples on it.\n const unsubscribeFrame = hud.subscribeFrame(() => {\n landed = true;\n // A refresh wanted while a bitmap is in flight is remembered rather than\n // dropped: the flag survives until a frame finds it settled, so the aim\n // the user ends a fast drag on is the one that gets read.\n if (!refreshWanted || pixelsPending) return;\n refreshWanted = false;\n refreshPixels();\n });\n\n const model: LoupeModel = createLoupeModel({\n surface,\n ...(opts.mode ? { mode: opts.mode } : {}),\n ...(opts.factor !== undefined ? { factor: opts.factor } : {}),\n ...(opts.onColorChange ? { onColorChange: opts.onColorChange } : {}),\n ...(opts.onPick ? { onPick: opts.onPick } : {}),\n onDispose: () => teardown(),\n });\n\n if (host) {\n lens = host.addView({\n id: `${win.id}:lens`,\n label: 'Loupe',\n bounds: () => (win.hidden ? NO_RECT : win.contentRect),\n view: (outer) => innerView(outer, win.contentRect),\n paint: false,\n interactive,\n ...(opts.source ? { layers: () => opts.source! } : {}),\n });\n }\n\n const local = (evt: PointerEvent): { x: number; y: number } => {\n const r = input.getBoundingClientRect();\n return { x: evt.clientX - r.left, y: evt.clientY - r.top };\n };\n\n const onPointerMove = (evt: PointerEvent) => {\n if (holding) return;\n model.aimAt(local(evt));\n };\n const onPointerDown = (evt: PointerEvent) => {\n if (interactive && surface.covers(local(evt))) holding = true;\n };\n const onPointerEnd = () => { holding = false; };\n const pointerEnds = ['pointerup', 'pointercancel', 'lostpointercapture'] as const;\n\n const teardown = () => {\n disposed = true;\n unsubscribeFrame();\n input.removeEventListener('pointermove', onPointerMove);\n input.removeEventListener('pointerdown', onPointerDown);\n for (const type of pointerEnds) input.removeEventListener(type, onPointerEnd);\n lens?.remove();\n lens = null;\n pixels?.close();\n pixels = null;\n };\n\n input.addEventListener('pointermove', onPointerMove);\n input.addEventListener('pointerdown', onPointerDown);\n for (const type of pointerEnds) input.addEventListener(type, onPointerEnd);\n\n return {\n window: win,\n get mode() { return model.mode; },\n get factor() { return model.factor; },\n get aim() { return model.aim; },\n get color() { return model.color; },\n setMode: model.setMode,\n setFactor: model.setFactor,\n aimAt: model.aimAt,\n pick: model.pick,\n dispose() {\n model.dispose();\n win.dispose();\n },\n };\n}\n"],"mappings":";;;;AASA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACA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sOf","createHud","DEFAULT_WIDGET_CLAIMS","DEFAULT_WINDOW_METRICS","createHudContribution","DEFAULT_FONT_FAMILY","attachHud","HUD_AFFORDANCE_KIND","cursorForZone","loupeInnerView$1","readbackRegion","cx","target","pointer","dpr","cy","gx","clamp","rw","gy","bufferHeight","rh","raw","gl","flipped","stride","row","src","v","lo","hi","NO_RECT","createLoupe","element","opts","host","interactive","input","lens","holding","pixels","pixelsPending","refreshWanted","disposed","landed","b","content","model","drawVector","ctx","drawPixels","backdropColor","backdrop","innerView","world","screenToWorld","viewToTransform","outer","rect","createViewportLayer","win","out","scheduleRefresh","read","cssRect","r","at","refreshPixels","data","bmp","requestRedraw","readHex","px","c","hud","p","surface","unsubscribeFrame","createLoupeModel","teardown","local","evt","onPointerMove","onPointerDown","onPointerEnd","pointerEnds","type","loupeInnerView","registerDefaultFont"],"sources":["../src/loupe/readback.ts","../src/loupe/createLoupe.ts"],"sourcesContent":["/**\n * Read a `rw × rh` device-pixel region of the drawing buffer centered on\n * `pointer`, returned top-down. `pointer` is in CSS px relative to `target`,\n * the rect of the buffer the canvas paints into (device px, top-left origin),\n * and the read is clamped to stay inside that rect.\n *\n * GL reports rows bottom-up; every consumer here wants top-down, so both the\n * read origin and the returned rows are flipped.\n */\nexport function readbackRegion(\n gl: WebGL2RenderingContext,\n bufferHeight: number,\n target: { x: number; y: number; width: number; height: number },\n pointer: { x: number; y: number },\n dpr: number,\n rw: number,\n rh: number,\n): ImageData {\n const cx = target.x + Math.round(pointer.x * dpr);\n const cy = target.y + Math.round(pointer.y * dpr);\n const gx = clamp(cx - Math.floor(rw / 2), target.x, target.x + Math.max(0, target.width - rw));\n const gyTop = clamp(cy - Math.floor(rh / 2), target.y, target.y + Math.max(0, target.height - rh));\n const gy = bufferHeight - gyTop - rh;\n\n const raw = new Uint8Array(rw * rh * 4);\n gl.readPixels(gx, gy, rw, rh, gl.RGBA, gl.UNSIGNED_BYTE, raw);\n\n const flipped = new Uint8ClampedArray(rw * rh * 4);\n const stride = rw * 4;\n for (let row = 0; row < rh; row++) {\n const src = (rh - 1 - row) * stride;\n flipped.set(raw.subarray(src, src + stride), row * stride);\n }\n return new ImageData(flipped, rw, rh);\n}\n\nfunction clamp(v: number, lo: number, hi: number): number {\n return v < lo ? lo : v > hi ? hi : v;\n}\n","import {\n createViewportLayer, screenToWorld, viewToTransform,\n type CanvasViewHandle, type RenderLayer, type SceneCanvasApi, type View,\n} from '@weasel-js/core';\nimport type { DrawCommand } from '@weasel-js/core/renderer';\nimport {\n createLoupeModel, loupeInnerView,\n type LoupeMode, type LoupeModel, type LoupeSurface,\n} from '@weasel-js/loupe';\nimport type { Hud } from '../hud';\nimport type { WindowWidget } from '../widgets/window/window';\nimport type { HudContentCtx, WidgetBounds } from '../widget';\nimport { readbackRegion } from './readback';\n\nexport type { LoupeMode };\n\n/** Options for `createLoupe` shared by a plain lens and an interactive one. */\nexport interface LoupeBaseOptions {\n hud: Hud;\n /** The canvas pixel mode reads back from. Supplies the GL context and the\n * drawing-buffer dimensions. */\n canvas: HTMLCanvasElement;\n /** Where the aim comes from: the element pointer events are taken from and\n * the rect client coords are measured against. Defaults to `canvas`, which\n * is right whenever the canvas is also the thing under the pointer. */\n input?: HTMLElement;\n /** The rect of `canvas` the magnified picture occupies, in its CSS px — the\n * one the aim is relative to. Pass `CanvasExtensionApi.getSurfaceRect` for\n * a pane painted into a shared canvas. Defaults to `views.getSurfaceRect`\n * when the lens is a view, and to the whole canvas otherwise. */\n region?: () => { x: number; y: number; width: number; height: number };\n requestRedraw: () => void;\n mode?: LoupeMode;\n factor?: number;\n bounds?: WidgetBounds;\n title?: string;\n /** Draw the window's titlebar and close box. Default `true`. Pass `false`\n * for a bare lens; the interior then doubles as the move handle. */\n titlebar?: boolean;\n /** Called with the hex color under the aim point whenever it changes.\n * Sampled from the framebuffer in both modes — vector content is a\n * re-render whose edge colors differ from the screen's, so reading the\n * color off it would report something the user cannot see. */\n onColorChange?: (hex: string) => void;\n /** Fired when a click inside the lens picks a color — an eyedropper on the\n * magnified surface. Where the color goes is the consumer's: the loupe\n * reports the pick and nothing else. An `interactive` lens gives its clicks\n * to the canvas, so only `pick()` reaches this. */\n onPick?: (hex: string) => void;\n /** Fired by the window's close box. The window does not hide itself —\n * whoever owns the loupe's visibility decides what closing means. */\n onClose?: () => void;\n /** Backdrop painted behind the magnified content in both modes, so the\n * outer canvas does not show through where the lens is empty. Defaults to\n * the theme's surface color. */\n background?: string;\n}\n\n/** Options for `createLoupe`. */\nexport type LoupeOptions = LoupeBaseOptions & (\n | {\n /** Layers re-rendered through the magnified inner view in vector mode. */\n source: RenderLayer<unknown>[];\n views?: undefined;\n interactive?: false;\n }\n | {\n /**\n * The canvas, as a host for views. The lens becomes a view on it: vector\n * mode paints the canvas's own stack — scene and selection chrome — and\n * the lens can take input. It magnifies the canvas's own camera; aimed\n * over another view, it shows the canvas's world, not that view's.\n */\n views: Pick<SceneCanvasApi, 'addView' | 'getSurfaceRect'>;\n /** Narrows what vector mode paints. Defaults to the canvas's stack. */\n source?: RenderLayer<unknown>[];\n /**\n * Route input inside the lens to what it shows: a press selects the node\n * magnified under the pointer, and a drag moves it by the pointer travel\n * divided by the magnification. Default `false` — the window keeps its\n * interior, and a click there picks a color.\n */\n interactive?: boolean;\n }\n);\n\n/** Where an interactive lens routes while its window is hidden: nowhere. */\nconst NO_RECT = { x: 0, y: 0, w: 0, h: 0 };\n\n/** Control surface for a live loupe: where it is aimed, how it magnifies,\n * what color it is over, and the window it lives in. */\nexport interface LoupeHandle {\n readonly window: WindowWidget;\n readonly mode: LoupeMode;\n readonly factor: number;\n /** Last aimed point, in screen-space CSS px relative to the canvas. */\n readonly aim: { x: number; y: number };\n /** Hex color under the aim point, read off the framebuffer on the first\n * frame to land after the aim. `null` until then, or when the GL context\n * is unavailable. */\n readonly color: string | null;\n setMode(mode: LoupeMode): void;\n setFactor(factor: number): void;\n /** Aim at a screen point. Ignored while the point is over the window —\n * that is the freeze rule that makes the borders reachable. */\n aimAt(p: { x: number; y: number }): void;\n /** Sample the color the lens is showing at `p` — a screen point inside the\n * lens — and report it to `onPick`. Omit `p` to pick at the aim point.\n * Returns the hex, or `null` when the framebuffer cannot answer for that\n * point, including before any frame has landed. Leaves the aim, and\n * `color`, alone. */\n pick(p?: { x: number; y: number }): string | null;\n dispose(): void;\n}\n\n/**\n * Build a magnifier: a HUD window whose interior shows the canvas around an\n * aim point, enlarged. Adds the window to the HUD and starts following the\n * pointer; `dispose` removes it again.\n */\nexport function createLoupe(opts: LoupeOptions): LoupeHandle {\n const { hud, canvas: element, requestRedraw } = opts;\n const host = opts.views;\n const interactive = host !== undefined && opts.interactive === true;\n const input = opts.input ?? element;\n let lens: CanvasViewHandle | null = null;\n // Set while a gesture that began over the window is held: the lens camera\n // follows the aim, so re-aiming mid-drag would move the world under it.\n let holding = false;\n let pixels: ImageBitmap | null = null;\n let pixelsPending = false;\n let refreshWanted = false;\n let disposed = false;\n // Until a paint lands, the context on a shared canvas may not exist yet, and\n // opening it here would give every tenant one with no stencil buffer.\n let landed = false;\n\n const b = opts.bounds ?? { x: 24, y: 24, w: 220, h: 200 };\n\n const content = (ctx: HudContentCtx): DrawCommand[] =>\n model.mode === 'vector' ? drawVector(ctx) : drawPixels(ctx);\n\n const backdropColor = (ctx: HudContentCtx): string =>\n opts.background ?? ctx.tokens['--wzl-surface'];\n\n const backdrop = (ctx: HudContentCtx): DrawCommand => ({\n kind: 'path',\n path: { kind: 'rect', x: ctx.rect.x, y: ctx.rect.y, width: ctx.rect.w, height: ctx.rect.h },\n fill: { fill: 'solid', color: backdropColor(ctx) },\n });\n\n const innerView = (outer: View, rect: WidgetBounds): View => {\n const world = screenToWorld(model.aim.x, model.aim.y, viewToTransform(outer));\n return loupeInnerView({ x: world[0], y: world[1] }, outer, rect, model.factor);\n };\n\n const drawVector = (ctx: HudContentCtx): DrawCommand[] => {\n if (host) return lens ? [backdrop(ctx), ...lens.draw(ctx.data, ctx.view, ctx.dims)] : [backdrop(ctx)];\n // A fresh lens per frame: CreateViewportLayerOpts.view is static, and the\n // inner view moves with the pointer.\n const picture = createViewportLayer<unknown>({\n id: `${win.id}:lens`,\n label: 'Loupe content',\n source: opts.source ?? [],\n view: innerView(ctx.view, ctx.rect),\n bounds: () => ctx.rect,\n background: backdropColor(ctx),\n });\n return picture.draw(ctx.data, ctx.view, ctx.dims);\n };\n\n const drawPixels = (ctx: HudContentCtx): DrawCommand[] => {\n // The backdrop paints even with a bitmap in hand: a readback of a\n // transparent framebuffer is transparent, and before the first one\n // settles there is nothing at all, either of which leaves the lens a\n // hole onto the unmagnified canvas.\n const out: DrawCommand[] = [backdrop(ctx)];\n if (pixels) {\n out.push({\n kind: 'image',\n image: pixels,\n x: ctx.rect.x, y: ctx.rect.y, w: ctx.rect.w, h: ctx.rect.h,\n sampling: 'nearest',\n });\n }\n return out;\n };\n\n // `gl.readPixels` outside a landed paint returns the *previous* frame, so an\n // aim only marks the lens dirty; the read itself happens in the frame\n // subscriber below, on the frame that painted.\n const scheduleRefresh = () => {\n if (disposed || model.mode !== 'pixel') return;\n refreshWanted = true;\n };\n\n /** Read device px of the loupe's region around `at`, sized for the\n * canvas's pixel ratio, or `null` when the framebuffer cannot answer. */\n const read = (\n at: { x: number; y: number },\n rw: (dpr: number) => number,\n rh: (dpr: number) => number,\n ): ImageData | null => {\n if (!landed) return null;\n const gl = element.getContext('webgl2');\n if (!gl) return null;\n const cssRect = element.getBoundingClientRect();\n if (cssRect.width === 0) return null;\n const dpr = element.width / cssRect.width;\n // A view-backed lens knows its canvas, so over a detached pane it reads\n // that pane's pixels without being told where the pane is.\n const r = (opts.region ?? host?.getSurfaceRect)?.();\n const target = r\n ? {\n x: Math.round(r.x * dpr), y: Math.round(r.y * dpr),\n width: Math.round(r.width * dpr), height: Math.round(r.height * dpr),\n }\n : { x: 0, y: 0, width: element.width, height: element.height };\n return readbackRegion(gl, element.height, target, at, dpr, rw(dpr), rh(dpr));\n };\n\n const refreshPixels = () => {\n if (disposed || model.mode !== 'pixel') return;\n const rect = win.contentRect;\n const data = read(\n model.aim,\n (dpr) => Math.max(1, Math.round((rect.w * dpr) / model.factor)),\n (dpr) => Math.max(1, Math.round((rect.h * dpr) / model.factor)),\n );\n if (!data) return;\n pixelsPending = true;\n createImageBitmap(data)\n .then((bmp) => {\n if (disposed) { bmp.close(); return; }\n pixels?.close();\n pixels = bmp;\n pixelsPending = false;\n requestRedraw();\n })\n .catch(() => {\n pixelsPending = false;\n requestRedraw();\n });\n };\n\n const readHex = (at: { x: number; y: number }): string | null => {\n const px = read(at, () => 1, () => 1);\n if (!px) return null;\n return '#' + [px.data[0], px.data[1], px.data[2]]\n .map((c) => c.toString(16).padStart(2, '0')).join('');\n };\n\n const win = hud.window({\n id: 'weasel-loupe',\n x: b.x, y: b.y, w: b.w, h: b.h,\n title: opts.title ?? 'Loupe',\n titlebar: opts.titlebar,\n content,\n interior: interactive ? 'pass' : 'claim',\n onResize: () => { scheduleRefresh(); },\n ...(interactive ? {} : { onContentClick: (p: { x: number; y: number }) => { model.pick(p); } }),\n ...(opts.onClose ? { onClose: opts.onClose } : {}),\n });\n\n const surface: LoupeSurface = {\n lens: () => win.contentRect,\n covers: (p) => win.hitTest(p.x, p.y) || (win.passes?.(p.x, p.y) ?? false),\n sample: readHex,\n hidden: () => win.hidden,\n gone: () => win.disposed === true,\n changed: () => { scheduleRefresh(); requestRedraw(); },\n subscribeFrame: hud.subscribeFrame,\n };\n\n // Subscribed ahead of the model, so the frame that lands first is already\n // readable by the time the model samples on it.\n const unsubscribeFrame = hud.subscribeFrame(() => {\n landed = true;\n // A refresh wanted while a bitmap is in flight is remembered rather than\n // dropped: the flag survives until a frame finds it settled, so the aim\n // the user ends a fast drag on is the one that gets read.\n if (!refreshWanted || pixelsPending) return;\n refreshWanted = false;\n refreshPixels();\n });\n\n const model: LoupeModel = createLoupeModel({\n surface,\n ...(opts.mode ? { mode: opts.mode } : {}),\n ...(opts.factor !== undefined ? { factor: opts.factor } : {}),\n ...(opts.onColorChange ? { onColorChange: opts.onColorChange } : {}),\n ...(opts.onPick ? { onPick: opts.onPick } : {}),\n onDispose: () => teardown(),\n });\n\n if (host) {\n lens = host.addView({\n id: `${win.id}:lens`,\n label: 'Loupe',\n bounds: () => (win.hidden ? NO_RECT : win.contentRect),\n view: (outer) => innerView(outer, win.contentRect),\n paint: false,\n interactive,\n ...(opts.source ? { layers: () => opts.source! } : {}),\n });\n }\n\n const local = (evt: PointerEvent): { x: number; y: number } => {\n const r = input.getBoundingClientRect();\n return { x: evt.clientX - r.left, y: evt.clientY - r.top };\n };\n\n const onPointerMove = (evt: PointerEvent) => {\n if (holding) return;\n model.aimAt(local(evt));\n };\n const onPointerDown = (evt: PointerEvent) => {\n if (interactive && surface.covers(local(evt))) holding = true;\n };\n const onPointerEnd = () => { holding = false; };\n const pointerEnds = ['pointerup', 'pointercancel', 'lostpointercapture'] as const;\n\n const teardown = () => {\n disposed = true;\n unsubscribeFrame();\n input.removeEventListener('pointermove', onPointerMove);\n input.removeEventListener('pointerdown', onPointerDown);\n for (const type of pointerEnds) input.removeEventListener(type, onPointerEnd);\n lens?.remove();\n lens = null;\n pixels?.close();\n pixels = null;\n };\n\n input.addEventListener('pointermove', onPointerMove);\n input.addEventListener('pointerdown', onPointerDown);\n for (const type of pointerEnds) input.addEventListener(type, onPointerEnd);\n\n return {\n window: win,\n get mode() { return model.mode; },\n get factor() { return model.factor; },\n get aim() { return model.aim; },\n get color() { return model.color; },\n setMode: model.setMode,\n setFactor: model.setFactor,\n aimAt: model.aimAt,\n pick: model.pick,\n dispose() {\n model.dispose();\n win.dispose();\n },\n };\n}\n"],"mappings":";;;;AASA,SAAgBW,EACd,GACA,GACA,GACA,GACA,GACA,GACA,GACW;CACX,IAAMC,IAAKC,EAAO,IAAI,KAAK,MAAMC,EAAQ,IAAIC,CAAG,GAC1CC,IAAKH,EAAO,IAAI,KAAK,MAAMC,EAAQ,IAAIC,CAAG,GAC1CE,IAAKC,EAAMN,IAAK,KAAK,MAAM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C,CAAa;CACnD,KAAK,IAAMG,KAAQD,GAAa,EAAM,iBAAiBC,GAAMF,CAAY;CAEzE,OAAO;EACL,QAAQxB;EACR,IAAI,OAAO;GAAE,OAAOb,EAAM;EAAM;EAChC,IAAI,SAAS;GAAE,OAAOA,EAAM;EAAQ;EACpC,IAAI,MAAM;GAAE,OAAOA,EAAM;EAAK;EAC9B,IAAI,QAAQ;GAAE,OAAOA,EAAM;EAAO;EAClC,SAASA,EAAM;EACf,WAAWA,EAAM;EACjB,OAAOA,EAAM;EACb,MAAMA,EAAM;EACZ,UAAU;GAER,AADAA,EAAM,QAAQ,GACda,EAAI,QAAQ;EACd;CACF;AACF"}
@@ -1,30 +1,30 @@
1
- import { c as e, n as t, r as n } from "../tool-C2amOWae.js";
1
+ import { c as e, n as t, r as n } from "../tool-DThNTu9f.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
- function l(t, l = {}) {
7
- let [u] = s(() => e()), d = c(), f = o(() => d?.resolved ?? r(i), [d]), p = l.font;
6
+ function l(t, r = {}) {
7
+ let [i] = s(() => e()), o = u(r.font);
8
8
  return a(() => {
9
- let e = t.current;
9
+ let e = t?.current;
10
10
  if (!e) return;
11
- let r = n(e, u, {
12
- theme: f,
13
- ...d ? { tones: d } : {},
14
- ...p === void 0 ? {} : { font: p }
15
- });
11
+ let r = n(e, i, o);
16
12
  return e.requestRedraw(), r;
17
- }, [
18
- u,
19
- f,
20
- d,
21
- p
22
- ]), u;
13
+ }, [i, o]), i;
23
14
  }
24
- function u() {
25
- return o(() => t(), []);
15
+ function u(e) {
16
+ let t = c();
17
+ return o(() => ({
18
+ theme: t?.resolved ?? r(i),
19
+ ...t ? { tones: t } : {},
20
+ ...e === void 0 ? {} : { font: e }
21
+ }), [t, e]);
22
+ }
23
+ function d(e, n = {}) {
24
+ let r = u(n.font);
25
+ return o(() => t(e, r), [e, r]);
26
26
  }
27
27
  //#endregion
28
- export { l as useHud, u as useHudContribution };
28
+ export { l as useHud, d as useHudContribution };
29
29
 
30
30
  //# sourceMappingURL=index.js.map
@@ -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),\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, {\n theme,\n ...(provided ? { tones: provided } : {}),\n ...(font !== undefined ? { font } : {}),\n });\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, provided, 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;AAiBrB,QAhBA,QAAgB;EACd,IAAM,IAAM,EAAU;AACtB,MAAI,CAAC,EAAK;EACV,IAAM,IAAS,EAAU,GAAK,GAAK;GACjC;GACA,GAAI,IAAW,EAAE,OAAO,GAAU,GAAG,EAAE;GACvC,GAAI,MAAS,KAAA,IAAuB,EAAE,GAAb,EAAE,SAAM;GAClC,CAAC;AAEF,SADA,EAAI,eAAe,EACZ;IAKN;EAAC;EAAK;EAAO;EAAU;EAAK,CAAC,EAEzB;;AAUT,SAAgB,IAAmC;AACjD,QAAO,QAAc,GAAuB,EAAE,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","names":["createHud","createHudContribution","attachHud","useHud","hud","useState","attachOptions","useAttachOptions","options","useEffect","api","canvasRef","detach","provided","useThemeOptional","useMemo","resolveTheme","weaselTheme","font","useHudContribution"],"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, SurfaceContribution } from '@weasel-js/core';\nimport { createHudContribution } from '../tool';\n\n/**\n * Create a HUD, and — given the canvas's ref handle — attach it to that\n * canvas. Returns the Hud immediately (unbound); attaches in an effect after\n * the canvas ref populates. Cleans up on unmount.\n *\n * Omit the ref when the HUD installs through {@link useHudContribution}\n * instead, which attaches it as part of the canvas's `ambient` entry.\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 const attachOptions = useAttachOptions(options.font);\n\n useEffect(() => {\n const api = canvasRef?.current;\n if (!api) return;\n const detach = attachHud(api, hud, attachOptions);\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, attachOptions]);\n\n return hud;\n}\n\n/** The attach options that follow the app's theme. 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. */\nfunction useAttachOptions(font: AttachHudOptions['font']): AttachHudOptions {\n const provided = useThemeOptional();\n return useMemo(() => ({\n theme: provided?.resolved ?? resolveTheme(weaselTheme),\n ...(provided ? { tones: provided } : {}),\n ...(font !== undefined ? { font } : {}),\n }), [provided, font]);\n}\n\n/**\n * The HUD's canvas entry — see {@link createHudContribution} for how the\n * routing works. Given a HUD, the entry also attaches it, so one `ambient`\n * entry installs the whole HUD:\n *\n * ```tsx\n * const hud = useHud();\n * const hudEntry = useHudContribution(hud, { font: 'sans-serif' });\n * <SceneCanvas ambient={[hudEntry]} … />\n * ```\n *\n * Without one it is input routing only, stateless (its actions resolve the hit\n * widget from the gesture's affordance payload), and one instance serves any\n * number of HUDs attached some other way.\n */\nexport function useHudContribution(\n hud?: Hud,\n options: Pick<AttachHudOptions, 'font'> = {},\n): SurfaceContribution {\n const attachOptions = useAttachOptions(options.font);\n return useMemo(\n () => createHudContribution(hud, attachOptions),\n [hud, attachOptions],\n );\n}\n"],"mappings":";;;;;AAoBA,SAAgBG,EACd,GACA,IAA0C,CAAC,GACtC;CACL,IAAM,CAACC,KAAOC,QAAeL,EAAU,CAAC,GAClCM,IAAgBC,EAAiBC,EAAQ,IAAI;CAcnD,OAZAC,QAAgB;EACd,IAAMC,IAAMC,GAAW;EACvB,IAAI,CAACD,GAAK;EACV,IAAME,IAASV,EAAUQ,GAAKN,GAAKE,CAAa;EAEhD,OADAI,EAAI,cAAc,GACXE;CAKT,GAAG,CAACR,GAAKE,CAAa,CAAC,GAEhBF;AACT;AAKA,SAASG,EAAiB,GAAkD;CAC1E,IAAMM,IAAWC,EAAiB;CAClC,OAAOC,SAAe;EACpB,OAAOF,GAAU,YAAYG,EAAaC,CAAW;EACrD,GAAIJ,IAAW,EAAE,OAAOA,EAAS,IAAI,CAAC;EACtC,GAAIK,MAAS,KAAA,IAAuB,CAAC,IAAZ,EAAE,QAAK;CAClC,IAAI,CAACL,GAAUK,CAAI,CAAC;AACtB;AAiBA,SAAgBC,EACd,GACA,IAA0C,CAAC,GACtB;CACrB,IAAMb,IAAgBC,EAAiBC,EAAQ,IAAI;CACnD,OAAOO,QACCd,EAAsBG,GAAKE,CAAa,GAC9C,CAACF,GAAKE,CAAa,CACrB;AACF"}
@@ -1,30 +1,35 @@
1
1
  import { type Hud } from '../hud';
2
2
  import { type AttachHudOptions } from '../attach';
3
- import type { CanvasExtensionApi, Contribution } from '@weasel-js/core';
3
+ import type { CanvasExtensionApi, SurfaceContribution } from '@weasel-js/core';
4
4
  /**
5
- * Create a HUD and attach it to a Canvas via its imperative ref handle.
6
- * Returns the Hud immediately (unbound); attaches in an effect after the
7
- * canvas ref populates. Cleans up on unmount.
5
+ * Create a HUD, and — given the canvas's ref handle — attach it to that
6
+ * canvas. Returns the Hud immediately (unbound); attaches in an effect after
7
+ * the canvas ref populates. Cleans up on unmount.
8
8
  *
9
- * Usage:
10
- * const ref = useRef<CanvasExtensionApi>(null);
11
- * const hud = useHud(ref);
12
- * // ... later
13
- * const btn = hud.button({ ... });
9
+ * Omit the ref when the HUD installs through {@link useHudContribution}
10
+ * instead, which attaches it as part of the canvas's `ambient` entry.
14
11
  *
15
12
  * An app that has already registered a bitmap family should say so —
16
13
  * `useHud(ref, { font: 'sans-serif' })` — or the HUD fetches its own copy of
17
14
  * the same atlas.
18
15
  */
19
- export declare function useHud(canvasRef: {
16
+ export declare function useHud(canvasRef?: {
20
17
  current: CanvasExtensionApi | null;
21
18
  }, options?: Pick<AttachHudOptions, 'font'>): Hud;
22
19
  /**
23
- * Memoize the HUD's input contribution — see {@link createHudContribution}
24
- * for how the routing works.
20
+ * The HUD's canvas entry — see {@link createHudContribution} for how the
21
+ * routing works. Given a HUD, the entry also attaches it, so one `ambient`
22
+ * entry installs the whole HUD:
25
23
  *
26
- * It is stateless (its actions resolve the hit widget from the gesture's
27
- * affordance payload), so one instance serves any number of HUDs on the page.
24
+ * ```tsx
25
+ * const hud = useHud();
26
+ * const hudEntry = useHudContribution(hud, { font: 'sans-serif' });
27
+ * <SceneCanvas ambient={[hudEntry]} … />
28
+ * ```
29
+ *
30
+ * Without one it is input routing only, stateless (its actions resolve the hit
31
+ * widget from the gesture's affordance payload), and one instance serves any
32
+ * number of HUDs attached some other way.
28
33
  */
29
- export declare function useHudContribution(): Contribution;
34
+ export declare function useHudContribution(hud?: Hud, options?: Pick<AttachHudOptions, 'font'>): SurfaceContribution;
30
35
  //# sourceMappingURL=useHud.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useHud.d.ts","sourceRoot":"","sources":["../../src/react/useHud.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGxE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CACpB,SAAS,EAAE;IAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAAA;CAAE,EACjD,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAM,GAC3C,GAAG,CA8BL;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAEjD"}
1
+ {"version":3,"file":"useHud.d.ts","sourceRoot":"","sources":["../../src/react/useHud.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG/E;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CACpB,SAAS,CAAC,EAAE;IAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAAA;CAAE,EAClD,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAM,GAC3C,GAAG,CAiBL;AAcD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,CAAC,EAAE,GAAG,EACT,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAM,GAC3C,mBAAmB,CAMrB"}
@@ -52,7 +52,7 @@ function m(e) {
52
52
  }];
53
53
  },
54
54
  hitTest(e, t) {
55
- return r ? !1 : e >= n.x && e < n.x + n.w && t >= n.y && t < n.y + n.h;
55
+ return !r && e >= n.x && e < n.x + n.w && t >= n.y && t < n.y + n.h;
56
56
  },
57
57
  claims: [],
58
58
  onPointer(e) {},
@@ -169,7 +169,7 @@ function g(e) {
169
169
  }];
170
170
  },
171
171
  hitTest(e, t) {
172
- return i ? !1 : e >= n.x && e < n.x + n.w && t >= n.y && t < n.y + n.h;
172
+ return !i && e >= n.x && e < n.x + n.w && t >= n.y && t < n.y + n.h;
173
173
  },
174
174
  claims: [],
175
175
  onPointer(e) {},
@@ -263,7 +263,7 @@ function v(e) {
263
263
  })];
264
264
  },
265
265
  hitTest(e, t) {
266
- return i ? !1 : d(e, t);
266
+ return !i && d(e, t);
267
267
  },
268
268
  cursorAt(t, n) {
269
269
  return i || !d(t, n) ? "default" : e.cursor ?? "pointer";
@@ -287,10 +287,7 @@ function v(e) {
287
287
  case "hovermove":
288
288
  s || (s = !0, u("hover"), e.onChange?.());
289
289
  break;
290
- case "hoverleave":
291
- s && (s = !1, u("leave"), e.onChange?.());
292
- break;
293
- default: break;
290
+ case "hoverleave": s && (s = !1, u("leave"), e.onChange?.());
294
291
  }
295
292
  },
296
293
  dispose() {
@@ -490,7 +487,7 @@ function D(e) {
490
487
  });
491
488
  let S = Number.parseFloat(m["border-width"]) || 0;
492
489
  if (S > 0) {
493
- let e = o(m["border-style"] === "dashed" || m["border-style"] === "dotted" ? m["border-style"] : "solid", S), t = {
490
+ let e = m["border-style"] === "dashed" || m["border-style"] === "dotted" ? m["border-style"] : "solid", t = o(e, S), n = {
494
491
  kind: "path",
495
492
  path: {
496
493
  kind: "rect",
@@ -505,10 +502,10 @@ function D(e) {
505
502
  color: m["border-color"]
506
503
  },
507
504
  width: S,
508
- ...e ? { dash: e } : {}
505
+ ...t ? { dash: t } : {}
509
506
  }
510
507
  };
511
- d.push(t);
508
+ d.push(n);
512
509
  }
513
510
  if (!r) return d;
514
511
  d.push(n(i + c.edge + 2, a, [{
@@ -564,10 +561,7 @@ function D(e) {
564
561
  y: t.y
565
562
  }), k = null, M = null;
566
563
  break;
567
- case "cancel":
568
- k && (O = A, k = null, e.onChange?.()), M = null;
569
- break;
570
- default: break;
564
+ case "cancel": k && (O = A, k = null, e.onChange?.()), M = null;
571
565
  }
572
566
  },
573
567
  dispose() {
@@ -581,7 +575,7 @@ function O() {
581
575
  let e = [], t = null, n = !1, r = /* @__PURE__ */ new Set(), i = null, a = () => {
582
576
  t?.requestRedraw();
583
577
  }, o = () => {
584
- i || !t || r.size === 0 || (i = t.subscribeFrame(() => {
578
+ !i && t && r.size !== 0 && (i = t.subscribeFrame(() => {
585
579
  for (let e of [...r]) e();
586
580
  }));
587
581
  }, s = (t) => () => {
@@ -764,25 +758,25 @@ function P(e, t, n = {}) {
764
758
  return o;
765
759
  },
766
760
  hitTest: (e, t, n, a, o) => {
767
- let [s, c] = i(e, t, r(a)), l = h(s, c);
768
- if (!l) return null;
769
- let u = N(l, s, c);
761
+ let s = r(a), [c, l] = i(e, t, s), u = h(c, l);
762
+ if (!u) return null;
763
+ let d = N(u, c, l);
770
764
  return {
771
- initialScratch: { widget: l },
765
+ initialScratch: { widget: u },
772
766
  strength: "exclusive",
773
- claimedKinds: M(l),
774
- ...u === void 0 ? {} : { cursor: u }
767
+ claimedKinds: M(u),
768
+ ...d === void 0 ? {} : { cursor: d }
775
769
  };
776
770
  },
777
771
  onUncapturedMove: (t, n, a, o) => {
778
- let [s, c] = i(t, n, r(o)), l = h(s, c);
779
- l !== m && (m && m.onPointer({
772
+ let s = r(o), [c, l] = i(t, n, s), u = h(c, l);
773
+ u !== m && (m && m.onPointer({
780
774
  type: "hoverleave",
781
775
  native: a
782
- }), m = l, e.requestRedraw()), l && l.onPointer({
776
+ }), m = u, e.requestRedraw()), u && u.onPointer({
783
777
  type: "hovermove",
784
- x: s,
785
- y: c,
778
+ x: c,
779
+ y: l,
786
780
  native: a
787
781
  });
788
782
  },
@@ -942,7 +936,7 @@ function G() {
942
936
  timing: "immediate",
943
937
  run: (e, t) => {
944
938
  let n = t, r = R(n?.affordance);
945
- !r || n?.clientX === void 0 || n.clientY === void 0 || r.onPointer({
939
+ r && n?.clientX !== void 0 && n.clientY !== void 0 && r.onPointer({
946
940
  type: "wheel",
947
941
  x: n.clientX,
948
942
  y: n.clientY,
@@ -954,9 +948,13 @@ function G() {
954
948
  }
955
949
  };
956
950
  }
957
- function K() {
951
+ function K(e, t) {
958
952
  return {
959
953
  id: "weasel-hud",
954
+ ...e ? { attach: (n) => {
955
+ let r = P(n, e, t);
956
+ return n.requestRedraw(), r;
957
+ } } : {},
960
958
  eligibility: { claimed: !0 },
961
959
  actions: [
962
960
  V(),
@@ -1030,4 +1028,4 @@ function K() {
1030
1028
  //#endregion
1031
1029
  export { M as a, O as c, j as i, y as l, K as n, k as o, P as r, A as s, F as t, C as u };
1032
1030
 
1033
- //# sourceMappingURL=tool-C2amOWae.js.map
1031
+ //# sourceMappingURL=tool-DThNTu9f.js.map