@trungtnm/agent-annotator 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +215 -2
- package/dist/index.d.ts +232 -0
- package/dist/index.js +4054 -0
- package/dist/index.js.map +1 -0
- package/package.json +78 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,4054 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// src/annotator.tsx
|
|
4
|
+
import { useCallback, useEffect as useEffect3, useMemo, useRef as useRef3, useState as useState3 } from "react";
|
|
5
|
+
import { createPortal } from "react-dom";
|
|
6
|
+
|
|
7
|
+
// src/redaction.ts
|
|
8
|
+
var REDACTED = "[redacted]";
|
|
9
|
+
var COUNTRY_RULES = {
|
|
10
|
+
vn: {
|
|
11
|
+
label: "Vietnam",
|
|
12
|
+
covers: "phone numbers, 12-digit citizen IDs (CCCD)",
|
|
13
|
+
keys: [/cccd|cmnd|zalo/],
|
|
14
|
+
values: [
|
|
15
|
+
// +84 or 0, then 9–10 digits, optionally grouped by spaces or dots.
|
|
16
|
+
/(?<!\d)(?:\+?84|0)(?:[\s.]?\d){9,10}(?!\d)/g,
|
|
17
|
+
// CCCD: 12 digits, starting with the 0 of a province code.
|
|
18
|
+
/(?<!\d)0\d{11}(?!\d)/g
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
us: {
|
|
22
|
+
label: "United States",
|
|
23
|
+
covers: "phone numbers, Social Security numbers written with dashes",
|
|
24
|
+
// `ssn` only at either end of the key: in the middle it is "claSSName".
|
|
25
|
+
keys: [/^ssn|ssn$|socialsecurity/],
|
|
26
|
+
values: [
|
|
27
|
+
// SSN with its dashes, minus the ranges never issued.
|
|
28
|
+
/(?<!\d)(?!000|666|9\d\d)\d{3}-(?!00)\d{2}-(?!0000)\d{4}(?!\d)/g,
|
|
29
|
+
// NANP: optional +1, area code and exchange each starting 2–9, then 4 digits.
|
|
30
|
+
/(?<![\d+])(?:\+1[\s.-]?)?(?:\([2-9]\d{2}\)\s?|[2-9]\d{2}[\s.-]?)[2-9]\d{2}[\s.-]?\d{4}(?!\d)/g
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
sg: {
|
|
34
|
+
label: "Singapore",
|
|
35
|
+
covers: "phone numbers with +65 or a space or dash, NRIC/FIN numbers",
|
|
36
|
+
keys: [/nric/],
|
|
37
|
+
values: [
|
|
38
|
+
/\b[STFGM]\d{7}[A-Z]\b/g,
|
|
39
|
+
// 8 digits starting 3, 6, 8 or 9: with +65, or split 4-4, so a bare amount survives.
|
|
40
|
+
/(?<!\d)(?:\+65[\s-]?[3689]\d{3}[\s-]?\d{4}|[3689]\d{3}[\s-]\d{4})(?!\d)/g
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var COUNTRIES = Object.keys(COUNTRY_RULES);
|
|
45
|
+
var DEFAULT_REDACTION = { enabled: true, countries: ["vn"], patterns: [] };
|
|
46
|
+
var SHARED_KEY = /(nationalid|citizenid|identitynumber|idnumber|idcard|passport|phone|mobile|msisdn|email|fullname|(debtor|borrower|customer|guarantor|contact|person|holder|relative|spouse|recipient|payer)name|address|dob|dateofbirth|birthday|birthdate|bankaccount|accountnumber|cardnumber|password|passwd|secret|token|otp|apikey|authorization|cookie|signature)/;
|
|
47
|
+
var EMAIL = /[^\s@<>()[\]"']+@[^\s@<>()[\]"']+\.[a-z]{2,}/gi;
|
|
48
|
+
function createRedactor(settings) {
|
|
49
|
+
if (!settings.enabled) return { enabled: false, isPiiKey: () => false, text: (text) => text };
|
|
50
|
+
const rules = settings.countries.map((country) => COUNTRY_RULES[country]);
|
|
51
|
+
const keys = [SHARED_KEY, ...rules.flatMap((rule) => rule.keys)];
|
|
52
|
+
const values = [
|
|
53
|
+
EMAIL,
|
|
54
|
+
...rules.flatMap((rule) => rule.values),
|
|
55
|
+
...settings.patterns.filter((source) => source.trim() !== "").map((source) => compilePattern(source)).filter((pattern) => pattern instanceof RegExp)
|
|
56
|
+
];
|
|
57
|
+
return {
|
|
58
|
+
enabled: true,
|
|
59
|
+
isPiiKey: (key) => {
|
|
60
|
+
const normalised = key.toLowerCase().replace(/[\s_-]/g, "");
|
|
61
|
+
return keys.some((pattern) => pattern.test(normalised));
|
|
62
|
+
},
|
|
63
|
+
text: (text) => values.reduce((out, pattern) => out.replace(pattern, REDACTED), text)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
var DEFAULT_REDACTOR = createRedactor(DEFAULT_REDACTION);
|
|
67
|
+
function compilePattern(source) {
|
|
68
|
+
const literal = /^\/(.+)\/([a-z]*)$/s.exec(source);
|
|
69
|
+
const body = literal?.[1] ?? source;
|
|
70
|
+
const flags = new Set(literal?.[2] ?? "");
|
|
71
|
+
flags.add("g");
|
|
72
|
+
let pattern;
|
|
73
|
+
try {
|
|
74
|
+
pattern = new RegExp(body, [...flags].join(""));
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return error instanceof Error ? error.message : "Invalid pattern";
|
|
77
|
+
}
|
|
78
|
+
if (pattern.test("")) return "Matches empty text";
|
|
79
|
+
pattern.lastIndex = 0;
|
|
80
|
+
return pattern;
|
|
81
|
+
}
|
|
82
|
+
function resolveRedaction(options) {
|
|
83
|
+
return {
|
|
84
|
+
enabled: options?.enabled ?? DEFAULT_REDACTION.enabled,
|
|
85
|
+
countries: (options?.countries ?? DEFAULT_REDACTION.countries).filter((country) => country in COUNTRY_RULES),
|
|
86
|
+
patterns: (options?.patterns ?? DEFAULT_REDACTION.patterns).map(
|
|
87
|
+
(pattern) => typeof pattern === "string" ? pattern : `/${pattern.source}/${pattern.flags.replace("g", "")}`
|
|
88
|
+
)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function readRedaction(key) {
|
|
92
|
+
try {
|
|
93
|
+
const raw = window.localStorage.getItem(key);
|
|
94
|
+
if (raw === null) return null;
|
|
95
|
+
const value = JSON.parse(raw);
|
|
96
|
+
if (typeof value.enabled !== "boolean" || !Array.isArray(value.countries) || !Array.isArray(value.patterns)) return null;
|
|
97
|
+
return {
|
|
98
|
+
enabled: value.enabled,
|
|
99
|
+
countries: value.countries.filter((country) => typeof country === "string" && country in COUNTRY_RULES),
|
|
100
|
+
patterns: value.patterns.filter((pattern) => typeof pattern === "string")
|
|
101
|
+
};
|
|
102
|
+
} catch {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function writeRedaction(key, settings) {
|
|
107
|
+
try {
|
|
108
|
+
if (settings === null) window.localStorage.removeItem(key);
|
|
109
|
+
else window.localStorage.setItem(key, JSON.stringify(settings));
|
|
110
|
+
} catch {
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/serialize.ts
|
|
115
|
+
var DEFAULT_LIMITS = { depth: 4, keys: 25, items: 5, string: 160 };
|
|
116
|
+
var SKIPPED_KEYS = /* @__PURE__ */ new Set(["children", "ref", "key", "$$typeof", "_owner", "_store"]);
|
|
117
|
+
var REACT_ELEMENT_TYPES = /* @__PURE__ */ new Set([/* @__PURE__ */ Symbol.for("react.transitional.element"), /* @__PURE__ */ Symbol.for("react.element")]);
|
|
118
|
+
function toSnapshot(value, limits = DEFAULT_LIMITS, redactor = DEFAULT_REDACTOR) {
|
|
119
|
+
return walk(value, 0, { limits, redactor }, /* @__PURE__ */ new Set());
|
|
120
|
+
}
|
|
121
|
+
function walk(value, depth, walker, path) {
|
|
122
|
+
const { limits, redactor } = walker;
|
|
123
|
+
switch (typeof value) {
|
|
124
|
+
case "undefined":
|
|
125
|
+
return "<undefined>";
|
|
126
|
+
case "boolean":
|
|
127
|
+
return value;
|
|
128
|
+
case "number":
|
|
129
|
+
return Number.isFinite(value) ? value : String(value);
|
|
130
|
+
case "bigint":
|
|
131
|
+
return `${value}n`;
|
|
132
|
+
case "string":
|
|
133
|
+
return truncate(redactor.text(value), limits.string);
|
|
134
|
+
case "symbol":
|
|
135
|
+
return value.toString();
|
|
136
|
+
case "function":
|
|
137
|
+
return `\u0192 ${value.name || "anonymous"}()`;
|
|
138
|
+
default:
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
if (value === null) return null;
|
|
142
|
+
const object = value;
|
|
143
|
+
if (path.has(object)) return "<circular>";
|
|
144
|
+
const summary = summarise(object, redactor);
|
|
145
|
+
if (summary !== null) return summary;
|
|
146
|
+
path.add(object);
|
|
147
|
+
try {
|
|
148
|
+
if (Array.isArray(object)) return walkList(object, object.length, depth, walker, path);
|
|
149
|
+
if (object instanceof Set) return { "<Set>": walkList([...object], object.size, depth, walker, path) };
|
|
150
|
+
if (object instanceof Map) {
|
|
151
|
+
if (depth >= limits.depth) return `<Map(${object.size})>`;
|
|
152
|
+
const entries = {};
|
|
153
|
+
let kept = 0;
|
|
154
|
+
for (const [key, entry] of object) {
|
|
155
|
+
if (kept === limits.items) {
|
|
156
|
+
entries["\u2026"] = `+${object.size - kept}`;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
const name = typeof key === "string" ? key : String(walk(key, limits.depth, walker, path));
|
|
160
|
+
entries[name] = redactor.isPiiKey(name) ? redactWhole(entry) : walk(entry, depth + 1, walker, path);
|
|
161
|
+
kept += 1;
|
|
162
|
+
}
|
|
163
|
+
return { "<Map>": entries };
|
|
164
|
+
}
|
|
165
|
+
return walkObject(object, depth, walker, path);
|
|
166
|
+
} finally {
|
|
167
|
+
path.delete(object);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function walkList(items, size, depth, walker, path) {
|
|
171
|
+
const { limits } = walker;
|
|
172
|
+
if (depth >= limits.depth) return `<Array(${size})>`;
|
|
173
|
+
const kept = items.slice(0, limits.items).map((item) => walk(item, depth + 1, walker, path));
|
|
174
|
+
return size > limits.items ? [...kept, `\u2026 +${size - limits.items}`] : kept;
|
|
175
|
+
}
|
|
176
|
+
function walkObject(object, depth, walker, path) {
|
|
177
|
+
const { limits, redactor } = walker;
|
|
178
|
+
const keys = Object.keys(object).filter((key) => !SKIPPED_KEYS.has(key) && !key.startsWith("__react"));
|
|
179
|
+
if (depth >= limits.depth) return keys.length === 0 ? {} : `{\u2026${keys.length} keys}`;
|
|
180
|
+
const out = {};
|
|
181
|
+
for (const key of keys.slice(0, limits.keys)) {
|
|
182
|
+
let entry;
|
|
183
|
+
try {
|
|
184
|
+
entry = object[key];
|
|
185
|
+
} catch {
|
|
186
|
+
out[key] = "<getter threw>";
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
out[key] = redactor.isPiiKey(key) ? redactWhole(entry) : walk(entry, depth + 1, walker, path);
|
|
190
|
+
}
|
|
191
|
+
if (keys.length > limits.keys) out["\u2026"] = `+${keys.length - limits.keys} keys`;
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
function redactWhole(value) {
|
|
195
|
+
if (value === null) return null;
|
|
196
|
+
if (value === void 0) return "<undefined>";
|
|
197
|
+
if (value === "") return "";
|
|
198
|
+
return REDACTED;
|
|
199
|
+
}
|
|
200
|
+
function summarise(object, redactor) {
|
|
201
|
+
if (REACT_ELEMENT_TYPES.has(object.$$typeof)) {
|
|
202
|
+
return `<${typeName(object.type)} />`;
|
|
203
|
+
}
|
|
204
|
+
if (object instanceof Date) return Number.isNaN(object.getTime()) ? "<Invalid Date>" : object.toISOString();
|
|
205
|
+
if (object instanceof Error) return `<${object.name}: ${truncate(redactor.text(object.message), 120)}>`;
|
|
206
|
+
if (object instanceof RegExp) return object.toString();
|
|
207
|
+
if (typeof Node !== "undefined" && object instanceof Node) return `<${nodeLabel(object)}>`;
|
|
208
|
+
if (typeof object.then === "function") return "<Promise>";
|
|
209
|
+
if (ArrayBuffer.isView(object)) return `<${object.constructor.name}(${object.byteLength} bytes)>`;
|
|
210
|
+
if (object instanceof ArrayBuffer) return `<ArrayBuffer(${object.byteLength} bytes)>`;
|
|
211
|
+
if (Array.isArray(object) || object instanceof Map || object instanceof Set) return null;
|
|
212
|
+
const proto = Object.getPrototypeOf(object);
|
|
213
|
+
if (proto !== null && proto !== Object.prototype) {
|
|
214
|
+
const name = object.constructor?.name;
|
|
215
|
+
return `<${name || "object"}>`;
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
function nodeLabel(node) {
|
|
220
|
+
if (typeof Element !== "undefined" && node instanceof Element) {
|
|
221
|
+
const id = node.id ? `#${node.id}` : "";
|
|
222
|
+
return `${node.tagName.toLowerCase()}${id}`;
|
|
223
|
+
}
|
|
224
|
+
return node.nodeName.toLowerCase();
|
|
225
|
+
}
|
|
226
|
+
function typeName(type) {
|
|
227
|
+
if (typeof type === "string") return type;
|
|
228
|
+
if (typeof type === "function") {
|
|
229
|
+
const fn = type;
|
|
230
|
+
return fn.displayName || fn.name || "Anonymous";
|
|
231
|
+
}
|
|
232
|
+
if (typeof type === "object" && type !== null) {
|
|
233
|
+
const wrapper = type;
|
|
234
|
+
if (wrapper.displayName) return wrapper.displayName;
|
|
235
|
+
if (wrapper.render !== void 0) return typeName(wrapper.render);
|
|
236
|
+
if (wrapper.type !== void 0) return typeName(wrapper.type);
|
|
237
|
+
}
|
|
238
|
+
return "Anonymous";
|
|
239
|
+
}
|
|
240
|
+
function truncate(text, max) {
|
|
241
|
+
return text.length <= max ? text : `${text.slice(0, max)}\u2026 (+${text.length - max} chars)`;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// src/context.ts
|
|
245
|
+
var IMPLICIT_ROLES = {
|
|
246
|
+
a: "link",
|
|
247
|
+
article: "article",
|
|
248
|
+
aside: "complementary",
|
|
249
|
+
button: "button",
|
|
250
|
+
dialog: "dialog",
|
|
251
|
+
form: "form",
|
|
252
|
+
h1: "heading",
|
|
253
|
+
h2: "heading",
|
|
254
|
+
h3: "heading",
|
|
255
|
+
h4: "heading",
|
|
256
|
+
h5: "heading",
|
|
257
|
+
h6: "heading",
|
|
258
|
+
img: "img",
|
|
259
|
+
li: "listitem",
|
|
260
|
+
main: "main",
|
|
261
|
+
nav: "navigation",
|
|
262
|
+
ol: "list",
|
|
263
|
+
option: "option",
|
|
264
|
+
select: "combobox",
|
|
265
|
+
table: "table",
|
|
266
|
+
td: "cell",
|
|
267
|
+
textarea: "textbox",
|
|
268
|
+
th: "columnheader",
|
|
269
|
+
tr: "row",
|
|
270
|
+
ul: "list"
|
|
271
|
+
};
|
|
272
|
+
var INPUT_ROLES = {
|
|
273
|
+
checkbox: "checkbox",
|
|
274
|
+
radio: "radio",
|
|
275
|
+
range: "slider",
|
|
276
|
+
search: "searchbox",
|
|
277
|
+
submit: "button",
|
|
278
|
+
button: "button",
|
|
279
|
+
number: "spinbutton"
|
|
280
|
+
};
|
|
281
|
+
var STATES = ["aria-expanded", "aria-selected", "aria-checked", "aria-pressed", "aria-current", "aria-invalid", "aria-busy"];
|
|
282
|
+
function roleOf(element) {
|
|
283
|
+
const explicit = element.getAttribute("role");
|
|
284
|
+
if (explicit) return explicit;
|
|
285
|
+
const tag = element.tagName.toLowerCase();
|
|
286
|
+
if (tag === "input") return INPUT_ROLES[element.type] ?? "textbox";
|
|
287
|
+
if (tag === "a" && !element.hasAttribute("href")) return null;
|
|
288
|
+
return IMPLICIT_ROLES[tag] ?? null;
|
|
289
|
+
}
|
|
290
|
+
function textOfIds(element, ids) {
|
|
291
|
+
return ids.split(/\s+/).map((id) => visibleText(element.ownerDocument.getElementById(id))).join(" ");
|
|
292
|
+
}
|
|
293
|
+
function accessibleName(element) {
|
|
294
|
+
const label = element.getAttribute("aria-label");
|
|
295
|
+
if (label) return label;
|
|
296
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
297
|
+
if (labelledBy) return textOfIds(element, labelledBy);
|
|
298
|
+
const labels = element.labels;
|
|
299
|
+
if (labels && labels.length > 0) return Array.from(labels, (node) => visibleText(node)).join(" ");
|
|
300
|
+
return element.getAttribute("alt") ?? element.getAttribute("title") ?? visibleText(element);
|
|
301
|
+
}
|
|
302
|
+
function clean(text, max, redactor) {
|
|
303
|
+
return truncate(redactor.text(text.replace(/\s+/g, " ").trim()), max);
|
|
304
|
+
}
|
|
305
|
+
function describeAccessibility(element, redactor = DEFAULT_REDACTOR) {
|
|
306
|
+
const role = roleOf(element);
|
|
307
|
+
if (role === null) return null;
|
|
308
|
+
const name = clean(accessibleName(element), 80, redactor);
|
|
309
|
+
const states = [];
|
|
310
|
+
if (element.disabled === true || element.getAttribute("aria-disabled") === "true") {
|
|
311
|
+
states.push("disabled");
|
|
312
|
+
}
|
|
313
|
+
for (const state of STATES) {
|
|
314
|
+
const value = element.getAttribute(state);
|
|
315
|
+
if (value !== null) states.push(`${state}=${value}`);
|
|
316
|
+
}
|
|
317
|
+
return `${role}${name ? ` "${name}"` : ""}${states.length > 0 ? ` (${states.join(", ")})` : ""}`;
|
|
318
|
+
}
|
|
319
|
+
var SECTIONS = 'section, form, fieldset, dialog, [role="dialog"], table, article, aside, nav, [aria-label], [aria-labelledby]';
|
|
320
|
+
var SECTION_TITLE = ":scope > h1, :scope > h2, :scope > h3, :scope > h4, :scope > legend, :scope > caption, :scope > header h1, :scope > header h2, :scope > header h3, :scope > div > h1, :scope > div > h2, :scope > div > h3";
|
|
321
|
+
var MAX_SECTIONS = 3;
|
|
322
|
+
function sectionLabel(section2) {
|
|
323
|
+
const label = section2.getAttribute("aria-label");
|
|
324
|
+
if (label) return label;
|
|
325
|
+
const labelledBy = section2.getAttribute("aria-labelledby");
|
|
326
|
+
if (labelledBy) return textOfIds(section2, labelledBy);
|
|
327
|
+
const title = section2.querySelector(SECTION_TITLE);
|
|
328
|
+
return title === null ? null : visibleText(title);
|
|
329
|
+
}
|
|
330
|
+
function sectionPath(element, redactor = DEFAULT_REDACTOR) {
|
|
331
|
+
const labels = [];
|
|
332
|
+
for (let current = element.parentElement?.closest(SECTIONS) ?? null; current !== null && labels.length < MAX_SECTIONS; current = current.parentElement?.closest(SECTIONS) ?? null) {
|
|
333
|
+
const label = sectionLabel(current);
|
|
334
|
+
if (label) labels.unshift(clean(label, 50, redactor));
|
|
335
|
+
}
|
|
336
|
+
const pageHeading = element.ownerDocument.querySelector("h1");
|
|
337
|
+
if (pageHeading && !pageHeading.contains(element)) {
|
|
338
|
+
const heading = clean(visibleText(pageHeading), 50, redactor);
|
|
339
|
+
if (heading && labels[0] !== heading) labels.unshift(heading);
|
|
340
|
+
}
|
|
341
|
+
const path = labels.filter((label) => label !== "");
|
|
342
|
+
return path.length === 0 ? null : path.join(" \u203A ");
|
|
343
|
+
}
|
|
344
|
+
function nearbyText(element, redactor = DEFAULT_REDACTOR) {
|
|
345
|
+
const before = visibleText(element.previousElementSibling);
|
|
346
|
+
const after = visibleText(element.nextElementSibling);
|
|
347
|
+
const parts = [clean(before, 60, redactor), clean(after, 60, redactor)];
|
|
348
|
+
if (parts[0] === "" && parts[1] === "") return null;
|
|
349
|
+
return `before: "${parts[0]}" \xB7 after: "${parts[1]}"`;
|
|
350
|
+
}
|
|
351
|
+
function visibleText(node) {
|
|
352
|
+
if (node === null || node === void 0) return "";
|
|
353
|
+
const raw = node instanceof HTMLElement && typeof node.innerText === "string" ? node.innerText : node.textContent;
|
|
354
|
+
return (raw ?? "").replace(/\s+/g, " ").trim();
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// src/fiber.ts
|
|
358
|
+
var FUNCTION_COMPONENT = 0;
|
|
359
|
+
var CLASS_COMPONENT = 1;
|
|
360
|
+
var FORWARD_REF = 11;
|
|
361
|
+
var MEMO_COMPONENT = 14;
|
|
362
|
+
var SIMPLE_MEMO_COMPONENT = 15;
|
|
363
|
+
var COMPONENT_TAGS = /* @__PURE__ */ new Set([FUNCTION_COMPONENT, CLASS_COMPONENT, FORWARD_REF, MEMO_COMPONENT, SIMPLE_MEMO_COMPONENT]);
|
|
364
|
+
var FRAMEWORK_COMPONENTS = /* @__PURE__ */ new Set([
|
|
365
|
+
"AppDevOverlay",
|
|
366
|
+
"AppDevOverlayErrorBoundary",
|
|
367
|
+
"AppRouter",
|
|
368
|
+
"ClientPageRoot",
|
|
369
|
+
"ClientSegmentRoot",
|
|
370
|
+
"DevRootHTTPAccessFallbackBoundary",
|
|
371
|
+
"ErrorBoundary",
|
|
372
|
+
"ErrorBoundaryHandler",
|
|
373
|
+
"GlobalError",
|
|
374
|
+
"HTTPAccessFallbackBoundary",
|
|
375
|
+
"HTTPAccessFallbackErrorBoundary",
|
|
376
|
+
"HandleRedirect",
|
|
377
|
+
"Head",
|
|
378
|
+
"HistoryUpdater",
|
|
379
|
+
"HotReload",
|
|
380
|
+
"InnerLayoutRouter",
|
|
381
|
+
"InnerScrollAndFocusHandler",
|
|
382
|
+
"LayoutRouter",
|
|
383
|
+
"LoadingBoundary",
|
|
384
|
+
"MetadataBoundary",
|
|
385
|
+
"MetadataOutlet",
|
|
386
|
+
"OuterLayoutRouter",
|
|
387
|
+
"OutletBoundary",
|
|
388
|
+
"RedirectBoundary",
|
|
389
|
+
"RedirectErrorBoundary",
|
|
390
|
+
"RenderFromTemplateContext",
|
|
391
|
+
"ReplaySsrOnlyErrors",
|
|
392
|
+
"Root",
|
|
393
|
+
"RootErrorBoundary",
|
|
394
|
+
"Router",
|
|
395
|
+
"RuntimeStyles",
|
|
396
|
+
"ScrollAndFocusHandler",
|
|
397
|
+
"SegmentStateProvider",
|
|
398
|
+
"SegmentViewNode",
|
|
399
|
+
"ServerRoot",
|
|
400
|
+
"ViewportBoundary",
|
|
401
|
+
"DevAnnotator"
|
|
402
|
+
]);
|
|
403
|
+
function fiberOf(node) {
|
|
404
|
+
let current = node;
|
|
405
|
+
while (current !== null) {
|
|
406
|
+
for (const key of Object.keys(current)) {
|
|
407
|
+
if (key.startsWith("__reactFiber$")) return current[key] ?? null;
|
|
408
|
+
}
|
|
409
|
+
current = current.parentNode;
|
|
410
|
+
}
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
function isComponent(fiber) {
|
|
414
|
+
return COMPONENT_TAGS.has(fiber.tag);
|
|
415
|
+
}
|
|
416
|
+
function componentName(fiber) {
|
|
417
|
+
return typeName(fiber.elementType ?? fiber.type);
|
|
418
|
+
}
|
|
419
|
+
function componentAncestors(fiber, limit = 12) {
|
|
420
|
+
const out = [];
|
|
421
|
+
let previousName = null;
|
|
422
|
+
for (let current = fiber; current !== null && out.length < limit; current = current.return) {
|
|
423
|
+
if (!isComponent(current)) continue;
|
|
424
|
+
const name = componentName(current);
|
|
425
|
+
if (FRAMEWORK_COMPONENTS.has(name) || name.startsWith("__next") || name === "Anonymous" || name === previousName) {
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
out.push(current);
|
|
429
|
+
previousName = name;
|
|
430
|
+
}
|
|
431
|
+
return out;
|
|
432
|
+
}
|
|
433
|
+
function componentState(fiber) {
|
|
434
|
+
if (fiber.tag === CLASS_COMPONENT) {
|
|
435
|
+
return fiber.memoizedState === null || fiber.memoizedState === void 0 ? [] : [fiber.memoizedState];
|
|
436
|
+
}
|
|
437
|
+
const values = [];
|
|
438
|
+
let hook = fiber.memoizedState;
|
|
439
|
+
while (hook !== null && typeof hook === "object" && "next" in hook) {
|
|
440
|
+
if (hook.queue !== null && hook.queue !== void 0) values.push(hook.memoizedState);
|
|
441
|
+
hook = hook.next;
|
|
442
|
+
}
|
|
443
|
+
return values;
|
|
444
|
+
}
|
|
445
|
+
function debugStackOf(fiber) {
|
|
446
|
+
const stack = fiber._debugStack;
|
|
447
|
+
if (stack instanceof Error) return stack.stack ?? null;
|
|
448
|
+
return typeof stack === "string" ? stack : null;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// src/selector.ts
|
|
452
|
+
var MAX_DEPTH = 6;
|
|
453
|
+
var TEST_ID_ATTRIBUTES = ["data-testid", "data-test", "data-qa", "data-cy", "data-component"];
|
|
454
|
+
function cssSelector(element) {
|
|
455
|
+
const doc = element.ownerDocument;
|
|
456
|
+
const steps = [];
|
|
457
|
+
let current = element;
|
|
458
|
+
while (current !== null && current !== doc.documentElement && steps.length < MAX_DEPTH) {
|
|
459
|
+
const anchor = uniqueAnchor(current, doc);
|
|
460
|
+
if (anchor !== null) {
|
|
461
|
+
steps.unshift(anchor);
|
|
462
|
+
return steps.join(" > ");
|
|
463
|
+
}
|
|
464
|
+
steps.unshift(positionalStep(current));
|
|
465
|
+
current = current.parentElement;
|
|
466
|
+
}
|
|
467
|
+
return steps.join(" > ");
|
|
468
|
+
}
|
|
469
|
+
function uniqueAnchor(element, doc) {
|
|
470
|
+
if (element.id && !/[«:]/.test(element.id)) {
|
|
471
|
+
const selector = `#${escapeCss(element.id)}`;
|
|
472
|
+
if (doc.querySelectorAll(selector).length === 1) return selector;
|
|
473
|
+
}
|
|
474
|
+
for (const attribute of TEST_ID_ATTRIBUTES) {
|
|
475
|
+
const value = element.getAttribute(attribute);
|
|
476
|
+
if (value) {
|
|
477
|
+
const selector = `[${attribute}="${value.replace(/"/g, '\\"')}"]`;
|
|
478
|
+
if (doc.querySelectorAll(selector).length === 1) return selector;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return null;
|
|
482
|
+
}
|
|
483
|
+
function positionalStep(element) {
|
|
484
|
+
const tag = element.tagName.toLowerCase();
|
|
485
|
+
const parent = element.parentElement;
|
|
486
|
+
if (parent === null) return tag;
|
|
487
|
+
const sameTag = Array.from(parent.children).filter((sibling) => sibling.tagName === element.tagName);
|
|
488
|
+
return sameTag.length === 1 ? tag : `${tag}:nth-of-type(${sameTag.indexOf(element) + 1})`;
|
|
489
|
+
}
|
|
490
|
+
function escapeCss(value) {
|
|
491
|
+
const native = globalThis.CSS?.escape;
|
|
492
|
+
return native ? native(value) : value.replace(/([^\w-])/g, "\\$1");
|
|
493
|
+
}
|
|
494
|
+
var DESCRIBED_ATTRIBUTES = [
|
|
495
|
+
"id",
|
|
496
|
+
"role",
|
|
497
|
+
"type",
|
|
498
|
+
"name",
|
|
499
|
+
"href",
|
|
500
|
+
"aria-label",
|
|
501
|
+
"placeholder",
|
|
502
|
+
"title",
|
|
503
|
+
"alt",
|
|
504
|
+
...TEST_ID_ATTRIBUTES
|
|
505
|
+
];
|
|
506
|
+
function describeElement(element, redactor = DEFAULT_REDACTOR) {
|
|
507
|
+
const parts = [element.tagName.toLowerCase()];
|
|
508
|
+
for (const attribute of DESCRIBED_ATTRIBUTES) {
|
|
509
|
+
const value = element.getAttribute(attribute);
|
|
510
|
+
if (value) parts.push(`${attribute}="${truncate(redactor.text(value), 60)}"`);
|
|
511
|
+
}
|
|
512
|
+
const className = element.getAttribute("class");
|
|
513
|
+
if (className) parts.push(`class="${truncate(className.trim().replace(/\s+/g, " "), 120)}"`);
|
|
514
|
+
return `<${parts.join(" ")}>`;
|
|
515
|
+
}
|
|
516
|
+
function elementText(element, max = 120, redactor = DEFAULT_REDACTOR) {
|
|
517
|
+
const raw = element instanceof HTMLElement && typeof element.innerText === "string" ? element.innerText : element.textContent;
|
|
518
|
+
const text = (raw ?? "").replace(/\s+/g, " ").trim();
|
|
519
|
+
return truncate(redactor.text(text), max);
|
|
520
|
+
}
|
|
521
|
+
function controlValue(element, redactor = DEFAULT_REDACTOR) {
|
|
522
|
+
if (element instanceof HTMLInputElement) {
|
|
523
|
+
if (element.type === "password") return REDACTED;
|
|
524
|
+
if (element.type === "checkbox" || element.type === "radio") return element.checked ? "checked" : "unchecked";
|
|
525
|
+
return truncate(redactor.text(element.value), 120);
|
|
526
|
+
}
|
|
527
|
+
if (element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) {
|
|
528
|
+
return truncate(redactor.text(element.value), 120);
|
|
529
|
+
}
|
|
530
|
+
return null;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// src/source-map.ts
|
|
534
|
+
var BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
535
|
+
var DIGIT = new Map([...BASE64].map((char, index) => [char, index]));
|
|
536
|
+
function decodeVlq(segment) {
|
|
537
|
+
const values = [];
|
|
538
|
+
let value = 0;
|
|
539
|
+
let shift = 0;
|
|
540
|
+
for (const char of segment) {
|
|
541
|
+
const digit = DIGIT.get(char);
|
|
542
|
+
if (digit === void 0) return values;
|
|
543
|
+
value += (digit & 31) << shift;
|
|
544
|
+
if (digit & 32) {
|
|
545
|
+
shift += 5;
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
values.push(value & 1 ? -(value >> 1) : value >> 1);
|
|
549
|
+
value = 0;
|
|
550
|
+
shift = 0;
|
|
551
|
+
}
|
|
552
|
+
return values;
|
|
553
|
+
}
|
|
554
|
+
function lookupPlain(map, line, column) {
|
|
555
|
+
let source = 0;
|
|
556
|
+
let sourceLine = 0;
|
|
557
|
+
let sourceColumn = 0;
|
|
558
|
+
const lines = map.mappings.split(";");
|
|
559
|
+
for (let current = 0; current <= line && current < lines.length; current++) {
|
|
560
|
+
let generated = 0;
|
|
561
|
+
let best = null;
|
|
562
|
+
for (const segment of (lines[current] ?? "").split(",")) {
|
|
563
|
+
if (segment === "") continue;
|
|
564
|
+
const fields = decodeVlq(segment);
|
|
565
|
+
generated += fields[0] ?? 0;
|
|
566
|
+
if (fields.length < 4) continue;
|
|
567
|
+
source += fields[1] ?? 0;
|
|
568
|
+
sourceLine += fields[2] ?? 0;
|
|
569
|
+
sourceColumn += fields[3] ?? 0;
|
|
570
|
+
const name = map.sources[source];
|
|
571
|
+
if (current === line && generated <= column && name !== void 0) {
|
|
572
|
+
best = { source: name, line: sourceLine, column: sourceColumn };
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
if (current === line) return best;
|
|
576
|
+
}
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
function originalPosition(map, line1, column1) {
|
|
580
|
+
const line = line1 - 1;
|
|
581
|
+
const column = column1 - 1;
|
|
582
|
+
if (!("sections" in map)) return lookupPlain(map, line, column);
|
|
583
|
+
let hit;
|
|
584
|
+
for (const section2 of map.sections) {
|
|
585
|
+
const { offset } = section2;
|
|
586
|
+
if (offset.line < line || offset.line === line && offset.column <= column) hit = section2;
|
|
587
|
+
else break;
|
|
588
|
+
}
|
|
589
|
+
if (hit === void 0) return null;
|
|
590
|
+
const inLine = line - hit.offset.line;
|
|
591
|
+
return lookupPlain(hit.map, inLine, inLine === 0 ? column - hit.offset.column : column);
|
|
592
|
+
}
|
|
593
|
+
function sourcePath(source) {
|
|
594
|
+
if (source.startsWith("file://")) return decodeURIComponent(source.slice("file://".length));
|
|
595
|
+
if (/^https?:\/\//.test(source)) {
|
|
596
|
+
const path = decodeURIComponent(new URL(source).pathname);
|
|
597
|
+
return path.startsWith("/@fs/") ? path.slice("/@fs".length) : path.replace(/^\//, "");
|
|
598
|
+
}
|
|
599
|
+
if (/^turbopack:\/\/\/\[turbopack\]/.test(source)) return null;
|
|
600
|
+
return source;
|
|
601
|
+
}
|
|
602
|
+
var TIMEOUT_MS = 3e3;
|
|
603
|
+
function createSourceMapLookup(fetchImpl) {
|
|
604
|
+
const maps = /* @__PURE__ */ new Map();
|
|
605
|
+
const load = (url) => {
|
|
606
|
+
let pending = maps.get(url);
|
|
607
|
+
if (pending === void 0) {
|
|
608
|
+
pending = fetchMap(fetchImpl, `${url.replace(/[?#].*$/, "")}.map`).then(
|
|
609
|
+
(beside) => beside ?? mapFromScript(fetchImpl, url)
|
|
610
|
+
);
|
|
611
|
+
maps.set(url, pending);
|
|
612
|
+
}
|
|
613
|
+
return pending;
|
|
614
|
+
};
|
|
615
|
+
return async (frame) => {
|
|
616
|
+
if (!/^https?:\/\//.test(frame.file)) return null;
|
|
617
|
+
const map = await load(frame.file.replace(/#.*$/, ""));
|
|
618
|
+
if (map === null) return null;
|
|
619
|
+
const original = originalPosition(map, frame.line1, frame.column1);
|
|
620
|
+
const file = original === null ? null : sourcePath(original.source);
|
|
621
|
+
if (original === null || file === null) return null;
|
|
622
|
+
return {
|
|
623
|
+
file,
|
|
624
|
+
line: original.line + 1,
|
|
625
|
+
column: original.column + 1,
|
|
626
|
+
mapped: true,
|
|
627
|
+
.../(?:^|\/)node_modules\//.test(file) ? { ignored: true } : {}
|
|
628
|
+
};
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
var MAPPING_URL = /\/\/[#@] sourceMappingURL=(\S+)\s*$/;
|
|
632
|
+
async function mapFromScript(fetchImpl, url) {
|
|
633
|
+
const script = await fetchText(fetchImpl, url);
|
|
634
|
+
const tail = script?.slice(-2e5).trimEnd();
|
|
635
|
+
const reference = tail === void 0 ? void 0 : MAPPING_URL.exec(tail)?.[1];
|
|
636
|
+
if (reference === void 0) return null;
|
|
637
|
+
const inline = /^data:application\/json(?:;charset=[^;,]+)?;base64,(.*)$/i.exec(reference);
|
|
638
|
+
if (inline?.[1] !== void 0) {
|
|
639
|
+
try {
|
|
640
|
+
const bytes = Uint8Array.from(atob(inline[1]), (char) => char.charCodeAt(0));
|
|
641
|
+
return asSourceMap(JSON.parse(new TextDecoder().decode(bytes)), url);
|
|
642
|
+
} catch {
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
try {
|
|
647
|
+
return await fetchMap(fetchImpl, new URL(reference, url).href);
|
|
648
|
+
} catch {
|
|
649
|
+
return null;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
async function fetchText(fetchImpl, url) {
|
|
653
|
+
const controller = new AbortController();
|
|
654
|
+
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
655
|
+
try {
|
|
656
|
+
const response = await fetchImpl(url, { signal: controller.signal });
|
|
657
|
+
return response.ok ? await response.text() : null;
|
|
658
|
+
} catch {
|
|
659
|
+
return null;
|
|
660
|
+
} finally {
|
|
661
|
+
clearTimeout(timer);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
function asSourceMap(body, base) {
|
|
665
|
+
if (typeof body !== "object" || body === null) return null;
|
|
666
|
+
if ("sections" in body && Array.isArray(body.sections)) return body;
|
|
667
|
+
if (!("mappings" in body) || !("sources" in body) || !Array.isArray(body.sources)) return null;
|
|
668
|
+
const root = "sourceRoot" in body && typeof body.sourceRoot === "string" ? body.sourceRoot : "";
|
|
669
|
+
const prefix = root === "" || root.endsWith("/") ? root : `${root}/`;
|
|
670
|
+
const relative = (source) => !/^[a-z]+:|^\//i.test(source);
|
|
671
|
+
const sources = body.sources.map((source) => {
|
|
672
|
+
if (typeof source !== "string") return source;
|
|
673
|
+
const rooted = relative(source) ? `${prefix}${source}` : source;
|
|
674
|
+
if (base === void 0 || !relative(rooted)) return rooted;
|
|
675
|
+
try {
|
|
676
|
+
return new URL(rooted, base).href;
|
|
677
|
+
} catch {
|
|
678
|
+
return rooted;
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
return { ...body, sources };
|
|
682
|
+
}
|
|
683
|
+
async function fetchMap(fetchImpl, url) {
|
|
684
|
+
const controller = new AbortController();
|
|
685
|
+
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
686
|
+
try {
|
|
687
|
+
const response = await fetchImpl(url, { signal: controller.signal });
|
|
688
|
+
if (!response.ok) return null;
|
|
689
|
+
return asSourceMap(await response.json(), url);
|
|
690
|
+
} catch {
|
|
691
|
+
return null;
|
|
692
|
+
} finally {
|
|
693
|
+
clearTimeout(timer);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// src/stack.ts
|
|
698
|
+
var CHROME_FRAME = /^\s*at (?:(.+?) \()?(.+?):(\d+):(\d+)\)?\s*$/;
|
|
699
|
+
var FIREFOX_FRAME = /^\s*(.*?)@(.+?):(\d+):(\d+)\s*$/;
|
|
700
|
+
function parseStack(stack) {
|
|
701
|
+
const frames = [];
|
|
702
|
+
for (const line of stack.split("\n")) {
|
|
703
|
+
const match = CHROME_FRAME.exec(line) ?? FIREFOX_FRAME.exec(line);
|
|
704
|
+
if (match === null) continue;
|
|
705
|
+
const [, methodName, file, line1, column1] = match;
|
|
706
|
+
if (file === void 0 || line1 === void 0 || column1 === void 0) continue;
|
|
707
|
+
frames.push({ file, line1: Number(line1), column1: Number(column1), methodName: methodName ?? "" });
|
|
708
|
+
}
|
|
709
|
+
return frames;
|
|
710
|
+
}
|
|
711
|
+
var REACT_FRAME = /(?:^|[/\\])(?:react|react-dom|scheduler)(?:[/\\]|@)|react-jsx-(?:dev-)?runtime|react\.development|react-dom[^/\\]*\.development|next[/\\]dist[/\\]compiled[/\\]react/;
|
|
712
|
+
var REACT_METHOD = /^(?:exports\.)?(?:jsxDEV|jsxs?|createElement|react-stack-top-frame)$|^Object\.(?:jsxDEV|jsxs?)$/;
|
|
713
|
+
function callSiteFrame(stack) {
|
|
714
|
+
for (const frame of parseStack(stack)) {
|
|
715
|
+
if (REACT_METHOD.test(frame.methodName) || REACT_FRAME.test(frame.file)) continue;
|
|
716
|
+
return frame;
|
|
717
|
+
}
|
|
718
|
+
return null;
|
|
719
|
+
}
|
|
720
|
+
function bundledPath(file) {
|
|
721
|
+
const internal = /^webpack-internal:\/\/\/(?:\([^)]*\)\/)?(?:\.\/)?(.*)$/.exec(file);
|
|
722
|
+
if (internal?.[1]) return internal[1];
|
|
723
|
+
if (file.startsWith("file://")) return decodeURIComponent(file.slice("file://".length));
|
|
724
|
+
return file;
|
|
725
|
+
}
|
|
726
|
+
function unmapped(frame) {
|
|
727
|
+
return { file: bundledPath(frame.file), line: frame.line1, column: frame.column1, mapped: false };
|
|
728
|
+
}
|
|
729
|
+
var NEXT_ENDPOINT = "/__nextjs_original-stack-frames";
|
|
730
|
+
var TIMEOUT_MS2 = 3e3;
|
|
731
|
+
function createNextResolver(fetchImpl = (...args) => fetch(...args)) {
|
|
732
|
+
const cache = /* @__PURE__ */ new Map();
|
|
733
|
+
const keyOf = (frame) => `${frame.file}:${frame.line1}:${frame.column1}`;
|
|
734
|
+
const viaSourceMap = createSourceMapLookup(fetchImpl);
|
|
735
|
+
return async (frames) => {
|
|
736
|
+
const pending = frames.filter((frame) => !cache.has(keyOf(frame)));
|
|
737
|
+
if (pending.length > 0) {
|
|
738
|
+
const fromNext = await requestOriginalFrames(fetchImpl, pending);
|
|
739
|
+
const mapped = await Promise.all(
|
|
740
|
+
pending.map(async (frame, index) => fromNext[index] ?? await viaSourceMap(frame))
|
|
741
|
+
);
|
|
742
|
+
pending.forEach((frame, index) => cache.set(keyOf(frame), mapped[index] ?? unmapped(frame)));
|
|
743
|
+
}
|
|
744
|
+
return frames.map((frame) => cache.get(keyOf(frame)) ?? unmapped(frame));
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
async function requestOriginalFrames(fetchImpl, frames) {
|
|
748
|
+
const controller = new AbortController();
|
|
749
|
+
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS2);
|
|
750
|
+
try {
|
|
751
|
+
const response = await fetchImpl(NEXT_ENDPOINT, {
|
|
752
|
+
method: "POST",
|
|
753
|
+
headers: { "content-type": "application/json" },
|
|
754
|
+
body: JSON.stringify({
|
|
755
|
+
frames: frames.map((frame) => ({ ...frame, arguments: [] })),
|
|
756
|
+
isServer: false,
|
|
757
|
+
isEdgeServer: false,
|
|
758
|
+
isAppDirectory: true
|
|
759
|
+
}),
|
|
760
|
+
signal: controller.signal
|
|
761
|
+
});
|
|
762
|
+
if (!response.ok) return frames.map(() => null);
|
|
763
|
+
const body = await response.json();
|
|
764
|
+
if (!Array.isArray(body)) return frames.map(() => null);
|
|
765
|
+
return frames.map((_, index) => toLocation(body[index]));
|
|
766
|
+
} catch {
|
|
767
|
+
return frames.map(() => null);
|
|
768
|
+
} finally {
|
|
769
|
+
clearTimeout(timer);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
function toLocation(entry) {
|
|
773
|
+
const original = entry?.status === "fulfilled" ? entry.value?.originalStackFrame : null;
|
|
774
|
+
if (!original?.file || typeof original.line1 !== "number") return null;
|
|
775
|
+
if (/^(?:webpack-internal|https?):/.test(original.file)) return null;
|
|
776
|
+
return {
|
|
777
|
+
file: original.file,
|
|
778
|
+
line: original.line1,
|
|
779
|
+
column: original.column1 ?? null,
|
|
780
|
+
mapped: true,
|
|
781
|
+
...original.ignored === true || /(?:^|\/)node_modules\//.test(original.file) ? { ignored: true } : {}
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// src/capture.ts
|
|
786
|
+
var STYLE_PROPERTIES = [
|
|
787
|
+
"display",
|
|
788
|
+
"position",
|
|
789
|
+
"width",
|
|
790
|
+
"height",
|
|
791
|
+
"margin",
|
|
792
|
+
"padding",
|
|
793
|
+
"gap",
|
|
794
|
+
"font-family",
|
|
795
|
+
"font-size",
|
|
796
|
+
"font-weight",
|
|
797
|
+
"line-height",
|
|
798
|
+
"color",
|
|
799
|
+
"background-color",
|
|
800
|
+
"border",
|
|
801
|
+
"border-radius",
|
|
802
|
+
"opacity",
|
|
803
|
+
"overflow",
|
|
804
|
+
"white-space"
|
|
805
|
+
];
|
|
806
|
+
var DEFAULT_STYLE_VALUES = /* @__PURE__ */ new Set(["none", "normal", "auto", "0px", "rgba(0, 0, 0, 0)", "visible", "static", "1"]);
|
|
807
|
+
var DATA_COMPONENTS = 2;
|
|
808
|
+
var LOCATED_COMPONENTS = 4;
|
|
809
|
+
async function captureElement(element, resolve, options = {}) {
|
|
810
|
+
const win = element.ownerDocument.defaultView ?? window;
|
|
811
|
+
const redactor = options.redactor ?? DEFAULT_REDACTOR;
|
|
812
|
+
const fiber = fiberOf(element);
|
|
813
|
+
const components = fiber === null ? [] : componentAncestors(fiber);
|
|
814
|
+
const sites = [fiber, ...components.slice(0, LOCATED_COMPONENTS)].map(
|
|
815
|
+
(f) => f === null ? null : siteOf(f)
|
|
816
|
+
);
|
|
817
|
+
const wanted = sites.filter((site) => site !== null);
|
|
818
|
+
const resolved = wanted.length > 0 ? await resolve(wanted) : [];
|
|
819
|
+
const locations = new Map(wanted.map((site, index) => [site, resolved[index]]));
|
|
820
|
+
const locate = (site) => {
|
|
821
|
+
const location2 = site ? locations.get(site) : void 0;
|
|
822
|
+
return location2 === void 0 || location2.ignored === true ? null : location2;
|
|
823
|
+
};
|
|
824
|
+
const rect = element.getBoundingClientRect();
|
|
825
|
+
return {
|
|
826
|
+
page: {
|
|
827
|
+
url: win.location.href,
|
|
828
|
+
pathname: win.location.pathname,
|
|
829
|
+
search: win.location.search,
|
|
830
|
+
title: element.ownerDocument.title
|
|
831
|
+
},
|
|
832
|
+
element: {
|
|
833
|
+
tag: element.tagName.toLowerCase(),
|
|
834
|
+
opening: describeElement(element, redactor),
|
|
835
|
+
selector: cssSelector(element),
|
|
836
|
+
text: elementText(element, void 0, redactor),
|
|
837
|
+
value: controlValue(element, redactor),
|
|
838
|
+
rect: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) },
|
|
839
|
+
styles: notableStyles(win.getComputedStyle(element)),
|
|
840
|
+
accessibility: describeAccessibility(element, redactor),
|
|
841
|
+
section: sectionPath(element, redactor),
|
|
842
|
+
nearby: nearbyText(element, redactor)
|
|
843
|
+
},
|
|
844
|
+
viewport: { width: win.innerWidth, height: win.innerHeight, devicePixelRatio: win.devicePixelRatio },
|
|
845
|
+
jsx: locate(sites[0]),
|
|
846
|
+
components: components.map((component, index) => ({
|
|
847
|
+
name: componentName(component),
|
|
848
|
+
renderedAt: locate(sites[index + 1])
|
|
849
|
+
})),
|
|
850
|
+
data: components.slice(0, options.dataComponents ?? DATA_COMPONENTS).map((component) => ({
|
|
851
|
+
component: componentName(component),
|
|
852
|
+
props: toSnapshot(component.memoizedProps, DEFAULT_LIMITS, redactor),
|
|
853
|
+
state: toSnapshot(componentState(component), DEFAULT_LIMITS, redactor)
|
|
854
|
+
}))
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
function siteOf(fiber) {
|
|
858
|
+
const stack = debugStackOf(fiber);
|
|
859
|
+
return stack === null ? null : callSiteFrame(stack);
|
|
860
|
+
}
|
|
861
|
+
function notableStyles(style) {
|
|
862
|
+
const out = {};
|
|
863
|
+
for (const property of STYLE_PROPERTIES) {
|
|
864
|
+
const value = style.getPropertyValue(property).trim();
|
|
865
|
+
if (value && !DEFAULT_STYLE_VALUES.has(value)) out[property] = value;
|
|
866
|
+
}
|
|
867
|
+
return out;
|
|
868
|
+
}
|
|
869
|
+
function hoverLabel(element) {
|
|
870
|
+
const fiber = fiberOf(element);
|
|
871
|
+
const nearest = fiber === null ? void 0 : componentAncestors(fiber, 1)[0];
|
|
872
|
+
const tag = element.tagName.toLowerCase();
|
|
873
|
+
return nearest === void 0 ? tag : `${componentName(nearest)} \xB7 ${tag}`;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// src/callouts.ts
|
|
877
|
+
var CARD_WIDTH = 260;
|
|
878
|
+
var LINE_HEIGHT = 18;
|
|
879
|
+
var PADDING = 16;
|
|
880
|
+
var GAP = 6;
|
|
881
|
+
var MARGIN = 4;
|
|
882
|
+
var CARD_LINES = 4;
|
|
883
|
+
var CHARS_PER_LINE = 36;
|
|
884
|
+
function cardHeight(comment) {
|
|
885
|
+
const lines = comment.split("\n").reduce((total, line) => total + Math.max(1, Math.ceil(line.length / CHARS_PER_LINE)), 0);
|
|
886
|
+
return PADDING + LINE_HEIGHT * Math.min(CARD_LINES, Math.max(1, lines));
|
|
887
|
+
}
|
|
888
|
+
function overlaps(a, b) {
|
|
889
|
+
return a.left < b.left + b.width && b.left < a.left + a.width && a.top < b.top + b.height && b.top < a.top + a.height;
|
|
890
|
+
}
|
|
891
|
+
function layoutCallouts(targets, viewport) {
|
|
892
|
+
const placed = [];
|
|
893
|
+
const width = Math.min(CARD_WIDTH, viewport.width - 2 * MARGIN);
|
|
894
|
+
const ordered = [...targets].sort((a, b) => a.box.top - b.box.top || a.box.left - b.box.left);
|
|
895
|
+
for (const target of ordered) {
|
|
896
|
+
const height = cardHeight(target.comment);
|
|
897
|
+
const above = target.box.top - height - GAP;
|
|
898
|
+
let top = above >= MARGIN ? above : target.box.top + target.box.height + GAP;
|
|
899
|
+
const left = Math.min(Math.max(MARGIN, target.box.left), viewport.width - width - MARGIN);
|
|
900
|
+
let card = { top, left, width, height };
|
|
901
|
+
for (let moved = true; moved; ) {
|
|
902
|
+
moved = false;
|
|
903
|
+
for (const other of placed) {
|
|
904
|
+
if (overlaps(card, other.card)) {
|
|
905
|
+
top = other.card.top + other.card.height + GAP;
|
|
906
|
+
card = { top, left, width, height };
|
|
907
|
+
moved = true;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
placed.push({ ...target, card: { ...card, top: Math.min(card.top, viewport.height - height - MARGIN) } });
|
|
912
|
+
}
|
|
913
|
+
return placed.sort((a, b) => a.number - b.number);
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// src/icons.tsx
|
|
917
|
+
import { jsx } from "react/jsx-runtime";
|
|
918
|
+
var PATHS = {
|
|
919
|
+
comment: ["M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z", "M12 7v6M9 10h6"],
|
|
920
|
+
pause: ["M8 5v14M16 5v14"],
|
|
921
|
+
play: ["M7 4l13 8-13 8z"],
|
|
922
|
+
eye: ["M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z", "M12 9a3 3 0 1 0 0 6 3 3 0 0 0 0-6z"],
|
|
923
|
+
camera: ["M4 8h3l2-3h6l2 3h3a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z", "M12 9.5a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7z"],
|
|
924
|
+
list: ["M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01"],
|
|
925
|
+
copy: ["M10 9h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H10a1 1 0 0 1-1-1V10a1 1 0 0 1 1-1z", "M5 15H4a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1"],
|
|
926
|
+
help: ["M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18z", "M9.1 9a3 3 0 0 1 5.8 1c0 2-3 3-3 3M12 17h.01"],
|
|
927
|
+
arrow: ["M5 19L19 5", "M10 5h9v9"],
|
|
928
|
+
rect: ["M5 5h14a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z"],
|
|
929
|
+
highlight: ["M9 11l-6 6v3h9l3-3", "M22 12l-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4"],
|
|
930
|
+
pen: ["M12 20h9", "M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z"],
|
|
931
|
+
text: ["M4 7V4h16v3", "M9 20h6", "M12 4v16"],
|
|
932
|
+
pixelate: ["M3 3h6v6H3z", "M15 3h6v6h-6z", "M9 9h6v6H9z", "M3 15h6v6H3z", "M15 15h6v6h-6z"],
|
|
933
|
+
undo: ["M9 14L4 9l5-5", "M4 9h10.5a5.5 5.5 0 0 1 0 11H11"],
|
|
934
|
+
trash: ["M3 6h18", "M8 6V4h8v2", "M19 6l-1 14H6L5 6"],
|
|
935
|
+
download: ["M12 3v12", "M7 10l5 5 5-5", "M5 21h14"],
|
|
936
|
+
close: ["M18 6L6 18", "M6 6l12 12"],
|
|
937
|
+
select: ["M4 3l7 17 2.5-7.5L21 10z"],
|
|
938
|
+
redo: ["M15 14l5-5-5-5", "M20 9H9.5a5.5 5.5 0 0 0 0 11H13"],
|
|
939
|
+
zoomIn: ["M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14z", "M20 20l-4-4", "M11 8v6M8 11h6"],
|
|
940
|
+
zoomOut: ["M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14z", "M20 20l-4-4", "M8 11h6"],
|
|
941
|
+
fit: ["M4 9V4h5", "M20 9V4h-5", "M4 15v5h5", "M20 15v5h-5"],
|
|
942
|
+
eraser: ["M7 21h10", "M5 15l9-9 5 5-9 9H8z"],
|
|
943
|
+
crop: ["M6 2v14a2 2 0 0 0 2 2h14", "M18 22V8a2 2 0 0 0-2-2H2"],
|
|
944
|
+
cropOff: ["M6 2v14a2 2 0 0 0 2 2h14", "M18 22V8a2 2 0 0 0-2-2H2", "M3 3l18 18"],
|
|
945
|
+
collapse: ["M9 6l6 6-6 6"],
|
|
946
|
+
shield: ["M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6z", "M9 12l2 2 4-4"],
|
|
947
|
+
shieldOff: ["M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6z", "M3 3l18 18"],
|
|
948
|
+
ruler: ["M3 17L17 3l4 4L7 21z", "M7 13l2 2", "M10 10l2 2", "M13 7l2 2"]
|
|
949
|
+
};
|
|
950
|
+
function Icon(props) {
|
|
951
|
+
const size = props.size ?? 18;
|
|
952
|
+
return /* @__PURE__ */ jsx(
|
|
953
|
+
"svg",
|
|
954
|
+
{
|
|
955
|
+
width: size,
|
|
956
|
+
height: size,
|
|
957
|
+
viewBox: "0 0 24 24",
|
|
958
|
+
fill: "none",
|
|
959
|
+
stroke: "currentColor",
|
|
960
|
+
strokeWidth: 2,
|
|
961
|
+
strokeLinecap: "round",
|
|
962
|
+
strokeLinejoin: "round",
|
|
963
|
+
"aria-hidden": "true",
|
|
964
|
+
style: { display: "block", flex: "none" },
|
|
965
|
+
children: PATHS[props.name].map((d) => /* @__PURE__ */ jsx("path", { d }, d))
|
|
966
|
+
}
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// src/tooltip.tsx
|
|
971
|
+
import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
972
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
973
|
+
var FONT = 'ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif';
|
|
974
|
+
var DELAY_MS = 350;
|
|
975
|
+
var EDGE = 8;
|
|
976
|
+
var MOD_KEY = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent) ? "\u2318" : "Ctrl";
|
|
977
|
+
function Tooltip(props) {
|
|
978
|
+
const id = useId();
|
|
979
|
+
const [open, setOpen] = useState(false);
|
|
980
|
+
const [shift, setShift] = useState(0);
|
|
981
|
+
const timer = useRef(null);
|
|
982
|
+
const bubble = useRef(null);
|
|
983
|
+
const clear = () => {
|
|
984
|
+
if (timer.current !== null) window.clearTimeout(timer.current);
|
|
985
|
+
timer.current = null;
|
|
986
|
+
};
|
|
987
|
+
const show = (delay) => {
|
|
988
|
+
clear();
|
|
989
|
+
timer.current = window.setTimeout(() => setOpen(true), delay);
|
|
990
|
+
};
|
|
991
|
+
const hide = () => {
|
|
992
|
+
clear();
|
|
993
|
+
setOpen(false);
|
|
994
|
+
setShift(0);
|
|
995
|
+
};
|
|
996
|
+
useEffect(() => clear, []);
|
|
997
|
+
useLayoutEffect(() => {
|
|
998
|
+
if (!open || bubble.current === null) return;
|
|
999
|
+
const rect = bubble.current.getBoundingClientRect();
|
|
1000
|
+
if (rect.width === 0) return;
|
|
1001
|
+
if (rect.right > window.innerWidth - EDGE) setShift(window.innerWidth - EDGE - rect.right);
|
|
1002
|
+
else if (rect.left < EDGE) setShift(EDGE - rect.left);
|
|
1003
|
+
}, [open]);
|
|
1004
|
+
return /* @__PURE__ */ jsxs(
|
|
1005
|
+
"span",
|
|
1006
|
+
{
|
|
1007
|
+
style: { position: "relative", display: "inline-flex" },
|
|
1008
|
+
onPointerEnter: () => show(DELAY_MS),
|
|
1009
|
+
onPointerLeave: hide,
|
|
1010
|
+
onPointerDown: hide,
|
|
1011
|
+
onFocus: (event) => {
|
|
1012
|
+
if (focusVisible(event.target)) show(0);
|
|
1013
|
+
},
|
|
1014
|
+
onBlur: hide,
|
|
1015
|
+
children: [
|
|
1016
|
+
props.children(open ? id : void 0),
|
|
1017
|
+
open ? /* @__PURE__ */ jsxs(
|
|
1018
|
+
"span",
|
|
1019
|
+
{
|
|
1020
|
+
ref: bubble,
|
|
1021
|
+
id,
|
|
1022
|
+
role: "tooltip",
|
|
1023
|
+
style: {
|
|
1024
|
+
position: "absolute",
|
|
1025
|
+
left: "50%",
|
|
1026
|
+
[props.placement === "above" ? "bottom" : "top"]: "calc(100% + 8px)",
|
|
1027
|
+
transform: `translateX(calc(-50% + ${shift}px))`,
|
|
1028
|
+
display: "flex",
|
|
1029
|
+
flexDirection: "column",
|
|
1030
|
+
gap: 2,
|
|
1031
|
+
width: "max-content",
|
|
1032
|
+
maxWidth: 260,
|
|
1033
|
+
padding: "6px 9px",
|
|
1034
|
+
borderRadius: 7,
|
|
1035
|
+
background: "#0E0E0E",
|
|
1036
|
+
border: "1px solid rgba(255,255,255,0.14)",
|
|
1037
|
+
boxShadow: "0 6px 18px rgba(0,0,0,0.35)",
|
|
1038
|
+
color: "#FFFFFF",
|
|
1039
|
+
font: `500 12px/1.35 ${FONT}`,
|
|
1040
|
+
letterSpacing: "normal",
|
|
1041
|
+
textAlign: "left",
|
|
1042
|
+
textTransform: "none",
|
|
1043
|
+
whiteSpace: "normal",
|
|
1044
|
+
pointerEvents: "none",
|
|
1045
|
+
zIndex: 1
|
|
1046
|
+
},
|
|
1047
|
+
children: [
|
|
1048
|
+
/* @__PURE__ */ jsxs("span", { style: { display: "flex", alignItems: "center", gap: 8, whiteSpace: "nowrap" }, children: [
|
|
1049
|
+
/* @__PURE__ */ jsx2("span", { style: { fontWeight: 600 }, children: props.label }),
|
|
1050
|
+
props.shortcut === void 0 || props.shortcut.length === 0 ? null : /* @__PURE__ */ jsx2("span", { style: { display: "inline-flex", gap: 3, marginLeft: "auto" }, children: props.shortcut.map((key) => /* @__PURE__ */ jsx2(
|
|
1051
|
+
"kbd",
|
|
1052
|
+
{
|
|
1053
|
+
style: {
|
|
1054
|
+
font: `600 11px/16px ${FONT}`,
|
|
1055
|
+
minWidth: 16,
|
|
1056
|
+
padding: "0 4px",
|
|
1057
|
+
textAlign: "center",
|
|
1058
|
+
borderRadius: 4,
|
|
1059
|
+
background: "rgba(255,255,255,0.14)",
|
|
1060
|
+
color: "#FFFFFF"
|
|
1061
|
+
},
|
|
1062
|
+
children: key
|
|
1063
|
+
},
|
|
1064
|
+
key
|
|
1065
|
+
)) })
|
|
1066
|
+
] }),
|
|
1067
|
+
props.detail === void 0 ? null : /* @__PURE__ */ jsx2("span", { style: { color: "#B9B5AE" }, children: props.detail })
|
|
1068
|
+
]
|
|
1069
|
+
}
|
|
1070
|
+
) : null
|
|
1071
|
+
]
|
|
1072
|
+
}
|
|
1073
|
+
);
|
|
1074
|
+
}
|
|
1075
|
+
function focusVisible(target) {
|
|
1076
|
+
try {
|
|
1077
|
+
return target instanceof HTMLElement && target.matches(":focus-visible");
|
|
1078
|
+
} catch {
|
|
1079
|
+
return false;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
// src/overlay-parts.tsx
|
|
1084
|
+
import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1085
|
+
var ACCENT = "#D97757";
|
|
1086
|
+
var INK = "#1F1E1D";
|
|
1087
|
+
var MUTED = "#6B6862";
|
|
1088
|
+
var LINE = "#E5E2DC";
|
|
1089
|
+
var Z = 2147483e3;
|
|
1090
|
+
var FONT2 = {
|
|
1091
|
+
fontFamily: 'ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',
|
|
1092
|
+
fontSize: 13,
|
|
1093
|
+
lineHeight: 1.45,
|
|
1094
|
+
color: INK,
|
|
1095
|
+
letterSpacing: "normal",
|
|
1096
|
+
textTransform: "none"
|
|
1097
|
+
};
|
|
1098
|
+
var BUTTON = {
|
|
1099
|
+
...FONT2,
|
|
1100
|
+
appearance: "none",
|
|
1101
|
+
border: `1px solid ${LINE}`,
|
|
1102
|
+
background: "#FFFFFF",
|
|
1103
|
+
borderRadius: 6,
|
|
1104
|
+
padding: "5px 10px",
|
|
1105
|
+
cursor: "pointer",
|
|
1106
|
+
fontWeight: 500
|
|
1107
|
+
};
|
|
1108
|
+
var PRIMARY = { ...BUTTON, background: ACCENT, borderColor: ACCENT, color: "#FFFFFF" };
|
|
1109
|
+
function boxOf(element) {
|
|
1110
|
+
const rect = element.getBoundingClientRect();
|
|
1111
|
+
return { top: rect.top, left: rect.left, width: rect.width, height: rect.height };
|
|
1112
|
+
}
|
|
1113
|
+
function Highlight(props) {
|
|
1114
|
+
const { box } = props;
|
|
1115
|
+
const labelAbove = box.top > 24;
|
|
1116
|
+
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1117
|
+
/* @__PURE__ */ jsx3(
|
|
1118
|
+
"div",
|
|
1119
|
+
{
|
|
1120
|
+
style: {
|
|
1121
|
+
position: "fixed",
|
|
1122
|
+
top: box.top,
|
|
1123
|
+
left: box.left,
|
|
1124
|
+
width: box.width,
|
|
1125
|
+
height: box.height,
|
|
1126
|
+
border: `2px solid ${ACCENT}`,
|
|
1127
|
+
background: props.strong ? "rgba(217, 119, 87, 0.18)" : "rgba(217, 119, 87, 0.08)",
|
|
1128
|
+
borderRadius: 3,
|
|
1129
|
+
pointerEvents: "none",
|
|
1130
|
+
zIndex: Z,
|
|
1131
|
+
boxSizing: "border-box"
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
),
|
|
1135
|
+
/* @__PURE__ */ jsx3(
|
|
1136
|
+
"div",
|
|
1137
|
+
{
|
|
1138
|
+
style: {
|
|
1139
|
+
...FONT2,
|
|
1140
|
+
position: "fixed",
|
|
1141
|
+
top: labelAbove ? box.top - 22 : box.top + box.height + 2,
|
|
1142
|
+
left: Math.max(0, box.left),
|
|
1143
|
+
background: ACCENT,
|
|
1144
|
+
color: "#FFFFFF",
|
|
1145
|
+
fontSize: 11,
|
|
1146
|
+
fontWeight: 600,
|
|
1147
|
+
padding: "2px 6px",
|
|
1148
|
+
borderRadius: 3,
|
|
1149
|
+
pointerEvents: "none",
|
|
1150
|
+
zIndex: Z,
|
|
1151
|
+
whiteSpace: "nowrap"
|
|
1152
|
+
},
|
|
1153
|
+
children: props.label
|
|
1154
|
+
}
|
|
1155
|
+
)
|
|
1156
|
+
] });
|
|
1157
|
+
}
|
|
1158
|
+
function AreaBox(props) {
|
|
1159
|
+
return /* @__PURE__ */ jsx3(
|
|
1160
|
+
"div",
|
|
1161
|
+
{
|
|
1162
|
+
style: {
|
|
1163
|
+
position: "fixed",
|
|
1164
|
+
top: props.box.top,
|
|
1165
|
+
left: props.box.left,
|
|
1166
|
+
width: props.box.width,
|
|
1167
|
+
height: props.box.height,
|
|
1168
|
+
border: `2px dashed ${ACCENT}`,
|
|
1169
|
+
background: "rgba(217, 119, 87, 0.08)",
|
|
1170
|
+
pointerEvents: "none",
|
|
1171
|
+
zIndex: Z,
|
|
1172
|
+
boxSizing: "border-box"
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
);
|
|
1176
|
+
}
|
|
1177
|
+
function Pin(props) {
|
|
1178
|
+
const top = Math.min(Math.max(props.box.top - 10, 4), window.innerHeight - 26);
|
|
1179
|
+
const left = Math.min(Math.max(props.box.left - 10, 4), window.innerWidth - 26);
|
|
1180
|
+
return /* @__PURE__ */ jsx3(
|
|
1181
|
+
"button",
|
|
1182
|
+
{
|
|
1183
|
+
type: "button",
|
|
1184
|
+
onClick: props.onClick,
|
|
1185
|
+
"aria-label": `Comment ${props.number}`,
|
|
1186
|
+
style: {
|
|
1187
|
+
...FONT2,
|
|
1188
|
+
position: "fixed",
|
|
1189
|
+
top,
|
|
1190
|
+
left,
|
|
1191
|
+
width: 22,
|
|
1192
|
+
height: 22,
|
|
1193
|
+
borderRadius: "50% 50% 50% 4px",
|
|
1194
|
+
border: "2px solid #FFFFFF",
|
|
1195
|
+
background: ACCENT,
|
|
1196
|
+
color: "#FFFFFF",
|
|
1197
|
+
fontSize: 11,
|
|
1198
|
+
fontWeight: 700,
|
|
1199
|
+
padding: 0,
|
|
1200
|
+
cursor: "pointer",
|
|
1201
|
+
boxShadow: "0 1px 4px rgba(0,0,0,0.3)",
|
|
1202
|
+
zIndex: Z + 1
|
|
1203
|
+
},
|
|
1204
|
+
children: props.number
|
|
1205
|
+
}
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1208
|
+
function Hint(props) {
|
|
1209
|
+
return /* @__PURE__ */ jsxs2(
|
|
1210
|
+
"div",
|
|
1211
|
+
{
|
|
1212
|
+
role: "status",
|
|
1213
|
+
style: {
|
|
1214
|
+
display: "flex",
|
|
1215
|
+
alignItems: "center",
|
|
1216
|
+
gap: 10,
|
|
1217
|
+
...FONT2,
|
|
1218
|
+
position: "fixed",
|
|
1219
|
+
top: 8,
|
|
1220
|
+
left: "50%",
|
|
1221
|
+
transform: "translateX(-50%)",
|
|
1222
|
+
background: INK,
|
|
1223
|
+
color: "#FFFFFF",
|
|
1224
|
+
fontSize: 12,
|
|
1225
|
+
padding: "6px 12px",
|
|
1226
|
+
borderRadius: 999,
|
|
1227
|
+
zIndex: Z + 2,
|
|
1228
|
+
maxWidth: "calc(100vw - 32px)",
|
|
1229
|
+
textAlign: "center",
|
|
1230
|
+
boxShadow: "0 2px 8px rgba(0,0,0,0.25)"
|
|
1231
|
+
},
|
|
1232
|
+
children: [
|
|
1233
|
+
/* @__PURE__ */ jsx3("span", { style: { ...FONT2, fontSize: 12, color: "#FFFFFF" }, children: "Comment mode. Click: comment on an element \xB7 Select text: comment on a passage \xB7 \u2318/Ctrl+click: pick several \xB7 Shift+drag: mark an area \xB7 Alt+click: interact normally \xB7 Esc: exit" }),
|
|
1234
|
+
/* @__PURE__ */ jsx3(Tooltip, { label: "Hide this hint", detail: "The ? button in the toolbar brings it back.", placement: "below", children: (describedBy) => /* @__PURE__ */ jsx3(
|
|
1235
|
+
"button",
|
|
1236
|
+
{
|
|
1237
|
+
type: "button",
|
|
1238
|
+
onClick: props.onDismiss,
|
|
1239
|
+
"aria-label": "Hide hint",
|
|
1240
|
+
"aria-describedby": describedBy,
|
|
1241
|
+
style: { ...FONT2, appearance: "none", background: "none", border: 0, padding: "0 2px", color: "#FFFFFF", fontSize: 16, lineHeight: 1, cursor: "pointer" },
|
|
1242
|
+
children: "\xD7"
|
|
1243
|
+
}
|
|
1244
|
+
) })
|
|
1245
|
+
]
|
|
1246
|
+
}
|
|
1247
|
+
);
|
|
1248
|
+
}
|
|
1249
|
+
function Editor(props) {
|
|
1250
|
+
const width = 320;
|
|
1251
|
+
const height = 170;
|
|
1252
|
+
const { anchor } = props;
|
|
1253
|
+
let top = window.innerHeight - height - 80;
|
|
1254
|
+
let left = window.innerWidth - width - 16;
|
|
1255
|
+
if (anchor !== null) {
|
|
1256
|
+
const below = anchor.top + anchor.height + 8;
|
|
1257
|
+
top = below + height < window.innerHeight ? below : Math.max(8, anchor.top - height - 8);
|
|
1258
|
+
left = Math.min(Math.max(8, anchor.left), window.innerWidth - width - 8);
|
|
1259
|
+
}
|
|
1260
|
+
const canSave = props.comment.trim().length > 0;
|
|
1261
|
+
return /* @__PURE__ */ jsxs2(
|
|
1262
|
+
"div",
|
|
1263
|
+
{
|
|
1264
|
+
role: "dialog",
|
|
1265
|
+
"aria-label": "Comment on element",
|
|
1266
|
+
style: {
|
|
1267
|
+
...FONT2,
|
|
1268
|
+
position: "fixed",
|
|
1269
|
+
top,
|
|
1270
|
+
left,
|
|
1271
|
+
width,
|
|
1272
|
+
background: "#FFFFFF",
|
|
1273
|
+
border: `1px solid ${LINE}`,
|
|
1274
|
+
borderRadius: 10,
|
|
1275
|
+
boxShadow: "0 8px 24px rgba(0,0,0,0.18)",
|
|
1276
|
+
padding: 10,
|
|
1277
|
+
zIndex: Z + 3,
|
|
1278
|
+
boxSizing: "border-box"
|
|
1279
|
+
},
|
|
1280
|
+
children: [
|
|
1281
|
+
/* @__PURE__ */ jsx3("div", { style: { ...FONT2, fontSize: 11, color: MUTED, marginBottom: 6, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: props.title }),
|
|
1282
|
+
/* @__PURE__ */ jsx3(
|
|
1283
|
+
"textarea",
|
|
1284
|
+
{
|
|
1285
|
+
autoFocus: true,
|
|
1286
|
+
value: props.comment,
|
|
1287
|
+
placeholder: "What should change here?",
|
|
1288
|
+
onChange: (event) => props.onChange(event.target.value),
|
|
1289
|
+
onKeyDown: (event) => {
|
|
1290
|
+
event.stopPropagation();
|
|
1291
|
+
if (event.key === "Escape") props.onCancel();
|
|
1292
|
+
if (event.key === "Enter" && (event.metaKey || event.ctrlKey) && canSave) props.onSave();
|
|
1293
|
+
},
|
|
1294
|
+
style: {
|
|
1295
|
+
...FONT2,
|
|
1296
|
+
width: "100%",
|
|
1297
|
+
height: 84,
|
|
1298
|
+
resize: "vertical",
|
|
1299
|
+
border: `1px solid ${LINE}`,
|
|
1300
|
+
borderRadius: 6,
|
|
1301
|
+
padding: 8,
|
|
1302
|
+
boxSizing: "border-box",
|
|
1303
|
+
outline: "none",
|
|
1304
|
+
background: "#FFFFFF"
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
),
|
|
1308
|
+
/* @__PURE__ */ jsxs2("div", { style: { display: "flex", gap: 6, justifyContent: "flex-end", marginTop: 8 }, children: [
|
|
1309
|
+
props.editing ? /* @__PURE__ */ jsx3("button", { type: "button", onClick: props.onDelete, style: { ...BUTTON, marginRight: "auto", color: "#B42318" }, children: "Delete" }) : null,
|
|
1310
|
+
/* @__PURE__ */ jsx3("button", { type: "button", onClick: props.onCancel, style: BUTTON, children: "Cancel" }),
|
|
1311
|
+
/* @__PURE__ */ jsx3("button", { type: "button", onClick: props.onSave, disabled: !canSave, style: { ...PRIMARY, opacity: canSave ? 1 : 0.5 }, children: "Save (\u2318\u21B5)" })
|
|
1312
|
+
] })
|
|
1313
|
+
]
|
|
1314
|
+
}
|
|
1315
|
+
);
|
|
1316
|
+
}
|
|
1317
|
+
function Panel(props) {
|
|
1318
|
+
return /* @__PURE__ */ jsxs2(
|
|
1319
|
+
"div",
|
|
1320
|
+
{
|
|
1321
|
+
"aria-label": "Comment list",
|
|
1322
|
+
style: {
|
|
1323
|
+
...FONT2,
|
|
1324
|
+
position: "fixed",
|
|
1325
|
+
right: 16,
|
|
1326
|
+
bottom: 72,
|
|
1327
|
+
width: 340,
|
|
1328
|
+
maxHeight: "60vh",
|
|
1329
|
+
display: "flex",
|
|
1330
|
+
flexDirection: "column",
|
|
1331
|
+
background: "#FFFFFF",
|
|
1332
|
+
border: `1px solid ${LINE}`,
|
|
1333
|
+
borderRadius: 10,
|
|
1334
|
+
boxShadow: "0 8px 24px rgba(0,0,0,0.18)",
|
|
1335
|
+
zIndex: Z + 2,
|
|
1336
|
+
boxSizing: "border-box"
|
|
1337
|
+
},
|
|
1338
|
+
children: [
|
|
1339
|
+
/* @__PURE__ */ jsxs2("div", { style: { display: "flex", alignItems: "center", padding: "8px 10px", borderBottom: `1px solid ${LINE}` }, children: [
|
|
1340
|
+
/* @__PURE__ */ jsxs2("strong", { style: { ...FONT2, fontWeight: 600 }, children: [
|
|
1341
|
+
"Comments (",
|
|
1342
|
+
props.entries.length,
|
|
1343
|
+
")"
|
|
1344
|
+
] }),
|
|
1345
|
+
/* @__PURE__ */ jsx3("button", { type: "button", onClick: props.onClose, "aria-label": "Hide list", style: { ...BUTTON, marginLeft: "auto", padding: "2px 8px" }, children: "Hide" })
|
|
1346
|
+
] }),
|
|
1347
|
+
/* @__PURE__ */ jsx3("ol", { style: { ...FONT2, listStyle: "none", margin: 0, padding: 0, overflowY: "auto", flex: 1 }, children: props.entries.map((entry) => /* @__PURE__ */ jsx3("li", { style: { borderBottom: `1px solid ${LINE}` }, children: /* @__PURE__ */ jsxs2(
|
|
1348
|
+
"button",
|
|
1349
|
+
{
|
|
1350
|
+
type: "button",
|
|
1351
|
+
onClick: () => props.onEdit(entry.id),
|
|
1352
|
+
style: { ...FONT2, display: "flex", gap: 8, width: "100%", textAlign: "left", background: "none", border: 0, padding: "8px 10px", cursor: "pointer" },
|
|
1353
|
+
children: [
|
|
1354
|
+
/* @__PURE__ */ jsx3("span", { style: { ...FONT2, color: ACCENT, fontWeight: 700, minWidth: 16 }, children: entry.number }),
|
|
1355
|
+
/* @__PURE__ */ jsxs2("span", { style: { ...FONT2, flex: 1, minWidth: 0 }, children: [
|
|
1356
|
+
/* @__PURE__ */ jsx3("span", { style: { ...FONT2, display: "block", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: entry.comment }),
|
|
1357
|
+
/* @__PURE__ */ jsxs2("span", { style: { ...FONT2, display: "block", fontSize: 11, color: MUTED, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: [
|
|
1358
|
+
entry.where,
|
|
1359
|
+
entry.onThisPage ? "" : " \xB7 other page"
|
|
1360
|
+
] })
|
|
1361
|
+
] })
|
|
1362
|
+
]
|
|
1363
|
+
}
|
|
1364
|
+
) }, entry.id)) }),
|
|
1365
|
+
/* @__PURE__ */ jsxs2("div", { style: { padding: 10, display: "flex", alignItems: "center", gap: 8 }, children: [
|
|
1366
|
+
/* @__PURE__ */ jsxs2("label", { style: { ...FONT2, display: "flex", gap: 6, alignItems: "center", fontSize: 12, color: MUTED, cursor: "pointer", flex: 1 }, children: [
|
|
1367
|
+
/* @__PURE__ */ jsx3("input", { type: "checkbox", checked: props.includeData, onChange: (event) => props.onIncludeData(event.target.checked) }),
|
|
1368
|
+
"Include props/state (",
|
|
1369
|
+
props.redactionOn ? "personal data redacted" : "redaction off",
|
|
1370
|
+
")"
|
|
1371
|
+
] }),
|
|
1372
|
+
/* @__PURE__ */ jsx3("button", { type: "button", onClick: props.onClear, style: { ...BUTTON, color: "#B42318" }, children: "Clear all" })
|
|
1373
|
+
] })
|
|
1374
|
+
]
|
|
1375
|
+
}
|
|
1376
|
+
);
|
|
1377
|
+
}
|
|
1378
|
+
function Callouts(props) {
|
|
1379
|
+
return /* @__PURE__ */ jsx3(Fragment, { children: props.callouts.map((callout) => /* @__PURE__ */ jsxs2("div", { children: [
|
|
1380
|
+
/* @__PURE__ */ jsx3(
|
|
1381
|
+
"div",
|
|
1382
|
+
{
|
|
1383
|
+
style: {
|
|
1384
|
+
position: "fixed",
|
|
1385
|
+
top: callout.box.top,
|
|
1386
|
+
left: callout.box.left,
|
|
1387
|
+
width: callout.box.width,
|
|
1388
|
+
height: callout.box.height,
|
|
1389
|
+
border: `2px ${callout.area === true ? "dashed" : "solid"} ${ACCENT}`,
|
|
1390
|
+
background: callout.area === true ? "rgba(217, 119, 87, 0.08)" : "transparent",
|
|
1391
|
+
borderRadius: 3,
|
|
1392
|
+
pointerEvents: "none",
|
|
1393
|
+
zIndex: Z,
|
|
1394
|
+
boxSizing: "border-box"
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
),
|
|
1398
|
+
/* @__PURE__ */ jsxs2(
|
|
1399
|
+
"button",
|
|
1400
|
+
{
|
|
1401
|
+
type: "button",
|
|
1402
|
+
"aria-label": `Comment ${callout.number}: ${callout.comment}`,
|
|
1403
|
+
onClick: props.onEdit === null ? void 0 : () => props.onEdit?.(callout.number),
|
|
1404
|
+
style: {
|
|
1405
|
+
...FONT2,
|
|
1406
|
+
position: "fixed",
|
|
1407
|
+
top: callout.card.top,
|
|
1408
|
+
left: callout.card.left,
|
|
1409
|
+
width: callout.card.width,
|
|
1410
|
+
maxHeight: callout.card.height,
|
|
1411
|
+
display: "flex",
|
|
1412
|
+
gap: 8,
|
|
1413
|
+
alignItems: "flex-start",
|
|
1414
|
+
textAlign: "left",
|
|
1415
|
+
padding: "7px 10px",
|
|
1416
|
+
background: "#FFFFFF",
|
|
1417
|
+
border: `1.5px solid ${ACCENT}`,
|
|
1418
|
+
borderRadius: 8,
|
|
1419
|
+
boxShadow: "0 4px 14px rgba(0,0,0,0.18)",
|
|
1420
|
+
cursor: props.onEdit === null ? "default" : "pointer",
|
|
1421
|
+
zIndex: Z + 1,
|
|
1422
|
+
boxSizing: "border-box",
|
|
1423
|
+
overflow: "hidden"
|
|
1424
|
+
},
|
|
1425
|
+
children: [
|
|
1426
|
+
/* @__PURE__ */ jsx3(
|
|
1427
|
+
"span",
|
|
1428
|
+
{
|
|
1429
|
+
style: {
|
|
1430
|
+
...FONT2,
|
|
1431
|
+
flex: "none",
|
|
1432
|
+
minWidth: 18,
|
|
1433
|
+
height: 18,
|
|
1434
|
+
borderRadius: 9,
|
|
1435
|
+
background: ACCENT,
|
|
1436
|
+
color: "#FFFFFF",
|
|
1437
|
+
fontSize: 11,
|
|
1438
|
+
fontWeight: 700,
|
|
1439
|
+
lineHeight: "18px",
|
|
1440
|
+
textAlign: "center"
|
|
1441
|
+
},
|
|
1442
|
+
children: callout.number
|
|
1443
|
+
}
|
|
1444
|
+
),
|
|
1445
|
+
/* @__PURE__ */ jsx3(
|
|
1446
|
+
"span",
|
|
1447
|
+
{
|
|
1448
|
+
style: {
|
|
1449
|
+
...FONT2,
|
|
1450
|
+
lineHeight: "18px",
|
|
1451
|
+
whiteSpace: "pre-wrap",
|
|
1452
|
+
overflowWrap: "anywhere",
|
|
1453
|
+
display: "-webkit-box",
|
|
1454
|
+
WebkitBoxOrient: "vertical",
|
|
1455
|
+
WebkitLineClamp: CARD_LINES,
|
|
1456
|
+
overflow: "hidden"
|
|
1457
|
+
},
|
|
1458
|
+
children: callout.comment
|
|
1459
|
+
}
|
|
1460
|
+
)
|
|
1461
|
+
]
|
|
1462
|
+
}
|
|
1463
|
+
)
|
|
1464
|
+
] }, callout.number)) });
|
|
1465
|
+
}
|
|
1466
|
+
function Toast(props) {
|
|
1467
|
+
const error = props.notice.tone === "error";
|
|
1468
|
+
return /* @__PURE__ */ jsxs2(
|
|
1469
|
+
"div",
|
|
1470
|
+
{
|
|
1471
|
+
role: "status",
|
|
1472
|
+
"aria-live": "polite",
|
|
1473
|
+
onClick: props.onDismiss,
|
|
1474
|
+
style: {
|
|
1475
|
+
...FONT2,
|
|
1476
|
+
position: "fixed",
|
|
1477
|
+
left: "50%",
|
|
1478
|
+
bottom: 24,
|
|
1479
|
+
transform: "translateX(-50%)",
|
|
1480
|
+
width: "max-content",
|
|
1481
|
+
maxWidth: "min(420px, calc(100vw - 32px))",
|
|
1482
|
+
display: "flex",
|
|
1483
|
+
gap: 10,
|
|
1484
|
+
alignItems: "flex-start",
|
|
1485
|
+
padding: "10px 14px",
|
|
1486
|
+
background: INK,
|
|
1487
|
+
color: "#FFFFFF",
|
|
1488
|
+
borderRadius: 10,
|
|
1489
|
+
boxShadow: "0 8px 24px rgba(0,0,0,0.3)",
|
|
1490
|
+
// Above the screenshot editor, which reports through it.
|
|
1491
|
+
zIndex: Z + 6,
|
|
1492
|
+
cursor: "pointer"
|
|
1493
|
+
},
|
|
1494
|
+
children: [
|
|
1495
|
+
/* @__PURE__ */ jsx3("span", { style: { ...FONT2, color: error ? "#FF8A80" : "#7EE2A8", fontWeight: 700 }, children: error ? "!" : "\u2713" }),
|
|
1496
|
+
/* @__PURE__ */ jsxs2("span", { style: { ...FONT2, color: "#FFFFFF" }, children: [
|
|
1497
|
+
/* @__PURE__ */ jsx3("strong", { style: { ...FONT2, display: "block", color: "#FFFFFF", fontWeight: 600 }, children: props.notice.title }),
|
|
1498
|
+
props.notice.detail === void 0 ? null : /* @__PURE__ */ jsx3("span", { style: { ...FONT2, display: "block", color: "#D6D3CE", fontSize: 12 }, children: props.notice.detail })
|
|
1499
|
+
] })
|
|
1500
|
+
]
|
|
1501
|
+
}
|
|
1502
|
+
);
|
|
1503
|
+
}
|
|
1504
|
+
function Toolbar(props) {
|
|
1505
|
+
const none = props.count === 0;
|
|
1506
|
+
if (props.collapsed) return /* @__PURE__ */ jsx3(CollapsedToolbar, { ...props });
|
|
1507
|
+
return /* @__PURE__ */ jsxs2(
|
|
1508
|
+
"div",
|
|
1509
|
+
{
|
|
1510
|
+
role: "toolbar",
|
|
1511
|
+
"aria-label": "Dev annotator",
|
|
1512
|
+
style: {
|
|
1513
|
+
...FONT2,
|
|
1514
|
+
position: "fixed",
|
|
1515
|
+
right: 16,
|
|
1516
|
+
bottom: 16,
|
|
1517
|
+
display: "flex",
|
|
1518
|
+
alignItems: "center",
|
|
1519
|
+
gap: 2,
|
|
1520
|
+
padding: 4,
|
|
1521
|
+
background: INK,
|
|
1522
|
+
borderRadius: 12,
|
|
1523
|
+
boxShadow: "0 6px 20px rgba(0,0,0,0.28)",
|
|
1524
|
+
zIndex: Z + 2
|
|
1525
|
+
},
|
|
1526
|
+
children: [
|
|
1527
|
+
/* @__PURE__ */ jsx3(
|
|
1528
|
+
ToolButton,
|
|
1529
|
+
{
|
|
1530
|
+
icon: "comment",
|
|
1531
|
+
label: props.active ? "Turn off comment mode" : "Turn on comment mode",
|
|
1532
|
+
hint: "Click an element, select text, \u2318/Ctrl+click several or Shift+drag an area to comment on it.",
|
|
1533
|
+
shortcut: props.active ? "Esc" : "Alt+Shift+C",
|
|
1534
|
+
pressed: props.active,
|
|
1535
|
+
accent: true,
|
|
1536
|
+
onClick: props.onToggleActive
|
|
1537
|
+
}
|
|
1538
|
+
),
|
|
1539
|
+
/* @__PURE__ */ jsx3(
|
|
1540
|
+
ToolButton,
|
|
1541
|
+
{
|
|
1542
|
+
icon: props.paused ? "play" : "pause",
|
|
1543
|
+
label: props.paused ? "Resume animations" : "Pause animations",
|
|
1544
|
+
hint: props.paused ? "Resume animations and videos" : "Pause animations and videos to comment on the current frame",
|
|
1545
|
+
pressed: props.paused,
|
|
1546
|
+
onClick: props.onTogglePaused
|
|
1547
|
+
}
|
|
1548
|
+
),
|
|
1549
|
+
/* @__PURE__ */ jsx3(
|
|
1550
|
+
ToolButton,
|
|
1551
|
+
{
|
|
1552
|
+
icon: "eye",
|
|
1553
|
+
label: props.showComments ? "Show comments as numbers" : "Show comments in full",
|
|
1554
|
+
hint: props.showComments ? "Collapse comments back to numbered pins" : "Show every comment beside its element",
|
|
1555
|
+
pressed: props.showComments,
|
|
1556
|
+
disabled: none,
|
|
1557
|
+
onClick: props.onToggleComments
|
|
1558
|
+
}
|
|
1559
|
+
),
|
|
1560
|
+
/* @__PURE__ */ jsx3(
|
|
1561
|
+
ToolButton,
|
|
1562
|
+
{
|
|
1563
|
+
icon: "camera",
|
|
1564
|
+
label: "Screenshot",
|
|
1565
|
+
hint: "Capture this tab with every comment shown, then mark it up",
|
|
1566
|
+
disabled: props.capturing,
|
|
1567
|
+
onClick: props.onScreenshot
|
|
1568
|
+
}
|
|
1569
|
+
),
|
|
1570
|
+
/* @__PURE__ */ jsx3(
|
|
1571
|
+
ToolButton,
|
|
1572
|
+
{
|
|
1573
|
+
icon: props.redactionOn ? "shield" : "shieldOff",
|
|
1574
|
+
label: "Redaction settings",
|
|
1575
|
+
hint: props.redactionOn ? "Personal data is redacted from the prompt. Choose countries or add your own patterns." : "Redaction is OFF: new comments carry personal data as the page shows it.",
|
|
1576
|
+
pressed: props.settingsOpen,
|
|
1577
|
+
onClick: props.onToggleSettings
|
|
1578
|
+
}
|
|
1579
|
+
),
|
|
1580
|
+
/* @__PURE__ */ jsx3(Divider, {}),
|
|
1581
|
+
/* @__PURE__ */ jsx3(
|
|
1582
|
+
Tooltip,
|
|
1583
|
+
{
|
|
1584
|
+
label: props.panelOpen && !none ? "Hide comment list" : "Comment list",
|
|
1585
|
+
detail: none ? "No comments yet." : "Every comment, on this page and others; click one to edit it.",
|
|
1586
|
+
placement: "above",
|
|
1587
|
+
children: (describedBy) => /* @__PURE__ */ jsxs2(
|
|
1588
|
+
"button",
|
|
1589
|
+
{
|
|
1590
|
+
type: "button",
|
|
1591
|
+
onClick: props.onTogglePanel,
|
|
1592
|
+
disabled: none,
|
|
1593
|
+
"aria-pressed": props.panelOpen && !none,
|
|
1594
|
+
"aria-label": `Comment list (${props.count})`,
|
|
1595
|
+
"aria-describedby": describedBy,
|
|
1596
|
+
style: { ...barButton(props.panelOpen && !none, false, none), gap: 6, padding: "0 10px" },
|
|
1597
|
+
children: [
|
|
1598
|
+
/* @__PURE__ */ jsx3(Icon, { name: "list" }),
|
|
1599
|
+
/* @__PURE__ */ jsx3("span", { style: { ...FONT2, color: "inherit", fontWeight: 600 }, children: props.count })
|
|
1600
|
+
]
|
|
1601
|
+
}
|
|
1602
|
+
)
|
|
1603
|
+
}
|
|
1604
|
+
),
|
|
1605
|
+
/* @__PURE__ */ jsx3(
|
|
1606
|
+
Tooltip,
|
|
1607
|
+
{
|
|
1608
|
+
label: "Copy prompt",
|
|
1609
|
+
detail: none ? "Add a comment first." : "Every comment as one Markdown prompt for your coding agent.",
|
|
1610
|
+
placement: "above",
|
|
1611
|
+
children: (describedBy) => /* @__PURE__ */ jsxs2(
|
|
1612
|
+
"button",
|
|
1613
|
+
{
|
|
1614
|
+
type: "button",
|
|
1615
|
+
onClick: props.onCopy,
|
|
1616
|
+
disabled: none,
|
|
1617
|
+
"aria-describedby": describedBy,
|
|
1618
|
+
style: {
|
|
1619
|
+
...barButton(false, false, none),
|
|
1620
|
+
gap: 6,
|
|
1621
|
+
padding: "0 12px",
|
|
1622
|
+
background: none ? "transparent" : ACCENT,
|
|
1623
|
+
color: "#FFFFFF"
|
|
1624
|
+
},
|
|
1625
|
+
children: [
|
|
1626
|
+
/* @__PURE__ */ jsx3(Icon, { name: "copy", size: 16 }),
|
|
1627
|
+
/* @__PURE__ */ jsx3("span", { style: { ...FONT2, color: "inherit", fontWeight: 600 }, children: "Copy prompt" })
|
|
1628
|
+
]
|
|
1629
|
+
}
|
|
1630
|
+
)
|
|
1631
|
+
}
|
|
1632
|
+
),
|
|
1633
|
+
props.onShowHint === null ? null : /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1634
|
+
/* @__PURE__ */ jsx3(Divider, {}),
|
|
1635
|
+
/* @__PURE__ */ jsx3(ToolButton, { icon: "help", label: "Show hint", hint: "Show the comment-mode shortcuts", onClick: props.onShowHint })
|
|
1636
|
+
] }),
|
|
1637
|
+
/* @__PURE__ */ jsx3(Divider, {}),
|
|
1638
|
+
/* @__PURE__ */ jsx3(ToolButton, { icon: "collapse", label: "Collapse toolbar", hint: "Fold the toolbar into one button. Alt+Shift+C still works.", onClick: props.onToggleCollapsed })
|
|
1639
|
+
]
|
|
1640
|
+
}
|
|
1641
|
+
);
|
|
1642
|
+
}
|
|
1643
|
+
function CollapsedToolbar(props) {
|
|
1644
|
+
const detail = [
|
|
1645
|
+
props.count === 0 ? "No comments yet." : `${props.count} comment${props.count === 1 ? "" : "s"}.`,
|
|
1646
|
+
props.active ? "Comment mode is on." : null
|
|
1647
|
+
].filter(Boolean).join(" ");
|
|
1648
|
+
return /* @__PURE__ */ jsx3("div", { role: "toolbar", "aria-label": "Dev annotator", style: { position: "fixed", right: 16, bottom: 16, zIndex: Z + 2 }, children: /* @__PURE__ */ jsx3(Tooltip, { label: "Expand toolbar", detail, placement: "above", children: (describedBy) => /* @__PURE__ */ jsxs2(
|
|
1649
|
+
"button",
|
|
1650
|
+
{
|
|
1651
|
+
type: "button",
|
|
1652
|
+
onClick: props.onToggleCollapsed,
|
|
1653
|
+
"aria-label": "Expand toolbar",
|
|
1654
|
+
"aria-describedby": describedBy,
|
|
1655
|
+
style: {
|
|
1656
|
+
...barButton(false, false, false),
|
|
1657
|
+
position: "relative",
|
|
1658
|
+
width: 44,
|
|
1659
|
+
height: 44,
|
|
1660
|
+
borderRadius: 22,
|
|
1661
|
+
background: INK,
|
|
1662
|
+
boxShadow: props.active ? `0 0 0 2px ${ACCENT}, 0 6px 20px rgba(0,0,0,0.28)` : "0 6px 20px rgba(0,0,0,0.28)"
|
|
1663
|
+
},
|
|
1664
|
+
children: [
|
|
1665
|
+
/* @__PURE__ */ jsx3(Icon, { name: "comment" }),
|
|
1666
|
+
props.count === 0 ? null : /* @__PURE__ */ jsx3(
|
|
1667
|
+
"span",
|
|
1668
|
+
{
|
|
1669
|
+
"aria-hidden": "true",
|
|
1670
|
+
style: {
|
|
1671
|
+
...FONT2,
|
|
1672
|
+
position: "absolute",
|
|
1673
|
+
top: -4,
|
|
1674
|
+
right: -4,
|
|
1675
|
+
minWidth: 18,
|
|
1676
|
+
height: 18,
|
|
1677
|
+
padding: "0 5px",
|
|
1678
|
+
borderRadius: 9,
|
|
1679
|
+
background: ACCENT,
|
|
1680
|
+
color: "#FFFFFF",
|
|
1681
|
+
fontSize: 11,
|
|
1682
|
+
fontWeight: 700,
|
|
1683
|
+
lineHeight: "18px",
|
|
1684
|
+
textAlign: "center",
|
|
1685
|
+
boxSizing: "border-box"
|
|
1686
|
+
},
|
|
1687
|
+
children: props.count
|
|
1688
|
+
}
|
|
1689
|
+
)
|
|
1690
|
+
]
|
|
1691
|
+
}
|
|
1692
|
+
) }) });
|
|
1693
|
+
}
|
|
1694
|
+
function Divider() {
|
|
1695
|
+
return /* @__PURE__ */ jsx3("span", { "aria-hidden": "true", style: { width: 1, height: 20, margin: "0 4px", background: "rgba(255,255,255,0.18)" } });
|
|
1696
|
+
}
|
|
1697
|
+
function barButton(pressed, accent, disabled) {
|
|
1698
|
+
return {
|
|
1699
|
+
...FONT2,
|
|
1700
|
+
appearance: "none",
|
|
1701
|
+
height: 36,
|
|
1702
|
+
minWidth: 36,
|
|
1703
|
+
display: "inline-flex",
|
|
1704
|
+
alignItems: "center",
|
|
1705
|
+
justifyContent: "center",
|
|
1706
|
+
padding: 0,
|
|
1707
|
+
border: 0,
|
|
1708
|
+
borderRadius: 8,
|
|
1709
|
+
cursor: disabled ? "default" : "pointer",
|
|
1710
|
+
opacity: disabled ? 0.4 : 1,
|
|
1711
|
+
color: "#FFFFFF",
|
|
1712
|
+
background: pressed ? accent ? ACCENT : "rgba(255,255,255,0.18)" : "transparent"
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1715
|
+
function ToolButton(props) {
|
|
1716
|
+
return /* @__PURE__ */ jsx3(
|
|
1717
|
+
Tooltip,
|
|
1718
|
+
{
|
|
1719
|
+
label: props.label,
|
|
1720
|
+
...props.hint === void 0 ? {} : { detail: props.hint },
|
|
1721
|
+
...props.shortcut === void 0 ? {} : { shortcut: keyCaps(props.shortcut) },
|
|
1722
|
+
placement: "above",
|
|
1723
|
+
children: (describedBy) => /* @__PURE__ */ jsx3(
|
|
1724
|
+
"button",
|
|
1725
|
+
{
|
|
1726
|
+
type: "button",
|
|
1727
|
+
onClick: props.onClick,
|
|
1728
|
+
disabled: props.disabled,
|
|
1729
|
+
"aria-label": props.label,
|
|
1730
|
+
"aria-describedby": describedBy,
|
|
1731
|
+
...props.pressed === void 0 ? {} : { "aria-pressed": props.pressed },
|
|
1732
|
+
...props.shortcut === void 0 ? {} : { "aria-keyshortcuts": props.shortcut === "Esc" ? "Escape" : props.shortcut },
|
|
1733
|
+
style: barButton(props.pressed === true, props.accent === true, props.disabled === true),
|
|
1734
|
+
children: /* @__PURE__ */ jsx3(Icon, { name: props.icon })
|
|
1735
|
+
}
|
|
1736
|
+
)
|
|
1737
|
+
}
|
|
1738
|
+
);
|
|
1739
|
+
}
|
|
1740
|
+
function keyCaps(shortcut) {
|
|
1741
|
+
const mac = MOD_KEY === "\u2318";
|
|
1742
|
+
const names = mac ? { Alt: "\u2325", Shift: "\u21E7", Ctrl: "\u2303", Meta: "\u2318" } : {};
|
|
1743
|
+
return shortcut.split("+").map((key) => names[key] ?? key);
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
// src/redaction-panel.tsx
|
|
1747
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1748
|
+
var LABEL = { ...FONT2, display: "flex", gap: 8, alignItems: "flex-start", cursor: "pointer" };
|
|
1749
|
+
function RedactionPanel(props) {
|
|
1750
|
+
const { settings } = props;
|
|
1751
|
+
const off = !settings.enabled;
|
|
1752
|
+
const update = (patch) => props.onChange({ ...settings, ...patch });
|
|
1753
|
+
const toggleCountry = (country, on) => update({ countries: COUNTRIES.filter((each) => each === country ? on : settings.countries.includes(each)) });
|
|
1754
|
+
const errors = settings.patterns.flatMap((source, index) => {
|
|
1755
|
+
if (source.trim() === "") return [];
|
|
1756
|
+
const compiled = compilePattern(source);
|
|
1757
|
+
return typeof compiled === "string" ? [`Line ${index + 1}: ${compiled}`] : [];
|
|
1758
|
+
});
|
|
1759
|
+
return /* @__PURE__ */ jsxs3(
|
|
1760
|
+
"div",
|
|
1761
|
+
{
|
|
1762
|
+
role: "dialog",
|
|
1763
|
+
"aria-label": "Redaction settings",
|
|
1764
|
+
style: {
|
|
1765
|
+
...FONT2,
|
|
1766
|
+
position: "fixed",
|
|
1767
|
+
right: 16,
|
|
1768
|
+
bottom: 72,
|
|
1769
|
+
width: 340,
|
|
1770
|
+
maxHeight: "70vh",
|
|
1771
|
+
overflowY: "auto",
|
|
1772
|
+
background: "#FFFFFF",
|
|
1773
|
+
border: `1px solid ${LINE}`,
|
|
1774
|
+
borderRadius: 10,
|
|
1775
|
+
boxShadow: "0 8px 24px rgba(0,0,0,0.18)",
|
|
1776
|
+
zIndex: Z + 2,
|
|
1777
|
+
boxSizing: "border-box"
|
|
1778
|
+
},
|
|
1779
|
+
children: [
|
|
1780
|
+
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", padding: "8px 10px", borderBottom: `1px solid ${LINE}` }, children: [
|
|
1781
|
+
/* @__PURE__ */ jsx4("strong", { style: { ...FONT2, fontWeight: 600 }, children: "Personal data redaction" }),
|
|
1782
|
+
/* @__PURE__ */ jsx4("button", { type: "button", onClick: props.onClose, "aria-label": "Close redaction settings", style: { ...BUTTON, marginLeft: "auto", padding: "2px 8px" }, children: "Close" })
|
|
1783
|
+
] }),
|
|
1784
|
+
/* @__PURE__ */ jsxs3("div", { style: { ...FONT2, padding: 10, display: "flex", flexDirection: "column", gap: 12 }, children: [
|
|
1785
|
+
/* @__PURE__ */ jsxs3("label", { style: { ...LABEL, alignItems: "center" }, children: [
|
|
1786
|
+
/* @__PURE__ */ jsx4(
|
|
1787
|
+
"input",
|
|
1788
|
+
{
|
|
1789
|
+
type: "checkbox",
|
|
1790
|
+
role: "switch",
|
|
1791
|
+
checked: settings.enabled,
|
|
1792
|
+
"aria-checked": settings.enabled,
|
|
1793
|
+
onChange: (event) => update({ enabled: event.target.checked })
|
|
1794
|
+
}
|
|
1795
|
+
),
|
|
1796
|
+
/* @__PURE__ */ jsx4("span", { style: { ...FONT2, fontWeight: 600 }, children: "Redact personal data" })
|
|
1797
|
+
] }),
|
|
1798
|
+
/* @__PURE__ */ jsx4("p", { style: { ...FONT2, margin: 0, fontSize: 12, color: off ? "#B42318" : MUTED }, children: off ? "Off: new comments carry props, state and page text exactly as the page shows them. Password fields stay hidden." : "Values under keys like phone, email, name, address, ID, password or token, and every e-mail address, become [redacted]." }),
|
|
1799
|
+
/* @__PURE__ */ jsxs3("fieldset", { disabled: off, style: { ...FONT2, margin: 0, padding: 0, border: 0, opacity: off ? 0.5 : 1 }, children: [
|
|
1800
|
+
/* @__PURE__ */ jsx4("legend", { style: { ...FONT2, padding: 0, marginBottom: 6, fontWeight: 600 }, children: "Number formats" }),
|
|
1801
|
+
/* @__PURE__ */ jsx4("div", { style: { display: "flex", flexDirection: "column", gap: 6 }, children: COUNTRIES.map((country) => /* @__PURE__ */ jsxs3("label", { style: LABEL, children: [
|
|
1802
|
+
/* @__PURE__ */ jsx4(
|
|
1803
|
+
"input",
|
|
1804
|
+
{
|
|
1805
|
+
type: "checkbox",
|
|
1806
|
+
checked: settings.countries.includes(country),
|
|
1807
|
+
onChange: (event) => toggleCountry(country, event.target.checked),
|
|
1808
|
+
style: { marginTop: 3 }
|
|
1809
|
+
}
|
|
1810
|
+
),
|
|
1811
|
+
/* @__PURE__ */ jsxs3("span", { style: FONT2, children: [
|
|
1812
|
+
COUNTRY_RULES[country].label,
|
|
1813
|
+
/* @__PURE__ */ jsx4("span", { style: { ...FONT2, display: "block", fontSize: 11, color: MUTED }, children: COUNTRY_RULES[country].covers })
|
|
1814
|
+
] })
|
|
1815
|
+
] }, country)) })
|
|
1816
|
+
] }),
|
|
1817
|
+
/* @__PURE__ */ jsxs3("fieldset", { disabled: off, style: { ...FONT2, margin: 0, padding: 0, border: 0, opacity: off ? 0.5 : 1 }, children: [
|
|
1818
|
+
/* @__PURE__ */ jsx4("legend", { style: { ...FONT2, padding: 0, marginBottom: 4, fontWeight: 600 }, children: "Your own patterns" }),
|
|
1819
|
+
/* @__PURE__ */ jsxs3("label", { htmlFor: "agent-annotator-patterns", style: { ...FONT2, display: "block", fontSize: 11, color: MUTED, marginBottom: 4 }, children: [
|
|
1820
|
+
"One regular expression per line, e.g. ",
|
|
1821
|
+
/* @__PURE__ */ jsxs3("code", { children: [
|
|
1822
|
+
"INV-\\d",
|
|
1823
|
+
"{6}"
|
|
1824
|
+
] }),
|
|
1825
|
+
" or ",
|
|
1826
|
+
/* @__PURE__ */ jsx4("code", { children: "/acct[0-9]+/i" }),
|
|
1827
|
+
"."
|
|
1828
|
+
] }),
|
|
1829
|
+
/* @__PURE__ */ jsx4(
|
|
1830
|
+
"textarea",
|
|
1831
|
+
{
|
|
1832
|
+
id: "agent-annotator-patterns",
|
|
1833
|
+
value: settings.patterns.join("\n"),
|
|
1834
|
+
onChange: (event) => update({ patterns: event.target.value === "" ? [] : event.target.value.split("\n") }),
|
|
1835
|
+
rows: 3,
|
|
1836
|
+
spellCheck: false,
|
|
1837
|
+
"aria-invalid": errors.length > 0,
|
|
1838
|
+
style: {
|
|
1839
|
+
...FONT2,
|
|
1840
|
+
width: "100%",
|
|
1841
|
+
boxSizing: "border-box",
|
|
1842
|
+
fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
1843
|
+
fontSize: 12,
|
|
1844
|
+
padding: 6,
|
|
1845
|
+
border: `1px solid ${errors.length > 0 ? "#B42318" : LINE}`,
|
|
1846
|
+
borderRadius: 6,
|
|
1847
|
+
resize: "vertical"
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
),
|
|
1851
|
+
errors.length > 0 ? /* @__PURE__ */ jsx4("ul", { role: "alert", style: { ...FONT2, margin: "4px 0 0", paddingLeft: 16, fontSize: 11, color: "#B42318" }, children: errors.map((error) => /* @__PURE__ */ jsxs3("li", { children: [
|
|
1852
|
+
error,
|
|
1853
|
+
" \u2014 skipped"
|
|
1854
|
+
] }, error)) }) : null
|
|
1855
|
+
] }),
|
|
1856
|
+
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", gap: 8 }, children: [
|
|
1857
|
+
/* @__PURE__ */ jsx4("span", { style: { ...FONT2, flex: 1, fontSize: 11, color: MUTED }, children: "Applies to comments made from now on. Saved in this browser." }),
|
|
1858
|
+
/* @__PURE__ */ jsx4(
|
|
1859
|
+
"button",
|
|
1860
|
+
{
|
|
1861
|
+
type: "button",
|
|
1862
|
+
onClick: props.onReset,
|
|
1863
|
+
disabled: !props.customised,
|
|
1864
|
+
style: { ...BUTTON, color: props.customised ? ACCENT : MUTED, cursor: props.customised ? "pointer" : "default" },
|
|
1865
|
+
children: "Use app defaults"
|
|
1866
|
+
}
|
|
1867
|
+
)
|
|
1868
|
+
] })
|
|
1869
|
+
] })
|
|
1870
|
+
]
|
|
1871
|
+
}
|
|
1872
|
+
);
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
// src/page-tools.ts
|
|
1876
|
+
var OWN_SELECTOR = "[data-dev-annotator]";
|
|
1877
|
+
var MAX_AREA_ELEMENTS = 8;
|
|
1878
|
+
function contains(outer, inner) {
|
|
1879
|
+
return inner.left >= outer.x && inner.top >= outer.y && inner.right <= outer.x + outer.width && inner.bottom <= outer.y + outer.height;
|
|
1880
|
+
}
|
|
1881
|
+
function holds(rect, area) {
|
|
1882
|
+
return rect.left <= area.x && rect.top <= area.y && rect.right >= area.x + area.width && rect.bottom >= area.y + area.height;
|
|
1883
|
+
}
|
|
1884
|
+
function isContent(element) {
|
|
1885
|
+
if (element.closest(OWN_SELECTOR) !== null) return false;
|
|
1886
|
+
if (element.closest('[aria-hidden="true"]') !== null) return false;
|
|
1887
|
+
return !(element instanceof SVGElement) || element instanceof SVGSVGElement;
|
|
1888
|
+
}
|
|
1889
|
+
function commonAncestor(elements) {
|
|
1890
|
+
const [first, ...rest] = elements;
|
|
1891
|
+
let node = first ?? null;
|
|
1892
|
+
while (node !== null && !rest.every((element) => node?.contains(element))) node = node.parentElement;
|
|
1893
|
+
return node;
|
|
1894
|
+
}
|
|
1895
|
+
function coveringAncestor(start, area, body) {
|
|
1896
|
+
let node = start;
|
|
1897
|
+
while (node !== null && node !== body && !holds(node.getBoundingClientRect(), area)) node = node.parentElement;
|
|
1898
|
+
return node ?? body;
|
|
1899
|
+
}
|
|
1900
|
+
function elementsInArea(doc, area) {
|
|
1901
|
+
const inside2 = [];
|
|
1902
|
+
for (const element of Array.from(doc.body.querySelectorAll("*"))) {
|
|
1903
|
+
if (!isContent(element)) continue;
|
|
1904
|
+
const rect = element.getBoundingClientRect();
|
|
1905
|
+
if (rect.width === 0 || rect.height === 0) continue;
|
|
1906
|
+
if (contains(area, rect) && !inside2.some((kept) => kept.contains(element))) inside2.push(element);
|
|
1907
|
+
}
|
|
1908
|
+
let start;
|
|
1909
|
+
if (inside2.length > 0) {
|
|
1910
|
+
const common = commonAncestor(inside2);
|
|
1911
|
+
start = inside2.length === 1 ? common?.parentElement ?? null : common;
|
|
1912
|
+
} else {
|
|
1913
|
+
const centre = { x: area.x + area.width / 2, y: area.y + area.height / 2 };
|
|
1914
|
+
const under = typeof doc.elementsFromPoint === "function" ? doc.elementsFromPoint(centre.x, centre.y) : [];
|
|
1915
|
+
start = under.find(isContent) ?? null;
|
|
1916
|
+
}
|
|
1917
|
+
return { container: coveringAncestor(start, area, doc.body), inside: inside2.slice(0, MAX_AREA_ELEMENTS) };
|
|
1918
|
+
}
|
|
1919
|
+
function pauseMotion(doc) {
|
|
1920
|
+
const animations = typeof doc.getAnimations === "function" ? doc.getAnimations().filter((animation) => animation.playState === "running") : [];
|
|
1921
|
+
const videos = Array.from(doc.querySelectorAll("video")).filter((video) => !video.paused);
|
|
1922
|
+
for (const animation of animations) animation.pause();
|
|
1923
|
+
for (const video of videos) video.pause();
|
|
1924
|
+
return () => {
|
|
1925
|
+
for (const animation of animations) animation.play();
|
|
1926
|
+
for (const video of videos) void video.play().catch(() => void 0);
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
// src/prompt.ts
|
|
1931
|
+
var DATA_BLOCK_MAX = 3e3;
|
|
1932
|
+
function buildPrompt(annotations, options) {
|
|
1933
|
+
const first = annotations[0]?.targets[0]?.page;
|
|
1934
|
+
const origin = first === void 0 ? "" : new URL(first.url).origin;
|
|
1935
|
+
const lines = [
|
|
1936
|
+
`# Change requests: ${options.appName} (${annotations.length} ${annotations.length === 1 ? "comment" : "comments"})`,
|
|
1937
|
+
"",
|
|
1938
|
+
`Dev environment ${origin}, recorded ${formatTime(options.now)}.` + (options.appDir ? ` The app lives in \`${options.appDir}\`; file paths are from the repo root.` : ""),
|
|
1939
|
+
"",
|
|
1940
|
+
"Work through the comments below one by one. Each names the selected element, where its JSX is in the source, the components around it" + (options.includeData ? ", and their props/state when the comment was made" : "") + `. The element's JSX location is exact; a component's "rendered at" location may point at an earlier render branch when React reused the component, so check it against the code. Open the source file before editing. If the line numbers have drifted, search by selector, element text and component name. ` + redactionNote(annotations) + "When done, summarise the changes by comment number."
|
|
1941
|
+
];
|
|
1942
|
+
annotations.forEach((annotation, index) => {
|
|
1943
|
+
lines.push("", "---", "", ...section(annotation, index + 1, options));
|
|
1944
|
+
});
|
|
1945
|
+
return `${lines.join("\n")}
|
|
1946
|
+
`;
|
|
1947
|
+
}
|
|
1948
|
+
function redactionNote(annotations) {
|
|
1949
|
+
const raw = annotations.flatMap((annotation, index) => annotation.redacted === false ? [index + 1] : []);
|
|
1950
|
+
if (raw.length === annotations.length && raw.length > 0) return "";
|
|
1951
|
+
const except = raw.length === 0 ? "" : ` (except in comment${raw.length === 1 ? "" : "s"} ${raw.join(", ")}, recorded with redaction off)`;
|
|
1952
|
+
return `Personal data has been replaced with \`${REDACTED}\`${except}; never treat it as a real value. `;
|
|
1953
|
+
}
|
|
1954
|
+
var KIND_NOTE = {
|
|
1955
|
+
element: null,
|
|
1956
|
+
text: null,
|
|
1957
|
+
group: "The comment applies to ALL of the elements below.",
|
|
1958
|
+
area: "A comment on an area of the screen: the first element contains the area, the others lie wholly inside it."
|
|
1959
|
+
};
|
|
1960
|
+
function section(annotation, number, options) {
|
|
1961
|
+
const page = annotation.targets[0]?.page;
|
|
1962
|
+
const out = [
|
|
1963
|
+
`## ${number}. ${headline(annotation.comment)}`,
|
|
1964
|
+
"",
|
|
1965
|
+
...annotation.comment.split("\n").map((line) => `> ${line}`),
|
|
1966
|
+
""
|
|
1967
|
+
];
|
|
1968
|
+
if (page !== void 0) {
|
|
1969
|
+
out.push(`- **Page:** \`${page.pathname}${page.search}\`${page.title ? `, title "${page.title}"` : ""}`);
|
|
1970
|
+
}
|
|
1971
|
+
const note = KIND_NOTE[annotation.kind];
|
|
1972
|
+
if (note !== null) out.push(`- **Kind:** ${note}`);
|
|
1973
|
+
if (annotation.selectedText !== void 0) out.push(`- **Selected text:** "${annotation.selectedText}"`);
|
|
1974
|
+
if (annotation.area !== void 0) {
|
|
1975
|
+
const { area } = annotation;
|
|
1976
|
+
out.push(`- **Area:** ${area.width}\xD7${area.height} at (${area.x}, ${area.y}) in the viewport`);
|
|
1977
|
+
}
|
|
1978
|
+
if (annotation.kind !== "area" && annotation.targets.length === 1 && annotation.targets[0] !== void 0) {
|
|
1979
|
+
out.push(...targetLines(annotation.targets[0], options));
|
|
1980
|
+
out.push(...dataBlocks(annotation.targets[0], options));
|
|
1981
|
+
return out;
|
|
1982
|
+
}
|
|
1983
|
+
annotation.targets.forEach((target, index) => {
|
|
1984
|
+
const label = annotation.kind !== "area" ? `Element ${index + 1}` : index === 0 ? "Container" : `Inside the area ${index}`;
|
|
1985
|
+
out.push("", `### ${number}.${index + 1} ${label}`, "", ...targetLines(target, options));
|
|
1986
|
+
out.push(...dataBlocks(target, options));
|
|
1987
|
+
});
|
|
1988
|
+
if (annotation.kind === "area" && annotation.targets.length === 1) {
|
|
1989
|
+
out.push("", "_No element lies wholly inside the area: it is empty space within the container._");
|
|
1990
|
+
}
|
|
1991
|
+
return out;
|
|
1992
|
+
}
|
|
1993
|
+
function targetLines(capture, options) {
|
|
1994
|
+
const { element } = capture;
|
|
1995
|
+
const out = [`- **Element:** \`${element.opening}\`${element.text ? `, text "${element.text}"` : ""}`];
|
|
1996
|
+
if (element.accessibility !== null) out.push(`- **Role (a11y):** ${element.accessibility}`);
|
|
1997
|
+
if (element.section !== null) out.push(`- **Section:** ${element.section}`);
|
|
1998
|
+
if (element.nearby !== null) out.push(`- **Nearby:** ${element.nearby}`);
|
|
1999
|
+
if (element.value !== null) out.push(`- **Current input value:** "${element.value}"`);
|
|
2000
|
+
out.push(`- **Selector:** \`${element.selector}\``);
|
|
2001
|
+
out.push(`- **Element JSX:** ${capture.jsx === null ? "could not be located" : location(capture.jsx, options.appDir)}`);
|
|
2002
|
+
if (capture.components.length > 0) {
|
|
2003
|
+
const chain = capture.components.map(
|
|
2004
|
+
(component) => component.renderedAt === null ? `\`${component.name}\`` : `\`${component.name}\` (rendered at ${location(component.renderedAt, options.appDir)})`
|
|
2005
|
+
);
|
|
2006
|
+
out.push(`- **Components, nearest first:** ${chain.join(" \u2190 ")}`);
|
|
2007
|
+
}
|
|
2008
|
+
out.push(
|
|
2009
|
+
`- **Position:** ${element.rect.width}\xD7${element.rect.height} at (${element.rect.x}, ${element.rect.y}); viewport ${capture.viewport.width}\xD7${capture.viewport.height} @${capture.viewport.devicePixelRatio}x`
|
|
2010
|
+
);
|
|
2011
|
+
const styles = Object.entries(element.styles);
|
|
2012
|
+
if (styles.length > 0) out.push(`- **Current style:** ${styles.map(([key, value]) => `${key}: ${value}`).join("; ")}`);
|
|
2013
|
+
return out;
|
|
2014
|
+
}
|
|
2015
|
+
function dataBlocks(capture, options) {
|
|
2016
|
+
if (!options.includeData) return [];
|
|
2017
|
+
const telling = capture.data.filter((block) => !isEmpty(block.props) || !isEmpty(block.state));
|
|
2018
|
+
return telling.flatMap((block) => [
|
|
2019
|
+
"",
|
|
2020
|
+
`**Data of \`${block.component}\`** (state in hook call order):`,
|
|
2021
|
+
"",
|
|
2022
|
+
"```json",
|
|
2023
|
+
dataJson(block),
|
|
2024
|
+
"```"
|
|
2025
|
+
]);
|
|
2026
|
+
}
|
|
2027
|
+
function dataJson(block) {
|
|
2028
|
+
const value = { props: block.props, state: block.state };
|
|
2029
|
+
const pretty = JSON.stringify(value, null, 2);
|
|
2030
|
+
if (pretty.length <= DATA_BLOCK_MAX) return pretty;
|
|
2031
|
+
const compact = JSON.stringify(value);
|
|
2032
|
+
return compact.length <= DATA_BLOCK_MAX ? compact : `${compact.slice(0, DATA_BLOCK_MAX)} \u2026 (truncated)`;
|
|
2033
|
+
}
|
|
2034
|
+
function location(source, appDir) {
|
|
2035
|
+
const file = repoPath(source.file, appDir);
|
|
2036
|
+
const position = source.column === null ? `${source.line}` : `${source.line}:${source.column}`;
|
|
2037
|
+
return `\`${file}:${position}\`${source.mapped ? "" : " (line in the bundled output, approximate)"}`;
|
|
2038
|
+
}
|
|
2039
|
+
function repoPath(file, appDir) {
|
|
2040
|
+
if (!appDir || /^[a-z]+:/i.test(file)) return file;
|
|
2041
|
+
if (file.startsWith("/")) {
|
|
2042
|
+
const at = file.lastIndexOf(`/${appDir}/`);
|
|
2043
|
+
return at === -1 ? file : file.slice(at + 1);
|
|
2044
|
+
}
|
|
2045
|
+
const parts = [];
|
|
2046
|
+
for (const part of `${appDir}/${file}`.split("/")) {
|
|
2047
|
+
if (part === "" || part === ".") continue;
|
|
2048
|
+
if (part === "..") parts.pop();
|
|
2049
|
+
else parts.push(part);
|
|
2050
|
+
}
|
|
2051
|
+
return parts.join("/");
|
|
2052
|
+
}
|
|
2053
|
+
function headline(comment) {
|
|
2054
|
+
const first = comment.trim().split("\n")[0] ?? "";
|
|
2055
|
+
return first.length <= 70 ? first : `${first.slice(0, 70)}\u2026`;
|
|
2056
|
+
}
|
|
2057
|
+
function formatTime(date) {
|
|
2058
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
2059
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
2060
|
+
}
|
|
2061
|
+
function isEmpty(snapshot) {
|
|
2062
|
+
if (snapshot === null) return true;
|
|
2063
|
+
if (Array.isArray(snapshot)) return snapshot.length === 0;
|
|
2064
|
+
return typeof snapshot === "object" && Object.keys(snapshot).length === 0;
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
// src/flags.ts
|
|
2068
|
+
function readFlag(key) {
|
|
2069
|
+
try {
|
|
2070
|
+
return window.localStorage.getItem(key) === "1";
|
|
2071
|
+
} catch {
|
|
2072
|
+
return false;
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
function writeFlag(key, value) {
|
|
2076
|
+
try {
|
|
2077
|
+
if (value) window.localStorage.setItem(key, "1");
|
|
2078
|
+
else window.localStorage.removeItem(key);
|
|
2079
|
+
} catch {
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
|
|
2083
|
+
// src/screenshot.ts
|
|
2084
|
+
var CaptureCancelled = class extends Error {
|
|
2085
|
+
constructor() {
|
|
2086
|
+
super("Screen capture was cancelled");
|
|
2087
|
+
this.name = "CaptureCancelled";
|
|
2088
|
+
}
|
|
2089
|
+
};
|
|
2090
|
+
var captureTab = async (prepare) => {
|
|
2091
|
+
const media = typeof navigator === "undefined" ? void 0 : navigator.mediaDevices;
|
|
2092
|
+
if (media?.getDisplayMedia === void 0) {
|
|
2093
|
+
throw new Error("This browser cannot capture the tab (it needs the Screen Capture API, on localhost or https).");
|
|
2094
|
+
}
|
|
2095
|
+
const ratio = window.devicePixelRatio || 1;
|
|
2096
|
+
let stream;
|
|
2097
|
+
try {
|
|
2098
|
+
stream = await media.getDisplayMedia({
|
|
2099
|
+
video: {
|
|
2100
|
+
displaySurface: "browser",
|
|
2101
|
+
width: { ideal: Math.round(window.innerWidth * ratio) },
|
|
2102
|
+
height: { ideal: Math.round(window.innerHeight * ratio) },
|
|
2103
|
+
// Not part of the DOM lib yet; Chrome honours it.
|
|
2104
|
+
...{ cursor: "never" }
|
|
2105
|
+
},
|
|
2106
|
+
audio: false,
|
|
2107
|
+
// Chrome: offer this tab first, as a one-click "Allow".
|
|
2108
|
+
...{ preferCurrentTab: true, selfBrowserSurface: "include", surfaceSwitching: "exclude", monitorTypeSurfaces: "exclude" }
|
|
2109
|
+
});
|
|
2110
|
+
} catch (error) {
|
|
2111
|
+
if (error instanceof DOMException && error.name === "NotAllowedError") throw new CaptureCancelled();
|
|
2112
|
+
throw error;
|
|
2113
|
+
}
|
|
2114
|
+
const video = document.createElement("video");
|
|
2115
|
+
try {
|
|
2116
|
+
video.muted = true;
|
|
2117
|
+
video.playsInline = true;
|
|
2118
|
+
video.srcObject = stream;
|
|
2119
|
+
await video.play();
|
|
2120
|
+
await prepare();
|
|
2121
|
+
await freshFrame(video);
|
|
2122
|
+
const canvas = document.createElement("canvas");
|
|
2123
|
+
canvas.width = video.videoWidth;
|
|
2124
|
+
canvas.height = video.videoHeight;
|
|
2125
|
+
canvas.getContext("2d")?.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
2126
|
+
return canvas;
|
|
2127
|
+
} finally {
|
|
2128
|
+
for (const track of stream.getTracks()) track.stop();
|
|
2129
|
+
video.srcObject = null;
|
|
2130
|
+
}
|
|
2131
|
+
};
|
|
2132
|
+
async function freshFrame(video) {
|
|
2133
|
+
if (typeof video.requestVideoFrameCallback === "function") {
|
|
2134
|
+
for (let frame = 0; frame < 3; frame++) {
|
|
2135
|
+
await Promise.race([
|
|
2136
|
+
new Promise((resolve) => video.requestVideoFrameCallback(() => resolve())),
|
|
2137
|
+
// A static page may produce no new frame at all; then the current one is current.
|
|
2138
|
+
new Promise((resolve) => window.setTimeout(resolve, 250))
|
|
2139
|
+
]);
|
|
2140
|
+
}
|
|
2141
|
+
return;
|
|
2142
|
+
}
|
|
2143
|
+
await new Promise((resolve) => window.setTimeout(resolve, 400));
|
|
2144
|
+
}
|
|
2145
|
+
function canvasBlob(canvas) {
|
|
2146
|
+
return new Promise((resolve, reject) => {
|
|
2147
|
+
canvas.toBlob((blob) => blob === null ? reject(new Error("The image could not be encoded")) : resolve(blob), "image/png");
|
|
2148
|
+
});
|
|
2149
|
+
}
|
|
2150
|
+
async function copyImage(canvas) {
|
|
2151
|
+
if (typeof ClipboardItem === "undefined" || navigator.clipboard?.write === void 0) {
|
|
2152
|
+
throw new Error("This browser cannot put an image on the clipboard; use Save instead.");
|
|
2153
|
+
}
|
|
2154
|
+
await navigator.clipboard.write([new ClipboardItem({ "image/png": canvasBlob(canvas) })]);
|
|
2155
|
+
}
|
|
2156
|
+
async function saveImage(canvas, fileName) {
|
|
2157
|
+
const url = URL.createObjectURL(await canvasBlob(canvas));
|
|
2158
|
+
const link = document.createElement("a");
|
|
2159
|
+
link.href = url;
|
|
2160
|
+
link.download = fileName;
|
|
2161
|
+
link.setAttribute("data-dev-annotator", "");
|
|
2162
|
+
document.body.appendChild(link);
|
|
2163
|
+
link.click();
|
|
2164
|
+
link.remove();
|
|
2165
|
+
window.setTimeout(() => URL.revokeObjectURL(url), 1e3);
|
|
2166
|
+
}
|
|
2167
|
+
function shotFileName(appName, pathname, now) {
|
|
2168
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
2169
|
+
const page = pathname.split("/").filter(Boolean).join("-").replace(/[^a-z0-9-]+/gi, "").slice(0, 40);
|
|
2170
|
+
const stamp = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}`;
|
|
2171
|
+
return `${[appName, page || "home", stamp].join("-")}.png`;
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
// src/screenshot-editor.tsx
|
|
2175
|
+
import {
|
|
2176
|
+
useEffect as useEffect2,
|
|
2177
|
+
useLayoutEffect as useLayoutEffect2,
|
|
2178
|
+
useRef as useRef2,
|
|
2179
|
+
useState as useState2
|
|
2180
|
+
} from "react";
|
|
2181
|
+
|
|
2182
|
+
// src/callout-tip.tsx
|
|
2183
|
+
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
2184
|
+
var FONT3 = 'ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif';
|
|
2185
|
+
var RED = "#E5484D";
|
|
2186
|
+
var LOOP = "3.2s";
|
|
2187
|
+
var KEY_TIMES = "0;0.12;0.55;0.85;1";
|
|
2188
|
+
function CalloutTip(props) {
|
|
2189
|
+
return /* @__PURE__ */ jsxs4(
|
|
2190
|
+
"div",
|
|
2191
|
+
{
|
|
2192
|
+
role: "note",
|
|
2193
|
+
"aria-label": "Callout tip",
|
|
2194
|
+
style: {
|
|
2195
|
+
position: "absolute",
|
|
2196
|
+
left: props.left,
|
|
2197
|
+
top: props.top,
|
|
2198
|
+
width: 264,
|
|
2199
|
+
padding: 12,
|
|
2200
|
+
borderRadius: 10,
|
|
2201
|
+
background: "#0E0E0E",
|
|
2202
|
+
border: "1px solid rgba(255,255,255,0.16)",
|
|
2203
|
+
boxShadow: "0 12px 32px rgba(0,0,0,0.45)",
|
|
2204
|
+
color: "#FFFFFF",
|
|
2205
|
+
font: `500 12px/1.4 ${FONT3}`,
|
|
2206
|
+
zIndex: 2
|
|
2207
|
+
},
|
|
2208
|
+
children: [
|
|
2209
|
+
/* @__PURE__ */ jsx5(
|
|
2210
|
+
"span",
|
|
2211
|
+
{
|
|
2212
|
+
"aria-hidden": "true",
|
|
2213
|
+
style: {
|
|
2214
|
+
position: "absolute",
|
|
2215
|
+
top: -6,
|
|
2216
|
+
left: 18,
|
|
2217
|
+
width: 10,
|
|
2218
|
+
height: 10,
|
|
2219
|
+
background: "#0E0E0E",
|
|
2220
|
+
borderLeft: "1px solid rgba(255,255,255,0.16)",
|
|
2221
|
+
borderTop: "1px solid rgba(255,255,255,0.16)",
|
|
2222
|
+
transform: "rotate(45deg)"
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
),
|
|
2226
|
+
/* @__PURE__ */ jsx5(Demo, {}),
|
|
2227
|
+
/* @__PURE__ */ jsx5("strong", { style: { display: "block", marginTop: 10, font: `600 13px/1.35 ${FONT3}`, color: "#FFFFFF" }, children: props.nudge ? "Tip: drag instead of clicking" : "Drag to point at something" }),
|
|
2228
|
+
/* @__PURE__ */ jsx5("span", { style: { display: "block", marginTop: 4, color: "#C9C5BE" }, children: props.nudge ? "Press on what you mean and drag to where the text goes: the box gets a tail pointing there." : "Press on what you mean, drag to where the text goes, then type. A plain click makes a box without a tail." }),
|
|
2229
|
+
/* @__PURE__ */ jsx5(
|
|
2230
|
+
"button",
|
|
2231
|
+
{
|
|
2232
|
+
type: "button",
|
|
2233
|
+
onClick: props.onDismiss,
|
|
2234
|
+
style: {
|
|
2235
|
+
appearance: "none",
|
|
2236
|
+
marginTop: 10,
|
|
2237
|
+
padding: "5px 12px",
|
|
2238
|
+
border: 0,
|
|
2239
|
+
borderRadius: 6,
|
|
2240
|
+
background: "rgba(255,255,255,0.14)",
|
|
2241
|
+
color: "#FFFFFF",
|
|
2242
|
+
font: `600 12px/1.2 ${FONT3}`,
|
|
2243
|
+
cursor: "pointer"
|
|
2244
|
+
},
|
|
2245
|
+
children: "Got it"
|
|
2246
|
+
}
|
|
2247
|
+
)
|
|
2248
|
+
]
|
|
2249
|
+
}
|
|
2250
|
+
);
|
|
2251
|
+
}
|
|
2252
|
+
function Demo() {
|
|
2253
|
+
const x = "52;52;172;172;52";
|
|
2254
|
+
const y = "70;70;27;27;70";
|
|
2255
|
+
return /* @__PURE__ */ jsxs4("svg", { width: "240", height: "96", viewBox: "0 0 240 96", "aria-hidden": "true", style: { display: "block", borderRadius: 6, background: "#F6F3EE" }, children: [
|
|
2256
|
+
/* @__PURE__ */ jsx5("rect", { x: "16", y: "56", width: "74", height: "28", rx: "4", fill: "#E6E0D6" }),
|
|
2257
|
+
/* @__PURE__ */ jsx5("rect", { x: "24", y: "64", width: "40", height: "5", rx: "2", fill: "#B9B2A6" }),
|
|
2258
|
+
/* @__PURE__ */ jsx5("rect", { x: "24", y: "73", width: "56", height: "4", rx: "2", fill: "#CFC8BC" }),
|
|
2259
|
+
/* @__PURE__ */ jsxs4("line", { x1: "52", y1: "70", x2: "52", y2: "70", stroke: RED, strokeWidth: "3", strokeLinecap: "round", children: [
|
|
2260
|
+
/* @__PURE__ */ jsx5("animate", { attributeName: "x2", values: x, keyTimes: KEY_TIMES, dur: LOOP, repeatCount: "indefinite" }),
|
|
2261
|
+
/* @__PURE__ */ jsx5("animate", { attributeName: "y2", values: y, keyTimes: KEY_TIMES, dur: LOOP, repeatCount: "indefinite" }),
|
|
2262
|
+
/* @__PURE__ */ jsx5("animate", { attributeName: "opacity", values: "0;1;1;1;0", keyTimes: KEY_TIMES, dur: LOOP, calcMode: "discrete", repeatCount: "indefinite" })
|
|
2263
|
+
] }),
|
|
2264
|
+
/* @__PURE__ */ jsxs4("g", { opacity: "0", children: [
|
|
2265
|
+
/* @__PURE__ */ jsx5("rect", { x: "128", y: "13", width: "92", height: "28", rx: "5", fill: RED }),
|
|
2266
|
+
/* @__PURE__ */ jsx5("text", { x: "174", y: "31.5", textAnchor: "middle", fill: "#FFFFFF", style: { font: `600 12px ${FONT3}` }, children: "Too tight" }),
|
|
2267
|
+
/* @__PURE__ */ jsx5("animate", { attributeName: "opacity", values: "0;0;1;0;0", keyTimes: KEY_TIMES, dur: LOOP, calcMode: "discrete", repeatCount: "indefinite" })
|
|
2268
|
+
] }),
|
|
2269
|
+
/* @__PURE__ */ jsx5("circle", { cx: "52", cy: "70", r: "0", fill: "none", stroke: "#1F1E1D", strokeWidth: "1.5", children: /* @__PURE__ */ jsx5("animate", { attributeName: "r", values: "0;11;0;0;0", keyTimes: KEY_TIMES, dur: LOOP, repeatCount: "indefinite" }) }),
|
|
2270
|
+
/* @__PURE__ */ jsxs4("g", { children: [
|
|
2271
|
+
/* @__PURE__ */ jsx5("path", { d: "M0 0 L0 15 L4 11 L7 18 L10 17 L7 10 L12 10 Z", fill: "#FFFFFF", stroke: "#1F1E1D", strokeWidth: "1.2", strokeLinejoin: "round" }),
|
|
2272
|
+
/* @__PURE__ */ jsx5("animateTransform", { attributeName: "transform", type: "translate", values: "52 70;52 70;172 27;172 27;52 70", keyTimes: KEY_TIMES, dur: LOOP, repeatCount: "indefinite" })
|
|
2273
|
+
] })
|
|
2274
|
+
] });
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
// src/screenshot-draw.ts
|
|
2278
|
+
var WEIGHT_FACTOR = { 1: 0.6, 2: 1, 3: 1.7 };
|
|
2279
|
+
var COLORS = ["#E5484D", "#F5A524", "#30A46C", "#0091FF", "#8E4EC6", "#1F1E1D"];
|
|
2280
|
+
var FONT_FAMILY = 'ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif';
|
|
2281
|
+
var LINE_HEIGHT2 = 1.25;
|
|
2282
|
+
function strokeWidth(imageWidth, weight = 2) {
|
|
2283
|
+
return Math.max(2, Math.round(imageWidth / 400 * WEIGHT_FACTOR[weight]));
|
|
2284
|
+
}
|
|
2285
|
+
function fontSize(imageWidth, weight = 2) {
|
|
2286
|
+
return Math.max(14, Math.round(imageWidth / 48 * WEIGHT_FACTOR[weight]));
|
|
2287
|
+
}
|
|
2288
|
+
function textFont(imageWidth, weight) {
|
|
2289
|
+
return `600 ${fontSize(imageWidth, weight)}px ${FONT_FAMILY}`;
|
|
2290
|
+
}
|
|
2291
|
+
function headSize(from, to, width) {
|
|
2292
|
+
const span = Math.hypot(to.x - from.x, to.y - from.y);
|
|
2293
|
+
const length = Math.min(width * 6, span * 0.5);
|
|
2294
|
+
return { length, half: length * 0.52 };
|
|
2295
|
+
}
|
|
2296
|
+
function arrowOutline(from, to, width) {
|
|
2297
|
+
const { length, half } = headSize(from, to, width);
|
|
2298
|
+
const angle = Math.atan2(to.y - from.y, to.x - from.x);
|
|
2299
|
+
const along = { x: Math.cos(angle), y: Math.sin(angle) };
|
|
2300
|
+
const normal = { x: -along.y, y: along.x };
|
|
2301
|
+
const base = { x: to.x - along.x * length, y: to.y - along.y * length };
|
|
2302
|
+
const at = (point, offset) => ({ x: point.x + normal.x * offset, y: point.y + normal.y * offset });
|
|
2303
|
+
const tail = width * 0.35;
|
|
2304
|
+
const neck = width * 0.85;
|
|
2305
|
+
return [at(from, tail), at(base, neck), at(base, half), to, at(base, -half), at(base, -neck), at(from, -tail)];
|
|
2306
|
+
}
|
|
2307
|
+
function calloutLayout(mark, imageWidth, measure) {
|
|
2308
|
+
const size = fontSize(imageWidth, mark.weight);
|
|
2309
|
+
const lines = mark.text.split("\n");
|
|
2310
|
+
const font = textFont(imageWidth, mark.weight);
|
|
2311
|
+
const padX = size * 0.5;
|
|
2312
|
+
const padY = size * 0.3;
|
|
2313
|
+
const lineHeight = size * LINE_HEIGHT2;
|
|
2314
|
+
const textWidth = Math.max(size * 1.5, ...lines.map((line) => measure(line, font)));
|
|
2315
|
+
const width = textWidth + 2 * padX;
|
|
2316
|
+
const height = lines.length * lineHeight + 2 * padY;
|
|
2317
|
+
return {
|
|
2318
|
+
box: { x: mark.at.x - width / 2, y: mark.at.y - height / 2, width, height },
|
|
2319
|
+
size,
|
|
2320
|
+
padX,
|
|
2321
|
+
padY,
|
|
2322
|
+
lineHeight,
|
|
2323
|
+
lines,
|
|
2324
|
+
radius: size * 0.22
|
|
2325
|
+
};
|
|
2326
|
+
}
|
|
2327
|
+
function tailBase(layout, tip) {
|
|
2328
|
+
const { box, size, radius } = layout;
|
|
2329
|
+
const cx = box.x + box.width / 2;
|
|
2330
|
+
const cy = box.y + box.height / 2;
|
|
2331
|
+
const dx = tip.x - cx;
|
|
2332
|
+
const dy = tip.y - cy;
|
|
2333
|
+
if (Math.abs(dx) <= box.width / 2 && Math.abs(dy) <= box.height / 2) return null;
|
|
2334
|
+
const inset = 1;
|
|
2335
|
+
if (Math.abs(dy) * (box.width / 2) >= Math.abs(dx) * (box.height / 2)) {
|
|
2336
|
+
const half2 = Math.min(size * 0.32, (box.width - 2 * radius) / 3);
|
|
2337
|
+
const y2 = dy > 0 ? box.y + box.height - inset : box.y + inset;
|
|
2338
|
+
const reach2 = dy === 0 ? 0 : box.height / 2 / Math.abs(dy) * dx;
|
|
2339
|
+
const x2 = Math.min(Math.max(cx + reach2, box.x + radius + half2), box.x + box.width - radius - half2);
|
|
2340
|
+
return [{ x: x2 - half2, y: y2 }, { x: x2 + half2, y: y2 }];
|
|
2341
|
+
}
|
|
2342
|
+
const half = Math.min(size * 0.32, (box.height - 2 * radius) / 3);
|
|
2343
|
+
const x = dx > 0 ? box.x + box.width - inset : box.x + inset;
|
|
2344
|
+
const reach = dx === 0 ? 0 : box.width / 2 / Math.abs(dx) * dy;
|
|
2345
|
+
const y = Math.min(Math.max(cy + reach, box.y + radius + half), box.y + box.height - radius - half);
|
|
2346
|
+
return [{ x, y: y - half }, { x, y: y + half }];
|
|
2347
|
+
}
|
|
2348
|
+
function textColorOn(fill) {
|
|
2349
|
+
const hex = /^#?([0-9a-f]{6})$/i.exec(fill)?.[1];
|
|
2350
|
+
if (hex === void 0) return "#FFFFFF";
|
|
2351
|
+
const [r, g, b] = [0, 2, 4].map((at) => Number.parseInt(hex.slice(at, at + 2), 16) / 255);
|
|
2352
|
+
const luminance = 0.2126 * (r ?? 0) + 0.7152 * (g ?? 0) + 0.0722 * (b ?? 0);
|
|
2353
|
+
return luminance > 0.6 ? "#1F1E1D" : "#FFFFFF";
|
|
2354
|
+
}
|
|
2355
|
+
function normalized(from, to) {
|
|
2356
|
+
return {
|
|
2357
|
+
x: Math.min(from.x, to.x),
|
|
2358
|
+
y: Math.min(from.y, to.y),
|
|
2359
|
+
width: Math.abs(to.x - from.x),
|
|
2360
|
+
height: Math.abs(to.y - from.y)
|
|
2361
|
+
};
|
|
2362
|
+
}
|
|
2363
|
+
function isTrivial(mark) {
|
|
2364
|
+
if (mark.tool === "text") return mark.text.trim() === "";
|
|
2365
|
+
if (mark.tool === "pen") return mark.points.length < 2;
|
|
2366
|
+
const box = normalized(mark.from, mark.to);
|
|
2367
|
+
return box.width < 4 && box.height < 4;
|
|
2368
|
+
}
|
|
2369
|
+
function canvasMeasure(context) {
|
|
2370
|
+
return (text, font) => {
|
|
2371
|
+
if (context === null) return text.length * Number.parseFloat(font.split(" ")[1] ?? "16") * 0.56;
|
|
2372
|
+
context.save();
|
|
2373
|
+
context.font = font;
|
|
2374
|
+
const width = context.measureText(text).width;
|
|
2375
|
+
context.restore();
|
|
2376
|
+
return width;
|
|
2377
|
+
};
|
|
2378
|
+
}
|
|
2379
|
+
function markBounds(mark, imageWidth, measure) {
|
|
2380
|
+
const pad = strokeWidth(imageWidth, mark.weight) / 2;
|
|
2381
|
+
switch (mark.tool) {
|
|
2382
|
+
case "text":
|
|
2383
|
+
return calloutLayout(mark, imageWidth, measure).box;
|
|
2384
|
+
case "pen": {
|
|
2385
|
+
const xs = mark.points.map((point) => point.x);
|
|
2386
|
+
const ys = mark.points.map((point) => point.y);
|
|
2387
|
+
const x = Math.min(...xs);
|
|
2388
|
+
const y = Math.min(...ys);
|
|
2389
|
+
return { x: x - pad, y: y - pad, width: Math.max(...xs) - x + 2 * pad, height: Math.max(...ys) - y + 2 * pad };
|
|
2390
|
+
}
|
|
2391
|
+
case "arrow": {
|
|
2392
|
+
const points = arrowOutline(mark.from, mark.to, strokeWidth(imageWidth, mark.weight));
|
|
2393
|
+
const xs = points.map((point) => point.x);
|
|
2394
|
+
const ys = points.map((point) => point.y);
|
|
2395
|
+
const x = Math.min(...xs);
|
|
2396
|
+
const y = Math.min(...ys);
|
|
2397
|
+
return { x: x - pad, y: y - pad, width: Math.max(...xs) - x + 2 * pad, height: Math.max(...ys) - y + 2 * pad };
|
|
2398
|
+
}
|
|
2399
|
+
default: {
|
|
2400
|
+
const box = normalized(mark.from, mark.to);
|
|
2401
|
+
return { x: box.x - pad, y: box.y - pad, width: box.width + 2 * pad, height: box.height + 2 * pad };
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
function distanceToSegment(point, a, b) {
|
|
2406
|
+
const dx = b.x - a.x;
|
|
2407
|
+
const dy = b.y - a.y;
|
|
2408
|
+
const lengthSquared = dx * dx + dy * dy;
|
|
2409
|
+
const t = lengthSquared === 0 ? 0 : Math.max(0, Math.min(1, ((point.x - a.x) * dx + (point.y - a.y) * dy) / lengthSquared));
|
|
2410
|
+
return Math.hypot(point.x - (a.x + t * dx), point.y - (a.y + t * dy));
|
|
2411
|
+
}
|
|
2412
|
+
function inside(point, box, slack) {
|
|
2413
|
+
return point.x >= box.x - slack && point.x <= box.x + box.width + slack && point.y >= box.y - slack && point.y <= box.y + box.height + slack;
|
|
2414
|
+
}
|
|
2415
|
+
function hitTest(marks, point, imageWidth, measure, slack) {
|
|
2416
|
+
for (let index = marks.length - 1; index >= 0; index--) {
|
|
2417
|
+
const mark = marks[index];
|
|
2418
|
+
if (mark === void 0) continue;
|
|
2419
|
+
const tolerance = slack + strokeWidth(imageWidth, mark.weight);
|
|
2420
|
+
if ((mark.tool === "arrow" || mark.tool === "ruler") && distanceToSegment(point, mark.from, mark.to) <= tolerance) return index;
|
|
2421
|
+
if (mark.tool === "pen") {
|
|
2422
|
+
for (let at = 1; at < mark.points.length; at++) {
|
|
2423
|
+
const a = mark.points[at - 1];
|
|
2424
|
+
const b = mark.points[at];
|
|
2425
|
+
if (a !== void 0 && b !== void 0 && distanceToSegment(point, a, b) <= tolerance) return index;
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
if (mark.tool === "text" && mark.tail !== void 0) {
|
|
2429
|
+
const layout = calloutLayout(mark, imageWidth, measure);
|
|
2430
|
+
const base = tailBase(layout, mark.tail);
|
|
2431
|
+
if (base !== null) {
|
|
2432
|
+
const mid = { x: (base[0].x + base[1].x) / 2, y: (base[0].y + base[1].y) / 2 };
|
|
2433
|
+
if (distanceToSegment(point, mid, mark.tail) <= tolerance) return index;
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
if (mark.tool !== "arrow" && mark.tool !== "ruler" && mark.tool !== "pen" && inside(point, markBounds(mark, imageWidth, measure), slack)) return index;
|
|
2437
|
+
}
|
|
2438
|
+
return null;
|
|
2439
|
+
}
|
|
2440
|
+
function translate(mark, dx, dy) {
|
|
2441
|
+
const move = (point) => ({ x: point.x + dx, y: point.y + dy });
|
|
2442
|
+
switch (mark.tool) {
|
|
2443
|
+
case "text":
|
|
2444
|
+
return { ...mark, at: move(mark.at) };
|
|
2445
|
+
case "pen":
|
|
2446
|
+
return { ...mark, points: mark.points.map(move) };
|
|
2447
|
+
default:
|
|
2448
|
+
return { ...mark, from: move(mark.from), to: move(mark.to) };
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
function union(a, b) {
|
|
2452
|
+
const x = Math.min(a.x, b.x);
|
|
2453
|
+
const y = Math.min(a.y, b.y);
|
|
2454
|
+
return { x, y, width: Math.max(a.x + a.width, b.x + b.width) - x, height: Math.max(a.y + a.height, b.y + b.height) - y };
|
|
2455
|
+
}
|
|
2456
|
+
function expand(box, by) {
|
|
2457
|
+
return { x: box.x - by, y: box.y - by, width: box.width + 2 * by, height: box.height + 2 * by };
|
|
2458
|
+
}
|
|
2459
|
+
function outputFrame(image, marks, imageWidth, measure) {
|
|
2460
|
+
let frame = image;
|
|
2461
|
+
const margin = Math.max(16, Math.round(Math.max(image.width, image.height) / 50));
|
|
2462
|
+
for (const mark of marks) {
|
|
2463
|
+
const box = expand(markBounds(mark, imageWidth, measure), margin);
|
|
2464
|
+
const outside = box.x < image.x || box.y < image.y || box.x + box.width > image.x + image.width || box.y + box.height > image.y + image.height;
|
|
2465
|
+
if (outside) frame = union(frame, box);
|
|
2466
|
+
}
|
|
2467
|
+
return {
|
|
2468
|
+
x: Math.floor(frame.x),
|
|
2469
|
+
y: Math.floor(frame.y),
|
|
2470
|
+
width: Math.ceil(frame.x + frame.width) - Math.floor(frame.x),
|
|
2471
|
+
height: Math.ceil(frame.y + frame.height) - Math.floor(frame.y)
|
|
2472
|
+
};
|
|
2473
|
+
}
|
|
2474
|
+
function edgeColor(image) {
|
|
2475
|
+
try {
|
|
2476
|
+
const context = image.getContext("2d", { willReadFrequently: true });
|
|
2477
|
+
if (context === null || image.width === 0 || image.height === 0) return "#FFFFFF";
|
|
2478
|
+
const strips = [
|
|
2479
|
+
context.getImageData(0, 0, image.width, 1),
|
|
2480
|
+
context.getImageData(0, image.height - 1, image.width, 1),
|
|
2481
|
+
context.getImageData(0, 0, 1, image.height),
|
|
2482
|
+
context.getImageData(image.width - 1, 0, 1, image.height)
|
|
2483
|
+
];
|
|
2484
|
+
const tally = /* @__PURE__ */ new Map();
|
|
2485
|
+
for (const { data } of strips) {
|
|
2486
|
+
for (let at = 0; at < data.length; at += 4) {
|
|
2487
|
+
const red = data[at] ?? 0;
|
|
2488
|
+
const green = data[at + 1] ?? 0;
|
|
2489
|
+
const blue = data[at + 2] ?? 0;
|
|
2490
|
+
const key = red >> 3 << 10 | green >> 3 << 5 | blue >> 3;
|
|
2491
|
+
const entry = tally.get(key) ?? { count: 0, red: 0, green: 0, blue: 0 };
|
|
2492
|
+
entry.count++;
|
|
2493
|
+
entry.red += red;
|
|
2494
|
+
entry.green += green;
|
|
2495
|
+
entry.blue += blue;
|
|
2496
|
+
tally.set(key, entry);
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
let best;
|
|
2500
|
+
for (const entry of tally.values()) if (best === void 0 || entry.count > best.count) best = entry;
|
|
2501
|
+
if (best === void 0) return "#FFFFFF";
|
|
2502
|
+
const { count } = best;
|
|
2503
|
+
const hex = (sum) => Math.round(sum / count).toString(16).padStart(2, "0");
|
|
2504
|
+
return `#${hex(best.red)}${hex(best.green)}${hex(best.blue)}`;
|
|
2505
|
+
} catch {
|
|
2506
|
+
return "#FFFFFF";
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
function paint(canvas, base, marks, options = {}) {
|
|
2510
|
+
const context = canvas.getContext("2d");
|
|
2511
|
+
if (context === null) return;
|
|
2512
|
+
const imageWidth = base.width;
|
|
2513
|
+
const image = options.image ?? { x: 0, y: 0, width: base.width, height: base.height };
|
|
2514
|
+
const frame = options.frame ?? image;
|
|
2515
|
+
const view = options.view ?? frame;
|
|
2516
|
+
context.save();
|
|
2517
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
2518
|
+
context.translate(-view.x, -view.y);
|
|
2519
|
+
if (options.backdrop !== void 0) {
|
|
2520
|
+
context.fillStyle = options.backdrop;
|
|
2521
|
+
context.fillRect(view.x, view.y, view.width, view.height);
|
|
2522
|
+
}
|
|
2523
|
+
context.save();
|
|
2524
|
+
if (options.backdrop !== void 0) {
|
|
2525
|
+
context.shadowColor = "rgba(0, 0, 0, 0.5)";
|
|
2526
|
+
context.shadowBlur = Math.max(12, imageWidth / 80);
|
|
2527
|
+
context.shadowOffsetY = Math.max(4, imageWidth / 300);
|
|
2528
|
+
}
|
|
2529
|
+
context.fillStyle = options.background ?? "#FFFFFF";
|
|
2530
|
+
context.fillRect(frame.x, frame.y, frame.width, frame.height);
|
|
2531
|
+
context.restore();
|
|
2532
|
+
context.drawImage(base, image.x, image.y, image.width, image.height, image.x, image.y, image.width, image.height);
|
|
2533
|
+
for (const mark of marks) {
|
|
2534
|
+
context.save();
|
|
2535
|
+
const width = strokeWidth(imageWidth, mark.weight);
|
|
2536
|
+
context.lineCap = "round";
|
|
2537
|
+
context.lineJoin = "round";
|
|
2538
|
+
context.lineWidth = width;
|
|
2539
|
+
context.strokeStyle = mark.color;
|
|
2540
|
+
context.fillStyle = mark.color;
|
|
2541
|
+
drawMark(context, base, mark, width, imageWidth, options.pixelRatio ?? 1);
|
|
2542
|
+
context.restore();
|
|
2543
|
+
}
|
|
2544
|
+
const chosen = options.selected === null || options.selected === void 0 ? void 0 : marks[options.selected];
|
|
2545
|
+
if (chosen !== void 0) {
|
|
2546
|
+
const accent = options.accent ?? "#0091FF";
|
|
2547
|
+
drawSelection(context, markBounds(chosen, imageWidth, canvasMeasure(context)), imageWidth, accent);
|
|
2548
|
+
if (chosen.tool === "text" && chosen.tail !== void 0) drawHandle(context, chosen.tail, tailHandleRadius(imageWidth), accent);
|
|
2549
|
+
}
|
|
2550
|
+
if (options.cropPreview !== void 0 && options.cropPreview !== null) drawCropPreview(context, image, options.cropPreview, imageWidth, options.pixelRatio ?? 1);
|
|
2551
|
+
context.restore();
|
|
2552
|
+
}
|
|
2553
|
+
function drawCropPreview(context, view, crop, imageWidth, ratio) {
|
|
2554
|
+
context.save();
|
|
2555
|
+
context.beginPath();
|
|
2556
|
+
context.rect(view.x, view.y, view.width, view.height);
|
|
2557
|
+
context.rect(crop.x, crop.y, crop.width, crop.height);
|
|
2558
|
+
context.fillStyle = "rgba(0, 0, 0, 0.55)";
|
|
2559
|
+
context.fill("evenodd");
|
|
2560
|
+
const line = Math.max(1.5, imageWidth / 900);
|
|
2561
|
+
context.lineWidth = line;
|
|
2562
|
+
context.strokeStyle = "#FFFFFF";
|
|
2563
|
+
context.setLineDash([line * 5, line * 4]);
|
|
2564
|
+
context.strokeRect(crop.x, crop.y, crop.width, crop.height);
|
|
2565
|
+
context.setLineDash([]);
|
|
2566
|
+
pill(context, `${Math.round(crop.width / ratio)} \xD7 ${Math.round(crop.height / ratio)}`, { x: crop.x + crop.width / 2, y: crop.y + crop.height / 2 }, fontSize(imageWidth, 1), "rgba(0,0,0,0.75)", "#FFFFFF");
|
|
2567
|
+
context.restore();
|
|
2568
|
+
}
|
|
2569
|
+
function pill(context, label, at, size, fill, ink) {
|
|
2570
|
+
context.save();
|
|
2571
|
+
context.font = `600 ${size}px ${FONT_FAMILY}`;
|
|
2572
|
+
const width = context.measureText(label).width + size;
|
|
2573
|
+
const height = size * 1.5;
|
|
2574
|
+
context.beginPath();
|
|
2575
|
+
context.roundRect(at.x - width / 2, at.y - height / 2, width, height, height / 2);
|
|
2576
|
+
context.fillStyle = fill;
|
|
2577
|
+
context.fill();
|
|
2578
|
+
context.fillStyle = ink;
|
|
2579
|
+
context.textAlign = "center";
|
|
2580
|
+
context.textBaseline = "middle";
|
|
2581
|
+
context.fillText(label, at.x, at.y + size * 0.05);
|
|
2582
|
+
context.restore();
|
|
2583
|
+
}
|
|
2584
|
+
function rulerLabel(from, to, ratio) {
|
|
2585
|
+
const dx = Math.round(Math.abs(to.x - from.x) / ratio);
|
|
2586
|
+
const dy = Math.round(Math.abs(to.y - from.y) / ratio);
|
|
2587
|
+
const length = Math.round(Math.hypot(to.x - from.x, to.y - from.y) / ratio);
|
|
2588
|
+
return dx === 0 || dy === 0 ? `${length} px` : `${length} px \xB7 ${dx} \xD7 ${dy}`;
|
|
2589
|
+
}
|
|
2590
|
+
function tailHandleRadius(imageWidth) {
|
|
2591
|
+
return Math.max(5, imageWidth / 220);
|
|
2592
|
+
}
|
|
2593
|
+
function drawHandle(context, at, radius, accent) {
|
|
2594
|
+
context.save();
|
|
2595
|
+
context.beginPath();
|
|
2596
|
+
context.arc(at.x, at.y, radius, 0, Math.PI * 2);
|
|
2597
|
+
context.fillStyle = "#FFFFFF";
|
|
2598
|
+
context.fill();
|
|
2599
|
+
context.lineWidth = Math.max(1.5, radius / 3);
|
|
2600
|
+
context.strokeStyle = accent;
|
|
2601
|
+
context.stroke();
|
|
2602
|
+
context.restore();
|
|
2603
|
+
}
|
|
2604
|
+
function drawSelection(context, box, imageWidth, accent) {
|
|
2605
|
+
const line = Math.max(1.5, imageWidth / 1e3);
|
|
2606
|
+
const gap = line * 4;
|
|
2607
|
+
const x = box.x - gap;
|
|
2608
|
+
const y = box.y - gap;
|
|
2609
|
+
const width = box.width + 2 * gap;
|
|
2610
|
+
const height = box.height + 2 * gap;
|
|
2611
|
+
context.save();
|
|
2612
|
+
context.lineWidth = line;
|
|
2613
|
+
context.strokeStyle = accent;
|
|
2614
|
+
context.setLineDash([line * 4, line * 3]);
|
|
2615
|
+
context.strokeRect(x, y, width, height);
|
|
2616
|
+
context.setLineDash([]);
|
|
2617
|
+
context.fillStyle = "#FFFFFF";
|
|
2618
|
+
const handle = line * 5;
|
|
2619
|
+
for (const [hx, hy] of [
|
|
2620
|
+
[x, y],
|
|
2621
|
+
[x + width, y],
|
|
2622
|
+
[x, y + height],
|
|
2623
|
+
[x + width, y + height]
|
|
2624
|
+
]) {
|
|
2625
|
+
context.fillRect(hx - handle / 2, hy - handle / 2, handle, handle);
|
|
2626
|
+
context.strokeRect(hx - handle / 2, hy - handle / 2, handle, handle);
|
|
2627
|
+
}
|
|
2628
|
+
context.restore();
|
|
2629
|
+
}
|
|
2630
|
+
function drawMark(context, base, mark, width, imageWidth, pixelRatio) {
|
|
2631
|
+
switch (mark.tool) {
|
|
2632
|
+
case "ruler": {
|
|
2633
|
+
const line = Math.max(1.5, width * 0.45);
|
|
2634
|
+
const angle = Math.atan2(mark.to.y - mark.from.y, mark.to.x - mark.from.x);
|
|
2635
|
+
const normal = { x: -Math.sin(angle), y: Math.cos(angle) };
|
|
2636
|
+
const tick = line * 6;
|
|
2637
|
+
context.lineWidth = line;
|
|
2638
|
+
context.lineCap = "butt";
|
|
2639
|
+
context.beginPath();
|
|
2640
|
+
context.moveTo(mark.from.x, mark.from.y);
|
|
2641
|
+
context.lineTo(mark.to.x, mark.to.y);
|
|
2642
|
+
for (const end of [mark.from, mark.to]) {
|
|
2643
|
+
context.moveTo(end.x + normal.x * tick, end.y + normal.y * tick);
|
|
2644
|
+
context.lineTo(end.x - normal.x * tick, end.y - normal.y * tick);
|
|
2645
|
+
}
|
|
2646
|
+
context.stroke();
|
|
2647
|
+
const size = fontSize(imageWidth, 1);
|
|
2648
|
+
const side = normal.y > 0 ? -1 : 1;
|
|
2649
|
+
const mid = { x: (mark.from.x + mark.to.x) / 2 + normal.x * side * size * 1.3, y: (mark.from.y + mark.to.y) / 2 + normal.y * side * size * 1.3 };
|
|
2650
|
+
pill(context, rulerLabel(mark.from, mark.to, pixelRatio), mid, size, mark.color, textColorOn(mark.color));
|
|
2651
|
+
return;
|
|
2652
|
+
}
|
|
2653
|
+
case "arrow": {
|
|
2654
|
+
const [first, ...rest] = arrowOutline(mark.from, mark.to, width);
|
|
2655
|
+
if (first === void 0) return;
|
|
2656
|
+
context.beginPath();
|
|
2657
|
+
context.moveTo(first.x, first.y);
|
|
2658
|
+
for (const point of rest) context.lineTo(point.x, point.y);
|
|
2659
|
+
context.closePath();
|
|
2660
|
+
context.shadowColor = "rgba(0, 0, 0, 0.25)";
|
|
2661
|
+
context.shadowBlur = width * 1.2;
|
|
2662
|
+
context.shadowOffsetY = width * 0.3;
|
|
2663
|
+
context.fill();
|
|
2664
|
+
return;
|
|
2665
|
+
}
|
|
2666
|
+
case "rect": {
|
|
2667
|
+
const box = normalized(mark.from, mark.to);
|
|
2668
|
+
context.beginPath();
|
|
2669
|
+
context.roundRect(box.x, box.y, box.width, box.height, width * 1.5);
|
|
2670
|
+
context.stroke();
|
|
2671
|
+
return;
|
|
2672
|
+
}
|
|
2673
|
+
case "highlight": {
|
|
2674
|
+
const box = normalized(mark.from, mark.to);
|
|
2675
|
+
context.globalAlpha = 0.3;
|
|
2676
|
+
context.fillRect(box.x, box.y, box.width, box.height);
|
|
2677
|
+
return;
|
|
2678
|
+
}
|
|
2679
|
+
case "pixelate": {
|
|
2680
|
+
const box = normalized(mark.from, mark.to);
|
|
2681
|
+
if (box.width < 1 || box.height < 1) return;
|
|
2682
|
+
const block = Math.max(8, Math.round(imageWidth / 120) * (mark.weight === 3 ? 2 : 1));
|
|
2683
|
+
const small = document.createElement("canvas");
|
|
2684
|
+
small.width = Math.max(1, Math.round(box.width / block));
|
|
2685
|
+
small.height = Math.max(1, Math.round(box.height / block));
|
|
2686
|
+
small.getContext("2d")?.drawImage(base, box.x, box.y, box.width, box.height, 0, 0, small.width, small.height);
|
|
2687
|
+
context.imageSmoothingEnabled = false;
|
|
2688
|
+
context.drawImage(small, 0, 0, small.width, small.height, box.x, box.y, box.width, box.height);
|
|
2689
|
+
return;
|
|
2690
|
+
}
|
|
2691
|
+
case "pen": {
|
|
2692
|
+
const [first, ...rest] = mark.points;
|
|
2693
|
+
if (first === void 0) return;
|
|
2694
|
+
context.beginPath();
|
|
2695
|
+
context.moveTo(first.x, first.y);
|
|
2696
|
+
for (const point of rest) context.lineTo(point.x, point.y);
|
|
2697
|
+
context.stroke();
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
case "text": {
|
|
2701
|
+
const layout = calloutLayout(mark, imageWidth, canvasMeasure(context));
|
|
2702
|
+
const { box, size, padY, lineHeight, lines, radius } = layout;
|
|
2703
|
+
context.beginPath();
|
|
2704
|
+
context.roundRect(box.x, box.y, box.width, box.height, radius);
|
|
2705
|
+
const base2 = mark.tail === void 0 ? null : tailBase(layout, mark.tail);
|
|
2706
|
+
if (base2 !== null && mark.tail !== void 0) {
|
|
2707
|
+
const tip = mark.tail;
|
|
2708
|
+
const [a, c] = base2;
|
|
2709
|
+
const turn = a.x * tip.y - tip.x * a.y + tip.x * c.y - c.x * tip.y + c.x * a.y - a.x * c.y;
|
|
2710
|
+
const [first, last] = turn >= 0 ? [a, c] : [c, a];
|
|
2711
|
+
context.moveTo(first.x, first.y);
|
|
2712
|
+
context.lineTo(tip.x, tip.y);
|
|
2713
|
+
context.lineTo(last.x, last.y);
|
|
2714
|
+
context.closePath();
|
|
2715
|
+
}
|
|
2716
|
+
context.shadowColor = "rgba(0, 0, 0, 0.28)";
|
|
2717
|
+
context.shadowBlur = size * 0.5;
|
|
2718
|
+
context.shadowOffsetY = size * 0.12;
|
|
2719
|
+
context.fill("nonzero");
|
|
2720
|
+
context.shadowColor = "transparent";
|
|
2721
|
+
context.fillStyle = textColorOn(mark.color);
|
|
2722
|
+
context.font = textFont(imageWidth, mark.weight);
|
|
2723
|
+
context.textAlign = "center";
|
|
2724
|
+
context.textBaseline = "middle";
|
|
2725
|
+
lines.forEach((line, index) => {
|
|
2726
|
+
context.fillText(line, box.x + box.width / 2, box.y + padY + index * lineHeight + lineHeight / 2);
|
|
2727
|
+
});
|
|
2728
|
+
return;
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
|
|
2733
|
+
// src/screenshot-editor.tsx
|
|
2734
|
+
import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
2735
|
+
var TOOLS = [
|
|
2736
|
+
{ tool: "select", icon: "select", label: "Select & move", key: "V", detail: "Click a mark to select it, drag to move it, Delete to remove it. Double-click text to edit it." },
|
|
2737
|
+
{ tool: "arrow", icon: "arrow", label: "Arrow", key: "A", detail: "Hold Shift to snap to 45\xB0." },
|
|
2738
|
+
{ tool: "rect", icon: "rect", label: "Rectangle", key: "R", detail: "Hold Shift for a square." },
|
|
2739
|
+
{ tool: "highlight", icon: "highlight", label: "Highlight", key: "H", detail: "A translucent marker over an area." },
|
|
2740
|
+
{ tool: "pen", icon: "pen", label: "Pen", key: "P", detail: "Draw freehand." },
|
|
2741
|
+
{
|
|
2742
|
+
tool: "text",
|
|
2743
|
+
icon: "text",
|
|
2744
|
+
label: "Callout",
|
|
2745
|
+
key: "T",
|
|
2746
|
+
detail: "Drag from what you point at to where the text goes: one box with a tail. A click gives a box without one. Enter places it, Shift+Enter adds a line."
|
|
2747
|
+
},
|
|
2748
|
+
{ tool: "ruler", icon: "ruler", label: "Ruler", key: "M", detail: "Measure in the page\u2019s own pixels. Hold Shift to keep it straight." },
|
|
2749
|
+
{ tool: "crop", icon: "crop", label: "Crop", key: "C", detail: "Drag the part to keep. Undo, or Reset crop, brings the rest back." },
|
|
2750
|
+
{ tool: "pixelate", icon: "pixelate", label: "Pixelate", key: "B", detail: "Hide personal data before the image leaves this machine." }
|
|
2751
|
+
];
|
|
2752
|
+
var WEIGHTS = [
|
|
2753
|
+
{ weight: 1, label: "Thin", dot: 4 },
|
|
2754
|
+
{ weight: 2, label: "Medium", dot: 7 },
|
|
2755
|
+
{ weight: 3, label: "Thick", dot: 10 }
|
|
2756
|
+
];
|
|
2757
|
+
var ZOOM_STOPS = [0.1, 0.25, 0.33, 0.5, 0.67, 0.75, 1, 1.25, 1.5, 2, 3, 4, 6, 8];
|
|
2758
|
+
var MIN_ZOOM = 0.1;
|
|
2759
|
+
var MAX_ZOOM = 8;
|
|
2760
|
+
var PAD = 24;
|
|
2761
|
+
var PICK_SLACK = 6;
|
|
2762
|
+
var NO_MARKS = [];
|
|
2763
|
+
var CALLOUT_TIP_KEY = "agent-annotator:callout-tip-done";
|
|
2764
|
+
var EMPTY_DOC = { marks: NO_MARKS, crop: null };
|
|
2765
|
+
var measureContext;
|
|
2766
|
+
function textMeasure() {
|
|
2767
|
+
if (measureContext === void 0) {
|
|
2768
|
+
measureContext = typeof document === "undefined" ? null : document.createElement("canvas").getContext("2d");
|
|
2769
|
+
}
|
|
2770
|
+
return canvasMeasure(measureContext ?? null);
|
|
2771
|
+
}
|
|
2772
|
+
function ScreenshotEditor(props) {
|
|
2773
|
+
const { image, fileName, onClose, onNotice } = props;
|
|
2774
|
+
const ratio = typeof window === "undefined" ? 1 : window.devicePixelRatio || 1;
|
|
2775
|
+
const canvasRef = useRef2(null);
|
|
2776
|
+
const areaRef = useRef2(null);
|
|
2777
|
+
const customColorRef = useRef2(null);
|
|
2778
|
+
const [history, setHistory] = useState2({ past: [], present: EMPTY_DOC, future: [] });
|
|
2779
|
+
const marks = history.present.marks;
|
|
2780
|
+
const crop = history.present.crop;
|
|
2781
|
+
const view = crop ?? { x: 0, y: 0, width: image.width, height: image.height };
|
|
2782
|
+
const [saved, setSaved] = useState2(EMPTY_DOC);
|
|
2783
|
+
const [cropDraft, setCropDraftState] = useState2(null);
|
|
2784
|
+
const [tool, setTool] = useState2("arrow");
|
|
2785
|
+
const [color, setColor] = useState2(COLORS[0]);
|
|
2786
|
+
const [weight, setWeight] = useState2(2);
|
|
2787
|
+
const [selectedRaw, setSelected] = useState2(null);
|
|
2788
|
+
const selected = selectedRaw !== null && selectedRaw < marks.length ? selectedRaw : null;
|
|
2789
|
+
const [drawing, setDrawingState] = useState2(null);
|
|
2790
|
+
const [drag, setDragState] = useState2(null);
|
|
2791
|
+
const drawingRef = useRef2(null);
|
|
2792
|
+
const dragRef = useRef2(null);
|
|
2793
|
+
const cropRef = useRef2(null);
|
|
2794
|
+
const setDrawing = (next) => {
|
|
2795
|
+
drawingRef.current = next;
|
|
2796
|
+
setDrawingState(next);
|
|
2797
|
+
};
|
|
2798
|
+
const setDrag = (next) => {
|
|
2799
|
+
dragRef.current = next;
|
|
2800
|
+
setDragState(next);
|
|
2801
|
+
};
|
|
2802
|
+
const setCropDraft = (next) => {
|
|
2803
|
+
cropRef.current = next;
|
|
2804
|
+
setCropDraftState(next);
|
|
2805
|
+
};
|
|
2806
|
+
const [text, setText] = useState2(null);
|
|
2807
|
+
const [hovering, setHovering] = useState2(false);
|
|
2808
|
+
const [spaceHeld, setSpaceHeld] = useState2(false);
|
|
2809
|
+
const [panning, setPanning] = useState2(false);
|
|
2810
|
+
const panRef = useRef2(null);
|
|
2811
|
+
const [confirmClose, setConfirmClose] = useState2(false);
|
|
2812
|
+
const dialogRef = useRef2(null);
|
|
2813
|
+
const [tipDone, setTipDone] = useState2(() => readFlag(CALLOUT_TIP_KEY));
|
|
2814
|
+
const [tipNudge, setTipNudge] = useState2(false);
|
|
2815
|
+
const [tipAt, setTipAt] = useState2(null);
|
|
2816
|
+
const learnCallout = () => {
|
|
2817
|
+
setTipDone(true);
|
|
2818
|
+
writeFlag(CALLOUT_TIP_KEY, true);
|
|
2819
|
+
};
|
|
2820
|
+
const showTip = tool === "text" && !tipDone;
|
|
2821
|
+
useLayoutEffect2(() => {
|
|
2822
|
+
if (!showTip) return;
|
|
2823
|
+
const dialog = dialogRef.current;
|
|
2824
|
+
const button = dialog?.querySelector('[aria-label="Callout"]');
|
|
2825
|
+
if (dialog === null || dialog === void 0 || button === null || button === void 0) return;
|
|
2826
|
+
const box = button.getBoundingClientRect();
|
|
2827
|
+
const frame2 = dialog.getBoundingClientRect();
|
|
2828
|
+
setTipAt({ left: Math.max(8, box.left - frame2.left + box.width / 2 - 23), top: box.bottom - frame2.top + 10 });
|
|
2829
|
+
}, [showTip]);
|
|
2830
|
+
const [zoom, setZoom] = useState2(null);
|
|
2831
|
+
const [areaSize, setAreaSize] = useState2({ width: 0, height: 0 });
|
|
2832
|
+
const frame = outputFrame(view, marks, image.width, textMeasure());
|
|
2833
|
+
const fitScale = areaSize.width > 2 * PAD && areaSize.height > 2 * PAD ? (
|
|
2834
|
+
// Never blow a capture up past the size it had on the page.
|
|
2835
|
+
Math.min((areaSize.width - 2 * PAD) / frame.width, (areaSize.height - 2 * PAD) / frame.height, 1 / ratio)
|
|
2836
|
+
) : 1 / ratio;
|
|
2837
|
+
const scale = zoom ?? fitScale;
|
|
2838
|
+
const board = boardAround(expand(frame, 12 / scale), view, areaSize, scale);
|
|
2839
|
+
const [background] = useState2(() => edgeColor(image));
|
|
2840
|
+
const anchorRef = useRef2(null);
|
|
2841
|
+
const dirty = history.present !== saved && (marks.length > 0 || crop !== null);
|
|
2842
|
+
const commitDoc = (change) => setHistory((current) => ({ past: [...current.past, current.present], present: change(current.present), future: [] }));
|
|
2843
|
+
const commit = (next) => commitDoc((doc) => ({ ...doc, marks: next }));
|
|
2844
|
+
const commitCrop = (next) => {
|
|
2845
|
+
commitDoc((doc) => ({ ...doc, crop: next }));
|
|
2846
|
+
setZoom(null);
|
|
2847
|
+
};
|
|
2848
|
+
const undo = () => setHistory(
|
|
2849
|
+
(current) => current.past.length === 0 ? current : { past: current.past.slice(0, -1), present: current.past[current.past.length - 1] ?? EMPTY_DOC, future: [current.present, ...current.future] }
|
|
2850
|
+
);
|
|
2851
|
+
const redo = () => setHistory(
|
|
2852
|
+
(current) => current.future.length === 0 ? current : { past: [...current.past, current.present], present: current.future[0] ?? EMPTY_DOC, future: current.future.slice(1) }
|
|
2853
|
+
);
|
|
2854
|
+
const replaceAt = (index, mark) => commit(mark === null ? marks.filter((_, at) => at !== index) : marks.map((kept, at) => at === index ? mark : kept));
|
|
2855
|
+
let visible = drag === null ? marks : marks.map((mark, at) => at === drag.index ? drag.moved : mark);
|
|
2856
|
+
if (text !== null) {
|
|
2857
|
+
const live = {
|
|
2858
|
+
tool: "text",
|
|
2859
|
+
at: text.at,
|
|
2860
|
+
text: text.value,
|
|
2861
|
+
color: text.color,
|
|
2862
|
+
weight: text.weight,
|
|
2863
|
+
...text.tail === void 0 ? {} : { tail: text.tail }
|
|
2864
|
+
};
|
|
2865
|
+
visible = text.editing === null ? [...visible, live] : visible.map((mark, at) => at === text.editing ? live : mark);
|
|
2866
|
+
}
|
|
2867
|
+
if (drawing !== null) visible = [...visible, drawing];
|
|
2868
|
+
const outline = text === null && drawing === null ? selected : null;
|
|
2869
|
+
const liveFrame = outputFrame(view, visible, image.width, textMeasure());
|
|
2870
|
+
const paintBase = { view: board, image: view, frame: liveFrame, background, backdrop: "#0E0E0E", pixelRatio: ratio };
|
|
2871
|
+
const cropBox = cropDraft === null ? null : clampTo(normalized(cropDraft.from, cropDraft.to), view);
|
|
2872
|
+
useEffect2(() => {
|
|
2873
|
+
const canvas = canvasRef.current;
|
|
2874
|
+
if (canvas !== null) paint(canvas, image, visible, { ...paintBase, selected: outline, accent: "#0091FF", cropPreview: cropBox });
|
|
2875
|
+
});
|
|
2876
|
+
useEffect2(() => {
|
|
2877
|
+
const area = areaRef.current;
|
|
2878
|
+
if (area === null) return void 0;
|
|
2879
|
+
const measure = () => setAreaSize({ width: area.clientWidth, height: area.clientHeight });
|
|
2880
|
+
measure();
|
|
2881
|
+
if (typeof ResizeObserver === "undefined") {
|
|
2882
|
+
window.addEventListener("resize", measure);
|
|
2883
|
+
return () => window.removeEventListener("resize", measure);
|
|
2884
|
+
}
|
|
2885
|
+
const observer = new ResizeObserver(measure);
|
|
2886
|
+
observer.observe(area);
|
|
2887
|
+
return () => observer.disconnect();
|
|
2888
|
+
}, []);
|
|
2889
|
+
useLayoutEffect2(() => {
|
|
2890
|
+
const anchor = anchorRef.current;
|
|
2891
|
+
anchorRef.current = null;
|
|
2892
|
+
const canvas = canvasRef.current;
|
|
2893
|
+
const area = areaRef.current;
|
|
2894
|
+
if (anchor === null || canvas === null || area === null) return;
|
|
2895
|
+
const rect = canvas.getBoundingClientRect();
|
|
2896
|
+
area.scrollLeft += rect.left + (anchor.image.x - board.x) * scale - anchor.client.x;
|
|
2897
|
+
area.scrollTop += rect.top + (anchor.image.y - board.y) * scale - anchor.client.y;
|
|
2898
|
+
}, [scale, board.x, board.y]);
|
|
2899
|
+
const zoomTo = (nextScale, client) => {
|
|
2900
|
+
const canvas = canvasRef.current;
|
|
2901
|
+
const area = areaRef.current;
|
|
2902
|
+
if (canvas !== null && area !== null) {
|
|
2903
|
+
const rect = canvas.getBoundingClientRect();
|
|
2904
|
+
const box = area.getBoundingClientRect();
|
|
2905
|
+
const at = client ?? { x: box.left + box.width / 2, y: box.top + box.height / 2 };
|
|
2906
|
+
if (scale > 0) anchorRef.current = { image: { x: board.x + (at.x - rect.left) / scale, y: board.y + (at.y - rect.top) / scale }, client: at };
|
|
2907
|
+
}
|
|
2908
|
+
setZoom(nextScale === null ? null : Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, nextScale * ratio)) / ratio);
|
|
2909
|
+
};
|
|
2910
|
+
const percent = scale * ratio;
|
|
2911
|
+
const zoomStep = (direction) => {
|
|
2912
|
+
const next = direction === 1 ? ZOOM_STOPS.find((stop) => stop > percent * 1.01) : [...ZOOM_STOPS].reverse().find((stop) => stop < percent * 0.99);
|
|
2913
|
+
if (next !== void 0) zoomTo(next / ratio);
|
|
2914
|
+
};
|
|
2915
|
+
const wheelRef = useRef2(() => void 0);
|
|
2916
|
+
const onWheel = (event) => {
|
|
2917
|
+
if (!event.ctrlKey && !event.metaKey) return;
|
|
2918
|
+
event.preventDefault();
|
|
2919
|
+
zoomTo(scale * Math.exp(-event.deltaY * 0.01), { x: event.clientX, y: event.clientY });
|
|
2920
|
+
};
|
|
2921
|
+
useEffect2(() => {
|
|
2922
|
+
const area = areaRef.current;
|
|
2923
|
+
if (area === null) return void 0;
|
|
2924
|
+
const onWheel2 = (event) => wheelRef.current(event);
|
|
2925
|
+
area.addEventListener("wheel", onWheel2, { passive: false });
|
|
2926
|
+
return () => area.removeEventListener("wheel", onWheel2);
|
|
2927
|
+
}, []);
|
|
2928
|
+
const measureText = textMeasure;
|
|
2929
|
+
const pick = (point, only) => {
|
|
2930
|
+
const index = hitTest(marks, point, image.width, measureText(), PICK_SLACK / scale);
|
|
2931
|
+
return index !== null && (only === void 0 || marks[index]?.tool === only) ? index : null;
|
|
2932
|
+
};
|
|
2933
|
+
const imagePoint = (event) => {
|
|
2934
|
+
const rect = canvasRef.current?.getBoundingClientRect();
|
|
2935
|
+
if (rect === void 0 || scale <= 0) return { x: 0, y: 0 };
|
|
2936
|
+
return { x: board.x + (event.clientX - rect.left) / scale, y: board.y + (event.clientY - rect.top) / scale };
|
|
2937
|
+
};
|
|
2938
|
+
const commitText = () => {
|
|
2939
|
+
if (text === null) return;
|
|
2940
|
+
const value = text.value.replace(/\s+$/, "");
|
|
2941
|
+
if (text.editing !== null) {
|
|
2942
|
+
const original = marks[text.editing];
|
|
2943
|
+
if (original?.tool === "text") replaceAt(text.editing, value.trim() === "" ? null : { ...original, text: value });
|
|
2944
|
+
} else if (value.trim() !== "") {
|
|
2945
|
+
commit([
|
|
2946
|
+
...marks,
|
|
2947
|
+
{ tool: "text", at: text.at, text: value, color: text.color, weight: text.weight, ...text.tail === void 0 ? {} : { tail: text.tail } }
|
|
2948
|
+
]);
|
|
2949
|
+
}
|
|
2950
|
+
setText(null);
|
|
2951
|
+
};
|
|
2952
|
+
const editText = (index) => {
|
|
2953
|
+
const mark = marks[index];
|
|
2954
|
+
if (mark?.tool !== "text") return;
|
|
2955
|
+
setSelected(null);
|
|
2956
|
+
setText({ at: mark.at, value: mark.text, color: mark.color, weight: mark.weight, editing: index, ...mark.tail === void 0 ? {} : { tail: mark.tail } });
|
|
2957
|
+
};
|
|
2958
|
+
const onPointerDown = (event) => {
|
|
2959
|
+
if (event.button === 1 || event.button === 0 && spaceHeld) {
|
|
2960
|
+
const area = areaRef.current;
|
|
2961
|
+
if (area === null) return;
|
|
2962
|
+
event.preventDefault();
|
|
2963
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
2964
|
+
panRef.current = { x: event.clientX, y: event.clientY, left: area.scrollLeft, top: area.scrollTop };
|
|
2965
|
+
setPanning(true);
|
|
2966
|
+
return;
|
|
2967
|
+
}
|
|
2968
|
+
if (event.button !== 0) return;
|
|
2969
|
+
const point = imagePoint(event);
|
|
2970
|
+
if (tool === "select") {
|
|
2971
|
+
const current = selected === null ? void 0 : marks[selected];
|
|
2972
|
+
if (selected !== null && current?.tool === "text" && current.tail !== void 0) {
|
|
2973
|
+
const grip = tailHandleRadius(image.width) + PICK_SLACK / scale;
|
|
2974
|
+
if (Math.hypot(point.x - current.tail.x, point.y - current.tail.y) <= grip) {
|
|
2975
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
2976
|
+
setDrag({ mode: "tail", index: selected, origin: point, original: current, moved: current });
|
|
2977
|
+
return;
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
const index = pick(point);
|
|
2981
|
+
select(index);
|
|
2982
|
+
const mark = index === null ? void 0 : marks[index];
|
|
2983
|
+
if (index !== null && mark !== void 0) {
|
|
2984
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
2985
|
+
setDrag({ mode: "move", index, origin: point, original: mark, moved: mark });
|
|
2986
|
+
}
|
|
2987
|
+
return;
|
|
2988
|
+
}
|
|
2989
|
+
if (tool === "crop") {
|
|
2990
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
2991
|
+
setSelected(null);
|
|
2992
|
+
setCropDraft({ from: point, to: point });
|
|
2993
|
+
return;
|
|
2994
|
+
}
|
|
2995
|
+
if (tool === "text") {
|
|
2996
|
+
commitText();
|
|
2997
|
+
const existing = pick(point, "text");
|
|
2998
|
+
if (existing !== null) {
|
|
2999
|
+
editText(existing);
|
|
3000
|
+
return;
|
|
3001
|
+
}
|
|
3002
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
3003
|
+
setSelected(null);
|
|
3004
|
+
setDrawing({ tool: "text", at: point, text: "", tail: point, color, weight });
|
|
3005
|
+
return;
|
|
3006
|
+
}
|
|
3007
|
+
setSelected(null);
|
|
3008
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
3009
|
+
setDrawing(tool === "pen" ? { tool, points: [point], color, weight } : { tool, from: point, to: point, color, weight });
|
|
3010
|
+
};
|
|
3011
|
+
const onPointerMove = (event) => {
|
|
3012
|
+
const pan = panRef.current;
|
|
3013
|
+
if (pan !== null) {
|
|
3014
|
+
const area = areaRef.current;
|
|
3015
|
+
if (area !== null) {
|
|
3016
|
+
area.scrollLeft = pan.left - (event.clientX - pan.x);
|
|
3017
|
+
area.scrollTop = pan.top - (event.clientY - pan.y);
|
|
3018
|
+
}
|
|
3019
|
+
return;
|
|
3020
|
+
}
|
|
3021
|
+
const point = imagePoint(event);
|
|
3022
|
+
const cropDraft2 = cropRef.current;
|
|
3023
|
+
const drag2 = dragRef.current;
|
|
3024
|
+
const drawing2 = drawingRef.current;
|
|
3025
|
+
if (cropDraft2 !== null) {
|
|
3026
|
+
setCropDraft({ ...cropDraft2, to: point });
|
|
3027
|
+
return;
|
|
3028
|
+
}
|
|
3029
|
+
if (drag2 !== null) {
|
|
3030
|
+
let dx = point.x - drag2.origin.x;
|
|
3031
|
+
let dy = point.y - drag2.origin.y;
|
|
3032
|
+
if (event.shiftKey) {
|
|
3033
|
+
if (Math.abs(dx) > Math.abs(dy)) dy = 0;
|
|
3034
|
+
else dx = 0;
|
|
3035
|
+
}
|
|
3036
|
+
setDrag({
|
|
3037
|
+
...drag2,
|
|
3038
|
+
moved: drag2.mode === "tail" && drag2.original.tool === "text" ? { ...drag2.original, tail: point } : translate(drag2.original, dx, dy)
|
|
3039
|
+
});
|
|
3040
|
+
return;
|
|
3041
|
+
}
|
|
3042
|
+
if (drawing2 !== null) {
|
|
3043
|
+
setDrawing(
|
|
3044
|
+
drawing2.tool === "pen" ? { ...drawing2, points: [...drawing2.points, point] } : drawing2.tool === "text" ? { ...drawing2, at: point } : { ...drawing2, to: event.shiftKey ? straighten(drawing2.from, point, drawing2.tool) : point }
|
|
3045
|
+
);
|
|
3046
|
+
return;
|
|
3047
|
+
}
|
|
3048
|
+
if (tool === "select") setHovering(pick(point) !== null);
|
|
3049
|
+
};
|
|
3050
|
+
const onPointerUp = () => {
|
|
3051
|
+
if (panRef.current !== null) {
|
|
3052
|
+
panRef.current = null;
|
|
3053
|
+
setPanning(false);
|
|
3054
|
+
return;
|
|
3055
|
+
}
|
|
3056
|
+
const cropDraft2 = cropRef.current;
|
|
3057
|
+
const drag2 = dragRef.current;
|
|
3058
|
+
const drawing2 = drawingRef.current;
|
|
3059
|
+
if (cropDraft2 !== null) {
|
|
3060
|
+
const cropBox2 = clampTo(normalized(cropDraft2.from, cropDraft2.to), view);
|
|
3061
|
+
if (cropBox2.width * scale >= 8 && cropBox2.height * scale >= 8) {
|
|
3062
|
+
commitCrop({ x: Math.round(cropBox2.x), y: Math.round(cropBox2.y), width: Math.round(cropBox2.width), height: Math.round(cropBox2.height) });
|
|
3063
|
+
}
|
|
3064
|
+
setCropDraft(null);
|
|
3065
|
+
return;
|
|
3066
|
+
}
|
|
3067
|
+
if (drag2 !== null) {
|
|
3068
|
+
if (drag2.moved !== drag2.original) replaceAt(drag2.index, drag2.moved);
|
|
3069
|
+
setDrag(null);
|
|
3070
|
+
return;
|
|
3071
|
+
}
|
|
3072
|
+
if (drawing2 !== null) {
|
|
3073
|
+
if (drawing2.tool === "text") {
|
|
3074
|
+
const tip = drawing2.tail ?? drawing2.at;
|
|
3075
|
+
const dragged = Math.hypot(drawing2.at.x - tip.x, drawing2.at.y - tip.y) * scale >= 12;
|
|
3076
|
+
if (dragged) learnCallout();
|
|
3077
|
+
else if (!tipDone) setTipNudge(true);
|
|
3078
|
+
setText({ at: drawing2.at, value: "", color: drawing2.color, weight: drawing2.weight, editing: null, ...dragged ? { tail: tip } : {} });
|
|
3079
|
+
} else if (!isTrivial(drawing2)) {
|
|
3080
|
+
commit([...marks, drawing2]);
|
|
3081
|
+
}
|
|
3082
|
+
setDrawing(null);
|
|
3083
|
+
}
|
|
3084
|
+
};
|
|
3085
|
+
const pickColor = (next) => {
|
|
3086
|
+
setColor(next);
|
|
3087
|
+
const mark = selected === null ? void 0 : marks[selected];
|
|
3088
|
+
if (selected !== null && mark !== void 0 && mark.color !== next) replaceAt(selected, { ...mark, color: next });
|
|
3089
|
+
};
|
|
3090
|
+
const pickWeight = (next) => {
|
|
3091
|
+
setWeight(next);
|
|
3092
|
+
const mark = selected === null ? void 0 : marks[selected];
|
|
3093
|
+
if (selected !== null && mark !== void 0 && mark.weight !== next) replaceAt(selected, { ...mark, weight: next });
|
|
3094
|
+
};
|
|
3095
|
+
const chooseTool = (next) => {
|
|
3096
|
+
commitText();
|
|
3097
|
+
setTool(next);
|
|
3098
|
+
if (next !== "select") setSelected(null);
|
|
3099
|
+
};
|
|
3100
|
+
const select = (index) => {
|
|
3101
|
+
setSelected(index);
|
|
3102
|
+
const mark = index === null ? void 0 : marks[index];
|
|
3103
|
+
if (mark !== void 0) {
|
|
3104
|
+
setColor(mark.color);
|
|
3105
|
+
setWeight(mark.weight);
|
|
3106
|
+
}
|
|
3107
|
+
};
|
|
3108
|
+
const pickColorRef = useRef2(pickColor);
|
|
3109
|
+
useEffect2(() => {
|
|
3110
|
+
const input = customColorRef.current;
|
|
3111
|
+
if (input === null) return void 0;
|
|
3112
|
+
const onChange = () => pickColorRef.current(input.value);
|
|
3113
|
+
input.addEventListener("change", onChange);
|
|
3114
|
+
return () => input.removeEventListener("change", onChange);
|
|
3115
|
+
}, []);
|
|
3116
|
+
const run = async (action) => {
|
|
3117
|
+
commitText();
|
|
3118
|
+
const canvas = document.createElement("canvas");
|
|
3119
|
+
canvas.width = frame.width;
|
|
3120
|
+
canvas.height = frame.height;
|
|
3121
|
+
paint(canvas, image, marks, { view: frame, image: view, frame, background, pixelRatio: ratio });
|
|
3122
|
+
try {
|
|
3123
|
+
if (action === "copy") {
|
|
3124
|
+
await copyImage(canvas);
|
|
3125
|
+
onNotice({ title: "Screenshot copied", detail: "Paste it into your coding agent, a ticket or a chat." });
|
|
3126
|
+
} else {
|
|
3127
|
+
await saveImage(canvas, fileName);
|
|
3128
|
+
onNotice({ title: "Screenshot saved", detail: fileName });
|
|
3129
|
+
}
|
|
3130
|
+
setSaved(history.present);
|
|
3131
|
+
} catch (error) {
|
|
3132
|
+
onNotice({
|
|
3133
|
+
title: action === "copy" ? "Could not copy the screenshot" : "Could not save the screenshot",
|
|
3134
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
3135
|
+
tone: "error"
|
|
3136
|
+
});
|
|
3137
|
+
}
|
|
3138
|
+
};
|
|
3139
|
+
const requestClose = () => {
|
|
3140
|
+
if (dirty && !confirmClose) {
|
|
3141
|
+
setConfirmClose(true);
|
|
3142
|
+
return;
|
|
3143
|
+
}
|
|
3144
|
+
onClose();
|
|
3145
|
+
};
|
|
3146
|
+
useEffect2(() => {
|
|
3147
|
+
if (!confirmClose) return void 0;
|
|
3148
|
+
const timer = window.setTimeout(() => setConfirmClose(false), 3e3);
|
|
3149
|
+
return () => window.clearTimeout(timer);
|
|
3150
|
+
}, [confirmClose]);
|
|
3151
|
+
const keyRef = useRef2(() => false);
|
|
3152
|
+
const onKey = (event) => {
|
|
3153
|
+
const command = event.metaKey || event.ctrlKey;
|
|
3154
|
+
const key = event.key.toLowerCase();
|
|
3155
|
+
if (event.key === "Escape") {
|
|
3156
|
+
if (cropRef.current !== null) setCropDraft(null);
|
|
3157
|
+
else if (drawingRef.current !== null) setDrawing(null);
|
|
3158
|
+
else if (dragRef.current !== null) setDrag(null);
|
|
3159
|
+
else select(null);
|
|
3160
|
+
return true;
|
|
3161
|
+
}
|
|
3162
|
+
if (command) {
|
|
3163
|
+
if (key === "z") (event.shiftKey ? redo : undo)();
|
|
3164
|
+
else if (key === "y") redo();
|
|
3165
|
+
else if (key === "c") void run("copy");
|
|
3166
|
+
else if (key === "s") void run("save");
|
|
3167
|
+
else if (key === "=" || key === "+") zoomStep(1);
|
|
3168
|
+
else if (key === "-") zoomStep(-1);
|
|
3169
|
+
else if (key === "0") zoomTo(null);
|
|
3170
|
+
else if (key === "1") zoomTo(1 / ratio);
|
|
3171
|
+
else return false;
|
|
3172
|
+
return true;
|
|
3173
|
+
}
|
|
3174
|
+
if (event.altKey) return false;
|
|
3175
|
+
if ((event.key === "Delete" || event.key === "Backspace") && selected !== null) {
|
|
3176
|
+
replaceAt(selected, null);
|
|
3177
|
+
setSelected(null);
|
|
3178
|
+
return true;
|
|
3179
|
+
}
|
|
3180
|
+
const nudge = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }[event.key];
|
|
3181
|
+
const mark = selected === null ? void 0 : marks[selected];
|
|
3182
|
+
if (nudge !== void 0 && selected !== null && mark !== void 0) {
|
|
3183
|
+
const step = (event.shiftKey ? 10 : 1) / scale;
|
|
3184
|
+
replaceAt(selected, translate(mark, (nudge[0] ?? 0) * step, (nudge[1] ?? 0) * step));
|
|
3185
|
+
return true;
|
|
3186
|
+
}
|
|
3187
|
+
const weightKey = WEIGHTS.find((entry) => String(entry.weight) === event.key);
|
|
3188
|
+
if (weightKey !== void 0) {
|
|
3189
|
+
pickWeight(weightKey.weight);
|
|
3190
|
+
return true;
|
|
3191
|
+
}
|
|
3192
|
+
const toolKey = TOOLS.find((entry) => entry.key === event.key.toUpperCase());
|
|
3193
|
+
if (toolKey !== void 0) {
|
|
3194
|
+
chooseTool(toolKey.tool);
|
|
3195
|
+
return true;
|
|
3196
|
+
}
|
|
3197
|
+
return false;
|
|
3198
|
+
};
|
|
3199
|
+
useLayoutEffect2(() => {
|
|
3200
|
+
keyRef.current = onKey;
|
|
3201
|
+
wheelRef.current = onWheel;
|
|
3202
|
+
pickColorRef.current = pickColor;
|
|
3203
|
+
});
|
|
3204
|
+
useEffect2(() => {
|
|
3205
|
+
const typing = (target) => target instanceof HTMLTextAreaElement || target instanceof HTMLInputElement && target.type !== "color";
|
|
3206
|
+
const onKeyDown = (event) => {
|
|
3207
|
+
if (typing(event.target)) return;
|
|
3208
|
+
if (event.key === " ") {
|
|
3209
|
+
event.preventDefault();
|
|
3210
|
+
setSpaceHeld(true);
|
|
3211
|
+
return;
|
|
3212
|
+
}
|
|
3213
|
+
if (keyRef.current(event)) {
|
|
3214
|
+
event.preventDefault();
|
|
3215
|
+
event.stopPropagation();
|
|
3216
|
+
}
|
|
3217
|
+
};
|
|
3218
|
+
const onKeyUp = (event) => {
|
|
3219
|
+
if (event.key === " ") setSpaceHeld(false);
|
|
3220
|
+
};
|
|
3221
|
+
window.addEventListener("keydown", onKeyDown, true);
|
|
3222
|
+
window.addEventListener("keyup", onKeyUp, true);
|
|
3223
|
+
return () => {
|
|
3224
|
+
window.removeEventListener("keydown", onKeyDown, true);
|
|
3225
|
+
window.removeEventListener("keyup", onKeyUp, true);
|
|
3226
|
+
};
|
|
3227
|
+
}, []);
|
|
3228
|
+
const cursor = panning ? "grabbing" : spaceHeld ? "grab" : tool === "select" ? drag !== null ? "grabbing" : hovering ? "move" : "default" : "crosshair";
|
|
3229
|
+
const custom = !COLORS.includes(color.toUpperCase());
|
|
3230
|
+
const textLayout = text === null ? null : calloutLayout({ at: text.at, text: text.value, weight: text.weight }, image.width, measureText());
|
|
3231
|
+
return /* @__PURE__ */ jsxs5(
|
|
3232
|
+
"div",
|
|
3233
|
+
{
|
|
3234
|
+
ref: dialogRef,
|
|
3235
|
+
role: "dialog",
|
|
3236
|
+
"aria-modal": "true",
|
|
3237
|
+
"aria-label": "Screenshot editor",
|
|
3238
|
+
style: { ...FONT2, position: "fixed", inset: 0, display: "flex", flexDirection: "column", background: "#0E0E0E", zIndex: Z + 5 },
|
|
3239
|
+
children: [
|
|
3240
|
+
/* @__PURE__ */ jsxs5(
|
|
3241
|
+
"div",
|
|
3242
|
+
{
|
|
3243
|
+
role: "toolbar",
|
|
3244
|
+
"aria-label": "Markup tools",
|
|
3245
|
+
style: { display: "flex", alignItems: "center", gap: 2, padding: "8px 12px", background: INK, borderBottom: "1px solid rgba(255,255,255,0.12)", flexWrap: "wrap", rowGap: 6 },
|
|
3246
|
+
children: [
|
|
3247
|
+
TOOLS.map((entry) => /* @__PURE__ */ jsx6(
|
|
3248
|
+
BarButton,
|
|
3249
|
+
{
|
|
3250
|
+
icon: entry.icon,
|
|
3251
|
+
label: entry.label,
|
|
3252
|
+
detail: entry.detail,
|
|
3253
|
+
shortcut: [entry.key],
|
|
3254
|
+
pressed: tool === entry.tool,
|
|
3255
|
+
onClick: () => chooseTool(entry.tool)
|
|
3256
|
+
},
|
|
3257
|
+
entry.tool
|
|
3258
|
+
)),
|
|
3259
|
+
/* @__PURE__ */ jsx6(Divider2, {}),
|
|
3260
|
+
COLORS.map((swatch) => /* @__PURE__ */ jsx6(Tooltip, { label: COLOR_NAMES[swatch] ?? swatch, placement: "below", children: (describedBy) => /* @__PURE__ */ jsx6(
|
|
3261
|
+
"button",
|
|
3262
|
+
{
|
|
3263
|
+
type: "button",
|
|
3264
|
+
onClick: () => pickColor(swatch),
|
|
3265
|
+
"aria-label": `Colour ${COLOR_NAMES[swatch] ?? swatch}`,
|
|
3266
|
+
"aria-describedby": describedBy,
|
|
3267
|
+
"aria-pressed": color.toUpperCase() === swatch,
|
|
3268
|
+
style: swatchStyle(swatch, color.toUpperCase() === swatch)
|
|
3269
|
+
}
|
|
3270
|
+
) }, swatch)),
|
|
3271
|
+
/* @__PURE__ */ jsx6(Tooltip, { label: "Custom colour", detail: "Pick any colour.", placement: "below", children: (describedBy) => /* @__PURE__ */ jsxs5("span", { style: { position: "relative", display: "inline-flex" }, children: [
|
|
3272
|
+
/* @__PURE__ */ jsx6(
|
|
3273
|
+
"span",
|
|
3274
|
+
{
|
|
3275
|
+
"aria-hidden": "true",
|
|
3276
|
+
style: {
|
|
3277
|
+
...swatchStyle(custom ? color : "#FFFFFF", custom),
|
|
3278
|
+
background: custom ? `radial-gradient(circle, ${color} 0 45%, transparent 47%), conic-gradient(#E5484D, #F5A524, #30A46C, #0091FF, #8E4EC6, #E5484D)` : "conic-gradient(#E5484D, #F5A524, #30A46C, #0091FF, #8E4EC6, #E5484D)"
|
|
3279
|
+
}
|
|
3280
|
+
}
|
|
3281
|
+
),
|
|
3282
|
+
/* @__PURE__ */ jsx6(
|
|
3283
|
+
"input",
|
|
3284
|
+
{
|
|
3285
|
+
ref: customColorRef,
|
|
3286
|
+
type: "color",
|
|
3287
|
+
"aria-label": "Custom colour",
|
|
3288
|
+
"aria-describedby": describedBy,
|
|
3289
|
+
value: /^#[0-9a-f]{6}$/i.test(color) ? color : "#000000",
|
|
3290
|
+
onChange: (event) => setColor(event.target.value),
|
|
3291
|
+
style: { position: "absolute", inset: 0, width: "100%", height: "100%", opacity: 0, cursor: "pointer", padding: 0, border: 0 }
|
|
3292
|
+
}
|
|
3293
|
+
)
|
|
3294
|
+
] }) }),
|
|
3295
|
+
/* @__PURE__ */ jsx6(Divider2, {}),
|
|
3296
|
+
WEIGHTS.map((entry) => /* @__PURE__ */ jsx6(Tooltip, { label: `${entry.label} stroke`, shortcut: [String(entry.weight)], placement: "below", children: (describedBy) => /* @__PURE__ */ jsx6(
|
|
3297
|
+
"button",
|
|
3298
|
+
{
|
|
3299
|
+
type: "button",
|
|
3300
|
+
onClick: () => pickWeight(entry.weight),
|
|
3301
|
+
"aria-label": `${entry.label} stroke`,
|
|
3302
|
+
"aria-describedby": describedBy,
|
|
3303
|
+
"aria-pressed": weight === entry.weight,
|
|
3304
|
+
style: { ...iconButton(weight === entry.weight), width: 30, minWidth: 30 },
|
|
3305
|
+
children: /* @__PURE__ */ jsx6("span", { "aria-hidden": "true", style: { width: entry.dot, height: entry.dot, borderRadius: entry.dot, background: "#FFFFFF" } })
|
|
3306
|
+
}
|
|
3307
|
+
) }, entry.weight)),
|
|
3308
|
+
/* @__PURE__ */ jsx6(Divider2, {}),
|
|
3309
|
+
/* @__PURE__ */ jsx6(BarButton, { icon: "undo", label: "Undo", shortcut: [MOD_KEY, "Z"], disabled: history.past.length === 0, onClick: undo }),
|
|
3310
|
+
/* @__PURE__ */ jsx6(BarButton, { icon: "redo", label: "Redo", shortcut: [MOD_KEY, "\u21E7", "Z"], disabled: history.future.length === 0, onClick: redo }),
|
|
3311
|
+
/* @__PURE__ */ jsx6(
|
|
3312
|
+
BarButton,
|
|
3313
|
+
{
|
|
3314
|
+
icon: "eraser",
|
|
3315
|
+
label: "Delete selected",
|
|
3316
|
+
detail: "Select a mark with V first.",
|
|
3317
|
+
shortcut: ["\u232B"],
|
|
3318
|
+
disabled: selected === null,
|
|
3319
|
+
onClick: () => {
|
|
3320
|
+
if (selected === null) return;
|
|
3321
|
+
replaceAt(selected, null);
|
|
3322
|
+
setSelected(null);
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
),
|
|
3326
|
+
/* @__PURE__ */ jsx6(BarButton, { icon: "trash", label: "Clear all marks", disabled: marks.length === 0, onClick: () => commit(NO_MARKS) }),
|
|
3327
|
+
/* @__PURE__ */ jsx6(
|
|
3328
|
+
BarButton,
|
|
3329
|
+
{
|
|
3330
|
+
icon: "cropOff",
|
|
3331
|
+
label: "Reset crop",
|
|
3332
|
+
detail: crop === null ? "The image is not cropped." : "Show the whole capture again.",
|
|
3333
|
+
disabled: crop === null,
|
|
3334
|
+
onClick: () => commitCrop(null)
|
|
3335
|
+
}
|
|
3336
|
+
),
|
|
3337
|
+
/* @__PURE__ */ jsx6("span", { style: { flex: 1, minWidth: 8 } }),
|
|
3338
|
+
/* @__PURE__ */ jsx6(BarButton, { icon: "zoomOut", label: "Zoom out", shortcut: [MOD_KEY, "\u2212"], disabled: percent <= MIN_ZOOM * 1.01, onClick: () => zoomStep(-1) }),
|
|
3339
|
+
/* @__PURE__ */ jsx6(Tooltip, { label: zoom === null ? "Actual size" : "Fit to window", shortcut: zoom === null ? [MOD_KEY, "1"] : [MOD_KEY, "0"], placement: "below", children: (describedBy) => /* @__PURE__ */ jsx6(
|
|
3340
|
+
"button",
|
|
3341
|
+
{
|
|
3342
|
+
type: "button",
|
|
3343
|
+
onClick: () => zoomTo(zoom === null ? 1 / ratio : null),
|
|
3344
|
+
"aria-label": `Zoom ${Math.round(percent * 100)}%`,
|
|
3345
|
+
"aria-describedby": describedBy,
|
|
3346
|
+
style: { ...iconButton(false), minWidth: 54, padding: "0 6px", fontVariantNumeric: "tabular-nums" },
|
|
3347
|
+
children: /* @__PURE__ */ jsxs5("span", { style: { ...FONT2, color: "inherit", fontWeight: 600, fontSize: 12 }, children: [
|
|
3348
|
+
Math.round(percent * 100),
|
|
3349
|
+
"%"
|
|
3350
|
+
] })
|
|
3351
|
+
}
|
|
3352
|
+
) }),
|
|
3353
|
+
/* @__PURE__ */ jsx6(BarButton, { icon: "zoomIn", label: "Zoom in", shortcut: [MOD_KEY, "+"], disabled: percent >= MAX_ZOOM * 0.99, onClick: () => zoomStep(1) }),
|
|
3354
|
+
/* @__PURE__ */ jsx6(BarButton, { icon: "fit", label: "Fit to window", shortcut: [MOD_KEY, "0"], pressed: zoom === null, onClick: () => zoomTo(null) }),
|
|
3355
|
+
/* @__PURE__ */ jsx6(Divider2, {}),
|
|
3356
|
+
/* @__PURE__ */ jsx6(BarButton, { icon: "copy", label: "Copy image", shortcut: [MOD_KEY, "C"], text: "Copy", primary: true, onClick: () => void run("copy") }),
|
|
3357
|
+
/* @__PURE__ */ jsx6(BarButton, { icon: "download", label: "Save as PNG", detail: fileName, shortcut: [MOD_KEY, "S"], text: "Save", onClick: () => void run("save") }),
|
|
3358
|
+
/* @__PURE__ */ jsx6(
|
|
3359
|
+
BarButton,
|
|
3360
|
+
{
|
|
3361
|
+
icon: "close",
|
|
3362
|
+
label: confirmClose ? "Discard marks and close" : "Close",
|
|
3363
|
+
detail: confirmClose ? "Click again to close without copying or saving." : dirty ? "Your marks are not copied or saved yet." : void 0,
|
|
3364
|
+
text: confirmClose ? "Discard?" : void 0,
|
|
3365
|
+
danger: confirmClose,
|
|
3366
|
+
onClick: requestClose
|
|
3367
|
+
}
|
|
3368
|
+
)
|
|
3369
|
+
]
|
|
3370
|
+
}
|
|
3371
|
+
),
|
|
3372
|
+
showTip && tipAt !== null ? /* @__PURE__ */ jsx6(CalloutTip, { left: tipAt.left, top: tipAt.top, nudge: tipNudge, onDismiss: learnCallout }) : null,
|
|
3373
|
+
/* @__PURE__ */ jsx6("div", { ref: areaRef, style: { position: "relative", flex: 1, minHeight: 0, overflow: "auto" }, children: /* @__PURE__ */ jsx6("div", { style: { display: "flex", minWidth: "100%", minHeight: "100%", width: "max-content", height: "max-content" }, children: /* @__PURE__ */ jsxs5("div", { style: { position: "relative", margin: "auto", width: board.width * scale, height: board.height * scale, flex: "none" }, children: [
|
|
3374
|
+
/* @__PURE__ */ jsx6(
|
|
3375
|
+
"canvas",
|
|
3376
|
+
{
|
|
3377
|
+
ref: canvasRef,
|
|
3378
|
+
width: board.width,
|
|
3379
|
+
height: board.height,
|
|
3380
|
+
onPointerDown,
|
|
3381
|
+
onPointerMove,
|
|
3382
|
+
onPointerUp,
|
|
3383
|
+
onPointerCancel: onPointerUp,
|
|
3384
|
+
onPointerLeave: () => setHovering(false),
|
|
3385
|
+
onDoubleClick: (event) => {
|
|
3386
|
+
const index = pick(imagePoint(event), "text");
|
|
3387
|
+
if (index !== null) editText(index);
|
|
3388
|
+
},
|
|
3389
|
+
style: {
|
|
3390
|
+
display: "block",
|
|
3391
|
+
width: "100%",
|
|
3392
|
+
height: "100%",
|
|
3393
|
+
cursor,
|
|
3394
|
+
touchAction: "none"
|
|
3395
|
+
}
|
|
3396
|
+
}
|
|
3397
|
+
),
|
|
3398
|
+
text === null || textLayout === null ? null : /* @__PURE__ */ jsx6(
|
|
3399
|
+
"textarea",
|
|
3400
|
+
{
|
|
3401
|
+
"aria-label": "Callout text",
|
|
3402
|
+
autoFocus: true,
|
|
3403
|
+
spellCheck: false,
|
|
3404
|
+
rows: textLayout.lines.length,
|
|
3405
|
+
value: text.value,
|
|
3406
|
+
onChange: (event) => setText({ ...text, value: event.target.value }),
|
|
3407
|
+
onBlur: commitText,
|
|
3408
|
+
onKeyDown: (event) => {
|
|
3409
|
+
event.stopPropagation();
|
|
3410
|
+
if (event.key === "Escape") setText(null);
|
|
3411
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
3412
|
+
event.preventDefault();
|
|
3413
|
+
commitText();
|
|
3414
|
+
}
|
|
3415
|
+
},
|
|
3416
|
+
style: {
|
|
3417
|
+
position: "absolute",
|
|
3418
|
+
left: (textLayout.box.x - board.x) * scale,
|
|
3419
|
+
top: (textLayout.box.y - board.y) * scale,
|
|
3420
|
+
width: textLayout.box.width * scale,
|
|
3421
|
+
height: textLayout.box.height * scale,
|
|
3422
|
+
margin: 0,
|
|
3423
|
+
padding: `${textLayout.padY * scale}px ${textLayout.padX * scale}px`,
|
|
3424
|
+
boxSizing: "border-box",
|
|
3425
|
+
border: 0,
|
|
3426
|
+
borderRadius: textLayout.radius * scale,
|
|
3427
|
+
outline: "1.5px dashed rgba(255,255,255,0.85)",
|
|
3428
|
+
outlineOffset: 3,
|
|
3429
|
+
resize: "none",
|
|
3430
|
+
overflow: "hidden",
|
|
3431
|
+
whiteSpace: "pre",
|
|
3432
|
+
textAlign: "center",
|
|
3433
|
+
background: "transparent",
|
|
3434
|
+
// The canvas paints the text; this only shows the caret and the selection.
|
|
3435
|
+
color: "transparent",
|
|
3436
|
+
caretColor: textColorOn(text.color),
|
|
3437
|
+
font: `600 ${textLayout.size * scale}px/${textLayout.lineHeight * scale}px ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif`
|
|
3438
|
+
}
|
|
3439
|
+
}
|
|
3440
|
+
)
|
|
3441
|
+
] }) }) }),
|
|
3442
|
+
/* @__PURE__ */ jsx6(
|
|
3443
|
+
"div",
|
|
3444
|
+
{
|
|
3445
|
+
"aria-hidden": "true",
|
|
3446
|
+
style: { ...FONT2, padding: "6px 12px", fontSize: 12, color: "#9C978F", background: INK, borderTop: "1px solid rgba(255,255,255,0.08)", textAlign: "center" },
|
|
3447
|
+
children: tool === "select" ? "Drag a mark to move it (Shift keeps one axis) \xB7 drag a callout\u2019s round grip to re-aim its tail \xB7 arrow keys nudge \xB7 \u232B deletes \xB7 double-click text to edit" : tool === "text" ? "Drag from what you point at to where the text goes \xB7 click for a box without a tail \xB7 Enter places it, Shift+Enter adds a line" : `Hold Space and drag to pan \xB7 ${MOD_KEY} + scroll to zoom \xB7 V to select and move marks \xB7 Esc cancels`
|
|
3448
|
+
}
|
|
3449
|
+
)
|
|
3450
|
+
]
|
|
3451
|
+
}
|
|
3452
|
+
);
|
|
3453
|
+
}
|
|
3454
|
+
var COLOR_NAMES = {
|
|
3455
|
+
"#E5484D": "Red",
|
|
3456
|
+
"#F5A524": "Amber",
|
|
3457
|
+
"#30A46C": "Green",
|
|
3458
|
+
"#0091FF": "Blue",
|
|
3459
|
+
"#8E4EC6": "Purple",
|
|
3460
|
+
"#1F1E1D": "Black"
|
|
3461
|
+
};
|
|
3462
|
+
function swatchStyle(fill, active) {
|
|
3463
|
+
return {
|
|
3464
|
+
appearance: "none",
|
|
3465
|
+
display: "block",
|
|
3466
|
+
width: 22,
|
|
3467
|
+
height: 22,
|
|
3468
|
+
margin: "0 3px",
|
|
3469
|
+
padding: 0,
|
|
3470
|
+
borderRadius: 11,
|
|
3471
|
+
background: fill,
|
|
3472
|
+
border: active ? "2px solid #FFFFFF" : "2px solid rgba(255,255,255,0.25)",
|
|
3473
|
+
boxShadow: active ? `0 0 0 2px ${fill === "#FFFFFF" ? ACCENT : fill}` : "none",
|
|
3474
|
+
cursor: "pointer",
|
|
3475
|
+
boxSizing: "border-box"
|
|
3476
|
+
};
|
|
3477
|
+
}
|
|
3478
|
+
function iconButton(pressed) {
|
|
3479
|
+
return {
|
|
3480
|
+
...FONT2,
|
|
3481
|
+
appearance: "none",
|
|
3482
|
+
height: 34,
|
|
3483
|
+
minWidth: 34,
|
|
3484
|
+
display: "inline-flex",
|
|
3485
|
+
alignItems: "center",
|
|
3486
|
+
justifyContent: "center",
|
|
3487
|
+
gap: 6,
|
|
3488
|
+
padding: 0,
|
|
3489
|
+
border: 0,
|
|
3490
|
+
borderRadius: 8,
|
|
3491
|
+
cursor: "pointer",
|
|
3492
|
+
color: "#FFFFFF",
|
|
3493
|
+
background: pressed ? "rgba(255,255,255,0.2)" : "transparent"
|
|
3494
|
+
};
|
|
3495
|
+
}
|
|
3496
|
+
function Divider2() {
|
|
3497
|
+
return /* @__PURE__ */ jsx6("span", { "aria-hidden": "true", style: { width: 1, height: 20, margin: "0 6px", background: "rgba(255,255,255,0.18)" } });
|
|
3498
|
+
}
|
|
3499
|
+
function BarButton(props) {
|
|
3500
|
+
return /* @__PURE__ */ jsx6(Tooltip, { label: props.label, ...props.detail === void 0 ? {} : { detail: props.detail }, ...props.shortcut === void 0 ? {} : { shortcut: props.shortcut }, placement: "below", children: (describedBy) => /* @__PURE__ */ jsxs5(
|
|
3501
|
+
"button",
|
|
3502
|
+
{
|
|
3503
|
+
type: "button",
|
|
3504
|
+
onClick: props.onClick,
|
|
3505
|
+
disabled: props.disabled,
|
|
3506
|
+
"aria-label": props.label,
|
|
3507
|
+
"aria-describedby": describedBy,
|
|
3508
|
+
...props.pressed === void 0 ? {} : { "aria-pressed": props.pressed },
|
|
3509
|
+
style: {
|
|
3510
|
+
...iconButton(props.pressed === true),
|
|
3511
|
+
padding: props.text === void 0 ? 0 : "0 12px",
|
|
3512
|
+
cursor: props.disabled ? "default" : "pointer",
|
|
3513
|
+
opacity: props.disabled ? 0.35 : 1,
|
|
3514
|
+
background: props.danger ? "#B42318" : props.primary ? ACCENT : props.pressed ? "rgba(255,255,255,0.2)" : "transparent"
|
|
3515
|
+
},
|
|
3516
|
+
children: [
|
|
3517
|
+
/* @__PURE__ */ jsx6(Icon, { name: props.icon }),
|
|
3518
|
+
props.text === void 0 ? null : /* @__PURE__ */ jsx6("span", { style: { ...FONT2, color: "inherit", fontWeight: 600 }, children: props.text })
|
|
3519
|
+
]
|
|
3520
|
+
}
|
|
3521
|
+
) });
|
|
3522
|
+
}
|
|
3523
|
+
function straighten(from, to, tool) {
|
|
3524
|
+
const dx = to.x - from.x;
|
|
3525
|
+
const dy = to.y - from.y;
|
|
3526
|
+
if (tool === "arrow" || tool === "ruler") {
|
|
3527
|
+
const angle = Math.round(Math.atan2(dy, dx) / (Math.PI / 4)) * (Math.PI / 4);
|
|
3528
|
+
const length = Math.hypot(dx, dy);
|
|
3529
|
+
return { x: from.x + length * Math.cos(angle), y: from.y + length * Math.sin(angle) };
|
|
3530
|
+
}
|
|
3531
|
+
const side = Math.max(Math.abs(dx), Math.abs(dy));
|
|
3532
|
+
return { x: from.x + Math.sign(dx || 1) * side, y: from.y + Math.sign(dy || 1) * side };
|
|
3533
|
+
}
|
|
3534
|
+
function clampTo(box, within) {
|
|
3535
|
+
const x = Math.max(box.x, within.x);
|
|
3536
|
+
const y = Math.max(box.y, within.y);
|
|
3537
|
+
return {
|
|
3538
|
+
x,
|
|
3539
|
+
y,
|
|
3540
|
+
width: Math.max(0, Math.min(box.x + box.width, within.x + within.width) - x),
|
|
3541
|
+
height: Math.max(0, Math.min(box.y + box.height, within.y + within.height) - y)
|
|
3542
|
+
};
|
|
3543
|
+
}
|
|
3544
|
+
function boardAround(content, image, area, scale) {
|
|
3545
|
+
const width = Math.max(0, area.width - 2) / scale;
|
|
3546
|
+
const height = Math.max(0, area.height - 2) / scale;
|
|
3547
|
+
const centre = { x: image.x + image.width / 2, y: image.y + image.height / 2 };
|
|
3548
|
+
const box = union(content, { x: centre.x - width / 2, y: centre.y - height / 2, width, height });
|
|
3549
|
+
const x = Math.floor(box.x);
|
|
3550
|
+
const y = Math.floor(box.y);
|
|
3551
|
+
const right = box.width > content.width + 1 ? Math.floor(box.x + box.width) : Math.ceil(box.x + box.width);
|
|
3552
|
+
const bottom = box.height > content.height + 1 ? Math.floor(box.y + box.height) : Math.ceil(box.y + box.height);
|
|
3553
|
+
return { x, y, width: right - x, height: bottom - y };
|
|
3554
|
+
}
|
|
3555
|
+
|
|
3556
|
+
// src/annotator.tsx
|
|
3557
|
+
import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
3558
|
+
var ISOLATED = ["pointerdown", "pointerup", "mousedown", "mouseup", "dblclick"];
|
|
3559
|
+
var REFLOW_MS = 400;
|
|
3560
|
+
var MIN_AREA = 8;
|
|
3561
|
+
var HINT_HIDDEN_KEY = "agent-annotator:hint-hidden";
|
|
3562
|
+
var SHOW_COMMENTS_KEY = "agent-annotator:show-comments";
|
|
3563
|
+
var COLLAPSED_KEY = "agent-annotator:toolbar-collapsed";
|
|
3564
|
+
var NOTICE_MS = 5e3;
|
|
3565
|
+
var KIND_LABEL = {
|
|
3566
|
+
element: () => "",
|
|
3567
|
+
text: () => "text",
|
|
3568
|
+
group: (count) => `${count} element`,
|
|
3569
|
+
area: () => "area"
|
|
3570
|
+
};
|
|
3571
|
+
function DevAnnotator(props) {
|
|
3572
|
+
const { appName, appDir } = props;
|
|
3573
|
+
const storageKey = `agent-annotator:${appName}`;
|
|
3574
|
+
const redactionKey = `agent-annotator:redaction:${appName}`;
|
|
3575
|
+
const redactionDefaults = resolveRedaction(props.redaction);
|
|
3576
|
+
const [savedRedaction, setSavedRedaction] = useState3(() => readRedaction(redactionKey));
|
|
3577
|
+
const redaction = savedRedaction ?? redactionDefaults;
|
|
3578
|
+
const redactionJson = JSON.stringify(redaction);
|
|
3579
|
+
const redactor = useMemo(() => createRedactor(JSON.parse(redactionJson)), [redactionJson]);
|
|
3580
|
+
const [settingsOpen, setSettingsOpen] = useState3(false);
|
|
3581
|
+
const [resolveFrames] = useState3(() => props.resolveFrames ?? createNextResolver());
|
|
3582
|
+
const [active, setActive] = useState3(false);
|
|
3583
|
+
const [items, setItems] = useState3(() => restore(storageKey));
|
|
3584
|
+
const [includeData, setIncludeData] = useState3(true);
|
|
3585
|
+
const [panelOpen, setPanelOpen] = useState3(true);
|
|
3586
|
+
const [paused, setPaused] = useState3(false);
|
|
3587
|
+
const [hintHidden, setHintHidden] = useState3(() => readFlag(HINT_HIDDEN_KEY));
|
|
3588
|
+
const [hover, setHover] = useState3(null);
|
|
3589
|
+
const [group, setGroup] = useState3([]);
|
|
3590
|
+
const [dragBox, setDragBox] = useState3(null);
|
|
3591
|
+
const [draft, setDraft] = useState3(null);
|
|
3592
|
+
const [showComments, setShowComments] = useState3(() => readFlag(SHOW_COMMENTS_KEY));
|
|
3593
|
+
const [collapsed, setCollapsed] = useState3(() => readFlag(COLLAPSED_KEY));
|
|
3594
|
+
const [capturing, setCapturing] = useState3(false);
|
|
3595
|
+
const [shot, setShot] = useState3(null);
|
|
3596
|
+
const [notice, setNotice] = useState3(null);
|
|
3597
|
+
const [, setFrame] = useState3(0);
|
|
3598
|
+
useEffect3(() => {
|
|
3599
|
+
persist(
|
|
3600
|
+
storageKey,
|
|
3601
|
+
items.map((item) => item.annotation)
|
|
3602
|
+
);
|
|
3603
|
+
}, [items, storageKey]);
|
|
3604
|
+
const draftRef = useRef3(null);
|
|
3605
|
+
const groupRef = useRef3([]);
|
|
3606
|
+
const shotOpenRef = useRef3(false);
|
|
3607
|
+
useEffect3(() => {
|
|
3608
|
+
draftRef.current = draft;
|
|
3609
|
+
groupRef.current = group;
|
|
3610
|
+
shotOpenRef.current = shot !== null || capturing;
|
|
3611
|
+
});
|
|
3612
|
+
const startDraft = useCallback(
|
|
3613
|
+
(selection) => {
|
|
3614
|
+
if (draftRef.current !== null && draftRef.current.comment.trim() !== "") return;
|
|
3615
|
+
const several = selection.elements.length > 1;
|
|
3616
|
+
const captures = Promise.all(
|
|
3617
|
+
selection.elements.map(
|
|
3618
|
+
(element) => captureElement(element, resolveFrames, { dataComponents: several ? 1 : 2, redactor })
|
|
3619
|
+
)
|
|
3620
|
+
);
|
|
3621
|
+
const screened = selection.selectedText === void 0 ? {} : { selectedText: truncate(redactor.text(selection.selectedText), 500) };
|
|
3622
|
+
setDraft({ ...selection, ...screened, captures, comment: "", redacted: redactor.enabled, editingId: null });
|
|
3623
|
+
},
|
|
3624
|
+
[resolveFrames, redactor]
|
|
3625
|
+
);
|
|
3626
|
+
useEffect3(() => {
|
|
3627
|
+
if (!active) return void 0;
|
|
3628
|
+
let dragStart = null;
|
|
3629
|
+
let swallowNextClick = false;
|
|
3630
|
+
const ignored = (event) => event.altKey || event.target instanceof Element && event.target.closest(OWN_SELECTOR) !== null;
|
|
3631
|
+
const isolate = (event) => {
|
|
3632
|
+
if (ignored(event)) return;
|
|
3633
|
+
event.stopPropagation();
|
|
3634
|
+
event.stopImmediatePropagation();
|
|
3635
|
+
};
|
|
3636
|
+
const onMouseDown = (event) => {
|
|
3637
|
+
if (ignored(event)) return;
|
|
3638
|
+
isolate(event);
|
|
3639
|
+
if (event.shiftKey) {
|
|
3640
|
+
event.preventDefault();
|
|
3641
|
+
dragStart = { x: event.clientX, y: event.clientY };
|
|
3642
|
+
setDragBox({ x: event.clientX, y: event.clientY, width: 0, height: 0 });
|
|
3643
|
+
}
|
|
3644
|
+
};
|
|
3645
|
+
const onMouseUp = (event) => {
|
|
3646
|
+
if (ignored(event)) return;
|
|
3647
|
+
isolate(event);
|
|
3648
|
+
if (dragStart !== null) {
|
|
3649
|
+
const area = rectBetween(dragStart, { x: event.clientX, y: event.clientY });
|
|
3650
|
+
dragStart = null;
|
|
3651
|
+
setDragBox(null);
|
|
3652
|
+
if (area.width >= MIN_AREA && area.height >= MIN_AREA) {
|
|
3653
|
+
swallowNextClick = true;
|
|
3654
|
+
const { container, inside: inside2 } = elementsInArea(document, area);
|
|
3655
|
+
const origin = container.getBoundingClientRect();
|
|
3656
|
+
startDraft({
|
|
3657
|
+
kind: "area",
|
|
3658
|
+
elements: [container, ...inside2],
|
|
3659
|
+
label: `Area ${area.width}\xD7${area.height}`,
|
|
3660
|
+
area,
|
|
3661
|
+
areaInContainer: { ...area, x: area.x - origin.left, y: area.y - origin.top }
|
|
3662
|
+
});
|
|
3663
|
+
}
|
|
3664
|
+
return;
|
|
3665
|
+
}
|
|
3666
|
+
const text = selectedText();
|
|
3667
|
+
if (text !== null) {
|
|
3668
|
+
swallowNextClick = true;
|
|
3669
|
+
startDraft({ kind: "text", elements: [text.element], label: `Text \xB7 ${hoverLabel(text.element)}`, selectedText: text.text });
|
|
3670
|
+
}
|
|
3671
|
+
};
|
|
3672
|
+
const onClick = (event) => {
|
|
3673
|
+
if (ignored(event) || !(event.target instanceof Element)) return;
|
|
3674
|
+
event.preventDefault();
|
|
3675
|
+
isolate(event);
|
|
3676
|
+
if (swallowNextClick) {
|
|
3677
|
+
swallowNextClick = false;
|
|
3678
|
+
return;
|
|
3679
|
+
}
|
|
3680
|
+
const element = pickTarget(event.target);
|
|
3681
|
+
if (event.metaKey || event.ctrlKey) {
|
|
3682
|
+
setGroup(
|
|
3683
|
+
(current) => current.includes(element) ? current.filter((kept) => kept !== element) : [...current, element]
|
|
3684
|
+
);
|
|
3685
|
+
return;
|
|
3686
|
+
}
|
|
3687
|
+
startDraft({ kind: "element", elements: [element], label: hoverLabel(element) });
|
|
3688
|
+
};
|
|
3689
|
+
const onKeyUp = (event) => {
|
|
3690
|
+
if (event.key !== "Meta" && event.key !== "Control") return;
|
|
3691
|
+
const elements = groupRef.current;
|
|
3692
|
+
if (elements.length === 0) return;
|
|
3693
|
+
setGroup([]);
|
|
3694
|
+
const [only] = elements;
|
|
3695
|
+
if (elements.length === 1 && only !== void 0) {
|
|
3696
|
+
startDraft({ kind: "element", elements: [only], label: hoverLabel(only) });
|
|
3697
|
+
} else {
|
|
3698
|
+
startDraft({ kind: "group", elements, label: `${elements.length} element` });
|
|
3699
|
+
}
|
|
3700
|
+
};
|
|
3701
|
+
const onMove = (event) => {
|
|
3702
|
+
if (dragStart !== null) {
|
|
3703
|
+
setDragBox(rectBetween(dragStart, { x: event.clientX, y: event.clientY }));
|
|
3704
|
+
return;
|
|
3705
|
+
}
|
|
3706
|
+
if (!(event.target instanceof Element) || event.target.closest(OWN_SELECTOR) !== null) {
|
|
3707
|
+
setHover(null);
|
|
3708
|
+
return;
|
|
3709
|
+
}
|
|
3710
|
+
const element = pickTarget(event.target);
|
|
3711
|
+
setHover((current) => current?.element === element ? current : { element, label: hoverLabel(element) });
|
|
3712
|
+
};
|
|
3713
|
+
for (const type of ISOLATED) {
|
|
3714
|
+
if (type !== "mousedown" && type !== "mouseup") window.addEventListener(type, isolate, true);
|
|
3715
|
+
}
|
|
3716
|
+
window.addEventListener("mousedown", onMouseDown, true);
|
|
3717
|
+
window.addEventListener("mouseup", onMouseUp, true);
|
|
3718
|
+
window.addEventListener("click", onClick, true);
|
|
3719
|
+
window.addEventListener("pointermove", onMove, true);
|
|
3720
|
+
window.addEventListener("keyup", onKeyUp, true);
|
|
3721
|
+
const root = document.documentElement;
|
|
3722
|
+
const previousCursor = root.style.cursor;
|
|
3723
|
+
root.style.cursor = "crosshair";
|
|
3724
|
+
return () => {
|
|
3725
|
+
for (const type of ISOLATED) window.removeEventListener(type, isolate, true);
|
|
3726
|
+
window.removeEventListener("mousedown", onMouseDown, true);
|
|
3727
|
+
window.removeEventListener("mouseup", onMouseUp, true);
|
|
3728
|
+
window.removeEventListener("click", onClick, true);
|
|
3729
|
+
window.removeEventListener("pointermove", onMove, true);
|
|
3730
|
+
window.removeEventListener("keyup", onKeyUp, true);
|
|
3731
|
+
root.style.cursor = previousCursor;
|
|
3732
|
+
setHover(null);
|
|
3733
|
+
setGroup([]);
|
|
3734
|
+
setDragBox(null);
|
|
3735
|
+
};
|
|
3736
|
+
}, [active, startDraft]);
|
|
3737
|
+
useEffect3(() => {
|
|
3738
|
+
const onKey = (event) => {
|
|
3739
|
+
if (shotOpenRef.current) return;
|
|
3740
|
+
if (event.altKey && event.shiftKey && event.code === "KeyC") {
|
|
3741
|
+
event.preventDefault();
|
|
3742
|
+
setActive((value) => !value);
|
|
3743
|
+
} else if (event.key === "Escape") {
|
|
3744
|
+
if (draftRef.current !== null) setDraft(null);
|
|
3745
|
+
else if (groupRef.current.length > 0) setGroup([]);
|
|
3746
|
+
else setActive(false);
|
|
3747
|
+
}
|
|
3748
|
+
};
|
|
3749
|
+
window.addEventListener("keydown", onKey, true);
|
|
3750
|
+
return () => window.removeEventListener("keydown", onKey, true);
|
|
3751
|
+
}, []);
|
|
3752
|
+
useEffect3(() => paused ? pauseMotion(document) : void 0, [paused]);
|
|
3753
|
+
useEffect3(() => {
|
|
3754
|
+
if (notice === null) return void 0;
|
|
3755
|
+
const timer = window.setTimeout(() => setNotice(null), NOTICE_MS);
|
|
3756
|
+
return () => window.clearTimeout(timer);
|
|
3757
|
+
}, [notice]);
|
|
3758
|
+
const tracking = active || draft !== null || items.length > 0;
|
|
3759
|
+
useEffect3(() => {
|
|
3760
|
+
if (!tracking) return void 0;
|
|
3761
|
+
const bump = () => setFrame((frame) => frame + 1);
|
|
3762
|
+
window.addEventListener("scroll", bump, true);
|
|
3763
|
+
window.addEventListener("resize", bump);
|
|
3764
|
+
const timer = window.setInterval(bump, REFLOW_MS);
|
|
3765
|
+
return () => {
|
|
3766
|
+
window.removeEventListener("scroll", bump, true);
|
|
3767
|
+
window.removeEventListener("resize", bump);
|
|
3768
|
+
window.clearInterval(timer);
|
|
3769
|
+
};
|
|
3770
|
+
}, [tracking]);
|
|
3771
|
+
const saveDraft = async () => {
|
|
3772
|
+
if (draft === null || draft.comment.trim() === "") return;
|
|
3773
|
+
const { comment, editingId } = draft;
|
|
3774
|
+
setDraft(null);
|
|
3775
|
+
window.getSelection()?.removeAllRanges();
|
|
3776
|
+
if (editingId !== null) {
|
|
3777
|
+
setItems(
|
|
3778
|
+
(current) => current.map(
|
|
3779
|
+
(item) => item.annotation.id === editingId ? { ...item, annotation: { ...item.annotation, comment } } : item
|
|
3780
|
+
)
|
|
3781
|
+
);
|
|
3782
|
+
return;
|
|
3783
|
+
}
|
|
3784
|
+
const targets = await draft.captures;
|
|
3785
|
+
const annotation = {
|
|
3786
|
+
id: newId(),
|
|
3787
|
+
kind: draft.kind,
|
|
3788
|
+
comment,
|
|
3789
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3790
|
+
targets,
|
|
3791
|
+
...draft.selectedText === void 0 ? {} : { selectedText: draft.selectedText },
|
|
3792
|
+
...draft.area === void 0 ? {} : { area: draft.area },
|
|
3793
|
+
...draft.areaInContainer === void 0 ? {} : { areaInContainer: draft.areaInContainer },
|
|
3794
|
+
...draft.redacted ? {} : { redacted: false }
|
|
3795
|
+
};
|
|
3796
|
+
setItems((current) => [...current, { annotation, elements: draft.elements }]);
|
|
3797
|
+
setPanelOpen(true);
|
|
3798
|
+
};
|
|
3799
|
+
const editItem = (id) => {
|
|
3800
|
+
const item = items.find((candidate) => candidate.annotation.id === id);
|
|
3801
|
+
if (item === void 0) return;
|
|
3802
|
+
const { annotation } = item;
|
|
3803
|
+
const first = annotation.targets[0];
|
|
3804
|
+
const element = liveElement(item);
|
|
3805
|
+
const area = element === null ? null : liveArea(item, element);
|
|
3806
|
+
setDraft({
|
|
3807
|
+
kind: annotation.kind,
|
|
3808
|
+
...area === null ? {} : { area },
|
|
3809
|
+
elements: element === null ? [] : [element],
|
|
3810
|
+
label: first?.components[0]?.name ?? first?.element.tag ?? annotation.kind,
|
|
3811
|
+
...annotation.selectedText === void 0 ? {} : { selectedText: annotation.selectedText },
|
|
3812
|
+
captures: Promise.resolve(annotation.targets),
|
|
3813
|
+
comment: annotation.comment,
|
|
3814
|
+
redacted: annotation.redacted !== false,
|
|
3815
|
+
editingId: id
|
|
3816
|
+
});
|
|
3817
|
+
};
|
|
3818
|
+
const copyPrompt = async () => {
|
|
3819
|
+
const prompt = buildPrompt(
|
|
3820
|
+
items.map((item) => item.annotation),
|
|
3821
|
+
{ appName, appDir, includeData, now: /* @__PURE__ */ new Date() }
|
|
3822
|
+
);
|
|
3823
|
+
await writeClipboard(prompt);
|
|
3824
|
+
const count = items.length;
|
|
3825
|
+
setNotice({
|
|
3826
|
+
title: "Prompt copied \u2014 ready for your coding agent",
|
|
3827
|
+
detail: `Paste it into Claude Code, Codex or Cursor. It gives the file, line and component behind ${count === 1 ? "your comment" : `each of your ${count} comments`}.`
|
|
3828
|
+
});
|
|
3829
|
+
};
|
|
3830
|
+
const takeScreenshot = async () => {
|
|
3831
|
+
setDraft(null);
|
|
3832
|
+
setPanelOpen(false);
|
|
3833
|
+
setNotice(null);
|
|
3834
|
+
try {
|
|
3835
|
+
const image = await (props.captureScreen ?? captureTab)(async () => {
|
|
3836
|
+
setCapturing(true);
|
|
3837
|
+
await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
|
|
3838
|
+
await new Promise((resolve) => window.setTimeout(resolve, 300));
|
|
3839
|
+
});
|
|
3840
|
+
setShot({ image, fileName: shotFileName(appName, window.location.pathname, /* @__PURE__ */ new Date()) });
|
|
3841
|
+
} catch (error) {
|
|
3842
|
+
setNotice(
|
|
3843
|
+
error instanceof CaptureCancelled ? { title: "Screenshot cancelled", detail: 'Choose "This tab" and Allow when the browser asks.', tone: "error" } : { title: "Could not take the screenshot", detail: error instanceof Error ? error.message : String(error), tone: "error" }
|
|
3844
|
+
);
|
|
3845
|
+
} finally {
|
|
3846
|
+
setCapturing(false);
|
|
3847
|
+
}
|
|
3848
|
+
};
|
|
3849
|
+
const toggleComments = () => {
|
|
3850
|
+
setShowComments(!showComments);
|
|
3851
|
+
writeFlag(SHOW_COMMENTS_KEY, !showComments);
|
|
3852
|
+
};
|
|
3853
|
+
const entries = items.map((item, index) => {
|
|
3854
|
+
const { annotation } = item;
|
|
3855
|
+
const first = annotation.targets[0];
|
|
3856
|
+
const kind = KIND_LABEL[annotation.kind](annotation.targets.length);
|
|
3857
|
+
const component = first?.components[0]?.name;
|
|
3858
|
+
const what = kind || `${component ? `${component} \xB7 ` : ""}${first?.element.tag ?? ""}`;
|
|
3859
|
+
return {
|
|
3860
|
+
id: annotation.id,
|
|
3861
|
+
number: index + 1,
|
|
3862
|
+
comment: annotation.comment,
|
|
3863
|
+
where: `${first?.page.pathname ?? ""} \xB7 ${what}`,
|
|
3864
|
+
onThisPage: liveElement(item) !== null
|
|
3865
|
+
};
|
|
3866
|
+
});
|
|
3867
|
+
const hideHint = (hidden) => {
|
|
3868
|
+
setHintHidden(hidden);
|
|
3869
|
+
writeFlag(HINT_HIDDEN_KEY, hidden);
|
|
3870
|
+
};
|
|
3871
|
+
const draftElement = draft?.elements[0];
|
|
3872
|
+
const draftBox = draftElement?.isConnected ? boxOf(draftElement) : null;
|
|
3873
|
+
const onScreen = items.flatMap((item, index) => {
|
|
3874
|
+
const element = liveElement(item);
|
|
3875
|
+
if (element === null) return [];
|
|
3876
|
+
const area = liveArea(item, element);
|
|
3877
|
+
return [
|
|
3878
|
+
area === null ? { number: index + 1, comment: item.annotation.comment, box: boxOf(element) } : { number: index + 1, comment: item.annotation.comment, box: areaBox(area), area: true }
|
|
3879
|
+
];
|
|
3880
|
+
});
|
|
3881
|
+
const callouts = showComments || capturing ? layoutCallouts(onScreen, { width: window.innerWidth, height: window.innerHeight }) : null;
|
|
3882
|
+
const editNumber = (number) => {
|
|
3883
|
+
const item = items[number - 1];
|
|
3884
|
+
if (item !== void 0) editItem(item.annotation.id);
|
|
3885
|
+
};
|
|
3886
|
+
const overlay = capturing ? /* @__PURE__ */ jsx7("div", { "data-dev-annotator": "", children: /* @__PURE__ */ jsx7(Callouts, { callouts: callouts ?? [], onEdit: null }) }) : /* @__PURE__ */ jsxs6("div", { "data-dev-annotator": "", children: [
|
|
3887
|
+
active && !hintHidden ? /* @__PURE__ */ jsx7(Hint, { onDismiss: () => hideHint(true) }) : null,
|
|
3888
|
+
active && hover !== null && hover.element !== draftElement && dragBox === null ? /* @__PURE__ */ jsx7(Highlight, { box: boxOf(hover.element), label: hover.label, strong: false }) : null,
|
|
3889
|
+
group.map((element, index) => /* @__PURE__ */ jsx7(Highlight, { box: boxOf(element), label: `#${index + 1}`, strong: true }, index)),
|
|
3890
|
+
dragBox !== null ? /* @__PURE__ */ jsx7(AreaBox, { box: { top: dragBox.y, left: dragBox.x, width: dragBox.width, height: dragBox.height } }) : null,
|
|
3891
|
+
draft?.area !== void 0 ? /* @__PURE__ */ jsx7(AreaBox, { box: { top: draft.area.y, left: draft.area.x, width: draft.area.width, height: draft.area.height } }) : null,
|
|
3892
|
+
draft !== null && draft.kind !== "area" ? draft.elements.filter((element) => element.isConnected).map((element, index) => /* @__PURE__ */ jsx7(Highlight, { box: boxOf(element), label: index === 0 ? draft.label : `#${index + 1}`, strong: true }, index)) : null,
|
|
3893
|
+
callouts !== null ? /* @__PURE__ */ jsx7(Callouts, { callouts, onEdit: editNumber }) : onScreen.map((target) => /* @__PURE__ */ jsx7(Pin, { box: target.box, number: target.number, onClick: () => editNumber(target.number) }, target.number)),
|
|
3894
|
+
draft !== null ? /* @__PURE__ */ jsx7(
|
|
3895
|
+
Editor,
|
|
3896
|
+
{
|
|
3897
|
+
anchor: draft.area === void 0 ? draftBox : areaBox(draft.area),
|
|
3898
|
+
title: draft.editingId === null ? draft.label : `Edit comment \xB7 ${draft.label}`,
|
|
3899
|
+
comment: draft.comment,
|
|
3900
|
+
editing: draft.editingId !== null,
|
|
3901
|
+
onChange: (comment) => setDraft((current) => current === null ? null : { ...current, comment }),
|
|
3902
|
+
onSave: () => void saveDraft(),
|
|
3903
|
+
onCancel: () => setDraft(null),
|
|
3904
|
+
onDelete: () => {
|
|
3905
|
+
const id = draft.editingId;
|
|
3906
|
+
setDraft(null);
|
|
3907
|
+
setItems((current) => current.filter((item) => item.annotation.id !== id));
|
|
3908
|
+
}
|
|
3909
|
+
}
|
|
3910
|
+
) : null,
|
|
3911
|
+
settingsOpen && !collapsed ? /* @__PURE__ */ jsx7(
|
|
3912
|
+
RedactionPanel,
|
|
3913
|
+
{
|
|
3914
|
+
settings: redaction,
|
|
3915
|
+
customised: savedRedaction !== null,
|
|
3916
|
+
onChange: (next) => {
|
|
3917
|
+
setSavedRedaction(next);
|
|
3918
|
+
writeRedaction(redactionKey, next);
|
|
3919
|
+
},
|
|
3920
|
+
onReset: () => {
|
|
3921
|
+
setSavedRedaction(null);
|
|
3922
|
+
writeRedaction(redactionKey, null);
|
|
3923
|
+
},
|
|
3924
|
+
onClose: () => setSettingsOpen(false)
|
|
3925
|
+
}
|
|
3926
|
+
) : null,
|
|
3927
|
+
panelOpen && !settingsOpen && !collapsed && items.length > 0 ? /* @__PURE__ */ jsx7(
|
|
3928
|
+
Panel,
|
|
3929
|
+
{
|
|
3930
|
+
entries,
|
|
3931
|
+
includeData,
|
|
3932
|
+
redactionOn: redaction.enabled,
|
|
3933
|
+
onIncludeData: setIncludeData,
|
|
3934
|
+
onEdit: editItem,
|
|
3935
|
+
onClear: () => {
|
|
3936
|
+
setDraft(null);
|
|
3937
|
+
setItems([]);
|
|
3938
|
+
},
|
|
3939
|
+
onClose: () => setPanelOpen(false)
|
|
3940
|
+
}
|
|
3941
|
+
) : null,
|
|
3942
|
+
/* @__PURE__ */ jsx7(
|
|
3943
|
+
Toolbar,
|
|
3944
|
+
{
|
|
3945
|
+
active,
|
|
3946
|
+
paused,
|
|
3947
|
+
count: items.length,
|
|
3948
|
+
panelOpen,
|
|
3949
|
+
showComments,
|
|
3950
|
+
capturing,
|
|
3951
|
+
collapsed,
|
|
3952
|
+
redactionOn: redaction.enabled,
|
|
3953
|
+
settingsOpen,
|
|
3954
|
+
onToggleSettings: () => setSettingsOpen(!settingsOpen),
|
|
3955
|
+
onToggleCollapsed: () => {
|
|
3956
|
+
setCollapsed(!collapsed);
|
|
3957
|
+
writeFlag(COLLAPSED_KEY, !collapsed);
|
|
3958
|
+
},
|
|
3959
|
+
onShowHint: active && hintHidden ? () => hideHint(false) : null,
|
|
3960
|
+
onToggleActive: () => setActive((value) => !value),
|
|
3961
|
+
onTogglePaused: () => setPaused((value) => !value),
|
|
3962
|
+
onToggleComments: toggleComments,
|
|
3963
|
+
onScreenshot: () => void takeScreenshot(),
|
|
3964
|
+
onTogglePanel: () => setPanelOpen((value) => !value),
|
|
3965
|
+
onCopy: () => void copyPrompt()
|
|
3966
|
+
}
|
|
3967
|
+
),
|
|
3968
|
+
notice !== null ? /* @__PURE__ */ jsx7(Toast, { notice, onDismiss: () => setNotice(null) }) : null,
|
|
3969
|
+
shot !== null ? /* @__PURE__ */ jsx7(ScreenshotEditor, { image: shot.image, fileName: shot.fileName, onClose: () => setShot(null), onNotice: setNotice }) : null
|
|
3970
|
+
] });
|
|
3971
|
+
return createPortal(overlay, document.body);
|
|
3972
|
+
}
|
|
3973
|
+
function pickTarget(target) {
|
|
3974
|
+
if (target instanceof SVGElement && !(target instanceof SVGSVGElement)) return target.closest("svg") ?? target;
|
|
3975
|
+
return target;
|
|
3976
|
+
}
|
|
3977
|
+
function rectBetween(a, b) {
|
|
3978
|
+
return { x: Math.min(a.x, b.x), y: Math.min(a.y, b.y), width: Math.abs(a.x - b.x), height: Math.abs(a.y - b.y) };
|
|
3979
|
+
}
|
|
3980
|
+
function areaBox(area) {
|
|
3981
|
+
return { top: area.y, left: area.x, width: area.width, height: area.height };
|
|
3982
|
+
}
|
|
3983
|
+
function selectedText() {
|
|
3984
|
+
const selection = window.getSelection();
|
|
3985
|
+
if (selection === null || selection.isCollapsed || selection.rangeCount === 0) return null;
|
|
3986
|
+
const text = selection.toString().replace(/\s+/g, " ").trim();
|
|
3987
|
+
if (text === "") return null;
|
|
3988
|
+
const node = selection.getRangeAt(0).commonAncestorContainer;
|
|
3989
|
+
const element = node instanceof Element ? node : node.parentElement;
|
|
3990
|
+
if (element === null || element.closest(OWN_SELECTOR) !== null) return null;
|
|
3991
|
+
return { element, text };
|
|
3992
|
+
}
|
|
3993
|
+
function liveArea(item, container) {
|
|
3994
|
+
const offset = item.annotation.areaInContainer;
|
|
3995
|
+
if (item.annotation.kind !== "area" || offset === void 0) return null;
|
|
3996
|
+
const origin = container.getBoundingClientRect();
|
|
3997
|
+
return { x: origin.left + offset.x, y: origin.top + offset.y, width: offset.width, height: offset.height };
|
|
3998
|
+
}
|
|
3999
|
+
function liveElement(item) {
|
|
4000
|
+
const first = item.annotation.targets[0];
|
|
4001
|
+
if (first === void 0 || window.location.pathname !== first.page.pathname) return null;
|
|
4002
|
+
const [element] = item.elements;
|
|
4003
|
+
if (element?.isConnected) return element;
|
|
4004
|
+
try {
|
|
4005
|
+
return document.querySelector(first.element.selector);
|
|
4006
|
+
} catch {
|
|
4007
|
+
return null;
|
|
4008
|
+
}
|
|
4009
|
+
}
|
|
4010
|
+
function newId() {
|
|
4011
|
+
return typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
4012
|
+
}
|
|
4013
|
+
function restore(key) {
|
|
4014
|
+
try {
|
|
4015
|
+
const raw = window.sessionStorage.getItem(key);
|
|
4016
|
+
const parsed = raw === null ? [] : JSON.parse(raw);
|
|
4017
|
+
if (!Array.isArray(parsed)) return [];
|
|
4018
|
+
return parsed.filter((annotation) => Array.isArray(annotation?.targets) && annotation.targets.length > 0).map((annotation) => ({ annotation, elements: [] }));
|
|
4019
|
+
} catch {
|
|
4020
|
+
return [];
|
|
4021
|
+
}
|
|
4022
|
+
}
|
|
4023
|
+
function persist(key, annotations) {
|
|
4024
|
+
try {
|
|
4025
|
+
if (annotations.length === 0) window.sessionStorage.removeItem(key);
|
|
4026
|
+
else window.sessionStorage.setItem(key, JSON.stringify(annotations));
|
|
4027
|
+
} catch {
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
async function writeClipboard(text) {
|
|
4031
|
+
try {
|
|
4032
|
+
await navigator.clipboard.writeText(text);
|
|
4033
|
+
return;
|
|
4034
|
+
} catch {
|
|
4035
|
+
}
|
|
4036
|
+
const area = document.createElement("textarea");
|
|
4037
|
+
area.value = text;
|
|
4038
|
+
area.setAttribute("data-dev-annotator", "");
|
|
4039
|
+
area.style.position = "fixed";
|
|
4040
|
+
area.style.opacity = "0";
|
|
4041
|
+
document.body.appendChild(area);
|
|
4042
|
+
area.select();
|
|
4043
|
+
document.execCommand("copy");
|
|
4044
|
+
area.remove();
|
|
4045
|
+
}
|
|
4046
|
+
export {
|
|
4047
|
+
COUNTRIES,
|
|
4048
|
+
DEFAULT_REDACTION,
|
|
4049
|
+
DevAnnotator,
|
|
4050
|
+
REDACTED,
|
|
4051
|
+
buildPrompt,
|
|
4052
|
+
createNextResolver
|
|
4053
|
+
};
|
|
4054
|
+
//# sourceMappingURL=index.js.map
|