@whop/checkout
Version:
Embed Whop checkout on any website
1 lines • 10.7 kB
JavaScript
function e(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function t(e){if(Array.isArray(e))return e}function r(e){if(e===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e}function n(e,t,r,n,o,i,a){try{var u=e[i](a);var c=u.value}catch(e){r(e);return}if(u.done){t(c)}else{Promise.resolve(c).then(n,o)}}function o(e){return function(){var t=this,r=arguments;return new Promise(function(o,i){var a=e.apply(t,r);function u(e){n(a,o,i,u,c,"next",e)}function c(e){n(a,o,i,u,c,"throw",e)}u(undefined)})}}function i(e,t,r){t=l(t);return m(e,j()?Reflect.construct(t,r||[],l(e).constructor):t.apply(e,r))}function a(e,t){if(!(e instanceof t)){throw new TypeError("Cannot call a class as a function")}}function u(e,t,r){if(j()){u=Reflect.construct}else{u=function e(e,t,r){var n=[null];n.push.apply(n,t);var o=Function.bind.apply(e,n);var i=new o;if(r)b(i,r.prototype);return i}}return u.apply(null,arguments)}function c(e,t,r){if(t in e){Object.defineProperty(e,t,{value:r,enumerable:true,configurable:true,writable:true})}else{e[t]=r}return e}function l(e){l=Object.setPrototypeOf?Object.getPrototypeOf:function e(e){return e.__proto__||Object.getPrototypeOf(e)};return l(e)}function s(e,t){if(typeof t!=="function"&&t!==null){throw new TypeError("Super expression must either be null or a function")}e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:true,configurable:true}});if(t)b(e,t)}function f(e){return Function.toString.call(e).indexOf("[native code]")!==-1}function p(e,t){var r=e==null?null:typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(r==null)return;var n=[];var o=true;var i=false;var a,u;try{for(r=r.call(e);!(o=(a=r.next()).done);o=true){n.push(a.value);if(t&&n.length===t)break}}catch(e){i=true;u=e}finally{try{if(!o&&r["return"]!=null)r["return"]()}finally{if(i)throw u}}return n}function y(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function d(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};var n=Object.keys(r);if(typeof Object.getOwnPropertySymbols==="function"){n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))}n.forEach(function(t){c(e,t,r[t])})}return e}function v(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);if(t){n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})}r.push.apply(r,n)}return r}function h(e,t){t=t!=null?t:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(e,Object.getOwnPropertyDescriptors(t))}else{v(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function m(e,t){if(t&&(g(t)==="object"||typeof t==="function")){return t}return r(e)}function b(e,t){b=Object.setPrototypeOf||function e(e,t){e.__proto__=t;return e};return b(e,t)}function w(e,r){return t(e)||p(e,r)||O(e,r)||y()}function g(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}function O(t,r){if(!t)return;if(typeof t==="string")return e(t,r);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor)n=t.constructor.name;if(n==="Map"||n==="Set")return Array.from(n);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return e(t,r)}function P(e){var t=typeof Map==="function"?new Map:undefined;P=function e(e){if(e===null||!f(e))return e;if(typeof e!=="function"){throw new TypeError("Super expression must either be null or a function")}if(typeof t!=="undefined"){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return u(e,arguments,l(this).constructor)}r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:false,writable:true,configurable:true}});return b(r,e)};return P(e)}function j(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(j=function(){return!!e})()}function _(e,t){var r,n,o,i={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},a=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return a.next=u(0),a["throw"]=u(1),a["return"]=u(2),typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function u(e){return function(t){return c([e,t])}}function c(u){if(r)throw new TypeError("Generator is already executing.");while(a&&(a=0,u[0]&&(i=0)),i)try{if(r=1,n&&(o=u[0]&2?n["return"]:u[0]?n["throw"]||((o=n["return"])&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;if(n=0,o)u=[u[0]&2,o.value];switch(u[0]){case 0:case 1:o=u;break;case 4:i.label++;return{value:u[1],done:false};case 5:i.label++;n=u[1];u=[0];continue;case 7:u=i.ops.pop();i.trys.pop();continue;default:if(!(o=i.trys,o=o.length>0&&o[o.length-1])&&(u[0]===6||u[0]===2)){i=0;continue}if(u[0]===3&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(u[0]===6&&i.label<o[1]){i.label=o[1];o=u;break}if(o&&i.label<o[2]){i.label=o[2];i.ops.push(u);break}if(o[2])i.ops.pop();i.trys.pop();continue}u=t.call(e,i)}catch(e){u=[6,e];n=0}finally{r=o=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:true}}}var S=Object.defineProperty;var E=function(e,t,r){return t in e?S(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r};var k=function(e,t,r){return E(e,(typeof t==="undefined"?"undefined":g(t))!="symbol"?t+"":t,r)};var x=/*#__PURE__*/function(e){"use strict";s(t,e);function t(){a(this,t);var e;e=i(this,t,arguments);k(e,"type","WhopCheckoutError");return e}return t}(P(Error));var R=/*#__PURE__*/function(e){"use strict";s(t,e);function t(e){a(this,t);var r;r=i(this,t,[e!==null&&e!==void 0?e:"Timeout waiting for embed response"]);k(r,"name","WhopCheckoutRpcTimeoutError");return r}return t}(x);var A=/*#__PURE__*/function(e){"use strict";s(t,e);function t(){a(this,t);var e;e=i(this,t,arguments);k(e,"name","WhopCheckoutSetEmailError");return e}return t}(x);var T=["resize","center","complete","state","get-email-result","set-email-result"];function L(e){return g(e.data)=="object"&&e.data!==null&&"event"in e.data&&T.includes(e.data.event)}function U(e,t){return L(e)&&e.data.event===t}var W=[];function C(e){return W[e]||(W[e]=(e+256).toString(16).slice(1))}function M(){var e=new Uint8Array(16);if((typeof crypto==="undefined"?"undefined":g(crypto))<"u"&&typeof crypto.getRandomValues=="function")crypto.getRandomValues(e);else for(var t=0;t<16;t++)e[t]=Math.random()*256|0;return e[6]=e[6]&15|64,e[8]=e[8]&63|128,C(e[0])+C(e[1])+C(e[2])+C(e[3])+"-"+C(e[4])+C(e[5])+"-"+C(e[6])+C(e[7])+"-"+C(e[8])+C(e[9])+"-"+C(e[10])+C(e[11])+C(e[12])+C(e[13])+C(e[14])+C(e[15])}function D(e,t,r,n){var o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:2e3;var i;var a=new URL(e.src).origin,u=M();return(i=e.contentWindow)===null||i===void 0?void 0:i.postMessage(h(d({},t),{__scope:"whop-embedded-checkout",event_id:u}),a),new Promise(function(t,i){var a=setTimeout(function(){i(new R),window.removeEventListener("message",c)},o),c=function(o){if(o.source===e.contentWindow&&U(o,r)&&o.data.event===r&&o.data.event_id===u){clearTimeout(a),window.removeEventListener("message",c);try{t(n(o.data))}catch(e){i(e)}}};window.addEventListener("message",c)})}function I(e,t){function r(r){r.source===e.contentWindow&&L(r)&&t(r.data)}return window.addEventListener("message",r),function(){window.removeEventListener("message",r)}}function B(e,t){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:2e3;return o(function(){return _(this,function(n){return[2,D(e,{event:"set-email",email:t},"set-email-result",function(e){if(!e.ok)throw new A(e.error)},r)]})})()}function F(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:2e3;return o(function(){return _(this,function(r){return[2,D(e,{event:"get-email"},"get-email-result",function(e){return e.email},t)]})})()}function G(e,t){var r;var n=new URL(e.src).origin;(r=e.contentWindow)===null||r===void 0?void 0:r.postMessage({__scope:"whop-embedded-checkout",event:"submit"},n)}function V(e,t,r,n,o,i,a,u,c,l,s,f,p,y){var d=new URL("/embedded/checkout/".concat(e,"/"),n!==null&&n!==void 0?n:"https://whop.com/");if(d.searchParams.set("h",window.location.origin),t&&d.searchParams.set("theme",t),r&&d.searchParams.set("session",r),o&&d.searchParams.set("hide_price","true"),i&&d.searchParams.set("skip_redirect","true"),s&&d.searchParams.set("hide_submit_button","true"),f&&d.searchParams.set("hide_tos","true"),p&&d.searchParams.set("email.hidden","1"),y&&d.searchParams.set("email.disabled","1"),a){var v=true,h=false,m=undefined,b=true,g=false,O=undefined;try{for(var P=Object.entries(a).sort(function(e,t){return e[0].localeCompare(t[0])})[Symbol.iterator](),j;!(b=(j=P.next()).done);b=true){var _=w(j.value,2),S=_[0],E=_[1];if(S.startsWith("utm_"))if(Array.isArray(E))try{for(var k=E[Symbol.iterator](),x;!(v=(x=k.next()).done);v=true){var R=x.value;d.searchParams.append(S,R)}}catch(e){h=true;m=e}finally{try{if(!v&&k.return!=null){k.return()}}finally{if(h){throw m}}}else d.searchParams.set(S,E)}}catch(e){g=true;O=e}finally{try{if(!b&&P.return!=null){P.return()}}finally{if(g){throw O}}}}if(u){var A=true,T=false,L=undefined,U=true,W=false,C=undefined;try{for(var M=Object.entries(u)[Symbol.iterator](),D;!(U=(D=M.next()).done);U=true){var I=w(D.value,2),B=I[0],F=I[1];if(F)try{for(var G=Object.entries(F)[Symbol.iterator](),V;!(A=(V=G.next()).done);A=true){var q=w(V.value,2),z=q[0],J=q[1];d.searchParams.set("style.".concat(B,".").concat(z),J.toString())}}catch(e){T=true;L=e}finally{try{if(!A&&G.return!=null){G.return()}}finally{if(T){throw L}}}}}catch(e){W=true;C=e}finally{try{if(!U&&M.return!=null){M.return()}}finally{if(W){throw C}}}}var Q=true,Z=false,$=undefined;if((c===null||c===void 0?void 0:c.email)&&d.searchParams.set("email",c.email),l)try{for(var H=Object.entries(l)[Symbol.iterator](),K;!(Q=(K=H.next()).done);Q=true){var N=w(K.value,2),X=N[0],Y=N[1];Y&&d.searchParams.set("theme.".concat(X),Y)}}catch(e){Z=true;$=e}finally{try{if(!Q&&H.return!=null){H.return()}}finally{if(Z){throw $}}}return d.toString()}var q=["allow-forms","allow-modals","allow-orientation-lock","allow-pointer-lock","allow-popups","allow-presentation","allow-same-origin","allow-scripts","allow-top-navigation","allow-top-navigation-by-user-activation","allow-downloads"],z="document-domain; execution-while-not-rendered; execution-while-out-of-viewport; payment; paymentRequest; sync-script;";export{L as a,I as b,B as c,F as d,G as e,V as f,q as g,z as h};