dsh-codex-subscription 3.1.9 → 3.2.1

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,1191 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "dsh-codex-subscription",
3
+ chunk: "client.image-viewer.js",
4
+ factory: (require) => {
5
+ var module = { exports: {} };
6
+ var exports = module.exports;
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ //#region /0rolldown/runtime.js
9
+ var __create = Object.create;
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __getProtoOf = Object.getPrototypeOf;
14
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
17
+ key = keys[i];
18
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: ((k) => from[k]).bind(null, key),
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: true
28
+ }) : target, mod));
29
+ //#endregion
30
+ let react = require("react");
31
+ react = __toESM(react, 1);
32
+ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
33
+ _deepseek_ai_dsh_client_ui_primitives = __toESM(_deepseek_ai_dsh_client_ui_primitives, 1);
34
+ let react_dom = require("react-dom");
35
+ let react_jsx_runtime = require("react/jsx-runtime");
36
+ //#region src/client-primitives.js
37
+ const IconChevronRightOutline14 = _deepseek_ai_dsh_client_ui_primitives.IconChevronRightOutlineRegular;
38
+ const IconChevronLeftOutline14 = _deepseek_ai_dsh_client_ui_primitives.IconChevronLeftOutlineRegular;
39
+ const IconCloseOutline16 = _deepseek_ai_dsh_client_ui_primitives.IconCloseOutlineRegular;
40
+ const IconCopyOutline16 = _deepseek_ai_dsh_client_ui_primitives.IconCopyOutlineRegular;
41
+ const IconDownloadOutline16 = _deepseek_ai_dsh_client_ui_primitives.IconDownloadOutlineRegular;
42
+ const IconEditOutline16 = _deepseek_ai_dsh_client_ui_primitives.IconEditOutlineRegular;
43
+ //#endregion
44
+ //#region src/subscription-image-viewer-styles.js
45
+ const SUBSCRIPTION_IMAGE_VIEWER_CSS = String.raw`
46
+ .dcsiv-root{position:fixed;inset:0;z-index:1000;pointer-events:auto;overflow:hidden;background:rgba(7,8,10,.68);color:var(--dsw-alias-label-primary-inverted,#fff);outline:0;backdrop-filter:blur(13px) saturate(.72);-webkit-backdrop-filter:blur(13px) saturate(.72)}
47
+ .dcsiv-sr-only{position:absolute!important;width:1px!important;height:1px!important;padding:0!important;margin:-1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;white-space:nowrap!important;border:0!important}
48
+ .dcsiv-topbar{position:absolute;right:50%;bottom:22px;z-index:6;max-width:calc(100vw - 36px);padding:5px;border:1px solid rgba(255,255,255,.12);border-radius:999px;background:rgba(38,39,43,.86);box-shadow:0 10px 34px rgba(0,0,0,.3);transform:translateX(50%);backdrop-filter:blur(18px);-webkit-backdrop-filter:blur(18px)}
49
+ .dcsiv-actions{display:flex;align-items:center;gap:2px;overflow-x:auto;scrollbar-width:none}.dcsiv-actions::-webkit-scrollbar{display:none}.dcsiv-button,.dcsiv-download{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:6px;height:32px;padding:0 10px;border:0;border-radius:999px;background:transparent;color:rgba(255,255,255,.9);font:inherit;font-size:12px;text-decoration:none;white-space:nowrap;cursor:pointer}.dcsiv-button:hover,.dcsiv-download:hover,.dcsiv-button[data-active=true]{background:rgba(255,255,255,.12)}.dcsiv-button:focus-visible,.dcsiv-download:focus-visible,.dcsiv-close-floating:focus-visible{outline:2px solid rgba(255,255,255,.9);outline-offset:2px}.dcsiv-button:disabled,.dcsiv-download:disabled{opacity:.38;cursor:default}.dcsiv-icon-only{width:32px;padding:0}.dcsiv-zoom{min-width:44px;color:rgba(255,255,255,.68);font-size:12px;font-variant-numeric:tabular-nums;text-align:center}
50
+ .dcsiv-close-floating{position:absolute;top:20px;right:20px;z-index:8;display:grid;place-items:center;width:42px;height:42px;padding:0;border:1px solid rgba(255,255,255,.1);border-radius:50%;background:rgba(48,49,53,.82);box-shadow:0 8px 24px rgba(0,0,0,.28);color:#fff;cursor:pointer;backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px)}.dcsiv-close-floating:hover{background:rgba(66,67,72,.92)}
51
+ .dcsiv-workspace{position:absolute;inset:0;display:grid;min-width:0;min-height:0;padding:68px 24px 72px;box-sizing:border-box}
52
+ .dcsiv-stage{position:relative;display:grid;place-items:center;min-width:0;min-height:0;overflow:hidden;padding:0;touch-action:none;user-select:none}.dcsiv-stage[data-dragging=true]{cursor:grabbing}.dcsiv-stage[data-annotating=true]{cursor:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Ccircle cx='12' cy='12' r='7' fill='none' stroke='white' stroke-width='2'/%3E%3Ccircle cx='12' cy='12' r='8' fill='none' stroke='%23333'/%3E%3C/svg%3E") 12 12,pointer}
53
+ .dcsiv-surface{position:relative;display:inline-flex;max-width:100%;max-height:100%;transform-origin:center;will-change:transform}.dcsiv-image{display:block;max-width:calc(100vw - 72px);max-height:calc(100vh - 154px);border-radius:12px;object-fit:contain;box-shadow:0 22px 60px rgba(0,0,0,.46);user-select:none;-webkit-user-drag:none}
54
+ .dcsiv-annotation{position:absolute;z-index:5;width:24px;height:24px;transform-origin:center;pointer-events:none}.dcsiv-pin{position:absolute;inset:0;display:grid;place-items:center;width:24px;height:24px;padding:0;border:2px solid #fff;border-radius:50%;background:rgba(23,24,27,.94);box-shadow:0 4px 16px rgba(0,0,0,.35);color:#fff;font:inherit;font-size:11px;font-weight:700;cursor:pointer;pointer-events:auto}.dcsiv-pin[data-active=true]{background:var(--dsw-alias-state-business-primary,#3964fe)}
55
+ .dcsiv-inline-note{position:absolute;bottom:34px;box-sizing:border-box;display:grid;width:min(300px,calc(100vw - 40px));grid-template-columns:24px minmax(0,1fr) 24px;align-items:center;gap:7px;padding:7px 8px;border:1px solid rgba(255,255,255,.12);border-radius:18px;background:rgba(32,33,37,.94);box-shadow:0 14px 38px rgba(0,0,0,.38);color:#fff;pointer-events:auto;backdrop-filter:blur(20px);-webkit-backdrop-filter:blur(20px)}.dcsiv-annotation[data-x=right] .dcsiv-inline-note{left:-8px}.dcsiv-annotation[data-x=left] .dcsiv-inline-note{right:-8px}.dcsiv-annotation[data-x=center] .dcsiv-inline-note{left:50%;transform:translateX(-50%)}.dcsiv-annotation[data-y=down] .dcsiv-inline-note{top:34px;bottom:auto}.dcsiv-inline-note::after{position:absolute;width:9px;height:9px;background:rgba(32,33,37,.94);content:'';transform:rotate(45deg)}.dcsiv-annotation[data-y=up] .dcsiv-inline-note::after{bottom:-5px}.dcsiv-annotation[data-y=down] .dcsiv-inline-note::after{top:-5px}.dcsiv-annotation[data-x=right] .dcsiv-inline-note::after{left:13px}.dcsiv-annotation[data-x=left] .dcsiv-inline-note::after{right:13px}.dcsiv-annotation[data-x=center] .dcsiv-inline-note::after{left:calc(50% - 4px)}.dcsiv-inline-index{display:grid;place-items:center;width:22px;height:22px;border-radius:50%;background:var(--dsw-alias-state-business-primary,#3964fe);color:#fff;font-size:10px;font-weight:700}.dcsiv-inline-note textarea{box-sizing:border-box;width:100%;min-height:24px;max-height:92px;resize:none;overflow:auto;border:0;outline:0;background:transparent;color:#fff;font:inherit;font-size:12px;line-height:18px}.dcsiv-inline-note textarea::placeholder{color:rgba(255,255,255,.44)}.dcsiv-note-remove{display:grid;place-items:center;width:24px;height:24px;padding:0;border:0;border-radius:50%;background:transparent;color:rgba(255,255,255,.68);cursor:pointer}.dcsiv-note-remove:hover{background:rgba(255,255,255,.1);color:#fff}
56
+ .dcsiv-nav{position:absolute;top:50%;z-index:4;width:42px;height:42px;padding:0;transform:translateY(-50%);background:rgba(48,49,53,.82);box-shadow:0 8px 24px rgba(0,0,0,.28);backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px)}.dcsiv-prev{left:6px}.dcsiv-next{right:6px}.dcsiv-counter{position:absolute;bottom:8px;left:50%;padding:5px 10px;border-radius:999px;background:rgba(38,39,43,.86);color:rgba(255,255,255,.72);font-size:11px;transform:translateX(-50%);backdrop-filter:blur(16px)}
57
+ .dcsiv-hint{display:none}
58
+ .dcsiv-mask{position:absolute;inset:0;width:100%;height:100%;border-radius:12px;cursor:crosshair;touch-action:none}
59
+ .dcsiv-tool-icon{width:16px;height:16px;flex:none}.dcsiv-icon-button,.dcsiv-download[data-compact="true"]{width:34px;padding:0!important;justify-content:center}.dcsiv-zoom{min-width:52px;font-variant-numeric:tabular-nums}.dcsiv-divider{width:1px;height:18px;margin:0 4px;background:rgba(255,255,255,.14)}.dcsiv-menu{position:fixed;z-index:12;display:flex;flex-direction:column;min-width:150px;padding:6px;border:1px solid rgba(255,255,255,.12);border-radius:12px;background:rgba(32,33,37,.97);box-shadow:0 12px 32px rgba(0,0,0,.4)}.dcsiv-menu button{height:32px;padding:0 10px;border:0;border-radius:8px;background:none;color:rgba(255,255,255,.9);font:inherit;font-size:13px;text-align:left;cursor:pointer}.dcsiv-menu button:hover,.dcsiv-menu button:focus-visible{outline:none;background:rgba(255,255,255,.1)}
60
+ .dcsiv-erase-bar{position:absolute;left:50%;top:22px;z-index:7;display:flex;align-items:center;gap:10px;padding:6px 8px 6px 14px;transform:translateX(-50%);border:1px solid rgba(255,255,255,.1);border-radius:999px;background:rgba(38,39,43,.92);color:rgba(255,255,255,.86);font-size:12px;white-space:nowrap}.dcsiv-erase-bar label{display:inline-flex;align-items:center;gap:6px}.dcsiv-erase-bar input{width:90px}.dcsiv-primary{background:#fff!important;color:#111!important}.dcsiv-primary[data-state="failed"]{color:#c62828!important}.dcsiv-brush-cursor{position:fixed;z-index:9;pointer-events:none;border:1.5px solid #fff;border-radius:50%;corner-shape:round;box-shadow:0 0 0 1px rgba(0,0,0,.45),inset 0 0 0 1px rgba(0,0,0,.25);transform:translate(-50%,-50%)}@media(pointer:fine){.dcsiv-mask{cursor:none}}.dcsiv-button[data-state="pending"] .dcsiv-tool-icon{animation:dcsiv-pulse 1s ease-in-out infinite}.dcsiv-button[data-state="failed"]{color:#ff8a80!important}@keyframes dcsiv-pulse{50%{opacity:.3}}
61
+ .dcsiv-copy-notes{position:absolute;right:20px;bottom:22px;z-index:6;display:inline-flex;align-items:center;gap:6px;height:32px;padding:0 11px;border:1px solid rgba(255,255,255,.1);border-radius:999px;background:rgba(38,39,43,.86);color:rgba(255,255,255,.82);font:inherit;font-size:12px;cursor:pointer;backdrop-filter:blur(16px)}
62
+ .dcsiv-edit-short{display:none}
63
+ @media(max-width:760px){.dcsiv-actions{flex-wrap:wrap;justify-content:center}.dcsiv-edit-short{display:inline;white-space:normal;max-width:min(280px,calc(100vw - 80px))}.dcsiv-edit-action{height:auto;min-height:32px}.dcsiv-close-floating{top:12px;right:12px;width:40px;height:40px}.dcsiv-workspace{padding:60px 12px 68px}.dcsiv-image{max-width:calc(100vw - 24px);max-height:calc(100vh - 136px)}.dcsiv-topbar{bottom:12px;max-width:calc(100vw - 24px)}.dcsiv-button{padding:0 8px}.dcsiv-button span.dcsiv-label{display:none}.dcsiv-inline-note{width:min(260px,calc(100vw - 40px))}.dcsiv-copy-notes{display:none}}
64
+ @media(prefers-reduced-motion:reduce){.dcsiv-surface{transition:none}.dcsiv-tool-icon{animation:none!important}}
65
+ `;
66
+ //#endregion
67
+ //#region src/subscription-image-transform.js
68
+ const clamp$1 = (value, min, max) => Math.min(max, Math.max(min, value));
69
+ const fitted = () => ({
70
+ zoom: 1,
71
+ x: 0,
72
+ y: 0
73
+ });
74
+ function useImageTransform(identity) {
75
+ const [transform, setTransform] = (0, react.useState)(fitted);
76
+ const [dragging, setDragging] = (0, react.useState)(false);
77
+ const [pixelScale, setPixelScale] = (0, react.useState)(1);
78
+ const [geometry, setGeometry] = (0, react.useState)({
79
+ width: 0,
80
+ height: 0,
81
+ stageWidth: 0,
82
+ stageHeight: 0
83
+ });
84
+ const stageRef = (0, react.useRef)(null), surfaceRef = (0, react.useRef)(null), imageRef = (0, react.useRef)(null);
85
+ const transformRef = (0, react.useRef)(transform);
86
+ const pointers = (0, react.useRef)(/* @__PURE__ */ new Map()), gesture = (0, react.useRef)();
87
+ transformRef.current = transform;
88
+ const resetGesture = (0, react.useCallback)(() => {
89
+ pointers.current.clear();
90
+ gesture.current = void 0;
91
+ setDragging(false);
92
+ }, []);
93
+ const fit = (0, react.useCallback)(() => {
94
+ resetGesture();
95
+ setTransform(fitted());
96
+ }, [resetGesture]);
97
+ (0, react.useEffect)(() => {
98
+ fit();
99
+ }, [identity, fit]);
100
+ const actualScale = () => imageRef.current?.naturalWidth / Math.max(1, surfaceRef.current?.offsetWidth || 1) || 1;
101
+ const boundedPan = (0, react.useCallback)((zoom, x, y) => {
102
+ const stage = stageRef.current, surface = surfaceRef.current;
103
+ if (!stage || !surface || zoom <= 1) return {
104
+ x: 0,
105
+ y: 0
106
+ };
107
+ const limitX = Math.max(0, (surface.offsetWidth * zoom - stage.clientWidth) / 2);
108
+ const limitY = Math.max(0, (surface.offsetHeight * zoom - stage.clientHeight) / 2);
109
+ return {
110
+ x: clamp$1(x, -limitX, limitX),
111
+ y: clamp$1(y, -limitY, limitY)
112
+ };
113
+ }, []);
114
+ const setZoomAt = (0, react.useCallback)((zoom, clientX, clientY) => {
115
+ const stage = stageRef.current;
116
+ if (!stage) return;
117
+ setTransform((current) => {
118
+ const next = clamp$1(zoom, .5, Math.max(8, actualScale()));
119
+ const box = stage.getBoundingClientRect();
120
+ const px = clientX - box.left - box.width / 2, py = clientY - box.top - box.height / 2;
121
+ const ratio = next / current.zoom;
122
+ return {
123
+ zoom: next,
124
+ ...boundedPan(next, px - (px - current.x) * ratio, py - (py - current.y) * ratio)
125
+ };
126
+ });
127
+ }, [boundedPan]);
128
+ const actual = (0, react.useCallback)(() => {
129
+ if (!imageRef.current?.naturalWidth) return;
130
+ resetGesture();
131
+ setTransform({
132
+ zoom: actualScale(),
133
+ x: 0,
134
+ y: 0
135
+ });
136
+ }, [resetGesture]);
137
+ const measure = (0, react.useCallback)(() => {
138
+ const next = {
139
+ width: surfaceRef.current?.offsetWidth ?? 0,
140
+ height: surfaceRef.current?.offsetHeight ?? 0,
141
+ stageWidth: stageRef.current?.clientWidth ?? 0,
142
+ stageHeight: stageRef.current?.clientHeight ?? 0
143
+ };
144
+ setGeometry((current) => Object.keys(next).every((key) => current[key] === next[key]) ? current : next);
145
+ setPixelScale(1 / actualScale());
146
+ setTransform((current) => ({
147
+ ...current,
148
+ ...boundedPan(current.zoom, current.x, current.y)
149
+ }));
150
+ }, [boundedPan]);
151
+ (0, react.useEffect)(() => {
152
+ if (!stageRef.current || !surfaceRef.current) return;
153
+ const observer = new ResizeObserver(measure);
154
+ observer.observe(stageRef.current);
155
+ observer.observe(surfaceRef.current);
156
+ measure();
157
+ return () => observer.disconnect();
158
+ }, [identity, measure]);
159
+ (0, react.useEffect)(() => {
160
+ const stage = stageRef.current;
161
+ if (!stage) return;
162
+ const wheel = (event) => {
163
+ event.preventDefault();
164
+ const delta = event.deltaY * (event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? stage.clientHeight : 1);
165
+ setZoomAt(transformRef.current.zoom * Math.exp(-delta * .0015), event.clientX, event.clientY);
166
+ };
167
+ stage.addEventListener("wheel", wheel, { passive: false });
168
+ return () => stage.removeEventListener("wheel", wheel);
169
+ }, [identity, setZoomAt]);
170
+ const onPointerDown = (event) => {
171
+ if (event.button !== 0 || event.target.closest("button,a,input,textarea,select")) return;
172
+ const current = transformRef.current;
173
+ if (event.pointerType === "mouse" && current.zoom <= 1) return;
174
+ event.currentTarget.setPointerCapture(event.pointerId);
175
+ pointers.current.set(event.pointerId, {
176
+ x: event.clientX,
177
+ y: event.clientY
178
+ });
179
+ if (pointers.current.size === 2) {
180
+ const [a, b] = [...pointers.current.values()];
181
+ gesture.current = {
182
+ kind: "pinch",
183
+ distance: Math.hypot(a.x - b.x, a.y - b.y),
184
+ transform: current
185
+ };
186
+ } else gesture.current = {
187
+ kind: "pan",
188
+ x: event.clientX,
189
+ y: event.clientY,
190
+ transform: current
191
+ };
192
+ setDragging(true);
193
+ };
194
+ const onPointerMove = (event) => {
195
+ if (!pointers.current.has(event.pointerId)) return;
196
+ pointers.current.set(event.pointerId, {
197
+ x: event.clientX,
198
+ y: event.clientY
199
+ });
200
+ const start = gesture.current;
201
+ if (start?.kind === "pinch" && pointers.current.size >= 2) {
202
+ const [a, b] = [...pointers.current.values()];
203
+ setZoomAt(start.transform.zoom * Math.hypot(a.x - b.x, a.y - b.y) / Math.max(1, start.distance), (a.x + b.x) / 2, (a.y + b.y) / 2);
204
+ } else if (start?.kind === "pan") setTransform({
205
+ zoom: start.transform.zoom,
206
+ ...boundedPan(start.transform.zoom, start.transform.x + event.clientX - start.x, start.transform.y + event.clientY - start.y)
207
+ });
208
+ };
209
+ const endPointer = (event) => {
210
+ pointers.current.delete(event.pointerId);
211
+ const remaining = [...pointers.current.values()][0];
212
+ if (remaining) gesture.current = {
213
+ kind: "pan",
214
+ ...remaining,
215
+ transform: transformRef.current
216
+ };
217
+ else resetGesture();
218
+ };
219
+ return {
220
+ transform,
221
+ transformRef,
222
+ dragging,
223
+ pixelScale,
224
+ geometry,
225
+ stageRef,
226
+ surfaceRef,
227
+ imageRef,
228
+ fit,
229
+ actual,
230
+ measure,
231
+ setZoomAt,
232
+ resetGesture,
233
+ pointerHandlers: {
234
+ onPointerDown,
235
+ onPointerMove,
236
+ onPointerUp: endPointer,
237
+ onPointerCancel: endPointer,
238
+ onLostPointerCapture: endPointer
239
+ }
240
+ };
241
+ }
242
+ Object.freeze([
243
+ ["square", "1:1"],
244
+ ["portrait", "3:4"],
245
+ ["story", "9:16"],
246
+ ["landscape", "4:3"],
247
+ ["widescreen", "16:9"]
248
+ ]);
249
+ /** Draw relative erase strokes in one color onto a canvas of the given size. */
250
+ function paintEraseStrokes(context, strokes, width, height, color) {
251
+ context.strokeStyle = color;
252
+ context.fillStyle = color;
253
+ context.lineCap = "round";
254
+ context.lineJoin = "round";
255
+ const scale = Math.min(width, height);
256
+ for (const stroke of strokes) {
257
+ const points = stroke.points;
258
+ if (points.length === 0) continue;
259
+ context.lineWidth = stroke.size * scale;
260
+ context.beginPath();
261
+ if (points.length === 1) {
262
+ context.arc(points[0].x * width, points[0].y * height, stroke.size * scale / 2, 0, Math.PI * 2);
263
+ context.fill();
264
+ continue;
265
+ }
266
+ context.moveTo(points[0].x * width, points[0].y * height);
267
+ for (const point of points.slice(1)) context.lineTo(point.x * width, point.y * height);
268
+ context.stroke();
269
+ }
270
+ }
271
+ /** Codex's erase mask: the marked area white on black, at the image's own resolution. */
272
+ function paintEraseMask(context, strokes, width, height) {
273
+ context.fillStyle = "#000";
274
+ context.fillRect(0, 0, width, height);
275
+ paintEraseStrokes(context, strokes, width, height, "#fff");
276
+ }
277
+ //#endregion
278
+ //#region node_modules/.pnpm/@heroicons+react@2.2.0_react@18.3.1/node_modules/@heroicons/react/24/outline/esm/ArrowsPointingOutIcon.js
279
+ function ArrowsPointingOutIcon({ title, titleId, ...props }, svgRef) {
280
+ return /*#__PURE__*/ react.createElement("svg", Object.assign({
281
+ xmlns: "http://www.w3.org/2000/svg",
282
+ fill: "none",
283
+ viewBox: "0 0 24 24",
284
+ strokeWidth: 1.5,
285
+ stroke: "currentColor",
286
+ "aria-hidden": "true",
287
+ "data-slot": "icon",
288
+ ref: svgRef,
289
+ "aria-labelledby": titleId
290
+ }, props), title ? /*#__PURE__*/ react.createElement("title", { id: titleId }, title) : null, /*#__PURE__*/ react.createElement("path", {
291
+ strokeLinecap: "round",
292
+ strokeLinejoin: "round",
293
+ d: "M3.75 3.75v4.5m0-4.5h4.5m-4.5 0L9 9M3.75 20.25v-4.5m0 4.5h4.5m-4.5 0L9 15M20.25 3.75h-4.5m4.5 0v4.5m0-4.5L15 9m5.25 11.25h-4.5m4.5 0v-4.5m0 4.5L15 15"
294
+ }));
295
+ }
296
+ const ForwardRef$4 = /*#__PURE__*/ react.forwardRef(ArrowsPointingOutIcon);
297
+ //#endregion
298
+ //#region node_modules/.pnpm/@heroicons+react@2.2.0_react@18.3.1/node_modules/@heroicons/react/24/outline/esm/ChatBubbleLeftEllipsisIcon.js
299
+ function ChatBubbleLeftEllipsisIcon({ title, titleId, ...props }, svgRef) {
300
+ return /*#__PURE__*/ react.createElement("svg", Object.assign({
301
+ xmlns: "http://www.w3.org/2000/svg",
302
+ fill: "none",
303
+ viewBox: "0 0 24 24",
304
+ strokeWidth: 1.5,
305
+ stroke: "currentColor",
306
+ "aria-hidden": "true",
307
+ "data-slot": "icon",
308
+ ref: svgRef,
309
+ "aria-labelledby": titleId
310
+ }, props), title ? /*#__PURE__*/ react.createElement("title", { id: titleId }, title) : null, /*#__PURE__*/ react.createElement("path", {
311
+ strokeLinecap: "round",
312
+ strokeLinejoin: "round",
313
+ d: "M8.625 9.75a.375.375 0 1 1-.75 0 .375.375 0 0 1 .75 0Zm0 0H8.25m4.125 0a.375.375 0 1 1-.75 0 .375.375 0 0 1 .75 0Zm0 0H12m4.125 0a.375.375 0 1 1-.75 0 .375.375 0 0 1 .75 0Zm0 0h-.375m-13.5 3.01c0 1.6 1.123 2.994 2.707 3.227 1.087.16 2.185.283 3.293.369V21l4.184-4.183a1.14 1.14 0 0 1 .778-.332 48.294 48.294 0 0 0 5.83-.498c1.585-.233 2.708-1.626 2.708-3.228V6.741c0-1.602-1.123-2.995-2.707-3.228A48.394 48.394 0 0 0 12 3c-2.392 0-4.744.175-7.043.513C3.373 3.746 2.25 5.14 2.25 6.741v6.018Z"
314
+ }));
315
+ }
316
+ const ForwardRef$3 = /*#__PURE__*/ react.forwardRef(ChatBubbleLeftEllipsisIcon);
317
+ //#endregion
318
+ //#region node_modules/.pnpm/@heroicons+react@2.2.0_react@18.3.1/node_modules/@heroicons/react/24/outline/esm/PaintBrushIcon.js
319
+ function PaintBrushIcon({ title, titleId, ...props }, svgRef) {
320
+ return /*#__PURE__*/ react.createElement("svg", Object.assign({
321
+ xmlns: "http://www.w3.org/2000/svg",
322
+ fill: "none",
323
+ viewBox: "0 0 24 24",
324
+ strokeWidth: 1.5,
325
+ stroke: "currentColor",
326
+ "aria-hidden": "true",
327
+ "data-slot": "icon",
328
+ ref: svgRef,
329
+ "aria-labelledby": titleId
330
+ }, props), title ? /*#__PURE__*/ react.createElement("title", { id: titleId }, title) : null, /*#__PURE__*/ react.createElement("path", {
331
+ strokeLinecap: "round",
332
+ strokeLinejoin: "round",
333
+ d: "M9.53 16.122a3 3 0 0 0-5.78 1.128 2.25 2.25 0 0 1-2.4 2.245 4.5 4.5 0 0 0 8.4-2.245c0-.399-.078-.78-.22-1.128Zm0 0a15.998 15.998 0 0 0 3.388-1.62m-5.043-.025a15.994 15.994 0 0 1 1.622-3.395m3.42 3.42a15.995 15.995 0 0 0 4.764-4.648l3.876-5.814a1.151 1.151 0 0 0-1.597-1.597L14.146 6.32a15.996 15.996 0 0 0-4.649 4.763m3.42 3.42a6.776 6.776 0 0 0-3.42-3.42"
334
+ }));
335
+ }
336
+ const ForwardRef$2 = /*#__PURE__*/ react.forwardRef(PaintBrushIcon);
337
+ //#endregion
338
+ //#region node_modules/.pnpm/@heroicons+react@2.2.0_react@18.3.1/node_modules/@heroicons/react/24/outline/esm/PencilIcon.js
339
+ function PencilIcon({ title, titleId, ...props }, svgRef) {
340
+ return /*#__PURE__*/ react.createElement("svg", Object.assign({
341
+ xmlns: "http://www.w3.org/2000/svg",
342
+ fill: "none",
343
+ viewBox: "0 0 24 24",
344
+ strokeWidth: 1.5,
345
+ stroke: "currentColor",
346
+ "aria-hidden": "true",
347
+ "data-slot": "icon",
348
+ ref: svgRef,
349
+ "aria-labelledby": titleId
350
+ }, props), title ? /*#__PURE__*/ react.createElement("title", { id: titleId }, title) : null, /*#__PURE__*/ react.createElement("path", {
351
+ strokeLinecap: "round",
352
+ strokeLinejoin: "round",
353
+ d: "m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L6.832 19.82a4.5 4.5 0 0 1-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 0 1 1.13-1.897L16.863 4.487Zm0 0L19.5 7.125"
354
+ }));
355
+ }
356
+ const ForwardRef$1 = /*#__PURE__*/ react.forwardRef(PencilIcon);
357
+ //#endregion
358
+ //#region node_modules/.pnpm/@heroicons+react@2.2.0_react@18.3.1/node_modules/@heroicons/react/24/outline/esm/ScissorsIcon.js
359
+ function ScissorsIcon({ title, titleId, ...props }, svgRef) {
360
+ return /*#__PURE__*/ react.createElement("svg", Object.assign({
361
+ xmlns: "http://www.w3.org/2000/svg",
362
+ fill: "none",
363
+ viewBox: "0 0 24 24",
364
+ strokeWidth: 1.5,
365
+ stroke: "currentColor",
366
+ "aria-hidden": "true",
367
+ "data-slot": "icon",
368
+ ref: svgRef,
369
+ "aria-labelledby": titleId
370
+ }, props), title ? /*#__PURE__*/ react.createElement("title", { id: titleId }, title) : null, /*#__PURE__*/ react.createElement("path", {
371
+ strokeLinecap: "round",
372
+ strokeLinejoin: "round",
373
+ d: "m7.848 8.25 1.536.887M7.848 8.25a3 3 0 1 1-5.196-3 3 3 0 0 1 5.196 3Zm1.536.887a2.165 2.165 0 0 1 1.083 1.839c.005.351.054.695.14 1.024M9.384 9.137l2.077 1.199M7.848 15.75l1.536-.887m-1.536.887a3 3 0 1 1-5.196 3 3 3 0 0 1 5.196-3Zm1.536-.887a2.165 2.165 0 0 0 1.083-1.838c.005-.352.054-.695.14-1.025m-1.223 2.863 2.077-1.199m0-3.328a4.323 4.323 0 0 1 2.068-1.379l5.325-1.628a4.5 4.5 0 0 1 2.48-.044l.803.215-7.794 4.5m-2.882-1.664A4.33 4.33 0 0 0 10.607 12m3.736 0 7.794 4.5-.802.215a4.5 4.5 0 0 1-2.48-.043l-5.326-1.629a4.324 4.324 0 0 1-2.068-1.379M14.343 12l-2.882 1.664"
374
+ }));
375
+ }
376
+ //#endregion
377
+ //#region src/subscription-image-viewer.jsx
378
+ const TOOL_ICONS = {
379
+ "remove-background": /* @__PURE__ */ react.forwardRef(ScissorsIcon),
380
+ erase: ForwardRef$2,
381
+ resize: ForwardRef$4,
382
+ sketch: ForwardRef$1,
383
+ annotate: ForwardRef$3
384
+ };
385
+ const ToolIcon = ({ id }) => {
386
+ const Icon = TOOL_ICONS[id];
387
+ return Icon ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {
388
+ className: "dcsiv-tool-icon",
389
+ "aria-hidden": "true"
390
+ }) : null;
391
+ };
392
+ const fill = (value, variables) => Object.entries(variables).reduce((text, [key, replacement]) => text.replaceAll(`{${key}}`, String(replacement)), value);
393
+ const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
394
+ const bytesLabel = (bytes) => bytes === void 0 ? void 0 : bytes < 1024 * 1024 ? `${Math.max(.1, bytes / 1024).toLocaleString(void 0, { maximumFractionDigits: 1 })} KB` : `${(bytes / 1024 / 1024).toLocaleString(void 0, { maximumFractionDigits: 1 })} MB`;
395
+ const downloadName = (name) => {
396
+ const cleaned = String(name || "image.png").replace(/[<>:"/\\|?*\u0000-\u001f]/gu, "-").replace(/[. ]+$/u, "").trim();
397
+ return cleaned === "" ? "image.png" : cleaned;
398
+ };
399
+ const noteText = (annotations, t) => annotations.map((annotation, index) => {
400
+ return `${fill(t("imageAnnotation"), { value: index + 1 })} (${Math.round(annotation.x * 100)}%, ${Math.round(annotation.y * 100)}%): ${annotation.note.trim()}`;
401
+ }).filter((line) => !line.endsWith(": ")).join("\n");
402
+ function ViewerAction({ action, annotations, item, service, revision, t, onStartMask }) {
403
+ const [state, setState] = (0, react.useState)("idle");
404
+ const [menu, setMenu] = (0, react.useState)();
405
+ const active = (0, react.useRef)(true);
406
+ const menuRef = (0, react.useRef)(null);
407
+ const menuButtonRef = (0, react.useRef)(null);
408
+ (0, react.useEffect)(() => {
409
+ active.current = true;
410
+ return () => {
411
+ active.current = false;
412
+ };
413
+ }, []);
414
+ (0, react.useEffect)(() => {
415
+ if (menu === void 0) return void 0;
416
+ menuRef.current?.querySelector("[role=\"menuitem\"]")?.focus();
417
+ const onKeyDown = (event) => {
418
+ const items = [...menuRef.current?.querySelectorAll("[role=\"menuitem\"]") ?? []];
419
+ if (event.key === "Escape") {
420
+ event.preventDefault();
421
+ event.stopPropagation();
422
+ setMenu(void 0);
423
+ menuButtonRef.current?.focus();
424
+ } else if ((event.key === "ArrowDown" || event.key === "ArrowUp") && items.length > 0) {
425
+ event.preventDefault();
426
+ event.stopPropagation();
427
+ const step = event.key === "ArrowDown" ? 1 : -1;
428
+ items[(items.indexOf(document.activeElement) + step + items.length) % items.length].focus();
429
+ } else if (event.key === "Tab") setMenu(void 0);
430
+ };
431
+ const onPointerDown = (event) => {
432
+ if (!menuRef.current?.contains(event.target) && !menuButtonRef.current?.contains(event.target)) setMenu(void 0);
433
+ };
434
+ window.addEventListener("keydown", onKeyDown, true);
435
+ window.addEventListener("pointerdown", onPointerDown, true);
436
+ return () => {
437
+ window.removeEventListener("keydown", onKeyDown, true);
438
+ window.removeEventListener("pointerdown", onPointerDown, true);
439
+ };
440
+ }, [menu]);
441
+ const invoke = async (extra = {}) => {
442
+ if (state === "pending") return;
443
+ setState("pending");
444
+ try {
445
+ await action.onInvoke({
446
+ annotations,
447
+ item,
448
+ src: item.src,
449
+ ...extra
450
+ });
451
+ if (!active.current || service.getSnapshot()?.revision !== revision) return;
452
+ setState("idle");
453
+ if (action.closeOnSuccess) service.close();
454
+ } catch {
455
+ if (active.current) setState("failed");
456
+ }
457
+ };
458
+ const label = state === "pending" ? action.pendingLabel : state === "failed" ? action.errorLabel : action.label;
459
+ if (action.kind === "mask") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
460
+ type: "button",
461
+ className: "dcsiv-button dcsiv-icon-button",
462
+ title: action.label,
463
+ "aria-label": action.label,
464
+ onClick: () => onStartMask(action),
465
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolIcon, { id: action.id })
466
+ });
467
+ if (action.kind === "tool") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
468
+ type: "button",
469
+ className: "dcsiv-button dcsiv-icon-button",
470
+ title: label,
471
+ "aria-label": label,
472
+ "data-state": state,
473
+ disabled: state === "pending",
474
+ onClick: () => {
475
+ invoke();
476
+ },
477
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolIcon, { id: action.id })
478
+ });
479
+ if (action.id === "sketch" && state === "idle") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
480
+ type: "button",
481
+ className: "dcsiv-button dcsiv-icon-button",
482
+ title: action.label,
483
+ "aria-label": action.label,
484
+ onClick: () => {
485
+ invoke();
486
+ },
487
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolIcon, { id: "sketch" })
488
+ });
489
+ if (action.kind === "choice") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
490
+ ref: menuButtonRef,
491
+ type: "button",
492
+ "aria-haspopup": "menu",
493
+ "aria-expanded": menu !== void 0,
494
+ "data-state": state,
495
+ disabled: state === "pending",
496
+ onClick: (event) => {
497
+ const box = event.currentTarget.getBoundingClientRect();
498
+ const host = event.currentTarget.closest(".dcsiv-root");
499
+ setMenu((value) => value === void 0 && host ? {
500
+ host,
501
+ style: {
502
+ left: box.left,
503
+ bottom: window.innerHeight - box.top + 8
504
+ }
505
+ } : void 0);
506
+ },
507
+ className: "dcsiv-button dcsiv-icon-button",
508
+ title: label,
509
+ "aria-label": label,
510
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolIcon, { id: action.id })
511
+ }), menu ? (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
512
+ ref: menuRef,
513
+ className: "dcsiv-menu",
514
+ role: "menu",
515
+ "aria-label": action.label,
516
+ style: menu.style,
517
+ children: action.options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
518
+ type: "button",
519
+ role: "menuitem",
520
+ onClick: () => {
521
+ setMenu(void 0);
522
+ invoke({ option: option.value });
523
+ },
524
+ children: option.label
525
+ }, option.value))
526
+ }), menu.host) : null] });
527
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
528
+ type: "button",
529
+ className: "dcsiv-button dcsiv-edit-action",
530
+ "aria-label": label ?? t("imageEdit"),
531
+ disabled: state === "pending",
532
+ onClick: () => {
533
+ invoke();
534
+ },
535
+ children: [
536
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconEditOutline16, {}),
537
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
538
+ className: "dcsiv-label",
539
+ children: label ?? t("imageEdit")
540
+ }),
541
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
542
+ className: "dcsiv-edit-short",
543
+ children: state === "idle" ? action.id === "sketch" ? t("imageToSketch") : t("imageEditShort") : label
544
+ })
545
+ ]
546
+ });
547
+ }
548
+ function ViewerDownload({ download, item, t }) {
549
+ const [state, setState] = (0, react.useState)("idle");
550
+ const [progress, setProgress] = (0, react.useState)(0);
551
+ const active = (0, react.useRef)();
552
+ (0, react.useEffect)(() => () => {
553
+ active.current?.abort();
554
+ active.current = void 0;
555
+ }, [item.id, download]);
556
+ const invoke = async () => {
557
+ if (active.current) {
558
+ active.current.abort();
559
+ active.current = void 0;
560
+ setState("idle");
561
+ return;
562
+ }
563
+ const controller = new AbortController();
564
+ active.current = controller;
565
+ setProgress(0);
566
+ setState("pending");
567
+ try {
568
+ await download.onInvoke({
569
+ item,
570
+ src: item.src,
571
+ signal: controller.signal,
572
+ onProgress: ({ loaded, total }) => {
573
+ if (active.current === controller) setProgress(Math.floor(loaded / total * 100));
574
+ }
575
+ });
576
+ if (active.current === controller) setState("idle");
577
+ } catch {
578
+ if (active.current === controller) setState(controller.signal.aborted ? "idle" : "failed");
579
+ } finally {
580
+ if (active.current === controller) active.current = void 0;
581
+ }
582
+ };
583
+ const label = state === "pending" ? download.pendingLabel ?? t("imageDownloadPreparing") : state === "failed" ? download.errorLabel ?? t("imageDownloadFailed") : t("imageDownload");
584
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
585
+ type: "button",
586
+ className: "dcsiv-download",
587
+ "data-compact": state === "idle",
588
+ title: label,
589
+ "aria-label": label,
590
+ onClick: () => {
591
+ invoke();
592
+ },
593
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconDownloadOutline16, {}), state === "idle" ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
594
+ className: "dcsiv-label",
595
+ children: state === "pending" ? `${label} ${progress}% · ${t("cancel")}` : label
596
+ })]
597
+ });
598
+ }
599
+ function SubscriptionImageViewerOverlay({ service, t }) {
600
+ const request = (0, react.useSyncExternalStore)(service.subscribe, service.getSnapshot);
601
+ const [cursor, setCursor] = (0, react.useState)({
602
+ revision: 0,
603
+ index: 0
604
+ });
605
+ const index = cursor.revision === request?.revision ? cursor.index : request?.index ?? 0;
606
+ const setIndex = (update) => setCursor((current) => ({
607
+ revision: request.revision,
608
+ index: typeof update === "function" ? update(current.revision === request.revision ? current.index : request.index) : update
609
+ }));
610
+ const [annotating, setAnnotating] = (0, react.useState)(false);
611
+ const [annotationsByImage, setAnnotationsByImage] = (0, react.useState)(service.getAnnotationsSnapshot);
612
+ const annotationsByImageRef = (0, react.useRef)(annotationsByImage);
613
+ const [selected, setSelected] = (0, react.useState)();
614
+ const [focusNote, setFocusNote] = (0, react.useState)();
615
+ const [copied, setCopied] = (0, react.useState)(false);
616
+ const [erasing, setErasing] = (0, react.useState)();
617
+ const [strokes, setStrokes] = (0, react.useState)([]);
618
+ const [brush, setBrush] = (0, react.useState)(.05);
619
+ const [sending, setSending] = (0, react.useState)(false);
620
+ const [sendFailed, setSendFailed] = (0, react.useState)(false);
621
+ const [brushCursor, setBrushCursor] = (0, react.useState)();
622
+ const eraseRef = (0, react.useRef)({
623
+ erasing: void 0,
624
+ sending: false
625
+ });
626
+ eraseRef.current = {
627
+ erasing,
628
+ sending
629
+ };
630
+ const drawingRef = (0, react.useRef)(false);
631
+ const maskRef = (0, react.useRef)(null);
632
+ const rootRef = (0, react.useRef)(null);
633
+ annotationsByImageRef.current = annotationsByImage;
634
+ (0, react.useEffect)(() => {
635
+ if (request === void 0) return;
636
+ setAnnotating(false);
637
+ setSelected(void 0);
638
+ setCopied(false);
639
+ }, [request?.revision]);
640
+ const item = request?.items[index];
641
+ const { transform, transformRef, dragging, pixelScale, geometry, stageRef, surfaceRef, imageRef, fit, actual, measure, setZoomAt, resetGesture, pointerHandlers } = useImageTransform(`${request?.revision}:${item?.id}:${item?.src}`);
642
+ const annotations = item === void 0 ? [] : annotationsByImage[item.id] ?? [];
643
+ const setAnnotations = (0, react.useCallback)((update) => {
644
+ if (item === void 0) return;
645
+ const previous = annotationsByImageRef.current[item.id] ?? [];
646
+ const next = typeof update === "function" ? update(previous) : update;
647
+ const snapshot = {
648
+ ...annotationsByImageRef.current,
649
+ [item.id]: next
650
+ };
651
+ annotationsByImageRef.current = snapshot;
652
+ service.setAnnotations(item.id, next);
653
+ setAnnotationsByImage(snapshot);
654
+ }, [item?.id, service]);
655
+ (0, react.useEffect)(() => {
656
+ if (request === void 0) return void 0;
657
+ const previousOverflow = document.body.style.overflow;
658
+ document.body.style.overflow = "hidden";
659
+ rootRef.current?.focus();
660
+ const onKeyDown = (event) => {
661
+ if (eraseRef.current.erasing !== void 0) {
662
+ const key = event.key.toLowerCase();
663
+ if (event.key === "Escape") {
664
+ event.preventDefault();
665
+ if (!eraseRef.current.sending) {
666
+ setErasing(void 0);
667
+ setStrokes([]);
668
+ }
669
+ return;
670
+ }
671
+ if ((event.ctrlKey || event.metaKey) && key === "z") {
672
+ event.preventDefault();
673
+ if (!eraseRef.current.sending) setStrokes((current) => current.slice(0, -1));
674
+ return;
675
+ }
676
+ if (event.key === "[" || event.key === "]") {
677
+ event.preventDefault();
678
+ setBrush((value) => Math.round(clamp(value + (event.key === "]" ? .01 : -.01), .01, .15) * 100) / 100);
679
+ return;
680
+ }
681
+ if (event.key === "ArrowLeft" || event.key === "ArrowRight") return;
682
+ }
683
+ if (event.key === "Escape") {
684
+ event.preventDefault();
685
+ if (event.target instanceof Element && event.target.closest(".dcsiv-inline-note") !== null) {
686
+ setSelected(void 0);
687
+ return;
688
+ }
689
+ service.close();
690
+ return;
691
+ }
692
+ const editing = event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement;
693
+ if (!editing && event.key === "ArrowLeft" && request.items.length > 1) {
694
+ event.preventDefault();
695
+ setIndex((value) => (value - 1 + request.items.length) % request.items.length);
696
+ } else if (!editing && event.key === "ArrowRight" && request.items.length > 1) {
697
+ event.preventDefault();
698
+ setIndex((value) => (value + 1) % request.items.length);
699
+ } else if (!editing && (event.key === "+" || event.key === "=")) {
700
+ event.preventDefault();
701
+ const box = stageRef.current?.getBoundingClientRect();
702
+ if (box) setZoomAt(transformRef.current.zoom * 1.2, box.left + box.width / 2, box.top + box.height / 2);
703
+ } else if (!editing && event.key === "-") {
704
+ event.preventDefault();
705
+ const box = stageRef.current?.getBoundingClientRect();
706
+ if (box) setZoomAt(transformRef.current.zoom / 1.2, box.left + box.width / 2, box.top + box.height / 2);
707
+ } else if (!editing && event.key.toLowerCase() === "f") {
708
+ event.preventDefault();
709
+ fit();
710
+ } else if (event.key === "Tab") {
711
+ const controls = [...rootRef.current.querySelectorAll("button:not(:disabled),a[href],input:not(:disabled),textarea:not(:disabled),[tabindex]:not([tabindex=\"-1\"])")];
712
+ const first = controls[0];
713
+ const last = controls.at(-1);
714
+ if (event.shiftKey && document.activeElement === first) {
715
+ event.preventDefault();
716
+ last?.focus();
717
+ } else if (!event.shiftKey && document.activeElement === last) {
718
+ event.preventDefault();
719
+ first?.focus();
720
+ }
721
+ }
722
+ };
723
+ document.addEventListener("keydown", onKeyDown);
724
+ return () => {
725
+ document.body.style.overflow = previousOverflow;
726
+ document.removeEventListener("keydown", onKeyDown);
727
+ };
728
+ }, [
729
+ request,
730
+ service,
731
+ fit,
732
+ setZoomAt
733
+ ]);
734
+ (0, react.useEffect)(() => {
735
+ if (focusNote === void 0) return;
736
+ (rootRef.current?.querySelector(`[data-note-id="${CSS.escape(focusNote)}"] textarea`))?.focus();
737
+ setFocusNote(void 0);
738
+ }, [
739
+ focusNote,
740
+ selected,
741
+ annotations.length
742
+ ]);
743
+ (0, react.useEffect)(() => {
744
+ setAnnotating(false);
745
+ setSelected(void 0);
746
+ setErasing(void 0);
747
+ setStrokes([]);
748
+ }, [
749
+ item?.id,
750
+ item?.src,
751
+ request?.revision
752
+ ]);
753
+ (0, react.useEffect)(() => {
754
+ const canvas = maskRef.current;
755
+ if (!erasing || canvas === null) return;
756
+ const context = canvas.getContext("2d");
757
+ context.clearRect(0, 0, canvas.width, canvas.height);
758
+ paintEraseStrokes(context, strokes, canvas.width, canvas.height, "rgba(255,59,48,.5)");
759
+ }, [erasing, strokes]);
760
+ const strokePoint = (event) => {
761
+ const bounds = maskRef.current?.getBoundingClientRect();
762
+ if (bounds === void 0) return void 0;
763
+ return {
764
+ x: clamp((event.clientX - bounds.left) / bounds.width, 0, 1),
765
+ y: clamp((event.clientY - bounds.top) / bounds.height, 0, 1)
766
+ };
767
+ };
768
+ const maskHandlers = {
769
+ onPointerDown: (event) => {
770
+ const point = strokePoint(event);
771
+ if (point === void 0) return;
772
+ event.stopPropagation();
773
+ event.currentTarget.setPointerCapture?.(event.pointerId);
774
+ drawingRef.current = true;
775
+ setStrokes((current) => [...current, {
776
+ size: brush / transformRef.current.zoom,
777
+ points: [point]
778
+ }]);
779
+ },
780
+ onPointerMove: (event) => {
781
+ const bounds = maskRef.current?.getBoundingClientRect();
782
+ if (bounds !== void 0) setBrushCursor({
783
+ left: event.clientX,
784
+ top: event.clientY,
785
+ span: Math.min(bounds.width, bounds.height) / transformRef.current.zoom
786
+ });
787
+ if (!drawingRef.current) return;
788
+ const point = strokePoint(event);
789
+ if (point === void 0) return;
790
+ setStrokes((current) => current.length === 0 ? current : [...current.slice(0, -1), {
791
+ ...current.at(-1),
792
+ points: [...current.at(-1).points, point]
793
+ }]);
794
+ },
795
+ onPointerUp: () => {
796
+ drawingRef.current = false;
797
+ },
798
+ onPointerCancel: () => {
799
+ drawingRef.current = false;
800
+ },
801
+ onPointerLeave: () => {
802
+ setBrushCursor(void 0);
803
+ }
804
+ };
805
+ const startMask = (action) => {
806
+ resetGesture();
807
+ setAnnotating(false);
808
+ setStrokes([]);
809
+ setSendFailed(false);
810
+ setBrushCursor(void 0);
811
+ setErasing(action);
812
+ };
813
+ const sendMask = async () => {
814
+ const image = imageRef.current;
815
+ if (!erasing || strokes.length === 0 || image === null || sending) return;
816
+ setSending(true);
817
+ setSendFailed(false);
818
+ try {
819
+ const canvas = document.createElement("canvas");
820
+ canvas.width = image.naturalWidth;
821
+ canvas.height = image.naturalHeight;
822
+ paintEraseMask(canvas.getContext("2d"), strokes, canvas.width, canvas.height);
823
+ const mask = await new Promise((resolve, reject) => canvas.toBlob((blob) => blob ? resolve(blob) : reject(/* @__PURE__ */ new Error("Mask")), "image/png"));
824
+ await erasing.onInvoke({
825
+ mask,
826
+ item,
827
+ src: item.src,
828
+ annotations: []
829
+ });
830
+ setErasing(void 0);
831
+ setStrokes([]);
832
+ if (erasing.closeOnSuccess) service.close();
833
+ } catch {
834
+ setSendFailed(true);
835
+ } finally {
836
+ setSending(false);
837
+ }
838
+ };
839
+ const addAnnotation = (event) => {
840
+ if (!annotating || event.target.closest(".dcsiv-annotation")) return;
841
+ const bounds = surfaceRef.current?.getBoundingClientRect();
842
+ if (bounds === void 0) return;
843
+ const annotation = {
844
+ id: crypto.randomUUID(),
845
+ x: clamp((event.clientX - bounds.left) / bounds.width, 0, 1),
846
+ y: clamp((event.clientY - bounds.top) / bounds.height, 0, 1),
847
+ note: ""
848
+ };
849
+ setAnnotations((current) => [...current, annotation]);
850
+ setAnnotating(false);
851
+ setSelected(annotation.id);
852
+ setFocusNote(annotation.id);
853
+ };
854
+ const copyNotes = async () => {
855
+ const text = noteText(annotations, t);
856
+ if (text === "" || typeof navigator?.clipboard?.writeText !== "function") return;
857
+ try {
858
+ await navigator.clipboard.writeText(text);
859
+ setCopied(true);
860
+ window.setTimeout(() => {
861
+ setCopied(false);
862
+ }, 1200);
863
+ } catch {
864
+ setCopied(false);
865
+ }
866
+ };
867
+ if (request === void 0 || item === void 0) return null;
868
+ const meta = [item.width && item.height ? `${item.width} × ${item.height}` : void 0, bytesLabel(item.bytes)].filter(Boolean).join(" · ");
869
+ const showCounter = request.items.length > 1;
870
+ const annotationPosition = (annotation) => {
871
+ const ratio = globalThis.devicePixelRatio || 1;
872
+ const align = (value) => Math.round(value * ratio) / ratio;
873
+ return {
874
+ left: align(geometry.stageWidth / 2 + transform.x + (annotation.x - .5) * geometry.width * transform.zoom - 12),
875
+ top: align(geometry.stageHeight / 2 + transform.y + (annotation.y - .5) * geometry.height * transform.zoom - 12),
876
+ visibility: geometry.width > 0 ? "visible" : "hidden"
877
+ };
878
+ };
879
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
880
+ ref: rootRef,
881
+ className: "dcsiv-root",
882
+ role: "dialog",
883
+ "aria-modal": "true",
884
+ "aria-label": t("imagePreview"),
885
+ tabIndex: -1,
886
+ children: [
887
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
888
+ className: "dcsiv-title dcsiv-sr-only",
889
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: item.name }), meta !== "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: meta }) : null]
890
+ }),
891
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", {
892
+ className: "dcsiv-topbar",
893
+ role: "toolbar",
894
+ "aria-label": t("imagePreview"),
895
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
896
+ className: "dcsiv-actions",
897
+ children: [
898
+ request.annotations ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
899
+ type: "button",
900
+ className: annotating ? "dcsiv-button" : "dcsiv-button dcsiv-icon-button",
901
+ "data-active": annotating,
902
+ title: annotating ? t("imageAnnotateCancel") : t("imageAnnotate"),
903
+ "aria-label": annotating ? t("imageAnnotateCancel") : t("imageAnnotate"),
904
+ "aria-pressed": annotating,
905
+ onClick: () => {
906
+ resetGesture();
907
+ setAnnotating((value) => !value);
908
+ },
909
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolIcon, { id: "annotate" }), annotating ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
910
+ className: "dcsiv-label",
911
+ children: t("imageAnnotateCancel")
912
+ }) : null]
913
+ }) : null,
914
+ annotations.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
915
+ type: "button",
916
+ className: "dcsiv-button",
917
+ "data-active": selected !== void 0,
918
+ onClick: () => {
919
+ const first = annotations[0];
920
+ setSelected((current) => current === void 0 ? first.id : void 0);
921
+ if (selected === void 0) setFocusNote(first.id);
922
+ },
923
+ children: [
924
+ annotations.length,
925
+ " ",
926
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
927
+ className: "dcsiv-label",
928
+ children: t("imageRegions")
929
+ })
930
+ ]
931
+ }) : null,
932
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
933
+ type: "button",
934
+ className: "dcsiv-button dcsiv-zoom",
935
+ title: transform.zoom === 1 ? t("imageActual") : t("imageFit"),
936
+ "aria-label": transform.zoom === 1 ? t("imageActual") : t("imageFit"),
937
+ onClick: () => {
938
+ if (transform.zoom === 1) actual();
939
+ else fit();
940
+ },
941
+ children: [Math.round(transform.zoom * pixelScale * 100), "%"]
942
+ }),
943
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
944
+ className: "dcsiv-divider",
945
+ "aria-hidden": "true"
946
+ }),
947
+ item.download === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
948
+ className: "dcsiv-download",
949
+ "data-compact": "true",
950
+ href: item.src,
951
+ download: downloadName(item.name),
952
+ title: t("imageDownload"),
953
+ "aria-label": t("imageDownload"),
954
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconDownloadOutline16, {})
955
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewerDownload, {
956
+ download: item.download,
957
+ item,
958
+ t
959
+ }, item.id),
960
+ item.actions.map((action) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewerAction, {
961
+ action,
962
+ annotations,
963
+ item,
964
+ service,
965
+ revision: request.revision,
966
+ t,
967
+ onStartMask: startMask
968
+ }, `${request.revision}:${index}:${action.id}`))
969
+ ]
970
+ })
971
+ }),
972
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
973
+ type: "button",
974
+ className: "dcsiv-close-floating",
975
+ "aria-label": t("imageClosePreview"),
976
+ onClick: () => service.close(),
977
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconCloseOutline16, {})
978
+ }),
979
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
980
+ className: "dcsiv-workspace",
981
+ children: [
982
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("main", {
983
+ ref: stageRef,
984
+ className: "dcsiv-stage",
985
+ "data-dragging": dragging,
986
+ "data-annotating": annotating || erasing !== void 0,
987
+ onClick: (event) => {
988
+ if (event.target === event.currentTarget && !annotating && !erasing && transform.zoom === 1) service.close();
989
+ },
990
+ ...!annotating && !erasing ? pointerHandlers : {},
991
+ onDoubleClick: () => {
992
+ if (transform.zoom === 1) actual();
993
+ else fit();
994
+ },
995
+ children: [
996
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
997
+ ref: surfaceRef,
998
+ className: "dcsiv-surface",
999
+ onClick: addAnnotation,
1000
+ style: { transform: `translate3d(${transform.x}px,${transform.y}px,0) scale(${transform.zoom})` },
1001
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
1002
+ ref: imageRef,
1003
+ className: "dcsiv-image",
1004
+ src: item.src,
1005
+ alt: item.name,
1006
+ draggable: "false",
1007
+ onLoad: () => {
1008
+ measure();
1009
+ }
1010
+ }, `${request.revision}:${item.id}`), erasing ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("canvas", {
1011
+ ref: maskRef,
1012
+ className: "dcsiv-mask",
1013
+ width: imageRef.current?.naturalWidth || 1,
1014
+ height: imageRef.current?.naturalHeight || 1,
1015
+ "aria-label": t("imageEraseHint"),
1016
+ ...maskHandlers
1017
+ }) : null]
1018
+ }),
1019
+ annotations.map((annotation, position) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1020
+ className: "dcsiv-annotation",
1021
+ "data-x": annotation.x < .38 ? "right" : annotation.x > .62 ? "left" : "center",
1022
+ "data-y": annotation.y < .28 ? "down" : "up",
1023
+ style: annotationPosition(annotation),
1024
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1025
+ type: "button",
1026
+ className: "dcsiv-pin",
1027
+ "data-active": selected === annotation.id,
1028
+ "aria-label": fill(t("imageAnnotation"), { value: position + 1 }),
1029
+ onClick: (event) => {
1030
+ event.stopPropagation();
1031
+ const opening = selected !== annotation.id;
1032
+ setSelected(opening ? annotation.id : void 0);
1033
+ if (opening) setFocusNote(annotation.id);
1034
+ },
1035
+ children: position + 1
1036
+ }), selected === annotation.id ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1037
+ className: "dcsiv-inline-note",
1038
+ "data-note-id": annotation.id,
1039
+ onClick: (event) => event.stopPropagation(),
1040
+ children: [
1041
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1042
+ className: "dcsiv-inline-index",
1043
+ children: position + 1
1044
+ }),
1045
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
1046
+ value: annotation.note,
1047
+ rows: 1,
1048
+ "aria-label": fill(t("imageAnnotation"), { value: position + 1 }),
1049
+ placeholder: t("imageAnnotationPlaceholder"),
1050
+ onChange: (event) => {
1051
+ const note = event.target.value;
1052
+ setAnnotations((current) => current.map((entry) => entry.id === annotation.id ? {
1053
+ ...entry,
1054
+ note
1055
+ } : entry));
1056
+ },
1057
+ onKeyDown: (event) => {
1058
+ if (event.key === "Enter" && !event.shiftKey || event.key === "Escape") {
1059
+ event.preventDefault();
1060
+ event.stopPropagation();
1061
+ event.nativeEvent?.stopImmediatePropagation?.();
1062
+ setSelected(void 0);
1063
+ }
1064
+ }
1065
+ }),
1066
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1067
+ type: "button",
1068
+ className: "dcsiv-note-remove",
1069
+ "aria-label": t("imageRemoveAnnotation"),
1070
+ onClick: (event) => {
1071
+ event.stopPropagation();
1072
+ setAnnotations((current) => current.filter((entry) => entry.id !== annotation.id));
1073
+ setSelected(void 0);
1074
+ },
1075
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconCloseOutline16, {})
1076
+ })
1077
+ ]
1078
+ }) : null]
1079
+ }, annotation.id)),
1080
+ showCounter ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1081
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1082
+ type: "button",
1083
+ className: "dcsiv-button dcsiv-icon-only dcsiv-nav dcsiv-prev",
1084
+ "aria-label": t("imagePrevious"),
1085
+ onClick: (event) => {
1086
+ event.stopPropagation();
1087
+ setIndex((value) => (value - 1 + request.items.length) % request.items.length);
1088
+ },
1089
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconChevronLeftOutline14, {})
1090
+ }),
1091
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1092
+ type: "button",
1093
+ className: "dcsiv-button dcsiv-icon-only dcsiv-nav dcsiv-next",
1094
+ "aria-label": t("imageNext"),
1095
+ onClick: (event) => {
1096
+ event.stopPropagation();
1097
+ setIndex((value) => (value + 1) % request.items.length);
1098
+ },
1099
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconChevronRightOutline14, {})
1100
+ }),
1101
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1102
+ className: "dcsiv-counter",
1103
+ children: [
1104
+ index + 1,
1105
+ " / ",
1106
+ request.items.length
1107
+ ]
1108
+ })
1109
+ ] }) : annotating ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1110
+ className: "dcsiv-hint",
1111
+ children: t("imageAnnotateHint")
1112
+ }) : transform.zoom === 1 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1113
+ className: "dcsiv-hint",
1114
+ children: t("imageZoomHint")
1115
+ }) : null
1116
+ ]
1117
+ }),
1118
+ erasing ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1119
+ className: "dcsiv-erase-bar",
1120
+ role: "toolbar",
1121
+ "aria-label": t("imageErase"),
1122
+ children: [
1123
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("imageEraseHint") }),
1124
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [t("imageBrushSize"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1125
+ type: "range",
1126
+ min: "0.01",
1127
+ max: "0.15",
1128
+ step: "0.01",
1129
+ value: brush,
1130
+ onChange: (event) => setBrush(Number(event.target.value))
1131
+ })] }),
1132
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1133
+ type: "button",
1134
+ className: "dcsiv-button",
1135
+ disabled: strokes.length === 0 || sending,
1136
+ onClick: () => setStrokes((current) => current.slice(0, -1)),
1137
+ children: t("imageUndo")
1138
+ }),
1139
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1140
+ type: "button",
1141
+ className: "dcsiv-button",
1142
+ disabled: sending,
1143
+ onClick: () => {
1144
+ setErasing(void 0);
1145
+ setStrokes([]);
1146
+ },
1147
+ children: t("cancel")
1148
+ }),
1149
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1150
+ type: "button",
1151
+ className: "dcsiv-button dcsiv-primary",
1152
+ "data-state": sendFailed ? "failed" : void 0,
1153
+ disabled: strokes.length === 0 || sending,
1154
+ onClick: () => {
1155
+ sendMask();
1156
+ },
1157
+ children: sending ? t("imageEditPreparing") : sendFailed ? t("imageEditFailed") : t("imageSend")
1158
+ })
1159
+ ]
1160
+ }) : null,
1161
+ erasing && brushCursor ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1162
+ className: "dcsiv-brush-cursor",
1163
+ "aria-hidden": "true",
1164
+ style: {
1165
+ left: brushCursor.left,
1166
+ top: brushCursor.top,
1167
+ width: brush * brushCursor.span,
1168
+ height: brush * brushCursor.span
1169
+ }
1170
+ }) : null,
1171
+ annotations.some((annotation) => annotation.note.trim() !== "") ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1172
+ type: "button",
1173
+ className: "dcsiv-copy-notes",
1174
+ onClick: () => {
1175
+ copyNotes();
1176
+ },
1177
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconCopyOutline16, {}), copied ? t("imageCopied") : t("imageCopyNotes")]
1178
+ }) : null
1179
+ ]
1180
+ })
1181
+ ]
1182
+ });
1183
+ }
1184
+ //#endregion
1185
+ exports.SUBSCRIPTION_IMAGE_VIEWER_CSS = SUBSCRIPTION_IMAGE_VIEWER_CSS;
1186
+ exports.SubscriptionImageViewerOverlay = SubscriptionImageViewerOverlay;
1187
+ return module.exports;
1188
+ }
1189
+ });
1190
+
1191
+ //# sourceMappingURL=client.image-viewer.js.map