sykpcomposer 0.0.108 → 0.0.111

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,883 @@
1
+ import { j as C, u as ae, d as W, w as G, x as q, $ as J, a as te, b as he, c as ce, e as de, C as Y, f as le, k as ge, g as ue, I as pe, r as we, h as me, i as fe, l as xe, t as ye } from "./index-10f02946.js";
2
+ import { u as Ce, d as ve, L as De, P as be } from "./Placeholder-38b55ad9.js";
3
+ import x, { useRef as I, PureComponent as Re, createRef as ne, useState as K, useCallback as F, useEffect as Z, Suspense as Ee } from "react";
4
+ import "react-dom";
5
+ function Q(l, t, e) {
6
+ return Math.min(Math.max(l, t), e);
7
+ }
8
+ const y = {
9
+ east: 1,
10
+ north: 8,
11
+ south: 2,
12
+ west: 4
13
+ };
14
+ function Me({
15
+ onResizeStart: l,
16
+ onResizeEnd: t,
17
+ buttonRef: e,
18
+ imageRef: o,
19
+ maxWidth: n,
20
+ editor: r,
21
+ showCaption: a,
22
+ setShowCaption: u,
23
+ captionsEnabled: s
24
+ }) {
25
+ const i = I(null), c = I({
26
+ priority: "",
27
+ value: "default"
28
+ }), g = I({
29
+ currentHeight: 0,
30
+ currentWidth: 0,
31
+ direction: 0,
32
+ isResizing: !1,
33
+ ratio: 0,
34
+ startHeight: 0,
35
+ startWidth: 0,
36
+ startX: 0,
37
+ startY: 0
38
+ }), d = r.getRootElement(), h = n || (d !== null ? d.getBoundingClientRect().width - 20 : 100), v = d !== null ? d.getBoundingClientRect().height - 20 : 100, D = 100, k = 100, m = (p) => {
39
+ const f = p === y.east || p === y.west, w = p === y.north || p === y.south, N = p & y.north && p & y.west || p & y.south && p & y.east, H = f ? "ew" : w ? "ns" : N ? "nwse" : "nesw";
40
+ d !== null && d.style.setProperty(
41
+ "cursor",
42
+ `${H}-resize`,
43
+ "important"
44
+ ), document.body !== null && (document.body.style.setProperty(
45
+ "cursor",
46
+ `${H}-resize`,
47
+ "important"
48
+ ), c.current.value = document.body.style.getPropertyValue(
49
+ "-webkit-user-select"
50
+ ), c.current.priority = document.body.style.getPropertyPriority(
51
+ "-webkit-user-select"
52
+ ), document.body.style.setProperty(
53
+ "-webkit-user-select",
54
+ "none",
55
+ "important"
56
+ ));
57
+ }, X = () => {
58
+ d !== null && d.style.setProperty("cursor", "text"), document.body !== null && (document.body.style.setProperty("cursor", "default"), document.body.style.setProperty(
59
+ "-webkit-user-select",
60
+ c.current.value,
61
+ c.current.priority
62
+ ));
63
+ }, S = (p, f) => {
64
+ if (!r.isEditable())
65
+ return;
66
+ const w = o.current, N = i.current;
67
+ if (w !== null && N !== null) {
68
+ p.preventDefault();
69
+ const { width: H, height: R } = w.getBoundingClientRect(), E = g.current;
70
+ E.startWidth = H, E.startHeight = R, E.ratio = H / R, E.currentWidth = H, E.currentHeight = R, E.startX = p.clientX, E.startY = p.clientY, E.isResizing = !0, E.direction = f, m(f), l(), N.classList.add("image-control-wrapper--resizing"), w.style.height = `${R}px`, w.style.width = `${H}px`, document.addEventListener("pointermove", b), document.addEventListener("pointerup", z);
71
+ }
72
+ }, b = (p) => {
73
+ const f = o.current, w = g.current, N = w.direction & (y.east | y.west), H = w.direction & (y.south | y.north);
74
+ if (f !== null && w.isResizing)
75
+ if (N && H) {
76
+ let R = Math.floor(w.startX - p.clientX);
77
+ R = w.direction & y.east ? -R : R;
78
+ const E = Q(
79
+ w.startWidth + R,
80
+ D,
81
+ h
82
+ ), T = E / w.ratio;
83
+ f.style.width = `${E}px`, f.style.height = `${T}px`, w.currentHeight = T, w.currentWidth = E;
84
+ } else if (H) {
85
+ let R = Math.floor(w.startY - p.clientY);
86
+ R = w.direction & y.south ? -R : R;
87
+ const E = Q(
88
+ w.startHeight + R,
89
+ k,
90
+ v
91
+ );
92
+ f.style.height = `${E}px`, w.currentHeight = E;
93
+ } else {
94
+ let R = Math.floor(w.startX - p.clientX);
95
+ R = w.direction & y.east ? -R : R;
96
+ const E = Q(
97
+ w.startWidth + R,
98
+ D,
99
+ h
100
+ );
101
+ f.style.width = `${E}px`, w.currentWidth = E;
102
+ }
103
+ }, z = () => {
104
+ const p = o.current, f = g.current, w = i.current;
105
+ if (p !== null && w !== null && f.isResizing) {
106
+ const N = f.currentWidth, H = f.currentHeight;
107
+ f.startWidth = 0, f.startHeight = 0, f.ratio = 0, f.startX = 0, f.startY = 0, f.currentWidth = 0, f.currentHeight = 0, f.isResizing = !1, w.classList.remove("image-control-wrapper--resizing"), X(), t(N, H), document.removeEventListener("pointermove", b), document.removeEventListener("pointerup", z);
108
+ }
109
+ };
110
+ return /* @__PURE__ */ C.jsxs("div", { ref: i, children: [
111
+ !a && s && /* @__PURE__ */ C.jsx(
112
+ "button",
113
+ {
114
+ className: "image-caption-button",
115
+ ref: e,
116
+ onClick: () => {
117
+ u(!a);
118
+ },
119
+ children: "Add Caption"
120
+ }
121
+ ),
122
+ /* @__PURE__ */ C.jsx(
123
+ "div",
124
+ {
125
+ className: "image-resizer image-resizer-n",
126
+ onPointerDown: (p) => {
127
+ S(p, y.north);
128
+ }
129
+ }
130
+ ),
131
+ /* @__PURE__ */ C.jsx(
132
+ "div",
133
+ {
134
+ className: "image-resizer image-resizer-ne",
135
+ onPointerDown: (p) => {
136
+ S(p, y.north | y.east);
137
+ }
138
+ }
139
+ ),
140
+ /* @__PURE__ */ C.jsx(
141
+ "div",
142
+ {
143
+ className: "image-resizer image-resizer-e",
144
+ onPointerDown: (p) => {
145
+ S(p, y.east);
146
+ }
147
+ }
148
+ ),
149
+ /* @__PURE__ */ C.jsx(
150
+ "div",
151
+ {
152
+ className: "image-resizer image-resizer-se",
153
+ onPointerDown: (p) => {
154
+ S(p, y.south | y.east);
155
+ }
156
+ }
157
+ ),
158
+ /* @__PURE__ */ C.jsx(
159
+ "div",
160
+ {
161
+ className: "image-resizer image-resizer-s",
162
+ onPointerDown: (p) => {
163
+ S(p, y.south);
164
+ }
165
+ }
166
+ ),
167
+ /* @__PURE__ */ C.jsx(
168
+ "div",
169
+ {
170
+ className: "image-resizer image-resizer-sw",
171
+ onPointerDown: (p) => {
172
+ S(p, y.south | y.west);
173
+ }
174
+ }
175
+ ),
176
+ /* @__PURE__ */ C.jsx(
177
+ "div",
178
+ {
179
+ className: "image-resizer image-resizer-w",
180
+ onPointerDown: (p) => {
181
+ S(p, y.west);
182
+ }
183
+ }
184
+ ),
185
+ /* @__PURE__ */ C.jsx(
186
+ "div",
187
+ {
188
+ className: "image-resizer image-resizer-nw",
189
+ onPointerDown: (p) => {
190
+ S(p, y.north | y.west);
191
+ }
192
+ }
193
+ )
194
+ ] });
195
+ }
196
+ const V = {
197
+ x: 0,
198
+ y: 0,
199
+ width: 0,
200
+ height: 0,
201
+ unit: "px"
202
+ }, A = (l, t, e) => Math.min(Math.max(l, t), e), Pe = (...l) => l.filter((t) => t && typeof t == "string").join(" "), re = (l, t) => l === t || l.width === t.width && l.height === t.height && l.x === t.x && l.y === t.y && l.unit === t.unit;
203
+ function B(l, t, e) {
204
+ return l.unit === "%" ? { ...V, ...l, unit: "%" } : {
205
+ unit: "%",
206
+ x: l.x ? l.x / t * 100 : 0,
207
+ y: l.y ? l.y / e * 100 : 0,
208
+ width: l.width ? l.width / t * 100 : 0,
209
+ height: l.height ? l.height / e * 100 : 0
210
+ };
211
+ }
212
+ function L(l, t, e) {
213
+ return l.unit ? l.unit === "px" ? { ...V, ...l, unit: "px" } : {
214
+ unit: "px",
215
+ x: l.x ? l.x * t / 100 : 0,
216
+ y: l.y ? l.y * e / 100 : 0,
217
+ width: l.width ? l.width * t / 100 : 0,
218
+ height: l.height ? l.height * e / 100 : 0
219
+ } : { ...V, ...l, unit: "px" };
220
+ }
221
+ function ie(l, t, e, o, n, r = 0, a = 0, u = o, s = n) {
222
+ const i = { ...l };
223
+ let c = Math.min(r, o), g = Math.min(a, n), d = Math.min(u, o), h = Math.min(s, n);
224
+ t && (t > 1 ? (c = a ? a * t : c, g = c / t, d = u * t) : (g = r ? r / t : g, c = g * t, h = s / t)), i.y < 0 && (i.height = Math.max(i.height + i.y, g), i.y = 0), i.x < 0 && (i.width = Math.max(i.width + i.x, c), i.x = 0);
225
+ const v = o - (i.x + i.width);
226
+ v < 0 && (i.x = Math.min(i.x, o - c), i.width += v);
227
+ const D = n - (i.y + i.height);
228
+ if (D < 0 && (i.y = Math.min(i.y, n - g), i.height += D), i.width < c && ((e === "sw" || e == "nw") && (i.x -= c - i.width), i.width = c), i.height < g && ((e === "nw" || e == "ne") && (i.y -= g - i.height), i.height = g), i.width > d && ((e === "sw" || e == "nw") && (i.x -= d - i.width), i.width = d), i.height > h && ((e === "nw" || e == "ne") && (i.y -= h - i.height), i.height = h), t) {
229
+ const k = i.width / i.height;
230
+ if (k < t) {
231
+ const m = Math.max(i.width / t, g);
232
+ (e === "nw" || e == "ne") && (i.y -= m - i.height), i.height = m;
233
+ } else if (k > t) {
234
+ const m = Math.max(i.height * t, c);
235
+ (e === "sw" || e == "nw") && (i.x -= m - i.width), i.width = m;
236
+ }
237
+ }
238
+ return i;
239
+ }
240
+ function He(l, t, e, o) {
241
+ const n = { ...l };
242
+ return t === "ArrowLeft" ? o === "nw" ? (n.x -= e, n.y -= e, n.width += e, n.height += e) : o === "w" ? (n.x -= e, n.width += e) : o === "sw" ? (n.x -= e, n.width += e, n.height += e) : o === "ne" ? (n.y += e, n.width -= e, n.height -= e) : o === "e" ? n.width -= e : o === "se" && (n.width -= e, n.height -= e) : t === "ArrowRight" && (o === "nw" ? (n.x += e, n.y += e, n.width -= e, n.height -= e) : o === "w" ? (n.x += e, n.width -= e) : o === "sw" ? (n.x += e, n.width -= e, n.height -= e) : o === "ne" ? (n.y -= e, n.width += e, n.height += e) : o === "e" ? n.width += e : o === "se" && (n.width += e, n.height += e)), t === "ArrowUp" ? o === "nw" ? (n.x -= e, n.y -= e, n.width += e, n.height += e) : o === "n" ? (n.y -= e, n.height += e) : o === "ne" ? (n.y -= e, n.width += e, n.height += e) : o === "sw" ? (n.x += e, n.width -= e, n.height -= e) : o === "s" ? n.height -= e : o === "se" && (n.width -= e, n.height -= e) : t === "ArrowDown" && (o === "nw" ? (n.x += e, n.y += e, n.width -= e, n.height -= e) : o === "n" ? (n.y += e, n.height -= e) : o === "ne" ? (n.y += e, n.width -= e, n.height -= e) : o === "sw" ? (n.x -= e, n.width += e, n.height += e) : o === "s" ? n.height += e : o === "se" && (n.width += e, n.height += e)), n;
243
+ }
244
+ const O = { capture: !0, passive: !1 };
245
+ let ke = 0;
246
+ const j = class _ extends Re {
247
+ constructor() {
248
+ super(...arguments), this.docMoveBound = !1, this.mouseDownOnCrop = !1, this.dragStarted = !1, this.evData = {
249
+ startClientX: 0,
250
+ startClientY: 0,
251
+ startCropX: 0,
252
+ startCropY: 0,
253
+ clientX: 0,
254
+ clientY: 0,
255
+ isResize: !0
256
+ }, this.componentRef = ne(), this.mediaRef = ne(), this.initChangeCalled = !1, this.instanceId = `rc-${ke++}`, this.state = {
257
+ cropIsActive: !1,
258
+ newCropIsBeingDrawn: !1
259
+ }, this.onCropPointerDown = (t) => {
260
+ const { crop: e, disabled: o } = this.props, n = this.getBox();
261
+ if (!e)
262
+ return;
263
+ const r = L(e, n.width, n.height);
264
+ if (o)
265
+ return;
266
+ t.cancelable && t.preventDefault(), this.bindDocMove(), this.componentRef.current.focus({ preventScroll: !0 });
267
+ const a = t.target.dataset.ord, u = !!a;
268
+ let s = t.clientX, i = t.clientY, c = r.x, g = r.y;
269
+ if (a) {
270
+ const d = t.clientX - n.x, h = t.clientY - n.y;
271
+ let v = 0, D = 0;
272
+ a === "ne" || a == "e" ? (v = d - (r.x + r.width), D = h - r.y, c = r.x, g = r.y + r.height) : a === "se" || a === "s" ? (v = d - (r.x + r.width), D = h - (r.y + r.height), c = r.x, g = r.y) : a === "sw" || a == "w" ? (v = d - r.x, D = h - (r.y + r.height), c = r.x + r.width, g = r.y) : (a === "nw" || a == "n") && (v = d - r.x, D = h - r.y, c = r.x + r.width, g = r.y + r.height), s = c + n.x + v, i = g + n.y + D;
273
+ }
274
+ this.evData = {
275
+ startClientX: s,
276
+ startClientY: i,
277
+ startCropX: c,
278
+ startCropY: g,
279
+ clientX: t.clientX,
280
+ clientY: t.clientY,
281
+ isResize: u,
282
+ ord: a
283
+ }, this.mouseDownOnCrop = !0, this.setState({ cropIsActive: !0 });
284
+ }, this.onComponentPointerDown = (t) => {
285
+ const { crop: e, disabled: o, locked: n, keepSelection: r, onChange: a } = this.props, u = this.getBox();
286
+ if (o || n || r && e)
287
+ return;
288
+ t.cancelable && t.preventDefault(), this.bindDocMove(), this.componentRef.current.focus({ preventScroll: !0 });
289
+ const s = t.clientX - u.x, i = t.clientY - u.y, c = {
290
+ unit: "px",
291
+ x: s,
292
+ y: i,
293
+ width: 0,
294
+ height: 0
295
+ };
296
+ this.evData = {
297
+ startClientX: t.clientX,
298
+ startClientY: t.clientY,
299
+ startCropX: s,
300
+ startCropY: i,
301
+ clientX: t.clientX,
302
+ clientY: t.clientY,
303
+ isResize: !0
304
+ }, this.mouseDownOnCrop = !0, a(L(c, u.width, u.height), B(c, u.width, u.height)), this.setState({ cropIsActive: !0, newCropIsBeingDrawn: !0 });
305
+ }, this.onDocPointerMove = (t) => {
306
+ const { crop: e, disabled: o, onChange: n, onDragStart: r } = this.props, a = this.getBox();
307
+ if (o || !e || !this.mouseDownOnCrop)
308
+ return;
309
+ t.cancelable && t.preventDefault(), this.dragStarted || (this.dragStarted = !0, r && r(t));
310
+ const { evData: u } = this;
311
+ u.clientX = t.clientX, u.clientY = t.clientY;
312
+ let s;
313
+ u.isResize ? s = this.resizeCrop() : s = this.dragCrop(), re(e, s) || n(
314
+ L(s, a.width, a.height),
315
+ B(s, a.width, a.height)
316
+ );
317
+ }, this.onComponentKeyDown = (t) => {
318
+ const { crop: e, disabled: o, onChange: n, onComplete: r } = this.props;
319
+ if (o)
320
+ return;
321
+ const a = t.key;
322
+ let u = !1;
323
+ if (!e)
324
+ return;
325
+ const s = this.getBox(), i = this.makePixelCrop(s), c = (navigator.platform.match("Mac") ? t.metaKey : t.ctrlKey) ? _.nudgeStepLarge : t.shiftKey ? _.nudgeStepMedium : _.nudgeStep;
326
+ if (a === "ArrowLeft" ? (i.x -= c, u = !0) : a === "ArrowRight" ? (i.x += c, u = !0) : a === "ArrowUp" ? (i.y -= c, u = !0) : a === "ArrowDown" && (i.y += c, u = !0), u) {
327
+ t.cancelable && t.preventDefault(), i.x = A(i.x, 0, s.width - i.width), i.y = A(i.y, 0, s.height - i.height);
328
+ const g = L(i, s.width, s.height), d = B(i, s.width, s.height);
329
+ n(g, d), r && r(g, d);
330
+ }
331
+ }, this.onHandlerKeyDown = (t, e) => {
332
+ const {
333
+ aspect: o = 0,
334
+ crop: n,
335
+ disabled: r,
336
+ minWidth: a = 0,
337
+ minHeight: u = 0,
338
+ maxWidth: s,
339
+ maxHeight: i,
340
+ onChange: c,
341
+ onComplete: g
342
+ } = this.props, d = this.getBox();
343
+ if (r || !n)
344
+ return;
345
+ if (t.key === "ArrowUp" || t.key === "ArrowDown" || t.key === "ArrowLeft" || t.key === "ArrowRight")
346
+ t.stopPropagation(), t.preventDefault();
347
+ else
348
+ return;
349
+ const h = (navigator.platform.match("Mac") ? t.metaKey : t.ctrlKey) ? _.nudgeStepLarge : t.shiftKey ? _.nudgeStepMedium : _.nudgeStep, v = L(n, d.width, d.height), D = He(v, t.key, h, e), k = ie(
350
+ D,
351
+ o,
352
+ e,
353
+ d.width,
354
+ d.height,
355
+ a,
356
+ u,
357
+ s,
358
+ i
359
+ );
360
+ if (!re(n, k)) {
361
+ const m = B(k, d.width, d.height);
362
+ c(k, m), g && g(k, m);
363
+ }
364
+ }, this.onDocPointerDone = (t) => {
365
+ const { crop: e, disabled: o, onComplete: n, onDragEnd: r } = this.props, a = this.getBox();
366
+ this.unbindDocMove(), !(o || !e) && this.mouseDownOnCrop && (this.mouseDownOnCrop = !1, this.dragStarted = !1, r && r(t), n && n(L(e, a.width, a.height), B(e, a.width, a.height)), this.setState({ cropIsActive: !1, newCropIsBeingDrawn: !1 }));
367
+ }, this.onDragFocus = () => {
368
+ var t;
369
+ (t = this.componentRef.current) == null || t.scrollTo(0, 0);
370
+ };
371
+ }
372
+ get document() {
373
+ return document;
374
+ }
375
+ // We unfortunately get the bounding box every time as x+y changes
376
+ // due to scrolling.
377
+ getBox() {
378
+ const t = this.mediaRef.current;
379
+ if (!t)
380
+ return { x: 0, y: 0, width: 0, height: 0 };
381
+ const { x: e, y: o, width: n, height: r } = t.getBoundingClientRect();
382
+ return { x: e, y: o, width: n, height: r };
383
+ }
384
+ componentDidUpdate(t) {
385
+ const { crop: e, onComplete: o } = this.props;
386
+ if (o && !t.crop && e) {
387
+ const { width: n, height: r } = this.getBox();
388
+ n && r && o(L(e, n, r), B(e, n, r));
389
+ }
390
+ }
391
+ componentWillUnmount() {
392
+ this.resizeObserver && this.resizeObserver.disconnect(), this.unbindDocMove();
393
+ }
394
+ bindDocMove() {
395
+ this.docMoveBound || (this.document.addEventListener("pointermove", this.onDocPointerMove, O), this.document.addEventListener("pointerup", this.onDocPointerDone, O), this.document.addEventListener("pointercancel", this.onDocPointerDone, O), this.docMoveBound = !0);
396
+ }
397
+ unbindDocMove() {
398
+ this.docMoveBound && (this.document.removeEventListener("pointermove", this.onDocPointerMove, O), this.document.removeEventListener("pointerup", this.onDocPointerDone, O), this.document.removeEventListener("pointercancel", this.onDocPointerDone, O), this.docMoveBound = !1);
399
+ }
400
+ getCropStyle() {
401
+ const { crop: t } = this.props;
402
+ if (t)
403
+ return {
404
+ top: `${t.y}${t.unit}`,
405
+ left: `${t.x}${t.unit}`,
406
+ width: `${t.width}${t.unit}`,
407
+ height: `${t.height}${t.unit}`
408
+ };
409
+ }
410
+ dragCrop() {
411
+ const { evData: t } = this, e = this.getBox(), o = this.makePixelCrop(e), n = t.clientX - t.startClientX, r = t.clientY - t.startClientY;
412
+ return o.x = A(t.startCropX + n, 0, e.width - o.width), o.y = A(t.startCropY + r, 0, e.height - o.height), o;
413
+ }
414
+ getPointRegion(t, e, o, n) {
415
+ const { evData: r } = this, a = r.clientX - t.x, u = r.clientY - t.y;
416
+ let s;
417
+ n && e ? s = e === "nw" || e === "n" || e === "ne" : s = u < r.startCropY;
418
+ let i;
419
+ return o && e ? i = e === "nw" || e === "w" || e === "sw" : i = a < r.startCropX, i ? s ? "nw" : "sw" : s ? "ne" : "se";
420
+ }
421
+ resolveMinDimensions(t, e, o = 0, n = 0) {
422
+ const r = Math.min(o, t.width), a = Math.min(n, t.height);
423
+ return !e || !r && !a ? [r, a] : e > 1 ? r ? [r, r / e] : [a * e, a] : a ? [a * e, a] : [r, r / e];
424
+ }
425
+ resizeCrop() {
426
+ const { evData: t } = this, { aspect: e = 0, maxWidth: o, maxHeight: n } = this.props, r = this.getBox(), [a, u] = this.resolveMinDimensions(r, e, this.props.minWidth, this.props.minHeight);
427
+ let s = this.makePixelCrop(r);
428
+ const i = this.getPointRegion(r, t.ord, a, u), c = t.ord || i;
429
+ let g = t.clientX - t.startClientX, d = t.clientY - t.startClientY;
430
+ (a && c === "nw" || c === "w" || c === "sw") && (g = Math.min(g, -a)), (u && c === "nw" || c === "n" || c === "ne") && (d = Math.min(d, -u));
431
+ const h = {
432
+ unit: "px",
433
+ x: 0,
434
+ y: 0,
435
+ width: 0,
436
+ height: 0
437
+ };
438
+ i === "ne" ? (h.x = t.startCropX, h.width = g, e ? (h.height = h.width / e, h.y = t.startCropY - h.height) : (h.height = Math.abs(d), h.y = t.startCropY - h.height)) : i === "se" ? (h.x = t.startCropX, h.y = t.startCropY, h.width = g, e ? h.height = h.width / e : h.height = d) : i === "sw" ? (h.x = t.startCropX + g, h.y = t.startCropY, h.width = Math.abs(g), e ? h.height = h.width / e : h.height = d) : i === "nw" && (h.x = t.startCropX + g, h.width = Math.abs(g), e ? (h.height = h.width / e, h.y = t.startCropY - h.height) : (h.height = Math.abs(d), h.y = t.startCropY + d));
439
+ const v = ie(
440
+ h,
441
+ e,
442
+ i,
443
+ r.width,
444
+ r.height,
445
+ a,
446
+ u,
447
+ o,
448
+ n
449
+ );
450
+ return e || _.xyOrds.indexOf(c) > -1 ? s = v : _.xOrds.indexOf(c) > -1 ? (s.x = v.x, s.width = v.width) : _.yOrds.indexOf(c) > -1 && (s.y = v.y, s.height = v.height), s.x = A(s.x, 0, r.width - s.width), s.y = A(s.y, 0, r.height - s.height), s;
451
+ }
452
+ renderCropSelection() {
453
+ const {
454
+ ariaLabels: t = _.defaultProps.ariaLabels,
455
+ disabled: e,
456
+ locked: o,
457
+ renderSelectionAddon: n,
458
+ ruleOfThirds: r,
459
+ crop: a
460
+ } = this.props, u = this.getCropStyle();
461
+ if (a)
462
+ return /* @__PURE__ */ x.createElement(
463
+ "div",
464
+ {
465
+ style: u,
466
+ className: "ReactCrop__crop-selection",
467
+ onPointerDown: this.onCropPointerDown,
468
+ "aria-label": t.cropArea,
469
+ tabIndex: 0,
470
+ onKeyDown: this.onComponentKeyDown,
471
+ role: "group"
472
+ },
473
+ !e && !o && /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__drag-elements", onFocus: this.onDragFocus }, /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__drag-bar ord-n", "data-ord": "n" }), /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__drag-bar ord-e", "data-ord": "e" }), /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__drag-bar ord-s", "data-ord": "s" }), /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__drag-bar ord-w", "data-ord": "w" }), /* @__PURE__ */ x.createElement(
474
+ "div",
475
+ {
476
+ className: "ReactCrop__drag-handle ord-nw",
477
+ "data-ord": "nw",
478
+ tabIndex: 0,
479
+ "aria-label": t.nwDragHandle,
480
+ onKeyDown: (s) => this.onHandlerKeyDown(s, "nw"),
481
+ role: "button"
482
+ }
483
+ ), /* @__PURE__ */ x.createElement(
484
+ "div",
485
+ {
486
+ className: "ReactCrop__drag-handle ord-n",
487
+ "data-ord": "n",
488
+ tabIndex: 0,
489
+ "aria-label": t.nDragHandle,
490
+ onKeyDown: (s) => this.onHandlerKeyDown(s, "n"),
491
+ role: "button"
492
+ }
493
+ ), /* @__PURE__ */ x.createElement(
494
+ "div",
495
+ {
496
+ className: "ReactCrop__drag-handle ord-ne",
497
+ "data-ord": "ne",
498
+ tabIndex: 0,
499
+ "aria-label": t.neDragHandle,
500
+ onKeyDown: (s) => this.onHandlerKeyDown(s, "ne"),
501
+ role: "button"
502
+ }
503
+ ), /* @__PURE__ */ x.createElement(
504
+ "div",
505
+ {
506
+ className: "ReactCrop__drag-handle ord-e",
507
+ "data-ord": "e",
508
+ tabIndex: 0,
509
+ "aria-label": t.eDragHandle,
510
+ onKeyDown: (s) => this.onHandlerKeyDown(s, "e"),
511
+ role: "button"
512
+ }
513
+ ), /* @__PURE__ */ x.createElement(
514
+ "div",
515
+ {
516
+ className: "ReactCrop__drag-handle ord-se",
517
+ "data-ord": "se",
518
+ tabIndex: 0,
519
+ "aria-label": t.seDragHandle,
520
+ onKeyDown: (s) => this.onHandlerKeyDown(s, "se"),
521
+ role: "button"
522
+ }
523
+ ), /* @__PURE__ */ x.createElement(
524
+ "div",
525
+ {
526
+ className: "ReactCrop__drag-handle ord-s",
527
+ "data-ord": "s",
528
+ tabIndex: 0,
529
+ "aria-label": t.sDragHandle,
530
+ onKeyDown: (s) => this.onHandlerKeyDown(s, "s"),
531
+ role: "button"
532
+ }
533
+ ), /* @__PURE__ */ x.createElement(
534
+ "div",
535
+ {
536
+ className: "ReactCrop__drag-handle ord-sw",
537
+ "data-ord": "sw",
538
+ tabIndex: 0,
539
+ "aria-label": t.swDragHandle,
540
+ onKeyDown: (s) => this.onHandlerKeyDown(s, "sw"),
541
+ role: "button"
542
+ }
543
+ ), /* @__PURE__ */ x.createElement(
544
+ "div",
545
+ {
546
+ className: "ReactCrop__drag-handle ord-w",
547
+ "data-ord": "w",
548
+ tabIndex: 0,
549
+ "aria-label": t.wDragHandle,
550
+ onKeyDown: (s) => this.onHandlerKeyDown(s, "w"),
551
+ role: "button"
552
+ }
553
+ )),
554
+ n && /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__selection-addon", onPointerDown: (s) => s.stopPropagation() }, n(this.state)),
555
+ r && /* @__PURE__ */ x.createElement(x.Fragment, null, /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__rule-of-thirds-hz" }), /* @__PURE__ */ x.createElement("div", { className: "ReactCrop__rule-of-thirds-vt" }))
556
+ );
557
+ }
558
+ makePixelCrop(t) {
559
+ const e = { ...V, ...this.props.crop || {} };
560
+ return L(e, t.width, t.height);
561
+ }
562
+ render() {
563
+ const { aspect: t, children: e, circularCrop: o, className: n, crop: r, disabled: a, locked: u, style: s, ruleOfThirds: i } = this.props, { cropIsActive: c, newCropIsBeingDrawn: g } = this.state, d = r ? this.renderCropSelection() : null, h = Pe(
564
+ "ReactCrop",
565
+ n,
566
+ c && "ReactCrop--active",
567
+ a && "ReactCrop--disabled",
568
+ u && "ReactCrop--locked",
569
+ g && "ReactCrop--new-crop",
570
+ r && t && "ReactCrop--fixed-aspect",
571
+ r && o && "ReactCrop--circular-crop",
572
+ r && i && "ReactCrop--rule-of-thirds",
573
+ !this.dragStarted && r && !r.width && !r.height && "ReactCrop--invisible-crop",
574
+ o && "ReactCrop--no-animate"
575
+ );
576
+ return /* @__PURE__ */ x.createElement("div", { ref: this.componentRef, className: h, style: s }, /* @__PURE__ */ x.createElement("div", { ref: this.mediaRef, className: "ReactCrop__child-wrapper", onPointerDown: this.onComponentPointerDown }, e), r ? /* @__PURE__ */ x.createElement("svg", { className: "ReactCrop__crop-mask", width: "100%", height: "100%" }, /* @__PURE__ */ x.createElement("defs", null, /* @__PURE__ */ x.createElement("mask", { id: `hole-${this.instanceId}` }, /* @__PURE__ */ x.createElement("rect", { width: "100%", height: "100%", fill: "white" }), o ? /* @__PURE__ */ x.createElement(
577
+ "ellipse",
578
+ {
579
+ cx: `${r.x + r.width / 2}${r.unit}`,
580
+ cy: `${r.y + r.height / 2}${r.unit}`,
581
+ rx: `${r.width / 2}${r.unit}`,
582
+ ry: `${r.height / 2}${r.unit}`,
583
+ fill: "black"
584
+ }
585
+ ) : /* @__PURE__ */ x.createElement(
586
+ "rect",
587
+ {
588
+ x: `${r.x}${r.unit}`,
589
+ y: `${r.y}${r.unit}`,
590
+ width: `${r.width}${r.unit}`,
591
+ height: `${r.height}${r.unit}`,
592
+ fill: "black"
593
+ }
594
+ ))), /* @__PURE__ */ x.createElement("rect", { fill: "black", fillOpacity: 0.5, width: "100%", height: "100%", mask: `url(#hole-${this.instanceId})` })) : void 0, d);
595
+ }
596
+ };
597
+ j.xOrds = ["e", "w"], j.yOrds = ["n", "s"], j.xyOrds = ["nw", "ne", "se", "sw"], j.nudgeStep = 1, j.nudgeStepMedium = 10, j.nudgeStepLarge = 100, j.defaultProps = {
598
+ ariaLabels: {
599
+ cropArea: "Use the arrow keys to move the crop selection area",
600
+ nwDragHandle: "Use the arrow keys to move the north west drag handle to change the crop selection area",
601
+ nDragHandle: "Use the up and down arrow keys to move the north drag handle to change the crop selection area",
602
+ neDragHandle: "Use the arrow keys to move the north east drag handle to change the crop selection area",
603
+ eDragHandle: "Use the up and down arrow keys to move the east drag handle to change the crop selection area",
604
+ seDragHandle: "Use the arrow keys to move the south east drag handle to change the crop selection area",
605
+ sDragHandle: "Use the up and down arrow keys to move the south drag handle to change the crop selection area",
606
+ swDragHandle: "Use the arrow keys to move the south west drag handle to change the crop selection area",
607
+ wDragHandle: "Use the up and down arrow keys to move the west drag handle to change the crop selection area"
608
+ }
609
+ };
610
+ let Ne = j;
611
+ const oe = ye();
612
+ function Se({
613
+ altText: l,
614
+ className: t,
615
+ imageRef: e,
616
+ src: o,
617
+ width: n,
618
+ height: r,
619
+ maxWidth: a
620
+ }) {
621
+ const [u, s] = K({
622
+ aspect: 1,
623
+ x: 0,
624
+ y: 0,
625
+ width: 100,
626
+ height: 100
627
+ }), [i, c] = K(null), [g, d] = K(null), [h, v] = K(!1);
628
+ I("");
629
+ const D = I(null), k = I(null);
630
+ Z(() => {
631
+ i && (D.current = i);
632
+ }, [i]);
633
+ const m = () => {
634
+ v((b) => (b === !1 && s({ aspect: 1, x: 0, y: 0, width: 100, height: 100 }), !b));
635
+ }, X = (b) => {
636
+ k.current && !k.current.contains(b.target) && (console.log("Outside of the image clicked!"), v(!1));
637
+ };
638
+ Z(() => (document.addEventListener("mousedown", X), () => {
639
+ document.removeEventListener("mousedown", X);
640
+ }), []);
641
+ const S = () => {
642
+ if (i) {
643
+ const b = e.current;
644
+ if (!b || !i)
645
+ return;
646
+ const z = b.naturalWidth / b.width, p = b.naturalHeight / b.height, f = new OffscreenCanvas(
647
+ i.width * z,
648
+ i.height * p
649
+ ), w = f.getContext("2d");
650
+ if (!w)
651
+ throw new Error("No 2D context available");
652
+ w.drawImage(
653
+ b,
654
+ i.x * z,
655
+ i.y * p,
656
+ i.width * z,
657
+ i.height * p,
658
+ 0,
659
+ 0,
660
+ i.width * z,
661
+ i.height * p
662
+ ), f.convertToBlob({ type: "image/png" }).then((N) => {
663
+ const H = URL.createObjectURL(N);
664
+ d(H), v(!h), console.log("Updated cropped image:", H);
665
+ });
666
+ }
667
+ };
668
+ return /* @__PURE__ */ C.jsxs("div", { ref: k, children: [
669
+ h ? /* @__PURE__ */ C.jsx("button", { onClick: S, disabled: !i, children: "Apply Crop" }) : /* @__PURE__ */ C.jsx("button", { onClick: m, children: "Enable Crop" }),
670
+ h ? /* @__PURE__ */ C.jsx(
671
+ Ne,
672
+ {
673
+ crop: u,
674
+ onChange: (b) => s(b),
675
+ onComplete: (b) => c(b),
676
+ children: /* @__PURE__ */ C.jsx(
677
+ "img",
678
+ {
679
+ className: t || void 0,
680
+ src: g || o,
681
+ alt: l,
682
+ ref: e,
683
+ style: {
684
+ height: r,
685
+ maxWidth: a,
686
+ width: n
687
+ },
688
+ draggable: "false"
689
+ }
690
+ )
691
+ }
692
+ ) : (
693
+ // When selectCrop is false, show the cropped image or original image
694
+ /* @__PURE__ */ C.jsx(
695
+ "img",
696
+ {
697
+ className: t || void 0,
698
+ src: g || o,
699
+ alt: l,
700
+ ref: e,
701
+ style: {
702
+ height: r,
703
+ maxWidth: a,
704
+ width: n
705
+ },
706
+ draggable: "false"
707
+ }
708
+ )
709
+ )
710
+ ] });
711
+ }
712
+ function Xe({
713
+ src: l,
714
+ altText: t,
715
+ nodeKey: e,
716
+ width: o,
717
+ height: n,
718
+ maxWidth: r,
719
+ resizable: a,
720
+ showCaption: u,
721
+ caption: s,
722
+ captionsEnabled: i
723
+ }) {
724
+ const c = I(null), g = I(null), [d, h, v] = Ce(e), [D, k] = K(!1), [m] = ae(), [X, S] = K(null), b = I(null), z = F(
725
+ (P) => {
726
+ if (d && W(G())) {
727
+ P.preventDefault();
728
+ const $ = q(e);
729
+ if (J($))
730
+ return $.remove(), !0;
731
+ }
732
+ return !1;
733
+ },
734
+ [d, e]
735
+ ), p = F(
736
+ (P) => {
737
+ const M = G(), $ = g.current;
738
+ if (d && W(M) && M.getNodes().length === 1) {
739
+ if (u)
740
+ return te(null), P.preventDefault(), s.focus(), !0;
741
+ if ($ !== null && $ !== document.activeElement)
742
+ return P.preventDefault(), $.focus(), !0;
743
+ }
744
+ return !1;
745
+ },
746
+ [s, d, u]
747
+ ), f = F(
748
+ (P) => b.current === s || g.current === P.target ? (te(null), m.update(() => {
749
+ h(!0);
750
+ const M = m.getRootElement();
751
+ M !== null && M.focus();
752
+ }), !0) : !1,
753
+ [s, m, h]
754
+ ), w = F(
755
+ (P) => {
756
+ const M = P;
757
+ return D ? !0 : M.target === c.current ? (M.shiftKey ? h(!d) : (v(), h(!0)), !0) : !1;
758
+ },
759
+ [D, d, h, v]
760
+ ), N = F(
761
+ (P) => {
762
+ m.getEditorState().read(() => {
763
+ const M = G();
764
+ P.target.tagName === "IMG" && he(M) && M.getNodes().length === 1 && m.dispatchCommand(
765
+ oe,
766
+ P
767
+ );
768
+ });
769
+ },
770
+ [m]
771
+ );
772
+ Z(() => {
773
+ let P = !0;
774
+ const M = m.getRootElement(), $ = ce(
775
+ m.registerUpdateListener(({ editorState: U }) => {
776
+ P && S(U.read(() => G()));
777
+ }),
778
+ m.registerCommand(
779
+ me,
780
+ (U, se) => (b.current = se, !1),
781
+ Y
782
+ ),
783
+ m.registerCommand(
784
+ we,
785
+ w,
786
+ Y
787
+ ),
788
+ m.registerCommand(
789
+ oe,
790
+ w,
791
+ Y
792
+ ),
793
+ m.registerCommand(
794
+ pe,
795
+ (U) => U.target === c.current ? (U.preventDefault(), !0) : !1,
796
+ Y
797
+ ),
798
+ m.registerCommand(
799
+ ue,
800
+ z,
801
+ Y
802
+ ),
803
+ m.registerCommand(
804
+ ge,
805
+ z,
806
+ Y
807
+ ),
808
+ m.registerCommand(le, p, Y),
809
+ m.registerCommand(de, f, Y)
810
+ );
811
+ return M == null || M.addEventListener("contextmenu", N), () => {
812
+ P = !1, $(), M == null || M.removeEventListener("contextmenu", N);
813
+ };
814
+ }, [
815
+ v,
816
+ m,
817
+ D,
818
+ d,
819
+ e,
820
+ z,
821
+ p,
822
+ f,
823
+ w,
824
+ N,
825
+ h
826
+ ]);
827
+ const H = () => {
828
+ m.update(() => {
829
+ const P = q(e);
830
+ J(P) && P.setShowCaption(!0);
831
+ });
832
+ }, R = (P, M) => {
833
+ setTimeout(() => {
834
+ k(!1);
835
+ }, 200), m.update(() => {
836
+ const $ = q(e);
837
+ J($) && $.setWidthAndHeight(P, M);
838
+ });
839
+ }, E = () => {
840
+ k(!0);
841
+ }, T = d && W(X) && !D, ee = d || D;
842
+ return /* @__PURE__ */ C.jsx(Ee, { fallback: null, children: /* @__PURE__ */ C.jsxs(C.Fragment, { children: [
843
+ /* @__PURE__ */ C.jsx("div", { draggable: T, children: /* @__PURE__ */ C.jsx(
844
+ Se,
845
+ {
846
+ className: ee ? `focused ${W(X) ? "draggable" : ""}` : null,
847
+ src: l,
848
+ altText: t,
849
+ imageRef: c,
850
+ width: o,
851
+ height: n,
852
+ maxWidth: r
853
+ }
854
+ ) }),
855
+ u && /* @__PURE__ */ C.jsx("div", { className: "image-caption-container", children: /* @__PURE__ */ C.jsx(ve, { initialEditor: s, children: /* @__PURE__ */ C.jsx(
856
+ fe,
857
+ {
858
+ contentEditable: /* @__PURE__ */ C.jsx(De, { className: "ImageNode__contentEditable" }),
859
+ placeholder: /* @__PURE__ */ C.jsx(be, { className: "ImageNode__placeholder", children: "Enter a caption..." }),
860
+ ErrorBoundary: xe
861
+ }
862
+ ) }) }),
863
+ a && W(X) && ee && /* @__PURE__ */ C.jsx(
864
+ Me,
865
+ {
866
+ showCaption: u,
867
+ setShowCaption: H,
868
+ editor: m,
869
+ buttonRef: g,
870
+ imageRef: c,
871
+ maxWidth: r,
872
+ onResizeStart: E,
873
+ onResizeEnd: R,
874
+ captionsEnabled: i
875
+ }
876
+ )
877
+ ] }) });
878
+ }
879
+ export {
880
+ oe as RIGHT_CLICK_IMAGE_COMMAND,
881
+ Xe as default
882
+ };
883
+ //# sourceMappingURL=ImageComponent-c1cdbdf9.js.map