sykpcomposer 0.0.119 → 0.0.121

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