@weasel-js/hud 1.9.3 → 1.10.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/README.md +1 -1
- package/dist/attach.d.ts +7 -10
- package/dist/attach.d.ts.map +1 -1
- package/dist/colors.d.ts +9 -0
- package/dist/colors.d.ts.map +1 -0
- package/dist/hud.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +136 -104
- package/dist/index.js.map +1 -1
- package/dist/loupe/contentWatch.d.ts +16 -0
- package/dist/loupe/contentWatch.d.ts.map +1 -0
- package/dist/loupe/createLoupe.d.ts +11 -1
- package/dist/loupe/createLoupe.d.ts.map +1 -1
- package/dist/loupe/pointerAim.d.ts +15 -0
- package/dist/loupe/pointerAim.d.ts.map +1 -0
- package/dist/loupe/readback.d.ts.map +1 -1
- package/dist/react/index.js +18 -7
- package/dist/react/index.js.map +1 -1
- package/dist/react/useHud.d.ts.map +1 -1
- package/dist/{tool-DdwuyuMK.js → tool-Dq_D9qpD.js} +391 -377
- package/dist/tool-Dq_D9qpD.js.map +1 -0
- package/dist/tool.d.ts +0 -3
- package/dist/tool.d.ts.map +1 -1
- package/dist/widget.d.ts +10 -11
- package/dist/widget.d.ts.map +1 -1
- package/dist/widgets/image.d.ts +6 -0
- package/dist/widgets/image.d.ts.map +1 -1
- package/dist/widgets/rect.d.ts +6 -0
- package/dist/widgets/rect.d.ts.map +1 -1
- package/dist/widgets/window/window.d.ts +4 -3
- package/dist/widgets/window/window.d.ts.map +1 -1
- package/package.json +8 -7
- package/dist/tool-DdwuyuMK.js.map +0 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ import { /* … */ } from '@weasel-js/hud/react';
|
|
|
24
24
|
`rect`, `text`, `image`, `label`, `button`, and `window` — a draggable,
|
|
25
25
|
resizable frame whose interior is painted by an opt-in `content` callback. See
|
|
26
26
|
[`src/widgets/window`](src/widgets/window/README.md) for how content composes
|
|
27
|
-
with the frame, and `createLoupe` in [`src/loupe`](src/loupe) for
|
|
27
|
+
with the frame, and `createLoupe` in [`src/loupe`](src/loupe/createLoupe.ts) for a
|
|
28
28
|
consumer.
|
|
29
29
|
|
|
30
30
|
Widgets draw from a data-free context (`{ dims, defaultFont, tokens }`), which
|
package/dist/attach.d.ts
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import type { Hud } from './hud';
|
|
2
2
|
import type { CanvasExtensionApi } from '@weasel-js/core';
|
|
3
3
|
import { type FontAtlasUrls } from './fonts/registerDefaultFont';
|
|
4
|
-
import { type
|
|
4
|
+
import { type ColorSourceContext, type ResolvedTheme } from '@weasel-js/theme';
|
|
5
|
+
/** Options for `attachHud`. */
|
|
5
6
|
export interface AttachHudOptions {
|
|
6
7
|
/** Resolved theme the widgets draw with. Defaults to the built-in theme's
|
|
7
8
|
* default mode; pass `useTheme().resolved` to follow a live theme. */
|
|
8
9
|
readonly theme?: ResolvedTheme;
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* theme
|
|
12
|
-
readonly tones?:
|
|
13
|
-
readonly tones: ColorList;
|
|
14
|
-
};
|
|
10
|
+
/** What a widget's color sources resolve against: a theme, the tone list a
|
|
11
|
+
* numeric `tone` indexes, and a palette — `useTheme()`'s value is one.
|
|
12
|
+
* Defaults to the built-in theme and its list, resolved against `theme`. */
|
|
13
|
+
readonly tones?: ColorSourceContext;
|
|
15
14
|
/**
|
|
16
15
|
* Where the text a widget draws without naming a family comes from.
|
|
17
16
|
*
|
|
18
17
|
* - A family name: that family, already registered by the host. The HUD
|
|
19
|
-
* fetches nothing
|
|
20
|
-
* as `'sans-serif'` was downloading the HUD's byte-identical copy of it a
|
|
21
|
-
* second time.
|
|
18
|
+
* fetches nothing.
|
|
22
19
|
* - A `{ metricsUrl, atlasUrl }` pair: the HUD's own family, registered from
|
|
23
20
|
* the host's copy of the atlas rather than the bundled one.
|
|
24
21
|
*
|
package/dist/attach.d.ts.map
CHANGED
|
@@ -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,EAA+B,MAAM,iBAAiB,CAAC;AAIvF,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,6BAA6B,CAAC;AAMrC,OAAO,
|
|
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,EAA+B,MAAM,iBAAiB,CAAC;AAIvF,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,6BAA6B,CAAC;AAMrC,OAAO,EAA6B,KAAK,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAG1G,+BAA+B;AAC/B,MAAM,WAAW,gBAAgB;IAC/B;2EACuE;IACvE,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IAC/B;;iFAE6E;IAC7E,QAAQ,CAAC,KAAK,CAAC,EAAE,kBAAkB,CAAC;IACpC;;;;;;;;;OASG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC;CACxC;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,kBAAkB,EACvB,GAAG,EAAE,GAAG,EACR,OAAO,GAAE,gBAAqB,GAC7B,MAAM,IAAI,CA6JZ"}
|
package/dist/colors.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ColorSource } from '@weasel-js/paint';
|
|
2
|
+
import { type ColorSourceContext } from '@weasel-js/theme';
|
|
3
|
+
/**
|
|
4
|
+
* What a draw context's `color` is built from: a source resolved against
|
|
5
|
+
* `ctx` to a hex a canvas can draw. `undefined` for a source nothing answers,
|
|
6
|
+
* and for a custom property only a cascade could resolve.
|
|
7
|
+
*/
|
|
8
|
+
export declare function hudColor(ctx: ColorSourceContext): (source: ColorSource) => string | undefined;
|
|
9
|
+
//# sourceMappingURL=colors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE/E;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,kBAAkB,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK,MAAM,GAAG,SAAS,CAK7F"}
|
package/dist/hud.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hud.d.ts","sourceRoot":"","sources":["../src/hud.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hud.d.ts","sourceRoot":"","sources":["../src/hud.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAc,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAc,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAe,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAe,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAgB,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAgB,KAAK,aAAa,EA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;IAC9E,IAAI,CAAC,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC;IACpC,gFAAgF;IAChF,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,WAAW,CAAC;IACvC,+EAA+E;IAC/E,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,WAAW,CAAC;IACvC,gFAAgF;IAChF,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;IAC1C,gFAAgF;IAChF,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;CAC3C;AAED,oCAAoC;AACpC,wBAAgB,SAAS,IAAI,GAAG,CA2L/B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createHud, type Hud, type HudFocusOptions } from './hud';
|
|
2
|
-
export { attachHud } from './attach';
|
|
2
|
+
export { attachHud, type AttachHudOptions } from './attach';
|
|
3
3
|
export { createHudContribution, HUD_AFFORDANCE_KIND, type HudHitPayload } from './tool';
|
|
4
4
|
export type { Widget, WidgetBounds, HudDrawCtx, HudPointerEvent, HudKeyEvent, } from './widget';
|
|
5
5
|
export { DEFAULT_WIDGET_CLAIMS, claimsOf, isFocusable } from './widget';
|
|
@@ -8,13 +8,13 @@ export { DEFAULT_FONT_FAMILY, registerDefaultFont } from './fonts/registerDefaul
|
|
|
8
8
|
export type { FontAtlasUrls } from './fonts/registerDefaultFont';
|
|
9
9
|
export type { RectOptions, RectWidget } from './widgets/rect';
|
|
10
10
|
export type { TextOptions, TextWidget } from './widgets/text';
|
|
11
|
-
export type { ImageOptions, ImageWidget } from './widgets/image';
|
|
11
|
+
export type { ImageOptions, ImageWidget, SourceRect } from './widgets/image';
|
|
12
12
|
export type { LabelOptions, LabelWidget } from './widgets/label';
|
|
13
13
|
export type { ButtonOptions, ButtonWidget, ButtonEvent, ButtonHandler } from './widgets/button';
|
|
14
14
|
export type { WindowOptions, WindowWidget } from './widgets/window/window';
|
|
15
15
|
export { DEFAULT_WINDOW_METRICS, cursorForZone, type WindowZone, type WindowMetrics, } from './widgets/window/zones';
|
|
16
16
|
export type { HudContentCtx } from './widget';
|
|
17
|
-
export { createLoupe, type LoupeOptions, type LoupeHandle, type LoupeMode } from './loupe/createLoupe';
|
|
17
|
+
export { createLoupe, type LoupeOptions, type LoupeBaseOptions, type LoupeHandle, type LoupeMode } from './loupe/createLoupe';
|
|
18
18
|
export { loupeInnerView } from '@weasel-js/loupe';
|
|
19
19
|
export type { ResolvedTheme } from '@weasel-js/theme';
|
|
20
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,GAAG,EAAE,KAAK,eAAe,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,GAAG,EAAE,KAAK,eAAe,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,KAAK,aAAa,EAAE,MAAM,QAAQ,CAAC;AACxF,YAAY,EACV,MAAM,EACN,YAAY,EACZ,UAAU,EACV,eAAe,EACf,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACxE,YAAY,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACvF,YAAY,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC9D,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC9D,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7E,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACjE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChG,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EACL,sBAAsB,EAAE,aAAa,EACrC,KAAK,UAAU,EAAE,KAAK,aAAa,GACpC,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC9H,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,56 @@
|
|
|
1
|
-
import { a as e, c as t, d as n, i as r, l as i, n as a, o, r as s, s as c, t as l, u } from "./tool-
|
|
1
|
+
import { a as e, c as t, d as n, i as r, l as i, n as a, o, r as s, s as c, t as l, u } from "./tool-Dq_D9qpD.js";
|
|
2
2
|
import { createViewportLayer as d, screenToWorld as f, viewToTransform as p } from "@weasel-js/core";
|
|
3
|
-
import {
|
|
3
|
+
import { clamp as m } from "@weasel-js/geom";
|
|
4
|
+
import { releaseImageSource as h } from "@weasel-js/core/renderer";
|
|
5
|
+
import { createLoupeModel as g, loupeInnerView as _, loupeInnerView as v } from "@weasel-js/loupe";
|
|
6
|
+
//#region src/loupe/contentWatch.ts
|
|
7
|
+
function y(e) {
|
|
8
|
+
let t = "", n = null;
|
|
9
|
+
return {
|
|
10
|
+
drew(e) {
|
|
11
|
+
t = `${e.x},${e.y},${e.scale.x},${e.scale.y}`;
|
|
12
|
+
},
|
|
13
|
+
changed() {
|
|
14
|
+
let r = {
|
|
15
|
+
version: e?.(),
|
|
16
|
+
camera: t
|
|
17
|
+
}, i = n !== null && (n.version !== r.version || n.camera !== r.camera);
|
|
18
|
+
return n = r, i;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/loupe/pointerAim.ts
|
|
24
|
+
var b = [
|
|
25
|
+
"pointerup",
|
|
26
|
+
"pointercancel",
|
|
27
|
+
"lostpointercapture"
|
|
28
|
+
];
|
|
29
|
+
function x(e, t) {
|
|
30
|
+
let n = !1, r = (t) => {
|
|
31
|
+
let n = e.getBoundingClientRect();
|
|
32
|
+
return {
|
|
33
|
+
x: t.clientX - n.left,
|
|
34
|
+
y: t.clientY - n.top
|
|
35
|
+
};
|
|
36
|
+
}, i = (e) => {
|
|
37
|
+
n || t.aimAt(r(e));
|
|
38
|
+
}, a = (e) => {
|
|
39
|
+
t.holds(r(e)) && (n = !0);
|
|
40
|
+
}, o = () => {
|
|
41
|
+
n = !1;
|
|
42
|
+
};
|
|
43
|
+
e.addEventListener("pointermove", i), e.addEventListener("pointerdown", a);
|
|
44
|
+
for (let t of b) e.addEventListener(t, o);
|
|
45
|
+
return () => {
|
|
46
|
+
e.removeEventListener("pointermove", i), e.removeEventListener("pointerdown", a);
|
|
47
|
+
for (let t of b) e.removeEventListener(t, o);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
4
51
|
//#region src/loupe/readback.ts
|
|
5
|
-
function
|
|
6
|
-
let s = n.x + Math.round(r.x * i), c = n.y + Math.round(r.y * i), l =
|
|
52
|
+
function S(e, t, n, r, i, a, o) {
|
|
53
|
+
let s = n.x + Math.round(r.x * i), c = n.y + Math.round(r.y * i), l = m(s - Math.floor(a / 2), n.x, n.x + Math.max(0, n.width - a)), u = t - m(c - Math.floor(o / 2), n.y, n.y + Math.max(0, n.height - o)) - o, d = new Uint8Array(a * o * 4);
|
|
7
54
|
e.readPixels(l, u, a, o, e.RGBA, e.UNSIGNED_BYTE, d);
|
|
8
55
|
let f = new Uint8ClampedArray(a * o * 4), p = a * 4;
|
|
9
56
|
for (let e = 0; e < o; e++) {
|
|
@@ -12,63 +59,62 @@ function _(e, t, n, r, i, a, o) {
|
|
|
12
59
|
}
|
|
13
60
|
return new ImageData(f, a, o);
|
|
14
61
|
}
|
|
15
|
-
function v(e, t, n) {
|
|
16
|
-
return e < t ? t : e > n ? n : e;
|
|
17
|
-
}
|
|
18
62
|
//#endregion
|
|
19
63
|
//#region src/loupe/createLoupe.ts
|
|
20
|
-
var
|
|
64
|
+
var C = (e, t) => ({
|
|
65
|
+
kind: "path",
|
|
66
|
+
path: {
|
|
67
|
+
kind: "rect",
|
|
68
|
+
x: e.rect.x,
|
|
69
|
+
y: e.rect.y,
|
|
70
|
+
width: e.rect.w,
|
|
71
|
+
height: e.rect.h
|
|
72
|
+
},
|
|
73
|
+
fill: { paint: {
|
|
74
|
+
kind: "solid",
|
|
75
|
+
color: t
|
|
76
|
+
} }
|
|
77
|
+
}), w = {
|
|
21
78
|
x: 0,
|
|
22
79
|
y: 0,
|
|
23
80
|
w: 0,
|
|
24
81
|
h: 0
|
|
25
82
|
};
|
|
26
|
-
function
|
|
27
|
-
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 =
|
|
83
|
+
function T(e) {
|
|
84
|
+
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 = () => {
|
|
85
|
+
c &&= (h(c), c.close(), null);
|
|
86
|
+
}, u = !1, m = !1, _ = !1, b = !1, T = e.bounds ?? {
|
|
28
87
|
x: 24,
|
|
29
88
|
y: 24,
|
|
30
89
|
w: 220,
|
|
31
90
|
h: 200
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
kind: "rect",
|
|
36
|
-
x: e.rect.x,
|
|
37
|
-
y: e.rect.y,
|
|
38
|
-
width: e.rect.w,
|
|
39
|
-
height: e.rect.h
|
|
40
|
-
},
|
|
41
|
-
fill: {
|
|
42
|
-
fill: "solid",
|
|
43
|
-
color: C(e)
|
|
44
|
-
}
|
|
45
|
-
}), T = (e, t) => {
|
|
46
|
-
let n = f(F.aim.x, F.aim.y, p(e));
|
|
47
|
-
return g({
|
|
91
|
+
}, E = y(e.contentVersion ?? i?.getPaintedVersion), D = !1, O = (e) => (E.drew(e.view), V.mode === "vector" ? M(e) : N(e)), k = (t) => e.background ?? t.tokens["--wzl-surface"], A = (e) => C(e, k(e)), j = (e, t) => {
|
|
92
|
+
let n = f(V.aim.x, V.aim.y, p(e));
|
|
93
|
+
return v({
|
|
48
94
|
x: n[0],
|
|
49
95
|
y: n[1]
|
|
50
|
-
}, e, t,
|
|
51
|
-
},
|
|
52
|
-
id: `${
|
|
96
|
+
}, e, t, V.factor);
|
|
97
|
+
}, M = (t) => i ? s ? [A(t), ...s.draw(t.data, t.view, t.dims)] : [A(t)] : d({
|
|
98
|
+
id: `${R.id}:lens`,
|
|
53
99
|
label: "Loupe content",
|
|
54
100
|
source: e.source ?? [],
|
|
55
|
-
view:
|
|
101
|
+
view: j(t.view, t.rect),
|
|
56
102
|
bounds: () => t.rect,
|
|
57
|
-
background:
|
|
58
|
-
}).draw(t.data, t.view, t.dims),
|
|
59
|
-
let t = [
|
|
60
|
-
return
|
|
103
|
+
background: k(t)
|
|
104
|
+
}).draw(t.data, t.view, t.dims), N = (e) => {
|
|
105
|
+
let t = [A(e)];
|
|
106
|
+
return c && t.push({
|
|
61
107
|
kind: "image",
|
|
62
|
-
image:
|
|
108
|
+
image: c,
|
|
63
109
|
x: e.rect.x,
|
|
64
110
|
y: e.rect.y,
|
|
65
111
|
w: e.rect.w,
|
|
66
112
|
h: e.rect.h,
|
|
67
113
|
sampling: "nearest"
|
|
68
114
|
}), t;
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
},
|
|
115
|
+
}, P = () => {
|
|
116
|
+
_ || V.mode !== "pixel" || (m = !0);
|
|
117
|
+
}, F = (t, r, a) => {
|
|
72
118
|
if (!b) return null;
|
|
73
119
|
let o = n.getContext("webgl2");
|
|
74
120
|
if (!o) return null;
|
|
@@ -85,119 +131,105 @@ function b(e) {
|
|
|
85
131
|
width: n.width,
|
|
86
132
|
height: n.height
|
|
87
133
|
};
|
|
88
|
-
return
|
|
89
|
-
},
|
|
90
|
-
if (
|
|
91
|
-
let e =
|
|
134
|
+
return S(o, n.height, u, t, c, r(c), a(c));
|
|
135
|
+
}, I = () => {
|
|
136
|
+
if (_ || V.mode !== "pixel") return;
|
|
137
|
+
let e = R.contentRect, t = F(V.aim, (t) => Math.max(1, Math.round(e.w * t / V.factor)), (t) => Math.max(1, Math.round(e.h * t / V.factor)));
|
|
92
138
|
t && (u = !0, createImageBitmap(t).then((e) => {
|
|
93
|
-
if (
|
|
139
|
+
if (_) {
|
|
94
140
|
e.close();
|
|
95
141
|
return;
|
|
96
142
|
}
|
|
97
|
-
l
|
|
143
|
+
l(), c = e, u = !1, r();
|
|
98
144
|
}).catch(() => {
|
|
99
145
|
u = !1, r();
|
|
100
146
|
}));
|
|
101
|
-
},
|
|
102
|
-
let t =
|
|
103
|
-
return t ? "#" + [
|
|
147
|
+
}, L = (e) => {
|
|
148
|
+
let t = F(e, () => 1, () => 1);
|
|
149
|
+
return !t || t.data[3] === 0 ? null : "#" + [
|
|
104
150
|
t.data[0],
|
|
105
151
|
t.data[1],
|
|
106
152
|
t.data[2]
|
|
107
|
-
].map((e) => e.toString(16).padStart(2, "0")).join("")
|
|
108
|
-
},
|
|
153
|
+
].map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
154
|
+
}, R = t.window({
|
|
109
155
|
id: "weasel-loupe",
|
|
110
|
-
x:
|
|
111
|
-
y:
|
|
112
|
-
w:
|
|
113
|
-
h:
|
|
156
|
+
x: T.x,
|
|
157
|
+
y: T.y,
|
|
158
|
+
w: T.w,
|
|
159
|
+
h: T.h,
|
|
114
160
|
title: e.title ?? "Loupe",
|
|
115
161
|
titlebar: e.titlebar,
|
|
116
|
-
content:
|
|
162
|
+
content: O,
|
|
117
163
|
interior: a ? "pass" : "claim",
|
|
118
164
|
onResize: () => {
|
|
119
|
-
|
|
165
|
+
P();
|
|
120
166
|
},
|
|
121
167
|
...a ? {} : { onContentClick: (e) => {
|
|
122
|
-
|
|
168
|
+
V.pick(e);
|
|
123
169
|
} },
|
|
124
170
|
...e.onClose ? { onClose: e.onClose } : {}
|
|
125
|
-
}),
|
|
126
|
-
lens: () =>
|
|
127
|
-
covers: (e) =>
|
|
128
|
-
sample:
|
|
129
|
-
hidden: () =>
|
|
130
|
-
gone: () =>
|
|
171
|
+
}), z = {
|
|
172
|
+
lens: () => R.contentRect,
|
|
173
|
+
covers: (e) => R.hitTest(e.x, e.y) || (R.passes?.(e.x, e.y) ?? !1),
|
|
174
|
+
sample: L,
|
|
175
|
+
hidden: () => R.hidden,
|
|
176
|
+
gone: () => R.disposed === !0,
|
|
131
177
|
changed: () => {
|
|
132
|
-
|
|
178
|
+
P(), r();
|
|
133
179
|
},
|
|
134
180
|
subscribeFrame: t.subscribeFrame
|
|
135
|
-
},
|
|
136
|
-
b = !0,
|
|
137
|
-
}),
|
|
138
|
-
surface:
|
|
181
|
+
}, B = t.subscribeFrame(() => {
|
|
182
|
+
b = !0, (E.changed() || D) && (D = !1, P(), V.resample()), m && !u && (m = !1, I());
|
|
183
|
+
}), V = g({
|
|
184
|
+
surface: z,
|
|
139
185
|
...e.mode ? { mode: e.mode } : {},
|
|
140
186
|
...e.factor === void 0 ? {} : { factor: e.factor },
|
|
141
187
|
...e.onColorChange ? { onColorChange: e.onColorChange } : {},
|
|
142
188
|
...e.onPick ? { onPick: e.onPick } : {},
|
|
143
|
-
onDispose: () =>
|
|
189
|
+
onDispose: () => U()
|
|
144
190
|
});
|
|
145
191
|
i && (s = i.addView({
|
|
146
|
-
id: `${
|
|
192
|
+
id: `${R.id}:lens`,
|
|
147
193
|
label: "Loupe",
|
|
148
|
-
bounds: () =>
|
|
149
|
-
view: (e) =>
|
|
194
|
+
bounds: () => R.hidden ? w : R.contentRect,
|
|
195
|
+
view: (e) => j(e, R.contentRect),
|
|
150
196
|
paint: !1,
|
|
151
197
|
interactive: a,
|
|
152
198
|
...e.source ? { layers: () => e.source } : {}
|
|
153
199
|
}));
|
|
154
|
-
let
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
};
|
|
160
|
-
}, L = (e) => {
|
|
161
|
-
c || F.aimAt(I(e));
|
|
162
|
-
}, R = (e) => {
|
|
163
|
-
a && N.covers(I(e)) && (c = !0);
|
|
164
|
-
}, z = () => {
|
|
165
|
-
c = !1;
|
|
166
|
-
}, B = [
|
|
167
|
-
"pointerup",
|
|
168
|
-
"pointercancel",
|
|
169
|
-
"lostpointercapture"
|
|
170
|
-
], V = () => {
|
|
171
|
-
v = !0, P(), o.removeEventListener("pointermove", L), o.removeEventListener("pointerdown", R);
|
|
172
|
-
for (let e of B) o.removeEventListener(e, z);
|
|
173
|
-
s?.remove(), s = null, l?.close(), l = null;
|
|
200
|
+
let H = x(o, {
|
|
201
|
+
aimAt: (e) => V.aimAt(e),
|
|
202
|
+
holds: (e) => a && z.covers(e)
|
|
203
|
+
}), U = () => {
|
|
204
|
+
_ = !0, B(), H(), s?.remove(), s = null, l();
|
|
174
205
|
};
|
|
175
|
-
o.addEventListener("pointermove", L), o.addEventListener("pointerdown", R);
|
|
176
|
-
for (let e of B) o.addEventListener(e, z);
|
|
177
206
|
return {
|
|
178
|
-
window:
|
|
207
|
+
window: R,
|
|
179
208
|
get mode() {
|
|
180
|
-
return
|
|
209
|
+
return V.mode;
|
|
181
210
|
},
|
|
182
211
|
get factor() {
|
|
183
|
-
return
|
|
212
|
+
return V.factor;
|
|
184
213
|
},
|
|
185
214
|
get aim() {
|
|
186
|
-
return
|
|
215
|
+
return V.aim;
|
|
187
216
|
},
|
|
188
217
|
get color() {
|
|
189
|
-
return
|
|
218
|
+
return V.color;
|
|
219
|
+
},
|
|
220
|
+
setMode: V.setMode,
|
|
221
|
+
setFactor: V.setFactor,
|
|
222
|
+
aimAt: V.aimAt,
|
|
223
|
+
pick: V.pick,
|
|
224
|
+
refresh() {
|
|
225
|
+
_ || (D = !0, r());
|
|
190
226
|
},
|
|
191
|
-
setMode: F.setMode,
|
|
192
|
-
setFactor: F.setFactor,
|
|
193
|
-
aimAt: F.aimAt,
|
|
194
|
-
pick: F.pick,
|
|
195
227
|
dispose() {
|
|
196
|
-
|
|
228
|
+
V.dispose(), R.dispose();
|
|
197
229
|
}
|
|
198
230
|
};
|
|
199
231
|
}
|
|
200
232
|
//#endregion
|
|
201
|
-
export { r as DEFAULT_FONT_FAMILY, i as DEFAULT_WIDGET_CLAIMS, c as DEFAULT_WINDOW_METRICS, l as HUD_AFFORDANCE_KIND, s as attachHud, u as claimsOf, o as createHud, a as createHudContribution,
|
|
233
|
+
export { r as DEFAULT_FONT_FAMILY, i as DEFAULT_WIDGET_CLAIMS, c as DEFAULT_WINDOW_METRICS, l as HUD_AFFORDANCE_KIND, s as attachHud, u as claimsOf, o as createHud, a as createHudContribution, T as createLoupe, t as cursorForZone, n as isFocusable, _ as loupeInnerView, e as registerDefaultFont };
|
|
202
234
|
|
|
203
235
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["loupeInnerView","registerDefaultFont","cursorForZone","isFocusable","DEFAULT_FONT_FAMILY","DEFAULT_WIDGET_CLAIMS","createHudContribution","attachHud","DEFAULT_WINDOW_METRICS","HUD_AFFORDANCE_KIND","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","claimsOf","createHud","loupeInnerView"],"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, or, for an\n * `interactive` lens, a grip strip across its top does. */\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,MAAMO,IAAK,CAAC,GAAGN,EAAO,GAAGA,EAAO,IAAI,KAA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AiBC,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
|
+
{"version":3,"file":"index.js","names":["loupeInnerView","registerDefaultFont","cursorForZone","isFocusable","DEFAULT_FONT_FAMILY","DEFAULT_WIDGET_CLAIMS","createHudContribution","attachHud","DEFAULT_WINDOW_METRICS","HUD_AFFORDANCE_KIND","loupeInnerView$1","createContentWatch","camera","seen","view","now","version","moved","POINTER_ENDS","followPointer","holding","local","r","input","evt","onPointerMove","lens","onPointerDown","onPointerEnd","type","readbackRegion","cx","target","pointer","dpr","cy","gx","clamp","rw","gy","bufferHeight","rh","raw","gl","flipped","stride","row","src","backdropOf","ctx","NO_RECT","createLoupe","element","opts","host","interactive","pixels","dropPixels","releaseImageSource","pixelsPending","refreshWanted","disposed","landed","b","watch","refreshAsked","content","model","drawVector","drawPixels","backdropColor","backdrop","innerView","world","screenToWorld","viewToTransform","outer","rect","createViewportLayer","win","out","scheduleRefresh","read","cssRect","at","refreshPixels","data","bmp","requestRedraw","readHex","px","c","hud","p","surface","unsubscribeFrame","createLoupeModel","teardown","unfollow","claimsOf","createHud","loupeInnerView"],"sources":["../src/loupe/contentWatch.ts","../src/loupe/pointerAim.ts","../src/loupe/readback.ts","../src/loupe/createLoupe.ts"],"sourcesContent":["import type { View } from '@weasel-js/core';\n\n/** Says whether what a lens reads from changed between one landed frame and the next. */\nexport interface ContentWatch {\n /** The camera the lens was just drawn through. */\n drew(view: View): void;\n /** Whether the content version or the camera differs from the last time this was asked. The first ask only\n * takes its bearings, and answers `false`. */\n changed(): boolean;\n}\n\n/**\n * Watches the two things that change the pixels under an aim that holds still: the content, through `version`\n * when the lens is given one, and the camera it is drawn through. A lens redrawing itself moves neither, which is\n * what lets it read the framebuffer again on a change without that read's own redraw asking for another.\n */\nexport function createContentWatch(version: (() => number) | undefined): ContentWatch {\n let camera = '';\n let seen: { version: number | undefined; camera: string } | null = null;\n return {\n drew(view) {\n camera = `${view.x},${view.y},${view.scale.x},${view.scale.y}`;\n },\n changed() {\n const now = { version: version?.(), camera };\n const moved = seen !== null && (seen.version !== now.version || seen.camera !== now.camera);\n seen = now;\n return moved;\n },\n };\n}\n","interface Point { x: number; y: number }\n\nconst POINTER_ENDS = ['pointerup', 'pointercancel', 'lostpointercapture'] as const;\n\n/**\n * Aims a lens from the pointer moving over `input`, in CSS px relative to it. A gesture that begins where\n * `holds` answers true freezes the aim until it ends: the lens camera follows the aim, so re-aiming mid-drag\n * would move the world under the pointer. Returns a detach.\n */\nexport function followPointer(\n input: HTMLElement,\n lens: { aimAt(p: Point): void; holds(p: Point): boolean },\n): () => void {\n let holding = false;\n const local = (evt: PointerEvent): Point => {\n const r = input.getBoundingClientRect();\n return { x: evt.clientX - r.left, y: evt.clientY - r.top };\n };\n const onPointerMove = (evt: PointerEvent) => {\n if (!holding) lens.aimAt(local(evt));\n };\n const onPointerDown = (evt: PointerEvent) => {\n if (lens.holds(local(evt))) holding = true;\n };\n const onPointerEnd = () => { holding = false; };\n\n input.addEventListener('pointermove', onPointerMove);\n input.addEventListener('pointerdown', onPointerDown);\n for (const type of POINTER_ENDS) input.addEventListener(type, onPointerEnd);\n return () => {\n input.removeEventListener('pointermove', onPointerMove);\n input.removeEventListener('pointerdown', onPointerDown);\n for (const type of POINTER_ENDS) input.removeEventListener(type, onPointerEnd);\n };\n}\n","import { clamp } from '@weasel-js/geom';\n\n/**\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","import {\n createViewportLayer, screenToWorld, viewToTransform,\n type CanvasViewHandle, type RenderLayer, type SceneCanvasApi, type View,\n} from '@weasel-js/core';\nimport { releaseImageSource, 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 { createContentWatch } from './contentWatch';\nimport { followPointer } from './pointerAim';\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 /**\n * The version of what the canvas paints, read on every landed frame: when it moves, a lens whose aim has not\n * reads the framebuffer and the color under it again. Pass `CanvasExtensionApi.getPaintedVersion`. Defaults to\n * `views.getPaintedVersion` when the lens is a view. Without one the lens follows an edit under a parked aim\n * only in vector mode, or when told through `refresh()`; a camera move it follows either way.\n */\n contentVersion?: () => number;\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, or, for an\n * `interactive` lens, a grip strip across its top does. */\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'> & Partial<Pick<SceneCanvasApi, 'getPaintedVersion'>>;\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\nconst backdropOf = (ctx: HudContentCtx, color: string): 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: { paint: { kind: 'solid', color } },\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 /** Ask for a paint, and on the frame that lands read the picture and the color under the aim again: what is\n * under the aim changed in a way no `contentVersion` reports. */\n refresh(): void;\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 let pixels: ImageBitmap | null = null;\n const dropPixels = () => {\n if (!pixels) return;\n releaseImageSource(pixels);\n pixels.close();\n pixels = null;\n };\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 watch = createContentWatch(opts.contentVersion ?? host?.getPaintedVersion);\n let refreshAsked = false;\n\n const content = (ctx: HudContentCtx): DrawCommand[] => {\n watch.drew(ctx.view);\n return model.mode === 'vector' ? drawVector(ctx) : drawPixels(ctx);\n };\n\n const backdropColor = (ctx: HudContentCtx): string =>\n opts.background ?? ctx.tokens['--wzl-surface'];\n const backdrop = (ctx: HudContentCtx): DrawCommand => backdropOf(ctx, backdropColor(ctx));\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 dropPixels();\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 || px.data[3] === 0) 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 if (watch.changed() || refreshAsked) {\n refreshAsked = false;\n scheduleRefresh();\n model.resample();\n }\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 unfollow = followPointer(input, {\n aimAt: (p) => model.aimAt(p),\n holds: (p) => interactive && surface.covers(p),\n });\n\n const teardown = () => {\n disposed = true;\n unsubscribeFrame();\n unfollow();\n lens?.remove();\n lens = null;\n dropPixels();\n };\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 refresh() {\n if (disposed) return;\n refreshAsked = true;\n requestRedraw();\n },\n dispose() {\n model.dispose();\n win.dispose();\n },\n };\n}\n"],"mappings":";;;;;;AAgBA,SAAgBW,EAAmB,GAAmD;CACpF,IAAIC,IAAS,IACTC,IAA+D;CACnE,OAAO;EACL,KAAK,GAAM;GACT,IAAS,GAAGC,EAAK,EAAE,GAAGA,EAAK,EAAE,GAAGA,EAAK,MAAM,EAAE,GAAGA,EAAK,MAAM;EAC7D;EACA,UAAU;GACR,IAAMC,IAAM;IAAE,SAASC,IAAU;IAAG;GAAO,GACrCC,IAAQJ,MAAS,SAASA,EAAK,YAAYE,EAAI,WAAWF,EAAK,WAAWE,EAAI;GAEpF,OADA,IAAOA,GACAE;EACT;CACF;AACF;;;AC5BA,IAAMC,IAAe;CAAC;CAAa;CAAiB;AAAoB;AAOxE,SAAgBC,EACd,GACA,GACY;CACZ,IAAIC,IAAU,IACRC,KAAS,MAA6B;EAC1C,IAAMC,IAAIC,EAAM,sBAAsB;EACtC,OAAO;GAAE,GAAGC,EAAI,UAAUF,EAAE;GAAM,GAAGE,EAAI,UAAUF,EAAE;EAAI;CAC3D,GACMG,KAAiB,MAAsB;EAC3C,AAAKL,KAASM,EAAK,MAAML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cAAeA,EAAI,SAAS7B,IAAU6B,EAAI;EAC1C,OAAO,MAAUP,EAAUI,GAAOG,EAAI,WAAW;EACjD,OAAO;EACP;EACA,GAAI1B,EAAK,SAAS,EAAE,cAAcA,EAAK,OAAQ,IAAI,CAAC;CACtD,CAAC;CAGH,IAAM6C,IAAW/E,EAAcI,GAAO;EACpC,QAAQ,MAAM4C,EAAM,MAAM0B,CAAC;EAC3B,QAAQ,MAAMtC,KAAeuC,EAAQ,OAAOD,CAAC;CAC/C,CAAC,GAEKI,UAAiB;EAMrB,AALA,IAAW,IACXF,EAAiB,GACjBG,EAAS,GACTxE,GAAM,OAAO,GACb,IAAO,MACP+B,EAAW;CACb;CAEA,OAAO;EACL,QAAQsB;EACR,IAAI,OAAO;GAAE,OAAOZ,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;GACR,AAAIN,MACJ,IAAe,IACf2B,EAAc;EAChB;EACA,UAAU;GAER,AADArB,EAAM,QAAQ,GACdY,EAAI,QAAQ;EACd;CACF;AACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { View } from '@weasel-js/core';
|
|
2
|
+
/** Says whether what a lens reads from changed between one landed frame and the next. */
|
|
3
|
+
export interface ContentWatch {
|
|
4
|
+
/** The camera the lens was just drawn through. */
|
|
5
|
+
drew(view: View): void;
|
|
6
|
+
/** Whether the content version or the camera differs from the last time this was asked. The first ask only
|
|
7
|
+
* takes its bearings, and answers `false`. */
|
|
8
|
+
changed(): boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Watches the two things that change the pixels under an aim that holds still: the content, through `version`
|
|
12
|
+
* when the lens is given one, and the camera it is drawn through. A lens redrawing itself moves neither, which is
|
|
13
|
+
* what lets it read the framebuffer again on a change without that read's own redraw asking for another.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createContentWatch(version: (() => number) | undefined): ContentWatch;
|
|
16
|
+
//# sourceMappingURL=contentWatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contentWatch.d.ts","sourceRoot":"","sources":["../../src/loupe/contentWatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE5C,yFAAyF;AACzF,MAAM,WAAW,YAAY;IAC3B,kDAAkD;IAClD,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB;mDAC+C;IAC/C,OAAO,IAAI,OAAO,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,SAAS,GAAG,YAAY,CAcpF"}
|
|
@@ -25,6 +25,13 @@ export interface LoupeBaseOptions {
|
|
|
25
25
|
height: number;
|
|
26
26
|
};
|
|
27
27
|
requestRedraw: () => void;
|
|
28
|
+
/**
|
|
29
|
+
* The version of what the canvas paints, read on every landed frame: when it moves, a lens whose aim has not
|
|
30
|
+
* reads the framebuffer and the color under it again. Pass `CanvasExtensionApi.getPaintedVersion`. Defaults to
|
|
31
|
+
* `views.getPaintedVersion` when the lens is a view. Without one the lens follows an edit under a parked aim
|
|
32
|
+
* only in vector mode, or when told through `refresh()`; a camera move it follows either way.
|
|
33
|
+
*/
|
|
34
|
+
contentVersion?: () => number;
|
|
28
35
|
mode?: LoupeMode;
|
|
29
36
|
factor?: number;
|
|
30
37
|
bounds?: WidgetBounds;
|
|
@@ -64,7 +71,7 @@ export type LoupeOptions = LoupeBaseOptions & ({
|
|
|
64
71
|
* the lens can take input. It magnifies the canvas's own camera; aimed
|
|
65
72
|
* over another view, it shows the canvas's world, not that view's.
|
|
66
73
|
*/
|
|
67
|
-
views: Pick<SceneCanvasApi, 'addView' | 'getSurfaceRect'
|
|
74
|
+
views: Pick<SceneCanvasApi, 'addView' | 'getSurfaceRect'> & Partial<Pick<SceneCanvasApi, 'getPaintedVersion'>>;
|
|
68
75
|
/** Narrows what vector mode paints. Defaults to the canvas's stack. */
|
|
69
76
|
source?: RenderLayer<unknown>[];
|
|
70
77
|
/**
|
|
@@ -107,6 +114,9 @@ export interface LoupeHandle {
|
|
|
107
114
|
x: number;
|
|
108
115
|
y: number;
|
|
109
116
|
}): string | null;
|
|
117
|
+
/** Ask for a paint, and on the frame that lands read the picture and the color under the aim again: what is
|
|
118
|
+
* under the aim changed in a way no `contentVersion` reports. */
|
|
119
|
+
refresh(): void;
|
|
110
120
|
dispose(): void;
|
|
111
121
|
}
|
|
112
122
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLoupe.d.ts","sourceRoot":"","sources":["../../src/loupe/createLoupe.ts"],"names":[],"mappings":"AAAA,OAAO,EAEkB,KAAK,WAAW,EAAE,KAAK,cAAc,EAC7D,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAEL,KAAK,SAAS,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"createLoupe.d.ts","sourceRoot":"","sources":["../../src/loupe/createLoupe.ts"],"names":[],"mappings":"AAAA,OAAO,EAEkB,KAAK,WAAW,EAAE,KAAK,cAAc,EAC7D,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAEL,KAAK,SAAS,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,YAAY,EAAE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