Add barcode-detector-api-polyfill dependency and update environment variable declarations in SvelteKit project
CI / build (push) Has been skipped
CI / deploy (push) Successful in 1m50s

This commit is contained in:
eewing
2026-02-17 14:58:53 -06:00
parent cff20a652a
commit 9022114c8d
2137 changed files with 201996 additions and 762 deletions
@@ -0,0 +1,6 @@
import { Exception, Result } from '@zxing/library';
import { IScannerControls } from './IScannerControls';
/**
* Callback format for continuous decode scan.
*/
export declare type DecodeContinuouslyCallback = (result: Result | undefined, error: Exception | undefined, controls: IScannerControls) => void;
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=DecodeContinuouslyCallback.js.map
@@ -0,0 +1 @@
{"version":3,"file":"DecodeContinuouslyCallback.js","sourceRoot":"","sources":["../../../src/common/DecodeContinuouslyCallback.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
import { LuminanceSource } from '@zxing/library';
export declare class HTMLCanvasElementLuminanceSource extends LuminanceSource {
private canvas;
private static DEGREE_TO_RADIANS;
private static makeBufferFromCanvasImageData;
private static toGrayscaleBuffer;
private buffer;
private tempCanvasElement?;
constructor(canvas: HTMLCanvasElement);
getRow(y: number, row: Uint8ClampedArray): Uint8ClampedArray;
getMatrix(): Uint8ClampedArray;
isCropSupported(): boolean;
crop(left: number, top: number, width: number, height: number): LuminanceSource;
/**
* This is always true, since the image is a gray-scale image.
*
* @return true
*/
isRotateSupported(): boolean;
rotateCounterClockwise(): LuminanceSource;
rotateCounterClockwise45(): LuminanceSource;
invert(): LuminanceSource;
private getTempCanvasElement;
private rotate;
}
@@ -0,0 +1,132 @@
import { IllegalArgumentException, InvertedLuminanceSource, LuminanceSource, } from '@zxing/library';
/**/
export class HTMLCanvasElementLuminanceSource extends LuminanceSource {
constructor(canvas) {
super(canvas.width, canvas.height);
this.canvas = canvas;
this.tempCanvasElement = null;
this.buffer = HTMLCanvasElementLuminanceSource.makeBufferFromCanvasImageData(canvas);
}
static makeBufferFromCanvasImageData(canvas) {
let canvasCtx;
try {
canvasCtx = canvas.getContext('2d', { willReadFrequently: true });
}
catch (e) {
canvasCtx = canvas.getContext('2d');
}
if (!canvasCtx) {
throw new Error('Couldn\'t get canvas context.');
}
const imageData = canvasCtx.getImageData(0, 0, canvas.width, canvas.height);
return HTMLCanvasElementLuminanceSource.toGrayscaleBuffer(imageData.data, canvas.width, canvas.height);
}
static toGrayscaleBuffer(imageBuffer, width, height) {
const grayscaleBuffer = new Uint8ClampedArray(width * height);
for (let i = 0, j = 0, length = imageBuffer.length; i < length; i += 4, j++) {
let gray;
const alpha = imageBuffer[i + 3];
// The color of fully-transparent pixels is irrelevant. They are often, technically, fully-transparent
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
// barcode image. Force any such pixel to be white:
if (alpha === 0) {
gray = 0xFF;
}
else {
const pixelR = imageBuffer[i];
const pixelG = imageBuffer[i + 1];
const pixelB = imageBuffer[i + 2];
// .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
// (306*R) >> 10 is approximately equal to R*0.299, and so on.
// 0x200 >> 10 is 0.5, it implements rounding.
// tslint:disable-next-line:no-bitwise
gray = (306 * pixelR + 601 * pixelG + 117 * pixelB + 0x200) >> 10;
}
grayscaleBuffer[j] = gray;
}
return grayscaleBuffer;
}
getRow(y /*int*/, row) {
if (y < 0 || y >= this.getHeight()) {
throw new IllegalArgumentException('Requested row is outside the image: ' + y);
}
const width = this.getWidth();
const start = y * width;
if (row === null) {
row = this.buffer.slice(start, start + width);
}
else {
if (row.length < width) {
row = new Uint8ClampedArray(width);
}
// The underlying raster of image consists of bytes with the luminance values
// TODO: can avoid set/slice?
row.set(this.buffer.slice(start, start + width));
}
return row;
}
getMatrix() {
return this.buffer;
}
isCropSupported() {
return true;
}
crop(left /*int*/, top /*int*/, width /*int*/, height /*int*/) {
super.crop(left, top, width, height);
return this;
}
/**
* This is always true, since the image is a gray-scale image.
*
* @return true
*/
isRotateSupported() {
return true;
}
rotateCounterClockwise() {
this.rotate(-90);
return this;
}
rotateCounterClockwise45() {
this.rotate(-45);
return this;
}
invert() {
return new InvertedLuminanceSource(this);
}
getTempCanvasElement() {
if (null === this.tempCanvasElement) {
const tempCanvasElement = this.canvas.ownerDocument.createElement('canvas');
tempCanvasElement.width = this.canvas.width;
tempCanvasElement.height = this.canvas.height;
this.tempCanvasElement = tempCanvasElement;
}
return this.tempCanvasElement;
}
rotate(angle) {
const tempCanvasElement = this.getTempCanvasElement();
if (!tempCanvasElement) {
throw new Error('Could not create a Canvas element.');
}
const angleRadians = angle * HTMLCanvasElementLuminanceSource.DEGREE_TO_RADIANS;
// Calculate and set new dimensions for temp canvas
const width = this.canvas.width;
const height = this.canvas.height;
const newWidth = Math.ceil(Math.abs(Math.cos(angleRadians)) * width + Math.abs(Math.sin(angleRadians)) * height);
const newHeight = Math.ceil(Math.abs(Math.sin(angleRadians)) * width + Math.abs(Math.cos(angleRadians)) * height);
tempCanvasElement.width = newWidth;
tempCanvasElement.height = newHeight;
const tempContext = tempCanvasElement.getContext('2d');
if (!tempContext) {
throw new Error('Could not create a Canvas Context element.');
}
// Draw at center of temp canvas to prevent clipping of image data
tempContext.translate(newWidth / 2, newHeight / 2);
tempContext.rotate(angleRadians);
tempContext.drawImage(this.canvas, width / -2, height / -2);
this.buffer = HTMLCanvasElementLuminanceSource.makeBufferFromCanvasImageData(tempCanvasElement);
return this;
}
}
HTMLCanvasElementLuminanceSource.DEGREE_TO_RADIANS = Math.PI / 180;
//# sourceMappingURL=HTMLCanvasElementLuminanceSource.js.map
@@ -0,0 +1 @@
{"version":3,"file":"HTMLCanvasElementLuminanceSource.js","sourceRoot":"","sources":["../../../src/common/HTMLCanvasElementLuminanceSource.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,IAAI;AACJ,MAAM,OAAO,gCAAiC,SAAQ,eAAe;IA+CnE,YAA2B,MAAyB;QAClD,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,C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AAC,CAAC,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,GAAG,gCAAgC,CAAC,6BAA6B,CAAC,iBAAiB,CAAC,CAAC;QAChG,OAAO,IAAI,CAAC;IACd,CAAC;;AApJc,kDAAiB,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC"}
@@ -0,0 +1,4 @@
/**
* HTML elements that can be decoded.
*/
export declare type HTMLVisualMediaElement = HTMLVideoElement | HTMLImageElement;
+2
View File
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=HTMLVisualMediaElement.js.map
@@ -0,0 +1 @@
{"version":3,"file":"HTMLVisualMediaElement.js","sourceRoot":"","sources":["../../../src/common/HTMLVisualMediaElement.ts"],"names":[],"mappings":""}
+30
View File
@@ -0,0 +1,30 @@
export interface IScannerControls {
/**
* Stops the scan process loop.
*/
stop: () => void;
/**
* @experimental This is highly unstable and Torch support is not ready on browsers. Use at YOUR OWN risk.
*/
switchTorch?: (onOff: boolean) => Promise<void>;
/**
* Allows to apply constraints to all tracks or filtered tracks in the stream.
* @experimental
*/
streamVideoConstraintsApply?: (constraints: MediaTrackConstraints, trackFilter?: (track: MediaStreamTrack) => MediaStreamTrack[]) => void;
/**
* Get the desired track constraints.
* @experimental
*/
streamVideoConstraintsGet?: (trackFilter: (track: MediaStreamTrack) => MediaStreamTrack[]) => MediaTrackConstraints;
/**
* Get the desired track settings.
* @experimental
*/
streamVideoSettingsGet?: (trackFilter: (track: MediaStreamTrack) => MediaStreamTrack[]) => MediaTrackSettings;
/**
* Get the desired track capabilities.
* @experimental
*/
streamVideoCapabilitiesGet?: (trackFilter: (track: MediaStreamTrack) => MediaStreamTrack[]) => MediaTrackCapabilities;
}
+2
View File
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=IScannerControls.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"IScannerControls.js","sourceRoot":"","sources":["../../../src/common/IScannerControls.ts"],"names":[],"mappings":""}
+8
View File
@@ -0,0 +1,8 @@
/**
* If navigator is present.
*/
export declare function hasNavigator(): boolean;
/**
* If enumerateDevices under navigator is supported.
*/
export declare function canEnumerateDevices(): boolean;
+19
View File
@@ -0,0 +1,19 @@
/**
* If navigator is present.
*/
export function hasNavigator() {
return typeof navigator !== 'undefined';
}
/**
* If mediaDevices under navigator is supported.
*/
function isMediaDevicesSupported() {
return hasNavigator() && !!navigator.mediaDevices;
}
/**
* If enumerateDevices under navigator is supported.
*/
export function canEnumerateDevices() {
return !!(isMediaDevicesSupported() && navigator.mediaDevices.enumerateDevices);
}
//# sourceMappingURL=navigator-utils.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"navigator-utils.js","sourceRoot":"","sources":["../../../src/common/navigator-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,OAAO,SAAS,KAAK,WAAW,CAAC;AAC1C,CAAC;AACD;;GAEG;AACH,SAAS,uBAAuB;IAC9B,OAAO,YAAY,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC;AACpD,CAAC;AACD;;GAEG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,CAAC,CAAC,CAAC,uBAAuB,EAAE,IAAI,SAAS,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;AAClF,CAAC"}