@qr-platform/qr-code.js 0.9.1 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ import{writeFile as o}from"fs/promises";import{Image as t,ImageKind as i}from"image-js";async function n(n,r,a,f,m=!1){let e;e=new t(r,a,n,m?{kind:i.GREY}:{kind:i.RGBA});const s=await e.toBuffer({format:"png"});await o(f,s)}export{n as saveDebugImageImageJs};
@@ -0,0 +1 @@
1
+ import{Resvg as e}from"@resvg/resvg-js";import{scanImageData as t}from"@undecaf/zbar-wasm";import{Image as r}from"image-js";let a=!1;const s=e=>{a&&console.debug("[QR Validator]",e)},o=new class{constructor(e={}){this.maxRetries=e.maxRetries??5,this.retryInterval=e.retryInterval??100,this.debug=e.debug??!1}log(e){this.debug&&console.log(`[QRValidatorZbarNode] ${e}`)}async validate(e,r=!1){try{if(!t)throw new Error("zbar-wasm library not found. Please ensure @undecaf/zbar-wasm is installed and loaded correctly.");return this.validateWithRetry(e,r)}catch(e){return this.log(`Validation error: ${e instanceof Error?e.message:String(e)}`),{isValid:!1,error:e instanceof Error?e.message:String(e),errorCode:"VALIDATION_ERROR"}}}sleep(e){return new Promise((t=>setTimeout(t,e)))}async processImageResvg(t,r){try{const a=new e(t,{fitTo:{mode:"zoom",value:2}}).render(),s=a.width,o=a.height,i=a.pixels,n=Buffer.from(i);if(r)for(let e=0;e<n.length;e+=4)n[e]=255-n[e],n[e+1]=255-n[e+1],n[e+2]=255-n[e+2];return{imageData:{data:new Uint8ClampedArray(n),width:s,height:o},metadata:{width:s,height:o}}}catch(e){throw this.log(`Image processing error: ${e instanceof Error?e.message:String(e)}`),e}}async validateWithRetry(e,t){let r=0,a=null;const s=e;let o=!1;do{r++;try{const e=this.processImageResvg,{imageData:i}=await e(s,t);if(this.log(`Processed image ${i.width}x${i.height} pixels`),this.debug&&await this.saveDebugImage(i,`debug/qr-attempt-${r}-${o?"inverted":"normal"}`),a=await this.decodeQR(i),this.log(`Barcode scan attempt ${r}: ${a.success?"Success":"Failed"}`),a.success)return a.attempts=r,{isValid:!0,data:a.data,format:a.format,attempts:r,isInverted:t}}catch(e){this.log(`Attempt ${r} failed: ${e instanceof Error?e.message:String(e)}`),a={success:!1,error:e instanceof Error?e.message:String(e),errorCode:"PROCESSING_ERROR"}}!t||o?r<this.maxRetries&&await this.sleep(this.retryInterval):(o=!0,this.log("Switching to inverted image for next attempt"))}while(r<this.maxRetries);return{isValid:!1,attempts:r,error:`No barcode detected after ${r} attempts`,errorCode:"MAX_RETRIES_EXCEEDED"}}async saveDebugImage(e,t){try{const a=new r(e.width,e.height,e.data,{kind:"RGBA"}),s=`${t}-${Date.now()}`;await a.save(`${s}.png`,{format:"png"}),this.log(`Debug image saved to: ${s}`)}catch(e){this.log(`Failed to save debug image: ${e instanceof Error?e.message:String(e)}`)}}async decodeQR(e){try{let r;try{r=await t(e)}catch(e){this.log(`Error decoding QR code: ${e}`)}if(r&&r.length>0){const e=r[0],t=e.decode();return this.log(`Detected: ${e.typeName} - ${t}`),{success:!0,data:t,format:e.typeName||"UNKNOWN",confidence:.9,count:r.length,allSymbols:r.map((e=>({data:e.decode(),type:e.typeName,points:e.points})))}}return{success:!1,error:"No barcode detected",errorCode:"NO_BARCODE_DETECTED"}}catch(e){return this.log("Decoder error:"),console.error(e instanceof Error?e.message:String(e)),{success:!1,error:`Decoder error: ${e instanceof Error?e.message:String(e)}`,errorCode:"DECODER_ERROR"}}}}({maxRetries:1,debug:!1,retryInterval:200}),i={validateZbar:async(e,t=!1)=>{a=t||a,a&&console.time("scan-validator");const r=[{name:"Normal SVG",execute:async()=>{if(!e)throw new Error("No svg source");const t=await o.validate(e,!1);if(!t.isValid||!t.data)throw new Error("No text found in normal QR code");return{isValid:!0,isInverted:!1,decodedText:t.data,message:"Decoded successfully.",attempts:t.attempts}}},{name:"Inverted SVG",execute:async()=>{if(!e)throw new Error("No svg source for inverted attempt");const t=await o.validate(e,!0);if(!t.isValid||!t.data)throw new Error("No text found in inverted QR code");return{isValid:!0,isInverted:!0,decodedText:t.data,message:"Decoded successfully (inverted).",attempts:t.attempts}}}];for(const e of r)try{s(`Trying ${e.name} decode...`);const t=await e.execute();return a&&console.timeEnd("scan-validator"),t}catch(t){s(`${e.name} decode failed:`),s(t)}return a&&console.timeEnd("scan-validator"),{isValid:!1,message:"Failed to decode QR code after all attempts."}}};export{i as qrValidator};
@@ -0,0 +1 @@
1
+ import{Resvg as e}from"@resvg/resvg-js";import{Image as t}from"image-js";import r from"@undecaf/zbar-wasm/dist/zbar.wasm?module";const n=async(e,t)=>{try{t(await WebAssembly.instantiate(r,e),r)}catch(e){throw console.error("Zbar WASM: Error during instantiation:",e),e}},i=function(e){function t(e,t,r,n){return new(r||(r=Promise))((function(t,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function o(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r((function(e){e(n)}))).then(a,o)}s((n=n.apply(e,[])).next())}))}function r(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})})),r}"function"==typeof SuppressedError&&SuppressedError;var n={exports:{}};const i=r(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));function a(e,t){for(var r=0,n=e.length-1;n>=0;n--){var i=e[n];"."===i?e.splice(n,1):".."===i?(e.splice(n,1),r++):r&&(e.splice(n,1),r--)}if(t)for(;r--;r)e.unshift("..");return e}var o=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,s=function(e){return o.exec(e).slice(1)};function c(){for(var e="",t=!1,r=arguments.length-1;r>=-1&&!t;r--){var n=r>=0?arguments[r]:"/";if("string"!=typeof n)throw new TypeError("Arguments to path.resolve must be strings");n&&(e=n+"/"+e,t="/"===n.charAt(0))}return(t?"/":"")+(e=a(g(e.split("/"),(function(e){return!!e})),!t).join("/"))||"."}function u(e){var t=l(e),r="/"===p(e,-1);return(e=a(g(e.split("/"),(function(e){return!!e})),!t).join("/"))||t||(e="."),e&&r&&(e+="/"),(t?"/":"")+e}function l(e){return"/"===e.charAt(0)}function f(){return u(g(Array.prototype.slice.call(arguments,0),(function(e,t){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e})).join("/"))}function d(e,t){function r(e){for(var t=0;t<e.length&&""===e[t];t++);for(var r=e.length-1;r>=0&&""===e[r];r--);return t>r?[]:e.slice(t,r-t+1)}e=c(e).substr(1),t=c(t).substr(1);for(var n=r(e.split("/")),i=r(t.split("/")),a=Math.min(n.length,i.length),o=a,s=0;s<a;s++)if(n[s]!==i[s]){o=s;break}var u=[];for(s=o;s<n.length;s++)u.push("..");return(u=u.concat(i.slice(o))).join("/")}function h(e){var t=s(e),r=t[0],n=t[1];return r||n?(n&&(n=n.substr(0,n.length-1)),r+n):"."}function _(e,t){var r=s(e)[2];return t&&r.substr(-1*t.length)===t&&(r=r.substr(0,r.length-t.length)),r}function m(e){return s(e)[3]}const A={extname:m,basename:_,dirname:h,sep:"/",delimiter:":",relative:d,join:f,isAbsolute:l,normalize:u,resolve:c};function g(e,t){if(e.filter)return e.filter(t);for(var r=[],n=0;n<e.length;n++)t(e[n],n,e)&&r.push(e[n]);return r}var p="b"==="ab".substr(-1)?function(e,t,r){return e.substr(t,r)}:function(e,t,r){return t<0&&(t=e.length+t),e.substr(t,r)};const y=r(Object.freeze(Object.defineProperty({__proto__:null,basename:_,default:A,delimiter:":",dirname:h,extname:m,isAbsolute:l,join:f,normalize:u,relative:d,resolve:c,sep:"/"},Symbol.toStringTag,{value:"Module"})));!function(e){var t,r=(t="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0,"undefined"!=typeof __filename&&(t=t||__filename),function(e={}){var r,n,a=e;a.ready=new Promise(((e,t)=>{r=e,n=t}));var o,s,c,u=Object.assign({},a),l="object"==typeof window,f="function"==typeof importScripts,d="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,h="";if(d){var _=i,m=y;h=f?m.dirname(h)+"/":__dirname+"/",o=(e,t)=>(e=F(e)?new URL(e):m.normalize(e),_.readFileSync(e,t?void 0:"utf8")),c=e=>{var t=o(e,!0);return t.buffer||(t=new Uint8Array(t)),t},s=(e,t,r,n=!0)=>{e=F(e)?new URL(e):m.normalize(e),_.readFile(e,n?void 0:"utf8",((e,i)=>{e?r(e):t(n?i.buffer:i)}))},!a.thisProgram&&process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),a.inspect=()=>"[Emscripten Module object]"}else(l||f)&&(f?h=self.location.href:"undefined"!=typeof document&&document.currentScript&&(h=document.currentScript.src),t&&(h=t),h=0!==h.indexOf("blob:")?h.substr(0,h.replace(/[?#].*/,"").lastIndexOf("/")+1):"",o=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),t.responseText},f&&(c=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),s=(e,t,r)=>{var n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=()=>{200==n.status||0==n.status&&n.response?t(n.response):r()},n.onerror=r,n.send(null)});var A,g,p,R=a.print||console.log.bind(console),E=a.printErr||console.error.bind(console);Object.assign(a,u),u=null,a.arguments&&a.arguments,a.thisProgram&&a.thisProgram,a.quit&&a.quit,a.wasmBinary&&(A=a.wasmBinary),a.noExitRuntime,"object"!=typeof WebAssembly&&T("no native wasm support detected");var v,B,b=!1;function I(){var e=g.buffer;a.HEAP8=new Int8Array(e),a.HEAP16=new Int16Array(e),a.HEAP32=new Int32Array(e),a.HEAPU8=v=new Uint8Array(e),a.HEAPU16=new Uint16Array(e),a.HEAPU32=B=new Uint32Array(e),a.HEAPF32=new Float32Array(e),a.HEAPF64=new Float64Array(e)}var w=[],Z=[],S=[],C=0,N=null;function T(e){a.onAbort&&a.onAbort(e),E(e="Aborted("+e+")"),b=!0,e+=". Build with -sASSERTIONS for more info.";var t=new WebAssembly.RuntimeError(e);throw n(t),t}var D,O;function P(e){return e.startsWith("data:application/octet-stream;base64,")}function F(e){return e.startsWith("file://")}function G(e){if(e==D&&A)return new Uint8Array(A);if(c)return c(e);throw"both async and sync fetching of the wasm failed"}function U(e,t,r){return function(e){if(!A&&(l||f)){if("function"==typeof fetch&&!F(e))return fetch(e,{credentials:"same-origin"}).then((t=>{if(!t.ok)throw"failed to load wasm binary file at '"+e+"'";return t.arrayBuffer()})).catch((()=>G(e)));if(s)return new Promise(((t,r)=>{s(e,(e=>t(new Uint8Array(e))),r)}))}return Promise.resolve().then((()=>G(e)))}(e).then((e=>WebAssembly.instantiate(e,t))).then((e=>e)).then(r,(e=>{E("failed to asynchronously prepare wasm: "+e),T(e)}))}P(D="zbar.wasm")||(O=D,D=a.locateFile?a.locateFile(O,h):h+O);var x,H=e=>{for(;e.length>0;)e.shift()(a)},M=e=>{var t=e-g.buffer.byteLength+65535>>>16;try{return g.grow(t),I(),1}catch(e){}},$="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0,j=[null,[],[]],L=(e,t)=>{var r=j[e];0===t||10===t?((1===e?R:E)(((e,t)=>{for(var r=t+void 0,n=t;e[n]&&!(n>=r);)++n;if(n-t>16&&e.buffer&&$)return $.decode(e.subarray(t,n));for(var i="";t<n;){var a=e[t++];if(128&a){var o=63&e[t++];if(192!=(224&a)){var s=63&e[t++];if((a=224==(240&a)?(15&a)<<12|o<<6|s:(7&a)<<18|o<<12|s<<6|63&e[t++])<65536)i+=String.fromCharCode(a);else{var c=a-65536;i+=String.fromCharCode(55296|c>>10,56320|1023&c)}}else i+=String.fromCharCode((31&a)<<6|o)}else i+=String.fromCharCode(a)}return i})(r,0)),r.length=0):r.push(t)},W={d:()=>!0,e:function(){return Date.now()},c:e=>{var t=v.length,r=2147483648;if((e>>>=0)>r)return!1;for(var n,i=1;i<=4;i*=2){var a=t*(1+.2/i);a=Math.min(a,e+100663296);var o=Math.min(r,(n=Math.max(e,a))+(65536-n%65536)%65536);if(M(o))return!0}return!1},f:e=>52,b:function(e,t,r,n,i){return 70},a:(e,t,r,n)=>{for(var i=0,a=0;a<r;a++){var o=B[t>>2],s=B[t+4>>2];t+=8;for(var c=0;c<s;c++)L(e,v[o+c]);i+=s}return B[n>>2]=i,0}};function k(){function e(){x||(x=!0,a.calledRun=!0,b||(H(Z),r(a),a.onRuntimeInitialized&&a.onRuntimeInitialized(),function(){if(a.postRun)for("function"==typeof a.postRun&&(a.postRun=[a.postRun]);a.postRun.length;)e=a.postRun.shift(),S.unshift(e);var e;H(S)}()))}C>0||(function(){if(a.preRun)for("function"==typeof a.preRun&&(a.preRun=[a.preRun]);a.preRun.length;)e=a.preRun.shift(),w.unshift(e);var e;H(w)}(),C>0||(a.setStatus?(a.setStatus("Running..."),setTimeout((function(){setTimeout((function(){a.setStatus("")}),1),e()}),1)):e()))}if(function(){var e,t,r,i,o={a:W};function s(e,t){var r,n=e.exports;return g=(p=n).g,I(),p.s,r=p.h,Z.unshift(r),function(){if(C--,a.monitorRunDependencies&&a.monitorRunDependencies(C),0==C&&N){var e=N;N=null,e()}}(),n}if(C++,a.monitorRunDependencies&&a.monitorRunDependencies(C),a.instantiateWasm)try{return a.instantiateWasm(o,s)}catch(e){E("Module.instantiateWasm callback failed with error: "+e),n(e)}(e=A,t=D,r=o,i=function(e){s(e.instance)},e||"function"!=typeof WebAssembly.instantiateStreaming||P(t)||F(t)||d||"function"!=typeof fetch?U(t,r,i):fetch(t,{credentials:"same-origin"}).then((e=>WebAssembly.instantiateStreaming(e,r).then(i,(function(e){return E("wasm streaming compile failed: "+e),E("falling back to ArrayBuffer instantiation"),U(t,r,i)}))))).catch(n)}(),a._ImageScanner_create=()=>(a._ImageScanner_create=p.i)(),a._ImageScanner_destory=e=>(a._ImageScanner_destory=p.j)(e),a._ImageScanner_set_config=(e,t,r,n)=>(a._ImageScanner_set_config=p.k)(e,t,r,n),a._ImageScanner_enable_cache=(e,t)=>(a._ImageScanner_enable_cache=p.l)(e,t),a._ImageScanner_recycle_image=(e,t)=>(a._ImageScanner_recycle_image=p.m)(e,t),a._ImageScanner_get_results=e=>(a._ImageScanner_get_results=p.n)(e),a._ImageScanner_scan=(e,t)=>(a._ImageScanner_scan=p.o)(e,t),a._Image_create=(e,t,r,n,i,o)=>(a._Image_create=p.p)(e,t,r,n,i,o),a._Image_destory=e=>(a._Image_destory=p.q)(e),a._Image_get_symbols=e=>(a._Image_get_symbols=p.r)(e),a._free=e=>(a._free=p.t)(e),a._malloc=e=>(a._malloc=p.u)(e),N=function e(){x||k(),x||(N=e)},a.preInit)for("function"==typeof a.preInit&&(a.preInit=[a.preInit]);a.preInit.length>0;)a.preInit.pop()();return k(),e.ready});e.exports=r}(n);const R=function(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}(n.exports);let E;function v(e={}){E=function(){return t(this,0,void 0,(function*(){const t=yield R(e);if(t)return t;throw Error("WASM was not loaded")}))}()}function B(){return t(this,0,void 0,(function*(){return E||v(),yield E}))}var b,I,w;e.ZBarSymbolType=void 0,(b=e.ZBarSymbolType||(e.ZBarSymbolType={}))[b.ZBAR_NONE=0]="ZBAR_NONE",b[b.ZBAR_PARTIAL=1]="ZBAR_PARTIAL",b[b.ZBAR_EAN2=2]="ZBAR_EAN2",b[b.ZBAR_EAN5=5]="ZBAR_EAN5",b[b.ZBAR_EAN8=8]="ZBAR_EAN8",b[b.ZBAR_UPCE=9]="ZBAR_UPCE",b[b.ZBAR_ISBN10=10]="ZBAR_ISBN10",b[b.ZBAR_UPCA=12]="ZBAR_UPCA",b[b.ZBAR_EAN13=13]="ZBAR_EAN13",b[b.ZBAR_ISBN13=14]="ZBAR_ISBN13",b[b.ZBAR_COMPOSITE=15]="ZBAR_COMPOSITE",b[b.ZBAR_I25=25]="ZBAR_I25",b[b.ZBAR_DATABAR=34]="ZBAR_DATABAR",b[b.ZBAR_DATABAR_EXP=35]="ZBAR_DATABAR_EXP",b[b.ZBAR_CODABAR=38]="ZBAR_CODABAR",b[b.ZBAR_CODE39=39]="ZBAR_CODE39",b[b.ZBAR_PDF417=57]="ZBAR_PDF417",b[b.ZBAR_QRCODE=64]="ZBAR_QRCODE",b[b.ZBAR_SQCODE=80]="ZBAR_SQCODE",b[b.ZBAR_CODE93=93]="ZBAR_CODE93",b[b.ZBAR_CODE128=128]="ZBAR_CODE128",b[b.ZBAR_SYMBOL=255]="ZBAR_SYMBOL",b[b.ZBAR_ADDON2=512]="ZBAR_ADDON2",b[b.ZBAR_ADDON5=1280]="ZBAR_ADDON5",b[b.ZBAR_ADDON=1792]="ZBAR_ADDON",e.ZBarConfigType=void 0,(I=e.ZBarConfigType||(e.ZBarConfigType={}))[I.ZBAR_CFG_ENABLE=0]="ZBAR_CFG_ENABLE",I[I.ZBAR_CFG_ADD_CHECK=1]="ZBAR_CFG_ADD_CHECK",I[I.ZBAR_CFG_EMIT_CHECK=2]="ZBAR_CFG_EMIT_CHECK",I[I.ZBAR_CFG_ASCII=3]="ZBAR_CFG_ASCII",I[I.ZBAR_CFG_BINARY=4]="ZBAR_CFG_BINARY",I[I.ZBAR_CFG_NUM=5]="ZBAR_CFG_NUM",I[I.ZBAR_CFG_MIN_LEN=32]="ZBAR_CFG_MIN_LEN",I[I.ZBAR_CFG_MAX_LEN=33]="ZBAR_CFG_MAX_LEN",I[I.ZBAR_CFG_UNCERTAINTY=64]="ZBAR_CFG_UNCERTAINTY",I[I.ZBAR_CFG_POSITION=128]="ZBAR_CFG_POSITION",I[I.ZBAR_CFG_TEST_INVERTED=129]="ZBAR_CFG_TEST_INVERTED",I[I.ZBAR_CFG_X_DENSITY=256]="ZBAR_CFG_X_DENSITY",I[I.ZBAR_CFG_Y_DENSITY=257]="ZBAR_CFG_Y_DENSITY",e.ZBarOrientation=void 0,(w=e.ZBarOrientation||(e.ZBarOrientation={}))[w.ZBAR_ORIENT_UNKNOWN=-1]="ZBAR_ORIENT_UNKNOWN",w[w.ZBAR_ORIENT_UP=0]="ZBAR_ORIENT_UP",w[w.ZBAR_ORIENT_RIGHT=1]="ZBAR_ORIENT_RIGHT",w[w.ZBAR_ORIENT_DOWN=2]="ZBAR_ORIENT_DOWN",w[w.ZBAR_ORIENT_LEFT=3]="ZBAR_ORIENT_LEFT";class Z{constructor(e,t){this.ptr=e,this.inst=t}checkAlive(){if(!this.ptr)throw Error("Call after destroyed")}getPointer(){return this.checkAlive(),this.ptr}}class S{constructor(e,t){this.ptr=e,this.ptr32=e>>2,this.buf=t,this.HEAP8=new Int8Array(t),this.HEAPU32=new Uint32Array(t),this.HEAP32=new Int32Array(t)}}class C extends S{get type(){return this.HEAPU32[this.ptr32]}get data(){const e=this.HEAPU32[this.ptr32+4],t=this.HEAPU32[this.ptr32+5];return Int8Array.from(this.HEAP8.subarray(t,t+e))}get points(){const e=this.HEAPU32[this.ptr32+7],t=this.HEAPU32[this.ptr32+8]>>2,r=[];for(let n=0;n<e;++n){const e=this.HEAP32[t+2*n],i=this.HEAP32[t+2*n+1];r.push({x:e,y:i})}return r}get orientation(){return this.HEAP32[this.ptr32+9]}get next(){const e=this.HEAPU32[this.ptr32+11];return e?new C(e,this.buf):null}get time(){return this.HEAPU32[this.ptr32+13]}get cacheCount(){return this.HEAP32[this.ptr32+14]}get quality(){return this.HEAP32[this.ptr32+15]}}class N extends S{get head(){const e=this.HEAPU32[this.ptr32+2];return e?new C(e,this.buf):null}}class T{constructor(t){this.type=t.type,this.typeName=e.ZBarSymbolType[this.type],this.data=t.data,this.points=t.points,this.orientation=t.orientation,this.time=t.time,this.cacheCount=t.cacheCount,this.quality=t.quality}static createSymbolsFromPtr(e,t){if(0==e)return[];let r=new N(e,t).head;const n=[];for(;null!==r;)n.push(new T(r)),r=r.next;return n}decode(e){return new TextDecoder(e).decode(this.data)}}class D extends Z{static createFromGrayBuffer(e,r,n,i=0){return t(this,0,void 0,(function*(){const t=yield B(),a=new Uint8Array(n),o=e*r;if(o!==a.byteLength)throw Error(`data length (${a.byteLength} bytes) does not match width and height (${o} bytes)`);const s=t._malloc(o);return t.HEAPU8.set(a,s),new this(t._Image_create(e,r,808466521,s,o,i),t)}))}static createFromRGBABuffer(e,r,n,i=0){return t(this,0,void 0,(function*(){const t=yield B(),a=new Uint8Array(n),o=e*r;if(4*o!==a.byteLength)throw Error(`data length (${a.byteLength} bytes) does not match width and height (${4*o} bytes)`);const s=t._malloc(o),c=s+o,u=t.HEAPU8;for(let e=s,t=0;e<c;e++,t+=4)u[e]=19595*a[t]+38469*a[t+1]+7472*a[t+2]>>16;return new this(t._Image_create(e,r,808466521,s,o,i),t)}))}destroy(){this.checkAlive(),this.inst._Image_destory(this.ptr),this.ptr=0}getSymbols(){this.checkAlive();const e=this.inst._Image_get_symbols(this.ptr);return T.createSymbolsFromPtr(e,this.inst.HEAPU8.buffer)}}class O extends Z{static create(){return t(this,0,void 0,(function*(){const e=yield B();return new this(e._ImageScanner_create(),e)}))}destroy(){this.checkAlive(),this.inst._ImageScanner_destory(this.ptr),this.ptr=0}setConfig(e,t,r){return this.checkAlive(),this.inst._ImageScanner_set_config(this.ptr,e,t,r)}enableCache(e=!0){this.checkAlive(),this.inst._ImageScanner_enable_cache(this.ptr,e)}recycleImage(e){this.checkAlive(),this.inst._ImageScanner_recycle_image(this.ptr,e.getPointer())}getResults(){this.checkAlive();const e=this.inst._ImageScanner_get_results(this.ptr);return T.createSymbolsFromPtr(e,this.inst.HEAPU8.buffer)}scan(e){return this.checkAlive(),this.inst._ImageScanner_scan(this.ptr,e.getPointer())}}const P=()=>t(void 0,0,void 0,(function*(){const t=yield O.create();return t.setConfig(e.ZBarSymbolType.ZBAR_NONE,e.ZBarConfigType.ZBAR_CFG_BINARY,1),t}));let F;const G=(e,r)=>t(void 0,0,void 0,(function*(){void 0===r&&(r=F||(yield P()),F=r);const t=r.scan(e);if(t<0)throw Error("Scan Failed");return 0===t?[]:e.getSymbols()})),U=(e,r,n,i)=>t(void 0,0,void 0,(function*(){const t=yield D.createFromRGBABuffer(r,n,e),a=yield G(t,i);return t.destroy(),a}));return e.ZBarImage=D,e.ZBarScanner=O,e.ZBarSymbol=T,e.getDefaultScanner=P,e.getInstance=B,e.scanGrayBuffer=(e,r,n,i)=>t(void 0,0,void 0,(function*(){const t=yield D.createFromGrayBuffer(r,n,e),a=yield G(t,i);return t.destroy(),a})),e.scanImageData=(e,r)=>t(void 0,0,void 0,(function*(){return yield U(e.data.buffer,e.width,e.height,r)})),e.scanRGBABuffer=U,e.setModuleArgs=v,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});i.setModuleArgs&&i.setModuleArgs({instantiateWasm:n});let a=!1;const o=e=>{a&&console.debug("[QR Validator]",e)},s=new class{constructor(e={}){this.maxRetries=e.maxRetries??5,this.retryInterval=e.retryInterval??100,this.debug=e.debug??!1}log(e){this.debug&&console.log(`[QRValidatorZbarNode] ${e}`)}async validate(e,t=!1){try{if(!i.scanImageData)throw new Error("zbar-wasm library not found. Please ensure @undecaf/zbar-wasm is installed and loaded correctly.");return this.validateWithRetry(e,t)}catch(e){return this.log(`Validation error: ${e instanceof Error?e.message:String(e)}`),{isValid:!1,error:e instanceof Error?e.message:String(e),errorCode:"VALIDATION_ERROR"}}}sleep(e){return new Promise((t=>setTimeout(t,e)))}async processImageResvg(t,r){try{const n=new e(t,{fitTo:{mode:"zoom",value:2}}).render(),i=n.width,a=n.height,o=n.pixels,s=Buffer.from(o);if(r)for(let e=0;e<s.length;e+=4)s[e]=255-s[e],s[e+1]=255-s[e+1],s[e+2]=255-s[e+2];return{imageData:{data:new Uint8ClampedArray(s),width:i,height:a},metadata:{width:i,height:a}}}catch(e){throw this.log(`Image processing error: ${e instanceof Error?e.message:String(e)}`),e}}async validateWithRetry(e,t){let r=0,n=null;const i=e;let a=!1;do{r++;try{const e=this.processImageResvg,{imageData:o}=await e(i,t);if(this.log(`Processed image ${o.width}x${o.height} pixels`),this.debug&&await this.saveDebugImage(o,`debug/qr-attempt-${r}-${a?"inverted":"normal"}`),n=await this.decodeQR(o),this.log(`Barcode scan attempt ${r}: ${n.success?"Success":"Failed"}`),n.success)return n.attempts=r,{isValid:!0,data:n.data,format:n.format,attempts:r,isInverted:t}}catch(e){this.log(`Attempt ${r} failed: ${e instanceof Error?e.message:String(e)}`),n={success:!1,error:e instanceof Error?e.message:String(e),errorCode:"PROCESSING_ERROR"}}!t||a?r<this.maxRetries&&await this.sleep(this.retryInterval):(a=!0,this.log("Switching to inverted image for next attempt"))}while(r<this.maxRetries);return{isValid:!1,attempts:r,error:`No barcode detected after ${r} attempts`,errorCode:"MAX_RETRIES_EXCEEDED"}}async saveDebugImage(e,r){try{const n=new t(e.width,e.height,e.data,{kind:"RGBA"}),i=`${r}-${Date.now()}`;await n.save(`${i}.png`,{format:"png"}),this.log(`Debug image saved to: ${i}`)}catch(e){this.log(`Failed to save debug image: ${e instanceof Error?e.message:String(e)}`)}}async decodeQR(e){try{let t;try{t=await i.scanImageData(e)}catch(e){this.log(`Error decoding QR code: ${e}`)}if(t&&t.length>0){const e=t[0],r=e.decode();return this.log(`Detected: ${e.typeName} - ${r}`),{success:!0,data:r,format:e.typeName||"UNKNOWN",confidence:.9,count:t.length,allSymbols:t.map((e=>({data:e.decode(),type:e.typeName,points:e.points})))}}return{success:!1,error:"No barcode detected",errorCode:"NO_BARCODE_DETECTED"}}catch(e){return this.log("Decoder error:"),console.error(e instanceof Error?e.message:String(e)),{success:!1,error:`Decoder error: ${e instanceof Error?e.message:String(e)}`,errorCode:"DECODER_ERROR"}}}}({maxRetries:3,debug:!1,retryInterval:300}),c={validateZbar:async(e,t=!1)=>{a=t||a,a&&console.time("scan-validator");const r=[{name:"Normal SVG",execute:async()=>{if(!e)throw new Error("No svg source");const t=await s.validate(e,!1);if(!t.isValid||!t.data)throw new Error("No text found in normal QR code");return{isValid:!0,isInverted:!1,decodedText:t.data,message:"Decoded successfully.",attempts:t.attempts}}},{name:"Inverted SVG",execute:async()=>{if(!e)throw new Error("No svg source for inverted attempt");const t=await s.validate(e,!0);if(!t.isValid||!t.data)throw new Error("No text found in inverted QR code");return{isValid:!0,isInverted:!0,decodedText:t.data,message:"Decoded successfully (inverted).",attempts:t.attempts}}}];for(const e of r)try{o(`Trying ${e.name} decode...`);const t=await e.execute();return a&&console.timeEnd("scan-validator"),t}catch(t){o(`${e.name} decode failed:`),o(t)}return a&&console.timeEnd("scan-validator"),{isValid:!1,message:"Failed to decode QR code after all attempts."}}};export{c as qrValidator};
@@ -0,0 +1 @@
1
+ import{Resvg as t}from"@resvg/resvg-js";import{CustomError as e}from"ts-custom-error";import{Image as r}from"image-js";class n extends e{constructor(t=void 0){super(t),this.message=t}getKind(){return this.constructor.kind}}n.kind="Exception";class i extends n{static getNotFoundInstance(){return new i}}var s;i.kind="NotFoundException",function(t){t[t.AZTEC=0]="AZTEC",t[t.CODABAR=1]="CODABAR",t[t.CODE_39=2]="CODE_39",t[t.CODE_93=3]="CODE_93",t[t.CODE_128=4]="CODE_128",t[t.DATA_MATRIX=5]="DATA_MATRIX",t[t.EAN_8=6]="EAN_8",t[t.EAN_13=7]="EAN_13",t[t.ITF=8]="ITF",t[t.MAXICODE=9]="MAXICODE",t[t.PDF_417=10]="PDF_417",t[t.QR_CODE=11]="QR_CODE",t[t.RSS_14=12]="RSS_14",t[t.RSS_EXPANDED=13]="RSS_EXPANDED",t[t.UPC_A=14]="UPC_A",t[t.UPC_E=15]="UPC_E",t[t.UPC_EAN_EXTENSION=16]="UPC_EAN_EXTENSION"}(s||(s={}));var o,a=s;class h extends n{}h.kind="IllegalArgumentException";class l extends n{}l.kind="IndexOutOfBoundsException";class c extends l{constructor(t,e){super(e),this.index=t,this.message=e}}c.kind="ArrayIndexOutOfBoundsException";class u{static arraycopy(t,e,r,n,i){if(t===r&&e<n)for(n+=i-1,e+=i-1;i--;)r[n--]=t[e--];else for(;i--;)r[n++]=t[e++]}static currentTimeMillis(){return Date.now()}}class w{static fill(t,e){for(let r=0,n=t.length;r<n;r++)t[r]=e}static fillWithin(t,e,r,n){w.rangeCheck(t.length,e,r);for(let i=e;i<r;i++)t[i]=n}static rangeCheck(t,e,r){if(e>r)throw new h("fromIndex("+e+") > toIndex("+r+")");if(e<0)throw new c(e);if(r>t)throw new c(r)}static asList(...t){return t}static create(t,e,r){return Array.from({length:t}).map((t=>Array.from({length:e}).fill(r)))}static createInt32Array(t,e,r){return Array.from({length:t}).map((t=>Int32Array.from({length:e}).fill(r)))}static equals(t,e){if(!t)return!1;if(!e)return!1;if(!t.length)return!1;if(!e.length)return!1;if(t.length!==e.length)return!1;for(let r=0,n=t.length;r<n;r++)if(t[r]!==e[r])return!1;return!0}static hashCode(t){if(null===t)return 0;let e=1;for(const r of t)e=31*e+r;return e}static fillUint8Array(t,e){for(let r=0;r!==t.length;r++)t[r]=e}static copyOf(t,e){return t.slice(0,e)}static copyOfUint8Array(t,e){if(t.length<=e){const r=new Uint8Array(e);return r.set(t),r}return t.slice(0,e)}static copyOfRange(t,e,r){const n=r-e,i=new Int32Array(n);return u.arraycopy(t,e,i,0,n),i}static binarySearch(t,e,r){void 0===r&&(r=w.numberComparator);let n=0,i=t.length-1;for(;n<=i;){const s=i+n>>1,o=r(e,t[s]);if(o>0)n=s+1;else{if(!(o<0))return s;i=s-1}}return-n-1}static numberComparator(t,e){return t-e}}!function(t){t[t.OTHER=0]="OTHER",t[t.PURE_BARCODE=1]="PURE_BARCODE",t[t.POSSIBLE_FORMATS=2]="POSSIBLE_FORMATS",t[t.TRY_HARDER=3]="TRY_HARDER",t[t.CHARACTER_SET=4]="CHARACTER_SET",t[t.ALLOWED_LENGTHS=5]="ALLOWED_LENGTHS",t[t.ASSUME_CODE_39_CHECK_DIGIT=6]="ASSUME_CODE_39_CHECK_DIGIT",t[t.ENABLE_CODE_39_EXTENDED_MODE=7]="ENABLE_CODE_39_EXTENDED_MODE",t[t.ASSUME_GS1=8]="ASSUME_GS1",t[t.RETURN_CODABAR_START_END=9]="RETURN_CODABAR_START_END",t[t.NEED_RESULT_POINT_CALLBACK=10]="NEED_RESULT_POINT_CALLBACK",t[t.ALLOWED_EAN_EXTENSIONS=11]="ALLOWED_EAN_EXTENSIONS"}(o||(o={}));var f,d,g=o;class I extends n{static getFormatInstance(){return new I}}I.kind="FormatException",function(t){t[t.Cp437=0]="Cp437",t[t.ISO8859_1=1]="ISO8859_1",t[t.ISO8859_2=2]="ISO8859_2",t[t.ISO8859_3=3]="ISO8859_3",t[t.ISO8859_4=4]="ISO8859_4",t[t.ISO8859_5=5]="ISO8859_5",t[t.ISO8859_6=6]="ISO8859_6",t[t.ISO8859_7=7]="ISO8859_7",t[t.ISO8859_8=8]="ISO8859_8",t[t.ISO8859_9=9]="ISO8859_9",t[t.ISO8859_10=10]="ISO8859_10",t[t.ISO8859_11=11]="ISO8859_11",t[t.ISO8859_13=12]="ISO8859_13",t[t.ISO8859_14=13]="ISO8859_14",t[t.ISO8859_15=14]="ISO8859_15",t[t.ISO8859_16=15]="ISO8859_16",t[t.SJIS=16]="SJIS",t[t.Cp1250=17]="Cp1250",t[t.Cp1251=18]="Cp1251",t[t.Cp1252=19]="Cp1252",t[t.Cp1256=20]="Cp1256",t[t.UnicodeBigUnmarked=21]="UnicodeBigUnmarked",t[t.UTF8=22]="UTF8",t[t.ASCII=23]="ASCII",t[t.Big5=24]="Big5",t[t.GB18030=25]="GB18030",t[t.EUC_KR=26]="EUC_KR"}(f||(f={}));class S{constructor(t,e,r,...n){this.valueIdentifier=t,this.name=r,this.values="number"==typeof e?Int32Array.from([e]):e,this.otherEncodingNames=n,S.VALUE_IDENTIFIER_TO_ECI.set(t,this),S.NAME_TO_ECI.set(r,this);const i=this.values;for(let t=0,e=i.length;t!==e;t++){const e=i[t];S.VALUES_TO_ECI.set(e,this)}for(const t of n)S.NAME_TO_ECI.set(t,this)}getValueIdentifier(){return this.valueIdentifier}getName(){return this.name}getValue(){return this.values[0]}static getCharacterSetECIByValue(t){if(t<0||t>=900)throw new I("incorect value");const e=S.VALUES_TO_ECI.get(t);if(void 0===e)throw new I("incorect value");return e}static getCharacterSetECIByName(t){const e=S.NAME_TO_ECI.get(t);if(void 0===e)throw new I("incorect value");return e}equals(t){if(!(t instanceof S))return!1;const e=t;return this.getName()===e.getName()}}S.VALUE_IDENTIFIER_TO_ECI=new Map,S.VALUES_TO_ECI=new Map,S.NAME_TO_ECI=new Map,S.Cp437=new S(f.Cp437,Int32Array.from([0,2]),"Cp437"),S.ISO8859_1=new S(f.ISO8859_1,Int32Array.from([1,3]),"ISO-8859-1","ISO88591","ISO8859_1"),S.ISO8859_2=new S(f.ISO8859_2,4,"ISO-8859-2","ISO88592","ISO8859_2"),S.ISO8859_3=new S(f.ISO8859_3,5,"ISO-8859-3","ISO88593","ISO8859_3"),S.ISO8859_4=new S(f.ISO8859_4,6,"ISO-8859-4","ISO88594","ISO8859_4"),S.ISO8859_5=new S(f.ISO8859_5,7,"ISO-8859-5","ISO88595","ISO8859_5"),S.ISO8859_6=new S(f.ISO8859_6,8,"ISO-8859-6","ISO88596","ISO8859_6"),S.ISO8859_7=new S(f.ISO8859_7,9,"ISO-8859-7","ISO88597","ISO8859_7"),S.ISO8859_8=new S(f.ISO8859_8,10,"ISO-8859-8","ISO88598","ISO8859_8"),S.ISO8859_9=new S(f.ISO8859_9,11,"ISO-8859-9","ISO88599","ISO8859_9"),S.ISO8859_10=new S(f.ISO8859_10,12,"ISO-8859-10","ISO885910","ISO8859_10"),S.ISO8859_11=new S(f.ISO8859_11,13,"ISO-8859-11","ISO885911","ISO8859_11"),S.ISO8859_13=new S(f.ISO8859_13,15,"ISO-8859-13","ISO885913","ISO8859_13"),S.ISO8859_14=new S(f.ISO8859_14,16,"ISO-8859-14","ISO885914","ISO8859_14"),S.ISO8859_15=new S(f.ISO8859_15,17,"ISO-8859-15","ISO885915","ISO8859_15"),S.ISO8859_16=new S(f.ISO8859_16,18,"ISO-8859-16","ISO885916","ISO8859_16"),S.SJIS=new S(f.SJIS,20,"SJIS","Shift_JIS"),S.Cp1250=new S(f.Cp1250,21,"Cp1250","windows-1250"),S.Cp1251=new S(f.Cp1251,22,"Cp1251","windows-1251"),S.Cp1252=new S(f.Cp1252,23,"Cp1252","windows-1252"),S.Cp1256=new S(f.Cp1256,24,"Cp1256","windows-1256"),S.UnicodeBigUnmarked=new S(f.UnicodeBigUnmarked,25,"UnicodeBigUnmarked","UTF-16BE","UnicodeBig"),S.UTF8=new S(f.UTF8,26,"UTF8","UTF-8"),S.ASCII=new S(f.ASCII,Int32Array.from([27,170]),"ASCII","US-ASCII"),S.Big5=new S(f.Big5,28,"Big5"),S.GB18030=new S(f.GB18030,29,"GB18030","GB2312","EUC_CN","GBK"),S.EUC_KR=new S(f.EUC_KR,30,"EUC_KR","EUC-KR");class A extends n{}A.kind="UnsupportedOperationException";class m{static decode(t,e){const r=this.encodingName(e);return this.customDecoder?this.customDecoder(t,r):"undefined"==typeof TextDecoder||this.shouldDecodeOnFallback(r)?this.decodeFallback(t,r):new TextDecoder(r).decode(t)}static shouldDecodeOnFallback(t){return!m.isBrowser()&&"ISO-8859-1"===t}static encode(t,e){const r=this.encodingName(e);return this.customEncoder?this.customEncoder(t,r):"undefined"==typeof TextEncoder?this.encodeFallback(t):(new TextEncoder).encode(t)}static isBrowser(){return"undefined"!=typeof window&&"[object Window]"==={}.toString.call(window)}static encodingName(t){return"string"==typeof t?t:t.getName()}static encodingCharacterSet(t){return t instanceof S?t:S.getCharacterSetECIByName(t)}static decodeFallback(t,e){const r=this.encodingCharacterSet(e);if(m.isDecodeFallbackSupported(r)){let e="";for(let r=0,n=t.length;r<n;r++){let n=t[r].toString(16);n.length<2&&(n="0"+n),e+="%"+n}return decodeURIComponent(e)}if(r.equals(S.UnicodeBigUnmarked))return String.fromCharCode.apply(null,new Uint16Array(t.buffer));throw new A(`Encoding ${this.encodingName(e)} not supported by fallback.`)}static isDecodeFallbackSupported(t){return t.equals(S.UTF8)||t.equals(S.ISO8859_1)||t.equals(S.ASCII)}static encodeFallback(t){const e=btoa(unescape(encodeURIComponent(t))).split(""),r=[];for(let t=0;t<e.length;t++)r.push(e[t].charCodeAt(0));return new Uint8Array(r)}}class C{static castAsNonUtf8Char(t,e=null){const r=e?e.getName():this.ISO88591;return m.decode(new Uint8Array([t]),r)}static guessEncoding(t,e){if(null!=e&&void 0!==e.get(g.CHARACTER_SET))return e.get(g.CHARACTER_SET).toString();const r=t.length;let n=!0,i=!0,s=!0,o=0,a=0,h=0,l=0,c=0,u=0,w=0,f=0,d=0,I=0,S=0;const A=t.length>3&&239===t[0]&&187===t[1]&&191===t[2];for(let e=0;e<r&&(n||i||s);e++){const r=255&t[e];s&&(o>0?128&r?o--:s=!1:128&r&&(64&r?(o++,32&r?(o++,16&r?(o++,8&r?s=!1:l++):h++):a++):s=!1)),n&&(r>127&&r<160?n=!1:r>159&&(r<192||215===r||247===r)&&S++),i&&(c>0?r<64||127===r||r>252?i=!1:c--:128===r||160===r||r>239?i=!1:r>160&&r<224?(u++,f=0,w++,w>d&&(d=w)):r>127?(c++,w=0,f++,f>I&&(I=f)):(w=0,f=0))}return s&&o>0&&(s=!1),i&&c>0&&(i=!1),s&&(A||a+h+l>0)?C.UTF8:i&&(C.ASSUME_SHIFT_JIS||d>=3||I>=3)?C.SHIFT_JIS:n&&i?2===d&&2===u||10*S>=r?C.SHIFT_JIS:C.ISO88591:n?C.ISO88591:i?C.SHIFT_JIS:s?C.UTF8:C.PLATFORM_DEFAULT_ENCODING}static format(t,...e){let r=-1;return t.replace(/%(-)?(0?[0-9]+)?([.][0-9]+)?([#][0-9]+)?([scfpexd%])/g,(function(t,n,i,s,o,a){if("%%"===t)return"%";if(void 0===e[++r])return;t=s?parseInt(s.substr(1)):void 0;let h,l=o?parseInt(o.substr(1)):void 0;switch(a){case"s":h=e[r];break;case"c":h=e[r][0];break;case"f":h=parseFloat(e[r]).toFixed(t);break;case"p":h=parseFloat(e[r]).toPrecision(t);break;case"e":h=parseFloat(e[r]).toExponential(t);break;case"x":h=parseInt(e[r]).toString(l||16);break;case"d":h=parseFloat(parseInt(e[r],l||10).toPrecision(t)).toFixed(0)}h="object"==typeof h?JSON.stringify(h):(+h).toString(l);let c=parseInt(i),u=i&&i[0]+""=="0"?"0":" ";for(;h.length<c;)h=void 0!==n?h+u:u+h;return h}))}static getBytes(t,e){return m.encode(t,e)}static getCharCode(t,e=0){return t.charCodeAt(e)}static getCharAt(t){return String.fromCharCode(t)}}C.SHIFT_JIS=S.SJIS.getName(),C.GB2312="GB2312",C.ISO88591=S.ISO8859_1.getName(),C.EUC_JP="EUC_JP",C.UTF8=S.UTF8.getName(),C.PLATFORM_DEFAULT_ENCODING=C.UTF8,C.ASSUME_SHIFT_JIS=!1;class E{constructor(t=""){this.value=t}enableDecoding(t){return this.encoding=t,this}append(t){return"string"==typeof t?this.value+=t.toString():this.encoding?this.value+=C.castAsNonUtf8Char(t,this.encoding):this.value+=String.fromCharCode(t),this}appendChars(t,e,r){for(let n=e;e<e+r;n++)this.append(t[n]);return this}length(){return this.value.length}charAt(t){return this.value.charAt(t)}deleteCharAt(t){this.value=this.value.substr(0,t)+this.value.substring(t+1)}setCharAt(t,e){this.value=this.value.substr(0,t)+e+this.value.substr(t+1)}substring(t,e){return this.value.substring(t,e)}setLengthToZero(){this.value=""}toString(){return this.value}insert(t,e){this.value=this.value.substring(0,t)+e+this.value.substring(t)}}class _{static numberOfTrailingZeros(t){let e;if(0===t)return 32;let r=31;return e=t<<16,0!==e&&(r-=16,t=e),e=t<<8,0!==e&&(r-=8,t=e),e=t<<4,0!==e&&(r-=4,t=e),e=t<<2,0!==e&&(r-=2,t=e),r-(t<<1>>>31)}static numberOfLeadingZeros(t){if(0===t)return 32;let e=1;return t>>>16==0&&(e+=16,t<<=16),t>>>24==0&&(e+=8,t<<=8),t>>>28==0&&(e+=4,t<<=4),t>>>30==0&&(e+=2,t<<=2),e-=t>>>31,e}static toHexString(t){return t.toString(16)}static toBinaryString(t){return String(parseInt(String(t),2))}static bitCount(t){return t=(t=(858993459&(t-=t>>>1&1431655765))+(t>>>2&858993459))+(t>>>4)&252645135,t+=t>>>8,63&(t+=t>>>16)}static truncDivision(t,e){return Math.trunc(t/e)}static parseInt(t,e=void 0){return parseInt(t,e)}}_.MIN_VALUE_32_BITS=-2147483648,_.MAX_VALUE=Number.MAX_SAFE_INTEGER;class p{constructor(t,e){void 0===t?(this.size=0,this.bits=new Int32Array(1)):(this.size=t,this.bits=e??p.makeArray(t))}getSize(){return this.size}getSizeInBytes(){return Math.floor((this.size+7)/8)}ensureCapacity(t){if(t>32*this.bits.length){const e=p.makeArray(t);u.arraycopy(this.bits,0,e,0,this.bits.length),this.bits=e}}get(t){return!!(this.bits[Math.floor(t/32)]&1<<(31&t))}set(t){this.bits[Math.floor(t/32)]|=1<<(31&t)}flip(t){this.bits[Math.floor(t/32)]^=1<<(31&t)}getNextSet(t){const e=this.size;if(t>=e)return e;const r=this.bits;let n=Math.floor(t/32),i=r[n];i&=~((1<<(31&t))-1);const s=r.length;for(;0===i;){if(++n===s)return e;i=r[n]}const o=32*n+_.numberOfTrailingZeros(i);return o>e?e:o}getNextUnset(t){const e=this.size;if(t>=e)return e;const r=this.bits;let n=Math.floor(t/32),i=~r[n];i&=~((1<<(31&t))-1);const s=r.length;for(;0===i;){if(++n===s)return e;i=~r[n]}const o=32*n+_.numberOfTrailingZeros(i);return o>e?e:o}setBulk(t,e){this.bits[Math.floor(t/32)]=e}setRange(t,e){if(e<t||t<0||e>this.size)throw new h;if(e===t)return;e--;const r=Math.floor(t/32),n=Math.floor(e/32),i=this.bits;for(let s=r;s<=n;s++){const o=(2<<(s<n?31:31&e))-(1<<(s>r?0:31&t));i[s]|=o}}clear(){const t=this.bits.length,e=this.bits;for(let r=0;r<t;r++)e[r]=0}isRange(t,e,r){if(e<t||t<0||e>this.size)throw new h;if(e===t)return!0;e--;const n=Math.floor(t/32),i=Math.floor(e/32),s=this.bits;for(let o=n;o<=i;o++){const a=(2<<(o<i?31:31&e))-(1<<(o>n?0:31&t))&4294967295;if((s[o]&a)!==(r?a:0))return!1}return!0}appendBit(t){this.ensureCapacity(this.size+1),t&&(this.bits[Math.floor(this.size/32)]|=1<<(31&this.size)),this.size++}appendBits(t,e){if(e<0||e>32)throw new h("Num bits must be between 0 and 32");this.ensureCapacity(this.size+e);for(let r=e;r>0;r--)this.appendBit(1==(t>>r-1&1))}appendBitArray(t){const e=t.size;this.ensureCapacity(this.size+e);for(let r=0;r<e;r++)this.appendBit(t.get(r))}xor(t){if(this.size!==t.size)throw new h("Sizes don't match");const e=this.bits;for(let r=0,n=e.length;r<n;r++)e[r]^=t.bits[r]}toBytes(t,e,r,n){for(let i=0;i<n;i++){let n=0;for(let e=0;e<8;e++)this.get(t)&&(n|=1<<7-e),t++;e[r+i]=n}}getBitArray(){return this.bits}reverse(){const t=new Int32Array(this.bits.length),e=Math.floor((this.size-1)/32),r=e+1,n=this.bits;for(let i=0;i<r;i++){let r=n[i];r=r>>1&1431655765|(1431655765&r)<<1,r=r>>2&858993459|(858993459&r)<<2,r=r>>4&252645135|(252645135&r)<<4,r=r>>8&16711935|(16711935&r)<<8,r=r>>16&65535|(65535&r)<<16,t[e-i]=r}if(this.size!==32*r){const e=32*r-this.size;let n=t[0]>>>e;for(let i=1;i<r;i++){const r=t[i];n|=r<<32-e,t[i-1]=n,n=r>>>e}t[r-1]=n}this.bits=t}static makeArray(t){return new Int32Array(Math.floor((t+31)/32))}equals(t){if(!(t instanceof p))return!1;const e=t;return this.size===e.size&&w.equals(this.bits,e.bits)}hashCode(){return 31*this.size+w.hashCode(this.bits)}toString(){let t="";for(let e=0,r=this.size;e<r;e++)7&e||(t+=" "),t+=this.get(e)?"X":".";return t}clone(){return new p(this.size,this.bits.slice())}toArray(){let t=[];for(let e=0,r=this.size;e<r;e++)t.push(this.get(e));return t}}class M{constructor(t,e,r,n){if(this.width=t,this.height=e,this.rowSize=r,this.bits=n,null==e&&(e=t),this.height=e,t<1||e<1)throw new h("Both dimensions must be greater than 0");null==r&&(r=(t+31)/32|0),this.rowSize=r,null==n&&(this.bits=new Int32Array(this.rowSize*this.height))}static parseFromBooleanArray(t){const e=t.length,r=t[0].length,n=new M(r,e);for(let i=0;i<e;i++){const e=t[i];for(let t=0;t<r;t++)e[t]&&n.set(t,i)}return n}static parseFromString(t,e,r){if(null===t)throw new h("stringRepresentation cannot be null");const n=new Array(t.length);let i=0,s=0,o=-1,a=0,l=0;for(;l<t.length;){const c=t.charAt(l);if("\n"===c||"\r"===c){if(i>s){if(-1===o)o=i-s;else if(i-s!==o)throw new h("row lengths do not match");s=i,a++}l++}else if(t.substring(l,l+e.length)===e)l+=e.length,n[i++]=!0;else{if(t.substring(l,l+r.length)!==r)throw new h("illegal character encountered: "+t.substring(l));l+=r.length,n[i++]=!1}}if(i>s){if(-1===o)o=i-s;else if(i-s!==o)throw new h("row lengths do not match");a++}const c=new M(o,a);for(let t=0;t<i;t++)n[t]&&c.set(t%o,Math.floor(t/o));return c}get(t,e){const r=e*this.rowSize+(t>>5);return!!(this.bits[r]>>>(31&t)&1)}set(t,e){const r=e*this.rowSize+(t>>5);this.bits[r]|=1<<(31&t)}unset(t,e){const r=e*this.rowSize+(t>>5);this.bits[r]&=~(1<<(31&t))}flip(t,e){const r=e*this.rowSize+(t>>5);this.bits[r]^=1<<(31&t)}xor(t){if(this.width!==t.getWidth()||this.height!==t.getHeight()||this.rowSize!==t.getRowSize())throw new h("input matrix dimensions do not match");const e=new p(1+(this.width>>5)),r=this.rowSize,n=this.bits;for(let i=0,s=this.height;i<s;i++){const s=i*r,o=t.getRow(i,e).getBitArray();for(let t=0;t<r;t++)n[s+t]^=o[t]}}clear(){const t=this.bits,e=t.length;for(let r=0;r<e;r++)t[r]=0}setRegion(t,e,r,n){if(e<0||t<0)throw new h("Left and top must be nonnegative");if(n<1||r<1)throw new h("Height and width must be at least 1");const i=t+r,s=e+n;if(s>this.height||i>this.width)throw new h("The region must fit inside the matrix");const o=this.rowSize,a=this.bits;for(let r=e;r<s;r++){const e=r*o;for(let r=t;r<i;r++)a[e+(r>>5)]|=1<<(31&r)}}getRow(t,e){null==e||e.getSize()<this.width?e=new p(this.width):e.clear();const r=this.rowSize,n=this.bits,i=t*r;for(let t=0;t<r;t++)e.setBulk(32*t,n[i+t]);return e}setRow(t,e){u.arraycopy(e.getBitArray(),0,this.bits,t*this.rowSize,this.rowSize)}rotate180(){const t=this.getWidth(),e=this.getHeight();let r=new p(t),n=new p(t);for(let t=0,i=Math.floor((e+1)/2);t<i;t++)r=this.getRow(t,r),n=this.getRow(e-1-t,n),r.reverse(),n.reverse(),this.setRow(t,n),this.setRow(e-1-t,r)}getEnclosingRectangle(){const t=this.width,e=this.height,r=this.rowSize,n=this.bits;let i=t,s=e,o=-1,a=-1;for(let t=0;t<e;t++)for(let e=0;e<r;e++){const h=n[t*r+e];if(0!==h){if(t<s&&(s=t),t>a&&(a=t),32*e<i){let t=0;for(;h<<31-t>>>0==0;)t++;32*e+t<i&&(i=32*e+t)}if(32*e+31>o){let t=31;for(;h>>>t==0;)t--;32*e+t>o&&(o=32*e+t)}}}return o<i||a<s?null:Int32Array.from([i,s,o-i+1,a-s+1])}getTopLeftOnBit(){const t=this.rowSize,e=this.bits;let r=0;for(;r<e.length&&0===e[r];)r++;if(r===e.length)return null;const n=Math.floor(r/t);let i=r%t<<5;const s=e[r];let o=0;for(;s<<31-o>>>0==0;)o++;return i+=o,Int32Array.from([i,n])}getBottomRightOnBit(){const t=this.rowSize,e=this.bits;let r=e.length-1;for(;r>=0&&0===e[r];)r--;if(r<0)return null;const n=Math.floor(r/t);let i=r%t<<5;const s=e[r];let o=31;for(;s>>>o==0;)o--;return i+=o,Int32Array.from([i,n])}getWidth(){return this.width}getHeight(){return this.height}getRowSize(){return this.rowSize}equals(t){if(!(t instanceof M))return!1;const e=t;return this.width===e.width&&this.height===e.height&&this.rowSize===e.rowSize&&w.equals(this.bits,e.bits)}hashCode(){let t=this.width;return t=31*t+this.height,t=31*t+this.rowSize,t=31*t+w.hashCode(this.bits),t}toString(t="X ",e=" ",r="\n"){return this.buildToString(t,e,r)}buildToString(t,e,r){const n=new E,i=this.height,s=this.width;if(void 0===i||void 0===s)throw new Error("Matrix dimensions are undefined");for(let o=0;o<i;o++){for(let r=0;r<s;r++)n.append(this.get(r,o)?t:e);n.append(r)}return n.toString()}clone(){return new M(this.width,this.height,this.rowSize,this.bits.slice())}}class O{constructor(t=null,e,r=(null==e?0:8*e.length),n,i,s=u.currentTimeMillis()){this.text=t,this.rawBytes=e,this.numBits=r,this.resultPoints=n,this.format=i,this.timestamp=s,this.text=t,this.rawBytes=e,this.numBits=r??(null==e?0:8*e.length),this.resultPoints=n,this.format=i,this.resultMetadata=new Map,this.timestamp=s??u.currentTimeMillis()}getText(){return this.text?this.text:null}getRawBytes(){return this.rawBytes}getNumBits(){return this.numBits}getResultPoints(){return this.resultPoints}getBarcodeFormat(){return this.format}getResultMetadata(){return this.resultMetadata}putMetadata(t,e){null===this.resultMetadata&&(this.resultMetadata=new Map),this.resultMetadata.set(t,e)}putAllMetadata(t){null!==t&&(null===this.resultMetadata?this.resultMetadata=t:this.resultMetadata=new Map(t))}addResultPoints(t){const e=this.resultPoints;if(null===e)this.resultPoints=t;else if(null!==t&&t.length>0){const r=new Array(e.length+t.length);u.arraycopy(e,0,r,0,e.length),u.arraycopy(t,0,r,e.length,t.length),this.resultPoints=r}}getTimestamp(){return this.timestamp}toString(){return null===this.text?this.resultPoints.toString():this.text}}!function(t){t[t.OTHER=0]="OTHER",t[t.ORIENTATION=1]="ORIENTATION",t[t.BYTE_SEGMENTS=2]="BYTE_SEGMENTS",t[t.ERROR_CORRECTION_LEVEL=3]="ERROR_CORRECTION_LEVEL",t[t.ISSUE_NUMBER=4]="ISSUE_NUMBER",t[t.SUGGESTED_PRICE=5]="SUGGESTED_PRICE",t[t.POSSIBLE_COUNTRY=6]="POSSIBLE_COUNTRY",t[t.UPC_EAN_EXTENSION=7]="UPC_EAN_EXTENSION",t[t.PDF417_EXTRA_METADATA=8]="PDF417_EXTRA_METADATA",t[t.STRUCTURED_APPEND_SEQUENCE=9]="STRUCTURED_APPEND_SEQUENCE",t[t.STRUCTURED_APPEND_PARITY=10]="STRUCTURED_APPEND_PARITY"}(d||(d={}));var N,T,b,y=d;class R extends n{static getChecksumInstance(){return new R}}R.kind="ChecksumException";class B extends n{}B.kind="ArithmeticException";class D{exp(t){return this.expTable[t]}log(t){if(0===t)throw new h;return this.logTable[t]}static addOrSubtract(t,e){return t^e}}class P{constructor(t,e){if(0===e.length)throw new h;this.field=t;const r=e.length;if(r>1&&0===e[0]){let t=1;for(;t<r&&0===e[t];)t++;t===r?this.coefficients=Int32Array.from([0]):(this.coefficients=new Int32Array(r-t),u.arraycopy(e,t,this.coefficients,0,this.coefficients.length))}else this.coefficients=e}getCoefficients(){return this.coefficients}getDegree(){return this.coefficients.length-1}isZero(){return 0===this.coefficients[0]}getCoefficient(t){return this.coefficients[this.coefficients.length-1-t]}evaluateAt(t){if(0===t)return this.getCoefficient(0);const e=this.coefficients;let r;if(1===t){r=0;for(let t=0,n=e.length;t!==n;t++){const n=e[t];r=D.addOrSubtract(r,n)}return r}r=e[0];const n=e.length,i=this.field;for(let s=1;s<n;s++)r=D.addOrSubtract(i.multiply(t,r),e[s]);return r}addOrSubtract(t){if(!this.field.equals(t.field))throw new h("GenericGFPolys do not have same GenericGF field");if(this.isZero())return t;if(t.isZero())return this;let e=this.coefficients,r=t.coefficients;if(e.length>r.length){const t=e;e=r,r=t}let n=new Int32Array(r.length);const i=r.length-e.length;u.arraycopy(r,0,n,0,i);for(let t=i;t<r.length;t++)n[t]=D.addOrSubtract(e[t-i],r[t]);return new P(this.field,n)}multiply(t){if(!this.field.equals(t.field))throw new h("GenericGFPolys do not have same GenericGF field");if(this.isZero()||t.isZero())return this.field.getZero();const e=this.coefficients,r=e.length,n=t.coefficients,i=n.length,s=new Int32Array(r+i-1),o=this.field;for(let t=0;t<r;t++){const r=e[t];for(let e=0;e<i;e++)s[t+e]=D.addOrSubtract(s[t+e],o.multiply(r,n[e]))}return new P(o,s)}multiplyScalar(t){if(0===t)return this.field.getZero();if(1===t)return this;const e=this.coefficients.length,r=this.field,n=new Int32Array(e),i=this.coefficients;for(let s=0;s<e;s++)n[s]=r.multiply(i[s],t);return new P(r,n)}multiplyByMonomial(t,e){if(t<0)throw new h;if(0===e)return this.field.getZero();const r=this.coefficients,n=r.length,i=new Int32Array(n+t),s=this.field;for(let t=0;t<n;t++)i[t]=s.multiply(r[t],e);return new P(s,i)}divide(t){if(!this.field.equals(t.field))throw new h("GenericGFPolys do not have same GenericGF field");if(t.isZero())throw new h("Divide by 0");const e=this.field;let r=e.getZero(),n=this;const i=t.getCoefficient(t.getDegree()),s=e.inverse(i);for(;n.getDegree()>=t.getDegree()&&!n.isZero();){const i=n.getDegree()-t.getDegree(),o=e.multiply(n.getCoefficient(n.getDegree()),s),a=t.multiplyByMonomial(i,o),h=e.buildMonomial(i,o);r=r.addOrSubtract(h),n=n.addOrSubtract(a)}return[r,n]}toString(){let t="";for(let e=this.getDegree();e>=0;e--){let r=this.getCoefficient(e);if(0!==r){if(r<0?(t+=" - ",r=-r):t.length>0&&(t+=" + "),0===e||1!==r){const e=this.field.log(r);0===e?t+="1":1===e?t+="a":(t+="a^",t+=e)}0!==e&&(1===e?t+="x":(t+="x^",t+=e))}}return t}}class k extends D{constructor(t,e,r){super(),this.primitive=t,this.size=e,this.generatorBase=r;const n=new Int32Array(e);let i=1;for(let r=0;r<e;r++)n[r]=i,i*=2,i>=e&&(i^=t,i&=e-1);this.expTable=n;const s=new Int32Array(e);for(let t=0;t<e-1;t++)s[n[t]]=t;this.logTable=s,this.zero=new P(this,Int32Array.from([0])),this.one=new P(this,Int32Array.from([1]))}getZero(){return this.zero}getOne(){return this.one}buildMonomial(t,e){if(t<0)throw new h;if(0===e)return this.zero;const r=new Int32Array(t+1);return r[0]=e,new P(this,r)}inverse(t){if(0===t)throw new B;return this.expTable[this.size-this.logTable[t]-1]}multiply(t,e){return 0===t||0===e?0:this.expTable[(this.logTable[t]+this.logTable[e])%(this.size-1)]}getSize(){return this.size}getGeneratorBase(){return this.generatorBase}toString(){return"GF(0x"+_.toHexString(this.primitive)+","+this.size+")"}equals(t){return t===this}}k.AZTEC_DATA_12=new k(4201,4096,1),k.AZTEC_DATA_10=new k(1033,1024,1),k.AZTEC_DATA_6=new k(67,64,1),k.AZTEC_PARAM=new k(19,16,1),k.QR_CODE_FIELD_256=new k(285,256,0),k.DATA_MATRIX_FIELD_256=new k(301,256,1),k.AZTEC_DATA_8=k.DATA_MATRIX_FIELD_256,k.MAXICODE_FIELD_64=k.AZTEC_DATA_6;class U extends n{}U.kind="IllegalStateException";class F extends n{}F.kind="ReedSolomonException";class v{constructor(t){this.field=t}decode(t,e){const r=this.field,n=new P(r,t),i=new Int32Array(e);let s=!0;for(let t=0;t<e;t++){const e=n.evaluateAt(r.exp(t+r.getGeneratorBase()));i[i.length-1-t]=e,0!==e&&(s=!1)}if(s)return;const o=new P(r,i),a=this.runEuclideanAlgorithm(r.buildMonomial(e,1),o,e),h=a[0],l=a[1],c=this.findErrorLocations(h),u=this.findErrorMagnitudes(l,c);for(let e=0;e<c.length;e++){const n=t.length-1-r.log(c[e]);if(n<0)throw new F("Bad error location");t[n]=k.addOrSubtract(t[n],u[e])}}runEuclideanAlgorithm(t,e,r){if(t.getDegree()<e.getDegree()){const r=t;t=e,e=r}const n=this.field;let i=t,s=e,o=n.getZero(),a=n.getOne();for(;s.getDegree()>=(r/2|0);){let t=i,e=o;if(i=s,o=a,i.isZero())throw new F("r_{i-1} was zero");s=t;let r=n.getZero();const h=i.getCoefficient(i.getDegree()),l=n.inverse(h);for(;s.getDegree()>=i.getDegree()&&!s.isZero();){const t=s.getDegree()-i.getDegree(),e=n.multiply(s.getCoefficient(s.getDegree()),l);r=r.addOrSubtract(n.buildMonomial(t,e)),s=s.addOrSubtract(i.multiplyByMonomial(t,e))}if(a=r.multiply(o).addOrSubtract(e),s.getDegree()>=i.getDegree())throw new U("Division algorithm failed to reduce polynomial?")}const h=a.getCoefficient(0);if(0===h)throw new F("sigmaTilde(0) was zero");const l=n.inverse(h);return[a.multiplyScalar(l),s.multiplyScalar(l)]}findErrorLocations(t){const e=t.getDegree();if(1===e)return Int32Array.from([t.getCoefficient(1)]);const r=new Int32Array(e);let n=0;const i=this.field;for(let s=1;s<i.getSize()&&n<e;s++)0===t.evaluateAt(s)&&(r[n]=i.inverse(s),n++);if(n!==e)throw new F("Error locator degree does not match number of roots");return r}findErrorMagnitudes(t,e){const r=e.length,n=new Int32Array(r),i=this.field;for(let s=0;s<r;s++){const o=i.inverse(e[s]);let a=1;for(let t=0;t<r;t++)if(s!==t){const r=i.multiply(e[t],o),n=1&r?-2&r:1|r;a=i.multiply(a,n)}n[s]=i.multiply(t.evaluateAt(o),i.inverse(a)),0!==i.getGeneratorBase()&&(n[s]=i.multiply(n[s],o))}return n}}!function(t){t[t.DATA_MASK_000=0]="DATA_MASK_000",t[t.DATA_MASK_001=1]="DATA_MASK_001",t[t.DATA_MASK_010=2]="DATA_MASK_010",t[t.DATA_MASK_011=3]="DATA_MASK_011",t[t.DATA_MASK_100=4]="DATA_MASK_100",t[t.DATA_MASK_101=5]="DATA_MASK_101",t[t.DATA_MASK_110=6]="DATA_MASK_110",t[t.DATA_MASK_111=7]="DATA_MASK_111"}(N||(N={}));class x{constructor(t,e){this.value=t,this.isMasked=e}unmaskBitMatrix(t,e){for(let r=0;r<e;r++)for(let n=0;n<e;n++)this.isMasked(r,n)&&t.flip(n,r)}}x.values=new Map([[N.DATA_MASK_000,new x(N.DATA_MASK_000,((t,e)=>!(t+e&1)))],[N.DATA_MASK_001,new x(N.DATA_MASK_001,((t,e)=>!(1&t)))],[N.DATA_MASK_010,new x(N.DATA_MASK_010,((t,e)=>e%3==0))],[N.DATA_MASK_011,new x(N.DATA_MASK_011,((t,e)=>(t+e)%3==0))],[N.DATA_MASK_100,new x(N.DATA_MASK_100,((t,e)=>!(Math.floor(t/2)+Math.floor(e/3)&1)))],[N.DATA_MASK_101,new x(N.DATA_MASK_101,((t,e)=>t*e%6==0))],[N.DATA_MASK_110,new x(N.DATA_MASK_110,((t,e)=>t*e%6<3))],[N.DATA_MASK_111,new x(N.DATA_MASK_111,((t,e)=>!(t+e+t*e%3&1)))]]);class L extends n{}L.kind="ArgumentException",function(t){t[t.L=0]="L",t[t.M=1]="M",t[t.Q=2]="Q",t[t.H=3]="H"}(T||(T={}));class z{constructor(t,e,r){this.value=t,this.stringValue=e,this.bits=r,z.FOR_BITS.set(r,this),z.FOR_VALUE.set(t,this)}getValue(){return this.value}getBits(){return this.bits}static fromString(t){switch(t){case"L":return z.L;case"M":return z.M;case"Q":return z.Q;case"H":return z.H;default:throw new L(t+"not available")}}toString(){return this.stringValue}equals(t){if(!(t instanceof z))return!1;const e=t;return this.value===e.value}static forBits(t){if(t<0||t>=z.FOR_BITS.size)throw new h;return z.FOR_BITS.get(t)}}z.FOR_BITS=new Map,z.FOR_VALUE=new Map,z.L=new z(T.L,"L",1),z.M=new z(T.M,"M",0),z.Q=new z(T.Q,"Q",3),z.H=new z(T.H,"H",2);class H{constructor(t){this.errorCorrectionLevel=z.forBits(t>>3&3),this.dataMask=7&t}static numBitsDiffering(t,e){return _.bitCount(t^e)}static decodeFormatInformation(t,e){const r=H.doDecodeFormatInformation(t,e);return null!==r?r:H.doDecodeFormatInformation(t^H.FORMAT_INFO_MASK_QR,e^H.FORMAT_INFO_MASK_QR)}static doDecodeFormatInformation(t,e){let r=Number.MAX_SAFE_INTEGER,n=0;for(const i of H.FORMAT_INFO_DECODE_LOOKUP){const s=i[0];if(s===t||s===e)return new H(i[1]);let o=H.numBitsDiffering(t,s);o<r&&(n=i[1],r=o),t!==e&&(o=H.numBitsDiffering(e,s),o<r&&(n=i[1],r=o))}return r<=3?new H(n):null}getErrorCorrectionLevel(){return this.errorCorrectionLevel}getDataMask(){return this.dataMask}hashCode(){return this.errorCorrectionLevel.getBits()<<3|this.dataMask}equals(t){if(!(t instanceof H))return!1;const e=t;return this.errorCorrectionLevel===e.errorCorrectionLevel&&this.dataMask===e.dataMask}}H.FORMAT_INFO_MASK_QR=21522,H.FORMAT_INFO_DECODE_LOOKUP=[Int32Array.from([21522,0]),Int32Array.from([20773,1]),Int32Array.from([24188,2]),Int32Array.from([23371,3]),Int32Array.from([17913,4]),Int32Array.from([16590,5]),Int32Array.from([20375,6]),Int32Array.from([19104,7]),Int32Array.from([30660,8]),Int32Array.from([29427,9]),Int32Array.from([32170,10]),Int32Array.from([30877,11]),Int32Array.from([26159,12]),Int32Array.from([25368,13]),Int32Array.from([27713,14]),Int32Array.from([26998,15]),Int32Array.from([5769,16]),Int32Array.from([5054,17]),Int32Array.from([7399,18]),Int32Array.from([6608,19]),Int32Array.from([1890,20]),Int32Array.from([597,21]),Int32Array.from([3340,22]),Int32Array.from([2107,23]),Int32Array.from([13663,24]),Int32Array.from([12392,25]),Int32Array.from([16177,26]),Int32Array.from([14854,27]),Int32Array.from([9396,28]),Int32Array.from([8579,29]),Int32Array.from([11994,30]),Int32Array.from([11245,31])];class K{constructor(t,e){this.count=t,this.dataCodewords=e}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class V{constructor(t,...e){this.ecCodewordsPerBlock=t,this.ecBlocks=e}getECCodewordsPerBlock(){return this.ecCodewordsPerBlock}getNumBlocks(){let t=0;const e=this.ecBlocks;for(const r of e)t+=r.getCount();return t}getTotalECCodewords(){return this.ecCodewordsPerBlock*this.getNumBlocks()}getECBlocks(){return this.ecBlocks}}class G{constructor(t,e,...r){this.versionNumber=t,this.alignmentPatternCenters=e,this.ecBlocks=r;let n=0;const i=r[0].getECCodewordsPerBlock(),s=r[0].getECBlocks();for(const t of s)n+=t.getCount()*(t.getDataCodewords()+i);this.totalCodewords=n}getVersionNumber(){return this.versionNumber}getAlignmentPatternCenters(){return this.alignmentPatternCenters}getTotalCodewords(){return this.totalCodewords}getDimensionForVersion(){return 17+4*this.versionNumber}getECBlocksForLevel(t){return this.ecBlocks[t.getValue()]}static getProvisionalVersionForDimension(t){if(t%4!=1)throw new I;try{return this.getVersionForNumber((t-17)/4)}catch(t){throw new I}}static getVersionForNumber(t){if(t<1||t>40)throw new h;return G.VERSIONS[t-1]}static decodeVersionInformation(t){let e=Number.MAX_SAFE_INTEGER,r=0;for(let n=0;n<G.VERSION_DECODE_INFO.length;n++){const i=G.VERSION_DECODE_INFO[n];if(i===t)return G.getVersionForNumber(n+7);const s=H.numBitsDiffering(t,i);s<e&&(r=n+7,e=s)}return e<=3?G.getVersionForNumber(r):null}buildFunctionPattern(){const t=this.getDimensionForVersion(),e=new M(t);e.setRegion(0,0,9,9),e.setRegion(t-8,0,8,9),e.setRegion(0,t-8,9,8);const r=this.alignmentPatternCenters.length;for(let t=0;t<r;t++){const n=this.alignmentPatternCenters[t]-2;for(let i=0;i<r;i++)0===t&&(0===i||i===r-1)||t===r-1&&0===i||e.setRegion(this.alignmentPatternCenters[i]-2,n,5,5)}return e.setRegion(6,9,1,t-17),e.setRegion(9,6,t-17,1),this.versionNumber>6&&(e.setRegion(t-11,0,3,6),e.setRegion(0,t-11,6,3)),e}toString(){return""+this.versionNumber}}G.VERSION_DECODE_INFO=Int32Array.from([31892,34236,39577,42195,48118,51042,55367,58893,63784,68472,70749,76311,79154,84390,87683,92361,96236,102084,102881,110507,110734,117786,119615,126325,127568,133589,136944,141498,145311,150283,152622,158308,161089,167017]),G.VERSIONS=[new G(1,new Int32Array(0),new V(7,new K(1,19)),new V(10,new K(1,16)),new V(13,new K(1,13)),new V(17,new K(1,9))),new G(2,Int32Array.from([6,18]),new V(10,new K(1,34)),new V(16,new K(1,28)),new V(22,new K(1,22)),new V(28,new K(1,16))),new G(3,Int32Array.from([6,22]),new V(15,new K(1,55)),new V(26,new K(1,44)),new V(18,new K(2,17)),new V(22,new K(2,13))),new G(4,Int32Array.from([6,26]),new V(20,new K(1,80)),new V(18,new K(2,32)),new V(26,new K(2,24)),new V(16,new K(4,9))),new G(5,Int32Array.from([6,30]),new V(26,new K(1,108)),new V(24,new K(2,43)),new V(18,new K(2,15),new K(2,16)),new V(22,new K(2,11),new K(2,12))),new G(6,Int32Array.from([6,34]),new V(18,new K(2,68)),new V(16,new K(4,27)),new V(24,new K(4,19)),new V(28,new K(4,15))),new G(7,Int32Array.from([6,22,38]),new V(20,new K(2,78)),new V(18,new K(4,31)),new V(18,new K(2,14),new K(4,15)),new V(26,new K(4,13),new K(1,14))),new G(8,Int32Array.from([6,24,42]),new V(24,new K(2,97)),new V(22,new K(2,38),new K(2,39)),new V(22,new K(4,18),new K(2,19)),new V(26,new K(4,14),new K(2,15))),new G(9,Int32Array.from([6,26,46]),new V(30,new K(2,116)),new V(22,new K(3,36),new K(2,37)),new V(20,new K(4,16),new K(4,17)),new V(24,new K(4,12),new K(4,13))),new G(10,Int32Array.from([6,28,50]),new V(18,new K(2,68),new K(2,69)),new V(26,new K(4,43),new K(1,44)),new V(24,new K(6,19),new K(2,20)),new V(28,new K(6,15),new K(2,16))),new G(11,Int32Array.from([6,30,54]),new V(20,new K(4,81)),new V(30,new K(1,50),new K(4,51)),new V(28,new K(4,22),new K(4,23)),new V(24,new K(3,12),new K(8,13))),new G(12,Int32Array.from([6,32,58]),new V(24,new K(2,92),new K(2,93)),new V(22,new K(6,36),new K(2,37)),new V(26,new K(4,20),new K(6,21)),new V(28,new K(7,14),new K(4,15))),new G(13,Int32Array.from([6,34,62]),new V(26,new K(4,107)),new V(22,new K(8,37),new K(1,38)),new V(24,new K(8,20),new K(4,21)),new V(22,new K(12,11),new K(4,12))),new G(14,Int32Array.from([6,26,46,66]),new V(30,new K(3,115),new K(1,116)),new V(24,new K(4,40),new K(5,41)),new V(20,new K(11,16),new K(5,17)),new V(24,new K(11,12),new K(5,13))),new G(15,Int32Array.from([6,26,48,70]),new V(22,new K(5,87),new K(1,88)),new V(24,new K(5,41),new K(5,42)),new V(30,new K(5,24),new K(7,25)),new V(24,new K(11,12),new K(7,13))),new G(16,Int32Array.from([6,26,50,74]),new V(24,new K(5,98),new K(1,99)),new V(28,new K(7,45),new K(3,46)),new V(24,new K(15,19),new K(2,20)),new V(30,new K(3,15),new K(13,16))),new G(17,Int32Array.from([6,30,54,78]),new V(28,new K(1,107),new K(5,108)),new V(28,new K(10,46),new K(1,47)),new V(28,new K(1,22),new K(15,23)),new V(28,new K(2,14),new K(17,15))),new G(18,Int32Array.from([6,30,56,82]),new V(30,new K(5,120),new K(1,121)),new V(26,new K(9,43),new K(4,44)),new V(28,new K(17,22),new K(1,23)),new V(28,new K(2,14),new K(19,15))),new G(19,Int32Array.from([6,30,58,86]),new V(28,new K(3,113),new K(4,114)),new V(26,new K(3,44),new K(11,45)),new V(26,new K(17,21),new K(4,22)),new V(26,new K(9,13),new K(16,14))),new G(20,Int32Array.from([6,34,62,90]),new V(28,new K(3,107),new K(5,108)),new V(26,new K(3,41),new K(13,42)),new V(30,new K(15,24),new K(5,25)),new V(28,new K(15,15),new K(10,16))),new G(21,Int32Array.from([6,28,50,72,94]),new V(28,new K(4,116),new K(4,117)),new V(26,new K(17,42)),new V(28,new K(17,22),new K(6,23)),new V(30,new K(19,16),new K(6,17))),new G(22,Int32Array.from([6,26,50,74,98]),new V(28,new K(2,111),new K(7,112)),new V(28,new K(17,46)),new V(30,new K(7,24),new K(16,25)),new V(24,new K(34,13))),new G(23,Int32Array.from([6,30,54,78,102]),new V(30,new K(4,121),new K(5,122)),new V(28,new K(4,47),new K(14,48)),new V(30,new K(11,24),new K(14,25)),new V(30,new K(16,15),new K(14,16))),new G(24,Int32Array.from([6,28,54,80,106]),new V(30,new K(6,117),new K(4,118)),new V(28,new K(6,45),new K(14,46)),new V(30,new K(11,24),new K(16,25)),new V(30,new K(30,16),new K(2,17))),new G(25,Int32Array.from([6,32,58,84,110]),new V(26,new K(8,106),new K(4,107)),new V(28,new K(8,47),new K(13,48)),new V(30,new K(7,24),new K(22,25)),new V(30,new K(22,15),new K(13,16))),new G(26,Int32Array.from([6,30,58,86,114]),new V(28,new K(10,114),new K(2,115)),new V(28,new K(19,46),new K(4,47)),new V(28,new K(28,22),new K(6,23)),new V(30,new K(33,16),new K(4,17))),new G(27,Int32Array.from([6,34,62,90,118]),new V(30,new K(8,122),new K(4,123)),new V(28,new K(22,45),new K(3,46)),new V(30,new K(8,23),new K(26,24)),new V(30,new K(12,15),new K(28,16))),new G(28,Int32Array.from([6,26,50,74,98,122]),new V(30,new K(3,117),new K(10,118)),new V(28,new K(3,45),new K(23,46)),new V(30,new K(4,24),new K(31,25)),new V(30,new K(11,15),new K(31,16))),new G(29,Int32Array.from([6,30,54,78,102,126]),new V(30,new K(7,116),new K(7,117)),new V(28,new K(21,45),new K(7,46)),new V(30,new K(1,23),new K(37,24)),new V(30,new K(19,15),new K(26,16))),new G(30,Int32Array.from([6,26,52,78,104,130]),new V(30,new K(5,115),new K(10,116)),new V(28,new K(19,47),new K(10,48)),new V(30,new K(15,24),new K(25,25)),new V(30,new K(23,15),new K(25,16))),new G(31,Int32Array.from([6,30,56,82,108,134]),new V(30,new K(13,115),new K(3,116)),new V(28,new K(2,46),new K(29,47)),new V(30,new K(42,24),new K(1,25)),new V(30,new K(23,15),new K(28,16))),new G(32,Int32Array.from([6,34,60,86,112,138]),new V(30,new K(17,115)),new V(28,new K(10,46),new K(23,47)),new V(30,new K(10,24),new K(35,25)),new V(30,new K(19,15),new K(35,16))),new G(33,Int32Array.from([6,30,58,86,114,142]),new V(30,new K(17,115),new K(1,116)),new V(28,new K(14,46),new K(21,47)),new V(30,new K(29,24),new K(19,25)),new V(30,new K(11,15),new K(46,16))),new G(34,Int32Array.from([6,34,62,90,118,146]),new V(30,new K(13,115),new K(6,116)),new V(28,new K(14,46),new K(23,47)),new V(30,new K(44,24),new K(7,25)),new V(30,new K(59,16),new K(1,17))),new G(35,Int32Array.from([6,30,54,78,102,126,150]),new V(30,new K(12,121),new K(7,122)),new V(28,new K(12,47),new K(26,48)),new V(30,new K(39,24),new K(14,25)),new V(30,new K(22,15),new K(41,16))),new G(36,Int32Array.from([6,24,50,76,102,128,154]),new V(30,new K(6,121),new K(14,122)),new V(28,new K(6,47),new K(34,48)),new V(30,new K(46,24),new K(10,25)),new V(30,new K(2,15),new K(64,16))),new G(37,Int32Array.from([6,28,54,80,106,132,158]),new V(30,new K(17,122),new K(4,123)),new V(28,new K(29,46),new K(14,47)),new V(30,new K(49,24),new K(10,25)),new V(30,new K(24,15),new K(46,16))),new G(38,Int32Array.from([6,32,58,84,110,136,162]),new V(30,new K(4,122),new K(18,123)),new V(28,new K(13,46),new K(32,47)),new V(30,new K(48,24),new K(14,25)),new V(30,new K(42,15),new K(32,16))),new G(39,Int32Array.from([6,26,54,82,110,138,166]),new V(30,new K(20,117),new K(4,118)),new V(28,new K(40,47),new K(7,48)),new V(30,new K(43,24),new K(22,25)),new V(30,new K(10,15),new K(67,16))),new G(40,Int32Array.from([6,30,58,86,114,142,170]),new V(30,new K(19,118),new K(6,119)),new V(28,new K(18,47),new K(31,48)),new V(30,new K(34,24),new K(34,25)),new V(30,new K(20,15),new K(61,16)))];class W{constructor(t){const e=t.getHeight();if(e<21||1!=(3&e))throw new I;this.bitMatrix=t}readFormatInformation(){if(null!==this.parsedFormatInfo&&void 0!==this.parsedFormatInfo)return this.parsedFormatInfo;let t=0;for(let e=0;e<6;e++)t=this.copyBit(e,8,t);t=this.copyBit(7,8,t),t=this.copyBit(8,8,t),t=this.copyBit(8,7,t);for(let e=5;e>=0;e--)t=this.copyBit(8,e,t);const e=this.bitMatrix.getHeight();let r=0;const n=e-7;for(let t=e-1;t>=n;t--)r=this.copyBit(8,t,r);for(let t=e-8;t<e;t++)r=this.copyBit(t,8,r);if(this.parsedFormatInfo=H.decodeFormatInformation(t,r),null!==this.parsedFormatInfo)return this.parsedFormatInfo;throw new I}readVersion(){if(null!==this.parsedVersion&&void 0!==this.parsedVersion)return this.parsedVersion;const t=this.bitMatrix.getHeight(),e=Math.floor((t-17)/4);if(e<=6)return G.getVersionForNumber(e);let r=0;const n=t-11;for(let e=5;e>=0;e--)for(let i=t-9;i>=n;i--)r=this.copyBit(i,e,r);let i=G.decodeVersionInformation(r);if(null!==i&&i.getDimensionForVersion()===t)return this.parsedVersion=i,i;r=0;for(let e=5;e>=0;e--)for(let i=t-9;i>=n;i--)r=this.copyBit(e,i,r);if(i=G.decodeVersionInformation(r),null!==i&&i.getDimensionForVersion()===t)return this.parsedVersion=i,i;throw new I}copyBit(t,e,r){return(this.isMirror?this.bitMatrix.get(e,t):this.bitMatrix.get(t,e))?r<<1|1:r<<1}readCodewords(){const t=this.readFormatInformation(),e=this.readVersion(),r=x.values.get(t.getDataMask()),n=this.bitMatrix.getHeight();r?.unmaskBitMatrix(this.bitMatrix,n);const i=e.buildFunctionPattern();let s=!0;const o=new Uint8Array(e.getTotalCodewords());let a=0,h=0,l=0;for(let t=n-1;t>0;t-=2){6===t&&t--;for(let e=0;e<n;e++){const r=s?n-1-e:e;for(let e=0;e<2;e++)i.get(t-e,r)||(l++,h<<=1,this.bitMatrix.get(t-e,r)&&(h|=1),8===l&&(o[a++]=h,l=0,h=0))}s=!s}if(a!==e.getTotalCodewords())throw new I;return o}remask(){if(null===this.parsedFormatInfo)return;const t=this.parsedFormatInfo&&x.values.get(this.parsedFormatInfo.getDataMask()),e=this.bitMatrix.getHeight();t?.unmaskBitMatrix(this.bitMatrix,e)}setMirror(t){this.parsedVersion=null,this.parsedFormatInfo=null,this.isMirror=t}mirror(){const t=this.bitMatrix;for(let e=0,r=t.getWidth();e<r;e++)for(let r=e+1,n=t.getHeight();r<n;r++)t.get(e,r)!==t.get(r,e)&&(t.flip(r,e),t.flip(e,r))}}class Z{constructor(t,e){this.numDataCodewords=t,this.codewords=e}static getDataBlocks(t,e,r){if(t.length!==e.getTotalCodewords())throw new h;const n=e.getECBlocksForLevel(r);let i=0;const s=n.getECBlocks();for(const t of s)i+=t.getCount();const o=new Array(i);let a=0;for(const t of s)for(let e=0;e<t.getCount();e++){const e=t.getDataCodewords(),r=n.getECCodewordsPerBlock()+e;o[a++]=new Z(e,new Uint8Array(r))}const l=o[0].codewords.length;let c=o.length-1;for(;c>=0;){if(o[c].codewords.length===l)break;c--}c++;const u=l-n.getECCodewordsPerBlock();let w=0;for(let e=0;e<u;e++)for(let r=0;r<a;r++)o[r].codewords[e]=t[w++];for(let e=c;e<a;e++)o[e].codewords[u]=t[w++];const f=o[0].codewords.length;for(let e=u;e<f;e++)for(let r=0;r<a;r++){const n=r<c?e:e+1;o[r].codewords[n]=t[w++]}return o}getNumDataCodewords(){return this.numDataCodewords}getCodewords(){return this.codewords}}class X{constructor(t){this.bytes=t,this.byteOffset=0,this.bitOffset=0}getBitOffset(){return this.bitOffset}getByteOffset(){return this.byteOffset}readBits(t){if(t<1||t>32||t>this.available())throw new h(""+t);let e=0,r=this.bitOffset,n=this.byteOffset;const i=this.bytes;if(r>0){const s=8-r,o=t<s?t:s,a=s-o,h=255>>8-o<<a;e=(i[n]&h)>>a,t-=o,r+=o,8===r&&(r=0,n++)}if(t>0){for(;t>=8;)e=e<<8|255&i[n],n++,t-=8;if(t>0){const s=8-t,o=255>>s<<s;e=e<<t|(i[n]&o)>>s,r+=t}}return this.bitOffset=r,this.byteOffset=n,e}available(){return 8*(this.bytes.length-this.byteOffset)-this.bitOffset}}class Y{constructor(t,e,r,n,i=-1,s=-1){this.rawBytes=t,this.text=e,this.byteSegments=r,this.ecLevel=n,this.structuredAppendSequenceNumber=i,this.structuredAppendParity=s,this.numBits=null==t?0:8*t.length}getRawBytes(){return this.rawBytes}getNumBits(){return this.numBits}setNumBits(t){this.numBits=t}getText(){return this.text}getByteSegments(){return this.byteSegments}getECLevel(){return this.ecLevel}getErrorsCorrected(){return this.errorsCorrected}setErrorsCorrected(t){this.errorsCorrected=t}getErasures(){return this.erasures}setErasures(t){this.erasures=t}getOther(){return this.other}setOther(t){this.other=t}hasStructuredAppend(){return this.structuredAppendParity>=0&&this.structuredAppendSequenceNumber>=0}getStructuredAppendParity(){return this.structuredAppendParity}getStructuredAppendSequenceNumber(){return this.structuredAppendSequenceNumber}}!function(t){t[t.TERMINATOR=0]="TERMINATOR",t[t.NUMERIC=1]="NUMERIC",t[t.ALPHANUMERIC=2]="ALPHANUMERIC",t[t.STRUCTURED_APPEND=3]="STRUCTURED_APPEND",t[t.BYTE=4]="BYTE",t[t.ECI=5]="ECI",t[t.KANJI=6]="KANJI",t[t.FNC1_FIRST_POSITION=7]="FNC1_FIRST_POSITION",t[t.FNC1_SECOND_POSITION=8]="FNC1_SECOND_POSITION",t[t.HANZI=9]="HANZI"}(b||(b={}));class q{constructor(t,e,r,n){this.value=t,this.stringValue=e,this.characterCountBitsForVersions=r,this.bits=n,q.FOR_BITS.set(n,this),q.FOR_VALUE.set(t,this)}static forBits(t){const e=q.FOR_BITS.get(t);if(void 0===e)throw new h;return e}getCharacterCountBits(t){const e=t.getVersionNumber();let r;return r=e<=9?0:e<=26?1:2,this.characterCountBitsForVersions[r]}getValue(){return this.value}getBits(){return this.bits}equals(t){if(!(t instanceof q))return!1;const e=t;return this.value===e.value}toString(){return this.stringValue}}q.FOR_BITS=new Map,q.FOR_VALUE=new Map,q.TERMINATOR=new q(b.TERMINATOR,"TERMINATOR",Int32Array.from([0,0,0]),0),q.NUMERIC=new q(b.NUMERIC,"NUMERIC",Int32Array.from([10,12,14]),1),q.ALPHANUMERIC=new q(b.ALPHANUMERIC,"ALPHANUMERIC",Int32Array.from([9,11,13]),2),q.STRUCTURED_APPEND=new q(b.STRUCTURED_APPEND,"STRUCTURED_APPEND",Int32Array.from([0,0,0]),3),q.BYTE=new q(b.BYTE,"BYTE",Int32Array.from([8,16,16]),4),q.ECI=new q(b.ECI,"ECI",Int32Array.from([0,0,0]),7),q.KANJI=new q(b.KANJI,"KANJI",Int32Array.from([8,10,12]),8),q.FNC1_FIRST_POSITION=new q(b.FNC1_FIRST_POSITION,"FNC1_FIRST_POSITION",Int32Array.from([0,0,0]),5),q.FNC1_SECOND_POSITION=new q(b.FNC1_SECOND_POSITION,"FNC1_SECOND_POSITION",Int32Array.from([0,0,0]),9),q.HANZI=new q(b.HANZI,"HANZI",Int32Array.from([8,10,12]),13);class Q{static decode(t,e,r,n){const i=new X(t);let s=new E;const o=new Array;let a=-1,h=-1;try{let t,r=null,l=!1;do{if(i.available()<4)t=q.TERMINATOR;else{const e=i.readBits(4);t=q.forBits(e)}switch(t){case q.TERMINATOR:break;case q.FNC1_FIRST_POSITION:case q.FNC1_SECOND_POSITION:l=!0;break;case q.STRUCTURED_APPEND:if(i.available()<16)throw new I;a=i.readBits(8),h=i.readBits(8);break;case q.ECI:const c=Q.parseECIValue(i);if(r=S.getCharacterSetECIByValue(c),null===r)throw new I;break;case q.HANZI:const u=i.readBits(4),w=i.readBits(t.getCharacterCountBits(e));u===Q.GB2312_SUBSET&&Q.decodeHanziSegment(i,s,w);break;default:const f=i.readBits(t.getCharacterCountBits(e));switch(t){case q.NUMERIC:Q.decodeNumericSegment(i,s,f);break;case q.ALPHANUMERIC:Q.decodeAlphanumericSegment(i,s,f,l);break;case q.BYTE:Q.decodeByteSegment(i,s,f,r,o,n);break;case q.KANJI:Q.decodeKanjiSegment(i,s,f);break;default:throw new I}}}while(t!==q.TERMINATOR)}catch(t){throw new I}return new Y(t,s.toString(),0===o.length?null:o,null===r?null:r.toString(),a,h)}static decodeHanziSegment(t,e,r){if(13*r>t.available())throw new I;const n=new Uint8Array(2*r);let i=0;for(;r>0;){const e=t.readBits(13);let s=e/96<<8&4294967295|e%96;s+=s<959?41377:42657,n[i]=s>>8&255,n[i+1]=255&s,i+=2,r--}try{e.append(m.decode(n,C.GB2312))}catch(t){throw new I(t)}}static decodeKanjiSegment(t,e,r){if(13*r>t.available())throw new I;const n=new Uint8Array(2*r);let i=0;for(;r>0;){const e=t.readBits(13);let s=e/192<<8&4294967295|e%192;s+=s<7936?33088:49472,n[i]=s>>8,n[i+1]=s,i+=2,r--}try{e.append(m.decode(n,C.SHIFT_JIS))}catch(t){throw new I(t)}}static decodeByteSegment(t,e,r,n,i,s){if(8*r>t.available())throw new I;const o=new Uint8Array(r);for(let e=0;e<r;e++)o[e]=t.readBits(8);let a;a=null===n?C.guessEncoding(o,s):n.getName();try{e.append(m.decode(o,a))}catch(t){throw new I(t)}i.push(o)}static toAlphaNumericChar(t){if(t>=Q.ALPHANUMERIC_CHARS.length)throw new I;return Q.ALPHANUMERIC_CHARS[t]}static decodeAlphanumericSegment(t,e,r,n){const i=e.length();for(;r>1;){if(t.available()<11)throw new I;const n=t.readBits(11);e.append(Q.toAlphaNumericChar(Math.floor(n/45))),e.append(Q.toAlphaNumericChar(n%45)),r-=2}if(1===r){if(t.available()<6)throw new I;e.append(Q.toAlphaNumericChar(t.readBits(6)))}if(n)for(let t=i;t<e.length();t++)"%"===e.charAt(t)&&(t<e.length()-1&&"%"===e.charAt(t+1)?e.deleteCharAt(t+1):e.setCharAt(t,String.fromCharCode(29)))}static decodeNumericSegment(t,e,r){for(;r>=3;){if(t.available()<10)throw new I;const n=t.readBits(10);if(n>=1e3)throw new I;e.append(Q.toAlphaNumericChar(Math.floor(n/100))),e.append(Q.toAlphaNumericChar(Math.floor(n/10)%10)),e.append(Q.toAlphaNumericChar(n%10)),r-=3}if(2===r){if(t.available()<7)throw new I;const r=t.readBits(7);if(r>=100)throw new I;e.append(Q.toAlphaNumericChar(Math.floor(r/10))),e.append(Q.toAlphaNumericChar(r%10))}else if(1===r){if(t.available()<4)throw new I;const r=t.readBits(4);if(r>=10)throw new I;e.append(Q.toAlphaNumericChar(r))}}static parseECIValue(t){const e=t.readBits(8);if(!(128&e))return 127&e;if(128==(192&e)){return(63&e)<<8&4294967295|t.readBits(8)}if(192==(224&e)){return(31&e)<<16&4294967295|t.readBits(16)}throw new I}}Q.ALPHANUMERIC_CHARS="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",Q.GB2312_SUBSET=1;class J{constructor(t){this.mirrored=t}isMirrored(){return this.mirrored}applyMirroredCorrection(t){if(!this.mirrored||null===t||t.length<3)return;const e=t[0];t[0]=t[2],t[2]=e}}class j{constructor(){this.rsDecoder=new v(k.QR_CODE_FIELD_256)}decodeBooleanArray(t,e){return this.decodeBitMatrix(M.parseFromBooleanArray(t),e)}decodeBitMatrix(t,e){const r=new W(t);let n=null;try{return this.decodeBitMatrixParser(r,e)}catch(t){n=t}try{r.remask(),r.setMirror(!0),r.readVersion(),r.readFormatInformation(),r.mirror();const t=this.decodeBitMatrixParser(r,e);return t.setOther(new J(!0)),t}catch(t){if(null!==n)throw n;throw t}}decodeBitMatrixParser(t,e){const r=t.readVersion(),n=t.readFormatInformation().getErrorCorrectionLevel(),i=t.readCodewords(),s=Z.getDataBlocks(i,r,n);let o=0;for(const t of s)o+=t.getNumDataCodewords();const a=new Uint8Array(o);let h=0;for(const t of s){const e=t.getCodewords(),r=t.getNumDataCodewords();this.correctErrors(e,r);for(let t=0;t<r;t++)a[h++]=e[t]}return Q.decode(a,r,n,e)}correctErrors(t,e){const r=new Int32Array(t);try{this.rsDecoder.decode(r,t.length-e)}catch(t){throw new R}for(let n=0;n<e;n++)t[n]=r[n]}}class ${constructor(){}static round(t){return isNaN(t)?0:t<=Number.MIN_SAFE_INTEGER?Number.MIN_SAFE_INTEGER:t>=Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t+(t<0?-.5:.5)|0}static distance(t,e,r,n){const i=t-r,s=e-n;return Math.sqrt(i*i+s*s)}static sum(t){let e=0;for(let r=0,n=t.length;r!==n;r++){e+=t[r]}return e}}class tt{constructor(t,e){this.bits=t,this.points=e}getBits(){return this.bits}getPoints(){return this.points}}class et{static checkAndNudgePoints(t,e){const r=t.getWidth(),n=t.getHeight();let s=!0;for(let t=0;t<e.length&&s;t+=2){const o=Math.floor(e[t]),a=Math.floor(e[t+1]);if(o<-1||o>r||a<-1||a>n)throw new i;s=!1,-1===o?(e[t]=0,s=!0):o===r&&(e[t]=r-1,s=!0),-1===a?(e[t+1]=0,s=!0):a===n&&(e[t+1]=n-1,s=!0)}s=!0;for(let t=e.length-2;t>=0&&s;t-=2){const o=Math.floor(e[t]),a=Math.floor(e[t+1]);if(o<-1||o>r||a<-1||a>n)throw new i;s=!1,-1===o?(e[t]=0,s=!0):o===r&&(e[t]=r-1,s=!0),-1===a?(e[t+1]=0,s=!0):a===n&&(e[t+1]=n-1,s=!0)}}}class rt{constructor(t,e,r,n,i,s,o,a,h){this.a11=t,this.a21=e,this.a31=r,this.a12=n,this.a22=i,this.a32=s,this.a13=o,this.a23=a,this.a33=h}static quadrilateralToQuadrilateral(t,e,r,n,i,s,o,a,h,l,c,u,w,f,d,g){const I=rt.quadrilateralToSquare(t,e,r,n,i,s,o,a);return rt.squareToQuadrilateral(h,l,c,u,w,f,d,g).times(I)}transformPoints(t){const e=t.length,r=this.a11,n=this.a12,i=this.a13,s=this.a21,o=this.a22,a=this.a23,h=this.a31,l=this.a32,c=this.a33;for(let u=0;u<e;u+=2){const e=t[u],w=t[u+1],f=i*e+a*w+c;t[u]=(r*e+s*w+h)/f,t[u+1]=(n*e+o*w+l)/f}}transformPointsWithValues(t,e){const r=this.a11,n=this.a12,i=this.a13,s=this.a21,o=this.a22,a=this.a23,h=this.a31,l=this.a32,c=this.a33,u=t.length;for(let w=0;w<u;w++){const u=t[w],f=e[w],d=i*u+a*f+c;t[w]=(r*u+s*f+h)/d,e[w]=(n*u+o*f+l)/d}}static squareToQuadrilateral(t,e,r,n,i,s,o,a){const h=t-r+i-o,l=e-n+s-a;if(0===h&&0===l)return new rt(r-t,i-r,t,n-e,s-n,e,0,0,1);{const c=r-i,u=o-i,w=n-s,f=a-s,d=c*f-u*w,g=(h*f-u*l)/d,I=(c*l-h*w)/d;return new rt(r-t+g*r,o-t+I*o,t,n-e+g*n,a-e+I*a,e,g,I,1)}}static quadrilateralToSquare(t,e,r,n,i,s,o,a){return rt.squareToQuadrilateral(t,e,r,n,i,s,o,a).buildAdjoint()}buildAdjoint(){return new rt(this.a22*this.a33-this.a23*this.a32,this.a23*this.a31-this.a21*this.a33,this.a21*this.a32-this.a22*this.a31,this.a13*this.a32-this.a12*this.a33,this.a11*this.a33-this.a13*this.a31,this.a12*this.a31-this.a11*this.a32,this.a12*this.a23-this.a13*this.a22,this.a13*this.a21-this.a11*this.a23,this.a11*this.a22-this.a12*this.a21)}times(t){return new rt(this.a11*t.a11+this.a21*t.a12+this.a31*t.a13,this.a11*t.a21+this.a21*t.a22+this.a31*t.a23,this.a11*t.a31+this.a21*t.a32+this.a31*t.a33,this.a12*t.a11+this.a22*t.a12+this.a32*t.a13,this.a12*t.a21+this.a22*t.a22+this.a32*t.a23,this.a12*t.a31+this.a22*t.a32+this.a32*t.a33,this.a13*t.a11+this.a23*t.a12+this.a33*t.a13,this.a13*t.a21+this.a23*t.a22+this.a33*t.a23,this.a13*t.a31+this.a23*t.a32+this.a33*t.a33)}}class nt{static setGridSampler(t){nt.gridSampler=t}static getInstance(){return nt.gridSampler}}nt.gridSampler=new class extends et{sampleGrid(t,e,r,n,i,s,o,a,h,l,c,u,w,f,d,g,I,S,A){const m=rt.quadrilateralToQuadrilateral(n,i,s,o,a,h,l,c,u,w,f,d,g,I,S,A);return this.sampleGridWithTransform(t,e,r,m)}sampleGridWithTransform(t,e,r,n){if(e<=0||r<=0)throw new i;const s=new M(e,r),o=new Float32Array(2*e);for(let e=0;e<r;e++){const r=o.length,a=e+.5;for(let t=0;t<r;t+=2)o[t]=t/2+.5,o[t+1]=a;n.transformPoints(o),et.checkAndNudgePoints(t,o);try{for(let n=0;n<r;n+=2)t.get(Math.floor(o[n]),Math.floor(o[n+1]))&&s.set(n/2,e)}catch(t){throw new i}}return s}};class it{static floatToIntBits(t){return t}}it.MAX_VALUE=Number.MAX_SAFE_INTEGER;class st{constructor(t,e){this.x=t,this.y=e}getX(){return this.x}getY(){return this.y}equals(t){if(t instanceof st){const e=t;return this.x===e.x&&this.y===e.y}return!1}hashCode(){return 31*it.floatToIntBits(this.x)+it.floatToIntBits(this.y)}toString(){return"("+this.x+","+this.y+")"}static orderBestPatterns(t){const e=this.distance(t[0],t[1]),r=this.distance(t[1],t[2]),n=this.distance(t[0],t[2]);let i,s,o;if(r>=e&&r>=n?(s=t[0],i=t[1],o=t[2]):n>=r&&n>=e?(s=t[1],i=t[0],o=t[2]):(s=t[2],i=t[0],o=t[1]),this.crossProductZ(i,s,o)<0){const t=i;i=o,o=t}t[0]=i,t[1]=s,t[2]=o}static distance(t,e){return $.distance(t.x,t.y,e.x,e.y)}static crossProductZ(t,e,r){const n=e.x,i=e.y;return(r.x-n)*(t.y-i)-(r.y-i)*(t.x-n)}}class ot extends st{constructor(t,e,r){super(t,e),this.estimatedModuleSize=r}aboutEquals(t,e,r){if(Math.abs(e-this.getY())<=t&&Math.abs(r-this.getX())<=t){const e=Math.abs(t-this.estimatedModuleSize);return e<=1||e<=this.estimatedModuleSize}return!1}combineEstimate(t,e,r){const n=(this.getX()+e)/2,i=(this.getY()+t)/2,s=(this.estimatedModuleSize+r)/2;return new ot(n,i,s)}}class at{constructor(t,e,r,n,i,s,o){this.image=t,this.startX=e,this.startY=r,this.width=n,this.height=i,this.moduleSize=s,this.resultPointCallback=o,this.possibleCenters=[],this.crossCheckStateCount=new Int32Array(3)}find(){const t=this.startX,e=this.height,r=t+this.width,n=this.startY+e/2,s=new Int32Array(3),o=this.image;for(let i=0;i<e;i++){const e=n+(1&i?-Math.floor((i+1)/2):Math.floor((i+1)/2));s[0]=0,s[1]=0,s[2]=0;let a=t;for(;a<r&&!o.get(a,e);)a++;let h=0;for(;a<r;){if(o.get(a,e))if(1===h)s[1]++;else if(2===h){if(this.foundPatternCross(s)){const t=this.handlePossibleCenter(s,e,a);if(null!==t)return t}s[0]=s[2],s[1]=1,s[2]=0,h=1}else s[++h]++;else 1===h&&h++,s[h]++;a++}if(this.foundPatternCross(s)){const t=this.handlePossibleCenter(s,e,r);if(null!==t)return t}}if(0!==this.possibleCenters.length)return this.possibleCenters[0];throw new i}static centerFromEnd(t,e){return e-t[2]-t[1]/2}foundPatternCross(t){const e=this.moduleSize,r=e/2;for(let n=0;n<3;n++)if(Math.abs(e-t[n])>=r)return!1;return!0}crossCheckVertical(t,e,r,n){const i=this.image,s=i.getHeight(),o=this.crossCheckStateCount;o[0]=0,o[1]=0,o[2]=0;let a=t;for(;a>=0&&i.get(e,a)&&o[1]<=r;)o[1]++,a--;if(a<0||o[1]>r)return NaN;for(;a>=0&&!i.get(e,a)&&o[0]<=r;)o[0]++,a--;if(o[0]>r)return NaN;for(a=t+1;a<s&&i.get(e,a)&&o[1]<=r;)o[1]++,a++;if(a===s||o[1]>r)return NaN;for(;a<s&&!i.get(e,a)&&o[2]<=r;)o[2]++,a++;if(o[2]>r)return NaN;const h=o[0]+o[1]+o[2];return 5*Math.abs(h-n)>=2*n?NaN:this.foundPatternCross(o)?at.centerFromEnd(o,a):NaN}handlePossibleCenter(t,e,r){const n=t[0]+t[1]+t[2],i=at.centerFromEnd(t,r),s=this.crossCheckVertical(e,i,2*t[1],n);if(!isNaN(s)){const e=(t[0]+t[1]+t[2])/3;for(const t of this.possibleCenters)if(t.aboutEquals(e,s,i))return t.combineEstimate(s,i,e);const r=new ot(i,s,e);this.possibleCenters.push(r),null!==this.resultPointCallback&&void 0!==this.resultPointCallback&&this.resultPointCallback.foundPossibleResultPoint(r)}return null}}class ht extends st{constructor(t,e,r,n){super(t,e),this.estimatedModuleSize=r,this.count=n,void 0===n&&(this.count=1)}getEstimatedModuleSize(){return this.estimatedModuleSize}getCount(){return this.count}aboutEquals(t,e,r){if(Math.abs(e-this.getY())<=t&&Math.abs(r-this.getX())<=t){const e=Math.abs(t-this.estimatedModuleSize);return e<=1||e<=this.estimatedModuleSize}return!1}combineEstimate(t,e,r){const n=this.count??0,i=n+1,s=(n*this.getX()+e)/i,o=(n*this.getY()+t)/i,a=(n*this.estimatedModuleSize+r)/i;return new ht(s,o,a,i)}}class lt{constructor(t){this.bottomLeft=t[0],this.topLeft=t[1],this.topRight=t[2]}getBottomLeft(){return this.bottomLeft}getTopLeft(){return this.topLeft}getTopRight(){return this.topRight}}class ct{constructor(t,e){this.image=t,this.resultPointCallback=e,this.possibleCenters=[],this.crossCheckStateCount=new Int32Array(5),this.resultPointCallback=e}getImage(){return this.image}getPossibleCenters(){return this.possibleCenters}find(t){const e=null!=t&&void 0!==t.get(g.TRY_HARDER),r=null!=t&&void 0!==t.get(g.PURE_BARCODE),n=this.image,i=n.getHeight(),s=n.getWidth();let o=Math.floor(3*i/(4*ct.MAX_MODULES));(o<ct.MIN_SKIP||e)&&(o=ct.MIN_SKIP);let a=!1;const h=new Int32Array(5);for(let t=o-1;t<i&&!a;t+=o){h[0]=0,h[1]=0,h[2]=0,h[3]=0,h[4]=0;let e=0;for(let i=0;i<s;i++)if(n.get(i,t))1&~e||e++,h[e]++;else if(1&e)h[e]++;else if(4===e)if(ct.foundPatternCross(h)){if(!0!==this.handlePossibleCenter(h,t,i,r)){h[0]=h[2],h[1]=h[3],h[2]=h[4],h[3]=1,h[4]=0,e=3;continue}if(o=2,!0===this.hasSkipped)a=this.haveMultiplyConfirmedCenters();else{const e=this.findRowSkip();e>h[2]&&(t+=e-h[2]-o,i=s-1)}e=0,h[0]=0,h[1]=0,h[2]=0,h[3]=0,h[4]=0}else h[0]=h[2],h[1]=h[3],h[2]=h[4],h[3]=1,h[4]=0,e=3;else h[++e]++;if(ct.foundPatternCross(h)){!0===this.handlePossibleCenter(h,t,s,r)&&(o=h[0],this.hasSkipped&&(a=this.haveMultiplyConfirmedCenters()))}}const l=this.selectBestPatterns();return st.orderBestPatterns(l),new lt(l)}static centerFromEnd(t,e){return e-t[4]-t[3]-t[2]/2}static foundPatternCross(t){let e=0;for(let r=0;r<5;r++){const n=t[r];if(0===n)return!1;e+=n}if(e<7)return!1;const r=e/7,n=r/2;return Math.abs(r-t[0])<n&&Math.abs(r-t[1])<n&&Math.abs(3*r-t[2])<3*n&&Math.abs(r-t[3])<n&&Math.abs(r-t[4])<n}getCrossCheckStateCount(){const t=this.crossCheckStateCount;return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t}crossCheckDiagonal(t,e,r,n){const i=this.getCrossCheckStateCount();let s=0;const o=this.image;for(;t>=s&&e>=s&&o.get(e-s,t-s);)i[2]++,s++;if(t<s||e<s)return!1;for(;t>=s&&e>=s&&!o.get(e-s,t-s)&&i[1]<=r;)i[1]++,s++;if(t<s||e<s||i[1]>r)return!1;for(;t>=s&&e>=s&&o.get(e-s,t-s)&&i[0]<=r;)i[0]++,s++;if(i[0]>r)return!1;const a=o.getHeight(),h=o.getWidth();for(s=1;t+s<a&&e+s<h&&o.get(e+s,t+s);)i[2]++,s++;if(t+s>=a||e+s>=h)return!1;for(;t+s<a&&e+s<h&&!o.get(e+s,t+s)&&i[3]<r;)i[3]++,s++;if(t+s>=a||e+s>=h||i[3]>=r)return!1;for(;t+s<a&&e+s<h&&o.get(e+s,t+s)&&i[4]<r;)i[4]++,s++;if(i[4]>=r)return!1;const l=i[0]+i[1]+i[2]+i[3]+i[4];return Math.abs(l-n)<2*n&&ct.foundPatternCross(i)}crossCheckVertical(t,e,r,n){const i=this.image,s=i.getHeight(),o=this.getCrossCheckStateCount();let a=t;for(;a>=0&&i.get(e,a);)o[2]++,a--;if(a<0)return NaN;for(;a>=0&&!i.get(e,a)&&o[1]<=r;)o[1]++,a--;if(a<0||o[1]>r)return NaN;for(;a>=0&&i.get(e,a)&&o[0]<=r;)o[0]++,a--;if(o[0]>r)return NaN;for(a=t+1;a<s&&i.get(e,a);)o[2]++,a++;if(a===s)return NaN;for(;a<s&&!i.get(e,a)&&o[3]<r;)o[3]++,a++;if(a===s||o[3]>=r)return NaN;for(;a<s&&i.get(e,a)&&o[4]<r;)o[4]++,a++;if(o[4]>=r)return NaN;const h=o[0]+o[1]+o[2]+o[3]+o[4];return 5*Math.abs(h-n)>=2*n?NaN:ct.foundPatternCross(o)?ct.centerFromEnd(o,a):NaN}crossCheckHorizontal(t,e,r,n){const i=this.image,s=i.getWidth(),o=this.getCrossCheckStateCount();let a=t;for(;a>=0&&i.get(a,e);)o[2]++,a--;if(a<0)return NaN;for(;a>=0&&!i.get(a,e)&&o[1]<=r;)o[1]++,a--;if(a<0||o[1]>r)return NaN;for(;a>=0&&i.get(a,e)&&o[0]<=r;)o[0]++,a--;if(o[0]>r)return NaN;for(a=t+1;a<s&&i.get(a,e);)o[2]++,a++;if(a===s)return NaN;for(;a<s&&!i.get(a,e)&&o[3]<r;)o[3]++,a++;if(a===s||o[3]>=r)return NaN;for(;a<s&&i.get(a,e)&&o[4]<r;)o[4]++,a++;if(o[4]>=r)return NaN;const h=o[0]+o[1]+o[2]+o[3]+o[4];return 5*Math.abs(h-n)>=n?NaN:ct.foundPatternCross(o)?ct.centerFromEnd(o,a):NaN}handlePossibleCenter(t,e,r,n){const i=t[0]+t[1]+t[2]+t[3]+t[4];let s=ct.centerFromEnd(t,r),o=this.crossCheckVertical(e,Math.floor(s),t[2],i);if(!isNaN(o)&&(s=this.crossCheckHorizontal(Math.floor(s),Math.floor(o),t[2],i),!isNaN(s)&&(!n||this.crossCheckDiagonal(Math.floor(o),Math.floor(s),t[2],i)))){const t=i/7;let e=!1;const r=this.possibleCenters;for(let n=0,i=r.length;n<i;n++){const i=r[n];if(i.aboutEquals(t,o,s)){r[n]=i.combineEstimate(o,s,t),e=!0;break}}if(!e){const e=new ht(s,o,t);r.push(e),null!==this.resultPointCallback&&void 0!==this.resultPointCallback&&this.resultPointCallback.foundPossibleResultPoint(e)}return!0}return!1}findRowSkip(){if(this.possibleCenters.length<=1)return 0;let t=null;for(const e of this.possibleCenters){const r=e?.getCount();if(void 0!==r&&r>=ct.CENTER_QUORUM){if(null!=t)return this.hasSkipped=!0,Math.floor((Math.abs(t.getX()-e.getX())-Math.abs(t.getY()-e.getY()))/2);t=e}}return 0}haveMultiplyConfirmedCenters(){let t=0,e=0;const r=this.possibleCenters.length;for(const r of this.possibleCenters){const n=r.getCount();void 0!==n&&n>=ct.CENTER_QUORUM&&(t++,e+=r.getEstimatedModuleSize())}if(t<3)return!1;const n=e/r;let i=0;for(const t of this.possibleCenters)i+=Math.abs(t.getEstimatedModuleSize()-n);return i<=.05*e}selectBestPatterns(){const t=this.possibleCenters.length;if(t<3)throw new i;const e=this.possibleCenters;let r;if(t>3){let n=0,i=0;for(const t of this.possibleCenters){const e=t.getEstimatedModuleSize();n+=e,i+=e*e}r=n/t;let s=Math.sqrt(i/t-r*r);e.sort(((t,e)=>{const n=Math.abs(e.getEstimatedModuleSize()-r),i=Math.abs(t.getEstimatedModuleSize()-r);return n<i?-1:n>i?1:0}));const o=Math.max(.2*r,s);for(let t=0;t<e.length&&e.length>3;t++){const n=e[t];Math.abs(n.getEstimatedModuleSize()-r)>o&&(e.splice(t,1),t--)}}if(e.length>3){let t=0;for(const r of e)t+=r.getEstimatedModuleSize();r=t/e.length,e.sort(((t,e)=>{if(e.getCount()===t.getCount()){const n=Math.abs(e.getEstimatedModuleSize()-r),i=Math.abs(t.getEstimatedModuleSize()-r);return n<i?1:n>i?-1:0}return(e.getCount()??0)-(t.getCount()??0)})),e.splice(3)}return[e[0],e[1],e[2]]}}ct.CENTER_QUORUM=2,ct.MIN_SKIP=3,ct.MAX_MODULES=57;class ut{constructor(t){this.image=t}getImage(){return this.image}getResultPointCallback(){return this.resultPointCallback}detect(t){this.resultPointCallback=null==t?null:t.get(g.NEED_RESULT_POINT_CALLBACK);const e=new ct(this.image,this.resultPointCallback).find(t);return this.processFinderPatternInfo(e)}processFinderPatternInfo(t){const e=t.getTopLeft(),r=t.getTopRight(),n=t.getBottomLeft(),s=this.calculateModuleSize(e,r,n);if(s<1)throw new i("No pattern found in proccess finder.");const o=ut.computeDimension(e,r,n,s),a=G.getProvisionalVersionForDimension(o),h=a.getDimensionForVersion()-7;let l=null;if(a.getAlignmentPatternCenters().length>0){const t=r.getX()-e.getX()+n.getX(),o=r.getY()-e.getY()+n.getY(),a=1-3/h,c=Math.floor(e.getX()+a*(t-e.getX())),u=Math.floor(e.getY()+a*(o-e.getY()));for(let t=4;t<=16;t<<=1)try{l=this.findAlignmentInRegion(s,c,u,t);break}catch(t){if(!(t instanceof i))throw t}}const c=ut.createTransform(e,r,n,l,o),u=ut.sampleGrid(this.image,c,o);let w;return w=null===l?[n,e,r]:[n,e,r,l],new tt(u,w)}static createTransform(t,e,r,n,i){const s=i-3.5;let o,a,h,l;return null!==n?(o=n.getX(),a=n.getY(),h=s-3,l=h):(o=e.getX()-t.getX()+r.getX(),a=e.getY()-t.getY()+r.getY(),h=s,l=s),rt.quadrilateralToQuadrilateral(3.5,3.5,s,3.5,h,l,3.5,s,t.getX(),t.getY(),e.getX(),e.getY(),o,a,r.getX(),r.getY())}static sampleGrid(t,e,r){return nt.getInstance().sampleGridWithTransform(t,r,r,e)}static computeDimension(t,e,r,n){const s=$.round(st.distance(t,e)/n),o=$.round(st.distance(t,r)/n);let a=Math.floor((s+o)/2)+7;switch(3&a){case 0:a++;break;case 2:a--;break;case 3:throw new i("Dimensions could be not found.")}return a}calculateModuleSize(t,e,r){return(this.calculateModuleSizeOneWay(t,e)+this.calculateModuleSizeOneWay(t,r))/2}calculateModuleSizeOneWay(t,e){const r=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(t.getX()),Math.floor(t.getY()),Math.floor(e.getX()),Math.floor(e.getY())),n=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(e.getX()),Math.floor(e.getY()),Math.floor(t.getX()),Math.floor(t.getY()));return isNaN(r)?n/7:isNaN(n)?r/7:(r+n)/14}sizeOfBlackWhiteBlackRunBothWays(t,e,r,n){let i=this.sizeOfBlackWhiteBlackRun(t,e,r,n),s=1,o=t-(r-t);o<0?(s=t/(t-o),o=0):o>=this.image.getWidth()&&(s=(this.image.getWidth()-1-t)/(o-t),o=this.image.getWidth()-1);let a=Math.floor(e-(n-e)*s);return s=1,a<0?(s=e/(e-a),a=0):a>=this.image.getHeight()&&(s=(this.image.getHeight()-1-e)/(a-e),a=this.image.getHeight()-1),o=Math.floor(t+(o-t)*s),i+=this.sizeOfBlackWhiteBlackRun(t,e,o,a),i-1}sizeOfBlackWhiteBlackRun(t,e,r,n){const i=Math.abs(n-e)>Math.abs(r-t);if(i){let i=t;t=e,e=i,i=r,r=n,n=i}const s=Math.abs(r-t),o=Math.abs(n-e);let a=-s/2;const h=t<r?1:-1,l=e<n?1:-1;let c=0;const u=r+h;for(let r=t,w=e;r!==u;r+=h){const h=i?w:r,u=i?r:w;if(1===c===this.image.get(h,u)){if(2===c)return $.distance(r,w,t,e);c++}if(a+=o,a>0){if(w===n)break;w+=l,a-=s}}return 2===c?$.distance(r+h,n,t,e):NaN}findAlignmentInRegion(t,e,r,n){const s=Math.floor(n*t),o=Math.max(0,e-s),a=Math.min(this.image.getWidth()-1,e+s);if(a-o<3*t)throw new i("Alignment top exceeds estimated module size.");const h=Math.max(0,r-s),l=Math.min(this.image.getHeight()-1,r+s);if(l-h<3*t)throw new i("Alignment bottom exceeds estimated module size.");return new at(this.image,o,h,a-o,l-h,t,this.resultPointCallback).find()}}class wt{constructor(){this.decoder=new j}getDecoder(){return this.decoder}decode(t,e){let r,n;const i=e??(new Map).set(g.TRY_HARDER,!0);try{const e=wt.extractPureBits(t.getBlackMatrix());r=this.decoder.decodeBitMatrix(e,i),n=wt.NO_POINTS}catch(e){const s=new ut(t.getBlackMatrix()).detect(i);r=this.decoder.decodeBitMatrix(s.getBits(),i),n=s.getPoints()}r.getOther()instanceof J&&r.getOther().applyMirroredCorrection(n);const s=new O(r.getText(),r.getRawBytes(),void 0,n,a.QR_CODE,void 0),o=r.getByteSegments();o&&s.putMetadata(y.BYTE_SEGMENTS,o);const h=r.getECLevel();return h&&s.putMetadata(y.ERROR_CORRECTION_LEVEL,h),r.hasStructuredAppend()&&(s.putMetadata(y.STRUCTURED_APPEND_SEQUENCE,r.getStructuredAppendSequenceNumber()),s.putMetadata(y.STRUCTURED_APPEND_PARITY,r.getStructuredAppendParity())),s}decode2(t,e){let r,n;const i=null==e||null==e?(new Map).set(g.TRY_HARDER,!0):void 0;console.log("hintsDef",i);const s=wt.extractPureBits(t.getBlackMatrix());r=this.decoder.decodeBitMatrix(s,i),n=wt.NO_POINTS,r.getOther()instanceof J&&r.getOther().applyMirroredCorrection(n);const o=new O(r.getText(),r.getRawBytes(),void 0,n,a.QR_CODE,void 0),h=r.getByteSegments();null!==h&&o.putMetadata(y.BYTE_SEGMENTS,h);const l=r.getECLevel();return null!==l&&o.putMetadata(y.ERROR_CORRECTION_LEVEL,l),r.hasStructuredAppend()&&(o.putMetadata(y.STRUCTURED_APPEND_SEQUENCE,r.getStructuredAppendSequenceNumber()),o.putMetadata(y.STRUCTURED_APPEND_PARITY,r.getStructuredAppendParity())),o}reset(){}static extractPureBits(t){const e=t.getTopLeftOnBit(),r=t.getBottomRightOnBit();if(null===e||null===r)throw new i;const n=this.moduleSize(e,t);let s=e[1],o=r[1],a=e[0],h=r[0];if(a>=h||s>=o)throw new i;if(o-s!=h-a&&(h=a+(o-s),h>=t.getWidth()))throw new i;const l=Math.round((h-a+1)/n),c=Math.round((o-s+1)/n);if(l<=0||c<=0)throw new i;if(c!==l)throw new i;const u=Math.floor(n/2);s+=u,a+=u;const w=a+Math.floor((l-1)*n)-h;if(w>0){if(w>u)throw new i;a-=w}const f=s+Math.floor((c-1)*n)-o;if(f>0){if(f>u)throw new i;s-=f}const d=new M(l,c);for(let e=0;e<c;e++){const r=s+Math.floor(e*n);for(let i=0;i<l;i++)t.get(a+Math.floor(i*n),r)&&d.set(i,e)}return d}static moduleSize(t,e){const r=e.getHeight(),n=e.getWidth();let s=t[0],o=t[1],a=!0,h=0;for(;s<n&&o<r;){if(a!==e.get(s,o)){if(5==++h)break;a=!a}s++,o++}if(s===n||o===r)throw new i;return(s-t[0])/7}}wt.NO_POINTS=new Array;class ft{constructor(t){if(this.binarizer=t,null===t)throw new h("Binarizer must be non-null.")}getWidth(){return this.binarizer.getWidth()}getHeight(){return this.binarizer.getHeight()}getBlackRow(t,e){return this.binarizer.getBlackRow(t,e)}getBlackMatrix(){return null!==this.matrix&&void 0!==this.matrix||(this.matrix=this.binarizer.getBlackMatrix()),this.matrix}isCropSupported(){return this.binarizer.getLuminanceSource().isCropSupported()}crop(t,e,r,n){const i=this.binarizer.getLuminanceSource().crop(t,e,r,n);return new ft(this.binarizer.createBinarizer(i))}isRotateSupported(){return this.binarizer.getLuminanceSource().isRotateSupported()}rotateCounterClockwise(){const t=this.binarizer.getLuminanceSource().rotateCounterClockwise();return new ft(this.binarizer.createBinarizer(t))}rotateCounterClockwise45(){const t=this.binarizer.getLuminanceSource().rotateCounterClockwise45();return new ft(this.binarizer.createBinarizer(t))}toString(){try{return this.getBlackMatrix().toString()}catch(t){return""}}}class dt{constructor(t){this.source=t}getLuminanceSource(){return this.source}getWidth(){return this.source.getWidth()}getHeight(){return this.source.getHeight()}}class gt extends dt{constructor(t){super(t),this.luminances=gt.EMPTY,this.buckets=new Int32Array(gt.LUMINANCE_BUCKETS)}getBlackRow(t,e){const r=this.getLuminanceSource(),n=r.getWidth();null==e||e.getSize()<n?e=new p(n):e.clear(),this.initArrays(n);const i=r.getRow(t,this.luminances),s=this.buckets;for(let t=0;t<n;t++)s[(255&i[t])>>gt.LUMINANCE_SHIFT]++;const o=gt.estimateBlackPoint(s);if(n<3)for(let t=0;t<n;t++)(255&i[t])<o&&e.set(t);else{let t=255&i[0],r=255&i[1];for(let s=1;s<n-1;s++){const n=255&i[s+1];(4*r-t-n)/2<o&&e.set(s),t=r,r=n}}return e}getBlackMatrix(){const t=this.getLuminanceSource(),e=t.getWidth(),r=t.getHeight(),n=new M(e,r);this.initArrays(e);const i=this.buckets;for(let n=1;n<5;n++){const s=Math.floor(r*n/5),o=t.getRow(s,this.luminances),a=Math.floor(4*e/5);for(let t=Math.floor(e/5);t<a;t++){i[(255&o[t])>>gt.LUMINANCE_SHIFT]++}}const s=gt.estimateBlackPoint(i),o=t.getMatrix();for(let t=0;t<r;t++){const r=t*e;for(let i=0;i<e;i++){(255&o[r+i])<s&&n.set(i,t)}}return n}createBinarizer(t){return new gt(t)}initArrays(t){this.luminances.length<t&&(this.luminances=new Uint8ClampedArray(t));const e=this.buckets;for(let t=0;t<gt.LUMINANCE_BUCKETS;t++)e[t]=0}static estimateBlackPoint(t){const e=t.length;let r=0,n=0,s=0;for(let i=0;i<e;i++)t[i]>s&&(n=i,s=t[i]),t[i]>r&&(r=t[i]);let o=0,a=0;for(let r=0;r<e;r++){const e=r-n,i=t[r]*e*e;i>a&&(o=r,a=i)}if(n>o){const t=n;n=o,o=t}if(o-n<=e/16)throw new i;let h=o-1,l=-1;for(let e=o-1;e>n;e--){const i=e-n,s=i*i*(o-e)*(r-t[e]);s>l&&(h=e,l=s)}return h<<gt.LUMINANCE_SHIFT}}gt.LUMINANCE_BITS=5,gt.LUMINANCE_SHIFT=8-gt.LUMINANCE_BITS,gt.LUMINANCE_BUCKETS=1<<gt.LUMINANCE_BITS,gt.EMPTY=Uint8ClampedArray.from([0]);class It extends gt{constructor(t){super(t),this.matrix=null}getBlackMatrix(){if(null!==this.matrix)return this.matrix;const t=this.getLuminanceSource(),e=t.getWidth(),r=t.getHeight();if(e>=It.MINIMUM_DIMENSION&&r>=It.MINIMUM_DIMENSION){const n=t.getMatrix();let i=e>>It.BLOCK_SIZE_POWER;e&It.BLOCK_SIZE_MASK&&i++;let s=r>>It.BLOCK_SIZE_POWER;r&It.BLOCK_SIZE_MASK&&s++;const o=It.calculateBlackPoints(n,i,s,e,r),a=new M(e,r);It.calculateThresholdForBlock(n,i,s,e,r,o,a),this.matrix=a}else this.matrix=super.getBlackMatrix();return this.matrix}createBinarizer(t){return new It(t)}static calculateThresholdForBlock(t,e,r,n,i,s,o){const a=i-It.BLOCK_SIZE,h=n-It.BLOCK_SIZE;for(let i=0;i<r;i++){let l=i<<It.BLOCK_SIZE_POWER;l>a&&(l=a);const c=It.cap(i,2,r-3);for(let r=0;r<e;r++){let i=r<<It.BLOCK_SIZE_POWER;i>h&&(i=h);const a=It.cap(r,2,e-3);let u=0;for(let t=-2;t<=2;t++){const e=s[c+t];u+=e[a-2]+e[a-1]+e[a]+e[a+1]+e[a+2]}const w=u/25;It.thresholdBlock(t,i,l,w,n,o)}}}static cap(t,e,r){return t<e?e:t>r?r:t}static thresholdBlock(t,e,r,n,i,s){for(let o=0,a=r*i+e;o<It.BLOCK_SIZE;o++,a+=i)for(let i=0;i<It.BLOCK_SIZE;i++)(255&t[a+i])<=n&&s.set(e+i,r+o)}static calculateBlackPoints(t,e,r,n,i){const s=i-It.BLOCK_SIZE,o=n-It.BLOCK_SIZE,a=new Array(r);for(let i=0;i<r;i++){a[i]=new Int32Array(e);let r=i<<It.BLOCK_SIZE_POWER;r>s&&(r=s);for(let s=0;s<e;s++){let e=s<<It.BLOCK_SIZE_POWER;e>o&&(e=o);let h=0,l=255,c=0;for(let i=0,s=r*n+e;i<It.BLOCK_SIZE;i++,s+=n){for(let e=0;e<It.BLOCK_SIZE;e++){const r=255&t[s+e];h+=r,r<l&&(l=r),r>c&&(c=r)}if(c-l>It.MIN_DYNAMIC_RANGE)for(i++,s+=n;i<It.BLOCK_SIZE;i++,s+=n)for(let e=0;e<It.BLOCK_SIZE;e++)h+=255&t[s+e]}let u=h>>2*It.BLOCK_SIZE_POWER;if(c-l<=It.MIN_DYNAMIC_RANGE&&(u=l/2,i>0&&s>0)){const t=(a[i-1][s]+2*a[i][s-1]+a[i-1][s-1])/4;l<t&&(u=t)}a[i][s]=u}}return a}}It.BLOCK_SIZE_POWER=3,It.BLOCK_SIZE=1<<It.BLOCK_SIZE_POWER,It.BLOCK_SIZE_MASK=It.BLOCK_SIZE-1,It.MINIMUM_DIMENSION=5*It.BLOCK_SIZE,It.MIN_DYNAMIC_RANGE=24;class St{constructor(t,e){this.width=t,this.height=e}getWidth(){return this.width}getHeight(){return this.height}isCropSupported(){return!1}crop(t,e,r,n){throw new A("This luminance source does not support cropping.")}isRotateSupported(){return!1}rotateCounterClockwise(){throw new A("This luminance source does not support rotation by 90 degrees.")}rotateCounterClockwise45(){throw new A("This luminance source does not support rotation by 45 degrees.")}toString(){const t=new Uint8ClampedArray(this.width);let e=new E;for(let r=0;r<this.height;r++){const n=this.getRow(r,t);for(let t=0;t<this.width;t++){const r=255&n[t];let i;i=r<64?"#":r<128?"+":r<192?".":" ",e.append(i)}e.append("\n")}return e.toString()}}class At extends St{constructor(t){super(t.getWidth(),t.getHeight()),this.delegate=t}getRow(t,e){const r=this.delegate.getRow(t,e),n=this.getWidth();for(let t=0;t<n;t++)r[t]=255-(255&r[t]);return r}getMatrix(){const t=this.delegate.getMatrix(),e=this.getWidth()*this.getHeight(),r=new Uint8ClampedArray(e);for(let n=0;n<e;n++)r[n]=255-(255&t[n]);return r}isCropSupported(){return this.delegate.isCropSupported()}crop(t,e,r,n){return new At(this.delegate.crop(t,e,r,n))}isRotateSupported(){return this.delegate.isRotateSupported()}invert(){return this.delegate}rotateCounterClockwise(){return new At(this.delegate.rotateCounterClockwise())}rotateCounterClockwise45(){return new At(this.delegate.rotateCounterClockwise45())}}class mt extends St{constructor(t,e=128){super(t.getWidth(),t.getHeight()),this.delegate=t,this.threshold=e}getRow(t,e){const r=this.delegate.getRow(t,e),n=this.getWidth();for(let t=0;t<n;t++)r[t]=r[t]<this.threshold?0:255;return r}getMatrix(){const t=this.delegate.getMatrix(),e=this.getWidth()*this.getHeight(),r=new Uint8ClampedArray(e);for(let n=0;n<e;n++)r[n]=t[n]<this.threshold?0:255;return r}isCropSupported(){return this.delegate.isCropSupported()}crop(t,e,r,n){return new mt(this.delegate.crop(t,e,r,n),this.threshold)}isRotateSupported(){return this.delegate.isRotateSupported()}rotateCounterClockwise(){return new mt(this.delegate.rotateCounterClockwise(),this.threshold)}rotateCounterClockwise45(){return new mt(this.delegate.rotateCounterClockwise45(),this.threshold)}invert(){return new At(this)}highContrast(){return this}}class Ct extends St{constructor(t,e=!1){super(t.width,t.height),this.canvas=t,this.tempCanvasElement=null,this.buffer=Ct.makeBufferFromCanvasImageData(t,e)}static makeBufferFromCanvasImageData(t,e=!1){const r=t.getContext("2d").getImageData(0,0,t.width,t.height);return Ct.toGrayscaleBuffer(r.data,t.width,t.height,e)}static toGrayscaleBuffer(t,e,r,n=!1){const i=new Uint8ClampedArray(e*r);if(Ct.FRAME_INDEX=!Ct.FRAME_INDEX,Ct.FRAME_INDEX||!n)for(let e=0,r=0,n=t.length;e<n;e+=4,r++){let n;if(0===t[e+3])n=255;else{n=306*t[e]+601*t[e+1]+117*t[e+2]+512>>10}i[r]=n}else for(let e=0,r=0,n=t.length;e<n;e+=4,r++){let n;if(0===t[e+3])n=255;else{n=306*t[e]+601*t[e+1]+117*t[e+2]+512>>10}i[r]=255-n}return i}getRow(t,e){if(t<0||t>=this.getHeight())throw new h("Requested row is outside the image: "+t);const r=this.getWidth(),n=t*r;return null===e?e=this.buffer.slice(n,n+r):(e.length<r&&(e=new Uint8ClampedArray(r)),e.set(this.buffer.slice(n,n+r))),e}getMatrix(){return this.buffer}isCropSupported(){return!0}crop(t,e,r,n){return super.crop(t,e,r,n),this}isRotateSupported(){return!0}rotateCounterClockwise(){return this.rotate(-90),this}rotateCounterClockwise45(){return this.rotate(-45),this}getTempCanvasElement(){if(null===this.tempCanvasElement){const t=this.canvas.ownerDocument.createElement("canvas");t.width=this.canvas.width,t.height=this.canvas.height,this.tempCanvasElement=t}return this.tempCanvasElement}rotate(t){const e=this.getTempCanvasElement(),r=e.getContext("2d"),n=t*Ct.DEGREE_TO_RADIANS,i=this.canvas.width,s=this.canvas.height,o=Math.ceil(Math.abs(Math.cos(n))*i+Math.abs(Math.sin(n))*s),a=Math.ceil(Math.abs(Math.sin(n))*i+Math.abs(Math.cos(n))*s);return e.width=o,e.height=a,r.translate(o/2,a/2),r.rotate(n),r.drawImage(this.canvas,i/-2,s/-2),this.buffer=Ct.makeBufferFromCanvasImageData(e),this}invert(){return new At(this)}hightContrast(t=128){return new mt(this,t)}}Ct.DEGREE_TO_RADIANS=Math.PI/180,Ct.FRAME_INDEX=!0;class Et extends St{constructor(t,e,r){super(t,e),this.buffer=r}static async create(t,e,n,i,s=!1){let o,a,h;const l=t instanceof Uint8Array?t:new Uint8Array(t);if(e)try{const t=l.slice(0,8).join(","),e="137,80,78,71,13,10,26,10"===t,n=t.startsWith("255,216,255");if(!e&&!n)throw new Error("Invalid PNG or JPEG signature");const i=await r.load(l);if(a=i.width,h=i.height,!a||!h)throw new Error("Invalid image dimensions");o=new Uint8ClampedArray(i.data)}catch(t){throw console.error("image-js failed to read image buffer:",t),new Error("Failed to decode image buffer")}else{if(void 0===n||void 0===i)throw new Error("Width and height are required for raw RGBA buffer input");if(l.length!==n*i*4)throw new Error(`Raw RGBA buffer size (${l.length}) does not match dimensions (${n}x${i}x4 = ${n*i*4})`);a=n,h=i,o=new Uint8ClampedArray(l)}const c=Et.toGrayscaleBuffer(o,a,h,s);return new Et(a,h,c)}static toGrayscaleBuffer(t,e,r,n=!1){const i=new Uint8ClampedArray(e*r);if(n)for(let e=0,r=0,n=t.length;e<n;e+=4,r++){let n;if(0===t[e+3])n=255;else{n=306*t[e]+601*t[e+1]+117*t[e+2]+512>>10}i[r]=255-n}else for(let e=0,r=0,n=t.length;e<n;e+=4,r++){let n;if(0===t[e+3])n=255;else{n=306*t[e]+601*t[e+1]+117*t[e+2]+512>>10}i[r]=n}return i}getRow(t,e){if(t<0||t>=this.getHeight())throw new h("Requested row is outside the image: "+t);const r=this.getWidth(),n=t*r;return e?(e.length<r&&(e=new Uint8ClampedArray(r)),e.set(this.buffer.slice(n,n+r))):e=this.buffer.slice(n,n+r),e}getMatrix(){return this.buffer}isCropSupported(){return!0}crop(t,e,r,n){if(t<0||e<0||t+r>this.getWidth()||e+n>this.getHeight())throw new h("Crop rectangle does not fit within image data.");const i=new Uint8ClampedArray(r*n);for(let s=0;s<n;s++){const n=(e+s)*this.getWidth()+t,o=s*r;i.set(this.buffer.slice(n,n+r),o)}return new Et(r,n,i)}isRotateSupported(){return!1}invert(){return new At(this)}}"undefined"!=typeof navigator&&navigator.userAgent;const _t=!1;async function pt(e,r=!1){try{const{buffer:n,isPng:i,width:s,height:o}=function(e,r=!1){try{const n=new t(e,{fitTo:{mode:"zoom",value:2}}).render(),{width:i,height:s}=n;if(r){const t=Buffer.from(n.pixels);for(let e=0;e<t.length;e+=4)t[e]=255-t[e],t[e+1]=255-t[e+1],t[e+2]=255-t[e+2];return{buffer:t,isPng:!1,width:i,height:s}}return{buffer:n.asPng(),isPng:!0,width:i,height:s}}catch(t){throw new Error("Failed to preprocess image")}}(e,r);return await Et.create(n,i,s,o)}catch(t){throw new Error("Failed to convert SVG to luminance source")}}async function Mt(t){try{return(t=>{const e=new It(t);return new ft(e)})(t)}catch(t){throw new Error("Failed to create binary bitmap")}}async function Ot(t,e){const r=e.decode(t);if(!r.getText())throw new Error("Decoded result is empty");return r}const Nt={validateZxing:async t=>{if(!t)return{isValid:!1,isInverted:!1,message:"Input SVG string is undefined"};try{const e=new wt,r=await pt(t,!1);_t;const n=await Mt(r);let i;try{return i=await Ot(n,e),{isValid:!0,isInverted:!1,decodedText:i.getText(),message:"Decoded successfully"}}catch(r){try{const r=await pt(t,!0);_t;const n=await Mt(r);return i=await Ot(n,e),{isValid:!0,isInverted:!0,decodedText:i.getText(),message:"Inverted decode succeeded."}}catch(t){return{isValid:!1,isInverted:!1,message:"Failed to decode QR code (both normal and inverted attempts failed)"}}}}catch(t){return{isValid:!1,isInverted:!1,message:t instanceof Error?t.message:"Unknown error occurred during validation"}}}};export{Nt as qrValidatorZxing};