@opentiny/next-remoter 0.2.4 → 0.2.6

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.
@@ -1,68 +1,68 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("vue"),Pt=require("@opentiny/tiny-robot"),Cd=require("@opentiny/genui-sdk-vue"),Zn=require("@opentiny/tiny-robot-kit"),Ar=require("@opentiny/tiny-robot-svgs"),sr=require("@opentiny/next-sdk"),bd=require("@opentiny/vue-tooltip"),Ed=require("@opentiny/vue-icon");function Ad(t,r){for(var o=0;o<r.length;o++){const c=r[o];if(typeof c!="string"&&!Array.isArray(c)){for(const u in c)if(u!=="default"&&!(u in t)){const f=Object.getOwnPropertyDescriptor(c,u);f&&Object.defineProperty(t,u,f.get?f:{enumerable:!0,get:()=>c[u]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}var xl="vercel.ai.error",Id=Symbol.for(xl),bs,Es,gt=class wl extends(Es=Error,bs=Id,Es){constructor({name:r,message:o,cause:c}){super(o),this[bs]=!0,this.name=r,this.cause=c}static isInstance(r){return wl.hasMarker(r,xl)}static hasMarker(r,o){const c=Symbol.for(o);return r!=null&&typeof r=="object"&&c in r&&typeof r[c]=="boolean"&&r[c]===!0}},yl="AI_APICallError",_l=`vercel.ai.error.${yl}`,Sd=Symbol.for(_l),As,Is,on=class extends(Is=gt,As=Sd,Is){constructor({message:r,url:o,requestBodyValues:c,statusCode:u,responseHeaders:f,responseBody:p,cause:x,isRetryable:y=u!=null&&(u===408||u===409||u===429||u>=500),data:m}){super({name:yl,message:r,cause:x}),this[As]=!0,this.url=o,this.requestBodyValues=c,this.statusCode=u,this.responseHeaders=f,this.responseBody=p,this.isRetryable=y,this.data=m}static isInstance(r){return gt.hasMarker(r,_l)}},vl="AI_EmptyResponseBodyError",Cl=`vercel.ai.error.${vl}`,Td=Symbol.for(Cl),Ss,Ts,Nd=class extends(Ts=gt,Ss=Td,Ts){constructor({message:r="Empty response body"}={}){super({name:vl,message:r}),this[Ss]=!0}static isInstance(r){return gt.hasMarker(r,Cl)}};function bl(t){return t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:JSON.stringify(t)}var El="AI_InvalidArgumentError",Al=`vercel.ai.error.${El}`,Od=Symbol.for(Al),Ns,Os,Il=class extends(Os=gt,Ns=Od,Os){constructor({message:r,cause:o,argument:c}){super({name:El,message:r,cause:o}),this[Ns]=!0,this.argument=c}static isInstance(r){return gt.hasMarker(r,Al)}},Sl="AI_InvalidPromptError",Tl=`vercel.ai.error.${Sl}`,kd=Symbol.for(Tl),ks,Rs,Rd=class extends(Rs=gt,ks=kd,Rs){constructor({prompt:t,message:r,cause:o}){super({name:Sl,message:`Invalid prompt: ${r}`,cause:o}),this[ks]=!0,this.prompt=t}static isInstance(t){return gt.hasMarker(t,Tl)}},Nl="AI_InvalidResponseDataError",Ol=`vercel.ai.error.${Nl}`,Md=Symbol.for(Ol),Ms,Ds,uo=class extends(Ds=gt,Ms=Md,Ds){constructor({data:r,message:o=`Invalid response data: ${JSON.stringify(r)}.`}){super({name:Nl,message:o}),this[Ms]=!0,this.data=r}static isInstance(r){return gt.hasMarker(r,Ol)}},kl="AI_JSONParseError",Rl=`vercel.ai.error.${kl}`,Dd=Symbol.for(Rl),Ps,Bs,Oi=class extends(Bs=gt,Ps=Dd,Bs){constructor({text:r,cause:o}){super({name:kl,message:`JSON parsing failed: Text: ${r}.
2
- Error message: ${bl(o)}`,cause:o}),this[Ps]=!0,this.text=r}static isInstance(r){return gt.hasMarker(r,Rl)}},Ml="AI_LoadAPIKeyError",Dl=`vercel.ai.error.${Ml}`,Pd=Symbol.for(Dl),Ls,Fs,wi=class extends(Fs=gt,Ls=Pd,Fs){constructor({message:r}){super({name:Ml,message:r}),this[Ls]=!0}static isInstance(r){return gt.hasMarker(r,Dl)}},Pl="AI_TooManyEmbeddingValuesForCallError",Bl=`vercel.ai.error.${Pl}`,Bd=Symbol.for(Bl),Us,zs,Ld=class extends(zs=gt,Us=Bd,zs){constructor(t){super({name:Pl,message:`Too many values for a single embedding call. The ${t.provider} model "${t.modelId}" can only embed up to ${t.maxEmbeddingsPerCall} values per call, but ${t.values.length} values were provided.`}),this[Us]=!0,this.provider=t.provider,this.modelId=t.modelId,this.maxEmbeddingsPerCall=t.maxEmbeddingsPerCall,this.values=t.values}static isInstance(t){return gt.hasMarker(t,Bl)}},Ll="AI_TypeValidationError",Fl=`vercel.ai.error.${Ll}`,Fd=Symbol.for(Fl),Vs,$s,ar=class Eo extends($s=gt,Vs=Fd,$s){constructor({value:r,cause:o,context:c}){let u="Type validation failed";if(c?.field&&(u+=` for ${c.field}`),c?.entityName||c?.entityId){u+=" (";const f=[];c.entityName&&f.push(c.entityName),c.entityId&&f.push(`id: "${c.entityId}"`),u+=f.join(", "),u+=")"}super({name:Ll,message:`${u}: Value: ${JSON.stringify(r)}.
3
- Error message: ${bl(o)}`,cause:o}),this[Vs]=!0,this.value=r,this.context=c}static isInstance(r){return gt.hasMarker(r,Fl)}static wrap({value:r,cause:o,context:c}){var u,f,p;return Eo.isInstance(o)&&o.value===r&&((u=o.context)==null?void 0:u.field)===c?.field&&((f=o.context)==null?void 0:f.entityName)===c?.entityName&&((p=o.context)==null?void 0:p.entityId)===c?.entityId?o:new Eo({value:r,cause:o,context:c})}},Ul="AI_UnsupportedFunctionalityError",zl=`vercel.ai.error.${Ul}`,Ud=Symbol.for(zl),Zs,js,Rn=class extends(js=gt,Zs=Ud,js){constructor({functionality:r,message:o=`'${r}' functionality not supported.`}){super({name:Ul,message:o}),this[Zs]=!0,this.functionality=r}static isInstance(r){return gt.hasMarker(r,zl)}};function ie(t,r,o){function c(x,y){var m;Object.defineProperty(x,"_zod",{value:x._zod??{},enumerable:!1}),(m=x._zod).traits??(m.traits=new Set),x._zod.traits.add(t),r(x,y);for(const A in p.prototype)A in x||Object.defineProperty(x,A,{value:p.prototype[A].bind(x)});x._zod.constr=p,x._zod.def=y}const u=o?.Parent??Object;class f extends u{}Object.defineProperty(f,"name",{value:t});function p(x){var y;const m=o?.Parent?new f:this;c(m,x),(y=m._zod).deferred??(y.deferred=[]);for(const A of m._zod.deferred)A();return m}return Object.defineProperty(p,"init",{value:c}),Object.defineProperty(p,Symbol.hasInstance,{value:x=>o?.Parent&&x instanceof o.Parent?!0:x?._zod?.traits?.has(t)}),Object.defineProperty(p,"name",{value:t}),p}class qr extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}const Vl={};function Hn(t){return Vl}function $l(t){const r=Object.values(t).filter(c=>typeof c=="number");return Object.entries(t).filter(([c,u])=>r.indexOf(+c)===-1).map(([c,u])=>u)}function zd(t,r){return typeof r=="bigint"?r.toString():r}function Fo(t){return{get value(){{const r=t();return Object.defineProperty(this,"value",{value:r}),r}}}}function Uo(t){return t==null}function zo(t){const r=t.startsWith("^")?1:0,o=t.endsWith("$")?t.length-1:t.length;return t.slice(r,o)}function Vd(t,r){const o=(t.toString().split(".")[1]||"").length,c=(r.toString().split(".")[1]||"").length,u=o>c?o:c,f=Number.parseInt(t.toFixed(u).replace(".","")),p=Number.parseInt(r.toFixed(u).replace(".",""));return f%p/10**u}function Ke(t,r,o){Object.defineProperty(t,r,{get(){{const c=o();return t[r]=c,c}},set(c){Object.defineProperty(t,r,{value:c})},configurable:!0})}function Vo(t,r,o){Object.defineProperty(t,r,{value:o,writable:!0,enumerable:!0,configurable:!0})}function Fr(t){return JSON.stringify(t)}const Zl=Error.captureStackTrace?Error.captureStackTrace:(...t)=>{};function ki(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}const $d=Fo(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const t=Function;return new t(""),!0}catch{return!1}});function Ri(t){if(ki(t)===!1)return!1;const r=t.constructor;if(r===void 0)return!0;const o=r.prototype;return!(ki(o)===!1||Object.prototype.hasOwnProperty.call(o,"isPrototypeOf")===!1)}const Zd=new Set(["string","number","symbol"]);function ti(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function cr(t,r,o){const c=new t._zod.constr(r??t._zod.def);return(!r||o?.parent)&&(c._zod.parent=t),c}function Ae(t){const r=t;if(!r)return{};if(typeof r=="string")return{error:()=>r};if(r?.message!==void 0){if(r?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");r.error=r.message}return delete r.message,typeof r.error=="string"?{...r,error:()=>r.error}:r}function jd(t){return Object.keys(t).filter(r=>t[r]._zod.optin==="optional"&&t[r]._zod.optout==="optional")}const Hd={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Wd(t,r){const o={},c=t._zod.def;for(const u in r){if(!(u in c.shape))throw new Error(`Unrecognized key: "${u}"`);r[u]&&(o[u]=c.shape[u])}return cr(t,{...t._zod.def,shape:o,checks:[]})}function Gd(t,r){const o={...t._zod.def.shape},c=t._zod.def;for(const u in r){if(!(u in c.shape))throw new Error(`Unrecognized key: "${u}"`);r[u]&&delete o[u]}return cr(t,{...t._zod.def,shape:o,checks:[]})}function Xd(t,r){if(!Ri(r))throw new Error("Invalid input to extend: expected a plain object");const o={...t._zod.def,get shape(){const c={...t._zod.def.shape,...r};return Vo(this,"shape",c),c},checks:[]};return cr(t,o)}function qd(t,r){return cr(t,{...t._zod.def,get shape(){const o={...t._zod.def.shape,...r._zod.def.shape};return Vo(this,"shape",o),o},catchall:r._zod.def.catchall,checks:[]})}function Yd(t,r,o){const c=r._zod.def.shape,u={...c};if(o)for(const f in o){if(!(f in c))throw new Error(`Unrecognized key: "${f}"`);o[f]&&(u[f]=t?new t({type:"optional",innerType:c[f]}):c[f])}else for(const f in c)u[f]=t?new t({type:"optional",innerType:c[f]}):c[f];return cr(r,{...r._zod.def,shape:u,checks:[]})}function Jd(t,r,o){const c=r._zod.def.shape,u={...c};if(o)for(const f in o){if(!(f in u))throw new Error(`Unrecognized key: "${f}"`);o[f]&&(u[f]=new t({type:"nonoptional",innerType:c[f]}))}else for(const f in c)u[f]=new t({type:"nonoptional",innerType:c[f]});return cr(r,{...r._zod.def,shape:u,checks:[]})}function Wr(t,r=0){for(let o=r;o<t.issues.length;o++)if(t.issues[o]?.continue!==!0)return!0;return!1}function ir(t,r){return r.map(o=>{var c;return(c=o).path??(c.path=[]),o.path.unshift(t),o})}function yi(t){return typeof t=="string"?t:t?.message}function Wn(t,r,o){const c={...t,path:t.path??[]};if(!t.message){const u=yi(t.inst?._zod.def?.error?.(t))??yi(r?.error?.(t))??yi(o.customError?.(t))??yi(o.localeError?.(t))??"Invalid input";c.message=u}return delete c.inst,delete c.continue,r?.reportInput||delete c.input,c}function $o(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function Yr(...t){const[r,o,c]=t;return typeof r=="string"?{message:r,code:"custom",input:o,inst:c}:{...r}}const jl=(t,r)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:r,enumerable:!1}),Object.defineProperty(t,"message",{get(){return JSON.stringify(r,zd,2)},enumerable:!0}),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Hl=ie("$ZodError",jl),Wl=ie("$ZodError",jl,{Parent:Error});function Kd(t,r=o=>o.message){const o={},c=[];for(const u of t.issues)u.path.length>0?(o[u.path[0]]=o[u.path[0]]||[],o[u.path[0]].push(r(u))):c.push(r(u));return{formErrors:c,fieldErrors:o}}function Qd(t,r){const o=r||function(f){return f.message},c={_errors:[]},u=f=>{for(const p of f.issues)if(p.code==="invalid_union"&&p.errors.length)p.errors.map(x=>u({issues:x}));else if(p.code==="invalid_key")u({issues:p.issues});else if(p.code==="invalid_element")u({issues:p.issues});else if(p.path.length===0)c._errors.push(o(p));else{let x=c,y=0;for(;y<p.path.length;){const m=p.path[y];y===p.path.length-1?(x[m]=x[m]||{_errors:[]},x[m]._errors.push(o(p))):x[m]=x[m]||{_errors:[]},x=x[m],y++}}};return u(t),c}const e1=t=>(r,o,c,u)=>{const f=c?Object.assign(c,{async:!1}):{async:!1},p=r._zod.run({value:o,issues:[]},f);if(p instanceof Promise)throw new qr;if(p.issues.length){const x=new(u?.Err??t)(p.issues.map(y=>Wn(y,f,Hn())));throw Zl(x,u?.callee),x}return p.value},t1=t=>async(r,o,c,u)=>{const f=c?Object.assign(c,{async:!0}):{async:!0};let p=r._zod.run({value:o,issues:[]},f);if(p instanceof Promise&&(p=await p),p.issues.length){const x=new(u?.Err??t)(p.issues.map(y=>Wn(y,f,Hn())));throw Zl(x,u?.callee),x}return p.value},Gl=t=>(r,o,c)=>{const u=c?{...c,async:!1}:{async:!1},f=r._zod.run({value:o,issues:[]},u);if(f instanceof Promise)throw new qr;return f.issues.length?{success:!1,error:new(t??Hl)(f.issues.map(p=>Wn(p,u,Hn())))}:{success:!0,data:f.value}},n1=Gl(Wl),Xl=t=>async(r,o,c)=>{const u=c?Object.assign(c,{async:!0}):{async:!0};let f=r._zod.run({value:o,issues:[]},u);return f instanceof Promise&&(f=await f),f.issues.length?{success:!1,error:new t(f.issues.map(p=>Wn(p,u,Hn())))}:{success:!0,data:f.value}},r1=Xl(Wl),i1=/^[cC][^\s-]{8,}$/,o1=/^[0-9a-z]+$/,s1=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,a1=/^[0-9a-vA-V]{20}$/,l1=/^[A-Za-z0-9]{27}$/,c1=/^[a-zA-Z0-9_-]{21}$/,u1=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,d1=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Hs=t=>t?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/,f1=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,h1="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function p1(){return new RegExp(h1,"u")}const g1=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,m1=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/,x1=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,w1=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,y1=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,ql=/^[A-Za-z0-9_-]*$/,_1=/^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/,v1=/^\+(?:[0-9]){6,14}[0-9]$/,Yl="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",C1=new RegExp(`^${Yl}$`);function Jl(t){const r="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${r}`:t.precision===0?`${r}:[0-5]\\d`:`${r}:[0-5]\\d\\.\\d{${t.precision}}`:`${r}(?::[0-5]\\d(?:\\.\\d+)?)?`}function b1(t){return new RegExp(`^${Jl(t)}$`)}function E1(t){const r=Jl({precision:t.precision}),o=["Z"];t.local&&o.push(""),t.offset&&o.push("([+-]\\d{2}:\\d{2})");const c=`${r}(?:${o.join("|")})`;return new RegExp(`^${Yl}T(?:${c})$`)}const A1=t=>{const r=t?`[\\s\\S]{${t?.minimum??0},${t?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${r}$`)},I1=/^\d+$/,S1=/^-?\d+(?:\.\d+)?/i,T1=/true|false/i,N1=/null/i,O1=/^[^A-Z]*$/,k1=/^[^a-z]*$/,Qt=ie("$ZodCheck",(t,r)=>{var o;t._zod??(t._zod={}),t._zod.def=r,(o=t._zod).onattach??(o.onattach=[])}),Kl={number:"number",bigint:"bigint",object:"date"},Ql=ie("$ZodCheckLessThan",(t,r)=>{Qt.init(t,r);const o=Kl[typeof r.value];t._zod.onattach.push(c=>{const u=c._zod.bag,f=(r.inclusive?u.maximum:u.exclusiveMaximum)??Number.POSITIVE_INFINITY;r.value<f&&(r.inclusive?u.maximum=r.value:u.exclusiveMaximum=r.value)}),t._zod.check=c=>{(r.inclusive?c.value<=r.value:c.value<r.value)||c.issues.push({origin:o,code:"too_big",maximum:r.value,input:c.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),ec=ie("$ZodCheckGreaterThan",(t,r)=>{Qt.init(t,r);const o=Kl[typeof r.value];t._zod.onattach.push(c=>{const u=c._zod.bag,f=(r.inclusive?u.minimum:u.exclusiveMinimum)??Number.NEGATIVE_INFINITY;r.value>f&&(r.inclusive?u.minimum=r.value:u.exclusiveMinimum=r.value)}),t._zod.check=c=>{(r.inclusive?c.value>=r.value:c.value>r.value)||c.issues.push({origin:o,code:"too_small",minimum:r.value,input:c.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),R1=ie("$ZodCheckMultipleOf",(t,r)=>{Qt.init(t,r),t._zod.onattach.push(o=>{var c;(c=o._zod.bag).multipleOf??(c.multipleOf=r.value)}),t._zod.check=o=>{if(typeof o.value!=typeof r.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof o.value=="bigint"?o.value%r.value===BigInt(0):Vd(o.value,r.value)===0)||o.issues.push({origin:typeof o.value,code:"not_multiple_of",divisor:r.value,input:o.value,inst:t,continue:!r.abort})}}),M1=ie("$ZodCheckNumberFormat",(t,r)=>{Qt.init(t,r),r.format=r.format||"float64";const o=r.format?.includes("int"),c=o?"int":"number",[u,f]=Hd[r.format];t._zod.onattach.push(p=>{const x=p._zod.bag;x.format=r.format,x.minimum=u,x.maximum=f,o&&(x.pattern=I1)}),t._zod.check=p=>{const x=p.value;if(o){if(!Number.isInteger(x)){p.issues.push({expected:c,format:r.format,code:"invalid_type",input:x,inst:t});return}if(!Number.isSafeInteger(x)){x>0?p.issues.push({input:x,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:c,continue:!r.abort}):p.issues.push({input:x,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:c,continue:!r.abort});return}}x<u&&p.issues.push({origin:"number",input:x,code:"too_small",minimum:u,inclusive:!0,inst:t,continue:!r.abort}),x>f&&p.issues.push({origin:"number",input:x,code:"too_big",maximum:f,inst:t})}}),D1=ie("$ZodCheckMaxLength",(t,r)=>{var o;Qt.init(t,r),(o=t._zod.def).when??(o.when=c=>{const u=c.value;return!Uo(u)&&u.length!==void 0}),t._zod.onattach.push(c=>{const u=c._zod.bag.maximum??Number.POSITIVE_INFINITY;r.maximum<u&&(c._zod.bag.maximum=r.maximum)}),t._zod.check=c=>{const u=c.value;if(u.length<=r.maximum)return;const p=$o(u);c.issues.push({origin:p,code:"too_big",maximum:r.maximum,inclusive:!0,input:u,inst:t,continue:!r.abort})}}),P1=ie("$ZodCheckMinLength",(t,r)=>{var o;Qt.init(t,r),(o=t._zod.def).when??(o.when=c=>{const u=c.value;return!Uo(u)&&u.length!==void 0}),t._zod.onattach.push(c=>{const u=c._zod.bag.minimum??Number.NEGATIVE_INFINITY;r.minimum>u&&(c._zod.bag.minimum=r.minimum)}),t._zod.check=c=>{const u=c.value;if(u.length>=r.minimum)return;const p=$o(u);c.issues.push({origin:p,code:"too_small",minimum:r.minimum,inclusive:!0,input:u,inst:t,continue:!r.abort})}}),B1=ie("$ZodCheckLengthEquals",(t,r)=>{var o;Qt.init(t,r),(o=t._zod.def).when??(o.when=c=>{const u=c.value;return!Uo(u)&&u.length!==void 0}),t._zod.onattach.push(c=>{const u=c._zod.bag;u.minimum=r.length,u.maximum=r.length,u.length=r.length}),t._zod.check=c=>{const u=c.value,f=u.length;if(f===r.length)return;const p=$o(u),x=f>r.length;c.issues.push({origin:p,...x?{code:"too_big",maximum:r.length}:{code:"too_small",minimum:r.length},inclusive:!0,exact:!0,input:c.value,inst:t,continue:!r.abort})}}),Ui=ie("$ZodCheckStringFormat",(t,r)=>{var o,c;Qt.init(t,r),t._zod.onattach.push(u=>{const f=u._zod.bag;f.format=r.format,r.pattern&&(f.patterns??(f.patterns=new Set),f.patterns.add(r.pattern))}),r.pattern?(o=t._zod).check??(o.check=u=>{r.pattern.lastIndex=0,!r.pattern.test(u.value)&&u.issues.push({origin:"string",code:"invalid_format",format:r.format,input:u.value,...r.pattern?{pattern:r.pattern.toString()}:{},inst:t,continue:!r.abort})}):(c=t._zod).check??(c.check=()=>{})}),L1=ie("$ZodCheckRegex",(t,r)=>{Ui.init(t,r),t._zod.check=o=>{r.pattern.lastIndex=0,!r.pattern.test(o.value)&&o.issues.push({origin:"string",code:"invalid_format",format:"regex",input:o.value,pattern:r.pattern.toString(),inst:t,continue:!r.abort})}}),F1=ie("$ZodCheckLowerCase",(t,r)=>{r.pattern??(r.pattern=O1),Ui.init(t,r)}),U1=ie("$ZodCheckUpperCase",(t,r)=>{r.pattern??(r.pattern=k1),Ui.init(t,r)}),z1=ie("$ZodCheckIncludes",(t,r)=>{Qt.init(t,r);const o=ti(r.includes),c=new RegExp(typeof r.position=="number"?`^.{${r.position}}${o}`:o);r.pattern=c,t._zod.onattach.push(u=>{const f=u._zod.bag;f.patterns??(f.patterns=new Set),f.patterns.add(c)}),t._zod.check=u=>{u.value.includes(r.includes,r.position)||u.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:r.includes,input:u.value,inst:t,continue:!r.abort})}}),V1=ie("$ZodCheckStartsWith",(t,r)=>{Qt.init(t,r);const o=new RegExp(`^${ti(r.prefix)}.*`);r.pattern??(r.pattern=o),t._zod.onattach.push(c=>{const u=c._zod.bag;u.patterns??(u.patterns=new Set),u.patterns.add(o)}),t._zod.check=c=>{c.value.startsWith(r.prefix)||c.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:r.prefix,input:c.value,inst:t,continue:!r.abort})}}),$1=ie("$ZodCheckEndsWith",(t,r)=>{Qt.init(t,r);const o=new RegExp(`.*${ti(r.suffix)}$`);r.pattern??(r.pattern=o),t._zod.onattach.push(c=>{const u=c._zod.bag;u.patterns??(u.patterns=new Set),u.patterns.add(o)}),t._zod.check=c=>{c.value.endsWith(r.suffix)||c.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:r.suffix,input:c.value,inst:t,continue:!r.abort})}}),Z1=ie("$ZodCheckOverwrite",(t,r)=>{Qt.init(t,r),t._zod.check=o=>{o.value=r.tx(o.value)}});class j1{constructor(r=[]){this.content=[],this.indent=0,this&&(this.args=r)}indented(r){this.indent+=1,r(this),this.indent-=1}write(r){if(typeof r=="function"){r(this,{execution:"sync"}),r(this,{execution:"async"});return}const c=r.split(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("vue"),Lt=require("@opentiny/tiny-robot"),bd=require("@opentiny/genui-sdk-vue"),Wn=require("@opentiny/tiny-robot-kit"),Sr=require("@opentiny/tiny-robot-svgs"),cr=require("@opentiny/next-sdk"),Ed=require("@opentiny/vue-tooltip"),Ad=require("@opentiny/vue-icon");function Id(t,r){for(var o=0;o<r.length;o++){const c=r[o];if(typeof c!="string"&&!Array.isArray(c)){for(const u in c)if(u!=="default"&&!(u in t)){const f=Object.getOwnPropertyDescriptor(c,u);f&&Object.defineProperty(t,u,f.get?f:{enumerable:!0,get:()=>c[u]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}var wl="vercel.ai.error",Sd=Symbol.for(wl),Es,As,xt=class _l extends(As=Error,Es=Sd,As){constructor({name:r,message:o,cause:c}){super(o),this[Es]=!0,this.name=r,this.cause=c}static isInstance(r){return _l.hasMarker(r,wl)}static hasMarker(r,o){const c=Symbol.for(o);return r!=null&&typeof r=="object"&&c in r&&typeof r[c]=="boolean"&&r[c]===!0}},vl="AI_APICallError",Cl=`vercel.ai.error.${vl}`,Td=Symbol.for(Cl),Is,Ss,an=class extends(Ss=xt,Is=Td,Ss){constructor({message:r,url:o,requestBodyValues:c,statusCode:u,responseHeaders:f,responseBody:p,cause:x,isRetryable:_=u!=null&&(u===408||u===409||u===429||u>=500),data:g}){super({name:vl,message:r,cause:x}),this[Is]=!0,this.url=o,this.requestBodyValues=c,this.statusCode=u,this.responseHeaders=f,this.responseBody=p,this.isRetryable=_,this.data=g}static isInstance(r){return xt.hasMarker(r,Cl)}},bl="AI_EmptyResponseBodyError",El=`vercel.ai.error.${bl}`,Nd=Symbol.for(El),Ts,Ns,Od=class extends(Ns=xt,Ts=Nd,Ns){constructor({message:r="Empty response body"}={}){super({name:bl,message:r}),this[Ts]=!0}static isInstance(r){return xt.hasMarker(r,El)}};function Al(t){return t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:JSON.stringify(t)}var Il="AI_InvalidArgumentError",Sl=`vercel.ai.error.${Il}`,kd=Symbol.for(Sl),Os,ks,Tl=class extends(ks=xt,Os=kd,ks){constructor({message:r,cause:o,argument:c}){super({name:Il,message:r,cause:o}),this[Os]=!0,this.argument=c}static isInstance(r){return xt.hasMarker(r,Sl)}},Nl="AI_InvalidPromptError",Ol=`vercel.ai.error.${Nl}`,Rd=Symbol.for(Ol),Rs,Ms,Md=class extends(Ms=xt,Rs=Rd,Ms){constructor({prompt:t,message:r,cause:o}){super({name:Nl,message:`Invalid prompt: ${r}`,cause:o}),this[Rs]=!0,this.prompt=t}static isInstance(t){return xt.hasMarker(t,Ol)}},kl="AI_InvalidResponseDataError",Rl=`vercel.ai.error.${kl}`,Dd=Symbol.for(Rl),Ds,Ps,uo=class extends(Ps=xt,Ds=Dd,Ps){constructor({data:r,message:o=`Invalid response data: ${JSON.stringify(r)}.`}){super({name:kl,message:o}),this[Ds]=!0,this.data=r}static isInstance(r){return xt.hasMarker(r,Rl)}},Ml="AI_JSONParseError",Dl=`vercel.ai.error.${Ml}`,Pd=Symbol.for(Dl),Bs,Ls,Oi=class extends(Ls=xt,Bs=Pd,Ls){constructor({text:r,cause:o}){super({name:Ml,message:`JSON parsing failed: Text: ${r}.
2
+ Error message: ${Al(o)}`,cause:o}),this[Bs]=!0,this.text=r}static isInstance(r){return xt.hasMarker(r,Dl)}},Pl="AI_LoadAPIKeyError",Bl=`vercel.ai.error.${Pl}`,Bd=Symbol.for(Bl),Fs,Us,yi=class extends(Us=xt,Fs=Bd,Us){constructor({message:r}){super({name:Pl,message:r}),this[Fs]=!0}static isInstance(r){return xt.hasMarker(r,Bl)}},Ll="AI_TooManyEmbeddingValuesForCallError",Fl=`vercel.ai.error.${Ll}`,Ld=Symbol.for(Fl),zs,Vs,Fd=class extends(Vs=xt,zs=Ld,Vs){constructor(t){super({name:Ll,message:`Too many values for a single embedding call. The ${t.provider} model "${t.modelId}" can only embed up to ${t.maxEmbeddingsPerCall} values per call, but ${t.values.length} values were provided.`}),this[zs]=!0,this.provider=t.provider,this.modelId=t.modelId,this.maxEmbeddingsPerCall=t.maxEmbeddingsPerCall,this.values=t.values}static isInstance(t){return xt.hasMarker(t,Fl)}},Ul="AI_TypeValidationError",zl=`vercel.ai.error.${Ul}`,Ud=Symbol.for(zl),$s,Zs,ur=class Eo extends(Zs=xt,$s=Ud,Zs){constructor({value:r,cause:o,context:c}){let u="Type validation failed";if(c?.field&&(u+=` for ${c.field}`),c?.entityName||c?.entityId){u+=" (";const f=[];c.entityName&&f.push(c.entityName),c.entityId&&f.push(`id: "${c.entityId}"`),u+=f.join(", "),u+=")"}super({name:Ul,message:`${u}: Value: ${JSON.stringify(r)}.
3
+ Error message: ${Al(o)}`,cause:o}),this[$s]=!0,this.value=r,this.context=c}static isInstance(r){return xt.hasMarker(r,zl)}static wrap({value:r,cause:o,context:c}){var u,f,p;return Eo.isInstance(o)&&o.value===r&&((u=o.context)==null?void 0:u.field)===c?.field&&((f=o.context)==null?void 0:f.entityName)===c?.entityName&&((p=o.context)==null?void 0:p.entityId)===c?.entityId?o:new Eo({value:r,cause:o,context:c})}},Vl="AI_UnsupportedFunctionalityError",$l=`vercel.ai.error.${Vl}`,zd=Symbol.for($l),js,Hs,Dn=class extends(Hs=xt,js=zd,Hs){constructor({functionality:r,message:o=`'${r}' functionality not supported.`}){super({name:Vl,message:o}),this[js]=!0,this.functionality=r}static isInstance(r){return xt.hasMarker(r,$l)}};function se(t,r,o){function c(x,_){var g;Object.defineProperty(x,"_zod",{value:x._zod??{},enumerable:!1}),(g=x._zod).traits??(g.traits=new Set),x._zod.traits.add(t),r(x,_);for(const A in p.prototype)A in x||Object.defineProperty(x,A,{value:p.prototype[A].bind(x)});x._zod.constr=p,x._zod.def=_}const u=o?.Parent??Object;class f extends u{}Object.defineProperty(f,"name",{value:t});function p(x){var _;const g=o?.Parent?new f:this;c(g,x),(_=g._zod).deferred??(_.deferred=[]);for(const A of g._zod.deferred)A();return g}return Object.defineProperty(p,"init",{value:c}),Object.defineProperty(p,Symbol.hasInstance,{value:x=>o?.Parent&&x instanceof o.Parent?!0:x?._zod?.traits?.has(t)}),Object.defineProperty(p,"name",{value:t}),p}class Yr extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}const Zl={};function Xn(t){return Zl}function jl(t){const r=Object.values(t).filter(c=>typeof c=="number");return Object.entries(t).filter(([c,u])=>r.indexOf(+c)===-1).map(([c,u])=>u)}function Vd(t,r){return typeof r=="bigint"?r.toString():r}function Uo(t){return{get value(){{const r=t();return Object.defineProperty(this,"value",{value:r}),r}}}}function zo(t){return t==null}function Vo(t){const r=t.startsWith("^")?1:0,o=t.endsWith("$")?t.length-1:t.length;return t.slice(r,o)}function $d(t,r){const o=(t.toString().split(".")[1]||"").length,c=(r.toString().split(".")[1]||"").length,u=o>c?o:c,f=Number.parseInt(t.toFixed(u).replace(".","")),p=Number.parseInt(r.toFixed(u).replace(".",""));return f%p/10**u}function Qe(t,r,o){Object.defineProperty(t,r,{get(){{const c=o();return t[r]=c,c}},set(c){Object.defineProperty(t,r,{value:c})},configurable:!0})}function $o(t,r,o){Object.defineProperty(t,r,{value:o,writable:!0,enumerable:!0,configurable:!0})}function Ur(t){return JSON.stringify(t)}const Hl=Error.captureStackTrace?Error.captureStackTrace:(...t)=>{};function ki(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}const Zd=Uo(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const t=Function;return new t(""),!0}catch{return!1}});function Ri(t){if(ki(t)===!1)return!1;const r=t.constructor;if(r===void 0)return!0;const o=r.prototype;return!(ki(o)===!1||Object.prototype.hasOwnProperty.call(o,"isPrototypeOf")===!1)}const jd=new Set(["string","number","symbol"]);function ni(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function fr(t,r,o){const c=new t._zod.constr(r??t._zod.def);return(!r||o?.parent)&&(c._zod.parent=t),c}function be(t){const r=t;if(!r)return{};if(typeof r=="string")return{error:()=>r};if(r?.message!==void 0){if(r?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");r.error=r.message}return delete r.message,typeof r.error=="string"?{...r,error:()=>r.error}:r}function Hd(t){return Object.keys(t).filter(r=>t[r]._zod.optin==="optional"&&t[r]._zod.optout==="optional")}const Wd={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Gd(t,r){const o={},c=t._zod.def;for(const u in r){if(!(u in c.shape))throw new Error(`Unrecognized key: "${u}"`);r[u]&&(o[u]=c.shape[u])}return fr(t,{...t._zod.def,shape:o,checks:[]})}function Xd(t,r){const o={...t._zod.def.shape},c=t._zod.def;for(const u in r){if(!(u in c.shape))throw new Error(`Unrecognized key: "${u}"`);r[u]&&delete o[u]}return fr(t,{...t._zod.def,shape:o,checks:[]})}function qd(t,r){if(!Ri(r))throw new Error("Invalid input to extend: expected a plain object");const o={...t._zod.def,get shape(){const c={...t._zod.def.shape,...r};return $o(this,"shape",c),c},checks:[]};return fr(t,o)}function Yd(t,r){return fr(t,{...t._zod.def,get shape(){const o={...t._zod.def.shape,...r._zod.def.shape};return $o(this,"shape",o),o},catchall:r._zod.def.catchall,checks:[]})}function Jd(t,r,o){const c=r._zod.def.shape,u={...c};if(o)for(const f in o){if(!(f in c))throw new Error(`Unrecognized key: "${f}"`);o[f]&&(u[f]=t?new t({type:"optional",innerType:c[f]}):c[f])}else for(const f in c)u[f]=t?new t({type:"optional",innerType:c[f]}):c[f];return fr(r,{...r._zod.def,shape:u,checks:[]})}function Kd(t,r,o){const c=r._zod.def.shape,u={...c};if(o)for(const f in o){if(!(f in u))throw new Error(`Unrecognized key: "${f}"`);o[f]&&(u[f]=new t({type:"nonoptional",innerType:c[f]}))}else for(const f in c)u[f]=new t({type:"nonoptional",innerType:c[f]});return fr(r,{...r._zod.def,shape:u,checks:[]})}function Gr(t,r=0){for(let o=r;o<t.issues.length;o++)if(t.issues[o]?.continue!==!0)return!0;return!1}function ar(t,r){return r.map(o=>{var c;return(c=o).path??(c.path=[]),o.path.unshift(t),o})}function wi(t){return typeof t=="string"?t:t?.message}function qn(t,r,o){const c={...t,path:t.path??[]};if(!t.message){const u=wi(t.inst?._zod.def?.error?.(t))??wi(r?.error?.(t))??wi(o.customError?.(t))??wi(o.localeError?.(t))??"Invalid input";c.message=u}return delete c.inst,delete c.continue,r?.reportInput||delete c.input,c}function Zo(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function Jr(...t){const[r,o,c]=t;return typeof r=="string"?{message:r,code:"custom",input:o,inst:c}:{...r}}const Wl=(t,r)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:r,enumerable:!1}),Object.defineProperty(t,"message",{get(){return JSON.stringify(r,Vd,2)},enumerable:!0}),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Gl=se("$ZodError",Wl),Xl=se("$ZodError",Wl,{Parent:Error});function Qd(t,r=o=>o.message){const o={},c=[];for(const u of t.issues)u.path.length>0?(o[u.path[0]]=o[u.path[0]]||[],o[u.path[0]].push(r(u))):c.push(r(u));return{formErrors:c,fieldErrors:o}}function e1(t,r){const o=r||function(f){return f.message},c={_errors:[]},u=f=>{for(const p of f.issues)if(p.code==="invalid_union"&&p.errors.length)p.errors.map(x=>u({issues:x}));else if(p.code==="invalid_key")u({issues:p.issues});else if(p.code==="invalid_element")u({issues:p.issues});else if(p.path.length===0)c._errors.push(o(p));else{let x=c,_=0;for(;_<p.path.length;){const g=p.path[_];_===p.path.length-1?(x[g]=x[g]||{_errors:[]},x[g]._errors.push(o(p))):x[g]=x[g]||{_errors:[]},x=x[g],_++}}};return u(t),c}const t1=t=>(r,o,c,u)=>{const f=c?Object.assign(c,{async:!1}):{async:!1},p=r._zod.run({value:o,issues:[]},f);if(p instanceof Promise)throw new Yr;if(p.issues.length){const x=new(u?.Err??t)(p.issues.map(_=>qn(_,f,Xn())));throw Hl(x,u?.callee),x}return p.value},n1=t=>async(r,o,c,u)=>{const f=c?Object.assign(c,{async:!0}):{async:!0};let p=r._zod.run({value:o,issues:[]},f);if(p instanceof Promise&&(p=await p),p.issues.length){const x=new(u?.Err??t)(p.issues.map(_=>qn(_,f,Xn())));throw Hl(x,u?.callee),x}return p.value},ql=t=>(r,o,c)=>{const u=c?{...c,async:!1}:{async:!1},f=r._zod.run({value:o,issues:[]},u);if(f instanceof Promise)throw new Yr;return f.issues.length?{success:!1,error:new(t??Gl)(f.issues.map(p=>qn(p,u,Xn())))}:{success:!0,data:f.value}},r1=ql(Xl),Yl=t=>async(r,o,c)=>{const u=c?Object.assign(c,{async:!0}):{async:!0};let f=r._zod.run({value:o,issues:[]},u);return f instanceof Promise&&(f=await f),f.issues.length?{success:!1,error:new t(f.issues.map(p=>qn(p,u,Xn())))}:{success:!0,data:f.value}},i1=Yl(Xl),o1=/^[cC][^\s-]{8,}$/,s1=/^[0-9a-z]+$/,a1=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,l1=/^[0-9a-vA-V]{20}$/,c1=/^[A-Za-z0-9]{27}$/,u1=/^[a-zA-Z0-9_-]{21}$/,d1=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,f1=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Ws=t=>t?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/,h1=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,p1="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function m1(){return new RegExp(p1,"u")}const g1=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,x1=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/,y1=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,w1=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,_1=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Jl=/^[A-Za-z0-9_-]*$/,v1=/^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/,C1=/^\+(?:[0-9]){6,14}[0-9]$/,Kl="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",b1=new RegExp(`^${Kl}$`);function Ql(t){const r="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${r}`:t.precision===0?`${r}:[0-5]\\d`:`${r}:[0-5]\\d\\.\\d{${t.precision}}`:`${r}(?::[0-5]\\d(?:\\.\\d+)?)?`}function E1(t){return new RegExp(`^${Ql(t)}$`)}function A1(t){const r=Ql({precision:t.precision}),o=["Z"];t.local&&o.push(""),t.offset&&o.push("([+-]\\d{2}:\\d{2})");const c=`${r}(?:${o.join("|")})`;return new RegExp(`^${Kl}T(?:${c})$`)}const I1=t=>{const r=t?`[\\s\\S]{${t?.minimum??0},${t?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${r}$`)},S1=/^\d+$/,T1=/^-?\d+(?:\.\d+)?/i,N1=/true|false/i,O1=/null/i,k1=/^[^A-Z]*$/,R1=/^[^a-z]*$/,nn=se("$ZodCheck",(t,r)=>{var o;t._zod??(t._zod={}),t._zod.def=r,(o=t._zod).onattach??(o.onattach=[])}),ec={number:"number",bigint:"bigint",object:"date"},tc=se("$ZodCheckLessThan",(t,r)=>{nn.init(t,r);const o=ec[typeof r.value];t._zod.onattach.push(c=>{const u=c._zod.bag,f=(r.inclusive?u.maximum:u.exclusiveMaximum)??Number.POSITIVE_INFINITY;r.value<f&&(r.inclusive?u.maximum=r.value:u.exclusiveMaximum=r.value)}),t._zod.check=c=>{(r.inclusive?c.value<=r.value:c.value<r.value)||c.issues.push({origin:o,code:"too_big",maximum:r.value,input:c.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),nc=se("$ZodCheckGreaterThan",(t,r)=>{nn.init(t,r);const o=ec[typeof r.value];t._zod.onattach.push(c=>{const u=c._zod.bag,f=(r.inclusive?u.minimum:u.exclusiveMinimum)??Number.NEGATIVE_INFINITY;r.value>f&&(r.inclusive?u.minimum=r.value:u.exclusiveMinimum=r.value)}),t._zod.check=c=>{(r.inclusive?c.value>=r.value:c.value>r.value)||c.issues.push({origin:o,code:"too_small",minimum:r.value,input:c.value,inclusive:r.inclusive,inst:t,continue:!r.abort})}}),M1=se("$ZodCheckMultipleOf",(t,r)=>{nn.init(t,r),t._zod.onattach.push(o=>{var c;(c=o._zod.bag).multipleOf??(c.multipleOf=r.value)}),t._zod.check=o=>{if(typeof o.value!=typeof r.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof o.value=="bigint"?o.value%r.value===BigInt(0):$d(o.value,r.value)===0)||o.issues.push({origin:typeof o.value,code:"not_multiple_of",divisor:r.value,input:o.value,inst:t,continue:!r.abort})}}),D1=se("$ZodCheckNumberFormat",(t,r)=>{nn.init(t,r),r.format=r.format||"float64";const o=r.format?.includes("int"),c=o?"int":"number",[u,f]=Wd[r.format];t._zod.onattach.push(p=>{const x=p._zod.bag;x.format=r.format,x.minimum=u,x.maximum=f,o&&(x.pattern=S1)}),t._zod.check=p=>{const x=p.value;if(o){if(!Number.isInteger(x)){p.issues.push({expected:c,format:r.format,code:"invalid_type",input:x,inst:t});return}if(!Number.isSafeInteger(x)){x>0?p.issues.push({input:x,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:c,continue:!r.abort}):p.issues.push({input:x,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:c,continue:!r.abort});return}}x<u&&p.issues.push({origin:"number",input:x,code:"too_small",minimum:u,inclusive:!0,inst:t,continue:!r.abort}),x>f&&p.issues.push({origin:"number",input:x,code:"too_big",maximum:f,inst:t})}}),P1=se("$ZodCheckMaxLength",(t,r)=>{var o;nn.init(t,r),(o=t._zod.def).when??(o.when=c=>{const u=c.value;return!zo(u)&&u.length!==void 0}),t._zod.onattach.push(c=>{const u=c._zod.bag.maximum??Number.POSITIVE_INFINITY;r.maximum<u&&(c._zod.bag.maximum=r.maximum)}),t._zod.check=c=>{const u=c.value;if(u.length<=r.maximum)return;const p=Zo(u);c.issues.push({origin:p,code:"too_big",maximum:r.maximum,inclusive:!0,input:u,inst:t,continue:!r.abort})}}),B1=se("$ZodCheckMinLength",(t,r)=>{var o;nn.init(t,r),(o=t._zod.def).when??(o.when=c=>{const u=c.value;return!zo(u)&&u.length!==void 0}),t._zod.onattach.push(c=>{const u=c._zod.bag.minimum??Number.NEGATIVE_INFINITY;r.minimum>u&&(c._zod.bag.minimum=r.minimum)}),t._zod.check=c=>{const u=c.value;if(u.length>=r.minimum)return;const p=Zo(u);c.issues.push({origin:p,code:"too_small",minimum:r.minimum,inclusive:!0,input:u,inst:t,continue:!r.abort})}}),L1=se("$ZodCheckLengthEquals",(t,r)=>{var o;nn.init(t,r),(o=t._zod.def).when??(o.when=c=>{const u=c.value;return!zo(u)&&u.length!==void 0}),t._zod.onattach.push(c=>{const u=c._zod.bag;u.minimum=r.length,u.maximum=r.length,u.length=r.length}),t._zod.check=c=>{const u=c.value,f=u.length;if(f===r.length)return;const p=Zo(u),x=f>r.length;c.issues.push({origin:p,...x?{code:"too_big",maximum:r.length}:{code:"too_small",minimum:r.length},inclusive:!0,exact:!0,input:c.value,inst:t,continue:!r.abort})}}),Ui=se("$ZodCheckStringFormat",(t,r)=>{var o,c;nn.init(t,r),t._zod.onattach.push(u=>{const f=u._zod.bag;f.format=r.format,r.pattern&&(f.patterns??(f.patterns=new Set),f.patterns.add(r.pattern))}),r.pattern?(o=t._zod).check??(o.check=u=>{r.pattern.lastIndex=0,!r.pattern.test(u.value)&&u.issues.push({origin:"string",code:"invalid_format",format:r.format,input:u.value,...r.pattern?{pattern:r.pattern.toString()}:{},inst:t,continue:!r.abort})}):(c=t._zod).check??(c.check=()=>{})}),F1=se("$ZodCheckRegex",(t,r)=>{Ui.init(t,r),t._zod.check=o=>{r.pattern.lastIndex=0,!r.pattern.test(o.value)&&o.issues.push({origin:"string",code:"invalid_format",format:"regex",input:o.value,pattern:r.pattern.toString(),inst:t,continue:!r.abort})}}),U1=se("$ZodCheckLowerCase",(t,r)=>{r.pattern??(r.pattern=k1),Ui.init(t,r)}),z1=se("$ZodCheckUpperCase",(t,r)=>{r.pattern??(r.pattern=R1),Ui.init(t,r)}),V1=se("$ZodCheckIncludes",(t,r)=>{nn.init(t,r);const o=ni(r.includes),c=new RegExp(typeof r.position=="number"?`^.{${r.position}}${o}`:o);r.pattern=c,t._zod.onattach.push(u=>{const f=u._zod.bag;f.patterns??(f.patterns=new Set),f.patterns.add(c)}),t._zod.check=u=>{u.value.includes(r.includes,r.position)||u.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:r.includes,input:u.value,inst:t,continue:!r.abort})}}),$1=se("$ZodCheckStartsWith",(t,r)=>{nn.init(t,r);const o=new RegExp(`^${ni(r.prefix)}.*`);r.pattern??(r.pattern=o),t._zod.onattach.push(c=>{const u=c._zod.bag;u.patterns??(u.patterns=new Set),u.patterns.add(o)}),t._zod.check=c=>{c.value.startsWith(r.prefix)||c.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:r.prefix,input:c.value,inst:t,continue:!r.abort})}}),Z1=se("$ZodCheckEndsWith",(t,r)=>{nn.init(t,r);const o=new RegExp(`.*${ni(r.suffix)}$`);r.pattern??(r.pattern=o),t._zod.onattach.push(c=>{const u=c._zod.bag;u.patterns??(u.patterns=new Set),u.patterns.add(o)}),t._zod.check=c=>{c.value.endsWith(r.suffix)||c.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:r.suffix,input:c.value,inst:t,continue:!r.abort})}}),j1=se("$ZodCheckOverwrite",(t,r)=>{nn.init(t,r),t._zod.check=o=>{o.value=r.tx(o.value)}});class H1{constructor(r=[]){this.content=[],this.indent=0,this&&(this.args=r)}indented(r){this.indent+=1,r(this),this.indent-=1}write(r){if(typeof r=="function"){r(this,{execution:"sync"}),r(this,{execution:"async"});return}const c=r.split(`
4
4
  `).filter(p=>p),u=Math.min(...c.map(p=>p.length-p.trimStart().length)),f=c.map(p=>p.slice(u)).map(p=>" ".repeat(this.indent*2)+p);for(const p of f)this.content.push(p)}compile(){const r=Function,o=this?.args,u=[...(this?.content??[""]).map(f=>` ${f}`)];return new r(...o,u.join(`
5
- `))}}const H1={major:4,minor:0,patch:0},st=ie("$ZodType",(t,r)=>{var o;t??(t={}),t._zod.def=r,t._zod.bag=t._zod.bag||{},t._zod.version=H1;const c=[...t._zod.def.checks??[]];t._zod.traits.has("$ZodCheck")&&c.unshift(t);for(const u of c)for(const f of u._zod.onattach)f(t);if(c.length===0)(o=t._zod).deferred??(o.deferred=[]),t._zod.deferred?.push(()=>{t._zod.run=t._zod.parse});else{const u=(f,p,x)=>{let y=Wr(f),m;for(const A of p){if(A._zod.def.when){if(!A._zod.def.when(f))continue}else if(y)continue;const E=f.issues.length,B=A._zod.check(f);if(B instanceof Promise&&x?.async===!1)throw new qr;if(m||B instanceof Promise)m=(m??Promise.resolve()).then(async()=>{await B,f.issues.length!==E&&(y||(y=Wr(f,E)))});else{if(f.issues.length===E)continue;y||(y=Wr(f,E))}}return m?m.then(()=>f):f};t._zod.run=(f,p)=>{const x=t._zod.parse(f,p);if(x instanceof Promise){if(p.async===!1)throw new qr;return x.then(y=>u(y,c,p))}return u(x,c,p)}}t["~standard"]={validate:u=>{try{const f=n1(t,u);return f.success?{value:f.data}:{issues:f.error?.issues}}catch{return r1(t,u).then(p=>p.success?{value:p.data}:{issues:p.error?.issues})}},vendor:"zod",version:1}}),Zo=ie("$ZodString",(t,r)=>{st.init(t,r),t._zod.pattern=[...t?._zod.bag?.patterns??[]].pop()??A1(t._zod.bag),t._zod.parse=(o,c)=>{if(r.coerce)try{o.value=String(o.value)}catch{}return typeof o.value=="string"||o.issues.push({expected:"string",code:"invalid_type",input:o.value,inst:t}),o}}),mt=ie("$ZodStringFormat",(t,r)=>{Ui.init(t,r),Zo.init(t,r)}),W1=ie("$ZodGUID",(t,r)=>{r.pattern??(r.pattern=d1),mt.init(t,r)}),G1=ie("$ZodUUID",(t,r)=>{if(r.version){const c={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[r.version];if(c===void 0)throw new Error(`Invalid UUID version: "${r.version}"`);r.pattern??(r.pattern=Hs(c))}else r.pattern??(r.pattern=Hs());mt.init(t,r)}),X1=ie("$ZodEmail",(t,r)=>{r.pattern??(r.pattern=f1),mt.init(t,r)}),q1=ie("$ZodURL",(t,r)=>{mt.init(t,r),t._zod.check=o=>{try{const c=o.value,u=new URL(c),f=u.href;r.hostname&&(r.hostname.lastIndex=0,r.hostname.test(u.hostname)||o.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:_1.source,input:o.value,inst:t,continue:!r.abort})),r.protocol&&(r.protocol.lastIndex=0,r.protocol.test(u.protocol.endsWith(":")?u.protocol.slice(0,-1):u.protocol)||o.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:r.protocol.source,input:o.value,inst:t,continue:!r.abort})),!c.endsWith("/")&&f.endsWith("/")?o.value=f.slice(0,-1):o.value=f;return}catch{o.issues.push({code:"invalid_format",format:"url",input:o.value,inst:t,continue:!r.abort})}}}),Y1=ie("$ZodEmoji",(t,r)=>{r.pattern??(r.pattern=p1()),mt.init(t,r)}),J1=ie("$ZodNanoID",(t,r)=>{r.pattern??(r.pattern=c1),mt.init(t,r)}),K1=ie("$ZodCUID",(t,r)=>{r.pattern??(r.pattern=i1),mt.init(t,r)}),Q1=ie("$ZodCUID2",(t,r)=>{r.pattern??(r.pattern=o1),mt.init(t,r)}),e0=ie("$ZodULID",(t,r)=>{r.pattern??(r.pattern=s1),mt.init(t,r)}),t0=ie("$ZodXID",(t,r)=>{r.pattern??(r.pattern=a1),mt.init(t,r)}),n0=ie("$ZodKSUID",(t,r)=>{r.pattern??(r.pattern=l1),mt.init(t,r)}),r0=ie("$ZodISODateTime",(t,r)=>{r.pattern??(r.pattern=E1(r)),mt.init(t,r)}),i0=ie("$ZodISODate",(t,r)=>{r.pattern??(r.pattern=C1),mt.init(t,r)}),o0=ie("$ZodISOTime",(t,r)=>{r.pattern??(r.pattern=b1(r)),mt.init(t,r)}),s0=ie("$ZodISODuration",(t,r)=>{r.pattern??(r.pattern=u1),mt.init(t,r)}),a0=ie("$ZodIPv4",(t,r)=>{r.pattern??(r.pattern=g1),mt.init(t,r),t._zod.onattach.push(o=>{const c=o._zod.bag;c.format="ipv4"})}),l0=ie("$ZodIPv6",(t,r)=>{r.pattern??(r.pattern=m1),mt.init(t,r),t._zod.onattach.push(o=>{const c=o._zod.bag;c.format="ipv6"}),t._zod.check=o=>{try{new URL(`http://[${o.value}]`)}catch{o.issues.push({code:"invalid_format",format:"ipv6",input:o.value,inst:t,continue:!r.abort})}}}),c0=ie("$ZodCIDRv4",(t,r)=>{r.pattern??(r.pattern=x1),mt.init(t,r)}),u0=ie("$ZodCIDRv6",(t,r)=>{r.pattern??(r.pattern=w1),mt.init(t,r),t._zod.check=o=>{const[c,u]=o.value.split("/");try{if(!u)throw new Error;const f=Number(u);if(`${f}`!==u)throw new Error;if(f<0||f>128)throw new Error;new URL(`http://[${c}]`)}catch{o.issues.push({code:"invalid_format",format:"cidrv6",input:o.value,inst:t,continue:!r.abort})}}});function tc(t){if(t==="")return!0;if(t.length%4!==0)return!1;try{return atob(t),!0}catch{return!1}}const d0=ie("$ZodBase64",(t,r)=>{r.pattern??(r.pattern=y1),mt.init(t,r),t._zod.onattach.push(o=>{o._zod.bag.contentEncoding="base64"}),t._zod.check=o=>{tc(o.value)||o.issues.push({code:"invalid_format",format:"base64",input:o.value,inst:t,continue:!r.abort})}});function f0(t){if(!ql.test(t))return!1;const r=t.replace(/[-_]/g,c=>c==="-"?"+":"/"),o=r.padEnd(Math.ceil(r.length/4)*4,"=");return tc(o)}const h0=ie("$ZodBase64URL",(t,r)=>{r.pattern??(r.pattern=ql),mt.init(t,r),t._zod.onattach.push(o=>{o._zod.bag.contentEncoding="base64url"}),t._zod.check=o=>{f0(o.value)||o.issues.push({code:"invalid_format",format:"base64url",input:o.value,inst:t,continue:!r.abort})}}),p0=ie("$ZodE164",(t,r)=>{r.pattern??(r.pattern=v1),mt.init(t,r)});function g0(t,r=null){try{const o=t.split(".");if(o.length!==3)return!1;const[c]=o;if(!c)return!1;const u=JSON.parse(atob(c));return!("typ"in u&&u?.typ!=="JWT"||!u.alg||r&&(!("alg"in u)||u.alg!==r))}catch{return!1}}const m0=ie("$ZodJWT",(t,r)=>{mt.init(t,r),t._zod.check=o=>{g0(o.value,r.alg)||o.issues.push({code:"invalid_format",format:"jwt",input:o.value,inst:t,continue:!r.abort})}}),nc=ie("$ZodNumber",(t,r)=>{st.init(t,r),t._zod.pattern=t._zod.bag.pattern??S1,t._zod.parse=(o,c)=>{if(r.coerce)try{o.value=Number(o.value)}catch{}const u=o.value;if(typeof u=="number"&&!Number.isNaN(u)&&Number.isFinite(u))return o;const f=typeof u=="number"?Number.isNaN(u)?"NaN":Number.isFinite(u)?void 0:"Infinity":void 0;return o.issues.push({expected:"number",code:"invalid_type",input:u,inst:t,...f?{received:f}:{}}),o}}),x0=ie("$ZodNumber",(t,r)=>{M1.init(t,r),nc.init(t,r)}),w0=ie("$ZodBoolean",(t,r)=>{st.init(t,r),t._zod.pattern=T1,t._zod.parse=(o,c)=>{if(r.coerce)try{o.value=!!o.value}catch{}const u=o.value;return typeof u=="boolean"||o.issues.push({expected:"boolean",code:"invalid_type",input:u,inst:t}),o}}),y0=ie("$ZodNull",(t,r)=>{st.init(t,r),t._zod.pattern=N1,t._zod.values=new Set([null]),t._zod.parse=(o,c)=>{const u=o.value;return u===null||o.issues.push({expected:"null",code:"invalid_type",input:u,inst:t}),o}}),_0=ie("$ZodAny",(t,r)=>{st.init(t,r),t._zod.parse=o=>o}),v0=ie("$ZodUnknown",(t,r)=>{st.init(t,r),t._zod.parse=o=>o}),C0=ie("$ZodNever",(t,r)=>{st.init(t,r),t._zod.parse=(o,c)=>(o.issues.push({expected:"never",code:"invalid_type",input:o.value,inst:t}),o)});function Ws(t,r,o){t.issues.length&&r.issues.push(...ir(o,t.issues)),r.value[o]=t.value}const b0=ie("$ZodArray",(t,r)=>{st.init(t,r),t._zod.parse=(o,c)=>{const u=o.value;if(!Array.isArray(u))return o.issues.push({expected:"array",code:"invalid_type",input:u,inst:t}),o;o.value=Array(u.length);const f=[];for(let p=0;p<u.length;p++){const x=u[p],y=r.element._zod.run({value:x,issues:[]},c);y instanceof Promise?f.push(y.then(m=>Ws(m,o,p))):Ws(y,o,p)}return f.length?Promise.all(f).then(()=>o):o}});function _i(t,r,o){t.issues.length&&r.issues.push(...ir(o,t.issues)),r.value[o]=t.value}function Gs(t,r,o,c){t.issues.length?c[o]===void 0?o in c?r.value[o]=void 0:r.value[o]=t.value:r.issues.push(...ir(o,t.issues)):t.value===void 0?o in c&&(r.value[o]=void 0):r.value[o]=t.value}const E0=ie("$ZodObject",(t,r)=>{st.init(t,r);const o=Fo(()=>{const E=Object.keys(r.shape);for(const D of E)if(!(r.shape[D]instanceof st))throw new Error(`Invalid element at key "${D}": expected a Zod schema`);const B=jd(r.shape);return{shape:r.shape,keys:E,keySet:new Set(E),numKeys:E.length,optionalKeys:new Set(B)}});Ke(t._zod,"propValues",()=>{const E=r.shape,B={};for(const D in E){const M=E[D]._zod;if(M.values){B[D]??(B[D]=new Set);for(const R of M.values)B[D].add(R)}}return B});const c=E=>{const B=new j1(["shape","payload","ctx"]),D=o.value,M=Z=>{const z=Fr(Z);return`shape[${z}]._zod.run({ value: input[${z}], issues: [] }, ctx)`};B.write("const input = payload.value;");const R=Object.create(null);let k=0;for(const Z of D.keys)R[Z]=`key_${k++}`;B.write("const newResult = {}");for(const Z of D.keys)if(D.optionalKeys.has(Z)){const z=R[Z];B.write(`const ${z} = ${M(Z)};`);const $=Fr(Z);B.write(`
6
- if (${z}.issues.length) {
7
- if (input[${$}] === undefined) {
8
- if (${$} in input) {
9
- newResult[${$}] = undefined;
5
+ `))}}const W1={major:4,minor:0,patch:0},ct=se("$ZodType",(t,r)=>{var o;t??(t={}),t._zod.def=r,t._zod.bag=t._zod.bag||{},t._zod.version=W1;const c=[...t._zod.def.checks??[]];t._zod.traits.has("$ZodCheck")&&c.unshift(t);for(const u of c)for(const f of u._zod.onattach)f(t);if(c.length===0)(o=t._zod).deferred??(o.deferred=[]),t._zod.deferred?.push(()=>{t._zod.run=t._zod.parse});else{const u=(f,p,x)=>{let _=Gr(f),g;for(const A of p){if(A._zod.def.when){if(!A._zod.def.when(f))continue}else if(_)continue;const E=f.issues.length,L=A._zod.check(f);if(L instanceof Promise&&x?.async===!1)throw new Yr;if(g||L instanceof Promise)g=(g??Promise.resolve()).then(async()=>{await L,f.issues.length!==E&&(_||(_=Gr(f,E)))});else{if(f.issues.length===E)continue;_||(_=Gr(f,E))}}return g?g.then(()=>f):f};t._zod.run=(f,p)=>{const x=t._zod.parse(f,p);if(x instanceof Promise){if(p.async===!1)throw new Yr;return x.then(_=>u(_,c,p))}return u(x,c,p)}}t["~standard"]={validate:u=>{try{const f=r1(t,u);return f.success?{value:f.data}:{issues:f.error?.issues}}catch{return i1(t,u).then(p=>p.success?{value:p.data}:{issues:p.error?.issues})}},vendor:"zod",version:1}}),jo=se("$ZodString",(t,r)=>{ct.init(t,r),t._zod.pattern=[...t?._zod.bag?.patterns??[]].pop()??I1(t._zod.bag),t._zod.parse=(o,c)=>{if(r.coerce)try{o.value=String(o.value)}catch{}return typeof o.value=="string"||o.issues.push({expected:"string",code:"invalid_type",input:o.value,inst:t}),o}}),yt=se("$ZodStringFormat",(t,r)=>{Ui.init(t,r),jo.init(t,r)}),G1=se("$ZodGUID",(t,r)=>{r.pattern??(r.pattern=f1),yt.init(t,r)}),X1=se("$ZodUUID",(t,r)=>{if(r.version){const c={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[r.version];if(c===void 0)throw new Error(`Invalid UUID version: "${r.version}"`);r.pattern??(r.pattern=Ws(c))}else r.pattern??(r.pattern=Ws());yt.init(t,r)}),q1=se("$ZodEmail",(t,r)=>{r.pattern??(r.pattern=h1),yt.init(t,r)}),Y1=se("$ZodURL",(t,r)=>{yt.init(t,r),t._zod.check=o=>{try{const c=o.value,u=new URL(c),f=u.href;r.hostname&&(r.hostname.lastIndex=0,r.hostname.test(u.hostname)||o.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:v1.source,input:o.value,inst:t,continue:!r.abort})),r.protocol&&(r.protocol.lastIndex=0,r.protocol.test(u.protocol.endsWith(":")?u.protocol.slice(0,-1):u.protocol)||o.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:r.protocol.source,input:o.value,inst:t,continue:!r.abort})),!c.endsWith("/")&&f.endsWith("/")?o.value=f.slice(0,-1):o.value=f;return}catch{o.issues.push({code:"invalid_format",format:"url",input:o.value,inst:t,continue:!r.abort})}}}),J1=se("$ZodEmoji",(t,r)=>{r.pattern??(r.pattern=m1()),yt.init(t,r)}),K1=se("$ZodNanoID",(t,r)=>{r.pattern??(r.pattern=u1),yt.init(t,r)}),Q1=se("$ZodCUID",(t,r)=>{r.pattern??(r.pattern=o1),yt.init(t,r)}),e0=se("$ZodCUID2",(t,r)=>{r.pattern??(r.pattern=s1),yt.init(t,r)}),t0=se("$ZodULID",(t,r)=>{r.pattern??(r.pattern=a1),yt.init(t,r)}),n0=se("$ZodXID",(t,r)=>{r.pattern??(r.pattern=l1),yt.init(t,r)}),r0=se("$ZodKSUID",(t,r)=>{r.pattern??(r.pattern=c1),yt.init(t,r)}),i0=se("$ZodISODateTime",(t,r)=>{r.pattern??(r.pattern=A1(r)),yt.init(t,r)}),o0=se("$ZodISODate",(t,r)=>{r.pattern??(r.pattern=b1),yt.init(t,r)}),s0=se("$ZodISOTime",(t,r)=>{r.pattern??(r.pattern=E1(r)),yt.init(t,r)}),a0=se("$ZodISODuration",(t,r)=>{r.pattern??(r.pattern=d1),yt.init(t,r)}),l0=se("$ZodIPv4",(t,r)=>{r.pattern??(r.pattern=g1),yt.init(t,r),t._zod.onattach.push(o=>{const c=o._zod.bag;c.format="ipv4"})}),c0=se("$ZodIPv6",(t,r)=>{r.pattern??(r.pattern=x1),yt.init(t,r),t._zod.onattach.push(o=>{const c=o._zod.bag;c.format="ipv6"}),t._zod.check=o=>{try{new URL(`http://[${o.value}]`)}catch{o.issues.push({code:"invalid_format",format:"ipv6",input:o.value,inst:t,continue:!r.abort})}}}),u0=se("$ZodCIDRv4",(t,r)=>{r.pattern??(r.pattern=y1),yt.init(t,r)}),d0=se("$ZodCIDRv6",(t,r)=>{r.pattern??(r.pattern=w1),yt.init(t,r),t._zod.check=o=>{const[c,u]=o.value.split("/");try{if(!u)throw new Error;const f=Number(u);if(`${f}`!==u)throw new Error;if(f<0||f>128)throw new Error;new URL(`http://[${c}]`)}catch{o.issues.push({code:"invalid_format",format:"cidrv6",input:o.value,inst:t,continue:!r.abort})}}});function rc(t){if(t==="")return!0;if(t.length%4!==0)return!1;try{return atob(t),!0}catch{return!1}}const f0=se("$ZodBase64",(t,r)=>{r.pattern??(r.pattern=_1),yt.init(t,r),t._zod.onattach.push(o=>{o._zod.bag.contentEncoding="base64"}),t._zod.check=o=>{rc(o.value)||o.issues.push({code:"invalid_format",format:"base64",input:o.value,inst:t,continue:!r.abort})}});function h0(t){if(!Jl.test(t))return!1;const r=t.replace(/[-_]/g,c=>c==="-"?"+":"/"),o=r.padEnd(Math.ceil(r.length/4)*4,"=");return rc(o)}const p0=se("$ZodBase64URL",(t,r)=>{r.pattern??(r.pattern=Jl),yt.init(t,r),t._zod.onattach.push(o=>{o._zod.bag.contentEncoding="base64url"}),t._zod.check=o=>{h0(o.value)||o.issues.push({code:"invalid_format",format:"base64url",input:o.value,inst:t,continue:!r.abort})}}),m0=se("$ZodE164",(t,r)=>{r.pattern??(r.pattern=C1),yt.init(t,r)});function g0(t,r=null){try{const o=t.split(".");if(o.length!==3)return!1;const[c]=o;if(!c)return!1;const u=JSON.parse(atob(c));return!("typ"in u&&u?.typ!=="JWT"||!u.alg||r&&(!("alg"in u)||u.alg!==r))}catch{return!1}}const x0=se("$ZodJWT",(t,r)=>{yt.init(t,r),t._zod.check=o=>{g0(o.value,r.alg)||o.issues.push({code:"invalid_format",format:"jwt",input:o.value,inst:t,continue:!r.abort})}}),ic=se("$ZodNumber",(t,r)=>{ct.init(t,r),t._zod.pattern=t._zod.bag.pattern??T1,t._zod.parse=(o,c)=>{if(r.coerce)try{o.value=Number(o.value)}catch{}const u=o.value;if(typeof u=="number"&&!Number.isNaN(u)&&Number.isFinite(u))return o;const f=typeof u=="number"?Number.isNaN(u)?"NaN":Number.isFinite(u)?void 0:"Infinity":void 0;return o.issues.push({expected:"number",code:"invalid_type",input:u,inst:t,...f?{received:f}:{}}),o}}),y0=se("$ZodNumber",(t,r)=>{D1.init(t,r),ic.init(t,r)}),w0=se("$ZodBoolean",(t,r)=>{ct.init(t,r),t._zod.pattern=N1,t._zod.parse=(o,c)=>{if(r.coerce)try{o.value=!!o.value}catch{}const u=o.value;return typeof u=="boolean"||o.issues.push({expected:"boolean",code:"invalid_type",input:u,inst:t}),o}}),_0=se("$ZodNull",(t,r)=>{ct.init(t,r),t._zod.pattern=O1,t._zod.values=new Set([null]),t._zod.parse=(o,c)=>{const u=o.value;return u===null||o.issues.push({expected:"null",code:"invalid_type",input:u,inst:t}),o}}),v0=se("$ZodAny",(t,r)=>{ct.init(t,r),t._zod.parse=o=>o}),C0=se("$ZodUnknown",(t,r)=>{ct.init(t,r),t._zod.parse=o=>o}),b0=se("$ZodNever",(t,r)=>{ct.init(t,r),t._zod.parse=(o,c)=>(o.issues.push({expected:"never",code:"invalid_type",input:o.value,inst:t}),o)});function Gs(t,r,o){t.issues.length&&r.issues.push(...ar(o,t.issues)),r.value[o]=t.value}const E0=se("$ZodArray",(t,r)=>{ct.init(t,r),t._zod.parse=(o,c)=>{const u=o.value;if(!Array.isArray(u))return o.issues.push({expected:"array",code:"invalid_type",input:u,inst:t}),o;o.value=Array(u.length);const f=[];for(let p=0;p<u.length;p++){const x=u[p],_=r.element._zod.run({value:x,issues:[]},c);_ instanceof Promise?f.push(_.then(g=>Gs(g,o,p))):Gs(_,o,p)}return f.length?Promise.all(f).then(()=>o):o}});function _i(t,r,o){t.issues.length&&r.issues.push(...ar(o,t.issues)),r.value[o]=t.value}function Xs(t,r,o,c){t.issues.length?c[o]===void 0?o in c?r.value[o]=void 0:r.value[o]=t.value:r.issues.push(...ar(o,t.issues)):t.value===void 0?o in c&&(r.value[o]=void 0):r.value[o]=t.value}const A0=se("$ZodObject",(t,r)=>{ct.init(t,r);const o=Uo(()=>{const E=Object.keys(r.shape);for(const M of E)if(!(r.shape[M]instanceof ct))throw new Error(`Invalid element at key "${M}": expected a Zod schema`);const L=Hd(r.shape);return{shape:r.shape,keys:E,keySet:new Set(E),numKeys:E.length,optionalKeys:new Set(L)}});Qe(t._zod,"propValues",()=>{const E=r.shape,L={};for(const M in E){const D=E[M]._zod;if(D.values){L[M]??(L[M]=new Set);for(const R of D.values)L[M].add(R)}}return L});const c=E=>{const L=new H1(["shape","payload","ctx"]),M=o.value,D=Z=>{const $=Ur(Z);return`shape[${$}]._zod.run({ value: input[${$}], issues: [] }, ctx)`};L.write("const input = payload.value;");const R=Object.create(null);let P=0;for(const Z of M.keys)R[Z]=`key_${P++}`;L.write("const newResult = {}");for(const Z of M.keys)if(M.optionalKeys.has(Z)){const $=R[Z];L.write(`const ${$} = ${D(Z)};`);const V=Ur(Z);L.write(`
6
+ if (${$}.issues.length) {
7
+ if (input[${V}] === undefined) {
8
+ if (${V} in input) {
9
+ newResult[${V}] = undefined;
10
10
  }
11
11
  } else {
12
12
  payload.issues = payload.issues.concat(
13
- ${z}.issues.map((iss) => ({
13
+ ${$}.issues.map((iss) => ({
14
14
  ...iss,
15
- path: iss.path ? [${$}, ...iss.path] : [${$}],
15
+ path: iss.path ? [${V}, ...iss.path] : [${V}],
16
16
  }))
17
17
  );
18
18
  }
19
- } else if (${z}.value === undefined) {
20
- if (${$} in input) newResult[${$}] = undefined;
19
+ } else if (${$}.value === undefined) {
20
+ if (${V} in input) newResult[${V}] = undefined;
21
21
  } else {
22
- newResult[${$}] = ${z}.value;
22
+ newResult[${V}] = ${$}.value;
23
23
  }
24
- `)}else{const z=R[Z];B.write(`const ${z} = ${M(Z)};`),B.write(`
25
- if (${z}.issues.length) payload.issues = payload.issues.concat(${z}.issues.map(iss => ({
24
+ `)}else{const $=R[Z];L.write(`const ${$} = ${D(Z)};`),L.write(`
25
+ if (${$}.issues.length) payload.issues = payload.issues.concat(${$}.issues.map(iss => ({
26
26
  ...iss,
27
- path: iss.path ? [${Fr(Z)}, ...iss.path] : [${Fr(Z)}]
28
- })));`),B.write(`newResult[${Fr(Z)}] = ${z}.value`)}B.write("payload.value = newResult;"),B.write("return payload;");const q=B.compile();return(Z,z)=>q(E,Z,z)};let u;const f=ki,p=!Vl.jitless,y=p&&$d.value,m=r.catchall;let A;t._zod.parse=(E,B)=>{A??(A=o.value);const D=E.value;if(!f(D))return E.issues.push({expected:"object",code:"invalid_type",input:D,inst:t}),E;const M=[];if(p&&y&&B?.async===!1&&B.jitless!==!0)u||(u=c(r.shape)),E=u(E,B);else{E.value={};const z=A.shape;for(const $ of A.keys){const Q=z[$],O=Q._zod.run({value:D[$],issues:[]},B),V=Q._zod.optin==="optional"&&Q._zod.optout==="optional";O instanceof Promise?M.push(O.then(le=>V?Gs(le,E,$,D):_i(le,E,$))):V?Gs(O,E,$,D):_i(O,E,$)}}if(!m)return M.length?Promise.all(M).then(()=>E):E;const R=[],k=A.keySet,q=m._zod,Z=q.def.type;for(const z of Object.keys(D)){if(k.has(z))continue;if(Z==="never"){R.push(z);continue}const $=q.run({value:D[z],issues:[]},B);$ instanceof Promise?M.push($.then(Q=>_i(Q,E,z))):_i($,E,z)}return R.length&&E.issues.push({code:"unrecognized_keys",keys:R,input:D,inst:t}),M.length?Promise.all(M).then(()=>E):E}});function Xs(t,r,o,c){for(const u of t)if(u.issues.length===0)return r.value=u.value,r;return r.issues.push({code:"invalid_union",input:r.value,inst:o,errors:t.map(u=>u.issues.map(f=>Wn(f,c,Hn())))}),r}const rc=ie("$ZodUnion",(t,r)=>{st.init(t,r),Ke(t._zod,"optin",()=>r.options.some(o=>o._zod.optin==="optional")?"optional":void 0),Ke(t._zod,"optout",()=>r.options.some(o=>o._zod.optout==="optional")?"optional":void 0),Ke(t._zod,"values",()=>{if(r.options.every(o=>o._zod.values))return new Set(r.options.flatMap(o=>Array.from(o._zod.values)))}),Ke(t._zod,"pattern",()=>{if(r.options.every(o=>o._zod.pattern)){const o=r.options.map(c=>c._zod.pattern);return new RegExp(`^(${o.map(c=>zo(c.source)).join("|")})$`)}}),t._zod.parse=(o,c)=>{let u=!1;const f=[];for(const p of r.options){const x=p._zod.run({value:o.value,issues:[]},c);if(x instanceof Promise)f.push(x),u=!0;else{if(x.issues.length===0)return x;f.push(x)}}return u?Promise.all(f).then(p=>Xs(p,o,t,c)):Xs(f,o,t,c)}}),A0=ie("$ZodDiscriminatedUnion",(t,r)=>{rc.init(t,r);const o=t._zod.parse;Ke(t._zod,"propValues",()=>{const u={};for(const f of r.options){const p=f._zod.propValues;if(!p||Object.keys(p).length===0)throw new Error(`Invalid discriminated union option at index "${r.options.indexOf(f)}"`);for(const[x,y]of Object.entries(p)){u[x]||(u[x]=new Set);for(const m of y)u[x].add(m)}}return u});const c=Fo(()=>{const u=r.options,f=new Map;for(const p of u){const x=p._zod.propValues[r.discriminator];if(!x||x.size===0)throw new Error(`Invalid discriminated union option at index "${r.options.indexOf(p)}"`);for(const y of x){if(f.has(y))throw new Error(`Duplicate discriminator value "${String(y)}"`);f.set(y,p)}}return f});t._zod.parse=(u,f)=>{const p=u.value;if(!ki(p))return u.issues.push({code:"invalid_type",expected:"object",input:p,inst:t}),u;const x=c.value.get(p?.[r.discriminator]);return x?x._zod.run(u,f):r.unionFallback?o(u,f):(u.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",input:p,path:[r.discriminator],inst:t}),u)}}),I0=ie("$ZodIntersection",(t,r)=>{st.init(t,r),t._zod.parse=(o,c)=>{const u=o.value,f=r.left._zod.run({value:u,issues:[]},c),p=r.right._zod.run({value:u,issues:[]},c);return f instanceof Promise||p instanceof Promise?Promise.all([f,p]).then(([y,m])=>qs(o,y,m)):qs(o,f,p)}});function Ao(t,r){if(t===r)return{valid:!0,data:t};if(t instanceof Date&&r instanceof Date&&+t==+r)return{valid:!0,data:t};if(Ri(t)&&Ri(r)){const o=Object.keys(r),c=Object.keys(t).filter(f=>o.indexOf(f)!==-1),u={...t,...r};for(const f of c){const p=Ao(t[f],r[f]);if(!p.valid)return{valid:!1,mergeErrorPath:[f,...p.mergeErrorPath]};u[f]=p.data}return{valid:!0,data:u}}if(Array.isArray(t)&&Array.isArray(r)){if(t.length!==r.length)return{valid:!1,mergeErrorPath:[]};const o=[];for(let c=0;c<t.length;c++){const u=t[c],f=r[c],p=Ao(u,f);if(!p.valid)return{valid:!1,mergeErrorPath:[c,...p.mergeErrorPath]};o.push(p.data)}return{valid:!0,data:o}}return{valid:!1,mergeErrorPath:[]}}function qs(t,r,o){if(r.issues.length&&t.issues.push(...r.issues),o.issues.length&&t.issues.push(...o.issues),Wr(t))return t;const c=Ao(r.value,o.value);if(!c.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`);return t.value=c.data,t}const S0=ie("$ZodRecord",(t,r)=>{st.init(t,r),t._zod.parse=(o,c)=>{const u=o.value;if(!Ri(u))return o.issues.push({expected:"record",code:"invalid_type",input:u,inst:t}),o;const f=[];if(r.keyType._zod.values){const p=r.keyType._zod.values;o.value={};for(const y of p)if(typeof y=="string"||typeof y=="number"||typeof y=="symbol"){const m=r.valueType._zod.run({value:u[y],issues:[]},c);m instanceof Promise?f.push(m.then(A=>{A.issues.length&&o.issues.push(...ir(y,A.issues)),o.value[y]=A.value})):(m.issues.length&&o.issues.push(...ir(y,m.issues)),o.value[y]=m.value)}let x;for(const y in u)p.has(y)||(x=x??[],x.push(y));x&&x.length>0&&o.issues.push({code:"unrecognized_keys",input:u,inst:t,keys:x})}else{o.value={};for(const p of Reflect.ownKeys(u)){if(p==="__proto__")continue;const x=r.keyType._zod.run({value:p,issues:[]},c);if(x instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(x.issues.length){o.issues.push({origin:"record",code:"invalid_key",issues:x.issues.map(m=>Wn(m,c,Hn())),input:p,path:[p],inst:t}),o.value[x.value]=x.value;continue}const y=r.valueType._zod.run({value:u[p],issues:[]},c);y instanceof Promise?f.push(y.then(m=>{m.issues.length&&o.issues.push(...ir(p,m.issues)),o.value[x.value]=m.value})):(y.issues.length&&o.issues.push(...ir(p,y.issues)),o.value[x.value]=y.value)}}return f.length?Promise.all(f).then(()=>o):o}}),T0=ie("$ZodEnum",(t,r)=>{st.init(t,r);const o=$l(r.entries);t._zod.values=new Set(o),t._zod.pattern=new RegExp(`^(${o.filter(c=>Zd.has(typeof c)).map(c=>typeof c=="string"?ti(c):c.toString()).join("|")})$`),t._zod.parse=(c,u)=>{const f=c.value;return t._zod.values.has(f)||c.issues.push({code:"invalid_value",values:o,input:f,inst:t}),c}}),N0=ie("$ZodLiteral",(t,r)=>{st.init(t,r),t._zod.values=new Set(r.values),t._zod.pattern=new RegExp(`^(${r.values.map(o=>typeof o=="string"?ti(o):o?o.toString():String(o)).join("|")})$`),t._zod.parse=(o,c)=>{const u=o.value;return t._zod.values.has(u)||o.issues.push({code:"invalid_value",values:r.values,input:u,inst:t}),o}}),O0=ie("$ZodTransform",(t,r)=>{st.init(t,r),t._zod.parse=(o,c)=>{const u=r.transform(o.value,o);if(c.async)return(u instanceof Promise?u:Promise.resolve(u)).then(p=>(o.value=p,o));if(u instanceof Promise)throw new qr;return o.value=u,o}}),k0=ie("$ZodOptional",(t,r)=>{st.init(t,r),t._zod.optin="optional",t._zod.optout="optional",Ke(t._zod,"values",()=>r.innerType._zod.values?new Set([...r.innerType._zod.values,void 0]):void 0),Ke(t._zod,"pattern",()=>{const o=r.innerType._zod.pattern;return o?new RegExp(`^(${zo(o.source)})?$`):void 0}),t._zod.parse=(o,c)=>r.innerType._zod.optin==="optional"?r.innerType._zod.run(o,c):o.value===void 0?o:r.innerType._zod.run(o,c)}),R0=ie("$ZodNullable",(t,r)=>{st.init(t,r),Ke(t._zod,"optin",()=>r.innerType._zod.optin),Ke(t._zod,"optout",()=>r.innerType._zod.optout),Ke(t._zod,"pattern",()=>{const o=r.innerType._zod.pattern;return o?new RegExp(`^(${zo(o.source)}|null)$`):void 0}),Ke(t._zod,"values",()=>r.innerType._zod.values?new Set([...r.innerType._zod.values,null]):void 0),t._zod.parse=(o,c)=>o.value===null?o:r.innerType._zod.run(o,c)}),M0=ie("$ZodDefault",(t,r)=>{st.init(t,r),t._zod.optin="optional",Ke(t._zod,"values",()=>r.innerType._zod.values),t._zod.parse=(o,c)=>{if(o.value===void 0)return o.value=r.defaultValue,o;const u=r.innerType._zod.run(o,c);return u instanceof Promise?u.then(f=>Ys(f,r)):Ys(u,r)}});function Ys(t,r){return t.value===void 0&&(t.value=r.defaultValue),t}const D0=ie("$ZodPrefault",(t,r)=>{st.init(t,r),t._zod.optin="optional",Ke(t._zod,"values",()=>r.innerType._zod.values),t._zod.parse=(o,c)=>(o.value===void 0&&(o.value=r.defaultValue),r.innerType._zod.run(o,c))}),P0=ie("$ZodNonOptional",(t,r)=>{st.init(t,r),Ke(t._zod,"values",()=>{const o=r.innerType._zod.values;return o?new Set([...o].filter(c=>c!==void 0)):void 0}),t._zod.parse=(o,c)=>{const u=r.innerType._zod.run(o,c);return u instanceof Promise?u.then(f=>Js(f,t)):Js(u,t)}});function Js(t,r){return!t.issues.length&&t.value===void 0&&t.issues.push({code:"invalid_type",expected:"nonoptional",input:t.value,inst:r}),t}const B0=ie("$ZodCatch",(t,r)=>{st.init(t,r),t._zod.optin="optional",Ke(t._zod,"optout",()=>r.innerType._zod.optout),Ke(t._zod,"values",()=>r.innerType._zod.values),t._zod.parse=(o,c)=>{const u=r.innerType._zod.run(o,c);return u instanceof Promise?u.then(f=>(o.value=f.value,f.issues.length&&(o.value=r.catchValue({...o,error:{issues:f.issues.map(p=>Wn(p,c,Hn()))},input:o.value}),o.issues=[]),o)):(o.value=u.value,u.issues.length&&(o.value=r.catchValue({...o,error:{issues:u.issues.map(f=>Wn(f,c,Hn()))},input:o.value}),o.issues=[]),o)}}),L0=ie("$ZodPipe",(t,r)=>{st.init(t,r),Ke(t._zod,"values",()=>r.in._zod.values),Ke(t._zod,"optin",()=>r.in._zod.optin),Ke(t._zod,"optout",()=>r.out._zod.optout),t._zod.parse=(o,c)=>{const u=r.in._zod.run(o,c);return u instanceof Promise?u.then(f=>Ks(f,r,c)):Ks(u,r,c)}});function Ks(t,r,o){return Wr(t)?t:r.out._zod.run({value:t.value,issues:t.issues},o)}const F0=ie("$ZodReadonly",(t,r)=>{st.init(t,r),Ke(t._zod,"propValues",()=>r.innerType._zod.propValues),Ke(t._zod,"values",()=>r.innerType._zod.values),Ke(t._zod,"optin",()=>r.innerType._zod.optin),Ke(t._zod,"optout",()=>r.innerType._zod.optout),t._zod.parse=(o,c)=>{const u=r.innerType._zod.run(o,c);return u instanceof Promise?u.then(Qs):Qs(u)}});function Qs(t){return t.value=Object.freeze(t.value),t}const U0=ie("$ZodLazy",(t,r)=>{st.init(t,r),Ke(t._zod,"innerType",()=>r.getter()),Ke(t._zod,"pattern",()=>t._zod.innerType._zod.pattern),Ke(t._zod,"propValues",()=>t._zod.innerType._zod.propValues),Ke(t._zod,"optin",()=>t._zod.innerType._zod.optin),Ke(t._zod,"optout",()=>t._zod.innerType._zod.optout),t._zod.parse=(o,c)=>t._zod.innerType._zod.run(o,c)}),z0=ie("$ZodCustom",(t,r)=>{Qt.init(t,r),st.init(t,r),t._zod.parse=(o,c)=>o,t._zod.check=o=>{const c=o.value,u=r.fn(c);if(u instanceof Promise)return u.then(f=>ea(f,o,c,t));ea(u,o,c,t)}});function ea(t,r,o,c){if(!t){const u={code:"custom",input:o,inst:c,path:[...c._zod.def.path??[]],continue:!c._zod.def.abort};c._zod.def.params&&(u.params=c._zod.def.params),r.issues.push(Yr(u))}}class ic{constructor(){this._map=new Map,this._idmap=new Map}add(r,...o){const c=o[0];if(this._map.set(r,c),c&&typeof c=="object"&&"id"in c){if(this._idmap.has(c.id))throw new Error(`ID ${c.id} already exists in the registry`);this._idmap.set(c.id,r)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(r){const o=this._map.get(r);return o&&typeof o=="object"&&"id"in o&&this._idmap.delete(o.id),this._map.delete(r),this}get(r){const o=r._zod.parent;if(o){const c={...this.get(o)??{}};return delete c.id,{...c,...this._map.get(r)}}return this._map.get(r)}has(r){return this._map.has(r)}}function V0(){return new ic}const Zr=V0();function $0(t,r){return new t({type:"string",...Ae(r)})}function Z0(t,r){return new t({type:"string",format:"email",check:"string_format",abort:!1,...Ae(r)})}function ta(t,r){return new t({type:"string",format:"guid",check:"string_format",abort:!1,...Ae(r)})}function j0(t,r){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,...Ae(r)})}function H0(t,r){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...Ae(r)})}function W0(t,r){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...Ae(r)})}function G0(t,r){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...Ae(r)})}function X0(t,r){return new t({type:"string",format:"url",check:"string_format",abort:!1,...Ae(r)})}function q0(t,r){return new t({type:"string",format:"emoji",check:"string_format",abort:!1,...Ae(r)})}function Y0(t,r){return new t({type:"string",format:"nanoid",check:"string_format",abort:!1,...Ae(r)})}function J0(t,r){return new t({type:"string",format:"cuid",check:"string_format",abort:!1,...Ae(r)})}function K0(t,r){return new t({type:"string",format:"cuid2",check:"string_format",abort:!1,...Ae(r)})}function Q0(t,r){return new t({type:"string",format:"ulid",check:"string_format",abort:!1,...Ae(r)})}function ef(t,r){return new t({type:"string",format:"xid",check:"string_format",abort:!1,...Ae(r)})}function tf(t,r){return new t({type:"string",format:"ksuid",check:"string_format",abort:!1,...Ae(r)})}function nf(t,r){return new t({type:"string",format:"ipv4",check:"string_format",abort:!1,...Ae(r)})}function rf(t,r){return new t({type:"string",format:"ipv6",check:"string_format",abort:!1,...Ae(r)})}function of(t,r){return new t({type:"string",format:"cidrv4",check:"string_format",abort:!1,...Ae(r)})}function sf(t,r){return new t({type:"string",format:"cidrv6",check:"string_format",abort:!1,...Ae(r)})}function af(t,r){return new t({type:"string",format:"base64",check:"string_format",abort:!1,...Ae(r)})}function lf(t,r){return new t({type:"string",format:"base64url",check:"string_format",abort:!1,...Ae(r)})}function cf(t,r){return new t({type:"string",format:"e164",check:"string_format",abort:!1,...Ae(r)})}function uf(t,r){return new t({type:"string",format:"jwt",check:"string_format",abort:!1,...Ae(r)})}function df(t,r){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...Ae(r)})}function ff(t,r){return new t({type:"string",format:"date",check:"string_format",...Ae(r)})}function hf(t,r){return new t({type:"string",format:"time",check:"string_format",precision:null,...Ae(r)})}function pf(t,r){return new t({type:"string",format:"duration",check:"string_format",...Ae(r)})}function gf(t,r){return new t({type:"number",checks:[],...Ae(r)})}function mf(t,r){return new t({type:"number",coerce:!0,checks:[],...Ae(r)})}function xf(t,r){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",...Ae(r)})}function wf(t,r){return new t({type:"boolean",...Ae(r)})}function yf(t,r){return new t({type:"null",...Ae(r)})}function _f(t){return new t({type:"any"})}function vf(t){return new t({type:"unknown"})}function Cf(t,r){return new t({type:"never",...Ae(r)})}function na(t,r){return new Ql({check:"less_than",...Ae(r),value:t,inclusive:!1})}function fo(t,r){return new Ql({check:"less_than",...Ae(r),value:t,inclusive:!0})}function ra(t,r){return new ec({check:"greater_than",...Ae(r),value:t,inclusive:!1})}function ho(t,r){return new ec({check:"greater_than",...Ae(r),value:t,inclusive:!0})}function ia(t,r){return new R1({check:"multiple_of",...Ae(r),value:t})}function oc(t,r){return new D1({check:"max_length",...Ae(r),maximum:t})}function Mi(t,r){return new P1({check:"min_length",...Ae(r),minimum:t})}function sc(t,r){return new B1({check:"length_equals",...Ae(r),length:t})}function bf(t,r){return new L1({check:"string_format",format:"regex",...Ae(r),pattern:t})}function Ef(t){return new F1({check:"string_format",format:"lowercase",...Ae(t)})}function Af(t){return new U1({check:"string_format",format:"uppercase",...Ae(t)})}function If(t,r){return new z1({check:"string_format",format:"includes",...Ae(r),includes:t})}function Sf(t,r){return new V1({check:"string_format",format:"starts_with",...Ae(r),prefix:t})}function Tf(t,r){return new $1({check:"string_format",format:"ends_with",...Ae(r),suffix:t})}function ni(t){return new Z1({check:"overwrite",tx:t})}function Nf(t){return ni(r=>r.normalize(t))}function Of(){return ni(t=>t.trim())}function kf(){return ni(t=>t.toLowerCase())}function Rf(){return ni(t=>t.toUpperCase())}function Mf(t,r,o){return new t({type:"array",element:r,...Ae(o)})}function Df(t,r,o){const c=Ae(o);return c.abort??(c.abort=!0),new t({type:"custom",check:"custom",fn:r,...c})}function Pf(t,r,o){return new t({type:"custom",check:"custom",fn:r,...Ae(o)})}class oa{constructor(r){this.counter=0,this.metadataRegistry=r?.metadata??Zr,this.target=r?.target??"draft-2020-12",this.unrepresentable=r?.unrepresentable??"throw",this.override=r?.override??(()=>{}),this.io=r?.io??"output",this.seen=new Map}process(r,o={path:[],schemaPath:[]}){var c;const u=r._zod.def,f={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},p=this.seen.get(r);if(p)return p.count++,o.schemaPath.includes(r)&&(p.cycle=o.path),p.schema;const x={schema:{},count:1,cycle:void 0,path:o.path};this.seen.set(r,x);const y=r._zod.toJSONSchema?.();if(y)x.schema=y;else{const E={...o,schemaPath:[...o.schemaPath,r],path:o.path},B=r._zod.parent;if(B)x.ref=B,this.process(B,E),this.seen.get(B).isParent=!0;else{const D=x.schema;switch(u.type){case"string":{const M=D;M.type="string";const{minimum:R,maximum:k,format:q,patterns:Z,contentEncoding:z}=r._zod.bag;if(typeof R=="number"&&(M.minLength=R),typeof k=="number"&&(M.maxLength=k),q&&(M.format=f[q]??q,M.format===""&&delete M.format),z&&(M.contentEncoding=z),Z&&Z.size>0){const $=[...Z];$.length===1?M.pattern=$[0].source:$.length>1&&(x.schema.allOf=[...$.map(Q=>({...this.target==="draft-7"?{type:"string"}:{},pattern:Q.source}))])}break}case"number":{const M=D,{minimum:R,maximum:k,format:q,multipleOf:Z,exclusiveMaximum:z,exclusiveMinimum:$}=r._zod.bag;typeof q=="string"&&q.includes("int")?M.type="integer":M.type="number",typeof $=="number"&&(M.exclusiveMinimum=$),typeof R=="number"&&(M.minimum=R,typeof $=="number"&&($>=R?delete M.minimum:delete M.exclusiveMinimum)),typeof z=="number"&&(M.exclusiveMaximum=z),typeof k=="number"&&(M.maximum=k,typeof z=="number"&&(z<=k?delete M.maximum:delete M.exclusiveMaximum)),typeof Z=="number"&&(M.multipleOf=Z);break}case"boolean":{const M=D;M.type="boolean";break}case"bigint":{if(this.unrepresentable==="throw")throw new Error("BigInt cannot be represented in JSON Schema");break}case"symbol":{if(this.unrepresentable==="throw")throw new Error("Symbols cannot be represented in JSON Schema");break}case"null":{D.type="null";break}case"any":break;case"unknown":break;case"undefined":{if(this.unrepresentable==="throw")throw new Error("Undefined cannot be represented in JSON Schema");break}case"void":{if(this.unrepresentable==="throw")throw new Error("Void cannot be represented in JSON Schema");break}case"never":{D.not={};break}case"date":{if(this.unrepresentable==="throw")throw new Error("Date cannot be represented in JSON Schema");break}case"array":{const M=D,{minimum:R,maximum:k}=r._zod.bag;typeof R=="number"&&(M.minItems=R),typeof k=="number"&&(M.maxItems=k),M.type="array",M.items=this.process(u.element,{...E,path:[...E.path,"items"]});break}case"object":{const M=D;M.type="object",M.properties={};const R=u.shape;for(const Z in R)M.properties[Z]=this.process(R[Z],{...E,path:[...E.path,"properties",Z]});const k=new Set(Object.keys(R)),q=new Set([...k].filter(Z=>{const z=u.shape[Z]._zod;return this.io==="input"?z.optin===void 0:z.optout===void 0}));q.size>0&&(M.required=Array.from(q)),u.catchall?._zod.def.type==="never"?M.additionalProperties=!1:u.catchall?u.catchall&&(M.additionalProperties=this.process(u.catchall,{...E,path:[...E.path,"additionalProperties"]})):this.io==="output"&&(M.additionalProperties=!1);break}case"union":{const M=D;M.anyOf=u.options.map((R,k)=>this.process(R,{...E,path:[...E.path,"anyOf",k]}));break}case"intersection":{const M=D,R=this.process(u.left,{...E,path:[...E.path,"allOf",0]}),k=this.process(u.right,{...E,path:[...E.path,"allOf",1]}),q=z=>"allOf"in z&&Object.keys(z).length===1,Z=[...q(R)?R.allOf:[R],...q(k)?k.allOf:[k]];M.allOf=Z;break}case"tuple":{const M=D;M.type="array";const R=u.items.map((Z,z)=>this.process(Z,{...E,path:[...E.path,"prefixItems",z]}));if(this.target==="draft-2020-12"?M.prefixItems=R:M.items=R,u.rest){const Z=this.process(u.rest,{...E,path:[...E.path,"items"]});this.target==="draft-2020-12"?M.items=Z:M.additionalItems=Z}u.rest&&(M.items=this.process(u.rest,{...E,path:[...E.path,"items"]}));const{minimum:k,maximum:q}=r._zod.bag;typeof k=="number"&&(M.minItems=k),typeof q=="number"&&(M.maxItems=q);break}case"record":{const M=D;M.type="object",M.propertyNames=this.process(u.keyType,{...E,path:[...E.path,"propertyNames"]}),M.additionalProperties=this.process(u.valueType,{...E,path:[...E.path,"additionalProperties"]});break}case"map":{if(this.unrepresentable==="throw")throw new Error("Map cannot be represented in JSON Schema");break}case"set":{if(this.unrepresentable==="throw")throw new Error("Set cannot be represented in JSON Schema");break}case"enum":{const M=D,R=$l(u.entries);R.every(k=>typeof k=="number")&&(M.type="number"),R.every(k=>typeof k=="string")&&(M.type="string"),M.enum=R;break}case"literal":{const M=D,R=[];for(const k of u.values)if(k===void 0){if(this.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof k=="bigint"){if(this.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");R.push(Number(k))}else R.push(k);if(R.length!==0)if(R.length===1){const k=R[0];M.type=k===null?"null":typeof k,M.const=k}else R.every(k=>typeof k=="number")&&(M.type="number"),R.every(k=>typeof k=="string")&&(M.type="string"),R.every(k=>typeof k=="boolean")&&(M.type="string"),R.every(k=>k===null)&&(M.type="null"),M.enum=R;break}case"file":{const M=D,R={type:"string",format:"binary",contentEncoding:"binary"},{minimum:k,maximum:q,mime:Z}=r._zod.bag;k!==void 0&&(R.minLength=k),q!==void 0&&(R.maxLength=q),Z?Z.length===1?(R.contentMediaType=Z[0],Object.assign(M,R)):M.anyOf=Z.map(z=>({...R,contentMediaType:z})):Object.assign(M,R);break}case"transform":{if(this.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema");break}case"nullable":{const M=this.process(u.innerType,E);D.anyOf=[M,{type:"null"}];break}case"nonoptional":{this.process(u.innerType,E),x.ref=u.innerType;break}case"success":{const M=D;M.type="boolean";break}case"default":{this.process(u.innerType,E),x.ref=u.innerType,D.default=JSON.parse(JSON.stringify(u.defaultValue));break}case"prefault":{this.process(u.innerType,E),x.ref=u.innerType,this.io==="input"&&(D._prefault=JSON.parse(JSON.stringify(u.defaultValue)));break}case"catch":{this.process(u.innerType,E),x.ref=u.innerType;let M;try{M=u.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}D.default=M;break}case"nan":{if(this.unrepresentable==="throw")throw new Error("NaN cannot be represented in JSON Schema");break}case"template_literal":{const M=D,R=r._zod.pattern;if(!R)throw new Error("Pattern not found in template literal");M.type="string",M.pattern=R.source;break}case"pipe":{const M=this.io==="input"?u.in._zod.def.type==="transform"?u.out:u.in:u.out;this.process(M,E),x.ref=M;break}case"readonly":{this.process(u.innerType,E),x.ref=u.innerType,D.readOnly=!0;break}case"promise":{this.process(u.innerType,E),x.ref=u.innerType;break}case"optional":{this.process(u.innerType,E),x.ref=u.innerType;break}case"lazy":{const M=r._zod.innerType;this.process(M,E),x.ref=M;break}case"custom":{if(this.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema");break}}}}const m=this.metadataRegistry.get(r);return m&&Object.assign(x.schema,m),this.io==="input"&&Rt(r)&&(delete x.schema.examples,delete x.schema.default),this.io==="input"&&x.schema._prefault&&((c=x.schema).default??(c.default=x.schema._prefault)),delete x.schema._prefault,this.seen.get(r).schema}emit(r,o){const c={cycles:o?.cycles??"ref",reused:o?.reused??"inline",external:o?.external??void 0},u=this.seen.get(r);if(!u)throw new Error("Unprocessed schema. This is a bug in Zod.");const f=A=>{const E=this.target==="draft-2020-12"?"$defs":"definitions";if(c.external){const R=c.external.registry.get(A[0])?.id,k=c.external.uri??(Z=>Z);if(R)return{ref:k(R)};const q=A[1].defId??A[1].schema.id??`schema${this.counter++}`;return A[1].defId=q,{defId:q,ref:`${k("__shared")}#/${E}/${q}`}}if(A[1]===u)return{ref:"#"};const D=`#/${E}/`,M=A[1].schema.id??`__schema${this.counter++}`;return{defId:M,ref:D+M}},p=A=>{if(A[1].schema.$ref)return;const E=A[1],{ref:B,defId:D}=f(A);E.def={...E.schema},D&&(E.defId=D);const M=E.schema;for(const R in M)delete M[R];M.$ref=B};if(c.cycles==="throw")for(const A of this.seen.entries()){const E=A[1];if(E.cycle)throw new Error(`Cycle detected: #/${E.cycle?.join("/")}/<root>
27
+ path: iss.path ? [${Ur(Z)}, ...iss.path] : [${Ur(Z)}]
28
+ })));`),L.write(`newResult[${Ur(Z)}] = ${$}.value`)}L.write("payload.value = newResult;"),L.write("return payload;");const H=L.compile();return(Z,$)=>H(E,Z,$)};let u;const f=ki,p=!Zl.jitless,_=p&&Zd.value,g=r.catchall;let A;t._zod.parse=(E,L)=>{A??(A=o.value);const M=E.value;if(!f(M))return E.issues.push({expected:"object",code:"invalid_type",input:M,inst:t}),E;const D=[];if(p&&_&&L?.async===!1&&L.jitless!==!0)u||(u=c(r.shape)),E=u(E,L);else{E.value={};const $=A.shape;for(const V of A.keys){const ee=$[V],j=ee._zod.run({value:M[V],issues:[]},L),z=ee._zod.optin==="optional"&&ee._zod.optout==="optional";j instanceof Promise?D.push(j.then(q=>z?Xs(q,E,V,M):_i(q,E,V))):z?Xs(j,E,V,M):_i(j,E,V)}}if(!g)return D.length?Promise.all(D).then(()=>E):E;const R=[],P=A.keySet,H=g._zod,Z=H.def.type;for(const $ of Object.keys(M)){if(P.has($))continue;if(Z==="never"){R.push($);continue}const V=H.run({value:M[$],issues:[]},L);V instanceof Promise?D.push(V.then(ee=>_i(ee,E,$))):_i(V,E,$)}return R.length&&E.issues.push({code:"unrecognized_keys",keys:R,input:M,inst:t}),D.length?Promise.all(D).then(()=>E):E}});function qs(t,r,o,c){for(const u of t)if(u.issues.length===0)return r.value=u.value,r;return r.issues.push({code:"invalid_union",input:r.value,inst:o,errors:t.map(u=>u.issues.map(f=>qn(f,c,Xn())))}),r}const oc=se("$ZodUnion",(t,r)=>{ct.init(t,r),Qe(t._zod,"optin",()=>r.options.some(o=>o._zod.optin==="optional")?"optional":void 0),Qe(t._zod,"optout",()=>r.options.some(o=>o._zod.optout==="optional")?"optional":void 0),Qe(t._zod,"values",()=>{if(r.options.every(o=>o._zod.values))return new Set(r.options.flatMap(o=>Array.from(o._zod.values)))}),Qe(t._zod,"pattern",()=>{if(r.options.every(o=>o._zod.pattern)){const o=r.options.map(c=>c._zod.pattern);return new RegExp(`^(${o.map(c=>Vo(c.source)).join("|")})$`)}}),t._zod.parse=(o,c)=>{let u=!1;const f=[];for(const p of r.options){const x=p._zod.run({value:o.value,issues:[]},c);if(x instanceof Promise)f.push(x),u=!0;else{if(x.issues.length===0)return x;f.push(x)}}return u?Promise.all(f).then(p=>qs(p,o,t,c)):qs(f,o,t,c)}}),I0=se("$ZodDiscriminatedUnion",(t,r)=>{oc.init(t,r);const o=t._zod.parse;Qe(t._zod,"propValues",()=>{const u={};for(const f of r.options){const p=f._zod.propValues;if(!p||Object.keys(p).length===0)throw new Error(`Invalid discriminated union option at index "${r.options.indexOf(f)}"`);for(const[x,_]of Object.entries(p)){u[x]||(u[x]=new Set);for(const g of _)u[x].add(g)}}return u});const c=Uo(()=>{const u=r.options,f=new Map;for(const p of u){const x=p._zod.propValues[r.discriminator];if(!x||x.size===0)throw new Error(`Invalid discriminated union option at index "${r.options.indexOf(p)}"`);for(const _ of x){if(f.has(_))throw new Error(`Duplicate discriminator value "${String(_)}"`);f.set(_,p)}}return f});t._zod.parse=(u,f)=>{const p=u.value;if(!ki(p))return u.issues.push({code:"invalid_type",expected:"object",input:p,inst:t}),u;const x=c.value.get(p?.[r.discriminator]);return x?x._zod.run(u,f):r.unionFallback?o(u,f):(u.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",input:p,path:[r.discriminator],inst:t}),u)}}),S0=se("$ZodIntersection",(t,r)=>{ct.init(t,r),t._zod.parse=(o,c)=>{const u=o.value,f=r.left._zod.run({value:u,issues:[]},c),p=r.right._zod.run({value:u,issues:[]},c);return f instanceof Promise||p instanceof Promise?Promise.all([f,p]).then(([_,g])=>Ys(o,_,g)):Ys(o,f,p)}});function Ao(t,r){if(t===r)return{valid:!0,data:t};if(t instanceof Date&&r instanceof Date&&+t==+r)return{valid:!0,data:t};if(Ri(t)&&Ri(r)){const o=Object.keys(r),c=Object.keys(t).filter(f=>o.indexOf(f)!==-1),u={...t,...r};for(const f of c){const p=Ao(t[f],r[f]);if(!p.valid)return{valid:!1,mergeErrorPath:[f,...p.mergeErrorPath]};u[f]=p.data}return{valid:!0,data:u}}if(Array.isArray(t)&&Array.isArray(r)){if(t.length!==r.length)return{valid:!1,mergeErrorPath:[]};const o=[];for(let c=0;c<t.length;c++){const u=t[c],f=r[c],p=Ao(u,f);if(!p.valid)return{valid:!1,mergeErrorPath:[c,...p.mergeErrorPath]};o.push(p.data)}return{valid:!0,data:o}}return{valid:!1,mergeErrorPath:[]}}function Ys(t,r,o){if(r.issues.length&&t.issues.push(...r.issues),o.issues.length&&t.issues.push(...o.issues),Gr(t))return t;const c=Ao(r.value,o.value);if(!c.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`);return t.value=c.data,t}const T0=se("$ZodRecord",(t,r)=>{ct.init(t,r),t._zod.parse=(o,c)=>{const u=o.value;if(!Ri(u))return o.issues.push({expected:"record",code:"invalid_type",input:u,inst:t}),o;const f=[];if(r.keyType._zod.values){const p=r.keyType._zod.values;o.value={};for(const _ of p)if(typeof _=="string"||typeof _=="number"||typeof _=="symbol"){const g=r.valueType._zod.run({value:u[_],issues:[]},c);g instanceof Promise?f.push(g.then(A=>{A.issues.length&&o.issues.push(...ar(_,A.issues)),o.value[_]=A.value})):(g.issues.length&&o.issues.push(...ar(_,g.issues)),o.value[_]=g.value)}let x;for(const _ in u)p.has(_)||(x=x??[],x.push(_));x&&x.length>0&&o.issues.push({code:"unrecognized_keys",input:u,inst:t,keys:x})}else{o.value={};for(const p of Reflect.ownKeys(u)){if(p==="__proto__")continue;const x=r.keyType._zod.run({value:p,issues:[]},c);if(x instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(x.issues.length){o.issues.push({origin:"record",code:"invalid_key",issues:x.issues.map(g=>qn(g,c,Xn())),input:p,path:[p],inst:t}),o.value[x.value]=x.value;continue}const _=r.valueType._zod.run({value:u[p],issues:[]},c);_ instanceof Promise?f.push(_.then(g=>{g.issues.length&&o.issues.push(...ar(p,g.issues)),o.value[x.value]=g.value})):(_.issues.length&&o.issues.push(...ar(p,_.issues)),o.value[x.value]=_.value)}}return f.length?Promise.all(f).then(()=>o):o}}),N0=se("$ZodEnum",(t,r)=>{ct.init(t,r);const o=jl(r.entries);t._zod.values=new Set(o),t._zod.pattern=new RegExp(`^(${o.filter(c=>jd.has(typeof c)).map(c=>typeof c=="string"?ni(c):c.toString()).join("|")})$`),t._zod.parse=(c,u)=>{const f=c.value;return t._zod.values.has(f)||c.issues.push({code:"invalid_value",values:o,input:f,inst:t}),c}}),O0=se("$ZodLiteral",(t,r)=>{ct.init(t,r),t._zod.values=new Set(r.values),t._zod.pattern=new RegExp(`^(${r.values.map(o=>typeof o=="string"?ni(o):o?o.toString():String(o)).join("|")})$`),t._zod.parse=(o,c)=>{const u=o.value;return t._zod.values.has(u)||o.issues.push({code:"invalid_value",values:r.values,input:u,inst:t}),o}}),k0=se("$ZodTransform",(t,r)=>{ct.init(t,r),t._zod.parse=(o,c)=>{const u=r.transform(o.value,o);if(c.async)return(u instanceof Promise?u:Promise.resolve(u)).then(p=>(o.value=p,o));if(u instanceof Promise)throw new Yr;return o.value=u,o}}),R0=se("$ZodOptional",(t,r)=>{ct.init(t,r),t._zod.optin="optional",t._zod.optout="optional",Qe(t._zod,"values",()=>r.innerType._zod.values?new Set([...r.innerType._zod.values,void 0]):void 0),Qe(t._zod,"pattern",()=>{const o=r.innerType._zod.pattern;return o?new RegExp(`^(${Vo(o.source)})?$`):void 0}),t._zod.parse=(o,c)=>r.innerType._zod.optin==="optional"?r.innerType._zod.run(o,c):o.value===void 0?o:r.innerType._zod.run(o,c)}),M0=se("$ZodNullable",(t,r)=>{ct.init(t,r),Qe(t._zod,"optin",()=>r.innerType._zod.optin),Qe(t._zod,"optout",()=>r.innerType._zod.optout),Qe(t._zod,"pattern",()=>{const o=r.innerType._zod.pattern;return o?new RegExp(`^(${Vo(o.source)}|null)$`):void 0}),Qe(t._zod,"values",()=>r.innerType._zod.values?new Set([...r.innerType._zod.values,null]):void 0),t._zod.parse=(o,c)=>o.value===null?o:r.innerType._zod.run(o,c)}),D0=se("$ZodDefault",(t,r)=>{ct.init(t,r),t._zod.optin="optional",Qe(t._zod,"values",()=>r.innerType._zod.values),t._zod.parse=(o,c)=>{if(o.value===void 0)return o.value=r.defaultValue,o;const u=r.innerType._zod.run(o,c);return u instanceof Promise?u.then(f=>Js(f,r)):Js(u,r)}});function Js(t,r){return t.value===void 0&&(t.value=r.defaultValue),t}const P0=se("$ZodPrefault",(t,r)=>{ct.init(t,r),t._zod.optin="optional",Qe(t._zod,"values",()=>r.innerType._zod.values),t._zod.parse=(o,c)=>(o.value===void 0&&(o.value=r.defaultValue),r.innerType._zod.run(o,c))}),B0=se("$ZodNonOptional",(t,r)=>{ct.init(t,r),Qe(t._zod,"values",()=>{const o=r.innerType._zod.values;return o?new Set([...o].filter(c=>c!==void 0)):void 0}),t._zod.parse=(o,c)=>{const u=r.innerType._zod.run(o,c);return u instanceof Promise?u.then(f=>Ks(f,t)):Ks(u,t)}});function Ks(t,r){return!t.issues.length&&t.value===void 0&&t.issues.push({code:"invalid_type",expected:"nonoptional",input:t.value,inst:r}),t}const L0=se("$ZodCatch",(t,r)=>{ct.init(t,r),t._zod.optin="optional",Qe(t._zod,"optout",()=>r.innerType._zod.optout),Qe(t._zod,"values",()=>r.innerType._zod.values),t._zod.parse=(o,c)=>{const u=r.innerType._zod.run(o,c);return u instanceof Promise?u.then(f=>(o.value=f.value,f.issues.length&&(o.value=r.catchValue({...o,error:{issues:f.issues.map(p=>qn(p,c,Xn()))},input:o.value}),o.issues=[]),o)):(o.value=u.value,u.issues.length&&(o.value=r.catchValue({...o,error:{issues:u.issues.map(f=>qn(f,c,Xn()))},input:o.value}),o.issues=[]),o)}}),F0=se("$ZodPipe",(t,r)=>{ct.init(t,r),Qe(t._zod,"values",()=>r.in._zod.values),Qe(t._zod,"optin",()=>r.in._zod.optin),Qe(t._zod,"optout",()=>r.out._zod.optout),t._zod.parse=(o,c)=>{const u=r.in._zod.run(o,c);return u instanceof Promise?u.then(f=>Qs(f,r,c)):Qs(u,r,c)}});function Qs(t,r,o){return Gr(t)?t:r.out._zod.run({value:t.value,issues:t.issues},o)}const U0=se("$ZodReadonly",(t,r)=>{ct.init(t,r),Qe(t._zod,"propValues",()=>r.innerType._zod.propValues),Qe(t._zod,"values",()=>r.innerType._zod.values),Qe(t._zod,"optin",()=>r.innerType._zod.optin),Qe(t._zod,"optout",()=>r.innerType._zod.optout),t._zod.parse=(o,c)=>{const u=r.innerType._zod.run(o,c);return u instanceof Promise?u.then(ea):ea(u)}});function ea(t){return t.value=Object.freeze(t.value),t}const z0=se("$ZodLazy",(t,r)=>{ct.init(t,r),Qe(t._zod,"innerType",()=>r.getter()),Qe(t._zod,"pattern",()=>t._zod.innerType._zod.pattern),Qe(t._zod,"propValues",()=>t._zod.innerType._zod.propValues),Qe(t._zod,"optin",()=>t._zod.innerType._zod.optin),Qe(t._zod,"optout",()=>t._zod.innerType._zod.optout),t._zod.parse=(o,c)=>t._zod.innerType._zod.run(o,c)}),V0=se("$ZodCustom",(t,r)=>{nn.init(t,r),ct.init(t,r),t._zod.parse=(o,c)=>o,t._zod.check=o=>{const c=o.value,u=r.fn(c);if(u instanceof Promise)return u.then(f=>ta(f,o,c,t));ta(u,o,c,t)}});function ta(t,r,o,c){if(!t){const u={code:"custom",input:o,inst:c,path:[...c._zod.def.path??[]],continue:!c._zod.def.abort};c._zod.def.params&&(u.params=c._zod.def.params),r.issues.push(Jr(u))}}class sc{constructor(){this._map=new Map,this._idmap=new Map}add(r,...o){const c=o[0];if(this._map.set(r,c),c&&typeof c=="object"&&"id"in c){if(this._idmap.has(c.id))throw new Error(`ID ${c.id} already exists in the registry`);this._idmap.set(c.id,r)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(r){const o=this._map.get(r);return o&&typeof o=="object"&&"id"in o&&this._idmap.delete(o.id),this._map.delete(r),this}get(r){const o=r._zod.parent;if(o){const c={...this.get(o)??{}};return delete c.id,{...c,...this._map.get(r)}}return this._map.get(r)}has(r){return this._map.has(r)}}function $0(){return new sc}const jr=$0();function Z0(t,r){return new t({type:"string",...be(r)})}function j0(t,r){return new t({type:"string",format:"email",check:"string_format",abort:!1,...be(r)})}function na(t,r){return new t({type:"string",format:"guid",check:"string_format",abort:!1,...be(r)})}function H0(t,r){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,...be(r)})}function W0(t,r){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...be(r)})}function G0(t,r){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...be(r)})}function X0(t,r){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...be(r)})}function q0(t,r){return new t({type:"string",format:"url",check:"string_format",abort:!1,...be(r)})}function Y0(t,r){return new t({type:"string",format:"emoji",check:"string_format",abort:!1,...be(r)})}function J0(t,r){return new t({type:"string",format:"nanoid",check:"string_format",abort:!1,...be(r)})}function K0(t,r){return new t({type:"string",format:"cuid",check:"string_format",abort:!1,...be(r)})}function Q0(t,r){return new t({type:"string",format:"cuid2",check:"string_format",abort:!1,...be(r)})}function ef(t,r){return new t({type:"string",format:"ulid",check:"string_format",abort:!1,...be(r)})}function tf(t,r){return new t({type:"string",format:"xid",check:"string_format",abort:!1,...be(r)})}function nf(t,r){return new t({type:"string",format:"ksuid",check:"string_format",abort:!1,...be(r)})}function rf(t,r){return new t({type:"string",format:"ipv4",check:"string_format",abort:!1,...be(r)})}function of(t,r){return new t({type:"string",format:"ipv6",check:"string_format",abort:!1,...be(r)})}function sf(t,r){return new t({type:"string",format:"cidrv4",check:"string_format",abort:!1,...be(r)})}function af(t,r){return new t({type:"string",format:"cidrv6",check:"string_format",abort:!1,...be(r)})}function lf(t,r){return new t({type:"string",format:"base64",check:"string_format",abort:!1,...be(r)})}function cf(t,r){return new t({type:"string",format:"base64url",check:"string_format",abort:!1,...be(r)})}function uf(t,r){return new t({type:"string",format:"e164",check:"string_format",abort:!1,...be(r)})}function df(t,r){return new t({type:"string",format:"jwt",check:"string_format",abort:!1,...be(r)})}function ff(t,r){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...be(r)})}function hf(t,r){return new t({type:"string",format:"date",check:"string_format",...be(r)})}function pf(t,r){return new t({type:"string",format:"time",check:"string_format",precision:null,...be(r)})}function mf(t,r){return new t({type:"string",format:"duration",check:"string_format",...be(r)})}function gf(t,r){return new t({type:"number",checks:[],...be(r)})}function xf(t,r){return new t({type:"number",coerce:!0,checks:[],...be(r)})}function yf(t,r){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",...be(r)})}function wf(t,r){return new t({type:"boolean",...be(r)})}function _f(t,r){return new t({type:"null",...be(r)})}function vf(t){return new t({type:"any"})}function Cf(t){return new t({type:"unknown"})}function bf(t,r){return new t({type:"never",...be(r)})}function ra(t,r){return new tc({check:"less_than",...be(r),value:t,inclusive:!1})}function fo(t,r){return new tc({check:"less_than",...be(r),value:t,inclusive:!0})}function ia(t,r){return new nc({check:"greater_than",...be(r),value:t,inclusive:!1})}function ho(t,r){return new nc({check:"greater_than",...be(r),value:t,inclusive:!0})}function oa(t,r){return new M1({check:"multiple_of",...be(r),value:t})}function ac(t,r){return new P1({check:"max_length",...be(r),maximum:t})}function Mi(t,r){return new B1({check:"min_length",...be(r),minimum:t})}function lc(t,r){return new L1({check:"length_equals",...be(r),length:t})}function Ef(t,r){return new F1({check:"string_format",format:"regex",...be(r),pattern:t})}function Af(t){return new U1({check:"string_format",format:"lowercase",...be(t)})}function If(t){return new z1({check:"string_format",format:"uppercase",...be(t)})}function Sf(t,r){return new V1({check:"string_format",format:"includes",...be(r),includes:t})}function Tf(t,r){return new $1({check:"string_format",format:"starts_with",...be(r),prefix:t})}function Nf(t,r){return new Z1({check:"string_format",format:"ends_with",...be(r),suffix:t})}function ri(t){return new j1({check:"overwrite",tx:t})}function Of(t){return ri(r=>r.normalize(t))}function kf(){return ri(t=>t.trim())}function Rf(){return ri(t=>t.toLowerCase())}function Mf(){return ri(t=>t.toUpperCase())}function Df(t,r,o){return new t({type:"array",element:r,...be(o)})}function Pf(t,r,o){const c=be(o);return c.abort??(c.abort=!0),new t({type:"custom",check:"custom",fn:r,...c})}function Bf(t,r,o){return new t({type:"custom",check:"custom",fn:r,...be(o)})}class sa{constructor(r){this.counter=0,this.metadataRegistry=r?.metadata??jr,this.target=r?.target??"draft-2020-12",this.unrepresentable=r?.unrepresentable??"throw",this.override=r?.override??(()=>{}),this.io=r?.io??"output",this.seen=new Map}process(r,o={path:[],schemaPath:[]}){var c;const u=r._zod.def,f={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},p=this.seen.get(r);if(p)return p.count++,o.schemaPath.includes(r)&&(p.cycle=o.path),p.schema;const x={schema:{},count:1,cycle:void 0,path:o.path};this.seen.set(r,x);const _=r._zod.toJSONSchema?.();if(_)x.schema=_;else{const E={...o,schemaPath:[...o.schemaPath,r],path:o.path},L=r._zod.parent;if(L)x.ref=L,this.process(L,E),this.seen.get(L).isParent=!0;else{const M=x.schema;switch(u.type){case"string":{const D=M;D.type="string";const{minimum:R,maximum:P,format:H,patterns:Z,contentEncoding:$}=r._zod.bag;if(typeof R=="number"&&(D.minLength=R),typeof P=="number"&&(D.maxLength=P),H&&(D.format=f[H]??H,D.format===""&&delete D.format),$&&(D.contentEncoding=$),Z&&Z.size>0){const V=[...Z];V.length===1?D.pattern=V[0].source:V.length>1&&(x.schema.allOf=[...V.map(ee=>({...this.target==="draft-7"?{type:"string"}:{},pattern:ee.source}))])}break}case"number":{const D=M,{minimum:R,maximum:P,format:H,multipleOf:Z,exclusiveMaximum:$,exclusiveMinimum:V}=r._zod.bag;typeof H=="string"&&H.includes("int")?D.type="integer":D.type="number",typeof V=="number"&&(D.exclusiveMinimum=V),typeof R=="number"&&(D.minimum=R,typeof V=="number"&&(V>=R?delete D.minimum:delete D.exclusiveMinimum)),typeof $=="number"&&(D.exclusiveMaximum=$),typeof P=="number"&&(D.maximum=P,typeof $=="number"&&($<=P?delete D.maximum:delete D.exclusiveMaximum)),typeof Z=="number"&&(D.multipleOf=Z);break}case"boolean":{const D=M;D.type="boolean";break}case"bigint":{if(this.unrepresentable==="throw")throw new Error("BigInt cannot be represented in JSON Schema");break}case"symbol":{if(this.unrepresentable==="throw")throw new Error("Symbols cannot be represented in JSON Schema");break}case"null":{M.type="null";break}case"any":break;case"unknown":break;case"undefined":{if(this.unrepresentable==="throw")throw new Error("Undefined cannot be represented in JSON Schema");break}case"void":{if(this.unrepresentable==="throw")throw new Error("Void cannot be represented in JSON Schema");break}case"never":{M.not={};break}case"date":{if(this.unrepresentable==="throw")throw new Error("Date cannot be represented in JSON Schema");break}case"array":{const D=M,{minimum:R,maximum:P}=r._zod.bag;typeof R=="number"&&(D.minItems=R),typeof P=="number"&&(D.maxItems=P),D.type="array",D.items=this.process(u.element,{...E,path:[...E.path,"items"]});break}case"object":{const D=M;D.type="object",D.properties={};const R=u.shape;for(const Z in R)D.properties[Z]=this.process(R[Z],{...E,path:[...E.path,"properties",Z]});const P=new Set(Object.keys(R)),H=new Set([...P].filter(Z=>{const $=u.shape[Z]._zod;return this.io==="input"?$.optin===void 0:$.optout===void 0}));H.size>0&&(D.required=Array.from(H)),u.catchall?._zod.def.type==="never"?D.additionalProperties=!1:u.catchall?u.catchall&&(D.additionalProperties=this.process(u.catchall,{...E,path:[...E.path,"additionalProperties"]})):this.io==="output"&&(D.additionalProperties=!1);break}case"union":{const D=M;D.anyOf=u.options.map((R,P)=>this.process(R,{...E,path:[...E.path,"anyOf",P]}));break}case"intersection":{const D=M,R=this.process(u.left,{...E,path:[...E.path,"allOf",0]}),P=this.process(u.right,{...E,path:[...E.path,"allOf",1]}),H=$=>"allOf"in $&&Object.keys($).length===1,Z=[...H(R)?R.allOf:[R],...H(P)?P.allOf:[P]];D.allOf=Z;break}case"tuple":{const D=M;D.type="array";const R=u.items.map((Z,$)=>this.process(Z,{...E,path:[...E.path,"prefixItems",$]}));if(this.target==="draft-2020-12"?D.prefixItems=R:D.items=R,u.rest){const Z=this.process(u.rest,{...E,path:[...E.path,"items"]});this.target==="draft-2020-12"?D.items=Z:D.additionalItems=Z}u.rest&&(D.items=this.process(u.rest,{...E,path:[...E.path,"items"]}));const{minimum:P,maximum:H}=r._zod.bag;typeof P=="number"&&(D.minItems=P),typeof H=="number"&&(D.maxItems=H);break}case"record":{const D=M;D.type="object",D.propertyNames=this.process(u.keyType,{...E,path:[...E.path,"propertyNames"]}),D.additionalProperties=this.process(u.valueType,{...E,path:[...E.path,"additionalProperties"]});break}case"map":{if(this.unrepresentable==="throw")throw new Error("Map cannot be represented in JSON Schema");break}case"set":{if(this.unrepresentable==="throw")throw new Error("Set cannot be represented in JSON Schema");break}case"enum":{const D=M,R=jl(u.entries);R.every(P=>typeof P=="number")&&(D.type="number"),R.every(P=>typeof P=="string")&&(D.type="string"),D.enum=R;break}case"literal":{const D=M,R=[];for(const P of u.values)if(P===void 0){if(this.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof P=="bigint"){if(this.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");R.push(Number(P))}else R.push(P);if(R.length!==0)if(R.length===1){const P=R[0];D.type=P===null?"null":typeof P,D.const=P}else R.every(P=>typeof P=="number")&&(D.type="number"),R.every(P=>typeof P=="string")&&(D.type="string"),R.every(P=>typeof P=="boolean")&&(D.type="string"),R.every(P=>P===null)&&(D.type="null"),D.enum=R;break}case"file":{const D=M,R={type:"string",format:"binary",contentEncoding:"binary"},{minimum:P,maximum:H,mime:Z}=r._zod.bag;P!==void 0&&(R.minLength=P),H!==void 0&&(R.maxLength=H),Z?Z.length===1?(R.contentMediaType=Z[0],Object.assign(D,R)):D.anyOf=Z.map($=>({...R,contentMediaType:$})):Object.assign(D,R);break}case"transform":{if(this.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema");break}case"nullable":{const D=this.process(u.innerType,E);M.anyOf=[D,{type:"null"}];break}case"nonoptional":{this.process(u.innerType,E),x.ref=u.innerType;break}case"success":{const D=M;D.type="boolean";break}case"default":{this.process(u.innerType,E),x.ref=u.innerType,M.default=JSON.parse(JSON.stringify(u.defaultValue));break}case"prefault":{this.process(u.innerType,E),x.ref=u.innerType,this.io==="input"&&(M._prefault=JSON.parse(JSON.stringify(u.defaultValue)));break}case"catch":{this.process(u.innerType,E),x.ref=u.innerType;let D;try{D=u.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}M.default=D;break}case"nan":{if(this.unrepresentable==="throw")throw new Error("NaN cannot be represented in JSON Schema");break}case"template_literal":{const D=M,R=r._zod.pattern;if(!R)throw new Error("Pattern not found in template literal");D.type="string",D.pattern=R.source;break}case"pipe":{const D=this.io==="input"?u.in._zod.def.type==="transform"?u.out:u.in:u.out;this.process(D,E),x.ref=D;break}case"readonly":{this.process(u.innerType,E),x.ref=u.innerType,M.readOnly=!0;break}case"promise":{this.process(u.innerType,E),x.ref=u.innerType;break}case"optional":{this.process(u.innerType,E),x.ref=u.innerType;break}case"lazy":{const D=r._zod.innerType;this.process(D,E),x.ref=D;break}case"custom":{if(this.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema");break}}}}const g=this.metadataRegistry.get(r);return g&&Object.assign(x.schema,g),this.io==="input"&&Dt(r)&&(delete x.schema.examples,delete x.schema.default),this.io==="input"&&x.schema._prefault&&((c=x.schema).default??(c.default=x.schema._prefault)),delete x.schema._prefault,this.seen.get(r).schema}emit(r,o){const c={cycles:o?.cycles??"ref",reused:o?.reused??"inline",external:o?.external??void 0},u=this.seen.get(r);if(!u)throw new Error("Unprocessed schema. This is a bug in Zod.");const f=A=>{const E=this.target==="draft-2020-12"?"$defs":"definitions";if(c.external){const R=c.external.registry.get(A[0])?.id,P=c.external.uri??(Z=>Z);if(R)return{ref:P(R)};const H=A[1].defId??A[1].schema.id??`schema${this.counter++}`;return A[1].defId=H,{defId:H,ref:`${P("__shared")}#/${E}/${H}`}}if(A[1]===u)return{ref:"#"};const M=`#/${E}/`,D=A[1].schema.id??`__schema${this.counter++}`;return{defId:D,ref:M+D}},p=A=>{if(A[1].schema.$ref)return;const E=A[1],{ref:L,defId:M}=f(A);E.def={...E.schema},M&&(E.defId=M);const D=E.schema;for(const R in D)delete D[R];D.$ref=L};if(c.cycles==="throw")for(const A of this.seen.entries()){const E=A[1];if(E.cycle)throw new Error(`Cycle detected: #/${E.cycle?.join("/")}/<root>
29
29
 
30
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const A of this.seen.entries()){const E=A[1];if(r===A[0]){p(A);continue}if(c.external){const D=c.external.registry.get(A[0])?.id;if(r!==A[0]&&D){p(A);continue}}if(this.metadataRegistry.get(A[0])?.id){p(A);continue}if(E.cycle){p(A);continue}if(E.count>1&&c.reused==="ref"){p(A);continue}}const x=(A,E)=>{const B=this.seen.get(A),D=B.def??B.schema,M={...D};if(B.ref===null)return;const R=B.ref;if(B.ref=null,R){x(R,E);const k=this.seen.get(R).schema;k.$ref&&E.target==="draft-7"?(D.allOf=D.allOf??[],D.allOf.push(k)):(Object.assign(D,k),Object.assign(D,M))}B.isParent||this.override({zodSchema:A,jsonSchema:D,path:B.path??[]})};for(const A of[...this.seen.entries()].reverse())x(A[0],{target:this.target});const y={};if(this.target==="draft-2020-12"?y.$schema="https://json-schema.org/draft/2020-12/schema":this.target==="draft-7"?y.$schema="http://json-schema.org/draft-07/schema#":console.warn(`Invalid target: ${this.target}`),c.external?.uri){const A=c.external.registry.get(r)?.id;if(!A)throw new Error("Schema is missing an `id` property");y.$id=c.external.uri(A)}Object.assign(y,u.def);const m=c.external?.defs??{};for(const A of this.seen.entries()){const E=A[1];E.def&&E.defId&&(m[E.defId]=E.def)}c.external||Object.keys(m).length>0&&(this.target==="draft-2020-12"?y.$defs=m:y.definitions=m);try{return JSON.parse(JSON.stringify(y))}catch{throw new Error("Error converting schema to JSON.")}}}function Bf(t,r){if(t instanceof ic){const c=new oa(r),u={};for(const x of t._idmap.entries()){const[y,m]=x;c.process(m)}const f={},p={registry:t,uri:r?.uri,defs:u};for(const x of t._idmap.entries()){const[y,m]=x;f[y]=c.emit(m,{...r,external:p})}if(Object.keys(u).length>0){const x=c.target==="draft-2020-12"?"$defs":"definitions";f.__shared={[x]:u}}return{schemas:f}}const o=new oa(r);return o.process(t),o.emit(t,r)}function Rt(t,r){const o=r??{seen:new Set};if(o.seen.has(t))return!1;o.seen.add(t);const u=t._zod.def;switch(u.type){case"string":case"number":case"bigint":case"boolean":case"date":case"symbol":case"undefined":case"null":case"any":case"unknown":case"never":case"void":case"literal":case"enum":case"nan":case"file":case"template_literal":return!1;case"array":return Rt(u.element,o);case"object":{for(const f in u.shape)if(Rt(u.shape[f],o))return!0;return!1}case"union":{for(const f of u.options)if(Rt(f,o))return!0;return!1}case"intersection":return Rt(u.left,o)||Rt(u.right,o);case"tuple":{for(const f of u.items)if(Rt(f,o))return!0;return!!(u.rest&&Rt(u.rest,o))}case"record":return Rt(u.keyType,o)||Rt(u.valueType,o);case"map":return Rt(u.keyType,o)||Rt(u.valueType,o);case"set":return Rt(u.valueType,o);case"promise":case"optional":case"nonoptional":case"nullable":case"readonly":return Rt(u.innerType,o);case"lazy":return Rt(u.getter(),o);case"default":return Rt(u.innerType,o);case"prefault":return Rt(u.innerType,o);case"custom":return!1;case"transform":return!0;case"pipe":return Rt(u.in,o)||Rt(u.out,o);case"success":return!1;case"catch":return!1}throw new Error(`Unknown schema type: ${u.type}`)}const Lf=ie("ZodISODateTime",(t,r)=>{r0.init(t,r),yt.init(t,r)});function Ff(t){return df(Lf,t)}const Uf=ie("ZodISODate",(t,r)=>{i0.init(t,r),yt.init(t,r)});function zf(t){return ff(Uf,t)}const Vf=ie("ZodISOTime",(t,r)=>{o0.init(t,r),yt.init(t,r)});function $f(t){return hf(Vf,t)}const Zf=ie("ZodISODuration",(t,r)=>{s0.init(t,r),yt.init(t,r)});function jf(t){return pf(Zf,t)}const Hf=(t,r)=>{Hl.init(t,r),t.name="ZodError",Object.defineProperties(t,{format:{value:o=>Qd(t,o)},flatten:{value:o=>Kd(t,o)},addIssue:{value:o=>t.issues.push(o)},addIssues:{value:o=>t.issues.push(...o)},isEmpty:{get(){return t.issues.length===0}}})},zi=ie("ZodError",Hf,{Parent:Error}),Wf=e1(zi),Gf=t1(zi),Xf=Gl(zi),ac=Xl(zi),dt=ie("ZodType",(t,r)=>(st.init(t,r),t.def=r,Object.defineProperty(t,"_def",{value:r}),t.check=(...o)=>t.clone({...r,checks:[...r.checks??[],...o.map(c=>typeof c=="function"?{_zod:{check:c,def:{check:"custom"},onattach:[]}}:c)]}),t.clone=(o,c)=>cr(t,o,c),t.brand=()=>t,t.register=((o,c)=>(o.add(t,c),t)),t.parse=(o,c)=>Wf(t,o,c,{callee:t.parse}),t.safeParse=(o,c)=>Xf(t,o,c),t.parseAsync=async(o,c)=>Gf(t,o,c,{callee:t.parseAsync}),t.safeParseAsync=async(o,c)=>ac(t,o,c),t.spa=t.safeParseAsync,t.refine=(o,c)=>t.check(Zh(o,c)),t.superRefine=o=>t.check(jh(o)),t.overwrite=o=>t.check(ni(o)),t.optional=()=>la(t),t.nullable=()=>ca(t),t.nullish=()=>la(ca(t)),t.nonoptional=o=>Dh(t,o),t.array=()=>me(t),t.or=o=>Le([t,o]),t.and=o=>Eh(t,o),t.transform=o=>ua(t,Th(o)),t.default=o=>kh(t,o),t.prefault=o=>Mh(t,o),t.catch=o=>Bh(t,o),t.pipe=o=>ua(t,o),t.readonly=()=>Uh(t),t.describe=o=>{const c=t.clone();return Zr.add(c,{description:o}),c},Object.defineProperty(t,"description",{get(){return Zr.get(t)?.description},configurable:!0}),t.meta=(...o)=>{if(o.length===0)return Zr.get(t);const c=t.clone();return Zr.add(c,o[0]),c},t.isOptional=()=>t.safeParse(void 0).success,t.isNullable=()=>t.safeParse(null).success,t)),lc=ie("_ZodString",(t,r)=>{Zo.init(t,r),dt.init(t,r);const o=t._zod.bag;t.format=o.format??null,t.minLength=o.minimum??null,t.maxLength=o.maximum??null,t.regex=(...c)=>t.check(bf(...c)),t.includes=(...c)=>t.check(If(...c)),t.startsWith=(...c)=>t.check(Sf(...c)),t.endsWith=(...c)=>t.check(Tf(...c)),t.min=(...c)=>t.check(Mi(...c)),t.max=(...c)=>t.check(oc(...c)),t.length=(...c)=>t.check(sc(...c)),t.nonempty=(...c)=>t.check(Mi(1,...c)),t.lowercase=c=>t.check(Ef(c)),t.uppercase=c=>t.check(Af(c)),t.trim=()=>t.check(Of()),t.normalize=(...c)=>t.check(Nf(...c)),t.toLowerCase=()=>t.check(kf()),t.toUpperCase=()=>t.check(Rf())}),qf=ie("ZodString",(t,r)=>{Zo.init(t,r),lc.init(t,r),t.email=o=>t.check(Z0(Yf,o)),t.url=o=>t.check(X0(Jf,o)),t.jwt=o=>t.check(uf(fh,o)),t.emoji=o=>t.check(q0(Kf,o)),t.guid=o=>t.check(ta(sa,o)),t.uuid=o=>t.check(j0(vi,o)),t.uuidv4=o=>t.check(H0(vi,o)),t.uuidv6=o=>t.check(W0(vi,o)),t.uuidv7=o=>t.check(G0(vi,o)),t.nanoid=o=>t.check(Y0(Qf,o)),t.guid=o=>t.check(ta(sa,o)),t.cuid=o=>t.check(J0(eh,o)),t.cuid2=o=>t.check(K0(th,o)),t.ulid=o=>t.check(Q0(nh,o)),t.base64=o=>t.check(af(ch,o)),t.base64url=o=>t.check(lf(uh,o)),t.xid=o=>t.check(ef(rh,o)),t.ksuid=o=>t.check(tf(ih,o)),t.ipv4=o=>t.check(nf(oh,o)),t.ipv6=o=>t.check(rf(sh,o)),t.cidrv4=o=>t.check(of(ah,o)),t.cidrv6=o=>t.check(sf(lh,o)),t.e164=o=>t.check(cf(dh,o)),t.datetime=o=>t.check(Ff(o)),t.date=o=>t.check(zf(o)),t.time=o=>t.check($f(o)),t.duration=o=>t.check(jf(o))});function _(t){return $0(qf,t)}const yt=ie("ZodStringFormat",(t,r)=>{mt.init(t,r),lc.init(t,r)}),Yf=ie("ZodEmail",(t,r)=>{X1.init(t,r),yt.init(t,r)}),sa=ie("ZodGUID",(t,r)=>{W1.init(t,r),yt.init(t,r)}),vi=ie("ZodUUID",(t,r)=>{G1.init(t,r),yt.init(t,r)}),Jf=ie("ZodURL",(t,r)=>{q1.init(t,r),yt.init(t,r)}),Kf=ie("ZodEmoji",(t,r)=>{Y1.init(t,r),yt.init(t,r)}),Qf=ie("ZodNanoID",(t,r)=>{J1.init(t,r),yt.init(t,r)}),eh=ie("ZodCUID",(t,r)=>{K1.init(t,r),yt.init(t,r)}),th=ie("ZodCUID2",(t,r)=>{Q1.init(t,r),yt.init(t,r)}),nh=ie("ZodULID",(t,r)=>{e0.init(t,r),yt.init(t,r)}),rh=ie("ZodXID",(t,r)=>{t0.init(t,r),yt.init(t,r)}),ih=ie("ZodKSUID",(t,r)=>{n0.init(t,r),yt.init(t,r)}),oh=ie("ZodIPv4",(t,r)=>{a0.init(t,r),yt.init(t,r)}),sh=ie("ZodIPv6",(t,r)=>{l0.init(t,r),yt.init(t,r)}),ah=ie("ZodCIDRv4",(t,r)=>{c0.init(t,r),yt.init(t,r)}),lh=ie("ZodCIDRv6",(t,r)=>{u0.init(t,r),yt.init(t,r)}),ch=ie("ZodBase64",(t,r)=>{d0.init(t,r),yt.init(t,r)}),uh=ie("ZodBase64URL",(t,r)=>{h0.init(t,r),yt.init(t,r)}),dh=ie("ZodE164",(t,r)=>{p0.init(t,r),yt.init(t,r)}),fh=ie("ZodJWT",(t,r)=>{m0.init(t,r),yt.init(t,r)}),jo=ie("ZodNumber",(t,r)=>{nc.init(t,r),dt.init(t,r),t.gt=(c,u)=>t.check(ra(c,u)),t.gte=(c,u)=>t.check(ho(c,u)),t.min=(c,u)=>t.check(ho(c,u)),t.lt=(c,u)=>t.check(na(c,u)),t.lte=(c,u)=>t.check(fo(c,u)),t.max=(c,u)=>t.check(fo(c,u)),t.int=c=>t.check(aa(c)),t.safe=c=>t.check(aa(c)),t.positive=c=>t.check(ra(0,c)),t.nonnegative=c=>t.check(ho(0,c)),t.negative=c=>t.check(na(0,c)),t.nonpositive=c=>t.check(fo(0,c)),t.multipleOf=(c,u)=>t.check(ia(c,u)),t.step=(c,u)=>t.check(ia(c,u)),t.finite=()=>t;const o=t._zod.bag;t.minValue=Math.max(o.minimum??Number.NEGATIVE_INFINITY,o.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,t.maxValue=Math.min(o.maximum??Number.POSITIVE_INFINITY,o.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,t.isInt=(o.format??"").includes("int")||Number.isSafeInteger(o.multipleOf??.5),t.isFinite=!0,t.format=o.format??null});function X(t){return gf(jo,t)}const hh=ie("ZodNumberFormat",(t,r)=>{x0.init(t,r),jo.init(t,r)});function aa(t){return xf(hh,t)}const ph=ie("ZodBoolean",(t,r)=>{w0.init(t,r),dt.init(t,r)});function At(t){return wf(ph,t)}const gh=ie("ZodNull",(t,r)=>{y0.init(t,r),dt.init(t,r)});function cc(t){return yf(gh,t)}const mh=ie("ZodAny",(t,r)=>{_0.init(t,r),dt.init(t,r)});function ur(){return _f(mh)}const xh=ie("ZodUnknown",(t,r)=>{v0.init(t,r),dt.init(t,r)});function Ir(){return vf(xh)}const wh=ie("ZodNever",(t,r)=>{C0.init(t,r),dt.init(t,r)});function yh(t){return Cf(wh,t)}const _h=ie("ZodArray",(t,r)=>{b0.init(t,r),dt.init(t,r),t.element=r.element,t.min=(o,c)=>t.check(Mi(o,c)),t.nonempty=o=>t.check(Mi(1,o)),t.max=(o,c)=>t.check(oc(o,c)),t.length=(o,c)=>t.check(sc(o,c)),t.unwrap=()=>t.element});function me(t,r){return Mf(_h,t,r)}const vh=ie("ZodObject",(t,r)=>{E0.init(t,r),dt.init(t,r),Ke(t,"shape",()=>r.shape),t.keyof=()=>We(Object.keys(t._zod.def.shape)),t.catchall=o=>t.clone({...t._zod.def,catchall:o}),t.passthrough=()=>t.clone({...t._zod.def,catchall:Ir()}),t.loose=()=>t.clone({...t._zod.def,catchall:Ir()}),t.strict=()=>t.clone({...t._zod.def,catchall:yh()}),t.strip=()=>t.clone({...t._zod.def,catchall:void 0}),t.extend=o=>Xd(t,o),t.merge=o=>qd(t,o),t.pick=o=>Wd(t,o),t.omit=o=>Gd(t,o),t.partial=(...o)=>Yd(dc,t,o[0]),t.required=(...o)=>Jd(fc,t,o[0])});function T(t,r){const o={type:"object",get shape(){return Vo(this,"shape",{...t}),this.shape},...Ae(r)};return new vh(o)}const uc=ie("ZodUnion",(t,r)=>{rc.init(t,r),dt.init(t,r),t.options=r.options});function Le(t,r){return new uc({type:"union",options:t,...Ae(r)})}const Ch=ie("ZodDiscriminatedUnion",(t,r)=>{uc.init(t,r),A0.init(t,r)});function Et(t,r,o){return new Ch({type:"union",options:r,discriminator:t,...Ae(o)})}const bh=ie("ZodIntersection",(t,r)=>{I0.init(t,r),dt.init(t,r)});function Eh(t,r){return new bh({type:"intersection",left:t,right:r})}const Ah=ie("ZodRecord",(t,r)=>{S0.init(t,r),dt.init(t,r),t.keyType=r.keyType,t.valueType=r.valueType});function pt(t,r,o){return new Ah({type:"record",keyType:t,valueType:r,...Ae(o)})}const Io=ie("ZodEnum",(t,r)=>{T0.init(t,r),dt.init(t,r),t.enum=r.entries,t.options=Object.values(r.entries);const o=new Set(Object.keys(r.entries));t.extract=(c,u)=>{const f={};for(const p of c)if(o.has(p))f[p]=r.entries[p];else throw new Error(`Key ${p} not found in enum`);return new Io({...r,checks:[],...Ae(u),entries:f})},t.exclude=(c,u)=>{const f={...r.entries};for(const p of c)if(o.has(p))delete f[p];else throw new Error(`Key ${p} not found in enum`);return new Io({...r,checks:[],...Ae(u),entries:f})}});function We(t,r){const o=Array.isArray(t)?Object.fromEntries(t.map(c=>[c,c])):t;return new Io({type:"enum",entries:o,...Ae(r)})}const Ih=ie("ZodLiteral",(t,r)=>{N0.init(t,r),dt.init(t,r),t.values=new Set(r.values),Object.defineProperty(t,"value",{get(){if(r.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return r.values[0]}})});function Y(t,r){return new Ih({type:"literal",values:Array.isArray(t)?t:[t],...Ae(r)})}const Sh=ie("ZodTransform",(t,r)=>{O0.init(t,r),dt.init(t,r),t._zod.parse=(o,c)=>{o.addIssue=f=>{if(typeof f=="string")o.issues.push(Yr(f,o.value,r));else{const p=f;p.fatal&&(p.continue=!1),p.code??(p.code="custom"),p.input??(p.input=o.value),p.inst??(p.inst=t),p.continue??(p.continue=!0),o.issues.push(Yr(p))}};const u=r.transform(o.value,o);return u instanceof Promise?u.then(f=>(o.value=f,o)):(o.value=u,o)}});function Th(t){return new Sh({type:"transform",transform:t})}const dc=ie("ZodOptional",(t,r)=>{k0.init(t,r),dt.init(t,r),t.unwrap=()=>t._zod.def.innerType});function la(t){return new dc({type:"optional",innerType:t})}const Nh=ie("ZodNullable",(t,r)=>{R0.init(t,r),dt.init(t,r),t.unwrap=()=>t._zod.def.innerType});function ca(t){return new Nh({type:"nullable",innerType:t})}const Oh=ie("ZodDefault",(t,r)=>{M0.init(t,r),dt.init(t,r),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function kh(t,r){return new Oh({type:"default",innerType:t,get defaultValue(){return typeof r=="function"?r():r}})}const Rh=ie("ZodPrefault",(t,r)=>{D0.init(t,r),dt.init(t,r),t.unwrap=()=>t._zod.def.innerType});function Mh(t,r){return new Rh({type:"prefault",innerType:t,get defaultValue(){return typeof r=="function"?r():r}})}const fc=ie("ZodNonOptional",(t,r)=>{P0.init(t,r),dt.init(t,r),t.unwrap=()=>t._zod.def.innerType});function Dh(t,r){return new fc({type:"nonoptional",innerType:t,...Ae(r)})}const Ph=ie("ZodCatch",(t,r)=>{B0.init(t,r),dt.init(t,r),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function Bh(t,r){return new Ph({type:"catch",innerType:t,catchValue:typeof r=="function"?r:()=>r})}const Lh=ie("ZodPipe",(t,r)=>{L0.init(t,r),dt.init(t,r),t.in=r.in,t.out=r.out});function ua(t,r){return new Lh({type:"pipe",in:t,out:r})}const Fh=ie("ZodReadonly",(t,r)=>{F0.init(t,r),dt.init(t,r)});function Uh(t){return new Fh({type:"readonly",innerType:t})}const zh=ie("ZodLazy",(t,r)=>{U0.init(t,r),dt.init(t,r),t.unwrap=()=>t._zod.def.getter()});function Ho(t){return new zh({type:"lazy",getter:t})}const Wo=ie("ZodCustom",(t,r)=>{z0.init(t,r),dt.init(t,r)});function Vh(t){const r=new Qt({check:"custom"});return r._zod.check=t,r}function $h(t,r){return Df(Wo,t??(()=>!0),r)}function Zh(t,r={}){return Pf(Wo,t,r)}function jh(t){const r=Vh(o=>(o.addIssue=c=>{if(typeof c=="string")o.issues.push(Yr(c,o.value,r._zod.def));else{const u=c;u.fatal&&(u.continue=!1),u.code??(u.code="custom"),u.input??(u.input=o.value),u.inst??(u.inst=r),u.continue??(u.continue=!r._zod.def.abort),o.issues.push(Yr(u))}},t(o.value,o)));return r}function Di(t,r={error:`Input not instance of ${t.name}`}){const o=new Wo({type:"custom",check:"custom",fn:c=>c instanceof t,abort:!0,...Ae(r)});return o._zod.bag.Class=t,o}function Hh(t){return mf(jo,t)}var De;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(De||(De={}));class da extends Error{constructor(r,o){super(r),this.name="ParseError",this.type=o.type,this.field=o.field,this.value=o.value,this.line=o.line}}function po(t){}function Wh(t){if(typeof t=="function")throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");const{onEvent:r=po,onError:o=po,onRetry:c=po,onComment:u}=t;let f="",p=!0,x,y="",m="";function A(R){const k=p?R.replace(/^\xEF\xBB\xBF/,""):R,[q,Z]=Gh(`${f}${k}`);for(const z of q)E(z);f=Z,p=!1}function E(R){if(R===""){D();return}if(R.startsWith(":")){u&&u(R.slice(R.startsWith(": ")?2:1));return}const k=R.indexOf(":");if(k!==-1){const q=R.slice(0,k),Z=R[k+1]===" "?2:1,z=R.slice(k+Z);B(q,z,R);return}B(R,"",R)}function B(R,k,q){switch(R){case"event":m=k;break;case"data":y=`${y}${k}
31
- `;break;case"id":x=k.includes("\0")?void 0:k;break;case"retry":/^\d+$/.test(k)?c(parseInt(k,10)):o(new da(`Invalid \`retry\` value: "${k}"`,{type:"invalid-retry",value:k,line:q}));break;default:o(new da(`Unknown field "${R.length>20?`${R.slice(0,20)}…`:R}"`,{type:"unknown-field",field:R,value:k,line:q}));break}}function D(){y.length>0&&r({id:x,event:m||void 0,data:y.endsWith(`
32
- `)?y.slice(0,-1):y}),x=void 0,y="",m=""}function M(R={}){f&&R.consume&&E(f),p=!0,x=void 0,y="",m="",f=""}return{feed:A,reset:M}}function Gh(t){const r=[];let o="",c=0;for(;c<t.length;){const u=t.indexOf("\r",c),f=t.indexOf(`
30
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const A of this.seen.entries()){const E=A[1];if(r===A[0]){p(A);continue}if(c.external){const M=c.external.registry.get(A[0])?.id;if(r!==A[0]&&M){p(A);continue}}if(this.metadataRegistry.get(A[0])?.id){p(A);continue}if(E.cycle){p(A);continue}if(E.count>1&&c.reused==="ref"){p(A);continue}}const x=(A,E)=>{const L=this.seen.get(A),M=L.def??L.schema,D={...M};if(L.ref===null)return;const R=L.ref;if(L.ref=null,R){x(R,E);const P=this.seen.get(R).schema;P.$ref&&E.target==="draft-7"?(M.allOf=M.allOf??[],M.allOf.push(P)):(Object.assign(M,P),Object.assign(M,D))}L.isParent||this.override({zodSchema:A,jsonSchema:M,path:L.path??[]})};for(const A of[...this.seen.entries()].reverse())x(A[0],{target:this.target});const _={};if(this.target==="draft-2020-12"?_.$schema="https://json-schema.org/draft/2020-12/schema":this.target==="draft-7"?_.$schema="http://json-schema.org/draft-07/schema#":console.warn(`Invalid target: ${this.target}`),c.external?.uri){const A=c.external.registry.get(r)?.id;if(!A)throw new Error("Schema is missing an `id` property");_.$id=c.external.uri(A)}Object.assign(_,u.def);const g=c.external?.defs??{};for(const A of this.seen.entries()){const E=A[1];E.def&&E.defId&&(g[E.defId]=E.def)}c.external||Object.keys(g).length>0&&(this.target==="draft-2020-12"?_.$defs=g:_.definitions=g);try{return JSON.parse(JSON.stringify(_))}catch{throw new Error("Error converting schema to JSON.")}}}function Lf(t,r){if(t instanceof sc){const c=new sa(r),u={};for(const x of t._idmap.entries()){const[_,g]=x;c.process(g)}const f={},p={registry:t,uri:r?.uri,defs:u};for(const x of t._idmap.entries()){const[_,g]=x;f[_]=c.emit(g,{...r,external:p})}if(Object.keys(u).length>0){const x=c.target==="draft-2020-12"?"$defs":"definitions";f.__shared={[x]:u}}return{schemas:f}}const o=new sa(r);return o.process(t),o.emit(t,r)}function Dt(t,r){const o=r??{seen:new Set};if(o.seen.has(t))return!1;o.seen.add(t);const u=t._zod.def;switch(u.type){case"string":case"number":case"bigint":case"boolean":case"date":case"symbol":case"undefined":case"null":case"any":case"unknown":case"never":case"void":case"literal":case"enum":case"nan":case"file":case"template_literal":return!1;case"array":return Dt(u.element,o);case"object":{for(const f in u.shape)if(Dt(u.shape[f],o))return!0;return!1}case"union":{for(const f of u.options)if(Dt(f,o))return!0;return!1}case"intersection":return Dt(u.left,o)||Dt(u.right,o);case"tuple":{for(const f of u.items)if(Dt(f,o))return!0;return!!(u.rest&&Dt(u.rest,o))}case"record":return Dt(u.keyType,o)||Dt(u.valueType,o);case"map":return Dt(u.keyType,o)||Dt(u.valueType,o);case"set":return Dt(u.valueType,o);case"promise":case"optional":case"nonoptional":case"nullable":case"readonly":return Dt(u.innerType,o);case"lazy":return Dt(u.getter(),o);case"default":return Dt(u.innerType,o);case"prefault":return Dt(u.innerType,o);case"custom":return!1;case"transform":return!0;case"pipe":return Dt(u.in,o)||Dt(u.out,o);case"success":return!1;case"catch":return!1}throw new Error(`Unknown schema type: ${u.type}`)}const Ff=se("ZodISODateTime",(t,r)=>{i0.init(t,r),bt.init(t,r)});function Uf(t){return ff(Ff,t)}const zf=se("ZodISODate",(t,r)=>{o0.init(t,r),bt.init(t,r)});function Vf(t){return hf(zf,t)}const $f=se("ZodISOTime",(t,r)=>{s0.init(t,r),bt.init(t,r)});function Zf(t){return pf($f,t)}const jf=se("ZodISODuration",(t,r)=>{a0.init(t,r),bt.init(t,r)});function Hf(t){return mf(jf,t)}const Wf=(t,r)=>{Gl.init(t,r),t.name="ZodError",Object.defineProperties(t,{format:{value:o=>e1(t,o)},flatten:{value:o=>Qd(t,o)},addIssue:{value:o=>t.issues.push(o)},addIssues:{value:o=>t.issues.push(...o)},isEmpty:{get(){return t.issues.length===0}}})},zi=se("ZodError",Wf,{Parent:Error}),Gf=t1(zi),Xf=n1(zi),qf=ql(zi),cc=Yl(zi),pt=se("ZodType",(t,r)=>(ct.init(t,r),t.def=r,Object.defineProperty(t,"_def",{value:r}),t.check=(...o)=>t.clone({...r,checks:[...r.checks??[],...o.map(c=>typeof c=="function"?{_zod:{check:c,def:{check:"custom"},onattach:[]}}:c)]}),t.clone=(o,c)=>fr(t,o,c),t.brand=()=>t,t.register=((o,c)=>(o.add(t,c),t)),t.parse=(o,c)=>Gf(t,o,c,{callee:t.parse}),t.safeParse=(o,c)=>qf(t,o,c),t.parseAsync=async(o,c)=>Xf(t,o,c,{callee:t.parseAsync}),t.safeParseAsync=async(o,c)=>cc(t,o,c),t.spa=t.safeParseAsync,t.refine=(o,c)=>t.check(jh(o,c)),t.superRefine=o=>t.check(Hh(o)),t.overwrite=o=>t.check(ri(o)),t.optional=()=>ca(t),t.nullable=()=>ua(t),t.nullish=()=>ca(ua(t)),t.nonoptional=o=>Ph(t,o),t.array=()=>me(t),t.or=o=>Pe([t,o]),t.and=o=>Ah(t,o),t.transform=o=>da(t,Nh(o)),t.default=o=>Rh(t,o),t.prefault=o=>Dh(t,o),t.catch=o=>Lh(t,o),t.pipe=o=>da(t,o),t.readonly=()=>zh(t),t.describe=o=>{const c=t.clone();return jr.add(c,{description:o}),c},Object.defineProperty(t,"description",{get(){return jr.get(t)?.description},configurable:!0}),t.meta=(...o)=>{if(o.length===0)return jr.get(t);const c=t.clone();return jr.add(c,o[0]),c},t.isOptional=()=>t.safeParse(void 0).success,t.isNullable=()=>t.safeParse(null).success,t)),uc=se("_ZodString",(t,r)=>{jo.init(t,r),pt.init(t,r);const o=t._zod.bag;t.format=o.format??null,t.minLength=o.minimum??null,t.maxLength=o.maximum??null,t.regex=(...c)=>t.check(Ef(...c)),t.includes=(...c)=>t.check(Sf(...c)),t.startsWith=(...c)=>t.check(Tf(...c)),t.endsWith=(...c)=>t.check(Nf(...c)),t.min=(...c)=>t.check(Mi(...c)),t.max=(...c)=>t.check(ac(...c)),t.length=(...c)=>t.check(lc(...c)),t.nonempty=(...c)=>t.check(Mi(1,...c)),t.lowercase=c=>t.check(Af(c)),t.uppercase=c=>t.check(If(c)),t.trim=()=>t.check(kf()),t.normalize=(...c)=>t.check(Of(...c)),t.toLowerCase=()=>t.check(Rf()),t.toUpperCase=()=>t.check(Mf())}),Yf=se("ZodString",(t,r)=>{jo.init(t,r),uc.init(t,r),t.email=o=>t.check(j0(Jf,o)),t.url=o=>t.check(q0(Kf,o)),t.jwt=o=>t.check(df(hh,o)),t.emoji=o=>t.check(Y0(Qf,o)),t.guid=o=>t.check(na(aa,o)),t.uuid=o=>t.check(H0(vi,o)),t.uuidv4=o=>t.check(W0(vi,o)),t.uuidv6=o=>t.check(G0(vi,o)),t.uuidv7=o=>t.check(X0(vi,o)),t.nanoid=o=>t.check(J0(eh,o)),t.guid=o=>t.check(na(aa,o)),t.cuid=o=>t.check(K0(th,o)),t.cuid2=o=>t.check(Q0(nh,o)),t.ulid=o=>t.check(ef(rh,o)),t.base64=o=>t.check(lf(uh,o)),t.base64url=o=>t.check(cf(dh,o)),t.xid=o=>t.check(tf(ih,o)),t.ksuid=o=>t.check(nf(oh,o)),t.ipv4=o=>t.check(rf(sh,o)),t.ipv6=o=>t.check(of(ah,o)),t.cidrv4=o=>t.check(sf(lh,o)),t.cidrv6=o=>t.check(af(ch,o)),t.e164=o=>t.check(uf(fh,o)),t.datetime=o=>t.check(Uf(o)),t.date=o=>t.check(Vf(o)),t.time=o=>t.check(Zf(o)),t.duration=o=>t.check(Hf(o))});function w(t){return Z0(Yf,t)}const bt=se("ZodStringFormat",(t,r)=>{yt.init(t,r),uc.init(t,r)}),Jf=se("ZodEmail",(t,r)=>{q1.init(t,r),bt.init(t,r)}),aa=se("ZodGUID",(t,r)=>{G1.init(t,r),bt.init(t,r)}),vi=se("ZodUUID",(t,r)=>{X1.init(t,r),bt.init(t,r)}),Kf=se("ZodURL",(t,r)=>{Y1.init(t,r),bt.init(t,r)}),Qf=se("ZodEmoji",(t,r)=>{J1.init(t,r),bt.init(t,r)}),eh=se("ZodNanoID",(t,r)=>{K1.init(t,r),bt.init(t,r)}),th=se("ZodCUID",(t,r)=>{Q1.init(t,r),bt.init(t,r)}),nh=se("ZodCUID2",(t,r)=>{e0.init(t,r),bt.init(t,r)}),rh=se("ZodULID",(t,r)=>{t0.init(t,r),bt.init(t,r)}),ih=se("ZodXID",(t,r)=>{n0.init(t,r),bt.init(t,r)}),oh=se("ZodKSUID",(t,r)=>{r0.init(t,r),bt.init(t,r)}),sh=se("ZodIPv4",(t,r)=>{l0.init(t,r),bt.init(t,r)}),ah=se("ZodIPv6",(t,r)=>{c0.init(t,r),bt.init(t,r)}),lh=se("ZodCIDRv4",(t,r)=>{u0.init(t,r),bt.init(t,r)}),ch=se("ZodCIDRv6",(t,r)=>{d0.init(t,r),bt.init(t,r)}),uh=se("ZodBase64",(t,r)=>{f0.init(t,r),bt.init(t,r)}),dh=se("ZodBase64URL",(t,r)=>{p0.init(t,r),bt.init(t,r)}),fh=se("ZodE164",(t,r)=>{m0.init(t,r),bt.init(t,r)}),hh=se("ZodJWT",(t,r)=>{x0.init(t,r),bt.init(t,r)}),Ho=se("ZodNumber",(t,r)=>{ic.init(t,r),pt.init(t,r),t.gt=(c,u)=>t.check(ia(c,u)),t.gte=(c,u)=>t.check(ho(c,u)),t.min=(c,u)=>t.check(ho(c,u)),t.lt=(c,u)=>t.check(ra(c,u)),t.lte=(c,u)=>t.check(fo(c,u)),t.max=(c,u)=>t.check(fo(c,u)),t.int=c=>t.check(la(c)),t.safe=c=>t.check(la(c)),t.positive=c=>t.check(ia(0,c)),t.nonnegative=c=>t.check(ho(0,c)),t.negative=c=>t.check(ra(0,c)),t.nonpositive=c=>t.check(fo(0,c)),t.multipleOf=(c,u)=>t.check(oa(c,u)),t.step=(c,u)=>t.check(oa(c,u)),t.finite=()=>t;const o=t._zod.bag;t.minValue=Math.max(o.minimum??Number.NEGATIVE_INFINITY,o.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,t.maxValue=Math.min(o.maximum??Number.POSITIVE_INFINITY,o.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,t.isInt=(o.format??"").includes("int")||Number.isSafeInteger(o.multipleOf??.5),t.isFinite=!0,t.format=o.format??null});function Y(t){return gf(Ho,t)}const ph=se("ZodNumberFormat",(t,r)=>{y0.init(t,r),Ho.init(t,r)});function la(t){return yf(ph,t)}const mh=se("ZodBoolean",(t,r)=>{w0.init(t,r),pt.init(t,r)});function Nt(t){return wf(mh,t)}const gh=se("ZodNull",(t,r)=>{_0.init(t,r),pt.init(t,r)});function dc(t){return _f(gh,t)}const xh=se("ZodAny",(t,r)=>{v0.init(t,r),pt.init(t,r)});function hr(){return vf(xh)}const yh=se("ZodUnknown",(t,r)=>{C0.init(t,r),pt.init(t,r)});function Tr(){return Cf(yh)}const wh=se("ZodNever",(t,r)=>{b0.init(t,r),pt.init(t,r)});function _h(t){return bf(wh,t)}const vh=se("ZodArray",(t,r)=>{E0.init(t,r),pt.init(t,r),t.element=r.element,t.min=(o,c)=>t.check(Mi(o,c)),t.nonempty=o=>t.check(Mi(1,o)),t.max=(o,c)=>t.check(ac(o,c)),t.length=(o,c)=>t.check(lc(o,c)),t.unwrap=()=>t.element});function me(t,r){return Df(vh,t,r)}const Ch=se("ZodObject",(t,r)=>{A0.init(t,r),pt.init(t,r),Qe(t,"shape",()=>r.shape),t.keyof=()=>Fe(Object.keys(t._zod.def.shape)),t.catchall=o=>t.clone({...t._zod.def,catchall:o}),t.passthrough=()=>t.clone({...t._zod.def,catchall:Tr()}),t.loose=()=>t.clone({...t._zod.def,catchall:Tr()}),t.strict=()=>t.clone({...t._zod.def,catchall:_h()}),t.strip=()=>t.clone({...t._zod.def,catchall:void 0}),t.extend=o=>qd(t,o),t.merge=o=>Yd(t,o),t.pick=o=>Gd(t,o),t.omit=o=>Xd(t,o),t.partial=(...o)=>Jd(hc,t,o[0]),t.required=(...o)=>Kd(pc,t,o[0])});function S(t,r){const o={type:"object",get shape(){return $o(this,"shape",{...t}),this.shape},...be(r)};return new Ch(o)}const fc=se("ZodUnion",(t,r)=>{oc.init(t,r),pt.init(t,r),t.options=r.options});function Pe(t,r){return new fc({type:"union",options:t,...be(r)})}const bh=se("ZodDiscriminatedUnion",(t,r)=>{fc.init(t,r),I0.init(t,r)});function lt(t,r,o){return new bh({type:"union",options:r,discriminator:t,...be(o)})}const Eh=se("ZodIntersection",(t,r)=>{S0.init(t,r),pt.init(t,r)});function Ah(t,r){return new Eh({type:"intersection",left:t,right:r})}const Ih=se("ZodRecord",(t,r)=>{T0.init(t,r),pt.init(t,r),t.keyType=r.keyType,t.valueType=r.valueType});function gt(t,r,o){return new Ih({type:"record",keyType:t,valueType:r,...be(o)})}const Io=se("ZodEnum",(t,r)=>{N0.init(t,r),pt.init(t,r),t.enum=r.entries,t.options=Object.values(r.entries);const o=new Set(Object.keys(r.entries));t.extract=(c,u)=>{const f={};for(const p of c)if(o.has(p))f[p]=r.entries[p];else throw new Error(`Key ${p} not found in enum`);return new Io({...r,checks:[],...be(u),entries:f})},t.exclude=(c,u)=>{const f={...r.entries};for(const p of c)if(o.has(p))delete f[p];else throw new Error(`Key ${p} not found in enum`);return new Io({...r,checks:[],...be(u),entries:f})}});function Fe(t,r){const o=Array.isArray(t)?Object.fromEntries(t.map(c=>[c,c])):t;return new Io({type:"enum",entries:o,...be(r)})}const Sh=se("ZodLiteral",(t,r)=>{O0.init(t,r),pt.init(t,r),t.values=new Set(r.values),Object.defineProperty(t,"value",{get(){if(r.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return r.values[0]}})});function W(t,r){return new Sh({type:"literal",values:Array.isArray(t)?t:[t],...be(r)})}const Th=se("ZodTransform",(t,r)=>{k0.init(t,r),pt.init(t,r),t._zod.parse=(o,c)=>{o.addIssue=f=>{if(typeof f=="string")o.issues.push(Jr(f,o.value,r));else{const p=f;p.fatal&&(p.continue=!1),p.code??(p.code="custom"),p.input??(p.input=o.value),p.inst??(p.inst=t),p.continue??(p.continue=!0),o.issues.push(Jr(p))}};const u=r.transform(o.value,o);return u instanceof Promise?u.then(f=>(o.value=f,o)):(o.value=u,o)}});function Nh(t){return new Th({type:"transform",transform:t})}const hc=se("ZodOptional",(t,r)=>{R0.init(t,r),pt.init(t,r),t.unwrap=()=>t._zod.def.innerType});function ca(t){return new hc({type:"optional",innerType:t})}const Oh=se("ZodNullable",(t,r)=>{M0.init(t,r),pt.init(t,r),t.unwrap=()=>t._zod.def.innerType});function ua(t){return new Oh({type:"nullable",innerType:t})}const kh=se("ZodDefault",(t,r)=>{D0.init(t,r),pt.init(t,r),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function Rh(t,r){return new kh({type:"default",innerType:t,get defaultValue(){return typeof r=="function"?r():r}})}const Mh=se("ZodPrefault",(t,r)=>{P0.init(t,r),pt.init(t,r),t.unwrap=()=>t._zod.def.innerType});function Dh(t,r){return new Mh({type:"prefault",innerType:t,get defaultValue(){return typeof r=="function"?r():r}})}const pc=se("ZodNonOptional",(t,r)=>{B0.init(t,r),pt.init(t,r),t.unwrap=()=>t._zod.def.innerType});function Ph(t,r){return new pc({type:"nonoptional",innerType:t,...be(r)})}const Bh=se("ZodCatch",(t,r)=>{L0.init(t,r),pt.init(t,r),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function Lh(t,r){return new Bh({type:"catch",innerType:t,catchValue:typeof r=="function"?r:()=>r})}const Fh=se("ZodPipe",(t,r)=>{F0.init(t,r),pt.init(t,r),t.in=r.in,t.out=r.out});function da(t,r){return new Fh({type:"pipe",in:t,out:r})}const Uh=se("ZodReadonly",(t,r)=>{U0.init(t,r),pt.init(t,r)});function zh(t){return new Uh({type:"readonly",innerType:t})}const Vh=se("ZodLazy",(t,r)=>{z0.init(t,r),pt.init(t,r),t.unwrap=()=>t._zod.def.getter()});function Wo(t){return new Vh({type:"lazy",getter:t})}const Go=se("ZodCustom",(t,r)=>{V0.init(t,r),pt.init(t,r)});function $h(t){const r=new nn({check:"custom"});return r._zod.check=t,r}function Zh(t,r){return Pf(Go,t??(()=>!0),r)}function jh(t,r={}){return Bf(Go,t,r)}function Hh(t){const r=$h(o=>(o.addIssue=c=>{if(typeof c=="string")o.issues.push(Jr(c,o.value,r._zod.def));else{const u=c;u.fatal&&(u.continue=!1),u.code??(u.code="custom"),u.input??(u.input=o.value),u.inst??(u.inst=r),u.continue??(u.continue=!r._zod.def.abort),o.issues.push(Jr(u))}},t(o.value,o)));return r}function Di(t,r={error:`Input not instance of ${t.name}`}){const o=new Go({type:"custom",check:"custom",fn:c=>c instanceof t,abort:!0,...be(r)});return o._zod.bag.Class=t,o}function Wh(t){return xf(Ho,t)}var Re;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(Re||(Re={}));class fa extends Error{constructor(r,o){super(r),this.name="ParseError",this.type=o.type,this.field=o.field,this.value=o.value,this.line=o.line}}function po(t){}function Gh(t){if(typeof t=="function")throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");const{onEvent:r=po,onError:o=po,onRetry:c=po,onComment:u}=t;let f="",p=!0,x,_="",g="";function A(R){const P=p?R.replace(/^\xEF\xBB\xBF/,""):R,[H,Z]=Xh(`${f}${P}`);for(const $ of H)E($);f=Z,p=!1}function E(R){if(R===""){M();return}if(R.startsWith(":")){u&&u(R.slice(R.startsWith(": ")?2:1));return}const P=R.indexOf(":");if(P!==-1){const H=R.slice(0,P),Z=R[P+1]===" "?2:1,$=R.slice(P+Z);L(H,$,R);return}L(R,"",R)}function L(R,P,H){switch(R){case"event":g=P;break;case"data":_=`${_}${P}
31
+ `;break;case"id":x=P.includes("\0")?void 0:P;break;case"retry":/^\d+$/.test(P)?c(parseInt(P,10)):o(new fa(`Invalid \`retry\` value: "${P}"`,{type:"invalid-retry",value:P,line:H}));break;default:o(new fa(`Unknown field "${R.length>20?`${R.slice(0,20)}…`:R}"`,{type:"unknown-field",field:R,value:P,line:H}));break}}function M(){_.length>0&&r({id:x,event:g||void 0,data:_.endsWith(`
32
+ `)?_.slice(0,-1):_}),x=void 0,_="",g=""}function D(R={}){f&&R.consume&&E(f),p=!0,x=void 0,_="",g="",f=""}return{feed:A,reset:D}}function Xh(t){const r=[];let o="",c=0;for(;c<t.length;){const u=t.indexOf("\r",c),f=t.indexOf(`
33
33
  `,c);let p=-1;if(u!==-1&&f!==-1?p=Math.min(u,f):u!==-1?u===t.length-1?p=-1:p=u:f!==-1&&(p=f),p===-1){o=t.slice(c);break}else{const x=t.slice(c,p);r.push(x),c=p+1,t[c-1]==="\r"&&t[c]===`
34
- `&&c++}}return[r,o]}class hc extends TransformStream{constructor({onError:r,onRetry:o,onComment:c}={}){let u;super({start(f){u=Wh({onEvent:p=>{f.enqueue(p)},onError(p){r==="terminate"?f.error(p):typeof r=="function"&&r(p)},onRetry:o,onComment:c})},transform(f){u.feed(f)}})}}function _n(...t){return t.reduce((r,o)=>({...r,...o??{}}),{})}function Xh({tools:t=[],providerToolNames:r}){const o={},c={};for(const u of t)if(u.type==="provider"&&u.id in r){const f=r[u.id];o[u.name]=f,c[f]=u.name}return{toProviderToolName:u=>{var f;return(f=o[u])!=null?f:u},toCustomToolName:u=>{var f;return(f=c[u])!=null?f:u}}}var qh=class{constructor(){this.status={type:"pending"},this._resolve=void 0,this._reject=void 0}get promise(){return this._promise?this._promise:(this._promise=new Promise((t,r)=>{this.status.type==="resolved"?t(this.status.value):this.status.type==="rejected"&&r(this.status.error),this._resolve=t,this._reject=r}),this._promise)}resolve(t){var r;this.status={type:"resolved",value:t},this._promise&&((r=this._resolve)==null||r.call(this,t))}reject(t){var r;this.status={type:"rejected",error:t},this._promise&&((r=this._reject)==null||r.call(this,t))}isResolved(){return this.status.type==="resolved"}isRejected(){return this.status.type==="rejected"}isPending(){return this.status.type==="pending"}};function ri(t){return Object.fromEntries([...t.headers])}var{btoa:Yh,atob:Jh}=globalThis;function Go(t){const r=t.replace(/-/g,"+").replace(/_/g,"/"),o=Jh(r);return Uint8Array.from(o,c=>c.codePointAt(0))}function Kh(t){let r="";for(let o=0;o<t.length;o++)r+=String.fromCodePoint(t[o]);return Yh(r)}function br(t){return t instanceof Uint8Array?Kh(t):t}function Qh(t,r={}){const{useArrayBrackets:o=!0}=r,c=new FormData;for(const[u,f]of Object.entries(t))if(f!=null){if(Array.isArray(f)){if(f.length===1){c.append(u,f[0]);continue}const p=o?`${u}[]`:u;for(const x of f)c.append(p,x);continue}c.append(u,f)}return c}var pc="AI_DownloadError",gc=`vercel.ai.error.${pc}`,ep=Symbol.for(gc),fa,ha,Gr=class extends(ha=gt,fa=ep,ha){constructor({url:t,statusCode:r,statusText:o,cause:c,message:u=c==null?`Failed to download ${t}: ${r} ${o}`:`Failed to download ${t}: ${c}`}){super({name:pc,message:u,cause:c}),this[fa]=!0,this.url=t,this.statusCode=r,this.statusText=o}static isInstance(t){return gt.hasMarker(t,gc)}},mc=2*1024*1024*1024;async function tp({response:t,url:r,maxBytes:o=mc}){const c=t.headers.get("content-length");if(c!=null){const A=parseInt(c,10);if(!isNaN(A)&&A>o)throw new Gr({url:r,message:`Download of ${r} exceeded maximum size of ${o} bytes (Content-Length: ${A}).`})}const u=t.body;if(u==null)return new Uint8Array(0);const f=u.getReader(),p=[];let x=0;try{for(;;){const{done:A,value:E}=await f.read();if(A)break;if(x+=E.length,x>o)throw new Gr({url:r,message:`Download of ${r} exceeded maximum size of ${o} bytes.`});p.push(E)}}finally{try{await f.cancel()}finally{f.releaseLock()}}const y=new Uint8Array(x);let m=0;for(const A of p)y.set(A,m),m+=A.length;return y}async function xc(t,r){var o,c;try{const u=await fetch(t,{signal:r?.abortSignal});if(!u.ok)throw new Gr({url:t,statusCode:u.status,statusText:u.statusText});const f=await tp({response:u,url:t,maxBytes:(o=r?.maxBytes)!=null?o:mc}),p=(c=u.headers.get("content-type"))!=null?c:void 0;return new Blob([f],p?{type:p}:void 0)}catch(u){throw Gr.isInstance(u)?u:new Gr({url:t,cause:u})}}var ii=({prefix:t,size:r=16,alphabet:o="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",separator:c="-"}={})=>{const u=()=>{const f=o.length,p=new Array(r);for(let x=0;x<r;x++)p[x]=o[Math.random()*f|0];return p.join("")};if(t==null)return u;if(o.includes(c))throw new Il({argument:"separator",message:`The separator "${c}" must not be part of the alphabet "${o}".`});return()=>`${t}${c}${u()}`},Gt=ii();function So(t){return(t instanceof Error||t instanceof DOMException)&&(t.name==="AbortError"||t.name==="ResponseAborted"||t.name==="TimeoutError")}var np=["fetch failed","failed to fetch"],rp=["ConnectionRefused","ConnectionClosed","FailedToOpenSocket","ECONNRESET","ECONNREFUSED","ETIMEDOUT","EPIPE"];function ip(t){if(!(t instanceof Error))return!1;const r=t.code;return!!(typeof r=="string"&&rp.includes(r))}function op({error:t,url:r,requestBodyValues:o}){if(So(t))return t;if(t instanceof TypeError&&np.includes(t.message.toLowerCase())){const c=t.cause;if(c!=null)return new on({message:`Cannot connect to API: ${c.message}`,cause:c,url:r,requestBodyValues:o,isRetryable:!0})}return ip(t)?new on({message:`Cannot connect to API: ${t.message}`,cause:t,url:r,requestBodyValues:o,isRetryable:!0}):t}function sp(t=globalThis){var r,o,c;return t.window?"runtime/browser":(r=t.navigator)!=null&&r.userAgent?`runtime/${t.navigator.userAgent.toLowerCase()}`:(c=(o=t.process)==null?void 0:o.versions)!=null&&c.node?`runtime/node.js/${t.process.version.substring(0)}`:t.EdgeRuntime?"runtime/vercel-edge":"runtime/unknown"}function ap(t){if(t==null)return{};const r={};if(t instanceof Headers)t.forEach((o,c)=>{r[c.toLowerCase()]=o});else{Array.isArray(t)||(t=Object.entries(t));for(const[o,c]of t)c!=null&&(r[o.toLowerCase()]=c)}return r}function wc(t,...r){const o=new Headers(ap(t)),c=o.get("user-agent")||"";return o.set("user-agent",[c,...r].filter(Boolean).join(" ")),Object.fromEntries(o.entries())}var lp="4.0.15";function cp(t){return t!=null}function up({apiKey:t,environmentVariableName:r,apiKeyParameterName:o="apiKey",description:c}){if(typeof t=="string")return t;if(t!=null)throw new wi({message:`${c} API key must be a string.`});if(typeof process>"u")throw new wi({message:`${c} API key is missing. Pass it using the '${o}' parameter. Environment variables is not supported in this environment.`});if(t=process.env[r],t==null)throw new wi({message:`${c} API key is missing. Pass it using the '${o}' parameter or the ${r} environment variable.`});if(typeof t!="string")throw new wi({message:`${c} API key must be a string. The value of the ${r} environment variable is not a string.`});return t}function dp({settingValue:t,environmentVariableName:r}){if(typeof t=="string")return t;if(!(t!=null||typeof process>"u")&&(t=process.env[r],!(t==null||typeof t!="string")))return t}function fp(t){var r;const[o,c=""]=t.toLowerCase().split("/");return(r={mpeg:"mp3","x-wav":"wav",opus:"ogg",mp4:"m4a","x-m4a":"m4a"}[c])!=null?r:c}var hp=/"__proto__"\s*:/,pp=/"constructor"\s*:/;function pa(t){const r=JSON.parse(t);return r===null||typeof r!="object"||hp.test(t)===!1&&pp.test(t)===!1?r:gp(r)}function gp(t){let r=[t];for(;r.length;){const o=r;r=[];for(const c of o){if(Object.prototype.hasOwnProperty.call(c,"__proto__"))throw new SyntaxError("Object contains forbidden prototype property");if(Object.prototype.hasOwnProperty.call(c,"constructor")&&Object.prototype.hasOwnProperty.call(c.constructor,"prototype"))throw new SyntaxError("Object contains forbidden prototype property");for(const u in c){const f=c[u];f&&typeof f=="object"&&r.push(f)}}}return t}function Xo(t){const{stackTraceLimit:r}=Error;try{Error.stackTraceLimit=0}catch{return pa(t)}try{return pa(t)}finally{Error.stackTraceLimit=r}}function qo(t){if(t.type==="object"||Array.isArray(t.type)&&t.type.includes("object")){t.additionalProperties=!1;const{properties:o}=t;if(o!=null)for(const c of Object.keys(o))o[c]=nr(o[c])}t.items!=null&&(t.items=Array.isArray(t.items)?t.items.map(nr):nr(t.items)),t.anyOf!=null&&(t.anyOf=t.anyOf.map(nr)),t.allOf!=null&&(t.allOf=t.allOf.map(nr)),t.oneOf!=null&&(t.oneOf=t.oneOf.map(nr));const{definitions:r}=t;if(r!=null)for(const o of Object.keys(r))r[o]=nr(r[o]);return t}function nr(t){return typeof t=="boolean"?t:qo(t)}var mp=Symbol("Let zodToJsonSchema decide on which parser to use"),ga={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",strictUnions:!1,definitions:{},errorMessages:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref"},xp=t=>typeof t=="string"?{...ga,name:t}:{...ga,...t};function ln(){return{}}function wp(t,r){var o,c,u;const f={type:"array"};return(o=t.type)!=null&&o._def&&((u=(c=t.type)==null?void 0:c._def)==null?void 0:u.typeName)!==De.ZodAny&&(f.items=tt(t.type._def,{...r,currentPath:[...r.currentPath,"items"]})),t.minLength&&(f.minItems=t.minLength.value),t.maxLength&&(f.maxItems=t.maxLength.value),t.exactLength&&(f.minItems=t.exactLength.value,f.maxItems=t.exactLength.value),f}function yp(t){const r={type:"integer",format:"int64"};if(!t.checks)return r;for(const o of t.checks)switch(o.kind){case"min":o.inclusive?r.minimum=o.value:r.exclusiveMinimum=o.value;break;case"max":o.inclusive?r.maximum=o.value:r.exclusiveMaximum=o.value;break;case"multipleOf":r.multipleOf=o.value;break}return r}function _p(){return{type:"boolean"}}function yc(t,r){return tt(t.type._def,r)}var vp=(t,r)=>tt(t.innerType._def,r);function _c(t,r,o){const c=o??r.dateStrategy;if(Array.isArray(c))return{anyOf:c.map((u,f)=>_c(t,r,u))};switch(c){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return Cp(t)}}var Cp=t=>{const r={type:"integer",format:"unix-time"};for(const o of t.checks)switch(o.kind){case"min":r.minimum=o.value;break;case"max":r.maximum=o.value;break}return r};function bp(t,r){return{...tt(t.innerType._def,r),default:t.defaultValue()}}function Ep(t,r){return r.effectStrategy==="input"?tt(t.schema._def,r):ln()}function Ap(t){return{type:"string",enum:Array.from(t.values)}}var Ip=t=>"type"in t&&t.type==="string"?!1:"allOf"in t;function Sp(t,r){const o=[tt(t.left._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),tt(t.right._def,{...r,currentPath:[...r.currentPath,"allOf","1"]})].filter(u=>!!u),c=[];return o.forEach(u=>{if(Ip(u))c.push(...u.allOf);else{let f=u;if("additionalProperties"in u&&u.additionalProperties===!1){const{additionalProperties:p,...x}=u;f=x}c.push(f)}}),c.length?{allOf:c}:void 0}function Tp(t){const r=typeof t.value;return r!=="bigint"&&r!=="number"&&r!=="boolean"&&r!=="string"?{type:Array.isArray(t.value)?"array":"object"}:{type:r==="bigint"?"integer":r,const:t.value}}var go=void 0,xn={cuid:/^[cC][^\s-]{8,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,email:/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,emoji:()=>(go===void 0&&(go=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),go),uuid:/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv4Cidr:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,ipv6:/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,ipv6Cidr:/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64url:/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,jwt:/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/};function vc(t,r){const o={type:"string"};if(t.checks)for(const c of t.checks)switch(c.kind){case"min":o.minLength=typeof o.minLength=="number"?Math.max(o.minLength,c.value):c.value;break;case"max":o.maxLength=typeof o.maxLength=="number"?Math.min(o.maxLength,c.value):c.value;break;case"email":switch(r.emailStrategy){case"format:email":wn(o,"email",c.message,r);break;case"format:idn-email":wn(o,"idn-email",c.message,r);break;case"pattern:zod":Wt(o,xn.email,c.message,r);break}break;case"url":wn(o,"uri",c.message,r);break;case"uuid":wn(o,"uuid",c.message,r);break;case"regex":Wt(o,c.regex,c.message,r);break;case"cuid":Wt(o,xn.cuid,c.message,r);break;case"cuid2":Wt(o,xn.cuid2,c.message,r);break;case"startsWith":Wt(o,RegExp(`^${mo(c.value,r)}`),c.message,r);break;case"endsWith":Wt(o,RegExp(`${mo(c.value,r)}$`),c.message,r);break;case"datetime":wn(o,"date-time",c.message,r);break;case"date":wn(o,"date",c.message,r);break;case"time":wn(o,"time",c.message,r);break;case"duration":wn(o,"duration",c.message,r);break;case"length":o.minLength=typeof o.minLength=="number"?Math.max(o.minLength,c.value):c.value,o.maxLength=typeof o.maxLength=="number"?Math.min(o.maxLength,c.value):c.value;break;case"includes":{Wt(o,RegExp(mo(c.value,r)),c.message,r);break}case"ip":{c.version!=="v6"&&wn(o,"ipv4",c.message,r),c.version!=="v4"&&wn(o,"ipv6",c.message,r);break}case"base64url":Wt(o,xn.base64url,c.message,r);break;case"jwt":Wt(o,xn.jwt,c.message,r);break;case"cidr":{c.version!=="v6"&&Wt(o,xn.ipv4Cidr,c.message,r),c.version!=="v4"&&Wt(o,xn.ipv6Cidr,c.message,r);break}case"emoji":Wt(o,xn.emoji(),c.message,r);break;case"ulid":{Wt(o,xn.ulid,c.message,r);break}case"base64":{switch(r.base64Strategy){case"format:binary":{wn(o,"binary",c.message,r);break}case"contentEncoding:base64":{o.contentEncoding="base64";break}case"pattern:zod":{Wt(o,xn.base64,c.message,r);break}}break}case"nanoid":Wt(o,xn.nanoid,c.message,r)}return o}function mo(t,r){return r.patternStrategy==="escape"?Op(t):t}var Np=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function Op(t){let r="";for(let o=0;o<t.length;o++)Np.has(t[o])||(r+="\\"),r+=t[o];return r}function wn(t,r,o,c){var u;t.format||(u=t.anyOf)!=null&&u.some(f=>f.format)?(t.anyOf||(t.anyOf=[]),t.format&&(t.anyOf.push({format:t.format}),delete t.format),t.anyOf.push({format:r,...o&&c.errorMessages&&{errorMessage:{format:o}}})):t.format=r}function Wt(t,r,o,c){var u;t.pattern||(u=t.allOf)!=null&&u.some(f=>f.pattern)?(t.allOf||(t.allOf=[]),t.pattern&&(t.allOf.push({pattern:t.pattern}),delete t.pattern),t.allOf.push({pattern:ma(r,c),...o&&c.errorMessages&&{errorMessage:{pattern:o}}})):t.pattern=ma(r,c)}function ma(t,r){var o;if(!r.applyRegexFlags||!t.flags)return t.source;const c={i:t.flags.includes("i"),m:t.flags.includes("m"),s:t.flags.includes("s")},u=c.i?t.source.toLowerCase():t.source;let f="",p=!1,x=!1,y=!1;for(let m=0;m<u.length;m++){if(p){f+=u[m],p=!1;continue}if(c.i){if(x){if(u[m].match(/[a-z]/)){y?(f+=u[m],f+=`${u[m-2]}-${u[m]}`.toUpperCase(),y=!1):u[m+1]==="-"&&((o=u[m+2])!=null&&o.match(/[a-z]/))?(f+=u[m],y=!0):f+=`${u[m]}${u[m].toUpperCase()}`;continue}}else if(u[m].match(/[a-z]/)){f+=`[${u[m]}${u[m].toUpperCase()}]`;continue}}if(c.m){if(u[m]==="^"){f+=`(^|(?<=[\r
35
- ]))`;continue}else if(u[m]==="$"){f+=`($|(?=[\r
36
- ]))`;continue}}if(c.s&&u[m]==="."){f+=x?`${u[m]}\r
37
- `:`[${u[m]}\r
38
- ]`;continue}f+=u[m],u[m]==="\\"?p=!0:x&&u[m]==="]"?x=!1:!x&&u[m]==="["&&(x=!0)}try{new RegExp(f)}catch{return console.warn(`Could not convert regex pattern at ${r.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),t.source}return f}function Cc(t,r){var o,c,u,f,p,x;const y={type:"object",additionalProperties:(o=tt(t.valueType._def,{...r,currentPath:[...r.currentPath,"additionalProperties"]}))!=null?o:r.allowedAdditionalProperties};if(((c=t.keyType)==null?void 0:c._def.typeName)===De.ZodString&&((u=t.keyType._def.checks)!=null&&u.length)){const{type:m,...A}=vc(t.keyType._def,r);return{...y,propertyNames:A}}else{if(((f=t.keyType)==null?void 0:f._def.typeName)===De.ZodEnum)return{...y,propertyNames:{enum:t.keyType._def.values}};if(((p=t.keyType)==null?void 0:p._def.typeName)===De.ZodBranded&&t.keyType._def.type._def.typeName===De.ZodString&&((x=t.keyType._def.type._def.checks)!=null&&x.length)){const{type:m,...A}=yc(t.keyType._def,r);return{...y,propertyNames:A}}}return y}function kp(t,r){if(r.mapStrategy==="record")return Cc(t,r);const o=tt(t.keyType._def,{...r,currentPath:[...r.currentPath,"items","items","0"]})||ln(),c=tt(t.valueType._def,{...r,currentPath:[...r.currentPath,"items","items","1"]})||ln();return{type:"array",maxItems:125,items:{type:"array",items:[o,c],minItems:2,maxItems:2}}}function Rp(t){const r=t.values,c=Object.keys(t.values).filter(f=>typeof r[r[f]]!="number").map(f=>r[f]),u=Array.from(new Set(c.map(f=>typeof f)));return{type:u.length===1?u[0]==="string"?"string":"number":["string","number"],enum:c}}function Mp(){return{not:ln()}}function Dp(){return{type:"null"}}var To={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function Pp(t,r){const o=t.options instanceof Map?Array.from(t.options.values()):t.options;if(o.every(c=>c._def.typeName in To&&(!c._def.checks||!c._def.checks.length))){const c=o.reduce((u,f)=>{const p=To[f._def.typeName];return p&&!u.includes(p)?[...u,p]:u},[]);return{type:c.length>1?c:c[0]}}else if(o.every(c=>c._def.typeName==="ZodLiteral"&&!c.description)){const c=o.reduce((u,f)=>{const p=typeof f._def.value;switch(p){case"string":case"number":case"boolean":return[...u,p];case"bigint":return[...u,"integer"];case"object":if(f._def.value===null)return[...u,"null"];case"symbol":case"undefined":case"function":default:return u}},[]);if(c.length===o.length){const u=c.filter((f,p,x)=>x.indexOf(f)===p);return{type:u.length>1?u:u[0],enum:o.reduce((f,p)=>f.includes(p._def.value)?f:[...f,p._def.value],[])}}}else if(o.every(c=>c._def.typeName==="ZodEnum"))return{type:"string",enum:o.reduce((c,u)=>[...c,...u._def.values.filter(f=>!c.includes(f))],[])};return Bp(t,r)}var Bp=(t,r)=>{const o=(t.options instanceof Map?Array.from(t.options.values()):t.options).map((c,u)=>tt(c._def,{...r,currentPath:[...r.currentPath,"anyOf",`${u}`]})).filter(c=>!!c&&(!r.strictUnions||typeof c=="object"&&Object.keys(c).length>0));return o.length?{anyOf:o}:void 0};function Lp(t,r){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(t.innerType._def.typeName)&&(!t.innerType._def.checks||!t.innerType._def.checks.length))return{type:[To[t.innerType._def.typeName],"null"]};const o=tt(t.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","0"]});return o&&{anyOf:[o,{type:"null"}]}}function Fp(t){const r={type:"number"};if(!t.checks)return r;for(const o of t.checks)switch(o.kind){case"int":r.type="integer";break;case"min":o.inclusive?r.minimum=o.value:r.exclusiveMinimum=o.value;break;case"max":o.inclusive?r.maximum=o.value:r.exclusiveMaximum=o.value;break;case"multipleOf":r.multipleOf=o.value;break}return r}function Up(t,r){const o={type:"object",properties:{}},c=[],u=t.shape();for(const p in u){let x=u[p];if(x===void 0||x._def===void 0)continue;const y=Vp(x),m=tt(x._def,{...r,currentPath:[...r.currentPath,"properties",p],propertyPath:[...r.currentPath,"properties",p]});m!==void 0&&(o.properties[p]=m,y||c.push(p))}c.length&&(o.required=c);const f=zp(t,r);return f!==void 0&&(o.additionalProperties=f),o}function zp(t,r){if(t.catchall._def.typeName!=="ZodNever")return tt(t.catchall._def,{...r,currentPath:[...r.currentPath,"additionalProperties"]});switch(t.unknownKeys){case"passthrough":return r.allowedAdditionalProperties;case"strict":return r.rejectedAdditionalProperties;case"strip":return r.removeAdditionalStrategy==="strict"?r.allowedAdditionalProperties:r.rejectedAdditionalProperties}}function Vp(t){try{return t.isOptional()}catch{return!0}}var $p=(t,r)=>{var o;if(r.currentPath.toString()===((o=r.propertyPath)==null?void 0:o.toString()))return tt(t.innerType._def,r);const c=tt(t.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","1"]});return c?{anyOf:[{not:ln()},c]}:ln()},Zp=(t,r)=>{if(r.pipeStrategy==="input")return tt(t.in._def,r);if(r.pipeStrategy==="output")return tt(t.out._def,r);const o=tt(t.in._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),c=tt(t.out._def,{...r,currentPath:[...r.currentPath,"allOf",o?"1":"0"]});return{allOf:[o,c].filter(u=>u!==void 0)}};function jp(t,r){return tt(t.type._def,r)}function Hp(t,r){const c={type:"array",uniqueItems:!0,items:tt(t.valueType._def,{...r,currentPath:[...r.currentPath,"items"]})};return t.minSize&&(c.minItems=t.minSize.value),t.maxSize&&(c.maxItems=t.maxSize.value),c}function Wp(t,r){return t.rest?{type:"array",minItems:t.items.length,items:t.items.map((o,c)=>tt(o._def,{...r,currentPath:[...r.currentPath,"items",`${c}`]})).reduce((o,c)=>c===void 0?o:[...o,c],[]),additionalItems:tt(t.rest._def,{...r,currentPath:[...r.currentPath,"additionalItems"]})}:{type:"array",minItems:t.items.length,maxItems:t.items.length,items:t.items.map((o,c)=>tt(o._def,{...r,currentPath:[...r.currentPath,"items",`${c}`]})).reduce((o,c)=>c===void 0?o:[...o,c],[])}}function Gp(){return{not:ln()}}function Xp(){return ln()}var qp=(t,r)=>tt(t.innerType._def,r),Yp=(t,r,o)=>{switch(r){case De.ZodString:return vc(t,o);case De.ZodNumber:return Fp(t);case De.ZodObject:return Up(t,o);case De.ZodBigInt:return yp(t);case De.ZodBoolean:return _p();case De.ZodDate:return _c(t,o);case De.ZodUndefined:return Gp();case De.ZodNull:return Dp();case De.ZodArray:return wp(t,o);case De.ZodUnion:case De.ZodDiscriminatedUnion:return Pp(t,o);case De.ZodIntersection:return Sp(t,o);case De.ZodTuple:return Wp(t,o);case De.ZodRecord:return Cc(t,o);case De.ZodLiteral:return Tp(t);case De.ZodEnum:return Ap(t);case De.ZodNativeEnum:return Rp(t);case De.ZodNullable:return Lp(t,o);case De.ZodOptional:return $p(t,o);case De.ZodMap:return kp(t,o);case De.ZodSet:return Hp(t,o);case De.ZodLazy:return()=>t.getter()._def;case De.ZodPromise:return jp(t,o);case De.ZodNaN:case De.ZodNever:return Mp();case De.ZodEffects:return Ep(t,o);case De.ZodAny:return ln();case De.ZodUnknown:return Xp();case De.ZodDefault:return bp(t,o);case De.ZodBranded:return yc(t,o);case De.ZodReadonly:return qp(t,o);case De.ZodCatch:return vp(t,o);case De.ZodPipeline:return Zp(t,o);case De.ZodFunction:case De.ZodVoid:case De.ZodSymbol:return;default:return(c=>{})()}},Jp=(t,r)=>{let o=0;for(;o<t.length&&o<r.length&&t[o]===r[o];o++);return[(t.length-o).toString(),...r.slice(o)].join("/")};function tt(t,r,o=!1){var c;const u=r.seen.get(t);if(r.override){const y=(c=r.override)==null?void 0:c.call(r,t,r,u,o);if(y!==mp)return y}if(u&&!o){const y=Kp(u,r);if(y!==void 0)return y}const f={def:t,path:r.currentPath,jsonSchema:void 0};r.seen.set(t,f);const p=Yp(t,t.typeName,r),x=typeof p=="function"?tt(p(),r):p;if(x&&Qp(t,r,x),r.postProcess){const y=r.postProcess(x,t,r);return f.jsonSchema=x,y}return f.jsonSchema=x,x}var Kp=(t,r)=>{switch(r.$refStrategy){case"root":return{$ref:t.path.join("/")};case"relative":return{$ref:Jp(r.currentPath,t.path)};case"none":case"seen":return t.path.length<r.currentPath.length&&t.path.every((o,c)=>r.currentPath[c]===o)?(console.warn(`Recursive reference detected at ${r.currentPath.join("/")}! Defaulting to any`),ln()):r.$refStrategy==="seen"?ln():void 0}},Qp=(t,r,o)=>(t.description&&(o.description=t.description),o),eg=t=>{const r=xp(t),o=r.name!==void 0?[...r.basePath,r.definitionPath,r.name]:r.basePath;return{...r,currentPath:o,propertyPath:void 0,seen:new Map(Object.entries(r.definitions).map(([c,u])=>[u._def,{def:u._def,path:[...r.basePath,r.definitionPath,c],jsonSchema:void 0}]))}},tg=(t,r)=>{var o;const c=eg(r);let u=typeof r=="object"&&r.definitions?Object.entries(r.definitions).reduce((m,[A,E])=>{var B;return{...m,[A]:(B=tt(E._def,{...c,currentPath:[...c.basePath,c.definitionPath,A]},!0))!=null?B:ln()}},{}):void 0;const f=typeof r=="string"?r:r?.nameStrategy==="title"?void 0:r?.name,p=(o=tt(t._def,f===void 0?c:{...c,currentPath:[...c.basePath,c.definitionPath,f]},!1))!=null?o:ln(),x=typeof r=="object"&&r.name!==void 0&&r.nameStrategy==="title"?r.name:void 0;x!==void 0&&(p.title=x);const y=f===void 0?u?{...p,[c.definitionPath]:u}:p:{$ref:[...c.$refStrategy==="relative"?[]:c.basePath,c.definitionPath,f].join("/"),[c.definitionPath]:{...u,[f]:p}};return y.$schema="http://json-schema.org/draft-07/schema#",y},No=Symbol.for("vercel.ai.schema");function $e(t){let r;return()=>(r==null&&(r=t()),r)}function Vi(t,{validate:r}={}){return{[No]:!0,_type:void 0,get jsonSchema(){return typeof t=="function"&&(t=t()),t},validate:r}}function ng(t){return typeof t=="object"&&t!==null&&No in t&&t[No]===!0&&"jsonSchema"in t&&"validate"in t}function Yo(t){return t==null?Vi({properties:{},additionalProperties:!1}):ng(t)?t:"~standard"in t?t["~standard"].vendor==="zod"?Ve(t):rg(t):t()}function rg(t){return Vi(()=>qo(t["~standard"].jsonSchema.input({target:"draft-07"})),{validate:async r=>{const o=await t["~standard"].validate(r);return"value"in o?{success:!0,value:o.value}:{success:!1,error:new ar({value:r,cause:o.issues})}}})}function ig(t,r){var o;const c=(o=void 0)!=null?o:!1;return Vi(()=>tg(t,{$refStrategy:c?"root":"none"}),{validate:async u=>{const f=await t.safeParseAsync(u);return f.success?{success:!0,value:f.data}:{success:!1,error:f.error}}})}function og(t,r){var o;const c=(o=void 0)!=null?o:!1;return Vi(()=>qo(Bf(t,{target:"draft-7",io:"input",reused:c?"ref":"inline"})),{validate:async u=>{const f=await ac(t,u);return f.success?{success:!0,value:f.data}:{success:!1,error:f.error}}})}function sg(t){return"_zod"in t}function Ve(t,r){return sg(t)?og(t):ig(t)}async function rn({value:t,schema:r,context:o}){const c=await Sr({value:t,schema:r,context:o});if(!c.success)throw ar.wrap({value:t,cause:c.error,context:o});return c.value}async function Sr({value:t,schema:r,context:o}){const c=Yo(r);try{if(c.validate==null)return{success:!0,value:t,rawValue:t};const u=await c.validate(t);return u.success?{success:!0,value:u.value,rawValue:t}:{success:!1,error:ar.wrap({value:t,cause:u.error,context:o}),rawValue:t}}catch(u){return{success:!1,error:ar.wrap({value:t,cause:u,context:o}),rawValue:t}}}async function ag({text:t,schema:r}){try{const o=Xo(t);return r==null?o:rn({value:o,schema:r})}catch(o){throw Oi.isInstance(o)||ar.isInstance(o)?o:new Oi({text:t,cause:o})}}async function Gn({text:t,schema:r}){try{const o=Xo(t);return r==null?{success:!0,value:o,rawValue:o}:await Sr({value:o,schema:r})}catch(o){return{success:!1,error:Oi.isInstance(o)?o:new Oi({text:t,cause:o}),rawValue:void 0}}}function xa(t){try{return Xo(t),!0}catch{return!1}}function lg({stream:t,schema:r}){return t.pipeThrough(new TextDecoderStream).pipeThrough(new hc).pipeThrough(new TransformStream({async transform({data:o},c){o!=="[DONE]"&&c.enqueue(await Gn({text:o,schema:r}))}}))}async function Dn({provider:t,providerOptions:r,schema:o}){if(r?.[t]==null)return;const c=await Sr({value:r[t],schema:o});if(!c.success)throw new Il({argument:"providerOptions",message:`invalid ${t} provider options`,cause:c.error});return c.value}var cg=()=>globalThis.fetch,Pn=async({url:t,headers:r,body:o,failedResponseHandler:c,successfulResponseHandler:u,abortSignal:f,fetch:p})=>Ec({url:t,headers:{"Content-Type":"application/json",...r},body:{content:JSON.stringify(o),values:o},failedResponseHandler:c,successfulResponseHandler:u,abortSignal:f,fetch:p}),bc=async({url:t,headers:r,formData:o,failedResponseHandler:c,successfulResponseHandler:u,abortSignal:f,fetch:p})=>Ec({url:t,headers:r,body:{content:o,values:Object.fromEntries(o.entries())},failedResponseHandler:c,successfulResponseHandler:u,abortSignal:f,fetch:p}),Ec=async({url:t,headers:r={},body:o,successfulResponseHandler:c,failedResponseHandler:u,abortSignal:f,fetch:p=cg()})=>{try{const x=await p(t,{method:"POST",headers:wc(r,`ai-sdk/provider-utils/${lp}`,sp()),body:o.content,signal:f}),y=ri(x);if(!x.ok){let m;try{m=await u({response:x,url:t,requestBodyValues:o.values})}catch(A){throw So(A)||on.isInstance(A)?A:new on({message:"Failed to process error response",cause:A,statusCode:x.status,url:t,responseHeaders:y,requestBodyValues:o.values})}throw m.value}try{return await c({response:x,url:t,requestBodyValues:o.values})}catch(m){throw m instanceof Error&&(So(m)||on.isInstance(m))?m:new on({message:"Failed to process successful response",cause:m,statusCode:x.status,url:t,responseHeaders:y,requestBodyValues:o.values})}}catch(x){throw op({error:x,url:t,requestBodyValues:o.values})}};function Bn({id:t,inputSchema:r,outputSchema:o,supportsDeferredResults:c}){return({execute:u,needsApproval:f,toModelOutput:p,onInputStart:x,onInputDelta:y,onInputAvailable:m,...A})=>({type:"provider",id:t,args:A,inputSchema:r,outputSchema:o,execute:u,needsApproval:f,toModelOutput:p,onInputStart:x,onInputDelta:y,onInputAvailable:m,supportsDeferredResults:c})}async function Ac(t){return typeof t=="function"&&(t=t()),Promise.resolve(t)}var ug=({errorSchema:t,errorToMessage:r,isRetryable:o})=>async({response:c,url:u,requestBodyValues:f})=>{const p=await c.text(),x=ri(c);if(p.trim()==="")return{responseHeaders:x,value:new on({message:c.statusText,url:u,requestBodyValues:f,statusCode:c.status,responseHeaders:x,responseBody:p,isRetryable:o?.(c)})};try{const y=await ag({text:p,schema:t});return{responseHeaders:x,value:new on({message:r(y),url:u,requestBodyValues:f,statusCode:c.status,responseHeaders:x,responseBody:p,data:y,isRetryable:o?.(c,y)})}}catch{return{responseHeaders:x,value:new on({message:c.statusText,url:u,requestBodyValues:f,statusCode:c.status,responseHeaders:x,responseBody:p,isRetryable:o?.(c)})}}},Jo=t=>async({response:r})=>{const o=ri(r);if(r.body==null)throw new Nd({});return{responseHeaders:o,value:lg({stream:r.body,schema:t})}},lr=t=>async({response:r,url:o,requestBodyValues:c})=>{const u=await r.text(),f=await Gn({text:u,schema:t}),p=ri(r);if(!f.success)throw new on({message:"Invalid JSON response",cause:f.error,statusCode:r.status,responseHeaders:p,responseBody:u,url:o,requestBodyValues:c});return{responseHeaders:p,value:f.value,rawValue:f.rawValue}},dg=()=>async({response:t,url:r,requestBodyValues:o})=>{const c=ri(t);if(!t.body)throw new on({message:"Response body is empty",url:r,requestBodyValues:o,statusCode:t.status,responseHeaders:c,responseBody:void 0});try{const u=await t.arrayBuffer();return{responseHeaders:c,value:new Uint8Array(u)}}catch(u){throw new on({message:"Failed to read response as array buffer",url:r,requestBodyValues:o,statusCode:t.status,responseHeaders:c,responseBody:void 0,cause:u})}};function fg(t){return t?.replace(/\/$/,"")}var Ci=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ic(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var hg=Object.defineProperty,pg=(t,r)=>{for(var o in r)hg(t,o,{get:r[o],enumerable:!0})},Sc="AI_NoObjectGeneratedError",Tc=`vercel.ai.error.${Sc}`,gg=Symbol.for(Tc),Nc,jn=class extends gt{constructor({message:t="No object generated.",cause:r,text:o,response:c,usage:u,finishReason:f}){super({name:Sc,message:t,cause:r}),this[Nc]=!0,this.text=o,this.response=c,this.usage=u,this.finishReason=f}static isInstance(t){return gt.hasMarker(t,Tc)}};Nc=gg;var Oc=Le([_(),Di(Uint8Array),Di(ArrayBuffer),$h(t=>{var r,o;return(o=(r=globalThis.Buffer)==null?void 0:r.isBuffer(t))!=null?o:!1},{message:"Must be a Buffer"})]),Jr=Ho(()=>Le([cc(),_(),X(),At(),pt(_(),Jr.optional()),me(Jr)])),wt=pt(_(),pt(_(),Jr.optional())),kc=T({type:Y("text"),text:_(),providerOptions:wt.optional()}),mg=T({type:Y("image"),image:Le([Oc,Di(URL)]),mediaType:_().optional(),providerOptions:wt.optional()}),Rc=T({type:Y("file"),data:Le([Oc,Di(URL)]),filename:_().optional(),mediaType:_(),providerOptions:wt.optional()}),xg=T({type:Y("reasoning"),text:_(),providerOptions:wt.optional()}),wg=T({type:Y("tool-call"),toolCallId:_(),toolName:_(),input:Ir(),providerOptions:wt.optional(),providerExecuted:At().optional()}),yg=Et("type",[T({type:Y("text"),value:_(),providerOptions:wt.optional()}),T({type:Y("json"),value:Jr,providerOptions:wt.optional()}),T({type:Y("execution-denied"),reason:_().optional(),providerOptions:wt.optional()}),T({type:Y("error-text"),value:_(),providerOptions:wt.optional()}),T({type:Y("error-json"),value:Jr,providerOptions:wt.optional()}),T({type:Y("content"),value:me(Le([T({type:Y("text"),text:_(),providerOptions:wt.optional()}),T({type:Y("media"),data:_(),mediaType:_()}),T({type:Y("file-data"),data:_(),mediaType:_(),filename:_().optional(),providerOptions:wt.optional()}),T({type:Y("file-url"),url:_(),providerOptions:wt.optional()}),T({type:Y("file-id"),fileId:Le([_(),pt(_(),_())]),providerOptions:wt.optional()}),T({type:Y("image-data"),data:_(),mediaType:_(),providerOptions:wt.optional()}),T({type:Y("image-url"),url:_(),providerOptions:wt.optional()}),T({type:Y("image-file-id"),fileId:Le([_(),pt(_(),_())]),providerOptions:wt.optional()}),T({type:Y("custom"),providerOptions:wt.optional()})]))})]),Mc=T({type:Y("tool-result"),toolCallId:_(),toolName:_(),output:yg,providerOptions:wt.optional()}),_g=T({type:Y("tool-approval-request"),approvalId:_(),toolCallId:_()}),vg=T({type:Y("tool-approval-response"),approvalId:_(),approved:At(),reason:_().optional()}),Cg=T({role:Y("system"),content:_(),providerOptions:wt.optional()}),bg=T({role:Y("user"),content:Le([_(),me(Le([kc,mg,Rc]))]),providerOptions:wt.optional()}),Eg=T({role:Y("assistant"),content:Le([_(),me(Le([kc,Rc,xg,wg,Mc,_g]))]),providerOptions:wt.optional()}),Ag=T({role:Y("tool"),content:me(Le([Mc,vg])),providerOptions:wt.optional()});Le([Cg,bg,Eg,Ag]);var Ig={};pg(Ig,{array:()=>Og,choice:()=>kg,json:()=>Rg,object:()=>Ng,text:()=>Tg});function Sg(t){const r=["ROOT"];let o=-1,c=null;function u(y,m,A){switch(y){case'"':{o=m,r.pop(),r.push(A),r.push("INSIDE_STRING");break}case"f":case"t":case"n":{o=m,c=m,r.pop(),r.push(A),r.push("INSIDE_LITERAL");break}case"-":{r.pop(),r.push(A),r.push("INSIDE_NUMBER");break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{o=m,r.pop(),r.push(A),r.push("INSIDE_NUMBER");break}case"{":{o=m,r.pop(),r.push(A),r.push("INSIDE_OBJECT_START");break}case"[":{o=m,r.pop(),r.push(A),r.push("INSIDE_ARRAY_START");break}}}function f(y,m){switch(y){case",":{r.pop(),r.push("INSIDE_OBJECT_AFTER_COMMA");break}case"}":{o=m,r.pop();break}}}function p(y,m){switch(y){case",":{r.pop(),r.push("INSIDE_ARRAY_AFTER_COMMA");break}case"]":{o=m,r.pop();break}}}for(let y=0;y<t.length;y++){const m=t[y];switch(r[r.length-1]){case"ROOT":u(m,y,"FINISH");break;case"INSIDE_OBJECT_START":{switch(m){case'"':{r.pop(),r.push("INSIDE_OBJECT_KEY");break}case"}":{o=y,r.pop();break}}break}case"INSIDE_OBJECT_AFTER_COMMA":{switch(m){case'"':{r.pop(),r.push("INSIDE_OBJECT_KEY");break}}break}case"INSIDE_OBJECT_KEY":{switch(m){case'"':{r.pop(),r.push("INSIDE_OBJECT_AFTER_KEY");break}}break}case"INSIDE_OBJECT_AFTER_KEY":{switch(m){case":":{r.pop(),r.push("INSIDE_OBJECT_BEFORE_VALUE");break}}break}case"INSIDE_OBJECT_BEFORE_VALUE":{u(m,y,"INSIDE_OBJECT_AFTER_VALUE");break}case"INSIDE_OBJECT_AFTER_VALUE":{f(m,y);break}case"INSIDE_STRING":{switch(m){case'"':{r.pop(),o=y;break}case"\\":{r.push("INSIDE_STRING_ESCAPE");break}default:o=y}break}case"INSIDE_ARRAY_START":{switch(m){case"]":{o=y,r.pop();break}default:{o=y,u(m,y,"INSIDE_ARRAY_AFTER_VALUE");break}}break}case"INSIDE_ARRAY_AFTER_VALUE":{switch(m){case",":{r.pop(),r.push("INSIDE_ARRAY_AFTER_COMMA");break}case"]":{o=y,r.pop();break}default:{o=y;break}}break}case"INSIDE_ARRAY_AFTER_COMMA":{u(m,y,"INSIDE_ARRAY_AFTER_VALUE");break}case"INSIDE_STRING_ESCAPE":{r.pop(),o=y;break}case"INSIDE_NUMBER":{switch(m){case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{o=y;break}case"e":case"E":case"-":case".":break;case",":{r.pop(),r[r.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&p(m,y),r[r.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&f(m,y);break}case"}":{r.pop(),r[r.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&f(m,y);break}case"]":{r.pop(),r[r.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&p(m,y);break}default:{r.pop();break}}break}case"INSIDE_LITERAL":{const E=t.substring(c,y+1);!"false".startsWith(E)&&!"true".startsWith(E)&&!"null".startsWith(E)?(r.pop(),r[r.length-1]==="INSIDE_OBJECT_AFTER_VALUE"?f(m,y):r[r.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&p(m,y)):o=y;break}}}let x=t.slice(0,o+1);for(let y=r.length-1;y>=0;y--)switch(r[y]){case"INSIDE_STRING":{x+='"';break}case"INSIDE_OBJECT_KEY":case"INSIDE_OBJECT_AFTER_KEY":case"INSIDE_OBJECT_AFTER_COMMA":case"INSIDE_OBJECT_START":case"INSIDE_OBJECT_BEFORE_VALUE":case"INSIDE_OBJECT_AFTER_VALUE":{x+="}";break}case"INSIDE_ARRAY_START":case"INSIDE_ARRAY_AFTER_COMMA":case"INSIDE_ARRAY_AFTER_VALUE":{x+="]";break}case"INSIDE_LITERAL":{const A=t.substring(c,t.length);"true".startsWith(A)?x+="true".slice(A.length):"false".startsWith(A)?x+="false".slice(A.length):"null".startsWith(A)&&(x+="null".slice(A.length))}}return x}async function $i(t){if(t===void 0)return{value:void 0,state:"undefined-input"};let r=await Gn({text:t});return r.success?{value:r.value,state:"successful-parse"}:(r=await Gn({text:Sg(t)}),r.success?{value:r.value,state:"repaired-parse"}:{value:void 0,state:"failed-parse"})}var Tg=()=>({name:"text",responseFormat:Promise.resolve({type:"text"}),async parseCompleteOutput({text:t}){return t},async parsePartialOutput({text:t}){return{partial:t}},createElementStreamTransform(){}}),Ng=({schema:t,name:r,description:o})=>{const c=Yo(t);return{name:"object",responseFormat:Ac(c.jsonSchema).then(u=>({type:"json",schema:u,...r!=null&&{name:r},...o!=null&&{description:o}})),async parseCompleteOutput({text:u},f){const p=await Gn({text:u});if(!p.success)throw new jn({message:"No object generated: could not parse the response.",cause:p.error,text:u,response:f.response,usage:f.usage,finishReason:f.finishReason});const x=await Sr({value:p.value,schema:c});if(!x.success)throw new jn({message:"No object generated: response did not match schema.",cause:x.error,text:u,response:f.response,usage:f.usage,finishReason:f.finishReason});return x.value},async parsePartialOutput({text:u}){const f=await $i(u);switch(f.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":return{partial:f.value}}},createElementStreamTransform(){}}},Og=({element:t,name:r,description:o})=>{const c=Yo(t);return{name:"array",responseFormat:Ac(c.jsonSchema).then(u=>{const{$schema:f,...p}=u;return{type:"json",schema:{$schema:"http://json-schema.org/draft-07/schema#",type:"object",properties:{elements:{type:"array",items:p}},required:["elements"],additionalProperties:!1},...r!=null&&{name:r},...o!=null&&{description:o}}}),async parseCompleteOutput({text:u},f){const p=await Gn({text:u});if(!p.success)throw new jn({message:"No object generated: could not parse the response.",cause:p.error,text:u,response:f.response,usage:f.usage,finishReason:f.finishReason});const x=p.value;if(x==null||typeof x!="object"||!("elements"in x)||!Array.isArray(x.elements))throw new jn({message:"No object generated: response did not match schema.",cause:new ar({value:x,cause:"response must be an object with an elements array"}),text:u,response:f.response,usage:f.usage,finishReason:f.finishReason});for(const y of x.elements){const m=await Sr({value:y,schema:c});if(!m.success)throw new jn({message:"No object generated: response did not match schema.",cause:m.error,text:u,response:f.response,usage:f.usage,finishReason:f.finishReason})}return x.elements},async parsePartialOutput({text:u}){const f=await $i(u);switch(f.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":{const p=f.value;if(p==null||typeof p!="object"||!("elements"in p)||!Array.isArray(p.elements))return;const x=f.state==="repaired-parse"&&p.elements.length>0?p.elements.slice(0,-1):p.elements,y=[];for(const m of x){const A=await Sr({value:m,schema:c});A.success&&y.push(A.value)}return{partial:y}}}},createElementStreamTransform(){let u=0;return new TransformStream({transform({partialOutput:f},p){if(f!=null)for(;u<f.length;u++)p.enqueue(f[u])}})}}},kg=({options:t,name:r,description:o})=>({name:"choice",responseFormat:Promise.resolve({type:"json",schema:{$schema:"http://json-schema.org/draft-07/schema#",type:"object",properties:{result:{type:"string",enum:t}},required:["result"],additionalProperties:!1},...r!=null&&{name:r},...o!=null&&{description:o}}),async parseCompleteOutput({text:c},u){const f=await Gn({text:c});if(!f.success)throw new jn({message:"No object generated: could not parse the response.",cause:f.error,text:c,response:u.response,usage:u.usage,finishReason:u.finishReason});const p=f.value;if(p==null||typeof p!="object"||!("result"in p)||typeof p.result!="string"||!t.includes(p.result))throw new jn({message:"No object generated: response did not match schema.",cause:new ar({value:p,cause:"response must be an object that contains a choice value."}),text:c,response:u.response,usage:u.usage,finishReason:u.finishReason});return p.result},async parsePartialOutput({text:c}){const u=await $i(c);switch(u.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":{const f=u.value;if(f==null||typeof f!="object"||!("result"in f)||typeof f.result!="string")return;const p=t.filter(x=>x.startsWith(f.result));return u.state==="successful-parse"?p.includes(f.result)?{partial:f.result}:void 0:p.length===1?{partial:p[0]}:void 0}}},createElementStreamTransform(){}}),Rg=({name:t,description:r}={})=>({name:"json",responseFormat:Promise.resolve({type:"json",...t!=null&&{name:t},...r!=null&&{description:r}}),async parseCompleteOutput({text:o},c){const u=await Gn({text:o});if(!u.success)throw new jn({message:"No object generated: could not parse the response.",cause:u.error,text:o,response:c.response,usage:c.usage,finishReason:c.finishReason});return u.value},async parsePartialOutput({text:o}){const c=await $i(o);switch(c.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":return c.value===void 0?void 0:{partial:c.value}}},createElementStreamTransform(){}});ii({prefix:"aitxt",size:24});(class extends TransformStream{constructor(){super({transform(t,r){r.enqueue(`data: ${JSON.stringify(t)}
34
+ `&&c++}}return[r,o]}class mc extends TransformStream{constructor({onError:r,onRetry:o,onComment:c}={}){let u;super({start(f){u=Gh({onEvent:p=>{f.enqueue(p)},onError(p){r==="terminate"?f.error(p):typeof r=="function"&&r(p)},onRetry:o,onComment:c})},transform(f){u.feed(f)}})}}function Cn(...t){return t.reduce((r,o)=>({...r,...o??{}}),{})}function qh({tools:t=[],providerToolNames:r}){const o={},c={};for(const u of t)if(u.type==="provider"&&u.id in r){const f=r[u.id];o[u.name]=f,c[f]=u.name}return{toProviderToolName:u=>{var f;return(f=o[u])!=null?f:u},toCustomToolName:u=>{var f;return(f=c[u])!=null?f:u}}}var Yh=class{constructor(){this.status={type:"pending"},this._resolve=void 0,this._reject=void 0}get promise(){return this._promise?this._promise:(this._promise=new Promise((t,r)=>{this.status.type==="resolved"?t(this.status.value):this.status.type==="rejected"&&r(this.status.error),this._resolve=t,this._reject=r}),this._promise)}resolve(t){var r;this.status={type:"resolved",value:t},this._promise&&((r=this._resolve)==null||r.call(this,t))}reject(t){var r;this.status={type:"rejected",error:t},this._promise&&((r=this._reject)==null||r.call(this,t))}isResolved(){return this.status.type==="resolved"}isRejected(){return this.status.type==="rejected"}isPending(){return this.status.type==="pending"}};function ii(t){return Object.fromEntries([...t.headers])}var{btoa:Jh,atob:Kh}=globalThis;function Xo(t){const r=t.replace(/-/g,"+").replace(/_/g,"/"),o=Kh(r);return Uint8Array.from(o,c=>c.codePointAt(0))}function Qh(t){let r="";for(let o=0;o<t.length;o++)r+=String.fromCodePoint(t[o]);return Jh(r)}function Ar(t){return t instanceof Uint8Array?Qh(t):t}function ep(t,r={}){const{useArrayBrackets:o=!0}=r,c=new FormData;for(const[u,f]of Object.entries(t))if(f!=null){if(Array.isArray(f)){if(f.length===1){c.append(u,f[0]);continue}const p=o?`${u}[]`:u;for(const x of f)c.append(p,x);continue}c.append(u,f)}return c}var gc="AI_DownloadError",xc=`vercel.ai.error.${gc}`,tp=Symbol.for(xc),ha,pa,Xr=class extends(pa=xt,ha=tp,pa){constructor({url:t,statusCode:r,statusText:o,cause:c,message:u=c==null?`Failed to download ${t}: ${r} ${o}`:`Failed to download ${t}: ${c}`}){super({name:gc,message:u,cause:c}),this[ha]=!0,this.url=t,this.statusCode=r,this.statusText=o}static isInstance(t){return xt.hasMarker(t,xc)}},yc=2*1024*1024*1024;async function np({response:t,url:r,maxBytes:o=yc}){const c=t.headers.get("content-length");if(c!=null){const A=parseInt(c,10);if(!isNaN(A)&&A>o)throw new Xr({url:r,message:`Download of ${r} exceeded maximum size of ${o} bytes (Content-Length: ${A}).`})}const u=t.body;if(u==null)return new Uint8Array(0);const f=u.getReader(),p=[];let x=0;try{for(;;){const{done:A,value:E}=await f.read();if(A)break;if(x+=E.length,x>o)throw new Xr({url:r,message:`Download of ${r} exceeded maximum size of ${o} bytes.`});p.push(E)}}finally{try{await f.cancel()}finally{f.releaseLock()}}const _=new Uint8Array(x);let g=0;for(const A of p)_.set(A,g),g+=A.length;return _}async function wc(t,r){var o,c;try{const u=await fetch(t,{signal:r?.abortSignal});if(!u.ok)throw new Xr({url:t,statusCode:u.status,statusText:u.statusText});const f=await np({response:u,url:t,maxBytes:(o=r?.maxBytes)!=null?o:yc}),p=(c=u.headers.get("content-type"))!=null?c:void 0;return new Blob([f],p?{type:p}:void 0)}catch(u){throw Xr.isInstance(u)?u:new Xr({url:t,cause:u})}}var oi=({prefix:t,size:r=16,alphabet:o="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",separator:c="-"}={})=>{const u=()=>{const f=o.length,p=new Array(r);for(let x=0;x<r;x++)p[x]=o[Math.random()*f|0];return p.join("")};if(t==null)return u;if(o.includes(c))throw new Tl({argument:"separator",message:`The separator "${c}" must not be part of the alphabet "${o}".`});return()=>`${t}${c}${u()}`},qt=oi();function So(t){return(t instanceof Error||t instanceof DOMException)&&(t.name==="AbortError"||t.name==="ResponseAborted"||t.name==="TimeoutError")}var rp=["fetch failed","failed to fetch"],ip=["ConnectionRefused","ConnectionClosed","FailedToOpenSocket","ECONNRESET","ECONNREFUSED","ETIMEDOUT","EPIPE"];function op(t){if(!(t instanceof Error))return!1;const r=t.code;return!!(typeof r=="string"&&ip.includes(r))}function sp({error:t,url:r,requestBodyValues:o}){if(So(t))return t;if(t instanceof TypeError&&rp.includes(t.message.toLowerCase())){const c=t.cause;if(c!=null)return new an({message:`Cannot connect to API: ${c.message}`,cause:c,url:r,requestBodyValues:o,isRetryable:!0})}return op(t)?new an({message:`Cannot connect to API: ${t.message}`,cause:t,url:r,requestBodyValues:o,isRetryable:!0}):t}function ap(t=globalThis){var r,o,c;return t.window?"runtime/browser":(r=t.navigator)!=null&&r.userAgent?`runtime/${t.navigator.userAgent.toLowerCase()}`:(c=(o=t.process)==null?void 0:o.versions)!=null&&c.node?`runtime/node.js/${t.process.version.substring(0)}`:t.EdgeRuntime?"runtime/vercel-edge":"runtime/unknown"}function lp(t){if(t==null)return{};const r={};if(t instanceof Headers)t.forEach((o,c)=>{r[c.toLowerCase()]=o});else{Array.isArray(t)||(t=Object.entries(t));for(const[o,c]of t)c!=null&&(r[o.toLowerCase()]=c)}return r}function _c(t,...r){const o=new Headers(lp(t)),c=o.get("user-agent")||"";return o.set("user-agent",[c,...r].filter(Boolean).join(" ")),Object.fromEntries(o.entries())}var cp="4.0.15";function up(t){return t!=null}function dp({apiKey:t,environmentVariableName:r,apiKeyParameterName:o="apiKey",description:c}){if(typeof t=="string")return t;if(t!=null)throw new yi({message:`${c} API key must be a string.`});if(typeof process>"u")throw new yi({message:`${c} API key is missing. Pass it using the '${o}' parameter. Environment variables is not supported in this environment.`});if(t=process.env[r],t==null)throw new yi({message:`${c} API key is missing. Pass it using the '${o}' parameter or the ${r} environment variable.`});if(typeof t!="string")throw new yi({message:`${c} API key must be a string. The value of the ${r} environment variable is not a string.`});return t}function fp({settingValue:t,environmentVariableName:r}){if(typeof t=="string")return t;if(!(t!=null||typeof process>"u")&&(t=process.env[r],!(t==null||typeof t!="string")))return t}function hp(t){var r;const[o,c=""]=t.toLowerCase().split("/");return(r={mpeg:"mp3","x-wav":"wav",opus:"ogg",mp4:"m4a","x-m4a":"m4a"}[c])!=null?r:c}var pp=/"__proto__"\s*:/,mp=/"constructor"\s*:/;function ma(t){const r=JSON.parse(t);return r===null||typeof r!="object"||pp.test(t)===!1&&mp.test(t)===!1?r:gp(r)}function gp(t){let r=[t];for(;r.length;){const o=r;r=[];for(const c of o){if(Object.prototype.hasOwnProperty.call(c,"__proto__"))throw new SyntaxError("Object contains forbidden prototype property");if(Object.prototype.hasOwnProperty.call(c,"constructor")&&Object.prototype.hasOwnProperty.call(c.constructor,"prototype"))throw new SyntaxError("Object contains forbidden prototype property");for(const u in c){const f=c[u];f&&typeof f=="object"&&r.push(f)}}}return t}function qo(t){const{stackTraceLimit:r}=Error;try{Error.stackTraceLimit=0}catch{return ma(t)}try{return ma(t)}finally{Error.stackTraceLimit=r}}function Yo(t){if(t.type==="object"||Array.isArray(t.type)&&t.type.includes("object")){t.additionalProperties=!1;const{properties:o}=t;if(o!=null)for(const c of Object.keys(o))o[c]=or(o[c])}t.items!=null&&(t.items=Array.isArray(t.items)?t.items.map(or):or(t.items)),t.anyOf!=null&&(t.anyOf=t.anyOf.map(or)),t.allOf!=null&&(t.allOf=t.allOf.map(or)),t.oneOf!=null&&(t.oneOf=t.oneOf.map(or));const{definitions:r}=t;if(r!=null)for(const o of Object.keys(r))r[o]=or(r[o]);return t}function or(t){return typeof t=="boolean"?t:Yo(t)}var xp=Symbol("Let zodToJsonSchema decide on which parser to use"),ga={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",strictUnions:!1,definitions:{},errorMessages:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref"},yp=t=>typeof t=="string"?{...ga,name:t}:{...ga,...t};function un(){return{}}function wp(t,r){var o,c,u;const f={type:"array"};return(o=t.type)!=null&&o._def&&((u=(c=t.type)==null?void 0:c._def)==null?void 0:u.typeName)!==Re.ZodAny&&(f.items=nt(t.type._def,{...r,currentPath:[...r.currentPath,"items"]})),t.minLength&&(f.minItems=t.minLength.value),t.maxLength&&(f.maxItems=t.maxLength.value),t.exactLength&&(f.minItems=t.exactLength.value,f.maxItems=t.exactLength.value),f}function _p(t){const r={type:"integer",format:"int64"};if(!t.checks)return r;for(const o of t.checks)switch(o.kind){case"min":o.inclusive?r.minimum=o.value:r.exclusiveMinimum=o.value;break;case"max":o.inclusive?r.maximum=o.value:r.exclusiveMaximum=o.value;break;case"multipleOf":r.multipleOf=o.value;break}return r}function vp(){return{type:"boolean"}}function vc(t,r){return nt(t.type._def,r)}var Cp=(t,r)=>nt(t.innerType._def,r);function Cc(t,r,o){const c=o??r.dateStrategy;if(Array.isArray(c))return{anyOf:c.map((u,f)=>Cc(t,r,u))};switch(c){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return bp(t)}}var bp=t=>{const r={type:"integer",format:"unix-time"};for(const o of t.checks)switch(o.kind){case"min":r.minimum=o.value;break;case"max":r.maximum=o.value;break}return r};function Ep(t,r){return{...nt(t.innerType._def,r),default:t.defaultValue()}}function Ap(t,r){return r.effectStrategy==="input"?nt(t.schema._def,r):un()}function Ip(t){return{type:"string",enum:Array.from(t.values)}}var Sp=t=>"type"in t&&t.type==="string"?!1:"allOf"in t;function Tp(t,r){const o=[nt(t.left._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),nt(t.right._def,{...r,currentPath:[...r.currentPath,"allOf","1"]})].filter(u=>!!u),c=[];return o.forEach(u=>{if(Sp(u))c.push(...u.allOf);else{let f=u;if("additionalProperties"in u&&u.additionalProperties===!1){const{additionalProperties:p,...x}=u;f=x}c.push(f)}}),c.length?{allOf:c}:void 0}function Np(t){const r=typeof t.value;return r!=="bigint"&&r!=="number"&&r!=="boolean"&&r!=="string"?{type:Array.isArray(t.value)?"array":"object"}:{type:r==="bigint"?"integer":r,const:t.value}}var mo=void 0,wn={cuid:/^[cC][^\s-]{8,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,email:/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,emoji:()=>(mo===void 0&&(mo=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),mo),uuid:/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv4Cidr:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,ipv6:/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,ipv6Cidr:/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64url:/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,jwt:/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/};function bc(t,r){const o={type:"string"};if(t.checks)for(const c of t.checks)switch(c.kind){case"min":o.minLength=typeof o.minLength=="number"?Math.max(o.minLength,c.value):c.value;break;case"max":o.maxLength=typeof o.maxLength=="number"?Math.min(o.maxLength,c.value):c.value;break;case"email":switch(r.emailStrategy){case"format:email":_n(o,"email",c.message,r);break;case"format:idn-email":_n(o,"idn-email",c.message,r);break;case"pattern:zod":Xt(o,wn.email,c.message,r);break}break;case"url":_n(o,"uri",c.message,r);break;case"uuid":_n(o,"uuid",c.message,r);break;case"regex":Xt(o,c.regex,c.message,r);break;case"cuid":Xt(o,wn.cuid,c.message,r);break;case"cuid2":Xt(o,wn.cuid2,c.message,r);break;case"startsWith":Xt(o,RegExp(`^${go(c.value,r)}`),c.message,r);break;case"endsWith":Xt(o,RegExp(`${go(c.value,r)}$`),c.message,r);break;case"datetime":_n(o,"date-time",c.message,r);break;case"date":_n(o,"date",c.message,r);break;case"time":_n(o,"time",c.message,r);break;case"duration":_n(o,"duration",c.message,r);break;case"length":o.minLength=typeof o.minLength=="number"?Math.max(o.minLength,c.value):c.value,o.maxLength=typeof o.maxLength=="number"?Math.min(o.maxLength,c.value):c.value;break;case"includes":{Xt(o,RegExp(go(c.value,r)),c.message,r);break}case"ip":{c.version!=="v6"&&_n(o,"ipv4",c.message,r),c.version!=="v4"&&_n(o,"ipv6",c.message,r);break}case"base64url":Xt(o,wn.base64url,c.message,r);break;case"jwt":Xt(o,wn.jwt,c.message,r);break;case"cidr":{c.version!=="v6"&&Xt(o,wn.ipv4Cidr,c.message,r),c.version!=="v4"&&Xt(o,wn.ipv6Cidr,c.message,r);break}case"emoji":Xt(o,wn.emoji(),c.message,r);break;case"ulid":{Xt(o,wn.ulid,c.message,r);break}case"base64":{switch(r.base64Strategy){case"format:binary":{_n(o,"binary",c.message,r);break}case"contentEncoding:base64":{o.contentEncoding="base64";break}case"pattern:zod":{Xt(o,wn.base64,c.message,r);break}}break}case"nanoid":Xt(o,wn.nanoid,c.message,r)}return o}function go(t,r){return r.patternStrategy==="escape"?kp(t):t}var Op=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function kp(t){let r="";for(let o=0;o<t.length;o++)Op.has(t[o])||(r+="\\"),r+=t[o];return r}function _n(t,r,o,c){var u;t.format||(u=t.anyOf)!=null&&u.some(f=>f.format)?(t.anyOf||(t.anyOf=[]),t.format&&(t.anyOf.push({format:t.format}),delete t.format),t.anyOf.push({format:r,...o&&c.errorMessages&&{errorMessage:{format:o}}})):t.format=r}function Xt(t,r,o,c){var u;t.pattern||(u=t.allOf)!=null&&u.some(f=>f.pattern)?(t.allOf||(t.allOf=[]),t.pattern&&(t.allOf.push({pattern:t.pattern}),delete t.pattern),t.allOf.push({pattern:xa(r,c),...o&&c.errorMessages&&{errorMessage:{pattern:o}}})):t.pattern=xa(r,c)}function xa(t,r){var o;if(!r.applyRegexFlags||!t.flags)return t.source;const c={i:t.flags.includes("i"),m:t.flags.includes("m"),s:t.flags.includes("s")},u=c.i?t.source.toLowerCase():t.source;let f="",p=!1,x=!1,_=!1;for(let g=0;g<u.length;g++){if(p){f+=u[g],p=!1;continue}if(c.i){if(x){if(u[g].match(/[a-z]/)){_?(f+=u[g],f+=`${u[g-2]}-${u[g]}`.toUpperCase(),_=!1):u[g+1]==="-"&&((o=u[g+2])!=null&&o.match(/[a-z]/))?(f+=u[g],_=!0):f+=`${u[g]}${u[g].toUpperCase()}`;continue}}else if(u[g].match(/[a-z]/)){f+=`[${u[g]}${u[g].toUpperCase()}]`;continue}}if(c.m){if(u[g]==="^"){f+=`(^|(?<=[\r
35
+ ]))`;continue}else if(u[g]==="$"){f+=`($|(?=[\r
36
+ ]))`;continue}}if(c.s&&u[g]==="."){f+=x?`${u[g]}\r
37
+ `:`[${u[g]}\r
38
+ ]`;continue}f+=u[g],u[g]==="\\"?p=!0:x&&u[g]==="]"?x=!1:!x&&u[g]==="["&&(x=!0)}try{new RegExp(f)}catch{return console.warn(`Could not convert regex pattern at ${r.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),t.source}return f}function Ec(t,r){var o,c,u,f,p,x;const _={type:"object",additionalProperties:(o=nt(t.valueType._def,{...r,currentPath:[...r.currentPath,"additionalProperties"]}))!=null?o:r.allowedAdditionalProperties};if(((c=t.keyType)==null?void 0:c._def.typeName)===Re.ZodString&&((u=t.keyType._def.checks)!=null&&u.length)){const{type:g,...A}=bc(t.keyType._def,r);return{..._,propertyNames:A}}else{if(((f=t.keyType)==null?void 0:f._def.typeName)===Re.ZodEnum)return{..._,propertyNames:{enum:t.keyType._def.values}};if(((p=t.keyType)==null?void 0:p._def.typeName)===Re.ZodBranded&&t.keyType._def.type._def.typeName===Re.ZodString&&((x=t.keyType._def.type._def.checks)!=null&&x.length)){const{type:g,...A}=vc(t.keyType._def,r);return{..._,propertyNames:A}}}return _}function Rp(t,r){if(r.mapStrategy==="record")return Ec(t,r);const o=nt(t.keyType._def,{...r,currentPath:[...r.currentPath,"items","items","0"]})||un(),c=nt(t.valueType._def,{...r,currentPath:[...r.currentPath,"items","items","1"]})||un();return{type:"array",maxItems:125,items:{type:"array",items:[o,c],minItems:2,maxItems:2}}}function Mp(t){const r=t.values,c=Object.keys(t.values).filter(f=>typeof r[r[f]]!="number").map(f=>r[f]),u=Array.from(new Set(c.map(f=>typeof f)));return{type:u.length===1?u[0]==="string"?"string":"number":["string","number"],enum:c}}function Dp(){return{not:un()}}function Pp(){return{type:"null"}}var To={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function Bp(t,r){const o=t.options instanceof Map?Array.from(t.options.values()):t.options;if(o.every(c=>c._def.typeName in To&&(!c._def.checks||!c._def.checks.length))){const c=o.reduce((u,f)=>{const p=To[f._def.typeName];return p&&!u.includes(p)?[...u,p]:u},[]);return{type:c.length>1?c:c[0]}}else if(o.every(c=>c._def.typeName==="ZodLiteral"&&!c.description)){const c=o.reduce((u,f)=>{const p=typeof f._def.value;switch(p){case"string":case"number":case"boolean":return[...u,p];case"bigint":return[...u,"integer"];case"object":if(f._def.value===null)return[...u,"null"];case"symbol":case"undefined":case"function":default:return u}},[]);if(c.length===o.length){const u=c.filter((f,p,x)=>x.indexOf(f)===p);return{type:u.length>1?u:u[0],enum:o.reduce((f,p)=>f.includes(p._def.value)?f:[...f,p._def.value],[])}}}else if(o.every(c=>c._def.typeName==="ZodEnum"))return{type:"string",enum:o.reduce((c,u)=>[...c,...u._def.values.filter(f=>!c.includes(f))],[])};return Lp(t,r)}var Lp=(t,r)=>{const o=(t.options instanceof Map?Array.from(t.options.values()):t.options).map((c,u)=>nt(c._def,{...r,currentPath:[...r.currentPath,"anyOf",`${u}`]})).filter(c=>!!c&&(!r.strictUnions||typeof c=="object"&&Object.keys(c).length>0));return o.length?{anyOf:o}:void 0};function Fp(t,r){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(t.innerType._def.typeName)&&(!t.innerType._def.checks||!t.innerType._def.checks.length))return{type:[To[t.innerType._def.typeName],"null"]};const o=nt(t.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","0"]});return o&&{anyOf:[o,{type:"null"}]}}function Up(t){const r={type:"number"};if(!t.checks)return r;for(const o of t.checks)switch(o.kind){case"int":r.type="integer";break;case"min":o.inclusive?r.minimum=o.value:r.exclusiveMinimum=o.value;break;case"max":o.inclusive?r.maximum=o.value:r.exclusiveMaximum=o.value;break;case"multipleOf":r.multipleOf=o.value;break}return r}function zp(t,r){const o={type:"object",properties:{}},c=[],u=t.shape();for(const p in u){let x=u[p];if(x===void 0||x._def===void 0)continue;const _=$p(x),g=nt(x._def,{...r,currentPath:[...r.currentPath,"properties",p],propertyPath:[...r.currentPath,"properties",p]});g!==void 0&&(o.properties[p]=g,_||c.push(p))}c.length&&(o.required=c);const f=Vp(t,r);return f!==void 0&&(o.additionalProperties=f),o}function Vp(t,r){if(t.catchall._def.typeName!=="ZodNever")return nt(t.catchall._def,{...r,currentPath:[...r.currentPath,"additionalProperties"]});switch(t.unknownKeys){case"passthrough":return r.allowedAdditionalProperties;case"strict":return r.rejectedAdditionalProperties;case"strip":return r.removeAdditionalStrategy==="strict"?r.allowedAdditionalProperties:r.rejectedAdditionalProperties}}function $p(t){try{return t.isOptional()}catch{return!0}}var Zp=(t,r)=>{var o;if(r.currentPath.toString()===((o=r.propertyPath)==null?void 0:o.toString()))return nt(t.innerType._def,r);const c=nt(t.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","1"]});return c?{anyOf:[{not:un()},c]}:un()},jp=(t,r)=>{if(r.pipeStrategy==="input")return nt(t.in._def,r);if(r.pipeStrategy==="output")return nt(t.out._def,r);const o=nt(t.in._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),c=nt(t.out._def,{...r,currentPath:[...r.currentPath,"allOf",o?"1":"0"]});return{allOf:[o,c].filter(u=>u!==void 0)}};function Hp(t,r){return nt(t.type._def,r)}function Wp(t,r){const c={type:"array",uniqueItems:!0,items:nt(t.valueType._def,{...r,currentPath:[...r.currentPath,"items"]})};return t.minSize&&(c.minItems=t.minSize.value),t.maxSize&&(c.maxItems=t.maxSize.value),c}function Gp(t,r){return t.rest?{type:"array",minItems:t.items.length,items:t.items.map((o,c)=>nt(o._def,{...r,currentPath:[...r.currentPath,"items",`${c}`]})).reduce((o,c)=>c===void 0?o:[...o,c],[]),additionalItems:nt(t.rest._def,{...r,currentPath:[...r.currentPath,"additionalItems"]})}:{type:"array",minItems:t.items.length,maxItems:t.items.length,items:t.items.map((o,c)=>nt(o._def,{...r,currentPath:[...r.currentPath,"items",`${c}`]})).reduce((o,c)=>c===void 0?o:[...o,c],[])}}function Xp(){return{not:un()}}function qp(){return un()}var Yp=(t,r)=>nt(t.innerType._def,r),Jp=(t,r,o)=>{switch(r){case Re.ZodString:return bc(t,o);case Re.ZodNumber:return Up(t);case Re.ZodObject:return zp(t,o);case Re.ZodBigInt:return _p(t);case Re.ZodBoolean:return vp();case Re.ZodDate:return Cc(t,o);case Re.ZodUndefined:return Xp();case Re.ZodNull:return Pp();case Re.ZodArray:return wp(t,o);case Re.ZodUnion:case Re.ZodDiscriminatedUnion:return Bp(t,o);case Re.ZodIntersection:return Tp(t,o);case Re.ZodTuple:return Gp(t,o);case Re.ZodRecord:return Ec(t,o);case Re.ZodLiteral:return Np(t);case Re.ZodEnum:return Ip(t);case Re.ZodNativeEnum:return Mp(t);case Re.ZodNullable:return Fp(t,o);case Re.ZodOptional:return Zp(t,o);case Re.ZodMap:return Rp(t,o);case Re.ZodSet:return Wp(t,o);case Re.ZodLazy:return()=>t.getter()._def;case Re.ZodPromise:return Hp(t,o);case Re.ZodNaN:case Re.ZodNever:return Dp();case Re.ZodEffects:return Ap(t,o);case Re.ZodAny:return un();case Re.ZodUnknown:return qp();case Re.ZodDefault:return Ep(t,o);case Re.ZodBranded:return vc(t,o);case Re.ZodReadonly:return Yp(t,o);case Re.ZodCatch:return Cp(t,o);case Re.ZodPipeline:return jp(t,o);case Re.ZodFunction:case Re.ZodVoid:case Re.ZodSymbol:return;default:return(c=>{})()}},Kp=(t,r)=>{let o=0;for(;o<t.length&&o<r.length&&t[o]===r[o];o++);return[(t.length-o).toString(),...r.slice(o)].join("/")};function nt(t,r,o=!1){var c;const u=r.seen.get(t);if(r.override){const _=(c=r.override)==null?void 0:c.call(r,t,r,u,o);if(_!==xp)return _}if(u&&!o){const _=Qp(u,r);if(_!==void 0)return _}const f={def:t,path:r.currentPath,jsonSchema:void 0};r.seen.set(t,f);const p=Jp(t,t.typeName,r),x=typeof p=="function"?nt(p(),r):p;if(x&&em(t,r,x),r.postProcess){const _=r.postProcess(x,t,r);return f.jsonSchema=x,_}return f.jsonSchema=x,x}var Qp=(t,r)=>{switch(r.$refStrategy){case"root":return{$ref:t.path.join("/")};case"relative":return{$ref:Kp(r.currentPath,t.path)};case"none":case"seen":return t.path.length<r.currentPath.length&&t.path.every((o,c)=>r.currentPath[c]===o)?(console.warn(`Recursive reference detected at ${r.currentPath.join("/")}! Defaulting to any`),un()):r.$refStrategy==="seen"?un():void 0}},em=(t,r,o)=>(t.description&&(o.description=t.description),o),tm=t=>{const r=yp(t),o=r.name!==void 0?[...r.basePath,r.definitionPath,r.name]:r.basePath;return{...r,currentPath:o,propertyPath:void 0,seen:new Map(Object.entries(r.definitions).map(([c,u])=>[u._def,{def:u._def,path:[...r.basePath,r.definitionPath,c],jsonSchema:void 0}]))}},nm=(t,r)=>{var o;const c=tm(r);let u=typeof r=="object"&&r.definitions?Object.entries(r.definitions).reduce((g,[A,E])=>{var L;return{...g,[A]:(L=nt(E._def,{...c,currentPath:[...c.basePath,c.definitionPath,A]},!0))!=null?L:un()}},{}):void 0;const f=typeof r=="string"?r:r?.nameStrategy==="title"?void 0:r?.name,p=(o=nt(t._def,f===void 0?c:{...c,currentPath:[...c.basePath,c.definitionPath,f]},!1))!=null?o:un(),x=typeof r=="object"&&r.name!==void 0&&r.nameStrategy==="title"?r.name:void 0;x!==void 0&&(p.title=x);const _=f===void 0?u?{...p,[c.definitionPath]:u}:p:{$ref:[...c.$refStrategy==="relative"?[]:c.basePath,c.definitionPath,f].join("/"),[c.definitionPath]:{...u,[f]:p}};return _.$schema="http://json-schema.org/draft-07/schema#",_},No=Symbol.for("vercel.ai.schema");function $e(t){let r;return()=>(r==null&&(r=t()),r)}function Vi(t,{validate:r}={}){return{[No]:!0,_type:void 0,get jsonSchema(){return typeof t=="function"&&(t=t()),t},validate:r}}function rm(t){return typeof t=="object"&&t!==null&&No in t&&t[No]===!0&&"jsonSchema"in t&&"validate"in t}function Jo(t){return t==null?Vi({properties:{},additionalProperties:!1}):rm(t)?t:"~standard"in t?t["~standard"].vendor==="zod"?ze(t):im(t):t()}function im(t){return Vi(()=>Yo(t["~standard"].jsonSchema.input({target:"draft-07"})),{validate:async r=>{const o=await t["~standard"].validate(r);return"value"in o?{success:!0,value:o.value}:{success:!1,error:new ur({value:r,cause:o.issues})}}})}function om(t,r){var o;const c=(o=void 0)!=null?o:!1;return Vi(()=>nm(t,{$refStrategy:c?"root":"none"}),{validate:async u=>{const f=await t.safeParseAsync(u);return f.success?{success:!0,value:f.data}:{success:!1,error:f.error}}})}function sm(t,r){var o;const c=(o=void 0)!=null?o:!1;return Vi(()=>Yo(Lf(t,{target:"draft-7",io:"input",reused:c?"ref":"inline"})),{validate:async u=>{const f=await cc(t,u);return f.success?{success:!0,value:f.data}:{success:!1,error:f.error}}})}function am(t){return"_zod"in t}function ze(t,r){return am(t)?sm(t):om(t)}async function Yt({value:t,schema:r,context:o}){const c=await Nr({value:t,schema:r,context:o});if(!c.success)throw ur.wrap({value:t,cause:c.error,context:o});return c.value}async function Nr({value:t,schema:r,context:o}){const c=Jo(r);try{if(c.validate==null)return{success:!0,value:t,rawValue:t};const u=await c.validate(t);return u.success?{success:!0,value:u.value,rawValue:t}:{success:!1,error:ur.wrap({value:t,cause:u.error,context:o}),rawValue:t}}catch(u){return{success:!1,error:ur.wrap({value:t,cause:u,context:o}),rawValue:t}}}async function lm({text:t,schema:r}){try{const o=qo(t);return r==null?o:Yt({value:o,schema:r})}catch(o){throw Oi.isInstance(o)||ur.isInstance(o)?o:new Oi({text:t,cause:o})}}async function Yn({text:t,schema:r}){try{const o=qo(t);return r==null?{success:!0,value:o,rawValue:o}:await Nr({value:o,schema:r})}catch(o){return{success:!1,error:Oi.isInstance(o)?o:new Oi({text:t,cause:o}),rawValue:void 0}}}function ya(t){try{return qo(t),!0}catch{return!1}}function cm({stream:t,schema:r}){return t.pipeThrough(new TextDecoderStream).pipeThrough(new mc).pipeThrough(new TransformStream({async transform({data:o},c){o!=="[DONE]"&&c.enqueue(await Yn({text:o,schema:r}))}}))}async function Bn({provider:t,providerOptions:r,schema:o}){if(r?.[t]==null)return;const c=await Nr({value:r[t],schema:o});if(!c.success)throw new Tl({argument:"providerOptions",message:`invalid ${t} provider options`,cause:c.error});return c.value}var um=()=>globalThis.fetch,Ln=async({url:t,headers:r,body:o,failedResponseHandler:c,successfulResponseHandler:u,abortSignal:f,fetch:p})=>Ic({url:t,headers:{"Content-Type":"application/json",...r},body:{content:JSON.stringify(o),values:o},failedResponseHandler:c,successfulResponseHandler:u,abortSignal:f,fetch:p}),Ac=async({url:t,headers:r,formData:o,failedResponseHandler:c,successfulResponseHandler:u,abortSignal:f,fetch:p})=>Ic({url:t,headers:r,body:{content:o,values:Object.fromEntries(o.entries())},failedResponseHandler:c,successfulResponseHandler:u,abortSignal:f,fetch:p}),Ic=async({url:t,headers:r={},body:o,successfulResponseHandler:c,failedResponseHandler:u,abortSignal:f,fetch:p=um()})=>{try{const x=await p(t,{method:"POST",headers:_c(r,`ai-sdk/provider-utils/${cp}`,ap()),body:o.content,signal:f}),_=ii(x);if(!x.ok){let g;try{g=await u({response:x,url:t,requestBodyValues:o.values})}catch(A){throw So(A)||an.isInstance(A)?A:new an({message:"Failed to process error response",cause:A,statusCode:x.status,url:t,responseHeaders:_,requestBodyValues:o.values})}throw g.value}try{return await c({response:x,url:t,requestBodyValues:o.values})}catch(g){throw g instanceof Error&&(So(g)||an.isInstance(g))?g:new an({message:"Failed to process successful response",cause:g,statusCode:x.status,url:t,responseHeaders:_,requestBodyValues:o.values})}}catch(x){throw sp({error:x,url:t,requestBodyValues:o.values})}};function Fn({id:t,inputSchema:r,outputSchema:o,supportsDeferredResults:c}){return({execute:u,needsApproval:f,toModelOutput:p,onInputStart:x,onInputDelta:_,onInputAvailable:g,...A})=>({type:"provider",id:t,args:A,inputSchema:r,outputSchema:o,execute:u,needsApproval:f,toModelOutput:p,onInputStart:x,onInputDelta:_,onInputAvailable:g,supportsDeferredResults:c})}async function Sc(t){return typeof t=="function"&&(t=t()),Promise.resolve(t)}var dm=({errorSchema:t,errorToMessage:r,isRetryable:o})=>async({response:c,url:u,requestBodyValues:f})=>{const p=await c.text(),x=ii(c);if(p.trim()==="")return{responseHeaders:x,value:new an({message:c.statusText,url:u,requestBodyValues:f,statusCode:c.status,responseHeaders:x,responseBody:p,isRetryable:o?.(c)})};try{const _=await lm({text:p,schema:t});return{responseHeaders:x,value:new an({message:r(_),url:u,requestBodyValues:f,statusCode:c.status,responseHeaders:x,responseBody:p,data:_,isRetryable:o?.(c,_)})}}catch{return{responseHeaders:x,value:new an({message:c.statusText,url:u,requestBodyValues:f,statusCode:c.status,responseHeaders:x,responseBody:p,isRetryable:o?.(c)})}}},Ko=t=>async({response:r})=>{const o=ii(r);if(r.body==null)throw new Od({});return{responseHeaders:o,value:cm({stream:r.body,schema:t})}},dr=t=>async({response:r,url:o,requestBodyValues:c})=>{const u=await r.text(),f=await Yn({text:u,schema:t}),p=ii(r);if(!f.success)throw new an({message:"Invalid JSON response",cause:f.error,statusCode:r.status,responseHeaders:p,responseBody:u,url:o,requestBodyValues:c});return{responseHeaders:p,value:f.value,rawValue:f.rawValue}},fm=()=>async({response:t,url:r,requestBodyValues:o})=>{const c=ii(t);if(!t.body)throw new an({message:"Response body is empty",url:r,requestBodyValues:o,statusCode:t.status,responseHeaders:c,responseBody:void 0});try{const u=await t.arrayBuffer();return{responseHeaders:c,value:new Uint8Array(u)}}catch(u){throw new an({message:"Failed to read response as array buffer",url:r,requestBodyValues:o,statusCode:t.status,responseHeaders:c,responseBody:void 0,cause:u})}};function hm(t){return t?.replace(/\/$/,"")}var Ci=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Tc(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var pm=Object.defineProperty,mm=(t,r)=>{for(var o in r)pm(t,o,{get:r[o],enumerable:!0})},Nc="AI_NoObjectGeneratedError",Oc=`vercel.ai.error.${Nc}`,gm=Symbol.for(Oc),kc,Gn=class extends xt{constructor({message:t="No object generated.",cause:r,text:o,response:c,usage:u,finishReason:f}){super({name:Nc,message:t,cause:r}),this[kc]=!0,this.text=o,this.response=c,this.usage=u,this.finishReason=f}static isInstance(t){return xt.hasMarker(t,Oc)}};kc=gm;var Rc=Pe([w(),Di(Uint8Array),Di(ArrayBuffer),Zh(t=>{var r,o;return(o=(r=globalThis.Buffer)==null?void 0:r.isBuffer(t))!=null?o:!1},{message:"Must be a Buffer"})]),Kr=Wo(()=>Pe([dc(),w(),Y(),Nt(),gt(w(),Kr.optional()),me(Kr)])),Ct=gt(w(),gt(w(),Kr.optional())),Mc=S({type:W("text"),text:w(),providerOptions:Ct.optional()}),xm=S({type:W("image"),image:Pe([Rc,Di(URL)]),mediaType:w().optional(),providerOptions:Ct.optional()}),Dc=S({type:W("file"),data:Pe([Rc,Di(URL)]),filename:w().optional(),mediaType:w(),providerOptions:Ct.optional()}),ym=S({type:W("reasoning"),text:w(),providerOptions:Ct.optional()}),wm=S({type:W("tool-call"),toolCallId:w(),toolName:w(),input:Tr(),providerOptions:Ct.optional(),providerExecuted:Nt().optional()}),_m=lt("type",[S({type:W("text"),value:w(),providerOptions:Ct.optional()}),S({type:W("json"),value:Kr,providerOptions:Ct.optional()}),S({type:W("execution-denied"),reason:w().optional(),providerOptions:Ct.optional()}),S({type:W("error-text"),value:w(),providerOptions:Ct.optional()}),S({type:W("error-json"),value:Kr,providerOptions:Ct.optional()}),S({type:W("content"),value:me(Pe([S({type:W("text"),text:w(),providerOptions:Ct.optional()}),S({type:W("media"),data:w(),mediaType:w()}),S({type:W("file-data"),data:w(),mediaType:w(),filename:w().optional(),providerOptions:Ct.optional()}),S({type:W("file-url"),url:w(),providerOptions:Ct.optional()}),S({type:W("file-id"),fileId:Pe([w(),gt(w(),w())]),providerOptions:Ct.optional()}),S({type:W("image-data"),data:w(),mediaType:w(),providerOptions:Ct.optional()}),S({type:W("image-url"),url:w(),providerOptions:Ct.optional()}),S({type:W("image-file-id"),fileId:Pe([w(),gt(w(),w())]),providerOptions:Ct.optional()}),S({type:W("custom"),providerOptions:Ct.optional()})]))})]),Pc=S({type:W("tool-result"),toolCallId:w(),toolName:w(),output:_m,providerOptions:Ct.optional()}),vm=S({type:W("tool-approval-request"),approvalId:w(),toolCallId:w()}),Cm=S({type:W("tool-approval-response"),approvalId:w(),approved:Nt(),reason:w().optional()}),bm=S({role:W("system"),content:w(),providerOptions:Ct.optional()}),Em=S({role:W("user"),content:Pe([w(),me(Pe([Mc,xm,Dc]))]),providerOptions:Ct.optional()}),Am=S({role:W("assistant"),content:Pe([w(),me(Pe([Mc,Dc,ym,wm,Pc,vm]))]),providerOptions:Ct.optional()}),Im=S({role:W("tool"),content:me(Pe([Pc,Cm])),providerOptions:Ct.optional()});Pe([bm,Em,Am,Im]);var Sm={};mm(Sm,{array:()=>km,choice:()=>Rm,json:()=>Mm,object:()=>Om,text:()=>Nm});function Tm(t){const r=["ROOT"];let o=-1,c=null;function u(_,g,A){switch(_){case'"':{o=g,r.pop(),r.push(A),r.push("INSIDE_STRING");break}case"f":case"t":case"n":{o=g,c=g,r.pop(),r.push(A),r.push("INSIDE_LITERAL");break}case"-":{r.pop(),r.push(A),r.push("INSIDE_NUMBER");break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{o=g,r.pop(),r.push(A),r.push("INSIDE_NUMBER");break}case"{":{o=g,r.pop(),r.push(A),r.push("INSIDE_OBJECT_START");break}case"[":{o=g,r.pop(),r.push(A),r.push("INSIDE_ARRAY_START");break}}}function f(_,g){switch(_){case",":{r.pop(),r.push("INSIDE_OBJECT_AFTER_COMMA");break}case"}":{o=g,r.pop();break}}}function p(_,g){switch(_){case",":{r.pop(),r.push("INSIDE_ARRAY_AFTER_COMMA");break}case"]":{o=g,r.pop();break}}}for(let _=0;_<t.length;_++){const g=t[_];switch(r[r.length-1]){case"ROOT":u(g,_,"FINISH");break;case"INSIDE_OBJECT_START":{switch(g){case'"':{r.pop(),r.push("INSIDE_OBJECT_KEY");break}case"}":{o=_,r.pop();break}}break}case"INSIDE_OBJECT_AFTER_COMMA":{switch(g){case'"':{r.pop(),r.push("INSIDE_OBJECT_KEY");break}}break}case"INSIDE_OBJECT_KEY":{switch(g){case'"':{r.pop(),r.push("INSIDE_OBJECT_AFTER_KEY");break}}break}case"INSIDE_OBJECT_AFTER_KEY":{switch(g){case":":{r.pop(),r.push("INSIDE_OBJECT_BEFORE_VALUE");break}}break}case"INSIDE_OBJECT_BEFORE_VALUE":{u(g,_,"INSIDE_OBJECT_AFTER_VALUE");break}case"INSIDE_OBJECT_AFTER_VALUE":{f(g,_);break}case"INSIDE_STRING":{switch(g){case'"':{r.pop(),o=_;break}case"\\":{r.push("INSIDE_STRING_ESCAPE");break}default:o=_}break}case"INSIDE_ARRAY_START":{switch(g){case"]":{o=_,r.pop();break}default:{o=_,u(g,_,"INSIDE_ARRAY_AFTER_VALUE");break}}break}case"INSIDE_ARRAY_AFTER_VALUE":{switch(g){case",":{r.pop(),r.push("INSIDE_ARRAY_AFTER_COMMA");break}case"]":{o=_,r.pop();break}default:{o=_;break}}break}case"INSIDE_ARRAY_AFTER_COMMA":{u(g,_,"INSIDE_ARRAY_AFTER_VALUE");break}case"INSIDE_STRING_ESCAPE":{r.pop(),o=_;break}case"INSIDE_NUMBER":{switch(g){case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{o=_;break}case"e":case"E":case"-":case".":break;case",":{r.pop(),r[r.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&p(g,_),r[r.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&f(g,_);break}case"}":{r.pop(),r[r.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&f(g,_);break}case"]":{r.pop(),r[r.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&p(g,_);break}default:{r.pop();break}}break}case"INSIDE_LITERAL":{const E=t.substring(c,_+1);!"false".startsWith(E)&&!"true".startsWith(E)&&!"null".startsWith(E)?(r.pop(),r[r.length-1]==="INSIDE_OBJECT_AFTER_VALUE"?f(g,_):r[r.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&p(g,_)):o=_;break}}}let x=t.slice(0,o+1);for(let _=r.length-1;_>=0;_--)switch(r[_]){case"INSIDE_STRING":{x+='"';break}case"INSIDE_OBJECT_KEY":case"INSIDE_OBJECT_AFTER_KEY":case"INSIDE_OBJECT_AFTER_COMMA":case"INSIDE_OBJECT_START":case"INSIDE_OBJECT_BEFORE_VALUE":case"INSIDE_OBJECT_AFTER_VALUE":{x+="}";break}case"INSIDE_ARRAY_START":case"INSIDE_ARRAY_AFTER_COMMA":case"INSIDE_ARRAY_AFTER_VALUE":{x+="]";break}case"INSIDE_LITERAL":{const A=t.substring(c,t.length);"true".startsWith(A)?x+="true".slice(A.length):"false".startsWith(A)?x+="false".slice(A.length):"null".startsWith(A)&&(x+="null".slice(A.length))}}return x}async function $i(t){if(t===void 0)return{value:void 0,state:"undefined-input"};let r=await Yn({text:t});return r.success?{value:r.value,state:"successful-parse"}:(r=await Yn({text:Tm(t)}),r.success?{value:r.value,state:"repaired-parse"}:{value:void 0,state:"failed-parse"})}var Nm=()=>({name:"text",responseFormat:Promise.resolve({type:"text"}),async parseCompleteOutput({text:t}){return t},async parsePartialOutput({text:t}){return{partial:t}},createElementStreamTransform(){}}),Om=({schema:t,name:r,description:o})=>{const c=Jo(t);return{name:"object",responseFormat:Sc(c.jsonSchema).then(u=>({type:"json",schema:u,...r!=null&&{name:r},...o!=null&&{description:o}})),async parseCompleteOutput({text:u},f){const p=await Yn({text:u});if(!p.success)throw new Gn({message:"No object generated: could not parse the response.",cause:p.error,text:u,response:f.response,usage:f.usage,finishReason:f.finishReason});const x=await Nr({value:p.value,schema:c});if(!x.success)throw new Gn({message:"No object generated: response did not match schema.",cause:x.error,text:u,response:f.response,usage:f.usage,finishReason:f.finishReason});return x.value},async parsePartialOutput({text:u}){const f=await $i(u);switch(f.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":return{partial:f.value}}},createElementStreamTransform(){}}},km=({element:t,name:r,description:o})=>{const c=Jo(t);return{name:"array",responseFormat:Sc(c.jsonSchema).then(u=>{const{$schema:f,...p}=u;return{type:"json",schema:{$schema:"http://json-schema.org/draft-07/schema#",type:"object",properties:{elements:{type:"array",items:p}},required:["elements"],additionalProperties:!1},...r!=null&&{name:r},...o!=null&&{description:o}}}),async parseCompleteOutput({text:u},f){const p=await Yn({text:u});if(!p.success)throw new Gn({message:"No object generated: could not parse the response.",cause:p.error,text:u,response:f.response,usage:f.usage,finishReason:f.finishReason});const x=p.value;if(x==null||typeof x!="object"||!("elements"in x)||!Array.isArray(x.elements))throw new Gn({message:"No object generated: response did not match schema.",cause:new ur({value:x,cause:"response must be an object with an elements array"}),text:u,response:f.response,usage:f.usage,finishReason:f.finishReason});for(const _ of x.elements){const g=await Nr({value:_,schema:c});if(!g.success)throw new Gn({message:"No object generated: response did not match schema.",cause:g.error,text:u,response:f.response,usage:f.usage,finishReason:f.finishReason})}return x.elements},async parsePartialOutput({text:u}){const f=await $i(u);switch(f.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":{const p=f.value;if(p==null||typeof p!="object"||!("elements"in p)||!Array.isArray(p.elements))return;const x=f.state==="repaired-parse"&&p.elements.length>0?p.elements.slice(0,-1):p.elements,_=[];for(const g of x){const A=await Nr({value:g,schema:c});A.success&&_.push(A.value)}return{partial:_}}}},createElementStreamTransform(){let u=0;return new TransformStream({transform({partialOutput:f},p){if(f!=null)for(;u<f.length;u++)p.enqueue(f[u])}})}}},Rm=({options:t,name:r,description:o})=>({name:"choice",responseFormat:Promise.resolve({type:"json",schema:{$schema:"http://json-schema.org/draft-07/schema#",type:"object",properties:{result:{type:"string",enum:t}},required:["result"],additionalProperties:!1},...r!=null&&{name:r},...o!=null&&{description:o}}),async parseCompleteOutput({text:c},u){const f=await Yn({text:c});if(!f.success)throw new Gn({message:"No object generated: could not parse the response.",cause:f.error,text:c,response:u.response,usage:u.usage,finishReason:u.finishReason});const p=f.value;if(p==null||typeof p!="object"||!("result"in p)||typeof p.result!="string"||!t.includes(p.result))throw new Gn({message:"No object generated: response did not match schema.",cause:new ur({value:p,cause:"response must be an object that contains a choice value."}),text:c,response:u.response,usage:u.usage,finishReason:u.finishReason});return p.result},async parsePartialOutput({text:c}){const u=await $i(c);switch(u.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":{const f=u.value;if(f==null||typeof f!="object"||!("result"in f)||typeof f.result!="string")return;const p=t.filter(x=>x.startsWith(f.result));return u.state==="successful-parse"?p.includes(f.result)?{partial:f.result}:void 0:p.length===1?{partial:p[0]}:void 0}}},createElementStreamTransform(){}}),Mm=({name:t,description:r}={})=>({name:"json",responseFormat:Promise.resolve({type:"json",...t!=null&&{name:t},...r!=null&&{description:r}}),async parseCompleteOutput({text:o},c){const u=await Yn({text:o});if(!u.success)throw new Gn({message:"No object generated: could not parse the response.",cause:u.error,text:o,response:c.response,usage:c.usage,finishReason:c.finishReason});return u.value},async parsePartialOutput({text:o}){const c=await $i(o);switch(c.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":return c.value===void 0?void 0:{partial:c.value}}},createElementStreamTransform(){}});oi({prefix:"aitxt",size:24});(class extends TransformStream{constructor(){super({transform(t,r){r.enqueue(`data: ${JSON.stringify(t)}
39
39
 
40
40
  `)},flush(t){t.enqueue(`data: [DONE]
41
41
 
42
- `)}})}});ii({prefix:"aitxt",size:24});ii({prefix:"aiobj",size:24});ii({prefix:"aiobj",size:24});var Ni={exports:{}},Mg=Ni.exports,wa;function Dg(){return wa||(wa=1,(function(t,r){(function(o,c){t.exports=c()})(Mg,(function(){var o=1e3,c=6e4,u=36e5,f="millisecond",p="second",x="minute",y="hour",m="day",A="week",E="month",B="quarter",D="year",M="date",R="Invalid Date",k=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,q=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,Z={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(ee){var P=["th","st","nd","rd"],H=ee%100;return"["+ee+(P[(H-20)%10]||P[H]||P[0])+"]"}},z=function(ee,P,H){var re=String(ee);return!re||re.length>=P?ee:""+Array(P+1-re.length).join(H)+ee},$={s:z,z:function(ee){var P=-ee.utcOffset(),H=Math.abs(P),re=Math.floor(H/60),te=H%60;return(P<=0?"+":"-")+z(re,2,"0")+":"+z(te,2,"0")},m:function ee(P,H){if(P.date()<H.date())return-ee(H,P);var re=12*(H.year()-P.year())+(H.month()-P.month()),te=P.clone().add(re,E),we=H-te<0,se=P.clone().add(re+(we?-1:1),E);return+(-(re+(H-te)/(we?te-se:se-te))||0)},a:function(ee){return ee<0?Math.ceil(ee)||0:Math.floor(ee)},p:function(ee){return{M:E,y:D,w:A,d:m,D:M,h:y,m:x,s:p,ms:f,Q:B}[ee]||String(ee||"").toLowerCase().replace(/s$/,"")},u:function(ee){return ee===void 0}},Q="en",O={};O[Q]=Z;var V="$isDayjsObject",le=function(ee){return ee instanceof ne||!(!ee||!ee[V])},j=function ee(P,H,re){var te;if(!P)return Q;if(typeof P=="string"){var we=P.toLowerCase();O[we]&&(te=we),H&&(O[we]=H,te=we);var se=P.split("-");if(!te&&se.length>1)return ee(se[0])}else{var ye=P.name;O[ye]=P,te=ye}return!re&&te&&(Q=te),te||!re&&Q},Ee=function(ee,P){if(le(ee))return ee.clone();var H=typeof P=="object"?P:{};return H.date=ee,H.args=arguments,new ne(H)},de=$;de.l=j,de.i=le,de.w=function(ee,P){return Ee(ee,{locale:P.$L,utc:P.$u,x:P.$x,$offset:P.$offset})};var ne=(function(){function ee(H){this.$L=j(H.locale,null,!0),this.parse(H),this.$x=this.$x||H.x||{},this[V]=!0}var P=ee.prototype;return P.parse=function(H){this.$d=(function(re){var te=re.date,we=re.utc;if(te===null)return new Date(NaN);if(de.u(te))return new Date;if(te instanceof Date)return new Date(te);if(typeof te=="string"&&!/Z$/i.test(te)){var se=te.match(k);if(se){var ye=se[2]-1||0,_e=(se[7]||"0").substring(0,3);return we?new Date(Date.UTC(se[1],ye,se[3]||1,se[4]||0,se[5]||0,se[6]||0,_e)):new Date(se[1],ye,se[3]||1,se[4]||0,se[5]||0,se[6]||0,_e)}}return new Date(te)})(H),this.init()},P.init=function(){var H=this.$d;this.$y=H.getFullYear(),this.$M=H.getMonth(),this.$D=H.getDate(),this.$W=H.getDay(),this.$H=H.getHours(),this.$m=H.getMinutes(),this.$s=H.getSeconds(),this.$ms=H.getMilliseconds()},P.$utils=function(){return de},P.isValid=function(){return this.$d.toString()!==R},P.isSame=function(H,re){var te=Ee(H);return this.startOf(re)<=te&&te<=this.endOf(re)},P.isAfter=function(H,re){return Ee(H)<this.startOf(re)},P.isBefore=function(H,re){return this.endOf(re)<Ee(H)},P.$g=function(H,re,te){return de.u(H)?this[re]:this.set(te,H)},P.unix=function(){return Math.floor(this.valueOf()/1e3)},P.valueOf=function(){return this.$d.getTime()},P.startOf=function(H,re){var te=this,we=!!de.u(re)||re,se=de.p(H),ye=function(Nt,Qe){var et=de.w(te.$u?Date.UTC(te.$y,Qe,Nt):new Date(te.$y,Qe,Nt),te);return we?et:et.endOf(m)},_e=function(Nt,Qe){return de.w(te.toDate()[Nt].apply(te.toDate("s"),(we?[0,0,0,0]:[23,59,59,999]).slice(Qe)),te)},Ze=this.$W,Ue=this.$M,xe=this.$D,ge="set"+(this.$u?"UTC":"");switch(se){case D:return we?ye(1,0):ye(31,11);case E:return we?ye(1,Ue):ye(0,Ue+1);case A:var ft=this.$locale().weekStart||0,Se=(Ze<ft?Ze+7:Ze)-ft;return ye(we?xe-Se:xe+(6-Se),Ue);case m:case M:return _e(ge+"Hours",0);case y:return _e(ge+"Minutes",1);case x:return _e(ge+"Seconds",2);case p:return _e(ge+"Milliseconds",3);default:return this.clone()}},P.endOf=function(H){return this.startOf(H,!1)},P.$set=function(H,re){var te,we=de.p(H),se="set"+(this.$u?"UTC":""),ye=(te={},te[m]=se+"Date",te[M]=se+"Date",te[E]=se+"Month",te[D]=se+"FullYear",te[y]=se+"Hours",te[x]=se+"Minutes",te[p]=se+"Seconds",te[f]=se+"Milliseconds",te)[we],_e=we===m?this.$D+(re-this.$W):re;if(we===E||we===D){var Ze=this.clone().set(M,1);Ze.$d[ye](_e),Ze.init(),this.$d=Ze.set(M,Math.min(this.$D,Ze.daysInMonth())).$d}else ye&&this.$d[ye](_e);return this.init(),this},P.set=function(H,re){return this.clone().$set(H,re)},P.get=function(H){return this[de.p(H)]()},P.add=function(H,re){var te,we=this;H=Number(H);var se=de.p(re),ye=function(Ue){var xe=Ee(we);return de.w(xe.date(xe.date()+Math.round(Ue*H)),we)};if(se===E)return this.set(E,this.$M+H);if(se===D)return this.set(D,this.$y+H);if(se===m)return ye(1);if(se===A)return ye(7);var _e=(te={},te[x]=c,te[y]=u,te[p]=o,te)[se]||1,Ze=this.$d.getTime()+H*_e;return de.w(Ze,this)},P.subtract=function(H,re){return this.add(-1*H,re)},P.format=function(H){var re=this,te=this.$locale();if(!this.isValid())return te.invalidDate||R;var we=H||"YYYY-MM-DDTHH:mm:ssZ",se=de.z(this),ye=this.$H,_e=this.$m,Ze=this.$M,Ue=te.weekdays,xe=te.months,ge=te.meridiem,ft=function(Qe,et,jt,Be){return Qe&&(Qe[et]||Qe(re,we))||jt[et].slice(0,Be)},Se=function(Qe){return de.s(ye%12||12,Qe,"0")},Nt=ge||function(Qe,et,jt){var Be=Qe<12?"AM":"PM";return jt?Be.toLowerCase():Be};return we.replace(q,(function(Qe,et){return et||(function(jt){switch(jt){case"YY":return String(re.$y).slice(-2);case"YYYY":return de.s(re.$y,4,"0");case"M":return Ze+1;case"MM":return de.s(Ze+1,2,"0");case"MMM":return ft(te.monthsShort,Ze,xe,3);case"MMMM":return ft(xe,Ze);case"D":return re.$D;case"DD":return de.s(re.$D,2,"0");case"d":return String(re.$W);case"dd":return ft(te.weekdaysMin,re.$W,Ue,2);case"ddd":return ft(te.weekdaysShort,re.$W,Ue,3);case"dddd":return Ue[re.$W];case"H":return String(ye);case"HH":return de.s(ye,2,"0");case"h":return Se(1);case"hh":return Se(2);case"a":return Nt(ye,_e,!0);case"A":return Nt(ye,_e,!1);case"m":return String(_e);case"mm":return de.s(_e,2,"0");case"s":return String(re.$s);case"ss":return de.s(re.$s,2,"0");case"SSS":return de.s(re.$ms,3,"0");case"Z":return se}return null})(Qe)||se.replace(":","")}))},P.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},P.diff=function(H,re,te){var we,se=this,ye=de.p(re),_e=Ee(H),Ze=(_e.utcOffset()-this.utcOffset())*c,Ue=this-_e,xe=function(){return de.m(se,_e)};switch(ye){case D:we=xe()/12;break;case E:we=xe();break;case B:we=xe()/3;break;case A:we=(Ue-Ze)/6048e5;break;case m:we=(Ue-Ze)/864e5;break;case y:we=Ue/u;break;case x:we=Ue/c;break;case p:we=Ue/o;break;default:we=Ue}return te?we:de.a(we)},P.daysInMonth=function(){return this.endOf(E).$D},P.$locale=function(){return O[this.$L]},P.locale=function(H,re){if(!H)return this.$L;var te=this.clone(),we=j(H,re,!0);return we&&(te.$L=we),te},P.clone=function(){return de.w(this.$d,this)},P.toDate=function(){return new Date(this.valueOf())},P.toJSON=function(){return this.isValid()?this.toISOString():null},P.toISOString=function(){return this.$d.toISOString()},P.toString=function(){return this.$d.toUTCString()},ee})(),oe=ne.prototype;return Ee.prototype=oe,[["$ms",f],["$s",p],["$m",x],["$H",y],["$W",m],["$M",E],["$y",D],["$D",M]].forEach((function(ee){oe[ee[1]]=function(P){return this.$g(P,ee[0],ee[1])}})),Ee.extend=function(ee,P){return ee.$i||(ee(P,ne,Ee),ee.$i=!0),Ee},Ee.locale=j,Ee.isDayjs=le,Ee.unix=function(ee){return Ee(1e3*ee)},Ee.en=O[Q],Ee.Ls=O,Ee.p={},Ee}))})(Ni)),Ni.exports}var Pg=Dg();const Bg=Ic(Pg),Lg={description:"获取今天的日期",inputSchema:sr.z.object({}),execute:()=>({date:`当前日期: ${Bg().format("YYYY-M-D")}`})};var Dc="vercel.ai.error",Fg=Symbol.for(Dc),Pc,Ug=class Bc extends Error{constructor({name:r,message:o,cause:c}){super(o),this[Pc]=!0,this.name=r,this.cause=c}static isInstance(r){return Bc.hasMarker(r,Dc)}static hasMarker(r,o){const c=Symbol.for(o);return r!=null&&typeof r=="object"&&c in r&&typeof r[c]=="boolean"&&r[c]===!0}};Pc=Fg;var Bt=Ug,Lc="AI_APICallError",Fc=`vercel.ai.error.${Lc}`,zg=Symbol.for(Fc),Uc,Mn=class extends Bt{constructor({message:t,url:r,requestBodyValues:o,statusCode:c,responseHeaders:u,responseBody:f,cause:p,isRetryable:x=c!=null&&(c===408||c===409||c===429||c>=500),data:y}){super({name:Lc,message:t,cause:p}),this[Uc]=!0,this.url=r,this.requestBodyValues=o,this.statusCode=c,this.responseHeaders=u,this.responseBody=f,this.isRetryable=x,this.data=y}static isInstance(t){return Bt.hasMarker(t,Fc)}};Uc=zg;var zc="AI_EmptyResponseBodyError",Vc=`vercel.ai.error.${zc}`,Vg=Symbol.for(Vc),$c,$g=class extends Bt{constructor({message:t="Empty response body"}={}){super({name:zc,message:t}),this[$c]=!0}static isInstance(t){return Bt.hasMarker(t,Vc)}};$c=Vg;function Zc(t){return t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:JSON.stringify(t)}var jc="AI_InvalidArgumentError",Hc=`vercel.ai.error.${jc}`,Zg=Symbol.for(Hc),Wc,Gc=class extends Bt{constructor({message:t,cause:r,argument:o}){super({name:jc,message:t,cause:r}),this[Wc]=!0,this.argument=o}static isInstance(t){return Bt.hasMarker(t,Hc)}};Wc=Zg;var Xc="AI_InvalidResponseDataError",qc=`vercel.ai.error.${Xc}`,jg=Symbol.for(qc),Yc,ya=class extends Bt{constructor({data:t,message:r=`Invalid response data: ${JSON.stringify(t)}.`}){super({name:Xc,message:r}),this[Yc]=!0,this.data=t}static isInstance(t){return Bt.hasMarker(t,qc)}};Yc=jg;var Jc="AI_JSONParseError",Kc=`vercel.ai.error.${Jc}`,Hg=Symbol.for(Kc),Qc,Pi=class extends Bt{constructor({text:t,cause:r}){super({name:Jc,message:`JSON parsing failed: Text: ${t}.
43
- Error message: ${Zc(r)}`,cause:r}),this[Qc]=!0,this.text=t}static isInstance(t){return Bt.hasMarker(t,Kc)}};Qc=Hg;var eu="AI_LoadAPIKeyError",tu=`vercel.ai.error.${eu}`,Wg=Symbol.for(tu),nu,bi=class extends Bt{constructor({message:t}){super({name:eu,message:t}),this[nu]=!0}static isInstance(t){return Bt.hasMarker(t,tu)}};nu=Wg;var ru="AI_NoSuchModelError",iu=`vercel.ai.error.${ru}`,Gg=Symbol.for(iu),ou,_a=class extends Bt{constructor({errorName:t=ru,modelId:r,modelType:o,message:c=`No such ${o}: ${r}`}){super({name:t,message:c}),this[ou]=!0,this.modelId=r,this.modelType=o}static isInstance(t){return Bt.hasMarker(t,iu)}};ou=Gg;var su="AI_TypeValidationError",au=`vercel.ai.error.${su}`,Xg=Symbol.for(au),lu,qg=class Oo extends Bt{constructor({value:r,cause:o}){super({name:su,message:`Type validation failed: Value: ${JSON.stringify(r)}.
44
- Error message: ${Zc(o)}`,cause:o}),this[lu]=!0,this.value=r}static isInstance(r){return Bt.hasMarker(r,au)}static wrap({value:r,cause:o}){return Oo.isInstance(o)&&o.value===r?o:new Oo({value:r,cause:o})}};lu=Xg;var Kr=qg,cu="AI_UnsupportedFunctionalityError",uu=`vercel.ai.error.${cu}`,Yg=Symbol.for(uu),du,fu=class extends Bt{constructor({functionality:t,message:r=`'${t}' functionality not supported.`}){super({name:cu,message:r}),this[du]=!0,this.functionality=t}static isInstance(t){return Bt.hasMarker(t,uu)}};du=Yg;function va(...t){return t.reduce((r,o)=>({...r,...o??{}}),{})}function Zi(t){return Object.fromEntries([...t.headers])}var Jg=({prefix:t,size:r=16,alphabet:o="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",separator:c="-"}={})=>{const u=()=>{const f=o.length,p=new Array(r);for(let x=0;x<r;x++)p[x]=o[Math.random()*f|0];return p.join("")};if(t==null)return u;if(o.includes(c))throw new Gc({argument:"separator",message:`The separator "${c}" must not be part of the alphabet "${o}".`});return()=>`${t}${c}${u()}`},Ei=Jg();function ko(t){return(t instanceof Error||t instanceof DOMException)&&(t.name==="AbortError"||t.name==="ResponseAborted"||t.name==="TimeoutError")}var Kg=["fetch failed","failed to fetch"];function Qg({error:t,url:r,requestBodyValues:o}){if(ko(t))return t;if(t instanceof TypeError&&Kg.includes(t.message.toLowerCase())){const c=t.cause;if(c!=null)return new Mn({message:`Cannot connect to API: ${c.message}`,cause:c,url:r,requestBodyValues:o,isRetryable:!0})}return t}function em(t=globalThis){var r,o,c;return t.window?"runtime/browser":(r=t.navigator)!=null&&r.userAgent?`runtime/${t.navigator.userAgent.toLowerCase()}`:(c=(o=t.process)==null?void 0:o.versions)!=null&&c.node?`runtime/node.js/${t.process.version.substring(0)}`:t.EdgeRuntime?"runtime/vercel-edge":"runtime/unknown"}function tm(t){if(t==null)return{};const r={};if(t instanceof Headers)t.forEach((o,c)=>{r[c.toLowerCase()]=o});else{Array.isArray(t)||(t=Object.entries(t));for(const[o,c]of t)c!=null&&(r[o.toLowerCase()]=c)}return r}function hu(t,...r){const o=new Headers(tm(t)),c=o.get("user-agent")||"";return o.set("user-agent",[c,...r].filter(Boolean).join(" ")),Object.fromEntries(o.entries())}var nm="3.0.18";function rm({apiKey:t,environmentVariableName:r,apiKeyParameterName:o="apiKey",description:c}){if(typeof t=="string")return t;if(t!=null)throw new bi({message:`${c} API key must be a string.`});if(typeof process>"u")throw new bi({message:`${c} API key is missing. Pass it using the '${o}' parameter. Environment variables is not supported in this environment.`});if(t=process.env[r],t==null)throw new bi({message:`${c} API key is missing. Pass it using the '${o}' parameter or the ${r} environment variable.`});if(typeof t!="string")throw new bi({message:`${c} API key must be a string. The value of the ${r} environment variable is not a string.`});return t}var im=/"__proto__"\s*:/,om=/"constructor"\s*:/;function Ca(t){const r=JSON.parse(t);return r===null||typeof r!="object"||im.test(t)===!1&&om.test(t)===!1?r:sm(r)}function sm(t){let r=[t];for(;r.length;){const o=r;r=[];for(const c of o){if(Object.prototype.hasOwnProperty.call(c,"__proto__"))throw new SyntaxError("Object contains forbidden prototype property");if(Object.prototype.hasOwnProperty.call(c,"constructor")&&Object.prototype.hasOwnProperty.call(c.constructor,"prototype"))throw new SyntaxError("Object contains forbidden prototype property");for(const u in c){const f=c[u];f&&typeof f=="object"&&r.push(f)}}}return t}function Ko(t){const{stackTraceLimit:r}=Error;try{Error.stackTraceLimit=0}catch{return Ca(t)}try{return Ca(t)}finally{Error.stackTraceLimit=r}}var Ro=Symbol.for("vercel.ai.validator");function am(t){return{[Ro]:!0,validate:t}}function lm(t){return typeof t=="object"&&t!==null&&Ro in t&&t[Ro]===!0&&"validate"in t}function cm(t){return lm(t)?t:typeof t=="function"?t():um(t)}function um(t){return am(async r=>{const o=await t["~standard"].validate(r);return o.issues==null?{success:!0,value:o.value}:{success:!1,error:new Kr({value:r,cause:o.issues})}})}async function dm({value:t,schema:r}){const o=await Qr({value:t,schema:r});if(!o.success)throw Kr.wrap({value:t,cause:o.error});return o.value}async function Qr({value:t,schema:r}){const o=cm(r);try{if(o.validate==null)return{success:!0,value:t,rawValue:t};const c=await o.validate(t);return c.success?{success:!0,value:c.value,rawValue:t}:{success:!1,error:Kr.wrap({value:t,cause:c.error}),rawValue:t}}catch(c){return{success:!1,error:Kr.wrap({value:t,cause:c}),rawValue:t}}}async function fm({text:t,schema:r}){try{const o=Ko(t);return r==null?o:dm({value:o,schema:r})}catch(o){throw Pi.isInstance(o)||Kr.isInstance(o)?o:new Pi({text:t,cause:o})}}async function pu({text:t,schema:r}){try{const o=Ko(t);return r==null?{success:!0,value:o,rawValue:o}:await Qr({value:o,schema:r})}catch(o){return{success:!1,error:Pi.isInstance(o)?o:new Pi({text:t,cause:o}),rawValue:void 0}}}function ba(t){try{return Ko(t),!0}catch{return!1}}function hm({stream:t,schema:r}){return t.pipeThrough(new TextDecoderStream).pipeThrough(new hc).pipeThrough(new TransformStream({async transform({data:o},c){o!=="[DONE]"&&c.enqueue(await pu({text:o,schema:r}))}}))}async function Ea({provider:t,providerOptions:r,schema:o}){if(r?.[t]==null)return;const c=await Qr({value:r[t],schema:o});if(!c.success)throw new Gc({argument:"providerOptions",message:`invalid ${t} provider options`,cause:c.error});return c.value}var pm=()=>globalThis.fetch,Aa=async({url:t,headers:r,body:o,failedResponseHandler:c,successfulResponseHandler:u,abortSignal:f,fetch:p})=>gm({url:t,headers:{"Content-Type":"application/json",...r},body:{content:JSON.stringify(o),values:o},failedResponseHandler:c,successfulResponseHandler:u,abortSignal:f,fetch:p}),gm=async({url:t,headers:r={},body:o,successfulResponseHandler:c,failedResponseHandler:u,abortSignal:f,fetch:p=pm()})=>{try{const x=await p(t,{method:"POST",headers:hu(r,`ai-sdk/provider-utils/${nm}`,em()),body:o.content,signal:f}),y=Zi(x);if(!x.ok){let m;try{m=await u({response:x,url:t,requestBodyValues:o.values})}catch(A){throw ko(A)||Mn.isInstance(A)?A:new Mn({message:"Failed to process error response",cause:A,statusCode:x.status,url:t,responseHeaders:y,requestBodyValues:o.values})}throw m.value}try{return await c({response:x,url:t,requestBodyValues:o.values})}catch(m){throw m instanceof Error&&(ko(m)||Mn.isInstance(m))?m:new Mn({message:"Failed to process successful response",cause:m,statusCode:x.status,url:t,responseHeaders:y,requestBodyValues:o.values})}}catch(x){throw Qg({error:x,url:t,requestBodyValues:o.values})}},mm=({errorSchema:t,errorToMessage:r,isRetryable:o})=>async({response:c,url:u,requestBodyValues:f})=>{const p=await c.text(),x=Zi(c);if(p.trim()==="")return{responseHeaders:x,value:new Mn({message:c.statusText,url:u,requestBodyValues:f,statusCode:c.status,responseHeaders:x,responseBody:p,isRetryable:o?.(c)})};try{const y=await fm({text:p,schema:t});return{responseHeaders:x,value:new Mn({message:r(y),url:u,requestBodyValues:f,statusCode:c.status,responseHeaders:x,responseBody:p,data:y,isRetryable:o?.(c,y)})}}catch{return{responseHeaders:x,value:new Mn({message:c.statusText,url:u,requestBodyValues:f,statusCode:c.status,responseHeaders:x,responseBody:p,isRetryable:o?.(c)})}}},xm=t=>async({response:r})=>{const o=Zi(r);if(r.body==null)throw new $g({});return{responseHeaders:o,value:hm({stream:r.body,schema:t})}},wm=t=>async({response:r,url:o,requestBodyValues:c})=>{const u=await r.text(),f=await pu({text:u,schema:t}),p=Zi(r);if(!f.success)throw new Mn({message:"Invalid JSON response",cause:f.error,statusCode:r.status,responseHeaders:p,responseBody:u,url:o,requestBodyValues:c});return{responseHeaders:p,value:f.value,rawValue:f.rawValue}};new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");var{btoa:ym}=globalThis;function _m(t){let r="";for(let o=0;o<t.length;o++)r+=String.fromCodePoint(t[o]);return ym(r)}function vm(t){return t instanceof Uint8Array?_m(t):t}function Cm(t){return t?.replace(/\/$/,"")}function Ur(t){var r,o;return(o=(r=t?.providerOptions)==null?void 0:r.openaiCompatible)!=null?o:{}}function bm(t){const r=[];for(const{role:o,content:c,...u}of t){const f=Ur({...u});switch(o){case"system":{r.push({role:"system",content:c,...f});break}case"user":{if(c.length===1&&c[0].type==="text"){r.push({role:"user",content:c[0].text,...Ur(c[0])});break}r.push({role:"user",content:c.map(p=>{const x=Ur(p);switch(p.type){case"text":return{type:"text",text:p.text,...x};case"file":if(p.mediaType.startsWith("image/")){const y=p.mediaType==="image/*"?"image/jpeg":p.mediaType;return{type:"image_url",image_url:{url:p.data instanceof URL?p.data.toString():`data:${y};base64,${vm(p.data)}`},...x}}else throw new fu({functionality:`file part media type ${p.mediaType}`})}}),...f});break}case"assistant":{let p="";const x=[];for(const y of c){const m=Ur(y);switch(y.type){case"text":{p+=y.text;break}case"tool-call":{x.push({id:y.toolCallId,type:"function",function:{name:y.toolName,arguments:JSON.stringify(y.input)},...m});break}}}r.push({role:"assistant",content:p,tool_calls:x.length>0?x:void 0,...f});break}case"tool":{for(const p of c){const x=p.output;let y;switch(x.type){case"text":case"error-text":y=x.value;break;case"content":case"json":case"error-json":y=JSON.stringify(x.value);break}const m=Ur(p);r.push({role:"tool",tool_call_id:p.toolCallId,content:y,...m})}break}default:{const p=o;throw new Error(`Unsupported role: ${p}`)}}}return r}function Ia({id:t,model:r,created:o}){return{id:t??void 0,modelId:r??void 0,timestamp:o!=null?new Date(o*1e3):void 0}}function Sa(t){switch(t){case"stop":return"stop";case"length":return"length";case"content_filter":return"content-filter";case"function_call":case"tool_calls":return"tool-calls";default:return"unknown"}}var xo=T({user:_().optional(),reasoningEffort:_().optional(),textVerbosity:_().optional()}),Em=T({error:T({message:_(),type:_().nullish(),param:ur().nullish(),code:Le([_(),X()]).nullish()})}),Am={errorSchema:Em,errorToMessage:t=>t.error.message};function Im({tools:t,toolChoice:r}){t=t?.length?t:void 0;const o=[];if(t==null)return{tools:void 0,toolChoice:void 0,toolWarnings:o};const c=[];for(const f of t)f.type==="provider-defined"?o.push({type:"unsupported-tool",tool:f}):c.push({type:"function",function:{name:f.name,description:f.description,parameters:f.inputSchema}});if(r==null)return{tools:c,toolChoice:void 0,toolWarnings:o};const u=r.type;switch(u){case"auto":case"none":case"required":return{tools:c,toolChoice:u,toolWarnings:o};case"tool":return{tools:c,toolChoice:{type:"function",function:{name:r.toolName}},toolWarnings:o};default:{const f=u;throw new fu({functionality:`tool choice type: ${f}`})}}}var Sm=class{constructor(t,r){this.specificationVersion="v2";var o,c;this.modelId=t,this.config=r;const u=(o=r.errorStructure)!=null?o:Am;this.chunkSchema=Nm(u.errorSchema),this.failedResponseHandler=mm(u),this.supportsStructuredOutputs=(c=r.supportsStructuredOutputs)!=null?c:!1}get provider(){return this.config.provider}get providerOptionsName(){return this.config.provider.split(".")[0].trim()}get supportedUrls(){var t,r,o;return(o=(r=(t=this.config).supportedUrls)==null?void 0:r.call(t))!=null?o:{}}async getArgs({prompt:t,maxOutputTokens:r,temperature:o,topP:c,topK:u,frequencyPenalty:f,presencePenalty:p,providerOptions:x,stopSequences:y,responseFormat:m,seed:A,toolChoice:E,tools:B}){var D,M,R,k;const q=[],Z=Object.assign((D=await Ea({provider:"openai-compatible",providerOptions:x,schema:xo}))!=null?D:{},(M=await Ea({provider:this.providerOptionsName,providerOptions:x,schema:xo}))!=null?M:{});u!=null&&q.push({type:"unsupported-setting",setting:"topK"}),m?.type==="json"&&m.schema!=null&&!this.supportsStructuredOutputs&&q.push({type:"unsupported-setting",setting:"responseFormat",details:"JSON response format schema is only supported with structuredOutputs"});const{tools:z,toolChoice:$,toolWarnings:Q}=Im({tools:B,toolChoice:E});return{args:{model:this.modelId,user:Z.user,max_tokens:r,temperature:o,top_p:c,frequency_penalty:f,presence_penalty:p,response_format:m?.type==="json"?this.supportsStructuredOutputs===!0&&m.schema!=null?{type:"json_schema",json_schema:{schema:m.schema,name:(R=m.name)!=null?R:"response",description:m.description}}:{type:"json_object"}:void 0,stop:y,seed:A,...Object.fromEntries(Object.entries((k=x?.[this.providerOptionsName])!=null?k:{}).filter(([O])=>!Object.keys(xo.shape).includes(O))),reasoning_effort:Z.reasoningEffort,verbosity:Z.textVerbosity,messages:bm(t),tools:z,tool_choice:$},warnings:[...q,...Q]}}async doGenerate(t){var r,o,c,u,f,p,x,y,m,A,E,B,D,M,R,k,q;const{args:Z,warnings:z}=await this.getArgs({...t}),$=JSON.stringify(Z),{responseHeaders:Q,value:O,rawValue:V}=await Aa({url:this.config.url({path:"/chat/completions",modelId:this.modelId}),headers:va(this.config.headers(),t.headers),body:Z,failedResponseHandler:this.failedResponseHandler,successfulResponseHandler:wm(Tm),abortSignal:t.abortSignal,fetch:this.config.fetch}),le=O.choices[0],j=[],Ee=le.message.content;Ee!=null&&Ee.length>0&&j.push({type:"text",text:Ee});const de=(r=le.message.reasoning_content)!=null?r:le.message.reasoning;if(de!=null&&de.length>0&&j.push({type:"reasoning",text:de}),le.message.tool_calls!=null)for(const ee of le.message.tool_calls)j.push({type:"tool-call",toolCallId:(o=ee.id)!=null?o:Ei(),toolName:ee.function.name,input:ee.function.arguments});const ne={[this.providerOptionsName]:{},...await((u=(c=this.config.metadataExtractor)==null?void 0:c.extractMetadata)==null?void 0:u.call(c,{parsedBody:V}))},oe=(f=O.usage)==null?void 0:f.completion_tokens_details;return oe?.accepted_prediction_tokens!=null&&(ne[this.providerOptionsName].acceptedPredictionTokens=oe?.accepted_prediction_tokens),oe?.rejected_prediction_tokens!=null&&(ne[this.providerOptionsName].rejectedPredictionTokens=oe?.rejected_prediction_tokens),{content:j,finishReason:Sa(le.finish_reason),usage:{inputTokens:(x=(p=O.usage)==null?void 0:p.prompt_tokens)!=null?x:void 0,outputTokens:(m=(y=O.usage)==null?void 0:y.completion_tokens)!=null?m:void 0,totalTokens:(E=(A=O.usage)==null?void 0:A.total_tokens)!=null?E:void 0,reasoningTokens:(M=(D=(B=O.usage)==null?void 0:B.completion_tokens_details)==null?void 0:D.reasoning_tokens)!=null?M:void 0,cachedInputTokens:(q=(k=(R=O.usage)==null?void 0:R.prompt_tokens_details)==null?void 0:k.cached_tokens)!=null?q:void 0},providerMetadata:ne,request:{body:$},response:{...Ia(O),headers:Q,body:V},warnings:z}}async doStream(t){var r;const{args:o,warnings:c}=await this.getArgs({...t}),u={...o,stream:!0,stream_options:this.config.includeUsage?{include_usage:!0}:void 0},f=(r=this.config.metadataExtractor)==null?void 0:r.createStreamExtractor(),{responseHeaders:p,value:x}=await Aa({url:this.config.url({path:"/chat/completions",modelId:this.modelId}),headers:va(this.config.headers(),t.headers),body:u,failedResponseHandler:this.failedResponseHandler,successfulResponseHandler:xm(this.chunkSchema),abortSignal:t.abortSignal,fetch:this.config.fetch}),y=[];let m="unknown";const A={completionTokens:void 0,completionTokensDetails:{reasoningTokens:void 0,acceptedPredictionTokens:void 0,rejectedPredictionTokens:void 0},promptTokens:void 0,promptTokensDetails:{cachedTokens:void 0},totalTokens:void 0};let E=!0;const B=this.providerOptionsName;let D=!1,M=!1;return{stream:x.pipeThrough(new TransformStream({start(R){R.enqueue({type:"stream-start",warnings:c})},transform(R,k){var q,Z,z,$,Q,O,V,le,j,Ee,de,ne,oe;if(t.includeRawChunks&&k.enqueue({type:"raw",rawValue:R.rawValue}),!R.success){m="error",k.enqueue({type:"error",error:R.error});return}const ee=R.value;if(f?.processChunk(R.rawValue),"error"in ee){m="error",k.enqueue({type:"error",error:ee.error.message});return}if(E&&(E=!1,k.enqueue({type:"response-metadata",...Ia(ee)})),ee.usage!=null){const{prompt_tokens:te,completion_tokens:we,total_tokens:se,prompt_tokens_details:ye,completion_tokens_details:_e}=ee.usage;A.promptTokens=te??void 0,A.completionTokens=we??void 0,A.totalTokens=se??void 0,_e?.reasoning_tokens!=null&&(A.completionTokensDetails.reasoningTokens=_e?.reasoning_tokens),_e?.accepted_prediction_tokens!=null&&(A.completionTokensDetails.acceptedPredictionTokens=_e?.accepted_prediction_tokens),_e?.rejected_prediction_tokens!=null&&(A.completionTokensDetails.rejectedPredictionTokens=_e?.rejected_prediction_tokens),ye?.cached_tokens!=null&&(A.promptTokensDetails.cachedTokens=ye?.cached_tokens)}const P=ee.choices[0];if(P?.finish_reason!=null&&(m=Sa(P.finish_reason)),P?.delta==null)return;const H=P.delta,re=(q=H.reasoning_content)!=null?q:H.reasoning;if(re&&(D||(k.enqueue({type:"reasoning-start",id:"reasoning-0"}),D=!0),k.enqueue({type:"reasoning-delta",id:"reasoning-0",delta:re})),H.content&&(M||(k.enqueue({type:"text-start",id:"txt-0"}),M=!0),k.enqueue({type:"text-delta",id:"txt-0",delta:H.content})),H.tool_calls!=null)for(const te of H.tool_calls){const we=te.index;if(y[we]==null){if(te.id==null)throw new ya({data:te,message:"Expected 'id' to be a string."});if(((Z=te.function)==null?void 0:Z.name)==null)throw new ya({data:te,message:"Expected 'function.name' to be a string."});k.enqueue({type:"tool-input-start",id:te.id,toolName:te.function.name}),y[we]={id:te.id,type:"function",function:{name:te.function.name,arguments:(z=te.function.arguments)!=null?z:""},hasFinished:!1};const ye=y[we];(($=ye.function)==null?void 0:$.name)!=null&&((Q=ye.function)==null?void 0:Q.arguments)!=null&&(ye.function.arguments.length>0&&k.enqueue({type:"tool-input-delta",id:ye.id,delta:ye.function.arguments}),ba(ye.function.arguments)&&(k.enqueue({type:"tool-input-end",id:ye.id}),k.enqueue({type:"tool-call",toolCallId:(O=ye.id)!=null?O:Ei(),toolName:ye.function.name,input:ye.function.arguments}),ye.hasFinished=!0));continue}const se=y[we];se.hasFinished||(((V=te.function)==null?void 0:V.arguments)!=null&&(se.function.arguments+=(j=(le=te.function)==null?void 0:le.arguments)!=null?j:""),k.enqueue({type:"tool-input-delta",id:se.id,delta:(Ee=te.function.arguments)!=null?Ee:""}),((de=se.function)==null?void 0:de.name)!=null&&((ne=se.function)==null?void 0:ne.arguments)!=null&&ba(se.function.arguments)&&(k.enqueue({type:"tool-input-end",id:se.id}),k.enqueue({type:"tool-call",toolCallId:(oe=se.id)!=null?oe:Ei(),toolName:se.function.name,input:se.function.arguments}),se.hasFinished=!0))}},flush(R){var k,q,Z,z,$,Q;D&&R.enqueue({type:"reasoning-end",id:"reasoning-0"}),M&&R.enqueue({type:"text-end",id:"txt-0"});for(const V of y.filter(le=>!le.hasFinished))R.enqueue({type:"tool-input-end",id:V.id}),R.enqueue({type:"tool-call",toolCallId:(k=V.id)!=null?k:Ei(),toolName:V.function.name,input:V.function.arguments});const O={[B]:{},...f?.buildMetadata()};A.completionTokensDetails.acceptedPredictionTokens!=null&&(O[B].acceptedPredictionTokens=A.completionTokensDetails.acceptedPredictionTokens),A.completionTokensDetails.rejectedPredictionTokens!=null&&(O[B].rejectedPredictionTokens=A.completionTokensDetails.rejectedPredictionTokens),R.enqueue({type:"finish",finishReason:m,usage:{inputTokens:(q=A.promptTokens)!=null?q:void 0,outputTokens:(Z=A.completionTokens)!=null?Z:void 0,totalTokens:(z=A.totalTokens)!=null?z:void 0,reasoningTokens:($=A.completionTokensDetails.reasoningTokens)!=null?$:void 0,cachedInputTokens:(Q=A.promptTokensDetails.cachedTokens)!=null?Q:void 0},providerMetadata:O})}})),request:{body:u},response:{headers:p}}}},gu=T({prompt_tokens:X().nullish(),completion_tokens:X().nullish(),total_tokens:X().nullish(),prompt_tokens_details:T({cached_tokens:X().nullish()}).nullish(),completion_tokens_details:T({reasoning_tokens:X().nullish(),accepted_prediction_tokens:X().nullish(),rejected_prediction_tokens:X().nullish()}).nullish()}).nullish(),Tm=T({id:_().nullish(),created:X().nullish(),model:_().nullish(),choices:me(T({message:T({role:Y("assistant").nullish(),content:_().nullish(),reasoning_content:_().nullish(),reasoning:_().nullish(),tool_calls:me(T({id:_().nullish(),function:T({name:_(),arguments:_()})})).nullish()}),finish_reason:_().nullish()})),usage:gu}),Nm=t=>Le([T({id:_().nullish(),created:X().nullish(),model:_().nullish(),choices:me(T({delta:T({role:We(["assistant"]).nullish(),content:_().nullish(),reasoning_content:_().nullish(),reasoning:_().nullish(),tool_calls:me(T({index:X(),id:_().nullish(),function:T({name:_().nullish(),arguments:_().nullish()})})).nullish()}).nullish(),finish_reason:_().nullish()})),usage:gu}),t]);T({echo:At().optional(),logitBias:pt(_(),X()).optional(),suffix:_().optional(),user:_().optional()});var Om=T({prompt_tokens:X(),completion_tokens:X(),total_tokens:X()});T({id:_().nullish(),created:X().nullish(),model:_().nullish(),choices:me(T({text:_(),finish_reason:_()})),usage:Om.nullish()});T({dimensions:X().optional(),user:_().optional()});T({data:me(T({embedding:me(X())})),usage:T({prompt_tokens:X()}).nullish(),providerMetadata:pt(_(),pt(_(),ur())).optional()});T({data:me(T({b64_json:_()}))});var Ta=t=>{var r,o;return t==null?void 0:{deepseek:{promptCacheHitTokens:(r=t.prompt_cache_hit_tokens)!=null?r:NaN,promptCacheMissTokens:(o=t.prompt_cache_miss_tokens)!=null?o:NaN}}},km={extractMetadata:async({parsedBody:t})=>{const r=await Qr({value:t,schema:Rm});return!r.success||r.value.usage==null?void 0:Ta(r.value.usage)},createStreamExtractor:()=>{let t;return{processChunk:async r=>{var o,c;const u=await Qr({value:r,schema:Mm});u.success&&((c=(o=u.value.choices)==null?void 0:o[0])==null?void 0:c.finish_reason)==="stop"&&u.value.usage&&(t=u.value.usage)},buildMetadata:()=>Ta(t)}}},mu=T({prompt_cache_hit_tokens:X().nullish(),prompt_cache_miss_tokens:X().nullish()}),Rm=T({usage:mu.nullish()}),Mm=T({choices:me(T({finish_reason:_().nullish()})).nullish(),usage:mu.nullish()}),Dm="1.0.30";function xu(t={}){var r;const o=Cm((r=t.baseURL)!=null?r:"https://api.deepseek.com/v1"),c=()=>hu({Authorization:`Bearer ${rm({apiKey:t.apiKey,environmentVariableName:"DEEPSEEK_API_KEY",description:"DeepSeek API key"})}`,...t.headers},`ai-sdk/deepseek/${Dm}`);class u extends Sm{addJsonInstruction(y){var m;if(((m=y.responseFormat)==null?void 0:m.type)!=="json")return y;const B=[...Array.isArray(y.prompt)?y.prompt:[],{role:"user",content:[{type:"text",text:"Return ONLY a valid JSON object."}]}];return{...y,prompt:B}}async doGenerate(y){return super.doGenerate(this.addJsonInstruction(y))}async doStream(y){return super.doStream(this.addJsonInstruction(y))}}const f=x=>new u(x,{provider:"deepseek.chat",url:({path:y})=>`${o}${y}`,headers:c,fetch:t.fetch,metadataExtractor:km}),p=x=>f(x);return p.languageModel=f,p.chat=f,p.textEmbeddingModel=x=>{throw new _a({modelId:x,modelType:"textEmbeddingModel"})},p.imageModel=x=>{throw new _a({modelId:x,modelType:"imageModel"})},p}xu();var Qo=T({error:T({message:_(),type:_().nullish(),param:ur().nullish(),code:Le([_(),X()]).nullish()})}),vn=ug({errorSchema:Qo,errorToMessage:t=>t.error.message});function wu(t){const r=t.startsWith("o3")||t.startsWith("o4-mini")||t.startsWith("gpt-5")&&!t.startsWith("gpt-5-chat"),o=t.startsWith("gpt-4")||t.startsWith("gpt-5-mini")||t.startsWith("gpt-5")&&!t.startsWith("gpt-5-nano")&&!t.startsWith("gpt-5-chat")||t.startsWith("o3")||t.startsWith("o4-mini"),c=t.startsWith("o1")||t.startsWith("o3")||t.startsWith("o4-mini")||t.startsWith("codex-mini")||t.startsWith("computer-use-preview")||t.startsWith("gpt-5")&&!t.startsWith("gpt-5-chat"),u=t.startsWith("gpt-5.1")||t.startsWith("gpt-5.2");return{supportsFlexProcessing:r,supportsPriorityProcessing:o,isReasoningModel:c,systemMessageMode:c?"developer":"system",supportsNonReasoningParameters:u}}function Na(t){var r,o,c,u,f,p;if(t==null)return{inputTokens:{total:void 0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:void 0,text:void 0,reasoning:void 0},raw:void 0};const x=(r=t.prompt_tokens)!=null?r:0,y=(o=t.completion_tokens)!=null?o:0,m=(u=(c=t.prompt_tokens_details)==null?void 0:c.cached_tokens)!=null?u:0,A=(p=(f=t.completion_tokens_details)==null?void 0:f.reasoning_tokens)!=null?p:0;return{inputTokens:{total:x,noCache:x-m,cacheRead:m,cacheWrite:void 0},outputTokens:{total:y,text:y-A,reasoning:A},raw:t}}function Pm({prompt:t,systemMessageMode:r="system"}){var o;const c=[],u=[];for(const{role:f,content:p}of t)switch(f){case"system":{switch(r){case"system":{c.push({role:"system",content:p});break}case"developer":{c.push({role:"developer",content:p});break}case"remove":{u.push({type:"other",message:"system messages are removed for this model"});break}default:{const x=r;throw new Error(`Unsupported system message mode: ${x}`)}}break}case"user":{if(p.length===1&&p[0].type==="text"){c.push({role:"user",content:p[0].text});break}c.push({role:"user",content:p.map((x,y)=>{var m,A,E;switch(x.type){case"text":return{type:"text",text:x.text};case"file":if(x.mediaType.startsWith("image/")){const B=x.mediaType==="image/*"?"image/jpeg":x.mediaType;return{type:"image_url",image_url:{url:x.data instanceof URL?x.data.toString():`data:${B};base64,${br(x.data)}`,detail:(A=(m=x.providerOptions)==null?void 0:m.openai)==null?void 0:A.imageDetail}}}else if(x.mediaType.startsWith("audio/")){if(x.data instanceof URL)throw new Rn({functionality:"audio file parts with URLs"});switch(x.mediaType){case"audio/wav":return{type:"input_audio",input_audio:{data:br(x.data),format:"wav"}};case"audio/mp3":case"audio/mpeg":return{type:"input_audio",input_audio:{data:br(x.data),format:"mp3"}};default:throw new Rn({functionality:`audio content parts with media type ${x.mediaType}`})}}else if(x.mediaType==="application/pdf"){if(x.data instanceof URL)throw new Rn({functionality:"PDF file parts with URLs"});return{type:"file",file:typeof x.data=="string"&&x.data.startsWith("file-")?{file_id:x.data}:{filename:(E=x.filename)!=null?E:`part-${y}.pdf`,file_data:`data:application/pdf;base64,${br(x.data)}`}}}else throw new Rn({functionality:`file part media type ${x.mediaType}`})}})});break}case"assistant":{let x="";const y=[];for(const m of p)switch(m.type){case"text":{x+=m.text;break}case"tool-call":{y.push({id:m.toolCallId,type:"function",function:{name:m.toolName,arguments:JSON.stringify(m.input)}});break}}c.push({role:"assistant",content:x,tool_calls:y.length>0?y:void 0});break}case"tool":{for(const x of p){if(x.type==="tool-approval-response")continue;const y=x.output;let m;switch(y.type){case"text":case"error-text":m=y.value;break;case"execution-denied":m=(o=y.reason)!=null?o:"Tool execution denied.";break;case"content":case"json":case"error-json":m=JSON.stringify(y.value);break}c.push({role:"tool",tool_call_id:x.toolCallId,content:m})}break}default:{const x=f;throw new Error(`Unsupported role: ${x}`)}}return{messages:c,warnings:u}}function wo({id:t,model:r,created:o}){return{id:t??void 0,modelId:r??void 0,timestamp:o?new Date(o*1e3):void 0}}function Oa(t){switch(t){case"stop":return"stop";case"length":return"length";case"content_filter":return"content-filter";case"function_call":case"tool_calls":return"tool-calls";default:return"other"}}var Bm=$e(()=>Ve(T({id:_().nullish(),created:X().nullish(),model:_().nullish(),choices:me(T({message:T({role:Y("assistant").nullish(),content:_().nullish(),tool_calls:me(T({id:_().nullish(),type:Y("function"),function:T({name:_(),arguments:_()})})).nullish(),annotations:me(T({type:Y("url_citation"),url_citation:T({start_index:X(),end_index:X(),url:_(),title:_()})})).nullish()}),index:X(),logprobs:T({content:me(T({token:_(),logprob:X(),top_logprobs:me(T({token:_(),logprob:X()}))})).nullish()}).nullish(),finish_reason:_().nullish()})),usage:T({prompt_tokens:X().nullish(),completion_tokens:X().nullish(),total_tokens:X().nullish(),prompt_tokens_details:T({cached_tokens:X().nullish()}).nullish(),completion_tokens_details:T({reasoning_tokens:X().nullish(),accepted_prediction_tokens:X().nullish(),rejected_prediction_tokens:X().nullish()}).nullish()}).nullish()}))),Lm=$e(()=>Ve(Le([T({id:_().nullish(),created:X().nullish(),model:_().nullish(),choices:me(T({delta:T({role:We(["assistant"]).nullish(),content:_().nullish(),tool_calls:me(T({index:X(),id:_().nullish(),type:Y("function").nullish(),function:T({name:_().nullish(),arguments:_().nullish()})})).nullish(),annotations:me(T({type:Y("url_citation"),url_citation:T({start_index:X(),end_index:X(),url:_(),title:_()})})).nullish()}).nullish(),logprobs:T({content:me(T({token:_(),logprob:X(),top_logprobs:me(T({token:_(),logprob:X()}))})).nullish()}).nullish(),finish_reason:_().nullish(),index:X()})),usage:T({prompt_tokens:X().nullish(),completion_tokens:X().nullish(),total_tokens:X().nullish(),prompt_tokens_details:T({cached_tokens:X().nullish()}).nullish(),completion_tokens_details:T({reasoning_tokens:X().nullish(),accepted_prediction_tokens:X().nullish(),rejected_prediction_tokens:X().nullish()}).nullish()}).nullish()}),Qo]))),Fm=$e(()=>Ve(T({logitBias:pt(Hh(),X()).optional(),logprobs:Le([At(),X()]).optional(),parallelToolCalls:At().optional(),user:_().optional(),reasoningEffort:We(["none","minimal","low","medium","high","xhigh"]).optional(),maxCompletionTokens:X().optional(),store:At().optional(),metadata:pt(_().max(64),_().max(512)).optional(),prediction:pt(_(),ur()).optional(),serviceTier:We(["auto","flex","priority","default"]).optional(),strictJsonSchema:At().optional(),textVerbosity:We(["low","medium","high"]).optional(),promptCacheKey:_().optional(),promptCacheRetention:We(["in_memory","24h"]).optional(),safetyIdentifier:_().optional(),systemMessageMode:We(["system","developer","remove"]).optional(),forceReasoning:At().optional()})));function Um({tools:t,toolChoice:r}){t=t?.length?t:void 0;const o=[];if(t==null)return{tools:void 0,toolChoice:void 0,toolWarnings:o};const c=[];for(const f of t)switch(f.type){case"function":c.push({type:"function",function:{name:f.name,description:f.description,parameters:f.inputSchema,...f.strict!=null?{strict:f.strict}:{}}});break;default:o.push({type:"unsupported",feature:`tool type: ${f.type}`});break}if(r==null)return{tools:c,toolChoice:void 0,toolWarnings:o};const u=r.type;switch(u){case"auto":case"none":case"required":return{tools:c,toolChoice:u,toolWarnings:o};case"tool":return{tools:c,toolChoice:{type:"function",function:{name:r.toolName}},toolWarnings:o};default:{const f=u;throw new Rn({functionality:`tool choice type: ${f}`})}}}var zm=class{constructor(t,r){this.specificationVersion="v3",this.supportedUrls={"image/*":[/^https?:\/\/.*$/]},this.modelId=t,this.config=r}get provider(){return this.config.provider}async getArgs({prompt:t,maxOutputTokens:r,temperature:o,topP:c,topK:u,frequencyPenalty:f,presencePenalty:p,stopSequences:x,responseFormat:y,seed:m,tools:A,toolChoice:E,providerOptions:B}){var D,M,R,k,q;const Z=[],z=(D=await Dn({provider:"openai",providerOptions:B,schema:Fm}))!=null?D:{},$=wu(this.modelId),Q=(M=z.forceReasoning)!=null?M:$.isReasoningModel;u!=null&&Z.push({type:"unsupported",feature:"topK"});const{messages:O,warnings:V}=Pm({prompt:t,systemMessageMode:(R=z.systemMessageMode)!=null?R:Q?"developer":$.systemMessageMode});Z.push(...V);const le=(k=z.strictJsonSchema)!=null?k:!0,j={model:this.modelId,logit_bias:z.logitBias,logprobs:z.logprobs===!0||typeof z.logprobs=="number"?!0:void 0,top_logprobs:typeof z.logprobs=="number"?z.logprobs:typeof z.logprobs=="boolean"&&z.logprobs?0:void 0,user:z.user,parallel_tool_calls:z.parallelToolCalls,max_tokens:r,temperature:o,top_p:c,frequency_penalty:f,presence_penalty:p,response_format:y?.type==="json"?y.schema!=null?{type:"json_schema",json_schema:{schema:y.schema,strict:le,name:(q=y.name)!=null?q:"response",description:y.description}}:{type:"json_object"}:void 0,stop:x,seed:m,verbosity:z.textVerbosity,max_completion_tokens:z.maxCompletionTokens,store:z.store,metadata:z.metadata,prediction:z.prediction,reasoning_effort:z.reasoningEffort,service_tier:z.serviceTier,prompt_cache_key:z.promptCacheKey,prompt_cache_retention:z.promptCacheRetention,safety_identifier:z.safetyIdentifier,messages:O};Q?((z.reasoningEffort!=="none"||!$.supportsNonReasoningParameters)&&(j.temperature!=null&&(j.temperature=void 0,Z.push({type:"unsupported",feature:"temperature",details:"temperature is not supported for reasoning models"})),j.top_p!=null&&(j.top_p=void 0,Z.push({type:"unsupported",feature:"topP",details:"topP is not supported for reasoning models"})),j.logprobs!=null&&(j.logprobs=void 0,Z.push({type:"other",message:"logprobs is not supported for reasoning models"}))),j.frequency_penalty!=null&&(j.frequency_penalty=void 0,Z.push({type:"unsupported",feature:"frequencyPenalty",details:"frequencyPenalty is not supported for reasoning models"})),j.presence_penalty!=null&&(j.presence_penalty=void 0,Z.push({type:"unsupported",feature:"presencePenalty",details:"presencePenalty is not supported for reasoning models"})),j.logit_bias!=null&&(j.logit_bias=void 0,Z.push({type:"other",message:"logitBias is not supported for reasoning models"})),j.top_logprobs!=null&&(j.top_logprobs=void 0,Z.push({type:"other",message:"topLogprobs is not supported for reasoning models"})),j.max_tokens!=null&&(j.max_completion_tokens==null&&(j.max_completion_tokens=j.max_tokens),j.max_tokens=void 0)):(this.modelId.startsWith("gpt-4o-search-preview")||this.modelId.startsWith("gpt-4o-mini-search-preview"))&&j.temperature!=null&&(j.temperature=void 0,Z.push({type:"unsupported",feature:"temperature",details:"temperature is not supported for the search preview models and has been removed."})),z.serviceTier==="flex"&&!$.supportsFlexProcessing&&(Z.push({type:"unsupported",feature:"serviceTier",details:"flex processing is only available for o3, o4-mini, and gpt-5 models"}),j.service_tier=void 0),z.serviceTier==="priority"&&!$.supportsPriorityProcessing&&(Z.push({type:"unsupported",feature:"serviceTier",details:"priority processing is only available for supported models (gpt-4, gpt-5, gpt-5-mini, o3, o4-mini) and requires Enterprise access. gpt-5-nano is not supported"}),j.service_tier=void 0);const{tools:Ee,toolChoice:de,toolWarnings:ne}=Um({tools:A,toolChoice:E});return{args:{...j,tools:Ee,tool_choice:de},warnings:[...Z,...ne]}}async doGenerate(t){var r,o,c,u,f,p,x;const{args:y,warnings:m}=await this.getArgs(t),{responseHeaders:A,value:E,rawValue:B}=await Pn({url:this.config.url({path:"/chat/completions",modelId:this.modelId}),headers:_n(this.config.headers(),t.headers),body:y,failedResponseHandler:vn,successfulResponseHandler:lr(Bm),abortSignal:t.abortSignal,fetch:this.config.fetch}),D=E.choices[0],M=[],R=D.message.content;R!=null&&R.length>0&&M.push({type:"text",text:R});for(const Z of(r=D.message.tool_calls)!=null?r:[])M.push({type:"tool-call",toolCallId:(o=Z.id)!=null?o:Gt(),toolName:Z.function.name,input:Z.function.arguments});for(const Z of(c=D.message.annotations)!=null?c:[])M.push({type:"source",sourceType:"url",id:Gt(),url:Z.url_citation.url,title:Z.url_citation.title});const k=(u=E.usage)==null?void 0:u.completion_tokens_details;(f=E.usage)==null||f.prompt_tokens_details;const q={openai:{}};return k?.accepted_prediction_tokens!=null&&(q.openai.acceptedPredictionTokens=k?.accepted_prediction_tokens),k?.rejected_prediction_tokens!=null&&(q.openai.rejectedPredictionTokens=k?.rejected_prediction_tokens),((p=D.logprobs)==null?void 0:p.content)!=null&&(q.openai.logprobs=D.logprobs.content),{content:M,finishReason:{unified:Oa(D.finish_reason),raw:(x=D.finish_reason)!=null?x:void 0},usage:Na(E.usage),request:{body:y},response:{...wo(E),headers:A,body:B},warnings:m,providerMetadata:q}}async doStream(t){const{args:r,warnings:o}=await this.getArgs(t),c={...r,stream:!0,stream_options:{include_usage:!0}},{responseHeaders:u,value:f}=await Pn({url:this.config.url({path:"/chat/completions",modelId:this.modelId}),headers:_n(this.config.headers(),t.headers),body:c,failedResponseHandler:vn,successfulResponseHandler:Jo(Lm),abortSignal:t.abortSignal,fetch:this.config.fetch}),p=[];let x={unified:"other",raw:void 0},y,m=!1,A=!1;const E={openai:{}};return{stream:f.pipeThrough(new TransformStream({start(B){B.enqueue({type:"stream-start",warnings:o})},transform(B,D){var M,R,k,q,Z,z,$,Q,O,V,le,j,Ee,de,ne,oe,ee;if(t.includeRawChunks&&D.enqueue({type:"raw",rawValue:B.rawValue}),!B.success){x={unified:"error",raw:void 0},D.enqueue({type:"error",error:B.error});return}const P=B.value;if("error"in P){x={unified:"error",raw:void 0},D.enqueue({type:"error",error:P.error});return}if(!m){const te=wo(P);Object.values(te).some(Boolean)&&(m=!0,D.enqueue({type:"response-metadata",...wo(P)}))}P.usage!=null&&(y=P.usage,((M=P.usage.completion_tokens_details)==null?void 0:M.accepted_prediction_tokens)!=null&&(E.openai.acceptedPredictionTokens=(R=P.usage.completion_tokens_details)==null?void 0:R.accepted_prediction_tokens),((k=P.usage.completion_tokens_details)==null?void 0:k.rejected_prediction_tokens)!=null&&(E.openai.rejectedPredictionTokens=(q=P.usage.completion_tokens_details)==null?void 0:q.rejected_prediction_tokens));const H=P.choices[0];if(H?.finish_reason!=null&&(x={unified:Oa(H.finish_reason),raw:H.finish_reason}),((Z=H?.logprobs)==null?void 0:Z.content)!=null&&(E.openai.logprobs=H.logprobs.content),H?.delta==null)return;const re=H.delta;if(re.content!=null&&(A||(D.enqueue({type:"text-start",id:"0"}),A=!0),D.enqueue({type:"text-delta",id:"0",delta:re.content})),re.tool_calls!=null)for(const te of re.tool_calls){const we=te.index;if(p[we]==null){if(te.type!=="function")throw new uo({data:te,message:"Expected 'function' type."});if(te.id==null)throw new uo({data:te,message:"Expected 'id' to be a string."});if(((z=te.function)==null?void 0:z.name)==null)throw new uo({data:te,message:"Expected 'function.name' to be a string."});D.enqueue({type:"tool-input-start",id:te.id,toolName:te.function.name}),p[we]={id:te.id,type:"function",function:{name:te.function.name,arguments:($=te.function.arguments)!=null?$:""},hasFinished:!1};const ye=p[we];((Q=ye.function)==null?void 0:Q.name)!=null&&((O=ye.function)==null?void 0:O.arguments)!=null&&(ye.function.arguments.length>0&&D.enqueue({type:"tool-input-delta",id:ye.id,delta:ye.function.arguments}),xa(ye.function.arguments)&&(D.enqueue({type:"tool-input-end",id:ye.id}),D.enqueue({type:"tool-call",toolCallId:(V=ye.id)!=null?V:Gt(),toolName:ye.function.name,input:ye.function.arguments}),ye.hasFinished=!0));continue}const se=p[we];se.hasFinished||(((le=te.function)==null?void 0:le.arguments)!=null&&(se.function.arguments+=(Ee=(j=te.function)==null?void 0:j.arguments)!=null?Ee:""),D.enqueue({type:"tool-input-delta",id:se.id,delta:(de=te.function.arguments)!=null?de:""}),((ne=se.function)==null?void 0:ne.name)!=null&&((oe=se.function)==null?void 0:oe.arguments)!=null&&xa(se.function.arguments)&&(D.enqueue({type:"tool-input-end",id:se.id}),D.enqueue({type:"tool-call",toolCallId:(ee=se.id)!=null?ee:Gt(),toolName:se.function.name,input:se.function.arguments}),se.hasFinished=!0))}if(re.annotations!=null)for(const te of re.annotations)D.enqueue({type:"source",sourceType:"url",id:Gt(),url:te.url_citation.url,title:te.url_citation.title})},flush(B){A&&B.enqueue({type:"text-end",id:"0"}),B.enqueue({type:"finish",finishReason:x,usage:Na(y),...E!=null?{providerMetadata:E}:{}})}})),request:{body:c},response:{headers:u}}}};function ka(t){var r,o,c,u;if(t==null)return{inputTokens:{total:void 0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:void 0,text:void 0,reasoning:void 0},raw:void 0};const f=(r=t.prompt_tokens)!=null?r:0,p=(o=t.completion_tokens)!=null?o:0;return{inputTokens:{total:(c=t.prompt_tokens)!=null?c:void 0,noCache:f,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:(u=t.completion_tokens)!=null?u:void 0,text:p,reasoning:void 0},raw:t}}function Vm({prompt:t,user:r="user",assistant:o="assistant"}){let c="";t[0].role==="system"&&(c+=`${t[0].content}
42
+ `)}})}});oi({prefix:"aitxt",size:24});oi({prefix:"aiobj",size:24});oi({prefix:"aiobj",size:24});var Ni={exports:{}},Dm=Ni.exports,wa;function Pm(){return wa||(wa=1,(function(t,r){(function(o,c){t.exports=c()})(Dm,(function(){var o=1e3,c=6e4,u=36e5,f="millisecond",p="second",x="minute",_="hour",g="day",A="week",E="month",L="quarter",M="year",D="date",R="Invalid Date",P=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,H=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,Z={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(te){var O=["th","st","nd","rd"],J=te%100;return"["+te+(O[(J-20)%10]||O[J]||O[0])+"]"}},$=function(te,O,J){var ae=String(te);return!ae||ae.length>=O?te:""+Array(O+1-ae.length).join(J)+te},V={s:$,z:function(te){var O=-te.utcOffset(),J=Math.abs(O),ae=Math.floor(J/60),oe=J%60;return(O<=0?"+":"-")+$(ae,2,"0")+":"+$(oe,2,"0")},m:function te(O,J){if(O.date()<J.date())return-te(J,O);var ae=12*(J.year()-O.year())+(J.month()-O.month()),oe=O.clone().add(ae,E),ge=J-oe<0,he=O.clone().add(ae+(ge?-1:1),E);return+(-(ae+(J-oe)/(ge?oe-he:he-oe))||0)},a:function(te){return te<0?Math.ceil(te)||0:Math.floor(te)},p:function(te){return{M:E,y:M,w:A,d:g,D,h:_,m:x,s:p,ms:f,Q:L}[te]||String(te||"").toLowerCase().replace(/s$/,"")},u:function(te){return te===void 0}},ee="en",j={};j[ee]=Z;var z="$isDayjsObject",q=function(te){return te instanceof ne||!(!te||!te[z])},B=function te(O,J,ae){var oe;if(!O)return ee;if(typeof O=="string"){var ge=O.toLowerCase();j[ge]&&(oe=ge),J&&(j[ge]=J,oe=ge);var he=O.split("-");if(!oe&&he.length>1)return te(he[0])}else{var ue=O.name;j[ue]=O,oe=ue}return!ae&&oe&&(ee=oe),oe||!ae&&ee},we=function(te,O){if(q(te))return te.clone();var J=typeof O=="object"?O:{};return J.date=te,J.args=arguments,new ne(J)},re=V;re.l=B,re.i=q,re.w=function(te,O){return we(te,{locale:O.$L,utc:O.$u,x:O.$x,$offset:O.$offset})};var ne=(function(){function te(J){this.$L=B(J.locale,null,!0),this.parse(J),this.$x=this.$x||J.x||{},this[z]=!0}var O=te.prototype;return O.parse=function(J){this.$d=(function(ae){var oe=ae.date,ge=ae.utc;if(oe===null)return new Date(NaN);if(re.u(oe))return new Date;if(oe instanceof Date)return new Date(oe);if(typeof oe=="string"&&!/Z$/i.test(oe)){var he=oe.match(P);if(he){var ue=he[2]-1||0,Ce=(he[7]||"0").substring(0,3);return ge?new Date(Date.UTC(he[1],ue,he[3]||1,he[4]||0,he[5]||0,he[6]||0,Ce)):new Date(he[1],ue,he[3]||1,he[4]||0,he[5]||0,he[6]||0,Ce)}}return new Date(oe)})(J),this.init()},O.init=function(){var J=this.$d;this.$y=J.getFullYear(),this.$M=J.getMonth(),this.$D=J.getDate(),this.$W=J.getDay(),this.$H=J.getHours(),this.$m=J.getMinutes(),this.$s=J.getSeconds(),this.$ms=J.getMilliseconds()},O.$utils=function(){return re},O.isValid=function(){return this.$d.toString()!==R},O.isSame=function(J,ae){var oe=we(J);return this.startOf(ae)<=oe&&oe<=this.endOf(ae)},O.isAfter=function(J,ae){return we(J)<this.startOf(ae)},O.isBefore=function(J,ae){return this.endOf(ae)<we(J)},O.$g=function(J,ae,oe){return re.u(J)?this[ae]:this.set(oe,J)},O.unix=function(){return Math.floor(this.valueOf()/1e3)},O.valueOf=function(){return this.$d.getTime()},O.startOf=function(J,ae){var oe=this,ge=!!re.u(ae)||ae,he=re.p(J),ue=function(ke,et){var tt=re.w(oe.$u?Date.UTC(oe.$y,et,ke):new Date(oe.$y,et,ke),oe);return ge?tt:tt.endOf(g)},Ce=function(ke,et){return re.w(oe.toDate()[ke].apply(oe.toDate("s"),(ge?[0,0,0,0]:[23,59,59,999]).slice(et)),oe)},je=this.$W,Be=this.$M,ut=this.$D,ie="set"+(this.$u?"UTC":"");switch(he){case M:return ge?ue(1,0):ue(31,11);case E:return ge?ue(1,Be):ue(0,Be+1);case A:var Ae=this.$locale().weekStart||0,Me=(je<Ae?je+7:je)-Ae;return ue(ge?ut-Me:ut+(6-Me),Be);case g:case D:return Ce(ie+"Hours",0);case _:return Ce(ie+"Minutes",1);case x:return Ce(ie+"Seconds",2);case p:return Ce(ie+"Milliseconds",3);default:return this.clone()}},O.endOf=function(J){return this.startOf(J,!1)},O.$set=function(J,ae){var oe,ge=re.p(J),he="set"+(this.$u?"UTC":""),ue=(oe={},oe[g]=he+"Date",oe[D]=he+"Date",oe[E]=he+"Month",oe[M]=he+"FullYear",oe[_]=he+"Hours",oe[x]=he+"Minutes",oe[p]=he+"Seconds",oe[f]=he+"Milliseconds",oe)[ge],Ce=ge===g?this.$D+(ae-this.$W):ae;if(ge===E||ge===M){var je=this.clone().set(D,1);je.$d[ue](Ce),je.init(),this.$d=je.set(D,Math.min(this.$D,je.daysInMonth())).$d}else ue&&this.$d[ue](Ce);return this.init(),this},O.set=function(J,ae){return this.clone().$set(J,ae)},O.get=function(J){return this[re.p(J)]()},O.add=function(J,ae){var oe,ge=this;J=Number(J);var he=re.p(ae),ue=function(Be){var ut=we(ge);return re.w(ut.date(ut.date()+Math.round(Be*J)),ge)};if(he===E)return this.set(E,this.$M+J);if(he===M)return this.set(M,this.$y+J);if(he===g)return ue(1);if(he===A)return ue(7);var Ce=(oe={},oe[x]=c,oe[_]=u,oe[p]=o,oe)[he]||1,je=this.$d.getTime()+J*Ce;return re.w(je,this)},O.subtract=function(J,ae){return this.add(-1*J,ae)},O.format=function(J){var ae=this,oe=this.$locale();if(!this.isValid())return oe.invalidDate||R;var ge=J||"YYYY-MM-DDTHH:mm:ssZ",he=re.z(this),ue=this.$H,Ce=this.$m,je=this.$M,Be=oe.weekdays,ut=oe.months,ie=oe.meridiem,Ae=function(et,tt,Wt,Le){return et&&(et[tt]||et(ae,ge))||Wt[tt].slice(0,Le)},Me=function(et){return re.s(ue%12||12,et,"0")},ke=ie||function(et,tt,Wt){var Le=et<12?"AM":"PM";return Wt?Le.toLowerCase():Le};return ge.replace(H,(function(et,tt){return tt||(function(Wt){switch(Wt){case"YY":return String(ae.$y).slice(-2);case"YYYY":return re.s(ae.$y,4,"0");case"M":return je+1;case"MM":return re.s(je+1,2,"0");case"MMM":return Ae(oe.monthsShort,je,ut,3);case"MMMM":return Ae(ut,je);case"D":return ae.$D;case"DD":return re.s(ae.$D,2,"0");case"d":return String(ae.$W);case"dd":return Ae(oe.weekdaysMin,ae.$W,Be,2);case"ddd":return Ae(oe.weekdaysShort,ae.$W,Be,3);case"dddd":return Be[ae.$W];case"H":return String(ue);case"HH":return re.s(ue,2,"0");case"h":return Me(1);case"hh":return Me(2);case"a":return ke(ue,Ce,!0);case"A":return ke(ue,Ce,!1);case"m":return String(Ce);case"mm":return re.s(Ce,2,"0");case"s":return String(ae.$s);case"ss":return re.s(ae.$s,2,"0");case"SSS":return re.s(ae.$ms,3,"0");case"Z":return he}return null})(et)||he.replace(":","")}))},O.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},O.diff=function(J,ae,oe){var ge,he=this,ue=re.p(ae),Ce=we(J),je=(Ce.utcOffset()-this.utcOffset())*c,Be=this-Ce,ut=function(){return re.m(he,Ce)};switch(ue){case M:ge=ut()/12;break;case E:ge=ut();break;case L:ge=ut()/3;break;case A:ge=(Be-je)/6048e5;break;case g:ge=(Be-je)/864e5;break;case _:ge=Be/u;break;case x:ge=Be/c;break;case p:ge=Be/o;break;default:ge=Be}return oe?ge:re.a(ge)},O.daysInMonth=function(){return this.endOf(E).$D},O.$locale=function(){return j[this.$L]},O.locale=function(J,ae){if(!J)return this.$L;var oe=this.clone(),ge=B(J,ae,!0);return ge&&(oe.$L=ge),oe},O.clone=function(){return re.w(this.$d,this)},O.toDate=function(){return new Date(this.valueOf())},O.toJSON=function(){return this.isValid()?this.toISOString():null},O.toISOString=function(){return this.$d.toISOString()},O.toString=function(){return this.$d.toUTCString()},te})(),le=ne.prototype;return we.prototype=le,[["$ms",f],["$s",p],["$m",x],["$H",_],["$W",g],["$M",E],["$y",M],["$D",D]].forEach((function(te){le[te[1]]=function(O){return this.$g(O,te[0],te[1])}})),we.extend=function(te,O){return te.$i||(te(O,ne,we),te.$i=!0),we},we.locale=B,we.isDayjs=q,we.unix=function(te){return we(1e3*te)},we.en=j[ee],we.Ls=j,we.p={},we}))})(Ni)),Ni.exports}var Bm=Pm();const Lm=Tc(Bm),Fm={description:"获取今天的日期",inputSchema:cr.z.object({}),execute:()=>({date:`当前日期: ${Lm().format("YYYY-M-D")}`})};var Bc="vercel.ai.error",Um=Symbol.for(Bc),Lc,zm=class Fc extends Error{constructor({name:r,message:o,cause:c}){super(o),this[Lc]=!0,this.name=r,this.cause=c}static isInstance(r){return Fc.hasMarker(r,Bc)}static hasMarker(r,o){const c=Symbol.for(o);return r!=null&&typeof r=="object"&&c in r&&typeof r[c]=="boolean"&&r[c]===!0}};Lc=Um;var Ft=zm,Uc="AI_APICallError",zc=`vercel.ai.error.${Uc}`,Vm=Symbol.for(zc),Vc,Pn=class extends Ft{constructor({message:t,url:r,requestBodyValues:o,statusCode:c,responseHeaders:u,responseBody:f,cause:p,isRetryable:x=c!=null&&(c===408||c===409||c===429||c>=500),data:_}){super({name:Uc,message:t,cause:p}),this[Vc]=!0,this.url=r,this.requestBodyValues=o,this.statusCode=c,this.responseHeaders=u,this.responseBody=f,this.isRetryable=x,this.data=_}static isInstance(t){return Ft.hasMarker(t,zc)}};Vc=Vm;var $c="AI_EmptyResponseBodyError",Zc=`vercel.ai.error.${$c}`,$m=Symbol.for(Zc),jc,Zm=class extends Ft{constructor({message:t="Empty response body"}={}){super({name:$c,message:t}),this[jc]=!0}static isInstance(t){return Ft.hasMarker(t,Zc)}};jc=$m;function Hc(t){return t==null?"unknown error":typeof t=="string"?t:t instanceof Error?t.message:JSON.stringify(t)}var Wc="AI_InvalidArgumentError",Gc=`vercel.ai.error.${Wc}`,jm=Symbol.for(Gc),Xc,qc=class extends Ft{constructor({message:t,cause:r,argument:o}){super({name:Wc,message:t,cause:r}),this[Xc]=!0,this.argument=o}static isInstance(t){return Ft.hasMarker(t,Gc)}};Xc=jm;var Yc="AI_InvalidResponseDataError",Jc=`vercel.ai.error.${Yc}`,Hm=Symbol.for(Jc),Kc,_a=class extends Ft{constructor({data:t,message:r=`Invalid response data: ${JSON.stringify(t)}.`}){super({name:Yc,message:r}),this[Kc]=!0,this.data=t}static isInstance(t){return Ft.hasMarker(t,Jc)}};Kc=Hm;var Qc="AI_JSONParseError",eu=`vercel.ai.error.${Qc}`,Wm=Symbol.for(eu),tu,Pi=class extends Ft{constructor({text:t,cause:r}){super({name:Qc,message:`JSON parsing failed: Text: ${t}.
43
+ Error message: ${Hc(r)}`,cause:r}),this[tu]=!0,this.text=t}static isInstance(t){return Ft.hasMarker(t,eu)}};tu=Wm;var nu="AI_LoadAPIKeyError",ru=`vercel.ai.error.${nu}`,Gm=Symbol.for(ru),iu,bi=class extends Ft{constructor({message:t}){super({name:nu,message:t}),this[iu]=!0}static isInstance(t){return Ft.hasMarker(t,ru)}};iu=Gm;var ou="AI_NoSuchModelError",su=`vercel.ai.error.${ou}`,Xm=Symbol.for(su),au,va=class extends Ft{constructor({errorName:t=ou,modelId:r,modelType:o,message:c=`No such ${o}: ${r}`}){super({name:t,message:c}),this[au]=!0,this.modelId=r,this.modelType=o}static isInstance(t){return Ft.hasMarker(t,su)}};au=Xm;var lu="AI_TypeValidationError",cu=`vercel.ai.error.${lu}`,qm=Symbol.for(cu),uu,Ym=class Oo extends Ft{constructor({value:r,cause:o}){super({name:lu,message:`Type validation failed: Value: ${JSON.stringify(r)}.
44
+ Error message: ${Hc(o)}`,cause:o}),this[uu]=!0,this.value=r}static isInstance(r){return Ft.hasMarker(r,cu)}static wrap({value:r,cause:o}){return Oo.isInstance(o)&&o.value===r?o:new Oo({value:r,cause:o})}};uu=qm;var Qr=Ym,du="AI_UnsupportedFunctionalityError",fu=`vercel.ai.error.${du}`,Jm=Symbol.for(fu),hu,pu=class extends Ft{constructor({functionality:t,message:r=`'${t}' functionality not supported.`}){super({name:du,message:r}),this[hu]=!0,this.functionality=t}static isInstance(t){return Ft.hasMarker(t,fu)}};hu=Jm;function Ca(...t){return t.reduce((r,o)=>({...r,...o??{}}),{})}function Zi(t){return Object.fromEntries([...t.headers])}var Km=({prefix:t,size:r=16,alphabet:o="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",separator:c="-"}={})=>{const u=()=>{const f=o.length,p=new Array(r);for(let x=0;x<r;x++)p[x]=o[Math.random()*f|0];return p.join("")};if(t==null)return u;if(o.includes(c))throw new qc({argument:"separator",message:`The separator "${c}" must not be part of the alphabet "${o}".`});return()=>`${t}${c}${u()}`},Ei=Km();function ko(t){return(t instanceof Error||t instanceof DOMException)&&(t.name==="AbortError"||t.name==="ResponseAborted"||t.name==="TimeoutError")}var Qm=["fetch failed","failed to fetch"];function eg({error:t,url:r,requestBodyValues:o}){if(ko(t))return t;if(t instanceof TypeError&&Qm.includes(t.message.toLowerCase())){const c=t.cause;if(c!=null)return new Pn({message:`Cannot connect to API: ${c.message}`,cause:c,url:r,requestBodyValues:o,isRetryable:!0})}return t}function tg(t=globalThis){var r,o,c;return t.window?"runtime/browser":(r=t.navigator)!=null&&r.userAgent?`runtime/${t.navigator.userAgent.toLowerCase()}`:(c=(o=t.process)==null?void 0:o.versions)!=null&&c.node?`runtime/node.js/${t.process.version.substring(0)}`:t.EdgeRuntime?"runtime/vercel-edge":"runtime/unknown"}function ng(t){if(t==null)return{};const r={};if(t instanceof Headers)t.forEach((o,c)=>{r[c.toLowerCase()]=o});else{Array.isArray(t)||(t=Object.entries(t));for(const[o,c]of t)c!=null&&(r[o.toLowerCase()]=c)}return r}function mu(t,...r){const o=new Headers(ng(t)),c=o.get("user-agent")||"";return o.set("user-agent",[c,...r].filter(Boolean).join(" ")),Object.fromEntries(o.entries())}var rg="3.0.18";function ig({apiKey:t,environmentVariableName:r,apiKeyParameterName:o="apiKey",description:c}){if(typeof t=="string")return t;if(t!=null)throw new bi({message:`${c} API key must be a string.`});if(typeof process>"u")throw new bi({message:`${c} API key is missing. Pass it using the '${o}' parameter. Environment variables is not supported in this environment.`});if(t=process.env[r],t==null)throw new bi({message:`${c} API key is missing. Pass it using the '${o}' parameter or the ${r} environment variable.`});if(typeof t!="string")throw new bi({message:`${c} API key must be a string. The value of the ${r} environment variable is not a string.`});return t}var og=/"__proto__"\s*:/,sg=/"constructor"\s*:/;function ba(t){const r=JSON.parse(t);return r===null||typeof r!="object"||og.test(t)===!1&&sg.test(t)===!1?r:ag(r)}function ag(t){let r=[t];for(;r.length;){const o=r;r=[];for(const c of o){if(Object.prototype.hasOwnProperty.call(c,"__proto__"))throw new SyntaxError("Object contains forbidden prototype property");if(Object.prototype.hasOwnProperty.call(c,"constructor")&&Object.prototype.hasOwnProperty.call(c.constructor,"prototype"))throw new SyntaxError("Object contains forbidden prototype property");for(const u in c){const f=c[u];f&&typeof f=="object"&&r.push(f)}}}return t}function Qo(t){const{stackTraceLimit:r}=Error;try{Error.stackTraceLimit=0}catch{return ba(t)}try{return ba(t)}finally{Error.stackTraceLimit=r}}var Ro=Symbol.for("vercel.ai.validator");function lg(t){return{[Ro]:!0,validate:t}}function cg(t){return typeof t=="object"&&t!==null&&Ro in t&&t[Ro]===!0&&"validate"in t}function ug(t){return cg(t)?t:typeof t=="function"?t():dg(t)}function dg(t){return lg(async r=>{const o=await t["~standard"].validate(r);return o.issues==null?{success:!0,value:o.value}:{success:!1,error:new Qr({value:r,cause:o.issues})}})}async function fg({value:t,schema:r}){const o=await ei({value:t,schema:r});if(!o.success)throw Qr.wrap({value:t,cause:o.error});return o.value}async function ei({value:t,schema:r}){const o=ug(r);try{if(o.validate==null)return{success:!0,value:t,rawValue:t};const c=await o.validate(t);return c.success?{success:!0,value:c.value,rawValue:t}:{success:!1,error:Qr.wrap({value:t,cause:c.error}),rawValue:t}}catch(c){return{success:!1,error:Qr.wrap({value:t,cause:c}),rawValue:t}}}async function hg({text:t,schema:r}){try{const o=Qo(t);return r==null?o:fg({value:o,schema:r})}catch(o){throw Pi.isInstance(o)||Qr.isInstance(o)?o:new Pi({text:t,cause:o})}}async function gu({text:t,schema:r}){try{const o=Qo(t);return r==null?{success:!0,value:o,rawValue:o}:await ei({value:o,schema:r})}catch(o){return{success:!1,error:Pi.isInstance(o)?o:new Pi({text:t,cause:o}),rawValue:void 0}}}function Ea(t){try{return Qo(t),!0}catch{return!1}}function pg({stream:t,schema:r}){return t.pipeThrough(new TextDecoderStream).pipeThrough(new mc).pipeThrough(new TransformStream({async transform({data:o},c){o!=="[DONE]"&&c.enqueue(await gu({text:o,schema:r}))}}))}async function Aa({provider:t,providerOptions:r,schema:o}){if(r?.[t]==null)return;const c=await ei({value:r[t],schema:o});if(!c.success)throw new qc({argument:"providerOptions",message:`invalid ${t} provider options`,cause:c.error});return c.value}var mg=()=>globalThis.fetch,Ia=async({url:t,headers:r,body:o,failedResponseHandler:c,successfulResponseHandler:u,abortSignal:f,fetch:p})=>gg({url:t,headers:{"Content-Type":"application/json",...r},body:{content:JSON.stringify(o),values:o},failedResponseHandler:c,successfulResponseHandler:u,abortSignal:f,fetch:p}),gg=async({url:t,headers:r={},body:o,successfulResponseHandler:c,failedResponseHandler:u,abortSignal:f,fetch:p=mg()})=>{try{const x=await p(t,{method:"POST",headers:mu(r,`ai-sdk/provider-utils/${rg}`,tg()),body:o.content,signal:f}),_=Zi(x);if(!x.ok){let g;try{g=await u({response:x,url:t,requestBodyValues:o.values})}catch(A){throw ko(A)||Pn.isInstance(A)?A:new Pn({message:"Failed to process error response",cause:A,statusCode:x.status,url:t,responseHeaders:_,requestBodyValues:o.values})}throw g.value}try{return await c({response:x,url:t,requestBodyValues:o.values})}catch(g){throw g instanceof Error&&(ko(g)||Pn.isInstance(g))?g:new Pn({message:"Failed to process successful response",cause:g,statusCode:x.status,url:t,responseHeaders:_,requestBodyValues:o.values})}}catch(x){throw eg({error:x,url:t,requestBodyValues:o.values})}},xg=({errorSchema:t,errorToMessage:r,isRetryable:o})=>async({response:c,url:u,requestBodyValues:f})=>{const p=await c.text(),x=Zi(c);if(p.trim()==="")return{responseHeaders:x,value:new Pn({message:c.statusText,url:u,requestBodyValues:f,statusCode:c.status,responseHeaders:x,responseBody:p,isRetryable:o?.(c)})};try{const _=await hg({text:p,schema:t});return{responseHeaders:x,value:new Pn({message:r(_),url:u,requestBodyValues:f,statusCode:c.status,responseHeaders:x,responseBody:p,data:_,isRetryable:o?.(c,_)})}}catch{return{responseHeaders:x,value:new Pn({message:c.statusText,url:u,requestBodyValues:f,statusCode:c.status,responseHeaders:x,responseBody:p,isRetryable:o?.(c)})}}},yg=t=>async({response:r})=>{const o=Zi(r);if(r.body==null)throw new Zm({});return{responseHeaders:o,value:pg({stream:r.body,schema:t})}},wg=t=>async({response:r,url:o,requestBodyValues:c})=>{const u=await r.text(),f=await gu({text:u,schema:t}),p=Zi(r);if(!f.success)throw new Pn({message:"Invalid JSON response",cause:f.error,statusCode:r.status,responseHeaders:p,responseBody:u,url:o,requestBodyValues:c});return{responseHeaders:p,value:f.value,rawValue:f.rawValue}};new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");var{btoa:_g}=globalThis;function vg(t){let r="";for(let o=0;o<t.length;o++)r+=String.fromCodePoint(t[o]);return _g(r)}function Cg(t){return t instanceof Uint8Array?vg(t):t}function bg(t){return t?.replace(/\/$/,"")}function zr(t){var r,o;return(o=(r=t?.providerOptions)==null?void 0:r.openaiCompatible)!=null?o:{}}function Eg(t){const r=[];for(const{role:o,content:c,...u}of t){const f=zr({...u});switch(o){case"system":{r.push({role:"system",content:c,...f});break}case"user":{if(c.length===1&&c[0].type==="text"){r.push({role:"user",content:c[0].text,...zr(c[0])});break}r.push({role:"user",content:c.map(p=>{const x=zr(p);switch(p.type){case"text":return{type:"text",text:p.text,...x};case"file":if(p.mediaType.startsWith("image/")){const _=p.mediaType==="image/*"?"image/jpeg":p.mediaType;return{type:"image_url",image_url:{url:p.data instanceof URL?p.data.toString():`data:${_};base64,${Cg(p.data)}`},...x}}else throw new pu({functionality:`file part media type ${p.mediaType}`})}}),...f});break}case"assistant":{let p="";const x=[];for(const _ of c){const g=zr(_);switch(_.type){case"text":{p+=_.text;break}case"tool-call":{x.push({id:_.toolCallId,type:"function",function:{name:_.toolName,arguments:JSON.stringify(_.input)},...g});break}}}r.push({role:"assistant",content:p,tool_calls:x.length>0?x:void 0,...f});break}case"tool":{for(const p of c){const x=p.output;let _;switch(x.type){case"text":case"error-text":_=x.value;break;case"content":case"json":case"error-json":_=JSON.stringify(x.value);break}const g=zr(p);r.push({role:"tool",tool_call_id:p.toolCallId,content:_,...g})}break}default:{const p=o;throw new Error(`Unsupported role: ${p}`)}}}return r}function Sa({id:t,model:r,created:o}){return{id:t??void 0,modelId:r??void 0,timestamp:o!=null?new Date(o*1e3):void 0}}function Ta(t){switch(t){case"stop":return"stop";case"length":return"length";case"content_filter":return"content-filter";case"function_call":case"tool_calls":return"tool-calls";default:return"unknown"}}var xo=S({user:w().optional(),reasoningEffort:w().optional(),textVerbosity:w().optional()}),Ag=S({error:S({message:w(),type:w().nullish(),param:hr().nullish(),code:Pe([w(),Y()]).nullish()})}),Ig={errorSchema:Ag,errorToMessage:t=>t.error.message};function Sg({tools:t,toolChoice:r}){t=t?.length?t:void 0;const o=[];if(t==null)return{tools:void 0,toolChoice:void 0,toolWarnings:o};const c=[];for(const f of t)f.type==="provider-defined"?o.push({type:"unsupported-tool",tool:f}):c.push({type:"function",function:{name:f.name,description:f.description,parameters:f.inputSchema}});if(r==null)return{tools:c,toolChoice:void 0,toolWarnings:o};const u=r.type;switch(u){case"auto":case"none":case"required":return{tools:c,toolChoice:u,toolWarnings:o};case"tool":return{tools:c,toolChoice:{type:"function",function:{name:r.toolName}},toolWarnings:o};default:{const f=u;throw new pu({functionality:`tool choice type: ${f}`})}}}var Tg=class{constructor(t,r){this.specificationVersion="v2";var o,c;this.modelId=t,this.config=r;const u=(o=r.errorStructure)!=null?o:Ig;this.chunkSchema=Og(u.errorSchema),this.failedResponseHandler=xg(u),this.supportsStructuredOutputs=(c=r.supportsStructuredOutputs)!=null?c:!1}get provider(){return this.config.provider}get providerOptionsName(){return this.config.provider.split(".")[0].trim()}get supportedUrls(){var t,r,o;return(o=(r=(t=this.config).supportedUrls)==null?void 0:r.call(t))!=null?o:{}}async getArgs({prompt:t,maxOutputTokens:r,temperature:o,topP:c,topK:u,frequencyPenalty:f,presencePenalty:p,providerOptions:x,stopSequences:_,responseFormat:g,seed:A,toolChoice:E,tools:L}){var M,D,R,P;const H=[],Z=Object.assign((M=await Aa({provider:"openai-compatible",providerOptions:x,schema:xo}))!=null?M:{},(D=await Aa({provider:this.providerOptionsName,providerOptions:x,schema:xo}))!=null?D:{});u!=null&&H.push({type:"unsupported-setting",setting:"topK"}),g?.type==="json"&&g.schema!=null&&!this.supportsStructuredOutputs&&H.push({type:"unsupported-setting",setting:"responseFormat",details:"JSON response format schema is only supported with structuredOutputs"});const{tools:$,toolChoice:V,toolWarnings:ee}=Sg({tools:L,toolChoice:E});return{args:{model:this.modelId,user:Z.user,max_tokens:r,temperature:o,top_p:c,frequency_penalty:f,presence_penalty:p,response_format:g?.type==="json"?this.supportsStructuredOutputs===!0&&g.schema!=null?{type:"json_schema",json_schema:{schema:g.schema,name:(R=g.name)!=null?R:"response",description:g.description}}:{type:"json_object"}:void 0,stop:_,seed:A,...Object.fromEntries(Object.entries((P=x?.[this.providerOptionsName])!=null?P:{}).filter(([j])=>!Object.keys(xo.shape).includes(j))),reasoning_effort:Z.reasoningEffort,verbosity:Z.textVerbosity,messages:Eg(t),tools:$,tool_choice:V},warnings:[...H,...ee]}}async doGenerate(t){var r,o,c,u,f,p,x,_,g,A,E,L,M,D,R,P,H;const{args:Z,warnings:$}=await this.getArgs({...t}),V=JSON.stringify(Z),{responseHeaders:ee,value:j,rawValue:z}=await Ia({url:this.config.url({path:"/chat/completions",modelId:this.modelId}),headers:Ca(this.config.headers(),t.headers),body:Z,failedResponseHandler:this.failedResponseHandler,successfulResponseHandler:wg(Ng),abortSignal:t.abortSignal,fetch:this.config.fetch}),q=j.choices[0],B=[],we=q.message.content;we!=null&&we.length>0&&B.push({type:"text",text:we});const re=(r=q.message.reasoning_content)!=null?r:q.message.reasoning;if(re!=null&&re.length>0&&B.push({type:"reasoning",text:re}),q.message.tool_calls!=null)for(const te of q.message.tool_calls)B.push({type:"tool-call",toolCallId:(o=te.id)!=null?o:Ei(),toolName:te.function.name,input:te.function.arguments});const ne={[this.providerOptionsName]:{},...await((u=(c=this.config.metadataExtractor)==null?void 0:c.extractMetadata)==null?void 0:u.call(c,{parsedBody:z}))},le=(f=j.usage)==null?void 0:f.completion_tokens_details;return le?.accepted_prediction_tokens!=null&&(ne[this.providerOptionsName].acceptedPredictionTokens=le?.accepted_prediction_tokens),le?.rejected_prediction_tokens!=null&&(ne[this.providerOptionsName].rejectedPredictionTokens=le?.rejected_prediction_tokens),{content:B,finishReason:Ta(q.finish_reason),usage:{inputTokens:(x=(p=j.usage)==null?void 0:p.prompt_tokens)!=null?x:void 0,outputTokens:(g=(_=j.usage)==null?void 0:_.completion_tokens)!=null?g:void 0,totalTokens:(E=(A=j.usage)==null?void 0:A.total_tokens)!=null?E:void 0,reasoningTokens:(D=(M=(L=j.usage)==null?void 0:L.completion_tokens_details)==null?void 0:M.reasoning_tokens)!=null?D:void 0,cachedInputTokens:(H=(P=(R=j.usage)==null?void 0:R.prompt_tokens_details)==null?void 0:P.cached_tokens)!=null?H:void 0},providerMetadata:ne,request:{body:V},response:{...Sa(j),headers:ee,body:z},warnings:$}}async doStream(t){var r;const{args:o,warnings:c}=await this.getArgs({...t}),u={...o,stream:!0,stream_options:this.config.includeUsage?{include_usage:!0}:void 0},f=(r=this.config.metadataExtractor)==null?void 0:r.createStreamExtractor(),{responseHeaders:p,value:x}=await Ia({url:this.config.url({path:"/chat/completions",modelId:this.modelId}),headers:Ca(this.config.headers(),t.headers),body:u,failedResponseHandler:this.failedResponseHandler,successfulResponseHandler:yg(this.chunkSchema),abortSignal:t.abortSignal,fetch:this.config.fetch}),_=[];let g="unknown";const A={completionTokens:void 0,completionTokensDetails:{reasoningTokens:void 0,acceptedPredictionTokens:void 0,rejectedPredictionTokens:void 0},promptTokens:void 0,promptTokensDetails:{cachedTokens:void 0},totalTokens:void 0};let E=!0;const L=this.providerOptionsName;let M=!1,D=!1;return{stream:x.pipeThrough(new TransformStream({start(R){R.enqueue({type:"stream-start",warnings:c})},transform(R,P){var H,Z,$,V,ee,j,z,q,B,we,re,ne,le;if(t.includeRawChunks&&P.enqueue({type:"raw",rawValue:R.rawValue}),!R.success){g="error",P.enqueue({type:"error",error:R.error});return}const te=R.value;if(f?.processChunk(R.rawValue),"error"in te){g="error",P.enqueue({type:"error",error:te.error.message});return}if(E&&(E=!1,P.enqueue({type:"response-metadata",...Sa(te)})),te.usage!=null){const{prompt_tokens:oe,completion_tokens:ge,total_tokens:he,prompt_tokens_details:ue,completion_tokens_details:Ce}=te.usage;A.promptTokens=oe??void 0,A.completionTokens=ge??void 0,A.totalTokens=he??void 0,Ce?.reasoning_tokens!=null&&(A.completionTokensDetails.reasoningTokens=Ce?.reasoning_tokens),Ce?.accepted_prediction_tokens!=null&&(A.completionTokensDetails.acceptedPredictionTokens=Ce?.accepted_prediction_tokens),Ce?.rejected_prediction_tokens!=null&&(A.completionTokensDetails.rejectedPredictionTokens=Ce?.rejected_prediction_tokens),ue?.cached_tokens!=null&&(A.promptTokensDetails.cachedTokens=ue?.cached_tokens)}const O=te.choices[0];if(O?.finish_reason!=null&&(g=Ta(O.finish_reason)),O?.delta==null)return;const J=O.delta,ae=(H=J.reasoning_content)!=null?H:J.reasoning;if(ae&&(M||(P.enqueue({type:"reasoning-start",id:"reasoning-0"}),M=!0),P.enqueue({type:"reasoning-delta",id:"reasoning-0",delta:ae})),J.content&&(D||(P.enqueue({type:"text-start",id:"txt-0"}),D=!0),P.enqueue({type:"text-delta",id:"txt-0",delta:J.content})),J.tool_calls!=null)for(const oe of J.tool_calls){const ge=oe.index;if(_[ge]==null){if(oe.id==null)throw new _a({data:oe,message:"Expected 'id' to be a string."});if(((Z=oe.function)==null?void 0:Z.name)==null)throw new _a({data:oe,message:"Expected 'function.name' to be a string."});P.enqueue({type:"tool-input-start",id:oe.id,toolName:oe.function.name}),_[ge]={id:oe.id,type:"function",function:{name:oe.function.name,arguments:($=oe.function.arguments)!=null?$:""},hasFinished:!1};const ue=_[ge];((V=ue.function)==null?void 0:V.name)!=null&&((ee=ue.function)==null?void 0:ee.arguments)!=null&&(ue.function.arguments.length>0&&P.enqueue({type:"tool-input-delta",id:ue.id,delta:ue.function.arguments}),Ea(ue.function.arguments)&&(P.enqueue({type:"tool-input-end",id:ue.id}),P.enqueue({type:"tool-call",toolCallId:(j=ue.id)!=null?j:Ei(),toolName:ue.function.name,input:ue.function.arguments}),ue.hasFinished=!0));continue}const he=_[ge];he.hasFinished||(((z=oe.function)==null?void 0:z.arguments)!=null&&(he.function.arguments+=(B=(q=oe.function)==null?void 0:q.arguments)!=null?B:""),P.enqueue({type:"tool-input-delta",id:he.id,delta:(we=oe.function.arguments)!=null?we:""}),((re=he.function)==null?void 0:re.name)!=null&&((ne=he.function)==null?void 0:ne.arguments)!=null&&Ea(he.function.arguments)&&(P.enqueue({type:"tool-input-end",id:he.id}),P.enqueue({type:"tool-call",toolCallId:(le=he.id)!=null?le:Ei(),toolName:he.function.name,input:he.function.arguments}),he.hasFinished=!0))}},flush(R){var P,H,Z,$,V,ee;M&&R.enqueue({type:"reasoning-end",id:"reasoning-0"}),D&&R.enqueue({type:"text-end",id:"txt-0"});for(const z of _.filter(q=>!q.hasFinished))R.enqueue({type:"tool-input-end",id:z.id}),R.enqueue({type:"tool-call",toolCallId:(P=z.id)!=null?P:Ei(),toolName:z.function.name,input:z.function.arguments});const j={[L]:{},...f?.buildMetadata()};A.completionTokensDetails.acceptedPredictionTokens!=null&&(j[L].acceptedPredictionTokens=A.completionTokensDetails.acceptedPredictionTokens),A.completionTokensDetails.rejectedPredictionTokens!=null&&(j[L].rejectedPredictionTokens=A.completionTokensDetails.rejectedPredictionTokens),R.enqueue({type:"finish",finishReason:g,usage:{inputTokens:(H=A.promptTokens)!=null?H:void 0,outputTokens:(Z=A.completionTokens)!=null?Z:void 0,totalTokens:($=A.totalTokens)!=null?$:void 0,reasoningTokens:(V=A.completionTokensDetails.reasoningTokens)!=null?V:void 0,cachedInputTokens:(ee=A.promptTokensDetails.cachedTokens)!=null?ee:void 0},providerMetadata:j})}})),request:{body:u},response:{headers:p}}}},xu=S({prompt_tokens:Y().nullish(),completion_tokens:Y().nullish(),total_tokens:Y().nullish(),prompt_tokens_details:S({cached_tokens:Y().nullish()}).nullish(),completion_tokens_details:S({reasoning_tokens:Y().nullish(),accepted_prediction_tokens:Y().nullish(),rejected_prediction_tokens:Y().nullish()}).nullish()}).nullish(),Ng=S({id:w().nullish(),created:Y().nullish(),model:w().nullish(),choices:me(S({message:S({role:W("assistant").nullish(),content:w().nullish(),reasoning_content:w().nullish(),reasoning:w().nullish(),tool_calls:me(S({id:w().nullish(),function:S({name:w(),arguments:w()})})).nullish()}),finish_reason:w().nullish()})),usage:xu}),Og=t=>Pe([S({id:w().nullish(),created:Y().nullish(),model:w().nullish(),choices:me(S({delta:S({role:Fe(["assistant"]).nullish(),content:w().nullish(),reasoning_content:w().nullish(),reasoning:w().nullish(),tool_calls:me(S({index:Y(),id:w().nullish(),function:S({name:w().nullish(),arguments:w().nullish()})})).nullish()}).nullish(),finish_reason:w().nullish()})),usage:xu}),t]);S({echo:Nt().optional(),logitBias:gt(w(),Y()).optional(),suffix:w().optional(),user:w().optional()});var kg=S({prompt_tokens:Y(),completion_tokens:Y(),total_tokens:Y()});S({id:w().nullish(),created:Y().nullish(),model:w().nullish(),choices:me(S({text:w(),finish_reason:w()})),usage:kg.nullish()});S({dimensions:Y().optional(),user:w().optional()});S({data:me(S({embedding:me(Y())})),usage:S({prompt_tokens:Y()}).nullish(),providerMetadata:gt(w(),gt(w(),hr())).optional()});S({data:me(S({b64_json:w()}))});var Na=t=>{var r,o;return t==null?void 0:{deepseek:{promptCacheHitTokens:(r=t.prompt_cache_hit_tokens)!=null?r:NaN,promptCacheMissTokens:(o=t.prompt_cache_miss_tokens)!=null?o:NaN}}},Rg={extractMetadata:async({parsedBody:t})=>{const r=await ei({value:t,schema:Mg});return!r.success||r.value.usage==null?void 0:Na(r.value.usage)},createStreamExtractor:()=>{let t;return{processChunk:async r=>{var o,c;const u=await ei({value:r,schema:Dg});u.success&&((c=(o=u.value.choices)==null?void 0:o[0])==null?void 0:c.finish_reason)==="stop"&&u.value.usage&&(t=u.value.usage)},buildMetadata:()=>Na(t)}}},yu=S({prompt_cache_hit_tokens:Y().nullish(),prompt_cache_miss_tokens:Y().nullish()}),Mg=S({usage:yu.nullish()}),Dg=S({choices:me(S({finish_reason:w().nullish()})).nullish(),usage:yu.nullish()}),Pg="1.0.30";function wu(t={}){var r;const o=bg((r=t.baseURL)!=null?r:"https://api.deepseek.com/v1"),c=()=>mu({Authorization:`Bearer ${ig({apiKey:t.apiKey,environmentVariableName:"DEEPSEEK_API_KEY",description:"DeepSeek API key"})}`,...t.headers},`ai-sdk/deepseek/${Pg}`);class u extends Tg{addJsonInstruction(_){var g;if(((g=_.responseFormat)==null?void 0:g.type)!=="json")return _;const L=[...Array.isArray(_.prompt)?_.prompt:[],{role:"user",content:[{type:"text",text:"Return ONLY a valid JSON object."}]}];return{..._,prompt:L}}async doGenerate(_){return super.doGenerate(this.addJsonInstruction(_))}async doStream(_){return super.doStream(this.addJsonInstruction(_))}}const f=x=>new u(x,{provider:"deepseek.chat",url:({path:_})=>`${o}${_}`,headers:c,fetch:t.fetch,metadataExtractor:Rg}),p=x=>f(x);return p.languageModel=f,p.chat=f,p.textEmbeddingModel=x=>{throw new va({modelId:x,modelType:"textEmbeddingModel"})},p.imageModel=x=>{throw new va({modelId:x,modelType:"imageModel"})},p}wu();var es=S({error:S({message:w(),type:w().nullish(),param:hr().nullish(),code:Pe([w(),Y()]).nullish()})}),bn=dm({errorSchema:es,errorToMessage:t=>t.error.message});function _u(t){const r=t.startsWith("o3")||t.startsWith("o4-mini")||t.startsWith("gpt-5")&&!t.startsWith("gpt-5-chat"),o=t.startsWith("gpt-4")||t.startsWith("gpt-5-mini")||t.startsWith("gpt-5")&&!t.startsWith("gpt-5-nano")&&!t.startsWith("gpt-5-chat")||t.startsWith("o3")||t.startsWith("o4-mini"),c=t.startsWith("o1")||t.startsWith("o3")||t.startsWith("o4-mini")||t.startsWith("codex-mini")||t.startsWith("computer-use-preview")||t.startsWith("gpt-5")&&!t.startsWith("gpt-5-chat"),u=t.startsWith("gpt-5.1")||t.startsWith("gpt-5.2");return{supportsFlexProcessing:r,supportsPriorityProcessing:o,isReasoningModel:c,systemMessageMode:c?"developer":"system",supportsNonReasoningParameters:u}}function Oa(t){var r,o,c,u,f,p;if(t==null)return{inputTokens:{total:void 0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:void 0,text:void 0,reasoning:void 0},raw:void 0};const x=(r=t.prompt_tokens)!=null?r:0,_=(o=t.completion_tokens)!=null?o:0,g=(u=(c=t.prompt_tokens_details)==null?void 0:c.cached_tokens)!=null?u:0,A=(p=(f=t.completion_tokens_details)==null?void 0:f.reasoning_tokens)!=null?p:0;return{inputTokens:{total:x,noCache:x-g,cacheRead:g,cacheWrite:void 0},outputTokens:{total:_,text:_-A,reasoning:A},raw:t}}function Bg({prompt:t,systemMessageMode:r="system"}){var o;const c=[],u=[];for(const{role:f,content:p}of t)switch(f){case"system":{switch(r){case"system":{c.push({role:"system",content:p});break}case"developer":{c.push({role:"developer",content:p});break}case"remove":{u.push({type:"other",message:"system messages are removed for this model"});break}default:{const x=r;throw new Error(`Unsupported system message mode: ${x}`)}}break}case"user":{if(p.length===1&&p[0].type==="text"){c.push({role:"user",content:p[0].text});break}c.push({role:"user",content:p.map((x,_)=>{var g,A,E;switch(x.type){case"text":return{type:"text",text:x.text};case"file":if(x.mediaType.startsWith("image/")){const L=x.mediaType==="image/*"?"image/jpeg":x.mediaType;return{type:"image_url",image_url:{url:x.data instanceof URL?x.data.toString():`data:${L};base64,${Ar(x.data)}`,detail:(A=(g=x.providerOptions)==null?void 0:g.openai)==null?void 0:A.imageDetail}}}else if(x.mediaType.startsWith("audio/")){if(x.data instanceof URL)throw new Dn({functionality:"audio file parts with URLs"});switch(x.mediaType){case"audio/wav":return{type:"input_audio",input_audio:{data:Ar(x.data),format:"wav"}};case"audio/mp3":case"audio/mpeg":return{type:"input_audio",input_audio:{data:Ar(x.data),format:"mp3"}};default:throw new Dn({functionality:`audio content parts with media type ${x.mediaType}`})}}else if(x.mediaType==="application/pdf"){if(x.data instanceof URL)throw new Dn({functionality:"PDF file parts with URLs"});return{type:"file",file:typeof x.data=="string"&&x.data.startsWith("file-")?{file_id:x.data}:{filename:(E=x.filename)!=null?E:`part-${_}.pdf`,file_data:`data:application/pdf;base64,${Ar(x.data)}`}}}else throw new Dn({functionality:`file part media type ${x.mediaType}`})}})});break}case"assistant":{let x="";const _=[];for(const g of p)switch(g.type){case"text":{x+=g.text;break}case"tool-call":{_.push({id:g.toolCallId,type:"function",function:{name:g.toolName,arguments:JSON.stringify(g.input)}});break}}c.push({role:"assistant",content:x,tool_calls:_.length>0?_:void 0});break}case"tool":{for(const x of p){if(x.type==="tool-approval-response")continue;const _=x.output;let g;switch(_.type){case"text":case"error-text":g=_.value;break;case"execution-denied":g=(o=_.reason)!=null?o:"Tool execution denied.";break;case"content":case"json":case"error-json":g=JSON.stringify(_.value);break}c.push({role:"tool",tool_call_id:x.toolCallId,content:g})}break}default:{const x=f;throw new Error(`Unsupported role: ${x}`)}}return{messages:c,warnings:u}}function yo({id:t,model:r,created:o}){return{id:t??void 0,modelId:r??void 0,timestamp:o?new Date(o*1e3):void 0}}function ka(t){switch(t){case"stop":return"stop";case"length":return"length";case"content_filter":return"content-filter";case"function_call":case"tool_calls":return"tool-calls";default:return"other"}}var Lg=$e(()=>ze(S({id:w().nullish(),created:Y().nullish(),model:w().nullish(),choices:me(S({message:S({role:W("assistant").nullish(),content:w().nullish(),tool_calls:me(S({id:w().nullish(),type:W("function"),function:S({name:w(),arguments:w()})})).nullish(),annotations:me(S({type:W("url_citation"),url_citation:S({start_index:Y(),end_index:Y(),url:w(),title:w()})})).nullish()}),index:Y(),logprobs:S({content:me(S({token:w(),logprob:Y(),top_logprobs:me(S({token:w(),logprob:Y()}))})).nullish()}).nullish(),finish_reason:w().nullish()})),usage:S({prompt_tokens:Y().nullish(),completion_tokens:Y().nullish(),total_tokens:Y().nullish(),prompt_tokens_details:S({cached_tokens:Y().nullish()}).nullish(),completion_tokens_details:S({reasoning_tokens:Y().nullish(),accepted_prediction_tokens:Y().nullish(),rejected_prediction_tokens:Y().nullish()}).nullish()}).nullish()}))),Fg=$e(()=>ze(Pe([S({id:w().nullish(),created:Y().nullish(),model:w().nullish(),choices:me(S({delta:S({role:Fe(["assistant"]).nullish(),content:w().nullish(),tool_calls:me(S({index:Y(),id:w().nullish(),type:W("function").nullish(),function:S({name:w().nullish(),arguments:w().nullish()})})).nullish(),annotations:me(S({type:W("url_citation"),url_citation:S({start_index:Y(),end_index:Y(),url:w(),title:w()})})).nullish()}).nullish(),logprobs:S({content:me(S({token:w(),logprob:Y(),top_logprobs:me(S({token:w(),logprob:Y()}))})).nullish()}).nullish(),finish_reason:w().nullish(),index:Y()})),usage:S({prompt_tokens:Y().nullish(),completion_tokens:Y().nullish(),total_tokens:Y().nullish(),prompt_tokens_details:S({cached_tokens:Y().nullish()}).nullish(),completion_tokens_details:S({reasoning_tokens:Y().nullish(),accepted_prediction_tokens:Y().nullish(),rejected_prediction_tokens:Y().nullish()}).nullish()}).nullish()}),es]))),Ug=$e(()=>ze(S({logitBias:gt(Wh(),Y()).optional(),logprobs:Pe([Nt(),Y()]).optional(),parallelToolCalls:Nt().optional(),user:w().optional(),reasoningEffort:Fe(["none","minimal","low","medium","high","xhigh"]).optional(),maxCompletionTokens:Y().optional(),store:Nt().optional(),metadata:gt(w().max(64),w().max(512)).optional(),prediction:gt(w(),hr()).optional(),serviceTier:Fe(["auto","flex","priority","default"]).optional(),strictJsonSchema:Nt().optional(),textVerbosity:Fe(["low","medium","high"]).optional(),promptCacheKey:w().optional(),promptCacheRetention:Fe(["in_memory","24h"]).optional(),safetyIdentifier:w().optional(),systemMessageMode:Fe(["system","developer","remove"]).optional(),forceReasoning:Nt().optional()})));function zg({tools:t,toolChoice:r}){t=t?.length?t:void 0;const o=[];if(t==null)return{tools:void 0,toolChoice:void 0,toolWarnings:o};const c=[];for(const f of t)switch(f.type){case"function":c.push({type:"function",function:{name:f.name,description:f.description,parameters:f.inputSchema,...f.strict!=null?{strict:f.strict}:{}}});break;default:o.push({type:"unsupported",feature:`tool type: ${f.type}`});break}if(r==null)return{tools:c,toolChoice:void 0,toolWarnings:o};const u=r.type;switch(u){case"auto":case"none":case"required":return{tools:c,toolChoice:u,toolWarnings:o};case"tool":return{tools:c,toolChoice:{type:"function",function:{name:r.toolName}},toolWarnings:o};default:{const f=u;throw new Dn({functionality:`tool choice type: ${f}`})}}}var Vg=class{constructor(t,r){this.specificationVersion="v3",this.supportedUrls={"image/*":[/^https?:\/\/.*$/]},this.modelId=t,this.config=r}get provider(){return this.config.provider}async getArgs({prompt:t,maxOutputTokens:r,temperature:o,topP:c,topK:u,frequencyPenalty:f,presencePenalty:p,stopSequences:x,responseFormat:_,seed:g,tools:A,toolChoice:E,providerOptions:L}){var M,D,R,P,H;const Z=[],$=(M=await Bn({provider:"openai",providerOptions:L,schema:Ug}))!=null?M:{},V=_u(this.modelId),ee=(D=$.forceReasoning)!=null?D:V.isReasoningModel;u!=null&&Z.push({type:"unsupported",feature:"topK"});const{messages:j,warnings:z}=Bg({prompt:t,systemMessageMode:(R=$.systemMessageMode)!=null?R:ee?"developer":V.systemMessageMode});Z.push(...z);const q=(P=$.strictJsonSchema)!=null?P:!0,B={model:this.modelId,logit_bias:$.logitBias,logprobs:$.logprobs===!0||typeof $.logprobs=="number"?!0:void 0,top_logprobs:typeof $.logprobs=="number"?$.logprobs:typeof $.logprobs=="boolean"&&$.logprobs?0:void 0,user:$.user,parallel_tool_calls:$.parallelToolCalls,max_tokens:r,temperature:o,top_p:c,frequency_penalty:f,presence_penalty:p,response_format:_?.type==="json"?_.schema!=null?{type:"json_schema",json_schema:{schema:_.schema,strict:q,name:(H=_.name)!=null?H:"response",description:_.description}}:{type:"json_object"}:void 0,stop:x,seed:g,verbosity:$.textVerbosity,max_completion_tokens:$.maxCompletionTokens,store:$.store,metadata:$.metadata,prediction:$.prediction,reasoning_effort:$.reasoningEffort,service_tier:$.serviceTier,prompt_cache_key:$.promptCacheKey,prompt_cache_retention:$.promptCacheRetention,safety_identifier:$.safetyIdentifier,messages:j};ee?(($.reasoningEffort!=="none"||!V.supportsNonReasoningParameters)&&(B.temperature!=null&&(B.temperature=void 0,Z.push({type:"unsupported",feature:"temperature",details:"temperature is not supported for reasoning models"})),B.top_p!=null&&(B.top_p=void 0,Z.push({type:"unsupported",feature:"topP",details:"topP is not supported for reasoning models"})),B.logprobs!=null&&(B.logprobs=void 0,Z.push({type:"other",message:"logprobs is not supported for reasoning models"}))),B.frequency_penalty!=null&&(B.frequency_penalty=void 0,Z.push({type:"unsupported",feature:"frequencyPenalty",details:"frequencyPenalty is not supported for reasoning models"})),B.presence_penalty!=null&&(B.presence_penalty=void 0,Z.push({type:"unsupported",feature:"presencePenalty",details:"presencePenalty is not supported for reasoning models"})),B.logit_bias!=null&&(B.logit_bias=void 0,Z.push({type:"other",message:"logitBias is not supported for reasoning models"})),B.top_logprobs!=null&&(B.top_logprobs=void 0,Z.push({type:"other",message:"topLogprobs is not supported for reasoning models"})),B.max_tokens!=null&&(B.max_completion_tokens==null&&(B.max_completion_tokens=B.max_tokens),B.max_tokens=void 0)):(this.modelId.startsWith("gpt-4o-search-preview")||this.modelId.startsWith("gpt-4o-mini-search-preview"))&&B.temperature!=null&&(B.temperature=void 0,Z.push({type:"unsupported",feature:"temperature",details:"temperature is not supported for the search preview models and has been removed."})),$.serviceTier==="flex"&&!V.supportsFlexProcessing&&(Z.push({type:"unsupported",feature:"serviceTier",details:"flex processing is only available for o3, o4-mini, and gpt-5 models"}),B.service_tier=void 0),$.serviceTier==="priority"&&!V.supportsPriorityProcessing&&(Z.push({type:"unsupported",feature:"serviceTier",details:"priority processing is only available for supported models (gpt-4, gpt-5, gpt-5-mini, o3, o4-mini) and requires Enterprise access. gpt-5-nano is not supported"}),B.service_tier=void 0);const{tools:we,toolChoice:re,toolWarnings:ne}=zg({tools:A,toolChoice:E});return{args:{...B,tools:we,tool_choice:re},warnings:[...Z,...ne]}}async doGenerate(t){var r,o,c,u,f,p,x;const{args:_,warnings:g}=await this.getArgs(t),{responseHeaders:A,value:E,rawValue:L}=await Ln({url:this.config.url({path:"/chat/completions",modelId:this.modelId}),headers:Cn(this.config.headers(),t.headers),body:_,failedResponseHandler:bn,successfulResponseHandler:dr(Lg),abortSignal:t.abortSignal,fetch:this.config.fetch}),M=E.choices[0],D=[],R=M.message.content;R!=null&&R.length>0&&D.push({type:"text",text:R});for(const Z of(r=M.message.tool_calls)!=null?r:[])D.push({type:"tool-call",toolCallId:(o=Z.id)!=null?o:qt(),toolName:Z.function.name,input:Z.function.arguments});for(const Z of(c=M.message.annotations)!=null?c:[])D.push({type:"source",sourceType:"url",id:qt(),url:Z.url_citation.url,title:Z.url_citation.title});const P=(u=E.usage)==null?void 0:u.completion_tokens_details;(f=E.usage)==null||f.prompt_tokens_details;const H={openai:{}};return P?.accepted_prediction_tokens!=null&&(H.openai.acceptedPredictionTokens=P?.accepted_prediction_tokens),P?.rejected_prediction_tokens!=null&&(H.openai.rejectedPredictionTokens=P?.rejected_prediction_tokens),((p=M.logprobs)==null?void 0:p.content)!=null&&(H.openai.logprobs=M.logprobs.content),{content:D,finishReason:{unified:ka(M.finish_reason),raw:(x=M.finish_reason)!=null?x:void 0},usage:Oa(E.usage),request:{body:_},response:{...yo(E),headers:A,body:L},warnings:g,providerMetadata:H}}async doStream(t){const{args:r,warnings:o}=await this.getArgs(t),c={...r,stream:!0,stream_options:{include_usage:!0}},{responseHeaders:u,value:f}=await Ln({url:this.config.url({path:"/chat/completions",modelId:this.modelId}),headers:Cn(this.config.headers(),t.headers),body:c,failedResponseHandler:bn,successfulResponseHandler:Ko(Fg),abortSignal:t.abortSignal,fetch:this.config.fetch}),p=[];let x={unified:"other",raw:void 0},_,g=!1,A=!1;const E={openai:{}};return{stream:f.pipeThrough(new TransformStream({start(L){L.enqueue({type:"stream-start",warnings:o})},transform(L,M){var D,R,P,H,Z,$,V,ee,j,z,q,B,we,re,ne,le,te;if(t.includeRawChunks&&M.enqueue({type:"raw",rawValue:L.rawValue}),!L.success){x={unified:"error",raw:void 0},M.enqueue({type:"error",error:L.error});return}const O=L.value;if("error"in O){x={unified:"error",raw:void 0},M.enqueue({type:"error",error:O.error});return}if(!g){const oe=yo(O);Object.values(oe).some(Boolean)&&(g=!0,M.enqueue({type:"response-metadata",...yo(O)}))}O.usage!=null&&(_=O.usage,((D=O.usage.completion_tokens_details)==null?void 0:D.accepted_prediction_tokens)!=null&&(E.openai.acceptedPredictionTokens=(R=O.usage.completion_tokens_details)==null?void 0:R.accepted_prediction_tokens),((P=O.usage.completion_tokens_details)==null?void 0:P.rejected_prediction_tokens)!=null&&(E.openai.rejectedPredictionTokens=(H=O.usage.completion_tokens_details)==null?void 0:H.rejected_prediction_tokens));const J=O.choices[0];if(J?.finish_reason!=null&&(x={unified:ka(J.finish_reason),raw:J.finish_reason}),((Z=J?.logprobs)==null?void 0:Z.content)!=null&&(E.openai.logprobs=J.logprobs.content),J?.delta==null)return;const ae=J.delta;if(ae.content!=null&&(A||(M.enqueue({type:"text-start",id:"0"}),A=!0),M.enqueue({type:"text-delta",id:"0",delta:ae.content})),ae.tool_calls!=null)for(const oe of ae.tool_calls){const ge=oe.index;if(p[ge]==null){if(oe.type!=null&&oe.type!=="function")throw new uo({data:oe,message:"Expected 'function' type."});if(oe.id==null)throw new uo({data:oe,message:"Expected 'id' to be a string."});if((($=oe.function)==null?void 0:$.name)==null)throw new uo({data:oe,message:"Expected 'function.name' to be a string."});M.enqueue({type:"tool-input-start",id:oe.id,toolName:oe.function.name}),p[ge]={id:oe.id,type:"function",function:{name:oe.function.name,arguments:(V=oe.function.arguments)!=null?V:""},hasFinished:!1};const ue=p[ge];((ee=ue.function)==null?void 0:ee.name)!=null&&((j=ue.function)==null?void 0:j.arguments)!=null&&(ue.function.arguments.length>0&&M.enqueue({type:"tool-input-delta",id:ue.id,delta:ue.function.arguments}),ya(ue.function.arguments)&&(M.enqueue({type:"tool-input-end",id:ue.id}),M.enqueue({type:"tool-call",toolCallId:(z=ue.id)!=null?z:qt(),toolName:ue.function.name,input:ue.function.arguments}),ue.hasFinished=!0));continue}const he=p[ge];he.hasFinished||(((q=oe.function)==null?void 0:q.arguments)!=null&&(he.function.arguments+=(we=(B=oe.function)==null?void 0:B.arguments)!=null?we:""),M.enqueue({type:"tool-input-delta",id:he.id,delta:(re=oe.function.arguments)!=null?re:""}),((ne=he.function)==null?void 0:ne.name)!=null&&((le=he.function)==null?void 0:le.arguments)!=null&&ya(he.function.arguments)&&(M.enqueue({type:"tool-input-end",id:he.id}),M.enqueue({type:"tool-call",toolCallId:(te=he.id)!=null?te:qt(),toolName:he.function.name,input:he.function.arguments}),he.hasFinished=!0))}if(ae.annotations!=null)for(const oe of ae.annotations)M.enqueue({type:"source",sourceType:"url",id:qt(),url:oe.url_citation.url,title:oe.url_citation.title})},flush(L){A&&L.enqueue({type:"text-end",id:"0"}),L.enqueue({type:"finish",finishReason:x,usage:Oa(_),...E!=null?{providerMetadata:E}:{}})}})),request:{body:c},response:{headers:u}}}};function Ra(t){var r,o,c,u;if(t==null)return{inputTokens:{total:void 0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:void 0,text:void 0,reasoning:void 0},raw:void 0};const f=(r=t.prompt_tokens)!=null?r:0,p=(o=t.completion_tokens)!=null?o:0;return{inputTokens:{total:(c=t.prompt_tokens)!=null?c:void 0,noCache:f,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:(u=t.completion_tokens)!=null?u:void 0,text:p,reasoning:void 0},raw:t}}function $g({prompt:t,user:r="user",assistant:o="assistant"}){let c="";t[0].role==="system"&&(c+=`${t[0].content}
45
45
 
46
- `,t=t.slice(1));for(const{role:u,content:f}of t)switch(u){case"system":throw new Rd({message:"Unexpected system message in prompt: ${content}",prompt:t});case"user":{const p=f.map(x=>{switch(x.type){case"text":return x.text}}).filter(Boolean).join("");c+=`${r}:
46
+ `,t=t.slice(1));for(const{role:u,content:f}of t)switch(u){case"system":throw new Md({message:"Unexpected system message in prompt: ${content}",prompt:t});case"user":{const p=f.map(x=>{switch(x.type){case"text":return x.text}}).filter(Boolean).join("");c+=`${r}:
47
47
  ${p}
48
48
 
49
- `;break}case"assistant":{const p=f.map(x=>{switch(x.type){case"text":return x.text;case"tool-call":throw new Rn({functionality:"tool-call messages"})}}).join("");c+=`${o}:
49
+ `;break}case"assistant":{const p=f.map(x=>{switch(x.type){case"text":return x.text;case"tool-call":throw new Dn({functionality:"tool-call messages"})}}).join("");c+=`${o}:
50
50
  ${p}
51
51
 
52
- `;break}case"tool":throw new Rn({functionality:"tool messages"});default:{const p=u;throw new Error(`Unsupported role: ${p}`)}}return c+=`${o}:
52
+ `;break}case"tool":throw new Dn({functionality:"tool messages"});default:{const p=u;throw new Error(`Unsupported role: ${p}`)}}return c+=`${o}:
53
53
  `,{prompt:c,stopSequences:[`
54
- ${r}:`]}}function Ra({id:t,model:r,created:o}){return{id:t??void 0,modelId:r??void 0,timestamp:o!=null?new Date(o*1e3):void 0}}function Ma(t){switch(t){case"stop":return"stop";case"length":return"length";case"content_filter":return"content-filter";case"function_call":case"tool_calls":return"tool-calls";default:return"other"}}var $m=$e(()=>Ve(T({id:_().nullish(),created:X().nullish(),model:_().nullish(),choices:me(T({text:_(),finish_reason:_(),logprobs:T({tokens:me(_()),token_logprobs:me(X()),top_logprobs:me(pt(_(),X())).nullish()}).nullish()})),usage:T({prompt_tokens:X(),completion_tokens:X(),total_tokens:X()}).nullish()}))),Zm=$e(()=>Ve(Le([T({id:_().nullish(),created:X().nullish(),model:_().nullish(),choices:me(T({text:_(),finish_reason:_().nullish(),index:X(),logprobs:T({tokens:me(_()),token_logprobs:me(X()),top_logprobs:me(pt(_(),X())).nullish()}).nullish()})),usage:T({prompt_tokens:X(),completion_tokens:X(),total_tokens:X()}).nullish()}),Qo]))),Da=$e(()=>Ve(T({echo:At().optional(),logitBias:pt(_(),X()).optional(),suffix:_().optional(),user:_().optional(),logprobs:Le([At(),X()]).optional()}))),jm=class{constructor(t,r){this.specificationVersion="v3",this.supportedUrls={},this.modelId=t,this.config=r}get providerOptionsName(){return this.config.provider.split(".")[0].trim()}get provider(){return this.config.provider}async getArgs({prompt:t,maxOutputTokens:r,temperature:o,topP:c,topK:u,frequencyPenalty:f,presencePenalty:p,stopSequences:x,responseFormat:y,tools:m,toolChoice:A,seed:E,providerOptions:B}){const D=[],M={...await Dn({provider:"openai",providerOptions:B,schema:Da}),...await Dn({provider:this.providerOptionsName,providerOptions:B,schema:Da})};u!=null&&D.push({type:"unsupported",feature:"topK"}),m?.length&&D.push({type:"unsupported",feature:"tools"}),A!=null&&D.push({type:"unsupported",feature:"toolChoice"}),y!=null&&y.type!=="text"&&D.push({type:"unsupported",feature:"responseFormat",details:"JSON response format is not supported."});const{prompt:R,stopSequences:k}=Vm({prompt:t}),q=[...k??[],...x??[]];return{args:{model:this.modelId,echo:M.echo,logit_bias:M.logitBias,logprobs:M?.logprobs===!0?0:M?.logprobs===!1?void 0:M?.logprobs,suffix:M.suffix,user:M.user,max_tokens:r,temperature:o,top_p:c,frequency_penalty:f,presence_penalty:p,seed:E,prompt:R,stop:q.length>0?q:void 0},warnings:D}}async doGenerate(t){var r;const{args:o,warnings:c}=await this.getArgs(t),{responseHeaders:u,value:f,rawValue:p}=await Pn({url:this.config.url({path:"/completions",modelId:this.modelId}),headers:_n(this.config.headers(),t.headers),body:o,failedResponseHandler:vn,successfulResponseHandler:lr($m),abortSignal:t.abortSignal,fetch:this.config.fetch}),x=f.choices[0],y={openai:{}};return x.logprobs!=null&&(y.openai.logprobs=x.logprobs),{content:[{type:"text",text:x.text}],usage:ka(f.usage),finishReason:{unified:Ma(x.finish_reason),raw:(r=x.finish_reason)!=null?r:void 0},request:{body:o},response:{...Ra(f),headers:u,body:p},providerMetadata:y,warnings:c}}async doStream(t){const{args:r,warnings:o}=await this.getArgs(t),c={...r,stream:!0,stream_options:{include_usage:!0}},{responseHeaders:u,value:f}=await Pn({url:this.config.url({path:"/completions",modelId:this.modelId}),headers:_n(this.config.headers(),t.headers),body:c,failedResponseHandler:vn,successfulResponseHandler:Jo(Zm),abortSignal:t.abortSignal,fetch:this.config.fetch});let p={unified:"other",raw:void 0};const x={openai:{}};let y,m=!0;return{stream:f.pipeThrough(new TransformStream({start(A){A.enqueue({type:"stream-start",warnings:o})},transform(A,E){if(t.includeRawChunks&&E.enqueue({type:"raw",rawValue:A.rawValue}),!A.success){p={unified:"error",raw:void 0},E.enqueue({type:"error",error:A.error});return}const B=A.value;if("error"in B){p={unified:"error",raw:void 0},E.enqueue({type:"error",error:B.error});return}m&&(m=!1,E.enqueue({type:"response-metadata",...Ra(B)}),E.enqueue({type:"text-start",id:"0"})),B.usage!=null&&(y=B.usage);const D=B.choices[0];D?.finish_reason!=null&&(p={unified:Ma(D.finish_reason),raw:D.finish_reason}),D?.logprobs!=null&&(x.openai.logprobs=D.logprobs),D?.text!=null&&D.text.length>0&&E.enqueue({type:"text-delta",id:"0",delta:D.text})},flush(A){m||A.enqueue({type:"text-end",id:"0"}),A.enqueue({type:"finish",finishReason:p,providerMetadata:x,usage:ka(y)})}})),request:{body:c},response:{headers:u}}}},Hm=$e(()=>Ve(T({dimensions:X().optional(),user:_().optional()}))),Wm=$e(()=>Ve(T({data:me(T({embedding:me(X())})),usage:T({prompt_tokens:X()}).nullish()}))),Gm=class{constructor(t,r){this.specificationVersion="v3",this.maxEmbeddingsPerCall=2048,this.supportsParallelCalls=!0,this.modelId=t,this.config=r}get provider(){return this.config.provider}async doEmbed({values:t,headers:r,abortSignal:o,providerOptions:c}){var u;if(t.length>this.maxEmbeddingsPerCall)throw new Ld({provider:this.provider,modelId:this.modelId,maxEmbeddingsPerCall:this.maxEmbeddingsPerCall,values:t});const f=(u=await Dn({provider:"openai",providerOptions:c,schema:Hm}))!=null?u:{},{responseHeaders:p,value:x,rawValue:y}=await Pn({url:this.config.url({path:"/embeddings",modelId:this.modelId}),headers:_n(this.config.headers(),r),body:{model:this.modelId,input:t,encoding_format:"float",dimensions:f.dimensions,user:f.user},failedResponseHandler:vn,successfulResponseHandler:lr(Wm),abortSignal:o,fetch:this.config.fetch});return{warnings:[],embeddings:x.data.map(m=>m.embedding),usage:x.usage?{tokens:x.usage.prompt_tokens}:void 0,response:{headers:p,body:y}}}},Pa=$e(()=>Ve(T({created:X().nullish(),data:me(T({b64_json:_(),revised_prompt:_().nullish()})),background:_().nullish(),output_format:_().nullish(),size:_().nullish(),quality:_().nullish(),usage:T({input_tokens:X().nullish(),output_tokens:X().nullish(),total_tokens:X().nullish(),input_tokens_details:T({image_tokens:X().nullish(),text_tokens:X().nullish()}).nullish()}).nullish()}))),Xm={"dall-e-3":1,"dall-e-2":10,"gpt-image-1":10,"gpt-image-1-mini":10,"gpt-image-1.5":10},qm=["gpt-image-1-mini","gpt-image-1.5","gpt-image-1"];function Ym(t){return qm.some(r=>t.startsWith(r))}var Jm=class{constructor(t,r){this.modelId=t,this.config=r,this.specificationVersion="v3"}get maxImagesPerCall(){var t;return(t=Xm[this.modelId])!=null?t:1}get provider(){return this.config.provider}async doGenerate({prompt:t,files:r,mask:o,n:c,size:u,aspectRatio:f,seed:p,providerOptions:x,headers:y,abortSignal:m}){var A,E,B,D,M,R,k,q,Z,z,$;const Q=[];f!=null&&Q.push({type:"unsupported",feature:"aspectRatio",details:"This model does not support aspect ratio. Use `size` instead."}),p!=null&&Q.push({type:"unsupported",feature:"seed"});const O=(B=(E=(A=this.config._internal)==null?void 0:A.currentDate)==null?void 0:E.call(A))!=null?B:new Date;if(r!=null){const{value:j,responseHeaders:Ee}=await bc({url:this.config.url({path:"/images/edits",modelId:this.modelId}),headers:_n(this.config.headers(),y),formData:Qh({model:this.modelId,prompt:t,image:await Promise.all(r.map(de=>de.type==="file"?new Blob([de.data instanceof Uint8Array?new Blob([de.data],{type:de.mediaType}):new Blob([Go(de.data)],{type:de.mediaType})],{type:de.mediaType}):xc(de.url))),mask:o!=null?await Km(o):void 0,n:c,size:u,...(D=x.openai)!=null?D:{}}),failedResponseHandler:vn,successfulResponseHandler:lr(Pa),abortSignal:m,fetch:this.config.fetch});return{images:j.data.map(de=>de.b64_json),warnings:Q,usage:j.usage!=null?{inputTokens:(M=j.usage.input_tokens)!=null?M:void 0,outputTokens:(R=j.usage.output_tokens)!=null?R:void 0,totalTokens:(k=j.usage.total_tokens)!=null?k:void 0}:void 0,response:{timestamp:O,modelId:this.modelId,headers:Ee},providerMetadata:{openai:{images:j.data.map(de=>{var ne,oe,ee,P,H;return{...de.revised_prompt?{revisedPrompt:de.revised_prompt}:{},created:(ne=j.created)!=null?ne:void 0,size:(oe=j.size)!=null?oe:void 0,quality:(ee=j.quality)!=null?ee:void 0,background:(P=j.background)!=null?P:void 0,outputFormat:(H=j.output_format)!=null?H:void 0}})}}}}const{value:V,responseHeaders:le}=await Pn({url:this.config.url({path:"/images/generations",modelId:this.modelId}),headers:_n(this.config.headers(),y),body:{model:this.modelId,prompt:t,n:c,size:u,...(q=x.openai)!=null?q:{},...Ym(this.modelId)?{}:{response_format:"b64_json"}},failedResponseHandler:vn,successfulResponseHandler:lr(Pa),abortSignal:m,fetch:this.config.fetch});return{images:V.data.map(j=>j.b64_json),warnings:Q,usage:V.usage!=null?{inputTokens:(Z=V.usage.input_tokens)!=null?Z:void 0,outputTokens:(z=V.usage.output_tokens)!=null?z:void 0,totalTokens:($=V.usage.total_tokens)!=null?$:void 0}:void 0,response:{timestamp:O,modelId:this.modelId,headers:le},providerMetadata:{openai:{images:V.data.map(j=>{var Ee,de,ne,oe,ee;return{...j.revised_prompt?{revisedPrompt:j.revised_prompt}:{},created:(Ee=V.created)!=null?Ee:void 0,size:(de=V.size)!=null?de:void 0,quality:(ne=V.quality)!=null?ne:void 0,background:(oe=V.background)!=null?oe:void 0,outputFormat:(ee=V.output_format)!=null?ee:void 0}})}}}}};async function Km(t){if(!t)return;if(t.type==="url")return xc(t.url);const r=t.data instanceof Uint8Array?t.data:Go(t.data);return new Blob([r],{type:t.mediaType})}var yu=$e(()=>Ve(T({callId:_(),operation:Et("type",[T({type:Y("create_file"),path:_(),diff:_()}),T({type:Y("delete_file"),path:_()}),T({type:Y("update_file"),path:_(),diff:_()})])}))),_u=$e(()=>Ve(T({status:We(["completed","failed"]),output:_().optional()}))),Qm=Bn({id:"openai.apply_patch",inputSchema:yu,outputSchema:_u}),e2=Qm,t2=$e(()=>Ve(T({code:_().nullish(),containerId:_()}))),n2=$e(()=>Ve(T({outputs:me(Et("type",[T({type:Y("logs"),logs:_()}),T({type:Y("image"),url:_()})])).nullish()}))),r2=$e(()=>Ve(T({container:Le([_(),T({fileIds:me(_()).optional()})]).optional()}))),i2=Bn({id:"openai.code_interpreter",inputSchema:t2,outputSchema:n2}),o2=(t={})=>i2(t),vu=T({key:_(),type:We(["eq","ne","gt","gte","lt","lte","in","nin"]),value:Le([_(),X(),At(),me(_())])}),Cu=T({type:We(["and","or"]),filters:me(Le([vu,Ho(()=>Cu)]))}),s2=$e(()=>Ve(T({vectorStoreIds:me(_()),maxNumResults:X().optional(),ranking:T({ranker:_().optional(),scoreThreshold:X().optional()}).optional(),filters:Le([vu,Cu]).optional()}))),a2=$e(()=>Ve(T({queries:me(_()),results:me(T({attributes:pt(_(),Ir()),fileId:_(),filename:_(),score:X(),text:_()})).nullable()}))),l2=Bn({id:"openai.file_search",inputSchema:T({}),outputSchema:a2}),c2=$e(()=>Ve(T({background:We(["auto","opaque","transparent"]).optional(),inputFidelity:We(["low","high"]).optional(),inputImageMask:T({fileId:_().optional(),imageUrl:_().optional()}).optional(),model:_().optional(),moderation:We(["auto"]).optional(),outputCompression:X().int().min(0).max(100).optional(),outputFormat:We(["png","jpeg","webp"]).optional(),partialImages:X().int().min(0).max(3).optional(),quality:We(["auto","low","medium","high"]).optional(),size:We(["1024x1024","1024x1536","1536x1024","auto"]).optional()}).strict())),u2=$e(()=>Ve(T({}))),d2=$e(()=>Ve(T({result:_()}))),f2=Bn({id:"openai.image_generation",inputSchema:u2,outputSchema:d2}),h2=(t={})=>f2(t),bu=$e(()=>Ve(T({action:T({type:Y("exec"),command:me(_()),timeoutMs:X().optional(),user:_().optional(),workingDirectory:_().optional(),env:pt(_(),_()).optional()})}))),Eu=$e(()=>Ve(T({output:_()}))),p2=Bn({id:"openai.local_shell",inputSchema:bu,outputSchema:Eu}),Au=$e(()=>Ve(T({action:T({commands:me(_()),timeoutMs:X().optional(),maxOutputLength:X().optional()})}))),Iu=$e(()=>Ve(T({output:me(T({stdout:_(),stderr:_(),outcome:Et("type",[T({type:Y("timeout")}),T({type:Y("exit"),exitCode:X()})])}))}))),g2=Bn({id:"openai.shell",inputSchema:Au,outputSchema:Iu}),m2=$e(()=>Ve(T({externalWebAccess:At().optional(),filters:T({allowedDomains:me(_()).optional()}).optional(),searchContextSize:We(["low","medium","high"]).optional(),userLocation:T({type:Y("approximate"),country:_().optional(),city:_().optional(),region:_().optional(),timezone:_().optional()}).optional()}))),x2=$e(()=>Ve(T({}))),w2=$e(()=>Ve(T({action:Et("type",[T({type:Y("search"),query:_().optional()}),T({type:Y("openPage"),url:_().nullish()}),T({type:Y("findInPage"),url:_().nullish(),pattern:_().nullish()})]),sources:me(Et("type",[T({type:Y("url"),url:_()}),T({type:Y("api"),name:_()})])).optional()}))),y2=Bn({id:"openai.web_search",inputSchema:x2,outputSchema:w2}),_2=(t={})=>y2(t),v2=$e(()=>Ve(T({searchContextSize:We(["low","medium","high"]).optional(),userLocation:T({type:Y("approximate"),country:_().optional(),city:_().optional(),region:_().optional(),timezone:_().optional()}).optional()}))),C2=$e(()=>Ve(T({}))),b2=$e(()=>Ve(T({action:Et("type",[T({type:Y("search"),query:_().optional()}),T({type:Y("openPage"),url:_().nullish()}),T({type:Y("findInPage"),url:_().nullish(),pattern:_().nullish()})])}))),E2=Bn({id:"openai.web_search_preview",inputSchema:C2,outputSchema:b2}),Mo=Ho(()=>Le([_(),X(),At(),cc(),me(Mo),pt(_(),Mo)])),A2=$e(()=>Ve(T({serverLabel:_(),allowedTools:Le([me(_()),T({readOnly:At().optional(),toolNames:me(_()).optional()})]).optional(),authorization:_().optional(),connectorId:_().optional(),headers:pt(_(),_()).optional(),requireApproval:Le([We(["always","never"]),T({never:T({toolNames:me(_()).optional()}).optional()})]).optional(),serverDescription:_().optional(),serverUrl:_().optional()}).refine(t=>t.serverUrl!=null||t.connectorId!=null,"One of serverUrl or connectorId must be provided."))),I2=$e(()=>Ve(T({}))),S2=$e(()=>Ve(T({type:Y("call"),serverLabel:_(),name:_(),arguments:_(),output:_().nullish(),error:Le([_(),Mo]).optional()}))),T2=Bn({id:"openai.mcp",inputSchema:I2,outputSchema:S2}),N2=t=>T2(t),O2={applyPatch:e2,codeInterpreter:o2,fileSearch:l2,imageGeneration:h2,localShell:p2,shell:g2,webSearchPreview:E2,webSearch:_2,mcp:N2};function Ba(t){var r,o,c,u;if(t==null)return{inputTokens:{total:void 0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:void 0,text:void 0,reasoning:void 0},raw:void 0};const f=t.input_tokens,p=t.output_tokens,x=(o=(r=t.input_tokens_details)==null?void 0:r.cached_tokens)!=null?o:0,y=(u=(c=t.output_tokens_details)==null?void 0:c.reasoning_tokens)!=null?u:0;return{inputTokens:{total:f,noCache:f-x,cacheRead:x,cacheWrite:void 0},outputTokens:{total:p,text:p-y,reasoning:y},raw:t}}function La(t,r){return r?r.some(o=>t.startsWith(o)):!1}async function k2({prompt:t,toolNameMapping:r,systemMessageMode:o,providerOptionsName:c,fileIdPrefixes:u,store:f,hasConversation:p=!1,hasLocalShellTool:x=!1,hasShellTool:y=!1,hasApplyPatchTool:m=!1}){var A,E,B,D,M,R,k,q,Z,z,$,Q,O;const V=[],le=[],j=new Set;for(const{role:Ee,content:de}of t)switch(Ee){case"system":{switch(o){case"system":{V.push({role:"system",content:de});break}case"developer":{V.push({role:"developer",content:de});break}case"remove":{le.push({type:"other",message:"system messages are removed for this model"});break}default:{const ne=o;throw new Error(`Unsupported system message mode: ${ne}`)}}break}case"user":{V.push({role:"user",content:de.map((ne,oe)=>{var ee,P,H;switch(ne.type){case"text":return{type:"input_text",text:ne.text};case"file":if(ne.mediaType.startsWith("image/")){const re=ne.mediaType==="image/*"?"image/jpeg":ne.mediaType;return{type:"input_image",...ne.data instanceof URL?{image_url:ne.data.toString()}:typeof ne.data=="string"&&La(ne.data,u)?{file_id:ne.data}:{image_url:`data:${re};base64,${br(ne.data)}`},detail:(P=(ee=ne.providerOptions)==null?void 0:ee[c])==null?void 0:P.imageDetail}}else{if(ne.mediaType==="application/pdf")return ne.data instanceof URL?{type:"input_file",file_url:ne.data.toString()}:{type:"input_file",...typeof ne.data=="string"&&La(ne.data,u)?{file_id:ne.data}:{filename:(H=ne.filename)!=null?H:`part-${oe}.pdf`,file_data:`data:application/pdf;base64,${br(ne.data)}`}};throw new Rn({functionality:`file part media type ${ne.mediaType}`})}}})});break}case"assistant":{const ne={};for(const oe of de)switch(oe.type){case"text":{const ee=(E=(A=oe.providerOptions)==null?void 0:A[c])==null?void 0:E.itemId;if(p&&ee!=null)break;if(f&&ee!=null){V.push({type:"item_reference",id:ee});break}V.push({role:"assistant",content:[{type:"output_text",text:oe.text}],id:ee});break}case"tool-call":{const ee=(k=(D=(B=oe.providerOptions)==null?void 0:B[c])==null?void 0:D.itemId)!=null?k:(R=(M=oe.providerMetadata)==null?void 0:M[c])==null?void 0:R.itemId;if(p&&ee!=null)break;if(oe.providerExecuted){f&&ee!=null&&V.push({type:"item_reference",id:ee});break}if(f&&ee!=null){V.push({type:"item_reference",id:ee});break}const P=r.toProviderToolName(oe.toolName);if(x&&P==="local_shell"){const H=await rn({value:oe.input,schema:bu});V.push({type:"local_shell_call",call_id:oe.toolCallId,id:ee,action:{type:"exec",command:H.action.command,timeout_ms:H.action.timeoutMs,user:H.action.user,working_directory:H.action.workingDirectory,env:H.action.env}});break}if(y&&P==="shell"){const H=await rn({value:oe.input,schema:Au});V.push({type:"shell_call",call_id:oe.toolCallId,id:ee,status:"completed",action:{commands:H.action.commands,timeout_ms:H.action.timeoutMs,max_output_length:H.action.maxOutputLength}});break}if(m&&P==="apply_patch"){const H=await rn({value:oe.input,schema:yu});V.push({type:"apply_patch_call",call_id:H.callId,id:ee,status:"completed",operation:H.operation});break}V.push({type:"function_call",call_id:oe.toolCallId,name:P,arguments:JSON.stringify(oe.input),id:ee});break}case"tool-result":{if(oe.output.type==="execution-denied"||oe.output.type==="json"&&typeof oe.output.value=="object"&&oe.output.value!=null&&"type"in oe.output.value&&oe.output.value.type==="execution-denied"||p)break;if(f){const ee=(z=(Z=(q=oe.providerMetadata)==null?void 0:q[c])==null?void 0:Z.itemId)!=null?z:oe.toolCallId;V.push({type:"item_reference",id:ee})}else le.push({type:"other",message:`Results for OpenAI tool ${oe.toolName} are not sent to the API when store is false`});break}case"reasoning":{const ee=await Dn({provider:c,providerOptions:oe.providerOptions,schema:R2}),P=ee?.itemId;if(p&&P!=null)break;if(P!=null){const H=ne[P];if(f)H===void 0&&(V.push({type:"item_reference",id:P}),ne[P]={type:"reasoning",id:P,summary:[]});else{const re=[];oe.text.length>0?re.push({type:"summary_text",text:oe.text}):H!==void 0&&le.push({type:"other",message:`Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(oe)}.`}),H===void 0?(ne[P]={type:"reasoning",id:P,encrypted_content:ee?.reasoningEncryptedContent,summary:re},V.push(ne[P])):(H.summary.push(...re),ee?.reasoningEncryptedContent!=null&&(H.encrypted_content=ee.reasoningEncryptedContent))}}else le.push({type:"other",message:`Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(oe)}.`});break}}break}case"tool":{for(const ne of de){if(ne.type==="tool-approval-response"){const H=ne;if(j.has(H.approvalId))continue;j.add(H.approvalId),f&&V.push({type:"item_reference",id:H.approvalId}),V.push({type:"mcp_approval_response",approval_request_id:H.approvalId,approve:H.approved});continue}const oe=ne.output;if(oe.type==="execution-denied"&&((Q=($=oe.providerOptions)==null?void 0:$.openai)==null?void 0:Q.approvalId))continue;const ee=r.toProviderToolName(ne.toolName);if(x&&ee==="local_shell"&&oe.type==="json"){const H=await rn({value:oe.value,schema:Eu});V.push({type:"local_shell_call_output",call_id:ne.toolCallId,output:H.output});continue}if(y&&ee==="shell"&&oe.type==="json"){const H=await rn({value:oe.value,schema:Iu});V.push({type:"shell_call_output",call_id:ne.toolCallId,output:H.output.map(re=>({stdout:re.stdout,stderr:re.stderr,outcome:re.outcome.type==="timeout"?{type:"timeout"}:{type:"exit",exit_code:re.outcome.exitCode}}))});continue}if(m&&ne.toolName==="apply_patch"&&oe.type==="json"){const H=await rn({value:oe.value,schema:_u});V.push({type:"apply_patch_call_output",call_id:ne.toolCallId,status:H.status,output:H.output});continue}let P;switch(oe.type){case"text":case"error-text":P=oe.value;break;case"execution-denied":P=(O=oe.reason)!=null?O:"Tool execution denied.";break;case"json":case"error-json":P=JSON.stringify(oe.value);break;case"content":P=oe.value.map(H=>{var re;switch(H.type){case"text":return{type:"input_text",text:H.text};case"image-data":return{type:"input_image",image_url:`data:${H.mediaType};base64,${H.data}`};case"image-url":return{type:"input_image",image_url:H.url};case"file-data":return{type:"input_file",filename:(re=H.filename)!=null?re:"data",file_data:`data:${H.mediaType};base64,${H.data}`};default:{le.push({type:"other",message:`unsupported tool content part type: ${H.type}`});return}}}).filter(cp);break}V.push({type:"function_call_output",call_id:ne.toolCallId,output:P})}break}default:{const ne=Ee;throw new Error(`Unsupported role: ${ne}`)}}return{input:V,warnings:le}}var R2=T({itemId:_().nullish(),reasoningEncryptedContent:_().nullish()});function Fa({finishReason:t,hasFunctionCall:r}){switch(t){case void 0:case null:return r?"tool-calls":"stop";case"max_output_tokens":return"length";case"content_filter":return"content-filter";default:return r?"tool-calls":"other"}}var M2=$e(()=>Ve(Le([T({type:Y("response.output_text.delta"),item_id:_(),delta:_(),logprobs:me(T({token:_(),logprob:X(),top_logprobs:me(T({token:_(),logprob:X()}))})).nullish()}),T({type:We(["response.completed","response.incomplete"]),response:T({incomplete_details:T({reason:_()}).nullish(),usage:T({input_tokens:X(),input_tokens_details:T({cached_tokens:X().nullish()}).nullish(),output_tokens:X(),output_tokens_details:T({reasoning_tokens:X().nullish()}).nullish()}),service_tier:_().nullish()})}),T({type:Y("response.created"),response:T({id:_(),created_at:X(),model:_(),service_tier:_().nullish()})}),T({type:Y("response.output_item.added"),output_index:X(),item:Et("type",[T({type:Y("message"),id:_()}),T({type:Y("reasoning"),id:_(),encrypted_content:_().nullish()}),T({type:Y("function_call"),id:_(),call_id:_(),name:_(),arguments:_()}),T({type:Y("web_search_call"),id:_(),status:_()}),T({type:Y("computer_call"),id:_(),status:_()}),T({type:Y("file_search_call"),id:_()}),T({type:Y("image_generation_call"),id:_()}),T({type:Y("code_interpreter_call"),id:_(),container_id:_(),code:_().nullable(),outputs:me(Et("type",[T({type:Y("logs"),logs:_()}),T({type:Y("image"),url:_()})])).nullable(),status:_()}),T({type:Y("mcp_call"),id:_(),status:_(),approval_request_id:_().nullish()}),T({type:Y("mcp_list_tools"),id:_()}),T({type:Y("mcp_approval_request"),id:_()}),T({type:Y("apply_patch_call"),id:_(),call_id:_(),status:We(["in_progress","completed"]),operation:Et("type",[T({type:Y("create_file"),path:_(),diff:_()}),T({type:Y("delete_file"),path:_()}),T({type:Y("update_file"),path:_(),diff:_()})])}),T({type:Y("shell_call"),id:_(),call_id:_(),status:We(["in_progress","completed","incomplete"]),action:T({commands:me(_())})})])}),T({type:Y("response.output_item.done"),output_index:X(),item:Et("type",[T({type:Y("message"),id:_()}),T({type:Y("reasoning"),id:_(),encrypted_content:_().nullish()}),T({type:Y("function_call"),id:_(),call_id:_(),name:_(),arguments:_(),status:Y("completed")}),T({type:Y("code_interpreter_call"),id:_(),code:_().nullable(),container_id:_(),outputs:me(Et("type",[T({type:Y("logs"),logs:_()}),T({type:Y("image"),url:_()})])).nullable()}),T({type:Y("image_generation_call"),id:_(),result:_()}),T({type:Y("web_search_call"),id:_(),status:_(),action:Et("type",[T({type:Y("search"),query:_().nullish(),sources:me(Et("type",[T({type:Y("url"),url:_()}),T({type:Y("api"),name:_()})])).nullish()}),T({type:Y("open_page"),url:_().nullish()}),T({type:Y("find_in_page"),url:_().nullish(),pattern:_().nullish()})])}),T({type:Y("file_search_call"),id:_(),queries:me(_()),results:me(T({attributes:pt(_(),Le([_(),X(),At()])),file_id:_(),filename:_(),score:X(),text:_()})).nullish()}),T({type:Y("local_shell_call"),id:_(),call_id:_(),action:T({type:Y("exec"),command:me(_()),timeout_ms:X().optional(),user:_().optional(),working_directory:_().optional(),env:pt(_(),_()).optional()})}),T({type:Y("computer_call"),id:_(),status:Y("completed")}),T({type:Y("mcp_call"),id:_(),status:_(),arguments:_(),name:_(),server_label:_(),output:_().nullish(),error:Le([_(),T({type:_().optional(),code:Le([X(),_()]).optional(),message:_().optional()}).loose()]).nullish(),approval_request_id:_().nullish()}),T({type:Y("mcp_list_tools"),id:_(),server_label:_(),tools:me(T({name:_(),description:_().optional(),input_schema:ur(),annotations:pt(_(),Ir()).optional()})),error:Le([_(),T({type:_().optional(),code:Le([X(),_()]).optional(),message:_().optional()}).loose()]).optional()}),T({type:Y("mcp_approval_request"),id:_(),server_label:_(),name:_(),arguments:_(),approval_request_id:_().optional()}),T({type:Y("apply_patch_call"),id:_(),call_id:_(),status:We(["in_progress","completed"]),operation:Et("type",[T({type:Y("create_file"),path:_(),diff:_()}),T({type:Y("delete_file"),path:_()}),T({type:Y("update_file"),path:_(),diff:_()})])}),T({type:Y("shell_call"),id:_(),call_id:_(),status:We(["in_progress","completed","incomplete"]),action:T({commands:me(_())})})])}),T({type:Y("response.function_call_arguments.delta"),item_id:_(),output_index:X(),delta:_()}),T({type:Y("response.image_generation_call.partial_image"),item_id:_(),output_index:X(),partial_image_b64:_()}),T({type:Y("response.code_interpreter_call_code.delta"),item_id:_(),output_index:X(),delta:_()}),T({type:Y("response.code_interpreter_call_code.done"),item_id:_(),output_index:X(),code:_()}),T({type:Y("response.output_text.annotation.added"),annotation:Et("type",[T({type:Y("url_citation"),start_index:X(),end_index:X(),url:_(),title:_()}),T({type:Y("file_citation"),file_id:_(),filename:_(),index:X()}),T({type:Y("container_file_citation"),container_id:_(),file_id:_(),filename:_(),start_index:X(),end_index:X()}),T({type:Y("file_path"),file_id:_(),index:X()})])}),T({type:Y("response.reasoning_summary_part.added"),item_id:_(),summary_index:X()}),T({type:Y("response.reasoning_summary_text.delta"),item_id:_(),summary_index:X(),delta:_()}),T({type:Y("response.reasoning_summary_part.done"),item_id:_(),summary_index:X()}),T({type:Y("response.apply_patch_call_operation_diff.delta"),item_id:_(),output_index:X(),delta:_(),obfuscation:_().nullish()}),T({type:Y("response.apply_patch_call_operation_diff.done"),item_id:_(),output_index:X(),diff:_()}),T({type:Y("error"),sequence_number:X(),error:T({type:_(),code:_(),message:_(),param:_().nullish()})}),T({type:_()}).loose().transform(t=>({type:"unknown_chunk",message:t.type}))]))),D2=$e(()=>Ve(T({id:_().optional(),created_at:X().optional(),error:T({message:_(),type:_(),param:_().nullish(),code:_()}).nullish(),model:_().optional(),output:me(Et("type",[T({type:Y("message"),role:Y("assistant"),id:_(),content:me(T({type:Y("output_text"),text:_(),logprobs:me(T({token:_(),logprob:X(),top_logprobs:me(T({token:_(),logprob:X()}))})).nullish(),annotations:me(Et("type",[T({type:Y("url_citation"),start_index:X(),end_index:X(),url:_(),title:_()}),T({type:Y("file_citation"),file_id:_(),filename:_(),index:X()}),T({type:Y("container_file_citation"),container_id:_(),file_id:_(),filename:_(),start_index:X(),end_index:X()}),T({type:Y("file_path"),file_id:_(),index:X()})]))}))}),T({type:Y("web_search_call"),id:_(),status:_(),action:Et("type",[T({type:Y("search"),query:_().nullish(),sources:me(Et("type",[T({type:Y("url"),url:_()}),T({type:Y("api"),name:_()})])).nullish()}),T({type:Y("open_page"),url:_().nullish()}),T({type:Y("find_in_page"),url:_().nullish(),pattern:_().nullish()})])}),T({type:Y("file_search_call"),id:_(),queries:me(_()),results:me(T({attributes:pt(_(),Le([_(),X(),At()])),file_id:_(),filename:_(),score:X(),text:_()})).nullish()}),T({type:Y("code_interpreter_call"),id:_(),code:_().nullable(),container_id:_(),outputs:me(Et("type",[T({type:Y("logs"),logs:_()}),T({type:Y("image"),url:_()})])).nullable()}),T({type:Y("image_generation_call"),id:_(),result:_()}),T({type:Y("local_shell_call"),id:_(),call_id:_(),action:T({type:Y("exec"),command:me(_()),timeout_ms:X().optional(),user:_().optional(),working_directory:_().optional(),env:pt(_(),_()).optional()})}),T({type:Y("function_call"),call_id:_(),name:_(),arguments:_(),id:_()}),T({type:Y("computer_call"),id:_(),status:_().optional()}),T({type:Y("reasoning"),id:_(),encrypted_content:_().nullish(),summary:me(T({type:Y("summary_text"),text:_()}))}),T({type:Y("mcp_call"),id:_(),status:_(),arguments:_(),name:_(),server_label:_(),output:_().nullish(),error:Le([_(),T({type:_().optional(),code:Le([X(),_()]).optional(),message:_().optional()}).loose()]).nullish(),approval_request_id:_().nullish()}),T({type:Y("mcp_list_tools"),id:_(),server_label:_(),tools:me(T({name:_(),description:_().optional(),input_schema:ur(),annotations:pt(_(),Ir()).optional()})),error:Le([_(),T({type:_().optional(),code:Le([X(),_()]).optional(),message:_().optional()}).loose()]).optional()}),T({type:Y("mcp_approval_request"),id:_(),server_label:_(),name:_(),arguments:_(),approval_request_id:_().optional()}),T({type:Y("apply_patch_call"),id:_(),call_id:_(),status:We(["in_progress","completed"]),operation:Et("type",[T({type:Y("create_file"),path:_(),diff:_()}),T({type:Y("delete_file"),path:_()}),T({type:Y("update_file"),path:_(),diff:_()})])}),T({type:Y("shell_call"),id:_(),call_id:_(),status:We(["in_progress","completed","incomplete"]),action:T({commands:me(_())})})])).optional(),service_tier:_().nullish(),incomplete_details:T({reason:_()}).nullish(),usage:T({input_tokens:X(),input_tokens_details:T({cached_tokens:X().nullish()}).nullish(),output_tokens:X(),output_tokens_details:T({reasoning_tokens:X().nullish()}).nullish()}).optional()}))),Su=20,Ua=$e(()=>Ve(T({conversation:_().nullish(),include:me(We(["reasoning.encrypted_content","file_search_call.results","message.output_text.logprobs"])).nullish(),instructions:_().nullish(),logprobs:Le([At(),X().min(1).max(Su)]).optional(),maxToolCalls:X().nullish(),metadata:ur().nullish(),parallelToolCalls:At().nullish(),previousResponseId:_().nullish(),promptCacheKey:_().nullish(),promptCacheRetention:We(["in_memory","24h"]).nullish(),reasoningEffort:_().nullish(),reasoningSummary:_().nullish(),safetyIdentifier:_().nullish(),serviceTier:We(["auto","flex","priority","default"]).nullish(),store:At().nullish(),strictJsonSchema:At().nullish(),textVerbosity:We(["low","medium","high"]).nullish(),truncation:We(["auto","disabled"]).nullish(),user:_().nullish(),systemMessageMode:We(["system","developer","remove"]).optional(),forceReasoning:At().optional()})));async function P2({tools:t,toolChoice:r}){t=t?.length?t:void 0;const o=[];if(t==null)return{tools:void 0,toolChoice:void 0,toolWarnings:o};const c=[];for(const f of t)switch(f.type){case"function":c.push({type:"function",name:f.name,description:f.description,parameters:f.inputSchema,...f.strict!=null?{strict:f.strict}:{}});break;case"provider":{switch(f.id){case"openai.file_search":{const p=await rn({value:f.args,schema:s2});c.push({type:"file_search",vector_store_ids:p.vectorStoreIds,max_num_results:p.maxNumResults,ranking_options:p.ranking?{ranker:p.ranking.ranker,score_threshold:p.ranking.scoreThreshold}:void 0,filters:p.filters});break}case"openai.local_shell":{c.push({type:"local_shell"});break}case"openai.shell":{c.push({type:"shell"});break}case"openai.apply_patch":{c.push({type:"apply_patch"});break}case"openai.web_search_preview":{const p=await rn({value:f.args,schema:v2});c.push({type:"web_search_preview",search_context_size:p.searchContextSize,user_location:p.userLocation});break}case"openai.web_search":{const p=await rn({value:f.args,schema:m2});c.push({type:"web_search",filters:p.filters!=null?{allowed_domains:p.filters.allowedDomains}:void 0,external_web_access:p.externalWebAccess,search_context_size:p.searchContextSize,user_location:p.userLocation});break}case"openai.code_interpreter":{const p=await rn({value:f.args,schema:r2});c.push({type:"code_interpreter",container:p.container==null?{type:"auto",file_ids:void 0}:typeof p.container=="string"?p.container:{type:"auto",file_ids:p.container.fileIds}});break}case"openai.image_generation":{const p=await rn({value:f.args,schema:c2});c.push({type:"image_generation",background:p.background,input_fidelity:p.inputFidelity,input_image_mask:p.inputImageMask?{file_id:p.inputImageMask.fileId,image_url:p.inputImageMask.imageUrl}:void 0,model:p.model,moderation:p.moderation,partial_images:p.partialImages,quality:p.quality,output_compression:p.outputCompression,output_format:p.outputFormat,size:p.size});break}case"openai.mcp":{const p=await rn({value:f.args,schema:A2}),x=A=>({tool_names:A.toolNames}),y=p.requireApproval,m=y==null?void 0:typeof y=="string"?y:y.never!=null?{never:x(y.never)}:void 0;c.push({type:"mcp",server_label:p.serverLabel,allowed_tools:Array.isArray(p.allowedTools)?p.allowedTools:p.allowedTools?{read_only:p.allowedTools.readOnly,tool_names:p.allowedTools.toolNames}:void 0,authorization:p.authorization,connector_id:p.connectorId,headers:p.headers,require_approval:m??"never",server_description:p.serverDescription,server_url:p.serverUrl});break}}break}default:o.push({type:"unsupported",feature:`function tool ${f}`});break}if(r==null)return{tools:c,toolChoice:void 0,toolWarnings:o};const u=r.type;switch(u){case"auto":case"none":case"required":return{tools:c,toolChoice:u,toolWarnings:o};case"tool":return{tools:c,toolChoice:r.toolName==="code_interpreter"||r.toolName==="file_search"||r.toolName==="image_generation"||r.toolName==="web_search_preview"||r.toolName==="web_search"||r.toolName==="mcp"||r.toolName==="apply_patch"?{type:r.toolName}:{type:"function",name:r.toolName},toolWarnings:o};default:{const f=u;throw new Rn({functionality:`tool choice type: ${f}`})}}}function za(t){var r,o;const c={};for(const u of t)if(u.role==="assistant")for(const f of u.content){if(f.type!=="tool-call")continue;const p=(o=(r=f.providerOptions)==null?void 0:r.openai)==null?void 0:o.approvalRequestId;p!=null&&(c[p]=f.toolCallId)}return c}var B2=class{constructor(t,r){this.specificationVersion="v3",this.supportedUrls={"image/*":[/^https?:\/\/.*$/],"application/pdf":[/^https?:\/\/.*$/]},this.modelId=t,this.config=r}get provider(){return this.config.provider}async getArgs({maxOutputTokens:t,temperature:r,stopSequences:o,topP:c,topK:u,presencePenalty:f,frequencyPenalty:p,seed:x,prompt:y,providerOptions:m,tools:A,toolChoice:E,responseFormat:B}){var D,M,R,k,q,Z;const z=[],$=wu(this.modelId);u!=null&&z.push({type:"unsupported",feature:"topK"}),x!=null&&z.push({type:"unsupported",feature:"seed"}),f!=null&&z.push({type:"unsupported",feature:"presencePenalty"}),p!=null&&z.push({type:"unsupported",feature:"frequencyPenalty"}),o!=null&&z.push({type:"unsupported",feature:"stopSequences"});const Q=this.config.provider.includes("azure")?"azure":"openai";let O=await Dn({provider:Q,providerOptions:m,schema:Ua});O==null&&Q!=="openai"&&(O=await Dn({provider:"openai",providerOptions:m,schema:Ua}));const V=(D=O?.forceReasoning)!=null?D:$.isReasoningModel;O?.conversation&&O?.previousResponseId&&z.push({type:"unsupported",feature:"conversation",details:"conversation and previousResponseId cannot be used together"});const le=Xh({tools:A,providerToolNames:{"openai.code_interpreter":"code_interpreter","openai.file_search":"file_search","openai.image_generation":"image_generation","openai.local_shell":"local_shell","openai.shell":"shell","openai.web_search":"web_search","openai.web_search_preview":"web_search_preview","openai.mcp":"mcp","openai.apply_patch":"apply_patch"}}),{input:j,warnings:Ee}=await k2({prompt:y,toolNameMapping:le,systemMessageMode:(M=O?.systemMessageMode)!=null?M:V?"developer":$.systemMessageMode,providerOptionsName:Q,fileIdPrefixes:this.config.fileIdPrefixes,store:(R=O?.store)!=null?R:!0,hasConversation:O?.conversation!=null,hasLocalShellTool:ee("openai.local_shell"),hasShellTool:ee("openai.shell"),hasApplyPatchTool:ee("openai.apply_patch")});z.push(...Ee);const de=(k=O?.strictJsonSchema)!=null?k:!0;let ne=O?.include;function oe(_e){ne==null?ne=[_e]:ne.includes(_e)||(ne=[...ne,_e])}function ee(_e){return A?.find(Ze=>Ze.type==="provider"&&Ze.id===_e)!=null}const P=typeof O?.logprobs=="number"?O?.logprobs:O?.logprobs===!0?Su:void 0;P&&oe("message.output_text.logprobs");const H=(q=A?.find(_e=>_e.type==="provider"&&(_e.id==="openai.web_search"||_e.id==="openai.web_search_preview")))==null?void 0:q.name;H&&oe("web_search_call.action.sources"),ee("openai.code_interpreter")&&oe("code_interpreter_call.outputs");const re=O?.store;re===!1&&V&&oe("reasoning.encrypted_content");const te={model:this.modelId,input:j,temperature:r,top_p:c,max_output_tokens:t,...(B?.type==="json"||O?.textVerbosity)&&{text:{...B?.type==="json"&&{format:B.schema!=null?{type:"json_schema",strict:de,name:(Z=B.name)!=null?Z:"response",description:B.description,schema:B.schema}:{type:"json_object"}},...O?.textVerbosity&&{verbosity:O.textVerbosity}}},conversation:O?.conversation,max_tool_calls:O?.maxToolCalls,metadata:O?.metadata,parallel_tool_calls:O?.parallelToolCalls,previous_response_id:O?.previousResponseId,store:re,user:O?.user,instructions:O?.instructions,service_tier:O?.serviceTier,include:ne,prompt_cache_key:O?.promptCacheKey,prompt_cache_retention:O?.promptCacheRetention,safety_identifier:O?.safetyIdentifier,top_logprobs:P,truncation:O?.truncation,...V&&(O?.reasoningEffort!=null||O?.reasoningSummary!=null)&&{reasoning:{...O?.reasoningEffort!=null&&{effort:O.reasoningEffort},...O?.reasoningSummary!=null&&{summary:O.reasoningSummary}}}};V?O?.reasoningEffort==="none"&&$.supportsNonReasoningParameters||(te.temperature!=null&&(te.temperature=void 0,z.push({type:"unsupported",feature:"temperature",details:"temperature is not supported for reasoning models"})),te.top_p!=null&&(te.top_p=void 0,z.push({type:"unsupported",feature:"topP",details:"topP is not supported for reasoning models"}))):(O?.reasoningEffort!=null&&z.push({type:"unsupported",feature:"reasoningEffort",details:"reasoningEffort is not supported for non-reasoning models"}),O?.reasoningSummary!=null&&z.push({type:"unsupported",feature:"reasoningSummary",details:"reasoningSummary is not supported for non-reasoning models"})),O?.serviceTier==="flex"&&!$.supportsFlexProcessing&&(z.push({type:"unsupported",feature:"serviceTier",details:"flex processing is only available for o3, o4-mini, and gpt-5 models"}),delete te.service_tier),O?.serviceTier==="priority"&&!$.supportsPriorityProcessing&&(z.push({type:"unsupported",feature:"serviceTier",details:"priority processing is only available for supported models (gpt-4, gpt-5, gpt-5-mini, o3, o4-mini) and requires Enterprise access. gpt-5-nano is not supported"}),delete te.service_tier);const{tools:we,toolChoice:se,toolWarnings:ye}=await P2({tools:A,toolChoice:E});return{webSearchToolName:H,args:{...te,tools:we,tool_choice:se},warnings:[...z,...ye],store:re,toolNameMapping:le,providerOptionsName:Q}}async doGenerate(t){var r,o,c,u,f,p,x,y,m,A,E,B,D,M,R,k,q,Z,z,$,Q,O,V,le,j;const{args:Ee,warnings:de,webSearchToolName:ne,toolNameMapping:oe,providerOptionsName:ee}=await this.getArgs(t),P=this.config.url({path:"/responses",modelId:this.modelId}),H=za(t.prompt),{responseHeaders:re,value:te,rawValue:we}=await Pn({url:P,headers:_n(this.config.headers(),t.headers),body:Ee,failedResponseHandler:vn,successfulResponseHandler:lr(D2),abortSignal:t.abortSignal,fetch:this.config.fetch});if(te.error)throw new on({message:te.error.message,url:P,requestBodyValues:Ee,statusCode:400,responseHeaders:re,responseBody:we,isRetryable:!1});const se=[],ye=[];let _e=!1;for(const xe of te.output)switch(xe.type){case"reasoning":{xe.summary.length===0&&xe.summary.push({type:"summary_text",text:""});for(const ge of xe.summary)se.push({type:"reasoning",text:ge.text,providerMetadata:{[ee]:{itemId:xe.id,reasoningEncryptedContent:(r=xe.encrypted_content)!=null?r:null}}});break}case"image_generation_call":{se.push({type:"tool-call",toolCallId:xe.id,toolName:oe.toCustomToolName("image_generation"),input:"{}",providerExecuted:!0}),se.push({type:"tool-result",toolCallId:xe.id,toolName:oe.toCustomToolName("image_generation"),result:{result:xe.result}});break}case"local_shell_call":{se.push({type:"tool-call",toolCallId:xe.call_id,toolName:oe.toCustomToolName("local_shell"),input:JSON.stringify({action:xe.action}),providerMetadata:{[ee]:{itemId:xe.id}}});break}case"shell_call":{se.push({type:"tool-call",toolCallId:xe.call_id,toolName:oe.toCustomToolName("shell"),input:JSON.stringify({action:{commands:xe.action.commands}}),providerMetadata:{[ee]:{itemId:xe.id}}});break}case"message":{for(const ge of xe.content){(c=(o=t.providerOptions)==null?void 0:o[ee])!=null&&c.logprobs&&ge.logprobs&&ye.push(ge.logprobs);const ft={itemId:xe.id,...ge.annotations.length>0&&{annotations:ge.annotations}};se.push({type:"text",text:ge.text,providerMetadata:{[ee]:ft}});for(const Se of ge.annotations)Se.type==="url_citation"?se.push({type:"source",sourceType:"url",id:(p=(f=(u=this.config).generateId)==null?void 0:f.call(u))!=null?p:Gt(),url:Se.url,title:Se.title}):Se.type==="file_citation"?se.push({type:"source",sourceType:"document",id:(m=(y=(x=this.config).generateId)==null?void 0:y.call(x))!=null?m:Gt(),mediaType:"text/plain",title:Se.filename,filename:Se.filename,providerMetadata:{[ee]:{type:Se.type,fileId:Se.file_id,index:Se.index}}}):Se.type==="container_file_citation"?se.push({type:"source",sourceType:"document",id:(B=(E=(A=this.config).generateId)==null?void 0:E.call(A))!=null?B:Gt(),mediaType:"text/plain",title:Se.filename,filename:Se.filename,providerMetadata:{[ee]:{type:Se.type,fileId:Se.file_id,containerId:Se.container_id}}}):Se.type==="file_path"&&se.push({type:"source",sourceType:"document",id:(R=(M=(D=this.config).generateId)==null?void 0:M.call(D))!=null?R:Gt(),mediaType:"application/octet-stream",title:Se.file_id,filename:Se.file_id,providerMetadata:{[ee]:{type:Se.type,fileId:Se.file_id,index:Se.index}}})}break}case"function_call":{_e=!0,se.push({type:"tool-call",toolCallId:xe.call_id,toolName:xe.name,input:xe.arguments,providerMetadata:{[ee]:{itemId:xe.id}}});break}case"web_search_call":{se.push({type:"tool-call",toolCallId:xe.id,toolName:oe.toCustomToolName(ne??"web_search"),input:JSON.stringify({}),providerExecuted:!0}),se.push({type:"tool-result",toolCallId:xe.id,toolName:oe.toCustomToolName(ne??"web_search"),result:$a(xe.action)});break}case"mcp_call":{const ge=xe.approval_request_id!=null&&(k=H[xe.approval_request_id])!=null?k:xe.id,ft=`mcp.${xe.name}`;se.push({type:"tool-call",toolCallId:ge,toolName:ft,input:xe.arguments,providerExecuted:!0,dynamic:!0}),se.push({type:"tool-result",toolCallId:ge,toolName:ft,result:{type:"call",serverLabel:xe.server_label,name:xe.name,arguments:xe.arguments,...xe.output!=null?{output:xe.output}:{},...xe.error!=null?{error:xe.error}:{}},providerMetadata:{[ee]:{itemId:xe.id}}});break}case"mcp_list_tools":break;case"mcp_approval_request":{const ge=(q=xe.approval_request_id)!=null?q:xe.id,ft=($=(z=(Z=this.config).generateId)==null?void 0:z.call(Z))!=null?$:Gt(),Se=`mcp.${xe.name}`;se.push({type:"tool-call",toolCallId:ft,toolName:Se,input:xe.arguments,providerExecuted:!0,dynamic:!0}),se.push({type:"tool-approval-request",approvalId:ge,toolCallId:ft});break}case"computer_call":{se.push({type:"tool-call",toolCallId:xe.id,toolName:oe.toCustomToolName("computer_use"),input:"",providerExecuted:!0}),se.push({type:"tool-result",toolCallId:xe.id,toolName:oe.toCustomToolName("computer_use"),result:{type:"computer_use_tool_result",status:xe.status||"completed"}});break}case"file_search_call":{se.push({type:"tool-call",toolCallId:xe.id,toolName:oe.toCustomToolName("file_search"),input:"{}",providerExecuted:!0}),se.push({type:"tool-result",toolCallId:xe.id,toolName:oe.toCustomToolName("file_search"),result:{queries:xe.queries,results:(O=(Q=xe.results)==null?void 0:Q.map(ge=>({attributes:ge.attributes,fileId:ge.file_id,filename:ge.filename,score:ge.score,text:ge.text})))!=null?O:null}});break}case"code_interpreter_call":{se.push({type:"tool-call",toolCallId:xe.id,toolName:oe.toCustomToolName("code_interpreter"),input:JSON.stringify({code:xe.code,containerId:xe.container_id}),providerExecuted:!0}),se.push({type:"tool-result",toolCallId:xe.id,toolName:oe.toCustomToolName("code_interpreter"),result:{outputs:xe.outputs}});break}case"apply_patch_call":{se.push({type:"tool-call",toolCallId:xe.call_id,toolName:oe.toCustomToolName("apply_patch"),input:JSON.stringify({callId:xe.call_id,operation:xe.operation}),providerMetadata:{[ee]:{itemId:xe.id}}});break}}const Ze={[ee]:{responseId:te.id,...ye.length>0?{logprobs:ye}:{},...typeof te.service_tier=="string"?{serviceTier:te.service_tier}:{}}},Ue=te.usage;return{content:se,finishReason:{unified:Fa({finishReason:(V=te.incomplete_details)==null?void 0:V.reason,hasFunctionCall:_e}),raw:(j=(le=te.incomplete_details)==null?void 0:le.reason)!=null?j:void 0},usage:Ba(Ue),request:{body:Ee},response:{id:te.id,timestamp:new Date(te.created_at*1e3),modelId:te.model,headers:re,body:we},providerMetadata:Ze,warnings:de}}async doStream(t){const{args:r,warnings:o,webSearchToolName:c,toolNameMapping:u,store:f,providerOptionsName:p}=await this.getArgs(t),{responseHeaders:x,value:y}=await Pn({url:this.config.url({path:"/responses",modelId:this.modelId}),headers:_n(this.config.headers(),t.headers),body:{...r,stream:!0},failedResponseHandler:vn,successfulResponseHandler:Jo(M2),abortSignal:t.abortSignal,fetch:this.config.fetch}),m=this,A=za(t.prompt),E=new Map;let B={unified:"other",raw:void 0},D;const M=[];let R=null;const k={},q=[];let Z=!1;const z={};let $;return{stream:y.pipeThrough(new TransformStream({start(Q){Q.enqueue({type:"stream-start",warnings:o})},transform(Q,O){var V,le,j,Ee,de,ne,oe,ee,P,H,re,te,we,se,ye,_e,Ze,Ue,xe,ge,ft,Se,Nt,Qe,et,jt,Be,hn,Vt,Cn;if(t.includeRawChunks&&O.enqueue({type:"raw",rawValue:Q.rawValue}),!Q.success){B={unified:"error",raw:void 0},O.enqueue({type:"error",error:Q.error});return}const L=Q.value;if(Va(L)){if(L.item.type==="function_call")k[L.output_index]={toolName:L.item.name,toolCallId:L.item.call_id},O.enqueue({type:"tool-input-start",id:L.item.call_id,toolName:L.item.name});else if(L.item.type==="web_search_call")k[L.output_index]={toolName:u.toCustomToolName(c??"web_search"),toolCallId:L.item.id},O.enqueue({type:"tool-input-start",id:L.item.id,toolName:u.toCustomToolName(c??"web_search"),providerExecuted:!0}),O.enqueue({type:"tool-input-end",id:L.item.id}),O.enqueue({type:"tool-call",toolCallId:L.item.id,toolName:u.toCustomToolName(c??"web_search"),input:JSON.stringify({}),providerExecuted:!0});else if(L.item.type==="computer_call")k[L.output_index]={toolName:u.toCustomToolName("computer_use"),toolCallId:L.item.id},O.enqueue({type:"tool-input-start",id:L.item.id,toolName:u.toCustomToolName("computer_use"),providerExecuted:!0});else if(L.item.type==="code_interpreter_call")k[L.output_index]={toolName:u.toCustomToolName("code_interpreter"),toolCallId:L.item.id,codeInterpreter:{containerId:L.item.container_id}},O.enqueue({type:"tool-input-start",id:L.item.id,toolName:u.toCustomToolName("code_interpreter"),providerExecuted:!0}),O.enqueue({type:"tool-input-delta",id:L.item.id,delta:`{"containerId":"${L.item.container_id}","code":"`});else if(L.item.type==="file_search_call")O.enqueue({type:"tool-call",toolCallId:L.item.id,toolName:u.toCustomToolName("file_search"),input:"{}",providerExecuted:!0});else if(L.item.type==="image_generation_call")O.enqueue({type:"tool-call",toolCallId:L.item.id,toolName:u.toCustomToolName("image_generation"),input:"{}",providerExecuted:!0});else if(!(L.item.type==="mcp_call"||L.item.type==="mcp_list_tools"||L.item.type==="mcp_approval_request"))if(L.item.type==="apply_patch_call"){const{call_id:ue,operation:Te}=L.item;if(k[L.output_index]={toolName:u.toCustomToolName("apply_patch"),toolCallId:ue,applyPatch:{hasDiff:Te.type==="delete_file",endEmitted:Te.type==="delete_file"}},O.enqueue({type:"tool-input-start",id:ue,toolName:u.toCustomToolName("apply_patch")}),Te.type==="delete_file"){const It=JSON.stringify({callId:ue,operation:Te});O.enqueue({type:"tool-input-delta",id:ue,delta:It}),O.enqueue({type:"tool-input-end",id:ue})}else O.enqueue({type:"tool-input-delta",id:ue,delta:`{"callId":"${rr(ue)}","operation":{"type":"${rr(Te.type)}","path":"${rr(Te.path)}","diff":"`})}else L.item.type==="shell_call"?k[L.output_index]={toolName:u.toCustomToolName("shell"),toolCallId:L.item.call_id}:L.item.type==="message"?(q.splice(0,q.length),O.enqueue({type:"text-start",id:L.item.id,providerMetadata:{[p]:{itemId:L.item.id}}})):Va(L)&&L.item.type==="reasoning"&&(z[L.item.id]={encryptedContent:L.item.encrypted_content,summaryParts:{0:"active"}},O.enqueue({type:"reasoning-start",id:`${L.item.id}:0`,providerMetadata:{[p]:{itemId:L.item.id,reasoningEncryptedContent:(V=L.item.encrypted_content)!=null?V:null}}}))}else if(F2(L)){if(L.item.type==="message")O.enqueue({type:"text-end",id:L.item.id,providerMetadata:{[p]:{itemId:L.item.id,...q.length>0&&{annotations:q}}}});else if(L.item.type==="function_call")k[L.output_index]=void 0,Z=!0,O.enqueue({type:"tool-input-end",id:L.item.call_id}),O.enqueue({type:"tool-call",toolCallId:L.item.call_id,toolName:L.item.name,input:L.item.arguments,providerMetadata:{[p]:{itemId:L.item.id}}});else if(L.item.type==="web_search_call")k[L.output_index]=void 0,O.enqueue({type:"tool-result",toolCallId:L.item.id,toolName:u.toCustomToolName(c??"web_search"),result:$a(L.item.action)});else if(L.item.type==="computer_call")k[L.output_index]=void 0,O.enqueue({type:"tool-input-end",id:L.item.id}),O.enqueue({type:"tool-call",toolCallId:L.item.id,toolName:u.toCustomToolName("computer_use"),input:"",providerExecuted:!0}),O.enqueue({type:"tool-result",toolCallId:L.item.id,toolName:u.toCustomToolName("computer_use"),result:{type:"computer_use_tool_result",status:L.item.status||"completed"}});else if(L.item.type==="file_search_call")k[L.output_index]=void 0,O.enqueue({type:"tool-result",toolCallId:L.item.id,toolName:u.toCustomToolName("file_search"),result:{queries:L.item.queries,results:(j=(le=L.item.results)==null?void 0:le.map(ue=>({attributes:ue.attributes,fileId:ue.file_id,filename:ue.filename,score:ue.score,text:ue.text})))!=null?j:null}});else if(L.item.type==="code_interpreter_call")k[L.output_index]=void 0,O.enqueue({type:"tool-result",toolCallId:L.item.id,toolName:u.toCustomToolName("code_interpreter"),result:{outputs:L.item.outputs}});else if(L.item.type==="image_generation_call")O.enqueue({type:"tool-result",toolCallId:L.item.id,toolName:u.toCustomToolName("image_generation"),result:{result:L.item.result}});else if(L.item.type==="mcp_call"){k[L.output_index]=void 0;const ue=(Ee=L.item.approval_request_id)!=null?Ee:void 0,Te=ue!=null&&(ne=(de=E.get(ue))!=null?de:A[ue])!=null?ne:L.item.id,It=`mcp.${L.item.name}`;O.enqueue({type:"tool-call",toolCallId:Te,toolName:It,input:L.item.arguments,providerExecuted:!0,dynamic:!0}),O.enqueue({type:"tool-result",toolCallId:Te,toolName:It,result:{type:"call",serverLabel:L.item.server_label,name:L.item.name,arguments:L.item.arguments,...L.item.output!=null?{output:L.item.output}:{},...L.item.error!=null?{error:L.item.error}:{}},providerMetadata:{[p]:{itemId:L.item.id}}})}else if(L.item.type==="mcp_list_tools")k[L.output_index]=void 0;else if(L.item.type==="apply_patch_call"){const ue=k[L.output_index];ue?.applyPatch&&!ue.applyPatch.endEmitted&&L.item.operation.type!=="delete_file"&&(ue.applyPatch.hasDiff||O.enqueue({type:"tool-input-delta",id:ue.toolCallId,delta:rr(L.item.operation.diff)}),O.enqueue({type:"tool-input-delta",id:ue.toolCallId,delta:'"}}'}),O.enqueue({type:"tool-input-end",id:ue.toolCallId}),ue.applyPatch.endEmitted=!0),ue&&L.item.status==="completed"&&O.enqueue({type:"tool-call",toolCallId:ue.toolCallId,toolName:u.toCustomToolName("apply_patch"),input:JSON.stringify({callId:L.item.call_id,operation:L.item.operation}),providerMetadata:{[p]:{itemId:L.item.id}}}),k[L.output_index]=void 0}else if(L.item.type==="mcp_approval_request"){k[L.output_index]=void 0;const ue=(P=(ee=(oe=m.config).generateId)==null?void 0:ee.call(oe))!=null?P:Gt(),Te=(H=L.item.approval_request_id)!=null?H:L.item.id;E.set(Te,ue);const It=`mcp.${L.item.name}`;O.enqueue({type:"tool-call",toolCallId:ue,toolName:It,input:L.item.arguments,providerExecuted:!0,dynamic:!0}),O.enqueue({type:"tool-approval-request",approvalId:Te,toolCallId:ue})}else if(L.item.type==="local_shell_call")k[L.output_index]=void 0,O.enqueue({type:"tool-call",toolCallId:L.item.call_id,toolName:u.toCustomToolName("local_shell"),input:JSON.stringify({action:{type:"exec",command:L.item.action.command,timeoutMs:L.item.action.timeout_ms,user:L.item.action.user,workingDirectory:L.item.action.working_directory,env:L.item.action.env}}),providerMetadata:{[p]:{itemId:L.item.id}}});else if(L.item.type==="shell_call")k[L.output_index]=void 0,O.enqueue({type:"tool-call",toolCallId:L.item.call_id,toolName:u.toCustomToolName("shell"),input:JSON.stringify({action:{commands:L.item.action.commands}}),providerMetadata:{[p]:{itemId:L.item.id}}});else if(L.item.type==="reasoning"){const ue=z[L.item.id],Te=Object.entries(ue.summaryParts).filter(([It,be])=>be==="active"||be==="can-conclude").map(([It])=>It);for(const It of Te)O.enqueue({type:"reasoning-end",id:`${L.item.id}:${It}`,providerMetadata:{[p]:{itemId:L.item.id,reasoningEncryptedContent:(re=L.item.encrypted_content)!=null?re:null}}});delete z[L.item.id]}}else if(V2(L)){const ue=k[L.output_index];ue!=null&&O.enqueue({type:"tool-input-delta",id:ue.toolCallId,delta:L.delta})}else if(H2(L)){const ue=k[L.output_index];ue?.applyPatch&&(O.enqueue({type:"tool-input-delta",id:ue.toolCallId,delta:rr(L.delta)}),ue.applyPatch.hasDiff=!0)}else if(W2(L)){const ue=k[L.output_index];ue?.applyPatch&&!ue.applyPatch.endEmitted&&(ue.applyPatch.hasDiff||(O.enqueue({type:"tool-input-delta",id:ue.toolCallId,delta:rr(L.diff)}),ue.applyPatch.hasDiff=!0),O.enqueue({type:"tool-input-delta",id:ue.toolCallId,delta:'"}}'}),O.enqueue({type:"tool-input-end",id:ue.toolCallId}),ue.applyPatch.endEmitted=!0)}else if($2(L))O.enqueue({type:"tool-result",toolCallId:L.item_id,toolName:u.toCustomToolName("image_generation"),result:{result:L.partial_image_b64},preliminary:!0});else if(Z2(L)){const ue=k[L.output_index];ue!=null&&O.enqueue({type:"tool-input-delta",id:ue.toolCallId,delta:rr(L.delta)})}else if(j2(L)){const ue=k[L.output_index];ue!=null&&(O.enqueue({type:"tool-input-delta",id:ue.toolCallId,delta:'"}'}),O.enqueue({type:"tool-input-end",id:ue.toolCallId}),O.enqueue({type:"tool-call",toolCallId:ue.toolCallId,toolName:u.toCustomToolName("code_interpreter"),input:JSON.stringify({code:L.code,containerId:ue.codeInterpreter.containerId}),providerExecuted:!0}))}else if(z2(L))R=L.response.id,O.enqueue({type:"response-metadata",id:L.response.id,timestamp:new Date(L.response.created_at*1e3),modelId:L.response.model});else if(L2(L))O.enqueue({type:"text-delta",id:L.item_id,delta:L.delta}),(we=(te=t.providerOptions)==null?void 0:te[p])!=null&&we.logprobs&&L.logprobs&&M.push(L.logprobs);else if(L.type==="response.reasoning_summary_part.added"){if(L.summary_index>0){const ue=z[L.item_id];ue.summaryParts[L.summary_index]="active";for(const Te of Object.keys(ue.summaryParts))ue.summaryParts[Te]==="can-conclude"&&(O.enqueue({type:"reasoning-end",id:`${L.item_id}:${Te}`,providerMetadata:{[p]:{itemId:L.item_id}}}),ue.summaryParts[Te]="concluded");O.enqueue({type:"reasoning-start",id:`${L.item_id}:${L.summary_index}`,providerMetadata:{[p]:{itemId:L.item_id,reasoningEncryptedContent:(ye=(se=z[L.item_id])==null?void 0:se.encryptedContent)!=null?ye:null}}})}}else L.type==="response.reasoning_summary_text.delta"?O.enqueue({type:"reasoning-delta",id:`${L.item_id}:${L.summary_index}`,delta:L.delta,providerMetadata:{[p]:{itemId:L.item_id}}}):L.type==="response.reasoning_summary_part.done"?f?(O.enqueue({type:"reasoning-end",id:`${L.item_id}:${L.summary_index}`,providerMetadata:{[p]:{itemId:L.item_id}}}),z[L.item_id].summaryParts[L.summary_index]="concluded"):z[L.item_id].summaryParts[L.summary_index]="can-conclude":U2(L)?(B={unified:Fa({finishReason:(_e=L.response.incomplete_details)==null?void 0:_e.reason,hasFunctionCall:Z}),raw:(Ue=(Ze=L.response.incomplete_details)==null?void 0:Ze.reason)!=null?Ue:void 0},D=L.response.usage,typeof L.response.service_tier=="string"&&($=L.response.service_tier)):G2(L)?(q.push(L.annotation),L.annotation.type==="url_citation"?O.enqueue({type:"source",sourceType:"url",id:(ft=(ge=(xe=m.config).generateId)==null?void 0:ge.call(xe))!=null?ft:Gt(),url:L.annotation.url,title:L.annotation.title}):L.annotation.type==="file_citation"?O.enqueue({type:"source",sourceType:"document",id:(Qe=(Nt=(Se=m.config).generateId)==null?void 0:Nt.call(Se))!=null?Qe:Gt(),mediaType:"text/plain",title:L.annotation.filename,filename:L.annotation.filename,providerMetadata:{[p]:{type:L.annotation.type,fileId:L.annotation.file_id,index:L.annotation.index}}}):L.annotation.type==="container_file_citation"?O.enqueue({type:"source",sourceType:"document",id:(Be=(jt=(et=m.config).generateId)==null?void 0:jt.call(et))!=null?Be:Gt(),mediaType:"text/plain",title:L.annotation.filename,filename:L.annotation.filename,providerMetadata:{[p]:{type:L.annotation.type,fileId:L.annotation.file_id,containerId:L.annotation.container_id}}}):L.annotation.type==="file_path"&&O.enqueue({type:"source",sourceType:"document",id:(Cn=(Vt=(hn=m.config).generateId)==null?void 0:Vt.call(hn))!=null?Cn:Gt(),mediaType:"application/octet-stream",title:L.annotation.file_id,filename:L.annotation.file_id,providerMetadata:{[p]:{type:L.annotation.type,fileId:L.annotation.file_id,index:L.annotation.index}}})):X2(L)&&O.enqueue({type:"error",error:L})},flush(Q){const O={[p]:{responseId:R,...M.length>0?{logprobs:M}:{},...$!==void 0?{serviceTier:$}:{}}};Q.enqueue({type:"finish",finishReason:B,usage:Ba(D),providerMetadata:O})}})),request:{body:r},response:{headers:x}}}};function L2(t){return t.type==="response.output_text.delta"}function F2(t){return t.type==="response.output_item.done"}function U2(t){return t.type==="response.completed"||t.type==="response.incomplete"}function z2(t){return t.type==="response.created"}function V2(t){return t.type==="response.function_call_arguments.delta"}function $2(t){return t.type==="response.image_generation_call.partial_image"}function Z2(t){return t.type==="response.code_interpreter_call_code.delta"}function j2(t){return t.type==="response.code_interpreter_call_code.done"}function H2(t){return t.type==="response.apply_patch_call_operation_diff.delta"}function W2(t){return t.type==="response.apply_patch_call_operation_diff.done"}function Va(t){return t.type==="response.output_item.added"}function G2(t){return t.type==="response.output_text.annotation.added"}function X2(t){return t.type==="error"}function $a(t){var r;switch(t.type){case"search":return{action:{type:"search",query:(r=t.query)!=null?r:void 0},...t.sources!=null&&{sources:t.sources}};case"open_page":return{action:{type:"openPage",url:t.url}};case"find_in_page":return{action:{type:"findInPage",url:t.url,pattern:t.pattern}}}}function rr(t){return JSON.stringify(t).slice(1,-1)}var q2=$e(()=>Ve(T({instructions:_().nullish(),speed:X().min(.25).max(4).default(1).nullish()}))),Y2=class{constructor(t,r){this.modelId=t,this.config=r,this.specificationVersion="v3"}get provider(){return this.config.provider}async getArgs({text:t,voice:r="alloy",outputFormat:o="mp3",speed:c,instructions:u,language:f,providerOptions:p}){const x=[],y=await Dn({provider:"openai",providerOptions:p,schema:q2}),m={model:this.modelId,input:t,voice:r,response_format:"mp3",speed:c,instructions:u};if(o&&(["mp3","opus","aac","flac","wav","pcm"].includes(o)?m.response_format=o:x.push({type:"unsupported",feature:"outputFormat",details:`Unsupported output format: ${o}. Using mp3 instead.`})),y){const A={};for(const E in A){const B=A[E];B!==void 0&&(m[E]=B)}}return f&&x.push({type:"unsupported",feature:"language",details:`OpenAI speech models do not support language selection. Language parameter "${f}" was ignored.`}),{requestBody:m,warnings:x}}async doGenerate(t){var r,o,c;const u=(c=(o=(r=this.config._internal)==null?void 0:r.currentDate)==null?void 0:o.call(r))!=null?c:new Date,{requestBody:f,warnings:p}=await this.getArgs(t),{value:x,responseHeaders:y,rawValue:m}=await Pn({url:this.config.url({path:"/audio/speech",modelId:this.modelId}),headers:_n(this.config.headers(),t.headers),body:f,failedResponseHandler:vn,successfulResponseHandler:dg(),abortSignal:t.abortSignal,fetch:this.config.fetch});return{audio:x,warnings:p,request:{body:JSON.stringify(f)},response:{timestamp:u,modelId:this.modelId,headers:y,body:m}}}},J2=$e(()=>Ve(T({text:_(),language:_().nullish(),duration:X().nullish(),words:me(T({word:_(),start:X(),end:X()})).nullish(),segments:me(T({id:X(),seek:X(),start:X(),end:X(),text:_(),tokens:me(X()),temperature:X(),avg_logprob:X(),compression_ratio:X(),no_speech_prob:X()})).nullish()}))),K2=$e(()=>Ve(T({include:me(_()).optional(),language:_().optional(),prompt:_().optional(),temperature:X().min(0).max(1).default(0).optional(),timestampGranularities:me(We(["word","segment"])).default(["segment"]).optional()}))),Za={afrikaans:"af",arabic:"ar",armenian:"hy",azerbaijani:"az",belarusian:"be",bosnian:"bs",bulgarian:"bg",catalan:"ca",chinese:"zh",croatian:"hr",czech:"cs",danish:"da",dutch:"nl",english:"en",estonian:"et",finnish:"fi",french:"fr",galician:"gl",german:"de",greek:"el",hebrew:"he",hindi:"hi",hungarian:"hu",icelandic:"is",indonesian:"id",italian:"it",japanese:"ja",kannada:"kn",kazakh:"kk",korean:"ko",latvian:"lv",lithuanian:"lt",macedonian:"mk",malay:"ms",marathi:"mr",maori:"mi",nepali:"ne",norwegian:"no",persian:"fa",polish:"pl",portuguese:"pt",romanian:"ro",russian:"ru",serbian:"sr",slovak:"sk",slovenian:"sl",spanish:"es",swahili:"sw",swedish:"sv",tagalog:"tl",tamil:"ta",thai:"th",turkish:"tr",ukrainian:"uk",urdu:"ur",vietnamese:"vi",welsh:"cy"},Q2=class{constructor(t,r){this.modelId=t,this.config=r,this.specificationVersion="v3"}get provider(){return this.config.provider}async getArgs({audio:t,mediaType:r,providerOptions:o}){const c=[],u=await Dn({provider:"openai",providerOptions:o,schema:K2}),f=new FormData,p=t instanceof Uint8Array?new Blob([t]):new Blob([Go(t)]);f.append("model",this.modelId);const x=fp(r);if(f.append("file",new File([p],"audio",{type:r}),`audio.${x}`),u){const y={include:u.include,language:u.language,prompt:u.prompt,response_format:["gpt-4o-transcribe","gpt-4o-mini-transcribe"].includes(this.modelId)?"json":"verbose_json",temperature:u.temperature,timestamp_granularities:u.timestampGranularities};for(const[m,A]of Object.entries(y))if(A!=null)if(Array.isArray(A))for(const E of A)f.append(`${m}[]`,String(E));else f.append(m,String(A))}return{formData:f,warnings:c}}async doGenerate(t){var r,o,c,u,f,p,x,y;const m=(c=(o=(r=this.config._internal)==null?void 0:r.currentDate)==null?void 0:o.call(r))!=null?c:new Date,{formData:A,warnings:E}=await this.getArgs(t),{value:B,responseHeaders:D,rawValue:M}=await bc({url:this.config.url({path:"/audio/transcriptions",modelId:this.modelId}),headers:_n(this.config.headers(),t.headers),formData:A,failedResponseHandler:vn,successfulResponseHandler:lr(J2),abortSignal:t.abortSignal,fetch:this.config.fetch}),R=B.language!=null&&B.language in Za?Za[B.language]:void 0;return{text:B.text,segments:(x=(p=(u=B.segments)==null?void 0:u.map(k=>({text:k.text,startSecond:k.start,endSecond:k.end})))!=null?p:(f=B.words)==null?void 0:f.map(k=>({text:k.word,startSecond:k.start,endSecond:k.end})))!=null?x:[],language:R,durationInSeconds:(y=B.duration)!=null?y:void 0,warnings:E,response:{timestamp:m,modelId:this.modelId,headers:D,body:M}}}},ex="3.0.28";function Tu(t={}){var r,o;const c=(r=fg(dp({settingValue:t.baseURL,environmentVariableName:"OPENAI_BASE_URL"})))!=null?r:"https://api.openai.com/v1",u=(o=t.name)!=null?o:"openai",f=()=>wc({Authorization:`Bearer ${up({apiKey:t.apiKey,environmentVariableName:"OPENAI_API_KEY",description:"OpenAI"})}`,"OpenAI-Organization":t.organization,"OpenAI-Project":t.project,...t.headers},`ai-sdk/openai/${ex}`),p=R=>new zm(R,{provider:`${u}.chat`,url:({path:k})=>`${c}${k}`,headers:f,fetch:t.fetch}),x=R=>new jm(R,{provider:`${u}.completion`,url:({path:k})=>`${c}${k}`,headers:f,fetch:t.fetch}),y=R=>new Gm(R,{provider:`${u}.embedding`,url:({path:k})=>`${c}${k}`,headers:f,fetch:t.fetch}),m=R=>new Jm(R,{provider:`${u}.image`,url:({path:k})=>`${c}${k}`,headers:f,fetch:t.fetch}),A=R=>new Q2(R,{provider:`${u}.transcription`,url:({path:k})=>`${c}${k}`,headers:f,fetch:t.fetch}),E=R=>new Y2(R,{provider:`${u}.speech`,url:({path:k})=>`${c}${k}`,headers:f,fetch:t.fetch}),B=R=>{if(new.target)throw new Error("The OpenAI model function cannot be called with the new keyword.");return D(R)},D=R=>new B2(R,{provider:`${u}.responses`,url:({path:k})=>`${c}${k}`,headers:f,fetch:t.fetch,fileIdPrefixes:["file-"]}),M=function(R){return B(R)};return M.specificationVersion="v3",M.languageModel=B,M.chat=p,M.completion=x,M.responses=D,M.embedding=y,M.embeddingModel=y,M.textEmbedding=y,M.textEmbeddingModel=y,M.image=m,M.imageModel=m,M.transcription=A,M.transcriptionModel=A,M.speech=E,M.speechModel=E,M.tools=O2,M}Tu();const tx={deepseek:{prompt:{strategy:"append",id:"5ed1b9071c15d1ed59b5827ea5dcabd4",params:{customComponents:[{name:"选择用户组件",description:"选择用户组件,用于选择用户,支持模糊搜索",component:"TinyUser",schema:{properties:[{property:"modelValue",label:"用户绑定工号",required:!0,description:"用户的工号,双向绑定值",type:"string"},{property:"valueField",label:"值字段",required:!0,description:"用户工号值的绑定字段",type:"string"}]}}],customExamples:[{name:"选择用户示例",schema:{componentName:"Page",state:{reviewer:""},children:[{componentName:"h3",props:{},children:"输入用户名搜索工号并选择用户"},{componentName:"TinyUser",props:{modelValue:{type:"JSExpression",model:!0,value:"this.state.reviewer"},valueField:"uid"}},{componentName:"TinyButton",props:{text:"提交"}}]}}],customActions:[{name:"continueChat",description:"继续对话, 用于表单的提交按钮等",parameters:{type:"object",properties:{message:{type:"string",description:"对话消息,可以是按钮文本等,也可以是其他内容"}}}}]}}}};class nx{constructor(r={}){this.option=r}async traverse(r){const o=v.ref();return this.option.debug&&console.log("【stream-debug】 响应对象体:",o),(async()=>{let u,f,p,x,y;for await(const m of r.fullStream)switch(this.option.debug&&console.log("【stream-debug】 "+(new Date().getTime()/1e3).toString().slice(-6)+m.type,m),m.type){case"start":u=v.reactive({running:!0,steps:[]}),o.value=u,this.option.onStart?.(u);break;case"start-step":f=v.reactive({running:!0,contents:[],request:m.request}),u.steps.push(f),this.option.onStep?.(f);break;case"reasoning-start":p=v.reactive({type:"reasoning",id:m.id,running:!0,text:""}),f.contents.push(p),this.option.onReasoning?.(p);break;case"reasoning-delta":p.text+=m.text;break;case"reasoning-end":p.running=!1;break;case"text-start":x=v.reactive({type:"text",id:m.id,running:!0,text:""}),f.contents.push(x),this.option.onText?.(x);break;case"text-delta":x.text+=m.text;break;case"text-end":x.running=!1;break;case"tool-input-start":y=v.reactive({type:"tool",running:!0,id:m.id,toolCallId:m.id,title:"",toolName:m.toolName,dynamic:m.dynamic,inputStr:"",input:{},output:{}}),f.contents.push(y),this.option.onTool?.(y);break;case"tool-input-delta":y.inputStr+=m.delta;break;case"tool-input-end":break;case"tool-call":y.input=m.input;break;case"tool-result":y.output=m.output,y.running=!1;break;case"tool-error":y.error=m.error,y.running=!1;break;case"finish-step":f.running=!1,f.finishReason=m.finishReason,f.usage=m.usage;break;case"finish":u.running=!1,u.finishReason=m.finishReason,u.totalUsage=m.totalUsage,this.option.onFinish?.();break;case"source":case"file":break;case"error":u&&(u.running=!1,u.error=m.error,u.finishReason="error"),this.option.onFinish?.();break;case"abort":u&&(u.running=!1,u.error={message:m.reason},u.finishReason="other"),this.option.onFinish?.();break}})(),o}}function rx(t){const r=[];let o=0;for(;o<t.length;){const c="```schemaJson",u=t.indexOf(c,o),f=c.length;if(u===-1){const m=t.slice(o).trim();m&&r.push({type:"markdown",content:m});break}const p=t.slice(o,u).trim();p&&r.push({type:"markdown",content:p});const x=t.indexOf("```",u+f);let y;x===-1?(y=t.slice(u+f).trim(),o=t.length):(y=t.slice(u+f,x).trim(),o=x+3),r.push({type:"schema-card",content:y})}return r}const yo={model:"deepseek-ai/DeepSeek-V3",maxSteps:15,extraTools:{}},ja={apiKey:"sk-trial",baseURL:"https://agent.opentiny.design/api/v1/ai",providerType:"deepseek"};class ix extends Zn.BaseModelProvider{transport;agent;systemPrompt;llmConfig={...yo,...ja};isGenuiEnabled;constructor(r,o,c){super(r);let u;c&&"llm"in c?u={...yo,...c}:u={...yo,...ja,...c||{}},this.llmConfig=u;const p={llmConfig:u.llm?{llm:u.llm}:{...u}};this.agent=new sr.AgentModelProvider(p),this.systemPrompt=o}updateLLMConfig({modelId:r,baseURL:o,apiKey:c,providerType:u,useReActMode:f,llm:p}){if(p)this.agent.llm=p,this.llmConfig.model=r,this.llmConfig.useReActMode=f||!1,this.agent.useReActMode=f||!1;else if(u&&o&&c){this.isGenuiEnabled?.value?o.includes("/prompt")||(o=o+"/prompt"):o=o.replace("/prompt",""),this.llmConfig.model=r,this.llmConfig.apiKey=c,this.llmConfig.baseURL=o,this.llmConfig.providerType=u,this.llmConfig.useReActMode=f||!1,this.agent.useReActMode=f||!1;let x;if(u==="deepseek")x=xu;else if(u==="openai")x=Tu;else if(typeof u=="function")x=u;else throw new Error(`Unsupported providerType: ${u}`);this.agent.llm=x({apiKey:c,baseURL:o})}}cleanupOldSnapshotsInMessages(r){if(!r||r.length===0)return r;const c=this.agent.useReActMode===!0?"user":"tool",u=r[r.length-1];if(!u||u.role!==c||!this.isSnapshotContent(u.content))return r;const f=[...r];for(let p=f.length-2;p>=0;p--){const x=f[p];x.role===c&&this.isSnapshotContent(x.content)&&this.replaceSnapshotWithPlaceholder(x)}return f}removeSnapshotData(r){if(!r)return r;const o=["无障碍树快照:","无障碍树快照:","快照内容:","快照内容:","页面无障碍树快照:","页面无障碍树快照:","操作后的页面快照:","操作后的页面快照:"];let c=-1;for(const f of o){const p=r.indexOf(f);if(p!==-1){c=p;break}}if(c!==-1){const f=r.substring(0,c).trim();return f?`${f} 📸 [历史快照已清理]`:"📸 历史快照已清理"}const u=["已成功获取页面无障碍树快照","takeSnapshot","snapshotId_counter"];for(const f of u)if(r.startsWith(f))return"📸 历史快照已清理";return r}replaceSnapshotWithPlaceholder(r){if(Array.isArray(r.content)){const o=r.content[0];if(o?.output?.value?.content){const c=o.output.value.content;Array.isArray(c)&&(o.output.value.content=c.map(u=>u.type==="image"||u.type==="image_url"?null:u.type==="text"&&u.text&&this.isSnapshotContent(u.text)?{type:"text",text:this.removeSnapshotData(u.text)}:u).filter(u=>u!==null)),o.output.value.screenshot&&delete o.output.value.screenshot}else r.content=r.content.filter(c=>c.type!=="image"&&c.type!=="image_url")}else typeof r.content=="string"&&this.isSnapshotContent(r.content)&&(r.content=this.removeSnapshotData(r.content))}isSnapshotContent(r){if(!r)return!1;const o=["无障碍树快照","takeSnapshot","snapshotId_counter","UID 格式","快照 ID","操作后的页面快照","已成功获取页面无障碍树快照","快照内容:"];if(typeof r=="string")return o.some(c=>r.includes(c));if(Array.isArray(r))for(const c of r){const u=c?.output?.value?.content?.[0]?.text;if(u&&o.some(f=>u.includes(f))||c.type==="text"&&c.text&&o.some(f=>c.text.includes(f))||c.type==="image"||c.type==="image_url")return!0}return!1}async chatStream(r,o){let c=r.messages[r.messages.length-1];if(!c)return;if(this.llmConfig.beforeChatStream)try{const D=await this.llmConfig.beforeChatStream(c,this.systemPrompt);D&&(c=D)}catch(D){console.error("[beforeChatStream] 钩子执行失败:",D)}const u={model:this.llmConfig.model,system:this.systemPrompt,abortSignal:r.options?.signal,toolChoice:"auto",tools:{"get-today":Lg,...this.llmConfig.extraTools||{}},maxSteps:this.llmConfig.maxSteps,providerOptions:this.llmConfig.providerOptions||tx,prepareStep:({messages:D})=>({messages:this.cleanupOldSnapshotsInMessages(D)}),onFinish:async()=>{await this.agent.closeAll()}},f={role:"user",content:c.content},x=[...(D=>D.map(M=>({role:M.role,content:M.content})))(this.agent.responseMessages),f];u.messages=x;const y=await this.agent.chatStream(u),m=new qh,E=await new nx({debug:!1,onFinish:()=>{v.nextTick(()=>{m.resolve(),o.onDone()})}}).traverse(y),B={role:"assistant",content:"",uiContent:[]};return v.watch(E,D=>{if(!D)o.onData(B);else{const R=D.steps.map(k=>k.contents).flat().map(k=>{if(k.type==="text")return rx(k.text);if(k.type==="reasoning")return{type:"collapsible-text",title:"思考过程",content:k.text,thinkId:k.id};if(k.type==="tool")return{type:"tool",id:k.id,name:k.toolName,content:JSON.stringify({input:k.inputStr,output:k.output}),status:k.error?"failed":k.running?"running":"success"}});if(D?.error){const k={type:"markdown",content:`**错误**:${D.error.message||"未知错误"}`};R.push(k)}D.steps.length>=1&&o.onData({...B,uiContent:R.flat(),usage:D.totalUsage||null})}},{deep:!0}),m.promise}chat(r){throw new Error("Method not implemented.")}}const ox=({systemPrompt:t,llmConfig:r})=>{const o=new ix({provider:"custom"},t,r),c=new Zn.AIClient({providerImplementation:o,provider:"custom"}),{messageManager:u,createConversation:f,getCurrentConversation:p,switchConversation:x,deleteConversation:y,updateTitle:m,state:A}=Zn.useConversation({client:c,autoSave:!1,events:{onLoaded(){},onReceiveData($,Q,O){O(),Q.value[Q.value.length-1].role==="assistant"&&Q.value.pop(),Q.value.push($)}}}),{messageState:E,inputMessage:B,sendMessage:D,abortRequest:M,messages:R,addMessage:k,send:q}=u,Z=v.ref(),z=async($,Q,O)=>{if(O){const{shouldBlock:le}=await O($);if(le)return!1}B.value=$;const V=p();if(V&&V.title==="新会话"&&m(V.id,B.value.slice(0,15)),Q&&Q.length>0){const le=[{type:"text",text:B.value},...Q],j=[];B.value&&j.push({type:"text",content:B.value});for(const de of Q)de.type==="image"&&de.image&&j.push({type:"image",content:de.image});const Ee={role:"user",content:le,uiContent:j};R.value.push(Ee),B.value="",q()}else{const le={role:"user",content:B.value,uiContent:[{type:"text",content:B.value}]};R.value.push(le),B.value="",q()}return!0};return v.onMounted(()=>{Z.value?.focus()}),v.onUnmounted(()=>{o.agent.closeAll()}),{agent:o.agent,customAgentProvider:o,client:c,messageManager:u,addMessage:k,send:q,conversationState:A,messages:R,messageState:E,inputMessage:B,sendMessage:D,abortRequest:M,senderRef:Z,handleSendMessage:z,createConversation:f,switchConversation:x,deleteConversation:y,getCurrentConversation:p}};function sx(){}const On=Object.assign,es=typeof window<"u",ji=t=>t!==null&&typeof t=="object",Xn=t=>t!=null,Do=t=>typeof t=="function",ax=t=>ji(t)&&Do(t.then)&&Do(t.catch),Nu=t=>typeof t=="number"||/^\d+(\.\d+)?$/.test(t),lx=()=>es?/ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()):!1;function Ha(t,r){const o=r.split(".");let c=t;return o.forEach(u=>{var f;c=ji(c)&&(f=c[u])!=null?f:""}),c}function cx(t,r,o){return r.reduce((c,u)=>(c[u]=t[u],c),{})}const Bi=null,sn=[Number,String],or={type:Boolean,default:!0},ux=t=>({type:Number,default:t}),an=t=>({type:String,default:t});var ts=typeof window<"u";function Ou(t){let r;v.onMounted(()=>{t(),v.nextTick(()=>{r=!0})}),v.onActivated(()=>{r&&t()})}function ku(t,r,o={}){if(!ts)return;const{target:c=window,passive:u=!1,capture:f=!1}=o;let p=!1,x;const y=E=>{if(p)return;const B=v.unref(E);B&&!x&&(B.addEventListener(t,r,{capture:f,passive:u}),x=!0)},m=E=>{if(p)return;const B=v.unref(E);B&&x&&(B.removeEventListener(t,r,f),x=!1)};v.onUnmounted(()=>m(c)),v.onDeactivated(()=>m(c)),Ou(()=>y(c));let A;return v.isRef(c)&&(A=v.watch(c,(E,B)=>{m(B),y(E)})),()=>{A?.(),m(c),p=!0}}var Ai,_o;function dx(){if(!Ai&&(Ai=v.ref(0),_o=v.ref(0),ts)){const t=()=>{Ai.value=window.innerWidth,_o.value=window.innerHeight};t(),window.addEventListener("resize",t,{passive:!0}),window.addEventListener("orientationchange",t,{passive:!0})}return{width:Ai,height:_o}}var fx=/scroll|auto|overlay/i,hx=ts?window:void 0;function px(t){return t.tagName!=="HTML"&&t.tagName!=="BODY"&&t.nodeType===1}function gx(t,r=hx){let o=t;for(;o&&o!==r&&px(o);){const{overflowY:c}=window.getComputedStyle(o);if(fx.test(c))return o;o=o.parentNode}return r}lx();const mx=t=>t.stopPropagation();function Ru(t,r){(typeof t.cancelable!="boolean"||t.cancelable)&&t.preventDefault(),mx(t)}dx();function yn(t){if(Xn(t))return Nu(t)?`${t}px`:String(t)}function xx(t){if(Xn(t)){if(Array.isArray(t))return{width:yn(t[0]),height:yn(t[1])};const r=yn(t);return{width:r,height:r}}}function wx(t){const r={};return t!==void 0&&(r.zIndex=+t),r}const yx=/-(\w)/g,Mu=t=>t.replace(yx,(r,o)=>o.toUpperCase()),_x=t=>t.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,""),{hasOwnProperty:vx}=Object.prototype;function Cx(t,r,o){const c=r[o];Xn(c)&&(!vx.call(t,o)||!ji(c)?t[o]=c:t[o]=Du(Object(t[o]),c))}function Du(t,r){return Object.keys(r).forEach(o=>{Cx(t,r,o)}),t}var bx={name:"姓名",tel:"电话",save:"保存",clear:"清空",cancel:"取消",confirm:"确认",delete:"删除",loading:"加载中...",noCoupon:"暂无优惠券",nameEmpty:"请填写姓名",addContact:"添加联系人",telInvalid:"请填写正确的电话",vanCalendar:{end:"结束",start:"开始",title:"日期选择",weekdays:["日","一","二","三","四","五","六"],monthTitle:(t,r)=>`${t}年${r}月`,rangePrompt:t=>`最多选择 ${t} 天`},vanCascader:{select:"请选择"},vanPagination:{prev:"上一页",next:"下一页"},vanPullRefresh:{pulling:"下拉即可刷新...",loosing:"释放即可刷新..."},vanSubmitBar:{label:"合计:"},vanCoupon:{unlimited:"无门槛",discount:t=>`${t}折`,condition:t=>`满${t}元可用`},vanCouponCell:{title:"优惠券",count:t=>`${t}张可用`},vanCouponList:{exchange:"兑换",close:"不使用",enable:"可用",disabled:"不可用",placeholder:"输入优惠码"},vanAddressEdit:{area:"地区",areaEmpty:"请选择地区",addressEmpty:"请填写详细地址",addressDetail:"详细地址",defaultAddress:"设为默认收货地址"},vanAddressList:{add:"新增地址"}};const Wa=v.ref("zh-CN"),Ga=v.reactive({"zh-CN":bx}),Ex={messages(){return Ga[Wa.value]},use(t,r){Wa.value=t,this.add({[t]:r})},add(t={}){Du(Ga,t)}};var Ax=Ex;function Ix(t){const r=Mu(t)+".";return(o,...c)=>{const u=Ax.messages(),f=Ha(u,r+o)||Ha(u,o);return Do(f)?f(...c):f}}function Po(t,r){return r?typeof r=="string"?` ${t}--${r}`:Array.isArray(r)?r.reduce((o,c)=>o+Po(t,c),""):Object.keys(r).reduce((o,c)=>o+(r[c]?Po(t,c):""),""):""}function Sx(t){return(r,o)=>(r&&typeof r!="string"&&(o=r,r=""),r=r?`${t}__${r}`:t,`${r}${Po(r,o)}`)}function dr(t){const r=`van-${t}`;return[r,Sx(r),Ix(r)]}const Tx="van-haptics-feedback",Xa=5;function Nx(t,{args:r=[],done:o,canceled:c,error:u}){if(t){const f=t.apply(null,r);ax(f)?f.then(p=>{p?o():c&&c()}).catch(u||sx):f?o():c&&c()}else o()}function oi(t){return t.install=r=>{const{name:o}=t;o&&(r.component(o,t),r.component(Mu(`-${o}`),t))},t}const Ox=Symbol();function Pu(t){const r=v.getCurrentInstance();r&&On(r.proxy,t)}const[kx,qa]=dr("badge"),Rx={dot:Boolean,max:sn,tag:an("div"),color:String,offset:Array,content:sn,showZero:or,position:an("top-right")};var Mx=v.defineComponent({name:kx,props:Rx,setup(t,{slots:r}){const o=()=>{if(r.content)return!0;const{content:x,showZero:y}=t;return Xn(x)&&x!==""&&(y||x!==0&&x!=="0")},c=()=>{const{dot:x,max:y,content:m}=t;if(!x&&o())return r.content?r.content():Xn(y)&&Nu(m)&&+m>+y?`${y}+`:m},u=x=>x.startsWith("-")?x.replace("-",""):`-${x}`,f=v.computed(()=>{const x={background:t.color};if(t.offset){const[y,m]=t.offset,{position:A}=t,[E,B]=A.split("-");r.default?(typeof m=="number"?x[E]=yn(E==="top"?m:-m):x[E]=E==="top"?yn(m):u(m),typeof y=="number"?x[B]=yn(B==="left"?y:-y):x[B]=B==="left"?yn(y):u(y)):(x.marginTop=yn(m),x.marginLeft=yn(y))}return x}),p=()=>{if(o()||t.dot)return v.createVNode("div",{class:qa([t.position,{dot:t.dot,fixed:!!r.default}]),style:f.value},[c()])};return()=>{if(r.default){const{tag:x}=t;return v.createVNode(x,{class:qa("wrapper")},{default:()=>[r.default(),p()]})}return p()}}});const Dx=oi(Mx);let Bu=2e3;const Px=()=>++Bu,Bx=t=>{Bu=t},[Lu,Lx]=dr("config-provider"),Fu=Symbol(Lu),Fx={tag:an("div"),theme:an("light"),zIndex:Number,themeVars:Object,themeVarsDark:Object,themeVarsLight:Object,themeVarsScope:an("local"),iconPrefix:String};function Ux(t){return t.replace(/([a-zA-Z])(\d)/g,"$1-$2")}function zx(t){const r={};return Object.keys(t).forEach(o=>{const c=Ux(_x(o));r[`--van-${c}`]=t[o]}),r}function Ii(t={},r={}){Object.keys(t).forEach(o=>{t[o]!==r[o]&&document.documentElement.style.setProperty(o,t[o])}),Object.keys(r).forEach(o=>{t[o]||document.documentElement.style.removeProperty(o)})}v.defineComponent({name:Lu,props:Fx,setup(t,{slots:r}){const o=v.computed(()=>zx(On({},t.themeVars,t.theme==="dark"?t.themeVarsDark:t.themeVarsLight)));if(es){const c=()=>{document.documentElement.classList.add(`van-theme-${t.theme}`)},u=(f=t.theme)=>{document.documentElement.classList.remove(`van-theme-${f}`)};v.watch(()=>t.theme,(f,p)=>{p&&u(p),c()},{immediate:!0}),v.onActivated(c),v.onDeactivated(u),v.onBeforeUnmount(u),v.watch(o,(f,p)=>{t.themeVarsScope==="global"&&Ii(f,p)}),v.watch(()=>t.themeVarsScope,(f,p)=>{p==="global"&&Ii({},o.value),f==="global"&&Ii(o.value,{})}),t.themeVarsScope==="global"&&Ii(o.value,{})}return v.provide(Fu,t),v.watchEffect(()=>{t.zIndex!==void 0&&Bx(t.zIndex)}),()=>v.createVNode(t.tag,{class:Lx(),style:t.themeVarsScope==="local"?o.value:void 0},{default:()=>{var c;return[(c=r.default)==null?void 0:c.call(r)]}})}});const[Vx,Ya]=dr("icon"),$x=t=>t?.includes("/"),Zx={dot:Boolean,tag:an("i"),name:String,size:sn,badge:sn,color:String,badgeProps:Object,classPrefix:String};var jx=v.defineComponent({name:Vx,props:Zx,setup(t,{slots:r}){const o=v.inject(Fu,null),c=v.computed(()=>t.classPrefix||o?.iconPrefix||Ya());return()=>{const{tag:u,dot:f,name:p,size:x,badge:y,color:m}=t,A=$x(p);return v.createVNode(Dx,v.mergeProps({dot:f,tag:u,class:[c.value,A?"":`${c.value}-${p}`],style:{color:m,fontSize:yn(x)},content:y},t.badgeProps),{default:()=>{var E;return[(E=r.default)==null?void 0:E.call(r),A&&v.createVNode("img",{class:Ya("image"),src:p},null)]}})}}});const ns=oi(jx),[Hx,Xr]=dr("loading"),Wx=Array(12).fill(null).map((t,r)=>v.createVNode("i",{class:Xr("line",String(r+1))},null)),Gx=v.createVNode("svg",{class:Xr("circular"),viewBox:"25 25 50 50"},[v.createVNode("circle",{cx:"50",cy:"50",r:"20",fill:"none"},null)]),Xx={size:sn,type:an("circular"),color:String,vertical:Boolean,textSize:sn,textColor:String};var qx=v.defineComponent({name:Hx,props:Xx,setup(t,{slots:r}){const o=v.computed(()=>On({color:t.color},xx(t.size))),c=()=>{const f=t.type==="spinner"?Wx:Gx;return v.createVNode("span",{class:Xr("spinner",t.type),style:o.value},[r.icon?r.icon():f])},u=()=>{var f;if(r.default)return v.createVNode("span",{class:Xr("text"),style:{fontSize:yn(t.textSize),color:(f=t.textColor)!=null?f:t.color}},[r.default()])};return()=>{const{type:f,vertical:p}=t;return v.createVNode("div",{class:Xr([f,{vertical:p}]),"aria-live":"polite","aria-busy":!0},[c(),u()])}}});const Yx=oi(qx),Jx={show:Boolean,zIndex:sn,overlay:or,duration:sn,teleport:[String,Object],lockScroll:or,lazyRender:or,beforeClose:Function,overlayProps:Object,overlayStyle:Object,overlayClass:Bi,transitionAppear:Boolean,closeOnClickOverlay:or};function Kx(t,r){return t>r?"horizontal":r>t?"vertical":""}function Qx(){const t=v.ref(0),r=v.ref(0),o=v.ref(0),c=v.ref(0),u=v.ref(0),f=v.ref(0),p=v.ref(""),x=v.ref(!0),y=()=>p.value==="vertical",m=()=>p.value==="horizontal",A=()=>{o.value=0,c.value=0,u.value=0,f.value=0,p.value="",x.value=!0};return{move:(D=>{const M=D.touches[0];o.value=(M.clientX<0?0:M.clientX)-t.value,c.value=M.clientY-r.value,u.value=Math.abs(o.value),f.value=Math.abs(c.value);const R=10;(!p.value||u.value<R&&f.value<R)&&(p.value=Kx(u.value,f.value)),x.value&&(u.value>Xa||f.value>Xa)&&(x.value=!1)}),start:(D=>{A(),t.value=D.touches[0].clientX,r.value=D.touches[0].clientY}),reset:A,startX:t,startY:r,deltaX:o,deltaY:c,offsetX:u,offsetY:f,direction:p,isVertical:y,isHorizontal:m,isTap:x}}let zr=0;const Ja="van-overflow-hidden";function ew(t,r){const o=Qx(),c="01",u="10",f=A=>{o.move(A);const E=o.deltaY.value>0?u:c,B=gx(A.target,t.value),{scrollHeight:D,offsetHeight:M,scrollTop:R}=B;let k="11";R===0?k=M>=D?"00":"01":R+M>=D&&(k="10"),k!=="11"&&o.isVertical()&&!(parseInt(k,2)&parseInt(E,2))&&Ru(A)},p=()=>{document.addEventListener("touchstart",o.start),document.addEventListener("touchmove",f,{passive:!1}),zr||document.body.classList.add(Ja),zr++},x=()=>{zr&&(document.removeEventListener("touchstart",o.start),document.removeEventListener("touchmove",f),zr--,zr||document.body.classList.remove(Ja))},y=()=>r()&&p(),m=()=>r()&&x();Ou(y),v.onDeactivated(m),v.onBeforeUnmount(m),v.watch(r,A=>{A?p():x()})}function Uu(t){const r=v.ref(!1);return v.watch(t,o=>{o&&(r.value=o)},{immediate:!0}),o=>()=>r.value?o():null}const Ka=()=>{var t;const{scopeId:r}=((t=v.getCurrentInstance())==null?void 0:t.vnode)||{};return r?{[r]:""}:null},[tw,nw]=dr("overlay"),rw={show:Boolean,zIndex:sn,duration:sn,className:Bi,lockScroll:or,lazyRender:or,customStyle:Object,teleport:[String,Object]};var iw=v.defineComponent({name:tw,inheritAttrs:!1,props:rw,setup(t,{attrs:r,slots:o}){const c=v.ref(),u=Uu(()=>t.show||!t.lazyRender),f=x=>{t.lockScroll&&Ru(x)},p=u(()=>{var x;const y=On(wx(t.zIndex),t.customStyle);return Xn(t.duration)&&(y.animationDuration=`${t.duration}s`),v.withDirectives(v.createVNode("div",v.mergeProps({ref:c,style:y,class:[nw(),t.className]},r),[(x=o.default)==null?void 0:x.call(o)]),[[v.vShow,t.show]])});return ku("touchmove",f,{target:c}),()=>{const x=v.createVNode(v.Transition,{name:"van-fade",appear:!0},{default:p});return t.teleport?v.createVNode(v.Teleport,{to:t.teleport},{default:()=>[x]}):x}}});const ow=oi(iw),sw=On({},Jx,{round:Boolean,position:an("center"),closeIcon:an("cross"),closeable:Boolean,transition:String,iconPrefix:String,closeOnPopstate:Boolean,closeIconPosition:an("top-right"),destroyOnClose:Boolean,safeAreaInsetTop:Boolean,safeAreaInsetBottom:Boolean}),[aw,Qa]=dr("popup");var lw=v.defineComponent({name:aw,inheritAttrs:!1,props:sw,emits:["open","close","opened","closed","keydown","update:show","clickOverlay","clickCloseIcon"],setup(t,{emit:r,attrs:o,slots:c}){let u,f;const p=v.ref(),x=v.ref(),y=Uu(()=>t.show||!t.lazyRender),m=v.computed(()=>{const O={zIndex:p.value};if(Xn(t.duration)){const V=t.position==="center"?"animationDuration":"transitionDuration";O[V]=`${t.duration}s`}return O}),A=()=>{u||(u=!0,p.value=t.zIndex!==void 0?+t.zIndex:Px(),r("open"))},E=()=>{u&&Nx(t.beforeClose,{done(){u=!1,r("close"),r("update:show",!1)}})},B=O=>{r("clickOverlay",O),t.closeOnClickOverlay&&E()},D=()=>{if(t.overlay){const O=On({show:t.show,class:t.overlayClass,zIndex:p.value,duration:t.duration,customStyle:t.overlayStyle,role:t.closeOnClickOverlay?"button":void 0,tabindex:t.closeOnClickOverlay?0:void 0},t.overlayProps);return v.createVNode(ow,v.mergeProps(O,Ka(),{onClick:B}),{default:c["overlay-content"]})}},M=O=>{r("clickCloseIcon",O),E()},R=()=>{if(t.closeable)return v.createVNode(ns,{role:"button",tabindex:0,name:t.closeIcon,class:[Qa("close-icon",t.closeIconPosition),Tx],classPrefix:t.iconPrefix,onClick:M},null)};let k;const q=()=>{k&&clearTimeout(k),k=setTimeout(()=>{r("opened")})},Z=()=>r("closed"),z=O=>r("keydown",O),$=y(()=>{var O;const{destroyOnClose:V,round:le,position:j,safeAreaInsetTop:Ee,safeAreaInsetBottom:de,show:ne}=t;if(!(!ne&&V))return v.withDirectives(v.createVNode("div",v.mergeProps({ref:x,style:m.value,role:"dialog",tabindex:0,class:[Qa({round:le,[j]:j}),{"van-safe-area-top":Ee,"van-safe-area-bottom":de}],onKeydown:z},o,Ka()),[(O=c.default)==null?void 0:O.call(c),R()]),[[v.vShow,ne]])}),Q=()=>{const{position:O,transition:V,transitionAppear:le}=t,j=O==="center"?"van-fade":`van-popup-slide-${O}`;return v.createVNode(v.Transition,{name:V||j,appear:le,onAfterEnter:q,onAfterLeave:Z},{default:$})};return v.watch(()=>t.show,O=>{O&&!u&&(A(),o.tabindex===0&&v.nextTick(()=>{var V;(V=x.value)==null||V.focus()})),!O&&u&&(u=!1,r("close"))}),Pu({popupRef:x}),ew(x,()=>t.show&&t.lockScroll),ku("popstate",()=>{t.closeOnPopstate&&(E(),f=!1)}),v.onMounted(()=>{t.show&&A()}),v.onActivated(()=>{f&&(r("update:show",!0),f=!1)}),v.onDeactivated(()=>{t.show&&t.teleport&&(E(),f=!0)}),v.provide(Ox,()=>t.show),()=>t.teleport?v.createVNode(v.Teleport,{to:t.teleport},{default:()=>[D(),Q()]}):v.createVNode(v.Fragment,null,[D(),Q()])}});const cw=oi(lw);let Vr=0;function uw(t){t?(Vr||document.body.classList.add("van-toast--unclickable"),Vr++):Vr&&(Vr--,Vr||document.body.classList.remove("van-toast--unclickable"))}const[dw,Cr]=dr("toast"),fw=["show","overlay","teleport","transition","overlayClass","overlayStyle","closeOnClickOverlay","zIndex"],hw={icon:String,show:Boolean,type:an("text"),overlay:Boolean,message:sn,iconSize:sn,duration:ux(2e3),position:an("middle"),teleport:[String,Object],wordBreak:String,className:Bi,iconPrefix:String,transition:an("van-fade"),loadingType:String,forbidClick:Boolean,overlayClass:Bi,overlayStyle:Object,closeOnClick:Boolean,closeOnClickOverlay:Boolean,zIndex:sn};var pw=v.defineComponent({name:dw,props:hw,emits:["update:show"],setup(t,{emit:r,slots:o}){let c,u=!1;const f=()=>{const E=t.show&&t.forbidClick;u!==E&&(u=E,uw(u))},p=E=>r("update:show",E),x=()=>{t.closeOnClick&&p(!1)},y=()=>clearTimeout(c),m=()=>{const{icon:E,type:B,iconSize:D,iconPrefix:M,loadingType:R}=t;if(E||B==="success"||B==="fail")return v.createVNode(ns,{name:E||B,size:D,class:Cr("icon"),classPrefix:M},null);if(B==="loading")return v.createVNode(Yx,{class:Cr("loading"),size:D,type:R},null)},A=()=>{const{type:E,message:B}=t;if(o.message)return v.createVNode("div",{class:Cr("text")},[o.message()]);if(Xn(B)&&B!=="")return E==="html"?v.createVNode("div",{key:0,class:Cr("text"),innerHTML:String(B)},null):v.createVNode("div",{class:Cr("text")},[B])};return v.watch(()=>[t.show,t.forbidClick],f),v.watch(()=>[t.show,t.type,t.message,t.duration],()=>{y(),t.show&&t.duration>0&&(c=setTimeout(()=>{p(!1)},t.duration))}),v.onMounted(f),v.onUnmounted(f),()=>v.createVNode(cw,v.mergeProps({class:[Cr([t.position,t.wordBreak==="normal"?"break-normal":t.wordBreak,{[t.type]:!t.icon}]),t.className],lockScroll:!1,onClick:x,onClosed:y,"onUpdate:show":p},cx(t,fw)),{default:()=>[m(),A()]})}});function gw(){const t=v.reactive({show:!1}),r=u=>{t.show=u},o=u=>{On(t,u,{transitionAppear:!0}),r(!0)},c=()=>r(!1);return Pu({open:o,close:c,toggle:r}),{open:o,close:c,state:t,toggle:r}}function mw(t){const r=v.createApp(t),o=document.createElement("div");return document.body.appendChild(o),{instance:r.mount(o),unmount(){r.unmount(),document.body.removeChild(o)}}}const xw={icon:"",type:"text",message:"",className:"",overlay:!1,onClose:void 0,onOpened:void 0,duration:2e3,teleport:"body",iconSize:void 0,iconPrefix:void 0,position:"middle",transition:"van-fade",forbidClick:!1,loadingType:void 0,overlayClass:"",overlayStyle:void 0,closeOnClick:!1,closeOnClickOverlay:!1};let Si=[],ww=!1,el=On({},xw);const yw=new Map;function zu(t){return ji(t)?t:{message:t}}function _w(){const{instance:t}=mw({setup(){const r=v.ref(""),{open:o,state:c,close:u,toggle:f}=gw(),p=()=>{},x=()=>{const y={onClosed:p,"onUpdate:show":f};return v.createVNode(pw,v.mergeProps(c,y),null)};return v.watch(r,y=>{c.message=y}),v.getCurrentInstance().render=x,{open:o,close:u,message:r}}});return t}function vw(){if(!Si.length||ww){const t=_w();Si.push(t)}return Si[Si.length-1]}function Ye(t={}){if(!es)return{};const r=vw(),o=zu(t);return r.open(On({},el,yw.get(o.type||el.type),o)),r}const Cw=t=>r=>Ye(On({type:t},zu(r))),Vu=Cw("loading"),bw=t=>{try{const r=JSON.parse(t),o=[];if(!r.mcpServers||typeof r.mcpServers!="object")throw new Error("JSON 格式错误:缺少 mcpServers 字段");for(const[c,u]of Object.entries(r.mcpServers)){const f=Ew(u);f&&o.push({name:c,config:f})}return o}catch(r){throw new Error(`JSON 解析失败: ${r instanceof Error?r.message:"未知错误"}`)}},Ew=t=>{if(!t||typeof t!="object"||!t.url)return null;const{type:r,url:o,sessionId:c}=t;return r==="extension"?c?{type:"extension",url:o,sessionId:c,useAISdkClient:!0}:null:r==="streamableHttp"||r==="sse"?{type:r,url:o,useAISdkClient:!0}:{type:"streamableHttp",url:o,useAISdkClient:!0}},Aw=(t,r,o)=>{const c=async(f,p,x,y,m)=>{if(await t.insertMcpServer(f,p)){const E=t.mcpTools[f];if(E){const D={id:`plugin-${f.replace("mcp-server-","")}`,name:x,icon:m||o,description:y||(typeof p=="object"&&"url"in p?p.url:""),enabled:!0,expanded:!0,tools:Object.keys(E).map(M=>({id:M,name:M,description:E[M].description,enabled:!0})),originMcpConfig:v.markRaw(p)};return r.value.push(D),!0}else return await t.removeMcpServer(f),!1}else return!1};return{handleCustomAdd:async(f,p)=>{Vu("添加工具中...");try{if(f==="code"){if(typeof p!="string"){Ye("添加工具失败:code 类型需要 JSON 字符串格式");return}const q=bw(p);if(q.length===0){Ye("添加工具失败:JSON 配置格式不正确或未找到有效的服务器配置");return}let Z=0,z=0;for(const{name:$,config:Q}of q){const O=`mcp-server-${$}`;await c(O,Q,$)?Z++:z++}await t.closeAll(),z===0?Ye(`成功添加 ${Z} 个工具`):Z>0?Ye(`成功添加 ${Z} 个工具,${z} 个失败`):Ye("添加工具失败:所有服务器都无法连接");return}if(typeof p=="string"){Ye("添加工具失败:数据格式不正确");return}const{description:x,headers:y,name:m,thumbnail:A,type:E,url:B}=p;if(!m||!B||!E){Ye("添加工具失败:缺少必要参数(名称、URL或类型)");return}const M=`mcp-server-${`custom-${m}-${Date.now()}`}`;await c(M,{type:E,url:B,useAISdkClient:!0},m,x,A)?(await t.closeAll(),Ye("添加工具完成")):Ye("重复添加工具或无法获取工具列表")}catch(x){console.error("handleCustomAdd error:",x),Ye(`添加工具失败:${x instanceof Error?x.message:"未知错误"}`)}}}};function Iw(t,r,o){const c=v.ref([]),u=v.ref([]),f=v.ref(!1),p=$=>$==="mcp-server-localhost",x=($,Q)=>{Q?t.ignoreToolnames=t.ignoreToolnames.filter(O=>O!==$):t.ignoreToolnames.includes($)||t.ignoreToolnames.push($)},y=($,Q)=>{r.value||(r.value={});const O={...r.value};$===null?Object.keys(O).forEach(V=>{O[V]=Q}):O[$]=Q,r.value=O},m=$=>{const Q=u.value.find(O=>O.id===$);Q&&(Q.addState="idle")},A=$=>{const Q=t.mcpTools[$];if(!Q)return[];const O=p($),V=r.value||{};return Object.keys(Q).map(le=>{const j=O?!!V[le]:!0;return x(le,j),{id:le,name:le,description:Q[le].description,enabled:j}})},E=async $=>{const Q=$.pluginId;if(!await t.insertMcpServer(Q,$.mcpServer))return!1;if(!t.mcpTools[Q])return await t.removeMcpServer(Q),!1;const le=A(Q);if(le.length===0)return await t.removeMcpServer(Q),!1;const j=c.value.find(de=>de.id===$.pluginId);if(j)return j.tools=le,j.originMcpConfig=v.markRaw($.mcpServer),!0;const Ee={id:$.pluginId,name:$.name,icon:$.icon||o,description:$.description,enabled:!0,expanded:!1,tools:le,originMcpConfig:v.markRaw($.mcpServer)};return c.value.push(Ee),!0};return{installedPlugins:c,marketPlugins:u,pluginVisible:f,loadMcpServerToPlugin:async($,Q)=>{let O,V;if("type"in Q&&Q.type==="local")O="本地工具",V="本地工具列表";else{const le=new URL(Q.url);O=le.origin,V=le.searchParams.get("sessionId")||("sessionId"in Q?Q.sessionId:"")||""}await E({pluginId:$,name:O,description:V,mcpServer:Q})},togglePlugin:($,Q)=>{const O=p($.id);$.tools.forEach(V=>{V.enabled=Q,x(V.id,Q),O&&y(V.id,Q)})},toggleTool:($,Q,O)=>{const V=p($.id);$.tools.forEach(le=>{le.id===Q&&(le.enabled=O)}),x(Q,O),V&&y(Q,O)},deletePlugin:async $=>{const Q=c.value.find(V=>V.id===$.id);if(!Q)return;c.value=c.value.filter(V=>V.id!==Q.id),m(Q.id);const O=$.id;await t.removeMcpServer(O)},addPluginFromMarket:async $=>{$.addState="loading";const Q={type:$.type,url:$.url,useAISdkClient:!0},O=await E({pluginId:$.id,name:$.name,description:$.description||"",icon:$.icon,mcpServer:Q});$.addState=O?"added":"idle"},addPluginFromScan:async($,Q)=>{const O={type:"streamableHttp",url:`${Q}mcp?sessionId=${$}`},V=new URL(`${Q}mcp?sessionId=${$}`);return await E({pluginId:`plugin-${$}`,name:V.origin,description:$,mcpServer:O})},handleClientDisconnected:async $=>{const Q=$,O=c.value.find(V=>V.id===Q);return await t.removeMcpServer($),O?(c.value=c.value.filter(V=>V.id!==Q),m(Q),O):null},searchPlugin:($,Q)=>$.trim()===""||Q.name.toLowerCase().includes($.toLowerCase())}}function Sw(t){const{skillsRef:r,systemPrompt:o,customAgentProvider:c}=t,u=v.computed(()=>{const m=r?.value;return m?sr.getSkillOverviews(m):[]}),f=v.computed(()=>{const m=u.value;return m.length>0?sr.formatSkillsForSystemPrompt(m):""}),p=v.computed(()=>{const m=r?.value;return m?sr.createSkillTools(m):{}}),x=o||"";return v.watchEffect(()=>{if(c.systemPrompt=f.value?`${x}
54
+ ${r}:`]}}function Ma({id:t,model:r,created:o}){return{id:t??void 0,modelId:r??void 0,timestamp:o!=null?new Date(o*1e3):void 0}}function Da(t){switch(t){case"stop":return"stop";case"length":return"length";case"content_filter":return"content-filter";case"function_call":case"tool_calls":return"tool-calls";default:return"other"}}var Zg=$e(()=>ze(S({id:w().nullish(),created:Y().nullish(),model:w().nullish(),choices:me(S({text:w(),finish_reason:w(),logprobs:S({tokens:me(w()),token_logprobs:me(Y()),top_logprobs:me(gt(w(),Y())).nullish()}).nullish()})),usage:S({prompt_tokens:Y(),completion_tokens:Y(),total_tokens:Y()}).nullish()}))),jg=$e(()=>ze(Pe([S({id:w().nullish(),created:Y().nullish(),model:w().nullish(),choices:me(S({text:w(),finish_reason:w().nullish(),index:Y(),logprobs:S({tokens:me(w()),token_logprobs:me(Y()),top_logprobs:me(gt(w(),Y())).nullish()}).nullish()})),usage:S({prompt_tokens:Y(),completion_tokens:Y(),total_tokens:Y()}).nullish()}),es]))),Pa=$e(()=>ze(S({echo:Nt().optional(),logitBias:gt(w(),Y()).optional(),suffix:w().optional(),user:w().optional(),logprobs:Pe([Nt(),Y()]).optional()}))),Hg=class{constructor(t,r){this.specificationVersion="v3",this.supportedUrls={},this.modelId=t,this.config=r}get providerOptionsName(){return this.config.provider.split(".")[0].trim()}get provider(){return this.config.provider}async getArgs({prompt:t,maxOutputTokens:r,temperature:o,topP:c,topK:u,frequencyPenalty:f,presencePenalty:p,stopSequences:x,responseFormat:_,tools:g,toolChoice:A,seed:E,providerOptions:L}){const M=[],D={...await Bn({provider:"openai",providerOptions:L,schema:Pa}),...await Bn({provider:this.providerOptionsName,providerOptions:L,schema:Pa})};u!=null&&M.push({type:"unsupported",feature:"topK"}),g?.length&&M.push({type:"unsupported",feature:"tools"}),A!=null&&M.push({type:"unsupported",feature:"toolChoice"}),_!=null&&_.type!=="text"&&M.push({type:"unsupported",feature:"responseFormat",details:"JSON response format is not supported."});const{prompt:R,stopSequences:P}=$g({prompt:t}),H=[...P??[],...x??[]];return{args:{model:this.modelId,echo:D.echo,logit_bias:D.logitBias,logprobs:D?.logprobs===!0?0:D?.logprobs===!1?void 0:D?.logprobs,suffix:D.suffix,user:D.user,max_tokens:r,temperature:o,top_p:c,frequency_penalty:f,presence_penalty:p,seed:E,prompt:R,stop:H.length>0?H:void 0},warnings:M}}async doGenerate(t){var r;const{args:o,warnings:c}=await this.getArgs(t),{responseHeaders:u,value:f,rawValue:p}=await Ln({url:this.config.url({path:"/completions",modelId:this.modelId}),headers:Cn(this.config.headers(),t.headers),body:o,failedResponseHandler:bn,successfulResponseHandler:dr(Zg),abortSignal:t.abortSignal,fetch:this.config.fetch}),x=f.choices[0],_={openai:{}};return x.logprobs!=null&&(_.openai.logprobs=x.logprobs),{content:[{type:"text",text:x.text}],usage:Ra(f.usage),finishReason:{unified:Da(x.finish_reason),raw:(r=x.finish_reason)!=null?r:void 0},request:{body:o},response:{...Ma(f),headers:u,body:p},providerMetadata:_,warnings:c}}async doStream(t){const{args:r,warnings:o}=await this.getArgs(t),c={...r,stream:!0,stream_options:{include_usage:!0}},{responseHeaders:u,value:f}=await Ln({url:this.config.url({path:"/completions",modelId:this.modelId}),headers:Cn(this.config.headers(),t.headers),body:c,failedResponseHandler:bn,successfulResponseHandler:Ko(jg),abortSignal:t.abortSignal,fetch:this.config.fetch});let p={unified:"other",raw:void 0};const x={openai:{}};let _,g=!0;return{stream:f.pipeThrough(new TransformStream({start(A){A.enqueue({type:"stream-start",warnings:o})},transform(A,E){if(t.includeRawChunks&&E.enqueue({type:"raw",rawValue:A.rawValue}),!A.success){p={unified:"error",raw:void 0},E.enqueue({type:"error",error:A.error});return}const L=A.value;if("error"in L){p={unified:"error",raw:void 0},E.enqueue({type:"error",error:L.error});return}g&&(g=!1,E.enqueue({type:"response-metadata",...Ma(L)}),E.enqueue({type:"text-start",id:"0"})),L.usage!=null&&(_=L.usage);const M=L.choices[0];M?.finish_reason!=null&&(p={unified:Da(M.finish_reason),raw:M.finish_reason}),M?.logprobs!=null&&(x.openai.logprobs=M.logprobs),M?.text!=null&&M.text.length>0&&E.enqueue({type:"text-delta",id:"0",delta:M.text})},flush(A){g||A.enqueue({type:"text-end",id:"0"}),A.enqueue({type:"finish",finishReason:p,providerMetadata:x,usage:Ra(_)})}})),request:{body:c},response:{headers:u}}}},Wg=$e(()=>ze(S({dimensions:Y().optional(),user:w().optional()}))),Gg=$e(()=>ze(S({data:me(S({embedding:me(Y())})),usage:S({prompt_tokens:Y()}).nullish()}))),Xg=class{constructor(t,r){this.specificationVersion="v3",this.maxEmbeddingsPerCall=2048,this.supportsParallelCalls=!0,this.modelId=t,this.config=r}get provider(){return this.config.provider}async doEmbed({values:t,headers:r,abortSignal:o,providerOptions:c}){var u;if(t.length>this.maxEmbeddingsPerCall)throw new Fd({provider:this.provider,modelId:this.modelId,maxEmbeddingsPerCall:this.maxEmbeddingsPerCall,values:t});const f=(u=await Bn({provider:"openai",providerOptions:c,schema:Wg}))!=null?u:{},{responseHeaders:p,value:x,rawValue:_}=await Ln({url:this.config.url({path:"/embeddings",modelId:this.modelId}),headers:Cn(this.config.headers(),r),body:{model:this.modelId,input:t,encoding_format:"float",dimensions:f.dimensions,user:f.user},failedResponseHandler:bn,successfulResponseHandler:dr(Gg),abortSignal:o,fetch:this.config.fetch});return{warnings:[],embeddings:x.data.map(g=>g.embedding),usage:x.usage?{tokens:x.usage.prompt_tokens}:void 0,response:{headers:p,body:_}}}},Ba=$e(()=>ze(S({created:Y().nullish(),data:me(S({b64_json:w(),revised_prompt:w().nullish()})),background:w().nullish(),output_format:w().nullish(),size:w().nullish(),quality:w().nullish(),usage:S({input_tokens:Y().nullish(),output_tokens:Y().nullish(),total_tokens:Y().nullish(),input_tokens_details:S({image_tokens:Y().nullish(),text_tokens:Y().nullish()}).nullish()}).nullish()}))),qg={"dall-e-3":1,"dall-e-2":10,"gpt-image-1":10,"gpt-image-1-mini":10,"gpt-image-1.5":10,"chatgpt-image-latest":10},Yg=["chatgpt-image-","gpt-image-1-mini","gpt-image-1.5","gpt-image-1"];function Jg(t){return Yg.some(r=>t.startsWith(r))}var Kg=class{constructor(t,r){this.modelId=t,this.config=r,this.specificationVersion="v3"}get maxImagesPerCall(){var t;return(t=qg[this.modelId])!=null?t:1}get provider(){return this.config.provider}async doGenerate({prompt:t,files:r,mask:o,n:c,size:u,aspectRatio:f,seed:p,providerOptions:x,headers:_,abortSignal:g}){var A,E,L,M,D,R,P,H,Z,$,V;const ee=[];f!=null&&ee.push({type:"unsupported",feature:"aspectRatio",details:"This model does not support aspect ratio. Use `size` instead."}),p!=null&&ee.push({type:"unsupported",feature:"seed"});const j=(L=(E=(A=this.config._internal)==null?void 0:A.currentDate)==null?void 0:E.call(A))!=null?L:new Date;if(r!=null){const{value:B,responseHeaders:we}=await Ac({url:this.config.url({path:"/images/edits",modelId:this.modelId}),headers:Cn(this.config.headers(),_),formData:ep({model:this.modelId,prompt:t,image:await Promise.all(r.map(re=>re.type==="file"?new Blob([re.data instanceof Uint8Array?new Blob([re.data],{type:re.mediaType}):new Blob([Xo(re.data)],{type:re.mediaType})],{type:re.mediaType}):wc(re.url))),mask:o!=null?await Qg(o):void 0,n:c,size:u,...(M=x.openai)!=null?M:{}}),failedResponseHandler:bn,successfulResponseHandler:dr(Ba),abortSignal:g,fetch:this.config.fetch});return{images:B.data.map(re=>re.b64_json),warnings:ee,usage:B.usage!=null?{inputTokens:(D=B.usage.input_tokens)!=null?D:void 0,outputTokens:(R=B.usage.output_tokens)!=null?R:void 0,totalTokens:(P=B.usage.total_tokens)!=null?P:void 0}:void 0,response:{timestamp:j,modelId:this.modelId,headers:we},providerMetadata:{openai:{images:B.data.map((re,ne)=>{var le,te,O,J,ae,oe;return{...re.revised_prompt?{revisedPrompt:re.revised_prompt}:{},created:(le=B.created)!=null?le:void 0,size:(te=B.size)!=null?te:void 0,quality:(O=B.quality)!=null?O:void 0,background:(J=B.background)!=null?J:void 0,outputFormat:(ae=B.output_format)!=null?ae:void 0,...La((oe=B.usage)==null?void 0:oe.input_tokens_details,ne,B.data.length)}})}}}}const{value:z,responseHeaders:q}=await Ln({url:this.config.url({path:"/images/generations",modelId:this.modelId}),headers:Cn(this.config.headers(),_),body:{model:this.modelId,prompt:t,n:c,size:u,...(H=x.openai)!=null?H:{},...Jg(this.modelId)?{}:{response_format:"b64_json"}},failedResponseHandler:bn,successfulResponseHandler:dr(Ba),abortSignal:g,fetch:this.config.fetch});return{images:z.data.map(B=>B.b64_json),warnings:ee,usage:z.usage!=null?{inputTokens:(Z=z.usage.input_tokens)!=null?Z:void 0,outputTokens:($=z.usage.output_tokens)!=null?$:void 0,totalTokens:(V=z.usage.total_tokens)!=null?V:void 0}:void 0,response:{timestamp:j,modelId:this.modelId,headers:q},providerMetadata:{openai:{images:z.data.map((B,we)=>{var re,ne,le,te,O,J;return{...B.revised_prompt?{revisedPrompt:B.revised_prompt}:{},created:(re=z.created)!=null?re:void 0,size:(ne=z.size)!=null?ne:void 0,quality:(le=z.quality)!=null?le:void 0,background:(te=z.background)!=null?te:void 0,outputFormat:(O=z.output_format)!=null?O:void 0,...La((J=z.usage)==null?void 0:J.input_tokens_details,we,z.data.length)}})}}}}};function La(t,r,o){if(t==null)return{};const c={};if(t.image_tokens!=null){const u=Math.floor(t.image_tokens/o),f=t.image_tokens-u*(o-1);c.imageTokens=r===o-1?f:u}if(t.text_tokens!=null){const u=Math.floor(t.text_tokens/o),f=t.text_tokens-u*(o-1);c.textTokens=r===o-1?f:u}return c}async function Qg(t){if(!t)return;if(t.type==="url")return wc(t.url);const r=t.data instanceof Uint8Array?t.data:Xo(t.data);return new Blob([r],{type:t.mediaType})}var vu=$e(()=>ze(S({callId:w(),operation:lt("type",[S({type:W("create_file"),path:w(),diff:w()}),S({type:W("delete_file"),path:w()}),S({type:W("update_file"),path:w(),diff:w()})])}))),Cu=$e(()=>ze(S({status:Fe(["completed","failed"]),output:w().optional()}))),e2=Fn({id:"openai.apply_patch",inputSchema:vu,outputSchema:Cu}),t2=e2,n2=$e(()=>ze(S({code:w().nullish(),containerId:w()}))),r2=$e(()=>ze(S({outputs:me(lt("type",[S({type:W("logs"),logs:w()}),S({type:W("image"),url:w()})])).nullish()}))),i2=$e(()=>ze(S({container:Pe([w(),S({fileIds:me(w()).optional()})]).optional()}))),o2=Fn({id:"openai.code_interpreter",inputSchema:n2,outputSchema:r2}),s2=(t={})=>o2(t),bu=S({key:w(),type:Fe(["eq","ne","gt","gte","lt","lte","in","nin"]),value:Pe([w(),Y(),Nt(),me(w())])}),Eu=S({type:Fe(["and","or"]),filters:me(Pe([bu,Wo(()=>Eu)]))}),a2=$e(()=>ze(S({vectorStoreIds:me(w()),maxNumResults:Y().optional(),ranking:S({ranker:w().optional(),scoreThreshold:Y().optional()}).optional(),filters:Pe([bu,Eu]).optional()}))),l2=$e(()=>ze(S({queries:me(w()),results:me(S({attributes:gt(w(),Tr()),fileId:w(),filename:w(),score:Y(),text:w()})).nullable()}))),c2=Fn({id:"openai.file_search",inputSchema:S({}),outputSchema:l2}),u2=$e(()=>ze(S({background:Fe(["auto","opaque","transparent"]).optional(),inputFidelity:Fe(["low","high"]).optional(),inputImageMask:S({fileId:w().optional(),imageUrl:w().optional()}).optional(),model:w().optional(),moderation:Fe(["auto"]).optional(),outputCompression:Y().int().min(0).max(100).optional(),outputFormat:Fe(["png","jpeg","webp"]).optional(),partialImages:Y().int().min(0).max(3).optional(),quality:Fe(["auto","low","medium","high"]).optional(),size:Fe(["1024x1024","1024x1536","1536x1024","auto"]).optional()}).strict())),d2=$e(()=>ze(S({}))),f2=$e(()=>ze(S({result:w()}))),h2=Fn({id:"openai.image_generation",inputSchema:d2,outputSchema:f2}),p2=(t={})=>h2(t),Au=$e(()=>ze(S({action:S({type:W("exec"),command:me(w()),timeoutMs:Y().optional(),user:w().optional(),workingDirectory:w().optional(),env:gt(w(),w()).optional()})}))),Iu=$e(()=>ze(S({output:w()}))),m2=Fn({id:"openai.local_shell",inputSchema:Au,outputSchema:Iu}),Su=$e(()=>ze(S({action:S({commands:me(w()),timeoutMs:Y().optional(),maxOutputLength:Y().optional()})}))),Mo=$e(()=>ze(S({output:me(S({stdout:w(),stderr:w(),outcome:lt("type",[S({type:W("timeout")}),S({type:W("exit"),exitCode:Y()})])}))}))),g2=me(lt("type",[S({type:W("skillReference"),skillId:w(),version:w().optional()}),S({type:W("inline"),name:w(),description:w(),source:S({type:W("base64"),mediaType:W("application/zip"),data:w()})})])).optional(),x2=$e(()=>ze(S({environment:Pe([S({type:W("containerAuto"),fileIds:me(w()).optional(),memoryLimit:Fe(["1g","4g","16g","64g"]).optional(),networkPolicy:lt("type",[S({type:W("disabled")}),S({type:W("allowlist"),allowedDomains:me(w()),domainSecrets:me(S({domain:w(),name:w(),value:w()})).optional()})]).optional(),skills:g2}),S({type:W("containerReference"),containerId:w()}),S({type:W("local").optional(),skills:me(S({name:w(),description:w(),path:w()})).optional()})]).optional()}))),y2=Fn({id:"openai.shell",inputSchema:Su,outputSchema:Mo}),w2=$e(()=>ze(S({externalWebAccess:Nt().optional(),filters:S({allowedDomains:me(w()).optional()}).optional(),searchContextSize:Fe(["low","medium","high"]).optional(),userLocation:S({type:W("approximate"),country:w().optional(),city:w().optional(),region:w().optional(),timezone:w().optional()}).optional()}))),_2=$e(()=>ze(S({}))),v2=$e(()=>ze(S({action:lt("type",[S({type:W("search"),query:w().optional()}),S({type:W("openPage"),url:w().nullish()}),S({type:W("findInPage"),url:w().nullish(),pattern:w().nullish()})]).optional(),sources:me(lt("type",[S({type:W("url"),url:w()}),S({type:W("api"),name:w()})])).optional()}))),C2=Fn({id:"openai.web_search",inputSchema:_2,outputSchema:v2}),b2=(t={})=>C2(t),E2=$e(()=>ze(S({searchContextSize:Fe(["low","medium","high"]).optional(),userLocation:S({type:W("approximate"),country:w().optional(),city:w().optional(),region:w().optional(),timezone:w().optional()}).optional()}))),A2=$e(()=>ze(S({}))),I2=$e(()=>ze(S({action:lt("type",[S({type:W("search"),query:w().optional()}),S({type:W("openPage"),url:w().nullish()}),S({type:W("findInPage"),url:w().nullish(),pattern:w().nullish()})]).optional()}))),S2=Fn({id:"openai.web_search_preview",inputSchema:A2,outputSchema:I2}),Do=Wo(()=>Pe([w(),Y(),Nt(),dc(),me(Do),gt(w(),Do)])),T2=$e(()=>ze(S({serverLabel:w(),allowedTools:Pe([me(w()),S({readOnly:Nt().optional(),toolNames:me(w()).optional()})]).optional(),authorization:w().optional(),connectorId:w().optional(),headers:gt(w(),w()).optional(),requireApproval:Pe([Fe(["always","never"]),S({never:S({toolNames:me(w()).optional()}).optional()})]).optional(),serverDescription:w().optional(),serverUrl:w().optional()}).refine(t=>t.serverUrl!=null||t.connectorId!=null,"One of serverUrl or connectorId must be provided."))),N2=$e(()=>ze(S({}))),O2=$e(()=>ze(S({type:W("call"),serverLabel:w(),name:w(),arguments:w(),output:w().nullish(),error:Pe([w(),Do]).optional()}))),k2=Fn({id:"openai.mcp",inputSchema:N2,outputSchema:O2}),R2=t=>k2(t),M2={applyPatch:t2,codeInterpreter:s2,fileSearch:c2,imageGeneration:p2,localShell:m2,shell:y2,webSearchPreview:S2,webSearch:b2,mcp:R2};function Fa(t){var r,o,c,u;if(t==null)return{inputTokens:{total:void 0,noCache:void 0,cacheRead:void 0,cacheWrite:void 0},outputTokens:{total:void 0,text:void 0,reasoning:void 0},raw:void 0};const f=t.input_tokens,p=t.output_tokens,x=(o=(r=t.input_tokens_details)==null?void 0:r.cached_tokens)!=null?o:0,_=(u=(c=t.output_tokens_details)==null?void 0:c.reasoning_tokens)!=null?u:0;return{inputTokens:{total:f,noCache:f-x,cacheRead:x,cacheWrite:void 0},outputTokens:{total:p,text:p-_,reasoning:_},raw:t}}function Ua(t,r){return r?r.some(o=>t.startsWith(o)):!1}async function D2({prompt:t,toolNameMapping:r,systemMessageMode:o,providerOptionsName:c,fileIdPrefixes:u,store:f,hasConversation:p=!1,hasLocalShellTool:x=!1,hasShellTool:_=!1,hasApplyPatchTool:g=!1}){var A,E,L,M,D,R,P,H,Z,$,V,ee;const j=[],z=[],q=new Set;for(const{role:B,content:we}of t)switch(B){case"system":{switch(o){case"system":{j.push({role:"system",content:we});break}case"developer":{j.push({role:"developer",content:we});break}case"remove":{z.push({type:"other",message:"system messages are removed for this model"});break}default:{const re=o;throw new Error(`Unsupported system message mode: ${re}`)}}break}case"user":{j.push({role:"user",content:we.map((re,ne)=>{var le,te,O;switch(re.type){case"text":return{type:"input_text",text:re.text};case"file":if(re.mediaType.startsWith("image/")){const J=re.mediaType==="image/*"?"image/jpeg":re.mediaType;return{type:"input_image",...re.data instanceof URL?{image_url:re.data.toString()}:typeof re.data=="string"&&Ua(re.data,u)?{file_id:re.data}:{image_url:`data:${J};base64,${Ar(re.data)}`},detail:(te=(le=re.providerOptions)==null?void 0:le[c])==null?void 0:te.imageDetail}}else{if(re.mediaType==="application/pdf")return re.data instanceof URL?{type:"input_file",file_url:re.data.toString()}:{type:"input_file",...typeof re.data=="string"&&Ua(re.data,u)?{file_id:re.data}:{filename:(O=re.filename)!=null?O:`part-${ne}.pdf`,file_data:`data:application/pdf;base64,${Ar(re.data)}`}};throw new Dn({functionality:`file part media type ${re.mediaType}`})}}})});break}case"assistant":{const re={};for(const ne of we)switch(ne.type){case"text":{const le=(A=ne.providerOptions)==null?void 0:A[c],te=le?.itemId,O=le?.phase;if(p&&te!=null)break;if(f&&te!=null){j.push({type:"item_reference",id:te});break}j.push({role:"assistant",content:[{type:"output_text",text:ne.text}],id:te,...O!=null&&{phase:O}});break}case"tool-call":{const le=(R=(L=(E=ne.providerOptions)==null?void 0:E[c])==null?void 0:L.itemId)!=null?R:(D=(M=ne.providerMetadata)==null?void 0:M[c])==null?void 0:D.itemId;if(p&&le!=null)break;if(ne.providerExecuted){f&&le!=null&&j.push({type:"item_reference",id:le});break}if(f&&le!=null){j.push({type:"item_reference",id:le});break}const te=r.toProviderToolName(ne.toolName);if(x&&te==="local_shell"){const O=await Yt({value:ne.input,schema:Au});j.push({type:"local_shell_call",call_id:ne.toolCallId,id:le,action:{type:"exec",command:O.action.command,timeout_ms:O.action.timeoutMs,user:O.action.user,working_directory:O.action.workingDirectory,env:O.action.env}});break}if(_&&te==="shell"){const O=await Yt({value:ne.input,schema:Su});j.push({type:"shell_call",call_id:ne.toolCallId,id:le,status:"completed",action:{commands:O.action.commands,timeout_ms:O.action.timeoutMs,max_output_length:O.action.maxOutputLength}});break}if(g&&te==="apply_patch"){const O=await Yt({value:ne.input,schema:vu});j.push({type:"apply_patch_call",call_id:O.callId,id:le,status:"completed",operation:O.operation});break}j.push({type:"function_call",call_id:ne.toolCallId,name:te,arguments:JSON.stringify(ne.input),id:le});break}case"tool-result":{if(ne.output.type==="execution-denied"||ne.output.type==="json"&&typeof ne.output.value=="object"&&ne.output.value!=null&&"type"in ne.output.value&&ne.output.value.type==="execution-denied"||p)break;const le=r.toProviderToolName(ne.toolName);if(_&&le==="shell"){if(ne.output.type==="json"){const te=await Yt({value:ne.output.value,schema:Mo});j.push({type:"shell_call_output",call_id:ne.toolCallId,output:te.output.map(O=>({stdout:O.stdout,stderr:O.stderr,outcome:O.outcome.type==="timeout"?{type:"timeout"}:{type:"exit",exit_code:O.outcome.exitCode}}))})}break}if(f){const te=(Z=(H=(P=ne.providerOptions)==null?void 0:P[c])==null?void 0:H.itemId)!=null?Z:ne.toolCallId;j.push({type:"item_reference",id:te})}else z.push({type:"other",message:`Results for OpenAI tool ${ne.toolName} are not sent to the API when store is false`});break}case"reasoning":{const le=await Bn({provider:c,providerOptions:ne.providerOptions,schema:P2}),te=le?.itemId;if(p&&te!=null)break;if(te!=null){const O=re[te];if(f)O===void 0&&(j.push({type:"item_reference",id:te}),re[te]={type:"reasoning",id:te,summary:[]});else{const J=[];ne.text.length>0?J.push({type:"summary_text",text:ne.text}):O!==void 0&&z.push({type:"other",message:`Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(ne)}.`}),O===void 0?(re[te]={type:"reasoning",id:te,encrypted_content:le?.reasoningEncryptedContent,summary:J},j.push(re[te])):(O.summary.push(...J),le?.reasoningEncryptedContent!=null&&(O.encrypted_content=le.reasoningEncryptedContent))}}else{const O=le?.reasoningEncryptedContent;if(O!=null){const J=[];ne.text.length>0&&J.push({type:"summary_text",text:ne.text}),j.push({type:"reasoning",encrypted_content:O,summary:J})}else z.push({type:"other",message:`Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(ne)}.`})}break}}break}case"tool":{for(const re of we){if(re.type==="tool-approval-response"){const O=re;if(q.has(O.approvalId))continue;q.add(O.approvalId),f&&j.push({type:"item_reference",id:O.approvalId}),j.push({type:"mcp_approval_response",approval_request_id:O.approvalId,approve:O.approved});continue}const ne=re.output;if(ne.type==="execution-denied"&&((V=($=ne.providerOptions)==null?void 0:$.openai)==null?void 0:V.approvalId))continue;const le=r.toProviderToolName(re.toolName);if(x&&le==="local_shell"&&ne.type==="json"){const O=await Yt({value:ne.value,schema:Iu});j.push({type:"local_shell_call_output",call_id:re.toolCallId,output:O.output});continue}if(_&&le==="shell"&&ne.type==="json"){const O=await Yt({value:ne.value,schema:Mo});j.push({type:"shell_call_output",call_id:re.toolCallId,output:O.output.map(J=>({stdout:J.stdout,stderr:J.stderr,outcome:J.outcome.type==="timeout"?{type:"timeout"}:{type:"exit",exit_code:J.outcome.exitCode}}))});continue}if(g&&re.toolName==="apply_patch"&&ne.type==="json"){const O=await Yt({value:ne.value,schema:Cu});j.push({type:"apply_patch_call_output",call_id:re.toolCallId,status:O.status,output:O.output});continue}let te;switch(ne.type){case"text":case"error-text":te=ne.value;break;case"execution-denied":te=(ee=ne.reason)!=null?ee:"Tool execution denied.";break;case"json":case"error-json":te=JSON.stringify(ne.value);break;case"content":te=ne.value.map(O=>{var J;switch(O.type){case"text":return{type:"input_text",text:O.text};case"image-data":return{type:"input_image",image_url:`data:${O.mediaType};base64,${O.data}`};case"image-url":return{type:"input_image",image_url:O.url};case"file-data":return{type:"input_file",filename:(J=O.filename)!=null?J:"data",file_data:`data:${O.mediaType};base64,${O.data}`};default:{z.push({type:"other",message:`unsupported tool content part type: ${O.type}`});return}}}).filter(up);break}j.push({type:"function_call_output",call_id:re.toolCallId,output:te})}break}default:{const re=B;throw new Error(`Unsupported role: ${re}`)}}return{input:j,warnings:z}}var P2=S({itemId:w().nullish(),reasoningEncryptedContent:w().nullish()});function za({finishReason:t,hasFunctionCall:r}){switch(t){case void 0:case null:return r?"tool-calls":"stop";case"max_output_tokens":return"length";case"content_filter":return"content-filter";default:return r?"tool-calls":"other"}}var B2=$e(()=>ze(Pe([S({type:W("response.output_text.delta"),item_id:w(),delta:w(),logprobs:me(S({token:w(),logprob:Y(),top_logprobs:me(S({token:w(),logprob:Y()}))})).nullish()}),S({type:Fe(["response.completed","response.incomplete"]),response:S({incomplete_details:S({reason:w()}).nullish(),usage:S({input_tokens:Y(),input_tokens_details:S({cached_tokens:Y().nullish()}).nullish(),output_tokens:Y(),output_tokens_details:S({reasoning_tokens:Y().nullish()}).nullish()}),service_tier:w().nullish()})}),S({type:W("response.created"),response:S({id:w(),created_at:Y(),model:w(),service_tier:w().nullish()})}),S({type:W("response.output_item.added"),output_index:Y(),item:lt("type",[S({type:W("message"),id:w(),phase:Fe(["commentary","final_answer"]).nullish()}),S({type:W("reasoning"),id:w(),encrypted_content:w().nullish()}),S({type:W("function_call"),id:w(),call_id:w(),name:w(),arguments:w()}),S({type:W("web_search_call"),id:w(),status:w()}),S({type:W("computer_call"),id:w(),status:w()}),S({type:W("file_search_call"),id:w()}),S({type:W("image_generation_call"),id:w()}),S({type:W("code_interpreter_call"),id:w(),container_id:w(),code:w().nullable(),outputs:me(lt("type",[S({type:W("logs"),logs:w()}),S({type:W("image"),url:w()})])).nullable(),status:w()}),S({type:W("mcp_call"),id:w(),status:w(),approval_request_id:w().nullish()}),S({type:W("mcp_list_tools"),id:w()}),S({type:W("mcp_approval_request"),id:w()}),S({type:W("apply_patch_call"),id:w(),call_id:w(),status:Fe(["in_progress","completed"]),operation:lt("type",[S({type:W("create_file"),path:w(),diff:w()}),S({type:W("delete_file"),path:w()}),S({type:W("update_file"),path:w(),diff:w()})])}),S({type:W("shell_call"),id:w(),call_id:w(),status:Fe(["in_progress","completed","incomplete"]),action:S({commands:me(w())})}),S({type:W("shell_call_output"),id:w(),call_id:w(),status:Fe(["in_progress","completed","incomplete"]),output:me(S({stdout:w(),stderr:w(),outcome:lt("type",[S({type:W("timeout")}),S({type:W("exit"),exit_code:Y()})])}))})])}),S({type:W("response.output_item.done"),output_index:Y(),item:lt("type",[S({type:W("message"),id:w(),phase:Fe(["commentary","final_answer"]).nullish()}),S({type:W("reasoning"),id:w(),encrypted_content:w().nullish()}),S({type:W("function_call"),id:w(),call_id:w(),name:w(),arguments:w(),status:W("completed")}),S({type:W("code_interpreter_call"),id:w(),code:w().nullable(),container_id:w(),outputs:me(lt("type",[S({type:W("logs"),logs:w()}),S({type:W("image"),url:w()})])).nullable()}),S({type:W("image_generation_call"),id:w(),result:w()}),S({type:W("web_search_call"),id:w(),status:w(),action:lt("type",[S({type:W("search"),query:w().nullish(),sources:me(lt("type",[S({type:W("url"),url:w()}),S({type:W("api"),name:w()})])).nullish()}),S({type:W("open_page"),url:w().nullish()}),S({type:W("find_in_page"),url:w().nullish(),pattern:w().nullish()})]).nullish()}),S({type:W("file_search_call"),id:w(),queries:me(w()),results:me(S({attributes:gt(w(),Pe([w(),Y(),Nt()])),file_id:w(),filename:w(),score:Y(),text:w()})).nullish()}),S({type:W("local_shell_call"),id:w(),call_id:w(),action:S({type:W("exec"),command:me(w()),timeout_ms:Y().optional(),user:w().optional(),working_directory:w().optional(),env:gt(w(),w()).optional()})}),S({type:W("computer_call"),id:w(),status:W("completed")}),S({type:W("mcp_call"),id:w(),status:w(),arguments:w(),name:w(),server_label:w(),output:w().nullish(),error:Pe([w(),S({type:w().optional(),code:Pe([Y(),w()]).optional(),message:w().optional()}).loose()]).nullish(),approval_request_id:w().nullish()}),S({type:W("mcp_list_tools"),id:w(),server_label:w(),tools:me(S({name:w(),description:w().optional(),input_schema:hr(),annotations:gt(w(),Tr()).optional()})),error:Pe([w(),S({type:w().optional(),code:Pe([Y(),w()]).optional(),message:w().optional()}).loose()]).optional()}),S({type:W("mcp_approval_request"),id:w(),server_label:w(),name:w(),arguments:w(),approval_request_id:w().optional()}),S({type:W("apply_patch_call"),id:w(),call_id:w(),status:Fe(["in_progress","completed"]),operation:lt("type",[S({type:W("create_file"),path:w(),diff:w()}),S({type:W("delete_file"),path:w()}),S({type:W("update_file"),path:w(),diff:w()})])}),S({type:W("shell_call"),id:w(),call_id:w(),status:Fe(["in_progress","completed","incomplete"]),action:S({commands:me(w())})}),S({type:W("shell_call_output"),id:w(),call_id:w(),status:Fe(["in_progress","completed","incomplete"]),output:me(S({stdout:w(),stderr:w(),outcome:lt("type",[S({type:W("timeout")}),S({type:W("exit"),exit_code:Y()})])}))})])}),S({type:W("response.function_call_arguments.delta"),item_id:w(),output_index:Y(),delta:w()}),S({type:W("response.image_generation_call.partial_image"),item_id:w(),output_index:Y(),partial_image_b64:w()}),S({type:W("response.code_interpreter_call_code.delta"),item_id:w(),output_index:Y(),delta:w()}),S({type:W("response.code_interpreter_call_code.done"),item_id:w(),output_index:Y(),code:w()}),S({type:W("response.output_text.annotation.added"),annotation:lt("type",[S({type:W("url_citation"),start_index:Y(),end_index:Y(),url:w(),title:w()}),S({type:W("file_citation"),file_id:w(),filename:w(),index:Y()}),S({type:W("container_file_citation"),container_id:w(),file_id:w(),filename:w(),start_index:Y(),end_index:Y()}),S({type:W("file_path"),file_id:w(),index:Y()})])}),S({type:W("response.reasoning_summary_part.added"),item_id:w(),summary_index:Y()}),S({type:W("response.reasoning_summary_text.delta"),item_id:w(),summary_index:Y(),delta:w()}),S({type:W("response.reasoning_summary_part.done"),item_id:w(),summary_index:Y()}),S({type:W("response.apply_patch_call_operation_diff.delta"),item_id:w(),output_index:Y(),delta:w(),obfuscation:w().nullish()}),S({type:W("response.apply_patch_call_operation_diff.done"),item_id:w(),output_index:Y(),diff:w()}),S({type:W("error"),sequence_number:Y(),error:S({type:w(),code:w(),message:w(),param:w().nullish()})}),S({type:w()}).loose().transform(t=>({type:"unknown_chunk",message:t.type}))]))),L2=$e(()=>ze(S({id:w().optional(),created_at:Y().optional(),error:S({message:w(),type:w(),param:w().nullish(),code:w()}).nullish(),model:w().optional(),output:me(lt("type",[S({type:W("message"),role:W("assistant"),id:w(),phase:Fe(["commentary","final_answer"]).nullish(),content:me(S({type:W("output_text"),text:w(),logprobs:me(S({token:w(),logprob:Y(),top_logprobs:me(S({token:w(),logprob:Y()}))})).nullish(),annotations:me(lt("type",[S({type:W("url_citation"),start_index:Y(),end_index:Y(),url:w(),title:w()}),S({type:W("file_citation"),file_id:w(),filename:w(),index:Y()}),S({type:W("container_file_citation"),container_id:w(),file_id:w(),filename:w(),start_index:Y(),end_index:Y()}),S({type:W("file_path"),file_id:w(),index:Y()})]))}))}),S({type:W("web_search_call"),id:w(),status:w(),action:lt("type",[S({type:W("search"),query:w().nullish(),sources:me(lt("type",[S({type:W("url"),url:w()}),S({type:W("api"),name:w()})])).nullish()}),S({type:W("open_page"),url:w().nullish()}),S({type:W("find_in_page"),url:w().nullish(),pattern:w().nullish()})]).nullish()}),S({type:W("file_search_call"),id:w(),queries:me(w()),results:me(S({attributes:gt(w(),Pe([w(),Y(),Nt()])),file_id:w(),filename:w(),score:Y(),text:w()})).nullish()}),S({type:W("code_interpreter_call"),id:w(),code:w().nullable(),container_id:w(),outputs:me(lt("type",[S({type:W("logs"),logs:w()}),S({type:W("image"),url:w()})])).nullable()}),S({type:W("image_generation_call"),id:w(),result:w()}),S({type:W("local_shell_call"),id:w(),call_id:w(),action:S({type:W("exec"),command:me(w()),timeout_ms:Y().optional(),user:w().optional(),working_directory:w().optional(),env:gt(w(),w()).optional()})}),S({type:W("function_call"),call_id:w(),name:w(),arguments:w(),id:w()}),S({type:W("computer_call"),id:w(),status:w().optional()}),S({type:W("reasoning"),id:w(),encrypted_content:w().nullish(),summary:me(S({type:W("summary_text"),text:w()}))}),S({type:W("mcp_call"),id:w(),status:w(),arguments:w(),name:w(),server_label:w(),output:w().nullish(),error:Pe([w(),S({type:w().optional(),code:Pe([Y(),w()]).optional(),message:w().optional()}).loose()]).nullish(),approval_request_id:w().nullish()}),S({type:W("mcp_list_tools"),id:w(),server_label:w(),tools:me(S({name:w(),description:w().optional(),input_schema:hr(),annotations:gt(w(),Tr()).optional()})),error:Pe([w(),S({type:w().optional(),code:Pe([Y(),w()]).optional(),message:w().optional()}).loose()]).optional()}),S({type:W("mcp_approval_request"),id:w(),server_label:w(),name:w(),arguments:w(),approval_request_id:w().optional()}),S({type:W("apply_patch_call"),id:w(),call_id:w(),status:Fe(["in_progress","completed"]),operation:lt("type",[S({type:W("create_file"),path:w(),diff:w()}),S({type:W("delete_file"),path:w()}),S({type:W("update_file"),path:w(),diff:w()})])}),S({type:W("shell_call"),id:w(),call_id:w(),status:Fe(["in_progress","completed","incomplete"]),action:S({commands:me(w())})}),S({type:W("shell_call_output"),id:w(),call_id:w(),status:Fe(["in_progress","completed","incomplete"]),output:me(S({stdout:w(),stderr:w(),outcome:lt("type",[S({type:W("timeout")}),S({type:W("exit"),exit_code:Y()})])}))})])).optional(),service_tier:w().nullish(),incomplete_details:S({reason:w()}).nullish(),usage:S({input_tokens:Y(),input_tokens_details:S({cached_tokens:Y().nullish()}).nullish(),output_tokens:Y(),output_tokens_details:S({reasoning_tokens:Y().nullish()}).nullish()}).optional()}))),Tu=20,Va=$e(()=>ze(S({conversation:w().nullish(),include:me(Fe(["reasoning.encrypted_content","file_search_call.results","message.output_text.logprobs"])).nullish(),instructions:w().nullish(),logprobs:Pe([Nt(),Y().min(1).max(Tu)]).optional(),maxToolCalls:Y().nullish(),metadata:hr().nullish(),parallelToolCalls:Nt().nullish(),previousResponseId:w().nullish(),promptCacheKey:w().nullish(),promptCacheRetention:Fe(["in_memory","24h"]).nullish(),reasoningEffort:w().nullish(),reasoningSummary:w().nullish(),safetyIdentifier:w().nullish(),serviceTier:Fe(["auto","flex","priority","default"]).nullish(),store:Nt().nullish(),strictJsonSchema:Nt().nullish(),textVerbosity:Fe(["low","medium","high"]).nullish(),truncation:Fe(["auto","disabled"]).nullish(),user:w().nullish(),systemMessageMode:Fe(["system","developer","remove"]).optional(),forceReasoning:Nt().optional()})));async function F2({tools:t,toolChoice:r}){t=t?.length?t:void 0;const o=[];if(t==null)return{tools:void 0,toolChoice:void 0,toolWarnings:o};const c=[];for(const f of t)switch(f.type){case"function":c.push({type:"function",name:f.name,description:f.description,parameters:f.inputSchema,...f.strict!=null?{strict:f.strict}:{}});break;case"provider":{switch(f.id){case"openai.file_search":{const p=await Yt({value:f.args,schema:a2});c.push({type:"file_search",vector_store_ids:p.vectorStoreIds,max_num_results:p.maxNumResults,ranking_options:p.ranking?{ranker:p.ranking.ranker,score_threshold:p.ranking.scoreThreshold}:void 0,filters:p.filters});break}case"openai.local_shell":{c.push({type:"local_shell"});break}case"openai.shell":{const p=await Yt({value:f.args,schema:x2});c.push({type:"shell",...p.environment&&{environment:U2(p.environment)}});break}case"openai.apply_patch":{c.push({type:"apply_patch"});break}case"openai.web_search_preview":{const p=await Yt({value:f.args,schema:E2});c.push({type:"web_search_preview",search_context_size:p.searchContextSize,user_location:p.userLocation});break}case"openai.web_search":{const p=await Yt({value:f.args,schema:w2});c.push({type:"web_search",filters:p.filters!=null?{allowed_domains:p.filters.allowedDomains}:void 0,external_web_access:p.externalWebAccess,search_context_size:p.searchContextSize,user_location:p.userLocation});break}case"openai.code_interpreter":{const p=await Yt({value:f.args,schema:i2});c.push({type:"code_interpreter",container:p.container==null?{type:"auto",file_ids:void 0}:typeof p.container=="string"?p.container:{type:"auto",file_ids:p.container.fileIds}});break}case"openai.image_generation":{const p=await Yt({value:f.args,schema:u2});c.push({type:"image_generation",background:p.background,input_fidelity:p.inputFidelity,input_image_mask:p.inputImageMask?{file_id:p.inputImageMask.fileId,image_url:p.inputImageMask.imageUrl}:void 0,model:p.model,moderation:p.moderation,partial_images:p.partialImages,quality:p.quality,output_compression:p.outputCompression,output_format:p.outputFormat,size:p.size});break}case"openai.mcp":{const p=await Yt({value:f.args,schema:T2}),x=A=>({tool_names:A.toolNames}),_=p.requireApproval,g=_==null?void 0:typeof _=="string"?_:_.never!=null?{never:x(_.never)}:void 0;c.push({type:"mcp",server_label:p.serverLabel,allowed_tools:Array.isArray(p.allowedTools)?p.allowedTools:p.allowedTools?{read_only:p.allowedTools.readOnly,tool_names:p.allowedTools.toolNames}:void 0,authorization:p.authorization,connector_id:p.connectorId,headers:p.headers,require_approval:g??"never",server_description:p.serverDescription,server_url:p.serverUrl});break}}break}default:o.push({type:"unsupported",feature:`function tool ${f}`});break}if(r==null)return{tools:c,toolChoice:void 0,toolWarnings:o};const u=r.type;switch(u){case"auto":case"none":case"required":return{tools:c,toolChoice:u,toolWarnings:o};case"tool":return{tools:c,toolChoice:r.toolName==="code_interpreter"||r.toolName==="file_search"||r.toolName==="image_generation"||r.toolName==="web_search_preview"||r.toolName==="web_search"||r.toolName==="mcp"||r.toolName==="apply_patch"?{type:r.toolName}:{type:"function",name:r.toolName},toolWarnings:o};default:{const f=u;throw new Dn({functionality:`tool choice type: ${f}`})}}}function U2(t){if(t.type==="containerReference")return{type:"container_reference",container_id:t.containerId};if(t.type==="containerAuto"){const o=t;return{type:"container_auto",file_ids:o.fileIds,memory_limit:o.memoryLimit,network_policy:o.networkPolicy==null?void 0:o.networkPolicy.type==="disabled"?{type:"disabled"}:{type:"allowlist",allowed_domains:o.networkPolicy.allowedDomains,domain_secrets:o.networkPolicy.domainSecrets},skills:z2(o.skills)}}return{type:"local",skills:t.skills}}function z2(t){return t?.map(r=>r.type==="skillReference"?{type:"skill_reference",skill_id:r.skillId,version:r.version}:{type:"inline",name:r.name,description:r.description,source:{type:"base64",media_type:r.source.mediaType,data:r.source.data}})}function $a(t){var r,o;const c={};for(const u of t)if(u.role==="assistant")for(const f of u.content){if(f.type!=="tool-call")continue;const p=(o=(r=f.providerOptions)==null?void 0:r.openai)==null?void 0:o.approvalRequestId;p!=null&&(c[p]=f.toolCallId)}return c}var V2=class{constructor(t,r){this.specificationVersion="v3",this.supportedUrls={"image/*":[/^https?:\/\/.*$/],"application/pdf":[/^https?:\/\/.*$/]},this.modelId=t,this.config=r}get provider(){return this.config.provider}async getArgs({maxOutputTokens:t,temperature:r,stopSequences:o,topP:c,topK:u,presencePenalty:f,frequencyPenalty:p,seed:x,prompt:_,providerOptions:g,tools:A,toolChoice:E,responseFormat:L}){var M,D,R,P,H,Z,$,V,ee;const j=[],z=_u(this.modelId);u!=null&&j.push({type:"unsupported",feature:"topK"}),x!=null&&j.push({type:"unsupported",feature:"seed"}),f!=null&&j.push({type:"unsupported",feature:"presencePenalty"}),p!=null&&j.push({type:"unsupported",feature:"frequencyPenalty"}),o!=null&&j.push({type:"unsupported",feature:"stopSequences"});const q=this.config.provider.includes("azure")?"azure":"openai";let B=await Bn({provider:q,providerOptions:g,schema:Va});B==null&&q!=="openai"&&(B=await Bn({provider:"openai",providerOptions:g,schema:Va}));const we=(M=B?.forceReasoning)!=null?M:z.isReasoningModel;B?.conversation&&B?.previousResponseId&&j.push({type:"unsupported",feature:"conversation",details:"conversation and previousResponseId cannot be used together"});const re=qh({tools:A,providerToolNames:{"openai.code_interpreter":"code_interpreter","openai.file_search":"file_search","openai.image_generation":"image_generation","openai.local_shell":"local_shell","openai.shell":"shell","openai.web_search":"web_search","openai.web_search_preview":"web_search_preview","openai.mcp":"mcp","openai.apply_patch":"apply_patch"}}),{input:ne,warnings:le}=await D2({prompt:_,toolNameMapping:re,systemMessageMode:(D=B?.systemMessageMode)!=null?D:we?"developer":z.systemMessageMode,providerOptionsName:q,fileIdPrefixes:this.config.fileIdPrefixes,store:(R=B?.store)!=null?R:!0,hasConversation:B?.conversation!=null,hasLocalShellTool:ae("openai.local_shell"),hasShellTool:ae("openai.shell"),hasApplyPatchTool:ae("openai.apply_patch")});j.push(...le);const te=(P=B?.strictJsonSchema)!=null?P:!0;let O=B?.include;function J(Ae){O==null?O=[Ae]:O.includes(Ae)||(O=[...O,Ae])}function ae(Ae){return A?.find(Me=>Me.type==="provider"&&Me.id===Ae)!=null}const oe=typeof B?.logprobs=="number"?B?.logprobs:B?.logprobs===!0?Tu:void 0;oe&&J("message.output_text.logprobs");const ge=(H=A?.find(Ae=>Ae.type==="provider"&&(Ae.id==="openai.web_search"||Ae.id==="openai.web_search_preview")))==null?void 0:H.name;ge&&J("web_search_call.action.sources"),ae("openai.code_interpreter")&&J("code_interpreter_call.outputs");const he=B?.store;he===!1&&we&&J("reasoning.encrypted_content");const ue={model:this.modelId,input:ne,temperature:r,top_p:c,max_output_tokens:t,...(L?.type==="json"||B?.textVerbosity)&&{text:{...L?.type==="json"&&{format:L.schema!=null?{type:"json_schema",strict:te,name:(Z=L.name)!=null?Z:"response",description:L.description,schema:L.schema}:{type:"json_object"}},...B?.textVerbosity&&{verbosity:B.textVerbosity}}},conversation:B?.conversation,max_tool_calls:B?.maxToolCalls,metadata:B?.metadata,parallel_tool_calls:B?.parallelToolCalls,previous_response_id:B?.previousResponseId,store:he,user:B?.user,instructions:B?.instructions,service_tier:B?.serviceTier,include:O,prompt_cache_key:B?.promptCacheKey,prompt_cache_retention:B?.promptCacheRetention,safety_identifier:B?.safetyIdentifier,top_logprobs:oe,truncation:B?.truncation,...we&&(B?.reasoningEffort!=null||B?.reasoningSummary!=null)&&{reasoning:{...B?.reasoningEffort!=null&&{effort:B.reasoningEffort},...B?.reasoningSummary!=null&&{summary:B.reasoningSummary}}}};we?B?.reasoningEffort==="none"&&z.supportsNonReasoningParameters||(ue.temperature!=null&&(ue.temperature=void 0,j.push({type:"unsupported",feature:"temperature",details:"temperature is not supported for reasoning models"})),ue.top_p!=null&&(ue.top_p=void 0,j.push({type:"unsupported",feature:"topP",details:"topP is not supported for reasoning models"}))):(B?.reasoningEffort!=null&&j.push({type:"unsupported",feature:"reasoningEffort",details:"reasoningEffort is not supported for non-reasoning models"}),B?.reasoningSummary!=null&&j.push({type:"unsupported",feature:"reasoningSummary",details:"reasoningSummary is not supported for non-reasoning models"})),B?.serviceTier==="flex"&&!z.supportsFlexProcessing&&(j.push({type:"unsupported",feature:"serviceTier",details:"flex processing is only available for o3, o4-mini, and gpt-5 models"}),delete ue.service_tier),B?.serviceTier==="priority"&&!z.supportsPriorityProcessing&&(j.push({type:"unsupported",feature:"serviceTier",details:"priority processing is only available for supported models (gpt-4, gpt-5, gpt-5-mini, o3, o4-mini) and requires Enterprise access. gpt-5-nano is not supported"}),delete ue.service_tier);const{tools:Ce,toolChoice:je,toolWarnings:Be}=await F2({tools:A,toolChoice:E}),ut=(ee=(V=($=A?.find(Ae=>Ae.type==="provider"&&Ae.id==="openai.shell"))==null?void 0:$.args)==null?void 0:V.environment)==null?void 0:ee.type,ie=ut==="containerAuto"||ut==="containerReference";return{webSearchToolName:ge,args:{...ue,tools:Ce,tool_choice:je},warnings:[...j,...Be],store:he,toolNameMapping:re,providerOptionsName:q,isShellProviderExecuted:ie}}async doGenerate(t){var r,o,c,u,f,p,x,_,g,A,E,L,M,D,R,P,H,Z,$,V,ee,j,z,q,B;const{args:we,warnings:re,webSearchToolName:ne,toolNameMapping:le,providerOptionsName:te,isShellProviderExecuted:O}=await this.getArgs(t),J=this.config.url({path:"/responses",modelId:this.modelId}),ae=$a(t.prompt),{responseHeaders:oe,value:ge,rawValue:he}=await Ln({url:J,headers:Cn(this.config.headers(),t.headers),body:we,failedResponseHandler:bn,successfulResponseHandler:dr(L2),abortSignal:t.abortSignal,fetch:this.config.fetch});if(ge.error)throw new an({message:ge.error.message,url:J,requestBodyValues:we,statusCode:400,responseHeaders:oe,responseBody:he,isRetryable:!1});const ue=[],Ce=[];let je=!1;for(const ie of ge.output)switch(ie.type){case"reasoning":{ie.summary.length===0&&ie.summary.push({type:"summary_text",text:""});for(const Ae of ie.summary)ue.push({type:"reasoning",text:Ae.text,providerMetadata:{[te]:{itemId:ie.id,reasoningEncryptedContent:(r=ie.encrypted_content)!=null?r:null}}});break}case"image_generation_call":{ue.push({type:"tool-call",toolCallId:ie.id,toolName:le.toCustomToolName("image_generation"),input:"{}",providerExecuted:!0}),ue.push({type:"tool-result",toolCallId:ie.id,toolName:le.toCustomToolName("image_generation"),result:{result:ie.result}});break}case"local_shell_call":{ue.push({type:"tool-call",toolCallId:ie.call_id,toolName:le.toCustomToolName("local_shell"),input:JSON.stringify({action:ie.action}),providerMetadata:{[te]:{itemId:ie.id}}});break}case"shell_call":{ue.push({type:"tool-call",toolCallId:ie.call_id,toolName:le.toCustomToolName("shell"),input:JSON.stringify({action:{commands:ie.action.commands}}),...O&&{providerExecuted:!0},providerMetadata:{[te]:{itemId:ie.id}}});break}case"shell_call_output":{ue.push({type:"tool-result",toolCallId:ie.call_id,toolName:le.toCustomToolName("shell"),result:{output:ie.output.map(Ae=>({stdout:Ae.stdout,stderr:Ae.stderr,outcome:Ae.outcome.type==="exit"?{type:"exit",exitCode:Ae.outcome.exit_code}:{type:"timeout"}}))}});break}case"message":{for(const Ae of ie.content){(c=(o=t.providerOptions)==null?void 0:o[te])!=null&&c.logprobs&&Ae.logprobs&&Ce.push(Ae.logprobs);const Me={itemId:ie.id,...ie.phase!=null&&{phase:ie.phase},...Ae.annotations.length>0&&{annotations:Ae.annotations}};ue.push({type:"text",text:Ae.text,providerMetadata:{[te]:Me}});for(const ke of Ae.annotations)ke.type==="url_citation"?ue.push({type:"source",sourceType:"url",id:(p=(f=(u=this.config).generateId)==null?void 0:f.call(u))!=null?p:qt(),url:ke.url,title:ke.title}):ke.type==="file_citation"?ue.push({type:"source",sourceType:"document",id:(g=(_=(x=this.config).generateId)==null?void 0:_.call(x))!=null?g:qt(),mediaType:"text/plain",title:ke.filename,filename:ke.filename,providerMetadata:{[te]:{type:ke.type,fileId:ke.file_id,index:ke.index}}}):ke.type==="container_file_citation"?ue.push({type:"source",sourceType:"document",id:(L=(E=(A=this.config).generateId)==null?void 0:E.call(A))!=null?L:qt(),mediaType:"text/plain",title:ke.filename,filename:ke.filename,providerMetadata:{[te]:{type:ke.type,fileId:ke.file_id,containerId:ke.container_id}}}):ke.type==="file_path"&&ue.push({type:"source",sourceType:"document",id:(R=(D=(M=this.config).generateId)==null?void 0:D.call(M))!=null?R:qt(),mediaType:"application/octet-stream",title:ke.file_id,filename:ke.file_id,providerMetadata:{[te]:{type:ke.type,fileId:ke.file_id,index:ke.index}}})}break}case"function_call":{je=!0,ue.push({type:"tool-call",toolCallId:ie.call_id,toolName:ie.name,input:ie.arguments,providerMetadata:{[te]:{itemId:ie.id}}});break}case"web_search_call":{ue.push({type:"tool-call",toolCallId:ie.id,toolName:le.toCustomToolName(ne??"web_search"),input:JSON.stringify({}),providerExecuted:!0}),ue.push({type:"tool-result",toolCallId:ie.id,toolName:le.toCustomToolName(ne??"web_search"),result:ja(ie.action)});break}case"mcp_call":{const Ae=ie.approval_request_id!=null&&(P=ae[ie.approval_request_id])!=null?P:ie.id,Me=`mcp.${ie.name}`;ue.push({type:"tool-call",toolCallId:Ae,toolName:Me,input:ie.arguments,providerExecuted:!0,dynamic:!0}),ue.push({type:"tool-result",toolCallId:Ae,toolName:Me,result:{type:"call",serverLabel:ie.server_label,name:ie.name,arguments:ie.arguments,...ie.output!=null?{output:ie.output}:{},...ie.error!=null?{error:ie.error}:{}},providerMetadata:{[te]:{itemId:ie.id}}});break}case"mcp_list_tools":break;case"mcp_approval_request":{const Ae=(H=ie.approval_request_id)!=null?H:ie.id,Me=(V=($=(Z=this.config).generateId)==null?void 0:$.call(Z))!=null?V:qt(),ke=`mcp.${ie.name}`;ue.push({type:"tool-call",toolCallId:Me,toolName:ke,input:ie.arguments,providerExecuted:!0,dynamic:!0}),ue.push({type:"tool-approval-request",approvalId:Ae,toolCallId:Me});break}case"computer_call":{ue.push({type:"tool-call",toolCallId:ie.id,toolName:le.toCustomToolName("computer_use"),input:"",providerExecuted:!0}),ue.push({type:"tool-result",toolCallId:ie.id,toolName:le.toCustomToolName("computer_use"),result:{type:"computer_use_tool_result",status:ie.status||"completed"}});break}case"file_search_call":{ue.push({type:"tool-call",toolCallId:ie.id,toolName:le.toCustomToolName("file_search"),input:"{}",providerExecuted:!0}),ue.push({type:"tool-result",toolCallId:ie.id,toolName:le.toCustomToolName("file_search"),result:{queries:ie.queries,results:(j=(ee=ie.results)==null?void 0:ee.map(Ae=>({attributes:Ae.attributes,fileId:Ae.file_id,filename:Ae.filename,score:Ae.score,text:Ae.text})))!=null?j:null}});break}case"code_interpreter_call":{ue.push({type:"tool-call",toolCallId:ie.id,toolName:le.toCustomToolName("code_interpreter"),input:JSON.stringify({code:ie.code,containerId:ie.container_id}),providerExecuted:!0}),ue.push({type:"tool-result",toolCallId:ie.id,toolName:le.toCustomToolName("code_interpreter"),result:{outputs:ie.outputs}});break}case"apply_patch_call":{ue.push({type:"tool-call",toolCallId:ie.call_id,toolName:le.toCustomToolName("apply_patch"),input:JSON.stringify({callId:ie.call_id,operation:ie.operation}),providerMetadata:{[te]:{itemId:ie.id}}});break}}const Be={[te]:{responseId:ge.id,...Ce.length>0?{logprobs:Ce}:{},...typeof ge.service_tier=="string"?{serviceTier:ge.service_tier}:{}}},ut=ge.usage;return{content:ue,finishReason:{unified:za({finishReason:(z=ge.incomplete_details)==null?void 0:z.reason,hasFunctionCall:je}),raw:(B=(q=ge.incomplete_details)==null?void 0:q.reason)!=null?B:void 0},usage:Fa(ut),request:{body:we},response:{id:ge.id,timestamp:new Date(ge.created_at*1e3),modelId:ge.model,headers:oe,body:he},providerMetadata:Be,warnings:re}}async doStream(t){const{args:r,warnings:o,webSearchToolName:c,toolNameMapping:u,store:f,providerOptionsName:p,isShellProviderExecuted:x}=await this.getArgs(t),{responseHeaders:_,value:g}=await Ln({url:this.config.url({path:"/responses",modelId:this.modelId}),headers:Cn(this.config.headers(),t.headers),body:{...r,stream:!0},failedResponseHandler:bn,successfulResponseHandler:Ko(B2),abortSignal:t.abortSignal,fetch:this.config.fetch}),A=this,E=$a(t.prompt),L=new Map;let M={unified:"other",raw:void 0},D;const R=[];let P=null;const H={},Z=[];let $,V=!1;const ee={};let j;return{stream:g.pipeThrough(new TransformStream({start(z){z.enqueue({type:"stream-start",warnings:o})},transform(z,q){var B,we,re,ne,le,te,O,J,ae,oe,ge,he,ue,Ce,je,Be,ut,ie,Ae,Me,ke,et,tt,Wt,Le,gn,Zt,En,Et,Xe,Ze,dn;if(t.includeRawChunks&&q.enqueue({type:"raw",rawValue:z.rawValue}),!z.success){M={unified:"error",raw:void 0},q.enqueue({type:"error",error:z.error});return}const N=z.value;if(Za(N)){if(N.item.type==="function_call")H[N.output_index]={toolName:N.item.name,toolCallId:N.item.call_id},q.enqueue({type:"tool-input-start",id:N.item.call_id,toolName:N.item.name});else if(N.item.type==="web_search_call")H[N.output_index]={toolName:u.toCustomToolName(c??"web_search"),toolCallId:N.item.id},q.enqueue({type:"tool-input-start",id:N.item.id,toolName:u.toCustomToolName(c??"web_search"),providerExecuted:!0}),q.enqueue({type:"tool-input-end",id:N.item.id}),q.enqueue({type:"tool-call",toolCallId:N.item.id,toolName:u.toCustomToolName(c??"web_search"),input:JSON.stringify({}),providerExecuted:!0});else if(N.item.type==="computer_call")H[N.output_index]={toolName:u.toCustomToolName("computer_use"),toolCallId:N.item.id},q.enqueue({type:"tool-input-start",id:N.item.id,toolName:u.toCustomToolName("computer_use"),providerExecuted:!0});else if(N.item.type==="code_interpreter_call")H[N.output_index]={toolName:u.toCustomToolName("code_interpreter"),toolCallId:N.item.id,codeInterpreter:{containerId:N.item.container_id}},q.enqueue({type:"tool-input-start",id:N.item.id,toolName:u.toCustomToolName("code_interpreter"),providerExecuted:!0}),q.enqueue({type:"tool-input-delta",id:N.item.id,delta:`{"containerId":"${N.item.container_id}","code":"`});else if(N.item.type==="file_search_call")q.enqueue({type:"tool-call",toolCallId:N.item.id,toolName:u.toCustomToolName("file_search"),input:"{}",providerExecuted:!0});else if(N.item.type==="image_generation_call")q.enqueue({type:"tool-call",toolCallId:N.item.id,toolName:u.toCustomToolName("image_generation"),input:"{}",providerExecuted:!0});else if(!(N.item.type==="mcp_call"||N.item.type==="mcp_list_tools"||N.item.type==="mcp_approval_request"))if(N.item.type==="apply_patch_call"){const{call_id:ye,operation:wt}=N.item;if(H[N.output_index]={toolName:u.toCustomToolName("apply_patch"),toolCallId:ye,applyPatch:{hasDiff:wt.type==="delete_file",endEmitted:wt.type==="delete_file"}},q.enqueue({type:"tool-input-start",id:ye,toolName:u.toCustomToolName("apply_patch")}),wt.type==="delete_file"){const _t=JSON.stringify({callId:ye,operation:wt});q.enqueue({type:"tool-input-delta",id:ye,delta:_t}),q.enqueue({type:"tool-input-end",id:ye})}else q.enqueue({type:"tool-input-delta",id:ye,delta:`{"callId":"${sr(ye)}","operation":{"type":"${sr(wt.type)}","path":"${sr(wt.path)}","diff":"`})}else N.item.type==="shell_call"?H[N.output_index]={toolName:u.toCustomToolName("shell"),toolCallId:N.item.call_id}:N.item.type==="shell_call_output"||(N.item.type==="message"?(Z.splice(0,Z.length),$=(B=N.item.phase)!=null?B:void 0,q.enqueue({type:"text-start",id:N.item.id,providerMetadata:{[p]:{itemId:N.item.id,...N.item.phase!=null&&{phase:N.item.phase}}}})):Za(N)&&N.item.type==="reasoning"&&(ee[N.item.id]={encryptedContent:N.item.encrypted_content,summaryParts:{0:"active"}},q.enqueue({type:"reasoning-start",id:`${N.item.id}:0`,providerMetadata:{[p]:{itemId:N.item.id,reasoningEncryptedContent:(we=N.item.encrypted_content)!=null?we:null}}})))}else if(Z2(N)){if(N.item.type==="message"){const ye=(re=N.item.phase)!=null?re:$;$=void 0,q.enqueue({type:"text-end",id:N.item.id,providerMetadata:{[p]:{itemId:N.item.id,...ye!=null&&{phase:ye},...Z.length>0&&{annotations:Z}}}})}else if(N.item.type==="function_call")H[N.output_index]=void 0,V=!0,q.enqueue({type:"tool-input-end",id:N.item.call_id}),q.enqueue({type:"tool-call",toolCallId:N.item.call_id,toolName:N.item.name,input:N.item.arguments,providerMetadata:{[p]:{itemId:N.item.id}}});else if(N.item.type==="web_search_call")H[N.output_index]=void 0,q.enqueue({type:"tool-result",toolCallId:N.item.id,toolName:u.toCustomToolName(c??"web_search"),result:ja(N.item.action)});else if(N.item.type==="computer_call")H[N.output_index]=void 0,q.enqueue({type:"tool-input-end",id:N.item.id}),q.enqueue({type:"tool-call",toolCallId:N.item.id,toolName:u.toCustomToolName("computer_use"),input:"",providerExecuted:!0}),q.enqueue({type:"tool-result",toolCallId:N.item.id,toolName:u.toCustomToolName("computer_use"),result:{type:"computer_use_tool_result",status:N.item.status||"completed"}});else if(N.item.type==="file_search_call")H[N.output_index]=void 0,q.enqueue({type:"tool-result",toolCallId:N.item.id,toolName:u.toCustomToolName("file_search"),result:{queries:N.item.queries,results:(le=(ne=N.item.results)==null?void 0:ne.map(ye=>({attributes:ye.attributes,fileId:ye.file_id,filename:ye.filename,score:ye.score,text:ye.text})))!=null?le:null}});else if(N.item.type==="code_interpreter_call")H[N.output_index]=void 0,q.enqueue({type:"tool-result",toolCallId:N.item.id,toolName:u.toCustomToolName("code_interpreter"),result:{outputs:N.item.outputs}});else if(N.item.type==="image_generation_call")q.enqueue({type:"tool-result",toolCallId:N.item.id,toolName:u.toCustomToolName("image_generation"),result:{result:N.item.result}});else if(N.item.type==="mcp_call"){H[N.output_index]=void 0;const ye=(te=N.item.approval_request_id)!=null?te:void 0,wt=ye!=null&&(J=(O=L.get(ye))!=null?O:E[ye])!=null?J:N.item.id,_t=`mcp.${N.item.name}`;q.enqueue({type:"tool-call",toolCallId:wt,toolName:_t,input:N.item.arguments,providerExecuted:!0,dynamic:!0}),q.enqueue({type:"tool-result",toolCallId:wt,toolName:_t,result:{type:"call",serverLabel:N.item.server_label,name:N.item.name,arguments:N.item.arguments,...N.item.output!=null?{output:N.item.output}:{},...N.item.error!=null?{error:N.item.error}:{}},providerMetadata:{[p]:{itemId:N.item.id}}})}else if(N.item.type==="mcp_list_tools")H[N.output_index]=void 0;else if(N.item.type==="apply_patch_call"){const ye=H[N.output_index];ye?.applyPatch&&!ye.applyPatch.endEmitted&&N.item.operation.type!=="delete_file"&&(ye.applyPatch.hasDiff||q.enqueue({type:"tool-input-delta",id:ye.toolCallId,delta:sr(N.item.operation.diff)}),q.enqueue({type:"tool-input-delta",id:ye.toolCallId,delta:'"}}'}),q.enqueue({type:"tool-input-end",id:ye.toolCallId}),ye.applyPatch.endEmitted=!0),ye&&N.item.status==="completed"&&q.enqueue({type:"tool-call",toolCallId:ye.toolCallId,toolName:u.toCustomToolName("apply_patch"),input:JSON.stringify({callId:N.item.call_id,operation:N.item.operation}),providerMetadata:{[p]:{itemId:N.item.id}}}),H[N.output_index]=void 0}else if(N.item.type==="mcp_approval_request"){H[N.output_index]=void 0;const ye=(ge=(oe=(ae=A.config).generateId)==null?void 0:oe.call(ae))!=null?ge:qt(),wt=(he=N.item.approval_request_id)!=null?he:N.item.id;L.set(wt,ye);const _t=`mcp.${N.item.name}`;q.enqueue({type:"tool-call",toolCallId:ye,toolName:_t,input:N.item.arguments,providerExecuted:!0,dynamic:!0}),q.enqueue({type:"tool-approval-request",approvalId:wt,toolCallId:ye})}else if(N.item.type==="local_shell_call")H[N.output_index]=void 0,q.enqueue({type:"tool-call",toolCallId:N.item.call_id,toolName:u.toCustomToolName("local_shell"),input:JSON.stringify({action:{type:"exec",command:N.item.action.command,timeoutMs:N.item.action.timeout_ms,user:N.item.action.user,workingDirectory:N.item.action.working_directory,env:N.item.action.env}}),providerMetadata:{[p]:{itemId:N.item.id}}});else if(N.item.type==="shell_call")H[N.output_index]=void 0,q.enqueue({type:"tool-call",toolCallId:N.item.call_id,toolName:u.toCustomToolName("shell"),input:JSON.stringify({action:{commands:N.item.action.commands}}),...x&&{providerExecuted:!0},providerMetadata:{[p]:{itemId:N.item.id}}});else if(N.item.type==="shell_call_output")q.enqueue({type:"tool-result",toolCallId:N.item.call_id,toolName:u.toCustomToolName("shell"),result:{output:N.item.output.map(ye=>({stdout:ye.stdout,stderr:ye.stderr,outcome:ye.outcome.type==="exit"?{type:"exit",exitCode:ye.outcome.exit_code}:{type:"timeout"}}))}});else if(N.item.type==="reasoning"){const ye=ee[N.item.id],wt=Object.entries(ye.summaryParts).filter(([_t,Un])=>Un==="active"||Un==="can-conclude").map(([_t])=>_t);for(const _t of wt)q.enqueue({type:"reasoning-end",id:`${N.item.id}:${_t}`,providerMetadata:{[p]:{itemId:N.item.id,reasoningEncryptedContent:(ue=N.item.encrypted_content)!=null?ue:null}}});delete ee[N.item.id]}}else if(W2(N)){const ye=H[N.output_index];ye!=null&&q.enqueue({type:"tool-input-delta",id:ye.toolCallId,delta:N.delta})}else if(Y2(N)){const ye=H[N.output_index];ye?.applyPatch&&(q.enqueue({type:"tool-input-delta",id:ye.toolCallId,delta:sr(N.delta)}),ye.applyPatch.hasDiff=!0)}else if(J2(N)){const ye=H[N.output_index];ye?.applyPatch&&!ye.applyPatch.endEmitted&&(ye.applyPatch.hasDiff||(q.enqueue({type:"tool-input-delta",id:ye.toolCallId,delta:sr(N.diff)}),ye.applyPatch.hasDiff=!0),q.enqueue({type:"tool-input-delta",id:ye.toolCallId,delta:'"}}'}),q.enqueue({type:"tool-input-end",id:ye.toolCallId}),ye.applyPatch.endEmitted=!0)}else if(G2(N))q.enqueue({type:"tool-result",toolCallId:N.item_id,toolName:u.toCustomToolName("image_generation"),result:{result:N.partial_image_b64},preliminary:!0});else if(X2(N)){const ye=H[N.output_index];ye!=null&&q.enqueue({type:"tool-input-delta",id:ye.toolCallId,delta:sr(N.delta)})}else if(q2(N)){const ye=H[N.output_index];ye!=null&&(q.enqueue({type:"tool-input-delta",id:ye.toolCallId,delta:'"}'}),q.enqueue({type:"tool-input-end",id:ye.toolCallId}),q.enqueue({type:"tool-call",toolCallId:ye.toolCallId,toolName:u.toCustomToolName("code_interpreter"),input:JSON.stringify({code:N.code,containerId:ye.codeInterpreter.containerId}),providerExecuted:!0}))}else if(H2(N))P=N.response.id,q.enqueue({type:"response-metadata",id:N.response.id,timestamp:new Date(N.response.created_at*1e3),modelId:N.response.model});else if($2(N))q.enqueue({type:"text-delta",id:N.item_id,delta:N.delta}),(je=(Ce=t.providerOptions)==null?void 0:Ce[p])!=null&&je.logprobs&&N.logprobs&&R.push(N.logprobs);else if(N.type==="response.reasoning_summary_part.added"){if(N.summary_index>0){const ye=ee[N.item_id];ye.summaryParts[N.summary_index]="active";for(const wt of Object.keys(ye.summaryParts))ye.summaryParts[wt]==="can-conclude"&&(q.enqueue({type:"reasoning-end",id:`${N.item_id}:${wt}`,providerMetadata:{[p]:{itemId:N.item_id}}}),ye.summaryParts[wt]="concluded");q.enqueue({type:"reasoning-start",id:`${N.item_id}:${N.summary_index}`,providerMetadata:{[p]:{itemId:N.item_id,reasoningEncryptedContent:(ut=(Be=ee[N.item_id])==null?void 0:Be.encryptedContent)!=null?ut:null}}})}}else N.type==="response.reasoning_summary_text.delta"?q.enqueue({type:"reasoning-delta",id:`${N.item_id}:${N.summary_index}`,delta:N.delta,providerMetadata:{[p]:{itemId:N.item_id}}}):N.type==="response.reasoning_summary_part.done"?f?(q.enqueue({type:"reasoning-end",id:`${N.item_id}:${N.summary_index}`,providerMetadata:{[p]:{itemId:N.item_id}}}),ee[N.item_id].summaryParts[N.summary_index]="concluded"):ee[N.item_id].summaryParts[N.summary_index]="can-conclude":j2(N)?(M={unified:za({finishReason:(ie=N.response.incomplete_details)==null?void 0:ie.reason,hasFunctionCall:V}),raw:(Me=(Ae=N.response.incomplete_details)==null?void 0:Ae.reason)!=null?Me:void 0},D=N.response.usage,typeof N.response.service_tier=="string"&&(j=N.response.service_tier)):K2(N)?(Z.push(N.annotation),N.annotation.type==="url_citation"?q.enqueue({type:"source",sourceType:"url",id:(tt=(et=(ke=A.config).generateId)==null?void 0:et.call(ke))!=null?tt:qt(),url:N.annotation.url,title:N.annotation.title}):N.annotation.type==="file_citation"?q.enqueue({type:"source",sourceType:"document",id:(gn=(Le=(Wt=A.config).generateId)==null?void 0:Le.call(Wt))!=null?gn:qt(),mediaType:"text/plain",title:N.annotation.filename,filename:N.annotation.filename,providerMetadata:{[p]:{type:N.annotation.type,fileId:N.annotation.file_id,index:N.annotation.index}}}):N.annotation.type==="container_file_citation"?q.enqueue({type:"source",sourceType:"document",id:(Et=(En=(Zt=A.config).generateId)==null?void 0:En.call(Zt))!=null?Et:qt(),mediaType:"text/plain",title:N.annotation.filename,filename:N.annotation.filename,providerMetadata:{[p]:{type:N.annotation.type,fileId:N.annotation.file_id,containerId:N.annotation.container_id}}}):N.annotation.type==="file_path"&&q.enqueue({type:"source",sourceType:"document",id:(dn=(Ze=(Xe=A.config).generateId)==null?void 0:Ze.call(Xe))!=null?dn:qt(),mediaType:"application/octet-stream",title:N.annotation.file_id,filename:N.annotation.file_id,providerMetadata:{[p]:{type:N.annotation.type,fileId:N.annotation.file_id,index:N.annotation.index}}})):Q2(N)&&q.enqueue({type:"error",error:N})},flush(z){const q={[p]:{responseId:P,...R.length>0?{logprobs:R}:{},...j!==void 0?{serviceTier:j}:{}}};z.enqueue({type:"finish",finishReason:M,usage:Fa(D),providerMetadata:q})}})),request:{body:r},response:{headers:_}}}};function $2(t){return t.type==="response.output_text.delta"}function Z2(t){return t.type==="response.output_item.done"}function j2(t){return t.type==="response.completed"||t.type==="response.incomplete"}function H2(t){return t.type==="response.created"}function W2(t){return t.type==="response.function_call_arguments.delta"}function G2(t){return t.type==="response.image_generation_call.partial_image"}function X2(t){return t.type==="response.code_interpreter_call_code.delta"}function q2(t){return t.type==="response.code_interpreter_call_code.done"}function Y2(t){return t.type==="response.apply_patch_call_operation_diff.delta"}function J2(t){return t.type==="response.apply_patch_call_operation_diff.done"}function Za(t){return t.type==="response.output_item.added"}function K2(t){return t.type==="response.output_text.annotation.added"}function Q2(t){return t.type==="error"}function ja(t){var r;if(t==null)return{};switch(t.type){case"search":return{action:{type:"search",query:(r=t.query)!=null?r:void 0},...t.sources!=null&&{sources:t.sources}};case"open_page":return{action:{type:"openPage",url:t.url}};case"find_in_page":return{action:{type:"findInPage",url:t.url,pattern:t.pattern}}}}function sr(t){return JSON.stringify(t).slice(1,-1)}var ex=$e(()=>ze(S({instructions:w().nullish(),speed:Y().min(.25).max(4).default(1).nullish()}))),tx=class{constructor(t,r){this.modelId=t,this.config=r,this.specificationVersion="v3"}get provider(){return this.config.provider}async getArgs({text:t,voice:r="alloy",outputFormat:o="mp3",speed:c,instructions:u,language:f,providerOptions:p}){const x=[],_=await Bn({provider:"openai",providerOptions:p,schema:ex}),g={model:this.modelId,input:t,voice:r,response_format:"mp3",speed:c,instructions:u};if(o&&(["mp3","opus","aac","flac","wav","pcm"].includes(o)?g.response_format=o:x.push({type:"unsupported",feature:"outputFormat",details:`Unsupported output format: ${o}. Using mp3 instead.`})),_){const A={};for(const E in A){const L=A[E];L!==void 0&&(g[E]=L)}}return f&&x.push({type:"unsupported",feature:"language",details:`OpenAI speech models do not support language selection. Language parameter "${f}" was ignored.`}),{requestBody:g,warnings:x}}async doGenerate(t){var r,o,c;const u=(c=(o=(r=this.config._internal)==null?void 0:r.currentDate)==null?void 0:o.call(r))!=null?c:new Date,{requestBody:f,warnings:p}=await this.getArgs(t),{value:x,responseHeaders:_,rawValue:g}=await Ln({url:this.config.url({path:"/audio/speech",modelId:this.modelId}),headers:Cn(this.config.headers(),t.headers),body:f,failedResponseHandler:bn,successfulResponseHandler:fm(),abortSignal:t.abortSignal,fetch:this.config.fetch});return{audio:x,warnings:p,request:{body:JSON.stringify(f)},response:{timestamp:u,modelId:this.modelId,headers:_,body:g}}}},nx=$e(()=>ze(S({text:w(),language:w().nullish(),duration:Y().nullish(),words:me(S({word:w(),start:Y(),end:Y()})).nullish(),segments:me(S({id:Y(),seek:Y(),start:Y(),end:Y(),text:w(),tokens:me(Y()),temperature:Y(),avg_logprob:Y(),compression_ratio:Y(),no_speech_prob:Y()})).nullish()}))),rx=$e(()=>ze(S({include:me(w()).optional(),language:w().optional(),prompt:w().optional(),temperature:Y().min(0).max(1).default(0).optional(),timestampGranularities:me(Fe(["word","segment"])).default(["segment"]).optional()}))),Ha={afrikaans:"af",arabic:"ar",armenian:"hy",azerbaijani:"az",belarusian:"be",bosnian:"bs",bulgarian:"bg",catalan:"ca",chinese:"zh",croatian:"hr",czech:"cs",danish:"da",dutch:"nl",english:"en",estonian:"et",finnish:"fi",french:"fr",galician:"gl",german:"de",greek:"el",hebrew:"he",hindi:"hi",hungarian:"hu",icelandic:"is",indonesian:"id",italian:"it",japanese:"ja",kannada:"kn",kazakh:"kk",korean:"ko",latvian:"lv",lithuanian:"lt",macedonian:"mk",malay:"ms",marathi:"mr",maori:"mi",nepali:"ne",norwegian:"no",persian:"fa",polish:"pl",portuguese:"pt",romanian:"ro",russian:"ru",serbian:"sr",slovak:"sk",slovenian:"sl",spanish:"es",swahili:"sw",swedish:"sv",tagalog:"tl",tamil:"ta",thai:"th",turkish:"tr",ukrainian:"uk",urdu:"ur",vietnamese:"vi",welsh:"cy"},ix=class{constructor(t,r){this.modelId=t,this.config=r,this.specificationVersion="v3"}get provider(){return this.config.provider}async getArgs({audio:t,mediaType:r,providerOptions:o}){const c=[],u=await Bn({provider:"openai",providerOptions:o,schema:rx}),f=new FormData,p=t instanceof Uint8Array?new Blob([t]):new Blob([Xo(t)]);f.append("model",this.modelId);const x=hp(r);if(f.append("file",new File([p],"audio",{type:r}),`audio.${x}`),u){const _={include:u.include,language:u.language,prompt:u.prompt,response_format:["gpt-4o-transcribe","gpt-4o-mini-transcribe"].includes(this.modelId)?"json":"verbose_json",temperature:u.temperature,timestamp_granularities:u.timestampGranularities};for(const[g,A]of Object.entries(_))if(A!=null)if(Array.isArray(A))for(const E of A)f.append(`${g}[]`,String(E));else f.append(g,String(A))}return{formData:f,warnings:c}}async doGenerate(t){var r,o,c,u,f,p,x,_;const g=(c=(o=(r=this.config._internal)==null?void 0:r.currentDate)==null?void 0:o.call(r))!=null?c:new Date,{formData:A,warnings:E}=await this.getArgs(t),{value:L,responseHeaders:M,rawValue:D}=await Ac({url:this.config.url({path:"/audio/transcriptions",modelId:this.modelId}),headers:Cn(this.config.headers(),t.headers),formData:A,failedResponseHandler:bn,successfulResponseHandler:dr(nx),abortSignal:t.abortSignal,fetch:this.config.fetch}),R=L.language!=null&&L.language in Ha?Ha[L.language]:void 0;return{text:L.text,segments:(x=(p=(u=L.segments)==null?void 0:u.map(P=>({text:P.text,startSecond:P.start,endSecond:P.end})))!=null?p:(f=L.words)==null?void 0:f.map(P=>({text:P.word,startSecond:P.start,endSecond:P.end})))!=null?x:[],language:R,durationInSeconds:(_=L.duration)!=null?_:void 0,warnings:E,response:{timestamp:g,modelId:this.modelId,headers:M,body:D}}}},ox="3.0.36";function Nu(t={}){var r,o;const c=(r=hm(fp({settingValue:t.baseURL,environmentVariableName:"OPENAI_BASE_URL"})))!=null?r:"https://api.openai.com/v1",u=(o=t.name)!=null?o:"openai",f=()=>_c({Authorization:`Bearer ${dp({apiKey:t.apiKey,environmentVariableName:"OPENAI_API_KEY",description:"OpenAI"})}`,"OpenAI-Organization":t.organization,"OpenAI-Project":t.project,...t.headers},`ai-sdk/openai/${ox}`),p=R=>new Vg(R,{provider:`${u}.chat`,url:({path:P})=>`${c}${P}`,headers:f,fetch:t.fetch}),x=R=>new Hg(R,{provider:`${u}.completion`,url:({path:P})=>`${c}${P}`,headers:f,fetch:t.fetch}),_=R=>new Xg(R,{provider:`${u}.embedding`,url:({path:P})=>`${c}${P}`,headers:f,fetch:t.fetch}),g=R=>new Kg(R,{provider:`${u}.image`,url:({path:P})=>`${c}${P}`,headers:f,fetch:t.fetch}),A=R=>new ix(R,{provider:`${u}.transcription`,url:({path:P})=>`${c}${P}`,headers:f,fetch:t.fetch}),E=R=>new tx(R,{provider:`${u}.speech`,url:({path:P})=>`${c}${P}`,headers:f,fetch:t.fetch}),L=R=>{if(new.target)throw new Error("The OpenAI model function cannot be called with the new keyword.");return M(R)},M=R=>new V2(R,{provider:`${u}.responses`,url:({path:P})=>`${c}${P}`,headers:f,fetch:t.fetch,fileIdPrefixes:["file-"]}),D=function(R){return L(R)};return D.specificationVersion="v3",D.languageModel=L,D.chat=p,D.completion=x,D.responses=M,D.embedding=_,D.embeddingModel=_,D.textEmbedding=_,D.textEmbeddingModel=_,D.image=g,D.imageModel=g,D.transcription=A,D.transcriptionModel=A,D.speech=E,D.speechModel=E,D.tools=M2,D}Nu();const sx={deepseek:{prompt:{strategy:"append",id:"5ed1b9071c15d1ed59b5827ea5dcabd4",params:{customComponents:[{name:"选择用户组件",description:"选择用户组件,用于选择用户,支持模糊搜索",component:"TinyUser",schema:{properties:[{property:"modelValue",label:"用户绑定工号",required:!0,description:"用户的工号,双向绑定值",type:"string"},{property:"valueField",label:"值字段",required:!0,description:"用户工号值的绑定字段",type:"string"}]}}],customExamples:[{name:"选择用户示例",schema:{componentName:"Page",state:{reviewer:""},children:[{componentName:"h3",props:{},children:"输入用户名搜索工号并选择用户"},{componentName:"TinyUser",props:{modelValue:{type:"JSExpression",model:!0,value:"this.state.reviewer"},valueField:"uid"}},{componentName:"TinyButton",props:{text:"提交"}}]}}],customActions:[{name:"continueChat",description:"继续对话, 用于表单的提交按钮等",parameters:{type:"object",properties:{message:{type:"string",description:"对话消息,可以是按钮文本等,也可以是其他内容"}}}}]}}}};class ax{constructor(r={}){this.option=r}async traverse(r){const o=v.ref();return this.option.debug&&console.log("【stream-debug】 响应对象体:",o),(async()=>{let u,f,p,x,_;for await(const g of r.fullStream)switch(this.option.debug&&console.log("【stream-debug】 "+(new Date().getTime()/1e3).toString().slice(-6)+g.type,g),g.type){case"start":u=v.reactive({running:!0,steps:[]}),o.value=u,this.option.onStart?.(u);break;case"start-step":f=v.reactive({running:!0,contents:[],request:g.request}),u.steps.push(f),this.option.onStep?.(f);break;case"reasoning-start":p=v.reactive({type:"reasoning",id:g.id,running:!0,text:""}),f.contents.push(p),this.option.onReasoning?.(p);break;case"reasoning-delta":p.text+=g.text;break;case"reasoning-end":p.running=!1;break;case"text-start":x=v.reactive({type:"text",id:g.id,running:!0,text:""}),f.contents.push(x),this.option.onText?.(x);break;case"text-delta":x.text+=g.text;break;case"text-end":x.running=!1;break;case"tool-input-start":_=v.reactive({type:"tool",running:!0,id:g.id,toolCallId:g.id,title:"",toolName:g.toolName,dynamic:g.dynamic,inputStr:"",input:{},output:{}}),f.contents.push(_),this.option.onTool?.(_);break;case"tool-input-delta":_.inputStr+=g.delta;break;case"tool-input-end":break;case"tool-call":_.input=g.input;break;case"tool-result":_.output=g.output,_.running=!1;break;case"tool-error":_.error=g.error,_.running=!1;break;case"finish-step":f.running=!1,f.finishReason=g.finishReason,f.usage=g.usage;break;case"finish":u.running=!1,u.finishReason=g.finishReason,u.totalUsage=g.totalUsage,this.option.onFinish?.();break;case"source":case"file":break;case"error":u&&(u.running=!1,u.error=g.error,u.finishReason="error"),this.option.onFinish?.();break;case"abort":u&&(u.running=!1,u.error={message:g.reason},u.finishReason="other"),this.option.onFinish?.();break}})(),o}}function lx(t){const r=[];let o=0;for(;o<t.length;){const c="```schemaJson",u=t.indexOf(c,o),f=c.length;if(u===-1){const g=t.slice(o).trim();g&&r.push({type:"markdown",content:g});break}const p=t.slice(o,u).trim();p&&r.push({type:"markdown",content:p});const x=t.indexOf("```",u+f);let _;x===-1?(_=t.slice(u+f).trim(),o=t.length):(_=t.slice(u+f,x).trim(),o=x+3),r.push({type:"schema-card",content:_})}return r}const wo={model:"deepseek-ai/DeepSeek-V3",maxSteps:15,extraTools:{}},Wa={apiKey:"sk-trial",baseURL:"https://agent.opentiny.design/api/v1/ai/prompt",providerType:"deepseek"};function cx(t,r){if(!r&&!t)return;if(!t)return r;if(!r)return t;const o={...r};for(const[c,u]of Object.entries(t))u&&typeof u=="object"&&!Array.isArray(u)?o[c]={...o[c]||{},...u}:o[c]=u;return o}class ux extends Wn.BaseModelProvider{transport;agent;systemPrompt;llmConfig={...wo,...Wa};isGenuiEnabled;constructor(r,o,c){super(r);let u;c&&"llm"in c?u={...wo,...c}:u={...wo,...Wa,...c||{}},this.llmConfig=u;const p={llmConfig:u.llm?{llm:u.llm}:{...u}};this.agent=new cr.AgentModelProvider(p),this.systemPrompt=o}updateLLMConfig({modelId:r,baseURL:o,apiKey:c,providerType:u,useReActMode:f,llm:p,providerOptions:x,headers:_}){if(p)this.agent.llm=p,this.llmConfig.model=r,this.llmConfig.useReActMode=f||!1,this.agent.useReActMode=f||!1;else if(u&&o&&c){this.isGenuiEnabled?.value?o.includes("/prompt")||(o=o+"/prompt"):o=o.replace("/prompt",""),this.llmConfig.model=r,this.llmConfig.apiKey=c,this.llmConfig.baseURL=o,this.llmConfig.providerType=u,this.llmConfig.useReActMode=f||!1,this.agent.useReActMode=f||!1;let g;if(u==="deepseek")g=wu;else if(u==="openai")g=Nu;else if(typeof u=="function")g=u;else throw new Error(`Unsupported providerType: ${u}`);this.agent.llm=g({apiKey:c,baseURL:o,..._?{headers:_}:{}})}this.llmConfig.providerOptions=x,this.llmConfig.headers=_}cleanupOldSnapshotsInMessages(r){if(!r||r.length===0)return r;const c=this.agent.useReActMode===!0?"user":"tool",u=r[r.length-1];if(!u||u.role!==c||!this.isSnapshotContent(u.content))return r;const f=[...r];for(let p=f.length-2;p>=0;p--){const x=f[p];x.role===c&&this.isSnapshotContent(x.content)&&this.replaceSnapshotWithPlaceholder(x)}return f}removeSnapshotData(r){if(!r)return r;const o=["无障碍树快照:","无障碍树快照:","快照内容:","快照内容:","页面无障碍树快照:","页面无障碍树快照:","操作后的页面快照:","操作后的页面快照:"];let c=-1;for(const f of o){const p=r.indexOf(f);if(p!==-1){c=p;break}}if(c!==-1){const f=r.substring(0,c).trim();return f?`${f} 📸 [历史快照已清理]`:"📸 历史快照已清理"}const u=["已成功获取页面无障碍树快照","takeSnapshot","snapshotId_counter"];for(const f of u)if(r.startsWith(f))return"📸 历史快照已清理";return r}replaceSnapshotWithPlaceholder(r){if(Array.isArray(r.content)){const o=r.content[0];if(o?.output?.value?.content){const c=o.output.value.content;Array.isArray(c)&&(o.output.value.content=c.map(u=>u.type==="image"||u.type==="image_url"?null:u.type==="text"&&u.text&&this.isSnapshotContent(u.text)?{type:"text",text:this.removeSnapshotData(u.text)}:u).filter(u=>u!==null)),o.output.value.screenshot&&delete o.output.value.screenshot}else r.content=r.content.filter(c=>c.type!=="image"&&c.type!=="image_url")}else typeof r.content=="string"&&this.isSnapshotContent(r.content)&&(r.content=this.removeSnapshotData(r.content))}isSnapshotContent(r){if(!r)return!1;const o=["无障碍树快照","takeSnapshot","snapshotId_counter","UID 格式","快照 ID","操作后的页面快照","已成功获取页面无障碍树快照","快照内容:"];if(typeof r=="string")return o.some(c=>r.includes(c));if(Array.isArray(r))for(const c of r){const u=c?.output?.value?.content?.[0]?.text;if(u&&o.some(f=>u.includes(f))||c.type==="text"&&c.text&&o.some(f=>c.text.includes(f))||c.type==="image"||c.type==="image_url")return!0}return!1}async chatStream(r,o){let c=r.messages[r.messages.length-1];if(!c)return;if(this.llmConfig.beforeChatStream)try{const M=await this.llmConfig.beforeChatStream(c,this.systemPrompt);M&&(c=M)}catch(M){console.error("[beforeChatStream] 钩子执行失败:",M)}const u={model:this.llmConfig.model,system:this.systemPrompt,abortSignal:r.options?.signal,toolChoice:"auto",tools:{"get-today":Fm,...this.llmConfig.extraTools||{}},maxSteps:this.llmConfig.maxSteps,providerOptions:cx(this.llmConfig.providerOptions,sx),prepareStep:({messages:M})=>({messages:this.cleanupOldSnapshotsInMessages(M)}),onFinish:async()=>{await this.agent.closeAll()}},f={role:"user",content:c.content},x=[...(M=>M.map(D=>({role:D.role,content:D.content})))(this.agent.responseMessages),f];u.messages=x;const _=await this.agent.chatStream(u),g=new Yh,E=await new ax({debug:!1,onFinish:()=>{v.nextTick(()=>{g.resolve(),o.onDone()})}}).traverse(_),L={role:"assistant",content:"",uiContent:[]};return v.watch(E,M=>{if(!M)o.onData(L);else{const R=M.steps.map(P=>P.contents).flat().map(P=>{if(P.type==="text")return lx(P.text);if(P.type==="reasoning")return{type:"collapsible-text",title:"思考过程",content:P.text,thinkId:P.id};if(P.type==="tool")return{type:"tool",id:P.id,name:P.toolName,content:JSON.stringify({input:P.inputStr,output:P.output}),status:P.error?"failed":P.running?"running":"success"}});if(M?.error){const P={type:"markdown",content:`**错误**:${M.error.message||"未知错误"}`};R.push(P)}M.steps.length>=1&&o.onData({...L,uiContent:R.flat(),usage:M.totalUsage||null})}},{deep:!0}),g.promise}chat(r){throw new Error("Method not implemented.")}}const dx=({systemPrompt:t,llmConfig:r})=>{const o=new ux({provider:"custom"},t,r),c=new Wn.AIClient({providerImplementation:o,provider:"custom"}),{messageManager:u,createConversation:f,getCurrentConversation:p,switchConversation:x,deleteConversation:_,updateTitle:g,state:A}=Wn.useConversation({client:c,autoSave:!1,events:{onLoaded(){},onReceiveData(V,ee,j){j(),ee.value[ee.value.length-1].role==="assistant"&&ee.value.pop(),ee.value.push(V)}}}),{messageState:E,inputMessage:L,sendMessage:M,abortRequest:D,messages:R,addMessage:P,send:H}=u,Z=v.ref(),$=async(V,ee,j)=>{if(j){const{shouldBlock:q}=await j(V);if(q)return!1}L.value=V;const z=p();if(z&&z.title==="新会话"&&g(z.id,L.value.slice(0,15)),ee&&ee.length>0){const q=[{type:"text",text:L.value},...ee],B=[];L.value&&B.push({type:"text",content:L.value});for(const re of ee)re.type==="image"&&re.image&&B.push({type:"image",content:re.image});const we={role:"user",content:q,uiContent:B};R.value.push(we),L.value="",H()}else{const q={role:"user",content:L.value,uiContent:[{type:"text",content:L.value}]};R.value.push(q),L.value="",H()}return!0};return v.onMounted(()=>{Z.value?.focus()}),v.onUnmounted(()=>{o.agent.closeAll()}),{agent:o.agent,customAgentProvider:o,client:c,messageManager:u,addMessage:P,send:H,conversationState:A,messages:R,messageState:E,inputMessage:L,sendMessage:M,abortRequest:D,senderRef:Z,handleSendMessage:$,createConversation:f,switchConversation:x,deleteConversation:_,getCurrentConversation:p}};function fx(){}const Rn=Object.assign,ts=typeof window<"u",ji=t=>t!==null&&typeof t=="object",Jn=t=>t!=null,Po=t=>typeof t=="function",hx=t=>ji(t)&&Po(t.then)&&Po(t.catch),Ou=t=>typeof t=="number"||/^\d+(\.\d+)?$/.test(t),px=()=>ts?/ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()):!1;function Ga(t,r){const o=r.split(".");let c=t;return o.forEach(u=>{var f;c=ji(c)&&(f=c[u])!=null?f:""}),c}function mx(t,r,o){return r.reduce((c,u)=>(c[u]=t[u],c),{})}const Bi=null,ln=[Number,String],lr={type:Boolean,default:!0},gx=t=>({type:Number,default:t}),cn=t=>({type:String,default:t});var ns=typeof window<"u";function ku(t){let r;v.onMounted(()=>{t(),v.nextTick(()=>{r=!0})}),v.onActivated(()=>{r&&t()})}function Ru(t,r,o={}){if(!ns)return;const{target:c=window,passive:u=!1,capture:f=!1}=o;let p=!1,x;const _=E=>{if(p)return;const L=v.unref(E);L&&!x&&(L.addEventListener(t,r,{capture:f,passive:u}),x=!0)},g=E=>{if(p)return;const L=v.unref(E);L&&x&&(L.removeEventListener(t,r,f),x=!1)};v.onUnmounted(()=>g(c)),v.onDeactivated(()=>g(c)),ku(()=>_(c));let A;return v.isRef(c)&&(A=v.watch(c,(E,L)=>{g(L),_(E)})),()=>{A?.(),g(c),p=!0}}var Ai,_o;function xx(){if(!Ai&&(Ai=v.ref(0),_o=v.ref(0),ns)){const t=()=>{Ai.value=window.innerWidth,_o.value=window.innerHeight};t(),window.addEventListener("resize",t,{passive:!0}),window.addEventListener("orientationchange",t,{passive:!0})}return{width:Ai,height:_o}}var yx=/scroll|auto|overlay/i,wx=ns?window:void 0;function _x(t){return t.tagName!=="HTML"&&t.tagName!=="BODY"&&t.nodeType===1}function vx(t,r=wx){let o=t;for(;o&&o!==r&&_x(o);){const{overflowY:c}=window.getComputedStyle(o);if(yx.test(c))return o;o=o.parentNode}return r}px();const Cx=t=>t.stopPropagation();function Mu(t,r){(typeof t.cancelable!="boolean"||t.cancelable)&&t.preventDefault(),Cx(t)}xx();function vn(t){if(Jn(t))return Ou(t)?`${t}px`:String(t)}function bx(t){if(Jn(t)){if(Array.isArray(t))return{width:vn(t[0]),height:vn(t[1])};const r=vn(t);return{width:r,height:r}}}function Ex(t){const r={};return t!==void 0&&(r.zIndex=+t),r}const Ax=/-(\w)/g,Du=t=>t.replace(Ax,(r,o)=>o.toUpperCase()),Ix=t=>t.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,""),{hasOwnProperty:Sx}=Object.prototype;function Tx(t,r,o){const c=r[o];Jn(c)&&(!Sx.call(t,o)||!ji(c)?t[o]=c:t[o]=Pu(Object(t[o]),c))}function Pu(t,r){return Object.keys(r).forEach(o=>{Tx(t,r,o)}),t}var Nx={name:"姓名",tel:"电话",save:"保存",clear:"清空",cancel:"取消",confirm:"确认",delete:"删除",loading:"加载中...",noCoupon:"暂无优惠券",nameEmpty:"请填写姓名",addContact:"添加联系人",telInvalid:"请填写正确的电话",vanCalendar:{end:"结束",start:"开始",title:"日期选择",weekdays:["日","一","二","三","四","五","六"],monthTitle:(t,r)=>`${t}年${r}月`,rangePrompt:t=>`最多选择 ${t} 天`},vanCascader:{select:"请选择"},vanPagination:{prev:"上一页",next:"下一页"},vanPullRefresh:{pulling:"下拉即可刷新...",loosing:"释放即可刷新..."},vanSubmitBar:{label:"合计:"},vanCoupon:{unlimited:"无门槛",discount:t=>`${t}折`,condition:t=>`满${t}元可用`},vanCouponCell:{title:"优惠券",count:t=>`${t}张可用`},vanCouponList:{exchange:"兑换",close:"不使用",enable:"可用",disabled:"不可用",placeholder:"输入优惠码"},vanAddressEdit:{area:"地区",areaEmpty:"请选择地区",addressEmpty:"请填写详细地址",addressDetail:"详细地址",defaultAddress:"设为默认收货地址"},vanAddressList:{add:"新增地址"}};const Xa=v.ref("zh-CN"),qa=v.reactive({"zh-CN":Nx}),Ox={messages(){return qa[Xa.value]},use(t,r){Xa.value=t,this.add({[t]:r})},add(t={}){Pu(qa,t)}};var kx=Ox;function Rx(t){const r=Du(t)+".";return(o,...c)=>{const u=kx.messages(),f=Ga(u,r+o)||Ga(u,o);return Po(f)?f(...c):f}}function Bo(t,r){return r?typeof r=="string"?` ${t}--${r}`:Array.isArray(r)?r.reduce((o,c)=>o+Bo(t,c),""):Object.keys(r).reduce((o,c)=>o+(r[c]?Bo(t,c):""),""):""}function Mx(t){return(r,o)=>(r&&typeof r!="string"&&(o=r,r=""),r=r?`${t}__${r}`:t,`${r}${Bo(r,o)}`)}function pr(t){const r=`van-${t}`;return[r,Mx(r),Rx(r)]}const Dx="van-haptics-feedback",Ya=5;function Px(t,{args:r=[],done:o,canceled:c,error:u}){if(t){const f=t.apply(null,r);hx(f)?f.then(p=>{p?o():c&&c()}).catch(u||fx):f?o():c&&c()}else o()}function si(t){return t.install=r=>{const{name:o}=t;o&&(r.component(o,t),r.component(Du(`-${o}`),t))},t}const Bx=Symbol();function Bu(t){const r=v.getCurrentInstance();r&&Rn(r.proxy,t)}const[Lx,Ja]=pr("badge"),Fx={dot:Boolean,max:ln,tag:cn("div"),color:String,offset:Array,content:ln,showZero:lr,position:cn("top-right")};var Ux=v.defineComponent({name:Lx,props:Fx,setup(t,{slots:r}){const o=()=>{if(r.content)return!0;const{content:x,showZero:_}=t;return Jn(x)&&x!==""&&(_||x!==0&&x!=="0")},c=()=>{const{dot:x,max:_,content:g}=t;if(!x&&o())return r.content?r.content():Jn(_)&&Ou(g)&&+g>+_?`${_}+`:g},u=x=>x.startsWith("-")?x.replace("-",""):`-${x}`,f=v.computed(()=>{const x={background:t.color};if(t.offset){const[_,g]=t.offset,{position:A}=t,[E,L]=A.split("-");r.default?(typeof g=="number"?x[E]=vn(E==="top"?g:-g):x[E]=E==="top"?vn(g):u(g),typeof _=="number"?x[L]=vn(L==="left"?_:-_):x[L]=L==="left"?vn(_):u(_)):(x.marginTop=vn(g),x.marginLeft=vn(_))}return x}),p=()=>{if(o()||t.dot)return v.createVNode("div",{class:Ja([t.position,{dot:t.dot,fixed:!!r.default}]),style:f.value},[c()])};return()=>{if(r.default){const{tag:x}=t;return v.createVNode(x,{class:Ja("wrapper")},{default:()=>[r.default(),p()]})}return p()}}});const zx=si(Ux);let Lu=2e3;const Vx=()=>++Lu,$x=t=>{Lu=t},[Fu,Zx]=pr("config-provider"),Uu=Symbol(Fu),jx={tag:cn("div"),theme:cn("light"),zIndex:Number,themeVars:Object,themeVarsDark:Object,themeVarsLight:Object,themeVarsScope:cn("local"),iconPrefix:String};function Hx(t){return t.replace(/([a-zA-Z])(\d)/g,"$1-$2")}function Wx(t){const r={};return Object.keys(t).forEach(o=>{const c=Hx(Ix(o));r[`--van-${c}`]=t[o]}),r}function Ii(t={},r={}){Object.keys(t).forEach(o=>{t[o]!==r[o]&&document.documentElement.style.setProperty(o,t[o])}),Object.keys(r).forEach(o=>{t[o]||document.documentElement.style.removeProperty(o)})}v.defineComponent({name:Fu,props:jx,setup(t,{slots:r}){const o=v.computed(()=>Wx(Rn({},t.themeVars,t.theme==="dark"?t.themeVarsDark:t.themeVarsLight)));if(ts){const c=()=>{document.documentElement.classList.add(`van-theme-${t.theme}`)},u=(f=t.theme)=>{document.documentElement.classList.remove(`van-theme-${f}`)};v.watch(()=>t.theme,(f,p)=>{p&&u(p),c()},{immediate:!0}),v.onActivated(c),v.onDeactivated(u),v.onBeforeUnmount(u),v.watch(o,(f,p)=>{t.themeVarsScope==="global"&&Ii(f,p)}),v.watch(()=>t.themeVarsScope,(f,p)=>{p==="global"&&Ii({},o.value),f==="global"&&Ii(o.value,{})}),t.themeVarsScope==="global"&&Ii(o.value,{})}return v.provide(Uu,t),v.watchEffect(()=>{t.zIndex!==void 0&&$x(t.zIndex)}),()=>v.createVNode(t.tag,{class:Zx(),style:t.themeVarsScope==="local"?o.value:void 0},{default:()=>{var c;return[(c=r.default)==null?void 0:c.call(r)]}})}});const[Gx,Ka]=pr("icon"),Xx=t=>t?.includes("/"),qx={dot:Boolean,tag:cn("i"),name:String,size:ln,badge:ln,color:String,badgeProps:Object,classPrefix:String};var Yx=v.defineComponent({name:Gx,props:qx,setup(t,{slots:r}){const o=v.inject(Uu,null),c=v.computed(()=>t.classPrefix||o?.iconPrefix||Ka());return()=>{const{tag:u,dot:f,name:p,size:x,badge:_,color:g}=t,A=Xx(p);return v.createVNode(zx,v.mergeProps({dot:f,tag:u,class:[c.value,A?"":`${c.value}-${p}`],style:{color:g,fontSize:vn(x)},content:_},t.badgeProps),{default:()=>{var E;return[(E=r.default)==null?void 0:E.call(r),A&&v.createVNode("img",{class:Ka("image"),src:p},null)]}})}}});const rs=si(Yx),[Jx,qr]=pr("loading"),Kx=Array(12).fill(null).map((t,r)=>v.createVNode("i",{class:qr("line",String(r+1))},null)),Qx=v.createVNode("svg",{class:qr("circular"),viewBox:"25 25 50 50"},[v.createVNode("circle",{cx:"50",cy:"50",r:"20",fill:"none"},null)]),ey={size:ln,type:cn("circular"),color:String,vertical:Boolean,textSize:ln,textColor:String};var ty=v.defineComponent({name:Jx,props:ey,setup(t,{slots:r}){const o=v.computed(()=>Rn({color:t.color},bx(t.size))),c=()=>{const f=t.type==="spinner"?Kx:Qx;return v.createVNode("span",{class:qr("spinner",t.type),style:o.value},[r.icon?r.icon():f])},u=()=>{var f;if(r.default)return v.createVNode("span",{class:qr("text"),style:{fontSize:vn(t.textSize),color:(f=t.textColor)!=null?f:t.color}},[r.default()])};return()=>{const{type:f,vertical:p}=t;return v.createVNode("div",{class:qr([f,{vertical:p}]),"aria-live":"polite","aria-busy":!0},[c(),u()])}}});const ny=si(ty),ry={show:Boolean,zIndex:ln,overlay:lr,duration:ln,teleport:[String,Object],lockScroll:lr,lazyRender:lr,beforeClose:Function,overlayProps:Object,overlayStyle:Object,overlayClass:Bi,transitionAppear:Boolean,closeOnClickOverlay:lr};function iy(t,r){return t>r?"horizontal":r>t?"vertical":""}function oy(){const t=v.ref(0),r=v.ref(0),o=v.ref(0),c=v.ref(0),u=v.ref(0),f=v.ref(0),p=v.ref(""),x=v.ref(!0),_=()=>p.value==="vertical",g=()=>p.value==="horizontal",A=()=>{o.value=0,c.value=0,u.value=0,f.value=0,p.value="",x.value=!0};return{move:(M=>{const D=M.touches[0];o.value=(D.clientX<0?0:D.clientX)-t.value,c.value=D.clientY-r.value,u.value=Math.abs(o.value),f.value=Math.abs(c.value);const R=10;(!p.value||u.value<R&&f.value<R)&&(p.value=iy(u.value,f.value)),x.value&&(u.value>Ya||f.value>Ya)&&(x.value=!1)}),start:(M=>{A(),t.value=M.touches[0].clientX,r.value=M.touches[0].clientY}),reset:A,startX:t,startY:r,deltaX:o,deltaY:c,offsetX:u,offsetY:f,direction:p,isVertical:_,isHorizontal:g,isTap:x}}let Vr=0;const Qa="van-overflow-hidden";function sy(t,r){const o=oy(),c="01",u="10",f=A=>{o.move(A);const E=o.deltaY.value>0?u:c,L=vx(A.target,t.value),{scrollHeight:M,offsetHeight:D,scrollTop:R}=L;let P="11";R===0?P=D>=M?"00":"01":R+D>=M&&(P="10"),P!=="11"&&o.isVertical()&&!(parseInt(P,2)&parseInt(E,2))&&Mu(A)},p=()=>{document.addEventListener("touchstart",o.start),document.addEventListener("touchmove",f,{passive:!1}),Vr||document.body.classList.add(Qa),Vr++},x=()=>{Vr&&(document.removeEventListener("touchstart",o.start),document.removeEventListener("touchmove",f),Vr--,Vr||document.body.classList.remove(Qa))},_=()=>r()&&p(),g=()=>r()&&x();ku(_),v.onDeactivated(g),v.onBeforeUnmount(g),v.watch(r,A=>{A?p():x()})}function zu(t){const r=v.ref(!1);return v.watch(t,o=>{o&&(r.value=o)},{immediate:!0}),o=>()=>r.value?o():null}const el=()=>{var t;const{scopeId:r}=((t=v.getCurrentInstance())==null?void 0:t.vnode)||{};return r?{[r]:""}:null},[ay,ly]=pr("overlay"),cy={show:Boolean,zIndex:ln,duration:ln,className:Bi,lockScroll:lr,lazyRender:lr,customStyle:Object,teleport:[String,Object]};var uy=v.defineComponent({name:ay,inheritAttrs:!1,props:cy,setup(t,{attrs:r,slots:o}){const c=v.ref(),u=zu(()=>t.show||!t.lazyRender),f=x=>{t.lockScroll&&Mu(x)},p=u(()=>{var x;const _=Rn(Ex(t.zIndex),t.customStyle);return Jn(t.duration)&&(_.animationDuration=`${t.duration}s`),v.withDirectives(v.createVNode("div",v.mergeProps({ref:c,style:_,class:[ly(),t.className]},r),[(x=o.default)==null?void 0:x.call(o)]),[[v.vShow,t.show]])});return Ru("touchmove",f,{target:c}),()=>{const x=v.createVNode(v.Transition,{name:"van-fade",appear:!0},{default:p});return t.teleport?v.createVNode(v.Teleport,{to:t.teleport},{default:()=>[x]}):x}}});const dy=si(uy),fy=Rn({},ry,{round:Boolean,position:cn("center"),closeIcon:cn("cross"),closeable:Boolean,transition:String,iconPrefix:String,closeOnPopstate:Boolean,closeIconPosition:cn("top-right"),destroyOnClose:Boolean,safeAreaInsetTop:Boolean,safeAreaInsetBottom:Boolean}),[hy,tl]=pr("popup");var py=v.defineComponent({name:hy,inheritAttrs:!1,props:fy,emits:["open","close","opened","closed","keydown","update:show","clickOverlay","clickCloseIcon"],setup(t,{emit:r,attrs:o,slots:c}){let u,f;const p=v.ref(),x=v.ref(),_=zu(()=>t.show||!t.lazyRender),g=v.computed(()=>{const j={zIndex:p.value};if(Jn(t.duration)){const z=t.position==="center"?"animationDuration":"transitionDuration";j[z]=`${t.duration}s`}return j}),A=()=>{u||(u=!0,p.value=t.zIndex!==void 0?+t.zIndex:Vx(),r("open"))},E=()=>{u&&Px(t.beforeClose,{done(){u=!1,r("close"),r("update:show",!1)}})},L=j=>{r("clickOverlay",j),t.closeOnClickOverlay&&E()},M=()=>{if(t.overlay){const j=Rn({show:t.show,class:t.overlayClass,zIndex:p.value,duration:t.duration,customStyle:t.overlayStyle,role:t.closeOnClickOverlay?"button":void 0,tabindex:t.closeOnClickOverlay?0:void 0},t.overlayProps);return v.createVNode(dy,v.mergeProps(j,el(),{onClick:L}),{default:c["overlay-content"]})}},D=j=>{r("clickCloseIcon",j),E()},R=()=>{if(t.closeable)return v.createVNode(rs,{role:"button",tabindex:0,name:t.closeIcon,class:[tl("close-icon",t.closeIconPosition),Dx],classPrefix:t.iconPrefix,onClick:D},null)};let P;const H=()=>{P&&clearTimeout(P),P=setTimeout(()=>{r("opened")})},Z=()=>r("closed"),$=j=>r("keydown",j),V=_(()=>{var j;const{destroyOnClose:z,round:q,position:B,safeAreaInsetTop:we,safeAreaInsetBottom:re,show:ne}=t;if(!(!ne&&z))return v.withDirectives(v.createVNode("div",v.mergeProps({ref:x,style:g.value,role:"dialog",tabindex:0,class:[tl({round:q,[B]:B}),{"van-safe-area-top":we,"van-safe-area-bottom":re}],onKeydown:$},o,el()),[(j=c.default)==null?void 0:j.call(c),R()]),[[v.vShow,ne]])}),ee=()=>{const{position:j,transition:z,transitionAppear:q}=t,B=j==="center"?"van-fade":`van-popup-slide-${j}`;return v.createVNode(v.Transition,{name:z||B,appear:q,onAfterEnter:H,onAfterLeave:Z},{default:V})};return v.watch(()=>t.show,j=>{j&&!u&&(A(),o.tabindex===0&&v.nextTick(()=>{var z;(z=x.value)==null||z.focus()})),!j&&u&&(u=!1,r("close"))}),Bu({popupRef:x}),sy(x,()=>t.show&&t.lockScroll),Ru("popstate",()=>{t.closeOnPopstate&&(E(),f=!1)}),v.onMounted(()=>{t.show&&A()}),v.onActivated(()=>{f&&(r("update:show",!0),f=!1)}),v.onDeactivated(()=>{t.show&&t.teleport&&(E(),f=!0)}),v.provide(Bx,()=>t.show),()=>t.teleport?v.createVNode(v.Teleport,{to:t.teleport},{default:()=>[M(),ee()]}):v.createVNode(v.Fragment,null,[M(),ee()])}});const my=si(py);let $r=0;function gy(t){t?($r||document.body.classList.add("van-toast--unclickable"),$r++):$r&&($r--,$r||document.body.classList.remove("van-toast--unclickable"))}const[xy,Er]=pr("toast"),yy=["show","overlay","teleport","transition","overlayClass","overlayStyle","closeOnClickOverlay","zIndex"],wy={icon:String,show:Boolean,type:cn("text"),overlay:Boolean,message:ln,iconSize:ln,duration:gx(2e3),position:cn("middle"),teleport:[String,Object],wordBreak:String,className:Bi,iconPrefix:String,transition:cn("van-fade"),loadingType:String,forbidClick:Boolean,overlayClass:Bi,overlayStyle:Object,closeOnClick:Boolean,closeOnClickOverlay:Boolean,zIndex:ln};var _y=v.defineComponent({name:xy,props:wy,emits:["update:show"],setup(t,{emit:r,slots:o}){let c,u=!1;const f=()=>{const E=t.show&&t.forbidClick;u!==E&&(u=E,gy(u))},p=E=>r("update:show",E),x=()=>{t.closeOnClick&&p(!1)},_=()=>clearTimeout(c),g=()=>{const{icon:E,type:L,iconSize:M,iconPrefix:D,loadingType:R}=t;if(E||L==="success"||L==="fail")return v.createVNode(rs,{name:E||L,size:M,class:Er("icon"),classPrefix:D},null);if(L==="loading")return v.createVNode(ny,{class:Er("loading"),size:M,type:R},null)},A=()=>{const{type:E,message:L}=t;if(o.message)return v.createVNode("div",{class:Er("text")},[o.message()]);if(Jn(L)&&L!=="")return E==="html"?v.createVNode("div",{key:0,class:Er("text"),innerHTML:String(L)},null):v.createVNode("div",{class:Er("text")},[L])};return v.watch(()=>[t.show,t.forbidClick],f),v.watch(()=>[t.show,t.type,t.message,t.duration],()=>{_(),t.show&&t.duration>0&&(c=setTimeout(()=>{p(!1)},t.duration))}),v.onMounted(f),v.onUnmounted(f),()=>v.createVNode(my,v.mergeProps({class:[Er([t.position,t.wordBreak==="normal"?"break-normal":t.wordBreak,{[t.type]:!t.icon}]),t.className],lockScroll:!1,onClick:x,onClosed:_,"onUpdate:show":p},mx(t,yy)),{default:()=>[g(),A()]})}});function vy(){const t=v.reactive({show:!1}),r=u=>{t.show=u},o=u=>{Rn(t,u,{transitionAppear:!0}),r(!0)},c=()=>r(!1);return Bu({open:o,close:c,toggle:r}),{open:o,close:c,state:t,toggle:r}}function Cy(t){const r=v.createApp(t),o=document.createElement("div");return document.body.appendChild(o),{instance:r.mount(o),unmount(){r.unmount(),document.body.removeChild(o)}}}const by={icon:"",type:"text",message:"",className:"",overlay:!1,onClose:void 0,onOpened:void 0,duration:2e3,teleport:"body",iconSize:void 0,iconPrefix:void 0,position:"middle",transition:"van-fade",forbidClick:!1,loadingType:void 0,overlayClass:"",overlayStyle:void 0,closeOnClick:!1,closeOnClickOverlay:!1};let Si=[],Ey=!1,nl=Rn({},by);const Ay=new Map;function Vu(t){return ji(t)?t:{message:t}}function Iy(){const{instance:t}=Cy({setup(){const r=v.ref(""),{open:o,state:c,close:u,toggle:f}=vy(),p=()=>{},x=()=>{const _={onClosed:p,"onUpdate:show":f};return v.createVNode(_y,v.mergeProps(c,_),null)};return v.watch(r,_=>{c.message=_}),v.getCurrentInstance().render=x,{open:o,close:u,message:r}}});return t}function Sy(){if(!Si.length||Ey){const t=Iy();Si.push(t)}return Si[Si.length-1]}function Je(t={}){if(!ts)return{};const r=Sy(),o=Vu(t);return r.open(Rn({},nl,Ay.get(o.type||nl.type),o)),r}const Ty=t=>r=>Je(Rn({type:t},Vu(r))),$u=Ty("loading"),Ny=t=>{try{const r=JSON.parse(t),o=[];if(!r.mcpServers||typeof r.mcpServers!="object")throw new Error("JSON 格式错误:缺少 mcpServers 字段");for(const[c,u]of Object.entries(r.mcpServers)){const f=Oy(u);f&&o.push({name:c,config:f})}return o}catch(r){throw new Error(`JSON 解析失败: ${r instanceof Error?r.message:"未知错误"}`)}},Oy=t=>{if(!t||typeof t!="object"||!t.url)return null;const{type:r,url:o,sessionId:c}=t;return r==="extension"?c?{type:"extension",url:o,sessionId:c,useAISdkClient:!0}:null:r==="streamableHttp"||r==="sse"?{type:r,url:o,useAISdkClient:!0}:{type:"streamableHttp",url:o,useAISdkClient:!0}},ky=(t,r,o)=>{const c=async(f,p,x,_,g)=>{if(await t.insertMcpServer(f,p)){const E=t.mcpTools[f];if(E){const M={id:`plugin-${f.replace("mcp-server-","")}`,name:x,icon:g||o,description:_||(typeof p=="object"&&"url"in p?p.url:""),enabled:!0,expanded:!0,tools:Object.keys(E).map(D=>({id:D,name:D,description:E[D].description,enabled:!0})),originMcpConfig:v.markRaw(p)};return r.value.push(M),!0}else return await t.removeMcpServer(f),!1}else return!1};return{handleCustomAdd:async(f,p)=>{$u("添加工具中...");try{if(f==="code"){if(typeof p!="string"){Je("添加工具失败:code 类型需要 JSON 字符串格式");return}const H=Ny(p);if(H.length===0){Je("添加工具失败:JSON 配置格式不正确或未找到有效的服务器配置");return}let Z=0,$=0;for(const{name:V,config:ee}of H){const j=`mcp-server-${V}`;await c(j,ee,V)?Z++:$++}await t.closeAll(),$===0?Je(`成功添加 ${Z} 个工具`):Z>0?Je(`成功添加 ${Z} 个工具,${$} 个失败`):Je("添加工具失败:所有服务器都无法连接");return}if(typeof p=="string"){Je("添加工具失败:数据格式不正确");return}const{description:x,headers:_,name:g,thumbnail:A,type:E,url:L}=p;if(!g||!L||!E){Je("添加工具失败:缺少必要参数(名称、URL或类型)");return}const D=`mcp-server-${`custom-${g}-${Date.now()}`}`;await c(D,{type:E,url:L,useAISdkClient:!0},g,x,A)?(await t.closeAll(),Je("添加工具完成")):Je("重复添加工具或无法获取工具列表")}catch(x){console.error("handleCustomAdd error:",x),Je(`添加工具失败:${x instanceof Error?x.message:"未知错误"}`)}}}};function Ry(t,r,o){const c=v.ref([]),u=v.ref([]),f=v.ref(!1),p=V=>V==="mcp-server-localhost",x=(V,ee)=>{ee?t.ignoreToolnames=t.ignoreToolnames.filter(j=>j!==V):t.ignoreToolnames.includes(V)||t.ignoreToolnames.push(V)},_=(V,ee)=>{r.value||(r.value={});const j={...r.value};V===null?Object.keys(j).forEach(z=>{j[z]=ee}):j[V]=ee,r.value=j},g=V=>{const ee=u.value.find(j=>j.id===V);ee&&(ee.addState="idle")},A=V=>{const ee=t.mcpTools[V];if(!ee)return[];const j=p(V),z=r.value||{};return Object.keys(ee).map(q=>{const B=j?!!z[q]:!0;return x(q,B),{id:q,name:q,description:ee[q].description,enabled:B}})},E=async V=>{const ee=V.pluginId;if(!await t.insertMcpServer(ee,V.mcpServer))return!1;if(!t.mcpTools[ee])return await t.removeMcpServer(ee),!1;const q=A(ee);if(q.length===0)return await t.removeMcpServer(ee),!1;const B=c.value.find(re=>re.id===V.pluginId);if(B)return B.tools=q,B.originMcpConfig=v.markRaw(V.mcpServer),!0;const we={id:V.pluginId,name:V.name,icon:V.icon||o,description:V.description,enabled:!0,expanded:!1,tools:q,originMcpConfig:v.markRaw(V.mcpServer)};return c.value.push(we),!0};return{installedPlugins:c,marketPlugins:u,pluginVisible:f,loadMcpServerToPlugin:async(V,ee)=>{let j,z;if("type"in ee&&ee.type==="local")j="本地工具",z="本地工具列表";else{const q=new URL(ee.url);j=q.origin,z=q.searchParams.get("sessionId")||("sessionId"in ee?ee.sessionId:"")||""}await E({pluginId:V,name:j,description:z,mcpServer:ee})},togglePlugin:(V,ee)=>{const j=p(V.id);V.tools.forEach(z=>{z.enabled=ee,x(z.id,ee),j&&_(z.id,ee)})},toggleTool:(V,ee,j)=>{const z=p(V.id);V.tools.forEach(q=>{q.id===ee&&(q.enabled=j)}),x(ee,j),z&&_(ee,j)},deletePlugin:async V=>{const ee=c.value.find(z=>z.id===V.id);if(!ee)return;c.value=c.value.filter(z=>z.id!==ee.id),g(ee.id);const j=V.id;await t.removeMcpServer(j)},addPluginFromMarket:async V=>{V.addState="loading";const ee={type:V.type,url:V.url,useAISdkClient:!0},j=await E({pluginId:V.id,name:V.name,description:V.description||"",icon:V.icon,mcpServer:ee});V.addState=j?"added":"idle"},addPluginFromScan:async(V,ee)=>{const j={type:"streamableHttp",url:`${ee}mcp?sessionId=${V}`},z=new URL(`${ee}mcp?sessionId=${V}`);return await E({pluginId:`plugin-${V}`,name:z.origin,description:V,mcpServer:j})},handleClientDisconnected:async V=>{const ee=V,j=c.value.find(z=>z.id===ee);return await t.removeMcpServer(V),j?(c.value=c.value.filter(z=>z.id!==ee),g(ee),j):null},searchPlugin:(V,ee)=>V.trim()===""||ee.name.toLowerCase().includes(V.toLowerCase())}}function My(t){const{skillsRef:r,systemPrompt:o,customAgentProvider:c}=t,u=v.computed(()=>{const g=r?.value;return g?cr.getSkillOverviews(g):[]}),f=v.computed(()=>{const g=u.value;return g.length>0?cr.formatSkillsForSystemPrompt(g):""}),p=v.computed(()=>{const g=r?.value;return g?cr.createSkillTools(g):{}}),x=o||"";return v.watchEffect(()=>{if(c.systemPrompt=f.value?`${x}
55
55
 
56
- ${f.value}`:x,c.llmConfig){const m=c.llmConfig.extraTools??{};c.llmConfig.extraTools={...m,...p.value}}}),{processSkillMentions:async()=>({shouldBlock:!1,skillItems:[]}),skillPromptPart:f,skillTools:p,skillOverviews:u}}const Tw=["title"],Nw=v.defineComponent({__name:"tokenUsage",props:{usage:{type:Object,default:""}},setup(t){const r=t,o=v.computed(()=>{const{inputTokens:u=0,outputTokens:f=0,totalTokens:p=0,inputTokenDetails:x,outputTokenDetails:y}=r.usage,m=x?.cacheReadTokens||0,A=y?.reasoningTokens||0;return{cachedInputTokens:[m/p*100+"%",m],inputTokens:[(u-m)/p*100+"%",u],reasoningTokens:[A/p*100+"%",A],outputTokens:[(f-A)/p*100+"%",f]}}),c=v.computed(()=>{const{inputTokens:u=0,outputTokens:f=0,totalTokens:p=0,inputTokenDetails:x,outputTokenDetails:y}=r.usage,m=x?.cacheReadTokens||0,A=y?.reasoningTokens||0;return[`inputTokens: ${u}`,`outputTokens: ${f}`,`totalTokens: ${p}`,`cachedInputTokens: ${m}`,`reasoningTokens: ${A}`].join(`
57
- `)});return(u,f)=>(v.openBlock(),v.createElementBlock("div",{class:"token-usage-wrap",title:c.value},[(v.openBlock(!0),v.createElementBlock(v.Fragment,null,v.renderList(o.value,(p,x)=>(v.openBlock(),v.createElementBlock("div",{key:x,class:v.normalizeClass(x),style:v.normalizeStyle({width:p[0]})},null,6))),128))],8,Tw))}}),qn=(t,r)=>{const o=t.__vccOpts||t;for(const[c,u]of r)o[c]=u;return o},Ow=qn(Nw,[["__scopeId","data-v-78226cbc"]]),kw={width:"100.000000",height:"100.000000",viewBox:"0 0 100 100",fill:"none",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"};function Rw(t,r){return v.openBlock(),v.createElementBlock("svg",kw,[...r[0]||(r[0]=[v.createStaticVNode('<desc> Created with Pixso. </desc><defs><radialGradient gradientTransform="translate(32.4474 65.1156) rotate(128.932) scale(22.991 20.6919)" cx="0.000000" cy="0.000000" r="1.000000" id="paint_radial_9_3090_0" gradientUnits="userSpaceOnUse"><stop stop-color="#5ADDF8"></stop><stop stop-color="#AEBFFF"></stop><stop offset="0.329153" stop-color="#1476FF"></stop><stop offset="0.667785" stop-color="#655AF8"></stop><stop offset="0.868255" stop-color="#948CFF"></stop><stop offset="1.000000" stop-color="#D25AF8"></stop><stop offset="1.000000" stop-color="#5A8BF8"></stop></radialGradient><linearGradient x1="30.999874" y1="85.000229" x2="30.499891" y2="70.500214" id="paint_linear_9_3092_0" gradientUnits="userSpaceOnUse"><stop stop-color="#000000" stop-opacity="0.000000"></stop><stop offset="1.000000" stop-color="#000000"></stop></linearGradient><radialGradient gradientTransform="translate(26.9999 24.7118) rotate(38.3655) scale(77.7996 109.496)" cx="0.000000" cy="0.000000" r="1.000000" id="paint_radial_9_3094_0" gradientUnits="userSpaceOnUse"><stop stop-color="#5ADDF8"></stop><stop stop-color="#AEBFFF"></stop><stop offset="0.329153" stop-color="#1476FF"></stop><stop offset="0.667785" stop-color="#655AF8"></stop><stop offset="0.868255" stop-color="#948CFF"></stop><stop offset="1.000000" stop-color="#D25AF8"></stop><stop offset="1.000000" stop-color="#5A8BF8"></stop></radialGradient></defs><rect id="NEXT-LOGO-无背景渐变-右" width="100.000000" height="99.999939" transform="matrix(-1 0 0 1 100 0)" fill="#FFFFFF" fill-opacity="0"></rect>',3),v.createElementVNode("mask",{id:"mask9_3088","mask-type":"alpha",maskUnits:"userSpaceOnUse",x:"0.000061",y:"0.000061",width:"99.999939",height:"99.999939"},[v.createElementVNode("rect",{id:"画板 1773",width:"99.999962",height:"99.999947",transform:"matrix(-1 0 0 1 100 6.10352e-05)",fill:"#000000","fill-opacity":"1.000000"})],-1),v.createStaticVNode('<g mask="url(#mask9_3088)"><path id="矢量 1" d="M35.93 81.01L36 63L18 63.07L32.48 82.23C33.61 83.71 35.93 82.9 35.93 81.01Z" fill="url(#paint_radial_9_3090_0)" fill-opacity="1.000000" fill-rule="evenodd"></path><g opacity="0.100000" style="mix-blend-mode:normal;"><path id="矢量 1" d="M35.93 81.01L36 63L18 63.07L32.48 82.23C33.61 83.71 35.93 82.9 35.93 81.01Z" fill="url(#paint_linear_9_3092_0)" fill-opacity="1.000000" fill-rule="evenodd"></path></g><rect id="矩形 5" x="12.000000" y="19.000183" rx="26.999992" width="75.999977" height="53.999985" fill="url(#paint_radial_9_3094_0)" fill-opacity="1.000000"></rect><rect id="矩形 5" rx="26.499992" width="74.999977" height="52.999985" transform="matrix(-1 0 0 1 87.5 19.5002)" fill="#000000" fill-opacity="0"></rect><rect id="矩形 5" rx="26.499992" width="74.999977" height="52.999985" transform="matrix(-1 0 0 1 87.5 19.5002)" stroke="#000000" stroke-opacity="0" stroke-width="1.000000"></rect><path id="path" d="M45.39 59.06C44.22 60.05 42.9 60.66 41.43 60.89C39.95 61.12 38.57 61.04 37.28 60.65C36 60.26 34.04 58.58 34.04 58.58C34.04 58.58 29.02 54.73 29.02 45.61C29.02 36.5 33.5 32.5 33.5 32.5C33.5 32.5 34.72 31.31 36.5 31C38.29 30.68 39.43 30.98 40.66 31.33C50.89 34.23 62.38 34.33 72.58 31.33C73.81 30.98 74.91 30.93 75.89 31.17C76.87 31.42 77.71 31.89 78.42 32.59C81.65 35.81 82.87 41.06 83 45.61C83.12 50.09 81.97 55.24 78.94 58.54C78.04 59.52 76.98 60.22 75.78 60.63C74.58 61.04 73.32 61.12 71.99 60.89C70.66 60.66 69.48 60.05 68.46 59.06C68.01 58.62 67.39 58.07 66.57 57.4C65.76 56.73 64.83 56.08 63.79 55.44C62.75 54.8 61.62 54.25 60.39 53.8C59.16 53.35 57.91 53.13 56.62 53.13C55.36 53.13 54.16 53.36 53 53.83C51.85 54.29 50.79 54.84 49.82 55.48C48.86 56.12 48 56.78 47.26 57.45C46.51 58.11 45.89 58.65 45.39 59.06Z" fill="#FFFFFF" fill-opacity="1.000000" fill-rule="nonzero"></path><rect id="矩形 841" rx="2.000000" width="3.999999" height="11.999996" transform="matrix(-0.999983 0.00577157 0.00577157 0.999983 76.1109 38.0356)" fill="#1476FF" fill-opacity="1.000000"></rect><path id="合并" d="M42.96 38C43.77 37.97 44.55 38.42 44.92 39.19L48.73 47.11C49.22 48.13 48.79 49.34 47.75 49.81C46.72 50.28 45.48 49.83 44.99 48.8L42.96 44.59L40.94 48.81C40.45 49.83 39.21 50.28 38.18 49.81C37.14 49.34 36.7 48.13 37.2 47.11L41 39.19C41.37 38.42 42.16 37.98 42.96 38Z" fill="#1476FF" fill-opacity="1.000000" fill-rule="evenodd"></path></g>',1)])])}const tl={render:Rw};function Mw(t){const{messages:r,messageState:o,inputMessage:c,handleSendMessage:u}=t,f=v.h(tl,{style:{fontSize:"32px"}}),p=v.h(Ar.IconUser,{style:{fontSize:"32px"}}),x=v.h(tl,{style:{width:"48px",height:"48px"}}),y=v.ref({}),m=v.computed(()=>Zn.GeneratingStatus.includes(o.status)),A=v.computed(()=>r.value.findLastIndex(R=>R.role==="assistant")),E=R=>R===void 0?"复制":y.value[R]?"复制成功":"复制",B=async R=>{const k=r.value[R],q=typeof k.content=="string"?k.content:JSON.stringify(k.content);try{await navigator.clipboard.writeText(q),R!==void 0&&(y.value[R]=!0,setTimeout(()=>{y.value[R]=!1},3e3))}catch(Z){console.error("复制失败:",Z),Ye("复制失败,请重试")}},D=async R=>{const k=r.value.findLastIndex((Z,z)=>Z.role==="user"&&z<=R);if(k===-1){console.warn("未找到可重新生成的用户消息"),Ye("无法重新生成消息");return}const q=r.value[k];if(r.value=r.value.slice(0,k),Array.isArray(q.content)){const z=q.content.find(Q=>Q.type==="text")?.text||"",$=q.content.filter(Q=>Q.type!=="text");c.value=z,await u(z,$.length>0?$:void 0)}else c.value=q.content,await u(q.content)};return{aiAvatar:f,userAvatar:p,welcomeIcon:x,roles:{assistant:{type:"markdown",placement:"start",avatar:f,maxWidth:"80%",customContentField:"uiContent",slots:{footer:({index:R})=>{const k=A.value===R;return m.value&&k?"":v.h("div",{class:["assistant-actions",{"latest-assistant":k,"historical-assistant":!k}],style:{display:"flex",justifyContent:"flex-start",alignItems:"center",gap:"4px"}},[v.h(Pt.IconButton,{icon:Ar.IconRefresh,size:24,onClick:()=>D(R)}),v.h(bd,{effect:"light",content:E(R),placement:"right",visibleArrow:!1},()=>v.h(Pt.IconButton,{icon:Ar.IconCopy,size:24,onClick:()=>B(R)})),r.value[R].usage?v.h(Ow,{usage:r.value[R].usage}):null])}}},user:{placement:"end",avatar:p,maxWidth:"80%",customContentField:"uiContent"}},copyingStates:y,isProcessing:m,latestAssistantMessageIndex:A,copyTooltipContent:E,copyMessageToClipboard:B,regenerateMessage:D}}function Dw(t){const{createConversation:r,switchConversation:o,deleteConversation:c,getCurrentConversation:u,abortRequest:f,conversationState:p,customAgentProvider:x}=t,y=v.ref(!1),m=()=>{v.nextTick(()=>{const M=document.querySelector("div.tr-bubble-list");M&&M.scrollTo({top:M.scrollHeight,behavior:"smooth"})})};return{showHistory:y,handleCreateConversation:()=>{f();const M=[];x.agent.responseMessages=M,r();const R=u();R.aiSdkMessages=M},handleHistorySelect:M=>{f(),o(M.id);const R=u();x.agent.responseMessages=R.aiSdkMessages,y.value=!1,m()},handleHistoryUpdateTitle:(M,R)=>{R.title=M},handleHistoryDelete:(M,R)=>{if(M.id==="delete"){if(p.currentId===R.id){Ye("不允许删除当前会话");return}c(R.id)}},scrollToBottom:m}}function Pw(t){const{sessionId:r,agentRoot:o,mode:c,qrCodeUrl:u,remoteUrl:f,menuItems:p,AILogoUrl:x,show:y,addPluginFromScan:m,inputMessage:A}=t;let E=!1;const B=async q=>{if(Vu("添加工具中..."),q){const Z=await m(q,o);Ye(Z?"添加工具完成":"重复添加工具或添加失败")}else Ye("添加工具失败")},D=async q=>{if(/^\/[A-Za-z0-9-]{6,}$/.test(q)){try{const Z=await fetch(`${o}client?sessionId=${q.slice(1)}`);if(!Z.ok)throw new Error(`HTTP ${Z.status}`);const $=(await Z.json())?.data?.sessionId;$?await B($):Ye("添加工具失败,请检查识别码是否正确"),A.value=""}catch(Z){console.error("识别码处理失败:",Z),Ye("添加工具失败,请检查识别码是否正确"),A.value=""}return!0}return!1},M=()=>{v.watch(r,q=>{q&&c==="remoter"&&!E&&(sr.createRemoter({sessionId:q,qrCodeUrl:u,remoteUrl:f,menuItems:p,logoUrl:x,onShowAIChat:()=>y.value=!0}),E=!0)},{immediate:!0})},R=()=>{v.watch(r,q=>{q&&B(q)})};return{handleScanSuccess:B,handleSessionIdInput:D,initialize:()=>{r.value&&B(r.value),c==="remoter"&&M(),R()},initializeRemoter:M,watchSessionIdChanges:R}}function Bw(t){return new Promise((r,o)=>{const c=new FileReader;c.onload=()=>r(c.result),c.onerror=o,c.readAsDataURL(t)})}function Lw(t){return t.type.startsWith("image/")}function Fw(t,r){const o=r*1024*1024;return t.size<=o}async function Uw(t){if(t.length===0)return[];const r=[];for(const o of t)if(o.rawFile)try{const c=await Bw(o.rawFile);Lw(o.rawFile)&&r.push({type:"image",image:c})}catch(c){console.error("文件转换失败:",c),Ye({type:"fail",message:"文件处理失败"})}return r}function zw(t={}){const r=v.ref([]),o=async u=>{if(!u||u.length===0)return;c();const f=v.unref(t.maxFileSize)||10,p=v.unref(t.supportedTypes)||["image/"];for(const x of u){if(!p.some(m=>x.type.startsWith(m))){Ye({type:"fail",message:`不支持的文件类型: ${x.type}`});continue}if(!Fw(x,f)){Ye({type:"fail",message:`文件大小超过 ${f}MB 限制`});continue}r.value.push({rawFile:x,url:URL.createObjectURL(x)})}},c=()=>{r.value.forEach(u=>{u.url&&URL.revokeObjectURL(u.url)}),r.value=[]};return{attachments:r,handleFilesSelected:o,clearAttachments:c}}function Vw(t){const{selectedModel:r,selectedModelId:o}=t,c=v.computed(()=>r.value?.multimodal?.supportImages??!1),u=v.computed(()=>r.value?.multimodal?.maxFileSize||10),f=v.computed(()=>r.value?.multimodal?.supportedMimeTypes||["image/"]),{attachments:p,handleFilesSelected:x,clearAttachments:y}=zw({maxFileSize:u,supportedTypes:f});return v.watch(o,()=>{if(p.value.length>0&&r.value){const D=r.value.multimodal?.maxFileSize||10,M=r.value.multimodal?.supportedMimeTypes||["image/"];p.value.filter(k=>{if(!k.rawFile||!M.some(z=>k.rawFile.type.startsWith(z)))return!0;const Z=D*1024*1024;return k.rawFile.size>Z}).length>0&&(y(),Ye("切换模型后,之前选择的附件已清空"))}}),{hasMultimodalSupport:c,attachments:p,onFilesSelected:D=>{x(D)},checkCanSendAttachments:()=>p.value.length>0&&!c.value?(Ye("当前模型不支持附件,请先移除附件或切换支持多模态的模型"),!1):!0,processAttachments:async()=>p.value.length===0?[]:await Uw(p.value),cleanupAttachments:()=>{p.value.length>0&&y()},clearAttachments:y}}var Ce;(function(t){t[t.QR_CODE=0]="QR_CODE",t[t.AZTEC=1]="AZTEC",t[t.CODABAR=2]="CODABAR",t[t.CODE_39=3]="CODE_39",t[t.CODE_93=4]="CODE_93",t[t.CODE_128=5]="CODE_128",t[t.DATA_MATRIX=6]="DATA_MATRIX",t[t.MAXICODE=7]="MAXICODE",t[t.ITF=8]="ITF",t[t.EAN_13=9]="EAN_13",t[t.EAN_8=10]="EAN_8",t[t.PDF_417=11]="PDF_417",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"})(Ce||(Ce={}));var nl=new Map([[Ce.QR_CODE,"QR_CODE"],[Ce.AZTEC,"AZTEC"],[Ce.CODABAR,"CODABAR"],[Ce.CODE_39,"CODE_39"],[Ce.CODE_93,"CODE_93"],[Ce.CODE_128,"CODE_128"],[Ce.DATA_MATRIX,"DATA_MATRIX"],[Ce.MAXICODE,"MAXICODE"],[Ce.ITF,"ITF"],[Ce.EAN_13,"EAN_13"],[Ce.EAN_8,"EAN_8"],[Ce.PDF_417,"PDF_417"],[Ce.RSS_14,"RSS_14"],[Ce.RSS_EXPANDED,"RSS_EXPANDED"],[Ce.UPC_A,"UPC_A"],[Ce.UPC_E,"UPC_E"],[Ce.UPC_EAN_EXTENSION,"UPC_EAN_EXTENSION"]]),rl;(function(t){t[t.UNKNOWN=0]="UNKNOWN",t[t.URL=1]="URL"})(rl||(rl={}));function $w(t){return Object.values(Ce).includes(t)}var ei;(function(t){t[t.SCAN_TYPE_CAMERA=0]="SCAN_TYPE_CAMERA",t[t.SCAN_TYPE_FILE=1]="SCAN_TYPE_FILE"})(ei||(ei={}));var Zw=(function(){function t(){}return t.GITHUB_PROJECT_URL="https://github.com/mebjas/html5-qrcode",t.SCAN_DEFAULT_FPS=2,t.DEFAULT_DISABLE_FLIP=!1,t.DEFAULT_REMEMBER_LAST_CAMERA_USED=!0,t.DEFAULT_SUPPORTED_SCAN_TYPE=[ei.SCAN_TYPE_CAMERA,ei.SCAN_TYPE_FILE],t})(),$u=(function(){function t(r,o){this.format=r,this.formatName=o}return t.prototype.toString=function(){return this.formatName},t.create=function(r){if(!nl.has(r))throw"".concat(r," not in html5QrcodeSupportedFormatsTextMap");return new t(r,nl.get(r))},t})(),il=(function(){function t(){}return t.createFromText=function(r){var o={text:r};return{decodedText:r,result:o}},t.createFromQrcodeResult=function(r){return{decodedText:r.text,result:r}},t})(),Bo;(function(t){t[t.UNKWOWN_ERROR=0]="UNKWOWN_ERROR",t[t.IMPLEMENTATION_ERROR=1]="IMPLEMENTATION_ERROR",t[t.NO_CODE_FOUND_ERROR=2]="NO_CODE_FOUND_ERROR"})(Bo||(Bo={}));var jw=(function(){function t(){}return t.createFrom=function(r){return{errorMessage:r,type:Bo.UNKWOWN_ERROR}},t})(),Hw=(function(){function t(r){this.verbose=r}return t.prototype.log=function(r){this.verbose&&console.log(r)},t.prototype.warn=function(r){this.verbose&&console.warn(r)},t.prototype.logError=function(r,o){(this.verbose||o===!0)&&console.error(r)},t.prototype.logErrors=function(r){if(r.length===0)throw"Logger#logError called without arguments";this.verbose&&console.error(r)},t})();function kn(t){return typeof t>"u"||t===null}var Er=(function(){function t(){}return t.codeParseError=function(r){return"QR code parse error, error = ".concat(r)},t.errorGettingUserMedia=function(r){return"Error getting userMedia, error = ".concat(r)},t.onlyDeviceSupportedError=function(){return"The device doesn't support navigator.mediaDevices , only supported cameraIdOrConfig in this case is deviceId parameter (string)."},t.cameraStreamingNotSupported=function(){return"Camera streaming not supported by the browser."},t.unableToQuerySupportedDevices=function(){return"Unable to query supported devices, unknown error."},t.insecureContextCameraQueryError=function(){return"Camera access is only supported in secure context like https or localhost."},t.scannerPaused=function(){return"Scanner paused"},t})(),Zu=(function(){function t(){}return t.isMediaStreamConstraintsValid=function(r,o){if(typeof r!="object"){var c=typeof r;return o.logError("videoConstraints should be of type object, the "+"object passed is of type ".concat(c,"."),!0),!1}for(var u=["autoGainControl","channelCount","echoCancellation","latency","noiseSuppression","sampleRate","sampleSize","volume"],f=new Set(u),p=Object.keys(r),x=0,y=p;x<y.length;x++){var m=y[x];if(f.has(m))return o.logError("".concat(m," is not supported videoConstaints."),!0),!1}return!0},t})(),jr={exports:{}},Ww=jr.exports,ol;function Gw(){return ol||(ol=1,(function(t,r){(function(o,c){c(r)})(Ww,(function(o){function c(C){return C==null}var u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(C,e){C.__proto__=e}||function(C,e){for(var n in e)e.hasOwnProperty(n)&&(C[n]=e[n])};function f(C,e){u(C,e);function n(){this.constructor=C}C.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}function p(C,e){var n=Object.setPrototypeOf;n?n(C,e):C.__proto__=e}function x(C,e){e===void 0&&(e=C.constructor);var n=Error.captureStackTrace;n&&n(C,e)}var y=(function(C){f(e,C);function e(n){var i=this.constructor,s=C.call(this,n)||this;return Object.defineProperty(s,"name",{value:i.name,enumerable:!1}),p(s,i.prototype),x(s),s}return e})(Error);class m extends y{constructor(e=void 0){super(e),this.message=e}getKind(){return this.constructor.kind}}m.kind="Exception";class A extends m{}A.kind="ArgumentException";class E extends m{}E.kind="IllegalArgumentException";class B{constructor(e){if(this.binarizer=e,e===null)throw new E("Binarizer must be non-null.")}getWidth(){return this.binarizer.getWidth()}getHeight(){return this.binarizer.getHeight()}getBlackRow(e,n){return this.binarizer.getBlackRow(e,n)}getBlackMatrix(){return(this.matrix===null||this.matrix===void 0)&&(this.matrix=this.binarizer.getBlackMatrix()),this.matrix}isCropSupported(){return this.binarizer.getLuminanceSource().isCropSupported()}crop(e,n,i,s){const a=this.binarizer.getLuminanceSource().crop(e,n,i,s);return new B(this.binarizer.createBinarizer(a))}isRotateSupported(){return this.binarizer.getLuminanceSource().isRotateSupported()}rotateCounterClockwise(){const e=this.binarizer.getLuminanceSource().rotateCounterClockwise();return new B(this.binarizer.createBinarizer(e))}rotateCounterClockwise45(){const e=this.binarizer.getLuminanceSource().rotateCounterClockwise45();return new B(this.binarizer.createBinarizer(e))}toString(){try{return this.getBlackMatrix().toString()}catch{return""}}}class D extends m{static getChecksumInstance(){return new D}}D.kind="ChecksumException";class M{constructor(e){this.source=e}getLuminanceSource(){return this.source}getWidth(){return this.source.getWidth()}getHeight(){return this.source.getHeight()}}class R{static arraycopy(e,n,i,s,a){for(;a--;)i[s++]=e[n++]}static currentTimeMillis(){return Date.now()}}class k extends m{}k.kind="IndexOutOfBoundsException";class q extends k{constructor(e=void 0,n=void 0){super(n),this.index=e,this.message=n}}q.kind="ArrayIndexOutOfBoundsException";class Z{static fill(e,n){for(let i=0,s=e.length;i<s;i++)e[i]=n}static fillWithin(e,n,i,s){Z.rangeCheck(e.length,n,i);for(let a=n;a<i;a++)e[a]=s}static rangeCheck(e,n,i){if(n>i)throw new E("fromIndex("+n+") > toIndex("+i+")");if(n<0)throw new q(n);if(i>e)throw new q(i)}static asList(...e){return e}static create(e,n,i){return Array.from({length:e}).map(a=>Array.from({length:n}).fill(i))}static createInt32Array(e,n,i){return Array.from({length:e}).map(a=>Int32Array.from({length:n}).fill(i))}static equals(e,n){if(!e||!n||!e.length||!n.length||e.length!==n.length)return!1;for(let i=0,s=e.length;i<s;i++)if(e[i]!==n[i])return!1;return!0}static hashCode(e){if(e===null)return 0;let n=1;for(const i of e)n=31*n+i;return n}static fillUint8Array(e,n){for(let i=0;i!==e.length;i++)e[i]=n}static copyOf(e,n){return e.slice(0,n)}static copyOfUint8Array(e,n){if(e.length<=n){const i=new Uint8Array(n);return i.set(e),i}return e.slice(0,n)}static copyOfRange(e,n,i){const s=i-n,a=new Int32Array(s);return R.arraycopy(e,n,a,0,s),a}static binarySearch(e,n,i){i===void 0&&(i=Z.numberComparator);let s=0,a=e.length-1;for(;s<=a;){const l=a+s>>1,d=i(n,e[l]);if(d>0)s=l+1;else if(d<0)a=l-1;else return l}return-s-1}static numberComparator(e,n){return e-n}}class z{static numberOfTrailingZeros(e){let n;if(e===0)return 32;let i=31;return n=e<<16,n!==0&&(i-=16,e=n),n=e<<8,n!==0&&(i-=8,e=n),n=e<<4,n!==0&&(i-=4,e=n),n=e<<2,n!==0&&(i-=2,e=n),i-(e<<1>>>31)}static numberOfLeadingZeros(e){if(e===0)return 32;let n=1;return e>>>16||(n+=16,e<<=16),e>>>24||(n+=8,e<<=8),e>>>28||(n+=4,e<<=4),e>>>30||(n+=2,e<<=2),n-=e>>>31,n}static toHexString(e){return e.toString(16)}static toBinaryString(e){return String(parseInt(String(e),2))}static bitCount(e){return e=e-(e>>>1&1431655765),e=(e&858993459)+(e>>>2&858993459),e=e+(e>>>4)&252645135,e=e+(e>>>8),e=e+(e>>>16),e&63}static truncDivision(e,n){return Math.trunc(e/n)}static parseInt(e,n=void 0){return parseInt(e,n)}}z.MIN_VALUE_32_BITS=-2147483648,z.MAX_VALUE=Number.MAX_SAFE_INTEGER;class ${constructor(e,n){e===void 0?(this.size=0,this.bits=new Int32Array(1)):(this.size=e,n==null?this.bits=$.makeArray(e):this.bits=n)}getSize(){return this.size}getSizeInBytes(){return Math.floor((this.size+7)/8)}ensureCapacity(e){if(e>this.bits.length*32){const n=$.makeArray(e);R.arraycopy(this.bits,0,n,0,this.bits.length),this.bits=n}}get(e){return(this.bits[Math.floor(e/32)]&1<<(e&31))!==0}set(e){this.bits[Math.floor(e/32)]|=1<<(e&31)}flip(e){this.bits[Math.floor(e/32)]^=1<<(e&31)}getNextSet(e){const n=this.size;if(e>=n)return n;const i=this.bits;let s=Math.floor(e/32),a=i[s];a&=~((1<<(e&31))-1);const l=i.length;for(;a===0;){if(++s===l)return n;a=i[s]}const d=s*32+z.numberOfTrailingZeros(a);return d>n?n:d}getNextUnset(e){const n=this.size;if(e>=n)return n;const i=this.bits;let s=Math.floor(e/32),a=~i[s];a&=~((1<<(e&31))-1);const l=i.length;for(;a===0;){if(++s===l)return n;a=~i[s]}const d=s*32+z.numberOfTrailingZeros(a);return d>n?n:d}setBulk(e,n){this.bits[Math.floor(e/32)]=n}setRange(e,n){if(n<e||e<0||n>this.size)throw new E;if(n===e)return;n--;const i=Math.floor(e/32),s=Math.floor(n/32),a=this.bits;for(let l=i;l<=s;l++){const d=l>i?0:e&31,g=(2<<(l<s?31:n&31))-(1<<d);a[l]|=g}}clear(){const e=this.bits.length,n=this.bits;for(let i=0;i<e;i++)n[i]=0}isRange(e,n,i){if(n<e||e<0||n>this.size)throw new E;if(n===e)return!0;n--;const s=Math.floor(e/32),a=Math.floor(n/32),l=this.bits;for(let d=s;d<=a;d++){const h=d>s?0:e&31,w=(2<<(d<a?31:n&31))-(1<<h)&4294967295;if((l[d]&w)!==(i?w:0))return!1}return!0}appendBit(e){this.ensureCapacity(this.size+1),e&&(this.bits[Math.floor(this.size/32)]|=1<<(this.size&31)),this.size++}appendBits(e,n){if(n<0||n>32)throw new E("Num bits must be between 0 and 32");this.ensureCapacity(this.size+n);for(let i=n;i>0;i--)this.appendBit((e>>i-1&1)===1)}appendBitArray(e){const n=e.size;this.ensureCapacity(this.size+n);for(let i=0;i<n;i++)this.appendBit(e.get(i))}xor(e){if(this.size!==e.size)throw new E("Sizes don't match");const n=this.bits;for(let i=0,s=n.length;i<s;i++)n[i]^=e.bits[i]}toBytes(e,n,i,s){for(let a=0;a<s;a++){let l=0;for(let d=0;d<8;d++)this.get(e)&&(l|=1<<7-d),e++;n[i+a]=l}}getBitArray(){return this.bits}reverse(){const e=new Int32Array(this.bits.length),n=Math.floor((this.size-1)/32),i=n+1,s=this.bits;for(let a=0;a<i;a++){let l=s[a];l=l>>1&1431655765|(l&1431655765)<<1,l=l>>2&858993459|(l&858993459)<<2,l=l>>4&252645135|(l&252645135)<<4,l=l>>8&16711935|(l&16711935)<<8,l=l>>16&65535|(l&65535)<<16,e[n-a]=l}if(this.size!==i*32){const a=i*32-this.size;let l=e[0]>>>a;for(let d=1;d<i;d++){const h=e[d];l|=h<<32-a,e[d-1]=l,l=h>>>a}e[i-1]=l}this.bits=e}static makeArray(e){return new Int32Array(Math.floor((e+31)/32))}equals(e){if(!(e instanceof $))return!1;const n=e;return this.size===n.size&&Z.equals(this.bits,n.bits)}hashCode(){return 31*this.size+Z.hashCode(this.bits)}toString(){let e="";for(let n=0,i=this.size;n<i;n++)(n&7)===0&&(e+=" "),e+=this.get(n)?"X":".";return e}clone(){return new $(this.size,this.bits.slice())}}var Q;(function(C){C[C.OTHER=0]="OTHER",C[C.PURE_BARCODE=1]="PURE_BARCODE",C[C.POSSIBLE_FORMATS=2]="POSSIBLE_FORMATS",C[C.TRY_HARDER=3]="TRY_HARDER",C[C.CHARACTER_SET=4]="CHARACTER_SET",C[C.ALLOWED_LENGTHS=5]="ALLOWED_LENGTHS",C[C.ASSUME_CODE_39_CHECK_DIGIT=6]="ASSUME_CODE_39_CHECK_DIGIT",C[C.ASSUME_GS1=7]="ASSUME_GS1",C[C.RETURN_CODABAR_START_END=8]="RETURN_CODABAR_START_END",C[C.NEED_RESULT_POINT_CALLBACK=9]="NEED_RESULT_POINT_CALLBACK",C[C.ALLOWED_EAN_EXTENSIONS=10]="ALLOWED_EAN_EXTENSIONS"})(Q||(Q={}));var O=Q;class V extends m{static getFormatInstance(){return new V}}V.kind="FormatException";var le;(function(C){C[C.Cp437=0]="Cp437",C[C.ISO8859_1=1]="ISO8859_1",C[C.ISO8859_2=2]="ISO8859_2",C[C.ISO8859_3=3]="ISO8859_3",C[C.ISO8859_4=4]="ISO8859_4",C[C.ISO8859_5=5]="ISO8859_5",C[C.ISO8859_6=6]="ISO8859_6",C[C.ISO8859_7=7]="ISO8859_7",C[C.ISO8859_8=8]="ISO8859_8",C[C.ISO8859_9=9]="ISO8859_9",C[C.ISO8859_10=10]="ISO8859_10",C[C.ISO8859_11=11]="ISO8859_11",C[C.ISO8859_13=12]="ISO8859_13",C[C.ISO8859_14=13]="ISO8859_14",C[C.ISO8859_15=14]="ISO8859_15",C[C.ISO8859_16=15]="ISO8859_16",C[C.SJIS=16]="SJIS",C[C.Cp1250=17]="Cp1250",C[C.Cp1251=18]="Cp1251",C[C.Cp1252=19]="Cp1252",C[C.Cp1256=20]="Cp1256",C[C.UnicodeBigUnmarked=21]="UnicodeBigUnmarked",C[C.UTF8=22]="UTF8",C[C.ASCII=23]="ASCII",C[C.Big5=24]="Big5",C[C.GB18030=25]="GB18030",C[C.EUC_KR=26]="EUC_KR"})(le||(le={}));class j{constructor(e,n,i,...s){this.valueIdentifier=e,this.name=i,typeof n=="number"?this.values=Int32Array.from([n]):this.values=n,this.otherEncodingNames=s,j.VALUE_IDENTIFIER_TO_ECI.set(e,this),j.NAME_TO_ECI.set(i,this);const a=this.values;for(let l=0,d=a.length;l!==d;l++){const h=a[l];j.VALUES_TO_ECI.set(h,this)}for(const l of s)j.NAME_TO_ECI.set(l,this)}getValueIdentifier(){return this.valueIdentifier}getName(){return this.name}getValue(){return this.values[0]}static getCharacterSetECIByValue(e){if(e<0||e>=900)throw new V("incorect value");const n=j.VALUES_TO_ECI.get(e);if(n===void 0)throw new V("incorect value");return n}static getCharacterSetECIByName(e){const n=j.NAME_TO_ECI.get(e);if(n===void 0)throw new V("incorect value");return n}equals(e){if(!(e instanceof j))return!1;const n=e;return this.getName()===n.getName()}}j.VALUE_IDENTIFIER_TO_ECI=new Map,j.VALUES_TO_ECI=new Map,j.NAME_TO_ECI=new Map,j.Cp437=new j(le.Cp437,Int32Array.from([0,2]),"Cp437"),j.ISO8859_1=new j(le.ISO8859_1,Int32Array.from([1,3]),"ISO-8859-1","ISO88591","ISO8859_1"),j.ISO8859_2=new j(le.ISO8859_2,4,"ISO-8859-2","ISO88592","ISO8859_2"),j.ISO8859_3=new j(le.ISO8859_3,5,"ISO-8859-3","ISO88593","ISO8859_3"),j.ISO8859_4=new j(le.ISO8859_4,6,"ISO-8859-4","ISO88594","ISO8859_4"),j.ISO8859_5=new j(le.ISO8859_5,7,"ISO-8859-5","ISO88595","ISO8859_5"),j.ISO8859_6=new j(le.ISO8859_6,8,"ISO-8859-6","ISO88596","ISO8859_6"),j.ISO8859_7=new j(le.ISO8859_7,9,"ISO-8859-7","ISO88597","ISO8859_7"),j.ISO8859_8=new j(le.ISO8859_8,10,"ISO-8859-8","ISO88598","ISO8859_8"),j.ISO8859_9=new j(le.ISO8859_9,11,"ISO-8859-9","ISO88599","ISO8859_9"),j.ISO8859_10=new j(le.ISO8859_10,12,"ISO-8859-10","ISO885910","ISO8859_10"),j.ISO8859_11=new j(le.ISO8859_11,13,"ISO-8859-11","ISO885911","ISO8859_11"),j.ISO8859_13=new j(le.ISO8859_13,15,"ISO-8859-13","ISO885913","ISO8859_13"),j.ISO8859_14=new j(le.ISO8859_14,16,"ISO-8859-14","ISO885914","ISO8859_14"),j.ISO8859_15=new j(le.ISO8859_15,17,"ISO-8859-15","ISO885915","ISO8859_15"),j.ISO8859_16=new j(le.ISO8859_16,18,"ISO-8859-16","ISO885916","ISO8859_16"),j.SJIS=new j(le.SJIS,20,"SJIS","Shift_JIS"),j.Cp1250=new j(le.Cp1250,21,"Cp1250","windows-1250"),j.Cp1251=new j(le.Cp1251,22,"Cp1251","windows-1251"),j.Cp1252=new j(le.Cp1252,23,"Cp1252","windows-1252"),j.Cp1256=new j(le.Cp1256,24,"Cp1256","windows-1256"),j.UnicodeBigUnmarked=new j(le.UnicodeBigUnmarked,25,"UnicodeBigUnmarked","UTF-16BE","UnicodeBig"),j.UTF8=new j(le.UTF8,26,"UTF8","UTF-8"),j.ASCII=new j(le.ASCII,Int32Array.from([27,170]),"ASCII","US-ASCII"),j.Big5=new j(le.Big5,28,"Big5"),j.GB18030=new j(le.GB18030,29,"GB18030","GB2312","EUC_CN","GBK"),j.EUC_KR=new j(le.EUC_KR,30,"EUC_KR","EUC-KR");class Ee extends m{}Ee.kind="UnsupportedOperationException";class de{static decode(e,n){const i=this.encodingName(n);return this.customDecoder?this.customDecoder(e,i):typeof TextDecoder>"u"||this.shouldDecodeOnFallback(i)?this.decodeFallback(e,i):new TextDecoder(i).decode(e)}static shouldDecodeOnFallback(e){return!de.isBrowser()&&e==="ISO-8859-1"}static encode(e,n){const i=this.encodingName(n);return this.customEncoder?this.customEncoder(e,i):typeof TextEncoder>"u"?this.encodeFallback(e):new TextEncoder().encode(e)}static isBrowser(){return typeof window<"u"&&{}.toString.call(window)==="[object Window]"}static encodingName(e){return typeof e=="string"?e:e.getName()}static encodingCharacterSet(e){return e instanceof j?e:j.getCharacterSetECIByName(e)}static decodeFallback(e,n){const i=this.encodingCharacterSet(n);if(de.isDecodeFallbackSupported(i)){let s="";for(let a=0,l=e.length;a<l;a++){let d=e[a].toString(16);d.length<2&&(d="0"+d),s+="%"+d}return decodeURIComponent(s)}if(i.equals(j.UnicodeBigUnmarked))return String.fromCharCode.apply(null,new Uint16Array(e.buffer));throw new Ee(`Encoding ${this.encodingName(n)} not supported by fallback.`)}static isDecodeFallbackSupported(e){return e.equals(j.UTF8)||e.equals(j.ISO8859_1)||e.equals(j.ASCII)}static encodeFallback(e){const i=btoa(unescape(encodeURIComponent(e))).split(""),s=[];for(let a=0;a<i.length;a++)s.push(i[a].charCodeAt(0));return new Uint8Array(s)}}class ne{static castAsNonUtf8Char(e,n=null){const i=n?n.getName():this.ISO88591;return de.decode(new Uint8Array([e]),i)}static guessEncoding(e,n){if(n!=null&&n.get(O.CHARACTER_SET)!==void 0)return n.get(O.CHARACTER_SET).toString();const i=e.length;let s=!0,a=!0,l=!0,d=0,h=0,g=0,w=0,b=0,I=0,N=0,F=0,U=0,W=0,K=0;const fe=e.length>3&&e[0]===239&&e[1]===187&&e[2]===191;for(let he=0;he<i&&(s||a||l);he++){const ce=e[he]&255;l&&(d>0?(ce&128)===0?l=!1:d--:(ce&128)!==0&&((ce&64)===0?l=!1:(d++,(ce&32)===0?h++:(d++,(ce&16)===0?g++:(d++,(ce&8)===0?w++:l=!1))))),s&&(ce>127&&ce<160?s=!1:ce>159&&(ce<192||ce===215||ce===247)&&K++),a&&(b>0?ce<64||ce===127||ce>252?a=!1:b--:ce===128||ce===160||ce>239?a=!1:ce>160&&ce<224?(I++,F=0,N++,N>U&&(U=N)):ce>127?(b++,N=0,F++,F>W&&(W=F)):(N=0,F=0))}return l&&d>0&&(l=!1),a&&b>0&&(a=!1),l&&(fe||h+g+w>0)?ne.UTF8:a&&(ne.ASSUME_SHIFT_JIS||U>=3||W>=3)?ne.SHIFT_JIS:s&&a?U===2&&I===2||K*10>=i?ne.SHIFT_JIS:ne.ISO88591:s?ne.ISO88591:a?ne.SHIFT_JIS:l?ne.UTF8:ne.PLATFORM_DEFAULT_ENCODING}static format(e,...n){let i=-1;function s(l,d,h,g,w,b){if(l==="%%")return"%";if(n[++i]===void 0)return;l=g?parseInt(g.substr(1)):void 0;let I=w?parseInt(w.substr(1)):void 0,N;switch(b){case"s":N=n[i];break;case"c":N=n[i][0];break;case"f":N=parseFloat(n[i]).toFixed(l);break;case"p":N=parseFloat(n[i]).toPrecision(l);break;case"e":N=parseFloat(n[i]).toExponential(l);break;case"x":N=parseInt(n[i]).toString(I||16);break;case"d":N=parseFloat(parseInt(n[i],I||10).toPrecision(l)).toFixed(0);break}N=typeof N=="object"?JSON.stringify(N):(+N).toString(I);let F=parseInt(h),U=h&&h[0]+""=="0"?"0":" ";for(;N.length<F;)N=d!==void 0?N+U:U+N;return N}let a=/%(-)?(0?[0-9]+)?([.][0-9]+)?([#][0-9]+)?([scfpexd%])/g;return e.replace(a,s)}static getBytes(e,n){return de.encode(e,n)}static getCharCode(e,n=0){return e.charCodeAt(n)}static getCharAt(e){return String.fromCharCode(e)}}ne.SHIFT_JIS=j.SJIS.getName(),ne.GB2312="GB2312",ne.ISO88591=j.ISO8859_1.getName(),ne.EUC_JP="EUC_JP",ne.UTF8=j.UTF8.getName(),ne.PLATFORM_DEFAULT_ENCODING=ne.UTF8,ne.ASSUME_SHIFT_JIS=!1;class oe{constructor(e=""){this.value=e}enableDecoding(e){return this.encoding=e,this}append(e){return typeof e=="string"?this.value+=e.toString():this.encoding?this.value+=ne.castAsNonUtf8Char(e,this.encoding):this.value+=String.fromCharCode(e),this}appendChars(e,n,i){for(let s=n;n<n+i;s++)this.append(e[s]);return this}length(){return this.value.length}charAt(e){return this.value.charAt(e)}deleteCharAt(e){this.value=this.value.substr(0,e)+this.value.substring(e+1)}setCharAt(e,n){this.value=this.value.substr(0,e)+n+this.value.substr(e+1)}substring(e,n){return this.value.substring(e,n)}setLengthToZero(){this.value=""}toString(){return this.value}insert(e,n){this.value=this.value.substr(0,e)+n+this.value.substr(e+n.length)}}class ee{constructor(e,n,i,s){if(this.width=e,this.height=n,this.rowSize=i,this.bits=s,n==null&&(n=e),this.height=n,e<1||n<1)throw new E("Both dimensions must be greater than 0");i==null&&(i=Math.floor((e+31)/32)),this.rowSize=i,s==null&&(this.bits=new Int32Array(this.rowSize*this.height))}static parseFromBooleanArray(e){const n=e.length,i=e[0].length,s=new ee(i,n);for(let a=0;a<n;a++){const l=e[a];for(let d=0;d<i;d++)l[d]&&s.set(d,a)}return s}static parseFromString(e,n,i){if(e===null)throw new E("stringRepresentation cannot be null");const s=new Array(e.length);let a=0,l=0,d=-1,h=0,g=0;for(;g<e.length;)if(e.charAt(g)===`
58
- `||e.charAt(g)==="\r"){if(a>l){if(d===-1)d=a-l;else if(a-l!==d)throw new E("row lengths do not match");l=a,h++}g++}else if(e.substring(g,g+n.length)===n)g+=n.length,s[a]=!0,a++;else if(e.substring(g,g+i.length)===i)g+=i.length,s[a]=!1,a++;else throw new E("illegal character encountered: "+e.substring(g));if(a>l){if(d===-1)d=a-l;else if(a-l!==d)throw new E("row lengths do not match");h++}const w=new ee(d,h);for(let b=0;b<a;b++)s[b]&&w.set(Math.floor(b%d),Math.floor(b/d));return w}get(e,n){const i=n*this.rowSize+Math.floor(e/32);return(this.bits[i]>>>(e&31)&1)!==0}set(e,n){const i=n*this.rowSize+Math.floor(e/32);this.bits[i]|=1<<(e&31)&4294967295}unset(e,n){const i=n*this.rowSize+Math.floor(e/32);this.bits[i]&=~(1<<(e&31)&4294967295)}flip(e,n){const i=n*this.rowSize+Math.floor(e/32);this.bits[i]^=1<<(e&31)&4294967295}xor(e){if(this.width!==e.getWidth()||this.height!==e.getHeight()||this.rowSize!==e.getRowSize())throw new E("input matrix dimensions do not match");const n=new $(Math.floor(this.width/32)+1),i=this.rowSize,s=this.bits;for(let a=0,l=this.height;a<l;a++){const d=a*i,h=e.getRow(a,n).getBitArray();for(let g=0;g<i;g++)s[d+g]^=h[g]}}clear(){const e=this.bits,n=e.length;for(let i=0;i<n;i++)e[i]=0}setRegion(e,n,i,s){if(n<0||e<0)throw new E("Left and top must be nonnegative");if(s<1||i<1)throw new E("Height and width must be at least 1");const a=e+i,l=n+s;if(l>this.height||a>this.width)throw new E("The region must fit inside the matrix");const d=this.rowSize,h=this.bits;for(let g=n;g<l;g++){const w=g*d;for(let b=e;b<a;b++)h[w+Math.floor(b/32)]|=1<<(b&31)&4294967295}}getRow(e,n){n==null||n.getSize()<this.width?n=new $(this.width):n.clear();const i=this.rowSize,s=this.bits,a=e*i;for(let l=0;l<i;l++)n.setBulk(l*32,s[a+l]);return n}setRow(e,n){R.arraycopy(n.getBitArray(),0,this.bits,e*this.rowSize,this.rowSize)}rotate180(){const e=this.getWidth(),n=this.getHeight();let i=new $(e),s=new $(e);for(let a=0,l=Math.floor((n+1)/2);a<l;a++)i=this.getRow(a,i),s=this.getRow(n-1-a,s),i.reverse(),s.reverse(),this.setRow(a,s),this.setRow(n-1-a,i)}getEnclosingRectangle(){const e=this.width,n=this.height,i=this.rowSize,s=this.bits;let a=e,l=n,d=-1,h=-1;for(let g=0;g<n;g++)for(let w=0;w<i;w++){const b=s[g*i+w];if(b!==0){if(g<l&&(l=g),g>h&&(h=g),w*32<a){let I=0;for(;(b<<31-I&4294967295)===0;)I++;w*32+I<a&&(a=w*32+I)}if(w*32+31>d){let I=31;for(;!(b>>>I);)I--;w*32+I>d&&(d=w*32+I)}}}return d<a||h<l?null:Int32Array.from([a,l,d-a+1,h-l+1])}getTopLeftOnBit(){const e=this.rowSize,n=this.bits;let i=0;for(;i<n.length&&n[i]===0;)i++;if(i===n.length)return null;const s=i/e;let a=i%e*32;const l=n[i];let d=0;for(;(l<<31-d&4294967295)===0;)d++;return a+=d,Int32Array.from([a,s])}getBottomRightOnBit(){const e=this.rowSize,n=this.bits;let i=n.length-1;for(;i>=0&&n[i]===0;)i--;if(i<0)return null;const s=Math.floor(i/e);let a=Math.floor(i%e)*32;const l=n[i];let d=31;for(;!(l>>>d);)d--;return a+=d,Int32Array.from([a,s])}getWidth(){return this.width}getHeight(){return this.height}getRowSize(){return this.rowSize}equals(e){if(!(e instanceof ee))return!1;const n=e;return this.width===n.width&&this.height===n.height&&this.rowSize===n.rowSize&&Z.equals(this.bits,n.bits)}hashCode(){let e=this.width;return e=31*e+this.width,e=31*e+this.height,e=31*e+this.rowSize,e=31*e+Z.hashCode(this.bits),e}toString(e="X ",n=" ",i=`
59
- `){return this.buildToString(e,n,i)}buildToString(e,n,i){let s=new oe;for(let a=0,l=this.height;a<l;a++){for(let d=0,h=this.width;d<h;d++)s.append(this.get(d,a)?e:n);s.append(i)}return s.toString()}clone(){return new ee(this.width,this.height,this.rowSize,this.bits.slice())}}class P extends m{static getNotFoundInstance(){return new P}}P.kind="NotFoundException";class H extends M{constructor(e){super(e),this.luminances=H.EMPTY,this.buckets=new Int32Array(H.LUMINANCE_BUCKETS)}getBlackRow(e,n){const i=this.getLuminanceSource(),s=i.getWidth();n==null||n.getSize()<s?n=new $(s):n.clear(),this.initArrays(s);const a=i.getRow(e,this.luminances),l=this.buckets;for(let h=0;h<s;h++)l[(a[h]&255)>>H.LUMINANCE_SHIFT]++;const d=H.estimateBlackPoint(l);if(s<3)for(let h=0;h<s;h++)(a[h]&255)<d&&n.set(h);else{let h=a[0]&255,g=a[1]&255;for(let w=1;w<s-1;w++){const b=a[w+1]&255;(g*4-h-b)/2<d&&n.set(w),h=g,g=b}}return n}getBlackMatrix(){const e=this.getLuminanceSource(),n=e.getWidth(),i=e.getHeight(),s=new ee(n,i);this.initArrays(n);const a=this.buckets;for(let h=1;h<5;h++){const g=Math.floor(i*h/5),w=e.getRow(g,this.luminances),b=Math.floor(n*4/5);for(let I=Math.floor(n/5);I<b;I++){const N=w[I]&255;a[N>>H.LUMINANCE_SHIFT]++}}const l=H.estimateBlackPoint(a),d=e.getMatrix();for(let h=0;h<i;h++){const g=h*n;for(let w=0;w<n;w++)(d[g+w]&255)<l&&s.set(w,h)}return s}createBinarizer(e){return new H(e)}initArrays(e){this.luminances.length<e&&(this.luminances=new Uint8ClampedArray(e));const n=this.buckets;for(let i=0;i<H.LUMINANCE_BUCKETS;i++)n[i]=0}static estimateBlackPoint(e){const n=e.length;let i=0,s=0,a=0;for(let w=0;w<n;w++)e[w]>a&&(s=w,a=e[w]),e[w]>i&&(i=e[w]);let l=0,d=0;for(let w=0;w<n;w++){const b=w-s,I=e[w]*b*b;I>d&&(l=w,d=I)}if(s>l){const w=s;s=l,l=w}if(l-s<=n/16)throw new P;let h=l-1,g=-1;for(let w=l-1;w>s;w--){const b=w-s,I=b*b*(l-w)*(i-e[w]);I>g&&(h=w,g=I)}return h<<H.LUMINANCE_SHIFT}}H.LUMINANCE_BITS=5,H.LUMINANCE_SHIFT=8-H.LUMINANCE_BITS,H.LUMINANCE_BUCKETS=1<<H.LUMINANCE_BITS,H.EMPTY=Uint8ClampedArray.from([0]);class re extends H{constructor(e){super(e),this.matrix=null}getBlackMatrix(){if(this.matrix!==null)return this.matrix;const e=this.getLuminanceSource(),n=e.getWidth(),i=e.getHeight();if(n>=re.MINIMUM_DIMENSION&&i>=re.MINIMUM_DIMENSION){const s=e.getMatrix();let a=n>>re.BLOCK_SIZE_POWER;(n&re.BLOCK_SIZE_MASK)!==0&&a++;let l=i>>re.BLOCK_SIZE_POWER;(i&re.BLOCK_SIZE_MASK)!==0&&l++;const d=re.calculateBlackPoints(s,a,l,n,i),h=new ee(n,i);re.calculateThresholdForBlock(s,a,l,n,i,d,h),this.matrix=h}else this.matrix=super.getBlackMatrix();return this.matrix}createBinarizer(e){return new re(e)}static calculateThresholdForBlock(e,n,i,s,a,l,d){const h=a-re.BLOCK_SIZE,g=s-re.BLOCK_SIZE;for(let w=0;w<i;w++){let b=w<<re.BLOCK_SIZE_POWER;b>h&&(b=h);const I=re.cap(w,2,i-3);for(let N=0;N<n;N++){let F=N<<re.BLOCK_SIZE_POWER;F>g&&(F=g);const U=re.cap(N,2,n-3);let W=0;for(let fe=-2;fe<=2;fe++){const he=l[I+fe];W+=he[U-2]+he[U-1]+he[U]+he[U+1]+he[U+2]}const K=W/25;re.thresholdBlock(e,F,b,K,s,d)}}}static cap(e,n,i){return e<n?n:e>i?i:e}static thresholdBlock(e,n,i,s,a,l){for(let d=0,h=i*a+n;d<re.BLOCK_SIZE;d++,h+=a)for(let g=0;g<re.BLOCK_SIZE;g++)(e[h+g]&255)<=s&&l.set(n+g,i+d)}static calculateBlackPoints(e,n,i,s,a){const l=a-re.BLOCK_SIZE,d=s-re.BLOCK_SIZE,h=new Array(i);for(let g=0;g<i;g++){h[g]=new Int32Array(n);let w=g<<re.BLOCK_SIZE_POWER;w>l&&(w=l);for(let b=0;b<n;b++){let I=b<<re.BLOCK_SIZE_POWER;I>d&&(I=d);let N=0,F=255,U=0;for(let K=0,fe=w*s+I;K<re.BLOCK_SIZE;K++,fe+=s){for(let he=0;he<re.BLOCK_SIZE;he++){const ce=e[fe+he]&255;N+=ce,ce<F&&(F=ce),ce>U&&(U=ce)}if(U-F>re.MIN_DYNAMIC_RANGE)for(K++,fe+=s;K<re.BLOCK_SIZE;K++,fe+=s)for(let he=0;he<re.BLOCK_SIZE;he++)N+=e[fe+he]&255}let W=N>>re.BLOCK_SIZE_POWER*2;if(U-F<=re.MIN_DYNAMIC_RANGE&&(W=F/2,g>0&&b>0)){const K=(h[g-1][b]+2*h[g][b-1]+h[g-1][b-1])/4;F<K&&(W=K)}h[g][b]=W}}return h}}re.BLOCK_SIZE_POWER=3,re.BLOCK_SIZE=1<<re.BLOCK_SIZE_POWER,re.BLOCK_SIZE_MASK=re.BLOCK_SIZE-1,re.MINIMUM_DIMENSION=re.BLOCK_SIZE*5,re.MIN_DYNAMIC_RANGE=24;class te{constructor(e,n){this.width=e,this.height=n}getWidth(){return this.width}getHeight(){return this.height}isCropSupported(){return!1}crop(e,n,i,s){throw new Ee("This luminance source does not support cropping.")}isRotateSupported(){return!1}rotateCounterClockwise(){throw new Ee("This luminance source does not support rotation by 90 degrees.")}rotateCounterClockwise45(){throw new Ee("This luminance source does not support rotation by 45 degrees.")}toString(){const e=new Uint8ClampedArray(this.width);let n=new oe;for(let i=0;i<this.height;i++){const s=this.getRow(i,e);for(let a=0;a<this.width;a++){const l=s[a]&255;let d;l<64?d="#":l<128?d="+":l<192?d=".":d=" ",n.append(d)}n.append(`
60
- `)}return n.toString()}}class we extends te{constructor(e){super(e.getWidth(),e.getHeight()),this.delegate=e}getRow(e,n){const i=this.delegate.getRow(e,n),s=this.getWidth();for(let a=0;a<s;a++)i[a]=255-(i[a]&255);return i}getMatrix(){const e=this.delegate.getMatrix(),n=this.getWidth()*this.getHeight(),i=new Uint8ClampedArray(n);for(let s=0;s<n;s++)i[s]=255-(e[s]&255);return i}isCropSupported(){return this.delegate.isCropSupported()}crop(e,n,i,s){return new we(this.delegate.crop(e,n,i,s))}isRotateSupported(){return this.delegate.isRotateSupported()}invert(){return this.delegate}rotateCounterClockwise(){return new we(this.delegate.rotateCounterClockwise())}rotateCounterClockwise45(){return new we(this.delegate.rotateCounterClockwise45())}}class se extends te{constructor(e){super(e.width,e.height),this.canvas=e,this.tempCanvasElement=null,this.buffer=se.makeBufferFromCanvasImageData(e)}static makeBufferFromCanvasImageData(e){const n=e.getContext("2d").getImageData(0,0,e.width,e.height);return se.toGrayscaleBuffer(n.data,e.width,e.height)}static toGrayscaleBuffer(e,n,i){const s=new Uint8ClampedArray(n*i);for(let a=0,l=0,d=e.length;a<d;a+=4,l++){let h;if(e[a+3]===0)h=255;else{const w=e[a],b=e[a+1],I=e[a+2];h=306*w+601*b+117*I+512>>10}s[l]=h}return s}getRow(e,n){if(e<0||e>=this.getHeight())throw new E("Requested row is outside the image: "+e);const i=this.getWidth(),s=e*i;return n===null?n=this.buffer.slice(s,s+i):(n.length<i&&(n=new Uint8ClampedArray(i)),n.set(this.buffer.slice(s,s+i))),n}getMatrix(){return this.buffer}isCropSupported(){return!0}crop(e,n,i,s){return super.crop(e,n,i,s),this}isRotateSupported(){return!0}rotateCounterClockwise(){return this.rotate(-90),this}rotateCounterClockwise45(){return this.rotate(-45),this}getTempCanvasElement(){if(this.tempCanvasElement===null){const e=this.canvas.ownerDocument.createElement("canvas");e.width=this.canvas.width,e.height=this.canvas.height,this.tempCanvasElement=e}return this.tempCanvasElement}rotate(e){const n=this.getTempCanvasElement(),i=n.getContext("2d"),s=e*se.DEGREE_TO_RADIANS,a=this.canvas.width,l=this.canvas.height,d=Math.ceil(Math.abs(Math.cos(s))*a+Math.abs(Math.sin(s))*l),h=Math.ceil(Math.abs(Math.sin(s))*a+Math.abs(Math.cos(s))*l);return n.width=d,n.height=h,i.translate(d/2,h/2),i.rotate(s),i.drawImage(this.canvas,a/-2,l/-2),this.buffer=se.makeBufferFromCanvasImageData(n),this}invert(){return new we(this)}}se.DEGREE_TO_RADIANS=Math.PI/180;class ye{constructor(e,n,i){this.deviceId=e,this.label=n,this.kind="videoinput",this.groupId=i||void 0}toJSON(){return{kind:this.kind,groupId:this.groupId,deviceId:this.deviceId,label:this.label}}}var _e=(globalThis||Ci||self||window||void 0)&&(globalThis||Ci||self||window||void 0).__awaiter||function(C,e,n,i){function s(a){return a instanceof n?a:new n(function(l){l(a)})}return new(n||(n=Promise))(function(a,l){function d(w){try{g(i.next(w))}catch(b){l(b)}}function h(w){try{g(i.throw(w))}catch(b){l(b)}}function g(w){w.done?a(w.value):s(w.value).then(d,h)}g((i=i.apply(C,e||[])).next())})};class Ze{constructor(e,n=500,i){this.reader=e,this.timeBetweenScansMillis=n,this._hints=i,this._stopContinuousDecode=!1,this._stopAsyncDecode=!1,this._timeBetweenDecodingAttempts=0}get hasNavigator(){return typeof navigator<"u"}get isMediaDevicesSuported(){return this.hasNavigator&&!!navigator.mediaDevices}get canEnumerateDevices(){return!!(this.isMediaDevicesSuported&&navigator.mediaDevices.enumerateDevices)}get timeBetweenDecodingAttempts(){return this._timeBetweenDecodingAttempts}set timeBetweenDecodingAttempts(e){this._timeBetweenDecodingAttempts=e<0?0:e}set hints(e){this._hints=e||null}get hints(){return this._hints}listVideoInputDevices(){return _e(this,void 0,void 0,function*(){if(!this.hasNavigator)throw new Error("Can't enumerate devices, navigator is not present.");if(!this.canEnumerateDevices)throw new Error("Can't enumerate devices, method not supported.");const e=yield navigator.mediaDevices.enumerateDevices(),n=[];for(const i of e){const s=i.kind==="video"?"videoinput":i.kind;if(s!=="videoinput")continue;const a=i.deviceId||i.id,l=i.label||`Video device ${n.length+1}`,d=i.groupId,h={deviceId:a,label:l,kind:s,groupId:d};n.push(h)}return n})}getVideoInputDevices(){return _e(this,void 0,void 0,function*(){return(yield this.listVideoInputDevices()).map(n=>new ye(n.deviceId,n.label))})}findDeviceById(e){return _e(this,void 0,void 0,function*(){const n=yield this.listVideoInputDevices();return n?n.find(i=>i.deviceId===e):null})}decodeFromInputVideoDevice(e,n){return _e(this,void 0,void 0,function*(){return yield this.decodeOnceFromVideoDevice(e,n)})}decodeOnceFromVideoDevice(e,n){return _e(this,void 0,void 0,function*(){this.reset();let i;e?i={deviceId:{exact:e}}:i={facingMode:"environment"};const s={video:i};return yield this.decodeOnceFromConstraints(s,n)})}decodeOnceFromConstraints(e,n){return _e(this,void 0,void 0,function*(){const i=yield navigator.mediaDevices.getUserMedia(e);return yield this.decodeOnceFromStream(i,n)})}decodeOnceFromStream(e,n){return _e(this,void 0,void 0,function*(){this.reset();const i=yield this.attachStreamToVideo(e,n);return yield this.decodeOnce(i)})}decodeFromInputVideoDeviceContinuously(e,n,i){return _e(this,void 0,void 0,function*(){return yield this.decodeFromVideoDevice(e,n,i)})}decodeFromVideoDevice(e,n,i){return _e(this,void 0,void 0,function*(){let s;e?s={deviceId:{exact:e}}:s={facingMode:"environment"};const a={video:s};return yield this.decodeFromConstraints(a,n,i)})}decodeFromConstraints(e,n,i){return _e(this,void 0,void 0,function*(){const s=yield navigator.mediaDevices.getUserMedia(e);return yield this.decodeFromStream(s,n,i)})}decodeFromStream(e,n,i){return _e(this,void 0,void 0,function*(){this.reset();const s=yield this.attachStreamToVideo(e,n);return yield this.decodeContinuously(s,i)})}stopAsyncDecode(){this._stopAsyncDecode=!0}stopContinuousDecode(){this._stopContinuousDecode=!0}attachStreamToVideo(e,n){return _e(this,void 0,void 0,function*(){const i=this.prepareVideoElement(n);return this.addVideoSource(i,e),this.videoElement=i,this.stream=e,yield this.playVideoOnLoadAsync(i),i})}playVideoOnLoadAsync(e){return new Promise((n,i)=>this.playVideoOnLoad(e,()=>n()))}playVideoOnLoad(e,n){this.videoEndedListener=()=>this.stopStreams(),this.videoCanPlayListener=()=>this.tryPlayVideo(e),e.addEventListener("ended",this.videoEndedListener),e.addEventListener("canplay",this.videoCanPlayListener),e.addEventListener("playing",n),this.tryPlayVideo(e)}isVideoPlaying(e){return e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>2}tryPlayVideo(e){return _e(this,void 0,void 0,function*(){if(this.isVideoPlaying(e)){console.warn("Trying to play video that is already playing.");return}try{yield e.play()}catch{console.warn("It was not possible to play the video.")}})}getMediaElement(e,n){const i=document.getElementById(e);if(!i)throw new A(`element with id '${e}' not found`);if(i.nodeName.toLowerCase()!==n.toLowerCase())throw new A(`element with id '${e}' must be an ${n} element`);return i}decodeFromImage(e,n){if(!e&&!n)throw new A("either imageElement with a src set or an url must be provided");return n&&!e?this.decodeFromImageUrl(n):this.decodeFromImageElement(e)}decodeFromVideo(e,n){if(!e&&!n)throw new A("Either an element with a src set or an URL must be provided");return n&&!e?this.decodeFromVideoUrl(n):this.decodeFromVideoElement(e)}decodeFromVideoContinuously(e,n,i){if(e===void 0&&n===void 0)throw new A("Either an element with a src set or an URL must be provided");return n&&!e?this.decodeFromVideoUrlContinuously(n,i):this.decodeFromVideoElementContinuously(e,i)}decodeFromImageElement(e){if(!e)throw new A("An image element must be provided.");this.reset();const n=this.prepareImageElement(e);this.imageElement=n;let i;return this.isImageLoaded(n)?i=this.decodeOnce(n,!1,!0):i=this._decodeOnLoadImage(n),i}decodeFromVideoElement(e){const n=this._decodeFromVideoElementSetup(e);return this._decodeOnLoadVideo(n)}decodeFromVideoElementContinuously(e,n){const i=this._decodeFromVideoElementSetup(e);return this._decodeOnLoadVideoContinuously(i,n)}_decodeFromVideoElementSetup(e){if(!e)throw new A("A video element must be provided.");this.reset();const n=this.prepareVideoElement(e);return this.videoElement=n,n}decodeFromImageUrl(e){if(!e)throw new A("An URL must be provided.");this.reset();const n=this.prepareImageElement();this.imageElement=n;const i=this._decodeOnLoadImage(n);return n.src=e,i}decodeFromVideoUrl(e){if(!e)throw new A("An URL must be provided.");this.reset();const n=this.prepareVideoElement(),i=this.decodeFromVideoElement(n);return n.src=e,i}decodeFromVideoUrlContinuously(e,n){if(!e)throw new A("An URL must be provided.");this.reset();const i=this.prepareVideoElement(),s=this.decodeFromVideoElementContinuously(i,n);return i.src=e,s}_decodeOnLoadImage(e){return new Promise((n,i)=>{this.imageLoadedListener=()=>this.decodeOnce(e,!1,!0).then(n,i),e.addEventListener("load",this.imageLoadedListener)})}_decodeOnLoadVideo(e){return _e(this,void 0,void 0,function*(){return yield this.playVideoOnLoadAsync(e),yield this.decodeOnce(e)})}_decodeOnLoadVideoContinuously(e,n){return _e(this,void 0,void 0,function*(){yield this.playVideoOnLoadAsync(e),this.decodeContinuously(e,n)})}isImageLoaded(e){return!(!e.complete||e.naturalWidth===0)}prepareImageElement(e){let n;return typeof e>"u"&&(n=document.createElement("img"),n.width=200,n.height=200),typeof e=="string"&&(n=this.getMediaElement(e,"img")),e instanceof HTMLImageElement&&(n=e),n}prepareVideoElement(e){let n;return!e&&typeof document<"u"&&(n=document.createElement("video"),n.width=200,n.height=200),typeof e=="string"&&(n=this.getMediaElement(e,"video")),e instanceof HTMLVideoElement&&(n=e),n.setAttribute("autoplay","true"),n.setAttribute("muted","true"),n.setAttribute("playsinline","true"),n}decodeOnce(e,n=!0,i=!0){this._stopAsyncDecode=!1;const s=(a,l)=>{if(this._stopAsyncDecode){l(new P("Video stream has ended before any code could be detected.")),this._stopAsyncDecode=void 0;return}try{const d=this.decode(e);a(d)}catch(d){const h=n&&d instanceof P,w=(d instanceof D||d instanceof V)&&i;if(h||w)return setTimeout(s,this._timeBetweenDecodingAttempts,a,l);l(d)}};return new Promise((a,l)=>s(a,l))}decodeContinuously(e,n){this._stopContinuousDecode=!1;const i=()=>{if(this._stopContinuousDecode){this._stopContinuousDecode=void 0;return}try{const s=this.decode(e);n(s,null),setTimeout(i,this.timeBetweenScansMillis)}catch(s){n(null,s);const a=s instanceof D||s instanceof V,l=s instanceof P;(a||l)&&setTimeout(i,this._timeBetweenDecodingAttempts)}};i()}decode(e){const n=this.createBinaryBitmap(e);return this.decodeBitmap(n)}_isHTMLVideoElement(e){return e.videoWidth!==0}drawFrameOnCanvas(e,n,i){n||(n={sx:0,sy:0,sWidth:e.videoWidth,sHeight:e.videoHeight,dx:0,dy:0,dWidth:e.videoWidth,dHeight:e.videoHeight}),i||(i=this.captureCanvasContext),i.drawImage(e,n.sx,n.sy,n.sWidth,n.sHeight,n.dx,n.dy,n.dWidth,n.dHeight)}drawImageOnCanvas(e,n,i=this.captureCanvasContext){n||(n={sx:0,sy:0,sWidth:e.naturalWidth,sHeight:e.naturalHeight,dx:0,dy:0,dWidth:e.naturalWidth,dHeight:e.naturalHeight}),i||(i=this.captureCanvasContext),i.drawImage(e,n.sx,n.sy,n.sWidth,n.sHeight,n.dx,n.dy,n.dWidth,n.dHeight)}createBinaryBitmap(e){this.getCaptureCanvasContext(e),this._isHTMLVideoElement(e)?this.drawFrameOnCanvas(e):this.drawImageOnCanvas(e);const n=this.getCaptureCanvas(e),i=new se(n),s=new re(i);return new B(s)}getCaptureCanvasContext(e){if(!this.captureCanvasContext){const i=this.getCaptureCanvas(e).getContext("2d");this.captureCanvasContext=i}return this.captureCanvasContext}getCaptureCanvas(e){if(!this.captureCanvas){const n=this.createCaptureCanvas(e);this.captureCanvas=n}return this.captureCanvas}decodeBitmap(e){return this.reader.decode(e,this._hints)}createCaptureCanvas(e){if(typeof document>"u")return this._destroyCaptureCanvas(),null;const n=document.createElement("canvas");let i,s;return typeof e<"u"&&(e instanceof HTMLVideoElement?(i=e.videoWidth,s=e.videoHeight):e instanceof HTMLImageElement&&(i=e.naturalWidth||e.width,s=e.naturalHeight||e.height)),n.style.width=i+"px",n.style.height=s+"px",n.width=i,n.height=s,n}stopStreams(){this.stream&&(this.stream.getVideoTracks().forEach(e=>e.stop()),this.stream=void 0),this._stopAsyncDecode===!1&&this.stopAsyncDecode(),this._stopContinuousDecode===!1&&this.stopContinuousDecode()}reset(){this.stopStreams(),this._destroyVideoElement(),this._destroyImageElement(),this._destroyCaptureCanvas()}_destroyVideoElement(){this.videoElement&&(typeof this.videoEndedListener<"u"&&this.videoElement.removeEventListener("ended",this.videoEndedListener),typeof this.videoPlayingEventListener<"u"&&this.videoElement.removeEventListener("playing",this.videoPlayingEventListener),typeof this.videoCanPlayListener<"u"&&this.videoElement.removeEventListener("loadedmetadata",this.videoCanPlayListener),this.cleanVideoSource(this.videoElement),this.videoElement=void 0)}_destroyImageElement(){this.imageElement&&(this.imageLoadedListener!==void 0&&this.imageElement.removeEventListener("load",this.imageLoadedListener),this.imageElement.src=void 0,this.imageElement.removeAttribute("src"),this.imageElement=void 0)}_destroyCaptureCanvas(){this.captureCanvasContext=void 0,this.captureCanvas=void 0}addVideoSource(e,n){try{e.srcObject=n}catch{e.src=URL.createObjectURL(n)}}cleanVideoSource(e){try{e.srcObject=null}catch{e.src=""}this.videoElement.removeAttribute("src")}}class Ue{constructor(e,n,i=n==null?0:8*n.length,s,a,l=R.currentTimeMillis()){this.text=e,this.rawBytes=n,this.numBits=i,this.resultPoints=s,this.format=a,this.timestamp=l,this.text=e,this.rawBytes=n,i==null?this.numBits=n==null?0:8*n.length:this.numBits=i,this.resultPoints=s,this.format=a,this.resultMetadata=null,l==null?this.timestamp=R.currentTimeMillis():this.timestamp=l}getText(){return this.text}getRawBytes(){return this.rawBytes}getNumBits(){return this.numBits}getResultPoints(){return this.resultPoints}getBarcodeFormat(){return this.format}getResultMetadata(){return this.resultMetadata}putMetadata(e,n){this.resultMetadata===null&&(this.resultMetadata=new Map),this.resultMetadata.set(e,n)}putAllMetadata(e){e!==null&&(this.resultMetadata===null?this.resultMetadata=e:this.resultMetadata=new Map(e))}addResultPoints(e){const n=this.resultPoints;if(n===null)this.resultPoints=e;else if(e!==null&&e.length>0){const i=new Array(n.length+e.length);R.arraycopy(n,0,i,0,n.length),R.arraycopy(e,0,i,n.length,e.length),this.resultPoints=i}}getTimestamp(){return this.timestamp}toString(){return this.text}}var xe;(function(C){C[C.AZTEC=0]="AZTEC",C[C.CODABAR=1]="CODABAR",C[C.CODE_39=2]="CODE_39",C[C.CODE_93=3]="CODE_93",C[C.CODE_128=4]="CODE_128",C[C.DATA_MATRIX=5]="DATA_MATRIX",C[C.EAN_8=6]="EAN_8",C[C.EAN_13=7]="EAN_13",C[C.ITF=8]="ITF",C[C.MAXICODE=9]="MAXICODE",C[C.PDF_417=10]="PDF_417",C[C.QR_CODE=11]="QR_CODE",C[C.RSS_14=12]="RSS_14",C[C.RSS_EXPANDED=13]="RSS_EXPANDED",C[C.UPC_A=14]="UPC_A",C[C.UPC_E=15]="UPC_E",C[C.UPC_EAN_EXTENSION=16]="UPC_EAN_EXTENSION"})(xe||(xe={}));var ge=xe,ft;(function(C){C[C.OTHER=0]="OTHER",C[C.ORIENTATION=1]="ORIENTATION",C[C.BYTE_SEGMENTS=2]="BYTE_SEGMENTS",C[C.ERROR_CORRECTION_LEVEL=3]="ERROR_CORRECTION_LEVEL",C[C.ISSUE_NUMBER=4]="ISSUE_NUMBER",C[C.SUGGESTED_PRICE=5]="SUGGESTED_PRICE",C[C.POSSIBLE_COUNTRY=6]="POSSIBLE_COUNTRY",C[C.UPC_EAN_EXTENSION=7]="UPC_EAN_EXTENSION",C[C.PDF417_EXTRA_METADATA=8]="PDF417_EXTRA_METADATA",C[C.STRUCTURED_APPEND_SEQUENCE=9]="STRUCTURED_APPEND_SEQUENCE",C[C.STRUCTURED_APPEND_PARITY=10]="STRUCTURED_APPEND_PARITY"})(ft||(ft={}));var Se=ft;class Nt{constructor(e,n,i,s,a=-1,l=-1){this.rawBytes=e,this.text=n,this.byteSegments=i,this.ecLevel=s,this.structuredAppendSequenceNumber=a,this.structuredAppendParity=l,this.numBits=e==null?0:8*e.length}getRawBytes(){return this.rawBytes}getNumBits(){return this.numBits}setNumBits(e){this.numBits=e}getText(){return this.text}getByteSegments(){return this.byteSegments}getECLevel(){return this.ecLevel}getErrorsCorrected(){return this.errorsCorrected}setErrorsCorrected(e){this.errorsCorrected=e}getErasures(){return this.erasures}setErasures(e){this.erasures=e}getOther(){return this.other}setOther(e){this.other=e}hasStructuredAppend(){return this.structuredAppendParity>=0&&this.structuredAppendSequenceNumber>=0}getStructuredAppendParity(){return this.structuredAppendParity}getStructuredAppendSequenceNumber(){return this.structuredAppendSequenceNumber}}class Qe{exp(e){return this.expTable[e]}log(e){if(e===0)throw new E;return this.logTable[e]}static addOrSubtract(e,n){return e^n}}class et{constructor(e,n){if(n.length===0)throw new E;this.field=e;const i=n.length;if(i>1&&n[0]===0){let s=1;for(;s<i&&n[s]===0;)s++;s===i?this.coefficients=Int32Array.from([0]):(this.coefficients=new Int32Array(i-s),R.arraycopy(n,s,this.coefficients,0,this.coefficients.length))}else this.coefficients=n}getCoefficients(){return this.coefficients}getDegree(){return this.coefficients.length-1}isZero(){return this.coefficients[0]===0}getCoefficient(e){return this.coefficients[this.coefficients.length-1-e]}evaluateAt(e){if(e===0)return this.getCoefficient(0);const n=this.coefficients;let i;if(e===1){i=0;for(let l=0,d=n.length;l!==d;l++){const h=n[l];i=Qe.addOrSubtract(i,h)}return i}i=n[0];const s=n.length,a=this.field;for(let l=1;l<s;l++)i=Qe.addOrSubtract(a.multiply(e,i),n[l]);return i}addOrSubtract(e){if(!this.field.equals(e.field))throw new E("GenericGFPolys do not have same GenericGF field");if(this.isZero())return e;if(e.isZero())return this;let n=this.coefficients,i=e.coefficients;if(n.length>i.length){const l=n;n=i,i=l}let s=new Int32Array(i.length);const a=i.length-n.length;R.arraycopy(i,0,s,0,a);for(let l=a;l<i.length;l++)s[l]=Qe.addOrSubtract(n[l-a],i[l]);return new et(this.field,s)}multiply(e){if(!this.field.equals(e.field))throw new E("GenericGFPolys do not have same GenericGF field");if(this.isZero()||e.isZero())return this.field.getZero();const n=this.coefficients,i=n.length,s=e.coefficients,a=s.length,l=new Int32Array(i+a-1),d=this.field;for(let h=0;h<i;h++){const g=n[h];for(let w=0;w<a;w++)l[h+w]=Qe.addOrSubtract(l[h+w],d.multiply(g,s[w]))}return new et(d,l)}multiplyScalar(e){if(e===0)return this.field.getZero();if(e===1)return this;const n=this.coefficients.length,i=this.field,s=new Int32Array(n),a=this.coefficients;for(let l=0;l<n;l++)s[l]=i.multiply(a[l],e);return new et(i,s)}multiplyByMonomial(e,n){if(e<0)throw new E;if(n===0)return this.field.getZero();const i=this.coefficients,s=i.length,a=new Int32Array(s+e),l=this.field;for(let d=0;d<s;d++)a[d]=l.multiply(i[d],n);return new et(l,a)}divide(e){if(!this.field.equals(e.field))throw new E("GenericGFPolys do not have same GenericGF field");if(e.isZero())throw new E("Divide by 0");const n=this.field;let i=n.getZero(),s=this;const a=e.getCoefficient(e.getDegree()),l=n.inverse(a);for(;s.getDegree()>=e.getDegree()&&!s.isZero();){const d=s.getDegree()-e.getDegree(),h=n.multiply(s.getCoefficient(s.getDegree()),l),g=e.multiplyByMonomial(d,h),w=n.buildMonomial(d,h);i=i.addOrSubtract(w),s=s.addOrSubtract(g)}return[i,s]}toString(){let e="";for(let n=this.getDegree();n>=0;n--){let i=this.getCoefficient(n);if(i!==0){if(i<0?(e+=" - ",i=-i):e.length>0&&(e+=" + "),n===0||i!==1){const s=this.field.log(i);s===0?e+="1":s===1?e+="a":(e+="a^",e+=s)}n!==0&&(n===1?e+="x":(e+="x^",e+=n))}}return e}}class jt extends m{}jt.kind="ArithmeticException";class Be extends Qe{constructor(e,n,i){super(),this.primitive=e,this.size=n,this.generatorBase=i;const s=new Int32Array(n);let a=1;for(let d=0;d<n;d++)s[d]=a,a*=2,a>=n&&(a^=e,a&=n-1);this.expTable=s;const l=new Int32Array(n);for(let d=0;d<n-1;d++)l[s[d]]=d;this.logTable=l,this.zero=new et(this,Int32Array.from([0])),this.one=new et(this,Int32Array.from([1]))}getZero(){return this.zero}getOne(){return this.one}buildMonomial(e,n){if(e<0)throw new E;if(n===0)return this.zero;const i=new Int32Array(e+1);return i[0]=n,new et(this,i)}inverse(e){if(e===0)throw new jt;return this.expTable[this.size-this.logTable[e]-1]}multiply(e,n){return e===0||n===0?0:this.expTable[(this.logTable[e]+this.logTable[n])%(this.size-1)]}getSize(){return this.size}getGeneratorBase(){return this.generatorBase}toString(){return"GF(0x"+z.toHexString(this.primitive)+","+this.size+")"}equals(e){return e===this}}Be.AZTEC_DATA_12=new Be(4201,4096,1),Be.AZTEC_DATA_10=new Be(1033,1024,1),Be.AZTEC_DATA_6=new Be(67,64,1),Be.AZTEC_PARAM=new Be(19,16,1),Be.QR_CODE_FIELD_256=new Be(285,256,0),Be.DATA_MATRIX_FIELD_256=new Be(301,256,1),Be.AZTEC_DATA_8=Be.DATA_MATRIX_FIELD_256,Be.MAXICODE_FIELD_64=Be.AZTEC_DATA_6;class hn extends m{}hn.kind="ReedSolomonException";class Vt extends m{}Vt.kind="IllegalStateException";class Cn{constructor(e){this.field=e}decode(e,n){const i=this.field,s=new et(i,e),a=new Int32Array(n);let l=!0;for(let N=0;N<n;N++){const F=s.evaluateAt(i.exp(N+i.getGeneratorBase()));a[a.length-1-N]=F,F!==0&&(l=!1)}if(l)return;const d=new et(i,a),h=this.runEuclideanAlgorithm(i.buildMonomial(n,1),d,n),g=h[0],w=h[1],b=this.findErrorLocations(g),I=this.findErrorMagnitudes(w,b);for(let N=0;N<b.length;N++){const F=e.length-1-i.log(b[N]);if(F<0)throw new hn("Bad error location");e[F]=Be.addOrSubtract(e[F],I[N])}}runEuclideanAlgorithm(e,n,i){if(e.getDegree()<n.getDegree()){const N=e;e=n,n=N}const s=this.field;let a=e,l=n,d=s.getZero(),h=s.getOne();for(;l.getDegree()>=(i/2|0);){let N=a,F=d;if(a=l,d=h,a.isZero())throw new hn("r_{i-1} was zero");l=N;let U=s.getZero();const W=a.getCoefficient(a.getDegree()),K=s.inverse(W);for(;l.getDegree()>=a.getDegree()&&!l.isZero();){const fe=l.getDegree()-a.getDegree(),he=s.multiply(l.getCoefficient(l.getDegree()),K);U=U.addOrSubtract(s.buildMonomial(fe,he)),l=l.addOrSubtract(a.multiplyByMonomial(fe,he))}if(h=U.multiply(d).addOrSubtract(F),l.getDegree()>=a.getDegree())throw new Vt("Division algorithm failed to reduce polynomial?")}const g=h.getCoefficient(0);if(g===0)throw new hn("sigmaTilde(0) was zero");const w=s.inverse(g),b=h.multiplyScalar(w),I=l.multiplyScalar(w);return[b,I]}findErrorLocations(e){const n=e.getDegree();if(n===1)return Int32Array.from([e.getCoefficient(1)]);const i=new Int32Array(n);let s=0;const a=this.field;for(let l=1;l<a.getSize()&&s<n;l++)e.evaluateAt(l)===0&&(i[s]=a.inverse(l),s++);if(s!==n)throw new hn("Error locator degree does not match number of roots");return i}findErrorMagnitudes(e,n){const i=n.length,s=new Int32Array(i),a=this.field;for(let l=0;l<i;l++){const d=a.inverse(n[l]);let h=1;for(let g=0;g<i;g++)if(l!==g){const w=a.multiply(n[g],d),b=(w&1)===0?w|1:w&-2;h=a.multiply(h,b)}s[l]=a.multiply(e.evaluateAt(d),a.inverse(h)),a.getGeneratorBase()!==0&&(s[l]=a.multiply(s[l],d))}return s}}var L;(function(C){C[C.UPPER=0]="UPPER",C[C.LOWER=1]="LOWER",C[C.MIXED=2]="MIXED",C[C.DIGIT=3]="DIGIT",C[C.PUNCT=4]="PUNCT",C[C.BINARY=5]="BINARY"})(L||(L={}));class ue{decode(e){this.ddata=e;let n=e.getBits(),i=this.extractBits(n),s=this.correctBits(i),a=ue.convertBoolArrayToByteArray(s),l=ue.getEncodedData(s),d=new Nt(a,l,null,null);return d.setNumBits(s.length),d}static highLevelDecode(e){return this.getEncodedData(e)}static getEncodedData(e){let n=e.length,i=L.UPPER,s=L.UPPER,a="",l=0;for(;l<n;)if(s===L.BINARY){if(n-l<5)break;let d=ue.readCode(e,l,5);if(l+=5,d===0){if(n-l<11)break;d=ue.readCode(e,l,11)+31,l+=11}for(let h=0;h<d;h++){if(n-l<8){l=n;break}const g=ue.readCode(e,l,8);a+=ne.castAsNonUtf8Char(g),l+=8}s=i}else{let d=s===L.DIGIT?4:5;if(n-l<d)break;let h=ue.readCode(e,l,d);l+=d;let g=ue.getCharacter(s,h);g.startsWith("CTRL_")?(i=s,s=ue.getTable(g.charAt(5)),g.charAt(6)==="L"&&(i=s)):(a+=g,s=i)}return a}static getTable(e){switch(e){case"L":return L.LOWER;case"P":return L.PUNCT;case"M":return L.MIXED;case"D":return L.DIGIT;case"B":return L.BINARY;case"U":default:return L.UPPER}}static getCharacter(e,n){switch(e){case L.UPPER:return ue.UPPER_TABLE[n];case L.LOWER:return ue.LOWER_TABLE[n];case L.MIXED:return ue.MIXED_TABLE[n];case L.PUNCT:return ue.PUNCT_TABLE[n];case L.DIGIT:return ue.DIGIT_TABLE[n];default:throw new Vt("Bad table")}}correctBits(e){let n,i;this.ddata.getNbLayers()<=2?(i=6,n=Be.AZTEC_DATA_6):this.ddata.getNbLayers()<=8?(i=8,n=Be.AZTEC_DATA_8):this.ddata.getNbLayers()<=22?(i=10,n=Be.AZTEC_DATA_10):(i=12,n=Be.AZTEC_DATA_12);let s=this.ddata.getNbDatablocks(),a=e.length/i;if(a<s)throw new V;let l=e.length%i,d=new Int32Array(a);for(let I=0;I<a;I++,l+=i)d[I]=ue.readCode(e,l,i);try{new Cn(n).decode(d,a-s)}catch(I){throw new V(I)}let h=(1<<i)-1,g=0;for(let I=0;I<s;I++){let N=d[I];if(N===0||N===h)throw new V;(N===1||N===h-1)&&g++}let w=new Array(s*i-g),b=0;for(let I=0;I<s;I++){let N=d[I];if(N===1||N===h-1)w.fill(N>1,b,b+i-1),b+=i-1;else for(let F=i-1;F>=0;--F)w[b++]=(N&1<<F)!==0}return w}extractBits(e){let n=this.ddata.isCompact(),i=this.ddata.getNbLayers(),s=(n?11:14)+i*4,a=new Int32Array(s),l=new Array(this.totalBitsInLayer(i,n));if(n)for(let d=0;d<a.length;d++)a[d]=d;else{let d=s+1+2*z.truncDivision(z.truncDivision(s,2)-1,15),h=s/2,g=z.truncDivision(d,2);for(let w=0;w<h;w++){let b=w+z.truncDivision(w,15);a[h-w-1]=g-b-1,a[h+w]=g+b+1}}for(let d=0,h=0;d<i;d++){let g=(i-d)*4+(n?9:12),w=d*2,b=s-1-w;for(let I=0;I<g;I++){let N=I*2;for(let F=0;F<2;F++)l[h+N+F]=e.get(a[w+F],a[w+I]),l[h+2*g+N+F]=e.get(a[w+I],a[b-F]),l[h+4*g+N+F]=e.get(a[b-F],a[b-I]),l[h+6*g+N+F]=e.get(a[b-I],a[w+F])}h+=g*8}return l}static readCode(e,n,i){let s=0;for(let a=n;a<n+i;a++)s<<=1,e[a]&&(s|=1);return s}static readByte(e,n){let i=e.length-n;return i>=8?ue.readCode(e,n,8):ue.readCode(e,n,i)<<8-i}static convertBoolArrayToByteArray(e){let n=new Uint8Array((e.length+7)/8);for(let i=0;i<n.length;i++)n[i]=ue.readByte(e,8*i);return n}totalBitsInLayer(e,n){return((n?88:112)+16*e)*e}}ue.UPPER_TABLE=["CTRL_PS"," ","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","CTRL_LL","CTRL_ML","CTRL_DL","CTRL_BS"],ue.LOWER_TABLE=["CTRL_PS"," ","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","CTRL_US","CTRL_ML","CTRL_DL","CTRL_BS"],ue.MIXED_TABLE=["CTRL_PS"," ","\\1","\\2","\\3","\\4","\\5","\\6","\\7","\b"," ",`
61
- `,"\\13","\f","\r","\\33","\\34","\\35","\\36","\\37","@","\\","^","_","`","|","~","\\177","CTRL_LL","CTRL_UL","CTRL_PL","CTRL_BS"],ue.PUNCT_TABLE=["","\r",`\r
62
- `,". ",", ",": ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/",":",";","<","=",">","?","[","]","{","}","CTRL_UL"],ue.DIGIT_TABLE=["CTRL_PS"," ","0","1","2","3","4","5","6","7","8","9",",",".","CTRL_UL","CTRL_US"];class Te{constructor(){}static round(e){return e===NaN?0:e<=Number.MIN_SAFE_INTEGER?Number.MIN_SAFE_INTEGER:e>=Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:e+(e<0?-.5:.5)|0}static distance(e,n,i,s){const a=e-i,l=n-s;return Math.sqrt(a*a+l*l)}static sum(e){let n=0;for(let i=0,s=e.length;i!==s;i++){const a=e[i];n+=a}return n}}class It{static floatToIntBits(e){return e}}It.MAX_VALUE=Number.MAX_SAFE_INTEGER;class be{constructor(e,n){this.x=e,this.y=n}getX(){return this.x}getY(){return this.y}equals(e){if(e instanceof be){const n=e;return this.x===n.x&&this.y===n.y}return!1}hashCode(){return 31*It.floatToIntBits(this.x)+It.floatToIntBits(this.y)}toString(){return"("+this.x+","+this.y+")"}static orderBestPatterns(e){const n=this.distance(e[0],e[1]),i=this.distance(e[1],e[2]),s=this.distance(e[0],e[2]);let a,l,d;if(i>=n&&i>=s?(l=e[0],a=e[1],d=e[2]):s>=i&&s>=n?(l=e[1],a=e[0],d=e[2]):(l=e[2],a=e[0],d=e[1]),this.crossProductZ(a,l,d)<0){const h=a;a=d,d=h}e[0]=a,e[1]=l,e[2]=d}static distance(e,n){return Te.distance(e.x,e.y,n.x,n.y)}static crossProductZ(e,n,i){const s=n.x,a=n.y;return(i.x-s)*(e.y-a)-(i.y-a)*(e.x-s)}}class fr{constructor(e,n){this.bits=e,this.points=n}getBits(){return this.bits}getPoints(){return this.points}}class si extends fr{constructor(e,n,i,s,a){super(e,n),this.compact=i,this.nbDatablocks=s,this.nbLayers=a}getNbLayers(){return this.nbLayers}getNbDatablocks(){return this.nbDatablocks}isCompact(){return this.compact}}class pn{constructor(e,n,i,s){this.image=e,this.height=e.getHeight(),this.width=e.getWidth(),n==null&&(n=pn.INIT_SIZE),i==null&&(i=e.getWidth()/2|0),s==null&&(s=e.getHeight()/2|0);const a=n/2|0;if(this.leftInit=i-a,this.rightInit=i+a,this.upInit=s-a,this.downInit=s+a,this.upInit<0||this.leftInit<0||this.downInit>=this.height||this.rightInit>=this.width)throw new P}detect(){let e=this.leftInit,n=this.rightInit,i=this.upInit,s=this.downInit,a=!1,l=!0,d=!1,h=!1,g=!1,w=!1,b=!1;const I=this.width,N=this.height;for(;l;){l=!1;let F=!0;for(;(F||!h)&&n<I;)F=this.containsBlackPoint(i,s,n,!1),F?(n++,l=!0,h=!0):h||n++;if(n>=I){a=!0;break}let U=!0;for(;(U||!g)&&s<N;)U=this.containsBlackPoint(e,n,s,!0),U?(s++,l=!0,g=!0):g||s++;if(s>=N){a=!0;break}let W=!0;for(;(W||!w)&&e>=0;)W=this.containsBlackPoint(i,s,e,!1),W?(e--,l=!0,w=!0):w||e--;if(e<0){a=!0;break}let K=!0;for(;(K||!b)&&i>=0;)K=this.containsBlackPoint(e,n,i,!0),K?(i--,l=!0,b=!0):b||i--;if(i<0){a=!0;break}l&&(d=!0)}if(!a&&d){const F=n-e;let U=null;for(let he=1;U===null&&he<F;he++)U=this.getBlackPointOnSegment(e,s-he,e+he,s);if(U==null)throw new P;let W=null;for(let he=1;W===null&&he<F;he++)W=this.getBlackPointOnSegment(e,i+he,e+he,i);if(W==null)throw new P;let K=null;for(let he=1;K===null&&he<F;he++)K=this.getBlackPointOnSegment(n,i+he,n-he,i);if(K==null)throw new P;let fe=null;for(let he=1;fe===null&&he<F;he++)fe=this.getBlackPointOnSegment(n,s-he,n-he,s);if(fe==null)throw new P;return this.centerEdges(fe,U,K,W)}else throw new P}getBlackPointOnSegment(e,n,i,s){const a=Te.round(Te.distance(e,n,i,s)),l=(i-e)/a,d=(s-n)/a,h=this.image;for(let g=0;g<a;g++){const w=Te.round(e+g*l),b=Te.round(n+g*d);if(h.get(w,b))return new be(w,b)}return null}centerEdges(e,n,i,s){const a=e.getX(),l=e.getY(),d=n.getX(),h=n.getY(),g=i.getX(),w=i.getY(),b=s.getX(),I=s.getY(),N=pn.CORR;return a<this.width/2?[new be(b-N,I+N),new be(d+N,h+N),new be(g-N,w-N),new be(a+N,l-N)]:[new be(b+N,I+N),new be(d+N,h-N),new be(g-N,w+N),new be(a-N,l-N)]}containsBlackPoint(e,n,i,s){const a=this.image;if(s){for(let l=e;l<=n;l++)if(a.get(l,i))return!0}else for(let l=e;l<=n;l++)if(a.get(i,l))return!0;return!1}}pn.INIT_SIZE=10,pn.CORR=1;class Tr{static checkAndNudgePoints(e,n){const i=e.getWidth(),s=e.getHeight();let a=!0;for(let l=0;l<n.length&&a;l+=2){const d=Math.floor(n[l]),h=Math.floor(n[l+1]);if(d<-1||d>i||h<-1||h>s)throw new P;a=!1,d===-1?(n[l]=0,a=!0):d===i&&(n[l]=i-1,a=!0),h===-1?(n[l+1]=0,a=!0):h===s&&(n[l+1]=s-1,a=!0)}a=!0;for(let l=n.length-2;l>=0&&a;l-=2){const d=Math.floor(n[l]),h=Math.floor(n[l+1]);if(d<-1||d>i||h<-1||h>s)throw new P;a=!1,d===-1?(n[l]=0,a=!0):d===i&&(n[l]=i-1,a=!0),h===-1?(n[l+1]=0,a=!0):h===s&&(n[l+1]=s-1,a=!0)}}}class en{constructor(e,n,i,s,a,l,d,h,g){this.a11=e,this.a21=n,this.a31=i,this.a12=s,this.a22=a,this.a32=l,this.a13=d,this.a23=h,this.a33=g}static quadrilateralToQuadrilateral(e,n,i,s,a,l,d,h,g,w,b,I,N,F,U,W){const K=en.quadrilateralToSquare(e,n,i,s,a,l,d,h);return en.squareToQuadrilateral(g,w,b,I,N,F,U,W).times(K)}transformPoints(e){const n=e.length,i=this.a11,s=this.a12,a=this.a13,l=this.a21,d=this.a22,h=this.a23,g=this.a31,w=this.a32,b=this.a33;for(let I=0;I<n;I+=2){const N=e[I],F=e[I+1],U=a*N+h*F+b;e[I]=(i*N+l*F+g)/U,e[I+1]=(s*N+d*F+w)/U}}transformPointsWithValues(e,n){const i=this.a11,s=this.a12,a=this.a13,l=this.a21,d=this.a22,h=this.a23,g=this.a31,w=this.a32,b=this.a33,I=e.length;for(let N=0;N<I;N++){const F=e[N],U=n[N],W=a*F+h*U+b;e[N]=(i*F+l*U+g)/W,n[N]=(s*F+d*U+w)/W}}static squareToQuadrilateral(e,n,i,s,a,l,d,h){const g=e-i+a-d,w=n-s+l-h;if(g===0&&w===0)return new en(i-e,a-i,e,s-n,l-s,n,0,0,1);{const b=i-a,I=d-a,N=s-l,F=h-l,U=b*F-I*N,W=(g*F-I*w)/U,K=(b*w-g*N)/U;return new en(i-e+W*i,d-e+K*d,e,s-n+W*s,h-n+K*h,n,W,K,1)}}static quadrilateralToSquare(e,n,i,s,a,l,d,h){return en.squareToQuadrilateral(e,n,i,s,a,l,d,h).buildAdjoint()}buildAdjoint(){return new en(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(e){return new en(this.a11*e.a11+this.a21*e.a12+this.a31*e.a13,this.a11*e.a21+this.a21*e.a22+this.a31*e.a23,this.a11*e.a31+this.a21*e.a32+this.a31*e.a33,this.a12*e.a11+this.a22*e.a12+this.a32*e.a13,this.a12*e.a21+this.a22*e.a22+this.a32*e.a23,this.a12*e.a31+this.a22*e.a32+this.a32*e.a33,this.a13*e.a11+this.a23*e.a12+this.a33*e.a13,this.a13*e.a21+this.a23*e.a22+this.a33*e.a23,this.a13*e.a31+this.a23*e.a32+this.a33*e.a33)}}class ai extends Tr{sampleGrid(e,n,i,s,a,l,d,h,g,w,b,I,N,F,U,W,K,fe,he){const ce=en.quadrilateralToQuadrilateral(s,a,l,d,h,g,w,b,I,N,F,U,W,K,fe,he);return this.sampleGridWithTransform(e,n,i,ce)}sampleGridWithTransform(e,n,i,s){if(n<=0||i<=0)throw new P;const a=new ee(n,i),l=new Float32Array(2*n);for(let d=0;d<i;d++){const h=l.length,g=d+.5;for(let w=0;w<h;w+=2)l[w]=w/2+.5,l[w+1]=g;s.transformPoints(l),Tr.checkAndNudgePoints(e,l);try{for(let w=0;w<h;w+=2)e.get(Math.floor(l[w]),Math.floor(l[w+1]))&&a.set(w/2,d)}catch{throw new P}}return a}}class bn{static setGridSampler(e){bn.gridSampler=e}static getInstance(){return bn.gridSampler}}bn.gridSampler=new ai;class Lt{constructor(e,n){this.x=e,this.y=n}toResultPoint(){return new be(this.getX(),this.getY())}getX(){return this.x}getY(){return this.y}}class li{constructor(e){this.EXPECTED_CORNER_BITS=new Int32Array([3808,476,2107,1799]),this.image=e}detect(){return this.detectMirror(!1)}detectMirror(e){let n=this.getMatrixCenter(),i=this.getBullsEyeCorners(n);if(e){let l=i[0];i[0]=i[2],i[2]=l}this.extractParameters(i);let s=this.sampleGrid(this.image,i[this.shift%4],i[(this.shift+1)%4],i[(this.shift+2)%4],i[(this.shift+3)%4]),a=this.getMatrixCornerPoints(i);return new si(s,a,this.compact,this.nbDataBlocks,this.nbLayers)}extractParameters(e){if(!this.isValidPoint(e[0])||!this.isValidPoint(e[1])||!this.isValidPoint(e[2])||!this.isValidPoint(e[3]))throw new P;let n=2*this.nbCenterLayers,i=new Int32Array([this.sampleLine(e[0],e[1],n),this.sampleLine(e[1],e[2],n),this.sampleLine(e[2],e[3],n),this.sampleLine(e[3],e[0],n)]);this.shift=this.getRotation(i,n);let s=0;for(let l=0;l<4;l++){let d=i[(this.shift+l)%4];this.compact?(s<<=7,s+=d>>1&127):(s<<=10,s+=(d>>2&992)+(d>>1&31))}let a=this.getCorrectedParameterData(s,this.compact);this.compact?(this.nbLayers=(a>>6)+1,this.nbDataBlocks=(a&63)+1):(this.nbLayers=(a>>11)+1,this.nbDataBlocks=(a&2047)+1)}getRotation(e,n){let i=0;e.forEach((s,a,l)=>{let d=(s>>n-2<<1)+(s&1);i=(i<<3)+d}),i=((i&1)<<11)+(i>>1);for(let s=0;s<4;s++)if(z.bitCount(i^this.EXPECTED_CORNER_BITS[s])<=2)return s;throw new P}getCorrectedParameterData(e,n){let i,s;n?(i=7,s=2):(i=10,s=4);let a=i-s,l=new Int32Array(i);for(let h=i-1;h>=0;--h)l[h]=e&15,e>>=4;try{new Cn(Be.AZTEC_PARAM).decode(l,a)}catch{throw new P}let d=0;for(let h=0;h<s;h++)d=(d<<4)+l[h];return d}getBullsEyeCorners(e){let n=e,i=e,s=e,a=e,l=!0;for(this.nbCenterLayers=1;this.nbCenterLayers<9;this.nbCenterLayers++){let b=this.getFirstDifferent(n,l,1,-1),I=this.getFirstDifferent(i,l,1,1),N=this.getFirstDifferent(s,l,-1,1),F=this.getFirstDifferent(a,l,-1,-1);if(this.nbCenterLayers>2){let U=this.distancePoint(F,b)*this.nbCenterLayers/(this.distancePoint(a,n)*(this.nbCenterLayers+2));if(U<.75||U>1.25||!this.isWhiteOrBlackRectangle(b,I,N,F))break}n=b,i=I,s=N,a=F,l=!l}if(this.nbCenterLayers!==5&&this.nbCenterLayers!==7)throw new P;this.compact=this.nbCenterLayers===5;let d=new be(n.getX()+.5,n.getY()-.5),h=new be(i.getX()+.5,i.getY()+.5),g=new be(s.getX()-.5,s.getY()+.5),w=new be(a.getX()-.5,a.getY()-.5);return this.expandSquare([d,h,g,w],2*this.nbCenterLayers-3,2*this.nbCenterLayers)}getMatrixCenter(){let e,n,i,s;try{let d=new pn(this.image).detect();e=d[0],n=d[1],i=d[2],s=d[3]}catch{let h=this.image.getWidth()/2,g=this.image.getHeight()/2;e=this.getFirstDifferent(new Lt(h+7,g-7),!1,1,-1).toResultPoint(),n=this.getFirstDifferent(new Lt(h+7,g+7),!1,1,1).toResultPoint(),i=this.getFirstDifferent(new Lt(h-7,g+7),!1,-1,1).toResultPoint(),s=this.getFirstDifferent(new Lt(h-7,g-7),!1,-1,-1).toResultPoint()}let a=Te.round((e.getX()+s.getX()+n.getX()+i.getX())/4),l=Te.round((e.getY()+s.getY()+n.getY()+i.getY())/4);try{let d=new pn(this.image,15,a,l).detect();e=d[0],n=d[1],i=d[2],s=d[3]}catch{e=this.getFirstDifferent(new Lt(a+7,l-7),!1,1,-1).toResultPoint(),n=this.getFirstDifferent(new Lt(a+7,l+7),!1,1,1).toResultPoint(),i=this.getFirstDifferent(new Lt(a-7,l+7),!1,-1,1).toResultPoint(),s=this.getFirstDifferent(new Lt(a-7,l-7),!1,-1,-1).toResultPoint()}return a=Te.round((e.getX()+s.getX()+n.getX()+i.getX())/4),l=Te.round((e.getY()+s.getY()+n.getY()+i.getY())/4),new Lt(a,l)}getMatrixCornerPoints(e){return this.expandSquare(e,2*this.nbCenterLayers,this.getDimension())}sampleGrid(e,n,i,s,a){let l=bn.getInstance(),d=this.getDimension(),h=d/2-this.nbCenterLayers,g=d/2+this.nbCenterLayers;return l.sampleGrid(e,d,d,h,h,g,h,g,g,h,g,n.getX(),n.getY(),i.getX(),i.getY(),s.getX(),s.getY(),a.getX(),a.getY())}sampleLine(e,n,i){let s=0,a=this.distanceResultPoint(e,n),l=a/i,d=e.getX(),h=e.getY(),g=l*(n.getX()-e.getX())/a,w=l*(n.getY()-e.getY())/a;for(let b=0;b<i;b++)this.image.get(Te.round(d+b*g),Te.round(h+b*w))&&(s|=1<<i-b-1);return s}isWhiteOrBlackRectangle(e,n,i,s){let a=3;e=new Lt(e.getX()-a,e.getY()+a),n=new Lt(n.getX()-a,n.getY()-a),i=new Lt(i.getX()+a,i.getY()-a),s=new Lt(s.getX()+a,s.getY()+a);let l=this.getColor(s,e);if(l===0)return!1;let d=this.getColor(e,n);return d!==l||(d=this.getColor(n,i),d!==l)?!1:(d=this.getColor(i,s),d===l)}getColor(e,n){let i=this.distancePoint(e,n),s=(n.getX()-e.getX())/i,a=(n.getY()-e.getY())/i,l=0,d=e.getX(),h=e.getY(),g=this.image.get(e.getX(),e.getY()),w=Math.ceil(i);for(let I=0;I<w;I++)d+=s,h+=a,this.image.get(Te.round(d),Te.round(h))!==g&&l++;let b=l/i;return b>.1&&b<.9?0:b<=.1===g?1:-1}getFirstDifferent(e,n,i,s){let a=e.getX()+i,l=e.getY()+s;for(;this.isValid(a,l)&&this.image.get(a,l)===n;)a+=i,l+=s;for(a-=i,l-=s;this.isValid(a,l)&&this.image.get(a,l)===n;)a+=i;for(a-=i;this.isValid(a,l)&&this.image.get(a,l)===n;)l+=s;return l-=s,new Lt(a,l)}expandSquare(e,n,i){let s=i/(2*n),a=e[0].getX()-e[2].getX(),l=e[0].getY()-e[2].getY(),d=(e[0].getX()+e[2].getX())/2,h=(e[0].getY()+e[2].getY())/2,g=new be(d+s*a,h+s*l),w=new be(d-s*a,h-s*l);a=e[1].getX()-e[3].getX(),l=e[1].getY()-e[3].getY(),d=(e[1].getX()+e[3].getX())/2,h=(e[1].getY()+e[3].getY())/2;let b=new be(d+s*a,h+s*l),I=new be(d-s*a,h-s*l);return[g,b,w,I]}isValid(e,n){return e>=0&&e<this.image.getWidth()&&n>0&&n<this.image.getHeight()}isValidPoint(e){let n=Te.round(e.getX()),i=Te.round(e.getY());return this.isValid(n,i)}distancePoint(e,n){return Te.distance(e.getX(),e.getY(),n.getX(),n.getY())}distanceResultPoint(e,n){return Te.distance(e.getX(),e.getY(),n.getX(),n.getY())}getDimension(){return this.compact?4*this.nbLayers+11:this.nbLayers<=4?4*this.nbLayers+15:4*this.nbLayers+2*(z.truncDivision(this.nbLayers-4,8)+1)+15}}class at{decode(e,n=null){let i=null,s=new li(e.getBlackMatrix()),a=null,l=null;try{let w=s.detectMirror(!1);a=w.getPoints(),this.reportFoundResultPoints(n,a),l=new ue().decode(w)}catch(w){i=w}if(l==null)try{let w=s.detectMirror(!0);a=w.getPoints(),this.reportFoundResultPoints(n,a),l=new ue().decode(w)}catch(w){throw i??w}let d=new Ue(l.getText(),l.getRawBytes(),l.getNumBits(),a,ge.AZTEC,R.currentTimeMillis()),h=l.getByteSegments();h!=null&&d.putMetadata(Se.BYTE_SEGMENTS,h);let g=l.getECLevel();return g!=null&&d.putMetadata(Se.ERROR_CORRECTION_LEVEL,g),d}reportFoundResultPoints(e,n){if(e!=null){let i=e.get(O.NEED_RESULT_POINT_CALLBACK);i!=null&&n.forEach((s,a,l)=>{i.foundPossibleResultPoint(s)})}}reset(){}}class Me extends Ze{constructor(e=500){super(new at,e)}}class ke{decode(e,n){try{return this.doDecode(e,n)}catch{if(n&&n.get(O.TRY_HARDER)===!0&&e.isRotateSupported()){const a=e.rotateCounterClockwise(),l=this.doDecode(a,n),d=l.getResultMetadata();let h=270;d!==null&&d.get(Se.ORIENTATION)===!0&&(h=h+d.get(Se.ORIENTATION)%360),l.putMetadata(Se.ORIENTATION,h);const g=l.getResultPoints();if(g!==null){const w=a.getHeight();for(let b=0;b<g.length;b++)g[b]=new be(w-g[b].getY()-1,g[b].getX())}return l}else throw new P}}reset(){}doDecode(e,n){const i=e.getWidth(),s=e.getHeight();let a=new $(i);const l=n&&n.get(O.TRY_HARDER)===!0,d=Math.max(1,s>>(l?8:5));let h;l?h=s:h=15;const g=Math.trunc(s/2);for(let w=0;w<h;w++){const b=Math.trunc((w+1)/2),I=(w&1)===0,N=g+d*(I?b:-b);if(N<0||N>=s)break;try{a=e.getBlackRow(N,a)}catch{continue}for(let F=0;F<2;F++){if(F===1&&(a.reverse(),n&&n.get(O.NEED_RESULT_POINT_CALLBACK)===!0)){const U=new Map;n.forEach((W,K)=>U.set(K,W)),U.delete(O.NEED_RESULT_POINT_CALLBACK),n=U}try{const U=this.decodeRow(N,a,n);if(F===1){U.putMetadata(Se.ORIENTATION,180);const W=U.getResultPoints();W!==null&&(W[0]=new be(i-W[0].getX()-1,W[0].getY()),W[1]=new be(i-W[1].getX()-1,W[1].getY()))}return U}catch{}}}throw new P}static recordPattern(e,n,i){const s=i.length;for(let g=0;g<s;g++)i[g]=0;const a=e.getSize();if(n>=a)throw new P;let l=!e.get(n),d=0,h=n;for(;h<a;){if(e.get(h)!==l)i[d]++;else{if(++d===s)break;i[d]=1,l=!l}h++}if(!(d===s||d===s-1&&h===a))throw new P}static recordPatternInReverse(e,n,i){let s=i.length,a=e.get(n);for(;n>0&&s>=0;)e.get(--n)!==a&&(s--,a=!a);if(s>=0)throw new P;ke.recordPattern(e,n+1,i)}static patternMatchVariance(e,n,i){const s=e.length;let a=0,l=0;for(let g=0;g<s;g++)a+=e[g],l+=n[g];if(a<l)return Number.POSITIVE_INFINITY;const d=a/l;i*=d;let h=0;for(let g=0;g<s;g++){const w=e[g],b=n[g]*d,I=w>b?w-b:b-w;if(I>i)return Number.POSITIVE_INFINITY;h+=I}return h/a}}class pe extends ke{static findStartPattern(e){const n=e.getSize(),i=e.getNextSet(0);let s=0,a=Int32Array.from([0,0,0,0,0,0]),l=i,d=!1;const h=6;for(let g=i;g<n;g++)if(e.get(g)!==d)a[s]++;else{if(s===h-1){let w=pe.MAX_AVG_VARIANCE,b=-1;for(let I=pe.CODE_START_A;I<=pe.CODE_START_C;I++){const N=ke.patternMatchVariance(a,pe.CODE_PATTERNS[I],pe.MAX_INDIVIDUAL_VARIANCE);N<w&&(w=N,b=I)}if(b>=0&&e.isRange(Math.max(0,l-(g-l)/2),l,!1))return Int32Array.from([l,g,b]);l+=a[0]+a[1],a=a.slice(2,a.length-1),a[s-1]=0,a[s]=0,s--}else s++;a[s]=1,d=!d}throw new P}static decodeCode(e,n,i){ke.recordPattern(e,i,n);let s=pe.MAX_AVG_VARIANCE,a=-1;for(let l=0;l<pe.CODE_PATTERNS.length;l++){const d=pe.CODE_PATTERNS[l],h=this.patternMatchVariance(n,d,pe.MAX_INDIVIDUAL_VARIANCE);h<s&&(s=h,a=l)}if(a>=0)return a;throw new P}decodeRow(e,n,i){const s=i&&i.get(O.ASSUME_GS1)===!0,a=pe.findStartPattern(n),l=a[2];let d=0;const h=new Uint8Array(20);h[d++]=l;let g;switch(l){case pe.CODE_START_A:g=pe.CODE_CODE_A;break;case pe.CODE_START_B:g=pe.CODE_CODE_B;break;case pe.CODE_START_C:g=pe.CODE_CODE_C;break;default:throw new V}let w=!1,b=!1,I="",N=a[0],F=a[1];const U=Int32Array.from([0,0,0,0,0,0]);let W=0,K=0,fe=l,he=0,ce=!0,je=!1,Pe=!1;for(;!w;){const vr=b;switch(b=!1,W=K,K=pe.decodeCode(n,U,F),h[d++]=K,K!==pe.CODE_STOP&&(ce=!0),K!==pe.CODE_STOP&&(he++,fe+=he*K),N=F,F+=U.reduce((_d,vd)=>_d+vd,0),K){case pe.CODE_START_A:case pe.CODE_START_B:case pe.CODE_START_C:throw new V}switch(g){case pe.CODE_CODE_A:if(K<64)Pe===je?I+=String.fromCharCode(32+K):I+=String.fromCharCode(32+K+128),Pe=!1;else if(K<96)Pe===je?I+=String.fromCharCode(K-64):I+=String.fromCharCode(K+64),Pe=!1;else switch(K!==pe.CODE_STOP&&(ce=!1),K){case pe.CODE_FNC_1:s&&(I.length===0?I+="]C1":I+="");break;case pe.CODE_FNC_2:case pe.CODE_FNC_3:break;case pe.CODE_FNC_4_A:!je&&Pe?(je=!0,Pe=!1):je&&Pe?(je=!1,Pe=!1):Pe=!0;break;case pe.CODE_SHIFT:b=!0,g=pe.CODE_CODE_B;break;case pe.CODE_CODE_B:g=pe.CODE_CODE_B;break;case pe.CODE_CODE_C:g=pe.CODE_CODE_C;break;case pe.CODE_STOP:w=!0;break}break;case pe.CODE_CODE_B:if(K<96)Pe===je?I+=String.fromCharCode(32+K):I+=String.fromCharCode(32+K+128),Pe=!1;else switch(K!==pe.CODE_STOP&&(ce=!1),K){case pe.CODE_FNC_1:s&&(I.length===0?I+="]C1":I+="");break;case pe.CODE_FNC_2:case pe.CODE_FNC_3:break;case pe.CODE_FNC_4_B:!je&&Pe?(je=!0,Pe=!1):je&&Pe?(je=!1,Pe=!1):Pe=!0;break;case pe.CODE_SHIFT:b=!0,g=pe.CODE_CODE_A;break;case pe.CODE_CODE_A:g=pe.CODE_CODE_A;break;case pe.CODE_CODE_C:g=pe.CODE_CODE_C;break;case pe.CODE_STOP:w=!0;break}break;case pe.CODE_CODE_C:if(K<100)K<10&&(I+="0"),I+=K;else switch(K!==pe.CODE_STOP&&(ce=!1),K){case pe.CODE_FNC_1:s&&(I.length===0?I+="]C1":I+="");break;case pe.CODE_CODE_A:g=pe.CODE_CODE_A;break;case pe.CODE_CODE_B:g=pe.CODE_CODE_B;break;case pe.CODE_STOP:w=!0;break}break}vr&&(g=g===pe.CODE_CODE_A?pe.CODE_CODE_B:pe.CODE_CODE_A)}const Jt=F-N;if(F=n.getNextUnset(F),!n.isRange(F,Math.min(n.getSize(),F+(F-N)/2),!1))throw new P;if(fe-=he*W,fe%103!==W)throw new D;const mn=I.length;if(mn===0)throw new P;mn>0&&ce&&(g===pe.CODE_CODE_C?I=I.substring(0,mn-2):I=I.substring(0,mn-1));const Kt=(a[1]+a[0])/2,ot=N+Jt/2,zt=h.length,tn=new Uint8Array(zt);for(let vr=0;vr<zt;vr++)tn[vr]=h[vr];const _r=[new be(Kt,e),new be(ot,e)];return new Ue(I,tn,0,_r,ge.CODE_128,new Date().getTime())}}pe.CODE_PATTERNS=[Int32Array.from([2,1,2,2,2,2]),Int32Array.from([2,2,2,1,2,2]),Int32Array.from([2,2,2,2,2,1]),Int32Array.from([1,2,1,2,2,3]),Int32Array.from([1,2,1,3,2,2]),Int32Array.from([1,3,1,2,2,2]),Int32Array.from([1,2,2,2,1,3]),Int32Array.from([1,2,2,3,1,2]),Int32Array.from([1,3,2,2,1,2]),Int32Array.from([2,2,1,2,1,3]),Int32Array.from([2,2,1,3,1,2]),Int32Array.from([2,3,1,2,1,2]),Int32Array.from([1,1,2,2,3,2]),Int32Array.from([1,2,2,1,3,2]),Int32Array.from([1,2,2,2,3,1]),Int32Array.from([1,1,3,2,2,2]),Int32Array.from([1,2,3,1,2,2]),Int32Array.from([1,2,3,2,2,1]),Int32Array.from([2,2,3,2,1,1]),Int32Array.from([2,2,1,1,3,2]),Int32Array.from([2,2,1,2,3,1]),Int32Array.from([2,1,3,2,1,2]),Int32Array.from([2,2,3,1,1,2]),Int32Array.from([3,1,2,1,3,1]),Int32Array.from([3,1,1,2,2,2]),Int32Array.from([3,2,1,1,2,2]),Int32Array.from([3,2,1,2,2,1]),Int32Array.from([3,1,2,2,1,2]),Int32Array.from([3,2,2,1,1,2]),Int32Array.from([3,2,2,2,1,1]),Int32Array.from([2,1,2,1,2,3]),Int32Array.from([2,1,2,3,2,1]),Int32Array.from([2,3,2,1,2,1]),Int32Array.from([1,1,1,3,2,3]),Int32Array.from([1,3,1,1,2,3]),Int32Array.from([1,3,1,3,2,1]),Int32Array.from([1,1,2,3,1,3]),Int32Array.from([1,3,2,1,1,3]),Int32Array.from([1,3,2,3,1,1]),Int32Array.from([2,1,1,3,1,3]),Int32Array.from([2,3,1,1,1,3]),Int32Array.from([2,3,1,3,1,1]),Int32Array.from([1,1,2,1,3,3]),Int32Array.from([1,1,2,3,3,1]),Int32Array.from([1,3,2,1,3,1]),Int32Array.from([1,1,3,1,2,3]),Int32Array.from([1,1,3,3,2,1]),Int32Array.from([1,3,3,1,2,1]),Int32Array.from([3,1,3,1,2,1]),Int32Array.from([2,1,1,3,3,1]),Int32Array.from([2,3,1,1,3,1]),Int32Array.from([2,1,3,1,1,3]),Int32Array.from([2,1,3,3,1,1]),Int32Array.from([2,1,3,1,3,1]),Int32Array.from([3,1,1,1,2,3]),Int32Array.from([3,1,1,3,2,1]),Int32Array.from([3,3,1,1,2,1]),Int32Array.from([3,1,2,1,1,3]),Int32Array.from([3,1,2,3,1,1]),Int32Array.from([3,3,2,1,1,1]),Int32Array.from([3,1,4,1,1,1]),Int32Array.from([2,2,1,4,1,1]),Int32Array.from([4,3,1,1,1,1]),Int32Array.from([1,1,1,2,2,4]),Int32Array.from([1,1,1,4,2,2]),Int32Array.from([1,2,1,1,2,4]),Int32Array.from([1,2,1,4,2,1]),Int32Array.from([1,4,1,1,2,2]),Int32Array.from([1,4,1,2,2,1]),Int32Array.from([1,1,2,2,1,4]),Int32Array.from([1,1,2,4,1,2]),Int32Array.from([1,2,2,1,1,4]),Int32Array.from([1,2,2,4,1,1]),Int32Array.from([1,4,2,1,1,2]),Int32Array.from([1,4,2,2,1,1]),Int32Array.from([2,4,1,2,1,1]),Int32Array.from([2,2,1,1,1,4]),Int32Array.from([4,1,3,1,1,1]),Int32Array.from([2,4,1,1,1,2]),Int32Array.from([1,3,4,1,1,1]),Int32Array.from([1,1,1,2,4,2]),Int32Array.from([1,2,1,1,4,2]),Int32Array.from([1,2,1,2,4,1]),Int32Array.from([1,1,4,2,1,2]),Int32Array.from([1,2,4,1,1,2]),Int32Array.from([1,2,4,2,1,1]),Int32Array.from([4,1,1,2,1,2]),Int32Array.from([4,2,1,1,1,2]),Int32Array.from([4,2,1,2,1,1]),Int32Array.from([2,1,2,1,4,1]),Int32Array.from([2,1,4,1,2,1]),Int32Array.from([4,1,2,1,2,1]),Int32Array.from([1,1,1,1,4,3]),Int32Array.from([1,1,1,3,4,1]),Int32Array.from([1,3,1,1,4,1]),Int32Array.from([1,1,4,1,1,3]),Int32Array.from([1,1,4,3,1,1]),Int32Array.from([4,1,1,1,1,3]),Int32Array.from([4,1,1,3,1,1]),Int32Array.from([1,1,3,1,4,1]),Int32Array.from([1,1,4,1,3,1]),Int32Array.from([3,1,1,1,4,1]),Int32Array.from([4,1,1,1,3,1]),Int32Array.from([2,1,1,4,1,2]),Int32Array.from([2,1,1,2,1,4]),Int32Array.from([2,1,1,2,3,2]),Int32Array.from([2,3,3,1,1,1,2])],pe.MAX_AVG_VARIANCE=.25,pe.MAX_INDIVIDUAL_VARIANCE=.7,pe.CODE_SHIFT=98,pe.CODE_CODE_C=99,pe.CODE_CODE_B=100,pe.CODE_CODE_A=101,pe.CODE_FNC_1=102,pe.CODE_FNC_2=97,pe.CODE_FNC_3=96,pe.CODE_FNC_4_A=101,pe.CODE_FNC_4_B=100,pe.CODE_START_A=103,pe.CODE_START_B=104,pe.CODE_START_C=105,pe.CODE_STOP=106;class St extends ke{constructor(e=!1,n=!1){super(),this.usingCheckDigit=e,this.extendedMode=n,this.decodeRowResult="",this.counters=new Int32Array(9)}decodeRow(e,n,i){let s=this.counters;s.fill(0),this.decodeRowResult="";let a=St.findAsteriskPattern(n,s),l=n.getNextSet(a[1]),d=n.getSize(),h,g;do{St.recordPattern(n,l,s);let U=St.toNarrowWidePattern(s);if(U<0)throw new P;h=St.patternToChar(U),this.decodeRowResult+=h,g=l;for(let W of s)l+=W;l=n.getNextSet(l)}while(h!=="*");this.decodeRowResult=this.decodeRowResult.substring(0,this.decodeRowResult.length-1);let w=0;for(let U of s)w+=U;let b=l-g-w;if(l!==d&&b*2<w)throw new P;if(this.usingCheckDigit){let U=this.decodeRowResult.length-1,W=0;for(let K=0;K<U;K++)W+=St.ALPHABET_STRING.indexOf(this.decodeRowResult.charAt(K));if(this.decodeRowResult.charAt(U)!==St.ALPHABET_STRING.charAt(W%43))throw new D;this.decodeRowResult=this.decodeRowResult.substring(0,U)}if(this.decodeRowResult.length===0)throw new P;let I;this.extendedMode?I=St.decodeExtended(this.decodeRowResult):I=this.decodeRowResult;let N=(a[1]+a[0])/2,F=g+w/2;return new Ue(I,null,0,[new be(N,e),new be(F,e)],ge.CODE_39,new Date().getTime())}static findAsteriskPattern(e,n){let i=e.getSize(),s=e.getNextSet(0),a=0,l=s,d=!1,h=n.length;for(let g=s;g<i;g++)if(e.get(g)!==d)n[a]++;else{if(a===h-1){if(this.toNarrowWidePattern(n)===St.ASTERISK_ENCODING&&e.isRange(Math.max(0,l-Math.floor((g-l)/2)),l,!1))return[l,g];l+=n[0]+n[1],n.copyWithin(0,2,2+a-1),n[a-1]=0,n[a]=0,a--}else a++;n[a]=1,d=!d}throw new P}static toNarrowWidePattern(e){let n=e.length,i=0,s;do{let a=2147483647;for(let h of e)h<a&&h>i&&(a=h);i=a,s=0;let l=0,d=0;for(let h=0;h<n;h++){let g=e[h];g>i&&(d|=1<<n-1-h,s++,l+=g)}if(s===3){for(let h=0;h<n&&s>0;h++){let g=e[h];if(g>i&&(s--,g*2>=l))return-1}return d}}while(s>3);return-1}static patternToChar(e){for(let n=0;n<St.CHARACTER_ENCODINGS.length;n++)if(St.CHARACTER_ENCODINGS[n]===e)return St.ALPHABET_STRING.charAt(n);if(e===St.ASTERISK_ENCODING)return"*";throw new P}static decodeExtended(e){let n=e.length,i="";for(let s=0;s<n;s++){let a=e.charAt(s);if(a==="+"||a==="$"||a==="%"||a==="/"){let l=e.charAt(s+1),d="\0";switch(a){case"+":if(l>="A"&&l<="Z")d=String.fromCharCode(l.charCodeAt(0)+32);else throw new V;break;case"$":if(l>="A"&&l<="Z")d=String.fromCharCode(l.charCodeAt(0)-64);else throw new V;break;case"%":if(l>="A"&&l<="E")d=String.fromCharCode(l.charCodeAt(0)-38);else if(l>="F"&&l<="J")d=String.fromCharCode(l.charCodeAt(0)-11);else if(l>="K"&&l<="O")d=String.fromCharCode(l.charCodeAt(0)+16);else if(l>="P"&&l<="T")d=String.fromCharCode(l.charCodeAt(0)+43);else if(l==="U")d="\0";else if(l==="V")d="@";else if(l==="W")d="`";else if(l==="X"||l==="Y"||l==="Z")d="";else throw new V;break;case"/":if(l>="A"&&l<="O")d=String.fromCharCode(l.charCodeAt(0)-32);else if(l==="Z")d=":";else throw new V;break}i+=d,s++}else i+=a}return i}}St.ALPHABET_STRING="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%",St.CHARACTER_ENCODINGS=[52,289,97,352,49,304,112,37,292,100,265,73,328,25,280,88,13,268,76,28,259,67,322,19,274,82,7,262,70,22,385,193,448,145,400,208,133,388,196,168,162,138,42],St.ASTERISK_ENCODING=148;class rt extends ke{constructor(){super(...arguments),this.narrowLineWidth=-1}decodeRow(e,n,i){let s=this.decodeStart(n),a=this.decodeEnd(n),l=new oe;rt.decodeMiddle(n,s[1],a[0],l);let d=l.toString(),h=null;i!=null&&(h=i.get(O.ALLOWED_LENGTHS)),h==null&&(h=rt.DEFAULT_ALLOWED_LENGTHS);let g=d.length,w=!1,b=0;for(let F of h){if(g===F){w=!0;break}F>b&&(b=F)}if(!w&&g>b&&(w=!0),!w)throw new V;const I=[new be(s[1],e),new be(a[0],e)];return new Ue(d,null,0,I,ge.ITF,new Date().getTime())}static decodeMiddle(e,n,i,s){let a=new Int32Array(10),l=new Int32Array(5),d=new Int32Array(5);for(a.fill(0),l.fill(0),d.fill(0);n<i;){ke.recordPattern(e,n,a);for(let g=0;g<5;g++){let w=2*g;l[g]=a[w],d[g]=a[w+1]}let h=rt.decodeDigit(l);s.append(h.toString()),h=this.decodeDigit(d),s.append(h.toString()),a.forEach(function(g){n+=g})}}decodeStart(e){let n=rt.skipWhiteSpace(e),i=rt.findGuardPattern(e,n,rt.START_PATTERN);return this.narrowLineWidth=(i[1]-i[0])/4,this.validateQuietZone(e,i[0]),i}validateQuietZone(e,n){let i=this.narrowLineWidth*10;i=i<n?i:n;for(let s=n-1;i>0&&s>=0&&!e.get(s);s--)i--;if(i!==0)throw new P}static skipWhiteSpace(e){const n=e.getSize(),i=e.getNextSet(0);if(i===n)throw new P;return i}decodeEnd(e){e.reverse();try{let n=rt.skipWhiteSpace(e),i;try{i=rt.findGuardPattern(e,n,rt.END_PATTERN_REVERSED[0])}catch(a){a instanceof P&&(i=rt.findGuardPattern(e,n,rt.END_PATTERN_REVERSED[1]))}this.validateQuietZone(e,i[0]);let s=i[0];return i[0]=e.getSize()-i[1],i[1]=e.getSize()-s,i}finally{e.reverse()}}static findGuardPattern(e,n,i){let s=i.length,a=new Int32Array(s),l=e.getSize(),d=!1,h=0,g=n;a.fill(0);for(let w=n;w<l;w++)if(e.get(w)!==d)a[h]++;else{if(h===s-1){if(ke.patternMatchVariance(a,i,rt.MAX_INDIVIDUAL_VARIANCE)<rt.MAX_AVG_VARIANCE)return[g,w];g+=a[0]+a[1],R.arraycopy(a,2,a,0,h-1),a[h-1]=0,a[h]=0,h--}else h++;a[h]=1,d=!d}throw new P}static decodeDigit(e){let n=rt.MAX_AVG_VARIANCE,i=-1,s=rt.PATTERNS.length;for(let a=0;a<s;a++){let l=rt.PATTERNS[a],d=ke.patternMatchVariance(e,l,rt.MAX_INDIVIDUAL_VARIANCE);d<n?(n=d,i=a):d===n&&(i=-1)}if(i>=0)return i%10;throw new P}}rt.PATTERNS=[Int32Array.from([1,1,2,2,1]),Int32Array.from([2,1,1,1,2]),Int32Array.from([1,2,1,1,2]),Int32Array.from([2,2,1,1,1]),Int32Array.from([1,1,2,1,2]),Int32Array.from([2,1,2,1,1]),Int32Array.from([1,2,2,1,1]),Int32Array.from([1,1,1,2,2]),Int32Array.from([2,1,1,2,1]),Int32Array.from([1,2,1,2,1]),Int32Array.from([1,1,3,3,1]),Int32Array.from([3,1,1,1,3]),Int32Array.from([1,3,1,1,3]),Int32Array.from([3,3,1,1,1]),Int32Array.from([1,1,3,1,3]),Int32Array.from([3,1,3,1,1]),Int32Array.from([1,3,3,1,1]),Int32Array.from([1,1,1,3,3]),Int32Array.from([3,1,1,3,1]),Int32Array.from([1,3,1,3,1])],rt.MAX_AVG_VARIANCE=.38,rt.MAX_INDIVIDUAL_VARIANCE=.5,rt.DEFAULT_ALLOWED_LENGTHS=[6,8,10,12,14],rt.START_PATTERN=Int32Array.from([1,1,1,1]),rt.END_PATTERN_REVERSED=[Int32Array.from([1,1,2]),Int32Array.from([1,1,3])];class _t extends ke{constructor(){super(...arguments),this.decodeRowStringBuffer=""}static findStartGuardPattern(e){let n=!1,i,s=0,a=Int32Array.from([0,0,0]);for(;!n;){a=Int32Array.from([0,0,0]),i=_t.findGuardPattern(e,s,!1,this.START_END_PATTERN,a);let l=i[0];s=i[1];let d=l-(s-l);d>=0&&(n=e.isRange(d,l,!1))}return i}static checkChecksum(e){return _t.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let n=e.length;if(n===0)return!1;let i=parseInt(e.charAt(n-1),10);return _t.getStandardUPCEANChecksum(e.substring(0,n-1))===i}static getStandardUPCEANChecksum(e){let n=e.length,i=0;for(let s=n-1;s>=0;s-=2){let a=e.charAt(s).charCodeAt(0)-48;if(a<0||a>9)throw new V;i+=a}i*=3;for(let s=n-2;s>=0;s-=2){let a=e.charAt(s).charCodeAt(0)-48;if(a<0||a>9)throw new V;i+=a}return(1e3-i)%10}static decodeEnd(e,n){return _t.findGuardPattern(e,n,!1,_t.START_END_PATTERN,new Int32Array(_t.START_END_PATTERN.length).fill(0))}static findGuardPatternWithoutCounters(e,n,i,s){return this.findGuardPattern(e,n,i,s,new Int32Array(s.length))}static findGuardPattern(e,n,i,s,a){let l=e.getSize();n=i?e.getNextUnset(n):e.getNextSet(n);let d=0,h=n,g=s.length,w=i;for(let b=n;b<l;b++)if(e.get(b)!==w)a[d]++;else{if(d===g-1){if(ke.patternMatchVariance(a,s,_t.MAX_INDIVIDUAL_VARIANCE)<_t.MAX_AVG_VARIANCE)return Int32Array.from([h,b]);h+=a[0]+a[1];let I=a.slice(2,a.length-1);for(let N=0;N<d-1;N++)a[N]=I[N];a[d-1]=0,a[d]=0,d--}else d++;a[d]=1,w=!w}throw new P}static decodeDigit(e,n,i,s){this.recordPattern(e,i,n);let a=this.MAX_AVG_VARIANCE,l=-1,d=s.length;for(let h=0;h<d;h++){let g=s[h],w=ke.patternMatchVariance(n,g,_t.MAX_INDIVIDUAL_VARIANCE);w<a&&(a=w,l=h)}if(l>=0)return l;throw new P}}_t.MAX_AVG_VARIANCE=.48,_t.MAX_INDIVIDUAL_VARIANCE=.7,_t.START_END_PATTERN=Int32Array.from([1,1,1]),_t.MIDDLE_PATTERN=Int32Array.from([1,1,1,1,1]),_t.END_PATTERN=Int32Array.from([1,1,1,1,1,1]),_t.L_PATTERNS=[Int32Array.from([3,2,1,1]),Int32Array.from([2,2,2,1]),Int32Array.from([2,1,2,2]),Int32Array.from([1,4,1,1]),Int32Array.from([1,1,3,2]),Int32Array.from([1,2,3,1]),Int32Array.from([1,1,1,4]),Int32Array.from([1,3,1,2]),Int32Array.from([1,2,1,3]),Int32Array.from([3,1,1,2])];class Nr{constructor(){this.CHECK_DIGIT_ENCODINGS=[24,20,18,17,12,6,3,10,9,5],this.decodeMiddleCounters=Int32Array.from([0,0,0,0]),this.decodeRowStringBuffer=""}decodeRow(e,n,i){let s=this.decodeRowStringBuffer,a=this.decodeMiddle(n,i,s),l=s.toString(),d=Nr.parseExtensionString(l),h=[new be((i[0]+i[1])/2,e),new be(a,e)],g=new Ue(l,null,0,h,ge.UPC_EAN_EXTENSION,new Date().getTime());return d!=null&&g.putAllMetadata(d),g}decodeMiddle(e,n,i){let s=this.decodeMiddleCounters;s[0]=0,s[1]=0,s[2]=0,s[3]=0;let a=e.getSize(),l=n[1],d=0;for(let g=0;g<5&&l<a;g++){let w=_t.decodeDigit(e,s,l,_t.L_AND_G_PATTERNS);i+=String.fromCharCode(48+w%10);for(let b of s)l+=b;w>=10&&(d|=1<<4-g),g!==4&&(l=e.getNextSet(l),l=e.getNextUnset(l))}if(i.length!==5)throw new P;let h=this.determineCheckDigit(d);if(Nr.extensionChecksum(i.toString())!==h)throw new P;return l}static extensionChecksum(e){let n=e.length,i=0;for(let s=n-2;s>=0;s-=2)i+=e.charAt(s).charCodeAt(0)-48;i*=3;for(let s=n-1;s>=0;s-=2)i+=e.charAt(s).charCodeAt(0)-48;return i*=3,i%10}determineCheckDigit(e){for(let n=0;n<10;n++)if(e===this.CHECK_DIGIT_ENCODINGS[n])return n;throw new P}static parseExtensionString(e){if(e.length!==5)return null;let n=Nr.parseExtension5String(e);return n==null?null:new Map([[Se.SUGGESTED_PRICE,n]])}static parseExtension5String(e){let n;switch(e.charAt(0)){case"0":n="£";break;case"5":n="$";break;case"9":switch(e){case"90000":return null;case"99991":return"0.00";case"99990":return"Used"}n="";break;default:n="";break}let i=parseInt(e.substring(1)),s=(i/100).toString(),a=i%100,l=a<10?"0"+a:a.toString();return n+s+"."+l}}class Hi{constructor(){this.decodeMiddleCounters=Int32Array.from([0,0,0,0]),this.decodeRowStringBuffer=""}decodeRow(e,n,i){let s=this.decodeRowStringBuffer,a=this.decodeMiddle(n,i,s),l=s.toString(),d=Hi.parseExtensionString(l),h=[new be((i[0]+i[1])/2,e),new be(a,e)],g=new Ue(l,null,0,h,ge.UPC_EAN_EXTENSION,new Date().getTime());return d!=null&&g.putAllMetadata(d),g}decodeMiddle(e,n,i){let s=this.decodeMiddleCounters;s[0]=0,s[1]=0,s[2]=0,s[3]=0;let a=e.getSize(),l=n[1],d=0;for(let h=0;h<2&&l<a;h++){let g=_t.decodeDigit(e,s,l,_t.L_AND_G_PATTERNS);i+=String.fromCharCode(48+g%10);for(let w of s)l+=w;g>=10&&(d|=1<<1-h),h!==1&&(l=e.getNextSet(l),l=e.getNextUnset(l))}if(i.length!==2)throw new P;if(parseInt(i.toString())%4!==d)throw new P;return l}static parseExtensionString(e){return e.length!==2?null:new Map([[Se.ISSUE_NUMBER,parseInt(e)]])}}class ss{static decodeRow(e,n,i){let s=_t.findGuardPattern(n,i,!1,this.EXTENSION_START_PATTERN,new Int32Array(this.EXTENSION_START_PATTERN.length).fill(0));try{return new Nr().decodeRow(e,n,s)}catch{return new Hi().decodeRow(e,n,s)}}}ss.EXTENSION_START_PATTERN=Int32Array.from([1,1,2]);class Xe extends _t{constructor(){super(),this.decodeRowStringBuffer="",Xe.L_AND_G_PATTERNS=Xe.L_PATTERNS.map(e=>Int32Array.from(e));for(let e=10;e<20;e++){let n=Xe.L_PATTERNS[e-10],i=new Int32Array(n.length);for(let s=0;s<n.length;s++)i[s]=n[n.length-s-1];Xe.L_AND_G_PATTERNS[e]=i}}decodeRow(e,n,i){let s=Xe.findStartGuardPattern(n),a=i==null?null:i.get(O.NEED_RESULT_POINT_CALLBACK);if(a!=null){const ce=new be((s[0]+s[1])/2,e);a.foundPossibleResultPoint(ce)}let l=this.decodeMiddle(n,s,this.decodeRowStringBuffer),d=l.rowOffset,h=l.resultString;if(a!=null){const ce=new be(d,e);a.foundPossibleResultPoint(ce)}let g=this.decodeEnd(n,d);if(a!=null){const ce=new be((g[0]+g[1])/2,e);a.foundPossibleResultPoint(ce)}let w=g[1],b=w+(w-g[0]);if(b>=n.getSize()||!n.isRange(w,b,!1))throw new P;let I=h.toString();if(I.length<8)throw new V;if(!Xe.checkChecksum(I))throw new D;let N=(s[1]+s[0])/2,F=(g[1]+g[0])/2,U=this.getBarcodeFormat(),W=[new be(N,e),new be(F,e)],K=new Ue(I,null,0,W,U,new Date().getTime()),fe=0;try{let ce=ss.decodeRow(e,n,g[1]);K.putMetadata(Se.UPC_EAN_EXTENSION,ce.getText()),K.putAllMetadata(ce.getResultMetadata()),K.addResultPoints(ce.getResultPoints()),fe=ce.getText().length}catch{}let he=i==null?null:i.get(O.ALLOWED_EAN_EXTENSIONS);if(he!=null){let ce=!1;for(let je in he)if(fe.toString()===je){ce=!0;break}if(!ce)throw new P}return K}decodeEnd(e,n){return Xe.findGuardPattern(e,n,!1,Xe.START_END_PATTERN,new Int32Array(Xe.START_END_PATTERN.length).fill(0))}static checkChecksum(e){return Xe.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let n=e.length;if(n===0)return!1;let i=parseInt(e.charAt(n-1),10);return Xe.getStandardUPCEANChecksum(e.substring(0,n-1))===i}static getStandardUPCEANChecksum(e){let n=e.length,i=0;for(let s=n-1;s>=0;s-=2){let a=e.charAt(s).charCodeAt(0)-48;if(a<0||a>9)throw new V;i+=a}i*=3;for(let s=n-2;s>=0;s-=2){let a=e.charAt(s).charCodeAt(0)-48;if(a<0||a>9)throw new V;i+=a}return(1e3-i)%10}}class Yn extends Xe{constructor(){super(),this.decodeMiddleCounters=Int32Array.from([0,0,0,0])}decodeMiddle(e,n,i){let s=this.decodeMiddleCounters;s[0]=0,s[1]=0,s[2]=0,s[3]=0;let a=e.getSize(),l=n[1],d=0;for(let g=0;g<6&&l<a;g++){let w=Xe.decodeDigit(e,s,l,Xe.L_AND_G_PATTERNS);i+=String.fromCharCode(48+w%10);for(let b of s)l+=b;w>=10&&(d|=1<<5-g)}i=Yn.determineFirstDigit(i,d),l=Xe.findGuardPattern(e,l,!0,Xe.MIDDLE_PATTERN,new Int32Array(Xe.MIDDLE_PATTERN.length).fill(0))[1];for(let g=0;g<6&&l<a;g++){let w=Xe.decodeDigit(e,s,l,Xe.L_PATTERNS);i+=String.fromCharCode(48+w);for(let b of s)l+=b}return{rowOffset:l,resultString:i}}getBarcodeFormat(){return ge.EAN_13}static determineFirstDigit(e,n){for(let i=0;i<10;i++)if(n===this.FIRST_DIGIT_ENCODINGS[i])return e=String.fromCharCode(48+i)+e,e;throw new P}}Yn.FIRST_DIGIT_ENCODINGS=[0,11,13,14,19,25,28,21,22,26];class as extends Xe{constructor(){super(),this.decodeMiddleCounters=Int32Array.from([0,0,0,0])}decodeMiddle(e,n,i){const s=this.decodeMiddleCounters;s[0]=0,s[1]=0,s[2]=0,s[3]=0;let a=e.getSize(),l=n[1];for(let h=0;h<4&&l<a;h++){let g=Xe.decodeDigit(e,s,l,Xe.L_PATTERNS);i+=String.fromCharCode(48+g);for(let w of s)l+=w}l=Xe.findGuardPattern(e,l,!0,Xe.MIDDLE_PATTERN,new Int32Array(Xe.MIDDLE_PATTERN.length).fill(0))[1];for(let h=0;h<4&&l<a;h++){let g=Xe.decodeDigit(e,s,l,Xe.L_PATTERNS);i+=String.fromCharCode(48+g);for(let w of s)l+=w}return{rowOffset:l,resultString:i}}getBarcodeFormat(){return ge.EAN_8}}class ls extends Xe{constructor(){super(...arguments),this.ean13Reader=new Yn}getBarcodeFormat(){return ge.UPC_A}decode(e,n){return this.maybeReturnResult(this.ean13Reader.decode(e))}decodeRow(e,n,i){return this.maybeReturnResult(this.ean13Reader.decodeRow(e,n,i))}decodeMiddle(e,n,i){return this.ean13Reader.decodeMiddle(e,n,i)}maybeReturnResult(e){let n=e.getText();if(n.charAt(0)==="0"){let i=new Ue(n.substring(1),null,null,e.getResultPoints(),ge.UPC_A);return e.getResultMetadata()!=null&&i.putAllMetadata(e.getResultMetadata()),i}else throw new P}reset(){this.ean13Reader.reset()}}class gn extends Xe{constructor(){super(),this.decodeMiddleCounters=new Int32Array(4)}decodeMiddle(e,n,i){const s=this.decodeMiddleCounters.map(g=>g);s[0]=0,s[1]=0,s[2]=0,s[3]=0;const a=e.getSize();let l=n[1],d=0;for(let g=0;g<6&&l<a;g++){const w=gn.decodeDigit(e,s,l,gn.L_AND_G_PATTERNS);i+=String.fromCharCode(48+w%10);for(let b of s)l+=b;w>=10&&(d|=1<<5-g)}let h=gn.determineNumSysAndCheckDigit(i,d);return{rowOffset:l,resultString:h}}decodeEnd(e,n){return gn.findGuardPatternWithoutCounters(e,n,!0,gn.MIDDLE_END_PATTERN)}checkChecksum(e){return Xe.checkChecksum(gn.convertUPCEtoUPCA(e))}static determineNumSysAndCheckDigit(e,n){for(let i=0;i<=1;i++)for(let s=0;s<10;s++)if(n===this.NUMSYS_AND_CHECK_DIGIT_PATTERNS[i][s]){let a=String.fromCharCode(48+i),l=String.fromCharCode(48+s);return a+e+l}throw P.getNotFoundInstance()}getBarcodeFormat(){return ge.UPC_E}static convertUPCEtoUPCA(e){const n=e.slice(1,7).split("").map(a=>a.charCodeAt(0)),i=new oe;i.append(e.charAt(0));let s=n[5];switch(s){case 0:case 1:case 2:i.appendChars(n,0,2),i.append(s),i.append("0000"),i.appendChars(n,2,3);break;case 3:i.appendChars(n,0,3),i.append("00000"),i.appendChars(n,3,2);break;case 4:i.appendChars(n,0,4),i.append("00000"),i.append(n[4]);break;default:i.appendChars(n,0,5),i.append("0000"),i.append(s);break}return e.length>=8&&i.append(e.charAt(7)),i.toString()}}gn.MIDDLE_END_PATTERN=Int32Array.from([1,1,1,1,1,1]),gn.NUMSYS_AND_CHECK_DIGIT_PATTERNS=[Int32Array.from([56,52,50,49,44,38,35,42,41,37]),Int32Array.from([7,11,13,14,19,25,28,21,22,26])];class Wi extends ke{constructor(e){super();let n=e==null?null:e.get(O.POSSIBLE_FORMATS),i=[];c(n)?(i.push(new Yn),i.push(new ls),i.push(new as),i.push(new gn)):(n.indexOf(ge.EAN_13)>-1&&i.push(new Yn),n.indexOf(ge.UPC_A)>-1&&i.push(new ls),n.indexOf(ge.EAN_8)>-1&&i.push(new as),n.indexOf(ge.UPC_E)>-1&&i.push(new gn)),this.readers=i}decodeRow(e,n,i){for(let s of this.readers)try{const a=s.decodeRow(e,n,i),l=a.getBarcodeFormat()===ge.EAN_13&&a.getText().charAt(0)==="0",d=i==null?null:i.get(O.POSSIBLE_FORMATS),h=d==null||d.includes(ge.UPC_A);if(l&&h){const g=a.getRawBytes(),w=new Ue(a.getText().substring(1),g,g?g.length:null,a.getResultPoints(),ge.UPC_A);return w.putAllMetadata(a.getResultMetadata()),w}return a}catch{}throw new P}reset(){for(let e of this.readers)e.reset()}}class $t extends ke{constructor(){super(),this.decodeFinderCounters=new Int32Array(4),this.dataCharacterCounters=new Int32Array(8),this.oddRoundingErrors=new Array(4),this.evenRoundingErrors=new Array(4),this.oddCounts=new Array(this.dataCharacterCounters.length/2),this.evenCounts=new Array(this.dataCharacterCounters.length/2)}getDecodeFinderCounters(){return this.decodeFinderCounters}getDataCharacterCounters(){return this.dataCharacterCounters}getOddRoundingErrors(){return this.oddRoundingErrors}getEvenRoundingErrors(){return this.evenRoundingErrors}getOddCounts(){return this.oddCounts}getEvenCounts(){return this.evenCounts}parseFinderValue(e,n){for(let i=0;i<n.length;i++)if(ke.patternMatchVariance(e,n[i],$t.MAX_INDIVIDUAL_VARIANCE)<$t.MAX_AVG_VARIANCE)return i;throw new P}static count(e){return Te.sum(new Int32Array(e))}static increment(e,n){let i=0,s=n[0];for(let a=1;a<e.length;a++)n[a]>s&&(s=n[a],i=a);e[i]++}static decrement(e,n){let i=0,s=n[0];for(let a=1;a<e.length;a++)n[a]<s&&(s=n[a],i=a);e[i]--}static isFinderPattern(e){let n=e[0]+e[1],i=n+e[2]+e[3],s=n/i;if(s>=$t.MIN_FINDER_PATTERN_RATIO&&s<=$t.MAX_FINDER_PATTERN_RATIO){let a=Number.MAX_SAFE_INTEGER,l=Number.MIN_SAFE_INTEGER;for(let d of e)d>l&&(l=d),d<a&&(a=d);return l<10*a}return!1}}$t.MAX_AVG_VARIANCE=.2,$t.MAX_INDIVIDUAL_VARIANCE=.45,$t.MIN_FINDER_PATTERN_RATIO=9.5/12,$t.MAX_FINDER_PATTERN_RATIO=12.5/14;class hr{constructor(e,n){this.value=e,this.checksumPortion=n}getValue(){return this.value}getChecksumPortion(){return this.checksumPortion}toString(){return this.value+"("+this.checksumPortion+")"}equals(e){if(!(e instanceof hr))return!1;const n=e;return this.value===n.value&&this.checksumPortion===n.checksumPortion}hashCode(){return this.value^this.checksumPortion}}class ci{constructor(e,n,i,s,a){this.value=e,this.startEnd=n,this.value=e,this.startEnd=n,this.resultPoints=new Array,this.resultPoints.push(new be(i,a)),this.resultPoints.push(new be(s,a))}getValue(){return this.value}getStartEnd(){return this.startEnd}getResultPoints(){return this.resultPoints}equals(e){if(!(e instanceof ci))return!1;const n=e;return this.value===n.value}hashCode(){return this.value}}class En{constructor(){}static getRSSvalue(e,n,i){let s=0;for(let h of e)s+=h;let a=0,l=0,d=e.length;for(let h=0;h<d-1;h++){let g;for(g=1,l|=1<<h;g<e[h];g++,l&=~(1<<h)){let w=En.combins(s-g-1,d-h-2);if(i&&l===0&&s-g-(d-h-1)>=d-h-1&&(w-=En.combins(s-g-(d-h),d-h-2)),d-h-1>1){let b=0;for(let I=s-g-(d-h-2);I>n;I--)b+=En.combins(s-g-I-1,d-h-3);w-=b*(d-1-h)}else s-g>n&&w--;a+=w}s-=g}return a}static combins(e,n){let i,s;e-n>n?(s=n,i=e-n):(s=e-n,i=n);let a=1,l=1;for(let d=e;d>i;d--)a*=d,l<=s&&(a/=l,l++);for(;l<=s;)a/=l,l++;return a}}class Wu{static buildBitArray(e){let n=e.length*2-1;e[e.length-1].getRightChar()==null&&(n-=1);let i=12*n,s=new $(i),a=0,d=e[0].getRightChar().getValue();for(let h=11;h>=0;--h)(d&1<<h)!=0&&s.set(a),a++;for(let h=1;h<e.length;++h){let g=e[h],w=g.getLeftChar().getValue();for(let b=11;b>=0;--b)(w&1<<b)!=0&&s.set(a),a++;if(g.getRightChar()!=null){let b=g.getRightChar().getValue();for(let I=11;I>=0;--I)(b&1<<I)!=0&&s.set(a),a++}}return s}}class Jn{constructor(e,n){n?this.decodedInformation=null:(this.finished=e,this.decodedInformation=n)}getDecodedInformation(){return this.decodedInformation}isFinished(){return this.finished}}class Gi{constructor(e){this.newPosition=e}getNewPosition(){return this.newPosition}}class Xt extends Gi{constructor(e,n){super(e),this.value=n}getValue(){return this.value}isFNC1(){return this.value===Xt.FNC1}}Xt.FNC1="$";class Kn extends Gi{constructor(e,n,i){super(e),i?(this.remaining=!0,this.remainingValue=this.remainingValue):(this.remaining=!1,this.remainingValue=0),this.newString=n}getNewString(){return this.newString}isRemaining(){return this.remaining}getRemainingValue(){return this.remainingValue}}class cn extends Gi{constructor(e,n,i){if(super(e),n<0||n>10||i<0||i>10)throw new V;this.firstDigit=n,this.secondDigit=i}getFirstDigit(){return this.firstDigit}getSecondDigit(){return this.secondDigit}getValue(){return this.firstDigit*10+this.secondDigit}isFirstDigitFNC1(){return this.firstDigit===cn.FNC1}isSecondDigitFNC1(){return this.secondDigit===cn.FNC1}isAnyFNC1(){return this.firstDigit===cn.FNC1||this.secondDigit===cn.FNC1}}cn.FNC1=10;class ve{constructor(){}static parseFieldsInGeneralPurpose(e){if(!e)return null;if(e.length<2)throw new P;let n=e.substring(0,2);for(let a of ve.TWO_DIGIT_DATA_LENGTH)if(a[0]===n)return a[1]===ve.VARIABLE_LENGTH?ve.processVariableAI(2,a[2],e):ve.processFixedAI(2,a[1],e);if(e.length<3)throw new P;let i=e.substring(0,3);for(let a of ve.THREE_DIGIT_DATA_LENGTH)if(a[0]===i)return a[1]===ve.VARIABLE_LENGTH?ve.processVariableAI(3,a[2],e):ve.processFixedAI(3,a[1],e);for(let a of ve.THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH)if(a[0]===i)return a[1]===ve.VARIABLE_LENGTH?ve.processVariableAI(4,a[2],e):ve.processFixedAI(4,a[1],e);if(e.length<4)throw new P;let s=e.substring(0,4);for(let a of ve.FOUR_DIGIT_DATA_LENGTH)if(a[0]===s)return a[1]===ve.VARIABLE_LENGTH?ve.processVariableAI(4,a[2],e):ve.processFixedAI(4,a[1],e);throw new P}static processFixedAI(e,n,i){if(i.length<e)throw new P;let s=i.substring(0,e);if(i.length<e+n)throw new P;let a=i.substring(e,e+n),l=i.substring(e+n),d="("+s+")"+a,h=ve.parseFieldsInGeneralPurpose(l);return h==null?d:d+h}static processVariableAI(e,n,i){let s=i.substring(0,e),a;i.length<e+n?a=i.length:a=e+n;let l=i.substring(e,a),d=i.substring(a),h="("+s+")"+l,g=ve.parseFieldsInGeneralPurpose(d);return g==null?h:h+g}}ve.VARIABLE_LENGTH=[],ve.TWO_DIGIT_DATA_LENGTH=[["00",18],["01",14],["02",14],["10",ve.VARIABLE_LENGTH,20],["11",6],["12",6],["13",6],["15",6],["17",6],["20",2],["21",ve.VARIABLE_LENGTH,20],["22",ve.VARIABLE_LENGTH,29],["30",ve.VARIABLE_LENGTH,8],["37",ve.VARIABLE_LENGTH,8],["90",ve.VARIABLE_LENGTH,30],["91",ve.VARIABLE_LENGTH,30],["92",ve.VARIABLE_LENGTH,30],["93",ve.VARIABLE_LENGTH,30],["94",ve.VARIABLE_LENGTH,30],["95",ve.VARIABLE_LENGTH,30],["96",ve.VARIABLE_LENGTH,30],["97",ve.VARIABLE_LENGTH,3],["98",ve.VARIABLE_LENGTH,30],["99",ve.VARIABLE_LENGTH,30]],ve.THREE_DIGIT_DATA_LENGTH=[["240",ve.VARIABLE_LENGTH,30],["241",ve.VARIABLE_LENGTH,30],["242",ve.VARIABLE_LENGTH,6],["250",ve.VARIABLE_LENGTH,30],["251",ve.VARIABLE_LENGTH,30],["253",ve.VARIABLE_LENGTH,17],["254",ve.VARIABLE_LENGTH,20],["400",ve.VARIABLE_LENGTH,30],["401",ve.VARIABLE_LENGTH,30],["402",17],["403",ve.VARIABLE_LENGTH,30],["410",13],["411",13],["412",13],["413",13],["414",13],["420",ve.VARIABLE_LENGTH,20],["421",ve.VARIABLE_LENGTH,15],["422",3],["423",ve.VARIABLE_LENGTH,15],["424",3],["425",3],["426",3]],ve.THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH=[["310",6],["311",6],["312",6],["313",6],["314",6],["315",6],["316",6],["320",6],["321",6],["322",6],["323",6],["324",6],["325",6],["326",6],["327",6],["328",6],["329",6],["330",6],["331",6],["332",6],["333",6],["334",6],["335",6],["336",6],["340",6],["341",6],["342",6],["343",6],["344",6],["345",6],["346",6],["347",6],["348",6],["349",6],["350",6],["351",6],["352",6],["353",6],["354",6],["355",6],["356",6],["357",6],["360",6],["361",6],["362",6],["363",6],["364",6],["365",6],["366",6],["367",6],["368",6],["369",6],["390",ve.VARIABLE_LENGTH,15],["391",ve.VARIABLE_LENGTH,18],["392",ve.VARIABLE_LENGTH,15],["393",ve.VARIABLE_LENGTH,18],["703",ve.VARIABLE_LENGTH,30]],ve.FOUR_DIGIT_DATA_LENGTH=[["7001",13],["7002",ve.VARIABLE_LENGTH,30],["7003",10],["8001",14],["8002",ve.VARIABLE_LENGTH,20],["8003",ve.VARIABLE_LENGTH,30],["8004",ve.VARIABLE_LENGTH,30],["8005",6],["8006",18],["8007",ve.VARIABLE_LENGTH,30],["8008",ve.VARIABLE_LENGTH,12],["8018",18],["8020",ve.VARIABLE_LENGTH,25],["8100",6],["8101",10],["8102",2],["8110",ve.VARIABLE_LENGTH,70],["8200",ve.VARIABLE_LENGTH,70]];class pr{constructor(e){this.buffer=new oe,this.information=e}decodeAllCodes(e,n){let i=n,s=null;do{let a=this.decodeGeneralPurposeField(i,s),l=ve.parseFieldsInGeneralPurpose(a.getNewString());if(l!=null&&e.append(l),a.isRemaining()?s=""+a.getRemainingValue():s=null,i===a.getNewPosition())break;i=a.getNewPosition()}while(!0);return e.toString()}isStillNumeric(e){if(e+7>this.information.getSize())return e+4<=this.information.getSize();for(let n=e;n<e+3;++n)if(this.information.get(n))return!0;return this.information.get(e+3)}decodeNumeric(e){if(e+7>this.information.getSize()){let a=this.extractNumericValueFromBitArray(e,4);return a===0?new cn(this.information.getSize(),cn.FNC1,cn.FNC1):new cn(this.information.getSize(),a-1,cn.FNC1)}let n=this.extractNumericValueFromBitArray(e,7),i=(n-8)/11,s=(n-8)%11;return new cn(e+7,i,s)}extractNumericValueFromBitArray(e,n){return pr.extractNumericValueFromBitArray(this.information,e,n)}static extractNumericValueFromBitArray(e,n,i){let s=0;for(let a=0;a<i;++a)e.get(n+a)&&(s|=1<<i-a-1);return s}decodeGeneralPurposeField(e,n){this.buffer.setLengthToZero(),n!=null&&this.buffer.append(n),this.current.setPosition(e);let i=this.parseBlocks();return i!=null&&i.isRemaining()?new Kn(this.current.getPosition(),this.buffer.toString(),i.getRemainingValue()):new Kn(this.current.getPosition(),this.buffer.toString())}parseBlocks(){let e,n;do{let i=this.current.getPosition();if(this.current.isAlpha()?(n=this.parseAlphaBlock(),e=n.isFinished()):this.current.isIsoIec646()?(n=this.parseIsoIec646Block(),e=n.isFinished()):(n=this.parseNumericBlock(),e=n.isFinished()),!(i!==this.current.getPosition())&&!e)break}while(!e);return n.getDecodedInformation()}parseNumericBlock(){for(;this.isStillNumeric(this.current.getPosition());){let e=this.decodeNumeric(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFirstDigitFNC1()){let n;return e.isSecondDigitFNC1()?n=new Kn(this.current.getPosition(),this.buffer.toString()):n=new Kn(this.current.getPosition(),this.buffer.toString(),e.getSecondDigit()),new Jn(!0,n)}if(this.buffer.append(e.getFirstDigit()),e.isSecondDigitFNC1()){let n=new Kn(this.current.getPosition(),this.buffer.toString());return new Jn(!0,n)}this.buffer.append(e.getSecondDigit())}return this.isNumericToAlphaNumericLatch(this.current.getPosition())&&(this.current.setAlpha(),this.current.incrementPosition(4)),new Jn(!1)}parseIsoIec646Block(){for(;this.isStillIsoIec646(this.current.getPosition());){let e=this.decodeIsoIec646(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFNC1()){let n=new Kn(this.current.getPosition(),this.buffer.toString());return new Jn(!0,n)}this.buffer.append(e.getValue())}return this.isAlphaOr646ToNumericLatch(this.current.getPosition())?(this.current.incrementPosition(3),this.current.setNumeric()):this.isAlphaTo646ToAlphaLatch(this.current.getPosition())&&(this.current.getPosition()+5<this.information.getSize()?this.current.incrementPosition(5):this.current.setPosition(this.information.getSize()),this.current.setAlpha()),new Jn(!1)}parseAlphaBlock(){for(;this.isStillAlpha(this.current.getPosition());){let e=this.decodeAlphanumeric(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFNC1()){let n=new Kn(this.current.getPosition(),this.buffer.toString());return new Jn(!0,n)}this.buffer.append(e.getValue())}return this.isAlphaOr646ToNumericLatch(this.current.getPosition())?(this.current.incrementPosition(3),this.current.setNumeric()):this.isAlphaTo646ToAlphaLatch(this.current.getPosition())&&(this.current.getPosition()+5<this.information.getSize()?this.current.incrementPosition(5):this.current.setPosition(this.information.getSize()),this.current.setIsoIec646()),new Jn(!1)}isStillIsoIec646(e){if(e+5>this.information.getSize())return!1;let n=this.extractNumericValueFromBitArray(e,5);if(n>=5&&n<16)return!0;if(e+7>this.information.getSize())return!1;let i=this.extractNumericValueFromBitArray(e,7);if(i>=64&&i<116)return!0;if(e+8>this.information.getSize())return!1;let s=this.extractNumericValueFromBitArray(e,8);return s>=232&&s<253}decodeIsoIec646(e){let n=this.extractNumericValueFromBitArray(e,5);if(n===15)return new Xt(e+5,Xt.FNC1);if(n>=5&&n<15)return new Xt(e+5,"0"+(n-5));let i=this.extractNumericValueFromBitArray(e,7);if(i>=64&&i<90)return new Xt(e+7,""+(i+1));if(i>=90&&i<116)return new Xt(e+7,""+(i+7));let s=this.extractNumericValueFromBitArray(e,8),a;switch(s){case 232:a="!";break;case 233:a='"';break;case 234:a="%";break;case 235:a="&";break;case 236:a="'";break;case 237:a="(";break;case 238:a=")";break;case 239:a="*";break;case 240:a="+";break;case 241:a=",";break;case 242:a="-";break;case 243:a=".";break;case 244:a="/";break;case 245:a=":";break;case 246:a=";";break;case 247:a="<";break;case 248:a="=";break;case 249:a=">";break;case 250:a="?";break;case 251:a="_";break;case 252:a=" ";break;default:throw new V}return new Xt(e+8,a)}isStillAlpha(e){if(e+5>this.information.getSize())return!1;let n=this.extractNumericValueFromBitArray(e,5);if(n>=5&&n<16)return!0;if(e+6>this.information.getSize())return!1;let i=this.extractNumericValueFromBitArray(e,6);return i>=16&&i<63}decodeAlphanumeric(e){let n=this.extractNumericValueFromBitArray(e,5);if(n===15)return new Xt(e+5,Xt.FNC1);if(n>=5&&n<15)return new Xt(e+5,"0"+(n-5));let i=this.extractNumericValueFromBitArray(e,6);if(i>=32&&i<58)return new Xt(e+6,""+(i+33));let s;switch(i){case 58:s="*";break;case 59:s=",";break;case 60:s="-";break;case 61:s=".";break;case 62:s="/";break;default:throw new Vt("Decoding invalid alphanumeric value: "+i)}return new Xt(e+6,s)}isAlphaTo646ToAlphaLatch(e){if(e+1>this.information.getSize())return!1;for(let n=0;n<5&&n+e<this.information.getSize();++n)if(n===2){if(!this.information.get(e+2))return!1}else if(this.information.get(e+n))return!1;return!0}isAlphaOr646ToNumericLatch(e){if(e+3>this.information.getSize())return!1;for(let n=e;n<e+3;++n)if(this.information.get(n))return!1;return!0}isNumericToAlphaNumericLatch(e){if(e+1>this.information.getSize())return!1;for(let n=0;n<4&&n+e<this.information.getSize();++n)if(this.information.get(e+n))return!1;return!0}}class Xi{constructor(e){this.information=e,this.generalDecoder=new pr(e)}getInformation(){return this.information}getGeneralDecoder(){return this.generalDecoder}}class qt extends Xi{constructor(e){super(e)}encodeCompressedGtin(e,n){e.append("(01)");let i=e.length();e.append("9"),this.encodeCompressedGtinWithoutAI(e,n,i)}encodeCompressedGtinWithoutAI(e,n,i){for(let s=0;s<4;++s){let a=this.getGeneralDecoder().extractNumericValueFromBitArray(n+10*s,10);a/100===0&&e.append("0"),a/10===0&&e.append("0"),e.append(a)}qt.appendCheckDigit(e,i)}static appendCheckDigit(e,n){let i=0;for(let s=0;s<13;s++){let a=e.charAt(s+n).charCodeAt(0)-48;i+=(s&1)===0?3*a:a}i=10-i%10,i===10&&(i=0),e.append(i)}}qt.GTIN_SIZE=40;class gr extends qt{constructor(e){super(e)}parseInformation(){let e=new oe;e.append("(01)");let n=e.length(),i=this.getGeneralDecoder().extractNumericValueFromBitArray(gr.HEADER_SIZE,4);return e.append(i),this.encodeCompressedGtinWithoutAI(e,gr.HEADER_SIZE+4,n),this.getGeneralDecoder().decodeAllCodes(e,gr.HEADER_SIZE+44)}}gr.HEADER_SIZE=4;class ui extends Xi{constructor(e){super(e)}parseInformation(){let e=new oe;return this.getGeneralDecoder().decodeAllCodes(e,ui.HEADER_SIZE)}}ui.HEADER_SIZE=5;class di extends qt{constructor(e){super(e)}encodeCompressedWeight(e,n,i){let s=this.getGeneralDecoder().extractNumericValueFromBitArray(n,i);this.addWeightCode(e,s);let a=this.checkWeight(s),l=1e5;for(let d=0;d<5;++d)a/l===0&&e.append("0"),l/=10;e.append(a)}}class An extends di{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()!=An.HEADER_SIZE+di.GTIN_SIZE+An.WEIGHT_SIZE)throw new P;let e=new oe;return this.encodeCompressedGtin(e,An.HEADER_SIZE),this.encodeCompressedWeight(e,An.HEADER_SIZE+di.GTIN_SIZE,An.WEIGHT_SIZE),e.toString()}}An.HEADER_SIZE=5,An.WEIGHT_SIZE=15;class Gu extends An{constructor(e){super(e)}addWeightCode(e,n){e.append("(3103)")}checkWeight(e){return e}}class Xu extends An{constructor(e){super(e)}addWeightCode(e,n){n<1e4?e.append("(3202)"):e.append("(3203)")}checkWeight(e){return e<1e4?e:e-1e4}}class In extends qt{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<In.HEADER_SIZE+qt.GTIN_SIZE)throw new P;let e=new oe;this.encodeCompressedGtin(e,In.HEADER_SIZE);let n=this.getGeneralDecoder().extractNumericValueFromBitArray(In.HEADER_SIZE+qt.GTIN_SIZE,In.LAST_DIGIT_SIZE);e.append("(392"),e.append(n),e.append(")");let i=this.getGeneralDecoder().decodeGeneralPurposeField(In.HEADER_SIZE+qt.GTIN_SIZE+In.LAST_DIGIT_SIZE,null);return e.append(i.getNewString()),e.toString()}}In.HEADER_SIZE=8,In.LAST_DIGIT_SIZE=2;class Ht extends qt{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<Ht.HEADER_SIZE+qt.GTIN_SIZE)throw new P;let e=new oe;this.encodeCompressedGtin(e,Ht.HEADER_SIZE);let n=this.getGeneralDecoder().extractNumericValueFromBitArray(Ht.HEADER_SIZE+qt.GTIN_SIZE,Ht.LAST_DIGIT_SIZE);e.append("(393"),e.append(n),e.append(")");let i=this.getGeneralDecoder().extractNumericValueFromBitArray(Ht.HEADER_SIZE+qt.GTIN_SIZE+Ht.LAST_DIGIT_SIZE,Ht.FIRST_THREE_DIGITS_SIZE);i/100==0&&e.append("0"),i/10==0&&e.append("0"),e.append(i);let s=this.getGeneralDecoder().decodeGeneralPurposeField(Ht.HEADER_SIZE+qt.GTIN_SIZE+Ht.LAST_DIGIT_SIZE+Ht.FIRST_THREE_DIGITS_SIZE,null);return e.append(s.getNewString()),e.toString()}}Ht.HEADER_SIZE=8,Ht.LAST_DIGIT_SIZE=2,Ht.FIRST_THREE_DIGITS_SIZE=10;class ht extends di{constructor(e,n,i){super(e),this.dateCode=i,this.firstAIdigits=n}parseInformation(){if(this.getInformation().getSize()!=ht.HEADER_SIZE+ht.GTIN_SIZE+ht.WEIGHT_SIZE+ht.DATE_SIZE)throw new P;let e=new oe;return this.encodeCompressedGtin(e,ht.HEADER_SIZE),this.encodeCompressedWeight(e,ht.HEADER_SIZE+ht.GTIN_SIZE,ht.WEIGHT_SIZE),this.encodeCompressedDate(e,ht.HEADER_SIZE+ht.GTIN_SIZE+ht.WEIGHT_SIZE),e.toString()}encodeCompressedDate(e,n){let i=this.getGeneralDecoder().extractNumericValueFromBitArray(n,ht.DATE_SIZE);if(i==38400)return;e.append("("),e.append(this.dateCode),e.append(")");let s=i%32;i/=32;let a=i%12+1;i/=12;let l=i;l/10==0&&e.append("0"),e.append(l),a/10==0&&e.append("0"),e.append(a),s/10==0&&e.append("0"),e.append(s)}addWeightCode(e,n){e.append("("),e.append(this.firstAIdigits),e.append(n/1e5),e.append(")")}checkWeight(e){return e%1e5}}ht.HEADER_SIZE=8,ht.WEIGHT_SIZE=20,ht.DATE_SIZE=16;function cs(C){try{if(C.get(1))return new gr(C);if(!C.get(2))return new ui(C);switch(pr.extractNumericValueFromBitArray(C,1,4)){case 4:return new Gu(C);case 5:return new Xu(C)}switch(pr.extractNumericValueFromBitArray(C,1,5)){case 12:return new In(C);case 13:return new Ht(C)}switch(pr.extractNumericValueFromBitArray(C,1,7)){case 56:return new ht(C,"310","11");case 57:return new ht(C,"320","11");case 58:return new ht(C,"310","13");case 59:return new ht(C,"320","13");case 60:return new ht(C,"310","15");case 61:return new ht(C,"320","15");case 62:return new ht(C,"310","17");case 63:return new ht(C,"320","17")}}catch(e){throw console.log(e),new Vt("unknown decoder: "+C)}}class Ln{constructor(e,n,i,s){this.leftchar=e,this.rightchar=n,this.finderpattern=i,this.maybeLast=s}mayBeLast(){return this.maybeLast}getLeftChar(){return this.leftchar}getRightChar(){return this.rightchar}getFinderPattern(){return this.finderpattern}mustBeLast(){return this.rightchar==null}toString(){return"[ "+this.leftchar+", "+this.rightchar+" : "+(this.finderpattern==null?"null":this.finderpattern.getValue())+" ]"}static equals(e,n){return e instanceof Ln?Ln.equalsOrNull(e.leftchar,n.leftchar)&&Ln.equalsOrNull(e.rightchar,n.rightchar)&&Ln.equalsOrNull(e.finderpattern,n.finderpattern):!1}static equalsOrNull(e,n){return e===null?n===null:Ln.equals(e,n)}hashCode(){return this.leftchar.getValue()^this.rightchar.getValue()^this.finderpattern.getValue()}}class qi{constructor(e,n,i){this.pairs=e,this.rowNumber=n,this.wasReversed=i}getPairs(){return this.pairs}getRowNumber(){return this.rowNumber}isReversed(){return this.wasReversed}isEquivalent(e){return this.checkEqualitity(this,e)}toString(){return"{ "+this.pairs+" }"}equals(e,n){return e instanceof qi?this.checkEqualitity(e,n)&&e.wasReversed===n.wasReversed:!1}checkEqualitity(e,n){if(!e||!n)return;let i;return e.forEach((s,a)=>{n.forEach(l=>{s.getLeftChar().getValue()===l.getLeftChar().getValue()&&s.getRightChar().getValue()===l.getRightChar().getValue()&&s.getFinderPatter().getValue()===l.getFinderPatter().getValue()&&(i=!0)})}),i}}class ae extends $t{constructor(e){super(...arguments),this.pairs=new Array(ae.MAX_PAIRS),this.rows=new Array,this.startEnd=[2],this.verbose=e===!0}decodeRow(e,n,i){this.pairs.length=0,this.startFromEven=!1;try{return ae.constructResult(this.decodeRow2pairs(e,n))}catch(s){this.verbose&&console.log(s)}return this.pairs.length=0,this.startFromEven=!0,ae.constructResult(this.decodeRow2pairs(e,n))}reset(){this.pairs.length=0,this.rows.length=0}decodeRow2pairs(e,n){let i=!1;for(;!i;)try{this.pairs.push(this.retrieveNextPair(n,this.pairs,e))}catch(a){if(a instanceof P){if(!this.pairs.length)throw new P;i=!0}}if(this.checkChecksum())return this.pairs;let s;if(this.rows.length?s=!0:s=!1,this.storeRow(e,!1),s){let a=this.checkRowsBoolean(!1);if(a!=null||(a=this.checkRowsBoolean(!0),a!=null))return a}throw new P}checkRowsBoolean(e){if(this.rows.length>25)return this.rows.length=0,null;this.pairs.length=0,e&&(this.rows=this.rows.reverse());let n=null;try{n=this.checkRows(new Array,0)}catch(i){this.verbose&&console.log(i)}return e&&(this.rows=this.rows.reverse()),n}checkRows(e,n){for(let i=n;i<this.rows.length;i++){let s=this.rows[i];this.pairs.length=0;for(let l of e)this.pairs.push(l.getPairs());if(this.pairs.push(s.getPairs()),!ae.isValidSequence(this.pairs))continue;if(this.checkChecksum())return this.pairs;let a=new Array(e);a.push(s);try{return this.checkRows(a,i+1)}catch(l){this.verbose&&console.log(l)}}throw new P}static isValidSequence(e){for(let n of ae.FINDER_PATTERN_SEQUENCES){if(e.length>n.length)continue;let i=!0;for(let s=0;s<e.length;s++)if(e[s].getFinderPattern().getValue()!=n[s]){i=!1;break}if(i)return!0}return!1}storeRow(e,n){let i=0,s=!1,a=!1;for(;i<this.rows.length;){let l=this.rows[i];if(l.getRowNumber()>e){a=l.isEquivalent(this.pairs);break}s=l.isEquivalent(this.pairs),i++}a||s||ae.isPartialRow(this.pairs,this.rows)||(this.rows.push(i,new qi(this.pairs,e,n)),this.removePartialRows(this.pairs,this.rows))}removePartialRows(e,n){for(let i of n)if(i.getPairs().length!==e.length){for(let s of i.getPairs())for(let a of e)if(Ln.equals(s,a))break}}static isPartialRow(e,n){for(let i of n){let s=!0;for(let a of e){let l=!1;for(let d of i.getPairs())if(a.equals(d)){l=!0;break}if(!l){s=!1;break}}if(s)return!0}return!1}getRows(){return this.rows}static constructResult(e){let n=Wu.buildBitArray(e),s=cs(n).parseInformation(),a=e[0].getFinderPattern().getResultPoints(),l=e[e.length-1].getFinderPattern().getResultPoints(),d=[a[0],a[1],l[0],l[1]];return new Ue(s,null,null,d,ge.RSS_EXPANDED,null)}checkChecksum(){let e=this.pairs.get(0),n=e.getLeftChar(),i=e.getRightChar();if(i==null)return!1;let s=i.getChecksumPortion(),a=2;for(let d=1;d<this.pairs.size();++d){let h=this.pairs.get(d);s+=h.getLeftChar().getChecksumPortion(),a++;let g=h.getRightChar();g!=null&&(s+=g.getChecksumPortion(),a++)}return s%=211,211*(a-4)+s==n.getValue()}static getNextSecondBar(e,n){let i;return e.get(n)?(i=e.getNextUnset(n),i=e.getNextSet(i)):(i=e.getNextSet(n),i=e.getNextUnset(i)),i}retrieveNextPair(e,n,i){let s=n.length%2==0;this.startFromEven&&(s=!s);let a,l=!0,d=-1;do this.findNextPair(e,n,d),a=this.parseFoundFinderPattern(e,i,s),a==null?d=ae.getNextSecondBar(e,this.startEnd[0]):l=!1;while(l);let h=this.decodeDataCharacter(e,a,s,!0);if(!this.isEmptyPair(n)&&n[n.length-1].mustBeLast())throw new P;let g;try{g=this.decodeDataCharacter(e,a,s,!1)}catch(w){g=null,this.verbose&&console.log(w)}return new Ln(h,g,a,!0)}isEmptyPair(e){return e.length===0}findNextPair(e,n,i){let s=this.getDecodeFinderCounters();s[0]=0,s[1]=0,s[2]=0,s[3]=0;let a=e.getSize(),l;i>=0?l=i:this.isEmptyPair(n)?l=0:l=n[n.length-1].getFinderPattern().getStartEnd()[1];let d=n.length%2!=0;this.startFromEven&&(d=!d);let h=!1;for(;l<a&&(h=!e.get(l),!!h);)l++;let g=0,w=l;for(let b=l;b<a;b++)if(e.get(b)!=h)s[g]++;else{if(g==3){if(d&&ae.reverseCounters(s),ae.isFinderPattern(s)){this.startEnd[0]=w,this.startEnd[1]=b;return}d&&ae.reverseCounters(s),w+=s[0]+s[1],s[0]=s[2],s[1]=s[3],s[2]=0,s[3]=0,g--}else g++;s[g]=1,h=!h}throw new P}static reverseCounters(e){let n=e.length;for(let i=0;i<n/2;++i){let s=e[i];e[i]=e[n-i-1],e[n-i-1]=s}}parseFoundFinderPattern(e,n,i){let s,a,l;if(i){let g=this.startEnd[0]-1;for(;g>=0&&!e.get(g);)g--;g++,s=this.startEnd[0]-g,a=g,l=this.startEnd[1]}else a=this.startEnd[0],l=e.getNextUnset(this.startEnd[1]+1),s=l-this.startEnd[1];let d=this.getDecodeFinderCounters();R.arraycopy(d,0,d,1,d.length-1),d[0]=s;let h;try{h=this.parseFinderValue(d,ae.FINDER_PATTERNS)}catch{return null}return new ci(h,[a,l],a,l,n)}decodeDataCharacter(e,n,i,s){let a=this.getDataCharacterCounters();for(let ot=0;ot<a.length;ot++)a[ot]=0;if(s)ae.recordPatternInReverse(e,n.getStartEnd()[0],a);else{ae.recordPattern(e,n.getStartEnd()[1],a);for(let ot=0,zt=a.length-1;ot<zt;ot++,zt--){let tn=a[ot];a[ot]=a[zt],a[zt]=tn}}let l=17,d=Te.sum(new Int32Array(a))/l,h=(n.getStartEnd()[1]-n.getStartEnd()[0])/15;if(Math.abs(d-h)/h>.3)throw new P;let g=this.getOddCounts(),w=this.getEvenCounts(),b=this.getOddRoundingErrors(),I=this.getEvenRoundingErrors();for(let ot=0;ot<a.length;ot++){let zt=1*a[ot]/d,tn=zt+.5;if(tn<1){if(zt<.3)throw new P;tn=1}else if(tn>8){if(zt>8.7)throw new P;tn=8}let _r=ot/2;(ot&1)==0?(g[_r]=tn,b[_r]=zt-tn):(w[_r]=tn,I[_r]=zt-tn)}this.adjustOddEvenCounts(l);let N=4*n.getValue()+(i?0:2)+(s?0:1)-1,F=0,U=0;for(let ot=g.length-1;ot>=0;ot--){if(ae.isNotA1left(n,i,s)){let zt=ae.WEIGHTS[N][2*ot];U+=g[ot]*zt}F+=g[ot]}let W=0;for(let ot=w.length-1;ot>=0;ot--)if(ae.isNotA1left(n,i,s)){let zt=ae.WEIGHTS[N][2*ot+1];W+=w[ot]*zt}let K=U+W;if((F&1)!=0||F>13||F<4)throw new P;let fe=(13-F)/2,he=ae.SYMBOL_WIDEST[fe],ce=9-he,je=En.getRSSvalue(g,he,!0),Pe=En.getRSSvalue(w,ce,!1),Jt=ae.EVEN_TOTAL_SUBSET[fe],mn=ae.GSUM[fe],Kt=je*Jt+Pe+mn;return new hr(Kt,K)}static isNotA1left(e,n,i){return!(e.getValue()==0&&n&&i)}adjustOddEvenCounts(e){let n=Te.sum(new Int32Array(this.getOddCounts())),i=Te.sum(new Int32Array(this.getEvenCounts())),s=!1,a=!1;n>13?a=!0:n<4&&(s=!0);let l=!1,d=!1;i>13?d=!0:i<4&&(l=!0);let h=n+i-e,g=(n&1)==1,w=(i&1)==0;if(h==1)if(g){if(w)throw new P;a=!0}else{if(!w)throw new P;d=!0}else if(h==-1)if(g){if(w)throw new P;s=!0}else{if(!w)throw new P;l=!0}else if(h==0){if(g){if(!w)throw new P;n<i?(s=!0,d=!0):(a=!0,l=!0)}else if(w)throw new P}else throw new P;if(s){if(a)throw new P;ae.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(a&&ae.decrement(this.getOddCounts(),this.getOddRoundingErrors()),l){if(d)throw new P;ae.increment(this.getEvenCounts(),this.getOddRoundingErrors())}d&&ae.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}ae.SYMBOL_WIDEST=[7,5,4,3,1],ae.EVEN_TOTAL_SUBSET=[4,20,52,104,204],ae.GSUM=[0,348,1388,2948,3988],ae.FINDER_PATTERNS=[Int32Array.from([1,8,4,1]),Int32Array.from([3,6,4,1]),Int32Array.from([3,4,6,1]),Int32Array.from([3,2,8,1]),Int32Array.from([2,6,5,1]),Int32Array.from([2,2,9,1])],ae.WEIGHTS=[[1,3,9,27,81,32,96,77],[20,60,180,118,143,7,21,63],[189,145,13,39,117,140,209,205],[193,157,49,147,19,57,171,91],[62,186,136,197,169,85,44,132],[185,133,188,142,4,12,36,108],[113,128,173,97,80,29,87,50],[150,28,84,41,123,158,52,156],[46,138,203,187,139,206,196,166],[76,17,51,153,37,111,122,155],[43,129,176,106,107,110,119,146],[16,48,144,10,30,90,59,177],[109,116,137,200,178,112,125,164],[70,210,208,202,184,130,179,115],[134,191,151,31,93,68,204,190],[148,22,66,198,172,94,71,2],[6,18,54,162,64,192,154,40],[120,149,25,75,14,42,126,167],[79,26,78,23,69,207,199,175],[103,98,83,38,114,131,182,124],[161,61,183,127,170,88,53,159],[55,165,73,8,24,72,5,15],[45,135,194,160,58,174,100,89]],ae.FINDER_PAT_A=0,ae.FINDER_PAT_B=1,ae.FINDER_PAT_C=2,ae.FINDER_PAT_D=3,ae.FINDER_PAT_E=4,ae.FINDER_PAT_F=5,ae.FINDER_PATTERN_SEQUENCES=[[ae.FINDER_PAT_A,ae.FINDER_PAT_A],[ae.FINDER_PAT_A,ae.FINDER_PAT_B,ae.FINDER_PAT_B],[ae.FINDER_PAT_A,ae.FINDER_PAT_C,ae.FINDER_PAT_B,ae.FINDER_PAT_D],[ae.FINDER_PAT_A,ae.FINDER_PAT_E,ae.FINDER_PAT_B,ae.FINDER_PAT_D,ae.FINDER_PAT_C],[ae.FINDER_PAT_A,ae.FINDER_PAT_E,ae.FINDER_PAT_B,ae.FINDER_PAT_D,ae.FINDER_PAT_D,ae.FINDER_PAT_F],[ae.FINDER_PAT_A,ae.FINDER_PAT_E,ae.FINDER_PAT_B,ae.FINDER_PAT_D,ae.FINDER_PAT_E,ae.FINDER_PAT_F,ae.FINDER_PAT_F],[ae.FINDER_PAT_A,ae.FINDER_PAT_A,ae.FINDER_PAT_B,ae.FINDER_PAT_B,ae.FINDER_PAT_C,ae.FINDER_PAT_C,ae.FINDER_PAT_D,ae.FINDER_PAT_D],[ae.FINDER_PAT_A,ae.FINDER_PAT_A,ae.FINDER_PAT_B,ae.FINDER_PAT_B,ae.FINDER_PAT_C,ae.FINDER_PAT_C,ae.FINDER_PAT_D,ae.FINDER_PAT_E,ae.FINDER_PAT_E],[ae.FINDER_PAT_A,ae.FINDER_PAT_A,ae.FINDER_PAT_B,ae.FINDER_PAT_B,ae.FINDER_PAT_C,ae.FINDER_PAT_C,ae.FINDER_PAT_D,ae.FINDER_PAT_E,ae.FINDER_PAT_F,ae.FINDER_PAT_F],[ae.FINDER_PAT_A,ae.FINDER_PAT_A,ae.FINDER_PAT_B,ae.FINDER_PAT_B,ae.FINDER_PAT_C,ae.FINDER_PAT_D,ae.FINDER_PAT_D,ae.FINDER_PAT_E,ae.FINDER_PAT_E,ae.FINDER_PAT_F,ae.FINDER_PAT_F]],ae.MAX_PAIRS=11;class qu extends hr{constructor(e,n,i){super(e,n),this.count=0,this.finderPattern=i}getFinderPattern(){return this.finderPattern}getCount(){return this.count}incrementCount(){this.count++}}class vt extends $t{constructor(){super(...arguments),this.possibleLeftPairs=[],this.possibleRightPairs=[]}decodeRow(e,n,i){const s=this.decodePair(n,!1,e,i);vt.addOrTally(this.possibleLeftPairs,s),n.reverse();let a=this.decodePair(n,!0,e,i);vt.addOrTally(this.possibleRightPairs,a),n.reverse();for(let l of this.possibleLeftPairs)if(l.getCount()>1){for(let d of this.possibleRightPairs)if(d.getCount()>1&&vt.checkChecksum(l,d))return vt.constructResult(l,d)}throw new P}static addOrTally(e,n){if(n==null)return;let i=!1;for(let s of e)if(s.getValue()===n.getValue()){s.incrementCount(),i=!0;break}i||e.push(n)}reset(){this.possibleLeftPairs.length=0,this.possibleRightPairs.length=0}static constructResult(e,n){let i=4537077*e.getValue()+n.getValue(),s=new String(i).toString(),a=new oe;for(let g=13-s.length;g>0;g--)a.append("0");a.append(s);let l=0;for(let g=0;g<13;g++){let w=a.charAt(g).charCodeAt(0)-48;l+=(g&1)===0?3*w:w}l=10-l%10,l===10&&(l=0),a.append(l.toString());let d=e.getFinderPattern().getResultPoints(),h=n.getFinderPattern().getResultPoints();return new Ue(a.toString(),null,0,[d[0],d[1],h[0],h[1]],ge.RSS_14,new Date().getTime())}static checkChecksum(e,n){let i=(e.getChecksumPortion()+16*n.getChecksumPortion())%79,s=9*e.getFinderPattern().getValue()+n.getFinderPattern().getValue();return s>72&&s--,s>8&&s--,i===s}decodePair(e,n,i,s){try{let a=this.findFinderPattern(e,n),l=this.parseFoundFinderPattern(e,i,n,a),d=s==null?null:s.get(O.NEED_RESULT_POINT_CALLBACK);if(d!=null){let w=(a[0]+a[1])/2;n&&(w=e.getSize()-1-w),d.foundPossibleResultPoint(new be(w,i))}let h=this.decodeDataCharacter(e,l,!0),g=this.decodeDataCharacter(e,l,!1);return new qu(1597*h.getValue()+g.getValue(),h.getChecksumPortion()+4*g.getChecksumPortion(),l)}catch{return null}}decodeDataCharacter(e,n,i){let s=this.getDataCharacterCounters();for(let W=0;W<s.length;W++)s[W]=0;if(i)ke.recordPatternInReverse(e,n.getStartEnd()[0],s);else{ke.recordPattern(e,n.getStartEnd()[1]+1,s);for(let W=0,K=s.length-1;W<K;W++,K--){let fe=s[W];s[W]=s[K],s[K]=fe}}let a=i?16:15,l=Te.sum(new Int32Array(s))/a,d=this.getOddCounts(),h=this.getEvenCounts(),g=this.getOddRoundingErrors(),w=this.getEvenRoundingErrors();for(let W=0;W<s.length;W++){let K=s[W]/l,fe=Math.floor(K+.5);fe<1?fe=1:fe>8&&(fe=8);let he=Math.floor(W/2);(W&1)===0?(d[he]=fe,g[he]=K-fe):(h[he]=fe,w[he]=K-fe)}this.adjustOddEvenCounts(i,a);let b=0,I=0;for(let W=d.length-1;W>=0;W--)I*=9,I+=d[W],b+=d[W];let N=0,F=0;for(let W=h.length-1;W>=0;W--)N*=9,N+=h[W],F+=h[W];let U=I+3*N;if(i){if((b&1)!==0||b>12||b<4)throw new P;let W=(12-b)/2,K=vt.OUTSIDE_ODD_WIDEST[W],fe=9-K,he=En.getRSSvalue(d,K,!1),ce=En.getRSSvalue(h,fe,!0),je=vt.OUTSIDE_EVEN_TOTAL_SUBSET[W],Pe=vt.OUTSIDE_GSUM[W];return new hr(he*je+ce+Pe,U)}else{if((F&1)!==0||F>10||F<4)throw new P;let W=(10-F)/2,K=vt.INSIDE_ODD_WIDEST[W],fe=9-K,he=En.getRSSvalue(d,K,!0),ce=En.getRSSvalue(h,fe,!1),je=vt.INSIDE_ODD_TOTAL_SUBSET[W],Pe=vt.INSIDE_GSUM[W];return new hr(ce*je+he+Pe,U)}}findFinderPattern(e,n){let i=this.getDecodeFinderCounters();i[0]=0,i[1]=0,i[2]=0,i[3]=0;let s=e.getSize(),a=!1,l=0;for(;l<s&&(a=!e.get(l),n!==a);)l++;let d=0,h=l;for(let g=l;g<s;g++)if(e.get(g)!==a)i[d]++;else{if(d===3){if($t.isFinderPattern(i))return[h,g];h+=i[0]+i[1],i[0]=i[2],i[1]=i[3],i[2]=0,i[3]=0,d--}else d++;i[d]=1,a=!a}throw new P}parseFoundFinderPattern(e,n,i,s){let a=e.get(s[0]),l=s[0]-1;for(;l>=0&&a!==e.get(l);)l--;l++;const d=s[0]-l,h=this.getDecodeFinderCounters(),g=new Int32Array(h.length);R.arraycopy(h,0,g,1,h.length-1),g[0]=d;const w=this.parseFinderValue(g,vt.FINDER_PATTERNS);let b=l,I=s[1];return i&&(b=e.getSize()-1-b,I=e.getSize()-1-I),new ci(w,[l,s[1]],b,I,n)}adjustOddEvenCounts(e,n){let i=Te.sum(new Int32Array(this.getOddCounts())),s=Te.sum(new Int32Array(this.getEvenCounts())),a=!1,l=!1,d=!1,h=!1;e?(i>12?l=!0:i<4&&(a=!0),s>12?h=!0:s<4&&(d=!0)):(i>11?l=!0:i<5&&(a=!0),s>10?h=!0:s<4&&(d=!0));let g=i+s-n,w=(i&1)===(e?1:0),b=(s&1)===1;if(g===1)if(w){if(b)throw new P;l=!0}else{if(!b)throw new P;h=!0}else if(g===-1)if(w){if(b)throw new P;a=!0}else{if(!b)throw new P;d=!0}else if(g===0){if(w){if(!b)throw new P;i<s?(a=!0,h=!0):(l=!0,d=!0)}else if(b)throw new P}else throw new P;if(a){if(l)throw new P;$t.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(l&&$t.decrement(this.getOddCounts(),this.getOddRoundingErrors()),d){if(h)throw new P;$t.increment(this.getEvenCounts(),this.getOddRoundingErrors())}h&&$t.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}vt.OUTSIDE_EVEN_TOTAL_SUBSET=[1,10,34,70,126],vt.INSIDE_ODD_TOTAL_SUBSET=[4,20,48,81],vt.OUTSIDE_GSUM=[0,161,961,2015,2715],vt.INSIDE_GSUM=[0,336,1036,1516],vt.OUTSIDE_ODD_WIDEST=[8,6,4,3,1],vt.INSIDE_ODD_WIDEST=[2,4,6,8],vt.FINDER_PATTERNS=[Int32Array.from([3,8,2,1]),Int32Array.from([3,5,5,1]),Int32Array.from([3,3,7,1]),Int32Array.from([3,1,9,1]),Int32Array.from([2,7,4,1]),Int32Array.from([2,5,6,1]),Int32Array.from([2,3,8,1]),Int32Array.from([1,5,7,1]),Int32Array.from([1,3,9,1])];class mr extends ke{constructor(e,n){super(),this.readers=[],this.verbose=n===!0;const i=e?e.get(O.POSSIBLE_FORMATS):null,s=e&&e.get(O.ASSUME_CODE_39_CHECK_DIGIT)!==void 0;i?((i.includes(ge.EAN_13)||i.includes(ge.UPC_A)||i.includes(ge.EAN_8)||i.includes(ge.UPC_E))&&this.readers.push(new Wi(e)),i.includes(ge.CODE_39)&&this.readers.push(new St(s)),i.includes(ge.CODE_128)&&this.readers.push(new pe),i.includes(ge.ITF)&&this.readers.push(new rt),i.includes(ge.RSS_14)&&this.readers.push(new vt),i.includes(ge.RSS_EXPANDED)&&this.readers.push(new ae(this.verbose))):(this.readers.push(new Wi(e)),this.readers.push(new St),this.readers.push(new Wi(e)),this.readers.push(new pe),this.readers.push(new rt),this.readers.push(new vt),this.readers.push(new ae(this.verbose)))}decodeRow(e,n,i){for(let s=0;s<this.readers.length;s++)try{return this.readers[s].decodeRow(e,n,i)}catch{}throw new P}reset(){this.readers.forEach(e=>e.reset())}}class Yu extends Ze{constructor(e=500,n){super(new mr(n),e,n)}}class Je{constructor(e,n,i){this.ecCodewords=e,this.ecBlocks=[n],i&&this.ecBlocks.push(i)}getECCodewords(){return this.ecCodewords}getECBlocks(){return this.ecBlocks}}class qe{constructor(e,n){this.count=e,this.dataCodewords=n}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class He{constructor(e,n,i,s,a,l){this.versionNumber=e,this.symbolSizeRows=n,this.symbolSizeColumns=i,this.dataRegionSizeRows=s,this.dataRegionSizeColumns=a,this.ecBlocks=l;let d=0;const h=l.getECCodewords(),g=l.getECBlocks();for(let w of g)d+=w.getCount()*(w.getDataCodewords()+h);this.totalCodewords=d}getVersionNumber(){return this.versionNumber}getSymbolSizeRows(){return this.symbolSizeRows}getSymbolSizeColumns(){return this.symbolSizeColumns}getDataRegionSizeRows(){return this.dataRegionSizeRows}getDataRegionSizeColumns(){return this.dataRegionSizeColumns}getTotalCodewords(){return this.totalCodewords}getECBlocks(){return this.ecBlocks}static getVersionForDimensions(e,n){if((e&1)!==0||(n&1)!==0)throw new V;for(let i of He.VERSIONS)if(i.symbolSizeRows===e&&i.symbolSizeColumns===n)return i;throw new V}toString(){return""+this.versionNumber}static buildVersions(){return[new He(1,10,10,8,8,new Je(5,new qe(1,3))),new He(2,12,12,10,10,new Je(7,new qe(1,5))),new He(3,14,14,12,12,new Je(10,new qe(1,8))),new He(4,16,16,14,14,new Je(12,new qe(1,12))),new He(5,18,18,16,16,new Je(14,new qe(1,18))),new He(6,20,20,18,18,new Je(18,new qe(1,22))),new He(7,22,22,20,20,new Je(20,new qe(1,30))),new He(8,24,24,22,22,new Je(24,new qe(1,36))),new He(9,26,26,24,24,new Je(28,new qe(1,44))),new He(10,32,32,14,14,new Je(36,new qe(1,62))),new He(11,36,36,16,16,new Je(42,new qe(1,86))),new He(12,40,40,18,18,new Je(48,new qe(1,114))),new He(13,44,44,20,20,new Je(56,new qe(1,144))),new He(14,48,48,22,22,new Je(68,new qe(1,174))),new He(15,52,52,24,24,new Je(42,new qe(2,102))),new He(16,64,64,14,14,new Je(56,new qe(2,140))),new He(17,72,72,16,16,new Je(36,new qe(4,92))),new He(18,80,80,18,18,new Je(48,new qe(4,114))),new He(19,88,88,20,20,new Je(56,new qe(4,144))),new He(20,96,96,22,22,new Je(68,new qe(4,174))),new He(21,104,104,24,24,new Je(56,new qe(6,136))),new He(22,120,120,18,18,new Je(68,new qe(6,175))),new He(23,132,132,20,20,new Je(62,new qe(8,163))),new He(24,144,144,22,22,new Je(62,new qe(8,156),new qe(2,155))),new He(25,8,18,6,16,new Je(7,new qe(1,5))),new He(26,8,32,6,14,new Je(11,new qe(1,10))),new He(27,12,26,10,24,new Je(14,new qe(1,16))),new He(28,12,36,10,16,new Je(18,new qe(1,22))),new He(29,16,36,14,16,new Je(24,new qe(1,32))),new He(30,16,48,14,22,new Je(28,new qe(1,49)))]}}He.VERSIONS=He.buildVersions();class Yi{constructor(e){const n=e.getHeight();if(n<8||n>144||(n&1)!==0)throw new V;this.version=Yi.readVersion(e),this.mappingBitMatrix=this.extractDataRegion(e),this.readMappingMatrix=new ee(this.mappingBitMatrix.getWidth(),this.mappingBitMatrix.getHeight())}getVersion(){return this.version}static readVersion(e){const n=e.getHeight(),i=e.getWidth();return He.getVersionForDimensions(n,i)}readCodewords(){const e=new Int8Array(this.version.getTotalCodewords());let n=0,i=4,s=0;const a=this.mappingBitMatrix.getHeight(),l=this.mappingBitMatrix.getWidth();let d=!1,h=!1,g=!1,w=!1;do if(i===a&&s===0&&!d)e[n++]=this.readCorner1(a,l)&255,i-=2,s+=2,d=!0;else if(i===a-2&&s===0&&(l&3)!==0&&!h)e[n++]=this.readCorner2(a,l)&255,i-=2,s+=2,h=!0;else if(i===a+4&&s===2&&(l&7)===0&&!g)e[n++]=this.readCorner3(a,l)&255,i-=2,s+=2,g=!0;else if(i===a-2&&s===0&&(l&7)===4&&!w)e[n++]=this.readCorner4(a,l)&255,i-=2,s+=2,w=!0;else{do i<a&&s>=0&&!this.readMappingMatrix.get(s,i)&&(e[n++]=this.readUtah(i,s,a,l)&255),i-=2,s+=2;while(i>=0&&s<l);i+=1,s+=3;do i>=0&&s<l&&!this.readMappingMatrix.get(s,i)&&(e[n++]=this.readUtah(i,s,a,l)&255),i+=2,s-=2;while(i<a&&s>=0);i+=3,s+=1}while(i<a||s<l);if(n!==this.version.getTotalCodewords())throw new V;return e}readModule(e,n,i,s){return e<0&&(e+=i,n+=4-(i+4&7)),n<0&&(n+=s,e+=4-(s+4&7)),this.readMappingMatrix.set(n,e),this.mappingBitMatrix.get(n,e)}readUtah(e,n,i,s){let a=0;return this.readModule(e-2,n-2,i,s)&&(a|=1),a<<=1,this.readModule(e-2,n-1,i,s)&&(a|=1),a<<=1,this.readModule(e-1,n-2,i,s)&&(a|=1),a<<=1,this.readModule(e-1,n-1,i,s)&&(a|=1),a<<=1,this.readModule(e-1,n,i,s)&&(a|=1),a<<=1,this.readModule(e,n-2,i,s)&&(a|=1),a<<=1,this.readModule(e,n-1,i,s)&&(a|=1),a<<=1,this.readModule(e,n,i,s)&&(a|=1),a}readCorner1(e,n){let i=0;return this.readModule(e-1,0,e,n)&&(i|=1),i<<=1,this.readModule(e-1,1,e,n)&&(i|=1),i<<=1,this.readModule(e-1,2,e,n)&&(i|=1),i<<=1,this.readModule(0,n-2,e,n)&&(i|=1),i<<=1,this.readModule(0,n-1,e,n)&&(i|=1),i<<=1,this.readModule(1,n-1,e,n)&&(i|=1),i<<=1,this.readModule(2,n-1,e,n)&&(i|=1),i<<=1,this.readModule(3,n-1,e,n)&&(i|=1),i}readCorner2(e,n){let i=0;return this.readModule(e-3,0,e,n)&&(i|=1),i<<=1,this.readModule(e-2,0,e,n)&&(i|=1),i<<=1,this.readModule(e-1,0,e,n)&&(i|=1),i<<=1,this.readModule(0,n-4,e,n)&&(i|=1),i<<=1,this.readModule(0,n-3,e,n)&&(i|=1),i<<=1,this.readModule(0,n-2,e,n)&&(i|=1),i<<=1,this.readModule(0,n-1,e,n)&&(i|=1),i<<=1,this.readModule(1,n-1,e,n)&&(i|=1),i}readCorner3(e,n){let i=0;return this.readModule(e-1,0,e,n)&&(i|=1),i<<=1,this.readModule(e-1,n-1,e,n)&&(i|=1),i<<=1,this.readModule(0,n-3,e,n)&&(i|=1),i<<=1,this.readModule(0,n-2,e,n)&&(i|=1),i<<=1,this.readModule(0,n-1,e,n)&&(i|=1),i<<=1,this.readModule(1,n-3,e,n)&&(i|=1),i<<=1,this.readModule(1,n-2,e,n)&&(i|=1),i<<=1,this.readModule(1,n-1,e,n)&&(i|=1),i}readCorner4(e,n){let i=0;return this.readModule(e-3,0,e,n)&&(i|=1),i<<=1,this.readModule(e-2,0,e,n)&&(i|=1),i<<=1,this.readModule(e-1,0,e,n)&&(i|=1),i<<=1,this.readModule(0,n-2,e,n)&&(i|=1),i<<=1,this.readModule(0,n-1,e,n)&&(i|=1),i<<=1,this.readModule(1,n-1,e,n)&&(i|=1),i<<=1,this.readModule(2,n-1,e,n)&&(i|=1),i<<=1,this.readModule(3,n-1,e,n)&&(i|=1),i}extractDataRegion(e){const n=this.version.getSymbolSizeRows(),i=this.version.getSymbolSizeColumns();if(e.getHeight()!==n)throw new E("Dimension of bitMatrix must match the version size");const s=this.version.getDataRegionSizeRows(),a=this.version.getDataRegionSizeColumns(),l=n/s|0,d=i/a|0,h=l*s,g=d*a,w=new ee(g,h);for(let b=0;b<l;++b){const I=b*s;for(let N=0;N<d;++N){const F=N*a;for(let U=0;U<s;++U){const W=b*(s+2)+1+U,K=I+U;for(let fe=0;fe<a;++fe){const he=N*(a+2)+1+fe;if(e.get(he,W)){const ce=F+fe;w.set(ce,K)}}}}}return w}}class Ji{constructor(e,n){this.numDataCodewords=e,this.codewords=n}static getDataBlocks(e,n){const i=n.getECBlocks();let s=0;const a=i.getECBlocks();for(let U of a)s+=U.getCount();const l=new Array(s);let d=0;for(let U of a)for(let W=0;W<U.getCount();W++){const K=U.getDataCodewords(),fe=i.getECCodewords()+K;l[d++]=new Ji(K,new Uint8Array(fe))}const g=l[0].codewords.length-i.getECCodewords(),w=g-1;let b=0;for(let U=0;U<w;U++)for(let W=0;W<d;W++)l[W].codewords[U]=e[b++];const I=n.getVersionNumber()===24,N=I?8:d;for(let U=0;U<N;U++)l[U].codewords[g-1]=e[b++];const F=l[0].codewords.length;for(let U=g;U<F;U++)for(let W=0;W<d;W++){const K=I?(W+8)%d:W,fe=I&&K>7?U-1:U;l[K].codewords[fe]=e[b++]}if(b!==e.length)throw new E;return l}getNumDataCodewords(){return this.numDataCodewords}getCodewords(){return this.codewords}}class Ki{constructor(e){this.bytes=e,this.byteOffset=0,this.bitOffset=0}getBitOffset(){return this.bitOffset}getByteOffset(){return this.byteOffset}readBits(e){if(e<1||e>32||e>this.available())throw new E(""+e);let n=0,i=this.bitOffset,s=this.byteOffset;const a=this.bytes;if(i>0){const l=8-i,d=e<l?e:l,h=l-d,g=255>>8-d<<h;n=(a[s]&g)>>h,e-=d,i+=d,i===8&&(i=0,s++)}if(e>0){for(;e>=8;)n=n<<8|a[s]&255,s++,e-=8;if(e>0){const l=8-e,d=255>>l<<l;n=n<<e|(a[s]&d)>>l,i+=e}}return this.bitOffset=i,this.byteOffset=s,n}available(){return 8*(this.bytes.length-this.byteOffset)-this.bitOffset}}var Ot;(function(C){C[C.PAD_ENCODE=0]="PAD_ENCODE",C[C.ASCII_ENCODE=1]="ASCII_ENCODE",C[C.C40_ENCODE=2]="C40_ENCODE",C[C.TEXT_ENCODE=3]="TEXT_ENCODE",C[C.ANSIX12_ENCODE=4]="ANSIX12_ENCODE",C[C.EDIFACT_ENCODE=5]="EDIFACT_ENCODE",C[C.BASE256_ENCODE=6]="BASE256_ENCODE"})(Ot||(Ot={}));class Fn{static decode(e){const n=new Ki(e),i=new oe,s=new oe,a=new Array;let l=Ot.ASCII_ENCODE;do if(l===Ot.ASCII_ENCODE)l=this.decodeAsciiSegment(n,i,s);else{switch(l){case Ot.C40_ENCODE:this.decodeC40Segment(n,i);break;case Ot.TEXT_ENCODE:this.decodeTextSegment(n,i);break;case Ot.ANSIX12_ENCODE:this.decodeAnsiX12Segment(n,i);break;case Ot.EDIFACT_ENCODE:this.decodeEdifactSegment(n,i);break;case Ot.BASE256_ENCODE:this.decodeBase256Segment(n,i,a);break;default:throw new V}l=Ot.ASCII_ENCODE}while(l!==Ot.PAD_ENCODE&&n.available()>0);return s.length()>0&&i.append(s.toString()),new Nt(e,i.toString(),a.length===0?null:a,null)}static decodeAsciiSegment(e,n,i){let s=!1;do{let a=e.readBits(8);if(a===0)throw new V;if(a<=128)return s&&(a+=128),n.append(String.fromCharCode(a-1)),Ot.ASCII_ENCODE;if(a===129)return Ot.PAD_ENCODE;if(a<=229){const l=a-130;l<10&&n.append("0"),n.append(""+l)}else switch(a){case 230:return Ot.C40_ENCODE;case 231:return Ot.BASE256_ENCODE;case 232:n.append("");break;case 233:case 234:break;case 235:s=!0;break;case 236:n.append("[)>05"),i.insert(0,"");break;case 237:n.append("[)>06"),i.insert(0,"");break;case 238:return Ot.ANSIX12_ENCODE;case 239:return Ot.TEXT_ENCODE;case 240:return Ot.EDIFACT_ENCODE;case 241:break;default:if(a!==254||e.available()!==0)throw new V;break}}while(e.available()>0);return Ot.ASCII_ENCODE}static decodeC40Segment(e,n){let i=!1;const s=[];let a=0;do{if(e.available()===8)return;const l=e.readBits(8);if(l===254)return;this.parseTwoBytes(l,e.readBits(8),s);for(let d=0;d<3;d++){const h=s[d];switch(a){case 0:if(h<3)a=h+1;else if(h<this.C40_BASIC_SET_CHARS.length){const g=this.C40_BASIC_SET_CHARS[h];i?(n.append(String.fromCharCode(g.charCodeAt(0)+128)),i=!1):n.append(g)}else throw new V;break;case 1:i?(n.append(String.fromCharCode(h+128)),i=!1):n.append(String.fromCharCode(h)),a=0;break;case 2:if(h<this.C40_SHIFT2_SET_CHARS.length){const g=this.C40_SHIFT2_SET_CHARS[h];i?(n.append(String.fromCharCode(g.charCodeAt(0)+128)),i=!1):n.append(g)}else switch(h){case 27:n.append("");break;case 30:i=!0;break;default:throw new V}a=0;break;case 3:i?(n.append(String.fromCharCode(h+224)),i=!1):n.append(String.fromCharCode(h+96)),a=0;break;default:throw new V}}}while(e.available()>0)}static decodeTextSegment(e,n){let i=!1,s=[],a=0;do{if(e.available()===8)return;const l=e.readBits(8);if(l===254)return;this.parseTwoBytes(l,e.readBits(8),s);for(let d=0;d<3;d++){const h=s[d];switch(a){case 0:if(h<3)a=h+1;else if(h<this.TEXT_BASIC_SET_CHARS.length){const g=this.TEXT_BASIC_SET_CHARS[h];i?(n.append(String.fromCharCode(g.charCodeAt(0)+128)),i=!1):n.append(g)}else throw new V;break;case 1:i?(n.append(String.fromCharCode(h+128)),i=!1):n.append(String.fromCharCode(h)),a=0;break;case 2:if(h<this.TEXT_SHIFT2_SET_CHARS.length){const g=this.TEXT_SHIFT2_SET_CHARS[h];i?(n.append(String.fromCharCode(g.charCodeAt(0)+128)),i=!1):n.append(g)}else switch(h){case 27:n.append("");break;case 30:i=!0;break;default:throw new V}a=0;break;case 3:if(h<this.TEXT_SHIFT3_SET_CHARS.length){const g=this.TEXT_SHIFT3_SET_CHARS[h];i?(n.append(String.fromCharCode(g.charCodeAt(0)+128)),i=!1):n.append(g),a=0}else throw new V;break;default:throw new V}}}while(e.available()>0)}static decodeAnsiX12Segment(e,n){const i=[];do{if(e.available()===8)return;const s=e.readBits(8);if(s===254)return;this.parseTwoBytes(s,e.readBits(8),i);for(let a=0;a<3;a++){const l=i[a];switch(l){case 0:n.append("\r");break;case 1:n.append("*");break;case 2:n.append(">");break;case 3:n.append(" ");break;default:if(l<14)n.append(String.fromCharCode(l+44));else if(l<40)n.append(String.fromCharCode(l+51));else throw new V;break}}}while(e.available()>0)}static parseTwoBytes(e,n,i){let s=(e<<8)+n-1,a=Math.floor(s/1600);i[0]=a,s-=a*1600,a=Math.floor(s/40),i[1]=a,i[2]=s-a*40}static decodeEdifactSegment(e,n){do{if(e.available()<=16)return;for(let i=0;i<4;i++){let s=e.readBits(6);if(s===31){const a=8-e.getBitOffset();a!==8&&e.readBits(a);return}(s&32)===0&&(s|=64),n.append(String.fromCharCode(s))}}while(e.available()>0)}static decodeBase256Segment(e,n,i){let s=1+e.getByteOffset();const a=this.unrandomize255State(e.readBits(8),s++);let l;if(a===0?l=e.available()/8|0:a<250?l=a:l=250*(a-249)+this.unrandomize255State(e.readBits(8),s++),l<0)throw new V;const d=new Uint8Array(l);for(let h=0;h<l;h++){if(e.available()<8)throw new V;d[h]=this.unrandomize255State(e.readBits(8),s++)}i.push(d);try{n.append(de.decode(d,ne.ISO88591))}catch(h){throw new Vt("Platform does not support required encoding: "+h.message)}}static unrandomize255State(e,n){const i=149*n%255+1,s=e-i;return s>=0?s:s+256}}Fn.C40_BASIC_SET_CHARS=["*","*","*"," ","0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],Fn.C40_SHIFT2_SET_CHARS=["!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/",":",";","<","=",">","?","@","[","\\","]","^","_"],Fn.TEXT_BASIC_SET_CHARS=["*","*","*"," ","0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],Fn.TEXT_SHIFT2_SET_CHARS=Fn.C40_SHIFT2_SET_CHARS,Fn.TEXT_SHIFT3_SET_CHARS=["`","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","{","|","}","~",""];class Ju{constructor(){this.rsDecoder=new Cn(Be.DATA_MATRIX_FIELD_256)}decode(e){const n=new Yi(e),i=n.getVersion(),s=n.readCodewords(),a=Ji.getDataBlocks(s,i);let l=0;for(let g of a)l+=g.getNumDataCodewords();const d=new Uint8Array(l),h=a.length;for(let g=0;g<h;g++){const w=a[g],b=w.getCodewords(),I=w.getNumDataCodewords();this.correctErrors(b,I);for(let N=0;N<I;N++)d[N*h+g]=b[N]}return Fn.decode(d)}correctErrors(e,n){const i=new Int32Array(e);try{this.rsDecoder.decode(i,e.length-n)}catch{throw new D}for(let s=0;s<n;s++)e[s]=i[s]}}class Tt{constructor(e){this.image=e,this.rectangleDetector=new pn(this.image)}detect(){const e=this.rectangleDetector.detect();let n=this.detectSolid1(e);if(n=this.detectSolid2(n),n[3]=this.correctTopRight(n),!n[3])throw new P;n=this.shiftToModuleCenter(n);const i=n[0],s=n[1],a=n[2],l=n[3];let d=this.transitionsBetween(i,l)+1,h=this.transitionsBetween(a,l)+1;(d&1)===1&&(d+=1),(h&1)===1&&(h+=1),4*d<7*h&&4*h<7*d&&(d=h=Math.max(d,h));let g=Tt.sampleGrid(this.image,i,s,a,l,d,h);return new fr(g,[i,s,a,l])}static shiftPoint(e,n,i){let s=(n.getX()-e.getX())/(i+1),a=(n.getY()-e.getY())/(i+1);return new be(e.getX()+s,e.getY()+a)}static moveAway(e,n,i){let s=e.getX(),a=e.getY();return s<n?s-=1:s+=1,a<i?a-=1:a+=1,new be(s,a)}detectSolid1(e){let n=e[0],i=e[1],s=e[3],a=e[2],l=this.transitionsBetween(n,i),d=this.transitionsBetween(i,s),h=this.transitionsBetween(s,a),g=this.transitionsBetween(a,n),w=l,b=[a,n,i,s];return w>d&&(w=d,b[0]=n,b[1]=i,b[2]=s,b[3]=a),w>h&&(w=h,b[0]=i,b[1]=s,b[2]=a,b[3]=n),w>g&&(b[0]=s,b[1]=a,b[2]=n,b[3]=i),b}detectSolid2(e){let n=e[0],i=e[1],s=e[2],a=e[3],l=this.transitionsBetween(n,a),d=Tt.shiftPoint(i,s,(l+1)*4),h=Tt.shiftPoint(s,i,(l+1)*4),g=this.transitionsBetween(d,n),w=this.transitionsBetween(h,a);return g<w?(e[0]=n,e[1]=i,e[2]=s,e[3]=a):(e[0]=i,e[1]=s,e[2]=a,e[3]=n),e}correctTopRight(e){let n=e[0],i=e[1],s=e[2],a=e[3],l=this.transitionsBetween(n,a),d=this.transitionsBetween(i,a),h=Tt.shiftPoint(n,i,(d+1)*4),g=Tt.shiftPoint(s,i,(l+1)*4);l=this.transitionsBetween(h,a),d=this.transitionsBetween(g,a);let w=new be(a.getX()+(s.getX()-i.getX())/(l+1),a.getY()+(s.getY()-i.getY())/(l+1)),b=new be(a.getX()+(n.getX()-i.getX())/(d+1),a.getY()+(n.getY()-i.getY())/(d+1));if(!this.isValid(w))return this.isValid(b)?b:null;if(!this.isValid(b))return w;let I=this.transitionsBetween(h,w)+this.transitionsBetween(g,w),N=this.transitionsBetween(h,b)+this.transitionsBetween(g,b);return I>N?w:b}shiftToModuleCenter(e){let n=e[0],i=e[1],s=e[2],a=e[3],l=this.transitionsBetween(n,a)+1,d=this.transitionsBetween(s,a)+1,h=Tt.shiftPoint(n,i,d*4),g=Tt.shiftPoint(s,i,l*4);l=this.transitionsBetween(h,a)+1,d=this.transitionsBetween(g,a)+1,(l&1)===1&&(l+=1),(d&1)===1&&(d+=1);let w=(n.getX()+i.getX()+s.getX()+a.getX())/4,b=(n.getY()+i.getY()+s.getY()+a.getY())/4;n=Tt.moveAway(n,w,b),i=Tt.moveAway(i,w,b),s=Tt.moveAway(s,w,b),a=Tt.moveAway(a,w,b);let I,N;return h=Tt.shiftPoint(n,i,d*4),h=Tt.shiftPoint(h,a,l*4),I=Tt.shiftPoint(i,n,d*4),I=Tt.shiftPoint(I,s,l*4),g=Tt.shiftPoint(s,a,d*4),g=Tt.shiftPoint(g,i,l*4),N=Tt.shiftPoint(a,s,d*4),N=Tt.shiftPoint(N,n,l*4),[h,I,g,N]}isValid(e){return e.getX()>=0&&e.getX()<this.image.getWidth()&&e.getY()>0&&e.getY()<this.image.getHeight()}static sampleGrid(e,n,i,s,a,l,d){return bn.getInstance().sampleGrid(e,l,d,.5,.5,l-.5,.5,l-.5,d-.5,.5,d-.5,n.getX(),n.getY(),a.getX(),a.getY(),s.getX(),s.getY(),i.getX(),i.getY())}transitionsBetween(e,n){let i=Math.trunc(e.getX()),s=Math.trunc(e.getY()),a=Math.trunc(n.getX()),l=Math.trunc(n.getY()),d=Math.abs(l-s)>Math.abs(a-i);if(d){let U=i;i=s,s=U,U=a,a=l,l=U}let h=Math.abs(a-i),g=Math.abs(l-s),w=-h/2,b=s<l?1:-1,I=i<a?1:-1,N=0,F=this.image.get(d?s:i,d?i:s);for(let U=i,W=s;U!==a;U+=I){let K=this.image.get(d?W:U,d?U:W);if(K!==F&&(N++,F=K),w+=g,w>0){if(W===l)break;W+=b,w-=h}}return N}}class Un{constructor(){this.decoder=new Ju}decode(e,n=null){let i,s;if(n!=null&&n.has(O.PURE_BARCODE)){const g=Un.extractPureBits(e.getBlackMatrix());i=this.decoder.decode(g),s=Un.NO_POINTS}else{const g=new Tt(e.getBlackMatrix()).detect();i=this.decoder.decode(g.getBits()),s=g.getPoints()}const a=i.getRawBytes(),l=new Ue(i.getText(),a,8*a.length,s,ge.DATA_MATRIX,R.currentTimeMillis()),d=i.getByteSegments();d!=null&&l.putMetadata(Se.BYTE_SEGMENTS,d);const h=i.getECLevel();return h!=null&&l.putMetadata(Se.ERROR_CORRECTION_LEVEL,h),l}reset(){}static extractPureBits(e){const n=e.getTopLeftOnBit(),i=e.getBottomRightOnBit();if(n==null||i==null)throw new P;const s=this.moduleSize(n,e);let a=n[1];const l=i[1];let d=n[0];const g=(i[0]-d+1)/s,w=(l-a+1)/s;if(g<=0||w<=0)throw new P;const b=s/2;a+=b,d+=b;const I=new ee(g,w);for(let N=0;N<w;N++){const F=a+N*s;for(let U=0;U<g;U++)e.get(d+U*s,F)&&I.set(U,N)}return I}static moduleSize(e,n){const i=n.getWidth();let s=e[0];const a=e[1];for(;s<i&&n.get(s,a);)s++;if(s===i)throw new P;const l=s-e[0];if(l===0)throw new P;return l}}Un.NO_POINTS=[];class Ku extends Ze{constructor(e=500){super(new Un,e)}}var xr;(function(C){C[C.L=0]="L",C[C.M=1]="M",C[C.Q=2]="Q",C[C.H=3]="H"})(xr||(xr={}));class lt{constructor(e,n,i){this.value=e,this.stringValue=n,this.bits=i,lt.FOR_BITS.set(i,this),lt.FOR_VALUE.set(e,this)}getValue(){return this.value}getBits(){return this.bits}static fromString(e){switch(e){case"L":return lt.L;case"M":return lt.M;case"Q":return lt.Q;case"H":return lt.H;default:throw new A(e+"not available")}}toString(){return this.stringValue}equals(e){if(!(e instanceof lt))return!1;const n=e;return this.value===n.value}static forBits(e){if(e<0||e>=lt.FOR_BITS.size)throw new E;return lt.FOR_BITS.get(e)}}lt.FOR_BITS=new Map,lt.FOR_VALUE=new Map,lt.L=new lt(xr.L,"L",1),lt.M=new lt(xr.M,"M",0),lt.Q=new lt(xr.Q,"Q",3),lt.H=new lt(xr.H,"H",2);class Zt{constructor(e){this.errorCorrectionLevel=lt.forBits(e>>3&3),this.dataMask=e&7}static numBitsDiffering(e,n){return z.bitCount(e^n)}static decodeFormatInformation(e,n){const i=Zt.doDecodeFormatInformation(e,n);return i!==null?i:Zt.doDecodeFormatInformation(e^Zt.FORMAT_INFO_MASK_QR,n^Zt.FORMAT_INFO_MASK_QR)}static doDecodeFormatInformation(e,n){let i=Number.MAX_SAFE_INTEGER,s=0;for(const a of Zt.FORMAT_INFO_DECODE_LOOKUP){const l=a[0];if(l===e||l===n)return new Zt(a[1]);let d=Zt.numBitsDiffering(e,l);d<i&&(s=a[1],i=d),e!==n&&(d=Zt.numBitsDiffering(n,l),d<i&&(s=a[1],i=d))}return i<=3?new Zt(s):null}getErrorCorrectionLevel(){return this.errorCorrectionLevel}getDataMask(){return this.dataMask}hashCode(){return this.errorCorrectionLevel.getBits()<<3|this.dataMask}equals(e){if(!(e instanceof Zt))return!1;const n=e;return this.errorCorrectionLevel===n.errorCorrectionLevel&&this.dataMask===n.dataMask}}Zt.FORMAT_INFO_MASK_QR=21522,Zt.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 G{constructor(e,...n){this.ecCodewordsPerBlock=e,this.ecBlocks=n}getECCodewordsPerBlock(){return this.ecCodewordsPerBlock}getNumBlocks(){let e=0;const n=this.ecBlocks;for(const i of n)e+=i.getCount();return e}getTotalECCodewords(){return this.ecCodewordsPerBlock*this.getNumBlocks()}getECBlocks(){return this.ecBlocks}}class S{constructor(e,n){this.count=e,this.dataCodewords=n}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class Ie{constructor(e,n,...i){this.versionNumber=e,this.alignmentPatternCenters=n,this.ecBlocks=i;let s=0;const a=i[0].getECCodewordsPerBlock(),l=i[0].getECBlocks();for(const d of l)s+=d.getCount()*(d.getDataCodewords()+a);this.totalCodewords=s}getVersionNumber(){return this.versionNumber}getAlignmentPatternCenters(){return this.alignmentPatternCenters}getTotalCodewords(){return this.totalCodewords}getDimensionForVersion(){return 17+4*this.versionNumber}getECBlocksForLevel(e){return this.ecBlocks[e.getValue()]}static getProvisionalVersionForDimension(e){if(e%4!==1)throw new V;try{return this.getVersionForNumber((e-17)/4)}catch{throw new V}}static getVersionForNumber(e){if(e<1||e>40)throw new E;return Ie.VERSIONS[e-1]}static decodeVersionInformation(e){let n=Number.MAX_SAFE_INTEGER,i=0;for(let s=0;s<Ie.VERSION_DECODE_INFO.length;s++){const a=Ie.VERSION_DECODE_INFO[s];if(a===e)return Ie.getVersionForNumber(s+7);const l=Zt.numBitsDiffering(e,a);l<n&&(i=s+7,n=l)}return n<=3?Ie.getVersionForNumber(i):null}buildFunctionPattern(){const e=this.getDimensionForVersion(),n=new ee(e);n.setRegion(0,0,9,9),n.setRegion(e-8,0,8,9),n.setRegion(0,e-8,9,8);const i=this.alignmentPatternCenters.length;for(let s=0;s<i;s++){const a=this.alignmentPatternCenters[s]-2;for(let l=0;l<i;l++)s===0&&(l===0||l===i-1)||s===i-1&&l===0||n.setRegion(this.alignmentPatternCenters[l]-2,a,5,5)}return n.setRegion(6,9,1,e-17),n.setRegion(9,6,e-17,1),this.versionNumber>6&&(n.setRegion(e-11,0,3,6),n.setRegion(0,e-11,6,3)),n}toString(){return""+this.versionNumber}}Ie.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]),Ie.VERSIONS=[new Ie(1,new Int32Array(0),new G(7,new S(1,19)),new G(10,new S(1,16)),new G(13,new S(1,13)),new G(17,new S(1,9))),new Ie(2,Int32Array.from([6,18]),new G(10,new S(1,34)),new G(16,new S(1,28)),new G(22,new S(1,22)),new G(28,new S(1,16))),new Ie(3,Int32Array.from([6,22]),new G(15,new S(1,55)),new G(26,new S(1,44)),new G(18,new S(2,17)),new G(22,new S(2,13))),new Ie(4,Int32Array.from([6,26]),new G(20,new S(1,80)),new G(18,new S(2,32)),new G(26,new S(2,24)),new G(16,new S(4,9))),new Ie(5,Int32Array.from([6,30]),new G(26,new S(1,108)),new G(24,new S(2,43)),new G(18,new S(2,15),new S(2,16)),new G(22,new S(2,11),new S(2,12))),new Ie(6,Int32Array.from([6,34]),new G(18,new S(2,68)),new G(16,new S(4,27)),new G(24,new S(4,19)),new G(28,new S(4,15))),new Ie(7,Int32Array.from([6,22,38]),new G(20,new S(2,78)),new G(18,new S(4,31)),new G(18,new S(2,14),new S(4,15)),new G(26,new S(4,13),new S(1,14))),new Ie(8,Int32Array.from([6,24,42]),new G(24,new S(2,97)),new G(22,new S(2,38),new S(2,39)),new G(22,new S(4,18),new S(2,19)),new G(26,new S(4,14),new S(2,15))),new Ie(9,Int32Array.from([6,26,46]),new G(30,new S(2,116)),new G(22,new S(3,36),new S(2,37)),new G(20,new S(4,16),new S(4,17)),new G(24,new S(4,12),new S(4,13))),new Ie(10,Int32Array.from([6,28,50]),new G(18,new S(2,68),new S(2,69)),new G(26,new S(4,43),new S(1,44)),new G(24,new S(6,19),new S(2,20)),new G(28,new S(6,15),new S(2,16))),new Ie(11,Int32Array.from([6,30,54]),new G(20,new S(4,81)),new G(30,new S(1,50),new S(4,51)),new G(28,new S(4,22),new S(4,23)),new G(24,new S(3,12),new S(8,13))),new Ie(12,Int32Array.from([6,32,58]),new G(24,new S(2,92),new S(2,93)),new G(22,new S(6,36),new S(2,37)),new G(26,new S(4,20),new S(6,21)),new G(28,new S(7,14),new S(4,15))),new Ie(13,Int32Array.from([6,34,62]),new G(26,new S(4,107)),new G(22,new S(8,37),new S(1,38)),new G(24,new S(8,20),new S(4,21)),new G(22,new S(12,11),new S(4,12))),new Ie(14,Int32Array.from([6,26,46,66]),new G(30,new S(3,115),new S(1,116)),new G(24,new S(4,40),new S(5,41)),new G(20,new S(11,16),new S(5,17)),new G(24,new S(11,12),new S(5,13))),new Ie(15,Int32Array.from([6,26,48,70]),new G(22,new S(5,87),new S(1,88)),new G(24,new S(5,41),new S(5,42)),new G(30,new S(5,24),new S(7,25)),new G(24,new S(11,12),new S(7,13))),new Ie(16,Int32Array.from([6,26,50,74]),new G(24,new S(5,98),new S(1,99)),new G(28,new S(7,45),new S(3,46)),new G(24,new S(15,19),new S(2,20)),new G(30,new S(3,15),new S(13,16))),new Ie(17,Int32Array.from([6,30,54,78]),new G(28,new S(1,107),new S(5,108)),new G(28,new S(10,46),new S(1,47)),new G(28,new S(1,22),new S(15,23)),new G(28,new S(2,14),new S(17,15))),new Ie(18,Int32Array.from([6,30,56,82]),new G(30,new S(5,120),new S(1,121)),new G(26,new S(9,43),new S(4,44)),new G(28,new S(17,22),new S(1,23)),new G(28,new S(2,14),new S(19,15))),new Ie(19,Int32Array.from([6,30,58,86]),new G(28,new S(3,113),new S(4,114)),new G(26,new S(3,44),new S(11,45)),new G(26,new S(17,21),new S(4,22)),new G(26,new S(9,13),new S(16,14))),new Ie(20,Int32Array.from([6,34,62,90]),new G(28,new S(3,107),new S(5,108)),new G(26,new S(3,41),new S(13,42)),new G(30,new S(15,24),new S(5,25)),new G(28,new S(15,15),new S(10,16))),new Ie(21,Int32Array.from([6,28,50,72,94]),new G(28,new S(4,116),new S(4,117)),new G(26,new S(17,42)),new G(28,new S(17,22),new S(6,23)),new G(30,new S(19,16),new S(6,17))),new Ie(22,Int32Array.from([6,26,50,74,98]),new G(28,new S(2,111),new S(7,112)),new G(28,new S(17,46)),new G(30,new S(7,24),new S(16,25)),new G(24,new S(34,13))),new Ie(23,Int32Array.from([6,30,54,78,102]),new G(30,new S(4,121),new S(5,122)),new G(28,new S(4,47),new S(14,48)),new G(30,new S(11,24),new S(14,25)),new G(30,new S(16,15),new S(14,16))),new Ie(24,Int32Array.from([6,28,54,80,106]),new G(30,new S(6,117),new S(4,118)),new G(28,new S(6,45),new S(14,46)),new G(30,new S(11,24),new S(16,25)),new G(30,new S(30,16),new S(2,17))),new Ie(25,Int32Array.from([6,32,58,84,110]),new G(26,new S(8,106),new S(4,107)),new G(28,new S(8,47),new S(13,48)),new G(30,new S(7,24),new S(22,25)),new G(30,new S(22,15),new S(13,16))),new Ie(26,Int32Array.from([6,30,58,86,114]),new G(28,new S(10,114),new S(2,115)),new G(28,new S(19,46),new S(4,47)),new G(28,new S(28,22),new S(6,23)),new G(30,new S(33,16),new S(4,17))),new Ie(27,Int32Array.from([6,34,62,90,118]),new G(30,new S(8,122),new S(4,123)),new G(28,new S(22,45),new S(3,46)),new G(30,new S(8,23),new S(26,24)),new G(30,new S(12,15),new S(28,16))),new Ie(28,Int32Array.from([6,26,50,74,98,122]),new G(30,new S(3,117),new S(10,118)),new G(28,new S(3,45),new S(23,46)),new G(30,new S(4,24),new S(31,25)),new G(30,new S(11,15),new S(31,16))),new Ie(29,Int32Array.from([6,30,54,78,102,126]),new G(30,new S(7,116),new S(7,117)),new G(28,new S(21,45),new S(7,46)),new G(30,new S(1,23),new S(37,24)),new G(30,new S(19,15),new S(26,16))),new Ie(30,Int32Array.from([6,26,52,78,104,130]),new G(30,new S(5,115),new S(10,116)),new G(28,new S(19,47),new S(10,48)),new G(30,new S(15,24),new S(25,25)),new G(30,new S(23,15),new S(25,16))),new Ie(31,Int32Array.from([6,30,56,82,108,134]),new G(30,new S(13,115),new S(3,116)),new G(28,new S(2,46),new S(29,47)),new G(30,new S(42,24),new S(1,25)),new G(30,new S(23,15),new S(28,16))),new Ie(32,Int32Array.from([6,34,60,86,112,138]),new G(30,new S(17,115)),new G(28,new S(10,46),new S(23,47)),new G(30,new S(10,24),new S(35,25)),new G(30,new S(19,15),new S(35,16))),new Ie(33,Int32Array.from([6,30,58,86,114,142]),new G(30,new S(17,115),new S(1,116)),new G(28,new S(14,46),new S(21,47)),new G(30,new S(29,24),new S(19,25)),new G(30,new S(11,15),new S(46,16))),new Ie(34,Int32Array.from([6,34,62,90,118,146]),new G(30,new S(13,115),new S(6,116)),new G(28,new S(14,46),new S(23,47)),new G(30,new S(44,24),new S(7,25)),new G(30,new S(59,16),new S(1,17))),new Ie(35,Int32Array.from([6,30,54,78,102,126,150]),new G(30,new S(12,121),new S(7,122)),new G(28,new S(12,47),new S(26,48)),new G(30,new S(39,24),new S(14,25)),new G(30,new S(22,15),new S(41,16))),new Ie(36,Int32Array.from([6,24,50,76,102,128,154]),new G(30,new S(6,121),new S(14,122)),new G(28,new S(6,47),new S(34,48)),new G(30,new S(46,24),new S(10,25)),new G(30,new S(2,15),new S(64,16))),new Ie(37,Int32Array.from([6,28,54,80,106,132,158]),new G(30,new S(17,122),new S(4,123)),new G(28,new S(29,46),new S(14,47)),new G(30,new S(49,24),new S(10,25)),new G(30,new S(24,15),new S(46,16))),new Ie(38,Int32Array.from([6,32,58,84,110,136,162]),new G(30,new S(4,122),new S(18,123)),new G(28,new S(13,46),new S(32,47)),new G(30,new S(48,24),new S(14,25)),new G(30,new S(42,15),new S(32,16))),new Ie(39,Int32Array.from([6,26,54,82,110,138,166]),new G(30,new S(20,117),new S(4,118)),new G(28,new S(40,47),new S(7,48)),new G(30,new S(43,24),new S(22,25)),new G(30,new S(10,15),new S(67,16))),new Ie(40,Int32Array.from([6,30,58,86,114,142,170]),new G(30,new S(19,118),new S(6,119)),new G(28,new S(18,47),new S(31,48)),new G(30,new S(34,24),new S(34,25)),new G(30,new S(20,15),new S(61,16)))];var Mt;(function(C){C[C.DATA_MASK_000=0]="DATA_MASK_000",C[C.DATA_MASK_001=1]="DATA_MASK_001",C[C.DATA_MASK_010=2]="DATA_MASK_010",C[C.DATA_MASK_011=3]="DATA_MASK_011",C[C.DATA_MASK_100=4]="DATA_MASK_100",C[C.DATA_MASK_101=5]="DATA_MASK_101",C[C.DATA_MASK_110=6]="DATA_MASK_110",C[C.DATA_MASK_111=7]="DATA_MASK_111"})(Mt||(Mt={}));class un{constructor(e,n){this.value=e,this.isMasked=n}unmaskBitMatrix(e,n){for(let i=0;i<n;i++)for(let s=0;s<n;s++)this.isMasked(i,s)&&e.flip(s,i)}}un.values=new Map([[Mt.DATA_MASK_000,new un(Mt.DATA_MASK_000,(C,e)=>(C+e&1)===0)],[Mt.DATA_MASK_001,new un(Mt.DATA_MASK_001,(C,e)=>(C&1)===0)],[Mt.DATA_MASK_010,new un(Mt.DATA_MASK_010,(C,e)=>e%3===0)],[Mt.DATA_MASK_011,new un(Mt.DATA_MASK_011,(C,e)=>(C+e)%3===0)],[Mt.DATA_MASK_100,new un(Mt.DATA_MASK_100,(C,e)=>(Math.floor(C/2)+Math.floor(e/3)&1)===0)],[Mt.DATA_MASK_101,new un(Mt.DATA_MASK_101,(C,e)=>C*e%6===0)],[Mt.DATA_MASK_110,new un(Mt.DATA_MASK_110,(C,e)=>C*e%6<3)],[Mt.DATA_MASK_111,new un(Mt.DATA_MASK_111,(C,e)=>(C+e+C*e%3&1)===0)]]);class Qu{constructor(e){const n=e.getHeight();if(n<21||(n&3)!==1)throw new V;this.bitMatrix=e}readFormatInformation(){if(this.parsedFormatInfo!==null&&this.parsedFormatInfo!==void 0)return this.parsedFormatInfo;let e=0;for(let a=0;a<6;a++)e=this.copyBit(a,8,e);e=this.copyBit(7,8,e),e=this.copyBit(8,8,e),e=this.copyBit(8,7,e);for(let a=5;a>=0;a--)e=this.copyBit(8,a,e);const n=this.bitMatrix.getHeight();let i=0;const s=n-7;for(let a=n-1;a>=s;a--)i=this.copyBit(8,a,i);for(let a=n-8;a<n;a++)i=this.copyBit(a,8,i);if(this.parsedFormatInfo=Zt.decodeFormatInformation(e,i),this.parsedFormatInfo!==null)return this.parsedFormatInfo;throw new V}readVersion(){if(this.parsedVersion!==null&&this.parsedVersion!==void 0)return this.parsedVersion;const e=this.bitMatrix.getHeight(),n=Math.floor((e-17)/4);if(n<=6)return Ie.getVersionForNumber(n);let i=0;const s=e-11;for(let l=5;l>=0;l--)for(let d=e-9;d>=s;d--)i=this.copyBit(d,l,i);let a=Ie.decodeVersionInformation(i);if(a!==null&&a.getDimensionForVersion()===e)return this.parsedVersion=a,a;i=0;for(let l=5;l>=0;l--)for(let d=e-9;d>=s;d--)i=this.copyBit(l,d,i);if(a=Ie.decodeVersionInformation(i),a!==null&&a.getDimensionForVersion()===e)return this.parsedVersion=a,a;throw new V}copyBit(e,n,i){return(this.isMirror?this.bitMatrix.get(n,e):this.bitMatrix.get(e,n))?i<<1|1:i<<1}readCodewords(){const e=this.readFormatInformation(),n=this.readVersion(),i=un.values.get(e.getDataMask()),s=this.bitMatrix.getHeight();i.unmaskBitMatrix(this.bitMatrix,s);const a=n.buildFunctionPattern();let l=!0;const d=new Uint8Array(n.getTotalCodewords());let h=0,g=0,w=0;for(let b=s-1;b>0;b-=2){b===6&&b--;for(let I=0;I<s;I++){const N=l?s-1-I:I;for(let F=0;F<2;F++)a.get(b-F,N)||(w++,g<<=1,this.bitMatrix.get(b-F,N)&&(g|=1),w===8&&(d[h++]=g,w=0,g=0))}l=!l}if(h!==n.getTotalCodewords())throw new V;return d}remask(){if(this.parsedFormatInfo===null)return;const e=un.values[this.parsedFormatInfo.getDataMask()],n=this.bitMatrix.getHeight();e.unmaskBitMatrix(this.bitMatrix,n)}setMirror(e){this.parsedVersion=null,this.parsedFormatInfo=null,this.isMirror=e}mirror(){const e=this.bitMatrix;for(let n=0,i=e.getWidth();n<i;n++)for(let s=n+1,a=e.getHeight();s<a;s++)e.get(n,s)!==e.get(s,n)&&(e.flip(s,n),e.flip(n,s))}}class Qi{constructor(e,n){this.numDataCodewords=e,this.codewords=n}static getDataBlocks(e,n,i){if(e.length!==n.getTotalCodewords())throw new E;const s=n.getECBlocksForLevel(i);let a=0;const l=s.getECBlocks();for(const F of l)a+=F.getCount();const d=new Array(a);let h=0;for(const F of l)for(let U=0;U<F.getCount();U++){const W=F.getDataCodewords(),K=s.getECCodewordsPerBlock()+W;d[h++]=new Qi(W,new Uint8Array(K))}const g=d[0].codewords.length;let w=d.length-1;for(;w>=0&&d[w].codewords.length!==g;)w--;w++;const b=g-s.getECCodewordsPerBlock();let I=0;for(let F=0;F<b;F++)for(let U=0;U<h;U++)d[U].codewords[F]=e[I++];for(let F=w;F<h;F++)d[F].codewords[b]=e[I++];const N=d[0].codewords.length;for(let F=b;F<N;F++)for(let U=0;U<h;U++){const W=U<w?F:F+1;d[U].codewords[W]=e[I++]}return d}getNumDataCodewords(){return this.numDataCodewords}getCodewords(){return this.codewords}}var dn;(function(C){C[C.TERMINATOR=0]="TERMINATOR",C[C.NUMERIC=1]="NUMERIC",C[C.ALPHANUMERIC=2]="ALPHANUMERIC",C[C.STRUCTURED_APPEND=3]="STRUCTURED_APPEND",C[C.BYTE=4]="BYTE",C[C.ECI=5]="ECI",C[C.KANJI=6]="KANJI",C[C.FNC1_FIRST_POSITION=7]="FNC1_FIRST_POSITION",C[C.FNC1_SECOND_POSITION=8]="FNC1_SECOND_POSITION",C[C.HANZI=9]="HANZI"})(dn||(dn={}));class Ne{constructor(e,n,i,s){this.value=e,this.stringValue=n,this.characterCountBitsForVersions=i,this.bits=s,Ne.FOR_BITS.set(s,this),Ne.FOR_VALUE.set(e,this)}static forBits(e){const n=Ne.FOR_BITS.get(e);if(n===void 0)throw new E;return n}getCharacterCountBits(e){const n=e.getVersionNumber();let i;return n<=9?i=0:n<=26?i=1:i=2,this.characterCountBitsForVersions[i]}getValue(){return this.value}getBits(){return this.bits}equals(e){if(!(e instanceof Ne))return!1;const n=e;return this.value===n.value}toString(){return this.stringValue}}Ne.FOR_BITS=new Map,Ne.FOR_VALUE=new Map,Ne.TERMINATOR=new Ne(dn.TERMINATOR,"TERMINATOR",Int32Array.from([0,0,0]),0),Ne.NUMERIC=new Ne(dn.NUMERIC,"NUMERIC",Int32Array.from([10,12,14]),1),Ne.ALPHANUMERIC=new Ne(dn.ALPHANUMERIC,"ALPHANUMERIC",Int32Array.from([9,11,13]),2),Ne.STRUCTURED_APPEND=new Ne(dn.STRUCTURED_APPEND,"STRUCTURED_APPEND",Int32Array.from([0,0,0]),3),Ne.BYTE=new Ne(dn.BYTE,"BYTE",Int32Array.from([8,16,16]),4),Ne.ECI=new Ne(dn.ECI,"ECI",Int32Array.from([0,0,0]),7),Ne.KANJI=new Ne(dn.KANJI,"KANJI",Int32Array.from([8,10,12]),8),Ne.FNC1_FIRST_POSITION=new Ne(dn.FNC1_FIRST_POSITION,"FNC1_FIRST_POSITION",Int32Array.from([0,0,0]),5),Ne.FNC1_SECOND_POSITION=new Ne(dn.FNC1_SECOND_POSITION,"FNC1_SECOND_POSITION",Int32Array.from([0,0,0]),9),Ne.HANZI=new Ne(dn.HANZI,"HANZI",Int32Array.from([8,10,12]),13);class xt{static decode(e,n,i,s){const a=new Ki(e);let l=new oe;const d=new Array;let h=-1,g=-1;try{let w=null,b=!1,I;do{if(a.available()<4)I=Ne.TERMINATOR;else{const N=a.readBits(4);I=Ne.forBits(N)}switch(I){case Ne.TERMINATOR:break;case Ne.FNC1_FIRST_POSITION:case Ne.FNC1_SECOND_POSITION:b=!0;break;case Ne.STRUCTURED_APPEND:if(a.available()<16)throw new V;h=a.readBits(8),g=a.readBits(8);break;case Ne.ECI:const N=xt.parseECIValue(a);if(w=j.getCharacterSetECIByValue(N),w===null)throw new V;break;case Ne.HANZI:const F=a.readBits(4),U=a.readBits(I.getCharacterCountBits(n));F===xt.GB2312_SUBSET&&xt.decodeHanziSegment(a,l,U);break;default:const W=a.readBits(I.getCharacterCountBits(n));switch(I){case Ne.NUMERIC:xt.decodeNumericSegment(a,l,W);break;case Ne.ALPHANUMERIC:xt.decodeAlphanumericSegment(a,l,W,b);break;case Ne.BYTE:xt.decodeByteSegment(a,l,W,w,d,s);break;case Ne.KANJI:xt.decodeKanjiSegment(a,l,W);break;default:throw new V}break}}while(I!==Ne.TERMINATOR)}catch{throw new V}return new Nt(e,l.toString(),d.length===0?null:d,i===null?null:i.toString(),h,g)}static decodeHanziSegment(e,n,i){if(i*13>e.available())throw new V;const s=new Uint8Array(2*i);let a=0;for(;i>0;){const l=e.readBits(13);let d=l/96<<8&4294967295|l%96;d<959?d+=41377:d+=42657,s[a]=d>>8&255,s[a+1]=d&255,a+=2,i--}try{n.append(de.decode(s,ne.GB2312))}catch(l){throw new V(l)}}static decodeKanjiSegment(e,n,i){if(i*13>e.available())throw new V;const s=new Uint8Array(2*i);let a=0;for(;i>0;){const l=e.readBits(13);let d=l/192<<8&4294967295|l%192;d<7936?d+=33088:d+=49472,s[a]=d>>8,s[a+1]=d,a+=2,i--}try{n.append(de.decode(s,ne.SHIFT_JIS))}catch(l){throw new V(l)}}static decodeByteSegment(e,n,i,s,a,l){if(8*i>e.available())throw new V;const d=new Uint8Array(i);for(let g=0;g<i;g++)d[g]=e.readBits(8);let h;s===null?h=ne.guessEncoding(d,l):h=s.getName();try{n.append(de.decode(d,h))}catch(g){throw new V(g)}a.push(d)}static toAlphaNumericChar(e){if(e>=xt.ALPHANUMERIC_CHARS.length)throw new V;return xt.ALPHANUMERIC_CHARS[e]}static decodeAlphanumericSegment(e,n,i,s){const a=n.length();for(;i>1;){if(e.available()<11)throw new V;const l=e.readBits(11);n.append(xt.toAlphaNumericChar(Math.floor(l/45))),n.append(xt.toAlphaNumericChar(l%45)),i-=2}if(i===1){if(e.available()<6)throw new V;n.append(xt.toAlphaNumericChar(e.readBits(6)))}if(s)for(let l=a;l<n.length();l++)n.charAt(l)==="%"&&(l<n.length()-1&&n.charAt(l+1)==="%"?n.deleteCharAt(l+1):n.setCharAt(l,""))}static decodeNumericSegment(e,n,i){for(;i>=3;){if(e.available()<10)throw new V;const s=e.readBits(10);if(s>=1e3)throw new V;n.append(xt.toAlphaNumericChar(Math.floor(s/100))),n.append(xt.toAlphaNumericChar(Math.floor(s/10)%10)),n.append(xt.toAlphaNumericChar(s%10)),i-=3}if(i===2){if(e.available()<7)throw new V;const s=e.readBits(7);if(s>=100)throw new V;n.append(xt.toAlphaNumericChar(Math.floor(s/10))),n.append(xt.toAlphaNumericChar(s%10))}else if(i===1){if(e.available()<4)throw new V;const s=e.readBits(4);if(s>=10)throw new V;n.append(xt.toAlphaNumericChar(s))}}static parseECIValue(e){const n=e.readBits(8);if((n&128)===0)return n&127;if((n&192)===128){const i=e.readBits(8);return(n&63)<<8&4294967295|i}if((n&224)===192){const i=e.readBits(16);return(n&31)<<16&4294967295|i}throw new V}}xt.ALPHANUMERIC_CHARS="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",xt.GB2312_SUBSET=1;class us{constructor(e){this.mirrored=e}isMirrored(){return this.mirrored}applyMirroredCorrection(e){if(!this.mirrored||e===null||e.length<3)return;const n=e[0];e[0]=e[2],e[2]=n}}class ed{constructor(){this.rsDecoder=new Cn(Be.QR_CODE_FIELD_256)}decodeBooleanArray(e,n){return this.decodeBitMatrix(ee.parseFromBooleanArray(e),n)}decodeBitMatrix(e,n){const i=new Qu(e);let s=null;try{return this.decodeBitMatrixParser(i,n)}catch(a){s=a}try{i.remask(),i.setMirror(!0),i.readVersion(),i.readFormatInformation(),i.mirror();const a=this.decodeBitMatrixParser(i,n);return a.setOther(new us(!0)),a}catch(a){throw s!==null?s:a}}decodeBitMatrixParser(e,n){const i=e.readVersion(),s=e.readFormatInformation().getErrorCorrectionLevel(),a=e.readCodewords(),l=Qi.getDataBlocks(a,i,s);let d=0;for(const w of l)d+=w.getNumDataCodewords();const h=new Uint8Array(d);let g=0;for(const w of l){const b=w.getCodewords(),I=w.getNumDataCodewords();this.correctErrors(b,I);for(let N=0;N<I;N++)h[g++]=b[N]}return xt.decode(h,i,s,n)}correctErrors(e,n){const i=new Int32Array(e);try{this.rsDecoder.decode(i,e.length-n)}catch{throw new D}for(let s=0;s<n;s++)e[s]=i[s]}}class eo extends be{constructor(e,n,i){super(e,n),this.estimatedModuleSize=i}aboutEquals(e,n,i){if(Math.abs(n-this.getY())<=e&&Math.abs(i-this.getX())<=e){const s=Math.abs(e-this.estimatedModuleSize);return s<=1||s<=this.estimatedModuleSize}return!1}combineEstimate(e,n,i){const s=(this.getX()+n)/2,a=(this.getY()+e)/2,l=(this.estimatedModuleSize+i)/2;return new eo(s,a,l)}}class fi{constructor(e,n,i,s,a,l,d){this.image=e,this.startX=n,this.startY=i,this.width=s,this.height=a,this.moduleSize=l,this.resultPointCallback=d,this.possibleCenters=[],this.crossCheckStateCount=new Int32Array(3)}find(){const e=this.startX,n=this.height,i=this.width,s=e+i,a=this.startY+n/2,l=new Int32Array(3),d=this.image;for(let h=0;h<n;h++){const g=a+((h&1)===0?Math.floor((h+1)/2):-Math.floor((h+1)/2));l[0]=0,l[1]=0,l[2]=0;let w=e;for(;w<s&&!d.get(w,g);)w++;let b=0;for(;w<s;){if(d.get(w,g))if(b===1)l[1]++;else if(b===2){if(this.foundPatternCross(l)){const I=this.handlePossibleCenter(l,g,w);if(I!==null)return I}l[0]=l[2],l[1]=1,l[2]=0,b=1}else l[++b]++;else b===1&&b++,l[b]++;w++}if(this.foundPatternCross(l)){const I=this.handlePossibleCenter(l,g,s);if(I!==null)return I}}if(this.possibleCenters.length!==0)return this.possibleCenters[0];throw new P}static centerFromEnd(e,n){return n-e[2]-e[1]/2}foundPatternCross(e){const n=this.moduleSize,i=n/2;for(let s=0;s<3;s++)if(Math.abs(n-e[s])>=i)return!1;return!0}crossCheckVertical(e,n,i,s){const a=this.image,l=a.getHeight(),d=this.crossCheckStateCount;d[0]=0,d[1]=0,d[2]=0;let h=e;for(;h>=0&&a.get(n,h)&&d[1]<=i;)d[1]++,h--;if(h<0||d[1]>i)return NaN;for(;h>=0&&!a.get(n,h)&&d[0]<=i;)d[0]++,h--;if(d[0]>i)return NaN;for(h=e+1;h<l&&a.get(n,h)&&d[1]<=i;)d[1]++,h++;if(h===l||d[1]>i)return NaN;for(;h<l&&!a.get(n,h)&&d[2]<=i;)d[2]++,h++;if(d[2]>i)return NaN;const g=d[0]+d[1]+d[2];return 5*Math.abs(g-s)>=2*s?NaN:this.foundPatternCross(d)?fi.centerFromEnd(d,h):NaN}handlePossibleCenter(e,n,i){const s=e[0]+e[1]+e[2],a=fi.centerFromEnd(e,i),l=this.crossCheckVertical(n,a,2*e[1],s);if(!isNaN(l)){const d=(e[0]+e[1]+e[2])/3;for(const g of this.possibleCenters)if(g.aboutEquals(d,l,a))return g.combineEstimate(l,a,d);const h=new eo(a,l,d);this.possibleCenters.push(h),this.resultPointCallback!==null&&this.resultPointCallback!==void 0&&this.resultPointCallback.foundPossibleResultPoint(h)}return null}}class to extends be{constructor(e,n,i,s){super(e,n),this.estimatedModuleSize=i,this.count=s,s===void 0&&(this.count=1)}getEstimatedModuleSize(){return this.estimatedModuleSize}getCount(){return this.count}aboutEquals(e,n,i){if(Math.abs(n-this.getY())<=e&&Math.abs(i-this.getX())<=e){const s=Math.abs(e-this.estimatedModuleSize);return s<=1||s<=this.estimatedModuleSize}return!1}combineEstimate(e,n,i){const s=this.count+1,a=(this.count*this.getX()+n)/s,l=(this.count*this.getY()+e)/s,d=(this.count*this.estimatedModuleSize+i)/s;return new to(a,l,d,s)}}class td{constructor(e){this.bottomLeft=e[0],this.topLeft=e[1],this.topRight=e[2]}getBottomLeft(){return this.bottomLeft}getTopLeft(){return this.topLeft}getTopRight(){return this.topRight}}class Dt{constructor(e,n){this.image=e,this.resultPointCallback=n,this.possibleCenters=[],this.crossCheckStateCount=new Int32Array(5),this.resultPointCallback=n}getImage(){return this.image}getPossibleCenters(){return this.possibleCenters}find(e){const n=e!=null&&e.get(O.TRY_HARDER)!==void 0,i=e!=null&&e.get(O.PURE_BARCODE)!==void 0,s=this.image,a=s.getHeight(),l=s.getWidth();let d=Math.floor(3*a/(4*Dt.MAX_MODULES));(d<Dt.MIN_SKIP||n)&&(d=Dt.MIN_SKIP);let h=!1;const g=new Int32Array(5);for(let b=d-1;b<a&&!h;b+=d){g[0]=0,g[1]=0,g[2]=0,g[3]=0,g[4]=0;let I=0;for(let N=0;N<l;N++)if(s.get(N,b))(I&1)===1&&I++,g[I]++;else if((I&1)===0)if(I===4)if(Dt.foundPatternCross(g)){if(this.handlePossibleCenter(g,b,N,i)===!0)if(d=2,this.hasSkipped===!0)h=this.haveMultiplyConfirmedCenters();else{const U=this.findRowSkip();U>g[2]&&(b+=U-g[2]-d,N=l-1)}else{g[0]=g[2],g[1]=g[3],g[2]=g[4],g[3]=1,g[4]=0,I=3;continue}I=0,g[0]=0,g[1]=0,g[2]=0,g[3]=0,g[4]=0}else g[0]=g[2],g[1]=g[3],g[2]=g[4],g[3]=1,g[4]=0,I=3;else g[++I]++;else g[I]++;Dt.foundPatternCross(g)&&this.handlePossibleCenter(g,b,l,i)===!0&&(d=g[0],this.hasSkipped&&(h=this.haveMultiplyConfirmedCenters()))}const w=this.selectBestPatterns();return be.orderBestPatterns(w),new td(w)}static centerFromEnd(e,n){return n-e[4]-e[3]-e[2]/2}static foundPatternCross(e){let n=0;for(let a=0;a<5;a++){const l=e[a];if(l===0)return!1;n+=l}if(n<7)return!1;const i=n/7,s=i/2;return Math.abs(i-e[0])<s&&Math.abs(i-e[1])<s&&Math.abs(3*i-e[2])<3*s&&Math.abs(i-e[3])<s&&Math.abs(i-e[4])<s}getCrossCheckStateCount(){const e=this.crossCheckStateCount;return e[0]=0,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e}crossCheckDiagonal(e,n,i,s){const a=this.getCrossCheckStateCount();let l=0;const d=this.image;for(;e>=l&&n>=l&&d.get(n-l,e-l);)a[2]++,l++;if(e<l||n<l)return!1;for(;e>=l&&n>=l&&!d.get(n-l,e-l)&&a[1]<=i;)a[1]++,l++;if(e<l||n<l||a[1]>i)return!1;for(;e>=l&&n>=l&&d.get(n-l,e-l)&&a[0]<=i;)a[0]++,l++;if(a[0]>i)return!1;const h=d.getHeight(),g=d.getWidth();for(l=1;e+l<h&&n+l<g&&d.get(n+l,e+l);)a[2]++,l++;if(e+l>=h||n+l>=g)return!1;for(;e+l<h&&n+l<g&&!d.get(n+l,e+l)&&a[3]<i;)a[3]++,l++;if(e+l>=h||n+l>=g||a[3]>=i)return!1;for(;e+l<h&&n+l<g&&d.get(n+l,e+l)&&a[4]<i;)a[4]++,l++;if(a[4]>=i)return!1;const w=a[0]+a[1]+a[2]+a[3]+a[4];return Math.abs(w-s)<2*s&&Dt.foundPatternCross(a)}crossCheckVertical(e,n,i,s){const a=this.image,l=a.getHeight(),d=this.getCrossCheckStateCount();let h=e;for(;h>=0&&a.get(n,h);)d[2]++,h--;if(h<0)return NaN;for(;h>=0&&!a.get(n,h)&&d[1]<=i;)d[1]++,h--;if(h<0||d[1]>i)return NaN;for(;h>=0&&a.get(n,h)&&d[0]<=i;)d[0]++,h--;if(d[0]>i)return NaN;for(h=e+1;h<l&&a.get(n,h);)d[2]++,h++;if(h===l)return NaN;for(;h<l&&!a.get(n,h)&&d[3]<i;)d[3]++,h++;if(h===l||d[3]>=i)return NaN;for(;h<l&&a.get(n,h)&&d[4]<i;)d[4]++,h++;if(d[4]>=i)return NaN;const g=d[0]+d[1]+d[2]+d[3]+d[4];return 5*Math.abs(g-s)>=2*s?NaN:Dt.foundPatternCross(d)?Dt.centerFromEnd(d,h):NaN}crossCheckHorizontal(e,n,i,s){const a=this.image,l=a.getWidth(),d=this.getCrossCheckStateCount();let h=e;for(;h>=0&&a.get(h,n);)d[2]++,h--;if(h<0)return NaN;for(;h>=0&&!a.get(h,n)&&d[1]<=i;)d[1]++,h--;if(h<0||d[1]>i)return NaN;for(;h>=0&&a.get(h,n)&&d[0]<=i;)d[0]++,h--;if(d[0]>i)return NaN;for(h=e+1;h<l&&a.get(h,n);)d[2]++,h++;if(h===l)return NaN;for(;h<l&&!a.get(h,n)&&d[3]<i;)d[3]++,h++;if(h===l||d[3]>=i)return NaN;for(;h<l&&a.get(h,n)&&d[4]<i;)d[4]++,h++;if(d[4]>=i)return NaN;const g=d[0]+d[1]+d[2]+d[3]+d[4];return 5*Math.abs(g-s)>=s?NaN:Dt.foundPatternCross(d)?Dt.centerFromEnd(d,h):NaN}handlePossibleCenter(e,n,i,s){const a=e[0]+e[1]+e[2]+e[3]+e[4];let l=Dt.centerFromEnd(e,i),d=this.crossCheckVertical(n,Math.floor(l),e[2],a);if(!isNaN(d)&&(l=this.crossCheckHorizontal(Math.floor(l),Math.floor(d),e[2],a),!isNaN(l)&&(!s||this.crossCheckDiagonal(Math.floor(d),Math.floor(l),e[2],a)))){const h=a/7;let g=!1;const w=this.possibleCenters;for(let b=0,I=w.length;b<I;b++){const N=w[b];if(N.aboutEquals(h,d,l)){w[b]=N.combineEstimate(d,l,h),g=!0;break}}if(!g){const b=new to(l,d,h);w.push(b),this.resultPointCallback!==null&&this.resultPointCallback!==void 0&&this.resultPointCallback.foundPossibleResultPoint(b)}return!0}return!1}findRowSkip(){if(this.possibleCenters.length<=1)return 0;let n=null;for(const i of this.possibleCenters)if(i.getCount()>=Dt.CENTER_QUORUM)if(n==null)n=i;else return this.hasSkipped=!0,Math.floor((Math.abs(n.getX()-i.getX())-Math.abs(n.getY()-i.getY()))/2);return 0}haveMultiplyConfirmedCenters(){let e=0,n=0;const i=this.possibleCenters.length;for(const l of this.possibleCenters)l.getCount()>=Dt.CENTER_QUORUM&&(e++,n+=l.getEstimatedModuleSize());if(e<3)return!1;const s=n/i;let a=0;for(const l of this.possibleCenters)a+=Math.abs(l.getEstimatedModuleSize()-s);return a<=.05*n}selectBestPatterns(){const e=this.possibleCenters.length;if(e<3)throw new P;const n=this.possibleCenters;let i;if(e>3){let s=0,a=0;for(const h of this.possibleCenters){const g=h.getEstimatedModuleSize();s+=g,a+=g*g}i=s/e;let l=Math.sqrt(a/e-i*i);n.sort((h,g)=>{const w=Math.abs(g.getEstimatedModuleSize()-i),b=Math.abs(h.getEstimatedModuleSize()-i);return w<b?-1:w>b?1:0});const d=Math.max(.2*i,l);for(let h=0;h<n.length&&n.length>3;h++){const g=n[h];Math.abs(g.getEstimatedModuleSize()-i)>d&&(n.splice(h,1),h--)}}if(n.length>3){let s=0;for(const a of n)s+=a.getEstimatedModuleSize();i=s/n.length,n.sort((a,l)=>{if(l.getCount()===a.getCount()){const d=Math.abs(l.getEstimatedModuleSize()-i),h=Math.abs(a.getEstimatedModuleSize()-i);return d<h?1:d>h?-1:0}else return l.getCount()-a.getCount()}),n.splice(3)}return[n[0],n[1],n[2]]}}Dt.CENTER_QUORUM=2,Dt.MIN_SKIP=3,Dt.MAX_MODULES=57;class Or{constructor(e){this.image=e}getImage(){return this.image}getResultPointCallback(){return this.resultPointCallback}detect(e){this.resultPointCallback=e==null?null:e.get(O.NEED_RESULT_POINT_CALLBACK);const i=new Dt(this.image,this.resultPointCallback).find(e);return this.processFinderPatternInfo(i)}processFinderPatternInfo(e){const n=e.getTopLeft(),i=e.getTopRight(),s=e.getBottomLeft(),a=this.calculateModuleSize(n,i,s);if(a<1)throw new P("No pattern found in proccess finder.");const l=Or.computeDimension(n,i,s,a),d=Ie.getProvisionalVersionForDimension(l),h=d.getDimensionForVersion()-7;let g=null;if(d.getAlignmentPatternCenters().length>0){const N=i.getX()-n.getX()+s.getX(),F=i.getY()-n.getY()+s.getY(),U=1-3/h,W=Math.floor(n.getX()+U*(N-n.getX())),K=Math.floor(n.getY()+U*(F-n.getY()));for(let fe=4;fe<=16;fe<<=1)try{g=this.findAlignmentInRegion(a,W,K,fe);break}catch(he){if(!(he instanceof P))throw he}}const w=Or.createTransform(n,i,s,g,l),b=Or.sampleGrid(this.image,w,l);let I;return g===null?I=[s,n,i]:I=[s,n,i,g],new fr(b,I)}static createTransform(e,n,i,s,a){const l=a-3.5;let d,h,g,w;return s!==null?(d=s.getX(),h=s.getY(),g=l-3,w=g):(d=n.getX()-e.getX()+i.getX(),h=n.getY()-e.getY()+i.getY(),g=l,w=l),en.quadrilateralToQuadrilateral(3.5,3.5,l,3.5,g,w,3.5,l,e.getX(),e.getY(),n.getX(),n.getY(),d,h,i.getX(),i.getY())}static sampleGrid(e,n,i){return bn.getInstance().sampleGridWithTransform(e,i,i,n)}static computeDimension(e,n,i,s){const a=Te.round(be.distance(e,n)/s),l=Te.round(be.distance(e,i)/s);let d=Math.floor((a+l)/2)+7;switch(d&3){case 0:d++;break;case 2:d--;break;case 3:throw new P("Dimensions could be not found.")}return d}calculateModuleSize(e,n,i){return(this.calculateModuleSizeOneWay(e,n)+this.calculateModuleSizeOneWay(e,i))/2}calculateModuleSizeOneWay(e,n){const i=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(e.getX()),Math.floor(e.getY()),Math.floor(n.getX()),Math.floor(n.getY())),s=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(n.getX()),Math.floor(n.getY()),Math.floor(e.getX()),Math.floor(e.getY()));return isNaN(i)?s/7:isNaN(s)?i/7:(i+s)/14}sizeOfBlackWhiteBlackRunBothWays(e,n,i,s){let a=this.sizeOfBlackWhiteBlackRun(e,n,i,s),l=1,d=e-(i-e);d<0?(l=e/(e-d),d=0):d>=this.image.getWidth()&&(l=(this.image.getWidth()-1-e)/(d-e),d=this.image.getWidth()-1);let h=Math.floor(n-(s-n)*l);return l=1,h<0?(l=n/(n-h),h=0):h>=this.image.getHeight()&&(l=(this.image.getHeight()-1-n)/(h-n),h=this.image.getHeight()-1),d=Math.floor(e+(d-e)*l),a+=this.sizeOfBlackWhiteBlackRun(e,n,d,h),a-1}sizeOfBlackWhiteBlackRun(e,n,i,s){const a=Math.abs(s-n)>Math.abs(i-e);if(a){let N=e;e=n,n=N,N=i,i=s,s=N}const l=Math.abs(i-e),d=Math.abs(s-n);let h=-l/2;const g=e<i?1:-1,w=n<s?1:-1;let b=0;const I=i+g;for(let N=e,F=n;N!==I;N+=g){const U=a?F:N,W=a?N:F;if(b===1===this.image.get(U,W)){if(b===2)return Te.distance(N,F,e,n);b++}if(h+=d,h>0){if(F===s)break;F+=w,h-=l}}return b===2?Te.distance(i+g,s,e,n):NaN}findAlignmentInRegion(e,n,i,s){const a=Math.floor(s*e),l=Math.max(0,n-a),d=Math.min(this.image.getWidth()-1,n+a);if(d-l<e*3)throw new P("Alignment top exceeds estimated module size.");const h=Math.max(0,i-a),g=Math.min(this.image.getHeight()-1,i+a);if(g-h<e*3)throw new P("Alignment bottom exceeds estimated module size.");return new fi(this.image,l,h,d-l,g-h,e,this.resultPointCallback).find()}}class zn{constructor(){this.decoder=new ed}getDecoder(){return this.decoder}decode(e,n){let i,s;if(n!=null&&n.get(O.PURE_BARCODE)!==void 0){const h=zn.extractPureBits(e.getBlackMatrix());i=this.decoder.decodeBitMatrix(h,n),s=zn.NO_POINTS}else{const h=new Or(e.getBlackMatrix()).detect(n);i=this.decoder.decodeBitMatrix(h.getBits(),n),s=h.getPoints()}i.getOther()instanceof us&&i.getOther().applyMirroredCorrection(s);const a=new Ue(i.getText(),i.getRawBytes(),void 0,s,ge.QR_CODE,void 0),l=i.getByteSegments();l!==null&&a.putMetadata(Se.BYTE_SEGMENTS,l);const d=i.getECLevel();return d!==null&&a.putMetadata(Se.ERROR_CORRECTION_LEVEL,d),i.hasStructuredAppend()&&(a.putMetadata(Se.STRUCTURED_APPEND_SEQUENCE,i.getStructuredAppendSequenceNumber()),a.putMetadata(Se.STRUCTURED_APPEND_PARITY,i.getStructuredAppendParity())),a}reset(){}static extractPureBits(e){const n=e.getTopLeftOnBit(),i=e.getBottomRightOnBit();if(n===null||i===null)throw new P;const s=this.moduleSize(n,e);let a=n[1],l=i[1],d=n[0],h=i[0];if(d>=h||a>=l)throw new P;if(l-a!==h-d&&(h=d+(l-a),h>=e.getWidth()))throw new P;const g=Math.round((h-d+1)/s),w=Math.round((l-a+1)/s);if(g<=0||w<=0)throw new P;if(w!==g)throw new P;const b=Math.floor(s/2);a+=b,d+=b;const I=d+Math.floor((g-1)*s)-h;if(I>0){if(I>b)throw new P;d-=I}const N=a+Math.floor((w-1)*s)-l;if(N>0){if(N>b)throw new P;a-=N}const F=new ee(g,w);for(let U=0;U<w;U++){const W=a+Math.floor(U*s);for(let K=0;K<g;K++)e.get(d+Math.floor(K*s),W)&&F.set(K,U)}return F}static moduleSize(e,n){const i=n.getHeight(),s=n.getWidth();let a=e[0],l=e[1],d=!0,h=0;for(;a<s&&l<i;){if(d!==n.get(a,l)){if(++h===5)break;d=!d}a++,l++}if(a===s||l===i)throw new P;return(a-e[0])/7}}zn.NO_POINTS=new Array;class Re{PDF417Common(){}static getBitCountSum(e){return Te.sum(e)}static toIntArray(e){if(e==null||!e.length)return Re.EMPTY_INT_ARRAY;const n=new Int32Array(e.length);let i=0;for(const s of e)n[i++]=s;return n}static getCodeword(e){const n=Z.binarySearch(Re.SYMBOL_TABLE,e&262143);return n<0?-1:(Re.CODEWORD_TABLE[n]-1)%Re.NUMBER_OF_CODEWORDS}}Re.NUMBER_OF_CODEWORDS=929,Re.MAX_CODEWORDS_IN_BARCODE=Re.NUMBER_OF_CODEWORDS-1,Re.MIN_ROWS_IN_BARCODE=3,Re.MAX_ROWS_IN_BARCODE=90,Re.MODULES_IN_CODEWORD=17,Re.MODULES_IN_STOP_PATTERN=18,Re.BARS_IN_MODULE=8,Re.EMPTY_INT_ARRAY=new Int32Array([]),Re.SYMBOL_TABLE=Int32Array.from([66142,66170,66206,66236,66290,66292,66350,66382,66396,66454,66470,66476,66594,66600,66614,66626,66628,66632,66640,66654,66662,66668,66682,66690,66718,66720,66748,66758,66776,66798,66802,66804,66820,66824,66832,66846,66848,66876,66880,66936,66950,66956,66968,66992,67006,67022,67036,67042,67044,67048,67062,67118,67150,67164,67214,67228,67256,67294,67322,67350,67366,67372,67398,67404,67416,67438,67474,67476,67490,67492,67496,67510,67618,67624,67650,67656,67664,67678,67686,67692,67706,67714,67716,67728,67742,67744,67772,67782,67788,67800,67822,67826,67828,67842,67848,67870,67872,67900,67904,67960,67974,67992,68016,68030,68046,68060,68066,68068,68072,68086,68104,68112,68126,68128,68156,68160,68216,68336,68358,68364,68376,68400,68414,68448,68476,68494,68508,68536,68546,68548,68552,68560,68574,68582,68588,68654,68686,68700,68706,68708,68712,68726,68750,68764,68792,68802,68804,68808,68816,68830,68838,68844,68858,68878,68892,68920,68976,68990,68994,68996,69e3,69008,69022,69024,69052,69062,69068,69080,69102,69106,69108,69142,69158,69164,69190,69208,69230,69254,69260,69272,69296,69310,69326,69340,69386,69394,69396,69410,69416,69430,69442,69444,69448,69456,69470,69478,69484,69554,69556,69666,69672,69698,69704,69712,69726,69754,69762,69764,69776,69790,69792,69820,69830,69836,69848,69870,69874,69876,69890,69918,69920,69948,69952,70008,70022,70040,70064,70078,70094,70108,70114,70116,70120,70134,70152,70174,70176,70264,70384,70412,70448,70462,70496,70524,70542,70556,70584,70594,70600,70608,70622,70630,70636,70664,70672,70686,70688,70716,70720,70776,70896,71136,71180,71192,71216,71230,71264,71292,71360,71416,71452,71480,71536,71550,71554,71556,71560,71568,71582,71584,71612,71622,71628,71640,71662,71726,71732,71758,71772,71778,71780,71784,71798,71822,71836,71864,71874,71880,71888,71902,71910,71916,71930,71950,71964,71992,72048,72062,72066,72068,72080,72094,72096,72124,72134,72140,72152,72174,72178,72180,72206,72220,72248,72304,72318,72416,72444,72456,72464,72478,72480,72508,72512,72568,72588,72600,72624,72638,72654,72668,72674,72676,72680,72694,72726,72742,72748,72774,72780,72792,72814,72838,72856,72880,72894,72910,72924,72930,72932,72936,72950,72966,72972,72984,73008,73022,73056,73084,73102,73116,73144,73156,73160,73168,73182,73190,73196,73210,73226,73234,73236,73250,73252,73256,73270,73282,73284,73296,73310,73318,73324,73346,73348,73352,73360,73374,73376,73404,73414,73420,73432,73454,73498,73518,73522,73524,73550,73564,73570,73572,73576,73590,73800,73822,73858,73860,73872,73886,73888,73916,73944,73970,73972,73992,74014,74016,74044,74048,74104,74118,74136,74160,74174,74210,74212,74216,74230,74244,74256,74270,74272,74360,74480,74502,74508,74544,74558,74592,74620,74638,74652,74680,74690,74696,74704,74726,74732,74782,74784,74812,74992,75232,75288,75326,75360,75388,75456,75512,75576,75632,75646,75650,75652,75664,75678,75680,75708,75718,75724,75736,75758,75808,75836,75840,75896,76016,76256,76736,76824,76848,76862,76896,76924,76992,77048,77296,77340,77368,77424,77438,77536,77564,77572,77576,77584,77600,77628,77632,77688,77702,77708,77720,77744,77758,77774,77788,77870,77902,77916,77922,77928,77966,77980,78008,78018,78024,78032,78046,78060,78074,78094,78136,78192,78206,78210,78212,78224,78238,78240,78268,78278,78284,78296,78322,78324,78350,78364,78448,78462,78560,78588,78600,78622,78624,78652,78656,78712,78726,78744,78768,78782,78798,78812,78818,78820,78824,78838,78862,78876,78904,78960,78974,79072,79100,79296,79352,79368,79376,79390,79392,79420,79424,79480,79600,79628,79640,79664,79678,79712,79740,79772,79800,79810,79812,79816,79824,79838,79846,79852,79894,79910,79916,79942,79948,79960,79982,79988,80006,80024,80048,80062,80078,80092,80098,80100,80104,80134,80140,80176,80190,80224,80252,80270,80284,80312,80328,80336,80350,80358,80364,80378,80390,80396,80408,80432,80446,80480,80508,80576,80632,80654,80668,80696,80752,80766,80776,80784,80798,80800,80828,80844,80856,80878,80882,80884,80914,80916,80930,80932,80936,80950,80962,80968,80976,80990,80998,81004,81026,81028,81040,81054,81056,81084,81094,81100,81112,81134,81154,81156,81160,81168,81182,81184,81212,81216,81272,81286,81292,81304,81328,81342,81358,81372,81380,81384,81398,81434,81454,81458,81460,81486,81500,81506,81508,81512,81526,81550,81564,81592,81602,81604,81608,81616,81630,81638,81644,81702,81708,81722,81734,81740,81752,81774,81778,81780,82050,82078,82080,82108,82180,82184,82192,82206,82208,82236,82240,82296,82316,82328,82352,82366,82402,82404,82408,82440,82448,82462,82464,82492,82496,82552,82672,82694,82700,82712,82736,82750,82784,82812,82830,82882,82884,82888,82896,82918,82924,82952,82960,82974,82976,83004,83008,83064,83184,83424,83468,83480,83504,83518,83552,83580,83648,83704,83740,83768,83824,83838,83842,83844,83848,83856,83872,83900,83910,83916,83928,83950,83984,84e3,84028,84032,84088,84208,84448,84928,85040,85054,85088,85116,85184,85240,85488,85560,85616,85630,85728,85756,85764,85768,85776,85790,85792,85820,85824,85880,85894,85900,85912,85936,85966,85980,86048,86080,86136,86256,86496,86976,88160,88188,88256,88312,88560,89056,89200,89214,89312,89340,89536,89592,89608,89616,89632,89664,89720,89840,89868,89880,89904,89952,89980,89998,90012,90040,90190,90204,90254,90268,90296,90306,90308,90312,90334,90382,90396,90424,90480,90494,90500,90504,90512,90526,90528,90556,90566,90572,90584,90610,90612,90638,90652,90680,90736,90750,90848,90876,90884,90888,90896,90910,90912,90940,90944,91e3,91014,91020,91032,91056,91070,91086,91100,91106,91108,91112,91126,91150,91164,91192,91248,91262,91360,91388,91584,91640,91664,91678,91680,91708,91712,91768,91888,91928,91952,91966,92e3,92028,92046,92060,92088,92098,92100,92104,92112,92126,92134,92140,92188,92216,92272,92384,92412,92608,92664,93168,93200,93214,93216,93244,93248,93304,93424,93664,93720,93744,93758,93792,93820,93888,93944,93980,94008,94064,94078,94084,94088,94096,94110,94112,94140,94150,94156,94168,94246,94252,94278,94284,94296,94318,94342,94348,94360,94384,94398,94414,94428,94440,94470,94476,94488,94512,94526,94560,94588,94606,94620,94648,94658,94660,94664,94672,94686,94694,94700,94714,94726,94732,94744,94768,94782,94816,94844,94912,94968,94990,95004,95032,95088,95102,95112,95120,95134,95136,95164,95180,95192,95214,95218,95220,95244,95256,95280,95294,95328,95356,95424,95480,95728,95758,95772,95800,95856,95870,95968,95996,96008,96016,96030,96032,96060,96064,96120,96152,96176,96190,96220,96226,96228,96232,96290,96292,96296,96310,96322,96324,96328,96336,96350,96358,96364,96386,96388,96392,96400,96414,96416,96444,96454,96460,96472,96494,96498,96500,96514,96516,96520,96528,96542,96544,96572,96576,96632,96646,96652,96664,96688,96702,96718,96732,96738,96740,96744,96758,96772,96776,96784,96798,96800,96828,96832,96888,97008,97030,97036,97048,97072,97086,97120,97148,97166,97180,97208,97220,97224,97232,97246,97254,97260,97326,97330,97332,97358,97372,97378,97380,97384,97398,97422,97436,97464,97474,97476,97480,97488,97502,97510,97516,97550,97564,97592,97648,97666,97668,97672,97680,97694,97696,97724,97734,97740,97752,97774,97830,97836,97850,97862,97868,97880,97902,97906,97908,97926,97932,97944,97968,97998,98012,98018,98020,98024,98038,98618,98674,98676,98838,98854,98874,98892,98904,98926,98930,98932,98968,99006,99042,99044,99048,99062,99166,99194,99246,99286,99350,99366,99372,99386,99398,99416,99438,99442,99444,99462,99504,99518,99534,99548,99554,99556,99560,99574,99590,99596,99608,99632,99646,99680,99708,99726,99740,99768,99778,99780,99784,99792,99806,99814,99820,99834,99858,99860,99874,99880,99894,99906,99920,99934,99962,99970,99972,99976,99984,99998,1e5,100028,100038,100044,100056,100078,100082,100084,100142,100174,100188,100246,100262,100268,100306,100308,100390,100396,100410,100422,100428,100440,100462,100466,100468,100486,100504,100528,100542,100558,100572,100578,100580,100584,100598,100620,100656,100670,100704,100732,100750,100792,100802,100808,100816,100830,100838,100844,100858,100888,100912,100926,100960,100988,101056,101112,101148,101176,101232,101246,101250,101252,101256,101264,101278,101280,101308,101318,101324,101336,101358,101362,101364,101410,101412,101416,101430,101442,101448,101456,101470,101478,101498,101506,101508,101520,101534,101536,101564,101580,101618,101620,101636,101640,101648,101662,101664,101692,101696,101752,101766,101784,101838,101858,101860,101864,101934,101938,101940,101966,101980,101986,101988,101992,102030,102044,102072,102082,102084,102088,102096,102138,102166,102182,102188,102214,102220,102232,102254,102282,102290,102292,102306,102308,102312,102326,102444,102458,102470,102476,102488,102514,102516,102534,102552,102576,102590,102606,102620,102626,102632,102646,102662,102668,102704,102718,102752,102780,102798,102812,102840,102850,102856,102864,102878,102886,102892,102906,102936,102974,103008,103036,103104,103160,103224,103280,103294,103298,103300,103312,103326,103328,103356,103366,103372,103384,103406,103410,103412,103472,103486,103520,103548,103616,103672,103920,103992,104048,104062,104160,104188,104194,104196,104200,104208,104224,104252,104256,104312,104326,104332,104344,104368,104382,104398,104412,104418,104420,104424,104482,104484,104514,104520,104528,104542,104550,104570,104578,104580,104592,104606,104608,104636,104652,104690,104692,104706,104712,104734,104736,104764,104768,104824,104838,104856,104910,104930,104932,104936,104968,104976,104990,104992,105020,105024,105080,105200,105240,105278,105312,105372,105410,105412,105416,105424,105446,105518,105524,105550,105564,105570,105572,105576,105614,105628,105656,105666,105672,105680,105702,105722,105742,105756,105784,105840,105854,105858,105860,105864,105872,105888,105932,105970,105972,106006,106022,106028,106054,106060,106072,106100,106118,106124,106136,106160,106174,106190,106210,106212,106216,106250,106258,106260,106274,106276,106280,106306,106308,106312,106320,106334,106348,106394,106414,106418,106420,106566,106572,106610,106612,106630,106636,106648,106672,106686,106722,106724,106728,106742,106758,106764,106776,106800,106814,106848,106876,106894,106908,106936,106946,106948,106952,106960,106974,106982,106988,107032,107056,107070,107104,107132,107200,107256,107292,107320,107376,107390,107394,107396,107400,107408,107422,107424,107452,107462,107468,107480,107502,107506,107508,107544,107568,107582,107616,107644,107712,107768,108016,108060,108088,108144,108158,108256,108284,108290,108292,108296,108304,108318,108320,108348,108352,108408,108422,108428,108440,108464,108478,108494,108508,108514,108516,108520,108592,108640,108668,108736,108792,109040,109536,109680,109694,109792,109820,110016,110072,110084,110088,110096,110112,110140,110144,110200,110320,110342,110348,110360,110384,110398,110432,110460,110478,110492,110520,110532,110536,110544,110558,110658,110686,110714,110722,110724,110728,110736,110750,110752,110780,110796,110834,110836,110850,110852,110856,110864,110878,110880,110908,110912,110968,110982,111e3,111054,111074,111076,111080,111108,111112,111120,111134,111136,111164,111168,111224,111344,111372,111422,111456,111516,111554,111556,111560,111568,111590,111632,111646,111648,111676,111680,111736,111856,112096,112152,112224,112252,112320,112440,112514,112516,112520,112528,112542,112544,112588,112686,112718,112732,112782,112796,112824,112834,112836,112840,112848,112870,112890,112910,112924,112952,113008,113022,113026,113028,113032,113040,113054,113056,113100,113138,113140,113166,113180,113208,113264,113278,113376,113404,113416,113424,113440,113468,113472,113560,113614,113634,113636,113640,113686,113702,113708,113734,113740,113752,113778,113780,113798,113804,113816,113840,113854,113870,113890,113892,113896,113926,113932,113944,113968,113982,114016,114044,114076,114114,114116,114120,114128,114150,114170,114194,114196,114210,114212,114216,114242,114244,114248,114256,114270,114278,114306,114308,114312,114320,114334,114336,114364,114380,114420,114458,114478,114482,114484,114510,114524,114530,114532,114536,114842,114866,114868,114970,114994,114996,115042,115044,115048,115062,115130,115226,115250,115252,115278,115292,115298,115300,115304,115318,115342,115394,115396,115400,115408,115422,115430,115436,115450,115478,115494,115514,115526,115532,115570,115572,115738,115758,115762,115764,115790,115804,115810,115812,115816,115830,115854,115868,115896,115906,115912,115920,115934,115942,115948,115962,115996,116024,116080,116094,116098,116100,116104,116112,116126,116128,116156,116166,116172,116184,116206,116210,116212,116246,116262,116268,116282,116294,116300,116312,116334,116338,116340,116358,116364,116376,116400,116414,116430,116444,116450,116452,116456,116498,116500,116514,116520,116534,116546,116548,116552,116560,116574,116582,116588,116602,116654,116694,116714,116762,116782,116786,116788,116814,116828,116834,116836,116840,116854,116878,116892,116920,116930,116936,116944,116958,116966,116972,116986,117006,117048,117104,117118,117122,117124,117136,117150,117152,117180,117190,117196,117208,117230,117234,117236,117304,117360,117374,117472,117500,117506,117508,117512,117520,117536,117564,117568,117624,117638,117644,117656,117680,117694,117710,117724,117730,117732,117736,117750,117782,117798,117804,117818,117830,117848,117874,117876,117894,117936,117950,117966,117986,117988,117992,118022,118028,118040,118064,118078,118112,118140,118172,118210,118212,118216,118224,118238,118246,118266,118306,118312,118338,118352,118366,118374,118394,118402,118404,118408,118416,118430,118432,118460,118476,118514,118516,118574,118578,118580,118606,118620,118626,118628,118632,118678,118694,118700,118730,118738,118740,118830,118834,118836,118862,118876,118882,118884,118888,118902,118926,118940,118968,118978,118980,118984,118992,119006,119014,119020,119034,119068,119096,119152,119166,119170,119172,119176,119184,119198,119200,119228,119238,119244,119256,119278,119282,119284,119324,119352,119408,119422,119520,119548,119554,119556,119560,119568,119582,119584,119612,119616,119672,119686,119692,119704,119728,119742,119758,119772,119778,119780,119784,119798,119920,119934,120032,120060,120256,120312,120324,120328,120336,120352,120384,120440,120560,120582,120588,120600,120624,120638,120672,120700,120718,120732,120760,120770,120772,120776,120784,120798,120806,120812,120870,120876,120890,120902,120908,120920,120946,120948,120966,120972,120984,121008,121022,121038,121058,121060,121064,121078,121100,121112,121136,121150,121184,121212,121244,121282,121284,121288,121296,121318,121338,121356,121368,121392,121406,121440,121468,121536,121592,121656,121730,121732,121736,121744,121758,121760,121804,121842,121844,121890,121922,121924,121928,121936,121950,121958,121978,121986,121988,121992,122e3,122014,122016,122044,122060,122098,122100,122116,122120,122128,122142,122144,122172,122176,122232,122246,122264,122318,122338,122340,122344,122414,122418,122420,122446,122460,122466,122468,122472,122510,122524,122552,122562,122564,122568,122576,122598,122618,122646,122662,122668,122694,122700,122712,122738,122740,122762,122770,122772,122786,122788,122792,123018,123026,123028,123042,123044,123048,123062,123098,123146,123154,123156,123170,123172,123176,123190,123202,123204,123208,123216,123238,123244,123258,123290,123314,123316,123402,123410,123412,123426,123428,123432,123446,123458,123464,123472,123486,123494,123500,123514,123522,123524,123528,123536,123552,123580,123590,123596,123608,123630,123634,123636,123674,123698,123700,123740,123746,123748,123752,123834,123914,123922,123924,123938,123944,123958,123970,123976,123984,123998,124006,124012,124026,124034,124036,124048,124062,124064,124092,124102,124108,124120,124142,124146,124148,124162,124164,124168,124176,124190,124192,124220,124224,124280,124294,124300,124312,124336,124350,124366,124380,124386,124388,124392,124406,124442,124462,124466,124468,124494,124508,124514,124520,124558,124572,124600,124610,124612,124616,124624,124646,124666,124694,124710,124716,124730,124742,124748,124760,124786,124788,124818,124820,124834,124836,124840,124854,124946,124948,124962,124964,124968,124982,124994,124996,125e3,125008,125022,125030,125036,125050,125058,125060,125064,125072,125086,125088,125116,125126,125132,125144,125166,125170,125172,125186,125188,125192,125200,125216,125244,125248,125304,125318,125324,125336,125360,125374,125390,125404,125410,125412,125416,125430,125444,125448,125456,125472,125504,125560,125680,125702,125708,125720,125744,125758,125792,125820,125838,125852,125880,125890,125892,125896,125904,125918,125926,125932,125978,125998,126002,126004,126030,126044,126050,126052,126056,126094,126108,126136,126146,126148,126152,126160,126182,126202,126222,126236,126264,126320,126334,126338,126340,126344,126352,126366,126368,126412,126450,126452,126486,126502,126508,126522,126534,126540,126552,126574,126578,126580,126598,126604,126616,126640,126654,126670,126684,126690,126692,126696,126738,126754,126756,126760,126774,126786,126788,126792,126800,126814,126822,126828,126842,126894,126898,126900,126934,127126,127142,127148,127162,127178,127186,127188,127254,127270,127276,127290,127302,127308,127320,127342,127346,127348,127370,127378,127380,127394,127396,127400,127450,127510,127526,127532,127546,127558,127576,127598,127602,127604,127622,127628,127640,127664,127678,127694,127708,127714,127716,127720,127734,127754,127762,127764,127778,127784,127810,127812,127816,127824,127838,127846,127866,127898,127918,127922,127924,128022,128038,128044,128058,128070,128076,128088,128110,128114,128116,128134,128140,128152,128176,128190,128206,128220,128226,128228,128232,128246,128262,128268,128280,128304,128318,128352,128380,128398,128412,128440,128450,128452,128456,128464,128478,128486,128492,128506,128522,128530,128532,128546,128548,128552,128566,128578,128580,128584,128592,128606,128614,128634,128642,128644,128648,128656,128670,128672,128700,128716,128754,128756,128794,128814,128818,128820,128846,128860,128866,128868,128872,128886,128918,128934,128940,128954,128978,128980,129178,129198,129202,129204,129238,129258,129306,129326,129330,129332,129358,129372,129378,129380,129384,129398,129430,129446,129452,129466,129482,129490,129492,129562,129582,129586,129588,129614,129628,129634,129636,129640,129654,129678,129692,129720,129730,129732,129736,129744,129758,129766,129772,129814,129830,129836,129850,129862,129868,129880,129902,129906,129908,129930,129938,129940,129954,129956,129960,129974,130010]),Re.CODEWORD_TABLE=Int32Array.from([2627,1819,2622,2621,1813,1812,2729,2724,2723,2779,2774,2773,902,896,908,868,865,861,859,2511,873,871,1780,835,2493,825,2491,842,837,844,1764,1762,811,810,809,2483,807,2482,806,2480,815,814,813,812,2484,817,816,1745,1744,1742,1746,2655,2637,2635,2626,2625,2623,2628,1820,2752,2739,2737,2728,2727,2725,2730,2785,2783,2778,2777,2775,2780,787,781,747,739,736,2413,754,752,1719,692,689,681,2371,678,2369,700,697,694,703,1688,1686,642,638,2343,631,2341,627,2338,651,646,643,2345,654,652,1652,1650,1647,1654,601,599,2322,596,2321,594,2319,2317,611,610,608,606,2324,603,2323,615,614,612,1617,1616,1614,1612,616,1619,1618,2575,2538,2536,905,901,898,909,2509,2507,2504,870,867,864,860,2512,875,872,1781,2490,2489,2487,2485,1748,836,834,832,830,2494,827,2492,843,841,839,845,1765,1763,2701,2676,2674,2653,2648,2656,2634,2633,2631,2629,1821,2638,2636,2770,2763,2761,2750,2745,2753,2736,2735,2733,2731,1848,2740,2738,2786,2784,591,588,576,569,566,2296,1590,537,534,526,2276,522,2274,545,542,539,548,1572,1570,481,2245,466,2242,462,2239,492,485,482,2249,496,494,1534,1531,1528,1538,413,2196,406,2191,2188,425,419,2202,415,2199,432,430,427,1472,1467,1464,433,1476,1474,368,367,2160,365,2159,362,2157,2155,2152,378,377,375,2166,372,2165,369,2162,383,381,379,2168,1419,1418,1416,1414,385,1411,384,1423,1422,1420,1424,2461,802,2441,2439,790,786,783,794,2409,2406,2403,750,742,738,2414,756,753,1720,2367,2365,2362,2359,1663,693,691,684,2373,680,2370,702,699,696,704,1690,1687,2337,2336,2334,2332,1624,2329,1622,640,637,2344,634,2342,630,2340,650,648,645,2346,655,653,1653,1651,1649,1655,2612,2597,2595,2571,2568,2565,2576,2534,2529,2526,1787,2540,2537,907,904,900,910,2503,2502,2500,2498,1768,2495,1767,2510,2508,2506,869,866,863,2513,876,874,1782,2720,2713,2711,2697,2694,2691,2702,2672,2670,2664,1828,2678,2675,2647,2646,2644,2642,1823,2639,1822,2654,2652,2650,2657,2771,1855,2765,2762,1850,1849,2751,2749,2747,2754,353,2148,344,342,336,2142,332,2140,345,1375,1373,306,2130,299,2128,295,2125,319,314,311,2132,1354,1352,1349,1356,262,257,2101,253,2096,2093,274,273,267,2107,263,2104,280,278,275,1316,1311,1308,1320,1318,2052,202,2050,2044,2040,219,2063,212,2060,208,2055,224,221,2066,1260,1258,1252,231,1248,229,1266,1264,1261,1268,155,1998,153,1996,1994,1991,1988,165,164,2007,162,2006,159,2003,2e3,172,171,169,2012,166,2010,1186,1184,1182,1179,175,1176,173,1192,1191,1189,1187,176,1194,1193,2313,2307,2305,592,589,2294,2292,2289,578,572,568,2297,580,1591,2272,2267,2264,1547,538,536,529,2278,525,2275,547,544,541,1574,1571,2237,2235,2229,1493,2225,1489,478,2247,470,2244,465,2241,493,488,484,2250,498,495,1536,1533,1530,1539,2187,2186,2184,2182,1432,2179,1430,2176,1427,414,412,2197,409,2195,405,2193,2190,426,424,421,2203,418,2201,431,429,1473,1471,1469,1466,434,1477,1475,2478,2472,2470,2459,2457,2454,2462,803,2437,2432,2429,1726,2443,2440,792,789,785,2401,2399,2393,1702,2389,1699,2411,2408,2405,745,741,2415,758,755,1721,2358,2357,2355,2353,1661,2350,1660,2347,1657,2368,2366,2364,2361,1666,690,687,2374,683,2372,701,698,705,1691,1689,2619,2617,2610,2608,2605,2613,2593,2588,2585,1803,2599,2596,2563,2561,2555,1797,2551,1795,2573,2570,2567,2577,2525,2524,2522,2520,1786,2517,1785,2514,1783,2535,2533,2531,2528,1788,2541,2539,906,903,911,2721,1844,2715,2712,1838,1836,2699,2696,2693,2703,1827,1826,1824,2673,2671,2669,2666,1829,2679,2677,1858,1857,2772,1854,1853,1851,1856,2766,2764,143,1987,139,1986,135,133,131,1984,128,1983,125,1981,138,137,136,1985,1133,1132,1130,112,110,1974,107,1973,104,1971,1969,122,121,119,117,1977,114,1976,124,1115,1114,1112,1110,1117,1116,84,83,1953,81,1952,78,1950,1948,1945,94,93,91,1959,88,1958,85,1955,99,97,95,1961,1086,1085,1083,1081,1078,100,1090,1089,1087,1091,49,47,1917,44,1915,1913,1910,1907,59,1926,56,1925,53,1922,1919,66,64,1931,61,1929,1042,1040,1038,71,1035,70,1032,68,1048,1047,1045,1043,1050,1049,12,10,1869,1867,1864,1861,21,1880,19,1877,1874,1871,28,1888,25,1886,22,1883,982,980,977,974,32,30,991,989,987,984,34,995,994,992,2151,2150,2147,2146,2144,356,355,354,2149,2139,2138,2136,2134,1359,343,341,338,2143,335,2141,348,347,346,1376,1374,2124,2123,2121,2119,1326,2116,1324,310,308,305,2131,302,2129,298,2127,320,318,316,313,2133,322,321,1355,1353,1351,1357,2092,2091,2089,2087,1276,2084,1274,2081,1271,259,2102,256,2100,252,2098,2095,272,269,2108,266,2106,281,279,277,1317,1315,1313,1310,282,1321,1319,2039,2037,2035,2032,1203,2029,1200,1197,207,2053,205,2051,201,2049,2046,2043,220,218,2064,215,2062,211,2059,228,226,223,2069,1259,1257,1254,232,1251,230,1267,1265,1263,2316,2315,2312,2311,2309,2314,2304,2303,2301,2299,1593,2308,2306,590,2288,2287,2285,2283,1578,2280,1577,2295,2293,2291,579,577,574,571,2298,582,581,1592,2263,2262,2260,2258,1545,2255,1544,2252,1541,2273,2271,2269,2266,1550,535,532,2279,528,2277,546,543,549,1575,1573,2224,2222,2220,1486,2217,1485,2214,1482,1479,2238,2236,2234,2231,1496,2228,1492,480,477,2248,473,2246,469,2243,490,487,2251,497,1537,1535,1532,2477,2476,2474,2479,2469,2468,2466,2464,1730,2473,2471,2453,2452,2450,2448,1729,2445,1728,2460,2458,2456,2463,805,804,2428,2427,2425,2423,1725,2420,1724,2417,1722,2438,2436,2434,2431,1727,2444,2442,793,791,788,795,2388,2386,2384,1697,2381,1696,2378,1694,1692,2402,2400,2398,2395,1703,2392,1701,2412,2410,2407,751,748,744,2416,759,757,1807,2620,2618,1806,1805,2611,2609,2607,2614,1802,1801,1799,2594,2592,2590,2587,1804,2600,2598,1794,1793,1791,1789,2564,2562,2560,2557,1798,2554,1796,2574,2572,2569,2578,1847,1846,2722,1843,1842,1840,1845,2716,2714,1835,1834,1832,1830,1839,1837,2700,2698,2695,2704,1817,1811,1810,897,862,1777,829,826,838,1760,1758,808,2481,1741,1740,1738,1743,2624,1818,2726,2776,782,740,737,1715,686,679,695,1682,1680,639,628,2339,647,644,1645,1643,1640,1648,602,600,597,595,2320,593,2318,609,607,604,1611,1610,1608,1606,613,1615,1613,2328,926,924,892,886,899,857,850,2505,1778,824,823,821,819,2488,818,2486,833,831,828,840,1761,1759,2649,2632,2630,2746,2734,2732,2782,2781,570,567,1587,531,527,523,540,1566,1564,476,467,463,2240,486,483,1524,1521,1518,1529,411,403,2192,399,2189,423,416,1462,1457,1454,428,1468,1465,2210,366,363,2158,360,2156,357,2153,376,373,370,2163,1410,1409,1407,1405,382,1402,380,1417,1415,1412,1421,2175,2174,777,774,771,784,732,725,722,2404,743,1716,676,674,668,2363,665,2360,685,1684,1681,626,624,622,2335,620,2333,617,2330,641,635,649,1646,1644,1642,2566,928,925,2530,2527,894,891,888,2501,2499,2496,858,856,854,851,1779,2692,2668,2665,2645,2643,2640,2651,2768,2759,2757,2744,2743,2741,2748,352,1382,340,337,333,1371,1369,307,300,296,2126,315,312,1347,1342,1350,261,258,250,2097,246,2094,271,268,264,1306,1301,1298,276,1312,1309,2115,203,2048,195,2045,191,2041,213,209,2056,1246,1244,1238,225,1234,222,1256,1253,1249,1262,2080,2079,154,1997,150,1995,147,1992,1989,163,160,2004,156,2001,1175,1174,1172,1170,1167,170,1164,167,1185,1183,1180,1177,174,1190,1188,2025,2024,2022,587,586,564,559,556,2290,573,1588,520,518,512,2268,508,2265,530,1568,1565,461,457,2233,450,2230,446,2226,479,471,489,1526,1523,1520,397,395,2185,392,2183,389,2180,2177,410,2194,402,422,1463,1461,1459,1456,1470,2455,799,2433,2430,779,776,773,2397,2394,2390,734,728,724,746,1717,2356,2354,2351,2348,1658,677,675,673,670,667,688,1685,1683,2606,2589,2586,2559,2556,2552,927,2523,2521,2518,2515,1784,2532,895,893,890,2718,2709,2707,2689,2687,2684,2663,2662,2660,2658,1825,2667,2769,1852,2760,2758,142,141,1139,1138,134,132,129,126,1982,1129,1128,1126,1131,113,111,108,105,1972,101,1970,120,118,115,1109,1108,1106,1104,123,1113,1111,82,79,1951,75,1949,72,1946,92,89,86,1956,1077,1076,1074,1072,98,1069,96,1084,1082,1079,1088,1968,1967,48,45,1916,42,1914,39,1911,1908,60,57,54,1923,50,1920,1031,1030,1028,1026,67,1023,65,1020,62,1041,1039,1036,1033,69,1046,1044,1944,1943,1941,11,9,1868,7,1865,1862,1859,20,1878,16,1875,13,1872,970,968,966,963,29,960,26,23,983,981,978,975,33,971,31,990,988,985,1906,1904,1902,993,351,2145,1383,331,330,328,326,2137,323,2135,339,1372,1370,294,293,291,289,2122,286,2120,283,2117,309,303,317,1348,1346,1344,245,244,242,2090,239,2088,236,2085,2082,260,2099,249,270,1307,1305,1303,1300,1314,189,2038,186,2036,183,2033,2030,2026,206,198,2047,194,216,1247,1245,1243,1240,227,1237,1255,2310,2302,2300,2286,2284,2281,565,563,561,558,575,1589,2261,2259,2256,2253,1542,521,519,517,514,2270,511,533,1569,1567,2223,2221,2218,2215,1483,2211,1480,459,456,453,2232,449,474,491,1527,1525,1522,2475,2467,2465,2451,2449,2446,801,800,2426,2424,2421,2418,1723,2435,780,778,775,2387,2385,2382,2379,1695,2375,1693,2396,735,733,730,727,749,1718,2616,2615,2604,2603,2601,2584,2583,2581,2579,1800,2591,2550,2549,2547,2545,1792,2542,1790,2558,929,2719,1841,2710,2708,1833,1831,2690,2688,2686,1815,1809,1808,1774,1756,1754,1737,1736,1734,1739,1816,1711,1676,1674,633,629,1638,1636,1633,1641,598,1605,1604,1602,1600,605,1609,1607,2327,887,853,1775,822,820,1757,1755,1584,524,1560,1558,468,464,1514,1511,1508,1519,408,404,400,1452,1447,1444,417,1458,1455,2208,364,361,358,2154,1401,1400,1398,1396,374,1393,371,1408,1406,1403,1413,2173,2172,772,726,723,1712,672,669,666,682,1678,1675,625,623,621,618,2331,636,632,1639,1637,1635,920,918,884,880,889,849,848,847,846,2497,855,852,1776,2641,2742,2787,1380,334,1367,1365,301,297,1340,1338,1335,1343,255,251,247,1296,1291,1288,265,1302,1299,2113,204,196,192,2042,1232,1230,1224,214,1220,210,1242,1239,1235,1250,2077,2075,151,148,1993,144,1990,1163,1162,1160,1158,1155,161,1152,157,1173,1171,1168,1165,168,1181,1178,2021,2020,2018,2023,585,560,557,1585,516,509,1562,1559,458,447,2227,472,1516,1513,1510,398,396,393,390,2181,386,2178,407,1453,1451,1449,1446,420,1460,2209,769,764,720,712,2391,729,1713,664,663,661,659,2352,656,2349,671,1679,1677,2553,922,919,2519,2516,885,883,881,2685,2661,2659,2767,2756,2755,140,1137,1136,130,127,1125,1124,1122,1127,109,106,102,1103,1102,1100,1098,116,1107,1105,1980,80,76,73,1947,1068,1067,1065,1063,90,1060,87,1075,1073,1070,1080,1966,1965,46,43,40,1912,36,1909,1019,1018,1016,1014,58,1011,55,1008,51,1029,1027,1024,1021,63,1037,1034,1940,1939,1937,1942,8,1866,4,1863,1,1860,956,954,952,949,946,17,14,969,967,964,961,27,957,24,979,976,972,1901,1900,1898,1896,986,1905,1903,350,349,1381,329,327,324,1368,1366,292,290,287,284,2118,304,1341,1339,1337,1345,243,240,237,2086,233,2083,254,1297,1295,1293,1290,1304,2114,190,187,184,2034,180,2031,177,2027,199,1233,1231,1229,1226,217,1223,1241,2078,2076,584,555,554,552,550,2282,562,1586,507,506,504,502,2257,499,2254,515,1563,1561,445,443,441,2219,438,2216,435,2212,460,454,475,1517,1515,1512,2447,798,797,2422,2419,770,768,766,2383,2380,2376,721,719,717,714,731,1714,2602,2582,2580,2548,2546,2543,923,921,2717,2706,2705,2683,2682,2680,1771,1752,1750,1733,1732,1731,1735,1814,1707,1670,1668,1631,1629,1626,1634,1599,1598,1596,1594,1603,1601,2326,1772,1753,1751,1581,1554,1552,1504,1501,1498,1509,1442,1437,1434,401,1448,1445,2206,1392,1391,1389,1387,1384,359,1399,1397,1394,1404,2171,2170,1708,1672,1669,619,1632,1630,1628,1773,1378,1363,1361,1333,1328,1336,1286,1281,1278,248,1292,1289,2111,1218,1216,1210,197,1206,193,1228,1225,1221,1236,2073,2071,1151,1150,1148,1146,152,1143,149,1140,145,1161,1159,1156,1153,158,1169,1166,2017,2016,2014,2019,1582,510,1556,1553,452,448,1506,1500,394,391,387,1443,1441,1439,1436,1450,2207,765,716,713,1709,662,660,657,1673,1671,916,914,879,878,877,882,1135,1134,1121,1120,1118,1123,1097,1096,1094,1092,103,1101,1099,1979,1059,1058,1056,1054,77,1051,74,1066,1064,1061,1071,1964,1963,1007,1006,1004,1002,999,41,996,37,1017,1015,1012,1009,52,1025,1022,1936,1935,1933,1938,942,940,938,935,932,5,2,955,953,950,947,18,943,15,965,962,958,1895,1894,1892,1890,973,1899,1897,1379,325,1364,1362,288,285,1334,1332,1330,241,238,234,1287,1285,1283,1280,1294,2112,188,185,181,178,2028,1219,1217,1215,1212,200,1209,1227,2074,2072,583,553,551,1583,505,503,500,513,1557,1555,444,442,439,436,2213,455,451,1507,1505,1502,796,763,762,760,767,711,710,708,706,2377,718,715,1710,2544,917,915,2681,1627,1597,1595,2325,1769,1749,1747,1499,1438,1435,2204,1390,1388,1385,1395,2169,2167,1704,1665,1662,1625,1623,1620,1770,1329,1282,1279,2109,1214,1207,1222,2068,2065,1149,1147,1144,1141,146,1157,1154,2013,2011,2008,2015,1579,1549,1546,1495,1487,1433,1431,1428,1425,388,1440,2205,1705,658,1667,1664,1119,1095,1093,1978,1057,1055,1052,1062,1962,1960,1005,1003,1e3,997,38,1013,1010,1932,1930,1927,1934,941,939,936,933,6,930,3,951,948,944,1889,1887,1884,1881,959,1893,1891,35,1377,1360,1358,1327,1325,1322,1331,1277,1275,1272,1269,235,1284,2110,1205,1204,1201,1198,182,1195,179,1213,2070,2067,1580,501,1551,1548,440,437,1497,1494,1490,1503,761,709,707,1706,913,912,2198,1386,2164,2161,1621,1766,2103,1208,2058,2054,1145,1142,2005,2002,1999,2009,1488,1429,1426,2200,1698,1659,1656,1975,1053,1957,1954,1001,998,1924,1921,1918,1928,937,934,931,1879,1876,1873,1870,945,1885,1882,1323,1273,1270,2105,1202,1199,1196,1211,2061,2057,1576,1543,1540,1484,1481,1478,1491,1700]);class nd{constructor(e,n){this.bits=e,this.points=n}getBits(){return this.bits}getPoints(){return this.points}}class Fe{static detectMultiple(e,n,i){let s=e.getBlackMatrix(),a=Fe.detect(i,s);return a.length||(s=s.clone(),s.rotate180(),a=Fe.detect(i,s)),new nd(s,a)}static detect(e,n){const i=new Array;let s=0,a=0,l=!1;for(;s<n.getHeight();){const d=Fe.findVertices(n,s,a);if(d[0]==null&&d[3]==null){if(!l)break;l=!1,a=0;for(const h of i)h[1]!=null&&(s=Math.trunc(Math.max(s,h[1].getY()))),h[3]!=null&&(s=Math.max(s,Math.trunc(h[3].getY())));s+=Fe.ROW_STEP;continue}if(l=!0,i.push(d),!e)break;d[2]!=null?(a=Math.trunc(d[2].getX()),s=Math.trunc(d[2].getY())):(a=Math.trunc(d[4].getX()),s=Math.trunc(d[4].getY()))}return i}static findVertices(e,n,i){const s=e.getHeight(),a=e.getWidth(),l=new Array(8);return Fe.copyToResult(l,Fe.findRowsWithPattern(e,s,a,n,i,Fe.START_PATTERN),Fe.INDEXES_START_PATTERN),l[4]!=null&&(i=Math.trunc(l[4].getX()),n=Math.trunc(l[4].getY())),Fe.copyToResult(l,Fe.findRowsWithPattern(e,s,a,n,i,Fe.STOP_PATTERN),Fe.INDEXES_STOP_PATTERN),l}static copyToResult(e,n,i){for(let s=0;s<i.length;s++)e[i[s]]=n[s]}static findRowsWithPattern(e,n,i,s,a,l){const d=new Array(4);let h=!1;const g=new Int32Array(l.length);for(;s<n;s+=Fe.ROW_STEP){let b=Fe.findGuardPattern(e,a,s,i,!1,l,g);if(b!=null){for(;s>0;){const I=Fe.findGuardPattern(e,a,--s,i,!1,l,g);if(I!=null)b=I;else{s++;break}}d[0]=new be(b[0],s),d[1]=new be(b[1],s),h=!0;break}}let w=s+1;if(h){let b=0,I=Int32Array.from([Math.trunc(d[0].getX()),Math.trunc(d[1].getX())]);for(;w<n;w++){const N=Fe.findGuardPattern(e,I[0],w,i,!1,l,g);if(N!=null&&Math.abs(I[0]-N[0])<Fe.MAX_PATTERN_DRIFT&&Math.abs(I[1]-N[1])<Fe.MAX_PATTERN_DRIFT)I=N,b=0;else{if(b>Fe.SKIPPED_ROW_COUNT_MAX)break;b++}}w-=b+1,d[2]=new be(I[0],w),d[3]=new be(I[1],w)}return w-s<Fe.BARCODE_MIN_HEIGHT&&Z.fill(d,null),d}static findGuardPattern(e,n,i,s,a,l,d){Z.fillWithin(d,0,d.length,0);let h=n,g=0;for(;e.get(h,i)&&h>0&&g++<Fe.MAX_PIXEL_DRIFT;)h--;let w=h,b=0,I=l.length;for(let N=a;w<s;w++)if(e.get(w,i)!==N)d[b]++;else{if(b===I-1){if(Fe.patternMatchVariance(d,l,Fe.MAX_INDIVIDUAL_VARIANCE)<Fe.MAX_AVG_VARIANCE)return new Int32Array([h,w]);h+=d[0]+d[1],R.arraycopy(d,2,d,0,b-1),d[b-1]=0,d[b]=0,b--}else b++;d[b]=1,N=!N}return b===I-1&&Fe.patternMatchVariance(d,l,Fe.MAX_INDIVIDUAL_VARIANCE)<Fe.MAX_AVG_VARIANCE?new Int32Array([h,w-1]):null}static patternMatchVariance(e,n,i){let s=e.length,a=0,l=0;for(let g=0;g<s;g++)a+=e[g],l+=n[g];if(a<l)return 1/0;let d=a/l;i*=d;let h=0;for(let g=0;g<s;g++){let w=e[g],b=n[g]*d,I=w>b?w-b:b-w;if(I>i)return 1/0;h+=I}return h/a}}Fe.INDEXES_START_PATTERN=Int32Array.from([0,4,1,5]),Fe.INDEXES_STOP_PATTERN=Int32Array.from([6,2,7,3]),Fe.MAX_AVG_VARIANCE=.42,Fe.MAX_INDIVIDUAL_VARIANCE=.8,Fe.START_PATTERN=Int32Array.from([8,1,1,1,1,1,1,3]),Fe.STOP_PATTERN=Int32Array.from([7,1,1,3,1,1,1,2,1]),Fe.MAX_PIXEL_DRIFT=3,Fe.MAX_PATTERN_DRIFT=5,Fe.SKIPPED_ROW_COUNT_MAX=25,Fe.ROW_STEP=5,Fe.BARCODE_MIN_HEIGHT=10;class Ft{constructor(e,n){if(n.length===0)throw new E;this.field=e;let i=n.length;if(i>1&&n[0]===0){let s=1;for(;s<i&&n[s]===0;)s++;s===i?this.coefficients=new Int32Array([0]):(this.coefficients=new Int32Array(i-s),R.arraycopy(n,s,this.coefficients,0,this.coefficients.length))}else this.coefficients=n}getCoefficients(){return this.coefficients}getDegree(){return this.coefficients.length-1}isZero(){return this.coefficients[0]===0}getCoefficient(e){return this.coefficients[this.coefficients.length-1-e]}evaluateAt(e){if(e===0)return this.getCoefficient(0);if(e===1){let s=0;for(let a of this.coefficients)s=this.field.add(s,a);return s}let n=this.coefficients[0],i=this.coefficients.length;for(let s=1;s<i;s++)n=this.field.add(this.field.multiply(e,n),this.coefficients[s]);return n}add(e){if(!this.field.equals(e.field))throw new E("ModulusPolys do not have same ModulusGF field");if(this.isZero())return e;if(e.isZero())return this;let n=this.coefficients,i=e.coefficients;if(n.length>i.length){let l=n;n=i,i=l}let s=new Int32Array(i.length),a=i.length-n.length;R.arraycopy(i,0,s,0,a);for(let l=a;l<i.length;l++)s[l]=this.field.add(n[l-a],i[l]);return new Ft(this.field,s)}subtract(e){if(!this.field.equals(e.field))throw new E("ModulusPolys do not have same ModulusGF field");return e.isZero()?this:this.add(e.negative())}multiply(e){return e instanceof Ft?this.multiplyOther(e):this.multiplyScalar(e)}multiplyOther(e){if(!this.field.equals(e.field))throw new E("ModulusPolys do not have same ModulusGF field");if(this.isZero()||e.isZero())return new Ft(this.field,new Int32Array([0]));let n=this.coefficients,i=n.length,s=e.coefficients,a=s.length,l=new Int32Array(i+a-1);for(let d=0;d<i;d++){let h=n[d];for(let g=0;g<a;g++)l[d+g]=this.field.add(l[d+g],this.field.multiply(h,s[g]))}return new Ft(this.field,l)}negative(){let e=this.coefficients.length,n=new Int32Array(e);for(let i=0;i<e;i++)n[i]=this.field.subtract(0,this.coefficients[i]);return new Ft(this.field,n)}multiplyScalar(e){if(e===0)return new Ft(this.field,new Int32Array([0]));if(e===1)return this;let n=this.coefficients.length,i=new Int32Array(n);for(let s=0;s<n;s++)i[s]=this.field.multiply(this.coefficients[s],e);return new Ft(this.field,i)}multiplyByMonomial(e,n){if(e<0)throw new E;if(n===0)return new Ft(this.field,new Int32Array([0]));let i=this.coefficients.length,s=new Int32Array(i+e);for(let a=0;a<i;a++)s[a]=this.field.multiply(this.coefficients[a],n);return new Ft(this.field,s)}toString(){let e=new oe;for(let n=this.getDegree();n>=0;n--){let i=this.getCoefficient(n);i!==0&&(i<0?(e.append(" - "),i=-i):e.length()>0&&e.append(" + "),(n===0||i!==1)&&e.append(i),n!==0&&(n===1?e.append("x"):(e.append("x^"),e.append(n))))}return e.toString()}}class rd{add(e,n){return(e+n)%this.modulus}subtract(e,n){return(this.modulus+e-n)%this.modulus}exp(e){return this.expTable[e]}log(e){if(e===0)throw new E;return this.logTable[e]}inverse(e){if(e===0)throw new jt;return this.expTable[this.modulus-this.logTable[e]-1]}multiply(e,n){return e===0||n===0?0:this.expTable[(this.logTable[e]+this.logTable[n])%(this.modulus-1)]}getSize(){return this.modulus}equals(e){return e===this}}class no extends rd{constructor(e,n){super(),this.modulus=e,this.expTable=new Int32Array(e),this.logTable=new Int32Array(e);let i=1;for(let s=0;s<e;s++)this.expTable[s]=i,i=i*n%e;for(let s=0;s<e-1;s++)this.logTable[this.expTable[s]]=s;this.zero=new Ft(this,new Int32Array([0])),this.one=new Ft(this,new Int32Array([1]))}getZero(){return this.zero}getOne(){return this.one}buildMonomial(e,n){if(e<0)throw new E;if(n===0)return this.zero;let i=new Int32Array(e+1);return i[0]=n,new Ft(this,i)}}no.PDF417_GF=new no(Re.NUMBER_OF_CODEWORDS,3);class ds{constructor(){this.field=no.PDF417_GF}decode(e,n,i){let s=new Ft(this.field,e),a=new Int32Array(n),l=!1;for(let F=n;F>0;F--){let U=s.evaluateAt(this.field.exp(F));a[n-F]=U,U!==0&&(l=!0)}if(!l)return 0;let d=this.field.getOne();if(i!=null)for(const F of i){let U=this.field.exp(e.length-1-F),W=new Ft(this.field,new Int32Array([this.field.subtract(0,U),1]));d=d.multiply(W)}let h=new Ft(this.field,a),g=this.runEuclideanAlgorithm(this.field.buildMonomial(n,1),h,n),w=g[0],b=g[1],I=this.findErrorLocations(w),N=this.findErrorMagnitudes(b,w,I);for(let F=0;F<I.length;F++){let U=e.length-1-this.field.log(I[F]);if(U<0)throw D.getChecksumInstance();e[U]=this.field.subtract(e[U],N[F])}return I.length}runEuclideanAlgorithm(e,n,i){if(e.getDegree()<n.getDegree()){let I=e;e=n,n=I}let s=e,a=n,l=this.field.getZero(),d=this.field.getOne();for(;a.getDegree()>=Math.round(i/2);){let I=s,N=l;if(s=a,l=d,s.isZero())throw D.getChecksumInstance();a=I;let F=this.field.getZero(),U=s.getCoefficient(s.getDegree()),W=this.field.inverse(U);for(;a.getDegree()>=s.getDegree()&&!a.isZero();){let K=a.getDegree()-s.getDegree(),fe=this.field.multiply(a.getCoefficient(a.getDegree()),W);F=F.add(this.field.buildMonomial(K,fe)),a=a.subtract(s.multiplyByMonomial(K,fe))}d=F.multiply(l).subtract(N).negative()}let h=d.getCoefficient(0);if(h===0)throw D.getChecksumInstance();let g=this.field.inverse(h),w=d.multiply(g),b=a.multiply(g);return[w,b]}findErrorLocations(e){let n=e.getDegree(),i=new Int32Array(n),s=0;for(let a=1;a<this.field.getSize()&&s<n;a++)e.evaluateAt(a)===0&&(i[s]=this.field.inverse(a),s++);if(s!==n)throw D.getChecksumInstance();return i}findErrorMagnitudes(e,n,i){let s=n.getDegree(),a=new Int32Array(s);for(let g=1;g<=s;g++)a[s-g]=this.field.multiply(g,n.getCoefficient(g));let l=new Ft(this.field,a),d=i.length,h=new Int32Array(d);for(let g=0;g<d;g++){let w=this.field.inverse(i[g]),b=this.field.subtract(0,e.evaluateAt(w)),I=this.field.inverse(l.evaluateAt(w));h[g]=this.field.multiply(b,I)}return h}}class Qn{constructor(e,n,i,s,a){e instanceof Qn?this.constructor_2(e):this.constructor_1(e,n,i,s,a)}constructor_1(e,n,i,s,a){const l=n==null||i==null,d=s==null||a==null;if(l&&d)throw new P;l?(n=new be(0,s.getY()),i=new be(0,a.getY())):d&&(s=new be(e.getWidth()-1,n.getY()),a=new be(e.getWidth()-1,i.getY())),this.image=e,this.topLeft=n,this.bottomLeft=i,this.topRight=s,this.bottomRight=a,this.minX=Math.trunc(Math.min(n.getX(),i.getX())),this.maxX=Math.trunc(Math.max(s.getX(),a.getX())),this.minY=Math.trunc(Math.min(n.getY(),s.getY())),this.maxY=Math.trunc(Math.max(i.getY(),a.getY()))}constructor_2(e){this.image=e.image,this.topLeft=e.getTopLeft(),this.bottomLeft=e.getBottomLeft(),this.topRight=e.getTopRight(),this.bottomRight=e.getBottomRight(),this.minX=e.getMinX(),this.maxX=e.getMaxX(),this.minY=e.getMinY(),this.maxY=e.getMaxY()}static merge(e,n){return e==null?n:n==null?e:new Qn(e.image,e.topLeft,e.bottomLeft,n.topRight,n.bottomRight)}addMissingRows(e,n,i){let s=this.topLeft,a=this.bottomLeft,l=this.topRight,d=this.bottomRight;if(e>0){let h=i?this.topLeft:this.topRight,g=Math.trunc(h.getY()-e);g<0&&(g=0);let w=new be(h.getX(),g);i?s=w:l=w}if(n>0){let h=i?this.bottomLeft:this.bottomRight,g=Math.trunc(h.getY()+n);g>=this.image.getHeight()&&(g=this.image.getHeight()-1);let w=new be(h.getX(),g);i?a=w:d=w}return new Qn(this.image,s,a,l,d)}getMinX(){return this.minX}getMaxX(){return this.maxX}getMinY(){return this.minY}getMaxY(){return this.maxY}getTopLeft(){return this.topLeft}getTopRight(){return this.topRight}getBottomLeft(){return this.bottomLeft}getBottomRight(){return this.bottomRight}}class id{constructor(e,n,i,s){this.columnCount=e,this.errorCorrectionLevel=s,this.rowCountUpperPart=n,this.rowCountLowerPart=i,this.rowCount=n+i}getColumnCount(){return this.columnCount}getErrorCorrectionLevel(){return this.errorCorrectionLevel}getRowCount(){return this.rowCount}getRowCountUpperPart(){return this.rowCountUpperPart}getRowCountLowerPart(){return this.rowCountLowerPart}}class kr{constructor(){this.buffer=""}static form(e,n){let i=-1;function s(l,d,h,g,w,b){if(l==="%%")return"%";if(n[++i]===void 0)return;l=g?parseInt(g.substr(1)):void 0;let I=w?parseInt(w.substr(1)):void 0,N;switch(b){case"s":N=n[i];break;case"c":N=n[i][0];break;case"f":N=parseFloat(n[i]).toFixed(l);break;case"p":N=parseFloat(n[i]).toPrecision(l);break;case"e":N=parseFloat(n[i]).toExponential(l);break;case"x":N=parseInt(n[i]).toString(I||16);break;case"d":N=parseFloat(parseInt(n[i],I||10).toPrecision(l)).toFixed(0);break}N=typeof N=="object"?JSON.stringify(N):(+N).toString(I);let F=parseInt(h),U=h&&h[0]+""=="0"?"0":" ";for(;N.length<F;)N=d!==void 0?N+U:U+N;return N}let a=/%(-)?(0?[0-9]+)?([.][0-9]+)?([#][0-9]+)?([scfpexd%])/g;return e.replace(a,s)}format(e,...n){this.buffer+=kr.form(e,n)}toString(){return this.buffer}}class Rr{constructor(e){this.boundingBox=new Qn(e),this.codewords=new Array(e.getMaxY()-e.getMinY()+1)}getCodewordNearby(e){let n=this.getCodeword(e);if(n!=null)return n;for(let i=1;i<Rr.MAX_NEARBY_DISTANCE;i++){let s=this.imageRowToCodewordIndex(e)-i;if(s>=0&&(n=this.codewords[s],n!=null)||(s=this.imageRowToCodewordIndex(e)+i,s<this.codewords.length&&(n=this.codewords[s],n!=null)))return n}return null}imageRowToCodewordIndex(e){return e-this.boundingBox.getMinY()}setCodeword(e,n){this.codewords[this.imageRowToCodewordIndex(e)]=n}getCodeword(e){return this.codewords[this.imageRowToCodewordIndex(e)]}getBoundingBox(){return this.boundingBox}getCodewords(){return this.codewords}toString(){const e=new kr;let n=0;for(const i of this.codewords){if(i==null){e.format("%3d: | %n",n++);continue}e.format("%3d: %3d|%3d%n",n++,i.getRowNumber(),i.getValue())}return e.toString()}}Rr.MAX_NEARBY_DISTANCE=5;class Mr{constructor(){this.values=new Map}setValue(e){e=Math.trunc(e);let n=this.values.get(e);n==null&&(n=0),n++,this.values.set(e,n)}getValue(){let e=-1,n=new Array;for(const[i,s]of this.values.entries()){const a={getKey:()=>i,getValue:()=>s};a.getValue()>e?(e=a.getValue(),n=[],n.push(a.getKey())):a.getValue()===e&&n.push(a.getKey())}return Re.toIntArray(n)}getConfidence(e){return this.values.get(e)}}class fs extends Rr{constructor(e,n){super(e),this._isLeft=n}setRowNumbers(){for(let e of this.getCodewords())e?.setRowNumberAsRowIndicatorColumn()}adjustCompleteIndicatorColumnRowNumbers(e){let n=this.getCodewords();this.setRowNumbers(),this.removeIncorrectCodewords(n,e);let i=this.getBoundingBox(),s=this._isLeft?i.getTopLeft():i.getTopRight(),a=this._isLeft?i.getBottomLeft():i.getBottomRight(),l=this.imageRowToCodewordIndex(Math.trunc(s.getY())),d=this.imageRowToCodewordIndex(Math.trunc(a.getY())),h=-1,g=1,w=0;for(let b=l;b<d;b++){if(n[b]==null)continue;let I=n[b],N=I.getRowNumber()-h;if(N===0)w++;else if(N===1)g=Math.max(g,w),w=1,h=I.getRowNumber();else if(N<0||I.getRowNumber()>=e.getRowCount()||N>b)n[b]=null;else{let F;g>2?F=(g-2)*N:F=N;let U=F>=b;for(let W=1;W<=F&&!U;W++)U=n[b-W]!=null;U?n[b]=null:(h=I.getRowNumber(),w=1)}}}getRowHeights(){let e=this.getBarcodeMetadata();if(e==null)return null;this.adjustIncompleteIndicatorColumnRowNumbers(e);let n=new Int32Array(e.getRowCount());for(let i of this.getCodewords())if(i!=null){let s=i.getRowNumber();if(s>=n.length)continue;n[s]++}return n}adjustIncompleteIndicatorColumnRowNumbers(e){let n=this.getBoundingBox(),i=this._isLeft?n.getTopLeft():n.getTopRight(),s=this._isLeft?n.getBottomLeft():n.getBottomRight(),a=this.imageRowToCodewordIndex(Math.trunc(i.getY())),l=this.imageRowToCodewordIndex(Math.trunc(s.getY())),d=this.getCodewords(),h=-1;for(let g=a;g<l;g++){if(d[g]==null)continue;let w=d[g];w.setRowNumberAsRowIndicatorColumn();let b=w.getRowNumber()-h;b===0||(b===1?h=w.getRowNumber():w.getRowNumber()>=e.getRowCount()?d[g]=null:h=w.getRowNumber())}}getBarcodeMetadata(){let e=this.getCodewords(),n=new Mr,i=new Mr,s=new Mr,a=new Mr;for(let d of e){if(d==null)continue;d.setRowNumberAsRowIndicatorColumn();let h=d.getValue()%30,g=d.getRowNumber();switch(this._isLeft||(g+=2),g%3){case 0:i.setValue(h*3+1);break;case 1:a.setValue(h/3),s.setValue(h%3);break;case 2:n.setValue(h+1);break}}if(n.getValue().length===0||i.getValue().length===0||s.getValue().length===0||a.getValue().length===0||n.getValue()[0]<1||i.getValue()[0]+s.getValue()[0]<Re.MIN_ROWS_IN_BARCODE||i.getValue()[0]+s.getValue()[0]>Re.MAX_ROWS_IN_BARCODE)return null;let l=new id(n.getValue()[0],i.getValue()[0],s.getValue()[0],a.getValue()[0]);return this.removeIncorrectCodewords(e,l),l}removeIncorrectCodewords(e,n){for(let i=0;i<e.length;i++){let s=e[i];if(e[i]==null)continue;let a=s.getValue()%30,l=s.getRowNumber();if(l>n.getRowCount()){e[i]=null;continue}switch(this._isLeft||(l+=2),l%3){case 0:a*3+1!==n.getRowCountUpperPart()&&(e[i]=null);break;case 1:(Math.trunc(a/3)!==n.getErrorCorrectionLevel()||a%3!==n.getRowCountLowerPart())&&(e[i]=null);break;case 2:a+1!==n.getColumnCount()&&(e[i]=null);break}}}isLeft(){return this._isLeft}toString(){return"IsLeft: "+this._isLeft+`
63
- `+super.toString()}}class Dr{constructor(e,n){this.ADJUST_ROW_NUMBER_SKIP=2,this.barcodeMetadata=e,this.barcodeColumnCount=e.getColumnCount(),this.boundingBox=n,this.detectionResultColumns=new Array(this.barcodeColumnCount+2)}getDetectionResultColumns(){this.adjustIndicatorColumnRowNumbers(this.detectionResultColumns[0]),this.adjustIndicatorColumnRowNumbers(this.detectionResultColumns[this.barcodeColumnCount+1]);let e=Re.MAX_CODEWORDS_IN_BARCODE,n;do n=e,e=this.adjustRowNumbersAndGetCount();while(e>0&&e<n);return this.detectionResultColumns}adjustIndicatorColumnRowNumbers(e){e?.adjustCompleteIndicatorColumnRowNumbers(this.barcodeMetadata)}adjustRowNumbersAndGetCount(){let e=this.adjustRowNumbersByRow();if(e===0)return 0;for(let n=1;n<this.barcodeColumnCount+1;n++){let i=this.detectionResultColumns[n].getCodewords();for(let s=0;s<i.length;s++)i[s]!=null&&(i[s].hasValidRowNumber()||this.adjustRowNumbers(n,s,i))}return e}adjustRowNumbersByRow(){return this.adjustRowNumbersFromBothRI(),this.adjustRowNumbersFromLRI()+this.adjustRowNumbersFromRRI()}adjustRowNumbersFromBothRI(){if(this.detectionResultColumns[0]==null||this.detectionResultColumns[this.barcodeColumnCount+1]==null)return;let e=this.detectionResultColumns[0].getCodewords(),n=this.detectionResultColumns[this.barcodeColumnCount+1].getCodewords();for(let i=0;i<e.length;i++)if(e[i]!=null&&n[i]!=null&&e[i].getRowNumber()===n[i].getRowNumber())for(let s=1;s<=this.barcodeColumnCount;s++){let a=this.detectionResultColumns[s].getCodewords()[i];a!=null&&(a.setRowNumber(e[i].getRowNumber()),a.hasValidRowNumber()||(this.detectionResultColumns[s].getCodewords()[i]=null))}}adjustRowNumbersFromRRI(){if(this.detectionResultColumns[this.barcodeColumnCount+1]==null)return 0;let e=0,n=this.detectionResultColumns[this.barcodeColumnCount+1].getCodewords();for(let i=0;i<n.length;i++){if(n[i]==null)continue;let s=n[i].getRowNumber(),a=0;for(let l=this.barcodeColumnCount+1;l>0&&a<this.ADJUST_ROW_NUMBER_SKIP;l--){let d=this.detectionResultColumns[l].getCodewords()[i];d!=null&&(a=Dr.adjustRowNumberIfValid(s,a,d),d.hasValidRowNumber()||e++)}}return e}adjustRowNumbersFromLRI(){if(this.detectionResultColumns[0]==null)return 0;let e=0,n=this.detectionResultColumns[0].getCodewords();for(let i=0;i<n.length;i++){if(n[i]==null)continue;let s=n[i].getRowNumber(),a=0;for(let l=1;l<this.barcodeColumnCount+1&&a<this.ADJUST_ROW_NUMBER_SKIP;l++){let d=this.detectionResultColumns[l].getCodewords()[i];d!=null&&(a=Dr.adjustRowNumberIfValid(s,a,d),d.hasValidRowNumber()||e++)}}return e}static adjustRowNumberIfValid(e,n,i){return i==null||i.hasValidRowNumber()||(i.isValidRowNumber(e)?(i.setRowNumber(e),n=0):++n),n}adjustRowNumbers(e,n,i){if(!this.detectionResultColumns[e-1])return;let s=i[n],a=this.detectionResultColumns[e-1].getCodewords(),l=a;this.detectionResultColumns[e+1]!=null&&(l=this.detectionResultColumns[e+1].getCodewords());let d=new Array(14);d[2]=a[n],d[3]=l[n],n>0&&(d[0]=i[n-1],d[4]=a[n-1],d[5]=l[n-1]),n>1&&(d[8]=i[n-2],d[10]=a[n-2],d[11]=l[n-2]),n<i.length-1&&(d[1]=i[n+1],d[6]=a[n+1],d[7]=l[n+1]),n<i.length-2&&(d[9]=i[n+2],d[12]=a[n+2],d[13]=l[n+2]);for(let h of d)if(Dr.adjustRowNumber(s,h))return}static adjustRowNumber(e,n){return n==null?!1:n.hasValidRowNumber()&&n.getBucket()===e.getBucket()?(e.setRowNumber(n.getRowNumber()),!0):!1}getBarcodeColumnCount(){return this.barcodeColumnCount}getBarcodeRowCount(){return this.barcodeMetadata.getRowCount()}getBarcodeECLevel(){return this.barcodeMetadata.getErrorCorrectionLevel()}setBoundingBox(e){this.boundingBox=e}getBoundingBox(){return this.boundingBox}setDetectionResultColumn(e,n){this.detectionResultColumns[e]=n}getDetectionResultColumn(e){return this.detectionResultColumns[e]}toString(){let e=this.detectionResultColumns[0];e==null&&(e=this.detectionResultColumns[this.barcodeColumnCount+1]);let n=new kr;for(let i=0;i<e.getCodewords().length;i++){n.format("CW %3d:",i);for(let s=0;s<this.barcodeColumnCount+2;s++){if(this.detectionResultColumns[s]==null){n.format(" | ");continue}let a=this.detectionResultColumns[s].getCodewords()[i];if(a==null){n.format(" | ");continue}n.format(" %3d|%3d",a.getRowNumber(),a.getValue())}n.format("%n")}return n.toString()}}class Pr{constructor(e,n,i,s){this.rowNumber=Pr.BARCODE_ROW_UNKNOWN,this.startX=Math.trunc(e),this.endX=Math.trunc(n),this.bucket=Math.trunc(i),this.value=Math.trunc(s)}hasValidRowNumber(){return this.isValidRowNumber(this.rowNumber)}isValidRowNumber(e){return e!==Pr.BARCODE_ROW_UNKNOWN&&this.bucket===e%3*3}setRowNumberAsRowIndicatorColumn(){this.rowNumber=Math.trunc(Math.trunc(this.value/30)*3+Math.trunc(this.bucket/3))}getWidth(){return this.endX-this.startX}getStartX(){return this.startX}getEndX(){return this.endX}getBucket(){return this.bucket}getValue(){return this.value}getRowNumber(){return this.rowNumber}setRowNumber(e){this.rowNumber=e}toString(){return this.rowNumber+"|"+this.value}}Pr.BARCODE_ROW_UNKNOWN=-1;class Yt{static initialize(){for(let e=0;e<Re.SYMBOL_TABLE.length;e++){let n=Re.SYMBOL_TABLE[e],i=n&1;for(let s=0;s<Re.BARS_IN_MODULE;s++){let a=0;for(;(n&1)===i;)a+=1,n>>=1;i=n&1,Yt.RATIOS_TABLE[e]||(Yt.RATIOS_TABLE[e]=new Array(Re.BARS_IN_MODULE)),Yt.RATIOS_TABLE[e][Re.BARS_IN_MODULE-s-1]=Math.fround(a/Re.MODULES_IN_CODEWORD)}}this.bSymbolTableReady=!0}static getDecodedValue(e){let n=Yt.getDecodedCodewordValue(Yt.sampleBitCounts(e));return n!==-1?n:Yt.getClosestDecodedValue(e)}static sampleBitCounts(e){let n=Te.sum(e),i=new Int32Array(Re.BARS_IN_MODULE),s=0,a=0;for(let l=0;l<Re.MODULES_IN_CODEWORD;l++){let d=n/(2*Re.MODULES_IN_CODEWORD)+l*n/Re.MODULES_IN_CODEWORD;a+e[s]<=d&&(a+=e[s],s++),i[s]++}return i}static getDecodedCodewordValue(e){let n=Yt.getBitValue(e);return Re.getCodeword(n)===-1?-1:n}static getBitValue(e){let n=0;for(let i=0;i<e.length;i++)for(let s=0;s<e[i];s++)n=n<<1|(i%2===0?1:0);return Math.trunc(n)}static getClosestDecodedValue(e){let n=Te.sum(e),i=new Array(Re.BARS_IN_MODULE);if(n>1)for(let l=0;l<i.length;l++)i[l]=Math.fround(e[l]/n);let s=It.MAX_VALUE,a=-1;this.bSymbolTableReady||Yt.initialize();for(let l=0;l<Yt.RATIOS_TABLE.length;l++){let d=0,h=Yt.RATIOS_TABLE[l];for(let g=0;g<Re.BARS_IN_MODULE;g++){let w=Math.fround(h[g]-i[g]);if(d+=Math.fround(w*w),d>=s)break}d<s&&(s=d,a=Re.SYMBOL_TABLE[l])}return a}}Yt.bSymbolTableReady=!1,Yt.RATIOS_TABLE=new Array(Re.SYMBOL_TABLE.length).map(C=>new Array(Re.BARS_IN_MODULE));class hs{constructor(){this.segmentCount=-1,this.fileSize=-1,this.timestamp=-1,this.checksum=-1}getSegmentIndex(){return this.segmentIndex}setSegmentIndex(e){this.segmentIndex=e}getFileId(){return this.fileId}setFileId(e){this.fileId=e}getOptionalData(){return this.optionalData}setOptionalData(e){this.optionalData=e}isLastSegment(){return this.lastSegment}setLastSegment(e){this.lastSegment=e}getSegmentCount(){return this.segmentCount}setSegmentCount(e){this.segmentCount=e}getSender(){return this.sender||null}setSender(e){this.sender=e}getAddressee(){return this.addressee||null}setAddressee(e){this.addressee=e}getFileName(){return this.fileName}setFileName(e){this.fileName=e}getFileSize(){return this.fileSize}setFileSize(e){this.fileSize=e}getChecksum(){return this.checksum}setChecksum(e){this.checksum=e}getTimestamp(){return this.timestamp}setTimestamp(e){this.timestamp=e}}class ps{static parseLong(e,n=void 0){return parseInt(e,n)}}class gs extends m{}gs.kind="NullPointerException";class od{writeBytes(e){this.writeBytesOffset(e,0,e.length)}writeBytesOffset(e,n,i){if(e==null)throw new gs;if(n<0||n>e.length||i<0||n+i>e.length||n+i<0)throw new k;if(i===0)return;for(let s=0;s<i;s++)this.write(e[n+s])}flush(){}close(){}}class sd extends m{}class ad extends od{constructor(e=32){if(super(),this.count=0,e<0)throw new E("Negative initial size: "+e);this.buf=new Uint8Array(e)}ensureCapacity(e){e-this.buf.length>0&&this.grow(e)}grow(e){let i=this.buf.length<<1;if(i-e<0&&(i=e),i<0){if(e<0)throw new sd;i=z.MAX_VALUE}this.buf=Z.copyOfUint8Array(this.buf,i)}write(e){this.ensureCapacity(this.count+1),this.buf[this.count]=e,this.count+=1}writeBytesOffset(e,n,i){if(n<0||n>e.length||i<0||n+i-e.length>0)throw new k;this.ensureCapacity(this.count+i),R.arraycopy(e,n,this.buf,this.count,i),this.count+=i}writeTo(e){e.writeBytesOffset(this.buf,0,this.count)}reset(){this.count=0}toByteArray(){return Z.copyOfUint8Array(this.buf,this.count)}size(){return this.count}toString(e){return e?typeof e=="string"?this.toString_string(e):this.toString_number(e):this.toString_void()}toString_void(){return new String(this.buf).toString()}toString_string(e){return new String(this.buf).toString()}toString_number(e){return new String(this.buf).toString()}close(){}}var nt;(function(C){C[C.ALPHA=0]="ALPHA",C[C.LOWER=1]="LOWER",C[C.MIXED=2]="MIXED",C[C.PUNCT=3]="PUNCT",C[C.ALPHA_SHIFT=4]="ALPHA_SHIFT",C[C.PUNCT_SHIFT=5]="PUNCT_SHIFT"})(nt||(nt={}));function ms(){if(typeof window<"u")return window.BigInt||null;if(typeof Ci<"u")return Ci.BigInt||null;if(typeof self<"u")return self.BigInt||null;throw new Error("Can't search globals for BigInt!")}let hi;function Vn(C){if(typeof hi>"u"&&(hi=ms()),hi===null)throw new Error("BigInt is not supported!");return hi(C)}function ld(){let C=[];C[0]=Vn(1);let e=Vn(900);C[1]=e;for(let n=2;n<16;n++)C[n]=C[n-1]*e;return C}class J{static decode(e,n){let i=new oe(""),s=j.ISO8859_1;i.enableDecoding(s);let a=1,l=e[a++],d=new hs;for(;a<e[0];){switch(l){case J.TEXT_COMPACTION_MODE_LATCH:a=J.textCompaction(e,a,i);break;case J.BYTE_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:a=J.byteCompaction(l,e,s,a,i);break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:i.append(e[a++]);break;case J.NUMERIC_COMPACTION_MODE_LATCH:a=J.numericCompaction(e,a,i);break;case J.ECI_CHARSET:j.getCharacterSetECIByValue(e[a++]);break;case J.ECI_GENERAL_PURPOSE:a+=2;break;case J.ECI_USER_DEFINED:a++;break;case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:a=J.decodeMacroBlock(e,a,d);break;case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:throw new V;default:a--,a=J.textCompaction(e,a,i);break}if(a<e.length)l=e[a++];else throw V.getFormatInstance()}if(i.length()===0)throw V.getFormatInstance();let h=new Nt(null,i.toString(),null,n);return h.setOther(d),h}static decodeMacroBlock(e,n,i){if(n+J.NUMBER_OF_SEQUENCE_CODEWORDS>e[0])throw V.getFormatInstance();let s=new Int32Array(J.NUMBER_OF_SEQUENCE_CODEWORDS);for(let d=0;d<J.NUMBER_OF_SEQUENCE_CODEWORDS;d++,n++)s[d]=e[n];i.setSegmentIndex(z.parseInt(J.decodeBase900toBase10(s,J.NUMBER_OF_SEQUENCE_CODEWORDS)));let a=new oe;n=J.textCompaction(e,n,a),i.setFileId(a.toString());let l=-1;for(e[n]===J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD&&(l=n+1);n<e[0];)switch(e[n]){case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:switch(n++,e[n]){case J.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME:let d=new oe;n=J.textCompaction(e,n+1,d),i.setFileName(d.toString());break;case J.MACRO_PDF417_OPTIONAL_FIELD_SENDER:let h=new oe;n=J.textCompaction(e,n+1,h),i.setSender(h.toString());break;case J.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE:let g=new oe;n=J.textCompaction(e,n+1,g),i.setAddressee(g.toString());break;case J.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT:let w=new oe;n=J.numericCompaction(e,n+1,w),i.setSegmentCount(z.parseInt(w.toString()));break;case J.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP:let b=new oe;n=J.numericCompaction(e,n+1,b),i.setTimestamp(ps.parseLong(b.toString()));break;case J.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM:let I=new oe;n=J.numericCompaction(e,n+1,I),i.setChecksum(z.parseInt(I.toString()));break;case J.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE:let N=new oe;n=J.numericCompaction(e,n+1,N),i.setFileSize(ps.parseLong(N.toString()));break;default:throw V.getFormatInstance()}break;case J.MACRO_PDF417_TERMINATOR:n++,i.setLastSegment(!0);break;default:throw V.getFormatInstance()}if(l!==-1){let d=n-l;i.isLastSegment()&&d--,i.setOptionalData(Z.copyOfRange(e,l,l+d))}return n}static textCompaction(e,n,i){let s=new Int32Array((e[0]-n)*2),a=new Int32Array((e[0]-n)*2),l=0,d=!1;for(;n<e[0]&&!d;){let h=e[n++];if(h<J.TEXT_COMPACTION_MODE_LATCH)s[l]=h/30,s[l+1]=h%30,l+=2;else switch(h){case J.TEXT_COMPACTION_MODE_LATCH:s[l++]=J.TEXT_COMPACTION_MODE_LATCH;break;case J.BYTE_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.NUMERIC_COMPACTION_MODE_LATCH:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:n--,d=!0;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:s[l]=J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE,h=e[n++],a[l]=h,l++;break}}return J.decodeTextCompaction(s,a,l,i),n}static decodeTextCompaction(e,n,i,s){let a=nt.ALPHA,l=nt.ALPHA,d=0;for(;d<i;){let h=e[d],g="";switch(a){case nt.ALPHA:if(h<26)g=String.fromCharCode(65+h);else switch(h){case 26:g=" ";break;case J.LL:a=nt.LOWER;break;case J.ML:a=nt.MIXED;break;case J.PS:l=a,a=nt.PUNCT_SHIFT;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:s.append(n[d]);break;case J.TEXT_COMPACTION_MODE_LATCH:a=nt.ALPHA;break}break;case nt.LOWER:if(h<26)g=String.fromCharCode(97+h);else switch(h){case 26:g=" ";break;case J.AS:l=a,a=nt.ALPHA_SHIFT;break;case J.ML:a=nt.MIXED;break;case J.PS:l=a,a=nt.PUNCT_SHIFT;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:s.append(n[d]);break;case J.TEXT_COMPACTION_MODE_LATCH:a=nt.ALPHA;break}break;case nt.MIXED:if(h<J.PL)g=J.MIXED_CHARS[h];else switch(h){case J.PL:a=nt.PUNCT;break;case 26:g=" ";break;case J.LL:a=nt.LOWER;break;case J.AL:a=nt.ALPHA;break;case J.PS:l=a,a=nt.PUNCT_SHIFT;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:s.append(n[d]);break;case J.TEXT_COMPACTION_MODE_LATCH:a=nt.ALPHA;break}break;case nt.PUNCT:if(h<J.PAL)g=J.PUNCT_CHARS[h];else switch(h){case J.PAL:a=nt.ALPHA;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:s.append(n[d]);break;case J.TEXT_COMPACTION_MODE_LATCH:a=nt.ALPHA;break}break;case nt.ALPHA_SHIFT:if(a=l,h<26)g=String.fromCharCode(65+h);else switch(h){case 26:g=" ";break;case J.TEXT_COMPACTION_MODE_LATCH:a=nt.ALPHA;break}break;case nt.PUNCT_SHIFT:if(a=l,h<J.PAL)g=J.PUNCT_CHARS[h];else switch(h){case J.PAL:a=nt.ALPHA;break;case J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:s.append(n[d]);break;case J.TEXT_COMPACTION_MODE_LATCH:a=nt.ALPHA;break}break}g!==""&&s.append(g),d++}}static byteCompaction(e,n,i,s,a){let l=new ad,d=0,h=0,g=!1;switch(e){case J.BYTE_COMPACTION_MODE_LATCH:let w=new Int32Array(6),b=n[s++];for(;s<n[0]&&!g;)switch(w[d++]=b,h=900*h+b,b=n[s++],b){case J.TEXT_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH:case J.NUMERIC_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:s--,g=!0;break;default:if(d%5===0&&d>0){for(let I=0;I<6;++I)l.write(Number(Vn(h)>>Vn(8*(5-I))));h=0,d=0}break}s===n[0]&&b<J.TEXT_COMPACTION_MODE_LATCH&&(w[d++]=b);for(let I=0;I<d;I++)l.write(w[I]);break;case J.BYTE_COMPACTION_MODE_LATCH_6:for(;s<n[0]&&!g;){let I=n[s++];if(I<J.TEXT_COMPACTION_MODE_LATCH)d++,h=900*h+I;else switch(I){case J.TEXT_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH:case J.NUMERIC_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:s--,g=!0;break}if(d%5===0&&d>0){for(let N=0;N<6;++N)l.write(Number(Vn(h)>>Vn(8*(5-N))));h=0,d=0}}break}return a.append(de.decode(l.toByteArray(),i)),s}static numericCompaction(e,n,i){let s=0,a=!1,l=new Int32Array(J.MAX_NUMERIC_CODEWORDS);for(;n<e[0]&&!a;){let d=e[n++];if(n===e[0]&&(a=!0),d<J.TEXT_COMPACTION_MODE_LATCH)l[s]=d,s++;else switch(d){case J.TEXT_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH:case J.BYTE_COMPACTION_MODE_LATCH_6:case J.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case J.MACRO_PDF417_TERMINATOR:n--,a=!0;break}(s%J.MAX_NUMERIC_CODEWORDS===0||d===J.NUMERIC_COMPACTION_MODE_LATCH||a)&&s>0&&(i.append(J.decodeBase900toBase10(l,s)),s=0)}return n}static decodeBase900toBase10(e,n){let i=Vn(0);for(let a=0;a<n;a++)i+=J.EXP900[n-a-1]*Vn(e[a]);let s=i.toString();if(s.charAt(0)!=="1")throw new V;return s.substring(1)}}J.TEXT_COMPACTION_MODE_LATCH=900,J.BYTE_COMPACTION_MODE_LATCH=901,J.NUMERIC_COMPACTION_MODE_LATCH=902,J.BYTE_COMPACTION_MODE_LATCH_6=924,J.ECI_USER_DEFINED=925,J.ECI_GENERAL_PURPOSE=926,J.ECI_CHARSET=927,J.BEGIN_MACRO_PDF417_CONTROL_BLOCK=928,J.BEGIN_MACRO_PDF417_OPTIONAL_FIELD=923,J.MACRO_PDF417_TERMINATOR=922,J.MODE_SHIFT_TO_BYTE_COMPACTION_MODE=913,J.MAX_NUMERIC_CODEWORDS=15,J.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME=0,J.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT=1,J.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP=2,J.MACRO_PDF417_OPTIONAL_FIELD_SENDER=3,J.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE=4,J.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE=5,J.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM=6,J.PL=25,J.LL=27,J.AS=27,J.ML=28,J.AL=28,J.PS=29,J.PAL=29,J.PUNCT_CHARS=`;<>@[\\]_\`~!\r ,:
64
- -.$/"|*()?{}'`,J.MIXED_CHARS="0123456789&\r ,:#-.$/+%*=^",J.EXP900=ms()?ld():[],J.NUMBER_OF_SEQUENCE_CODEWORDS=2;class ze{constructor(){}static decode(e,n,i,s,a,l,d){let h=new Qn(e,n,i,s,a),g=null,w=null,b;for(let F=!0;;F=!1){if(n!=null&&(g=ze.getRowIndicatorColumn(e,h,n,!0,l,d)),s!=null&&(w=ze.getRowIndicatorColumn(e,h,s,!1,l,d)),b=ze.merge(g,w),b==null)throw P.getNotFoundInstance();let U=b.getBoundingBox();if(F&&U!=null&&(U.getMinY()<h.getMinY()||U.getMaxY()>h.getMaxY()))h=U;else break}b.setBoundingBox(h);let I=b.getBarcodeColumnCount()+1;b.setDetectionResultColumn(0,g),b.setDetectionResultColumn(I,w);let N=g!=null;for(let F=1;F<=I;F++){let U=N?F:I-F;if(b.getDetectionResultColumn(U)!==void 0)continue;let W;U===0||U===I?W=new fs(h,U===0):W=new Rr(h),b.setDetectionResultColumn(U,W);let K=-1,fe=K;for(let he=h.getMinY();he<=h.getMaxY();he++){if(K=ze.getStartColumn(b,U,he,N),K<0||K>h.getMaxX()){if(fe===-1)continue;K=fe}let ce=ze.detectCodeword(e,h.getMinX(),h.getMaxX(),N,K,he,l,d);ce!=null&&(W.setCodeword(he,ce),fe=K,l=Math.min(l,ce.getWidth()),d=Math.max(d,ce.getWidth()))}}return ze.createDecoderResult(b)}static merge(e,n){if(e==null&&n==null)return null;let i=ze.getBarcodeMetadata(e,n);if(i==null)return null;let s=Qn.merge(ze.adjustBoundingBox(e),ze.adjustBoundingBox(n));return new Dr(i,s)}static adjustBoundingBox(e){if(e==null)return null;let n=e.getRowHeights();if(n==null)return null;let i=ze.getMax(n),s=0;for(let d of n)if(s+=i-d,d>0)break;let a=e.getCodewords();for(let d=0;s>0&&a[d]==null;d++)s--;let l=0;for(let d=n.length-1;d>=0&&(l+=i-n[d],!(n[d]>0));d--);for(let d=a.length-1;l>0&&a[d]==null;d--)l--;return e.getBoundingBox().addMissingRows(s,l,e.isLeft())}static getMax(e){let n=-1;for(let i of e)n=Math.max(n,i);return n}static getBarcodeMetadata(e,n){let i;if(e==null||(i=e.getBarcodeMetadata())==null)return n==null?null:n.getBarcodeMetadata();let s;return n==null||(s=n.getBarcodeMetadata())==null?i:i.getColumnCount()!==s.getColumnCount()&&i.getErrorCorrectionLevel()!==s.getErrorCorrectionLevel()&&i.getRowCount()!==s.getRowCount()?null:i}static getRowIndicatorColumn(e,n,i,s,a,l){let d=new fs(n,s);for(let h=0;h<2;h++){let g=h===0?1:-1,w=Math.trunc(Math.trunc(i.getX()));for(let b=Math.trunc(Math.trunc(i.getY()));b<=n.getMaxY()&&b>=n.getMinY();b+=g){let I=ze.detectCodeword(e,0,e.getWidth(),s,w,b,a,l);I!=null&&(d.setCodeword(b,I),s?w=I.getStartX():w=I.getEndX())}}return d}static adjustCodewordCount(e,n){let i=n[0][1],s=i.getValue(),a=e.getBarcodeColumnCount()*e.getBarcodeRowCount()-ze.getNumberOfECCodeWords(e.getBarcodeECLevel());if(s.length===0){if(a<1||a>Re.MAX_CODEWORDS_IN_BARCODE)throw P.getNotFoundInstance();i.setValue(a)}else s[0]!==a&&i.setValue(a)}static createDecoderResult(e){let n=ze.createBarcodeMatrix(e);ze.adjustCodewordCount(e,n);let i=new Array,s=new Int32Array(e.getBarcodeRowCount()*e.getBarcodeColumnCount()),a=[],l=new Array;for(let h=0;h<e.getBarcodeRowCount();h++)for(let g=0;g<e.getBarcodeColumnCount();g++){let w=n[h][g+1].getValue(),b=h*e.getBarcodeColumnCount()+g;w.length===0?i.push(b):w.length===1?s[b]=w[0]:(l.push(b),a.push(w))}let d=new Array(a.length);for(let h=0;h<d.length;h++)d[h]=a[h];return ze.createDecoderResultFromAmbiguousValues(e.getBarcodeECLevel(),s,Re.toIntArray(i),Re.toIntArray(l),d)}static createDecoderResultFromAmbiguousValues(e,n,i,s,a){let l=new Int32Array(s.length),d=100;for(;d-- >0;){for(let h=0;h<l.length;h++)n[s[h]]=a[h][l[h]];try{return ze.decodeCodewords(n,e,i)}catch(h){if(!(h instanceof D))throw h}if(l.length===0)throw D.getChecksumInstance();for(let h=0;h<l.length;h++)if(l[h]<a[h].length-1){l[h]++;break}else if(l[h]=0,h===l.length-1)throw D.getChecksumInstance()}throw D.getChecksumInstance()}static createBarcodeMatrix(e){let n=Array.from({length:e.getBarcodeRowCount()},()=>new Array(e.getBarcodeColumnCount()+2));for(let s=0;s<n.length;s++)for(let a=0;a<n[s].length;a++)n[s][a]=new Mr;let i=0;for(let s of e.getDetectionResultColumns()){if(s!=null){for(let a of s.getCodewords())if(a!=null){let l=a.getRowNumber();if(l>=0){if(l>=n.length)continue;n[l][i].setValue(a.getValue())}}}i++}return n}static isValidBarcodeColumn(e,n){return n>=0&&n<=e.getBarcodeColumnCount()+1}static getStartColumn(e,n,i,s){let a=s?1:-1,l=null;if(ze.isValidBarcodeColumn(e,n-a)&&(l=e.getDetectionResultColumn(n-a).getCodeword(i)),l!=null)return s?l.getEndX():l.getStartX();if(l=e.getDetectionResultColumn(n).getCodewordNearby(i),l!=null)return s?l.getStartX():l.getEndX();if(ze.isValidBarcodeColumn(e,n-a)&&(l=e.getDetectionResultColumn(n-a).getCodewordNearby(i)),l!=null)return s?l.getEndX():l.getStartX();let d=0;for(;ze.isValidBarcodeColumn(e,n-a);){n-=a;for(let h of e.getDetectionResultColumn(n).getCodewords())if(h!=null)return(s?h.getEndX():h.getStartX())+a*d*(h.getEndX()-h.getStartX());d++}return s?e.getBoundingBox().getMinX():e.getBoundingBox().getMaxX()}static detectCodeword(e,n,i,s,a,l,d,h){a=ze.adjustCodewordStartColumn(e,n,i,s,a,l);let g=ze.getModuleBitCount(e,n,i,s,a,l);if(g==null)return null;let w,b=Te.sum(g);if(s)w=a+b;else{for(let F=0;F<g.length/2;F++){let U=g[F];g[F]=g[g.length-1-F],g[g.length-1-F]=U}w=a,a=w-b}if(!ze.checkCodewordSkew(b,d,h))return null;let I=Yt.getDecodedValue(g),N=Re.getCodeword(I);return N===-1?null:new Pr(a,w,ze.getCodewordBucketNumber(I),N)}static getModuleBitCount(e,n,i,s,a,l){let d=a,h=new Int32Array(8),g=0,w=s?1:-1,b=s;for(;(s?d<i:d>=n)&&g<h.length;)e.get(d,l)===b?(h[g]++,d+=w):(g++,b=!b);return g===h.length||d===(s?i:n)&&g===h.length-1?h:null}static getNumberOfECCodeWords(e){return 2<<e}static adjustCodewordStartColumn(e,n,i,s,a,l){let d=a,h=s?-1:1;for(let g=0;g<2;g++){for(;(s?d>=n:d<i)&&s===e.get(d,l);){if(Math.abs(a-d)>ze.CODEWORD_SKEW_SIZE)return a;d+=h}h=-h,s=!s}return d}static checkCodewordSkew(e,n,i){return n-ze.CODEWORD_SKEW_SIZE<=e&&e<=i+ze.CODEWORD_SKEW_SIZE}static decodeCodewords(e,n,i){if(e.length===0)throw V.getFormatInstance();let s=1<<n+1,a=ze.correctErrors(e,i,s);ze.verifyCodewordCount(e,s);let l=J.decode(e,""+n);return l.setErrorsCorrected(a),l.setErasures(i.length),l}static correctErrors(e,n,i){if(n!=null&&n.length>i/2+ze.MAX_ERRORS||i<0||i>ze.MAX_EC_CODEWORDS)throw D.getChecksumInstance();return ze.errorCorrection.decode(e,i,n)}static verifyCodewordCount(e,n){if(e.length<4)throw V.getFormatInstance();let i=e[0];if(i>e.length)throw V.getFormatInstance();if(i===0)if(n<e.length)e[0]=e.length-n;else throw V.getFormatInstance()}static getBitCountForCodeword(e){let n=new Int32Array(8),i=0,s=n.length-1;for(;!((e&1)!==i&&(i=e&1,s--,s<0));)n[s]++,e>>=1;return n}static getCodewordBucketNumber(e){return e instanceof Int32Array?this.getCodewordBucketNumber_Int32Array(e):this.getCodewordBucketNumber_number(e)}static getCodewordBucketNumber_number(e){return ze.getCodewordBucketNumber(ze.getBitCountForCodeword(e))}static getCodewordBucketNumber_Int32Array(e){return(e[0]-e[2]+e[4]-e[6]+9)%9}static toString(e){let n=new kr;for(let i=0;i<e.length;i++){n.format("Row %2d: ",i);for(let s=0;s<e[i].length;s++){let a=e[i][s];a.getValue().length===0?n.format(" ",null):n.format("%4d(%2d)",a.getValue()[0],a.getConfidence(a.getValue()[0]))}n.format("%n")}return n.toString()}}ze.CODEWORD_SKEW_SIZE=2,ze.MAX_ERRORS=3,ze.MAX_EC_CODEWORDS=512,ze.errorCorrection=new ds;class Ut{decode(e,n=null){let i=Ut.decode(e,n,!1);if(i==null||i.length===0||i[0]==null)throw P.getNotFoundInstance();return i[0]}decodeMultiple(e,n=null){try{return Ut.decode(e,n,!0)}catch(i){throw i instanceof V||i instanceof D?P.getNotFoundInstance():i}}static decode(e,n,i){const s=new Array,a=Fe.detectMultiple(e,n,i);for(const l of a.getPoints()){const d=ze.decode(a.getBits(),l[4],l[5],l[6],l[7],Ut.getMinCodewordWidth(l),Ut.getMaxCodewordWidth(l)),h=new Ue(d.getText(),d.getRawBytes(),void 0,l,ge.PDF_417);h.putMetadata(Se.ERROR_CORRECTION_LEVEL,d.getECLevel());const g=d.getOther();g!=null&&h.putMetadata(Se.PDF417_EXTRA_METADATA,g),s.push(h)}return s.map(l=>l)}static getMaxWidth(e,n){return e==null||n==null?0:Math.trunc(Math.abs(e.getX()-n.getX()))}static getMinWidth(e,n){return e==null||n==null?z.MAX_VALUE:Math.trunc(Math.abs(e.getX()-n.getX()))}static getMaxCodewordWidth(e){return Math.floor(Math.max(Math.max(Ut.getMaxWidth(e[0],e[4]),Ut.getMaxWidth(e[6],e[2])*Re.MODULES_IN_CODEWORD/Re.MODULES_IN_STOP_PATTERN),Math.max(Ut.getMaxWidth(e[1],e[5]),Ut.getMaxWidth(e[7],e[3])*Re.MODULES_IN_CODEWORD/Re.MODULES_IN_STOP_PATTERN)))}static getMinCodewordWidth(e){return Math.floor(Math.min(Math.min(Ut.getMinWidth(e[0],e[4]),Ut.getMinWidth(e[6],e[2])*Re.MODULES_IN_CODEWORD/Re.MODULES_IN_STOP_PATTERN),Math.min(Ut.getMinWidth(e[1],e[5]),Ut.getMinWidth(e[7],e[3])*Re.MODULES_IN_CODEWORD/Re.MODULES_IN_STOP_PATTERN)))}reset(){}}class pi extends m{}pi.kind="ReaderException";class xs{constructor(e,n){this.verbose=e===!0,n&&this.setHints(n)}decode(e,n){return n&&this.setHints(n),this.decodeInternal(e)}decodeWithState(e){return(this.readers===null||this.readers===void 0)&&this.setHints(null),this.decodeInternal(e)}setHints(e){this.hints=e;const n=!c(e)&&e.get(O.TRY_HARDER)===!0,i=c(e)?null:e.get(O.POSSIBLE_FORMATS),s=new Array;if(!c(i)){const a=i.some(l=>l===ge.UPC_A||l===ge.UPC_E||l===ge.EAN_13||l===ge.EAN_8||l===ge.CODABAR||l===ge.CODE_39||l===ge.CODE_93||l===ge.CODE_128||l===ge.ITF||l===ge.RSS_14||l===ge.RSS_EXPANDED);a&&!n&&s.push(new mr(e,this.verbose)),i.includes(ge.QR_CODE)&&s.push(new zn),i.includes(ge.DATA_MATRIX)&&s.push(new Un),i.includes(ge.AZTEC)&&s.push(new at),i.includes(ge.PDF_417)&&s.push(new Ut),a&&n&&s.push(new mr(e,this.verbose))}s.length===0&&(n||s.push(new mr(e,this.verbose)),s.push(new zn),s.push(new Un),s.push(new at),s.push(new Ut),n&&s.push(new mr(e,this.verbose))),this.readers=s}reset(){if(this.readers!==null)for(const e of this.readers)e.reset()}decodeInternal(e){if(this.readers===null)throw new pi("No readers where selected, nothing can be read.");for(const n of this.readers)try{return n.decode(e,this.hints)}catch(i){if(i instanceof pi)continue}throw new P("No MultiFormat Readers were able to detect the code.")}}class cd extends Ze{constructor(e=null,n=500){const i=new xs;i.setHints(e),super(i,n)}decodeBitmap(e){return this.reader.decodeWithState(e)}}class ud extends Ze{constructor(e=500){super(new Ut,e)}}class dd extends Ze{constructor(e=500){super(new zn,e)}}var ro;(function(C){C[C.ERROR_CORRECTION=0]="ERROR_CORRECTION",C[C.CHARACTER_SET=1]="CHARACTER_SET",C[C.DATA_MATRIX_SHAPE=2]="DATA_MATRIX_SHAPE",C[C.MIN_SIZE=3]="MIN_SIZE",C[C.MAX_SIZE=4]="MAX_SIZE",C[C.MARGIN=5]="MARGIN",C[C.PDF417_COMPACT=6]="PDF417_COMPACT",C[C.PDF417_COMPACTION=7]="PDF417_COMPACTION",C[C.PDF417_DIMENSIONS=8]="PDF417_DIMENSIONS",C[C.AZTEC_LAYERS=9]="AZTEC_LAYERS",C[C.QR_VERSION=10]="QR_VERSION"})(ro||(ro={}));var kt=ro;class io{constructor(e){this.field=e,this.cachedGenerators=[],this.cachedGenerators.push(new et(e,Int32Array.from([1])))}buildGenerator(e){const n=this.cachedGenerators;if(e>=n.length){let i=n[n.length-1];const s=this.field;for(let a=n.length;a<=e;a++){const l=i.multiply(new et(s,Int32Array.from([1,s.exp(a-1+s.getGeneratorBase())])));n.push(l),i=l}}return n[e]}encode(e,n){if(n===0)throw new E("No error correction bytes");const i=e.length-n;if(i<=0)throw new E("No data bytes provided");const s=this.buildGenerator(n),a=new Int32Array(i);R.arraycopy(e,0,a,0,i);let l=new et(this.field,a);l=l.multiplyByMonomial(n,1);const h=l.divide(s)[1].getCoefficients(),g=n-h.length;for(let w=0;w<g;w++)e[i+w]=0;R.arraycopy(h,0,e,i+g,h.length)}}class Ct{constructor(){}static applyMaskPenaltyRule1(e){return Ct.applyMaskPenaltyRule1Internal(e,!0)+Ct.applyMaskPenaltyRule1Internal(e,!1)}static applyMaskPenaltyRule2(e){let n=0;const i=e.getArray(),s=e.getWidth(),a=e.getHeight();for(let l=0;l<a-1;l++){const d=i[l];for(let h=0;h<s-1;h++){const g=d[h];g===d[h+1]&&g===i[l+1][h]&&g===i[l+1][h+1]&&n++}}return Ct.N2*n}static applyMaskPenaltyRule3(e){let n=0;const i=e.getArray(),s=e.getWidth(),a=e.getHeight();for(let l=0;l<a;l++)for(let d=0;d<s;d++){const h=i[l];d+6<s&&h[d]===1&&h[d+1]===0&&h[d+2]===1&&h[d+3]===1&&h[d+4]===1&&h[d+5]===0&&h[d+6]===1&&(Ct.isWhiteHorizontal(h,d-4,d)||Ct.isWhiteHorizontal(h,d+7,d+11))&&n++,l+6<a&&i[l][d]===1&&i[l+1][d]===0&&i[l+2][d]===1&&i[l+3][d]===1&&i[l+4][d]===1&&i[l+5][d]===0&&i[l+6][d]===1&&(Ct.isWhiteVertical(i,d,l-4,l)||Ct.isWhiteVertical(i,d,l+7,l+11))&&n++}return n*Ct.N3}static isWhiteHorizontal(e,n,i){n=Math.max(n,0),i=Math.min(i,e.length);for(let s=n;s<i;s++)if(e[s]===1)return!1;return!0}static isWhiteVertical(e,n,i,s){i=Math.max(i,0),s=Math.min(s,e.length);for(let a=i;a<s;a++)if(e[a][n]===1)return!1;return!0}static applyMaskPenaltyRule4(e){let n=0;const i=e.getArray(),s=e.getWidth(),a=e.getHeight();for(let h=0;h<a;h++){const g=i[h];for(let w=0;w<s;w++)g[w]===1&&n++}const l=e.getHeight()*e.getWidth();return Math.floor(Math.abs(n*2-l)*10/l)*Ct.N4}static getDataMaskBit(e,n,i){let s,a;switch(e){case 0:s=i+n&1;break;case 1:s=i&1;break;case 2:s=n%3;break;case 3:s=(i+n)%3;break;case 4:s=Math.floor(i/2)+Math.floor(n/3)&1;break;case 5:a=i*n,s=(a&1)+a%3;break;case 6:a=i*n,s=(a&1)+a%3&1;break;case 7:a=i*n,s=a%3+(i+n&1)&1;break;default:throw new E("Invalid mask pattern: "+e)}return s===0}static applyMaskPenaltyRule1Internal(e,n){let i=0;const s=n?e.getHeight():e.getWidth(),a=n?e.getWidth():e.getHeight(),l=e.getArray();for(let d=0;d<s;d++){let h=0,g=-1;for(let w=0;w<a;w++){const b=n?l[d][w]:l[w][d];b===g?h++:(h>=5&&(i+=Ct.N1+(h-5)),h=1,g=b)}h>=5&&(i+=Ct.N1+(h-5))}return i}}Ct.N1=3,Ct.N2=3,Ct.N3=40,Ct.N4=10;class gi{constructor(e,n){this.width=e,this.height=n;const i=new Array(n);for(let s=0;s!==n;s++)i[s]=new Uint8Array(e);this.bytes=i}getHeight(){return this.height}getWidth(){return this.width}get(e,n){return this.bytes[n][e]}getArray(){return this.bytes}setNumber(e,n,i){this.bytes[n][e]=i}setBoolean(e,n,i){this.bytes[n][e]=i?1:0}clear(e){for(const n of this.bytes)Z.fill(n,e)}equals(e){if(!(e instanceof gi))return!1;const n=e;if(this.width!==n.width||this.height!==n.height)return!1;for(let i=0,s=this.height;i<s;++i){const a=this.bytes[i],l=n.bytes[i];for(let d=0,h=this.width;d<h;++d)if(a[d]!==l[d])return!1}return!0}toString(){const e=new oe;for(let n=0,i=this.height;n<i;++n){const s=this.bytes[n];for(let a=0,l=this.width;a<l;++a)switch(s[a]){case 0:e.append(" 0");break;case 1:e.append(" 1");break;default:e.append(" ");break}e.append(`
65
- `)}return e.toString()}}class er{constructor(){this.maskPattern=-1}getMode(){return this.mode}getECLevel(){return this.ecLevel}getVersion(){return this.version}getMaskPattern(){return this.maskPattern}getMatrix(){return this.matrix}toString(){const e=new oe;return e.append(`<<
56
+ ${f.value}`:x,c.llmConfig){const g=c.llmConfig.extraTools??{};c.llmConfig.extraTools={...g,...p.value}}}),{processSkillMentions:async()=>({shouldBlock:!1,skillItems:[]}),skillPromptPart:f,skillTools:p,skillOverviews:u}}const Dy=["title"],Py=v.defineComponent({__name:"tokenUsage",props:{usage:{type:Object,default:""}},setup(t){const r=t,o=v.computed(()=>{const{inputTokens:u=0,outputTokens:f=0,totalTokens:p=0,inputTokenDetails:x,outputTokenDetails:_}=r.usage,g=x?.cacheReadTokens||0,A=_?.reasoningTokens||0;return{cachedInputTokens:[g/p*100+"%",g],inputTokens:[(u-g)/p*100+"%",u],reasoningTokens:[A/p*100+"%",A],outputTokens:[(f-A)/p*100+"%",f]}}),c=v.computed(()=>{const{inputTokens:u=0,outputTokens:f=0,totalTokens:p=0,inputTokenDetails:x,outputTokenDetails:_}=r.usage,g=x?.cacheReadTokens||0,A=_?.reasoningTokens||0;return[`inputTokens: ${u}`,`outputTokens: ${f}`,`totalTokens: ${p}`,`cachedInputTokens: ${g}`,`reasoningTokens: ${A}`].join(`
57
+ `)});return(u,f)=>(v.openBlock(),v.createElementBlock("div",{class:"token-usage-wrap",title:c.value},[(v.openBlock(!0),v.createElementBlock(v.Fragment,null,v.renderList(o.value,(p,x)=>(v.openBlock(),v.createElementBlock("div",{key:x,class:v.normalizeClass(x),style:v.normalizeStyle({width:p[0]})},null,6))),128))],8,Dy))}}),Kn=(t,r)=>{const o=t.__vccOpts||t;for(const[c,u]of r)o[c]=u;return o},By=Kn(Py,[["__scopeId","data-v-78226cbc"]]),Ly={width:"100.000000",height:"100.000000",viewBox:"0 0 100 100",fill:"none",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"};function Fy(t,r){return v.openBlock(),v.createElementBlock("svg",Ly,[...r[0]||(r[0]=[v.createStaticVNode('<desc> Created with Pixso. </desc><defs><radialGradient gradientTransform="translate(32.4474 65.1156) rotate(128.932) scale(22.991 20.6919)" cx="0.000000" cy="0.000000" r="1.000000" id="paint_radial_9_3090_0" gradientUnits="userSpaceOnUse"><stop stop-color="#5ADDF8"></stop><stop stop-color="#AEBFFF"></stop><stop offset="0.329153" stop-color="#1476FF"></stop><stop offset="0.667785" stop-color="#655AF8"></stop><stop offset="0.868255" stop-color="#948CFF"></stop><stop offset="1.000000" stop-color="#D25AF8"></stop><stop offset="1.000000" stop-color="#5A8BF8"></stop></radialGradient><linearGradient x1="30.999874" y1="85.000229" x2="30.499891" y2="70.500214" id="paint_linear_9_3092_0" gradientUnits="userSpaceOnUse"><stop stop-color="#000000" stop-opacity="0.000000"></stop><stop offset="1.000000" stop-color="#000000"></stop></linearGradient><radialGradient gradientTransform="translate(26.9999 24.7118) rotate(38.3655) scale(77.7996 109.496)" cx="0.000000" cy="0.000000" r="1.000000" id="paint_radial_9_3094_0" gradientUnits="userSpaceOnUse"><stop stop-color="#5ADDF8"></stop><stop stop-color="#AEBFFF"></stop><stop offset="0.329153" stop-color="#1476FF"></stop><stop offset="0.667785" stop-color="#655AF8"></stop><stop offset="0.868255" stop-color="#948CFF"></stop><stop offset="1.000000" stop-color="#D25AF8"></stop><stop offset="1.000000" stop-color="#5A8BF8"></stop></radialGradient></defs><rect id="NEXT-LOGO-无背景渐变-右" width="100.000000" height="99.999939" transform="matrix(-1 0 0 1 100 0)" fill="#FFFFFF" fill-opacity="0"></rect>',3),v.createElementVNode("mask",{id:"mask9_3088","mask-type":"alpha",maskUnits:"userSpaceOnUse",x:"0.000061",y:"0.000061",width:"99.999939",height:"99.999939"},[v.createElementVNode("rect",{id:"画板 1773",width:"99.999962",height:"99.999947",transform:"matrix(-1 0 0 1 100 6.10352e-05)",fill:"#000000","fill-opacity":"1.000000"})],-1),v.createStaticVNode('<g mask="url(#mask9_3088)"><path id="矢量 1" d="M35.93 81.01L36 63L18 63.07L32.48 82.23C33.61 83.71 35.93 82.9 35.93 81.01Z" fill="url(#paint_radial_9_3090_0)" fill-opacity="1.000000" fill-rule="evenodd"></path><g opacity="0.100000" style="mix-blend-mode:normal;"><path id="矢量 1" d="M35.93 81.01L36 63L18 63.07L32.48 82.23C33.61 83.71 35.93 82.9 35.93 81.01Z" fill="url(#paint_linear_9_3092_0)" fill-opacity="1.000000" fill-rule="evenodd"></path></g><rect id="矩形 5" x="12.000000" y="19.000183" rx="26.999992" width="75.999977" height="53.999985" fill="url(#paint_radial_9_3094_0)" fill-opacity="1.000000"></rect><rect id="矩形 5" rx="26.499992" width="74.999977" height="52.999985" transform="matrix(-1 0 0 1 87.5 19.5002)" fill="#000000" fill-opacity="0"></rect><rect id="矩形 5" rx="26.499992" width="74.999977" height="52.999985" transform="matrix(-1 0 0 1 87.5 19.5002)" stroke="#000000" stroke-opacity="0" stroke-width="1.000000"></rect><path id="path" d="M45.39 59.06C44.22 60.05 42.9 60.66 41.43 60.89C39.95 61.12 38.57 61.04 37.28 60.65C36 60.26 34.04 58.58 34.04 58.58C34.04 58.58 29.02 54.73 29.02 45.61C29.02 36.5 33.5 32.5 33.5 32.5C33.5 32.5 34.72 31.31 36.5 31C38.29 30.68 39.43 30.98 40.66 31.33C50.89 34.23 62.38 34.33 72.58 31.33C73.81 30.98 74.91 30.93 75.89 31.17C76.87 31.42 77.71 31.89 78.42 32.59C81.65 35.81 82.87 41.06 83 45.61C83.12 50.09 81.97 55.24 78.94 58.54C78.04 59.52 76.98 60.22 75.78 60.63C74.58 61.04 73.32 61.12 71.99 60.89C70.66 60.66 69.48 60.05 68.46 59.06C68.01 58.62 67.39 58.07 66.57 57.4C65.76 56.73 64.83 56.08 63.79 55.44C62.75 54.8 61.62 54.25 60.39 53.8C59.16 53.35 57.91 53.13 56.62 53.13C55.36 53.13 54.16 53.36 53 53.83C51.85 54.29 50.79 54.84 49.82 55.48C48.86 56.12 48 56.78 47.26 57.45C46.51 58.11 45.89 58.65 45.39 59.06Z" fill="#FFFFFF" fill-opacity="1.000000" fill-rule="nonzero"></path><rect id="矩形 841" rx="2.000000" width="3.999999" height="11.999996" transform="matrix(-0.999983 0.00577157 0.00577157 0.999983 76.1109 38.0356)" fill="#1476FF" fill-opacity="1.000000"></rect><path id="合并" d="M42.96 38C43.77 37.97 44.55 38.42 44.92 39.19L48.73 47.11C49.22 48.13 48.79 49.34 47.75 49.81C46.72 50.28 45.48 49.83 44.99 48.8L42.96 44.59L40.94 48.81C40.45 49.83 39.21 50.28 38.18 49.81C37.14 49.34 36.7 48.13 37.2 47.11L41 39.19C41.37 38.42 42.16 37.98 42.96 38Z" fill="#1476FF" fill-opacity="1.000000" fill-rule="evenodd"></path></g>',1)])])}const rl={render:Fy};function Uy(t){const{messages:r,messageState:o,inputMessage:c,handleSendMessage:u}=t,f=v.h(rl,{style:{fontSize:"32px"}}),p=v.h(Sr.IconUser,{style:{fontSize:"32px"}}),x=v.h(rl,{style:{width:"48px",height:"48px"}}),_=v.ref({}),g=v.computed(()=>Wn.GeneratingStatus.includes(o.status)),A=v.computed(()=>r.value.findLastIndex(R=>R.role==="assistant")),E=R=>R===void 0?"复制":_.value[R]?"复制成功":"复制",L=async R=>{const P=r.value[R],H=typeof P.content=="string"?P.content:JSON.stringify(P.content);try{await navigator.clipboard.writeText(H),R!==void 0&&(_.value[R]=!0,setTimeout(()=>{_.value[R]=!1},3e3))}catch(Z){console.error("复制失败:",Z),Je("复制失败,请重试")}},M=async R=>{const P=r.value.findLastIndex((Z,$)=>Z.role==="user"&&$<=R);if(P===-1){console.warn("未找到可重新生成的用户消息"),Je("无法重新生成消息");return}const H=r.value[P];if(r.value=r.value.slice(0,P),Array.isArray(H.content)){const $=H.content.find(ee=>ee.type==="text")?.text||"",V=H.content.filter(ee=>ee.type!=="text");c.value=$,await u($,V.length>0?V:void 0)}else c.value=H.content,await u(H.content)};return{aiAvatar:f,userAvatar:p,welcomeIcon:x,roles:{assistant:{type:"markdown",placement:"start",avatar:f,maxWidth:"80%",customContentField:"uiContent",slots:{footer:({index:R})=>{const P=A.value===R;return g.value&&P?"":v.h("div",{class:["assistant-actions",{"latest-assistant":P,"historical-assistant":!P}],style:{display:"flex",justifyContent:"flex-start",alignItems:"center",gap:"4px"}},[v.h(Lt.IconButton,{icon:Sr.IconRefresh,size:24,onClick:()=>M(R)}),v.h(Ed,{effect:"light",content:E(R),placement:"right",visibleArrow:!1},()=>v.h(Lt.IconButton,{icon:Sr.IconCopy,size:24,onClick:()=>L(R)})),r.value[R].usage?v.h(By,{usage:r.value[R].usage}):null])}}},user:{placement:"end",avatar:p,maxWidth:"80%",customContentField:"uiContent"}},copyingStates:_,isProcessing:g,latestAssistantMessageIndex:A,copyTooltipContent:E,copyMessageToClipboard:L,regenerateMessage:M}}function zy(t){const{createConversation:r,switchConversation:o,deleteConversation:c,getCurrentConversation:u,abortRequest:f,conversationState:p,customAgentProvider:x}=t,_=v.ref(!1),g=()=>{v.nextTick(()=>{const D=document.querySelector("div.tr-bubble-list");D&&D.scrollTo({top:D.scrollHeight,behavior:"smooth"})})};return{showHistory:_,handleCreateConversation:()=>{f();const D=[];x.agent.responseMessages=D,r();const R=u();R.aiSdkMessages=D},handleHistorySelect:D=>{f(),o(D.id);const R=u();x.agent.responseMessages=R.aiSdkMessages,_.value=!1,g()},handleHistoryUpdateTitle:(D,R)=>{R.title=D},handleHistoryDelete:(D,R)=>{if(D.id==="delete"){if(p.currentId===R.id){Je("不允许删除当前会话");return}c(R.id)}},scrollToBottom:g}}function Vy(t){const{sessionId:r,agentRoot:o,mode:c,qrCodeUrl:u,remoteUrl:f,menuItems:p,AILogoUrl:x,show:_,addPluginFromScan:g,inputMessage:A}=t;let E=!1;const L=async H=>{if($u("添加工具中..."),H){const Z=await g(H,o);Je(Z?"添加工具完成":"重复添加工具或添加失败")}else Je("添加工具失败")},M=async H=>{if(/^\/[A-Za-z0-9-]{6,}$/.test(H)){try{const Z=await fetch(`${o}client?sessionId=${H.slice(1)}`);if(!Z.ok)throw new Error(`HTTP ${Z.status}`);const V=(await Z.json())?.data?.sessionId;V?await L(V):Je("添加工具失败,请检查识别码是否正确"),A.value=""}catch(Z){console.error("识别码处理失败:",Z),Je("添加工具失败,请检查识别码是否正确"),A.value=""}return!0}return!1},D=()=>{v.watch(r,H=>{H&&c==="remoter"&&!E&&(cr.createRemoter({sessionId:H,qrCodeUrl:u,remoteUrl:f,menuItems:p,logoUrl:x,onShowAIChat:()=>_.value=!0}),E=!0)},{immediate:!0})},R=()=>{v.watch(r,H=>{H&&L(H)})};return{handleScanSuccess:L,handleSessionIdInput:M,initialize:()=>{r.value&&L(r.value),c==="remoter"&&D(),R()},initializeRemoter:D,watchSessionIdChanges:R}}function $y(t){return new Promise((r,o)=>{const c=new FileReader;c.onload=()=>r(c.result),c.onerror=o,c.readAsDataURL(t)})}function Zy(t){return t.type.startsWith("image/")}function jy(t,r){const o=r*1024*1024;return t.size<=o}async function Hy(t){if(t.length===0)return[];const r=[];for(const o of t)if(o.rawFile)try{const c=await $y(o.rawFile);Zy(o.rawFile)&&r.push({type:"image",image:c})}catch(c){console.error("文件转换失败:",c),Je({type:"fail",message:"文件处理失败"})}return r}function Wy(t={}){const r=v.ref([]),o=async u=>{if(!u||u.length===0)return;c();const f=v.unref(t.maxFileSize)||10,p=v.unref(t.supportedTypes)||["image/"];for(const x of u){if(!p.some(g=>x.type.startsWith(g))){Je({type:"fail",message:`不支持的文件类型: ${x.type}`});continue}if(!jy(x,f)){Je({type:"fail",message:`文件大小超过 ${f}MB 限制`});continue}r.value.push({rawFile:x,url:URL.createObjectURL(x)})}},c=()=>{r.value.forEach(u=>{u.url&&URL.revokeObjectURL(u.url)}),r.value=[]};return{attachments:r,handleFilesSelected:o,clearAttachments:c}}function Gy(t){const{selectedModel:r,selectedModelId:o}=t,c=v.computed(()=>r.value?.multimodal?.supportImages??!1),u=v.computed(()=>r.value?.multimodal?.maxFileSize||10),f=v.computed(()=>r.value?.multimodal?.supportedMimeTypes||["image/"]),{attachments:p,handleFilesSelected:x,clearAttachments:_}=Wy({maxFileSize:u,supportedTypes:f});return v.watch(o,()=>{if(p.value.length>0&&r.value){const M=r.value.multimodal?.maxFileSize||10,D=r.value.multimodal?.supportedMimeTypes||["image/"];p.value.filter(P=>{if(!P.rawFile||!D.some($=>P.rawFile.type.startsWith($)))return!0;const Z=M*1024*1024;return P.rawFile.size>Z}).length>0&&(_(),Je("切换模型后,之前选择的附件已清空"))}}),{hasMultimodalSupport:c,attachments:p,onFilesSelected:M=>{x(M)},checkCanSendAttachments:()=>p.value.length>0&&!c.value?(Je("当前模型不支持附件,请先移除附件或切换支持多模态的模型"),!1):!0,processAttachments:async()=>p.value.length===0?[]:await Hy(p.value),cleanupAttachments:()=>{p.value.length>0&&_()},clearAttachments:_}}var ve;(function(t){t[t.QR_CODE=0]="QR_CODE",t[t.AZTEC=1]="AZTEC",t[t.CODABAR=2]="CODABAR",t[t.CODE_39=3]="CODE_39",t[t.CODE_93=4]="CODE_93",t[t.CODE_128=5]="CODE_128",t[t.DATA_MATRIX=6]="DATA_MATRIX",t[t.MAXICODE=7]="MAXICODE",t[t.ITF=8]="ITF",t[t.EAN_13=9]="EAN_13",t[t.EAN_8=10]="EAN_8",t[t.PDF_417=11]="PDF_417",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"})(ve||(ve={}));var il=new Map([[ve.QR_CODE,"QR_CODE"],[ve.AZTEC,"AZTEC"],[ve.CODABAR,"CODABAR"],[ve.CODE_39,"CODE_39"],[ve.CODE_93,"CODE_93"],[ve.CODE_128,"CODE_128"],[ve.DATA_MATRIX,"DATA_MATRIX"],[ve.MAXICODE,"MAXICODE"],[ve.ITF,"ITF"],[ve.EAN_13,"EAN_13"],[ve.EAN_8,"EAN_8"],[ve.PDF_417,"PDF_417"],[ve.RSS_14,"RSS_14"],[ve.RSS_EXPANDED,"RSS_EXPANDED"],[ve.UPC_A,"UPC_A"],[ve.UPC_E,"UPC_E"],[ve.UPC_EAN_EXTENSION,"UPC_EAN_EXTENSION"]]),ol;(function(t){t[t.UNKNOWN=0]="UNKNOWN",t[t.URL=1]="URL"})(ol||(ol={}));function Xy(t){return Object.values(ve).includes(t)}var ti;(function(t){t[t.SCAN_TYPE_CAMERA=0]="SCAN_TYPE_CAMERA",t[t.SCAN_TYPE_FILE=1]="SCAN_TYPE_FILE"})(ti||(ti={}));var qy=(function(){function t(){}return t.GITHUB_PROJECT_URL="https://github.com/mebjas/html5-qrcode",t.SCAN_DEFAULT_FPS=2,t.DEFAULT_DISABLE_FLIP=!1,t.DEFAULT_REMEMBER_LAST_CAMERA_USED=!0,t.DEFAULT_SUPPORTED_SCAN_TYPE=[ti.SCAN_TYPE_CAMERA,ti.SCAN_TYPE_FILE],t})(),Zu=(function(){function t(r,o){this.format=r,this.formatName=o}return t.prototype.toString=function(){return this.formatName},t.create=function(r){if(!il.has(r))throw"".concat(r," not in html5QrcodeSupportedFormatsTextMap");return new t(r,il.get(r))},t})(),sl=(function(){function t(){}return t.createFromText=function(r){var o={text:r};return{decodedText:r,result:o}},t.createFromQrcodeResult=function(r){return{decodedText:r.text,result:r}},t})(),Lo;(function(t){t[t.UNKWOWN_ERROR=0]="UNKWOWN_ERROR",t[t.IMPLEMENTATION_ERROR=1]="IMPLEMENTATION_ERROR",t[t.NO_CODE_FOUND_ERROR=2]="NO_CODE_FOUND_ERROR"})(Lo||(Lo={}));var Yy=(function(){function t(){}return t.createFrom=function(r){return{errorMessage:r,type:Lo.UNKWOWN_ERROR}},t})(),Jy=(function(){function t(r){this.verbose=r}return t.prototype.log=function(r){this.verbose&&console.log(r)},t.prototype.warn=function(r){this.verbose&&console.warn(r)},t.prototype.logError=function(r,o){(this.verbose||o===!0)&&console.error(r)},t.prototype.logErrors=function(r){if(r.length===0)throw"Logger#logError called without arguments";this.verbose&&console.error(r)},t})();function Mn(t){return typeof t>"u"||t===null}var Ir=(function(){function t(){}return t.codeParseError=function(r){return"QR code parse error, error = ".concat(r)},t.errorGettingUserMedia=function(r){return"Error getting userMedia, error = ".concat(r)},t.onlyDeviceSupportedError=function(){return"The device doesn't support navigator.mediaDevices , only supported cameraIdOrConfig in this case is deviceId parameter (string)."},t.cameraStreamingNotSupported=function(){return"Camera streaming not supported by the browser."},t.unableToQuerySupportedDevices=function(){return"Unable to query supported devices, unknown error."},t.insecureContextCameraQueryError=function(){return"Camera access is only supported in secure context like https or localhost."},t.scannerPaused=function(){return"Scanner paused"},t})(),ju=(function(){function t(){}return t.isMediaStreamConstraintsValid=function(r,o){if(typeof r!="object"){var c=typeof r;return o.logError("videoConstraints should be of type object, the "+"object passed is of type ".concat(c,"."),!0),!1}for(var u=["autoGainControl","channelCount","echoCancellation","latency","noiseSuppression","sampleRate","sampleSize","volume"],f=new Set(u),p=Object.keys(r),x=0,_=p;x<_.length;x++){var g=_[x];if(f.has(g))return o.logError("".concat(g," is not supported videoConstaints."),!0),!1}return!0},t})(),Hr={exports:{}},Ky=Hr.exports,al;function Qy(){return al||(al=1,(function(t,r){(function(o,c){c(r)})(Ky,(function(o){function c(C){return C==null}var u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(C,e){C.__proto__=e}||function(C,e){for(var n in e)e.hasOwnProperty(n)&&(C[n]=e[n])};function f(C,e){u(C,e);function n(){this.constructor=C}C.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}function p(C,e){var n=Object.setPrototypeOf;n?n(C,e):C.__proto__=e}function x(C,e){e===void 0&&(e=C.constructor);var n=Error.captureStackTrace;n&&n(C,e)}var _=(function(C){f(e,C);function e(n){var i=this.constructor,s=C.call(this,n)||this;return Object.defineProperty(s,"name",{value:i.name,enumerable:!1}),p(s,i.prototype),x(s),s}return e})(Error);class g extends _{constructor(e=void 0){super(e),this.message=e}getKind(){return this.constructor.kind}}g.kind="Exception";class A extends g{}A.kind="ArgumentException";class E extends g{}E.kind="IllegalArgumentException";class L{constructor(e){if(this.binarizer=e,e===null)throw new E("Binarizer must be non-null.")}getWidth(){return this.binarizer.getWidth()}getHeight(){return this.binarizer.getHeight()}getBlackRow(e,n){return this.binarizer.getBlackRow(e,n)}getBlackMatrix(){return(this.matrix===null||this.matrix===void 0)&&(this.matrix=this.binarizer.getBlackMatrix()),this.matrix}isCropSupported(){return this.binarizer.getLuminanceSource().isCropSupported()}crop(e,n,i,s){const a=this.binarizer.getLuminanceSource().crop(e,n,i,s);return new L(this.binarizer.createBinarizer(a))}isRotateSupported(){return this.binarizer.getLuminanceSource().isRotateSupported()}rotateCounterClockwise(){const e=this.binarizer.getLuminanceSource().rotateCounterClockwise();return new L(this.binarizer.createBinarizer(e))}rotateCounterClockwise45(){const e=this.binarizer.getLuminanceSource().rotateCounterClockwise45();return new L(this.binarizer.createBinarizer(e))}toString(){try{return this.getBlackMatrix().toString()}catch{return""}}}class M extends g{static getChecksumInstance(){return new M}}M.kind="ChecksumException";class D{constructor(e){this.source=e}getLuminanceSource(){return this.source}getWidth(){return this.source.getWidth()}getHeight(){return this.source.getHeight()}}class R{static arraycopy(e,n,i,s,a){for(;a--;)i[s++]=e[n++]}static currentTimeMillis(){return Date.now()}}class P extends g{}P.kind="IndexOutOfBoundsException";class H extends P{constructor(e=void 0,n=void 0){super(n),this.index=e,this.message=n}}H.kind="ArrayIndexOutOfBoundsException";class Z{static fill(e,n){for(let i=0,s=e.length;i<s;i++)e[i]=n}static fillWithin(e,n,i,s){Z.rangeCheck(e.length,n,i);for(let a=n;a<i;a++)e[a]=s}static rangeCheck(e,n,i){if(n>i)throw new E("fromIndex("+n+") > toIndex("+i+")");if(n<0)throw new H(n);if(i>e)throw new H(i)}static asList(...e){return e}static create(e,n,i){return Array.from({length:e}).map(a=>Array.from({length:n}).fill(i))}static createInt32Array(e,n,i){return Array.from({length:e}).map(a=>Int32Array.from({length:n}).fill(i))}static equals(e,n){if(!e||!n||!e.length||!n.length||e.length!==n.length)return!1;for(let i=0,s=e.length;i<s;i++)if(e[i]!==n[i])return!1;return!0}static hashCode(e){if(e===null)return 0;let n=1;for(const i of e)n=31*n+i;return n}static fillUint8Array(e,n){for(let i=0;i!==e.length;i++)e[i]=n}static copyOf(e,n){return e.slice(0,n)}static copyOfUint8Array(e,n){if(e.length<=n){const i=new Uint8Array(n);return i.set(e),i}return e.slice(0,n)}static copyOfRange(e,n,i){const s=i-n,a=new Int32Array(s);return R.arraycopy(e,n,a,0,s),a}static binarySearch(e,n,i){i===void 0&&(i=Z.numberComparator);let s=0,a=e.length-1;for(;s<=a;){const l=a+s>>1,d=i(n,e[l]);if(d>0)s=l+1;else if(d<0)a=l-1;else return l}return-s-1}static numberComparator(e,n){return e-n}}class ${static numberOfTrailingZeros(e){let n;if(e===0)return 32;let i=31;return n=e<<16,n!==0&&(i-=16,e=n),n=e<<8,n!==0&&(i-=8,e=n),n=e<<4,n!==0&&(i-=4,e=n),n=e<<2,n!==0&&(i-=2,e=n),i-(e<<1>>>31)}static numberOfLeadingZeros(e){if(e===0)return 32;let n=1;return e>>>16||(n+=16,e<<=16),e>>>24||(n+=8,e<<=8),e>>>28||(n+=4,e<<=4),e>>>30||(n+=2,e<<=2),n-=e>>>31,n}static toHexString(e){return e.toString(16)}static toBinaryString(e){return String(parseInt(String(e),2))}static bitCount(e){return e=e-(e>>>1&1431655765),e=(e&858993459)+(e>>>2&858993459),e=e+(e>>>4)&252645135,e=e+(e>>>8),e=e+(e>>>16),e&63}static truncDivision(e,n){return Math.trunc(e/n)}static parseInt(e,n=void 0){return parseInt(e,n)}}$.MIN_VALUE_32_BITS=-2147483648,$.MAX_VALUE=Number.MAX_SAFE_INTEGER;class V{constructor(e,n){e===void 0?(this.size=0,this.bits=new Int32Array(1)):(this.size=e,n==null?this.bits=V.makeArray(e):this.bits=n)}getSize(){return this.size}getSizeInBytes(){return Math.floor((this.size+7)/8)}ensureCapacity(e){if(e>this.bits.length*32){const n=V.makeArray(e);R.arraycopy(this.bits,0,n,0,this.bits.length),this.bits=n}}get(e){return(this.bits[Math.floor(e/32)]&1<<(e&31))!==0}set(e){this.bits[Math.floor(e/32)]|=1<<(e&31)}flip(e){this.bits[Math.floor(e/32)]^=1<<(e&31)}getNextSet(e){const n=this.size;if(e>=n)return n;const i=this.bits;let s=Math.floor(e/32),a=i[s];a&=~((1<<(e&31))-1);const l=i.length;for(;a===0;){if(++s===l)return n;a=i[s]}const d=s*32+$.numberOfTrailingZeros(a);return d>n?n:d}getNextUnset(e){const n=this.size;if(e>=n)return n;const i=this.bits;let s=Math.floor(e/32),a=~i[s];a&=~((1<<(e&31))-1);const l=i.length;for(;a===0;){if(++s===l)return n;a=~i[s]}const d=s*32+$.numberOfTrailingZeros(a);return d>n?n:d}setBulk(e,n){this.bits[Math.floor(e/32)]=n}setRange(e,n){if(n<e||e<0||n>this.size)throw new E;if(n===e)return;n--;const i=Math.floor(e/32),s=Math.floor(n/32),a=this.bits;for(let l=i;l<=s;l++){const d=l>i?0:e&31,m=(2<<(l<s?31:n&31))-(1<<d);a[l]|=m}}clear(){const e=this.bits.length,n=this.bits;for(let i=0;i<e;i++)n[i]=0}isRange(e,n,i){if(n<e||e<0||n>this.size)throw new E;if(n===e)return!0;n--;const s=Math.floor(e/32),a=Math.floor(n/32),l=this.bits;for(let d=s;d<=a;d++){const h=d>s?0:e&31,y=(2<<(d<a?31:n&31))-(1<<h)&4294967295;if((l[d]&y)!==(i?y:0))return!1}return!0}appendBit(e){this.ensureCapacity(this.size+1),e&&(this.bits[Math.floor(this.size/32)]|=1<<(this.size&31)),this.size++}appendBits(e,n){if(n<0||n>32)throw new E("Num bits must be between 0 and 32");this.ensureCapacity(this.size+n);for(let i=n;i>0;i--)this.appendBit((e>>i-1&1)===1)}appendBitArray(e){const n=e.size;this.ensureCapacity(this.size+n);for(let i=0;i<n;i++)this.appendBit(e.get(i))}xor(e){if(this.size!==e.size)throw new E("Sizes don't match");const n=this.bits;for(let i=0,s=n.length;i<s;i++)n[i]^=e.bits[i]}toBytes(e,n,i,s){for(let a=0;a<s;a++){let l=0;for(let d=0;d<8;d++)this.get(e)&&(l|=1<<7-d),e++;n[i+a]=l}}getBitArray(){return this.bits}reverse(){const e=new Int32Array(this.bits.length),n=Math.floor((this.size-1)/32),i=n+1,s=this.bits;for(let a=0;a<i;a++){let l=s[a];l=l>>1&1431655765|(l&1431655765)<<1,l=l>>2&858993459|(l&858993459)<<2,l=l>>4&252645135|(l&252645135)<<4,l=l>>8&16711935|(l&16711935)<<8,l=l>>16&65535|(l&65535)<<16,e[n-a]=l}if(this.size!==i*32){const a=i*32-this.size;let l=e[0]>>>a;for(let d=1;d<i;d++){const h=e[d];l|=h<<32-a,e[d-1]=l,l=h>>>a}e[i-1]=l}this.bits=e}static makeArray(e){return new Int32Array(Math.floor((e+31)/32))}equals(e){if(!(e instanceof V))return!1;const n=e;return this.size===n.size&&Z.equals(this.bits,n.bits)}hashCode(){return 31*this.size+Z.hashCode(this.bits)}toString(){let e="";for(let n=0,i=this.size;n<i;n++)(n&7)===0&&(e+=" "),e+=this.get(n)?"X":".";return e}clone(){return new V(this.size,this.bits.slice())}}var ee;(function(C){C[C.OTHER=0]="OTHER",C[C.PURE_BARCODE=1]="PURE_BARCODE",C[C.POSSIBLE_FORMATS=2]="POSSIBLE_FORMATS",C[C.TRY_HARDER=3]="TRY_HARDER",C[C.CHARACTER_SET=4]="CHARACTER_SET",C[C.ALLOWED_LENGTHS=5]="ALLOWED_LENGTHS",C[C.ASSUME_CODE_39_CHECK_DIGIT=6]="ASSUME_CODE_39_CHECK_DIGIT",C[C.ASSUME_GS1=7]="ASSUME_GS1",C[C.RETURN_CODABAR_START_END=8]="RETURN_CODABAR_START_END",C[C.NEED_RESULT_POINT_CALLBACK=9]="NEED_RESULT_POINT_CALLBACK",C[C.ALLOWED_EAN_EXTENSIONS=10]="ALLOWED_EAN_EXTENSIONS"})(ee||(ee={}));var j=ee;class z extends g{static getFormatInstance(){return new z}}z.kind="FormatException";var q;(function(C){C[C.Cp437=0]="Cp437",C[C.ISO8859_1=1]="ISO8859_1",C[C.ISO8859_2=2]="ISO8859_2",C[C.ISO8859_3=3]="ISO8859_3",C[C.ISO8859_4=4]="ISO8859_4",C[C.ISO8859_5=5]="ISO8859_5",C[C.ISO8859_6=6]="ISO8859_6",C[C.ISO8859_7=7]="ISO8859_7",C[C.ISO8859_8=8]="ISO8859_8",C[C.ISO8859_9=9]="ISO8859_9",C[C.ISO8859_10=10]="ISO8859_10",C[C.ISO8859_11=11]="ISO8859_11",C[C.ISO8859_13=12]="ISO8859_13",C[C.ISO8859_14=13]="ISO8859_14",C[C.ISO8859_15=14]="ISO8859_15",C[C.ISO8859_16=15]="ISO8859_16",C[C.SJIS=16]="SJIS",C[C.Cp1250=17]="Cp1250",C[C.Cp1251=18]="Cp1251",C[C.Cp1252=19]="Cp1252",C[C.Cp1256=20]="Cp1256",C[C.UnicodeBigUnmarked=21]="UnicodeBigUnmarked",C[C.UTF8=22]="UTF8",C[C.ASCII=23]="ASCII",C[C.Big5=24]="Big5",C[C.GB18030=25]="GB18030",C[C.EUC_KR=26]="EUC_KR"})(q||(q={}));class B{constructor(e,n,i,...s){this.valueIdentifier=e,this.name=i,typeof n=="number"?this.values=Int32Array.from([n]):this.values=n,this.otherEncodingNames=s,B.VALUE_IDENTIFIER_TO_ECI.set(e,this),B.NAME_TO_ECI.set(i,this);const a=this.values;for(let l=0,d=a.length;l!==d;l++){const h=a[l];B.VALUES_TO_ECI.set(h,this)}for(const l of s)B.NAME_TO_ECI.set(l,this)}getValueIdentifier(){return this.valueIdentifier}getName(){return this.name}getValue(){return this.values[0]}static getCharacterSetECIByValue(e){if(e<0||e>=900)throw new z("incorect value");const n=B.VALUES_TO_ECI.get(e);if(n===void 0)throw new z("incorect value");return n}static getCharacterSetECIByName(e){const n=B.NAME_TO_ECI.get(e);if(n===void 0)throw new z("incorect value");return n}equals(e){if(!(e instanceof B))return!1;const n=e;return this.getName()===n.getName()}}B.VALUE_IDENTIFIER_TO_ECI=new Map,B.VALUES_TO_ECI=new Map,B.NAME_TO_ECI=new Map,B.Cp437=new B(q.Cp437,Int32Array.from([0,2]),"Cp437"),B.ISO8859_1=new B(q.ISO8859_1,Int32Array.from([1,3]),"ISO-8859-1","ISO88591","ISO8859_1"),B.ISO8859_2=new B(q.ISO8859_2,4,"ISO-8859-2","ISO88592","ISO8859_2"),B.ISO8859_3=new B(q.ISO8859_3,5,"ISO-8859-3","ISO88593","ISO8859_3"),B.ISO8859_4=new B(q.ISO8859_4,6,"ISO-8859-4","ISO88594","ISO8859_4"),B.ISO8859_5=new B(q.ISO8859_5,7,"ISO-8859-5","ISO88595","ISO8859_5"),B.ISO8859_6=new B(q.ISO8859_6,8,"ISO-8859-6","ISO88596","ISO8859_6"),B.ISO8859_7=new B(q.ISO8859_7,9,"ISO-8859-7","ISO88597","ISO8859_7"),B.ISO8859_8=new B(q.ISO8859_8,10,"ISO-8859-8","ISO88598","ISO8859_8"),B.ISO8859_9=new B(q.ISO8859_9,11,"ISO-8859-9","ISO88599","ISO8859_9"),B.ISO8859_10=new B(q.ISO8859_10,12,"ISO-8859-10","ISO885910","ISO8859_10"),B.ISO8859_11=new B(q.ISO8859_11,13,"ISO-8859-11","ISO885911","ISO8859_11"),B.ISO8859_13=new B(q.ISO8859_13,15,"ISO-8859-13","ISO885913","ISO8859_13"),B.ISO8859_14=new B(q.ISO8859_14,16,"ISO-8859-14","ISO885914","ISO8859_14"),B.ISO8859_15=new B(q.ISO8859_15,17,"ISO-8859-15","ISO885915","ISO8859_15"),B.ISO8859_16=new B(q.ISO8859_16,18,"ISO-8859-16","ISO885916","ISO8859_16"),B.SJIS=new B(q.SJIS,20,"SJIS","Shift_JIS"),B.Cp1250=new B(q.Cp1250,21,"Cp1250","windows-1250"),B.Cp1251=new B(q.Cp1251,22,"Cp1251","windows-1251"),B.Cp1252=new B(q.Cp1252,23,"Cp1252","windows-1252"),B.Cp1256=new B(q.Cp1256,24,"Cp1256","windows-1256"),B.UnicodeBigUnmarked=new B(q.UnicodeBigUnmarked,25,"UnicodeBigUnmarked","UTF-16BE","UnicodeBig"),B.UTF8=new B(q.UTF8,26,"UTF8","UTF-8"),B.ASCII=new B(q.ASCII,Int32Array.from([27,170]),"ASCII","US-ASCII"),B.Big5=new B(q.Big5,28,"Big5"),B.GB18030=new B(q.GB18030,29,"GB18030","GB2312","EUC_CN","GBK"),B.EUC_KR=new B(q.EUC_KR,30,"EUC_KR","EUC-KR");class we extends g{}we.kind="UnsupportedOperationException";class re{static decode(e,n){const i=this.encodingName(n);return this.customDecoder?this.customDecoder(e,i):typeof TextDecoder>"u"||this.shouldDecodeOnFallback(i)?this.decodeFallback(e,i):new TextDecoder(i).decode(e)}static shouldDecodeOnFallback(e){return!re.isBrowser()&&e==="ISO-8859-1"}static encode(e,n){const i=this.encodingName(n);return this.customEncoder?this.customEncoder(e,i):typeof TextEncoder>"u"?this.encodeFallback(e):new TextEncoder().encode(e)}static isBrowser(){return typeof window<"u"&&{}.toString.call(window)==="[object Window]"}static encodingName(e){return typeof e=="string"?e:e.getName()}static encodingCharacterSet(e){return e instanceof B?e:B.getCharacterSetECIByName(e)}static decodeFallback(e,n){const i=this.encodingCharacterSet(n);if(re.isDecodeFallbackSupported(i)){let s="";for(let a=0,l=e.length;a<l;a++){let d=e[a].toString(16);d.length<2&&(d="0"+d),s+="%"+d}return decodeURIComponent(s)}if(i.equals(B.UnicodeBigUnmarked))return String.fromCharCode.apply(null,new Uint16Array(e.buffer));throw new we(`Encoding ${this.encodingName(n)} not supported by fallback.`)}static isDecodeFallbackSupported(e){return e.equals(B.UTF8)||e.equals(B.ISO8859_1)||e.equals(B.ASCII)}static encodeFallback(e){const i=btoa(unescape(encodeURIComponent(e))).split(""),s=[];for(let a=0;a<i.length;a++)s.push(i[a].charCodeAt(0));return new Uint8Array(s)}}class ne{static castAsNonUtf8Char(e,n=null){const i=n?n.getName():this.ISO88591;return re.decode(new Uint8Array([e]),i)}static guessEncoding(e,n){if(n!=null&&n.get(j.CHARACTER_SET)!==void 0)return n.get(j.CHARACTER_SET).toString();const i=e.length;let s=!0,a=!0,l=!0,d=0,h=0,m=0,y=0,b=0,I=0,k=0,F=0,U=0,G=0,Q=0;const fe=e.length>3&&e[0]===239&&e[1]===187&&e[2]===191;for(let pe=0;pe<i&&(s||a||l);pe++){const de=e[pe]&255;l&&(d>0?(de&128)===0?l=!1:d--:(de&128)!==0&&((de&64)===0?l=!1:(d++,(de&32)===0?h++:(d++,(de&16)===0?m++:(d++,(de&8)===0?y++:l=!1))))),s&&(de>127&&de<160?s=!1:de>159&&(de<192||de===215||de===247)&&Q++),a&&(b>0?de<64||de===127||de>252?a=!1:b--:de===128||de===160||de>239?a=!1:de>160&&de<224?(I++,F=0,k++,k>U&&(U=k)):de>127?(b++,k=0,F++,F>G&&(G=F)):(k=0,F=0))}return l&&d>0&&(l=!1),a&&b>0&&(a=!1),l&&(fe||h+m+y>0)?ne.UTF8:a&&(ne.ASSUME_SHIFT_JIS||U>=3||G>=3)?ne.SHIFT_JIS:s&&a?U===2&&I===2||Q*10>=i?ne.SHIFT_JIS:ne.ISO88591:s?ne.ISO88591:a?ne.SHIFT_JIS:l?ne.UTF8:ne.PLATFORM_DEFAULT_ENCODING}static format(e,...n){let i=-1;function s(l,d,h,m,y,b){if(l==="%%")return"%";if(n[++i]===void 0)return;l=m?parseInt(m.substr(1)):void 0;let I=y?parseInt(y.substr(1)):void 0,k;switch(b){case"s":k=n[i];break;case"c":k=n[i][0];break;case"f":k=parseFloat(n[i]).toFixed(l);break;case"p":k=parseFloat(n[i]).toPrecision(l);break;case"e":k=parseFloat(n[i]).toExponential(l);break;case"x":k=parseInt(n[i]).toString(I||16);break;case"d":k=parseFloat(parseInt(n[i],I||10).toPrecision(l)).toFixed(0);break}k=typeof k=="object"?JSON.stringify(k):(+k).toString(I);let F=parseInt(h),U=h&&h[0]+""=="0"?"0":" ";for(;k.length<F;)k=d!==void 0?k+U:U+k;return k}let a=/%(-)?(0?[0-9]+)?([.][0-9]+)?([#][0-9]+)?([scfpexd%])/g;return e.replace(a,s)}static getBytes(e,n){return re.encode(e,n)}static getCharCode(e,n=0){return e.charCodeAt(n)}static getCharAt(e){return String.fromCharCode(e)}}ne.SHIFT_JIS=B.SJIS.getName(),ne.GB2312="GB2312",ne.ISO88591=B.ISO8859_1.getName(),ne.EUC_JP="EUC_JP",ne.UTF8=B.UTF8.getName(),ne.PLATFORM_DEFAULT_ENCODING=ne.UTF8,ne.ASSUME_SHIFT_JIS=!1;class le{constructor(e=""){this.value=e}enableDecoding(e){return this.encoding=e,this}append(e){return typeof e=="string"?this.value+=e.toString():this.encoding?this.value+=ne.castAsNonUtf8Char(e,this.encoding):this.value+=String.fromCharCode(e),this}appendChars(e,n,i){for(let s=n;n<n+i;s++)this.append(e[s]);return this}length(){return this.value.length}charAt(e){return this.value.charAt(e)}deleteCharAt(e){this.value=this.value.substr(0,e)+this.value.substring(e+1)}setCharAt(e,n){this.value=this.value.substr(0,e)+n+this.value.substr(e+1)}substring(e,n){return this.value.substring(e,n)}setLengthToZero(){this.value=""}toString(){return this.value}insert(e,n){this.value=this.value.substr(0,e)+n+this.value.substr(e+n.length)}}class te{constructor(e,n,i,s){if(this.width=e,this.height=n,this.rowSize=i,this.bits=s,n==null&&(n=e),this.height=n,e<1||n<1)throw new E("Both dimensions must be greater than 0");i==null&&(i=Math.floor((e+31)/32)),this.rowSize=i,s==null&&(this.bits=new Int32Array(this.rowSize*this.height))}static parseFromBooleanArray(e){const n=e.length,i=e[0].length,s=new te(i,n);for(let a=0;a<n;a++){const l=e[a];for(let d=0;d<i;d++)l[d]&&s.set(d,a)}return s}static parseFromString(e,n,i){if(e===null)throw new E("stringRepresentation cannot be null");const s=new Array(e.length);let a=0,l=0,d=-1,h=0,m=0;for(;m<e.length;)if(e.charAt(m)===`
58
+ `||e.charAt(m)==="\r"){if(a>l){if(d===-1)d=a-l;else if(a-l!==d)throw new E("row lengths do not match");l=a,h++}m++}else if(e.substring(m,m+n.length)===n)m+=n.length,s[a]=!0,a++;else if(e.substring(m,m+i.length)===i)m+=i.length,s[a]=!1,a++;else throw new E("illegal character encountered: "+e.substring(m));if(a>l){if(d===-1)d=a-l;else if(a-l!==d)throw new E("row lengths do not match");h++}const y=new te(d,h);for(let b=0;b<a;b++)s[b]&&y.set(Math.floor(b%d),Math.floor(b/d));return y}get(e,n){const i=n*this.rowSize+Math.floor(e/32);return(this.bits[i]>>>(e&31)&1)!==0}set(e,n){const i=n*this.rowSize+Math.floor(e/32);this.bits[i]|=1<<(e&31)&4294967295}unset(e,n){const i=n*this.rowSize+Math.floor(e/32);this.bits[i]&=~(1<<(e&31)&4294967295)}flip(e,n){const i=n*this.rowSize+Math.floor(e/32);this.bits[i]^=1<<(e&31)&4294967295}xor(e){if(this.width!==e.getWidth()||this.height!==e.getHeight()||this.rowSize!==e.getRowSize())throw new E("input matrix dimensions do not match");const n=new V(Math.floor(this.width/32)+1),i=this.rowSize,s=this.bits;for(let a=0,l=this.height;a<l;a++){const d=a*i,h=e.getRow(a,n).getBitArray();for(let m=0;m<i;m++)s[d+m]^=h[m]}}clear(){const e=this.bits,n=e.length;for(let i=0;i<n;i++)e[i]=0}setRegion(e,n,i,s){if(n<0||e<0)throw new E("Left and top must be nonnegative");if(s<1||i<1)throw new E("Height and width must be at least 1");const a=e+i,l=n+s;if(l>this.height||a>this.width)throw new E("The region must fit inside the matrix");const d=this.rowSize,h=this.bits;for(let m=n;m<l;m++){const y=m*d;for(let b=e;b<a;b++)h[y+Math.floor(b/32)]|=1<<(b&31)&4294967295}}getRow(e,n){n==null||n.getSize()<this.width?n=new V(this.width):n.clear();const i=this.rowSize,s=this.bits,a=e*i;for(let l=0;l<i;l++)n.setBulk(l*32,s[a+l]);return n}setRow(e,n){R.arraycopy(n.getBitArray(),0,this.bits,e*this.rowSize,this.rowSize)}rotate180(){const e=this.getWidth(),n=this.getHeight();let i=new V(e),s=new V(e);for(let a=0,l=Math.floor((n+1)/2);a<l;a++)i=this.getRow(a,i),s=this.getRow(n-1-a,s),i.reverse(),s.reverse(),this.setRow(a,s),this.setRow(n-1-a,i)}getEnclosingRectangle(){const e=this.width,n=this.height,i=this.rowSize,s=this.bits;let a=e,l=n,d=-1,h=-1;for(let m=0;m<n;m++)for(let y=0;y<i;y++){const b=s[m*i+y];if(b!==0){if(m<l&&(l=m),m>h&&(h=m),y*32<a){let I=0;for(;(b<<31-I&4294967295)===0;)I++;y*32+I<a&&(a=y*32+I)}if(y*32+31>d){let I=31;for(;!(b>>>I);)I--;y*32+I>d&&(d=y*32+I)}}}return d<a||h<l?null:Int32Array.from([a,l,d-a+1,h-l+1])}getTopLeftOnBit(){const e=this.rowSize,n=this.bits;let i=0;for(;i<n.length&&n[i]===0;)i++;if(i===n.length)return null;const s=i/e;let a=i%e*32;const l=n[i];let d=0;for(;(l<<31-d&4294967295)===0;)d++;return a+=d,Int32Array.from([a,s])}getBottomRightOnBit(){const e=this.rowSize,n=this.bits;let i=n.length-1;for(;i>=0&&n[i]===0;)i--;if(i<0)return null;const s=Math.floor(i/e);let a=Math.floor(i%e)*32;const l=n[i];let d=31;for(;!(l>>>d);)d--;return a+=d,Int32Array.from([a,s])}getWidth(){return this.width}getHeight(){return this.height}getRowSize(){return this.rowSize}equals(e){if(!(e instanceof te))return!1;const n=e;return this.width===n.width&&this.height===n.height&&this.rowSize===n.rowSize&&Z.equals(this.bits,n.bits)}hashCode(){let e=this.width;return e=31*e+this.width,e=31*e+this.height,e=31*e+this.rowSize,e=31*e+Z.hashCode(this.bits),e}toString(e="X ",n=" ",i=`
59
+ `){return this.buildToString(e,n,i)}buildToString(e,n,i){let s=new le;for(let a=0,l=this.height;a<l;a++){for(let d=0,h=this.width;d<h;d++)s.append(this.get(d,a)?e:n);s.append(i)}return s.toString()}clone(){return new te(this.width,this.height,this.rowSize,this.bits.slice())}}class O extends g{static getNotFoundInstance(){return new O}}O.kind="NotFoundException";class J extends D{constructor(e){super(e),this.luminances=J.EMPTY,this.buckets=new Int32Array(J.LUMINANCE_BUCKETS)}getBlackRow(e,n){const i=this.getLuminanceSource(),s=i.getWidth();n==null||n.getSize()<s?n=new V(s):n.clear(),this.initArrays(s);const a=i.getRow(e,this.luminances),l=this.buckets;for(let h=0;h<s;h++)l[(a[h]&255)>>J.LUMINANCE_SHIFT]++;const d=J.estimateBlackPoint(l);if(s<3)for(let h=0;h<s;h++)(a[h]&255)<d&&n.set(h);else{let h=a[0]&255,m=a[1]&255;for(let y=1;y<s-1;y++){const b=a[y+1]&255;(m*4-h-b)/2<d&&n.set(y),h=m,m=b}}return n}getBlackMatrix(){const e=this.getLuminanceSource(),n=e.getWidth(),i=e.getHeight(),s=new te(n,i);this.initArrays(n);const a=this.buckets;for(let h=1;h<5;h++){const m=Math.floor(i*h/5),y=e.getRow(m,this.luminances),b=Math.floor(n*4/5);for(let I=Math.floor(n/5);I<b;I++){const k=y[I]&255;a[k>>J.LUMINANCE_SHIFT]++}}const l=J.estimateBlackPoint(a),d=e.getMatrix();for(let h=0;h<i;h++){const m=h*n;for(let y=0;y<n;y++)(d[m+y]&255)<l&&s.set(y,h)}return s}createBinarizer(e){return new J(e)}initArrays(e){this.luminances.length<e&&(this.luminances=new Uint8ClampedArray(e));const n=this.buckets;for(let i=0;i<J.LUMINANCE_BUCKETS;i++)n[i]=0}static estimateBlackPoint(e){const n=e.length;let i=0,s=0,a=0;for(let y=0;y<n;y++)e[y]>a&&(s=y,a=e[y]),e[y]>i&&(i=e[y]);let l=0,d=0;for(let y=0;y<n;y++){const b=y-s,I=e[y]*b*b;I>d&&(l=y,d=I)}if(s>l){const y=s;s=l,l=y}if(l-s<=n/16)throw new O;let h=l-1,m=-1;for(let y=l-1;y>s;y--){const b=y-s,I=b*b*(l-y)*(i-e[y]);I>m&&(h=y,m=I)}return h<<J.LUMINANCE_SHIFT}}J.LUMINANCE_BITS=5,J.LUMINANCE_SHIFT=8-J.LUMINANCE_BITS,J.LUMINANCE_BUCKETS=1<<J.LUMINANCE_BITS,J.EMPTY=Uint8ClampedArray.from([0]);class ae extends J{constructor(e){super(e),this.matrix=null}getBlackMatrix(){if(this.matrix!==null)return this.matrix;const e=this.getLuminanceSource(),n=e.getWidth(),i=e.getHeight();if(n>=ae.MINIMUM_DIMENSION&&i>=ae.MINIMUM_DIMENSION){const s=e.getMatrix();let a=n>>ae.BLOCK_SIZE_POWER;(n&ae.BLOCK_SIZE_MASK)!==0&&a++;let l=i>>ae.BLOCK_SIZE_POWER;(i&ae.BLOCK_SIZE_MASK)!==0&&l++;const d=ae.calculateBlackPoints(s,a,l,n,i),h=new te(n,i);ae.calculateThresholdForBlock(s,a,l,n,i,d,h),this.matrix=h}else this.matrix=super.getBlackMatrix();return this.matrix}createBinarizer(e){return new ae(e)}static calculateThresholdForBlock(e,n,i,s,a,l,d){const h=a-ae.BLOCK_SIZE,m=s-ae.BLOCK_SIZE;for(let y=0;y<i;y++){let b=y<<ae.BLOCK_SIZE_POWER;b>h&&(b=h);const I=ae.cap(y,2,i-3);for(let k=0;k<n;k++){let F=k<<ae.BLOCK_SIZE_POWER;F>m&&(F=m);const U=ae.cap(k,2,n-3);let G=0;for(let fe=-2;fe<=2;fe++){const pe=l[I+fe];G+=pe[U-2]+pe[U-1]+pe[U]+pe[U+1]+pe[U+2]}const Q=G/25;ae.thresholdBlock(e,F,b,Q,s,d)}}}static cap(e,n,i){return e<n?n:e>i?i:e}static thresholdBlock(e,n,i,s,a,l){for(let d=0,h=i*a+n;d<ae.BLOCK_SIZE;d++,h+=a)for(let m=0;m<ae.BLOCK_SIZE;m++)(e[h+m]&255)<=s&&l.set(n+m,i+d)}static calculateBlackPoints(e,n,i,s,a){const l=a-ae.BLOCK_SIZE,d=s-ae.BLOCK_SIZE,h=new Array(i);for(let m=0;m<i;m++){h[m]=new Int32Array(n);let y=m<<ae.BLOCK_SIZE_POWER;y>l&&(y=l);for(let b=0;b<n;b++){let I=b<<ae.BLOCK_SIZE_POWER;I>d&&(I=d);let k=0,F=255,U=0;for(let Q=0,fe=y*s+I;Q<ae.BLOCK_SIZE;Q++,fe+=s){for(let pe=0;pe<ae.BLOCK_SIZE;pe++){const de=e[fe+pe]&255;k+=de,de<F&&(F=de),de>U&&(U=de)}if(U-F>ae.MIN_DYNAMIC_RANGE)for(Q++,fe+=s;Q<ae.BLOCK_SIZE;Q++,fe+=s)for(let pe=0;pe<ae.BLOCK_SIZE;pe++)k+=e[fe+pe]&255}let G=k>>ae.BLOCK_SIZE_POWER*2;if(U-F<=ae.MIN_DYNAMIC_RANGE&&(G=F/2,m>0&&b>0)){const Q=(h[m-1][b]+2*h[m][b-1]+h[m-1][b-1])/4;F<Q&&(G=Q)}h[m][b]=G}}return h}}ae.BLOCK_SIZE_POWER=3,ae.BLOCK_SIZE=1<<ae.BLOCK_SIZE_POWER,ae.BLOCK_SIZE_MASK=ae.BLOCK_SIZE-1,ae.MINIMUM_DIMENSION=ae.BLOCK_SIZE*5,ae.MIN_DYNAMIC_RANGE=24;class oe{constructor(e,n){this.width=e,this.height=n}getWidth(){return this.width}getHeight(){return this.height}isCropSupported(){return!1}crop(e,n,i,s){throw new we("This luminance source does not support cropping.")}isRotateSupported(){return!1}rotateCounterClockwise(){throw new we("This luminance source does not support rotation by 90 degrees.")}rotateCounterClockwise45(){throw new we("This luminance source does not support rotation by 45 degrees.")}toString(){const e=new Uint8ClampedArray(this.width);let n=new le;for(let i=0;i<this.height;i++){const s=this.getRow(i,e);for(let a=0;a<this.width;a++){const l=s[a]&255;let d;l<64?d="#":l<128?d="+":l<192?d=".":d=" ",n.append(d)}n.append(`
60
+ `)}return n.toString()}}class ge extends oe{constructor(e){super(e.getWidth(),e.getHeight()),this.delegate=e}getRow(e,n){const i=this.delegate.getRow(e,n),s=this.getWidth();for(let a=0;a<s;a++)i[a]=255-(i[a]&255);return i}getMatrix(){const e=this.delegate.getMatrix(),n=this.getWidth()*this.getHeight(),i=new Uint8ClampedArray(n);for(let s=0;s<n;s++)i[s]=255-(e[s]&255);return i}isCropSupported(){return this.delegate.isCropSupported()}crop(e,n,i,s){return new ge(this.delegate.crop(e,n,i,s))}isRotateSupported(){return this.delegate.isRotateSupported()}invert(){return this.delegate}rotateCounterClockwise(){return new ge(this.delegate.rotateCounterClockwise())}rotateCounterClockwise45(){return new ge(this.delegate.rotateCounterClockwise45())}}class he extends oe{constructor(e){super(e.width,e.height),this.canvas=e,this.tempCanvasElement=null,this.buffer=he.makeBufferFromCanvasImageData(e)}static makeBufferFromCanvasImageData(e){const n=e.getContext("2d").getImageData(0,0,e.width,e.height);return he.toGrayscaleBuffer(n.data,e.width,e.height)}static toGrayscaleBuffer(e,n,i){const s=new Uint8ClampedArray(n*i);for(let a=0,l=0,d=e.length;a<d;a+=4,l++){let h;if(e[a+3]===0)h=255;else{const y=e[a],b=e[a+1],I=e[a+2];h=306*y+601*b+117*I+512>>10}s[l]=h}return s}getRow(e,n){if(e<0||e>=this.getHeight())throw new E("Requested row is outside the image: "+e);const i=this.getWidth(),s=e*i;return n===null?n=this.buffer.slice(s,s+i):(n.length<i&&(n=new Uint8ClampedArray(i)),n.set(this.buffer.slice(s,s+i))),n}getMatrix(){return this.buffer}isCropSupported(){return!0}crop(e,n,i,s){return super.crop(e,n,i,s),this}isRotateSupported(){return!0}rotateCounterClockwise(){return this.rotate(-90),this}rotateCounterClockwise45(){return this.rotate(-45),this}getTempCanvasElement(){if(this.tempCanvasElement===null){const e=this.canvas.ownerDocument.createElement("canvas");e.width=this.canvas.width,e.height=this.canvas.height,this.tempCanvasElement=e}return this.tempCanvasElement}rotate(e){const n=this.getTempCanvasElement(),i=n.getContext("2d"),s=e*he.DEGREE_TO_RADIANS,a=this.canvas.width,l=this.canvas.height,d=Math.ceil(Math.abs(Math.cos(s))*a+Math.abs(Math.sin(s))*l),h=Math.ceil(Math.abs(Math.sin(s))*a+Math.abs(Math.cos(s))*l);return n.width=d,n.height=h,i.translate(d/2,h/2),i.rotate(s),i.drawImage(this.canvas,a/-2,l/-2),this.buffer=he.makeBufferFromCanvasImageData(n),this}invert(){return new ge(this)}}he.DEGREE_TO_RADIANS=Math.PI/180;class ue{constructor(e,n,i){this.deviceId=e,this.label=n,this.kind="videoinput",this.groupId=i||void 0}toJSON(){return{kind:this.kind,groupId:this.groupId,deviceId:this.deviceId,label:this.label}}}var Ce=(globalThis||Ci||self||window||void 0)&&(globalThis||Ci||self||window||void 0).__awaiter||function(C,e,n,i){function s(a){return a instanceof n?a:new n(function(l){l(a)})}return new(n||(n=Promise))(function(a,l){function d(y){try{m(i.next(y))}catch(b){l(b)}}function h(y){try{m(i.throw(y))}catch(b){l(b)}}function m(y){y.done?a(y.value):s(y.value).then(d,h)}m((i=i.apply(C,e||[])).next())})};class je{constructor(e,n=500,i){this.reader=e,this.timeBetweenScansMillis=n,this._hints=i,this._stopContinuousDecode=!1,this._stopAsyncDecode=!1,this._timeBetweenDecodingAttempts=0}get hasNavigator(){return typeof navigator<"u"}get isMediaDevicesSuported(){return this.hasNavigator&&!!navigator.mediaDevices}get canEnumerateDevices(){return!!(this.isMediaDevicesSuported&&navigator.mediaDevices.enumerateDevices)}get timeBetweenDecodingAttempts(){return this._timeBetweenDecodingAttempts}set timeBetweenDecodingAttempts(e){this._timeBetweenDecodingAttempts=e<0?0:e}set hints(e){this._hints=e||null}get hints(){return this._hints}listVideoInputDevices(){return Ce(this,void 0,void 0,function*(){if(!this.hasNavigator)throw new Error("Can't enumerate devices, navigator is not present.");if(!this.canEnumerateDevices)throw new Error("Can't enumerate devices, method not supported.");const e=yield navigator.mediaDevices.enumerateDevices(),n=[];for(const i of e){const s=i.kind==="video"?"videoinput":i.kind;if(s!=="videoinput")continue;const a=i.deviceId||i.id,l=i.label||`Video device ${n.length+1}`,d=i.groupId,h={deviceId:a,label:l,kind:s,groupId:d};n.push(h)}return n})}getVideoInputDevices(){return Ce(this,void 0,void 0,function*(){return(yield this.listVideoInputDevices()).map(n=>new ue(n.deviceId,n.label))})}findDeviceById(e){return Ce(this,void 0,void 0,function*(){const n=yield this.listVideoInputDevices();return n?n.find(i=>i.deviceId===e):null})}decodeFromInputVideoDevice(e,n){return Ce(this,void 0,void 0,function*(){return yield this.decodeOnceFromVideoDevice(e,n)})}decodeOnceFromVideoDevice(e,n){return Ce(this,void 0,void 0,function*(){this.reset();let i;e?i={deviceId:{exact:e}}:i={facingMode:"environment"};const s={video:i};return yield this.decodeOnceFromConstraints(s,n)})}decodeOnceFromConstraints(e,n){return Ce(this,void 0,void 0,function*(){const i=yield navigator.mediaDevices.getUserMedia(e);return yield this.decodeOnceFromStream(i,n)})}decodeOnceFromStream(e,n){return Ce(this,void 0,void 0,function*(){this.reset();const i=yield this.attachStreamToVideo(e,n);return yield this.decodeOnce(i)})}decodeFromInputVideoDeviceContinuously(e,n,i){return Ce(this,void 0,void 0,function*(){return yield this.decodeFromVideoDevice(e,n,i)})}decodeFromVideoDevice(e,n,i){return Ce(this,void 0,void 0,function*(){let s;e?s={deviceId:{exact:e}}:s={facingMode:"environment"};const a={video:s};return yield this.decodeFromConstraints(a,n,i)})}decodeFromConstraints(e,n,i){return Ce(this,void 0,void 0,function*(){const s=yield navigator.mediaDevices.getUserMedia(e);return yield this.decodeFromStream(s,n,i)})}decodeFromStream(e,n,i){return Ce(this,void 0,void 0,function*(){this.reset();const s=yield this.attachStreamToVideo(e,n);return yield this.decodeContinuously(s,i)})}stopAsyncDecode(){this._stopAsyncDecode=!0}stopContinuousDecode(){this._stopContinuousDecode=!0}attachStreamToVideo(e,n){return Ce(this,void 0,void 0,function*(){const i=this.prepareVideoElement(n);return this.addVideoSource(i,e),this.videoElement=i,this.stream=e,yield this.playVideoOnLoadAsync(i),i})}playVideoOnLoadAsync(e){return new Promise((n,i)=>this.playVideoOnLoad(e,()=>n()))}playVideoOnLoad(e,n){this.videoEndedListener=()=>this.stopStreams(),this.videoCanPlayListener=()=>this.tryPlayVideo(e),e.addEventListener("ended",this.videoEndedListener),e.addEventListener("canplay",this.videoCanPlayListener),e.addEventListener("playing",n),this.tryPlayVideo(e)}isVideoPlaying(e){return e.currentTime>0&&!e.paused&&!e.ended&&e.readyState>2}tryPlayVideo(e){return Ce(this,void 0,void 0,function*(){if(this.isVideoPlaying(e)){console.warn("Trying to play video that is already playing.");return}try{yield e.play()}catch{console.warn("It was not possible to play the video.")}})}getMediaElement(e,n){const i=document.getElementById(e);if(!i)throw new A(`element with id '${e}' not found`);if(i.nodeName.toLowerCase()!==n.toLowerCase())throw new A(`element with id '${e}' must be an ${n} element`);return i}decodeFromImage(e,n){if(!e&&!n)throw new A("either imageElement with a src set or an url must be provided");return n&&!e?this.decodeFromImageUrl(n):this.decodeFromImageElement(e)}decodeFromVideo(e,n){if(!e&&!n)throw new A("Either an element with a src set or an URL must be provided");return n&&!e?this.decodeFromVideoUrl(n):this.decodeFromVideoElement(e)}decodeFromVideoContinuously(e,n,i){if(e===void 0&&n===void 0)throw new A("Either an element with a src set or an URL must be provided");return n&&!e?this.decodeFromVideoUrlContinuously(n,i):this.decodeFromVideoElementContinuously(e,i)}decodeFromImageElement(e){if(!e)throw new A("An image element must be provided.");this.reset();const n=this.prepareImageElement(e);this.imageElement=n;let i;return this.isImageLoaded(n)?i=this.decodeOnce(n,!1,!0):i=this._decodeOnLoadImage(n),i}decodeFromVideoElement(e){const n=this._decodeFromVideoElementSetup(e);return this._decodeOnLoadVideo(n)}decodeFromVideoElementContinuously(e,n){const i=this._decodeFromVideoElementSetup(e);return this._decodeOnLoadVideoContinuously(i,n)}_decodeFromVideoElementSetup(e){if(!e)throw new A("A video element must be provided.");this.reset();const n=this.prepareVideoElement(e);return this.videoElement=n,n}decodeFromImageUrl(e){if(!e)throw new A("An URL must be provided.");this.reset();const n=this.prepareImageElement();this.imageElement=n;const i=this._decodeOnLoadImage(n);return n.src=e,i}decodeFromVideoUrl(e){if(!e)throw new A("An URL must be provided.");this.reset();const n=this.prepareVideoElement(),i=this.decodeFromVideoElement(n);return n.src=e,i}decodeFromVideoUrlContinuously(e,n){if(!e)throw new A("An URL must be provided.");this.reset();const i=this.prepareVideoElement(),s=this.decodeFromVideoElementContinuously(i,n);return i.src=e,s}_decodeOnLoadImage(e){return new Promise((n,i)=>{this.imageLoadedListener=()=>this.decodeOnce(e,!1,!0).then(n,i),e.addEventListener("load",this.imageLoadedListener)})}_decodeOnLoadVideo(e){return Ce(this,void 0,void 0,function*(){return yield this.playVideoOnLoadAsync(e),yield this.decodeOnce(e)})}_decodeOnLoadVideoContinuously(e,n){return Ce(this,void 0,void 0,function*(){yield this.playVideoOnLoadAsync(e),this.decodeContinuously(e,n)})}isImageLoaded(e){return!(!e.complete||e.naturalWidth===0)}prepareImageElement(e){let n;return typeof e>"u"&&(n=document.createElement("img"),n.width=200,n.height=200),typeof e=="string"&&(n=this.getMediaElement(e,"img")),e instanceof HTMLImageElement&&(n=e),n}prepareVideoElement(e){let n;return!e&&typeof document<"u"&&(n=document.createElement("video"),n.width=200,n.height=200),typeof e=="string"&&(n=this.getMediaElement(e,"video")),e instanceof HTMLVideoElement&&(n=e),n.setAttribute("autoplay","true"),n.setAttribute("muted","true"),n.setAttribute("playsinline","true"),n}decodeOnce(e,n=!0,i=!0){this._stopAsyncDecode=!1;const s=(a,l)=>{if(this._stopAsyncDecode){l(new O("Video stream has ended before any code could be detected.")),this._stopAsyncDecode=void 0;return}try{const d=this.decode(e);a(d)}catch(d){const h=n&&d instanceof O,y=(d instanceof M||d instanceof z)&&i;if(h||y)return setTimeout(s,this._timeBetweenDecodingAttempts,a,l);l(d)}};return new Promise((a,l)=>s(a,l))}decodeContinuously(e,n){this._stopContinuousDecode=!1;const i=()=>{if(this._stopContinuousDecode){this._stopContinuousDecode=void 0;return}try{const s=this.decode(e);n(s,null),setTimeout(i,this.timeBetweenScansMillis)}catch(s){n(null,s);const a=s instanceof M||s instanceof z,l=s instanceof O;(a||l)&&setTimeout(i,this._timeBetweenDecodingAttempts)}};i()}decode(e){const n=this.createBinaryBitmap(e);return this.decodeBitmap(n)}_isHTMLVideoElement(e){return e.videoWidth!==0}drawFrameOnCanvas(e,n,i){n||(n={sx:0,sy:0,sWidth:e.videoWidth,sHeight:e.videoHeight,dx:0,dy:0,dWidth:e.videoWidth,dHeight:e.videoHeight}),i||(i=this.captureCanvasContext),i.drawImage(e,n.sx,n.sy,n.sWidth,n.sHeight,n.dx,n.dy,n.dWidth,n.dHeight)}drawImageOnCanvas(e,n,i=this.captureCanvasContext){n||(n={sx:0,sy:0,sWidth:e.naturalWidth,sHeight:e.naturalHeight,dx:0,dy:0,dWidth:e.naturalWidth,dHeight:e.naturalHeight}),i||(i=this.captureCanvasContext),i.drawImage(e,n.sx,n.sy,n.sWidth,n.sHeight,n.dx,n.dy,n.dWidth,n.dHeight)}createBinaryBitmap(e){this.getCaptureCanvasContext(e),this._isHTMLVideoElement(e)?this.drawFrameOnCanvas(e):this.drawImageOnCanvas(e);const n=this.getCaptureCanvas(e),i=new he(n),s=new ae(i);return new L(s)}getCaptureCanvasContext(e){if(!this.captureCanvasContext){const i=this.getCaptureCanvas(e).getContext("2d");this.captureCanvasContext=i}return this.captureCanvasContext}getCaptureCanvas(e){if(!this.captureCanvas){const n=this.createCaptureCanvas(e);this.captureCanvas=n}return this.captureCanvas}decodeBitmap(e){return this.reader.decode(e,this._hints)}createCaptureCanvas(e){if(typeof document>"u")return this._destroyCaptureCanvas(),null;const n=document.createElement("canvas");let i,s;return typeof e<"u"&&(e instanceof HTMLVideoElement?(i=e.videoWidth,s=e.videoHeight):e instanceof HTMLImageElement&&(i=e.naturalWidth||e.width,s=e.naturalHeight||e.height)),n.style.width=i+"px",n.style.height=s+"px",n.width=i,n.height=s,n}stopStreams(){this.stream&&(this.stream.getVideoTracks().forEach(e=>e.stop()),this.stream=void 0),this._stopAsyncDecode===!1&&this.stopAsyncDecode(),this._stopContinuousDecode===!1&&this.stopContinuousDecode()}reset(){this.stopStreams(),this._destroyVideoElement(),this._destroyImageElement(),this._destroyCaptureCanvas()}_destroyVideoElement(){this.videoElement&&(typeof this.videoEndedListener<"u"&&this.videoElement.removeEventListener("ended",this.videoEndedListener),typeof this.videoPlayingEventListener<"u"&&this.videoElement.removeEventListener("playing",this.videoPlayingEventListener),typeof this.videoCanPlayListener<"u"&&this.videoElement.removeEventListener("loadedmetadata",this.videoCanPlayListener),this.cleanVideoSource(this.videoElement),this.videoElement=void 0)}_destroyImageElement(){this.imageElement&&(this.imageLoadedListener!==void 0&&this.imageElement.removeEventListener("load",this.imageLoadedListener),this.imageElement.src=void 0,this.imageElement.removeAttribute("src"),this.imageElement=void 0)}_destroyCaptureCanvas(){this.captureCanvasContext=void 0,this.captureCanvas=void 0}addVideoSource(e,n){try{e.srcObject=n}catch{e.src=URL.createObjectURL(n)}}cleanVideoSource(e){try{e.srcObject=null}catch{e.src=""}this.videoElement.removeAttribute("src")}}class Be{constructor(e,n,i=n==null?0:8*n.length,s,a,l=R.currentTimeMillis()){this.text=e,this.rawBytes=n,this.numBits=i,this.resultPoints=s,this.format=a,this.timestamp=l,this.text=e,this.rawBytes=n,i==null?this.numBits=n==null?0:8*n.length:this.numBits=i,this.resultPoints=s,this.format=a,this.resultMetadata=null,l==null?this.timestamp=R.currentTimeMillis():this.timestamp=l}getText(){return this.text}getRawBytes(){return this.rawBytes}getNumBits(){return this.numBits}getResultPoints(){return this.resultPoints}getBarcodeFormat(){return this.format}getResultMetadata(){return this.resultMetadata}putMetadata(e,n){this.resultMetadata===null&&(this.resultMetadata=new Map),this.resultMetadata.set(e,n)}putAllMetadata(e){e!==null&&(this.resultMetadata===null?this.resultMetadata=e:this.resultMetadata=new Map(e))}addResultPoints(e){const n=this.resultPoints;if(n===null)this.resultPoints=e;else if(e!==null&&e.length>0){const i=new Array(n.length+e.length);R.arraycopy(n,0,i,0,n.length),R.arraycopy(e,0,i,n.length,e.length),this.resultPoints=i}}getTimestamp(){return this.timestamp}toString(){return this.text}}var ut;(function(C){C[C.AZTEC=0]="AZTEC",C[C.CODABAR=1]="CODABAR",C[C.CODE_39=2]="CODE_39",C[C.CODE_93=3]="CODE_93",C[C.CODE_128=4]="CODE_128",C[C.DATA_MATRIX=5]="DATA_MATRIX",C[C.EAN_8=6]="EAN_8",C[C.EAN_13=7]="EAN_13",C[C.ITF=8]="ITF",C[C.MAXICODE=9]="MAXICODE",C[C.PDF_417=10]="PDF_417",C[C.QR_CODE=11]="QR_CODE",C[C.RSS_14=12]="RSS_14",C[C.RSS_EXPANDED=13]="RSS_EXPANDED",C[C.UPC_A=14]="UPC_A",C[C.UPC_E=15]="UPC_E",C[C.UPC_EAN_EXTENSION=16]="UPC_EAN_EXTENSION"})(ut||(ut={}));var ie=ut,Ae;(function(C){C[C.OTHER=0]="OTHER",C[C.ORIENTATION=1]="ORIENTATION",C[C.BYTE_SEGMENTS=2]="BYTE_SEGMENTS",C[C.ERROR_CORRECTION_LEVEL=3]="ERROR_CORRECTION_LEVEL",C[C.ISSUE_NUMBER=4]="ISSUE_NUMBER",C[C.SUGGESTED_PRICE=5]="SUGGESTED_PRICE",C[C.POSSIBLE_COUNTRY=6]="POSSIBLE_COUNTRY",C[C.UPC_EAN_EXTENSION=7]="UPC_EAN_EXTENSION",C[C.PDF417_EXTRA_METADATA=8]="PDF417_EXTRA_METADATA",C[C.STRUCTURED_APPEND_SEQUENCE=9]="STRUCTURED_APPEND_SEQUENCE",C[C.STRUCTURED_APPEND_PARITY=10]="STRUCTURED_APPEND_PARITY"})(Ae||(Ae={}));var Me=Ae;class ke{constructor(e,n,i,s,a=-1,l=-1){this.rawBytes=e,this.text=n,this.byteSegments=i,this.ecLevel=s,this.structuredAppendSequenceNumber=a,this.structuredAppendParity=l,this.numBits=e==null?0:8*e.length}getRawBytes(){return this.rawBytes}getNumBits(){return this.numBits}setNumBits(e){this.numBits=e}getText(){return this.text}getByteSegments(){return this.byteSegments}getECLevel(){return this.ecLevel}getErrorsCorrected(){return this.errorsCorrected}setErrorsCorrected(e){this.errorsCorrected=e}getErasures(){return this.erasures}setErasures(e){this.erasures=e}getOther(){return this.other}setOther(e){this.other=e}hasStructuredAppend(){return this.structuredAppendParity>=0&&this.structuredAppendSequenceNumber>=0}getStructuredAppendParity(){return this.structuredAppendParity}getStructuredAppendSequenceNumber(){return this.structuredAppendSequenceNumber}}class et{exp(e){return this.expTable[e]}log(e){if(e===0)throw new E;return this.logTable[e]}static addOrSubtract(e,n){return e^n}}class tt{constructor(e,n){if(n.length===0)throw new E;this.field=e;const i=n.length;if(i>1&&n[0]===0){let s=1;for(;s<i&&n[s]===0;)s++;s===i?this.coefficients=Int32Array.from([0]):(this.coefficients=new Int32Array(i-s),R.arraycopy(n,s,this.coefficients,0,this.coefficients.length))}else this.coefficients=n}getCoefficients(){return this.coefficients}getDegree(){return this.coefficients.length-1}isZero(){return this.coefficients[0]===0}getCoefficient(e){return this.coefficients[this.coefficients.length-1-e]}evaluateAt(e){if(e===0)return this.getCoefficient(0);const n=this.coefficients;let i;if(e===1){i=0;for(let l=0,d=n.length;l!==d;l++){const h=n[l];i=et.addOrSubtract(i,h)}return i}i=n[0];const s=n.length,a=this.field;for(let l=1;l<s;l++)i=et.addOrSubtract(a.multiply(e,i),n[l]);return i}addOrSubtract(e){if(!this.field.equals(e.field))throw new E("GenericGFPolys do not have same GenericGF field");if(this.isZero())return e;if(e.isZero())return this;let n=this.coefficients,i=e.coefficients;if(n.length>i.length){const l=n;n=i,i=l}let s=new Int32Array(i.length);const a=i.length-n.length;R.arraycopy(i,0,s,0,a);for(let l=a;l<i.length;l++)s[l]=et.addOrSubtract(n[l-a],i[l]);return new tt(this.field,s)}multiply(e){if(!this.field.equals(e.field))throw new E("GenericGFPolys do not have same GenericGF field");if(this.isZero()||e.isZero())return this.field.getZero();const n=this.coefficients,i=n.length,s=e.coefficients,a=s.length,l=new Int32Array(i+a-1),d=this.field;for(let h=0;h<i;h++){const m=n[h];for(let y=0;y<a;y++)l[h+y]=et.addOrSubtract(l[h+y],d.multiply(m,s[y]))}return new tt(d,l)}multiplyScalar(e){if(e===0)return this.field.getZero();if(e===1)return this;const n=this.coefficients.length,i=this.field,s=new Int32Array(n),a=this.coefficients;for(let l=0;l<n;l++)s[l]=i.multiply(a[l],e);return new tt(i,s)}multiplyByMonomial(e,n){if(e<0)throw new E;if(n===0)return this.field.getZero();const i=this.coefficients,s=i.length,a=new Int32Array(s+e),l=this.field;for(let d=0;d<s;d++)a[d]=l.multiply(i[d],n);return new tt(l,a)}divide(e){if(!this.field.equals(e.field))throw new E("GenericGFPolys do not have same GenericGF field");if(e.isZero())throw new E("Divide by 0");const n=this.field;let i=n.getZero(),s=this;const a=e.getCoefficient(e.getDegree()),l=n.inverse(a);for(;s.getDegree()>=e.getDegree()&&!s.isZero();){const d=s.getDegree()-e.getDegree(),h=n.multiply(s.getCoefficient(s.getDegree()),l),m=e.multiplyByMonomial(d,h),y=n.buildMonomial(d,h);i=i.addOrSubtract(y),s=s.addOrSubtract(m)}return[i,s]}toString(){let e="";for(let n=this.getDegree();n>=0;n--){let i=this.getCoefficient(n);if(i!==0){if(i<0?(e+=" - ",i=-i):e.length>0&&(e+=" + "),n===0||i!==1){const s=this.field.log(i);s===0?e+="1":s===1?e+="a":(e+="a^",e+=s)}n!==0&&(n===1?e+="x":(e+="x^",e+=n))}}return e}}class Wt extends g{}Wt.kind="ArithmeticException";class Le extends et{constructor(e,n,i){super(),this.primitive=e,this.size=n,this.generatorBase=i;const s=new Int32Array(n);let a=1;for(let d=0;d<n;d++)s[d]=a,a*=2,a>=n&&(a^=e,a&=n-1);this.expTable=s;const l=new Int32Array(n);for(let d=0;d<n-1;d++)l[s[d]]=d;this.logTable=l,this.zero=new tt(this,Int32Array.from([0])),this.one=new tt(this,Int32Array.from([1]))}getZero(){return this.zero}getOne(){return this.one}buildMonomial(e,n){if(e<0)throw new E;if(n===0)return this.zero;const i=new Int32Array(e+1);return i[0]=n,new tt(this,i)}inverse(e){if(e===0)throw new Wt;return this.expTable[this.size-this.logTable[e]-1]}multiply(e,n){return e===0||n===0?0:this.expTable[(this.logTable[e]+this.logTable[n])%(this.size-1)]}getSize(){return this.size}getGeneratorBase(){return this.generatorBase}toString(){return"GF(0x"+$.toHexString(this.primitive)+","+this.size+")"}equals(e){return e===this}}Le.AZTEC_DATA_12=new Le(4201,4096,1),Le.AZTEC_DATA_10=new Le(1033,1024,1),Le.AZTEC_DATA_6=new Le(67,64,1),Le.AZTEC_PARAM=new Le(19,16,1),Le.QR_CODE_FIELD_256=new Le(285,256,0),Le.DATA_MATRIX_FIELD_256=new Le(301,256,1),Le.AZTEC_DATA_8=Le.DATA_MATRIX_FIELD_256,Le.MAXICODE_FIELD_64=Le.AZTEC_DATA_6;class gn extends g{}gn.kind="ReedSolomonException";class Zt extends g{}Zt.kind="IllegalStateException";class En{constructor(e){this.field=e}decode(e,n){const i=this.field,s=new tt(i,e),a=new Int32Array(n);let l=!0;for(let k=0;k<n;k++){const F=s.evaluateAt(i.exp(k+i.getGeneratorBase()));a[a.length-1-k]=F,F!==0&&(l=!1)}if(l)return;const d=new tt(i,a),h=this.runEuclideanAlgorithm(i.buildMonomial(n,1),d,n),m=h[0],y=h[1],b=this.findErrorLocations(m),I=this.findErrorMagnitudes(y,b);for(let k=0;k<b.length;k++){const F=e.length-1-i.log(b[k]);if(F<0)throw new gn("Bad error location");e[F]=Le.addOrSubtract(e[F],I[k])}}runEuclideanAlgorithm(e,n,i){if(e.getDegree()<n.getDegree()){const k=e;e=n,n=k}const s=this.field;let a=e,l=n,d=s.getZero(),h=s.getOne();for(;l.getDegree()>=(i/2|0);){let k=a,F=d;if(a=l,d=h,a.isZero())throw new gn("r_{i-1} was zero");l=k;let U=s.getZero();const G=a.getCoefficient(a.getDegree()),Q=s.inverse(G);for(;l.getDegree()>=a.getDegree()&&!l.isZero();){const fe=l.getDegree()-a.getDegree(),pe=s.multiply(l.getCoefficient(l.getDegree()),Q);U=U.addOrSubtract(s.buildMonomial(fe,pe)),l=l.addOrSubtract(a.multiplyByMonomial(fe,pe))}if(h=U.multiply(d).addOrSubtract(F),l.getDegree()>=a.getDegree())throw new Zt("Division algorithm failed to reduce polynomial?")}const m=h.getCoefficient(0);if(m===0)throw new gn("sigmaTilde(0) was zero");const y=s.inverse(m),b=h.multiplyScalar(y),I=l.multiplyScalar(y);return[b,I]}findErrorLocations(e){const n=e.getDegree();if(n===1)return Int32Array.from([e.getCoefficient(1)]);const i=new Int32Array(n);let s=0;const a=this.field;for(let l=1;l<a.getSize()&&s<n;l++)e.evaluateAt(l)===0&&(i[s]=a.inverse(l),s++);if(s!==n)throw new gn("Error locator degree does not match number of roots");return i}findErrorMagnitudes(e,n){const i=n.length,s=new Int32Array(i),a=this.field;for(let l=0;l<i;l++){const d=a.inverse(n[l]);let h=1;for(let m=0;m<i;m++)if(l!==m){const y=a.multiply(n[m],d),b=(y&1)===0?y|1:y&-2;h=a.multiply(h,b)}s[l]=a.multiply(e.evaluateAt(d),a.inverse(h)),a.getGeneratorBase()!==0&&(s[l]=a.multiply(s[l],d))}return s}}var Et;(function(C){C[C.UPPER=0]="UPPER",C[C.LOWER=1]="LOWER",C[C.MIXED=2]="MIXED",C[C.DIGIT=3]="DIGIT",C[C.PUNCT=4]="PUNCT",C[C.BINARY=5]="BINARY"})(Et||(Et={}));class Xe{decode(e){this.ddata=e;let n=e.getBits(),i=this.extractBits(n),s=this.correctBits(i),a=Xe.convertBoolArrayToByteArray(s),l=Xe.getEncodedData(s),d=new ke(a,l,null,null);return d.setNumBits(s.length),d}static highLevelDecode(e){return this.getEncodedData(e)}static getEncodedData(e){let n=e.length,i=Et.UPPER,s=Et.UPPER,a="",l=0;for(;l<n;)if(s===Et.BINARY){if(n-l<5)break;let d=Xe.readCode(e,l,5);if(l+=5,d===0){if(n-l<11)break;d=Xe.readCode(e,l,11)+31,l+=11}for(let h=0;h<d;h++){if(n-l<8){l=n;break}const m=Xe.readCode(e,l,8);a+=ne.castAsNonUtf8Char(m),l+=8}s=i}else{let d=s===Et.DIGIT?4:5;if(n-l<d)break;let h=Xe.readCode(e,l,d);l+=d;let m=Xe.getCharacter(s,h);m.startsWith("CTRL_")?(i=s,s=Xe.getTable(m.charAt(5)),m.charAt(6)==="L"&&(i=s)):(a+=m,s=i)}return a}static getTable(e){switch(e){case"L":return Et.LOWER;case"P":return Et.PUNCT;case"M":return Et.MIXED;case"D":return Et.DIGIT;case"B":return Et.BINARY;case"U":default:return Et.UPPER}}static getCharacter(e,n){switch(e){case Et.UPPER:return Xe.UPPER_TABLE[n];case Et.LOWER:return Xe.LOWER_TABLE[n];case Et.MIXED:return Xe.MIXED_TABLE[n];case Et.PUNCT:return Xe.PUNCT_TABLE[n];case Et.DIGIT:return Xe.DIGIT_TABLE[n];default:throw new Zt("Bad table")}}correctBits(e){let n,i;this.ddata.getNbLayers()<=2?(i=6,n=Le.AZTEC_DATA_6):this.ddata.getNbLayers()<=8?(i=8,n=Le.AZTEC_DATA_8):this.ddata.getNbLayers()<=22?(i=10,n=Le.AZTEC_DATA_10):(i=12,n=Le.AZTEC_DATA_12);let s=this.ddata.getNbDatablocks(),a=e.length/i;if(a<s)throw new z;let l=e.length%i,d=new Int32Array(a);for(let I=0;I<a;I++,l+=i)d[I]=Xe.readCode(e,l,i);try{new En(n).decode(d,a-s)}catch(I){throw new z(I)}let h=(1<<i)-1,m=0;for(let I=0;I<s;I++){let k=d[I];if(k===0||k===h)throw new z;(k===1||k===h-1)&&m++}let y=new Array(s*i-m),b=0;for(let I=0;I<s;I++){let k=d[I];if(k===1||k===h-1)y.fill(k>1,b,b+i-1),b+=i-1;else for(let F=i-1;F>=0;--F)y[b++]=(k&1<<F)!==0}return y}extractBits(e){let n=this.ddata.isCompact(),i=this.ddata.getNbLayers(),s=(n?11:14)+i*4,a=new Int32Array(s),l=new Array(this.totalBitsInLayer(i,n));if(n)for(let d=0;d<a.length;d++)a[d]=d;else{let d=s+1+2*$.truncDivision($.truncDivision(s,2)-1,15),h=s/2,m=$.truncDivision(d,2);for(let y=0;y<h;y++){let b=y+$.truncDivision(y,15);a[h-y-1]=m-b-1,a[h+y]=m+b+1}}for(let d=0,h=0;d<i;d++){let m=(i-d)*4+(n?9:12),y=d*2,b=s-1-y;for(let I=0;I<m;I++){let k=I*2;for(let F=0;F<2;F++)l[h+k+F]=e.get(a[y+F],a[y+I]),l[h+2*m+k+F]=e.get(a[y+I],a[b-F]),l[h+4*m+k+F]=e.get(a[b-F],a[b-I]),l[h+6*m+k+F]=e.get(a[b-I],a[y+F])}h+=m*8}return l}static readCode(e,n,i){let s=0;for(let a=n;a<n+i;a++)s<<=1,e[a]&&(s|=1);return s}static readByte(e,n){let i=e.length-n;return i>=8?Xe.readCode(e,n,8):Xe.readCode(e,n,i)<<8-i}static convertBoolArrayToByteArray(e){let n=new Uint8Array((e.length+7)/8);for(let i=0;i<n.length;i++)n[i]=Xe.readByte(e,8*i);return n}totalBitsInLayer(e,n){return((n?88:112)+16*e)*e}}Xe.UPPER_TABLE=["CTRL_PS"," ","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","CTRL_LL","CTRL_ML","CTRL_DL","CTRL_BS"],Xe.LOWER_TABLE=["CTRL_PS"," ","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","CTRL_US","CTRL_ML","CTRL_DL","CTRL_BS"],Xe.MIXED_TABLE=["CTRL_PS"," ","\\1","\\2","\\3","\\4","\\5","\\6","\\7","\b"," ",`
61
+ `,"\\13","\f","\r","\\33","\\34","\\35","\\36","\\37","@","\\","^","_","`","|","~","\\177","CTRL_LL","CTRL_UL","CTRL_PL","CTRL_BS"],Xe.PUNCT_TABLE=["","\r",`\r
62
+ `,". ",", ",": ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/",":",";","<","=",">","?","[","]","{","}","CTRL_UL"],Xe.DIGIT_TABLE=["CTRL_PS"," ","0","1","2","3","4","5","6","7","8","9",",",".","CTRL_UL","CTRL_US"];class Ze{constructor(){}static round(e){return e===NaN?0:e<=Number.MIN_SAFE_INTEGER?Number.MIN_SAFE_INTEGER:e>=Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:e+(e<0?-.5:.5)|0}static distance(e,n,i,s){const a=e-i,l=n-s;return Math.sqrt(a*a+l*l)}static sum(e){let n=0;for(let i=0,s=e.length;i!==s;i++){const a=e[i];n+=a}return n}}class dn{static floatToIntBits(e){return e}}dn.MAX_VALUE=Number.MAX_SAFE_INTEGER;class N{constructor(e,n){this.x=e,this.y=n}getX(){return this.x}getY(){return this.y}equals(e){if(e instanceof N){const n=e;return this.x===n.x&&this.y===n.y}return!1}hashCode(){return 31*dn.floatToIntBits(this.x)+dn.floatToIntBits(this.y)}toString(){return"("+this.x+","+this.y+")"}static orderBestPatterns(e){const n=this.distance(e[0],e[1]),i=this.distance(e[1],e[2]),s=this.distance(e[0],e[2]);let a,l,d;if(i>=n&&i>=s?(l=e[0],a=e[1],d=e[2]):s>=i&&s>=n?(l=e[1],a=e[0],d=e[2]):(l=e[2],a=e[0],d=e[1]),this.crossProductZ(a,l,d)<0){const h=a;a=d,d=h}e[0]=a,e[1]=l,e[2]=d}static distance(e,n){return Ze.distance(e.x,e.y,n.x,n.y)}static crossProductZ(e,n,i){const s=n.x,a=n.y;return(i.x-s)*(e.y-a)-(i.y-a)*(e.x-s)}}class ye{constructor(e,n){this.bits=e,this.points=n}getBits(){return this.bits}getPoints(){return this.points}}class wt extends ye{constructor(e,n,i,s,a){super(e,n),this.compact=i,this.nbDatablocks=s,this.nbLayers=a}getNbLayers(){return this.nbLayers}getNbDatablocks(){return this.nbDatablocks}isCompact(){return this.compact}}class _t{constructor(e,n,i,s){this.image=e,this.height=e.getHeight(),this.width=e.getWidth(),n==null&&(n=_t.INIT_SIZE),i==null&&(i=e.getWidth()/2|0),s==null&&(s=e.getHeight()/2|0);const a=n/2|0;if(this.leftInit=i-a,this.rightInit=i+a,this.upInit=s-a,this.downInit=s+a,this.upInit<0||this.leftInit<0||this.downInit>=this.height||this.rightInit>=this.width)throw new O}detect(){let e=this.leftInit,n=this.rightInit,i=this.upInit,s=this.downInit,a=!1,l=!0,d=!1,h=!1,m=!1,y=!1,b=!1;const I=this.width,k=this.height;for(;l;){l=!1;let F=!0;for(;(F||!h)&&n<I;)F=this.containsBlackPoint(i,s,n,!1),F?(n++,l=!0,h=!0):h||n++;if(n>=I){a=!0;break}let U=!0;for(;(U||!m)&&s<k;)U=this.containsBlackPoint(e,n,s,!0),U?(s++,l=!0,m=!0):m||s++;if(s>=k){a=!0;break}let G=!0;for(;(G||!y)&&e>=0;)G=this.containsBlackPoint(i,s,e,!1),G?(e--,l=!0,y=!0):y||e--;if(e<0){a=!0;break}let Q=!0;for(;(Q||!b)&&i>=0;)Q=this.containsBlackPoint(e,n,i,!0),Q?(i--,l=!0,b=!0):b||i--;if(i<0){a=!0;break}l&&(d=!0)}if(!a&&d){const F=n-e;let U=null;for(let pe=1;U===null&&pe<F;pe++)U=this.getBlackPointOnSegment(e,s-pe,e+pe,s);if(U==null)throw new O;let G=null;for(let pe=1;G===null&&pe<F;pe++)G=this.getBlackPointOnSegment(e,i+pe,e+pe,i);if(G==null)throw new O;let Q=null;for(let pe=1;Q===null&&pe<F;pe++)Q=this.getBlackPointOnSegment(n,i+pe,n-pe,i);if(Q==null)throw new O;let fe=null;for(let pe=1;fe===null&&pe<F;pe++)fe=this.getBlackPointOnSegment(n,s-pe,n-pe,s);if(fe==null)throw new O;return this.centerEdges(fe,U,Q,G)}else throw new O}getBlackPointOnSegment(e,n,i,s){const a=Ze.round(Ze.distance(e,n,i,s)),l=(i-e)/a,d=(s-n)/a,h=this.image;for(let m=0;m<a;m++){const y=Ze.round(e+m*l),b=Ze.round(n+m*d);if(h.get(y,b))return new N(y,b)}return null}centerEdges(e,n,i,s){const a=e.getX(),l=e.getY(),d=n.getX(),h=n.getY(),m=i.getX(),y=i.getY(),b=s.getX(),I=s.getY(),k=_t.CORR;return a<this.width/2?[new N(b-k,I+k),new N(d+k,h+k),new N(m-k,y-k),new N(a+k,l-k)]:[new N(b+k,I+k),new N(d+k,h-k),new N(m-k,y+k),new N(a-k,l-k)]}containsBlackPoint(e,n,i,s){const a=this.image;if(s){for(let l=e;l<=n;l++)if(a.get(l,i))return!0}else for(let l=e;l<=n;l++)if(a.get(i,l))return!0;return!1}}_t.INIT_SIZE=10,_t.CORR=1;class Un{static checkAndNudgePoints(e,n){const i=e.getWidth(),s=e.getHeight();let a=!0;for(let l=0;l<n.length&&a;l+=2){const d=Math.floor(n[l]),h=Math.floor(n[l+1]);if(d<-1||d>i||h<-1||h>s)throw new O;a=!1,d===-1?(n[l]=0,a=!0):d===i&&(n[l]=i-1,a=!0),h===-1?(n[l+1]=0,a=!0):h===s&&(n[l+1]=s-1,a=!0)}a=!0;for(let l=n.length-2;l>=0&&a;l-=2){const d=Math.floor(n[l]),h=Math.floor(n[l+1]);if(d<-1||d>i||h<-1||h>s)throw new O;a=!1,d===-1?(n[l]=0,a=!0):d===i&&(n[l]=i-1,a=!0),h===-1?(n[l+1]=0,a=!0):h===s&&(n[l+1]=s-1,a=!0)}}}class rn{constructor(e,n,i,s,a,l,d,h,m){this.a11=e,this.a21=n,this.a31=i,this.a12=s,this.a22=a,this.a32=l,this.a13=d,this.a23=h,this.a33=m}static quadrilateralToQuadrilateral(e,n,i,s,a,l,d,h,m,y,b,I,k,F,U,G){const Q=rn.quadrilateralToSquare(e,n,i,s,a,l,d,h);return rn.squareToQuadrilateral(m,y,b,I,k,F,U,G).times(Q)}transformPoints(e){const n=e.length,i=this.a11,s=this.a12,a=this.a13,l=this.a21,d=this.a22,h=this.a23,m=this.a31,y=this.a32,b=this.a33;for(let I=0;I<n;I+=2){const k=e[I],F=e[I+1],U=a*k+h*F+b;e[I]=(i*k+l*F+m)/U,e[I+1]=(s*k+d*F+y)/U}}transformPointsWithValues(e,n){const i=this.a11,s=this.a12,a=this.a13,l=this.a21,d=this.a22,h=this.a23,m=this.a31,y=this.a32,b=this.a33,I=e.length;for(let k=0;k<I;k++){const F=e[k],U=n[k],G=a*F+h*U+b;e[k]=(i*F+l*U+m)/G,n[k]=(s*F+d*U+y)/G}}static squareToQuadrilateral(e,n,i,s,a,l,d,h){const m=e-i+a-d,y=n-s+l-h;if(m===0&&y===0)return new rn(i-e,a-i,e,s-n,l-s,n,0,0,1);{const b=i-a,I=d-a,k=s-l,F=h-l,U=b*F-I*k,G=(m*F-I*y)/U,Q=(b*y-m*k)/U;return new rn(i-e+G*i,d-e+Q*d,e,s-n+G*s,h-n+Q*h,n,G,Q,1)}}static quadrilateralToSquare(e,n,i,s,a,l,d,h){return rn.squareToQuadrilateral(e,n,i,s,a,l,d,h).buildAdjoint()}buildAdjoint(){return new rn(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(e){return new rn(this.a11*e.a11+this.a21*e.a12+this.a31*e.a13,this.a11*e.a21+this.a21*e.a22+this.a31*e.a23,this.a11*e.a31+this.a21*e.a32+this.a31*e.a33,this.a12*e.a11+this.a22*e.a12+this.a32*e.a13,this.a12*e.a21+this.a22*e.a22+this.a32*e.a23,this.a12*e.a31+this.a22*e.a32+this.a32*e.a33,this.a13*e.a11+this.a23*e.a12+this.a33*e.a13,this.a13*e.a21+this.a23*e.a22+this.a33*e.a23,this.a13*e.a31+this.a23*e.a32+this.a33*e.a33)}}class ai extends Un{sampleGrid(e,n,i,s,a,l,d,h,m,y,b,I,k,F,U,G,Q,fe,pe){const de=rn.quadrilateralToQuadrilateral(s,a,l,d,h,m,y,b,I,k,F,U,G,Q,fe,pe);return this.sampleGridWithTransform(e,n,i,de)}sampleGridWithTransform(e,n,i,s){if(n<=0||i<=0)throw new O;const a=new te(n,i),l=new Float32Array(2*n);for(let d=0;d<i;d++){const h=l.length,m=d+.5;for(let y=0;y<h;y+=2)l[y]=y/2+.5,l[y+1]=m;s.transformPoints(l),Un.checkAndNudgePoints(e,l);try{for(let y=0;y<h;y+=2)e.get(Math.floor(l[y]),Math.floor(l[y+1]))&&a.set(y/2,d)}catch{throw new O}}return a}}class An{static setGridSampler(e){An.gridSampler=e}static getInstance(){return An.gridSampler}}An.gridSampler=new ai;class Ut{constructor(e,n){this.x=e,this.y=n}toResultPoint(){return new N(this.getX(),this.getY())}getX(){return this.x}getY(){return this.y}}class li{constructor(e){this.EXPECTED_CORNER_BITS=new Int32Array([3808,476,2107,1799]),this.image=e}detect(){return this.detectMirror(!1)}detectMirror(e){let n=this.getMatrixCenter(),i=this.getBullsEyeCorners(n);if(e){let l=i[0];i[0]=i[2],i[2]=l}this.extractParameters(i);let s=this.sampleGrid(this.image,i[this.shift%4],i[(this.shift+1)%4],i[(this.shift+2)%4],i[(this.shift+3)%4]),a=this.getMatrixCornerPoints(i);return new wt(s,a,this.compact,this.nbDataBlocks,this.nbLayers)}extractParameters(e){if(!this.isValidPoint(e[0])||!this.isValidPoint(e[1])||!this.isValidPoint(e[2])||!this.isValidPoint(e[3]))throw new O;let n=2*this.nbCenterLayers,i=new Int32Array([this.sampleLine(e[0],e[1],n),this.sampleLine(e[1],e[2],n),this.sampleLine(e[2],e[3],n),this.sampleLine(e[3],e[0],n)]);this.shift=this.getRotation(i,n);let s=0;for(let l=0;l<4;l++){let d=i[(this.shift+l)%4];this.compact?(s<<=7,s+=d>>1&127):(s<<=10,s+=(d>>2&992)+(d>>1&31))}let a=this.getCorrectedParameterData(s,this.compact);this.compact?(this.nbLayers=(a>>6)+1,this.nbDataBlocks=(a&63)+1):(this.nbLayers=(a>>11)+1,this.nbDataBlocks=(a&2047)+1)}getRotation(e,n){let i=0;e.forEach((s,a,l)=>{let d=(s>>n-2<<1)+(s&1);i=(i<<3)+d}),i=((i&1)<<11)+(i>>1);for(let s=0;s<4;s++)if($.bitCount(i^this.EXPECTED_CORNER_BITS[s])<=2)return s;throw new O}getCorrectedParameterData(e,n){let i,s;n?(i=7,s=2):(i=10,s=4);let a=i-s,l=new Int32Array(i);for(let h=i-1;h>=0;--h)l[h]=e&15,e>>=4;try{new En(Le.AZTEC_PARAM).decode(l,a)}catch{throw new O}let d=0;for(let h=0;h<s;h++)d=(d<<4)+l[h];return d}getBullsEyeCorners(e){let n=e,i=e,s=e,a=e,l=!0;for(this.nbCenterLayers=1;this.nbCenterLayers<9;this.nbCenterLayers++){let b=this.getFirstDifferent(n,l,1,-1),I=this.getFirstDifferent(i,l,1,1),k=this.getFirstDifferent(s,l,-1,1),F=this.getFirstDifferent(a,l,-1,-1);if(this.nbCenterLayers>2){let U=this.distancePoint(F,b)*this.nbCenterLayers/(this.distancePoint(a,n)*(this.nbCenterLayers+2));if(U<.75||U>1.25||!this.isWhiteOrBlackRectangle(b,I,k,F))break}n=b,i=I,s=k,a=F,l=!l}if(this.nbCenterLayers!==5&&this.nbCenterLayers!==7)throw new O;this.compact=this.nbCenterLayers===5;let d=new N(n.getX()+.5,n.getY()-.5),h=new N(i.getX()+.5,i.getY()+.5),m=new N(s.getX()-.5,s.getY()+.5),y=new N(a.getX()-.5,a.getY()-.5);return this.expandSquare([d,h,m,y],2*this.nbCenterLayers-3,2*this.nbCenterLayers)}getMatrixCenter(){let e,n,i,s;try{let d=new _t(this.image).detect();e=d[0],n=d[1],i=d[2],s=d[3]}catch{let h=this.image.getWidth()/2,m=this.image.getHeight()/2;e=this.getFirstDifferent(new Ut(h+7,m-7),!1,1,-1).toResultPoint(),n=this.getFirstDifferent(new Ut(h+7,m+7),!1,1,1).toResultPoint(),i=this.getFirstDifferent(new Ut(h-7,m+7),!1,-1,1).toResultPoint(),s=this.getFirstDifferent(new Ut(h-7,m-7),!1,-1,-1).toResultPoint()}let a=Ze.round((e.getX()+s.getX()+n.getX()+i.getX())/4),l=Ze.round((e.getY()+s.getY()+n.getY()+i.getY())/4);try{let d=new _t(this.image,15,a,l).detect();e=d[0],n=d[1],i=d[2],s=d[3]}catch{e=this.getFirstDifferent(new Ut(a+7,l-7),!1,1,-1).toResultPoint(),n=this.getFirstDifferent(new Ut(a+7,l+7),!1,1,1).toResultPoint(),i=this.getFirstDifferent(new Ut(a-7,l+7),!1,-1,1).toResultPoint(),s=this.getFirstDifferent(new Ut(a-7,l-7),!1,-1,-1).toResultPoint()}return a=Ze.round((e.getX()+s.getX()+n.getX()+i.getX())/4),l=Ze.round((e.getY()+s.getY()+n.getY()+i.getY())/4),new Ut(a,l)}getMatrixCornerPoints(e){return this.expandSquare(e,2*this.nbCenterLayers,this.getDimension())}sampleGrid(e,n,i,s,a){let l=An.getInstance(),d=this.getDimension(),h=d/2-this.nbCenterLayers,m=d/2+this.nbCenterLayers;return l.sampleGrid(e,d,d,h,h,m,h,m,m,h,m,n.getX(),n.getY(),i.getX(),i.getY(),s.getX(),s.getY(),a.getX(),a.getY())}sampleLine(e,n,i){let s=0,a=this.distanceResultPoint(e,n),l=a/i,d=e.getX(),h=e.getY(),m=l*(n.getX()-e.getX())/a,y=l*(n.getY()-e.getY())/a;for(let b=0;b<i;b++)this.image.get(Ze.round(d+b*m),Ze.round(h+b*y))&&(s|=1<<i-b-1);return s}isWhiteOrBlackRectangle(e,n,i,s){let a=3;e=new Ut(e.getX()-a,e.getY()+a),n=new Ut(n.getX()-a,n.getY()-a),i=new Ut(i.getX()+a,i.getY()-a),s=new Ut(s.getX()+a,s.getY()+a);let l=this.getColor(s,e);if(l===0)return!1;let d=this.getColor(e,n);return d!==l||(d=this.getColor(n,i),d!==l)?!1:(d=this.getColor(i,s),d===l)}getColor(e,n){let i=this.distancePoint(e,n),s=(n.getX()-e.getX())/i,a=(n.getY()-e.getY())/i,l=0,d=e.getX(),h=e.getY(),m=this.image.get(e.getX(),e.getY()),y=Math.ceil(i);for(let I=0;I<y;I++)d+=s,h+=a,this.image.get(Ze.round(d),Ze.round(h))!==m&&l++;let b=l/i;return b>.1&&b<.9?0:b<=.1===m?1:-1}getFirstDifferent(e,n,i,s){let a=e.getX()+i,l=e.getY()+s;for(;this.isValid(a,l)&&this.image.get(a,l)===n;)a+=i,l+=s;for(a-=i,l-=s;this.isValid(a,l)&&this.image.get(a,l)===n;)a+=i;for(a-=i;this.isValid(a,l)&&this.image.get(a,l)===n;)l+=s;return l-=s,new Ut(a,l)}expandSquare(e,n,i){let s=i/(2*n),a=e[0].getX()-e[2].getX(),l=e[0].getY()-e[2].getY(),d=(e[0].getX()+e[2].getX())/2,h=(e[0].getY()+e[2].getY())/2,m=new N(d+s*a,h+s*l),y=new N(d-s*a,h-s*l);a=e[1].getX()-e[3].getX(),l=e[1].getY()-e[3].getY(),d=(e[1].getX()+e[3].getX())/2,h=(e[1].getY()+e[3].getY())/2;let b=new N(d+s*a,h+s*l),I=new N(d-s*a,h-s*l);return[m,b,y,I]}isValid(e,n){return e>=0&&e<this.image.getWidth()&&n>0&&n<this.image.getHeight()}isValidPoint(e){let n=Ze.round(e.getX()),i=Ze.round(e.getY());return this.isValid(n,i)}distancePoint(e,n){return Ze.distance(e.getX(),e.getY(),n.getX(),n.getY())}distanceResultPoint(e,n){return Ze.distance(e.getX(),e.getY(),n.getX(),n.getY())}getDimension(){return this.compact?4*this.nbLayers+11:this.nbLayers<=4?4*this.nbLayers+15:4*this.nbLayers+2*($.truncDivision(this.nbLayers-4,8)+1)+15}}class rt{decode(e,n=null){let i=null,s=new li(e.getBlackMatrix()),a=null,l=null;try{let y=s.detectMirror(!1);a=y.getPoints(),this.reportFoundResultPoints(n,a),l=new Xe().decode(y)}catch(y){i=y}if(l==null)try{let y=s.detectMirror(!0);a=y.getPoints(),this.reportFoundResultPoints(n,a),l=new Xe().decode(y)}catch(y){throw i??y}let d=new Be(l.getText(),l.getRawBytes(),l.getNumBits(),a,ie.AZTEC,R.currentTimeMillis()),h=l.getByteSegments();h!=null&&d.putMetadata(Me.BYTE_SEGMENTS,h);let m=l.getECLevel();return m!=null&&d.putMetadata(Me.ERROR_CORRECTION_LEVEL,m),d}reportFoundResultPoints(e,n){if(e!=null){let i=e.get(j.NEED_RESULT_POINT_CALLBACK);i!=null&&n.forEach((s,a,l)=>{i.foundPossibleResultPoint(s)})}}reset(){}}class Oe extends je{constructor(e=500){super(new rt,e)}}class Te{decode(e,n){try{return this.doDecode(e,n)}catch{if(n&&n.get(j.TRY_HARDER)===!0&&e.isRotateSupported()){const a=e.rotateCounterClockwise(),l=this.doDecode(a,n),d=l.getResultMetadata();let h=270;d!==null&&d.get(Me.ORIENTATION)===!0&&(h=h+d.get(Me.ORIENTATION)%360),l.putMetadata(Me.ORIENTATION,h);const m=l.getResultPoints();if(m!==null){const y=a.getHeight();for(let b=0;b<m.length;b++)m[b]=new N(y-m[b].getY()-1,m[b].getX())}return l}else throw new O}}reset(){}doDecode(e,n){const i=e.getWidth(),s=e.getHeight();let a=new V(i);const l=n&&n.get(j.TRY_HARDER)===!0,d=Math.max(1,s>>(l?8:5));let h;l?h=s:h=15;const m=Math.trunc(s/2);for(let y=0;y<h;y++){const b=Math.trunc((y+1)/2),I=(y&1)===0,k=m+d*(I?b:-b);if(k<0||k>=s)break;try{a=e.getBlackRow(k,a)}catch{continue}for(let F=0;F<2;F++){if(F===1&&(a.reverse(),n&&n.get(j.NEED_RESULT_POINT_CALLBACK)===!0)){const U=new Map;n.forEach((G,Q)=>U.set(Q,G)),U.delete(j.NEED_RESULT_POINT_CALLBACK),n=U}try{const U=this.decodeRow(k,a,n);if(F===1){U.putMetadata(Me.ORIENTATION,180);const G=U.getResultPoints();G!==null&&(G[0]=new N(i-G[0].getX()-1,G[0].getY()),G[1]=new N(i-G[1].getX()-1,G[1].getY()))}return U}catch{}}}throw new O}static recordPattern(e,n,i){const s=i.length;for(let m=0;m<s;m++)i[m]=0;const a=e.getSize();if(n>=a)throw new O;let l=!e.get(n),d=0,h=n;for(;h<a;){if(e.get(h)!==l)i[d]++;else{if(++d===s)break;i[d]=1,l=!l}h++}if(!(d===s||d===s-1&&h===a))throw new O}static recordPatternInReverse(e,n,i){let s=i.length,a=e.get(n);for(;n>0&&s>=0;)e.get(--n)!==a&&(s--,a=!a);if(s>=0)throw new O;Te.recordPattern(e,n+1,i)}static patternMatchVariance(e,n,i){const s=e.length;let a=0,l=0;for(let m=0;m<s;m++)a+=e[m],l+=n[m];if(a<l)return Number.POSITIVE_INFINITY;const d=a/l;i*=d;let h=0;for(let m=0;m<s;m++){const y=e[m],b=n[m]*d,I=y>b?y-b:b-y;if(I>i)return Number.POSITIVE_INFINITY;h+=I}return h/a}}class xe extends Te{static findStartPattern(e){const n=e.getSize(),i=e.getNextSet(0);let s=0,a=Int32Array.from([0,0,0,0,0,0]),l=i,d=!1;const h=6;for(let m=i;m<n;m++)if(e.get(m)!==d)a[s]++;else{if(s===h-1){let y=xe.MAX_AVG_VARIANCE,b=-1;for(let I=xe.CODE_START_A;I<=xe.CODE_START_C;I++){const k=Te.patternMatchVariance(a,xe.CODE_PATTERNS[I],xe.MAX_INDIVIDUAL_VARIANCE);k<y&&(y=k,b=I)}if(b>=0&&e.isRange(Math.max(0,l-(m-l)/2),l,!1))return Int32Array.from([l,m,b]);l+=a[0]+a[1],a=a.slice(2,a.length-1),a[s-1]=0,a[s]=0,s--}else s++;a[s]=1,d=!d}throw new O}static decodeCode(e,n,i){Te.recordPattern(e,i,n);let s=xe.MAX_AVG_VARIANCE,a=-1;for(let l=0;l<xe.CODE_PATTERNS.length;l++){const d=xe.CODE_PATTERNS[l],h=this.patternMatchVariance(n,d,xe.MAX_INDIVIDUAL_VARIANCE);h<s&&(s=h,a=l)}if(a>=0)return a;throw new O}decodeRow(e,n,i){const s=i&&i.get(j.ASSUME_GS1)===!0,a=xe.findStartPattern(n),l=a[2];let d=0;const h=new Uint8Array(20);h[d++]=l;let m;switch(l){case xe.CODE_START_A:m=xe.CODE_CODE_A;break;case xe.CODE_START_B:m=xe.CODE_CODE_B;break;case xe.CODE_START_C:m=xe.CODE_CODE_C;break;default:throw new z}let y=!1,b=!1,I="",k=a[0],F=a[1];const U=Int32Array.from([0,0,0,0,0,0]);let G=0,Q=0,fe=l,pe=0,de=!0,He=!1,De=!1;for(;!y;){const br=b;switch(b=!1,G=Q,Q=xe.decodeCode(n,U,F),h[d++]=Q,Q!==xe.CODE_STOP&&(de=!0),Q!==xe.CODE_STOP&&(pe++,fe+=pe*Q),k=F,F+=U.reduce((vd,Cd)=>vd+Cd,0),Q){case xe.CODE_START_A:case xe.CODE_START_B:case xe.CODE_START_C:throw new z}switch(m){case xe.CODE_CODE_A:if(Q<64)De===He?I+=String.fromCharCode(32+Q):I+=String.fromCharCode(32+Q+128),De=!1;else if(Q<96)De===He?I+=String.fromCharCode(Q-64):I+=String.fromCharCode(Q+64),De=!1;else switch(Q!==xe.CODE_STOP&&(de=!1),Q){case xe.CODE_FNC_1:s&&(I.length===0?I+="]C1":I+="");break;case xe.CODE_FNC_2:case xe.CODE_FNC_3:break;case xe.CODE_FNC_4_A:!He&&De?(He=!0,De=!1):He&&De?(He=!1,De=!1):De=!0;break;case xe.CODE_SHIFT:b=!0,m=xe.CODE_CODE_B;break;case xe.CODE_CODE_B:m=xe.CODE_CODE_B;break;case xe.CODE_CODE_C:m=xe.CODE_CODE_C;break;case xe.CODE_STOP:y=!0;break}break;case xe.CODE_CODE_B:if(Q<96)De===He?I+=String.fromCharCode(32+Q):I+=String.fromCharCode(32+Q+128),De=!1;else switch(Q!==xe.CODE_STOP&&(de=!1),Q){case xe.CODE_FNC_1:s&&(I.length===0?I+="]C1":I+="");break;case xe.CODE_FNC_2:case xe.CODE_FNC_3:break;case xe.CODE_FNC_4_B:!He&&De?(He=!0,De=!1):He&&De?(He=!1,De=!1):De=!0;break;case xe.CODE_SHIFT:b=!0,m=xe.CODE_CODE_A;break;case xe.CODE_CODE_A:m=xe.CODE_CODE_A;break;case xe.CODE_CODE_C:m=xe.CODE_CODE_C;break;case xe.CODE_STOP:y=!0;break}break;case xe.CODE_CODE_C:if(Q<100)Q<10&&(I+="0"),I+=Q;else switch(Q!==xe.CODE_STOP&&(de=!1),Q){case xe.CODE_FNC_1:s&&(I.length===0?I+="]C1":I+="");break;case xe.CODE_CODE_A:m=xe.CODE_CODE_A;break;case xe.CODE_CODE_B:m=xe.CODE_CODE_B;break;case xe.CODE_STOP:y=!0;break}break}br&&(m=m===xe.CODE_CODE_A?xe.CODE_CODE_B:xe.CODE_CODE_A)}const en=F-k;if(F=n.getNextUnset(F),!n.isRange(F,Math.min(n.getSize(),F+(F-k)/2),!1))throw new O;if(fe-=pe*G,fe%103!==G)throw new M;const yn=I.length;if(yn===0)throw new O;yn>0&&de&&(m===xe.CODE_CODE_C?I=I.substring(0,yn-2):I=I.substring(0,yn-1));const tn=(a[1]+a[0])/2,at=k+en/2,$t=h.length,on=new Uint8Array($t);for(let br=0;br<$t;br++)on[br]=h[br];const Cr=[new N(tn,e),new N(at,e)];return new Be(I,on,0,Cr,ie.CODE_128,new Date().getTime())}}xe.CODE_PATTERNS=[Int32Array.from([2,1,2,2,2,2]),Int32Array.from([2,2,2,1,2,2]),Int32Array.from([2,2,2,2,2,1]),Int32Array.from([1,2,1,2,2,3]),Int32Array.from([1,2,1,3,2,2]),Int32Array.from([1,3,1,2,2,2]),Int32Array.from([1,2,2,2,1,3]),Int32Array.from([1,2,2,3,1,2]),Int32Array.from([1,3,2,2,1,2]),Int32Array.from([2,2,1,2,1,3]),Int32Array.from([2,2,1,3,1,2]),Int32Array.from([2,3,1,2,1,2]),Int32Array.from([1,1,2,2,3,2]),Int32Array.from([1,2,2,1,3,2]),Int32Array.from([1,2,2,2,3,1]),Int32Array.from([1,1,3,2,2,2]),Int32Array.from([1,2,3,1,2,2]),Int32Array.from([1,2,3,2,2,1]),Int32Array.from([2,2,3,2,1,1]),Int32Array.from([2,2,1,1,3,2]),Int32Array.from([2,2,1,2,3,1]),Int32Array.from([2,1,3,2,1,2]),Int32Array.from([2,2,3,1,1,2]),Int32Array.from([3,1,2,1,3,1]),Int32Array.from([3,1,1,2,2,2]),Int32Array.from([3,2,1,1,2,2]),Int32Array.from([3,2,1,2,2,1]),Int32Array.from([3,1,2,2,1,2]),Int32Array.from([3,2,2,1,1,2]),Int32Array.from([3,2,2,2,1,1]),Int32Array.from([2,1,2,1,2,3]),Int32Array.from([2,1,2,3,2,1]),Int32Array.from([2,3,2,1,2,1]),Int32Array.from([1,1,1,3,2,3]),Int32Array.from([1,3,1,1,2,3]),Int32Array.from([1,3,1,3,2,1]),Int32Array.from([1,1,2,3,1,3]),Int32Array.from([1,3,2,1,1,3]),Int32Array.from([1,3,2,3,1,1]),Int32Array.from([2,1,1,3,1,3]),Int32Array.from([2,3,1,1,1,3]),Int32Array.from([2,3,1,3,1,1]),Int32Array.from([1,1,2,1,3,3]),Int32Array.from([1,1,2,3,3,1]),Int32Array.from([1,3,2,1,3,1]),Int32Array.from([1,1,3,1,2,3]),Int32Array.from([1,1,3,3,2,1]),Int32Array.from([1,3,3,1,2,1]),Int32Array.from([3,1,3,1,2,1]),Int32Array.from([2,1,1,3,3,1]),Int32Array.from([2,3,1,1,3,1]),Int32Array.from([2,1,3,1,1,3]),Int32Array.from([2,1,3,3,1,1]),Int32Array.from([2,1,3,1,3,1]),Int32Array.from([3,1,1,1,2,3]),Int32Array.from([3,1,1,3,2,1]),Int32Array.from([3,3,1,1,2,1]),Int32Array.from([3,1,2,1,1,3]),Int32Array.from([3,1,2,3,1,1]),Int32Array.from([3,3,2,1,1,1]),Int32Array.from([3,1,4,1,1,1]),Int32Array.from([2,2,1,4,1,1]),Int32Array.from([4,3,1,1,1,1]),Int32Array.from([1,1,1,2,2,4]),Int32Array.from([1,1,1,4,2,2]),Int32Array.from([1,2,1,1,2,4]),Int32Array.from([1,2,1,4,2,1]),Int32Array.from([1,4,1,1,2,2]),Int32Array.from([1,4,1,2,2,1]),Int32Array.from([1,1,2,2,1,4]),Int32Array.from([1,1,2,4,1,2]),Int32Array.from([1,2,2,1,1,4]),Int32Array.from([1,2,2,4,1,1]),Int32Array.from([1,4,2,1,1,2]),Int32Array.from([1,4,2,2,1,1]),Int32Array.from([2,4,1,2,1,1]),Int32Array.from([2,2,1,1,1,4]),Int32Array.from([4,1,3,1,1,1]),Int32Array.from([2,4,1,1,1,2]),Int32Array.from([1,3,4,1,1,1]),Int32Array.from([1,1,1,2,4,2]),Int32Array.from([1,2,1,1,4,2]),Int32Array.from([1,2,1,2,4,1]),Int32Array.from([1,1,4,2,1,2]),Int32Array.from([1,2,4,1,1,2]),Int32Array.from([1,2,4,2,1,1]),Int32Array.from([4,1,1,2,1,2]),Int32Array.from([4,2,1,1,1,2]),Int32Array.from([4,2,1,2,1,1]),Int32Array.from([2,1,2,1,4,1]),Int32Array.from([2,1,4,1,2,1]),Int32Array.from([4,1,2,1,2,1]),Int32Array.from([1,1,1,1,4,3]),Int32Array.from([1,1,1,3,4,1]),Int32Array.from([1,3,1,1,4,1]),Int32Array.from([1,1,4,1,1,3]),Int32Array.from([1,1,4,3,1,1]),Int32Array.from([4,1,1,1,1,3]),Int32Array.from([4,1,1,3,1,1]),Int32Array.from([1,1,3,1,4,1]),Int32Array.from([1,1,4,1,3,1]),Int32Array.from([3,1,1,1,4,1]),Int32Array.from([4,1,1,1,3,1]),Int32Array.from([2,1,1,4,1,2]),Int32Array.from([2,1,1,2,1,4]),Int32Array.from([2,1,1,2,3,2]),Int32Array.from([2,3,3,1,1,1,2])],xe.MAX_AVG_VARIANCE=.25,xe.MAX_INDIVIDUAL_VARIANCE=.7,xe.CODE_SHIFT=98,xe.CODE_CODE_C=99,xe.CODE_CODE_B=100,xe.CODE_CODE_A=101,xe.CODE_FNC_1=102,xe.CODE_FNC_2=97,xe.CODE_FNC_3=96,xe.CODE_FNC_4_A=101,xe.CODE_FNC_4_B=100,xe.CODE_START_A=103,xe.CODE_START_B=104,xe.CODE_START_C=105,xe.CODE_STOP=106;class Ot extends Te{constructor(e=!1,n=!1){super(),this.usingCheckDigit=e,this.extendedMode=n,this.decodeRowResult="",this.counters=new Int32Array(9)}decodeRow(e,n,i){let s=this.counters;s.fill(0),this.decodeRowResult="";let a=Ot.findAsteriskPattern(n,s),l=n.getNextSet(a[1]),d=n.getSize(),h,m;do{Ot.recordPattern(n,l,s);let U=Ot.toNarrowWidePattern(s);if(U<0)throw new O;h=Ot.patternToChar(U),this.decodeRowResult+=h,m=l;for(let G of s)l+=G;l=n.getNextSet(l)}while(h!=="*");this.decodeRowResult=this.decodeRowResult.substring(0,this.decodeRowResult.length-1);let y=0;for(let U of s)y+=U;let b=l-m-y;if(l!==d&&b*2<y)throw new O;if(this.usingCheckDigit){let U=this.decodeRowResult.length-1,G=0;for(let Q=0;Q<U;Q++)G+=Ot.ALPHABET_STRING.indexOf(this.decodeRowResult.charAt(Q));if(this.decodeRowResult.charAt(U)!==Ot.ALPHABET_STRING.charAt(G%43))throw new M;this.decodeRowResult=this.decodeRowResult.substring(0,U)}if(this.decodeRowResult.length===0)throw new O;let I;this.extendedMode?I=Ot.decodeExtended(this.decodeRowResult):I=this.decodeRowResult;let k=(a[1]+a[0])/2,F=m+y/2;return new Be(I,null,0,[new N(k,e),new N(F,e)],ie.CODE_39,new Date().getTime())}static findAsteriskPattern(e,n){let i=e.getSize(),s=e.getNextSet(0),a=0,l=s,d=!1,h=n.length;for(let m=s;m<i;m++)if(e.get(m)!==d)n[a]++;else{if(a===h-1){if(this.toNarrowWidePattern(n)===Ot.ASTERISK_ENCODING&&e.isRange(Math.max(0,l-Math.floor((m-l)/2)),l,!1))return[l,m];l+=n[0]+n[1],n.copyWithin(0,2,2+a-1),n[a-1]=0,n[a]=0,a--}else a++;n[a]=1,d=!d}throw new O}static toNarrowWidePattern(e){let n=e.length,i=0,s;do{let a=2147483647;for(let h of e)h<a&&h>i&&(a=h);i=a,s=0;let l=0,d=0;for(let h=0;h<n;h++){let m=e[h];m>i&&(d|=1<<n-1-h,s++,l+=m)}if(s===3){for(let h=0;h<n&&s>0;h++){let m=e[h];if(m>i&&(s--,m*2>=l))return-1}return d}}while(s>3);return-1}static patternToChar(e){for(let n=0;n<Ot.CHARACTER_ENCODINGS.length;n++)if(Ot.CHARACTER_ENCODINGS[n]===e)return Ot.ALPHABET_STRING.charAt(n);if(e===Ot.ASTERISK_ENCODING)return"*";throw new O}static decodeExtended(e){let n=e.length,i="";for(let s=0;s<n;s++){let a=e.charAt(s);if(a==="+"||a==="$"||a==="%"||a==="/"){let l=e.charAt(s+1),d="\0";switch(a){case"+":if(l>="A"&&l<="Z")d=String.fromCharCode(l.charCodeAt(0)+32);else throw new z;break;case"$":if(l>="A"&&l<="Z")d=String.fromCharCode(l.charCodeAt(0)-64);else throw new z;break;case"%":if(l>="A"&&l<="E")d=String.fromCharCode(l.charCodeAt(0)-38);else if(l>="F"&&l<="J")d=String.fromCharCode(l.charCodeAt(0)-11);else if(l>="K"&&l<="O")d=String.fromCharCode(l.charCodeAt(0)+16);else if(l>="P"&&l<="T")d=String.fromCharCode(l.charCodeAt(0)+43);else if(l==="U")d="\0";else if(l==="V")d="@";else if(l==="W")d="`";else if(l==="X"||l==="Y"||l==="Z")d="";else throw new z;break;case"/":if(l>="A"&&l<="O")d=String.fromCharCode(l.charCodeAt(0)-32);else if(l==="Z")d=":";else throw new z;break}i+=d,s++}else i+=a}return i}}Ot.ALPHABET_STRING="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%",Ot.CHARACTER_ENCODINGS=[52,289,97,352,49,304,112,37,292,100,265,73,328,25,280,88,13,268,76,28,259,67,322,19,274,82,7,262,70,22,385,193,448,145,400,208,133,388,196,168,162,138,42],Ot.ASTERISK_ENCODING=148;class ot extends Te{constructor(){super(...arguments),this.narrowLineWidth=-1}decodeRow(e,n,i){let s=this.decodeStart(n),a=this.decodeEnd(n),l=new le;ot.decodeMiddle(n,s[1],a[0],l);let d=l.toString(),h=null;i!=null&&(h=i.get(j.ALLOWED_LENGTHS)),h==null&&(h=ot.DEFAULT_ALLOWED_LENGTHS);let m=d.length,y=!1,b=0;for(let F of h){if(m===F){y=!0;break}F>b&&(b=F)}if(!y&&m>b&&(y=!0),!y)throw new z;const I=[new N(s[1],e),new N(a[0],e)];return new Be(d,null,0,I,ie.ITF,new Date().getTime())}static decodeMiddle(e,n,i,s){let a=new Int32Array(10),l=new Int32Array(5),d=new Int32Array(5);for(a.fill(0),l.fill(0),d.fill(0);n<i;){Te.recordPattern(e,n,a);for(let m=0;m<5;m++){let y=2*m;l[m]=a[y],d[m]=a[y+1]}let h=ot.decodeDigit(l);s.append(h.toString()),h=this.decodeDigit(d),s.append(h.toString()),a.forEach(function(m){n+=m})}}decodeStart(e){let n=ot.skipWhiteSpace(e),i=ot.findGuardPattern(e,n,ot.START_PATTERN);return this.narrowLineWidth=(i[1]-i[0])/4,this.validateQuietZone(e,i[0]),i}validateQuietZone(e,n){let i=this.narrowLineWidth*10;i=i<n?i:n;for(let s=n-1;i>0&&s>=0&&!e.get(s);s--)i--;if(i!==0)throw new O}static skipWhiteSpace(e){const n=e.getSize(),i=e.getNextSet(0);if(i===n)throw new O;return i}decodeEnd(e){e.reverse();try{let n=ot.skipWhiteSpace(e),i;try{i=ot.findGuardPattern(e,n,ot.END_PATTERN_REVERSED[0])}catch(a){a instanceof O&&(i=ot.findGuardPattern(e,n,ot.END_PATTERN_REVERSED[1]))}this.validateQuietZone(e,i[0]);let s=i[0];return i[0]=e.getSize()-i[1],i[1]=e.getSize()-s,i}finally{e.reverse()}}static findGuardPattern(e,n,i){let s=i.length,a=new Int32Array(s),l=e.getSize(),d=!1,h=0,m=n;a.fill(0);for(let y=n;y<l;y++)if(e.get(y)!==d)a[h]++;else{if(h===s-1){if(Te.patternMatchVariance(a,i,ot.MAX_INDIVIDUAL_VARIANCE)<ot.MAX_AVG_VARIANCE)return[m,y];m+=a[0]+a[1],R.arraycopy(a,2,a,0,h-1),a[h-1]=0,a[h]=0,h--}else h++;a[h]=1,d=!d}throw new O}static decodeDigit(e){let n=ot.MAX_AVG_VARIANCE,i=-1,s=ot.PATTERNS.length;for(let a=0;a<s;a++){let l=ot.PATTERNS[a],d=Te.patternMatchVariance(e,l,ot.MAX_INDIVIDUAL_VARIANCE);d<n?(n=d,i=a):d===n&&(i=-1)}if(i>=0)return i%10;throw new O}}ot.PATTERNS=[Int32Array.from([1,1,2,2,1]),Int32Array.from([2,1,1,1,2]),Int32Array.from([1,2,1,1,2]),Int32Array.from([2,2,1,1,1]),Int32Array.from([1,1,2,1,2]),Int32Array.from([2,1,2,1,1]),Int32Array.from([1,2,2,1,1]),Int32Array.from([1,1,1,2,2]),Int32Array.from([2,1,1,2,1]),Int32Array.from([1,2,1,2,1]),Int32Array.from([1,1,3,3,1]),Int32Array.from([3,1,1,1,3]),Int32Array.from([1,3,1,1,3]),Int32Array.from([3,3,1,1,1]),Int32Array.from([1,1,3,1,3]),Int32Array.from([3,1,3,1,1]),Int32Array.from([1,3,3,1,1]),Int32Array.from([1,1,1,3,3]),Int32Array.from([3,1,1,3,1]),Int32Array.from([1,3,1,3,1])],ot.MAX_AVG_VARIANCE=.38,ot.MAX_INDIVIDUAL_VARIANCE=.5,ot.DEFAULT_ALLOWED_LENGTHS=[6,8,10,12,14],ot.START_PATTERN=Int32Array.from([1,1,1,1]),ot.END_PATTERN_REVERSED=[Int32Array.from([1,1,2]),Int32Array.from([1,1,3])];class At extends Te{constructor(){super(...arguments),this.decodeRowStringBuffer=""}static findStartGuardPattern(e){let n=!1,i,s=0,a=Int32Array.from([0,0,0]);for(;!n;){a=Int32Array.from([0,0,0]),i=At.findGuardPattern(e,s,!1,this.START_END_PATTERN,a);let l=i[0];s=i[1];let d=l-(s-l);d>=0&&(n=e.isRange(d,l,!1))}return i}static checkChecksum(e){return At.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let n=e.length;if(n===0)return!1;let i=parseInt(e.charAt(n-1),10);return At.getStandardUPCEANChecksum(e.substring(0,n-1))===i}static getStandardUPCEANChecksum(e){let n=e.length,i=0;for(let s=n-1;s>=0;s-=2){let a=e.charAt(s).charCodeAt(0)-48;if(a<0||a>9)throw new z;i+=a}i*=3;for(let s=n-2;s>=0;s-=2){let a=e.charAt(s).charCodeAt(0)-48;if(a<0||a>9)throw new z;i+=a}return(1e3-i)%10}static decodeEnd(e,n){return At.findGuardPattern(e,n,!1,At.START_END_PATTERN,new Int32Array(At.START_END_PATTERN.length).fill(0))}static findGuardPatternWithoutCounters(e,n,i,s){return this.findGuardPattern(e,n,i,s,new Int32Array(s.length))}static findGuardPattern(e,n,i,s,a){let l=e.getSize();n=i?e.getNextUnset(n):e.getNextSet(n);let d=0,h=n,m=s.length,y=i;for(let b=n;b<l;b++)if(e.get(b)!==y)a[d]++;else{if(d===m-1){if(Te.patternMatchVariance(a,s,At.MAX_INDIVIDUAL_VARIANCE)<At.MAX_AVG_VARIANCE)return Int32Array.from([h,b]);h+=a[0]+a[1];let I=a.slice(2,a.length-1);for(let k=0;k<d-1;k++)a[k]=I[k];a[d-1]=0,a[d]=0,d--}else d++;a[d]=1,y=!y}throw new O}static decodeDigit(e,n,i,s){this.recordPattern(e,i,n);let a=this.MAX_AVG_VARIANCE,l=-1,d=s.length;for(let h=0;h<d;h++){let m=s[h],y=Te.patternMatchVariance(n,m,At.MAX_INDIVIDUAL_VARIANCE);y<a&&(a=y,l=h)}if(l>=0)return l;throw new O}}At.MAX_AVG_VARIANCE=.48,At.MAX_INDIVIDUAL_VARIANCE=.7,At.START_END_PATTERN=Int32Array.from([1,1,1]),At.MIDDLE_PATTERN=Int32Array.from([1,1,1,1,1]),At.END_PATTERN=Int32Array.from([1,1,1,1,1,1]),At.L_PATTERNS=[Int32Array.from([3,2,1,1]),Int32Array.from([2,2,2,1]),Int32Array.from([2,1,2,2]),Int32Array.from([1,4,1,1]),Int32Array.from([1,1,3,2]),Int32Array.from([1,2,3,1]),Int32Array.from([1,1,1,4]),Int32Array.from([1,3,1,2]),Int32Array.from([1,2,1,3]),Int32Array.from([3,1,1,2])];class Or{constructor(){this.CHECK_DIGIT_ENCODINGS=[24,20,18,17,12,6,3,10,9,5],this.decodeMiddleCounters=Int32Array.from([0,0,0,0]),this.decodeRowStringBuffer=""}decodeRow(e,n,i){let s=this.decodeRowStringBuffer,a=this.decodeMiddle(n,i,s),l=s.toString(),d=Or.parseExtensionString(l),h=[new N((i[0]+i[1])/2,e),new N(a,e)],m=new Be(l,null,0,h,ie.UPC_EAN_EXTENSION,new Date().getTime());return d!=null&&m.putAllMetadata(d),m}decodeMiddle(e,n,i){let s=this.decodeMiddleCounters;s[0]=0,s[1]=0,s[2]=0,s[3]=0;let a=e.getSize(),l=n[1],d=0;for(let m=0;m<5&&l<a;m++){let y=At.decodeDigit(e,s,l,At.L_AND_G_PATTERNS);i+=String.fromCharCode(48+y%10);for(let b of s)l+=b;y>=10&&(d|=1<<4-m),m!==4&&(l=e.getNextSet(l),l=e.getNextUnset(l))}if(i.length!==5)throw new O;let h=this.determineCheckDigit(d);if(Or.extensionChecksum(i.toString())!==h)throw new O;return l}static extensionChecksum(e){let n=e.length,i=0;for(let s=n-2;s>=0;s-=2)i+=e.charAt(s).charCodeAt(0)-48;i*=3;for(let s=n-1;s>=0;s-=2)i+=e.charAt(s).charCodeAt(0)-48;return i*=3,i%10}determineCheckDigit(e){for(let n=0;n<10;n++)if(e===this.CHECK_DIGIT_ENCODINGS[n])return n;throw new O}static parseExtensionString(e){if(e.length!==5)return null;let n=Or.parseExtension5String(e);return n==null?null:new Map([[Me.SUGGESTED_PRICE,n]])}static parseExtension5String(e){let n;switch(e.charAt(0)){case"0":n="£";break;case"5":n="$";break;case"9":switch(e){case"90000":return null;case"99991":return"0.00";case"99990":return"Used"}n="";break;default:n="";break}let i=parseInt(e.substring(1)),s=(i/100).toString(),a=i%100,l=a<10?"0"+a:a.toString();return n+s+"."+l}}class Hi{constructor(){this.decodeMiddleCounters=Int32Array.from([0,0,0,0]),this.decodeRowStringBuffer=""}decodeRow(e,n,i){let s=this.decodeRowStringBuffer,a=this.decodeMiddle(n,i,s),l=s.toString(),d=Hi.parseExtensionString(l),h=[new N((i[0]+i[1])/2,e),new N(a,e)],m=new Be(l,null,0,h,ie.UPC_EAN_EXTENSION,new Date().getTime());return d!=null&&m.putAllMetadata(d),m}decodeMiddle(e,n,i){let s=this.decodeMiddleCounters;s[0]=0,s[1]=0,s[2]=0,s[3]=0;let a=e.getSize(),l=n[1],d=0;for(let h=0;h<2&&l<a;h++){let m=At.decodeDigit(e,s,l,At.L_AND_G_PATTERNS);i+=String.fromCharCode(48+m%10);for(let y of s)l+=y;m>=10&&(d|=1<<1-h),h!==1&&(l=e.getNextSet(l),l=e.getNextUnset(l))}if(i.length!==2)throw new O;if(parseInt(i.toString())%4!==d)throw new O;return l}static parseExtensionString(e){return e.length!==2?null:new Map([[Me.ISSUE_NUMBER,parseInt(e)]])}}class as{static decodeRow(e,n,i){let s=At.findGuardPattern(n,i,!1,this.EXTENSION_START_PATTERN,new Int32Array(this.EXTENSION_START_PATTERN.length).fill(0));try{return new Or().decodeRow(e,n,s)}catch{return new Hi().decodeRow(e,n,s)}}}as.EXTENSION_START_PATTERN=Int32Array.from([1,1,2]);class qe extends At{constructor(){super(),this.decodeRowStringBuffer="",qe.L_AND_G_PATTERNS=qe.L_PATTERNS.map(e=>Int32Array.from(e));for(let e=10;e<20;e++){let n=qe.L_PATTERNS[e-10],i=new Int32Array(n.length);for(let s=0;s<n.length;s++)i[s]=n[n.length-s-1];qe.L_AND_G_PATTERNS[e]=i}}decodeRow(e,n,i){let s=qe.findStartGuardPattern(n),a=i==null?null:i.get(j.NEED_RESULT_POINT_CALLBACK);if(a!=null){const de=new N((s[0]+s[1])/2,e);a.foundPossibleResultPoint(de)}let l=this.decodeMiddle(n,s,this.decodeRowStringBuffer),d=l.rowOffset,h=l.resultString;if(a!=null){const de=new N(d,e);a.foundPossibleResultPoint(de)}let m=this.decodeEnd(n,d);if(a!=null){const de=new N((m[0]+m[1])/2,e);a.foundPossibleResultPoint(de)}let y=m[1],b=y+(y-m[0]);if(b>=n.getSize()||!n.isRange(y,b,!1))throw new O;let I=h.toString();if(I.length<8)throw new z;if(!qe.checkChecksum(I))throw new M;let k=(s[1]+s[0])/2,F=(m[1]+m[0])/2,U=this.getBarcodeFormat(),G=[new N(k,e),new N(F,e)],Q=new Be(I,null,0,G,U,new Date().getTime()),fe=0;try{let de=as.decodeRow(e,n,m[1]);Q.putMetadata(Me.UPC_EAN_EXTENSION,de.getText()),Q.putAllMetadata(de.getResultMetadata()),Q.addResultPoints(de.getResultPoints()),fe=de.getText().length}catch{}let pe=i==null?null:i.get(j.ALLOWED_EAN_EXTENSIONS);if(pe!=null){let de=!1;for(let He in pe)if(fe.toString()===He){de=!0;break}if(!de)throw new O}return Q}decodeEnd(e,n){return qe.findGuardPattern(e,n,!1,qe.START_END_PATTERN,new Int32Array(qe.START_END_PATTERN.length).fill(0))}static checkChecksum(e){return qe.checkStandardUPCEANChecksum(e)}static checkStandardUPCEANChecksum(e){let n=e.length;if(n===0)return!1;let i=parseInt(e.charAt(n-1),10);return qe.getStandardUPCEANChecksum(e.substring(0,n-1))===i}static getStandardUPCEANChecksum(e){let n=e.length,i=0;for(let s=n-1;s>=0;s-=2){let a=e.charAt(s).charCodeAt(0)-48;if(a<0||a>9)throw new z;i+=a}i*=3;for(let s=n-2;s>=0;s-=2){let a=e.charAt(s).charCodeAt(0)-48;if(a<0||a>9)throw new z;i+=a}return(1e3-i)%10}}class Qn extends qe{constructor(){super(),this.decodeMiddleCounters=Int32Array.from([0,0,0,0])}decodeMiddle(e,n,i){let s=this.decodeMiddleCounters;s[0]=0,s[1]=0,s[2]=0,s[3]=0;let a=e.getSize(),l=n[1],d=0;for(let m=0;m<6&&l<a;m++){let y=qe.decodeDigit(e,s,l,qe.L_AND_G_PATTERNS);i+=String.fromCharCode(48+y%10);for(let b of s)l+=b;y>=10&&(d|=1<<5-m)}i=Qn.determineFirstDigit(i,d),l=qe.findGuardPattern(e,l,!0,qe.MIDDLE_PATTERN,new Int32Array(qe.MIDDLE_PATTERN.length).fill(0))[1];for(let m=0;m<6&&l<a;m++){let y=qe.decodeDigit(e,s,l,qe.L_PATTERNS);i+=String.fromCharCode(48+y);for(let b of s)l+=b}return{rowOffset:l,resultString:i}}getBarcodeFormat(){return ie.EAN_13}static determineFirstDigit(e,n){for(let i=0;i<10;i++)if(n===this.FIRST_DIGIT_ENCODINGS[i])return e=String.fromCharCode(48+i)+e,e;throw new O}}Qn.FIRST_DIGIT_ENCODINGS=[0,11,13,14,19,25,28,21,22,26];class ls extends qe{constructor(){super(),this.decodeMiddleCounters=Int32Array.from([0,0,0,0])}decodeMiddle(e,n,i){const s=this.decodeMiddleCounters;s[0]=0,s[1]=0,s[2]=0,s[3]=0;let a=e.getSize(),l=n[1];for(let h=0;h<4&&l<a;h++){let m=qe.decodeDigit(e,s,l,qe.L_PATTERNS);i+=String.fromCharCode(48+m);for(let y of s)l+=y}l=qe.findGuardPattern(e,l,!0,qe.MIDDLE_PATTERN,new Int32Array(qe.MIDDLE_PATTERN.length).fill(0))[1];for(let h=0;h<4&&l<a;h++){let m=qe.decodeDigit(e,s,l,qe.L_PATTERNS);i+=String.fromCharCode(48+m);for(let y of s)l+=y}return{rowOffset:l,resultString:i}}getBarcodeFormat(){return ie.EAN_8}}class cs extends qe{constructor(){super(...arguments),this.ean13Reader=new Qn}getBarcodeFormat(){return ie.UPC_A}decode(e,n){return this.maybeReturnResult(this.ean13Reader.decode(e))}decodeRow(e,n,i){return this.maybeReturnResult(this.ean13Reader.decodeRow(e,n,i))}decodeMiddle(e,n,i){return this.ean13Reader.decodeMiddle(e,n,i)}maybeReturnResult(e){let n=e.getText();if(n.charAt(0)==="0"){let i=new Be(n.substring(1),null,null,e.getResultPoints(),ie.UPC_A);return e.getResultMetadata()!=null&&i.putAllMetadata(e.getResultMetadata()),i}else throw new O}reset(){this.ean13Reader.reset()}}class xn extends qe{constructor(){super(),this.decodeMiddleCounters=new Int32Array(4)}decodeMiddle(e,n,i){const s=this.decodeMiddleCounters.map(m=>m);s[0]=0,s[1]=0,s[2]=0,s[3]=0;const a=e.getSize();let l=n[1],d=0;for(let m=0;m<6&&l<a;m++){const y=xn.decodeDigit(e,s,l,xn.L_AND_G_PATTERNS);i+=String.fromCharCode(48+y%10);for(let b of s)l+=b;y>=10&&(d|=1<<5-m)}let h=xn.determineNumSysAndCheckDigit(i,d);return{rowOffset:l,resultString:h}}decodeEnd(e,n){return xn.findGuardPatternWithoutCounters(e,n,!0,xn.MIDDLE_END_PATTERN)}checkChecksum(e){return qe.checkChecksum(xn.convertUPCEtoUPCA(e))}static determineNumSysAndCheckDigit(e,n){for(let i=0;i<=1;i++)for(let s=0;s<10;s++)if(n===this.NUMSYS_AND_CHECK_DIGIT_PATTERNS[i][s]){let a=String.fromCharCode(48+i),l=String.fromCharCode(48+s);return a+e+l}throw O.getNotFoundInstance()}getBarcodeFormat(){return ie.UPC_E}static convertUPCEtoUPCA(e){const n=e.slice(1,7).split("").map(a=>a.charCodeAt(0)),i=new le;i.append(e.charAt(0));let s=n[5];switch(s){case 0:case 1:case 2:i.appendChars(n,0,2),i.append(s),i.append("0000"),i.appendChars(n,2,3);break;case 3:i.appendChars(n,0,3),i.append("00000"),i.appendChars(n,3,2);break;case 4:i.appendChars(n,0,4),i.append("00000"),i.append(n[4]);break;default:i.appendChars(n,0,5),i.append("0000"),i.append(s);break}return e.length>=8&&i.append(e.charAt(7)),i.toString()}}xn.MIDDLE_END_PATTERN=Int32Array.from([1,1,1,1,1,1]),xn.NUMSYS_AND_CHECK_DIGIT_PATTERNS=[Int32Array.from([56,52,50,49,44,38,35,42,41,37]),Int32Array.from([7,11,13,14,19,25,28,21,22,26])];class Wi extends Te{constructor(e){super();let n=e==null?null:e.get(j.POSSIBLE_FORMATS),i=[];c(n)?(i.push(new Qn),i.push(new cs),i.push(new ls),i.push(new xn)):(n.indexOf(ie.EAN_13)>-1&&i.push(new Qn),n.indexOf(ie.UPC_A)>-1&&i.push(new cs),n.indexOf(ie.EAN_8)>-1&&i.push(new ls),n.indexOf(ie.UPC_E)>-1&&i.push(new xn)),this.readers=i}decodeRow(e,n,i){for(let s of this.readers)try{const a=s.decodeRow(e,n,i),l=a.getBarcodeFormat()===ie.EAN_13&&a.getText().charAt(0)==="0",d=i==null?null:i.get(j.POSSIBLE_FORMATS),h=d==null||d.includes(ie.UPC_A);if(l&&h){const m=a.getRawBytes(),y=new Be(a.getText().substring(1),m,m?m.length:null,a.getResultPoints(),ie.UPC_A);return y.putAllMetadata(a.getResultMetadata()),y}return a}catch{}throw new O}reset(){for(let e of this.readers)e.reset()}}class jt extends Te{constructor(){super(),this.decodeFinderCounters=new Int32Array(4),this.dataCharacterCounters=new Int32Array(8),this.oddRoundingErrors=new Array(4),this.evenRoundingErrors=new Array(4),this.oddCounts=new Array(this.dataCharacterCounters.length/2),this.evenCounts=new Array(this.dataCharacterCounters.length/2)}getDecodeFinderCounters(){return this.decodeFinderCounters}getDataCharacterCounters(){return this.dataCharacterCounters}getOddRoundingErrors(){return this.oddRoundingErrors}getEvenRoundingErrors(){return this.evenRoundingErrors}getOddCounts(){return this.oddCounts}getEvenCounts(){return this.evenCounts}parseFinderValue(e,n){for(let i=0;i<n.length;i++)if(Te.patternMatchVariance(e,n[i],jt.MAX_INDIVIDUAL_VARIANCE)<jt.MAX_AVG_VARIANCE)return i;throw new O}static count(e){return Ze.sum(new Int32Array(e))}static increment(e,n){let i=0,s=n[0];for(let a=1;a<e.length;a++)n[a]>s&&(s=n[a],i=a);e[i]++}static decrement(e,n){let i=0,s=n[0];for(let a=1;a<e.length;a++)n[a]<s&&(s=n[a],i=a);e[i]--}static isFinderPattern(e){let n=e[0]+e[1],i=n+e[2]+e[3],s=n/i;if(s>=jt.MIN_FINDER_PATTERN_RATIO&&s<=jt.MAX_FINDER_PATTERN_RATIO){let a=Number.MAX_SAFE_INTEGER,l=Number.MIN_SAFE_INTEGER;for(let d of e)d>l&&(l=d),d<a&&(a=d);return l<10*a}return!1}}jt.MAX_AVG_VARIANCE=.2,jt.MAX_INDIVIDUAL_VARIANCE=.45,jt.MIN_FINDER_PATTERN_RATIO=9.5/12,jt.MAX_FINDER_PATTERN_RATIO=12.5/14;class mr{constructor(e,n){this.value=e,this.checksumPortion=n}getValue(){return this.value}getChecksumPortion(){return this.checksumPortion}toString(){return this.value+"("+this.checksumPortion+")"}equals(e){if(!(e instanceof mr))return!1;const n=e;return this.value===n.value&&this.checksumPortion===n.checksumPortion}hashCode(){return this.value^this.checksumPortion}}class ci{constructor(e,n,i,s,a){this.value=e,this.startEnd=n,this.value=e,this.startEnd=n,this.resultPoints=new Array,this.resultPoints.push(new N(i,a)),this.resultPoints.push(new N(s,a))}getValue(){return this.value}getStartEnd(){return this.startEnd}getResultPoints(){return this.resultPoints}equals(e){if(!(e instanceof ci))return!1;const n=e;return this.value===n.value}hashCode(){return this.value}}class In{constructor(){}static getRSSvalue(e,n,i){let s=0;for(let h of e)s+=h;let a=0,l=0,d=e.length;for(let h=0;h<d-1;h++){let m;for(m=1,l|=1<<h;m<e[h];m++,l&=~(1<<h)){let y=In.combins(s-m-1,d-h-2);if(i&&l===0&&s-m-(d-h-1)>=d-h-1&&(y-=In.combins(s-m-(d-h),d-h-2)),d-h-1>1){let b=0;for(let I=s-m-(d-h-2);I>n;I--)b+=In.combins(s-m-I-1,d-h-3);y-=b*(d-1-h)}else s-m>n&&y--;a+=y}s-=m}return a}static combins(e,n){let i,s;e-n>n?(s=n,i=e-n):(s=e-n,i=n);let a=1,l=1;for(let d=e;d>i;d--)a*=d,l<=s&&(a/=l,l++);for(;l<=s;)a/=l,l++;return a}}class Gu{static buildBitArray(e){let n=e.length*2-1;e[e.length-1].getRightChar()==null&&(n-=1);let i=12*n,s=new V(i),a=0,d=e[0].getRightChar().getValue();for(let h=11;h>=0;--h)(d&1<<h)!=0&&s.set(a),a++;for(let h=1;h<e.length;++h){let m=e[h],y=m.getLeftChar().getValue();for(let b=11;b>=0;--b)(y&1<<b)!=0&&s.set(a),a++;if(m.getRightChar()!=null){let b=m.getRightChar().getValue();for(let I=11;I>=0;--I)(b&1<<I)!=0&&s.set(a),a++}}return s}}class er{constructor(e,n){n?this.decodedInformation=null:(this.finished=e,this.decodedInformation=n)}getDecodedInformation(){return this.decodedInformation}isFinished(){return this.finished}}class Gi{constructor(e){this.newPosition=e}getNewPosition(){return this.newPosition}}class Jt extends Gi{constructor(e,n){super(e),this.value=n}getValue(){return this.value}isFNC1(){return this.value===Jt.FNC1}}Jt.FNC1="$";class tr extends Gi{constructor(e,n,i){super(e),i?(this.remaining=!0,this.remainingValue=this.remainingValue):(this.remaining=!1,this.remainingValue=0),this.newString=n}getNewString(){return this.newString}isRemaining(){return this.remaining}getRemainingValue(){return this.remainingValue}}class fn extends Gi{constructor(e,n,i){if(super(e),n<0||n>10||i<0||i>10)throw new z;this.firstDigit=n,this.secondDigit=i}getFirstDigit(){return this.firstDigit}getSecondDigit(){return this.secondDigit}getValue(){return this.firstDigit*10+this.secondDigit}isFirstDigitFNC1(){return this.firstDigit===fn.FNC1}isSecondDigitFNC1(){return this.secondDigit===fn.FNC1}isAnyFNC1(){return this.firstDigit===fn.FNC1||this.secondDigit===fn.FNC1}}fn.FNC1=10;class _e{constructor(){}static parseFieldsInGeneralPurpose(e){if(!e)return null;if(e.length<2)throw new O;let n=e.substring(0,2);for(let a of _e.TWO_DIGIT_DATA_LENGTH)if(a[0]===n)return a[1]===_e.VARIABLE_LENGTH?_e.processVariableAI(2,a[2],e):_e.processFixedAI(2,a[1],e);if(e.length<3)throw new O;let i=e.substring(0,3);for(let a of _e.THREE_DIGIT_DATA_LENGTH)if(a[0]===i)return a[1]===_e.VARIABLE_LENGTH?_e.processVariableAI(3,a[2],e):_e.processFixedAI(3,a[1],e);for(let a of _e.THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH)if(a[0]===i)return a[1]===_e.VARIABLE_LENGTH?_e.processVariableAI(4,a[2],e):_e.processFixedAI(4,a[1],e);if(e.length<4)throw new O;let s=e.substring(0,4);for(let a of _e.FOUR_DIGIT_DATA_LENGTH)if(a[0]===s)return a[1]===_e.VARIABLE_LENGTH?_e.processVariableAI(4,a[2],e):_e.processFixedAI(4,a[1],e);throw new O}static processFixedAI(e,n,i){if(i.length<e)throw new O;let s=i.substring(0,e);if(i.length<e+n)throw new O;let a=i.substring(e,e+n),l=i.substring(e+n),d="("+s+")"+a,h=_e.parseFieldsInGeneralPurpose(l);return h==null?d:d+h}static processVariableAI(e,n,i){let s=i.substring(0,e),a;i.length<e+n?a=i.length:a=e+n;let l=i.substring(e,a),d=i.substring(a),h="("+s+")"+l,m=_e.parseFieldsInGeneralPurpose(d);return m==null?h:h+m}}_e.VARIABLE_LENGTH=[],_e.TWO_DIGIT_DATA_LENGTH=[["00",18],["01",14],["02",14],["10",_e.VARIABLE_LENGTH,20],["11",6],["12",6],["13",6],["15",6],["17",6],["20",2],["21",_e.VARIABLE_LENGTH,20],["22",_e.VARIABLE_LENGTH,29],["30",_e.VARIABLE_LENGTH,8],["37",_e.VARIABLE_LENGTH,8],["90",_e.VARIABLE_LENGTH,30],["91",_e.VARIABLE_LENGTH,30],["92",_e.VARIABLE_LENGTH,30],["93",_e.VARIABLE_LENGTH,30],["94",_e.VARIABLE_LENGTH,30],["95",_e.VARIABLE_LENGTH,30],["96",_e.VARIABLE_LENGTH,30],["97",_e.VARIABLE_LENGTH,3],["98",_e.VARIABLE_LENGTH,30],["99",_e.VARIABLE_LENGTH,30]],_e.THREE_DIGIT_DATA_LENGTH=[["240",_e.VARIABLE_LENGTH,30],["241",_e.VARIABLE_LENGTH,30],["242",_e.VARIABLE_LENGTH,6],["250",_e.VARIABLE_LENGTH,30],["251",_e.VARIABLE_LENGTH,30],["253",_e.VARIABLE_LENGTH,17],["254",_e.VARIABLE_LENGTH,20],["400",_e.VARIABLE_LENGTH,30],["401",_e.VARIABLE_LENGTH,30],["402",17],["403",_e.VARIABLE_LENGTH,30],["410",13],["411",13],["412",13],["413",13],["414",13],["420",_e.VARIABLE_LENGTH,20],["421",_e.VARIABLE_LENGTH,15],["422",3],["423",_e.VARIABLE_LENGTH,15],["424",3],["425",3],["426",3]],_e.THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH=[["310",6],["311",6],["312",6],["313",6],["314",6],["315",6],["316",6],["320",6],["321",6],["322",6],["323",6],["324",6],["325",6],["326",6],["327",6],["328",6],["329",6],["330",6],["331",6],["332",6],["333",6],["334",6],["335",6],["336",6],["340",6],["341",6],["342",6],["343",6],["344",6],["345",6],["346",6],["347",6],["348",6],["349",6],["350",6],["351",6],["352",6],["353",6],["354",6],["355",6],["356",6],["357",6],["360",6],["361",6],["362",6],["363",6],["364",6],["365",6],["366",6],["367",6],["368",6],["369",6],["390",_e.VARIABLE_LENGTH,15],["391",_e.VARIABLE_LENGTH,18],["392",_e.VARIABLE_LENGTH,15],["393",_e.VARIABLE_LENGTH,18],["703",_e.VARIABLE_LENGTH,30]],_e.FOUR_DIGIT_DATA_LENGTH=[["7001",13],["7002",_e.VARIABLE_LENGTH,30],["7003",10],["8001",14],["8002",_e.VARIABLE_LENGTH,20],["8003",_e.VARIABLE_LENGTH,30],["8004",_e.VARIABLE_LENGTH,30],["8005",6],["8006",18],["8007",_e.VARIABLE_LENGTH,30],["8008",_e.VARIABLE_LENGTH,12],["8018",18],["8020",_e.VARIABLE_LENGTH,25],["8100",6],["8101",10],["8102",2],["8110",_e.VARIABLE_LENGTH,70],["8200",_e.VARIABLE_LENGTH,70]];class gr{constructor(e){this.buffer=new le,this.information=e}decodeAllCodes(e,n){let i=n,s=null;do{let a=this.decodeGeneralPurposeField(i,s),l=_e.parseFieldsInGeneralPurpose(a.getNewString());if(l!=null&&e.append(l),a.isRemaining()?s=""+a.getRemainingValue():s=null,i===a.getNewPosition())break;i=a.getNewPosition()}while(!0);return e.toString()}isStillNumeric(e){if(e+7>this.information.getSize())return e+4<=this.information.getSize();for(let n=e;n<e+3;++n)if(this.information.get(n))return!0;return this.information.get(e+3)}decodeNumeric(e){if(e+7>this.information.getSize()){let a=this.extractNumericValueFromBitArray(e,4);return a===0?new fn(this.information.getSize(),fn.FNC1,fn.FNC1):new fn(this.information.getSize(),a-1,fn.FNC1)}let n=this.extractNumericValueFromBitArray(e,7),i=(n-8)/11,s=(n-8)%11;return new fn(e+7,i,s)}extractNumericValueFromBitArray(e,n){return gr.extractNumericValueFromBitArray(this.information,e,n)}static extractNumericValueFromBitArray(e,n,i){let s=0;for(let a=0;a<i;++a)e.get(n+a)&&(s|=1<<i-a-1);return s}decodeGeneralPurposeField(e,n){this.buffer.setLengthToZero(),n!=null&&this.buffer.append(n),this.current.setPosition(e);let i=this.parseBlocks();return i!=null&&i.isRemaining()?new tr(this.current.getPosition(),this.buffer.toString(),i.getRemainingValue()):new tr(this.current.getPosition(),this.buffer.toString())}parseBlocks(){let e,n;do{let i=this.current.getPosition();if(this.current.isAlpha()?(n=this.parseAlphaBlock(),e=n.isFinished()):this.current.isIsoIec646()?(n=this.parseIsoIec646Block(),e=n.isFinished()):(n=this.parseNumericBlock(),e=n.isFinished()),!(i!==this.current.getPosition())&&!e)break}while(!e);return n.getDecodedInformation()}parseNumericBlock(){for(;this.isStillNumeric(this.current.getPosition());){let e=this.decodeNumeric(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFirstDigitFNC1()){let n;return e.isSecondDigitFNC1()?n=new tr(this.current.getPosition(),this.buffer.toString()):n=new tr(this.current.getPosition(),this.buffer.toString(),e.getSecondDigit()),new er(!0,n)}if(this.buffer.append(e.getFirstDigit()),e.isSecondDigitFNC1()){let n=new tr(this.current.getPosition(),this.buffer.toString());return new er(!0,n)}this.buffer.append(e.getSecondDigit())}return this.isNumericToAlphaNumericLatch(this.current.getPosition())&&(this.current.setAlpha(),this.current.incrementPosition(4)),new er(!1)}parseIsoIec646Block(){for(;this.isStillIsoIec646(this.current.getPosition());){let e=this.decodeIsoIec646(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFNC1()){let n=new tr(this.current.getPosition(),this.buffer.toString());return new er(!0,n)}this.buffer.append(e.getValue())}return this.isAlphaOr646ToNumericLatch(this.current.getPosition())?(this.current.incrementPosition(3),this.current.setNumeric()):this.isAlphaTo646ToAlphaLatch(this.current.getPosition())&&(this.current.getPosition()+5<this.information.getSize()?this.current.incrementPosition(5):this.current.setPosition(this.information.getSize()),this.current.setAlpha()),new er(!1)}parseAlphaBlock(){for(;this.isStillAlpha(this.current.getPosition());){let e=this.decodeAlphanumeric(this.current.getPosition());if(this.current.setPosition(e.getNewPosition()),e.isFNC1()){let n=new tr(this.current.getPosition(),this.buffer.toString());return new er(!0,n)}this.buffer.append(e.getValue())}return this.isAlphaOr646ToNumericLatch(this.current.getPosition())?(this.current.incrementPosition(3),this.current.setNumeric()):this.isAlphaTo646ToAlphaLatch(this.current.getPosition())&&(this.current.getPosition()+5<this.information.getSize()?this.current.incrementPosition(5):this.current.setPosition(this.information.getSize()),this.current.setIsoIec646()),new er(!1)}isStillIsoIec646(e){if(e+5>this.information.getSize())return!1;let n=this.extractNumericValueFromBitArray(e,5);if(n>=5&&n<16)return!0;if(e+7>this.information.getSize())return!1;let i=this.extractNumericValueFromBitArray(e,7);if(i>=64&&i<116)return!0;if(e+8>this.information.getSize())return!1;let s=this.extractNumericValueFromBitArray(e,8);return s>=232&&s<253}decodeIsoIec646(e){let n=this.extractNumericValueFromBitArray(e,5);if(n===15)return new Jt(e+5,Jt.FNC1);if(n>=5&&n<15)return new Jt(e+5,"0"+(n-5));let i=this.extractNumericValueFromBitArray(e,7);if(i>=64&&i<90)return new Jt(e+7,""+(i+1));if(i>=90&&i<116)return new Jt(e+7,""+(i+7));let s=this.extractNumericValueFromBitArray(e,8),a;switch(s){case 232:a="!";break;case 233:a='"';break;case 234:a="%";break;case 235:a="&";break;case 236:a="'";break;case 237:a="(";break;case 238:a=")";break;case 239:a="*";break;case 240:a="+";break;case 241:a=",";break;case 242:a="-";break;case 243:a=".";break;case 244:a="/";break;case 245:a=":";break;case 246:a=";";break;case 247:a="<";break;case 248:a="=";break;case 249:a=">";break;case 250:a="?";break;case 251:a="_";break;case 252:a=" ";break;default:throw new z}return new Jt(e+8,a)}isStillAlpha(e){if(e+5>this.information.getSize())return!1;let n=this.extractNumericValueFromBitArray(e,5);if(n>=5&&n<16)return!0;if(e+6>this.information.getSize())return!1;let i=this.extractNumericValueFromBitArray(e,6);return i>=16&&i<63}decodeAlphanumeric(e){let n=this.extractNumericValueFromBitArray(e,5);if(n===15)return new Jt(e+5,Jt.FNC1);if(n>=5&&n<15)return new Jt(e+5,"0"+(n-5));let i=this.extractNumericValueFromBitArray(e,6);if(i>=32&&i<58)return new Jt(e+6,""+(i+33));let s;switch(i){case 58:s="*";break;case 59:s=",";break;case 60:s="-";break;case 61:s=".";break;case 62:s="/";break;default:throw new Zt("Decoding invalid alphanumeric value: "+i)}return new Jt(e+6,s)}isAlphaTo646ToAlphaLatch(e){if(e+1>this.information.getSize())return!1;for(let n=0;n<5&&n+e<this.information.getSize();++n)if(n===2){if(!this.information.get(e+2))return!1}else if(this.information.get(e+n))return!1;return!0}isAlphaOr646ToNumericLatch(e){if(e+3>this.information.getSize())return!1;for(let n=e;n<e+3;++n)if(this.information.get(n))return!1;return!0}isNumericToAlphaNumericLatch(e){if(e+1>this.information.getSize())return!1;for(let n=0;n<4&&n+e<this.information.getSize();++n)if(this.information.get(e+n))return!1;return!0}}class Xi{constructor(e){this.information=e,this.generalDecoder=new gr(e)}getInformation(){return this.information}getGeneralDecoder(){return this.generalDecoder}}class Kt extends Xi{constructor(e){super(e)}encodeCompressedGtin(e,n){e.append("(01)");let i=e.length();e.append("9"),this.encodeCompressedGtinWithoutAI(e,n,i)}encodeCompressedGtinWithoutAI(e,n,i){for(let s=0;s<4;++s){let a=this.getGeneralDecoder().extractNumericValueFromBitArray(n+10*s,10);a/100===0&&e.append("0"),a/10===0&&e.append("0"),e.append(a)}Kt.appendCheckDigit(e,i)}static appendCheckDigit(e,n){let i=0;for(let s=0;s<13;s++){let a=e.charAt(s+n).charCodeAt(0)-48;i+=(s&1)===0?3*a:a}i=10-i%10,i===10&&(i=0),e.append(i)}}Kt.GTIN_SIZE=40;class xr extends Kt{constructor(e){super(e)}parseInformation(){let e=new le;e.append("(01)");let n=e.length(),i=this.getGeneralDecoder().extractNumericValueFromBitArray(xr.HEADER_SIZE,4);return e.append(i),this.encodeCompressedGtinWithoutAI(e,xr.HEADER_SIZE+4,n),this.getGeneralDecoder().decodeAllCodes(e,xr.HEADER_SIZE+44)}}xr.HEADER_SIZE=4;class ui extends Xi{constructor(e){super(e)}parseInformation(){let e=new le;return this.getGeneralDecoder().decodeAllCodes(e,ui.HEADER_SIZE)}}ui.HEADER_SIZE=5;class di extends Kt{constructor(e){super(e)}encodeCompressedWeight(e,n,i){let s=this.getGeneralDecoder().extractNumericValueFromBitArray(n,i);this.addWeightCode(e,s);let a=this.checkWeight(s),l=1e5;for(let d=0;d<5;++d)a/l===0&&e.append("0"),l/=10;e.append(a)}}class Sn extends di{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()!=Sn.HEADER_SIZE+di.GTIN_SIZE+Sn.WEIGHT_SIZE)throw new O;let e=new le;return this.encodeCompressedGtin(e,Sn.HEADER_SIZE),this.encodeCompressedWeight(e,Sn.HEADER_SIZE+di.GTIN_SIZE,Sn.WEIGHT_SIZE),e.toString()}}Sn.HEADER_SIZE=5,Sn.WEIGHT_SIZE=15;class Xu extends Sn{constructor(e){super(e)}addWeightCode(e,n){e.append("(3103)")}checkWeight(e){return e}}class qu extends Sn{constructor(e){super(e)}addWeightCode(e,n){n<1e4?e.append("(3202)"):e.append("(3203)")}checkWeight(e){return e<1e4?e:e-1e4}}class Tn extends Kt{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<Tn.HEADER_SIZE+Kt.GTIN_SIZE)throw new O;let e=new le;this.encodeCompressedGtin(e,Tn.HEADER_SIZE);let n=this.getGeneralDecoder().extractNumericValueFromBitArray(Tn.HEADER_SIZE+Kt.GTIN_SIZE,Tn.LAST_DIGIT_SIZE);e.append("(392"),e.append(n),e.append(")");let i=this.getGeneralDecoder().decodeGeneralPurposeField(Tn.HEADER_SIZE+Kt.GTIN_SIZE+Tn.LAST_DIGIT_SIZE,null);return e.append(i.getNewString()),e.toString()}}Tn.HEADER_SIZE=8,Tn.LAST_DIGIT_SIZE=2;class Gt extends Kt{constructor(e){super(e)}parseInformation(){if(this.getInformation().getSize()<Gt.HEADER_SIZE+Kt.GTIN_SIZE)throw new O;let e=new le;this.encodeCompressedGtin(e,Gt.HEADER_SIZE);let n=this.getGeneralDecoder().extractNumericValueFromBitArray(Gt.HEADER_SIZE+Kt.GTIN_SIZE,Gt.LAST_DIGIT_SIZE);e.append("(393"),e.append(n),e.append(")");let i=this.getGeneralDecoder().extractNumericValueFromBitArray(Gt.HEADER_SIZE+Kt.GTIN_SIZE+Gt.LAST_DIGIT_SIZE,Gt.FIRST_THREE_DIGITS_SIZE);i/100==0&&e.append("0"),i/10==0&&e.append("0"),e.append(i);let s=this.getGeneralDecoder().decodeGeneralPurposeField(Gt.HEADER_SIZE+Kt.GTIN_SIZE+Gt.LAST_DIGIT_SIZE+Gt.FIRST_THREE_DIGITS_SIZE,null);return e.append(s.getNewString()),e.toString()}}Gt.HEADER_SIZE=8,Gt.LAST_DIGIT_SIZE=2,Gt.FIRST_THREE_DIGITS_SIZE=10;class mt extends di{constructor(e,n,i){super(e),this.dateCode=i,this.firstAIdigits=n}parseInformation(){if(this.getInformation().getSize()!=mt.HEADER_SIZE+mt.GTIN_SIZE+mt.WEIGHT_SIZE+mt.DATE_SIZE)throw new O;let e=new le;return this.encodeCompressedGtin(e,mt.HEADER_SIZE),this.encodeCompressedWeight(e,mt.HEADER_SIZE+mt.GTIN_SIZE,mt.WEIGHT_SIZE),this.encodeCompressedDate(e,mt.HEADER_SIZE+mt.GTIN_SIZE+mt.WEIGHT_SIZE),e.toString()}encodeCompressedDate(e,n){let i=this.getGeneralDecoder().extractNumericValueFromBitArray(n,mt.DATE_SIZE);if(i==38400)return;e.append("("),e.append(this.dateCode),e.append(")");let s=i%32;i/=32;let a=i%12+1;i/=12;let l=i;l/10==0&&e.append("0"),e.append(l),a/10==0&&e.append("0"),e.append(a),s/10==0&&e.append("0"),e.append(s)}addWeightCode(e,n){e.append("("),e.append(this.firstAIdigits),e.append(n/1e5),e.append(")")}checkWeight(e){return e%1e5}}mt.HEADER_SIZE=8,mt.WEIGHT_SIZE=20,mt.DATE_SIZE=16;function us(C){try{if(C.get(1))return new xr(C);if(!C.get(2))return new ui(C);switch(gr.extractNumericValueFromBitArray(C,1,4)){case 4:return new Xu(C);case 5:return new qu(C)}switch(gr.extractNumericValueFromBitArray(C,1,5)){case 12:return new Tn(C);case 13:return new Gt(C)}switch(gr.extractNumericValueFromBitArray(C,1,7)){case 56:return new mt(C,"310","11");case 57:return new mt(C,"320","11");case 58:return new mt(C,"310","13");case 59:return new mt(C,"320","13");case 60:return new mt(C,"310","15");case 61:return new mt(C,"320","15");case 62:return new mt(C,"310","17");case 63:return new mt(C,"320","17")}}catch(e){throw console.log(e),new Zt("unknown decoder: "+C)}}class zn{constructor(e,n,i,s){this.leftchar=e,this.rightchar=n,this.finderpattern=i,this.maybeLast=s}mayBeLast(){return this.maybeLast}getLeftChar(){return this.leftchar}getRightChar(){return this.rightchar}getFinderPattern(){return this.finderpattern}mustBeLast(){return this.rightchar==null}toString(){return"[ "+this.leftchar+", "+this.rightchar+" : "+(this.finderpattern==null?"null":this.finderpattern.getValue())+" ]"}static equals(e,n){return e instanceof zn?zn.equalsOrNull(e.leftchar,n.leftchar)&&zn.equalsOrNull(e.rightchar,n.rightchar)&&zn.equalsOrNull(e.finderpattern,n.finderpattern):!1}static equalsOrNull(e,n){return e===null?n===null:zn.equals(e,n)}hashCode(){return this.leftchar.getValue()^this.rightchar.getValue()^this.finderpattern.getValue()}}class qi{constructor(e,n,i){this.pairs=e,this.rowNumber=n,this.wasReversed=i}getPairs(){return this.pairs}getRowNumber(){return this.rowNumber}isReversed(){return this.wasReversed}isEquivalent(e){return this.checkEqualitity(this,e)}toString(){return"{ "+this.pairs+" }"}equals(e,n){return e instanceof qi?this.checkEqualitity(e,n)&&e.wasReversed===n.wasReversed:!1}checkEqualitity(e,n){if(!e||!n)return;let i;return e.forEach((s,a)=>{n.forEach(l=>{s.getLeftChar().getValue()===l.getLeftChar().getValue()&&s.getRightChar().getValue()===l.getRightChar().getValue()&&s.getFinderPatter().getValue()===l.getFinderPatter().getValue()&&(i=!0)})}),i}}class ce extends jt{constructor(e){super(...arguments),this.pairs=new Array(ce.MAX_PAIRS),this.rows=new Array,this.startEnd=[2],this.verbose=e===!0}decodeRow(e,n,i){this.pairs.length=0,this.startFromEven=!1;try{return ce.constructResult(this.decodeRow2pairs(e,n))}catch(s){this.verbose&&console.log(s)}return this.pairs.length=0,this.startFromEven=!0,ce.constructResult(this.decodeRow2pairs(e,n))}reset(){this.pairs.length=0,this.rows.length=0}decodeRow2pairs(e,n){let i=!1;for(;!i;)try{this.pairs.push(this.retrieveNextPair(n,this.pairs,e))}catch(a){if(a instanceof O){if(!this.pairs.length)throw new O;i=!0}}if(this.checkChecksum())return this.pairs;let s;if(this.rows.length?s=!0:s=!1,this.storeRow(e,!1),s){let a=this.checkRowsBoolean(!1);if(a!=null||(a=this.checkRowsBoolean(!0),a!=null))return a}throw new O}checkRowsBoolean(e){if(this.rows.length>25)return this.rows.length=0,null;this.pairs.length=0,e&&(this.rows=this.rows.reverse());let n=null;try{n=this.checkRows(new Array,0)}catch(i){this.verbose&&console.log(i)}return e&&(this.rows=this.rows.reverse()),n}checkRows(e,n){for(let i=n;i<this.rows.length;i++){let s=this.rows[i];this.pairs.length=0;for(let l of e)this.pairs.push(l.getPairs());if(this.pairs.push(s.getPairs()),!ce.isValidSequence(this.pairs))continue;if(this.checkChecksum())return this.pairs;let a=new Array(e);a.push(s);try{return this.checkRows(a,i+1)}catch(l){this.verbose&&console.log(l)}}throw new O}static isValidSequence(e){for(let n of ce.FINDER_PATTERN_SEQUENCES){if(e.length>n.length)continue;let i=!0;for(let s=0;s<e.length;s++)if(e[s].getFinderPattern().getValue()!=n[s]){i=!1;break}if(i)return!0}return!1}storeRow(e,n){let i=0,s=!1,a=!1;for(;i<this.rows.length;){let l=this.rows[i];if(l.getRowNumber()>e){a=l.isEquivalent(this.pairs);break}s=l.isEquivalent(this.pairs),i++}a||s||ce.isPartialRow(this.pairs,this.rows)||(this.rows.push(i,new qi(this.pairs,e,n)),this.removePartialRows(this.pairs,this.rows))}removePartialRows(e,n){for(let i of n)if(i.getPairs().length!==e.length){for(let s of i.getPairs())for(let a of e)if(zn.equals(s,a))break}}static isPartialRow(e,n){for(let i of n){let s=!0;for(let a of e){let l=!1;for(let d of i.getPairs())if(a.equals(d)){l=!0;break}if(!l){s=!1;break}}if(s)return!0}return!1}getRows(){return this.rows}static constructResult(e){let n=Gu.buildBitArray(e),s=us(n).parseInformation(),a=e[0].getFinderPattern().getResultPoints(),l=e[e.length-1].getFinderPattern().getResultPoints(),d=[a[0],a[1],l[0],l[1]];return new Be(s,null,null,d,ie.RSS_EXPANDED,null)}checkChecksum(){let e=this.pairs.get(0),n=e.getLeftChar(),i=e.getRightChar();if(i==null)return!1;let s=i.getChecksumPortion(),a=2;for(let d=1;d<this.pairs.size();++d){let h=this.pairs.get(d);s+=h.getLeftChar().getChecksumPortion(),a++;let m=h.getRightChar();m!=null&&(s+=m.getChecksumPortion(),a++)}return s%=211,211*(a-4)+s==n.getValue()}static getNextSecondBar(e,n){let i;return e.get(n)?(i=e.getNextUnset(n),i=e.getNextSet(i)):(i=e.getNextSet(n),i=e.getNextUnset(i)),i}retrieveNextPair(e,n,i){let s=n.length%2==0;this.startFromEven&&(s=!s);let a,l=!0,d=-1;do this.findNextPair(e,n,d),a=this.parseFoundFinderPattern(e,i,s),a==null?d=ce.getNextSecondBar(e,this.startEnd[0]):l=!1;while(l);let h=this.decodeDataCharacter(e,a,s,!0);if(!this.isEmptyPair(n)&&n[n.length-1].mustBeLast())throw new O;let m;try{m=this.decodeDataCharacter(e,a,s,!1)}catch(y){m=null,this.verbose&&console.log(y)}return new zn(h,m,a,!0)}isEmptyPair(e){return e.length===0}findNextPair(e,n,i){let s=this.getDecodeFinderCounters();s[0]=0,s[1]=0,s[2]=0,s[3]=0;let a=e.getSize(),l;i>=0?l=i:this.isEmptyPair(n)?l=0:l=n[n.length-1].getFinderPattern().getStartEnd()[1];let d=n.length%2!=0;this.startFromEven&&(d=!d);let h=!1;for(;l<a&&(h=!e.get(l),!!h);)l++;let m=0,y=l;for(let b=l;b<a;b++)if(e.get(b)!=h)s[m]++;else{if(m==3){if(d&&ce.reverseCounters(s),ce.isFinderPattern(s)){this.startEnd[0]=y,this.startEnd[1]=b;return}d&&ce.reverseCounters(s),y+=s[0]+s[1],s[0]=s[2],s[1]=s[3],s[2]=0,s[3]=0,m--}else m++;s[m]=1,h=!h}throw new O}static reverseCounters(e){let n=e.length;for(let i=0;i<n/2;++i){let s=e[i];e[i]=e[n-i-1],e[n-i-1]=s}}parseFoundFinderPattern(e,n,i){let s,a,l;if(i){let m=this.startEnd[0]-1;for(;m>=0&&!e.get(m);)m--;m++,s=this.startEnd[0]-m,a=m,l=this.startEnd[1]}else a=this.startEnd[0],l=e.getNextUnset(this.startEnd[1]+1),s=l-this.startEnd[1];let d=this.getDecodeFinderCounters();R.arraycopy(d,0,d,1,d.length-1),d[0]=s;let h;try{h=this.parseFinderValue(d,ce.FINDER_PATTERNS)}catch{return null}return new ci(h,[a,l],a,l,n)}decodeDataCharacter(e,n,i,s){let a=this.getDataCharacterCounters();for(let at=0;at<a.length;at++)a[at]=0;if(s)ce.recordPatternInReverse(e,n.getStartEnd()[0],a);else{ce.recordPattern(e,n.getStartEnd()[1],a);for(let at=0,$t=a.length-1;at<$t;at++,$t--){let on=a[at];a[at]=a[$t],a[$t]=on}}let l=17,d=Ze.sum(new Int32Array(a))/l,h=(n.getStartEnd()[1]-n.getStartEnd()[0])/15;if(Math.abs(d-h)/h>.3)throw new O;let m=this.getOddCounts(),y=this.getEvenCounts(),b=this.getOddRoundingErrors(),I=this.getEvenRoundingErrors();for(let at=0;at<a.length;at++){let $t=1*a[at]/d,on=$t+.5;if(on<1){if($t<.3)throw new O;on=1}else if(on>8){if($t>8.7)throw new O;on=8}let Cr=at/2;(at&1)==0?(m[Cr]=on,b[Cr]=$t-on):(y[Cr]=on,I[Cr]=$t-on)}this.adjustOddEvenCounts(l);let k=4*n.getValue()+(i?0:2)+(s?0:1)-1,F=0,U=0;for(let at=m.length-1;at>=0;at--){if(ce.isNotA1left(n,i,s)){let $t=ce.WEIGHTS[k][2*at];U+=m[at]*$t}F+=m[at]}let G=0;for(let at=y.length-1;at>=0;at--)if(ce.isNotA1left(n,i,s)){let $t=ce.WEIGHTS[k][2*at+1];G+=y[at]*$t}let Q=U+G;if((F&1)!=0||F>13||F<4)throw new O;let fe=(13-F)/2,pe=ce.SYMBOL_WIDEST[fe],de=9-pe,He=In.getRSSvalue(m,pe,!0),De=In.getRSSvalue(y,de,!1),en=ce.EVEN_TOTAL_SUBSET[fe],yn=ce.GSUM[fe],tn=He*en+De+yn;return new mr(tn,Q)}static isNotA1left(e,n,i){return!(e.getValue()==0&&n&&i)}adjustOddEvenCounts(e){let n=Ze.sum(new Int32Array(this.getOddCounts())),i=Ze.sum(new Int32Array(this.getEvenCounts())),s=!1,a=!1;n>13?a=!0:n<4&&(s=!0);let l=!1,d=!1;i>13?d=!0:i<4&&(l=!0);let h=n+i-e,m=(n&1)==1,y=(i&1)==0;if(h==1)if(m){if(y)throw new O;a=!0}else{if(!y)throw new O;d=!0}else if(h==-1)if(m){if(y)throw new O;s=!0}else{if(!y)throw new O;l=!0}else if(h==0){if(m){if(!y)throw new O;n<i?(s=!0,d=!0):(a=!0,l=!0)}else if(y)throw new O}else throw new O;if(s){if(a)throw new O;ce.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(a&&ce.decrement(this.getOddCounts(),this.getOddRoundingErrors()),l){if(d)throw new O;ce.increment(this.getEvenCounts(),this.getOddRoundingErrors())}d&&ce.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}ce.SYMBOL_WIDEST=[7,5,4,3,1],ce.EVEN_TOTAL_SUBSET=[4,20,52,104,204],ce.GSUM=[0,348,1388,2948,3988],ce.FINDER_PATTERNS=[Int32Array.from([1,8,4,1]),Int32Array.from([3,6,4,1]),Int32Array.from([3,4,6,1]),Int32Array.from([3,2,8,1]),Int32Array.from([2,6,5,1]),Int32Array.from([2,2,9,1])],ce.WEIGHTS=[[1,3,9,27,81,32,96,77],[20,60,180,118,143,7,21,63],[189,145,13,39,117,140,209,205],[193,157,49,147,19,57,171,91],[62,186,136,197,169,85,44,132],[185,133,188,142,4,12,36,108],[113,128,173,97,80,29,87,50],[150,28,84,41,123,158,52,156],[46,138,203,187,139,206,196,166],[76,17,51,153,37,111,122,155],[43,129,176,106,107,110,119,146],[16,48,144,10,30,90,59,177],[109,116,137,200,178,112,125,164],[70,210,208,202,184,130,179,115],[134,191,151,31,93,68,204,190],[148,22,66,198,172,94,71,2],[6,18,54,162,64,192,154,40],[120,149,25,75,14,42,126,167],[79,26,78,23,69,207,199,175],[103,98,83,38,114,131,182,124],[161,61,183,127,170,88,53,159],[55,165,73,8,24,72,5,15],[45,135,194,160,58,174,100,89]],ce.FINDER_PAT_A=0,ce.FINDER_PAT_B=1,ce.FINDER_PAT_C=2,ce.FINDER_PAT_D=3,ce.FINDER_PAT_E=4,ce.FINDER_PAT_F=5,ce.FINDER_PATTERN_SEQUENCES=[[ce.FINDER_PAT_A,ce.FINDER_PAT_A],[ce.FINDER_PAT_A,ce.FINDER_PAT_B,ce.FINDER_PAT_B],[ce.FINDER_PAT_A,ce.FINDER_PAT_C,ce.FINDER_PAT_B,ce.FINDER_PAT_D],[ce.FINDER_PAT_A,ce.FINDER_PAT_E,ce.FINDER_PAT_B,ce.FINDER_PAT_D,ce.FINDER_PAT_C],[ce.FINDER_PAT_A,ce.FINDER_PAT_E,ce.FINDER_PAT_B,ce.FINDER_PAT_D,ce.FINDER_PAT_D,ce.FINDER_PAT_F],[ce.FINDER_PAT_A,ce.FINDER_PAT_E,ce.FINDER_PAT_B,ce.FINDER_PAT_D,ce.FINDER_PAT_E,ce.FINDER_PAT_F,ce.FINDER_PAT_F],[ce.FINDER_PAT_A,ce.FINDER_PAT_A,ce.FINDER_PAT_B,ce.FINDER_PAT_B,ce.FINDER_PAT_C,ce.FINDER_PAT_C,ce.FINDER_PAT_D,ce.FINDER_PAT_D],[ce.FINDER_PAT_A,ce.FINDER_PAT_A,ce.FINDER_PAT_B,ce.FINDER_PAT_B,ce.FINDER_PAT_C,ce.FINDER_PAT_C,ce.FINDER_PAT_D,ce.FINDER_PAT_E,ce.FINDER_PAT_E],[ce.FINDER_PAT_A,ce.FINDER_PAT_A,ce.FINDER_PAT_B,ce.FINDER_PAT_B,ce.FINDER_PAT_C,ce.FINDER_PAT_C,ce.FINDER_PAT_D,ce.FINDER_PAT_E,ce.FINDER_PAT_F,ce.FINDER_PAT_F],[ce.FINDER_PAT_A,ce.FINDER_PAT_A,ce.FINDER_PAT_B,ce.FINDER_PAT_B,ce.FINDER_PAT_C,ce.FINDER_PAT_D,ce.FINDER_PAT_D,ce.FINDER_PAT_E,ce.FINDER_PAT_E,ce.FINDER_PAT_F,ce.FINDER_PAT_F]],ce.MAX_PAIRS=11;class Yu extends mr{constructor(e,n,i){super(e,n),this.count=0,this.finderPattern=i}getFinderPattern(){return this.finderPattern}getCount(){return this.count}incrementCount(){this.count++}}class It extends jt{constructor(){super(...arguments),this.possibleLeftPairs=[],this.possibleRightPairs=[]}decodeRow(e,n,i){const s=this.decodePair(n,!1,e,i);It.addOrTally(this.possibleLeftPairs,s),n.reverse();let a=this.decodePair(n,!0,e,i);It.addOrTally(this.possibleRightPairs,a),n.reverse();for(let l of this.possibleLeftPairs)if(l.getCount()>1){for(let d of this.possibleRightPairs)if(d.getCount()>1&&It.checkChecksum(l,d))return It.constructResult(l,d)}throw new O}static addOrTally(e,n){if(n==null)return;let i=!1;for(let s of e)if(s.getValue()===n.getValue()){s.incrementCount(),i=!0;break}i||e.push(n)}reset(){this.possibleLeftPairs.length=0,this.possibleRightPairs.length=0}static constructResult(e,n){let i=4537077*e.getValue()+n.getValue(),s=new String(i).toString(),a=new le;for(let m=13-s.length;m>0;m--)a.append("0");a.append(s);let l=0;for(let m=0;m<13;m++){let y=a.charAt(m).charCodeAt(0)-48;l+=(m&1)===0?3*y:y}l=10-l%10,l===10&&(l=0),a.append(l.toString());let d=e.getFinderPattern().getResultPoints(),h=n.getFinderPattern().getResultPoints();return new Be(a.toString(),null,0,[d[0],d[1],h[0],h[1]],ie.RSS_14,new Date().getTime())}static checkChecksum(e,n){let i=(e.getChecksumPortion()+16*n.getChecksumPortion())%79,s=9*e.getFinderPattern().getValue()+n.getFinderPattern().getValue();return s>72&&s--,s>8&&s--,i===s}decodePair(e,n,i,s){try{let a=this.findFinderPattern(e,n),l=this.parseFoundFinderPattern(e,i,n,a),d=s==null?null:s.get(j.NEED_RESULT_POINT_CALLBACK);if(d!=null){let y=(a[0]+a[1])/2;n&&(y=e.getSize()-1-y),d.foundPossibleResultPoint(new N(y,i))}let h=this.decodeDataCharacter(e,l,!0),m=this.decodeDataCharacter(e,l,!1);return new Yu(1597*h.getValue()+m.getValue(),h.getChecksumPortion()+4*m.getChecksumPortion(),l)}catch{return null}}decodeDataCharacter(e,n,i){let s=this.getDataCharacterCounters();for(let G=0;G<s.length;G++)s[G]=0;if(i)Te.recordPatternInReverse(e,n.getStartEnd()[0],s);else{Te.recordPattern(e,n.getStartEnd()[1]+1,s);for(let G=0,Q=s.length-1;G<Q;G++,Q--){let fe=s[G];s[G]=s[Q],s[Q]=fe}}let a=i?16:15,l=Ze.sum(new Int32Array(s))/a,d=this.getOddCounts(),h=this.getEvenCounts(),m=this.getOddRoundingErrors(),y=this.getEvenRoundingErrors();for(let G=0;G<s.length;G++){let Q=s[G]/l,fe=Math.floor(Q+.5);fe<1?fe=1:fe>8&&(fe=8);let pe=Math.floor(G/2);(G&1)===0?(d[pe]=fe,m[pe]=Q-fe):(h[pe]=fe,y[pe]=Q-fe)}this.adjustOddEvenCounts(i,a);let b=0,I=0;for(let G=d.length-1;G>=0;G--)I*=9,I+=d[G],b+=d[G];let k=0,F=0;for(let G=h.length-1;G>=0;G--)k*=9,k+=h[G],F+=h[G];let U=I+3*k;if(i){if((b&1)!==0||b>12||b<4)throw new O;let G=(12-b)/2,Q=It.OUTSIDE_ODD_WIDEST[G],fe=9-Q,pe=In.getRSSvalue(d,Q,!1),de=In.getRSSvalue(h,fe,!0),He=It.OUTSIDE_EVEN_TOTAL_SUBSET[G],De=It.OUTSIDE_GSUM[G];return new mr(pe*He+de+De,U)}else{if((F&1)!==0||F>10||F<4)throw new O;let G=(10-F)/2,Q=It.INSIDE_ODD_WIDEST[G],fe=9-Q,pe=In.getRSSvalue(d,Q,!0),de=In.getRSSvalue(h,fe,!1),He=It.INSIDE_ODD_TOTAL_SUBSET[G],De=It.INSIDE_GSUM[G];return new mr(de*He+pe+De,U)}}findFinderPattern(e,n){let i=this.getDecodeFinderCounters();i[0]=0,i[1]=0,i[2]=0,i[3]=0;let s=e.getSize(),a=!1,l=0;for(;l<s&&(a=!e.get(l),n!==a);)l++;let d=0,h=l;for(let m=l;m<s;m++)if(e.get(m)!==a)i[d]++;else{if(d===3){if(jt.isFinderPattern(i))return[h,m];h+=i[0]+i[1],i[0]=i[2],i[1]=i[3],i[2]=0,i[3]=0,d--}else d++;i[d]=1,a=!a}throw new O}parseFoundFinderPattern(e,n,i,s){let a=e.get(s[0]),l=s[0]-1;for(;l>=0&&a!==e.get(l);)l--;l++;const d=s[0]-l,h=this.getDecodeFinderCounters(),m=new Int32Array(h.length);R.arraycopy(h,0,m,1,h.length-1),m[0]=d;const y=this.parseFinderValue(m,It.FINDER_PATTERNS);let b=l,I=s[1];return i&&(b=e.getSize()-1-b,I=e.getSize()-1-I),new ci(y,[l,s[1]],b,I,n)}adjustOddEvenCounts(e,n){let i=Ze.sum(new Int32Array(this.getOddCounts())),s=Ze.sum(new Int32Array(this.getEvenCounts())),a=!1,l=!1,d=!1,h=!1;e?(i>12?l=!0:i<4&&(a=!0),s>12?h=!0:s<4&&(d=!0)):(i>11?l=!0:i<5&&(a=!0),s>10?h=!0:s<4&&(d=!0));let m=i+s-n,y=(i&1)===(e?1:0),b=(s&1)===1;if(m===1)if(y){if(b)throw new O;l=!0}else{if(!b)throw new O;h=!0}else if(m===-1)if(y){if(b)throw new O;a=!0}else{if(!b)throw new O;d=!0}else if(m===0){if(y){if(!b)throw new O;i<s?(a=!0,h=!0):(l=!0,d=!0)}else if(b)throw new O}else throw new O;if(a){if(l)throw new O;jt.increment(this.getOddCounts(),this.getOddRoundingErrors())}if(l&&jt.decrement(this.getOddCounts(),this.getOddRoundingErrors()),d){if(h)throw new O;jt.increment(this.getEvenCounts(),this.getOddRoundingErrors())}h&&jt.decrement(this.getEvenCounts(),this.getEvenRoundingErrors())}}It.OUTSIDE_EVEN_TOTAL_SUBSET=[1,10,34,70,126],It.INSIDE_ODD_TOTAL_SUBSET=[4,20,48,81],It.OUTSIDE_GSUM=[0,161,961,2015,2715],It.INSIDE_GSUM=[0,336,1036,1516],It.OUTSIDE_ODD_WIDEST=[8,6,4,3,1],It.INSIDE_ODD_WIDEST=[2,4,6,8],It.FINDER_PATTERNS=[Int32Array.from([3,8,2,1]),Int32Array.from([3,5,5,1]),Int32Array.from([3,3,7,1]),Int32Array.from([3,1,9,1]),Int32Array.from([2,7,4,1]),Int32Array.from([2,5,6,1]),Int32Array.from([2,3,8,1]),Int32Array.from([1,5,7,1]),Int32Array.from([1,3,9,1])];class yr extends Te{constructor(e,n){super(),this.readers=[],this.verbose=n===!0;const i=e?e.get(j.POSSIBLE_FORMATS):null,s=e&&e.get(j.ASSUME_CODE_39_CHECK_DIGIT)!==void 0;i?((i.includes(ie.EAN_13)||i.includes(ie.UPC_A)||i.includes(ie.EAN_8)||i.includes(ie.UPC_E))&&this.readers.push(new Wi(e)),i.includes(ie.CODE_39)&&this.readers.push(new Ot(s)),i.includes(ie.CODE_128)&&this.readers.push(new xe),i.includes(ie.ITF)&&this.readers.push(new ot),i.includes(ie.RSS_14)&&this.readers.push(new It),i.includes(ie.RSS_EXPANDED)&&this.readers.push(new ce(this.verbose))):(this.readers.push(new Wi(e)),this.readers.push(new Ot),this.readers.push(new Wi(e)),this.readers.push(new xe),this.readers.push(new ot),this.readers.push(new It),this.readers.push(new ce(this.verbose)))}decodeRow(e,n,i){for(let s=0;s<this.readers.length;s++)try{return this.readers[s].decodeRow(e,n,i)}catch{}throw new O}reset(){this.readers.forEach(e=>e.reset())}}class Ju extends je{constructor(e=500,n){super(new yr(n),e,n)}}class Ke{constructor(e,n,i){this.ecCodewords=e,this.ecBlocks=[n],i&&this.ecBlocks.push(i)}getECCodewords(){return this.ecCodewords}getECBlocks(){return this.ecBlocks}}class Ye{constructor(e,n){this.count=e,this.dataCodewords=n}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class We{constructor(e,n,i,s,a,l){this.versionNumber=e,this.symbolSizeRows=n,this.symbolSizeColumns=i,this.dataRegionSizeRows=s,this.dataRegionSizeColumns=a,this.ecBlocks=l;let d=0;const h=l.getECCodewords(),m=l.getECBlocks();for(let y of m)d+=y.getCount()*(y.getDataCodewords()+h);this.totalCodewords=d}getVersionNumber(){return this.versionNumber}getSymbolSizeRows(){return this.symbolSizeRows}getSymbolSizeColumns(){return this.symbolSizeColumns}getDataRegionSizeRows(){return this.dataRegionSizeRows}getDataRegionSizeColumns(){return this.dataRegionSizeColumns}getTotalCodewords(){return this.totalCodewords}getECBlocks(){return this.ecBlocks}static getVersionForDimensions(e,n){if((e&1)!==0||(n&1)!==0)throw new z;for(let i of We.VERSIONS)if(i.symbolSizeRows===e&&i.symbolSizeColumns===n)return i;throw new z}toString(){return""+this.versionNumber}static buildVersions(){return[new We(1,10,10,8,8,new Ke(5,new Ye(1,3))),new We(2,12,12,10,10,new Ke(7,new Ye(1,5))),new We(3,14,14,12,12,new Ke(10,new Ye(1,8))),new We(4,16,16,14,14,new Ke(12,new Ye(1,12))),new We(5,18,18,16,16,new Ke(14,new Ye(1,18))),new We(6,20,20,18,18,new Ke(18,new Ye(1,22))),new We(7,22,22,20,20,new Ke(20,new Ye(1,30))),new We(8,24,24,22,22,new Ke(24,new Ye(1,36))),new We(9,26,26,24,24,new Ke(28,new Ye(1,44))),new We(10,32,32,14,14,new Ke(36,new Ye(1,62))),new We(11,36,36,16,16,new Ke(42,new Ye(1,86))),new We(12,40,40,18,18,new Ke(48,new Ye(1,114))),new We(13,44,44,20,20,new Ke(56,new Ye(1,144))),new We(14,48,48,22,22,new Ke(68,new Ye(1,174))),new We(15,52,52,24,24,new Ke(42,new Ye(2,102))),new We(16,64,64,14,14,new Ke(56,new Ye(2,140))),new We(17,72,72,16,16,new Ke(36,new Ye(4,92))),new We(18,80,80,18,18,new Ke(48,new Ye(4,114))),new We(19,88,88,20,20,new Ke(56,new Ye(4,144))),new We(20,96,96,22,22,new Ke(68,new Ye(4,174))),new We(21,104,104,24,24,new Ke(56,new Ye(6,136))),new We(22,120,120,18,18,new Ke(68,new Ye(6,175))),new We(23,132,132,20,20,new Ke(62,new Ye(8,163))),new We(24,144,144,22,22,new Ke(62,new Ye(8,156),new Ye(2,155))),new We(25,8,18,6,16,new Ke(7,new Ye(1,5))),new We(26,8,32,6,14,new Ke(11,new Ye(1,10))),new We(27,12,26,10,24,new Ke(14,new Ye(1,16))),new We(28,12,36,10,16,new Ke(18,new Ye(1,22))),new We(29,16,36,14,16,new Ke(24,new Ye(1,32))),new We(30,16,48,14,22,new Ke(28,new Ye(1,49)))]}}We.VERSIONS=We.buildVersions();class Yi{constructor(e){const n=e.getHeight();if(n<8||n>144||(n&1)!==0)throw new z;this.version=Yi.readVersion(e),this.mappingBitMatrix=this.extractDataRegion(e),this.readMappingMatrix=new te(this.mappingBitMatrix.getWidth(),this.mappingBitMatrix.getHeight())}getVersion(){return this.version}static readVersion(e){const n=e.getHeight(),i=e.getWidth();return We.getVersionForDimensions(n,i)}readCodewords(){const e=new Int8Array(this.version.getTotalCodewords());let n=0,i=4,s=0;const a=this.mappingBitMatrix.getHeight(),l=this.mappingBitMatrix.getWidth();let d=!1,h=!1,m=!1,y=!1;do if(i===a&&s===0&&!d)e[n++]=this.readCorner1(a,l)&255,i-=2,s+=2,d=!0;else if(i===a-2&&s===0&&(l&3)!==0&&!h)e[n++]=this.readCorner2(a,l)&255,i-=2,s+=2,h=!0;else if(i===a+4&&s===2&&(l&7)===0&&!m)e[n++]=this.readCorner3(a,l)&255,i-=2,s+=2,m=!0;else if(i===a-2&&s===0&&(l&7)===4&&!y)e[n++]=this.readCorner4(a,l)&255,i-=2,s+=2,y=!0;else{do i<a&&s>=0&&!this.readMappingMatrix.get(s,i)&&(e[n++]=this.readUtah(i,s,a,l)&255),i-=2,s+=2;while(i>=0&&s<l);i+=1,s+=3;do i>=0&&s<l&&!this.readMappingMatrix.get(s,i)&&(e[n++]=this.readUtah(i,s,a,l)&255),i+=2,s-=2;while(i<a&&s>=0);i+=3,s+=1}while(i<a||s<l);if(n!==this.version.getTotalCodewords())throw new z;return e}readModule(e,n,i,s){return e<0&&(e+=i,n+=4-(i+4&7)),n<0&&(n+=s,e+=4-(s+4&7)),this.readMappingMatrix.set(n,e),this.mappingBitMatrix.get(n,e)}readUtah(e,n,i,s){let a=0;return this.readModule(e-2,n-2,i,s)&&(a|=1),a<<=1,this.readModule(e-2,n-1,i,s)&&(a|=1),a<<=1,this.readModule(e-1,n-2,i,s)&&(a|=1),a<<=1,this.readModule(e-1,n-1,i,s)&&(a|=1),a<<=1,this.readModule(e-1,n,i,s)&&(a|=1),a<<=1,this.readModule(e,n-2,i,s)&&(a|=1),a<<=1,this.readModule(e,n-1,i,s)&&(a|=1),a<<=1,this.readModule(e,n,i,s)&&(a|=1),a}readCorner1(e,n){let i=0;return this.readModule(e-1,0,e,n)&&(i|=1),i<<=1,this.readModule(e-1,1,e,n)&&(i|=1),i<<=1,this.readModule(e-1,2,e,n)&&(i|=1),i<<=1,this.readModule(0,n-2,e,n)&&(i|=1),i<<=1,this.readModule(0,n-1,e,n)&&(i|=1),i<<=1,this.readModule(1,n-1,e,n)&&(i|=1),i<<=1,this.readModule(2,n-1,e,n)&&(i|=1),i<<=1,this.readModule(3,n-1,e,n)&&(i|=1),i}readCorner2(e,n){let i=0;return this.readModule(e-3,0,e,n)&&(i|=1),i<<=1,this.readModule(e-2,0,e,n)&&(i|=1),i<<=1,this.readModule(e-1,0,e,n)&&(i|=1),i<<=1,this.readModule(0,n-4,e,n)&&(i|=1),i<<=1,this.readModule(0,n-3,e,n)&&(i|=1),i<<=1,this.readModule(0,n-2,e,n)&&(i|=1),i<<=1,this.readModule(0,n-1,e,n)&&(i|=1),i<<=1,this.readModule(1,n-1,e,n)&&(i|=1),i}readCorner3(e,n){let i=0;return this.readModule(e-1,0,e,n)&&(i|=1),i<<=1,this.readModule(e-1,n-1,e,n)&&(i|=1),i<<=1,this.readModule(0,n-3,e,n)&&(i|=1),i<<=1,this.readModule(0,n-2,e,n)&&(i|=1),i<<=1,this.readModule(0,n-1,e,n)&&(i|=1),i<<=1,this.readModule(1,n-3,e,n)&&(i|=1),i<<=1,this.readModule(1,n-2,e,n)&&(i|=1),i<<=1,this.readModule(1,n-1,e,n)&&(i|=1),i}readCorner4(e,n){let i=0;return this.readModule(e-3,0,e,n)&&(i|=1),i<<=1,this.readModule(e-2,0,e,n)&&(i|=1),i<<=1,this.readModule(e-1,0,e,n)&&(i|=1),i<<=1,this.readModule(0,n-2,e,n)&&(i|=1),i<<=1,this.readModule(0,n-1,e,n)&&(i|=1),i<<=1,this.readModule(1,n-1,e,n)&&(i|=1),i<<=1,this.readModule(2,n-1,e,n)&&(i|=1),i<<=1,this.readModule(3,n-1,e,n)&&(i|=1),i}extractDataRegion(e){const n=this.version.getSymbolSizeRows(),i=this.version.getSymbolSizeColumns();if(e.getHeight()!==n)throw new E("Dimension of bitMatrix must match the version size");const s=this.version.getDataRegionSizeRows(),a=this.version.getDataRegionSizeColumns(),l=n/s|0,d=i/a|0,h=l*s,m=d*a,y=new te(m,h);for(let b=0;b<l;++b){const I=b*s;for(let k=0;k<d;++k){const F=k*a;for(let U=0;U<s;++U){const G=b*(s+2)+1+U,Q=I+U;for(let fe=0;fe<a;++fe){const pe=k*(a+2)+1+fe;if(e.get(pe,G)){const de=F+fe;y.set(de,Q)}}}}}return y}}class Ji{constructor(e,n){this.numDataCodewords=e,this.codewords=n}static getDataBlocks(e,n){const i=n.getECBlocks();let s=0;const a=i.getECBlocks();for(let U of a)s+=U.getCount();const l=new Array(s);let d=0;for(let U of a)for(let G=0;G<U.getCount();G++){const Q=U.getDataCodewords(),fe=i.getECCodewords()+Q;l[d++]=new Ji(Q,new Uint8Array(fe))}const m=l[0].codewords.length-i.getECCodewords(),y=m-1;let b=0;for(let U=0;U<y;U++)for(let G=0;G<d;G++)l[G].codewords[U]=e[b++];const I=n.getVersionNumber()===24,k=I?8:d;for(let U=0;U<k;U++)l[U].codewords[m-1]=e[b++];const F=l[0].codewords.length;for(let U=m;U<F;U++)for(let G=0;G<d;G++){const Q=I?(G+8)%d:G,fe=I&&Q>7?U-1:U;l[Q].codewords[fe]=e[b++]}if(b!==e.length)throw new E;return l}getNumDataCodewords(){return this.numDataCodewords}getCodewords(){return this.codewords}}class Ki{constructor(e){this.bytes=e,this.byteOffset=0,this.bitOffset=0}getBitOffset(){return this.bitOffset}getByteOffset(){return this.byteOffset}readBits(e){if(e<1||e>32||e>this.available())throw new E(""+e);let n=0,i=this.bitOffset,s=this.byteOffset;const a=this.bytes;if(i>0){const l=8-i,d=e<l?e:l,h=l-d,m=255>>8-d<<h;n=(a[s]&m)>>h,e-=d,i+=d,i===8&&(i=0,s++)}if(e>0){for(;e>=8;)n=n<<8|a[s]&255,s++,e-=8;if(e>0){const l=8-e,d=255>>l<<l;n=n<<e|(a[s]&d)>>l,i+=e}}return this.bitOffset=i,this.byteOffset=s,n}available(){return 8*(this.bytes.length-this.byteOffset)-this.bitOffset}}var Rt;(function(C){C[C.PAD_ENCODE=0]="PAD_ENCODE",C[C.ASCII_ENCODE=1]="ASCII_ENCODE",C[C.C40_ENCODE=2]="C40_ENCODE",C[C.TEXT_ENCODE=3]="TEXT_ENCODE",C[C.ANSIX12_ENCODE=4]="ANSIX12_ENCODE",C[C.EDIFACT_ENCODE=5]="EDIFACT_ENCODE",C[C.BASE256_ENCODE=6]="BASE256_ENCODE"})(Rt||(Rt={}));class Vn{static decode(e){const n=new Ki(e),i=new le,s=new le,a=new Array;let l=Rt.ASCII_ENCODE;do if(l===Rt.ASCII_ENCODE)l=this.decodeAsciiSegment(n,i,s);else{switch(l){case Rt.C40_ENCODE:this.decodeC40Segment(n,i);break;case Rt.TEXT_ENCODE:this.decodeTextSegment(n,i);break;case Rt.ANSIX12_ENCODE:this.decodeAnsiX12Segment(n,i);break;case Rt.EDIFACT_ENCODE:this.decodeEdifactSegment(n,i);break;case Rt.BASE256_ENCODE:this.decodeBase256Segment(n,i,a);break;default:throw new z}l=Rt.ASCII_ENCODE}while(l!==Rt.PAD_ENCODE&&n.available()>0);return s.length()>0&&i.append(s.toString()),new ke(e,i.toString(),a.length===0?null:a,null)}static decodeAsciiSegment(e,n,i){let s=!1;do{let a=e.readBits(8);if(a===0)throw new z;if(a<=128)return s&&(a+=128),n.append(String.fromCharCode(a-1)),Rt.ASCII_ENCODE;if(a===129)return Rt.PAD_ENCODE;if(a<=229){const l=a-130;l<10&&n.append("0"),n.append(""+l)}else switch(a){case 230:return Rt.C40_ENCODE;case 231:return Rt.BASE256_ENCODE;case 232:n.append("");break;case 233:case 234:break;case 235:s=!0;break;case 236:n.append("[)>05"),i.insert(0,"");break;case 237:n.append("[)>06"),i.insert(0,"");break;case 238:return Rt.ANSIX12_ENCODE;case 239:return Rt.TEXT_ENCODE;case 240:return Rt.EDIFACT_ENCODE;case 241:break;default:if(a!==254||e.available()!==0)throw new z;break}}while(e.available()>0);return Rt.ASCII_ENCODE}static decodeC40Segment(e,n){let i=!1;const s=[];let a=0;do{if(e.available()===8)return;const l=e.readBits(8);if(l===254)return;this.parseTwoBytes(l,e.readBits(8),s);for(let d=0;d<3;d++){const h=s[d];switch(a){case 0:if(h<3)a=h+1;else if(h<this.C40_BASIC_SET_CHARS.length){const m=this.C40_BASIC_SET_CHARS[h];i?(n.append(String.fromCharCode(m.charCodeAt(0)+128)),i=!1):n.append(m)}else throw new z;break;case 1:i?(n.append(String.fromCharCode(h+128)),i=!1):n.append(String.fromCharCode(h)),a=0;break;case 2:if(h<this.C40_SHIFT2_SET_CHARS.length){const m=this.C40_SHIFT2_SET_CHARS[h];i?(n.append(String.fromCharCode(m.charCodeAt(0)+128)),i=!1):n.append(m)}else switch(h){case 27:n.append("");break;case 30:i=!0;break;default:throw new z}a=0;break;case 3:i?(n.append(String.fromCharCode(h+224)),i=!1):n.append(String.fromCharCode(h+96)),a=0;break;default:throw new z}}}while(e.available()>0)}static decodeTextSegment(e,n){let i=!1,s=[],a=0;do{if(e.available()===8)return;const l=e.readBits(8);if(l===254)return;this.parseTwoBytes(l,e.readBits(8),s);for(let d=0;d<3;d++){const h=s[d];switch(a){case 0:if(h<3)a=h+1;else if(h<this.TEXT_BASIC_SET_CHARS.length){const m=this.TEXT_BASIC_SET_CHARS[h];i?(n.append(String.fromCharCode(m.charCodeAt(0)+128)),i=!1):n.append(m)}else throw new z;break;case 1:i?(n.append(String.fromCharCode(h+128)),i=!1):n.append(String.fromCharCode(h)),a=0;break;case 2:if(h<this.TEXT_SHIFT2_SET_CHARS.length){const m=this.TEXT_SHIFT2_SET_CHARS[h];i?(n.append(String.fromCharCode(m.charCodeAt(0)+128)),i=!1):n.append(m)}else switch(h){case 27:n.append("");break;case 30:i=!0;break;default:throw new z}a=0;break;case 3:if(h<this.TEXT_SHIFT3_SET_CHARS.length){const m=this.TEXT_SHIFT3_SET_CHARS[h];i?(n.append(String.fromCharCode(m.charCodeAt(0)+128)),i=!1):n.append(m),a=0}else throw new z;break;default:throw new z}}}while(e.available()>0)}static decodeAnsiX12Segment(e,n){const i=[];do{if(e.available()===8)return;const s=e.readBits(8);if(s===254)return;this.parseTwoBytes(s,e.readBits(8),i);for(let a=0;a<3;a++){const l=i[a];switch(l){case 0:n.append("\r");break;case 1:n.append("*");break;case 2:n.append(">");break;case 3:n.append(" ");break;default:if(l<14)n.append(String.fromCharCode(l+44));else if(l<40)n.append(String.fromCharCode(l+51));else throw new z;break}}}while(e.available()>0)}static parseTwoBytes(e,n,i){let s=(e<<8)+n-1,a=Math.floor(s/1600);i[0]=a,s-=a*1600,a=Math.floor(s/40),i[1]=a,i[2]=s-a*40}static decodeEdifactSegment(e,n){do{if(e.available()<=16)return;for(let i=0;i<4;i++){let s=e.readBits(6);if(s===31){const a=8-e.getBitOffset();a!==8&&e.readBits(a);return}(s&32)===0&&(s|=64),n.append(String.fromCharCode(s))}}while(e.available()>0)}static decodeBase256Segment(e,n,i){let s=1+e.getByteOffset();const a=this.unrandomize255State(e.readBits(8),s++);let l;if(a===0?l=e.available()/8|0:a<250?l=a:l=250*(a-249)+this.unrandomize255State(e.readBits(8),s++),l<0)throw new z;const d=new Uint8Array(l);for(let h=0;h<l;h++){if(e.available()<8)throw new z;d[h]=this.unrandomize255State(e.readBits(8),s++)}i.push(d);try{n.append(re.decode(d,ne.ISO88591))}catch(h){throw new Zt("Platform does not support required encoding: "+h.message)}}static unrandomize255State(e,n){const i=149*n%255+1,s=e-i;return s>=0?s:s+256}}Vn.C40_BASIC_SET_CHARS=["*","*","*"," ","0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],Vn.C40_SHIFT2_SET_CHARS=["!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/",":",";","<","=",">","?","@","[","\\","]","^","_"],Vn.TEXT_BASIC_SET_CHARS=["*","*","*"," ","0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],Vn.TEXT_SHIFT2_SET_CHARS=Vn.C40_SHIFT2_SET_CHARS,Vn.TEXT_SHIFT3_SET_CHARS=["`","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","{","|","}","~",""];class Ku{constructor(){this.rsDecoder=new En(Le.DATA_MATRIX_FIELD_256)}decode(e){const n=new Yi(e),i=n.getVersion(),s=n.readCodewords(),a=Ji.getDataBlocks(s,i);let l=0;for(let m of a)l+=m.getNumDataCodewords();const d=new Uint8Array(l),h=a.length;for(let m=0;m<h;m++){const y=a[m],b=y.getCodewords(),I=y.getNumDataCodewords();this.correctErrors(b,I);for(let k=0;k<I;k++)d[k*h+m]=b[k]}return Vn.decode(d)}correctErrors(e,n){const i=new Int32Array(e);try{this.rsDecoder.decode(i,e.length-n)}catch{throw new M}for(let s=0;s<n;s++)e[s]=i[s]}}class kt{constructor(e){this.image=e,this.rectangleDetector=new _t(this.image)}detect(){const e=this.rectangleDetector.detect();let n=this.detectSolid1(e);if(n=this.detectSolid2(n),n[3]=this.correctTopRight(n),!n[3])throw new O;n=this.shiftToModuleCenter(n);const i=n[0],s=n[1],a=n[2],l=n[3];let d=this.transitionsBetween(i,l)+1,h=this.transitionsBetween(a,l)+1;(d&1)===1&&(d+=1),(h&1)===1&&(h+=1),4*d<7*h&&4*h<7*d&&(d=h=Math.max(d,h));let m=kt.sampleGrid(this.image,i,s,a,l,d,h);return new ye(m,[i,s,a,l])}static shiftPoint(e,n,i){let s=(n.getX()-e.getX())/(i+1),a=(n.getY()-e.getY())/(i+1);return new N(e.getX()+s,e.getY()+a)}static moveAway(e,n,i){let s=e.getX(),a=e.getY();return s<n?s-=1:s+=1,a<i?a-=1:a+=1,new N(s,a)}detectSolid1(e){let n=e[0],i=e[1],s=e[3],a=e[2],l=this.transitionsBetween(n,i),d=this.transitionsBetween(i,s),h=this.transitionsBetween(s,a),m=this.transitionsBetween(a,n),y=l,b=[a,n,i,s];return y>d&&(y=d,b[0]=n,b[1]=i,b[2]=s,b[3]=a),y>h&&(y=h,b[0]=i,b[1]=s,b[2]=a,b[3]=n),y>m&&(b[0]=s,b[1]=a,b[2]=n,b[3]=i),b}detectSolid2(e){let n=e[0],i=e[1],s=e[2],a=e[3],l=this.transitionsBetween(n,a),d=kt.shiftPoint(i,s,(l+1)*4),h=kt.shiftPoint(s,i,(l+1)*4),m=this.transitionsBetween(d,n),y=this.transitionsBetween(h,a);return m<y?(e[0]=n,e[1]=i,e[2]=s,e[3]=a):(e[0]=i,e[1]=s,e[2]=a,e[3]=n),e}correctTopRight(e){let n=e[0],i=e[1],s=e[2],a=e[3],l=this.transitionsBetween(n,a),d=this.transitionsBetween(i,a),h=kt.shiftPoint(n,i,(d+1)*4),m=kt.shiftPoint(s,i,(l+1)*4);l=this.transitionsBetween(h,a),d=this.transitionsBetween(m,a);let y=new N(a.getX()+(s.getX()-i.getX())/(l+1),a.getY()+(s.getY()-i.getY())/(l+1)),b=new N(a.getX()+(n.getX()-i.getX())/(d+1),a.getY()+(n.getY()-i.getY())/(d+1));if(!this.isValid(y))return this.isValid(b)?b:null;if(!this.isValid(b))return y;let I=this.transitionsBetween(h,y)+this.transitionsBetween(m,y),k=this.transitionsBetween(h,b)+this.transitionsBetween(m,b);return I>k?y:b}shiftToModuleCenter(e){let n=e[0],i=e[1],s=e[2],a=e[3],l=this.transitionsBetween(n,a)+1,d=this.transitionsBetween(s,a)+1,h=kt.shiftPoint(n,i,d*4),m=kt.shiftPoint(s,i,l*4);l=this.transitionsBetween(h,a)+1,d=this.transitionsBetween(m,a)+1,(l&1)===1&&(l+=1),(d&1)===1&&(d+=1);let y=(n.getX()+i.getX()+s.getX()+a.getX())/4,b=(n.getY()+i.getY()+s.getY()+a.getY())/4;n=kt.moveAway(n,y,b),i=kt.moveAway(i,y,b),s=kt.moveAway(s,y,b),a=kt.moveAway(a,y,b);let I,k;return h=kt.shiftPoint(n,i,d*4),h=kt.shiftPoint(h,a,l*4),I=kt.shiftPoint(i,n,d*4),I=kt.shiftPoint(I,s,l*4),m=kt.shiftPoint(s,a,d*4),m=kt.shiftPoint(m,i,l*4),k=kt.shiftPoint(a,s,d*4),k=kt.shiftPoint(k,n,l*4),[h,I,m,k]}isValid(e){return e.getX()>=0&&e.getX()<this.image.getWidth()&&e.getY()>0&&e.getY()<this.image.getHeight()}static sampleGrid(e,n,i,s,a,l,d){return An.getInstance().sampleGrid(e,l,d,.5,.5,l-.5,.5,l-.5,d-.5,.5,d-.5,n.getX(),n.getY(),a.getX(),a.getY(),s.getX(),s.getY(),i.getX(),i.getY())}transitionsBetween(e,n){let i=Math.trunc(e.getX()),s=Math.trunc(e.getY()),a=Math.trunc(n.getX()),l=Math.trunc(n.getY()),d=Math.abs(l-s)>Math.abs(a-i);if(d){let U=i;i=s,s=U,U=a,a=l,l=U}let h=Math.abs(a-i),m=Math.abs(l-s),y=-h/2,b=s<l?1:-1,I=i<a?1:-1,k=0,F=this.image.get(d?s:i,d?i:s);for(let U=i,G=s;U!==a;U+=I){let Q=this.image.get(d?G:U,d?U:G);if(Q!==F&&(k++,F=Q),y+=m,y>0){if(G===l)break;G+=b,y-=h}}return k}}class $n{constructor(){this.decoder=new Ku}decode(e,n=null){let i,s;if(n!=null&&n.has(j.PURE_BARCODE)){const m=$n.extractPureBits(e.getBlackMatrix());i=this.decoder.decode(m),s=$n.NO_POINTS}else{const m=new kt(e.getBlackMatrix()).detect();i=this.decoder.decode(m.getBits()),s=m.getPoints()}const a=i.getRawBytes(),l=new Be(i.getText(),a,8*a.length,s,ie.DATA_MATRIX,R.currentTimeMillis()),d=i.getByteSegments();d!=null&&l.putMetadata(Me.BYTE_SEGMENTS,d);const h=i.getECLevel();return h!=null&&l.putMetadata(Me.ERROR_CORRECTION_LEVEL,h),l}reset(){}static extractPureBits(e){const n=e.getTopLeftOnBit(),i=e.getBottomRightOnBit();if(n==null||i==null)throw new O;const s=this.moduleSize(n,e);let a=n[1];const l=i[1];let d=n[0];const m=(i[0]-d+1)/s,y=(l-a+1)/s;if(m<=0||y<=0)throw new O;const b=s/2;a+=b,d+=b;const I=new te(m,y);for(let k=0;k<y;k++){const F=a+k*s;for(let U=0;U<m;U++)e.get(d+U*s,F)&&I.set(U,k)}return I}static moduleSize(e,n){const i=n.getWidth();let s=e[0];const a=e[1];for(;s<i&&n.get(s,a);)s++;if(s===i)throw new O;const l=s-e[0];if(l===0)throw new O;return l}}$n.NO_POINTS=[];class Qu extends je{constructor(e=500){super(new $n,e)}}var wr;(function(C){C[C.L=0]="L",C[C.M=1]="M",C[C.Q=2]="Q",C[C.H=3]="H"})(wr||(wr={}));class dt{constructor(e,n,i){this.value=e,this.stringValue=n,this.bits=i,dt.FOR_BITS.set(i,this),dt.FOR_VALUE.set(e,this)}getValue(){return this.value}getBits(){return this.bits}static fromString(e){switch(e){case"L":return dt.L;case"M":return dt.M;case"Q":return dt.Q;case"H":return dt.H;default:throw new A(e+"not available")}}toString(){return this.stringValue}equals(e){if(!(e instanceof dt))return!1;const n=e;return this.value===n.value}static forBits(e){if(e<0||e>=dt.FOR_BITS.size)throw new E;return dt.FOR_BITS.get(e)}}dt.FOR_BITS=new Map,dt.FOR_VALUE=new Map,dt.L=new dt(wr.L,"L",1),dt.M=new dt(wr.M,"M",0),dt.Q=new dt(wr.Q,"Q",3),dt.H=new dt(wr.H,"H",2);class Ht{constructor(e){this.errorCorrectionLevel=dt.forBits(e>>3&3),this.dataMask=e&7}static numBitsDiffering(e,n){return $.bitCount(e^n)}static decodeFormatInformation(e,n){const i=Ht.doDecodeFormatInformation(e,n);return i!==null?i:Ht.doDecodeFormatInformation(e^Ht.FORMAT_INFO_MASK_QR,n^Ht.FORMAT_INFO_MASK_QR)}static doDecodeFormatInformation(e,n){let i=Number.MAX_SAFE_INTEGER,s=0;for(const a of Ht.FORMAT_INFO_DECODE_LOOKUP){const l=a[0];if(l===e||l===n)return new Ht(a[1]);let d=Ht.numBitsDiffering(e,l);d<i&&(s=a[1],i=d),e!==n&&(d=Ht.numBitsDiffering(n,l),d<i&&(s=a[1],i=d))}return i<=3?new Ht(s):null}getErrorCorrectionLevel(){return this.errorCorrectionLevel}getDataMask(){return this.dataMask}hashCode(){return this.errorCorrectionLevel.getBits()<<3|this.dataMask}equals(e){if(!(e instanceof Ht))return!1;const n=e;return this.errorCorrectionLevel===n.errorCorrectionLevel&&this.dataMask===n.dataMask}}Ht.FORMAT_INFO_MASK_QR=21522,Ht.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 X{constructor(e,...n){this.ecCodewordsPerBlock=e,this.ecBlocks=n}getECCodewordsPerBlock(){return this.ecCodewordsPerBlock}getNumBlocks(){let e=0;const n=this.ecBlocks;for(const i of n)e+=i.getCount();return e}getTotalECCodewords(){return this.ecCodewordsPerBlock*this.getNumBlocks()}getECBlocks(){return this.ecBlocks}}class T{constructor(e,n){this.count=e,this.dataCodewords=n}getCount(){return this.count}getDataCodewords(){return this.dataCodewords}}class Ee{constructor(e,n,...i){this.versionNumber=e,this.alignmentPatternCenters=n,this.ecBlocks=i;let s=0;const a=i[0].getECCodewordsPerBlock(),l=i[0].getECBlocks();for(const d of l)s+=d.getCount()*(d.getDataCodewords()+a);this.totalCodewords=s}getVersionNumber(){return this.versionNumber}getAlignmentPatternCenters(){return this.alignmentPatternCenters}getTotalCodewords(){return this.totalCodewords}getDimensionForVersion(){return 17+4*this.versionNumber}getECBlocksForLevel(e){return this.ecBlocks[e.getValue()]}static getProvisionalVersionForDimension(e){if(e%4!==1)throw new z;try{return this.getVersionForNumber((e-17)/4)}catch{throw new z}}static getVersionForNumber(e){if(e<1||e>40)throw new E;return Ee.VERSIONS[e-1]}static decodeVersionInformation(e){let n=Number.MAX_SAFE_INTEGER,i=0;for(let s=0;s<Ee.VERSION_DECODE_INFO.length;s++){const a=Ee.VERSION_DECODE_INFO[s];if(a===e)return Ee.getVersionForNumber(s+7);const l=Ht.numBitsDiffering(e,a);l<n&&(i=s+7,n=l)}return n<=3?Ee.getVersionForNumber(i):null}buildFunctionPattern(){const e=this.getDimensionForVersion(),n=new te(e);n.setRegion(0,0,9,9),n.setRegion(e-8,0,8,9),n.setRegion(0,e-8,9,8);const i=this.alignmentPatternCenters.length;for(let s=0;s<i;s++){const a=this.alignmentPatternCenters[s]-2;for(let l=0;l<i;l++)s===0&&(l===0||l===i-1)||s===i-1&&l===0||n.setRegion(this.alignmentPatternCenters[l]-2,a,5,5)}return n.setRegion(6,9,1,e-17),n.setRegion(9,6,e-17,1),this.versionNumber>6&&(n.setRegion(e-11,0,3,6),n.setRegion(0,e-11,6,3)),n}toString(){return""+this.versionNumber}}Ee.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]),Ee.VERSIONS=[new Ee(1,new Int32Array(0),new X(7,new T(1,19)),new X(10,new T(1,16)),new X(13,new T(1,13)),new X(17,new T(1,9))),new Ee(2,Int32Array.from([6,18]),new X(10,new T(1,34)),new X(16,new T(1,28)),new X(22,new T(1,22)),new X(28,new T(1,16))),new Ee(3,Int32Array.from([6,22]),new X(15,new T(1,55)),new X(26,new T(1,44)),new X(18,new T(2,17)),new X(22,new T(2,13))),new Ee(4,Int32Array.from([6,26]),new X(20,new T(1,80)),new X(18,new T(2,32)),new X(26,new T(2,24)),new X(16,new T(4,9))),new Ee(5,Int32Array.from([6,30]),new X(26,new T(1,108)),new X(24,new T(2,43)),new X(18,new T(2,15),new T(2,16)),new X(22,new T(2,11),new T(2,12))),new Ee(6,Int32Array.from([6,34]),new X(18,new T(2,68)),new X(16,new T(4,27)),new X(24,new T(4,19)),new X(28,new T(4,15))),new Ee(7,Int32Array.from([6,22,38]),new X(20,new T(2,78)),new X(18,new T(4,31)),new X(18,new T(2,14),new T(4,15)),new X(26,new T(4,13),new T(1,14))),new Ee(8,Int32Array.from([6,24,42]),new X(24,new T(2,97)),new X(22,new T(2,38),new T(2,39)),new X(22,new T(4,18),new T(2,19)),new X(26,new T(4,14),new T(2,15))),new Ee(9,Int32Array.from([6,26,46]),new X(30,new T(2,116)),new X(22,new T(3,36),new T(2,37)),new X(20,new T(4,16),new T(4,17)),new X(24,new T(4,12),new T(4,13))),new Ee(10,Int32Array.from([6,28,50]),new X(18,new T(2,68),new T(2,69)),new X(26,new T(4,43),new T(1,44)),new X(24,new T(6,19),new T(2,20)),new X(28,new T(6,15),new T(2,16))),new Ee(11,Int32Array.from([6,30,54]),new X(20,new T(4,81)),new X(30,new T(1,50),new T(4,51)),new X(28,new T(4,22),new T(4,23)),new X(24,new T(3,12),new T(8,13))),new Ee(12,Int32Array.from([6,32,58]),new X(24,new T(2,92),new T(2,93)),new X(22,new T(6,36),new T(2,37)),new X(26,new T(4,20),new T(6,21)),new X(28,new T(7,14),new T(4,15))),new Ee(13,Int32Array.from([6,34,62]),new X(26,new T(4,107)),new X(22,new T(8,37),new T(1,38)),new X(24,new T(8,20),new T(4,21)),new X(22,new T(12,11),new T(4,12))),new Ee(14,Int32Array.from([6,26,46,66]),new X(30,new T(3,115),new T(1,116)),new X(24,new T(4,40),new T(5,41)),new X(20,new T(11,16),new T(5,17)),new X(24,new T(11,12),new T(5,13))),new Ee(15,Int32Array.from([6,26,48,70]),new X(22,new T(5,87),new T(1,88)),new X(24,new T(5,41),new T(5,42)),new X(30,new T(5,24),new T(7,25)),new X(24,new T(11,12),new T(7,13))),new Ee(16,Int32Array.from([6,26,50,74]),new X(24,new T(5,98),new T(1,99)),new X(28,new T(7,45),new T(3,46)),new X(24,new T(15,19),new T(2,20)),new X(30,new T(3,15),new T(13,16))),new Ee(17,Int32Array.from([6,30,54,78]),new X(28,new T(1,107),new T(5,108)),new X(28,new T(10,46),new T(1,47)),new X(28,new T(1,22),new T(15,23)),new X(28,new T(2,14),new T(17,15))),new Ee(18,Int32Array.from([6,30,56,82]),new X(30,new T(5,120),new T(1,121)),new X(26,new T(9,43),new T(4,44)),new X(28,new T(17,22),new T(1,23)),new X(28,new T(2,14),new T(19,15))),new Ee(19,Int32Array.from([6,30,58,86]),new X(28,new T(3,113),new T(4,114)),new X(26,new T(3,44),new T(11,45)),new X(26,new T(17,21),new T(4,22)),new X(26,new T(9,13),new T(16,14))),new Ee(20,Int32Array.from([6,34,62,90]),new X(28,new T(3,107),new T(5,108)),new X(26,new T(3,41),new T(13,42)),new X(30,new T(15,24),new T(5,25)),new X(28,new T(15,15),new T(10,16))),new Ee(21,Int32Array.from([6,28,50,72,94]),new X(28,new T(4,116),new T(4,117)),new X(26,new T(17,42)),new X(28,new T(17,22),new T(6,23)),new X(30,new T(19,16),new T(6,17))),new Ee(22,Int32Array.from([6,26,50,74,98]),new X(28,new T(2,111),new T(7,112)),new X(28,new T(17,46)),new X(30,new T(7,24),new T(16,25)),new X(24,new T(34,13))),new Ee(23,Int32Array.from([6,30,54,78,102]),new X(30,new T(4,121),new T(5,122)),new X(28,new T(4,47),new T(14,48)),new X(30,new T(11,24),new T(14,25)),new X(30,new T(16,15),new T(14,16))),new Ee(24,Int32Array.from([6,28,54,80,106]),new X(30,new T(6,117),new T(4,118)),new X(28,new T(6,45),new T(14,46)),new X(30,new T(11,24),new T(16,25)),new X(30,new T(30,16),new T(2,17))),new Ee(25,Int32Array.from([6,32,58,84,110]),new X(26,new T(8,106),new T(4,107)),new X(28,new T(8,47),new T(13,48)),new X(30,new T(7,24),new T(22,25)),new X(30,new T(22,15),new T(13,16))),new Ee(26,Int32Array.from([6,30,58,86,114]),new X(28,new T(10,114),new T(2,115)),new X(28,new T(19,46),new T(4,47)),new X(28,new T(28,22),new T(6,23)),new X(30,new T(33,16),new T(4,17))),new Ee(27,Int32Array.from([6,34,62,90,118]),new X(30,new T(8,122),new T(4,123)),new X(28,new T(22,45),new T(3,46)),new X(30,new T(8,23),new T(26,24)),new X(30,new T(12,15),new T(28,16))),new Ee(28,Int32Array.from([6,26,50,74,98,122]),new X(30,new T(3,117),new T(10,118)),new X(28,new T(3,45),new T(23,46)),new X(30,new T(4,24),new T(31,25)),new X(30,new T(11,15),new T(31,16))),new Ee(29,Int32Array.from([6,30,54,78,102,126]),new X(30,new T(7,116),new T(7,117)),new X(28,new T(21,45),new T(7,46)),new X(30,new T(1,23),new T(37,24)),new X(30,new T(19,15),new T(26,16))),new Ee(30,Int32Array.from([6,26,52,78,104,130]),new X(30,new T(5,115),new T(10,116)),new X(28,new T(19,47),new T(10,48)),new X(30,new T(15,24),new T(25,25)),new X(30,new T(23,15),new T(25,16))),new Ee(31,Int32Array.from([6,30,56,82,108,134]),new X(30,new T(13,115),new T(3,116)),new X(28,new T(2,46),new T(29,47)),new X(30,new T(42,24),new T(1,25)),new X(30,new T(23,15),new T(28,16))),new Ee(32,Int32Array.from([6,34,60,86,112,138]),new X(30,new T(17,115)),new X(28,new T(10,46),new T(23,47)),new X(30,new T(10,24),new T(35,25)),new X(30,new T(19,15),new T(35,16))),new Ee(33,Int32Array.from([6,30,58,86,114,142]),new X(30,new T(17,115),new T(1,116)),new X(28,new T(14,46),new T(21,47)),new X(30,new T(29,24),new T(19,25)),new X(30,new T(11,15),new T(46,16))),new Ee(34,Int32Array.from([6,34,62,90,118,146]),new X(30,new T(13,115),new T(6,116)),new X(28,new T(14,46),new T(23,47)),new X(30,new T(44,24),new T(7,25)),new X(30,new T(59,16),new T(1,17))),new Ee(35,Int32Array.from([6,30,54,78,102,126,150]),new X(30,new T(12,121),new T(7,122)),new X(28,new T(12,47),new T(26,48)),new X(30,new T(39,24),new T(14,25)),new X(30,new T(22,15),new T(41,16))),new Ee(36,Int32Array.from([6,24,50,76,102,128,154]),new X(30,new T(6,121),new T(14,122)),new X(28,new T(6,47),new T(34,48)),new X(30,new T(46,24),new T(10,25)),new X(30,new T(2,15),new T(64,16))),new Ee(37,Int32Array.from([6,28,54,80,106,132,158]),new X(30,new T(17,122),new T(4,123)),new X(28,new T(29,46),new T(14,47)),new X(30,new T(49,24),new T(10,25)),new X(30,new T(24,15),new T(46,16))),new Ee(38,Int32Array.from([6,32,58,84,110,136,162]),new X(30,new T(4,122),new T(18,123)),new X(28,new T(13,46),new T(32,47)),new X(30,new T(48,24),new T(14,25)),new X(30,new T(42,15),new T(32,16))),new Ee(39,Int32Array.from([6,26,54,82,110,138,166]),new X(30,new T(20,117),new T(4,118)),new X(28,new T(40,47),new T(7,48)),new X(30,new T(43,24),new T(22,25)),new X(30,new T(10,15),new T(67,16))),new Ee(40,Int32Array.from([6,30,58,86,114,142,170]),new X(30,new T(19,118),new T(6,119)),new X(28,new T(18,47),new T(31,48)),new X(30,new T(34,24),new T(34,25)),new X(30,new T(20,15),new T(61,16)))];var Pt;(function(C){C[C.DATA_MASK_000=0]="DATA_MASK_000",C[C.DATA_MASK_001=1]="DATA_MASK_001",C[C.DATA_MASK_010=2]="DATA_MASK_010",C[C.DATA_MASK_011=3]="DATA_MASK_011",C[C.DATA_MASK_100=4]="DATA_MASK_100",C[C.DATA_MASK_101=5]="DATA_MASK_101",C[C.DATA_MASK_110=6]="DATA_MASK_110",C[C.DATA_MASK_111=7]="DATA_MASK_111"})(Pt||(Pt={}));class hn{constructor(e,n){this.value=e,this.isMasked=n}unmaskBitMatrix(e,n){for(let i=0;i<n;i++)for(let s=0;s<n;s++)this.isMasked(i,s)&&e.flip(s,i)}}hn.values=new Map([[Pt.DATA_MASK_000,new hn(Pt.DATA_MASK_000,(C,e)=>(C+e&1)===0)],[Pt.DATA_MASK_001,new hn(Pt.DATA_MASK_001,(C,e)=>(C&1)===0)],[Pt.DATA_MASK_010,new hn(Pt.DATA_MASK_010,(C,e)=>e%3===0)],[Pt.DATA_MASK_011,new hn(Pt.DATA_MASK_011,(C,e)=>(C+e)%3===0)],[Pt.DATA_MASK_100,new hn(Pt.DATA_MASK_100,(C,e)=>(Math.floor(C/2)+Math.floor(e/3)&1)===0)],[Pt.DATA_MASK_101,new hn(Pt.DATA_MASK_101,(C,e)=>C*e%6===0)],[Pt.DATA_MASK_110,new hn(Pt.DATA_MASK_110,(C,e)=>C*e%6<3)],[Pt.DATA_MASK_111,new hn(Pt.DATA_MASK_111,(C,e)=>(C+e+C*e%3&1)===0)]]);class ed{constructor(e){const n=e.getHeight();if(n<21||(n&3)!==1)throw new z;this.bitMatrix=e}readFormatInformation(){if(this.parsedFormatInfo!==null&&this.parsedFormatInfo!==void 0)return this.parsedFormatInfo;let e=0;for(let a=0;a<6;a++)e=this.copyBit(a,8,e);e=this.copyBit(7,8,e),e=this.copyBit(8,8,e),e=this.copyBit(8,7,e);for(let a=5;a>=0;a--)e=this.copyBit(8,a,e);const n=this.bitMatrix.getHeight();let i=0;const s=n-7;for(let a=n-1;a>=s;a--)i=this.copyBit(8,a,i);for(let a=n-8;a<n;a++)i=this.copyBit(a,8,i);if(this.parsedFormatInfo=Ht.decodeFormatInformation(e,i),this.parsedFormatInfo!==null)return this.parsedFormatInfo;throw new z}readVersion(){if(this.parsedVersion!==null&&this.parsedVersion!==void 0)return this.parsedVersion;const e=this.bitMatrix.getHeight(),n=Math.floor((e-17)/4);if(n<=6)return Ee.getVersionForNumber(n);let i=0;const s=e-11;for(let l=5;l>=0;l--)for(let d=e-9;d>=s;d--)i=this.copyBit(d,l,i);let a=Ee.decodeVersionInformation(i);if(a!==null&&a.getDimensionForVersion()===e)return this.parsedVersion=a,a;i=0;for(let l=5;l>=0;l--)for(let d=e-9;d>=s;d--)i=this.copyBit(l,d,i);if(a=Ee.decodeVersionInformation(i),a!==null&&a.getDimensionForVersion()===e)return this.parsedVersion=a,a;throw new z}copyBit(e,n,i){return(this.isMirror?this.bitMatrix.get(n,e):this.bitMatrix.get(e,n))?i<<1|1:i<<1}readCodewords(){const e=this.readFormatInformation(),n=this.readVersion(),i=hn.values.get(e.getDataMask()),s=this.bitMatrix.getHeight();i.unmaskBitMatrix(this.bitMatrix,s);const a=n.buildFunctionPattern();let l=!0;const d=new Uint8Array(n.getTotalCodewords());let h=0,m=0,y=0;for(let b=s-1;b>0;b-=2){b===6&&b--;for(let I=0;I<s;I++){const k=l?s-1-I:I;for(let F=0;F<2;F++)a.get(b-F,k)||(y++,m<<=1,this.bitMatrix.get(b-F,k)&&(m|=1),y===8&&(d[h++]=m,y=0,m=0))}l=!l}if(h!==n.getTotalCodewords())throw new z;return d}remask(){if(this.parsedFormatInfo===null)return;const e=hn.values[this.parsedFormatInfo.getDataMask()],n=this.bitMatrix.getHeight();e.unmaskBitMatrix(this.bitMatrix,n)}setMirror(e){this.parsedVersion=null,this.parsedFormatInfo=null,this.isMirror=e}mirror(){const e=this.bitMatrix;for(let n=0,i=e.getWidth();n<i;n++)for(let s=n+1,a=e.getHeight();s<a;s++)e.get(n,s)!==e.get(s,n)&&(e.flip(s,n),e.flip(n,s))}}class Qi{constructor(e,n){this.numDataCodewords=e,this.codewords=n}static getDataBlocks(e,n,i){if(e.length!==n.getTotalCodewords())throw new E;const s=n.getECBlocksForLevel(i);let a=0;const l=s.getECBlocks();for(const F of l)a+=F.getCount();const d=new Array(a);let h=0;for(const F of l)for(let U=0;U<F.getCount();U++){const G=F.getDataCodewords(),Q=s.getECCodewordsPerBlock()+G;d[h++]=new Qi(G,new Uint8Array(Q))}const m=d[0].codewords.length;let y=d.length-1;for(;y>=0&&d[y].codewords.length!==m;)y--;y++;const b=m-s.getECCodewordsPerBlock();let I=0;for(let F=0;F<b;F++)for(let U=0;U<h;U++)d[U].codewords[F]=e[I++];for(let F=y;F<h;F++)d[F].codewords[b]=e[I++];const k=d[0].codewords.length;for(let F=b;F<k;F++)for(let U=0;U<h;U++){const G=U<y?F:F+1;d[U].codewords[G]=e[I++]}return d}getNumDataCodewords(){return this.numDataCodewords}getCodewords(){return this.codewords}}var pn;(function(C){C[C.TERMINATOR=0]="TERMINATOR",C[C.NUMERIC=1]="NUMERIC",C[C.ALPHANUMERIC=2]="ALPHANUMERIC",C[C.STRUCTURED_APPEND=3]="STRUCTURED_APPEND",C[C.BYTE=4]="BYTE",C[C.ECI=5]="ECI",C[C.KANJI=6]="KANJI",C[C.FNC1_FIRST_POSITION=7]="FNC1_FIRST_POSITION",C[C.FNC1_SECOND_POSITION=8]="FNC1_SECOND_POSITION",C[C.HANZI=9]="HANZI"})(pn||(pn={}));class Ie{constructor(e,n,i,s){this.value=e,this.stringValue=n,this.characterCountBitsForVersions=i,this.bits=s,Ie.FOR_BITS.set(s,this),Ie.FOR_VALUE.set(e,this)}static forBits(e){const n=Ie.FOR_BITS.get(e);if(n===void 0)throw new E;return n}getCharacterCountBits(e){const n=e.getVersionNumber();let i;return n<=9?i=0:n<=26?i=1:i=2,this.characterCountBitsForVersions[i]}getValue(){return this.value}getBits(){return this.bits}equals(e){if(!(e instanceof Ie))return!1;const n=e;return this.value===n.value}toString(){return this.stringValue}}Ie.FOR_BITS=new Map,Ie.FOR_VALUE=new Map,Ie.TERMINATOR=new Ie(pn.TERMINATOR,"TERMINATOR",Int32Array.from([0,0,0]),0),Ie.NUMERIC=new Ie(pn.NUMERIC,"NUMERIC",Int32Array.from([10,12,14]),1),Ie.ALPHANUMERIC=new Ie(pn.ALPHANUMERIC,"ALPHANUMERIC",Int32Array.from([9,11,13]),2),Ie.STRUCTURED_APPEND=new Ie(pn.STRUCTURED_APPEND,"STRUCTURED_APPEND",Int32Array.from([0,0,0]),3),Ie.BYTE=new Ie(pn.BYTE,"BYTE",Int32Array.from([8,16,16]),4),Ie.ECI=new Ie(pn.ECI,"ECI",Int32Array.from([0,0,0]),7),Ie.KANJI=new Ie(pn.KANJI,"KANJI",Int32Array.from([8,10,12]),8),Ie.FNC1_FIRST_POSITION=new Ie(pn.FNC1_FIRST_POSITION,"FNC1_FIRST_POSITION",Int32Array.from([0,0,0]),5),Ie.FNC1_SECOND_POSITION=new Ie(pn.FNC1_SECOND_POSITION,"FNC1_SECOND_POSITION",Int32Array.from([0,0,0]),9),Ie.HANZI=new Ie(pn.HANZI,"HANZI",Int32Array.from([8,10,12]),13);class vt{static decode(e,n,i,s){const a=new Ki(e);let l=new le;const d=new Array;let h=-1,m=-1;try{let y=null,b=!1,I;do{if(a.available()<4)I=Ie.TERMINATOR;else{const k=a.readBits(4);I=Ie.forBits(k)}switch(I){case Ie.TERMINATOR:break;case Ie.FNC1_FIRST_POSITION:case Ie.FNC1_SECOND_POSITION:b=!0;break;case Ie.STRUCTURED_APPEND:if(a.available()<16)throw new z;h=a.readBits(8),m=a.readBits(8);break;case Ie.ECI:const k=vt.parseECIValue(a);if(y=B.getCharacterSetECIByValue(k),y===null)throw new z;break;case Ie.HANZI:const F=a.readBits(4),U=a.readBits(I.getCharacterCountBits(n));F===vt.GB2312_SUBSET&&vt.decodeHanziSegment(a,l,U);break;default:const G=a.readBits(I.getCharacterCountBits(n));switch(I){case Ie.NUMERIC:vt.decodeNumericSegment(a,l,G);break;case Ie.ALPHANUMERIC:vt.decodeAlphanumericSegment(a,l,G,b);break;case Ie.BYTE:vt.decodeByteSegment(a,l,G,y,d,s);break;case Ie.KANJI:vt.decodeKanjiSegment(a,l,G);break;default:throw new z}break}}while(I!==Ie.TERMINATOR)}catch{throw new z}return new ke(e,l.toString(),d.length===0?null:d,i===null?null:i.toString(),h,m)}static decodeHanziSegment(e,n,i){if(i*13>e.available())throw new z;const s=new Uint8Array(2*i);let a=0;for(;i>0;){const l=e.readBits(13);let d=l/96<<8&4294967295|l%96;d<959?d+=41377:d+=42657,s[a]=d>>8&255,s[a+1]=d&255,a+=2,i--}try{n.append(re.decode(s,ne.GB2312))}catch(l){throw new z(l)}}static decodeKanjiSegment(e,n,i){if(i*13>e.available())throw new z;const s=new Uint8Array(2*i);let a=0;for(;i>0;){const l=e.readBits(13);let d=l/192<<8&4294967295|l%192;d<7936?d+=33088:d+=49472,s[a]=d>>8,s[a+1]=d,a+=2,i--}try{n.append(re.decode(s,ne.SHIFT_JIS))}catch(l){throw new z(l)}}static decodeByteSegment(e,n,i,s,a,l){if(8*i>e.available())throw new z;const d=new Uint8Array(i);for(let m=0;m<i;m++)d[m]=e.readBits(8);let h;s===null?h=ne.guessEncoding(d,l):h=s.getName();try{n.append(re.decode(d,h))}catch(m){throw new z(m)}a.push(d)}static toAlphaNumericChar(e){if(e>=vt.ALPHANUMERIC_CHARS.length)throw new z;return vt.ALPHANUMERIC_CHARS[e]}static decodeAlphanumericSegment(e,n,i,s){const a=n.length();for(;i>1;){if(e.available()<11)throw new z;const l=e.readBits(11);n.append(vt.toAlphaNumericChar(Math.floor(l/45))),n.append(vt.toAlphaNumericChar(l%45)),i-=2}if(i===1){if(e.available()<6)throw new z;n.append(vt.toAlphaNumericChar(e.readBits(6)))}if(s)for(let l=a;l<n.length();l++)n.charAt(l)==="%"&&(l<n.length()-1&&n.charAt(l+1)==="%"?n.deleteCharAt(l+1):n.setCharAt(l,""))}static decodeNumericSegment(e,n,i){for(;i>=3;){if(e.available()<10)throw new z;const s=e.readBits(10);if(s>=1e3)throw new z;n.append(vt.toAlphaNumericChar(Math.floor(s/100))),n.append(vt.toAlphaNumericChar(Math.floor(s/10)%10)),n.append(vt.toAlphaNumericChar(s%10)),i-=3}if(i===2){if(e.available()<7)throw new z;const s=e.readBits(7);if(s>=100)throw new z;n.append(vt.toAlphaNumericChar(Math.floor(s/10))),n.append(vt.toAlphaNumericChar(s%10))}else if(i===1){if(e.available()<4)throw new z;const s=e.readBits(4);if(s>=10)throw new z;n.append(vt.toAlphaNumericChar(s))}}static parseECIValue(e){const n=e.readBits(8);if((n&128)===0)return n&127;if((n&192)===128){const i=e.readBits(8);return(n&63)<<8&4294967295|i}if((n&224)===192){const i=e.readBits(16);return(n&31)<<16&4294967295|i}throw new z}}vt.ALPHANUMERIC_CHARS="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:",vt.GB2312_SUBSET=1;class ds{constructor(e){this.mirrored=e}isMirrored(){return this.mirrored}applyMirroredCorrection(e){if(!this.mirrored||e===null||e.length<3)return;const n=e[0];e[0]=e[2],e[2]=n}}class td{constructor(){this.rsDecoder=new En(Le.QR_CODE_FIELD_256)}decodeBooleanArray(e,n){return this.decodeBitMatrix(te.parseFromBooleanArray(e),n)}decodeBitMatrix(e,n){const i=new ed(e);let s=null;try{return this.decodeBitMatrixParser(i,n)}catch(a){s=a}try{i.remask(),i.setMirror(!0),i.readVersion(),i.readFormatInformation(),i.mirror();const a=this.decodeBitMatrixParser(i,n);return a.setOther(new ds(!0)),a}catch(a){throw s!==null?s:a}}decodeBitMatrixParser(e,n){const i=e.readVersion(),s=e.readFormatInformation().getErrorCorrectionLevel(),a=e.readCodewords(),l=Qi.getDataBlocks(a,i,s);let d=0;for(const y of l)d+=y.getNumDataCodewords();const h=new Uint8Array(d);let m=0;for(const y of l){const b=y.getCodewords(),I=y.getNumDataCodewords();this.correctErrors(b,I);for(let k=0;k<I;k++)h[m++]=b[k]}return vt.decode(h,i,s,n)}correctErrors(e,n){const i=new Int32Array(e);try{this.rsDecoder.decode(i,e.length-n)}catch{throw new M}for(let s=0;s<n;s++)e[s]=i[s]}}class eo extends N{constructor(e,n,i){super(e,n),this.estimatedModuleSize=i}aboutEquals(e,n,i){if(Math.abs(n-this.getY())<=e&&Math.abs(i-this.getX())<=e){const s=Math.abs(e-this.estimatedModuleSize);return s<=1||s<=this.estimatedModuleSize}return!1}combineEstimate(e,n,i){const s=(this.getX()+n)/2,a=(this.getY()+e)/2,l=(this.estimatedModuleSize+i)/2;return new eo(s,a,l)}}class fi{constructor(e,n,i,s,a,l,d){this.image=e,this.startX=n,this.startY=i,this.width=s,this.height=a,this.moduleSize=l,this.resultPointCallback=d,this.possibleCenters=[],this.crossCheckStateCount=new Int32Array(3)}find(){const e=this.startX,n=this.height,i=this.width,s=e+i,a=this.startY+n/2,l=new Int32Array(3),d=this.image;for(let h=0;h<n;h++){const m=a+((h&1)===0?Math.floor((h+1)/2):-Math.floor((h+1)/2));l[0]=0,l[1]=0,l[2]=0;let y=e;for(;y<s&&!d.get(y,m);)y++;let b=0;for(;y<s;){if(d.get(y,m))if(b===1)l[1]++;else if(b===2){if(this.foundPatternCross(l)){const I=this.handlePossibleCenter(l,m,y);if(I!==null)return I}l[0]=l[2],l[1]=1,l[2]=0,b=1}else l[++b]++;else b===1&&b++,l[b]++;y++}if(this.foundPatternCross(l)){const I=this.handlePossibleCenter(l,m,s);if(I!==null)return I}}if(this.possibleCenters.length!==0)return this.possibleCenters[0];throw new O}static centerFromEnd(e,n){return n-e[2]-e[1]/2}foundPatternCross(e){const n=this.moduleSize,i=n/2;for(let s=0;s<3;s++)if(Math.abs(n-e[s])>=i)return!1;return!0}crossCheckVertical(e,n,i,s){const a=this.image,l=a.getHeight(),d=this.crossCheckStateCount;d[0]=0,d[1]=0,d[2]=0;let h=e;for(;h>=0&&a.get(n,h)&&d[1]<=i;)d[1]++,h--;if(h<0||d[1]>i)return NaN;for(;h>=0&&!a.get(n,h)&&d[0]<=i;)d[0]++,h--;if(d[0]>i)return NaN;for(h=e+1;h<l&&a.get(n,h)&&d[1]<=i;)d[1]++,h++;if(h===l||d[1]>i)return NaN;for(;h<l&&!a.get(n,h)&&d[2]<=i;)d[2]++,h++;if(d[2]>i)return NaN;const m=d[0]+d[1]+d[2];return 5*Math.abs(m-s)>=2*s?NaN:this.foundPatternCross(d)?fi.centerFromEnd(d,h):NaN}handlePossibleCenter(e,n,i){const s=e[0]+e[1]+e[2],a=fi.centerFromEnd(e,i),l=this.crossCheckVertical(n,a,2*e[1],s);if(!isNaN(l)){const d=(e[0]+e[1]+e[2])/3;for(const m of this.possibleCenters)if(m.aboutEquals(d,l,a))return m.combineEstimate(l,a,d);const h=new eo(a,l,d);this.possibleCenters.push(h),this.resultPointCallback!==null&&this.resultPointCallback!==void 0&&this.resultPointCallback.foundPossibleResultPoint(h)}return null}}class to extends N{constructor(e,n,i,s){super(e,n),this.estimatedModuleSize=i,this.count=s,s===void 0&&(this.count=1)}getEstimatedModuleSize(){return this.estimatedModuleSize}getCount(){return this.count}aboutEquals(e,n,i){if(Math.abs(n-this.getY())<=e&&Math.abs(i-this.getX())<=e){const s=Math.abs(e-this.estimatedModuleSize);return s<=1||s<=this.estimatedModuleSize}return!1}combineEstimate(e,n,i){const s=this.count+1,a=(this.count*this.getX()+n)/s,l=(this.count*this.getY()+e)/s,d=(this.count*this.estimatedModuleSize+i)/s;return new to(a,l,d,s)}}class nd{constructor(e){this.bottomLeft=e[0],this.topLeft=e[1],this.topRight=e[2]}getBottomLeft(){return this.bottomLeft}getTopLeft(){return this.topLeft}getTopRight(){return this.topRight}}class Bt{constructor(e,n){this.image=e,this.resultPointCallback=n,this.possibleCenters=[],this.crossCheckStateCount=new Int32Array(5),this.resultPointCallback=n}getImage(){return this.image}getPossibleCenters(){return this.possibleCenters}find(e){const n=e!=null&&e.get(j.TRY_HARDER)!==void 0,i=e!=null&&e.get(j.PURE_BARCODE)!==void 0,s=this.image,a=s.getHeight(),l=s.getWidth();let d=Math.floor(3*a/(4*Bt.MAX_MODULES));(d<Bt.MIN_SKIP||n)&&(d=Bt.MIN_SKIP);let h=!1;const m=new Int32Array(5);for(let b=d-1;b<a&&!h;b+=d){m[0]=0,m[1]=0,m[2]=0,m[3]=0,m[4]=0;let I=0;for(let k=0;k<l;k++)if(s.get(k,b))(I&1)===1&&I++,m[I]++;else if((I&1)===0)if(I===4)if(Bt.foundPatternCross(m)){if(this.handlePossibleCenter(m,b,k,i)===!0)if(d=2,this.hasSkipped===!0)h=this.haveMultiplyConfirmedCenters();else{const U=this.findRowSkip();U>m[2]&&(b+=U-m[2]-d,k=l-1)}else{m[0]=m[2],m[1]=m[3],m[2]=m[4],m[3]=1,m[4]=0,I=3;continue}I=0,m[0]=0,m[1]=0,m[2]=0,m[3]=0,m[4]=0}else m[0]=m[2],m[1]=m[3],m[2]=m[4],m[3]=1,m[4]=0,I=3;else m[++I]++;else m[I]++;Bt.foundPatternCross(m)&&this.handlePossibleCenter(m,b,l,i)===!0&&(d=m[0],this.hasSkipped&&(h=this.haveMultiplyConfirmedCenters()))}const y=this.selectBestPatterns();return N.orderBestPatterns(y),new nd(y)}static centerFromEnd(e,n){return n-e[4]-e[3]-e[2]/2}static foundPatternCross(e){let n=0;for(let a=0;a<5;a++){const l=e[a];if(l===0)return!1;n+=l}if(n<7)return!1;const i=n/7,s=i/2;return Math.abs(i-e[0])<s&&Math.abs(i-e[1])<s&&Math.abs(3*i-e[2])<3*s&&Math.abs(i-e[3])<s&&Math.abs(i-e[4])<s}getCrossCheckStateCount(){const e=this.crossCheckStateCount;return e[0]=0,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e}crossCheckDiagonal(e,n,i,s){const a=this.getCrossCheckStateCount();let l=0;const d=this.image;for(;e>=l&&n>=l&&d.get(n-l,e-l);)a[2]++,l++;if(e<l||n<l)return!1;for(;e>=l&&n>=l&&!d.get(n-l,e-l)&&a[1]<=i;)a[1]++,l++;if(e<l||n<l||a[1]>i)return!1;for(;e>=l&&n>=l&&d.get(n-l,e-l)&&a[0]<=i;)a[0]++,l++;if(a[0]>i)return!1;const h=d.getHeight(),m=d.getWidth();for(l=1;e+l<h&&n+l<m&&d.get(n+l,e+l);)a[2]++,l++;if(e+l>=h||n+l>=m)return!1;for(;e+l<h&&n+l<m&&!d.get(n+l,e+l)&&a[3]<i;)a[3]++,l++;if(e+l>=h||n+l>=m||a[3]>=i)return!1;for(;e+l<h&&n+l<m&&d.get(n+l,e+l)&&a[4]<i;)a[4]++,l++;if(a[4]>=i)return!1;const y=a[0]+a[1]+a[2]+a[3]+a[4];return Math.abs(y-s)<2*s&&Bt.foundPatternCross(a)}crossCheckVertical(e,n,i,s){const a=this.image,l=a.getHeight(),d=this.getCrossCheckStateCount();let h=e;for(;h>=0&&a.get(n,h);)d[2]++,h--;if(h<0)return NaN;for(;h>=0&&!a.get(n,h)&&d[1]<=i;)d[1]++,h--;if(h<0||d[1]>i)return NaN;for(;h>=0&&a.get(n,h)&&d[0]<=i;)d[0]++,h--;if(d[0]>i)return NaN;for(h=e+1;h<l&&a.get(n,h);)d[2]++,h++;if(h===l)return NaN;for(;h<l&&!a.get(n,h)&&d[3]<i;)d[3]++,h++;if(h===l||d[3]>=i)return NaN;for(;h<l&&a.get(n,h)&&d[4]<i;)d[4]++,h++;if(d[4]>=i)return NaN;const m=d[0]+d[1]+d[2]+d[3]+d[4];return 5*Math.abs(m-s)>=2*s?NaN:Bt.foundPatternCross(d)?Bt.centerFromEnd(d,h):NaN}crossCheckHorizontal(e,n,i,s){const a=this.image,l=a.getWidth(),d=this.getCrossCheckStateCount();let h=e;for(;h>=0&&a.get(h,n);)d[2]++,h--;if(h<0)return NaN;for(;h>=0&&!a.get(h,n)&&d[1]<=i;)d[1]++,h--;if(h<0||d[1]>i)return NaN;for(;h>=0&&a.get(h,n)&&d[0]<=i;)d[0]++,h--;if(d[0]>i)return NaN;for(h=e+1;h<l&&a.get(h,n);)d[2]++,h++;if(h===l)return NaN;for(;h<l&&!a.get(h,n)&&d[3]<i;)d[3]++,h++;if(h===l||d[3]>=i)return NaN;for(;h<l&&a.get(h,n)&&d[4]<i;)d[4]++,h++;if(d[4]>=i)return NaN;const m=d[0]+d[1]+d[2]+d[3]+d[4];return 5*Math.abs(m-s)>=s?NaN:Bt.foundPatternCross(d)?Bt.centerFromEnd(d,h):NaN}handlePossibleCenter(e,n,i,s){const a=e[0]+e[1]+e[2]+e[3]+e[4];let l=Bt.centerFromEnd(e,i),d=this.crossCheckVertical(n,Math.floor(l),e[2],a);if(!isNaN(d)&&(l=this.crossCheckHorizontal(Math.floor(l),Math.floor(d),e[2],a),!isNaN(l)&&(!s||this.crossCheckDiagonal(Math.floor(d),Math.floor(l),e[2],a)))){const h=a/7;let m=!1;const y=this.possibleCenters;for(let b=0,I=y.length;b<I;b++){const k=y[b];if(k.aboutEquals(h,d,l)){y[b]=k.combineEstimate(d,l,h),m=!0;break}}if(!m){const b=new to(l,d,h);y.push(b),this.resultPointCallback!==null&&this.resultPointCallback!==void 0&&this.resultPointCallback.foundPossibleResultPoint(b)}return!0}return!1}findRowSkip(){if(this.possibleCenters.length<=1)return 0;let n=null;for(const i of this.possibleCenters)if(i.getCount()>=Bt.CENTER_QUORUM)if(n==null)n=i;else return this.hasSkipped=!0,Math.floor((Math.abs(n.getX()-i.getX())-Math.abs(n.getY()-i.getY()))/2);return 0}haveMultiplyConfirmedCenters(){let e=0,n=0;const i=this.possibleCenters.length;for(const l of this.possibleCenters)l.getCount()>=Bt.CENTER_QUORUM&&(e++,n+=l.getEstimatedModuleSize());if(e<3)return!1;const s=n/i;let a=0;for(const l of this.possibleCenters)a+=Math.abs(l.getEstimatedModuleSize()-s);return a<=.05*n}selectBestPatterns(){const e=this.possibleCenters.length;if(e<3)throw new O;const n=this.possibleCenters;let i;if(e>3){let s=0,a=0;for(const h of this.possibleCenters){const m=h.getEstimatedModuleSize();s+=m,a+=m*m}i=s/e;let l=Math.sqrt(a/e-i*i);n.sort((h,m)=>{const y=Math.abs(m.getEstimatedModuleSize()-i),b=Math.abs(h.getEstimatedModuleSize()-i);return y<b?-1:y>b?1:0});const d=Math.max(.2*i,l);for(let h=0;h<n.length&&n.length>3;h++){const m=n[h];Math.abs(m.getEstimatedModuleSize()-i)>d&&(n.splice(h,1),h--)}}if(n.length>3){let s=0;for(const a of n)s+=a.getEstimatedModuleSize();i=s/n.length,n.sort((a,l)=>{if(l.getCount()===a.getCount()){const d=Math.abs(l.getEstimatedModuleSize()-i),h=Math.abs(a.getEstimatedModuleSize()-i);return d<h?1:d>h?-1:0}else return l.getCount()-a.getCount()}),n.splice(3)}return[n[0],n[1],n[2]]}}Bt.CENTER_QUORUM=2,Bt.MIN_SKIP=3,Bt.MAX_MODULES=57;class kr{constructor(e){this.image=e}getImage(){return this.image}getResultPointCallback(){return this.resultPointCallback}detect(e){this.resultPointCallback=e==null?null:e.get(j.NEED_RESULT_POINT_CALLBACK);const i=new Bt(this.image,this.resultPointCallback).find(e);return this.processFinderPatternInfo(i)}processFinderPatternInfo(e){const n=e.getTopLeft(),i=e.getTopRight(),s=e.getBottomLeft(),a=this.calculateModuleSize(n,i,s);if(a<1)throw new O("No pattern found in proccess finder.");const l=kr.computeDimension(n,i,s,a),d=Ee.getProvisionalVersionForDimension(l),h=d.getDimensionForVersion()-7;let m=null;if(d.getAlignmentPatternCenters().length>0){const k=i.getX()-n.getX()+s.getX(),F=i.getY()-n.getY()+s.getY(),U=1-3/h,G=Math.floor(n.getX()+U*(k-n.getX())),Q=Math.floor(n.getY()+U*(F-n.getY()));for(let fe=4;fe<=16;fe<<=1)try{m=this.findAlignmentInRegion(a,G,Q,fe);break}catch(pe){if(!(pe instanceof O))throw pe}}const y=kr.createTransform(n,i,s,m,l),b=kr.sampleGrid(this.image,y,l);let I;return m===null?I=[s,n,i]:I=[s,n,i,m],new ye(b,I)}static createTransform(e,n,i,s,a){const l=a-3.5;let d,h,m,y;return s!==null?(d=s.getX(),h=s.getY(),m=l-3,y=m):(d=n.getX()-e.getX()+i.getX(),h=n.getY()-e.getY()+i.getY(),m=l,y=l),rn.quadrilateralToQuadrilateral(3.5,3.5,l,3.5,m,y,3.5,l,e.getX(),e.getY(),n.getX(),n.getY(),d,h,i.getX(),i.getY())}static sampleGrid(e,n,i){return An.getInstance().sampleGridWithTransform(e,i,i,n)}static computeDimension(e,n,i,s){const a=Ze.round(N.distance(e,n)/s),l=Ze.round(N.distance(e,i)/s);let d=Math.floor((a+l)/2)+7;switch(d&3){case 0:d++;break;case 2:d--;break;case 3:throw new O("Dimensions could be not found.")}return d}calculateModuleSize(e,n,i){return(this.calculateModuleSizeOneWay(e,n)+this.calculateModuleSizeOneWay(e,i))/2}calculateModuleSizeOneWay(e,n){const i=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(e.getX()),Math.floor(e.getY()),Math.floor(n.getX()),Math.floor(n.getY())),s=this.sizeOfBlackWhiteBlackRunBothWays(Math.floor(n.getX()),Math.floor(n.getY()),Math.floor(e.getX()),Math.floor(e.getY()));return isNaN(i)?s/7:isNaN(s)?i/7:(i+s)/14}sizeOfBlackWhiteBlackRunBothWays(e,n,i,s){let a=this.sizeOfBlackWhiteBlackRun(e,n,i,s),l=1,d=e-(i-e);d<0?(l=e/(e-d),d=0):d>=this.image.getWidth()&&(l=(this.image.getWidth()-1-e)/(d-e),d=this.image.getWidth()-1);let h=Math.floor(n-(s-n)*l);return l=1,h<0?(l=n/(n-h),h=0):h>=this.image.getHeight()&&(l=(this.image.getHeight()-1-n)/(h-n),h=this.image.getHeight()-1),d=Math.floor(e+(d-e)*l),a+=this.sizeOfBlackWhiteBlackRun(e,n,d,h),a-1}sizeOfBlackWhiteBlackRun(e,n,i,s){const a=Math.abs(s-n)>Math.abs(i-e);if(a){let k=e;e=n,n=k,k=i,i=s,s=k}const l=Math.abs(i-e),d=Math.abs(s-n);let h=-l/2;const m=e<i?1:-1,y=n<s?1:-1;let b=0;const I=i+m;for(let k=e,F=n;k!==I;k+=m){const U=a?F:k,G=a?k:F;if(b===1===this.image.get(U,G)){if(b===2)return Ze.distance(k,F,e,n);b++}if(h+=d,h>0){if(F===s)break;F+=y,h-=l}}return b===2?Ze.distance(i+m,s,e,n):NaN}findAlignmentInRegion(e,n,i,s){const a=Math.floor(s*e),l=Math.max(0,n-a),d=Math.min(this.image.getWidth()-1,n+a);if(d-l<e*3)throw new O("Alignment top exceeds estimated module size.");const h=Math.max(0,i-a),m=Math.min(this.image.getHeight()-1,i+a);if(m-h<e*3)throw new O("Alignment bottom exceeds estimated module size.");return new fi(this.image,l,h,d-l,m-h,e,this.resultPointCallback).find()}}class Zn{constructor(){this.decoder=new td}getDecoder(){return this.decoder}decode(e,n){let i,s;if(n!=null&&n.get(j.PURE_BARCODE)!==void 0){const h=Zn.extractPureBits(e.getBlackMatrix());i=this.decoder.decodeBitMatrix(h,n),s=Zn.NO_POINTS}else{const h=new kr(e.getBlackMatrix()).detect(n);i=this.decoder.decodeBitMatrix(h.getBits(),n),s=h.getPoints()}i.getOther()instanceof ds&&i.getOther().applyMirroredCorrection(s);const a=new Be(i.getText(),i.getRawBytes(),void 0,s,ie.QR_CODE,void 0),l=i.getByteSegments();l!==null&&a.putMetadata(Me.BYTE_SEGMENTS,l);const d=i.getECLevel();return d!==null&&a.putMetadata(Me.ERROR_CORRECTION_LEVEL,d),i.hasStructuredAppend()&&(a.putMetadata(Me.STRUCTURED_APPEND_SEQUENCE,i.getStructuredAppendSequenceNumber()),a.putMetadata(Me.STRUCTURED_APPEND_PARITY,i.getStructuredAppendParity())),a}reset(){}static extractPureBits(e){const n=e.getTopLeftOnBit(),i=e.getBottomRightOnBit();if(n===null||i===null)throw new O;const s=this.moduleSize(n,e);let a=n[1],l=i[1],d=n[0],h=i[0];if(d>=h||a>=l)throw new O;if(l-a!==h-d&&(h=d+(l-a),h>=e.getWidth()))throw new O;const m=Math.round((h-d+1)/s),y=Math.round((l-a+1)/s);if(m<=0||y<=0)throw new O;if(y!==m)throw new O;const b=Math.floor(s/2);a+=b,d+=b;const I=d+Math.floor((m-1)*s)-h;if(I>0){if(I>b)throw new O;d-=I}const k=a+Math.floor((y-1)*s)-l;if(k>0){if(k>b)throw new O;a-=k}const F=new te(m,y);for(let U=0;U<y;U++){const G=a+Math.floor(U*s);for(let Q=0;Q<m;Q++)e.get(d+Math.floor(Q*s),G)&&F.set(Q,U)}return F}static moduleSize(e,n){const i=n.getHeight(),s=n.getWidth();let a=e[0],l=e[1],d=!0,h=0;for(;a<s&&l<i;){if(d!==n.get(a,l)){if(++h===5)break;d=!d}a++,l++}if(a===s||l===i)throw new O;return(a-e[0])/7}}Zn.NO_POINTS=new Array;class Ne{PDF417Common(){}static getBitCountSum(e){return Ze.sum(e)}static toIntArray(e){if(e==null||!e.length)return Ne.EMPTY_INT_ARRAY;const n=new Int32Array(e.length);let i=0;for(const s of e)n[i++]=s;return n}static getCodeword(e){const n=Z.binarySearch(Ne.SYMBOL_TABLE,e&262143);return n<0?-1:(Ne.CODEWORD_TABLE[n]-1)%Ne.NUMBER_OF_CODEWORDS}}Ne.NUMBER_OF_CODEWORDS=929,Ne.MAX_CODEWORDS_IN_BARCODE=Ne.NUMBER_OF_CODEWORDS-1,Ne.MIN_ROWS_IN_BARCODE=3,Ne.MAX_ROWS_IN_BARCODE=90,Ne.MODULES_IN_CODEWORD=17,Ne.MODULES_IN_STOP_PATTERN=18,Ne.BARS_IN_MODULE=8,Ne.EMPTY_INT_ARRAY=new Int32Array([]),Ne.SYMBOL_TABLE=Int32Array.from([66142,66170,66206,66236,66290,66292,66350,66382,66396,66454,66470,66476,66594,66600,66614,66626,66628,66632,66640,66654,66662,66668,66682,66690,66718,66720,66748,66758,66776,66798,66802,66804,66820,66824,66832,66846,66848,66876,66880,66936,66950,66956,66968,66992,67006,67022,67036,67042,67044,67048,67062,67118,67150,67164,67214,67228,67256,67294,67322,67350,67366,67372,67398,67404,67416,67438,67474,67476,67490,67492,67496,67510,67618,67624,67650,67656,67664,67678,67686,67692,67706,67714,67716,67728,67742,67744,67772,67782,67788,67800,67822,67826,67828,67842,67848,67870,67872,67900,67904,67960,67974,67992,68016,68030,68046,68060,68066,68068,68072,68086,68104,68112,68126,68128,68156,68160,68216,68336,68358,68364,68376,68400,68414,68448,68476,68494,68508,68536,68546,68548,68552,68560,68574,68582,68588,68654,68686,68700,68706,68708,68712,68726,68750,68764,68792,68802,68804,68808,68816,68830,68838,68844,68858,68878,68892,68920,68976,68990,68994,68996,69e3,69008,69022,69024,69052,69062,69068,69080,69102,69106,69108,69142,69158,69164,69190,69208,69230,69254,69260,69272,69296,69310,69326,69340,69386,69394,69396,69410,69416,69430,69442,69444,69448,69456,69470,69478,69484,69554,69556,69666,69672,69698,69704,69712,69726,69754,69762,69764,69776,69790,69792,69820,69830,69836,69848,69870,69874,69876,69890,69918,69920,69948,69952,70008,70022,70040,70064,70078,70094,70108,70114,70116,70120,70134,70152,70174,70176,70264,70384,70412,70448,70462,70496,70524,70542,70556,70584,70594,70600,70608,70622,70630,70636,70664,70672,70686,70688,70716,70720,70776,70896,71136,71180,71192,71216,71230,71264,71292,71360,71416,71452,71480,71536,71550,71554,71556,71560,71568,71582,71584,71612,71622,71628,71640,71662,71726,71732,71758,71772,71778,71780,71784,71798,71822,71836,71864,71874,71880,71888,71902,71910,71916,71930,71950,71964,71992,72048,72062,72066,72068,72080,72094,72096,72124,72134,72140,72152,72174,72178,72180,72206,72220,72248,72304,72318,72416,72444,72456,72464,72478,72480,72508,72512,72568,72588,72600,72624,72638,72654,72668,72674,72676,72680,72694,72726,72742,72748,72774,72780,72792,72814,72838,72856,72880,72894,72910,72924,72930,72932,72936,72950,72966,72972,72984,73008,73022,73056,73084,73102,73116,73144,73156,73160,73168,73182,73190,73196,73210,73226,73234,73236,73250,73252,73256,73270,73282,73284,73296,73310,73318,73324,73346,73348,73352,73360,73374,73376,73404,73414,73420,73432,73454,73498,73518,73522,73524,73550,73564,73570,73572,73576,73590,73800,73822,73858,73860,73872,73886,73888,73916,73944,73970,73972,73992,74014,74016,74044,74048,74104,74118,74136,74160,74174,74210,74212,74216,74230,74244,74256,74270,74272,74360,74480,74502,74508,74544,74558,74592,74620,74638,74652,74680,74690,74696,74704,74726,74732,74782,74784,74812,74992,75232,75288,75326,75360,75388,75456,75512,75576,75632,75646,75650,75652,75664,75678,75680,75708,75718,75724,75736,75758,75808,75836,75840,75896,76016,76256,76736,76824,76848,76862,76896,76924,76992,77048,77296,77340,77368,77424,77438,77536,77564,77572,77576,77584,77600,77628,77632,77688,77702,77708,77720,77744,77758,77774,77788,77870,77902,77916,77922,77928,77966,77980,78008,78018,78024,78032,78046,78060,78074,78094,78136,78192,78206,78210,78212,78224,78238,78240,78268,78278,78284,78296,78322,78324,78350,78364,78448,78462,78560,78588,78600,78622,78624,78652,78656,78712,78726,78744,78768,78782,78798,78812,78818,78820,78824,78838,78862,78876,78904,78960,78974,79072,79100,79296,79352,79368,79376,79390,79392,79420,79424,79480,79600,79628,79640,79664,79678,79712,79740,79772,79800,79810,79812,79816,79824,79838,79846,79852,79894,79910,79916,79942,79948,79960,79982,79988,80006,80024,80048,80062,80078,80092,80098,80100,80104,80134,80140,80176,80190,80224,80252,80270,80284,80312,80328,80336,80350,80358,80364,80378,80390,80396,80408,80432,80446,80480,80508,80576,80632,80654,80668,80696,80752,80766,80776,80784,80798,80800,80828,80844,80856,80878,80882,80884,80914,80916,80930,80932,80936,80950,80962,80968,80976,80990,80998,81004,81026,81028,81040,81054,81056,81084,81094,81100,81112,81134,81154,81156,81160,81168,81182,81184,81212,81216,81272,81286,81292,81304,81328,81342,81358,81372,81380,81384,81398,81434,81454,81458,81460,81486,81500,81506,81508,81512,81526,81550,81564,81592,81602,81604,81608,81616,81630,81638,81644,81702,81708,81722,81734,81740,81752,81774,81778,81780,82050,82078,82080,82108,82180,82184,82192,82206,82208,82236,82240,82296,82316,82328,82352,82366,82402,82404,82408,82440,82448,82462,82464,82492,82496,82552,82672,82694,82700,82712,82736,82750,82784,82812,82830,82882,82884,82888,82896,82918,82924,82952,82960,82974,82976,83004,83008,83064,83184,83424,83468,83480,83504,83518,83552,83580,83648,83704,83740,83768,83824,83838,83842,83844,83848,83856,83872,83900,83910,83916,83928,83950,83984,84e3,84028,84032,84088,84208,84448,84928,85040,85054,85088,85116,85184,85240,85488,85560,85616,85630,85728,85756,85764,85768,85776,85790,85792,85820,85824,85880,85894,85900,85912,85936,85966,85980,86048,86080,86136,86256,86496,86976,88160,88188,88256,88312,88560,89056,89200,89214,89312,89340,89536,89592,89608,89616,89632,89664,89720,89840,89868,89880,89904,89952,89980,89998,90012,90040,90190,90204,90254,90268,90296,90306,90308,90312,90334,90382,90396,90424,90480,90494,90500,90504,90512,90526,90528,90556,90566,90572,90584,90610,90612,90638,90652,90680,90736,90750,90848,90876,90884,90888,90896,90910,90912,90940,90944,91e3,91014,91020,91032,91056,91070,91086,91100,91106,91108,91112,91126,91150,91164,91192,91248,91262,91360,91388,91584,91640,91664,91678,91680,91708,91712,91768,91888,91928,91952,91966,92e3,92028,92046,92060,92088,92098,92100,92104,92112,92126,92134,92140,92188,92216,92272,92384,92412,92608,92664,93168,93200,93214,93216,93244,93248,93304,93424,93664,93720,93744,93758,93792,93820,93888,93944,93980,94008,94064,94078,94084,94088,94096,94110,94112,94140,94150,94156,94168,94246,94252,94278,94284,94296,94318,94342,94348,94360,94384,94398,94414,94428,94440,94470,94476,94488,94512,94526,94560,94588,94606,94620,94648,94658,94660,94664,94672,94686,94694,94700,94714,94726,94732,94744,94768,94782,94816,94844,94912,94968,94990,95004,95032,95088,95102,95112,95120,95134,95136,95164,95180,95192,95214,95218,95220,95244,95256,95280,95294,95328,95356,95424,95480,95728,95758,95772,95800,95856,95870,95968,95996,96008,96016,96030,96032,96060,96064,96120,96152,96176,96190,96220,96226,96228,96232,96290,96292,96296,96310,96322,96324,96328,96336,96350,96358,96364,96386,96388,96392,96400,96414,96416,96444,96454,96460,96472,96494,96498,96500,96514,96516,96520,96528,96542,96544,96572,96576,96632,96646,96652,96664,96688,96702,96718,96732,96738,96740,96744,96758,96772,96776,96784,96798,96800,96828,96832,96888,97008,97030,97036,97048,97072,97086,97120,97148,97166,97180,97208,97220,97224,97232,97246,97254,97260,97326,97330,97332,97358,97372,97378,97380,97384,97398,97422,97436,97464,97474,97476,97480,97488,97502,97510,97516,97550,97564,97592,97648,97666,97668,97672,97680,97694,97696,97724,97734,97740,97752,97774,97830,97836,97850,97862,97868,97880,97902,97906,97908,97926,97932,97944,97968,97998,98012,98018,98020,98024,98038,98618,98674,98676,98838,98854,98874,98892,98904,98926,98930,98932,98968,99006,99042,99044,99048,99062,99166,99194,99246,99286,99350,99366,99372,99386,99398,99416,99438,99442,99444,99462,99504,99518,99534,99548,99554,99556,99560,99574,99590,99596,99608,99632,99646,99680,99708,99726,99740,99768,99778,99780,99784,99792,99806,99814,99820,99834,99858,99860,99874,99880,99894,99906,99920,99934,99962,99970,99972,99976,99984,99998,1e5,100028,100038,100044,100056,100078,100082,100084,100142,100174,100188,100246,100262,100268,100306,100308,100390,100396,100410,100422,100428,100440,100462,100466,100468,100486,100504,100528,100542,100558,100572,100578,100580,100584,100598,100620,100656,100670,100704,100732,100750,100792,100802,100808,100816,100830,100838,100844,100858,100888,100912,100926,100960,100988,101056,101112,101148,101176,101232,101246,101250,101252,101256,101264,101278,101280,101308,101318,101324,101336,101358,101362,101364,101410,101412,101416,101430,101442,101448,101456,101470,101478,101498,101506,101508,101520,101534,101536,101564,101580,101618,101620,101636,101640,101648,101662,101664,101692,101696,101752,101766,101784,101838,101858,101860,101864,101934,101938,101940,101966,101980,101986,101988,101992,102030,102044,102072,102082,102084,102088,102096,102138,102166,102182,102188,102214,102220,102232,102254,102282,102290,102292,102306,102308,102312,102326,102444,102458,102470,102476,102488,102514,102516,102534,102552,102576,102590,102606,102620,102626,102632,102646,102662,102668,102704,102718,102752,102780,102798,102812,102840,102850,102856,102864,102878,102886,102892,102906,102936,102974,103008,103036,103104,103160,103224,103280,103294,103298,103300,103312,103326,103328,103356,103366,103372,103384,103406,103410,103412,103472,103486,103520,103548,103616,103672,103920,103992,104048,104062,104160,104188,104194,104196,104200,104208,104224,104252,104256,104312,104326,104332,104344,104368,104382,104398,104412,104418,104420,104424,104482,104484,104514,104520,104528,104542,104550,104570,104578,104580,104592,104606,104608,104636,104652,104690,104692,104706,104712,104734,104736,104764,104768,104824,104838,104856,104910,104930,104932,104936,104968,104976,104990,104992,105020,105024,105080,105200,105240,105278,105312,105372,105410,105412,105416,105424,105446,105518,105524,105550,105564,105570,105572,105576,105614,105628,105656,105666,105672,105680,105702,105722,105742,105756,105784,105840,105854,105858,105860,105864,105872,105888,105932,105970,105972,106006,106022,106028,106054,106060,106072,106100,106118,106124,106136,106160,106174,106190,106210,106212,106216,106250,106258,106260,106274,106276,106280,106306,106308,106312,106320,106334,106348,106394,106414,106418,106420,106566,106572,106610,106612,106630,106636,106648,106672,106686,106722,106724,106728,106742,106758,106764,106776,106800,106814,106848,106876,106894,106908,106936,106946,106948,106952,106960,106974,106982,106988,107032,107056,107070,107104,107132,107200,107256,107292,107320,107376,107390,107394,107396,107400,107408,107422,107424,107452,107462,107468,107480,107502,107506,107508,107544,107568,107582,107616,107644,107712,107768,108016,108060,108088,108144,108158,108256,108284,108290,108292,108296,108304,108318,108320,108348,108352,108408,108422,108428,108440,108464,108478,108494,108508,108514,108516,108520,108592,108640,108668,108736,108792,109040,109536,109680,109694,109792,109820,110016,110072,110084,110088,110096,110112,110140,110144,110200,110320,110342,110348,110360,110384,110398,110432,110460,110478,110492,110520,110532,110536,110544,110558,110658,110686,110714,110722,110724,110728,110736,110750,110752,110780,110796,110834,110836,110850,110852,110856,110864,110878,110880,110908,110912,110968,110982,111e3,111054,111074,111076,111080,111108,111112,111120,111134,111136,111164,111168,111224,111344,111372,111422,111456,111516,111554,111556,111560,111568,111590,111632,111646,111648,111676,111680,111736,111856,112096,112152,112224,112252,112320,112440,112514,112516,112520,112528,112542,112544,112588,112686,112718,112732,112782,112796,112824,112834,112836,112840,112848,112870,112890,112910,112924,112952,113008,113022,113026,113028,113032,113040,113054,113056,113100,113138,113140,113166,113180,113208,113264,113278,113376,113404,113416,113424,113440,113468,113472,113560,113614,113634,113636,113640,113686,113702,113708,113734,113740,113752,113778,113780,113798,113804,113816,113840,113854,113870,113890,113892,113896,113926,113932,113944,113968,113982,114016,114044,114076,114114,114116,114120,114128,114150,114170,114194,114196,114210,114212,114216,114242,114244,114248,114256,114270,114278,114306,114308,114312,114320,114334,114336,114364,114380,114420,114458,114478,114482,114484,114510,114524,114530,114532,114536,114842,114866,114868,114970,114994,114996,115042,115044,115048,115062,115130,115226,115250,115252,115278,115292,115298,115300,115304,115318,115342,115394,115396,115400,115408,115422,115430,115436,115450,115478,115494,115514,115526,115532,115570,115572,115738,115758,115762,115764,115790,115804,115810,115812,115816,115830,115854,115868,115896,115906,115912,115920,115934,115942,115948,115962,115996,116024,116080,116094,116098,116100,116104,116112,116126,116128,116156,116166,116172,116184,116206,116210,116212,116246,116262,116268,116282,116294,116300,116312,116334,116338,116340,116358,116364,116376,116400,116414,116430,116444,116450,116452,116456,116498,116500,116514,116520,116534,116546,116548,116552,116560,116574,116582,116588,116602,116654,116694,116714,116762,116782,116786,116788,116814,116828,116834,116836,116840,116854,116878,116892,116920,116930,116936,116944,116958,116966,116972,116986,117006,117048,117104,117118,117122,117124,117136,117150,117152,117180,117190,117196,117208,117230,117234,117236,117304,117360,117374,117472,117500,117506,117508,117512,117520,117536,117564,117568,117624,117638,117644,117656,117680,117694,117710,117724,117730,117732,117736,117750,117782,117798,117804,117818,117830,117848,117874,117876,117894,117936,117950,117966,117986,117988,117992,118022,118028,118040,118064,118078,118112,118140,118172,118210,118212,118216,118224,118238,118246,118266,118306,118312,118338,118352,118366,118374,118394,118402,118404,118408,118416,118430,118432,118460,118476,118514,118516,118574,118578,118580,118606,118620,118626,118628,118632,118678,118694,118700,118730,118738,118740,118830,118834,118836,118862,118876,118882,118884,118888,118902,118926,118940,118968,118978,118980,118984,118992,119006,119014,119020,119034,119068,119096,119152,119166,119170,119172,119176,119184,119198,119200,119228,119238,119244,119256,119278,119282,119284,119324,119352,119408,119422,119520,119548,119554,119556,119560,119568,119582,119584,119612,119616,119672,119686,119692,119704,119728,119742,119758,119772,119778,119780,119784,119798,119920,119934,120032,120060,120256,120312,120324,120328,120336,120352,120384,120440,120560,120582,120588,120600,120624,120638,120672,120700,120718,120732,120760,120770,120772,120776,120784,120798,120806,120812,120870,120876,120890,120902,120908,120920,120946,120948,120966,120972,120984,121008,121022,121038,121058,121060,121064,121078,121100,121112,121136,121150,121184,121212,121244,121282,121284,121288,121296,121318,121338,121356,121368,121392,121406,121440,121468,121536,121592,121656,121730,121732,121736,121744,121758,121760,121804,121842,121844,121890,121922,121924,121928,121936,121950,121958,121978,121986,121988,121992,122e3,122014,122016,122044,122060,122098,122100,122116,122120,122128,122142,122144,122172,122176,122232,122246,122264,122318,122338,122340,122344,122414,122418,122420,122446,122460,122466,122468,122472,122510,122524,122552,122562,122564,122568,122576,122598,122618,122646,122662,122668,122694,122700,122712,122738,122740,122762,122770,122772,122786,122788,122792,123018,123026,123028,123042,123044,123048,123062,123098,123146,123154,123156,123170,123172,123176,123190,123202,123204,123208,123216,123238,123244,123258,123290,123314,123316,123402,123410,123412,123426,123428,123432,123446,123458,123464,123472,123486,123494,123500,123514,123522,123524,123528,123536,123552,123580,123590,123596,123608,123630,123634,123636,123674,123698,123700,123740,123746,123748,123752,123834,123914,123922,123924,123938,123944,123958,123970,123976,123984,123998,124006,124012,124026,124034,124036,124048,124062,124064,124092,124102,124108,124120,124142,124146,124148,124162,124164,124168,124176,124190,124192,124220,124224,124280,124294,124300,124312,124336,124350,124366,124380,124386,124388,124392,124406,124442,124462,124466,124468,124494,124508,124514,124520,124558,124572,124600,124610,124612,124616,124624,124646,124666,124694,124710,124716,124730,124742,124748,124760,124786,124788,124818,124820,124834,124836,124840,124854,124946,124948,124962,124964,124968,124982,124994,124996,125e3,125008,125022,125030,125036,125050,125058,125060,125064,125072,125086,125088,125116,125126,125132,125144,125166,125170,125172,125186,125188,125192,125200,125216,125244,125248,125304,125318,125324,125336,125360,125374,125390,125404,125410,125412,125416,125430,125444,125448,125456,125472,125504,125560,125680,125702,125708,125720,125744,125758,125792,125820,125838,125852,125880,125890,125892,125896,125904,125918,125926,125932,125978,125998,126002,126004,126030,126044,126050,126052,126056,126094,126108,126136,126146,126148,126152,126160,126182,126202,126222,126236,126264,126320,126334,126338,126340,126344,126352,126366,126368,126412,126450,126452,126486,126502,126508,126522,126534,126540,126552,126574,126578,126580,126598,126604,126616,126640,126654,126670,126684,126690,126692,126696,126738,126754,126756,126760,126774,126786,126788,126792,126800,126814,126822,126828,126842,126894,126898,126900,126934,127126,127142,127148,127162,127178,127186,127188,127254,127270,127276,127290,127302,127308,127320,127342,127346,127348,127370,127378,127380,127394,127396,127400,127450,127510,127526,127532,127546,127558,127576,127598,127602,127604,127622,127628,127640,127664,127678,127694,127708,127714,127716,127720,127734,127754,127762,127764,127778,127784,127810,127812,127816,127824,127838,127846,127866,127898,127918,127922,127924,128022,128038,128044,128058,128070,128076,128088,128110,128114,128116,128134,128140,128152,128176,128190,128206,128220,128226,128228,128232,128246,128262,128268,128280,128304,128318,128352,128380,128398,128412,128440,128450,128452,128456,128464,128478,128486,128492,128506,128522,128530,128532,128546,128548,128552,128566,128578,128580,128584,128592,128606,128614,128634,128642,128644,128648,128656,128670,128672,128700,128716,128754,128756,128794,128814,128818,128820,128846,128860,128866,128868,128872,128886,128918,128934,128940,128954,128978,128980,129178,129198,129202,129204,129238,129258,129306,129326,129330,129332,129358,129372,129378,129380,129384,129398,129430,129446,129452,129466,129482,129490,129492,129562,129582,129586,129588,129614,129628,129634,129636,129640,129654,129678,129692,129720,129730,129732,129736,129744,129758,129766,129772,129814,129830,129836,129850,129862,129868,129880,129902,129906,129908,129930,129938,129940,129954,129956,129960,129974,130010]),Ne.CODEWORD_TABLE=Int32Array.from([2627,1819,2622,2621,1813,1812,2729,2724,2723,2779,2774,2773,902,896,908,868,865,861,859,2511,873,871,1780,835,2493,825,2491,842,837,844,1764,1762,811,810,809,2483,807,2482,806,2480,815,814,813,812,2484,817,816,1745,1744,1742,1746,2655,2637,2635,2626,2625,2623,2628,1820,2752,2739,2737,2728,2727,2725,2730,2785,2783,2778,2777,2775,2780,787,781,747,739,736,2413,754,752,1719,692,689,681,2371,678,2369,700,697,694,703,1688,1686,642,638,2343,631,2341,627,2338,651,646,643,2345,654,652,1652,1650,1647,1654,601,599,2322,596,2321,594,2319,2317,611,610,608,606,2324,603,2323,615,614,612,1617,1616,1614,1612,616,1619,1618,2575,2538,2536,905,901,898,909,2509,2507,2504,870,867,864,860,2512,875,872,1781,2490,2489,2487,2485,1748,836,834,832,830,2494,827,2492,843,841,839,845,1765,1763,2701,2676,2674,2653,2648,2656,2634,2633,2631,2629,1821,2638,2636,2770,2763,2761,2750,2745,2753,2736,2735,2733,2731,1848,2740,2738,2786,2784,591,588,576,569,566,2296,1590,537,534,526,2276,522,2274,545,542,539,548,1572,1570,481,2245,466,2242,462,2239,492,485,482,2249,496,494,1534,1531,1528,1538,413,2196,406,2191,2188,425,419,2202,415,2199,432,430,427,1472,1467,1464,433,1476,1474,368,367,2160,365,2159,362,2157,2155,2152,378,377,375,2166,372,2165,369,2162,383,381,379,2168,1419,1418,1416,1414,385,1411,384,1423,1422,1420,1424,2461,802,2441,2439,790,786,783,794,2409,2406,2403,750,742,738,2414,756,753,1720,2367,2365,2362,2359,1663,693,691,684,2373,680,2370,702,699,696,704,1690,1687,2337,2336,2334,2332,1624,2329,1622,640,637,2344,634,2342,630,2340,650,648,645,2346,655,653,1653,1651,1649,1655,2612,2597,2595,2571,2568,2565,2576,2534,2529,2526,1787,2540,2537,907,904,900,910,2503,2502,2500,2498,1768,2495,1767,2510,2508,2506,869,866,863,2513,876,874,1782,2720,2713,2711,2697,2694,2691,2702,2672,2670,2664,1828,2678,2675,2647,2646,2644,2642,1823,2639,1822,2654,2652,2650,2657,2771,1855,2765,2762,1850,1849,2751,2749,2747,2754,353,2148,344,342,336,2142,332,2140,345,1375,1373,306,2130,299,2128,295,2125,319,314,311,2132,1354,1352,1349,1356,262,257,2101,253,2096,2093,274,273,267,2107,263,2104,280,278,275,1316,1311,1308,1320,1318,2052,202,2050,2044,2040,219,2063,212,2060,208,2055,224,221,2066,1260,1258,1252,231,1248,229,1266,1264,1261,1268,155,1998,153,1996,1994,1991,1988,165,164,2007,162,2006,159,2003,2e3,172,171,169,2012,166,2010,1186,1184,1182,1179,175,1176,173,1192,1191,1189,1187,176,1194,1193,2313,2307,2305,592,589,2294,2292,2289,578,572,568,2297,580,1591,2272,2267,2264,1547,538,536,529,2278,525,2275,547,544,541,1574,1571,2237,2235,2229,1493,2225,1489,478,2247,470,2244,465,2241,493,488,484,2250,498,495,1536,1533,1530,1539,2187,2186,2184,2182,1432,2179,1430,2176,1427,414,412,2197,409,2195,405,2193,2190,426,424,421,2203,418,2201,431,429,1473,1471,1469,1466,434,1477,1475,2478,2472,2470,2459,2457,2454,2462,803,2437,2432,2429,1726,2443,2440,792,789,785,2401,2399,2393,1702,2389,1699,2411,2408,2405,745,741,2415,758,755,1721,2358,2357,2355,2353,1661,2350,1660,2347,1657,2368,2366,2364,2361,1666,690,687,2374,683,2372,701,698,705,1691,1689,2619,2617,2610,2608,2605,2613,2593,2588,2585,1803,2599,2596,2563,2561,2555,1797,2551,1795,2573,2570,2567,2577,2525,2524,2522,2520,1786,2517,1785,2514,1783,2535,2533,2531,2528,1788,2541,2539,906,903,911,2721,1844,2715,2712,1838,1836,2699,2696,2693,2703,1827,1826,1824,2673,2671,2669,2666,1829,2679,2677,1858,1857,2772,1854,1853,1851,1856,2766,2764,143,1987,139,1986,135,133,131,1984,128,1983,125,1981,138,137,136,1985,1133,1132,1130,112,110,1974,107,1973,104,1971,1969,122,121,119,117,1977,114,1976,124,1115,1114,1112,1110,1117,1116,84,83,1953,81,1952,78,1950,1948,1945,94,93,91,1959,88,1958,85,1955,99,97,95,1961,1086,1085,1083,1081,1078,100,1090,1089,1087,1091,49,47,1917,44,1915,1913,1910,1907,59,1926,56,1925,53,1922,1919,66,64,1931,61,1929,1042,1040,1038,71,1035,70,1032,68,1048,1047,1045,1043,1050,1049,12,10,1869,1867,1864,1861,21,1880,19,1877,1874,1871,28,1888,25,1886,22,1883,982,980,977,974,32,30,991,989,987,984,34,995,994,992,2151,2150,2147,2146,2144,356,355,354,2149,2139,2138,2136,2134,1359,343,341,338,2143,335,2141,348,347,346,1376,1374,2124,2123,2121,2119,1326,2116,1324,310,308,305,2131,302,2129,298,2127,320,318,316,313,2133,322,321,1355,1353,1351,1357,2092,2091,2089,2087,1276,2084,1274,2081,1271,259,2102,256,2100,252,2098,2095,272,269,2108,266,2106,281,279,277,1317,1315,1313,1310,282,1321,1319,2039,2037,2035,2032,1203,2029,1200,1197,207,2053,205,2051,201,2049,2046,2043,220,218,2064,215,2062,211,2059,228,226,223,2069,1259,1257,1254,232,1251,230,1267,1265,1263,2316,2315,2312,2311,2309,2314,2304,2303,2301,2299,1593,2308,2306,590,2288,2287,2285,2283,1578,2280,1577,2295,2293,2291,579,577,574,571,2298,582,581,1592,2263,2262,2260,2258,1545,2255,1544,2252,1541,2273,2271,2269,2266,1550,535,532,2279,528,2277,546,543,549,1575,1573,2224,2222,2220,1486,2217,1485,2214,1482,1479,2238,2236,2234,2231,1496,2228,1492,480,477,2248,473,2246,469,2243,490,487,2251,497,1537,1535,1532,2477,2476,2474,2479,2469,2468,2466,2464,1730,2473,2471,2453,2452,2450,2448,1729,2445,1728,2460,2458,2456,2463,805,804,2428,2427,2425,2423,1725,2420,1724,2417,1722,2438,2436,2434,2431,1727,2444,2442,793,791,788,795,2388,2386,2384,1697,2381,1696,2378,1694,1692,2402,2400,2398,2395,1703,2392,1701,2412,2410,2407,751,748,744,2416,759,757,1807,2620,2618,1806,1805,2611,2609,2607,2614,1802,1801,1799,2594,2592,2590,2587,1804,2600,2598,1794,1793,1791,1789,2564,2562,2560,2557,1798,2554,1796,2574,2572,2569,2578,1847,1846,2722,1843,1842,1840,1845,2716,2714,1835,1834,1832,1830,1839,1837,2700,2698,2695,2704,1817,1811,1810,897,862,1777,829,826,838,1760,1758,808,2481,1741,1740,1738,1743,2624,1818,2726,2776,782,740,737,1715,686,679,695,1682,1680,639,628,2339,647,644,1645,1643,1640,1648,602,600,597,595,2320,593,2318,609,607,604,1611,1610,1608,1606,613,1615,1613,2328,926,924,892,886,899,857,850,2505,1778,824,823,821,819,2488,818,2486,833,831,828,840,1761,1759,2649,2632,2630,2746,2734,2732,2782,2781,570,567,1587,531,527,523,540,1566,1564,476,467,463,2240,486,483,1524,1521,1518,1529,411,403,2192,399,2189,423,416,1462,1457,1454,428,1468,1465,2210,366,363,2158,360,2156,357,2153,376,373,370,2163,1410,1409,1407,1405,382,1402,380,1417,1415,1412,1421,2175,2174,777,774,771,784,732,725,722,2404,743,1716,676,674,668,2363,665,2360,685,1684,1681,626,624,622,2335,620,2333,617,2330,641,635,649,1646,1644,1642,2566,928,925,2530,2527,894,891,888,2501,2499,2496,858,856,854,851,1779,2692,2668,2665,2645,2643,2640,2651,2768,2759,2757,2744,2743,2741,2748,352,1382,340,337,333,1371,1369,307,300,296,2126,315,312,1347,1342,1350,261,258,250,2097,246,2094,271,268,264,1306,1301,1298,276,1312,1309,2115,203,2048,195,2045,191,2041,213,209,2056,1246,1244,1238,225,1234,222,1256,1253,1249,1262,2080,2079,154,1997,150,1995,147,1992,1989,163,160,2004,156,2001,1175,1174,1172,1170,1167,170,1164,167,1185,1183,1180,1177,174,1190,1188,2025,2024,2022,587,586,564,559,556,2290,573,1588,520,518,512,2268,508,2265,530,1568,1565,461,457,2233,450,2230,446,2226,479,471,489,1526,1523,1520,397,395,2185,392,2183,389,2180,2177,410,2194,402,422,1463,1461,1459,1456,1470,2455,799,2433,2430,779,776,773,2397,2394,2390,734,728,724,746,1717,2356,2354,2351,2348,1658,677,675,673,670,667,688,1685,1683,2606,2589,2586,2559,2556,2552,927,2523,2521,2518,2515,1784,2532,895,893,890,2718,2709,2707,2689,2687,2684,2663,2662,2660,2658,1825,2667,2769,1852,2760,2758,142,141,1139,1138,134,132,129,126,1982,1129,1128,1126,1131,113,111,108,105,1972,101,1970,120,118,115,1109,1108,1106,1104,123,1113,1111,82,79,1951,75,1949,72,1946,92,89,86,1956,1077,1076,1074,1072,98,1069,96,1084,1082,1079,1088,1968,1967,48,45,1916,42,1914,39,1911,1908,60,57,54,1923,50,1920,1031,1030,1028,1026,67,1023,65,1020,62,1041,1039,1036,1033,69,1046,1044,1944,1943,1941,11,9,1868,7,1865,1862,1859,20,1878,16,1875,13,1872,970,968,966,963,29,960,26,23,983,981,978,975,33,971,31,990,988,985,1906,1904,1902,993,351,2145,1383,331,330,328,326,2137,323,2135,339,1372,1370,294,293,291,289,2122,286,2120,283,2117,309,303,317,1348,1346,1344,245,244,242,2090,239,2088,236,2085,2082,260,2099,249,270,1307,1305,1303,1300,1314,189,2038,186,2036,183,2033,2030,2026,206,198,2047,194,216,1247,1245,1243,1240,227,1237,1255,2310,2302,2300,2286,2284,2281,565,563,561,558,575,1589,2261,2259,2256,2253,1542,521,519,517,514,2270,511,533,1569,1567,2223,2221,2218,2215,1483,2211,1480,459,456,453,2232,449,474,491,1527,1525,1522,2475,2467,2465,2451,2449,2446,801,800,2426,2424,2421,2418,1723,2435,780,778,775,2387,2385,2382,2379,1695,2375,1693,2396,735,733,730,727,749,1718,2616,2615,2604,2603,2601,2584,2583,2581,2579,1800,2591,2550,2549,2547,2545,1792,2542,1790,2558,929,2719,1841,2710,2708,1833,1831,2690,2688,2686,1815,1809,1808,1774,1756,1754,1737,1736,1734,1739,1816,1711,1676,1674,633,629,1638,1636,1633,1641,598,1605,1604,1602,1600,605,1609,1607,2327,887,853,1775,822,820,1757,1755,1584,524,1560,1558,468,464,1514,1511,1508,1519,408,404,400,1452,1447,1444,417,1458,1455,2208,364,361,358,2154,1401,1400,1398,1396,374,1393,371,1408,1406,1403,1413,2173,2172,772,726,723,1712,672,669,666,682,1678,1675,625,623,621,618,2331,636,632,1639,1637,1635,920,918,884,880,889,849,848,847,846,2497,855,852,1776,2641,2742,2787,1380,334,1367,1365,301,297,1340,1338,1335,1343,255,251,247,1296,1291,1288,265,1302,1299,2113,204,196,192,2042,1232,1230,1224,214,1220,210,1242,1239,1235,1250,2077,2075,151,148,1993,144,1990,1163,1162,1160,1158,1155,161,1152,157,1173,1171,1168,1165,168,1181,1178,2021,2020,2018,2023,585,560,557,1585,516,509,1562,1559,458,447,2227,472,1516,1513,1510,398,396,393,390,2181,386,2178,407,1453,1451,1449,1446,420,1460,2209,769,764,720,712,2391,729,1713,664,663,661,659,2352,656,2349,671,1679,1677,2553,922,919,2519,2516,885,883,881,2685,2661,2659,2767,2756,2755,140,1137,1136,130,127,1125,1124,1122,1127,109,106,102,1103,1102,1100,1098,116,1107,1105,1980,80,76,73,1947,1068,1067,1065,1063,90,1060,87,1075,1073,1070,1080,1966,1965,46,43,40,1912,36,1909,1019,1018,1016,1014,58,1011,55,1008,51,1029,1027,1024,1021,63,1037,1034,1940,1939,1937,1942,8,1866,4,1863,1,1860,956,954,952,949,946,17,14,969,967,964,961,27,957,24,979,976,972,1901,1900,1898,1896,986,1905,1903,350,349,1381,329,327,324,1368,1366,292,290,287,284,2118,304,1341,1339,1337,1345,243,240,237,2086,233,2083,254,1297,1295,1293,1290,1304,2114,190,187,184,2034,180,2031,177,2027,199,1233,1231,1229,1226,217,1223,1241,2078,2076,584,555,554,552,550,2282,562,1586,507,506,504,502,2257,499,2254,515,1563,1561,445,443,441,2219,438,2216,435,2212,460,454,475,1517,1515,1512,2447,798,797,2422,2419,770,768,766,2383,2380,2376,721,719,717,714,731,1714,2602,2582,2580,2548,2546,2543,923,921,2717,2706,2705,2683,2682,2680,1771,1752,1750,1733,1732,1731,1735,1814,1707,1670,1668,1631,1629,1626,1634,1599,1598,1596,1594,1603,1601,2326,1772,1753,1751,1581,1554,1552,1504,1501,1498,1509,1442,1437,1434,401,1448,1445,2206,1392,1391,1389,1387,1384,359,1399,1397,1394,1404,2171,2170,1708,1672,1669,619,1632,1630,1628,1773,1378,1363,1361,1333,1328,1336,1286,1281,1278,248,1292,1289,2111,1218,1216,1210,197,1206,193,1228,1225,1221,1236,2073,2071,1151,1150,1148,1146,152,1143,149,1140,145,1161,1159,1156,1153,158,1169,1166,2017,2016,2014,2019,1582,510,1556,1553,452,448,1506,1500,394,391,387,1443,1441,1439,1436,1450,2207,765,716,713,1709,662,660,657,1673,1671,916,914,879,878,877,882,1135,1134,1121,1120,1118,1123,1097,1096,1094,1092,103,1101,1099,1979,1059,1058,1056,1054,77,1051,74,1066,1064,1061,1071,1964,1963,1007,1006,1004,1002,999,41,996,37,1017,1015,1012,1009,52,1025,1022,1936,1935,1933,1938,942,940,938,935,932,5,2,955,953,950,947,18,943,15,965,962,958,1895,1894,1892,1890,973,1899,1897,1379,325,1364,1362,288,285,1334,1332,1330,241,238,234,1287,1285,1283,1280,1294,2112,188,185,181,178,2028,1219,1217,1215,1212,200,1209,1227,2074,2072,583,553,551,1583,505,503,500,513,1557,1555,444,442,439,436,2213,455,451,1507,1505,1502,796,763,762,760,767,711,710,708,706,2377,718,715,1710,2544,917,915,2681,1627,1597,1595,2325,1769,1749,1747,1499,1438,1435,2204,1390,1388,1385,1395,2169,2167,1704,1665,1662,1625,1623,1620,1770,1329,1282,1279,2109,1214,1207,1222,2068,2065,1149,1147,1144,1141,146,1157,1154,2013,2011,2008,2015,1579,1549,1546,1495,1487,1433,1431,1428,1425,388,1440,2205,1705,658,1667,1664,1119,1095,1093,1978,1057,1055,1052,1062,1962,1960,1005,1003,1e3,997,38,1013,1010,1932,1930,1927,1934,941,939,936,933,6,930,3,951,948,944,1889,1887,1884,1881,959,1893,1891,35,1377,1360,1358,1327,1325,1322,1331,1277,1275,1272,1269,235,1284,2110,1205,1204,1201,1198,182,1195,179,1213,2070,2067,1580,501,1551,1548,440,437,1497,1494,1490,1503,761,709,707,1706,913,912,2198,1386,2164,2161,1621,1766,2103,1208,2058,2054,1145,1142,2005,2002,1999,2009,1488,1429,1426,2200,1698,1659,1656,1975,1053,1957,1954,1001,998,1924,1921,1918,1928,937,934,931,1879,1876,1873,1870,945,1885,1882,1323,1273,1270,2105,1202,1199,1196,1211,2061,2057,1576,1543,1540,1484,1481,1478,1491,1700]);class rd{constructor(e,n){this.bits=e,this.points=n}getBits(){return this.bits}getPoints(){return this.points}}class Ue{static detectMultiple(e,n,i){let s=e.getBlackMatrix(),a=Ue.detect(i,s);return a.length||(s=s.clone(),s.rotate180(),a=Ue.detect(i,s)),new rd(s,a)}static detect(e,n){const i=new Array;let s=0,a=0,l=!1;for(;s<n.getHeight();){const d=Ue.findVertices(n,s,a);if(d[0]==null&&d[3]==null){if(!l)break;l=!1,a=0;for(const h of i)h[1]!=null&&(s=Math.trunc(Math.max(s,h[1].getY()))),h[3]!=null&&(s=Math.max(s,Math.trunc(h[3].getY())));s+=Ue.ROW_STEP;continue}if(l=!0,i.push(d),!e)break;d[2]!=null?(a=Math.trunc(d[2].getX()),s=Math.trunc(d[2].getY())):(a=Math.trunc(d[4].getX()),s=Math.trunc(d[4].getY()))}return i}static findVertices(e,n,i){const s=e.getHeight(),a=e.getWidth(),l=new Array(8);return Ue.copyToResult(l,Ue.findRowsWithPattern(e,s,a,n,i,Ue.START_PATTERN),Ue.INDEXES_START_PATTERN),l[4]!=null&&(i=Math.trunc(l[4].getX()),n=Math.trunc(l[4].getY())),Ue.copyToResult(l,Ue.findRowsWithPattern(e,s,a,n,i,Ue.STOP_PATTERN),Ue.INDEXES_STOP_PATTERN),l}static copyToResult(e,n,i){for(let s=0;s<i.length;s++)e[i[s]]=n[s]}static findRowsWithPattern(e,n,i,s,a,l){const d=new Array(4);let h=!1;const m=new Int32Array(l.length);for(;s<n;s+=Ue.ROW_STEP){let b=Ue.findGuardPattern(e,a,s,i,!1,l,m);if(b!=null){for(;s>0;){const I=Ue.findGuardPattern(e,a,--s,i,!1,l,m);if(I!=null)b=I;else{s++;break}}d[0]=new N(b[0],s),d[1]=new N(b[1],s),h=!0;break}}let y=s+1;if(h){let b=0,I=Int32Array.from([Math.trunc(d[0].getX()),Math.trunc(d[1].getX())]);for(;y<n;y++){const k=Ue.findGuardPattern(e,I[0],y,i,!1,l,m);if(k!=null&&Math.abs(I[0]-k[0])<Ue.MAX_PATTERN_DRIFT&&Math.abs(I[1]-k[1])<Ue.MAX_PATTERN_DRIFT)I=k,b=0;else{if(b>Ue.SKIPPED_ROW_COUNT_MAX)break;b++}}y-=b+1,d[2]=new N(I[0],y),d[3]=new N(I[1],y)}return y-s<Ue.BARCODE_MIN_HEIGHT&&Z.fill(d,null),d}static findGuardPattern(e,n,i,s,a,l,d){Z.fillWithin(d,0,d.length,0);let h=n,m=0;for(;e.get(h,i)&&h>0&&m++<Ue.MAX_PIXEL_DRIFT;)h--;let y=h,b=0,I=l.length;for(let k=a;y<s;y++)if(e.get(y,i)!==k)d[b]++;else{if(b===I-1){if(Ue.patternMatchVariance(d,l,Ue.MAX_INDIVIDUAL_VARIANCE)<Ue.MAX_AVG_VARIANCE)return new Int32Array([h,y]);h+=d[0]+d[1],R.arraycopy(d,2,d,0,b-1),d[b-1]=0,d[b]=0,b--}else b++;d[b]=1,k=!k}return b===I-1&&Ue.patternMatchVariance(d,l,Ue.MAX_INDIVIDUAL_VARIANCE)<Ue.MAX_AVG_VARIANCE?new Int32Array([h,y-1]):null}static patternMatchVariance(e,n,i){let s=e.length,a=0,l=0;for(let m=0;m<s;m++)a+=e[m],l+=n[m];if(a<l)return 1/0;let d=a/l;i*=d;let h=0;for(let m=0;m<s;m++){let y=e[m],b=n[m]*d,I=y>b?y-b:b-y;if(I>i)return 1/0;h+=I}return h/a}}Ue.INDEXES_START_PATTERN=Int32Array.from([0,4,1,5]),Ue.INDEXES_STOP_PATTERN=Int32Array.from([6,2,7,3]),Ue.MAX_AVG_VARIANCE=.42,Ue.MAX_INDIVIDUAL_VARIANCE=.8,Ue.START_PATTERN=Int32Array.from([8,1,1,1,1,1,1,3]),Ue.STOP_PATTERN=Int32Array.from([7,1,1,3,1,1,1,2,1]),Ue.MAX_PIXEL_DRIFT=3,Ue.MAX_PATTERN_DRIFT=5,Ue.SKIPPED_ROW_COUNT_MAX=25,Ue.ROW_STEP=5,Ue.BARCODE_MIN_HEIGHT=10;class zt{constructor(e,n){if(n.length===0)throw new E;this.field=e;let i=n.length;if(i>1&&n[0]===0){let s=1;for(;s<i&&n[s]===0;)s++;s===i?this.coefficients=new Int32Array([0]):(this.coefficients=new Int32Array(i-s),R.arraycopy(n,s,this.coefficients,0,this.coefficients.length))}else this.coefficients=n}getCoefficients(){return this.coefficients}getDegree(){return this.coefficients.length-1}isZero(){return this.coefficients[0]===0}getCoefficient(e){return this.coefficients[this.coefficients.length-1-e]}evaluateAt(e){if(e===0)return this.getCoefficient(0);if(e===1){let s=0;for(let a of this.coefficients)s=this.field.add(s,a);return s}let n=this.coefficients[0],i=this.coefficients.length;for(let s=1;s<i;s++)n=this.field.add(this.field.multiply(e,n),this.coefficients[s]);return n}add(e){if(!this.field.equals(e.field))throw new E("ModulusPolys do not have same ModulusGF field");if(this.isZero())return e;if(e.isZero())return this;let n=this.coefficients,i=e.coefficients;if(n.length>i.length){let l=n;n=i,i=l}let s=new Int32Array(i.length),a=i.length-n.length;R.arraycopy(i,0,s,0,a);for(let l=a;l<i.length;l++)s[l]=this.field.add(n[l-a],i[l]);return new zt(this.field,s)}subtract(e){if(!this.field.equals(e.field))throw new E("ModulusPolys do not have same ModulusGF field");return e.isZero()?this:this.add(e.negative())}multiply(e){return e instanceof zt?this.multiplyOther(e):this.multiplyScalar(e)}multiplyOther(e){if(!this.field.equals(e.field))throw new E("ModulusPolys do not have same ModulusGF field");if(this.isZero()||e.isZero())return new zt(this.field,new Int32Array([0]));let n=this.coefficients,i=n.length,s=e.coefficients,a=s.length,l=new Int32Array(i+a-1);for(let d=0;d<i;d++){let h=n[d];for(let m=0;m<a;m++)l[d+m]=this.field.add(l[d+m],this.field.multiply(h,s[m]))}return new zt(this.field,l)}negative(){let e=this.coefficients.length,n=new Int32Array(e);for(let i=0;i<e;i++)n[i]=this.field.subtract(0,this.coefficients[i]);return new zt(this.field,n)}multiplyScalar(e){if(e===0)return new zt(this.field,new Int32Array([0]));if(e===1)return this;let n=this.coefficients.length,i=new Int32Array(n);for(let s=0;s<n;s++)i[s]=this.field.multiply(this.coefficients[s],e);return new zt(this.field,i)}multiplyByMonomial(e,n){if(e<0)throw new E;if(n===0)return new zt(this.field,new Int32Array([0]));let i=this.coefficients.length,s=new Int32Array(i+e);for(let a=0;a<i;a++)s[a]=this.field.multiply(this.coefficients[a],n);return new zt(this.field,s)}toString(){let e=new le;for(let n=this.getDegree();n>=0;n--){let i=this.getCoefficient(n);i!==0&&(i<0?(e.append(" - "),i=-i):e.length()>0&&e.append(" + "),(n===0||i!==1)&&e.append(i),n!==0&&(n===1?e.append("x"):(e.append("x^"),e.append(n))))}return e.toString()}}class id{add(e,n){return(e+n)%this.modulus}subtract(e,n){return(this.modulus+e-n)%this.modulus}exp(e){return this.expTable[e]}log(e){if(e===0)throw new E;return this.logTable[e]}inverse(e){if(e===0)throw new Wt;return this.expTable[this.modulus-this.logTable[e]-1]}multiply(e,n){return e===0||n===0?0:this.expTable[(this.logTable[e]+this.logTable[n])%(this.modulus-1)]}getSize(){return this.modulus}equals(e){return e===this}}class no extends id{constructor(e,n){super(),this.modulus=e,this.expTable=new Int32Array(e),this.logTable=new Int32Array(e);let i=1;for(let s=0;s<e;s++)this.expTable[s]=i,i=i*n%e;for(let s=0;s<e-1;s++)this.logTable[this.expTable[s]]=s;this.zero=new zt(this,new Int32Array([0])),this.one=new zt(this,new Int32Array([1]))}getZero(){return this.zero}getOne(){return this.one}buildMonomial(e,n){if(e<0)throw new E;if(n===0)return this.zero;let i=new Int32Array(e+1);return i[0]=n,new zt(this,i)}}no.PDF417_GF=new no(Ne.NUMBER_OF_CODEWORDS,3);class fs{constructor(){this.field=no.PDF417_GF}decode(e,n,i){let s=new zt(this.field,e),a=new Int32Array(n),l=!1;for(let F=n;F>0;F--){let U=s.evaluateAt(this.field.exp(F));a[n-F]=U,U!==0&&(l=!0)}if(!l)return 0;let d=this.field.getOne();if(i!=null)for(const F of i){let U=this.field.exp(e.length-1-F),G=new zt(this.field,new Int32Array([this.field.subtract(0,U),1]));d=d.multiply(G)}let h=new zt(this.field,a),m=this.runEuclideanAlgorithm(this.field.buildMonomial(n,1),h,n),y=m[0],b=m[1],I=this.findErrorLocations(y),k=this.findErrorMagnitudes(b,y,I);for(let F=0;F<I.length;F++){let U=e.length-1-this.field.log(I[F]);if(U<0)throw M.getChecksumInstance();e[U]=this.field.subtract(e[U],k[F])}return I.length}runEuclideanAlgorithm(e,n,i){if(e.getDegree()<n.getDegree()){let I=e;e=n,n=I}let s=e,a=n,l=this.field.getZero(),d=this.field.getOne();for(;a.getDegree()>=Math.round(i/2);){let I=s,k=l;if(s=a,l=d,s.isZero())throw M.getChecksumInstance();a=I;let F=this.field.getZero(),U=s.getCoefficient(s.getDegree()),G=this.field.inverse(U);for(;a.getDegree()>=s.getDegree()&&!a.isZero();){let Q=a.getDegree()-s.getDegree(),fe=this.field.multiply(a.getCoefficient(a.getDegree()),G);F=F.add(this.field.buildMonomial(Q,fe)),a=a.subtract(s.multiplyByMonomial(Q,fe))}d=F.multiply(l).subtract(k).negative()}let h=d.getCoefficient(0);if(h===0)throw M.getChecksumInstance();let m=this.field.inverse(h),y=d.multiply(m),b=a.multiply(m);return[y,b]}findErrorLocations(e){let n=e.getDegree(),i=new Int32Array(n),s=0;for(let a=1;a<this.field.getSize()&&s<n;a++)e.evaluateAt(a)===0&&(i[s]=this.field.inverse(a),s++);if(s!==n)throw M.getChecksumInstance();return i}findErrorMagnitudes(e,n,i){let s=n.getDegree(),a=new Int32Array(s);for(let m=1;m<=s;m++)a[s-m]=this.field.multiply(m,n.getCoefficient(m));let l=new zt(this.field,a),d=i.length,h=new Int32Array(d);for(let m=0;m<d;m++){let y=this.field.inverse(i[m]),b=this.field.subtract(0,e.evaluateAt(y)),I=this.field.inverse(l.evaluateAt(y));h[m]=this.field.multiply(b,I)}return h}}class nr{constructor(e,n,i,s,a){e instanceof nr?this.constructor_2(e):this.constructor_1(e,n,i,s,a)}constructor_1(e,n,i,s,a){const l=n==null||i==null,d=s==null||a==null;if(l&&d)throw new O;l?(n=new N(0,s.getY()),i=new N(0,a.getY())):d&&(s=new N(e.getWidth()-1,n.getY()),a=new N(e.getWidth()-1,i.getY())),this.image=e,this.topLeft=n,this.bottomLeft=i,this.topRight=s,this.bottomRight=a,this.minX=Math.trunc(Math.min(n.getX(),i.getX())),this.maxX=Math.trunc(Math.max(s.getX(),a.getX())),this.minY=Math.trunc(Math.min(n.getY(),s.getY())),this.maxY=Math.trunc(Math.max(i.getY(),a.getY()))}constructor_2(e){this.image=e.image,this.topLeft=e.getTopLeft(),this.bottomLeft=e.getBottomLeft(),this.topRight=e.getTopRight(),this.bottomRight=e.getBottomRight(),this.minX=e.getMinX(),this.maxX=e.getMaxX(),this.minY=e.getMinY(),this.maxY=e.getMaxY()}static merge(e,n){return e==null?n:n==null?e:new nr(e.image,e.topLeft,e.bottomLeft,n.topRight,n.bottomRight)}addMissingRows(e,n,i){let s=this.topLeft,a=this.bottomLeft,l=this.topRight,d=this.bottomRight;if(e>0){let h=i?this.topLeft:this.topRight,m=Math.trunc(h.getY()-e);m<0&&(m=0);let y=new N(h.getX(),m);i?s=y:l=y}if(n>0){let h=i?this.bottomLeft:this.bottomRight,m=Math.trunc(h.getY()+n);m>=this.image.getHeight()&&(m=this.image.getHeight()-1);let y=new N(h.getX(),m);i?a=y:d=y}return new nr(this.image,s,a,l,d)}getMinX(){return this.minX}getMaxX(){return this.maxX}getMinY(){return this.minY}getMaxY(){return this.maxY}getTopLeft(){return this.topLeft}getTopRight(){return this.topRight}getBottomLeft(){return this.bottomLeft}getBottomRight(){return this.bottomRight}}class od{constructor(e,n,i,s){this.columnCount=e,this.errorCorrectionLevel=s,this.rowCountUpperPart=n,this.rowCountLowerPart=i,this.rowCount=n+i}getColumnCount(){return this.columnCount}getErrorCorrectionLevel(){return this.errorCorrectionLevel}getRowCount(){return this.rowCount}getRowCountUpperPart(){return this.rowCountUpperPart}getRowCountLowerPart(){return this.rowCountLowerPart}}class Rr{constructor(){this.buffer=""}static form(e,n){let i=-1;function s(l,d,h,m,y,b){if(l==="%%")return"%";if(n[++i]===void 0)return;l=m?parseInt(m.substr(1)):void 0;let I=y?parseInt(y.substr(1)):void 0,k;switch(b){case"s":k=n[i];break;case"c":k=n[i][0];break;case"f":k=parseFloat(n[i]).toFixed(l);break;case"p":k=parseFloat(n[i]).toPrecision(l);break;case"e":k=parseFloat(n[i]).toExponential(l);break;case"x":k=parseInt(n[i]).toString(I||16);break;case"d":k=parseFloat(parseInt(n[i],I||10).toPrecision(l)).toFixed(0);break}k=typeof k=="object"?JSON.stringify(k):(+k).toString(I);let F=parseInt(h),U=h&&h[0]+""=="0"?"0":" ";for(;k.length<F;)k=d!==void 0?k+U:U+k;return k}let a=/%(-)?(0?[0-9]+)?([.][0-9]+)?([#][0-9]+)?([scfpexd%])/g;return e.replace(a,s)}format(e,...n){this.buffer+=Rr.form(e,n)}toString(){return this.buffer}}class Mr{constructor(e){this.boundingBox=new nr(e),this.codewords=new Array(e.getMaxY()-e.getMinY()+1)}getCodewordNearby(e){let n=this.getCodeword(e);if(n!=null)return n;for(let i=1;i<Mr.MAX_NEARBY_DISTANCE;i++){let s=this.imageRowToCodewordIndex(e)-i;if(s>=0&&(n=this.codewords[s],n!=null)||(s=this.imageRowToCodewordIndex(e)+i,s<this.codewords.length&&(n=this.codewords[s],n!=null)))return n}return null}imageRowToCodewordIndex(e){return e-this.boundingBox.getMinY()}setCodeword(e,n){this.codewords[this.imageRowToCodewordIndex(e)]=n}getCodeword(e){return this.codewords[this.imageRowToCodewordIndex(e)]}getBoundingBox(){return this.boundingBox}getCodewords(){return this.codewords}toString(){const e=new Rr;let n=0;for(const i of this.codewords){if(i==null){e.format("%3d: | %n",n++);continue}e.format("%3d: %3d|%3d%n",n++,i.getRowNumber(),i.getValue())}return e.toString()}}Mr.MAX_NEARBY_DISTANCE=5;class Dr{constructor(){this.values=new Map}setValue(e){e=Math.trunc(e);let n=this.values.get(e);n==null&&(n=0),n++,this.values.set(e,n)}getValue(){let e=-1,n=new Array;for(const[i,s]of this.values.entries()){const a={getKey:()=>i,getValue:()=>s};a.getValue()>e?(e=a.getValue(),n=[],n.push(a.getKey())):a.getValue()===e&&n.push(a.getKey())}return Ne.toIntArray(n)}getConfidence(e){return this.values.get(e)}}class hs extends Mr{constructor(e,n){super(e),this._isLeft=n}setRowNumbers(){for(let e of this.getCodewords())e?.setRowNumberAsRowIndicatorColumn()}adjustCompleteIndicatorColumnRowNumbers(e){let n=this.getCodewords();this.setRowNumbers(),this.removeIncorrectCodewords(n,e);let i=this.getBoundingBox(),s=this._isLeft?i.getTopLeft():i.getTopRight(),a=this._isLeft?i.getBottomLeft():i.getBottomRight(),l=this.imageRowToCodewordIndex(Math.trunc(s.getY())),d=this.imageRowToCodewordIndex(Math.trunc(a.getY())),h=-1,m=1,y=0;for(let b=l;b<d;b++){if(n[b]==null)continue;let I=n[b],k=I.getRowNumber()-h;if(k===0)y++;else if(k===1)m=Math.max(m,y),y=1,h=I.getRowNumber();else if(k<0||I.getRowNumber()>=e.getRowCount()||k>b)n[b]=null;else{let F;m>2?F=(m-2)*k:F=k;let U=F>=b;for(let G=1;G<=F&&!U;G++)U=n[b-G]!=null;U?n[b]=null:(h=I.getRowNumber(),y=1)}}}getRowHeights(){let e=this.getBarcodeMetadata();if(e==null)return null;this.adjustIncompleteIndicatorColumnRowNumbers(e);let n=new Int32Array(e.getRowCount());for(let i of this.getCodewords())if(i!=null){let s=i.getRowNumber();if(s>=n.length)continue;n[s]++}return n}adjustIncompleteIndicatorColumnRowNumbers(e){let n=this.getBoundingBox(),i=this._isLeft?n.getTopLeft():n.getTopRight(),s=this._isLeft?n.getBottomLeft():n.getBottomRight(),a=this.imageRowToCodewordIndex(Math.trunc(i.getY())),l=this.imageRowToCodewordIndex(Math.trunc(s.getY())),d=this.getCodewords(),h=-1;for(let m=a;m<l;m++){if(d[m]==null)continue;let y=d[m];y.setRowNumberAsRowIndicatorColumn();let b=y.getRowNumber()-h;b===0||(b===1?h=y.getRowNumber():y.getRowNumber()>=e.getRowCount()?d[m]=null:h=y.getRowNumber())}}getBarcodeMetadata(){let e=this.getCodewords(),n=new Dr,i=new Dr,s=new Dr,a=new Dr;for(let d of e){if(d==null)continue;d.setRowNumberAsRowIndicatorColumn();let h=d.getValue()%30,m=d.getRowNumber();switch(this._isLeft||(m+=2),m%3){case 0:i.setValue(h*3+1);break;case 1:a.setValue(h/3),s.setValue(h%3);break;case 2:n.setValue(h+1);break}}if(n.getValue().length===0||i.getValue().length===0||s.getValue().length===0||a.getValue().length===0||n.getValue()[0]<1||i.getValue()[0]+s.getValue()[0]<Ne.MIN_ROWS_IN_BARCODE||i.getValue()[0]+s.getValue()[0]>Ne.MAX_ROWS_IN_BARCODE)return null;let l=new od(n.getValue()[0],i.getValue()[0],s.getValue()[0],a.getValue()[0]);return this.removeIncorrectCodewords(e,l),l}removeIncorrectCodewords(e,n){for(let i=0;i<e.length;i++){let s=e[i];if(e[i]==null)continue;let a=s.getValue()%30,l=s.getRowNumber();if(l>n.getRowCount()){e[i]=null;continue}switch(this._isLeft||(l+=2),l%3){case 0:a*3+1!==n.getRowCountUpperPart()&&(e[i]=null);break;case 1:(Math.trunc(a/3)!==n.getErrorCorrectionLevel()||a%3!==n.getRowCountLowerPart())&&(e[i]=null);break;case 2:a+1!==n.getColumnCount()&&(e[i]=null);break}}}isLeft(){return this._isLeft}toString(){return"IsLeft: "+this._isLeft+`
63
+ `+super.toString()}}class Pr{constructor(e,n){this.ADJUST_ROW_NUMBER_SKIP=2,this.barcodeMetadata=e,this.barcodeColumnCount=e.getColumnCount(),this.boundingBox=n,this.detectionResultColumns=new Array(this.barcodeColumnCount+2)}getDetectionResultColumns(){this.adjustIndicatorColumnRowNumbers(this.detectionResultColumns[0]),this.adjustIndicatorColumnRowNumbers(this.detectionResultColumns[this.barcodeColumnCount+1]);let e=Ne.MAX_CODEWORDS_IN_BARCODE,n;do n=e,e=this.adjustRowNumbersAndGetCount();while(e>0&&e<n);return this.detectionResultColumns}adjustIndicatorColumnRowNumbers(e){e?.adjustCompleteIndicatorColumnRowNumbers(this.barcodeMetadata)}adjustRowNumbersAndGetCount(){let e=this.adjustRowNumbersByRow();if(e===0)return 0;for(let n=1;n<this.barcodeColumnCount+1;n++){let i=this.detectionResultColumns[n].getCodewords();for(let s=0;s<i.length;s++)i[s]!=null&&(i[s].hasValidRowNumber()||this.adjustRowNumbers(n,s,i))}return e}adjustRowNumbersByRow(){return this.adjustRowNumbersFromBothRI(),this.adjustRowNumbersFromLRI()+this.adjustRowNumbersFromRRI()}adjustRowNumbersFromBothRI(){if(this.detectionResultColumns[0]==null||this.detectionResultColumns[this.barcodeColumnCount+1]==null)return;let e=this.detectionResultColumns[0].getCodewords(),n=this.detectionResultColumns[this.barcodeColumnCount+1].getCodewords();for(let i=0;i<e.length;i++)if(e[i]!=null&&n[i]!=null&&e[i].getRowNumber()===n[i].getRowNumber())for(let s=1;s<=this.barcodeColumnCount;s++){let a=this.detectionResultColumns[s].getCodewords()[i];a!=null&&(a.setRowNumber(e[i].getRowNumber()),a.hasValidRowNumber()||(this.detectionResultColumns[s].getCodewords()[i]=null))}}adjustRowNumbersFromRRI(){if(this.detectionResultColumns[this.barcodeColumnCount+1]==null)return 0;let e=0,n=this.detectionResultColumns[this.barcodeColumnCount+1].getCodewords();for(let i=0;i<n.length;i++){if(n[i]==null)continue;let s=n[i].getRowNumber(),a=0;for(let l=this.barcodeColumnCount+1;l>0&&a<this.ADJUST_ROW_NUMBER_SKIP;l--){let d=this.detectionResultColumns[l].getCodewords()[i];d!=null&&(a=Pr.adjustRowNumberIfValid(s,a,d),d.hasValidRowNumber()||e++)}}return e}adjustRowNumbersFromLRI(){if(this.detectionResultColumns[0]==null)return 0;let e=0,n=this.detectionResultColumns[0].getCodewords();for(let i=0;i<n.length;i++){if(n[i]==null)continue;let s=n[i].getRowNumber(),a=0;for(let l=1;l<this.barcodeColumnCount+1&&a<this.ADJUST_ROW_NUMBER_SKIP;l++){let d=this.detectionResultColumns[l].getCodewords()[i];d!=null&&(a=Pr.adjustRowNumberIfValid(s,a,d),d.hasValidRowNumber()||e++)}}return e}static adjustRowNumberIfValid(e,n,i){return i==null||i.hasValidRowNumber()||(i.isValidRowNumber(e)?(i.setRowNumber(e),n=0):++n),n}adjustRowNumbers(e,n,i){if(!this.detectionResultColumns[e-1])return;let s=i[n],a=this.detectionResultColumns[e-1].getCodewords(),l=a;this.detectionResultColumns[e+1]!=null&&(l=this.detectionResultColumns[e+1].getCodewords());let d=new Array(14);d[2]=a[n],d[3]=l[n],n>0&&(d[0]=i[n-1],d[4]=a[n-1],d[5]=l[n-1]),n>1&&(d[8]=i[n-2],d[10]=a[n-2],d[11]=l[n-2]),n<i.length-1&&(d[1]=i[n+1],d[6]=a[n+1],d[7]=l[n+1]),n<i.length-2&&(d[9]=i[n+2],d[12]=a[n+2],d[13]=l[n+2]);for(let h of d)if(Pr.adjustRowNumber(s,h))return}static adjustRowNumber(e,n){return n==null?!1:n.hasValidRowNumber()&&n.getBucket()===e.getBucket()?(e.setRowNumber(n.getRowNumber()),!0):!1}getBarcodeColumnCount(){return this.barcodeColumnCount}getBarcodeRowCount(){return this.barcodeMetadata.getRowCount()}getBarcodeECLevel(){return this.barcodeMetadata.getErrorCorrectionLevel()}setBoundingBox(e){this.boundingBox=e}getBoundingBox(){return this.boundingBox}setDetectionResultColumn(e,n){this.detectionResultColumns[e]=n}getDetectionResultColumn(e){return this.detectionResultColumns[e]}toString(){let e=this.detectionResultColumns[0];e==null&&(e=this.detectionResultColumns[this.barcodeColumnCount+1]);let n=new Rr;for(let i=0;i<e.getCodewords().length;i++){n.format("CW %3d:",i);for(let s=0;s<this.barcodeColumnCount+2;s++){if(this.detectionResultColumns[s]==null){n.format(" | ");continue}let a=this.detectionResultColumns[s].getCodewords()[i];if(a==null){n.format(" | ");continue}n.format(" %3d|%3d",a.getRowNumber(),a.getValue())}n.format("%n")}return n.toString()}}class Br{constructor(e,n,i,s){this.rowNumber=Br.BARCODE_ROW_UNKNOWN,this.startX=Math.trunc(e),this.endX=Math.trunc(n),this.bucket=Math.trunc(i),this.value=Math.trunc(s)}hasValidRowNumber(){return this.isValidRowNumber(this.rowNumber)}isValidRowNumber(e){return e!==Br.BARCODE_ROW_UNKNOWN&&this.bucket===e%3*3}setRowNumberAsRowIndicatorColumn(){this.rowNumber=Math.trunc(Math.trunc(this.value/30)*3+Math.trunc(this.bucket/3))}getWidth(){return this.endX-this.startX}getStartX(){return this.startX}getEndX(){return this.endX}getBucket(){return this.bucket}getValue(){return this.value}getRowNumber(){return this.rowNumber}setRowNumber(e){this.rowNumber=e}toString(){return this.rowNumber+"|"+this.value}}Br.BARCODE_ROW_UNKNOWN=-1;class Qt{static initialize(){for(let e=0;e<Ne.SYMBOL_TABLE.length;e++){let n=Ne.SYMBOL_TABLE[e],i=n&1;for(let s=0;s<Ne.BARS_IN_MODULE;s++){let a=0;for(;(n&1)===i;)a+=1,n>>=1;i=n&1,Qt.RATIOS_TABLE[e]||(Qt.RATIOS_TABLE[e]=new Array(Ne.BARS_IN_MODULE)),Qt.RATIOS_TABLE[e][Ne.BARS_IN_MODULE-s-1]=Math.fround(a/Ne.MODULES_IN_CODEWORD)}}this.bSymbolTableReady=!0}static getDecodedValue(e){let n=Qt.getDecodedCodewordValue(Qt.sampleBitCounts(e));return n!==-1?n:Qt.getClosestDecodedValue(e)}static sampleBitCounts(e){let n=Ze.sum(e),i=new Int32Array(Ne.BARS_IN_MODULE),s=0,a=0;for(let l=0;l<Ne.MODULES_IN_CODEWORD;l++){let d=n/(2*Ne.MODULES_IN_CODEWORD)+l*n/Ne.MODULES_IN_CODEWORD;a+e[s]<=d&&(a+=e[s],s++),i[s]++}return i}static getDecodedCodewordValue(e){let n=Qt.getBitValue(e);return Ne.getCodeword(n)===-1?-1:n}static getBitValue(e){let n=0;for(let i=0;i<e.length;i++)for(let s=0;s<e[i];s++)n=n<<1|(i%2===0?1:0);return Math.trunc(n)}static getClosestDecodedValue(e){let n=Ze.sum(e),i=new Array(Ne.BARS_IN_MODULE);if(n>1)for(let l=0;l<i.length;l++)i[l]=Math.fround(e[l]/n);let s=dn.MAX_VALUE,a=-1;this.bSymbolTableReady||Qt.initialize();for(let l=0;l<Qt.RATIOS_TABLE.length;l++){let d=0,h=Qt.RATIOS_TABLE[l];for(let m=0;m<Ne.BARS_IN_MODULE;m++){let y=Math.fround(h[m]-i[m]);if(d+=Math.fround(y*y),d>=s)break}d<s&&(s=d,a=Ne.SYMBOL_TABLE[l])}return a}}Qt.bSymbolTableReady=!1,Qt.RATIOS_TABLE=new Array(Ne.SYMBOL_TABLE.length).map(C=>new Array(Ne.BARS_IN_MODULE));class ps{constructor(){this.segmentCount=-1,this.fileSize=-1,this.timestamp=-1,this.checksum=-1}getSegmentIndex(){return this.segmentIndex}setSegmentIndex(e){this.segmentIndex=e}getFileId(){return this.fileId}setFileId(e){this.fileId=e}getOptionalData(){return this.optionalData}setOptionalData(e){this.optionalData=e}isLastSegment(){return this.lastSegment}setLastSegment(e){this.lastSegment=e}getSegmentCount(){return this.segmentCount}setSegmentCount(e){this.segmentCount=e}getSender(){return this.sender||null}setSender(e){this.sender=e}getAddressee(){return this.addressee||null}setAddressee(e){this.addressee=e}getFileName(){return this.fileName}setFileName(e){this.fileName=e}getFileSize(){return this.fileSize}setFileSize(e){this.fileSize=e}getChecksum(){return this.checksum}setChecksum(e){this.checksum=e}getTimestamp(){return this.timestamp}setTimestamp(e){this.timestamp=e}}class ms{static parseLong(e,n=void 0){return parseInt(e,n)}}class gs extends g{}gs.kind="NullPointerException";class sd{writeBytes(e){this.writeBytesOffset(e,0,e.length)}writeBytesOffset(e,n,i){if(e==null)throw new gs;if(n<0||n>e.length||i<0||n+i>e.length||n+i<0)throw new P;if(i===0)return;for(let s=0;s<i;s++)this.write(e[n+s])}flush(){}close(){}}class ad extends g{}class ld extends sd{constructor(e=32){if(super(),this.count=0,e<0)throw new E("Negative initial size: "+e);this.buf=new Uint8Array(e)}ensureCapacity(e){e-this.buf.length>0&&this.grow(e)}grow(e){let i=this.buf.length<<1;if(i-e<0&&(i=e),i<0){if(e<0)throw new ad;i=$.MAX_VALUE}this.buf=Z.copyOfUint8Array(this.buf,i)}write(e){this.ensureCapacity(this.count+1),this.buf[this.count]=e,this.count+=1}writeBytesOffset(e,n,i){if(n<0||n>e.length||i<0||n+i-e.length>0)throw new P;this.ensureCapacity(this.count+i),R.arraycopy(e,n,this.buf,this.count,i),this.count+=i}writeTo(e){e.writeBytesOffset(this.buf,0,this.count)}reset(){this.count=0}toByteArray(){return Z.copyOfUint8Array(this.buf,this.count)}size(){return this.count}toString(e){return e?typeof e=="string"?this.toString_string(e):this.toString_number(e):this.toString_void()}toString_void(){return new String(this.buf).toString()}toString_string(e){return new String(this.buf).toString()}toString_number(e){return new String(this.buf).toString()}close(){}}var it;(function(C){C[C.ALPHA=0]="ALPHA",C[C.LOWER=1]="LOWER",C[C.MIXED=2]="MIXED",C[C.PUNCT=3]="PUNCT",C[C.ALPHA_SHIFT=4]="ALPHA_SHIFT",C[C.PUNCT_SHIFT=5]="PUNCT_SHIFT"})(it||(it={}));function xs(){if(typeof window<"u")return window.BigInt||null;if(typeof Ci<"u")return Ci.BigInt||null;if(typeof self<"u")return self.BigInt||null;throw new Error("Can't search globals for BigInt!")}let hi;function jn(C){if(typeof hi>"u"&&(hi=xs()),hi===null)throw new Error("BigInt is not supported!");return hi(C)}function cd(){let C=[];C[0]=jn(1);let e=jn(900);C[1]=e;for(let n=2;n<16;n++)C[n]=C[n-1]*e;return C}class K{static decode(e,n){let i=new le(""),s=B.ISO8859_1;i.enableDecoding(s);let a=1,l=e[a++],d=new ps;for(;a<e[0];){switch(l){case K.TEXT_COMPACTION_MODE_LATCH:a=K.textCompaction(e,a,i);break;case K.BYTE_COMPACTION_MODE_LATCH:case K.BYTE_COMPACTION_MODE_LATCH_6:a=K.byteCompaction(l,e,s,a,i);break;case K.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:i.append(e[a++]);break;case K.NUMERIC_COMPACTION_MODE_LATCH:a=K.numericCompaction(e,a,i);break;case K.ECI_CHARSET:B.getCharacterSetECIByValue(e[a++]);break;case K.ECI_GENERAL_PURPOSE:a+=2;break;case K.ECI_USER_DEFINED:a++;break;case K.BEGIN_MACRO_PDF417_CONTROL_BLOCK:a=K.decodeMacroBlock(e,a,d);break;case K.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case K.MACRO_PDF417_TERMINATOR:throw new z;default:a--,a=K.textCompaction(e,a,i);break}if(a<e.length)l=e[a++];else throw z.getFormatInstance()}if(i.length()===0)throw z.getFormatInstance();let h=new ke(null,i.toString(),null,n);return h.setOther(d),h}static decodeMacroBlock(e,n,i){if(n+K.NUMBER_OF_SEQUENCE_CODEWORDS>e[0])throw z.getFormatInstance();let s=new Int32Array(K.NUMBER_OF_SEQUENCE_CODEWORDS);for(let d=0;d<K.NUMBER_OF_SEQUENCE_CODEWORDS;d++,n++)s[d]=e[n];i.setSegmentIndex($.parseInt(K.decodeBase900toBase10(s,K.NUMBER_OF_SEQUENCE_CODEWORDS)));let a=new le;n=K.textCompaction(e,n,a),i.setFileId(a.toString());let l=-1;for(e[n]===K.BEGIN_MACRO_PDF417_OPTIONAL_FIELD&&(l=n+1);n<e[0];)switch(e[n]){case K.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:switch(n++,e[n]){case K.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME:let d=new le;n=K.textCompaction(e,n+1,d),i.setFileName(d.toString());break;case K.MACRO_PDF417_OPTIONAL_FIELD_SENDER:let h=new le;n=K.textCompaction(e,n+1,h),i.setSender(h.toString());break;case K.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE:let m=new le;n=K.textCompaction(e,n+1,m),i.setAddressee(m.toString());break;case K.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT:let y=new le;n=K.numericCompaction(e,n+1,y),i.setSegmentCount($.parseInt(y.toString()));break;case K.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP:let b=new le;n=K.numericCompaction(e,n+1,b),i.setTimestamp(ms.parseLong(b.toString()));break;case K.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM:let I=new le;n=K.numericCompaction(e,n+1,I),i.setChecksum($.parseInt(I.toString()));break;case K.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE:let k=new le;n=K.numericCompaction(e,n+1,k),i.setFileSize(ms.parseLong(k.toString()));break;default:throw z.getFormatInstance()}break;case K.MACRO_PDF417_TERMINATOR:n++,i.setLastSegment(!0);break;default:throw z.getFormatInstance()}if(l!==-1){let d=n-l;i.isLastSegment()&&d--,i.setOptionalData(Z.copyOfRange(e,l,l+d))}return n}static textCompaction(e,n,i){let s=new Int32Array((e[0]-n)*2),a=new Int32Array((e[0]-n)*2),l=0,d=!1;for(;n<e[0]&&!d;){let h=e[n++];if(h<K.TEXT_COMPACTION_MODE_LATCH)s[l]=h/30,s[l+1]=h%30,l+=2;else switch(h){case K.TEXT_COMPACTION_MODE_LATCH:s[l++]=K.TEXT_COMPACTION_MODE_LATCH;break;case K.BYTE_COMPACTION_MODE_LATCH:case K.BYTE_COMPACTION_MODE_LATCH_6:case K.NUMERIC_COMPACTION_MODE_LATCH:case K.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case K.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case K.MACRO_PDF417_TERMINATOR:n--,d=!0;break;case K.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:s[l]=K.MODE_SHIFT_TO_BYTE_COMPACTION_MODE,h=e[n++],a[l]=h,l++;break}}return K.decodeTextCompaction(s,a,l,i),n}static decodeTextCompaction(e,n,i,s){let a=it.ALPHA,l=it.ALPHA,d=0;for(;d<i;){let h=e[d],m="";switch(a){case it.ALPHA:if(h<26)m=String.fromCharCode(65+h);else switch(h){case 26:m=" ";break;case K.LL:a=it.LOWER;break;case K.ML:a=it.MIXED;break;case K.PS:l=a,a=it.PUNCT_SHIFT;break;case K.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:s.append(n[d]);break;case K.TEXT_COMPACTION_MODE_LATCH:a=it.ALPHA;break}break;case it.LOWER:if(h<26)m=String.fromCharCode(97+h);else switch(h){case 26:m=" ";break;case K.AS:l=a,a=it.ALPHA_SHIFT;break;case K.ML:a=it.MIXED;break;case K.PS:l=a,a=it.PUNCT_SHIFT;break;case K.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:s.append(n[d]);break;case K.TEXT_COMPACTION_MODE_LATCH:a=it.ALPHA;break}break;case it.MIXED:if(h<K.PL)m=K.MIXED_CHARS[h];else switch(h){case K.PL:a=it.PUNCT;break;case 26:m=" ";break;case K.LL:a=it.LOWER;break;case K.AL:a=it.ALPHA;break;case K.PS:l=a,a=it.PUNCT_SHIFT;break;case K.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:s.append(n[d]);break;case K.TEXT_COMPACTION_MODE_LATCH:a=it.ALPHA;break}break;case it.PUNCT:if(h<K.PAL)m=K.PUNCT_CHARS[h];else switch(h){case K.PAL:a=it.ALPHA;break;case K.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:s.append(n[d]);break;case K.TEXT_COMPACTION_MODE_LATCH:a=it.ALPHA;break}break;case it.ALPHA_SHIFT:if(a=l,h<26)m=String.fromCharCode(65+h);else switch(h){case 26:m=" ";break;case K.TEXT_COMPACTION_MODE_LATCH:a=it.ALPHA;break}break;case it.PUNCT_SHIFT:if(a=l,h<K.PAL)m=K.PUNCT_CHARS[h];else switch(h){case K.PAL:a=it.ALPHA;break;case K.MODE_SHIFT_TO_BYTE_COMPACTION_MODE:s.append(n[d]);break;case K.TEXT_COMPACTION_MODE_LATCH:a=it.ALPHA;break}break}m!==""&&s.append(m),d++}}static byteCompaction(e,n,i,s,a){let l=new ld,d=0,h=0,m=!1;switch(e){case K.BYTE_COMPACTION_MODE_LATCH:let y=new Int32Array(6),b=n[s++];for(;s<n[0]&&!m;)switch(y[d++]=b,h=900*h+b,b=n[s++],b){case K.TEXT_COMPACTION_MODE_LATCH:case K.BYTE_COMPACTION_MODE_LATCH:case K.NUMERIC_COMPACTION_MODE_LATCH:case K.BYTE_COMPACTION_MODE_LATCH_6:case K.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case K.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case K.MACRO_PDF417_TERMINATOR:s--,m=!0;break;default:if(d%5===0&&d>0){for(let I=0;I<6;++I)l.write(Number(jn(h)>>jn(8*(5-I))));h=0,d=0}break}s===n[0]&&b<K.TEXT_COMPACTION_MODE_LATCH&&(y[d++]=b);for(let I=0;I<d;I++)l.write(y[I]);break;case K.BYTE_COMPACTION_MODE_LATCH_6:for(;s<n[0]&&!m;){let I=n[s++];if(I<K.TEXT_COMPACTION_MODE_LATCH)d++,h=900*h+I;else switch(I){case K.TEXT_COMPACTION_MODE_LATCH:case K.BYTE_COMPACTION_MODE_LATCH:case K.NUMERIC_COMPACTION_MODE_LATCH:case K.BYTE_COMPACTION_MODE_LATCH_6:case K.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case K.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case K.MACRO_PDF417_TERMINATOR:s--,m=!0;break}if(d%5===0&&d>0){for(let k=0;k<6;++k)l.write(Number(jn(h)>>jn(8*(5-k))));h=0,d=0}}break}return a.append(re.decode(l.toByteArray(),i)),s}static numericCompaction(e,n,i){let s=0,a=!1,l=new Int32Array(K.MAX_NUMERIC_CODEWORDS);for(;n<e[0]&&!a;){let d=e[n++];if(n===e[0]&&(a=!0),d<K.TEXT_COMPACTION_MODE_LATCH)l[s]=d,s++;else switch(d){case K.TEXT_COMPACTION_MODE_LATCH:case K.BYTE_COMPACTION_MODE_LATCH:case K.BYTE_COMPACTION_MODE_LATCH_6:case K.BEGIN_MACRO_PDF417_CONTROL_BLOCK:case K.BEGIN_MACRO_PDF417_OPTIONAL_FIELD:case K.MACRO_PDF417_TERMINATOR:n--,a=!0;break}(s%K.MAX_NUMERIC_CODEWORDS===0||d===K.NUMERIC_COMPACTION_MODE_LATCH||a)&&s>0&&(i.append(K.decodeBase900toBase10(l,s)),s=0)}return n}static decodeBase900toBase10(e,n){let i=jn(0);for(let a=0;a<n;a++)i+=K.EXP900[n-a-1]*jn(e[a]);let s=i.toString();if(s.charAt(0)!=="1")throw new z;return s.substring(1)}}K.TEXT_COMPACTION_MODE_LATCH=900,K.BYTE_COMPACTION_MODE_LATCH=901,K.NUMERIC_COMPACTION_MODE_LATCH=902,K.BYTE_COMPACTION_MODE_LATCH_6=924,K.ECI_USER_DEFINED=925,K.ECI_GENERAL_PURPOSE=926,K.ECI_CHARSET=927,K.BEGIN_MACRO_PDF417_CONTROL_BLOCK=928,K.BEGIN_MACRO_PDF417_OPTIONAL_FIELD=923,K.MACRO_PDF417_TERMINATOR=922,K.MODE_SHIFT_TO_BYTE_COMPACTION_MODE=913,K.MAX_NUMERIC_CODEWORDS=15,K.MACRO_PDF417_OPTIONAL_FIELD_FILE_NAME=0,K.MACRO_PDF417_OPTIONAL_FIELD_SEGMENT_COUNT=1,K.MACRO_PDF417_OPTIONAL_FIELD_TIME_STAMP=2,K.MACRO_PDF417_OPTIONAL_FIELD_SENDER=3,K.MACRO_PDF417_OPTIONAL_FIELD_ADDRESSEE=4,K.MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE=5,K.MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM=6,K.PL=25,K.LL=27,K.AS=27,K.ML=28,K.AL=28,K.PS=29,K.PAL=29,K.PUNCT_CHARS=`;<>@[\\]_\`~!\r ,:
64
+ -.$/"|*()?{}'`,K.MIXED_CHARS="0123456789&\r ,:#-.$/+%*=^",K.EXP900=xs()?cd():[],K.NUMBER_OF_SEQUENCE_CODEWORDS=2;class Ve{constructor(){}static decode(e,n,i,s,a,l,d){let h=new nr(e,n,i,s,a),m=null,y=null,b;for(let F=!0;;F=!1){if(n!=null&&(m=Ve.getRowIndicatorColumn(e,h,n,!0,l,d)),s!=null&&(y=Ve.getRowIndicatorColumn(e,h,s,!1,l,d)),b=Ve.merge(m,y),b==null)throw O.getNotFoundInstance();let U=b.getBoundingBox();if(F&&U!=null&&(U.getMinY()<h.getMinY()||U.getMaxY()>h.getMaxY()))h=U;else break}b.setBoundingBox(h);let I=b.getBarcodeColumnCount()+1;b.setDetectionResultColumn(0,m),b.setDetectionResultColumn(I,y);let k=m!=null;for(let F=1;F<=I;F++){let U=k?F:I-F;if(b.getDetectionResultColumn(U)!==void 0)continue;let G;U===0||U===I?G=new hs(h,U===0):G=new Mr(h),b.setDetectionResultColumn(U,G);let Q=-1,fe=Q;for(let pe=h.getMinY();pe<=h.getMaxY();pe++){if(Q=Ve.getStartColumn(b,U,pe,k),Q<0||Q>h.getMaxX()){if(fe===-1)continue;Q=fe}let de=Ve.detectCodeword(e,h.getMinX(),h.getMaxX(),k,Q,pe,l,d);de!=null&&(G.setCodeword(pe,de),fe=Q,l=Math.min(l,de.getWidth()),d=Math.max(d,de.getWidth()))}}return Ve.createDecoderResult(b)}static merge(e,n){if(e==null&&n==null)return null;let i=Ve.getBarcodeMetadata(e,n);if(i==null)return null;let s=nr.merge(Ve.adjustBoundingBox(e),Ve.adjustBoundingBox(n));return new Pr(i,s)}static adjustBoundingBox(e){if(e==null)return null;let n=e.getRowHeights();if(n==null)return null;let i=Ve.getMax(n),s=0;for(let d of n)if(s+=i-d,d>0)break;let a=e.getCodewords();for(let d=0;s>0&&a[d]==null;d++)s--;let l=0;for(let d=n.length-1;d>=0&&(l+=i-n[d],!(n[d]>0));d--);for(let d=a.length-1;l>0&&a[d]==null;d--)l--;return e.getBoundingBox().addMissingRows(s,l,e.isLeft())}static getMax(e){let n=-1;for(let i of e)n=Math.max(n,i);return n}static getBarcodeMetadata(e,n){let i;if(e==null||(i=e.getBarcodeMetadata())==null)return n==null?null:n.getBarcodeMetadata();let s;return n==null||(s=n.getBarcodeMetadata())==null?i:i.getColumnCount()!==s.getColumnCount()&&i.getErrorCorrectionLevel()!==s.getErrorCorrectionLevel()&&i.getRowCount()!==s.getRowCount()?null:i}static getRowIndicatorColumn(e,n,i,s,a,l){let d=new hs(n,s);for(let h=0;h<2;h++){let m=h===0?1:-1,y=Math.trunc(Math.trunc(i.getX()));for(let b=Math.trunc(Math.trunc(i.getY()));b<=n.getMaxY()&&b>=n.getMinY();b+=m){let I=Ve.detectCodeword(e,0,e.getWidth(),s,y,b,a,l);I!=null&&(d.setCodeword(b,I),s?y=I.getStartX():y=I.getEndX())}}return d}static adjustCodewordCount(e,n){let i=n[0][1],s=i.getValue(),a=e.getBarcodeColumnCount()*e.getBarcodeRowCount()-Ve.getNumberOfECCodeWords(e.getBarcodeECLevel());if(s.length===0){if(a<1||a>Ne.MAX_CODEWORDS_IN_BARCODE)throw O.getNotFoundInstance();i.setValue(a)}else s[0]!==a&&i.setValue(a)}static createDecoderResult(e){let n=Ve.createBarcodeMatrix(e);Ve.adjustCodewordCount(e,n);let i=new Array,s=new Int32Array(e.getBarcodeRowCount()*e.getBarcodeColumnCount()),a=[],l=new Array;for(let h=0;h<e.getBarcodeRowCount();h++)for(let m=0;m<e.getBarcodeColumnCount();m++){let y=n[h][m+1].getValue(),b=h*e.getBarcodeColumnCount()+m;y.length===0?i.push(b):y.length===1?s[b]=y[0]:(l.push(b),a.push(y))}let d=new Array(a.length);for(let h=0;h<d.length;h++)d[h]=a[h];return Ve.createDecoderResultFromAmbiguousValues(e.getBarcodeECLevel(),s,Ne.toIntArray(i),Ne.toIntArray(l),d)}static createDecoderResultFromAmbiguousValues(e,n,i,s,a){let l=new Int32Array(s.length),d=100;for(;d-- >0;){for(let h=0;h<l.length;h++)n[s[h]]=a[h][l[h]];try{return Ve.decodeCodewords(n,e,i)}catch(h){if(!(h instanceof M))throw h}if(l.length===0)throw M.getChecksumInstance();for(let h=0;h<l.length;h++)if(l[h]<a[h].length-1){l[h]++;break}else if(l[h]=0,h===l.length-1)throw M.getChecksumInstance()}throw M.getChecksumInstance()}static createBarcodeMatrix(e){let n=Array.from({length:e.getBarcodeRowCount()},()=>new Array(e.getBarcodeColumnCount()+2));for(let s=0;s<n.length;s++)for(let a=0;a<n[s].length;a++)n[s][a]=new Dr;let i=0;for(let s of e.getDetectionResultColumns()){if(s!=null){for(let a of s.getCodewords())if(a!=null){let l=a.getRowNumber();if(l>=0){if(l>=n.length)continue;n[l][i].setValue(a.getValue())}}}i++}return n}static isValidBarcodeColumn(e,n){return n>=0&&n<=e.getBarcodeColumnCount()+1}static getStartColumn(e,n,i,s){let a=s?1:-1,l=null;if(Ve.isValidBarcodeColumn(e,n-a)&&(l=e.getDetectionResultColumn(n-a).getCodeword(i)),l!=null)return s?l.getEndX():l.getStartX();if(l=e.getDetectionResultColumn(n).getCodewordNearby(i),l!=null)return s?l.getStartX():l.getEndX();if(Ve.isValidBarcodeColumn(e,n-a)&&(l=e.getDetectionResultColumn(n-a).getCodewordNearby(i)),l!=null)return s?l.getEndX():l.getStartX();let d=0;for(;Ve.isValidBarcodeColumn(e,n-a);){n-=a;for(let h of e.getDetectionResultColumn(n).getCodewords())if(h!=null)return(s?h.getEndX():h.getStartX())+a*d*(h.getEndX()-h.getStartX());d++}return s?e.getBoundingBox().getMinX():e.getBoundingBox().getMaxX()}static detectCodeword(e,n,i,s,a,l,d,h){a=Ve.adjustCodewordStartColumn(e,n,i,s,a,l);let m=Ve.getModuleBitCount(e,n,i,s,a,l);if(m==null)return null;let y,b=Ze.sum(m);if(s)y=a+b;else{for(let F=0;F<m.length/2;F++){let U=m[F];m[F]=m[m.length-1-F],m[m.length-1-F]=U}y=a,a=y-b}if(!Ve.checkCodewordSkew(b,d,h))return null;let I=Qt.getDecodedValue(m),k=Ne.getCodeword(I);return k===-1?null:new Br(a,y,Ve.getCodewordBucketNumber(I),k)}static getModuleBitCount(e,n,i,s,a,l){let d=a,h=new Int32Array(8),m=0,y=s?1:-1,b=s;for(;(s?d<i:d>=n)&&m<h.length;)e.get(d,l)===b?(h[m]++,d+=y):(m++,b=!b);return m===h.length||d===(s?i:n)&&m===h.length-1?h:null}static getNumberOfECCodeWords(e){return 2<<e}static adjustCodewordStartColumn(e,n,i,s,a,l){let d=a,h=s?-1:1;for(let m=0;m<2;m++){for(;(s?d>=n:d<i)&&s===e.get(d,l);){if(Math.abs(a-d)>Ve.CODEWORD_SKEW_SIZE)return a;d+=h}h=-h,s=!s}return d}static checkCodewordSkew(e,n,i){return n-Ve.CODEWORD_SKEW_SIZE<=e&&e<=i+Ve.CODEWORD_SKEW_SIZE}static decodeCodewords(e,n,i){if(e.length===0)throw z.getFormatInstance();let s=1<<n+1,a=Ve.correctErrors(e,i,s);Ve.verifyCodewordCount(e,s);let l=K.decode(e,""+n);return l.setErrorsCorrected(a),l.setErasures(i.length),l}static correctErrors(e,n,i){if(n!=null&&n.length>i/2+Ve.MAX_ERRORS||i<0||i>Ve.MAX_EC_CODEWORDS)throw M.getChecksumInstance();return Ve.errorCorrection.decode(e,i,n)}static verifyCodewordCount(e,n){if(e.length<4)throw z.getFormatInstance();let i=e[0];if(i>e.length)throw z.getFormatInstance();if(i===0)if(n<e.length)e[0]=e.length-n;else throw z.getFormatInstance()}static getBitCountForCodeword(e){let n=new Int32Array(8),i=0,s=n.length-1;for(;!((e&1)!==i&&(i=e&1,s--,s<0));)n[s]++,e>>=1;return n}static getCodewordBucketNumber(e){return e instanceof Int32Array?this.getCodewordBucketNumber_Int32Array(e):this.getCodewordBucketNumber_number(e)}static getCodewordBucketNumber_number(e){return Ve.getCodewordBucketNumber(Ve.getBitCountForCodeword(e))}static getCodewordBucketNumber_Int32Array(e){return(e[0]-e[2]+e[4]-e[6]+9)%9}static toString(e){let n=new Rr;for(let i=0;i<e.length;i++){n.format("Row %2d: ",i);for(let s=0;s<e[i].length;s++){let a=e[i][s];a.getValue().length===0?n.format(" ",null):n.format("%4d(%2d)",a.getValue()[0],a.getConfidence(a.getValue()[0]))}n.format("%n")}return n.toString()}}Ve.CODEWORD_SKEW_SIZE=2,Ve.MAX_ERRORS=3,Ve.MAX_EC_CODEWORDS=512,Ve.errorCorrection=new fs;class Vt{decode(e,n=null){let i=Vt.decode(e,n,!1);if(i==null||i.length===0||i[0]==null)throw O.getNotFoundInstance();return i[0]}decodeMultiple(e,n=null){try{return Vt.decode(e,n,!0)}catch(i){throw i instanceof z||i instanceof M?O.getNotFoundInstance():i}}static decode(e,n,i){const s=new Array,a=Ue.detectMultiple(e,n,i);for(const l of a.getPoints()){const d=Ve.decode(a.getBits(),l[4],l[5],l[6],l[7],Vt.getMinCodewordWidth(l),Vt.getMaxCodewordWidth(l)),h=new Be(d.getText(),d.getRawBytes(),void 0,l,ie.PDF_417);h.putMetadata(Me.ERROR_CORRECTION_LEVEL,d.getECLevel());const m=d.getOther();m!=null&&h.putMetadata(Me.PDF417_EXTRA_METADATA,m),s.push(h)}return s.map(l=>l)}static getMaxWidth(e,n){return e==null||n==null?0:Math.trunc(Math.abs(e.getX()-n.getX()))}static getMinWidth(e,n){return e==null||n==null?$.MAX_VALUE:Math.trunc(Math.abs(e.getX()-n.getX()))}static getMaxCodewordWidth(e){return Math.floor(Math.max(Math.max(Vt.getMaxWidth(e[0],e[4]),Vt.getMaxWidth(e[6],e[2])*Ne.MODULES_IN_CODEWORD/Ne.MODULES_IN_STOP_PATTERN),Math.max(Vt.getMaxWidth(e[1],e[5]),Vt.getMaxWidth(e[7],e[3])*Ne.MODULES_IN_CODEWORD/Ne.MODULES_IN_STOP_PATTERN)))}static getMinCodewordWidth(e){return Math.floor(Math.min(Math.min(Vt.getMinWidth(e[0],e[4]),Vt.getMinWidth(e[6],e[2])*Ne.MODULES_IN_CODEWORD/Ne.MODULES_IN_STOP_PATTERN),Math.min(Vt.getMinWidth(e[1],e[5]),Vt.getMinWidth(e[7],e[3])*Ne.MODULES_IN_CODEWORD/Ne.MODULES_IN_STOP_PATTERN)))}reset(){}}class pi extends g{}pi.kind="ReaderException";class ys{constructor(e,n){this.verbose=e===!0,n&&this.setHints(n)}decode(e,n){return n&&this.setHints(n),this.decodeInternal(e)}decodeWithState(e){return(this.readers===null||this.readers===void 0)&&this.setHints(null),this.decodeInternal(e)}setHints(e){this.hints=e;const n=!c(e)&&e.get(j.TRY_HARDER)===!0,i=c(e)?null:e.get(j.POSSIBLE_FORMATS),s=new Array;if(!c(i)){const a=i.some(l=>l===ie.UPC_A||l===ie.UPC_E||l===ie.EAN_13||l===ie.EAN_8||l===ie.CODABAR||l===ie.CODE_39||l===ie.CODE_93||l===ie.CODE_128||l===ie.ITF||l===ie.RSS_14||l===ie.RSS_EXPANDED);a&&!n&&s.push(new yr(e,this.verbose)),i.includes(ie.QR_CODE)&&s.push(new Zn),i.includes(ie.DATA_MATRIX)&&s.push(new $n),i.includes(ie.AZTEC)&&s.push(new rt),i.includes(ie.PDF_417)&&s.push(new Vt),a&&n&&s.push(new yr(e,this.verbose))}s.length===0&&(n||s.push(new yr(e,this.verbose)),s.push(new Zn),s.push(new $n),s.push(new rt),s.push(new Vt),n&&s.push(new yr(e,this.verbose))),this.readers=s}reset(){if(this.readers!==null)for(const e of this.readers)e.reset()}decodeInternal(e){if(this.readers===null)throw new pi("No readers where selected, nothing can be read.");for(const n of this.readers)try{return n.decode(e,this.hints)}catch(i){if(i instanceof pi)continue}throw new O("No MultiFormat Readers were able to detect the code.")}}class ud extends je{constructor(e=null,n=500){const i=new ys;i.setHints(e),super(i,n)}decodeBitmap(e){return this.reader.decodeWithState(e)}}class dd extends je{constructor(e=500){super(new Vt,e)}}class fd extends je{constructor(e=500){super(new Zn,e)}}var ro;(function(C){C[C.ERROR_CORRECTION=0]="ERROR_CORRECTION",C[C.CHARACTER_SET=1]="CHARACTER_SET",C[C.DATA_MATRIX_SHAPE=2]="DATA_MATRIX_SHAPE",C[C.MIN_SIZE=3]="MIN_SIZE",C[C.MAX_SIZE=4]="MAX_SIZE",C[C.MARGIN=5]="MARGIN",C[C.PDF417_COMPACT=6]="PDF417_COMPACT",C[C.PDF417_COMPACTION=7]="PDF417_COMPACTION",C[C.PDF417_DIMENSIONS=8]="PDF417_DIMENSIONS",C[C.AZTEC_LAYERS=9]="AZTEC_LAYERS",C[C.QR_VERSION=10]="QR_VERSION"})(ro||(ro={}));var Mt=ro;class io{constructor(e){this.field=e,this.cachedGenerators=[],this.cachedGenerators.push(new tt(e,Int32Array.from([1])))}buildGenerator(e){const n=this.cachedGenerators;if(e>=n.length){let i=n[n.length-1];const s=this.field;for(let a=n.length;a<=e;a++){const l=i.multiply(new tt(s,Int32Array.from([1,s.exp(a-1+s.getGeneratorBase())])));n.push(l),i=l}}return n[e]}encode(e,n){if(n===0)throw new E("No error correction bytes");const i=e.length-n;if(i<=0)throw new E("No data bytes provided");const s=this.buildGenerator(n),a=new Int32Array(i);R.arraycopy(e,0,a,0,i);let l=new tt(this.field,a);l=l.multiplyByMonomial(n,1);const h=l.divide(s)[1].getCoefficients(),m=n-h.length;for(let y=0;y<m;y++)e[i+y]=0;R.arraycopy(h,0,e,i+m,h.length)}}class St{constructor(){}static applyMaskPenaltyRule1(e){return St.applyMaskPenaltyRule1Internal(e,!0)+St.applyMaskPenaltyRule1Internal(e,!1)}static applyMaskPenaltyRule2(e){let n=0;const i=e.getArray(),s=e.getWidth(),a=e.getHeight();for(let l=0;l<a-1;l++){const d=i[l];for(let h=0;h<s-1;h++){const m=d[h];m===d[h+1]&&m===i[l+1][h]&&m===i[l+1][h+1]&&n++}}return St.N2*n}static applyMaskPenaltyRule3(e){let n=0;const i=e.getArray(),s=e.getWidth(),a=e.getHeight();for(let l=0;l<a;l++)for(let d=0;d<s;d++){const h=i[l];d+6<s&&h[d]===1&&h[d+1]===0&&h[d+2]===1&&h[d+3]===1&&h[d+4]===1&&h[d+5]===0&&h[d+6]===1&&(St.isWhiteHorizontal(h,d-4,d)||St.isWhiteHorizontal(h,d+7,d+11))&&n++,l+6<a&&i[l][d]===1&&i[l+1][d]===0&&i[l+2][d]===1&&i[l+3][d]===1&&i[l+4][d]===1&&i[l+5][d]===0&&i[l+6][d]===1&&(St.isWhiteVertical(i,d,l-4,l)||St.isWhiteVertical(i,d,l+7,l+11))&&n++}return n*St.N3}static isWhiteHorizontal(e,n,i){n=Math.max(n,0),i=Math.min(i,e.length);for(let s=n;s<i;s++)if(e[s]===1)return!1;return!0}static isWhiteVertical(e,n,i,s){i=Math.max(i,0),s=Math.min(s,e.length);for(let a=i;a<s;a++)if(e[a][n]===1)return!1;return!0}static applyMaskPenaltyRule4(e){let n=0;const i=e.getArray(),s=e.getWidth(),a=e.getHeight();for(let h=0;h<a;h++){const m=i[h];for(let y=0;y<s;y++)m[y]===1&&n++}const l=e.getHeight()*e.getWidth();return Math.floor(Math.abs(n*2-l)*10/l)*St.N4}static getDataMaskBit(e,n,i){let s,a;switch(e){case 0:s=i+n&1;break;case 1:s=i&1;break;case 2:s=n%3;break;case 3:s=(i+n)%3;break;case 4:s=Math.floor(i/2)+Math.floor(n/3)&1;break;case 5:a=i*n,s=(a&1)+a%3;break;case 6:a=i*n,s=(a&1)+a%3&1;break;case 7:a=i*n,s=a%3+(i+n&1)&1;break;default:throw new E("Invalid mask pattern: "+e)}return s===0}static applyMaskPenaltyRule1Internal(e,n){let i=0;const s=n?e.getHeight():e.getWidth(),a=n?e.getWidth():e.getHeight(),l=e.getArray();for(let d=0;d<s;d++){let h=0,m=-1;for(let y=0;y<a;y++){const b=n?l[d][y]:l[y][d];b===m?h++:(h>=5&&(i+=St.N1+(h-5)),h=1,m=b)}h>=5&&(i+=St.N1+(h-5))}return i}}St.N1=3,St.N2=3,St.N3=40,St.N4=10;class mi{constructor(e,n){this.width=e,this.height=n;const i=new Array(n);for(let s=0;s!==n;s++)i[s]=new Uint8Array(e);this.bytes=i}getHeight(){return this.height}getWidth(){return this.width}get(e,n){return this.bytes[n][e]}getArray(){return this.bytes}setNumber(e,n,i){this.bytes[n][e]=i}setBoolean(e,n,i){this.bytes[n][e]=i?1:0}clear(e){for(const n of this.bytes)Z.fill(n,e)}equals(e){if(!(e instanceof mi))return!1;const n=e;if(this.width!==n.width||this.height!==n.height)return!1;for(let i=0,s=this.height;i<s;++i){const a=this.bytes[i],l=n.bytes[i];for(let d=0,h=this.width;d<h;++d)if(a[d]!==l[d])return!1}return!0}toString(){const e=new le;for(let n=0,i=this.height;n<i;++n){const s=this.bytes[n];for(let a=0,l=this.width;a<l;++a)switch(s[a]){case 0:e.append(" 0");break;case 1:e.append(" 1");break;default:e.append(" ");break}e.append(`
65
+ `)}return e.toString()}}class rr{constructor(){this.maskPattern=-1}getMode(){return this.mode}getECLevel(){return this.ecLevel}getVersion(){return this.version}getMaskPattern(){return this.maskPattern}getMatrix(){return this.matrix}toString(){const e=new le;return e.append(`<<
66
66
  `),e.append(" mode: "),e.append(this.mode?this.mode.toString():"null"),e.append(`
67
67
  ecLevel: `),e.append(this.ecLevel?this.ecLevel.toString():"null"),e.append(`
68
68
  version: `),e.append(this.version?this.version.toString():"null"),e.append(`
@@ -71,9 +71,9 @@ ${f.value}`:x,c.llmConfig){const m=c.llmConfig.extraTools??{};c.llmConfig.extraT
71
71
  `),e.append(this.matrix.toString())):e.append(`
72
72
  matrix: null
73
73
  `),e.append(`>>
74
- `),e.toString()}setMode(e){this.mode=e}setECLevel(e){this.ecLevel=e}setVersion(e){this.version=e}setMaskPattern(e){this.maskPattern=e}setMatrix(e){this.matrix=e}static isValidMaskPattern(e){return e>=0&&e<er.NUM_MASK_PATTERNS}}er.NUM_MASK_PATTERNS=8;class it extends m{}it.kind="WriterException";class Oe{constructor(){}static clearMatrix(e){e.clear(255)}static buildMatrix(e,n,i,s,a){Oe.clearMatrix(a),Oe.embedBasicPatterns(i,a),Oe.embedTypeInfo(n,s,a),Oe.maybeEmbedVersionInfo(i,a),Oe.embedDataBits(e,s,a)}static embedBasicPatterns(e,n){Oe.embedPositionDetectionPatternsAndSeparators(n),Oe.embedDarkDotAtLeftBottomCorner(n),Oe.maybeEmbedPositionAdjustmentPatterns(e,n),Oe.embedTimingPatterns(n)}static embedTypeInfo(e,n,i){const s=new $;Oe.makeTypeInfoBits(e,n,s);for(let a=0,l=s.getSize();a<l;++a){const d=s.get(s.getSize()-1-a),h=Oe.TYPE_INFO_COORDINATES[a],g=h[0],w=h[1];if(i.setBoolean(g,w,d),a<8){const b=i.getWidth()-a-1;i.setBoolean(b,8,d)}else{const I=i.getHeight()-7+(a-8);i.setBoolean(8,I,d)}}}static maybeEmbedVersionInfo(e,n){if(e.getVersionNumber()<7)return;const i=new $;Oe.makeVersionInfoBits(e,i);let s=17;for(let a=0;a<6;++a)for(let l=0;l<3;++l){const d=i.get(s);s--,n.setBoolean(a,n.getHeight()-11+l,d),n.setBoolean(n.getHeight()-11+l,a,d)}}static embedDataBits(e,n,i){let s=0,a=-1,l=i.getWidth()-1,d=i.getHeight()-1;for(;l>0;){for(l===6&&(l-=1);d>=0&&d<i.getHeight();){for(let h=0;h<2;++h){const g=l-h;if(!Oe.isEmpty(i.get(g,d)))continue;let w;s<e.getSize()?(w=e.get(s),++s):w=!1,n!==255&&Ct.getDataMaskBit(n,g,d)&&(w=!w),i.setBoolean(g,d,w)}d+=a}a=-a,d+=a,l-=2}if(s!==e.getSize())throw new it("Not all bits consumed: "+s+"/"+e.getSize())}static findMSBSet(e){return 32-z.numberOfLeadingZeros(e)}static calculateBCHCode(e,n){if(n===0)throw new E("0 polynomial");const i=Oe.findMSBSet(n);for(e<<=i-1;Oe.findMSBSet(e)>=i;)e^=n<<Oe.findMSBSet(e)-i;return e}static makeTypeInfoBits(e,n,i){if(!er.isValidMaskPattern(n))throw new it("Invalid mask pattern");const s=e.getBits()<<3|n;i.appendBits(s,5);const a=Oe.calculateBCHCode(s,Oe.TYPE_INFO_POLY);i.appendBits(a,10);const l=new $;if(l.appendBits(Oe.TYPE_INFO_MASK_PATTERN,15),i.xor(l),i.getSize()!==15)throw new it("should not happen but we got: "+i.getSize())}static makeVersionInfoBits(e,n){n.appendBits(e.getVersionNumber(),6);const i=Oe.calculateBCHCode(e.getVersionNumber(),Oe.VERSION_INFO_POLY);if(n.appendBits(i,12),n.getSize()!==18)throw new it("should not happen but we got: "+n.getSize())}static isEmpty(e){return e===255}static embedTimingPatterns(e){for(let n=8;n<e.getWidth()-8;++n){const i=(n+1)%2;Oe.isEmpty(e.get(n,6))&&e.setNumber(n,6,i),Oe.isEmpty(e.get(6,n))&&e.setNumber(6,n,i)}}static embedDarkDotAtLeftBottomCorner(e){if(e.get(8,e.getHeight()-8)===0)throw new it;e.setNumber(8,e.getHeight()-8,1)}static embedHorizontalSeparationPattern(e,n,i){for(let s=0;s<8;++s){if(!Oe.isEmpty(i.get(e+s,n)))throw new it;i.setNumber(e+s,n,0)}}static embedVerticalSeparationPattern(e,n,i){for(let s=0;s<7;++s){if(!Oe.isEmpty(i.get(e,n+s)))throw new it;i.setNumber(e,n+s,0)}}static embedPositionAdjustmentPattern(e,n,i){for(let s=0;s<5;++s){const a=Oe.POSITION_ADJUSTMENT_PATTERN[s];for(let l=0;l<5;++l)i.setNumber(e+l,n+s,a[l])}}static embedPositionDetectionPattern(e,n,i){for(let s=0;s<7;++s){const a=Oe.POSITION_DETECTION_PATTERN[s];for(let l=0;l<7;++l)i.setNumber(e+l,n+s,a[l])}}static embedPositionDetectionPatternsAndSeparators(e){const n=Oe.POSITION_DETECTION_PATTERN[0].length;Oe.embedPositionDetectionPattern(0,0,e),Oe.embedPositionDetectionPattern(e.getWidth()-n,0,e),Oe.embedPositionDetectionPattern(0,e.getWidth()-n,e);const i=8;Oe.embedHorizontalSeparationPattern(0,i-1,e),Oe.embedHorizontalSeparationPattern(e.getWidth()-i,i-1,e),Oe.embedHorizontalSeparationPattern(0,e.getWidth()-i,e);const s=7;Oe.embedVerticalSeparationPattern(s,0,e),Oe.embedVerticalSeparationPattern(e.getHeight()-s-1,0,e),Oe.embedVerticalSeparationPattern(s,e.getHeight()-s,e)}static maybeEmbedPositionAdjustmentPatterns(e,n){if(e.getVersionNumber()<2)return;const i=e.getVersionNumber()-1,s=Oe.POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[i];for(let a=0,l=s.length;a!==l;a++){const d=s[a];if(d>=0)for(let h=0;h!==l;h++){const g=s[h];g>=0&&Oe.isEmpty(n.get(g,d))&&Oe.embedPositionAdjustmentPattern(g-2,d-2,n)}}}}Oe.POSITION_DETECTION_PATTERN=Array.from([Int32Array.from([1,1,1,1,1,1,1]),Int32Array.from([1,0,0,0,0,0,1]),Int32Array.from([1,0,1,1,1,0,1]),Int32Array.from([1,0,1,1,1,0,1]),Int32Array.from([1,0,1,1,1,0,1]),Int32Array.from([1,0,0,0,0,0,1]),Int32Array.from([1,1,1,1,1,1,1])]),Oe.POSITION_ADJUSTMENT_PATTERN=Array.from([Int32Array.from([1,1,1,1,1]),Int32Array.from([1,0,0,0,1]),Int32Array.from([1,0,1,0,1]),Int32Array.from([1,0,0,0,1]),Int32Array.from([1,1,1,1,1])]),Oe.POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE=Array.from([Int32Array.from([-1,-1,-1,-1,-1,-1,-1]),Int32Array.from([6,18,-1,-1,-1,-1,-1]),Int32Array.from([6,22,-1,-1,-1,-1,-1]),Int32Array.from([6,26,-1,-1,-1,-1,-1]),Int32Array.from([6,30,-1,-1,-1,-1,-1]),Int32Array.from([6,34,-1,-1,-1,-1,-1]),Int32Array.from([6,22,38,-1,-1,-1,-1]),Int32Array.from([6,24,42,-1,-1,-1,-1]),Int32Array.from([6,26,46,-1,-1,-1,-1]),Int32Array.from([6,28,50,-1,-1,-1,-1]),Int32Array.from([6,30,54,-1,-1,-1,-1]),Int32Array.from([6,32,58,-1,-1,-1,-1]),Int32Array.from([6,34,62,-1,-1,-1,-1]),Int32Array.from([6,26,46,66,-1,-1,-1]),Int32Array.from([6,26,48,70,-1,-1,-1]),Int32Array.from([6,26,50,74,-1,-1,-1]),Int32Array.from([6,30,54,78,-1,-1,-1]),Int32Array.from([6,30,56,82,-1,-1,-1]),Int32Array.from([6,30,58,86,-1,-1,-1]),Int32Array.from([6,34,62,90,-1,-1,-1]),Int32Array.from([6,28,50,72,94,-1,-1]),Int32Array.from([6,26,50,74,98,-1,-1]),Int32Array.from([6,30,54,78,102,-1,-1]),Int32Array.from([6,28,54,80,106,-1,-1]),Int32Array.from([6,32,58,84,110,-1,-1]),Int32Array.from([6,30,58,86,114,-1,-1]),Int32Array.from([6,34,62,90,118,-1,-1]),Int32Array.from([6,26,50,74,98,122,-1]),Int32Array.from([6,30,54,78,102,126,-1]),Int32Array.from([6,26,52,78,104,130,-1]),Int32Array.from([6,30,56,82,108,134,-1]),Int32Array.from([6,34,60,86,112,138,-1]),Int32Array.from([6,30,58,86,114,142,-1]),Int32Array.from([6,34,62,90,118,146,-1]),Int32Array.from([6,30,54,78,102,126,150]),Int32Array.from([6,24,50,76,102,128,154]),Int32Array.from([6,28,54,80,106,132,158]),Int32Array.from([6,32,58,84,110,136,162]),Int32Array.from([6,26,54,82,110,138,166]),Int32Array.from([6,30,58,86,114,142,170])]),Oe.TYPE_INFO_COORDINATES=Array.from([Int32Array.from([8,0]),Int32Array.from([8,1]),Int32Array.from([8,2]),Int32Array.from([8,3]),Int32Array.from([8,4]),Int32Array.from([8,5]),Int32Array.from([8,7]),Int32Array.from([8,8]),Int32Array.from([7,8]),Int32Array.from([5,8]),Int32Array.from([4,8]),Int32Array.from([3,8]),Int32Array.from([2,8]),Int32Array.from([1,8]),Int32Array.from([0,8])]),Oe.VERSION_INFO_POLY=7973,Oe.TYPE_INFO_POLY=1335,Oe.TYPE_INFO_MASK_PATTERN=21522;class fd{constructor(e,n){this.dataBytes=e,this.errorCorrectionBytes=n}getDataBytes(){return this.dataBytes}getErrorCorrectionBytes(){return this.errorCorrectionBytes}}class ct{constructor(){}static calculateMaskPenalty(e){return Ct.applyMaskPenaltyRule1(e)+Ct.applyMaskPenaltyRule2(e)+Ct.applyMaskPenaltyRule3(e)+Ct.applyMaskPenaltyRule4(e)}static encode(e,n,i=null){let s=ct.DEFAULT_BYTE_MODE_ENCODING;const a=i!==null&&i.get(kt.CHARACTER_SET)!==void 0;a&&(s=i.get(kt.CHARACTER_SET).toString());const l=this.chooseMode(e,s),d=new $;if(l===Ne.BYTE&&(a||ct.DEFAULT_BYTE_MODE_ENCODING!==s)){const he=j.getCharacterSetECIByName(s);he!==void 0&&this.appendECI(he,d)}this.appendModeInfo(l,d);const h=new $;this.appendBytes(e,l,h,s);let g;if(i!==null&&i.get(kt.QR_VERSION)!==void 0){const he=Number.parseInt(i.get(kt.QR_VERSION).toString(),10);g=Ie.getVersionForNumber(he);const ce=this.calculateBitsNeeded(l,d,h,g);if(!this.willFit(ce,g,n))throw new it("Data too big for requested version")}else g=this.recommendVersion(n,l,d,h);const w=new $;w.appendBitArray(d);const b=l===Ne.BYTE?h.getSizeInBytes():e.length;this.appendLengthInfo(b,g,l,w),w.appendBitArray(h);const I=g.getECBlocksForLevel(n),N=g.getTotalCodewords()-I.getTotalECCodewords();this.terminateBits(N,w);const F=this.interleaveWithECBytes(w,g.getTotalCodewords(),N,I.getNumBlocks()),U=new er;U.setECLevel(n),U.setMode(l),U.setVersion(g);const W=g.getDimensionForVersion(),K=new gi(W,W),fe=this.chooseMaskPattern(F,n,g,K);return U.setMaskPattern(fe),Oe.buildMatrix(F,n,g,fe,K),U.setMatrix(K),U}static recommendVersion(e,n,i,s){const a=this.calculateBitsNeeded(n,i,s,Ie.getVersionForNumber(1)),l=this.chooseVersion(a,e),d=this.calculateBitsNeeded(n,i,s,l);return this.chooseVersion(d,e)}static calculateBitsNeeded(e,n,i,s){return n.getSize()+e.getCharacterCountBits(s)+i.getSize()}static getAlphanumericCode(e){return e<ct.ALPHANUMERIC_TABLE.length?ct.ALPHANUMERIC_TABLE[e]:-1}static chooseMode(e,n=null){if(j.SJIS.getName()===n&&this.isOnlyDoubleByteKanji(e))return Ne.KANJI;let i=!1,s=!1;for(let a=0,l=e.length;a<l;++a){const d=e.charAt(a);if(ct.isDigit(d))i=!0;else if(this.getAlphanumericCode(d.charCodeAt(0))!==-1)s=!0;else return Ne.BYTE}return s?Ne.ALPHANUMERIC:i?Ne.NUMERIC:Ne.BYTE}static isOnlyDoubleByteKanji(e){let n;try{n=de.encode(e,j.SJIS)}catch{return!1}const i=n.length;if(i%2!==0)return!1;for(let s=0;s<i;s+=2){const a=n[s]&255;if((a<129||a>159)&&(a<224||a>235))return!1}return!0}static chooseMaskPattern(e,n,i,s){let a=Number.MAX_SAFE_INTEGER,l=-1;for(let d=0;d<er.NUM_MASK_PATTERNS;d++){Oe.buildMatrix(e,n,i,d,s);let h=this.calculateMaskPenalty(s);h<a&&(a=h,l=d)}return l}static chooseVersion(e,n){for(let i=1;i<=40;i++){const s=Ie.getVersionForNumber(i);if(ct.willFit(e,s,n))return s}throw new it("Data too big")}static willFit(e,n,i){const s=n.getTotalCodewords(),l=n.getECBlocksForLevel(i).getTotalECCodewords(),d=s-l,h=(e+7)/8;return d>=h}static terminateBits(e,n){const i=e*8;if(n.getSize()>i)throw new it("data bits cannot fit in the QR Code"+n.getSize()+" > "+i);for(let l=0;l<4&&n.getSize()<i;++l)n.appendBit(!1);const s=n.getSize()&7;if(s>0)for(let l=s;l<8;l++)n.appendBit(!1);const a=e-n.getSizeInBytes();for(let l=0;l<a;++l)n.appendBits((l&1)===0?236:17,8);if(n.getSize()!==i)throw new it("Bits size does not equal capacity")}static getNumDataBytesAndNumECBytesForBlockID(e,n,i,s,a,l){if(s>=i)throw new it("Block ID too large");const d=e%i,h=i-d,g=Math.floor(e/i),w=g+1,b=Math.floor(n/i),I=b+1,N=g-b,F=w-I;if(N!==F)throw new it("EC bytes mismatch");if(i!==h+d)throw new it("RS blocks mismatch");if(e!==(b+N)*h+(I+F)*d)throw new it("Total bytes mismatch");s<h?(a[0]=b,l[0]=N):(a[0]=I,l[0]=F)}static interleaveWithECBytes(e,n,i,s){if(e.getSizeInBytes()!==i)throw new it("Number of bits and data bytes does not match");let a=0,l=0,d=0;const h=new Array;for(let w=0;w<s;++w){const b=new Int32Array(1),I=new Int32Array(1);ct.getNumDataBytesAndNumECBytesForBlockID(n,i,s,w,b,I);const N=b[0],F=new Uint8Array(N);e.toBytes(8*a,F,0,N);const U=ct.generateECBytes(F,I[0]);h.push(new fd(F,U)),l=Math.max(l,N),d=Math.max(d,U.length),a+=b[0]}if(i!==a)throw new it("Data bytes does not match offset");const g=new $;for(let w=0;w<l;++w)for(const b of h){const I=b.getDataBytes();w<I.length&&g.appendBits(I[w],8)}for(let w=0;w<d;++w)for(const b of h){const I=b.getErrorCorrectionBytes();w<I.length&&g.appendBits(I[w],8)}if(n!==g.getSizeInBytes())throw new it("Interleaving error: "+n+" and "+g.getSizeInBytes()+" differ.");return g}static generateECBytes(e,n){const i=e.length,s=new Int32Array(i+n);for(let l=0;l<i;l++)s[l]=e[l]&255;new io(Be.QR_CODE_FIELD_256).encode(s,n);const a=new Uint8Array(n);for(let l=0;l<n;l++)a[l]=s[i+l];return a}static appendModeInfo(e,n){n.appendBits(e.getBits(),4)}static appendLengthInfo(e,n,i,s){const a=i.getCharacterCountBits(n);if(e>=1<<a)throw new it(e+" is bigger than "+((1<<a)-1));s.appendBits(e,a)}static appendBytes(e,n,i,s){switch(n){case Ne.NUMERIC:ct.appendNumericBytes(e,i);break;case Ne.ALPHANUMERIC:ct.appendAlphanumericBytes(e,i);break;case Ne.BYTE:ct.append8BitBytes(e,i,s);break;case Ne.KANJI:ct.appendKanjiBytes(e,i);break;default:throw new it("Invalid mode: "+n)}}static getDigit(e){return e.charCodeAt(0)-48}static isDigit(e){const n=ct.getDigit(e);return n>=0&&n<=9}static appendNumericBytes(e,n){const i=e.length;let s=0;for(;s<i;){const a=ct.getDigit(e.charAt(s));if(s+2<i){const l=ct.getDigit(e.charAt(s+1)),d=ct.getDigit(e.charAt(s+2));n.appendBits(a*100+l*10+d,10),s+=3}else if(s+1<i){const l=ct.getDigit(e.charAt(s+1));n.appendBits(a*10+l,7),s+=2}else n.appendBits(a,4),s++}}static appendAlphanumericBytes(e,n){const i=e.length;let s=0;for(;s<i;){const a=ct.getAlphanumericCode(e.charCodeAt(s));if(a===-1)throw new it;if(s+1<i){const l=ct.getAlphanumericCode(e.charCodeAt(s+1));if(l===-1)throw new it;n.appendBits(a*45+l,11),s+=2}else n.appendBits(a,6),s++}}static append8BitBytes(e,n,i){let s;try{s=de.encode(e,i)}catch(a){throw new it(a)}for(let a=0,l=s.length;a!==l;a++){const d=s[a];n.appendBits(d,8)}}static appendKanjiBytes(e,n){let i;try{i=de.encode(e,j.SJIS)}catch(a){throw new it(a)}const s=i.length;for(let a=0;a<s;a+=2){const l=i[a]&255,d=i[a+1]&255,h=l<<8&4294967295|d;let g=-1;if(h>=33088&&h<=40956?g=h-33088:h>=57408&&h<=60351&&(g=h-49472),g===-1)throw new it("Invalid byte sequence");const w=(g>>8)*192+(g&255);n.appendBits(w,13)}}static appendECI(e,n){n.appendBits(Ne.ECI.getBits(),4),n.appendBits(e.getValue(),8)}}ct.ALPHANUMERIC_TABLE=Int32Array.from([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,36,-1,-1,-1,37,38,-1,-1,-1,-1,39,40,-1,41,42,43,0,1,2,3,4,5,6,7,8,9,44,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1]),ct.DEFAULT_BYTE_MODE_ENCODING=j.UTF8.getName();class tr{write(e,n,i,s=null){if(e.length===0)throw new E("Found empty contents");if(n<0||i<0)throw new E("Requested dimensions are too small: "+n+"x"+i);let a=lt.L,l=tr.QUIET_ZONE_SIZE;s!==null&&(s.get(kt.ERROR_CORRECTION)!==void 0&&(a=lt.fromString(s.get(kt.ERROR_CORRECTION).toString())),s.get(kt.MARGIN)!==void 0&&(l=Number.parseInt(s.get(kt.MARGIN).toString(),10)));const d=ct.encode(e,a,s);return this.renderResult(d,n,i,l)}writeToDom(e,n,i,s,a=null){typeof e=="string"&&(e=document.querySelector(e));const l=this.write(n,i,s,a);e&&e.appendChild(l)}renderResult(e,n,i,s){const a=e.getMatrix();if(a===null)throw new Vt;const l=a.getWidth(),d=a.getHeight(),h=l+s*2,g=d+s*2,w=Math.max(n,h),b=Math.max(i,g),I=Math.min(Math.floor(w/h),Math.floor(b/g)),N=Math.floor((w-l*I)/2),F=Math.floor((b-d*I)/2),U=this.createSVGElement(w,b);for(let W=0,K=F;W<d;W++,K+=I)for(let fe=0,he=N;fe<l;fe++,he+=I)if(a.get(fe,W)===1){const ce=this.createSvgRectElement(he,K,I,I);U.appendChild(ce)}return U}createSVGElement(e,n){const i=document.createElementNS(tr.SVG_NS,"svg");return i.setAttributeNS(null,"height",e.toString()),i.setAttributeNS(null,"width",n.toString()),i}createSvgRectElement(e,n,i,s){const a=document.createElementNS(tr.SVG_NS,"rect");return a.setAttributeNS(null,"x",e.toString()),a.setAttributeNS(null,"y",n.toString()),a.setAttributeNS(null,"height",i.toString()),a.setAttributeNS(null,"width",s.toString()),a.setAttributeNS(null,"fill","#000000"),a}}tr.QUIET_ZONE_SIZE=4,tr.SVG_NS="http://www.w3.org/2000/svg";class wr{encode(e,n,i,s,a){if(e.length===0)throw new E("Found empty contents");if(n!==ge.QR_CODE)throw new E("Can only encode QR_CODE, but got "+n);if(i<0||s<0)throw new E(`Requested dimensions are too small: ${i}x${s}`);let l=lt.L,d=wr.QUIET_ZONE_SIZE;a!==null&&(a.get(kt.ERROR_CORRECTION)!==void 0&&(l=lt.fromString(a.get(kt.ERROR_CORRECTION).toString())),a.get(kt.MARGIN)!==void 0&&(d=Number.parseInt(a.get(kt.MARGIN).toString(),10)));const h=ct.encode(e,l,a);return wr.renderResult(h,i,s,d)}static renderResult(e,n,i,s){const a=e.getMatrix();if(a===null)throw new Vt;const l=a.getWidth(),d=a.getHeight(),h=l+s*2,g=d+s*2,w=Math.max(n,h),b=Math.max(i,g),I=Math.min(Math.floor(w/h),Math.floor(b/g)),N=Math.floor((w-l*I)/2),F=Math.floor((b-d*I)/2),U=new ee(w,b);for(let W=0,K=F;W<d;W++,K+=I)for(let fe=0,he=N;fe<l;fe++,he+=I)a.get(fe,W)===1&&U.setRegion(he,K,I,I);return U}}wr.QUIET_ZONE_SIZE=4;class hd{encode(e,n,i,s,a){let l;switch(n){case ge.QR_CODE:l=new wr;break;default:throw new E("No encoder available for format "+n)}return l.encode(e,n,i,s,a)}}class Sn extends te{constructor(e,n,i,s,a,l,d,h){if(super(l,d),this.yuvData=e,this.dataWidth=n,this.dataHeight=i,this.left=s,this.top=a,s+l>n||a+d>i)throw new E("Crop rectangle does not fit within image data.");h&&this.reverseHorizontal(l,d)}getRow(e,n){if(e<0||e>=this.getHeight())throw new E("Requested row is outside the image: "+e);const i=this.getWidth();(n==null||n.length<i)&&(n=new Uint8ClampedArray(i));const s=(e+this.top)*this.dataWidth+this.left;return R.arraycopy(this.yuvData,s,n,0,i),n}getMatrix(){const e=this.getWidth(),n=this.getHeight();if(e===this.dataWidth&&n===this.dataHeight)return this.yuvData;const i=e*n,s=new Uint8ClampedArray(i);let a=this.top*this.dataWidth+this.left;if(e===this.dataWidth)return R.arraycopy(this.yuvData,a,s,0,i),s;for(let l=0;l<n;l++){const d=l*e;R.arraycopy(this.yuvData,a,s,d,e),a+=this.dataWidth}return s}isCropSupported(){return!0}crop(e,n,i,s){return new Sn(this.yuvData,this.dataWidth,this.dataHeight,this.left+e,this.top+n,i,s,!1)}renderThumbnail(){const e=this.getWidth()/Sn.THUMBNAIL_SCALE_FACTOR,n=this.getHeight()/Sn.THUMBNAIL_SCALE_FACTOR,i=new Int32Array(e*n),s=this.yuvData;let a=this.top*this.dataWidth+this.left;for(let l=0;l<n;l++){const d=l*e;for(let h=0;h<e;h++){const g=s[a+h*Sn.THUMBNAIL_SCALE_FACTOR]&255;i[d+h]=4278190080|g*65793}a+=this.dataWidth*Sn.THUMBNAIL_SCALE_FACTOR}return i}getThumbnailWidth(){return this.getWidth()/Sn.THUMBNAIL_SCALE_FACTOR}getThumbnailHeight(){return this.getHeight()/Sn.THUMBNAIL_SCALE_FACTOR}reverseHorizontal(e,n){const i=this.yuvData;for(let s=0,a=this.top*this.dataWidth+this.left;s<n;s++,a+=this.dataWidth){const l=a+e/2;for(let d=a,h=a+e-1;d<l;d++,h--){const g=i[d];i[d]=i[h],i[h]=g}}}invert(){return new we(this)}}Sn.THUMBNAIL_SCALE_FACTOR=2;class oo extends te{constructor(e,n,i,s,a,l,d){if(super(n,i),this.dataWidth=s,this.dataHeight=a,this.left=l,this.top=d,e.BYTES_PER_ELEMENT===4){const h=n*i,g=new Uint8ClampedArray(h);for(let w=0;w<h;w++){const b=e[w],I=b>>16&255,N=b>>7&510,F=b&255;g[w]=(I+N+F)/4&255}this.luminances=g}else this.luminances=e;if(s===void 0&&(this.dataWidth=n),a===void 0&&(this.dataHeight=i),l===void 0&&(this.left=0),d===void 0&&(this.top=0),this.left+n>this.dataWidth||this.top+i>this.dataHeight)throw new E("Crop rectangle does not fit within image data.")}getRow(e,n){if(e<0||e>=this.getHeight())throw new E("Requested row is outside the image: "+e);const i=this.getWidth();(n==null||n.length<i)&&(n=new Uint8ClampedArray(i));const s=(e+this.top)*this.dataWidth+this.left;return R.arraycopy(this.luminances,s,n,0,i),n}getMatrix(){const e=this.getWidth(),n=this.getHeight();if(e===this.dataWidth&&n===this.dataHeight)return this.luminances;const i=e*n,s=new Uint8ClampedArray(i);let a=this.top*this.dataWidth+this.left;if(e===this.dataWidth)return R.arraycopy(this.luminances,a,s,0,i),s;for(let l=0;l<n;l++){const d=l*e;R.arraycopy(this.luminances,a,s,d,e),a+=this.dataWidth}return s}isCropSupported(){return!0}crop(e,n,i,s){return new oo(this.luminances,i,s,this.dataWidth,this.dataHeight,this.left+e,this.top+n)}invert(){return new we(this)}}class ws extends j{static forName(e){return this.getCharacterSetECIByName(e)}}class so{}so.ISO_8859_1=j.ISO8859_1;class ys{isCompact(){return this.compact}setCompact(e){this.compact=e}getSize(){return this.size}setSize(e){this.size=e}getLayers(){return this.layers}setLayers(e){this.layers=e}getCodeWords(){return this.codeWords}setCodeWords(e){this.codeWords=e}getMatrix(){return this.matrix}setMatrix(e){this.matrix=e}}class _s{static singletonList(e){return[e]}static min(e,n){return e.sort(n)[0]}}class pd{constructor(e){this.previous=e}getPrevious(){return this.previous}}class yr extends pd{constructor(e,n,i){super(e),this.value=n,this.bitCount=i}appendTo(e,n){e.appendBits(this.value,this.bitCount)}add(e,n){return new yr(this,e,n)}addBinaryShift(e,n){return console.warn("addBinaryShift on SimpleToken, this simply returns a copy of this token"),new yr(this,e,n)}toString(){let e=this.value&(1<<this.bitCount)-1;return e|=1<<this.bitCount,"<"+z.toBinaryString(e|1<<this.bitCount).substring(1)+">"}}class ao extends yr{constructor(e,n,i){super(e,0,0),this.binaryShiftStart=n,this.binaryShiftByteCount=i}appendTo(e,n){for(let i=0;i<this.binaryShiftByteCount;i++)(i===0||i===31&&this.binaryShiftByteCount<=62)&&(e.appendBits(31,5),this.binaryShiftByteCount>62?e.appendBits(this.binaryShiftByteCount-31,16):i===0?e.appendBits(Math.min(this.binaryShiftByteCount,31),5):e.appendBits(this.binaryShiftByteCount-31,5)),e.appendBits(n[this.binaryShiftStart+i],8)}addBinaryShift(e,n){return new ao(this,e,n)}toString(){return"<"+this.binaryShiftStart+"::"+(this.binaryShiftStart+this.binaryShiftByteCount-1)+">"}}function gd(C,e,n){return new ao(C,e,n)}function Br(C,e,n){return new yr(C,e,n)}const md=["UPPER","LOWER","DIGIT","MIXED","PUNCT"],$n=0,mi=1,fn=2,vs=3,Tn=4,xd=new yr(null,0,0),lo=[Int32Array.from([0,(5<<16)+28,(5<<16)+30,(5<<16)+29,656318]),Int32Array.from([(9<<16)+480+14,0,(5<<16)+30,(5<<16)+29,656318]),Int32Array.from([(4<<16)+14,(9<<16)+448+28,0,(9<<16)+448+29,932798]),Int32Array.from([(5<<16)+29,(5<<16)+28,656318,0,(5<<16)+30]),Int32Array.from([(5<<16)+31,656380,656382,656381,0])];function wd(C){for(let e of C)Z.fill(e,-1);return C[$n][Tn]=0,C[mi][Tn]=0,C[mi][$n]=28,C[vs][Tn]=0,C[fn][Tn]=0,C[fn][$n]=15,C}const Cs=wd(Z.createInt32Array(6,6));class Nn{constructor(e,n,i,s){this.token=e,this.mode=n,this.binaryShiftByteCount=i,this.bitCount=s}getMode(){return this.mode}getToken(){return this.token}getBinaryShiftByteCount(){return this.binaryShiftByteCount}getBitCount(){return this.bitCount}latchAndAppend(e,n){let i=this.bitCount,s=this.token;if(e!==this.mode){let l=lo[this.mode][e];s=Br(s,l&65535,l>>16),i+=l>>16}let a=e===fn?4:5;return s=Br(s,n,a),new Nn(s,e,0,i+a)}shiftAndAppend(e,n){let i=this.token,s=this.mode===fn?4:5;return i=Br(i,Cs[this.mode][e],s),i=Br(i,n,5),new Nn(i,this.mode,0,this.bitCount+s+5)}addBinaryShiftChar(e){let n=this.token,i=this.mode,s=this.bitCount;if(this.mode===Tn||this.mode===fn){let d=lo[i][$n];n=Br(n,d&65535,d>>16),s+=d>>16,i=$n}let a=this.binaryShiftByteCount===0||this.binaryShiftByteCount===31?18:this.binaryShiftByteCount===62?9:8,l=new Nn(n,i,this.binaryShiftByteCount+1,s+a);return l.binaryShiftByteCount===2078&&(l=l.endBinaryShift(e+1)),l}endBinaryShift(e){if(this.binaryShiftByteCount===0)return this;let n=this.token;return n=gd(n,e-this.binaryShiftByteCount,this.binaryShiftByteCount),new Nn(n,this.mode,0,this.bitCount)}isBetterThanOrEqualTo(e){let n=this.bitCount+(lo[this.mode][e.mode]>>16);return this.binaryShiftByteCount<e.binaryShiftByteCount?n+=Nn.calculateBinaryShiftCost(e)-Nn.calculateBinaryShiftCost(this):this.binaryShiftByteCount>e.binaryShiftByteCount&&e.binaryShiftByteCount>0&&(n+=10),n<=e.bitCount}toBitArray(e){let n=[];for(let s=this.endBinaryShift(e.length).token;s!==null;s=s.getPrevious())n.unshift(s);let i=new $;for(const s of n)s.appendTo(i,e);return i}toString(){return ne.format("%s bits=%d bytes=%d",md[this.mode],this.bitCount,this.binaryShiftByteCount)}static calculateBinaryShiftCost(e){return e.binaryShiftByteCount>62?21:e.binaryShiftByteCount>31?20:e.binaryShiftByteCount>0?10:0}}Nn.INITIAL_STATE=new Nn(xd,$n,0,0);function yd(C){const e=ne.getCharCode(" "),n=ne.getCharCode("."),i=ne.getCharCode(",");C[$n][e]=1;const s=ne.getCharCode("Z"),a=ne.getCharCode("A");for(let I=a;I<=s;I++)C[$n][I]=I-a+2;C[mi][e]=1;const l=ne.getCharCode("z"),d=ne.getCharCode("a");for(let I=d;I<=l;I++)C[mi][I]=I-d+2;C[fn][e]=1;const h=ne.getCharCode("9"),g=ne.getCharCode("0");for(let I=g;I<=h;I++)C[fn][I]=I-g+2;C[fn][i]=12,C[fn][n]=13;const w=["\0"," ","","","","","","","\x07","\b"," ",`
75
- `,"\v","\f","\r","\x1B","","","","","@","\\","^","_","`","|","~",""];for(let I=0;I<w.length;I++)C[vs][ne.getCharCode(w[I])]=I;const b=["\0","\r","\0","\0","\0","\0","!","'","#","$","%","&","'","(",")","*","+",",","-",".","/",":",";","<","=",">","?","[","]","{","}"];for(let I=0;I<b.length;I++)ne.getCharCode(b[I])>0&&(C[Tn][ne.getCharCode(b[I])]=I);return C}const co=yd(Z.createInt32Array(5,256));class Lr{constructor(e){this.text=e}encode(){const e=ne.getCharCode(" "),n=ne.getCharCode(`
76
- `);let i=_s.singletonList(Nn.INITIAL_STATE);for(let a=0;a<this.text.length;a++){let l,d=a+1<this.text.length?this.text[a+1]:0;switch(this.text[a]){case ne.getCharCode("\r"):l=d===n?2:0;break;case ne.getCharCode("."):l=d===e?3:0;break;case ne.getCharCode(","):l=d===e?4:0;break;case ne.getCharCode(":"):l=d===e?5:0;break;default:l=0}l>0?(i=Lr.updateStateListForPair(i,a,l),a++):i=this.updateStateListForChar(i,a)}return _s.min(i,(a,l)=>a.getBitCount()-l.getBitCount()).toBitArray(this.text)}updateStateListForChar(e,n){const i=[];for(let s of e)this.updateStateForChar(s,n,i);return Lr.simplifyStates(i)}updateStateForChar(e,n,i){let s=this.text[n]&255,a=co[e.getMode()][s]>0,l=null;for(let d=0;d<=Tn;d++){let h=co[d][s];if(h>0){if(l==null&&(l=e.endBinaryShift(n)),!a||d===e.getMode()||d===fn){const g=l.latchAndAppend(d,h);i.push(g)}if(!a&&Cs[e.getMode()][d]>=0){const g=l.shiftAndAppend(d,h);i.push(g)}}}if(e.getBinaryShiftByteCount()>0||co[e.getMode()][s]===0){let d=e.addBinaryShiftChar(n);i.push(d)}}static updateStateListForPair(e,n,i){const s=[];for(let a of e)this.updateStateForPair(a,n,i,s);return this.simplifyStates(s)}static updateStateForPair(e,n,i,s){let a=e.endBinaryShift(n);if(s.push(a.latchAndAppend(Tn,i)),e.getMode()!==Tn&&s.push(a.shiftAndAppend(Tn,i)),i===3||i===4){let l=a.latchAndAppend(fn,16-i).latchAndAppend(fn,1);s.push(l)}if(e.getBinaryShiftByteCount()>0){let l=e.addBinaryShiftChar(n).addBinaryShiftChar(n+1);s.push(l)}}static simplifyStates(e){let n=[];for(const i of e){let s=!0;for(const a of n){if(a.isBetterThanOrEqualTo(i)){s=!1;break}i.isBetterThanOrEqualTo(a)&&(n=n.filter(l=>l!==a))}s&&n.push(i)}return n}}class Ge{constructor(){}static encodeBytes(e){return Ge.encode(e,Ge.DEFAULT_EC_PERCENT,Ge.DEFAULT_AZTEC_LAYERS)}static encode(e,n,i){let s=new Lr(e).encode(),a=z.truncDivision(s.getSize()*n,100)+11,l=s.getSize()+a,d,h,g,w,b;if(i!==Ge.DEFAULT_AZTEC_LAYERS){if(d=i<0,h=Math.abs(i),h>(d?Ge.MAX_NB_BITS_COMPACT:Ge.MAX_NB_BITS))throw new E(ne.format("Illegal value %s for layers",i));g=Ge.totalBitsInLayer(h,d),w=Ge.WORD_SIZE[h];let ce=g-g%w;if(b=Ge.stuffBits(s,w),b.getSize()+a>ce)throw new E("Data to large for user specified layer");if(d&&b.getSize()>w*64)throw new E("Data to large for user specified layer")}else{w=0,b=null;for(let ce=0;;ce++){if(ce>Ge.MAX_NB_BITS)throw new E("Data too large for an Aztec code");if(d=ce<=3,h=d?ce+1:ce,g=Ge.totalBitsInLayer(h,d),l>g)continue;(b==null||w!==Ge.WORD_SIZE[h])&&(w=Ge.WORD_SIZE[h],b=Ge.stuffBits(s,w));let je=g-g%w;if(!(d&&b.getSize()>w*64)&&b.getSize()+a<=je)break}}let I=Ge.generateCheckWords(b,g,w),N=b.getSize()/w,F=Ge.generateModeMessage(d,h,N),U=(d?11:14)+h*4,W=new Int32Array(U),K;if(d){K=U;for(let ce=0;ce<W.length;ce++)W[ce]=ce}else{K=U+1+2*z.truncDivision(z.truncDivision(U,2)-1,15);let ce=z.truncDivision(U,2),je=z.truncDivision(K,2);for(let Pe=0;Pe<ce;Pe++){let Jt=Pe+z.truncDivision(Pe,15);W[ce-Pe-1]=je-Jt-1,W[ce+Pe]=je+Jt+1}}let fe=new ee(K);for(let ce=0,je=0;ce<h;ce++){let Pe=(h-ce)*4+(d?9:12);for(let Jt=0;Jt<Pe;Jt++){let mn=Jt*2;for(let Kt=0;Kt<2;Kt++)I.get(je+mn+Kt)&&fe.set(W[ce*2+Kt],W[ce*2+Jt]),I.get(je+Pe*2+mn+Kt)&&fe.set(W[ce*2+Jt],W[U-1-ce*2-Kt]),I.get(je+Pe*4+mn+Kt)&&fe.set(W[U-1-ce*2-Kt],W[U-1-ce*2-Jt]),I.get(je+Pe*6+mn+Kt)&&fe.set(W[U-1-ce*2-Jt],W[ce*2+Kt])}je+=Pe*8}if(Ge.drawModeMessage(fe,d,K,F),d)Ge.drawBullsEye(fe,z.truncDivision(K,2),5);else{Ge.drawBullsEye(fe,z.truncDivision(K,2),7);for(let ce=0,je=0;ce<z.truncDivision(U,2)-1;ce+=15,je+=16)for(let Pe=z.truncDivision(K,2)&1;Pe<K;Pe+=2)fe.set(z.truncDivision(K,2)-je,Pe),fe.set(z.truncDivision(K,2)+je,Pe),fe.set(Pe,z.truncDivision(K,2)-je),fe.set(Pe,z.truncDivision(K,2)+je)}let he=new ys;return he.setCompact(d),he.setSize(K),he.setLayers(h),he.setCodeWords(N),he.setMatrix(fe),he}static drawBullsEye(e,n,i){for(let s=0;s<i;s+=2)for(let a=n-s;a<=n+s;a++)e.set(a,n-s),e.set(a,n+s),e.set(n-s,a),e.set(n+s,a);e.set(n-i,n-i),e.set(n-i+1,n-i),e.set(n-i,n-i+1),e.set(n+i,n-i),e.set(n+i,n-i+1),e.set(n+i,n+i-1)}static generateModeMessage(e,n,i){let s=new $;return e?(s.appendBits(n-1,2),s.appendBits(i-1,6),s=Ge.generateCheckWords(s,28,4)):(s.appendBits(n-1,5),s.appendBits(i-1,11),s=Ge.generateCheckWords(s,40,4)),s}static drawModeMessage(e,n,i,s){let a=z.truncDivision(i,2);if(n)for(let l=0;l<7;l++){let d=a-3+l;s.get(l)&&e.set(d,a-5),s.get(l+7)&&e.set(a+5,d),s.get(20-l)&&e.set(d,a+5),s.get(27-l)&&e.set(a-5,d)}else for(let l=0;l<10;l++){let d=a-5+l+z.truncDivision(l,5);s.get(l)&&e.set(d,a-7),s.get(l+10)&&e.set(a+7,d),s.get(29-l)&&e.set(d,a+7),s.get(39-l)&&e.set(a-7,d)}}static generateCheckWords(e,n,i){let s=e.getSize()/i,a=new io(Ge.getGF(i)),l=z.truncDivision(n,i),d=Ge.bitsToWords(e,i,l);a.encode(d,l-s);let h=n%i,g=new $;g.appendBits(0,h);for(const w of Array.from(d))g.appendBits(w,i);return g}static bitsToWords(e,n,i){let s=new Int32Array(i),a,l;for(a=0,l=e.getSize()/n;a<l;a++){let d=0;for(let h=0;h<n;h++)d|=e.get(a*n+h)?1<<n-h-1:0;s[a]=d}return s}static getGF(e){switch(e){case 4:return Be.AZTEC_PARAM;case 6:return Be.AZTEC_DATA_6;case 8:return Be.AZTEC_DATA_8;case 10:return Be.AZTEC_DATA_10;case 12:return Be.AZTEC_DATA_12;default:throw new E("Unsupported word size "+e)}}static stuffBits(e,n){let i=new $,s=e.getSize(),a=(1<<n)-2;for(let l=0;l<s;l+=n){let d=0;for(let h=0;h<n;h++)(l+h>=s||e.get(l+h))&&(d|=1<<n-1-h);(d&a)===a?(i.appendBits(d&a,n),l--):(d&a)===0?(i.appendBits(d|1,n),l--):i.appendBits(d,n)}return i}static totalBitsInLayer(e,n){return((n?88:112)+16*e)*e}}Ge.DEFAULT_EC_PERCENT=33,Ge.DEFAULT_AZTEC_LAYERS=0,Ge.MAX_NB_BITS=32,Ge.MAX_NB_BITS_COMPACT=4,Ge.WORD_SIZE=Int32Array.from([4,6,6,8,8,8,8,8,8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,12,12,12,12,12,12,12,12,12,12]);class xi{encode(e,n,i,s){return this.encodeWithHints(e,n,i,s,null)}encodeWithHints(e,n,i,s,a){let l=so.ISO_8859_1,d=Ge.DEFAULT_EC_PERCENT,h=Ge.DEFAULT_AZTEC_LAYERS;return a!=null&&(a.has(kt.CHARACTER_SET)&&(l=ws.forName(a.get(kt.CHARACTER_SET).toString())),a.has(kt.ERROR_CORRECTION)&&(d=z.parseInt(a.get(kt.ERROR_CORRECTION).toString())),a.has(kt.AZTEC_LAYERS)&&(h=z.parseInt(a.get(kt.AZTEC_LAYERS).toString()))),xi.encodeLayers(e,n,i,s,l,d,h)}static encodeLayers(e,n,i,s,a,l,d){if(n!==ge.AZTEC)throw new E("Can only encode AZTEC, but got "+n);let h=Ge.encode(ne.getBytes(e,a),l,d);return xi.renderResult(h,i,s)}static renderResult(e,n,i){let s=e.getMatrix();if(s==null)throw new Vt;let a=s.getWidth(),l=s.getHeight(),d=Math.max(n,a),h=Math.max(i,l),g=Math.min(d/a,h/l),w=(d-a*g)/2,b=(h-l*g)/2,I=new ee(d,h);for(let N=0,F=b;N<l;N++,F+=g)for(let U=0,W=w;U<a;U++,W+=g)s.get(U,N)&&I.setRegion(W,F,g,g);return I}}o.AbstractExpandedDecoder=Xi,o.ArgumentException=A,o.ArithmeticException=jt,o.AztecCode=ys,o.AztecCodeReader=at,o.AztecCodeWriter=xi,o.AztecDecoder=ue,o.AztecDetector=li,o.AztecDetectorResult=si,o.AztecEncoder=Ge,o.AztecHighLevelEncoder=Lr,o.AztecPoint=Lt,o.BarcodeFormat=ge,o.Binarizer=M,o.BinaryBitmap=B,o.BitArray=$,o.BitMatrix=ee,o.BitSource=Ki,o.BrowserAztecCodeReader=Me,o.BrowserBarcodeReader=Yu,o.BrowserCodeReader=Ze,o.BrowserDatamatrixCodeReader=Ku,o.BrowserMultiFormatReader=cd,o.BrowserPDF417Reader=ud,o.BrowserQRCodeReader=dd,o.BrowserQRCodeSvgWriter=tr,o.CharacterSetECI=j,o.ChecksumException=D,o.Code128Reader=pe,o.Code39Reader=St,o.DataMatrixDecodedBitStreamParser=Fn,o.DataMatrixReader=Un,o.DecodeHintType=O,o.DecoderResult=Nt,o.DefaultGridSampler=ai,o.DetectorResult=fr,o.EAN13Reader=Yn,o.EncodeHintType=kt,o.Exception=m,o.FormatException=V,o.GenericGF=Be,o.GenericGFPoly=et,o.GlobalHistogramBinarizer=H,o.GridSampler=Tr,o.GridSamplerInstance=bn,o.HTMLCanvasElementLuminanceSource=se,o.HybridBinarizer=re,o.ITFReader=rt,o.IllegalArgumentException=E,o.IllegalStateException=Vt,o.InvertedLuminanceSource=we,o.LuminanceSource=te,o.MathUtils=Te,o.MultiFormatOneDReader=mr,o.MultiFormatReader=xs,o.MultiFormatWriter=hd,o.NotFoundException=P,o.OneDReader=ke,o.PDF417DecodedBitStreamParser=J,o.PDF417DecoderErrorCorrection=ds,o.PDF417Reader=Ut,o.PDF417ResultMetadata=hs,o.PerspectiveTransform=en,o.PlanarYUVLuminanceSource=Sn,o.QRCodeByteMatrix=gi,o.QRCodeDataMask=un,o.QRCodeDecodedBitStreamParser=xt,o.QRCodeDecoderErrorCorrectionLevel=lt,o.QRCodeDecoderFormatInformation=Zt,o.QRCodeEncoder=ct,o.QRCodeEncoderQRCode=er,o.QRCodeMaskUtil=Ct,o.QRCodeMatrixUtil=Oe,o.QRCodeMode=Ne,o.QRCodeReader=zn,o.QRCodeVersion=Ie,o.QRCodeWriter=wr,o.RGBLuminanceSource=oo,o.RSS14Reader=vt,o.RSSExpandedReader=ae,o.ReaderException=pi,o.ReedSolomonDecoder=Cn,o.ReedSolomonEncoder=io,o.ReedSolomonException=hn,o.Result=Ue,o.ResultMetadataType=Se,o.ResultPoint=be,o.StringUtils=ne,o.UnsupportedOperationException=Ee,o.VideoInputDevice=ye,o.WhiteRectangleDetector=pn,o.WriterException=it,o.ZXingArrays=Z,o.ZXingCharset=ws,o.ZXingInteger=z,o.ZXingStandardCharsets=so,o.ZXingStringBuilder=oe,o.ZXingStringEncoding=de,o.ZXingSystem=R,o.createAbstractExpandedDecoder=cs,Object.defineProperty(o,"__esModule",{value:!0})}))})(jr,jr.exports)),jr.exports}var ut=Gw();const Xw=Ic(ut),qw=Ad({__proto__:null,default:Xw},[ut]);var sl=(function(){function t(r,o,c){if(this.formatMap=new Map([[Ce.QR_CODE,ut.BarcodeFormat.QR_CODE],[Ce.AZTEC,ut.BarcodeFormat.AZTEC],[Ce.CODABAR,ut.BarcodeFormat.CODABAR],[Ce.CODE_39,ut.BarcodeFormat.CODE_39],[Ce.CODE_93,ut.BarcodeFormat.CODE_93],[Ce.CODE_128,ut.BarcodeFormat.CODE_128],[Ce.DATA_MATRIX,ut.BarcodeFormat.DATA_MATRIX],[Ce.MAXICODE,ut.BarcodeFormat.MAXICODE],[Ce.ITF,ut.BarcodeFormat.ITF],[Ce.EAN_13,ut.BarcodeFormat.EAN_13],[Ce.EAN_8,ut.BarcodeFormat.EAN_8],[Ce.PDF_417,ut.BarcodeFormat.PDF_417],[Ce.RSS_14,ut.BarcodeFormat.RSS_14],[Ce.RSS_EXPANDED,ut.BarcodeFormat.RSS_EXPANDED],[Ce.UPC_A,ut.BarcodeFormat.UPC_A],[Ce.UPC_E,ut.BarcodeFormat.UPC_E],[Ce.UPC_EAN_EXTENSION,ut.BarcodeFormat.UPC_EAN_EXTENSION]]),this.reverseFormatMap=this.createReverseFormatMap(),!qw)throw"Use html5qrcode.min.js without edit, ZXing not found.";this.verbose=o,this.logger=c;var u=this.createZXingFormats(r),f=new Map;f.set(ut.DecodeHintType.POSSIBLE_FORMATS,u),f.set(ut.DecodeHintType.TRY_HARDER,!1),this.hints=f}return t.prototype.decodeAsync=function(r){var o=this;return new Promise(function(c,u){try{c(o.decode(r))}catch(f){u(f)}})},t.prototype.decode=function(r){var o=new ut.MultiFormatReader(this.verbose,this.hints),c=new ut.HTMLCanvasElementLuminanceSource(r),u=new ut.BinaryBitmap(new ut.HybridBinarizer(c)),f=o.decode(u);return{text:f.text,format:$u.create(this.toHtml5QrcodeSupportedFormats(f.format)),debugData:this.createDebugData()}},t.prototype.createReverseFormatMap=function(){var r=new Map;return this.formatMap.forEach(function(o,c,u){r.set(o,c)}),r},t.prototype.toHtml5QrcodeSupportedFormats=function(r){if(!this.reverseFormatMap.has(r))throw"reverseFormatMap doesn't have ".concat(r);return this.reverseFormatMap.get(r)},t.prototype.createZXingFormats=function(r){for(var o=[],c=0,u=r;c<u.length;c++){var f=u[c];this.formatMap.has(f)?o.push(this.formatMap.get(f)):this.logger.logError("".concat(f," is not supported by")+"ZXingHtml5QrcodeShim")}return o},t.prototype.createDebugData=function(){return{decoderName:"zxing-js"}},t})(),Yw=function(t,r,o,c){function u(f){return f instanceof o?f:new o(function(p){p(f)})}return new(o||(o=Promise))(function(f,p){function x(A){try{m(c.next(A))}catch(E){p(E)}}function y(A){try{m(c.throw(A))}catch(E){p(E)}}function m(A){A.done?f(A.value):u(A.value).then(x,y)}m((c=c.apply(t,r||[])).next())})},Jw=function(t,r){var o={label:0,sent:function(){if(f[0]&1)throw f[1];return f[1]},trys:[],ops:[]},c,u,f,p;return p={next:x(0),throw:x(1),return:x(2)},typeof Symbol=="function"&&(p[Symbol.iterator]=function(){return this}),p;function x(m){return function(A){return y([m,A])}}function y(m){if(c)throw new TypeError("Generator is already executing.");for(;p&&(p=0,m[0]&&(o=0)),o;)try{if(c=1,u&&(f=m[0]&2?u.return:m[0]?u.throw||((f=u.return)&&f.call(u),0):u.next)&&!(f=f.call(u,m[1])).done)return f;switch(u=0,f&&(m=[m[0]&2,f.value]),m[0]){case 0:case 1:f=m;break;case 4:return o.label++,{value:m[1],done:!1};case 5:o.label++,u=m[1],m=[0];continue;case 7:m=o.ops.pop(),o.trys.pop();continue;default:if(f=o.trys,!(f=f.length>0&&f[f.length-1])&&(m[0]===6||m[0]===2)){o=0;continue}if(m[0]===3&&(!f||m[1]>f[0]&&m[1]<f[3])){o.label=m[1];break}if(m[0]===6&&o.label<f[1]){o.label=f[1],f=m;break}if(f&&o.label<f[2]){o.label=f[2],o.ops.push(m);break}f[2]&&o.ops.pop(),o.trys.pop();continue}m=r.call(t,o)}catch(A){m=[6,A],u=0}finally{c=f=0}if(m[0]&5)throw m[1];return{value:m[0]?m[1]:void 0,done:!0}}},al=(function(){function t(r,o,c){if(this.formatMap=new Map([[Ce.QR_CODE,"qr_code"],[Ce.AZTEC,"aztec"],[Ce.CODABAR,"codabar"],[Ce.CODE_39,"code_39"],[Ce.CODE_93,"code_93"],[Ce.CODE_128,"code_128"],[Ce.DATA_MATRIX,"data_matrix"],[Ce.ITF,"itf"],[Ce.EAN_13,"ean_13"],[Ce.EAN_8,"ean_8"],[Ce.PDF_417,"pdf417"],[Ce.UPC_A,"upc_a"],[Ce.UPC_E,"upc_e"]]),this.reverseFormatMap=this.createReverseFormatMap(),!t.isSupported())throw"Use html5qrcode.min.js without edit, Use BarcodeDetectorDelegate only if it isSupported();";this.verbose=o,this.logger=c;var u=this.createBarcodeDetectorFormats(r);if(this.detector=new BarcodeDetector(u),!this.detector)throw"BarcodeDetector detector not supported"}return t.isSupported=function(){if(!("BarcodeDetector"in window))return!1;var r=new BarcodeDetector({formats:["qr_code"]});return typeof r<"u"},t.prototype.decodeAsync=function(r){return Yw(this,void 0,void 0,function(){var o,c;return Jw(this,function(u){switch(u.label){case 0:return[4,this.detector.detect(r)];case 1:if(o=u.sent(),!o||o.length===0)throw"No barcode or QR code detected.";return c=this.selectLargestBarcode(o),[2,{text:c.rawValue,format:$u.create(this.toHtml5QrcodeSupportedFormats(c.format)),debugData:this.createDebugData()}]}})})},t.prototype.selectLargestBarcode=function(r){for(var o=null,c=0,u=0,f=r;u<f.length;u++){var p=f[u],x=p.boundingBox.width*p.boundingBox.height;x>c&&(c=x,o=p)}if(!o)throw"No largest barcode found";return o},t.prototype.createBarcodeDetectorFormats=function(r){for(var o=[],c=0,u=r;c<u.length;c++){var f=u[c];this.formatMap.has(f)?o.push(this.formatMap.get(f)):this.logger.warn("".concat(f," is not supported by")+"BarcodeDetectorDelegate")}return{formats:o}},t.prototype.toHtml5QrcodeSupportedFormats=function(r){if(!this.reverseFormatMap.has(r))throw"reverseFormatMap doesn't have ".concat(r);return this.reverseFormatMap.get(r)},t.prototype.createReverseFormatMap=function(){var r=new Map;return this.formatMap.forEach(function(o,c,u){r.set(o,c)}),r},t.prototype.createDebugData=function(){return{decoderName:"BarcodeDetector"}},t})(),ll=function(t,r,o,c){function u(f){return f instanceof o?f:new o(function(p){p(f)})}return new(o||(o=Promise))(function(f,p){function x(A){try{m(c.next(A))}catch(E){p(E)}}function y(A){try{m(c.throw(A))}catch(E){p(E)}}function m(A){A.done?f(A.value):u(A.value).then(x,y)}m((c=c.apply(t,r||[])).next())})},cl=function(t,r){var o={label:0,sent:function(){if(f[0]&1)throw f[1];return f[1]},trys:[],ops:[]},c,u,f,p;return p={next:x(0),throw:x(1),return:x(2)},typeof Symbol=="function"&&(p[Symbol.iterator]=function(){return this}),p;function x(m){return function(A){return y([m,A])}}function y(m){if(c)throw new TypeError("Generator is already executing.");for(;p&&(p=0,m[0]&&(o=0)),o;)try{if(c=1,u&&(f=m[0]&2?u.return:m[0]?u.throw||((f=u.return)&&f.call(u),0):u.next)&&!(f=f.call(u,m[1])).done)return f;switch(u=0,f&&(m=[m[0]&2,f.value]),m[0]){case 0:case 1:f=m;break;case 4:return o.label++,{value:m[1],done:!1};case 5:o.label++,u=m[1],m=[0];continue;case 7:m=o.ops.pop(),o.trys.pop();continue;default:if(f=o.trys,!(f=f.length>0&&f[f.length-1])&&(m[0]===6||m[0]===2)){o=0;continue}if(m[0]===3&&(!f||m[1]>f[0]&&m[1]<f[3])){o.label=m[1];break}if(m[0]===6&&o.label<f[1]){o.label=f[1],f=m;break}if(f&&o.label<f[2]){o.label=f[2],o.ops.push(m);break}f[2]&&o.ops.pop(),o.trys.pop();continue}m=r.call(t,o)}catch(A){m=[6,A],u=0}finally{c=f=0}if(m[0]&5)throw m[1];return{value:m[0]?m[1]:void 0,done:!0}}},Kw=(function(){function t(r,o,c,u){this.EXECUTIONS_TO_REPORT_PERFORMANCE=100,this.executions=0,this.executionResults=[],this.wasPrimaryDecoderUsedInLastDecode=!1,this.verbose=c,o&&al.isSupported()?(this.primaryDecoder=new al(r,c,u),this.secondaryDecoder=new sl(r,c,u)):this.primaryDecoder=new sl(r,c,u)}return t.prototype.decodeAsync=function(r){return ll(this,void 0,void 0,function(){var o;return cl(this,function(c){switch(c.label){case 0:o=performance.now(),c.label=1;case 1:return c.trys.push([1,,3,4]),[4,this.getDecoder().decodeAsync(r)];case 2:return[2,c.sent()];case 3:return this.possiblyLogPerformance(o),[7];case 4:return[2]}})})},t.prototype.decodeRobustlyAsync=function(r){return ll(this,void 0,void 0,function(){var o,c;return cl(this,function(u){switch(u.label){case 0:o=performance.now(),u.label=1;case 1:return u.trys.push([1,3,4,5]),[4,this.primaryDecoder.decodeAsync(r)];case 2:return[2,u.sent()];case 3:if(c=u.sent(),this.secondaryDecoder)return[2,this.secondaryDecoder.decodeAsync(r)];throw c;case 4:return this.possiblyLogPerformance(o),[7];case 5:return[2]}})})},t.prototype.getDecoder=function(){return this.secondaryDecoder?this.wasPrimaryDecoderUsedInLastDecode===!1?(this.wasPrimaryDecoderUsedInLastDecode=!0,this.primaryDecoder):(this.wasPrimaryDecoderUsedInLastDecode=!1,this.secondaryDecoder):this.primaryDecoder},t.prototype.possiblyLogPerformance=function(r){if(this.verbose){var o=performance.now()-r;this.executionResults.push(o),this.executions++,this.possiblyFlushPerformanceReport()}},t.prototype.possiblyFlushPerformanceReport=function(){if(!(this.executions<this.EXECUTIONS_TO_REPORT_PERFORMANCE)){for(var r=0,o=0,c=this.executionResults;o<c.length;o++){var u=c[o];r+=u}var f=r/this.executionResults.length;console.log("".concat(f," ms for ").concat(this.executionResults.length," last runs.")),this.executions=0,this.executionResults=[]}},t})(),rs=(function(){var t=function(r,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,u){c.__proto__=u}||function(c,u){for(var f in u)Object.prototype.hasOwnProperty.call(u,f)&&(c[f]=u[f])},t(r,o)};return function(r,o){if(typeof o!="function"&&o!==null)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");t(r,o);function c(){this.constructor=r}r.prototype=o===null?Object.create(o):(c.prototype=o.prototype,new c)}})(),Li=function(t,r,o,c){function u(f){return f instanceof o?f:new o(function(p){p(f)})}return new(o||(o=Promise))(function(f,p){function x(A){try{m(c.next(A))}catch(E){p(E)}}function y(A){try{m(c.throw(A))}catch(E){p(E)}}function m(A){A.done?f(A.value):u(A.value).then(x,y)}m((c=c.apply(t,r||[])).next())})},Fi=function(t,r){var o={label:0,sent:function(){if(f[0]&1)throw f[1];return f[1]},trys:[],ops:[]},c,u,f,p;return p={next:x(0),throw:x(1),return:x(2)},typeof Symbol=="function"&&(p[Symbol.iterator]=function(){return this}),p;function x(m){return function(A){return y([m,A])}}function y(m){if(c)throw new TypeError("Generator is already executing.");for(;p&&(p=0,m[0]&&(o=0)),o;)try{if(c=1,u&&(f=m[0]&2?u.return:m[0]?u.throw||((f=u.return)&&f.call(u),0):u.next)&&!(f=f.call(u,m[1])).done)return f;switch(u=0,f&&(m=[m[0]&2,f.value]),m[0]){case 0:case 1:f=m;break;case 4:return o.label++,{value:m[1],done:!1};case 5:o.label++,u=m[1],m=[0];continue;case 7:m=o.ops.pop(),o.trys.pop();continue;default:if(f=o.trys,!(f=f.length>0&&f[f.length-1])&&(m[0]===6||m[0]===2)){o=0;continue}if(m[0]===3&&(!f||m[1]>f[0]&&m[1]<f[3])){o.label=m[1];break}if(m[0]===6&&o.label<f[1]){o.label=f[1],f=m;break}if(f&&o.label<f[2]){o.label=f[2],o.ops.push(m);break}f[2]&&o.ops.pop(),o.trys.pop();continue}m=r.call(t,o)}catch(A){m=[6,A],u=0}finally{c=f=0}if(m[0]&5)throw m[1];return{value:m[0]?m[1]:void 0,done:!0}}},ju=(function(){function t(r,o){this.name=r,this.track=o}return t.prototype.isSupported=function(){return this.track.getCapabilities?this.name in this.track.getCapabilities():!1},t.prototype.apply=function(r){var o={};o[this.name]=r;var c={advanced:[o]};return this.track.applyConstraints(c)},t.prototype.value=function(){var r=this.track.getSettings();if(this.name in r){var o=r[this.name];return o}return null},t})(),Qw=(function(t){rs(r,t);function r(o,c){return t.call(this,o,c)||this}return r.prototype.min=function(){return this.getCapabilities().min},r.prototype.max=function(){return this.getCapabilities().max},r.prototype.step=function(){return this.getCapabilities().step},r.prototype.apply=function(o){var c={};c[this.name]=o;var u={advanced:[c]};return this.track.applyConstraints(u)},r.prototype.getCapabilities=function(){this.failIfNotSupported();var o=this.track.getCapabilities(),c=o[this.name];return{min:c.min,max:c.max,step:c.step}},r.prototype.failIfNotSupported=function(){if(!this.isSupported())throw new Error("".concat(this.name," capability not supported"))},r})(ju),ey=(function(t){rs(r,t);function r(o){return t.call(this,"zoom",o)||this}return r})(Qw),ty=(function(t){rs(r,t);function r(o){return t.call(this,"torch",o)||this}return r})(ju),ny=(function(){function t(r){this.track=r}return t.prototype.zoomFeature=function(){return new ey(this.track)},t.prototype.torchFeature=function(){return new ty(this.track)},t})(),ry=(function(){function t(r,o,c){this.isClosed=!1,this.parentElement=r,this.mediaStream=o,this.callbacks=c,this.surface=this.createVideoElement(this.parentElement.clientWidth),r.append(this.surface)}return t.prototype.createVideoElement=function(r){var o=document.createElement("video");return o.style.width="".concat(r,"px"),o.style.display="block",o.muted=!0,o.setAttribute("muted","true"),o.playsInline=!0,o},t.prototype.setupSurface=function(){var r=this;this.surface.onabort=function(){throw"RenderedCameraImpl video surface onabort() called"},this.surface.onerror=function(){throw"RenderedCameraImpl video surface onerror() called"};var o=function(){var c=r.surface.clientWidth,u=r.surface.clientHeight;r.callbacks.onRenderSurfaceReady(c,u),r.surface.removeEventListener("playing",o)};this.surface.addEventListener("playing",o),this.surface.srcObject=this.mediaStream,this.surface.play()},t.create=function(r,o,c,u){return Li(this,void 0,void 0,function(){var f,p;return Fi(this,function(x){switch(x.label){case 0:return f=new t(r,o,u),c.aspectRatio?(p={aspectRatio:c.aspectRatio},[4,f.getFirstTrackOrFail().applyConstraints(p)]):[3,2];case 1:x.sent(),x.label=2;case 2:return f.setupSurface(),[2,f]}})})},t.prototype.failIfClosed=function(){if(this.isClosed)throw"The RenderedCamera has already been closed."},t.prototype.getFirstTrackOrFail=function(){if(this.failIfClosed(),this.mediaStream.getVideoTracks().length===0)throw"No video tracks found";return this.mediaStream.getVideoTracks()[0]},t.prototype.pause=function(){this.failIfClosed(),this.surface.pause()},t.prototype.resume=function(r){this.failIfClosed();var o=this,c=function(){setTimeout(r,200),o.surface.removeEventListener("playing",c)};this.surface.addEventListener("playing",c),this.surface.play()},t.prototype.isPaused=function(){return this.failIfClosed(),this.surface.paused},t.prototype.getSurface=function(){return this.failIfClosed(),this.surface},t.prototype.getRunningTrackCapabilities=function(){return this.getFirstTrackOrFail().getCapabilities()},t.prototype.getRunningTrackSettings=function(){return this.getFirstTrackOrFail().getSettings()},t.prototype.applyVideoConstraints=function(r){return Li(this,void 0,void 0,function(){return Fi(this,function(o){if("aspectRatio"in r)throw"Changing 'aspectRatio' in run-time is not yet supported.";return[2,this.getFirstTrackOrFail().applyConstraints(r)]})})},t.prototype.close=function(){if(this.isClosed)return Promise.resolve();var r=this;return new Promise(function(o,c){var u=r.mediaStream.getVideoTracks(),f=u.length,p=0;r.mediaStream.getVideoTracks().forEach(function(x){r.mediaStream.removeTrack(x),x.stop(),++p,p>=f&&(r.isClosed=!0,r.parentElement.removeChild(r.surface),o())})})},t.prototype.getCapabilities=function(){return new ny(this.getFirstTrackOrFail())},t})(),iy=(function(){function t(r){this.mediaStream=r}return t.prototype.render=function(r,o,c){return Li(this,void 0,void 0,function(){return Fi(this,function(u){return[2,ry.create(r,this.mediaStream,o,c)]})})},t.create=function(r){return Li(this,void 0,void 0,function(){var o,c;return Fi(this,function(u){switch(u.label){case 0:if(!navigator.mediaDevices)throw"navigator.mediaDevices not supported";return o={audio:!1,video:r},[4,navigator.mediaDevices.getUserMedia(o)];case 1:return c=u.sent(),[2,new t(c)]}})})},t})(),ul=function(t,r,o,c){function u(f){return f instanceof o?f:new o(function(p){p(f)})}return new(o||(o=Promise))(function(f,p){function x(A){try{m(c.next(A))}catch(E){p(E)}}function y(A){try{m(c.throw(A))}catch(E){p(E)}}function m(A){A.done?f(A.value):u(A.value).then(x,y)}m((c=c.apply(t,r||[])).next())})},dl=function(t,r){var o={label:0,sent:function(){if(f[0]&1)throw f[1];return f[1]},trys:[],ops:[]},c,u,f,p;return p={next:x(0),throw:x(1),return:x(2)},typeof Symbol=="function"&&(p[Symbol.iterator]=function(){return this}),p;function x(m){return function(A){return y([m,A])}}function y(m){if(c)throw new TypeError("Generator is already executing.");for(;p&&(p=0,m[0]&&(o=0)),o;)try{if(c=1,u&&(f=m[0]&2?u.return:m[0]?u.throw||((f=u.return)&&f.call(u),0):u.next)&&!(f=f.call(u,m[1])).done)return f;switch(u=0,f&&(m=[m[0]&2,f.value]),m[0]){case 0:case 1:f=m;break;case 4:return o.label++,{value:m[1],done:!1};case 5:o.label++,u=m[1],m=[0];continue;case 7:m=o.ops.pop(),o.trys.pop();continue;default:if(f=o.trys,!(f=f.length>0&&f[f.length-1])&&(m[0]===6||m[0]===2)){o=0;continue}if(m[0]===3&&(!f||m[1]>f[0]&&m[1]<f[3])){o.label=m[1];break}if(m[0]===6&&o.label<f[1]){o.label=f[1],f=m;break}if(f&&o.label<f[2]){o.label=f[2],o.ops.push(m);break}f[2]&&o.ops.pop(),o.trys.pop();continue}m=r.call(t,o)}catch(A){m=[6,A],u=0}finally{c=f=0}if(m[0]&5)throw m[1];return{value:m[0]?m[1]:void 0,done:!0}}},oy=(function(){function t(){}return t.failIfNotSupported=function(){return ul(this,void 0,void 0,function(){return dl(this,function(r){if(!navigator.mediaDevices)throw"navigator.mediaDevices not supported";return[2,new t]})})},t.prototype.create=function(r){return ul(this,void 0,void 0,function(){return dl(this,function(o){return[2,iy.create(r)]})})},t})(),sy=function(t,r,o,c){function u(f){return f instanceof o?f:new o(function(p){p(f)})}return new(o||(o=Promise))(function(f,p){function x(A){try{m(c.next(A))}catch(E){p(E)}}function y(A){try{m(c.throw(A))}catch(E){p(E)}}function m(A){A.done?f(A.value):u(A.value).then(x,y)}m((c=c.apply(t,r||[])).next())})},ay=function(t,r){var o={label:0,sent:function(){if(f[0]&1)throw f[1];return f[1]},trys:[],ops:[]},c,u,f,p;return p={next:x(0),throw:x(1),return:x(2)},typeof Symbol=="function"&&(p[Symbol.iterator]=function(){return this}),p;function x(m){return function(A){return y([m,A])}}function y(m){if(c)throw new TypeError("Generator is already executing.");for(;p&&(p=0,m[0]&&(o=0)),o;)try{if(c=1,u&&(f=m[0]&2?u.return:m[0]?u.throw||((f=u.return)&&f.call(u),0):u.next)&&!(f=f.call(u,m[1])).done)return f;switch(u=0,f&&(m=[m[0]&2,f.value]),m[0]){case 0:case 1:f=m;break;case 4:return o.label++,{value:m[1],done:!1};case 5:o.label++,u=m[1],m=[0];continue;case 7:m=o.ops.pop(),o.trys.pop();continue;default:if(f=o.trys,!(f=f.length>0&&f[f.length-1])&&(m[0]===6||m[0]===2)){o=0;continue}if(m[0]===3&&(!f||m[1]>f[0]&&m[1]<f[3])){o.label=m[1];break}if(m[0]===6&&o.label<f[1]){o.label=f[1],f=m;break}if(f&&o.label<f[2]){o.label=f[2],o.ops.push(m);break}f[2]&&o.ops.pop(),o.trys.pop();continue}m=r.call(t,o)}catch(A){m=[6,A],u=0}finally{c=f=0}if(m[0]&5)throw m[1];return{value:m[0]?m[1]:void 0,done:!0}}},ly=(function(){function t(){}return t.retrieve=function(){if(navigator.mediaDevices)return t.getCamerasFromMediaDevices();var r=MediaStreamTrack;return MediaStreamTrack&&r.getSources?t.getCamerasFromMediaStreamTrack():t.rejectWithError()},t.rejectWithError=function(){var r=Er.unableToQuerySupportedDevices();return t.isHttpsOrLocalhost()||(r=Er.insecureContextCameraQueryError()),Promise.reject(r)},t.isHttpsOrLocalhost=function(){if(location.protocol==="https:")return!0;var r=location.host.split(":")[0];return r==="127.0.0.1"||r==="localhost"},t.getCamerasFromMediaDevices=function(){return sy(this,void 0,void 0,function(){var r,o,c,u,f,p,x;return ay(this,function(y){switch(y.label){case 0:return r=function(m){for(var A=m.getVideoTracks(),E=0,B=A;E<B.length;E++){var D=B[E];D.enabled=!1,D.stop(),m.removeTrack(D)}},[4,navigator.mediaDevices.getUserMedia({audio:!1,video:!0})];case 1:return o=y.sent(),[4,navigator.mediaDevices.enumerateDevices()];case 2:for(c=y.sent(),u=[],f=0,p=c;f<p.length;f++)x=p[f],x.kind==="videoinput"&&u.push({id:x.deviceId,label:x.label});return r(o),[2,u]}})})},t.getCamerasFromMediaStreamTrack=function(){return new Promise(function(r,o){var c=function(f){for(var p=[],x=0,y=f;x<y.length;x++){var m=y[x];m.kind==="video"&&p.push({id:m.id,label:m.label})}r(p)},u=MediaStreamTrack;u.getSources(c)})},t})(),bt;(function(t){t[t.UNKNOWN=0]="UNKNOWN",t[t.NOT_STARTED=1]="NOT_STARTED",t[t.SCANNING=2]="SCANNING",t[t.PAUSED=3]="PAUSED"})(bt||(bt={}));var cy=(function(){function t(){this.state=bt.NOT_STARTED,this.onGoingTransactionNewState=bt.UNKNOWN}return t.prototype.directTransition=function(r){this.failIfTransitionOngoing(),this.validateTransition(r),this.state=r},t.prototype.startTransition=function(r){return this.failIfTransitionOngoing(),this.validateTransition(r),this.onGoingTransactionNewState=r,this},t.prototype.execute=function(){if(this.onGoingTransactionNewState===bt.UNKNOWN)throw"Transaction is already cancelled, cannot execute().";var r=this.onGoingTransactionNewState;this.onGoingTransactionNewState=bt.UNKNOWN,this.directTransition(r)},t.prototype.cancel=function(){if(this.onGoingTransactionNewState===bt.UNKNOWN)throw"Transaction is already cancelled, cannot cancel().";this.onGoingTransactionNewState=bt.UNKNOWN},t.prototype.getState=function(){return this.state},t.prototype.failIfTransitionOngoing=function(){if(this.onGoingTransactionNewState!==bt.UNKNOWN)throw"Cannot transition to a new state, already under transition"},t.prototype.validateTransition=function(r){switch(this.state){case bt.UNKNOWN:throw"Transition from unknown is not allowed";case bt.NOT_STARTED:this.failIfNewStateIs(r,[bt.PAUSED]);break;case bt.SCANNING:break;case bt.PAUSED:break}},t.prototype.failIfNewStateIs=function(r,o){for(var c=0,u=o;c<u.length;c++){var f=u[c];if(r===f)throw"Cannot transition from ".concat(this.state," to ").concat(r)}},t})(),uy=(function(){function t(r){this.stateManager=r}return t.prototype.startTransition=function(r){return this.stateManager.startTransition(r)},t.prototype.directTransition=function(r){this.stateManager.directTransition(r)},t.prototype.getState=function(){return this.stateManager.getState()},t.prototype.canScanFile=function(){return this.stateManager.getState()===bt.NOT_STARTED},t.prototype.isScanning=function(){return this.stateManager.getState()!==bt.NOT_STARTED},t.prototype.isStrictlyScanning=function(){return this.stateManager.getState()===bt.SCANNING},t.prototype.isPaused=function(){return this.stateManager.getState()===bt.PAUSED},t})(),dy=(function(){function t(){}return t.create=function(){return new uy(new cy)},t})(),fy=(function(){var t=function(r,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,u){c.__proto__=u}||function(c,u){for(var f in u)Object.prototype.hasOwnProperty.call(u,f)&&(c[f]=u[f])},t(r,o)};return function(r,o){if(typeof o!="function"&&o!==null)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");t(r,o);function c(){this.constructor=r}r.prototype=o===null?Object.create(o):(c.prototype=o.prototype,new c)}})(),nn=(function(t){fy(r,t);function r(){return t!==null&&t.apply(this,arguments)||this}return r.DEFAULT_WIDTH=300,r.DEFAULT_WIDTH_OFFSET=2,r.FILE_SCAN_MIN_HEIGHT=300,r.FILE_SCAN_HIDDEN_CANVAS_PADDING=100,r.MIN_QR_BOX_SIZE=50,r.SHADED_LEFT=1,r.SHADED_RIGHT=2,r.SHADED_TOP=3,r.SHADED_BOTTOM=4,r.SHADED_REGION_ELEMENT_ID="qr-shaded-region",r.VERBOSE=!1,r.BORDER_SHADER_DEFAULT_COLOR="#ffffff",r.BORDER_SHADER_MATCH_COLOR="rgb(90, 193, 56)",r})(Zw),hy=(function(){function t(r,o){this.logger=o,this.fps=nn.SCAN_DEFAULT_FPS,r?(r.fps&&(this.fps=r.fps),this.disableFlip=r.disableFlip===!0,this.qrbox=r.qrbox,this.aspectRatio=r.aspectRatio,this.videoConstraints=r.videoConstraints):this.disableFlip=nn.DEFAULT_DISABLE_FLIP}return t.prototype.isMediaStreamConstraintsValid=function(){return this.videoConstraints?Zu.isMediaStreamConstraintsValid(this.videoConstraints,this.logger):(this.logger.logError("Empty videoConstraints",!0),!1)},t.prototype.isShadedBoxEnabled=function(){return!kn(this.qrbox)},t.create=function(r,o){return new t(r,o)},t})(),fl=(function(){function t(r,o){if(this.element=null,this.canvasElement=null,this.scannerPausedUiElement=null,this.hasBorderShaders=null,this.borderShaders=null,this.qrMatch=null,this.renderedCamera=null,this.qrRegion=null,this.context=null,this.lastScanImageFile=null,this.isScanning=!1,!document.getElementById(r))throw"HTML Element with id=".concat(r," not found");this.elementId=r,this.verbose=!1;var c;typeof o=="boolean"?this.verbose=o===!0:o&&(c=o,this.verbose=c.verbose===!0,c.experimentalFeatures),this.logger=new Hw(this.verbose),this.qrcode=new Kw(this.getSupportedFormats(o),this.getUseBarCodeDetectorIfSupported(c),this.verbose,this.logger),this.foreverScanTimeout,this.shouldScan=!0,this.stateManagerProxy=dy.create()}return t.prototype.start=function(r,o,c,u){var f=this;if(!r)throw"cameraIdOrConfig is required";if(!c||typeof c!="function")throw"qrCodeSuccessCallback is required and should be a function.";var p;u?p=u:p=this.verbose?this.logger.log:function(){};var x=hy.create(o,this.logger);this.clearElement();var y=!1;x.videoConstraints&&(x.isMediaStreamConstraintsValid()?y=!0:this.logger.logError("'videoConstraints' is not valid 'MediaStreamConstraints, it will be ignored.'",!0));var m=y,A=document.getElementById(this.elementId);A.clientWidth?A.clientWidth:nn.DEFAULT_WIDTH,A.style.position="relative",this.shouldScan=!0,this.element=A;var E=this,B=this.stateManagerProxy.startTransition(bt.SCANNING);return new Promise(function(D,M){var R=m?x.videoConstraints:E.createVideoConstraints(r);if(!R){B.cancel(),M("videoConstraints should be defined");return}var k={};(!m||x.aspectRatio)&&(k.aspectRatio=x.aspectRatio);var q={onRenderSurfaceReady:function(Z,z){E.setupUi(Z,z,x),E.isScanning=!0,E.foreverScan(x,c,p)}};oy.failIfNotSupported().then(function(Z){Z.create(R).then(function(z){return z.render(f.element,k,q).then(function($){E.renderedCamera=$,B.execute(),D(null)}).catch(function($){B.cancel(),M($)})}).catch(function(z){B.cancel(),M(Er.errorGettingUserMedia(z))})}).catch(function(Z){B.cancel(),M(Er.cameraStreamingNotSupported())})})},t.prototype.pause=function(r){if(!this.stateManagerProxy.isStrictlyScanning())throw"Cannot pause, scanner is not scanning.";this.stateManagerProxy.directTransition(bt.PAUSED),this.showPausedState(),(kn(r)||r!==!0)&&(r=!1),r&&this.renderedCamera&&this.renderedCamera.pause()},t.prototype.resume=function(){if(!this.stateManagerProxy.isPaused())throw"Cannot result, scanner is not paused.";if(!this.renderedCamera)throw"renderedCamera doesn't exist while trying resume()";var r=this,o=function(){r.stateManagerProxy.directTransition(bt.SCANNING),r.hidePausedState()};if(!this.renderedCamera.isPaused()){o();return}this.renderedCamera.resume(function(){o()})},t.prototype.getState=function(){return this.stateManagerProxy.getState()},t.prototype.stop=function(){var r=this;if(!this.stateManagerProxy.isScanning())throw"Cannot stop, scanner is not running or paused.";var o=this.stateManagerProxy.startTransition(bt.NOT_STARTED);this.shouldScan=!1,this.foreverScanTimeout&&clearTimeout(this.foreverScanTimeout);var c=function(){if(r.element){var f=document.getElementById(nn.SHADED_REGION_ELEMENT_ID);f&&r.element.removeChild(f)}},u=this;return this.renderedCamera.close().then(function(){return u.renderedCamera=null,u.element&&(u.element.removeChild(u.canvasElement),u.canvasElement=null),c(),u.qrRegion&&(u.qrRegion=null),u.context&&(u.context=null),o.execute(),u.hidePausedState(),u.isScanning=!1,Promise.resolve()})},t.prototype.scanFile=function(r,o){return this.scanFileV2(r,o).then(function(c){return c.decodedText})},t.prototype.scanFileV2=function(r,o){var c=this;if(!r||!(r instanceof File))throw"imageFile argument is mandatory and should be instance of File. Use 'event.target.files[0]'.";if(kn(o)&&(o=!0),!this.stateManagerProxy.canScanFile())throw"Cannot start file scan - ongoing camera scan";return new Promise(function(u,f){c.possiblyCloseLastScanImageFile(),c.clearElement(),c.lastScanImageFile=URL.createObjectURL(r);var p=new Image;p.onload=function(){var x=p.width,y=p.height,m=document.getElementById(c.elementId),A=m.clientWidth?m.clientWidth:nn.DEFAULT_WIDTH,E=Math.max(m.clientHeight?m.clientHeight:y,nn.FILE_SCAN_MIN_HEIGHT),B=c.computeCanvasDrawConfig(x,y,A,E);if(o){var D=c.createCanvasElement(A,E,"qr-canvas-visible");D.style.display="inline-block",m.appendChild(D);var M=D.getContext("2d");if(!M)throw"Unable to get 2d context from canvas";M.canvas.width=A,M.canvas.height=E,M.drawImage(p,0,0,x,y,B.x,B.y,B.width,B.height)}var R=nn.FILE_SCAN_HIDDEN_CANVAS_PADDING,k=Math.max(p.width,B.width),q=Math.max(p.height,B.height),Z=k+2*R,z=q+2*R,$=c.createCanvasElement(Z,z);m.appendChild($);var Q=$.getContext("2d");if(!Q)throw"Unable to get 2d context from canvas";Q.canvas.width=Z,Q.canvas.height=z,Q.drawImage(p,0,0,x,y,R,R,k,q);try{c.qrcode.decodeRobustlyAsync($).then(function(O){u(il.createFromQrcodeResult(O))}).catch(f)}catch(O){f("QR code parse error, error = ".concat(O))}},p.onerror=f,p.onabort=f,p.onstalled=f,p.onsuspend=f,p.src=URL.createObjectURL(r)})},t.prototype.clear=function(){this.clearElement()},t.getCameras=function(){return ly.retrieve()},t.prototype.getRunningTrackCapabilities=function(){return this.getRenderedCameraOrFail().getRunningTrackCapabilities()},t.prototype.getRunningTrackSettings=function(){return this.getRenderedCameraOrFail().getRunningTrackSettings()},t.prototype.getRunningTrackCameraCapabilities=function(){return this.getRenderedCameraOrFail().getCapabilities()},t.prototype.applyVideoConstraints=function(r){if(r){if(!Zu.isMediaStreamConstraintsValid(r,this.logger))throw"invalid videoConstaints passed, check logs for more details"}else throw"videoConstaints is required argument.";return this.getRenderedCameraOrFail().applyVideoConstraints(r)},t.prototype.getRenderedCameraOrFail=function(){if(this.renderedCamera==null)throw"Scanning is not in running state, call this API only when QR code scanning using camera is in running state.";return this.renderedCamera},t.prototype.getSupportedFormats=function(r){var o=[Ce.QR_CODE,Ce.AZTEC,Ce.CODABAR,Ce.CODE_39,Ce.CODE_93,Ce.CODE_128,Ce.DATA_MATRIX,Ce.MAXICODE,Ce.ITF,Ce.EAN_13,Ce.EAN_8,Ce.PDF_417,Ce.RSS_14,Ce.RSS_EXPANDED,Ce.UPC_A,Ce.UPC_E,Ce.UPC_EAN_EXTENSION];if(!r||typeof r=="boolean"||!r.formatsToSupport)return o;if(!Array.isArray(r.formatsToSupport))throw"configOrVerbosityFlag.formatsToSupport should be undefined or an array.";if(r.formatsToSupport.length===0)throw"Atleast 1 formatsToSupport is needed.";for(var c=[],u=0,f=r.formatsToSupport;u<f.length;u++){var p=f[u];$w(p)?c.push(p):this.logger.warn("Invalid format: ".concat(p," passed in config, ignoring."))}if(c.length===0)throw"None of formatsToSupport match supported values.";return c},t.prototype.getUseBarCodeDetectorIfSupported=function(r){if(kn(r))return!0;if(!kn(r.useBarCodeDetectorIfSupported))return r.useBarCodeDetectorIfSupported!==!1;if(kn(r.experimentalFeatures))return!0;var o=r.experimentalFeatures;return kn(o.useBarCodeDetectorIfSupported)?!0:o.useBarCodeDetectorIfSupported!==!1},t.prototype.validateQrboxSize=function(r,o,c){var u=this,f=c.qrbox;this.validateQrboxConfig(f);var p=this.toQrdimensions(r,o,f),x=function(m){if(m<nn.MIN_QR_BOX_SIZE)throw"minimum size of 'config.qrbox' dimension value is"+" ".concat(nn.MIN_QR_BOX_SIZE,"px.")},y=function(m){return m>r&&(u.logger.warn("`qrbox.width` or `qrbox` is larger than the width of the root element. The width will be truncated to the width of root element."),m=r),m};x(p.width),x(p.height),p.width=y(p.width)},t.prototype.validateQrboxConfig=function(r){if(typeof r!="number"&&typeof r!="function"&&(r.width===void 0||r.height===void 0))throw"Invalid instance of QrDimensions passed for 'config.qrbox'. Both 'width' and 'height' should be set."},t.prototype.toQrdimensions=function(r,o,c){if(typeof c=="number")return{width:c,height:c};if(typeof c=="function")try{return c(r,o)}catch(u){throw new Error("qrbox config was passed as a function but it failed with unknown error"+u)}return c},t.prototype.setupUi=function(r,o,c){c.isShadedBoxEnabled()&&this.validateQrboxSize(r,o,c);var u=kn(c.qrbox)?{width:r,height:o}:c.qrbox;this.validateQrboxConfig(u);var f=this.toQrdimensions(r,o,u);f.height>o&&this.logger.warn("[Html5Qrcode] config.qrbox has height that isgreater than the height of the video stream. Shading will be ignored");var p=c.isShadedBoxEnabled()&&f.height<=o,x={x:0,y:0,width:r,height:o},y=p?this.getShadedRegionBounds(r,o,f):x,m=this.createCanvasElement(y.width,y.height),A={willReadFrequently:!0},E=m.getContext("2d",A);E.canvas.width=y.width,E.canvas.height=y.height,this.element.append(m),p&&this.possiblyInsertShadingElement(this.element,r,o,f),this.createScannerPausedUiElement(this.element),this.qrRegion=y,this.context=E,this.canvasElement=m},t.prototype.createScannerPausedUiElement=function(r){var o=document.createElement("div");o.innerText=Er.scannerPaused(),o.style.display="none",o.style.position="absolute",o.style.top="0px",o.style.zIndex="1",o.style.background="rgba(9, 9, 9, 0.46)",o.style.color="#FFECEC",o.style.textAlign="center",o.style.width="100%",r.appendChild(o),this.scannerPausedUiElement=o},t.prototype.scanContext=function(r,o){var c=this;return this.stateManagerProxy.isPaused()?Promise.resolve(!1):this.qrcode.decodeAsync(this.canvasElement).then(function(u){return r(u.text,il.createFromQrcodeResult(u)),c.possiblyUpdateShaders(!0),!0}).catch(function(u){c.possiblyUpdateShaders(!1);var f=Er.codeParseError(u);return o(f,jw.createFrom(f)),!1})},t.prototype.foreverScan=function(r,o,c){var u=this;if(this.shouldScan&&this.renderedCamera){var f=this.renderedCamera.getSurface(),p=f.videoWidth/f.clientWidth,x=f.videoHeight/f.clientHeight;if(!this.qrRegion)throw"qrRegion undefined when localMediaStream is ready.";var y=this.qrRegion.width*p,m=this.qrRegion.height*x,A=this.qrRegion.x*p,E=this.qrRegion.y*x;this.context.drawImage(f,A,E,y,m,0,0,this.qrRegion.width,this.qrRegion.height);var B=function(){u.foreverScanTimeout=setTimeout(function(){u.foreverScan(r,o,c)},u.getTimeoutFps(r.fps))};this.scanContext(o,c).then(function(D){!D&&r.disableFlip!==!0?(u.context.translate(u.context.canvas.width,0),u.context.scale(-1,1),u.scanContext(o,c).finally(function(){B()})):B()}).catch(function(D){u.logger.logError("Error happend while scanning context",D),B()})}},t.prototype.createVideoConstraints=function(r){if(typeof r=="string")return{deviceId:{exact:r}};if(typeof r=="object"){var o="facingMode",c="deviceId",u={user:!0,environment:!0},f="exact",p=function(M){if(M in u)return!0;throw"config has invalid 'facingMode' value = "+"'".concat(M,"'")},x=Object.keys(r);if(x.length!==1)throw"'cameraIdOrConfig' object should have exactly 1 key,"+" if passed as an object, found ".concat(x.length," keys");var y=Object.keys(r)[0];if(y!==o&&y!==c)throw"Only '".concat(o,"' and '").concat(c,"' ")+" are supported for 'cameraIdOrConfig'";if(y===o){var m=r.facingMode;if(typeof m=="string"){if(p(m))return{facingMode:m}}else if(typeof m=="object")if(f in m){if(p(m["".concat(f)]))return{facingMode:{exact:m["".concat(f)]}}}else throw"'facingMode' should be string or object with"+" ".concat(f," as key.");else{var A=typeof m;throw"Invalid type of 'facingMode' = ".concat(A)}}else{var E=r.deviceId;if(typeof E=="string")return{deviceId:E};if(typeof E=="object"){if(f in E)return{deviceId:{exact:E["".concat(f)]}};throw"'deviceId' should be string or object with"+" ".concat(f," as key.")}else{var B=typeof E;throw"Invalid type of 'deviceId' = ".concat(B)}}}var D=typeof r;throw"Invalid type of 'cameraIdOrConfig' = ".concat(D)},t.prototype.computeCanvasDrawConfig=function(r,o,c,u){if(r<=c&&o<=u){var f=(c-r)/2,p=(u-o)/2;return{x:f,y:p,width:r,height:o}}else{var x=r,y=o;return r>c&&(o=c/r*o,r=c),o>u&&(r=u/o*r,o=u),this.logger.log("Image downsampled from "+"".concat(x,"X").concat(y)+" to ".concat(r,"X").concat(o,".")),this.computeCanvasDrawConfig(r,o,c,u)}},t.prototype.clearElement=function(){if(this.stateManagerProxy.isScanning())throw"Cannot clear while scan is ongoing, close it first.";var r=document.getElementById(this.elementId);r&&(r.innerHTML="")},t.prototype.possiblyUpdateShaders=function(r){this.qrMatch!==r&&(this.hasBorderShaders&&this.borderShaders&&this.borderShaders.length&&this.borderShaders.forEach(function(o){o.style.backgroundColor=r?nn.BORDER_SHADER_MATCH_COLOR:nn.BORDER_SHADER_DEFAULT_COLOR}),this.qrMatch=r)},t.prototype.possiblyCloseLastScanImageFile=function(){this.lastScanImageFile&&(URL.revokeObjectURL(this.lastScanImageFile),this.lastScanImageFile=null)},t.prototype.createCanvasElement=function(r,o,c){var u=r,f=o,p=document.createElement("canvas");return p.style.width="".concat(u,"px"),p.style.height="".concat(f,"px"),p.style.display="none",p.id=kn(c)?"qr-canvas":c,p},t.prototype.getShadedRegionBounds=function(r,o,c){if(c.width>r||c.height>o)throw"'config.qrbox' dimensions should not be greater than the dimensions of the root HTML element.";return{x:(r-c.width)/2,y:(o-c.height)/2,width:c.width,height:c.height}},t.prototype.possiblyInsertShadingElement=function(r,o,c,u){if(!(o-u.width<1||c-u.height<1)){var f=document.createElement("div");f.style.position="absolute";var p=(o-u.width)/2,x=(c-u.height)/2;if(f.style.borderLeft="".concat(p,"px solid rgba(0, 0, 0, 0.48)"),f.style.borderRight="".concat(p,"px solid rgba(0, 0, 0, 0.48)"),f.style.borderTop="".concat(x,"px solid rgba(0, 0, 0, 0.48)"),f.style.borderBottom="".concat(x,"px solid rgba(0, 0, 0, 0.48)"),f.style.boxSizing="border-box",f.style.top="0px",f.style.bottom="0px",f.style.left="0px",f.style.right="0px",f.id="".concat(nn.SHADED_REGION_ELEMENT_ID),o-u.width<11||c-u.height<11)this.hasBorderShaders=!1;else{var y=5,m=40;this.insertShaderBorders(f,m,y,-y,null,0,!0),this.insertShaderBorders(f,m,y,-y,null,0,!1),this.insertShaderBorders(f,m,y,null,-y,0,!0),this.insertShaderBorders(f,m,y,null,-y,0,!1),this.insertShaderBorders(f,y,m+y,-y,null,-y,!0),this.insertShaderBorders(f,y,m+y,null,-y,-y,!0),this.insertShaderBorders(f,y,m+y,-y,null,-y,!1),this.insertShaderBorders(f,y,m+y,null,-y,-y,!1),this.hasBorderShaders=!0}r.append(f)}},t.prototype.insertShaderBorders=function(r,o,c,u,f,p,x){var y=document.createElement("div");y.style.position="absolute",y.style.backgroundColor=nn.BORDER_SHADER_DEFAULT_COLOR,y.style.width="".concat(o,"px"),y.style.height="".concat(c,"px"),u!==null&&(y.style.top="".concat(u,"px")),f!==null&&(y.style.bottom="".concat(f,"px")),x?y.style.left="".concat(p,"px"):y.style.right="".concat(p,"px"),this.borderShaders||(this.borderShaders=[]),this.borderShaders.push(y),r.appendChild(y)},t.prototype.showPausedState=function(){if(!this.scannerPausedUiElement)throw"[internal error] scanner paused UI element not found";this.scannerPausedUiElement.style.display="block"},t.prototype.hidePausedState=function(){if(!this.scannerPausedUiElement)throw"[internal error] scanner paused UI element not found";this.scannerPausedUiElement.style.display="none"},t.prototype.getTimeoutFps=function(r){return 1e3/r},t})(),hl;(function(t){t[t.STATUS_DEFAULT=0]="STATUS_DEFAULT",t[t.STATUS_SUCCESS=1]="STATUS_SUCCESS",t[t.STATUS_WARNING=2]="STATUS_WARNING",t[t.STATUS_REQUESTING_PERMISSION=3]="STATUS_REQUESTING_PERMISSION"})(hl||(hl={}));const py={class:"scan-code"},gy={class:"btn"},my={class:"left-back"},xy=v.defineComponent({name:"QrCodeScan",__name:"QrCodeScan",emits:["scanSuccess"],setup(t,{emit:r}){const o=r,c=Ed.IconScan(),u=v.reactive({html5QrCode:null}),f=v.ref(!1),p=()=>{if(!u.html5QrCode){Ye("摄像头无访问权限!");return}f.value=!0,u.html5QrCode.start({facingMode:"environment"},{fps:30,aspectRatio:1,supportedScanTypes:[ei.SCAN_TYPE_CAMERA],showTorchButtonIfSupported:!0,showZoomSliderIfSupported:!0,defaultZoomValueIfSupported:2,useBarCodeDetectorIfSupported:!0},E=>{try{const D=new URL(E).searchParams.get("sessionId");D?o("scanSuccess",D):Ye("无效的二维码")}catch{Ye("无效的二维码")}A()}).catch(E=>{console.log(E),Ye({message:"二维码识别失败",duration:3e3})})},x=()=>{m().then(()=>{p()})},y=()=>{A()},m=()=>fl.getCameras().then(E=>{E&&E.length&&(u.html5QrCode=new fl("reader"))}).catch(()=>{Ye({message:"摄像头无访问权限!",duration:3e3})}),A=()=>{u.html5QrCode&&u.html5QrCode.stop().then(E=>{console.log("停止扫码",E)}).catch(E=>{console.log(E),Ye("停止扫码失败")}).finally(()=>{f.value=!1})};return v.onUnmounted(()=>{u.html5QrCode&&u.html5QrCode.isScanning&&A()}),(E,B)=>{const D=ns;return v.openBlock(),v.createElementBlock("div",null,[v.createVNode(v.unref(Pt.TrIconButton),{icon:v.unref(c),size:"28",svgSize:"20",onClick:B[0]||(B[0]=M=>x())},null,8,["icon"]),(v.openBlock(),v.createBlock(v.Teleport,{to:"body"},[v.withDirectives(v.createElementVNode("div",py,[B[1]||(B[1]=v.createElementVNode("div",{class:"container"},[v.createElementVNode("div",{class:"qrcode"},[v.createElementVNode("div",{id:"reader"})])],-1)),v.createElementVNode("div",gy,[v.createElementVNode("div",my,[v.createVNode(D,{name:"arrow-left",onClick:y})])])],512),[[v.vShow,f.value]])]))])}}}),wy=qn(xy,[["__scopeId","data-v-2d988579"]]);function is(t,r,o){const c=v.computed(()=>t?Array.isArray(t)?t:t.value:[]),u=()=>{const A=c.value;if(A.length===0)return"";if(r){const B=typeof r=="string"?r:r.value;if(B&&A.some(D=>D.id===B))return B}const E=A.find(B=>B.isDefault);return E?E.id:A[0].id};let f,p=!1;if(r&&typeof r!="string")f=r,p=!0,(!f.value||!c.value.some(A=>A.id===f.value))&&(f.value=u());else{let A;r&&typeof r=="string"&&(A=r),f=v.ref(A&&c.value.some(E=>E.id===A)?A:u())}(!p||o)&&v.watch(f,A=>{o&&o(A)});const x=v.computed(()=>c.value.find(A=>A.id===f.value)),y=v.computed(()=>c.value);return{selectedModelId:f,selectedModel:x,availableModels:y,setSelectedModel:A=>{c.value.find(B=>B.id===A)?f.value=A:console.warn(`[useModel] Model not found: ${A}`)}}}const yy=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const _y=Object.prototype.toString,vy=t=>_y.call(t)==="[object Object]",Ti=()=>{};function vo(t){return Array.isArray(t)?t:[t]}function Cy(t,r,o){return v.watch(t,r,{...o,immediate:!0})}const Hu=yy?window:void 0;function Hr(t){var r;const o=v.toValue(t);return(r=o?.$el)!==null&&r!==void 0?r:o}function Co(...t){const r=(c,u,f,p)=>(c.addEventListener(u,f,p),()=>c.removeEventListener(u,f,p)),o=v.computed(()=>{const c=vo(v.toValue(t[0])).filter(u=>u!=null);return c.every(u=>typeof u!="string")?c:void 0});return Cy(()=>{var c,u;return[(c=(u=o.value)===null||u===void 0?void 0:u.map(f=>Hr(f)))!==null&&c!==void 0?c:[Hu].filter(f=>f!=null),vo(v.toValue(o.value?t[1]:t[0])),vo(v.unref(o.value?t[2]:t[1])),v.toValue(o.value?t[3]:t[2])]},([c,u,f,p],x,y)=>{if(!c?.length||!u?.length||!f?.length)return;const m=vy(p)?{...p}:p,A=c.flatMap(E=>u.flatMap(B=>f.map(D=>r(E,B,D,m))));y(()=>{A.forEach(E=>E())})},{flush:"post"})}function by(t,r,o={}){const{window:c=Hu,ignore:u=[],capture:f=!0,detectIframe:p=!1,controls:x=!1}=o;if(!c)return x?{stop:Ti,cancel:Ti,trigger:Ti}:Ti;let y=!0;const m=k=>v.toValue(u).some(q=>{if(typeof q=="string")return Array.from(c.document.querySelectorAll(q)).some(Z=>Z===k.target||k.composedPath().includes(Z));{const Z=Hr(q);return Z&&(k.target===Z||k.composedPath().includes(Z))}});function A(k){const q=v.toValue(k);return q&&q.$.subTree.shapeFlag===16}function E(k,q){const Z=v.toValue(k),z=Z.$.subTree&&Z.$.subTree.children;return z==null||!Array.isArray(z)?!1:z.some($=>$.el===q.target||q.composedPath().includes($.el))}const B=k=>{const q=Hr(t);if(k.target!=null&&!(!(q instanceof Element)&&A(t)&&E(t,k))&&!(!q||q===k.target||k.composedPath().includes(q))){if("detail"in k&&k.detail===0&&(y=!m(k)),!y){y=!0;return}r(k)}};let D=!1;const M=[Co(c,"click",k=>{D||(D=!0,setTimeout(()=>{D=!1},0),B(k))},{passive:!0,capture:f}),Co(c,"pointerdown",k=>{const q=Hr(t);y=!m(k)&&!!(q&&!k.composedPath().includes(q))},{passive:!0}),p&&Co(c,"blur",k=>{setTimeout(()=>{var q;const Z=Hr(t);((q=c.document.activeElement)===null||q===void 0?void 0:q.tagName)==="IFRAME"&&!Z?.contains(c.document.activeElement)&&r(k)},0)},{passive:!0})].filter(Boolean),R=()=>M.forEach(k=>k());return x?{stop:R,cancel:()=>{y=!1},trigger:k=>{y=!0,B(k),y=!1}}:R}const Ey=["data-active","disabled"],Ay=v.defineComponent({__name:"Button",props:{active:{type:Boolean},rounded:{type:Boolean},size:{default:"medium"},disabled:{type:Boolean}},setup(t){return(r,o)=>(v.openBlock(),v.createElementBlock("button",{class:v.normalizeClass(["button",{rounded:t.rounded,[t.size]:!0}]),"data-active":t.active||void 0,disabled:t.disabled||void 0},[v.renderSlot(r.$slots,"default",{},void 0,!0)],10,Ey))}}),os=qn(Ay,[["__scopeId","data-v-6f582cce"]]),Iy={viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",fill:"none"};function Sy(t,r){return v.openBlock(),v.createElementBlock("svg",Iy,[...r[0]||(r[0]=[v.createElementVNode("rect",{id:"大模型",width:"16.000000",height:"16.000000",x:"0.000000",y:"0.000000"},null,-1),v.createElementVNode("path",{id:"矢量 90",d:"M13.683 2.26904C12.5753 1.16177 10.344 1.47577 8.02582 2.86527C5.70758 1.47576 3.47637 1.16179 2.36913 2.26904C1.2619 3.37646 1.57573 5.60771 2.96524 7.92589C1.57573 10.2441 1.2619 12.4754 2.36913 13.5827C3.47637 14.6901 5.7078 14.3762 8.02599 12.9867C10.344 14.3762 12.5752 14.6901 13.6825 13.5827C14.7901 12.4754 14.4761 10.2441 13.0866 7.92594C14.4761 5.60775 14.7902 3.37646 13.683 2.26904ZM10.8544 5.09764C11.4667 5.70995 12.0076 6.34819 12.4699 6.99044C12.7244 6.52061 12.9268 6.06037 13.077 5.60959C13.2948 4.95652 13.3832 4.38597 13.3426 3.89769C13.3089 3.49437 13.1869 3.18725 12.9754 2.97631C12.7645 2.76513 12.4574 2.64282 12.0541 2.60912C11.5658 2.56835 10.9955 2.65698 10.3422 2.87475C9.89153 3.02497 9.43121 3.22735 8.96135 3.48197C9.60365 3.94428 10.242 4.48527 10.8544 5.09764ZM5.70991 2.87475C6.16049 3.02494 6.62073 3.22729 7.09051 3.48185C6.44826 3.94412 5.81002 4.48507 5.19771 5.09739C4.58523 5.70982 4.04417 6.34819 3.58181 6.99055C3.32716 6.52071 3.1248 6.06037 2.97459 5.60959C2.75682 4.95677 2.66844 4.38597 2.70897 3.89769C2.74266 3.49437 2.86522 3.18725 3.07615 2.97631C3.28709 2.76513 3.59421 2.64282 3.99753 2.60912C4.4858 2.5686 5.0566 2.65698 5.70991 2.87475ZM5.90473 5.80466Q4.89236 6.81738 4.14938 7.92595C4.64428 8.66515 5.2294 9.3722 5.90473 10.0473C6.57966 10.7222 7.28696 11.3074 8.02584 11.8027C8.76507 11.3074 9.47197 10.7222 10.1474 10.0473C10.8222 9.37218 11.4074 8.66511 11.9027 7.92588Q11.1597 6.81736 10.1474 5.80466C9.47203 5.12956 8.7652 4.54447 8.02604 4.04937C7.28683 4.54447 6.5796 5.12956 5.90473 5.80466ZM7.99992 6.90011C7.44768 6.90011 6.99993 7.34787 6.99993 7.90011C6.99993 8.45235 7.44768 8.9001 7.99992 8.9001C8.55216 8.9001 8.99991 8.45235 8.99991 7.90011C8.99991 7.34787 8.55216 6.90011 7.99992 6.90011ZM10.3422 12.9772C9.89161 12.827 9.43138 12.6246 8.96148 12.37C9.60377 11.9077 10.242 11.3667 10.8544 10.7543C11.4667 10.142 12.0077 9.50369 12.4699 8.8614C12.7245 9.33127 12.9268 9.79154 13.077 10.2421C13.2948 10.8952 13.3832 11.4658 13.3426 11.954C13.3089 12.3574 13.1864 12.6647 12.9754 12.8757C12.7645 13.0866 12.4574 13.2089 12.0541 13.2426C11.5658 13.2834 10.995 13.195 10.3422 12.9772ZM2.97459 10.2421C3.12478 9.7914 3.32733 9.3312 3.58196 8.86141C4.04428 9.50369 4.5853 10.142 5.19771 10.7543C5.81003 11.3667 6.44827 11.9077 7.09052 12.37C6.62074 12.6246 6.16049 12.827 5.70991 12.9772C5.0566 13.195 4.48629 13.2834 3.99802 13.2426C3.5947 13.2089 3.28709 13.0866 3.07615 12.8757C2.86522 12.6647 2.74315 12.3574 2.70946 11.954C2.66844 11.4658 2.75682 10.8952 2.97459 10.2421Z",fill:"rgb(89,89,89)","fill-rule":"evenodd"},null,-1)])])}const Ty={render:Sy},Ny={class:"button-text"},Oy={class:"dropdown-menu__items"},ky=["onClick"],Ry=v.defineComponent({__name:"ModelSwitch",props:v.mergeModels({modelConfigs:{}},{selectedModelId:{type:String,default:void 0,required:!1},selectedModelIdModifiers:{}}),emits:["update:selectedModelId"],setup(t){const r=t,o=v.useModel(t,"selectedModelId"),c=r.modelConfigs?Array.isArray(r.modelConfigs)?v.shallowRef(r.modelConfigs):r.modelConfigs:void 0,{selectedModel:u,availableModels:f,setSelectedModel:p}=is(c,o),x=v.ref(!1),y=D=>{p(D),A()},m=()=>{x.value=!x.value},A=()=>{x.value=!1},E=v.ref(null),B=v.ref(null);return by(B,()=>{A()},{ignore:[E]}),(D,M)=>(v.openBlock(),v.createElementBlock("div",{class:"model-switch-wrapper",ref_key:"wrapperRef",ref:E},[v.createVNode(os,{size:"small",class:"action-button",rounded:"",onClick:m},{default:v.withCtx(()=>[(v.openBlock(),v.createBlock(v.resolveDynamicComponent(v.unref(u)?.icon),{width:16,height:16,class:"selected-model__icon"})),v.createElementVNode("span",Ny,v.toDisplayString(v.unref(u)?.label),1),v.createVNode(v.unref(Ty),{width:16,height:16})]),_:1}),v.createVNode(v.Transition,{name:"dropdown"},{default:v.withCtx(()=>[x.value?(v.openBlock(),v.createElementBlock("div",{key:0,class:"dropdown-menu",ref_key:"dropdownMenuRef",ref:B},[v.createElementVNode("div",Oy,[(v.openBlock(!0),v.createElementBlock(v.Fragment,null,v.renderList(v.unref(f),R=>(v.openBlock(),v.createElementBlock("div",{key:R.id,class:v.normalizeClass(["dropdown-menu__item",{"active-menu":R.id===o.value}]),onClick:v.withModifiers(k=>y(R.id),["stop"])},[R.icon?(v.openBlock(),v.createBlock(v.resolveDynamicComponent(R.icon),{key:0,width:16,height:16,class:"dropdown-menu__icon"})):v.createCommentVNode("",!0),v.createElementVNode("span",null,v.toDisplayString(R.label),1)],10,ky))),128))])],512)):v.createCommentVNode("",!0)]),_:1}),x.value?(v.openBlock(),v.createElementBlock("div",{key:0,class:"dropdown-overlay",onClick:A})):v.createCommentVNode("",!0)],512))}}),My=qn(Ry,[["__scopeId","data-v-cee7e07b"]]),Dy={key:0,class:"active-count"},Py=v.defineComponent({__name:"PluginToggleButton",props:{installedPlugins:{}},emits:["click"],setup(t){const r=t,o=v.computed(()=>r.installedPlugins.filter(c=>c.enabled).length);return(c,u)=>(v.openBlock(),v.createBlock(os,{size:"small",class:"action-button",active:o.value>0,rounded:"",onClick:u[0]||(u[0]=f=>c.$emit("click"))},{default:v.withCtx(()=>[v.createVNode(v.unref(Ar.IconPlugin),{class:"icon",style:{"font-size":"16px"}}),u[1]||(u[1]=v.createElementVNode("span",{class:"button-text"},"扩展",-1)),o.value>0?(v.openBlock(),v.createElementBlock("span",Dy,v.toDisplayString(o.value),1)):v.createCommentVNode("",!0)]),_:1},8,["active"]))}}),By=qn(Py,[["__scopeId","data-v-c2a16c66"]]),Ly={"data-v-99394ae9":"",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",width:"16.000000",height:"16.000000",fill:"none",customFrame:"#000000",size:"16"};function Fy(t,r){return v.openBlock(),v.createElementBlock("svg",Ly,[...r[0]||(r[0]=[v.createElementVNode("rect",{id:"生成式UI",width:"16.000000",height:"16.000000",x:"0.000000",y:"0.000000",fill:"currentColor","fill-opacity":"0"},null,-1),v.createElementVNode("path",{id:"矢量 154",d:"M7.41014 2.09741L7.67112 2.70606C7.68333 2.73438 7.70579 2.75684 7.73411 2.76905L8.34275 3.02979C8.43968 3.0713 8.43968 3.20875 8.34275 3.25025L7.73411 3.51124C7.70579 3.52345 7.68333 3.54591 7.67112 3.57423L7.41014 4.18288C7.36863 4.2798 7.23118 4.2798 7.18968 4.18288L6.92894 3.57423C6.91673 3.54591 6.89427 3.52345 6.86595 3.51124L6.25731 3.25025C6.16039 3.20875 6.16039 3.0713 6.25731 3.02979L6.86595 2.76905C6.89427 2.75684 6.91673 2.73438 6.92894 2.70606L7.18968 2.09741C7.23118 2.00049 7.36863 2.00049 7.41014 2.09741ZM4.57006 11.9625L7.27611 8.09746L9.69944 4.63674L10.592 3.36207C10.6899 3.22218 10.8017 3.09864 10.9272 2.99122C11.0529 2.88404 11.1926 2.79297 11.3459 2.71802C11.4992 2.64332 11.657 2.58936 11.8191 2.5564C11.9809 2.52369 12.1472 2.51172 12.3176 2.52051C12.5315 2.53174 12.7336 2.57373 12.9238 2.64649C13.0678 2.70118 13.205 2.77369 13.3354 2.86353C13.4651 2.95289 13.5813 3.05445 13.6836 3.16822C13.8064 3.3047 13.9094 3.45851 13.9929 3.6299C14.0766 3.80128 14.1342 3.97731 14.1662 4.15773C14.1928 4.30861 14.2014 4.46267 14.1919 4.61989C14.1823 4.7781 14.1547 4.93069 14.1096 5.07791C14.0495 5.27249 13.958 5.45755 13.8352 5.63309L7.81321 14.2335Q7.66985 14.4382 7.48649 14.5965Q7.4825 14.6 7.4785 14.6034Q7.29063 14.7641 7.06102 14.8766C6.90794 14.9513 6.75072 15.0052 6.5891 15.0384C6.42748 15.0714 6.2617 15.0836 6.09154 15.0751C5.87743 15.0643 5.67504 15.0226 5.48436 14.9503C5.34008 14.8956 5.20287 14.8233 5.07201 14.7335C4.94213 14.6444 4.82592 14.5428 4.72313 14.4291C4.60033 14.2928 4.49682 14.1388 4.41308 13.9674C4.32934 13.7958 4.27123 13.6197 4.23925 13.4391C4.21239 13.2882 4.20385 13.1339 4.21313 12.9767C4.22265 12.8184 4.24999 12.6656 4.2954 12.5184C4.35546 12.3233 4.44701 12.138 4.57006 11.9625ZM4.7185 4.67361L4.18383 3.42579C4.11449 3.26441 3.88549 3.26441 3.81616 3.42579L3.28149 4.67361C3.26123 4.72073 3.22363 4.75832 3.17651 4.77859L1.92871 5.31326C1.76733 5.3826 1.76733 5.6116 1.92871 5.68094L3.17651 6.21561C3.22363 6.23587 3.26123 6.27347 3.28149 6.32059L3.81616 7.56841C3.88549 7.73003 4.11449 7.73003 4.18383 7.56841L4.7185 6.32059C4.73876 6.27347 4.77636 6.23587 4.82348 6.21561L6.07128 5.68094C6.23265 5.6116 6.23265 5.3826 6.07128 5.31326L4.82348 4.77859C4.77636 4.75832 4.73876 4.72073 4.7185 4.67361ZM5.38915 12.536C5.32006 12.6346 5.27099 12.7384 5.24169 12.8475C5.22533 12.9088 5.21532 12.9718 5.21141 13.0362C5.20726 13.1063 5.21044 13.1751 5.22094 13.2428C5.23583 13.3402 5.2661 13.4354 5.31151 13.5282C5.35692 13.6209 5.41332 13.7032 5.48095 13.775C5.52806 13.8248 5.58031 13.8695 5.63817 13.9093C5.69139 13.9459 5.7473 13.9764 5.80565 14.0011C5.9099 14.0453 6.02196 14.0702 6.14208 14.0763C6.2263 14.0807 6.30834 14.0746 6.38841 14.0582C6.46825 14.0418 6.54613 14.015 6.62181 13.9781C6.69749 13.941 6.76634 13.8961 6.8286 13.8429C6.89061 13.7899 6.94578 13.7289 6.99412 13.6598L11.9415 6.59405L10.3381 5.46789L5.38915 12.536ZM10.9168 4.6415L12.5202 5.76762L13.0161 5.05935C13.0849 4.96096 13.134 4.85745 13.1633 4.74831C13.1797 4.68703 13.1897 4.62429 13.1936 4.55959C13.198 4.48977 13.1948 4.42092 13.1843 4.35329C13.1694 4.25588 13.1394 4.16091 13.0942 4.06813C13.0488 3.97536 12.9926 3.89308 12.925 3.8213C12.8781 3.7715 12.8259 3.72682 12.7683 3.68703C12.7148 3.6504 12.6591 3.61964 12.6008 3.59474C12.4968 3.55079 12.385 3.5254 12.2651 3.5193C12.1806 3.51466 12.0984 3.52076 12.0183 3.53688C11.9382 3.55324 11.8601 3.57985 11.7841 3.61696C11.7082 3.65407 11.6391 3.69899 11.5771 3.75221C11.5149 3.80519 11.4594 3.86647 11.4111 3.93556L10.9168 4.6415Z",fill:"currentColor","fill-rule":"evenodd"},null,-1)])])}const Uy={render:Fy},zy=v.defineComponent({__name:"GenUISwitch",props:{genuiEnabled:{type:Boolean,type:Boolean,default:!1,required:!1},genuiEnabledModifiers:{}},emits:["update:genuiEnabled"],setup(t){const r=v.useModel(t,"genuiEnabled"),o=()=>{r.value=!r.value};return(c,u)=>(v.openBlock(),v.createBlock(os,{class:"action-button",active:r.value,rounded:"",size:"small",onClick:o},{default:v.withCtx(()=>[v.createVNode(v.unref(Uy),{width:16,height:16}),u[0]||(u[0]=v.createElementVNode("span",{class:"button-text"},"生成式UI",-1))]),_:1},8,["active"]))}}),Vy=qn(zy,[["__scopeId","data-v-7f3b0372"]]),$y={class:"bubble-image-wrapper"},Zy=["src"],jy=["src"],Hy=v.defineComponent({__name:"BubbleImageRenderer",props:{content:{}},setup(t){const r=v.ref(!1),o=v.ref(null),c=()=>{r.value=!0},u=()=>{r.value=!1};return v.watch(r,f=>{f&&v.nextTick(()=>{o.value?.focus()})}),(f,p)=>(v.openBlock(),v.createElementBlock("div",$y,[v.createElementVNode("img",{src:t.content,class:"bubble-image",alt:"用户上传的图片",onClick:c},null,8,Zy),(v.openBlock(),v.createBlock(v.Teleport,{to:"body"},[r.value?(v.openBlock(),v.createElementBlock("div",{key:0,class:"image-preview-modal",role:"dialog","aria-modal":"true","aria-label":"图片预览",onClick:u,onKeydown:v.withKeys(u,["esc"])},[v.createElementVNode("button",{ref_key:"closeButtonRef",ref:o,class:"preview-close",type:"button","aria-label":"关闭预览",onClick:u},[...p[1]||(p[1]=[v.createElementVNode("svg",{viewBox:"0 0 1024 1024",width:"24",height:"24","aria-hidden":"true"},[v.createElementVNode("path",{d:"M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z",fill:"currentColor"})],-1)])],512),v.createElementVNode("div",{class:"preview-content",onClick:p[0]||(p[0]=v.withModifiers(()=>{},["stop"]))},[v.createElementVNode("img",{src:t.content,alt:"预览图片"},null,8,jy)])],32)):v.createCommentVNode("",!0)]))]))}}),Wy=qn(Hy,[["__scopeId","data-v-91c75579"]]),$r="https://agent.opentiny.design",Gy=[{id:"12306-mcp",name:"12306服务器",description:"12306购票搜索服务器",icon:"https://agent.opentiny.design/public-assets/icons/icon-12306.webp",enabled:!1,addState:"idle",tools:[],url:$r+"/api/v1/mcp-server/12306/mcp",type:"StreamableHTTP"},{id:"markdown2pdf-mcp",name:"Markdown转PDF MCP服务器",description:"Markdown转PDF MCP服务器,可以将Markdown文件转换为PDF文件",icon:"https://agent.opentiny.design/public-assets/icons/icon-pdf.png",url:$r+"/servers/markdown2pdf-mcp/sse",type:"sse",enabled:!1,addState:"idle",tools:[]},{id:"docx-mcp",name:"Word文档MCP服务器",description:"Word文档MCP服务器,可以创建、编辑、保存Word文档",icon:"https://agent.opentiny.design/public-assets/icons/icon-word.png",url:$r+"/servers/excel-mcp/sse",type:"sse",enabled:!1,addState:"idle",tools:[]},{id:"excel-mcp",name:"Excel文档MCP服务器",description:"Excel文档MCP服务器,可以创建、编辑、保存Excel文档",icon:"https://agent.opentiny.design/public-assets/icons/icon-excel.png",url:$r+"/servers/excel-mcp/mcp",type:"StreamableHTTP",enabled:!1,addState:"idle",tools:[]},{id:"doc-tools-mcp",name:"文档工具MCP服务器",description:"文档工具MCP服务器,可以创建、编辑、保存文档",icon:"https://agent.opentiny.design/public-assets/icons/icon-doc.png",url:$r+"/servers/doc-tools-mcp/sse",type:"sse",enabled:!1,addState:"idle",tools:[]}],Xy=`
74
+ `),e.toString()}setMode(e){this.mode=e}setECLevel(e){this.ecLevel=e}setVersion(e){this.version=e}setMaskPattern(e){this.maskPattern=e}setMatrix(e){this.matrix=e}static isValidMaskPattern(e){return e>=0&&e<rr.NUM_MASK_PATTERNS}}rr.NUM_MASK_PATTERNS=8;class st extends g{}st.kind="WriterException";class Se{constructor(){}static clearMatrix(e){e.clear(255)}static buildMatrix(e,n,i,s,a){Se.clearMatrix(a),Se.embedBasicPatterns(i,a),Se.embedTypeInfo(n,s,a),Se.maybeEmbedVersionInfo(i,a),Se.embedDataBits(e,s,a)}static embedBasicPatterns(e,n){Se.embedPositionDetectionPatternsAndSeparators(n),Se.embedDarkDotAtLeftBottomCorner(n),Se.maybeEmbedPositionAdjustmentPatterns(e,n),Se.embedTimingPatterns(n)}static embedTypeInfo(e,n,i){const s=new V;Se.makeTypeInfoBits(e,n,s);for(let a=0,l=s.getSize();a<l;++a){const d=s.get(s.getSize()-1-a),h=Se.TYPE_INFO_COORDINATES[a],m=h[0],y=h[1];if(i.setBoolean(m,y,d),a<8){const b=i.getWidth()-a-1;i.setBoolean(b,8,d)}else{const I=i.getHeight()-7+(a-8);i.setBoolean(8,I,d)}}}static maybeEmbedVersionInfo(e,n){if(e.getVersionNumber()<7)return;const i=new V;Se.makeVersionInfoBits(e,i);let s=17;for(let a=0;a<6;++a)for(let l=0;l<3;++l){const d=i.get(s);s--,n.setBoolean(a,n.getHeight()-11+l,d),n.setBoolean(n.getHeight()-11+l,a,d)}}static embedDataBits(e,n,i){let s=0,a=-1,l=i.getWidth()-1,d=i.getHeight()-1;for(;l>0;){for(l===6&&(l-=1);d>=0&&d<i.getHeight();){for(let h=0;h<2;++h){const m=l-h;if(!Se.isEmpty(i.get(m,d)))continue;let y;s<e.getSize()?(y=e.get(s),++s):y=!1,n!==255&&St.getDataMaskBit(n,m,d)&&(y=!y),i.setBoolean(m,d,y)}d+=a}a=-a,d+=a,l-=2}if(s!==e.getSize())throw new st("Not all bits consumed: "+s+"/"+e.getSize())}static findMSBSet(e){return 32-$.numberOfLeadingZeros(e)}static calculateBCHCode(e,n){if(n===0)throw new E("0 polynomial");const i=Se.findMSBSet(n);for(e<<=i-1;Se.findMSBSet(e)>=i;)e^=n<<Se.findMSBSet(e)-i;return e}static makeTypeInfoBits(e,n,i){if(!rr.isValidMaskPattern(n))throw new st("Invalid mask pattern");const s=e.getBits()<<3|n;i.appendBits(s,5);const a=Se.calculateBCHCode(s,Se.TYPE_INFO_POLY);i.appendBits(a,10);const l=new V;if(l.appendBits(Se.TYPE_INFO_MASK_PATTERN,15),i.xor(l),i.getSize()!==15)throw new st("should not happen but we got: "+i.getSize())}static makeVersionInfoBits(e,n){n.appendBits(e.getVersionNumber(),6);const i=Se.calculateBCHCode(e.getVersionNumber(),Se.VERSION_INFO_POLY);if(n.appendBits(i,12),n.getSize()!==18)throw new st("should not happen but we got: "+n.getSize())}static isEmpty(e){return e===255}static embedTimingPatterns(e){for(let n=8;n<e.getWidth()-8;++n){const i=(n+1)%2;Se.isEmpty(e.get(n,6))&&e.setNumber(n,6,i),Se.isEmpty(e.get(6,n))&&e.setNumber(6,n,i)}}static embedDarkDotAtLeftBottomCorner(e){if(e.get(8,e.getHeight()-8)===0)throw new st;e.setNumber(8,e.getHeight()-8,1)}static embedHorizontalSeparationPattern(e,n,i){for(let s=0;s<8;++s){if(!Se.isEmpty(i.get(e+s,n)))throw new st;i.setNumber(e+s,n,0)}}static embedVerticalSeparationPattern(e,n,i){for(let s=0;s<7;++s){if(!Se.isEmpty(i.get(e,n+s)))throw new st;i.setNumber(e,n+s,0)}}static embedPositionAdjustmentPattern(e,n,i){for(let s=0;s<5;++s){const a=Se.POSITION_ADJUSTMENT_PATTERN[s];for(let l=0;l<5;++l)i.setNumber(e+l,n+s,a[l])}}static embedPositionDetectionPattern(e,n,i){for(let s=0;s<7;++s){const a=Se.POSITION_DETECTION_PATTERN[s];for(let l=0;l<7;++l)i.setNumber(e+l,n+s,a[l])}}static embedPositionDetectionPatternsAndSeparators(e){const n=Se.POSITION_DETECTION_PATTERN[0].length;Se.embedPositionDetectionPattern(0,0,e),Se.embedPositionDetectionPattern(e.getWidth()-n,0,e),Se.embedPositionDetectionPattern(0,e.getWidth()-n,e);const i=8;Se.embedHorizontalSeparationPattern(0,i-1,e),Se.embedHorizontalSeparationPattern(e.getWidth()-i,i-1,e),Se.embedHorizontalSeparationPattern(0,e.getWidth()-i,e);const s=7;Se.embedVerticalSeparationPattern(s,0,e),Se.embedVerticalSeparationPattern(e.getHeight()-s-1,0,e),Se.embedVerticalSeparationPattern(s,e.getHeight()-s,e)}static maybeEmbedPositionAdjustmentPatterns(e,n){if(e.getVersionNumber()<2)return;const i=e.getVersionNumber()-1,s=Se.POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[i];for(let a=0,l=s.length;a!==l;a++){const d=s[a];if(d>=0)for(let h=0;h!==l;h++){const m=s[h];m>=0&&Se.isEmpty(n.get(m,d))&&Se.embedPositionAdjustmentPattern(m-2,d-2,n)}}}}Se.POSITION_DETECTION_PATTERN=Array.from([Int32Array.from([1,1,1,1,1,1,1]),Int32Array.from([1,0,0,0,0,0,1]),Int32Array.from([1,0,1,1,1,0,1]),Int32Array.from([1,0,1,1,1,0,1]),Int32Array.from([1,0,1,1,1,0,1]),Int32Array.from([1,0,0,0,0,0,1]),Int32Array.from([1,1,1,1,1,1,1])]),Se.POSITION_ADJUSTMENT_PATTERN=Array.from([Int32Array.from([1,1,1,1,1]),Int32Array.from([1,0,0,0,1]),Int32Array.from([1,0,1,0,1]),Int32Array.from([1,0,0,0,1]),Int32Array.from([1,1,1,1,1])]),Se.POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE=Array.from([Int32Array.from([-1,-1,-1,-1,-1,-1,-1]),Int32Array.from([6,18,-1,-1,-1,-1,-1]),Int32Array.from([6,22,-1,-1,-1,-1,-1]),Int32Array.from([6,26,-1,-1,-1,-1,-1]),Int32Array.from([6,30,-1,-1,-1,-1,-1]),Int32Array.from([6,34,-1,-1,-1,-1,-1]),Int32Array.from([6,22,38,-1,-1,-1,-1]),Int32Array.from([6,24,42,-1,-1,-1,-1]),Int32Array.from([6,26,46,-1,-1,-1,-1]),Int32Array.from([6,28,50,-1,-1,-1,-1]),Int32Array.from([6,30,54,-1,-1,-1,-1]),Int32Array.from([6,32,58,-1,-1,-1,-1]),Int32Array.from([6,34,62,-1,-1,-1,-1]),Int32Array.from([6,26,46,66,-1,-1,-1]),Int32Array.from([6,26,48,70,-1,-1,-1]),Int32Array.from([6,26,50,74,-1,-1,-1]),Int32Array.from([6,30,54,78,-1,-1,-1]),Int32Array.from([6,30,56,82,-1,-1,-1]),Int32Array.from([6,30,58,86,-1,-1,-1]),Int32Array.from([6,34,62,90,-1,-1,-1]),Int32Array.from([6,28,50,72,94,-1,-1]),Int32Array.from([6,26,50,74,98,-1,-1]),Int32Array.from([6,30,54,78,102,-1,-1]),Int32Array.from([6,28,54,80,106,-1,-1]),Int32Array.from([6,32,58,84,110,-1,-1]),Int32Array.from([6,30,58,86,114,-1,-1]),Int32Array.from([6,34,62,90,118,-1,-1]),Int32Array.from([6,26,50,74,98,122,-1]),Int32Array.from([6,30,54,78,102,126,-1]),Int32Array.from([6,26,52,78,104,130,-1]),Int32Array.from([6,30,56,82,108,134,-1]),Int32Array.from([6,34,60,86,112,138,-1]),Int32Array.from([6,30,58,86,114,142,-1]),Int32Array.from([6,34,62,90,118,146,-1]),Int32Array.from([6,30,54,78,102,126,150]),Int32Array.from([6,24,50,76,102,128,154]),Int32Array.from([6,28,54,80,106,132,158]),Int32Array.from([6,32,58,84,110,136,162]),Int32Array.from([6,26,54,82,110,138,166]),Int32Array.from([6,30,58,86,114,142,170])]),Se.TYPE_INFO_COORDINATES=Array.from([Int32Array.from([8,0]),Int32Array.from([8,1]),Int32Array.from([8,2]),Int32Array.from([8,3]),Int32Array.from([8,4]),Int32Array.from([8,5]),Int32Array.from([8,7]),Int32Array.from([8,8]),Int32Array.from([7,8]),Int32Array.from([5,8]),Int32Array.from([4,8]),Int32Array.from([3,8]),Int32Array.from([2,8]),Int32Array.from([1,8]),Int32Array.from([0,8])]),Se.VERSION_INFO_POLY=7973,Se.TYPE_INFO_POLY=1335,Se.TYPE_INFO_MASK_PATTERN=21522;class hd{constructor(e,n){this.dataBytes=e,this.errorCorrectionBytes=n}getDataBytes(){return this.dataBytes}getErrorCorrectionBytes(){return this.errorCorrectionBytes}}class ft{constructor(){}static calculateMaskPenalty(e){return St.applyMaskPenaltyRule1(e)+St.applyMaskPenaltyRule2(e)+St.applyMaskPenaltyRule3(e)+St.applyMaskPenaltyRule4(e)}static encode(e,n,i=null){let s=ft.DEFAULT_BYTE_MODE_ENCODING;const a=i!==null&&i.get(Mt.CHARACTER_SET)!==void 0;a&&(s=i.get(Mt.CHARACTER_SET).toString());const l=this.chooseMode(e,s),d=new V;if(l===Ie.BYTE&&(a||ft.DEFAULT_BYTE_MODE_ENCODING!==s)){const pe=B.getCharacterSetECIByName(s);pe!==void 0&&this.appendECI(pe,d)}this.appendModeInfo(l,d);const h=new V;this.appendBytes(e,l,h,s);let m;if(i!==null&&i.get(Mt.QR_VERSION)!==void 0){const pe=Number.parseInt(i.get(Mt.QR_VERSION).toString(),10);m=Ee.getVersionForNumber(pe);const de=this.calculateBitsNeeded(l,d,h,m);if(!this.willFit(de,m,n))throw new st("Data too big for requested version")}else m=this.recommendVersion(n,l,d,h);const y=new V;y.appendBitArray(d);const b=l===Ie.BYTE?h.getSizeInBytes():e.length;this.appendLengthInfo(b,m,l,y),y.appendBitArray(h);const I=m.getECBlocksForLevel(n),k=m.getTotalCodewords()-I.getTotalECCodewords();this.terminateBits(k,y);const F=this.interleaveWithECBytes(y,m.getTotalCodewords(),k,I.getNumBlocks()),U=new rr;U.setECLevel(n),U.setMode(l),U.setVersion(m);const G=m.getDimensionForVersion(),Q=new mi(G,G),fe=this.chooseMaskPattern(F,n,m,Q);return U.setMaskPattern(fe),Se.buildMatrix(F,n,m,fe,Q),U.setMatrix(Q),U}static recommendVersion(e,n,i,s){const a=this.calculateBitsNeeded(n,i,s,Ee.getVersionForNumber(1)),l=this.chooseVersion(a,e),d=this.calculateBitsNeeded(n,i,s,l);return this.chooseVersion(d,e)}static calculateBitsNeeded(e,n,i,s){return n.getSize()+e.getCharacterCountBits(s)+i.getSize()}static getAlphanumericCode(e){return e<ft.ALPHANUMERIC_TABLE.length?ft.ALPHANUMERIC_TABLE[e]:-1}static chooseMode(e,n=null){if(B.SJIS.getName()===n&&this.isOnlyDoubleByteKanji(e))return Ie.KANJI;let i=!1,s=!1;for(let a=0,l=e.length;a<l;++a){const d=e.charAt(a);if(ft.isDigit(d))i=!0;else if(this.getAlphanumericCode(d.charCodeAt(0))!==-1)s=!0;else return Ie.BYTE}return s?Ie.ALPHANUMERIC:i?Ie.NUMERIC:Ie.BYTE}static isOnlyDoubleByteKanji(e){let n;try{n=re.encode(e,B.SJIS)}catch{return!1}const i=n.length;if(i%2!==0)return!1;for(let s=0;s<i;s+=2){const a=n[s]&255;if((a<129||a>159)&&(a<224||a>235))return!1}return!0}static chooseMaskPattern(e,n,i,s){let a=Number.MAX_SAFE_INTEGER,l=-1;for(let d=0;d<rr.NUM_MASK_PATTERNS;d++){Se.buildMatrix(e,n,i,d,s);let h=this.calculateMaskPenalty(s);h<a&&(a=h,l=d)}return l}static chooseVersion(e,n){for(let i=1;i<=40;i++){const s=Ee.getVersionForNumber(i);if(ft.willFit(e,s,n))return s}throw new st("Data too big")}static willFit(e,n,i){const s=n.getTotalCodewords(),l=n.getECBlocksForLevel(i).getTotalECCodewords(),d=s-l,h=(e+7)/8;return d>=h}static terminateBits(e,n){const i=e*8;if(n.getSize()>i)throw new st("data bits cannot fit in the QR Code"+n.getSize()+" > "+i);for(let l=0;l<4&&n.getSize()<i;++l)n.appendBit(!1);const s=n.getSize()&7;if(s>0)for(let l=s;l<8;l++)n.appendBit(!1);const a=e-n.getSizeInBytes();for(let l=0;l<a;++l)n.appendBits((l&1)===0?236:17,8);if(n.getSize()!==i)throw new st("Bits size does not equal capacity")}static getNumDataBytesAndNumECBytesForBlockID(e,n,i,s,a,l){if(s>=i)throw new st("Block ID too large");const d=e%i,h=i-d,m=Math.floor(e/i),y=m+1,b=Math.floor(n/i),I=b+1,k=m-b,F=y-I;if(k!==F)throw new st("EC bytes mismatch");if(i!==h+d)throw new st("RS blocks mismatch");if(e!==(b+k)*h+(I+F)*d)throw new st("Total bytes mismatch");s<h?(a[0]=b,l[0]=k):(a[0]=I,l[0]=F)}static interleaveWithECBytes(e,n,i,s){if(e.getSizeInBytes()!==i)throw new st("Number of bits and data bytes does not match");let a=0,l=0,d=0;const h=new Array;for(let y=0;y<s;++y){const b=new Int32Array(1),I=new Int32Array(1);ft.getNumDataBytesAndNumECBytesForBlockID(n,i,s,y,b,I);const k=b[0],F=new Uint8Array(k);e.toBytes(8*a,F,0,k);const U=ft.generateECBytes(F,I[0]);h.push(new hd(F,U)),l=Math.max(l,k),d=Math.max(d,U.length),a+=b[0]}if(i!==a)throw new st("Data bytes does not match offset");const m=new V;for(let y=0;y<l;++y)for(const b of h){const I=b.getDataBytes();y<I.length&&m.appendBits(I[y],8)}for(let y=0;y<d;++y)for(const b of h){const I=b.getErrorCorrectionBytes();y<I.length&&m.appendBits(I[y],8)}if(n!==m.getSizeInBytes())throw new st("Interleaving error: "+n+" and "+m.getSizeInBytes()+" differ.");return m}static generateECBytes(e,n){const i=e.length,s=new Int32Array(i+n);for(let l=0;l<i;l++)s[l]=e[l]&255;new io(Le.QR_CODE_FIELD_256).encode(s,n);const a=new Uint8Array(n);for(let l=0;l<n;l++)a[l]=s[i+l];return a}static appendModeInfo(e,n){n.appendBits(e.getBits(),4)}static appendLengthInfo(e,n,i,s){const a=i.getCharacterCountBits(n);if(e>=1<<a)throw new st(e+" is bigger than "+((1<<a)-1));s.appendBits(e,a)}static appendBytes(e,n,i,s){switch(n){case Ie.NUMERIC:ft.appendNumericBytes(e,i);break;case Ie.ALPHANUMERIC:ft.appendAlphanumericBytes(e,i);break;case Ie.BYTE:ft.append8BitBytes(e,i,s);break;case Ie.KANJI:ft.appendKanjiBytes(e,i);break;default:throw new st("Invalid mode: "+n)}}static getDigit(e){return e.charCodeAt(0)-48}static isDigit(e){const n=ft.getDigit(e);return n>=0&&n<=9}static appendNumericBytes(e,n){const i=e.length;let s=0;for(;s<i;){const a=ft.getDigit(e.charAt(s));if(s+2<i){const l=ft.getDigit(e.charAt(s+1)),d=ft.getDigit(e.charAt(s+2));n.appendBits(a*100+l*10+d,10),s+=3}else if(s+1<i){const l=ft.getDigit(e.charAt(s+1));n.appendBits(a*10+l,7),s+=2}else n.appendBits(a,4),s++}}static appendAlphanumericBytes(e,n){const i=e.length;let s=0;for(;s<i;){const a=ft.getAlphanumericCode(e.charCodeAt(s));if(a===-1)throw new st;if(s+1<i){const l=ft.getAlphanumericCode(e.charCodeAt(s+1));if(l===-1)throw new st;n.appendBits(a*45+l,11),s+=2}else n.appendBits(a,6),s++}}static append8BitBytes(e,n,i){let s;try{s=re.encode(e,i)}catch(a){throw new st(a)}for(let a=0,l=s.length;a!==l;a++){const d=s[a];n.appendBits(d,8)}}static appendKanjiBytes(e,n){let i;try{i=re.encode(e,B.SJIS)}catch(a){throw new st(a)}const s=i.length;for(let a=0;a<s;a+=2){const l=i[a]&255,d=i[a+1]&255,h=l<<8&4294967295|d;let m=-1;if(h>=33088&&h<=40956?m=h-33088:h>=57408&&h<=60351&&(m=h-49472),m===-1)throw new st("Invalid byte sequence");const y=(m>>8)*192+(m&255);n.appendBits(y,13)}}static appendECI(e,n){n.appendBits(Ie.ECI.getBits(),4),n.appendBits(e.getValue(),8)}}ft.ALPHANUMERIC_TABLE=Int32Array.from([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,36,-1,-1,-1,37,38,-1,-1,-1,-1,39,40,-1,41,42,43,0,1,2,3,4,5,6,7,8,9,44,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1]),ft.DEFAULT_BYTE_MODE_ENCODING=B.UTF8.getName();class ir{write(e,n,i,s=null){if(e.length===0)throw new E("Found empty contents");if(n<0||i<0)throw new E("Requested dimensions are too small: "+n+"x"+i);let a=dt.L,l=ir.QUIET_ZONE_SIZE;s!==null&&(s.get(Mt.ERROR_CORRECTION)!==void 0&&(a=dt.fromString(s.get(Mt.ERROR_CORRECTION).toString())),s.get(Mt.MARGIN)!==void 0&&(l=Number.parseInt(s.get(Mt.MARGIN).toString(),10)));const d=ft.encode(e,a,s);return this.renderResult(d,n,i,l)}writeToDom(e,n,i,s,a=null){typeof e=="string"&&(e=document.querySelector(e));const l=this.write(n,i,s,a);e&&e.appendChild(l)}renderResult(e,n,i,s){const a=e.getMatrix();if(a===null)throw new Zt;const l=a.getWidth(),d=a.getHeight(),h=l+s*2,m=d+s*2,y=Math.max(n,h),b=Math.max(i,m),I=Math.min(Math.floor(y/h),Math.floor(b/m)),k=Math.floor((y-l*I)/2),F=Math.floor((b-d*I)/2),U=this.createSVGElement(y,b);for(let G=0,Q=F;G<d;G++,Q+=I)for(let fe=0,pe=k;fe<l;fe++,pe+=I)if(a.get(fe,G)===1){const de=this.createSvgRectElement(pe,Q,I,I);U.appendChild(de)}return U}createSVGElement(e,n){const i=document.createElementNS(ir.SVG_NS,"svg");return i.setAttributeNS(null,"height",e.toString()),i.setAttributeNS(null,"width",n.toString()),i}createSvgRectElement(e,n,i,s){const a=document.createElementNS(ir.SVG_NS,"rect");return a.setAttributeNS(null,"x",e.toString()),a.setAttributeNS(null,"y",n.toString()),a.setAttributeNS(null,"height",i.toString()),a.setAttributeNS(null,"width",s.toString()),a.setAttributeNS(null,"fill","#000000"),a}}ir.QUIET_ZONE_SIZE=4,ir.SVG_NS="http://www.w3.org/2000/svg";class _r{encode(e,n,i,s,a){if(e.length===0)throw new E("Found empty contents");if(n!==ie.QR_CODE)throw new E("Can only encode QR_CODE, but got "+n);if(i<0||s<0)throw new E(`Requested dimensions are too small: ${i}x${s}`);let l=dt.L,d=_r.QUIET_ZONE_SIZE;a!==null&&(a.get(Mt.ERROR_CORRECTION)!==void 0&&(l=dt.fromString(a.get(Mt.ERROR_CORRECTION).toString())),a.get(Mt.MARGIN)!==void 0&&(d=Number.parseInt(a.get(Mt.MARGIN).toString(),10)));const h=ft.encode(e,l,a);return _r.renderResult(h,i,s,d)}static renderResult(e,n,i,s){const a=e.getMatrix();if(a===null)throw new Zt;const l=a.getWidth(),d=a.getHeight(),h=l+s*2,m=d+s*2,y=Math.max(n,h),b=Math.max(i,m),I=Math.min(Math.floor(y/h),Math.floor(b/m)),k=Math.floor((y-l*I)/2),F=Math.floor((b-d*I)/2),U=new te(y,b);for(let G=0,Q=F;G<d;G++,Q+=I)for(let fe=0,pe=k;fe<l;fe++,pe+=I)a.get(fe,G)===1&&U.setRegion(pe,Q,I,I);return U}}_r.QUIET_ZONE_SIZE=4;class pd{encode(e,n,i,s,a){let l;switch(n){case ie.QR_CODE:l=new _r;break;default:throw new E("No encoder available for format "+n)}return l.encode(e,n,i,s,a)}}class Nn extends oe{constructor(e,n,i,s,a,l,d,h){if(super(l,d),this.yuvData=e,this.dataWidth=n,this.dataHeight=i,this.left=s,this.top=a,s+l>n||a+d>i)throw new E("Crop rectangle does not fit within image data.");h&&this.reverseHorizontal(l,d)}getRow(e,n){if(e<0||e>=this.getHeight())throw new E("Requested row is outside the image: "+e);const i=this.getWidth();(n==null||n.length<i)&&(n=new Uint8ClampedArray(i));const s=(e+this.top)*this.dataWidth+this.left;return R.arraycopy(this.yuvData,s,n,0,i),n}getMatrix(){const e=this.getWidth(),n=this.getHeight();if(e===this.dataWidth&&n===this.dataHeight)return this.yuvData;const i=e*n,s=new Uint8ClampedArray(i);let a=this.top*this.dataWidth+this.left;if(e===this.dataWidth)return R.arraycopy(this.yuvData,a,s,0,i),s;for(let l=0;l<n;l++){const d=l*e;R.arraycopy(this.yuvData,a,s,d,e),a+=this.dataWidth}return s}isCropSupported(){return!0}crop(e,n,i,s){return new Nn(this.yuvData,this.dataWidth,this.dataHeight,this.left+e,this.top+n,i,s,!1)}renderThumbnail(){const e=this.getWidth()/Nn.THUMBNAIL_SCALE_FACTOR,n=this.getHeight()/Nn.THUMBNAIL_SCALE_FACTOR,i=new Int32Array(e*n),s=this.yuvData;let a=this.top*this.dataWidth+this.left;for(let l=0;l<n;l++){const d=l*e;for(let h=0;h<e;h++){const m=s[a+h*Nn.THUMBNAIL_SCALE_FACTOR]&255;i[d+h]=4278190080|m*65793}a+=this.dataWidth*Nn.THUMBNAIL_SCALE_FACTOR}return i}getThumbnailWidth(){return this.getWidth()/Nn.THUMBNAIL_SCALE_FACTOR}getThumbnailHeight(){return this.getHeight()/Nn.THUMBNAIL_SCALE_FACTOR}reverseHorizontal(e,n){const i=this.yuvData;for(let s=0,a=this.top*this.dataWidth+this.left;s<n;s++,a+=this.dataWidth){const l=a+e/2;for(let d=a,h=a+e-1;d<l;d++,h--){const m=i[d];i[d]=i[h],i[h]=m}}}invert(){return new ge(this)}}Nn.THUMBNAIL_SCALE_FACTOR=2;class oo extends oe{constructor(e,n,i,s,a,l,d){if(super(n,i),this.dataWidth=s,this.dataHeight=a,this.left=l,this.top=d,e.BYTES_PER_ELEMENT===4){const h=n*i,m=new Uint8ClampedArray(h);for(let y=0;y<h;y++){const b=e[y],I=b>>16&255,k=b>>7&510,F=b&255;m[y]=(I+k+F)/4&255}this.luminances=m}else this.luminances=e;if(s===void 0&&(this.dataWidth=n),a===void 0&&(this.dataHeight=i),l===void 0&&(this.left=0),d===void 0&&(this.top=0),this.left+n>this.dataWidth||this.top+i>this.dataHeight)throw new E("Crop rectangle does not fit within image data.")}getRow(e,n){if(e<0||e>=this.getHeight())throw new E("Requested row is outside the image: "+e);const i=this.getWidth();(n==null||n.length<i)&&(n=new Uint8ClampedArray(i));const s=(e+this.top)*this.dataWidth+this.left;return R.arraycopy(this.luminances,s,n,0,i),n}getMatrix(){const e=this.getWidth(),n=this.getHeight();if(e===this.dataWidth&&n===this.dataHeight)return this.luminances;const i=e*n,s=new Uint8ClampedArray(i);let a=this.top*this.dataWidth+this.left;if(e===this.dataWidth)return R.arraycopy(this.luminances,a,s,0,i),s;for(let l=0;l<n;l++){const d=l*e;R.arraycopy(this.luminances,a,s,d,e),a+=this.dataWidth}return s}isCropSupported(){return!0}crop(e,n,i,s){return new oo(this.luminances,i,s,this.dataWidth,this.dataHeight,this.left+e,this.top+n)}invert(){return new ge(this)}}class ws extends B{static forName(e){return this.getCharacterSetECIByName(e)}}class so{}so.ISO_8859_1=B.ISO8859_1;class _s{isCompact(){return this.compact}setCompact(e){this.compact=e}getSize(){return this.size}setSize(e){this.size=e}getLayers(){return this.layers}setLayers(e){this.layers=e}getCodeWords(){return this.codeWords}setCodeWords(e){this.codeWords=e}getMatrix(){return this.matrix}setMatrix(e){this.matrix=e}}class vs{static singletonList(e){return[e]}static min(e,n){return e.sort(n)[0]}}class md{constructor(e){this.previous=e}getPrevious(){return this.previous}}class vr extends md{constructor(e,n,i){super(e),this.value=n,this.bitCount=i}appendTo(e,n){e.appendBits(this.value,this.bitCount)}add(e,n){return new vr(this,e,n)}addBinaryShift(e,n){return console.warn("addBinaryShift on SimpleToken, this simply returns a copy of this token"),new vr(this,e,n)}toString(){let e=this.value&(1<<this.bitCount)-1;return e|=1<<this.bitCount,"<"+$.toBinaryString(e|1<<this.bitCount).substring(1)+">"}}class ao extends vr{constructor(e,n,i){super(e,0,0),this.binaryShiftStart=n,this.binaryShiftByteCount=i}appendTo(e,n){for(let i=0;i<this.binaryShiftByteCount;i++)(i===0||i===31&&this.binaryShiftByteCount<=62)&&(e.appendBits(31,5),this.binaryShiftByteCount>62?e.appendBits(this.binaryShiftByteCount-31,16):i===0?e.appendBits(Math.min(this.binaryShiftByteCount,31),5):e.appendBits(this.binaryShiftByteCount-31,5)),e.appendBits(n[this.binaryShiftStart+i],8)}addBinaryShift(e,n){return new ao(this,e,n)}toString(){return"<"+this.binaryShiftStart+"::"+(this.binaryShiftStart+this.binaryShiftByteCount-1)+">"}}function gd(C,e,n){return new ao(C,e,n)}function Lr(C,e,n){return new vr(C,e,n)}const xd=["UPPER","LOWER","DIGIT","MIXED","PUNCT"],Hn=0,gi=1,mn=2,Cs=3,On=4,yd=new vr(null,0,0),lo=[Int32Array.from([0,(5<<16)+28,(5<<16)+30,(5<<16)+29,656318]),Int32Array.from([(9<<16)+480+14,0,(5<<16)+30,(5<<16)+29,656318]),Int32Array.from([(4<<16)+14,(9<<16)+448+28,0,(9<<16)+448+29,932798]),Int32Array.from([(5<<16)+29,(5<<16)+28,656318,0,(5<<16)+30]),Int32Array.from([(5<<16)+31,656380,656382,656381,0])];function wd(C){for(let e of C)Z.fill(e,-1);return C[Hn][On]=0,C[gi][On]=0,C[gi][Hn]=28,C[Cs][On]=0,C[mn][On]=0,C[mn][Hn]=15,C}const bs=wd(Z.createInt32Array(6,6));class kn{constructor(e,n,i,s){this.token=e,this.mode=n,this.binaryShiftByteCount=i,this.bitCount=s}getMode(){return this.mode}getToken(){return this.token}getBinaryShiftByteCount(){return this.binaryShiftByteCount}getBitCount(){return this.bitCount}latchAndAppend(e,n){let i=this.bitCount,s=this.token;if(e!==this.mode){let l=lo[this.mode][e];s=Lr(s,l&65535,l>>16),i+=l>>16}let a=e===mn?4:5;return s=Lr(s,n,a),new kn(s,e,0,i+a)}shiftAndAppend(e,n){let i=this.token,s=this.mode===mn?4:5;return i=Lr(i,bs[this.mode][e],s),i=Lr(i,n,5),new kn(i,this.mode,0,this.bitCount+s+5)}addBinaryShiftChar(e){let n=this.token,i=this.mode,s=this.bitCount;if(this.mode===On||this.mode===mn){let d=lo[i][Hn];n=Lr(n,d&65535,d>>16),s+=d>>16,i=Hn}let a=this.binaryShiftByteCount===0||this.binaryShiftByteCount===31?18:this.binaryShiftByteCount===62?9:8,l=new kn(n,i,this.binaryShiftByteCount+1,s+a);return l.binaryShiftByteCount===2078&&(l=l.endBinaryShift(e+1)),l}endBinaryShift(e){if(this.binaryShiftByteCount===0)return this;let n=this.token;return n=gd(n,e-this.binaryShiftByteCount,this.binaryShiftByteCount),new kn(n,this.mode,0,this.bitCount)}isBetterThanOrEqualTo(e){let n=this.bitCount+(lo[this.mode][e.mode]>>16);return this.binaryShiftByteCount<e.binaryShiftByteCount?n+=kn.calculateBinaryShiftCost(e)-kn.calculateBinaryShiftCost(this):this.binaryShiftByteCount>e.binaryShiftByteCount&&e.binaryShiftByteCount>0&&(n+=10),n<=e.bitCount}toBitArray(e){let n=[];for(let s=this.endBinaryShift(e.length).token;s!==null;s=s.getPrevious())n.unshift(s);let i=new V;for(const s of n)s.appendTo(i,e);return i}toString(){return ne.format("%s bits=%d bytes=%d",xd[this.mode],this.bitCount,this.binaryShiftByteCount)}static calculateBinaryShiftCost(e){return e.binaryShiftByteCount>62?21:e.binaryShiftByteCount>31?20:e.binaryShiftByteCount>0?10:0}}kn.INITIAL_STATE=new kn(yd,Hn,0,0);function _d(C){const e=ne.getCharCode(" "),n=ne.getCharCode("."),i=ne.getCharCode(",");C[Hn][e]=1;const s=ne.getCharCode("Z"),a=ne.getCharCode("A");for(let I=a;I<=s;I++)C[Hn][I]=I-a+2;C[gi][e]=1;const l=ne.getCharCode("z"),d=ne.getCharCode("a");for(let I=d;I<=l;I++)C[gi][I]=I-d+2;C[mn][e]=1;const h=ne.getCharCode("9"),m=ne.getCharCode("0");for(let I=m;I<=h;I++)C[mn][I]=I-m+2;C[mn][i]=12,C[mn][n]=13;const y=["\0"," ","","","","","","","\x07","\b"," ",`
75
+ `,"\v","\f","\r","\x1B","","","","","@","\\","^","_","`","|","~",""];for(let I=0;I<y.length;I++)C[Cs][ne.getCharCode(y[I])]=I;const b=["\0","\r","\0","\0","\0","\0","!","'","#","$","%","&","'","(",")","*","+",",","-",".","/",":",";","<","=",">","?","[","]","{","}"];for(let I=0;I<b.length;I++)ne.getCharCode(b[I])>0&&(C[On][ne.getCharCode(b[I])]=I);return C}const co=_d(Z.createInt32Array(5,256));class Fr{constructor(e){this.text=e}encode(){const e=ne.getCharCode(" "),n=ne.getCharCode(`
76
+ `);let i=vs.singletonList(kn.INITIAL_STATE);for(let a=0;a<this.text.length;a++){let l,d=a+1<this.text.length?this.text[a+1]:0;switch(this.text[a]){case ne.getCharCode("\r"):l=d===n?2:0;break;case ne.getCharCode("."):l=d===e?3:0;break;case ne.getCharCode(","):l=d===e?4:0;break;case ne.getCharCode(":"):l=d===e?5:0;break;default:l=0}l>0?(i=Fr.updateStateListForPair(i,a,l),a++):i=this.updateStateListForChar(i,a)}return vs.min(i,(a,l)=>a.getBitCount()-l.getBitCount()).toBitArray(this.text)}updateStateListForChar(e,n){const i=[];for(let s of e)this.updateStateForChar(s,n,i);return Fr.simplifyStates(i)}updateStateForChar(e,n,i){let s=this.text[n]&255,a=co[e.getMode()][s]>0,l=null;for(let d=0;d<=On;d++){let h=co[d][s];if(h>0){if(l==null&&(l=e.endBinaryShift(n)),!a||d===e.getMode()||d===mn){const m=l.latchAndAppend(d,h);i.push(m)}if(!a&&bs[e.getMode()][d]>=0){const m=l.shiftAndAppend(d,h);i.push(m)}}}if(e.getBinaryShiftByteCount()>0||co[e.getMode()][s]===0){let d=e.addBinaryShiftChar(n);i.push(d)}}static updateStateListForPair(e,n,i){const s=[];for(let a of e)this.updateStateForPair(a,n,i,s);return this.simplifyStates(s)}static updateStateForPair(e,n,i,s){let a=e.endBinaryShift(n);if(s.push(a.latchAndAppend(On,i)),e.getMode()!==On&&s.push(a.shiftAndAppend(On,i)),i===3||i===4){let l=a.latchAndAppend(mn,16-i).latchAndAppend(mn,1);s.push(l)}if(e.getBinaryShiftByteCount()>0){let l=e.addBinaryShiftChar(n).addBinaryShiftChar(n+1);s.push(l)}}static simplifyStates(e){let n=[];for(const i of e){let s=!0;for(const a of n){if(a.isBetterThanOrEqualTo(i)){s=!1;break}i.isBetterThanOrEqualTo(a)&&(n=n.filter(l=>l!==a))}s&&n.push(i)}return n}}class Ge{constructor(){}static encodeBytes(e){return Ge.encode(e,Ge.DEFAULT_EC_PERCENT,Ge.DEFAULT_AZTEC_LAYERS)}static encode(e,n,i){let s=new Fr(e).encode(),a=$.truncDivision(s.getSize()*n,100)+11,l=s.getSize()+a,d,h,m,y,b;if(i!==Ge.DEFAULT_AZTEC_LAYERS){if(d=i<0,h=Math.abs(i),h>(d?Ge.MAX_NB_BITS_COMPACT:Ge.MAX_NB_BITS))throw new E(ne.format("Illegal value %s for layers",i));m=Ge.totalBitsInLayer(h,d),y=Ge.WORD_SIZE[h];let de=m-m%y;if(b=Ge.stuffBits(s,y),b.getSize()+a>de)throw new E("Data to large for user specified layer");if(d&&b.getSize()>y*64)throw new E("Data to large for user specified layer")}else{y=0,b=null;for(let de=0;;de++){if(de>Ge.MAX_NB_BITS)throw new E("Data too large for an Aztec code");if(d=de<=3,h=d?de+1:de,m=Ge.totalBitsInLayer(h,d),l>m)continue;(b==null||y!==Ge.WORD_SIZE[h])&&(y=Ge.WORD_SIZE[h],b=Ge.stuffBits(s,y));let He=m-m%y;if(!(d&&b.getSize()>y*64)&&b.getSize()+a<=He)break}}let I=Ge.generateCheckWords(b,m,y),k=b.getSize()/y,F=Ge.generateModeMessage(d,h,k),U=(d?11:14)+h*4,G=new Int32Array(U),Q;if(d){Q=U;for(let de=0;de<G.length;de++)G[de]=de}else{Q=U+1+2*$.truncDivision($.truncDivision(U,2)-1,15);let de=$.truncDivision(U,2),He=$.truncDivision(Q,2);for(let De=0;De<de;De++){let en=De+$.truncDivision(De,15);G[de-De-1]=He-en-1,G[de+De]=He+en+1}}let fe=new te(Q);for(let de=0,He=0;de<h;de++){let De=(h-de)*4+(d?9:12);for(let en=0;en<De;en++){let yn=en*2;for(let tn=0;tn<2;tn++)I.get(He+yn+tn)&&fe.set(G[de*2+tn],G[de*2+en]),I.get(He+De*2+yn+tn)&&fe.set(G[de*2+en],G[U-1-de*2-tn]),I.get(He+De*4+yn+tn)&&fe.set(G[U-1-de*2-tn],G[U-1-de*2-en]),I.get(He+De*6+yn+tn)&&fe.set(G[U-1-de*2-en],G[de*2+tn])}He+=De*8}if(Ge.drawModeMessage(fe,d,Q,F),d)Ge.drawBullsEye(fe,$.truncDivision(Q,2),5);else{Ge.drawBullsEye(fe,$.truncDivision(Q,2),7);for(let de=0,He=0;de<$.truncDivision(U,2)-1;de+=15,He+=16)for(let De=$.truncDivision(Q,2)&1;De<Q;De+=2)fe.set($.truncDivision(Q,2)-He,De),fe.set($.truncDivision(Q,2)+He,De),fe.set(De,$.truncDivision(Q,2)-He),fe.set(De,$.truncDivision(Q,2)+He)}let pe=new _s;return pe.setCompact(d),pe.setSize(Q),pe.setLayers(h),pe.setCodeWords(k),pe.setMatrix(fe),pe}static drawBullsEye(e,n,i){for(let s=0;s<i;s+=2)for(let a=n-s;a<=n+s;a++)e.set(a,n-s),e.set(a,n+s),e.set(n-s,a),e.set(n+s,a);e.set(n-i,n-i),e.set(n-i+1,n-i),e.set(n-i,n-i+1),e.set(n+i,n-i),e.set(n+i,n-i+1),e.set(n+i,n+i-1)}static generateModeMessage(e,n,i){let s=new V;return e?(s.appendBits(n-1,2),s.appendBits(i-1,6),s=Ge.generateCheckWords(s,28,4)):(s.appendBits(n-1,5),s.appendBits(i-1,11),s=Ge.generateCheckWords(s,40,4)),s}static drawModeMessage(e,n,i,s){let a=$.truncDivision(i,2);if(n)for(let l=0;l<7;l++){let d=a-3+l;s.get(l)&&e.set(d,a-5),s.get(l+7)&&e.set(a+5,d),s.get(20-l)&&e.set(d,a+5),s.get(27-l)&&e.set(a-5,d)}else for(let l=0;l<10;l++){let d=a-5+l+$.truncDivision(l,5);s.get(l)&&e.set(d,a-7),s.get(l+10)&&e.set(a+7,d),s.get(29-l)&&e.set(d,a+7),s.get(39-l)&&e.set(a-7,d)}}static generateCheckWords(e,n,i){let s=e.getSize()/i,a=new io(Ge.getGF(i)),l=$.truncDivision(n,i),d=Ge.bitsToWords(e,i,l);a.encode(d,l-s);let h=n%i,m=new V;m.appendBits(0,h);for(const y of Array.from(d))m.appendBits(y,i);return m}static bitsToWords(e,n,i){let s=new Int32Array(i),a,l;for(a=0,l=e.getSize()/n;a<l;a++){let d=0;for(let h=0;h<n;h++)d|=e.get(a*n+h)?1<<n-h-1:0;s[a]=d}return s}static getGF(e){switch(e){case 4:return Le.AZTEC_PARAM;case 6:return Le.AZTEC_DATA_6;case 8:return Le.AZTEC_DATA_8;case 10:return Le.AZTEC_DATA_10;case 12:return Le.AZTEC_DATA_12;default:throw new E("Unsupported word size "+e)}}static stuffBits(e,n){let i=new V,s=e.getSize(),a=(1<<n)-2;for(let l=0;l<s;l+=n){let d=0;for(let h=0;h<n;h++)(l+h>=s||e.get(l+h))&&(d|=1<<n-1-h);(d&a)===a?(i.appendBits(d&a,n),l--):(d&a)===0?(i.appendBits(d|1,n),l--):i.appendBits(d,n)}return i}static totalBitsInLayer(e,n){return((n?88:112)+16*e)*e}}Ge.DEFAULT_EC_PERCENT=33,Ge.DEFAULT_AZTEC_LAYERS=0,Ge.MAX_NB_BITS=32,Ge.MAX_NB_BITS_COMPACT=4,Ge.WORD_SIZE=Int32Array.from([4,6,6,8,8,8,8,8,8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,12,12,12,12,12,12,12,12,12,12]);class xi{encode(e,n,i,s){return this.encodeWithHints(e,n,i,s,null)}encodeWithHints(e,n,i,s,a){let l=so.ISO_8859_1,d=Ge.DEFAULT_EC_PERCENT,h=Ge.DEFAULT_AZTEC_LAYERS;return a!=null&&(a.has(Mt.CHARACTER_SET)&&(l=ws.forName(a.get(Mt.CHARACTER_SET).toString())),a.has(Mt.ERROR_CORRECTION)&&(d=$.parseInt(a.get(Mt.ERROR_CORRECTION).toString())),a.has(Mt.AZTEC_LAYERS)&&(h=$.parseInt(a.get(Mt.AZTEC_LAYERS).toString()))),xi.encodeLayers(e,n,i,s,l,d,h)}static encodeLayers(e,n,i,s,a,l,d){if(n!==ie.AZTEC)throw new E("Can only encode AZTEC, but got "+n);let h=Ge.encode(ne.getBytes(e,a),l,d);return xi.renderResult(h,i,s)}static renderResult(e,n,i){let s=e.getMatrix();if(s==null)throw new Zt;let a=s.getWidth(),l=s.getHeight(),d=Math.max(n,a),h=Math.max(i,l),m=Math.min(d/a,h/l),y=(d-a*m)/2,b=(h-l*m)/2,I=new te(d,h);for(let k=0,F=b;k<l;k++,F+=m)for(let U=0,G=y;U<a;U++,G+=m)s.get(U,k)&&I.setRegion(G,F,m,m);return I}}o.AbstractExpandedDecoder=Xi,o.ArgumentException=A,o.ArithmeticException=Wt,o.AztecCode=_s,o.AztecCodeReader=rt,o.AztecCodeWriter=xi,o.AztecDecoder=Xe,o.AztecDetector=li,o.AztecDetectorResult=wt,o.AztecEncoder=Ge,o.AztecHighLevelEncoder=Fr,o.AztecPoint=Ut,o.BarcodeFormat=ie,o.Binarizer=D,o.BinaryBitmap=L,o.BitArray=V,o.BitMatrix=te,o.BitSource=Ki,o.BrowserAztecCodeReader=Oe,o.BrowserBarcodeReader=Ju,o.BrowserCodeReader=je,o.BrowserDatamatrixCodeReader=Qu,o.BrowserMultiFormatReader=ud,o.BrowserPDF417Reader=dd,o.BrowserQRCodeReader=fd,o.BrowserQRCodeSvgWriter=ir,o.CharacterSetECI=B,o.ChecksumException=M,o.Code128Reader=xe,o.Code39Reader=Ot,o.DataMatrixDecodedBitStreamParser=Vn,o.DataMatrixReader=$n,o.DecodeHintType=j,o.DecoderResult=ke,o.DefaultGridSampler=ai,o.DetectorResult=ye,o.EAN13Reader=Qn,o.EncodeHintType=Mt,o.Exception=g,o.FormatException=z,o.GenericGF=Le,o.GenericGFPoly=tt,o.GlobalHistogramBinarizer=J,o.GridSampler=Un,o.GridSamplerInstance=An,o.HTMLCanvasElementLuminanceSource=he,o.HybridBinarizer=ae,o.ITFReader=ot,o.IllegalArgumentException=E,o.IllegalStateException=Zt,o.InvertedLuminanceSource=ge,o.LuminanceSource=oe,o.MathUtils=Ze,o.MultiFormatOneDReader=yr,o.MultiFormatReader=ys,o.MultiFormatWriter=pd,o.NotFoundException=O,o.OneDReader=Te,o.PDF417DecodedBitStreamParser=K,o.PDF417DecoderErrorCorrection=fs,o.PDF417Reader=Vt,o.PDF417ResultMetadata=ps,o.PerspectiveTransform=rn,o.PlanarYUVLuminanceSource=Nn,o.QRCodeByteMatrix=mi,o.QRCodeDataMask=hn,o.QRCodeDecodedBitStreamParser=vt,o.QRCodeDecoderErrorCorrectionLevel=dt,o.QRCodeDecoderFormatInformation=Ht,o.QRCodeEncoder=ft,o.QRCodeEncoderQRCode=rr,o.QRCodeMaskUtil=St,o.QRCodeMatrixUtil=Se,o.QRCodeMode=Ie,o.QRCodeReader=Zn,o.QRCodeVersion=Ee,o.QRCodeWriter=_r,o.RGBLuminanceSource=oo,o.RSS14Reader=It,o.RSSExpandedReader=ce,o.ReaderException=pi,o.ReedSolomonDecoder=En,o.ReedSolomonEncoder=io,o.ReedSolomonException=gn,o.Result=Be,o.ResultMetadataType=Me,o.ResultPoint=N,o.StringUtils=ne,o.UnsupportedOperationException=we,o.VideoInputDevice=ue,o.WhiteRectangleDetector=_t,o.WriterException=st,o.ZXingArrays=Z,o.ZXingCharset=ws,o.ZXingInteger=$,o.ZXingStandardCharsets=so,o.ZXingStringBuilder=le,o.ZXingStringEncoding=re,o.ZXingSystem=R,o.createAbstractExpandedDecoder=us,Object.defineProperty(o,"__esModule",{value:!0})}))})(Hr,Hr.exports)),Hr.exports}var ht=Qy();const ew=Tc(ht),tw=Id({__proto__:null,default:ew},[ht]);var ll=(function(){function t(r,o,c){if(this.formatMap=new Map([[ve.QR_CODE,ht.BarcodeFormat.QR_CODE],[ve.AZTEC,ht.BarcodeFormat.AZTEC],[ve.CODABAR,ht.BarcodeFormat.CODABAR],[ve.CODE_39,ht.BarcodeFormat.CODE_39],[ve.CODE_93,ht.BarcodeFormat.CODE_93],[ve.CODE_128,ht.BarcodeFormat.CODE_128],[ve.DATA_MATRIX,ht.BarcodeFormat.DATA_MATRIX],[ve.MAXICODE,ht.BarcodeFormat.MAXICODE],[ve.ITF,ht.BarcodeFormat.ITF],[ve.EAN_13,ht.BarcodeFormat.EAN_13],[ve.EAN_8,ht.BarcodeFormat.EAN_8],[ve.PDF_417,ht.BarcodeFormat.PDF_417],[ve.RSS_14,ht.BarcodeFormat.RSS_14],[ve.RSS_EXPANDED,ht.BarcodeFormat.RSS_EXPANDED],[ve.UPC_A,ht.BarcodeFormat.UPC_A],[ve.UPC_E,ht.BarcodeFormat.UPC_E],[ve.UPC_EAN_EXTENSION,ht.BarcodeFormat.UPC_EAN_EXTENSION]]),this.reverseFormatMap=this.createReverseFormatMap(),!tw)throw"Use html5qrcode.min.js without edit, ZXing not found.";this.verbose=o,this.logger=c;var u=this.createZXingFormats(r),f=new Map;f.set(ht.DecodeHintType.POSSIBLE_FORMATS,u),f.set(ht.DecodeHintType.TRY_HARDER,!1),this.hints=f}return t.prototype.decodeAsync=function(r){var o=this;return new Promise(function(c,u){try{c(o.decode(r))}catch(f){u(f)}})},t.prototype.decode=function(r){var o=new ht.MultiFormatReader(this.verbose,this.hints),c=new ht.HTMLCanvasElementLuminanceSource(r),u=new ht.BinaryBitmap(new ht.HybridBinarizer(c)),f=o.decode(u);return{text:f.text,format:Zu.create(this.toHtml5QrcodeSupportedFormats(f.format)),debugData:this.createDebugData()}},t.prototype.createReverseFormatMap=function(){var r=new Map;return this.formatMap.forEach(function(o,c,u){r.set(o,c)}),r},t.prototype.toHtml5QrcodeSupportedFormats=function(r){if(!this.reverseFormatMap.has(r))throw"reverseFormatMap doesn't have ".concat(r);return this.reverseFormatMap.get(r)},t.prototype.createZXingFormats=function(r){for(var o=[],c=0,u=r;c<u.length;c++){var f=u[c];this.formatMap.has(f)?o.push(this.formatMap.get(f)):this.logger.logError("".concat(f," is not supported by")+"ZXingHtml5QrcodeShim")}return o},t.prototype.createDebugData=function(){return{decoderName:"zxing-js"}},t})(),nw=function(t,r,o,c){function u(f){return f instanceof o?f:new o(function(p){p(f)})}return new(o||(o=Promise))(function(f,p){function x(A){try{g(c.next(A))}catch(E){p(E)}}function _(A){try{g(c.throw(A))}catch(E){p(E)}}function g(A){A.done?f(A.value):u(A.value).then(x,_)}g((c=c.apply(t,r||[])).next())})},rw=function(t,r){var o={label:0,sent:function(){if(f[0]&1)throw f[1];return f[1]},trys:[],ops:[]},c,u,f,p;return p={next:x(0),throw:x(1),return:x(2)},typeof Symbol=="function"&&(p[Symbol.iterator]=function(){return this}),p;function x(g){return function(A){return _([g,A])}}function _(g){if(c)throw new TypeError("Generator is already executing.");for(;p&&(p=0,g[0]&&(o=0)),o;)try{if(c=1,u&&(f=g[0]&2?u.return:g[0]?u.throw||((f=u.return)&&f.call(u),0):u.next)&&!(f=f.call(u,g[1])).done)return f;switch(u=0,f&&(g=[g[0]&2,f.value]),g[0]){case 0:case 1:f=g;break;case 4:return o.label++,{value:g[1],done:!1};case 5:o.label++,u=g[1],g=[0];continue;case 7:g=o.ops.pop(),o.trys.pop();continue;default:if(f=o.trys,!(f=f.length>0&&f[f.length-1])&&(g[0]===6||g[0]===2)){o=0;continue}if(g[0]===3&&(!f||g[1]>f[0]&&g[1]<f[3])){o.label=g[1];break}if(g[0]===6&&o.label<f[1]){o.label=f[1],f=g;break}if(f&&o.label<f[2]){o.label=f[2],o.ops.push(g);break}f[2]&&o.ops.pop(),o.trys.pop();continue}g=r.call(t,o)}catch(A){g=[6,A],u=0}finally{c=f=0}if(g[0]&5)throw g[1];return{value:g[0]?g[1]:void 0,done:!0}}},cl=(function(){function t(r,o,c){if(this.formatMap=new Map([[ve.QR_CODE,"qr_code"],[ve.AZTEC,"aztec"],[ve.CODABAR,"codabar"],[ve.CODE_39,"code_39"],[ve.CODE_93,"code_93"],[ve.CODE_128,"code_128"],[ve.DATA_MATRIX,"data_matrix"],[ve.ITF,"itf"],[ve.EAN_13,"ean_13"],[ve.EAN_8,"ean_8"],[ve.PDF_417,"pdf417"],[ve.UPC_A,"upc_a"],[ve.UPC_E,"upc_e"]]),this.reverseFormatMap=this.createReverseFormatMap(),!t.isSupported())throw"Use html5qrcode.min.js without edit, Use BarcodeDetectorDelegate only if it isSupported();";this.verbose=o,this.logger=c;var u=this.createBarcodeDetectorFormats(r);if(this.detector=new BarcodeDetector(u),!this.detector)throw"BarcodeDetector detector not supported"}return t.isSupported=function(){if(!("BarcodeDetector"in window))return!1;var r=new BarcodeDetector({formats:["qr_code"]});return typeof r<"u"},t.prototype.decodeAsync=function(r){return nw(this,void 0,void 0,function(){var o,c;return rw(this,function(u){switch(u.label){case 0:return[4,this.detector.detect(r)];case 1:if(o=u.sent(),!o||o.length===0)throw"No barcode or QR code detected.";return c=this.selectLargestBarcode(o),[2,{text:c.rawValue,format:Zu.create(this.toHtml5QrcodeSupportedFormats(c.format)),debugData:this.createDebugData()}]}})})},t.prototype.selectLargestBarcode=function(r){for(var o=null,c=0,u=0,f=r;u<f.length;u++){var p=f[u],x=p.boundingBox.width*p.boundingBox.height;x>c&&(c=x,o=p)}if(!o)throw"No largest barcode found";return o},t.prototype.createBarcodeDetectorFormats=function(r){for(var o=[],c=0,u=r;c<u.length;c++){var f=u[c];this.formatMap.has(f)?o.push(this.formatMap.get(f)):this.logger.warn("".concat(f," is not supported by")+"BarcodeDetectorDelegate")}return{formats:o}},t.prototype.toHtml5QrcodeSupportedFormats=function(r){if(!this.reverseFormatMap.has(r))throw"reverseFormatMap doesn't have ".concat(r);return this.reverseFormatMap.get(r)},t.prototype.createReverseFormatMap=function(){var r=new Map;return this.formatMap.forEach(function(o,c,u){r.set(o,c)}),r},t.prototype.createDebugData=function(){return{decoderName:"BarcodeDetector"}},t})(),ul=function(t,r,o,c){function u(f){return f instanceof o?f:new o(function(p){p(f)})}return new(o||(o=Promise))(function(f,p){function x(A){try{g(c.next(A))}catch(E){p(E)}}function _(A){try{g(c.throw(A))}catch(E){p(E)}}function g(A){A.done?f(A.value):u(A.value).then(x,_)}g((c=c.apply(t,r||[])).next())})},dl=function(t,r){var o={label:0,sent:function(){if(f[0]&1)throw f[1];return f[1]},trys:[],ops:[]},c,u,f,p;return p={next:x(0),throw:x(1),return:x(2)},typeof Symbol=="function"&&(p[Symbol.iterator]=function(){return this}),p;function x(g){return function(A){return _([g,A])}}function _(g){if(c)throw new TypeError("Generator is already executing.");for(;p&&(p=0,g[0]&&(o=0)),o;)try{if(c=1,u&&(f=g[0]&2?u.return:g[0]?u.throw||((f=u.return)&&f.call(u),0):u.next)&&!(f=f.call(u,g[1])).done)return f;switch(u=0,f&&(g=[g[0]&2,f.value]),g[0]){case 0:case 1:f=g;break;case 4:return o.label++,{value:g[1],done:!1};case 5:o.label++,u=g[1],g=[0];continue;case 7:g=o.ops.pop(),o.trys.pop();continue;default:if(f=o.trys,!(f=f.length>0&&f[f.length-1])&&(g[0]===6||g[0]===2)){o=0;continue}if(g[0]===3&&(!f||g[1]>f[0]&&g[1]<f[3])){o.label=g[1];break}if(g[0]===6&&o.label<f[1]){o.label=f[1],f=g;break}if(f&&o.label<f[2]){o.label=f[2],o.ops.push(g);break}f[2]&&o.ops.pop(),o.trys.pop();continue}g=r.call(t,o)}catch(A){g=[6,A],u=0}finally{c=f=0}if(g[0]&5)throw g[1];return{value:g[0]?g[1]:void 0,done:!0}}},iw=(function(){function t(r,o,c,u){this.EXECUTIONS_TO_REPORT_PERFORMANCE=100,this.executions=0,this.executionResults=[],this.wasPrimaryDecoderUsedInLastDecode=!1,this.verbose=c,o&&cl.isSupported()?(this.primaryDecoder=new cl(r,c,u),this.secondaryDecoder=new ll(r,c,u)):this.primaryDecoder=new ll(r,c,u)}return t.prototype.decodeAsync=function(r){return ul(this,void 0,void 0,function(){var o;return dl(this,function(c){switch(c.label){case 0:o=performance.now(),c.label=1;case 1:return c.trys.push([1,,3,4]),[4,this.getDecoder().decodeAsync(r)];case 2:return[2,c.sent()];case 3:return this.possiblyLogPerformance(o),[7];case 4:return[2]}})})},t.prototype.decodeRobustlyAsync=function(r){return ul(this,void 0,void 0,function(){var o,c;return dl(this,function(u){switch(u.label){case 0:o=performance.now(),u.label=1;case 1:return u.trys.push([1,3,4,5]),[4,this.primaryDecoder.decodeAsync(r)];case 2:return[2,u.sent()];case 3:if(c=u.sent(),this.secondaryDecoder)return[2,this.secondaryDecoder.decodeAsync(r)];throw c;case 4:return this.possiblyLogPerformance(o),[7];case 5:return[2]}})})},t.prototype.getDecoder=function(){return this.secondaryDecoder?this.wasPrimaryDecoderUsedInLastDecode===!1?(this.wasPrimaryDecoderUsedInLastDecode=!0,this.primaryDecoder):(this.wasPrimaryDecoderUsedInLastDecode=!1,this.secondaryDecoder):this.primaryDecoder},t.prototype.possiblyLogPerformance=function(r){if(this.verbose){var o=performance.now()-r;this.executionResults.push(o),this.executions++,this.possiblyFlushPerformanceReport()}},t.prototype.possiblyFlushPerformanceReport=function(){if(!(this.executions<this.EXECUTIONS_TO_REPORT_PERFORMANCE)){for(var r=0,o=0,c=this.executionResults;o<c.length;o++){var u=c[o];r+=u}var f=r/this.executionResults.length;console.log("".concat(f," ms for ").concat(this.executionResults.length," last runs.")),this.executions=0,this.executionResults=[]}},t})(),is=(function(){var t=function(r,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,u){c.__proto__=u}||function(c,u){for(var f in u)Object.prototype.hasOwnProperty.call(u,f)&&(c[f]=u[f])},t(r,o)};return function(r,o){if(typeof o!="function"&&o!==null)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");t(r,o);function c(){this.constructor=r}r.prototype=o===null?Object.create(o):(c.prototype=o.prototype,new c)}})(),Li=function(t,r,o,c){function u(f){return f instanceof o?f:new o(function(p){p(f)})}return new(o||(o=Promise))(function(f,p){function x(A){try{g(c.next(A))}catch(E){p(E)}}function _(A){try{g(c.throw(A))}catch(E){p(E)}}function g(A){A.done?f(A.value):u(A.value).then(x,_)}g((c=c.apply(t,r||[])).next())})},Fi=function(t,r){var o={label:0,sent:function(){if(f[0]&1)throw f[1];return f[1]},trys:[],ops:[]},c,u,f,p;return p={next:x(0),throw:x(1),return:x(2)},typeof Symbol=="function"&&(p[Symbol.iterator]=function(){return this}),p;function x(g){return function(A){return _([g,A])}}function _(g){if(c)throw new TypeError("Generator is already executing.");for(;p&&(p=0,g[0]&&(o=0)),o;)try{if(c=1,u&&(f=g[0]&2?u.return:g[0]?u.throw||((f=u.return)&&f.call(u),0):u.next)&&!(f=f.call(u,g[1])).done)return f;switch(u=0,f&&(g=[g[0]&2,f.value]),g[0]){case 0:case 1:f=g;break;case 4:return o.label++,{value:g[1],done:!1};case 5:o.label++,u=g[1],g=[0];continue;case 7:g=o.ops.pop(),o.trys.pop();continue;default:if(f=o.trys,!(f=f.length>0&&f[f.length-1])&&(g[0]===6||g[0]===2)){o=0;continue}if(g[0]===3&&(!f||g[1]>f[0]&&g[1]<f[3])){o.label=g[1];break}if(g[0]===6&&o.label<f[1]){o.label=f[1],f=g;break}if(f&&o.label<f[2]){o.label=f[2],o.ops.push(g);break}f[2]&&o.ops.pop(),o.trys.pop();continue}g=r.call(t,o)}catch(A){g=[6,A],u=0}finally{c=f=0}if(g[0]&5)throw g[1];return{value:g[0]?g[1]:void 0,done:!0}}},Hu=(function(){function t(r,o){this.name=r,this.track=o}return t.prototype.isSupported=function(){return this.track.getCapabilities?this.name in this.track.getCapabilities():!1},t.prototype.apply=function(r){var o={};o[this.name]=r;var c={advanced:[o]};return this.track.applyConstraints(c)},t.prototype.value=function(){var r=this.track.getSettings();if(this.name in r){var o=r[this.name];return o}return null},t})(),ow=(function(t){is(r,t);function r(o,c){return t.call(this,o,c)||this}return r.prototype.min=function(){return this.getCapabilities().min},r.prototype.max=function(){return this.getCapabilities().max},r.prototype.step=function(){return this.getCapabilities().step},r.prototype.apply=function(o){var c={};c[this.name]=o;var u={advanced:[c]};return this.track.applyConstraints(u)},r.prototype.getCapabilities=function(){this.failIfNotSupported();var o=this.track.getCapabilities(),c=o[this.name];return{min:c.min,max:c.max,step:c.step}},r.prototype.failIfNotSupported=function(){if(!this.isSupported())throw new Error("".concat(this.name," capability not supported"))},r})(Hu),sw=(function(t){is(r,t);function r(o){return t.call(this,"zoom",o)||this}return r})(ow),aw=(function(t){is(r,t);function r(o){return t.call(this,"torch",o)||this}return r})(Hu),lw=(function(){function t(r){this.track=r}return t.prototype.zoomFeature=function(){return new sw(this.track)},t.prototype.torchFeature=function(){return new aw(this.track)},t})(),cw=(function(){function t(r,o,c){this.isClosed=!1,this.parentElement=r,this.mediaStream=o,this.callbacks=c,this.surface=this.createVideoElement(this.parentElement.clientWidth),r.append(this.surface)}return t.prototype.createVideoElement=function(r){var o=document.createElement("video");return o.style.width="".concat(r,"px"),o.style.display="block",o.muted=!0,o.setAttribute("muted","true"),o.playsInline=!0,o},t.prototype.setupSurface=function(){var r=this;this.surface.onabort=function(){throw"RenderedCameraImpl video surface onabort() called"},this.surface.onerror=function(){throw"RenderedCameraImpl video surface onerror() called"};var o=function(){var c=r.surface.clientWidth,u=r.surface.clientHeight;r.callbacks.onRenderSurfaceReady(c,u),r.surface.removeEventListener("playing",o)};this.surface.addEventListener("playing",o),this.surface.srcObject=this.mediaStream,this.surface.play()},t.create=function(r,o,c,u){return Li(this,void 0,void 0,function(){var f,p;return Fi(this,function(x){switch(x.label){case 0:return f=new t(r,o,u),c.aspectRatio?(p={aspectRatio:c.aspectRatio},[4,f.getFirstTrackOrFail().applyConstraints(p)]):[3,2];case 1:x.sent(),x.label=2;case 2:return f.setupSurface(),[2,f]}})})},t.prototype.failIfClosed=function(){if(this.isClosed)throw"The RenderedCamera has already been closed."},t.prototype.getFirstTrackOrFail=function(){if(this.failIfClosed(),this.mediaStream.getVideoTracks().length===0)throw"No video tracks found";return this.mediaStream.getVideoTracks()[0]},t.prototype.pause=function(){this.failIfClosed(),this.surface.pause()},t.prototype.resume=function(r){this.failIfClosed();var o=this,c=function(){setTimeout(r,200),o.surface.removeEventListener("playing",c)};this.surface.addEventListener("playing",c),this.surface.play()},t.prototype.isPaused=function(){return this.failIfClosed(),this.surface.paused},t.prototype.getSurface=function(){return this.failIfClosed(),this.surface},t.prototype.getRunningTrackCapabilities=function(){return this.getFirstTrackOrFail().getCapabilities()},t.prototype.getRunningTrackSettings=function(){return this.getFirstTrackOrFail().getSettings()},t.prototype.applyVideoConstraints=function(r){return Li(this,void 0,void 0,function(){return Fi(this,function(o){if("aspectRatio"in r)throw"Changing 'aspectRatio' in run-time is not yet supported.";return[2,this.getFirstTrackOrFail().applyConstraints(r)]})})},t.prototype.close=function(){if(this.isClosed)return Promise.resolve();var r=this;return new Promise(function(o,c){var u=r.mediaStream.getVideoTracks(),f=u.length,p=0;r.mediaStream.getVideoTracks().forEach(function(x){r.mediaStream.removeTrack(x),x.stop(),++p,p>=f&&(r.isClosed=!0,r.parentElement.removeChild(r.surface),o())})})},t.prototype.getCapabilities=function(){return new lw(this.getFirstTrackOrFail())},t})(),uw=(function(){function t(r){this.mediaStream=r}return t.prototype.render=function(r,o,c){return Li(this,void 0,void 0,function(){return Fi(this,function(u){return[2,cw.create(r,this.mediaStream,o,c)]})})},t.create=function(r){return Li(this,void 0,void 0,function(){var o,c;return Fi(this,function(u){switch(u.label){case 0:if(!navigator.mediaDevices)throw"navigator.mediaDevices not supported";return o={audio:!1,video:r},[4,navigator.mediaDevices.getUserMedia(o)];case 1:return c=u.sent(),[2,new t(c)]}})})},t})(),fl=function(t,r,o,c){function u(f){return f instanceof o?f:new o(function(p){p(f)})}return new(o||(o=Promise))(function(f,p){function x(A){try{g(c.next(A))}catch(E){p(E)}}function _(A){try{g(c.throw(A))}catch(E){p(E)}}function g(A){A.done?f(A.value):u(A.value).then(x,_)}g((c=c.apply(t,r||[])).next())})},hl=function(t,r){var o={label:0,sent:function(){if(f[0]&1)throw f[1];return f[1]},trys:[],ops:[]},c,u,f,p;return p={next:x(0),throw:x(1),return:x(2)},typeof Symbol=="function"&&(p[Symbol.iterator]=function(){return this}),p;function x(g){return function(A){return _([g,A])}}function _(g){if(c)throw new TypeError("Generator is already executing.");for(;p&&(p=0,g[0]&&(o=0)),o;)try{if(c=1,u&&(f=g[0]&2?u.return:g[0]?u.throw||((f=u.return)&&f.call(u),0):u.next)&&!(f=f.call(u,g[1])).done)return f;switch(u=0,f&&(g=[g[0]&2,f.value]),g[0]){case 0:case 1:f=g;break;case 4:return o.label++,{value:g[1],done:!1};case 5:o.label++,u=g[1],g=[0];continue;case 7:g=o.ops.pop(),o.trys.pop();continue;default:if(f=o.trys,!(f=f.length>0&&f[f.length-1])&&(g[0]===6||g[0]===2)){o=0;continue}if(g[0]===3&&(!f||g[1]>f[0]&&g[1]<f[3])){o.label=g[1];break}if(g[0]===6&&o.label<f[1]){o.label=f[1],f=g;break}if(f&&o.label<f[2]){o.label=f[2],o.ops.push(g);break}f[2]&&o.ops.pop(),o.trys.pop();continue}g=r.call(t,o)}catch(A){g=[6,A],u=0}finally{c=f=0}if(g[0]&5)throw g[1];return{value:g[0]?g[1]:void 0,done:!0}}},dw=(function(){function t(){}return t.failIfNotSupported=function(){return fl(this,void 0,void 0,function(){return hl(this,function(r){if(!navigator.mediaDevices)throw"navigator.mediaDevices not supported";return[2,new t]})})},t.prototype.create=function(r){return fl(this,void 0,void 0,function(){return hl(this,function(o){return[2,uw.create(r)]})})},t})(),fw=function(t,r,o,c){function u(f){return f instanceof o?f:new o(function(p){p(f)})}return new(o||(o=Promise))(function(f,p){function x(A){try{g(c.next(A))}catch(E){p(E)}}function _(A){try{g(c.throw(A))}catch(E){p(E)}}function g(A){A.done?f(A.value):u(A.value).then(x,_)}g((c=c.apply(t,r||[])).next())})},hw=function(t,r){var o={label:0,sent:function(){if(f[0]&1)throw f[1];return f[1]},trys:[],ops:[]},c,u,f,p;return p={next:x(0),throw:x(1),return:x(2)},typeof Symbol=="function"&&(p[Symbol.iterator]=function(){return this}),p;function x(g){return function(A){return _([g,A])}}function _(g){if(c)throw new TypeError("Generator is already executing.");for(;p&&(p=0,g[0]&&(o=0)),o;)try{if(c=1,u&&(f=g[0]&2?u.return:g[0]?u.throw||((f=u.return)&&f.call(u),0):u.next)&&!(f=f.call(u,g[1])).done)return f;switch(u=0,f&&(g=[g[0]&2,f.value]),g[0]){case 0:case 1:f=g;break;case 4:return o.label++,{value:g[1],done:!1};case 5:o.label++,u=g[1],g=[0];continue;case 7:g=o.ops.pop(),o.trys.pop();continue;default:if(f=o.trys,!(f=f.length>0&&f[f.length-1])&&(g[0]===6||g[0]===2)){o=0;continue}if(g[0]===3&&(!f||g[1]>f[0]&&g[1]<f[3])){o.label=g[1];break}if(g[0]===6&&o.label<f[1]){o.label=f[1],f=g;break}if(f&&o.label<f[2]){o.label=f[2],o.ops.push(g);break}f[2]&&o.ops.pop(),o.trys.pop();continue}g=r.call(t,o)}catch(A){g=[6,A],u=0}finally{c=f=0}if(g[0]&5)throw g[1];return{value:g[0]?g[1]:void 0,done:!0}}},pw=(function(){function t(){}return t.retrieve=function(){if(navigator.mediaDevices)return t.getCamerasFromMediaDevices();var r=MediaStreamTrack;return MediaStreamTrack&&r.getSources?t.getCamerasFromMediaStreamTrack():t.rejectWithError()},t.rejectWithError=function(){var r=Ir.unableToQuerySupportedDevices();return t.isHttpsOrLocalhost()||(r=Ir.insecureContextCameraQueryError()),Promise.reject(r)},t.isHttpsOrLocalhost=function(){if(location.protocol==="https:")return!0;var r=location.host.split(":")[0];return r==="127.0.0.1"||r==="localhost"},t.getCamerasFromMediaDevices=function(){return fw(this,void 0,void 0,function(){var r,o,c,u,f,p,x;return hw(this,function(_){switch(_.label){case 0:return r=function(g){for(var A=g.getVideoTracks(),E=0,L=A;E<L.length;E++){var M=L[E];M.enabled=!1,M.stop(),g.removeTrack(M)}},[4,navigator.mediaDevices.getUserMedia({audio:!1,video:!0})];case 1:return o=_.sent(),[4,navigator.mediaDevices.enumerateDevices()];case 2:for(c=_.sent(),u=[],f=0,p=c;f<p.length;f++)x=p[f],x.kind==="videoinput"&&u.push({id:x.deviceId,label:x.label});return r(o),[2,u]}})})},t.getCamerasFromMediaStreamTrack=function(){return new Promise(function(r,o){var c=function(f){for(var p=[],x=0,_=f;x<_.length;x++){var g=_[x];g.kind==="video"&&p.push({id:g.id,label:g.label})}r(p)},u=MediaStreamTrack;u.getSources(c)})},t})(),Tt;(function(t){t[t.UNKNOWN=0]="UNKNOWN",t[t.NOT_STARTED=1]="NOT_STARTED",t[t.SCANNING=2]="SCANNING",t[t.PAUSED=3]="PAUSED"})(Tt||(Tt={}));var mw=(function(){function t(){this.state=Tt.NOT_STARTED,this.onGoingTransactionNewState=Tt.UNKNOWN}return t.prototype.directTransition=function(r){this.failIfTransitionOngoing(),this.validateTransition(r),this.state=r},t.prototype.startTransition=function(r){return this.failIfTransitionOngoing(),this.validateTransition(r),this.onGoingTransactionNewState=r,this},t.prototype.execute=function(){if(this.onGoingTransactionNewState===Tt.UNKNOWN)throw"Transaction is already cancelled, cannot execute().";var r=this.onGoingTransactionNewState;this.onGoingTransactionNewState=Tt.UNKNOWN,this.directTransition(r)},t.prototype.cancel=function(){if(this.onGoingTransactionNewState===Tt.UNKNOWN)throw"Transaction is already cancelled, cannot cancel().";this.onGoingTransactionNewState=Tt.UNKNOWN},t.prototype.getState=function(){return this.state},t.prototype.failIfTransitionOngoing=function(){if(this.onGoingTransactionNewState!==Tt.UNKNOWN)throw"Cannot transition to a new state, already under transition"},t.prototype.validateTransition=function(r){switch(this.state){case Tt.UNKNOWN:throw"Transition from unknown is not allowed";case Tt.NOT_STARTED:this.failIfNewStateIs(r,[Tt.PAUSED]);break;case Tt.SCANNING:break;case Tt.PAUSED:break}},t.prototype.failIfNewStateIs=function(r,o){for(var c=0,u=o;c<u.length;c++){var f=u[c];if(r===f)throw"Cannot transition from ".concat(this.state," to ").concat(r)}},t})(),gw=(function(){function t(r){this.stateManager=r}return t.prototype.startTransition=function(r){return this.stateManager.startTransition(r)},t.prototype.directTransition=function(r){this.stateManager.directTransition(r)},t.prototype.getState=function(){return this.stateManager.getState()},t.prototype.canScanFile=function(){return this.stateManager.getState()===Tt.NOT_STARTED},t.prototype.isScanning=function(){return this.stateManager.getState()!==Tt.NOT_STARTED},t.prototype.isStrictlyScanning=function(){return this.stateManager.getState()===Tt.SCANNING},t.prototype.isPaused=function(){return this.stateManager.getState()===Tt.PAUSED},t})(),xw=(function(){function t(){}return t.create=function(){return new gw(new mw)},t})(),yw=(function(){var t=function(r,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,u){c.__proto__=u}||function(c,u){for(var f in u)Object.prototype.hasOwnProperty.call(u,f)&&(c[f]=u[f])},t(r,o)};return function(r,o){if(typeof o!="function"&&o!==null)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");t(r,o);function c(){this.constructor=r}r.prototype=o===null?Object.create(o):(c.prototype=o.prototype,new c)}})(),sn=(function(t){yw(r,t);function r(){return t!==null&&t.apply(this,arguments)||this}return r.DEFAULT_WIDTH=300,r.DEFAULT_WIDTH_OFFSET=2,r.FILE_SCAN_MIN_HEIGHT=300,r.FILE_SCAN_HIDDEN_CANVAS_PADDING=100,r.MIN_QR_BOX_SIZE=50,r.SHADED_LEFT=1,r.SHADED_RIGHT=2,r.SHADED_TOP=3,r.SHADED_BOTTOM=4,r.SHADED_REGION_ELEMENT_ID="qr-shaded-region",r.VERBOSE=!1,r.BORDER_SHADER_DEFAULT_COLOR="#ffffff",r.BORDER_SHADER_MATCH_COLOR="rgb(90, 193, 56)",r})(qy),ww=(function(){function t(r,o){this.logger=o,this.fps=sn.SCAN_DEFAULT_FPS,r?(r.fps&&(this.fps=r.fps),this.disableFlip=r.disableFlip===!0,this.qrbox=r.qrbox,this.aspectRatio=r.aspectRatio,this.videoConstraints=r.videoConstraints):this.disableFlip=sn.DEFAULT_DISABLE_FLIP}return t.prototype.isMediaStreamConstraintsValid=function(){return this.videoConstraints?ju.isMediaStreamConstraintsValid(this.videoConstraints,this.logger):(this.logger.logError("Empty videoConstraints",!0),!1)},t.prototype.isShadedBoxEnabled=function(){return!Mn(this.qrbox)},t.create=function(r,o){return new t(r,o)},t})(),pl=(function(){function t(r,o){if(this.element=null,this.canvasElement=null,this.scannerPausedUiElement=null,this.hasBorderShaders=null,this.borderShaders=null,this.qrMatch=null,this.renderedCamera=null,this.qrRegion=null,this.context=null,this.lastScanImageFile=null,this.isScanning=!1,!document.getElementById(r))throw"HTML Element with id=".concat(r," not found");this.elementId=r,this.verbose=!1;var c;typeof o=="boolean"?this.verbose=o===!0:o&&(c=o,this.verbose=c.verbose===!0,c.experimentalFeatures),this.logger=new Jy(this.verbose),this.qrcode=new iw(this.getSupportedFormats(o),this.getUseBarCodeDetectorIfSupported(c),this.verbose,this.logger),this.foreverScanTimeout,this.shouldScan=!0,this.stateManagerProxy=xw.create()}return t.prototype.start=function(r,o,c,u){var f=this;if(!r)throw"cameraIdOrConfig is required";if(!c||typeof c!="function")throw"qrCodeSuccessCallback is required and should be a function.";var p;u?p=u:p=this.verbose?this.logger.log:function(){};var x=ww.create(o,this.logger);this.clearElement();var _=!1;x.videoConstraints&&(x.isMediaStreamConstraintsValid()?_=!0:this.logger.logError("'videoConstraints' is not valid 'MediaStreamConstraints, it will be ignored.'",!0));var g=_,A=document.getElementById(this.elementId);A.clientWidth?A.clientWidth:sn.DEFAULT_WIDTH,A.style.position="relative",this.shouldScan=!0,this.element=A;var E=this,L=this.stateManagerProxy.startTransition(Tt.SCANNING);return new Promise(function(M,D){var R=g?x.videoConstraints:E.createVideoConstraints(r);if(!R){L.cancel(),D("videoConstraints should be defined");return}var P={};(!g||x.aspectRatio)&&(P.aspectRatio=x.aspectRatio);var H={onRenderSurfaceReady:function(Z,$){E.setupUi(Z,$,x),E.isScanning=!0,E.foreverScan(x,c,p)}};dw.failIfNotSupported().then(function(Z){Z.create(R).then(function($){return $.render(f.element,P,H).then(function(V){E.renderedCamera=V,L.execute(),M(null)}).catch(function(V){L.cancel(),D(V)})}).catch(function($){L.cancel(),D(Ir.errorGettingUserMedia($))})}).catch(function(Z){L.cancel(),D(Ir.cameraStreamingNotSupported())})})},t.prototype.pause=function(r){if(!this.stateManagerProxy.isStrictlyScanning())throw"Cannot pause, scanner is not scanning.";this.stateManagerProxy.directTransition(Tt.PAUSED),this.showPausedState(),(Mn(r)||r!==!0)&&(r=!1),r&&this.renderedCamera&&this.renderedCamera.pause()},t.prototype.resume=function(){if(!this.stateManagerProxy.isPaused())throw"Cannot result, scanner is not paused.";if(!this.renderedCamera)throw"renderedCamera doesn't exist while trying resume()";var r=this,o=function(){r.stateManagerProxy.directTransition(Tt.SCANNING),r.hidePausedState()};if(!this.renderedCamera.isPaused()){o();return}this.renderedCamera.resume(function(){o()})},t.prototype.getState=function(){return this.stateManagerProxy.getState()},t.prototype.stop=function(){var r=this;if(!this.stateManagerProxy.isScanning())throw"Cannot stop, scanner is not running or paused.";var o=this.stateManagerProxy.startTransition(Tt.NOT_STARTED);this.shouldScan=!1,this.foreverScanTimeout&&clearTimeout(this.foreverScanTimeout);var c=function(){if(r.element){var f=document.getElementById(sn.SHADED_REGION_ELEMENT_ID);f&&r.element.removeChild(f)}},u=this;return this.renderedCamera.close().then(function(){return u.renderedCamera=null,u.element&&(u.element.removeChild(u.canvasElement),u.canvasElement=null),c(),u.qrRegion&&(u.qrRegion=null),u.context&&(u.context=null),o.execute(),u.hidePausedState(),u.isScanning=!1,Promise.resolve()})},t.prototype.scanFile=function(r,o){return this.scanFileV2(r,o).then(function(c){return c.decodedText})},t.prototype.scanFileV2=function(r,o){var c=this;if(!r||!(r instanceof File))throw"imageFile argument is mandatory and should be instance of File. Use 'event.target.files[0]'.";if(Mn(o)&&(o=!0),!this.stateManagerProxy.canScanFile())throw"Cannot start file scan - ongoing camera scan";return new Promise(function(u,f){c.possiblyCloseLastScanImageFile(),c.clearElement(),c.lastScanImageFile=URL.createObjectURL(r);var p=new Image;p.onload=function(){var x=p.width,_=p.height,g=document.getElementById(c.elementId),A=g.clientWidth?g.clientWidth:sn.DEFAULT_WIDTH,E=Math.max(g.clientHeight?g.clientHeight:_,sn.FILE_SCAN_MIN_HEIGHT),L=c.computeCanvasDrawConfig(x,_,A,E);if(o){var M=c.createCanvasElement(A,E,"qr-canvas-visible");M.style.display="inline-block",g.appendChild(M);var D=M.getContext("2d");if(!D)throw"Unable to get 2d context from canvas";D.canvas.width=A,D.canvas.height=E,D.drawImage(p,0,0,x,_,L.x,L.y,L.width,L.height)}var R=sn.FILE_SCAN_HIDDEN_CANVAS_PADDING,P=Math.max(p.width,L.width),H=Math.max(p.height,L.height),Z=P+2*R,$=H+2*R,V=c.createCanvasElement(Z,$);g.appendChild(V);var ee=V.getContext("2d");if(!ee)throw"Unable to get 2d context from canvas";ee.canvas.width=Z,ee.canvas.height=$,ee.drawImage(p,0,0,x,_,R,R,P,H);try{c.qrcode.decodeRobustlyAsync(V).then(function(j){u(sl.createFromQrcodeResult(j))}).catch(f)}catch(j){f("QR code parse error, error = ".concat(j))}},p.onerror=f,p.onabort=f,p.onstalled=f,p.onsuspend=f,p.src=URL.createObjectURL(r)})},t.prototype.clear=function(){this.clearElement()},t.getCameras=function(){return pw.retrieve()},t.prototype.getRunningTrackCapabilities=function(){return this.getRenderedCameraOrFail().getRunningTrackCapabilities()},t.prototype.getRunningTrackSettings=function(){return this.getRenderedCameraOrFail().getRunningTrackSettings()},t.prototype.getRunningTrackCameraCapabilities=function(){return this.getRenderedCameraOrFail().getCapabilities()},t.prototype.applyVideoConstraints=function(r){if(r){if(!ju.isMediaStreamConstraintsValid(r,this.logger))throw"invalid videoConstaints passed, check logs for more details"}else throw"videoConstaints is required argument.";return this.getRenderedCameraOrFail().applyVideoConstraints(r)},t.prototype.getRenderedCameraOrFail=function(){if(this.renderedCamera==null)throw"Scanning is not in running state, call this API only when QR code scanning using camera is in running state.";return this.renderedCamera},t.prototype.getSupportedFormats=function(r){var o=[ve.QR_CODE,ve.AZTEC,ve.CODABAR,ve.CODE_39,ve.CODE_93,ve.CODE_128,ve.DATA_MATRIX,ve.MAXICODE,ve.ITF,ve.EAN_13,ve.EAN_8,ve.PDF_417,ve.RSS_14,ve.RSS_EXPANDED,ve.UPC_A,ve.UPC_E,ve.UPC_EAN_EXTENSION];if(!r||typeof r=="boolean"||!r.formatsToSupport)return o;if(!Array.isArray(r.formatsToSupport))throw"configOrVerbosityFlag.formatsToSupport should be undefined or an array.";if(r.formatsToSupport.length===0)throw"Atleast 1 formatsToSupport is needed.";for(var c=[],u=0,f=r.formatsToSupport;u<f.length;u++){var p=f[u];Xy(p)?c.push(p):this.logger.warn("Invalid format: ".concat(p," passed in config, ignoring."))}if(c.length===0)throw"None of formatsToSupport match supported values.";return c},t.prototype.getUseBarCodeDetectorIfSupported=function(r){if(Mn(r))return!0;if(!Mn(r.useBarCodeDetectorIfSupported))return r.useBarCodeDetectorIfSupported!==!1;if(Mn(r.experimentalFeatures))return!0;var o=r.experimentalFeatures;return Mn(o.useBarCodeDetectorIfSupported)?!0:o.useBarCodeDetectorIfSupported!==!1},t.prototype.validateQrboxSize=function(r,o,c){var u=this,f=c.qrbox;this.validateQrboxConfig(f);var p=this.toQrdimensions(r,o,f),x=function(g){if(g<sn.MIN_QR_BOX_SIZE)throw"minimum size of 'config.qrbox' dimension value is"+" ".concat(sn.MIN_QR_BOX_SIZE,"px.")},_=function(g){return g>r&&(u.logger.warn("`qrbox.width` or `qrbox` is larger than the width of the root element. The width will be truncated to the width of root element."),g=r),g};x(p.width),x(p.height),p.width=_(p.width)},t.prototype.validateQrboxConfig=function(r){if(typeof r!="number"&&typeof r!="function"&&(r.width===void 0||r.height===void 0))throw"Invalid instance of QrDimensions passed for 'config.qrbox'. Both 'width' and 'height' should be set."},t.prototype.toQrdimensions=function(r,o,c){if(typeof c=="number")return{width:c,height:c};if(typeof c=="function")try{return c(r,o)}catch(u){throw new Error("qrbox config was passed as a function but it failed with unknown error"+u)}return c},t.prototype.setupUi=function(r,o,c){c.isShadedBoxEnabled()&&this.validateQrboxSize(r,o,c);var u=Mn(c.qrbox)?{width:r,height:o}:c.qrbox;this.validateQrboxConfig(u);var f=this.toQrdimensions(r,o,u);f.height>o&&this.logger.warn("[Html5Qrcode] config.qrbox has height that isgreater than the height of the video stream. Shading will be ignored");var p=c.isShadedBoxEnabled()&&f.height<=o,x={x:0,y:0,width:r,height:o},_=p?this.getShadedRegionBounds(r,o,f):x,g=this.createCanvasElement(_.width,_.height),A={willReadFrequently:!0},E=g.getContext("2d",A);E.canvas.width=_.width,E.canvas.height=_.height,this.element.append(g),p&&this.possiblyInsertShadingElement(this.element,r,o,f),this.createScannerPausedUiElement(this.element),this.qrRegion=_,this.context=E,this.canvasElement=g},t.prototype.createScannerPausedUiElement=function(r){var o=document.createElement("div");o.innerText=Ir.scannerPaused(),o.style.display="none",o.style.position="absolute",o.style.top="0px",o.style.zIndex="1",o.style.background="rgba(9, 9, 9, 0.46)",o.style.color="#FFECEC",o.style.textAlign="center",o.style.width="100%",r.appendChild(o),this.scannerPausedUiElement=o},t.prototype.scanContext=function(r,o){var c=this;return this.stateManagerProxy.isPaused()?Promise.resolve(!1):this.qrcode.decodeAsync(this.canvasElement).then(function(u){return r(u.text,sl.createFromQrcodeResult(u)),c.possiblyUpdateShaders(!0),!0}).catch(function(u){c.possiblyUpdateShaders(!1);var f=Ir.codeParseError(u);return o(f,Yy.createFrom(f)),!1})},t.prototype.foreverScan=function(r,o,c){var u=this;if(this.shouldScan&&this.renderedCamera){var f=this.renderedCamera.getSurface(),p=f.videoWidth/f.clientWidth,x=f.videoHeight/f.clientHeight;if(!this.qrRegion)throw"qrRegion undefined when localMediaStream is ready.";var _=this.qrRegion.width*p,g=this.qrRegion.height*x,A=this.qrRegion.x*p,E=this.qrRegion.y*x;this.context.drawImage(f,A,E,_,g,0,0,this.qrRegion.width,this.qrRegion.height);var L=function(){u.foreverScanTimeout=setTimeout(function(){u.foreverScan(r,o,c)},u.getTimeoutFps(r.fps))};this.scanContext(o,c).then(function(M){!M&&r.disableFlip!==!0?(u.context.translate(u.context.canvas.width,0),u.context.scale(-1,1),u.scanContext(o,c).finally(function(){L()})):L()}).catch(function(M){u.logger.logError("Error happend while scanning context",M),L()})}},t.prototype.createVideoConstraints=function(r){if(typeof r=="string")return{deviceId:{exact:r}};if(typeof r=="object"){var o="facingMode",c="deviceId",u={user:!0,environment:!0},f="exact",p=function(D){if(D in u)return!0;throw"config has invalid 'facingMode' value = "+"'".concat(D,"'")},x=Object.keys(r);if(x.length!==1)throw"'cameraIdOrConfig' object should have exactly 1 key,"+" if passed as an object, found ".concat(x.length," keys");var _=Object.keys(r)[0];if(_!==o&&_!==c)throw"Only '".concat(o,"' and '").concat(c,"' ")+" are supported for 'cameraIdOrConfig'";if(_===o){var g=r.facingMode;if(typeof g=="string"){if(p(g))return{facingMode:g}}else if(typeof g=="object")if(f in g){if(p(g["".concat(f)]))return{facingMode:{exact:g["".concat(f)]}}}else throw"'facingMode' should be string or object with"+" ".concat(f," as key.");else{var A=typeof g;throw"Invalid type of 'facingMode' = ".concat(A)}}else{var E=r.deviceId;if(typeof E=="string")return{deviceId:E};if(typeof E=="object"){if(f in E)return{deviceId:{exact:E["".concat(f)]}};throw"'deviceId' should be string or object with"+" ".concat(f," as key.")}else{var L=typeof E;throw"Invalid type of 'deviceId' = ".concat(L)}}}var M=typeof r;throw"Invalid type of 'cameraIdOrConfig' = ".concat(M)},t.prototype.computeCanvasDrawConfig=function(r,o,c,u){if(r<=c&&o<=u){var f=(c-r)/2,p=(u-o)/2;return{x:f,y:p,width:r,height:o}}else{var x=r,_=o;return r>c&&(o=c/r*o,r=c),o>u&&(r=u/o*r,o=u),this.logger.log("Image downsampled from "+"".concat(x,"X").concat(_)+" to ".concat(r,"X").concat(o,".")),this.computeCanvasDrawConfig(r,o,c,u)}},t.prototype.clearElement=function(){if(this.stateManagerProxy.isScanning())throw"Cannot clear while scan is ongoing, close it first.";var r=document.getElementById(this.elementId);r&&(r.innerHTML="")},t.prototype.possiblyUpdateShaders=function(r){this.qrMatch!==r&&(this.hasBorderShaders&&this.borderShaders&&this.borderShaders.length&&this.borderShaders.forEach(function(o){o.style.backgroundColor=r?sn.BORDER_SHADER_MATCH_COLOR:sn.BORDER_SHADER_DEFAULT_COLOR}),this.qrMatch=r)},t.prototype.possiblyCloseLastScanImageFile=function(){this.lastScanImageFile&&(URL.revokeObjectURL(this.lastScanImageFile),this.lastScanImageFile=null)},t.prototype.createCanvasElement=function(r,o,c){var u=r,f=o,p=document.createElement("canvas");return p.style.width="".concat(u,"px"),p.style.height="".concat(f,"px"),p.style.display="none",p.id=Mn(c)?"qr-canvas":c,p},t.prototype.getShadedRegionBounds=function(r,o,c){if(c.width>r||c.height>o)throw"'config.qrbox' dimensions should not be greater than the dimensions of the root HTML element.";return{x:(r-c.width)/2,y:(o-c.height)/2,width:c.width,height:c.height}},t.prototype.possiblyInsertShadingElement=function(r,o,c,u){if(!(o-u.width<1||c-u.height<1)){var f=document.createElement("div");f.style.position="absolute";var p=(o-u.width)/2,x=(c-u.height)/2;if(f.style.borderLeft="".concat(p,"px solid rgba(0, 0, 0, 0.48)"),f.style.borderRight="".concat(p,"px solid rgba(0, 0, 0, 0.48)"),f.style.borderTop="".concat(x,"px solid rgba(0, 0, 0, 0.48)"),f.style.borderBottom="".concat(x,"px solid rgba(0, 0, 0, 0.48)"),f.style.boxSizing="border-box",f.style.top="0px",f.style.bottom="0px",f.style.left="0px",f.style.right="0px",f.id="".concat(sn.SHADED_REGION_ELEMENT_ID),o-u.width<11||c-u.height<11)this.hasBorderShaders=!1;else{var _=5,g=40;this.insertShaderBorders(f,g,_,-_,null,0,!0),this.insertShaderBorders(f,g,_,-_,null,0,!1),this.insertShaderBorders(f,g,_,null,-_,0,!0),this.insertShaderBorders(f,g,_,null,-_,0,!1),this.insertShaderBorders(f,_,g+_,-_,null,-_,!0),this.insertShaderBorders(f,_,g+_,null,-_,-_,!0),this.insertShaderBorders(f,_,g+_,-_,null,-_,!1),this.insertShaderBorders(f,_,g+_,null,-_,-_,!1),this.hasBorderShaders=!0}r.append(f)}},t.prototype.insertShaderBorders=function(r,o,c,u,f,p,x){var _=document.createElement("div");_.style.position="absolute",_.style.backgroundColor=sn.BORDER_SHADER_DEFAULT_COLOR,_.style.width="".concat(o,"px"),_.style.height="".concat(c,"px"),u!==null&&(_.style.top="".concat(u,"px")),f!==null&&(_.style.bottom="".concat(f,"px")),x?_.style.left="".concat(p,"px"):_.style.right="".concat(p,"px"),this.borderShaders||(this.borderShaders=[]),this.borderShaders.push(_),r.appendChild(_)},t.prototype.showPausedState=function(){if(!this.scannerPausedUiElement)throw"[internal error] scanner paused UI element not found";this.scannerPausedUiElement.style.display="block"},t.prototype.hidePausedState=function(){if(!this.scannerPausedUiElement)throw"[internal error] scanner paused UI element not found";this.scannerPausedUiElement.style.display="none"},t.prototype.getTimeoutFps=function(r){return 1e3/r},t})(),ml;(function(t){t[t.STATUS_DEFAULT=0]="STATUS_DEFAULT",t[t.STATUS_SUCCESS=1]="STATUS_SUCCESS",t[t.STATUS_WARNING=2]="STATUS_WARNING",t[t.STATUS_REQUESTING_PERMISSION=3]="STATUS_REQUESTING_PERMISSION"})(ml||(ml={}));const _w={class:"scan-code"},vw={class:"btn"},Cw={class:"left-back"},bw=v.defineComponent({name:"QrCodeScan",__name:"QrCodeScan",emits:["scanSuccess"],setup(t,{emit:r}){const o=r,c=Ad.IconScan(),u=v.reactive({html5QrCode:null}),f=v.ref(!1),p=()=>{if(!u.html5QrCode){Je("摄像头无访问权限!");return}f.value=!0,u.html5QrCode.start({facingMode:"environment"},{fps:30,aspectRatio:1,supportedScanTypes:[ti.SCAN_TYPE_CAMERA],showTorchButtonIfSupported:!0,showZoomSliderIfSupported:!0,defaultZoomValueIfSupported:2,useBarCodeDetectorIfSupported:!0},E=>{try{const M=new URL(E).searchParams.get("sessionId");M?o("scanSuccess",M):Je("无效的二维码")}catch{Je("无效的二维码")}A()}).catch(E=>{console.log(E),Je({message:"二维码识别失败",duration:3e3})})},x=()=>{g().then(()=>{p()})},_=()=>{A()},g=()=>pl.getCameras().then(E=>{E&&E.length&&(u.html5QrCode=new pl("reader"))}).catch(()=>{Je({message:"摄像头无访问权限!",duration:3e3})}),A=()=>{u.html5QrCode&&u.html5QrCode.stop().then(E=>{console.log("停止扫码",E)}).catch(E=>{console.log(E),Je("停止扫码失败")}).finally(()=>{f.value=!1})};return v.onUnmounted(()=>{u.html5QrCode&&u.html5QrCode.isScanning&&A()}),(E,L)=>{const M=rs;return v.openBlock(),v.createElementBlock("div",null,[v.createVNode(v.unref(Lt.TrIconButton),{icon:v.unref(c),size:"28",svgSize:"20",onClick:L[0]||(L[0]=D=>x())},null,8,["icon"]),(v.openBlock(),v.createBlock(v.Teleport,{to:"body"},[v.withDirectives(v.createElementVNode("div",_w,[L[1]||(L[1]=v.createElementVNode("div",{class:"container"},[v.createElementVNode("div",{class:"qrcode"},[v.createElementVNode("div",{id:"reader"})])],-1)),v.createElementVNode("div",vw,[v.createElementVNode("div",Cw,[v.createVNode(M,{name:"arrow-left",onClick:_})])])],512),[[v.vShow,f.value]])]))])}}}),Ew=Kn(bw,[["__scopeId","data-v-2d988579"]]);function os(t,r,o){const c=v.computed(()=>t?Array.isArray(t)?t:t.value:[]),u=()=>{const A=c.value;if(A.length===0)return"";if(r){const L=typeof r=="string"?r:r.value;if(L&&A.some(M=>M.id===L))return L}const E=A.find(L=>L.isDefault);return E?E.id:A[0].id};let f,p=!1;if(r&&typeof r!="string")f=r,p=!0,(!f.value||!c.value.some(A=>A.id===f.value))&&(f.value=u());else{let A;r&&typeof r=="string"&&(A=r),f=v.ref(A&&c.value.some(E=>E.id===A)?A:u())}(!p||o)&&v.watch(f,A=>{o&&o(A)});const x=v.computed(()=>c.value.find(A=>A.id===f.value)),_=v.computed(()=>c.value);return{selectedModelId:f,selectedModel:x,availableModels:_,setSelectedModel:A=>{c.value.find(L=>L.id===A)?f.value=A:console.warn(`[useModel] Model not found: ${A}`)}}}const Aw=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Iw=Object.prototype.toString,Sw=t=>Iw.call(t)==="[object Object]",Ti=()=>{};function vo(t){return Array.isArray(t)?t:[t]}function Tw(t,r,o){return v.watch(t,r,{...o,immediate:!0})}const Wu=Aw?window:void 0;function Wr(t){var r;const o=v.toValue(t);return(r=o?.$el)!==null&&r!==void 0?r:o}function Co(...t){const r=(c,u,f,p)=>(c.addEventListener(u,f,p),()=>c.removeEventListener(u,f,p)),o=v.computed(()=>{const c=vo(v.toValue(t[0])).filter(u=>u!=null);return c.every(u=>typeof u!="string")?c:void 0});return Tw(()=>{var c,u;return[(c=(u=o.value)===null||u===void 0?void 0:u.map(f=>Wr(f)))!==null&&c!==void 0?c:[Wu].filter(f=>f!=null),vo(v.toValue(o.value?t[1]:t[0])),vo(v.unref(o.value?t[2]:t[1])),v.toValue(o.value?t[3]:t[2])]},([c,u,f,p],x,_)=>{if(!c?.length||!u?.length||!f?.length)return;const g=Sw(p)?{...p}:p,A=c.flatMap(E=>u.flatMap(L=>f.map(M=>r(E,L,M,g))));_(()=>{A.forEach(E=>E())})},{flush:"post"})}function Nw(t,r,o={}){const{window:c=Wu,ignore:u=[],capture:f=!0,detectIframe:p=!1,controls:x=!1}=o;if(!c)return x?{stop:Ti,cancel:Ti,trigger:Ti}:Ti;let _=!0;const g=P=>v.toValue(u).some(H=>{if(typeof H=="string")return Array.from(c.document.querySelectorAll(H)).some(Z=>Z===P.target||P.composedPath().includes(Z));{const Z=Wr(H);return Z&&(P.target===Z||P.composedPath().includes(Z))}});function A(P){const H=v.toValue(P);return H&&H.$.subTree.shapeFlag===16}function E(P,H){const Z=v.toValue(P),$=Z.$.subTree&&Z.$.subTree.children;return $==null||!Array.isArray($)?!1:$.some(V=>V.el===H.target||H.composedPath().includes(V.el))}const L=P=>{const H=Wr(t);if(P.target!=null&&!(!(H instanceof Element)&&A(t)&&E(t,P))&&!(!H||H===P.target||P.composedPath().includes(H))){if("detail"in P&&P.detail===0&&(_=!g(P)),!_){_=!0;return}r(P)}};let M=!1;const D=[Co(c,"click",P=>{M||(M=!0,setTimeout(()=>{M=!1},0),L(P))},{passive:!0,capture:f}),Co(c,"pointerdown",P=>{const H=Wr(t);_=!g(P)&&!!(H&&!P.composedPath().includes(H))},{passive:!0}),p&&Co(c,"blur",P=>{setTimeout(()=>{var H;const Z=Wr(t);((H=c.document.activeElement)===null||H===void 0?void 0:H.tagName)==="IFRAME"&&!Z?.contains(c.document.activeElement)&&r(P)},0)},{passive:!0})].filter(Boolean),R=()=>D.forEach(P=>P());return x?{stop:R,cancel:()=>{_=!1},trigger:P=>{_=!0,L(P),_=!1}}:R}const Ow=["data-active","disabled"],kw=v.defineComponent({__name:"Button",props:{active:{type:Boolean},rounded:{type:Boolean},size:{default:"medium"},disabled:{type:Boolean}},setup(t){return(r,o)=>(v.openBlock(),v.createElementBlock("button",{class:v.normalizeClass(["button",{rounded:t.rounded,[t.size]:!0}]),"data-active":t.active||void 0,disabled:t.disabled||void 0},[v.renderSlot(r.$slots,"default",{},void 0,!0)],10,Ow))}}),ss=Kn(kw,[["__scopeId","data-v-6f582cce"]]),Rw={viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",fill:"none"};function Mw(t,r){return v.openBlock(),v.createElementBlock("svg",Rw,[...r[0]||(r[0]=[v.createElementVNode("rect",{id:"大模型",width:"16.000000",height:"16.000000",x:"0.000000",y:"0.000000"},null,-1),v.createElementVNode("path",{id:"矢量 90",d:"M13.683 2.26904C12.5753 1.16177 10.344 1.47577 8.02582 2.86527C5.70758 1.47576 3.47637 1.16179 2.36913 2.26904C1.2619 3.37646 1.57573 5.60771 2.96524 7.92589C1.57573 10.2441 1.2619 12.4754 2.36913 13.5827C3.47637 14.6901 5.7078 14.3762 8.02599 12.9867C10.344 14.3762 12.5752 14.6901 13.6825 13.5827C14.7901 12.4754 14.4761 10.2441 13.0866 7.92594C14.4761 5.60775 14.7902 3.37646 13.683 2.26904ZM10.8544 5.09764C11.4667 5.70995 12.0076 6.34819 12.4699 6.99044C12.7244 6.52061 12.9268 6.06037 13.077 5.60959C13.2948 4.95652 13.3832 4.38597 13.3426 3.89769C13.3089 3.49437 13.1869 3.18725 12.9754 2.97631C12.7645 2.76513 12.4574 2.64282 12.0541 2.60912C11.5658 2.56835 10.9955 2.65698 10.3422 2.87475C9.89153 3.02497 9.43121 3.22735 8.96135 3.48197C9.60365 3.94428 10.242 4.48527 10.8544 5.09764ZM5.70991 2.87475C6.16049 3.02494 6.62073 3.22729 7.09051 3.48185C6.44826 3.94412 5.81002 4.48507 5.19771 5.09739C4.58523 5.70982 4.04417 6.34819 3.58181 6.99055C3.32716 6.52071 3.1248 6.06037 2.97459 5.60959C2.75682 4.95677 2.66844 4.38597 2.70897 3.89769C2.74266 3.49437 2.86522 3.18725 3.07615 2.97631C3.28709 2.76513 3.59421 2.64282 3.99753 2.60912C4.4858 2.5686 5.0566 2.65698 5.70991 2.87475ZM5.90473 5.80466Q4.89236 6.81738 4.14938 7.92595C4.64428 8.66515 5.2294 9.3722 5.90473 10.0473C6.57966 10.7222 7.28696 11.3074 8.02584 11.8027C8.76507 11.3074 9.47197 10.7222 10.1474 10.0473C10.8222 9.37218 11.4074 8.66511 11.9027 7.92588Q11.1597 6.81736 10.1474 5.80466C9.47203 5.12956 8.7652 4.54447 8.02604 4.04937C7.28683 4.54447 6.5796 5.12956 5.90473 5.80466ZM7.99992 6.90011C7.44768 6.90011 6.99993 7.34787 6.99993 7.90011C6.99993 8.45235 7.44768 8.9001 7.99992 8.9001C8.55216 8.9001 8.99991 8.45235 8.99991 7.90011C8.99991 7.34787 8.55216 6.90011 7.99992 6.90011ZM10.3422 12.9772C9.89161 12.827 9.43138 12.6246 8.96148 12.37C9.60377 11.9077 10.242 11.3667 10.8544 10.7543C11.4667 10.142 12.0077 9.50369 12.4699 8.8614C12.7245 9.33127 12.9268 9.79154 13.077 10.2421C13.2948 10.8952 13.3832 11.4658 13.3426 11.954C13.3089 12.3574 13.1864 12.6647 12.9754 12.8757C12.7645 13.0866 12.4574 13.2089 12.0541 13.2426C11.5658 13.2834 10.995 13.195 10.3422 12.9772ZM2.97459 10.2421C3.12478 9.7914 3.32733 9.3312 3.58196 8.86141C4.04428 9.50369 4.5853 10.142 5.19771 10.7543C5.81003 11.3667 6.44827 11.9077 7.09052 12.37C6.62074 12.6246 6.16049 12.827 5.70991 12.9772C5.0566 13.195 4.48629 13.2834 3.99802 13.2426C3.5947 13.2089 3.28709 13.0866 3.07615 12.8757C2.86522 12.6647 2.74315 12.3574 2.70946 11.954C2.66844 11.4658 2.75682 10.8952 2.97459 10.2421Z",fill:"rgb(89,89,89)","fill-rule":"evenodd"},null,-1)])])}const Dw={render:Mw},Pw={class:"button-text"},Bw={class:"dropdown-menu__items"},Lw=["onClick"],Fw=v.defineComponent({__name:"ModelSwitch",props:v.mergeModels({modelConfigs:{}},{selectedModelId:{type:String,default:void 0,required:!1},selectedModelIdModifiers:{}}),emits:["update:selectedModelId"],setup(t){const r=t,o=v.useModel(t,"selectedModelId"),c=r.modelConfigs?Array.isArray(r.modelConfigs)?v.shallowRef(r.modelConfigs):r.modelConfigs:void 0,{selectedModel:u,availableModels:f,setSelectedModel:p}=os(c,o),x=v.ref(!1),_=M=>{p(M),A()},g=()=>{x.value=!x.value},A=()=>{x.value=!1},E=v.ref(null),L=v.ref(null);return Nw(L,()=>{A()},{ignore:[E]}),(M,D)=>(v.openBlock(),v.createElementBlock("div",{class:"model-switch-wrapper",ref_key:"wrapperRef",ref:E},[v.createVNode(ss,{size:"small",class:"action-button",rounded:"",onClick:g},{default:v.withCtx(()=>[(v.openBlock(),v.createBlock(v.resolveDynamicComponent(v.unref(u)?.icon),{width:16,height:16,class:"selected-model__icon"})),v.createElementVNode("span",Pw,v.toDisplayString(v.unref(u)?.label),1),v.createVNode(v.unref(Dw),{width:16,height:16})]),_:1}),v.createVNode(v.Transition,{name:"dropdown"},{default:v.withCtx(()=>[x.value?(v.openBlock(),v.createElementBlock("div",{key:0,class:"dropdown-menu",ref_key:"dropdownMenuRef",ref:L},[v.createElementVNode("div",Bw,[(v.openBlock(!0),v.createElementBlock(v.Fragment,null,v.renderList(v.unref(f),R=>(v.openBlock(),v.createElementBlock("div",{key:R.id,class:v.normalizeClass(["dropdown-menu__item",{"active-menu":R.id===o.value}]),onClick:v.withModifiers(P=>_(R.id),["stop"])},[R.icon?(v.openBlock(),v.createBlock(v.resolveDynamicComponent(R.icon),{key:0,width:16,height:16,class:"dropdown-menu__icon"})):v.createCommentVNode("",!0),v.createElementVNode("span",null,v.toDisplayString(R.label),1)],10,Lw))),128))])],512)):v.createCommentVNode("",!0)]),_:1}),x.value?(v.openBlock(),v.createElementBlock("div",{key:0,class:"dropdown-overlay",onClick:A})):v.createCommentVNode("",!0)],512))}}),Uw=Kn(Fw,[["__scopeId","data-v-cee7e07b"]]),zw={key:0,class:"active-count"},Vw=v.defineComponent({__name:"PluginToggleButton",props:{installedPlugins:{}},emits:["click"],setup(t){const r=t,o=v.computed(()=>r.installedPlugins.filter(c=>c.enabled).length);return(c,u)=>(v.openBlock(),v.createBlock(ss,{size:"small",class:"action-button",active:o.value>0,rounded:"",onClick:u[0]||(u[0]=f=>c.$emit("click"))},{default:v.withCtx(()=>[v.createVNode(v.unref(Sr.IconPlugin),{class:"icon",style:{"font-size":"16px"}}),u[1]||(u[1]=v.createElementVNode("span",{class:"button-text"},"扩展",-1)),o.value>0?(v.openBlock(),v.createElementBlock("span",zw,v.toDisplayString(o.value),1)):v.createCommentVNode("",!0)]),_:1},8,["active"]))}}),$w=Kn(Vw,[["__scopeId","data-v-c2a16c66"]]),Zw={"data-v-99394ae9":"",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",width:"16.000000",height:"16.000000",fill:"none",customFrame:"#000000",size:"16"};function jw(t,r){return v.openBlock(),v.createElementBlock("svg",Zw,[...r[0]||(r[0]=[v.createElementVNode("rect",{id:"生成式UI",width:"16.000000",height:"16.000000",x:"0.000000",y:"0.000000",fill:"currentColor","fill-opacity":"0"},null,-1),v.createElementVNode("path",{id:"矢量 154",d:"M7.41014 2.09741L7.67112 2.70606C7.68333 2.73438 7.70579 2.75684 7.73411 2.76905L8.34275 3.02979C8.43968 3.0713 8.43968 3.20875 8.34275 3.25025L7.73411 3.51124C7.70579 3.52345 7.68333 3.54591 7.67112 3.57423L7.41014 4.18288C7.36863 4.2798 7.23118 4.2798 7.18968 4.18288L6.92894 3.57423C6.91673 3.54591 6.89427 3.52345 6.86595 3.51124L6.25731 3.25025C6.16039 3.20875 6.16039 3.0713 6.25731 3.02979L6.86595 2.76905C6.89427 2.75684 6.91673 2.73438 6.92894 2.70606L7.18968 2.09741C7.23118 2.00049 7.36863 2.00049 7.41014 2.09741ZM4.57006 11.9625L7.27611 8.09746L9.69944 4.63674L10.592 3.36207C10.6899 3.22218 10.8017 3.09864 10.9272 2.99122C11.0529 2.88404 11.1926 2.79297 11.3459 2.71802C11.4992 2.64332 11.657 2.58936 11.8191 2.5564C11.9809 2.52369 12.1472 2.51172 12.3176 2.52051C12.5315 2.53174 12.7336 2.57373 12.9238 2.64649C13.0678 2.70118 13.205 2.77369 13.3354 2.86353C13.4651 2.95289 13.5813 3.05445 13.6836 3.16822C13.8064 3.3047 13.9094 3.45851 13.9929 3.6299C14.0766 3.80128 14.1342 3.97731 14.1662 4.15773C14.1928 4.30861 14.2014 4.46267 14.1919 4.61989C14.1823 4.7781 14.1547 4.93069 14.1096 5.07791C14.0495 5.27249 13.958 5.45755 13.8352 5.63309L7.81321 14.2335Q7.66985 14.4382 7.48649 14.5965Q7.4825 14.6 7.4785 14.6034Q7.29063 14.7641 7.06102 14.8766C6.90794 14.9513 6.75072 15.0052 6.5891 15.0384C6.42748 15.0714 6.2617 15.0836 6.09154 15.0751C5.87743 15.0643 5.67504 15.0226 5.48436 14.9503C5.34008 14.8956 5.20287 14.8233 5.07201 14.7335C4.94213 14.6444 4.82592 14.5428 4.72313 14.4291C4.60033 14.2928 4.49682 14.1388 4.41308 13.9674C4.32934 13.7958 4.27123 13.6197 4.23925 13.4391C4.21239 13.2882 4.20385 13.1339 4.21313 12.9767C4.22265 12.8184 4.24999 12.6656 4.2954 12.5184C4.35546 12.3233 4.44701 12.138 4.57006 11.9625ZM4.7185 4.67361L4.18383 3.42579C4.11449 3.26441 3.88549 3.26441 3.81616 3.42579L3.28149 4.67361C3.26123 4.72073 3.22363 4.75832 3.17651 4.77859L1.92871 5.31326C1.76733 5.3826 1.76733 5.6116 1.92871 5.68094L3.17651 6.21561C3.22363 6.23587 3.26123 6.27347 3.28149 6.32059L3.81616 7.56841C3.88549 7.73003 4.11449 7.73003 4.18383 7.56841L4.7185 6.32059C4.73876 6.27347 4.77636 6.23587 4.82348 6.21561L6.07128 5.68094C6.23265 5.6116 6.23265 5.3826 6.07128 5.31326L4.82348 4.77859C4.77636 4.75832 4.73876 4.72073 4.7185 4.67361ZM5.38915 12.536C5.32006 12.6346 5.27099 12.7384 5.24169 12.8475C5.22533 12.9088 5.21532 12.9718 5.21141 13.0362C5.20726 13.1063 5.21044 13.1751 5.22094 13.2428C5.23583 13.3402 5.2661 13.4354 5.31151 13.5282C5.35692 13.6209 5.41332 13.7032 5.48095 13.775C5.52806 13.8248 5.58031 13.8695 5.63817 13.9093C5.69139 13.9459 5.7473 13.9764 5.80565 14.0011C5.9099 14.0453 6.02196 14.0702 6.14208 14.0763C6.2263 14.0807 6.30834 14.0746 6.38841 14.0582C6.46825 14.0418 6.54613 14.015 6.62181 13.9781C6.69749 13.941 6.76634 13.8961 6.8286 13.8429C6.89061 13.7899 6.94578 13.7289 6.99412 13.6598L11.9415 6.59405L10.3381 5.46789L5.38915 12.536ZM10.9168 4.6415L12.5202 5.76762L13.0161 5.05935C13.0849 4.96096 13.134 4.85745 13.1633 4.74831C13.1797 4.68703 13.1897 4.62429 13.1936 4.55959C13.198 4.48977 13.1948 4.42092 13.1843 4.35329C13.1694 4.25588 13.1394 4.16091 13.0942 4.06813C13.0488 3.97536 12.9926 3.89308 12.925 3.8213C12.8781 3.7715 12.8259 3.72682 12.7683 3.68703C12.7148 3.6504 12.6591 3.61964 12.6008 3.59474C12.4968 3.55079 12.385 3.5254 12.2651 3.5193C12.1806 3.51466 12.0984 3.52076 12.0183 3.53688C11.9382 3.55324 11.8601 3.57985 11.7841 3.61696C11.7082 3.65407 11.6391 3.69899 11.5771 3.75221C11.5149 3.80519 11.4594 3.86647 11.4111 3.93556L10.9168 4.6415Z",fill:"currentColor","fill-rule":"evenodd"},null,-1)])])}const Hw={render:jw},Ww=v.defineComponent({__name:"GenUISwitch",props:{genuiEnabled:{type:Boolean,type:Boolean,default:!1,required:!1},genuiEnabledModifiers:{}},emits:["update:genuiEnabled"],setup(t){const r=v.useModel(t,"genuiEnabled"),o=()=>{r.value=!r.value};return(c,u)=>(v.openBlock(),v.createBlock(ss,{class:"action-button",active:r.value,rounded:"",size:"small",onClick:o},{default:v.withCtx(()=>[v.createVNode(v.unref(Hw),{width:16,height:16}),u[0]||(u[0]=v.createElementVNode("span",{class:"button-text"},"生成式UI",-1))]),_:1},8,["active"]))}}),Gw=Kn(Ww,[["__scopeId","data-v-7f3b0372"]]),Xw={class:"bubble-image-wrapper"},qw=["src"],Yw=["src"],Jw=v.defineComponent({__name:"BubbleImageRenderer",props:{content:{}},setup(t){const r=v.ref(!1),o=v.ref(null),c=()=>{r.value=!0},u=()=>{r.value=!1};return v.watch(r,f=>{f&&v.nextTick(()=>{o.value?.focus()})}),(f,p)=>(v.openBlock(),v.createElementBlock("div",Xw,[v.createElementVNode("img",{src:t.content,class:"bubble-image",alt:"用户上传的图片",onClick:c},null,8,qw),(v.openBlock(),v.createBlock(v.Teleport,{to:"body"},[r.value?(v.openBlock(),v.createElementBlock("div",{key:0,class:"image-preview-modal",role:"dialog","aria-modal":"true","aria-label":"图片预览",onClick:u,onKeydown:v.withKeys(u,["esc"])},[v.createElementVNode("button",{ref_key:"closeButtonRef",ref:o,class:"preview-close",type:"button","aria-label":"关闭预览",onClick:u},[...p[1]||(p[1]=[v.createElementVNode("svg",{viewBox:"0 0 1024 1024",width:"24",height:"24","aria-hidden":"true"},[v.createElementVNode("path",{d:"M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z",fill:"currentColor"})],-1)])],512),v.createElementVNode("div",{class:"preview-content",onClick:p[0]||(p[0]=v.withModifiers(()=>{},["stop"]))},[v.createElementVNode("img",{src:t.content,alt:"预览图片"},null,8,Yw)])],32)):v.createCommentVNode("",!0)]))]))}}),Kw=Kn(Jw,[["__scopeId","data-v-91c75579"]]),Zr="https://agent.opentiny.design",Qw=[{id:"12306-mcp",name:"12306服务器",description:"12306购票搜索服务器",icon:"https://agent.opentiny.design/public-assets/icons/icon-12306.webp",enabled:!1,addState:"idle",tools:[],url:Zr+"/api/v1/mcp-server/12306/mcp",type:"StreamableHTTP"},{id:"markdown2pdf-mcp",name:"Markdown转PDF MCP服务器",description:"Markdown转PDF MCP服务器,可以将Markdown文件转换为PDF文件",icon:"https://agent.opentiny.design/public-assets/icons/icon-pdf.png",url:Zr+"/servers/markdown2pdf-mcp/sse",type:"sse",enabled:!1,addState:"idle",tools:[]},{id:"docx-mcp",name:"Word文档MCP服务器",description:"Word文档MCP服务器,可以创建、编辑、保存Word文档",icon:"https://agent.opentiny.design/public-assets/icons/icon-word.png",url:Zr+"/servers/excel-mcp/sse",type:"sse",enabled:!1,addState:"idle",tools:[]},{id:"excel-mcp",name:"Excel文档MCP服务器",description:"Excel文档MCP服务器,可以创建、编辑、保存Excel文档",icon:"https://agent.opentiny.design/public-assets/icons/icon-excel.png",url:Zr+"/servers/excel-mcp/mcp",type:"StreamableHTTP",enabled:!1,addState:"idle",tools:[]},{id:"doc-tools-mcp",name:"文档工具MCP服务器",description:"文档工具MCP服务器,可以创建、编辑、保存文档",icon:"https://agent.opentiny.design/public-assets/icons/icon-doc.png",url:Zr+"/servers/doc-tools-mcp/sse",type:"sse",enabled:!1,addState:"idle",tools:[]}],e3=`
77
77
  <svg width="1em" height="1em" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
78
78
  <defs>
79
79
  <clipPath id="clip657_188316">
@@ -86,4 +86,4 @@ ${f.value}`:x,c.llmConfig){const m=c.llmConfig.extraTools??{};c.llmConfig.extraT
86
86
  <path id="path" d="M1.25 9.97C1.25 9.63 1.53 9.35 1.87 9.35L4.37 9.35C4.72 9.35 5 9.63 5 9.97C5 10.32 4.72 10.6 4.37 10.6L1.87 10.6C1.53 10.6 1.25 10.32 1.25 9.97ZM12.5 6.25C12.5 5.9 12.78 5.62 13.12 5.62L17.46 5.62C17.8 5.62 18.08 5.9 18.08 6.25C18.08 6.59 17.8 6.87 17.46 6.87L13.12 6.87C12.78 6.87 12.5 6.59 12.5 6.25ZM12.5 13.73C12.5 13.39 12.78 13.11 13.12 13.11L17.46 13.11C17.8 13.11 18.08 13.39 18.08 13.73C18.08 14.08 17.8 14.36 17.46 14.36L13.12 14.36C12.78 14.36 12.5 14.08 12.5 13.73Z" fill="currentColor" fill-opacity="1" fill-rule="nonzero"></path>
87
87
  </g>
88
88
  </svg>
89
- `,qy=btoa(Xy),pl=`data:image/svg+xml;base64,${qy}`,bo=(t,r)=>{const[o,c]=t.split("#");return{id:r,text:o,inputMessage:c}},Yy=t=>{const r={"zh-CN":{title:"OpenTiny NEXT",description:"我是你的私人智能助手",placeholder:"请输入您的问题",thinking:"正在思考中..."},"en-US":{title:"OpenTiny NEXT",description:"I am your private AI assistant",placeholder:"Please enter your question",thinking:"Thinking..."}},o=[{id:"office",text:t.locale==="zh-CN"?"办公助手":"Office Assistant",menus:["接收邮件#请同步邮箱的新邮件。","编写邮件#请新建一个邮件,收件人为 opentiny-next@meeting.com, 内容为举办一个临时会议。","安排会议#创建一个临时的在线会议,主题为讨论问题,时长为1小时。","整理文档#请分析附件中的销售情况,把销售额绘制成折线图。"].map(bo)},{id:"development",text:t.locale==="zh-CN"?"开发支持":"Development Support",menus:["遇到代码问题#请检查当前位置的报错原因。","架构建议#请使用NodeJs实现一个分块上传文件的模块。","最新的技术趋势#请分析Vue与React 框架的优劣分别是什么?"].map(bo)},{id:"management",text:t.locale==="zh-CN"?"项目管理":"Project Management",menus:["项目规划#如何开展品牌推广的活动?","任务分配#将本季度的销售任务分配给三个人,并生成甘特图进行跟踪。","进度跟踪#分析团队的任务完成情况。"].map(bo)}],c=[{label:t.locale==="zh-CN"?"企业办公助手":"Enterprise Office Assistant",description:t.locale==="zh-CN"?"需要我帮你处理邮件、安排会议、整理文档,还是优化工作流程?":"Need help with emails, meeting scheduling, document organization, or workflow optimization?",icon:v.h("span",{style:{fontSize:"18px"}},"🧠"),badge:"NEW"},{label:t.locale==="zh-CN"?"开发技术支持":"Development Support",description:t.locale==="zh-CN"?"遇到代码问题?需要架构建议?还是想了解最新的技术趋势?":"Facing code issues? Need architecture advice? Or want to learn about latest tech trends?",icon:v.h("span",{style:{fontSize:"18px"}},"💻")},{label:t.locale==="zh-CN"?"项目管理协作":"Project Management",description:t.locale==="zh-CN"?"需要项目规划、任务分配、进度跟踪,还是团队协作建议?":"Need project planning, task assignment, progress tracking, or team collaboration advice?",icon:v.h("span",{style:{fontSize:"18px"}},"📊")}];return{lang:r,pillItems:o,promptItems:c}},gl={"No client found for session ID":"受控端页面已关闭请重新打开或者刷新页面","Failed to create MCP client":"创建MCP客户端失败"},Jy=t=>{console.log("message",t);const r=Object.keys(gl),o=r.findIndex(u=>t.includes(u));return(o!==-1?gl[r[o]]:t)||t},Ky={class:"tr-container__title"},Qy={style:{flex:"1"}},e3={class:"chat-input"},t3={class:"chat-input-pills"},n3={class:"attachments-container"},r3={class:"action-buttons"},i3=v.defineComponent({name:"TinyRemoter",__name:"TinyRobotChat",props:v.mergeModels({sessionId:{type:String,default:""},agentRoot:{type:String,default:"https://agent.opentiny.design/api/v1/webmcp-trial/"},systemPrompt:{type:String,default:"你是一个智能生活助手,擅长通过工具调用帮助用户完成任务"},title:{type:String,default:"OpenTiny NEXT"},locale:{type:String,default:"zh-CN"},remoteUrl:{type:String},menuItems:{type:Array},qrCodeUrl:{type:String},AILogoUrl:{type:String},mode:{type:String,default:"remoter"},llmConfig:{type:Object,default:void 0},inBrowserExt:{type:Boolean,default:!1},genUiComponents:{type:Object,default:()=>({})},customMarketMcpServers:{type:Array,default:()=>[]},mcpServers:{type:Object,default:void 0},llmConfigs:{type:Array,default:void 0},skills:{type:Object,default:void 0},layoutMode:{type:String,default:"fixed"}},{fullscreen:{type:Boolean,default:!1},fullscreenModifiers:{},show:{type:Boolean,default:!1},showModifiers:{},selectedModelId:{type:String,default:void 0,required:!1},selectedModelIdModifiers:{},genUiAble:{type:Boolean,default:!1,required:!1},genUiAbleModifiers:{},enabledTools:{type:Object,default:void 0,required:!1},enabledToolsModifiers:{}}),emits:["update:fullscreen","update:show","update:selectedModelId","update:genUiAble","update:enabledTools"],setup(t,{expose:r}){const o=t,c=v.useModel(t,"fullscreen"),u=v.useModel(t,"show"),f=v.useModel(t,"selectedModelId"),p=v.useModel(t,"genUiAble"),x=v.useModel(t,"enabledTools"),y=o.llmConfigs?v.toRef(o,"llmConfigs"):void 0,{selectedModel:m}=is(y,f),{hasMultimodalSupport:A,attachments:E,onFilesSelected:B,checkCanSendAttachments:D,processAttachments:M,cleanupAttachments:R}=Vw({selectedModel:m,selectedModelId:f}),{agent:k,customAgentProvider:q,conversationState:Z,messages:z,messageState:$,inputMessage:Q,abortRequest:O,senderRef:V,sendMessage:le,handleSendMessage:j,addMessage:Ee,send:de,createConversation:ne,switchConversation:oe,deleteConversation:ee,getCurrentConversation:P}=ox({systemPrompt:o.systemPrompt||"",llmConfig:o.llmConfig});q.isGenuiEnabled=p;const H=v.toRef(o,"skills"),{processSkillMentions:re}=Sw({skillsRef:H,systemPrompt:o.systemPrompt||"",customAgentProvider:q}),te=async(at,Me)=>j(at,Me,re),{welcomeIcon:we,roles:se}=Mw({messages:z,messageState:$,inputMessage:Q,handleSendMessage:te}),{showHistory:ye,handleCreateConversation:_e,handleHistorySelect:Ze,handleHistoryUpdateTitle:Ue,handleHistoryDelete:xe}=Dw({createConversation:ne,switchConversation:oe,deleteConversation:ee,getCurrentConversation:P,abortRequest:O,conversationState:Z,customAgentProvider:q}),ge=()=>{if(m.value){const at=m.value;q.updateLLMConfig({modelId:at.id,baseURL:at.baseURL||"",apiKey:at.apiKey||"",providerType:at.providerType,useReActMode:at.useReActMode,llm:at.llm})}};o.llmConfigs&&v.watch(m,ge,{immediate:!0}),o.inBrowserExt&&v.watch(p,ge);const ft={markdown:new Pt.BubbleMarkdownContentRenderer({mdConfig:{html:!0}}),"schema-card":at=>v.h(Cd.GenuiRenderer,{...at,customActions:{continueChat:{execute:(Me,ke)=>{const pe=typeof Me=="string"?Me:Me.message,St=`${pe},相关参数为:${JSON.stringify(ke?.state||{})}`;Ee({role:"user",content:St,uiContent:[{type:"markdown",content:pe}]}),de()}}},generating:Zn.GeneratingStatus.includes($.status),customComponents:o.genUiComponents,requiredCompleteFieldSelectors:["[componentName=TinyUser] > props > modelValue"]}),image:Wy},{installedPlugins:Se,marketPlugins:Nt,pluginVisible:Qe,loadMcpServerToPlugin:et,togglePlugin:jt,toggleTool:Be,deletePlugin:hn,addPluginFromMarket:Vt,addPluginFromScan:Cn,handleClientDisconnected:L,searchPlugin:ue}=Iw(k,x,pl);Nt.value=[...Gy,...o.customMarketMcpServers];const Te=v.ref([{value:"",label:"全部分类"},{value:"productivity",label:"生产力工具"},{value:"communication",label:"沟通协作"},{value:"development",label:"开发工具"},{value:"ai",label:"AI 助手"}]),{lang:It,pillItems:be,promptItems:fr}=Yy(o),{handleScanSuccess:si,handleSessionIdInput:pn,initialize:Tr}=Pw({sessionId:v.toRef(o,"sessionId"),agentRoot:o.agentRoot,mode:o.mode,qrCodeUrl:o.qrCodeUrl,remoteUrl:o.remoteUrl,menuItems:o.menuItems,AILogoUrl:o.AILogoUrl,show:u,addPluginFromScan:Cn,inputMessage:Q}),en=async at=>{if(await pn(Q.value)||!D())return;const ke=await M();try{await te(at,ke),R()}catch(pe){console.error("发送消息失败:",pe)}},ai=v.computed(()=>Zn.GeneratingStatus.includes($.status)?It[o.locale].thinking:It[o.locale].placeholder),bn=v.computed(()=>Zn.GeneratingStatus.includes($.status)),Lt=at=>{Q.value=at.inputMessage};Tr(),v.onMounted(async()=>{_e(),k.onError=Me=>{Me&&Ye(Jy(Me))};const at=Nt.value.filter(Me=>Me.addState==="added"&&Me.enabled);for(const Me of at)await Vt(Me);if(o.mcpServers)for(const[Me,ke]of Object.entries(o.mcpServers))await et(Me,ke)});const{handleCustomAdd:li}=Aw(k,Se,pl);return r({agent:k,welcomeIcon:we,messages:z,messageState:$,roles:se,inputMessage:Q,senderRef:V,abortRequest:O,sendMessage:le,loadMcpServerToPlugin:et,handleClientDisconnected:L,addMessage:Ee}),(at,Me)=>(v.openBlock(),v.createBlock(v.unref(Pt.TrContainer),{show:u.value,"onUpdate:show":Me[11]||(Me[11]=ke=>u.value=ke),fullscreen:c.value,"onUpdate:fullscreen":Me[12]||(Me[12]=ke=>c.value=ke),style:v.normalizeStyle({position:t.layoutMode,width:t.layoutMode!=="fixed"?"unset":void 0,height:t.layoutMode!=="fixed"?"100%":void 0})},{title:v.withCtx(()=>[v.createElementVNode("h3",Ky,v.toDisplayString(t.title),1)]),operations:v.withCtx(()=>[v.renderSlot(at.$slots,"operations",{},()=>[v.createVNode(v.unref(Pt.TrIconButton),{icon:v.unref(Ar.IconNewSession),size:"28",svgSize:"20",onClick:Me[0]||(Me[0]=ke=>v.unref(_e)())},null,8,["icon"]),v.createVNode(v.unref(Pt.TrIconButton),{icon:v.unref(Ar.IconHistory),size:"28",svgSize:"20",onClick:Me[1]||(Me[1]=ke=>ye.value=!v.unref(ye))},null,8,["icon"]),v.createVNode(wy,{onScanSuccess:v.unref(si)},null,8,["onScanSuccess"]),v.createVNode(v.Transition,{name:"drawer-slide",appear:""},{default:v.withCtx(()=>[v.unref(ye)?(v.openBlock(),v.createElementBlock("div",{key:0,class:"drawer-overlay",onClick:Me[4]||(Me[4]=ke=>ye.value=!1)},[v.createElementVNode("div",{class:"drawer-container",onClick:Me[3]||(Me[3]=v.withModifiers(()=>{},["stop"])),style:{"--tr-history-item-selected-bg":"#ebeeff"}},[Me[13]||(Me[13]=v.createElementVNode("h4",null,"历史会话",-1)),v.createVNode(v.unref(Pt.TrHistory),{class:"tr-history-demo",selected:v.unref(Z).currentId,data:v.unref(Z).conversations,showRenameControls:!0,onClose:Me[2]||(Me[2]=ke=>ye.value=!1),onItemClick:v.unref(Ze),onItemTitleChange:v.unref(Ue),onItemAction:v.unref(xe)},null,8,["selected","data","onItemClick","onItemTitleChange","onItemAction"])])])):v.createCommentVNode("",!0)]),_:1})],!0)]),footer:v.withCtx(()=>[v.createElementVNode("div",e3,[v.renderSlot(at.$slots,"suggestions",{},()=>[v.createElementVNode("div",t3,[(v.openBlock(!0),v.createElementBlock(v.Fragment,null,v.renderList(v.unref(be),ke=>(v.openBlock(),v.createBlock(v.unref(Pt.TrDropdownMenu),{key:ke.id,items:ke.menus,onItemClick:Lt,trigger:"click"},{trigger:v.withCtx(()=>[v.createVNode(v.unref(Pt.TrSuggestionPillButton),null,{default:v.withCtx(()=>[v.createTextVNode(v.toDisplayString(ke.text),1)]),_:2},1024)]),_:2},1032,["items"]))),128))])],!0),v.createVNode(v.unref(Pt.TrSender),{ref_key:"senderRef",ref:V,mode:"multiple",modelValue:v.unref(Q),"onUpdate:modelValue":Me[9]||(Me[9]=ke=>v.isRef(Q)?Q.value=ke:null),placeholder:ai.value,clearable:!!v.unref(Q),loading:bn.value,showWordLimit:!0,maxLength:2e4,onSubmit:en,onCancel:v.unref(O)},v.createSlots({footer:v.withCtx(()=>[v.createElementVNode("div",r3,[v.createVNode(By,{"installed-plugins":v.unref(Se),onClick:Me[6]||(Me[6]=ke=>Qe.value=!v.unref(Qe))},null,8,["installed-plugins"]),v.unref(y)&&v.unref(y).length>0?(v.openBlock(),v.createBlock(My,{key:0,"model-configs":v.unref(y),"selected-model-id":f.value,"onUpdate:selectedModelId":Me[7]||(Me[7]=ke=>f.value=ke)},null,8,["model-configs","selected-model-id"])):v.createCommentVNode("",!0),t.inBrowserExt?(v.openBlock(),v.createBlock(Vy,{key:1,"genui-enabled":p.value,"onUpdate:genuiEnabled":Me[8]||(Me[8]=ke=>p.value=ke)},null,8,["genui-enabled"])):v.createCommentVNode("",!0),v.unref(A)?(v.openBlock(),v.createBlock(v.unref(Pt.TrUploadButton),{key:2,accept:"image/*,application/pdf,.doc,.docx,.txt",multiple:!0,onSelect:v.unref(B)},null,8,["onSelect"])):v.createCommentVNode("",!0)])]),_:2},[v.unref(E).length>0?{name:"header",fn:v.withCtx(()=>[v.createElementVNode("div",n3,[v.createVNode(v.unref(Pt.TrAttachments),{items:v.unref(E),"onUpdate:items":Me[5]||(Me[5]=ke=>v.isRef(E)?E.value=ke:null)},null,8,["items"])])]),key:"0"}:void 0]),1032,["modelValue","placeholder","clearable","loading","onCancel"]),v.createVNode(v.unref(Pt.TrMcpServerPicker),{visible:v.unref(Qe),"onUpdate:visible":Me[10]||(Me[10]=ke=>v.isRef(Qe)?Qe.value=ke:null),"popup-config":{type:"drawer"},"show-custom-add-button":!0,marketTabTitle:"MCP市场",installedTabTitle:"已添加MCP服务",title:"扩展",installedPlugins:v.unref(Se),marketPlugins:v.unref(Nt),"market-category-options":Te.value,"installed-search-fn":v.unref(ue),"market-search-fn":v.unref(ue),onPluginToggle:v.unref(jt),onPluginAdd:v.unref(Vt),onPluginDelete:v.unref(hn),onToolToggle:v.unref(Be),onPluginCreate:v.unref(li)},{"header-actions":v.withCtx(()=>[v.renderSlot(at.$slots,"header-actions",{},void 0,!0)]),_:3},8,["visible","installedPlugins","marketPlugins","market-category-options","installed-search-fn","market-search-fn","onPluginToggle","onPluginAdd","onPluginDelete","onToolToggle","onPluginCreate"])])]),default:v.withCtx(()=>[v.createVNode(v.unref(Pt.TrBubbleProvider),{"content-renderers":ft},{default:v.withCtx(()=>[v.unref(z).length===0?v.renderSlot(at.$slots,"welcome",{key:0},()=>[v.createElementVNode("div",Qy,[v.createVNode(v.unref(Pt.TrWelcome),{title:v.unref(It)[t.locale].title,description:v.unref(It)[t.locale].description,icon:v.unref(we)},null,8,["title","description","icon"]),v.createVNode(v.unref(Pt.TrPrompts),{items:v.unref(fr),wrap:!0,class:"tiny-prompts","item-class":"prompt-item"},null,8,["items"])])],!0):(v.openBlock(),v.createBlock(v.unref(Pt.TrBubbleList),{key:1,style:{flex:"1"},items:v.unref(z),roles:v.unref(se),"auto-scroll":"",loading:v.unref($).status===v.unref(Zn.STATUS).PROCESSING,"loading-role":"assistant"},null,8,["items","roles","loading"]))]),_:3})]),_:3},8,["show","fullscreen","style"]))}}),Lo=qn(i3,[["__scopeId","data-v-7ad258d3"]]);function o3(t){const r=t.sessionId?ml(t.sessionId,t.agentRoot):[],o=new sr.AgentModelProvider({llmConfig:t.llmConfig,mcpServers:r}),c=v.ref("ready"),u=v.ref([]),f=v.ref("");let p=null;async function x(){const E=f.value;if(!E)return;if(/^\/[A-Za-z0-9-]{6,}$/.test(E)){A(E.slice(1));return}c.value="submitted",p=new AbortController;const B=await o.chatStream({message:E,model:t.model,system:t.systemPrompt||"",abortSignal:p.signal,maxSteps:t.maxSteps||5,onFinish:async()=>{await o.closeAll(),c.value="ready"},onError:()=>c.value="error",onAbort:()=>c.value="ready"});if(f.value="",t.processStream&&typeof t.processStream=="function"){t.processStream(B.fullStream,u,E);return}t.ui==="matechat"?s3(B.fullStream,u,E):t.ui==="antx"?a3(B.fullStream,u,E):t.ui==="elplusx"?l3(B.fullStream,u,E):t.ui==="tdchat"?c3(B.fullStream,u,E):console.warn("暂时未实现")}function y(){p&&p.abort()}function m(){u.value=[],o.responseMessages=[]}async function A(E){const D=(await fetch(`${t.agentRoot}client?sessionId=${E}`).then(M=>M.json()))?.data?.sessionId||"";if(D){const M=ml(D,t.agentRoot);Object.assign(o.mcpServers,M)}}return{agent:o,status:c,messages:u,inputValue:f,chatStream:x,stopChat:y,newConversation:m,addSessionId:A}}function ml(t,r){if(!t)return{};const o=t.includes(",")?t.split(",").map(u=>u.trim()):[t],c={};return o.forEach(u=>{c[`mcp-server-${u}`]={type:"streamableHttp",url:`${r}mcp?sessionId=${u}`}}),c}async function s3(t,r,o){r.value.push({from:"user",content:o,avatarConfig:{name:"user"}});let c={from:"model",content:"",avatarConfig:{name:"model"},id:Date.now().toString()};r.value.push(c),c=r.value[r.value.length-1];for await(const u of t)u.type.startsWith("text-")?u.text&&(c.content+=u.text):u.type.startsWith("tool-")?u.delta&&(c.content+=u.delta):u.type.startsWith("reasoning-")&&u.text&&(c.content+=u.text)}async function a3(t,r,o){r.value.push({from:"user",content:o}),r.value.push({from:"model",content:""});const c=r.value[r.value.length-1];for await(const u of t)u.type.startsWith("text-")?u.text&&(c.content+=u.text):u.type.startsWith("tool-")?u.delta&&(c.content+=u.delta):u.type.startsWith("reasoning-")&&u.text&&(c.content+=u.text)}async function l3(t,r,o){r.value.push({from:"user",content:o}),r.value.push({from:"model",content:""});const c=r.value[r.value.length-1];for await(const u of t)u.type.startsWith("text-")?u.text&&(c.content+=u.text):u.type.startsWith("tool-")?u.delta&&(c.content+=u.delta):u.type.startsWith("reasoning-")&&u.text&&(c.content+=u.text)}async function c3(t,r,o){r.value.push({role:"user",content:o,avatar:"https://tdesign.gtimg.com/site/avatar.jpg"}),r.value.push({role:"assistant",content:"",avatar:"https://tdesign.gtimg.com/site/chat-avatar.png"});const c=r.value[r.value.length-1];for await(const u of t)u.type.startsWith("text-")?u.text&&(c.content+=u.text):u.type.startsWith("tool-")?u.delta&&(c.content+=u.delta):u.type.startsWith("reasoning-")&&u.text&&(c.content+=u.text)}Lo.install=function(t){t.component("tiny-remoter",Lo)};exports.TinyRemoter=Lo;exports.useModel=is;exports.useNextAgent=o3;
89
+ `,t3=btoa(e3),gl=`data:image/svg+xml;base64,${t3}`,bo=(t,r)=>{const[o,c]=t.split("#");return{id:r,text:o,inputMessage:c}},n3=t=>{const r={"zh-CN":{title:"OpenTiny NEXT",description:"我是你的私人智能助手",placeholder:"请输入您的问题",thinking:"正在思考中..."},"en-US":{title:"OpenTiny NEXT",description:"I am your private AI assistant",placeholder:"Please enter your question",thinking:"Thinking..."}},o=[{id:"office",text:t.locale==="zh-CN"?"办公助手":"Office Assistant",menus:["接收邮件#请同步邮箱的新邮件。","编写邮件#请新建一个邮件,收件人为 opentiny-next@meeting.com, 内容为举办一个临时会议。","安排会议#创建一个临时的在线会议,主题为讨论问题,时长为1小时。","整理文档#请分析附件中的销售情况,把销售额绘制成折线图。"].map(bo)},{id:"development",text:t.locale==="zh-CN"?"开发支持":"Development Support",menus:["遇到代码问题#请检查当前位置的报错原因。","架构建议#请使用NodeJs实现一个分块上传文件的模块。","最新的技术趋势#请分析Vue与React 框架的优劣分别是什么?"].map(bo)},{id:"management",text:t.locale==="zh-CN"?"项目管理":"Project Management",menus:["项目规划#如何开展品牌推广的活动?","任务分配#将本季度的销售任务分配给三个人,并生成甘特图进行跟踪。","进度跟踪#分析团队的任务完成情况。"].map(bo)}],c=[{label:t.locale==="zh-CN"?"企业办公助手":"Enterprise Office Assistant",description:t.locale==="zh-CN"?"需要我帮你处理邮件、安排会议、整理文档,还是优化工作流程?":"Need help with emails, meeting scheduling, document organization, or workflow optimization?",icon:v.h("span",{style:{fontSize:"18px"}},"🧠"),badge:"NEW"},{label:t.locale==="zh-CN"?"开发技术支持":"Development Support",description:t.locale==="zh-CN"?"遇到代码问题?需要架构建议?还是想了解最新的技术趋势?":"Facing code issues? Need architecture advice? Or want to learn about latest tech trends?",icon:v.h("span",{style:{fontSize:"18px"}},"💻")},{label:t.locale==="zh-CN"?"项目管理协作":"Project Management",description:t.locale==="zh-CN"?"需要项目规划、任务分配、进度跟踪,还是团队协作建议?":"Need project planning, task assignment, progress tracking, or team collaboration advice?",icon:v.h("span",{style:{fontSize:"18px"}},"📊")}];return{lang:r,pillItems:o,promptItems:c}},xl={"No client found for session ID":"受控端页面已关闭请重新打开或者刷新页面","Failed to create MCP client":"创建MCP客户端失败"},r3=t=>{console.log("message",t);const r=Object.keys(xl),o=r.findIndex(u=>t.includes(u));return(o!==-1?xl[r[o]]:t)||t},i3={class:"tr-container__title"},o3={style:{flex:"1"}},s3={class:"chat-input"},a3={class:"chat-input-pills"},l3={class:"attachments-container"},c3={class:"action-buttons"},u3=v.defineComponent({name:"TinyRemoter",__name:"TinyRobotChat",props:v.mergeModels({sessionId:{type:String,default:""},agentRoot:{type:String,default:"https://agent.opentiny.design/api/v1/webmcp-trial/"},systemPrompt:{type:String,default:"你是一个智能助手,擅长通过工具调用帮助用户解决问题和满足用户需求"},title:{type:String,default:"OpenTiny NEXT"},locale:{type:String,default:"zh-CN"},remoteUrl:{type:String},menuItems:{type:Array},qrCodeUrl:{type:String},AILogoUrl:{type:String},mode:{type:String,default:"remoter"},llmConfig:{type:Object,default:void 0},inBrowserExt:{type:Boolean,default:!1},genUiComponents:{type:Object,default:()=>({})},customMarketMcpServers:{type:Array,default:()=>[]},mcpServers:{type:Object,default:void 0},llmConfigs:{type:Array,default:void 0},skills:{type:Object,default:void 0},layoutMode:{type:String,default:"fixed"}},{fullscreen:{type:Boolean,default:!1},fullscreenModifiers:{},show:{type:Boolean,default:!1},showModifiers:{},selectedModelId:{type:String,default:void 0,required:!1},selectedModelIdModifiers:{},genUiAble:{type:Boolean,default:!1,required:!1},genUiAbleModifiers:{},enabledTools:{type:Object,default:void 0,required:!1},enabledToolsModifiers:{}}),emits:["update:fullscreen","update:show","update:selectedModelId","update:genUiAble","update:enabledTools"],setup(t,{expose:r}){const o=t,c=v.useModel(t,"fullscreen"),u=v.useModel(t,"show"),f=v.useModel(t,"selectedModelId"),p=v.useModel(t,"genUiAble"),x=v.useModel(t,"enabledTools"),_=o.llmConfigs?v.toRef(o,"llmConfigs"):void 0,{selectedModel:g}=os(_,f),{hasMultimodalSupport:A,attachments:E,onFilesSelected:L,checkCanSendAttachments:M,processAttachments:D,cleanupAttachments:R}=Gy({selectedModel:g,selectedModelId:f}),{agent:P,customAgentProvider:H,conversationState:Z,messages:$,messageState:V,inputMessage:ee,abortRequest:j,senderRef:z,sendMessage:q,handleSendMessage:B,addMessage:we,send:re,createConversation:ne,switchConversation:le,deleteConversation:te,getCurrentConversation:O}=dx({systemPrompt:o.systemPrompt||"",llmConfig:o.llmConfig});H.isGenuiEnabled=p;const J=v.toRef(o,"skills"),{processSkillMentions:ae}=My({skillsRef:J,systemPrompt:o.systemPrompt||"",customAgentProvider:H}),oe=async(rt,Oe)=>B(rt,Oe,ae),{welcomeIcon:ge,roles:he}=Uy({messages:$,messageState:V,inputMessage:ee,handleSendMessage:oe}),{showHistory:ue,handleCreateConversation:Ce,handleHistorySelect:je,handleHistoryUpdateTitle:Be,handleHistoryDelete:ut}=zy({createConversation:ne,switchConversation:le,deleteConversation:te,getCurrentConversation:O,abortRequest:j,conversationState:Z,customAgentProvider:H}),ie=()=>{if(g.value){const rt=g.value;H.updateLLMConfig({modelId:rt.id,baseURL:rt.baseURL||"",apiKey:rt.apiKey||"",providerType:rt.providerType,useReActMode:rt.useReActMode,llm:rt.llm,providerOptions:rt.providerOptions,headers:rt.headers})}};o.llmConfigs&&v.watch(g,ie,{immediate:!0}),o.inBrowserExt&&v.watch(p,ie);const Ae={markdown:new Lt.BubbleMarkdownContentRenderer({mdConfig:{html:!0}}),"schema-card":rt=>v.h(bd.GenuiRenderer,{...rt,customActions:{continueChat:{execute:(Oe,Te)=>{const xe=typeof Oe=="string"?Oe:Oe.message,Ot=`${xe},相关参数为:${JSON.stringify(Te?.state||{})}`;we({role:"user",content:Ot,uiContent:[{type:"markdown",content:xe}]}),re()}}},generating:Wn.GeneratingStatus.includes(V.status),customComponents:o.genUiComponents,requiredCompleteFieldSelectors:["[componentName=TinyUser] > props > modelValue"]}),image:Kw},{installedPlugins:Me,marketPlugins:ke,pluginVisible:et,loadMcpServerToPlugin:tt,togglePlugin:Wt,toggleTool:Le,deletePlugin:gn,addPluginFromMarket:Zt,addPluginFromScan:En,handleClientDisconnected:Et,searchPlugin:Xe}=Ry(P,x,gl);ke.value=[...Qw,...o.customMarketMcpServers];const Ze=v.ref([{value:"",label:"全部分类"},{value:"productivity",label:"生产力工具"},{value:"communication",label:"沟通协作"},{value:"development",label:"开发工具"},{value:"ai",label:"AI 助手"}]),{lang:dn,pillItems:N,promptItems:ye}=n3(o),{handleScanSuccess:wt,handleSessionIdInput:_t,initialize:Un}=Vy({sessionId:v.toRef(o,"sessionId"),agentRoot:o.agentRoot,mode:o.mode,qrCodeUrl:o.qrCodeUrl,remoteUrl:o.remoteUrl,menuItems:o.menuItems,AILogoUrl:o.AILogoUrl,show:u,addPluginFromScan:En,inputMessage:ee}),rn=async rt=>{if(await _t(ee.value)||!M())return;const Te=await D();try{await oe(rt,Te),R()}catch(xe){console.error("发送消息失败:",xe)}},ai=v.computed(()=>Wn.GeneratingStatus.includes(V.status)?dn[o.locale].thinking:dn[o.locale].placeholder),An=v.computed(()=>Wn.GeneratingStatus.includes(V.status)),Ut=rt=>{ee.value=rt.inputMessage};Un(),v.onMounted(async()=>{Ce(),P.onError=Oe=>{Oe&&Je(r3(Oe))};const rt=ke.value.filter(Oe=>Oe.addState==="added"&&Oe.enabled);for(const Oe of rt)await Zt(Oe);if(o.mcpServers)for(const[Oe,Te]of Object.entries(o.mcpServers))await tt(Oe,Te)});const{handleCustomAdd:li}=ky(P,Me,gl);return r({agent:P,welcomeIcon:ge,messages:$,messageState:V,roles:he,inputMessage:ee,senderRef:z,abortRequest:j,sendMessage:q,loadMcpServerToPlugin:tt,handleClientDisconnected:Et,addMessage:we}),(rt,Oe)=>(v.openBlock(),v.createBlock(v.unref(Lt.TrContainer),{show:u.value,"onUpdate:show":Oe[11]||(Oe[11]=Te=>u.value=Te),fullscreen:c.value,"onUpdate:fullscreen":Oe[12]||(Oe[12]=Te=>c.value=Te),style:v.normalizeStyle({position:t.layoutMode,width:t.layoutMode!=="fixed"?"unset":void 0,height:t.layoutMode!=="fixed"?"100%":void 0})},{title:v.withCtx(()=>[v.createElementVNode("h3",i3,v.toDisplayString(t.title),1)]),operations:v.withCtx(()=>[v.renderSlot(rt.$slots,"operations",{},()=>[v.createVNode(v.unref(Lt.TrIconButton),{icon:v.unref(Sr.IconNewSession),size:"28",svgSize:"20",onClick:Oe[0]||(Oe[0]=Te=>v.unref(Ce)())},null,8,["icon"]),v.createVNode(v.unref(Lt.TrIconButton),{icon:v.unref(Sr.IconHistory),size:"28",svgSize:"20",onClick:Oe[1]||(Oe[1]=Te=>ue.value=!v.unref(ue))},null,8,["icon"]),v.createVNode(Ew,{onScanSuccess:v.unref(wt)},null,8,["onScanSuccess"]),v.createVNode(v.Transition,{name:"drawer-slide",appear:""},{default:v.withCtx(()=>[v.unref(ue)?(v.openBlock(),v.createElementBlock("div",{key:0,class:"drawer-overlay",onClick:Oe[4]||(Oe[4]=Te=>ue.value=!1)},[v.createElementVNode("div",{class:"drawer-container",onClick:Oe[3]||(Oe[3]=v.withModifiers(()=>{},["stop"])),style:{"--tr-history-item-selected-bg":"#ebeeff"}},[Oe[13]||(Oe[13]=v.createElementVNode("h4",null,"历史会话",-1)),v.createVNode(v.unref(Lt.TrHistory),{class:"tr-history-demo",selected:v.unref(Z).currentId,data:v.unref(Z).conversations,showRenameControls:!0,onClose:Oe[2]||(Oe[2]=Te=>ue.value=!1),onItemClick:v.unref(je),onItemTitleChange:v.unref(Be),onItemAction:v.unref(ut)},null,8,["selected","data","onItemClick","onItemTitleChange","onItemAction"])])])):v.createCommentVNode("",!0)]),_:1})],!0)]),footer:v.withCtx(()=>[v.createElementVNode("div",s3,[v.renderSlot(rt.$slots,"suggestions",{},()=>[v.createElementVNode("div",a3,[(v.openBlock(!0),v.createElementBlock(v.Fragment,null,v.renderList(v.unref(N),Te=>(v.openBlock(),v.createBlock(v.unref(Lt.TrDropdownMenu),{key:Te.id,items:Te.menus,onItemClick:Ut,trigger:"click"},{trigger:v.withCtx(()=>[v.createVNode(v.unref(Lt.TrSuggestionPillButton),null,{default:v.withCtx(()=>[v.createTextVNode(v.toDisplayString(Te.text),1)]),_:2},1024)]),_:2},1032,["items"]))),128))])],!0),v.createVNode(v.unref(Lt.TrSender),{ref_key:"senderRef",ref:z,mode:"multiple",modelValue:v.unref(ee),"onUpdate:modelValue":Oe[9]||(Oe[9]=Te=>v.isRef(ee)?ee.value=Te:null),placeholder:ai.value,clearable:!!v.unref(ee),loading:An.value,showWordLimit:!0,maxLength:2e4,onSubmit:rn,onCancel:v.unref(j)},v.createSlots({footer:v.withCtx(()=>[v.createElementVNode("div",c3,[v.createVNode($w,{"installed-plugins":v.unref(Me),onClick:Oe[6]||(Oe[6]=Te=>et.value=!v.unref(et))},null,8,["installed-plugins"]),v.unref(_)&&v.unref(_).length>0?(v.openBlock(),v.createBlock(Uw,{key:0,"model-configs":v.unref(_),"selected-model-id":f.value,"onUpdate:selectedModelId":Oe[7]||(Oe[7]=Te=>f.value=Te)},null,8,["model-configs","selected-model-id"])):v.createCommentVNode("",!0),t.inBrowserExt?(v.openBlock(),v.createBlock(Gw,{key:1,"genui-enabled":p.value,"onUpdate:genuiEnabled":Oe[8]||(Oe[8]=Te=>p.value=Te)},null,8,["genui-enabled"])):v.createCommentVNode("",!0),v.unref(A)?(v.openBlock(),v.createBlock(v.unref(Lt.TrUploadButton),{key:2,accept:"image/*,application/pdf,.doc,.docx,.txt",multiple:!0,onSelect:v.unref(L)},null,8,["onSelect"])):v.createCommentVNode("",!0)])]),_:2},[v.unref(E).length>0?{name:"header",fn:v.withCtx(()=>[v.createElementVNode("div",l3,[v.createVNode(v.unref(Lt.TrAttachments),{items:v.unref(E),"onUpdate:items":Oe[5]||(Oe[5]=Te=>v.isRef(E)?E.value=Te:null)},null,8,["items"])])]),key:"0"}:void 0]),1032,["modelValue","placeholder","clearable","loading","onCancel"]),v.createVNode(v.unref(Lt.TrMcpServerPicker),{visible:v.unref(et),"onUpdate:visible":Oe[10]||(Oe[10]=Te=>v.isRef(et)?et.value=Te:null),"popup-config":{type:"drawer"},"show-custom-add-button":!0,marketTabTitle:"MCP市场",installedTabTitle:"已添加MCP服务",title:"扩展",installedPlugins:v.unref(Me),marketPlugins:v.unref(ke),"market-category-options":Ze.value,"installed-search-fn":v.unref(Xe),"market-search-fn":v.unref(Xe),onPluginToggle:v.unref(Wt),onPluginAdd:v.unref(Zt),onPluginDelete:v.unref(gn),onToolToggle:v.unref(Le),onPluginCreate:v.unref(li)},{"header-actions":v.withCtx(()=>[v.renderSlot(rt.$slots,"header-actions",{},void 0,!0)]),_:3},8,["visible","installedPlugins","marketPlugins","market-category-options","installed-search-fn","market-search-fn","onPluginToggle","onPluginAdd","onPluginDelete","onToolToggle","onPluginCreate"])])]),default:v.withCtx(()=>[v.createVNode(v.unref(Lt.TrBubbleProvider),{"content-renderers":Ae},{default:v.withCtx(()=>[v.unref($).length===0?v.renderSlot(rt.$slots,"welcome",{key:0},()=>[v.createElementVNode("div",o3,[v.createVNode(v.unref(Lt.TrWelcome),{title:v.unref(dn)[t.locale].title,description:v.unref(dn)[t.locale].description,icon:v.unref(ge)},null,8,["title","description","icon"]),v.createVNode(v.unref(Lt.TrPrompts),{items:v.unref(ye),wrap:!0,class:"tiny-prompts","item-class":"prompt-item"},null,8,["items"])])],!0):(v.openBlock(),v.createBlock(v.unref(Lt.TrBubbleList),{key:1,style:{flex:"1"},items:v.unref($),roles:v.unref(he),"auto-scroll":"",loading:v.unref(V).status===v.unref(Wn.STATUS).PROCESSING,"loading-role":"assistant"},null,8,["items","roles","loading"]))]),_:3})]),_:3},8,["show","fullscreen","style"]))}}),Fo=Kn(u3,[["__scopeId","data-v-595e13f4"]]);function d3(t){const r=t.sessionId?yl(t.sessionId,t.agentRoot):[],o=new cr.AgentModelProvider({llmConfig:t.llmConfig,mcpServers:r}),c=v.ref("ready"),u=v.ref([]),f=v.ref("");let p=null;async function x(){const E=f.value;if(!E)return;if(/^\/[A-Za-z0-9-]{6,}$/.test(E)){A(E.slice(1));return}c.value="submitted",p=new AbortController;const L=await o.chatStream({message:E,model:t.model,system:t.systemPrompt||"",abortSignal:p.signal,maxSteps:t.maxSteps||5,onFinish:async()=>{await o.closeAll(),c.value="ready"},onError:()=>c.value="error",onAbort:()=>c.value="ready"});if(f.value="",t.processStream&&typeof t.processStream=="function"){t.processStream(L.fullStream,u,E);return}t.ui==="matechat"?f3(L.fullStream,u,E):t.ui==="antx"?h3(L.fullStream,u,E):t.ui==="elplusx"?p3(L.fullStream,u,E):t.ui==="tdchat"?m3(L.fullStream,u,E):console.warn("暂时未实现")}function _(){p&&p.abort()}function g(){u.value=[],o.responseMessages=[]}async function A(E){const M=(await fetch(`${t.agentRoot}client?sessionId=${E}`).then(D=>D.json()))?.data?.sessionId||"";if(M){const D=yl(M,t.agentRoot);Object.assign(o.mcpServers,D)}}return{agent:o,status:c,messages:u,inputValue:f,chatStream:x,stopChat:_,newConversation:g,addSessionId:A}}function yl(t,r){if(!t)return{};const o=t.includes(",")?t.split(",").map(u=>u.trim()):[t],c={};return o.forEach(u=>{c[`mcp-server-${u}`]={type:"streamableHttp",url:`${r}mcp?sessionId=${u}`}}),c}async function f3(t,r,o){r.value.push({from:"user",content:o,avatarConfig:{name:"user"}});let c={from:"model",content:"",avatarConfig:{name:"model"},id:Date.now().toString()};r.value.push(c),c=r.value[r.value.length-1];for await(const u of t)u.type.startsWith("text-")?u.text&&(c.content+=u.text):u.type.startsWith("tool-")?u.delta&&(c.content+=u.delta):u.type.startsWith("reasoning-")&&u.text&&(c.content+=u.text)}async function h3(t,r,o){r.value.push({from:"user",content:o}),r.value.push({from:"model",content:""});const c=r.value[r.value.length-1];for await(const u of t)u.type.startsWith("text-")?u.text&&(c.content+=u.text):u.type.startsWith("tool-")?u.delta&&(c.content+=u.delta):u.type.startsWith("reasoning-")&&u.text&&(c.content+=u.text)}async function p3(t,r,o){r.value.push({from:"user",content:o}),r.value.push({from:"model",content:""});const c=r.value[r.value.length-1];for await(const u of t)u.type.startsWith("text-")?u.text&&(c.content+=u.text):u.type.startsWith("tool-")?u.delta&&(c.content+=u.delta):u.type.startsWith("reasoning-")&&u.text&&(c.content+=u.text)}async function m3(t,r,o){r.value.push({role:"user",content:o,avatar:"https://tdesign.gtimg.com/site/avatar.jpg"}),r.value.push({role:"assistant",content:"",avatar:"https://tdesign.gtimg.com/site/chat-avatar.png"});const c=r.value[r.value.length-1];for await(const u of t)u.type.startsWith("text-")?u.text&&(c.content+=u.text):u.type.startsWith("tool-")?u.delta&&(c.content+=u.delta):u.type.startsWith("reasoning-")&&u.text&&(c.content+=u.text)}Fo.install=function(t){t.component("tiny-remoter",Fo)};exports.TinyRemoter=Fo;exports.useModel=os;exports.useNextAgent=d3;