@weasel-js/hud 1.4.3 → 1.5.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/dist/attach.d.ts.map +1 -1
- package/dist/index.js +146 -110
- package/dist/index.js.map +1 -1
- package/dist/loupe/createLoupe.d.ts +44 -9
- package/dist/loupe/createLoupe.d.ts.map +1 -1
- package/dist/loupe/readback.d.ts +6 -2
- package/dist/loupe/readback.d.ts.map +1 -1
- package/dist/react/index.js +1 -1
- package/dist/{tool-ahNtvOfu.js → tool-QNtLieKj.js} +63 -57
- package/dist/{tool-ahNtvOfu.js.map → tool-QNtLieKj.js.map} +1 -1
- package/dist/widget.d.ts +5 -0
- package/dist/widget.d.ts.map +1 -1
- package/dist/widgets/window/window.d.ts +9 -0
- package/dist/widgets/window/window.d.ts.map +1 -1
- package/package.json +6 -6
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;AAGrC,OAAO,EAA6B,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjF,MAAM,WAAW,gBAAgB;IAC/B;2EACuE;IACvE,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IAC/B;;;;;;;;;;;OAWG;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,
|
|
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;AAGrC,OAAO,EAA6B,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjF,MAAM,WAAW,gBAAgB;IAC/B;2EACuE;IACvE,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IAC/B;;;;;;;;;;;OAWG;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,CAyIZ"}
|
package/dist/index.js
CHANGED
|
@@ -1,167 +1,203 @@
|
|
|
1
|
-
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c, u as l } from "./tool-
|
|
1
|
+
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c, u as l } from "./tool-QNtLieKj.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
|
|
5
|
-
function g(e, t, n, r, i, a) {
|
|
6
|
-
let
|
|
7
|
-
e.readPixels(
|
|
8
|
-
let f = new Uint8ClampedArray(
|
|
9
|
-
for (let e = 0; e <
|
|
10
|
-
let t = (
|
|
5
|
+
function g(e, t, n, r, i, a, o) {
|
|
6
|
+
let s = n.x + Math.round(r.x * i), c = n.y + Math.round(r.y * i), l = _(s - Math.floor(a / 2), n.x, n.x + Math.max(0, n.width - a)), u = t - _(c - Math.floor(o / 2), n.y, n.y + Math.max(0, n.height - o)) - o, d = new Uint8Array(a * o * 4);
|
|
7
|
+
e.readPixels(l, u, a, o, e.RGBA, e.UNSIGNED_BYTE, d);
|
|
8
|
+
let f = new Uint8ClampedArray(a * o * 4), p = a * 4;
|
|
9
|
+
for (let e = 0; e < o; e++) {
|
|
10
|
+
let t = (o - 1 - e) * p;
|
|
11
11
|
f.set(d.subarray(t, t + p), e * p);
|
|
12
12
|
}
|
|
13
|
-
return new ImageData(f,
|
|
13
|
+
return new ImageData(f, a, o);
|
|
14
14
|
}
|
|
15
15
|
function _(e, t, n) {
|
|
16
16
|
return e < t ? t : e > n ? n : e;
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/loupe/createLoupe.ts
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
var v = {
|
|
21
|
+
x: 0,
|
|
22
|
+
y: 0,
|
|
23
|
+
w: 0,
|
|
24
|
+
h: 0
|
|
25
|
+
};
|
|
26
|
+
function y(e) {
|
|
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 = !1, l = null, m = !1, _ = !1, y = !1, b = !1, x = e.bounds ?? {
|
|
22
28
|
x: 24,
|
|
23
29
|
y: 24,
|
|
24
30
|
w: 220,
|
|
25
31
|
h: 200
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
let
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return
|
|
32
|
+
}, S = (e) => F.mode === "vector" ? E(e) : D(e), C = (t) => e.background ?? t.tokens["--wzl-surface"], w = (e) => ({
|
|
33
|
+
kind: "path",
|
|
34
|
+
path: {
|
|
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 = d(F.aim.x, F.aim.y, f(e));
|
|
47
|
+
return h({
|
|
48
|
+
x: n[0],
|
|
49
|
+
y: n[1]
|
|
50
|
+
}, e, t, F.factor);
|
|
51
|
+
}, E = (t) => i ? s ? [w(t), ...s.draw(t.data, t.view, t.dims)] : [w(t)] : u({
|
|
52
|
+
id: `${M.id}:lens`,
|
|
53
|
+
label: "Loupe content",
|
|
54
|
+
source: e.source ?? [],
|
|
55
|
+
view: T(t.view, t.rect),
|
|
56
|
+
bounds: () => t.rect,
|
|
57
|
+
background: C(t)
|
|
58
|
+
}).draw(t.data, t.view, t.dims), D = (e) => {
|
|
59
|
+
let t = [w(e)];
|
|
60
|
+
return l && t.push({
|
|
55
61
|
kind: "image",
|
|
56
|
-
image:
|
|
62
|
+
image: l,
|
|
57
63
|
x: e.rect.x,
|
|
58
64
|
y: e.rect.y,
|
|
59
65
|
w: e.rect.w,
|
|
60
66
|
h: e.rect.h,
|
|
61
67
|
sampling: "nearest"
|
|
62
68
|
}), t;
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
if (
|
|
67
|
-
let
|
|
68
|
-
if (!
|
|
69
|
-
let
|
|
70
|
-
if (
|
|
71
|
-
let
|
|
69
|
+
}, O = () => {
|
|
70
|
+
y || F.mode !== "pixel" || (_ = !0);
|
|
71
|
+
}, k = (t, r, a) => {
|
|
72
|
+
if (!b) return null;
|
|
73
|
+
let o = n.getContext("webgl2");
|
|
74
|
+
if (!o) return null;
|
|
75
|
+
let s = n.getBoundingClientRect();
|
|
76
|
+
if (s.width === 0) return null;
|
|
77
|
+
let c = n.width / s.width, l = (e.region ?? i?.getSurfaceRect)?.(), u = l ? {
|
|
78
|
+
x: Math.round(l.x * c),
|
|
79
|
+
y: Math.round(l.y * c),
|
|
80
|
+
width: Math.round(l.width * c),
|
|
81
|
+
height: Math.round(l.height * c)
|
|
82
|
+
} : {
|
|
83
|
+
x: 0,
|
|
84
|
+
y: 0,
|
|
72
85
|
width: n.width,
|
|
73
86
|
height: n.height
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
87
|
+
};
|
|
88
|
+
return g(o, n.height, u, t, c, r(c), a(c));
|
|
89
|
+
}, A = () => {
|
|
90
|
+
if (y || F.mode !== "pixel") return;
|
|
91
|
+
let e = M.contentRect, t = k(F.aim, (t) => Math.max(1, Math.round(e.w * t / F.factor)), (t) => Math.max(1, Math.round(e.h * t / F.factor)));
|
|
92
|
+
t && (m = !0, createImageBitmap(t).then((e) => {
|
|
93
|
+
if (y) {
|
|
77
94
|
e.close();
|
|
78
95
|
return;
|
|
79
96
|
}
|
|
80
|
-
|
|
97
|
+
l?.close(), l = e, m = !1, r();
|
|
81
98
|
}).catch(() => {
|
|
82
|
-
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
|
-
let t =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}, e, i, 1, 1);
|
|
93
|
-
return "#" + [
|
|
94
|
-
a.data[0],
|
|
95
|
-
a.data[1],
|
|
96
|
-
a.data[2]
|
|
97
|
-
].map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
98
|
-
}, w = t.window({
|
|
99
|
+
m = !1, r();
|
|
100
|
+
}));
|
|
101
|
+
}, j = (e) => {
|
|
102
|
+
let t = k(e, () => 1, () => 1);
|
|
103
|
+
return t ? "#" + [
|
|
104
|
+
t.data[0],
|
|
105
|
+
t.data[1],
|
|
106
|
+
t.data[2]
|
|
107
|
+
].map((e) => e.toString(16).padStart(2, "0")).join("") : null;
|
|
108
|
+
}, M = t.window({
|
|
99
109
|
id: "weasel-loupe",
|
|
100
|
-
x:
|
|
101
|
-
y:
|
|
102
|
-
w:
|
|
103
|
-
h:
|
|
110
|
+
x: x.x,
|
|
111
|
+
y: x.y,
|
|
112
|
+
w: x.w,
|
|
113
|
+
h: x.h,
|
|
104
114
|
title: e.title ?? "Loupe",
|
|
105
115
|
titlebar: e.titlebar,
|
|
106
|
-
content:
|
|
116
|
+
content: S,
|
|
117
|
+
interior: a ? "pass" : "claim",
|
|
107
118
|
onResize: () => {
|
|
108
|
-
|
|
109
|
-
},
|
|
110
|
-
onContentClick: (e) => {
|
|
111
|
-
T.pick(e);
|
|
119
|
+
O();
|
|
112
120
|
},
|
|
121
|
+
...a ? {} : { onContentClick: (e) => {
|
|
122
|
+
F.pick(e);
|
|
123
|
+
} },
|
|
113
124
|
...e.onClose ? { onClose: e.onClose } : {}
|
|
114
|
-
}),
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
x(), i();
|
|
123
|
-
}
|
|
125
|
+
}), N = {
|
|
126
|
+
lens: () => M.contentRect,
|
|
127
|
+
covers: (e) => M.hitTest(e.x, e.y) || (M.passes?.(e.x, e.y) ?? !1),
|
|
128
|
+
sample: j,
|
|
129
|
+
hidden: () => M.hidden,
|
|
130
|
+
gone: () => M.disposed === !0,
|
|
131
|
+
changed: () => {
|
|
132
|
+
O(), r();
|
|
124
133
|
},
|
|
134
|
+
subscribeFrame: t.subscribeFrame
|
|
135
|
+
}, P = t.subscribeFrame(() => {
|
|
136
|
+
b = !0, !(!_ || m) && (_ = !1, A());
|
|
137
|
+
}), F = p({
|
|
138
|
+
surface: N,
|
|
125
139
|
...e.mode ? { mode: e.mode } : {},
|
|
126
140
|
...e.factor === void 0 ? {} : { factor: e.factor },
|
|
127
141
|
...e.onColorChange ? { onColorChange: e.onColorChange } : {},
|
|
128
142
|
...e.onPick ? { onPick: e.onPick } : {},
|
|
129
|
-
onDispose: () =>
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
|
|
143
|
+
onDispose: () => V()
|
|
144
|
+
});
|
|
145
|
+
i && (s = i.addView({
|
|
146
|
+
id: `${M.id}:lens`,
|
|
147
|
+
label: "Loupe",
|
|
148
|
+
bounds: () => M.hidden ? v : M.contentRect,
|
|
149
|
+
view: (e) => T(e, M.contentRect),
|
|
150
|
+
paint: !1,
|
|
151
|
+
interactive: a,
|
|
152
|
+
...e.source ? { layers: () => e.source } : {}
|
|
153
|
+
}));
|
|
154
|
+
let I = (e) => {
|
|
155
|
+
let t = o.getBoundingClientRect();
|
|
156
|
+
return {
|
|
133
157
|
x: e.clientX - t.left,
|
|
134
158
|
y: e.clientY - t.top
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
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
|
+
y = !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;
|
|
140
174
|
};
|
|
141
|
-
|
|
142
|
-
|
|
175
|
+
o.addEventListener("pointermove", L), o.addEventListener("pointerdown", R);
|
|
176
|
+
for (let e of B) o.addEventListener(e, z);
|
|
177
|
+
return {
|
|
178
|
+
window: M,
|
|
143
179
|
get mode() {
|
|
144
|
-
return
|
|
180
|
+
return F.mode;
|
|
145
181
|
},
|
|
146
182
|
get factor() {
|
|
147
|
-
return
|
|
183
|
+
return F.factor;
|
|
148
184
|
},
|
|
149
185
|
get aim() {
|
|
150
|
-
return
|
|
186
|
+
return F.aim;
|
|
151
187
|
},
|
|
152
188
|
get color() {
|
|
153
|
-
return
|
|
189
|
+
return F.color;
|
|
154
190
|
},
|
|
155
|
-
setMode:
|
|
156
|
-
setFactor:
|
|
157
|
-
aimAt:
|
|
158
|
-
pick:
|
|
191
|
+
setMode: F.setMode,
|
|
192
|
+
setFactor: F.setFactor,
|
|
193
|
+
aimAt: F.aimAt,
|
|
194
|
+
pick: F.pick,
|
|
159
195
|
dispose() {
|
|
160
|
-
|
|
196
|
+
F.dispose(), M.dispose();
|
|
161
197
|
}
|
|
162
198
|
};
|
|
163
199
|
}
|
|
164
200
|
//#endregion
|
|
165
|
-
export { a as DEFAULT_FONT_FAMILY, n as DEFAULT_WIDGET_CLAIMS, r as DEFAULT_WINDOW_METRICS, c as HUD_AFFORDANCE_KIND, o as attachHud, e as claimsOf, t as createHud, i as createHudContribution,
|
|
201
|
+
export { a as DEFAULT_FONT_FAMILY, n as DEFAULT_WIDGET_CLAIMS, r as DEFAULT_WINDOW_METRICS, c as HUD_AFFORDANCE_KIND, o as attachHud, e as claimsOf, t as createHud, i as createHudContribution, y as createLoupe, l as cursorForZone, m as loupeInnerView, s as registerDefaultFont };
|
|
166
202
|
|
|
167
203
|
//# sourceMappingURL=index.js.map
|
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` (CSS px relative to the canvas), returned top-down.\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 buffer: { width: number; height: number },\n pointer: { x: number; y: number },\n dpr: number,\n rw: number,\n rh: number,\n): ImageData {\n const cx = Math.round(pointer.x * dpr);\n const cy = Math.round(pointer.y * dpr);\n const gx = clamp(cx - Math.floor(rw / 2), 0, Math.max(0, buffer.width - rw));\n const gyTop = clamp(cy - Math.floor(rh / 2), 0, Math.max(0, buffer.height - rh));\n const gy = buffer.height - 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 RenderLayer, 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`. */\nexport interface LoupeOptions {\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 /** Layers re-rendered through the magnified inner view in vector mode. */\n source: RenderLayer<unknown>[];\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. */\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/** 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. `null` before\n * the first aim, or when the GL context 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. Leaves the aim, and `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, source, requestRedraw } = opts;\n const input = opts.input ?? element;\n let pixels: ImageBitmap | null = null;\n let pixelsPending = false;\n let refreshWanted = false;\n let disposed = 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 drawVector = (ctx: HudContentCtx): DrawCommand[] => {\n const world = screenToWorld(model.aim.x, model.aim.y, viewToTransform(ctx.view));\n const inner: View = loupeInnerView(\n { x: world[0], y: world[1] }, ctx.view, ctx.rect, model.factor,\n );\n // A fresh lens per frame: CreateViewportLayerOpts.view is static, and the\n // inner view moves with the pointer.\n const lens = createViewportLayer<unknown>({\n id: `${win.id}:lens`,\n label: 'Loupe content',\n source,\n view: inner,\n bounds: () => ctx.rect,\n background: backdropColor(ctx),\n });\n return lens.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[] = [{\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 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 const refreshPixels = () => {\n if (disposed || model.mode !== 'pixel') return;\n const gl = element.getContext('webgl2');\n if (!gl) return;\n const cssRect = element.getBoundingClientRect();\n if (cssRect.width === 0) return;\n const dpr = element.width / cssRect.width;\n const rect = win.contentRect;\n const rw = Math.max(1, Math.round((rect.w * dpr) / model.factor));\n const rh = Math.max(1, Math.round((rect.h * dpr) / model.factor));\n const data = readbackRegion(\n gl, { width: element.width, height: element.height }, model.aim, dpr, rw, rh,\n );\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 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 const px = readbackRegion(\n gl, { width: element.width, height: element.height }, at, dpr, 1, 1,\n );\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 onResize: () => { scheduleRefresh(); },\n onContentClick: (p) => { 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),\n sample: readHex,\n hidden: () => win.hidden,\n gone: () => win.disposed === true,\n changed: () => { scheduleRefresh(); requestRedraw(); },\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 const onPointerMove = (evt: PointerEvent) => {\n const r = input.getBoundingClientRect();\n model.aimAt({ x: evt.clientX - r.left, y: evt.clientY - r.top });\n };\n\n const unsubscribeFrame = hud.subscribeFrame(() => {\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 teardown = () => {\n disposed = true;\n unsubscribeFrame();\n input.removeEventListener('pointermove', onPointerMove);\n pixels?.close();\n pixels = null;\n };\n\n input.addEventListener('pointermove', onPointerMove);\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":";;;;AAOA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACA,GACW;CACX,IAAM,IAAK,KAAK,MAAM,EAAQ,IAAI,EAAI,EAChC,IAAK,KAAK,MAAM,EAAQ,IAAI,EAAI,EAChC,IAAK,EAAM,IAAK,KAAK,MAAM,IAAK,EAAE,EAAE,GAAG,KAAK,IAAI,GAAG,EAAO,QAAQ,EAAG,CAAC,EACtE,IAAQ,EAAM,IAAK,KAAK,MAAM,IAAK,EAAE,EAAE,GAAG,KAAK,IAAI,GAAG,EAAO,SAAS,EAAG,CAAC,EAC1E,IAAK,EAAO,SAAS,IAAQ,GAE7B,IAAM,IAAI,WAAW,IAAK,IAAK,EAAE;AACvC,GAAG,WAAW,GAAI,GAAI,GAAI,GAAI,EAAG,MAAM,EAAG,eAAe,EAAI;CAE7D,IAAM,IAAU,IAAI,kBAAkB,IAAK,IAAK,EAAE,EAC5C,IAAS,IAAK;AACpB,MAAK,IAAI,IAAM,GAAG,IAAM,GAAI,KAAO;EACjC,IAAM,KAAO,IAAK,IAAI,KAAO;AAC7B,IAAQ,IAAI,EAAI,SAAS,GAAK,IAAM,EAAO,EAAE,IAAM,EAAO;;AAE5D,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AAc,EAE7C;EACL,QAAQ;EACR,IAAI,OAAO;AAAE,UAAO,EAAM;;EAC1B,IAAI,SAAS;AAAE,UAAO,EAAM;;EAC5B,IAAI,MAAM;AAAE,UAAO,EAAM;;EACzB,IAAI,QAAQ;AAAE,UAAO,EAAM;;EAC3B,SAAS,EAAM;EACf,WAAW,EAAM;EACjB,OAAO,EAAM;EACb,MAAM,EAAM;EACZ,UAAU;AAER,GADA,EAAM,SAAS,EACf,EAAI,SAAS;;EAEhB"}
|
|
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,GACA,GACW;CACX,IAAM,IAAK,EAAO,IAAI,KAAK,MAAM,EAAQ,IAAI,EAAI,EAC3C,IAAK,EAAO,IAAI,KAAK,MAAM,EAAQ,IAAI,EAAI,EAC3C,IAAK,EAAM,IAAK,KAAK,MAAM,IAAK,EAAE,EAAE,EAAO,GAAG,EAAO,IAAI,KAAK,IAAI,GAAG,EAAO,QAAQ,EAAG,CAAC,EAExF,IAAK,IADG,EAAM,IAAK,KAAK,MAAM,IAAK,EAAE,EAAE,EAAO,GAAG,EAAO,IAAI,KAAK,IAAI,GAAG,EAAO,SAAS,E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AAI,CAAC;IAEnB,KAAiB,MAAsB;AAC3C,EAAI,KAAe,EAAQ,OAAO,EAAM,EAAI,CAAC,KAAE,IAAU;IAErD,UAAqB;AAAE,MAAU;IACjC,IAAc;EAAC;EAAa;EAAiB;EAAqB,EAElE,UAAiB;AAIrB,EAHA,IAAW,IACX,GAAkB,EAClB,EAAM,oBAAoB,eAAe,EAAc,EACvD,EAAM,oBAAoB,eAAe,EAAc;AACvD,OAAK,IAAM,KAAQ,EAAa,GAAM,oBAAoB,GAAM,EAAa;AAI7E,EAHA,GAAM,QAAQ,EACd,IAAO,MACP,GAAQ,OAAO,EACf,IAAS;;AAIX,CADA,EAAM,iBAAiB,eAAe,EAAc,EACpD,EAAM,iBAAiB,eAAe,EAAc;AACpD,MAAK,IAAM,KAAQ,EAAa,GAAM,iBAAiB,GAAM,EAAa;AAE1E,QAAO;EACL,QAAQ;EACR,IAAI,OAAO;AAAE,UAAO,EAAM;;EAC1B,IAAI,SAAS;AAAE,UAAO,EAAM;;EAC5B,IAAI,MAAM;AAAE,UAAO,EAAM;;EACzB,IAAI,QAAQ;AAAE,UAAO,EAAM;;EAC3B,SAAS,EAAM;EACf,WAAW,EAAM;EACjB,OAAO,EAAM;EACb,MAAM,EAAM;EACZ,UAAU;AAER,GADA,EAAM,SAAS,EACf,EAAI,SAAS;;EAEhB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type RenderLayer } from '@weasel-js/core';
|
|
1
|
+
import { type RenderLayer, type SceneCanvasApi } from '@weasel-js/core';
|
|
2
2
|
import { type LoupeMode } from '@weasel-js/loupe';
|
|
3
3
|
import type { Hud } from '../hud';
|
|
4
4
|
import type { WindowWidget } from '../widgets/window/window';
|
|
5
5
|
import type { WidgetBounds } from '../widget';
|
|
6
6
|
export type { LoupeMode };
|
|
7
|
-
/** Options for `createLoupe
|
|
8
|
-
export interface
|
|
7
|
+
/** Options for `createLoupe` shared by a plain lens and an interactive one. */
|
|
8
|
+
export interface LoupeBaseOptions {
|
|
9
9
|
hud: Hud;
|
|
10
10
|
/** The canvas pixel mode reads back from. Supplies the GL context and the
|
|
11
11
|
* drawing-buffer dimensions. */
|
|
@@ -14,8 +14,16 @@ export interface LoupeOptions {
|
|
|
14
14
|
* the rect client coords are measured against. Defaults to `canvas`, which
|
|
15
15
|
* is right whenever the canvas is also the thing under the pointer. */
|
|
16
16
|
input?: HTMLElement;
|
|
17
|
-
/**
|
|
18
|
-
|
|
17
|
+
/** The rect of `canvas` the magnified picture occupies, in its CSS px — the
|
|
18
|
+
* one the aim is relative to. Pass `CanvasExtensionApi.getSurfaceRect` for
|
|
19
|
+
* a pane painted into a shared canvas. Defaults to `views.getSurfaceRect`
|
|
20
|
+
* when the lens is a view, and to the whole canvas otherwise. */
|
|
21
|
+
region?: () => {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
};
|
|
19
27
|
requestRedraw: () => void;
|
|
20
28
|
mode?: LoupeMode;
|
|
21
29
|
factor?: number;
|
|
@@ -31,7 +39,8 @@ export interface LoupeOptions {
|
|
|
31
39
|
onColorChange?: (hex: string) => void;
|
|
32
40
|
/** Fired when a click inside the lens picks a color — an eyedropper on the
|
|
33
41
|
* magnified surface. Where the color goes is the consumer's: the loupe
|
|
34
|
-
* reports the pick and nothing else.
|
|
42
|
+
* reports the pick and nothing else. An `interactive` lens gives its clicks
|
|
43
|
+
* to the canvas, so only `pick()` reaches this. */
|
|
35
44
|
onPick?: (hex: string) => void;
|
|
36
45
|
/** Fired by the window's close box. The window does not hide itself —
|
|
37
46
|
* whoever owns the loupe's visibility decides what closing means. */
|
|
@@ -41,6 +50,30 @@ export interface LoupeOptions {
|
|
|
41
50
|
* the theme's surface color. */
|
|
42
51
|
background?: string;
|
|
43
52
|
}
|
|
53
|
+
/** Options for `createLoupe`. */
|
|
54
|
+
export type LoupeOptions = LoupeBaseOptions & ({
|
|
55
|
+
/** Layers re-rendered through the magnified inner view in vector mode. */
|
|
56
|
+
source: RenderLayer<unknown>[];
|
|
57
|
+
views?: undefined;
|
|
58
|
+
interactive?: false;
|
|
59
|
+
} | {
|
|
60
|
+
/**
|
|
61
|
+
* The canvas, as a host for views. The lens becomes a view on it: vector
|
|
62
|
+
* mode paints the canvas's own stack — scene and selection chrome — and
|
|
63
|
+
* the lens can take input. It magnifies the canvas's own camera; aimed
|
|
64
|
+
* over another view, it shows the canvas's world, not that view's.
|
|
65
|
+
*/
|
|
66
|
+
views: Pick<SceneCanvasApi, 'addView' | 'getSurfaceRect'>;
|
|
67
|
+
/** Narrows what vector mode paints. Defaults to the canvas's stack. */
|
|
68
|
+
source?: RenderLayer<unknown>[];
|
|
69
|
+
/**
|
|
70
|
+
* Route input inside the lens to what it shows: a press selects the node
|
|
71
|
+
* magnified under the pointer, and a drag moves it by the pointer travel
|
|
72
|
+
* divided by the magnification. Default `false` — the window keeps its
|
|
73
|
+
* interior, and a click there picks a color.
|
|
74
|
+
*/
|
|
75
|
+
interactive?: boolean;
|
|
76
|
+
});
|
|
44
77
|
/** Control surface for a live loupe: where it is aimed, how it magnifies,
|
|
45
78
|
* what color it is over, and the window it lives in. */
|
|
46
79
|
export interface LoupeHandle {
|
|
@@ -52,8 +85,9 @@ export interface LoupeHandle {
|
|
|
52
85
|
x: number;
|
|
53
86
|
y: number;
|
|
54
87
|
};
|
|
55
|
-
/** Hex color under the aim point, read off the framebuffer
|
|
56
|
-
* the
|
|
88
|
+
/** Hex color under the aim point, read off the framebuffer on the first
|
|
89
|
+
* frame to land after the aim. `null` until then, or when the GL context
|
|
90
|
+
* is unavailable. */
|
|
57
91
|
readonly color: string | null;
|
|
58
92
|
setMode(mode: LoupeMode): void;
|
|
59
93
|
setFactor(factor: number): void;
|
|
@@ -66,7 +100,8 @@ export interface LoupeHandle {
|
|
|
66
100
|
/** Sample the color the lens is showing at `p` — a screen point inside the
|
|
67
101
|
* lens — and report it to `onPick`. Omit `p` to pick at the aim point.
|
|
68
102
|
* Returns the hex, or `null` when the framebuffer cannot answer for that
|
|
69
|
-
* point. Leaves the aim, and
|
|
103
|
+
* point, including before any frame has landed. Leaves the aim, and
|
|
104
|
+
* `color`, alone. */
|
|
70
105
|
pick(p?: {
|
|
71
106
|
x: number;
|
|
72
107
|
y: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLoupe.d.ts","sourceRoot":"","sources":["../../src/loupe/createLoupe.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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;AAG7D,YAAY,EAAE,SAAS,EAAE,CAAC;AAE1B,+EAA+E;AAC/E,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,GAAG,CAAC;IACT;qCACiC;IACjC,MAAM,EAAE,iBAAiB,CAAC;IAC1B;;4EAEwE;IACxE,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;sEAGkE;IAClE,MAAM,CAAC,EAAE,MAAM;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACvE,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;IACt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C/B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC;oEACgE;IAChE,KAAK,CAAC,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACzC;;;;0BAIsB;IACtB,IAAI,CAAC,CAAC,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,GAAG,IAAI,CAAC;IAClD,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,WAAW,CAyO3D"}
|
package/dist/loupe/readback.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Read a `rw × rh` device-pixel region of the drawing buffer centered on
|
|
3
|
-
* `pointer`
|
|
3
|
+
* `pointer`, returned top-down. `pointer` is in CSS px relative to `target`,
|
|
4
|
+
* the rect of the buffer the canvas paints into (device px, top-left origin),
|
|
5
|
+
* and the read is clamped to stay inside that rect.
|
|
4
6
|
*
|
|
5
7
|
* GL reports rows bottom-up; every consumer here wants top-down, so both the
|
|
6
8
|
* read origin and the returned rows are flipped.
|
|
7
9
|
*/
|
|
8
|
-
export declare function readbackRegion(gl: WebGL2RenderingContext,
|
|
10
|
+
export declare function readbackRegion(gl: WebGL2RenderingContext, bufferHeight: number, target: {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
9
13
|
width: number;
|
|
10
14
|
height: number;
|
|
11
15
|
}, pointer: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readback.d.ts","sourceRoot":"","sources":["../../src/loupe/readback.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"readback.d.ts","sourceRoot":"","sources":["../../src/loupe/readback.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,EAAE,EAAE,sBAAsB,EAC1B,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC/D,OAAO,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EACjC,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,GACT,SAAS,CAiBX"}
|
package/dist/react/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as e, n as t, r as n } from "../tool-
|
|
1
|
+
import { c as e, n as t, r as n } from "../tool-QNtLieKj.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";
|