/*!
 * @undecaf/barcode-detector-polyfill v0.9.23
 * A WebAssembly polyfill for the Barcode Detection API
 * Built 2025-07-15T19:32:39.610Z
 * (c) 2021-present Ferdinand Kasper <fkasper@modus-operandi.at>
 * Released under the MIT license.
 * 
 * This work uses https://github.com/undecaf/zbar-wasm.git as per
 * LGPL-2.1 section 6 (https://opensource.org/licenses/LGPL-2.1).
 */
const barcodeDetectorPolyfill=function(e,t){"use strict";
/*! *****************************************************************************
    Copyright (c) Microsoft Corporation.

    Permission to use, copy, modify, and/or distribute this software for any
    purpose with or without fee is hereby granted.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
    REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
    OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    PERFORMANCE OF THIS SOFTWARE.
    ***************************************************************************** */function n(e,t,n,a){return new(n||(n=Promise))((function(r,i){function o(e){try{m(a.next(e))}catch(e){i(e)}}function s(e){try{m(a.throw(e))}catch(e){i(e)}}function m(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,s)}m((a=a.apply(e,t||[])).next())}))}class a{constructor(e,n=t.ZBarConfigType.ZBAR_CFG_ENABLE,a=1){this.symbolType=e,this.configType=n,this.number=a,this.configSteps=[this]}static register(e,t,n=t.symbolType){return a.formatsToConfigs[e]=t,a.typesToFormats[n]=a.typesToFormats[n]||e,t}static formats(){return Object.keys(a.formatsToConfigs)}static toFormat(e){return a.typesToFormats[e]}static configure(e,t){var n;null===(n=a.formatsToConfigs[t])||void 0===n||n.configSteps.forEach((t=>e.setConfig(t.symbolType,t.configType,t.number)))}add(e){return this.configSteps.push(e),this}}var r;a.formatsToConfigs={},a.typesToFormats={},a.register("codabar",new a(t.ZBarSymbolType.ZBAR_CODABAR)),a.register("code_39",new a(t.ZBarSymbolType.ZBAR_CODE39)),a.register("code_93",new a(t.ZBarSymbolType.ZBAR_CODE93)),a.register("code_128",new a(t.ZBarSymbolType.ZBAR_CODE128)),a.register("databar",new a(t.ZBarSymbolType.ZBAR_DATABAR)),a.register("databar_exp",new a(t.ZBarSymbolType.ZBAR_DATABAR_EXP)),a.register("ean_2",new a(t.ZBarSymbolType.ZBAR_EAN2)),a.register("ean_5",new a(t.ZBarSymbolType.ZBAR_EAN5)),a.register("ean_8",new a(t.ZBarSymbolType.ZBAR_EAN8)),a.register("ean_13",new a(t.ZBarSymbolType.ZBAR_EAN13)),a.register("ean_13+2",new a(t.ZBarSymbolType.ZBAR_EAN13)).add(new a(t.ZBarSymbolType.ZBAR_EAN2)),a.register("ean_13+5",new a(t.ZBarSymbolType.ZBAR_EAN13)).add(new a(t.ZBarSymbolType.ZBAR_EAN5)),a.register("isbn_10",new a(t.ZBarSymbolType.ZBAR_ISBN10)).add(new a(t.ZBarSymbolType.ZBAR_EAN13)),a.register("isbn_13",new a(t.ZBarSymbolType.ZBAR_ISBN13)).add(new a(t.ZBarSymbolType.ZBAR_EAN13)),a.register("isbn_13+2",new a(t.ZBarSymbolType.ZBAR_ISBN13)).add(new a(t.ZBarSymbolType.ZBAR_EAN13)).add(new a(t.ZBarSymbolType.ZBAR_EAN2)),a.register("isbn_13+5",new a(t.ZBarSymbolType.ZBAR_ISBN13)).add(new a(t.ZBarSymbolType.ZBAR_EAN13)).add(new a(t.ZBarSymbolType.ZBAR_EAN5)),a.register("itf",new a(t.ZBarSymbolType.ZBAR_I25)),a.register("qr_code",new a(t.ZBarSymbolType.ZBAR_QRCODE)),a.register("sq_code",new a(t.ZBarSymbolType.ZBAR_SQCODE)),a.register("upc_a",new a(t.ZBarSymbolType.ZBAR_UPCA)).add(new a(t.ZBarSymbolType.ZBAR_EAN13)),a.register("upc_e",new a(t.ZBarSymbolType.ZBAR_UPCE)).add(new a(t.ZBarSymbolType.ZBAR_EAN13)),e.Orientation=void 0,(r=e.Orientation||(e.Orientation={}))[r.UNKNOWN=-1]="UNKNOWN",r[r.UPRIGHT=0]="UPRIGHT",r[r.ROTATED_RIGHT=1]="ROTATED_RIGHT",r[r.UPSIDE_DOWN=2]="UPSIDE_DOWN",r[r.ROTATED_LEFT=3]="ROTATED_LEFT";class i{}const o=(()=>{try{return new OffscreenCanvas(1,1).getContext("2d")instanceof OffscreenCanvasRenderingContext2D}catch(e){return!1}})();class s{constructor(e={}){if(void 0!==e.formats){if(!Array.isArray(e.formats)||!e.formats.length)throw new TypeError(`Barcode formats should be a non-empty array of strings but are: ${JSON.stringify(e)}`);const t=e.formats.filter((e=>!a.formats().includes(e)));if(t.length)throw new TypeError(`Unsupported barcode format(s): ${t.join(", ")}`)}this.formats=e.formats||a.formats(),this.zbarConfig=e.zbar||new i}static getSupportedFormats(){return Promise.resolve(a.formats())}detect(e){s.validate(e);const n=s.intrinsicDimensions(e);if(0===n.width||0===n.height)return Promise.resolve([]);try{return Promise.all([this.toImageData(e),this.getScanner()]).then((e=>{const n=e[0],a=e[1];return void 0!==this.zbarConfig.enableCache&&a.enableCache(this.zbarConfig.enableCache),t.scanRGBABuffer(n.data,n.width,n.height,a)})).then((e=>e.map((e=>this.toBarcodeDetectorResult(e)))))}catch(e){return Promise.reject(e)}}getScanner(){return new Promise(((e,r)=>n(this,void 0,void 0,(function*(){if(!this.scanner){const e=yield t.getDefaultScanner();this.formats.length>0&&(e.setConfig(t.ZBarSymbolType.ZBAR_NONE,t.ZBarConfigType.ZBAR_CFG_ENABLE,0),this.formats.forEach((t=>a.configure(e,t)))),this.scanner=e}e(this.scanner)}))))}toImageData(e){const t=e=>{const t=s.intrinsicDimensions(e);this.canvas&&this.canvas.width===t.width&&this.canvas.height===t.height||(this.canvas=function(e,t){if(o)return new OffscreenCanvas(e,t);{const n=document.createElement("canvas");return n.width=e,n.height=t,n}}(t.width,t.height));const n=this.canvas,a=n.getContext("2d");return a.drawImage(e,0,0),a.getImageData(0,0,n.width,n.height)};if(e instanceof ImageData)return Promise.resolve(e);if(e instanceof Blob){if("function"==typeof createImageBitmap)return createImageBitmap(e).then((e=>t(e)));{const n=document.createElement("img");return n.src=URL.createObjectURL(e),n.decode().then((()=>t(n))).finally((()=>URL.revokeObjectURL(n.src)))}}return s.isRenderingContext(e)?Promise.resolve(e.getImageData(0,0,e.canvas.width,e.canvas.height)):Promise.resolve(t(e))}toBarcodeDetectorResult(e){const t={minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};e.points.forEach((e=>{t.minX=Math.min(t.minX,e.x),t.maxX=Math.max(t.maxX,e.x),t.minY=Math.min(t.minY,e.y),t.maxY=Math.max(t.maxY,e.y)}));return{format:a.toFormat(e.type),rawValue:e.decode(this.zbarConfig.encoding),orientation:e.orientation,quality:e.quality,boundingBox:DOMRectReadOnly.fromRect({x:t.minX,y:t.minY,width:t.maxX-t.minX,height:t.maxY-t.minY}),cornerPoints:[{x:t.minX,y:t.minY},{x:t.maxX,y:t.minY},{x:t.maxX,y:t.maxY},{x:t.minX,y:t.maxY}]}}static validate(e){if(!s.isPolyfillImageBitmapSource(e))throw new TypeError("BarcodeDetector.detect() argument is not an ImageBitmapSource");if("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement&&!e.complete)throw new DOMException(`Invalid HTMLImageElement.complete state: ${e.complete}`,"InvalidStateError");if("undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement&&[HTMLMediaElement.HAVE_NOTHING,HTMLMediaElement.HAVE_METADATA].includes(e.readyState))throw new DOMException(`Invalid HTMLVideoElement.readyState: ${e.readyState}`,"InvalidStateError");return!0}static isRenderingContext(e){return"undefined"!=typeof CanvasRenderingContext2D&&e instanceof CanvasRenderingContext2D||"undefined"!=typeof OffscreenCanvasRenderingContext2D&&e instanceof OffscreenCanvasRenderingContext2D}static isPolyfillImageBitmapSource(e){return"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof SVGImageElement&&e instanceof SVGImageElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas||"undefined"!=typeof VideoFrame&&e instanceof VideoFrame||s.isRenderingContext(e)||e instanceof ImageData||e instanceof Blob||e&&(0==e.width||0==e.height)}static intrinsicDimensions(e){return s.isRenderingContext(e)&&(e=e.canvas),{width:Number(e.naturalWidth||e.videoWidth||e.codedWidth||e.clientWidth||e.width),height:Number(e.naturalHeight||e.videoHeight||e.codedHeight||e.clientHeight||e.height)}}}return e.BarcodeDetectorPolyfill=s,e.ZBAR_WASM_PKG_NAME="@undecaf/zbar-wasm",e.ZBAR_WASM_REPOSITORY="https://cdn.jsdelivr.net/npm/@undecaf/zbar-wasm@0.9.16",e.ZBAR_WASM_VERSION="0.9.16",e.ZBarConfig=i,Object.defineProperty(e,"__esModule",{value:!0}),e}({},zbarWasm);
//# sourceMappingURL=index.js.map
