@qaiddev/thumbs-embed 1.11.0 → 1.12.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.
Files changed (47) hide show
  1. package/dist/a11y-dialog.d.ts +77 -0
  2. package/dist/a11y.d.ts +6 -65
  3. package/dist/chunks/annotate-DGyRcgPt.js +2 -0
  4. package/dist/chunks/{annotate-5zJWs-aB.js.map → annotate-DGyRcgPt.js.map} +1 -1
  5. package/dist/chunks/core-BsR7oV99.js +26 -0
  6. package/dist/chunks/core-BsR7oV99.js.map +1 -0
  7. package/dist/chunks/dom-scpOS8nl.js +2 -0
  8. package/dist/chunks/{dom-DvdtcUS8.js.map → dom-scpOS8nl.js.map} +1 -1
  9. package/dist/chunks/modal-DYxcs1Gm.js +2 -0
  10. package/dist/chunks/modal-DYxcs1Gm.js.map +1 -0
  11. package/dist/chunks/recording-BUw5-5Rf.js +2 -0
  12. package/dist/chunks/{recording-CPzxRL7f.js.map → recording-BUw5-5Rf.js.map} +1 -1
  13. package/dist/chunks/screenshot-CNe1irEz.js +2 -0
  14. package/dist/chunks/{screenshot-DYOKg2bS.js.map → screenshot-CNe1irEz.js.map} +1 -1
  15. package/dist/chunks/screenshot-dom-ZYP2w2h0.js +2 -0
  16. package/dist/chunks/{screenshot-dom-CME7tYRE.js.map → screenshot-dom-ZYP2w2h0.js.map} +1 -1
  17. package/dist/chunks/send-C26DRoYc.js +2 -0
  18. package/dist/chunks/send-C26DRoYc.js.map +1 -0
  19. package/dist/chunks/targeting-CMUEe-7C.js +6 -0
  20. package/dist/chunks/{targeting-mahtuPpo.js.map → targeting-CMUEe-7C.js.map} +1 -1
  21. package/dist/chunks/video-BSP4s2te.js +2 -0
  22. package/dist/chunks/{video-Bd_29-rK.js.map → video-BSP4s2te.js.map} +1 -1
  23. package/dist/embed.d.ts +26 -31
  24. package/dist/index.js +1495 -1390
  25. package/dist/index.js.map +1 -1
  26. package/dist/loader.d.ts +6 -4
  27. package/dist/loader.js +1 -6
  28. package/dist/loader.js.map +1 -1
  29. package/dist/modal-positioning.d.ts +0 -27
  30. package/dist/qaid.umd.cjs +14 -14
  31. package/dist/qaid.umd.cjs.map +1 -1
  32. package/dist/quest-config.d.ts +2 -0
  33. package/dist/quest-launcher.d.ts +1 -3
  34. package/dist/send.d.ts +60 -0
  35. package/dist/tooltip-positioning.d.ts +31 -0
  36. package/package.json +1 -1
  37. package/dist/chunks/annotate-5zJWs-aB.js +0 -357
  38. package/dist/chunks/core-CL1dwdaN.js +0 -1342
  39. package/dist/chunks/core-CL1dwdaN.js.map +0 -1
  40. package/dist/chunks/dom-DvdtcUS8.js +0 -17
  41. package/dist/chunks/modal-DccueVYZ.js +0 -222
  42. package/dist/chunks/modal-DccueVYZ.js.map +0 -1
  43. package/dist/chunks/recording-CPzxRL7f.js +0 -323
  44. package/dist/chunks/screenshot-DYOKg2bS.js +0 -33
  45. package/dist/chunks/screenshot-dom-CME7tYRE.js +0 -63
  46. package/dist/chunks/targeting-mahtuPpo.js +0 -298
  47. package/dist/chunks/video-Bd_29-rK.js +0 -214
@@ -0,0 +1,2 @@
1
+ /** Default ES-module URL for the quests widget, pinned to a compatible major on unpkg. */
2
+ export declare const DEFAULT_QUESTS_MODULE_URL = "https://unpkg.com/@qaiddev/quests-embed@1/dist/qaid-quests.js";
@@ -10,8 +10,7 @@
10
10
  * modelled here structurally, so a version bump of the quests package that
11
11
  * keeps this surface stable needs no change in thumbs-embed.
12
12
  */
13
- /** Default ES-module URL, pinned to a compatible major on unpkg. */
14
- export declare const DEFAULT_QUESTS_MODULE_URL = "https://unpkg.com/@qaiddev/quests-embed@1/dist/qaid-quests.js";
13
+ export { DEFAULT_QUESTS_MODULE_URL } from "./quest-config";
15
14
  /** The bit of a QaidQuests instance we hold onto. */
16
15
  export interface QuestInstance {
17
16
  destroy(): void;
@@ -83,4 +82,3 @@ export interface LaunchQuestOptions {
83
82
  * caller should fall back to its normal UI.
84
83
  */
85
84
  export declare function launchQuest(opts: LaunchQuestOptions): Promise<QuestInstance>;
86
- export {};
package/dist/send.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The feedback send flow — extracted from embed.ts into its own lazily-loaded
3
+ * chunk. It runs only after a thumb click (or a targeted element), so it is
4
+ * pre-warmed when the pointer or focus reaches the buttons, or on idle,
5
+ * whichever comes first.
6
+ *
7
+ * It captures (and lets the visitor mark up) a screenshot when configured,
8
+ * POSTs the feedback, then opens the linked quest or the message box. It talks
9
+ * back to the embed through the narrow `SendHost` interface.
10
+ */
11
+ import { type QuestInstance } from "./quest-launcher";
12
+ import type { ModalController } from "./modal";
13
+ import type { ResolvedFeedbackConfig, EmbedState, FeedbackData, SelectedBounds } from "./types";
14
+ /** The slice of the embed the send flow needs. */
15
+ export interface SendHost {
16
+ readonly config: ResolvedFeedbackConfig;
17
+ readonly visitorId: string;
18
+ /** Live references, filled in by the click or the targeting controller. */
19
+ readonly feedbackData: FeedbackData;
20
+ readonly selectedBounds: SelectedBounds;
21
+ readonly destroyed: boolean;
22
+ readonly overlayShadowHost: HTMLDivElement | null;
23
+ /** A quest launched from a button, so destroy() can tear it down. */
24
+ activeQuest: QuestInstance | null;
25
+ setState(state: EmbedState): void;
26
+ /** Record the pending POST, which the message box's PATCHes wait on. */
27
+ setFeedbackId(id: Promise<number | null>): void;
28
+ shouldCaptureViaDom(): boolean;
29
+ ensureOverlayHost(): ShadowRoot;
30
+ ensureModal(): Promise<ModalController>;
31
+ addFeatureStyles(css: string): void;
32
+ applyVars(el: HTMLElement): void;
33
+ announceMsg(message: string, assertive?: boolean): void;
34
+ openDialogA11y(container: HTMLElement, opts: {
35
+ labelledbyId?: string;
36
+ describedbyId?: string;
37
+ label?: string;
38
+ }): void;
39
+ closeDialogA11y(): void;
40
+ resetFeedbackUi(): void;
41
+ }
42
+ /**
43
+ * Open the full-screen annotation editor over the captured screenshot,
44
+ * reusing the overlay shadow host and the shared dialog a11y helpers.
45
+ * Resolves with the composited WebP data URL, or null when the user skips
46
+ * (caller keeps the original). Pointer events on the overlay host are
47
+ * enabled while the editor is open and restored on close.
48
+ */
49
+ export declare function openAnnotationEditor(host: SendHost, screenshot: string): Promise<string | null>;
50
+ /** Capture, POST, then hand off to a linked quest or the message box. */
51
+ export declare function submitFeedback(host: SendHost): Promise<void>;
52
+ /**
53
+ * Launch the quest linked to `type`, if any. Resolves `true` when a quest
54
+ * was configured and the widget launched; `false` when no quest is
55
+ * configured (quest launching off: no `base`, or this button has no quest)
56
+ * or the widget failed to load (caller falls back to its normal UI). The
57
+ * created feedback record id is passed through so the quest response can be
58
+ * joined back to it server-side.
59
+ */
60
+ export declare function tryLaunchQuest(host: SendHost, type: "up" | "down" | "video", feedbackId: number | string | null | Promise<number | string | null>): Promise<boolean>;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Tooltip positioning. Kept apart from modal-positioning so the startup chunk
3
+ * carries only this, and the modal maths travels with the modal chunk.
4
+ */
5
+ export interface TooltipPositionOptions {
6
+ /** Gap in pixels between anchor and tooltip, and from viewport edges */
7
+ gap?: number;
8
+ }
9
+ /**
10
+ * Calculate tooltip position relative to an anchor, clamped to the viewport.
11
+ * Pure function: no DOM access — caller passes measured rects and viewport size.
12
+ *
13
+ * Strategy:
14
+ * - Place below the anchor by default
15
+ * - Flip above if below would overflow vertically
16
+ * - Clamp horizontally to viewport, then vertically to viewport
17
+ */
18
+ export declare function calculateTooltipPosition(anchor: {
19
+ top: number;
20
+ bottom: number;
21
+ left: number;
22
+ }, tooltip: {
23
+ width: number;
24
+ height: number;
25
+ }, viewport: {
26
+ width: number;
27
+ height: number;
28
+ }, options?: TooltipPositionOptions): {
29
+ top: number;
30
+ left: number;
31
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qaiddev/thumbs-embed",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "description": "Precision User Feedback",
5
5
  "type": "module",
6
6
  "main": "./dist/qaid.umd.cjs",
@@ -1,357 +0,0 @@
1
- import { c as r, R as v, A as m, P as q, B as y, U as k, S as x, D as C } from "./core-CL1dwdaN.js";
2
- const E = ".qaid-annotate{position:fixed;inset:0;z-index:2147483000;display:flex;flex-direction:column;gap:.75rem;padding:16px;padding-top:max(16px,env(safe-area-inset-top));padding-bottom:max(16px,env(safe-area-inset-bottom));box-sizing:border-box;background:#000000d9;font-family:var(--qaid-font-family, system-ui, -apple-system, sans-serif);font-size:var(--qaid-font-size, 16px);animation:qaid-fadeIn .2s ease-out}.qaid-annotate-title{margin:0;font-size:var(--qaid-font-size, 16px);font-weight:700;text-align:center;color:#f9fafb}.qaid-annotate-desc{margin:0;font-size:calc(var(--qaid-font-size, 16px) * .8125);line-height:1.4;text-align:center;color:#f9fafbbf}.qaid-annotate-stage{flex:1 1 auto;min-height:0;display:flex;align-items:center;justify-content:center;overflow:auto}.qaid-annotate-canvas{max-width:100%;max-height:100%;object-fit:contain;background:light-dark(#ffffff,#111827);border-radius:.5rem;box-shadow:0 10px 30px #00000080;touch-action:none;cursor:crosshair}.qaid-annotate-toolbar{display:flex;flex-wrap:wrap;gap:.75rem;align-items:center;justify-content:center;padding:.5rem .75rem;background:light-dark(#ffffff,#1f2937);border-radius:.75rem;box-shadow:0 10px 30px light-dark(rgba(0,0,0,.25),rgba(0,0,0,.5))}.qaid-annotate-tools,.qaid-annotate-actions{display:flex;gap:.375rem;align-items:center}button.qaid-annotate-tool,button.qaid-annotate-action{display:inline-flex;align-items:center;justify-content:center;gap:.375rem;min-width:44px;min-height:44px;padding:0 .75rem;border:1px solid light-dark(#d1d5db,#374151);border-radius:.5rem;background:light-dark(#f9fafb,#111827);color:light-dark(#1f2937,#f9fafb);font-family:inherit;font-size:calc(var(--qaid-font-size, 16px) * .8125);font-weight:600;cursor:pointer;-webkit-appearance:none;appearance:none;transition:background-color .15s,color .15s,border-color .15s,filter .15s}button.qaid-annotate-tool svg,button.qaid-annotate-action svg{width:20px;height:20px}.qaid-annotate-colors{display:flex;gap:.25rem;align-items:center}button.qaid-annotate-swatch{width:28px;height:28px;min-width:28px;padding:0;border-radius:9999px;border:2px solid light-dark(#d1d5db,#4b5563);background:var(--qaid-swatch, #000);cursor:pointer;-webkit-appearance:none;appearance:none;transition:transform .1s,box-shadow .15s,border-color .15s}button.qaid-annotate-swatch:hover{transform:scale(1.12)}button.qaid-annotate-swatch[aria-pressed=true]{border-color:light-dark(#111827,#f9fafb);box-shadow:0 0 0 2px var(--qaid-swatch)}@media(forced-colors:active){button.qaid-annotate-swatch[aria-pressed=true]{outline:2px solid Highlight;outline-offset:1px}}button.qaid-annotate-tool:hover,button.qaid-annotate-action:hover{background:light-dark(#eef2ff,#312e81)}button.qaid-annotate-tool[aria-pressed=true],button.qaid-annotate-done{background:var(--qaid-marker, #6365f1);color:var(--qaid-marker-text, #fff);border-color:var(--qaid-marker, #6365f1)}button.qaid-annotate-done:hover{filter:brightness(.9);background:var(--qaid-marker, #6365f1)}button.qaid-annotate-action:disabled{opacity:.45;cursor:not-allowed}@media(forced-colors:active){button.qaid-annotate-tool[aria-pressed=true],button.qaid-annotate-done{border:2px solid Highlight}.qaid-annotate-canvas{border:1px solid CanvasText}}@keyframes qaid-fadeIn{0%{opacity:0}to{opacity:1}}", d = 12, L = "#ef4444", A = ["#ef4444", "#f59e0b", "#22c55e", "#3b82f6", "#111827", "#ffffff"], I = {
3
- "#ef4444": "red",
4
- "#f59e0b": "amber",
5
- "#22c55e": "green",
6
- "#3b82f6": "blue",
7
- "#111827": "black",
8
- "#ffffff": "white",
9
- // The default marker (nudged from #6366f1 so white text on it clears 4.5:1);
10
- // the old value keeps its name for sites that pass it explicitly.
11
- "#6365f1": "indigo",
12
- "#6366f1": "indigo"
13
- };
14
- function f(a) {
15
- return I[a.toLowerCase()] ?? a;
16
- }
17
- const T = 4, B = 0.8, D = {
18
- title: "Annotate screenshot",
19
- instructions: "Draw on the screenshot to highlight or hide details, then choose Done to attach it or Skip to send the original.",
20
- rectangle: "Rectangle",
21
- arrow: "Arrow",
22
- pen: "Pen",
23
- blur: "Blur or redact",
24
- undo: "Undo last",
25
- skip: "Skip annotation",
26
- done: "Done",
27
- colors: "Drawing colour"
28
- };
29
- function u(a, t) {
30
- return {
31
- x: Math.min(a.x, t.x),
32
- y: Math.min(a.y, t.y),
33
- w: Math.abs(a.x - t.x),
34
- h: Math.abs(a.y - t.y)
35
- };
36
- }
37
- function P(a) {
38
- if (a.type === "pen") return a.points.length < 2;
39
- const t = u(a.points[0], a.points[1]);
40
- return t.w < 3 && t.h < 3;
41
- }
42
- function M(a, t, e, n) {
43
- a.beginPath(), a.moveTo(t.x, t.y), a.lineTo(e.x, e.y), a.stroke();
44
- const o = Math.atan2(e.y - t.y, e.x - t.x), i = Math.max(10, n * 3);
45
- a.beginPath(), a.moveTo(e.x, e.y), a.lineTo(
46
- e.x - i * Math.cos(o - Math.PI / 6),
47
- e.y - i * Math.sin(o - Math.PI / 6)
48
- ), a.moveTo(e.x, e.y), a.lineTo(
49
- e.x - i * Math.cos(o + Math.PI / 6),
50
- e.y - i * Math.sin(o + Math.PI / 6)
51
- ), a.stroke();
52
- }
53
- function R(a, t) {
54
- if (t.length !== 0) {
55
- a.beginPath(), a.moveTo(t[0].x, t[0].y);
56
- for (let e = 1; e < t.length; e++)
57
- a.lineTo(t[e].x, t[e].y);
58
- a.stroke();
59
- }
60
- }
61
- function S(a, t, e, n, o) {
62
- a.fillStyle = "rgb(15, 23, 42)", a.fillRect(t, e, n, o), a.fillStyle = "rgb(37, 47, 63)";
63
- for (let i = e; i < e + o; i += d)
64
- for (let s = t; s < t + n; s += d)
65
- (Math.floor((s - t) / d) + Math.floor((i - e) / d)) % 2 === 0 && a.fillRect(
66
- s,
67
- i,
68
- Math.min(d, t + n - s),
69
- Math.min(d, e + o - i)
70
- );
71
- }
72
- function p(a, t) {
73
- switch (a.save(), a.strokeStyle = t.color, a.fillStyle = t.color, a.lineWidth = t.strokeWidth, a.lineJoin = "round", a.lineCap = "round", t.type) {
74
- case "rect": {
75
- const e = u(t.points[0], t.points[1]);
76
- a.strokeRect(e.x, e.y, e.w, e.h);
77
- break;
78
- }
79
- case "arrow":
80
- M(a, t.points[0], t.points[1], t.strokeWidth);
81
- break;
82
- case "pen":
83
- R(a, t.points);
84
- break;
85
- case "blur": {
86
- const e = u(t.points[0], t.points[1]);
87
- S(a, e.x, e.y, e.w, e.h);
88
- break;
89
- }
90
- }
91
- a.restore();
92
- }
93
- function b(a) {
94
- return new Promise((t, e) => {
95
- const n = new Image();
96
- n.onload = () => t(n), n.onerror = () => e(new Error("Failed to load screenshot")), n.src = a;
97
- });
98
- }
99
- async function _(a, t, e = {}) {
100
- const n = e.quality ?? B;
101
- let o;
102
- try {
103
- o = await b(a);
104
- } catch {
105
- return a;
106
- }
107
- const i = document.createElement("canvas");
108
- i.width = o.naturalWidth || o.width || 1, i.height = o.naturalHeight || o.height || 1;
109
- const s = i.getContext("2d");
110
- if (!s) return a;
111
- s.drawImage(o, 0, 0, i.width, i.height);
112
- for (const h of t)
113
- p(s, h);
114
- return i.toDataURL("image/webp", n);
115
- }
116
- let N = 0;
117
- class U {
118
- shapes = [];
119
- tool = "rect";
120
- opts;
121
- labels;
122
- color;
123
- palette;
124
- strokeWidth;
125
- uid = `qaid-annotate-${++N}`;
126
- container;
127
- canvas;
128
- ctx = null;
129
- toolbar;
130
- undoBtn;
131
- img = null;
132
- drawing = !1;
133
- current = null;
134
- settled = !1;
135
- // Assigned in open() before any settle() is reachable (done/skip only fire
136
- // after the editor is mounted).
137
- resolveResult;
138
- constructor(t) {
139
- this.opts = t, this.labels = { ...D, ...t.labels ?? {} }, this.color = t.color ?? L, this.palette = (t.palette && t.palette.length ? t.palette : A).slice(), this.palette.some((e) => e.toLowerCase() === this.color.toLowerCase()) || this.palette.unshift(this.color), this.strokeWidth = t.strokeWidth ?? T;
140
- }
141
- /** Mount the editor and resolve when the user commits (Done) or skips. */
142
- open() {
143
- const t = new Promise((e) => {
144
- this.resolveResult = e;
145
- });
146
- return this.mount(), t;
147
- }
148
- toolButton(t, e, n) {
149
- const o = r("button", {
150
- type: "button",
151
- class: "qaid-annotate-tool",
152
- "data-qaid-tool": t,
153
- "aria-pressed": t === this.tool ? "true" : "false",
154
- "aria-label": `${n} tool`,
155
- title: n
156
- });
157
- return o.innerHTML = `${e}<span class="qaid-annotate-btn-text">${n}</span>`, o;
158
- }
159
- /** A round colour swatch button for the toolbar's colour group. */
160
- swatchButton(t) {
161
- const e = f(t), n = r("button", {
162
- type: "button",
163
- class: "qaid-annotate-swatch",
164
- "data-qaid-color": t,
165
- "aria-pressed": t.toLowerCase() === this.color.toLowerCase() ? "true" : "false",
166
- "aria-label": `Draw in ${e}`,
167
- title: e
168
- });
169
- return n.style.setProperty("--qaid-swatch", t), n;
170
- }
171
- actionButton(t, e, n, o) {
172
- const i = r("button", {
173
- type: "button",
174
- class: `qaid-annotate-action ${o}`,
175
- "data-qaid-action": t,
176
- "aria-label": n,
177
- title: n
178
- });
179
- return i.innerHTML = `${e}<span class="qaid-annotate-btn-text">${n}</span>`, i;
180
- }
181
- mount() {
182
- const t = `${this.uid}-title`, e = `${this.uid}-desc`;
183
- this.container = r("div", { class: "qaid-annotate" }), this.opts.applyVars?.(this.container);
184
- const n = r("h2", {
185
- id: t,
186
- class: "qaid-annotate-title"
187
- });
188
- n.textContent = this.labels.title;
189
- const o = r("p", {
190
- id: e,
191
- class: "qaid-annotate-desc"
192
- });
193
- o.textContent = this.labels.instructions;
194
- const i = r("div", { class: "qaid-annotate-stage" });
195
- this.canvas = document.createElement("canvas"), this.canvas.className = "qaid-annotate-canvas", this.canvas.width = 1, this.canvas.height = 1, this.canvas.setAttribute("role", "img"), this.canvas.setAttribute("aria-label", this.labels.title), this.ctx = this.canvas.getContext("2d"), i.appendChild(this.canvas), this.toolbar = r("div", {
196
- class: "qaid-annotate-toolbar",
197
- role: "toolbar",
198
- "aria-label": this.labels.title
199
- });
200
- const s = r("div", { class: "qaid-annotate-tools" });
201
- s.appendChild(this.toolButton("rect", v, this.labels.rectangle)), s.appendChild(this.toolButton("arrow", m, this.labels.arrow)), s.appendChild(this.toolButton("pen", q, this.labels.pen)), s.appendChild(this.toolButton("blur", y, this.labels.blur));
202
- const h = r("div", {
203
- class: "qaid-annotate-colors",
204
- role: "group",
205
- "aria-label": this.labels.colors
206
- });
207
- for (const l of this.palette) h.appendChild(this.swatchButton(l));
208
- this.undoBtn = this.actionButton("undo", k, this.labels.undo, "qaid-annotate-undo"), this.undoBtn.disabled = !0;
209
- const g = this.actionButton("skip", x, this.labels.skip, "qaid-annotate-skip"), w = this.actionButton("done", C, this.labels.done, "qaid-annotate-done"), c = r("div", { class: "qaid-annotate-actions" });
210
- c.appendChild(this.undoBtn), c.appendChild(g), c.appendChild(w), this.toolbar.appendChild(s), this.toolbar.appendChild(h), this.toolbar.appendChild(c), this.container.appendChild(n), this.container.appendChild(o), this.container.appendChild(i), this.container.appendChild(this.toolbar), this.opts.root.appendChild(this.container), this.toolbar.addEventListener("click", this.onToolbarClick), this.canvas.addEventListener("pointerdown", this.onPointerDown), this.container.addEventListener("pointermove", this.onPointerMove), this.container.addEventListener("pointerup", this.onPointerUp), this.container.addEventListener("keydown", this.onKeyDown), this.opts.openDialog?.(this.container, {
211
- labelledbyId: t,
212
- describedbyId: e
213
- }), this.opts.announce?.(this.labels.instructions), b(this.opts.dataUrl).then((l) => {
214
- this.img = l, this.canvas.width = l.naturalWidth || l.width || 1, this.canvas.height = l.naturalHeight || l.height || 1, this.redraw();
215
- }).catch(() => {
216
- this.img = null, this.redraw();
217
- });
218
- }
219
- /** Convert a pointer event's client coordinates into natural image pixels. */
220
- toImageCoords(t) {
221
- const e = this.canvas.getBoundingClientRect(), n = this.canvas.width / (e.width || this.canvas.width), o = this.canvas.height / (e.height || this.canvas.height);
222
- return {
223
- x: (t.clientX - e.left) * n,
224
- y: (t.clientY - e.top) * o
225
- };
226
- }
227
- /** Repaint the display canvas: base image (if loaded) then every shape. */
228
- redraw() {
229
- const t = this.ctx;
230
- if (t) {
231
- t.clearRect(0, 0, this.canvas.width, this.canvas.height), this.img && t.drawImage(this.img, 0, 0, this.canvas.width, this.canvas.height);
232
- for (const e of this.shapes)
233
- p(t, e);
234
- this.current && p(t, this.current);
235
- }
236
- }
237
- /** Select the active drawing tool and reflect it on the toolbar. */
238
- selectTool(t) {
239
- this.tool = t, this.toolbar.querySelectorAll("[data-qaid-tool]").forEach((o) => {
240
- o.setAttribute(
241
- "aria-pressed",
242
- o.getAttribute("data-qaid-tool") === t ? "true" : "false"
243
- );
244
- });
245
- const n = this.labels[O[t]];
246
- this.opts.announce?.(`${n} tool selected`);
247
- }
248
- /** Set the active drawing colour; subsequent shapes use it. */
249
- selectColor(t) {
250
- this.color = t, this.toolbar.querySelectorAll("[data-qaid-color]").forEach((n) => {
251
- n.setAttribute(
252
- "aria-pressed",
253
- (n.getAttribute("data-qaid-color") ?? "").toLowerCase() === t.toLowerCase() ? "true" : "false"
254
- );
255
- }), this.opts.announce?.(`${f(t)} colour selected`);
256
- }
257
- onToolbarClick = (t) => {
258
- const n = t.target?.closest(
259
- "[data-qaid-tool],[data-qaid-action],[data-qaid-color]"
260
- );
261
- if (!n) return;
262
- const o = n.getAttribute("data-qaid-color");
263
- if (o) {
264
- this.selectColor(o);
265
- return;
266
- }
267
- const i = n.getAttribute("data-qaid-tool");
268
- if (i) {
269
- this.selectTool(i);
270
- return;
271
- }
272
- const s = n.getAttribute("data-qaid-action");
273
- s === "undo" ? this.undo() : s === "skip" ? this.skip() : s === "done" && this.done();
274
- };
275
- onPointerDown = (t) => {
276
- t.preventDefault?.(), this.drawing = !0;
277
- const e = this.toImageCoords(t);
278
- this.current = {
279
- type: this.tool,
280
- color: this.color,
281
- strokeWidth: this.strokeWidth,
282
- points: this.tool === "pen" ? [e] : [e, { ...e }]
283
- }, this.redraw();
284
- };
285
- onPointerMove = (t) => {
286
- if (!this.drawing || !this.current) return;
287
- const e = this.toImageCoords(t);
288
- this.current.type === "pen" ? this.current.points.push(e) : this.current.points[1] = e, this.redraw();
289
- };
290
- onPointerUp = () => {
291
- if (!this.drawing || !this.current) return;
292
- this.drawing = !1;
293
- const t = this.current;
294
- if (this.current = null, P(t)) {
295
- this.redraw();
296
- return;
297
- }
298
- this.shapes.push(t), this.undoBtn.disabled = !1, this.opts.announce?.("Annotation added"), this.redraw();
299
- };
300
- onKeyDown = (t) => {
301
- if (t.key === "Escape") {
302
- t.preventDefault(), this.skip();
303
- return;
304
- }
305
- if (t.key === "Enter") {
306
- const e = t.target;
307
- if (e?.getAttribute("data-qaid-tool") || e?.getAttribute("data-qaid-action"))
308
- return;
309
- t.preventDefault(), this.done();
310
- }
311
- };
312
- /** Remove the most recently added shape. */
313
- undo() {
314
- if (this.shapes.length === 0) {
315
- this.opts.announce?.("Nothing to undo");
316
- return;
317
- }
318
- this.shapes.pop(), this.undoBtn.disabled = this.shapes.length === 0, this.opts.announce?.("Removed last annotation"), this.redraw();
319
- }
320
- /** Composite the annotations and resolve with the new WebP data URL. */
321
- async done() {
322
- if (this.settled) return;
323
- const t = await _(this.opts.dataUrl, this.shapes, {
324
- quality: this.opts.quality
325
- });
326
- this.opts.announce?.("Annotated screenshot attached"), this.settle(t);
327
- }
328
- /** Discard annotations and resolve with `null` (caller keeps the original). */
329
- skip() {
330
- this.settled || (this.opts.announce?.("Annotation skipped"), this.settle(null));
331
- }
332
- settle(t) {
333
- this.settled = !0, this.teardown(), this.resolveResult(t);
334
- }
335
- teardown() {
336
- this.toolbar.removeEventListener("click", this.onToolbarClick), this.canvas.removeEventListener("pointerdown", this.onPointerDown), this.container.removeEventListener("pointermove", this.onPointerMove), this.container.removeEventListener("pointerup", this.onPointerUp), this.container.removeEventListener("keydown", this.onKeyDown), this.opts.closeDialog?.(), this.container.remove();
337
- }
338
- }
339
- const O = {
340
- rect: "rectangle",
341
- arrow: "arrow",
342
- pen: "pen",
343
- blur: "blur"
344
- };
345
- function $(a) {
346
- return new U(a).open();
347
- }
348
- const z = E;
349
- export {
350
- U as AnnotationEditor,
351
- _ as compositeAnnotations,
352
- p as drawShape,
353
- $ as openAnnotationEditor,
354
- u as rectFromPoints,
355
- z as styles
356
- };
357
- //# sourceMappingURL=annotate-5zJWs-aB.js.map