@tinkerlandai/longplay-sdk 0.10.26-rc.1 → 0.10.26

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.
@@ -1 +1 @@
1
- import{a as Ue,c as un}from"./chunk-JGG4R75K.js";import{d as sn,f as De,g as Ve,h as an,i as Me,k as ln}from"./chunk-CNIBGSVO.js";import{$ as _e}from"./chunk-PMCGTXGH.js";import{a as Le,e as en,f as nn,g as tn,h as rn,i as on}from"./chunk-PWQ5BHBJ.js";import{b as Xe}from"./chunk-HMRIMJ5W.js";import{R as Ye,qa as Ze}from"./chunk-5RXU57I5.js";import{a as I}from"./chunk-X7G7JMZ3.js";import{b as dn,e as pn}from"./chunk-SLUA7ABW.js";import{d as cn}from"./chunk-4IJU33UM.js";import{a as oe}from"./chunk-DSPLGTQI.js";import{b as Ke}from"./chunk-O4KXODTJ.js";var Ee=new WeakMap;function Dn(n){let v=n.view,m=v?.paywall?.resolution;if(!v||!["running","waiting"].includes(v.status)||v.stopped||!m||"document"in m||!n.resolvePaywall||n.identitySignal?.aborted)return;let e=JSON.stringify(m);if(Ee.get(n)?.key===e)return;let f=JSON.parse(e),P=n.identitySignal,r=Promise.resolve().then(async()=>{P?.throwIfAborted();let o=await n.resolvePaywall(f);return P?.throwIfAborted(),o}),R={key:e,content:r};return Ee.set(n,R),r.catch(()=>{}),()=>{Ee.get(n)===R&&Ee.delete(n)}}function fn(n,v){let m=Ee.get(n);return Ee.delete(n),m?.key===JSON.stringify(v)?m.content:n.resolvePaywall(v)}async function mn(n){let{session:v,load:m}=En(n);try{return await m(),v}catch(e){throw v.destroy(),e}}function En(n){let v=n.view;if(!v?.paywall)throw new I("INVALID_REQUEST","The current node is not a Paywall");let m=v.paywall.receiptId,e=v.nodeId,f=v.visit,P=v.paywall.resolution,r=v.paywall,R="document"in P?{document:P.document,offering:P.offering,capabilities:P.capabilities}:null;function o(){let i=r.resolution;return"document"in i?i:R&&{...i,document:R.document,offering:R.offering,capabilities:en(i.capabilities,R.capabilities)}}function y(i){if(!nn(i,P))throw new I("INVALID_RESPONSE","The pinned Paywall binding changed")}let d=!1,q=new Set,_=null;function T(){let i=o();if(i&&!d)for(let p of q)oe(p,structuredClone(i))}async function D(){U();let i=o();if(i)return structuredClone(i);if(!_){let p=(async()=>{if("document"in r.resolution||!n.resolvePaywall)throw new I("INVALID_RESPONSE","Public Paywall reader is unavailable");let b=await fn(n,r.resolution);return U(),y(b),R={document:b.document,offering:b.offering,capabilities:b.capabilities},T(),o()})();_=p;let a=()=>{_===p&&(_=null)};p.then(a,a)}return _.then(p=>structuredClone(p))}let c=new AbortController,O=(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).find(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===f&&i.input.type==="paywall_quote")?.requestId??v.paywall.purchaseRequestId,G=0,M=null,F=new Set,j=null,w=new Map;function A(i){if(i.purchase&&i.purchase.receiptId!==m)throw new I("INVALID_RESPONSE","Purchase receipt changed");let p=i.run.paywall;return i.purchase??(p?.receiptId===m?p:null)}function U(){if(d)throw new I("IDENTITY_CHANGED","Paywall presentation has closed")}function X(i,p,a){if(U(),p!==G||a!==void 0&&r.quote?.operationId!==a)return!1;let b=r.selectionGeneration??0,u=i.run.paywall;if(u?.receiptId===m){if((u.selectionGeneration??0)<(r.selectionGeneration??0))return!1;y(u.resolution)}let h=A(i),Q=u?.receiptId===m&&(u.selectionGeneration??0)>b,J=Q?h?.quote??null:h?.quote??r.quote,K=h?.operation??(J?.operationId===r.quote?.operationId?r.operation:null);return J&&K&&tn(K,{operationId:J.operationId},"Purchase operation changed"),(Q||J?.operationId!==r.quote?.operationId)&&(G++,u?.receiptId===m&&(O=u.purchaseRequestId)),r={...r,...u?.receiptId===m?u:{},quote:J,operation:on(r.operation,K,!0)},T(),!0}function k(i,p,a){return new Promise((b,u)=>{let h=!1,Q=()=>{clearTimeout(ye),c.signal.removeEventListener("abort",W)},J=ae=>{h||(h=!0,Q(),b(ae))},K=ae=>{h||(h=!0,Q(),u(ae))},W=()=>K(new I("IDENTITY_CHANGED","Paywall presentation has closed")),ye=setTimeout(()=>K(new I("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,a)),Math.max(0,p-Date.now()));c.signal.addEventListener("abort",W,{once:!0}),c.signal.aborted&&W(),i.then(J,K)})}function x(i){return new Promise(p=>{let a=()=>{clearTimeout(b),c.signal.removeEventListener("abort",a),p()},b=setTimeout(a,i);c.signal.addEventListener("abort",a,{once:!0}),c.signal.aborted&&a()})}function L(i,p){U();let a=w.get(i)??n.pendingCommands?.find(h=>h.requestId===i)??n.pendingCommand;if(a?.operation==="submit"&&a.requestId===i&&a.nodeId===e&&a.visit===f){p.type==="paywall_quote"&&a.input.type==="paywall_quote"&&a.input.predecessor&&!p.predecessor&&(p={...p,predecessor:a.input.predecessor});let h=_e.parse(a),Q=_e.parse({...a,input:p});if(h.operation!=="submit"||Q.operation!=="submit"||JSON.stringify(h.input)!==JSON.stringify(Q.input))throw new I("CONFLICT","A purchase request cannot change its input");return w.set(i,h),h}let b=n.view;if(!b||b.nodeId!==e||b.visit!==f||b.paywall?.receiptId!==m)throw new I("PRECONDITION_FAILED","The Paywall visit has changed");let u=_e.parse({operation:"submit",requestId:i,nodeId:e,visit:f,revision:b.revision,input:structuredClone(p)});if(u.operation!=="submit")throw new I("INVALID_REQUEST","A purchase submission is required");return w.set(i,u),u}async function se(i,p){U();let{requestId:a,input:b}=i,u=Date.now()+3e4;F.add(a);try{let h=await k(n.submit(i),u,a);for(;h.run.pendingRequest?.requestId===a&&Date.now()<u&&!d&&(await x(Math.min(1e3,u-Date.now())),!(d||Date.now()>=u));)h=await k(n.resume(a),u,a);if(d)throw new I("IDENTITY_CHANGED","Paywall presentation has closed");if(h.run.pendingRequest?.requestId===a)throw new I("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,a);if(!X(h,p,b.type==="paywall_confirm"||b.type==="paywall_cancel"?b.operationId:void 0))throw new I("PRECONDITION_FAILED","The purchase selection has changed");j===a&&(j=null)}catch(h){throw j=a,h instanceof I&&h.code==="COMMAND_PENDING"&&h.status===void 0&&w.delete(a),h}finally{F.delete(a)}}async function C(i){if(!r.quote)throw new I("INVALID_REQUEST","A quoted purchase is required");let p=i==="confirm"?"paywall_confirm":"paywall_cancel",a=[...w.values(),...n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])].find(u=>u.operation==="submit"&&u.input.type===p&&"operationId"in u.input&&u.input.operationId===r.quote.operationId),b=a?.operation==="submit"&&a.input.type===p&&"operationId"in a.input&&a.input.operationId===r.quote.operationId?a.requestId:crypto.randomUUID();if(await se(L(b,{type:i==="confirm"?"paywall_confirm":"paywall_cancel",operationId:r.quote.operationId}),G),!r.operation)throw new I("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(r.operation)}let S={get view(){return structuredClone(o())},get quote(){return r.quote?structuredClone(r.quote):null},get operation(){return r.operation?structuredClone(r.operation):null},get webViewUrl(){return n.webViewUrl},get canReselect(){return r.canReselect===!0},get recovery(){let i=n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[]),p=n.pendingPurchase;if(p&&(p.receiptId!==m||p.operationId!==r.quote?.operationId))return{type:"recover",operationId:p.operationId,requestId:i[0]?.requestId??null};let a=Le({quote:r.quote,operation:r.operation,requestId:i[0]?.requestId??j??O,pending:F.size>0||i.length>0||j!==null,destroyed:d,canReselect:r.canReselect});return a.type==="recover"&&a.requestId===null&&!d&&n.hasDurableJournal===!0&&!r.quote&&!r.operation&&(r.selectionGeneration??0)===0&&!p&&!i.length&&!F.size&&!O?{type:"native",operationId:null}:a},get pendingCancellation(){return!d&&(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).some(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===f&&i.input.type==="paywall_cancel"&&i.input.operationId===r.quote?.operationId)},subscribe(i){return d?()=>{}:(q.add(i),()=>q.delete(i))},async refresh(){U();let i=G,p=await n.get();if(X(p,i),p.run.paywall?.receiptId!==m)throw new I("PRECONDITION_FAILED","Paywall presentation has changed");return D()},preview(i){let p=o();if(!p)return Promise.reject(new I("PRECONDITION_FAILED","Load the Paywall presentation first"));if(O&&O!==i.requestId&&(M||r.canReselect!==!0))return Promise.reject(new I("COMMAND_PENDING","Retry the original purchase before starting another"));let a=p.document.buttons[i.actionId],b=a?.type==="checkout"?Xe(a.product,i.selection,p.capabilities):null;if(!b)return Promise.reject(new I("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let u=Ze(p.document.screen,b,i.selection,p.capabilities),h=O!==i.requestId&&(r.selectionGeneration??0)>0?{operationId:r.quote?.operationId??null,generation:r.selectionGeneration??0}:void 0;if(h&&r.canReselect!==!0)return Promise.reject(new I("COMMAND_PENDING","Original purchase requires authoritative termination"));let Q;try{Q=L(i.requestId,{type:"paywall_quote",actionId:i.actionId,productVersionId:b,...Object.keys(u).length?{featureQuantities:u}:{},...h?{predecessor:h}:{},...i.offerId?{offerId:i.offerId}:{},...i.nativeOffer?{nativeOffer:i.nativeOffer}:{}})}catch(W){return Promise.reject(W)}if(O===i.requestId&&M)return M;O!==i.requestId&&G++;let J=G;O=i.requestId;let K=(async()=>{if(await se(Q,J),!r.quote)throw new I("INVALID_RESPONSE","The accepted quote is missing");return rn(r.quote,{productVersionId:b,featureQuantities:u},"The selected purchase changed"),structuredClone(r.quote)})();return M=K,K.then(()=>{M===K&&(M=null)},W=>{M===K&&(M=null),O===i.requestId&&n.pendingCommand?.requestId!==i.requestId&&W instanceof I&&W.status!==void 0&&W.status<500&&![401,425].includes(W.status)&&(O=null)}),K},confirm:()=>C("confirm"),cancel:()=>C("cancel"),async read(){if(U(),!r.quote)throw new I("INVALID_REQUEST","A quoted purchase is required");let i=r.quote.operationId,p=G,a=n.pendingCommands?.find(J=>J.operation==="submit"&&(J.input.type==="paywall_confirm"||J.input.type==="paywall_cancel")&&J.input.operationId===i)??n.pendingCommand;a?.operation==="submit"&&(a.input.type==="paywall_confirm"||a.input.type==="paywall_cancel")&&a.input.operationId===i&&await n.settle?.(a.requestId);let b=await n.get(void 0,{receiptId:m,operationId:i});U();let u=A(b);if(u?.quote&&u.quote.operationId!==i||u?.operation&&u.operation.operationId!==i)throw new I("INVALID_RESPONSE","Purchase operation changed");let h=X(b,p,i),Q=h?r.operation:u?.operation;if(!Q)throw new I("INVALID_RESPONSE","The current purchase result is missing");return h&&F.size===0&&!(n.pendingCommands?.length??(n.pendingCommand?1:0))&&(j=null),structuredClone(Q)},destroy(){d=!0,ne(),q.clear(),c.abort(),w.clear()}},ne=n.subscribe(i=>{d||i.nodeId!==e||i.visit!==f||i.paywall?.receiptId!==m||(i.paywall.selectionGeneration??0)<(r.selectionGeneration??0)||(y(i.paywall.resolution),r={...r,resolution:i.paywall.resolution},T())});return{session:S,load:D}}function wn(n){let v=new Set,m=new Set,e=null;async function f(o,y){let d=!1;for(;!n.stopped&&n.key===o&&n.client.pendingCommand?.requestId===y;){if(!n.client.settle)throw new I("COMMAND_PENDING","The original display acknowledgement is still pending");await n.client.settle(y),d=!0,n.client.pendingCommand?.requestId===y&&await new Promise(q=>setTimeout(q,1500))}n.stopped||n.key!==o||(d&&await n.client.get(),!(n.stopped||n.key!==o)&&v.add(o))}function P(o,y){e=y;let d=()=>{e===y&&(e=null),m.delete(o)};return y.then(d,q=>{d(),n.busy||n.fail(q)}),y}function r(o){if(n.reviewing||v.has(o)||m.has(o)||n.stopped)return;m.add(o);let y=async()=>{if(n.reviewing||n.stopped||n.key!==o||v.has(o)){m.delete(o);return}if(n.busy||n.client.pendingCommand){setTimeout(()=>{y()},250);return}let d=(async()=>{if(n.staleRead){if(await n.staleRead,n.stopped||n.key!==o)return;if(n.client.pendingCommand){setTimeout(()=>{y()},250);return}}let q=n.client.view,_=n.expected(),T=_.requestId;try{await n.client.submit({operation:"shown",..._})}catch(D){if(!(D instanceof I)||D.code!=="CONFLICT"||D.status!==409||n.client.pendingCommand)throw D;await n.client.get();let c=n.client.view;if(n.stopped||n.reviewing||n.key!==o||!c||!q||c.id!==q.id||c.source.versionId!==q.source.versionId||c.nodeId!==_.nodeId||c.visit!==_.visit||c.revision<=_.revision||c.stopped||!c.screen&&(!c.paywall||c.paywall.receiptId!==q.paywall?.receiptId)||!["running","waiting"].includes(c.status)||n.client.pendingCommand)throw D;let N=n.expected();T=N.requestId,await n.client.submit({operation:"shown",...N})}await f(o,T)})();P(o,d)};y()}function R(){if(e)return e;let o=n.client.pendingCommand;if(o?.operation!=="shown")return null;let y=n.key;return m.add(y),P(y,(async()=>{await n.client.retry(),await f(y,o.requestId)})())}return{report:r,settled:R,get inFlight(){return e}}}function yn(n){let v={},m=new Map;async function e(f){let P=n.client.view,r=P?.screen,R=r?.customerData.nodes[f.nodeId];if(n.stopped||n.busy||!P||!r||!R)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(f.action)){let D=n.document,c=D?Ye(D,f.nodeId):null,N=c?.type==="customer_data"?c.data.outputs?.[f.action]:void 0;N&&r.outputs.includes(N)?await n.perform(()=>n.client.submit({operation:"submit",...n.expected(),input:{type:"screen",output:N,answers:n.answers,selection:f.value?{[f.nodeId]:f.value}:{}}})):await n.onIntent?.(f,P);return}let y=f.action.startsWith("sources_")?R.resources.find(D=>D.key===f.value):null;if(f.action.startsWith("sources_")&&!y)throw new I("INVALID_REQUEST","Choose a current resource");let d=`${P.visit}:${f.nodeId}:${y?.key??""}`,q=m.get(d)??[null],T=v[f.nodeId]??{page:1,after:null,filter:"all",...y?{resourceKey:y.key}:{}};if(f.action==="filter"){let D=f.value;if(!D||!(R.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(D))throw new I("INVALID_REQUEST","Unknown data filter");T={page:1,after:null,filter:D},q.splice(0,q.length,null)}else if(f.action==="next"||f.action==="sources_next"){let D=y?.sources.at(-1),c=y?D?{kind:"ledger",cursor:{at:D.detail[0],id:D.id,type:"source"}}:null:r.dataCursors[f.nodeId];if(!c||!y&&!R.hasNext)return;q[T.page]=c,T={...T,page:T.page+1,after:c}}else if(f.action==="previous"||f.action==="sources_previous"){if(T.page<=1)return;T={...T,page:T.page-1,after:q[T.page-2]??null}}m.set(d,q),v={...v,[f.nodeId]:T},await n.perform(()=>n.client.get({nodeId:P.nodeId,visit:P.visit,revision:P.revision,components:v}))}return{get queries(){return v},intent:e,reset(){v={},m.clear()}}}function gn(n){let{doc:v,holder:m,reviewHolder:e,mountScreenPreview:f}=n,P=!1,r,R=0,o=null,y="",d,q=new Map,_=c=>c?`${c.id}:${c.nodeId}:${c.visit}:${c.revision}:${c.paywall?.quote?.operationId??""}`:"";async function T(c){if(n.stopped||!n.client.review||P&&c===r&&d?.active)return;let N=!P||c!==r;P||(y=_(n.client.view),q.set(y,structuredClone(n.answers))),P=!0,r=c,m.hidden=!0,n.suspend(!0),e.hidden=!1;let O=++R;N&&(d?.finish("dismissed"),o?.destroy(),o=null,e.replaceChildren(),d=Ve(e,n.loadingOptions,"funnel",()=>{D()}));let G=N?d:void 0;try{if(G?.start(!1,n.client.view?.locale),O!==R||n.stopped)return;let M=n.client.review(c),F=await(G?.wait(M,De)??M);if(n.stopped||O!==R||!P)return;if(!F.review)throw new I("INVALID_RESPONSE","Historical projection is missing");o?.destroy(),o=null,G||e.replaceChildren();let j=v.createElement("div"),w=G?Me(j,e):()=>{};e.append(j);let A=F.run.locale.startsWith("zh"),U=v.createElement("p");U.textContent=A?"\u53EA\u8BFB\u56DE\u770B":"Read-only history",j.append(U);for(let[k,x]of F.review.pages.entries()){let L=v.createElement("button");L.type="button",L.textContent=A?`\u7B2C ${k+1} \u9875`:`Page ${k+1}`,L.onclick=()=>{T(x.receiptId)},j.append(L)}if(F.review.page){let k=F.review.page,x=v.createElement("div");x.inert=!0,j.append(x),o=f(x,{mode:"live",rendererUrl:n.client.webViewUrl,title:k.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{O===R&&!n.stopped&&G?.present(w)},onError:se=>{if(O!==R||n.stopped)return;let C=new Error(se);G?.finish("error",C),o?.destroy(),o=null,j.remove(),n.fail(C)},onEscape:()=>{D()}});let L=o;if(L.update(k.document,F.run.locale,{serverInput:{bindings:k.inputs,answers:k.answers,values:k.values}}),await L.ready,n.stopped||O!==R||!P)return}let X=A?{issued:"\u5DF2\u9886\u53D6",reserved:"\u5DF2\u9884\u7559",redeemed:"\u5DF2\u4F7F\u7528",expired:"\u5DF2\u8FC7\u671F",revoked:"\u5DF2\u64A4\u9500",unknown:"\u72B6\u6001\u5F85\u786E\u8BA4"}:{issued:"Issued",reserved:"Reserved",redeemed:"Used",expired:"Expired",revoked:"Revoked",unknown:"Status unconfirmed"};for(let k of[...F.review.coupons.map((x,L)=>`${A?"\u4F18\u60E0\u5238":"Coupon"} ${L+1}: ${X[x.status]}`),...F.review.purchases.map((x,L)=>`${A?"\u8D2D\u4E70":"Purchase"} ${L+1}: ${un(x.status,A)}`)]){let x=v.createElement("p");x.textContent=k,j.append(x)}F.review.page||G?.present(w),n.client.view&&await n.enqueue(n.client.view)}catch(M){if(O!==R||n.stopped)return;G?.finish("error",M),o?.destroy(),o=null,e.replaceChildren(),n.fail(M)}}async function D(){if(!P||n.stopped||!n.client.review)return;let c=++R;d?.finish("dismissed");try{if(await n.client.review(),n.stopped||c!==R)return;P=!1,R++,d?.finish("dismissed"),o?.destroy(),o=null,e.replaceChildren(),e.hidden=!0,m.hidden=!1;let N=n.client.view;_(N)!==y?(q.set(y,structuredClone(n.answers)),n.resetScreen()):(q.delete(y),n.suspend(!1)),N&&await n.enqueue(N)}catch(N){if(c!==R||n.stopped)return;o?.destroy(),o=null,e.replaceChildren(),n.fail(N)}}return{get active(){return P},get receipt(){return r},open:T,exit:D,get drafts(){return new Map([...q].map(([c,N])=>[c,structuredClone(N)]))},stop(){P=!1,R++,d?.finish("dismissed"),o?.destroy(),o=null,e.replaceChildren(),e.hidden=!0,m.hidden=!1}}}function vn(n){if(!n.client.pageExperiments)throw new Error("The Run controller does not support page experiments");let v=n.client.pageExperiments.bind(n.client),m=!1,e=!1,f=0,P=!1,r=!1,R="",o=()=>{let w=n.client.view;return JSON.stringify([w?.id,w?.source.versionId,w?.visit,w?.revision,w?.status,w?.stopped])},y=new Map,d=new Set,q={},_=new Map,T=dn(n.appManifestRelease),D=()=>{for(let w of y.values())w.effect.revert();y.clear()},c=()=>{D();for(let w of _.values())w();_.clear()};function N(w){if(m||d.has(w))return;d.add(w);let A=f;v(n.appManifestRelease,[w]).catch(U=>{d.delete(w),!m&&A===f&&oe(n.onError,U)})}async function O(){if(m)return;R=o();let w=n.client.view;if(!w||w.stopped||!["running","waiting"].includes(w.status)){f++,c();return}if(document.visibilityState==="hidden")return;if(P){r=!0;return}P=!0;let A=++f,U=`${w.id}:${w.visit}:${w.revision}`,X=location.href;try{let[k,{applyVisualVariation:x}]=await Promise.all([v(n.appManifestRelease),import("./visual-dom-5LUN4AHO.js")]),L=n.client.view;if(m||A!==f||!L||L.stopped||!["running","waiting"].includes(L.status)||`${L.id}:${L.visit}:${L.revision}`!==U||location.href!==X)return;let se=new Set,C=new Set;for(let S of k.assignments){let ne=`${k.payload.environmentId}:${S.experimentKey}`;if(C.add(ne),_.has(ne)||_.set(ne,pn(ne,q)),!!S.inExperiment)for(let i of k.payload.experiments){if(i.key!==S.experimentKey||!Ke(location.href,i.urlPatterns??[]))continue;let p=i.meta?.findIndex(J=>J.key===S.variationKey)??-1,a=i.variations[p];if(!a?.renderGuard)continue;let b=S.receiptId+":"+i.changeId,u=JSON.stringify([S.variationKey,a]);se.add(b);let h=y.get(b);if(h?.signature===u){h.effect.applied&&N(S.receiptId);continue}y.get(b)?.effect.revert(),y.delete(b);let Q=x(a,{requireUniqueTargets:!0,boundVariations:i.variations,allowJs:!1,onApplied:()=>N(S.receiptId),onError:J=>oe(n.onError,J)});y.set(b,{signature:u,effect:Q}),Q.applied&&N(S.receiptId)}}for(let[S,ne]of y)se.has(S)||(ne.effect.revert(),y.delete(S));for(let[S,ne]of _)C.has(S)||(ne(),_.delete(S))}catch(k){A===f&&c(),!m&&A===f&&oe(n.onError,k)}finally{P=!1,r&&!m&&(r=!1,O())}}let G=n.client.subscribe(()=>{if(o()===R)return;R=o(),f++;let w=n.client.view;(!w||w.stopped||!["running","waiting"].includes(w.status))&&c(),e&&O()}),M=cn(()=>{f++,c(),e&&O()}),F=()=>{f++,D()};document.addEventListener("visibilitychange",F);let j=Ue({document,run:async()=>{e&&await O()},delay:()=>e&&!m?15e3:void 0});return{async start(){e||m||(e=!0,await j.refresh())},refresh:O,destroy(){m=!0,f++,j.destroy(),document.removeEventListener("visibilitychange",F),G(),M(),c(),T.destroy()}}}var ze=5e3;async function qn(n,v,m){let e=v,[{mountScreenPreview:f},{showPaywall:P}]=await Promise.all([import("./screen-renderer-G2EWN3WB.js"),import("./paywall-54WX5YUZ.js")]),r=e.client.identitySignal;e.signal?.throwIfAborted(),r?.throwIfAborted();let R=e.appManifestRelease?vn({client:e.client,appManifestRelease:e.appManifestRelease,onError:e.onError}):void 0;R?.start();let o=n.ownerDocument,y=ln(o),d=o.createElement("section"),q=o.createElement("div"),_=o.createElement("div"),T=o.createElement("div"),D=o.createElement("button");T.hidden=!0,D.type="button";let c=o.createElement("p"),N=o.createElement("p"),O=o.createElement("button"),G=o.createElement("button"),M=o.createElement("button"),F=o.createElement("dialog"),j;d.dataset.indianaFunnel="",d.setAttribute("aria-busy","false"),d.style.cssText="box-sizing:border-box;width:100%;min-width:0;font:14px/1.5 system-ui,sans-serif;color:#172033;background:#fff",_.style.cssText="display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding:12px 20px",c.setAttribute("role","status"),N.setAttribute("role","alert"),N.hidden=!0,O.type=G.type=M.type="button",_.append(O,c,N,M,D,G),d.append(q,T,_),n.append(d);let w=null,A=null,U=null,X="",k="",x="",L="",se="",C=!1,S=0,ne=!1,i="",p=null,a=Promise.resolve(),b=!e.client.view,u=m,h,Q,J="",K,W=!1,ye=null,ae=!1,Fe=()=>e.client.pendingCommand?.operation==="close",re=null,B=null,je=Ue({document:o,run:async()=>{(!A?.observing||e.client.pendingCommand)&&await He()},delay:()=>{if(!(C||!U||!["running","waiting"].includes(U.status)&&!e.client.pendingCommand)&&!(A?.observing&&!e.client.pendingCommand))return U.pendingRequest||e.client.pendingCommand?1500:ze},hiddenDelay:()=>!C&&e.client.pendingCommand?15e3:void 0}),Y=null;function $e(){return B&&e.client.hasDurableJournal===!0&&Y?.acknowledged===!0&&Y.operationId===B.operationId&&e.client.view?.id===Y.runId&&e.client.view?.status==="closed"&&e.client.view.revision===Y.revision+1&&!(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0))&&!e.client.pendingPurchase?B:null}function xe(t){let s=t.run.paywall;if(Y&&t.settlement?.requestId===Y.requestId&&t.settlement.state==="settled"&&t.settlement.operationId===null&&t.run.id===Y.runId&&t.run.status==="closed"&&!t.run.pendingRequest&&t.run.revision===Y.revision+1&&t.run.nodeId===Y.nodeId&&t.run.visit===Y.visit&&s?.receiptId===Y.receiptId&&s.selectionGeneration===Y.selectionGeneration&&(s.quote?.operationId??null)===Y.operationId&&(s.operation?.operationId??s.quote?.operationId??null)===Y.operationId){let l=Y.operationId===null&&s.selectionGeneration===0&&!s.quote&&!s.operation&&!s.purchaseRequestId,te=Le({quote:s.quote,operation:s.operation,requestId:s.purchaseRequestId,pending:!1,destroyed:!1,canReselect:s.canReselect});(l||s.canReselect===!0&&te.type==="native")&&(Y.acknowledged=!0)}}let Ce=null,ke=new Set,pe={},le=(t,s=null)=>{C||(Ce=s,N.textContent=t instanceof Error?t.message:"Request failed",N.hidden=!1,M.hidden=e.client.pendingCommand===null,oe(e.onError,t))};function he(){let t=e.client.view;if(!t)throw new I("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision}}let V=gn({client:e.client,doc:o,holder:q,reviewHolder:T,mountScreenPreview:f,loadingOptions:e,get stopped(){return C},get answers(){return pe},suspend(t){A?.setSuspended(t)},resetScreen(){X="",k="",x=""},enqueue:fe,fail:le}),Se=wn({client:e.client,expected:he,fail:le,get stopped(){return C},get reviewing(){return V.active},get key(){return X},get busy(){return S},get staleRead(){return p}}),Ne=yn({client:e.client,expected:he,perform:Re,onIntent:e.onCustomerDataIntent,get stopped(){return C},get busy(){return S},get document(){return w?.document},get answers(){return pe}}),Oe=t=>`${t.id}:${t.nodeId}:${t.visit}`,Pe=t=>t&&(t.screen||t.paywall)?Oe(t):"";function Ie(){let t=e.client.view;O.disabled=!V.active&&(S>0||!!e.client.pendingCommand||!t?.canBack||t.stopped||!["running","waiting"].includes(t.status)||!Pe(t)||k!==Pe(t))}async function We(t){if(!t)return;let s=e.client.view;await t;let l=e.client.view;if(!s||!l||l.id!==s.id||l.nodeId!==s.nodeId||l.visit!==s.visit||l.stopped||!["running","waiting"].includes(l.status))throw new I("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}async function Re(t,s=!1){if(!((S||ae||re||B)&&!s||C||V.active&&!s)){S++,d.setAttribute("aria-busy","true"),Ie(),N.hidden=!0,Ce=null;try{if(s||await We(Se.inFlight),C)return;let l=await t();C||await fe(e.client.view??l.run)}catch(l){le(l,e.client.pendingCommand?.requestId??null)}finally{S=Math.max(0,S-1),d.setAttribute("aria-busy",String(S>0)),C||(M.hidden=e.client.pendingCommand===null,Ie())}}}function qe(){je.schedule()}async function He(){if(!(C||ne||S)){if(V.active){await V.open(V.receipt);return}ne=!0;try{let t=e.client.pendingCommand;t&&e.client.settle&&await e.client.settle(t.requestId);let s=e.client.view,l=Ne.queries,te=await e.client.get(s?.screen&&Object.keys(l).length?{nodeId:s.nodeId,visit:s.visit,revision:s.revision,components:l}:void 0);!C&&l===Ne.queries&&await fe(e.client.view??te.run)}catch(t){le(t)}finally{ne=!1}}}function Ae(t,s){if(u?.active){let te=u;return te.setDismissHandler(()=>Be(te)),te}let l=Ve(n,e,"funnel",()=>Be(l));return u=l,l.start(t,s),l}function Be(t){C||W||(W=!0,t.finish("dismissed"),ge(),d.hidden=!0,e.client.view?be().finally(ue):ue())}function Ge(){clearTimeout(K?.timeout),K=void 0}function ge(){Ge(),h?.abort(),h=void 0,w?.destroy(),w=null,A?.destroy(),A=null,Q?.(),Q=void 0,F.open&&F.close(),q.replaceChildren(),X="",k="",x="",se=""}function Qe(t){let s=t.screen?.presentation;if(!s||s.type==="inline"){F.open&&F.close(),d.parentElement!==n&&n.append(d);return}d.parentElement!==F&&(F.append(d),n.append(F));let l={sm:420,md:640,lg:900};F.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in s?l[s.size]+"px":"100vw"}`,F.setAttribute("aria-label",(j?.screen===t.screen?.content.document.name?j?.label:void 0)??w?.document?.name??t.screen?.content.document.name??"Funnel")}async function hn(t){if(C||W||ae&&(Fe()||["running","waiting"].includes(t.status)))return;U=t,Ce&&e.client.pendingCommand?.requestId!==Ce&&(N.hidden=!0,Ce=null);let s=t.locale.startsWith("zh");if(D.textContent=s?"\u56DE\u770B":"History",D.hidden=!e.client.review,O.textContent=V.active?s?"\u8FD4\u56DE\u5F53\u524D":"Return to current":s?"\u8FD4\u56DE":"Back",G.textContent=s?"\u5173\u95ED":"Close",M.textContent=s?"\u91CD\u8BD5":"Retry",Ie(),M.hidden=e.client.pendingCommand===null,c.textContent=t.pendingRequest?s?"\u6B63\u5728\u5904\u7406":"Processing":t.instruction?.type==="wait"?s?"\u7B49\u5F85\u4E2D":"Waiting":"",i!==`${t.revision}:${t.visit}:${t.status}:${t.stopped}`&&(i=`${t.revision}:${t.visit}:${t.status}:${t.stopped}`,oe(e.onState,structuredClone(t))),C||W)return;if((!t.pendingRequest||ae&&t.status==="closed")&&["closed","ineligible","failed"].includes(t.status)){ue();return}if(t.stopped||e.client.configurationReady===!1){V.stop(),ge(),u?.finish("skipped"),d.hidden=!0,qe();return}if(d.hidden=!1,V.active){qe();return}let l=Pe(t),te=e.client.view;if(te&&te.revision>t.revision&&Pe(te)!==l)return;let Je=!t.instruction&&!t.pendingRequest&&t.nodeType==="screen"&&["running","waiting"].includes(t.status);l!==X&&(X&&u?.finish("dismissed"),ge(),X=l,pe={...t.answers},Ne.reset());let me=Oe(t);if(J===me){d.hidden=!0;return}if(Je&&!l){d.hidden=!0;let E=Ae(!0,t.locale);!C&&!W&&K?.key!==me&&(Ge(),K={key:me,timeout:setTimeout(()=>{let g=e.client.view;if(!E.active||!g||Oe(g)!==me)return;J=me;let ee=new Error("Funnel screen preparation timed out");E.finish("error",ee),ge(),le(ee)},De)}),qe();return}Ge();let ie=E=>{let g=e.client.view;return!C&&!W&&!ye&&!E.aborted&&e.client.configurationReady!==!1&&!!g&&!g.stopped&&!["closed","ineligible","failed"].includes(g.status)&&Pe(g)===l},Z=(E,g)=>{ie(g)&&(J=l,u?.finish("error",E),ge(),d.hidden=!0,le(E))};if(l||(Qe(t),t.instruction?.type!=="event"&&t.instruction?.type!=="open_url"&&u?.finish("skipped")),t.screen){let E=t.screen.content;if(!w){let z=t.screen.presentation.type!=="inline",we=Ae(z,t.locale);if(C||W)return;let de=(h=new AbortController).signal;Qe(t),Q=z?an(F):Me(d,n),w=f(q,{mode:"live",rendererUrl:e.client.webViewUrl,title:E.document.name,onAction(ce,ve={},Pn={}){if(V.active||!ie(de)||k!==l)return;pe={...pe,...Pn};let Rn=Object.fromEntries((t.screen?.inputs??[]).filter(({variable:Te})=>Object.hasOwn(pe,Te)).map(({variable:Te})=>[Te,pe[Te]]));Re(()=>e.client.submit({operation:"submit",...he(),input:{type:"screen",output:ce,answers:Rn,selection:ve}}))},onAnswers:ce=>{V.active||!ie(de)||k!==l||(pe={...pe,...ce})},onCustomerDataIntent:ce=>{V.active||!ie(de)||k!==l||Ne.intent(ce).catch(le)},onEscape:()=>{!ie(de)||k!==l||V.active||re||B||be()},onError:ce=>{let ve=new Error(ce);k===l?le(ve):Z(ve,de)},onRendered:ce=>{if(!(!ie(de)||k===l))try{we.present(ve=>{Q?.(),Q=void 0,ce&&(j={screen:E.document.name,label:ce},F.setAttribute("aria-label",ce)),z&&(F.showModal(),!ve&&e.loading!=="host"&&sn(F,t.screen.presentation.type)),k=l,Ie()}),ie(de)&&Se.report(l)}catch(ve){Z(ve,de)}}})}let g={capabilities:t.screen.capabilities,customerData:t.screen.customerData,parameters:t.parameters,serverInput:{bindings:t.screen.inputs,answers:pe,values:t.screen.values}},ee=JSON.stringify([E,t.locale,g.parameters,t.screen.inputs,t.screen.values]);if(ee!==x)w.update(E.document,t.locale,g),x=ee,L=JSON.stringify(g.capabilities),se=JSON.stringify(g.customerData);else{let z=JSON.stringify(g.capabilities);z!==L&&(w.updateCapabilities(g.capabilities),L=z),JSON.stringify(g.customerData)!==se&&(w.updateCustomerData(g.customerData),se=JSON.stringify(g.customerData))}let H=w;if(H)try{await(u?.wait(H.ready)??H.ready)}catch(z){h&&Z(z,h.signal)}}else if(t.paywall&&!A){let E=Ae(!0,t.locale);if(C||W)return;let g=(h=new AbortController).signal;Qe(t);let ee=await P(q,{loading:"host",signal:g,canInteract:()=>ie(g)&&!V.active&&!re&&!B,beforeAction:async()=>{S++;try{await We(Se.settled()),N.hidden=!0,Ce=null}finally{S=Math.max(0,S-1)}},start:()=>mn(e.client),onObservationChange:qe,onPurchase:e.onPurchase,onCheckoutUrl:e.onCheckoutUrl,checkoutNavigation:e.checkoutNavigation,resolveOfferId:e.resolveOfferId,onEvent:e.onEvent,onOpenUrl:H=>e.onOpenUrl?e.onOpenUrl({receiptId:t.paywall.receiptId,url:H,openIn:"same_window"}):o.defaultView?.location.assign(H),onAction:async H=>{if(V.active)return;let z=await e.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:e.client.view?.revision??t.revision,input:{type:"screen",output:H,answers:{}}});await fe(e.client.view??z.run)},onError:H=>{k===l?le(H):Z(H,g)}},{quoteError:H=>oe(e.onError,H),present(H){ie(g)&&(E.present(()=>{H(),k=l,Ie()}),ie(g)&&Se.report(l))},async dismiss(){C||g.aborted||V.active||re||B||!ae&&!ie(g)||(ae=!0,await be())}}).catch(H=>(Z(H,g),null));!ie(g)&&!(ae&&!C&&!g.aborted)?ee?.host?.destroy():ee&&(A=ee.host,A?.setSuspended(V.active))}if(C||W)return;Ie();let $=t.instruction;if($&&($.type==="open_url"||$.type==="event")&&!ke.has($.receiptId)){let E=o.createElement("button");E.type="button",E.textContent=$.type==="open_url"?`${s?"\u524D\u5F80":"Continue to"} ${new URL($.url).host}`:s?"\u7EE7\u7EED":"Continue",E.onclick=()=>{let g=he(),ee=$.type==="open_url"&&!e.onOpenUrl&&$.openIn==="new_window"?In($.url):null;Re(async()=>{let H="success";if($.type==="open_url")if(e.onOpenUrl)try{H=await e.onOpenUrl({receiptId:$.receiptId,url:$.url,openIn:$.openIn})===!1?"failed":"opened"}catch(we){oe(e.onError,we),H="failed"}else H=$.openIn==="new_window"&&!ee?"failed":"opened";if($.type==="event"){if(!e.onEvent)throw new I("EVENT_HANDLER_REQUIRED","Provide the event handler");await e.onEvent($.event)}if(C||e.client.view?.nodeId!==g.nodeId||e.client.view.visit!==g.visit)throw new I("PRECONDITION_FAILED","The client action visit changed");let z=await e.client.submit({operation:"submit",...g,input:{type:"client_action",receiptId:$.receiptId,outcome:H}});return ke.add($.receiptId),$.type==="open_url"&&!e.onOpenUrl&&$.openIn==="same_window"&&o.defaultView?.location.assign($.url),z})},u?.active?u.present(()=>q.replaceChildren(E)):q.replaceChildren(E)}!t.pendingRequest&&t.status==="completed"&&!ke.has(`complete:${t.id}`)&&(ke.add(`complete:${t.id}`),oe(e.onComplete,structuredClone(t))),qe()}function In(t){let s=o.defaultView?.open(t,"_blank")??null;return s&&(s.opener=null),s}function fe(t){return Ie(),a=a.catch(()=>{}).then(async()=>{try{await hn(t)}catch(s){throw u?.active&&(J=Oe(t),u.finish("error",s),ge(),d.hidden=!0),s}}),a}let bn=e.client.subscribe(t=>{b||(!ae&&(t.stopped||e.client.configurationReady===!1||X&&k!==X&&(Pe(t)!==X||["closed","ineligible","failed"].includes(t.status)))&&(ge(),u?.finish("dismissed"),d.hidden=!0),fe(t).catch(le))}),Cn=e.client.subscribeError?.(le);function be(t){if(ye)return ye;if(C||!t&&(re||B))return Promise.resolve();let s=!t&&Fe();return!s&&e.client.view&&!["running","waiting"].includes(e.client.view.status)?(U=e.client.view,ue(),Promise.resolve()):(ye=Re(async()=>{let l=s?await e.client.retry():await e.client.submit({operation:"close",...t??he()});return t&&xe(l),l},!0).then(()=>{let l=e.client.view;l?.status==="closed"&&!Fe()&&(U=l,ue())}).finally(()=>{ye=null}),ye)}function ue(){R?.destroy(),!C&&(C=!0,e.signal?.removeEventListener("abort",ue),r?.removeEventListener("abort",ue),u?.finish("dismissed"),je.destroy(),bn(),Cn?.(),ge(),V.stop(),F.remove(),d.remove(),y(),oe(e.onDismiss,U?structuredClone(U):null))}O.onclick=()=>{if(!O.disabled){if(V.active){V.exit();return}Re(()=>e.client.submit({operation:"back",...he()}))}},D.onclick=()=>{V.open()},G.onclick=()=>{u?.active?u.dismiss():re||be()},M.onclick=()=>{Fe()?be():Re(()=>e.client.retry())},F.addEventListener("cancel",t=>{t.preventDefault(),u?.active?u.dismiss():re||be()}),e.signal?.addEventListener("abort",ue,{once:!0}),r?.addEventListener("abort",ue,{once:!0});try{let t=e.client.view;if(t)((e.client.viewAgeMs??ze)>=ze||t.instruction?.type==="evaluate_segment")&&(p=He().finally(()=>{p=null})),await fe(t);else{d.hidden=!0;let s=Ae(e.client.view?.screen?.presentation.type!=="inline",e.client.view?.locale);if(C||W)throw new DOMException("Presentation cancelled","AbortError");let l=await s.wait(e.client.get(),De);b=!1,await fe(e.client.view??l.run)}}catch(t){throw u?.finish("error",t),ue(),t}return{destroy:ue,refresh:He,get recovery(){let t=$e();if(t)return t;if(!C&&!S&&!ae&&!re&&A){let s=A.recovery;if(s.type!=="native")return s}return{type:"recover",operationId:e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??B?.operationId??null,requestId:e.client.pendingCommand?.requestId??null}},prepareFallback(){if(re)return re;let t=$e();if(t)return Promise.resolve(t);let s=e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??B?.operationId??null,l=()=>({type:"recover",operationId:s,requestId:e.client.pendingCommand?.requestId??null});if(e.client.hasDurableJournal!==!0){let Z=A?.recovery;return Promise.resolve(Z&&Z.type!=="native"&&Z.type!=="cancel"?Z:l())}let te=(e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[])).some(Z=>Z.operation==="close");if(C&&!(te||B&&e.client.view?.status==="closed")||S||ne||ye||V.active||!A&&!B&&!te)return Promise.resolve(l());let Je=A,me=(async()=>{try{if(!B&&te){let E=await e.client.retry();return await fe(e.client.view??E.run),l()}if(!B){let E=await Je.prepareFallback();if(E.type!=="native")return E;if(e.client.hasDurableJournal!==!0)return l();B=E}let Z=e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[]);if(Z.length){let E=Z.find(ee=>ee.operation==="close");if(!E||!Y||E.requestId!==Y.requestId)return l();let g=await e.client.retry();xe(g),await fe(e.client.view??g.run)}else{let E=e.client.view,g=E?.paywall;if(!E||!g||g.selectionGeneration===void 0||(g.quote?.operationId??null)!==B.operationId||B.operationId!==null&&g.canReselect!==!0)return l();let ee=g.selectionGeneration,H=await e.client.get();await fe(e.client.view??H.run);let z=e.client.view,we=z?.paywall;if(!z||!we||!["running","waiting"].includes(z.status)||z.stopped||z.id!==E.id||z.nodeId!==E.nodeId||z.visit!==E.visit||we.receiptId!==g.receiptId||we.selectionGeneration!==ee||(we.quote?.operationId??null)!==B.operationId||B.operationId!==null&&we.canReselect!==!0||e.client.pendingPurchase||(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0)))return l();let de=he();Y={runId:z.id,operationId:B.operationId,revision:de.revision,requestId:de.requestId,nodeId:z.nodeId,visit:z.visit,receiptId:we.receiptId,selectionGeneration:ee,acknowledged:!1},await be(de)}let $=$e();return $?(ue(),$):l()}catch(Z){return le(Z),l()}})();re=me;let ie=()=>{re===me&&(re=null)};return me.then(ie,ie),me},review:V.open,exitReview:V.exit,get unappliedDrafts(){return V.drafts}}}function mt(n,v,m){return qn(n,v,m)}export{Dn as a,vn as b,qn as c,mt as d};
1
+ import{a as Ue,c as un}from"./chunk-JGG4R75K.js";import{d as sn,f as De,g as Ve,h as an,i as Me,k as ln}from"./chunk-CNIBGSVO.js";import{$ as _e}from"./chunk-PMCGTXGH.js";import{a as Le,e as en,f as nn,g as tn,h as rn,i as on}from"./chunk-PWQ5BHBJ.js";import{b as Xe}from"./chunk-HMRIMJ5W.js";import{R as Ye,qa as Ze}from"./chunk-5RXU57I5.js";import{a as I}from"./chunk-X7G7JMZ3.js";import{b as dn,e as pn}from"./chunk-SLUA7ABW.js";import{d as cn}from"./chunk-DCIGO3NJ.js";import{a as oe}from"./chunk-DSPLGTQI.js";import{b as Ke}from"./chunk-O4KXODTJ.js";var Ee=new WeakMap;function Dn(n){let v=n.view,m=v?.paywall?.resolution;if(!v||!["running","waiting"].includes(v.status)||v.stopped||!m||"document"in m||!n.resolvePaywall||n.identitySignal?.aborted)return;let e=JSON.stringify(m);if(Ee.get(n)?.key===e)return;let f=JSON.parse(e),P=n.identitySignal,r=Promise.resolve().then(async()=>{P?.throwIfAborted();let o=await n.resolvePaywall(f);return P?.throwIfAborted(),o}),R={key:e,content:r};return Ee.set(n,R),r.catch(()=>{}),()=>{Ee.get(n)===R&&Ee.delete(n)}}function fn(n,v){let m=Ee.get(n);return Ee.delete(n),m?.key===JSON.stringify(v)?m.content:n.resolvePaywall(v)}async function mn(n){let{session:v,load:m}=En(n);try{return await m(),v}catch(e){throw v.destroy(),e}}function En(n){let v=n.view;if(!v?.paywall)throw new I("INVALID_REQUEST","The current node is not a Paywall");let m=v.paywall.receiptId,e=v.nodeId,f=v.visit,P=v.paywall.resolution,r=v.paywall,R="document"in P?{document:P.document,offering:P.offering,capabilities:P.capabilities}:null;function o(){let i=r.resolution;return"document"in i?i:R&&{...i,document:R.document,offering:R.offering,capabilities:en(i.capabilities,R.capabilities)}}function y(i){if(!nn(i,P))throw new I("INVALID_RESPONSE","The pinned Paywall binding changed")}let d=!1,q=new Set,_=null;function T(){let i=o();if(i&&!d)for(let p of q)oe(p,structuredClone(i))}async function D(){U();let i=o();if(i)return structuredClone(i);if(!_){let p=(async()=>{if("document"in r.resolution||!n.resolvePaywall)throw new I("INVALID_RESPONSE","Public Paywall reader is unavailable");let b=await fn(n,r.resolution);return U(),y(b),R={document:b.document,offering:b.offering,capabilities:b.capabilities},T(),o()})();_=p;let a=()=>{_===p&&(_=null)};p.then(a,a)}return _.then(p=>structuredClone(p))}let c=new AbortController,O=(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).find(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===f&&i.input.type==="paywall_quote")?.requestId??v.paywall.purchaseRequestId,G=0,M=null,F=new Set,j=null,w=new Map;function A(i){if(i.purchase&&i.purchase.receiptId!==m)throw new I("INVALID_RESPONSE","Purchase receipt changed");let p=i.run.paywall;return i.purchase??(p?.receiptId===m?p:null)}function U(){if(d)throw new I("IDENTITY_CHANGED","Paywall presentation has closed")}function X(i,p,a){if(U(),p!==G||a!==void 0&&r.quote?.operationId!==a)return!1;let b=r.selectionGeneration??0,u=i.run.paywall;if(u?.receiptId===m){if((u.selectionGeneration??0)<(r.selectionGeneration??0))return!1;y(u.resolution)}let h=A(i),Q=u?.receiptId===m&&(u.selectionGeneration??0)>b,J=Q?h?.quote??null:h?.quote??r.quote,K=h?.operation??(J?.operationId===r.quote?.operationId?r.operation:null);return J&&K&&tn(K,{operationId:J.operationId},"Purchase operation changed"),(Q||J?.operationId!==r.quote?.operationId)&&(G++,u?.receiptId===m&&(O=u.purchaseRequestId)),r={...r,...u?.receiptId===m?u:{},quote:J,operation:on(r.operation,K,!0)},T(),!0}function k(i,p,a){return new Promise((b,u)=>{let h=!1,Q=()=>{clearTimeout(ye),c.signal.removeEventListener("abort",W)},J=ae=>{h||(h=!0,Q(),b(ae))},K=ae=>{h||(h=!0,Q(),u(ae))},W=()=>K(new I("IDENTITY_CHANGED","Paywall presentation has closed")),ye=setTimeout(()=>K(new I("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,a)),Math.max(0,p-Date.now()));c.signal.addEventListener("abort",W,{once:!0}),c.signal.aborted&&W(),i.then(J,K)})}function x(i){return new Promise(p=>{let a=()=>{clearTimeout(b),c.signal.removeEventListener("abort",a),p()},b=setTimeout(a,i);c.signal.addEventListener("abort",a,{once:!0}),c.signal.aborted&&a()})}function L(i,p){U();let a=w.get(i)??n.pendingCommands?.find(h=>h.requestId===i)??n.pendingCommand;if(a?.operation==="submit"&&a.requestId===i&&a.nodeId===e&&a.visit===f){p.type==="paywall_quote"&&a.input.type==="paywall_quote"&&a.input.predecessor&&!p.predecessor&&(p={...p,predecessor:a.input.predecessor});let h=_e.parse(a),Q=_e.parse({...a,input:p});if(h.operation!=="submit"||Q.operation!=="submit"||JSON.stringify(h.input)!==JSON.stringify(Q.input))throw new I("CONFLICT","A purchase request cannot change its input");return w.set(i,h),h}let b=n.view;if(!b||b.nodeId!==e||b.visit!==f||b.paywall?.receiptId!==m)throw new I("PRECONDITION_FAILED","The Paywall visit has changed");let u=_e.parse({operation:"submit",requestId:i,nodeId:e,visit:f,revision:b.revision,input:structuredClone(p)});if(u.operation!=="submit")throw new I("INVALID_REQUEST","A purchase submission is required");return w.set(i,u),u}async function se(i,p){U();let{requestId:a,input:b}=i,u=Date.now()+3e4;F.add(a);try{let h=await k(n.submit(i),u,a);for(;h.run.pendingRequest?.requestId===a&&Date.now()<u&&!d&&(await x(Math.min(1e3,u-Date.now())),!(d||Date.now()>=u));)h=await k(n.resume(a),u,a);if(d)throw new I("IDENTITY_CHANGED","Paywall presentation has closed");if(h.run.pendingRequest?.requestId===a)throw new I("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,a);if(!X(h,p,b.type==="paywall_confirm"||b.type==="paywall_cancel"?b.operationId:void 0))throw new I("PRECONDITION_FAILED","The purchase selection has changed");j===a&&(j=null)}catch(h){throw j=a,h instanceof I&&h.code==="COMMAND_PENDING"&&h.status===void 0&&w.delete(a),h}finally{F.delete(a)}}async function C(i){if(!r.quote)throw new I("INVALID_REQUEST","A quoted purchase is required");let p=i==="confirm"?"paywall_confirm":"paywall_cancel",a=[...w.values(),...n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])].find(u=>u.operation==="submit"&&u.input.type===p&&"operationId"in u.input&&u.input.operationId===r.quote.operationId),b=a?.operation==="submit"&&a.input.type===p&&"operationId"in a.input&&a.input.operationId===r.quote.operationId?a.requestId:crypto.randomUUID();if(await se(L(b,{type:i==="confirm"?"paywall_confirm":"paywall_cancel",operationId:r.quote.operationId}),G),!r.operation)throw new I("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(r.operation)}let S={get view(){return structuredClone(o())},get quote(){return r.quote?structuredClone(r.quote):null},get operation(){return r.operation?structuredClone(r.operation):null},get webViewUrl(){return n.webViewUrl},get canReselect(){return r.canReselect===!0},get recovery(){let i=n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[]),p=n.pendingPurchase;if(p&&(p.receiptId!==m||p.operationId!==r.quote?.operationId))return{type:"recover",operationId:p.operationId,requestId:i[0]?.requestId??null};let a=Le({quote:r.quote,operation:r.operation,requestId:i[0]?.requestId??j??O,pending:F.size>0||i.length>0||j!==null,destroyed:d,canReselect:r.canReselect});return a.type==="recover"&&a.requestId===null&&!d&&n.hasDurableJournal===!0&&!r.quote&&!r.operation&&(r.selectionGeneration??0)===0&&!p&&!i.length&&!F.size&&!O?{type:"native",operationId:null}:a},get pendingCancellation(){return!d&&(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).some(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===f&&i.input.type==="paywall_cancel"&&i.input.operationId===r.quote?.operationId)},subscribe(i){return d?()=>{}:(q.add(i),()=>q.delete(i))},async refresh(){U();let i=G,p=await n.get();if(X(p,i),p.run.paywall?.receiptId!==m)throw new I("PRECONDITION_FAILED","Paywall presentation has changed");return D()},preview(i){let p=o();if(!p)return Promise.reject(new I("PRECONDITION_FAILED","Load the Paywall presentation first"));if(O&&O!==i.requestId&&(M||r.canReselect!==!0))return Promise.reject(new I("COMMAND_PENDING","Retry the original purchase before starting another"));let a=p.document.buttons[i.actionId],b=a?.type==="checkout"?Xe(a.product,i.selection,p.capabilities):null;if(!b)return Promise.reject(new I("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let u=Ze(p.document.screen,b,i.selection,p.capabilities),h=O!==i.requestId&&(r.selectionGeneration??0)>0?{operationId:r.quote?.operationId??null,generation:r.selectionGeneration??0}:void 0;if(h&&r.canReselect!==!0)return Promise.reject(new I("COMMAND_PENDING","Original purchase requires authoritative termination"));let Q;try{Q=L(i.requestId,{type:"paywall_quote",actionId:i.actionId,productVersionId:b,...Object.keys(u).length?{featureQuantities:u}:{},...h?{predecessor:h}:{},...i.offerId?{offerId:i.offerId}:{},...i.nativeOffer?{nativeOffer:i.nativeOffer}:{}})}catch(W){return Promise.reject(W)}if(O===i.requestId&&M)return M;O!==i.requestId&&G++;let J=G;O=i.requestId;let K=(async()=>{if(await se(Q,J),!r.quote)throw new I("INVALID_RESPONSE","The accepted quote is missing");return rn(r.quote,{productVersionId:b,featureQuantities:u},"The selected purchase changed"),structuredClone(r.quote)})();return M=K,K.then(()=>{M===K&&(M=null)},W=>{M===K&&(M=null),O===i.requestId&&n.pendingCommand?.requestId!==i.requestId&&W instanceof I&&W.status!==void 0&&W.status<500&&![401,425].includes(W.status)&&(O=null)}),K},confirm:()=>C("confirm"),cancel:()=>C("cancel"),async read(){if(U(),!r.quote)throw new I("INVALID_REQUEST","A quoted purchase is required");let i=r.quote.operationId,p=G,a=n.pendingCommands?.find(J=>J.operation==="submit"&&(J.input.type==="paywall_confirm"||J.input.type==="paywall_cancel")&&J.input.operationId===i)??n.pendingCommand;a?.operation==="submit"&&(a.input.type==="paywall_confirm"||a.input.type==="paywall_cancel")&&a.input.operationId===i&&await n.settle?.(a.requestId);let b=await n.get(void 0,{receiptId:m,operationId:i});U();let u=A(b);if(u?.quote&&u.quote.operationId!==i||u?.operation&&u.operation.operationId!==i)throw new I("INVALID_RESPONSE","Purchase operation changed");let h=X(b,p,i),Q=h?r.operation:u?.operation;if(!Q)throw new I("INVALID_RESPONSE","The current purchase result is missing");return h&&F.size===0&&!(n.pendingCommands?.length??(n.pendingCommand?1:0))&&(j=null),structuredClone(Q)},destroy(){d=!0,ne(),q.clear(),c.abort(),w.clear()}},ne=n.subscribe(i=>{d||i.nodeId!==e||i.visit!==f||i.paywall?.receiptId!==m||(i.paywall.selectionGeneration??0)<(r.selectionGeneration??0)||(y(i.paywall.resolution),r={...r,resolution:i.paywall.resolution},T())});return{session:S,load:D}}function wn(n){let v=new Set,m=new Set,e=null;async function f(o,y){let d=!1;for(;!n.stopped&&n.key===o&&n.client.pendingCommand?.requestId===y;){if(!n.client.settle)throw new I("COMMAND_PENDING","The original display acknowledgement is still pending");await n.client.settle(y),d=!0,n.client.pendingCommand?.requestId===y&&await new Promise(q=>setTimeout(q,1500))}n.stopped||n.key!==o||(d&&await n.client.get(),!(n.stopped||n.key!==o)&&v.add(o))}function P(o,y){e=y;let d=()=>{e===y&&(e=null),m.delete(o)};return y.then(d,q=>{d(),n.busy||n.fail(q)}),y}function r(o){if(n.reviewing||v.has(o)||m.has(o)||n.stopped)return;m.add(o);let y=async()=>{if(n.reviewing||n.stopped||n.key!==o||v.has(o)){m.delete(o);return}if(n.busy||n.client.pendingCommand){setTimeout(()=>{y()},250);return}let d=(async()=>{if(n.staleRead){if(await n.staleRead,n.stopped||n.key!==o)return;if(n.client.pendingCommand){setTimeout(()=>{y()},250);return}}let q=n.client.view,_=n.expected(),T=_.requestId;try{await n.client.submit({operation:"shown",..._})}catch(D){if(!(D instanceof I)||D.code!=="CONFLICT"||D.status!==409||n.client.pendingCommand)throw D;await n.client.get();let c=n.client.view;if(n.stopped||n.reviewing||n.key!==o||!c||!q||c.id!==q.id||c.source.versionId!==q.source.versionId||c.nodeId!==_.nodeId||c.visit!==_.visit||c.revision<=_.revision||c.stopped||!c.screen&&(!c.paywall||c.paywall.receiptId!==q.paywall?.receiptId)||!["running","waiting"].includes(c.status)||n.client.pendingCommand)throw D;let N=n.expected();T=N.requestId,await n.client.submit({operation:"shown",...N})}await f(o,T)})();P(o,d)};y()}function R(){if(e)return e;let o=n.client.pendingCommand;if(o?.operation!=="shown")return null;let y=n.key;return m.add(y),P(y,(async()=>{await n.client.retry(),await f(y,o.requestId)})())}return{report:r,settled:R,get inFlight(){return e}}}function yn(n){let v={},m=new Map;async function e(f){let P=n.client.view,r=P?.screen,R=r?.customerData.nodes[f.nodeId];if(n.stopped||n.busy||!P||!r||!R)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(f.action)){let D=n.document,c=D?Ye(D,f.nodeId):null,N=c?.type==="customer_data"?c.data.outputs?.[f.action]:void 0;N&&r.outputs.includes(N)?await n.perform(()=>n.client.submit({operation:"submit",...n.expected(),input:{type:"screen",output:N,answers:n.answers,selection:f.value?{[f.nodeId]:f.value}:{}}})):await n.onIntent?.(f,P);return}let y=f.action.startsWith("sources_")?R.resources.find(D=>D.key===f.value):null;if(f.action.startsWith("sources_")&&!y)throw new I("INVALID_REQUEST","Choose a current resource");let d=`${P.visit}:${f.nodeId}:${y?.key??""}`,q=m.get(d)??[null],T=v[f.nodeId]??{page:1,after:null,filter:"all",...y?{resourceKey:y.key}:{}};if(f.action==="filter"){let D=f.value;if(!D||!(R.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(D))throw new I("INVALID_REQUEST","Unknown data filter");T={page:1,after:null,filter:D},q.splice(0,q.length,null)}else if(f.action==="next"||f.action==="sources_next"){let D=y?.sources.at(-1),c=y?D?{kind:"ledger",cursor:{at:D.detail[0],id:D.id,type:"source"}}:null:r.dataCursors[f.nodeId];if(!c||!y&&!R.hasNext)return;q[T.page]=c,T={...T,page:T.page+1,after:c}}else if(f.action==="previous"||f.action==="sources_previous"){if(T.page<=1)return;T={...T,page:T.page-1,after:q[T.page-2]??null}}m.set(d,q),v={...v,[f.nodeId]:T},await n.perform(()=>n.client.get({nodeId:P.nodeId,visit:P.visit,revision:P.revision,components:v}))}return{get queries(){return v},intent:e,reset(){v={},m.clear()}}}function gn(n){let{doc:v,holder:m,reviewHolder:e,mountScreenPreview:f}=n,P=!1,r,R=0,o=null,y="",d,q=new Map,_=c=>c?`${c.id}:${c.nodeId}:${c.visit}:${c.revision}:${c.paywall?.quote?.operationId??""}`:"";async function T(c){if(n.stopped||!n.client.review||P&&c===r&&d?.active)return;let N=!P||c!==r;P||(y=_(n.client.view),q.set(y,structuredClone(n.answers))),P=!0,r=c,m.hidden=!0,n.suspend(!0),e.hidden=!1;let O=++R;N&&(d?.finish("dismissed"),o?.destroy(),o=null,e.replaceChildren(),d=Ve(e,n.loadingOptions,"funnel",()=>{D()}));let G=N?d:void 0;try{if(G?.start(!1,n.client.view?.locale),O!==R||n.stopped)return;let M=n.client.review(c),F=await(G?.wait(M,De)??M);if(n.stopped||O!==R||!P)return;if(!F.review)throw new I("INVALID_RESPONSE","Historical projection is missing");o?.destroy(),o=null,G||e.replaceChildren();let j=v.createElement("div"),w=G?Me(j,e):()=>{};e.append(j);let A=F.run.locale.startsWith("zh"),U=v.createElement("p");U.textContent=A?"\u53EA\u8BFB\u56DE\u770B":"Read-only history",j.append(U);for(let[k,x]of F.review.pages.entries()){let L=v.createElement("button");L.type="button",L.textContent=A?`\u7B2C ${k+1} \u9875`:`Page ${k+1}`,L.onclick=()=>{T(x.receiptId)},j.append(L)}if(F.review.page){let k=F.review.page,x=v.createElement("div");x.inert=!0,j.append(x),o=f(x,{mode:"live",rendererUrl:n.client.webViewUrl,title:k.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{O===R&&!n.stopped&&G?.present(w)},onError:se=>{if(O!==R||n.stopped)return;let C=new Error(se);G?.finish("error",C),o?.destroy(),o=null,j.remove(),n.fail(C)},onEscape:()=>{D()}});let L=o;if(L.update(k.document,F.run.locale,{serverInput:{bindings:k.inputs,answers:k.answers,values:k.values}}),await L.ready,n.stopped||O!==R||!P)return}let X=A?{issued:"\u5DF2\u9886\u53D6",reserved:"\u5DF2\u9884\u7559",redeemed:"\u5DF2\u4F7F\u7528",expired:"\u5DF2\u8FC7\u671F",revoked:"\u5DF2\u64A4\u9500",unknown:"\u72B6\u6001\u5F85\u786E\u8BA4"}:{issued:"Issued",reserved:"Reserved",redeemed:"Used",expired:"Expired",revoked:"Revoked",unknown:"Status unconfirmed"};for(let k of[...F.review.coupons.map((x,L)=>`${A?"\u4F18\u60E0\u5238":"Coupon"} ${L+1}: ${X[x.status]}`),...F.review.purchases.map((x,L)=>`${A?"\u8D2D\u4E70":"Purchase"} ${L+1}: ${un(x.status,A)}`)]){let x=v.createElement("p");x.textContent=k,j.append(x)}F.review.page||G?.present(w),n.client.view&&await n.enqueue(n.client.view)}catch(M){if(O!==R||n.stopped)return;G?.finish("error",M),o?.destroy(),o=null,e.replaceChildren(),n.fail(M)}}async function D(){if(!P||n.stopped||!n.client.review)return;let c=++R;d?.finish("dismissed");try{if(await n.client.review(),n.stopped||c!==R)return;P=!1,R++,d?.finish("dismissed"),o?.destroy(),o=null,e.replaceChildren(),e.hidden=!0,m.hidden=!1;let N=n.client.view;_(N)!==y?(q.set(y,structuredClone(n.answers)),n.resetScreen()):(q.delete(y),n.suspend(!1)),N&&await n.enqueue(N)}catch(N){if(c!==R||n.stopped)return;o?.destroy(),o=null,e.replaceChildren(),n.fail(N)}}return{get active(){return P},get receipt(){return r},open:T,exit:D,get drafts(){return new Map([...q].map(([c,N])=>[c,structuredClone(N)]))},stop(){P=!1,R++,d?.finish("dismissed"),o?.destroy(),o=null,e.replaceChildren(),e.hidden=!0,m.hidden=!1}}}function vn(n){if(!n.client.pageExperiments)throw new Error("The Run controller does not support page experiments");let v=n.client.pageExperiments.bind(n.client),m=!1,e=!1,f=0,P=!1,r=!1,R="",o=()=>{let w=n.client.view;return JSON.stringify([w?.id,w?.source.versionId,w?.visit,w?.revision,w?.status,w?.stopped])},y=new Map,d=new Set,q={},_=new Map,T=dn(n.appManifestRelease),D=()=>{for(let w of y.values())w.effect.revert();y.clear()},c=()=>{D();for(let w of _.values())w();_.clear()};function N(w){if(m||d.has(w))return;d.add(w);let A=f;v(n.appManifestRelease,[w]).catch(U=>{d.delete(w),!m&&A===f&&oe(n.onError,U)})}async function O(){if(m)return;R=o();let w=n.client.view;if(!w||w.stopped||!["running","waiting"].includes(w.status)){f++,c();return}if(document.visibilityState==="hidden")return;if(P){r=!0;return}P=!0;let A=++f,U=`${w.id}:${w.visit}:${w.revision}`,X=location.href;try{let[k,{applyVisualVariation:x}]=await Promise.all([v(n.appManifestRelease),import("./visual-dom-5LUN4AHO.js")]),L=n.client.view;if(m||A!==f||!L||L.stopped||!["running","waiting"].includes(L.status)||`${L.id}:${L.visit}:${L.revision}`!==U||location.href!==X)return;let se=new Set,C=new Set;for(let S of k.assignments){let ne=`${k.payload.environmentId}:${S.experimentKey}`;if(C.add(ne),_.has(ne)||_.set(ne,pn(ne,q)),!!S.inExperiment)for(let i of k.payload.experiments){if(i.key!==S.experimentKey||!Ke(location.href,i.urlPatterns??[]))continue;let p=i.meta?.findIndex(J=>J.key===S.variationKey)??-1,a=i.variations[p];if(!a?.renderGuard)continue;let b=S.receiptId+":"+i.changeId,u=JSON.stringify([S.variationKey,a]);se.add(b);let h=y.get(b);if(h?.signature===u){h.effect.applied&&N(S.receiptId);continue}y.get(b)?.effect.revert(),y.delete(b);let Q=x(a,{requireUniqueTargets:!0,boundVariations:i.variations,allowJs:!1,onApplied:()=>N(S.receiptId),onError:J=>oe(n.onError,J)});y.set(b,{signature:u,effect:Q}),Q.applied&&N(S.receiptId)}}for(let[S,ne]of y)se.has(S)||(ne.effect.revert(),y.delete(S));for(let[S,ne]of _)C.has(S)||(ne(),_.delete(S))}catch(k){A===f&&c(),!m&&A===f&&oe(n.onError,k)}finally{P=!1,r&&!m&&(r=!1,O())}}let G=n.client.subscribe(()=>{if(o()===R)return;R=o(),f++;let w=n.client.view;(!w||w.stopped||!["running","waiting"].includes(w.status))&&c(),e&&O()}),M=cn(()=>{f++,c(),e&&O()}),F=()=>{f++,D()};document.addEventListener("visibilitychange",F);let j=Ue({document,run:async()=>{e&&await O()},delay:()=>e&&!m?15e3:void 0});return{async start(){e||m||(e=!0,await j.refresh())},refresh:O,destroy(){m=!0,f++,j.destroy(),document.removeEventListener("visibilitychange",F),G(),M(),c(),T.destroy()}}}var ze=5e3;async function qn(n,v,m){let e=v,[{mountScreenPreview:f},{showPaywall:P}]=await Promise.all([import("./screen-renderer-G2EWN3WB.js"),import("./paywall-QQ2MC4KO.js")]),r=e.client.identitySignal;e.signal?.throwIfAborted(),r?.throwIfAborted();let R=e.appManifestRelease?vn({client:e.client,appManifestRelease:e.appManifestRelease,onError:e.onError}):void 0;R?.start();let o=n.ownerDocument,y=ln(o),d=o.createElement("section"),q=o.createElement("div"),_=o.createElement("div"),T=o.createElement("div"),D=o.createElement("button");T.hidden=!0,D.type="button";let c=o.createElement("p"),N=o.createElement("p"),O=o.createElement("button"),G=o.createElement("button"),M=o.createElement("button"),F=o.createElement("dialog"),j;d.dataset.indianaFunnel="",d.setAttribute("aria-busy","false"),d.style.cssText="box-sizing:border-box;width:100%;min-width:0;font:14px/1.5 system-ui,sans-serif;color:#172033;background:#fff",_.style.cssText="display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding:12px 20px",c.setAttribute("role","status"),N.setAttribute("role","alert"),N.hidden=!0,O.type=G.type=M.type="button",_.append(O,c,N,M,D,G),d.append(q,T,_),n.append(d);let w=null,A=null,U=null,X="",k="",x="",L="",se="",C=!1,S=0,ne=!1,i="",p=null,a=Promise.resolve(),b=!e.client.view,u=m,h,Q,J="",K,W=!1,ye=null,ae=!1,Fe=()=>e.client.pendingCommand?.operation==="close",re=null,B=null,je=Ue({document:o,run:async()=>{(!A?.observing||e.client.pendingCommand)&&await He()},delay:()=>{if(!(C||!U||!["running","waiting"].includes(U.status)&&!e.client.pendingCommand)&&!(A?.observing&&!e.client.pendingCommand))return U.pendingRequest||e.client.pendingCommand?1500:ze},hiddenDelay:()=>!C&&e.client.pendingCommand?15e3:void 0}),Y=null;function $e(){return B&&e.client.hasDurableJournal===!0&&Y?.acknowledged===!0&&Y.operationId===B.operationId&&e.client.view?.id===Y.runId&&e.client.view?.status==="closed"&&e.client.view.revision===Y.revision+1&&!(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0))&&!e.client.pendingPurchase?B:null}function xe(t){let s=t.run.paywall;if(Y&&t.settlement?.requestId===Y.requestId&&t.settlement.state==="settled"&&t.settlement.operationId===null&&t.run.id===Y.runId&&t.run.status==="closed"&&!t.run.pendingRequest&&t.run.revision===Y.revision+1&&t.run.nodeId===Y.nodeId&&t.run.visit===Y.visit&&s?.receiptId===Y.receiptId&&s.selectionGeneration===Y.selectionGeneration&&(s.quote?.operationId??null)===Y.operationId&&(s.operation?.operationId??s.quote?.operationId??null)===Y.operationId){let l=Y.operationId===null&&s.selectionGeneration===0&&!s.quote&&!s.operation&&!s.purchaseRequestId,te=Le({quote:s.quote,operation:s.operation,requestId:s.purchaseRequestId,pending:!1,destroyed:!1,canReselect:s.canReselect});(l||s.canReselect===!0&&te.type==="native")&&(Y.acknowledged=!0)}}let Ce=null,ke=new Set,pe={},le=(t,s=null)=>{C||(Ce=s,N.textContent=t instanceof Error?t.message:"Request failed",N.hidden=!1,M.hidden=e.client.pendingCommand===null,oe(e.onError,t))};function he(){let t=e.client.view;if(!t)throw new I("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision}}let V=gn({client:e.client,doc:o,holder:q,reviewHolder:T,mountScreenPreview:f,loadingOptions:e,get stopped(){return C},get answers(){return pe},suspend(t){A?.setSuspended(t)},resetScreen(){X="",k="",x=""},enqueue:fe,fail:le}),Se=wn({client:e.client,expected:he,fail:le,get stopped(){return C},get reviewing(){return V.active},get key(){return X},get busy(){return S},get staleRead(){return p}}),Ne=yn({client:e.client,expected:he,perform:Re,onIntent:e.onCustomerDataIntent,get stopped(){return C},get busy(){return S},get document(){return w?.document},get answers(){return pe}}),Oe=t=>`${t.id}:${t.nodeId}:${t.visit}`,Pe=t=>t&&(t.screen||t.paywall)?Oe(t):"";function Ie(){let t=e.client.view;O.disabled=!V.active&&(S>0||!!e.client.pendingCommand||!t?.canBack||t.stopped||!["running","waiting"].includes(t.status)||!Pe(t)||k!==Pe(t))}async function We(t){if(!t)return;let s=e.client.view;await t;let l=e.client.view;if(!s||!l||l.id!==s.id||l.nodeId!==s.nodeId||l.visit!==s.visit||l.stopped||!["running","waiting"].includes(l.status))throw new I("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}async function Re(t,s=!1){if(!((S||ae||re||B)&&!s||C||V.active&&!s)){S++,d.setAttribute("aria-busy","true"),Ie(),N.hidden=!0,Ce=null;try{if(s||await We(Se.inFlight),C)return;let l=await t();C||await fe(e.client.view??l.run)}catch(l){le(l,e.client.pendingCommand?.requestId??null)}finally{S=Math.max(0,S-1),d.setAttribute("aria-busy",String(S>0)),C||(M.hidden=e.client.pendingCommand===null,Ie())}}}function qe(){je.schedule()}async function He(){if(!(C||ne||S)){if(V.active){await V.open(V.receipt);return}ne=!0;try{let t=e.client.pendingCommand;t&&e.client.settle&&await e.client.settle(t.requestId);let s=e.client.view,l=Ne.queries,te=await e.client.get(s?.screen&&Object.keys(l).length?{nodeId:s.nodeId,visit:s.visit,revision:s.revision,components:l}:void 0);!C&&l===Ne.queries&&await fe(e.client.view??te.run)}catch(t){le(t)}finally{ne=!1}}}function Ae(t,s){if(u?.active){let te=u;return te.setDismissHandler(()=>Be(te)),te}let l=Ve(n,e,"funnel",()=>Be(l));return u=l,l.start(t,s),l}function Be(t){C||W||(W=!0,t.finish("dismissed"),ge(),d.hidden=!0,e.client.view?be().finally(ue):ue())}function Ge(){clearTimeout(K?.timeout),K=void 0}function ge(){Ge(),h?.abort(),h=void 0,w?.destroy(),w=null,A?.destroy(),A=null,Q?.(),Q=void 0,F.open&&F.close(),q.replaceChildren(),X="",k="",x="",se=""}function Qe(t){let s=t.screen?.presentation;if(!s||s.type==="inline"){F.open&&F.close(),d.parentElement!==n&&n.append(d);return}d.parentElement!==F&&(F.append(d),n.append(F));let l={sm:420,md:640,lg:900};F.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in s?l[s.size]+"px":"100vw"}`,F.setAttribute("aria-label",(j?.screen===t.screen?.content.document.name?j?.label:void 0)??w?.document?.name??t.screen?.content.document.name??"Funnel")}async function hn(t){if(C||W||ae&&(Fe()||["running","waiting"].includes(t.status)))return;U=t,Ce&&e.client.pendingCommand?.requestId!==Ce&&(N.hidden=!0,Ce=null);let s=t.locale.startsWith("zh");if(D.textContent=s?"\u56DE\u770B":"History",D.hidden=!e.client.review,O.textContent=V.active?s?"\u8FD4\u56DE\u5F53\u524D":"Return to current":s?"\u8FD4\u56DE":"Back",G.textContent=s?"\u5173\u95ED":"Close",M.textContent=s?"\u91CD\u8BD5":"Retry",Ie(),M.hidden=e.client.pendingCommand===null,c.textContent=t.pendingRequest?s?"\u6B63\u5728\u5904\u7406":"Processing":t.instruction?.type==="wait"?s?"\u7B49\u5F85\u4E2D":"Waiting":"",i!==`${t.revision}:${t.visit}:${t.status}:${t.stopped}`&&(i=`${t.revision}:${t.visit}:${t.status}:${t.stopped}`,oe(e.onState,structuredClone(t))),C||W)return;if((!t.pendingRequest||ae&&t.status==="closed")&&["closed","ineligible","failed"].includes(t.status)){ue();return}if(t.stopped||e.client.configurationReady===!1){V.stop(),ge(),u?.finish("skipped"),d.hidden=!0,qe();return}if(d.hidden=!1,V.active){qe();return}let l=Pe(t),te=e.client.view;if(te&&te.revision>t.revision&&Pe(te)!==l)return;let Je=!t.instruction&&!t.pendingRequest&&t.nodeType==="screen"&&["running","waiting"].includes(t.status);l!==X&&(X&&u?.finish("dismissed"),ge(),X=l,pe={...t.answers},Ne.reset());let me=Oe(t);if(J===me){d.hidden=!0;return}if(Je&&!l){d.hidden=!0;let E=Ae(!0,t.locale);!C&&!W&&K?.key!==me&&(Ge(),K={key:me,timeout:setTimeout(()=>{let g=e.client.view;if(!E.active||!g||Oe(g)!==me)return;J=me;let ee=new Error("Funnel screen preparation timed out");E.finish("error",ee),ge(),le(ee)},De)}),qe();return}Ge();let ie=E=>{let g=e.client.view;return!C&&!W&&!ye&&!E.aborted&&e.client.configurationReady!==!1&&!!g&&!g.stopped&&!["closed","ineligible","failed"].includes(g.status)&&Pe(g)===l},Z=(E,g)=>{ie(g)&&(J=l,u?.finish("error",E),ge(),d.hidden=!0,le(E))};if(l||(Qe(t),t.instruction?.type!=="event"&&t.instruction?.type!=="open_url"&&u?.finish("skipped")),t.screen){let E=t.screen.content;if(!w){let z=t.screen.presentation.type!=="inline",we=Ae(z,t.locale);if(C||W)return;let de=(h=new AbortController).signal;Qe(t),Q=z?an(F):Me(d,n),w=f(q,{mode:"live",rendererUrl:e.client.webViewUrl,title:E.document.name,onAction(ce,ve={},Pn={}){if(V.active||!ie(de)||k!==l)return;pe={...pe,...Pn};let Rn=Object.fromEntries((t.screen?.inputs??[]).filter(({variable:Te})=>Object.hasOwn(pe,Te)).map(({variable:Te})=>[Te,pe[Te]]));Re(()=>e.client.submit({operation:"submit",...he(),input:{type:"screen",output:ce,answers:Rn,selection:ve}}))},onAnswers:ce=>{V.active||!ie(de)||k!==l||(pe={...pe,...ce})},onCustomerDataIntent:ce=>{V.active||!ie(de)||k!==l||Ne.intent(ce).catch(le)},onEscape:()=>{!ie(de)||k!==l||V.active||re||B||be()},onError:ce=>{let ve=new Error(ce);k===l?le(ve):Z(ve,de)},onRendered:ce=>{if(!(!ie(de)||k===l))try{we.present(ve=>{Q?.(),Q=void 0,ce&&(j={screen:E.document.name,label:ce},F.setAttribute("aria-label",ce)),z&&(F.showModal(),!ve&&e.loading!=="host"&&sn(F,t.screen.presentation.type)),k=l,Ie()}),ie(de)&&Se.report(l)}catch(ve){Z(ve,de)}}})}let g={capabilities:t.screen.capabilities,customerData:t.screen.customerData,parameters:t.parameters,serverInput:{bindings:t.screen.inputs,answers:pe,values:t.screen.values}},ee=JSON.stringify([E,t.locale,g.parameters,t.screen.inputs,t.screen.values]);if(ee!==x)w.update(E.document,t.locale,g),x=ee,L=JSON.stringify(g.capabilities),se=JSON.stringify(g.customerData);else{let z=JSON.stringify(g.capabilities);z!==L&&(w.updateCapabilities(g.capabilities),L=z),JSON.stringify(g.customerData)!==se&&(w.updateCustomerData(g.customerData),se=JSON.stringify(g.customerData))}let H=w;if(H)try{await(u?.wait(H.ready)??H.ready)}catch(z){h&&Z(z,h.signal)}}else if(t.paywall&&!A){let E=Ae(!0,t.locale);if(C||W)return;let g=(h=new AbortController).signal;Qe(t);let ee=await P(q,{loading:"host",signal:g,canInteract:()=>ie(g)&&!V.active&&!re&&!B,beforeAction:async()=>{S++;try{await We(Se.settled()),N.hidden=!0,Ce=null}finally{S=Math.max(0,S-1)}},start:()=>mn(e.client),onObservationChange:qe,onPurchase:e.onPurchase,onCheckoutUrl:e.onCheckoutUrl,checkoutNavigation:e.checkoutNavigation,resolveOfferId:e.resolveOfferId,onEvent:e.onEvent,onOpenUrl:H=>e.onOpenUrl?e.onOpenUrl({receiptId:t.paywall.receiptId,url:H,openIn:"same_window"}):o.defaultView?.location.assign(H),onAction:async H=>{if(V.active)return;let z=await e.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:e.client.view?.revision??t.revision,input:{type:"screen",output:H,answers:{}}});await fe(e.client.view??z.run)},onError:H=>{k===l?le(H):Z(H,g)}},{quoteError:H=>oe(e.onError,H),present(H){ie(g)&&(E.present(()=>{H(),k=l,Ie()}),ie(g)&&Se.report(l))},async dismiss(){C||g.aborted||V.active||re||B||!ae&&!ie(g)||(ae=!0,await be())}}).catch(H=>(Z(H,g),null));!ie(g)&&!(ae&&!C&&!g.aborted)?ee?.host?.destroy():ee&&(A=ee.host,A?.setSuspended(V.active))}if(C||W)return;Ie();let $=t.instruction;if($&&($.type==="open_url"||$.type==="event")&&!ke.has($.receiptId)){let E=o.createElement("button");E.type="button",E.textContent=$.type==="open_url"?`${s?"\u524D\u5F80":"Continue to"} ${new URL($.url).host}`:s?"\u7EE7\u7EED":"Continue",E.onclick=()=>{let g=he(),ee=$.type==="open_url"&&!e.onOpenUrl&&$.openIn==="new_window"?In($.url):null;Re(async()=>{let H="success";if($.type==="open_url")if(e.onOpenUrl)try{H=await e.onOpenUrl({receiptId:$.receiptId,url:$.url,openIn:$.openIn})===!1?"failed":"opened"}catch(we){oe(e.onError,we),H="failed"}else H=$.openIn==="new_window"&&!ee?"failed":"opened";if($.type==="event"){if(!e.onEvent)throw new I("EVENT_HANDLER_REQUIRED","Provide the event handler");await e.onEvent($.event)}if(C||e.client.view?.nodeId!==g.nodeId||e.client.view.visit!==g.visit)throw new I("PRECONDITION_FAILED","The client action visit changed");let z=await e.client.submit({operation:"submit",...g,input:{type:"client_action",receiptId:$.receiptId,outcome:H}});return ke.add($.receiptId),$.type==="open_url"&&!e.onOpenUrl&&$.openIn==="same_window"&&o.defaultView?.location.assign($.url),z})},u?.active?u.present(()=>q.replaceChildren(E)):q.replaceChildren(E)}!t.pendingRequest&&t.status==="completed"&&!ke.has(`complete:${t.id}`)&&(ke.add(`complete:${t.id}`),oe(e.onComplete,structuredClone(t))),qe()}function In(t){let s=o.defaultView?.open(t,"_blank")??null;return s&&(s.opener=null),s}function fe(t){return Ie(),a=a.catch(()=>{}).then(async()=>{try{await hn(t)}catch(s){throw u?.active&&(J=Oe(t),u.finish("error",s),ge(),d.hidden=!0),s}}),a}let bn=e.client.subscribe(t=>{b||(!ae&&(t.stopped||e.client.configurationReady===!1||X&&k!==X&&(Pe(t)!==X||["closed","ineligible","failed"].includes(t.status)))&&(ge(),u?.finish("dismissed"),d.hidden=!0),fe(t).catch(le))}),Cn=e.client.subscribeError?.(le);function be(t){if(ye)return ye;if(C||!t&&(re||B))return Promise.resolve();let s=!t&&Fe();return!s&&e.client.view&&!["running","waiting"].includes(e.client.view.status)?(U=e.client.view,ue(),Promise.resolve()):(ye=Re(async()=>{let l=s?await e.client.retry():await e.client.submit({operation:"close",...t??he()});return t&&xe(l),l},!0).then(()=>{let l=e.client.view;l?.status==="closed"&&!Fe()&&(U=l,ue())}).finally(()=>{ye=null}),ye)}function ue(){R?.destroy(),!C&&(C=!0,e.signal?.removeEventListener("abort",ue),r?.removeEventListener("abort",ue),u?.finish("dismissed"),je.destroy(),bn(),Cn?.(),ge(),V.stop(),F.remove(),d.remove(),y(),oe(e.onDismiss,U?structuredClone(U):null))}O.onclick=()=>{if(!O.disabled){if(V.active){V.exit();return}Re(()=>e.client.submit({operation:"back",...he()}))}},D.onclick=()=>{V.open()},G.onclick=()=>{u?.active?u.dismiss():re||be()},M.onclick=()=>{Fe()?be():Re(()=>e.client.retry())},F.addEventListener("cancel",t=>{t.preventDefault(),u?.active?u.dismiss():re||be()}),e.signal?.addEventListener("abort",ue,{once:!0}),r?.addEventListener("abort",ue,{once:!0});try{let t=e.client.view;if(t)((e.client.viewAgeMs??ze)>=ze||t.instruction?.type==="evaluate_segment")&&(p=He().finally(()=>{p=null})),await fe(t);else{d.hidden=!0;let s=Ae(e.client.view?.screen?.presentation.type!=="inline",e.client.view?.locale);if(C||W)throw new DOMException("Presentation cancelled","AbortError");let l=await s.wait(e.client.get(),De);b=!1,await fe(e.client.view??l.run)}}catch(t){throw u?.finish("error",t),ue(),t}return{destroy:ue,refresh:He,get recovery(){let t=$e();if(t)return t;if(!C&&!S&&!ae&&!re&&A){let s=A.recovery;if(s.type!=="native")return s}return{type:"recover",operationId:e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??B?.operationId??null,requestId:e.client.pendingCommand?.requestId??null}},prepareFallback(){if(re)return re;let t=$e();if(t)return Promise.resolve(t);let s=e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??B?.operationId??null,l=()=>({type:"recover",operationId:s,requestId:e.client.pendingCommand?.requestId??null});if(e.client.hasDurableJournal!==!0){let Z=A?.recovery;return Promise.resolve(Z&&Z.type!=="native"&&Z.type!=="cancel"?Z:l())}let te=(e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[])).some(Z=>Z.operation==="close");if(C&&!(te||B&&e.client.view?.status==="closed")||S||ne||ye||V.active||!A&&!B&&!te)return Promise.resolve(l());let Je=A,me=(async()=>{try{if(!B&&te){let E=await e.client.retry();return await fe(e.client.view??E.run),l()}if(!B){let E=await Je.prepareFallback();if(E.type!=="native")return E;if(e.client.hasDurableJournal!==!0)return l();B=E}let Z=e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[]);if(Z.length){let E=Z.find(ee=>ee.operation==="close");if(!E||!Y||E.requestId!==Y.requestId)return l();let g=await e.client.retry();xe(g),await fe(e.client.view??g.run)}else{let E=e.client.view,g=E?.paywall;if(!E||!g||g.selectionGeneration===void 0||(g.quote?.operationId??null)!==B.operationId||B.operationId!==null&&g.canReselect!==!0)return l();let ee=g.selectionGeneration,H=await e.client.get();await fe(e.client.view??H.run);let z=e.client.view,we=z?.paywall;if(!z||!we||!["running","waiting"].includes(z.status)||z.stopped||z.id!==E.id||z.nodeId!==E.nodeId||z.visit!==E.visit||we.receiptId!==g.receiptId||we.selectionGeneration!==ee||(we.quote?.operationId??null)!==B.operationId||B.operationId!==null&&we.canReselect!==!0||e.client.pendingPurchase||(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0)))return l();let de=he();Y={runId:z.id,operationId:B.operationId,revision:de.revision,requestId:de.requestId,nodeId:z.nodeId,visit:z.visit,receiptId:we.receiptId,selectionGeneration:ee,acknowledged:!1},await be(de)}let $=$e();return $?(ue(),$):l()}catch(Z){return le(Z),l()}})();re=me;let ie=()=>{re===me&&(re=null)};return me.then(ie,ie),me},review:V.open,exitReview:V.exit,get unappliedDrafts(){return V.drafts}}}function mt(n,v,m){return qn(n,v,m)}export{Dn as a,vn as b,qn as c,mt as d};
@@ -1 +1 @@
1
- import{i as ie}from"./chunk-B5JHPPR4.js";import{a as Z,c as ee,d as te,e as ne,g as re,h as oe,i as se,k as N}from"./chunk-CNIBGSVO.js";import{b as X}from"./chunk-2KOQBV3Y.js";import{r as V}from"./chunk-MYUYN7ZG.js";import"./chunk-PMCGTXGH.js";import"./chunk-7CFF6SWH.js";import"./chunk-HMRIMJ5W.js";import"./chunk-NZSLDALU.js";import"./chunk-UBKD6VMS.js";import{E as $,P as G,U as R,la as Y,ma as K}from"./chunk-5RXU57I5.js";import"./chunk-DOJE7VUR.js";import{a as p}from"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import"./chunk-ATMVXNDD.js";import{b as u}from"./chunk-WM27UTWT.js";import{a as h}from"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";var z=new WeakMap;function ce(s){let t={string:u.string(),number:u.number().finite(),boolean:u.boolean(),strings:u.array(u.string()),json:R}[s.type];return s.nullable?t.nullable():t}function ae(s,t){let f=u.record(u.string(),R).parse(s);if(Object.keys(f).length>40)throw new p("INVALID_REQUEST","Too many content inputs");for(let[m,r]of Object.entries(f))Y.parse({[m]:r});if(Object.keys(f).some(m=>!Object.hasOwn(t.inputs,m)))throw new p("INVALID_REQUEST","Undeclared content input");for(let[m,r]of Object.entries(t.inputs))if(Object.hasOwn(f,m))ce(r).parse(f[m]);else if(r.required)throw new p("INVALID_REQUEST",`Missing content input ${m}`);return f}async function Ae(s,t){return le(s,t,!1)}async function Se(s,t){return le(s,t,!0)}async function le(s,t,f){t.signal?.throwIfAborted();let m=X.parse(t.content),r=m.document;if(t.closeControl==="content"&&!r.screen.actions.some(e=>e.type==="event"&&e.close))throw new p("INVALID_REQUEST","An authored Close control requires a declared Close action");if(z.has(s))throw new p("CONFLICT","Content is already mounted in this container");let y=ae(t.inputs??{},r.contract),T=new Set(u.array(u.string()).max(40).parse(t.mutableInputs??[]));if(T.size!==(t.mutableInputs?.length??0)||[...T].some(e=>!Object.hasOwn(r.contract.inputs,e)))throw new p("INVALID_REQUEST","Mutable content inputs must name unique declared inputs");for(let e of Object.keys(r.contract.outputs))if(typeof t.actions[e]!="function")throw new p("INVALID_REQUEST",`Missing host handler for ${e}`);let M=K.parse(t.bindings??[]),d=s.ownerDocument,ue=s.clientHeight||d.defaultView?.innerHeight||800,P,w,a,_,x=r.kind==="popup",n=x?d.createElement("dialog"):null,c=d.createElement("div");if(c.dataset.indianaContent=r.kind,c.setAttribute("aria-label",r.name),c.style.cssText="width:100%;min-width:0",n){n.setAttribute("aria-label",r.name);let e=r.screen.presentation;n.style.cssText="box-sizing:border-box;padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto",e.type==="modal"||e.type==="sheet"?(n.style.width=`${$[e.size]}px`,e.type==="sheet"&&(n.style.margin="auto auto 0")):n.style.width="100vw",a=ee(n,r.screen,()=>{w?.resizeViewport(d.defaultView?.innerHeight||800,d.defaultView?.innerWidth||1024)}),n.append(c),s.append(n)}else s.append(c);let i=!1,A=!1,E=!1,S=!1,de=n?oe(n):se(c,s),D=re(s,t,r.kind,()=>{k()&&(b(),h(t.onDismiss))}),q,H,L=new Promise((e,o)=>{q=e,H=o});L.catch(()=>{});let g=null,I=structuredClone(r.screen),W=G(I,[t.locale,...d.defaultView?.navigator.languages??[]]),j=t.capabilities;I.actions=I.actions.map(e=>e.type==="event"?{...e,close:!1}:e);function b(){i||(i=!0,t.signal?.removeEventListener("abort",b),D.finish("dismissed"),H(new Error("Content preparation cancelled")),a?.destroy(),_?.(),w?.destroy(),n?.close(),n?.remove(),c.remove(),z.delete(s),n&&P?.())}let v=()=>{!E||!k()||(b(),h(t.onDismiss))};function k(){try{return t.canDismiss?.()!==!1}catch(e){return h(t.onError,e),!1}}if(n&&t.closeControl!=="content"){let e=d.createElement("button");e.type="button",e.textContent="\xD7",e.setAttribute("aria-label",t.locale?.startsWith("zh")?"\u5173\u95ED":"Close"),ne(e,r.screen.theme),e.addEventListener("click",v),n.prepend(e)}n&&a?.responsive&&(_=Z(n,v,k,t.locale?.startsWith("zh")?"\u5173\u95ED":"Close"),n.addEventListener("click",e=>{if(e.target!==n)return;let o=n.getBoundingClientRect();(e.clientX<o.left||e.clientX>o.right||e.clientY<o.top||e.clientY>o.bottom)&&v()})),n?.addEventListener("cancel",e=>{e.preventDefault(),v()}),n?.addEventListener("keydown",e=>{e.key==="Escape"&&(e.preventDefault(),v())});async function F(){if(i||!E||A||!g)return;let e=g;A=!0,c.setAttribute("aria-busy","true");try{await t.actions[e.actionId](structuredClone(e)),g=null}catch(o){i||h(t.onError,o)}finally{A=!1,i||c.removeAttribute("aria-busy")}}function J(){if(i)throw new p("CONFLICT","Content host has been destroyed");E||!S||(P??=N(d),D.present(e=>{de(),n&&(a?.latch(),n.showModal(),a?.responsive&&n.focus({preventScroll:!0}),!e&&t.loading!=="host"&&te(n,a?.type??r.screen.presentation.type,a?.responsive)),E=!0}))}function U(e){D.finish("error",e),H(e instanceof Error?e:new Error(String(e))),b()}let Q={destroy:b,show:J,get pendingAction(){return g?structuredClone(g):null},retryAction:F,updateInputs(e){if(i)throw new p("CONFLICT","Content host has been destroyed");let o=u.record(u.string(),R).parse(e),C=ae({...y,...o},r.contract);for(let l of Object.keys(o))if(!T.has(l)&&(!Object.hasOwn(y,l)||V(y[l])!==V(C[l])))throw new p("PRECONDITION_FAILED","This content input is frozen; prepare a new presentation");V(y)!==V(C)&&(w?.update(I,W,{capabilities:j,serverInput:{bindings:M,answers:{},values:C}}),y=C)},updateCapabilities(e){if(i)return;let o=structuredClone(e);w?.updateCapabilities(o),j=o}};z.set(s,Q),t.signal?.addEventListener("abort",b,{once:!0});try{if(t.signal?.throwIfAborted(),f||(P=N(d),D.start(x,t.locale??r.screen.strings.defaultLocale),i&&await L),w=ie(c,{mode:"live",rendererUrl:t.rendererUrl,title:r.name,viewportHeight:r.kind==="page"?ue:a?.responsive?d.defaultView?.innerHeight||800:void 0,...a?.responsive?{viewportWidth:d.defaultView?.innerWidth||1024,hostPresentation:()=>a.type}:{},onResize:e=>{i||a?.responsive&&(c.style.height=`${e}px`,c.style.overflow="clip",a.setContentHeight(e))},onRendered:e=>{if(!i&&(e&&n?.setAttribute("aria-label",e),!S))try{S=!0,f||J(),q()}catch(o){U(o),h(t.onError,o)}},onError:e=>{if(i)return;let o=new Error(e);S||U(o),h(t.onError,o)},onEscape:x?v:void 0,onAction:(e,o,C)=>{if(i||!E||A||g)return;let l=r.screen.actions.find(O=>O.id===e),B=r.contract.outputs[e];if(!(l?.type!=="event"||!B)&&!(l.close&&!k()))try{let O=ce(B).parse(Object.hasOwn(l.properties,"value")?l.properties.value:l.properties);g=structuredClone({requestId:crypto.randomUUID(),contentVersionId:m.id,actionId:e,event:l.event,value:O,selection:o??{},answers:C??{},requestedClose:l.close}),F()}catch(O){h(t.onError,O)}}}),w.update(I,W,{capabilities:j,serverInput:{bindings:M,answers:{},values:y}}),await Promise.race([w.ready,L]),f&&await L,i)throw new Error("Content preparation cancelled");return Q}catch(e){throw U(e),e}}export{Ae as mountContent,Se as prepareContent};
1
+ import{i as ie}from"./chunk-B5JHPPR4.js";import{a as Z,c as ee,d as te,e as ne,g as re,h as oe,i as se,k as N}from"./chunk-CNIBGSVO.js";import{b as X}from"./chunk-2KOQBV3Y.js";import{r as V}from"./chunk-MYUYN7ZG.js";import"./chunk-PMCGTXGH.js";import"./chunk-7CFF6SWH.js";import"./chunk-HMRIMJ5W.js";import"./chunk-MWDR5FEU.js";import"./chunk-UBKD6VMS.js";import{E as $,P as G,U as R,la as Y,ma as K}from"./chunk-5RXU57I5.js";import"./chunk-DOJE7VUR.js";import{a as p}from"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import"./chunk-SMIO7OG5.js";import{b as u}from"./chunk-WM27UTWT.js";import{a as h}from"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";var z=new WeakMap;function ce(s){let t={string:u.string(),number:u.number().finite(),boolean:u.boolean(),strings:u.array(u.string()),json:R}[s.type];return s.nullable?t.nullable():t}function ae(s,t){let f=u.record(u.string(),R).parse(s);if(Object.keys(f).length>40)throw new p("INVALID_REQUEST","Too many content inputs");for(let[m,r]of Object.entries(f))Y.parse({[m]:r});if(Object.keys(f).some(m=>!Object.hasOwn(t.inputs,m)))throw new p("INVALID_REQUEST","Undeclared content input");for(let[m,r]of Object.entries(t.inputs))if(Object.hasOwn(f,m))ce(r).parse(f[m]);else if(r.required)throw new p("INVALID_REQUEST",`Missing content input ${m}`);return f}async function Ae(s,t){return le(s,t,!1)}async function Se(s,t){return le(s,t,!0)}async function le(s,t,f){t.signal?.throwIfAborted();let m=X.parse(t.content),r=m.document;if(t.closeControl==="content"&&!r.screen.actions.some(e=>e.type==="event"&&e.close))throw new p("INVALID_REQUEST","An authored Close control requires a declared Close action");if(z.has(s))throw new p("CONFLICT","Content is already mounted in this container");let y=ae(t.inputs??{},r.contract),T=new Set(u.array(u.string()).max(40).parse(t.mutableInputs??[]));if(T.size!==(t.mutableInputs?.length??0)||[...T].some(e=>!Object.hasOwn(r.contract.inputs,e)))throw new p("INVALID_REQUEST","Mutable content inputs must name unique declared inputs");for(let e of Object.keys(r.contract.outputs))if(typeof t.actions[e]!="function")throw new p("INVALID_REQUEST",`Missing host handler for ${e}`);let M=K.parse(t.bindings??[]),d=s.ownerDocument,ue=s.clientHeight||d.defaultView?.innerHeight||800,P,w,a,_,x=r.kind==="popup",n=x?d.createElement("dialog"):null,c=d.createElement("div");if(c.dataset.indianaContent=r.kind,c.setAttribute("aria-label",r.name),c.style.cssText="width:100%;min-width:0",n){n.setAttribute("aria-label",r.name);let e=r.screen.presentation;n.style.cssText="box-sizing:border-box;padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto",e.type==="modal"||e.type==="sheet"?(n.style.width=`${$[e.size]}px`,e.type==="sheet"&&(n.style.margin="auto auto 0")):n.style.width="100vw",a=ee(n,r.screen,()=>{w?.resizeViewport(d.defaultView?.innerHeight||800,d.defaultView?.innerWidth||1024)}),n.append(c),s.append(n)}else s.append(c);let i=!1,A=!1,E=!1,S=!1,de=n?oe(n):se(c,s),D=re(s,t,r.kind,()=>{k()&&(b(),h(t.onDismiss))}),q,H,L=new Promise((e,o)=>{q=e,H=o});L.catch(()=>{});let g=null,I=structuredClone(r.screen),W=G(I,[t.locale,...d.defaultView?.navigator.languages??[]]),j=t.capabilities;I.actions=I.actions.map(e=>e.type==="event"?{...e,close:!1}:e);function b(){i||(i=!0,t.signal?.removeEventListener("abort",b),D.finish("dismissed"),H(new Error("Content preparation cancelled")),a?.destroy(),_?.(),w?.destroy(),n?.close(),n?.remove(),c.remove(),z.delete(s),n&&P?.())}let v=()=>{!E||!k()||(b(),h(t.onDismiss))};function k(){try{return t.canDismiss?.()!==!1}catch(e){return h(t.onError,e),!1}}if(n&&t.closeControl!=="content"){let e=d.createElement("button");e.type="button",e.textContent="\xD7",e.setAttribute("aria-label",t.locale?.startsWith("zh")?"\u5173\u95ED":"Close"),ne(e,r.screen.theme),e.addEventListener("click",v),n.prepend(e)}n&&a?.responsive&&(_=Z(n,v,k,t.locale?.startsWith("zh")?"\u5173\u95ED":"Close"),n.addEventListener("click",e=>{if(e.target!==n)return;let o=n.getBoundingClientRect();(e.clientX<o.left||e.clientX>o.right||e.clientY<o.top||e.clientY>o.bottom)&&v()})),n?.addEventListener("cancel",e=>{e.preventDefault(),v()}),n?.addEventListener("keydown",e=>{e.key==="Escape"&&(e.preventDefault(),v())});async function F(){if(i||!E||A||!g)return;let e=g;A=!0,c.setAttribute("aria-busy","true");try{await t.actions[e.actionId](structuredClone(e)),g=null}catch(o){i||h(t.onError,o)}finally{A=!1,i||c.removeAttribute("aria-busy")}}function J(){if(i)throw new p("CONFLICT","Content host has been destroyed");E||!S||(P??=N(d),D.present(e=>{de(),n&&(a?.latch(),n.showModal(),a?.responsive&&n.focus({preventScroll:!0}),!e&&t.loading!=="host"&&te(n,a?.type??r.screen.presentation.type,a?.responsive)),E=!0}))}function U(e){D.finish("error",e),H(e instanceof Error?e:new Error(String(e))),b()}let Q={destroy:b,show:J,get pendingAction(){return g?structuredClone(g):null},retryAction:F,updateInputs(e){if(i)throw new p("CONFLICT","Content host has been destroyed");let o=u.record(u.string(),R).parse(e),C=ae({...y,...o},r.contract);for(let l of Object.keys(o))if(!T.has(l)&&(!Object.hasOwn(y,l)||V(y[l])!==V(C[l])))throw new p("PRECONDITION_FAILED","This content input is frozen; prepare a new presentation");V(y)!==V(C)&&(w?.update(I,W,{capabilities:j,serverInput:{bindings:M,answers:{},values:C}}),y=C)},updateCapabilities(e){if(i)return;let o=structuredClone(e);w?.updateCapabilities(o),j=o}};z.set(s,Q),t.signal?.addEventListener("abort",b,{once:!0});try{if(t.signal?.throwIfAborted(),f||(P=N(d),D.start(x,t.locale??r.screen.strings.defaultLocale),i&&await L),w=ie(c,{mode:"live",rendererUrl:t.rendererUrl,title:r.name,viewportHeight:r.kind==="page"?ue:a?.responsive?d.defaultView?.innerHeight||800:void 0,...a?.responsive?{viewportWidth:d.defaultView?.innerWidth||1024,hostPresentation:()=>a.type}:{},onResize:e=>{i||a?.responsive&&(c.style.height=`${e}px`,c.style.overflow="clip",a.setContentHeight(e))},onRendered:e=>{if(!i&&(e&&n?.setAttribute("aria-label",e),!S))try{S=!0,f||J(),q()}catch(o){U(o),h(t.onError,o)}},onError:e=>{if(i)return;let o=new Error(e);S||U(o),h(t.onError,o)},onEscape:x?v:void 0,onAction:(e,o,C)=>{if(i||!E||A||g)return;let l=r.screen.actions.find(O=>O.id===e),B=r.contract.outputs[e];if(!(l?.type!=="event"||!B)&&!(l.close&&!k()))try{let O=ce(B).parse(Object.hasOwn(l.properties,"value")?l.properties.value:l.properties);g=structuredClone({requestId:crypto.randomUUID(),contentVersionId:m.id,actionId:e,event:l.event,value:O,selection:o??{},answers:C??{},requestedClose:l.close}),F()}catch(O){h(t.onError,O)}}}),w.update(I,W,{capabilities:j,serverInput:{bindings:M,answers:{},values:y}}),await Promise.race([w.ready,L]),f&&await L,i)throw new Error("Content preparation cancelled");return Q}catch(e){throw U(e),e}}export{Ae as mountContent,Se as prepareContent};
@@ -1 +1 @@
1
- import{b as y}from"./chunk-GCNYVAYY.js";import{d as A}from"./chunk-HPXSHXSB.js";import"./chunk-JGG4R75K.js";import{f as g,g as I}from"./chunk-CNIBGSVO.js";import"./chunk-4CH6FLDU.js";import"./chunk-ECMWY3G2.js";import"./chunk-WZLEYOWM.js";import"./chunk-6DBYFYEU.js";import"./chunk-GIV4FOOW.js";import"./chunk-MYUYN7ZG.js";import"./chunk-C6JRUYKW.js";import"./chunk-PMCGTXGH.js";import"./chunk-7CFF6SWH.js";import"./chunk-PWQ5BHBJ.js";import"./chunk-HMRIMJ5W.js";import"./chunk-NZSLDALU.js";import"./chunk-UBKD6VMS.js";import"./chunk-5RXU57I5.js";import"./chunk-DOJE7VUR.js";import{a as c}from"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import"./chunk-SLUA7ABW.js";import"./chunk-4IJU33UM.js";import"./chunk-3VUPVXAV.js";import"./chunk-ATMVXNDD.js";import"./chunk-WM27UTWT.js";import{a as i}from"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";var d=new WeakMap;function T(h,e){let P=d.get(e.client);if(P)return P;let m=Promise.resolve().then(async()=>{let n=!1,s,w,E=!1,v=()=>{},r=e.signal?AbortSignal.any([e.signal,e.client.identitySignal]):e.client.identitySignal,u=()=>{d.get(e.client)===m&&d.delete(e.client),r.removeEventListener("abort",f),v()},o=I(h,e,"funnel",f);function f(){n||(n=!0,o.finish("dismissed"),s?s.destroy():(u(),i(e.onDismiss,null)))}r.addEventListener("abort",f,{once:!0});try{let b=function(){!n&&!r.aborted&&!E&&w&&e.client.recovery.status==="complete"&&(E=!0,i(e.onComplete,structuredClone(w)))};var C=b;r.throwIfAborted(),o.start(!0,e.start?.locale);let l=await o.wait(e.start?e.client.start(e.start):e.client.refresh(),g);r.throwIfAborted();let O=e.client.controller;return l.mode!=="run"||l.status==="blocked"||!O?(o.finish("skipped"),u(),null):(r.removeEventListener("abort",f),v=e.client.subscribe(b),s=await A(h,{...e,client:O,signal:r,checkoutNavigation:"after_confirmation",onCheckoutUrl(t){if(r.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");if(y(e.client.recovery)!==t)throw new c("PURCHASE_PENDING","Checkout differs from the original recovery proof");return e.onCheckoutUrl?e.onCheckoutUrl(t):h.ownerDocument.defaultView?.location.assign(t)},async resolveOfferId(t){if(r.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");let a=e.client.attempt;if(!a)throw new c("PURCHASE_PENDING","Read the original Start before selecting an offer");let F=await e.resolveOfferId?.(t,a);if(r.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");if(e.client.attempt?.requestId!==a.requestId)throw new c("PURCHASE_STORAGE_CONFLICT","The original purchase changed while selecting an offer");return F},onComplete(t){w=t,b()},onError(t){i(e.onError,t),t instanceof c&&t.status===401&&!r.aborted&&e.client.refresh().catch(a=>i(e.onError,a))},onDismiss(t){n=!0,u(),i(e.onDismiss,t)}},o),n||r.aborted?(s.destroy(),null):s)}catch(l){if(n)return null;throw o.finish("error",l),u(),i(e.onError,l),l}});return d.set(e.client,m),m}export{T as showFunnelPurchase};
1
+ import{b as y}from"./chunk-DCCM7FYR.js";import{d as A}from"./chunk-YSNMXK4R.js";import"./chunk-JGG4R75K.js";import{f as g,g as I}from"./chunk-CNIBGSVO.js";import"./chunk-3FPYCF7Z.js";import"./chunk-ECMWY3G2.js";import"./chunk-UHI7SPHK.js";import"./chunk-G7NSECIG.js";import"./chunk-GIV4FOOW.js";import"./chunk-MYUYN7ZG.js";import"./chunk-C6JRUYKW.js";import"./chunk-PMCGTXGH.js";import"./chunk-7CFF6SWH.js";import"./chunk-PWQ5BHBJ.js";import"./chunk-HMRIMJ5W.js";import"./chunk-MWDR5FEU.js";import"./chunk-UBKD6VMS.js";import"./chunk-5RXU57I5.js";import"./chunk-DOJE7VUR.js";import{a as c}from"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import"./chunk-SLUA7ABW.js";import"./chunk-DCIGO3NJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-SMIO7OG5.js";import"./chunk-WM27UTWT.js";import{a as i}from"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";var d=new WeakMap;function T(h,e){let P=d.get(e.client);if(P)return P;let m=Promise.resolve().then(async()=>{let n=!1,s,w,E=!1,v=()=>{},r=e.signal?AbortSignal.any([e.signal,e.client.identitySignal]):e.client.identitySignal,u=()=>{d.get(e.client)===m&&d.delete(e.client),r.removeEventListener("abort",f),v()},o=I(h,e,"funnel",f);function f(){n||(n=!0,o.finish("dismissed"),s?s.destroy():(u(),i(e.onDismiss,null)))}r.addEventListener("abort",f,{once:!0});try{let b=function(){!n&&!r.aborted&&!E&&w&&e.client.recovery.status==="complete"&&(E=!0,i(e.onComplete,structuredClone(w)))};var C=b;r.throwIfAborted(),o.start(!0,e.start?.locale);let l=await o.wait(e.start?e.client.start(e.start):e.client.refresh(),g);r.throwIfAborted();let O=e.client.controller;return l.mode!=="run"||l.status==="blocked"||!O?(o.finish("skipped"),u(),null):(r.removeEventListener("abort",f),v=e.client.subscribe(b),s=await A(h,{...e,client:O,signal:r,checkoutNavigation:"after_confirmation",onCheckoutUrl(t){if(r.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");if(y(e.client.recovery)!==t)throw new c("PURCHASE_PENDING","Checkout differs from the original recovery proof");return e.onCheckoutUrl?e.onCheckoutUrl(t):h.ownerDocument.defaultView?.location.assign(t)},async resolveOfferId(t){if(r.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");let a=e.client.attempt;if(!a)throw new c("PURCHASE_PENDING","Read the original Start before selecting an offer");let F=await e.resolveOfferId?.(t,a);if(r.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");if(e.client.attempt?.requestId!==a.requestId)throw new c("PURCHASE_STORAGE_CONFLICT","The original purchase changed while selecting an offer");return F},onComplete(t){w=t,b()},onError(t){i(e.onError,t),t instanceof c&&t.status===401&&!r.aborted&&e.client.refresh().catch(a=>i(e.onError,a))},onDismiss(t){n=!0,u(),i(e.onDismiss,t)}},o),n||r.aborted?(s.destroy(),null):s)}catch(l){if(n)return null;throw o.finish("error",l),u(),i(e.onError,l),l}});return d.set(e.client,m),m}export{T as showFunnelPurchase};
@@ -1 +1 @@
1
- import{c as a,d as b}from"./chunk-HPXSHXSB.js";import"./chunk-JGG4R75K.js";import"./chunk-CNIBGSVO.js";import"./chunk-PMCGTXGH.js";import"./chunk-7CFF6SWH.js";import"./chunk-PWQ5BHBJ.js";import"./chunk-HMRIMJ5W.js";import"./chunk-NZSLDALU.js";import"./chunk-UBKD6VMS.js";import"./chunk-5RXU57I5.js";import"./chunk-DOJE7VUR.js";import"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import"./chunk-SLUA7ABW.js";import"./chunk-4IJU33UM.js";import"./chunk-ATMVXNDD.js";import"./chunk-WM27UTWT.js";import"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as showFunnelRun,b as showObservedFunnelRun};
1
+ import{c as a,d as b}from"./chunk-YSNMXK4R.js";import"./chunk-JGG4R75K.js";import"./chunk-CNIBGSVO.js";import"./chunk-PMCGTXGH.js";import"./chunk-7CFF6SWH.js";import"./chunk-PWQ5BHBJ.js";import"./chunk-HMRIMJ5W.js";import"./chunk-MWDR5FEU.js";import"./chunk-UBKD6VMS.js";import"./chunk-5RXU57I5.js";import"./chunk-DOJE7VUR.js";import"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import"./chunk-SLUA7ABW.js";import"./chunk-DCIGO3NJ.js";import"./chunk-SMIO7OG5.js";import"./chunk-WM27UTWT.js";import"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as showFunnelRun,b as showObservedFunnelRun};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as cn,c as dn}from"./chunk-GCNYVAYY.js";import{a as Ue,b as fn,c as Ie}from"./chunk-HPXSHXSB.js";import{a as pe}from"./chunk-JGG4R75K.js";import"./chunk-CNIBGSVO.js";import{a as en,c as sn,d as un}from"./chunk-I5RVPWVD.js";import"./chunk-4CH6FLDU.js";import{a as an}from"./chunk-4RQNPBLW.js";import"./chunk-ECMWY3G2.js";import{h as Qe,i as on,k as ln}from"./chunk-UNG42D7U.js";import"./chunk-BZSKOOMM.js";import"./chunk-LPDUK7HT.js";import{F as Re,e as Ve,g as je,h as fe,i as me,j as Ge,x as nn}from"./chunk-WZLEYOWM.js";import{a as qe}from"./chunk-6DBYFYEU.js";import"./chunk-GIV4FOOW.js";import"./chunk-MYUYN7ZG.js";import{B as Fe,D as Oe,E as xe,G as De,H as Te,I as ke,J as Be,K as Ee,L as He,x as ve,y as Me,z as Ne}from"./chunk-C6JRUYKW.js";import{$ as Le,l as Ye,m as Ze,n as We}from"./chunk-PMCGTXGH.js";import"./chunk-7CFF6SWH.js";import{c as tn,d as rn}from"./chunk-PWQ5BHBJ.js";import"./chunk-HMRIMJ5W.js";import{b as be}from"./chunk-NZSLDALU.js";import"./chunk-UBKD6VMS.js";import"./chunk-5RXU57I5.js";import"./chunk-DOJE7VUR.js";import{a as H}from"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import{a as ge,c as ce}from"./chunk-J6KIN4RH.js";import"./chunk-SLUA7ABW.js";import{c as ye,d as he}from"./chunk-4IJU33UM.js";import"./chunk-3VUPVXAV.js";import"./chunk-ATMVXNDD.js";import{b as K}from"./chunk-WM27UTWT.js";import{a as Z}from"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";var y=class extends Error{constructor(m,k=0,_=!1,E="fix_request"){super(m);this.code=m;this.status=k;this.retryable=_;this.recovery=E;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function mn(n,A){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");let m=n.body?.getReader();if(!m)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");let k=()=>{m.cancel().catch(()=>{})};A.addEventListener("abort",k,{once:!0});let _=0,E="",r=new TextDecoder("utf-8",{fatal:!0});try{for(A.throwIfAborted();;){let i=await m.read();if(A.throwIfAborted(),i.done)break;if(_+=i.value.byteLength,_>262144)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");E+=r.decode(i.value,{stream:!0})}return E+=r.decode(),JSON.parse(E)}catch(i){throw A.throwIfAborted(),i instanceof y?i:new y("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{A.removeEventListener("abort",k),await m.cancel().catch(()=>{}),m.releaseLock()}}function pn(n){let A=Oe.parse(n.origin),m=xe.parse(n.manifest),k={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let c of["projectId","environmentId","environment"])if(m[c]!==n.scope[c])throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");let _=n.customerId===void 0?null:K.uuid().parse(n.customerId),E=0,r=null,i=null,g=new AbortController,I=n.fetch??globalThis.fetch;async function U(c,s,p,w,h){if(!m.capabilities.includes(c))throw new y("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let d=Fe[c];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(d.authority))throw new y("MERCHANT_BRIDGE_FORBIDDEN",403);let l=E,o=AbortSignal.any([g.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...w?[w]:[]]);o.throwIfAborted();let N=new Headers(await n.headers?.());if(o.throwIfAborted(),l!==E)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(N.get("authorization")??"")||N.has("X-Indiana-Bridge-Signature")||N.has("X-Indiana-Bridge-Key-Id"))throw new y("MERCHANT_BRIDGE_FORBIDDEN",403);N.set(Ne,String(ve)),N.set("Accept","application/json");let P=crypto.randomUUID();N.set("X-Request-Id",P),N.set("Content-Type","application/json");let b=await I(A+Me,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:N,signal:o,body:JSON.stringify({bridgeVersion:ve,requestId:P,command:d.command,scope:k,data:h??(p===void 0?{}:{operationId:p})})}),V=await mn(b,o);if(o.throwIfAborted(),l!==E)throw new DOMException("Merchant identity changed","AbortError");if(!b.ok){let D=He.safeParse(V);throw!D.success||D.data.scope.projectId!==n.scope.projectId||D.data.scope.environment!==n.scope.environment||D.data.scope.environmentId!==n.scope.environmentId||D.data.requestId!==P||D.data.command!==d.command?new y("MERCHANT_BRIDGE_INVALID_RESPONSE",b.status):new y(D.data.error.code,b.status,D.data.error.retryable,D.data.error.recovery)}let u=De(K.unknown()).safeParse(V);if(!u.success||u.data.scope.projectId!==n.scope.projectId||u.data.scope.environment!==n.scope.environment||u.data.scope.environmentId!==n.scope.environmentId||u.data.requestId!==P||u.data.command!==d.command)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE",b.status);let j=s.safeParse(u.data.data);if(!j.success)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE",b.status);return j.data}function M(){if(!_)throw new y("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return _}async function z(c,s,p,w){let h=M();if(w!==void 0&&Ee.parse({operationId:w,customerId:h}),!m.capabilities.includes(c))throw new y("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let d=E,l=AbortSignal.any([g.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...s?[s]:[]]);l.throwIfAborted();let o,N=new Promise((P,b)=>{o=()=>b(l.reason),l.addEventListener("abort",o,{once:!0})});try{let b=p(async()=>{let u=await import("./merchant-bridge-contracts-N3Q4W6ZU.js");if(l.throwIfAborted(),d!==E||_!==h)throw new DOMException("Merchant identity changed","AbortError");return u},l),V=await Promise.race([b,N]);return l.throwIfAborted(),V}finally{l.removeEventListener("abort",o)}}async function J(c,s,p,w){let h=M(),d=Ee.parse({operationId:p,customerId:h}),l=await U(c,s,d.operationId,w,d);if(l.customerId!==h||l.operationId!==d.operationId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return l}return{async readPresentation(c){let s=await U("presentation",ke,void 0,c);if(i!==null&&i!==s.nativeUserId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(s.presentation&&_!==null&&s.presentation.customerId!==_)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=s.nativeUserId,r=s.presentation,s},async createSession(c){let s=await U("session",Te,void 0,c);if(i!==null&&i!==s.nativeUserId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(_!==null&&_!==s.session.customerId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(r&&r.customerId!==s.session.customerId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return _=s.session.customerId,i=s.nativeUserId,s.session},async reportPresentation(c,s){let p=M(),w=Be.parse(c);if(!r||r.customerId!==p||r.decisionId!==w.decisionId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return U("presentation_events",K.strictObject({queued:K.literal(!0)}),void 0,s,w)},async readCustomerCommerce(c){let s=M(),p=await z("customer_commerce",c,async(w,h)=>{let[d,l]=await Promise.all([w(),U("customer_commerce",K.unknown(),void 0,h)]),o=d.merchantBridgeCommerceSchema.safeParse(l);if(!o.success)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");return o.data});if(p.customerId!==s)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return p},async executePurchase(c,s){let p=await z("purchases",s,async(w,h)=>J("purchases",(await w()).merchantBridgeOperationSchema,c,h),c);if(p.type!=="purchase")throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");return p},readOperation:(c,s)=>z("operation_status",s,async(p,w)=>J("operation_status",(await p()).merchantOperationLookupSchema,c,w),c),async executeSubscriptionChange(c,s){let p=await z("subscription_changes",s,async(w,h)=>J("subscription_changes",(await w()).merchantBridgeOperationSchema,c,h),c);if(p.type!=="subscription_change")throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");return p},reset(){E++,g.abort(),g=new AbortController,_=null,r=null,i=null}}}var $e=K.strictObject({command:me,target:je,runId:K.uuid().optional(),expiresAt:K.iso.datetime({offset:!0}).optional()}).refine(n=>n.command.release===n.target.release),Ke=K.strictObject({schemaVersion:K.literal(1),entries:K.array($e).max(4e3)});function ze(n){let A=!1,m=()=>{A||n.unavailable(),A=!0};function k(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function _(r){let i=k()?.getItem(r);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return Ke.parse(JSON.parse(i)).entries}function E(r,i){let g=k();if(!g)return;if(!i.length)return g.removeItem(r);let I=JSON.stringify(Ke.parse({schemaVersion:1,entries:i}));if(I.length>1048576)throw Error("Entry recovery is too large");g.setItem(r,I)}return{load(){try{let r=n.binding();if(!r||n.storage===!1)return;let i="indiana.funnel.entries.v1."+JSON.stringify(r);return{key:i,entries:_(i)}}catch{m();return}},retain(r,i){if(r)try{let g=$e.parse(i);E(r,[..._(r).filter(I=>I.command.funnelId!==g.command.funnelId),g])}catch{m()}},forget(r,i){if(r)try{E(r,_(r).filter(g=>g.command.requestId!==i))}catch{m()}}}}var we=n=>["running","waiting"].includes(n.status)&&!n.pendingRequest&&(n.stopped||!n.screen&&!n.paywall&&n.instruction?.type==="wait"&&n.instruction.kind!=="operation");function yn(n){let A=ye(n.baseUrl),m=n.scope,k=be(n),_=n.fetch??globalThis.fetch.bind(globalThis),E,r=!1,i=!1,g=0,I=0,U="",M=0,z=0,J=0,c=!1,s,p=!0,w,h,d,l,o,N=-1,P,b=e=>{P===e&&(P=void 0,q())},V=new Set,u=(e,a)=>Z(n.onStatus,e,a),j=new Set,D=ze({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[A,m.projectId,m.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>u("recovery_unavailable")}),X=e=>D.forget(e.storageKey,e.command.requestId);function re(e,a){a&&(e.runId=a.id,e.expiresAt=a.runExpiresAt),D.retain(e.storageKey,{command:e.command,target:e.target,...e.runId&&{runId:e.runId},...e.expiresAt&&{expiresAt:e.expiresAt}})}function ee(){let e=o;o=void 0,e?.host.destroy(),e?.slot.remove(),e?.client.reset(),q()}let de=()=>P!==void 0||o!==void 0&&!o.background;function t(e,a){if(o?.client!==e)return;re(o.recovery,a);let f=we(a);o.slot.hidden=f,f!==o.background&&(o.background=f,f?u("run_background",o.entryId):N=I,q())}function R(e,a,f){let S=e.client.view;if(!a||e.background||!S?.screen||S.paywall||S.pendingRequest||S.stopped||S.status!=="waiting")return;let O=Le.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:S.nodeId,visit:S.visit,revision:S.revision,customerToken:a}),$=be({...n,session:void 0});$.requestWithCredential("funnels",O,e.runToken,{keepalive:f}).then(()=>X(e.recovery)).catch(()=>{}).finally(()=>$.dispose())}let F=()=>{o&&R(o,n.session.peek(),!0)},L=()=>Date.now()<z&&performance.now()<J;function G(e){if(e.target.release!==n.appManifestRelease||!L())return!1;try{return ce(e.target.render,document,location.pathname,()=>{})}catch{return u("incompatible",e.id),!1}}function ne(e){if(r||e.epoch!==M||e.visit!==I||document.visibilityState==="hidden")return!1;try{return ce(e.target.render,document,location.pathname,()=>{})}catch{return!1}}async function oe(e){if(de()){u("in_progress",e.id);return}if(!n.session.peek()){u("identity_required",e.id);return}let a=D.load(),f=a?.entries.find(O=>O.command.funnelId===e.funnelId&&(!O.expiresAt||Date.parse(O.expiresAt)>Date.now()));if(f){if(!ae(f)){u("recovery_pending",e.id);return}let O={...f,storageKey:a.key,epoch:M,visit:I};j.add(O.command.requestId),P=O,await te(O);return}let S={freshStart:!0,command:me.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:crypto.randomUUID(),locale:document.documentElement.lang||"en"}),epoch:M,visit:I,target:e.target,storageKey:a?.key};j.add(S.command.requestId),P=S,await te(S)}async function te(e){if(e.dispatching)return;e.dispatching=!0;let a=e.freshStart===!0;e.freshStart=!1;let f,S=!1,O=!1;async function $(T){if(e.epoch!==M)return;let v=T.view;if(!(e.storageKey&&v&&(we(v)||v.paywall||v.pendingRequest))&&v&&["running","waiting"].includes(v.status))try{await T.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:v.nodeId,visit:v.visit,revision:v.revision}),X(e)}catch(x){if(!(x instanceof H&&x.code==="FORBIDDEN"))throw x}}try{re(e),u("starting",e.command.entryId);let T=await k.request("funnels",e.command),v=Ge.safeParse(T);if(v.success){if(v.data.scope.projectId!==m.projectId||v.data.scope.environment!==m.environment)throw new H("SCOPE_MISMATCH","Entry scope changed");e.epoch===M&&u(v.data.reason,e.command.entryId),X(e),b(e);return}let x=Ve.parse(T);if(!x.runToken||x.scope.projectId!==m.projectId||x.scope.environment!==m.environment||x.run.source.type!=="funnel"||x.run.source.id!==e.command.funnelId||x.run.source.versionId!==e.command.versionId||e.runId!==void 0&&x.run.id!==e.runId)throw new H("INVALID_RESPONSE","Invalid entry Run");if(e.epoch!==M){b(e),u("identity_changed",e.command.entryId);return}re(e,x.run);let C=Re({...n,runToken:x.runToken,funnelId:e.command.funnelId,initialResponse:a?T:void 0});f=C,O=!0,await C.get(),O=!1;let Y=C.view;if(!Y||Y.id!==x.run.id||Y.source.type!=="funnel"||Y.source.id!==e.command.funnelId||Y.source.versionId!==e.command.versionId)throw new H("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(Y.status)){X(e),b(e),u("run_ended",e.command.entryId);return}if(!ne(e)){await $(C),u("left_screen",e.command.entryId),b(e);return}let se=!1,Ae=!1;if(o&&!o.background){await $(C),u("in_progress",e.command.entryId),b(e);return}o&&ee();let Q=document.createElement("div");Q.hidden=we(Y),n.container.append(Q);let Ce=await Ie(Q,{...n.host,client:C,appManifestRelease:n.appManifestRelease,onState(B){t(C,B),Z(n.host?.onState,B)},onDismiss(B){se=!0,Q.remove(),B&&!["running","waiting"].includes(B.status)&&X(e),o?.client===C&&(o=void 0,C.reset(),q(),B&&B.status!=="completed"&&u("run_ended",e.command.entryId)),Z(n.host?.onDismiss,B)},onComplete(B){Ae=!0,X(e),o?.client===C&&ee(),Z(n.host?.onComplete,B)},onError(B){Z(n.host?.onError,B),o?.client===C&&B instanceof H&&B.code==="FORBIDDEN"&&(X(e),ee(),u("run_ended",e.command.entryId))}}).catch(B=>{throw Q.remove(),B});if(!ne(e)||se||Ae){Ce.destroy(),Q.remove(),ne(e)||await $(C),b(e);return}let le=we(C.view??Y);Q.hidden=le,o={host:Ce,client:C,slot:Q,entryId:e.command.entryId,background:le,runToken:x.runToken,owner:n.session.peek(),recovery:e},le||(N=e.visit),S=!0,b(e),u("started",e.command.entryId),le&&u("run_background",e.command.entryId)}catch(T){T instanceof H&&(!f||O&&T.code==="FORBIDDEN")&&T.status!==void 0&&T.status>=400&&T.status<500&&!T.retryable&&(X(e),b(e)),e.epoch===M&&!r&&(u("start_failed",e.command.entryId),Z(n.host?.onError,T))}finally{S||f?.reset(),e.dispatching=!1}}function ae(e){if(e.command.release!==n.appManifestRelease||e.target.release!==n.appManifestRelease)return!1;try{return ce(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function W(){if(de())return!1;let e=D.load();for(let a of e?.entries??[]){if(a.expiresAt&&Date.parse(a.expiresAt)<=Date.now()){D.forget(e.key,a.command.requestId);continue}if(a.command.requestId===o?.recovery.command.requestId||j.has(a.command.requestId)||!ae(a))continue;j.add(a.command.requestId);let f={...a,storageKey:e.key,epoch:M,visit:I};return P=f,te(f),!0}return!1}function ue(){if(c=!1,r||!i||document.visibilityState==="hidden")return;ie();let e=o!==void 0&&!o.background;if(e&&(N=I),!W()){if(!L()){p=!0;return}p=!1;for(let a of E?.entries??[]){let f=`${a.funnelId}:${a.id}`;if(!(a.event!=="screen_enter"||V.has(f)||!G(a))){if(!n.session.peek()){u("identity_required",a.id);continue}if(N===I){V.add(f),e&&u("in_progress",a.id);continue}if(P){u("in_progress",a.id);return}V.add(f),oe(a);break}}}}let q=()=>{!c&&!r&&(c=!0,queueMicrotask(ue))};function ie(){let e=location.origin+location.pathname;return e===U?!1:(U=e,I++,p=!0,V.clear(),j.clear(),!0)}function Je(){ie()&&q()}function Se(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let a=e.target;if(!(a instanceof Element)||a.closest("[data-indiana-funnel]"))return;let f=a.closest("button,a,input");if(!(!f||f.matches(":disabled,[aria-disabled='true']")||f.closest("[hidden],[inert],[aria-hidden='true']")))for(let S of E?.entries??[]){let O=S.target.button;if(!(S.event!=="button_click"||!O||!G(S))){try{let $=ge(document);if(!f.matches(O.selector)||$(O.selector,f)!==1)continue}catch{u("incompatible",S.id);continue}oe(S);break}}}async function _e(){if(r)return;if(s)return s;let e=++g,a=new AbortController;w=a;let f,S=new Promise((T,v)=>{f=()=>v(new H("TIMEOUT","Funnel entry configuration read cancelled or timed out")),a.signal.addEventListener("abort",f,{once:!0})}),O=setTimeout(()=>a.abort(),n.timeoutMs??5e3),$=(async()=>{let T=async()=>{let se=await _(`${A}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:a.signal});if(!se.ok)throw new H("SERVICE_UNAVAILABLE","Funnel entries unavailable",se.status);return fe.parse(await se.json())},v=await Promise.race([T(),S]),x=Date.parse(v.validatedAt),C=Date.parse(v.validUntil);if(v.scope.projectId!==m.projectId||v.scope.environment!==m.environment||v.scope.environmentId!==n.environmentId||v.release!==n.appManifestRelease||C<=Date.now()||x>Date.now()+5e3||C-x>6e4||C<=x)throw new H("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(r||e!==g)return;let Y=E===void 0;E=v,z=C,J=performance.now()+Math.min(C-Date.now(),6e4),(Y||p)&&q()})();s=$;try{await $}finally{clearTimeout(O),a.signal.removeEventListener("abort",f),s===$&&(s=void 0)}}async function Xe(){if(!(!i||r)){try{await _e()}catch{r||u("configuration_unavailable")}q()}}let Pe=pe({document,run:Xe,delay:()=>i&&!r?15e3:void 0});return{async start(){i||r||(i=!0,U=location.origin+location.pathname,h=he(Je),d=n.session.subscribeIdentity(()=>{M++,p=!0,P=void 0,V.clear(),N=-1,j.clear(),o&&R(o,o.owner,!1),ee(),q()}),l=new MutationObserver(q),l.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",Se,!0),addEventListener("pagehide",F),await Pe.refresh())},refresh:_e,async retry(){P&&!r&&P.epoch===M&&await te(P)},destroy(){r=!0,g++,Pe.destroy(),w?.abort(),l?.disconnect(),h?.(),d?.(),document.removeEventListener("click",Se,!0),removeEventListener("pagehide",F),F(),ee(),k.dispose(),E=void 0}}}function hn(n){let A=ye(n.baseUrl),m=n.fetch??globalThis.fetch.bind(globalThis),k,_=0,E=0,r=!1,i=!1,g=0,I=0,U=-1,M=!1,z="",J,c,s,p,w=new Set,h,d,l,o=(t,R)=>Z(n.onStatus,t,R),N=()=>Date.now()<_&&performance.now()<E;function P(t){try{return N()&&t.target.release===n.appManifestRelease&&ce(t.target.render,document,location.pathname,()=>{})}catch{return o("incompatible",t.id),!1}}function b(){let t=l;l=void 0,t?.host.destroy(),t?.slot.remove()}async function V(t){if(t.dispatching)return;t.dispatching=!0;let R=g;try{let F=await t.process.open({operation:"entry_start",funnelId:t.entry.funnelId,versionId:t.entry.versionId,entryId:t.entry.id,release:n.appManifestRelease,locale:n.locale??"en"});if(r||R!==g||d!==t)return;let L=document.createElement("div");n.container.append(L),U=I;let G=await Ie(L,{...n.host,client:F.controller,appManifestRelease:n.appManifestRelease,onDismiss(ne){l?.process===t.process&&(l=void 0,L.remove()),Z(n.host?.onDismiss,ne)}});if(r||R!==g||d!==t){G.destroy(),L.remove();return}l={entry:t.entry,process:t.process,host:G,slot:L},d=void 0,o("run_presented",t.entry.id)}catch(F){if(r||R!==g||d!==t)return;F instanceof H&&"result"in F?(d=void 0,t.process.destroy(),o("suppressed",t.entry.id),j()):o("entry_unavailable",t.entry.id)}finally{t.dispatching=!1}}function u(t){if(r||d||l||h||U===I||!P(t))return;let R=`${I}:${t.id}`;if(w.has(R))return;w.add(R);let F={entry:t,process:n.createProcess(t),visit:I};d=F,V(F)}function j(){M||r||(M=!0,queueMicrotask(()=>{if(M=!1,!(r||document.visibilityState==="hidden"||!N()||d||l||h||U===I)){for(let t of k?.entries??[])if(t.event==="screen_enter"&&P(t)){u(t);break}}}))}function D(t){if(!t.isTrusted||t.defaultPrevented||!(t.target instanceof Element)||d||l||h||U===I)return;let R=ge(document,()=>{});for(let F of k?.entries??[]){let L=F.target.button;if(F.event!=="button_click"||!L||!P(F))continue;let G=t.target.closest(L.selector);if(!(!G||G.tagName.toLowerCase()!==L.tag||R(L.selector)!==1||G.matches(":disabled")||G.closest('[inert],[hidden],[aria-hidden="true"]'))){u(F);break}}}let X=()=>{let t=location.origin+location.pathname;t!==z&&(z=t,I++,w.clear(),j())};async function re(){if(r)return;if(c)return c;let t=g,R=new AbortController;J=R;let F,L=new Promise((te,ae)=>{F=ae}),G=()=>F(new H("TIMEOUT","Funnel entry read cancelled"));R.signal.addEventListener("abort",G,{once:!0});let ne=setTimeout(()=>R.abort(),n.timeoutMs??5e3),oe=(async()=>{let te=encodeURIComponent(JSON.stringify(["funnel-process/1"])),ae=async()=>{let ie=await m(`${A}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${te}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:R.signal});if(!ie.ok)throw new H("SERVICE_UNAVAILABLE","Funnel entries unavailable",ie.status);return fe.parse(await ie.json())},W=await Promise.race([ae(),L]),ue=Date.parse(W.validatedAt),q=Date.parse(W.validUntil);if(W.scope.projectId!==n.scope.projectId||W.scope.environment!==n.scope.environment||W.scope.environmentId!==n.environmentId||W.release!==n.appManifestRelease||q<=Date.now()||ue>Date.now()+5e3||q<=ue||q-ue>6e4)throw new H("INVALID_RESPONSE","Entry scope or deadline changed");r||t!==g||(k=W,_=q,E=performance.now()+Math.min(q-Date.now(),6e4),j())})();c=oe;try{await oe}finally{clearTimeout(ne),R.signal.removeEventListener("abort",G),c===oe&&(c=void 0)}}async function ee(){if(!(!i||r))try{await re()}catch{r||o("configuration_unavailable")}}let de=pe({document,run:ee,delay:()=>i&&!r?15e3:void 0});return{async start(){i||r||(i=!0,z=location.origin+location.pathname,s=he(X),p=new MutationObserver(j),p.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",D,!0),await de.refresh())},refresh:re,async retry(){d&&!r&&await V(d)},async syncIdentity(){let t=l??d??h;if(t)try{let R=await t.process.syncIdentity();return h===t&&(d={entry:t.entry,process:t.process,visit:I},h=void 0,await V(d)),R}catch(R){throw t.process.view||(h={entry:t.entry,process:t.process,visit:I},d=void 0,b()),R}},async detach(){g++,J?.abort();let t=l??d??h;t&&(h={entry:t.entry,process:t.process,visit:I}),d=void 0,b(),t&&await t.process.detach()},destroy(){r=!0,g++,de.destroy(),J?.abort(),p?.disconnect(),s?.(),document.removeEventListener("click",D,!0);let t=l??d??h;d=void 0,h=void 0,b(),t?.process.destroy(),k=void 0}}}async function zn(n,A){return(await import("./paywall-54WX5YUZ.js")).showPaywall(n,A)}async function Jn(...n){return n[1]=qe(n[1]),(await import("./paywall-session-7VQENUWU.js")).createPaywallSession(...n)}async function Xn(...n){let A=n[1].signal?.aborted?void 0:Ue(n[1].client);try{let[m]=await Promise.all([import("./funnel-runtime-host-GWRYR523.js"),import("./screen-renderer-G2EWN3WB.js"),import("./paywall-54WX5YUZ.js")]);return await m.showFunnelRun(...n)}finally{A?.()}}async function Yn(...n){return(await import("./funnel-host-purchase-LWIBVHF2.js")).showFunnelPurchase(...n)}async function Zn(...n){return(await import("./content-BP7GV42L.js")).mountContent(...n)}async function Wn(...n){return(await import("./content-BP7GV42L.js")).prepareContent(...n)}export{H as LongplayError,y as MerchantBridgeError,nn as createBrowserFunnelCommandStorage,cn as createBrowserFunnelPurchaseStorage,on as createConfigurationSync,Qe as createFeatureClient,sn as createFunnelClient,fn as createFunnelPageExperiments,un as createFunnelProcess,dn as createFunnelPurchaseClient,Re as createFunnelRunController,yn as createIamFunnelEntries,hn as createIamFunnelProcessEntries,ln as createLocalFunnelClient,en as createLongplay,pn as createMerchantBridge,Jn as createPaywallSession,an as evaluateFunnelNode,Ze as formatCouponDiscount,Ye as formatCouponMoney,We as formatCouponTerms,tn as getPaywallRecovery,Zn as mountContent,Wn as prepareContent,rn as preparePaywallFallback,Yn as showFunnelPurchase,Xn as showFunnelRun,zn as showPaywall};
1
+ import{a as cn,c as dn}from"./chunk-DCCM7FYR.js";import{a as Ue,b as fn,c as Ie}from"./chunk-YSNMXK4R.js";import{a as pe}from"./chunk-JGG4R75K.js";import"./chunk-CNIBGSVO.js";import{a as en,c as sn,d as un}from"./chunk-MRFBMFNK.js";import"./chunk-3FPYCF7Z.js";import{a as an}from"./chunk-ORPOCB2J.js";import"./chunk-ECMWY3G2.js";import{h as Qe,i as on,k as ln}from"./chunk-2MTTK3BT.js";import"./chunk-BZSKOOMM.js";import"./chunk-LPDUK7HT.js";import{F as Re,e as Ve,g as je,h as fe,i as me,j as Ge,x as nn}from"./chunk-UHI7SPHK.js";import{a as qe}from"./chunk-G7NSECIG.js";import"./chunk-GIV4FOOW.js";import"./chunk-MYUYN7ZG.js";import{B as Fe,D as Oe,E as xe,G as De,H as Te,I as ke,J as Be,K as Ee,L as He,x as ve,y as Me,z as Ne}from"./chunk-C6JRUYKW.js";import{$ as Le,l as Ye,m as Ze,n as We}from"./chunk-PMCGTXGH.js";import"./chunk-7CFF6SWH.js";import{c as tn,d as rn}from"./chunk-PWQ5BHBJ.js";import"./chunk-HMRIMJ5W.js";import{b as be}from"./chunk-MWDR5FEU.js";import"./chunk-UBKD6VMS.js";import"./chunk-5RXU57I5.js";import"./chunk-DOJE7VUR.js";import{a as H}from"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import{a as ge,c as ce}from"./chunk-J6KIN4RH.js";import"./chunk-SLUA7ABW.js";import{c as ye,d as he}from"./chunk-DCIGO3NJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-SMIO7OG5.js";import{b as K}from"./chunk-WM27UTWT.js";import{a as Z}from"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";var y=class extends Error{constructor(m,k=0,_=!1,E="fix_request"){super(m);this.code=m;this.status=k;this.retryable=_;this.recovery=E;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function mn(n,A){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");let m=n.body?.getReader();if(!m)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");let k=()=>{m.cancel().catch(()=>{})};A.addEventListener("abort",k,{once:!0});let _=0,E="",r=new TextDecoder("utf-8",{fatal:!0});try{for(A.throwIfAborted();;){let i=await m.read();if(A.throwIfAborted(),i.done)break;if(_+=i.value.byteLength,_>262144)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");E+=r.decode(i.value,{stream:!0})}return E+=r.decode(),JSON.parse(E)}catch(i){throw A.throwIfAborted(),i instanceof y?i:new y("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{A.removeEventListener("abort",k),await m.cancel().catch(()=>{}),m.releaseLock()}}function pn(n){let A=Oe.parse(n.origin),m=xe.parse(n.manifest),k={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let c of["projectId","environmentId","environment"])if(m[c]!==n.scope[c])throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");let _=n.customerId===void 0?null:K.uuid().parse(n.customerId),E=0,r=null,i=null,g=new AbortController,I=n.fetch??globalThis.fetch;async function U(c,s,p,w,h){if(!m.capabilities.includes(c))throw new y("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let d=Fe[c];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(d.authority))throw new y("MERCHANT_BRIDGE_FORBIDDEN",403);let l=E,o=AbortSignal.any([g.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...w?[w]:[]]);o.throwIfAborted();let N=new Headers(await n.headers?.());if(o.throwIfAborted(),l!==E)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(N.get("authorization")??"")||N.has("X-Indiana-Bridge-Signature")||N.has("X-Indiana-Bridge-Key-Id"))throw new y("MERCHANT_BRIDGE_FORBIDDEN",403);N.set(Ne,String(ve)),N.set("Accept","application/json");let P=crypto.randomUUID();N.set("X-Request-Id",P),N.set("Content-Type","application/json");let b=await I(A+Me,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:N,signal:o,body:JSON.stringify({bridgeVersion:ve,requestId:P,command:d.command,scope:k,data:h??(p===void 0?{}:{operationId:p})})}),V=await mn(b,o);if(o.throwIfAborted(),l!==E)throw new DOMException("Merchant identity changed","AbortError");if(!b.ok){let D=He.safeParse(V);throw!D.success||D.data.scope.projectId!==n.scope.projectId||D.data.scope.environment!==n.scope.environment||D.data.scope.environmentId!==n.scope.environmentId||D.data.requestId!==P||D.data.command!==d.command?new y("MERCHANT_BRIDGE_INVALID_RESPONSE",b.status):new y(D.data.error.code,b.status,D.data.error.retryable,D.data.error.recovery)}let u=De(K.unknown()).safeParse(V);if(!u.success||u.data.scope.projectId!==n.scope.projectId||u.data.scope.environment!==n.scope.environment||u.data.scope.environmentId!==n.scope.environmentId||u.data.requestId!==P||u.data.command!==d.command)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE",b.status);let j=s.safeParse(u.data.data);if(!j.success)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE",b.status);return j.data}function M(){if(!_)throw new y("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return _}async function z(c,s,p,w){let h=M();if(w!==void 0&&Ee.parse({operationId:w,customerId:h}),!m.capabilities.includes(c))throw new y("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let d=E,l=AbortSignal.any([g.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...s?[s]:[]]);l.throwIfAborted();let o,N=new Promise((P,b)=>{o=()=>b(l.reason),l.addEventListener("abort",o,{once:!0})});try{let b=p(async()=>{let u=await import("./merchant-bridge-contracts-N3Q4W6ZU.js");if(l.throwIfAborted(),d!==E||_!==h)throw new DOMException("Merchant identity changed","AbortError");return u},l),V=await Promise.race([b,N]);return l.throwIfAborted(),V}finally{l.removeEventListener("abort",o)}}async function J(c,s,p,w){let h=M(),d=Ee.parse({operationId:p,customerId:h}),l=await U(c,s,d.operationId,w,d);if(l.customerId!==h||l.operationId!==d.operationId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return l}return{async readPresentation(c){let s=await U("presentation",ke,void 0,c);if(i!==null&&i!==s.nativeUserId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(s.presentation&&_!==null&&s.presentation.customerId!==_)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=s.nativeUserId,r=s.presentation,s},async createSession(c){let s=await U("session",Te,void 0,c);if(i!==null&&i!==s.nativeUserId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(_!==null&&_!==s.session.customerId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(r&&r.customerId!==s.session.customerId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return _=s.session.customerId,i=s.nativeUserId,s.session},async reportPresentation(c,s){let p=M(),w=Be.parse(c);if(!r||r.customerId!==p||r.decisionId!==w.decisionId)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return U("presentation_events",K.strictObject({queued:K.literal(!0)}),void 0,s,w)},async readCustomerCommerce(c){let s=M(),p=await z("customer_commerce",c,async(w,h)=>{let[d,l]=await Promise.all([w(),U("customer_commerce",K.unknown(),void 0,h)]),o=d.merchantBridgeCommerceSchema.safeParse(l);if(!o.success)throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");return o.data});if(p.customerId!==s)throw new y("MERCHANT_BRIDGE_SCOPE_MISMATCH");return p},async executePurchase(c,s){let p=await z("purchases",s,async(w,h)=>J("purchases",(await w()).merchantBridgeOperationSchema,c,h),c);if(p.type!=="purchase")throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");return p},readOperation:(c,s)=>z("operation_status",s,async(p,w)=>J("operation_status",(await p()).merchantOperationLookupSchema,c,w),c),async executeSubscriptionChange(c,s){let p=await z("subscription_changes",s,async(w,h)=>J("subscription_changes",(await w()).merchantBridgeOperationSchema,c,h),c);if(p.type!=="subscription_change")throw new y("MERCHANT_BRIDGE_INVALID_RESPONSE");return p},reset(){E++,g.abort(),g=new AbortController,_=null,r=null,i=null}}}var $e=K.strictObject({command:me,target:je,runId:K.uuid().optional(),expiresAt:K.iso.datetime({offset:!0}).optional()}).refine(n=>n.command.release===n.target.release),Ke=K.strictObject({schemaVersion:K.literal(1),entries:K.array($e).max(4e3)});function ze(n){let A=!1,m=()=>{A||n.unavailable(),A=!0};function k(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function _(r){let i=k()?.getItem(r);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return Ke.parse(JSON.parse(i)).entries}function E(r,i){let g=k();if(!g)return;if(!i.length)return g.removeItem(r);let I=JSON.stringify(Ke.parse({schemaVersion:1,entries:i}));if(I.length>1048576)throw Error("Entry recovery is too large");g.setItem(r,I)}return{load(){try{let r=n.binding();if(!r||n.storage===!1)return;let i="indiana.funnel.entries.v1."+JSON.stringify(r);return{key:i,entries:_(i)}}catch{m();return}},retain(r,i){if(r)try{let g=$e.parse(i);E(r,[..._(r).filter(I=>I.command.funnelId!==g.command.funnelId),g])}catch{m()}},forget(r,i){if(r)try{E(r,_(r).filter(g=>g.command.requestId!==i))}catch{m()}}}}var we=n=>["running","waiting"].includes(n.status)&&!n.pendingRequest&&(n.stopped||!n.screen&&!n.paywall&&n.instruction?.type==="wait"&&n.instruction.kind!=="operation");function yn(n){let A=ye(n.baseUrl),m=n.scope,k=be(n),_=n.fetch??globalThis.fetch.bind(globalThis),E,r=!1,i=!1,g=0,I=0,U="",M=0,z=0,J=0,c=!1,s,p=!0,w,h,d,l,o,N=-1,P,b=e=>{P===e&&(P=void 0,q())},V=new Set,u=(e,a)=>Z(n.onStatus,e,a),j=new Set,D=ze({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[A,m.projectId,m.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>u("recovery_unavailable")}),X=e=>D.forget(e.storageKey,e.command.requestId);function re(e,a){a&&(e.runId=a.id,e.expiresAt=a.runExpiresAt),D.retain(e.storageKey,{command:e.command,target:e.target,...e.runId&&{runId:e.runId},...e.expiresAt&&{expiresAt:e.expiresAt}})}function ee(){let e=o;o=void 0,e?.host.destroy(),e?.slot.remove(),e?.client.reset(),q()}let de=()=>P!==void 0||o!==void 0&&!o.background;function t(e,a){if(o?.client!==e)return;re(o.recovery,a);let f=we(a);o.slot.hidden=f,f!==o.background&&(o.background=f,f?u("run_background",o.entryId):N=I,q())}function R(e,a,f){let S=e.client.view;if(!a||e.background||!S?.screen||S.paywall||S.pendingRequest||S.stopped||S.status!=="waiting")return;let O=Le.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:S.nodeId,visit:S.visit,revision:S.revision,customerToken:a}),$=be({...n,session:void 0});$.requestWithCredential("funnels",O,e.runToken,{keepalive:f}).then(()=>X(e.recovery)).catch(()=>{}).finally(()=>$.dispose())}let F=()=>{o&&R(o,n.session.peek(),!0)},L=()=>Date.now()<z&&performance.now()<J;function G(e){if(e.target.release!==n.appManifestRelease||!L())return!1;try{return ce(e.target.render,document,location.pathname,()=>{})}catch{return u("incompatible",e.id),!1}}function ne(e){if(r||e.epoch!==M||e.visit!==I||document.visibilityState==="hidden")return!1;try{return ce(e.target.render,document,location.pathname,()=>{})}catch{return!1}}async function oe(e){if(de()){u("in_progress",e.id);return}if(!n.session.peek()){u("identity_required",e.id);return}let a=D.load(),f=a?.entries.find(O=>O.command.funnelId===e.funnelId&&(!O.expiresAt||Date.parse(O.expiresAt)>Date.now()));if(f){if(!ae(f)){u("recovery_pending",e.id);return}let O={...f,storageKey:a.key,epoch:M,visit:I};j.add(O.command.requestId),P=O,await te(O);return}let S={freshStart:!0,command:me.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:crypto.randomUUID(),locale:document.documentElement.lang||"en"}),epoch:M,visit:I,target:e.target,storageKey:a?.key};j.add(S.command.requestId),P=S,await te(S)}async function te(e){if(e.dispatching)return;e.dispatching=!0;let a=e.freshStart===!0;e.freshStart=!1;let f,S=!1,O=!1;async function $(T){if(e.epoch!==M)return;let v=T.view;if(!(e.storageKey&&v&&(we(v)||v.paywall||v.pendingRequest))&&v&&["running","waiting"].includes(v.status))try{await T.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:v.nodeId,visit:v.visit,revision:v.revision}),X(e)}catch(x){if(!(x instanceof H&&x.code==="FORBIDDEN"))throw x}}try{re(e),u("starting",e.command.entryId);let T=await k.request("funnels",e.command),v=Ge.safeParse(T);if(v.success){if(v.data.scope.projectId!==m.projectId||v.data.scope.environment!==m.environment)throw new H("SCOPE_MISMATCH","Entry scope changed");e.epoch===M&&u(v.data.reason,e.command.entryId),X(e),b(e);return}let x=Ve.parse(T);if(!x.runToken||x.scope.projectId!==m.projectId||x.scope.environment!==m.environment||x.run.source.type!=="funnel"||x.run.source.id!==e.command.funnelId||x.run.source.versionId!==e.command.versionId||e.runId!==void 0&&x.run.id!==e.runId)throw new H("INVALID_RESPONSE","Invalid entry Run");if(e.epoch!==M){b(e),u("identity_changed",e.command.entryId);return}re(e,x.run);let C=Re({...n,runToken:x.runToken,funnelId:e.command.funnelId,initialResponse:a?T:void 0});f=C,O=!0,await C.get(),O=!1;let Y=C.view;if(!Y||Y.id!==x.run.id||Y.source.type!=="funnel"||Y.source.id!==e.command.funnelId||Y.source.versionId!==e.command.versionId)throw new H("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(Y.status)){X(e),b(e),u("run_ended",e.command.entryId);return}if(!ne(e)){await $(C),u("left_screen",e.command.entryId),b(e);return}let se=!1,Ae=!1;if(o&&!o.background){await $(C),u("in_progress",e.command.entryId),b(e);return}o&&ee();let Q=document.createElement("div");Q.hidden=we(Y),n.container.append(Q);let Ce=await Ie(Q,{...n.host,client:C,appManifestRelease:n.appManifestRelease,onState(B){t(C,B),Z(n.host?.onState,B)},onDismiss(B){se=!0,Q.remove(),B&&!["running","waiting"].includes(B.status)&&X(e),o?.client===C&&(o=void 0,C.reset(),q(),B&&B.status!=="completed"&&u("run_ended",e.command.entryId)),Z(n.host?.onDismiss,B)},onComplete(B){Ae=!0,X(e),o?.client===C&&ee(),Z(n.host?.onComplete,B)},onError(B){Z(n.host?.onError,B),o?.client===C&&B instanceof H&&B.code==="FORBIDDEN"&&(X(e),ee(),u("run_ended",e.command.entryId))}}).catch(B=>{throw Q.remove(),B});if(!ne(e)||se||Ae){Ce.destroy(),Q.remove(),ne(e)||await $(C),b(e);return}let le=we(C.view??Y);Q.hidden=le,o={host:Ce,client:C,slot:Q,entryId:e.command.entryId,background:le,runToken:x.runToken,owner:n.session.peek(),recovery:e},le||(N=e.visit),S=!0,b(e),u("started",e.command.entryId),le&&u("run_background",e.command.entryId)}catch(T){T instanceof H&&(!f||O&&T.code==="FORBIDDEN")&&T.status!==void 0&&T.status>=400&&T.status<500&&!T.retryable&&(X(e),b(e)),e.epoch===M&&!r&&(u("start_failed",e.command.entryId),Z(n.host?.onError,T))}finally{S||f?.reset(),e.dispatching=!1}}function ae(e){if(e.command.release!==n.appManifestRelease||e.target.release!==n.appManifestRelease)return!1;try{return ce(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function W(){if(de())return!1;let e=D.load();for(let a of e?.entries??[]){if(a.expiresAt&&Date.parse(a.expiresAt)<=Date.now()){D.forget(e.key,a.command.requestId);continue}if(a.command.requestId===o?.recovery.command.requestId||j.has(a.command.requestId)||!ae(a))continue;j.add(a.command.requestId);let f={...a,storageKey:e.key,epoch:M,visit:I};return P=f,te(f),!0}return!1}function ue(){if(c=!1,r||!i||document.visibilityState==="hidden")return;ie();let e=o!==void 0&&!o.background;if(e&&(N=I),!W()){if(!L()){p=!0;return}p=!1;for(let a of E?.entries??[]){let f=`${a.funnelId}:${a.id}`;if(!(a.event!=="screen_enter"||V.has(f)||!G(a))){if(!n.session.peek()){u("identity_required",a.id);continue}if(N===I){V.add(f),e&&u("in_progress",a.id);continue}if(P){u("in_progress",a.id);return}V.add(f),oe(a);break}}}}let q=()=>{!c&&!r&&(c=!0,queueMicrotask(ue))};function ie(){let e=location.origin+location.pathname;return e===U?!1:(U=e,I++,p=!0,V.clear(),j.clear(),!0)}function Je(){ie()&&q()}function Se(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let a=e.target;if(!(a instanceof Element)||a.closest("[data-indiana-funnel]"))return;let f=a.closest("button,a,input");if(!(!f||f.matches(":disabled,[aria-disabled='true']")||f.closest("[hidden],[inert],[aria-hidden='true']")))for(let S of E?.entries??[]){let O=S.target.button;if(!(S.event!=="button_click"||!O||!G(S))){try{let $=ge(document);if(!f.matches(O.selector)||$(O.selector,f)!==1)continue}catch{u("incompatible",S.id);continue}oe(S);break}}}async function _e(){if(r)return;if(s)return s;let e=++g,a=new AbortController;w=a;let f,S=new Promise((T,v)=>{f=()=>v(new H("TIMEOUT","Funnel entry configuration read cancelled or timed out")),a.signal.addEventListener("abort",f,{once:!0})}),O=setTimeout(()=>a.abort(),n.timeoutMs??5e3),$=(async()=>{let T=async()=>{let se=await _(`${A}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:a.signal});if(!se.ok)throw new H("SERVICE_UNAVAILABLE","Funnel entries unavailable",se.status);return fe.parse(await se.json())},v=await Promise.race([T(),S]),x=Date.parse(v.validatedAt),C=Date.parse(v.validUntil);if(v.scope.projectId!==m.projectId||v.scope.environment!==m.environment||v.scope.environmentId!==n.environmentId||v.release!==n.appManifestRelease||C<=Date.now()||x>Date.now()+5e3||C-x>6e4||C<=x)throw new H("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(r||e!==g)return;let Y=E===void 0;E=v,z=C,J=performance.now()+Math.min(C-Date.now(),6e4),(Y||p)&&q()})();s=$;try{await $}finally{clearTimeout(O),a.signal.removeEventListener("abort",f),s===$&&(s=void 0)}}async function Xe(){if(!(!i||r)){try{await _e()}catch{r||u("configuration_unavailable")}q()}}let Pe=pe({document,run:Xe,delay:()=>i&&!r?15e3:void 0});return{async start(){i||r||(i=!0,U=location.origin+location.pathname,h=he(Je),d=n.session.subscribeIdentity(()=>{M++,p=!0,P=void 0,V.clear(),N=-1,j.clear(),o&&R(o,o.owner,!1),ee(),q()}),l=new MutationObserver(q),l.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",Se,!0),addEventListener("pagehide",F),await Pe.refresh())},refresh:_e,async retry(){P&&!r&&P.epoch===M&&await te(P)},destroy(){r=!0,g++,Pe.destroy(),w?.abort(),l?.disconnect(),h?.(),d?.(),document.removeEventListener("click",Se,!0),removeEventListener("pagehide",F),F(),ee(),k.dispose(),E=void 0}}}function hn(n){let A=ye(n.baseUrl),m=n.fetch??globalThis.fetch.bind(globalThis),k,_=0,E=0,r=!1,i=!1,g=0,I=0,U=-1,M=!1,z="",J,c,s,p,w=new Set,h,d,l,o=(t,R)=>Z(n.onStatus,t,R),N=()=>Date.now()<_&&performance.now()<E;function P(t){try{return N()&&t.target.release===n.appManifestRelease&&ce(t.target.render,document,location.pathname,()=>{})}catch{return o("incompatible",t.id),!1}}function b(){let t=l;l=void 0,t?.host.destroy(),t?.slot.remove()}async function V(t){if(t.dispatching)return;t.dispatching=!0;let R=g;try{let F=await t.process.open({operation:"entry_start",funnelId:t.entry.funnelId,versionId:t.entry.versionId,entryId:t.entry.id,release:n.appManifestRelease,locale:n.locale??"en"});if(r||R!==g||d!==t)return;let L=document.createElement("div");n.container.append(L),U=I;let G=await Ie(L,{...n.host,client:F.controller,appManifestRelease:n.appManifestRelease,onDismiss(ne){l?.process===t.process&&(l=void 0,L.remove()),Z(n.host?.onDismiss,ne)}});if(r||R!==g||d!==t){G.destroy(),L.remove();return}l={entry:t.entry,process:t.process,host:G,slot:L},d=void 0,o("run_presented",t.entry.id)}catch(F){if(r||R!==g||d!==t)return;F instanceof H&&"result"in F?(d=void 0,t.process.destroy(),o("suppressed",t.entry.id),j()):o("entry_unavailable",t.entry.id)}finally{t.dispatching=!1}}function u(t){if(r||d||l||h||U===I||!P(t))return;let R=`${I}:${t.id}`;if(w.has(R))return;w.add(R);let F={entry:t,process:n.createProcess(t),visit:I};d=F,V(F)}function j(){M||r||(M=!0,queueMicrotask(()=>{if(M=!1,!(r||document.visibilityState==="hidden"||!N()||d||l||h||U===I)){for(let t of k?.entries??[])if(t.event==="screen_enter"&&P(t)){u(t);break}}}))}function D(t){if(!t.isTrusted||t.defaultPrevented||!(t.target instanceof Element)||d||l||h||U===I)return;let R=ge(document,()=>{});for(let F of k?.entries??[]){let L=F.target.button;if(F.event!=="button_click"||!L||!P(F))continue;let G=t.target.closest(L.selector);if(!(!G||G.tagName.toLowerCase()!==L.tag||R(L.selector)!==1||G.matches(":disabled")||G.closest('[inert],[hidden],[aria-hidden="true"]'))){u(F);break}}}let X=()=>{let t=location.origin+location.pathname;t!==z&&(z=t,I++,w.clear(),j())};async function re(){if(r)return;if(c)return c;let t=g,R=new AbortController;J=R;let F,L=new Promise((te,ae)=>{F=ae}),G=()=>F(new H("TIMEOUT","Funnel entry read cancelled"));R.signal.addEventListener("abort",G,{once:!0});let ne=setTimeout(()=>R.abort(),n.timeoutMs??5e3),oe=(async()=>{let te=encodeURIComponent(JSON.stringify(["funnel-process/1"])),ae=async()=>{let ie=await m(`${A}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${te}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:R.signal});if(!ie.ok)throw new H("SERVICE_UNAVAILABLE","Funnel entries unavailable",ie.status);return fe.parse(await ie.json())},W=await Promise.race([ae(),L]),ue=Date.parse(W.validatedAt),q=Date.parse(W.validUntil);if(W.scope.projectId!==n.scope.projectId||W.scope.environment!==n.scope.environment||W.scope.environmentId!==n.environmentId||W.release!==n.appManifestRelease||q<=Date.now()||ue>Date.now()+5e3||q<=ue||q-ue>6e4)throw new H("INVALID_RESPONSE","Entry scope or deadline changed");r||t!==g||(k=W,_=q,E=performance.now()+Math.min(q-Date.now(),6e4),j())})();c=oe;try{await oe}finally{clearTimeout(ne),R.signal.removeEventListener("abort",G),c===oe&&(c=void 0)}}async function ee(){if(!(!i||r))try{await re()}catch{r||o("configuration_unavailable")}}let de=pe({document,run:ee,delay:()=>i&&!r?15e3:void 0});return{async start(){i||r||(i=!0,z=location.origin+location.pathname,s=he(X),p=new MutationObserver(j),p.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",D,!0),await de.refresh())},refresh:re,async retry(){d&&!r&&await V(d)},async syncIdentity(){let t=l??d??h;if(t)try{let R=await t.process.syncIdentity();return h===t&&(d={entry:t.entry,process:t.process,visit:I},h=void 0,await V(d)),R}catch(R){throw t.process.view||(h={entry:t.entry,process:t.process,visit:I},d=void 0,b()),R}},async detach(){g++,J?.abort();let t=l??d??h;t&&(h={entry:t.entry,process:t.process,visit:I}),d=void 0,b(),t&&await t.process.detach()},destroy(){r=!0,g++,de.destroy(),J?.abort(),p?.disconnect(),s?.(),document.removeEventListener("click",D,!0);let t=l??d??h;d=void 0,h=void 0,b(),t?.process.destroy(),k=void 0}}}async function zn(n,A){return(await import("./paywall-QQ2MC4KO.js")).showPaywall(n,A)}async function Jn(...n){return n[1]=qe(n[1]),(await import("./paywall-session-WC2WFWBQ.js")).createPaywallSession(...n)}async function Xn(...n){let A=n[1].signal?.aborted?void 0:Ue(n[1].client);try{let[m]=await Promise.all([import("./funnel-runtime-host-ZWUAGDBU.js"),import("./screen-renderer-G2EWN3WB.js"),import("./paywall-QQ2MC4KO.js")]);return await m.showFunnelRun(...n)}finally{A?.()}}async function Yn(...n){return(await import("./funnel-host-purchase-5NLPYJRK.js")).showFunnelPurchase(...n)}async function Zn(...n){return(await import("./content-UDP5VQS4.js")).mountContent(...n)}async function Wn(...n){return(await import("./content-UDP5VQS4.js")).prepareContent(...n)}export{H as LongplayError,y as MerchantBridgeError,nn as createBrowserFunnelCommandStorage,cn as createBrowserFunnelPurchaseStorage,on as createConfigurationSync,Qe as createFeatureClient,sn as createFunnelClient,fn as createFunnelPageExperiments,un as createFunnelProcess,dn as createFunnelPurchaseClient,Re as createFunnelRunController,yn as createIamFunnelEntries,hn as createIamFunnelProcessEntries,ln as createLocalFunnelClient,en as createLongplay,pn as createMerchantBridge,Jn as createPaywallSession,an as evaluateFunnelNode,Ze as formatCouponDiscount,Ye as formatCouponMoney,We as formatCouponTerms,tn as getPaywallRecovery,Zn as mountContent,Wn as prepareContent,rn as preparePaywallFallback,Yn as showFunnelPurchase,Xn as showFunnelRun,zn as showPaywall};
@@ -1 +1 @@
1
- import"./chunk-T4GTAH43.js";import"./chunk-NMKZ724L.js";import"./chunk-NZSLDALU.js";import"./chunk-UBKD6VMS.js";import{a as i}from"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import"./chunk-ATMVXNDD.js";import{b as A}from"./chunk-WM27UTWT.js";import"./chunk-WOT6VMZA.js";var c=A.number().int().min(0).max(1e9);function R(e,o){let a=c.parse(e.promptTokens),p=c.parse(e.completionTokens),s=c.parse(e.promptTokensDetails?.cachedTokens??0),t=c.parse(e.promptTokensDetails?.cacheWriteTokens??0),r=c.parse(e.promptTokensDetails?.audioTokens??0),l=c.parse(e.completionTokensDetails?.audioTokens??0),n=c.parse(e.completionTokensDetails?.reasoningTokens??0);if(c.parse(e.totalTokens)!==a+p||s+t+r>a||n+l>p||(e.promptTokensDetails?.videoTokens??0)>0)throw new i("AI_USAGE_UNAVAILABLE","Token pools must conserve usage; video needs an explicit token mapper");return{input:a-s-t-r,output:p-l-(o==="separate"?n:0),cache_read:s,cache_write:t,input_audio:r,output_audio:l,reasoning:o==="separate"?n:0}}function I(e){if(!Number.isFinite(e)||e<0)throw new i("AI_USAGE_UNAVAILABLE","Provider cost must be a nonnegative USD amount");let o=String(e),a=o.includes("e")?e.toFixed(18).replace(/0+$/,"").replace(/\.$/,""):o;if(!/^(0|[1-9]\d{0,11})(\.\d{1,18})?$/.test(a)||Number(a)!==e)throw new i("AI_USAGE_UNAVAILABLE","Provider cost exceeds the supported precision");return a}async function f(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning)||!e.modelId||!e.generationId)throw new i("INVALID_REQUEST","Actual model, generation ID and reasoning pricing are required");let o={context:e.context,generationId:e.generationId,modelId:`openrouter/${e.modelId}`,usage:e.usage,tokens:null,quote:null,receipt:null,phase:"captured"};await e.persist(o);let a=e.mapTokens?e.mapTokens(e.usage):R(e.usage,e.reasoning),p=e.usage.cost==null?void 0:I(e.usage.cost),s=e.quote??await e.pricing.quoteTokens({modelId:o.modelId,tokens:a});if(s.pricing.modelId!==o.modelId||Object.keys(a).some(l=>a[l]!==s.tokens[l]))throw new i("INVALID_REQUEST","Saved quote must match the provider model and token pools");await e.persist({...o,tokens:a,quote:s,phase:"quoted"});let t=await e.pricing.trackTokens(e.client,{...e.context,quote:s,providerCostUsd:p,generationId:e.generationId});if(!t.receipt.accepted)throw new i("AI_BALANCE_REJECTED","OpenRouter usage was saved but the balance request was rejected");let r={...o,tokens:a,quote:s,receipt:t,phase:"settled"};return await e.persist(r),r}function T(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning))throw new i("INVALID_REQUEST","Reasoning pricing is required");let o=e.openRouter.chat;async function a(t){if(!t.usage||!t.modelId||!t.generationId)throw new i("AI_USAGE_UNAVAILABLE","OpenRouter did not return final usage and the actual model");await f({...e,context:t.context,generationId:t.generationId,modelId:t.modelId.slice(11),usage:t.usage})}let p=async(t,r)=>{let n={context:await e.context(),generationId:null,modelId:null,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"},d;try{d=await o.send(t,r)}catch(g){throw await e.persist(n),g}if(!(d instanceof ReadableStream)){if(n={...n,generationId:d.id,modelId:d.model?`openrouter/${d.model}`:null,usage:d.usage??null},!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter omitted final accounting");return await a(n),d}let w=d.getReader(),m=!1;return new ReadableStream({async pull(g){try{let{value:u,done:k}=await w.read();if(k){if(m=!0,!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter stream ended without final accounting");await a(n),g.close();return}if(u.error)throw new i("AI_PROVIDER_ERROR",u.error.message);u.usage&&(n={...n,generationId:u.id,modelId:u.model?`openrouter/${u.model}`:null,usage:u.usage}),g.enqueue(u)}catch(u){m||(m=!0,await e.persist(n)),await w.cancel(u),g.error(u)}},async cancel(g){m||(m=!0,await e.persist(n)),await w.cancel(g)}})},s=new Proxy(o,{get(t,r){return r==="send"?p:Reflect.get(t,r,t)}});return new Proxy(e.openRouter,{get(t,r){return r==="chat"?s:Reflect.get(t,r,t)}})}export{T as createOpenRouterUsageClient,f as trackOpenRouterUsage};
1
+ import"./chunk-T4GTAH43.js";import"./chunk-NMKZ724L.js";import"./chunk-MWDR5FEU.js";import"./chunk-UBKD6VMS.js";import{a as i}from"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import"./chunk-SMIO7OG5.js";import{b as A}from"./chunk-WM27UTWT.js";import"./chunk-WOT6VMZA.js";var c=A.number().int().min(0).max(1e9);function R(e,o){let a=c.parse(e.promptTokens),p=c.parse(e.completionTokens),s=c.parse(e.promptTokensDetails?.cachedTokens??0),t=c.parse(e.promptTokensDetails?.cacheWriteTokens??0),r=c.parse(e.promptTokensDetails?.audioTokens??0),l=c.parse(e.completionTokensDetails?.audioTokens??0),n=c.parse(e.completionTokensDetails?.reasoningTokens??0);if(c.parse(e.totalTokens)!==a+p||s+t+r>a||n+l>p||(e.promptTokensDetails?.videoTokens??0)>0)throw new i("AI_USAGE_UNAVAILABLE","Token pools must conserve usage; video needs an explicit token mapper");return{input:a-s-t-r,output:p-l-(o==="separate"?n:0),cache_read:s,cache_write:t,input_audio:r,output_audio:l,reasoning:o==="separate"?n:0}}function I(e){if(!Number.isFinite(e)||e<0)throw new i("AI_USAGE_UNAVAILABLE","Provider cost must be a nonnegative USD amount");let o=String(e),a=o.includes("e")?e.toFixed(18).replace(/0+$/,"").replace(/\.$/,""):o;if(!/^(0|[1-9]\d{0,11})(\.\d{1,18})?$/.test(a)||Number(a)!==e)throw new i("AI_USAGE_UNAVAILABLE","Provider cost exceeds the supported precision");return a}async function f(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning)||!e.modelId||!e.generationId)throw new i("INVALID_REQUEST","Actual model, generation ID and reasoning pricing are required");let o={context:e.context,generationId:e.generationId,modelId:`openrouter/${e.modelId}`,usage:e.usage,tokens:null,quote:null,receipt:null,phase:"captured"};await e.persist(o);let a=e.mapTokens?e.mapTokens(e.usage):R(e.usage,e.reasoning),p=e.usage.cost==null?void 0:I(e.usage.cost),s=e.quote??await e.pricing.quoteTokens({modelId:o.modelId,tokens:a});if(s.pricing.modelId!==o.modelId||Object.keys(a).some(l=>a[l]!==s.tokens[l]))throw new i("INVALID_REQUEST","Saved quote must match the provider model and token pools");await e.persist({...o,tokens:a,quote:s,phase:"quoted"});let t=await e.pricing.trackTokens(e.client,{...e.context,quote:s,providerCostUsd:p,generationId:e.generationId});if(!t.receipt.accepted)throw new i("AI_BALANCE_REJECTED","OpenRouter usage was saved but the balance request was rejected");let r={...o,tokens:a,quote:s,receipt:t,phase:"settled"};return await e.persist(r),r}function T(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning))throw new i("INVALID_REQUEST","Reasoning pricing is required");let o=e.openRouter.chat;async function a(t){if(!t.usage||!t.modelId||!t.generationId)throw new i("AI_USAGE_UNAVAILABLE","OpenRouter did not return final usage and the actual model");await f({...e,context:t.context,generationId:t.generationId,modelId:t.modelId.slice(11),usage:t.usage})}let p=async(t,r)=>{let n={context:await e.context(),generationId:null,modelId:null,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"},d;try{d=await o.send(t,r)}catch(g){throw await e.persist(n),g}if(!(d instanceof ReadableStream)){if(n={...n,generationId:d.id,modelId:d.model?`openrouter/${d.model}`:null,usage:d.usage??null},!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter omitted final accounting");return await a(n),d}let w=d.getReader(),m=!1;return new ReadableStream({async pull(g){try{let{value:u,done:k}=await w.read();if(k){if(m=!0,!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter stream ended without final accounting");await a(n),g.close();return}if(u.error)throw new i("AI_PROVIDER_ERROR",u.error.message);u.usage&&(n={...n,generationId:u.id,modelId:u.model?`openrouter/${u.model}`:null,usage:u.usage}),g.enqueue(u)}catch(u){m||(m=!0,await e.persist(n)),await w.cancel(u),g.error(u)}},async cancel(g){m||(m=!0,await e.persist(n)),await w.cancel(g)}})},s=new Proxy(o,{get(t,r){return r==="send"?p:Reflect.get(t,r,t)}});return new Proxy(e.openRouter,{get(t,r){return r==="chat"?s:Reflect.get(t,r,t)}})}export{T as createOpenRouterUsageClient,f as trackOpenRouterUsage};
package/dist/page.js CHANGED
@@ -1 +1 @@
1
- import{d as o,e as r,f as e,g as f}from"./chunk-N7CRURKE.js";import"./chunk-4IJU33UM.js";import"./chunk-3VUPVXAV.js";import"./chunk-ATMVXNDD.js";import"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
1
+ import{d as o,e as r,f as e,g as f}from"./chunk-KRTX4QEH.js";import"./chunk-DCIGO3NJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-SMIO7OG5.js";import"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
@@ -1 +1 @@
1
- import{b as Ye,c as Je}from"./chunk-JGG4R75K.js";import{c as ze,d as He,e as Be,f as de,g as Qe,h as Ge,i as je,k as We}from"./chunk-CNIBGSVO.js";import{a as qe,c as Ae,d as Ve,g as Fe}from"./chunk-PWQ5BHBJ.js";import{b as ee}from"./chunk-HMRIMJ5W.js";import"./chunk-NZSLDALU.js";import"./chunk-UBKD6VMS.js";import{c as Y,o as Z,oa as te,qa as Me}from"./chunk-5RXU57I5.js";import{c as Ie}from"./chunk-DOJE7VUR.js";import{a as A}from"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import"./chunk-ATMVXNDD.js";import"./chunk-WM27UTWT.js";import{a as z}from"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";async function Ke(s,n,v){if(n.status!=="complete")throw new A("INVALID_RESPONSE","A verified completed purchase is required");let g=s?Z.parse(s):null;if(await v.onComplete?.(n),!g||!v.check)return;let y=Z.parse(await v.check());if(y.internal_feature_id!==g.internal_feature_id||y.quantity!==g.quantity||g.observation!==void 0&&(y.observation===void 0||y.observation.requirementDigest!==g.observation.requirementDigest||y.observation.authority!==g.observation.authority||Ie(y.observation.subject)!==Ie(g.observation.subject)))throw new A("INVALID_RESPONSE","The access requirement changed");y.allowed&&await v.onAccessGranted?.(y)}var st={none:0,sm:4,md:8,lg:14,full:9999},ct={system:"system-ui,sans-serif",serif:"Georgia,serif",rounded:"ui-rounded,system-ui,sans-serif",mono:"ui-monospace,monospace"};function lt(s){let[n,v,g]=[1,3,5].map(y=>{let x=Number.parseInt(s.slice(y,y+2),16)/255;return x<=.03928?x/12.92:((x+.055)/1.055)**2.4});return .2126*n+.7152*v+.0722*g}function Xe(s){let n=lt(s.primary),v=(n+.05)/.05>1.05/(n+.05)?"#111318":"#FFFFFF",g=`color-mix(in srgb, ${s.text} 22%, ${s.background})`,y=`${st[s.radius]}px`,x=`appearance:none;margin:0;min-height:44px;padding:10px 18px;border:0;border-radius:${y};font:inherit;font-size:15px;font-weight:600;line-height:1.25;cursor:pointer;touch-action:manipulation`;return{root:`width:100%;box-sizing:border-box;background:${s.background};color:${s.text};font:14px/1.5 ${ct[s.font]}`,controls:"display:flex;gap:12px;padding:0 20px 12px;align-items:center;flex-wrap:wrap",message:"flex:1 1 200px;min-width:0;margin:0;font-size:13px",panel:`flex:1 0 100%;box-sizing:border-box;display:flex;flex-direction:column;gap:8px;padding:16px;border:1px solid ${g};border-radius:${y}`,summary:"margin:0;font-size:15px;font-weight:600",terms:"display:flex;flex-direction:column;gap:4px;font-size:13px;opacity:.72",actions:"display:flex;gap:8px;flex-wrap:wrap;margin-top:4px",primary:`${x};background:${s.primary};color:${v}`,secondary:`${x};background:transparent;color:${s.text};box-shadow:inset 0 0 0 1px ${g}`,link:`${x};background:transparent;color:${s.text};opacity:.72;font-weight:500`}}function Re(s){s.style.opacity=s.disabled?".55":"",s.style.cursor=s.disabled?"not-allowed":"pointer"}function Se(s){return Object.entries(s.document.buttons).filter(([,n])=>n.type==="checkout"&&n.product.type==="fixed"&&!ee(n.product,{},s.capabilities)).map(([n])=>n)}async function Nt(s,n,v){let g=We(s.ownerDocument),y=()=>{C.finish("dismissed"),g()},x=()=>y(),C=Qe(s,n,"paywall",()=>{y(),z(n.onDismiss)});n.signal?.throwIfAborted(),n.signal?.addEventListener("abort",x,{once:!0});let H=null,N,b,Te;try{if(C.start(!0),C.cancelled)throw new DOMException("Presentation cancelled","AbortError");if(H=n.check?Z.parse(await C.wait(n.check(),de)):null,H?.allowed)return C.finish("skipped"),n.signal?.removeEventListener("abort",x),g(),await n.onAccessGranted?.(H),{check:H,host:null};let[e,t]=await Promise.allSettled([C.wait(import("./screen-renderer-G2EWN3WB.js")),C.wait(n.start().then(d=>(C.cancelled&&d.destroy(),d)),de)]);if(e.status==="rejected")throw t.status==="fulfilled"&&t.value.destroy(),e.reason;if(t.status==="rejected")throw t.reason;Te=e.value,N=t.value,n.signal?.throwIfAborted(),N.signal?.throwIfAborted(),N.signal?.addEventListener("abort",x,{once:!0});let a=N.view??await C.wait(N.refresh(),de);if(!a)throw new A("INVALID_RESPONSE","Paywall presentation is missing");N.signal?.throwIfAborted(),b=a}catch(e){throw C.finish("error",e),n.signal?.removeEventListener("abort",x),N?.signal?.removeEventListener("abort",x),N?.destroy(),g(),e}let r=N,{mountScreenPreview:Ze}=Te,u=s.ownerDocument,pe=new AbortController,L=u.createElement("section"),fe=u.createElement("div"),M=u.createElement("div"),m=u.createElement("p"),f=u.createElement("button"),P=u.createElement("button"),w=u.createElement("dialog"),i=b.document.screen.strings.defaultLocale.startsWith("zh"),et=i?"\u6B63\u5728\u5904\u7406\u2026":"Processing\u2026",tt=i?"\u6B63\u5728\u51C6\u5907\u62A5\u4EF7\u2026":"Preparing your price\u2026",O=Xe(b.document.screen.theme);L.dataset.indianaPaywall="",L.setAttribute("aria-label",b.document.name),L.style.cssText=O.root,M.style.cssText=O.controls,m.style.cssText=O.message,m.setAttribute("role","status"),P.style.cssText=O.link,P.textContent=i?"\u5173\u95ED":"Close",f.style.cssText=O.secondary,f.textContent=i?"\u91CD\u8BD5":"Retry",f.hidden=!0,M.append(m,f,P),L.append(fe,M);let B=b.document.presentation,Q,Oe,me=!1,De=JSON.stringify(b.capabilities);function he(e){if(p)return;b=e;let t=JSON.stringify(e.capabilities);t!==De&&(Q?.updateCapabilities(e.capabilities,Se(e)),De=t),rt(e)}let R;function Ne(){let e=u.defaultView;R?.responsive&&e&&Q?.resizeViewport?.(e.innerHeight,e.innerWidth)}let p=!1,J=!1,E=null,ne=!1,Le=!1,q=!1,ye,we=!1,$,G;function nt(){return J||p||$||we?{type:"recover",operationId:r.operation?.operationId??r.quote?.operationId??null,requestId:null}:Ae(r)}let S=()=>!p&&!ne&&!$&&n.canInteract?.()!==!1,ge=!1,c=null,U=null;function rt(e){J||E||r.quote||r.operation||(m.textContent=Object.values(e.capabilities.plans).some(t=>t.available)?"":i?"\u5F53\u524D\u8D26\u53F7\u6682\u65E0\u53EF\u8D2D\u4E70\u7684\u65B9\u6848\u3002":"No plans are currently available for this account.")}let be=new Map,re=e=>qe({quote:r.quote,operation:e,requestId:null,pending:!1,destroyed:p,canReselect:r.canReselect});async function ve(e){let t=e.merchantExecution;if(!(!S()||!e.checkoutUrl||n.checkoutNavigation==="after_confirmation"&&re(e).type!=="checkout"||t?.type==="purchase"&&!["not_started","pending"].includes(t.paymentStatus)||be.get(e.operationId)===e.checkoutUrl)){be.set(e.operationId,e.checkoutUrl);try{n.onCheckoutUrl?await n.onCheckoutUrl(e.checkoutUrl):u.defaultView?.location.assign(e.checkoutUrl)}catch(a){throw be.delete(e.operationId),a}}}let j=(e,t=!1)=>{if(t){let a=e instanceof A?e.code:void 0;a==="CAPABILITY_UNAVAILABLE"||a==="NOT_CONFIGURED"?(c=null,m.textContent=i?"\u6682\u65F6\u65E0\u6CD5\u4E3A\u6B64\u5957\u9910\u62A5\u4EF7\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002":"Pricing for this plan is unavailable. Payment hasn\u2019t started."):a==="COMMAND_PENDING"?m.textContent=i?"\u4ECD\u5728\u51C6\u5907\u62A5\u4EF7\uFF0C\u8BF7\u91CD\u8BD5\u4EE5\u67E5\u770B\u7ED3\u679C\u3002":"Your price is still being prepared. Retry to check the result.":m.textContent=i?"\u672A\u80FD\u53D6\u5F97\u62A5\u4EF7\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002\u8BF7\u91CD\u8BD5\u3002":"We couldn\u2019t prepare your price. Payment hasn\u2019t started. Try again."}else m.textContent=e instanceof Error?e.message:i?"\u8BF7\u6C42\u5931\u8D25":"Request failed";f.hidden=c===null,t&&m.scrollIntoView?.({block:"nearest"}),z(t&&v?.quoteError?v.quoteError:n.onError,e)},ie=new WeakMap;function oe(e){J=e;for(let t of U?.querySelectorAll("button")??[])e?(ie.set(t,t.disabled),t.disabled=!0):ie.has(t)&&(t.disabled=ie.get(t),ie.delete(t)),Re(t)}function xe(){m.textContent=i?"\u6682\u65F6\u65E0\u6CD5\u64CD\u4F5C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002":"This action is unavailable right now. Try again in a moment."}async function it(e){if(n.beforeAction)try{await n.beforeAction()}catch(t){throw c=e,t}}async function _(e){if(J||p)return;if(!S()){xe();return}let t=e===se,a=t?tt:et;oe(!0),f.hidden=!0,m.textContent=a,t&&m.scrollIntoView?.({block:"nearest"});try{if(await it(e),p)return;if(!S()){c=e,f.hidden=!1,xe();return}await e()}catch(d){p||j(d,t)}finally{oe(!1),m.textContent===a&&(m.textContent="")}}async function ot(e){await Ke(H,e,n)}function Ue(e){return Ae(r).type==="recording"||re(e).type==="recording"}async function k(e,t=n.checkoutNavigation!=="after_confirmation"){if(p)return;if(!S()){c=async()=>k(await r.read()),f.hidden=!1;return}if(m.textContent=Je(e.status,i),Ue(e)){let o=e.merchantExecution?.type==="purchase"&&e.merchantExecution.recordingStatus==="failed";m.textContent=o?i?"\u4ED8\u6B3E\u548C\u5546\u6237\u5904\u7406\u5DF2\u5B8C\u6210\uFF0C\u4F46\u4EA4\u6613\u8BB0\u5F55\u5931\u8D25\u3002\u8BF7\u8054\u7CFB\u5546\u6237\u4FEE\u590D\uFF0C\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"Payment and fulfillment succeeded, but recording failed. Contact the merchant to repair this purchase; do not buy again.":i?"\u4ED8\u6B3E\u548C\u5546\u6237\u5904\u7406\u5DF2\u5B8C\u6210\uFF0C\u6B63\u5728\u786E\u8BA4\u4EA4\u6613\u8BB0\u5F55\u3002\u8BF7\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"Payment and merchant fulfillment are complete. Recording is pending confirmation; do not purchase again.",f.textContent=i?"\u67E5\u8BE2\u8BB0\u5F55":"Check recording",c=async()=>k(await r.read()),f.hidden=!1;return}if(e.problem){let o=e.problem;c=ae,f.textContent=i?"\u68C0\u67E5\u5E76\u6062\u590D\u539F\u64CD\u4F5C":"Check and recover original purchase",j(new A(o.code,o.reason==="RESULT_UNKNOWN"?i?"\u4ED8\u6B3E\u7ED3\u679C\u5C1A\u672A\u786E\u5B9A\uFF0C\u8BF7\u6062\u590D\u539F\u64CD\u4F5C\uFF0C\u6682\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"The payment result is unknown. Recover the original purchase before buying again.":o.phase==="fulfillment"?i?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u5546\u6237\u6743\u76CA\u5904\u7406\u9700\u8981\u6838\u5BF9\u3002":"Payment was recorded. Access fulfillment needs attention.":o.code==="CAPABILITY_UNAVAILABLE"?i?"\u5546\u6237\u5C1A\u4E0D\u652F\u6301\u672C\u6B21\u8D2D\u4E70\u6240\u9700\u7684\u5B8C\u6574\u80FD\u529B\uFF0C\u8BF7\u5904\u7406\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The merchant does not currently support all actions required by this purchase. Recover the original purchase after this is resolved.":o.code==="NOT_CONFIGURED"?i?"\u4ED8\u6B3E\u670D\u52A1\u8FDE\u63A5\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u8054\u7CFB\u5546\u6237\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The payment connection needs attention. Contact the merchant, then recover the original purchase.":i?"\u539F\u8D2D\u4E70\u64CD\u4F5C\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u67E5\u8BE2\u6216\u6062\u590D\u6B64\u64CD\u4F5C\u3002":"The original purchase needs attention. Check or recover this operation.",void 0,void 0,o));return}if(e.merchantExecution?.type==="purchase"&&e.merchantExecution.paymentStatus==="succeeded"&&!["applied","not_applicable"].includes(e.merchantExecution.fulfillmentStatus)&&(m.textContent=i?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u6B63\u5728\u7B49\u5F85\u5546\u6237\u5B8C\u6210\u5904\u7406\u3002":"Payment was recorded. Waiting for merchant fulfillment."),e.status==="complete"){c=null,await ot(e);return}if(e.status!=="pending"){if(r.canReselect===!1){m.textContent=i?"\u6B63\u5728\u6838\u5BF9\u539F\u8D2D\u4E70\u7ED3\u679C":"Checking the original purchase result",f.textContent=i?"\u67E5\u8BE2\u7ED3\u679C":"Check result",c=async()=>k(await r.read()),f.hidden=!1;return}f.textContent=i?"\u91CD\u8BD5":"Retry",c=null,E=null;return}if(!t&&re(e).type==="checkout"){m.textContent=i?"\u539F\u4ED8\u6B3E\u5C1A\u672A\u5B8C\u6210\uFF0C\u53EF\u7EE7\u7EED\u539F\u6536\u94F6\u53F0\u3002":"Payment is unfinished. Continue the original checkout.",f.textContent=i?"\u7EE7\u7EED\u4ED8\u6B3E":"Continue checkout",c=async()=>k(await r.read(),!0),f.hidden=!1;return}await ve(e);let a=Date.now()+6e5,d=2e3;me=!0,z(n.onObservationChange,!0);try{for(;!p&&Date.now()<a;){if(await Ye(d,u,pe.signal),p)return;if(!S()){c=async()=>k(await r.read()),f.hidden=!1;return}let o=await r.read();if(!t&&re(o).type==="checkout"){await k(o,!1);return}if(!o.problem&&o.status==="pending"&&await ve(o),o.status!=="pending"||o.problem||Ue(o)){await k(o);return}d=Math.min(d*1.5,3e4)}}finally{me=!1,z(n.onObservationChange,!1)}c=async()=>k(await r.read()),f.hidden=!1}async function Ce(){let e=await r.read();if(p)return;if(!S()){c=Ce,f.hidden=!1;return}let t=r.quote;if(t&&Fe(e,{operationId:t.operationId,currency:t.currency},"The original purchase operation changed"),t&&e.status==="pending"&&e.quoteFinalized===!1&&!e.confirmedAt&&!e.checkoutUrl&&!e.nativePurchase&&!e.merchantExecution&&!e.problem&&!r.pendingCancellation){_e(t);return}await k(e)}async function ae(){U?.remove(),U=null,c=ae;let e=await r.confirm();if(!S()){c=ae,f.hidden=!1;return}if(e.problem){await k(e);return}if(e.status==="pending"){if(e.checkoutUrl)await ve(e);else if(e.execution&&e.execution.provider!=="merchant"||e.nativePurchase){if(!n.onPurchase)throw new A("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await n.onPurchase({operation:e,signal:pe.signal})}}c=async()=>k(await r.read()),await k(e,!0)}function _e(e){U?.remove();let t=!(Date.parse(e.expiresAt)>Date.now());m.textContent=t?i?"\u6B64\u62A5\u4EF7\u5DF2\u8FC7\u671F\u3002\u8BF7\u5148\u53D6\u6D88\uFF0C\u518D\u91CD\u65B0\u9009\u62E9\u3002":"This quote has expired. Cancel it, then choose again.":"";let a=u.createElement("div"),d=u.createElement("button"),o=u.createElement("button"),V=u.createElement("div"),K=u.createElement("p"),T=e.merchantTerms,ce=T?T.totalMinor:e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),le=i?"zh-CN":"en",ue=T?.subscriptionTerms?.items??[],X=T?ue.length===1&&ue[0]?.amountMinor===ce&&ue[0]:e.lines.length===1&&e.lines[0]?.catalogAmountMinor===ce&&e.lines[0];K.textContent=e.lines.map(l=>l.productName).join(", ")+" \xB7 "+(ce===null?i?`${Y(T.subtotalMinor-T.discountMinor,e.currency)} + \u5F85\u786E\u8BA4\u7A0E\u8D39`:`${Y(T.subtotalMinor-T.discountMinor,e.currency)} + tax confirmed at checkout`:Y(ce,e.currency)+(X?te(X.interval,le,X.intervalCount??1):"")),d.textContent=i?"\u786E\u8BA4\u8D2D\u4E70":"Confirm purchase",d.disabled=t,o.textContent=i?"\u53D6\u6D88":"Cancel",a.style.cssText=O.panel,K.style.cssText=O.summary,V.style.cssText=O.actions,d.style.cssText=O.primary,o.style.cssText=O.secondary,Re(d),d.onclick=()=>{_(ae)};let $e=async()=>{let l=await r.cancel();p||(a.remove(),U=null,await k(l))};o.onclick=()=>{c=$e,_($e)};let D=u.createElement("div");if(D.style.cssText=O.terms,T){for(let h of ue){if(h===X)continue;let I=u.createElement("p");I.textContent=Y(h.amountMinor,e.currency)+te(h.interval,le,h.intervalCount),D.append(I)}let l=T.subscriptionTerms?.trial;if(l){let h=u.createElement("p");h.textContent=i?`\u8BD5\u7528 ${l.days} \u5929\uFF1B${l.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${l.days}; ${l.cardRequired?"a payment method is required":"no payment method is required"}`,D.append(h)}for(let h of[...T.expectedEffects.map(I=>I.description),...T.requiredConsents.map(I=>I.summary)]){let I=u.createElement("p");I.textContent=h,D.append(I)}}else{for(let l of e.lines){if(l!==X){let h=u.createElement("p");h.textContent=`${l.productName} \xB7 ${Y(l.catalogAmountMinor,e.currency)}${te(l.interval,le,l.intervalCount??1)}`,D.append(h)}for(let h of l.prepaid??[]){let I=u.createElement("p"),F=r.view?.capabilities.plans[l.productVersionId]?.prepaid?.find(at=>at.internalFeatureId===h.internal_feature_id);I.textContent=`${F?.name??h.internal_feature_id} \xB7 ${h.quantity} ${i?"\u4EFD":"packs"} \xD7 ${h.terms.units}`,F&&(I.textContent+=te(F.reset==="week"||F.reset==="month"||F.reset==="year"?F.reset:"one_time",le,F.resetCount)),D.append(I)}if(l.trial){let h=u.createElement("p");h.textContent=i?`\u8BD5\u7528 ${l.trial.days} \u5929\uFF1B${l.trial.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${l.trial.days}; ${l.trial.cardRequired?"a payment method is required":"no payment method is required"}`,D.append(h)}}if(!e.charge){let l=u.createElement("p");l.textContent=i?"\u76EE\u5F55\u4EF7\u683C\uFF1B\u6700\u7EC8\u91D1\u989D\u4EE5\u7ED3\u8D26\u65F6\u7A0E\u8D39\u548C\u8BD5\u7528\u89C4\u5219\u4E3A\u51C6\u3002":"Catalog price; the final charge depends on checkout taxes and trial terms.",D.append(l)}}for(let l of D.children)l.style.margin="0";V.append(d,o),a.append(K,...D.childElementCount?[D]:[],V),M.prepend(a),a.scrollIntoView?.({block:"nearest"}),d.focus({preventScroll:!0}),U=a,c=null}async function se(){if(!E)return;if(c=se,!ge){let t=r.view,a=t?.document.buttons[E.actionId],d=t&&a?.type==="checkout"?ee(a.product,E.selection,t.capabilities):null;if(!d)throw new A("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");let o=await n.resolveOfferId?.({actionId:E.actionId,productVersionId:d});if(p)return;o!==void 0&&(E.offerId=o),ge=!0}if(!S()){f.hidden=!1;return}let e=await r.preview(E);p||_e(e)}function W(e="destroy"){p||(p=!0,n.signal?.removeEventListener("abort",x),r.signal?.removeEventListener("abort",x),C.finish("dismissed"),Oe?.(),pe.abort(),R?.destroy(),Q?.destroy(),r.destroy(),w.open&&w.close(),w.remove(),L.remove(),g(),e==="dismiss"&&z(n.onDismiss))}y=W;async function Pe(){if(!q||p||ne||$==="closing"||!$&&!S())return;if(!v){W("dismiss");return}let e=u.createElement("p");e.setAttribute("role","status"),e.textContent=i?"\u6B63\u5728\u5173\u95ED\u2026":"Closing\u2026",G||(G=u.createElement("div"),G.style.cssText=M.style.cssText,M.replaceWith(G),fe.inert=!0),G.replaceChildren(e,P),$="closing",P.setAttribute("aria-disabled","true"),P.focus({preventScroll:!0});try{await v.dismiss()}catch(t){p||z(n.onError,t)}p||($="retry",e.textContent=i?"\u672A\u80FD\u786E\u8BA4\u5173\u95ED\uFF0C\u8BF7\u91CD\u8BD5\u3002":"Could not confirm closure. Try again.",P.textContent=i?"\u91CD\u8BD5\u5173\u95ED":"Retry closing",P.removeAttribute("aria-label"),P.removeAttribute("aria-disabled"))}P.onclick=()=>{Pe()},w.addEventListener("cancel",e=>{e.preventDefault(),Pe()}),f.onclick=()=>{c&&_(c)};function Ee(e){C.finish("error",e),W()}function ke(){if(!(!Le||q||p||ne||R&&!S()))try{let e=t=>{ye?.(),R&&(w.showModal(),R.responsive&&w.focus({preventScroll:!0}),!t&&n.loading!=="host"&&He(w,R.type,R.responsive)),q=!0};v?v.present(()=>C.present(()=>e(!0))):C.present(e)}catch(e){Ee(e),j(e)}}try{if(B.type==="inline")ye=je(L,s),s.append(L);else{let t={sm:420,md:640,lg:900};w.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in B?t[B.size]+"px":"100vw"}`,w.setAttribute("aria-label",b.document.name),P.textContent="\xD7",P.setAttribute("aria-label",i?"\u5173\u95ED":"Close"),Be(P,b.document.screen.theme),w.append(P,L),s.append(w),R=ze(w,{...b.document.screen,presentation:B},Ne),R.latch(),ye=Ge(w)}Q=Ze(fe,{mode:"live",rendererUrl:r.webViewUrl,title:b.document.name,hostPresentation:()=>R?.type??B.type,onResize:t=>{R?.responsive&&R.setContentHeight(t+(G??M).getBoundingClientRect().height)},onAction(t,a={}){if(!q||p||$)return;if(!S()){xe();return}let d=r.view,o=d?.document.buttons[t];if(!o)return;if(o.type==="close"){_(async()=>{await n.onAction?.(t),W(n.onAction?"action":"dismiss")});return}if(o.type==="action"){c=async()=>{if(o.action.type==="event"){if(!n.onEvent)throw new A("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(o.action.event)}else n.onOpenUrl?await n.onOpenUrl(o.action.url):u.defaultView?.location.assign(o.action.url);await n.onAction?.(t),c=null},_(c);return}if(U&&r.canReselect===!1){m.textContent=i?"\u8BF7\u5148\u786E\u8BA4\u6216\u53D6\u6D88\u5F53\u524D\u8D2D\u4E70\u3002":"Confirm or cancel the current purchase first.",U.scrollIntoView?.({block:"nearest"}),U.querySelector("button")?.focus({preventScroll:!0});return}if((r.quote||E)&&r.canReselect===!1){c=r.quote?Ce:se,_(c);return}let V=d&&ee(o.product,a,d.capabilities);if(!d||!V){j(new A("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(n.onPurchaseIntent){c=null,_(async()=>{let K={actionId:t,productVersionId:V,selection:structuredClone(a),featureQuantities:Me(d.document.screen,V,a,d.capabilities)};we=!0,await n.onPurchaseIntent(K)});return}if(E&&E.actionId!==t){j(new A("COMMAND_PENDING","Finish the current purchase"));return}E||(E={requestId:crypto.randomUUID(),actionId:t,selection:a},ge=!1),_(se)},onEscape:()=>{Pe()},onError:t=>{let a=new Error(t);!q&&!p&&Ee(a),j(a)},onRendered:t=>{t&&w.setAttribute("aria-label",t),Le=!0,ke()}}),Ne(),Q.update(b.document.screen,b.document.screen.strings.defaultLocale,{capabilities:b.capabilities,unavailableActions:Se(b),serverInput:{bindings:[],answers:{}}}),Oe=r.subscribe?.(he),he(r.view??b),await C.wait(Q.ready);let e=r.operation;(r.quote||e&&(e.confirmedAt||e.checkoutUrl||e.status==="complete"))&&(c=Ce,_(c))}catch(e){throw Ee(e),e}return{check:H,host:{get observing(){return me},get recovery(){return nt()},async prepareFallback(){if(J||p||$||we)return{type:"recover",operationId:r.operation?.operationId??r.quote?.operationId??null,requestId:null};oe(!0);try{let e=await Ve(r);return e.type==="native"&&W(),e}finally{oe(!1)}},setSuspended(e){ne=e,L.hidden=e,e&&w.open?w.close():!e&&!q?ke():!e&&!p&&q&&B.type!=="inline"&&!w.open&&w.showModal()},destroy:W,refresh:async()=>{if(!S()){if(r.view)return r.view;throw new A("PRECONDITION_FAILED","Paywall presentation is suspended")}let e=await r.refresh();return he(e),ke(),e}}}}export{Nt as showPaywall};
1
+ import{b as Ye,c as Je}from"./chunk-JGG4R75K.js";import{c as ze,d as He,e as Be,f as de,g as Qe,h as Ge,i as je,k as We}from"./chunk-CNIBGSVO.js";import{a as qe,c as Ae,d as Ve,g as Fe}from"./chunk-PWQ5BHBJ.js";import{b as ee}from"./chunk-HMRIMJ5W.js";import"./chunk-MWDR5FEU.js";import"./chunk-UBKD6VMS.js";import{c as Y,o as Z,oa as te,qa as Me}from"./chunk-5RXU57I5.js";import{c as Ie}from"./chunk-DOJE7VUR.js";import{a as A}from"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import"./chunk-SMIO7OG5.js";import"./chunk-WM27UTWT.js";import{a as z}from"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";async function Ke(s,n,v){if(n.status!=="complete")throw new A("INVALID_RESPONSE","A verified completed purchase is required");let g=s?Z.parse(s):null;if(await v.onComplete?.(n),!g||!v.check)return;let y=Z.parse(await v.check());if(y.internal_feature_id!==g.internal_feature_id||y.quantity!==g.quantity||g.observation!==void 0&&(y.observation===void 0||y.observation.requirementDigest!==g.observation.requirementDigest||y.observation.authority!==g.observation.authority||Ie(y.observation.subject)!==Ie(g.observation.subject)))throw new A("INVALID_RESPONSE","The access requirement changed");y.allowed&&await v.onAccessGranted?.(y)}var st={none:0,sm:4,md:8,lg:14,full:9999},ct={system:"system-ui,sans-serif",serif:"Georgia,serif",rounded:"ui-rounded,system-ui,sans-serif",mono:"ui-monospace,monospace"};function lt(s){let[n,v,g]=[1,3,5].map(y=>{let x=Number.parseInt(s.slice(y,y+2),16)/255;return x<=.03928?x/12.92:((x+.055)/1.055)**2.4});return .2126*n+.7152*v+.0722*g}function Xe(s){let n=lt(s.primary),v=(n+.05)/.05>1.05/(n+.05)?"#111318":"#FFFFFF",g=`color-mix(in srgb, ${s.text} 22%, ${s.background})`,y=`${st[s.radius]}px`,x=`appearance:none;margin:0;min-height:44px;padding:10px 18px;border:0;border-radius:${y};font:inherit;font-size:15px;font-weight:600;line-height:1.25;cursor:pointer;touch-action:manipulation`;return{root:`width:100%;box-sizing:border-box;background:${s.background};color:${s.text};font:14px/1.5 ${ct[s.font]}`,controls:"display:flex;gap:12px;padding:0 20px 12px;align-items:center;flex-wrap:wrap",message:"flex:1 1 200px;min-width:0;margin:0;font-size:13px",panel:`flex:1 0 100%;box-sizing:border-box;display:flex;flex-direction:column;gap:8px;padding:16px;border:1px solid ${g};border-radius:${y}`,summary:"margin:0;font-size:15px;font-weight:600",terms:"display:flex;flex-direction:column;gap:4px;font-size:13px;opacity:.72",actions:"display:flex;gap:8px;flex-wrap:wrap;margin-top:4px",primary:`${x};background:${s.primary};color:${v}`,secondary:`${x};background:transparent;color:${s.text};box-shadow:inset 0 0 0 1px ${g}`,link:`${x};background:transparent;color:${s.text};opacity:.72;font-weight:500`}}function Re(s){s.style.opacity=s.disabled?".55":"",s.style.cursor=s.disabled?"not-allowed":"pointer"}function Se(s){return Object.entries(s.document.buttons).filter(([,n])=>n.type==="checkout"&&n.product.type==="fixed"&&!ee(n.product,{},s.capabilities)).map(([n])=>n)}async function Nt(s,n,v){let g=We(s.ownerDocument),y=()=>{C.finish("dismissed"),g()},x=()=>y(),C=Qe(s,n,"paywall",()=>{y(),z(n.onDismiss)});n.signal?.throwIfAborted(),n.signal?.addEventListener("abort",x,{once:!0});let H=null,N,b,Te;try{if(C.start(!0),C.cancelled)throw new DOMException("Presentation cancelled","AbortError");if(H=n.check?Z.parse(await C.wait(n.check(),de)):null,H?.allowed)return C.finish("skipped"),n.signal?.removeEventListener("abort",x),g(),await n.onAccessGranted?.(H),{check:H,host:null};let[e,t]=await Promise.allSettled([C.wait(import("./screen-renderer-G2EWN3WB.js")),C.wait(n.start().then(d=>(C.cancelled&&d.destroy(),d)),de)]);if(e.status==="rejected")throw t.status==="fulfilled"&&t.value.destroy(),e.reason;if(t.status==="rejected")throw t.reason;Te=e.value,N=t.value,n.signal?.throwIfAborted(),N.signal?.throwIfAborted(),N.signal?.addEventListener("abort",x,{once:!0});let a=N.view??await C.wait(N.refresh(),de);if(!a)throw new A("INVALID_RESPONSE","Paywall presentation is missing");N.signal?.throwIfAborted(),b=a}catch(e){throw C.finish("error",e),n.signal?.removeEventListener("abort",x),N?.signal?.removeEventListener("abort",x),N?.destroy(),g(),e}let r=N,{mountScreenPreview:Ze}=Te,u=s.ownerDocument,pe=new AbortController,L=u.createElement("section"),fe=u.createElement("div"),M=u.createElement("div"),m=u.createElement("p"),f=u.createElement("button"),P=u.createElement("button"),w=u.createElement("dialog"),i=b.document.screen.strings.defaultLocale.startsWith("zh"),et=i?"\u6B63\u5728\u5904\u7406\u2026":"Processing\u2026",tt=i?"\u6B63\u5728\u51C6\u5907\u62A5\u4EF7\u2026":"Preparing your price\u2026",O=Xe(b.document.screen.theme);L.dataset.indianaPaywall="",L.setAttribute("aria-label",b.document.name),L.style.cssText=O.root,M.style.cssText=O.controls,m.style.cssText=O.message,m.setAttribute("role","status"),P.style.cssText=O.link,P.textContent=i?"\u5173\u95ED":"Close",f.style.cssText=O.secondary,f.textContent=i?"\u91CD\u8BD5":"Retry",f.hidden=!0,M.append(m,f,P),L.append(fe,M);let B=b.document.presentation,Q,Oe,me=!1,De=JSON.stringify(b.capabilities);function he(e){if(p)return;b=e;let t=JSON.stringify(e.capabilities);t!==De&&(Q?.updateCapabilities(e.capabilities,Se(e)),De=t),rt(e)}let R;function Ne(){let e=u.defaultView;R?.responsive&&e&&Q?.resizeViewport?.(e.innerHeight,e.innerWidth)}let p=!1,J=!1,E=null,ne=!1,Le=!1,q=!1,ye,we=!1,$,G;function nt(){return J||p||$||we?{type:"recover",operationId:r.operation?.operationId??r.quote?.operationId??null,requestId:null}:Ae(r)}let S=()=>!p&&!ne&&!$&&n.canInteract?.()!==!1,ge=!1,c=null,U=null;function rt(e){J||E||r.quote||r.operation||(m.textContent=Object.values(e.capabilities.plans).some(t=>t.available)?"":i?"\u5F53\u524D\u8D26\u53F7\u6682\u65E0\u53EF\u8D2D\u4E70\u7684\u65B9\u6848\u3002":"No plans are currently available for this account.")}let be=new Map,re=e=>qe({quote:r.quote,operation:e,requestId:null,pending:!1,destroyed:p,canReselect:r.canReselect});async function ve(e){let t=e.merchantExecution;if(!(!S()||!e.checkoutUrl||n.checkoutNavigation==="after_confirmation"&&re(e).type!=="checkout"||t?.type==="purchase"&&!["not_started","pending"].includes(t.paymentStatus)||be.get(e.operationId)===e.checkoutUrl)){be.set(e.operationId,e.checkoutUrl);try{n.onCheckoutUrl?await n.onCheckoutUrl(e.checkoutUrl):u.defaultView?.location.assign(e.checkoutUrl)}catch(a){throw be.delete(e.operationId),a}}}let j=(e,t=!1)=>{if(t){let a=e instanceof A?e.code:void 0;a==="CAPABILITY_UNAVAILABLE"||a==="NOT_CONFIGURED"?(c=null,m.textContent=i?"\u6682\u65F6\u65E0\u6CD5\u4E3A\u6B64\u5957\u9910\u62A5\u4EF7\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002":"Pricing for this plan is unavailable. Payment hasn\u2019t started."):a==="COMMAND_PENDING"?m.textContent=i?"\u4ECD\u5728\u51C6\u5907\u62A5\u4EF7\uFF0C\u8BF7\u91CD\u8BD5\u4EE5\u67E5\u770B\u7ED3\u679C\u3002":"Your price is still being prepared. Retry to check the result.":m.textContent=i?"\u672A\u80FD\u53D6\u5F97\u62A5\u4EF7\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002\u8BF7\u91CD\u8BD5\u3002":"We couldn\u2019t prepare your price. Payment hasn\u2019t started. Try again."}else m.textContent=e instanceof Error?e.message:i?"\u8BF7\u6C42\u5931\u8D25":"Request failed";f.hidden=c===null,t&&m.scrollIntoView?.({block:"nearest"}),z(t&&v?.quoteError?v.quoteError:n.onError,e)},ie=new WeakMap;function oe(e){J=e;for(let t of U?.querySelectorAll("button")??[])e?(ie.set(t,t.disabled),t.disabled=!0):ie.has(t)&&(t.disabled=ie.get(t),ie.delete(t)),Re(t)}function xe(){m.textContent=i?"\u6682\u65F6\u65E0\u6CD5\u64CD\u4F5C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002":"This action is unavailable right now. Try again in a moment."}async function it(e){if(n.beforeAction)try{await n.beforeAction()}catch(t){throw c=e,t}}async function _(e){if(J||p)return;if(!S()){xe();return}let t=e===se,a=t?tt:et;oe(!0),f.hidden=!0,m.textContent=a,t&&m.scrollIntoView?.({block:"nearest"});try{if(await it(e),p)return;if(!S()){c=e,f.hidden=!1,xe();return}await e()}catch(d){p||j(d,t)}finally{oe(!1),m.textContent===a&&(m.textContent="")}}async function ot(e){await Ke(H,e,n)}function Ue(e){return Ae(r).type==="recording"||re(e).type==="recording"}async function k(e,t=n.checkoutNavigation!=="after_confirmation"){if(p)return;if(!S()){c=async()=>k(await r.read()),f.hidden=!1;return}if(m.textContent=Je(e.status,i),Ue(e)){let o=e.merchantExecution?.type==="purchase"&&e.merchantExecution.recordingStatus==="failed";m.textContent=o?i?"\u4ED8\u6B3E\u548C\u5546\u6237\u5904\u7406\u5DF2\u5B8C\u6210\uFF0C\u4F46\u4EA4\u6613\u8BB0\u5F55\u5931\u8D25\u3002\u8BF7\u8054\u7CFB\u5546\u6237\u4FEE\u590D\uFF0C\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"Payment and fulfillment succeeded, but recording failed. Contact the merchant to repair this purchase; do not buy again.":i?"\u4ED8\u6B3E\u548C\u5546\u6237\u5904\u7406\u5DF2\u5B8C\u6210\uFF0C\u6B63\u5728\u786E\u8BA4\u4EA4\u6613\u8BB0\u5F55\u3002\u8BF7\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"Payment and merchant fulfillment are complete. Recording is pending confirmation; do not purchase again.",f.textContent=i?"\u67E5\u8BE2\u8BB0\u5F55":"Check recording",c=async()=>k(await r.read()),f.hidden=!1;return}if(e.problem){let o=e.problem;c=ae,f.textContent=i?"\u68C0\u67E5\u5E76\u6062\u590D\u539F\u64CD\u4F5C":"Check and recover original purchase",j(new A(o.code,o.reason==="RESULT_UNKNOWN"?i?"\u4ED8\u6B3E\u7ED3\u679C\u5C1A\u672A\u786E\u5B9A\uFF0C\u8BF7\u6062\u590D\u539F\u64CD\u4F5C\uFF0C\u6682\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"The payment result is unknown. Recover the original purchase before buying again.":o.phase==="fulfillment"?i?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u5546\u6237\u6743\u76CA\u5904\u7406\u9700\u8981\u6838\u5BF9\u3002":"Payment was recorded. Access fulfillment needs attention.":o.code==="CAPABILITY_UNAVAILABLE"?i?"\u5546\u6237\u5C1A\u4E0D\u652F\u6301\u672C\u6B21\u8D2D\u4E70\u6240\u9700\u7684\u5B8C\u6574\u80FD\u529B\uFF0C\u8BF7\u5904\u7406\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The merchant does not currently support all actions required by this purchase. Recover the original purchase after this is resolved.":o.code==="NOT_CONFIGURED"?i?"\u4ED8\u6B3E\u670D\u52A1\u8FDE\u63A5\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u8054\u7CFB\u5546\u6237\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The payment connection needs attention. Contact the merchant, then recover the original purchase.":i?"\u539F\u8D2D\u4E70\u64CD\u4F5C\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u67E5\u8BE2\u6216\u6062\u590D\u6B64\u64CD\u4F5C\u3002":"The original purchase needs attention. Check or recover this operation.",void 0,void 0,o));return}if(e.merchantExecution?.type==="purchase"&&e.merchantExecution.paymentStatus==="succeeded"&&!["applied","not_applicable"].includes(e.merchantExecution.fulfillmentStatus)&&(m.textContent=i?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u6B63\u5728\u7B49\u5F85\u5546\u6237\u5B8C\u6210\u5904\u7406\u3002":"Payment was recorded. Waiting for merchant fulfillment."),e.status==="complete"){c=null,await ot(e);return}if(e.status!=="pending"){if(r.canReselect===!1){m.textContent=i?"\u6B63\u5728\u6838\u5BF9\u539F\u8D2D\u4E70\u7ED3\u679C":"Checking the original purchase result",f.textContent=i?"\u67E5\u8BE2\u7ED3\u679C":"Check result",c=async()=>k(await r.read()),f.hidden=!1;return}f.textContent=i?"\u91CD\u8BD5":"Retry",c=null,E=null;return}if(!t&&re(e).type==="checkout"){m.textContent=i?"\u539F\u4ED8\u6B3E\u5C1A\u672A\u5B8C\u6210\uFF0C\u53EF\u7EE7\u7EED\u539F\u6536\u94F6\u53F0\u3002":"Payment is unfinished. Continue the original checkout.",f.textContent=i?"\u7EE7\u7EED\u4ED8\u6B3E":"Continue checkout",c=async()=>k(await r.read(),!0),f.hidden=!1;return}await ve(e);let a=Date.now()+6e5,d=2e3;me=!0,z(n.onObservationChange,!0);try{for(;!p&&Date.now()<a;){if(await Ye(d,u,pe.signal),p)return;if(!S()){c=async()=>k(await r.read()),f.hidden=!1;return}let o=await r.read();if(!t&&re(o).type==="checkout"){await k(o,!1);return}if(!o.problem&&o.status==="pending"&&await ve(o),o.status!=="pending"||o.problem||Ue(o)){await k(o);return}d=Math.min(d*1.5,3e4)}}finally{me=!1,z(n.onObservationChange,!1)}c=async()=>k(await r.read()),f.hidden=!1}async function Ce(){let e=await r.read();if(p)return;if(!S()){c=Ce,f.hidden=!1;return}let t=r.quote;if(t&&Fe(e,{operationId:t.operationId,currency:t.currency},"The original purchase operation changed"),t&&e.status==="pending"&&e.quoteFinalized===!1&&!e.confirmedAt&&!e.checkoutUrl&&!e.nativePurchase&&!e.merchantExecution&&!e.problem&&!r.pendingCancellation){_e(t);return}await k(e)}async function ae(){U?.remove(),U=null,c=ae;let e=await r.confirm();if(!S()){c=ae,f.hidden=!1;return}if(e.problem){await k(e);return}if(e.status==="pending"){if(e.checkoutUrl)await ve(e);else if(e.execution&&e.execution.provider!=="merchant"||e.nativePurchase){if(!n.onPurchase)throw new A("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await n.onPurchase({operation:e,signal:pe.signal})}}c=async()=>k(await r.read()),await k(e,!0)}function _e(e){U?.remove();let t=!(Date.parse(e.expiresAt)>Date.now());m.textContent=t?i?"\u6B64\u62A5\u4EF7\u5DF2\u8FC7\u671F\u3002\u8BF7\u5148\u53D6\u6D88\uFF0C\u518D\u91CD\u65B0\u9009\u62E9\u3002":"This quote has expired. Cancel it, then choose again.":"";let a=u.createElement("div"),d=u.createElement("button"),o=u.createElement("button"),V=u.createElement("div"),K=u.createElement("p"),T=e.merchantTerms,ce=T?T.totalMinor:e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),le=i?"zh-CN":"en",ue=T?.subscriptionTerms?.items??[],X=T?ue.length===1&&ue[0]?.amountMinor===ce&&ue[0]:e.lines.length===1&&e.lines[0]?.catalogAmountMinor===ce&&e.lines[0];K.textContent=e.lines.map(l=>l.productName).join(", ")+" \xB7 "+(ce===null?i?`${Y(T.subtotalMinor-T.discountMinor,e.currency)} + \u5F85\u786E\u8BA4\u7A0E\u8D39`:`${Y(T.subtotalMinor-T.discountMinor,e.currency)} + tax confirmed at checkout`:Y(ce,e.currency)+(X?te(X.interval,le,X.intervalCount??1):"")),d.textContent=i?"\u786E\u8BA4\u8D2D\u4E70":"Confirm purchase",d.disabled=t,o.textContent=i?"\u53D6\u6D88":"Cancel",a.style.cssText=O.panel,K.style.cssText=O.summary,V.style.cssText=O.actions,d.style.cssText=O.primary,o.style.cssText=O.secondary,Re(d),d.onclick=()=>{_(ae)};let $e=async()=>{let l=await r.cancel();p||(a.remove(),U=null,await k(l))};o.onclick=()=>{c=$e,_($e)};let D=u.createElement("div");if(D.style.cssText=O.terms,T){for(let h of ue){if(h===X)continue;let I=u.createElement("p");I.textContent=Y(h.amountMinor,e.currency)+te(h.interval,le,h.intervalCount),D.append(I)}let l=T.subscriptionTerms?.trial;if(l){let h=u.createElement("p");h.textContent=i?`\u8BD5\u7528 ${l.days} \u5929\uFF1B${l.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${l.days}; ${l.cardRequired?"a payment method is required":"no payment method is required"}`,D.append(h)}for(let h of[...T.expectedEffects.map(I=>I.description),...T.requiredConsents.map(I=>I.summary)]){let I=u.createElement("p");I.textContent=h,D.append(I)}}else{for(let l of e.lines){if(l!==X){let h=u.createElement("p");h.textContent=`${l.productName} \xB7 ${Y(l.catalogAmountMinor,e.currency)}${te(l.interval,le,l.intervalCount??1)}`,D.append(h)}for(let h of l.prepaid??[]){let I=u.createElement("p"),F=r.view?.capabilities.plans[l.productVersionId]?.prepaid?.find(at=>at.internalFeatureId===h.internal_feature_id);I.textContent=`${F?.name??h.internal_feature_id} \xB7 ${h.quantity} ${i?"\u4EFD":"packs"} \xD7 ${h.terms.units}`,F&&(I.textContent+=te(F.reset==="week"||F.reset==="month"||F.reset==="year"?F.reset:"one_time",le,F.resetCount)),D.append(I)}if(l.trial){let h=u.createElement("p");h.textContent=i?`\u8BD5\u7528 ${l.trial.days} \u5929\uFF1B${l.trial.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${l.trial.days}; ${l.trial.cardRequired?"a payment method is required":"no payment method is required"}`,D.append(h)}}if(!e.charge){let l=u.createElement("p");l.textContent=i?"\u76EE\u5F55\u4EF7\u683C\uFF1B\u6700\u7EC8\u91D1\u989D\u4EE5\u7ED3\u8D26\u65F6\u7A0E\u8D39\u548C\u8BD5\u7528\u89C4\u5219\u4E3A\u51C6\u3002":"Catalog price; the final charge depends on checkout taxes and trial terms.",D.append(l)}}for(let l of D.children)l.style.margin="0";V.append(d,o),a.append(K,...D.childElementCount?[D]:[],V),M.prepend(a),a.scrollIntoView?.({block:"nearest"}),d.focus({preventScroll:!0}),U=a,c=null}async function se(){if(!E)return;if(c=se,!ge){let t=r.view,a=t?.document.buttons[E.actionId],d=t&&a?.type==="checkout"?ee(a.product,E.selection,t.capabilities):null;if(!d)throw new A("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");let o=await n.resolveOfferId?.({actionId:E.actionId,productVersionId:d});if(p)return;o!==void 0&&(E.offerId=o),ge=!0}if(!S()){f.hidden=!1;return}let e=await r.preview(E);p||_e(e)}function W(e="destroy"){p||(p=!0,n.signal?.removeEventListener("abort",x),r.signal?.removeEventListener("abort",x),C.finish("dismissed"),Oe?.(),pe.abort(),R?.destroy(),Q?.destroy(),r.destroy(),w.open&&w.close(),w.remove(),L.remove(),g(),e==="dismiss"&&z(n.onDismiss))}y=W;async function Pe(){if(!q||p||ne||$==="closing"||!$&&!S())return;if(!v){W("dismiss");return}let e=u.createElement("p");e.setAttribute("role","status"),e.textContent=i?"\u6B63\u5728\u5173\u95ED\u2026":"Closing\u2026",G||(G=u.createElement("div"),G.style.cssText=M.style.cssText,M.replaceWith(G),fe.inert=!0),G.replaceChildren(e,P),$="closing",P.setAttribute("aria-disabled","true"),P.focus({preventScroll:!0});try{await v.dismiss()}catch(t){p||z(n.onError,t)}p||($="retry",e.textContent=i?"\u672A\u80FD\u786E\u8BA4\u5173\u95ED\uFF0C\u8BF7\u91CD\u8BD5\u3002":"Could not confirm closure. Try again.",P.textContent=i?"\u91CD\u8BD5\u5173\u95ED":"Retry closing",P.removeAttribute("aria-label"),P.removeAttribute("aria-disabled"))}P.onclick=()=>{Pe()},w.addEventListener("cancel",e=>{e.preventDefault(),Pe()}),f.onclick=()=>{c&&_(c)};function Ee(e){C.finish("error",e),W()}function ke(){if(!(!Le||q||p||ne||R&&!S()))try{let e=t=>{ye?.(),R&&(w.showModal(),R.responsive&&w.focus({preventScroll:!0}),!t&&n.loading!=="host"&&He(w,R.type,R.responsive)),q=!0};v?v.present(()=>C.present(()=>e(!0))):C.present(e)}catch(e){Ee(e),j(e)}}try{if(B.type==="inline")ye=je(L,s),s.append(L);else{let t={sm:420,md:640,lg:900};w.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in B?t[B.size]+"px":"100vw"}`,w.setAttribute("aria-label",b.document.name),P.textContent="\xD7",P.setAttribute("aria-label",i?"\u5173\u95ED":"Close"),Be(P,b.document.screen.theme),w.append(P,L),s.append(w),R=ze(w,{...b.document.screen,presentation:B},Ne),R.latch(),ye=Ge(w)}Q=Ze(fe,{mode:"live",rendererUrl:r.webViewUrl,title:b.document.name,hostPresentation:()=>R?.type??B.type,onResize:t=>{R?.responsive&&R.setContentHeight(t+(G??M).getBoundingClientRect().height)},onAction(t,a={}){if(!q||p||$)return;if(!S()){xe();return}let d=r.view,o=d?.document.buttons[t];if(!o)return;if(o.type==="close"){_(async()=>{await n.onAction?.(t),W(n.onAction?"action":"dismiss")});return}if(o.type==="action"){c=async()=>{if(o.action.type==="event"){if(!n.onEvent)throw new A("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(o.action.event)}else n.onOpenUrl?await n.onOpenUrl(o.action.url):u.defaultView?.location.assign(o.action.url);await n.onAction?.(t),c=null},_(c);return}if(U&&r.canReselect===!1){m.textContent=i?"\u8BF7\u5148\u786E\u8BA4\u6216\u53D6\u6D88\u5F53\u524D\u8D2D\u4E70\u3002":"Confirm or cancel the current purchase first.",U.scrollIntoView?.({block:"nearest"}),U.querySelector("button")?.focus({preventScroll:!0});return}if((r.quote||E)&&r.canReselect===!1){c=r.quote?Ce:se,_(c);return}let V=d&&ee(o.product,a,d.capabilities);if(!d||!V){j(new A("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(n.onPurchaseIntent){c=null,_(async()=>{let K={actionId:t,productVersionId:V,selection:structuredClone(a),featureQuantities:Me(d.document.screen,V,a,d.capabilities)};we=!0,await n.onPurchaseIntent(K)});return}if(E&&E.actionId!==t){j(new A("COMMAND_PENDING","Finish the current purchase"));return}E||(E={requestId:crypto.randomUUID(),actionId:t,selection:a},ge=!1),_(se)},onEscape:()=>{Pe()},onError:t=>{let a=new Error(t);!q&&!p&&Ee(a),j(a)},onRendered:t=>{t&&w.setAttribute("aria-label",t),Le=!0,ke()}}),Ne(),Q.update(b.document.screen,b.document.screen.strings.defaultLocale,{capabilities:b.capabilities,unavailableActions:Se(b),serverInput:{bindings:[],answers:{}}}),Oe=r.subscribe?.(he),he(r.view??b),await C.wait(Q.ready);let e=r.operation;(r.quote||e&&(e.confirmedAt||e.checkoutUrl||e.status==="complete"))&&(c=Ce,_(c))}catch(e){throw Ee(e),e}return{check:H,host:{get observing(){return me},get recovery(){return nt()},async prepareFallback(){if(J||p||$||we)return{type:"recover",operationId:r.operation?.operationId??r.quote?.operationId??null,requestId:null};oe(!0);try{let e=await Ve(r);return e.type==="native"&&W(),e}finally{oe(!1)}},setSuspended(e){ne=e,L.hidden=e,e&&w.open?w.close():!e&&!q?ke():!e&&!p&&q&&B.type!=="inline"&&!w.open&&w.showModal()},destroy:W,refresh:async()=>{if(!S()){if(r.view)return r.view;throw new A("PRECONDITION_FAILED","Paywall presentation is suspended")}let e=await r.refresh();return he(e),ke(),e}}}}export{Nt as showPaywall};
@@ -1 +1 @@
1
- import{a}from"./chunk-5K2E5XBL.js";import"./chunk-6VY4PZZ6.js";import"./chunk-2KOQBV3Y.js";import"./chunk-BZSKOOMM.js";import"./chunk-LPDUK7HT.js";import"./chunk-6DBYFYEU.js";import"./chunk-GIV4FOOW.js";import"./chunk-MYUYN7ZG.js";import"./chunk-C6JRUYKW.js";import"./chunk-PMCGTXGH.js";import"./chunk-7CFF6SWH.js";import"./chunk-PWQ5BHBJ.js";import"./chunk-HMRIMJ5W.js";import"./chunk-NMKZ724L.js";import"./chunk-NZSLDALU.js";import"./chunk-UBKD6VMS.js";import"./chunk-5RXU57I5.js";import"./chunk-DOJE7VUR.js";import"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import"./chunk-3VUPVXAV.js";import"./chunk-ATMVXNDD.js";import"./chunk-WM27UTWT.js";import"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as createPaywallSession};
1
+ import{a}from"./chunk-CZ3H2X7D.js";import"./chunk-6VY4PZZ6.js";import"./chunk-2KOQBV3Y.js";import"./chunk-BZSKOOMM.js";import"./chunk-LPDUK7HT.js";import"./chunk-G7NSECIG.js";import"./chunk-GIV4FOOW.js";import"./chunk-MYUYN7ZG.js";import"./chunk-C6JRUYKW.js";import"./chunk-PMCGTXGH.js";import"./chunk-7CFF6SWH.js";import"./chunk-PWQ5BHBJ.js";import"./chunk-HMRIMJ5W.js";import"./chunk-NMKZ724L.js";import"./chunk-MWDR5FEU.js";import"./chunk-UBKD6VMS.js";import"./chunk-5RXU57I5.js";import"./chunk-DOJE7VUR.js";import"./chunk-X7G7JMZ3.js";import"./chunk-JAKOBECD.js";import"./chunk-3VUPVXAV.js";import"./chunk-SMIO7OG5.js";import"./chunk-WM27UTWT.js";import"./chunk-DSPLGTQI.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as createPaywallSession};