@onefootprint/footprint-js
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -33,3 +33,2 @@ import * as CSS from 'csstype'; | ||
borderRadius: CSS.Property.BorderRadius; | ||
colorInfo: CSS.Property.Color; | ||
colorError: CSS.Property.Color; | ||
@@ -143,2 +142,3 @@ colorWarning: CSS.Property.Color; | ||
show: ({ publicKey, onCompleted, onCanceled, }: ShowFootprint) => Promise<void>; | ||
hide: () => Promise<void>; | ||
}; | ||
@@ -153,4 +153,6 @@ declare enum FootprintEvents { | ||
show: ({ appearance, publicKey, onCompleted, onCanceled, }: ShowFootprint) => Promise<void>; | ||
hide: () => Promise<void>; | ||
createButton: (container?: HTMLElement | undefined) => HTMLButtonElement; | ||
}; | ||
export { Footprint, FootprintAppearance, FootprintAppearanceParams, FootprintAppearanceRules, FootprintAppearanceTheme, FootprintAppearanceVariables, FootprintEvents, FootprintExternalStyles, FootprintMainStyles, FootprintShowParams, ShowFootprint, footprint as default }; |
@@ -1,12 +0,12 @@ | ||
var b=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var E=(o,e)=>{var t={};for(var n in o)j.call(o,n)&&e.indexOf(n)<0&&(t[n]=o[n]);if(o!=null&&b)for(var n of b(o))e.indexOf(n)<0&&W.call(o,n)&&(t[n]=o[n]);return t};var C=(o,e,t)=>new Promise((n,r)=>{var i=d=>{try{p(t.next(d));}catch(s){r(s);}},a=d=>{try{p(t.throw(d));}catch(s){r(s);}},p=d=>d.done?n(d.value):Promise.resolve(d.value).then(i,a);p((t=t.apply(o,e)).next());});var w=(n=>(n.closed="closed",n.completed="completed",n.canceled="canceled",n))(w||{});var S="application/x-postmate-v1+json",U=5,K=0,q=function(){return ++K};var z=function(e){var t=document.createElement("a");t.href=e;var n=t.protocol.length>4?t.protocol:window.location.protocol,r=t.host.length?t.port==="80"||t.port==="443"?t.hostname:t.host:window.location.host;return t.origin||n+"//"+r},J={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},f=function(e,t){return !(typeof t=="string"&&e.origin!==t||!e.data||typeof e.data=="object"&&!("postmate"in e.data)||e.data.type!==S||!J[e.data.postmate])},Y=function(e,t){var n=typeof e[t]=="function"?e[t]():e[t];return y.Promise.resolve(n)},Z=function(){function o(t){var n=this;this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},this.listener=function(r){if(!f(r,n.childOrigin))return !1;var i=((r||{}).data||{}).value||{},a=i.data,p=i.name;r.data.postmate==="emit"&&p in n.events&&n.events[p].call(n,a);},this.parent.addEventListener("message",this.listener,!1);}var e=o.prototype;return e.get=function(n){var r=this;return new y.Promise(function(i){var a=q(),p=function d(s){s.data.uid===a&&s.data.postmate==="reply"&&(r.parent.removeEventListener("message",d,!1),i(s.data.value));};r.parent.addEventListener("message",p,!1),r.child.postMessage({postmate:"request",type:S,property:n,uid:a},r.childOrigin);})},e.call=function(n,r){this.child.postMessage({postmate:"call",type:S,property:n,data:r},this.childOrigin);},e.on=function(n,r){this.events[n]=r;},e.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},o}(),G=function(){function o(t){var n=this;this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,this.child.addEventListener("message",function(r){if(!!f(r,n.parentOrigin)){var i=r.data,a=i.property,p=i.uid,d=i.data;if(r.data.postmate==="call"){a in n.model&&typeof n.model[a]=="function"&&n.model[a](d);return}Y(n.model,a).then(function(s){return r.source.postMessage({property:a,postmate:"reply",type:S,uid:p,value:s},r.origin)});}});}var e=o.prototype;return e.emit=function(n,r){this.parent.postMessage({postmate:"emit",type:S,value:{name:n,data:r}},this.parentOrigin);},o}(),y=function(){function o(t){var n=t.container,r=n===void 0?typeof r!="undefined"?r:document.body:n,i=t.model,a=t.url,p=t.name,d=t.classListArray,s=d===void 0?[]:d;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=p||"",this.frame.classList.add.apply(this.frame.classList,s),r.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=i||{},this.sendHandshake(a)}var e=o.prototype;return e.sendHandshake=function(n){var r=this,i=z(n),a=0,p;return new o.Promise(function(d,s){var l=function g(m){return f(m,i)?m.data.postmate==="handshake-reply"?(clearInterval(p),r.parent.removeEventListener("message",g,!1),r.childOrigin=m.origin,d(new Z(r))):s("Failed handshake"):!1};r.parent.addEventListener("message",l,!1);var c=function(){a++,r.child.postMessage({postmate:"handshake",type:S,model:r.model},i),a===U&&clearInterval(p);},u=function(){c(),p=setInterval(c,500);};r.frame.attachEvent?r.frame.attachEvent("onload",u):r.frame.onload=u,r.frame.src=n;})},o}();y.debug=!1;y.Promise=function(){try{return window?window.Promise:Promise}catch(o){return null}}();y.Model=function(){function o(t){return this.child=window,this.model=t,this.parent=this.child.parent,this.sendHandshakeReply()}var e=o.prototype;return e.sendHandshakeReply=function(){var n=this;return new y.Promise(function(r,i){var a=function p(d){if(!!d.data.postmate){if(d.data.postmate==="handshake"){n.child.removeEventListener("message",p,!1),d.source.postMessage({postmate:"handshake-reply",type:S},d.origin),n.parentOrigin=d.origin;var s=d.data.model;return s&&Object.keys(s).forEach(function(l){n.model[l]=s[l];}),r(new G(n))}return i("Handshake Reply Failed")}};n.child.addEventListener("message",a,!1);})},o}();var A=y;var k="footprint-container",F="footprint-overlay",O="footprint-loading-indicator",Q="footprint-custom-styles",X=o=>{if(typeof window=="undefined")return;let e=document.getElementById(Q);e&&e.remove();let t=document.createElement("style");t.setAttribute("id","footprint-custom-styles"),t.textContent=o,document.head.append(t);},h=(o,e)=>e?`${o}: ${e}`:"",x=({variables:o={}})=>{X(` | ||
var E=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var A=(o,e)=>{var t={};for(var r in o)W.call(o,r)&&e.indexOf(r)<0&&(t[r]=o[r]);if(o!=null&&E)for(var r of E(o))e.indexOf(r)<0&&U.call(o,r)&&(t[r]=o[r]);return t};var C=(o,e,t)=>new Promise((r,n)=>{var i=d=>{try{s(t.next(d));}catch(p){n(p);}},a=d=>{try{s(t.throw(d));}catch(p){n(p);}},s=d=>d.done?r(d.value):Promise.resolve(d.value).then(i,a);s((t=t.apply(o,e)).next());});var k=(r=>(r.closed="closed",r.completed="completed",r.canceled="canceled",r))(k||{});var h="application/x-postmate-v1+json",K=5,q=0,z=function(){return ++q};var J=function(e){var t=document.createElement("a");t.href=e;var r=t.protocol.length>4?t.protocol:window.location.protocol,n=t.host.length?t.port==="80"||t.port==="443"?t.hostname:t.host:window.location.host;return t.origin||r+"//"+n},Y={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},P=function(e,t){return !(typeof t=="string"&&e.origin!==t||!e.data||typeof e.data=="object"&&!("postmate"in e.data)||e.data.type!==h||!Y[e.data.postmate])},Z=function(e,t){var r=typeof e[t]=="function"?e[t]():e[t];return y.Promise.resolve(r)},G=function(){function o(t){var r=this;this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},this.listener=function(n){if(!P(n,r.childOrigin))return !1;var i=((n||{}).data||{}).value||{},a=i.data,s=i.name;n.data.postmate==="emit"&&s in r.events&&r.events[s].call(r,a);},this.parent.addEventListener("message",this.listener,!1);}var e=o.prototype;return e.get=function(r){var n=this;return new y.Promise(function(i){var a=z(),s=function d(p){p.data.uid===a&&p.data.postmate==="reply"&&(n.parent.removeEventListener("message",d,!1),i(p.data.value));};n.parent.addEventListener("message",s,!1),n.child.postMessage({postmate:"request",type:h,property:r,uid:a},n.childOrigin);})},e.call=function(r,n){this.child.postMessage({postmate:"call",type:h,property:r,data:n},this.childOrigin);},e.on=function(r,n){this.events[r]=n;},e.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},o}(),Q=function(){function o(t){var r=this;this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,this.child.addEventListener("message",function(n){if(!!P(n,r.parentOrigin)){var i=n.data,a=i.property,s=i.uid,d=i.data;if(n.data.postmate==="call"){a in r.model&&typeof r.model[a]=="function"&&r.model[a](d);return}Z(r.model,a).then(function(p){return n.source.postMessage({property:a,postmate:"reply",type:h,uid:s,value:p},n.origin)});}});}var e=o.prototype;return e.emit=function(r,n){this.parent.postMessage({postmate:"emit",type:h,value:{name:r,data:n}},this.parentOrigin);},o}(),y=function(){function o(t){var r=t.container,n=r===void 0?typeof n!="undefined"?n:document.body:r,i=t.model,a=t.url,s=t.name,d=t.classListArray,p=d===void 0?[]:d;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=s||"",this.frame.classList.add.apply(this.frame.classList,p),n.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=i||{},this.sendHandshake(a)}var e=o.prototype;return e.sendHandshake=function(r){var n=this,i=J(r),a=0,s;return new o.Promise(function(d,p){var l=function c(v){return P(v,i)?v.data.postmate==="handshake-reply"?(clearInterval(s),n.parent.removeEventListener("message",c,!1),n.childOrigin=v.origin,d(new G(n))):p("Failed handshake"):!1};n.parent.addEventListener("message",l,!1);var u=function(){a++,n.child.postMessage({postmate:"handshake",type:h,model:n.model},i),a===K&&clearInterval(s);},S=function(){u(),s=setInterval(u,500);};n.frame.attachEvent?n.frame.attachEvent("onload",S):n.frame.onload=S,n.frame.src=r;})},o}();y.debug=!1;y.Promise=function(){try{return window?window.Promise:Promise}catch(o){return null}}();y.Model=function(){function o(t){return this.child=window,this.model=t,this.parent=this.child.parent,this.sendHandshakeReply()}var e=o.prototype;return e.sendHandshakeReply=function(){var r=this;return new y.Promise(function(n,i){var a=function s(d){if(!!d.data.postmate){if(d.data.postmate==="handshake"){r.child.removeEventListener("message",s,!1),d.source.postMessage({postmate:"handshake-reply",type:h},d.origin),r.parentOrigin=d.origin;var p=d.data.model;return p&&Object.keys(p).forEach(function(l){r.model[l]=p[l];}),n(new Q(r))}return i("Handshake Reply Failed")}};r.child.addEventListener("message",a,!1);})},o}();var F=y;var O="footprint-container",x="footprint-overlay",L="footprint-loading-indicator",X="footprint-custom-styles",tt=o=>{if(typeof window=="undefined")return;let e=document.getElementById(X);e&&e.remove();let t=document.createElement("style");t.setAttribute("id","footprint-custom-styles"),t.textContent=o,document.head.append(t);},g=(o,e)=>e?`${o}: ${e}`:"",R=({variables:o={}})=>{tt(` | ||
:root { | ||
${h("--fp-fp-button-height",o.fpButtonHeight)} | ||
${h("--fp-fp-button-border-radius",o.fpButtonBorderRadius)} | ||
${h("--fp-loading-bg",o.loadingBg)} | ||
${h("--fp-loading-color",o.loadingColor)} | ||
${h("--fp-loading-border-radius",o.loadingBorderRadius)} | ||
${h("--fp-loading-padding",o.loadingPadding)} | ||
${h("--fp-overlay-bg",o.overlayBg)} | ||
${g("--fp-fp-button-height",o.fpButtonHeight)} | ||
${g("--fp-fp-button-border-radius",o.fpButtonBorderRadius)} | ||
${g("--fp-loading-bg",o.loadingBg)} | ||
${g("--fp-loading-color",o.loadingColor)} | ||
${g("--fp-loading-border-radius",o.loadingBorderRadius)} | ||
${g("--fp-loading-padding",o.loadingPadding)} | ||
${g("--fp-overlay-bg",o.overlayBg)} | ||
} | ||
`);},L=o=>{let e=v();return o.appendChild(e),e},R=o=>{document.body.classList.add("footprint-body-locked");let e=document.createElement("div");e.setAttribute("id",F);let t=tt(O);e.appendChild(t),e.classList.add("footprint-overlay"),o.appendChild(e);},N=()=>{let o=document.getElementById(O);o&&o.remove();},I=()=>{document.body.classList.remove("footprint-body-locked");let o=document.getElementById(F);o&&o.remove();},H=()=>{let o=document.getElementById(k);if(o)return o;let e=document.createElement("div");return e.setAttribute("id",k),document.body.appendChild(e),e},tt=o=>{let e=document.createElement("div");e.setAttribute("id",o),e.classList.add("footprint-loading-indicator");let t=document.createElement("div");t.classList.add("footprint-loading-spin");let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","24px"),n.setAttribute("height","24px"),n.setAttribute("fill","none"),n.setAttribute("aria-hidden","true");let r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),n.appendChild(r),t.appendChild(n),e.appendChild(t),e},ot=()=>{let o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.setAttribute("width","24px"),o.setAttribute("height","24px"),o.setAttribute("fill","none"),o.setAttribute("aria-hidden","true");let e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("d","M14.66 14h2.666v-2.36a2.666 2.666 0 1 1 0-4.614V4H6.66v16h4.666v-2.666A3.333 3.333 0 0 1 14.66 14Z"),e.setAttribute("fill","#76fb8f"),o.appendChild(e),o},v=()=>{let o=ot(),e=document.createElement("button");e.appendChild(o);let t=document.createElement("span");return t.innerText="Verify with Footprint",e.appendChild(t),e.classList.add("footprint-button"),e};var P=class{constructor(){this.child=null;}show(e){return C(this,null,function*(){let t=()=>{N();},n=H();R(n);let r=yield new A({classListArray:["footprint-modal"],container:n,name:"footprint-iframe",url:e});r.frame.setAttribute("allow","otp-credentials; publickey-credentials-get *; camera *;"),t(),r.on("closed",()=>this.hide()),this.child=r;})}on(e,t){if(!this.child)throw new Error("Footprint should be open in order to listen events");return this.child.on(e,t)}hide(){I(),this.child&&this.child.destroy();}createButton(e){let t=v();return e.appendChild(t),t}},_=P;var D=o=>{let e="https://id.onefootprint.com",{publicKey:t,variables:n,rules:r,fontSrc:i}=o,a=new URLSearchParams;return t&&a.append("public_key",t),n&&a.append("tokens",n),r&&a.append("rules",r),i&&a.append("font_src",i),`${e}?${a.toString()}`},V=({fontSrc:o,variables:e={},rules:t={}}={})=>{let g=e,l=E(g,["fpButtonBorderRadius","fpButtonHeight","loadingBg","loadingBorderRadius","loadingColor","loadingPadding","overlayBg"]),c=()=>Object.keys(l).length?encodeURIComponent(JSON.stringify(l)):void 0,u=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0;return {fontSrc:o,variables:c(),rules:u()}};var B=new _,et=()=>{let o=({theme:r="light",variables:i={}}={})=>{let{fpButtonBorderRadius:a,fpButtonHeight:p,loadingBg:d,loadingBorderRadius:s,loadingColor:l,loadingPadding:c,overlayBg:u}=i;x({theme:r,variables:{fpButtonBorderRadius:a,fpButtonHeight:p,loadingBg:d,loadingBorderRadius:s,loadingColor:l,loadingPadding:c,overlayBg:u}});},e=r=>B.on("completed",i=>{i&&typeof i=="string"&&r(i);}),t=r=>B.on("canceled",r);return {show:d=>C(void 0,[d],function*({appearance:r,publicKey:i,onCompleted:a,onCanceled:p}){o(r);let{fontSrc:s,rules:l,variables:c}=V(r),u=D({fontSrc:s,publicKey:i,rules:l,variables:c});yield B.show(u),a&&e(a),p&&t(p);})}},M=et;var rt=o=>{window.setTimeout(o,0);},nt=o=>{if(typeof window=="undefined")return;let e=r=>{o.show({publicKey:r,onCanceled:()=>{var i;(i=window.onFootprintCanceled)==null||i.call(window);},onCompleted:i=>{var a;(a=window.onFootprintCompleted)==null||a.call(window,i);}});},t=()=>{let r=document.getElementById("footprint-button");if(!r)return;let i=r.getAttribute("data-public-key");if(!i)throw Error("A public key must be passed as `data-public-key` in the #footprint-button element");n(i,r);},n=(r,i)=>{rt(()=>{L(i).addEventListener("click",()=>{e(r);});});};document.addEventListener("DOMContentLoaded",()=>t());},T=nt;var $=M();T($);var kt=$;/** | ||
`);},m=o=>{if(!o)throw new Error("A container is required to create a Footprint button");let e=B();return o.appendChild(e),e},N=o=>{document.body.classList.add("footprint-body-locked");let e=document.createElement("div");e.setAttribute("id",x);let t=ot(L);e.appendChild(t),e.classList.add("footprint-overlay"),o.appendChild(e);},I=()=>{let o=document.getElementById(L);o&&o.remove();},H=()=>{document.body.classList.remove("footprint-body-locked");let o=document.getElementById(x);o&&o.remove();},_=()=>{let o=document.getElementById(O);if(o)return o;let e=document.createElement("div");return e.setAttribute("id",O),document.body.appendChild(e),e},ot=o=>{let e=document.createElement("div");e.setAttribute("id",o),e.classList.add("footprint-loading-indicator");let t=document.createElement("div");t.classList.add("footprint-loading-spin");let r=document.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("width","24px"),r.setAttribute("height","24px"),r.setAttribute("fill","none"),r.setAttribute("aria-hidden","true");let n=document.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),r.appendChild(n),t.appendChild(r),e.appendChild(t),e},et=()=>{let o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.setAttribute("width","24px"),o.setAttribute("height","24px"),o.setAttribute("fill","none"),o.setAttribute("aria-hidden","true");let e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("d","M14.66 14h2.666v-2.36a2.666 2.666 0 1 1 0-4.614V4H6.66v16h4.666v-2.666A3.333 3.333 0 0 1 14.66 14Z"),e.setAttribute("fill","#76fb8f"),o.appendChild(e),o},B=()=>{let o=et(),e=document.createElement("button");e.appendChild(o);let t=document.createElement("span");return t.innerText="Verify with Footprint",e.appendChild(t),e.classList.add("footprint-button"),e};var b=class{constructor(){this.child=null;}show(e){return C(this,null,function*(){let t=()=>{I();},r=_();N(r);let n=yield new F({classListArray:["footprint-modal"],container:r,name:"footprint-iframe",url:e});n.frame.setAttribute("allow","otp-credentials; publickey-credentials-get *; camera *;"),t(),n.on("closed",()=>this.hide()),this.child=n;})}on(e,t){if(!this.child)throw new Error("Footprint should be open in order to listen events");return this.child.on(e,t)}hide(){H(),this.child&&this.child.destroy();}createButton(e){let t=B();return e.appendChild(t),t}},D=b;var V=o=>{let e="https://id.onefootprint.com",{publicKey:t,variables:r,rules:n,fontSrc:i}=o,a=new URLSearchParams;return t&&a.append("public_key",t),r&&a.append("tokens",r),n&&a.append("rules",n),i&&a.append("font_src",i),`${e}?${a.toString()}`},M=({fontSrc:o,variables:e={},rules:t={}}={})=>{let c=e,l=A(c,["fpButtonBorderRadius","fpButtonHeight","loadingBg","loadingBorderRadius","loadingColor","loadingPadding","overlayBg"]),u=()=>Object.keys(l).length?encodeURIComponent(JSON.stringify(l)):void 0,S=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0;return {fontSrc:o,variables:u(),rules:S()}};var f=new D,w=!1,rt=()=>{let o=({theme:i="light",variables:a={}}={})=>{let{fpButtonBorderRadius:s,fpButtonHeight:d,loadingBg:p,loadingBorderRadius:l,loadingColor:u,loadingPadding:S,overlayBg:c}=a;R({theme:i,variables:{fpButtonBorderRadius:s,fpButtonHeight:d,loadingBg:p,loadingBorderRadius:l,loadingColor:u,loadingPadding:S,overlayBg:c}});},e=i=>f.on("completed",a=>{a&&typeof a=="string"&&i(a);}),t=i=>f.on("canceled",i);return {show:p=>C(void 0,[p],function*({appearance:i,publicKey:a,onCompleted:s,onCanceled:d}){if(w)return;w=!0,o(i);let{fontSrc:l,rules:u,variables:S}=M(i),c=V({fontSrc:l,publicKey:a,rules:u,variables:S});yield f.show(c),s&&e(s),d&&t(d);}),hide:()=>C(void 0,null,function*(){yield f.hide(),w=!1;}),createButton:m}},T=rt;var nt=o=>{window.setTimeout(o,0);},it=o=>{if(typeof window=="undefined")return;let e=n=>{o.show({publicKey:n,onCanceled:()=>{var i;(i=window.onFootprintCanceled)==null||i.call(window);},onCompleted:i=>{var a;(a=window.onFootprintCompleted)==null||a.call(window,i);}});},t=()=>{let n=document.getElementById("footprint-button");if(!n)return;let i=n.getAttribute("data-public-key");if(!i)throw Error("A public key must be passed as `data-public-key` in the #footprint-button element");r(i,n);},r=(n,i)=>{nt(()=>{m(i).addEventListener("click",()=>{e(n);});});};document.addEventListener("DOMContentLoaded",()=>t());},$=it;var j=T();$(j);var Ft=j;/** | ||
postmate - A powerful, simple, promise-based postMessage library | ||
@@ -19,2 +19,2 @@ @version v1.5.2 | ||
export { w as FootprintEvents, kt as default }; | ||
export { k as FootprintEvents, Ft as default }; |
(function (exports) { | ||
'use strict'; | ||
var b=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var E=(o,e)=>{var t={};for(var n in o)j.call(o,n)&&e.indexOf(n)<0&&(t[n]=o[n]);if(o!=null&&b)for(var n of b(o))e.indexOf(n)<0&&W.call(o,n)&&(t[n]=o[n]);return t};var C=(o,e,t)=>new Promise((n,r)=>{var i=d=>{try{p(t.next(d));}catch(s){r(s);}},a=d=>{try{p(t.throw(d));}catch(s){r(s);}},p=d=>d.done?n(d.value):Promise.resolve(d.value).then(i,a);p((t=t.apply(o,e)).next());});var w=(n=>(n.closed="closed",n.completed="completed",n.canceled="canceled",n))(w||{});var S="application/x-postmate-v1+json",U=5,K=0,q=function(){return ++K};var z=function(e){var t=document.createElement("a");t.href=e;var n=t.protocol.length>4?t.protocol:window.location.protocol,r=t.host.length?t.port==="80"||t.port==="443"?t.hostname:t.host:window.location.host;return t.origin||n+"//"+r},J={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},f=function(e,t){return !(typeof t=="string"&&e.origin!==t||!e.data||typeof e.data=="object"&&!("postmate"in e.data)||e.data.type!==S||!J[e.data.postmate])},Y=function(e,t){var n=typeof e[t]=="function"?e[t]():e[t];return y.Promise.resolve(n)},Z=function(){function o(t){var n=this;this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},this.listener=function(r){if(!f(r,n.childOrigin))return !1;var i=((r||{}).data||{}).value||{},a=i.data,p=i.name;r.data.postmate==="emit"&&p in n.events&&n.events[p].call(n,a);},this.parent.addEventListener("message",this.listener,!1);}var e=o.prototype;return e.get=function(n){var r=this;return new y.Promise(function(i){var a=q(),p=function d(s){s.data.uid===a&&s.data.postmate==="reply"&&(r.parent.removeEventListener("message",d,!1),i(s.data.value));};r.parent.addEventListener("message",p,!1),r.child.postMessage({postmate:"request",type:S,property:n,uid:a},r.childOrigin);})},e.call=function(n,r){this.child.postMessage({postmate:"call",type:S,property:n,data:r},this.childOrigin);},e.on=function(n,r){this.events[n]=r;},e.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},o}(),G=function(){function o(t){var n=this;this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,this.child.addEventListener("message",function(r){if(!!f(r,n.parentOrigin)){var i=r.data,a=i.property,p=i.uid,d=i.data;if(r.data.postmate==="call"){a in n.model&&typeof n.model[a]=="function"&&n.model[a](d);return}Y(n.model,a).then(function(s){return r.source.postMessage({property:a,postmate:"reply",type:S,uid:p,value:s},r.origin)});}});}var e=o.prototype;return e.emit=function(n,r){this.parent.postMessage({postmate:"emit",type:S,value:{name:n,data:r}},this.parentOrigin);},o}(),y=function(){function o(t){var n=t.container,r=n===void 0?typeof r!="undefined"?r:document.body:n,i=t.model,a=t.url,p=t.name,d=t.classListArray,s=d===void 0?[]:d;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=p||"",this.frame.classList.add.apply(this.frame.classList,s),r.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=i||{},this.sendHandshake(a)}var e=o.prototype;return e.sendHandshake=function(n){var r=this,i=z(n),a=0,p;return new o.Promise(function(d,s){var l=function g(m){return f(m,i)?m.data.postmate==="handshake-reply"?(clearInterval(p),r.parent.removeEventListener("message",g,!1),r.childOrigin=m.origin,d(new Z(r))):s("Failed handshake"):!1};r.parent.addEventListener("message",l,!1);var c=function(){a++,r.child.postMessage({postmate:"handshake",type:S,model:r.model},i),a===U&&clearInterval(p);},u=function(){c(),p=setInterval(c,500);};r.frame.attachEvent?r.frame.attachEvent("onload",u):r.frame.onload=u,r.frame.src=n;})},o}();y.debug=!1;y.Promise=function(){try{return window?window.Promise:Promise}catch(o){return null}}();y.Model=function(){function o(t){return this.child=window,this.model=t,this.parent=this.child.parent,this.sendHandshakeReply()}var e=o.prototype;return e.sendHandshakeReply=function(){var n=this;return new y.Promise(function(r,i){var a=function p(d){if(!!d.data.postmate){if(d.data.postmate==="handshake"){n.child.removeEventListener("message",p,!1),d.source.postMessage({postmate:"handshake-reply",type:S},d.origin),n.parentOrigin=d.origin;var s=d.data.model;return s&&Object.keys(s).forEach(function(l){n.model[l]=s[l];}),r(new G(n))}return i("Handshake Reply Failed")}};n.child.addEventListener("message",a,!1);})},o}();var A=y;var k="footprint-container",F="footprint-overlay",O="footprint-loading-indicator",Q="footprint-custom-styles",X=o=>{if(typeof window=="undefined")return;let e=document.getElementById(Q);e&&e.remove();let t=document.createElement("style");t.setAttribute("id","footprint-custom-styles"),t.textContent=o,document.head.append(t);},h=(o,e)=>e?`${o}: ${e}`:"",x=({variables:o={}})=>{X(` | ||
var E=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var A=(o,e)=>{var t={};for(var r in o)W.call(o,r)&&e.indexOf(r)<0&&(t[r]=o[r]);if(o!=null&&E)for(var r of E(o))e.indexOf(r)<0&&U.call(o,r)&&(t[r]=o[r]);return t};var C=(o,e,t)=>new Promise((r,n)=>{var i=d=>{try{s(t.next(d));}catch(p){n(p);}},a=d=>{try{s(t.throw(d));}catch(p){n(p);}},s=d=>d.done?r(d.value):Promise.resolve(d.value).then(i,a);s((t=t.apply(o,e)).next());});var k=(r=>(r.closed="closed",r.completed="completed",r.canceled="canceled",r))(k||{});var h="application/x-postmate-v1+json",K=5,q=0,z=function(){return ++q};var J=function(e){var t=document.createElement("a");t.href=e;var r=t.protocol.length>4?t.protocol:window.location.protocol,n=t.host.length?t.port==="80"||t.port==="443"?t.hostname:t.host:window.location.host;return t.origin||r+"//"+n},Y={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},P=function(e,t){return !(typeof t=="string"&&e.origin!==t||!e.data||typeof e.data=="object"&&!("postmate"in e.data)||e.data.type!==h||!Y[e.data.postmate])},Z=function(e,t){var r=typeof e[t]=="function"?e[t]():e[t];return y.Promise.resolve(r)},G=function(){function o(t){var r=this;this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},this.listener=function(n){if(!P(n,r.childOrigin))return !1;var i=((n||{}).data||{}).value||{},a=i.data,s=i.name;n.data.postmate==="emit"&&s in r.events&&r.events[s].call(r,a);},this.parent.addEventListener("message",this.listener,!1);}var e=o.prototype;return e.get=function(r){var n=this;return new y.Promise(function(i){var a=z(),s=function d(p){p.data.uid===a&&p.data.postmate==="reply"&&(n.parent.removeEventListener("message",d,!1),i(p.data.value));};n.parent.addEventListener("message",s,!1),n.child.postMessage({postmate:"request",type:h,property:r,uid:a},n.childOrigin);})},e.call=function(r,n){this.child.postMessage({postmate:"call",type:h,property:r,data:n},this.childOrigin);},e.on=function(r,n){this.events[r]=n;},e.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame);},o}(),Q=function(){function o(t){var r=this;this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,this.child.addEventListener("message",function(n){if(!!P(n,r.parentOrigin)){var i=n.data,a=i.property,s=i.uid,d=i.data;if(n.data.postmate==="call"){a in r.model&&typeof r.model[a]=="function"&&r.model[a](d);return}Z(r.model,a).then(function(p){return n.source.postMessage({property:a,postmate:"reply",type:h,uid:s,value:p},n.origin)});}});}var e=o.prototype;return e.emit=function(r,n){this.parent.postMessage({postmate:"emit",type:h,value:{name:r,data:n}},this.parentOrigin);},o}(),y=function(){function o(t){var r=t.container,n=r===void 0?typeof n!="undefined"?n:document.body:r,i=t.model,a=t.url,s=t.name,d=t.classListArray,p=d===void 0?[]:d;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=s||"",this.frame.classList.add.apply(this.frame.classList,p),n.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=i||{},this.sendHandshake(a)}var e=o.prototype;return e.sendHandshake=function(r){var n=this,i=J(r),a=0,s;return new o.Promise(function(d,p){var l=function c(v){return P(v,i)?v.data.postmate==="handshake-reply"?(clearInterval(s),n.parent.removeEventListener("message",c,!1),n.childOrigin=v.origin,d(new G(n))):p("Failed handshake"):!1};n.parent.addEventListener("message",l,!1);var u=function(){a++,n.child.postMessage({postmate:"handshake",type:h,model:n.model},i),a===K&&clearInterval(s);},S=function(){u(),s=setInterval(u,500);};n.frame.attachEvent?n.frame.attachEvent("onload",S):n.frame.onload=S,n.frame.src=r;})},o}();y.debug=!1;y.Promise=function(){try{return window?window.Promise:Promise}catch(o){return null}}();y.Model=function(){function o(t){return this.child=window,this.model=t,this.parent=this.child.parent,this.sendHandshakeReply()}var e=o.prototype;return e.sendHandshakeReply=function(){var r=this;return new y.Promise(function(n,i){var a=function s(d){if(!!d.data.postmate){if(d.data.postmate==="handshake"){r.child.removeEventListener("message",s,!1),d.source.postMessage({postmate:"handshake-reply",type:h},d.origin),r.parentOrigin=d.origin;var p=d.data.model;return p&&Object.keys(p).forEach(function(l){r.model[l]=p[l];}),n(new Q(r))}return i("Handshake Reply Failed")}};r.child.addEventListener("message",a,!1);})},o}();var F=y;var O="footprint-container",x="footprint-overlay",L="footprint-loading-indicator",X="footprint-custom-styles",tt=o=>{if(typeof window=="undefined")return;let e=document.getElementById(X);e&&e.remove();let t=document.createElement("style");t.setAttribute("id","footprint-custom-styles"),t.textContent=o,document.head.append(t);},g=(o,e)=>e?`${o}: ${e}`:"",R=({variables:o={}})=>{tt(` | ||
:root { | ||
${h("--fp-fp-button-height",o.fpButtonHeight)} | ||
${h("--fp-fp-button-border-radius",o.fpButtonBorderRadius)} | ||
${h("--fp-loading-bg",o.loadingBg)} | ||
${h("--fp-loading-color",o.loadingColor)} | ||
${h("--fp-loading-border-radius",o.loadingBorderRadius)} | ||
${h("--fp-loading-padding",o.loadingPadding)} | ||
${h("--fp-overlay-bg",o.overlayBg)} | ||
${g("--fp-fp-button-height",o.fpButtonHeight)} | ||
${g("--fp-fp-button-border-radius",o.fpButtonBorderRadius)} | ||
${g("--fp-loading-bg",o.loadingBg)} | ||
${g("--fp-loading-color",o.loadingColor)} | ||
${g("--fp-loading-border-radius",o.loadingBorderRadius)} | ||
${g("--fp-loading-padding",o.loadingPadding)} | ||
${g("--fp-overlay-bg",o.overlayBg)} | ||
} | ||
`);},L=o=>{let e=v();return o.appendChild(e),e},R=o=>{document.body.classList.add("footprint-body-locked");let e=document.createElement("div");e.setAttribute("id",F);let t=tt(O);e.appendChild(t),e.classList.add("footprint-overlay"),o.appendChild(e);},N=()=>{let o=document.getElementById(O);o&&o.remove();},I=()=>{document.body.classList.remove("footprint-body-locked");let o=document.getElementById(F);o&&o.remove();},H=()=>{let o=document.getElementById(k);if(o)return o;let e=document.createElement("div");return e.setAttribute("id",k),document.body.appendChild(e),e},tt=o=>{let e=document.createElement("div");e.setAttribute("id",o),e.classList.add("footprint-loading-indicator");let t=document.createElement("div");t.classList.add("footprint-loading-spin");let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","24px"),n.setAttribute("height","24px"),n.setAttribute("fill","none"),n.setAttribute("aria-hidden","true");let r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),n.appendChild(r),t.appendChild(n),e.appendChild(t),e},ot=()=>{let o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.setAttribute("width","24px"),o.setAttribute("height","24px"),o.setAttribute("fill","none"),o.setAttribute("aria-hidden","true");let e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("d","M14.66 14h2.666v-2.36a2.666 2.666 0 1 1 0-4.614V4H6.66v16h4.666v-2.666A3.333 3.333 0 0 1 14.66 14Z"),e.setAttribute("fill","#76fb8f"),o.appendChild(e),o},v=()=>{let o=ot(),e=document.createElement("button");e.appendChild(o);let t=document.createElement("span");return t.innerText="Verify with Footprint",e.appendChild(t),e.classList.add("footprint-button"),e};var P=class{constructor(){this.child=null;}show(e){return C(this,null,function*(){let t=()=>{N();},n=H();R(n);let r=yield new A({classListArray:["footprint-modal"],container:n,name:"footprint-iframe",url:e});r.frame.setAttribute("allow","otp-credentials; publickey-credentials-get *; camera *;"),t(),r.on("closed",()=>this.hide()),this.child=r;})}on(e,t){if(!this.child)throw new Error("Footprint should be open in order to listen events");return this.child.on(e,t)}hide(){I(),this.child&&this.child.destroy();}createButton(e){let t=v();return e.appendChild(t),t}},_=P;var D=o=>{let e="https://id.onefootprint.com",{publicKey:t,variables:n,rules:r,fontSrc:i}=o,a=new URLSearchParams;return t&&a.append("public_key",t),n&&a.append("tokens",n),r&&a.append("rules",r),i&&a.append("font_src",i),`${e}?${a.toString()}`},V=({fontSrc:o,variables:e={},rules:t={}}={})=>{let g=e,l=E(g,["fpButtonBorderRadius","fpButtonHeight","loadingBg","loadingBorderRadius","loadingColor","loadingPadding","overlayBg"]),c=()=>Object.keys(l).length?encodeURIComponent(JSON.stringify(l)):void 0,u=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0;return {fontSrc:o,variables:c(),rules:u()}};var B=new _,et=()=>{let o=({theme:r="light",variables:i={}}={})=>{let{fpButtonBorderRadius:a,fpButtonHeight:p,loadingBg:d,loadingBorderRadius:s,loadingColor:l,loadingPadding:c,overlayBg:u}=i;x({theme:r,variables:{fpButtonBorderRadius:a,fpButtonHeight:p,loadingBg:d,loadingBorderRadius:s,loadingColor:l,loadingPadding:c,overlayBg:u}});},e=r=>B.on("completed",i=>{i&&typeof i=="string"&&r(i);}),t=r=>B.on("canceled",r);return {show:d=>C(void 0,[d],function*({appearance:r,publicKey:i,onCompleted:a,onCanceled:p}){o(r);let{fontSrc:s,rules:l,variables:c}=V(r),u=D({fontSrc:s,publicKey:i,rules:l,variables:c});yield B.show(u),a&&e(a),p&&t(p);})}},M=et;var rt=o=>{window.setTimeout(o,0);},nt=o=>{if(typeof window=="undefined")return;let e=r=>{o.show({publicKey:r,onCanceled:()=>{var i;(i=window.onFootprintCanceled)==null||i.call(window);},onCompleted:i=>{var a;(a=window.onFootprintCompleted)==null||a.call(window,i);}});},t=()=>{let r=document.getElementById("footprint-button");if(!r)return;let i=r.getAttribute("data-public-key");if(!i)throw Error("A public key must be passed as `data-public-key` in the #footprint-button element");n(i,r);},n=(r,i)=>{rt(()=>{L(i).addEventListener("click",()=>{e(r);});});};document.addEventListener("DOMContentLoaded",()=>t());},T=nt;var $=M();T($);var kt=$;/** | ||
`);},m=o=>{if(!o)throw new Error("A container is required to create a Footprint button");let e=B();return o.appendChild(e),e},N=o=>{document.body.classList.add("footprint-body-locked");let e=document.createElement("div");e.setAttribute("id",x);let t=ot(L);e.appendChild(t),e.classList.add("footprint-overlay"),o.appendChild(e);},I=()=>{let o=document.getElementById(L);o&&o.remove();},H=()=>{document.body.classList.remove("footprint-body-locked");let o=document.getElementById(x);o&&o.remove();},_=()=>{let o=document.getElementById(O);if(o)return o;let e=document.createElement("div");return e.setAttribute("id",O),document.body.appendChild(e),e},ot=o=>{let e=document.createElement("div");e.setAttribute("id",o),e.classList.add("footprint-loading-indicator");let t=document.createElement("div");t.classList.add("footprint-loading-spin");let r=document.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("width","24px"),r.setAttribute("height","24px"),r.setAttribute("fill","none"),r.setAttribute("aria-hidden","true");let n=document.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttribute("d","M12 2a10 10 0 0 1 10 10h-2a7.999 7.999 0 0 0-8-8V2Z"),r.appendChild(n),t.appendChild(r),e.appendChild(t),e},et=()=>{let o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.setAttribute("width","24px"),o.setAttribute("height","24px"),o.setAttribute("fill","none"),o.setAttribute("aria-hidden","true");let e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("d","M14.66 14h2.666v-2.36a2.666 2.666 0 1 1 0-4.614V4H6.66v16h4.666v-2.666A3.333 3.333 0 0 1 14.66 14Z"),e.setAttribute("fill","#76fb8f"),o.appendChild(e),o},B=()=>{let o=et(),e=document.createElement("button");e.appendChild(o);let t=document.createElement("span");return t.innerText="Verify with Footprint",e.appendChild(t),e.classList.add("footprint-button"),e};var b=class{constructor(){this.child=null;}show(e){return C(this,null,function*(){let t=()=>{I();},r=_();N(r);let n=yield new F({classListArray:["footprint-modal"],container:r,name:"footprint-iframe",url:e});n.frame.setAttribute("allow","otp-credentials; publickey-credentials-get *; camera *;"),t(),n.on("closed",()=>this.hide()),this.child=n;})}on(e,t){if(!this.child)throw new Error("Footprint should be open in order to listen events");return this.child.on(e,t)}hide(){H(),this.child&&this.child.destroy();}createButton(e){let t=B();return e.appendChild(t),t}},D=b;var V=o=>{let e="https://id.onefootprint.com",{publicKey:t,variables:r,rules:n,fontSrc:i}=o,a=new URLSearchParams;return t&&a.append("public_key",t),r&&a.append("tokens",r),n&&a.append("rules",n),i&&a.append("font_src",i),`${e}?${a.toString()}`},M=({fontSrc:o,variables:e={},rules:t={}}={})=>{let c=e,l=A(c,["fpButtonBorderRadius","fpButtonHeight","loadingBg","loadingBorderRadius","loadingColor","loadingPadding","overlayBg"]),u=()=>Object.keys(l).length?encodeURIComponent(JSON.stringify(l)):void 0,S=()=>Object.keys(t).length?encodeURIComponent(JSON.stringify(t)):void 0;return {fontSrc:o,variables:u(),rules:S()}};var f=new D,w=!1,rt=()=>{let o=({theme:i="light",variables:a={}}={})=>{let{fpButtonBorderRadius:s,fpButtonHeight:d,loadingBg:p,loadingBorderRadius:l,loadingColor:u,loadingPadding:S,overlayBg:c}=a;R({theme:i,variables:{fpButtonBorderRadius:s,fpButtonHeight:d,loadingBg:p,loadingBorderRadius:l,loadingColor:u,loadingPadding:S,overlayBg:c}});},e=i=>f.on("completed",a=>{a&&typeof a=="string"&&i(a);}),t=i=>f.on("canceled",i);return {show:p=>C(void 0,[p],function*({appearance:i,publicKey:a,onCompleted:s,onCanceled:d}){if(w)return;w=!0,o(i);let{fontSrc:l,rules:u,variables:S}=M(i),c=V({fontSrc:l,publicKey:a,rules:u,variables:S});yield f.show(c),s&&e(s),d&&t(d);}),hide:()=>C(void 0,null,function*(){yield f.hide(),w=!1;}),createButton:m}},T=rt;var nt=o=>{window.setTimeout(o,0);},it=o=>{if(typeof window=="undefined")return;let e=n=>{o.show({publicKey:n,onCanceled:()=>{var i;(i=window.onFootprintCanceled)==null||i.call(window);},onCompleted:i=>{var a;(a=window.onFootprintCompleted)==null||a.call(window,i);}});},t=()=>{let n=document.getElementById("footprint-button");if(!n)return;let i=n.getAttribute("data-public-key");if(!i)throw Error("A public key must be passed as `data-public-key` in the #footprint-button element");r(i,n);},r=(n,i)=>{nt(()=>{m(i).addEventListener("click",()=>{e(n);});});};document.addEventListener("DOMContentLoaded",()=>t());},$=it;var j=T();$(j);var Ft=j;/** | ||
postmate - A powerful, simple, promise-based postMessage library | ||
@@ -22,4 +22,4 @@ @version v1.5.2 | ||
exports.FootprintEvents = w; | ||
exports.default = kt; | ||
exports.FootprintEvents = k; | ||
exports.default = Ft; | ||
@@ -26,0 +26,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"main": "./dist/footprint-js.umd.js", | ||
@@ -8,0 +8,0 @@ "module": "./dist/footprint-js.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
40072
330
0