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
+11
View File
@@ -0,0 +1,11 @@
import type { IDetectedBarcode, IBarcodeDetector } from './models';
export declare class BarcodeDetector implements IBarcodeDetector {
private reader;
constructor(options?: {
formats: string[];
});
static getSupportedFormats(): Promise<string[]>;
detect(imageSource: ImageBitmapSource): Promise<IDetectedBarcode[]>;
private blobToImage;
private imageDataSourceToCanvas;
}
+87
View File
@@ -0,0 +1,87 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BarcodeDetector = void 0;
const browser_1 = require("@zxing/browser");
const library_1 = require("@zxing/library");
const constants_1 = require("./constants");
class BarcodeDetector {
constructor(options) {
const hints = new Map([
[library_1.DecodeHintType.TRY_HARDER, true],
[
library_1.DecodeHintType.POSSIBLE_FORMATS,
options
? options.formats.map((f) => constants_1.nativeToZxingFormat[f])
: Object.values(constants_1.nativeToZxingFormat),
],
]);
this.reader = new browser_1.BrowserMultiFormatReader(hints);
}
static getSupportedFormats() {
return Promise.resolve(Object.values(constants_1.zxingToNativeFormat));
}
async detect(imageSource) {
try {
let result;
if (imageSource instanceof HTMLVideoElement || imageSource instanceof HTMLImageElement) {
result = await this.reader.scanOneResult(imageSource, false);
}
else if (imageSource instanceof HTMLCanvasElement) {
result = this.reader.decodeFromCanvas(imageSource);
}
else if (imageSource instanceof Blob) {
const image = await this.blobToImage(imageSource);
result = await this.reader.scanOneResult(image, false);
}
else if (imageSource instanceof ImageBitmap
|| imageSource instanceof ImageData
|| imageSource instanceof VideoFrame) {
result = this.reader.decodeFromCanvas(this.imageDataSourceToCanvas(imageSource));
}
else {
throw new TypeError('Image source is not supported');
}
return [{
rawValue: result.getText(),
format: constants_1.zxingToNativeFormat[result.getBarcodeFormat()],
boundingBox: new DOMRectReadOnly(), // TODO: think of a way to map this in a meaningful way
cornerPoints: result.getResultPoints().map((p) => ({ x: p.getX(), y: p.getY() })),
}];
}
catch (err) {
if (err && !(err instanceof library_1.NotFoundException)) {
throw err;
}
return [];
}
}
async blobToImage(blob) {
return new Promise((resolve, reject) => {
const imageObjUrl = URL.createObjectURL(blob);
const image = new Image();
image.onload = () => {
URL.revokeObjectURL(imageObjUrl);
resolve(image);
};
image.onerror = () => reject();
image.src = imageObjUrl;
});
}
imageDataSourceToCanvas(source) {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const width = source instanceof VideoFrame ? source.displayWidth : source.width;
const height = source instanceof VideoFrame ? source.displayHeight : source.height;
if (ctx) {
if (source instanceof ImageData) {
ctx.putImageData(source, width, height);
}
else {
ctx.drawImage(source, width, height);
}
}
return canvas;
}
}
exports.BarcodeDetector = BarcodeDetector;
//# sourceMappingURL=BarcodeDetector.js.map
@@ -0,0 +1 @@
{"version":3,"file":"BarcodeDetector.js","sourceRoot":"","sources":["../../src/BarcodeDetector.ts"],"names":[],"mappings":";;;AAAA,4CAA0D;AAC1D,4CAA2E;AAE3E,2CAAuE;AAEvE,MAAa,eAAe;IAG1B,YAAY,OAA+B;QACzC,MAAM,KAAK,GAAG,IAAI,GAAG,CAA0B;YAC7C,CAAC,wBAAc,CAAC,UAAU,EAAE,IAAI,CAAC;YACjC;gBACE,wBAAc,CAAC,gBAAgB;gBAC/B,OAAO;oBACL,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,+BAAmB,CAAC,CAAC,CAAC,CAAC;oBACpD,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,+BAAmB,CAAC;aACvC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,GAAG,IAAI,kCAAwB,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IAEM,MAAM,CAAC,mBAAmB;QAC/B,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,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AAC;QAEnF,IAAI,GAAG,EAAE,CAAC;YACR,IAAI,MAAM,YAAY,SAAS,EAAE,CAAC;gBAChC,GAAG,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;YAC1C,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAvFD,0CAuFC"}
+1
View File
@@ -0,0 +1 @@
export {};
+7
View File
@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const BarcodeDetector_1 = require("./BarcodeDetector");
if (!('BarcodeDetector' in window)) {
window.BarcodeDetector = BarcodeDetector_1.BarcodeDetector;
}
//# sourceMappingURL=browser.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":";;AACA,uDAAoD;AAEpD,IAAI,CAAC,CAAC,iBAAiB,IAAI,MAAM,CAAC,EAAE,CAAC;IAClC,MAAoC,CAAC,eAAe,GAAG,iCAAe,CAAC;AAC1E,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
import { BarcodeFormat } from '@zxing/library';
export declare const zxingToNativeFormat: Record<BarcodeFormat, string>;
export declare const nativeToZxingFormat: Record<string, BarcodeFormat>;
+40
View File
@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nativeToZxingFormat = exports.zxingToNativeFormat = void 0;
const library_1 = require("@zxing/library");
// format names taken from https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API#supported_barcode_formats
exports.zxingToNativeFormat = {
[library_1.BarcodeFormat.AZTEC]: 'aztec',
[library_1.BarcodeFormat.CODABAR]: 'codabar',
[library_1.BarcodeFormat.CODE_39]: 'code_39',
[library_1.BarcodeFormat.CODE_93]: 'code_93',
[library_1.BarcodeFormat.CODE_128]: 'code_128',
[library_1.BarcodeFormat.DATA_MATRIX]: 'data_matrix',
[library_1.BarcodeFormat.EAN_8]: 'ean_8',
[library_1.BarcodeFormat.EAN_13]: 'ean_13',
[library_1.BarcodeFormat.ITF]: 'itf',
[library_1.BarcodeFormat.PDF_417]: 'pdf417',
[library_1.BarcodeFormat.QR_CODE]: 'qr_code',
[library_1.BarcodeFormat.UPC_A]: 'upc_a',
[library_1.BarcodeFormat.UPC_E]: 'upc_e',
[library_1.BarcodeFormat.UPC_EAN_EXTENSION]: 'unknown',
[library_1.BarcodeFormat.MAXICODE]: 'unknown',
[library_1.BarcodeFormat.RSS_14]: 'unknown',
[library_1.BarcodeFormat.RSS_EXPANDED]: 'unknown',
};
exports.nativeToZxingFormat = {
aztec: library_1.BarcodeFormat.AZTEC,
codabar: library_1.BarcodeFormat.CODABAR,
code_39: library_1.BarcodeFormat.CODE_39,
code_93: library_1.BarcodeFormat.CODE_93,
code_128: library_1.BarcodeFormat.CODE_128,
data_matrix: library_1.BarcodeFormat.DATA_MATRIX,
ean_8: library_1.BarcodeFormat.EAN_8,
ean_13: library_1.BarcodeFormat.EAN_13,
itf: library_1.BarcodeFormat.ITF,
pdf417: library_1.BarcodeFormat.PDF_417,
qr_code: library_1.BarcodeFormat.QR_CODE,
upc_a: library_1.BarcodeFormat.UPC_A,
upc_e: library_1.BarcodeFormat.UPC_E,
};
//# sourceMappingURL=constants.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAE/C,2HAA2H;AAE9G,QAAA,mBAAmB,GAAkC;IAChE,CAAC,uBAAa,CAAC,KAAK,CAAC,EAAE,OAAO;IAC9B,CAAC,uBAAa,CAAC,OAAO,CAAC,EAAE,SAAS;IAClC,CAAC,uBAAa,CAAC,OAAO,CAAC,EAAE,SAAS;IAClC,CAAC,uBAAa,CAAC,OAAO,CAAC,EAAE,S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1,4 @@
import { BarcodeDetector } from './BarcodeDetector';
export type * from './models';
export { BarcodeDetector };
export default BarcodeDetector;
+7
View File
@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BarcodeDetector = void 0;
const BarcodeDetector_1 = require("./BarcodeDetector");
Object.defineProperty(exports, "BarcodeDetector", { enumerable: true, get: function () { return BarcodeDetector_1.BarcodeDetector; } });
exports.default = BarcodeDetector_1.BarcodeDetector;
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAG3C,gGAHA,iCAAe,OAGA;AACxB,kBAAe,iCAAe,CAAC"}
@@ -0,0 +1,4 @@
import { IDetectedBarcode } from './IDetectedBarcode';
export interface IBarcodeDetector {
detect(image: ImageBitmapSource): Promise<IDetectedBarcode[]>;
}
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IBarcodeDetector.js.map
@@ -0,0 +1 @@
{"version":3,"file":"IBarcodeDetector.js","sourceRoot":"","sources":["../../../src/models/IBarcodeDetector.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
export interface ICornerPoint {
x: number;
y: number;
}
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ICornerPoint.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ICornerPoint.js","sourceRoot":"","sources":["../../../src/models/ICornerPoint.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
import { ICornerPoint } from './ICornerPoint';
export interface IDetectedBarcode {
boundingBox: DOMRectReadOnly;
cornerPoints: ICornerPoint[];
format: string;
rawValue: string;
}
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IDetectedBarcode.js.map
@@ -0,0 +1 @@
{"version":3,"file":"IDetectedBarcode.js","sourceRoot":"","sources":["../../../src/models/IDetectedBarcode.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
import { IBarcodeDetector } from './IBarcodeDetector';
export type WindowWithBarcodeDetector = Window & typeof globalThis & {
BarcodeDetector: {
prototype: IBarcodeDetector;
new (): IBarcodeDetector;
getSupportedFormats(): Promise<string[]>;
};
};
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=WindowWithBarcodeDetector.js.map
@@ -0,0 +1 @@
{"version":3,"file":"WindowWithBarcodeDetector.js","sourceRoot":"","sources":["../../../src/models/WindowWithBarcodeDetector.ts"],"names":[],"mappings":""}
+4
View File
@@ -0,0 +1,4 @@
export * from './ICornerPoint';
export * from './IDetectedBarcode';
export * from './IBarcodeDetector';
export * from './WindowWithBarcodeDetector';
+21
View File
@@ -0,0 +1,21 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./ICornerPoint"), exports);
__exportStar(require("./IDetectedBarcode"), exports);
__exportStar(require("./IBarcodeDetector"), exports);
__exportStar(require("./WindowWithBarcodeDetector"), exports);
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,qDAAmC;AACnC,qDAAmC;AACnC,8DAA4C"}