@azx-pbc/axiom-web 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +161 -2
- package/dist/address.d.ts +32 -0
- package/dist/address.d.ts.map +1 -0
- package/dist/address.js +146 -0
- package/dist/address.js.map +1 -0
- package/dist/capture/MediaCapture.d.ts +45 -0
- package/dist/capture/MediaCapture.d.ts.map +1 -0
- package/dist/capture/MediaCapture.js +669 -0
- package/dist/capture/MediaCapture.js.map +1 -0
- package/dist/capture/SignatureCapture.d.ts +31 -0
- package/dist/capture/SignatureCapture.d.ts.map +1 -0
- package/dist/capture/SignatureCapture.js +329 -0
- package/dist/capture/SignatureCapture.js.map +1 -0
- package/dist/capture/copy.d.ts +101 -0
- package/dist/capture/copy.d.ts.map +1 -0
- package/dist/capture/copy.js +1369 -0
- package/dist/capture/copy.js.map +1 -0
- package/dist/capture/index.d.ts +19 -0
- package/dist/capture/index.d.ts.map +1 -0
- package/dist/capture/index.js +14 -0
- package/dist/capture/index.js.map +1 -0
- package/dist/capture/media-kind.d.ts +16 -0
- package/dist/capture/media-kind.d.ts.map +1 -0
- package/dist/capture/media-kind.js +64 -0
- package/dist/capture/media-kind.js.map +1 -0
- package/dist/capture/permissions.d.ts +109 -0
- package/dist/capture/permissions.d.ts.map +1 -0
- package/dist/capture/permissions.js +172 -0
- package/dist/capture/permissions.js.map +1 -0
- package/dist/capture/refusal.d.ts +13 -0
- package/dist/capture/refusal.d.ts.map +1 -0
- package/dist/capture/refusal.js +16 -0
- package/dist/capture/refusal.js.map +1 -0
- package/dist/controls.d.ts +64 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +2524 -0
- package/dist/controls.js.map +1 -0
- package/dist/coordinate.d.ts +38 -0
- package/dist/coordinate.d.ts.map +1 -0
- package/dist/coordinate.js +220 -0
- package/dist/coordinate.js.map +1 -0
- package/dist/copy.d.ts +313 -0
- package/dist/copy.d.ts.map +1 -0
- package/dist/copy.js +2602 -0
- package/dist/copy.js.map +1 -0
- package/dist/countries.d.ts +14 -0
- package/dist/countries.d.ts.map +1 -0
- package/dist/countries.js +264 -0
- package/dist/countries.js.map +1 -0
- package/dist/format/calendar-locale.d.ts +19 -0
- package/dist/format/calendar-locale.d.ts.map +1 -0
- package/dist/format/calendar-locale.js +38 -0
- package/dist/format/calendar-locale.js.map +1 -0
- package/dist/format/country-names.d.ts +21 -0
- package/dist/format/country-names.d.ts.map +1 -0
- package/dist/format/country-names.js +2277 -0
- package/dist/format/country-names.js.map +1 -0
- package/dist/format/date.d.ts +58 -0
- package/dist/format/date.d.ts.map +1 -0
- package/dist/format/date.js +155 -0
- package/dist/format/date.js.map +1 -0
- package/dist/format/digits.d.ts +23 -0
- package/dist/format/digits.d.ts.map +1 -0
- package/dist/format/digits.js +46 -0
- package/dist/format/digits.js.map +1 -0
- package/dist/format/index.d.ts +28 -0
- package/dist/format/index.d.ts.map +1 -0
- package/dist/format/index.js +24 -0
- package/dist/format/index.js.map +1 -0
- package/dist/format/invariant.d.ts +8 -0
- package/dist/format/invariant.d.ts.map +1 -0
- package/dist/format/invariant.js +10 -0
- package/dist/format/invariant.js.map +1 -0
- package/dist/format/locale.d.ts +33 -0
- package/dist/format/locale.d.ts.map +1 -0
- package/dist/format/locale.js +39 -0
- package/dist/format/locale.js.map +1 -0
- package/dist/format/media-type.d.ts +8 -0
- package/dist/format/media-type.d.ts.map +1 -0
- package/dist/format/media-type.js +302 -0
- package/dist/format/media-type.js.map +1 -0
- package/dist/format/money.d.ts +52 -0
- package/dist/format/money.d.ts.map +1 -0
- package/dist/format/money.js +36 -0
- package/dist/format/money.js.map +1 -0
- package/dist/format/number.d.ts +28 -0
- package/dist/format/number.d.ts.map +1 -0
- package/dist/format/number.js +91 -0
- package/dist/format/number.js.map +1 -0
- package/dist/host.d.ts +122 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +20 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/media.d.ts +42 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +151 -0
- package/dist/media.js.map +1 -0
- package/dist/pickers/DatePicker.d.ts +35 -0
- package/dist/pickers/DatePicker.d.ts.map +1 -0
- package/dist/pickers/DatePicker.js +212 -0
- package/dist/pickers/DatePicker.js.map +1 -0
- package/dist/pickers/TimeSegments.d.ts +27 -0
- package/dist/pickers/TimeSegments.d.ts.map +1 -0
- package/dist/pickers/TimeSegments.js +82 -0
- package/dist/pickers/TimeSegments.js.map +1 -0
- package/dist/pickers/day-picker-locale.d.ts +15 -0
- package/dist/pickers/day-picker-locale.d.ts.map +1 -0
- package/dist/pickers/day-picker-locale.js +46 -0
- package/dist/pickers/day-picker-locale.js.map +1 -0
- package/dist/render/dom.d.ts +100 -0
- package/dist/render/dom.d.ts.map +1 -0
- package/dist/render/dom.js +882 -0
- package/dist/render/dom.js.map +1 -0
- package/dist/render/layout.d.ts +45 -0
- package/dist/render/layout.d.ts.map +1 -0
- package/dist/render/layout.js +8 -0
- package/dist/render/layout.js.map +1 -0
- package/dist/schedule/SchedulePicker.d.ts +46 -0
- package/dist/schedule/SchedulePicker.d.ts.map +1 -0
- package/dist/schedule/SchedulePicker.js +160 -0
- package/dist/schedule/SchedulePicker.js.map +1 -0
- package/dist/schedule/timeslot.d.ts +52 -0
- package/dist/schedule/timeslot.d.ts.map +1 -0
- package/dist/schedule/timeslot.js +265 -0
- package/dist/schedule/timeslot.js.map +1 -0
- package/dist/styles.css +2151 -0
- package/dist/theme/index.d.ts +12 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +11 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/presets.d.ts +93 -0
- package/dist/theme/presets.d.ts.map +1 -0
- package/dist/theme/presets.js +200 -0
- package/dist/theme/presets.js.map +1 -0
- package/dist/tokens.css +234 -0
- package/dist/wizard-checkpoints.d.ts +18 -0
- package/dist/wizard-checkpoints.d.ts.map +1 -0
- package/dist/wizard-checkpoints.js +56 -0
- package/dist/wizard-checkpoints.js.map +1 -0
- package/package.json +76 -3
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* One capture panel for a `media_ref`: live camera or microphone, a recording, or a file.
|
|
4
|
+
*
|
|
5
|
+
* The panel owns no storage and no digest. It produces a `Blob` and a filename, hands them to the
|
|
6
|
+
* host's `store`, and paints the `media_ref` the host returns. Permission is asked only from the
|
|
7
|
+
* reader's own "Use camera" or "Use microphone" action; the sentence beside that button says what
|
|
8
|
+
* the browser is about to request and why. Every refusal is a state with words, the file picker
|
|
9
|
+
* stays available in all of them, and no stream outlives the panel.
|
|
10
|
+
*/
|
|
11
|
+
import { MEDIA_EXTENSION_TYPES, mediaAcceptMatches } from '@azx-pbc/axiom-runtime';
|
|
12
|
+
import { useCallback, useEffect, useId, useRef, useState } from 'react';
|
|
13
|
+
import { humanSize, mediaDisplayLine } from '../media.js';
|
|
14
|
+
import { useLocale } from '../host.js';
|
|
15
|
+
import { captureMessages } from './copy.js';
|
|
16
|
+
import { captureKinds, fileAccept, hasLiveSource } from './media-kind.js';
|
|
17
|
+
import { RECORDER_CANDIDATES, baseMimeType, browserCapturePlatform, cameraCount, forgetCaptureOutcome, rememberCaptureOutcome, rememberedCaptureOutcome, requestDevice, stopStream, } from './permissions.js';
|
|
18
|
+
/** A duration as `m:ss`, the reading a recorder states. */
|
|
19
|
+
export function elapsedText(milliseconds) {
|
|
20
|
+
const total = Math.max(0, Math.floor(milliseconds / 1000));
|
|
21
|
+
const minutes = Math.floor(total / 60);
|
|
22
|
+
const seconds = total % 60;
|
|
23
|
+
return `${String(minutes)}:${String(seconds).padStart(2, '0')}`;
|
|
24
|
+
}
|
|
25
|
+
/** The device one live kind needs. A video needs both; the camera is the one that prompts. */
|
|
26
|
+
function deviceOf(kind) {
|
|
27
|
+
return kind === 'audio' ? 'microphone' : 'camera';
|
|
28
|
+
}
|
|
29
|
+
/** A remembered outcome as the refusal view's shape, without a stream. */
|
|
30
|
+
function permissionOfKind(kind) {
|
|
31
|
+
switch (kind) {
|
|
32
|
+
case 'granted':
|
|
33
|
+
return { kind: 'error' };
|
|
34
|
+
case 'error':
|
|
35
|
+
return { kind: 'error' };
|
|
36
|
+
default:
|
|
37
|
+
return { kind };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** The media type a file states, or the type its extension denotes through the closed table. */
|
|
41
|
+
function mimeOfFile(file) {
|
|
42
|
+
const stated = baseMimeType(file.type);
|
|
43
|
+
if (stated !== '')
|
|
44
|
+
return stated;
|
|
45
|
+
const dot = file.name.lastIndexOf('.');
|
|
46
|
+
if (dot === -1)
|
|
47
|
+
return '';
|
|
48
|
+
return MEDIA_EXTENSION_TYPES.get(file.name.slice(dot).toLowerCase()) ?? '';
|
|
49
|
+
}
|
|
50
|
+
/** The file extension a recorder's media type implies, so the named file matches its bytes. */
|
|
51
|
+
function extensionForMime(mime) {
|
|
52
|
+
if (mime.includes('webm'))
|
|
53
|
+
return 'webm';
|
|
54
|
+
if (mime.includes('mp4') || mime.includes('quicktime'))
|
|
55
|
+
return 'mp4';
|
|
56
|
+
if (mime.includes('ogg'))
|
|
57
|
+
return 'ogg';
|
|
58
|
+
if (mime.includes('wav'))
|
|
59
|
+
return 'wav';
|
|
60
|
+
if (mime.includes('mpeg'))
|
|
61
|
+
return 'mp3';
|
|
62
|
+
return 'bin';
|
|
63
|
+
}
|
|
64
|
+
/** The kind a media type belongs to, for the preview and the noun. */
|
|
65
|
+
function kindOfMime(mime, fallback) {
|
|
66
|
+
if (mime.startsWith('image/'))
|
|
67
|
+
return 'image';
|
|
68
|
+
if (mime.startsWith('audio/'))
|
|
69
|
+
return 'audio';
|
|
70
|
+
if (mime.startsWith('video/'))
|
|
71
|
+
return 'video';
|
|
72
|
+
return fallback;
|
|
73
|
+
}
|
|
74
|
+
/** The host's stated reason for an error-shaped value, when it carried one. */
|
|
75
|
+
function detailOf(error) {
|
|
76
|
+
if (error instanceof Error && error.message !== '')
|
|
77
|
+
return error.message;
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* One capture panel.
|
|
82
|
+
*
|
|
83
|
+
* The state machine is the visible surface: choosing, requesting, refused, live, recording,
|
|
84
|
+
* review, saving, captured and error. Only `requesting` calls `getUserMedia`, and only an event
|
|
85
|
+
* handler can enter it; there is no effect that opens a device on mount.
|
|
86
|
+
*/
|
|
87
|
+
export function MediaCapture(props) {
|
|
88
|
+
const { name, description, accept, minBytes, maxBytes, required = false, error, disabled = false, platform: suppliedPlatform, messages: overrides, store, onCaptured, onCancel, } = props;
|
|
89
|
+
const locale = useLocale();
|
|
90
|
+
const messages = captureMessages(locale, overrides);
|
|
91
|
+
const platform = suppliedPlatform ?? browserCapturePlatform();
|
|
92
|
+
const kinds = captureKinds(accept);
|
|
93
|
+
const cameraAdmitted = accept === undefined || accept.length === 0 || mediaAcceptMatches(accept, 'image/jpeg');
|
|
94
|
+
const admittedRecorderMime = (live) => {
|
|
95
|
+
const candidate = platform.recorderMime(live, accept);
|
|
96
|
+
if (candidate === undefined)
|
|
97
|
+
return undefined;
|
|
98
|
+
const base = baseMimeType(candidate);
|
|
99
|
+
if (accept !== undefined && accept.length > 0 && !mediaAcceptMatches(accept, base)) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
return candidate;
|
|
103
|
+
};
|
|
104
|
+
const declarationAdmitsRecorder = (live) => accept === undefined ||
|
|
105
|
+
accept.length === 0 ||
|
|
106
|
+
RECORDER_CANDIDATES[live].some((candidate) => mediaAcceptMatches(accept, baseMimeType(candidate)));
|
|
107
|
+
const liveKinds = kinds.filter(hasLiveSource).filter((live) => {
|
|
108
|
+
if (live === 'image')
|
|
109
|
+
return cameraAdmitted;
|
|
110
|
+
if (admittedRecorderMime(live) !== undefined)
|
|
111
|
+
return true;
|
|
112
|
+
// When the platform cannot record at all, keep the disabled affordance with its browser-support
|
|
113
|
+
// guidance only if the declaration actually admits a recorder format.
|
|
114
|
+
return platform.recorderMime(live) === undefined && declarationAdmitsRecorder(live);
|
|
115
|
+
});
|
|
116
|
+
const baseId = useId();
|
|
117
|
+
const legendId = `${baseId}-legend`;
|
|
118
|
+
const descriptionId = `${baseId}-description`;
|
|
119
|
+
const fileId = `${baseId}-file`;
|
|
120
|
+
const permissionId = `${baseId}-permission`;
|
|
121
|
+
const recordingId = `${baseId}-recording`;
|
|
122
|
+
const [view, setView] = useState({ kind: 'choosing' });
|
|
123
|
+
const [stream, setStream] = useState(null);
|
|
124
|
+
const [cameraReady, setCameraReady] = useState(false);
|
|
125
|
+
const streamRef = useRef(null);
|
|
126
|
+
const videoRef = useRef(null);
|
|
127
|
+
const panelRef = useRef(null);
|
|
128
|
+
const previousKindRef = useRef('choosing');
|
|
129
|
+
const recorderRef = useRef(null);
|
|
130
|
+
const timerRef = useRef(undefined);
|
|
131
|
+
const elapsedRef = useRef(0);
|
|
132
|
+
const urlRef = useRef(undefined);
|
|
133
|
+
/** Whether the panel is still mounted; a permission prompt can resolve after an unmount. */
|
|
134
|
+
const mountedRef = useRef(true);
|
|
135
|
+
const chunksRef = useRef([]);
|
|
136
|
+
const clearTimer = () => {
|
|
137
|
+
if (timerRef.current !== undefined) {
|
|
138
|
+
window.clearInterval(timerRef.current);
|
|
139
|
+
timerRef.current = undefined;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const releaseStream = () => {
|
|
143
|
+
stopStream(streamRef.current ?? undefined);
|
|
144
|
+
streamRef.current = null;
|
|
145
|
+
setStream(null);
|
|
146
|
+
setCameraReady(false);
|
|
147
|
+
};
|
|
148
|
+
const releaseUrl = () => {
|
|
149
|
+
if (urlRef.current !== undefined) {
|
|
150
|
+
URL.revokeObjectURL(urlRef.current);
|
|
151
|
+
urlRef.current = undefined;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
/** Stop a recorder that is still running, without letting its `stop` paint a closed panel. */
|
|
155
|
+
const stopRecorder = () => {
|
|
156
|
+
const recorder = recorderRef.current;
|
|
157
|
+
recorderRef.current = null;
|
|
158
|
+
if (recorder === null || recorder.state === 'inactive')
|
|
159
|
+
return;
|
|
160
|
+
recorder.ondataavailable = null;
|
|
161
|
+
recorder.onstop = null;
|
|
162
|
+
recorder.onerror = null;
|
|
163
|
+
try {
|
|
164
|
+
recorder.stop();
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
// A recorder that already ended is the state this function exists to reach.
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
const stopEverything = () => {
|
|
171
|
+
clearTimer();
|
|
172
|
+
stopRecorder();
|
|
173
|
+
releaseStream();
|
|
174
|
+
};
|
|
175
|
+
// The panel's lifetime, not a state transition, owns the release: a close, a route change and
|
|
176
|
+
// an unmount all take the same path, and no track outlives the element that showed it. Re-arming
|
|
177
|
+
// `mountedRef` in the effect body preserves liveness across React StrictMode's effect replay.
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
mountedRef.current = true;
|
|
180
|
+
return () => {
|
|
181
|
+
// A prompt the reader left open can grant after this cleanup has run, so the async
|
|
182
|
+
// acquisition reads this before it stores a track nobody will release.
|
|
183
|
+
mountedRef.current = false;
|
|
184
|
+
if (timerRef.current !== undefined) {
|
|
185
|
+
window.clearInterval(timerRef.current);
|
|
186
|
+
timerRef.current = undefined;
|
|
187
|
+
}
|
|
188
|
+
const recorder = recorderRef.current;
|
|
189
|
+
recorderRef.current = null;
|
|
190
|
+
if (recorder !== null && recorder.state !== 'inactive') {
|
|
191
|
+
recorder.ondataavailable = null;
|
|
192
|
+
recorder.onstop = null;
|
|
193
|
+
recorder.onerror = null;
|
|
194
|
+
try {
|
|
195
|
+
recorder.stop();
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
// Already stopped.
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const active = streamRef.current;
|
|
202
|
+
if (active !== null) {
|
|
203
|
+
for (const track of active.getTracks()) {
|
|
204
|
+
try {
|
|
205
|
+
track.stop();
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// A track that is already ended is the state this cleanup exists to reach.
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
streamRef.current = null;
|
|
213
|
+
if (urlRef.current !== undefined) {
|
|
214
|
+
URL.revokeObjectURL(urlRef.current);
|
|
215
|
+
urlRef.current = undefined;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}, [timerRef, streamRef, urlRef]);
|
|
219
|
+
// A state change removes the control the reader just pressed. Moving focus to the group keeps
|
|
220
|
+
// the new state announced instead of dropping focus onto the document body; the initial
|
|
221
|
+
// choosing panel is left alone so mounting the dialog does not steal focus from the page.
|
|
222
|
+
useEffect(() => {
|
|
223
|
+
if (previousKindRef.current !== view.kind && view.kind !== 'choosing') {
|
|
224
|
+
panelRef.current?.focus();
|
|
225
|
+
}
|
|
226
|
+
previousKindRef.current = view.kind;
|
|
227
|
+
}, [view.kind]);
|
|
228
|
+
// The callback ref is memoised on `stream`, so React re-attaches only when the stream changes or
|
|
229
|
+
// when the `<video>` element mounts across the live and recording branches, never on unrelated
|
|
230
|
+
// renders such as metadata events or 250 ms recording timer ticks.
|
|
231
|
+
const attachVideo = useCallback((node) => {
|
|
232
|
+
videoRef.current = node;
|
|
233
|
+
if (node === null)
|
|
234
|
+
return;
|
|
235
|
+
if (stream === null) {
|
|
236
|
+
node.srcObject = null;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (node.srcObject !== stream) {
|
|
240
|
+
node.srcObject = stream;
|
|
241
|
+
const played = node.play();
|
|
242
|
+
if (played !== undefined)
|
|
243
|
+
void played.catch(() => undefined);
|
|
244
|
+
}
|
|
245
|
+
}, [stream]);
|
|
246
|
+
const reset = () => {
|
|
247
|
+
stopEverything();
|
|
248
|
+
releaseUrl();
|
|
249
|
+
setView({ kind: 'choosing' });
|
|
250
|
+
};
|
|
251
|
+
const cancel = () => {
|
|
252
|
+
stopEverything();
|
|
253
|
+
releaseUrl();
|
|
254
|
+
setView({ kind: 'choosing' });
|
|
255
|
+
onCancel?.();
|
|
256
|
+
};
|
|
257
|
+
const askLive = async (live, facing) => {
|
|
258
|
+
const device = deviceOf(live);
|
|
259
|
+
const remembered = rememberedCaptureOutcome(device);
|
|
260
|
+
if (remembered !== undefined && remembered !== 'granted') {
|
|
261
|
+
setView({ kind: 'refused', device, live, permission: permissionOfKind(remembered) });
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
setView({ kind: 'requesting', device, live });
|
|
265
|
+
const permission = await requestDevice(platform, device, facing, live === 'video');
|
|
266
|
+
if (!mountedRef.current) {
|
|
267
|
+
// The panel went away while the permission prompt was open. Nothing will ever release a
|
|
268
|
+
// granted stream, so release it here and write no state to an unmounted tree.
|
|
269
|
+
if (permission.kind === 'granted')
|
|
270
|
+
stopStream(permission.stream);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
rememberCaptureOutcome(device, permission.kind);
|
|
274
|
+
if (live === 'video')
|
|
275
|
+
rememberCaptureOutcome('microphone', permission.kind);
|
|
276
|
+
if (permission.kind !== 'granted') {
|
|
277
|
+
setView({ kind: 'refused', device, live, permission });
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
stopStream(streamRef.current ?? undefined);
|
|
281
|
+
streamRef.current = permission.stream;
|
|
282
|
+
setStream(permission.stream);
|
|
283
|
+
setCameraReady(live === 'audio');
|
|
284
|
+
const cameras = live === 'image' || live === 'video' ? await cameraCount(platform) : 0;
|
|
285
|
+
if (!mountedRef.current) {
|
|
286
|
+
stopStream(streamRef.current ?? undefined);
|
|
287
|
+
streamRef.current = null;
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
setView({ kind: 'live', live, facing, cameras });
|
|
291
|
+
};
|
|
292
|
+
const askAgain = (live, facing) => {
|
|
293
|
+
forgetCaptureOutcome(deviceOf(live));
|
|
294
|
+
void askLive(live, facing);
|
|
295
|
+
};
|
|
296
|
+
const startRecording = (live, facing) => {
|
|
297
|
+
const streamNow = streamRef.current;
|
|
298
|
+
if (streamNow === null) {
|
|
299
|
+
void askLive(live, facing);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const recorderType = admittedRecorderMime(live);
|
|
303
|
+
if (recorderType === undefined) {
|
|
304
|
+
releaseStream();
|
|
305
|
+
setView({
|
|
306
|
+
kind: 'refused',
|
|
307
|
+
device: deviceOf(live),
|
|
308
|
+
live,
|
|
309
|
+
permission: { kind: 'unsupported' },
|
|
310
|
+
});
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const mime = baseMimeType(recorderType);
|
|
314
|
+
const fileName = `recording.${extensionForMime(mime)}`;
|
|
315
|
+
chunksRef.current = [];
|
|
316
|
+
let recordedBytes = 0;
|
|
317
|
+
let refusedByLimit = false;
|
|
318
|
+
let recorder;
|
|
319
|
+
try {
|
|
320
|
+
recorder = platform.createRecorder(streamNow, recorderType);
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
releaseStream();
|
|
324
|
+
setView({
|
|
325
|
+
kind: 'refused',
|
|
326
|
+
device: deviceOf(live),
|
|
327
|
+
live,
|
|
328
|
+
permission: { kind: 'unsupported' },
|
|
329
|
+
});
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const kind = live;
|
|
333
|
+
elapsedRef.current = 0;
|
|
334
|
+
recorder.ondataavailable = (event) => {
|
|
335
|
+
if (!mountedRef.current || refusedByLimit)
|
|
336
|
+
return;
|
|
337
|
+
if (event.data.size === 0)
|
|
338
|
+
return;
|
|
339
|
+
chunksRef.current.push(event.data);
|
|
340
|
+
recordedBytes += event.data.size;
|
|
341
|
+
if (maxBytes !== undefined && recordedBytes > maxBytes) {
|
|
342
|
+
// The declaration refuses this recording already; stop before a longer one is written, and
|
|
343
|
+
// detach the recorder callbacks so the async `stop` event cannot overwrite this refusal.
|
|
344
|
+
refusedByLimit = true;
|
|
345
|
+
clearTimer();
|
|
346
|
+
recorder.ondataavailable = null;
|
|
347
|
+
recorder.onstop = null;
|
|
348
|
+
recorder.onerror = null;
|
|
349
|
+
recorderRef.current = null;
|
|
350
|
+
chunksRef.current = [];
|
|
351
|
+
try {
|
|
352
|
+
recorder.stop();
|
|
353
|
+
}
|
|
354
|
+
catch {
|
|
355
|
+
// A recorder that already ended is the state this branch exists to reach.
|
|
356
|
+
}
|
|
357
|
+
const sentence = messages.fileTooLarge(fileName, humanSize(recordedBytes, locale), humanSize(maxBytes, locale));
|
|
358
|
+
releaseStream();
|
|
359
|
+
setView({ kind: 'error', sentence });
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
recorder.onerror = () => {
|
|
363
|
+
if (!mountedRef.current || refusedByLimit)
|
|
364
|
+
return;
|
|
365
|
+
clearTimer();
|
|
366
|
+
recorderRef.current = null;
|
|
367
|
+
chunksRef.current = [];
|
|
368
|
+
releaseStream();
|
|
369
|
+
setView({ kind: 'error', sentence: messages.recorderStopped });
|
|
370
|
+
};
|
|
371
|
+
recorder.onstop = () => {
|
|
372
|
+
if (!mountedRef.current || refusedByLimit)
|
|
373
|
+
return;
|
|
374
|
+
clearTimer();
|
|
375
|
+
recorderRef.current = null;
|
|
376
|
+
const durationMs = elapsedRef.current;
|
|
377
|
+
const blob = new Blob(chunksRef.current, { type: mime });
|
|
378
|
+
chunksRef.current = [];
|
|
379
|
+
releaseStream();
|
|
380
|
+
if (blob.size === 0) {
|
|
381
|
+
setView({ kind: 'error', sentence: messages.emptyCapture });
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
releaseUrl();
|
|
385
|
+
const url = URL.createObjectURL(blob);
|
|
386
|
+
urlRef.current = url;
|
|
387
|
+
setView({
|
|
388
|
+
kind: 'review',
|
|
389
|
+
review: {
|
|
390
|
+
mediaKind: kind,
|
|
391
|
+
blob,
|
|
392
|
+
url,
|
|
393
|
+
mime,
|
|
394
|
+
fileName,
|
|
395
|
+
source: 'recorder',
|
|
396
|
+
durationMs,
|
|
397
|
+
},
|
|
398
|
+
});
|
|
399
|
+
};
|
|
400
|
+
recorderRef.current = recorder;
|
|
401
|
+
try {
|
|
402
|
+
recorder.start(250);
|
|
403
|
+
}
|
|
404
|
+
catch {
|
|
405
|
+
recorderRef.current = null;
|
|
406
|
+
releaseStream();
|
|
407
|
+
setView({ kind: 'error', sentence: messages.recorderFailedToStart });
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
setView({ kind: 'recording', live, elapsedMs: 0 });
|
|
411
|
+
timerRef.current = window.setInterval(() => {
|
|
412
|
+
elapsedRef.current += 250;
|
|
413
|
+
setView((current) => current.kind === 'recording' ? { ...current, elapsedMs: elapsedRef.current } : current);
|
|
414
|
+
}, 250);
|
|
415
|
+
};
|
|
416
|
+
const stopRecording = () => {
|
|
417
|
+
clearTimer();
|
|
418
|
+
recorderRef.current?.stop();
|
|
419
|
+
recorderRef.current = null;
|
|
420
|
+
};
|
|
421
|
+
const switchCamera = async (live, facing) => {
|
|
422
|
+
const next = facing === 'environment' ? 'user' : 'environment';
|
|
423
|
+
releaseStream();
|
|
424
|
+
const permission = await requestDevice(platform, 'camera', next, live === 'video');
|
|
425
|
+
if (!mountedRef.current) {
|
|
426
|
+
if (permission.kind === 'granted')
|
|
427
|
+
stopStream(permission.stream);
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
rememberCaptureOutcome('camera', permission.kind);
|
|
431
|
+
if (permission.kind !== 'granted') {
|
|
432
|
+
setView({ kind: 'refused', device: 'camera', live, permission });
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
stopStream(streamRef.current ?? undefined);
|
|
436
|
+
streamRef.current = permission.stream;
|
|
437
|
+
setStream(permission.stream);
|
|
438
|
+
setCameraReady(false);
|
|
439
|
+
const cameras = await cameraCount(platform);
|
|
440
|
+
if (!mountedRef.current) {
|
|
441
|
+
stopStream(streamRef.current ?? undefined);
|
|
442
|
+
streamRef.current = null;
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
setView({ kind: 'live', live, facing: next, cameras });
|
|
446
|
+
};
|
|
447
|
+
const takePhoto = (facing) => {
|
|
448
|
+
const video = videoRef.current;
|
|
449
|
+
if (video === null || streamRef.current === null) {
|
|
450
|
+
setView({ kind: 'error', sentence: messages.cameraNotReady });
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const width = video.videoWidth === 0 ? 1280 : video.videoWidth;
|
|
454
|
+
const height = video.videoHeight === 0 ? 720 : video.videoHeight;
|
|
455
|
+
const canvas = document.createElement('canvas');
|
|
456
|
+
canvas.width = width;
|
|
457
|
+
canvas.height = height;
|
|
458
|
+
const context = canvas.getContext('2d');
|
|
459
|
+
if (context === null) {
|
|
460
|
+
setView({ kind: 'error', sentence: messages.imageNotDrawn });
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
context.drawImage(video, 0, 0, width, height);
|
|
464
|
+
const finish = (blob) => {
|
|
465
|
+
if (blob === null) {
|
|
466
|
+
if (!mountedRef.current) {
|
|
467
|
+
stopStream(streamRef.current ?? undefined);
|
|
468
|
+
streamRef.current = null;
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
releaseStream();
|
|
472
|
+
setView({ kind: 'error', sentence: messages.emptyCapture });
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
const url = URL.createObjectURL(blob);
|
|
476
|
+
if (!mountedRef.current) {
|
|
477
|
+
// The panel unmounted while `canvas.toBlob` was encoding; release both the stream and the
|
|
478
|
+
// object URL immediately without writing state to an unmounted tree.
|
|
479
|
+
stopStream(streamRef.current ?? undefined);
|
|
480
|
+
streamRef.current = null;
|
|
481
|
+
URL.revokeObjectURL(url);
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
releaseStream();
|
|
485
|
+
releaseUrl();
|
|
486
|
+
urlRef.current = url;
|
|
487
|
+
setView({
|
|
488
|
+
kind: 'review',
|
|
489
|
+
review: {
|
|
490
|
+
mediaKind: 'image',
|
|
491
|
+
blob,
|
|
492
|
+
url,
|
|
493
|
+
mime: blob.type === '' ? 'image/jpeg' : baseMimeType(blob.type),
|
|
494
|
+
fileName: facing === 'user' ? 'selfie.jpg' : 'photo.jpg',
|
|
495
|
+
source: 'camera',
|
|
496
|
+
},
|
|
497
|
+
});
|
|
498
|
+
};
|
|
499
|
+
if (typeof canvas.toBlob === 'function') {
|
|
500
|
+
canvas.toBlob(finish, 'image/jpeg', 0.92);
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
finish(null);
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
/**
|
|
507
|
+
* Why these bytes are outside the declaration, in words a reader can act on.
|
|
508
|
+
*
|
|
509
|
+
* The same check runs for a chosen file and for a photo or recording the platform produced,
|
|
510
|
+
* so a camera capture cannot upload bytes the declaration already refuses. The adapter repeats
|
|
511
|
+
* the check on the reference it receives; this is the earlier refusal the declaration entitles
|
|
512
|
+
* the panel to make.
|
|
513
|
+
*/
|
|
514
|
+
const declaredRefusal = (bytes, mime, fileName) => {
|
|
515
|
+
if (accept !== undefined &&
|
|
516
|
+
accept.length > 0 &&
|
|
517
|
+
(mime === '' || !mediaAcceptMatches(accept, mime))) {
|
|
518
|
+
return messages.fileTypeRefused(fileName, mime, accept);
|
|
519
|
+
}
|
|
520
|
+
if (maxBytes !== undefined && bytes > maxBytes) {
|
|
521
|
+
return messages.fileTooLarge(fileName, humanSize(bytes, locale), humanSize(maxBytes, locale));
|
|
522
|
+
}
|
|
523
|
+
if (minBytes !== undefined && bytes < minBytes) {
|
|
524
|
+
return messages.fileTooSmall(fileName, humanSize(bytes, locale), humanSize(minBytes, locale));
|
|
525
|
+
}
|
|
526
|
+
if (mime === '')
|
|
527
|
+
return messages.fileUnreadable(fileName);
|
|
528
|
+
return undefined;
|
|
529
|
+
};
|
|
530
|
+
const chooseFile = async (event) => {
|
|
531
|
+
const input = event.currentTarget;
|
|
532
|
+
const file = input.files?.[0];
|
|
533
|
+
// The same path may be chosen again after a refusal; a cleared value is what allows it.
|
|
534
|
+
input.value = '';
|
|
535
|
+
if (file === undefined)
|
|
536
|
+
return;
|
|
537
|
+
const mime = mimeOfFile(file);
|
|
538
|
+
const refused = declaredRefusal(file.size, mime, file.name);
|
|
539
|
+
if (refused !== undefined) {
|
|
540
|
+
setView({ kind: 'error', sentence: refused });
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
releaseUrl();
|
|
544
|
+
const url = URL.createObjectURL(file);
|
|
545
|
+
urlRef.current = url;
|
|
546
|
+
const inferred = kinds.find((kind) => kind !== 'file') ?? 'file';
|
|
547
|
+
setView({
|
|
548
|
+
kind: 'review',
|
|
549
|
+
review: {
|
|
550
|
+
mediaKind: kindOfMime(mime, inferred),
|
|
551
|
+
blob: file,
|
|
552
|
+
url,
|
|
553
|
+
mime,
|
|
554
|
+
fileName: file.name,
|
|
555
|
+
source: 'files',
|
|
556
|
+
},
|
|
557
|
+
});
|
|
558
|
+
};
|
|
559
|
+
const save = async (review) => {
|
|
560
|
+
const refused = declaredRefusal(review.blob.size, review.mime, review.fileName);
|
|
561
|
+
if (refused !== undefined) {
|
|
562
|
+
setView({ kind: 'error', review, sentence: refused });
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
setView({ kind: 'saving', review });
|
|
566
|
+
try {
|
|
567
|
+
const reference = await store({
|
|
568
|
+
blob: review.blob,
|
|
569
|
+
name: review.fileName,
|
|
570
|
+
mime: review.mime,
|
|
571
|
+
source: review.source,
|
|
572
|
+
...(review.durationMs === undefined ? {} : { durationMs: review.durationMs }),
|
|
573
|
+
});
|
|
574
|
+
if (!mountedRef.current)
|
|
575
|
+
return;
|
|
576
|
+
if (reference === undefined) {
|
|
577
|
+
setView({ kind: 'error', review, sentence: messages.storeFailed() });
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
setView({ kind: 'captured', review, reference });
|
|
581
|
+
onCaptured?.(reference);
|
|
582
|
+
}
|
|
583
|
+
catch (caught) {
|
|
584
|
+
if (!mountedRef.current)
|
|
585
|
+
return;
|
|
586
|
+
const detail = detailOf(caught);
|
|
587
|
+
setView({
|
|
588
|
+
kind: 'error',
|
|
589
|
+
review,
|
|
590
|
+
sentence: messages.storeFailed(),
|
|
591
|
+
...(detail === undefined ? {} : { detail }),
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
const declaredKinds = accept !== undefined && accept.length > 0;
|
|
596
|
+
const fileKind = declaredKinds
|
|
597
|
+
? (kinds.find((kind) => kind !== 'file') ?? 'file')
|
|
598
|
+
: 'file';
|
|
599
|
+
const descriptionText = description ?? messages.mediaIntro(fileKind, name);
|
|
600
|
+
const fileAcceptValue = fileAccept('file', accept);
|
|
601
|
+
const permissionText = (permission, device, live) => {
|
|
602
|
+
switch (permission.kind) {
|
|
603
|
+
case 'denied':
|
|
604
|
+
return messages.permissionDenied(device, live);
|
|
605
|
+
case 'dismissed':
|
|
606
|
+
return messages.permissionDismissed(device, live);
|
|
607
|
+
case 'missing':
|
|
608
|
+
return messages.deviceMissing(device, live);
|
|
609
|
+
case 'busy':
|
|
610
|
+
return messages.deviceBusy(device, live);
|
|
611
|
+
case 'insecure':
|
|
612
|
+
return messages.insecure;
|
|
613
|
+
case 'unsupported':
|
|
614
|
+
return messages.unsupportedRecorder(live);
|
|
615
|
+
case 'error':
|
|
616
|
+
return messages.deviceFailed;
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
const canAskAgain = (permission) => permission.kind === 'denied' ||
|
|
620
|
+
permission.kind === 'dismissed' ||
|
|
621
|
+
permission.kind === 'missing' ||
|
|
622
|
+
permission.kind === 'busy' ||
|
|
623
|
+
permission.kind === 'error';
|
|
624
|
+
const recorderAvailable = (live) => live === 'image' || admittedRecorderMime(live) !== undefined;
|
|
625
|
+
const renderPreview = (review) => {
|
|
626
|
+
switch (review.mediaKind) {
|
|
627
|
+
case 'image':
|
|
628
|
+
return _jsx("img", { className: "ax-capture__preview", src: review.url, alt: "" });
|
|
629
|
+
case 'audio':
|
|
630
|
+
return (_jsx("audio", { className: "ax-capture__preview", src: review.url, controls: true, "aria-label": messages.mediaPlayerLabel(review.mediaKind) }));
|
|
631
|
+
case 'video':
|
|
632
|
+
return (_jsx("video", { className: "ax-capture__preview", src: review.url, controls: true, playsInline: true, "aria-label": messages.mediaPlayerLabel(review.mediaKind) }));
|
|
633
|
+
case 'file':
|
|
634
|
+
return _jsx("p", { className: "ax-capture__file-line", children: review.fileName });
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
const renderLivePreview = (live) => {
|
|
638
|
+
if (live === 'audio')
|
|
639
|
+
return null;
|
|
640
|
+
return (_jsx("video", { ref: attachVideo, className: "ax-capture__live", playsInline: true, muted: true, autoPlay: true, "aria-label": messages.livePreview(live), onLoadedMetadata: () => setCameraReady(true), onCanPlay: () => setCameraReady(true) }));
|
|
641
|
+
};
|
|
642
|
+
return (_jsxs("fieldset", { ref: panelRef, className: "ax-capture", disabled: disabled, "aria-describedby": descriptionId, "data-capture": view.kind, id: legendId, tabIndex: -1, children: [_jsxs("legend", { className: "ax-capture__legend", children: [name, required ? (_jsxs(_Fragment, { children: [' ', _jsx("span", { className: "ax-capture__required", children: messages.requiredMarker })] })) : null] }), _jsx("p", { className: "ax-hint", id: descriptionId, children: descriptionText }), error === undefined ? null : (_jsx("p", { className: "ax-error", role: "alert", children: error })), required ? _jsx("p", { className: "ax-hint", children: messages.required }) : null, view.kind === 'choosing' ? (_jsx("div", { className: "ax-capture__sources", children: liveKinds.map((live) => {
|
|
643
|
+
const device = deviceOf(live);
|
|
644
|
+
const remembersRefusal = rememberedCaptureOutcome(device);
|
|
645
|
+
const available = recorderAvailable(live);
|
|
646
|
+
return (_jsxs("div", { className: "ax-capture__source", children: [_jsx("button", { type: "button", className: "ax-button ax-button--secondary", onClick: () => void askLive(live, 'environment'), disabled: !available, "aria-describedby": `${permissionId}-${live}`, children: messages.startLive(live) }), _jsx("p", { className: "ax-hint", id: `${permissionId}-${live}`, children: available
|
|
647
|
+
? messages.permissionExplanation(device, live, name)
|
|
648
|
+
: messages.unsupportedRecorder(live) }), remembersRefusal === undefined || remembersRefusal === 'granted' ? null : (_jsx("p", { className: "ax-hint", "data-capture-remembered": remembersRefusal, children: permissionText(permissionOfKind(remembersRefusal), device, live) }))] }, live));
|
|
649
|
+
}) })) : null, view.kind === 'requesting' ? (_jsx("p", { className: "ax-capture__status", role: "status", children: messages.permissionExplanation(view.device, view.live, name) })) : null, view.kind === 'refused' ? (_jsxs("div", { className: "ax-capture__refusal", role: "alert", children: [_jsx("p", { children: permissionText(view.permission, view.device, view.live) }), canAskAgain(view.permission) ? (_jsx("button", { type: "button", className: "ax-button ax-button--secondary", onClick: () => askAgain(view.live, 'environment'), children: messages.askAgain })) : null] })) : null, view.kind === 'live' ? (_jsxs("div", { className: "ax-capture__live-wrap", children: [renderLivePreview(view.live), _jsxs("div", { className: "ax-actions", children: [view.live === 'image' ? (_jsx("button", { type: "button", className: "ax-button ax-button--secondary", onClick: () => takePhoto(view.facing), disabled: !cameraReady, children: messages.takePhoto })) : (_jsx("button", { type: "button", className: "ax-button ax-button--secondary", onClick: () => {
|
|
650
|
+
if (view.live !== 'image') {
|
|
651
|
+
startRecording(view.live, view.facing);
|
|
652
|
+
}
|
|
653
|
+
}, children: messages.startRecording })), view.live !== 'audio' && view.cameras > 1 ? (_jsx("button", { type: "button", className: "ax-button ax-button--secondary", onClick: () => void switchCamera(view.live, view.facing), children: messages.switchCamera })) : null, _jsx("button", { type: "button", className: "ax-button ax-button--danger", onClick: () => reset(), children: messages.stopLive(view.live) })] })] })) : null, view.kind === 'recording' ? (_jsxs("div", { className: "ax-capture__recording", children: [renderLivePreview(view.live), _jsx("p", { className: "ax-capture__timer", role: "timer", "aria-live": "off", id: recordingId, children: messages.recordingState(elapsedText(view.elapsedMs)) }), _jsx("p", { className: "ax-capture__status", role: "status", children: messages.recordingStarted }), _jsx("div", { className: "ax-actions", children: _jsx("button", { type: "button", className: "ax-button ax-button--danger", onClick: () => stopRecording(), children: messages.stopRecording }) })] })) : null, view.kind === 'review' || view.kind === 'saving' || view.kind === 'captured' ? (_jsxs("div", { className: "ax-capture__review", children: [renderPreview(view.review), _jsxs("p", { className: "ax-capture__file-line", children: [view.review.fileName, " \u00B7 ", humanSize(view.review.blob.size, locale), view.review.mime === '' ? null : ` · ${view.review.mime}`] }), view.review.durationMs === undefined ? null : (_jsx("p", { className: "ax-capture__timer", children: messages.recordedState(elapsedText(view.review.durationMs)) })), view.kind === 'review' && view.review.durationMs !== undefined ? (_jsx("p", { className: "ax-capture__status", role: "status", children: messages.recordingStopped(elapsedText(view.review.durationMs)) })) : null, _jsx("a", { className: "ax-capture__open", href: view.review.url, target: "_blank", rel: "noreferrer", children: messages.openPreview(view.review.mediaKind) }), view.kind === 'captured' ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "ax-capture__status", role: "status", children: messages.stored() }), _jsx("p", { className: "ax-capture__file-line", children: mediaDisplayLine(view.reference, 28, locale) })] })) : null, view.kind === 'saving' ? (_jsx("p", { className: "ax-capture__status", role: "status", children: messages.saving })) : null, _jsxs("div", { className: "ax-actions", children: [view.kind === 'captured' ? null : (_jsx("button", { type: "button", className: "ax-button ax-button--secondary", onClick: () => void save(view.review), disabled: view.kind === 'saving', children: messages.applyCapture(view.review.mediaKind) })), _jsx("button", { type: "button", className: "ax-button ax-button--secondary", onClick: () => {
|
|
654
|
+
const source = view.review.source;
|
|
655
|
+
const mediaKind = view.review.mediaKind;
|
|
656
|
+
reset();
|
|
657
|
+
if (source === 'recorder' && (mediaKind === 'audio' || mediaKind === 'video')) {
|
|
658
|
+
void askLive(mediaKind, 'environment');
|
|
659
|
+
}
|
|
660
|
+
else if (source === 'camera') {
|
|
661
|
+
void askLive('image', 'environment');
|
|
662
|
+
}
|
|
663
|
+
}, disabled: view.kind === 'saving', children: messages.retake(view.review.mediaKind) })] })] })) : null, view.kind === 'error' ? (_jsxs("div", { className: "ax-capture__error", role: "alert", children: [_jsx("p", { children: view.sentence }), view.detail === undefined ? null : (_jsx("p", { className: "ax-hint", "data-capture-detail": "", children: view.detail })), view.review === undefined ? null : (_jsx("div", { className: "ax-actions", children: _jsx("button", { type: "button", className: "ax-button ax-button--secondary", onClick: () => {
|
|
664
|
+
const review = view.review;
|
|
665
|
+
if (review !== undefined)
|
|
666
|
+
void save(review);
|
|
667
|
+
}, children: messages.applyCapture(view.review.mediaKind) }) }))] })) : null, view.kind === 'saving' ? null : (_jsxs("div", { className: "ax-capture__file", children: [_jsx("label", { className: "ax-label", htmlFor: fileId, children: messages.chooseFile(fileKind) }), _jsx("input", { id: fileId, className: "ax-capture__file-input", type: "file", accept: fileAcceptValue, onChange: (event) => void chooseFile(event) })] })), _jsx("div", { className: "ax-actions ax-capture__actions", children: _jsx("button", { type: "button", className: "ax-button ax-button--secondary", onClick: cancel, children: messages.cancel }) })] }));
|
|
668
|
+
}
|
|
669
|
+
//# sourceMappingURL=MediaCapture.js.map
|