@commentkit/comment-kit 1.0.0 → 1.5.0

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 (77) hide show
  1. package/CHANGELOG.md +133 -1
  2. package/README.md +12 -5
  3. package/SECURITY.md +3 -1
  4. package/dist/npm/THIRD_PARTY_NOTICES.txt +22 -23
  5. package/dist/npm/chunks/AgentSend-DyWxNQ0p.js +64 -0
  6. package/dist/npm/chunks/Checklist-VYkSl6Q9.js +259 -0
  7. package/dist/npm/chunks/Composer-CnsGQirF.js +679 -0
  8. package/dist/npm/chunks/Guest-DkIvY5zt.js +170 -0
  9. package/dist/npm/chunks/MarkupEditor-DxTI9nJH.js +334 -0
  10. package/dist/npm/chunks/Panel-riaMYxt-.js +863 -0
  11. package/dist/npm/chunks/Settings-CB4zxQAL.js +206 -0
  12. package/dist/npm/chunks/{Shortcuts-BSOKdMHt.js → Shortcuts-D1cbajg_.js} +21 -17
  13. package/dist/npm/chunks/StyleEditor-BtTv3I8_.js +44 -0
  14. package/dist/npm/chunks/StylePanel-BI-n5Me1.js +199 -0
  15. package/dist/npm/chunks/TaskFields-HwrD0FrH.js +272 -0
  16. package/dist/npm/chunks/ThreadCard-CjaC8BTa.js +1026 -0
  17. package/dist/npm/chunks/Viewer-BnWshSXb.js +110 -0
  18. package/dist/npm/chunks/agent-Cr6NB6We.js +146 -0
  19. package/dist/npm/chunks/anchor-OCQnjp_6.js +294 -0
  20. package/dist/npm/chunks/{ar-O7EPv0mI.js → ar-BQ9K9Oqf.js} +189 -8
  21. package/dist/npm/chunks/card-bits-CxteYiZ9.js +126 -0
  22. package/dist/npm/chunks/client-CJ1tpI62.js +754 -0
  23. package/dist/npm/chunks/colors-0Ied7PE2.js +101 -0
  24. package/dist/npm/chunks/confetti-DKeKR7-6.js +41 -0
  25. package/dist/npm/chunks/{de-PGyZVNHX.js → de-CcPi8xdC.js} +160 -8
  26. package/dist/npm/chunks/drafts-CpQdHhcK.js +51 -0
  27. package/dist/npm/chunks/{es-Bq1idl8M.js → es-DXgkjDCG.js} +160 -8
  28. package/dist/npm/chunks/extension-BIGfr4Gh.js +50 -0
  29. package/dist/npm/chunks/{extension-B7SelsS0.js → extension-DkDSW4qw.js} +2 -2
  30. package/dist/npm/chunks/{fr-BVB9GGco.js → fr-IjJaUbWh.js} +160 -8
  31. package/dist/npm/chunks/{hi-DyBvrjzQ.js → hi-BhKQK2MU.js} +160 -8
  32. package/dist/npm/chunks/html2canvas-pro.esm-lgs6tb4C.js +8378 -0
  33. package/dist/npm/chunks/i18n-DAJGndZ2.js +904 -0
  34. package/dist/npm/chunks/{it-BlMMMwZh.js → it-DKiSCkiD.js} +160 -8
  35. package/dist/npm/chunks/{ja-lAioBCJv.js → ja-BI1WagDg.js} +160 -8
  36. package/dist/npm/chunks/{live-YFyP1GnP.js → live-B-mo27Qq.js} +1 -1
  37. package/dist/npm/chunks/lock-C82sC17d.js +30 -0
  38. package/dist/npm/chunks/{nl-DR8mLHnn.js → nl-CJw3VUQ5.js} +160 -8
  39. package/dist/npm/chunks/pick-CYPkLLFJ.js +120 -0
  40. package/dist/npm/chunks/{pt-BR-D7j6aDPx.js → pt-BR-CjBolC5g.js} +160 -8
  41. package/dist/npm/chunks/{pusher-BSsQoE1K.js → realtime-D22tI_AS.js} +58 -4
  42. package/dist/npm/chunks/source-CTQmAh0Y.js +146 -0
  43. package/dist/npm/chunks/src-CgBEoWl0.js +150 -0
  44. package/dist/npm/chunks/start-DW9_DKmf.js +1783 -0
  45. package/dist/npm/chunks/upload-BmrpZE5G.js +42 -0
  46. package/dist/npm/chunks/uploads-CipONvCy.js +541 -0
  47. package/dist/npm/chunks/{zh-CN-tzYg9NPH.js → zh-CN-BrZGx2S0.js} +160 -8
  48. package/dist/npm/element.js +4 -5
  49. package/dist/npm/headless.js +3 -3
  50. package/dist/npm/index.js +2 -2
  51. package/dist/npm/react.js +1 -1
  52. package/dist/npm/svelte.js +1 -1
  53. package/dist/npm/types/adapters/vue.d.ts +14 -0
  54. package/dist/npm/types/anchor/index.d.ts +22 -1
  55. package/dist/npm/types/core/api.d.ts +3 -0
  56. package/dist/npm/types/core/auth.d.ts +11 -0
  57. package/dist/npm/types/core/client.d.ts +128 -6
  58. package/dist/npm/types/core/types.d.ts +78 -4
  59. package/dist/npm/types/headless.d.ts +1 -1
  60. package/dist/npm/types/index.d.ts +6 -1
  61. package/dist/npm/vue.js +5 -1
  62. package/package.json +7 -5
  63. package/dist/npm/chunks/Guest-VNoofLxw.js +0 -157
  64. package/dist/npm/chunks/MarkupEditor-DTXrS3DD.js +0 -199
  65. package/dist/npm/chunks/Panel-B88JYH52.js +0 -438
  66. package/dist/npm/chunks/ThreadCard-izybwXIC.js +0 -817
  67. package/dist/npm/chunks/anchor-DT-Ynhh1.js +0 -270
  68. package/dist/npm/chunks/art-DK1JwPIo.js +0 -155
  69. package/dist/npm/chunks/client-Iegfv6ZC.js +0 -620
  70. package/dist/npm/chunks/colors-CX-IPjvb.js +0 -86
  71. package/dist/npm/chunks/extension-DSA8S8Qz.js +0 -26
  72. package/dist/npm/chunks/format-B5tJGtPC.js +0 -524
  73. package/dist/npm/chunks/html2canvas-DfGb8yka.js +0 -4024
  74. package/dist/npm/chunks/mount-Dx_8NhX3.js +0 -1484
  75. package/dist/npm/chunks/privacy-DLhezjyi.js +0 -30
  76. package/dist/npm/chunks/realtime-CBRW9BB3.js +0 -34
  77. package/dist/npm/chunks/src-C1Qp94nr.js +0 -549
@@ -0,0 +1,170 @@
1
+ import { p as e } from "./client-CJ1tpI62.js";
2
+ import { f as t, l as n, m as r, s as i, u as a } from "./i18n-DAJGndZ2.js";
3
+ import { r as o } from "./card-bits-CxteYiZ9.js";
4
+ import { c as s, d as c, n as l } from "./start-DW9_DKmf.js";
5
+ //#endregion
6
+ //#region src/ui/Guest.tsx
7
+ l(".ck-verify-text{margin:0 0 12px;line-height:1.5}.ck-code{font-family:var(--ck-mono);letter-spacing:.32em;text-align:center;height:46px;font-size:20px}.ck-verify-text{text-wrap:pretty}");
8
+ async function u(t, n) {
9
+ try {
10
+ let e = await t.api.request("/guest/start", {
11
+ method: "POST",
12
+ anonymous: !0,
13
+ body: {
14
+ client_id: t.options.project,
15
+ share: n.share,
16
+ name: n.name.trim(),
17
+ email: n.email.trim()
18
+ }
19
+ }), r = Date.parse(e.pending_session.expires_at);
20
+ return t.auth.setPending({
21
+ token: e.access_token,
22
+ email: e.pending_session.email,
23
+ expiresAt: Number.isFinite(r) ? r : Date.now() + e.expires_in * 1e3
24
+ }), "started";
25
+ } catch (t) {
26
+ if (t instanceof e && t.code === "origin_not_allowed") return "popup";
27
+ throw t instanceof e && (t.code === "share_expired" || t.status === 410 || t.errors?.share) ? new e(410, "share_expired", i("shareExpired")) : t;
28
+ }
29
+ }
30
+ function d({ client: l, email: u, onDone: d, onDifferentEmail: m, onClose: h }) {
31
+ let [g, _] = r(""), [v, y] = r(!1), [b, x] = r(null), [S, C] = r(null), w = t(null);
32
+ a(() => w.current?.focus({ preventScroll: !0 }), []);
33
+ let [T, E] = r(f);
34
+ a(() => {
35
+ if (T <= 0) return;
36
+ let e = setTimeout(() => E((e) => e - 1), 1e3);
37
+ return () => clearTimeout(e);
38
+ }, [T]);
39
+ let D = async (t = g) => {
40
+ if (/^\d{6}$/.test(t) && !v) {
41
+ y(!0), x(null);
42
+ try {
43
+ let e = await l.api.request("/guest/verify", {
44
+ method: "POST",
45
+ body: { code: t }
46
+ });
47
+ l.auth.adopt(e), await l.loadSession().catch(() => null), d(e.published_thread_ids ?? []);
48
+ } catch (t) {
49
+ if ((t instanceof e ? t.status : 0) === 422) return _(""), w.current?.focus({ preventScroll: !0 }), x({
50
+ text: i("verifyWrong"),
51
+ tone: "warning"
52
+ });
53
+ let n = p(t);
54
+ n && (l.auth.setPending(null), C(n === "expired" ? "again" : "stop")), x({
55
+ text: n ? i(n === "link" ? "verifyLinkExpired" : n === "removed" ? "verifyRemoved" : "verifyExpired") : s(t),
56
+ tone: "warning"
57
+ });
58
+ } finally {
59
+ y(!1);
60
+ }
61
+ }
62
+ }, O = async () => {
63
+ try {
64
+ await l.api.request("/guest/resend", { method: "POST" }), x({ text: i("verifyResent") }), E(f);
65
+ } catch (t) {
66
+ x({
67
+ text: t instanceof e && t.status === 429 ? i("verifyWait") : i("errorGeneric"),
68
+ tone: "warning"
69
+ });
70
+ }
71
+ };
72
+ return /* @__PURE__ */ n("div", {
73
+ class: "ck-card",
74
+ style: o({
75
+ x: innerWidth / 2 - 190,
76
+ y: 80
77
+ }),
78
+ role: "dialog",
79
+ "aria-labelledby": "ck-verify-title",
80
+ "data-commentkit-ui": !0,
81
+ onKeyDown: (e) => e.key === "Escape" && h(),
82
+ children: [
83
+ /* @__PURE__ */ n("div", {
84
+ class: "ck-card-head",
85
+ children: [/* @__PURE__ */ n("h2", {
86
+ class: "ck-card-title",
87
+ id: "ck-verify-title",
88
+ children: i("verifyTitle")
89
+ }), /* @__PURE__ */ n("button", {
90
+ class: "ck-ghost",
91
+ "aria-label": i("close"),
92
+ onClick: h,
93
+ children: /* @__PURE__ */ n(c, { name: "close" })
94
+ })]
95
+ }),
96
+ /* @__PURE__ */ n("div", {
97
+ class: "ck-card-body",
98
+ children: [
99
+ /* @__PURE__ */ n("p", {
100
+ class: "ck-verify-text",
101
+ children: i("verifyBody", { email: u })
102
+ }),
103
+ /* @__PURE__ */ n("label", {
104
+ class: "ck-field",
105
+ children: [/* @__PURE__ */ n("span", { children: i("verifyCode") }), /* @__PURE__ */ n("input", {
106
+ ref: w,
107
+ class: "ck-input ck-code",
108
+ inputMode: "numeric",
109
+ autoComplete: "one-time-code",
110
+ pattern: "[0-9]*",
111
+ maxLength: 6,
112
+ value: g,
113
+ onInput: (e) => {
114
+ let t = e.target.value.replace(/\D/g, "").slice(0, 6);
115
+ _(t), b?.tone && x(null), t.length === 6 && t !== g && D(t);
116
+ },
117
+ onKeyDown: (e) => {
118
+ e.stopPropagation(), e.key === "Enter" && D(), e.key === "Escape" && h();
119
+ }
120
+ })]
121
+ }),
122
+ b ? /* @__PURE__ */ n("div", {
123
+ class: "ck-note",
124
+ role: b.tone ? "alert" : "status",
125
+ "data-tone": b.tone,
126
+ children: b.text
127
+ }) : null,
128
+ S ? null : /* @__PURE__ */ n("div", {
129
+ class: "ck-actions",
130
+ children: [/* @__PURE__ */ n("button", {
131
+ class: "ck-chip",
132
+ disabled: T > 0,
133
+ onClick: () => void O(),
134
+ children: T > 0 ? i("verifyResendIn", { n: T }) : i("verifyResend")
135
+ }), /* @__PURE__ */ n("button", {
136
+ class: "ck-chip",
137
+ onClick: () => {
138
+ l.auth.setPending(null), m();
139
+ },
140
+ children: i("verifyDifferent")
141
+ })]
142
+ })
143
+ ]
144
+ }),
145
+ /* @__PURE__ */ n("div", {
146
+ class: "ck-card-foot",
147
+ children: [/* @__PURE__ */ n("span", { class: "ck-spacer" }), S === "again" ? /* @__PURE__ */ n("button", {
148
+ class: "ck-btn ck-primary",
149
+ onClick: m,
150
+ children: i("writeAgain")
151
+ }) : S === "stop" ? /* @__PURE__ */ n("button", {
152
+ class: "ck-btn",
153
+ onClick: h,
154
+ children: i("close")
155
+ }) : /* @__PURE__ */ n("button", {
156
+ class: "ck-btn ck-primary",
157
+ disabled: v || g.length !== 6,
158
+ onClick: () => void D(),
159
+ children: i(v ? "sending" : "verifyPublish")
160
+ })]
161
+ })
162
+ ]
163
+ });
164
+ }
165
+ var f = 60;
166
+ function p(t) {
167
+ return t instanceof e ? t.code === "share_expired" || t.status === 410 ? "link" : t.code === "guest_removed" ? "removed" : t.status === 403 ? /\blink\b/i.test(t.message) ? "link" : "removed" : t.status === 409 || t.status === 401 ? "expired" : null : null;
168
+ }
169
+ //#endregion
170
+ export { d as GuestVerify, u as startGuest };
@@ -0,0 +1,334 @@
1
+ import { f as e, l as t, m as n, s as r, u as i } from "./i18n-DAJGndZ2.js";
2
+ import { m as a, n as o } from "./start-DW9_DKmf.js";
3
+ //#endregion
4
+ //#region src/ui/MarkupEditor.tsx
5
+ o(".ck-markup-tools{background:var(--ck-bg);max-width:100%;box-shadow:var(--ck-shadow);border-radius:999px;flex-wrap:wrap;justify-content:center;gap:4px;padding:6px;display:flex}.ck-label-box{z-index:1;background:var(--ck-bg);box-shadow:var(--ck-shadow);border:1px solid #0000;border-radius:12px;align-items:center;gap:6px;padding:6px;display:flex;position:fixed}.ck-markup-tools{align-items:center;gap:2px;padding:4px}.ck-markup-group{align-items:center;gap:2px;padding:0 4px;display:flex}.ck-markup-group+.ck-markup-group{border-inline-start:1px solid var(--ck-hairline);margin-inline-start:4px;padding-inline-start:8px}.ck-tool{width:32px;height:32px;color:var(--ck-text-muted);background:0 0;border:0;border-radius:999px;place-items:center;padding:0;transition:background-color .12s,color .12s,scale .15s ease-out;display:grid}.ck-tool[aria-pressed=true]{background:var(--ck-accent-soft);color:color-mix(in srgb, var(--ck-accent) 70%, var(--ck-text))}.ck-tool:disabled{opacity:.35;cursor:default}.ck-tool:active:not(:disabled),.ck-icon-btn:active:not(:disabled){scale:.96}.ck-tool{width:30px;height:30px}.ck-dot{border-radius:50%;width:14px;height:14px;display:block;box-shadow:0 0 0 1px #00000014}.ck-tool[aria-pressed=true] .ck-dot{box-shadow:0 0 0 2px var(--ck-bg), 0 0 0 3.5px currentColor}.ck-width{gap:8px;width:150px}.ck-width input{min-width:0;accent-color:var(--ck-accent);cursor:pointer;flex:1}.ck-width span{width:30px;color:var(--ck-text-muted);font-variant-numeric:tabular-nums;flex:none;font-size:12px}.ck-btn-group{display:inline-flex}.ck-icon-btn{border:1px solid var(--ck-border);background:var(--ck-bg);width:30px;height:30px;color:var(--ck-text);place-items:center;padding:0;transition:background-color .12s;display:grid}.ck-icon-btn+.ck-icon-btn{margin-inline-start:-1px}.ck-icon-btn:first-child:not(:-webkit-any(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi))){border-top-left-radius:8px;border-bottom-left-radius:8px}.ck-icon-btn:first-child:not(:is(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi))){border-top-left-radius:8px;border-bottom-left-radius:8px}.ck-icon-btn:first-child:-webkit-any(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi)){border-top-right-radius:8px;border-bottom-right-radius:8px}.ck-icon-btn:first-child:is(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi)){border-top-right-radius:8px;border-bottom-right-radius:8px}.ck-icon-btn:last-child:not(:-webkit-any(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi))){border-top-right-radius:8px;border-bottom-right-radius:8px}.ck-icon-btn:last-child:not(:is(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi))){border-top-right-radius:8px;border-bottom-right-radius:8px}.ck-icon-btn:last-child:-webkit-any(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi)){border-top-left-radius:8px;border-bottom-left-radius:8px}.ck-icon-btn:last-child:is(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi)){border-top-left-radius:8px;border-bottom-left-radius:8px}.ck-icon-btn:disabled,.ck-icon-btn[aria-disabled=true]{opacity:.45;cursor:default}.ck-icon-btn.ck-primary{border-color:var(--ck-accent);background:var(--ck-accent);color:var(--ck-accent-ink);position:relative}@media (hover:hover){.ck-icon-btn:hover:not(:disabled):not(.ck-primary){background:var(--ck-bg-hover)}.ck-tool:hover:not(:disabled){background:var(--ck-bg-hover);color:var(--ck-text)}}@media (pointer:coarse){.ck-tool,.ck-icon-btn{width:40px;height:40px}}@media (max-width:520px){.ck-markup-tools{border-radius:16px}}");
6
+ var s = /* @__PURE__ */ new WeakSet(), c = [
7
+ "pen",
8
+ "line",
9
+ "rect",
10
+ "ellipse",
11
+ "arrow",
12
+ "blur",
13
+ "text"
14
+ ], l = [
15
+ "#ef4444",
16
+ "#f97316",
17
+ "#eab308",
18
+ "#22c55e",
19
+ "#3b82f6",
20
+ "#8b5cf6",
21
+ "#ec4899"
22
+ ], u = [
23
+ "color_red",
24
+ "color_orange",
25
+ "color_yellow",
26
+ "color_green",
27
+ "color_blue",
28
+ "color_purple",
29
+ "color_pink"
30
+ ], d = {
31
+ arrow: "M5 19L19 5M10 5h9v9",
32
+ line: "M5 19L19 5",
33
+ rect: "M5 6h14v12H5z",
34
+ ellipse: "M12 20a8 8 0 1 0 0-16 8 8 0 0 0 0 16z",
35
+ pen: "M4 20l4-1 11-11-3-3L5 16z",
36
+ blur: "M4 4h4v4H4zM10 4h4v4h-4zM16 4h4v4h-4zM4 10h4v4H4zM16 10h4v4h-4zM4 16h4v4H4zM10 16h4v4h-4zM16 16h4v4h-4zM10 10h4v4h-4z",
37
+ text: "M5 6V5h14v1M12 5v14M9 19h6"
38
+ }, f = {
39
+ undo: "M9 14L4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3",
40
+ redo: "M15 14l5-5-5-5M20 9H10a6 6 0 0 0 0 12h3",
41
+ clear: "M5 7h14M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3",
42
+ cancel: "M6 6l12 12M18 6L6 18",
43
+ save: "M5 12l5 5L20 7"
44
+ };
45
+ function p({ d: e }) {
46
+ return /* @__PURE__ */ t("svg", {
47
+ width: "16",
48
+ height: "16",
49
+ viewBox: "0 0 24 24",
50
+ fill: "none",
51
+ stroke: "currentColor",
52
+ "stroke-width": "2",
53
+ "stroke-linecap": "round",
54
+ "stroke-linejoin": "round",
55
+ "aria-hidden": "true",
56
+ children: /* @__PURE__ */ t("path", { d: e })
57
+ });
58
+ }
59
+ function m({ image: o, onDone: m, onCancel: v }) {
60
+ let y = e(null), [b, x] = n(null), [S, C] = n("pen"), [w, T] = n(l[0]), [E, D] = n(3), [O, k] = n({
61
+ steps: [[]],
62
+ at: 0
63
+ }), A = O.steps[O.at], j = (e) => k((t) => ({
64
+ steps: [...t.steps.slice(0, t.at + 1), e],
65
+ at: t.at + 1
66
+ })), M = () => k((e) => ({
67
+ ...e,
68
+ at: Math.max(0, e.at - 1)
69
+ })), N = () => k((e) => ({
70
+ ...e,
71
+ at: Math.min(e.steps.length - 1, e.at + 1)
72
+ })), P = e(null), [F, I] = n(null), L = e(null), R = e(null);
73
+ i(() => (L.current ?? R.current)?.focus({ preventScroll: !0 }), [!!F]);
74
+ let z = () => {
75
+ let e = F?.text.trim().slice(0, 500);
76
+ F && e && j([...A, {
77
+ tool: "text",
78
+ color: w,
79
+ points: [F.x, F.y],
80
+ text: e,
81
+ width: h(y.current, E)
82
+ }]), R.current?.focus({ preventScroll: !0 }), I(null);
83
+ };
84
+ i(() => {
85
+ let e = !0, t = null;
86
+ return createImageBitmap(o).then((n) => e ? x(t = n) : n.close()), () => {
87
+ if (e = !1, t) {
88
+ let e = t;
89
+ x((t) => t === e ? null : t), s.add(e), e.close();
90
+ }
91
+ };
92
+ }, [o]), i(() => B(), [b, A]);
93
+ let B = (e) => {
94
+ let t = y.current;
95
+ if (!t || !b || s.has(b)) return;
96
+ (t.width !== b.width || t.height !== b.height) && (t.width = b.width, t.height = b.height);
97
+ let n = t.getContext("2d");
98
+ n.clearRect(0, 0, t.width, t.height), n.drawImage(b, 0, 0);
99
+ for (let t of e ? [...A, e] : A) _(n, t, b);
100
+ }, V = (e) => {
101
+ let t = y.current, n = t.getBoundingClientRect();
102
+ return [Math.round((e.clientX - n.left) / n.width * t.width), Math.round((e.clientY - n.top) / n.height * t.height)];
103
+ }, H = (e) => {
104
+ let [t, n] = V(e);
105
+ S === "text" ? (e.preventDefault(), z(), I({
106
+ x: t,
107
+ y: n,
108
+ left: Math.min(e.clientX, innerWidth - 240),
109
+ top: Math.max(8, e.clientY - 18),
110
+ text: ""
111
+ })) : (P.current = {
112
+ tool: S,
113
+ color: w,
114
+ points: [
115
+ t,
116
+ n,
117
+ t,
118
+ n
119
+ ],
120
+ width: h(y.current, E)
121
+ }, y.current?.setPointerCapture(e.pointerId));
122
+ }, U = (e) => {
123
+ let t = P.current;
124
+ if (!t?.points) return;
125
+ let [n, r] = V(e);
126
+ t.tool === "pen" ? t.points.length < 4e3 && t.points.push(n, r) : (t.points[2] = n, t.points[3] = r), B(t);
127
+ }, W = () => {
128
+ P.current && j([...A, P.current]), P.current = null;
129
+ }, G = () => {
130
+ let e = F?.text.trim().slice(0, 500), t = F && e ? {
131
+ tool: "text",
132
+ color: w,
133
+ points: [F.x, F.y],
134
+ text: e,
135
+ width: h(y.current, E)
136
+ } : null;
137
+ t && B(t), y.current?.toBlob((e) => e && m(e, t ? [...A, t] : A), "image/webp", .88);
138
+ };
139
+ return /* @__PURE__ */ t("div", {
140
+ class: "ck-markup",
141
+ ref: R,
142
+ tabIndex: -1,
143
+ role: "dialog",
144
+ "aria-label": r("markup"),
145
+ "data-commentkit-ui": !0,
146
+ onKeyDown: (e) => {
147
+ if ((e.metaKey || e.ctrlKey) && !F && (e.key.toLowerCase() === "z" || e.key.toLowerCase() === "y")) return e.preventDefault(), e.stopPropagation(), e.key.toLowerCase() === "y" || e.shiftKey ? N() : M();
148
+ e.key === "Escape" && (e.stopPropagation(), F ? (R.current?.focus({ preventScroll: !0 }), I(null)) : v());
149
+ },
150
+ children: [
151
+ /* @__PURE__ */ t("div", {
152
+ class: "ck-markup-tools",
153
+ role: "toolbar",
154
+ "aria-label": r("markup"),
155
+ children: [
156
+ /* @__PURE__ */ t("div", {
157
+ class: "ck-markup-group",
158
+ role: "group",
159
+ "aria-label": r("markupTools"),
160
+ children: c.map((e) => /* @__PURE__ */ t("button", {
161
+ class: "ck-tool",
162
+ "aria-pressed": S === e,
163
+ "aria-label": r(`tool_${e}`),
164
+ title: r(`tool_${e}`),
165
+ onClick: () => C(e),
166
+ children: /* @__PURE__ */ t(p, { d: d[e] })
167
+ }))
168
+ }),
169
+ /* @__PURE__ */ t("div", {
170
+ class: "ck-markup-group",
171
+ role: "group",
172
+ "aria-label": r("markupColors"),
173
+ children: l.map((e, n) => /* @__PURE__ */ t("button", {
174
+ class: "ck-tool",
175
+ "aria-pressed": w === e,
176
+ "aria-label": r(u[n]),
177
+ title: r(u[n]),
178
+ onClick: () => T(e),
179
+ children: /* @__PURE__ */ t("span", {
180
+ class: "ck-dot",
181
+ style: { background: e }
182
+ })
183
+ }))
184
+ }),
185
+ /* @__PURE__ */ t("label", {
186
+ class: "ck-markup-group ck-width",
187
+ children: [/* @__PURE__ */ t("input", {
188
+ type: "range",
189
+ min: 1,
190
+ max: 12,
191
+ step: 1,
192
+ value: E,
193
+ "aria-label": r("markupSize"),
194
+ onInput: (e) => D(Number(e.target.value))
195
+ }), /* @__PURE__ */ t("span", { children: [E, "px"] })]
196
+ }),
197
+ /* @__PURE__ */ t("div", {
198
+ class: "ck-markup-group",
199
+ role: "group",
200
+ "aria-label": r("markupHistory"),
201
+ children: /* @__PURE__ */ t("span", {
202
+ class: "ck-btn-group",
203
+ children: [
204
+ /* @__PURE__ */ t("button", {
205
+ class: "ck-icon-btn",
206
+ disabled: O.at === 0,
207
+ "aria-label": r("undo"),
208
+ title: `${r("undo")} (${g()} Z)`,
209
+ "aria-keyshortcuts": "Meta+Z",
210
+ onClick: M,
211
+ children: /* @__PURE__ */ t(p, { d: f.undo })
212
+ }),
213
+ /* @__PURE__ */ t("button", {
214
+ class: "ck-icon-btn",
215
+ disabled: O.at === O.steps.length - 1,
216
+ "aria-label": r("redo"),
217
+ title: `${r("redo")} (${g()} Shift Z)`,
218
+ "aria-keyshortcuts": "Meta+Shift+Z",
219
+ onClick: N,
220
+ children: /* @__PURE__ */ t(p, { d: f.redo })
221
+ }),
222
+ /* @__PURE__ */ t("button", {
223
+ class: "ck-icon-btn",
224
+ disabled: !A.length,
225
+ "aria-label": r("clearAll"),
226
+ title: r("clearAll"),
227
+ onClick: () => j([]),
228
+ children: /* @__PURE__ */ t(p, { d: f.clear })
229
+ })
230
+ ]
231
+ })
232
+ }),
233
+ /* @__PURE__ */ t("div", {
234
+ class: "ck-markup-group",
235
+ children: /* @__PURE__ */ t("span", {
236
+ class: "ck-btn-group",
237
+ children: [/* @__PURE__ */ t("button", {
238
+ class: "ck-icon-btn",
239
+ "aria-label": r("cancel"),
240
+ title: `${r("cancel")} (Esc)`,
241
+ onClick: v,
242
+ children: /* @__PURE__ */ t(p, { d: f.cancel })
243
+ }), /* @__PURE__ */ t("button", {
244
+ class: "ck-icon-btn ck-primary",
245
+ "aria-disabled": !A.length && !F?.text.trim() || void 0,
246
+ "aria-label": r("markupDone"),
247
+ title: !A.length && !F?.text.trim() ? r("markupEmpty") : r("markupDone"),
248
+ onClick: () => (A.length || F?.text.trim()) && G(),
249
+ children: /* @__PURE__ */ t(p, { d: f.save })
250
+ })]
251
+ })
252
+ })
253
+ ]
254
+ }),
255
+ /* @__PURE__ */ t("canvas", {
256
+ ref: y,
257
+ onPointerDown: H,
258
+ onPointerMove: U,
259
+ onPointerUp: W
260
+ }),
261
+ F ? /* @__PURE__ */ t("div", {
262
+ class: "ck-label-box",
263
+ style: a(F.left, F.top),
264
+ children: [/* @__PURE__ */ t("input", {
265
+ ref: L,
266
+ class: "ck-input",
267
+ maxLength: 500,
268
+ value: F.text,
269
+ placeholder: r("markupTextPrompt"),
270
+ "aria-label": r("markupTextPrompt"),
271
+ style: { color: w },
272
+ onInput: (e) => I({
273
+ ...F,
274
+ text: e.target.value
275
+ }),
276
+ onKeyDown: (e) => {
277
+ e.key === "Enter" && (e.preventDefault(), z());
278
+ }
279
+ }), /* @__PURE__ */ t("button", {
280
+ class: "ck-chip ck-primary",
281
+ onMouseDown: (e) => e.preventDefault(),
282
+ onClick: z,
283
+ children: r("markupTextAdd")
284
+ })]
285
+ }) : null
286
+ ]
287
+ });
288
+ }
289
+ function h(e, t) {
290
+ let n = e?.getBoundingClientRect().width || e?.width || 1;
291
+ return Math.max(1, Math.min(64, Math.round(t * ((e?.width ?? n) / n))));
292
+ }
293
+ var g = () => /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent) ? "⌘" : "Ctrl";
294
+ function _(e, t, n) {
295
+ let r = t.points ?? [], i = t.width ?? Math.max(3, Math.round(n.width / 300));
296
+ e.save(), e.strokeStyle = e.fillStyle = t.color ?? "#ff3b30", e.lineWidth = i, e.lineCap = e.lineJoin = "round";
297
+ let [a = 0, o = 0, s = 0, c = 0] = r;
298
+ switch (t.tool) {
299
+ case "rect":
300
+ e.strokeRect(Math.min(a, s), Math.min(o, c), Math.abs(s - a), Math.abs(c - o));
301
+ break;
302
+ case "ellipse":
303
+ e.beginPath(), e.ellipse((a + s) / 2, (o + c) / 2, Math.abs(s - a) / 2, Math.abs(c - o) / 2, 0, 0, Math.PI * 2), e.stroke();
304
+ break;
305
+ case "line":
306
+ e.beginPath(), e.moveTo(a, o), e.lineTo(s, c), e.stroke();
307
+ break;
308
+ case "arrow": {
309
+ let t = Math.atan2(c - o, s - a), n = i * 5;
310
+ e.beginPath(), e.moveTo(a, o), e.lineTo(s, c), e.stroke(), e.beginPath(), e.moveTo(s, c), e.lineTo(s - n * Math.cos(t - .45), c - n * Math.sin(t - .45)), e.lineTo(s - n * Math.cos(t + .45), c - n * Math.sin(t + .45)), e.closePath(), e.fill();
311
+ break;
312
+ }
313
+ case "pen":
314
+ e.beginPath();
315
+ for (let t = 0; t < r.length; t += 2) (t ? e.lineTo : e.moveTo).call(e, r[t], r[t + 1]);
316
+ e.stroke();
317
+ break;
318
+ case "blur": {
319
+ let t = Math.min(a, s), n = Math.min(o, c), r = Math.abs(s - a), i = Math.abs(c - o);
320
+ if (r > 2 && i > 2) {
321
+ let a = Math.max(8, Math.round(Math.min(r, i) / 6)), o = e.getImageData(t, n, r, i);
322
+ for (let s = 0; s < i; s += a) for (let i = 0; i < r; i += a) {
323
+ let c = (s * r + i) * 4;
324
+ e.fillStyle = `rgb(${o.data[c]},${o.data[c + 1]},${o.data[c + 2]})`, e.fillRect(t + i, n + s, a, a);
325
+ }
326
+ }
327
+ break;
328
+ }
329
+ case "text": e.font = `bold ${Math.max(14, i * 6)}px system-ui, sans-serif`, e.lineWidth = i * 1.5, e.strokeStyle = "#ffffff", e.strokeText(t.text ?? "", a, o), e.fillText(t.text ?? "", a, o);
330
+ }
331
+ e.restore();
332
+ }
333
+ //#endregion
334
+ export { m as MarkupEditor };