@ai-matrx/capture 0.0.0 → 0.1.0

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