UNPKG

@whop/checkout

Version:

Embed Whop checkout on any website

1 lines 6.24 kB
function e(e,r){if(r==null||r>e.length)r=e.length;for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function r(e){if(Array.isArray(e))return e}function t(r){if(Array.isArray(r))return e(r)}function n(e,r,t){if(r in e){Object.defineProperty(e,r,{value:t,enumerable:true,configurable:true,writable:true})}else{e[r]=t}return e}function o(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function i(e,r){var t=e==null?null:typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(t==null)return;var n=[];var o=true;var i=false;var u,a;try{for(t=t.call(e);!(o=(u=t.next()).done);o=true){n.push(u.value);if(r&&n.length===r)break}}catch(e){i=true;a=e}finally{try{if(!o&&t["return"]!=null)t["return"]()}finally{if(i)throw a}}return n}function u(){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 a(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(e){for(var r=1;r<arguments.length;r++){var t=arguments[r]!=null?arguments[r]:{};var o=Object.keys(t);if(typeof Object.getOwnPropertySymbols==="function"){o=o.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))}o.forEach(function(r){n(e,r,t[r])})}return e}function l(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);if(r){n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})}t.push.apply(t,n)}return t}function f(e,r){r=r!=null?r:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(e,Object.getOwnPropertyDescriptors(r))}else{l(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function s(e,r){if(e==null)return{};var t=d(e,r);var n,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++){n=i[o];if(r.indexOf(n)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(e,n))continue;t[n]=e[n]}}return t}function d(e,r){if(e==null)return{};var t={};var n=Object.keys(e);var o,i;for(i=0;i<n.length;i++){o=n[i];if(r.indexOf(o)>=0)continue;t[o]=e[o]}return t}function m(e,t){return r(e)||i(e,t)||b(e,t)||u()}function p(e){return t(e)||o(e)||b(e)||a()}function b(r,t){if(!r)return;if(typeof r==="string")return e(r,t);var n=Object.prototype.toString.call(r).slice(8,-1);if(n==="Object"&&r.constructor)n=r.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(r,t)}import{b as y,c as h,d as v,e as g,f as w,g as O,h as E}from"../chunk-N2KVERZN.mjs";import j,{forwardRef as k,useEffect as S,useMemo as P,useRef as C,useState as A}from"react";import{useSyncExternalStore as I}from"react";function W(){return function(){}}function x(){return I(W,function(){return!0},function(){return!1})}var D=["tomato","red","ruby","crimson","pink","plum","purple","violet","iris","cyan","teal","jade","green","grass","brown","blue","orange","indigo","sky","mint","yellow","amber","lime","lemon","magenta","gold","bronze","gray"];function N(e){return e?D.includes(e):!1}import{useEffect as R,useMemo as M}from"react";import{useRef as T}from"react";var U=Symbol("none");function V(e){var r=T(U);return r.current===U&&(r.current=e()),r}function _(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++){r[t]=arguments[t]}var n=V(function(){return w.apply(void 0,p(r))}),o=n.current;return o&&z.apply(void 0,[o].concat(p(r))),o}function z(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++){t[n-1]=arguments[n]}var o=m(t,12),i=o[0],u=o[1],a=o[2],c=o[3],l=o[4],f=o[5],s=o[6],d=o[7],p=o[8],b=o[9],y=o[10],h=o[11];var v=M(function(){return w(i,u,a,void 0,l,f,s,d,p,b,y,h)},[i,u,a,l,f,s,d,p,b,y,h]);R(function(){e!==v&&process.env.NODE_ENV==="development"&&console.warn("[WhopCheckoutEmbed] iframeUrl changed from ".concat(e," to ").concat(v,". Updating props on the checkout embed is not supported. Please rerender the component."))},[e,v])}var Z=O.join(" ");var B=k(function(e,r){var t=e.planId,n=e.theme,o=e.sessionId,i=e.hidePrice,u=i===void 0?!1:i,a=e.skipRedirect,c=a===void 0?!1:a,l=e.onComplete,f=e.onStateChange,s=e.utm,d=e.styles,p=e.prefill,b=e.themeOptions,w=e.hideSubmitButton,O=w===void 0?!1:w,k=e.hideTermsAndConditions,I=k===void 0?!1:k,W=e.hideEmail,x=W===void 0?!1:W,D=e.disableEmail,R=D===void 0?!1:D;var M=P(function(){return{accentColor:N(b===null||b===void 0?void 0:b.accentColor)?b.accentColor:void 0}},[b===null||b===void 0?void 0:b.accentColor]),T=_(t,n,o,void 0,u,c||!!l,s,d,p,M,O,I,x,R),U=C(null),V=m(A(480),2),z=V[0],B=V[1];return S(function(){var e=U.current;if(e)return y(e,function(r){switch(r.event){case"resize":{B(r.height);break}case"center":{e.scrollIntoView({block:"center",inline:"center"});break}case"complete":{l&&l(r.plan_id,r.receipt_id);break}case"state":{f&&f(r.state);break}}})},[l,f]),r&&(typeof r=="function"?r({submit:function(e){U.current&&g(U.current,e)},getEmail:function(e){if(!U.current)throw new Error("Whop embedded checkout frame not found");return v(U.current,e)},setEmail:function(e,r){if(!U.current)throw new Error("Whop embedded checkout frame not found");return h(U.current,e,r)}}):r.current={submit:function(e){U.current&&g(U.current,e)},getEmail:function(e){if(!U.current)throw new Error("Whop embedded checkout frame not found");return v(U.current,e)},setEmail:function(e,r){if(!U.current)throw new Error("Whop embedded checkout frame not found");return h(U.current,e,r)}}),j.createElement("iframe",{ref:U,allow:E,sandbox:Z,title:"Whop Embedded Checkout",src:T!==null&&T!==void 0?T:void 0,style:{border:"none",height:"".concat(z,"px"),width:"100%",overflow:"hidden"}})});B.displayName="WhopCheckoutEmbedInner";var K=k(function(e,r){var t=e.fallback,n=s(e,["fallback"]);return x()?j.createElement(B,f(c({},n),{ref:r})):t!==null&&t!==void 0?t:null});K.displayName="WhopCheckoutEmbed";import{useRef as $}from"react";function q(){return $(null)}export{K as WhopCheckoutEmbed,q as useCheckoutEmbedControls};