voltage-payments-component
Version:
Lightweight, framework-agnostic Bitcoin payment components for web applications using Voltage Payments
1 lines • 93.4 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).VoltagePayments={})}(this,(function(t){"use strict";var e=Object.defineProperty,n=Object.defineProperties,o=Object.getOwnPropertyDescriptors,r=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,s=(t,n,o)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o,l=(t,e)=>{for(var n in e||(e={}))i.call(e,n)&&s(t,n,e[n]);if(r)for(var n of r(e))a.call(e,n)&&s(t,n,e[n]);return t},d=(t,e)=>n(t,o(e)),c=(t,e)=>{var n={};for(var o in t)i.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&r)for(var o of r(t))e.indexOf(o)<0&&a.call(t,o)&&(n[o]=t[o]);return n},u=(t,e,n)=>s(t,"symbol"!=typeof e?e+"":e,n);class p{constructor(t){this.svelteComponent=null,this.container=null,this.options=t}async mount(t){const e="string"==typeof t?document.querySelector(t):t;if(!e)throw new Error(`Cannot find element: ${t}`);if(!(e instanceof HTMLElement))throw new Error("Target must be an HTMLElement");this.container=e;const n=(await Promise.resolve().then((()=>Sn))).default;this.svelteComponent=new n({target:this.container,props:{apiKey:this.options.apiKey,walletId:this.options.walletId,amount:this.options.amount,paymentKind:this.options.paymentKind||"bip21",description:this.options.description||"",appearance:this.options.appearance||{},theme:this.options.theme||"auto",showQRCode:!1!==this.options.showQRCode,showCopyButton:!1!==this.options.showCopyButton,pollingConfig:this.options.pollingConfig||{},organizationId:this.options.organizationId,environmentId:this.options.environmentId,baseUrl:this.options.baseUrl}}),this.setupEventListeners()}unmount(){this.svelteComponent&&(this.svelteComponent.$destroy(),this.svelteComponent=null),this.container=null}destroy(){this.unmount()}updateOptions(t){this.options=l(l({},this.options),t),this.svelteComponent&&this.svelteComponent.$set({apiKey:this.options.apiKey,walletId:this.options.walletId,amount:this.options.amount,paymentKind:this.options.paymentKind||"bip21",description:this.options.description||"",appearance:this.options.appearance||{},theme:this.options.theme||"auto",showQRCode:!1!==this.options.showQRCode,showCopyButton:!1!==this.options.showCopyButton,pollingConfig:this.options.pollingConfig||{},organizationId:this.options.organizationId,environmentId:this.options.environmentId,baseUrl:this.options.baseUrl})}getStatus(){return"generating"}getPaymentData(){return null}setupEventListeners(){this.svelteComponent&&(this.svelteComponent.$on("ready",(t=>{var e,n;null==(n=(e=this.options).onReady)||n.call(e,t.detail)})),this.svelteComponent.$on("qrGenerated",(t=>{var e,n;const{qrData:o,paymentRequest:r}=t.detail;null==(n=(e=this.options).onQRGenerated)||n.call(e,o,r)})),this.svelteComponent.$on("statusChange",(t=>{var e,n;const{status:o,payment:r}=t.detail;null==(n=(e=this.options).onStatusChange)||n.call(e,o,r)})),this.svelteComponent.$on("success",(t=>{var e,n;null==(n=(e=this.options).onSuccess)||n.call(e,t.detail)})),this.svelteComponent.$on("error",(t=>{var e,n;null==(n=(e=this.options).onError)||n.call(e,t.detail)})),this.svelteComponent.$on("expired",(t=>{var e,n;null==(n=(e=this.options).onExpired)||n.call(e,t.detail)})))}}class m{constructor(t){this.svelteComponent=null,this.container=null,this.triggerButton=null,this.options=t}async mount(t){const e="string"==typeof t?document.querySelector(t):t;if(!e)throw new Error(`Cannot find element: ${t}`);if(!(e instanceof HTMLElement))throw new Error("Target must be an HTMLElement");this.container=e,this.createTriggerButton();const n=(await Promise.resolve().then((()=>Fn))).default;this.svelteComponent=new n({target:document.body,props:{apiKey:this.options.apiKey,walletId:this.options.walletId,amount:this.options.amount,paymentKind:this.options.paymentKind||"bip21",description:this.options.description||"",appearance:this.options.appearance||{},theme:this.options.theme||"auto",showQRCode:!1!==this.options.showQRCode,showCopyButton:!1!==this.options.showCopyButton,pollingConfig:this.options.pollingConfig||{},organizationId:this.options.organizationId,environmentId:this.options.environmentId,baseUrl:this.options.baseUrl,autoClose:!1!==this.options.autoClose}}),this.setupEventListeners()}unmount(){this.svelteComponent&&(this.svelteComponent.$destroy(),this.svelteComponent=null),this.triggerButton&&this.container&&(this.container.removeChild(this.triggerButton),this.triggerButton=null),this.container=null}destroy(){this.unmount()}updateOptions(t){if(this.options=l(l({},this.options),t),this.svelteComponent&&this.svelteComponent.$set({apiKey:this.options.apiKey,walletId:this.options.walletId,amount:this.options.amount,paymentKind:this.options.paymentKind||"bip21",description:this.options.description||"",appearance:this.options.appearance||{},theme:this.options.theme||"auto",showQRCode:!1!==this.options.showQRCode,showCopyButton:!1!==this.options.showCopyButton,pollingConfig:this.options.pollingConfig||{},organizationId:this.options.organizationId,environmentId:this.options.environmentId,baseUrl:this.options.baseUrl,autoClose:!1!==this.options.autoClose}),this.triggerButton&&t.description){const e=this.triggerButton.querySelector(".voltage-modal-trigger-text");e&&(e.textContent=t.description)}}getStatus(){return"generating"}getPaymentData(){return null}open(){var t,e;this.svelteComponent&&(this.svelteComponent.open(),null==(e=(t=this.options).onModalOpen)||e.call(t))}close(){var t,e;this.svelteComponent&&(this.svelteComponent.close(),null==(e=(t=this.options).onModalClose)||e.call(t))}createTriggerButton(){this.container&&(this.triggerButton=document.createElement("button"),this.triggerButton.className="voltage-modal-trigger",this.triggerButton.innerHTML=`\n <svg class="voltage-modal-trigger-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">\n <path d="M12 2L2 7v10c0 5.55 3.84 10 9 11 5.16-1 9-5.45 9-11V7z"/>\n <path d="M9 12l2 2 4-4"/>\n </svg>\n <span class="voltage-modal-trigger-text">\n ${this.options.description||"Pay with Bitcoin"}\n </span>\n `,this.triggerButton.addEventListener("click",(()=>{this.open()})),this.addTriggerButtonStyles(),this.container.appendChild(this.triggerButton))}addTriggerButtonStyles(){var t,e,n;if(!this.triggerButton)return;const o=(null==(t=this.options.appearance)?void 0:t.primaryColor)||"#f7931a",r=(null==(e=this.options.appearance)?void 0:e.borderRadius)||"8px",i=(null==(n=this.options.appearance)?void 0:n.fontFamily)||"system-ui, sans-serif";if(!document.getElementById("voltage-modal-trigger-styles")){const t=document.createElement("style");t.id="voltage-modal-trigger-styles",t.textContent=`\n .voltage-modal-trigger {\n display: inline-flex;\n align-items: center;\n gap: 0.5rem;\n padding: 0.75rem 1.5rem;\n background: ${o};\n color: white;\n border: none;\n border-radius: ${r};\n font-family: ${i};\n font-size: 1rem;\n font-weight: 600;\n cursor: pointer;\n transition: all 150ms ease-in-out;\n text-decoration: none;\n box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);\n }\n\n .voltage-modal-trigger:hover {\n opacity: 0.9;\n transform: translateY(-1px);\n box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);\n }\n\n .voltage-modal-trigger:active {\n transform: translateY(0);\n }\n\n .voltage-modal-trigger:focus {\n outline: 2px solid ${o};\n outline-offset: 2px;\n }\n\n .voltage-modal-trigger-icon {\n flex-shrink: 0;\n }\n\n .voltage-modal-trigger-text {\n white-space: nowrap;\n }\n\n /* Dark theme support */\n @media (prefers-color-scheme: dark) {\n .voltage-modal-trigger {\n box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.3);\n }\n\n .voltage-modal-trigger:hover {\n box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);\n }\n }\n\n /* Mobile responsive */\n @media (max-width: 640px) {\n .voltage-modal-trigger {\n padding: 0.625rem 1.25rem;\n font-size: 0.875rem;\n }\n }\n `,document.head.appendChild(t)}}setupEventListeners(){this.svelteComponent&&(this.svelteComponent.$on("ready",(t=>{var e,n;null==(n=(e=this.options).onReady)||n.call(e,t.detail)})),this.svelteComponent.$on("qrGenerated",(t=>{var e,n;const{qrData:o,paymentRequest:r}=t.detail;null==(n=(e=this.options).onQRGenerated)||n.call(e,o,r)})),this.svelteComponent.$on("statusChange",(t=>{var e,n;const{status:o,payment:r}=t.detail;null==(n=(e=this.options).onStatusChange)||n.call(e,o,r)})),this.svelteComponent.$on("success",(t=>{var e,n;null==(n=(e=this.options).onSuccess)||n.call(e,t.detail)})),this.svelteComponent.$on("error",(t=>{var e,n;null==(n=(e=this.options).onError)||n.call(e,t.detail)})),this.svelteComponent.$on("expired",(t=>{var e,n;null==(n=(e=this.options).onExpired)||n.call(e,t.detail)})),this.svelteComponent.$on("modalClosed",(()=>{var t,e;null==(e=(t=this.options).onModalClose)||e.call(t)})))}}class g{constructor(t){this.svelteComponent=null,this.container=null,this.options=t}async mount(t){const e="string"==typeof t?document.querySelector(t):t;if(!e)throw new Error(`Cannot find element: ${t}`);if(!(e instanceof HTMLElement))throw new Error("Target must be an HTMLElement");this.container=e;const n=(await Promise.resolve().then((()=>eo))).default;this.svelteComponent=new n({target:this.container,props:{apiKey:this.options.apiKey,walletId:this.options.walletId,amount:this.options.amount,paymentKind:this.options.paymentKind||"bip21",description:this.options.description||"",appearance:this.options.appearance||{},theme:this.options.theme||"auto",showQRCode:!1!==this.options.showQRCode,showCopyButton:!1!==this.options.showCopyButton,pollingConfig:this.options.pollingConfig||{},organizationId:this.options.organizationId,environmentId:this.options.environmentId,baseUrl:this.options.baseUrl}}),this.setupEventListeners()}unmount(){this.svelteComponent&&(this.svelteComponent.$destroy(),this.svelteComponent=null),this.container=null}destroy(){this.unmount()}updateOptions(t){this.options=l(l({},this.options),t),this.svelteComponent&&this.svelteComponent.$set({apiKey:this.options.apiKey,walletId:this.options.walletId,amount:this.options.amount,paymentKind:this.options.paymentKind||"bip21",description:this.options.description||"",appearance:this.options.appearance||{},theme:this.options.theme||"auto",showQRCode:!1!==this.options.showQRCode,showCopyButton:!1!==this.options.showCopyButton,pollingConfig:this.options.pollingConfig||{},organizationId:this.options.organizationId,environmentId:this.options.environmentId,baseUrl:this.options.baseUrl})}getStatus(){return"generating"}getPaymentData(){return null}togglePayment(){this.svelteComponent&&this.svelteComponent.togglePayment()}isPaymentVisible(){return!1}setupEventListeners(){this.svelteComponent&&(this.svelteComponent.$on("ready",(t=>{var e,n;null==(n=(e=this.options).onReady)||n.call(e,t.detail)})),this.svelteComponent.$on("qrGenerated",(t=>{var e,n;const{qrData:o,paymentRequest:r}=t.detail;null==(n=(e=this.options).onQRGenerated)||n.call(e,o,r)})),this.svelteComponent.$on("statusChange",(t=>{var e,n;const{status:o,payment:r}=t.detail;null==(n=(e=this.options).onStatusChange)||n.call(e,o,r)})),this.svelteComponent.$on("success",(t=>{var e,n;null==(n=(e=this.options).onSuccess)||n.call(e,t.detail)})),this.svelteComponent.$on("error",(t=>{var e,n;null==(n=(e=this.options).onError)||n.call(e,t.detail)})),this.svelteComponent.$on("expired",(t=>{var e,n;null==(n=(e=this.options).onExpired)||n.call(e,t.detail)})),this.svelteComponent.$on("buttonActivated",(()=>{var t,e;null==(e=(t=this.options).onButtonActivated)||e.call(t)})),this.svelteComponent.$on("buttonDeactivated",(()=>{var t,e;null==(e=(t=this.options).onButtonDeactivated)||e.call(t)})))}}function h(){}const f=t=>t;function v(t){return t()}function y(){return Object.create(null)}function w(t){t.forEach(v)}function b(t){return"function"==typeof t}function x(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}let C;function $(t,e){return t===e||(C||(C=document.createElement("a")),C.href=e,t===C.href)}const E="undefined"!=typeof window;let _=E?()=>window.performance.now():()=>Date.now(),I=E?t=>requestAnimationFrame(t):h;const k=new Set;function z(t){k.forEach((e=>{e.c(t)||(k.delete(e),e.f())})),0!==k.size&&I(z)}function P(t,e){t.appendChild(e)}function T(t,e,n){const o=B(t);if(!o.getElementById(e)){const t=q("style");t.id=e,t.textContent=n,A(o,t)}}function B(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function R(t){const e=q("style");return e.textContent="/* empty */",A(B(t),e),e.sheet}function A(t,e){return P(t.head||t,e),e.sheet}function M(t,e,n){t.insertBefore(e,n||null)}function S(t){t.parentNode&&t.parentNode.removeChild(t)}function q(t){return document.createElement(t)}function U(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function L(t){return document.createTextNode(t)}function N(){return L(" ")}function K(t,e,n,o){return t.addEventListener(e,n,o),()=>t.removeEventListener(e,n,o)}function j(t,e,n){null==n?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function O(t,e){e=""+e,t.data!==e&&(t.data=e)}function D(t,e,n,o){null==n?t.style.removeProperty(e):t.style.setProperty(e,n,"")}function F(t,e,n){t.classList.toggle(e,!!n)}function Q(t,e,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:o})}const H=new Map;let Y,J=0;function V(t,e,n,o,r,i,a,s=0){const l=16.666/o;let d="{\n";for(let f=0;f<=1;f+=l){const t=e+(n-e)*i(f);d+=100*f+`%{${a(t,1-t)}}\n`}const c=d+`100% {${a(n,1-n)}}\n}`,u=`__svelte_${function(t){let e=5381,n=t.length;for(;n--;)e=(e<<5)-e^t.charCodeAt(n);return e>>>0}(c)}_${s}`,p=B(t),{stylesheet:m,rules:g}=H.get(p)||function(t,e){const n={stylesheet:R(e),rules:{}};return H.set(t,n),n}(p,t);g[u]||(g[u]=!0,m.insertRule(`@keyframes ${u} ${c}`,m.cssRules.length));const h=t.style.animation||"";return t.style.animation=`${h?`${h}, `:""}${u} ${o}ms linear ${r}ms 1 both`,J+=1,u}function W(t,e){const n=(t.style.animation||"").split(", "),o=n.filter(e?t=>t.indexOf(e)<0:t=>-1===t.indexOf("__svelte")),r=n.length-o.length;r&&(t.style.animation=o.join(", "),J-=r,J||I((()=>{J||(H.forEach((t=>{const{ownerNode:e}=t.stylesheet;e&&S(e)})),H.clear())})))}function G(t){Y=t}function X(){if(!Y)throw new Error("Function called outside component initialization");return Y}function Z(t){X().$$.on_mount.push(t)}function tt(){const t=X();return(e,n,{cancelable:o=!1}={})=>{const r=t.$$.callbacks[e];if(r){const i=Q(e,n,{cancelable:o});return r.slice().forEach((e=>{e.call(t,i)})),!i.defaultPrevented}return!0}}const et=[],nt=[];let ot=[];const rt=[],it=Promise.resolve();let at=!1;function st(t){ot.push(t)}const lt=new Set;let dt,ct=0;function ut(){if(0!==ct)return;const t=Y;do{try{for(;ct<et.length;){const t=et[ct];ct++,G(t),pt(t.$$)}}catch(e){throw et.length=0,ct=0,e}for(G(null),et.length=0,ct=0;nt.length;)nt.pop()();for(let t=0;t<ot.length;t+=1){const e=ot[t];lt.has(e)||(lt.add(e),e())}ot.length=0}while(et.length);for(;rt.length;)rt.pop()();at=!1,lt.clear(),G(t)}function pt(t){if(null!==t.fragment){t.update(),w(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(st)}}function mt(t,e,n){t.dispatchEvent(Q(`${e?"intro":"outro"}${n}`))}const gt=new Set;let ht;function ft(){ht={r:0,c:[],p:ht}}function vt(){ht.r||w(ht.c),ht=ht.p}function yt(t,e){t&&t.i&&(gt.delete(t),t.i(e))}function wt(t,e,n,o){if(t&&t.o){if(gt.has(t))return;gt.add(t),ht.c.push((()=>{gt.delete(t),o&&(n&&t.d(1),o())})),t.o(e)}else o&&o()}const bt={duration:0};function xt(t,e,n,o){let r,i=e(t,n,{direction:"both"}),a=o?0:1,s=null,l=null,d=null;function c(){d&&W(t,d)}function u(t,e){const n=t.b-a;return e*=Math.abs(n),{a:a,b:t.b,d:n,duration:e,start:t.start,end:t.start+e,group:t.group}}function p(e){const{delay:n=0,duration:o=300,easing:p=f,tick:m=h,css:g}=i||bt,v={start:_()+n,b:e};e||(v.group=ht,ht.r+=1),"inert"in t&&(e?void 0!==r&&(t.inert=r):(r=t.inert,t.inert=!0)),s||l?l=v:(g&&(c(),d=V(t,a,e,o,n,p,g)),e&&m(0,1),s=u(v,o),st((()=>mt(t,e,"start"))),function(t){let e;0===k.size&&I(z),new Promise((n=>{k.add(e={c:t,f:n})}))}((e=>{if(l&&e>l.start&&(s=u(l,o),l=null,mt(t,s.b,"start"),g&&(c(),d=V(t,a,s.b,s.duration,0,p,i.css))),s)if(e>=s.end)m(a=s.b,1-a),mt(t,s.b,"end"),l||(s.b?c():--s.group.r||w(s.group.c)),s=null;else if(e>=s.start){const t=e-s.start;a=s.a+s.d*p(t/s.duration),m(a,1-a)}return!(!s&&!l)})))}return{run(t){b(i)?(dt||(dt=Promise.resolve(),dt.then((()=>{dt=null}))),dt).then((()=>{i=i({direction:t?"in":"out"}),p(t)})):p(t)},end(){c(),s=l=null}}}function Ct(t){t&&t.c()}function $t(t,e,n){const{fragment:o,after_update:r}=t.$$;o&&o.m(e,n),st((()=>{const e=t.$$.on_mount.map(v).filter(b);t.$$.on_destroy?t.$$.on_destroy.push(...e):w(e),t.$$.on_mount=[]})),r.forEach(st)}function Et(t,e){const n=t.$$;null!==n.fragment&&(!function(t){const e=[],n=[];ot.forEach((o=>-1===t.indexOf(o)?e.push(o):n.push(o))),n.forEach((t=>t())),ot=e}(n.after_update),w(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function _t(t,e){-1===t.$$.dirty[0]&&(et.push(t),at||(at=!0,it.then(ut)),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function It(t,e,n,o,r,i,a=null,s=[-1]){const l=Y;G(t);const d=t.$$={fragment:null,ctx:[],props:i,update:h,not_equal:r,bound:y(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(l?l.$$.context:[])),callbacks:y(),dirty:s,skip_bound:!1,root:e.target||l.$$.root};a&&a(d.root);let c=!1;if(d.ctx=n?n(t,e.props||{},((e,n,...o)=>{const i=o.length?o[0]:n;return d.ctx&&r(d.ctx[e],d.ctx[e]=i)&&(!d.skip_bound&&d.bound[e]&&d.bound[e](i),c&&_t(t,e)),n})):[],d.update(),c=!0,w(d.before_update),d.fragment=!!o&&o(d.ctx),e.target){if(e.hydrate){const t=(u=e.target,Array.from(u.childNodes));d.fragment&&d.fragment.l(t),t.forEach(S)}else d.fragment&&d.fragment.c();e.intro&&yt(t.$$.fragment),$t(t,e.target,e.anchor),ut()}var u;G(l)}class kt{constructor(){u(this,"$$"),u(this,"$$set")}$destroy(){Et(this,1),this.$destroy=h}$on(t,e){if(!b(e))return h;const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(t){var e;this.$$set&&(e=t,0!==Object.keys(e).length)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}"undefined"!=typeof window&&(window.__svelte||(window.__svelte={v:new Set})).v.add("4");class zt extends Error{constructor(t,e,n,o){super(t),this.name="VoltageApiError",this.status=e,this.code=n,this.details=o}}class Pt{constructor(t){if(this.baseUrl=t.baseUrl||"https://voltageapi.com/v1",this.apiKey=t.apiKey,this.bearerToken=t.bearerToken,this.timeout=t.timeout||3e4,this.baseUrl.endsWith("/")&&(this.baseUrl=this.baseUrl.slice(0,-1)),"undefined"==typeof fetch)throw new Error("Fetch is not available. Please use Node.js 18+ or provide a fetch polyfill.")}getAuthHeaders(){const t={};return this.bearerToken?t.Authorization=`Bearer ${this.bearerToken}`:this.apiKey&&(t["X-Api-Key"]=this.apiKey),t}async withTimeout(t,e){let n;const o=new Promise(((t,o)=>{n=setTimeout((()=>o(new zt("Request timeout",408))),e)}));try{const e=await Promise.race([t,o]);return n&&clearTimeout(n),e}catch(r){throw n&&clearTimeout(n),r}}async request(t,e={}){const{method:n="GET",body:o,headers:r={},timeout:i=this.timeout}=e,a=`${this.baseUrl}${t}`,s=this.getAuthHeaders(),d={method:n,headers:l(l({"Content-Type":"application/json"},s),r)};o&&"GET"!==n&&(d.body=JSON.stringify(o));try{const t=await this.withTimeout(fetch(a,d),i),e=await t.text();let n;try{n=e?JSON.parse(e):null}catch(c){throw new zt("Failed to parse response as JSON",t.status,"PARSE_ERROR",c)}if(!t.ok){const e="object"==typeof n&&null!==n&&"message"in n?n.message:`HTTP ${t.status}: ${t.statusText}`;throw new zt(e,t.status,"HTTP_ERROR",n)}return{data:n,status:t.status,statusText:t.statusText}}catch(u){if(u instanceof zt)throw u;throw new zt(u instanceof Error?u.message:"Unknown error occurred",void 0,"NETWORK_ERROR",u)}}async get(t,e){return this.request(t,{method:"GET",headers:e})}async post(t,e,n){return this.request(t,{method:"POST",body:e,headers:n})}async put(t,e,n){return this.request(t,{method:"PUT",body:e,headers:n})}async patch(t,e,n){return this.request(t,{method:"PATCH",body:e,headers:n})}async delete(t,e){return this.request(t,{method:"DELETE",headers:e})}}const Tt={maxAttempts:30,intervalMs:1e3,timeoutMs:3e4};class Bt{constructor(t){if(!t.apiKey&&!t.bearerToken)throw new Error("Either apiKey or bearerToken must be provided");this.httpClient=new Pt(t)}async getWallets(t){const{organization_id:e}=t;if(!e)throw new Error("organization_id is required");return(await this.httpClient.get(`/organizations/${e}/wallets`)).data}async getWallet(t){const{organization_id:e,wallet_id:n}=t;if(!e||!n)throw new Error("organization_id and wallet_id are required");return(await this.httpClient.get(`/organizations/${e}/wallets/${n}`)).data}async createWallet(t){const{organization_id:e,wallet:n}=t;if(!e)throw new Error("organization_id is required");if(!n)throw new Error("wallet data is required");await this.httpClient.post(`/organizations/${e}/wallets`,n)}async deleteWallet(t){const{organization_id:e,wallet_id:n}=t;if(!e||!n)throw new Error("organization_id and wallet_id are required");await this.httpClient.delete(`/organizations/${e}/wallets/${n}`)}async createPaymentRequest(t,e){const{organization_id:n,environment_id:o,payment:r}=t;if(!n||!o)throw new Error("organization_id and environment_id are required");if(!r)throw new Error("payment data is required");const i=d(l({},r),{id:r.id||crypto.randomUUID()}),a=l(l({},Tt),e);return await this.httpClient.post(`/organizations/${n}/environments/${o}/payments`,i),this.pollForPayment({organization_id:n,environment_id:o,payment_id:i.id},a)}async getPayment(t){const{organization_id:e,environment_id:n,payment_id:o}=t;if(!e||!n||!o)throw new Error("organization_id, environment_id, and payment_id are required");return(await this.httpClient.get(`/organizations/${e}/environments/${n}/payments/${o}`)).data}async getPayments(t){const e=t,{organization_id:n,environment_id:o}=e,r=c(e,["organization_id","environment_id"]);if(!n||!o)throw new Error("organization_id and environment_id are required");const i=new URLSearchParams;Object.entries(r).forEach((([t,e])=>{null!=e&&(Array.isArray(e)?e.forEach((e=>i.append(t,e.toString()))):i.append(t,e.toString()))}));const a=i.toString(),s=`/organizations/${n}/environments/${o}/payments${a?`?${a}`:""}`;return(await this.httpClient.get(s)).data}async pollForPayment(t,e){const n=Date.now();let o=0;for(;o<e.maxAttempts;){if(Date.now()-n>e.timeoutMs)throw new Error(`Payment polling timed out after ${e.timeoutMs}ms`);try{const n=await this.getPayment(t);if("receive"!==n.direction)throw new Error("Expected receive payment but got send payment");const r=n;if("generating"!==r.status){if("failed"===r.status){let t="Payment generation failed";throw r.error&&("receive_failed"===r.error.type?t=`Payment generation failed: ${r.error.detail}`:"expired"===r.error.type&&(t="Payment generation failed: Payment expired")),new Error(t)}return r}await this.sleep(e.intervalMs),o++}catch(r){if(r instanceof Error&&r.message.includes("timed out"))throw r;if(r instanceof Error&&r.message.includes("Payment generation failed"))throw r;await this.sleep(e.intervalMs),o++}}throw new Error(`Payment polling failed after ${e.maxAttempts} attempts`)}sleep(t){return new Promise((e=>setTimeout(e,t)))}async sendPayment(t,e){const{organization_id:n,environment_id:o,payment:r}=t;if(!n||!o)throw new Error("organization_id and environment_id are required");if(!r)throw new Error("payment data is required");const i=d(l({},r),{id:r.id||crypto.randomUUID()}),a=l(l({},Tt),e);return await this.httpClient.post(`/organizations/${n}/environments/${o}/payments`,i),this.pollForSendPayment({organization_id:n,environment_id:o,payment_id:i.id},a)}async pollForSendPayment(t,e){const n=Date.now();let o=0;for(;o<e.maxAttempts;){if(Date.now()-n>e.timeoutMs)throw new Error(`Send payment polling timed out after ${e.timeoutMs}ms`);try{const n=await this.getPayment(t);if("send"!==n.direction)throw new Error("Expected send payment but got receive payment");const r=n;if("sending"!==r.status){if("failed"===r.status){let t="Send payment failed";throw r.error&&(t=`Send payment failed: ${r.error.detail}`),new Error(t)}return r}await this.sleep(e.intervalMs),o++}catch(r){if(r instanceof Error&&r.message.includes("timed out"))throw r;if(r instanceof Error&&r.message.includes("Send payment failed"))throw r;await this.sleep(e.intervalMs),o++}}throw new Error(`Send payment polling failed after ${e.maxAttempts} attempts`)}async getWalletLedger(t){const e=t,{organization_id:n,wallet_id:o}=e,r=c(e,["organization_id","wallet_id"]);if(!n||!o)throw new Error("organization_id and wallet_id are required");const i=new URLSearchParams;Object.entries(r).forEach((([t,e])=>{null!=e&&i.append(t,e.toString())}));const a=i.toString(),s=`/organizations/${n}/wallets/${o}/ledger${a?`?${a}`:""}`;return(await this.httpClient.get(s)).data}async getPaymentHistory(t){const{organization_id:e,environment_id:n,payment_id:o}=t;if(!e||!n||!o)throw new Error("organization_id, environment_id, and payment_id are required");return(await this.httpClient.get(`/organizations/${e}/environments/${n}/payments/${o}/history`)).data}async getLineOfCredit(t){const{organization_id:e,line_id:n}=t;if(!e||!n)throw new Error("organization_id and line_id are required");return(await this.httpClient.get(`/organizations/${e}/lines_of_credit/${n}/summary`)).data}async getLinesOfCredit(t){const{organization_id:e}=t;if(!e)throw new Error("organization_id is required");return(await this.httpClient.get(`/organizations/${e}/lines_of_credit/summaries`)).data}async getWebhooks(t){const e=t,{organization_id:n}=e,o=c(e,["organization_id"]);if(!n)throw new Error("organization_id is required");const r=new URLSearchParams;Object.entries(o).forEach((([t,e])=>{null!=e&&(Array.isArray(e)?e.forEach((e=>r.append(t,e.toString()))):r.append(t,e.toString()))}));const i=r.toString(),a=`/organizations/${n}/webhooks${i?`?${i}`:""}`;return(await this.httpClient.get(a)).data}async getWebhook(t){const{organization_id:e,environment_id:n,webhook_id:o}=t;if(!e||!n||!o)throw new Error("organization_id, environment_id, and webhook_id are required");return(await this.httpClient.get(`/organizations/${e}/environments/${n}/webhooks/${o}`)).data}async createWebhook(t){const{organization_id:e,environment_id:n,webhook:o}=t;if(!e||!n)throw new Error("organization_id and environment_id are required");if(!o)throw new Error("webhook data is required");const r=d(l({},o),{id:o.id||crypto.randomUUID()});return(await this.httpClient.post(`/organizations/${e}/environments/${n}/webhooks`,r)).data}async updateWebhook(t){const{organization_id:e,environment_id:n,webhook_id:o,webhook:r}=t;if(!e||!n||!o)throw new Error("organization_id, environment_id, and webhook_id are required");if(!r)throw new Error("webhook data is required");await this.httpClient.patch(`/organizations/${e}/environments/${n}/webhooks/${o}`,r)}async deleteWebhook(t){const{organization_id:e,environment_id:n,webhook_id:o}=t;if(!e||!n||!o)throw new Error("organization_id, environment_id, and webhook_id are required");await this.httpClient.delete(`/organizations/${e}/environments/${n}/webhooks/${o}`)}async startWebhook(t){const{organization_id:e,environment_id:n,webhook_id:o}=t;if(!e||!n||!o)throw new Error("organization_id, environment_id, and webhook_id are required");await this.httpClient.post(`/organizations/${e}/environments/${n}/webhooks/${o}/start`)}async stopWebhook(t){const{organization_id:e,environment_id:n,webhook_id:o}=t;if(!e||!n||!o)throw new Error("organization_id, environment_id, and webhook_id are required");await this.httpClient.post(`/organizations/${e}/environments/${n}/webhooks/${o}/stop`)}async generateWebhookKey(t){const{organization_id:e,environment_id:n,webhook_id:o}=t;if(!e||!n||!o)throw new Error("organization_id, environment_id, and webhook_id are required");return(await this.httpClient.post(`/organizations/${e}/environments/${n}/webhooks/${o}/keys`)).data}getHttpClient(){return this.httpClient}}var Rt={},At={},Mt={};let St;const qt=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];Mt.getSymbolSize=function(t){if(!t)throw new Error('"version" cannot be null or undefined');if(t<1||t>40)throw new Error('"version" should be in range from 1 to 40');return 4*t+17},Mt.getSymbolTotalCodewords=function(t){return qt[t]},Mt.getBCHDigit=function(t){let e=0;for(;0!==t;)e++,t>>>=1;return e},Mt.setToSJISFunction=function(t){if("function"!=typeof t)throw new Error('"toSJISFunc" is not a valid function.');St=t},Mt.isKanjiModeEnabled=function(){return void 0!==St},Mt.toSJIS=function(t){return St(t)};var Ut,Lt={};function Nt(){this.buffer=[],this.length=0}(Ut=Lt).L={bit:1},Ut.M={bit:0},Ut.Q={bit:3},Ut.H={bit:2},Ut.isValid=function(t){return t&&void 0!==t.bit&&t.bit>=0&&t.bit<4},Ut.from=function(t,e){if(Ut.isValid(t))return t;try{return function(t){if("string"!=typeof t)throw new Error("Param is not a string");switch(t.toLowerCase()){case"l":case"low":return Ut.L;case"m":case"medium":return Ut.M;case"q":case"quartile":return Ut.Q;case"h":case"high":return Ut.H;default:throw new Error("Unknown EC Level: "+t)}}(t)}catch(n){return e}},Nt.prototype={get:function(t){const e=Math.floor(t/8);return 1==(this.buffer[e]>>>7-t%8&1)},put:function(t,e){for(let n=0;n<e;n++)this.putBit(1==(t>>>e-n-1&1))},getLengthInBits:function(){return this.length},putBit:function(t){const e=Math.floor(this.length/8);this.buffer.length<=e&&this.buffer.push(0),t&&(this.buffer[e]|=128>>>this.length%8),this.length++}};var Kt=Nt;function jt(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new Uint8Array(t*t),this.reservedBit=new Uint8Array(t*t)}jt.prototype.set=function(t,e,n,o){const r=t*this.size+e;this.data[r]=n,o&&(this.reservedBit[r]=!0)},jt.prototype.get=function(t,e){return this.data[t*this.size+e]},jt.prototype.xor=function(t,e,n){this.data[t*this.size+e]^=n},jt.prototype.isReserved=function(t,e){return this.reservedBit[t*this.size+e]};var Ot=jt,Dt={};!function(t){const e=Mt.getSymbolSize;t.getRowColCoords=function(t){if(1===t)return[];const n=Math.floor(t/7)+2,o=e(t),r=145===o?26:2*Math.ceil((o-13)/(2*n-2)),i=[o-7];for(let e=1;e<n-1;e++)i[e]=i[e-1]-r;return i.push(6),i.reverse()},t.getPositions=function(e){const n=[],o=t.getRowColCoords(e),r=o.length;for(let t=0;t<r;t++)for(let e=0;e<r;e++)0===t&&0===e||0===t&&e===r-1||t===r-1&&0===e||n.push([o[t],o[e]]);return n}}(Dt);var Ft={};const Qt=Mt.getSymbolSize;Ft.getPositions=function(t){const e=Qt(t);return[[0,0],[e-7,0],[0,e-7]]};var Ht={};!function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const e=3,n=3,o=40,r=10;function i(e,n,o){switch(e){case t.Patterns.PATTERN000:return(n+o)%2==0;case t.Patterns.PATTERN001:return n%2==0;case t.Patterns.PATTERN010:return o%3==0;case t.Patterns.PATTERN011:return(n+o)%3==0;case t.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(o/3))%2==0;case t.Patterns.PATTERN101:return n*o%2+n*o%3==0;case t.Patterns.PATTERN110:return(n*o%2+n*o%3)%2==0;case t.Patterns.PATTERN111:return(n*o%3+(n+o)%2)%2==0;default:throw new Error("bad maskPattern:"+e)}}t.isValid=function(t){return null!=t&&""!==t&&!isNaN(t)&&t>=0&&t<=7},t.from=function(e){return t.isValid(e)?parseInt(e,10):void 0},t.getPenaltyN1=function(t){const n=t.size;let o=0,r=0,i=0,a=null,s=null;for(let l=0;l<n;l++){r=i=0,a=s=null;for(let d=0;d<n;d++){let n=t.get(l,d);n===a?r++:(r>=5&&(o+=e+(r-5)),a=n,r=1),n=t.get(d,l),n===s?i++:(i>=5&&(o+=e+(i-5)),s=n,i=1)}r>=5&&(o+=e+(r-5)),i>=5&&(o+=e+(i-5))}return o},t.getPenaltyN2=function(t){const e=t.size;let o=0;for(let n=0;n<e-1;n++)for(let r=0;r<e-1;r++){const e=t.get(n,r)+t.get(n,r+1)+t.get(n+1,r)+t.get(n+1,r+1);4!==e&&0!==e||o++}return o*n},t.getPenaltyN3=function(t){const e=t.size;let n=0,r=0,i=0;for(let o=0;o<e;o++){r=i=0;for(let a=0;a<e;a++)r=r<<1&2047|t.get(o,a),a>=10&&(1488===r||93===r)&&n++,i=i<<1&2047|t.get(a,o),a>=10&&(1488===i||93===i)&&n++}return n*o},t.getPenaltyN4=function(t){let e=0;const n=t.data.length;for(let o=0;o<n;o++)e+=t.data[o];return Math.abs(Math.ceil(100*e/n/5)-10)*r},t.applyMask=function(t,e){const n=e.size;for(let o=0;o<n;o++)for(let r=0;r<n;r++)e.isReserved(r,o)||e.xor(r,o,i(t,r,o))},t.getBestMask=function(e,n){const o=Object.keys(t.Patterns).length;let r=0,i=1/0;for(let a=0;a<o;a++){n(a),t.applyMask(a,e);const o=t.getPenaltyN1(e)+t.getPenaltyN2(e)+t.getPenaltyN3(e)+t.getPenaltyN4(e);t.applyMask(a,e),o<i&&(i=o,r=a)}return r}}(Ht);var Yt={};const Jt=Lt,Vt=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],Wt=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];Yt.getBlocksCount=function(t,e){switch(e){case Jt.L:return Vt[4*(t-1)+0];case Jt.M:return Vt[4*(t-1)+1];case Jt.Q:return Vt[4*(t-1)+2];case Jt.H:return Vt[4*(t-1)+3];default:return}},Yt.getTotalCodewordsCount=function(t,e){switch(e){case Jt.L:return Wt[4*(t-1)+0];case Jt.M:return Wt[4*(t-1)+1];case Jt.Q:return Wt[4*(t-1)+2];case Jt.H:return Wt[4*(t-1)+3];default:return}};var Gt={},Xt={};const Zt=new Uint8Array(512),te=new Uint8Array(256);!function(){let t=1;for(let e=0;e<255;e++)Zt[e]=t,te[t]=e,t<<=1,256&t&&(t^=285);for(let e=255;e<512;e++)Zt[e]=Zt[e-255]}(),Xt.log=function(t){if(t<1)throw new Error("log("+t+")");return te[t]},Xt.exp=function(t){return Zt[t]},Xt.mul=function(t,e){return 0===t||0===e?0:Zt[te[t]+te[e]]},function(t){const e=Xt;t.mul=function(t,n){const o=new Uint8Array(t.length+n.length-1);for(let r=0;r<t.length;r++)for(let i=0;i<n.length;i++)o[r+i]^=e.mul(t[r],n[i]);return o},t.mod=function(t,n){let o=new Uint8Array(t);for(;o.length-n.length>=0;){const t=o[0];for(let i=0;i<n.length;i++)o[i]^=e.mul(n[i],t);let r=0;for(;r<o.length&&0===o[r];)r++;o=o.slice(r)}return o},t.generateECPolynomial=function(n){let o=new Uint8Array([1]);for(let r=0;r<n;r++)o=t.mul(o,new Uint8Array([1,e.exp(r)]));return o}}(Gt);const ee=Gt;function ne(t){this.genPoly=void 0,this.degree=t,this.degree&&this.initialize(this.degree)}ne.prototype.initialize=function(t){this.degree=t,this.genPoly=ee.generateECPolynomial(this.degree)},ne.prototype.encode=function(t){if(!this.genPoly)throw new Error("Encoder not initialized");const e=new Uint8Array(t.length+this.degree);e.set(t);const n=ee.mod(e,this.genPoly),o=this.degree-n.length;if(o>0){const t=new Uint8Array(this.degree);return t.set(n,o),t}return n};var oe=ne,re={},ie={},ae={isValid:function(t){return!isNaN(t)&&t>=1&&t<=40}},se={};const le="[0-9]+";let de="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";de=de.replace(/u/g,"\\u");const ce="(?:(?![A-Z0-9 $%*+\\-./:]|"+de+")(?:.|[\r\n]))+";se.KANJI=new RegExp(de,"g"),se.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),se.BYTE=new RegExp(ce,"g"),se.NUMERIC=new RegExp(le,"g"),se.ALPHANUMERIC=new RegExp("[A-Z $%*+\\-./:]+","g");const ue=new RegExp("^"+de+"$"),pe=new RegExp("^"+le+"$"),me=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");se.testKanji=function(t){return ue.test(t)},se.testNumeric=function(t){return pe.test(t)},se.testAlphanumeric=function(t){return me.test(t)},function(t){const e=ae,n=se;t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(t,n){if(!t.ccBits)throw new Error("Invalid mode: "+t);if(!e.isValid(n))throw new Error("Invalid version: "+n);return n>=1&&n<10?t.ccBits[0]:n<27?t.ccBits[1]:t.ccBits[2]},t.getBestModeForData=function(e){return n.testNumeric(e)?t.NUMERIC:n.testAlphanumeric(e)?t.ALPHANUMERIC:n.testKanji(e)?t.KANJI:t.BYTE},t.toString=function(t){if(t&&t.id)return t.id;throw new Error("Invalid mode")},t.isValid=function(t){return t&&t.bit&&t.ccBits},t.from=function(e,n){if(t.isValid(e))return e;try{return function(e){if("string"!=typeof e)throw new Error("Param is not a string");switch(e.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+e)}}(e)}catch(o){return n}}}(ie),function(t){const e=Mt,n=Yt,o=Lt,r=ie,i=ae,a=e.getBCHDigit(7973);function s(t,e){return r.getCharCountIndicator(t,e)+4}function l(t,e){let n=0;return t.forEach((function(t){const o=s(t.mode,e);n+=o+t.getBitsLength()})),n}t.from=function(t,e){return i.isValid(t)?parseInt(t,10):e},t.getCapacity=function(t,o,a){if(!i.isValid(t))throw new Error("Invalid QR Code version");void 0===a&&(a=r.BYTE);const l=8*(e.getSymbolTotalCodewords(t)-n.getTotalCodewordsCount(t,o));if(a===r.MIXED)return l;const d=l-s(a,t);switch(a){case r.NUMERIC:return Math.floor(d/10*3);case r.ALPHANUMERIC:return Math.floor(d/11*2);case r.KANJI:return Math.floor(d/13);case r.BYTE:default:return Math.floor(d/8)}},t.getBestVersionForData=function(e,n){let i;const a=o.from(n,o.M);if(Array.isArray(e)){if(e.length>1)return function(e,n){for(let o=1;o<=40;o++)if(l(e,o)<=t.getCapacity(o,n,r.MIXED))return o}(e,a);if(0===e.length)return 1;i=e[0]}else i=e;return function(e,n,o){for(let r=1;r<=40;r++)if(n<=t.getCapacity(r,o,e))return r}(i.mode,i.getLength(),a)},t.getEncodedBits=function(t){if(!i.isValid(t)||t<7)throw new Error("Invalid QR Code version");let n=t<<12;for(;e.getBCHDigit(n)-a>=0;)n^=7973<<e.getBCHDigit(n)-a;return t<<12|n}}(re);var ge={};const he=Mt,fe=he.getBCHDigit(1335);ge.getEncodedBits=function(t,e){const n=t.bit<<3|e;let o=n<<10;for(;he.getBCHDigit(o)-fe>=0;)o^=1335<<he.getBCHDigit(o)-fe;return 21522^(n<<10|o)};var ve={};const ye=ie;function we(t){this.mode=ye.NUMERIC,this.data=t.toString()}we.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)},we.prototype.getLength=function(){return this.data.length},we.prototype.getBitsLength=function(){return we.getBitsLength(this.data.length)},we.prototype.write=function(t){let e,n,o;for(e=0;e+3<=this.data.length;e+=3)n=this.data.substr(e,3),o=parseInt(n,10),t.put(o,10);const r=this.data.length-e;r>0&&(n=this.data.substr(e),o=parseInt(n,10),t.put(o,3*r+1))};var be=we;const xe=ie,Ce=["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"," ","$","%","*","+","-",".","/",":"];function $e(t){this.mode=xe.ALPHANUMERIC,this.data=t}$e.getBitsLength=function(t){return 11*Math.floor(t/2)+t%2*6},$e.prototype.getLength=function(){return this.data.length},$e.prototype.getBitsLength=function(){return $e.getBitsLength(this.data.length)},$e.prototype.write=function(t){let e;for(e=0;e+2<=this.data.length;e+=2){let n=45*Ce.indexOf(this.data[e]);n+=Ce.indexOf(this.data[e+1]),t.put(n,11)}this.data.length%2&&t.put(Ce.indexOf(this.data[e]),6)};var Ee=$e;const _e=ie;function Ie(t){this.mode=_e.BYTE,this.data="string"==typeof t?(new TextEncoder).encode(t):new Uint8Array(t)}Ie.getBitsLength=function(t){return 8*t},Ie.prototype.getLength=function(){return this.data.length},Ie.prototype.getBitsLength=function(){return Ie.getBitsLength(this.data.length)},Ie.prototype.write=function(t){for(let e=0,n=this.data.length;e<n;e++)t.put(this.data[e],8)};var ke=Ie;const ze=ie,Pe=Mt;function Te(t){this.mode=ze.KANJI,this.data=t}Te.getBitsLength=function(t){return 13*t},Te.prototype.getLength=function(){return this.data.length},Te.prototype.getBitsLength=function(){return Te.getBitsLength(this.data.length)},Te.prototype.write=function(t){let e;for(e=0;e<this.data.length;e++){let n=Pe.toSJIS(this.data[e]);if(n>=33088&&n<=40956)n-=33088;else{if(!(n>=57408&&n<=60351))throw new Error("Invalid SJIS character: "+this.data[e]+"\nMake sure your charset is UTF-8");n-=49472}n=192*(n>>>8&255)+(255&n),t.put(n,13)}};var Be,Re=Te,Ae={exports:{}};Ae.exports=Be={single_source_shortest_paths:function(t,e,n){var o={},r={};r[e]=0;var i,a,s,l,d,c,u,p=Be.PriorityQueue.make();for(p.push(e,0);!p.empty();)for(s in a=(i=p.pop()).value,l=i.cost,d=t[a]||{})d.hasOwnProperty(s)&&(c=l+d[s],u=r[s],(void 0===r[s]||u>c)&&(r[s]=c,p.push(s,c),o[s]=a));if(void 0!==n&&void 0===r[n]){var m=["Could not find a path from ",e," to ",n,"."].join("");throw new Error(m)}return o},extract_shortest_path_from_predecessor_list:function(t,e){for(var n=[],o=e;o;)n.push(o),t[o],o=t[o];return n.reverse(),n},find_path:function(t,e,n){var o=Be.single_source_shortest_paths(t,e,n);return Be.extract_shortest_path_from_predecessor_list(o,n)},PriorityQueue:{make:function(t){var e,n=Be.PriorityQueue,o={};for(e in t=t||{},n)n.hasOwnProperty(e)&&(o[e]=n[e]);return o.queue=[],o.sorter=t.sorter||n.default_sorter,o},default_sorter:function(t,e){return t.cost-e.cost},push:function(t,e){var n={value:t,cost:e};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return 0===this.queue.length}}};var Me=Ae.exports;!function(t){const e=ie,n=be,o=Ee,r=ke,i=Re,a=se,s=Mt,l=Me;function d(t){return unescape(encodeURIComponent(t)).length}function c(t,e,n){const o=[];let r;for(;null!==(r=t.exec(n));)o.push({data:r[0],index:r.index,mode:e,length:r[0].length});return o}function u(t){const n=c(a.NUMERIC,e.NUMERIC,t),o=c(a.ALPHANUMERIC,e.ALPHANUMERIC,t);let r,i;s.isKanjiModeEnabled()?(r=c(a.BYTE,e.BYTE,t),i=c(a.KANJI,e.KANJI,t)):(r=c(a.BYTE_KANJI,e.BYTE,t),i=[]);return n.concat(o,r,i).sort((function(t,e){return t.index-e.index})).map((function(t){return{data:t.data,mode:t.mode,length:t.length}}))}function p(t,a){switch(a){case e.NUMERIC:return n.getBitsLength(t);case e.ALPHANUMERIC:return o.getBitsLength(t);case e.KANJI:return i.getBitsLength(t);case e.BYTE:return r.getBitsLength(t)}}function m(t,a){let l;const d=e.getBestModeForData(t);if(l=e.from(a,d),l!==e.BYTE&&l.bit<d.bit)throw new Error('"'+t+'" cannot be encoded with mode '+e.toString(l)+".\n Suggested mode is: "+e.toString(d));switch(l!==e.KANJI||s.isKanjiModeEnabled()||(l=e.BYTE),l){case e.NUMERIC:return new n(t);case e.ALPHANUMERIC:return new o(t);case e.KANJI:return new i(t);case e.BYTE:return new r(t)}}t.fromArray=function(t){return t.reduce((function(t,e){return"string"==typeof e?t.push(m(e,null)):e.data&&t.push(m(e.data,e.mode)),t}),[])},t.fromString=function(n,o){const r=function(t){const n=[];for(let o=0;o<t.length;o++){const r=t[o];switch(r.mode){case e.NUMERIC:n.push([r,{data:r.data,mode:e.ALPHANUMERIC,length:r.length},{data:r.data,mode:e.BYTE,length:r.length}]);break;case e.ALPHANUMERIC:n.push([r,{data:r.data,mode:e.BYTE,length:r.length}]);break;case e.KANJI:n.push([r,{data:r.data,mode:e.BYTE,length:d(r.data)}]);break;case e.BYTE:n.push([{data:r.data,mode:e.BYTE,length:d(r.data)}])}}return n}(u(n,s.isKanjiModeEnabled())),i=function(t,n){const o={},r={start:{}};let i=["start"];for(let a=0;a<t.length;a++){const s=t[a],l=[];for(let t=0;t<s.length;t++){const d=s[t],c=""+a+t;l.push(c),o[c]={node:d,lastCount:0},r[c]={};for(let t=0;t<i.length;t++){const a=i[t];o[a]&&o[a].node.mode===d.mode?(r[a][c]=p(o[a].lastCount+d.length,d.mode)-p(o[a].lastCount,d.mode),o[a].lastCount+=d.length):(o[a]&&(o[a].lastCount=d.length),r[a][c]=p(d.length,d.mode)+4+e.getCharCountIndicator(d.mode,n))}}i=l}for(let e=0;e<i.length;e++)r[i[e]].end=0;return{map:r,table:o}}(r,o),a=l.find_path(i.map,"start","end"),c=[];for(let t=1;t<a.length-1;t++)c.push(i.table[a[t]].node);return t.fromArray(function(t){return t.reduce((function(t,e){const n=t.length-1>=0?t[t.length-1]:null;return n&&n.mode===e.mode?(t[t.length-1].data+=e.data,t):(t.push(e),t)}),[])}(c))},t.rawSplit=function(e){return t.fromArray(u(e,s.isKanjiModeEnabled()))}}(ve);const Se=Mt,qe=Lt,Ue=Kt,Le=Ot,Ne=Dt,Ke=Ft,je=Ht,Oe=Yt,De=oe,Fe=re,Qe=ge,He=ie,Ye=ve;function Je(t,e,n){const o=t.size,r=Qe.getEncodedBits(e,n);let i,a;for(i=0;i<15;i++)a=1==(r>>i&1),i<6?t.set(i,8,a,!0):i<8?t.set(i+1,8,a,!0):t.set(o-15+i,8,a,!0),i<8?t.set(8,o-i-1,a,!0):i<9?t.set(8,15-i-1+1,a,!0):t.set(8,15-i-1,a,!0);t.set(o-8,8,1,!0)}function Ve(t,e,n){const o=new Ue;n.forEach((function(e){o.put(e.mode.bit,4),o.put(e.getLength(),He.getCharCountIndicator(e.mode,t)),e.write(o)}));const r=8*(Se.getSymbolTotalCodewords(t)-Oe.getTotalCodewordsCount(t,e));for(o.getLengthInBits()+4<=r&&o.put(0,4);o.getLengthInBits()%8!=0;)o.putBit(0);const i=(r-o.getLengthInBits())/8;for(let a=0;a<i;a++)o.put(a%2?17:236,8);return function(t,e,n){const o=Se.getSymbolTotalCodewords(e),r=Oe.getTotalCodewordsCount(e,n),i=o-r,a=Oe.getBlocksCount(e,n),s=o%a,l=a-s,d=Math.floor(o/a),c=Math.floor(i/a),u=c+1,p=d-c,m=new De(p);let g=0;const h=new Array(a),f=new Array(a);let v=0;const y=new Uint8Array(t.buffer);for(let $=0;$<a;$++){const t=$<l?c:u;h[$]=y.slice(g,g+t),f[$]=m.encode(h[$]),g+=t,v=Math.max(v,t)}const w=new Uint8Array(o);let b,x,C=0;for(b=0;b<v;b++)for(x=0;x<a;x++)b<h[x].length&&(w[C++]=h[x][b]);for(b=0;b<p;b++)for(x=0;x<a;x++)w[C++]=f[x][b];return w}(o,t,e)}function We(t,e,n,o){let r;if(Array.isArray(t))r=Ye.fromArray(t);else{if("string"!=typeof t)throw new Error("Invalid data");{let o=e;if(!o){const e=Ye.rawSplit(t);o=Fe.getBestVersionForData(e,n)}r=Ye.fromString(t,o||40)}}const i=Fe.getBestVersionForData(r,n);if(!i)throw new Error("The amount of data is too big to be stored in a QR Code");if(e){if(e<i)throw new Error("\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: "+i+".\n")}else e=i;const a=Ve(e,n,r),s=Se.getSymbolSize(e),l=new Le(s);return function(t,e){const n=t.size,o=Ke.getPositions(e);for(let r=0;r<o.length;r++){const e=o[r][0],i=o[r][1];for(let o=-1;o<=7;o++)if(!(e+o<=-1||n<=e+o))for(let r=-1;r<=7;r++)i+r<=-1||n<=i+r||(o>=0&&o<=6&&(0===r||6===r)||r>=0&&r<=6&&(0===o||6===o)||o>=2&&o<=4&&r>=2&&r<=4?t.set(e+o,i+r,!0,!0):t.set(e+o,i+r,!1,!0))}}(l,e),function(t){const e=t.size;for(let n=8;n<e-8;n++){const e=n%2==0;t.set(n,6,e,!0),t.set(6,n,e,!0)}}(l),function(t,e){const n=Ne.getPositions(e);for(let o=0;o<n.length;o++){const e=n[o][0],r=n[o][1];for(let n=-2;n<=2;n++)for(let o=-2;o<=2;o++)-2===n||2===n||-2===o||2===o||0===n&&0===o?t.set(e+n,r+o,!0,!0):t.set(e+n,r+o,!1,!0)}}(l,e),Je(l,n,0),e>=7&&function(t,e){const n=t.size,o=Fe.getEncodedBits(e);let r,i,a;for(let s=0;s<18;s++)r=Math.floor(s/3),i=s%3+n-8-3,a=1==(o>>s&1),t.set(r,i,a,!0),t.set(i,r,a,!0)}(l,e),function(t,e){const n=t.size;let o=-1,r=n-1,i=7,a=0;for(let s=n-1;s>0;s-=2)for(6===s&&s--;;){for(let n=0;n<2;n++)if(!t.isReserved(r,s-n)){let o=!1;a<e.length&&(o=1==(e[a]>>>i&1)),t.set(r,s-n,o),i--,-1===i&&(a++,i=7)}if(r+=o,r<0||n<=r){r-=o,o=-o;break}}}(l,a),isNaN(o)&&(o=je.getBestMask(l,Je.bind(null,l,n))),je.applyMask(o,l),Je(l,n,o),{modules:l,version:e,errorCorrectionLevel:n,maskPattern:o,segments:r}}At.create=function(t,e){if(void 0===t||""===t)throw new Error("No input text");let n,o,r=qe.M;return void 0!==e&&(r=qe.from(e.errorCorrectionLevel,qe.M),n=Fe.from(e.version),o=je.from(e.maskPattern),e.toSJISFunc&&Se.setToSJISFunction(e.toSJISFunc)),We(t,n,r,o)};var Ge={},Xe={};!function(t){function e(t){if("number"==typeof t&&(t=t.toString()),"string"!=typeof t)throw new Error("Color should be defined as hex string");let e=t.slice().replace("#","").split("");if(e.length<3||5===e.length||e.length>8)throw new Error("Invalid hex color: "+t);3!==e.length&&4!==e.length||(e=Array.prototype.concat.apply([],e.map((function(t){return[t,t]})))),6===e.length&&e.push("F","F");const n=parseInt(e.join(""),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:255&n,hex:"#"+e.slice(0,6).join("")}}t.getOptions=function(t){t||(t={}),t.color||(t.color={});const n=void 0===t.margin||null===t.margin||t.margin<0?4:t.margin,o=t.width&&t.width>=21?t.width:void 0,r=t.scale||4;return{width:o,scale:o?4:r,margin:n,color:{dark:e(t.color.dark||"#000000ff"),light:e(t.color.light||"#ffffffff")},type:t.type,rendererOpts:t.rendererOpts||{}}},t.getScale=function(t,e){return e.width&&e.width>=t+2*e.margin?e.width/(t+2*e.margin):e.scale},t.getImageWidth=function(e,n){const o=t.getScale(e,n);return Math.floor((e+2*n.margin)*o)},t.qrToImageData=function(e,n,o){const r=n.modules.size,i=n.modules.data,a=t.getScale(r,o),s=Math.floor((r+2*o.margin)*a),l=o.margin*a,d=[o.color.light,o.color.dark];for(let t=0