realtime-gallery
Source: realtime-gallery.js:24
Stores, renders and exports spike captures.
STORAGE. IndexedDB, not localStorage. localStorage caps around 5MB per origin, is shared with the baseline, the settings and the existing thumbnail store, and inflates binary by a third on the way through base64 — a 640x480 JPEG lands near 70KB encoded, so the quota starts evicting things you care about after roughly fifty frames. IndexedDB takes Blobs natively.
PRIVACY. This module is the point where the tool starts holding photographs of a face rather than a 128-d template. Everything stays on the device, the count is always visible in the settings bar, and "Delete all" really empties the store. Deleting the baseline deliberately does NOT clear captures: the gallery is expected to outlive a re-baseline, and that is stated in the UI rather than left to be inferred.
EXPORT. Store-only ZIP written here in ~70 lines. JPEGs do not compress, so DEFLATE would buy nothing, and pulling in JSZip would put a third-party script on a page whose whole point is that it makes no third-party requests.
Instance Methods
openDb(): Promise.<IDBDatabase>
Opens (and upgrades) the capture database.
Returns
Promise.<IDBDatabase>— Open database handle.
run(
db: IDBDatabase,
mode: IDBTransactionMode,
work: function,
): Promise.<*>
Runs one transaction against the capture store.
Parameters
db(IDBDatabase) — Open database.mode(IDBTransactionMode) — Transaction mode.work(function) — Callback issuing the request.
Returns
Promise.<*>— Request result.
stamp(timestamp: number, fileSafe?: boolean): string
Formats a timestamp for filenames.
Parameters
timestamp(number) — Epoch milliseconds.fileSafe(boolean, optional, default: false) — Whether to avoid characters illegal in filenames.
Returns
string— Formatted stamp.
drawLogoMark()
Draws the project mark using the same geometry as mark-small-mono-cream.svg.
toBlob(
canvas: HTMLCanvasElement,
type: string,
quality?: number,
): Promise.<Blob>
Encodes a canvas to a Blob.
Parameters
canvas(HTMLCanvasElement) — Canvas to encode.type(string) — MIME type.quality(number, optional) — Encoder quality for lossy types.
Returns
Promise.<Blob>— Encoded blob.
crc32(bytes: Uint8Array): number
Computes a CRC-32 checksum.
Parameters
bytes(Uint8Array) — Input bytes.
Returns
number— Unsigned checksum.
dosDate(date: Date): Object
Encodes a date as a DOS time/date pair.
Parameters
date(Date) — Source date.
Returns
Object— DOS fields.
download(blob: Blob, filename: string): void
Triggers a browser download for a blob.
Parameters
blob(Blob) — Payload.filename(string) — Suggested filename.
Returns
void
size(): number
Reports how many captures are stored.
Returns
number— Capture count.
isOpen(): boolean
Reports whether the viewer overlay is showing.
Returns
boolean— True while open.
Static Methods
formatCaptureMeasurement(meta: object): string
Formats the only measurement claim shown with a saved frame.
Parameters
meta(object) — Measurement metadata.meta.distance(number) — Distance at capture.meta.threshold(number) — Match threshold used for the verdict.
Returns
string— Human-readable distance and verdict.
watermark(
source: HTMLCanvasElement,
meta: object,
): HTMLCanvasElement
Burns the project mark and the distance verdict into the frame.
Parameters
source(HTMLCanvasElement) — Frame to watermark.meta(object) — Measurement metadata.meta.distance(number) — Distance at capture.meta.threshold(number) — Cited match threshold.
Returns
HTMLCanvasElement— Watermarked canvas.
buildZip(
files: Array.<{name: string, bytes: Uint8Array, date: Date}>,
): Blob
Builds an uncompressed ZIP archive.
Parameters
files(Array.<{name: string, bytes: Uint8Array, date: Date}>) — Archive members.
Returns
Blob— ZIP blob.
createGallery(options: object): object
Creates the gallery controller.
Parameters
options(object) — Wiring options.options.viewerEl(HTMLElement) — Viewer overlay root.options.imageEl(HTMLImageElement) — Viewer image element.options.metaEl(HTMLElement) — Viewer metadata line.options.countEl(HTMLElement) — Settings-bar count element.options.onCountChange(function) — Count change callback.options.onDelete(function) — Deletion callback.options.onStatus(function) — Status message callback.
Returns
object— Gallery controller.