@ai-matrx/capture 0.0.0 → 0.1.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.
package/dist/react.js ADDED
@@ -0,0 +1,996 @@
1
+ "use client";
2
+
3
+ // src/components/CameraCapture.tsx
4
+ import { useCallback as useCallback2, useEffect as useEffect2, useRef, useState as useState2 } from "react";
5
+ import {
6
+ Grip,
7
+ Grid3x3,
8
+ Proportions,
9
+ SunMedium,
10
+ Timer,
11
+ X as X2,
12
+ Zap,
13
+ ZapOff,
14
+ RefreshCw
15
+ } from "lucide-react";
16
+
17
+ // src/cn.ts
18
+ import { twMerge } from "tailwind-merge";
19
+ function cn(...inputs) {
20
+ return twMerge(inputs.filter(Boolean).join(" "));
21
+ }
22
+
23
+ // src/hooks/useTrackControls.ts
24
+ import { useCallback, useEffect, useMemo, useState } from "react";
25
+ var ZOOM_LADDER = [0.5, 1, 2, 4, 8];
26
+ function useTrackControls(stream) {
27
+ const [torchOn, setTorchOn] = useState(false);
28
+ const [zoom, setZoomState] = useState(1);
29
+ const [exposure, setExposureState] = useState(0);
30
+ const [caps, setCaps] = useState(null);
31
+ const track = stream?.getVideoTracks()[0] ?? null;
32
+ useEffect(() => {
33
+ setTorchOn(false);
34
+ if (!track || typeof track.getCapabilities !== "function") {
35
+ setCaps(null);
36
+ return;
37
+ }
38
+ const read = () => {
39
+ try {
40
+ setCaps(track.getCapabilities());
41
+ const settings = track.getSettings();
42
+ if (typeof settings.zoom === "number") setZoomState(settings.zoom);
43
+ if (typeof settings.exposureCompensation === "number")
44
+ setExposureState(settings.exposureCompensation);
45
+ } catch {
46
+ setCaps(null);
47
+ }
48
+ };
49
+ read();
50
+ const timer = window.setTimeout(read, 750);
51
+ return () => window.clearTimeout(timer);
52
+ }, [track]);
53
+ const torchSupported = caps?.torch === true;
54
+ const toggleTorch = useCallback(() => {
55
+ if (!track || !torchSupported) return;
56
+ const next = !torchOn;
57
+ track.applyConstraints({ advanced: [{ torch: next }] }).then(() => setTorchOn(next)).catch((err) => {
58
+ console.error("[capture-camera] torch toggle failed", err);
59
+ });
60
+ }, [track, torchSupported, torchOn]);
61
+ const zoomOptions = useMemo(() => {
62
+ const range = caps?.zoom;
63
+ if (!range || !(range.max > range.min)) return [];
64
+ const options = ZOOM_LADDER.filter(
65
+ (f) => f >= range.min && f <= range.max
66
+ );
67
+ if (!options.includes(1) && 1 >= range.min && 1 <= range.max) {
68
+ options.push(1);
69
+ options.sort((a, b) => a - b);
70
+ }
71
+ return options.length >= 2 ? options : [];
72
+ }, [caps]);
73
+ const setZoom = useCallback(
74
+ (factor) => {
75
+ if (!track || !caps?.zoom) return;
76
+ const clamped = Math.min(caps.zoom.max, Math.max(caps.zoom.min, factor));
77
+ track.applyConstraints({
78
+ advanced: [{ zoom: clamped }]
79
+ }).then(() => setZoomState(clamped)).catch((err) => {
80
+ console.error("[capture-camera] zoom failed", err);
81
+ });
82
+ },
83
+ [track, caps]
84
+ );
85
+ const exposureCaps = caps?.exposureCompensation;
86
+ const exposureRange = exposureCaps && exposureCaps.max > exposureCaps.min ? {
87
+ min: exposureCaps.min,
88
+ max: exposureCaps.max,
89
+ step: exposureCaps.step && exposureCaps.step > 0 ? exposureCaps.step : 0.5
90
+ } : null;
91
+ const setExposure = useCallback(
92
+ (value) => {
93
+ if (!track || !exposureRange) return;
94
+ const clamped = Math.min(
95
+ exposureRange.max,
96
+ Math.max(exposureRange.min, value)
97
+ );
98
+ track.applyConstraints({
99
+ advanced: [
100
+ { exposureCompensation: clamped }
101
+ ]
102
+ }).then(() => setExposureState(clamped)).catch((err) => {
103
+ console.error("[capture-camera] exposure failed", err);
104
+ });
105
+ },
106
+ [track, exposureRange]
107
+ );
108
+ return {
109
+ torchSupported,
110
+ torchOn,
111
+ toggleTorch,
112
+ zoomOptions,
113
+ zoom,
114
+ setZoom,
115
+ exposureSupported: exposureRange !== null,
116
+ exposure,
117
+ exposureRange,
118
+ setExposure
119
+ };
120
+ }
121
+
122
+ // src/components/ShutterButton.tsx
123
+ import { jsx } from "react/jsx-runtime";
124
+ function ShutterButton({
125
+ mode,
126
+ recording,
127
+ disabled = false,
128
+ onPress
129
+ }) {
130
+ return /* @__PURE__ */ jsx(
131
+ "button",
132
+ {
133
+ type: "button",
134
+ onClick: onPress,
135
+ disabled,
136
+ "aria-label": mode === "photo" ? "Take photo" : recording ? "Stop recording" : "Start recording",
137
+ className: cn(
138
+ "group flex h-[74px] w-[74px] shrink-0 items-center justify-center rounded-full",
139
+ "border-[3.5px] border-white transition-opacity",
140
+ disabled && "opacity-30"
141
+ ),
142
+ children: /* @__PURE__ */ jsx(
143
+ "span",
144
+ {
145
+ className: cn(
146
+ "block transition-all duration-200 ease-out group-active:scale-90",
147
+ mode === "photo" ? "h-[62px] w-[62px] rounded-full bg-white" : recording ? "h-8 w-8 rounded-md bg-[#FF3B30]" : "h-[62px] w-[62px] rounded-full bg-[#FF3B30]"
148
+ )
149
+ }
150
+ )
151
+ }
152
+ );
153
+ }
154
+
155
+ // src/components/ModeSelector.tsx
156
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
157
+ var SPRING_EASING = "linear(0, 0.0047 0.71%, 0.0189 1.44%, 0.0755 2.93%, 0.1692 4.49%, 0.3921 7.55%, 0.8121 12.94%, 0.9804 15.49%, 1.0946 18.14%, 1.1423 20.16%, 1.1568 21.62%, 1.1541 23.03%, 1.1113 26.4%, 1.0322 31.83%, 0.9902 36.25%, 0.9769 40.24%, 0.9844 45.87%, 1.0028 55.35%, 1.0075 63.42%, 1.0006 85.48%, 1)";
158
+ var LABEL_BASE = "relative z-10 flex h-8 min-w-0 touch-manipulation items-center justify-center rounded-full px-3 text-[11px] font-semibold uppercase tracking-[0.12em] transition-colors duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70 disabled:opacity-40";
159
+ function ModeSelector({
160
+ mode,
161
+ onModeChange,
162
+ onUpload,
163
+ modeDisabled = false,
164
+ uploadDisabled = false,
165
+ extraModes = []
166
+ }) {
167
+ const segments = 3 + extraModes.length;
168
+ const activeIndex = mode === "video" ? 0 : 1;
169
+ return /* @__PURE__ */ jsxs(
170
+ "div",
171
+ {
172
+ role: "tablist",
173
+ "aria-label": "Capture mode",
174
+ className: "relative inline-grid rounded-full bg-white/10 p-1",
175
+ style: { gridTemplateColumns: `repeat(${segments}, minmax(0, 1fr))` },
176
+ children: [
177
+ /* @__PURE__ */ jsx2(
178
+ "div",
179
+ {
180
+ "aria-hidden": true,
181
+ className: "pointer-events-none absolute bottom-1 top-1 left-1 rounded-full bg-white/20 transition-transform duration-500 ease-[cubic-bezier(0.34,1.56,0.64,1)] will-change-transform motion-reduce:transition-none",
182
+ style: {
183
+ width: `calc((100% - 0.5rem) / ${segments})`,
184
+ transform: `translateX(${activeIndex * 100}%)`,
185
+ transitionTimingFunction: SPRING_EASING
186
+ }
187
+ }
188
+ ),
189
+ /* @__PURE__ */ jsx2(
190
+ "button",
191
+ {
192
+ type: "button",
193
+ role: "tab",
194
+ "aria-selected": mode === "video",
195
+ disabled: modeDisabled,
196
+ onClick: () => onModeChange("video"),
197
+ className: cn(
198
+ LABEL_BASE,
199
+ mode === "video" ? "text-[#FFCC00]" : "text-white"
200
+ ),
201
+ children: "Video"
202
+ }
203
+ ),
204
+ /* @__PURE__ */ jsx2(
205
+ "button",
206
+ {
207
+ type: "button",
208
+ role: "tab",
209
+ "aria-selected": mode === "photo",
210
+ disabled: modeDisabled,
211
+ onClick: () => onModeChange("photo"),
212
+ className: cn(
213
+ LABEL_BASE,
214
+ mode === "photo" ? "text-[#FFCC00]" : "text-white"
215
+ ),
216
+ children: "Photo"
217
+ }
218
+ ),
219
+ /* @__PURE__ */ jsx2(
220
+ "button",
221
+ {
222
+ type: "button",
223
+ "aria-label": "Upload photos or videos from this device",
224
+ disabled: modeDisabled || uploadDisabled,
225
+ onClick: onUpload,
226
+ className: cn(LABEL_BASE, "text-white active:text-[#FFCC00]"),
227
+ children: "Upload"
228
+ }
229
+ ),
230
+ extraModes.map((extra) => /* @__PURE__ */ jsx2(
231
+ "button",
232
+ {
233
+ type: "button",
234
+ "aria-label": extra.label,
235
+ disabled: modeDisabled,
236
+ onClick: extra.onSelect,
237
+ className: cn(LABEL_BASE, "text-white active:text-[#FFCC00]"),
238
+ children: extra.label
239
+ },
240
+ extra.id
241
+ ))
242
+ ]
243
+ }
244
+ );
245
+ }
246
+
247
+ // src/components/ZoomRow.tsx
248
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
249
+ function formatFactor(factor) {
250
+ return factor < 1 ? `.${String(Math.round(factor * 10))}` : String(Math.round(factor * 10) / 10);
251
+ }
252
+ function ZoomRow({ options, value, onSelect }) {
253
+ if (options.length < 2) return null;
254
+ const active = options.reduce(
255
+ (best, opt) => Math.abs(opt - value) < Math.abs(best - value) ? opt : best
256
+ );
257
+ return /* @__PURE__ */ jsx3("div", { className: "flex items-center justify-center gap-3", children: options.map((opt) => {
258
+ const isActive = opt === active;
259
+ return /* @__PURE__ */ jsxs2(
260
+ "button",
261
+ {
262
+ type: "button",
263
+ onClick: () => onSelect(opt),
264
+ "aria-label": `Zoom ${formatFactor(opt)}x`,
265
+ "aria-pressed": isActive,
266
+ className: cn(
267
+ "flex touch-manipulation items-center justify-center rounded-full font-semibold transition-all duration-200",
268
+ isActive ? "h-10 w-10 bg-black/45 text-[13px] text-[#FFCC00]" : "h-8 w-8 bg-black/35 text-[12px] text-white"
269
+ ),
270
+ children: [
271
+ formatFactor(opt),
272
+ isActive && /* @__PURE__ */ jsx3("span", { className: "text-[10px]", children: "\xD7" })
273
+ ]
274
+ },
275
+ opt
276
+ );
277
+ }) });
278
+ }
279
+
280
+ // src/components/OptionsGridPanel.tsx
281
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
282
+ function OptionsGridPanel({
283
+ open,
284
+ onClose,
285
+ tiles
286
+ }) {
287
+ if (!open) return null;
288
+ return /* @__PURE__ */ jsxs3("div", { className: "absolute inset-0 z-40", children: [
289
+ /* @__PURE__ */ jsx4(
290
+ "button",
291
+ {
292
+ type: "button",
293
+ "aria-label": "Close camera options",
294
+ onClick: onClose,
295
+ className: "absolute inset-0 bg-black/70"
296
+ }
297
+ ),
298
+ /* @__PURE__ */ jsx4("div", { className: "absolute inset-x-3 bottom-3 mb-safe rounded-[2.5rem] bg-[#3a3a3c]/95 px-6 py-8 shadow-2xl", children: /* @__PURE__ */ jsx4("div", { className: "grid grid-cols-3 gap-x-4 gap-y-7", children: tiles.map((tile) => /* @__PURE__ */ jsxs3("div", { className: "flex flex-col items-center gap-2.5", children: [
299
+ /* @__PURE__ */ jsx4(
300
+ "button",
301
+ {
302
+ type: "button",
303
+ onClick: tile.onPress,
304
+ disabled: tile.disabled,
305
+ "aria-label": tile.label,
306
+ "aria-pressed": tile.active === true,
307
+ className: cn(
308
+ "flex h-16 w-16 touch-manipulation items-center justify-center rounded-full bg-[#2c2c2e] transition-colors",
309
+ tile.active ? "text-[#FFCC00]" : "text-white",
310
+ tile.disabled && "opacity-40"
311
+ ),
312
+ children: tile.icon
313
+ }
314
+ ),
315
+ /* @__PURE__ */ jsx4("span", { className: "text-[13px] font-semibold uppercase tracking-[0.14em] text-white", children: tile.valueLabel ? `${tile.label} ${tile.valueLabel}` : tile.label })
316
+ ] }, tile.id)) }) })
317
+ ] });
318
+ }
319
+
320
+ // src/components/CaptureSheet.tsx
321
+ import { Loader2, X } from "lucide-react";
322
+ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
323
+ function CaptureSheet({
324
+ open,
325
+ onClose,
326
+ variant = "content",
327
+ icon,
328
+ title,
329
+ body,
330
+ actions = [],
331
+ busyLabel = "Working\u2026"
332
+ }) {
333
+ if (!open) return null;
334
+ return /* @__PURE__ */ jsxs4("div", { className: "absolute inset-0 z-50 flex flex-col justify-end", children: [
335
+ /* @__PURE__ */ jsx5(
336
+ "button",
337
+ {
338
+ type: "button",
339
+ "aria-label": "Dismiss",
340
+ onClick: onClose,
341
+ className: "absolute inset-0 bg-black/30"
342
+ }
343
+ ),
344
+ /* @__PURE__ */ jsxs4("div", { className: "relative mx-2 mb-2 mb-safe rounded-[2rem] bg-[#f2f2f7] px-6 pb-6 pt-5 text-black shadow-2xl", children: [
345
+ /* @__PURE__ */ jsx5(
346
+ "button",
347
+ {
348
+ type: "button",
349
+ onClick: onClose,
350
+ "aria-label": "Close",
351
+ className: "absolute right-4 top-4 flex h-9 w-9 items-center justify-center rounded-full bg-black/5 text-black/70 transition-colors hover:bg-black/10",
352
+ children: /* @__PURE__ */ jsx5(X, { className: "h-5 w-5", strokeWidth: 2.5 })
353
+ }
354
+ ),
355
+ variant === "busy" ? /* @__PURE__ */ jsxs4("div", { className: "flex min-h-[220px] items-center justify-center gap-2.5", children: [
356
+ /* @__PURE__ */ jsx5(Loader2, { className: "h-5 w-5 animate-spin text-black/50" }),
357
+ /* @__PURE__ */ jsx5("span", { className: "text-[17px] font-medium text-black/80", children: busyLabel })
358
+ ] }) : /* @__PURE__ */ jsxs4("div", { className: "pt-4", children: [
359
+ icon && /* @__PURE__ */ jsx5("div", { className: "mb-5 text-[#0a84ff]", children: icon }),
360
+ title && /* @__PURE__ */ jsx5("h2", { className: "mb-2 text-[26px] font-bold leading-tight", children: title }),
361
+ body && /* @__PURE__ */ jsx5("div", { className: "text-[17px] leading-snug text-black/85", children: body }),
362
+ actions.length > 0 && /* @__PURE__ */ jsx5("div", { className: "mt-7 flex flex-col gap-3", children: actions.map((action) => /* @__PURE__ */ jsx5(
363
+ "button",
364
+ {
365
+ type: "button",
366
+ onClick: action.onPress,
367
+ className: cn(
368
+ "h-[50px] w-full touch-manipulation rounded-full text-[17px] font-semibold transition-transform active:scale-[0.98]",
369
+ (action.kind ?? "primary") === "primary" ? "bg-[#0a84ff] text-white" : "bg-black/[0.06] text-[#0a84ff]"
370
+ ),
371
+ children: action.label
372
+ },
373
+ action.label
374
+ )) })
375
+ ] })
376
+ ] })
377
+ ] });
378
+ }
379
+
380
+ // src/components/GridOverlay.tsx
381
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
382
+ function GridOverlay({ visible }) {
383
+ if (!visible) return null;
384
+ return /* @__PURE__ */ jsxs5("div", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 z-10", children: [
385
+ /* @__PURE__ */ jsx6("div", { className: "absolute inset-y-0 left-1/3 w-px bg-white/40" }),
386
+ /* @__PURE__ */ jsx6("div", { className: "absolute inset-y-0 left-2/3 w-px bg-white/40" }),
387
+ /* @__PURE__ */ jsx6("div", { className: "absolute inset-x-0 top-1/3 h-px bg-white/40" }),
388
+ /* @__PURE__ */ jsx6("div", { className: "absolute inset-x-0 top-2/3 h-px bg-white/40" })
389
+ ] });
390
+ }
391
+
392
+ // src/components/CountdownOverlay.tsx
393
+ import { jsx as jsx7 } from "react/jsx-runtime";
394
+ function CountdownOverlay({ seconds }) {
395
+ if (seconds === null || seconds <= 0) return null;
396
+ return /* @__PURE__ */ jsx7("div", { className: "pointer-events-none absolute inset-0 z-30 flex items-center justify-center", children: /* @__PURE__ */ jsx7(
397
+ "span",
398
+ {
399
+ className: "text-[120px] font-light text-white drop-shadow-lg [@starting-style]:scale-125 [@starting-style]:opacity-0 transition-all duration-300",
400
+ children: seconds
401
+ },
402
+ seconds
403
+ ) });
404
+ }
405
+
406
+ // src/components/CameraCapture.tsx
407
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
408
+ function formatElapsed(totalSeconds) {
409
+ const m = Math.floor(totalSeconds / 60);
410
+ const s = String(totalSeconds % 60).padStart(2, "0");
411
+ return `${m}:${s}`;
412
+ }
413
+ var ASPECT_CYCLE = ["full", "4:3", "1:1", "16:9"];
414
+ function CameraCapture({
415
+ engine,
416
+ cloud,
417
+ mode,
418
+ onModeChange,
419
+ preview,
420
+ onClose,
421
+ blockedSheet,
422
+ controlsHidden = false,
423
+ shutterDisabled = false,
424
+ slots = {}
425
+ }) {
426
+ const [optionsOpen, setOptionsOpen] = useState2(false);
427
+ const [gridOn, setGridOn] = useState2(false);
428
+ const [timerSetting, setTimerSetting] = useState2(0);
429
+ const [aspect, setAspect] = useState2("full");
430
+ const [exposureOpen, setExposureOpen] = useState2(false);
431
+ const [countdown, setCountdown] = useState2(null);
432
+ const [blockedDismissed, setBlockedDismissed] = useState2(false);
433
+ const countdownRef = useRef(null);
434
+ const controls = useTrackControls(engine.stream);
435
+ const clearCountdown = useCallback2(() => {
436
+ if (countdownRef.current) clearInterval(countdownRef.current);
437
+ countdownRef.current = null;
438
+ setCountdown(null);
439
+ }, []);
440
+ useEffect2(() => clearCountdown, [clearCountdown]);
441
+ const onShutter = useCallback2(() => {
442
+ if (mode === "video") {
443
+ if (engine.recording) engine.onStopRecording();
444
+ else engine.onStartRecording();
445
+ return;
446
+ }
447
+ if (countdown !== null) {
448
+ clearCountdown();
449
+ return;
450
+ }
451
+ if (timerSetting === 0) {
452
+ engine.onCapturePhoto({ aspect });
453
+ return;
454
+ }
455
+ let remaining = timerSetting;
456
+ setCountdown(remaining);
457
+ countdownRef.current = setInterval(() => {
458
+ remaining -= 1;
459
+ if (remaining <= 0) {
460
+ clearCountdown();
461
+ engine.onCapturePhoto({ aspect });
462
+ } else {
463
+ setCountdown(remaining);
464
+ }
465
+ }, 1e3);
466
+ }, [mode, engine, countdown, timerSetting, aspect, clearCountdown]);
467
+ const cycleTimer = useCallback2(() => {
468
+ setTimerSetting((t) => t === 0 ? 3 : t === 3 ? 10 : 0);
469
+ }, []);
470
+ const coreTiles = [
471
+ ...controls.torchSupported ? [
472
+ {
473
+ id: "flash",
474
+ label: "Flash",
475
+ icon: controls.torchOn ? /* @__PURE__ */ jsx8(Zap, { className: "h-6 w-6", fill: "currentColor" }) : /* @__PURE__ */ jsx8(ZapOff, { className: "h-6 w-6" }),
476
+ active: controls.torchOn,
477
+ onPress: controls.toggleTorch
478
+ }
479
+ ] : [],
480
+ {
481
+ id: "timer",
482
+ label: "Timer",
483
+ icon: /* @__PURE__ */ jsx8(Timer, { className: "h-6 w-6" }),
484
+ active: timerSetting !== 0,
485
+ valueLabel: timerSetting === 0 ? void 0 : `${timerSetting}s`,
486
+ onPress: cycleTimer
487
+ },
488
+ {
489
+ id: "grid",
490
+ label: "Grid",
491
+ icon: /* @__PURE__ */ jsx8(Grid3x3, { className: "h-6 w-6" }),
492
+ active: gridOn,
493
+ onPress: () => setGridOn((g) => !g)
494
+ },
495
+ // Aspect applies to PHOTO output (center-cropped from the full sensor).
496
+ {
497
+ id: "aspect",
498
+ label: "Aspect",
499
+ icon: /* @__PURE__ */ jsx8(Proportions, { className: "h-6 w-6" }),
500
+ active: aspect !== "full",
501
+ valueLabel: aspect === "full" ? void 0 : aspect,
502
+ onPress: () => setAspect(
503
+ (a) => ASPECT_CYCLE[(ASPECT_CYCLE.indexOf(a) + 1) % ASPECT_CYCLE.length] ?? "full"
504
+ )
505
+ },
506
+ ...controls.exposureSupported ? [
507
+ {
508
+ id: "exposure",
509
+ label: "Exposure",
510
+ icon: /* @__PURE__ */ jsx8(SunMedium, { className: "h-6 w-6" }),
511
+ active: controls.exposure !== 0 || exposureOpen,
512
+ valueLabel: controls.exposure === 0 ? void 0 : `${controls.exposure > 0 ? "+" : ""}${controls.exposure}`,
513
+ onPress: () => setExposureOpen((o) => !o)
514
+ }
515
+ ] : []
516
+ ];
517
+ const tiles = [...coreTiles, ...slots.optionTiles ?? []];
518
+ const blocked = engine.blocked !== null;
519
+ return /* @__PURE__ */ jsxs6("div", { className: "absolute inset-0 select-none overflow-hidden bg-black", children: [
520
+ /* @__PURE__ */ jsx8("div", { className: "absolute inset-0", children: preview }),
521
+ /* @__PURE__ */ jsx8(GridOverlay, { visible: gridOn && !blocked }),
522
+ mode === "photo" && aspect !== "full" && !blocked && /* @__PURE__ */ jsx8(
523
+ "div",
524
+ {
525
+ "aria-hidden": true,
526
+ className: "pointer-events-none absolute inset-0 z-10 flex items-center justify-center",
527
+ children: /* @__PURE__ */ jsx8(
528
+ "div",
529
+ {
530
+ className: "shadow-[0_0_0_9999px_rgba(0,0,0,0.45)]",
531
+ style: {
532
+ aspectRatio: aspect === "1:1" ? "1 / 1" : aspect === "4:3" ? "3 / 4" : "9 / 16",
533
+ width: aspect === "16:9" ? "100%" : void 0,
534
+ height: aspect === "16:9" ? void 0 : "70%",
535
+ maxWidth: "100%",
536
+ maxHeight: "100%"
537
+ }
538
+ }
539
+ )
540
+ }
541
+ ),
542
+ /* @__PURE__ */ jsx8(CountdownOverlay, { seconds: countdown }),
543
+ !controlsHidden && /* @__PURE__ */ jsx8("div", { className: "absolute inset-x-0 top-0 z-20 bg-black/65 pt-safe backdrop-blur-[2px]", children: /* @__PURE__ */ jsxs6("div", { className: "flex h-11 items-center gap-0.5 px-1.5", children: [
544
+ onClose ? /* @__PURE__ */ jsx8(
545
+ "button",
546
+ {
547
+ type: "button",
548
+ onClick: onClose,
549
+ "aria-label": "Close camera",
550
+ className: "flex h-10 w-10 shrink-0 touch-manipulation items-center justify-center rounded-full text-white transition-colors hover:bg-white/10",
551
+ children: /* @__PURE__ */ jsx8(X2, { className: "h-5 w-5" })
552
+ }
553
+ ) : /* @__PURE__ */ jsx8("span", { className: "w-10 shrink-0" }),
554
+ /* @__PURE__ */ jsx8("div", { className: "min-w-0 flex-1", children: slots.topBarCenter }),
555
+ controls.torchSupported && /* @__PURE__ */ jsx8(
556
+ "button",
557
+ {
558
+ type: "button",
559
+ onClick: controls.toggleTorch,
560
+ "aria-label": controls.torchOn ? "Turn flash off" : "Turn flash on",
561
+ "aria-pressed": controls.torchOn,
562
+ className: cn(
563
+ "flex h-10 w-10 shrink-0 touch-manipulation items-center justify-center rounded-full transition-colors",
564
+ controls.torchOn ? "text-[#FFCC00]" : "text-white hover:bg-white/10"
565
+ ),
566
+ children: /* @__PURE__ */ jsx8(
567
+ Zap,
568
+ {
569
+ className: "h-5 w-5",
570
+ fill: controls.torchOn ? "currentColor" : "none"
571
+ }
572
+ )
573
+ }
574
+ ),
575
+ slots.topBarTrailing,
576
+ /* @__PURE__ */ jsx8(
577
+ "button",
578
+ {
579
+ type: "button",
580
+ onClick: () => setOptionsOpen((o) => !o),
581
+ "aria-label": "More camera options",
582
+ "aria-expanded": optionsOpen,
583
+ className: cn(
584
+ "flex h-10 w-10 shrink-0 touch-manipulation items-center justify-center rounded-full transition-colors",
585
+ optionsOpen ? "bg-white/20 text-white" : "text-white hover:bg-white/10"
586
+ ),
587
+ children: /* @__PURE__ */ jsx8(Grip, { className: "h-5 w-5" })
588
+ }
589
+ )
590
+ ] }) }),
591
+ /* @__PURE__ */ jsxs6("div", { className: "pointer-events-none absolute inset-x-0 top-[50px] z-20 mt-safe flex flex-col items-center gap-1.5", children: [
592
+ engine.recording && /* @__PURE__ */ jsxs6("span", { className: "flex items-center gap-2 rounded-full bg-black/60 px-3 py-1.5 text-sm font-medium text-white", children: [
593
+ /* @__PURE__ */ jsx8("span", { className: "h-2.5 w-2.5 animate-pulse rounded-full bg-[#FF3B30]" }),
594
+ formatElapsed(engine.recordElapsedSeconds)
595
+ ] }),
596
+ slots.statusChips
597
+ ] }),
598
+ !controlsHidden && /* @__PURE__ */ jsxs6("div", { className: "absolute inset-x-0 bottom-0 z-20", children: [
599
+ !blocked && controls.zoomOptions.length >= 2 && /* @__PURE__ */ jsx8("div", { className: "mb-2", children: /* @__PURE__ */ jsx8(
600
+ ZoomRow,
601
+ {
602
+ options: controls.zoomOptions,
603
+ value: controls.zoom,
604
+ onSelect: controls.setZoom
605
+ }
606
+ ) }),
607
+ slots.aboveBar && /* @__PURE__ */ jsx8("div", { className: "mb-1.5 px-2", children: slots.aboveBar }),
608
+ exposureOpen && controls.exposureSupported && controls.exposureRange && /* @__PURE__ */ jsxs6("div", { className: "mx-auto mb-3 flex w-64 items-center gap-3 rounded-full bg-black/55 px-4 py-2", children: [
609
+ /* @__PURE__ */ jsx8(SunMedium, { className: "h-4 w-4 shrink-0 text-[#FFCC00]" }),
610
+ /* @__PURE__ */ jsx8(
611
+ "input",
612
+ {
613
+ type: "range",
614
+ min: controls.exposureRange.min,
615
+ max: controls.exposureRange.max,
616
+ step: controls.exposureRange.step,
617
+ value: controls.exposure,
618
+ onChange: (e) => controls.setExposure(Number(e.target.value)),
619
+ "aria-label": "Exposure compensation",
620
+ className: "w-full accent-[#FFCC00]"
621
+ }
622
+ ),
623
+ /* @__PURE__ */ jsxs6("span", { className: "w-8 shrink-0 text-right text-xs tabular-nums text-white", children: [
624
+ controls.exposure > 0 ? "+" : "",
625
+ controls.exposure
626
+ ] })
627
+ ] }),
628
+ /* @__PURE__ */ jsxs6("div", { className: "bg-black/65 px-3 pb-safe backdrop-blur-[2px]", children: [
629
+ slots.aboveModeSelector,
630
+ /* @__PURE__ */ jsxs6("div", { className: "relative flex items-center justify-center py-1.5", children: [
631
+ /* @__PURE__ */ jsx8(
632
+ ModeSelector,
633
+ {
634
+ mode,
635
+ onModeChange,
636
+ onUpload: engine.onUpload,
637
+ modeDisabled: engine.recording,
638
+ uploadDisabled: shutterDisabled && !blocked,
639
+ extraModes: slots.extraModes
640
+ }
641
+ ),
642
+ slots.modeRowTrailing && /* @__PURE__ */ jsx8("div", { className: "absolute right-0", children: slots.modeRowTrailing })
643
+ ] }),
644
+ /* @__PURE__ */ jsxs6("div", { className: "flex items-center justify-between px-2 pb-1.5 pt-0.5", children: [
645
+ /* @__PURE__ */ jsx8("div", { className: "flex w-14 justify-start", children: /* @__PURE__ */ jsx8(
646
+ "button",
647
+ {
648
+ type: "button",
649
+ onClick: cloud.onOpenLibrary,
650
+ "aria-label": "Open your media library",
651
+ className: "h-11 w-11 touch-manipulation overflow-hidden rounded-xl bg-white/10 ring-1 ring-white/25 transition-transform active:scale-95",
652
+ children: cloud.recentsThumb ?? /* @__PURE__ */ jsx8("span", { className: "block h-full w-full bg-white/5" })
653
+ }
654
+ ) }),
655
+ /* @__PURE__ */ jsx8(
656
+ ShutterButton,
657
+ {
658
+ mode,
659
+ recording: engine.recording,
660
+ disabled: shutterDisabled || blocked,
661
+ onPress: onShutter
662
+ }
663
+ ),
664
+ /* @__PURE__ */ jsx8("div", { className: "flex w-14 justify-end", children: engine.onFlipCamera ? /* @__PURE__ */ jsx8(
665
+ "button",
666
+ {
667
+ type: "button",
668
+ onClick: engine.onFlipCamera,
669
+ "aria-label": "Switch camera",
670
+ className: "flex h-11 w-11 touch-manipulation items-center justify-center rounded-full bg-white/15 text-white transition-transform active:rotate-180 active:scale-95 duration-300",
671
+ children: /* @__PURE__ */ jsx8(RefreshCw, { className: "h-5 w-5" })
672
+ }
673
+ ) : /* @__PURE__ */ jsx8("span", { className: "h-11 w-11" }) })
674
+ ] })
675
+ ] })
676
+ ] }),
677
+ /* @__PURE__ */ jsx8(
678
+ OptionsGridPanel,
679
+ {
680
+ open: optionsOpen && !controlsHidden,
681
+ onClose: () => setOptionsOpen(false),
682
+ tiles
683
+ }
684
+ ),
685
+ blocked && blockedSheet && !blockedDismissed && /* @__PURE__ */ jsx8(
686
+ CaptureSheet,
687
+ {
688
+ open: true,
689
+ onClose: () => setBlockedDismissed(true),
690
+ body: blockedSheet.body,
691
+ title: "Camera unavailable",
692
+ actions: blockedSheet.actions
693
+ }
694
+ ),
695
+ slots.overlays
696
+ ] });
697
+ }
698
+
699
+ // src/components/ImageEditSheet.tsx
700
+ import {
701
+ useCallback as useCallback3,
702
+ useEffect as useEffect3,
703
+ useRef as useRef2,
704
+ useState as useState3
705
+ } from "react";
706
+ import { Check, FlipHorizontal2, RotateCcw, X as X3 } from "lucide-react";
707
+ import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
708
+ var ASPECTS = [
709
+ { id: "free", label: "Free", ratio: null },
710
+ { id: "1:1", label: "Square", ratio: 1 },
711
+ { id: "4:3", label: "4:3", ratio: 4 / 3 },
712
+ { id: "16:9", label: "16:9", ratio: 16 / 9 }
713
+ ];
714
+ var FULL_CROP = { x: 0, y: 0, w: 1, h: 1 };
715
+ var MIN_CROP = 0.08;
716
+ function ImageEditSheet({
717
+ open,
718
+ src,
719
+ onClose,
720
+ onSave
721
+ }) {
722
+ const [rotation, setRotation] = useState3(0);
723
+ const [flipped, setFlipped] = useState3(false);
724
+ const [aspect, setAspect] = useState3("free");
725
+ const [crop, setCrop] = useState3(FULL_CROP);
726
+ const [saving, setSaving] = useState3(false);
727
+ const stageRef = useRef2(null);
728
+ const imgRef = useRef2(null);
729
+ const dragRef = useRef2(null);
730
+ useEffect3(() => {
731
+ if (open) {
732
+ setRotation(0);
733
+ setFlipped(false);
734
+ setAspect("free");
735
+ setCrop(FULL_CROP);
736
+ setSaving(false);
737
+ }
738
+ }, [open, src]);
739
+ const applyAspect = useCallback3((preset) => {
740
+ setAspect(preset);
741
+ const ratio = ASPECTS.find((a) => a.id === preset)?.ratio ?? null;
742
+ if (ratio === null) return;
743
+ const img = imgRef.current;
744
+ if (!img || img.naturalWidth === 0) return;
745
+ const rotated = rotationSwapsAxes();
746
+ const iw = rotated ? img.naturalHeight : img.naturalWidth;
747
+ const ih = rotated ? img.naturalWidth : img.naturalHeight;
748
+ const imageRatio = iw / ih;
749
+ let w = 1;
750
+ let h = 1;
751
+ if (ratio > imageRatio) h = imageRatio / ratio;
752
+ else w = ratio / imageRatio;
753
+ setCrop({ x: (1 - w) / 2, y: (1 - h) / 2, w, h });
754
+ function rotationSwapsAxes() {
755
+ return rotation % 180 !== 0;
756
+ }
757
+ }, [rotation]);
758
+ const onPointerDown = useCallback3(
759
+ (kind) => (e) => {
760
+ e.preventDefault();
761
+ e.stopPropagation();
762
+ e.target.setPointerCapture(e.pointerId);
763
+ dragRef.current = {
764
+ kind,
765
+ startX: e.clientX,
766
+ startY: e.clientY,
767
+ startCrop: crop
768
+ };
769
+ },
770
+ [crop]
771
+ );
772
+ const onPointerMove = useCallback3(
773
+ (e) => {
774
+ const drag = dragRef.current;
775
+ const img = imgRef.current;
776
+ if (!drag || !img) return;
777
+ const rect = img.getBoundingClientRect();
778
+ if (rect.width === 0 || rect.height === 0) return;
779
+ const dx = (e.clientX - drag.startX) / rect.width;
780
+ const dy = (e.clientY - drag.startY) / rect.height;
781
+ const c = { ...drag.startCrop };
782
+ const ratio = ASPECTS.find((a) => a.id === aspect)?.ratio ?? null;
783
+ const frameRatio = rect.width / rect.height;
784
+ if (drag.kind === "move") {
785
+ c.x = Math.min(1 - c.w, Math.max(0, c.x + dx));
786
+ c.y = Math.min(1 - c.h, Math.max(0, c.y + dy));
787
+ } else {
788
+ const left = drag.kind === "nw" || drag.kind === "sw";
789
+ const top = drag.kind === "nw" || drag.kind === "ne";
790
+ let x2 = c.x + c.w;
791
+ let y2 = c.y + c.h;
792
+ if (left) c.x = Math.min(x2 - MIN_CROP, Math.max(0, c.x + dx));
793
+ else x2 = Math.max(c.x + MIN_CROP, Math.min(1, x2 + dx));
794
+ if (top) c.y = Math.min(y2 - MIN_CROP, Math.max(0, c.y + dy));
795
+ else y2 = Math.max(c.y + MIN_CROP, Math.min(1, y2 + dy));
796
+ c.w = x2 - c.x;
797
+ c.h = y2 - c.y;
798
+ if (ratio !== null) {
799
+ const targetH = c.w * frameRatio / ratio;
800
+ if (top) c.y = y2 - Math.min(targetH, y2);
801
+ c.h = Math.min(targetH, top ? y2 - c.y : 1 - c.y);
802
+ c.w = c.h * ratio / frameRatio;
803
+ if (left) c.x = x2 - c.w;
804
+ }
805
+ }
806
+ setCrop(c);
807
+ },
808
+ [aspect]
809
+ );
810
+ const onPointerUp = useCallback3(() => {
811
+ dragRef.current = null;
812
+ }, []);
813
+ const save = useCallback3(() => {
814
+ const img = imgRef.current;
815
+ if (!img || img.naturalWidth === 0) return;
816
+ setSaving(true);
817
+ try {
818
+ const swap = rotation % 180 !== 0;
819
+ const outW = Math.round((swap ? img.naturalHeight : img.naturalWidth) * crop.w);
820
+ const outH = Math.round((swap ? img.naturalWidth : img.naturalHeight) * crop.h);
821
+ const canvas = document.createElement("canvas");
822
+ canvas.width = Math.max(1, outW);
823
+ canvas.height = Math.max(1, outH);
824
+ const ctx = canvas.getContext("2d");
825
+ if (!ctx) throw new Error("no 2d context");
826
+ const rw = swap ? img.naturalHeight : img.naturalWidth;
827
+ const rh = swap ? img.naturalWidth : img.naturalHeight;
828
+ ctx.translate(-crop.x * rw, -crop.y * rh);
829
+ ctx.translate(rw / 2, rh / 2);
830
+ ctx.rotate(rotation * Math.PI / 180);
831
+ if (flipped) ctx.scale(-1, 1);
832
+ ctx.drawImage(img, -img.naturalWidth / 2, -img.naturalHeight / 2);
833
+ canvas.toBlob(
834
+ (blob) => {
835
+ setSaving(false);
836
+ if (blob) {
837
+ onSave(blob);
838
+ onClose();
839
+ }
840
+ },
841
+ "image/jpeg",
842
+ 0.92
843
+ );
844
+ } catch (err) {
845
+ console.error("[capture-camera] edit save failed", err);
846
+ setSaving(false);
847
+ }
848
+ }, [rotation, flipped, crop, onSave, onClose]);
849
+ if (!open || !src) return null;
850
+ return /* @__PURE__ */ jsxs7("div", { className: "absolute inset-0 z-50 flex flex-col bg-black", children: [
851
+ /* @__PURE__ */ jsxs7("div", { className: "flex shrink-0 items-center justify-between px-4 pt-safe", children: [
852
+ /* @__PURE__ */ jsxs7(
853
+ "button",
854
+ {
855
+ type: "button",
856
+ onClick: onClose,
857
+ "aria-label": "Cancel editing",
858
+ className: "flex h-11 items-center gap-1.5 rounded-full px-3 text-[15px] font-medium text-white",
859
+ children: [
860
+ /* @__PURE__ */ jsx9(X3, { className: "h-5 w-5" }),
861
+ "Cancel"
862
+ ]
863
+ }
864
+ ),
865
+ /* @__PURE__ */ jsx9("span", { className: "text-[15px] font-semibold text-white/90", children: "Edit" }),
866
+ /* @__PURE__ */ jsxs7(
867
+ "button",
868
+ {
869
+ type: "button",
870
+ onClick: save,
871
+ disabled: saving,
872
+ "aria-label": "Save edited image",
873
+ className: "flex h-11 items-center gap-1.5 rounded-full px-3 text-[15px] font-semibold text-[#FFCC00] disabled:opacity-50",
874
+ children: [
875
+ /* @__PURE__ */ jsx9(Check, { className: "h-5 w-5" }),
876
+ "Save"
877
+ ]
878
+ }
879
+ )
880
+ ] }),
881
+ /* @__PURE__ */ jsx9(
882
+ "div",
883
+ {
884
+ ref: stageRef,
885
+ className: "relative flex min-h-0 flex-1 items-center justify-center overflow-hidden p-4",
886
+ onPointerMove,
887
+ onPointerUp,
888
+ onPointerCancel: onPointerUp,
889
+ children: /* @__PURE__ */ jsxs7("div", { className: "relative max-h-full max-w-full", children: [
890
+ /* @__PURE__ */ jsx9(
891
+ "img",
892
+ {
893
+ ref: imgRef,
894
+ src,
895
+ alt: "Image being edited",
896
+ draggable: false,
897
+ className: "max-h-[62dvh] max-w-full select-none object-contain",
898
+ style: {
899
+ transform: `rotate(${rotation}deg) ${flipped ? "scaleX(-1)" : ""}`
900
+ }
901
+ }
902
+ ),
903
+ /* @__PURE__ */ jsx9(
904
+ "div",
905
+ {
906
+ role: "presentation",
907
+ onPointerDown: onPointerDown("move"),
908
+ className: "absolute cursor-move touch-none border-2 border-white shadow-[0_0_0_9999px_rgba(0,0,0,0.55)]",
909
+ style: {
910
+ left: `${crop.x * 100}%`,
911
+ top: `${crop.y * 100}%`,
912
+ width: `${crop.w * 100}%`,
913
+ height: `${crop.h * 100}%`
914
+ },
915
+ children: ["nw", "ne", "sw", "se"].map((corner) => /* @__PURE__ */ jsx9(
916
+ "span",
917
+ {
918
+ role: "presentation",
919
+ onPointerDown: onPointerDown(corner),
920
+ className: cn(
921
+ "absolute h-6 w-6 touch-none",
922
+ corner === "nw" && "-left-1.5 -top-1.5 border-l-4 border-t-4 cursor-nwse-resize",
923
+ corner === "ne" && "-right-1.5 -top-1.5 border-r-4 border-t-4 cursor-nesw-resize",
924
+ corner === "sw" && "-bottom-1.5 -left-1.5 border-b-4 border-l-4 cursor-nesw-resize",
925
+ corner === "se" && "-bottom-1.5 -right-1.5 border-b-4 border-r-4 cursor-nwse-resize",
926
+ "border-white"
927
+ )
928
+ },
929
+ corner
930
+ ))
931
+ }
932
+ )
933
+ ] })
934
+ }
935
+ ),
936
+ /* @__PURE__ */ jsxs7("div", { className: "shrink-0 pb-safe", children: [
937
+ /* @__PURE__ */ jsx9("div", { className: "flex items-center justify-center gap-2 pb-2", children: ASPECTS.map((a) => /* @__PURE__ */ jsx9(
938
+ "button",
939
+ {
940
+ type: "button",
941
+ onClick: () => applyAspect(a.id),
942
+ "aria-pressed": aspect === a.id,
943
+ className: cn(
944
+ "touch-manipulation rounded-full px-3.5 py-1.5 text-[12px] font-semibold uppercase tracking-wide transition-colors",
945
+ aspect === a.id ? "bg-white/20 text-[#FFCC00]" : "text-white/80"
946
+ ),
947
+ children: a.label
948
+ },
949
+ a.id
950
+ )) }),
951
+ /* @__PURE__ */ jsxs7("div", { className: "flex items-center justify-center gap-6 pb-4", children: [
952
+ /* @__PURE__ */ jsx9(
953
+ "button",
954
+ {
955
+ type: "button",
956
+ onClick: () => {
957
+ setRotation((r) => (r + 270) % 360);
958
+ setCrop(FULL_CROP);
959
+ setAspect("free");
960
+ },
961
+ "aria-label": "Rotate left",
962
+ className: "flex h-12 w-12 touch-manipulation items-center justify-center rounded-full bg-white/10 text-white",
963
+ children: /* @__PURE__ */ jsx9(RotateCcw, { className: "h-5 w-5" })
964
+ }
965
+ ),
966
+ /* @__PURE__ */ jsx9(
967
+ "button",
968
+ {
969
+ type: "button",
970
+ onClick: () => setFlipped((f) => !f),
971
+ "aria-label": "Flip horizontally",
972
+ "aria-pressed": flipped,
973
+ className: cn(
974
+ "flex h-12 w-12 touch-manipulation items-center justify-center rounded-full bg-white/10",
975
+ flipped ? "text-[#FFCC00]" : "text-white"
976
+ ),
977
+ children: /* @__PURE__ */ jsx9(FlipHorizontal2, { className: "h-5 w-5" })
978
+ }
979
+ )
980
+ ] })
981
+ ] })
982
+ ] });
983
+ }
984
+ export {
985
+ CameraCapture,
986
+ CaptureSheet,
987
+ CountdownOverlay,
988
+ GridOverlay,
989
+ ImageEditSheet,
990
+ ModeSelector,
991
+ OptionsGridPanel,
992
+ ShutterButton,
993
+ ZoomRow,
994
+ useTrackControls
995
+ };
996
+ //# sourceMappingURL=react.js.map