@matija2209/payload-plugin-admin-feedback 1.0.0 → 1.0.4

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.
@@ -0,0 +1,1638 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ var React = require('react');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var navigation = require('next/navigation');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var React__default = /*#__PURE__*/_interopDefault(React);
11
+
12
+ var DEFAULT_COLORS = ["#ef4444", "#f97316", "#eab308", "#22c55e", "#06b6d4", "#3b82f6", "#a855f7"];
13
+ var DEFAULT_HISTORY = {
14
+ operations: [],
15
+ redoStack: [],
16
+ undoStack: []
17
+ };
18
+ var createOperationId = () => `annotation-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
19
+ var getCssSelector = (element) => {
20
+ if (element.id) {
21
+ return `#${element.id}`;
22
+ }
23
+ const parts = [];
24
+ let current = element;
25
+ while (current && current.nodeType === Node.ELEMENT_NODE && current !== document.body) {
26
+ let part = current.tagName.toLowerCase();
27
+ const className = current.className;
28
+ if (typeof className === "string") {
29
+ const firstClass = className.split(" ").map((value) => value.trim()).filter(Boolean)[0];
30
+ if (firstClass) {
31
+ part += `.${firstClass}`;
32
+ }
33
+ }
34
+ const parent = current.parentElement;
35
+ if (parent) {
36
+ const siblings = Array.from(parent.children).filter(
37
+ (candidate) => candidate.tagName === current?.tagName
38
+ );
39
+ if (siblings.length > 1) {
40
+ const index = siblings.indexOf(current);
41
+ part += `:nth-of-type(${index + 1})`;
42
+ }
43
+ }
44
+ parts.unshift(part);
45
+ current = current.parentElement;
46
+ }
47
+ return parts.join(" > ");
48
+ };
49
+ var fileToDataUrl = async (file) => new Promise((resolve, reject) => {
50
+ const reader = new FileReader();
51
+ reader.onload = () => {
52
+ if (typeof reader.result === "string") {
53
+ resolve(reader.result);
54
+ return;
55
+ }
56
+ reject(new Error("Unsupported image format."));
57
+ };
58
+ reader.onerror = () => reject(new Error("Could not read image."));
59
+ reader.readAsDataURL(file);
60
+ });
61
+ var loadImage = async (src) => new Promise((resolve, reject) => {
62
+ const image = new Image();
63
+ image.onload = () => resolve(image);
64
+ image.onerror = () => reject(new Error("Could not load image."));
65
+ image.src = src;
66
+ });
67
+ var createEditorImage = async (file) => {
68
+ const src = await fileToDataUrl(file);
69
+ const element = await loadImage(src);
70
+ return {
71
+ element,
72
+ fileName: file.name,
73
+ height: element.naturalHeight || element.height,
74
+ src,
75
+ width: element.naturalWidth || element.width
76
+ };
77
+ };
78
+ var canvasToFile = async (canvas, fileName = `feedback-${Date.now()}.png`) => {
79
+ const blob = await new Promise((resolve) => {
80
+ canvas.toBlob((nextBlob) => resolve(nextBlob), "image/png");
81
+ });
82
+ if (!blob) {
83
+ throw new Error("Failed to prepare annotated screenshot.");
84
+ }
85
+ return new File([blob], fileName.replace(/\.[a-z0-9]+$/i, "") + ".png", { type: "image/png" });
86
+ };
87
+ var waitForRenderedVideoFrame = async (video) => {
88
+ if ("requestVideoFrameCallback" in video) {
89
+ await new Promise((resolve) => {
90
+ video.requestVideoFrameCallback(() => resolve());
91
+ });
92
+ return;
93
+ }
94
+ await new Promise((resolve) => {
95
+ window.requestAnimationFrame(() => resolve());
96
+ });
97
+ };
98
+ var captureScreenshotFile = async (capturePolicy) => {
99
+ if (!navigator.mediaDevices?.getDisplayMedia) {
100
+ throw new Error("Browser does not support screen capture.");
101
+ }
102
+ const options = capturePolicy === "any-surface" ? {
103
+ video: true,
104
+ audio: false
105
+ } : {
106
+ video: {
107
+ displaySurface: "browser"
108
+ },
109
+ audio: false,
110
+ preferCurrentTab: true,
111
+ selfBrowserSurface: "include",
112
+ surfaceSwitching: "exclude"
113
+ };
114
+ const stream = await navigator.mediaDevices.getDisplayMedia(options);
115
+ const track = stream.getVideoTracks()[0];
116
+ if (!track) {
117
+ stream.getTracks().forEach((item) => item.stop());
118
+ throw new Error("Screen capture failed.");
119
+ }
120
+ const settings = track.getSettings();
121
+ const surface = typeof settings.displaySurface === "string" ? settings.displaySurface : null;
122
+ if (capturePolicy === "strict-current-tab" && surface !== "browser") {
123
+ stream.getTracks().forEach((item) => item.stop());
124
+ throw new Error("Please share the current browser tab to capture a screenshot.");
125
+ }
126
+ const video = document.createElement("video");
127
+ try {
128
+ video.srcObject = stream;
129
+ video.muted = true;
130
+ video.playsInline = true;
131
+ await video.play();
132
+ await waitForRenderedVideoFrame(video);
133
+ const width = video.videoWidth || window.innerWidth;
134
+ const height = video.videoHeight || window.innerHeight;
135
+ if (!width || !height) {
136
+ throw new Error("Screen capture failed.");
137
+ }
138
+ const canvas = document.createElement("canvas");
139
+ canvas.width = width;
140
+ canvas.height = height;
141
+ const context = canvas.getContext("2d");
142
+ if (!context) {
143
+ throw new Error("Browser does not support canvas context.");
144
+ }
145
+ context.drawImage(video, 0, 0, width, height);
146
+ return {
147
+ file: await canvasToFile(canvas),
148
+ surface
149
+ };
150
+ } finally {
151
+ video.pause();
152
+ video.srcObject = null;
153
+ stream.getTracks().forEach((item) => item.stop());
154
+ }
155
+ };
156
+ var getCanvasPoint = (event, canvas) => {
157
+ const bounds = canvas.getBoundingClientRect();
158
+ const scaleX = bounds.width === 0 ? 1 : canvas.width / bounds.width;
159
+ const scaleY = bounds.height === 0 ? 1 : canvas.height / bounds.height;
160
+ return {
161
+ x: (event.clientX - bounds.left) * scaleX,
162
+ y: (event.clientY - bounds.top) * scaleY
163
+ };
164
+ };
165
+ var drawPenOperation = (context, operation) => {
166
+ if (operation.points.length === 0) {
167
+ return;
168
+ }
169
+ context.save();
170
+ context.strokeStyle = operation.style.color;
171
+ context.lineWidth = operation.style.size;
172
+ context.lineCap = "round";
173
+ context.lineJoin = "round";
174
+ context.beginPath();
175
+ context.moveTo(operation.points[0].x, operation.points[0].y);
176
+ for (const point of operation.points.slice(1)) {
177
+ context.lineTo(point.x, point.y);
178
+ }
179
+ if (operation.points.length === 1) {
180
+ const point = operation.points[0];
181
+ context.lineTo(point.x + 0.01, point.y + 0.01);
182
+ }
183
+ context.stroke();
184
+ context.restore();
185
+ };
186
+ var drawRectangleOperation = (context, operation) => {
187
+ const left = Math.min(operation.start.x, operation.end.x);
188
+ const top = Math.min(operation.start.y, operation.end.y);
189
+ const width = Math.abs(operation.end.x - operation.start.x);
190
+ const height = Math.abs(operation.end.y - operation.start.y);
191
+ context.save();
192
+ context.strokeStyle = operation.style.color;
193
+ context.lineWidth = operation.style.size;
194
+ context.strokeRect(left, top, width, height);
195
+ context.restore();
196
+ };
197
+ var drawArrowOperation = (context, operation) => {
198
+ const angle = Math.atan2(operation.end.y - operation.start.y, operation.end.x - operation.start.x);
199
+ const headLength = Math.max(14, operation.style.size * 4);
200
+ context.save();
201
+ context.strokeStyle = operation.style.color;
202
+ context.fillStyle = operation.style.color;
203
+ context.lineWidth = operation.style.size;
204
+ context.lineCap = "round";
205
+ context.lineJoin = "round";
206
+ context.beginPath();
207
+ context.moveTo(operation.start.x, operation.start.y);
208
+ context.lineTo(operation.end.x, operation.end.y);
209
+ context.stroke();
210
+ context.beginPath();
211
+ context.moveTo(operation.end.x, operation.end.y);
212
+ context.lineTo(
213
+ operation.end.x - headLength * Math.cos(angle - Math.PI / 6),
214
+ operation.end.y - headLength * Math.sin(angle - Math.PI / 6)
215
+ );
216
+ context.lineTo(
217
+ operation.end.x - headLength * Math.cos(angle + Math.PI / 6),
218
+ operation.end.y - headLength * Math.sin(angle + Math.PI / 6)
219
+ );
220
+ context.closePath();
221
+ context.fill();
222
+ context.restore();
223
+ };
224
+ var drawTextOperation = (context, operation) => {
225
+ const fontSize = Math.max(16, operation.style.size * 6);
226
+ context.save();
227
+ context.fillStyle = operation.style.color;
228
+ context.font = `600 ${fontSize}px ui-sans-serif, system-ui, sans-serif`;
229
+ context.textBaseline = "top";
230
+ context.fillText(operation.text, operation.point.x, operation.point.y);
231
+ context.restore();
232
+ };
233
+ var drawOperation = (context, operation) => {
234
+ switch (operation.type) {
235
+ case "pen":
236
+ drawPenOperation(context, operation);
237
+ return;
238
+ case "rectangle":
239
+ drawRectangleOperation(context, operation);
240
+ return;
241
+ case "arrow":
242
+ drawArrowOperation(context, operation);
243
+ return;
244
+ case "text":
245
+ drawTextOperation(context, operation);
246
+ return;
247
+ }
248
+ };
249
+ var isShapeMeaningful = (start, end) => Math.abs(end.x - start.x) > 3 || Math.abs(end.y - start.y) > 3;
250
+ function ChatIcon() {
251
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) });
252
+ }
253
+ function XIcon({ size = 18 }) {
254
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
255
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
256
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
257
+ ] });
258
+ }
259
+ function CameraIcon() {
260
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
261
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z" }),
262
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "13", r: "4" })
263
+ ] });
264
+ }
265
+ function CursorIcon() {
266
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 4l7.07 17 2.51-7.39L21 11.07z" }) });
267
+ }
268
+ function UploadIcon() {
269
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
270
+ /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "16 16 12 12 8 16" }),
271
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "12", x2: "12", y2: "21" }),
272
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20.39 18.39A5 5 0 0 0 18 9h-1.26A8 8 0 1 0 3 16.3" })
273
+ ] });
274
+ }
275
+ function SendIcon() {
276
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
277
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "22", y1: "2", x2: "11", y2: "13" }),
278
+ /* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "22 2 15 22 11 13 2 9 22 2" })
279
+ ] });
280
+ }
281
+ function CheckCircleIcon() {
282
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "48", height: "48", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
283
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M22 11.08V12a10 10 0 1 1-5.93-9.14" }),
284
+ /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "22 4 12 14.01 9 11.01" })
285
+ ] });
286
+ }
287
+ function PenIcon() {
288
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
289
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 19l7-7 3 3-7 7-3-3z" }),
290
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 13l-1.5-7.5L2 2l3.5 14.5L13 18l5-5z" }),
291
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M2 2l7.586 7.586" }),
292
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "11", cy: "11", r: "2" })
293
+ ] });
294
+ }
295
+ function RectIcon() {
296
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2", ry: "2" }) });
297
+ }
298
+ function ArrowIcon() {
299
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
300
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "5", y1: "19", x2: "19", y2: "5" }),
301
+ /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "13 5 19 5 19 11" })
302
+ ] });
303
+ }
304
+ function TextIcon() {
305
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
306
+ /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "4 7 4 4 20 4 20 7" }),
307
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "9", y1: "20", x2: "15", y2: "20" }),
308
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "4", x2: "12", y2: "20" })
309
+ ] });
310
+ }
311
+ function UndoIcon() {
312
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
313
+ /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "9 14 4 9 9 4" }),
314
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 20v-7a4 4 0 0 0-4-4H4" })
315
+ ] });
316
+ }
317
+ function RedoIcon() {
318
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
319
+ /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "15 14 20 9 15 4" }),
320
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 20v-7a4 4 0 0 1 4-4h12" })
321
+ ] });
322
+ }
323
+ function TrashIcon() {
324
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
325
+ /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "3 6 5 6 21 6" }),
326
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M19 6l-1 14H6L5 6" }),
327
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M10 11v6M14 11v6" }),
328
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M9 6V4h6v2" })
329
+ ] });
330
+ }
331
+ function FeedbackWidget({
332
+ title = "Admin feedback",
333
+ submitLabel = "Send",
334
+ uploadLabel = "Upload image",
335
+ allowScreenshotUpload = true,
336
+ screenshotMaxFileSizeBytes = 5 * 1024 * 1024,
337
+ screenshotAllowedMimeTypes = ["image/png", "image/jpeg", "image/webp"],
338
+ capturePolicy = "current-tab-first",
339
+ onSubmit,
340
+ onUpload,
341
+ onDeleteScreenshot
342
+ }) {
343
+ const [open, setOpen] = React__default.default.useState(false);
344
+ const [message, setMessage] = React__default.default.useState("");
345
+ const [captureMode, setCaptureMode] = React__default.default.useState(false);
346
+ const [captureData, setCaptureData] = React__default.default.useState(null);
347
+ const [screenshotId, setScreenshotId] = React__default.default.useState(null);
348
+ const [screenshotPreviewUrl, setScreenshotPreviewUrl] = React__default.default.useState(null);
349
+ const [uploading, setUploading] = React__default.default.useState(false);
350
+ const [deletingScreenshot, setDeletingScreenshot] = React__default.default.useState(false);
351
+ const [submitting, setSubmitting] = React__default.default.useState(false);
352
+ const [submitted, setSubmitted] = React__default.default.useState(false);
353
+ const [currentPath, setCurrentPath] = React__default.default.useState("");
354
+ const [capturingScreen, setCapturingScreen] = React__default.default.useState(false);
355
+ const [error, setError] = React__default.default.useState(null);
356
+ const [notice, setNotice] = React__default.default.useState(null);
357
+ const [annotating, setAnnotating] = React__default.default.useState(false);
358
+ const [editorImage, setEditorImage] = React__default.default.useState(null);
359
+ const [editorHistory, setEditorHistory] = React__default.default.useState(DEFAULT_HISTORY);
360
+ const [draftOperation, setDraftOperation] = React__default.default.useState(null);
361
+ const [annotationTool, setAnnotationTool] = React__default.default.useState("pen");
362
+ const [annotationColor, setAnnotationColor] = React__default.default.useState(DEFAULT_COLORS[0]);
363
+ const [annotationSize, setAnnotationSize] = React__default.default.useState(4);
364
+ const [textCursor, setTextCursor] = React__default.default.useState(null);
365
+ const [inlineText, setInlineText] = React__default.default.useState("");
366
+ const hoverTargetRef = React__default.default.useRef(null);
367
+ const annotationCanvasRef = React__default.default.useRef(null);
368
+ const annotationScrollRef = React__default.default.useRef(null);
369
+ const textInputRef = React__default.default.useRef(null);
370
+ const pointerIdRef = React__default.default.useRef(null);
371
+ const draftOperationRef = React__default.default.useRef(null);
372
+ const inlineTextRef = React__default.default.useRef("");
373
+ const textCursorRef = React__default.default.useRef(null);
374
+ const annotationColorRef = React__default.default.useRef(DEFAULT_COLORS[0]);
375
+ const annotationSizeRef = React__default.default.useRef(4);
376
+ React__default.default.useEffect(() => {
377
+ draftOperationRef.current = draftOperation;
378
+ }, [draftOperation]);
379
+ React__default.default.useEffect(() => {
380
+ inlineTextRef.current = inlineText;
381
+ }, [inlineText]);
382
+ React__default.default.useEffect(() => {
383
+ textCursorRef.current = textCursor;
384
+ }, [textCursor]);
385
+ React__default.default.useEffect(() => {
386
+ annotationColorRef.current = annotationColor;
387
+ }, [annotationColor]);
388
+ React__default.default.useEffect(() => {
389
+ annotationSizeRef.current = annotationSize;
390
+ }, [annotationSize]);
391
+ React__default.default.useEffect(() => {
392
+ if (!captureMode) {
393
+ return;
394
+ }
395
+ const clearOutline = () => {
396
+ if (hoverTargetRef.current instanceof HTMLElement) {
397
+ hoverTargetRef.current.style.outline = "";
398
+ }
399
+ hoverTargetRef.current = null;
400
+ };
401
+ const onMouseMove = (event) => {
402
+ const target = event.target;
403
+ if (!(target instanceof HTMLElement)) {
404
+ return;
405
+ }
406
+ if (hoverTargetRef.current !== target) {
407
+ clearOutline();
408
+ target.style.outline = "2px dashed #22c55e";
409
+ hoverTargetRef.current = target;
410
+ }
411
+ };
412
+ const onClick = (event) => {
413
+ event.preventDefault();
414
+ event.stopPropagation();
415
+ const target = event.target;
416
+ if (!(target instanceof HTMLElement)) {
417
+ return;
418
+ }
419
+ setCaptureData({
420
+ selector: getCssSelector(target),
421
+ selectedText: target.textContent?.trim().slice(0, 200) || ""
422
+ });
423
+ clearOutline();
424
+ setCaptureMode(false);
425
+ };
426
+ document.addEventListener("mousemove", onMouseMove, true);
427
+ document.addEventListener("click", onClick, true);
428
+ return () => {
429
+ clearOutline();
430
+ document.removeEventListener("mousemove", onMouseMove, true);
431
+ document.removeEventListener("click", onClick, true);
432
+ };
433
+ }, [captureMode]);
434
+ React__default.default.useEffect(() => {
435
+ if (!annotating) {
436
+ return;
437
+ }
438
+ const previousOverflow = document.body.style.overflow;
439
+ document.body.style.overflow = "hidden";
440
+ return () => {
441
+ document.body.style.overflow = previousOverflow;
442
+ };
443
+ }, [annotating]);
444
+ React__default.default.useEffect(() => {
445
+ if (!annotating || !editorImage || !annotationCanvasRef.current) {
446
+ return;
447
+ }
448
+ const canvas = annotationCanvasRef.current;
449
+ canvas.width = editorImage.width;
450
+ canvas.height = editorImage.height;
451
+ const context = canvas.getContext("2d");
452
+ if (!context) {
453
+ setError("Browser does not support canvas context.");
454
+ return;
455
+ }
456
+ context.clearRect(0, 0, canvas.width, canvas.height);
457
+ context.drawImage(editorImage.element, 0, 0, canvas.width, canvas.height);
458
+ for (const operation of editorHistory.operations) {
459
+ drawOperation(context, operation);
460
+ }
461
+ if (draftOperation) {
462
+ drawOperation(context, draftOperation);
463
+ }
464
+ }, [annotating, draftOperation, editorHistory.operations, editorImage]);
465
+ React__default.default.useEffect(() => {
466
+ setCurrentPath(window.location.pathname);
467
+ }, []);
468
+ React__default.default.useEffect(() => {
469
+ if (!submitted) return;
470
+ const timer = setTimeout(() => {
471
+ setOpen(false);
472
+ setSubmitted(false);
473
+ }, 2500);
474
+ return () => clearTimeout(timer);
475
+ }, [submitted]);
476
+ const validateImageFile = React__default.default.useCallback(
477
+ (file) => {
478
+ if (!screenshotAllowedMimeTypes.includes(file.type)) {
479
+ return `Supported image types: ${screenshotAllowedMimeTypes.join(", ")}`;
480
+ }
481
+ if (file.size > screenshotMaxFileSizeBytes) {
482
+ return `Image is too large. Maximum size: ${Math.round(screenshotMaxFileSizeBytes / 1024 / 1024)}MB.`;
483
+ }
484
+ return null;
485
+ },
486
+ [screenshotAllowedMimeTypes, screenshotMaxFileSizeBytes]
487
+ );
488
+ const uploadImageFile = React__default.default.useCallback(
489
+ async (file) => {
490
+ if (!onUpload) {
491
+ return false;
492
+ }
493
+ setError(null);
494
+ setUploading(true);
495
+ try {
496
+ const formData = new FormData();
497
+ formData.append("file", file);
498
+ formData.append("alt", file.name);
499
+ const result = await onUpload(formData);
500
+ if (result.success) {
501
+ setScreenshotId(result.mediaId);
502
+ setNotice("Annotated screenshot uploaded.");
503
+ return true;
504
+ }
505
+ setError(result.error);
506
+ return false;
507
+ } finally {
508
+ setUploading(false);
509
+ }
510
+ },
511
+ [onUpload]
512
+ );
513
+ const closeAnnotationEditor = React__default.default.useCallback(() => {
514
+ setAnnotating(false);
515
+ setEditorImage(null);
516
+ setEditorHistory(DEFAULT_HISTORY);
517
+ setDraftOperation(null);
518
+ setTextCursor(null);
519
+ setInlineText("");
520
+ draftOperationRef.current = null;
521
+ }, []);
522
+ const handleStartAnnotation = React__default.default.useCallback(
523
+ async (file) => {
524
+ const validationError = validateImageFile(file);
525
+ if (validationError) {
526
+ setError(validationError);
527
+ return;
528
+ }
529
+ try {
530
+ const nextImage = await createEditorImage(file);
531
+ setEditorImage(nextImage);
532
+ setEditorHistory(DEFAULT_HISTORY);
533
+ setDraftOperation(null);
534
+ setTextCursor(null);
535
+ setInlineText("");
536
+ draftOperationRef.current = null;
537
+ setAnnotating(true);
538
+ setError(null);
539
+ } catch (nextError) {
540
+ setError(nextError instanceof Error ? nextError.message : "Failed to process image.");
541
+ }
542
+ },
543
+ [validateImageFile]
544
+ );
545
+ React__default.default.useEffect(() => {
546
+ if (!open || !allowScreenshotUpload) {
547
+ return;
548
+ }
549
+ const onPaste = async (event) => {
550
+ const file = Array.from(event.clipboardData?.items || []).find((item) => item.type.startsWith("image/"))?.getAsFile();
551
+ if (!file) {
552
+ return;
553
+ }
554
+ event.preventDefault();
555
+ await handleStartAnnotation(file);
556
+ };
557
+ window.addEventListener("paste", onPaste);
558
+ return () => window.removeEventListener("paste", onPaste);
559
+ }, [allowScreenshotUpload, handleStartAnnotation, open]);
560
+ const commitOperations = React__default.default.useCallback((nextOperations) => {
561
+ setEditorHistory((current) => ({
562
+ operations: nextOperations,
563
+ redoStack: [],
564
+ undoStack: [...current.undoStack, current.operations]
565
+ }));
566
+ }, []);
567
+ const appendOperation = React__default.default.useCallback((operation) => {
568
+ setEditorHistory((current) => ({
569
+ operations: [...current.operations, operation],
570
+ redoStack: [],
571
+ undoStack: [...current.undoStack, current.operations]
572
+ }));
573
+ }, []);
574
+ const commitTextInput = React__default.default.useCallback(() => {
575
+ const text = inlineTextRef.current.trim();
576
+ const cursor = textCursorRef.current;
577
+ if (text && cursor) {
578
+ const operation = {
579
+ id: createOperationId(),
580
+ type: "text",
581
+ style: { color: annotationColorRef.current, size: annotationSizeRef.current },
582
+ point: cursor.canvasPoint,
583
+ text
584
+ };
585
+ appendOperation(operation);
586
+ }
587
+ textCursorRef.current = null;
588
+ setTextCursor(null);
589
+ setInlineText("");
590
+ }, [appendOperation]);
591
+ const handleUpload = async (event) => {
592
+ const file = event.target.files?.[0];
593
+ if (file) {
594
+ await handleStartAnnotation(file);
595
+ }
596
+ event.target.value = "";
597
+ };
598
+ const handleCaptureScreenshot = async () => {
599
+ try {
600
+ setError(null);
601
+ setCapturingScreen(true);
602
+ await new Promise((resolve) => setTimeout(resolve, 120));
603
+ const { file, surface } = await captureScreenshotFile(capturePolicy);
604
+ if (capturePolicy === "current-tab-first") {
605
+ if (surface === "browser") {
606
+ setNotice("Captured the current tab.");
607
+ } else if (surface) {
608
+ setNotice(`Captured a ${surface} surface because the browser allowed a broader selection.`);
609
+ } else {
610
+ setNotice("Captured a screenshot.");
611
+ }
612
+ } else if (capturePolicy === "strict-current-tab") {
613
+ setNotice("Captured the current tab.");
614
+ } else {
615
+ setNotice("Captured a screenshot.");
616
+ }
617
+ await handleStartAnnotation(file);
618
+ } catch (nextError) {
619
+ setError(nextError instanceof Error ? nextError.message : "Screen capture failed.");
620
+ } finally {
621
+ setCapturingScreen(false);
622
+ }
623
+ };
624
+ const handleUndo = () => {
625
+ setEditorHistory((current) => {
626
+ if (current.undoStack.length === 0) {
627
+ return current;
628
+ }
629
+ const previousOperations = current.undoStack[current.undoStack.length - 1];
630
+ return {
631
+ operations: previousOperations,
632
+ redoStack: [current.operations, ...current.redoStack],
633
+ undoStack: current.undoStack.slice(0, -1)
634
+ };
635
+ });
636
+ };
637
+ const handleRedo = () => {
638
+ setEditorHistory((current) => {
639
+ if (current.redoStack.length === 0) {
640
+ return current;
641
+ }
642
+ const [nextOperations, ...remainingRedo] = current.redoStack;
643
+ return {
644
+ operations: nextOperations,
645
+ redoStack: remainingRedo,
646
+ undoStack: [...current.undoStack, current.operations]
647
+ };
648
+ });
649
+ };
650
+ const handleClearAnnotations = () => {
651
+ if (editorHistory.operations.length === 0) {
652
+ return;
653
+ }
654
+ commitOperations([]);
655
+ };
656
+ const handleCanvasPointerDown = (event) => {
657
+ if (!annotationCanvasRef.current) {
658
+ return;
659
+ }
660
+ setError(null);
661
+ const canvas = annotationCanvasRef.current;
662
+ const canvasPoint = getCanvasPoint(event, canvas);
663
+ if (annotationTool === "text") {
664
+ const existingText = inlineTextRef.current.trim();
665
+ const existingCursor = textCursorRef.current;
666
+ if (existingText && existingCursor) {
667
+ appendOperation({
668
+ id: createOperationId(),
669
+ type: "text",
670
+ style: { color: annotationColorRef.current, size: annotationSizeRef.current },
671
+ point: existingCursor.canvasPoint,
672
+ text: existingText
673
+ });
674
+ }
675
+ const domX = event.clientX;
676
+ const domY = event.clientY;
677
+ inlineTextRef.current = "";
678
+ textCursorRef.current = { domX, domY, canvasPoint };
679
+ setInlineText("");
680
+ setTextCursor({ domX, domY, canvasPoint });
681
+ return;
682
+ }
683
+ event.preventDefault();
684
+ canvas.setPointerCapture(event.pointerId);
685
+ pointerIdRef.current = event.pointerId;
686
+ const style = { color: annotationColor, size: annotationSize };
687
+ const nextDraft = annotationTool === "pen" ? {
688
+ id: createOperationId(),
689
+ type: "pen",
690
+ style,
691
+ points: [canvasPoint]
692
+ } : annotationTool === "rectangle" ? {
693
+ id: createOperationId(),
694
+ type: "rectangle",
695
+ style,
696
+ start: canvasPoint,
697
+ end: canvasPoint
698
+ } : {
699
+ id: createOperationId(),
700
+ type: "arrow",
701
+ style,
702
+ start: canvasPoint,
703
+ end: canvasPoint
704
+ };
705
+ draftOperationRef.current = nextDraft;
706
+ setDraftOperation(nextDraft);
707
+ };
708
+ const handleCanvasPointerMove = (event) => {
709
+ if (!annotationCanvasRef.current || pointerIdRef.current !== event.pointerId) {
710
+ return;
711
+ }
712
+ const activeDraft = draftOperationRef.current;
713
+ if (!activeDraft) {
714
+ return;
715
+ }
716
+ const point = getCanvasPoint(event, annotationCanvasRef.current);
717
+ const nextDraft = activeDraft.type === "pen" ? {
718
+ ...activeDraft,
719
+ points: [...activeDraft.points, point]
720
+ } : {
721
+ ...activeDraft,
722
+ end: point
723
+ };
724
+ draftOperationRef.current = nextDraft;
725
+ setDraftOperation(nextDraft);
726
+ };
727
+ const handleCanvasPointerUp = (event) => {
728
+ if (!annotationCanvasRef.current || pointerIdRef.current !== event.pointerId) {
729
+ return;
730
+ }
731
+ const canvas = annotationCanvasRef.current;
732
+ if (canvas.hasPointerCapture(event.pointerId)) {
733
+ canvas.releasePointerCapture(event.pointerId);
734
+ }
735
+ pointerIdRef.current = null;
736
+ const activeDraft = draftOperationRef.current;
737
+ draftOperationRef.current = null;
738
+ setDraftOperation(null);
739
+ if (!activeDraft) {
740
+ return;
741
+ }
742
+ if (activeDraft.type === "pen") {
743
+ const points = activeDraft.points.length === 1 ? [...activeDraft.points, activeDraft.points[0]] : activeDraft.points;
744
+ appendOperation({ ...activeDraft, points });
745
+ return;
746
+ }
747
+ if (!isShapeMeaningful(activeDraft.start, activeDraft.end)) {
748
+ return;
749
+ }
750
+ appendOperation(activeDraft);
751
+ };
752
+ const handleCanvasPointerCancel = (event) => {
753
+ if (annotationCanvasRef.current && pointerIdRef.current === event.pointerId && annotationCanvasRef.current.hasPointerCapture(event.pointerId)) {
754
+ annotationCanvasRef.current.releasePointerCapture(event.pointerId);
755
+ }
756
+ pointerIdRef.current = null;
757
+ draftOperationRef.current = null;
758
+ setDraftOperation(null);
759
+ };
760
+ const handleApplyAnnotation = async () => {
761
+ if (!annotationCanvasRef.current || !editorImage) {
762
+ return;
763
+ }
764
+ try {
765
+ const previewUrl = annotationCanvasRef.current.toDataURL("image/png");
766
+ const file = await canvasToFile(annotationCanvasRef.current, editorImage.fileName);
767
+ const uploaded = await uploadImageFile(file);
768
+ if (uploaded) {
769
+ setScreenshotPreviewUrl(previewUrl);
770
+ closeAnnotationEditor();
771
+ }
772
+ } catch (nextError) {
773
+ setError(nextError instanceof Error ? nextError.message : "Failed to export image.");
774
+ }
775
+ };
776
+ const handleRemoveScreenshot = async () => {
777
+ if (!screenshotId) {
778
+ setScreenshotPreviewUrl(null);
779
+ return;
780
+ }
781
+ if (!onDeleteScreenshot) {
782
+ setScreenshotId(null);
783
+ setScreenshotPreviewUrl(null);
784
+ return;
785
+ }
786
+ setDeletingScreenshot(true);
787
+ setError(null);
788
+ try {
789
+ const result = await onDeleteScreenshot(screenshotId);
790
+ if (!result.success) {
791
+ setError(result.error);
792
+ return;
793
+ }
794
+ setScreenshotId(null);
795
+ setScreenshotPreviewUrl(null);
796
+ setNotice("Screenshot removed.");
797
+ } finally {
798
+ setDeletingScreenshot(false);
799
+ }
800
+ };
801
+ const handleSubmit = async () => {
802
+ if (!message.trim()) {
803
+ setError("Please enter a message.");
804
+ return;
805
+ }
806
+ setSubmitting(true);
807
+ setError(null);
808
+ const result = await onSubmit({
809
+ message: message.trim(),
810
+ pagePath: currentPath,
811
+ selector: captureData?.selector,
812
+ selectedText: captureData?.selectedText,
813
+ screenshotId,
814
+ meta: {
815
+ userAgent: window.navigator.userAgent,
816
+ locale: window.navigator.language,
817
+ viewport: `${window.innerWidth}x${window.innerHeight}`
818
+ }
819
+ });
820
+ setSubmitting(false);
821
+ if (!result.success) {
822
+ setError(result.error);
823
+ return;
824
+ }
825
+ setMessage("");
826
+ setCaptureData(null);
827
+ setScreenshotId(null);
828
+ setScreenshotPreviewUrl(null);
829
+ setNotice(null);
830
+ setSubmitted(true);
831
+ };
832
+ const currentHasUndo = editorHistory.undoStack.length > 0;
833
+ const currentHasRedo = editorHistory.redoStack.length > 0;
834
+ const hasAnnotations = editorHistory.operations.length > 0;
835
+ const toolBtn = (tool, icon, label) => /* @__PURE__ */ jsxRuntime.jsxs(
836
+ "button",
837
+ {
838
+ type: "button",
839
+ title: label,
840
+ onClick: () => setAnnotationTool(tool),
841
+ style: {
842
+ display: "flex",
843
+ alignItems: "center",
844
+ gap: "5px",
845
+ borderRadius: "6px",
846
+ border: annotationTool === tool ? "1px solid #4ade80" : "1px solid #334155",
847
+ background: annotationTool === tool ? "rgba(74,222,128,0.12)" : "#0f172a",
848
+ color: annotationTool === tool ? "#4ade80" : "#94a3b8",
849
+ padding: "5px 9px",
850
+ cursor: "pointer",
851
+ fontSize: "12px",
852
+ fontWeight: 500
853
+ },
854
+ children: [
855
+ icon,
856
+ label
857
+ ]
858
+ },
859
+ tool
860
+ );
861
+ const iconBtn = (onClick, icon, label, disabled = false) => /* @__PURE__ */ jsxRuntime.jsxs(
862
+ "button",
863
+ {
864
+ type: "button",
865
+ title: label,
866
+ onClick,
867
+ disabled,
868
+ style: {
869
+ display: "flex",
870
+ alignItems: "center",
871
+ gap: "4px",
872
+ borderRadius: "6px",
873
+ border: "1px solid #334155",
874
+ background: "#0f172a",
875
+ color: disabled ? "#475569" : "#94a3b8",
876
+ padding: "5px 9px",
877
+ cursor: disabled ? "not-allowed" : "pointer",
878
+ fontSize: "12px"
879
+ },
880
+ children: [
881
+ icon,
882
+ label
883
+ ]
884
+ }
885
+ );
886
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
887
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: `
888
+ @keyframes afb-spin-in {
889
+ from { transform: rotate(-90deg) scale(0.7); opacity: 0; }
890
+ to { transform: rotate(0deg) scale(1); opacity: 1; }
891
+ }
892
+ .afb-icon-enter {
893
+ animation: afb-spin-in 0.18s ease forwards;
894
+ }
895
+ ` }),
896
+ /* @__PURE__ */ jsxRuntime.jsx(
897
+ "button",
898
+ {
899
+ type: "button",
900
+ onClick: () => {
901
+ if (submitted) return;
902
+ setOpen((v) => !v);
903
+ },
904
+ title: open ? "Close feedback" : "Send feedback",
905
+ style: {
906
+ position: "fixed",
907
+ right: "20px",
908
+ bottom: "20px",
909
+ zIndex: 9999,
910
+ width: "48px",
911
+ height: "48px",
912
+ borderRadius: "50%",
913
+ backgroundColor: open ? "#374151" : "#15803d",
914
+ color: "#ffffff",
915
+ border: "none",
916
+ display: "flex",
917
+ alignItems: "center",
918
+ justifyContent: "center",
919
+ cursor: "pointer",
920
+ boxShadow: "0 4px 14px rgba(0,0,0,0.4)",
921
+ transition: "background-color 0.2s ease, transform 0.15s ease",
922
+ visibility: capturingScreen ? "hidden" : "visible"
923
+ },
924
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "afb-icon-enter", children: open ? /* @__PURE__ */ jsxRuntime.jsx(XIcon, { size: 20 }) : /* @__PURE__ */ jsxRuntime.jsx(ChatIcon, {}) }, open ? "x" : "chat")
925
+ }
926
+ ),
927
+ /* @__PURE__ */ jsxRuntime.jsx(
928
+ "div",
929
+ {
930
+ style: {
931
+ position: "fixed",
932
+ right: "20px",
933
+ bottom: "80px",
934
+ width: "360px",
935
+ background: "#0f172a",
936
+ color: "#f1f5f9",
937
+ borderRadius: "14px",
938
+ border: "1px solid #1e293b",
939
+ padding: "0",
940
+ zIndex: 9999,
941
+ boxShadow: "0 16px 48px rgba(0,0,0,0.55)",
942
+ display: "flex",
943
+ flexDirection: "column",
944
+ maxHeight: "calc(100vh - 110px)",
945
+ opacity: open ? 1 : 0,
946
+ transform: open ? "scale(1) translateY(0)" : "scale(0.92) translateY(8px)",
947
+ pointerEvents: open ? "auto" : "none",
948
+ transformOrigin: "bottom right",
949
+ transition: "opacity 0.18s ease, transform 0.18s ease",
950
+ visibility: capturingScreen ? "hidden" : "visible",
951
+ overflow: "hidden"
952
+ },
953
+ children: submitted ? (
954
+ /* ── Success screen ── */
955
+ /* @__PURE__ */ jsxRuntime.jsxs(
956
+ "div",
957
+ {
958
+ style: {
959
+ display: "flex",
960
+ flexDirection: "column",
961
+ alignItems: "center",
962
+ justifyContent: "center",
963
+ gap: "12px",
964
+ padding: "40px 24px",
965
+ textAlign: "center",
966
+ color: "#4ade80"
967
+ },
968
+ children: [
969
+ /* @__PURE__ */ jsxRuntime.jsx(CheckCircleIcon, {}),
970
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
971
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: "0 0 4px", fontSize: "16px", fontWeight: 600, color: "#f1f5f9" }, children: "Feedback sent!" }),
972
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, fontSize: "13px", color: "#94a3b8" }, children: "Thank you \u2014 we'll take a look." })
973
+ ] })
974
+ ]
975
+ }
976
+ )
977
+ ) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
978
+ /* @__PURE__ */ jsxRuntime.jsxs(
979
+ "div",
980
+ {
981
+ style: {
982
+ display: "flex",
983
+ alignItems: "center",
984
+ justifyContent: "space-between",
985
+ padding: "12px 14px 10px",
986
+ borderBottom: "1px solid #1e293b"
987
+ },
988
+ children: [
989
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
990
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, fontSize: "14px", fontWeight: 600, color: "#f1f5f9" }, children: title }),
991
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: "2px 0 0", fontSize: "11px", color: "#64748b" }, children: currentPath })
992
+ ] }),
993
+ /* @__PURE__ */ jsxRuntime.jsx(
994
+ "button",
995
+ {
996
+ type: "button",
997
+ onClick: () => setOpen(false),
998
+ title: "Close",
999
+ style: {
1000
+ background: "none",
1001
+ border: "none",
1002
+ color: "#64748b",
1003
+ cursor: "pointer",
1004
+ padding: "4px",
1005
+ display: "flex",
1006
+ alignItems: "center",
1007
+ borderRadius: "6px"
1008
+ },
1009
+ children: /* @__PURE__ */ jsxRuntime.jsx(XIcon, { size: 16 })
1010
+ }
1011
+ )
1012
+ ]
1013
+ }
1014
+ ),
1015
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { padding: "12px 14px", display: "flex", flexDirection: "column", gap: "10px", overflowY: "auto", minHeight: 0 }, children: [
1016
+ /* @__PURE__ */ jsxRuntime.jsx(
1017
+ "textarea",
1018
+ {
1019
+ value: message,
1020
+ onChange: (event) => setMessage(event.target.value),
1021
+ rows: 5,
1022
+ placeholder: "Describe the issue or share your thoughts\u2026",
1023
+ style: {
1024
+ width: "100%",
1025
+ borderRadius: "8px",
1026
+ border: "1px solid #1e293b",
1027
+ background: "#1e293b",
1028
+ color: "#f1f5f9",
1029
+ padding: "10px",
1030
+ resize: "vertical",
1031
+ fontSize: "13px",
1032
+ lineHeight: "1.5",
1033
+ outline: "none",
1034
+ boxSizing: "border-box"
1035
+ }
1036
+ }
1037
+ ),
1038
+ allowScreenshotUpload && onUpload ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" }, children: [
1039
+ /* @__PURE__ */ jsxRuntime.jsxs(
1040
+ "button",
1041
+ {
1042
+ type: "button",
1043
+ onClick: handleCaptureScreenshot,
1044
+ style: {
1045
+ display: "flex",
1046
+ alignItems: "center",
1047
+ gap: "5px",
1048
+ borderRadius: "7px",
1049
+ border: "1px solid #1e293b",
1050
+ background: "#1e293b",
1051
+ color: "#94a3b8",
1052
+ padding: "5px 9px",
1053
+ cursor: "pointer",
1054
+ fontSize: "12px"
1055
+ },
1056
+ children: [
1057
+ /* @__PURE__ */ jsxRuntime.jsx(CameraIcon, {}),
1058
+ "Capture screen"
1059
+ ]
1060
+ }
1061
+ ),
1062
+ /* @__PURE__ */ jsxRuntime.jsxs(
1063
+ "button",
1064
+ {
1065
+ type: "button",
1066
+ onClick: () => setCaptureMode((v) => !v),
1067
+ style: {
1068
+ display: "flex",
1069
+ alignItems: "center",
1070
+ gap: "5px",
1071
+ borderRadius: "7px",
1072
+ border: captureMode ? "1px solid #4ade80" : "1px solid #1e293b",
1073
+ background: captureMode ? "rgba(74,222,128,0.08)" : "#1e293b",
1074
+ color: captureMode ? "#4ade80" : "#94a3b8",
1075
+ padding: "5px 9px",
1076
+ cursor: "pointer",
1077
+ fontSize: "12px"
1078
+ },
1079
+ children: [
1080
+ /* @__PURE__ */ jsxRuntime.jsx(CursorIcon, {}),
1081
+ captureMode ? "Click an element\u2026" : "Capture element"
1082
+ ]
1083
+ }
1084
+ ),
1085
+ /* @__PURE__ */ jsxRuntime.jsxs(
1086
+ "label",
1087
+ {
1088
+ style: {
1089
+ display: "flex",
1090
+ alignItems: "center",
1091
+ gap: "5px",
1092
+ borderRadius: "7px",
1093
+ border: "1px solid #1e293b",
1094
+ background: "#1e293b",
1095
+ color: "#94a3b8",
1096
+ padding: "5px 9px",
1097
+ cursor: "pointer",
1098
+ fontSize: "12px"
1099
+ },
1100
+ children: [
1101
+ /* @__PURE__ */ jsxRuntime.jsx(UploadIcon, {}),
1102
+ uploading ? "Uploading\u2026" : uploadLabel,
1103
+ /* @__PURE__ */ jsxRuntime.jsx(
1104
+ "input",
1105
+ {
1106
+ type: "file",
1107
+ accept: screenshotAllowedMimeTypes.join(","),
1108
+ onChange: handleUpload,
1109
+ hidden: true
1110
+ }
1111
+ )
1112
+ ]
1113
+ }
1114
+ )
1115
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", gap: "6px", flexWrap: "wrap" }, children: /* @__PURE__ */ jsxRuntime.jsxs(
1116
+ "button",
1117
+ {
1118
+ type: "button",
1119
+ onClick: () => setCaptureMode((v) => !v),
1120
+ style: {
1121
+ display: "flex",
1122
+ alignItems: "center",
1123
+ gap: "5px",
1124
+ borderRadius: "7px",
1125
+ border: captureMode ? "1px solid #4ade80" : "1px solid #1e293b",
1126
+ background: captureMode ? "rgba(74,222,128,0.08)" : "#1e293b",
1127
+ color: captureMode ? "#4ade80" : "#94a3b8",
1128
+ padding: "5px 9px",
1129
+ cursor: "pointer",
1130
+ fontSize: "12px"
1131
+ },
1132
+ children: [
1133
+ /* @__PURE__ */ jsxRuntime.jsx(CursorIcon, {}),
1134
+ captureMode ? "Click an element\u2026" : "Capture element"
1135
+ ]
1136
+ }
1137
+ ) }),
1138
+ allowScreenshotUpload && onUpload ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, fontSize: "11px", color: "#475569" }, children: "Paste an image with Ctrl/Cmd+V or capture the current tab first." }) : null,
1139
+ captureData ? /* @__PURE__ */ jsxRuntime.jsxs("p", { style: { margin: 0, fontSize: "11px", color: "#64748b", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: [
1140
+ "Element: ",
1141
+ /* @__PURE__ */ jsxRuntime.jsx("code", { style: { color: "#94a3b8" }, children: captureData.selector })
1142
+ ] }) : null,
1143
+ screenshotId ? /* @__PURE__ */ jsxRuntime.jsxs(
1144
+ "div",
1145
+ {
1146
+ style: {
1147
+ borderRadius: "10px",
1148
+ border: "1px solid #1e293b",
1149
+ background: "#0a0f1e",
1150
+ padding: "8px"
1151
+ },
1152
+ children: [
1153
+ screenshotPreviewUrl ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: "8px", borderRadius: "6px", overflow: "hidden" }, children: /* @__PURE__ */ jsxRuntime.jsx(
1154
+ "img",
1155
+ {
1156
+ src: screenshotPreviewUrl,
1157
+ alt: "Annotated screenshot preview",
1158
+ style: { width: "100%", height: "auto", display: "block" }
1159
+ }
1160
+ ) }) : null,
1161
+ /* @__PURE__ */ jsxRuntime.jsxs(
1162
+ "div",
1163
+ {
1164
+ style: {
1165
+ display: "flex",
1166
+ justifyContent: "space-between",
1167
+ alignItems: "center"
1168
+ },
1169
+ children: [
1170
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, fontSize: "11px", color: "#64748b" }, children: "Screenshot attached" }),
1171
+ /* @__PURE__ */ jsxRuntime.jsxs(
1172
+ "button",
1173
+ {
1174
+ type: "button",
1175
+ onClick: handleRemoveScreenshot,
1176
+ disabled: deletingScreenshot,
1177
+ style: {
1178
+ display: "flex",
1179
+ alignItems: "center",
1180
+ gap: "4px",
1181
+ borderRadius: "6px",
1182
+ border: "1px solid #7f1d1d",
1183
+ background: "#450a0a",
1184
+ color: "#fca5a5",
1185
+ padding: "3px 8px",
1186
+ cursor: deletingScreenshot ? "wait" : "pointer",
1187
+ opacity: deletingScreenshot ? 0.7 : 1,
1188
+ fontSize: "11px"
1189
+ },
1190
+ children: [
1191
+ /* @__PURE__ */ jsxRuntime.jsx(TrashIcon, {}),
1192
+ deletingScreenshot ? "Removing\u2026" : "Remove"
1193
+ ]
1194
+ }
1195
+ )
1196
+ ]
1197
+ }
1198
+ )
1199
+ ]
1200
+ }
1201
+ ) : null,
1202
+ notice ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, color: "#93c5fd", fontSize: "12px" }, children: notice }) : null,
1203
+ error ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, color: "#fca5a5", fontSize: "12px" }, children: error }) : null
1204
+ ] }),
1205
+ /* @__PURE__ */ jsxRuntime.jsx(
1206
+ "div",
1207
+ {
1208
+ style: {
1209
+ display: "flex",
1210
+ justifyContent: "flex-end",
1211
+ padding: "10px 14px 14px",
1212
+ borderTop: "1px solid #1e293b"
1213
+ },
1214
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
1215
+ "button",
1216
+ {
1217
+ type: "button",
1218
+ onClick: handleSubmit,
1219
+ disabled: submitting,
1220
+ style: {
1221
+ display: "flex",
1222
+ alignItems: "center",
1223
+ gap: "7px",
1224
+ borderRadius: "8px",
1225
+ border: "none",
1226
+ background: "#15803d",
1227
+ color: "#f1f5f9",
1228
+ padding: "8px 16px",
1229
+ cursor: submitting ? "wait" : "pointer",
1230
+ fontWeight: 600,
1231
+ fontSize: "13px",
1232
+ opacity: submitting ? 0.75 : 1,
1233
+ transition: "opacity 0.15s ease"
1234
+ },
1235
+ children: [
1236
+ /* @__PURE__ */ jsxRuntime.jsx(SendIcon, {}),
1237
+ submitting ? "Sending\u2026" : submitLabel
1238
+ ]
1239
+ }
1240
+ )
1241
+ }
1242
+ )
1243
+ ] })
1244
+ }
1245
+ ),
1246
+ annotating && editorImage ? /* @__PURE__ */ jsxRuntime.jsxs(
1247
+ "div",
1248
+ {
1249
+ style: {
1250
+ position: "fixed",
1251
+ inset: "0",
1252
+ zIndex: 1e4,
1253
+ background: "rgba(3, 7, 18, 0.96)",
1254
+ color: "#f8fafc",
1255
+ display: "flex",
1256
+ flexDirection: "column"
1257
+ },
1258
+ children: [
1259
+ /* @__PURE__ */ jsxRuntime.jsxs(
1260
+ "div",
1261
+ {
1262
+ style: {
1263
+ display: "flex",
1264
+ flexWrap: "wrap",
1265
+ gap: "10px",
1266
+ alignItems: "center",
1267
+ justifyContent: "space-between",
1268
+ padding: "10px 16px",
1269
+ borderBottom: "1px solid rgba(148, 163, 184, 0.15)",
1270
+ background: "rgba(15, 23, 42, 0.97)"
1271
+ },
1272
+ children: [
1273
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: "12px" }, children: [
1274
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { style: { fontSize: "14px", color: "#f1f5f9" }, children: "Annotate screenshot" }),
1275
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "11px", color: "#475569" }, children: editorImage.fileName })
1276
+ ] }),
1277
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexWrap: "wrap", gap: "6px", alignItems: "center" }, children: [
1278
+ toolBtn("pen", /* @__PURE__ */ jsxRuntime.jsx(PenIcon, {}), "Pen"),
1279
+ toolBtn("rectangle", /* @__PURE__ */ jsxRuntime.jsx(RectIcon, {}), "Rect"),
1280
+ toolBtn("arrow", /* @__PURE__ */ jsxRuntime.jsx(ArrowIcon, {}), "Arrow"),
1281
+ toolBtn("text", /* @__PURE__ */ jsxRuntime.jsx(TextIcon, {}), "Text"),
1282
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: "4px", alignItems: "center" }, children: [
1283
+ DEFAULT_COLORS.map((color) => /* @__PURE__ */ jsxRuntime.jsx(
1284
+ "button",
1285
+ {
1286
+ type: "button",
1287
+ onClick: () => setAnnotationColor(color),
1288
+ "aria-label": `Select ${color} color`,
1289
+ style: {
1290
+ width: "20px",
1291
+ height: "20px",
1292
+ borderRadius: "50%",
1293
+ border: annotationColor === color ? "2px solid #f8fafc" : "1px solid #334155",
1294
+ background: color,
1295
+ cursor: "pointer",
1296
+ flexShrink: 0
1297
+ }
1298
+ },
1299
+ color
1300
+ )),
1301
+ /* @__PURE__ */ jsxRuntime.jsx(
1302
+ "input",
1303
+ {
1304
+ type: "color",
1305
+ value: annotationColor,
1306
+ onChange: (e) => setAnnotationColor(e.target.value),
1307
+ "aria-label": "Custom color",
1308
+ title: "Custom color",
1309
+ style: { width: "28px", height: "28px", border: "none", background: "transparent", cursor: "pointer" }
1310
+ }
1311
+ )
1312
+ ] }),
1313
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: { display: "flex", alignItems: "center", gap: "6px", fontSize: "11px", color: "#64748b" }, children: [
1314
+ "Size",
1315
+ /* @__PURE__ */ jsxRuntime.jsx(
1316
+ "input",
1317
+ {
1318
+ type: "range",
1319
+ min: 1,
1320
+ max: 18,
1321
+ value: annotationSize,
1322
+ onChange: (e) => setAnnotationSize(Number(e.target.value)),
1323
+ "aria-label": "Stroke size",
1324
+ style: { width: "72px" }
1325
+ }
1326
+ )
1327
+ ] }),
1328
+ iconBtn(handleUndo, /* @__PURE__ */ jsxRuntime.jsx(UndoIcon, {}), "Undo", !currentHasUndo),
1329
+ iconBtn(handleRedo, /* @__PURE__ */ jsxRuntime.jsx(RedoIcon, {}), "Redo", !currentHasRedo),
1330
+ iconBtn(handleClearAnnotations, /* @__PURE__ */ jsxRuntime.jsx(TrashIcon, {}), "Clear", !hasAnnotations)
1331
+ ] })
1332
+ ]
1333
+ }
1334
+ ),
1335
+ /* @__PURE__ */ jsxRuntime.jsxs(
1336
+ "div",
1337
+ {
1338
+ ref: annotationScrollRef,
1339
+ style: {
1340
+ flex: 1,
1341
+ overflow: "auto",
1342
+ padding: "16px",
1343
+ display: "flex",
1344
+ alignItems: "flex-start",
1345
+ justifyContent: "center",
1346
+ position: "relative"
1347
+ },
1348
+ children: [
1349
+ /* @__PURE__ */ jsxRuntime.jsx(
1350
+ "canvas",
1351
+ {
1352
+ ref: annotationCanvasRef,
1353
+ onPointerDown: handleCanvasPointerDown,
1354
+ onPointerMove: handleCanvasPointerMove,
1355
+ onPointerUp: handleCanvasPointerUp,
1356
+ onPointerCancel: handleCanvasPointerCancel,
1357
+ style: {
1358
+ width: "min(100%, 1400px)",
1359
+ height: "auto",
1360
+ display: "block",
1361
+ borderRadius: "12px",
1362
+ background: "#ffffff",
1363
+ boxShadow: "0 24px 80px rgba(15, 23, 42, 0.6)",
1364
+ touchAction: "none",
1365
+ cursor: annotationTool === "text" ? "text" : "crosshair"
1366
+ }
1367
+ }
1368
+ ),
1369
+ textCursor ? /* @__PURE__ */ jsxRuntime.jsx(
1370
+ "input",
1371
+ {
1372
+ autoFocus: true,
1373
+ ref: textInputRef,
1374
+ type: "text",
1375
+ value: inlineText,
1376
+ onChange: (e) => {
1377
+ inlineTextRef.current = e.target.value;
1378
+ setInlineText(e.target.value);
1379
+ },
1380
+ onKeyDown: (e) => {
1381
+ if (e.key === "Enter") {
1382
+ e.preventDefault();
1383
+ commitTextInput();
1384
+ }
1385
+ if (e.key === "Escape") {
1386
+ textCursorRef.current = null;
1387
+ setTextCursor(null);
1388
+ setInlineText("");
1389
+ inlineTextRef.current = "";
1390
+ }
1391
+ },
1392
+ placeholder: "Type \u2192 Enter to place",
1393
+ style: {
1394
+ position: "fixed",
1395
+ left: textCursor.domX,
1396
+ top: textCursor.domY,
1397
+ minWidth: "180px",
1398
+ background: "rgba(15, 23, 42, 0.92)",
1399
+ color: annotationColor,
1400
+ border: "1px dashed rgba(255,255,255,0.6)",
1401
+ borderRadius: "4px",
1402
+ padding: "4px 8px",
1403
+ fontSize: `${Math.max(14, annotationSize * 4)}px`,
1404
+ fontWeight: 600,
1405
+ outline: "none",
1406
+ zIndex: 10002,
1407
+ backdropFilter: "blur(6px)",
1408
+ boxShadow: "0 2px 12px rgba(0,0,0,0.4)"
1409
+ }
1410
+ }
1411
+ ) : null
1412
+ ]
1413
+ }
1414
+ ),
1415
+ /* @__PURE__ */ jsxRuntime.jsxs(
1416
+ "div",
1417
+ {
1418
+ style: {
1419
+ display: "flex",
1420
+ justifyContent: "space-between",
1421
+ alignItems: "center",
1422
+ gap: "12px",
1423
+ flexWrap: "wrap",
1424
+ padding: "10px 16px",
1425
+ borderTop: "1px solid rgba(148, 163, 184, 0.15)",
1426
+ background: "rgba(15, 23, 42, 0.97)"
1427
+ },
1428
+ children: [
1429
+ annotationTool === "text" ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, fontSize: "12px", color: "#64748b" }, children: "Click on the image to place text at that position." }) : /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, fontSize: "12px", color: "#64748b" }, children: "Draw on the image, then save when done." }),
1430
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: "8px" }, children: [
1431
+ /* @__PURE__ */ jsxRuntime.jsx(
1432
+ "button",
1433
+ {
1434
+ type: "button",
1435
+ onClick: closeAnnotationEditor,
1436
+ style: {
1437
+ borderRadius: "8px",
1438
+ border: "1px solid #334155",
1439
+ background: "#0f172a",
1440
+ color: "#94a3b8",
1441
+ padding: "7px 14px",
1442
+ cursor: "pointer",
1443
+ fontSize: "13px"
1444
+ },
1445
+ children: "Cancel"
1446
+ }
1447
+ ),
1448
+ /* @__PURE__ */ jsxRuntime.jsxs(
1449
+ "button",
1450
+ {
1451
+ type: "button",
1452
+ onClick: handleApplyAnnotation,
1453
+ disabled: uploading,
1454
+ style: {
1455
+ display: "flex",
1456
+ alignItems: "center",
1457
+ gap: "6px",
1458
+ borderRadius: "8px",
1459
+ border: "none",
1460
+ background: "#15803d",
1461
+ color: "#f1f5f9",
1462
+ padding: "7px 14px",
1463
+ cursor: uploading ? "wait" : "pointer",
1464
+ opacity: uploading ? 0.8 : 1,
1465
+ fontWeight: 600,
1466
+ fontSize: "13px"
1467
+ },
1468
+ children: [
1469
+ /* @__PURE__ */ jsxRuntime.jsx(SendIcon, {}),
1470
+ uploading ? "Uploading\u2026" : "Save screenshot"
1471
+ ]
1472
+ }
1473
+ )
1474
+ ] })
1475
+ ]
1476
+ }
1477
+ )
1478
+ ]
1479
+ }
1480
+ ) : null
1481
+ ] });
1482
+ }
1483
+ function AdminFeedbackWidget() {
1484
+ return /* @__PURE__ */ jsxRuntime.jsx(
1485
+ FeedbackWidget,
1486
+ {
1487
+ title: "Admin feedback",
1488
+ submitLabel: "Send",
1489
+ uploadLabel: "Upload image",
1490
+ allowScreenshotUpload: true,
1491
+ onSubmit: async (payload) => {
1492
+ const response = await fetch("/api/admin-feedback/submit", {
1493
+ method: "POST",
1494
+ credentials: "include",
1495
+ headers: { "content-type": "application/json" },
1496
+ body: JSON.stringify(payload)
1497
+ });
1498
+ const result = await response.json();
1499
+ if (!result.success) {
1500
+ return { success: false, error: result.error || "Submit failed." };
1501
+ }
1502
+ return { success: true };
1503
+ },
1504
+ onUpload: async (formData) => {
1505
+ const response = await fetch("/api/admin-feedback/upload", {
1506
+ method: "POST",
1507
+ credentials: "include",
1508
+ body: formData
1509
+ });
1510
+ const result = await response.json();
1511
+ if (!result.success || typeof result.mediaId !== "number") {
1512
+ return { success: false, error: result.error || "Upload failed." };
1513
+ }
1514
+ return { success: true, mediaId: result.mediaId };
1515
+ },
1516
+ onDeleteScreenshot: async (mediaId) => {
1517
+ const response = await fetch(`/api/admin-feedback/upload/${mediaId}`, {
1518
+ method: "DELETE",
1519
+ credentials: "include"
1520
+ });
1521
+ const result = await response.json();
1522
+ if (!result.success) {
1523
+ return { success: false, error: result.error || "Delete failed." };
1524
+ }
1525
+ return { success: true };
1526
+ }
1527
+ }
1528
+ );
1529
+ }
1530
+
1531
+ // src/tenant/extractTenantSlug.ts
1532
+ var extractTenantSlugFromPathname = (pathname, pathMarkers) => {
1533
+ if (pathMarkers.length === 0) {
1534
+ return null;
1535
+ }
1536
+ const segments = pathname.split("?")[0].split("/").filter(Boolean);
1537
+ for (const marker of pathMarkers) {
1538
+ const markerIndex = segments.indexOf(marker);
1539
+ if (markerIndex > 0) {
1540
+ return segments[markerIndex - 1] ?? null;
1541
+ }
1542
+ }
1543
+ return null;
1544
+ };
1545
+
1546
+ // src/client/routeMatcher.ts
1547
+ var escapeRegex = (input) => input.replace(/[.+^${}()|[\]\\]/g, "\\$&");
1548
+ var toRegExp = (pattern) => {
1549
+ const escaped = pattern.split("*").map((segment) => escapeRegex(segment)).join(".*");
1550
+ return new RegExp(`^${escaped}$`);
1551
+ };
1552
+ var pathMatchesAllowlist = (pathname, patterns) => {
1553
+ if (patterns.length === 0) {
1554
+ return false;
1555
+ }
1556
+ return patterns.some((pattern) => toRegExp(pattern).test(pathname));
1557
+ };
1558
+ var normalizePathname = (pathname, locales) => {
1559
+ if (locales.length === 0) {
1560
+ return pathname;
1561
+ }
1562
+ const segments = pathname.split("/").filter(Boolean);
1563
+ const maybeLocale = segments[0];
1564
+ if (maybeLocale && locales.includes(maybeLocale)) {
1565
+ return `/${segments.slice(1).join("/")}`;
1566
+ }
1567
+ return pathname;
1568
+ };
1569
+ function FrontendFeedbackWidget({
1570
+ include,
1571
+ locales = [],
1572
+ title = "Feedback",
1573
+ submitLabel = "Send",
1574
+ uploadLabel = "Upload image",
1575
+ tenantPathMarkers = [],
1576
+ tenantFormDataKey = "tenant"
1577
+ }) {
1578
+ const pathname = navigation.usePathname();
1579
+ const normalizedPathname = normalizePathname(pathname, locales);
1580
+ if (!pathMatchesAllowlist(normalizedPathname, include)) {
1581
+ return null;
1582
+ }
1583
+ return /* @__PURE__ */ jsxRuntime.jsx(
1584
+ FeedbackWidget,
1585
+ {
1586
+ title,
1587
+ submitLabel,
1588
+ uploadLabel,
1589
+ allowScreenshotUpload: true,
1590
+ onSubmit: async (payload) => {
1591
+ const response = await fetch("/api/admin-feedback/submit", {
1592
+ method: "POST",
1593
+ credentials: "include",
1594
+ headers: { "content-type": "application/json" },
1595
+ body: JSON.stringify(payload)
1596
+ });
1597
+ const result = await response.json();
1598
+ if (!result.success) {
1599
+ return { success: false, error: result.error || "Submit failed." };
1600
+ }
1601
+ return { success: true };
1602
+ },
1603
+ onUpload: async (formData) => {
1604
+ if (tenantPathMarkers.length > 0) {
1605
+ const tenantSlug = extractTenantSlugFromPathname(pathname, tenantPathMarkers);
1606
+ if (tenantSlug) {
1607
+ formData.set(tenantFormDataKey, tenantSlug);
1608
+ }
1609
+ }
1610
+ const response = await fetch("/api/admin-feedback/upload", {
1611
+ method: "POST",
1612
+ credentials: "include",
1613
+ body: formData
1614
+ });
1615
+ const result = await response.json();
1616
+ if (!result.success || typeof result.mediaId !== "number") {
1617
+ return { success: false, error: result.error || "Upload failed." };
1618
+ }
1619
+ return { success: true, mediaId: result.mediaId };
1620
+ },
1621
+ onDeleteScreenshot: async (mediaId) => {
1622
+ const response = await fetch(`/api/admin-feedback/upload/${mediaId}`, {
1623
+ method: "DELETE",
1624
+ credentials: "include"
1625
+ });
1626
+ const result = await response.json();
1627
+ if (!result.success) {
1628
+ return { success: false, error: result.error || "Delete failed." };
1629
+ }
1630
+ return { success: true };
1631
+ }
1632
+ }
1633
+ );
1634
+ }
1635
+
1636
+ exports.AdminFeedbackWidget = AdminFeedbackWidget;
1637
+ exports.FeedbackWidget = FeedbackWidget;
1638
+ exports.FrontendFeedbackWidget = FrontendFeedbackWidget;