@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/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +40 -1
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +116 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +984 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +342 -0
- package/dist/react.d.ts +342 -0
- package/dist/react.js +977 -0
- package/dist/react.js.map +1 -0
- package/package.json +95 -7
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,984 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/react.ts
|
|
22
|
+
var react_exports = {};
|
|
23
|
+
__export(react_exports, {
|
|
24
|
+
CameraCapture: () => CameraCapture,
|
|
25
|
+
CaptureSheet: () => CaptureSheet,
|
|
26
|
+
CountdownOverlay: () => CountdownOverlay,
|
|
27
|
+
GridOverlay: () => GridOverlay,
|
|
28
|
+
ImageEditSheet: () => ImageEditSheet,
|
|
29
|
+
ModeSelector: () => ModeSelector,
|
|
30
|
+
OptionsGridPanel: () => OptionsGridPanel,
|
|
31
|
+
ShutterButton: () => ShutterButton,
|
|
32
|
+
ZoomRow: () => ZoomRow,
|
|
33
|
+
useTrackControls: () => useTrackControls
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(react_exports);
|
|
36
|
+
|
|
37
|
+
// src/components/CameraCapture.tsx
|
|
38
|
+
var import_react2 = require("react");
|
|
39
|
+
var import_lucide_react2 = require("lucide-react");
|
|
40
|
+
|
|
41
|
+
// src/cn.ts
|
|
42
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
43
|
+
function cn(...inputs) {
|
|
44
|
+
return (0, import_tailwind_merge.twMerge)(inputs.filter(Boolean).join(" "));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/hooks/useTrackControls.ts
|
|
48
|
+
var import_react = require("react");
|
|
49
|
+
var ZOOM_LADDER = [0.5, 1, 2, 4, 8];
|
|
50
|
+
function useTrackControls(stream) {
|
|
51
|
+
const [torchOn, setTorchOn] = (0, import_react.useState)(false);
|
|
52
|
+
const [zoom, setZoomState] = (0, import_react.useState)(1);
|
|
53
|
+
const [exposure, setExposureState] = (0, import_react.useState)(0);
|
|
54
|
+
const [caps, setCaps] = (0, import_react.useState)(null);
|
|
55
|
+
const track = stream?.getVideoTracks()[0] ?? null;
|
|
56
|
+
(0, import_react.useEffect)(() => {
|
|
57
|
+
setTorchOn(false);
|
|
58
|
+
if (!track || typeof track.getCapabilities !== "function") {
|
|
59
|
+
setCaps(null);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const read = () => {
|
|
63
|
+
try {
|
|
64
|
+
setCaps(track.getCapabilities());
|
|
65
|
+
const settings = track.getSettings();
|
|
66
|
+
if (typeof settings.zoom === "number") setZoomState(settings.zoom);
|
|
67
|
+
if (typeof settings.exposureCompensation === "number")
|
|
68
|
+
setExposureState(settings.exposureCompensation);
|
|
69
|
+
} catch {
|
|
70
|
+
setCaps(null);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
read();
|
|
74
|
+
const timer = window.setTimeout(read, 750);
|
|
75
|
+
return () => window.clearTimeout(timer);
|
|
76
|
+
}, [track]);
|
|
77
|
+
const torchSupported = caps?.torch === true;
|
|
78
|
+
const toggleTorch = (0, import_react.useCallback)(() => {
|
|
79
|
+
if (!track || !torchSupported) return;
|
|
80
|
+
const next = !torchOn;
|
|
81
|
+
track.applyConstraints({ advanced: [{ torch: next }] }).then(() => setTorchOn(next)).catch((err) => {
|
|
82
|
+
console.error("[capture-camera] torch toggle failed", err);
|
|
83
|
+
});
|
|
84
|
+
}, [track, torchSupported, torchOn]);
|
|
85
|
+
const zoomOptions = (0, import_react.useMemo)(() => {
|
|
86
|
+
const range = caps?.zoom;
|
|
87
|
+
if (!range || !(range.max > range.min)) return [];
|
|
88
|
+
const options = ZOOM_LADDER.filter(
|
|
89
|
+
(f) => f >= range.min && f <= range.max
|
|
90
|
+
);
|
|
91
|
+
if (!options.includes(1) && 1 >= range.min && 1 <= range.max) {
|
|
92
|
+
options.push(1);
|
|
93
|
+
options.sort((a, b) => a - b);
|
|
94
|
+
}
|
|
95
|
+
return options.length >= 2 ? options : [];
|
|
96
|
+
}, [caps]);
|
|
97
|
+
const setZoom = (0, import_react.useCallback)(
|
|
98
|
+
(factor) => {
|
|
99
|
+
if (!track || !caps?.zoom) return;
|
|
100
|
+
const clamped = Math.min(caps.zoom.max, Math.max(caps.zoom.min, factor));
|
|
101
|
+
track.applyConstraints({
|
|
102
|
+
advanced: [{ zoom: clamped }]
|
|
103
|
+
}).then(() => setZoomState(clamped)).catch((err) => {
|
|
104
|
+
console.error("[capture-camera] zoom failed", err);
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
[track, caps]
|
|
108
|
+
);
|
|
109
|
+
const exposureCaps = caps?.exposureCompensation;
|
|
110
|
+
const exposureRange = exposureCaps && exposureCaps.max > exposureCaps.min ? {
|
|
111
|
+
min: exposureCaps.min,
|
|
112
|
+
max: exposureCaps.max,
|
|
113
|
+
step: exposureCaps.step && exposureCaps.step > 0 ? exposureCaps.step : 0.5
|
|
114
|
+
} : null;
|
|
115
|
+
const setExposure = (0, import_react.useCallback)(
|
|
116
|
+
(value) => {
|
|
117
|
+
if (!track || !exposureRange) return;
|
|
118
|
+
const clamped = Math.min(
|
|
119
|
+
exposureRange.max,
|
|
120
|
+
Math.max(exposureRange.min, value)
|
|
121
|
+
);
|
|
122
|
+
track.applyConstraints({
|
|
123
|
+
advanced: [
|
|
124
|
+
{ exposureCompensation: clamped }
|
|
125
|
+
]
|
|
126
|
+
}).then(() => setExposureState(clamped)).catch((err) => {
|
|
127
|
+
console.error("[capture-camera] exposure failed", err);
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
[track, exposureRange]
|
|
131
|
+
);
|
|
132
|
+
return {
|
|
133
|
+
torchSupported,
|
|
134
|
+
torchOn,
|
|
135
|
+
toggleTorch,
|
|
136
|
+
zoomOptions,
|
|
137
|
+
zoom,
|
|
138
|
+
setZoom,
|
|
139
|
+
exposureSupported: exposureRange !== null,
|
|
140
|
+
exposure,
|
|
141
|
+
exposureRange,
|
|
142
|
+
setExposure
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/components/ShutterButton.tsx
|
|
147
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
148
|
+
function ShutterButton({
|
|
149
|
+
mode,
|
|
150
|
+
recording,
|
|
151
|
+
disabled = false,
|
|
152
|
+
onPress
|
|
153
|
+
}) {
|
|
154
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
155
|
+
"button",
|
|
156
|
+
{
|
|
157
|
+
type: "button",
|
|
158
|
+
onClick: onPress,
|
|
159
|
+
disabled,
|
|
160
|
+
"aria-label": mode === "photo" ? "Take photo" : recording ? "Stop recording" : "Start recording",
|
|
161
|
+
className: cn(
|
|
162
|
+
"group flex h-[74px] w-[74px] shrink-0 items-center justify-center rounded-full",
|
|
163
|
+
"border-[3.5px] border-white transition-opacity",
|
|
164
|
+
disabled && "opacity-30"
|
|
165
|
+
),
|
|
166
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
167
|
+
"span",
|
|
168
|
+
{
|
|
169
|
+
className: cn(
|
|
170
|
+
"block transition-all duration-200 ease-out group-active:scale-90",
|
|
171
|
+
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]"
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/components/ModeSelector.tsx
|
|
180
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
181
|
+
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";
|
|
182
|
+
function ModeSelector({
|
|
183
|
+
mode,
|
|
184
|
+
onModeChange,
|
|
185
|
+
onUpload,
|
|
186
|
+
modeDisabled = false,
|
|
187
|
+
uploadDisabled = false,
|
|
188
|
+
extraModes = []
|
|
189
|
+
}) {
|
|
190
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
191
|
+
"div",
|
|
192
|
+
{
|
|
193
|
+
role: "tablist",
|
|
194
|
+
"aria-label": "Capture mode",
|
|
195
|
+
className: "flex items-center justify-center gap-1",
|
|
196
|
+
children: [
|
|
197
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
198
|
+
"button",
|
|
199
|
+
{
|
|
200
|
+
type: "button",
|
|
201
|
+
role: "tab",
|
|
202
|
+
"aria-selected": mode === "video",
|
|
203
|
+
disabled: modeDisabled,
|
|
204
|
+
onClick: () => onModeChange("video"),
|
|
205
|
+
className: cn(
|
|
206
|
+
LABEL_BASE,
|
|
207
|
+
mode === "video" ? "bg-white/15 text-[#FFCC00]" : "text-white"
|
|
208
|
+
),
|
|
209
|
+
children: "Video"
|
|
210
|
+
}
|
|
211
|
+
),
|
|
212
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
213
|
+
"button",
|
|
214
|
+
{
|
|
215
|
+
type: "button",
|
|
216
|
+
role: "tab",
|
|
217
|
+
"aria-selected": mode === "photo",
|
|
218
|
+
disabled: modeDisabled,
|
|
219
|
+
onClick: () => onModeChange("photo"),
|
|
220
|
+
className: cn(
|
|
221
|
+
LABEL_BASE,
|
|
222
|
+
mode === "photo" ? "bg-white/15 text-[#FFCC00]" : "text-white"
|
|
223
|
+
),
|
|
224
|
+
children: "Photo"
|
|
225
|
+
}
|
|
226
|
+
),
|
|
227
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
228
|
+
"button",
|
|
229
|
+
{
|
|
230
|
+
type: "button",
|
|
231
|
+
"aria-label": "Upload photos or videos from this device",
|
|
232
|
+
disabled: modeDisabled || uploadDisabled,
|
|
233
|
+
onClick: onUpload,
|
|
234
|
+
className: cn(LABEL_BASE, "text-white active:text-[#FFCC00]"),
|
|
235
|
+
children: "Upload"
|
|
236
|
+
}
|
|
237
|
+
),
|
|
238
|
+
extraModes.map((extra) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
239
|
+
"button",
|
|
240
|
+
{
|
|
241
|
+
type: "button",
|
|
242
|
+
"aria-label": extra.label,
|
|
243
|
+
disabled: modeDisabled,
|
|
244
|
+
onClick: extra.onSelect,
|
|
245
|
+
className: cn(LABEL_BASE, "text-white active:text-[#FFCC00]"),
|
|
246
|
+
children: extra.label
|
|
247
|
+
},
|
|
248
|
+
extra.id
|
|
249
|
+
))
|
|
250
|
+
]
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/components/ZoomRow.tsx
|
|
256
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
257
|
+
function formatFactor(factor) {
|
|
258
|
+
return factor < 1 ? `.${String(Math.round(factor * 10))}` : String(Math.round(factor * 10) / 10);
|
|
259
|
+
}
|
|
260
|
+
function ZoomRow({ options, value, onSelect }) {
|
|
261
|
+
if (options.length < 2) return null;
|
|
262
|
+
const active = options.reduce(
|
|
263
|
+
(best, opt) => Math.abs(opt - value) < Math.abs(best - value) ? opt : best
|
|
264
|
+
);
|
|
265
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "flex items-center justify-center gap-3", children: options.map((opt) => {
|
|
266
|
+
const isActive = opt === active;
|
|
267
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
268
|
+
"button",
|
|
269
|
+
{
|
|
270
|
+
type: "button",
|
|
271
|
+
onClick: () => onSelect(opt),
|
|
272
|
+
"aria-label": `Zoom ${formatFactor(opt)}x`,
|
|
273
|
+
"aria-pressed": isActive,
|
|
274
|
+
className: cn(
|
|
275
|
+
"flex touch-manipulation items-center justify-center rounded-full font-semibold transition-all duration-200",
|
|
276
|
+
isActive ? "h-10 w-10 bg-black/45 text-[13px] text-[#FFCC00]" : "h-8 w-8 bg-black/35 text-[12px] text-white"
|
|
277
|
+
),
|
|
278
|
+
children: [
|
|
279
|
+
formatFactor(opt),
|
|
280
|
+
isActive && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-[10px]", children: "\xD7" })
|
|
281
|
+
]
|
|
282
|
+
},
|
|
283
|
+
opt
|
|
284
|
+
);
|
|
285
|
+
}) });
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/components/OptionsGridPanel.tsx
|
|
289
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
290
|
+
function OptionsGridPanel({
|
|
291
|
+
open,
|
|
292
|
+
onClose,
|
|
293
|
+
tiles
|
|
294
|
+
}) {
|
|
295
|
+
if (!open) return null;
|
|
296
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "absolute inset-0 z-40", children: [
|
|
297
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
298
|
+
"button",
|
|
299
|
+
{
|
|
300
|
+
type: "button",
|
|
301
|
+
"aria-label": "Close camera options",
|
|
302
|
+
onClick: onClose,
|
|
303
|
+
className: "absolute inset-0 bg-black/70"
|
|
304
|
+
}
|
|
305
|
+
),
|
|
306
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "absolute inset-x-3 bottom-3 mb-safe rounded-[2.5rem] bg-[#3a3a3c]/95 px-6 py-8 shadow-2xl", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "grid grid-cols-3 gap-x-4 gap-y-7", children: tiles.map((tile) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex flex-col items-center gap-2.5", children: [
|
|
307
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
308
|
+
"button",
|
|
309
|
+
{
|
|
310
|
+
type: "button",
|
|
311
|
+
onClick: tile.onPress,
|
|
312
|
+
disabled: tile.disabled,
|
|
313
|
+
"aria-label": tile.label,
|
|
314
|
+
"aria-pressed": tile.active === true,
|
|
315
|
+
className: cn(
|
|
316
|
+
"flex h-16 w-16 touch-manipulation items-center justify-center rounded-full bg-[#2c2c2e] transition-colors",
|
|
317
|
+
tile.active ? "text-[#FFCC00]" : "text-white",
|
|
318
|
+
tile.disabled && "opacity-40"
|
|
319
|
+
),
|
|
320
|
+
children: tile.icon
|
|
321
|
+
}
|
|
322
|
+
),
|
|
323
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-[13px] font-semibold uppercase tracking-[0.14em] text-white", children: tile.valueLabel ? `${tile.label} ${tile.valueLabel}` : tile.label })
|
|
324
|
+
] }, tile.id)) }) })
|
|
325
|
+
] });
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// src/components/CaptureSheet.tsx
|
|
329
|
+
var import_lucide_react = require("lucide-react");
|
|
330
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
331
|
+
function CaptureSheet({
|
|
332
|
+
open,
|
|
333
|
+
onClose,
|
|
334
|
+
variant = "content",
|
|
335
|
+
icon,
|
|
336
|
+
title,
|
|
337
|
+
body,
|
|
338
|
+
actions = [],
|
|
339
|
+
busyLabel = "Working\u2026"
|
|
340
|
+
}) {
|
|
341
|
+
if (!open) return null;
|
|
342
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "absolute inset-0 z-50 flex flex-col justify-end", children: [
|
|
343
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
344
|
+
"button",
|
|
345
|
+
{
|
|
346
|
+
type: "button",
|
|
347
|
+
"aria-label": "Dismiss",
|
|
348
|
+
onClick: onClose,
|
|
349
|
+
className: "absolute inset-0 bg-black/30"
|
|
350
|
+
}
|
|
351
|
+
),
|
|
352
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "relative mx-2 mb-2 mb-safe rounded-[2rem] bg-[#f2f2f7] px-6 pb-6 pt-5 text-black shadow-2xl", children: [
|
|
353
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
354
|
+
"button",
|
|
355
|
+
{
|
|
356
|
+
type: "button",
|
|
357
|
+
onClick: onClose,
|
|
358
|
+
"aria-label": "Close",
|
|
359
|
+
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",
|
|
360
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.X, { className: "h-5 w-5", strokeWidth: 2.5 })
|
|
361
|
+
}
|
|
362
|
+
),
|
|
363
|
+
variant === "busy" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex min-h-[220px] items-center justify-center gap-2.5", children: [
|
|
364
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.Loader2, { className: "h-5 w-5 animate-spin text-black/50" }),
|
|
365
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-[17px] font-medium text-black/80", children: busyLabel })
|
|
366
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "pt-4", children: [
|
|
367
|
+
icon && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mb-5 text-[#0a84ff]", children: icon }),
|
|
368
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { className: "mb-2 text-[26px] font-bold leading-tight", children: title }),
|
|
369
|
+
body && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "text-[17px] leading-snug text-black/85", children: body }),
|
|
370
|
+
actions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mt-7 flex flex-col gap-3", children: actions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
371
|
+
"button",
|
|
372
|
+
{
|
|
373
|
+
type: "button",
|
|
374
|
+
onClick: action.onPress,
|
|
375
|
+
className: cn(
|
|
376
|
+
"h-[50px] w-full touch-manipulation rounded-full text-[17px] font-semibold transition-transform active:scale-[0.98]",
|
|
377
|
+
(action.kind ?? "primary") === "primary" ? "bg-[#0a84ff] text-white" : "bg-black/[0.06] text-[#0a84ff]"
|
|
378
|
+
),
|
|
379
|
+
children: action.label
|
|
380
|
+
},
|
|
381
|
+
action.label
|
|
382
|
+
)) })
|
|
383
|
+
] })
|
|
384
|
+
] })
|
|
385
|
+
] });
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// src/components/GridOverlay.tsx
|
|
389
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
390
|
+
function GridOverlay({ visible }) {
|
|
391
|
+
if (!visible) return null;
|
|
392
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 z-10", children: [
|
|
393
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "absolute inset-y-0 left-1/3 w-px bg-white/40" }),
|
|
394
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "absolute inset-y-0 left-2/3 w-px bg-white/40" }),
|
|
395
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "absolute inset-x-0 top-1/3 h-px bg-white/40" }),
|
|
396
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "absolute inset-x-0 top-2/3 h-px bg-white/40" })
|
|
397
|
+
] });
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// src/components/CountdownOverlay.tsx
|
|
401
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
402
|
+
function CountdownOverlay({ seconds }) {
|
|
403
|
+
if (seconds === null || seconds <= 0) return null;
|
|
404
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "pointer-events-none absolute inset-0 z-30 flex items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
405
|
+
"span",
|
|
406
|
+
{
|
|
407
|
+
className: "text-[120px] font-light text-white drop-shadow-lg [@starting-style]:scale-125 [@starting-style]:opacity-0 transition-all duration-300",
|
|
408
|
+
children: seconds
|
|
409
|
+
},
|
|
410
|
+
seconds
|
|
411
|
+
) });
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// src/components/CameraCapture.tsx
|
|
415
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
416
|
+
function formatElapsed(totalSeconds) {
|
|
417
|
+
const m = Math.floor(totalSeconds / 60);
|
|
418
|
+
const s = String(totalSeconds % 60).padStart(2, "0");
|
|
419
|
+
return `${m}:${s}`;
|
|
420
|
+
}
|
|
421
|
+
var ASPECT_CYCLE = ["full", "4:3", "1:1", "16:9"];
|
|
422
|
+
function CameraCapture({
|
|
423
|
+
engine,
|
|
424
|
+
cloud,
|
|
425
|
+
mode,
|
|
426
|
+
onModeChange,
|
|
427
|
+
preview,
|
|
428
|
+
onClose,
|
|
429
|
+
blockedSheet,
|
|
430
|
+
controlsHidden = false,
|
|
431
|
+
shutterDisabled = false,
|
|
432
|
+
slots = {}
|
|
433
|
+
}) {
|
|
434
|
+
const [optionsOpen, setOptionsOpen] = (0, import_react2.useState)(false);
|
|
435
|
+
const [gridOn, setGridOn] = (0, import_react2.useState)(false);
|
|
436
|
+
const [timerSetting, setTimerSetting] = (0, import_react2.useState)(0);
|
|
437
|
+
const [aspect, setAspect] = (0, import_react2.useState)("full");
|
|
438
|
+
const [exposureOpen, setExposureOpen] = (0, import_react2.useState)(false);
|
|
439
|
+
const [countdown, setCountdown] = (0, import_react2.useState)(null);
|
|
440
|
+
const [blockedDismissed, setBlockedDismissed] = (0, import_react2.useState)(false);
|
|
441
|
+
const countdownRef = (0, import_react2.useRef)(null);
|
|
442
|
+
const controls = useTrackControls(engine.stream);
|
|
443
|
+
const clearCountdown = (0, import_react2.useCallback)(() => {
|
|
444
|
+
if (countdownRef.current) clearInterval(countdownRef.current);
|
|
445
|
+
countdownRef.current = null;
|
|
446
|
+
setCountdown(null);
|
|
447
|
+
}, []);
|
|
448
|
+
(0, import_react2.useEffect)(() => clearCountdown, [clearCountdown]);
|
|
449
|
+
const onShutter = (0, import_react2.useCallback)(() => {
|
|
450
|
+
if (mode === "video") {
|
|
451
|
+
if (engine.recording) engine.onStopRecording();
|
|
452
|
+
else engine.onStartRecording();
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (countdown !== null) {
|
|
456
|
+
clearCountdown();
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (timerSetting === 0) {
|
|
460
|
+
engine.onCapturePhoto({ aspect });
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
let remaining = timerSetting;
|
|
464
|
+
setCountdown(remaining);
|
|
465
|
+
countdownRef.current = setInterval(() => {
|
|
466
|
+
remaining -= 1;
|
|
467
|
+
if (remaining <= 0) {
|
|
468
|
+
clearCountdown();
|
|
469
|
+
engine.onCapturePhoto({ aspect });
|
|
470
|
+
} else {
|
|
471
|
+
setCountdown(remaining);
|
|
472
|
+
}
|
|
473
|
+
}, 1e3);
|
|
474
|
+
}, [mode, engine, countdown, timerSetting, aspect, clearCountdown]);
|
|
475
|
+
const cycleTimer = (0, import_react2.useCallback)(() => {
|
|
476
|
+
setTimerSetting((t) => t === 0 ? 3 : t === 3 ? 10 : 0);
|
|
477
|
+
}, []);
|
|
478
|
+
const coreTiles = [
|
|
479
|
+
...controls.torchSupported ? [
|
|
480
|
+
{
|
|
481
|
+
id: "flash",
|
|
482
|
+
label: "Flash",
|
|
483
|
+
icon: controls.torchOn ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.Zap, { className: "h-6 w-6", fill: "currentColor" }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.ZapOff, { className: "h-6 w-6" }),
|
|
484
|
+
active: controls.torchOn,
|
|
485
|
+
onPress: controls.toggleTorch
|
|
486
|
+
}
|
|
487
|
+
] : [],
|
|
488
|
+
{
|
|
489
|
+
id: "timer",
|
|
490
|
+
label: "Timer",
|
|
491
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.Timer, { className: "h-6 w-6" }),
|
|
492
|
+
active: timerSetting !== 0,
|
|
493
|
+
valueLabel: timerSetting === 0 ? void 0 : `${timerSetting}s`,
|
|
494
|
+
onPress: cycleTimer
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
id: "grid",
|
|
498
|
+
label: "Grid",
|
|
499
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.Grid3x3, { className: "h-6 w-6" }),
|
|
500
|
+
active: gridOn,
|
|
501
|
+
onPress: () => setGridOn((g) => !g)
|
|
502
|
+
},
|
|
503
|
+
// Aspect applies to PHOTO output (center-cropped from the full sensor).
|
|
504
|
+
{
|
|
505
|
+
id: "aspect",
|
|
506
|
+
label: "Aspect",
|
|
507
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.Proportions, { className: "h-6 w-6" }),
|
|
508
|
+
active: aspect !== "full",
|
|
509
|
+
valueLabel: aspect === "full" ? void 0 : aspect,
|
|
510
|
+
onPress: () => setAspect(
|
|
511
|
+
(a) => ASPECT_CYCLE[(ASPECT_CYCLE.indexOf(a) + 1) % ASPECT_CYCLE.length] ?? "full"
|
|
512
|
+
)
|
|
513
|
+
},
|
|
514
|
+
...controls.exposureSupported ? [
|
|
515
|
+
{
|
|
516
|
+
id: "exposure",
|
|
517
|
+
label: "Exposure",
|
|
518
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.SunMedium, { className: "h-6 w-6" }),
|
|
519
|
+
active: controls.exposure !== 0 || exposureOpen,
|
|
520
|
+
valueLabel: controls.exposure === 0 ? void 0 : `${controls.exposure > 0 ? "+" : ""}${controls.exposure}`,
|
|
521
|
+
onPress: () => setExposureOpen((o) => !o)
|
|
522
|
+
}
|
|
523
|
+
] : []
|
|
524
|
+
];
|
|
525
|
+
const tiles = [...coreTiles, ...slots.optionTiles ?? []];
|
|
526
|
+
const blocked = engine.blocked !== null;
|
|
527
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "absolute inset-0 select-none overflow-hidden bg-black", children: [
|
|
528
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "absolute inset-0", children: preview }),
|
|
529
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(GridOverlay, { visible: gridOn && !blocked }),
|
|
530
|
+
mode === "photo" && aspect !== "full" && !blocked && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
531
|
+
"div",
|
|
532
|
+
{
|
|
533
|
+
"aria-hidden": true,
|
|
534
|
+
className: "pointer-events-none absolute inset-0 z-10 flex items-center justify-center",
|
|
535
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
536
|
+
"div",
|
|
537
|
+
{
|
|
538
|
+
className: "shadow-[0_0_0_9999px_rgba(0,0,0,0.45)]",
|
|
539
|
+
style: {
|
|
540
|
+
aspectRatio: aspect === "1:1" ? "1 / 1" : aspect === "4:3" ? "3 / 4" : "9 / 16",
|
|
541
|
+
width: aspect === "16:9" ? "100%" : void 0,
|
|
542
|
+
height: aspect === "16:9" ? void 0 : "70%",
|
|
543
|
+
maxWidth: "100%",
|
|
544
|
+
maxHeight: "100%"
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
)
|
|
548
|
+
}
|
|
549
|
+
),
|
|
550
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CountdownOverlay, { seconds: countdown }),
|
|
551
|
+
!controlsHidden && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "absolute inset-x-0 top-0 z-20 bg-black/65 pt-safe backdrop-blur-[2px]", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex h-16 items-center gap-1 px-3", children: [
|
|
552
|
+
onClose ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
553
|
+
"button",
|
|
554
|
+
{
|
|
555
|
+
type: "button",
|
|
556
|
+
onClick: onClose,
|
|
557
|
+
"aria-label": "Close camera",
|
|
558
|
+
className: "flex h-11 w-11 shrink-0 touch-manipulation items-center justify-center rounded-full text-white transition-colors hover:bg-white/10",
|
|
559
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.X, { className: "h-6 w-6" })
|
|
560
|
+
}
|
|
561
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "w-11 shrink-0" }),
|
|
562
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "min-w-0 flex-1", children: slots.topBarCenter }),
|
|
563
|
+
controls.torchSupported && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
564
|
+
"button",
|
|
565
|
+
{
|
|
566
|
+
type: "button",
|
|
567
|
+
onClick: controls.toggleTorch,
|
|
568
|
+
"aria-label": controls.torchOn ? "Turn flash off" : "Turn flash on",
|
|
569
|
+
"aria-pressed": controls.torchOn,
|
|
570
|
+
className: cn(
|
|
571
|
+
"flex h-11 w-11 shrink-0 touch-manipulation items-center justify-center rounded-full transition-colors",
|
|
572
|
+
controls.torchOn ? "text-[#FFCC00]" : "text-white hover:bg-white/10"
|
|
573
|
+
),
|
|
574
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
575
|
+
import_lucide_react2.Zap,
|
|
576
|
+
{
|
|
577
|
+
className: "h-[22px] w-[22px]",
|
|
578
|
+
fill: controls.torchOn ? "currentColor" : "none"
|
|
579
|
+
}
|
|
580
|
+
)
|
|
581
|
+
}
|
|
582
|
+
),
|
|
583
|
+
slots.topBarTrailing,
|
|
584
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
585
|
+
"button",
|
|
586
|
+
{
|
|
587
|
+
type: "button",
|
|
588
|
+
onClick: () => setOptionsOpen((o) => !o),
|
|
589
|
+
"aria-label": "More camera options",
|
|
590
|
+
"aria-expanded": optionsOpen,
|
|
591
|
+
className: cn(
|
|
592
|
+
"flex h-11 w-11 shrink-0 touch-manipulation items-center justify-center rounded-full transition-colors",
|
|
593
|
+
optionsOpen ? "bg-white/20 text-white" : "text-white hover:bg-white/10"
|
|
594
|
+
),
|
|
595
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.Grip, { className: "h-[22px] w-[22px]" })
|
|
596
|
+
}
|
|
597
|
+
)
|
|
598
|
+
] }) }),
|
|
599
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "pointer-events-none absolute inset-x-0 top-20 z-20 mt-safe flex flex-col items-center gap-2", children: [
|
|
600
|
+
engine.recording && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "flex items-center gap-2 rounded-full bg-black/60 px-3 py-1.5 text-sm font-medium text-white", children: [
|
|
601
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "h-2.5 w-2.5 animate-pulse rounded-full bg-[#FF3B30]" }),
|
|
602
|
+
formatElapsed(engine.recordElapsedSeconds)
|
|
603
|
+
] }),
|
|
604
|
+
slots.statusChips
|
|
605
|
+
] }),
|
|
606
|
+
!controlsHidden && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "absolute inset-x-0 bottom-0 z-20", children: [
|
|
607
|
+
!blocked && controls.zoomOptions.length >= 2 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "mb-3", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
608
|
+
ZoomRow,
|
|
609
|
+
{
|
|
610
|
+
options: controls.zoomOptions,
|
|
611
|
+
value: controls.zoom,
|
|
612
|
+
onSelect: controls.setZoom
|
|
613
|
+
}
|
|
614
|
+
) }),
|
|
615
|
+
exposureOpen && controls.exposureSupported && controls.exposureRange && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "mx-auto mb-3 flex w-64 items-center gap-3 rounded-full bg-black/55 px-4 py-2", children: [
|
|
616
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.SunMedium, { className: "h-4 w-4 shrink-0 text-[#FFCC00]" }),
|
|
617
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
618
|
+
"input",
|
|
619
|
+
{
|
|
620
|
+
type: "range",
|
|
621
|
+
min: controls.exposureRange.min,
|
|
622
|
+
max: controls.exposureRange.max,
|
|
623
|
+
step: controls.exposureRange.step,
|
|
624
|
+
value: controls.exposure,
|
|
625
|
+
onChange: (e) => controls.setExposure(Number(e.target.value)),
|
|
626
|
+
"aria-label": "Exposure compensation",
|
|
627
|
+
className: "w-full accent-[#FFCC00]"
|
|
628
|
+
}
|
|
629
|
+
),
|
|
630
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "w-8 shrink-0 text-right text-xs tabular-nums text-white", children: [
|
|
631
|
+
controls.exposure > 0 ? "+" : "",
|
|
632
|
+
controls.exposure
|
|
633
|
+
] })
|
|
634
|
+
] }),
|
|
635
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "bg-black/65 px-3 pb-safe backdrop-blur-[2px]", children: [
|
|
636
|
+
slots.aboveModeSelector,
|
|
637
|
+
slots.modeRowTrailing && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex justify-end pb-1 pt-1.5", children: slots.modeRowTrailing }),
|
|
638
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex items-center justify-center py-2.5", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
639
|
+
ModeSelector,
|
|
640
|
+
{
|
|
641
|
+
mode,
|
|
642
|
+
onModeChange,
|
|
643
|
+
onUpload: engine.onUpload,
|
|
644
|
+
modeDisabled: engine.recording,
|
|
645
|
+
uploadDisabled: shutterDisabled && !blocked,
|
|
646
|
+
extraModes: slots.extraModes
|
|
647
|
+
}
|
|
648
|
+
) }),
|
|
649
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex items-center justify-between px-2 pb-4 pt-1", children: [
|
|
650
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex w-16 justify-start", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
651
|
+
"button",
|
|
652
|
+
{
|
|
653
|
+
type: "button",
|
|
654
|
+
onClick: cloud.onOpenLibrary,
|
|
655
|
+
"aria-label": "Open your media library",
|
|
656
|
+
className: "h-12 w-12 touch-manipulation overflow-hidden rounded-xl bg-white/10 ring-1 ring-white/25 transition-transform active:scale-95",
|
|
657
|
+
children: cloud.recentsThumb ?? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "block h-full w-full bg-white/5" })
|
|
658
|
+
}
|
|
659
|
+
) }),
|
|
660
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
661
|
+
ShutterButton,
|
|
662
|
+
{
|
|
663
|
+
mode,
|
|
664
|
+
recording: engine.recording,
|
|
665
|
+
disabled: shutterDisabled || blocked,
|
|
666
|
+
onPress: onShutter
|
|
667
|
+
}
|
|
668
|
+
),
|
|
669
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex w-16 justify-end", children: engine.onFlipCamera ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
670
|
+
"button",
|
|
671
|
+
{
|
|
672
|
+
type: "button",
|
|
673
|
+
onClick: engine.onFlipCamera,
|
|
674
|
+
"aria-label": "Switch camera",
|
|
675
|
+
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",
|
|
676
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_lucide_react2.RefreshCw, { className: "h-5 w-5" })
|
|
677
|
+
}
|
|
678
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "h-12 w-12" }) })
|
|
679
|
+
] })
|
|
680
|
+
] })
|
|
681
|
+
] }),
|
|
682
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
683
|
+
OptionsGridPanel,
|
|
684
|
+
{
|
|
685
|
+
open: optionsOpen && !controlsHidden,
|
|
686
|
+
onClose: () => setOptionsOpen(false),
|
|
687
|
+
tiles
|
|
688
|
+
}
|
|
689
|
+
),
|
|
690
|
+
blocked && blockedSheet && !blockedDismissed && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
691
|
+
CaptureSheet,
|
|
692
|
+
{
|
|
693
|
+
open: true,
|
|
694
|
+
onClose: () => setBlockedDismissed(true),
|
|
695
|
+
body: blockedSheet.body,
|
|
696
|
+
title: "Camera unavailable",
|
|
697
|
+
actions: blockedSheet.actions
|
|
698
|
+
}
|
|
699
|
+
),
|
|
700
|
+
slots.overlays
|
|
701
|
+
] });
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// src/components/ImageEditSheet.tsx
|
|
705
|
+
var import_react3 = require("react");
|
|
706
|
+
var import_lucide_react3 = require("lucide-react");
|
|
707
|
+
var import_jsx_runtime9 = require("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] = (0, import_react3.useState)(0);
|
|
723
|
+
const [flipped, setFlipped] = (0, import_react3.useState)(false);
|
|
724
|
+
const [aspect, setAspect] = (0, import_react3.useState)("free");
|
|
725
|
+
const [crop, setCrop] = (0, import_react3.useState)(FULL_CROP);
|
|
726
|
+
const [saving, setSaving] = (0, import_react3.useState)(false);
|
|
727
|
+
const stageRef = (0, import_react3.useRef)(null);
|
|
728
|
+
const imgRef = (0, import_react3.useRef)(null);
|
|
729
|
+
const dragRef = (0, import_react3.useRef)(null);
|
|
730
|
+
(0, import_react3.useEffect)(() => {
|
|
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 = (0, import_react3.useCallback)((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 = (0, import_react3.useCallback)(
|
|
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 = (0, import_react3.useCallback)(
|
|
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 = (0, import_react3.useCallback)(() => {
|
|
811
|
+
dragRef.current = null;
|
|
812
|
+
}, []);
|
|
813
|
+
const save = (0, import_react3.useCallback)(() => {
|
|
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__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "absolute inset-0 z-50 flex flex-col bg-black", children: [
|
|
851
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex shrink-0 items-center justify-between px-4 pt-safe", children: [
|
|
852
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
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__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react3.X, { className: "h-5 w-5" }),
|
|
861
|
+
"Cancel"
|
|
862
|
+
]
|
|
863
|
+
}
|
|
864
|
+
),
|
|
865
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "text-[15px] font-semibold text-white/90", children: "Edit" }),
|
|
866
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
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__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react3.Check, { className: "h-5 w-5" }),
|
|
876
|
+
"Save"
|
|
877
|
+
]
|
|
878
|
+
}
|
|
879
|
+
)
|
|
880
|
+
] }),
|
|
881
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
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__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "relative max-h-full max-w-full", children: [
|
|
890
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
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__ */ (0, import_jsx_runtime9.jsx)(
|
|
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__ */ (0, import_jsx_runtime9.jsx)(
|
|
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__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "shrink-0 pb-safe", children: [
|
|
937
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "flex items-center justify-center gap-2 pb-2", children: ASPECTS.map((a) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
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__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex items-center justify-center gap-6 pb-4", children: [
|
|
952
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
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__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react3.RotateCcw, { className: "h-5 w-5" })
|
|
964
|
+
}
|
|
965
|
+
),
|
|
966
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
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__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react3.FlipHorizontal2, { className: "h-5 w-5" })
|
|
978
|
+
}
|
|
979
|
+
)
|
|
980
|
+
] })
|
|
981
|
+
] })
|
|
982
|
+
] });
|
|
983
|
+
}
|
|
984
|
+
//# sourceMappingURL=react.cjs.map
|