react-screenshots 0.5.16 → 0.5.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +145 -145
  3. package/electron/assets/electron-ed141e06.css +1 -0
  4. package/electron/assets/index-73f470f6.js +53 -0
  5. package/electron/electron.html +14 -0
  6. package/lib/react-screenshots.cjs.js +14 -0
  7. package/lib/react-screenshots.es.js +1716 -0
  8. package/lib/style.css +1 -0
  9. package/lib/types/ScreenshotsBackground/getBoundsByPoints.d.ts +2 -0
  10. package/lib/types/ScreenshotsBackground/index.d.ts +4 -0
  11. package/lib/types/ScreenshotsButton/index.d.ts +12 -0
  12. package/lib/types/ScreenshotsCanvas/getBoundsByPoints.d.ts +2 -0
  13. package/lib/types/ScreenshotsCanvas/getPoints.d.ts +2 -0
  14. package/lib/types/ScreenshotsCanvas/index.d.ts +15 -0
  15. package/lib/types/ScreenshotsCanvas/isPointInDraw.d.ts +2 -0
  16. package/lib/types/ScreenshotsColor/index.d.ts +8 -0
  17. package/lib/types/ScreenshotsContext.d.ts +29 -0
  18. package/lib/types/ScreenshotsMagnifier/index.d.ts +8 -0
  19. package/lib/types/ScreenshotsOperations/index.d.ts +6 -0
  20. package/lib/types/ScreenshotsOption/index.d.ts +15 -0
  21. package/lib/types/ScreenshotsSize/index.d.ts +8 -0
  22. package/lib/types/ScreenshotsSizeColor/index.d.ts +10 -0
  23. package/lib/types/ScreenshotsTextarea/calculateNodeSize.d.ts +17 -0
  24. package/lib/types/ScreenshotsTextarea/index.d.ts +15 -0
  25. package/lib/types/composeImage.d.ts +10 -0
  26. package/lib/types/exports.d.ts +3 -0
  27. package/lib/types/hooks/useBounds.d.ts +7 -0
  28. package/lib/types/hooks/useCall.d.ts +2 -0
  29. package/lib/types/hooks/useCanvasContextRef.d.ts +2 -0
  30. package/lib/types/hooks/useCanvasMousedown.d.ts +1 -0
  31. package/lib/types/hooks/useCanvasMousemove.d.ts +1 -0
  32. package/lib/types/hooks/useCanvasMouseup.d.ts +1 -0
  33. package/lib/types/hooks/useCursor.d.ts +6 -0
  34. package/lib/types/hooks/useDispatcher.d.ts +2 -0
  35. package/lib/types/hooks/useDrawSelect.d.ts +2 -0
  36. package/lib/types/hooks/useEmiter.d.ts +8 -0
  37. package/lib/types/hooks/useHistory.d.ts +16 -0
  38. package/lib/types/hooks/useLang.d.ts +2 -0
  39. package/lib/types/hooks/useOperation.d.ts +9 -0
  40. package/lib/types/hooks/useReset.d.ts +2 -0
  41. package/lib/types/hooks/useStore.d.ts +2 -0
  42. package/lib/types/index.d.ts +13 -0
  43. package/lib/types/operations/Arrow/draw.d.ts +11 -0
  44. package/lib/types/operations/Arrow/index.d.ts +22 -0
  45. package/lib/types/operations/Brush/draw.d.ts +3 -0
  46. package/lib/types/operations/Brush/index.d.ts +14 -0
  47. package/lib/types/operations/Cancel/index.d.ts +2 -0
  48. package/lib/types/operations/Ellipse/draw.d.ts +11 -0
  49. package/lib/types/operations/Ellipse/index.d.ts +28 -0
  50. package/lib/types/operations/Mosaic/index.d.ts +11 -0
  51. package/lib/types/operations/Ok/index.d.ts +2 -0
  52. package/lib/types/operations/Rectangle/draw.d.ts +11 -0
  53. package/lib/types/operations/Rectangle/index.d.ts +28 -0
  54. package/lib/types/operations/Redo/index.d.ts +2 -0
  55. package/lib/types/operations/Save/index.d.ts +2 -0
  56. package/lib/types/operations/Text/index.d.ts +22 -0
  57. package/lib/types/operations/Undo/index.d.ts +2 -0
  58. package/lib/types/operations/index.d.ts +3 -0
  59. package/lib/types/operations/utils.d.ts +4 -0
  60. package/lib/types/types.d.ts +39 -0
  61. package/lib/types/useGetLoadedImage.d.ts +1 -0
  62. package/lib/types/zh_CN.d.ts +16 -0
  63. package/package.json +22 -21
@@ -0,0 +1,1716 @@
1
+ import y, { useContext as pe, useCallback as g, memo as F, useState as $, useRef as E, useLayoutEffect as Q, useEffect as T, forwardRef as Me, useImperativeHandle as Be, cloneElement as $e } from "react";
2
+ import { createPortal as we } from "react-dom";
3
+ var _ = /* @__PURE__ */ ((e) => (e[e.Edit = 0] = "Edit", e[e.Source = 1] = "Source", e))(_ || {});
4
+ function fe({ image: e, width: t, height: s, history: i, bounds: r }) {
5
+ return new Promise((o, n) => {
6
+ const c = document.createElement("canvas"), f = r.width * window.devicePixelRatio, h = r.height * window.devicePixelRatio;
7
+ c.width = f, c.height = h;
8
+ const a = c.getContext("2d");
9
+ if (!a)
10
+ return n(new Error("convert image to blob fail"));
11
+ const l = e.naturalWidth / t, u = e.naturalHeight / s;
12
+ a.imageSmoothingEnabled = !0, a.imageSmoothingQuality = "low", a.setTransform(window.devicePixelRatio, 0, 0, window.devicePixelRatio, 0, 0), a.clearRect(0, 0, r.width, r.height), a.drawImage(
13
+ e,
14
+ r.x * l,
15
+ r.y * u,
16
+ r.width * l,
17
+ r.height * u,
18
+ 0,
19
+ 0,
20
+ r.width,
21
+ r.height
22
+ ), i.stack.slice(0, i.index + 1).forEach((d) => {
23
+ d.type === _.Source && d.draw(a, d);
24
+ }), c.toBlob((d) => {
25
+ if (!d)
26
+ return n(new Error("canvas toBlob fail"));
27
+ o(d);
28
+ }, "image/png");
29
+ });
30
+ }
31
+ const Re = {
32
+ magnifier_position_label: "坐标",
33
+ operation_ok_title: "确定",
34
+ operation_cancel_title: "取消",
35
+ operation_save_title: "保存",
36
+ operation_redo_title: "重做",
37
+ operation_undo_title: "撤销",
38
+ operation_mosaic_title: "马赛克",
39
+ operation_text_title: "文本",
40
+ operation_brush_title: "画笔",
41
+ operation_arrow_title: "箭头",
42
+ operation_ellipse_title: "椭圆",
43
+ operation_rectangle_title: "矩形"
44
+ }, ye = y.createContext({
45
+ store: {
46
+ url: void 0,
47
+ image: null,
48
+ width: 0,
49
+ height: 0,
50
+ lang: Re,
51
+ emiterRef: { current: {} },
52
+ canvasContextRef: { current: null },
53
+ history: {
54
+ index: -1,
55
+ stack: []
56
+ },
57
+ bounds: null,
58
+ cursor: "move",
59
+ operation: void 0
60
+ },
61
+ dispatcher: {
62
+ call: void 0,
63
+ setHistory: void 0,
64
+ setBounds: void 0,
65
+ setCursor: void 0,
66
+ setOperation: void 0
67
+ }
68
+ });
69
+ function se() {
70
+ const { dispatcher: e } = pe(ye);
71
+ return e;
72
+ }
73
+ function Y() {
74
+ const { store: e } = pe(ye);
75
+ return e;
76
+ }
77
+ function K() {
78
+ const { bounds: e } = Y(), { setBounds: t } = se(), s = g(
79
+ (r) => {
80
+ t == null || t(r);
81
+ },
82
+ [t]
83
+ ), i = g(() => {
84
+ t == null || t(null);
85
+ }, [t]);
86
+ return [
87
+ e,
88
+ {
89
+ set: s,
90
+ reset: i
91
+ }
92
+ ];
93
+ }
94
+ function O() {
95
+ const { lang: e } = Y();
96
+ return e;
97
+ }
98
+ const q = 100, G = 80, De = F(function({ x: t, y: s }) {
99
+ const { width: i, height: r, image: o } = Y(), n = O(), [c, f] = $(null), h = E(null), a = E(null), l = E(null), [u, d] = $("000000");
100
+ return Q(() => {
101
+ if (!h.current)
102
+ return;
103
+ const p = h.current.getBoundingClientRect();
104
+ let w = t + 20, S = s + 20;
105
+ w + p.width > i && (w = t - p.width - 20), S + p.height > r && (S = s - p.height - 20), w < 0 && (w = 0), S < 0 && (S = 0), f({
106
+ x: w,
107
+ y: S
108
+ });
109
+ }, [i, r, t, s]), T(() => {
110
+ if (!o || !a.current) {
111
+ l.current = null;
112
+ return;
113
+ }
114
+ if (l.current || (l.current = a.current.getContext("2d")), !l.current)
115
+ return;
116
+ const p = l.current;
117
+ p.clearRect(0, 0, q, G);
118
+ const w = o.naturalWidth / i, S = o.naturalHeight / r;
119
+ p.drawImage(
120
+ o,
121
+ t * w - q / 2,
122
+ s * S - G / 2,
123
+ q,
124
+ G,
125
+ 0,
126
+ 0,
127
+ q,
128
+ G
129
+ );
130
+ const { data: R } = p.getImageData(Math.floor(q / 2), Math.floor(G / 2), 1, 1), b = Array.from(R.slice(0, 3)).map((M) => M >= 16 ? M.toString(16) : `0${M.toString(16)}`).join("").toUpperCase();
131
+ d(b);
132
+ }, [i, r, o, t, s]), /* @__PURE__ */ y.createElement(
133
+ "div",
134
+ {
135
+ ref: h,
136
+ className: "screenshots-magnifier",
137
+ style: {
138
+ transform: `translate(${c == null ? void 0 : c.x}px, ${c == null ? void 0 : c.y}px)`
139
+ }
140
+ },
141
+ /* @__PURE__ */ y.createElement("div", { className: "screenshots-magnifier-body" }, /* @__PURE__ */ y.createElement(
142
+ "canvas",
143
+ {
144
+ ref: a,
145
+ className: "screenshots-magnifier-body-canvas",
146
+ width: q,
147
+ height: G
148
+ }
149
+ )),
150
+ /* @__PURE__ */ y.createElement("div", { className: "screenshots-magnifier-footer" }, /* @__PURE__ */ y.createElement("div", { className: "screenshots-magnifier-footer-item" }, n.magnifier_position_label, ": (", t, ",", s, ")"), /* @__PURE__ */ y.createElement("div", { className: "screenshots-magnifier-footer-item" }, "RGB: #", u))
151
+ );
152
+ });
153
+ function _e({ x: e, y: t }, { x: s, y: i }, r, o) {
154
+ return e > s && ([e, s] = [s, e]), t > i && ([t, i] = [i, t]), e < 0 && (e = 0), s > r && (s = r), t < 0 && (t = 0), i > o && (i = o), {
155
+ x: e,
156
+ y: t,
157
+ width: s - e,
158
+ height: i - t
159
+ };
160
+ }
161
+ const Pe = F(function() {
162
+ const { url: t, image: s, width: i, height: r } = Y(), [o, n] = K(), c = E(null), f = E(null), h = E(!1), [a, l] = $(null), u = g(
163
+ (p, w) => {
164
+ if (!c.current)
165
+ return;
166
+ const { x: S, y: R } = c.current.getBoundingClientRect();
167
+ n.set(
168
+ _e(
169
+ {
170
+ x: p.x - S,
171
+ y: p.y - R
172
+ },
173
+ {
174
+ x: w.x - S,
175
+ y: w.y - R
176
+ },
177
+ i,
178
+ r
179
+ )
180
+ );
181
+ },
182
+ [i, r, n]
183
+ ), d = g(
184
+ (p) => {
185
+ f.current || o || p.button !== 0 || (f.current = {
186
+ x: p.clientX,
187
+ y: p.clientY
188
+ }, h.current = !1);
189
+ },
190
+ [o]
191
+ );
192
+ return T(() => {
193
+ const p = (S) => {
194
+ if (c.current) {
195
+ const R = c.current.getBoundingClientRect();
196
+ S.clientX < R.left || S.clientY < R.top || S.clientX > R.right || S.clientY > R.bottom ? l(null) : l({
197
+ x: S.clientX - R.x,
198
+ y: S.clientY - R.y
199
+ });
200
+ }
201
+ f.current && (u(f.current, {
202
+ x: S.clientX,
203
+ y: S.clientY
204
+ }), h.current = !0);
205
+ }, w = (S) => {
206
+ f.current && (h.current && u(f.current, {
207
+ x: S.clientX,
208
+ y: S.clientY
209
+ }), f.current = null, h.current = !1);
210
+ };
211
+ return window.addEventListener("mousemove", p), window.addEventListener("mouseup", w), () => {
212
+ window.removeEventListener("mousemove", p), window.removeEventListener("mouseup", w);
213
+ };
214
+ }, [u]), Q(() => {
215
+ (!s || o) && l(null);
216
+ }, [s, o]), !t || !s ? null : /* @__PURE__ */ y.createElement("div", { ref: c, className: "screenshots-background", onMouseDown: d }, /* @__PURE__ */ y.createElement("img", { className: "screenshots-background-image", src: t }), /* @__PURE__ */ y.createElement("div", { className: "screenshots-background-mask" }), a && !o && /* @__PURE__ */ y.createElement(De, { x: a == null ? void 0 : a.x, y: a == null ? void 0 : a.y }));
217
+ });
218
+ function j() {
219
+ const { cursor: e } = Y(), { setCursor: t } = se(), s = g(
220
+ (r) => {
221
+ t == null || t(r);
222
+ },
223
+ [t]
224
+ ), i = g(() => {
225
+ t == null || t("move");
226
+ }, [t]);
227
+ return [
228
+ e,
229
+ {
230
+ set: s,
231
+ reset: i
232
+ }
233
+ ];
234
+ }
235
+ function Z() {
236
+ const { emiterRef: e } = Y(), t = g(
237
+ (o, n) => {
238
+ const c = e.current;
239
+ Array.isArray(c[o]) ? c[o].push(n) : c[o] = [n];
240
+ },
241
+ [e]
242
+ ), s = g(
243
+ (o, n) => {
244
+ const c = e.current;
245
+ if (Array.isArray(c[o])) {
246
+ const f = c[o].findIndex((h) => h === n);
247
+ f !== -1 && c[o].splice(f, 1);
248
+ }
249
+ },
250
+ [e]
251
+ ), i = g(
252
+ (o, ...n) => {
253
+ const c = e.current;
254
+ Array.isArray(c[o]) && c[o].forEach((f) => f(...n));
255
+ },
256
+ [e]
257
+ ), r = g(() => {
258
+ e.current = {};
259
+ }, [e]);
260
+ return {
261
+ on: t,
262
+ off: s,
263
+ emit: i,
264
+ reset: r
265
+ };
266
+ }
267
+ function H() {
268
+ const { history: e } = Y(), { setHistory: t } = se(), s = g(
269
+ (a) => {
270
+ const { index: l, stack: u } = e;
271
+ u.forEach((d) => {
272
+ d.type === _.Source && (d.isSelected = !1);
273
+ }), a.type === _.Source ? a.isSelected = !0 : a.type === _.Edit && (a.source.isSelected = !0), u.splice(l + 1), u.push(a), t == null || t({
274
+ index: u.length - 1,
275
+ stack: u
276
+ });
277
+ },
278
+ [e, t]
279
+ ), i = g(() => {
280
+ const { stack: a } = e;
281
+ a.pop(), t == null || t({
282
+ index: a.length - 1,
283
+ stack: a
284
+ });
285
+ }, [e, t]), r = g(() => {
286
+ const { index: a, stack: l } = e, u = l[a];
287
+ u && (u.type === _.Source ? u.isSelected = !1 : u.type === _.Edit && u.source.editHistory.pop()), t == null || t({
288
+ index: a <= 0 ? -1 : a - 1,
289
+ stack: l
290
+ });
291
+ }, [e, t]), o = g(() => {
292
+ const { index: a, stack: l } = e, u = l[a + 1];
293
+ u && (u.type === _.Source ? u.isSelected = !1 : u.type === _.Edit && u.source.editHistory.push(u)), t == null || t({
294
+ index: a >= l.length - 1 ? l.length - 1 : a + 1,
295
+ stack: l
296
+ });
297
+ }, [e, t]), n = g(
298
+ (a) => {
299
+ t == null || t({ ...a });
300
+ },
301
+ [t]
302
+ ), c = g(
303
+ (a) => {
304
+ e.stack.forEach((l) => {
305
+ l.type === _.Source && (l === a ? l.isSelected = !0 : l.isSelected = !1);
306
+ }), t == null || t({ ...e });
307
+ },
308
+ [e, t]
309
+ ), f = g(() => {
310
+ e.stack.forEach((a) => {
311
+ a.type === _.Source && (a.isSelected = !1);
312
+ }), t == null || t({ ...e });
313
+ }, [e, t]), h = g(() => {
314
+ t == null || t({
315
+ index: -1,
316
+ stack: []
317
+ });
318
+ }, [t]);
319
+ return [
320
+ {
321
+ index: e.index,
322
+ stack: e.stack,
323
+ top: e.stack.slice(e.index, e.index + 1)[0]
324
+ },
325
+ {
326
+ push: s,
327
+ pop: i,
328
+ undo: r,
329
+ redo: o,
330
+ set: n,
331
+ select: c,
332
+ clearSelect: f,
333
+ reset: h
334
+ }
335
+ ];
336
+ }
337
+ function J() {
338
+ const { operation: e } = Y(), { setOperation: t } = se(), s = g(
339
+ (r) => {
340
+ t == null || t(r);
341
+ },
342
+ [t]
343
+ ), i = g(() => {
344
+ t == null || t(void 0);
345
+ }, [t]);
346
+ return [
347
+ e,
348
+ {
349
+ set: s,
350
+ reset: i
351
+ }
352
+ ];
353
+ }
354
+ function Xe({ x: e, y: t }, { x: s, y: i }, r, o, n, c) {
355
+ return e > s && ([e, s] = [s, e]), t > i && ([t, i] = [i, t]), e < 0 && (e = 0, c === "move" && (s = r.width)), s > o && (s = o, c === "move" && (e = s - r.width)), t < 0 && (t = 0, c === "move" && (i = r.height)), i > n && (i = n, c === "move" && (t = i - r.height)), {
356
+ x: e,
357
+ y: t,
358
+ width: Math.max(s - e, 1),
359
+ height: Math.max(i - t, 1)
360
+ };
361
+ }
362
+ function Ne(e, t, s, i) {
363
+ const r = e.clientX - s.x, o = e.clientY - s.y;
364
+ let n = i.x, c = i.y, f = i.x + i.width, h = i.y + i.height;
365
+ switch (t) {
366
+ case "top":
367
+ c += o;
368
+ break;
369
+ case "top-right":
370
+ f += r, c += o;
371
+ break;
372
+ case "right":
373
+ f += r;
374
+ break;
375
+ case "right-bottom":
376
+ f += r, h += o;
377
+ break;
378
+ case "bottom":
379
+ h += o;
380
+ break;
381
+ case "bottom-left":
382
+ n += r, h += o;
383
+ break;
384
+ case "left":
385
+ n += r;
386
+ break;
387
+ case "left-top":
388
+ n += r, c += o;
389
+ break;
390
+ case "move":
391
+ n += r, c += o, f += r, h += o;
392
+ break;
393
+ }
394
+ return [
395
+ {
396
+ x: n,
397
+ y: c
398
+ },
399
+ {
400
+ x: f,
401
+ y: h
402
+ }
403
+ ];
404
+ }
405
+ function Ye(e, t, s, i) {
406
+ if (!t)
407
+ return !1;
408
+ const r = document.createElement("canvas");
409
+ r.width = e.width, r.height = e.height;
410
+ const o = r.getContext("2d");
411
+ if (!o)
412
+ return !1;
413
+ const { left: n, top: c } = t.getBoundingClientRect(), f = i.clientX - n, h = i.clientY - c;
414
+ return [...s.stack.slice(0, s.index + 1)].reverse().find((l) => {
415
+ var u;
416
+ return l.type !== _.Source ? !1 : (o.clearRect(0, 0, e.width, e.height), (u = l.isHit) == null ? void 0 : u.call(l, o, l, { x: f, y: h }));
417
+ });
418
+ }
419
+ const Le = ["top", "right", "bottom", "left"], Te = [
420
+ "top",
421
+ "top-right",
422
+ "right",
423
+ "right-bottom",
424
+ "bottom",
425
+ "bottom-left",
426
+ "left",
427
+ "left-top"
428
+ /* ResizeLeftTop */
429
+ ], He = F(
430
+ Me(function(t, s) {
431
+ const { url: i, image: r, width: o, height: n } = Y(), c = Z(), [f] = H(), [h] = j(), [a, l] = K(), [u] = J(), d = E(), p = E(null), w = E(null), S = E(null), R = E(null), b = a && !f.stack.length && !u, M = g(() => {
432
+ if (!a || !R.current)
433
+ return;
434
+ const x = R.current;
435
+ x.imageSmoothingEnabled = !0, x.imageSmoothingQuality = "low", x.clearRect(0, 0, a.width, a.height), f.stack.slice(0, f.index + 1).forEach((C) => {
436
+ C.type === _.Source && C.draw(x, C);
437
+ });
438
+ }, [a, R, f]), v = g(
439
+ (x, C) => {
440
+ if (!(x.button !== 0 || !a))
441
+ if (!u)
442
+ d.current = C, p.current = {
443
+ x: x.clientX,
444
+ y: x.clientY
445
+ }, w.current = {
446
+ x: a.x,
447
+ y: a.y,
448
+ width: a.width,
449
+ height: a.height
450
+ };
451
+ else {
452
+ const z = Ye(
453
+ a,
454
+ S.current,
455
+ f,
456
+ x.nativeEvent
457
+ );
458
+ z ? c.emit("drawselect", z, x.nativeEvent) : c.emit("mousedown", x.nativeEvent);
459
+ }
460
+ },
461
+ [a, u, c, f]
462
+ ), m = g(
463
+ (x) => {
464
+ if (!d.current || !p.current || !w.current || !a)
465
+ return;
466
+ const C = Ne(
467
+ x,
468
+ d.current,
469
+ p.current,
470
+ w.current
471
+ );
472
+ l.set(
473
+ Xe(
474
+ C[0],
475
+ C[1],
476
+ a,
477
+ o,
478
+ n,
479
+ d.current
480
+ )
481
+ );
482
+ },
483
+ [o, n, a, l]
484
+ );
485
+ return Q(() => {
486
+ if (!r || !a || !S.current) {
487
+ R.current = null;
488
+ return;
489
+ }
490
+ R.current || (R.current = S.current.getContext("2d")), M();
491
+ }, [r, a, M]), T(() => {
492
+ const x = (z) => {
493
+ if (u)
494
+ c.emit("mousemove", z);
495
+ else {
496
+ if (!d.current || !p.current || !w.current)
497
+ return;
498
+ m(z);
499
+ }
500
+ }, C = (z) => {
501
+ if (u)
502
+ c.emit("mouseup", z);
503
+ else {
504
+ if (!d.current || !p.current || !w.current)
505
+ return;
506
+ m(z), d.current = void 0, p.current = null, w.current = null;
507
+ }
508
+ };
509
+ return window.addEventListener("mousemove", x), window.addEventListener("mouseup", C), () => {
510
+ window.removeEventListener("mousemove", x), window.removeEventListener("mouseup", C);
511
+ };
512
+ }, [m, u, c]), Be(s, () => R.current), /* @__PURE__ */ y.createElement(
513
+ "div",
514
+ {
515
+ className: "screenshots-canvas",
516
+ style: {
517
+ width: (a == null ? void 0 : a.width) || 0,
518
+ height: (a == null ? void 0 : a.height) || 0,
519
+ transform: a ? `translate(${a.x}px, ${a.y}px)` : "none"
520
+ }
521
+ },
522
+ /* @__PURE__ */ y.createElement("div", { className: "screenshots-canvas-body" }, /* @__PURE__ */ y.createElement(
523
+ "img",
524
+ {
525
+ className: "screenshots-canvas-image",
526
+ src: i,
527
+ style: {
528
+ width: o,
529
+ height: n,
530
+ transform: a ? `translate(${-a.x}px, ${-a.y}px)` : "none"
531
+ }
532
+ }
533
+ ), /* @__PURE__ */ y.createElement(
534
+ "canvas",
535
+ {
536
+ ref: S,
537
+ className: "screenshots-canvas-panel",
538
+ width: (a == null ? void 0 : a.width) || 0,
539
+ height: (a == null ? void 0 : a.height) || 0
540
+ }
541
+ )),
542
+ /* @__PURE__ */ y.createElement(
543
+ "div",
544
+ {
545
+ className: "screenshots-canvas-mask",
546
+ style: {
547
+ cursor: h
548
+ },
549
+ onMouseDown: (x) => v(x, "move")
550
+ },
551
+ b && /* @__PURE__ */ y.createElement("div", { className: "screenshots-canvas-size" }, a.width, " × ", a.height)
552
+ ),
553
+ Le.map((x) => /* @__PURE__ */ y.createElement(
554
+ "div",
555
+ {
556
+ key: x,
557
+ className: `screenshots-canvas-border-${x}`
558
+ }
559
+ )),
560
+ b && Te.map((x) => /* @__PURE__ */ y.createElement(
561
+ "div",
562
+ {
563
+ key: x,
564
+ className: `screenshots-canvas-point-${x}`,
565
+ onMouseDown: (C) => v(C, x)
566
+ }
567
+ ))
568
+ );
569
+ })
570
+ );
571
+ function ve() {
572
+ const e = se();
573
+ return g(
574
+ (s, ...i) => {
575
+ var r;
576
+ (r = e.call) == null || r.call(e, s, ...i);
577
+ },
578
+ [e]
579
+ );
580
+ }
581
+ function U() {
582
+ const { canvasContextRef: e } = Y();
583
+ return e;
584
+ }
585
+ function xe() {
586
+ const e = Z(), [, t] = K(), [, s] = j(), [, i] = H(), [, r] = J();
587
+ return g(() => {
588
+ e.reset(), i.reset(), t.reset(), s.reset(), r.reset();
589
+ }, [e, i, t, s, r]);
590
+ }
591
+ const Ae = F(function({ open: t, content: s, children: i }) {
592
+ const r = E(null), o = E(null), n = E(null), c = pe(Ee), [f, h] = $(
593
+ "bottom"
594
+ /* Bottom */
595
+ ), [a, l] = $(null), [u, d] = $(0), p = () => (o.current || (o.current = document.createElement("div")), o.current);
596
+ return T(() => {
597
+ const w = p();
598
+ return t && document.body.appendChild(w), () => {
599
+ w.remove();
600
+ };
601
+ }, [t]), T(() => {
602
+ if (!t || !c || !r.current || !n.current)
603
+ return;
604
+ const w = r.current.getBoundingClientRect(), S = n.current.getBoundingClientRect();
605
+ let R = f, b = w.left + w.width / 2, M = w.top + w.height, v = u;
606
+ if (b + S.width / 2 > c.x + c.width) {
607
+ const m = b;
608
+ b = c.x + c.width - S.width / 2, v = m - b;
609
+ }
610
+ if (b < c.x + S.width / 2) {
611
+ const m = b;
612
+ b = c.x + S.width / 2, v = m - b;
613
+ }
614
+ M > window.innerHeight - S.height && (R === "bottom" && (R = "top"), M = w.top - S.height), M < 0 && (R === "top" && (R = "bottom"), M = w.top + w.height), R !== f && h(R), ((a == null ? void 0 : a.x) !== b || a.y !== M) && l({
615
+ x: b,
616
+ y: M
617
+ }), v !== u && d(v);
618
+ }), /* @__PURE__ */ y.createElement(y.Fragment, null, $e(i, {
619
+ ref: r
620
+ }), t && s && we(
621
+ /* @__PURE__ */ y.createElement(
622
+ "div",
623
+ {
624
+ ref: n,
625
+ className: "screenshots-option",
626
+ style: {
627
+ visibility: a ? "visible" : "hidden",
628
+ transform: `translate(${(a == null ? void 0 : a.x) ?? 0}px, ${(a == null ? void 0 : a.y) ?? 0}px)`
629
+ },
630
+ "data-placement": f
631
+ },
632
+ /* @__PURE__ */ y.createElement("div", { className: "screenshots-option-container" }, s),
633
+ /* @__PURE__ */ y.createElement("div", { className: "screenshots-option-arrow", style: { marginLeft: u } })
634
+ ),
635
+ p()
636
+ ));
637
+ });
638
+ const A = F(function({
639
+ title: t,
640
+ icon: s,
641
+ checked: i,
642
+ disabled: r,
643
+ option: o,
644
+ onClick: n
645
+ }) {
646
+ const c = ["screenshots-button"], f = g(
647
+ (h) => {
648
+ r || !n || n(h);
649
+ },
650
+ [r, n]
651
+ );
652
+ return i && c.push("screenshots-button-checked"), r && c.push("screenshots-button-disabled"), /* @__PURE__ */ y.createElement(Ae, { open: i, content: o }, /* @__PURE__ */ y.createElement(
653
+ "div",
654
+ {
655
+ className: c.join(" "),
656
+ title: t,
657
+ onClick: f
658
+ },
659
+ /* @__PURE__ */ y.createElement("span", { className: s })
660
+ ));
661
+ });
662
+ function Ie() {
663
+ const { image: e, width: t, height: s, history: i, bounds: r, lang: o } = Y(), n = U(), [, c] = H(), f = ve(), h = xe(), a = g(() => {
664
+ c.clearSelect(), setTimeout(() => {
665
+ !n.current || !e || !r || fe({
666
+ image: e,
667
+ width: t,
668
+ height: s,
669
+ history: i,
670
+ bounds: r
671
+ }).then((l) => {
672
+ f("onOk", l, r), h();
673
+ });
674
+ });
675
+ }, [n, c, e, t, s, i, r, f, h]);
676
+ return /* @__PURE__ */ y.createElement(A, { title: o.operation_ok_title, icon: "icon-ok", onClick: a });
677
+ }
678
+ function We() {
679
+ const e = ve(), t = xe(), s = O(), i = g(() => {
680
+ e("onCancel"), t();
681
+ }, [e, t]);
682
+ return /* @__PURE__ */ y.createElement(A, { title: s.operation_cancel_title, icon: "icon-cancel", onClick: i });
683
+ }
684
+ function Fe() {
685
+ const { image: e, width: t, height: s, history: i, bounds: r, lang: o } = Y(), n = U(), [, c] = H(), f = ve(), h = xe(), a = g(() => {
686
+ c.clearSelect(), setTimeout(() => {
687
+ !n.current || !e || !r || fe({
688
+ image: e,
689
+ width: t,
690
+ height: s,
691
+ history: i,
692
+ bounds: r
693
+ }).then((l) => {
694
+ f("onSave", l, r), h();
695
+ });
696
+ });
697
+ }, [n, c, e, t, s, i, r, f, h]);
698
+ return /* @__PURE__ */ y.createElement(A, { title: o.operation_save_title, icon: "icon-save", onClick: a });
699
+ }
700
+ function Oe() {
701
+ const e = O(), [t, s] = H(), i = g(() => {
702
+ s.redo();
703
+ }, [s]);
704
+ return /* @__PURE__ */ y.createElement(
705
+ A,
706
+ {
707
+ title: e.operation_redo_title,
708
+ icon: "icon-redo",
709
+ disabled: !t.stack.length || t.stack.length - 1 === t.index,
710
+ onClick: i
711
+ }
712
+ );
713
+ }
714
+ function Ve() {
715
+ const e = O(), [t, s] = H(), i = g(() => {
716
+ s.undo();
717
+ }, [s]);
718
+ return /* @__PURE__ */ y.createElement(
719
+ A,
720
+ {
721
+ title: e.operation_undo_title,
722
+ icon: "icon-undo",
723
+ disabled: t.index === -1,
724
+ onClick: i
725
+ }
726
+ );
727
+ }
728
+ const Se = F(function({ value: t, onChange: s }) {
729
+ const i = [3, 6, 9];
730
+ return /* @__PURE__ */ y.createElement("div", { className: "screenshots-size" }, i.map((r) => {
731
+ const o = ["screenshots-size-item"];
732
+ return r === t && o.push("screenshots-size-active"), /* @__PURE__ */ y.createElement("div", { key: r, className: o.join(" "), onClick: () => s && s(r) }, /* @__PURE__ */ y.createElement(
733
+ "div",
734
+ {
735
+ className: "screenshots-size-pointer",
736
+ style: {
737
+ width: r * 1.8,
738
+ height: r * 1.8
739
+ }
740
+ }
741
+ ));
742
+ }));
743
+ });
744
+ function ee(e) {
745
+ const t = Z();
746
+ T(() => (t.on("mousedown", e), () => {
747
+ t.off("mousedown", e);
748
+ }), [e, t]);
749
+ }
750
+ function te(e) {
751
+ const t = Z();
752
+ T(() => (t.on("mousemove", e), () => {
753
+ t.off("mousemove", e);
754
+ }), [e, t]);
755
+ }
756
+ function ne(e) {
757
+ const t = Z();
758
+ T(() => (t.on("mouseup", e), () => {
759
+ t.off("mouseup", e);
760
+ }), [e, t]);
761
+ }
762
+ function le(e, t, s) {
763
+ if (!s)
764
+ return [0, 0, 0, 0];
765
+ const { data: i, width: r } = s, o = t * r * 4 + e * 4;
766
+ return Array.from(i.slice(o, o + 4));
767
+ }
768
+ function je(e, t) {
769
+ const { tiles: s, size: i } = t.data;
770
+ s.forEach((r) => {
771
+ const o = Math.round(r.color[0]), n = Math.round(r.color[1]), c = Math.round(r.color[2]), f = r.color[3] / 255;
772
+ e.fillStyle = `rgba(${o}, ${n}, ${c}, ${f})`, e.fillRect(r.x - i / 2, r.y - i / 2, i, i);
773
+ });
774
+ }
775
+ function Je() {
776
+ const e = O(), { image: t, width: s, height: i } = Y(), [r, o] = J(), n = U(), [c, f] = H(), [h] = K(), [, a] = j(), [l, u] = $(3), d = E(null), p = E(null), w = r === "Mosaic", S = g(() => {
777
+ o.set("Mosaic"), a.set("crosshair");
778
+ }, [o, a]), R = g(() => {
779
+ w || (S(), f.clearSelect());
780
+ }, [w, S, f]), b = g(
781
+ (m) => {
782
+ if (!w || p.current || !d.current || !n.current)
783
+ return;
784
+ const x = n.current.canvas.getBoundingClientRect(), C = m.clientX - x.x, z = m.clientY - x.y, B = l * 2;
785
+ p.current = {
786
+ name: "Mosaic",
787
+ type: _.Source,
788
+ data: {
789
+ size: B,
790
+ tiles: [
791
+ {
792
+ x: C,
793
+ y: z,
794
+ color: le(C, z, d.current)
795
+ }
796
+ ]
797
+ },
798
+ editHistory: [],
799
+ draw: je
800
+ };
801
+ },
802
+ [w, l, n]
803
+ ), M = g(
804
+ (m) => {
805
+ if (!w || !p.current || !n.current || !d.current)
806
+ return;
807
+ const x = n.current.canvas.getBoundingClientRect(), C = m.clientX - x.x, z = m.clientY - x.y, B = p.current.data.size, D = p.current.data.tiles;
808
+ let k = D[D.length - 1];
809
+ if (!k)
810
+ D.push({
811
+ x: C,
812
+ y: z,
813
+ color: le(C, z, d.current)
814
+ });
815
+ else {
816
+ const ae = k.x - C, P = k.y - z;
817
+ let L = Math.sqrt(ae ** 2 + P ** 2);
818
+ const de = -P / L, me = -ae / L;
819
+ for (; L > B; ) {
820
+ const re = Math.floor(k.x + B * me), oe = Math.floor(k.y + B * de);
821
+ k = {
822
+ x: re,
823
+ y: oe,
824
+ color: le(re, oe, d.current)
825
+ }, D.push(k), L -= B;
826
+ }
827
+ L > B / 2 && D.push({
828
+ x: C,
829
+ y: z,
830
+ color: le(C, z, d.current)
831
+ });
832
+ }
833
+ c.top !== p.current ? f.push(p.current) : f.set(c);
834
+ },
835
+ [w, n, c, f]
836
+ ), v = g(() => {
837
+ w && (p.current = null);
838
+ }, [w]);
839
+ return ee(b), te(M), ne(v), T(() => {
840
+ if (!h || !t || !w)
841
+ return;
842
+ const m = document.createElement("canvas"), x = m.getContext("2d");
843
+ if (!x)
844
+ return;
845
+ m.width = h.width, m.height = h.height;
846
+ const C = t.naturalWidth / s, z = t.naturalHeight / i;
847
+ x.drawImage(
848
+ t,
849
+ h.x * C,
850
+ h.y * z,
851
+ h.width * C,
852
+ h.height * z,
853
+ 0,
854
+ 0,
855
+ h.width,
856
+ h.height
857
+ ), d.current = x.getImageData(0, 0, h.width, h.height);
858
+ }, [s, i, h, t, w]), /* @__PURE__ */ y.createElement(
859
+ A,
860
+ {
861
+ title: e.operation_mosaic_title,
862
+ icon: "icon-mosaic",
863
+ checked: w,
864
+ onClick: R,
865
+ option: /* @__PURE__ */ y.createElement(Se, { value: l, onChange: u })
866
+ }
867
+ );
868
+ }
869
+ const Ue = F(function({ value: t, onChange: s }) {
870
+ const i = ["#ee5126", "#fceb4d", "#90e746", "#51c0fa", "#7a7a7a", "#ffffff"];
871
+ return /* @__PURE__ */ y.createElement("div", { className: "screenshots-color" }, i.map((r) => {
872
+ const o = ["screenshots-color-item"];
873
+ return r === t && o.push("screenshots-color-active"), /* @__PURE__ */ y.createElement(
874
+ "div",
875
+ {
876
+ key: r,
877
+ className: o.join(" "),
878
+ style: { backgroundColor: r },
879
+ onClick: () => s && s(r)
880
+ }
881
+ );
882
+ }));
883
+ });
884
+ const ce = F(function({
885
+ size: t,
886
+ color: s,
887
+ onSizeChange: i,
888
+ onColorChange: r
889
+ }) {
890
+ return /* @__PURE__ */ y.createElement("div", { className: "screenshots-sizecolor" }, /* @__PURE__ */ y.createElement(Se, { value: t, onChange: i }), /* @__PURE__ */ y.createElement(Ue, { value: s, onChange: r }));
891
+ }), qe = `
892
+ min-width: 0 !important;
893
+ width: 0 !important;
894
+ min-height: 0 !important;
895
+ height:0 !important;
896
+ visibility: hidden !important;
897
+ overflow: hidden !important;
898
+ position: absolute !important;
899
+ z-index: -1000 !important;
900
+ top:0 !important;
901
+ right:0 !important;
902
+ `, Ge = [
903
+ "letter-spacing",
904
+ "line-height",
905
+ "padding-top",
906
+ "padding-bottom",
907
+ "font-family",
908
+ "font-weight",
909
+ "font-size",
910
+ "font-variant",
911
+ "text-rendering",
912
+ "text-transform",
913
+ "text-indent",
914
+ "padding-left",
915
+ "padding-right",
916
+ "border-width",
917
+ "box-sizing",
918
+ "white-space",
919
+ "word-break"
920
+ ];
921
+ let V;
922
+ function Qe(e) {
923
+ const t = window.getComputedStyle(e), s = t.getPropertyValue("box-sizing") || t.getPropertyValue("-moz-box-sizing") || t.getPropertyValue("-webkit-box-sizing"), i = parseFloat(t.getPropertyValue("padding-bottom")) + parseFloat(t.getPropertyValue("padding-top")), r = parseFloat(t.getPropertyValue("border-bottom-width")) + parseFloat(t.getPropertyValue("border-top-width"));
924
+ return {
925
+ sizingStyle: Ge.map((n) => `${n}:${t.getPropertyValue(n)}`).join(";"),
926
+ paddingSize: i,
927
+ borderSize: r,
928
+ boxSizing: s
929
+ };
930
+ }
931
+ function Ke(e, t, s, i) {
932
+ V || (V = document.createElement("textarea"), V.setAttribute("tab-index", "-1"), document.body.appendChild(V));
933
+ const { paddingSize: r, borderSize: o, boxSizing: n, sizingStyle: c } = Qe(e);
934
+ V.setAttribute(
935
+ "style",
936
+ `${c};${qe};max-width:${s}px;max-height:${i}px`
937
+ ), V.value = t || " ";
938
+ let f = V.scrollWidth, h = V.scrollHeight;
939
+ return n === "border-box" ? (f += o, h += o) : n === "content-box" && (f -= r, h -= r), {
940
+ width: Math.min(f, s),
941
+ height: Math.min(h, i)
942
+ };
943
+ }
944
+ const Ze = F(function({
945
+ x: t,
946
+ y: s,
947
+ maxWidth: i,
948
+ maxHeight: r,
949
+ size: o,
950
+ color: n,
951
+ value: c,
952
+ onChange: f,
953
+ onBlur: h
954
+ }) {
955
+ const a = E(null), l = E(null), [u, d] = $(0), [p, w] = $(0), S = () => (a.current || (a.current = document.createElement("div")), a.current);
956
+ return Q(() => (a.current && (document.body.appendChild(a.current), requestAnimationFrame(() => {
957
+ var R;
958
+ (R = l.current) == null || R.focus();
959
+ })), () => {
960
+ var R;
961
+ (R = a.current) == null || R.remove();
962
+ }), []), Q(() => {
963
+ if (!l.current)
964
+ return;
965
+ const { width: R, height: b } = Ke(l.current, c, i, r);
966
+ d(R), w(b);
967
+ }, [c, i, r]), we(
968
+ /* @__PURE__ */ y.createElement(
969
+ "textarea",
970
+ {
971
+ ref: l,
972
+ className: "screenshots-textarea",
973
+ style: {
974
+ color: n,
975
+ width: u,
976
+ height: p,
977
+ maxWidth: i,
978
+ maxHeight: r,
979
+ fontSize: o,
980
+ lineHeight: `${o}px`,
981
+ transform: `translate(${t}px, ${s}px)`
982
+ },
983
+ value: c,
984
+ onChange: (R) => f && f(R.target.value),
985
+ onBlur: (R) => h && h(R)
986
+ }
987
+ ),
988
+ S()
989
+ );
990
+ });
991
+ function ie(e) {
992
+ const t = Z();
993
+ T(() => (t.on("drawselect", e), () => {
994
+ t.off("drawselect", e);
995
+ }), [e, t]);
996
+ }
997
+ const ge = {
998
+ 3: 18,
999
+ 6: 32,
1000
+ 9: 46
1001
+ };
1002
+ function et(e, t) {
1003
+ const { size: s, color: i, fontFamily: r, x: o, y: n, text: c } = t.data;
1004
+ e.fillStyle = i, e.textAlign = "left", e.textBaseline = "top", e.font = `${s}px ${r}`;
1005
+ const f = t.editHistory.reduce(
1006
+ (h, { data: a }) => ({
1007
+ x: h.x + a.x2 - a.x1,
1008
+ y: h.y + a.y2 - a.y1
1009
+ }),
1010
+ { x: 0, y: 0 }
1011
+ );
1012
+ c.split(`
1013
+ `).forEach((h, a) => {
1014
+ e.fillText(h, o + f.x, n + f.y + a * s);
1015
+ });
1016
+ }
1017
+ function tt(e, t, s) {
1018
+ e.textAlign = "left", e.textBaseline = "top", e.font = `${t.data.size}px ${t.data.fontFamily}`;
1019
+ let i = 0, r = 0;
1020
+ t.data.text.split(`
1021
+ `).forEach((l) => {
1022
+ const u = e.measureText(l);
1023
+ i < u.width && (i = u.width), r += t.data.size;
1024
+ });
1025
+ const { x: o, y: n } = t.editHistory.reduce(
1026
+ (l, { data: u }) => ({
1027
+ x: l.x + u.x2 - u.x1,
1028
+ y: l.y + u.y2 - u.y1
1029
+ }),
1030
+ { x: 0, y: 0 }
1031
+ ), c = t.data.x + o, f = t.data.y + n, h = c + i, a = f + r;
1032
+ return s.x >= c && s.x <= h && s.y >= f && s.y <= a;
1033
+ }
1034
+ function nt() {
1035
+ const e = O(), [t, s] = H(), [i] = K(), [r, o] = J(), [, n] = j(), c = U(), [f, h] = $(3), [a, l] = $("#ee5126"), u = E(
1036
+ null
1037
+ ), d = E(
1038
+ null
1039
+ ), [p, w] = $(
1040
+ null
1041
+ ), [S, R] = $(""), b = r === "Text", M = g(() => {
1042
+ o.set("Text"), n.set("default");
1043
+ }, [o, n]), v = g(() => {
1044
+ b || (M(), s.clearSelect());
1045
+ }, [b, M, s]), m = g((P) => {
1046
+ u.current && (u.current.data.size = ge[P]), h(P);
1047
+ }, []), x = g((P) => {
1048
+ u.current && (u.current.data.color = P), l(P);
1049
+ }, []), C = g(
1050
+ (P) => {
1051
+ R(P), b && u.current && (u.current.data.text = P);
1052
+ },
1053
+ [b]
1054
+ ), z = g(() => {
1055
+ u.current && u.current.data.text && s.push(u.current), u.current = null, R(""), w(null);
1056
+ }, [s]), B = g(
1057
+ (P, L) => {
1058
+ P.name === "Text" && (M(), d.current = {
1059
+ type: _.Edit,
1060
+ data: {
1061
+ x1: L.clientX,
1062
+ y1: L.clientY,
1063
+ x2: L.clientX,
1064
+ y2: L.clientY
1065
+ },
1066
+ source: P
1067
+ }, s.select(P));
1068
+ },
1069
+ [M, s]
1070
+ ), D = g(
1071
+ (P) => {
1072
+ if (!b || !c.current || u.current || !i)
1073
+ return;
1074
+ const { left: L, top: de } = c.current.canvas.getBoundingClientRect(), me = window.getComputedStyle(
1075
+ c.current.canvas
1076
+ ).fontFamily, re = P.clientX - L, oe = P.clientY - de;
1077
+ u.current = {
1078
+ name: "Text",
1079
+ type: _.Source,
1080
+ data: {
1081
+ size: ge[f],
1082
+ color: a,
1083
+ fontFamily: me,
1084
+ x: re,
1085
+ y: oe,
1086
+ text: ""
1087
+ },
1088
+ editHistory: [],
1089
+ draw: et,
1090
+ isHit: tt
1091
+ }, w({
1092
+ x: P.clientX,
1093
+ y: P.clientY,
1094
+ maxWidth: i.width - re,
1095
+ maxHeight: i.height - oe
1096
+ });
1097
+ },
1098
+ [b, f, a, i, c]
1099
+ ), k = g(
1100
+ (P) => {
1101
+ b && d.current && (d.current.data.x2 = P.clientX, d.current.data.y2 = P.clientY, t.top !== d.current ? (d.current.source.editHistory.push(d.current), s.push(d.current)) : s.set(t));
1102
+ },
1103
+ [b, t, s]
1104
+ ), ae = g(() => {
1105
+ b && (d.current = null);
1106
+ }, [b]);
1107
+ return ie(B), ee(D), te(k), ne(ae), /* @__PURE__ */ y.createElement(y.Fragment, null, /* @__PURE__ */ y.createElement(
1108
+ A,
1109
+ {
1110
+ title: e.operation_text_title,
1111
+ icon: "icon-text",
1112
+ checked: b,
1113
+ onClick: v,
1114
+ option: /* @__PURE__ */ y.createElement(
1115
+ ce,
1116
+ {
1117
+ size: f,
1118
+ color: a,
1119
+ onSizeChange: m,
1120
+ onColorChange: x
1121
+ }
1122
+ )
1123
+ }
1124
+ ), b && p && /* @__PURE__ */ y.createElement(
1125
+ Ze,
1126
+ {
1127
+ x: p.x,
1128
+ y: p.y,
1129
+ maxWidth: p.maxWidth,
1130
+ maxHeight: p.maxHeight,
1131
+ size: ge[f],
1132
+ color: a,
1133
+ value: S,
1134
+ onChange: C,
1135
+ onBlur: z
1136
+ }
1137
+ ));
1138
+ }
1139
+ const Ce = 4;
1140
+ function X(e, t, s) {
1141
+ e.lineWidth = 1, e.strokeStyle = "#000000", e.fillStyle = "#ffffff", e.beginPath(), e.arc(t, s, Ce, 0, 2 * Math.PI), e.fill(), e.stroke();
1142
+ }
1143
+ function he(e, t, s) {
1144
+ t.draw(e, t);
1145
+ const { data: i } = e.getImageData(s.x, s.y, 1, 1);
1146
+ return i.some((r) => r !== 0);
1147
+ }
1148
+ function N(e, t, s) {
1149
+ if (!e)
1150
+ return !1;
1151
+ const { left: i, top: r } = e.getBoundingClientRect(), o = t.clientX - i, n = t.clientY - r;
1152
+ return (s.x - o) ** 2 + (s.y - n) ** 2 < Ce ** 2;
1153
+ }
1154
+ function rt(e, t) {
1155
+ const { size: s, color: i, points: r } = t.data;
1156
+ e.lineCap = "round", e.lineJoin = "round", e.lineWidth = s, e.strokeStyle = i;
1157
+ const o = t.editHistory.reduce(
1158
+ (n, { data: c }) => ({
1159
+ x: n.x + c.x2 - c.x1,
1160
+ y: n.y + c.y2 - c.y1
1161
+ }),
1162
+ { x: 0, y: 0 }
1163
+ );
1164
+ e.beginPath(), r.forEach((n, c) => {
1165
+ c === 0 ? e.moveTo(n.x + o.x, n.y + o.y) : e.lineTo(n.x + o.x, n.y + o.y);
1166
+ }), e.stroke(), t.isSelected && (e.lineWidth = 1, e.strokeStyle = "#000000", e.beginPath(), r.forEach((n, c) => {
1167
+ c === 0 ? e.moveTo(n.x + o.x, n.y + o.y) : e.lineTo(n.x + o.x, n.y + o.y);
1168
+ }), e.stroke());
1169
+ }
1170
+ function ot() {
1171
+ const e = O(), [, t] = j(), [s, i] = J(), r = U(), [o, n] = H(), [c, f] = $(3), [h, a] = $("#ee5126"), l = E(null), u = E(null), d = s === "Brush", p = g(() => {
1172
+ i.set("Brush"), t.set("default");
1173
+ }, [i, t]), w = g(() => {
1174
+ d || (p(), n.clearSelect());
1175
+ }, [d, p, n]), S = g(
1176
+ (v, m) => {
1177
+ v.name === "Brush" && (p(), u.current = {
1178
+ type: _.Edit,
1179
+ data: {
1180
+ x1: m.clientX,
1181
+ y1: m.clientY,
1182
+ x2: m.clientX,
1183
+ y2: m.clientY
1184
+ },
1185
+ source: v
1186
+ }, n.select(v));
1187
+ },
1188
+ [p, n]
1189
+ ), R = g(
1190
+ (v) => {
1191
+ if (!d || l.current || !r.current)
1192
+ return;
1193
+ const { left: m, top: x } = r.current.canvas.getBoundingClientRect();
1194
+ l.current = {
1195
+ name: "Brush",
1196
+ type: _.Source,
1197
+ data: {
1198
+ size: c,
1199
+ color: h,
1200
+ points: [
1201
+ {
1202
+ x: v.clientX - m,
1203
+ y: v.clientY - x
1204
+ }
1205
+ ]
1206
+ },
1207
+ editHistory: [],
1208
+ draw: rt,
1209
+ isHit: he
1210
+ };
1211
+ },
1212
+ [d, r, c, h]
1213
+ ), b = g(
1214
+ (v) => {
1215
+ if (!(!d || !r.current)) {
1216
+ if (u.current)
1217
+ u.current.data.x2 = v.clientX, u.current.data.y2 = v.clientY, o.top !== u.current ? (u.current.source.editHistory.push(u.current), n.push(u.current)) : n.set(o);
1218
+ else if (l.current) {
1219
+ const { left: m, top: x } = r.current.canvas.getBoundingClientRect();
1220
+ l.current.data.points.push({
1221
+ x: v.clientX - m,
1222
+ y: v.clientY - x
1223
+ }), o.top !== l.current ? n.push(l.current) : n.set(o);
1224
+ }
1225
+ }
1226
+ },
1227
+ [d, o, r, n]
1228
+ ), M = g(() => {
1229
+ d && (l.current && n.clearSelect(), l.current = null, u.current = null);
1230
+ }, [d, n]);
1231
+ return ie(S), ee(R), te(b), ne(M), /* @__PURE__ */ y.createElement(
1232
+ A,
1233
+ {
1234
+ title: e.operation_brush_title,
1235
+ icon: "icon-brush",
1236
+ checked: d,
1237
+ onClick: w,
1238
+ option: /* @__PURE__ */ y.createElement(ce, { size: c, color: h, onSizeChange: f, onColorChange: a })
1239
+ }
1240
+ );
1241
+ }
1242
+ function ze(e) {
1243
+ let { x1: t, y1: s, x2: i, y2: r } = e.data;
1244
+ return e.editHistory.forEach(({ data: o }) => {
1245
+ const n = o.x2 - o.x1, c = o.y2 - o.y1;
1246
+ o.type === ue.Move ? (t += n, s += c, i += n, r += c) : o.type === ue.MoveStart ? (t += n, s += c) : o.type === ue.MoveEnd && (i += n, r += c);
1247
+ }), {
1248
+ ...e.data,
1249
+ x1: t,
1250
+ x2: i,
1251
+ y1: s,
1252
+ y2: r
1253
+ };
1254
+ }
1255
+ function st(e, t) {
1256
+ const { size: s, color: i, x1: r, x2: o, y1: n, y2: c } = ze(t);
1257
+ e.lineCap = "round", e.lineJoin = "bevel", e.lineWidth = s, e.strokeStyle = i;
1258
+ const f = o - r, h = c - n, a = s * 3, l = Math.atan2(h, f);
1259
+ e.beginPath(), e.moveTo(r, n), e.lineTo(o, c), e.lineTo(o - a * Math.cos(l - Math.PI / 6), c - a * Math.sin(l - Math.PI / 6)), e.moveTo(o, c), e.lineTo(o - a * Math.cos(l + Math.PI / 6), c - a * Math.sin(l + Math.PI / 6)), e.stroke(), t.isSelected && (X(e, r, n), X(e, o, c));
1260
+ }
1261
+ var ue = /* @__PURE__ */ ((e) => (e[e.Move = 0] = "Move", e[e.MoveStart = 1] = "MoveStart", e[e.MoveEnd = 2] = "MoveEnd", e))(ue || {});
1262
+ function ct() {
1263
+ const e = O(), [, t] = j(), [s, i] = J(), [r, o] = H(), n = U(), [c, f] = $(3), [h, a] = $("#ee5126"), l = E(null), u = E(null), d = s === "Arrow", p = g(() => {
1264
+ i.set("Arrow"), t.set("default");
1265
+ }, [i, t]), w = g(() => {
1266
+ d || (p(), o.clearSelect());
1267
+ }, [d, p, o]), S = g(
1268
+ (v, m) => {
1269
+ if (v.name !== "Arrow" || !n.current)
1270
+ return;
1271
+ const x = v;
1272
+ p();
1273
+ const { x1: C, y1: z, x2: B, y2: D } = ze(x);
1274
+ let k = 0;
1275
+ N(n.current.canvas, m, {
1276
+ x: C,
1277
+ y: z
1278
+ }) ? k = 1 : N(n.current.canvas, m, {
1279
+ x: B,
1280
+ y: D
1281
+ }) && (k = 2), u.current = {
1282
+ type: _.Edit,
1283
+ data: {
1284
+ type: k,
1285
+ x1: m.clientX,
1286
+ y1: m.clientY,
1287
+ x2: m.clientX,
1288
+ y2: m.clientY
1289
+ },
1290
+ source: x
1291
+ }, o.select(v);
1292
+ },
1293
+ [n, p, o]
1294
+ ), R = g(
1295
+ (v) => {
1296
+ if (!d || l.current || !n.current)
1297
+ return;
1298
+ const { left: m, top: x } = n.current.canvas.getBoundingClientRect();
1299
+ l.current = {
1300
+ name: "Arrow",
1301
+ type: _.Source,
1302
+ data: {
1303
+ size: c,
1304
+ color: h,
1305
+ x1: v.clientX - m,
1306
+ y1: v.clientY - x,
1307
+ x2: v.clientX - m,
1308
+ y2: v.clientY - x
1309
+ },
1310
+ editHistory: [],
1311
+ draw: st,
1312
+ isHit: he
1313
+ };
1314
+ },
1315
+ [d, h, c, n]
1316
+ ), b = g(
1317
+ (v) => {
1318
+ if (!(!d || !n.current)) {
1319
+ if (u.current)
1320
+ u.current.data.x2 = v.clientX, u.current.data.y2 = v.clientY, r.top !== u.current ? (u.current.source.editHistory.push(u.current), o.push(u.current)) : o.set(r);
1321
+ else if (l.current) {
1322
+ const { left: m, top: x } = n.current.canvas.getBoundingClientRect();
1323
+ l.current.data.x2 = v.clientX - m, l.current.data.y2 = v.clientY - x, r.top !== l.current ? o.push(l.current) : o.set(r);
1324
+ }
1325
+ }
1326
+ },
1327
+ [d, r, n, o]
1328
+ ), M = g(() => {
1329
+ d && (l.current && o.clearSelect(), l.current = null, u.current = null);
1330
+ }, [d, o]);
1331
+ return ie(S), ee(R), te(b), ne(M), /* @__PURE__ */ y.createElement(
1332
+ A,
1333
+ {
1334
+ title: e.operation_arrow_title,
1335
+ icon: "icon-arrow",
1336
+ checked: d,
1337
+ onClick: w,
1338
+ option: /* @__PURE__ */ y.createElement(ce, { size: c, color: h, onSizeChange: f, onColorChange: a })
1339
+ }
1340
+ );
1341
+ }
1342
+ function be(e) {
1343
+ let { x1: t, y1: s, x2: i, y2: r } = e.data;
1344
+ return e.editHistory.forEach(({ data: o }) => {
1345
+ const n = o.x2 - o.x1, c = o.y2 - o.y1;
1346
+ o.type === I.Move ? (t += n, s += c, i += n, r += c) : o.type === I.ResizeTop ? s += c : o.type === I.ResizeRightTop ? (i += n, s += c) : o.type === I.ResizeRight ? i += n : o.type === I.ResizeRightBottom ? (i += n, r += c) : o.type === I.ResizeBottom ? r += c : o.type === I.ResizeLeftBottom ? (t += n, r += c) : o.type === I.ResizeLeft ? t += n : o.type === I.ResizeLeftTop && (t += n, s += c);
1347
+ }), {
1348
+ ...e.data,
1349
+ x1: t,
1350
+ x2: i,
1351
+ y1: s,
1352
+ y2: r
1353
+ };
1354
+ }
1355
+ function it(e, t) {
1356
+ const { size: s, color: i, x1: r, y1: o, x2: n, y2: c } = be(t);
1357
+ e.lineCap = "butt", e.lineJoin = "miter", e.lineWidth = s, e.strokeStyle = i;
1358
+ const f = (r + n) / 2, h = (o + c) / 2, a = Math.abs(n - r) / 2, l = Math.abs(c - o) / 2, u = 0.5522848, d = a * u, p = l * u;
1359
+ e.beginPath(), e.moveTo(f - a, h), e.bezierCurveTo(f - a, h - p, f - d, h - l, f, h - l), e.bezierCurveTo(f + d, h - l, f + a, h - p, f + a, h), e.bezierCurveTo(f + a, h + p, f + d, h + l, f, h + l), e.bezierCurveTo(f - d, h + l, f - a, h + p, f - a, h), e.closePath(), e.stroke(), t.isSelected && (e.lineWidth = 1, e.strokeStyle = "#000000", e.fillStyle = "#ffffff", e.beginPath(), e.moveTo(r, o), e.lineTo(n, o), e.lineTo(n, c), e.lineTo(r, c), e.closePath(), e.stroke(), X(e, (r + n) / 2, o), X(e, n, o), X(e, n, (o + c) / 2), X(e, n, c), X(e, (r + n) / 2, c), X(e, r, c), X(e, r, (o + c) / 2), X(e, r, o));
1360
+ }
1361
+ var I = /* @__PURE__ */ ((e) => (e[e.Move = 0] = "Move", e[e.ResizeTop = 1] = "ResizeTop", e[e.ResizeRightTop = 2] = "ResizeRightTop", e[e.ResizeRight = 3] = "ResizeRight", e[e.ResizeRightBottom = 4] = "ResizeRightBottom", e[e.ResizeBottom = 5] = "ResizeBottom", e[e.ResizeLeftBottom = 6] = "ResizeLeftBottom", e[e.ResizeLeft = 7] = "ResizeLeft", e[e.ResizeLeftTop = 8] = "ResizeLeftTop", e))(I || {});
1362
+ function at() {
1363
+ const e = O(), [t, s] = H(), [i, r] = J(), [, o] = j(), n = U(), [c, f] = $(3), [h, a] = $("#ee5126"), l = E(null), u = E(null), d = i === "Ellipse", p = g(() => {
1364
+ r.set("Ellipse"), o.set("crosshair");
1365
+ }, [r, o]), w = g(() => {
1366
+ d || (p(), s.clearSelect());
1367
+ }, [d, p, s]), S = g(
1368
+ (v, m) => {
1369
+ if (v.name !== "Ellipse" || !n.current)
1370
+ return;
1371
+ const x = v;
1372
+ p();
1373
+ const { x1: C, y1: z, x2: B, y2: D } = be(x);
1374
+ let k = 0;
1375
+ N(n.current.canvas, m, {
1376
+ x: (C + B) / 2,
1377
+ y: z
1378
+ }) ? k = 1 : N(n.current.canvas, m, {
1379
+ x: B,
1380
+ y: z
1381
+ }) ? k = 2 : N(n.current.canvas, m, {
1382
+ x: B,
1383
+ y: (z + D) / 2
1384
+ }) ? k = 3 : N(n.current.canvas, m, {
1385
+ x: B,
1386
+ y: D
1387
+ }) ? k = 4 : N(n.current.canvas, m, {
1388
+ x: (C + B) / 2,
1389
+ y: D
1390
+ }) ? k = 5 : N(n.current.canvas, m, {
1391
+ x: C,
1392
+ y: D
1393
+ }) ? k = 6 : N(n.current.canvas, m, {
1394
+ x: C,
1395
+ y: (z + D) / 2
1396
+ }) ? k = 7 : N(n.current.canvas, m, {
1397
+ x: C,
1398
+ y: z
1399
+ }) && (k = 8), u.current = {
1400
+ type: _.Edit,
1401
+ data: {
1402
+ type: k,
1403
+ x1: m.clientX,
1404
+ y1: m.clientY,
1405
+ x2: m.clientX,
1406
+ y2: m.clientY
1407
+ },
1408
+ source: x
1409
+ }, s.select(v);
1410
+ },
1411
+ [n, p, s]
1412
+ ), R = g(
1413
+ (v) => {
1414
+ if (!d || !n.current || l.current)
1415
+ return;
1416
+ const { left: m, top: x } = n.current.canvas.getBoundingClientRect(), C = v.clientX - m, z = v.clientY - x;
1417
+ l.current = {
1418
+ name: "Ellipse",
1419
+ type: _.Source,
1420
+ data: {
1421
+ size: c,
1422
+ color: h,
1423
+ x1: C,
1424
+ y1: z,
1425
+ x2: C,
1426
+ y2: z
1427
+ },
1428
+ editHistory: [],
1429
+ draw: it,
1430
+ isHit: he
1431
+ };
1432
+ },
1433
+ [d, c, h, n]
1434
+ ), b = g(
1435
+ (v) => {
1436
+ if (!(!d || !n.current)) {
1437
+ if (u.current)
1438
+ u.current.data.x2 = v.clientX, u.current.data.y2 = v.clientY, t.top !== u.current ? (u.current.source.editHistory.push(u.current), s.push(u.current)) : s.set(t);
1439
+ else if (l.current) {
1440
+ const { left: m, top: x } = n.current.canvas.getBoundingClientRect();
1441
+ l.current.data.x2 = v.clientX - m, l.current.data.y2 = v.clientY - x, t.top !== l.current ? s.push(l.current) : s.set(t);
1442
+ }
1443
+ }
1444
+ },
1445
+ [d, n, t, s]
1446
+ ), M = g(() => {
1447
+ d && (l.current && s.clearSelect(), l.current = null, u.current = null);
1448
+ }, [d, s]);
1449
+ return ie(S), ee(R), te(b), ne(M), /* @__PURE__ */ y.createElement(
1450
+ A,
1451
+ {
1452
+ title: e.operation_ellipse_title,
1453
+ icon: "icon-ellipse",
1454
+ checked: d,
1455
+ onClick: w,
1456
+ option: /* @__PURE__ */ y.createElement(ce, { size: c, color: h, onSizeChange: f, onColorChange: a })
1457
+ }
1458
+ );
1459
+ }
1460
+ function ke(e) {
1461
+ let { x1: t, y1: s, x2: i, y2: r } = e.data;
1462
+ return e.editHistory.forEach(({ data: o }) => {
1463
+ const n = o.x2 - o.x1, c = o.y2 - o.y1;
1464
+ o.type === W.Move ? (t += n, s += c, i += n, r += c) : o.type === W.ResizeTop ? s += c : o.type === W.ResizeRightTop ? (i += n, s += c) : o.type === W.ResizeRight ? i += n : o.type === W.ResizeRightBottom ? (i += n, r += c) : o.type === W.ResizeBottom ? r += c : o.type === W.ResizeLeftBottom ? (t += n, r += c) : o.type === W.ResizeLeft ? t += n : o.type === W.ResizeLeftTop && (t += n, s += c);
1465
+ }), {
1466
+ ...e.data,
1467
+ x1: t,
1468
+ x2: i,
1469
+ y1: s,
1470
+ y2: r
1471
+ };
1472
+ }
1473
+ function lt(e, t) {
1474
+ const { size: s, color: i, x1: r, y1: o, x2: n, y2: c } = ke(t);
1475
+ e.lineCap = "butt", e.lineJoin = "miter", e.lineWidth = s, e.strokeStyle = i, e.beginPath(), e.moveTo(r, o), e.lineTo(n, o), e.lineTo(n, c), e.lineTo(r, c), e.closePath(), e.stroke(), t.isSelected && (e.lineWidth = 1, e.strokeStyle = "#000000", e.fillStyle = "#ffffff", X(e, (r + n) / 2, o), X(e, n, o), X(e, n, (o + c) / 2), X(e, n, c), X(e, (r + n) / 2, c), X(e, r, c), X(e, r, (o + c) / 2), X(e, r, o));
1476
+ }
1477
+ var W = /* @__PURE__ */ ((e) => (e[e.Move = 0] = "Move", e[e.ResizeTop = 1] = "ResizeTop", e[e.ResizeRightTop = 2] = "ResizeRightTop", e[e.ResizeRight = 3] = "ResizeRight", e[e.ResizeRightBottom = 4] = "ResizeRightBottom", e[e.ResizeBottom = 5] = "ResizeBottom", e[e.ResizeLeftBottom = 6] = "ResizeLeftBottom", e[e.ResizeLeft = 7] = "ResizeLeft", e[e.ResizeLeftTop = 8] = "ResizeLeftTop", e))(W || {});
1478
+ function ut() {
1479
+ const e = O(), [t, s] = H(), [i, r] = J(), [, o] = j(), n = U(), [c, f] = $(3), [h, a] = $("#ee5126"), l = E(null), u = E(null), d = i === "Rectangle", p = g(() => {
1480
+ r.set("Rectangle"), o.set("crosshair");
1481
+ }, [r, o]), w = g(() => {
1482
+ d || (p(), s.clearSelect());
1483
+ }, [d, p, s]), S = g(
1484
+ (v, m) => {
1485
+ if (v.name !== "Rectangle" || !n.current)
1486
+ return;
1487
+ const x = v;
1488
+ p();
1489
+ const { x1: C, y1: z, x2: B, y2: D } = ke(x);
1490
+ let k = 0;
1491
+ N(n.current.canvas, m, {
1492
+ x: (C + B) / 2,
1493
+ y: z
1494
+ }) ? k = 1 : N(n.current.canvas, m, {
1495
+ x: B,
1496
+ y: z
1497
+ }) ? k = 2 : N(n.current.canvas, m, {
1498
+ x: B,
1499
+ y: (z + D) / 2
1500
+ }) ? k = 3 : N(n.current.canvas, m, {
1501
+ x: B,
1502
+ y: D
1503
+ }) ? k = 4 : N(n.current.canvas, m, {
1504
+ x: (C + B) / 2,
1505
+ y: D
1506
+ }) ? k = 5 : N(n.current.canvas, m, {
1507
+ x: C,
1508
+ y: D
1509
+ }) ? k = 6 : N(n.current.canvas, m, {
1510
+ x: C,
1511
+ y: (z + D) / 2
1512
+ }) ? k = 7 : N(n.current.canvas, m, {
1513
+ x: C,
1514
+ y: z
1515
+ }) && (k = 8), u.current = {
1516
+ type: _.Edit,
1517
+ data: {
1518
+ type: k,
1519
+ x1: m.clientX,
1520
+ y1: m.clientY,
1521
+ x2: m.clientX,
1522
+ y2: m.clientY
1523
+ },
1524
+ source: v
1525
+ }, s.select(v);
1526
+ },
1527
+ [n, p, s]
1528
+ ), R = g(
1529
+ (v) => {
1530
+ if (!d || !n.current || l.current)
1531
+ return;
1532
+ const { left: m, top: x } = n.current.canvas.getBoundingClientRect(), C = v.clientX - m, z = v.clientY - x;
1533
+ l.current = {
1534
+ name: "Rectangle",
1535
+ type: _.Source,
1536
+ data: {
1537
+ size: c,
1538
+ color: h,
1539
+ x1: C,
1540
+ y1: z,
1541
+ x2: C,
1542
+ y2: z
1543
+ },
1544
+ editHistory: [],
1545
+ draw: lt,
1546
+ isHit: he
1547
+ };
1548
+ },
1549
+ [d, c, h, n]
1550
+ ), b = g(
1551
+ (v) => {
1552
+ if (!(!d || !n.current)) {
1553
+ if (u.current)
1554
+ u.current.data.x2 = v.clientX, u.current.data.y2 = v.clientY, t.top !== u.current ? (u.current.source.editHistory.push(u.current), s.push(u.current)) : s.set(t);
1555
+ else if (l.current) {
1556
+ const { left: m, top: x } = n.current.canvas.getBoundingClientRect(), C = l.current.data;
1557
+ C.x2 = v.clientX - m, C.y2 = v.clientY - x, t.top !== l.current ? s.push(l.current) : s.set(t);
1558
+ }
1559
+ }
1560
+ },
1561
+ [d, n, t, s]
1562
+ ), M = g(() => {
1563
+ d && (l.current && s.clearSelect(), l.current = null, u.current = null);
1564
+ }, [d, s]);
1565
+ return ie(S), ee(R), te(b), ne(M), /* @__PURE__ */ y.createElement(
1566
+ A,
1567
+ {
1568
+ title: e.operation_rectangle_title,
1569
+ icon: "icon-rectangle",
1570
+ checked: d,
1571
+ onClick: w,
1572
+ option: /* @__PURE__ */ y.createElement(ce, { size: c, color: h, onSizeChange: f, onColorChange: a })
1573
+ }
1574
+ );
1575
+ }
1576
+ const ft = [ut, at, ct, ot, nt, Je, "|", Ve, Oe, "|", Fe, We, Ie];
1577
+ const Ee = y.createContext(null), ht = F(function() {
1578
+ const { width: t, height: s } = Y(), [i] = K(), [r, o] = $(null), [n, c] = $(null), f = E(null), h = g((l) => {
1579
+ l.stopPropagation();
1580
+ }, []), a = g((l) => {
1581
+ l.preventDefault(), l.stopPropagation();
1582
+ }, []);
1583
+ return T(() => {
1584
+ if (!i || !f.current)
1585
+ return;
1586
+ const l = f.current.getBoundingClientRect();
1587
+ let u = i.x + i.width - l.width, d = i.y + i.height + 10;
1588
+ u < 0 && (u = 0), u > t - l.width && (u = t - l.width), d > s - l.height && (d = s - l.height - 10), (!n || Math.abs(n.x - u) > 1 || Math.abs(n.y - d) > 1) && c({
1589
+ x: u,
1590
+ y: d
1591
+ }), (!r || Math.abs(r.x - l.x) > 1 || Math.abs(r.y - l.y) > 1 || Math.abs(r.width - l.width) > 1 || Math.abs(r.height - l.height) > 1) && o({
1592
+ x: l.x,
1593
+ y: l.y,
1594
+ width: l.width,
1595
+ height: l.height
1596
+ });
1597
+ }), i ? /* @__PURE__ */ y.createElement(Ee.Provider, { value: r }, /* @__PURE__ */ y.createElement(
1598
+ "div",
1599
+ {
1600
+ ref: f,
1601
+ className: "screenshots-operations",
1602
+ style: {
1603
+ visibility: n ? "visible" : "hidden",
1604
+ transform: `translate(${(n == null ? void 0 : n.x) ?? 0}px, ${(n == null ? void 0 : n.y) ?? 0}px)`
1605
+ },
1606
+ onDoubleClick: h,
1607
+ onContextMenu: a
1608
+ },
1609
+ /* @__PURE__ */ y.createElement("div", { className: "screenshots-operations-buttons" }, ft.map((l, u) => l === "|" ? /* @__PURE__ */ y.createElement("div", { key: u, className: "screenshots-operations-divider" }) : /* @__PURE__ */ y.createElement(l, { key: u })))
1610
+ )) : null;
1611
+ });
1612
+ function dt(e) {
1613
+ const [t, s] = $(null);
1614
+ return T(() => {
1615
+ if (s(null), e == null)
1616
+ return;
1617
+ const i = document.createElement("img"), r = () => s(i), o = () => s(null);
1618
+ return i.addEventListener("load", r), i.addEventListener("error", o), i.src = e, () => {
1619
+ i.removeEventListener("load", r), i.removeEventListener("error", o);
1620
+ };
1621
+ }, [e]), t;
1622
+ }
1623
+ function pt({ url: e, width: t, height: s, lang: i, className: r, ...o }) {
1624
+ const n = dt(e), c = E(null), f = E({}), [h, a] = $({
1625
+ index: -1,
1626
+ stack: []
1627
+ }), [l, u] = $(null), [d, p] = $("move"), [w, S] = $(void 0), R = {
1628
+ url: e,
1629
+ width: t,
1630
+ height: s,
1631
+ image: n,
1632
+ lang: {
1633
+ ...Re,
1634
+ ...i
1635
+ },
1636
+ emiterRef: f,
1637
+ canvasContextRef: c,
1638
+ history: h,
1639
+ bounds: l,
1640
+ cursor: d,
1641
+ operation: w
1642
+ }, b = g(
1643
+ (z, ...B) => {
1644
+ const D = o[z];
1645
+ typeof D == "function" && D(...B);
1646
+ },
1647
+ [o]
1648
+ ), M = {
1649
+ call: b,
1650
+ setHistory: a,
1651
+ setBounds: u,
1652
+ setCursor: p,
1653
+ setOperation: S
1654
+ }, v = ["screenshots"];
1655
+ r && v.push(r);
1656
+ const m = () => {
1657
+ f.current = {}, a({
1658
+ index: -1,
1659
+ stack: []
1660
+ }), u(null), p("move"), S(void 0);
1661
+ }, x = g(
1662
+ async (z) => {
1663
+ if (!(z.button !== 0 || !n))
1664
+ if (l && c.current)
1665
+ fe({
1666
+ image: n,
1667
+ width: t,
1668
+ height: s,
1669
+ history: h,
1670
+ bounds: l
1671
+ }).then((B) => {
1672
+ b("onOk", B, l), m();
1673
+ });
1674
+ else {
1675
+ const B = {
1676
+ x: 0,
1677
+ y: 0,
1678
+ width: t,
1679
+ height: s
1680
+ };
1681
+ fe({
1682
+ image: n,
1683
+ width: t,
1684
+ height: s,
1685
+ history: h,
1686
+ bounds: B
1687
+ }).then((D) => {
1688
+ b("onOk", D, B), m();
1689
+ });
1690
+ }
1691
+ },
1692
+ [n, h, l, t, s, b]
1693
+ ), C = g(
1694
+ (z) => {
1695
+ z.button === 2 && (z.preventDefault(), b("onCancel"), m());
1696
+ },
1697
+ [b]
1698
+ );
1699
+ return Q(() => {
1700
+ m();
1701
+ }, [e]), /* @__PURE__ */ y.createElement(ye.Provider, { value: { store: R, dispatcher: M } }, /* @__PURE__ */ y.createElement(
1702
+ "div",
1703
+ {
1704
+ className: v.join(" "),
1705
+ style: { width: t, height: s },
1706
+ onDoubleClick: x,
1707
+ onContextMenu: C
1708
+ },
1709
+ /* @__PURE__ */ y.createElement(Pe, null),
1710
+ /* @__PURE__ */ y.createElement(He, { ref: c }),
1711
+ /* @__PURE__ */ y.createElement(ht, null)
1712
+ ));
1713
+ }
1714
+ export {
1715
+ pt as default
1716
+ };