eddyter 1.4.15 → 1.4.17

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 (40) hide show
  1. package/dist/AIChatPlugin-2pIKhzIw.js +871 -0
  2. package/dist/{CommentBubblePlugin-VCZgBJUi.js → CommentBubblePlugin-J3r4kNGK.js} +1 -1
  3. package/dist/CommentPlugin-BbuE8_Aj.js +154 -0
  4. package/dist/LazyCodeMirror-DdCIk-83.js +21374 -0
  5. package/dist/{LazySignatureCanvas-RMigH9yY.js → LazySignatureCanvas-D1t8oQDK.js} +1 -1
  6. package/dist/NotePanelPlugin-C16G36Jd.js +31 -0
  7. package/dist/TextEnhancePlugin-BShY1r5J.js +198 -0
  8. package/dist/assets/style.css +1 -1
  9. package/dist/components/AiPlugin/commands.d.ts +4 -0
  10. package/dist/components/AiPlugin/index.d.ts +0 -4
  11. package/dist/components/NotePanelView/NotePanelView.d.ts +2 -1
  12. package/dist/{generateDocxThumbnail-fv5LNJIq.js → generateDocxThumbnail-Ve0zlObJ.js} +1 -1
  13. package/dist/{generatePdfThumbnail-C0rDYo5e.js → generatePdfThumbnail-EuSjdwzm.js} +1 -1
  14. package/dist/{generateXlsxThumbnail-C_vobxPD.js → generateXlsxThumbnail-C10kl6qh.js} +1 -1
  15. package/dist/{html2pdf.bundle.min-CFWvTTWI.js → html2pdf.bundle.min-BQaO0VTp.js} +1 -1
  16. package/dist/{index-MXcGtHZr.js → index-B8zPtmsK.js} +20 -20
  17. package/dist/{index-DKRhyxUF.js → index-BSgLtgyt.js} +26 -26
  18. package/dist/{index-o_C9Vw0n.js → index-ClsuXAKJ.js} +1 -1
  19. package/dist/index-CoLO4gm_.js +719 -0
  20. package/dist/{index-D5W6pnOr.js → index-CxOOJD40.js} +16224 -19078
  21. package/dist/index-D25uusM-.js +1430 -0
  22. package/dist/{index-Dhc1wcFH.js → index-gPq4n7_a.js} +34 -33
  23. package/dist/index.js +3 -3
  24. package/dist/marked.esm-Tjr8Gfse.js +1114 -0
  25. package/dist/nodes/NotePanelNode.d.ts +7 -2
  26. package/dist/plugins/AIChatPlugin.commands.d.ts +7 -0
  27. package/dist/plugins/AIChatPlugin.d.ts +0 -7
  28. package/dist/plugins/CommentPlugin.commands.d.ts +5 -0
  29. package/dist/plugins/CommentPlugin.d.ts +0 -5
  30. package/dist/plugins/NotePanelPlugin.commands.d.ts +6 -0
  31. package/dist/plugins/NotePanelPlugin.d.ts +0 -6
  32. package/dist/plugins/TextEnhancePlugin.commands.d.ts +1 -0
  33. package/dist/plugins/TextEnhancePlugin.d.ts +0 -1
  34. package/dist/square-DrMKkLmP.js +7 -0
  35. package/dist/useVoiceToText-DCddJzYF.js +153 -0
  36. package/dist/utils/notePanelExport.d.ts +11 -0
  37. package/dist/utils/notePanelPaste.d.ts +7 -0
  38. package/package.json +5 -2
  39. package/dist/LazyCodeMirror-C1bW4mVF.js +0 -44822
  40. package/dist/index-Ct2Ouofi.js +0 -1613
@@ -0,0 +1,1430 @@
1
+ import { jsx as e, jsxs as h, Fragment as Kt } from "react/jsx-runtime";
2
+ import { I as Me } from "./ImageResizer-BVwxL4Eh.js";
3
+ import { CodeNode as De } from "@lexical/code";
4
+ import { LinkNode as Le } from "@lexical/link";
5
+ import { AutoFocusPlugin as Ae } from "@lexical/react/LexicalAutoFocusPlugin";
6
+ import { useCollaborationContext as ze } from "@lexical/react/LexicalCollaborationContext";
7
+ import { useLexicalComposerContext as $e } from "@lexical/react/LexicalComposerContext";
8
+ import { ContentEditable as We } from "@lexical/react/LexicalContentEditable";
9
+ import { LexicalErrorBoundary as Te } from "@lexical/react/LexicalErrorBoundary";
10
+ import { HistoryPlugin as Oe } from "@lexical/react/LexicalHistoryPlugin";
11
+ import { LexicalNestedComposer as _e } from "@lexical/react/LexicalNestedComposer";
12
+ import { OnChangePlugin as je } from "@lexical/react/LexicalOnChangePlugin";
13
+ import { RichTextPlugin as Fe } from "@lexical/react/LexicalRichTextPlugin";
14
+ import { useLexicalEditable as He } from "@lexical/react/useLexicalEditable";
15
+ import { useLexicalNodeSelection as Ye } from "@lexical/react/useLexicalNodeSelection";
16
+ import { mergeRegister as Be } from "@lexical/utils";
17
+ import { $getRoot as qt, $isNodeSelection as st, $getSelection as tt, $isParagraphNode as _t, $setSelection as pt, $isRangeSelection as Xe, SELECTION_CHANGE_COMMAND as Ue, COMMAND_PRIORITY_LOW as et, CLICK_COMMAND as Ge, DRAGSTART_COMMAND as Ke, KEY_DELETE_COMMAND as qe, KEY_BACKSPACE_COMMAND as Ve, KEY_ENTER_COMMAND as Je, KEY_ESCAPE_COMMAND as Qe, $getNodeByKey as rt, RootNode as Ze, TextNode as tr, LineBreakNode as er, ParagraphNode as rr, createCommand as or } from "lexical";
18
+ import { useState as C, useEffect as X, useRef as B, useMemo as Vt, useCallback as R, useLayoutEffect as Jt, Suspense as ir } from "react";
19
+ import { c as Rt, D as oe, a as ie, b as ne, d as ce, e as ae, g as de, B as Qt, av as Pt, t as k, a6 as nr, q as cr, aw as V, ax as ar, ay as dr, az as sr, a8 as lr, a9 as ur, aa as mr, ab as gr, ac as hr, aA as fr, a4 as pr, S as br, aB as wr, aC as xr, X as yr, aD as Cr, aE as vr, l as Nr, aF as Rr, aG as kr } from "./index-CxOOJD40.js";
20
+ import { S as Ir } from "./square-DrMKkLmP.js";
21
+ const se = Rt("Crop", [
22
+ ["path", { d: "M6 2v14a2 2 0 0 0 2 2h14", key: "ron5a4" }],
23
+ ["path", { d: "M18 22V8a2 2 0 0 0-2-2H2", key: "7s9ehn" }]
24
+ ]);
25
+ const Er = Rt("Link2", [
26
+ ["path", { d: "M9 17H7A5 5 0 0 1 7 7h2", key: "8i5ue5" }],
27
+ ["path", { d: "M15 7h2a5 5 0 1 1 0 10h-2", key: "1b9ql8" }],
28
+ ["line", { x1: "8", x2: "16", y1: "12", y2: "12", key: "1jonct" }]
29
+ ]);
30
+ const Zt = Rt("RectangleHorizontal", [
31
+ ["rect", { width: "20", height: "12", x: "2", y: "6", rx: "2", key: "9lu3g6" }]
32
+ ]);
33
+ const te = Rt("RectangleVertical", [
34
+ ["rect", { width: "12", height: "20", x: "6", y: "2", rx: "2", key: "1oxtiu" }]
35
+ ]);
36
+ const Pr = Rt("RotateCcw", [
37
+ ["path", { d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8", key: "1357e3" }],
38
+ ["path", { d: "M3 3v5h5", key: "1xhq8a" }]
39
+ ]), Sr = ({
40
+ open: o,
41
+ onOpenChange: c,
42
+ oldImageUrl: s,
43
+ newImageUrl: f,
44
+ onReplace: y,
45
+ onCancel: N
46
+ }) => /* @__PURE__ */ e(oe, { open: o, onOpenChange: c, children: /* @__PURE__ */ h(ie, { className: "sm:max-w-[800px] max-h-[90vh] overflow-y-auto", children: [
47
+ /* @__PURE__ */ h(ne, { children: [
48
+ /* @__PURE__ */ h(ce, { className: "flex items-center gap-2 text-xl", children: [
49
+ /* @__PURE__ */ e("span", { className: "text-2xl", children: "🔄" }),
50
+ "Compare Images"
51
+ ] }),
52
+ /* @__PURE__ */ e(ae, { className: "text-sm pt-1", children: "Choose whether to replace the original image with the refined version." })
53
+ ] }),
54
+ /* @__PURE__ */ h("div", { className: "space-y-4 py-4", children: [
55
+ /* @__PURE__ */ e("div", { className: "grid grid-cols-2 gap-4", children: /* @__PURE__ */ h("div", { className: "space-y-2", children: [
56
+ /* @__PURE__ */ h("div", { className: "flex items-center justify-between", children: [
57
+ /* @__PURE__ */ e("span", { className: "text-sm font-semibold text-gray-700 dark:text-gray-300", children: "Refined Image" }),
58
+ /* @__PURE__ */ e("span", { className: "text-xs px-2 py-1 rounded-full bg-blue-100 dark:bg-blue-950/30 text-blue-600 dark:text-blue-400", children: "New" })
59
+ ] }),
60
+ /* @__PURE__ */ e("div", { className: "relative aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border-2 border-blue-500 dark:border-blue-600", children: /* @__PURE__ */ e(
61
+ "img",
62
+ {
63
+ src: f,
64
+ alt: "Refined",
65
+ className: "w-full h-full object-contain"
66
+ }
67
+ ) })
68
+ ] }) }),
69
+ /* @__PURE__ */ e("div", { className: "p-3 rounded-lg bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-800", children: /* @__PURE__ */ h("p", { className: "text-sm text-blue-800 dark:text-blue-200", children: [
70
+ /* @__PURE__ */ e("span", { className: "font-semibold", children: "Note:" }),
71
+ ' Clicking "Replace" will update the image in your document. This action cannot be undone.'
72
+ ] }) })
73
+ ] }),
74
+ /* @__PURE__ */ h(de, { className: "gap-2", children: [
75
+ /* @__PURE__ */ e(
76
+ Qt,
77
+ {
78
+ variant: "outline",
79
+ onClick: N,
80
+ children: "Keep Original"
81
+ }
82
+ ),
83
+ /* @__PURE__ */ h(
84
+ Qt,
85
+ {
86
+ onClick: y,
87
+ className: "bg-blue-500 hover:bg-blue-600 text-white",
88
+ children: [
89
+ /* @__PURE__ */ e("span", { className: "mr-2", children: "✓" }),
90
+ "Replace Image"
91
+ ]
92
+ }
93
+ )
94
+ ] })
95
+ ] }) });
96
+ function Mr({
97
+ caption: o
98
+ }) {
99
+ const [c, s] = C(""), [f, y] = C("");
100
+ return X(() => ((() => {
101
+ const E = o.getEditorState().read(() => qt().getTextContent()).split(" • ");
102
+ s(E[0] || ""), y(E[1] || "");
103
+ })(), o.registerUpdateListener(({ editorState: $ }) => {
104
+ const M = $.read(() => qt().getTextContent()).split(" • ");
105
+ s(M[0] || ""), y(M[1] || "");
106
+ })), [o]), /* @__PURE__ */ e("div", { className: "signature-caption-container", children: /* @__PURE__ */ h("div", { className: "signature-caption-info", children: [
107
+ c && /* @__PURE__ */ e("span", { className: "signature-user-name", children: c }),
108
+ c && f && /* @__PURE__ */ e("span", { className: "signature-separator" }),
109
+ f && /* @__PURE__ */ e("span", { className: "signature-timestamp", children: f }),
110
+ !c && !f && /* @__PURE__ */ e("span", { children: "Signature" })
111
+ ] }) });
112
+ }
113
+ const Dr = "/transform-image/";
114
+ function lt(o) {
115
+ if (!Pt || o.startsWith("data:") || o.toLowerCase().endsWith(".svg")) return !1;
116
+ try {
117
+ const c = new URL(o).origin, s = new URL(Pt).origin;
118
+ return c === s;
119
+ } catch {
120
+ return !1;
121
+ }
122
+ }
123
+ function le(o) {
124
+ if (!lt(o)) return null;
125
+ try {
126
+ const s = new URL(o).pathname.replace(/^\//, ""), f = "transform-image/";
127
+ return s.startsWith(f) ? s.slice(f.length) || null : s || null;
128
+ } catch {
129
+ return null;
130
+ }
131
+ }
132
+ function Lr(o, c) {
133
+ if (!lt(o)) return o;
134
+ const s = le(o);
135
+ if (!s) return o;
136
+ const f = `${c.x},${c.y},${c.width},${c.height}`;
137
+ return `${Pt.replace(/\/$/, "")}${Dr}${s}?crop=${f}`;
138
+ }
139
+ function ee(o) {
140
+ if (!lt(o)) return o;
141
+ try {
142
+ const c = new URL(o);
143
+ return c.searchParams.delete("crop"), c.toString();
144
+ } catch {
145
+ return o;
146
+ }
147
+ }
148
+ function vt(o) {
149
+ if (!lt(o)) return ee(o);
150
+ const c = le(o);
151
+ return c ? `${Pt.replace(/\/$/, "")}/${c}` : ee(o);
152
+ }
153
+ function Ar({
154
+ open: o,
155
+ onOpenChange: c,
156
+ src: s,
157
+ altText: f,
158
+ width: y,
159
+ height: N,
160
+ onCropApply: $
161
+ }) {
162
+ const [E, M] = C("freeform"), [ot, W] = C(s), [w, I] = C(!1), x = B(null), J = B(null), [i, A] = C({ x: 0, y: 0, width: 0, height: 0 }), [v, D] = C({ x: 0, y: 0, width: 0, height: 0 }), it = B(null), ut = Vt(() => typeof y == "number" && typeof N == "number" && N > 0 ? y / N : i.width > 0 && i.height > 0 ? i.width / i.height : null, [i.height, i.width, N, y]), bt = Vt(() => {
163
+ switch (E) {
164
+ case "original":
165
+ return ut;
166
+ case "1:1":
167
+ return 1;
168
+ case "4:3":
169
+ return 4 / 3;
170
+ case "16:9":
171
+ return 16 / 9;
172
+ case "3:4":
173
+ return 3 / 4;
174
+ case "9:16":
175
+ return 9 / 16;
176
+ default:
177
+ return null;
178
+ }
179
+ }, [ut, E]), d = 24, z = R(
180
+ (n) => {
181
+ let { x: g, y: p, width: u, height: b } = n;
182
+ const j = i.width, mt = i.height;
183
+ return g = Math.max(0, Math.min(g, j - d)), p = Math.max(0, Math.min(p, mt - d)), u = Math.max(d, Math.min(u, j - g)), b = Math.max(d, Math.min(b, mt - p)), { x: g, y: p, width: u, height: b };
184
+ },
185
+ [i.height, i.width]
186
+ ), wt = R(
187
+ (n) => {
188
+ if (i.width <= 0 || i.height <= 0) return;
189
+ if (n == null) {
190
+ D({
191
+ x: 0,
192
+ y: 0,
193
+ width: i.width,
194
+ height: i.height
195
+ });
196
+ return;
197
+ }
198
+ const g = i.width * 0.9, p = i.height * 0.9;
199
+ let u = g, b = u / n;
200
+ b > p && (b = p, u = b * n), D(
201
+ z({
202
+ x: (i.width - u) / 2,
203
+ y: (i.height - b) / 2,
204
+ width: u,
205
+ height: b
206
+ })
207
+ );
208
+ },
209
+ [i.height, i.width, z]
210
+ ), nt = R(() => {
211
+ const n = x.current, g = J.current;
212
+ if (!n || !g) return;
213
+ let p = 0, u = 0, b = g;
214
+ for (; b && b !== n; )
215
+ p += b.offsetLeft, u += b.offsetTop, b = b.offsetParent;
216
+ A({
217
+ x: p,
218
+ y: u,
219
+ width: g.offsetWidth,
220
+ height: g.offsetHeight
221
+ });
222
+ }, []), U = R(
223
+ (n) => {
224
+ i.width <= 0 || i.height <= 0 || (n.preventDefault(), n.stopPropagation(), n.target.setPointerCapture?.(n.pointerId), it.current = {
225
+ mode: "move",
226
+ startX: n.clientX,
227
+ startY: n.clientY,
228
+ initialRect: { ...v }
229
+ });
230
+ },
231
+ [i.height, i.width, v]
232
+ ), xt = R(
233
+ (n, g) => {
234
+ i.width <= 0 || i.height <= 0 || (n.preventDefault(), n.stopPropagation(), n.target.setPointerCapture?.(n.pointerId), it.current = {
235
+ mode: g,
236
+ startX: n.clientX,
237
+ startY: n.clientY,
238
+ initialRect: { ...v }
239
+ });
240
+ },
241
+ [i.height, i.width, v]
242
+ ), St = R(async () => {
243
+ if (i.width <= 0 || i.height <= 0) {
244
+ c(!1);
245
+ return;
246
+ }
247
+ const n = J.current;
248
+ if (!n || !n.naturalWidth || !n.naturalHeight) {
249
+ k.error("Could not read image dimensions");
250
+ return;
251
+ }
252
+ const g = n.naturalWidth / i.width, p = n.naturalHeight / i.height, u = {
253
+ x: Math.max(0, Math.round(v.x * g)),
254
+ y: Math.max(0, Math.round(v.y * p)),
255
+ width: Math.max(1, Math.round(v.width * g)),
256
+ height: Math.max(1, Math.round(v.height * p)),
257
+ naturalWidth: n.naturalWidth,
258
+ naturalHeight: n.naturalHeight
259
+ };
260
+ u.width = Math.min(u.width, n.naturalWidth - u.x), u.height = Math.min(u.height, n.naturalHeight - u.y), c(!1), Promise.resolve($(u));
261
+ }, [i, v, $, c]);
262
+ return X(() => {
263
+ o && (A({ x: 0, y: 0, width: 0, height: 0 }), D({ x: 0, y: 0, width: 0, height: 0 }), I(!1), W(vt(s)));
264
+ }, [o, s]), X(() => {
265
+ if (!o) return;
266
+ const n = x.current;
267
+ if (!n) return;
268
+ const g = new ResizeObserver(() => {
269
+ nt();
270
+ });
271
+ g.observe(n);
272
+ const p = J.current;
273
+ p && g.observe(p);
274
+ const u = () => nt();
275
+ return window.addEventListener("resize", u), () => {
276
+ g.disconnect(), window.removeEventListener("resize", u);
277
+ };
278
+ }, [o, nt]), X(() => {
279
+ if (!o) return;
280
+ const n = (p) => {
281
+ const u = it.current;
282
+ if (!u) return;
283
+ p.preventDefault();
284
+ const b = p.clientX - u.startX, j = p.clientY - u.startY, mt = i.width, gt = i.height, Q = bt ?? null, { x: G, y: ct, width: T, height: K } = u.initialRect;
285
+ if (u.mode === "move") {
286
+ const ht = Math.max(0, mt - T), kt = Math.max(0, gt - K);
287
+ D(
288
+ z({
289
+ x: Math.max(0, Math.min(ht, G + b)),
290
+ y: Math.max(0, Math.min(kt, ct + j)),
291
+ width: T,
292
+ height: K
293
+ })
294
+ );
295
+ return;
296
+ }
297
+ const S = u.mode;
298
+ let O = G, Z = ct, F = T, H = K;
299
+ S.includes("e") && (F = T + b), S.includes("w") && (O = G + b, F = T - b), S.includes("s") && (H = K + j), S.includes("n") && (Z = ct + j, H = K - j), Q != null && Q > 0 && (S === "e" || S === "w" ? (H = F / Q, S.includes("n") && (Z = ct + K - H)) : S === "n" || S === "s" ? (F = H * Q, S.includes("w") && (O = G + T - F)) : (H = F / Q, S.includes("n") && (Z = ct + K - H), S.includes("w") && (O = G + T - F))), D(z({ x: O, y: Z, width: F, height: H }));
300
+ }, g = () => {
301
+ it.current = null;
302
+ };
303
+ return window.addEventListener("pointermove", n), window.addEventListener("pointerup", g), () => {
304
+ window.removeEventListener("pointermove", n), window.removeEventListener("pointerup", g);
305
+ };
306
+ }, [
307
+ o,
308
+ i.width,
309
+ i.height,
310
+ bt,
311
+ z
312
+ ]), X(() => {
313
+ o && wt(bt);
314
+ }, [o, bt, i, wt]), /* @__PURE__ */ e(oe, { open: o, onOpenChange: c, children: /* @__PURE__ */ e(
315
+ ie,
316
+ {
317
+ className: "sm:cteditor-max-w-[860px] cteditor-max-w-[calc(100%-2rem)] cteditor-rounded-xl cteditor-overflow-hidden cteditor-p-0",
318
+ onClick: (n) => n.stopPropagation(),
319
+ onPointerDown: (n) => n.stopPropagation(),
320
+ children: /* @__PURE__ */ h("div", { className: "cteditor-grid md:cteditor-grid-cols-[1.4fr_320px]", children: [
321
+ /* @__PURE__ */ e("div", { className: "cteditor-bg-muted/20 cteditor-p-4 md:cteditor-p-6", children: /* @__PURE__ */ h(
322
+ "div",
323
+ {
324
+ ref: x,
325
+ className: "cteditor-relative cteditor-min-h-[340px] cteditor-rounded-lg cteditor-bg-black/70 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-select-none cteditor-touch-none",
326
+ children: [
327
+ /* @__PURE__ */ e("div", { className: "cteditor-overflow-hidden cteditor-rounded-lg cteditor-flex cteditor-items-center cteditor-justify-center cteditor-w-full", children: w ? /* @__PURE__ */ e("div", { className: "cteditor-text-sm cteditor-text-muted-foreground", children: "Failed to load image preview" }) : /* @__PURE__ */ e(
328
+ "img",
329
+ {
330
+ ref: J,
331
+ src: ot,
332
+ alt: f || "Crop preview",
333
+ className: "cteditor-max-w-full cteditor-max-h-[460px] cteditor-w-auto cteditor-h-auto cteditor-select-none cteditor-block",
334
+ draggable: !1,
335
+ onLoad: () => {
336
+ I(!1), nt();
337
+ },
338
+ onError: () => {
339
+ I(!0);
340
+ }
341
+ }
342
+ ) }),
343
+ i.width > 0 && i.height > 0 && !w && /* @__PURE__ */ h(
344
+ "div",
345
+ {
346
+ className: "cteditor-absolute cteditor-border-2 cteditor-border-blue-500 cteditor-cursor-move cteditor-select-none",
347
+ style: {
348
+ left: i.x + v.x,
349
+ top: i.y + v.y,
350
+ width: v.width,
351
+ height: v.height
352
+ },
353
+ children: [
354
+ /* @__PURE__ */ e(
355
+ "div",
356
+ {
357
+ className: "cteditor-absolute cteditor-inset-0 cteditor-grid cteditor-grid-cols-3 cteditor-grid-rows-3 cteditor-pointer-events-none",
358
+ "aria-hidden": !0,
359
+ children: Array.from({ length: 9 }).map((n, g) => /* @__PURE__ */ e(
360
+ "div",
361
+ {
362
+ className: "cteditor-border cteditor-border-white/30"
363
+ },
364
+ g
365
+ ))
366
+ }
367
+ ),
368
+ /* @__PURE__ */ e(
369
+ "div",
370
+ {
371
+ className: "cteditor-absolute cteditor-inset-0 cteditor-pointer-events-auto",
372
+ onPointerDown: U,
373
+ "aria-label": "Move crop area"
374
+ }
375
+ ),
376
+ [
377
+ ["n", "cteditor-top-0 cteditor-left-1/2 cteditor--translate-x-1/2 cteditor--translate-y-1/2", "cteditor-cursor-n-resize", "cteditor-w-8 cteditor-h-2"],
378
+ ["s", "cteditor-bottom-0 cteditor-left-1/2 cteditor--translate-x-1/2 cteditor-translate-y-1/2", "cteditor-cursor-s-resize", "cteditor-w-8 cteditor-h-2"],
379
+ ["e", "cteditor-right-0 cteditor-top-1/2 cteditor-translate-x-1/2 cteditor--translate-y-1/2", "cteditor-cursor-e-resize", "cteditor-w-2 cteditor-h-8"],
380
+ ["w", "cteditor-left-0 cteditor-top-1/2 cteditor--translate-x-1/2 cteditor--translate-y-1/2", "cteditor-cursor-w-resize", "cteditor-w-2 cteditor-h-8"],
381
+ ["nw", "cteditor-left-0 cteditor-top-0 cteditor--translate-x-1/2 cteditor--translate-y-1/2", "cteditor-cursor-nw-resize", "cteditor-size-4"],
382
+ ["ne", "cteditor-right-0 cteditor-top-0 cteditor-translate-x-1/2 cteditor--translate-y-1/2", "cteditor-cursor-ne-resize", "cteditor-size-4"],
383
+ ["sw", "cteditor-left-0 cteditor-bottom-0 cteditor--translate-x-1/2 cteditor-translate-y-1/2", "cteditor-cursor-sw-resize", "cteditor-size-4"],
384
+ ["se", "cteditor-right-0 cteditor-bottom-0 cteditor-translate-x-1/2 cteditor-translate-y-1/2", "cteditor-cursor-se-resize", "cteditor-size-4"]
385
+ ].map(([n, g, p, u]) => /* @__PURE__ */ e(
386
+ "div",
387
+ {
388
+ className: `cteditor-absolute cteditor-border-2 cteditor-border-white cteditor-bg-blue-500 cteditor-rounded-sm cteditor-pointer-events-auto cteditor-shadow ${g} ${p} ${u}`,
389
+ onPointerDown: (b) => xt(b, n),
390
+ "aria-label": `Resize ${n}`
391
+ },
392
+ n
393
+ ))
394
+ ]
395
+ }
396
+ )
397
+ ]
398
+ }
399
+ ) }),
400
+ /* @__PURE__ */ h("div", { className: "cteditor-p-4 md:cteditor-p-5 cteditor-border-l cteditor-border-border cteditor-bg-background", children: [
401
+ /* @__PURE__ */ h(ne, { className: "cteditor-mb-4 cteditor-space-y-1", children: [
402
+ /* @__PURE__ */ e(ce, { children: "Crop" }),
403
+ /* @__PURE__ */ e(ae, { children: "Choose an aspect ratio and adjust the crop area, then click Apply." })
404
+ ] }),
405
+ /* @__PURE__ */ h("div", { className: "cteditor-space-y-4", children: [
406
+ /* @__PURE__ */ h("div", { children: [
407
+ /* @__PURE__ */ e("p", { className: "cteditor-text-sm cteditor-font-medium cteditor-mb-2", children: "Aspect ratio" }),
408
+ /* @__PURE__ */ e("div", { className: "cteditor-grid cteditor-grid-cols-3 cteditor-gap-2", children: [
409
+ { id: "freeform", label: "Freeform", icon: se },
410
+ { id: "original", label: "Original", icon: nr },
411
+ { id: "1:1", label: "1:1", icon: Ir },
412
+ { id: "4:3", label: "4:3", icon: Zt },
413
+ { id: "16:9", label: "16:9", icon: Zt },
414
+ { id: "3:4", label: "3:4", icon: te },
415
+ { id: "9:16", label: "9:16", icon: te }
416
+ ].map((n) => {
417
+ const g = n.icon, p = E === n.id;
418
+ return /* @__PURE__ */ h(
419
+ "button",
420
+ {
421
+ type: "button",
422
+ onClick: () => {
423
+ M(n.id);
424
+ },
425
+ className: `cteditor-h-20 cteditor-rounded-md cteditor-border cteditor-text-sm cteditor-transition-colors cteditor-flex cteditor-flex-col cteditor-items-center cteditor-justify-center cteditor-gap-1.5 ${p ? "cteditor-border-primary cteditor-bg-primary/10 cteditor-text-primary" : "cteditor-border-border hover:cteditor-bg-accent"}`,
426
+ children: [
427
+ /* @__PURE__ */ e(g, { className: "cteditor-w-4 cteditor-h-4" }),
428
+ /* @__PURE__ */ e("span", { children: n.label })
429
+ ]
430
+ },
431
+ n.id
432
+ );
433
+ }) })
434
+ ] }),
435
+ /* @__PURE__ */ h("div", { className: "cteditor-rounded-md cteditor-border cteditor-border-border cteditor-p-3 cteditor-bg-muted/20 cteditor-space-y-2", children: [
436
+ /* @__PURE__ */ h("div", { children: [
437
+ /* @__PURE__ */ e("p", { className: "cteditor-text-xs cteditor-text-muted-foreground cteditor-mb-0.5", children: "Crop size" }),
438
+ /* @__PURE__ */ h("p", { className: "cteditor-text-sm cteditor-font-medium", children: [
439
+ Math.round(v.width),
440
+ " × ",
441
+ Math.round(v.height),
442
+ " px"
443
+ ] })
444
+ ] }),
445
+ /* @__PURE__ */ h("div", { children: [
446
+ /* @__PURE__ */ e("p", { className: "cteditor-text-xs cteditor-text-muted-foreground cteditor-mb-0.5", children: "Aspect ratio" }),
447
+ /* @__PURE__ */ e("p", { className: "cteditor-text-sm", children: E === "freeform" ? "Free" : E === "original" ? "Original" : E })
448
+ ] })
449
+ ] })
450
+ ] }),
451
+ /* @__PURE__ */ h(de, { className: "cteditor-gap-2 cteditor-mt-4", children: [
452
+ /* @__PURE__ */ e(
453
+ "button",
454
+ {
455
+ type: "button",
456
+ onClick: () => {
457
+ M("freeform"), wt(null);
458
+ },
459
+ className: "cteditor-px-3 cteditor-py-2 cteditor-text-sm cteditor-rounded-md cteditor-bg-background cteditor-border cteditor-border-border cteditor-text-foreground hover:cteditor-bg-accent cteditor-transition-colors",
460
+ children: "Reset"
461
+ }
462
+ ),
463
+ /* @__PURE__ */ e(
464
+ "button",
465
+ {
466
+ type: "button",
467
+ onClick: () => c(!1),
468
+ className: "cteditor-px-3 cteditor-py-2 cteditor-text-sm cteditor-rounded-md cteditor-bg-background cteditor-border cteditor-border-border cteditor-text-foreground hover:cteditor-bg-accent cteditor-transition-colors",
469
+ children: "Cancel"
470
+ }
471
+ ),
472
+ /* @__PURE__ */ e(
473
+ "button",
474
+ {
475
+ type: "button",
476
+ onClick: St,
477
+ className: "cteditor-px-3 cteditor-py-2 cteditor-text-sm cteditor-rounded-md cteditor-bg-primary cteditor-text-primary-foreground hover:cteditor-bg-primary/90 cteditor-transition-colors",
478
+ children: "Apply"
479
+ }
480
+ )
481
+ ] })
482
+ ] })
483
+ ] })
484
+ }
485
+ ) });
486
+ }
487
+ const Nt = /* @__PURE__ */ new Set(), re = or("RIGHT_CLICK_IMAGE_COMMAND");
488
+ function zr(o) {
489
+ if (!Nt.has(o))
490
+ throw new Promise((c) => {
491
+ const s = new Image();
492
+ s.src = o, s.onload = () => {
493
+ Nt.add(o), c(null);
494
+ }, s.onerror = () => {
495
+ Nt.add(o);
496
+ };
497
+ });
498
+ }
499
+ function $r({
500
+ altText: o,
501
+ className: c,
502
+ imageRef: s,
503
+ src: f,
504
+ width: y,
505
+ height: N,
506
+ maxWidth: $,
507
+ onError: E,
508
+ onLoad: M
509
+ }) {
510
+ zr(f);
511
+ const ot = typeof y == "number", W = typeof N == "number", w = ot && W, I = ot ? y : "auto", x = W ? N : "auto";
512
+ return /* @__PURE__ */ e(
513
+ "img",
514
+ {
515
+ className: c || void 0,
516
+ src: f,
517
+ alt: o,
518
+ ref: s,
519
+ style: w ? {
520
+ width: I,
521
+ height: "auto",
522
+ aspectRatio: `${I} / ${x}`,
523
+ maxWidth: "100%"
524
+ } : ot ? {
525
+ // Only width known (e.g. bogus height stripped from source HTML):
526
+ // fix the width and let the browser compute height naturally.
527
+ width: I,
528
+ height: "auto",
529
+ maxWidth: "100%"
530
+ } : W ? {
531
+ // Only height known: fix height, let browser compute width.
532
+ width: "auto",
533
+ height: x,
534
+ maxWidth: "100%"
535
+ } : {
536
+ // No dimensions specified - use original image size.
537
+ height: "auto"
538
+ },
539
+ onError: E,
540
+ onLoad: M,
541
+ draggable: "false"
542
+ }
543
+ );
544
+ }
545
+ function Wr() {
546
+ return /* @__PURE__ */ e(
547
+ "img",
548
+ {
549
+ src: "",
550
+ style: {
551
+ height: 200,
552
+ opacity: 0.2,
553
+ width: 200
554
+ },
555
+ draggable: "false"
556
+ }
557
+ );
558
+ }
559
+ function Tr(o, c = 12e3) {
560
+ return new Promise((s, f) => {
561
+ const y = new Image();
562
+ let N = !1;
563
+ const $ = window.setTimeout(() => {
564
+ N || (N = !0, f(new Error("Image load timeout")));
565
+ }, c);
566
+ y.onload = () => {
567
+ N || (N = !0, window.clearTimeout($), s());
568
+ }, y.onerror = () => {
569
+ N || (N = !0, window.clearTimeout($), f(new Error("Image failed to load")));
570
+ }, y.src = o;
571
+ });
572
+ }
573
+ function no({
574
+ src: o,
575
+ altText: c,
576
+ nodeKey: s,
577
+ width: f,
578
+ height: y,
579
+ maxWidth: N,
580
+ resizable: $,
581
+ showCaption: E,
582
+ caption: M,
583
+ captionsEnabled: ot,
584
+ originalPrompt: W,
585
+ position: w = "none",
586
+ linkUrl: I
587
+ }) {
588
+ const x = B(null), J = B(null), [i, A, v] = Ye(s), [D, it] = C(!1), ut = B(!1), { isCollabActive: bt } = ze(), [d] = $e(), [z, wt] = C(null), nt = B(null), [U, xt] = C(!1), St = He(), [n, g] = C(!1), [p, u] = C(""), [b, j] = C(!1), [mt, gt] = C(!1), [Q, G] = C(""), [ct, T] = C(""), [K, S] = C(!1), O = B(null), [Z, F] = C(0), [H, ht] = C(!1), kt = B(null), [ue, yt] = C(null), [Mt, Ct] = C(!1), [jt, Ft] = C(!1), at = B(null), It = cr()?.apiKey, Dt = Z > 0 && Z < 350;
589
+ Jt(() => {
590
+ if (!i || !st(z) || U) {
591
+ yt(null);
592
+ return;
593
+ }
594
+ const t = kt.current, r = d.getRootElement(), a = t?.parentElement;
595
+ if (!t || !r || !a) {
596
+ yt(null);
597
+ return;
598
+ }
599
+ const l = r.getBoundingClientRect(), m = a.getBoundingClientRect(), P = t.getBoundingClientRect(), L = 8, _ = P.width;
600
+ if (_ <= 0) {
601
+ yt(null);
602
+ return;
603
+ }
604
+ if (Dt) {
605
+ const dt = m.left + m.width / 2 - _ / 2, Y = Math.max(l.left + L, Math.min(dt, l.right - L - _));
606
+ yt({
607
+ left: Y - m.left,
608
+ bottom: 0,
609
+ right: "auto",
610
+ transform: "translateY(100%) translateY(4px)"
611
+ });
612
+ } else {
613
+ const dt = m.right - L - _, Y = Math.max(l.left + L, Math.min(dt, l.right - L - _));
614
+ yt({
615
+ left: Y - m.left,
616
+ top: L,
617
+ right: "auto"
618
+ });
619
+ }
620
+ }, [i, z, U, Dt, d, Z]), X(() => {
621
+ if (x.current) {
622
+ const t = () => {
623
+ ut.current || x.current && F(x.current.offsetWidth);
624
+ };
625
+ t();
626
+ const r = new ResizeObserver(t);
627
+ return r.observe(x.current), () => r.disconnect();
628
+ }
629
+ }, [f, y, i]), Jt(() => {
630
+ if ((w === "left" || w === "right") && typeof f == "number" && x.current) {
631
+ const t = x.current.closest(".editor-image"), r = t?.parentElement, a = d.getRootElement(), l = a ? a.getBoundingClientRect().width : f + 32, m = `${Math.min(f + 32, l)}px`;
632
+ return t && (t.style.removeProperty("display"), t.style.setProperty("max-width", m, "important")), r && r.style.setProperty("max-width", m, "important"), () => {
633
+ t && (t.style.removeProperty("max-width"), t.style.removeProperty("display")), r && r.style.removeProperty("max-width");
634
+ };
635
+ }
636
+ }, [w, f, d]);
637
+ const Lt = R(
638
+ (t) => {
639
+ const r = tt();
640
+ return i && st(r) && (t.preventDefault(), d.update(() => {
641
+ r.getNodes().forEach((l) => {
642
+ if (V(l)) {
643
+ const m = l.getParent();
644
+ l.remove(), m && _t(m) && m.getChildrenSize() === 0 && m.setFormat("left");
645
+ }
646
+ });
647
+ })), !1;
648
+ },
649
+ [d, i]
650
+ ), Ht = R(
651
+ (t) => {
652
+ const r = tt(), a = J.current;
653
+ if (i && st(r) && r.getNodes().length === 1) {
654
+ if (E)
655
+ return pt(null), t.preventDefault(), M.focus(), !0;
656
+ if (a !== null && a !== document.activeElement)
657
+ return t.preventDefault(), a.focus(), !0;
658
+ }
659
+ return !1;
660
+ },
661
+ [M, i, E]
662
+ ), Yt = R(
663
+ (t) => nt.current === M || J.current === t.target ? (pt(null), d.update(() => {
664
+ A(!0);
665
+ const r = d.getRootElement();
666
+ r !== null && r.focus();
667
+ }), !0) : !1,
668
+ [M, d, A]
669
+ ), At = R(
670
+ (t) => {
671
+ const r = t;
672
+ if (D)
673
+ return !0;
674
+ const a = r.target;
675
+ if (a.closest("button") && x.current && a.closest(".editor-image") === x.current.closest(".editor-image"))
676
+ return !0;
677
+ const l = a === x.current;
678
+ let m = !1;
679
+ if (!l && x.current) {
680
+ const P = x.current.getBoundingClientRect();
681
+ m = r.clientX >= P.left && r.clientX <= P.right && r.clientY >= P.top && r.clientY <= P.bottom;
682
+ }
683
+ return l || m ? (r.shiftKey ? A(!i) : (v(), A(!0)), !0) : !1;
684
+ },
685
+ [D, i, A, v]
686
+ ), zt = R(
687
+ (t) => {
688
+ d.getEditorState().read(() => {
689
+ const r = tt();
690
+ t.target.tagName === "IMG" && Xe(r) && r.getNodes().length === 1 && d.dispatchCommand(
691
+ re,
692
+ t
693
+ );
694
+ });
695
+ },
696
+ [d]
697
+ );
698
+ X(() => {
699
+ let t = !0;
700
+ const r = d.getRootElement(), a = Be(
701
+ d.registerUpdateListener(({ editorState: l }) => {
702
+ t && wt(l.read(() => tt()));
703
+ }),
704
+ d.registerCommand(
705
+ Ue,
706
+ (l, m) => (nt.current = m, !1),
707
+ et
708
+ ),
709
+ d.registerCommand(
710
+ Ge,
711
+ At,
712
+ et
713
+ ),
714
+ d.registerCommand(
715
+ re,
716
+ At,
717
+ et
718
+ ),
719
+ d.registerCommand(
720
+ Ke,
721
+ (l) => l.target === x.current ? (l.preventDefault(), !0) : !1,
722
+ et
723
+ ),
724
+ d.registerCommand(
725
+ qe,
726
+ Lt,
727
+ et
728
+ ),
729
+ d.registerCommand(
730
+ Ve,
731
+ Lt,
732
+ et
733
+ ),
734
+ d.registerCommand(Je, Ht, et),
735
+ d.registerCommand(
736
+ Qe,
737
+ Yt,
738
+ et
739
+ )
740
+ );
741
+ return r?.addEventListener("contextmenu", zt), () => {
742
+ t = !1, a(), r?.removeEventListener("contextmenu", zt);
743
+ };
744
+ }, [
745
+ v,
746
+ d,
747
+ D,
748
+ i,
749
+ s,
750
+ Lt,
751
+ Ht,
752
+ Yt,
753
+ At,
754
+ zt,
755
+ A
756
+ ]);
757
+ const me = () => {
758
+ d.update(() => {
759
+ const t = rt(s);
760
+ V(t) && t.setShowCaption(!0);
761
+ });
762
+ }, ge = (t, r) => {
763
+ ut.current = !1, setTimeout(() => {
764
+ it(!1);
765
+ }, 200), d.update(() => {
766
+ const a = rt(s);
767
+ V(a) && a.setWidthAndHeight(t, r);
768
+ });
769
+ }, he = () => {
770
+ ut.current = !0, it(!0);
771
+ }, fe = (t) => {
772
+ if (t.preventDefault(), t.stopPropagation(), o.startsWith("data:")) {
773
+ const r = window.open("", "_blank");
774
+ r && (r.document.write(`
775
+ <!DOCTYPE html>
776
+ <html>
777
+ <head>
778
+ <title>${c || "Image"}</title>
779
+ <style>
780
+ body {
781
+ margin: 0;
782
+ display: flex;
783
+ justify-content: center;
784
+ align-items: center;
785
+ min-height: 100vh;
786
+ background-color: #1a1a1a;
787
+ }
788
+ img {
789
+ max-width: 100%;
790
+ max-height: 100vh;
791
+ object-fit: contain;
792
+ }
793
+ </style>
794
+ </head>
795
+ <body>
796
+ <img src="${o}" alt="${c || "Image"}" />
797
+ </body>
798
+ </html>
799
+ `), r.document.close());
800
+ } else
801
+ window.open(o, "_blank");
802
+ }, pe = (t) => {
803
+ t.preventDefault(), t.stopPropagation(), d.update(() => {
804
+ const r = rt(s);
805
+ if (V(r)) {
806
+ const a = r.getParent();
807
+ r.remove(), a && _t(a) && a.getChildrenSize() === 0 && a.setFormat("left");
808
+ }
809
+ });
810
+ }, ft = (t, r) => {
811
+ t.preventDefault(), t.stopPropagation(), d.update(() => {
812
+ const a = rt(s);
813
+ if (V(a)) {
814
+ a.setPosition(r);
815
+ const l = a.getParent();
816
+ l && _t(l) && (r === "left" ? l.setFormat("left") : r === "right" ? l.setFormat("right") : l.setFormat(""));
817
+ }
818
+ });
819
+ }, be = (t) => {
820
+ t.preventDefault(), t.stopPropagation(), g(!n);
821
+ }, we = R((t) => {
822
+ t.preventDefault(), t.stopPropagation(), ht(!0);
823
+ }, []), xe = R(
824
+ (t) => {
825
+ t.preventDefault(), t.stopPropagation();
826
+ const r = vt(o);
827
+ if (!(lt(o) && o !== r) && !(typeof f == "number" || typeof y == "number"))
828
+ return;
829
+ d.update(
830
+ () => {
831
+ const P = rt(s);
832
+ if (!V(P)) return;
833
+ P.setSrc(r), P.setWidthAndHeight("inherit", "inherit");
834
+ const L = tt();
835
+ L && pt(L.clone());
836
+ },
837
+ { tag: "image-reset" }
838
+ );
839
+ const m = x.current;
840
+ m && requestAnimationFrame(() => {
841
+ m.src = r, m.style.removeProperty("width"), m.style.removeProperty("height");
842
+ }), k.success("Image reset to original size and crop");
843
+ },
844
+ [d, s, o, f, y]
845
+ ), ye = R(
846
+ async (t) => {
847
+ let r = o;
848
+ if (lt(o))
849
+ r = vt(o);
850
+ else {
851
+ if (!It) {
852
+ k.error("API key is required to upload and crop external images.");
853
+ return;
854
+ }
855
+ const l = k.loading("Uploading image…");
856
+ try {
857
+ r = (await ar.post(
858
+ dr.project.fileUploadFromUrl,
859
+ { url: o, prefix: "uploads" },
860
+ { headers: { "x-api-key": It } }
861
+ )).data.fileUrl, k.dismiss(l);
862
+ } catch {
863
+ k.dismiss(l), k.error("Failed to upload image. Try again.");
864
+ return;
865
+ }
866
+ }
867
+ const a = Lr(r, t);
868
+ if (a === r) {
869
+ k.error("Cropping is only supported for images hosted on the CDN.");
870
+ return;
871
+ }
872
+ Ct(!0), at.current = a;
873
+ try {
874
+ await Tr(a), Nt.add(a), d.update(() => {
875
+ const l = rt(s);
876
+ if (!V(l)) return;
877
+ l.setSrc(a), l.setWidthAndHeight(t.width, t.height);
878
+ const m = tt();
879
+ m && pt(m.clone());
880
+ }), k.success("Image cropped");
881
+ } catch {
882
+ at.current = null, Ct(!1), k.error("Crop failed to load. Showing original image.");
883
+ }
884
+ },
885
+ [d, s, o, It]
886
+ ), Ce = R(() => {
887
+ I && !i && (O.current = setTimeout(() => {
888
+ S(!0);
889
+ }, 300));
890
+ }, [I, i]), ve = R(() => {
891
+ O.current && (clearTimeout(O.current), O.current = null), S(!1);
892
+ }, []), Bt = R((t) => {
893
+ t.preventDefault(), t.stopPropagation(), I && window.open(I, "_blank", "noopener,noreferrer");
894
+ }, [I]);
895
+ X(() => () => {
896
+ O.current && clearTimeout(O.current);
897
+ }, []), X(() => {
898
+ i || ht(!1);
899
+ }, [i]), X(() => {
900
+ xt(!1), Ft(!1);
901
+ }, [o]);
902
+ const Xt = async () => {
903
+ if (!p.trim() || b) return;
904
+ j(!0);
905
+ const t = k.loading("Refining image...", {
906
+ description: "This may take 10-30 seconds. Please wait."
907
+ });
908
+ try {
909
+ let r = p.trim();
910
+ const l = p.trim().replace(/^(add|also add|include|with|and)\s+(some|a|an)\s+/gi, "").replace(/^(add|also add|include|with|and)\s+/gi, "").trim(), m = (Y) => {
911
+ const Tt = Y.toLowerCase();
912
+ return [
913
+ "article",
914
+ "write",
915
+ "blog",
916
+ "post",
917
+ "essay",
918
+ "content",
919
+ "generate an article",
920
+ "create an article",
921
+ "write about",
922
+ "and add some pictures",
923
+ "with pictures",
924
+ "with images",
925
+ "add some images",
926
+ "include images",
927
+ "include pictures"
928
+ ].some((Et) => Tt.includes(Et));
929
+ };
930
+ let P = "";
931
+ if (W && W.trim()) {
932
+ const Y = W.trim();
933
+ m(Y) && c && c !== "Generated image" && c.trim() ? P = c.trim() : P = Y;
934
+ } else c && c !== "Generated image" && c.trim() && (P = c.trim());
935
+ P ? r = `${P} with ${l}` : r = l;
936
+ const L = await fetch(`${Nr}/agent/stream`, {
937
+ method: "POST",
938
+ headers: { "Content-Type": "application/json" },
939
+ body: JSON.stringify({
940
+ type: "general",
941
+ query: `Generate Image: ${r}`,
942
+ model: "openai",
943
+ api_key: It || ""
944
+ })
945
+ });
946
+ if (!L.ok)
947
+ throw new Error(`Image service error: ${L.status}`);
948
+ const _ = L.body?.getReader(), Wt = new TextDecoder();
949
+ if (!_) throw new Error("Stream reader not available");
950
+ let dt = null;
951
+ t: for (; ; ) {
952
+ const { done: Y, value: Tt } = await _.read();
953
+ if (Y) break;
954
+ const Gt = Wt.decode(Tt, { stream: !0 }).split(`
955
+ `);
956
+ for (const Et of Gt) {
957
+ if (!Et.startsWith("data: ")) continue;
958
+ const Ot = Et.slice(6).trim();
959
+ if (!(!Ot || Ot === "[DONE]"))
960
+ try {
961
+ const q = JSON.parse(Ot);
962
+ if (q.type === "image_ready") {
963
+ dt = q.url, _.cancel();
964
+ break t;
965
+ } else {
966
+ if (q.type === "image_failed")
967
+ throw _.cancel(), new Error(q.error || "Image generation failed");
968
+ if (q.type === "error")
969
+ throw _.cancel(), new Error(q.message || "Image generation failed");
970
+ }
971
+ } catch (q) {
972
+ if (q instanceof SyntaxError) continue;
973
+ throw q;
974
+ }
975
+ }
976
+ }
977
+ if (!dt)
978
+ throw new Error("Failed to generate image - no image received");
979
+ k.dismiss(t), k.success("Image refined successfully!", {
980
+ description: "Compare the images and choose which to keep."
981
+ }), G(dt), T(r), gt(!0), u(""), g(!1);
982
+ } catch (r) {
983
+ if (k.dismiss(t), r instanceof Rr) {
984
+ const a = r.code === "API_KEYS_DISABLED" ? "API Keys Disabled" : "API Key Required";
985
+ k.error(a, {
986
+ description: r.message,
987
+ duration: 8e3
988
+ });
989
+ } else r instanceof kr ? k.error("Credits Issue", {
990
+ description: r.message,
991
+ duration: 8e3
992
+ }) : k.error("Failed to refine image", {
993
+ description: r instanceof Error ? r.message : "Unknown error. Please try again."
994
+ });
995
+ } finally {
996
+ j(!1);
997
+ }
998
+ }, Ne = () => {
999
+ d.update(() => {
1000
+ const t = rt(s);
1001
+ if (V(t)) {
1002
+ t.setSrc(Q), t.setOriginalPrompt(ct);
1003
+ const r = tt();
1004
+ r && pt(r.clone());
1005
+ }
1006
+ }), gt(!1), G(""), T(""), k.success("Image replaced successfully!", {
1007
+ description: "The image has been updated with the refined version."
1008
+ });
1009
+ }, Re = () => {
1010
+ gt(!1), G(""), T("");
1011
+ }, ke = i && st(z) && !D, Ut = (i || D) && St, $t = vt(o), Ie = R(() => {
1012
+ at.current && o === at.current && (Nt.add(o), at.current = null, Ct(!1));
1013
+ }, [o]), Ee = R(() => {
1014
+ if (!jt && lt(o) && o !== $t) {
1015
+ Ft(!0), xt(!1), Ct(!1), at.current = null, d.update(() => {
1016
+ const r = rt(s);
1017
+ if (!V(r)) return;
1018
+ r.setSrc($t);
1019
+ const a = tt();
1020
+ a && pt(a.clone());
1021
+ }), k.error("Cropped image failed. Showing original image instead.");
1022
+ return;
1023
+ }
1024
+ Ct(!1), at.current = null, xt(!0);
1025
+ }, [jt, o, $t, d, s]), Pe = () => w === "left" || w === "right" ? {
1026
+ position: "relative",
1027
+ display: "block",
1028
+ width: "100%"
1029
+ // Fill the floated container
1030
+ } : w === "full" ? {
1031
+ position: "relative",
1032
+ display: "block",
1033
+ width: "fit-content",
1034
+ margin: "0 auto"
1035
+ } : w === "inline-left" ? {
1036
+ position: "relative",
1037
+ display: "block",
1038
+ width: "fit-content",
1039
+ marginRight: "auto"
1040
+ } : w === "inline-center" ? {
1041
+ position: "relative",
1042
+ display: "block",
1043
+ width: "fit-content",
1044
+ margin: "0 auto"
1045
+ } : w === "inline-right" ? {
1046
+ position: "relative",
1047
+ display: "block",
1048
+ width: "fit-content",
1049
+ marginLeft: "auto"
1050
+ } : {
1051
+ position: "relative",
1052
+ display: "inline-block"
1053
+ }, Se = R(
1054
+ (t) => {
1055
+ if (D || t.target.closest("button"))
1056
+ return;
1057
+ const a = t.target === x.current;
1058
+ let l = !1;
1059
+ if (!a && x.current) {
1060
+ const m = x.current.getBoundingClientRect();
1061
+ l = t.clientX >= m.left && t.clientX <= m.right && t.clientY >= m.top && t.clientY <= m.bottom;
1062
+ }
1063
+ !a && !l || (t.stopPropagation(), t.shiftKey ? A(!i) : (v(), A(!0)));
1064
+ },
1065
+ [D, i, A, v]
1066
+ );
1067
+ return /* @__PURE__ */ e(ir, { fallback: null, children: /* @__PURE__ */ h(Kt, { children: [
1068
+ /* @__PURE__ */ h(
1069
+ "div",
1070
+ {
1071
+ draggable: ke,
1072
+ style: Pe(),
1073
+ onClick: Se,
1074
+ onMouseEnter: Ce,
1075
+ onMouseLeave: ve,
1076
+ children: [
1077
+ U ? /* @__PURE__ */ e(Wr, {}) : /* @__PURE__ */ e(
1078
+ $r,
1079
+ {
1080
+ className: Ut ? `focused ${st(z) ? "draggable" : ""}` : I ? "cteditor-cursor-pointer" : null,
1081
+ src: o,
1082
+ altText: c,
1083
+ imageRef: x,
1084
+ width: f,
1085
+ height: y,
1086
+ maxWidth: N,
1087
+ onLoad: Ie,
1088
+ onError: Ee
1089
+ }
1090
+ ),
1091
+ Mt && !U && /* @__PURE__ */ h("div", { className: "cteditor-absolute cteditor-inset-0 cteditor-flex cteditor-flex-col cteditor-items-center cteditor-justify-center cteditor-rounded-lg cteditor-bg-background/50 cteditor-backdrop-blur-[1px] cteditor-pointer-events-none", children: [
1092
+ /* @__PURE__ */ e(sr, { className: "cteditor-w-10 cteditor-h-10 cteditor-text-foreground cteditor-animate-spin cteditor-mb-2", "aria-hidden": !0 }),
1093
+ /* @__PURE__ */ e("span", { className: "cteditor-text-sm cteditor-font-medium cteditor-text-foreground", children: "Applying crop..." })
1094
+ ] }),
1095
+ K && I && !i && /* @__PURE__ */ h(
1096
+ "div",
1097
+ {
1098
+ className: "cteditor-absolute cteditor-bottom-2 cteditor-left-2 cteditor-right-2 cteditor-bg-background cteditor-rounded-lg cteditor-shadow-lg cteditor-border cteditor-border-border cteditor-p-2 cteditor-flex cteditor-items-center cteditor-gap-2",
1099
+ style: { zIndex: 10 },
1100
+ children: [
1101
+ /* @__PURE__ */ e(Er, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-muted-foreground cteditor-flex-shrink-0" }),
1102
+ /* @__PURE__ */ e("span", { className: "cteditor-text-sm cteditor-text-foreground cteditor-truncate cteditor-flex-1", children: I }),
1103
+ /* @__PURE__ */ e(
1104
+ "button",
1105
+ {
1106
+ type: "button",
1107
+ onClick: Bt,
1108
+ className: "cteditor-px-2 cteditor-py-1.5 cteditor-text-xs cteditor-rounded cteditor-bg-primary cteditor-text-primary-foreground hover:cteditor-bg-primary/90 cteditor-transition-colors cteditor-flex-shrink-0",
1109
+ children: "Open"
1110
+ }
1111
+ )
1112
+ ]
1113
+ }
1114
+ ),
1115
+ i && st(z) && !U && !Mt && /* @__PURE__ */ h(
1116
+ "div",
1117
+ {
1118
+ ref: kt,
1119
+ className: "cteditor-absolute cteditor-flex cteditor-gap-1 z-10 cteditor-text-foreground",
1120
+ style: ue ?? (Dt ? { left: "50%", transform: "translateX(-50%) translateY(100%) translateY(4px)", bottom: 0 } : { top: 8, right: 8 }),
1121
+ children: [
1122
+ /* @__PURE__ */ h("div", { className: "cteditor-flex cteditor-items-center cteditor-gap-0.5 cteditor-bg-accent cteditor-border cteditor-border-foreground/10 cteditor-rounded-md cteditor-shadow-md cteditor-p-0.5", children: [
1123
+ /* @__PURE__ */ e(
1124
+ "button",
1125
+ {
1126
+ type: "button",
1127
+ onClick: (t) => ft(t, "left"),
1128
+ className: ` cteditor-size-6 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-rounded hover:cteditor-bg-foreground/10 cteditor-transition-colors ${w === "left" ? "cteditor-bg-foreground/10" : ""}`,
1129
+ "aria-label": "Wrap text left",
1130
+ title: "Wrap text left",
1131
+ children: /* @__PURE__ */ e(lr, {})
1132
+ }
1133
+ ),
1134
+ /* @__PURE__ */ e(
1135
+ "button",
1136
+ {
1137
+ type: "button",
1138
+ onClick: (t) => ft(t, "right"),
1139
+ className: ` cteditor-size-6 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-rounded hover:cteditor-bg-foreground/10 cteditor-transition-colors ${w === "right" ? "cteditor-bg-foreground/10" : ""}`,
1140
+ "aria-label": "Wrap text right",
1141
+ title: "Wrap text right",
1142
+ children: /* @__PURE__ */ e(ur, {})
1143
+ }
1144
+ ),
1145
+ /* @__PURE__ */ e("div", { className: "cteditor-w-px cteditor-h-5 cteditor-bg-foreground/10 cteditor-mx-0.5" }),
1146
+ /* @__PURE__ */ e(
1147
+ "button",
1148
+ {
1149
+ type: "button",
1150
+ onClick: (t) => ft(t, "inline-left"),
1151
+ className: `cteditor-size-6 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-rounded hover:cteditor-bg-foreground/10 cteditor-transition-colors ${w === "inline-left" ? "cteditor-bg-foreground/10" : ""}`,
1152
+ "aria-label": "Align left",
1153
+ title: "Align left (no text wrap)",
1154
+ children: /* @__PURE__ */ e(mr, {})
1155
+ }
1156
+ ),
1157
+ /* @__PURE__ */ e(
1158
+ "button",
1159
+ {
1160
+ type: "button",
1161
+ onClick: (t) => ft(t, "inline-center"),
1162
+ className: `cteditor-size-6 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-rounded hover:cteditor-bg-foreground/10 cteditor-transition-colors ${w === "inline-center" || w === "full" ? "cteditor-bg-foreground/10" : ""}`,
1163
+ "aria-label": "Align center",
1164
+ title: "Align center (no text wrap)",
1165
+ children: /* @__PURE__ */ e(gr, {})
1166
+ }
1167
+ ),
1168
+ /* @__PURE__ */ e(
1169
+ "button",
1170
+ {
1171
+ type: "button",
1172
+ onClick: (t) => ft(t, "inline-right"),
1173
+ className: `cteditor-size-6 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-rounded hover:cteditor-bg-foreground/10 cteditor-transition-colors ${w === "inline-right" ? "cteditor-bg-foreground/10" : ""}`,
1174
+ "aria-label": "Align right",
1175
+ title: "Align right (no text wrap)",
1176
+ children: /* @__PURE__ */ e(hr, {})
1177
+ }
1178
+ ),
1179
+ /* @__PURE__ */ e("div", { className: "cteditor-w-px cteditor-h-5 cteditor-bg-foreground/10 cteditor-mx-0.5" }),
1180
+ /* @__PURE__ */ e(
1181
+ "button",
1182
+ {
1183
+ type: "button",
1184
+ onClick: (t) => ft(t, "none"),
1185
+ className: `cteditor-size-6 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-rounded hover:cteditor-bg-foreground/10 cteditor-transition-colors ${w === "none" ? "cteditor-bg-foreground/10" : ""}`,
1186
+ "aria-label": "Inline",
1187
+ title: "Inline with text",
1188
+ children: /* @__PURE__ */ e(fr, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground" })
1189
+ }
1190
+ ),
1191
+ /* @__PURE__ */ e("div", { className: "cteditor-w-px cteditor-h-5 cteditor-bg-foreground/10 cteditor-mx-0.5" }),
1192
+ !o.startsWith("data:") && !o.toLowerCase().endsWith(".svg") && /* @__PURE__ */ h(Kt, { children: [
1193
+ /* @__PURE__ */ e(
1194
+ "button",
1195
+ {
1196
+ type: "button",
1197
+ onClick: we,
1198
+ className: "cteditor-size-6 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-rounded hover:cteditor-bg-foreground/10 cteditor-transition-colors",
1199
+ "aria-label": "Crop image",
1200
+ title: "Crop image",
1201
+ children: /* @__PURE__ */ e(se, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground" })
1202
+ }
1203
+ ),
1204
+ (vt(o) !== o || typeof f == "number" || typeof y == "number") && /* @__PURE__ */ e(
1205
+ "button",
1206
+ {
1207
+ type: "button",
1208
+ onClick: xe,
1209
+ className: "cteditor-size-6 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-rounded hover:cteditor-bg-foreground/10 cteditor-transition-colors",
1210
+ "aria-label": "Reset image to original size and crop",
1211
+ title: "Reset to original size and crop",
1212
+ children: /* @__PURE__ */ e(Pr, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground" })
1213
+ }
1214
+ )
1215
+ ] })
1216
+ ] }),
1217
+ I && /* @__PURE__ */ e(
1218
+ "button",
1219
+ {
1220
+ type: "button",
1221
+ onClick: Bt,
1222
+ className: " cteditor-size-6 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-rounded-md cteditor-bg-accent hover:cteditor-bg-accent/95 cteditor-transition-colors cteditor-shadow-md cteditor-border cteditor-border-foreground/20",
1223
+ "aria-label": "Visit link",
1224
+ title: `Visit: ${I}`,
1225
+ children: /* @__PURE__ */ e(pr, {})
1226
+ }
1227
+ ),
1228
+ W && /* @__PURE__ */ e(
1229
+ "button",
1230
+ {
1231
+ type: "button",
1232
+ onClick: (t) => {
1233
+ t.stopPropagation(), be(t);
1234
+ },
1235
+ className: " cteditor-size-8 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-rounded-md cteditor-bg-accent hover:cteditor-bg-accent/90 cteditor-transition-colors cteditor-shadow-md cteditor-border cteditor-border-foreground/20",
1236
+ "aria-label": "Refine image",
1237
+ title: "Refine image",
1238
+ children: /* @__PURE__ */ e(br, { className: "cteditor-w-4 cteditor-h-4 cteditor-text-foreground" })
1239
+ }
1240
+ ),
1241
+ /* @__PURE__ */ e(
1242
+ "button",
1243
+ {
1244
+ type: "button",
1245
+ onClick: (t) => {
1246
+ t.stopPropagation(), fe(t);
1247
+ },
1248
+ className: " cteditor-size-8 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-rounded-md cteditor-bg-accent hover:cteditor-bg-accent/90 cteditor-transition-colors cteditor-shadow-md cteditor-border cteditor-border-foreground/20",
1249
+ "aria-label": "Open image in new tab",
1250
+ title: "Open in new tab",
1251
+ children: /* @__PURE__ */ e(wr, {})
1252
+ }
1253
+ ),
1254
+ /* @__PURE__ */ e(
1255
+ "button",
1256
+ {
1257
+ type: "button",
1258
+ onClick: (t) => {
1259
+ t.stopPropagation(), pe(t);
1260
+ },
1261
+ className: " cteditor-size-8 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-rounded-md cteditor-bg-accent hover:cteditor-bg-destructive hover:cteditor-text-destructive-foreground cteditor-transition-colors cteditor-shadow-md cteditor-border cteditor-border-foreground/20",
1262
+ "aria-label": "Delete image",
1263
+ title: "Delete image",
1264
+ children: /* @__PURE__ */ e(xr, {})
1265
+ }
1266
+ )
1267
+ ]
1268
+ }
1269
+ ),
1270
+ n && i && !U && W && /* @__PURE__ */ e(
1271
+ "div",
1272
+ {
1273
+ className: "cteditor-absolute cteditor-bottom-2 cteditor-left-2 cteditor-right-2 cteditor-bg-background/85 cteditor-rounded-lg cteditor-shadow-xl cteditor-border cteditor-border-foreground/20 cteditor-p-3 cteditor-backdrop-blur-lg md:cteditor-min-w-80",
1274
+ style: { zIndex: 10 },
1275
+ onClick: (t) => t.stopPropagation(),
1276
+ onKeyDown: (t) => t.stopPropagation(),
1277
+ onKeyUp: (t) => t.stopPropagation(),
1278
+ children: /* @__PURE__ */ h("div", { className: "cteditor-flex cteditor-flex-col cteditor-gap-2", children: [
1279
+ /* @__PURE__ */ e("label", { className: "cteditor-text-xs cteditor-font-medium cteditor-text-foreground", children: "What else do you want in this scene?" }),
1280
+ /* @__PURE__ */ e(
1281
+ "input",
1282
+ {
1283
+ type: "text",
1284
+ value: p,
1285
+ onChange: (t) => u(t.target.value),
1286
+ onKeyDown: (t) => {
1287
+ t.stopPropagation(), t.key === "Enter" && p.trim() && !b && Xt(), t.key === "Escape" && (g(!1), u(""));
1288
+ },
1289
+ onKeyUp: (t) => {
1290
+ t.stopPropagation();
1291
+ },
1292
+ onClick: (t) => {
1293
+ t.stopPropagation();
1294
+ },
1295
+ placeholder: "e.g., flying birds, golden sunset, stormy clouds...",
1296
+ className: "cteditor-w-full cteditor-px-3 cteditor-py-2 cteditor-text-sm cteditor-border cteditor-border-foreground/10 focus:cteditor-border-foreground cteditor-rounded-md cteditor-bg-background cteditor-text-foreground ",
1297
+ disabled: b,
1298
+ autoFocus: !0
1299
+ }
1300
+ ),
1301
+ /* @__PURE__ */ h("div", { className: "cteditor-flex cteditor-gap-2 cteditor-justify-end", children: [
1302
+ /* @__PURE__ */ e(
1303
+ "button",
1304
+ {
1305
+ type: "button",
1306
+ onClick: (t) => {
1307
+ t.stopPropagation(), Xt();
1308
+ },
1309
+ disabled: b || !p.trim(),
1310
+ className: " cteditor-px-5 cteditor-py-2 cteditor-text-sm cteditor-rounded-md cteditor-bg-foreground cteditor-text-background hover:cteditor-bg-foreground/95 disabled:cteditor-opacity-50 disabled:cteditor-cursor-not-allowed cteditor-transition-colors focus:cteditor-outline-none focus:cteditor-ring-2 focus:cteditor-ring-background",
1311
+ children: b ? /* @__PURE__ */ h("span", { className: "cteditor-flex cteditor-items-center cteditor-justify-center cteditor-gap-2", children: [
1312
+ /* @__PURE__ */ e("span", { className: "cteditor-inline-block cteditor-w-4 cteditor-h-4 cteditor-border-2 cteditor-border-t-transparent cteditor-rounded-full cteditor-animate-spin" }),
1313
+ "Refining..."
1314
+ ] }) : "Refine Image"
1315
+ }
1316
+ ),
1317
+ /* @__PURE__ */ e(
1318
+ "button",
1319
+ {
1320
+ type: "button",
1321
+ onClick: (t) => {
1322
+ t.stopPropagation(), g(!1), u("");
1323
+ },
1324
+ disabled: b,
1325
+ className: "cteditor-size-9 cteditor-flex cteditor-items-center cteditor-justify-center cteditor-text-sm cteditor-rounded-md cteditor-bg-background cteditor-border cteditor-border-border cteditor-text-foreground hover:cteditor-bg-accent disabled:cteditor-opacity-50 disabled:cteditor-cursor-not-allowed cteditor-transition-colors",
1326
+ children: /* @__PURE__ */ e(yr, { size: 16 })
1327
+ }
1328
+ )
1329
+ ] })
1330
+ ] })
1331
+ }
1332
+ ),
1333
+ $ && st(z) && Ut && !Mt && /* @__PURE__ */ e(
1334
+ Me,
1335
+ {
1336
+ showCaption: E,
1337
+ setShowCaption: me,
1338
+ editor: d,
1339
+ buttonRef: J,
1340
+ imageRef: x,
1341
+ maxWidth: N,
1342
+ onResizeStart: he,
1343
+ onResizeEnd: ge,
1344
+ captionsEnabled: !U && ot
1345
+ }
1346
+ )
1347
+ ]
1348
+ }
1349
+ ),
1350
+ E && (c.startsWith("Signature by") ? /* @__PURE__ */ e(Mr, { caption: M }) : /* @__PURE__ */ e(
1351
+ "div",
1352
+ {
1353
+ className: "image-caption-container",
1354
+ style: {
1355
+ width: typeof f == "number" ? `${f}px` : "100%",
1356
+ maxWidth: "100%",
1357
+ // Match the image's alignment
1358
+ ...w === "inline-center" || w === "full" ? { margin: "0 auto" } : w === "inline-right" ? { marginLeft: "auto" } : w === "left" ? { float: "left", clear: "left" } : w === "right" ? { float: "right", clear: "right" } : {}
1359
+ },
1360
+ children: /* @__PURE__ */ h(
1361
+ _e,
1362
+ {
1363
+ initialEditor: M,
1364
+ initialNodes: [
1365
+ Ze,
1366
+ tr,
1367
+ er,
1368
+ rr,
1369
+ Le,
1370
+ De
1371
+ ],
1372
+ children: [
1373
+ /* @__PURE__ */ e(Ae, {}),
1374
+ /* @__PURE__ */ e(
1375
+ Fe,
1376
+ {
1377
+ contentEditable: /* @__PURE__ */ e(
1378
+ We,
1379
+ {
1380
+ "aria-placeholder": "Enter a caption...",
1381
+ placeholder: () => /* @__PURE__ */ e("span", { className: "cteditor-text-xs cteditor-absolute cteditor-left-2 cteditor-top-[7px]", children: "Enter a caption..." }),
1382
+ className: " cteditor-outline-none !cteditor-shadow-none cteditor-bg-foreground/10 cteditor-border !cteditor-border-foreground/15 cteditor-py-1 cteditor-px-2 cteditor-rounded-sm cteditor-text-xs cteditor-relative"
1383
+ }
1384
+ ),
1385
+ ErrorBoundary: Te
1386
+ }
1387
+ ),
1388
+ /* @__PURE__ */ e(
1389
+ je,
1390
+ {
1391
+ onChange: () => {
1392
+ }
1393
+ }
1394
+ ),
1395
+ /* @__PURE__ */ e(Oe, {}),
1396
+ /* @__PURE__ */ e(Cr, { namespace: vr.namespace })
1397
+ ]
1398
+ }
1399
+ )
1400
+ }
1401
+ )),
1402
+ /* @__PURE__ */ e(
1403
+ Ar,
1404
+ {
1405
+ open: H,
1406
+ onOpenChange: ht,
1407
+ src: o,
1408
+ altText: c,
1409
+ width: f,
1410
+ height: y,
1411
+ onCropApply: ye
1412
+ }
1413
+ ),
1414
+ /* @__PURE__ */ e(
1415
+ Sr,
1416
+ {
1417
+ open: mt,
1418
+ onOpenChange: gt,
1419
+ oldImageUrl: o,
1420
+ newImageUrl: Q,
1421
+ onReplace: Ne,
1422
+ onCancel: Re
1423
+ }
1424
+ )
1425
+ ] }) });
1426
+ }
1427
+ export {
1428
+ re as RIGHT_CLICK_IMAGE_COMMAND,
1429
+ no as default
1430
+ };