@stigg/react-sdk 7.12.0 → 7.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4967,7 +4967,7 @@ ${e.o5f}`,e.zBW=r.default`
4967
4967
  display: flex;
4968
4968
  flex-direction: column;
4969
4969
  align-items: center;
4970
- `,_S=({plans:t,customer:e,currentSubscription:n,highlightedPlanId:r,selectedBillingPeriod:i,onBillingPeriodChanged:o,availableBillingPeriods:s,isCustomerOnTrial:c,onPlanSelected:p,paywallLocale:h,locale:v,shouldHidePlan:P,selectDefaultTierIndex:x,currentSubscriptionOverride:T,hideCompatibleAddons:I,showWatermark:R})=>{let A=SS(t),O=t.some(Y=>!!Y.description),N=jb(t,be.Monthly),V=jb(t,be.Annually),G=ES(t,i,P),X=Bv.useCallback((Y,at,pt)=>p({plan:Y,customer:e,subscription:n,intentionType:at,selectedBillingPeriod:i,billableFeatures:pt}),[e,i,n,p]),nt=!!n&&n.plan.pricingType===Rn.Custom,st=Bv.useMemo(()=>G.some(Y=>{var dt;let at=Y.pricePoints.filter(mt=>mt.billingPeriod===i),pt=(dt=Y.paywallCalculatedPricePoints)==null?void 0:dt.find(mt=>mt.billingPeriod===i);return at.length>1&&!!(pt!=null&&pt.additionalChargesMayApply)}),[i,G]),U=Bv.useMemo(()=>G.some(Y=>!!um(Y,i,h,v,N).unit),[i,N,v,h,G]),j=Bv.useMemo(()=>!nt&&G.some(Y=>{let at=cm({plan:Y,billingPeriod:i,currentSubscription:n,currentSubscriptionOverride:T});return Object.values(at).length>0}),[i,n,T,nt,G]),ut=G.some(Y=>Y.isCurrentCustomerPlan&&Y.trialDaysLeft);return jsxRuntime.jsx(hA,{className:"stigg-paywall-container",children:jsxRuntime.jsxs(mA,{className:"stigg-paywall-layout",children:[jsxRuntime.jsx(yS,{onBillingPeriodChanged:o,selectedBillingPeriod:i,availableBillingPeriods:s,discountRate:A}),jsxRuntime.jsx(fA,{className:"stigg-paywall-plans-layout",children:G.map(Y=>jsxRuntime.jsx(mS,{withUnitPriceRow:U,withTiersRow:j,withTrialLeftRow:ut,shouldShowDescriptionSection:O,hasMonthlyPrice:N,hasAnnuallyPrice:V,plan:Y,withStartingAtRow:st,currentSubscription:n,currentSubscriptionOverride:T,billingPeriod:i,isHighlighted:Y.id===r,isCustomerOnTrial:c,onPlanSelected:(at,pt)=>X(Y,at,pt),paywallLocale:h,locale:v,customer:e,isCustomerInCustomPlan:nt,selectDefaultTierIndex:x,hideCompatibleAddons:I},Y.id))}),jsxRuntime.jsx(so,{source:"paywall",align:"end",style:{marginTop:16},showWatermark:R})]})})};var zb=class{error(e,n,...r){console.error(e,n||{},r);}log(e,n){console.log(e,n||{});}debug(e,n){console.debug(e,n||{});}},tl=new zb;function TS(t,e,n){let r=t.flatMap(c=>c.pricePoints).map(c=>c.billingPeriod),i=lodash.countBy(r),o=lodash.uniq(r),s;if(n&&o.includes(n))s=n;else if(e){let c=e.find(p=>p.status===bi.Active);c&&c.prices.length>0&&(s=c==null?void 0:c.prices[0].billingPeriod);}return s||(s=(i[be.Monthly]||0)>(i[be.Annually]||0)?be.Monthly:be.Annually),{defaultBillingPeriod:s,availableBillingPeriods:o}}function IS(t){return $1__default.default.utc(t).diff($1__default.default.utc(),"days",false)+1}var fm={h1:{fontSize:"24px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"16px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};function el(t,e="px"){if(t)return `${t}${e}`}function hm(t){if(!t)return "normal";switch(t){case gb.Normal:return "normal";case gb.Bold:return "bold";default:return "normal"}}function $p(t,e){var r,i,o,s,c,p,h,v;let n=e||{h1:{fontSize:"32px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"24px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};return {fontFamilyUrl:(t==null?void 0:t.fontFamily)||void 0,h1:{fontSize:el((r=t==null?void 0:t.h1)==null?void 0:r.fontSize)||n.h1.fontSize,fontWeight:hm((i=t==null?void 0:t.h1)==null?void 0:i.fontWeight)||n.h1.fontWeight,semanticElement:n.h1.semanticElement},h2:{fontSize:el((o=t==null?void 0:t.h2)==null?void 0:o.fontSize)||n.h2.fontSize,fontWeight:hm((s=t==null?void 0:t.h2)==null?void 0:s.fontWeight)||n.h2.fontWeight,semanticElement:n.h2.semanticElement},h3:{fontSize:el((c=t==null?void 0:t.h3)==null?void 0:c.fontSize)||n.h3.fontSize,fontWeight:hm((p=t==null?void 0:t.h3)==null?void 0:p.fontWeight)||n.h3.fontWeight,semanticElement:n.h3.semanticElement},body:{fontSize:el((h=t==null?void 0:t.body)==null?void 0:h.fontSize)||n.body.fontSize,fontWeight:hm((v=t==null?void 0:t.body)==null?void 0:v.fontWeight)||n.body.fontWeight,semanticElement:n.body.semanticElement}}}function Hb(t){if(t)switch(t){case Jh.Left:return "left";case Jh.Center:return "center";case Jh.Right:return "right";default:return}}function kS(t){let{palette:e,customCss:n,typography:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.paywallBackgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:$p(r),customCss:n||void 0}}function DS(t){let{palette:e,layout:n,customCss:r,typography:i}=t;return {customCss:r||void 0,palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:$p(i),layout:{ctaAlignment:Hb(n==null?void 0:n.alignment),headerAlignment:Hb(n==null?void 0:n.alignment),descriptionAlignment:Hb(n==null?void 0:n.alignment),planMaxWidth:el(n==null?void 0:n.planWidth),planMinWidth:el(n==null?void 0:n.planWidth),planMargin:el(n==null?void 0:n.planMargin),planPadding:el(n==null?void 0:n.planPadding)}}}function AS(t){let{palette:e,typography:n,customCss:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0},backgroundHighlight:(e==null?void 0:e.summaryBackgroundColor)||void 0},typography:$p(n,fm),customCss:r||void 0}}function CA(t){let e=true,n=(t==null?void 0:t.find(o=>o.status===bi.InTrial))||null,r=n==null?void 0:n.plan,i=n!=null&&n.trialEndDate?IS(n.trialEndDate):void 0;return r||(e=false,n=(t==null?void 0:t.find(o=>o.status===bi.Active))||null,r=n==null?void 0:n.plan),{currentSubscription:n,currentPlan:r,isCustomerOnTrial:e,trialDaysLeft:i}}function RS(t,e,n){var G,X;let{plans:r,currency:i,configuration:o,customer:s,activeSubscriptions:c,paywallCalculatedPricePoints:p}=t||{},{currentSubscription:h,currentPlan:v,isCustomerOnTrial:P,trialDaysLeft:x}=CA(c),T=n==null?void 0:n({currentSubscription:h}),I=(h==null?void 0:h.scheduledUpdates)||[],R=(G=h==null?void 0:h.price)==null?void 0:G.billingPeriod,A=I.find(({subscriptionScheduleType:nt})=>nt===Ui.Downgrade),O=I.find(({subscriptionScheduleType:nt})=>nt===Ui.BillingPeriod),N=px__default.default(r,nt=>nt.order).map(nt=>{var ut;let st=(ut=s==null?void 0:s.eligibleForTrial)==null?void 0:ut.find(Y=>Y.productId===nt.product.id),U=T!=null&&T.planId?(T==null?void 0:T.planId)===nt.id:nt.id===(v==null?void 0:v.id),j=Y=>{var mt;let at=A==null?void 0:A.scheduleVariables,pt=O==null?void 0:O.scheduleVariables,dt=nt.pricePoints.some(Ct=>Ct.billingPeriod===Y);return A?((mt=A.targetPackage)==null?void 0:mt.refId)===nt.id&&(!dt||at.billingPeriod===Y):O&&U?pt.billingPeriod===Y:false};return St(W({},nt),{paywallCalculatedPricePoints:p==null?void 0:p.filter(Y=>Y.planId===nt.id),isTriable:!lm__default.default(nt.defaultTrialConfig)&&(!st||st.eligible),isCurrentCustomerPlan:U,currentCustomerPlanBillingPeriod:R,isUpcomingPlan:false,trialDaysLeft:x,isNextPlan:j,paywallCurrency:i,scheduledUpdate:A||O})});if(r&&v){let nt=v&&((X=r==null?void 0:r.find(st=>st.id===(v==null?void 0:v.id)))==null?void 0:X.order);lm__default.default(nt)||(N=N.map(st=>St(W({},st),{isLowerThanCurrentPlan:nt>st.order})),e&&(N=N.filter(st=>st.order>=nt)));}let V=o?DS(o):void 0;return {currentPlan:v,currentSubscription:h,currentSubscriptionOverride:T,isCustomerOnTrial:P,plans:N,paywallConfiguration:V}}var MS="7.12.0";var NS="@stigg/react-sdk";var Gp=Bv__default.default.createContext(null);Gp.displayName="StiggContext";var _A="en-US",TA=({apiKey:t,baseUri:e,baseEdgeUri:n,enableEdge:r,customerId:i,customerToken:o,resourceId:s,theme:c,locale:p,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,entitlementsFallback:x,stiggClient:T,children:I,offline:R,clientName:A=NS,clientVersion:O=MS})=>{let N=Bv.useRef(t),V={apiKey:t,customerId:i,customerToken:o,resourceId:s,baseUri:e,baseEdgeUri:n,enableEdge:r,entitlementsFallback:x,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,clientName:A,clientVersion:O,offline:R},[G,X]=Bv.useState(()=>({stigg:T!=null?T:bb.initialize(St(W({},V),{lazyLoad:true})),locale:p||_A,isInitialized:false,theme:c,refreshData:()=>ce(null,null,function*(){X(nt=>St(W({},nt),{customerPortalUpdatedAt:new Date})),yield G.stigg.refresh();})}));return Bv.useEffect(()=>{let nt=true,st=Y=>{nt&&X(Y);},U=()=>st(Y=>St(W({},Y),{updatedAt:new Date})),j=Y=>st(at=>(at.stigg&&at.stigg.removeListener("entitlementsUpdated",U),Y.addListener("entitlementsUpdated",U),St(W({},at),{stigg:Y,isInitialized:true,updatedAt:new Date})));return ce(null,null,function*(){let Y=G.stigg;t!==N.current&&(tl.log("Updating stigg client",{apiKey:t}),N.current=t,Y=bb.initialize(W({},V)),st(at=>St(W({},at),{isInitialized:false,updatedAt:new Date}))),yield Y.waitForInitialization(),j(Y);}),()=>{nt=false,G.stigg.removeListener("entitlementsUpdated",U),G.stigg.clearCustomer();}},[t]),Bv.useEffect(()=>{let nt=G.stigg;i?nt.setCustomerId(i,o,s):nt.clearCustomer();},[i,o,s]),Bv.useEffect(()=>{X(nt=>St(W({},nt),{theme:c}));},[c]),jsxRuntime.jsx(Gp.Provider,{value:G,children:jsxRuntime.jsx(nl.SkeletonTheme,{baseColor:"#F5F6F9",highlightColor:"#e5e6ea",children:I})})};function ve(t){let{optional:e}=t||{},n=Bv.useContext(Gp);if(!n&&!e)throw new Error("Could not find Stigg context; You need to wrap your app in an <StiggProvider> component.");return n}function BS({productId:t,resourceId:e,showOnlyEligiblePlans:n,billingCountryCode:r,preferredBillingPeriod:i,currentSubscriptionOverrideFn:o}){let{stigg:s,locale:c}=ve(),[p,h]=Bv.useState(be.Annually),[v,P]=Bv.useState([]),[x,T]=Bv.useState(null),[I,R]=Bv.useState(true);Bv.useEffect(()=>{ce(null,null,function*(){try{R(!0),yield s.waitForInitialization();let N=yield s.getPaywall({productId:t,resourceId:e,billingCountryCode:r}),{availableBillingPeriods:V,defaultBillingPeriod:G}=TS(N.plans,N.activeSubscriptions,i);T(N),P(V),h(G);}catch(N){tl.error(`Failed to load paywall ${N==null?void 0:N.message}`,N);}finally{R(false);}});},[s,t,s.isCustomerLoaded,r,e,i]);let A=RS(x,n,o);return W({customer:(x==null?void 0:x.customer)||null,isLoading:I,selectedBillingPeriod:p,setSelectedBillingPeriod:h,availableBillingPeriods:v,locale:c,configuration:A.paywallConfiguration,showWatermark:s.getShowWatermark()},A)}function US(t){return zD__default.default({highlightChip:"Recommended",addonsTitle:"Available add-ons:",planCTAButton:{upgrade:"Upgrade",downgrade:"Downgrade",startTrial:n=>{var r;return `Start ${(r=n.defaultTrialConfig)==null?void 0:r.duration} day trial`},custom:"Contact us",currentPlan:"Current plan",startNew:"Get started",switchToBillingPeriod:n=>n===be.Monthly?"Switch to monthly billing":"Switch to annual billing",cancelScheduledUpdate:"Cancel"},price:{startingAtCaption:"Starts at",pricePeriod:n=>n===be.Monthly?"/ month":"/ year",free:n=>({price:`${n==null?void 0:n.symbol}0`}),custom:"Custom",priceNotSet:"Price not set"}},t)}var DA=t=>jsxRuntime.jsx("svg",St(W({width:15,height:11,viewBox:"0 0 15 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},t),{children:jsxRuntime.jsx("path",{d:"M5.59 7.9899L2.125 4.5249C1.73524 4.13514 1.10365 4.13402 0.712509 4.52241V4.52241C0.319409 4.91274 0.318286 5.54819 0.710005 5.9399L5.59 10.8199L14.2948 2.11513C14.6843 1.72565 14.6843 1.09417 14.2948 0.704691V0.704691C13.9055 0.315381 13.2743 0.315184 12.8848 0.70425L5.59 7.9899Z",fill:"#B2BBD3"})})),GS=DA;var AA=Q.div`
4970
+ `,_S=({plans:t,customer:e,currentSubscription:n,highlightedPlanId:r,selectedBillingPeriod:i,onBillingPeriodChanged:o,availableBillingPeriods:s,isCustomerOnTrial:c,onPlanSelected:p,paywallLocale:h,locale:v,shouldHidePlan:P,selectDefaultTierIndex:x,currentSubscriptionOverride:T,hideCompatibleAddons:I,showWatermark:R})=>{let A=SS(t),O=t.some(Y=>!!Y.description),N=jb(t,be.Monthly),V=jb(t,be.Annually),G=ES(t,i,P),X=Bv.useCallback((Y,at,pt)=>p({plan:Y,customer:e,subscription:n,intentionType:at,selectedBillingPeriod:i,billableFeatures:pt}),[e,i,n,p]),nt=!!n&&n.plan.pricingType===Rn.Custom,st=Bv.useMemo(()=>G.some(Y=>{var dt;let at=Y.pricePoints.filter(mt=>mt.billingPeriod===i),pt=(dt=Y.paywallCalculatedPricePoints)==null?void 0:dt.find(mt=>mt.billingPeriod===i);return at.length>1&&!!(pt!=null&&pt.additionalChargesMayApply)}),[i,G]),U=Bv.useMemo(()=>G.some(Y=>!!um(Y,i,h,v,N).unit),[i,N,v,h,G]),j=Bv.useMemo(()=>!nt&&G.some(Y=>{let at=cm({plan:Y,billingPeriod:i,currentSubscription:n,currentSubscriptionOverride:T});return Object.values(at).length>0}),[i,n,T,nt,G]),ut=G.some(Y=>Y.isCurrentCustomerPlan&&Y.trialDaysLeft);return jsxRuntime.jsx(hA,{className:"stigg-paywall-container",children:jsxRuntime.jsxs(mA,{className:"stigg-paywall-layout",children:[jsxRuntime.jsx(yS,{onBillingPeriodChanged:o,selectedBillingPeriod:i,availableBillingPeriods:s,discountRate:A}),jsxRuntime.jsx(fA,{className:"stigg-paywall-plans-layout",children:G.map(Y=>jsxRuntime.jsx(mS,{withUnitPriceRow:U,withTiersRow:j,withTrialLeftRow:ut,shouldShowDescriptionSection:O,hasMonthlyPrice:N,hasAnnuallyPrice:V,plan:Y,withStartingAtRow:st,currentSubscription:n,currentSubscriptionOverride:T,billingPeriod:i,isHighlighted:Y.id===r,isCustomerOnTrial:c,onPlanSelected:(at,pt)=>X(Y,at,pt),paywallLocale:h,locale:v,customer:e,isCustomerInCustomPlan:nt,selectDefaultTierIndex:x,hideCompatibleAddons:I},Y.id))}),jsxRuntime.jsx(so,{source:"paywall",align:"end",style:{marginTop:16},showWatermark:R})]})})};var zb=class{error(e,n,...r){console.error(e,n||{},r);}log(e,n){console.log(e,n||{});}debug(e,n){console.debug(e,n||{});}},tl=new zb;function TS(t,e,n){let r=t.flatMap(c=>c.pricePoints).map(c=>c.billingPeriod),i=lodash.countBy(r),o=lodash.uniq(r),s;if(n&&o.includes(n))s=n;else if(e){let c=e.find(p=>p.status===bi.Active);c&&c.prices.length>0&&(s=c==null?void 0:c.prices[0].billingPeriod);}return s||(s=(i[be.Monthly]||0)>(i[be.Annually]||0)?be.Monthly:be.Annually),{defaultBillingPeriod:s,availableBillingPeriods:o}}function IS(t){return $1__default.default.utc(t).diff($1__default.default.utc(),"days",false)+1}var fm={h1:{fontSize:"24px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"16px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};function el(t,e="px"){if(t)return `${t}${e}`}function hm(t){if(!t)return "normal";switch(t){case gb.Normal:return "normal";case gb.Bold:return "bold";default:return "normal"}}function $p(t,e){var r,i,o,s,c,p,h,v;let n=e||{h1:{fontSize:"32px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"24px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};return {fontFamilyUrl:(t==null?void 0:t.fontFamily)||void 0,h1:{fontSize:el((r=t==null?void 0:t.h1)==null?void 0:r.fontSize)||n.h1.fontSize,fontWeight:hm((i=t==null?void 0:t.h1)==null?void 0:i.fontWeight)||n.h1.fontWeight,semanticElement:n.h1.semanticElement},h2:{fontSize:el((o=t==null?void 0:t.h2)==null?void 0:o.fontSize)||n.h2.fontSize,fontWeight:hm((s=t==null?void 0:t.h2)==null?void 0:s.fontWeight)||n.h2.fontWeight,semanticElement:n.h2.semanticElement},h3:{fontSize:el((c=t==null?void 0:t.h3)==null?void 0:c.fontSize)||n.h3.fontSize,fontWeight:hm((p=t==null?void 0:t.h3)==null?void 0:p.fontWeight)||n.h3.fontWeight,semanticElement:n.h3.semanticElement},body:{fontSize:el((h=t==null?void 0:t.body)==null?void 0:h.fontSize)||n.body.fontSize,fontWeight:hm((v=t==null?void 0:t.body)==null?void 0:v.fontWeight)||n.body.fontWeight,semanticElement:n.body.semanticElement}}}function Hb(t){if(t)switch(t){case Jh.Left:return "left";case Jh.Center:return "center";case Jh.Right:return "right";default:return}}function kS(t){let{palette:e,customCss:n,typography:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.paywallBackgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:$p(r),customCss:n||void 0}}function DS(t){let{palette:e,layout:n,customCss:r,typography:i}=t;return {customCss:r||void 0,palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:$p(i),layout:{ctaAlignment:Hb(n==null?void 0:n.alignment),headerAlignment:Hb(n==null?void 0:n.alignment),descriptionAlignment:Hb(n==null?void 0:n.alignment),planMaxWidth:el(n==null?void 0:n.planWidth),planMinWidth:el(n==null?void 0:n.planWidth),planMargin:el(n==null?void 0:n.planMargin),planPadding:el(n==null?void 0:n.planPadding)}}}function AS(t){let{palette:e,typography:n,customCss:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0},backgroundHighlight:(e==null?void 0:e.summaryBackgroundColor)||void 0},typography:$p(n,fm),customCss:r||void 0}}function CA(t){let e=true,n=(t==null?void 0:t.find(o=>o.status===bi.InTrial))||null,r=n==null?void 0:n.plan,i=n!=null&&n.trialEndDate?IS(n.trialEndDate):void 0;return r||(e=false,n=(t==null?void 0:t.find(o=>o.status===bi.Active))||null,r=n==null?void 0:n.plan),{currentSubscription:n,currentPlan:r,isCustomerOnTrial:e,trialDaysLeft:i}}function RS(t,e,n){var G,X;let{plans:r,currency:i,configuration:o,customer:s,activeSubscriptions:c,paywallCalculatedPricePoints:p}=t||{},{currentSubscription:h,currentPlan:v,isCustomerOnTrial:P,trialDaysLeft:x}=CA(c),T=n==null?void 0:n({currentSubscription:h}),I=(h==null?void 0:h.scheduledUpdates)||[],R=(G=h==null?void 0:h.price)==null?void 0:G.billingPeriod,A=I.find(({subscriptionScheduleType:nt})=>nt===Ui.Downgrade),O=I.find(({subscriptionScheduleType:nt})=>nt===Ui.BillingPeriod),N=px__default.default(r,nt=>nt.order).map(nt=>{var ut;let st=(ut=s==null?void 0:s.eligibleForTrial)==null?void 0:ut.find(Y=>Y.productId===nt.product.id),U=T!=null&&T.planId?(T==null?void 0:T.planId)===nt.id:nt.id===(v==null?void 0:v.id),j=Y=>{var mt;let at=A==null?void 0:A.scheduleVariables,pt=O==null?void 0:O.scheduleVariables,dt=nt.pricePoints.some(Ct=>Ct.billingPeriod===Y);return A?((mt=A.targetPackage)==null?void 0:mt.refId)===nt.id&&(!dt||at.billingPeriod===Y):O&&U?pt.billingPeriod===Y:false};return St(W({},nt),{paywallCalculatedPricePoints:p==null?void 0:p.filter(Y=>Y.planId===nt.id),isTriable:!lm__default.default(nt.defaultTrialConfig)&&(!st||st.eligible),isCurrentCustomerPlan:U,currentCustomerPlanBillingPeriod:R,isUpcomingPlan:false,trialDaysLeft:x,isNextPlan:j,paywallCurrency:i,scheduledUpdate:A||O})});if(r&&v){let nt=v&&((X=r==null?void 0:r.find(st=>st.id===(v==null?void 0:v.id)))==null?void 0:X.order);lm__default.default(nt)||(N=N.map(st=>St(W({},st),{isLowerThanCurrentPlan:nt>st.order})),e&&(N=N.filter(st=>st.order>=nt)));}let V=o?DS(o):void 0;return {currentPlan:v,currentSubscription:h,currentSubscriptionOverride:T,isCustomerOnTrial:P,plans:N,paywallConfiguration:V}}var MS="7.12.1";var NS="@stigg/react-sdk";var Gp=Bv__default.default.createContext(null);Gp.displayName="StiggContext";var _A="en-US",TA=({apiKey:t,baseUri:e,baseEdgeUri:n,enableEdge:r,customerId:i,customerToken:o,resourceId:s,theme:c,locale:p,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,entitlementsFallback:x,stiggClient:T,children:I,offline:R,clientName:A=NS,clientVersion:O=MS})=>{let N=Bv.useRef(t),V={apiKey:t,customerId:i,customerToken:o,resourceId:s,baseUri:e,baseEdgeUri:n,enableEdge:r,entitlementsFallback:x,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,clientName:A,clientVersion:O,offline:R},[G,X]=Bv.useState(()=>({stigg:T!=null?T:bb.initialize(St(W({},V),{lazyLoad:true})),locale:p||_A,isInitialized:false,theme:c,refreshData:()=>ce(null,null,function*(){X(nt=>St(W({},nt),{customerPortalUpdatedAt:new Date})),yield G.stigg.refresh();})}));return Bv.useEffect(()=>{let nt=true,st=Y=>{nt&&X(Y);},U=()=>st(Y=>St(W({},Y),{updatedAt:new Date})),j=Y=>st(at=>(at.stigg&&at.stigg.removeListener("entitlementsUpdated",U),Y.addListener("entitlementsUpdated",U),St(W({},at),{stigg:Y,isInitialized:true,updatedAt:new Date})));return ce(null,null,function*(){let Y=G.stigg;t!==N.current&&(tl.log("Updating stigg client",{apiKey:t}),N.current=t,Y=bb.initialize(W({},V)),st(at=>St(W({},at),{isInitialized:false,updatedAt:new Date}))),yield Y.waitForInitialization(),j(Y);}),()=>{nt=false,G.stigg.removeListener("entitlementsUpdated",U),G.stigg.clearCustomer();}},[t]),Bv.useEffect(()=>{let nt=G.stigg;i?nt.setCustomerId(i,o,s):nt.clearCustomer();},[i,o,s]),Bv.useEffect(()=>{X(nt=>St(W({},nt),{theme:c}));},[c]),jsxRuntime.jsx(Gp.Provider,{value:G,children:jsxRuntime.jsx(nl.SkeletonTheme,{baseColor:"#F5F6F9",highlightColor:"#e5e6ea",children:I})})};function ve(t){let{optional:e}=t||{},n=Bv.useContext(Gp);if(!n&&!e)throw new Error("Could not find Stigg context; You need to wrap your app in an <StiggProvider> component.");return n}function BS({productId:t,resourceId:e,showOnlyEligiblePlans:n,billingCountryCode:r,preferredBillingPeriod:i,currentSubscriptionOverrideFn:o}){let{stigg:s,locale:c}=ve(),[p,h]=Bv.useState(be.Annually),[v,P]=Bv.useState([]),[x,T]=Bv.useState(null),[I,R]=Bv.useState(true);Bv.useEffect(()=>{ce(null,null,function*(){try{R(!0),yield s.waitForInitialization();let N=yield s.getPaywall({productId:t,resourceId:e,billingCountryCode:r}),{availableBillingPeriods:V,defaultBillingPeriod:G}=TS(N.plans,N.activeSubscriptions,i);T(N),P(V),h(G);}catch(N){tl.error(`Failed to load paywall ${N==null?void 0:N.message}`,N);}finally{R(false);}});},[s,t,s.isCustomerLoaded,r,e,i]);let A=RS(x,n,o);return W({customer:(x==null?void 0:x.customer)||null,isLoading:I,selectedBillingPeriod:p,setSelectedBillingPeriod:h,availableBillingPeriods:v,locale:c,configuration:A.paywallConfiguration,showWatermark:s.getShowWatermark()},A)}function US(t){return zD__default.default({highlightChip:"Recommended",addonsTitle:"Available add-ons:",planCTAButton:{upgrade:"Upgrade",downgrade:"Downgrade",startTrial:n=>{var r;return `Start ${(r=n.defaultTrialConfig)==null?void 0:r.duration} day trial`},custom:"Contact us",currentPlan:"Current plan",startNew:"Get started",switchToBillingPeriod:n=>n===be.Monthly?"Switch to monthly billing":"Switch to annual billing",cancelScheduledUpdate:"Cancel"},price:{startingAtCaption:"Starts at",pricePeriod:n=>n===be.Monthly?"/ month":"/ year",free:n=>({price:`${n==null?void 0:n.symbol}0`}),custom:"Custom",priceNotSet:"Price not set"}},t)}var DA=t=>jsxRuntime.jsx("svg",St(W({width:15,height:11,viewBox:"0 0 15 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},t),{children:jsxRuntime.jsx("path",{d:"M5.59 7.9899L2.125 4.5249C1.73524 4.13514 1.10365 4.13402 0.712509 4.52241V4.52241C0.319409 4.91274 0.318286 5.54819 0.710005 5.9399L5.59 10.8199L14.2948 2.11513C14.6843 1.72565 14.6843 1.09417 14.2948 0.704691V0.704691C13.9055 0.315381 13.2743 0.315184 12.8848 0.70425L5.59 7.9899Z",fill:"#B2BBD3"})})),GS=DA;var AA=Q.div`
4971
4971
  display: flex;
4972
4972
  flex-direction: column;
4973
4973
  align-items: center;
@@ -4967,7 +4967,7 @@ ${e.o5f}`,e.zBW=r.default`
4967
4967
  display: flex;
4968
4968
  flex-direction: column;
4969
4969
  align-items: center;
4970
- `,_S=({plans:t,customer:e,currentSubscription:n,highlightedPlanId:r,selectedBillingPeriod:i,onBillingPeriodChanged:o,availableBillingPeriods:s,isCustomerOnTrial:c,onPlanSelected:p,paywallLocale:h,locale:v,shouldHidePlan:P,selectDefaultTierIndex:x,currentSubscriptionOverride:T,hideCompatibleAddons:I,showWatermark:R})=>{let A=SS(t),O=t.some(Y=>!!Y.description),N=jb(t,be.Monthly),V=jb(t,be.Annually),G=ES(t,i,P),X=useCallback((Y,at,pt)=>p({plan:Y,customer:e,subscription:n,intentionType:at,selectedBillingPeriod:i,billableFeatures:pt}),[e,i,n,p]),nt=!!n&&n.plan.pricingType===Rn.Custom,st=useMemo(()=>G.some(Y=>{var dt;let at=Y.pricePoints.filter(mt=>mt.billingPeriod===i),pt=(dt=Y.paywallCalculatedPricePoints)==null?void 0:dt.find(mt=>mt.billingPeriod===i);return at.length>1&&!!(pt!=null&&pt.additionalChargesMayApply)}),[i,G]),U=useMemo(()=>G.some(Y=>!!um(Y,i,h,v,N).unit),[i,N,v,h,G]),j=useMemo(()=>!nt&&G.some(Y=>{let at=cm({plan:Y,billingPeriod:i,currentSubscription:n,currentSubscriptionOverride:T});return Object.values(at).length>0}),[i,n,T,nt,G]),ut=G.some(Y=>Y.isCurrentCustomerPlan&&Y.trialDaysLeft);return jsx(hA,{className:"stigg-paywall-container",children:jsxs(mA,{className:"stigg-paywall-layout",children:[jsx(yS,{onBillingPeriodChanged:o,selectedBillingPeriod:i,availableBillingPeriods:s,discountRate:A}),jsx(fA,{className:"stigg-paywall-plans-layout",children:G.map(Y=>jsx(mS,{withUnitPriceRow:U,withTiersRow:j,withTrialLeftRow:ut,shouldShowDescriptionSection:O,hasMonthlyPrice:N,hasAnnuallyPrice:V,plan:Y,withStartingAtRow:st,currentSubscription:n,currentSubscriptionOverride:T,billingPeriod:i,isHighlighted:Y.id===r,isCustomerOnTrial:c,onPlanSelected:(at,pt)=>X(Y,at,pt),paywallLocale:h,locale:v,customer:e,isCustomerInCustomPlan:nt,selectDefaultTierIndex:x,hideCompatibleAddons:I},Y.id))}),jsx(so,{source:"paywall",align:"end",style:{marginTop:16},showWatermark:R})]})})};var zb=class{error(e,n,...r){console.error(e,n||{},r);}log(e,n){console.log(e,n||{});}debug(e,n){console.debug(e,n||{});}},tl=new zb;function TS(t,e,n){let r=t.flatMap(c=>c.pricePoints).map(c=>c.billingPeriod),i=countBy(r),o=uniq(r),s;if(n&&o.includes(n))s=n;else if(e){let c=e.find(p=>p.status===bi.Active);c&&c.prices.length>0&&(s=c==null?void 0:c.prices[0].billingPeriod);}return s||(s=(i[be.Monthly]||0)>(i[be.Annually]||0)?be.Monthly:be.Annually),{defaultBillingPeriod:s,availableBillingPeriods:o}}function IS(t){return $1.utc(t).diff($1.utc(),"days",false)+1}var fm={h1:{fontSize:"24px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"16px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};function el(t,e="px"){if(t)return `${t}${e}`}function hm(t){if(!t)return "normal";switch(t){case gb.Normal:return "normal";case gb.Bold:return "bold";default:return "normal"}}function $p(t,e){var r,i,o,s,c,p,h,v;let n=e||{h1:{fontSize:"32px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"24px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};return {fontFamilyUrl:(t==null?void 0:t.fontFamily)||void 0,h1:{fontSize:el((r=t==null?void 0:t.h1)==null?void 0:r.fontSize)||n.h1.fontSize,fontWeight:hm((i=t==null?void 0:t.h1)==null?void 0:i.fontWeight)||n.h1.fontWeight,semanticElement:n.h1.semanticElement},h2:{fontSize:el((o=t==null?void 0:t.h2)==null?void 0:o.fontSize)||n.h2.fontSize,fontWeight:hm((s=t==null?void 0:t.h2)==null?void 0:s.fontWeight)||n.h2.fontWeight,semanticElement:n.h2.semanticElement},h3:{fontSize:el((c=t==null?void 0:t.h3)==null?void 0:c.fontSize)||n.h3.fontSize,fontWeight:hm((p=t==null?void 0:t.h3)==null?void 0:p.fontWeight)||n.h3.fontWeight,semanticElement:n.h3.semanticElement},body:{fontSize:el((h=t==null?void 0:t.body)==null?void 0:h.fontSize)||n.body.fontSize,fontWeight:hm((v=t==null?void 0:t.body)==null?void 0:v.fontWeight)||n.body.fontWeight,semanticElement:n.body.semanticElement}}}function Hb(t){if(t)switch(t){case Jh.Left:return "left";case Jh.Center:return "center";case Jh.Right:return "right";default:return}}function kS(t){let{palette:e,customCss:n,typography:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.paywallBackgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:$p(r),customCss:n||void 0}}function DS(t){let{palette:e,layout:n,customCss:r,typography:i}=t;return {customCss:r||void 0,palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:$p(i),layout:{ctaAlignment:Hb(n==null?void 0:n.alignment),headerAlignment:Hb(n==null?void 0:n.alignment),descriptionAlignment:Hb(n==null?void 0:n.alignment),planMaxWidth:el(n==null?void 0:n.planWidth),planMinWidth:el(n==null?void 0:n.planWidth),planMargin:el(n==null?void 0:n.planMargin),planPadding:el(n==null?void 0:n.planPadding)}}}function AS(t){let{palette:e,typography:n,customCss:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0},backgroundHighlight:(e==null?void 0:e.summaryBackgroundColor)||void 0},typography:$p(n,fm),customCss:r||void 0}}function CA(t){let e=true,n=(t==null?void 0:t.find(o=>o.status===bi.InTrial))||null,r=n==null?void 0:n.plan,i=n!=null&&n.trialEndDate?IS(n.trialEndDate):void 0;return r||(e=false,n=(t==null?void 0:t.find(o=>o.status===bi.Active))||null,r=n==null?void 0:n.plan),{currentSubscription:n,currentPlan:r,isCustomerOnTrial:e,trialDaysLeft:i}}function RS(t,e,n){var G,X;let{plans:r,currency:i,configuration:o,customer:s,activeSubscriptions:c,paywallCalculatedPricePoints:p}=t||{},{currentSubscription:h,currentPlan:v,isCustomerOnTrial:P,trialDaysLeft:x}=CA(c),T=n==null?void 0:n({currentSubscription:h}),I=(h==null?void 0:h.scheduledUpdates)||[],R=(G=h==null?void 0:h.price)==null?void 0:G.billingPeriod,A=I.find(({subscriptionScheduleType:nt})=>nt===Ui.Downgrade),O=I.find(({subscriptionScheduleType:nt})=>nt===Ui.BillingPeriod),N=px(r,nt=>nt.order).map(nt=>{var ut;let st=(ut=s==null?void 0:s.eligibleForTrial)==null?void 0:ut.find(Y=>Y.productId===nt.product.id),U=T!=null&&T.planId?(T==null?void 0:T.planId)===nt.id:nt.id===(v==null?void 0:v.id),j=Y=>{var mt;let at=A==null?void 0:A.scheduleVariables,pt=O==null?void 0:O.scheduleVariables,dt=nt.pricePoints.some(Ct=>Ct.billingPeriod===Y);return A?((mt=A.targetPackage)==null?void 0:mt.refId)===nt.id&&(!dt||at.billingPeriod===Y):O&&U?pt.billingPeriod===Y:false};return St(W({},nt),{paywallCalculatedPricePoints:p==null?void 0:p.filter(Y=>Y.planId===nt.id),isTriable:!lm(nt.defaultTrialConfig)&&(!st||st.eligible),isCurrentCustomerPlan:U,currentCustomerPlanBillingPeriod:R,isUpcomingPlan:false,trialDaysLeft:x,isNextPlan:j,paywallCurrency:i,scheduledUpdate:A||O})});if(r&&v){let nt=v&&((X=r==null?void 0:r.find(st=>st.id===(v==null?void 0:v.id)))==null?void 0:X.order);lm(nt)||(N=N.map(st=>St(W({},st),{isLowerThanCurrentPlan:nt>st.order})),e&&(N=N.filter(st=>st.order>=nt)));}let V=o?DS(o):void 0;return {currentPlan:v,currentSubscription:h,currentSubscriptionOverride:T,isCustomerOnTrial:P,plans:N,paywallConfiguration:V}}var MS="7.12.0";var NS="@stigg/react-sdk";var Gp=Bv.createContext(null);Gp.displayName="StiggContext";var _A="en-US",TA=({apiKey:t,baseUri:e,baseEdgeUri:n,enableEdge:r,customerId:i,customerToken:o,resourceId:s,theme:c,locale:p,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,entitlementsFallback:x,stiggClient:T,children:I,offline:R,clientName:A=NS,clientVersion:O=MS})=>{let N=useRef(t),V={apiKey:t,customerId:i,customerToken:o,resourceId:s,baseUri:e,baseEdgeUri:n,enableEdge:r,entitlementsFallback:x,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,clientName:A,clientVersion:O,offline:R},[G,X]=useState(()=>({stigg:T!=null?T:bb.initialize(St(W({},V),{lazyLoad:true})),locale:p||_A,isInitialized:false,theme:c,refreshData:()=>ce(null,null,function*(){X(nt=>St(W({},nt),{customerPortalUpdatedAt:new Date})),yield G.stigg.refresh();})}));return useEffect(()=>{let nt=true,st=Y=>{nt&&X(Y);},U=()=>st(Y=>St(W({},Y),{updatedAt:new Date})),j=Y=>st(at=>(at.stigg&&at.stigg.removeListener("entitlementsUpdated",U),Y.addListener("entitlementsUpdated",U),St(W({},at),{stigg:Y,isInitialized:true,updatedAt:new Date})));return ce(null,null,function*(){let Y=G.stigg;t!==N.current&&(tl.log("Updating stigg client",{apiKey:t}),N.current=t,Y=bb.initialize(W({},V)),st(at=>St(W({},at),{isInitialized:false,updatedAt:new Date}))),yield Y.waitForInitialization(),j(Y);}),()=>{nt=false,G.stigg.removeListener("entitlementsUpdated",U),G.stigg.clearCustomer();}},[t]),useEffect(()=>{let nt=G.stigg;i?nt.setCustomerId(i,o,s):nt.clearCustomer();},[i,o,s]),useEffect(()=>{X(nt=>St(W({},nt),{theme:c}));},[c]),jsx(Gp.Provider,{value:G,children:jsx(SkeletonTheme,{baseColor:"#F5F6F9",highlightColor:"#e5e6ea",children:I})})};function ve(t){let{optional:e}=t||{},n=useContext(Gp);if(!n&&!e)throw new Error("Could not find Stigg context; You need to wrap your app in an <StiggProvider> component.");return n}function BS({productId:t,resourceId:e,showOnlyEligiblePlans:n,billingCountryCode:r,preferredBillingPeriod:i,currentSubscriptionOverrideFn:o}){let{stigg:s,locale:c}=ve(),[p,h]=useState(be.Annually),[v,P]=useState([]),[x,T]=useState(null),[I,R]=useState(true);useEffect(()=>{ce(null,null,function*(){try{R(!0),yield s.waitForInitialization();let N=yield s.getPaywall({productId:t,resourceId:e,billingCountryCode:r}),{availableBillingPeriods:V,defaultBillingPeriod:G}=TS(N.plans,N.activeSubscriptions,i);T(N),P(V),h(G);}catch(N){tl.error(`Failed to load paywall ${N==null?void 0:N.message}`,N);}finally{R(false);}});},[s,t,s.isCustomerLoaded,r,e,i]);let A=RS(x,n,o);return W({customer:(x==null?void 0:x.customer)||null,isLoading:I,selectedBillingPeriod:p,setSelectedBillingPeriod:h,availableBillingPeriods:v,locale:c,configuration:A.paywallConfiguration,showWatermark:s.getShowWatermark()},A)}function US(t){return zD({highlightChip:"Recommended",addonsTitle:"Available add-ons:",planCTAButton:{upgrade:"Upgrade",downgrade:"Downgrade",startTrial:n=>{var r;return `Start ${(r=n.defaultTrialConfig)==null?void 0:r.duration} day trial`},custom:"Contact us",currentPlan:"Current plan",startNew:"Get started",switchToBillingPeriod:n=>n===be.Monthly?"Switch to monthly billing":"Switch to annual billing",cancelScheduledUpdate:"Cancel"},price:{startingAtCaption:"Starts at",pricePeriod:n=>n===be.Monthly?"/ month":"/ year",free:n=>({price:`${n==null?void 0:n.symbol}0`}),custom:"Custom",priceNotSet:"Price not set"}},t)}var DA=t=>jsx("svg",St(W({width:15,height:11,viewBox:"0 0 15 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},t),{children:jsx("path",{d:"M5.59 7.9899L2.125 4.5249C1.73524 4.13514 1.10365 4.13402 0.712509 4.52241V4.52241C0.319409 4.91274 0.318286 5.54819 0.710005 5.9399L5.59 10.8199L14.2948 2.11513C14.6843 1.72565 14.6843 1.09417 14.2948 0.704691V0.704691C13.9055 0.315381 13.2743 0.315184 12.8848 0.70425L5.59 7.9899Z",fill:"#B2BBD3"})})),GS=DA;var AA=Q.div`
4970
+ `,_S=({plans:t,customer:e,currentSubscription:n,highlightedPlanId:r,selectedBillingPeriod:i,onBillingPeriodChanged:o,availableBillingPeriods:s,isCustomerOnTrial:c,onPlanSelected:p,paywallLocale:h,locale:v,shouldHidePlan:P,selectDefaultTierIndex:x,currentSubscriptionOverride:T,hideCompatibleAddons:I,showWatermark:R})=>{let A=SS(t),O=t.some(Y=>!!Y.description),N=jb(t,be.Monthly),V=jb(t,be.Annually),G=ES(t,i,P),X=useCallback((Y,at,pt)=>p({plan:Y,customer:e,subscription:n,intentionType:at,selectedBillingPeriod:i,billableFeatures:pt}),[e,i,n,p]),nt=!!n&&n.plan.pricingType===Rn.Custom,st=useMemo(()=>G.some(Y=>{var dt;let at=Y.pricePoints.filter(mt=>mt.billingPeriod===i),pt=(dt=Y.paywallCalculatedPricePoints)==null?void 0:dt.find(mt=>mt.billingPeriod===i);return at.length>1&&!!(pt!=null&&pt.additionalChargesMayApply)}),[i,G]),U=useMemo(()=>G.some(Y=>!!um(Y,i,h,v,N).unit),[i,N,v,h,G]),j=useMemo(()=>!nt&&G.some(Y=>{let at=cm({plan:Y,billingPeriod:i,currentSubscription:n,currentSubscriptionOverride:T});return Object.values(at).length>0}),[i,n,T,nt,G]),ut=G.some(Y=>Y.isCurrentCustomerPlan&&Y.trialDaysLeft);return jsx(hA,{className:"stigg-paywall-container",children:jsxs(mA,{className:"stigg-paywall-layout",children:[jsx(yS,{onBillingPeriodChanged:o,selectedBillingPeriod:i,availableBillingPeriods:s,discountRate:A}),jsx(fA,{className:"stigg-paywall-plans-layout",children:G.map(Y=>jsx(mS,{withUnitPriceRow:U,withTiersRow:j,withTrialLeftRow:ut,shouldShowDescriptionSection:O,hasMonthlyPrice:N,hasAnnuallyPrice:V,plan:Y,withStartingAtRow:st,currentSubscription:n,currentSubscriptionOverride:T,billingPeriod:i,isHighlighted:Y.id===r,isCustomerOnTrial:c,onPlanSelected:(at,pt)=>X(Y,at,pt),paywallLocale:h,locale:v,customer:e,isCustomerInCustomPlan:nt,selectDefaultTierIndex:x,hideCompatibleAddons:I},Y.id))}),jsx(so,{source:"paywall",align:"end",style:{marginTop:16},showWatermark:R})]})})};var zb=class{error(e,n,...r){console.error(e,n||{},r);}log(e,n){console.log(e,n||{});}debug(e,n){console.debug(e,n||{});}},tl=new zb;function TS(t,e,n){let r=t.flatMap(c=>c.pricePoints).map(c=>c.billingPeriod),i=countBy(r),o=uniq(r),s;if(n&&o.includes(n))s=n;else if(e){let c=e.find(p=>p.status===bi.Active);c&&c.prices.length>0&&(s=c==null?void 0:c.prices[0].billingPeriod);}return s||(s=(i[be.Monthly]||0)>(i[be.Annually]||0)?be.Monthly:be.Annually),{defaultBillingPeriod:s,availableBillingPeriods:o}}function IS(t){return $1.utc(t).diff($1.utc(),"days",false)+1}var fm={h1:{fontSize:"24px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"16px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};function el(t,e="px"){if(t)return `${t}${e}`}function hm(t){if(!t)return "normal";switch(t){case gb.Normal:return "normal";case gb.Bold:return "bold";default:return "normal"}}function $p(t,e){var r,i,o,s,c,p,h,v;let n=e||{h1:{fontSize:"32px",fontWeight:"bold",semanticElement:"h1"},h2:{fontSize:"24px",fontWeight:"normal",semanticElement:"h2"},h3:{fontSize:"16px",fontWeight:"normal",semanticElement:"h3"},body:{fontSize:"14px",fontWeight:"normal",semanticElement:"p"}};return {fontFamilyUrl:(t==null?void 0:t.fontFamily)||void 0,h1:{fontSize:el((r=t==null?void 0:t.h1)==null?void 0:r.fontSize)||n.h1.fontSize,fontWeight:hm((i=t==null?void 0:t.h1)==null?void 0:i.fontWeight)||n.h1.fontWeight,semanticElement:n.h1.semanticElement},h2:{fontSize:el((o=t==null?void 0:t.h2)==null?void 0:o.fontSize)||n.h2.fontSize,fontWeight:hm((s=t==null?void 0:t.h2)==null?void 0:s.fontWeight)||n.h2.fontWeight,semanticElement:n.h2.semanticElement},h3:{fontSize:el((c=t==null?void 0:t.h3)==null?void 0:c.fontSize)||n.h3.fontSize,fontWeight:hm((p=t==null?void 0:t.h3)==null?void 0:p.fontWeight)||n.h3.fontWeight,semanticElement:n.h3.semanticElement},body:{fontSize:el((h=t==null?void 0:t.body)==null?void 0:h.fontSize)||n.body.fontSize,fontWeight:hm((v=t==null?void 0:t.body)==null?void 0:v.fontWeight)||n.body.fontWeight,semanticElement:n.body.semanticElement}}}function Hb(t){if(t)switch(t){case Jh.Left:return "left";case Jh.Center:return "center";case Jh.Right:return "right";default:return}}function kS(t){let{palette:e,customCss:n,typography:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.paywallBackgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:$p(r),customCss:n||void 0}}function DS(t){let{palette:e,layout:n,customCss:r,typography:i}=t;return {customCss:r||void 0,palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,backgroundHighlight:(e==null?void 0:e.currentPlanBackground)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0}},typography:$p(i),layout:{ctaAlignment:Hb(n==null?void 0:n.alignment),headerAlignment:Hb(n==null?void 0:n.alignment),descriptionAlignment:Hb(n==null?void 0:n.alignment),planMaxWidth:el(n==null?void 0:n.planWidth),planMinWidth:el(n==null?void 0:n.planWidth),planMargin:el(n==null?void 0:n.planMargin),planPadding:el(n==null?void 0:n.planPadding)}}}function AS(t){let{palette:e,typography:n,customCss:r}=t;return {palette:{primary:(e==null?void 0:e.primary)||void 0,backgroundPaper:(e==null?void 0:e.backgroundColor)||void 0,outlinedBorder:(e==null?void 0:e.borderColor)||void 0,text:{primary:(e==null?void 0:e.textColor)||void 0},backgroundHighlight:(e==null?void 0:e.summaryBackgroundColor)||void 0},typography:$p(n,fm),customCss:r||void 0}}function CA(t){let e=true,n=(t==null?void 0:t.find(o=>o.status===bi.InTrial))||null,r=n==null?void 0:n.plan,i=n!=null&&n.trialEndDate?IS(n.trialEndDate):void 0;return r||(e=false,n=(t==null?void 0:t.find(o=>o.status===bi.Active))||null,r=n==null?void 0:n.plan),{currentSubscription:n,currentPlan:r,isCustomerOnTrial:e,trialDaysLeft:i}}function RS(t,e,n){var G,X;let{plans:r,currency:i,configuration:o,customer:s,activeSubscriptions:c,paywallCalculatedPricePoints:p}=t||{},{currentSubscription:h,currentPlan:v,isCustomerOnTrial:P,trialDaysLeft:x}=CA(c),T=n==null?void 0:n({currentSubscription:h}),I=(h==null?void 0:h.scheduledUpdates)||[],R=(G=h==null?void 0:h.price)==null?void 0:G.billingPeriod,A=I.find(({subscriptionScheduleType:nt})=>nt===Ui.Downgrade),O=I.find(({subscriptionScheduleType:nt})=>nt===Ui.BillingPeriod),N=px(r,nt=>nt.order).map(nt=>{var ut;let st=(ut=s==null?void 0:s.eligibleForTrial)==null?void 0:ut.find(Y=>Y.productId===nt.product.id),U=T!=null&&T.planId?(T==null?void 0:T.planId)===nt.id:nt.id===(v==null?void 0:v.id),j=Y=>{var mt;let at=A==null?void 0:A.scheduleVariables,pt=O==null?void 0:O.scheduleVariables,dt=nt.pricePoints.some(Ct=>Ct.billingPeriod===Y);return A?((mt=A.targetPackage)==null?void 0:mt.refId)===nt.id&&(!dt||at.billingPeriod===Y):O&&U?pt.billingPeriod===Y:false};return St(W({},nt),{paywallCalculatedPricePoints:p==null?void 0:p.filter(Y=>Y.planId===nt.id),isTriable:!lm(nt.defaultTrialConfig)&&(!st||st.eligible),isCurrentCustomerPlan:U,currentCustomerPlanBillingPeriod:R,isUpcomingPlan:false,trialDaysLeft:x,isNextPlan:j,paywallCurrency:i,scheduledUpdate:A||O})});if(r&&v){let nt=v&&((X=r==null?void 0:r.find(st=>st.id===(v==null?void 0:v.id)))==null?void 0:X.order);lm(nt)||(N=N.map(st=>St(W({},st),{isLowerThanCurrentPlan:nt>st.order})),e&&(N=N.filter(st=>st.order>=nt)));}let V=o?DS(o):void 0;return {currentPlan:v,currentSubscription:h,currentSubscriptionOverride:T,isCustomerOnTrial:P,plans:N,paywallConfiguration:V}}var MS="7.12.1";var NS="@stigg/react-sdk";var Gp=Bv.createContext(null);Gp.displayName="StiggContext";var _A="en-US",TA=({apiKey:t,baseUri:e,baseEdgeUri:n,enableEdge:r,customerId:i,customerToken:o,resourceId:s,theme:c,locale:p,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,entitlementsFallback:x,stiggClient:T,children:I,offline:R,clientName:A=NS,clientVersion:O=MS})=>{let N=useRef(t),V={apiKey:t,customerId:i,customerToken:o,resourceId:s,baseUri:e,baseEdgeUri:n,enableEdge:r,entitlementsFallback:x,cacheTtlMs:h,useEntitlementPolling:v,entitlementPollingInterval:P,clientName:A,clientVersion:O,offline:R},[G,X]=useState(()=>({stigg:T!=null?T:bb.initialize(St(W({},V),{lazyLoad:true})),locale:p||_A,isInitialized:false,theme:c,refreshData:()=>ce(null,null,function*(){X(nt=>St(W({},nt),{customerPortalUpdatedAt:new Date})),yield G.stigg.refresh();})}));return useEffect(()=>{let nt=true,st=Y=>{nt&&X(Y);},U=()=>st(Y=>St(W({},Y),{updatedAt:new Date})),j=Y=>st(at=>(at.stigg&&at.stigg.removeListener("entitlementsUpdated",U),Y.addListener("entitlementsUpdated",U),St(W({},at),{stigg:Y,isInitialized:true,updatedAt:new Date})));return ce(null,null,function*(){let Y=G.stigg;t!==N.current&&(tl.log("Updating stigg client",{apiKey:t}),N.current=t,Y=bb.initialize(W({},V)),st(at=>St(W({},at),{isInitialized:false,updatedAt:new Date}))),yield Y.waitForInitialization(),j(Y);}),()=>{nt=false,G.stigg.removeListener("entitlementsUpdated",U),G.stigg.clearCustomer();}},[t]),useEffect(()=>{let nt=G.stigg;i?nt.setCustomerId(i,o,s):nt.clearCustomer();},[i,o,s]),useEffect(()=>{X(nt=>St(W({},nt),{theme:c}));},[c]),jsx(Gp.Provider,{value:G,children:jsx(SkeletonTheme,{baseColor:"#F5F6F9",highlightColor:"#e5e6ea",children:I})})};function ve(t){let{optional:e}=t||{},n=useContext(Gp);if(!n&&!e)throw new Error("Could not find Stigg context; You need to wrap your app in an <StiggProvider> component.");return n}function BS({productId:t,resourceId:e,showOnlyEligiblePlans:n,billingCountryCode:r,preferredBillingPeriod:i,currentSubscriptionOverrideFn:o}){let{stigg:s,locale:c}=ve(),[p,h]=useState(be.Annually),[v,P]=useState([]),[x,T]=useState(null),[I,R]=useState(true);useEffect(()=>{ce(null,null,function*(){try{R(!0),yield s.waitForInitialization();let N=yield s.getPaywall({productId:t,resourceId:e,billingCountryCode:r}),{availableBillingPeriods:V,defaultBillingPeriod:G}=TS(N.plans,N.activeSubscriptions,i);T(N),P(V),h(G);}catch(N){tl.error(`Failed to load paywall ${N==null?void 0:N.message}`,N);}finally{R(false);}});},[s,t,s.isCustomerLoaded,r,e,i]);let A=RS(x,n,o);return W({customer:(x==null?void 0:x.customer)||null,isLoading:I,selectedBillingPeriod:p,setSelectedBillingPeriod:h,availableBillingPeriods:v,locale:c,configuration:A.paywallConfiguration,showWatermark:s.getShowWatermark()},A)}function US(t){return zD({highlightChip:"Recommended",addonsTitle:"Available add-ons:",planCTAButton:{upgrade:"Upgrade",downgrade:"Downgrade",startTrial:n=>{var r;return `Start ${(r=n.defaultTrialConfig)==null?void 0:r.duration} day trial`},custom:"Contact us",currentPlan:"Current plan",startNew:"Get started",switchToBillingPeriod:n=>n===be.Monthly?"Switch to monthly billing":"Switch to annual billing",cancelScheduledUpdate:"Cancel"},price:{startingAtCaption:"Starts at",pricePeriod:n=>n===be.Monthly?"/ month":"/ year",free:n=>({price:`${n==null?void 0:n.symbol}0`}),custom:"Custom",priceNotSet:"Price not set"}},t)}var DA=t=>jsx("svg",St(W({width:15,height:11,viewBox:"0 0 15 11",fill:"none",xmlns:"http://www.w3.org/2000/svg"},t),{children:jsx("path",{d:"M5.59 7.9899L2.125 4.5249C1.73524 4.13514 1.10365 4.13402 0.712509 4.52241V4.52241C0.319409 4.91274 0.318286 5.54819 0.710005 5.9399L5.59 10.8199L14.2948 2.11513C14.6843 1.72565 14.6843 1.09417 14.2948 0.704691V0.704691C13.9055 0.315381 13.2743 0.315184 12.8848 0.70425L5.59 7.9899Z",fill:"#B2BBD3"})})),GS=DA;var AA=Q.div`
4971
4971
  display: flex;
4972
4972
  flex-direction: column;
4973
4973
  align-items: center;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.12.0",
2
+ "version": "7.12.1",
3
3
  "license": "MIT",
4
4
  "main": "dist/stigg-sdk.cjs.js",
5
5
  "types": "dist/index.d.ts",