var Zr=Object.create;var De=Object.defineProperty;var qr=Object.getOwnPropertyDescriptor;var kr=Object.getOwnPropertyNames;var et=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty;var tt=p=>De(p,"__esModule",{value:!0});var ve=(p=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(p,{get:(g,O)=>(typeof require!="undefined"?require:g)[O]}):p)(function(p){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+p+'" is not supported')});var $e=(p,g)=>()=>(g||p((g={exports:{}}).exports,g),g.exports);var nt=(p,g,O,L)=>{if(g&&typeof g=="object"||typeof g=="function")for(let M of kr(g))!rt.call(p,M)&&(O||M!=="default")&&De(p,M,{get:()=>g[M],enumerable:!(L=qr(g,M))||L.enumerable});return p},Ze=(p,g)=>nt(tt(De(p!=null?Zr(et(p)):{},"default",!g&&p&&p.__esModule?{get:()=>p.default,enumerable:!0}:{value:p,enumerable:!0})),p);var se=(p,g,O)=>new Promise((L,M)=>{var Q=S=>{try{Y(O.next(S))}catch(P){M(P)}},C=S=>{try{Y(O.throw(S))}catch(P){M(P)}},Y=S=>S.done?L(S.value):Promise.resolve(S.value).then(Q,C);Y((O=O.apply(p,g)).next())});var ke=$e((qe,Ne)=>{(function(p){if(typeof qe=="object"&&typeof Ne!="undefined")Ne.exports=p();else if(typeof define=="function"&&define.amd)define([],p);else{var g;typeof window!="undefined"?g=window:typeof global!="undefined"?g=global:typeof self!="undefined"?g=self:g=this,g.localforage=p()}})(function(){var p,g,O;return function L(M,Q,C){function Y(K,Z){if(!Q[K]){if(!M[K]){var m=typeof ve=="function"&&ve;if(!Z&&m)return m(K,!0);if(S)return S(K,!0);var w=new Error("Cannot find module '"+K+"'");throw w.code="MODULE_NOT_FOUND",w}var N=Q[K]={exports:{}};M[K][0].call(N.exports,function(z){var q=M[K][1][z];return Y(q||z)},N,N.exports,L,M,Q,C)}return Q[K].exports}for(var S=typeof ve=="function"&&ve,P=0;P=43)}}).catch(function(){return!1})}function B(e){return typeof k=="boolean"?m.resolve(k):I(e).then(function(t){return k=t,k})}function H(e){var t=U[e.name],r={};r.promise=new m(function(o,i){r.resolve=o,r.reject=i}),t.deferredOperations.push(r),t.dbReady?t.dbReady=t.dbReady.then(function(){return r.promise}):t.dbReady=r.promise}function j(e){var t=U[e.name],r=t.deferredOperations.pop();if(r)return r.resolve(),r.promise}function J(e,t){var r=U[e.name],o=r.deferredOperations.pop();if(o)return o.reject(t),o.promise}function $(e,t){return new m(function(r,o){if(U[e.name]=U[e.name]||G(),e.db)if(t)H(e),e.db.close();else return r(e.db);var i=[e.name];t&&i.push(e.version);var n=P.open.apply(P,i);t&&(n.onupgradeneeded=function(f){var u=n.result;try{u.createObjectStore(e.storeName),f.oldVersion<=1&&u.createObjectStore(F)}catch(c){if(c.name==="ConstraintError")console.warn('The database "'+e.name+'" has been upgraded from version '+f.oldVersion+" to version "+f.newVersion+', but the storage "'+e.storeName+'" already exists.');else throw c}}),n.onerror=function(f){f.preventDefault(),o(n.error)},n.onsuccess=function(){r(n.result),j(e)}})}function ee(e){return $(e,!1)}function oe(e){return $(e,!0)}function a(e,t){if(!e.db)return!0;var r=!e.db.objectStoreNames.contains(e.storeName),o=e.versione.db.version;if(o&&(e.version!==t&&console.warn('The database "'+e.name+`" can't be downgraded from version `+e.db.version+" to version "+e.version+"."),e.version=e.db.version),i||r){if(r){var n=e.db.version+1;n>e.version&&(e.version=n)}return!0}return!1}function s(e){return new m(function(t,r){var o=new FileReader;o.onerror=r,o.onloadend=function(i){var n=btoa(i.target.result||"");t({__local_forage_encoded_blob:!0,data:n,type:e.type})},o.readAsBinaryString(e)})}function v(e){var t=R(atob(e.data));return Z([t],{type:e.type})}function b(e){return e&&e.__local_forage_encoded_blob}function _(e){var t=this,r=t._initReady().then(function(){var o=U[t._dbInfo.name];if(o&&o.dbReady)return o.dbReady});return N(r,e,e),r}function E(e){H(e);for(var t=U[e.name],r=t.forages,o=0;o0&&(!e.db||n.name==="InvalidStateError"||n.name==="NotFoundError"))return m.resolve().then(function(){if(!e.db||n.name==="NotFoundError"&&!e.db.objectStoreNames.contains(e.storeName)&&e.version<=e.db.version)return e.db&&(e.version=e.db.version+1),oe(e)}).then(function(){return E(e).then(function(){D(e,t,r,o-1)})}).catch(r);r(n)}}function G(){return{forages:[],db:null,dbReady:null,deferredOperations:[]}}function fe(e){var t=this,r={db:null};if(e)for(var o in e)r[o]=e[o];var i=U[r.name];i||(i=G(),U[r.name]=i),i.forages.push(t),t._initReady||(t._initReady=t.ready,t.ready=_);var n=[];function f(){return m.resolve()}for(var u=0;u>4,d[i++]=(f&15)<<4|u>>2,d[i++]=(u&3)<<6|c&63;return l}function we(e){var t=new Uint8Array(e),r="",o;for(o=0;o>2],r+=te[(t[o]&3)<<4|t[o+1]>>4],r+=te[(t[o+1]&15)<<2|t[o+2]>>6],r+=te[t[o+2]&63];return t.length%3===2?r=r.substring(0,r.length-1)+"=":t.length%3===1&&(r=r.substring(0,r.length-2)+"=="),r}function vr(e,t){var r="";if(e&&(r=Ke.call(e)),e&&(r==="[object ArrayBuffer]"||e.buffer&&Ke.call(e.buffer)==="[object ArrayBuffer]")){var o,i=he;e instanceof ArrayBuffer?(o=e,i+=be):(o=e.buffer,r==="[object Int8Array]"?i+=Oe:r==="[object Uint8Array]"?i+=Ce:r==="[object Uint8ClampedArray]"?i+=Le:r==="[object Int16Array]"?i+=Pe:r==="[object Uint16Array]"?i+=Fe:r==="[object Int32Array]"?i+=Me:r==="[object Uint32Array]"?i+=Ue:r==="[object Float32Array]"?i+=Ye:r==="[object Float64Array]"?i+=ze:t(new Error("Failed to get type for BinaryArray"))),t(i+we(o))}else if(r==="[object Blob]"){var n=new FileReader;n.onload=function(){var f=dr+e.type+"~"+we(this.result);t(he+_e+f)},n.readAsArrayBuffer(e)}else try{t(JSON.stringify(e))}catch(f){console.error("Couldn't convert value into a JSON string: ",e),t(null,f)}}function hr(e){if(e.substring(0,ge)!==he)return JSON.parse(e);var t=e.substring(We),r=e.substring(ge,We),o;if(r===_e&&xe.test(t)){var i=t.match(xe);o=i[1],t=t.substring(i[0].length)}var n=He(t);switch(r){case be:return n;case _e:return Z([n],{type:o});case Oe:return new Int8Array(n);case Ce:return new Uint8Array(n);case Le:return new Uint8ClampedArray(n);case Pe:return new Int16Array(n);case Fe:return new Uint16Array(n);case Me:return new Int32Array(n);case Ue:return new Uint32Array(n);case Ye:return new Float32Array(n);case ze:return new Float64Array(n);default:throw new Error("Unkown type: "+r)}}var Ee={serialize:vr,deserialize:hr,stringToBuffer:He,bufferToString:we};function Ve(e,t,r,o){e.executeSql("CREATE TABLE IF NOT EXISTS "+t.storeName+" (id INTEGER PRIMARY KEY, key unique, value)",[],r,o)}function mr(e){var t=this,r={db:null};if(e)for(var o in e)r[o]=typeof e[o]!="string"?e[o].toString():e[o];var i=new m(function(n,f){try{r.db=openDatabase(r.name,String(r.version),r.description,r.size)}catch(u){return f(u)}r.db.transaction(function(u){Ve(u,r,function(){t._dbInfo=r,n()},function(c,l){f(l)})},f)});return r.serializer=Ee,i}function ne(e,t,r,o,i,n){e.executeSql(r,o,i,function(f,u){u.code===u.SYNTAX_ERR?f.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name = ?",[t.storeName],function(c,l){l.rows.length?n(c,u):Ve(c,t,function(){c.executeSql(r,o,i,n)},n)},n):n(f,u)},n)}function yr(e,t){var r=this;e=z(e);var o=new m(function(i,n){r.ready().then(function(){var f=r._dbInfo;f.db.transaction(function(u){ne(u,f,"SELECT * FROM "+f.storeName+" WHERE key = ? LIMIT 1",[e],function(c,l){var d=l.rows.length?l.rows.item(0).value:null;d&&(d=f.serializer.deserialize(d)),i(d)},function(c,l){n(l)})})}).catch(n)});return w(o,t),o}function pr(e,t){var r=this,o=new m(function(i,n){r.ready().then(function(){var f=r._dbInfo;f.db.transaction(function(u){ne(u,f,"SELECT * FROM "+f.storeName,[],function(c,l){for(var d=l.rows,y=d.length,A=0;A0){f(Ge.apply(i,[e,c,r,o-1]));return}u(A)}})})}).catch(u)});return w(n,r),n}function gr(e,t,r){return Ge.apply(this,[e,t,r,1])}function br(e,t){var r=this;e=z(e);var o=new m(function(i,n){r.ready().then(function(){var f=r._dbInfo;f.db.transaction(function(u){ne(u,f,"DELETE FROM "+f.storeName+" WHERE key = ?",[e],function(){i()},function(c,l){n(l)})})}).catch(n)});return w(o,t),o}function _r(e){var t=this,r=new m(function(o,i){t.ready().then(function(){var n=t._dbInfo;n.db.transaction(function(f){ne(f,n,"DELETE FROM "+n.storeName,[],function(){o()},function(u,c){i(c)})})}).catch(i)});return w(r,e),r}function wr(e){var t=this,r=new m(function(o,i){t.ready().then(function(){var n=t._dbInfo;n.db.transaction(function(f){ne(f,n,"SELECT COUNT(key) as c FROM "+n.storeName,[],function(u,c){var l=c.rows.item(0).c;o(l)},function(u,c){i(c)})})}).catch(i)});return w(r,e),r}function Er(e,t){var r=this,o=new m(function(i,n){r.ready().then(function(){var f=r._dbInfo;f.db.transaction(function(u){ne(u,f,"SELECT key FROM "+f.storeName+" WHERE id = ? LIMIT 1",[e+1],function(c,l){var d=l.rows.length?l.rows.item(0).key:null;i(d)},function(c,l){n(l)})})}).catch(n)});return w(o,t),o}function Ir(e){var t=this,r=new m(function(o,i){t.ready().then(function(){var n=t._dbInfo;n.db.transaction(function(f){ne(f,n,"SELECT key FROM "+n.storeName,[],function(u,c){for(var l=[],d=0;d '__WebKitDatabaseInfoTable__'",[],function(i,n){for(var f=[],u=0;u0}function Br(e){var t=this,r={};if(e)for(var o in e)r[o]=e[o];return r.keyPrefix=je(e,t._defaultConfig),Tr()?(t._dbInfo=r,r.serializer=Ee,m.resolve()):m.reject()}function xr(e){var t=this,r=t.ready().then(function(){for(var o=t._dbInfo.keyPrefix,i=localStorage.length-1;i>=0;i--){var n=localStorage.key(i);n.indexOf(o)===0&&localStorage.removeItem(n)}});return w(r,e),r}function Or(e,t){var r=this;e=z(e);var o=r.ready().then(function(){var i=r._dbInfo,n=localStorage.getItem(i.keyPrefix+e);return n&&(n=i.serializer.deserialize(n)),n});return w(o,t),o}function Cr(e,t){var r=this,o=r.ready().then(function(){for(var i=r._dbInfo,n=i.keyPrefix,f=n.length,u=localStorage.length,c=1,l=0;l=0;f--){var u=localStorage.key(f);u.indexOf(n)===0&&localStorage.removeItem(u)}}):i=m.reject("Invalid arguments"),w(i,t),i}var zr={_driver:"localStorageWrapper",_initStorage:Br,_support:Dr(),iterate:Cr,getItem:Or,setItem:Ur,removeItem:Fr,clear:xr,length:Mr,key:Lr,keys:Pr,dropInstance:Yr},Wr=function(t,r){return t===r||typeof t=="number"&&typeof r=="number"&&isNaN(t)&&isNaN(r)},Kr=function(t,r){for(var o=t.length,i=0;i{(function(p,g){typeof ye=="object"&&typeof er!="undefined"?g(ye):typeof define=="function"&&define.amd?define("localforage-driver-memory",["exports"],g):g(p.LocalforageDriverMemory={})})(typeof self!="undefined"?self:ye,function(p){"use strict";var g="localforage-driver-memory";function O(a){var s=typeof Symbol=="function"&&a[Symbol.iterator],v=0;return s?s.call(a):{next:function(){return a&&v>=a.length&&(a=void 0),{value:a&&a[v++],done:!a}}}}function L(a,s){a=a||[],s=s||{};try{return new Blob(a,s)}catch(E){if(E.name!=="TypeError")throw E;for(var v=typeof BlobBuilder!="undefined"?BlobBuilder:typeof MSBlobBuilder!="undefined"?MSBlobBuilder:typeof MozBlobBuilder!="undefined"?MozBlobBuilder:WebKitBlobBuilder,b=new v,_=0;_>4,_[D++]=(fe&15)<<4|ie>>2,_[D++]=(ie&3)<<6|ce&63}return b}function P(a){for(var s=new Uint8Array(a),v="",b=0;b>2],v+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(s[b]&3)<<4|s[b+1]>>4],v+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(s[b+1]&15)<<2|s[b+2]>>6],v+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[s[b+2]&63];return s.length%3===2?v=v.substring(0,v.length-1)+"=":s.length%3===1&&(v=v.substring(0,v.length-2)+"=="),v}function K(a,s){var v="";if(a&&(v=Y.call(a)),a&&(v==="[object ArrayBuffer]"||a.buffer&&Y.call(a.buffer)==="[object ArrayBuffer]")){var b=void 0,_="__lfsc__:";a instanceof ArrayBuffer?(b=a,_+="arbf"):(b=a.buffer,v==="[object Int8Array]"?_+="si08":v==="[object Uint8Array]"?_+="ui08":v==="[object Uint8ClampedArray]"?_+="uic8":v==="[object Int16Array]"?_+="si16":v==="[object Uint16Array]"?_+="ur16":v==="[object Int32Array]"?_+="si32":v==="[object Uint32Array]"?_+="ui32":v==="[object Float32Array]"?_+="fl32":v==="[object Float64Array]"?_+="fl64":s(new Error("Failed to get type for BinaryArray"))),s(_+P(b))}else if(v==="[object Blob]"){var E=new FileReader;E.onload=function(){var D="~~local_forage_type~"+a.type+"~"+P(this.result);s("__lfsc__:blob"+D)},E.readAsArrayBuffer(a)}else try{s(JSON.stringify(a))}catch(D){console.error("Couldn't convert value into a JSON string: ",a),s(null,D)}}function Z(a){if(a.substring(0,Q)!=="__lfsc__:")return JSON.parse(a);var s=a.substring(C),v=a.substring(Q,C),b;if(v==="blob"&&M.test(s)){var _=s.match(M);b=_[1],s=s.substring(_[0].length)}var E=S(s);switch(v){case"arbf":return E;case"blob":return L([E],{type:b});case"si08":return new Int8Array(E);case"ui08":return new Uint8Array(E);case"uic8":return new Uint8ClampedArray(E);case"si16":return new Int16Array(E);case"ur16":return new Uint16Array(E);case"si32":return new Int32Array(E);case"ui32":return new Uint32Array(E);case"fl32":return new Float32Array(E);case"fl64":return new Float64Array(E);default:throw new Error("Unkown type: "+v)}}function m(a){var s,v;if(a===null||typeof a!="object"||"isActiveClone"in a)return a;var b=a instanceof Date?new Date(a):a.constructor();try{for(var _=O(Object.keys(a)),E=_.next();!E.done;E=_.next()){var D=E.value;Object.prototype.hasOwnProperty.call(a,D)&&(a.isActiveClone=null,b[D]=m(a[D]),delete a.isActiveClone)}}catch(G){s={error:G}}finally{try{E&&!E.done&&(v=_.return)&&v.call(_)}finally{if(s)throw s.error}}return b}function w(a,s){return(a.name||s.name)+"/"+(a.storeName||s.storeName)+"/"}function N(a,s){s&&a.then(function(v){s(null,v)},function(v){s(v)})}function z(){for(var a=[],s=0;sO.src.includes(p)))}var Te=class extends ot{constructor(){super(...arguments);this.activeElement=null}init(){this.test="hello",this.iframe=new Promise(g=>{let O=()=>{if(st(encodeURIComponent(this.parameters)))it().log();else{let L=document.createElement("iframe");L.classList.add("magic-iframe"),L.dataset.magicIframeLabel=tr(this.endpoint).host,L.title="Secure Modal",L.src=tr(`/send?params=${encodeURIComponent(this.parameters)}`,this.endpoint).href,ut(L),document.body.appendChild(L),g(L)}};["loaded","interactive","complete"].includes(document.readyState)?O():window.addEventListener("load",O,!1)}),window.addEventListener("message",g=>{var O;if(g.origin===this.endpoint&&g.data&&g.data.msgType&&this.messageHandlers.size){g.data.response=(O=g.data.response)!=null?O:{};for(let L of this.messageHandlers.values())L(g)}})}showOverlay(){return se(this,null,function*(){let g=yield this.iframe;g.style.display="block",this.activeElement=document.activeElement,g.focus()})}hideOverlay(){return se(this,null,function*(){var O;let g=yield this.iframe;g.style.display="none",((O=this.activeElement)==null?void 0:O.focus)&&this.activeElement.focus(),this.activeElement=null})}_post(g){return se(this,null,function*(){let O=yield this.iframe;if(O&&O.contentWindow)O.contentWindow.postMessage(g,this.endpoint);else throw at()})}};export*from"@magic-sdk/commons";var _t=lt(ct,{platform:"web",sdkName:"magic-sdk",version:"8.0.1",defaultEndpoint:"https://auth.magic.link/",ViewController:Te,configureStorage:()=>se(void 0,null,function*(){let p=pe.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"});return yield p.defineDriver(Be),yield p.setDriver([pe.default.INDEXEDDB,pe.default.LOCALSTORAGE,Be._driver]),p})});export{_t as Magic}; //# sourceMappingURL=index.js.map