Camera Capture
A camera viewfinder for documents, cards and faces: a framing guide, quality hints, auto-capture when steady, retake or keep, front/back switch and a list of required shots. Each photo is a Blob.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
guide | CameraGuide | none | The framing guide: none, document, card or face. A shot of shots may choose its own. |
facing | CameraFacing | environment | The camera to open: environment (the back one, the default) or user (the front one). Switching camera updates it. |
shots | CameraShot[] | [] | The photos to take, in order: [{ "id": "front", "label": "Front of the card", "guide": "card" }, …]. As an
attribute, JSON. Empty takes a single photo. Setting a list with other content starts it over; the same content
again (a framework re-rendering a new array literal) changes nothing. |
auto-capture | boolean | false | Takes the photo by itself once the picture has no problem and holds steady for steady-time. The shutter still works. |
steady-time | number | 1200 | How long, in milliseconds, the picture must hold steady before auto-capture takes it. |
crop | boolean | false | Keeps only the area inside the guide in the photo. Without it, the photo is the camera's whole frame. |
image-type | string | image/jpeg | The image format of the photos. A browser that cannot write it gives PNG. |
image-quality | number | 0.92 | The quality of a JPEG or WebP photo, from 0 to 1. |
autostart | boolean | false | Opens the camera as soon as the element is on the page, without waiting for the Start camera button. |
label | string | — | The accessible name of the component. Empty uses the built-in "Camera". |
Slots
| Name | Description |
|---|---|
idle | Replaces the screen shown before the camera starts (an icon, a sentence and the Start camera button). Call start() from your own button. |
error | Replaces the screen shown when the camera cannot start. Read the reason from the camera-error event. |
guide | Replaces the drawing of the framing guide; the guide's box (part="guide") stays, and is the area crop keeps. |
actions | Action zone beside the shutter, for the app's own commands: upload a file instead, cancel. |
done | Replaces the summary shown once every photo is taken (the photos, each with a Retake button). The events do not bubble: listen on the element itself. |
Events
| Name | Type | Description |
|---|---|---|
camera-start | CustomEvent<{ facing: 'user' | 'environment' }> | Fired when the camera shows its first picture. |
camera-error | CustomEvent<{ kind: 'denied' | 'not-found' | 'busy' | 'unsupported' | 'ended' | 'unknown'; error: unknown }> | Fired when the camera cannot start, or stops while open (ended: unplugged, permission revoked); kind says why. |
capture | CustomEvent<CameraPhoto> | Fired when a photo is taken, before the user keeps or retakes it. detail.blob is the image. |
retake | CustomEvent<{ id: string; index: number }> | Fired when the user throws a photo away to take it again. |
accept | CustomEvent<CameraPhoto> | Fired when the user keeps a photo. |
complete | CustomEvent<{ photos: CameraPhoto[] }> | Fired once every shot has a photo kept; the camera then closes. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
stage | The dark box that holds the picture and the idle, error and done screens. |
video | The camera picture. |
guide | The box of the framing guide, wrapping the guide slot and its default drawing; crop keeps its area. |
frame | The default drawing of the guide. |
hint | The instruction or quality hint over the picture. |
preview | The photo under review. |
shots | The list of required shots. |
shot | One shot of the list. |
controls | The bar under the picture. |
actions | The wrapper of the actions slot. |
shutter | The button that takes the photo. |
switch | The button that switches camera, shown when the device has more than one. |
button | The Start camera, Try again, Retake and Use photo buttons. |
accept | The Use photo button. |
idle | The region of the idle screen, wrapping the idle slot and its default content. |
error | The region of the error screen, wrapping the error slot and its default content. |
done | The region of the summary, wrapping the done slot and its default photos. |
thumbnail | A photo of the summary. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-camera-capture--width | length | 480px | Width of the component, never wider than its container; 100% fills it. |
--c2-camera-capture__stage--aspect-ratio | aspect-ratio | 4 / 3 | Shape of the picture; the camera is cropped to fill it. |
--c2-camera-capture__stage--background | background | #18181b | Behind the picture, and of the idle, error and done screens. Dark in both themes, like a viewfinder. |
--c2-camera-capture__stage--color | color | #fafafa | Text on the stage. |
--c2-camera-capture__stage--border-radius | border-radius | 8px | |
--c2-camera-capture__stage__muted--color | color | #a1a1aa | Secondary text on the stage. |
--c2-camera-capture__guide--width | length | 82% | The most of the stage's width the document and card guides take. The guide keeps its shape and fits both this and the height. |
--c2-camera-capture__guide--height | length | 86% | The most of the stage's height a guide takes. |
--c2-camera-capture__guide--border-radius | border-radius | 14px | Corners of the document and card guides. |
--c2-camera-capture__guide--border-width | pixel | 3px | |
--c2-camera-capture__guide--border-color | color | #ffffff | |
--c2-camera-capture__guide__face--width | length | 52% | The most of the stage's width the face oval takes. |
--c2-camera-capture__guide__face--aspect-ratio | number | 0.75 | |
--c2-camera-capture__guide__document--aspect-ratio | number | 0.707 | Width over height, as a number: 0.707 is A4 upright. A cheque wants about 2.3, a receipt about 0.4. |
--c2-camera-capture__guide__card--aspect-ratio | number | 1.586 | An ID-1 card: a bank card, a driving licence. |
--c2-camera-capture__guide__ready--border-color | color | #16a34a | The guide while the picture is fine. |
--c2-camera-capture__guide__scrim--color | color | rgba(0, 0, 0, 0.45) | Darkens the picture outside the guide. |
--c2-camera-capture__hint--background | background | rgba(24, 24, 27, 0.72) | |
--c2-camera-capture__hint--color | color | #fafafa | |
--c2-camera-capture__hint--font-size | font-size | 14px | |
--c2-camera-capture__hint--border-radius | border-radius | 999px | |
--c2-camera-capture__hint--display | display | block | none hides the instructions and quality hints. |
--c2-camera-capture__hint__issue--background | background | rgba(180, 83, 9, 0.92) | The hint while the picture has a problem. |
--c2-camera-capture__shot--color | color | #71717a | |
--c2-camera-capture__shot--font-size | font-size | 12px | |
--c2-camera-capture__shot__current--color | color | #18181b | |
--c2-camera-capture__shot__current--font-weight | font-weight | 600 | |
--c2-camera-capture__mark__done--background | background | #16a34a | The disc behind the check of a shot already taken. |
--c2-camera-capture__mark__done--color | color | #ffffff | The check of a shot already taken. |
--c2-camera-capture__screen--font-size | font-size | 14px | Text of the idle, starting and error screens. |
--c2-camera-capture__controls--padding | length | 12px 0 0 | |
--c2-camera-capture__controls--gap | length | 12px | |
--c2-camera-capture__shutter--size | pixel | 60px | |
--c2-camera-capture__shutter--background | background | rgb(2, 101, 220) | |
--c2-camera-capture__shutter--ring-color | color | #ffffff | The inner ring of the shutter. |
--c2-camera-capture__shutter__hover--background | background | rgb(1, 84, 184) | |
--c2-camera-capture__shutter__progress--color | color | #16a34a | The ring that fills while auto-capture waits for a steady picture. |
--c2-camera-capture__switch--size | pixel | 40px | The Switch camera button. |
--c2-camera-capture__button--background | background | #ffffff | |
--c2-camera-capture__button--color | color | #18181b | |
--c2-camera-capture__button--border | border | 1px solid #bcbcc6 | |
--c2-camera-capture__button--border-radius | border-radius | 6px | |
--c2-camera-capture__button--height | pixel | 36px | |
--c2-camera-capture__button--font-size | font-size | 14px | |
--c2-camera-capture__button--font-weight | font-weight | 500 | |
--c2-camera-capture__button__hover--background | background | #f4f4f5 | |
--c2-camera-capture__accept--background | background | rgb(2, 101, 220) | The Use photo and Start camera buttons. |
--c2-camera-capture__accept--color | color | #ffffff | |
--c2-camera-capture__accept__hover--background | background | rgb(1, 84, 184) | |
--c2-camera-capture__thumbnail--border-radius | border-radius | 6px | |
--c2-camera-capture__thumbnail--min-width | length | 140px | The summary fits as many photos of at least this width per row as it can. |
--c2-camera-capture__thumbnail__button--height | pixel | 28px | The Retake button on a photo of the summary. |
--c2-camera-capture__thumbnail__button--font-size | font-size | 12px | |
--c2-camera-capture__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under camera-capture, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
label | Camera | — |
idle | Take a photo with your camera. | — |
start | Start camera | — |
starting | Starting the camera… | — |
capture | Take photo | — |
switchCamera | Switch camera | — |
retake | Retake | — |
accept | Use photo | — |
retakeShot | Retake {0} | {0} label |
preview | Photo to review | — |
shot | Photo {0} | {0} index |
shots | Photos to take | — |
progress | Photo {0} of {1}: {2} | {0} index {1} total {2} label |
shotDone | taken | — |
done | All photos taken. | — |
guideDocument | Fit the document inside the frame. | — |
guideCard | Fit the card inside the frame. | — |
guideFace | Centre your face in the oval. | — |
dark | More light needed. | — |
glare | Avoid glare: tilt away from the light. | — |
moving | Hold the camera steady. | — |
blurry | The picture is blurry: move closer or wait for focus. | — |
holdStill | Hold still… | — |
captured | Photo taken. | — |
errorDenied | Camera access was denied. Allow it in the browser settings, then try again. | — |
errorNotFound | No camera was found on this device. | — |
errorBusy | The camera is in use by another application. | — |
errorUnsupported | This browser cannot use a camera on this page. | — |
errorEnded | The camera stopped. Check that it is connected, then try again. | — |
errorUnknown | The camera could not start. | — |
retry | Try again | — |