@tinkerlandai/longplay-sdk 0.10.50 → 0.10.51
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.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/dist/chunk-2G23BYBI.js +1 -0
- package/dist/{chunk-GMKLSHXK.js → chunk-3TSFGU4T.js} +1 -1
- package/dist/{chunk-A2ZWWIUK.js → chunk-3Z3HL42M.js} +2 -2
- package/dist/{chunk-CGJMEKO2.js → chunk-4NO6U4X6.js} +1 -1
- package/dist/{chunk-T3AEVS6M.js → chunk-67LPUJMN.js} +1 -1
- package/dist/{chunk-KECKTHAM.js → chunk-7GU34JD4.js} +1 -1
- package/dist/{chunk-ZS2AOY44.js → chunk-B4SM2KRI.js} +1 -1
- package/dist/chunk-CGJZIDG3.js +1 -0
- package/dist/{chunk-PMUKZX2R.js → chunk-DB5S72HJ.js} +1 -1
- package/dist/{chunk-KKKO6GZ5.js → chunk-FN462OVO.js} +1 -1
- package/dist/{chunk-Z7ESO2IN.js → chunk-GJSQZGBE.js} +1 -1
- package/dist/chunk-IXXVMGMF.js +1 -0
- package/dist/{chunk-5J2CFNYR.js → chunk-MVUNV5XR.js} +1 -1
- package/dist/{chunk-K4TQ5REL.js → chunk-TIUD3N72.js} +1 -1
- package/dist/chunk-TM72XBM5.js +1 -0
- package/dist/{chunk-XLTR45M5.js → chunk-US65SQX4.js} +1 -1
- package/dist/{chunk-EFROBK74.js → chunk-VPYKAEHU.js} +1 -1
- package/dist/{content-AZXMOLCZ.js → content-VTHRQSFT.js} +1 -1
- package/dist/funnel-host-purchase-HBQOWEES.js +1 -0
- package/dist/{funnel-paywall-prerender-HWQX4YNE.js → funnel-paywall-prerender-MD4UI2AP.js} +1 -1
- package/dist/{funnel-runtime-host-Y4IEIGCK.js → funnel-runtime-host-NZAV6C5O.js} +1 -1
- package/dist/index.d.ts +21 -7
- package/dist/index.js +1 -1
- package/dist/native-shell.js +1 -1
- package/dist/openrouter.js +1 -1
- package/dist/page.js +1 -1
- package/dist/paywall-DKTGQZDJ.js +1 -0
- package/dist/{paywall-content-TPXYF6DN.js → paywall-content-SML4CL2Q.js} +1 -1
- package/dist/{paywall-session-FQ4VC5WG.js → paywall-session-YKE2CHHI.js} +1 -1
- package/dist/popup.d.ts +2 -2
- package/dist/popup.js +1 -1
- package/dist/{presentation-loading-BaPatcfq.d.ts → presentation-loading-BWUNotNa.d.ts} +8 -1
- package/dist/react-native.js +1 -1
- package/dist/{screen-renderer-Y57TAOIX.js → screen-renderer-HW2WXDTR.js} +1 -1
- package/dist/server.js +1 -1
- package/dist/visual.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-A4TLE4OF.js +0 -1
- package/dist/chunk-J6UQGMH5.js +0 -1
- package/dist/chunk-P5NO4YS3.js +0 -1
- package/dist/chunk-WEHUXUXS.js +0 -1
- package/dist/funnel-host-purchase-VS4BXFCP.js +0 -1
- package/dist/paywall-LNVEFOAB.js +0 -1
- /package/dist/{chunk-A2ZWWIUK.js.LEGAL.txt → chunk-3Z3HL42M.js.LEGAL.txt} +0 -0
package/dist/openrouter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-PJAZ2UP4.js";import"./chunk-IVXYLNAF.js";import"./chunk-
|
|
1
|
+
import"./chunk-PJAZ2UP4.js";import"./chunk-IVXYLNAF.js";import"./chunk-FN462OVO.js";import"./chunk-FRRKTQNZ.js";import{a as i}from"./chunk-ZDIWOE4Q.js";import"./chunk-FYD7CMS7.js";import"./chunk-B4SM2KRI.js";import{b as A}from"./chunk-XVCSRZX4.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-
|
|
1
|
+
import{d as o,e as r,f as e,g as f}from"./chunk-3Z3HL42M.js";import"./chunk-GJSQZGBE.js";import"./chunk-3VUPVXAV.js";import"./chunk-B4SM2KRI.js";import"./chunk-DSPLGTQI.js";import"./chunk-A5KU4MMN.js";import"./chunk-WPFTSHP2.js";import"./chunk-WOT6VMZA.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as Ft,c as qt,d as pt,f as mt,g as Gt,k as Wt}from"./chunk-7GU34JD4.js";import{b as dt}from"./chunk-W32FI2A2.js";import{d as Vt,e as $t,f as Qt,h as ft,i as qe,j as Ht,k as jt,l as Bt}from"./chunk-2G23BYBI.js";import{a as Lt,c as ct,d as Nt,e as _t}from"./chunk-LSHIR6QM.js";import{a as Fe,b as we,d as ut,f as Mt,j as Ut}from"./chunk-OPUIFAQS.js";import{b as de}from"./chunk-HYX3EDZS.js";import{B as S,C as Be,D as Re,E as Oe,y as Dt}from"./chunk-EGFVGCDG.js";import"./chunk-YFLVGOCJ.js";import"./chunk-VILB5M4X.js";import"./chunk-FN462OVO.js";import"./chunk-FRRKTQNZ.js";import{r as Pe,t as ye}from"./chunk-MQ5LJEWV.js";import{i as St}from"./chunk-JDIFYMSA.js";import{c as ue,j as Ae}from"./chunk-TNPBYYAX.js";import{c as lt}from"./chunk-KCN6OGYG.js";import"./chunk-PF6PRPRO.js";import{a as v}from"./chunk-ZDIWOE4Q.js";import"./chunk-FYD7CMS7.js";import"./chunk-B4SM2KRI.js";import"./chunk-XVCSRZX4.js";import{a as G}from"./chunk-DSPLGTQI.js";import"./chunk-A5KU4MMN.js";import"./chunk-WPFTSHP2.js";import"./chunk-WOT6VMZA.js";async function zt(_,r,x){if(!Re(r))throw new v("INVALID_RESPONSE","A verified completed purchase is required");let k=_?Ae.parse(_):null;if(await x.onComplete?.(r),!k||!x.check)return;let Q=Ae.parse(await x.check());if(Q.internal_feature_id!==k.internal_feature_id||Q.quantity!==k.quantity||k.observation!==void 0&&(Q.observation===void 0||Q.observation.requirementDigest!==k.observation.requirementDigest||Q.observation.authority!==k.observation.authority||lt(Q.observation.subject)!==lt(k.observation.subject)))throw new v("INVALID_RESPONSE","The access requirement changed");Q.allowed&&await x.onAccessGranted?.(Q)}function ht(_){return Object.entries(_.document.buttons).filter(([,r])=>r.type==="checkout"&&r.product.type==="fixed"&&!de(r.product,{},_.capabilities)).map(([r])=>r)}function Yt(_,r){let x=S(r)?void 0:r.lines[0];if(!S(r)&&(r.lines.length!==1||!x))return;let k=S(r)?r.productVersionId:x.productVersionId,{screen:Q,buttons:X}=_.document,R=new Map(S(r)?Object.entries(r.featureQuantities??{}):(x?.prepaid??[]).map(h=>[h.internal_feature_id,h.quantity]));function Z(h,m){if(h.hidden)return!1;if(h.type==="plan_picker"&&_.capabilities.pickers[h.id]?.options.includes(k))return m[h.id]=k,!0;if(h.type==="quantity_picker"){let Y=R.get(h.internalFeatureId);return Y!==void 0&&(!h.bind?.plan||h.bind.plan===k)&&(m[h.id]=Y),!1}if(h.type==="button"&&h.action){let Y=X[h.action];return Y?.type==="checkout"&&Y.product.type==="fixed"&&Y.product.productVersionId===k}if(h.type!=="stack")return!1;let z=h.interaction,i=h.bind?.plan===k;for(let[Y,f]of h.children.entries()){let ie={},L=Z(f,ie);if(z?.type==="toggle"||z?.type==="tabs"){if(!L)continue;return m[h.id]=z.type==="toggle"?Y===0:f.id,Object.assign(m,ie),!0}Object.assign(m,ie),L&&(i=!0,z?.type==="select"&&z.purpose==="product"&&z.pickerId&&f.type==="stack"&&f.bind?.plan===k&&(m[h.id]=f.id,m[z.pickerId]=k))}return i}for(let h of Q.pages){let m={__page:h.id};if(Z(h.root,m))return m}}async function Un(_,r,x){let k=r.focusAtReveal?()=>{}:ft(_.ownerDocument),Q=()=>{R.finish("dismissed"),k()},X=()=>Q(),R=Ht(_,r,"paywall",()=>{Q(),G(r.onDismiss)},Ft);r.signal?.throwIfAborted(),r.signal?.addEventListener("abort",X,{once:!0});let Z=null,h,m,z;try{if(R.start(!0,r.loadingDocument?.screen.strings.defaultLocale,r.loadingDocument??null),R.cancelled)throw new DOMException("Presentation cancelled","AbortError");if(Z=r.check?Ae.parse(await R.wait(r.check(),qe)):null,Z?.allowed)return R.finish("skipped"),r.signal?.removeEventListener("abort",X),k(),await r.onAccessGranted?.(Z),{check:Z,host:null};let[e,n]=await Promise.allSettled([R.wait(import("./screen-renderer-HW2WXDTR.js")),R.wait(r.start().then(a=>(R.cancelled&&a.destroy(),a)),qe)]);if(e.status==="rejected")throw n.status==="fulfilled"&&n.value.destroy(),e.reason;if(n.status==="rejected")throw n.reason;z=e.value,h=n.value,r.signal?.throwIfAborted(),h.signal?.throwIfAborted(),h.signal?.addEventListener("abort",X,{once:!0});let t=h.view??await R.wait(h.refresh(),qe);if(!t)throw new v("INVALID_RESPONSE","Paywall presentation is missing");h.signal?.throwIfAborted(),m=t}catch(e){throw R.finish("error",e),r.signal?.removeEventListener("abort",X),h?.signal?.removeEventListener("abort",X),h?.destroy(),k(),e}let i=h,{mountScreenPreview:Y}=z,f=_.ownerDocument,ie=new AbortController,L=f.createElement("section"),ae=f.createElement("div"),J=f.createElement("div"),Ge=r.mountControls,W=Ge?f.createElement("div"):void 0,p=f.createElement("p"),C=f.createElement("button"),I=f.createElement("button"),E=f.createElement("dialog"),We=i.locale||m.document.screen.strings.defaultLocale,o=We.toLowerCase().startsWith("zh"),Jt=o?"正在处理…":"Processing…",Kt=o?"正在准备报价…":"Preparing your price…",M=qt(m.document.screen.theme);L.dataset.indianaPaywall="",L.setAttribute("aria-label",m.document.name),L.style.cssText=M.root,J.style.cssText=M.controls,p.style.cssText=M.message,p.setAttribute("role","status"),I.style.cssText=M.link,I.textContent=o?"关闭":"Close",C.style.cssText=M.secondary,C.textContent=o?"重试":"Retry",C.hidden=!0,J.append(p,C,I),W&&(W.style.cssText="flex:1 0 100%;min-width:0",W.hidden=!0,J.prepend(W)),L.append(ae,J);let ze=()=>{if(W){let a=!W.childElementCount&&!W.textContent?.trim();W.hidden!==a&&(W.hidden=a)}let e=se??J,n=[...e.children].every(a=>a===p?!p.textContent:a.hidden),t=[...e.children].some(a=>a===I?!1:a===p?!!p.textContent:!a.hidden);e.style.cssText=n?M.controls.replace(/padding:[^;]+/,"padding:0"):t?`${M.controls};${M.pinned}`:M.controls,Xe()},yt=typeof MutationObserver>"u"?void 0:new MutationObserver(ze);yt?.observe(L,{attributes:!0,attributeFilter:["hidden"],characterData:!0,childList:!0,subtree:!0});let Te=m.document.presentation,Xt=Object.entries(m.document.buttons).filter(([,e])=>e.type==="close").map(([e])=>e),B,wt,Ye=!1,gt=JSON.stringify(m.capabilities),Je=e=>oe&&!Ce?Object.entries(e.document.buttons).filter(([,n])=>n.type==="checkout").map(([n])=>n):ht(e);function Se(e){if(w)return;m=e;let n=JSON.stringify(e.capabilities);if(n!==gt){let t=!b&&!i.quote&&!i.operation?Fe(e,q,Ct):q;JSON.stringify(t)!==JSON.stringify(q)?(q=t,B?.update(e.document.screen,We,{capabilities:we(e),unavailableActions:Je(e),serverInput:{bindings:[],answers:{}},selection:q})):B?.updateCapabilities(we(e),Je(e)),gt=n}en(e),ke()}let O,Ke=0;function Xe(){let e=f.defaultView;if(!O?.responsive||!e)return;let n=se??J,t=e.innerHeight-(O.type==="modal"?32:0);n.style.maxHeight=`${Math.max(1,t)}px`,n.style.overflowY="auto",n.style.flexShrink="0",Ke=Math.max(1,t-n.getBoundingClientRect().height),B?.resizeViewport?.(Ke,e.innerWidth)}let w=!1,oe=!1,b=null,Ze,De=!1,bt=!1,fe=!1,et,tt=!1,ee,se;function Zt(){return oe||w||ee||tt?{type:"recover",operationId:i.operation?.operationId??i.quote?.operationId??null,requestId:null}:ct(i)}let A=()=>!w&&!De&&!ee&&r.canInteract?.()!==!1,F,ge=!1,be=!1,u=null,te=null,nt="",pe=()=>r.checkoutNavigation==="after_confirmation"&&!!(r.terminateCheckout||r.resumeCheckout),q={},Ct=new Set,Ce,K=null;function ke(){if(!pe()||!B?.updateCheckoutControls)return;let e=i.quote,n=!K&&!!e&&!!i.operation&&T(i.operation).type==="checkout",t=Object.entries(m.document.buttons).flatMap(([a,c])=>c.type==="checkout"?[{actionId:a,policy:c}]:[]);B.updateCheckoutControls({actions:t.map(({actionId:a})=>a),resume:n?t.filter(({actionId:a,policy:c})=>Me(e,m,a,c.product,q)).map(({actionId:a})=>a):[],resumeLabel:o?"继续付款":"Continue checkout",busy:Ce})}function vt(){te?.remove(),te=null}async function rt(){if(K)return;if(r.resumeCheckout&&i.operation){await r.resumeCheckout(i.operation.operationId);return}let e=await i.read();if(T(e).type!=="checkout")return U(e,!1);A()&&(Ne.delete(e.operationId),await Ue(e))}function Pt(){p.textContent=o?"暂时无法打开付款页面。请重试。":"Couldn’t open checkout. Try again.",C.hidden=!0}async function kt(e=!1){let n=K;if(!n)return;C.hidden=!0;let t=Date.now()+2e4;for(;A();){let a=await i.read();if(a.operationId!==n.operationId)throw new v("PURCHASE_PENDING","The original Checkout changed");if(!A())break;let c=T(a);if(c.type==="native"){K=null,vt(),b=n.selection,F=n.coupon,ge=!1,be=!1,await Ie();return}if(c.type==="complete"||c.type==="fulfillment"||c.type==="recording"){K=null,await U(a,!1);return}if(e&&c.type==="checkout"){e=!1;try{await r.terminateCheckout(n.operationId)}catch(y){G(r.onError,y)}}if(Date.now()>=t)break;await dt(1e3,f,ie.signal)}w||Pt()}async function Et(e,n,t,a){if(u=()=>Et(e,n,t,a),await r.beforeCheckoutReplacement?.(structuredClone(a)),!A())return;let c=i.operation;if(c?.operationId!==e||T(c).type!=="checkout"){u=null,c&&await U(c,!1);return}K={operationId:e,selection:n,coupon:t};let y=!1;try{await r.terminateCheckout(e)}catch(l){if(l instanceof v&&["CAPABILITY_UNAVAILABLE","NOT_CONFIGURED"].includes(l.code)){K=null,p.textContent=o?"请继续原订单,或等待它过期后再更换方案。":"Continue your original checkout, or wait for it to expire before changing plans.",G(r.onError,l);return}y=l instanceof v&&(l.status??0)>=500,G(r.onError,l)}A()&&await kt(y)}function Le(e,n,t,a,c){let y=we(e).checkoutCoupons?.[n],l=y?y.products[t]:r.claimCoupon&&c?St(e.capabilities,c,a):void 0;return l?.couponId&&l.planVersionId===t?{id:l.couponId,offerId:l.offerId}:void 0}function en(e){oe||b||i.quote||i.operation||nt&&p.textContent===nt||(p.textContent=Object.values(e.capabilities.plans).some(n=>n.available)?"":o?"当前账号暂无可购买的方案。":"No plans are currently available for this account.")}let Ne=new Map,_e=!1;function Me(e,n,t,a,c,y){if(S(e)){let $=de(a,c,n.capabilities),ce=$&&Le(n,t,$,c,y),he=e.merchantTerms?.discount??(e.execution.provider==="merchant"?e.execution.discount:void 0),$e=ye(n.document.screen,e.productVersionId,c,n.capabilities);return $===e.productVersionId&&Object.keys($e).length===Object.keys(e.featureQuantities??{}).length&&Object.entries($e).every(([Qe,He])=>e.featureQuantities?.[Qe]===He)&&(!ce||he?.couponId===ce.id&&(!ce.offerId||he.grantId===ce.offerId))}let l=e.lines.length===1?e.lines[0]:void 0,s=de(a,c,n.capabilities);if(!l||!s||l.productVersionId!==s)return!1;let N=Le(n,t,s,c,y);if((N||we(n).checkoutCoupons?.[t])&&(N?.id??null)!==(e.discount?.couponId??null))return!1;let V;try{V=ye(n.document.screen,s,c,n.capabilities)}catch{return!1}let ne=Object.fromEntries((l.prepaid??[]).map($=>[$.internal_feature_id,$.quantity]));return[...new Set([...Object.keys(V),...Object.keys(ne)])].every($=>(V[$]??0)===(ne[$]??0))}let T=e=>Lt({quote:i.quote,operation:e,requestId:null,pending:!1,destroyed:w,canReselect:i.canReselect});async function Ue(e){let n=e.merchantExecution,t=T(e),a=t.type==="checkout"?t.checkoutUrl:e.checkoutUrl;if(!(!A()||!a||Be(e)&&t.type!=="checkout"||r.checkoutNavigation==="after_confirmation"&&t.type!=="checkout"||n?.type==="purchase"&&!["not_started","pending"].includes(n.paymentStatus)||Ne.get(e.operationId)===a)){Ne.set(e.operationId,a);try{r.onCheckoutUrl?await r.onCheckoutUrl(a):f.defaultView?.location.assign(a)}catch(c){throw Ne.delete(e.operationId),c}}}let le=(e,n=!1)=>{if(e instanceof ut)u=null,p.textContent=e.customerMessage(o);else if(Gt(e))u=null,p.textContent=n?o?"当前无法在此购买,付款尚未开始。请联系商户。":"Purchases aren’t available here right now. Payment hasn’t started. Contact the merchant for help.":mt(e,o);else if(n){let t=e instanceof v?e.code:void 0;t==="CAPABILITY_UNAVAILABLE"||t==="NOT_CONFIGURED"?(u=null,p.textContent=o?"暂时无法为此套餐报价,付款尚未开始。":"Pricing for this plan is unavailable. Payment hasn’t started."):i.canReselect===!0&&!b?p.textContent=o?"未能取得报价,付款尚未开始。请重新选择套餐。":"We couldn’t prepare your price. Payment hasn’t started. Choose a plan again.":t==="COMMAND_PENDING"?p.textContent=o?"仍在准备报价,请重试以查看结果。":"Your price is still being prepared. Retry to check the result.":p.textContent=o?"未能取得报价,付款尚未开始。请重试。":"We couldn’t prepare your price. Payment hasn’t started. Try again."}else p.textContent=e instanceof v&&(e.code==="NETWORK_ERROR"||e.code==="TIMEOUT")?mt(e,o):e instanceof v?e.message:o?"操作未完成,请重试。":"This action couldn’t be completed. Try again.";C.hidden=u===null,nt=p.textContent,n&&Ce===void 0&&!O?.responsive&&p.scrollIntoView?.({block:"nearest"}),G(n&&x?.quoteError?x.quoteError:r.onError,e)},Ee=new WeakMap;function xe(e){oe=e,C.disabled=e,B?.updateCapabilities?.(we(m),Je(m));for(let n of te?.querySelectorAll("button")??[])e?(Ee.has(n)||Ee.set(n,n.disabled),n.disabled=!0):Ee.has(n)&&(n.disabled=Ee.get(n),Ee.delete(n)),pt(n)}function it(){p.textContent=o?"暂时无法操作,请稍后重试。":"This action is unavailable right now. Try again in a moment."}async function tn(e){if(r.beforeAction)try{await r.beforeAction()}catch(n){throw n instanceof ut?(b=null,ge=!1,be=!1,u=null):u=e,n}}async function j(e,n){if(oe||w)return;if(!A()){it();return}let t=e===Ie,a=t?Kt:Jt,c=pe()&&n!==void 0;Ce=c?n:void 0,xe(!0),ke(),C.hidden=!0,p.textContent=c?"":a;try{if(e!==At&&(e!==rt||!r.resumeCheckout)&&await tn(e),w)return;if(!A()){u=e,C.hidden=!1,it();return}await e()}catch(y){w||le(y,t)}finally{Ce=void 0,xe(!1),ke(),p.textContent===a&&(p.textContent="")}}async function nn(e){await zt(Z,e,r)}function xt(e){return ct(i).type==="recording"||T(e).type==="recording"}function It(e){let n=e.merchantTerms,t=n?.subscriptionTerms?.items??[],a=n?n.totalMinor:S(e)?e.totalMinor:e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),c=n?t.length===1&&t[0]?.amountMinor===a&&t[0]:!S(e)&&e.lines.length===1&&e.lines[0]?.catalogAmountMinor===a&&e.lines[0],y=a===null?ue(n.subtotalMinor-n.discountMinor,e.currency)+(o?" + 待确认税费":" + tax confirmed at checkout"):ue(a,e.currency)+(c?Pe(c.interval,o?"zh-CN":"en",c.intervalCount??1):""),l=S(e)?i.view?.capabilities.plans[e.productVersionId]?.name??"":e.lines.map(s=>s.productName).join(", ");return{label:l?`${l} · ${y}`:y,recurring:c}}async function U(e,n=r.checkoutNavigation!=="after_confirmation"){if(w)return;if(!A()){u=async()=>U(await i.read()),C.hidden=!1;return}if(p.textContent=Wt(e.status,o),xt(e)){let s=e.merchantExecution?.recordingStatus==="failed";p.textContent=s?o?"付款和商户处理已完成,但交易记录失败。请联系商户修复,勿重复购买。":"Payment and fulfillment succeeded, but recording failed. Contact the merchant to repair this purchase; do not buy again.":o?"付款和商户处理已完成,正在确认交易记录。请勿重复购买。":"Payment and merchant fulfillment are complete. Recording is pending confirmation; do not purchase again.",C.textContent=o?"查询记录":"Check recording",u=async()=>U(await i.read()),C.hidden=!1;return}if(e.problem&&T(e).type!=="native"){let s=e.problem;u=ve,C.textContent=o?"检查并恢复原操作":"Check and recover original purchase",le(new v(s.code,s.reason==="RESULT_UNKNOWN"?o?"付款结果尚未确定,请恢复原操作,暂勿重复购买。":"The payment result is unknown. Recover the original purchase before buying again.":s.phase==="fulfillment"?o?"付款已记录,商户权益处理需要核对。":"Payment was recorded. Access fulfillment needs attention.":s.code==="CAPABILITY_UNAVAILABLE"?o?"商户尚不支持本次购买所需的完整能力,请处理后恢复原操作。":"The merchant does not currently support all actions required by this purchase. Recover the original purchase after this is resolved.":s.code==="NOT_CONFIGURED"?o?"付款服务连接需要处理,请联系商户后恢复原操作。":"The payment connection needs attention. Contact the merchant, then recover the original purchase.":o?"原购买操作需要处理,请查询或恢复此操作。":"The original purchase needs attention. Check or recover this operation.",void 0,void 0,s));return}if((e.merchantExecution?.type==="purchase"&&e.merchantExecution.paymentStatus==="succeeded"||e.merchantExecution?.type==="subscription_change"&&e.merchantExecution.status==="applied")&&!["applied","not_applicable"].includes(e.merchantExecution.fulfillmentStatus)&&(p.textContent=o?"付款已记录,正在等待商户完成处理。":"Payment was recorded. Waiting for merchant fulfillment."),Re(e)&&T(e).type==="complete"){u=null,await nn(e);return}if(!Oe(e)&&T(e).type!=="fulfillment"){if(i.canReselect===!1){p.textContent=o?"正在核对原购买结果":"Checking the original purchase result",C.textContent=o?"查询结果":"Check result",u=async()=>U(await i.read()),C.hidden=!1;return}e.status==="cancelled"?p.textContent=o?"这笔购买已取消,可以重新选择方案。":"This purchase was cancelled. Choose a plan to start again.":e.status==="failed"&&(p.textContent=o?"这笔购买未能完成,可以重新选择方案。":"This purchase didn’t go through. Choose a plan to try again."),C.textContent=o?"重试":"Retry",u=null,b=null;return}if(!n&&T(e).type==="checkout"){if(K){Pt();return}if(pe()){p.textContent="",_e=!1,u=null,ke();return}let s=i.quote,N=s?.operationId===e.operationId?It(s).label:"";p.textContent=_e?N?o?`${N} 尚未付款。再次选择该方案即可继续付款。`:`${N} is still unpaid. Choose it again to continue paying.`:o?"之前的购买尚未付款。再次选择该方案即可继续付款。":"Your earlier purchase is still unpaid. Choose that plan again to continue paying.":"",_e=!1,u=null;return}await Ue(e);let t=Date.now(),a=t+6e5,c=2e3,y=T(e).type!=="checkout",l=()=>y&&Date.now()-t<15e3;Ye=!0,G(r.onObservationChange,!0);try{for(;!w&&Date.now()<a;){if(await dt(l()?700:c,f,ie.signal),w)return;if(!A()){u=async()=>U(await i.read()),C.hidden=!1;return}let s=await i.read();if(T(s).type==="checkout"&&(y=!1),!n&&T(s).type==="checkout"){await U(s,!1);return}if(!s.problem&&Oe(s)&&await Ue(s),!Oe(s)||s.problem||xt(s)){await U(s);return}l()||(c=Math.min(c*1.5,3e4))}}finally{Ye=!1,G(r.onObservationChange,!1)}u=async()=>U(await i.read()),C.hidden=!1}async function at(e=!1){let n=await i.read();if(w)return;if(!A()){u=()=>at(e),C.hidden=!1;return}let t=i.quote;if(t&&Mt(n,{operationId:t.operationId,currency:t.currency},"The original purchase operation changed"),t&&(Be(n)?["prepared","quoted"].includes(n.status):n.status==="pending")&&(Be(n)||n.quoteFinalized===!1)&&!n.confirmedAt&&!n.checkoutUrl&&!("nativePurchase"in n&&n.nativePurchase)&&!n.merchantExecution&&!n.problem&&!i.pendingCancellation){if(r.purchaseConfirmation!=="paywall"){e?await ve():u=null;return}setTimeout(Rt,0,t);return}await U(n,e||void 0)}async function At(){await at()}async function ve(){if(i.quote&&!(Date.parse(i.quote.expiresAt)>Date.now()))throw new v("INVALID_REQUEST",o?"此报价已过期,请重新选择套餐。":"This quote has expired. Choose a plan again.");vt(),u=ve;let e=await i.confirm();if(!A()){u=ve,C.hidden=!1;return}if(e.problem){await U(e);return}if(Oe(e)){if(T(e).type==="checkout")await Ue(e);else if(e.execution&&e.execution.provider!=="merchant"||"nativePurchase"in e&&e.nativePurchase){if(!r.onPurchase)throw new v("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await r.onPurchase({operation:e,signal:ie.signal})}}u=async()=>U(await i.read()),await U(e,!0)}function Rt(e){if(w)return;te?.remove();let n=!(Date.parse(e.expiresAt)>Date.now());p.textContent=n?o?"此报价已过期。请先取消,再重新选择。":"This quote has expired. Cancel it, then choose again.":"";let t=f.createElement("div"),a=f.createElement("button"),c=f.createElement("button"),y=f.createElement("div"),l=f.createElement("p"),s=e.merchantTerms,N=o?"zh-CN":"en",V=s?.subscriptionTerms?.items??[],ne=s?s.subscriptionTerms?.trial?.days:S(e)?void 0:e.lines.find(d=>d.trial)?.trial?.days,re=S(e)?s?s.totalMinor:e.totalMinor:ne===void 0?null:s?s.totalMinor:e.charge?e.charge.totalMinor:e.lines.every(d=>d.trial)?0:null,$=(d,g)=>o?`${g} 天试用结束后 ${d}`:`Then ${d} after the ${g}-day trial`,{label:ce,recurring:he}=It(e),$e=S(e)?i.view?.capabilities.plans[e.productVersionId]?.name??"":e.lines.map(d=>d.productName).join(", "),Qe=re===null?"":`${o?"今天应付":"Due today"} ${ue(re,e.currency)}`;l.textContent=Qe?[$e,Qe].filter(Boolean).join(" · "):ce,a.textContent=S(e)?o?"确认变更":"Confirm change":o?"确认购买":"Confirm purchase",a.disabled=n,c.textContent=o?"取消":"Cancel",t.style.cssText=M.panel,l.style.cssText=M.summary,y.style.cssText=M.actions,a.style.cssText=M.primary,c.style.cssText=M.secondary,pt(a),a.onclick=()=>{j(ve)};let He=async()=>{let d=await i.cancel();w||(t.remove(),te=null,await U(d))};c.onclick=()=>{u=He,j(He)};let H=f.createElement("div");if(H.style.cssText=M.terms,S(e)){for(let[g,P]of Object.entries(e.featureQuantities??{})){let D=i.view?.capabilities.plans[e.productVersionId]?.prepaid?.find(rn=>rn.internalFeatureId===g),je=f.createElement("p");je.textContent=`${D?.name??g} · ${P} ${o?"份":"packs"}${D?` × ${D.terms.units}`:""}`,H.append(je)}for(let[g,P]of[[o?"原订阅抵扣":"Unused subscription credit",e.creditMinor],[o?"新套餐费用":"New plan charge",e.debitMinor],[o?"优惠减免":"Offer savings",s?.discountMinor??e.discountMinor],[o?"税费":"Tax",s?s.taxMinor:e.taxMinor]]){let D=f.createElement("p");D.textContent=`${g}: ${P===null?o?"结账时确认":"Confirmed at checkout":ue(P,e.currency)}`,H.append(D)}let d=f.createElement("p");d.textContent=`${o?"生效时间":"Effective"}: ${e.effectiveAt}`,H.append(d)}if(s){for(let g of V){if(re===null&&g===he)continue;let P=f.createElement("p"),D=ue(g.amountMinor,e.currency)+Pe(g.interval,N,g.intervalCount);P.textContent=re!==null&&ne!==void 0?$(D,ne):D,g.amountAfterOfferMinor!==void 0&&(P.textContent+=` · ${o?"优惠结束后":"After the offer"} ${ue(g.amountAfterOfferMinor,e.currency)}${Pe(g.interval,N,g.intervalCount)}`),H.append(P)}let d=s.subscriptionTerms?.trial;if(d){let g=f.createElement("p");g.textContent=o?`试用 ${d.days} 天;${d.cardRequired?"需要提供付款方式":"无需提供付款方式"}`:`Trial days: ${d.days}; ${d.cardRequired?"a payment method is required":"no payment method is required"}`,H.append(g)}for(let g of[...s.expectedEffects.map(P=>P.description),...s.requiredConsents.map(P=>P.summary)]){let P=f.createElement("p");P.textContent=g,H.append(P)}}else if(!S(e)){for(let d of e.lines){if(re!==null||d!==he){let g=f.createElement("p"),P=`${ue(d.catalogAmountMinor,e.currency)}${Pe(d.interval,N,d.intervalCount??1)}`;g.textContent=re!==null&&d.trial?(e.lines.length>1?`${d.productName} · `:"")+$(P,d.trial.days):`${d.productName} · ${P}`,H.append(g)}for(let g of d.prepaid??[]){let P=f.createElement("p"),D=i.view?.capabilities.plans[d.productVersionId]?.prepaid?.find(je=>je.internalFeatureId===g.internal_feature_id);P.textContent=`${D?.name??g.internal_feature_id} · ${g.quantity} ${o?"份":"packs"} × ${g.terms.units}`,D&&(P.textContent+=Pe(D.reset==="week"||D.reset==="month"||D.reset==="year"?D.reset:"one_time",N,D.resetCount)),H.append(P)}if(d.trial){let g=f.createElement("p");g.textContent=o?`试用 ${d.trial.days} 天;${d.trial.cardRequired?"需要提供付款方式":"无需提供付款方式"}`:`Trial days: ${d.trial.days}; ${d.trial.cardRequired?"a payment method is required":"no payment method is required"}`,H.append(g)}}if(!e.charge){let d=f.createElement("p");d.textContent=o?"目录价格;最终金额以结账时税费和试用规则为准。":"Catalog price; the final charge depends on checkout taxes and trial terms.",H.append(d)}}for(let d of H.children)d.style.margin="0";y.append(a,c),t.append(l,...H.childElementCount?[H]:[],y),J.prepend(t),O?.responsive||t.scrollIntoView?.({block:"nearest"}),a.focus({preventScroll:!0}),te=t,oe&&xe(!0),u=null}async function Ie(){if(!b)return;if(u=Ie,!ge){let t=i.view,a=t?.document.buttons[b.actionId],c=t&&a?.type==="checkout"?de(a.product,b.selection,t.capabilities):null;if(!t||!c)throw new v("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");if(!be){let l=await r.resolveSubscriptionChange?.({actionId:b.actionId,productVersionId:c,featureQuantities:ye(t.document.screen,c,b.selection,t.capabilities)});if(w)return;l!==void 0&&(b.subscriptionChange=Dt.parse(l)),be=!0}let y=F?.offerId;if(F&&!y){if(!r.claimCoupon)throw new v("CAPABILITY_UNAVAILABLE","Coupon claiming is unavailable");let{offer:l}=await r.claimCoupon(F.id,b.requestId);if(w)return;if(!l||l.couponId!==F.id||l.status!=="issued"||!(Date.parse(l.expiresAt)>Date.now()))throw b=null,F=void 0,u=async()=>{Se(await i.refresh()),u=null},new v("COUPON_UNAVAILABLE","This Coupon is no longer available for this purchase");y=l.id}if(!F&&!t.document.screen.actions.some(l=>l.id===b?.actionId&&typeof l.properties.couponBinding=="string")&&(y=await r.resolveOfferId?.({actionId:b.actionId,productVersionId:c,featureQuantities:ye(t.document.screen,c,b.selection,t.capabilities)})),w)return;y!==void 0&&(b.offerId=y),ge=!0}if(!A()){C.hidden=!1;return}let e;try{e=await i.preview(b)}catch(t){throw i.canReselect===!0&&(b=null,ge=!1,be=!1,F=void 0,u=null),t}if(F&&(S(e)?(()=>{let t=e.merchantTerms?.discount??(e.execution.provider==="merchant"?e.execution.discount:void 0);return t?.couponId!==F.id||t.grantId!==b.offerId})():e.discount?.couponId!==F.id||e.discount.offerId!==b.offerId))throw new v("INVALID_RESPONSE","The quote did not apply the Coupon selected on this Paywall");if(w)return;let n=e.merchantTerms;if(r.purchaseConfirmation!=="paywall"||r.confirmOnHostedCheckout&&A()&&!S(e)&&e.provider==="merchant"&&e.billingSubscriptionId===null&&n?.request.action==="purchase"&&n.request.mode==="subscription"&&n.subscriptionTerms?.trial===null&&n.requiredConsents.length===0&&Date.parse(e.expiresAt)>Date.now()){if(!A()){C.hidden=!1;return}if(!(Date.parse(e.expiresAt)>Date.now()))throw new v("INVALID_REQUEST",o?"此报价已过期,请重新选择套餐。":"This quote has expired. Choose a plan again.");let t=Ce?"":o?"正在打开收银台…":"Opening checkout…";p.textContent=t;try{await ve()}catch(a){w||le(a)}finally{p.textContent===t&&(p.textContent="")}return}Rt(e)}function me(e="destroy",n=!1){if(w)return;w=!0;let t=Ze;Ze=void 0,G(t),r.signal?.removeEventListener("abort",X),i.signal?.removeEventListener("abort",X),R.finish("dismissed"),wt?.(),ie.abort(),yt?.disconnect(),B?.destroy(),i.destroy(),E.removeEventListener("cancel",Tt),I.remove(),L.remove(),n||Ot(),e==="dismiss"&&G(r.onDismiss)}function Ot(){O?.destroy(),E.open&&E.close(),E.remove(),k()}Q=me;async function Ve(){if(!fe||w||De||ee==="closing"||!ee&&!A())return;if(!x){me("dismiss");return}let e=f.createElement("p");e.setAttribute("role","status"),e.textContent=o?"正在关闭…":"Closing…",se||(se=f.createElement("div"),se.style.cssText=J.style.cssText,J.replaceWith(se),ae.inert=!0),I.hidden=!1,se.replaceChildren(e,I),ee="closing",I.setAttribute("aria-disabled","true"),I.focus({preventScroll:!0});try{await x.dismiss()}catch(n){w||G(r.onError,n)}w||(ee="retry",e.textContent=o?"未能确认关闭,请重试。":"Could not confirm closure. Try again.",I.textContent=o?"重试关闭":"Retry closing",I.removeAttribute("aria-label"),I.removeAttribute("aria-disabled"))}I.onclick=()=>{Ve()};function Tt(e){e.preventDefault(),Ve()}E.addEventListener("cancel",Tt),C.onclick=()=>{u&&j(u)};function ot(e){R.finish("error",e),me()}function st(){if(!(!bt||fe||w||De||O&&!A()))try{let e=n=>{r.focusAtReveal&&(k=ft(f)),B?.setHidden?.(!1),et?.(),O&&(E.showModal(),O.responsive&&E.focus({preventScroll:!0}),!n&&r.loading!=="host"&&$t(E,O.type,O.responsive)),n&&r.loading!=="host"&&typeof ae.animate=="function"&&!f.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches&&ae.animate([{opacity:.55},{opacity:1}],{duration:160,easing:"ease-out"}),fe=!0};x?x.present(n=>R.present(t=>e(n??t))):R.present(e)}catch(e){ot(e),le(e)}}try{if(Te.type==="inline"?(ze(),et=Bt(L,_),_.append(L)):(E.setAttribute("aria-label",m.document.name),I.textContent="×",I.setAttribute("aria-label",o?"关闭":"Close"),Qt(I,m.document.screen.theme),I.hidden=Ut(m.document),E.append(I,L),_.append(E),O=Vt(E,{...m.document.screen,presentation:Te},Xe),O.latch(),O.responsive&&(L.style.display="flex",L.style.flexDirection="column",L.style.maxHeight="100%",ae.style.overflow="clip",ae.style.minHeight="0"),et=jt(E)),Ge&&W){let t=Ge(W);if(typeof t=="function"&&(w?G(t):Ze=t),w)throw new DOMException("Presentation cancelled","AbortError");ze()}B=Y(ae,{mode:"live",loadingLayout:()=>R.getLoadingLayout?.()??x?.loadingLayout?.(),rendererUrl:"bundled",title:m.document.name,closeActions:Xt,onAuthoredClose(t){ee||w||(I.hidden=t)},hostPresentation:()=>O?.type??Te.type,reportContentHeight:O?.responsive,onResize:t=>{if(!O?.responsive)return;let a=Math.min(t,Ke);ae.style.height=`${a}px`,O.setContentHeight(a+(se??J).getBoundingClientRect().height)},onSelection(t){for(let[a,c]of Object.entries(t))typeof c=="number"&&typeof q[a]=="number"&&q[a]!==c&&Ct.add(a);q=t,ke()},onAction(t,a={},c,y){if(!fe||w||ee)return;let l=i.view,s=l?.document.buttons[t];if(!s)return;if(s.type==="close"&&x&&r.resumeCheckout&&i.operation&&Nt(T(i.operation))){Ve();return}if(oe)return;if(!A()){it();return}if(s.type==="close"){j(async()=>{x?.closeAction?await x.closeAction(t):await r.onAction?.(t),me(r.onAction?"action":"dismiss")});return}if(s.type==="action"){u=async()=>{if(s.action.type==="event"){if(!r.onEvent)throw new v("EVENT_HANDLER_REQUIRED","Provide the event handler");await r.onEvent(s.action.event)}else r.onOpenUrl?await r.onOpenUrl(s.action.url):f.defaultView?.location.assign(s.action.url);await r.onAction?.(t),u=null},j(u);return}if(r.allowNewPurchase===!1){pe()&&l&&i.quote&&i.operation&&T(i.operation).type==="checkout"&&Me(i.quote,l,t,s.product,a,y)?j(rt,t):p.textContent=o?"当前只能继续原订单。":"Only your original checkout is available.";return}if(te&&i.canReselect===!1){p.textContent=o?"请先确认或取消当前购买。":"Confirm or cancel the current purchase first.",O?.responsive||te.scrollIntoView?.({block:"nearest"}),te.querySelector("button")?.focus({preventScroll:!0});return}if(pe()&&K){K.selection.actionId===t&&j(()=>kt(!0),t);return}if(pe()&&r.terminateCheckout&&l&&i.quote&&i.operation&&i.canReselect===!1&&T(i.operation).type==="checkout"){if(Me(i.quote,l,t,s.product,a,y)){j(rt,t);return}let V=de(s.product,a,l.capabilities),ne;try{if(!V)throw new v("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");ne=ye(l.document.screen,V,a,l.capabilities)}catch(he){le(he);return}let re=i.operation.operationId,$={actionId:t,requestId:crypto.randomUUID(),selection:structuredClone(a)},ce=Le(l,t,V,a,y);j(()=>Et(re,$,ce,{actionId:t,productVersionId:V,selection:$.selection,featureQuantities:ne}),t);return}if((i.quote||b)&&i.canReselect===!1){let V=!!l&&!!i.quote&&Me(i.quote,l,t,s.product,a,y);_e=!!i.quote&&!V,u=i.quote?()=>at(V):Ie,j(u);return}let N=l&&de(s.product,a,l.capabilities);if(!l||!N){le(new v("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(r.onPurchaseIntent){u=null,j(async()=>{let V={actionId:t,productVersionId:N,selection:structuredClone(a),featureQuantities:ye(l.document.screen,N,a,l.capabilities)};tt=!0,await r.onPurchaseIntent(V)});return}if(b&&b.actionId!==t){le(new v("COMMAND_PENDING","Finish the current purchase"));return}b||(F=Le(l,t,N,a,y),b={requestId:crypto.randomUUID(),actionId:t,selection:structuredClone(a)},ge=!1,be=!1),j(Ie,t)},onEscape:()=>{Ve()},onError:t=>{let a=new Error(t);!fe&&!w&&ot(a),le(a)},onRendered:t=>{t&&E.setAttribute("aria-label",t),bt=!0,st()}}),B.setHidden?.(!0),Xe();let e=pe()&&!!i.quote&&!!i.operation&&T(i.operation).type==="checkout";q=i.quote?Yt(m,i.quote)??Fe(m,{}):Fe(m,{}),B.update(m.document.screen,We,{capabilities:we(m),unavailableActions:ht(m),serverInput:{bindings:[],answers:{}},...Object.keys(q).length?{selection:q}:{}}),wt=i.subscribe?.(Se),Se(i.view??m),await R.wait(B.ready);let n=i.operation;!e&&(i.quote||n&&(n.confirmedAt||n.checkoutUrl||Re(n)))&&(u=At,j(u))}catch(e){throw ot(e),e}return{check:Z,host:{get observing(){return Ye},get recovery(){return Zt()},async prepareFallback(){if(oe||w||ee||tt)return{type:"recover",operationId:i.operation?.operationId??i.quote?.operationId??null,requestId:null};xe(!0);try{let e=await _t(i);return e.type==="native"&&me(),e}finally{xe(!1)}},setSuspended(e){De=e,L.hidden=e,e&&E.open?E.close():!e&&!fe?st():!e&&!w&&fe&&Te.type!=="inline"&&!E.open&&E.showModal()},destroy:me,retainPurchaseDialog(){if(!(w||!E.open||!E.isConnected))return me("destroy",!0),{dialog:E,release:Ot}},refresh:async()=>{if(!A()){if(i.view)return i.view;throw new v("PRECONDITION_FAILED","Paywall presentation is suspended")}let e=await i.refresh();return Se(e),st(),e}}}}export{Un as showPaywall};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as a}from"./chunk-
|
|
1
|
+
import{b as a}from"./chunk-US65SQX4.js";import"./chunk-HYCLLEFU.js";import"./chunk-KSME3N3A.js";import"./chunk-LE32WTZ7.js";import"./chunk-IDDPWGQE.js";import"./chunk-HYX3EDZS.js";import"./chunk-EGFVGCDG.js";import"./chunk-YFLVGOCJ.js";import"./chunk-VILB5M4X.js";import"./chunk-FN462OVO.js";import"./chunk-FRRKTQNZ.js";import"./chunk-MQ5LJEWV.js";import"./chunk-JDIFYMSA.js";import"./chunk-TNPBYYAX.js";import"./chunk-KCN6OGYG.js";import"./chunk-PF6PRPRO.js";import"./chunk-ZDIWOE4Q.js";import"./chunk-FYD7CMS7.js";import"./chunk-3VUPVXAV.js";import"./chunk-B4SM2KRI.js";import"./chunk-XVCSRZX4.js";import"./chunk-A5KU4MMN.js";import"./chunk-WPFTSHP2.js";import"./chunk-WOT6VMZA.js";export{a as readPaywallContent};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-VPYKAEHU.js";import"./chunk-VKFLQEW4.js";import"./chunk-HP6OV6WF.js";import"./chunk-Y2ASROJH.js";import"./chunk-TIOPNTMP.js";import"./chunk-RFWVXTZ7.js";import"./chunk-US65SQX4.js";import"./chunk-HYCLLEFU.js";import"./chunk-KSME3N3A.js";import"./chunk-LE32WTZ7.js";import"./chunk-IDDPWGQE.js";import"./chunk-LSHIR6QM.js";import"./chunk-OPUIFAQS.js";import"./chunk-HYX3EDZS.js";import"./chunk-EGFVGCDG.js";import"./chunk-YFLVGOCJ.js";import"./chunk-VILB5M4X.js";import"./chunk-IVXYLNAF.js";import"./chunk-FN462OVO.js";import"./chunk-FRRKTQNZ.js";import"./chunk-MQ5LJEWV.js";import"./chunk-JDIFYMSA.js";import"./chunk-TNPBYYAX.js";import"./chunk-KCN6OGYG.js";import"./chunk-PF6PRPRO.js";import"./chunk-ZDIWOE4Q.js";import"./chunk-FYD7CMS7.js";import"./chunk-3VUPVXAV.js";import"./chunk-B4SM2KRI.js";import"./chunk-XVCSRZX4.js";import"./chunk-DSPLGTQI.js";import"./chunk-A5KU4MMN.js";import"./chunk-WPFTSHP2.js";import"./chunk-WOT6VMZA.js";export{a as createPaywallSession};
|
package/dist/popup.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as CustomerPageData, a as SurfaceData, P as PresentationLoadingOptions, L as LoadingLayout, f as ScreenParameters, g as ScreenRendererInput, S as ScreenAnswers, C as CustomerDataIntent } from './presentation-loading-
|
|
2
|
-
export { d as PresentationState } from './presentation-loading-
|
|
1
|
+
import { e as CustomerPageData, a as SurfaceData, P as PresentationLoadingOptions, L as LoadingLayout, f as ScreenParameters, g as ScreenRendererInput, S as ScreenAnswers, C as CustomerDataIntent } from './presentation-loading-BWUNotNa.js';
|
|
2
|
+
export { d as PresentationState } from './presentation-loading-BWUNotNa.js';
|
|
3
3
|
import { b as ScreenAction, c as ScreenNode, d as ScreenInteractivity, e as ScreenDocument } from './screen-CJepeiBT.js';
|
|
4
4
|
import { O as Offer, a as OfferUnavailableReason } from './coupon-kfkIVf9n.js';
|
|
5
5
|
import { WindowLike } from 'dompurify';
|
package/dist/popup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a}from"./chunk-
|
|
1
|
+
import{a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a}from"./chunk-67LPUJMN.js";import"./chunk-2G23BYBI.js";import"./chunk-MQ5LJEWV.js";import"./chunk-JDIFYMSA.js";import"./chunk-TNPBYYAX.js";import"./chunk-KCN6OGYG.js";import"./chunk-PF6PRPRO.js";import"./chunk-ZDIWOE4Q.js";import"./chunk-FYD7CMS7.js";import"./chunk-XVCSRZX4.js";import"./chunk-DSPLGTQI.js";import"./chunk-A5KU4MMN.js";import"./chunk-WPFTSHP2.js";import"./chunk-WOT6VMZA.js";export{p as formatCustomerDecimal,r as hostedRendererScript,o as hostedRendererShell,f as inspectCustomHtml,a as mountScreenPreview,x as preparePopup,m as prepareScreen,e as sanitizeCustomHtml,t as showPopup};
|
|
@@ -1017,6 +1017,11 @@ type LoadingLayout = {
|
|
|
1017
1017
|
}[];
|
|
1018
1018
|
};
|
|
1019
1019
|
|
|
1020
|
+
type RetainedPurchaseDialog = {
|
|
1021
|
+
dialog: HTMLDialogElement;
|
|
1022
|
+
release(): void;
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1020
1025
|
/** The display portion of an already available published Paywall document. */
|
|
1021
1026
|
type PaywallLoadingDocument = {
|
|
1022
1027
|
presentation: ScreenDocument["presentation"];
|
|
@@ -1055,6 +1060,7 @@ declare function createPresentationLoading(container: HTMLElement | ShadowRoot,
|
|
|
1055
1060
|
readonly active: boolean;
|
|
1056
1061
|
readonly cancelled: boolean;
|
|
1057
1062
|
getLoadingLayout(): LoadingLayout | undefined;
|
|
1063
|
+
retainPurchaseDialog(): RetainedPurchaseDialog | undefined;
|
|
1058
1064
|
/** Null selects the Paywall loading status when its layout is unavailable. */
|
|
1059
1065
|
start(modal: boolean, locale?: string, paywall?: PaywallLoadingDocument | null): void;
|
|
1060
1066
|
/** Remove the placeholder and reveal in the same turn, before notifying the host. */
|
|
@@ -1069,6 +1075,7 @@ declare function createPresentationLoading(container: HTMLElement | ShadowRoot,
|
|
|
1069
1075
|
readonly active: boolean;
|
|
1070
1076
|
readonly cancelled: boolean;
|
|
1071
1077
|
getLoadingLayout(): LoadingLayout | undefined;
|
|
1078
|
+
retainPurchaseDialog(): RetainedPurchaseDialog | undefined;
|
|
1072
1079
|
/** Null selects the Paywall loading status when its layout is unavailable. */
|
|
1073
1080
|
start(modal: boolean, locale?: string, paywall?: PaywallLoadingDocument | null): void;
|
|
1074
1081
|
/** Remove the placeholder and reveal in the same turn, before notifying the host. */
|
|
@@ -1080,4 +1087,4 @@ declare function createPresentationLoading(container: HTMLElement | ShadowRoot,
|
|
|
1080
1087
|
wait<T>(work: Promise<T>, timeoutMs?: number): Promise<T>;
|
|
1081
1088
|
}, "getLoadingLayout">>;
|
|
1082
1089
|
|
|
1083
|
-
export { type CustomerDataIntent as C, type LoadingLayout as L, type PresentationLoadingOptions as P, type ScreenAnswers as S, type SurfaceData as a, type PaywallLoadingDocument as b, createPresentationLoading as c, type PresentationState as d, type CustomerPageData as e, type ScreenParameters as f, type ScreenRendererInput as g, screenInputBindingsSchema as s };
|
|
1090
|
+
export { type CustomerDataIntent as C, type LoadingLayout as L, type PresentationLoadingOptions as P, type RetainedPurchaseDialog as R, type ScreenAnswers as S, type SurfaceData as a, type PaywallLoadingDocument as b, createPresentationLoading as c, type PresentationState as d, type CustomerPageData as e, type ScreenParameters as f, type ScreenRendererInput as g, screenInputBindingsSchema as s };
|
package/dist/react-native.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as S,c as E,d as T}from"./chunk-
|
|
1
|
+
import{b as S,c as E,d as T}from"./chunk-4NO6U4X6.js";import"./chunk-3ITNAFAH.js";import{a as A}from"./chunk-VPYKAEHU.js";import{e as P}from"./chunk-VKFLQEW4.js";import"./chunk-HP6OV6WF.js";import{h as b,i as x,k as L}from"./chunk-DB5S72HJ.js";import{E as C}from"./chunk-3TSFGU4T.js";import"./chunk-W3B4GT74.js";import"./chunk-Y2ASROJH.js";import"./chunk-TIOPNTMP.js";import"./chunk-RFWVXTZ7.js";import"./chunk-US65SQX4.js";import"./chunk-HYCLLEFU.js";import"./chunk-KSME3N3A.js";import"./chunk-LE32WTZ7.js";import"./chunk-SZZIYCXK.js";import"./chunk-IDDPWGQE.js";import"./chunk-LSHIR6QM.js";import"./chunk-OPUIFAQS.js";import"./chunk-HYX3EDZS.js";import"./chunk-EGFVGCDG.js";import"./chunk-YFLVGOCJ.js";import"./chunk-VILB5M4X.js";import"./chunk-IVXYLNAF.js";import"./chunk-FN462OVO.js";import"./chunk-FRRKTQNZ.js";import"./chunk-MQ5LJEWV.js";import"./chunk-JDIFYMSA.js";import"./chunk-TNPBYYAX.js";import"./chunk-KCN6OGYG.js";import"./chunk-PF6PRPRO.js";import{a as r}from"./chunk-ZDIWOE4Q.js";import{h as R}from"./chunk-FYD7CMS7.js";import"./chunk-3VUPVXAV.js";import"./chunk-B4SM2KRI.js";import"./chunk-XVCSRZX4.js";import"./chunk-DSPLGTQI.js";import"./chunk-A5KU4MMN.js";import"./chunk-WPFTSHP2.js";import"./chunk-WOT6VMZA.js";function k(t,d){let n,a=0,m=-1,l,i=!1,y=()=>{if(i)throw new r("CLOSED","Native host was destroyed");if(!t.nativeModule)throw new r("CAPABILITY_UNAVAILABLE","Link IndianaBridge and supply nativeModule");return t.nativeModule},o=()=>new r("IDENTITY_CHANGED","Customer identity changed during the native operation"),h=d.subscribeIdentity(()=>{a++,m=-1;let e=a;n&&t.nativeModule&&n.then(c=>t.nativeModule.reset(c,e)).catch(()=>{})}),I=t.nativeEvents?.(e=>{!n||!t.nativeModule||typeof e?.requestId!="string"||(async()=>{let c=await n;if(e.instanceId!==c)return;if(e.kind==="credential"){let w=a,f=null;try{if(!i&&e.revision===w){let N=await d.access();!i&&a===w&&(f=N)}}finally{await t.nativeModule.provideCredential(c,e.requestId,f)}return}let s=!1,u=a;try{if(i||e.revision!==u||!t.onNativeAction)throw o();await t.onNativeAction(e.action),s=!i&&a===u}finally{await t.nativeModule.acknowledge(c,e.requestId,s)}})().catch(()=>{})});async function p(e,c={}){let s=y();if(d.snapshot()&&!t.nativeEvents)throw new r("CAPABILITY_UNAVAILABLE","Supply nativeEvents to share credential refresh with the native host");let u=a,w=await d.access();if(i||a!==u)throw o();if(!n){let v=s.create(JSON.stringify({baseUrl:t.baseUrl??"https://api.longplayai.com",scope:t.scope,timeout:(t.timeoutMs??15e3)/1e3,credentialEvents:!!t.nativeEvents}));n=v,v.catch(()=>{n===v&&(n=void 0)})}let f=await n;if(i||a!==u)throw o();if(m!==u){if(!l||l.epoch!==u){let O=(async()=>{if(await s.identify(f,JSON.stringify({revision:u,credentials:w})),i||a!==u)throw await s.reset(f,u),o();m=u})();l={epoch:u,task:O}}let v=l;try{await v.task}finally{l===v&&(l=void 0)}}let N=await s.invoke(f,e,JSON.stringify(c));if(i||a!==u)throw o();try{return JSON.parse(N)}catch{throw new r("INVALID_RESPONSE","Native host returned invalid JSON")}}async function g(e,c){let s=await p(e,c);if(!s||typeof s!="object"||Array.isArray(s)||s.status!=="complete"&&s.status!=="dismissed")throw new r("INVALID_RESPONSE","Native presentation returned an invalid result");return s}return{showFunnel(e){return g("showFunnel",{runToken:e})},showPaywall(e){return g("showPaywall",e)},showContent(e){return g("showContent",e)},purchaseSubscription(e,c){return p("purchaseSubscription",{operationId:e,accepted:c})},switchSubscription(e,c){return p("switchSubscription",{operationId:e,accepted:c})},restorePurchases(){return p("restorePurchases")},manageSubscriptions(e){return p("manageSubscriptions",e?{productId:e}:{})},async dismiss(){a++,m=-1,n&&await y().reset(await n,a)},async destroy(){i||(i=!0,a++,h(),I?.(),n&&t.nativeModule&&await t.nativeModule.destroy(await n))}}}var M=P.trackUsage.request.shape.command,U=P.trackUsage.response;function F(t){let d=R.parse(t.scope),n=S({...t,scope:d}),a={...t,scope:d,session:n.session},m=k(t,n.session),l=0,i=!1;n.subscribeIdentity(()=>{l++});let y=()=>{if(i)throw new r("CLOSED","SDK client was destroyed");let o=n.session.peek();if(!o)throw new r("UNAUTHENTICATED","Identify the Customer first");return o};return{...n,native:m,async destroy(){i||(i=!0,l++,n.destroy(),await m.destroy())},funnel(){return E({...a,customerToken:y()})},resumeFunnel(o){return y(),C({...a,runToken:o})},paywall(o){return A(a,{...o,customerToken:y()})},async trackUsage(o){if(y(),!t.usageReporter)throw new r("INVALID_REQUEST","Configure your authenticated backend usageReporter");let h=M.parse(o),I=l,p;try{p=await t.usageReporter(h)}catch(e){throw I!==l?new r("IDENTITY_CHANGED","Customer identity changed during usage reporting"):e}if(I!==l)throw new r("IDENTITY_CHANGED","Customer identity changed during usage reporting");let g=U.parse(p);if(g.scope.projectId!==d.projectId||g.scope.environment!==d.environment)throw new r("INVALID_RESPONSE","Usage response scope differs");return g}}}export{r as LongplayError,x as createConfigurationSync,b as createFeatureClient,T as createFunnelProcess,L as createLocalFunnelClient,F as createLongplayReactNative};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i}from"./chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i}from"./chunk-67LPUJMN.js";import"./chunk-2G23BYBI.js";import"./chunk-MQ5LJEWV.js";import"./chunk-JDIFYMSA.js";import"./chunk-TNPBYYAX.js";import"./chunk-KCN6OGYG.js";import"./chunk-PF6PRPRO.js";import"./chunk-ZDIWOE4Q.js";import"./chunk-FYD7CMS7.js";import"./chunk-XVCSRZX4.js";import"./chunk-DSPLGTQI.js";import"./chunk-A5KU4MMN.js";import"./chunk-WPFTSHP2.js";import"./chunk-WOT6VMZA.js";export{f as formatCustomerDecimal,b as hostedRendererScript,a as hostedRendererShell,d as inspectCustomHtml,i as mountScreenPreview,h as preparePopup,e as prepareScreen,c as sanitizeCustomHtml,g as showPopup};
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as pn}from"./chunk-
|
|
1
|
+
import{a as pn}from"./chunk-TM72XBM5.js";import{a as I}from"./chunk-2I2S5ZIH.js";import{a as fn,b as hn,c as gn,d as yn}from"./chunk-PJAZ2UP4.js";import{a as xt}from"./chunk-VPYKAEHU.js";import{a as Ue,b as Ve,c as qe,d as He,e as m}from"./chunk-VKFLQEW4.js";import"./chunk-HP6OV6WF.js";import{a as Te,b as ae,c as yt,d as It,e as wt,f as xe,g as vt,h as Me,i as dn,j as ln,k as mn}from"./chunk-DB5S72HJ.js";import{B as V,C as N,d as ft,e as ht,k as gt,l as z,m as St,p as Ct,q as Rt,r as bt,s as At,t as Ot,y as pe,z as Tt}from"./chunk-3TSFGU4T.js";import"./chunk-W3B4GT74.js";import{c as h}from"./chunk-Y2ASROJH.js";import"./chunk-TIOPNTMP.js";import{a as Et,b as _e}from"./chunk-RFWVXTZ7.js";import"./chunk-US65SQX4.js";import"./chunk-HYCLLEFU.js";import{e as at}from"./chunk-KSME3N3A.js";import{B as pt,C as de,D as Z,E as lt,J as mt,a as et,e as q,j as Re,k as st,l as ct,q as ut,r as dt,s as be,t as Ae}from"./chunk-LE32WTZ7.js";import{b as Oe}from"./chunk-SZZIYCXK.js";import{e as ve,i as Ze,l as it}from"./chunk-IDDPWGQE.js";import"./chunk-LSHIR6QM.js";import"./chunk-OPUIFAQS.js";import"./chunk-HYX3EDZS.js";import"./chunk-EGFVGCDG.js";import{A as W,B as oe,C as tt,D as Se,E as ie,G as se,H as Ce,M as j,O as ce,P as nt,R as Ee,S as rt,T as ot,f as Ge,g as je,j as we,r as ze,s as Ke,u as an,v as sn,y as cn,z as X}from"./chunk-YFLVGOCJ.js";import"./chunk-VILB5M4X.js";import"./chunk-IVXYLNAF.js";import"./chunk-FN462OVO.js";import{a as Ne,b as Le}from"./chunk-FRRKTQNZ.js";import{o as ue}from"./chunk-MQ5LJEWV.js";import"./chunk-JDIFYMSA.js";import{i as un,k as $e,l as Qe,m as Je}from"./chunk-TNPBYYAX.js";import{c as Ie}from"./chunk-KCN6OGYG.js";import{e as Xe,h as We}from"./chunk-PF6PRPRO.js";import{a as c}from"./chunk-ZDIWOE4Q.js";import{h as Y}from"./chunk-FYD7CMS7.js";import"./chunk-3VUPVXAV.js";import"./chunk-B4SM2KRI.js";import{b as u}from"./chunk-XVCSRZX4.js";import"./chunk-DSPLGTQI.js";import{a as Ye}from"./chunk-A5KU4MMN.js";import"./chunk-WPFTSHP2.js";import"./chunk-WOT6VMZA.js";var _t=4,Mt=[...tt,"requirement_checks","native_offers","preparations","benefit_claims","authorizations","business_results","checkout_termination"],In=u.enum(Mt),ee=(e,n)=>u.array(e).max(n).refine(t=>new Set(t).size===t.length,"Declarations must be unique"),ke=u.strictObject({...se.shape,bridgeVersion:u.literal(_t),capabilities:ee(In,Mt.length),checkKinds:ee(u.enum(["access","metered","credit"]),3),preparationActions:ee(u.enum(["purchase","subscription_change","refund"]),3),authorizationKinds:ee(u.enum(["auto_topup"]),1),nextActionTypes:ee(u.enum(["redirect","authenticate"]),2),resultEvents:ee(u.enum(["benefit.claimed","authorization.updated"]),2)}).superRefine((e,n)=>{e.capabilities.includes("catalog")!==(e.catalog!=="none")&&n.addIssue({code:"custom",path:["catalog"],message:"Catalog declaration differs from its capability"}),(e.capabilities.includes("billing_records")!==e.billingEvents.length>0||new Set(e.billingEvents).size!==e.billingEvents.length)&&n.addIssue({code:"custom",path:["billingEvents"],message:"Declare unique supported billing events"});let t=r=>e.capabilities.includes(r),o=(r,a)=>n.addIssue({code:"custom",path:[r],message:a});t("requirement_checks")!==e.checkKinds.length>0&&o("checkKinds","Declare the supported Check kinds"),t("preparations")!==e.preparationActions.length>0&&o("preparationActions","Declare the supported preparation actions"),t("authorizations")!==e.authorizationKinds.length>0&&o("authorizationKinds","Declare the supported authorization kinds"),t("business_results")!==e.resultEvents.length>0&&o("resultEvents","Declare the supported non-financial results");for(let[r,a,s]of[["purchases","purchase","purchase.completed"],["subscription_changes","subscription_change","subscription.change.completed"],["refunds","refund","refund.updated"]])t(r)&&(!t("operation_status")||!t("billing_records")||!t("preparations")||!e.preparationActions.includes(a)||!e.billingEvents.includes(s))&&o("capabilities",`${r} requires preparation, original lookup and its billing result`);t("purchases")&&!e.billingEvents.includes("purchase.closed")&&o("billingEvents","Purchase execution requires its terminal closure result"),t("checkout_termination")&&(!t("operation_status")||!t("billing_records")||!e.billingEvents.includes("purchase.closed"))&&o("capabilities","Checkout termination requires original lookup and purchase.closed"),t("subscription_changes")&&!e.billingEvents.includes("subscription.change.closed")&&o("billingEvents","Subscription change execution requires its terminal closure result");for(let[r,a]of[["benefit_claims","benefit.claimed"],["authorizations","authorization.updated"]])t(r)&&(!t("operation_status")||!t("business_results")||!e.resultEvents.includes(a))&&o("capabilities",`${r} requires original lookup and its non-financial result`)}),K={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":u.strictObject({}),"requirement.check":$e,"operation.prepare":ze,"benefit.claim":Ue,"operation.read":qe,"purchase.terminate":j},wn={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":ke,"requirement.check":Qe,"operation.prepare":Ke,"benefit.claim":Ve,"operation.read":He,"purchase.terminate":j.extend({outcome:u.enum(["requested","already_paid"])})},Gn=u.enum(["bridge.ping","bridge.describe","requirement.check","operation.prepare","benefit.claim","operation.read","purchase.terminate"]);function $(e,n){return u.strictObject({bridgeVersion:u.literal(_t),requestId:u.uuid(),scope:Ce,command:u.literal(e),data:n})}var kt=u.discriminatedUnion("command",[$("bridge.ping",K["bridge.ping"]),$("bridge.describe",K["bridge.describe"]),$("requirement.check",K["requirement.check"]),$("operation.prepare",K["operation.prepare"]),$("benefit.claim",K["benefit.claim"]),$("operation.read",K["operation.read"]),$("purchase.terminate",K["purchase.terminate"])]),Be=u.strictObject({code:u.string().regex(/^MERCHANT_BRIDGE_[A-Z_]+$/),message:u.string().min(1).max(500),retryable:u.boolean(),recovery:u.string().min(1).max(80),effect:u.enum(["none","unknown"])}).refine(e=>e.effect!=="unknown"||!e.retryable&&e.recovery==="recover_operation","Unknown effects require original-operation recovery");function Bt(e){let n={bridgeVersion:u.literal(4),requestId:u.uuid(),scope:Ce,command:u.literal(e)};return u.union([u.strictObject({...n,data:wn[e]}),u.strictObject({...n,error:Be})])}var Pt="X-Indiana-Bridge-Signature",Q="X-Indiana-Bridge-Key-Id";function vn(e){return new TextEncoder().encode(e)}function Dt(e){return Uint8Array.from(atob(e.replaceAll("-","+").replaceAll("_","/")),n=>n.charCodeAt(0))}function Ft(e,n,t,o){return vn(`indiana-merchant-bridge:${o}
|
|
2
2
|
${n}
|
|
3
3
|
POST
|
|
4
4
|
${W}
|
package/dist/visual.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as pe,c as fe}from"./chunk-RA7GZ67U.js";import{b as le}from"./chunk-J6KIN4RH.js";import{a as Ve,b as ce,c as de,d as ue}from"./chunk-SLUA7ABW.js";import{a as J,b as F,c as ge,e as me}from"./chunk-
|
|
1
|
+
import{a as pe,c as fe}from"./chunk-RA7GZ67U.js";import{b as le}from"./chunk-J6KIN4RH.js";import{a as Ve,b as ce,c as de,d as ue}from"./chunk-SLUA7ABW.js";import{a as J,b as F,c as ge,e as me}from"./chunk-3Z3HL42M.js";import{a as re,b as ae,c as se,d as oe}from"./chunk-GJSQZGBE.js";import"./chunk-3VUPVXAV.js";import"./chunk-B4SM2KRI.js";import{b as o}from"./chunk-XVCSRZX4.js";import"./chunk-DSPLGTQI.js";import{c as te,e as ie,g as M}from"./chunk-A5KU4MMN.js";import"./chunk-WPFTSHP2.js";import"./chunk-WOT6VMZA.js";var K="indiana-visual-diagnostics-v1",Ae=o.strictObject({environmentId:o.string().uuid(),release:o.string().regex(/^[a-f0-9]{64}$/).nullable(),generation:o.string().regex(/^[a-f0-9]{64}$/).nullable(),publishedGeneration:o.string().regex(/^[a-f0-9]{64}$/).nullable(),checkedAt:o.string().datetime(),origin:o.string().url(),pathname:o.string().max(2048),urlMatches:o.boolean(),stopped:o.boolean(),rows:o.array(o.strictObject({changeId:o.string().regex(/^[a-f0-9]{64}$/),experimentKey:o.string().max(256),variationKey:o.string().max(256),inExperiment:o.boolean(),fingerprint:o.string().regex(/^[a-f0-9]{64}$/),status:o.enum(["inactive","waiting","partial","applied","mismatch","no_changes","unavailable","error"]),total:o.number().int().min(0).max(600),applied:o.number().int().min(0).max(600)})).max(100)});function ye(e){let l=n=>Array.isArray(n)?"["+n.map(l).join(",")+"]":n&&typeof n=="object"?"{"+Object.entries(n).filter(([,c])=>c!==void 0).sort(([c],[y])=>c.localeCompare(y)).map(([c,y])=>JSON.stringify(c)+":"+l(y)).join(",")+"}":JSON.stringify(n);return l({css:e.css,js:e.js,domMutations:e.domMutations,...e.renderGuard?{renderGuard:e.renderGuard}:{}})}function he(e){let l=new URL(e.baseUrl),n=l.origin==="https://api.longplayai.com"||l.origin==="https://api.dev.longplayai.com"?l.hostname.slice(4):void 0,c=e.origins??(n?[`https://console.${n}`]:[]),y=new Set(c.filter(t=>{try{let i=new URL(t);return i.origin===t&&(i.protocol==="https:"||i.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(i.hostname))}catch{return!1}})),v=!1,I=!1,k=0,T=async t=>{if(v||I||!t.source||!y.has(t.origin)||!t.data||typeof t.data!="object")return;let i=t.data;if(!(i.channel!==K||i.type!=="inspect"||i.environmentId!==e.environmentId||typeof i.nonce!="string"||!/^[a-f0-9-]{36}$/i.test(i.nonce)||typeof i.changeId!="string"||!/^[a-f0-9]{64}$/.test(i.changeId)||typeof i.url!="string"||i.url.length>2048||Date.now()-k<250)){try{if(new URL(i.url).origin!==location.origin)return}catch{return}I=!0,k=Date.now();try{let x=await e.inspect(i.changeId,i.url);!v&&x.rows.some(S=>S.changeId===i.changeId)&&t.source.postMessage({channel:K,type:"result",nonce:i.nonce,snapshot:x},t.origin)}finally{I=!1}}},u=t=>{T(t).catch(()=>{})};return window.addEventListener("message",u),()=>{v=!0,window.removeEventListener("message",u)}}var R=e=>!!e&&typeof e=="object"&&!Array.isArray(e),E=(e,l)=>typeof e=="string"&&e.length<=l,Ee=e=>typeof e=="string"&&(["html","class","style","position","href","src","alt","title","id","role","hidden"].includes(e)||/^(aria|data)-[a-z0-9_-]+$/.test(e));function ke(e){if(!R(e)||!E(e.css??"",1e5)||!E(e.js??"",1e5)||!Array.isArray(e.domMutations??[])||Array.isArray(e.domMutations)&&e.domMutations.length>200)throw new Error("Invalid visual variation");let l=e.domMutations??[];for(let n of l)if(!R(n)||!E(n.selector,2048)||!n.selector||!Ee(n.attribute)||!["set","append","remove"].includes(String(n.action))||n.value!==void 0&&!E(n.value,5e4)||n.parentSelector!==void 0&&!E(n.parentSelector,2048)||n.insertBeforeSelector!==void 0&&!E(n.insertBeforeSelector,2048))throw new Error("Invalid visual mutation");return{css:e.css??"",js:e.js??"",domMutations:l,...e.renderGuard===void 0?{}:{renderGuard:le(e.renderGuard)}}}function q(e){if(!R(e)||typeof e.environmentId!="string"||typeof e.trackExposures!="boolean"||!/^[-a-f0-9]{36}$/i.test(e.environmentId)||typeof e.generation!="string"||!/^[a-f0-9]{64}$/.test(e.generation)||!Array.isArray(e.experiments)||e.experiments.length>100||!R(e.savedGroups))throw new Error("Invalid visual experiment payload");let l=e.experiments.map(n=>{if(!R(n)||!["key","changeId"].every(c=>typeof n[c]=="string"&&n[c])||!/^[a-f0-9]{64}$/.test(String(n.changeId))||["namespace","status","groups","url"].some(c=>Object.hasOwn(n,c))||n.hashVersion!==void 0&&n.hashVersion!==2||!Array.isArray(n.variations)||n.variations.length<2||n.variations.length>20||n.urlPatterns!==void 0&&!Array.isArray(n.urlPatterns))throw new Error("Invalid visual experiment");return{...n,variations:n.variations.map(ke)}});return{...e,experiments:l}}var ve=6e4;function qe(e){let l=se(e.baseUrl);if(e.appManifestRelease!==void 0&&!/^[a-f0-9]{64}$/.test(e.appManifestRelease))throw new Error("Invalid IAM manifest digest");if(!/^[0-9a-f-]{36}$/i.test(e.environmentId))throw new Error("Invalid App environment ID");let n=e.fetch??globalThis.fetch.bind(globalThis),c=F(n),y=F(n),v=`${l}/api/v1/visual-experiments/${e.environmentId}`,I=e.appManifestRelease?`${v}?iam=${e.appManifestRelease}`:v,k=re(e.deviceIdCookie??"indiana_did"),T=ae(),u=null,t=!1,i=!1,x="",S={...e.attributes??{}},G,B,D=0,H=-1/0,$,m=new Map,O=new Map,C=new Set,z=ge({endpoint:`${v}/events`,fetch:n,log:e.log,label:"Visual exposure"}),P=z.flush,W,b;function j(){clearTimeout(W),b?.remove(),b=void 0}function Y(s,d){let f=M(s,d);C.has(f)||e.trackExposures===!1||u?.trackExposures===!1||t||(C.add(f),z.push({eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString(),deviceId:k,...T?{sessionId:T}:{},url:location.href,pageTitle:document.title.slice(0,512),experimentKey:s.key,variationKey:d.key}))}function we(s){if(!u||t)return;let d=new Set,f={onExperimentViewed:(r,p)=>{d.add(M(r,p))},url:location.href,attributes:{...me(k,location),...S,indianaAppManifestRelease:e.appManifestRelease??null},savedGroups:te(u.savedGroups),log:e.log},h=new Set;for(let r of u.experiments){if(de(`${e.environmentId}:${r.key}`))continue;let p=r;try{let a=ie(p,f);if(O.set(r.changeId,a),!a.inExperiment)continue;h.add(r.changeId);let w=JSON.stringify([a.key,a.value]),U=m.get(r.changeId);if(U?.signature===w){d.has(M(p,a))&&s.push(()=>{U.applied()&&Y(p,a)});continue}m.get(r.changeId)?.revert(),m.delete(r.changeId);let A=fe(a.value,{requireUniqueTargets:!!e.appManifestRelease&&Array.isArray(r.condition?.$and)&&r.condition.$and.some(g=>g!==null&&typeof g=="object"&&!Array.isArray(g)&&g.indianaAppManifestRelease===e.appManifestRelease),boundVariations:r.variations,allowJs:e.disableJsInjection===!1,nonce:e.nonce,onApplied:()=>{d.has(M(p,a))&&Y(p,a)},onError:g=>e.log?.("Visual experiment stopped",{experiment:r.key,changeId:r.changeId,variation:a.key,error:String(g)}),onTargetStatus:e.log?g=>e.log?.("Visual target status changed",{experiment:r.key,changeId:r.changeId,variation:a.key,...g}):void 0});m.set(r.changeId,{signature:w,revert:A.revert,applied:()=>A.applied,inspect:()=>A.inspect()})}catch(a){e.log?.("Skipping visual experiment",{experiment:r.key,error:String(a)})}}for(let[r,p]of m)h.has(r)||(p.revert(),m.delete(r));j()}let V=()=>{let s=[];pe(()=>we(s));for(let d of s)d()};async function _(){let s=++D,d;try{d=await c.read(I,J)}catch(h){if(t||s!==D)return!1;throw h}let f=q(d);if(f.environmentId.toLowerCase()!==e.environmentId.toLowerCase())throw new Error("Visual payload scope changed");return t||s!==D?!1:(u=f,H=performance.now(),!0)}async function Q(){!await _()||t||(N(),V())}function L(){clearTimeout($),$=setTimeout(()=>{if(document.visibilityState==="hidden")return L();Q().catch(s=>e.log?.("Visual payload refresh failed",{error:String(s)})).finally(()=>{t||L()})},ve)}let X=()=>{t||document.visibilityState==="hidden"||performance.now()-H<ve||(clearTimeout($),Q().catch(s=>e.log?.("Visual payload refresh failed",{error:String(s)})).finally(()=>{t||L()}))},Ie=()=>{x!==location.href&&(x=location.href,V())},Z=()=>{P(!0)},N=()=>{G||t||(G=oe(Ie),addEventListener("pagehide",Z),x=location.href)};async function ee(s,d){let f=location.href,h=u,r=[],p=null;if(!t)try{let a=q(await y.read(I,J));a.environmentId===e.environmentId&&(p=a.generation)}catch{}for(let a of h?.experiments??[]){if(s&&a.changeId!==s)continue;let w=O.get(a.changeId);if(!w)continue;let U=new TextEncoder().encode(ye(w.value)),A=[...new Uint8Array(await crypto.subtle.digest("SHA-256",U))].map(be=>be.toString(16).padStart(2,"0")).join(""),g=m.get(a.changeId)?.inspect()??{status:"inactive",total:0,applied:0};r.push({changeId:a.changeId,experimentKey:a.key,variationKey:w.key,inExperiment:w.inExperiment,fingerprint:A,...g})}return{environmentId:e.environmentId,release:e.appManifestRelease??null,generation:h?.generation??null,publishedGeneration:p,checkedAt:new Date().toISOString(),origin:location.origin,pathname:location.pathname,urlMatches:location.href===f&&(!d||d===f)&&h===u,stopped:t,rows:r}}let ne,xe=ue(()=>{i&&!t&&V()});return{async start(){if(!(i||t)){i=!0,e.appManifestRelease&&(B=ce(e.appManifestRelease)),e.antiFlicker&&(b=document.createElement("style"),e.nonce&&(b.nonce=e.nonce),b.textContent="body { visibility: hidden !important }",document.head.append(b),W=setTimeout(j,Math.min(3e3,Math.max(0,e.antiFlickerTimeout??1e3))));try{if(!await _()||t)return;N(),V()}finally{j(),t||(L(),document.addEventListener("visibilitychange",X),ne=he({environmentId:e.environmentId,baseUrl:l,origins:e.diagnosticsOrigins,inspect:ee}))}}},async refresh(){t||await _()&&(i&&N(),V())},setAttributes(s){S={...s},V()},flush:()=>P(),getDiagnostics:ee,getResults(){return new Map(O)},get generation(){return u?.generation??null},destroy(){t=!0,clearTimeout($),document.removeEventListener("visibilitychange",X),xe(),ne?.(),D++,c.destroy(),y.destroy(),G?.(),B?.destroy(),removeEventListener("pagehide",Z),j();for(let s of m.values())s.revert();m.clear(),P(!0),u=null,O.clear(),C.clear(),S={}}}}export{qe as createVisualExperiments,Ve as loadAppManifestRelease};
|
package/package.json
CHANGED
package/dist/chunk-A4TLE4OF.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as I}from"./chunk-PF6PRPRO.js";import{a as H}from"./chunk-DSPLGTQI.js";var _={sm:420,md:640,lg:900},z=767;function ye(e,n,r=()=>!0,c="Close"){let t=e.ownerDocument.defaultView,o=e.ownerDocument.createElement("button");o.type="button",o.setAttribute("aria-label",c),o.style.cssText="position:absolute;inset:0 48px auto;z-index:2;height:24px;border:0;padding:0;background:transparent;touch-action:none;cursor:grab";let d=e.ownerDocument.createElement("span");d.style.cssText="display:block;width:36px;height:4px;border-radius:4px;margin:8px auto 12px;background:currentColor;opacity:.22;pointer-events:none",o.append(d),e.prepend(o);let p,s=0,a=!1,m=()=>{o.hidden=e.dataset.presentation!=="sheet",o.setAttribute("aria-disabled",String(!r()))},g=i=>{m(),!(o.hidden||!r()||i.button!==0)&&(p={y:i.clientY,time:Date.now(),id:i.pointerId},s=0,a=!1,o.setPointerCapture?.(i.pointerId))},h=i=>{!p||i.pointerId!==p.id||(s=Math.max(0,i.clientY-p.y),e.style.transform=`translateY(${s}px)`)},w=i=>{if(!p||i.pointerId!==p.id)return;let l=Math.max(1,Date.now()-p.time),u=i.type!=="pointercancel"&&r()&&(s>120||s>40&&s/l>.5);a=s>6,p=void 0,o.releasePointerCapture?.(i.pointerId),e.style.transform="",u?n():s&&typeof e.animate=="function"&&!t?.matchMedia?.("(prefers-reduced-motion: reduce)").matches&&e.animate([{transform:`translateY(${s}px)`},{transform:"none"}],{duration:200,easing:"cubic-bezier(.2,.8,.2,1)"}),s=0},f=()=>{if(a){a=!1;return}!p&&s===0&&r()&&n()};o.addEventListener("pointerdown",g),o.addEventListener("pointermove",h),o.addEventListener("pointerup",w),o.addEventListener("pointercancel",w),o.addEventListener("click",f);let b=typeof MutationObserver=="function"?new MutationObserver(m):void 0;return b?.observe(e,{attributes:!0,attributeFilter:["data-presentation"]}),t?.addEventListener("resize",m),m(),()=>{b?.disconnect(),t?.removeEventListener("resize",m),o.remove(),e.style.transform=""}}function F(e,n,r=!1){return(e.type==="modal"||e.type==="sheet")&&e.mobile&&r&&n<=z?e.mobile:e.type}function V(e,n,r){let c=e.ownerDocument.defaultView,t=n.presentation,o;if((t.type==="modal"||t.type==="sheet")&&t.backdrop){let i=`lp-backdrop-${crypto.randomUUID()}`,l={none:"transparent",scrim:"#f2f2f2cc",dim:"#0006","strong-dim":"#000000bf",blur:"#0006"};e.dataset.indianaBackdrop=i,o=e.ownerDocument.createElement("style"),o.textContent=`dialog[data-indiana-backdrop="${i}"]::backdrop{background:${l[t.backdrop]};backdrop-filter:${t.backdrop==="blur"?"blur(16px)":"none"}}`,e.append(o)}let d=n.pages?.[0]?.root.style?.shape,p=d?.type==="pill"?"9999px":d?.type==="rect"?typeof d.radius=="number"?`${d.radius}px`:[d.radius.topLeft,d.radius.topRight,d.radius.bottomRight,d.radius.bottomLeft].map(i=>`${i}px`).join(" "):void 0,s=(t.type==="modal"||t.type==="sheet")&&(t.desktopWidth!==void 0||t.mobile!==void 0||t.type==="modal"&&t.position!==void 0),a=t.type,m,g,h=!1,w=i=>{h||!Number.isFinite(i)||i<0||(g=i,a!=="fullscreen"&&a!=="inline"&&(e.style.height=`min(${Math.max(i,40)}px, calc(100dvh - ${a==="sheet"?0:32}px))`))},f=()=>{if(!h&&(a=m??F(t,c?.innerWidth??1024,c?.matchMedia?.("(pointer: coarse)").matches===!0),e.dataset.presentation=a,!(!s||t.type!=="modal"&&t.type!=="sheet"))){if(e.style.boxSizing="border-box",e.style.padding="0",e.style.border="0",e.style.overflow="hidden",e.style.outline="none",e.tabIndex=-1,e.style.background=n.theme.background,e.style.color=n.theme.text,a==="fullscreen")e.style.width="100vw",e.style.height="100dvh",e.style.maxWidth="100vw",e.style.maxHeight="100dvh",e.style.margin="0",e.style.borderRadius="0";else{let i=t.mobile==="sheet"&&a==="sheet",l=t.desktopWidth,u=c?.innerWidth??1024;e.style.width=i?`${u}px`:l?`${Math.min(l.max,Math.max(u*l.viewport/100,l.min))}px`:`${I[t.size]}px`,e.style.maxWidth=`${Math.max(0,u-(a==="sheet"?0:32))}px`,e.style.maxHeight=a==="sheet"?"100dvh":"calc(100dvh - 32px)",e.style.margin=a==="sheet"?"auto auto 0":t.type==="modal"&&t.position==="top"?"16px auto auto":t.type==="modal"&&t.position==="bottom"?"auto auto 16px":"auto",e.style.borderRadius=p??(a==="sheet"?"16px 16px 0 0":"24px"),e.style.height="",g!==void 0&&w(g)}r?.(a)}},b=s?[c?.matchMedia?.(`(max-width: ${z}px)`),c?.matchMedia?.("(pointer: coarse)")].filter(i=>i!==void 0):[];if(s){c?.addEventListener("resize",f);for(let i of b)i.addEventListener?i.addEventListener("change",f):i.addListener?.(f)}return f(),{responsive:s,get type(){return a},latch(){h||m!==void 0||(f(),m=a)},setContentHeight:w,destroy(){if(!h){h=!0,o?.remove(),delete e.dataset.indianaBackdrop,c?.removeEventListener("resize",f);for(let i of b)i.removeEventListener?i.removeEventListener("change",f):i.removeListener?.(f)}}}}function xe(e,n,r){let{presentation:c}=n,t="size"in c?`${_[c.size]}px`:"100vw";return e.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${t}`,V(e,n,r)}function he(e,n,r=!1){let c=e.ownerDocument.defaultView;if(typeof e.animate!="function"||c?.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;let t=r?{duration:300,easing:"cubic-bezier(0.23, 1, 0.32, 1)"}:{duration:240,easing:"cubic-bezier(0.2, 0.8, 0.2, 1)"};e.animate(n==="sheet"?[{transform:"translateY(100%)"},{transform:"none"}]:n==="modal"?[{opacity:0,transform:r?"translateY(12px) scale(0.96)":"translateY(8px) scale(0.98)"},{opacity:1,transform:"none"}]:[{opacity:0},{opacity:1}],t);try{e.animate([{opacity:0},{opacity:1}],{...t,pseudoElement:"::backdrop"})}catch{}}function O(e,n){e.style.cssText=["position:absolute","z-index:1","top:calc(4px + env(safe-area-inset-top, 0px))","inset-inline-end:calc(4px + env(safe-area-inset-right, 0px))","width:44px","height:44px","padding:0","border:0","border-radius:50%","font:400 20px/1 system-ui,sans-serif","cursor:pointer","touch-action:manipulation"].join(";"),e.style.background=`radial-gradient(circle, ${n.background} 0 15px, color-mix(in srgb, ${n.text} 22%, ${n.background}) 15px 16px, transparent 16.5px)`,e.style.color=n.text}var A=new WeakMap;function ve(e,n){return A.set(e,n),()=>A.delete(e)}function ge(e){let n=e.defaultView?.HTMLElement,r=e.activeElement;for(let t=0;t<16&&r?.shadowRoot?.activeElement;t++)r=r.shadowRoot.activeElement;let c=r?A.get(r)?.():void 0;return()=>{!r?.isConnected||!n||!(r instanceof n)||(r.focus({preventScroll:!0}),c?.())}}var Le=15e3;function Pe(e,n,r,c,t){let o=e.ownerDocument,d=new AbortController,p=!1,s=!1,a,m,g;function h(){clearTimeout(g),g=void 0,m?.(),m=void 0,a?.tagName==="DIALOG"&&a.close?.(),a?.remove(),a=void 0}function w(l,u){s||(s=!0,h(),(l==="dismissed"||l==="error")&&d.abort(u??new DOMException("Presentation cancelled","AbortError")),!(!p&&l!=="ready")&&H(n.onPresentationState,l==="error"?{surface:r,state:l,error:u}:{surface:r,state:l}))}let f=c,b=()=>{s||f()};return{setDismissHandler(l){f=l},get active(){return p&&!s},get cancelled(){return d.signal.aborted},getLoadingLayout(){return m?.getLayout?.()},start(l,u,y){if(p||s)return;p=!0;let D=()=>{if(!s&&n.loading!=="host"){let E=(u??o.documentElement.lang)||"en",L=l&&y?.presentation?.type!=="inline",S=y!==void 0,x=o.createElement(L?"dialog":"div");a=x,x.dataset.longplayLoading=r;let M=E.startsWith("zh"),R=S?M?"正在加载套餐":"Loading plans":M?"正在加载":"Loading",W=y?.screen.theme??{background:"Canvas",text:"CanvasText"};x.setAttribute("aria-label",R);let P=o.createElement("div");P.setAttribute("role","status");let k=o.createElement("div");k.setAttribute("aria-hidden","true"),S?(P.style.cssText="padding:calc(24px + env(safe-area-inset-top, 0px)) 24px 16px;padding-inline-end:68px;font:650 20px/1.3 system-ui,sans-serif;letter-spacing:-.015em",y||(P.style.paddingBlockEnd="24px")):P.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)",P.textContent=R;let v=o.createElement("button");v.type="button",v.textContent="×",v.setAttribute("aria-label",M?"取消加载":"Cancel loading"),O(v,W),S&&(v.style.borderRadius="50%",v.style.top="calc(15px + env(safe-area-inset-top, 0px))",v.style.insetInlineEnd="calc(15px + env(safe-area-inset-right, 0px))"),v.addEventListener("click",b),x.addEventListener("cancel",T=>{T.preventDefault(),b()});let $=o.createElement("style");$.textContent="[data-longplay-loading] > button:focus-visible{outline:2px solid currentColor;outline-offset:-2px}",x.append(P,k,v,$),e.append(x);let C=()=>{if(!s&&L){let T=x;T.showModal?T.showModal():T.open=!0,v.focus({preventScroll:!0})}};y&&t?(m=t(x,k,y,E),C()):S?(x.style.cssText=L?"padding:0;border:0;border-radius:24px;background:Canvas;color:CanvasText;width:min(420px,calc(100vw - 32px))":"position:relative;background:Canvas;color:CanvasText;width:100%",C()):(N(x,k,L,r),C())}};y!==void 0&&n.loading!=="host"?g=setTimeout(D,120):D(),H(n.onPresentationState,{surface:r,state:"loading",dismiss:b})},present(l){if(s)return;let u=!!a;h(),l(u),w("ready")},dismiss:b,finish:w,async wait(l,u){let y=d.signal,D,E,L=new Promise((S,x)=>{E=()=>x(y.reason),y.aborted?E():y.addEventListener("abort",E,{once:!0}),u!==void 0&&(D=setTimeout(()=>x(new Error("Presentation data timed out")),u))});try{let S=await Promise.race([L,l]);return y.throwIfAborted(),S}finally{y.removeEventListener("abort",E),clearTimeout(D)}}}}function N(e,n,r,c){e.style.cssText="position:relative;box-sizing:border-box;background:Canvas;color:CanvasText;padding:24px 48px 24px 24px;"+(r?"position:fixed;width:min(480px,calc(100% - 32px));border:0;border-radius:16px;max-height:calc(100dvh - 32px)":"width:100%"),n.style.cssText="display:grid;gap:12px";let t=c==="banner"?[["72%",12],["44%",10]]:[["46%",20],["84%",12],["65%",12],["100%",64]];for(let[o,d]of t){let p=e.ownerDocument.createElement("div");p.style.cssText=`width:${o};height:${d}px;background:currentColor;opacity:.11;border-radius:6px`,n.append(p)}}function B(e){let n={display:"block",position:"fixed",top:"0",left:"0",opacity:"0",pointerEvents:"none",zIndex:"-1"},r=Object.keys(n).map(o=>{let d=o,p=e.style[d];return e.style[d]=n[d],[d,p]}),c=e.inert??!1,t=e.getAttribute("aria-hidden");return e.inert=!0,e.setAttribute("aria-hidden","true"),()=>{for(let[o,d]of r)e.style[o]=d;e.inert=c,t===null?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",t)}}function Te(e,n){let r=e.style.width;e.style.width=`${n.getBoundingClientRect().width||n.ownerDocument.defaultView?.innerWidth||800}px`;let c=B(e);return()=>{c(),e.style.width=r}}export{ye as a,F as b,V as c,xe as d,he as e,O as f,ve as g,ge as h,Le as i,Pe as j,B as k,Te as l};
|
package/dist/chunk-J6UQGMH5.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as Kn}from"./chunk-P5NO4YS3.js";import{a as Jn,b as jn,c as mn,d as wn,e as $e,f as Bn,h as Wn,i as Yn,j as Xn,k as Zn}from"./chunk-KECKTHAM.js";import{b as Sn,c as et}from"./chunk-K4TQ5REL.js";import{a as Mn}from"./chunk-W32FI2A2.js";import{c as $n,e as xn,f as Gn,h as Qn,i as Le,j as tn,k as zn,l as rn}from"./chunk-A4TLE4OF.js";import{b as Fn}from"./chunk-W3B4GT74.js";import{K as nn}from"./chunk-LE32WTZ7.js";import{a as Me,d as Nn}from"./chunk-LSHIR6QM.js";import{c as On,e as _n,f as Ln,g as Hn,h as Vn,i as Un}from"./chunk-OPUIFAQS.js";import{b as Tn}from"./chunk-HYX3EDZS.js";import{B as fn}from"./chunk-EGFVGCDG.js";import{x as Dn}from"./chunk-YFLVGOCJ.js";import{t as An}from"./chunk-MQ5LJEWV.js";import{C as kn}from"./chunk-JDIFYMSA.js";import{a as m}from"./chunk-ZDIWOE4Q.js";import{a as Ee}from"./chunk-DSPLGTQI.js";async function yn(t){let{session:b,load:P}=ut(t);try{return await P(),b}catch(n){throw b.destroy(),n}}function ut(t){let b=t.view;if(!b?.paywall)throw new m("INVALID_REQUEST","The current node is not a Paywall");let P=b.paywall.receiptId,n=b.nodeId,g=b.visit,A=b.paywall.resolution,o=b.paywall,O="document"in A?{document:A.document,offering:A.offering,capabilities:A.capabilities}:null;function u(){let i=o.resolution;return"document"in i?i:O&&{...i,document:O.document,offering:O.offering,capabilities:On(i.capabilities,O.capabilities)}}function C(i){if(!_n(i,A))throw new m("INVALID_RESPONSE","The pinned Paywall binding changed")}let R=!1,G=new Set,ie=null;function w(){let i=u();if(i&&!R)for(let a of G)Ee(a,structuredClone(i))}async function _(){I();let i=u();if(i)return structuredClone(i);if(!ie){let a=(async()=>{if("document"in o.resolution||!t.resolvePaywall)throw new m("INVALID_RESPONSE","Public Paywall reader is unavailable");let q=await Sn(t,o.resolution);return I(),C(q),O={document:q.document,offering:q.offering,capabilities:q.capabilities},w(),u()})();ie=a;let s=()=>{ie===a&&(ie=null)};a.then(s,s)}return ie.then(a=>structuredClone(a))}let l=new AbortController,E=(t.pendingCommands??(t.pendingCommand?[t.pendingCommand]:[])).find(i=>i.operation==="submit"&&i.nodeId===n&&i.visit===g&&i.input.type==="paywall_quote")?.requestId??b.paywall.purchaseRequestId,S=0,re=null,U=new Set,M=null,z=new Map;function Q(i){if(i.purchase&&i.purchase.receiptId!==P)throw new m("INVALID_RESPONSE","Purchase receipt changed");let a=i.run.paywall;return i.purchase??(a?.receiptId===P?a:null)}function I(){if(R)throw new m("IDENTITY_CHANGED","Paywall presentation has closed")}function K(i,a,s){if(I(),a!==S||s!==void 0&&o.quote?.operationId!==s)return!1;let q=o.selectionGeneration??0,f=i.run.paywall;if(f?.receiptId===P){if((f.selectionGeneration??0)<(o.selectionGeneration??0))return!1;C(f.resolution)}let p=Q(i),F=f?.receiptId===P&&(f.selectionGeneration??0)>q,y=F?p?.quote??null:p?.quote??o.quote,Y=p?.operation??(y?.operationId===o.quote?.operationId?o.operation:null);return o.quote&&y&&Vn(o.quote,y),y&&Y&&Ln(Y,{operationId:y.operationId,membershipId:fn(y)?y.membershipId:null,...fn(y)?{featureQuantities:y.featureQuantities??{}}:{}},"Purchase operation changed"),(F||y?.operationId!==o.quote?.operationId)&&(S++,f?.receiptId===P&&(E=f.purchaseRequestId)),f?.canReselect===!0&&f.purchaseRequestId===M&&!(t.pendingCommands??[t.pendingCommand]).some(X=>X?.requestId===M)&&(M=null),o={...o,...f?.receiptId===P?f:{},...s!==void 0&&!F&&p?.canReselect!==void 0?{canReselect:p.canReselect}:{},quote:y,operation:Un(o.operation,Y,!0)},w(),!0}function N(i,a,s){return new Promise((q,f)=>{let p=!1,F=()=>{clearTimeout(j),l.signal.removeEventListener("abort",X)},y=ge=>{p||(p=!0,F(),q(ge))},Y=ge=>{p||(p=!0,F(),f(ge))},X=()=>Y(new m("IDENTITY_CHANGED","Paywall presentation has closed")),j=setTimeout(()=>Y(new m("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,s)),Math.max(0,a-Date.now()));l.signal.addEventListener("abort",X,{once:!0}),l.signal.aborted&&X(),i.then(y,Y)})}function qe(i){return new Promise(a=>{let s=()=>{clearTimeout(q),l.signal.removeEventListener("abort",s),a()},q=setTimeout(s,i);l.signal.addEventListener("abort",s,{once:!0}),l.signal.aborted&&s()})}function he(i,a){I();let s=z.get(i)??t.pendingCommands?.find(p=>p.requestId===i)??t.pendingCommand;if(s?.operation==="submit"&&s.requestId===i&&s.nodeId===n&&s.visit===g){a.type==="paywall_quote"&&s.input.type==="paywall_quote"&&s.input.predecessor&&!a.predecessor&&(a={...a,predecessor:s.input.predecessor});let p=nn.parse(s),F=nn.parse({...s,input:a});if(p.operation!=="submit"||F.operation!=="submit"||JSON.stringify(p.input)!==JSON.stringify(F.input))throw new m("CONFLICT","A purchase request cannot change its input");return z.set(i,p),p}let q=t.view;if(!q||q.nodeId!==n||q.visit!==g||q.paywall?.receiptId!==P)throw new m("PRECONDITION_FAILED","The Paywall visit has changed");let f=nn.parse({operation:"submit",requestId:i,nodeId:n,visit:g,revision:q.revision,input:structuredClone(a)});if(f.operation!=="submit")throw new m("INVALID_REQUEST","A purchase submission is required");return z.set(i,f),f}async function we(i,a){I();let{requestId:s,input:q}=i,f=Date.now()+3e4;U.add(s);try{let p=await N(t.submit(i),f,s);for(;p.run.pendingRequest?.requestId===s&&Date.now()<f&&!R&&(await qe(Math.min(1e3,f-Date.now())),!(R||Date.now()>=f));)p=await N(t.resume(s),f,s);if(R)throw new m("IDENTITY_CHANGED","Paywall presentation has closed");if(p.run.pendingRequest?.requestId===s)throw new m("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,s);if(!K(p,a,q.type==="paywall_confirm"||q.type==="paywall_cancel"?q.operationId:void 0))throw new m("PRECONDITION_FAILED","The purchase selection has changed");M===s&&(M=null)}catch(p){if(M=s,q.type==="paywall_quote"&&t.settle&&!R&&p instanceof m&&p.status!==void 0&&![401,425].includes(p.status)&&!p.retryable&&p.recovery!=="recover_operation")try{if((await N(t.settle(s),f,s)).settlement?.state==="settled"){let y=await N(t.get(),f,s);K(y,a)&&y.run.paywall?.purchaseRequestId===s&&o.canReselect===!0&&z.delete(s)}}catch{}throw p instanceof m&&p.code==="COMMAND_PENDING"&&p.status===void 0&&z.delete(s),p}finally{U.delete(s)}}async function W(i){if(!o.quote)throw new m("INVALID_REQUEST","A quoted purchase is required");let a=i==="confirm"?"paywall_confirm":"paywall_cancel",s=[...z.values(),...t.pendingCommands??(t.pendingCommand?[t.pendingCommand]:[])].find(f=>f.operation==="submit"&&f.input.type===a&&"operationId"in f.input&&f.input.operationId===o.quote.operationId),q=s?.operation==="submit"&&s.input.type===a&&"operationId"in s.input&&s.input.operationId===o.quote.operationId?s.requestId:crypto.randomUUID();if(await we(he(q,{type:i==="confirm"?"paywall_confirm":"paywall_cancel",operationId:o.quote.operationId,...i==="confirm"&&o.quote.merchantTerms?{merchantConfirmation:Dn(o.quote.merchantTerms)}:{}}),S),!o.operation)throw new m("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(o.operation)}let le={get view(){return structuredClone(u())},get quote(){return o.quote?structuredClone(o.quote):null},get operation(){return o.operation?structuredClone(o.operation):null},get webViewUrl(){return t.webViewUrl},get locale(){return t.view?.locale??b.locale},get canReselect(){return o.canReselect===!0&&M===null},get recovery(){let i=t.pendingCommands??(t.pendingCommand?[t.pendingCommand]:[]),a=t.pendingPurchase;if(a&&(a.receiptId!==P||a.operationId!==o.quote?.operationId))return{type:"recover",operationId:a.operationId,requestId:i[0]?.requestId??null};let s=Me({quote:o.quote,operation:o.operation,requestId:i[0]?.requestId??M??E,pending:U.size>0||i.length>0||M!==null,destroyed:R,canReselect:o.canReselect});return s.type==="recover"&&s.requestId===null&&!R&&t.hasDurableJournal===!0&&!o.quote&&!o.operation&&(o.selectionGeneration??0)===0&&!a&&!i.length&&!U.size&&!E?{type:"native",operationId:null}:s},get pendingCancellation(){return!R&&(t.pendingCommands??(t.pendingCommand?[t.pendingCommand]:[])).some(i=>i.operation==="submit"&&i.nodeId===n&&i.visit===g&&i.input.type==="paywall_cancel"&&i.input.operationId===o.quote?.operationId)},subscribe(i){return R?()=>{}:(G.add(i),()=>G.delete(i))},async refresh(){I();let i=S,a=await t.get();if(K(a,i),a.run.paywall?.receiptId!==P)throw new m("PRECONDITION_FAILED","Paywall presentation has changed");return _()},preview(i){let a=u();if(!a)return Promise.reject(new m("PRECONDITION_FAILED","Load the Paywall presentation first"));if(E&&E!==i.requestId&&(re||o.canReselect!==!0))return Promise.reject(new m("COMMAND_PENDING","Retry the original purchase before starting another"));let s=a.document.buttons[i.actionId],q=s?.type==="checkout"?Tn(s.product,i.selection,a.capabilities):null;if(!q)return Promise.reject(new m("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let f=An(a.document.screen,q,i.selection,a.capabilities),p=E!==i.requestId&&(o.selectionGeneration??0)>0?{operationId:o.quote?.operationId??null,generation:o.selectionGeneration??0}:void 0,F=t.view?.parameters.commerce;if(F&&typeof F=="object"&&!Array.isArray(F)&&F.intent==="subscription_change"&&!i.subscriptionChange)return Promise.reject(new m("INVALID_REQUEST","Choose the existing membership for this subscription change"));if(i.subscriptionChange&&i.nativeOffer)return Promise.reject(new m("INVALID_REQUEST","A web membership change cannot include a store offer"));if(p&&o.canReselect!==!0)return Promise.reject(new m("COMMAND_PENDING","Original purchase requires authoritative termination"));let y;try{y=he(i.requestId,{type:"paywall_quote",actionId:i.actionId,productVersionId:q,...Object.keys(f).length?{featureQuantities:f}:{},...p?{predecessor:p}:{},...i.offerId?{offerId:i.offerId}:{},...i.nativeOffer?{nativeOffer:i.nativeOffer}:{},...i.subscriptionChange?{subscriptionChange:i.subscriptionChange}:{}})}catch(j){return Promise.reject(j)}if(E===i.requestId&&re)return re;E!==i.requestId&&S++;let Y=S;E=i.requestId;let X=(async()=>{if(await we(y,Y),!o.quote)throw new m("INVALID_RESPONSE","The accepted quote is missing");return Hn(o.quote,{productVersionId:q,featureQuantities:f,subscriptionChange:i.subscriptionChange},"The selected purchase changed"),structuredClone(o.quote)})();return re=X,X.then(()=>{re===X&&(re=null)},j=>{re===X&&(re=null),E===i.requestId&&t.pendingCommand?.requestId!==i.requestId&&j instanceof m&&j.status!==void 0&&j.status<500&&![401,425].includes(j.status)&&(E=null)}),X},confirm:()=>W("confirm"),cancel:()=>W("cancel"),async read(){if(I(),!o.quote)throw new m("INVALID_REQUEST","A quoted purchase is required");let i=o.quote.operationId,a=S,s=t.pendingCommands?.find(y=>y.operation==="submit"&&(y.input.type==="paywall_confirm"||y.input.type==="paywall_cancel")&&y.input.operationId===i)??t.pendingCommand;s?.operation==="submit"&&(s.input.type==="paywall_confirm"||s.input.type==="paywall_cancel")&&s.input.operationId===i&&await t.settle?.(s.requestId);let q=await t.get(void 0,{receiptId:P,operationId:i});I();let f=Q(q);if(f?.quote&&f.quote.operationId!==i||f?.operation&&f.operation.operationId!==i)throw new m("INVALID_RESPONSE","Purchase operation changed");let p=K(q,a,i),F=p?o.operation:f?.operation;if(!F)throw new m("INVALID_RESPONSE","The current purchase result is missing");return p&&U.size===0&&!(t.pendingCommands?.length??(t.pendingCommand?1:0))&&(M=null),structuredClone(F)},destroy(){R=!0,L(),G.clear(),l.abort(),z.clear()}},L=t.subscribe(i=>{R||i.nodeId!==n||i.visit!==g||i.paywall?.receiptId!==P||(i.paywall.selectionGeneration??0)<(o.selectionGeneration??0)||(C(i.paywall.resolution),o={...o,resolution:i.paywall.resolution},w())});return{session:le,load:_}}function nt(t){let b=new Set,P=new Set,n=null;async function g(u,C){let R=!1;for(;!t.stopped&&t.key===u&&t.client.pendingCommand?.requestId===C;){if(!t.client.settle)throw new m("COMMAND_PENDING","The original display acknowledgement is still pending");await t.client.settle(C),R=!0,t.client.pendingCommand?.requestId===C&&await new Promise(G=>setTimeout(G,1500))}t.stopped||t.key!==u||(R&&await t.client.get(),!(t.stopped||t.key!==u)&&b.add(u))}function A(u,C){n=C;let R=()=>{n===C&&(n=null),P.delete(u)};return C.then(R,G=>{R(),t.busy||t.fail(G)}),C}function o(u){if(t.reviewing||b.has(u)||P.has(u)||t.stopped)return;P.add(u);let C=async()=>{if(t.reviewing||t.stopped||t.key!==u||b.has(u)){P.delete(u);return}if(t.busy||t.client.pendingCommand){setTimeout(()=>{C()},250);return}let R=(async()=>{if(t.staleRead){if(await t.staleRead,t.stopped||t.key!==u)return;if(t.client.pendingCommand){setTimeout(()=>{C()},250);return}}let G=t.client.view,ie=t.expected(),w=ie.requestId;try{await t.client.submit({operation:"shown",...ie})}catch(_){if(!(_ instanceof m)||_.code!=="CONFLICT"||_.status!==409||t.client.pendingCommand)throw _;await t.client.get();let l=t.client.view;if(t.stopped||t.reviewing||t.key!==u||!l||!G||l.id!==G.id||l.source.versionId!==G.source.versionId||l.nodeId!==ie.nodeId||l.visit!==ie.visit||l.revision<=ie.revision||l.stopped||!l.screen&&(!l.paywall||l.paywall.receiptId!==G.paywall?.receiptId)||!["running","waiting"].includes(l.status)||t.client.pendingCommand)throw _;let c=t.expected();w=c.requestId,await t.client.submit({operation:"shown",...c})}await g(u,w)})();A(u,R)};C()}function O(){if(n)return n;let u=t.client.pendingCommand;if(u?.operation!=="shown")return null;let C=t.key;return P.add(C),A(C,(async()=>{await t.client.retry(),await g(C,u.requestId)})())}return{report:o,settled:O,get inFlight(){return n}}}function tt(t){let b={},P=new Map;async function n(g){let A=t.client.view,o=A?.screen,O=o?.customerData.nodes[g.nodeId];if(t.stopped||t.busy||!A||!o||!O)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(g.action)){let _=t.document,l=_?kn(_,g.nodeId):null,c=l?.type==="customer_data"?l.data.outputs?.[g.action]:void 0;c&&o.outputs.includes(c)?await t.perform(()=>t.client.submit({operation:"submit",...t.expected(),input:{type:"screen",output:c,answers:t.answers,selection:g.value?{[g.nodeId]:g.value}:{}}})):await t.onIntent?.(g,A);return}let C=g.action.startsWith("sources_")?O.resources.find(_=>_.key===g.value):null;if(g.action.startsWith("sources_")&&!C)throw new m("INVALID_REQUEST","Choose a current resource");let R=`${A.visit}:${g.nodeId}:${C?.key??""}`,G=P.get(R)??[null],w=b[g.nodeId]??{page:1,after:null,filter:"all",...C?{resourceKey:C.key}:{}};if(g.action==="filter"){let _=g.value;if(!_||!(O.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(_))throw new m("INVALID_REQUEST","Unknown data filter");w={page:1,after:null,filter:_},G.splice(0,G.length,null)}else if(g.action==="next"||g.action==="sources_next"){let _=C?.sources.at(-1),l=C?_?{kind:"ledger",cursor:{at:_.detail[0],id:_.id,type:"source"}}:null:o.dataCursors[g.nodeId];if(!l||!C&&!O.hasNext)return;G[w.page]=l,w={...w,page:w.page+1,after:l}}else if(g.action==="previous"||g.action==="sources_previous"){if(w.page<=1)return;w={...w,page:w.page-1,after:G[w.page-2]??null}}P.set(R,G),b={...b,[g.nodeId]:w},await t.perform(()=>t.client.get({nodeId:A.nodeId,visit:A.visit,revision:A.revision,components:b}))}return{get queries(){return b},intent:n,reset(){b={},P.clear()}}}function it(t){let{doc:b,holder:P,reviewHolder:n,mountScreenPreview:g}=t,A=!1,o,O=0,u=null,C="",R,G=new Map,ie=l=>l?`${l.id}:${l.nodeId}:${l.visit}:${l.revision}:${l.paywall?.quote?.operationId??""}`:"";async function w(l){if(t.stopped||!t.client.review||A&&l===o&&R?.active)return;let c=!A||l!==o;A||(C=ie(t.client.view),G.set(C,structuredClone(t.answers))),A=!0,o=l,P.hidden=!0,t.suspend(!0),n.hidden=!1;let E=++O;c&&(R?.finish("dismissed"),u?.destroy(),u=null,n.replaceChildren(),R=tn(n,t.loadingOptions,"funnel",()=>{_()}));let S=c?R:void 0;try{if(S?.start(!1,t.client.view?.locale),E!==O||t.stopped)return;let re=t.client.review(l),U=await(S?.wait(re,Le)??re);if(t.stopped||E!==O||!A)return;if(!U.review)throw new m("INVALID_RESPONSE","Historical projection is missing");u?.destroy(),u=null,S||n.replaceChildren();let M=b.createElement("div"),z=S?rn(M,n):()=>{};n.append(M);let Q=U.run.locale.startsWith("zh"),I=t.chrome;M.style.cssText=I.history;let K=b.createElement("p");K.textContent=Q?"只读回看":"Read-only history",K.style.cssText=I.historyTitle,M.append(K);let N=b.createElement("p");N.style.cssText=I.historyNote,N.textContent=U.review.pages.length?Q?"选择一页查看当时的内容,回看不会改动任何信息。":"Choose a page to see it as it was. Nothing here can be changed.":Q?"还没有可回看的页面。":"There are no earlier pages yet.",M.append(N);let qe=U.review.page?.receiptId,he=b.createElement("div");he.style.cssText=I.historyPages;for(let[le,L]of U.review.pages.entries()){let i=b.createElement("button");i.type="button",i.textContent=Q?`第 ${le+1} 页`:`Page ${le+1}`;let a=qe!==void 0&&L.receiptId===qe;i.style.cssText=a?I.primary:I.secondary,a&&i.setAttribute("aria-current","page"),$e(i,()=>t.chrome.focus),i.onclick=()=>{w(L.receiptId)},he.append(i)}if(he.childElementCount&&M.append(he),U.review.page){let le=U.review.page,L=b.createElement("div");L.inert=!0,L.style.cssText=I.historyPage,M.append(L),u=g(L,{mode:"live",rendererUrl:t.client.webViewUrl,title:le.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{E===O&&!t.stopped&&S?.present(z)},onError:a=>{if(E!==O||t.stopped)return;let s=new Error(a);S?.finish("error",s),u?.destroy(),u=null,M.remove(),t.fail(s)},onEscape:()=>{_()}});let i=u;if(i.update(le.document,U.run.locale,{serverInput:{bindings:le.inputs,answers:le.answers,values:le.values}}),await i.ready,t.stopped||E!==O||!A)return}let we=Q?{issued:"已领取",reserved:"已预留",redeemed:"已使用",expired:"已过期",revoked:"已撤销",unknown:"状态待确认"}:{issued:"Issued",reserved:"Reserved",redeemed:"Used",expired:"Expired",revoked:"Revoked",unknown:"Status unconfirmed"},W=b.createElement("div");W.style.cssText=I.historyRecords;for(let le of[...U.review.coupons.map((L,i)=>`${Q?"优惠券":"Coupon"} ${i+1}: ${we[L.status]}`),...U.review.purchases.map((L,i)=>`${Q?"购买":"Purchase"} ${i+1}: ${Zn(L.status,Q)}`)]){let L=b.createElement("p");L.textContent=le,L.style.margin="0",W.append(L)}W.childElementCount&&M.append(W),U.review.page||S?.present(z),t.client.view&&await t.enqueue(t.client.view)}catch(re){if(E!==O||t.stopped)return;S?.finish("error",re),u?.destroy(),u=null,n.replaceChildren(),t.fail(re)}}async function _(){if(!A||t.stopped||!t.client.review)return;let l=++O;R?.finish("dismissed");try{if(await t.client.review(),t.stopped||l!==O)return;A=!1,O++,R?.finish("dismissed"),u?.destroy(),u=null,n.replaceChildren(),n.hidden=!0,P.hidden=!1;let c=t.client.view;ie(c)!==C?(G.set(C,structuredClone(t.answers)),t.resetScreen()):(G.delete(C),t.suspend(!1)),c&&await t.enqueue(c)}catch(c){if(l!==O||t.stopped)return;u?.destroy(),u=null,n.replaceChildren(),t.fail(c)}}return{get active(){return A},get receipt(){return o},open:w,exit:_,get drafts(){return new Map([...G].map(([l,c])=>[l,structuredClone(c)]))},stop(){A=!1,O++,R?.finish("dismissed"),u?.destroy(),u=null,n.replaceChildren(),n.hidden=!0,P.hidden=!1}}}var hn=5e3;async function dt(t,b,P){let n=b,g=n.prepared&&Kn(n.prepared),A=()=>{};function o(){n.prepared&&n.prepared.state!=="adopted"&&g?.release()}let O=()=>n.prepared?.state==="shown"&&!!g?.modal,u=n.client.identitySignal,C;try{C=await Promise.all([import("./screen-renderer-Y57TAOIX.js"),import("./paywall-LNVEFOAB.js")]),n.signal?.throwIfAborted(),u?.throwIfAborted()}catch(e){throw o(),e}let[{mountScreenPreview:R},{showPaywall:G}]=C,ie=(typeof INDIANA_NATIVE_SHELL_BUILD>"u"||!INDIANA_NATIVE_SHELL_BUILD)&&n.appManifestRelease?et({client:n.client,appManifestRelease:n.appManifestRelease,onError:n.onError}):void 0;ie?.start();let w=t.ownerDocument,_=Qn(w),l=!1,c=w.createElement("section"),E=w.createElement("div"),S=w.createElement("div"),re=w.createElement("div"),U=w.createElement("button");re.hidden=!0,U.type="button";let M=w.createElement("p"),z=w.createElement("p"),Q=w.createElement("button"),I=w.createElement("button"),K=w.createElement("button"),N=w.createElement("dialog"),qe,he=!1;c.dataset.indianaFunnel="",c.dataset.longplayCloseOwner="sdk",c.setAttribute("aria-busy","false"),M.setAttribute("role","status"),z.setAttribute("role","alert"),z.hidden=!0,Q.type=I.type=K.type="button",S.append(Q,U,M,z,K,I),c.append(E,re,S),t.append(c);let we=jn,W=mn(we),le="",L=(w.documentElement.lang||"").startsWith("zh"),i,a="",s;for(let e of[Q,U,K,I])$e(e,()=>W.focus);function q(){let e=L?"关闭":"Close";I.parentElement===N?(I.textContent="×",I.setAttribute("aria-label",e),Gn(I,we)):(I.textContent=e,I.removeAttribute("aria-label"),I.style.cssText=W.link+";margin-inline-start:auto")}function f(e){let r=e?.screen?.content.document.theme??we,d=JSON.stringify([r.primary,r.background,r.text,r.radius,r.font,I.parentElement===N]);if(d===le)return;le=d,we=r;let H=I.parentElement===N;W=mn(we,H),c.style.cssText=W.root+";min-width:0"+(H?";display:flex;flex-direction:column;min-height:100%":""),S.style.cssText=W.bar+(H?";margin-top:auto":""),S.hidden&&(S.style.display="none"),Q.style.cssText=U.style.cssText=W.secondary,K.style.cssText=W.primary,M.style.cssText=W.status,z.style.cssText=W.alert,q(),wn(Q)}function p(){S.hidden=Q.hidden&&U.hidden&&K.hidden&&z.hidden&&!M.textContent&&(I.hidden||I.parentElement!==S),S.style.display=S.hidden?"none":"flex",i?.responsive&&s!==void 0&&i.setContentHeight(s+S.getBoundingClientRect().height)}f();let F=null,y=null,Y=null,X="",j="",ge=!1,xe="",on="",Ge="",h=!1,ue=0,Qe=!1,gn="",sn=null,an=Promise.resolve(),vn=!n.client.view,J=P,Se,He,ze="",Je,pe=!1,De=null,ve=!1,je=()=>n.client.pendingCommand?.operation==="close",fe=null,ee=null,ln=Mn({document:w,run:async()=>{(!y?.observing||n.client.pendingCommand)&&await dn()},delay:()=>{if(!me.pending&&!(h||!Y||!["running","waiting"].includes(Y.status)&&!n.client.pendingCommand)&&!(y?.observing&&!n.client.pendingCommand))return Y.pendingRequest||n.client.pendingCommand?1500:hn},hiddenDelay:()=>!h&&!me.pending&&n.client.pendingCommand?15e3:void 0}),ne=null;function un(){return ee&&n.client.hasDurableJournal===!0&&ne?.acknowledged===!0&&ne.operationId===ee.operationId&&n.client.view?.id===ne.runId&&n.client.view?.status==="closed"&&n.client.view.revision===ne.revision+1&&!(n.client.pendingCommands?.length??(n.client.pendingCommand?1:0))&&!n.client.pendingPurchase?ee:null}function In(e){let r=e.run.paywall;if(ne&&e.settlement?.requestId===ne.requestId&&e.settlement.state==="settled"&&e.settlement.operationId===null&&e.run.id===ne.runId&&e.run.status==="closed"&&!e.run.pendingRequest&&e.run.revision===ne.revision+1&&e.run.nodeId===ne.nodeId&&e.run.visit===ne.visit&&r?.receiptId===ne.receiptId&&r.selectionGeneration===ne.selectionGeneration&&(r.quote?.operationId??null)===ne.operationId&&(r.operation?.operationId??r.quote?.operationId??null)===ne.operationId){let d=ne.operationId===null&&r.selectionGeneration===0&&!r.quote&&!r.operation&&!r.purchaseRequestId,H=Me({quote:r.quote,operation:r.operation,requestId:r.purchaseRequestId,pending:!1,destroyed:!1,canReselect:r.canReselect});(d||r.canReselect===!0&&H.type==="native")&&(ne.acknowledged=!0)}}let ke=null,Be=new Set,Ie={},Fe=!1,de=(e,r=null)=>{h||(e instanceof m&&e.status===409&&e.reason==="STATE_CHANGED"&&e.recovery==="recover_operation"&&ln.destroy(),ke=r,Fe=!1,z.textContent=Bn(e,L),z.hidden=!1,K.hidden=n.client.pendingCommand===null,p(),Ee(n.onError,e))},me=Fn({client:n.client,document:w,conceal(){h||(be(),J?.finish("dismissed"),c.hidden=!0,l||(l=!0,_()))},async receive(e){h||await ye(n.client.view??e.run)},failed(e){if(!h){if(!me.pending){ve=!1;let r=n.client.view;r&&ye(r).then(()=>de(e),de);return}Ze(),c.parentElement!==t&&t.append(c),c.hidden=!1,Q.hidden=U.hidden=I.hidden=!0,M.textContent="",f(),de(e,n.client.pendingCommand?.requestId??null)}}}),bn=()=>{h||(ke=null,z.textContent=Yn(L),z.hidden=!1,K.hidden=!0,p())};function Te(){let e=n.client.view;if(!e)throw new m("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision}}let T=it({client:n.client,doc:w,holder:E,reviewHolder:re,mountScreenPreview:R,loadingOptions:n,get chrome(){return W},get stopped(){return h},get answers(){return Ie},suspend(e){y?.setSuspended(e)},resetScreen(){X="",j="",xe=""},enqueue:ye,fail:de}),Ve=nt({client:n.client,expected:Te,fail:de,get stopped(){return h},get reviewing(){return T.active},get key(){return X},get busy(){return ue},get staleRead(){return sn}}),We=tt({client:n.client,expected:Te,perform:Oe,onIntent:n.onCustomerDataIntent,get stopped(){return h},get busy(){return ue},get document(){return F?.document},get answers(){return Ie}}),Ye=e=>`${e.id}:${e.nodeId}:${e.visit}`,Ne=e=>e&&(e.screen||e.paywall)?Ye(e):"";function Pe(){let e=n.client.view;Q.disabled=!T.active&&(ue>0||!!n.client.pendingCommand||!e?.canBack||e.stopped||!["running","waiting"].includes(e.status)||!Ne(e)||j!==Ne(e)),Q.hidden=!T.active&&!e?.canBack,wn(Q);let r=!!y&&!T.active;I.hidden=r&&!J?.active||he&&!T.active,U.hidden=!n.client.review||!T.active&&!e?.canBack;let d=e?.locale.startsWith("zh");M.textContent=r?"":ue>0||e?.pendingRequest?d?"正在处理":"Processing":e?.instruction?.type==="wait"?d?"等待中":"Waiting":"",p()}async function Cn(e){if(!e)return;let r=n.client.view;await e;let d=n.client.view;if(!r||!d||d.id!==r.id||d.nodeId!==r.nodeId||d.visit!==r.visit||d.stopped||!["running","waiting"].includes(d.status))throw new m("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}async function Oe(e,r=!1,d){if(!((ue||ve||fe||ee)&&!r||h||T.active&&!r)){ue++,c.setAttribute("aria-busy","true"),z.hidden=!0,ke=null,Fe=!1,Pe();try{if(r||await Cn(Ve.inFlight),h)return;let H=await e();h||await ye(n.client.view??H.run)}catch(H){d?.(H)&&n.client.pendingCommand===null?bn():me.pending||de(H,n.client.pendingCommand?.requestId??null)}finally{ue=Math.max(0,ue-1),c.setAttribute("aria-busy",String(ue>0)),h||(K.hidden=n.client.pendingCommand===null,Pe())}}}function Ue(){ln.schedule()}async function dn(){if(!(h||Qe||ue)&&!me.pending){if(T.active){await T.open(T.receipt);return}Qe=!0;try{let e=n.client.pendingCommand;e&&n.client.settle&&await n.client.settle(e.requestId);let r=n.client.view,d=We.queries,H=await n.client.get(r?.screen&&Object.keys(d).length?{nodeId:r.nodeId,visit:r.visit,revision:r.revision,components:d}:void 0);Fe&&!h&&(Fe=!1,z.hidden=!0,p()),!h&&d===We.queries&&await ye(n.client.view??H.run)}catch(e){de(e),Fe=!h}finally{Qe=!1}}}function Xe(e,r,d){if(J?.active){let ce=J;return ce.setDismissHandler(()=>Pn(ce)),ce}let H=tn(t,n,"funnel",()=>Pn(H),Jn);return J=H,H.start(e,r,d),H}function Pn(e){h||pe||(pe=!0,e.finish("dismissed"),be(),c.hidden=!0,n.client.view?Re().finally(se):se())}function cn(){clearTimeout(Je?.timeout),Je=void 0}function be(){he=!1,cn(),Se?.abort(),Se=void 0,F?.destroy(),F=null,y?.destroy(),y=null,He?.(),He=void 0,N.open&&N.close(),E.replaceChildren(),E.style.cssText="",s=void 0,X="",j="",ge=!1,xe="",Ge=""}function Rn(){let e=w.defaultView;i?.responsive&&e&&F?.resizeViewport?.(e.innerHeight,e.innerWidth)}function Ze(){i?.destroy(),i=void 0,a=""}function Ke(e){let r=e.screen?.presentation;if(!r||r.type==="inline"){N.open&&N.close(),Ze(),I.parentElement!==S&&S.append(I),c.parentElement!==t&&t.append(c);for(let ce of["flex","display","flex-direction","justify-content"])E.style.removeProperty(ce);f(e),p();return}c.parentElement!==N&&(N.append(I,c),t.append(N)),E.style.flex="1 0 auto",E.style.display="flex",E.style.flexDirection="column",E.style.justifyContent="center",f(e);let d=e.screen.content.document,H=JSON.stringify([r,le]);if(H!==a){Ze(),a=H;let ce={sm:420,md:640,lg:900},Ce="size"in r&&!r.backdrop?",0 0 0 100vmax #16142566":"";N.style.cssText=`box-sizing:border-box;padding:0;border:0;overflow:auto;background:${we.background};color:${we.text};`+(r.type==="fullscreen"?"width:100vw;height:100dvh;max-width:100vw;max-height:100dvh;margin:0;border-radius:0":`width:${ce[r.size]}px;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);box-shadow:0 24px 80px #0003${Ce};`+(r.type==="sheet"?"margin:auto auto 0;border-radius:14px 14px 0 0":"border-radius:14px")),i=$n(N,{presentation:r,theme:d.theme,pages:d.pages},Rn),i.latch()}p(),N.setAttribute("aria-label",(qe?.screen===e.screen?.content.document.name?qe?.label:void 0)??F?.document?.name??e.screen?.content.document.name??"Funnel")}async function rt(e){if(h||pe)return;if(me.observe(),me.pending){Y=e;return}if(ve&&(je()||["running","waiting"].includes(e.status))||(Y=e,ke&&n.client.pendingCommand?.requestId!==ke&&(z.hidden=!0,ke=null),L=e.locale.startsWith("zh"),U.textContent=L?"回看":"History",Q.textContent=T.active?L?"返回当前":"Return to current":L?"返回":"Back",q(),K.textContent=L?"重试":"Retry",K.hidden=n.client.pendingCommand===null,Pe(),gn!==`${e.revision}:${e.visit}:${e.status}:${e.stopped}`&&(gn=`${e.revision}:${e.visit}:${e.status}:${e.stopped}`,Ee(n.onState,structuredClone(e))),h||pe))return;if((!e.pendingRequest||ve&&e.status==="closed")&&["closed","ineligible","failed"].includes(e.status)){se();return}if(e.stopped&&O()){se();return}if(e.stopped||n.client.configurationReady===!1){T.stop(),o(),be(),J?.finish("skipped"),c.hidden=!0,Ue();return}if(c.hidden=!1,T.active){Ue();return}let r=Ne(e),d=n.client.view;if(d&&d.revision>e.revision&&Ne(d)!==r)return;let H=!e.instruction&&!e.pendingRequest&&e.nodeType==="screen"&&["running","waiting"].includes(e.status);r!==X&&(X&&J?.finish("dismissed"),be(),X=r,Ie={...e.answers},We.reset());let ce=Ye(e);if(ze===ce){c.hidden=!0;return}if(H&&!r){c.hidden=!0;let $=n.prepared?.state==="shown"?null:Xe(!0,e.locale);!h&&!pe&&Je?.key!==ce&&(cn(),Je={key:ce,timeout:setTimeout(()=>{let v=n.client.view;if(h||!$?.active&&n.prepared?.state!=="shown"||!v||Ye(v)!==ce)return;ze=ce;let B=new Error("Funnel screen preparation timed out");$?.finish("error",B),o(),be(),de(B)},Le)}),Ue();return}cn();let Z=$=>{let v=n.client.view;return!h&&!pe&&!De&&!$.aborted&&n.client.configurationReady!==!1&&!!v&&!v.stopped&&!["closed","ineligible","failed"].includes(v.status)&&Ne(v)===r},Ce=($,v)=>{Z(v)&&(ze=r,J?.finish("error",$),be(),c.hidden=!0,de($))};if(r||((e.instruction&&e.instruction.type!=="evaluate_segment"||!["running","waiting"].includes(e.status))&&o(),Ke(e),e.instruction?.type!=="event"&&e.instruction?.type!=="open_url"&&J?.finish("skipped")),e.screen){o();let $=e.screen.content;if(!F){let oe=e.screen.presentation.type!=="inline",x=Xe(oe,e.locale);if(h||pe)return;let te=(Se=new AbortController).signal;Ke(e),He=oe?zn(N):rn(c,t),F=R(E,{mode:"live",closeActions:Array.from(new Set([...n.closeActions??[],...$.document.actions.filter(V=>V.type==="event"&&V.close).map(V=>V.id)])),onAuthoredClose(V){Z(te)&&(he=V,Pe())},rendererUrl:n.client.webViewUrl,title:$.document.name,...oe?{hostPresentation:()=>i?.type??e.screen.presentation.type}:{},onResize:V=>{s=V,i?.responsive&&i.setContentHeight(V+S.getBoundingClientRect().height)},onAction(V,k={},Ae={}){if(T.active||!Z(te)||j!==r)return;Ie={...Ie,...Ae};let pn=e.screen?.inputs??[],qn=Object.fromEntries(pn.filter(({variable:_e})=>Object.hasOwn(Ie,_e)).map(({variable:_e})=>[_e,Ie[_e]]));if(Xn(pn,qn).length){bn();return}Oe(()=>n.client.submit({operation:"submit",...Te(),input:{type:"screen",output:V,answers:qn,selection:k}}),!1,_e=>Wn(_e,pn))},onAnswers:V=>{T.active||!Z(te)||j!==r||(Ie={...Ie,...V})},onCustomerDataIntent:V=>{T.active||!Z(te)||j!==r||We.intent(V).catch(de)},onEscape:()=>{!Z(te)||j!==r||T.active||fe||ee||Re()},onError:V=>{let k=new Error(V);j===r?de(k):Ce(k,te)},onRendered:V=>{if(!(!Z(te)||j===r))try{x.present(k=>{He?.(),He=void 0,V&&(qe={screen:$.document.name,label:V},N.setAttribute("aria-label",V)),oe&&(N.showModal(),l=!1,i?.responsive&&N.focus({preventScroll:!0}),!k&&n.loading!=="host"&&xn(N,i?.type??e.screen.presentation.type,i?.responsive)),j=r,ge=oe,Pe()}),Z(te)&&Ve.report(r)}catch(k){Ce(k,te)}}}),Rn()}let v={capabilities:e.screen.capabilities,customerData:e.screen.customerData,parameters:e.parameters,serverInput:{bindings:e.screen.inputs,answers:Ie,values:e.screen.values}},B=JSON.stringify([$,e.locale,v.parameters,e.screen.inputs,e.screen.values]);if(B!==xe)F.update($.document,e.locale,v),xe=B,on=JSON.stringify(v.capabilities),Ge=JSON.stringify(v.customerData);else{let oe=JSON.stringify(v.capabilities);oe!==on&&(F.updateCapabilities(v.capabilities),on=oe),JSON.stringify(v.customerData)!==Ge&&(F.updateCustomerData(v.customerData),Ge=JSON.stringify(v.customerData))}let ae=F;if(ae)try{await(J?.wait(ae.ready)??ae.ready)}catch(oe){Se&&Ce(oe,Se.signal)}}else if(e.paywall&&!y){let $=e.paywall.resolution,v="document"in $?$.document:null,B=g,ae=n.mountPaywallControls,oe=null,x=(Se=new AbortController).signal,te={loading:"host",signal:x,...ae&&{mountControls:k=>ae(k,e)},canInteract:()=>Z(x)&&!T.active&&!fe&&!ee,beforeAction:async()=>{ue++;try{await Cn(Ve.settled()),z.hidden=!0,ke=null,Fe=!1,p()}finally{ue=Math.max(0,ue-1)}},start:()=>yn(n.client),onObservationChange:Ue,onPurchase:n.onPurchase,onCheckoutUrl:n.onCheckoutUrl,resumeCheckout:n.resumeCheckout,allowNewPurchase:n.allowNewPurchase,checkoutNavigation:n.checkoutNavigation,terminateCheckout:n.terminateCheckout,beforeCheckoutReplacement:n.beforeCheckoutReplacement,purchaseConfirmation:n.purchaseConfirmation,confirmOnHostedCheckout:n.confirmOnHostedCheckout,resolveOfferId:n.resolveOfferId,resolveSubscriptionChange:n.resolveSubscriptionChange,claimCoupon:n.claimCoupon,onEvent:n.onEvent,onOpenUrl:k=>n.onOpenUrl?n.onOpenUrl({receiptId:e.paywall.receiptId,url:k,openIn:"same_window"}):w.defaultView?.location.assign(k),onAction:async k=>{if(T.active)return;let Ae=await n.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:n.client.view?.revision??e.revision,input:{type:"screen",output:k,answers:{}}});await ye(n.client.view??Ae.run)},onError:k=>{j===r?de(k):Ce(k,x)}},V={quoteError:k=>Ee(n.onError,k),loadingLayout:()=>Z(x)?oe?.getLoadingLayout?.():void 0,present(k){Z(x)&&(oe?.present(Ae=>{k(Ae),j=r,ge=!!E.querySelector("dialog[open]"),ge&&(l=!1),Pe()}),Z(x)&&Ve.report(r))},async closeAction(k){h||T.active||await me.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:n.client.view?.revision??e.revision,input:{type:"screen",output:k,answers:{}}})},async dismiss(){if(!(h||x.aborted||T.active||fe||ee||!ve&&!Z(x))){if(ve=!0,(n.resumeCheckout||n.terminateCheckout)&<()){Y=n.client.view,se();return}await Re()}}};if(B&&ae)o();else if(B){let k=await B.adopt(e,{options:te,handoff:V,start:()=>yn(n.client)});k&&Z(x)&&!h?(Ke(e),y=k,J?.active&&J.present(()=>{}),j=r,ge=B.modal,ge&&(l=!1),Pe(),Ve.report(r),T.active&&y.setSuspended(!0)):(k?.destroy(),o())}if(h||pe)return;if(!y){if(oe=Xe(!0,e.locale,v),h||pe)return;Ke(e);let k=await G(E,te,V).catch(Ae=>(Ce(Ae,x),null));!Z(x)&&!(ve&&!h&&!x.aborted)?k?.host?.destroy():k&&(y=k.host,y?.setSuspended(T.active))}}if(h||pe)return;Pe();let D=e.instruction;if(D&&(D.type==="open_url"||D.type==="event")&&!Be.has(D.receiptId)){let $=w.createElement("button");$.type="button",$.style.cssText=W.primary,$e($,()=>W.focus),E.style.cssText=W.stage,$.textContent=D.type==="open_url"?`${L?"前往":"Continue to"} ${new URL(D.url).host}`:L?"继续":"Continue",$.onclick=()=>{let v=Te(),B=D.type==="open_url"&&!n.onOpenUrl&&D.openIn==="new_window"?ot(D.url):null;Oe(async()=>{let ae="success";if(D.type==="open_url")if(n.onOpenUrl)try{ae=await n.onOpenUrl({receiptId:D.receiptId,url:D.url,openIn:D.openIn})===!1?"failed":"opened"}catch(x){Ee(n.onError,x),ae="failed"}else ae=D.openIn==="new_window"&&!B?"failed":"opened";if(D.type==="event"){if(!n.onEvent)throw new m("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(D.event)}if(h||n.client.view?.nodeId!==v.nodeId||n.client.view.visit!==v.visit)throw new m("PRECONDITION_FAILED","The client action visit changed");let oe=await n.client.submit({operation:"submit",...v,input:{type:"client_action",receiptId:D.receiptId,outcome:ae}});return Be.add(D.receiptId),D.type==="open_url"&&!n.onOpenUrl&&D.openIn==="same_window"&&w.defaultView?.location.assign(D.url),oe})},J?.active?J.present(()=>E.replaceChildren($)):E.replaceChildren($)}!e.pendingRequest&&e.status==="completed"&&!Be.has(`complete:${e.id}`)&&(Be.add(`complete:${e.id}`),Ee(n.onComplete,structuredClone(e))),Ue()}function ot(e){let r=w.defaultView?.open(e,"_blank")??null;return r&&(r.opener=null),r}function ye(e){return Pe(),an=an.catch(()=>{}).then(async()=>{try{await rt(e)}catch(r){throw J?.active&&(ze=Ye(e),J.finish("error",r),be(),c.hidden=!0),r}}),an}let st=n.client.subscribe(e=>{if(!vn){if(e.stopped&&(ge||O())&&!ve){Y=e,se();return}!ve&&(e.stopped||n.client.configurationReady===!1||X&&j!==X&&(Ne(e)!==X||["closed","ineligible","failed"].includes(e.status)))&&(be(),J?.finish("dismissed"),c.hidden=!0),ye(e).catch(de)}}),at=n.client.subscribeError?.(e=>{me.pending||de(e)});function lt(){let e=n.client.view,r=e?.paywall;return!!r?.operation&&!!e&&["running","waiting"].includes(e.status)&&Nn(Me({quote:r.quote,operation:r.operation,requestId:r.purchaseRequestId,pending:!1,destroyed:!1,canReselect:r.canReselect}))}function Re(e){if(De)return De;if(h||!e&&(fe||ee))return Promise.resolve();let r=!e&&je();return!r&&n.client.view&&!["running","waiting"].includes(n.client.view.status)?(Y=n.client.view,se(),Promise.resolve()):(De=Oe(async()=>{let d=r?await n.client.retry():await(e?n.client.submit.bind(n.client):me.submit)({operation:"close",...e??Te()});return e&&In(d),d},!0).then(()=>{let d=n.client.view;d?.status==="closed"&&!je()&&(Y=d,se())}).finally(()=>{De=null}),De)}function se(){ie?.destroy(),!h&&(h=!0,me.destroy(),A(),o(),n.signal?.removeEventListener("abort",se),u?.removeEventListener("abort",se),J?.finish("dismissed"),ln.destroy(),st(),at?.(),be(),Ze(),T.stop(),N.remove(),c.remove(),l||_(),Ee(n.onDismiss,Y?structuredClone(Y):null))}Q.onclick=()=>{if(!Q.disabled){if(T.active){T.exit();return}Oe(()=>n.client.submit({operation:"back",...Te()}))}},U.onclick=()=>{T.open()},I.onclick=()=>{J?.active?J.dismiss():fe||Re()},K.onclick=()=>{me.pending?me.retry().catch(()=>{}):je()?Re():Oe(()=>n.client.retry())},N.addEventListener("cancel",e=>{e.preventDefault(),J?.active?J.dismiss():fe||Re()}),n.signal?.addEventListener("abort",se,{once:!0}),u?.addEventListener("abort",se,{once:!0});let en=!1;g&&(A=g.onClose(()=>{h||pe||(pe=!0,J?.finish("dismissed"),be(),c.hidden=!0,n.client.view?Re().finally(se):en=!0)}));let En={destroy:se,refresh:dn,get recovery(){let e=un();if(e)return e;if(!h&&!ue&&!ve&&!fe&&y){let r=y.recovery;if(r.type!=="native")return r}return{type:"recover",operationId:n.client.pendingPurchase?.operationId??n.client.view?.paywall?.quote?.operationId??ee?.operationId??null,requestId:n.client.pendingCommand?.requestId??null}},prepareFallback(){if(fe)return fe;let e=un();if(e)return Promise.resolve(e);let r=n.client.pendingPurchase?.operationId??n.client.view?.paywall?.quote?.operationId??ee?.operationId??null,d=()=>({type:"recover",operationId:r,requestId:n.client.pendingCommand?.requestId??null});if(n.client.hasDurableJournal!==!0){let D=y?.recovery;return Promise.resolve(D&&D.type!=="native"&&D.type!=="cancel"?D:d())}let H=(n.client.pendingCommands??(n.client.pendingCommand?[n.client.pendingCommand]:[])).some(D=>D.operation==="close");if(h&&!(H||ee&&n.client.view?.status==="closed")||ue||Qe||De||T.active||!y&&!ee&&!H)return Promise.resolve(d());let ce=y,Z=(async()=>{try{if(!ee&&H){let v=await n.client.retry();return await ye(n.client.view??v.run),d()}if(!ee){let v=await ce.prepareFallback();if(v.type!=="native")return v;if(n.client.hasDurableJournal!==!0)return d();ee=v}let D=n.client.pendingCommands??(n.client.pendingCommand?[n.client.pendingCommand]:[]);if(D.length){let v=D.find(ae=>ae.operation==="close");if(!v||!ne||v.requestId!==ne.requestId)return d();let B=await n.client.retry();In(B),await ye(n.client.view??B.run)}else{let v=n.client.view,B=v?.paywall;if(!v||!B||B.selectionGeneration===void 0||(B.quote?.operationId??null)!==ee.operationId||ee.operationId!==null&&B.canReselect!==!0)return d();let ae=B.selectionGeneration,oe=await n.client.get();await ye(n.client.view??oe.run);let x=n.client.view,te=x?.paywall;if(!x||!te||!["running","waiting"].includes(x.status)||x.stopped||x.id!==v.id||x.nodeId!==v.nodeId||x.visit!==v.visit||te.receiptId!==B.receiptId||te.selectionGeneration!==ae||(te.quote?.operationId??null)!==ee.operationId||ee.operationId!==null&&te.canReselect!==!0||n.client.pendingPurchase||(n.client.pendingCommands?.length??(n.client.pendingCommand?1:0)))return d();let V=Te();ne={runId:x.id,operationId:ee.operationId,revision:V.revision,requestId:V.requestId,nodeId:x.nodeId,visit:x.visit,receiptId:te.receiptId,selectionGeneration:ae,acknowledged:!1},await Re(V)}let $=un();return $?(se(),$):d()}catch(D){return de(D),d()}})();fe=Z;let Ce=()=>{fe===Z&&(fe=null)};return Z.then(Ce,Ce),Z},review:T.open,exitReview:T.exit,get unappliedDrafts(){return T.drafts}};try{let e=n.client.view;if(e)((n.client.viewAgeMs??hn)>=hn||e.instruction?.type==="evaluate_segment")&&(sn=dn().finally(()=>{sn=null})),await ye(e);else{if(c.hidden=!0,h)throw new DOMException("Presentation cancelled","AbortError");let r=en||n.prepared?.state==="shown"?null:Xe(n.client.view?.screen?.presentation.type!=="inline",n.client.view?.locale);if(h||pe&&!en)throw new DOMException("Presentation cancelled","AbortError");let d=n.client.get(),H=await(r?r.wait(d,Le):ct(d,Le));if(vn=!1,en)return h||await Re().finally(se),En;await ye(n.client.view??H.run)}}catch(e){throw J?.finish("error",e),se(),e}return En}function ct(t,b){let P;return Promise.race([t,new Promise((n,g)=>{P=setTimeout(()=>g(new Error("Presentation data timed out")),b)})]).finally(()=>clearTimeout(P))}function Zt(t,b,P){return dt(t,b,P)}export{dt as a,Zt as b};
|
package/dist/chunk-P5NO4YS3.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as ye,b as we}from"./chunk-N3PZMMOO.js";import{d as pe,e as $}from"./chunk-OPUIFAQS.js";import{a as fe}from"./chunk-ZDIWOE4Q.js";import{a as P}from"./chunk-DSPLGTQI.js";var Ce=5*6e4,Ae=15e3,ge=new WeakMap;function Oe(i){return ge.get(i)}var C=i=>Array.isArray(i)?i.map(C):i&&typeof i=="object"?Object.fromEntries(Object.keys(i).sort().map(n=>[n,C(i[n])])):i,R=(i,n)=>JSON.stringify(C(i))===JSON.stringify(C(n)),me=i=>JSON.stringify(C([i.funnelId,i.locale??null,i.parameters??{}])),Ee=["onObservationChange","onPurchase","onCheckoutUrl","resumeCheckout","allowNewPurchase","checkoutNavigation","terminateCheckout","beforeCheckoutReplacement","purchaseConfirmation","confirmOnHostedCheckout","resolveOfferId","resolveSubscriptionChange","onOpenUrl","onEvent","onAction","onComplete","onError"];function Fe(i,n){let z=e=>structuredClone({funnelId:e.funnelId,locale:e.locale,parameters:e.parameters}),y,Q="",Y=n.start instanceof Promise?void 0:z(n.start),N=e=>e?.parameters?.commerce,Z=Promise.resolve(n.start).then(e=>e?z(e):void 0),D=n.maxAgeMs??Ce,ee=new AbortController,p=AbortSignal.any([ee.signal,n.client.identitySignal,...n.signal?[n.signal]:[]]),M=()=>o("released","aborted"),t="preparing",ne,_,q=()=>{},V=0,h=null,m=null,g=null,u=null,b,x,ae=new Map,f=null,O=new Set,S=new Map,j,te=new Promise(e=>j=e),T,he=new Promise(e=>T=e);function F(e,a){t!==e&&(t=e,ne=a,P(n.onState,e))}function be(){p.removeEventListener("abort",M),H(),m?.destroy(),m=null,h?.remove(),h=null,g=null}function o(e,a){["adopted","unavailable","released","closed"].includes(t)||(F(e,a),be(),j(!1),T(null))}let J=e=>`error:${e?.code??e?.name??"unknown"}`,U=i.ownerDocument.defaultView,A=!0,re=null,I=!1,ve=e=>e.storageArea===U?.localStorage&&(e.key===null||e.key.startsWith("indiana.funnel.purchases.")),oe=e=>{ve(e)&&L()},Pe=n.client.subscribe(()=>L());function H(){A&&(A=!1,U?.removeEventListener("storage",oe),Pe(),q())}let G=()=>A&&(t==="ready"||t==="preparing");function W(e){(t==="ready"||t==="preparing")&&o("unavailable",e)}function L(){if(t==="ready"&&Date.now()-V>=D)return H();I=!0,re??=(async()=>{for(;I&&y&&G();){I=!1;try{await n.client.retained()==="pending"&&W("purchase_pending")}catch(e){p.aborted?o("released","aborted"):W(J(e))}}})().finally(()=>{re=null,I&&y&&G()&&L()})}U?.addEventListener("storage",oe),p.addEventListener("abort",M,{once:!0});let le=n.client.findPurchase();le.catch(()=>{});let E;function K(e){let a=JSON.stringify(C(e)),r=ae.get(a);return r||(r=n.client.readPaywall({paywallVersionId:E?.paywallVersionId??n.paywallVersionId??u?.id,...E?.paywallVersionId||n.paywallVersionId||u?{}:{paywallId:E?.paywallId??n.paywallId},...e}),ae.set(a,r)),r}function B(e){let a=Object.values(e.capabilities.plans);return!(Object.values(e.document.buttons).some(c=>c.type==="checkout")&&a.length===0)&&!a.some(c=>!c.available)}function ie(e,a){if(u&&!$(e,u))return o("unavailable","paywall_changed"),!1;u=e,x=a;for(let r of S.keys())P(r,structuredClone(e));return!0}async function k(){let e=await he;if(!e)throw new fe("PURCHASE_PENDING","The purchase did not start; open it again");return e}let Se={get view(){return f?f.view:u},get signal(){return f?.signal??n.client.identitySignal},get quote(){return f?.quote??null},get operation(){return f?.operation??null},webViewUrl:"bundled",get canReselect(){return f?.canReselect},get recovery(){return f?.recovery},get pendingCancellation(){return f?.pendingCancellation},subscribe(e){return S.set(e,f?.subscribe?.(e)??(()=>{})),()=>{S.get(e)?.(),S.delete(e)}},refresh:async()=>f?f.refresh():structuredClone(u),preview:async e=>(await k()).preview(e),confirm:async()=>(await k()).confirm(),cancel:async()=>(await k()).cancel(),read:async()=>(await k()).read(),destroy(){f?.destroy()}},s={options:{},handoff:{}},se={loading:"host",focusAtReveal:!0,signal:n.client.identitySignal,start:async()=>Se,canInteract:()=>s.options.canInteract?s.options.canInteract():!["unavailable","released","closed"].includes(t),async beforeAction(){let e=t!=="adopted",a=u?.capabilities,r=await k();if(e&&!R(r.view?.capabilities,a))throw new pe;await s.options.beforeAction?.()}};for(let e of Ee)Object.defineProperty(se,e,{enumerable:!0,get:()=>s.options[e]});function X(){t!=="preparing"||!g||!m||!y||!R(x?.commerce,N(y))||x?.locale!==y.locale||(F("ready"),j(!0))}let ce={loadingLayout:()=>s.handoff.loadingLayout?.(),present(e){if(s.handoff.present)return s.handoff.present(e);t==="preparing"&&(g=e,V=Date.now(),X())},async dismiss(){if(s.handoff.dismiss)return s.handoff.dismiss();o("closed");for(let e of[...O])P(e)},async closeAction(e){if(s.handoff.closeAction)return s.handoff.closeAction(e);s.options.onAction?await s.options.onAction(e):await ce.dismiss()},quoteError(e){s.handoff.quoteError?s.handoff.quoteError(e):P(s.options.onError,e)}};async function Ie(){if(n.paywallVersionId||n.paywallId)return{paywallVersionId:n.paywallVersionId,paywallId:n.paywallId};let e=n.configuration;if(!e)return o("unavailable","paywall_missing"),null;let a=await Promise.resolve(n.start).catch(()=>null);if(!a||t!=="preparing")return null;let r=()=>ye(e,{funnelId:a.funnelId,customerId:n.client.customerId,parameters:a.parameters??{}});if(_=await r(),t!=="preparing")return null;let c=_;if(c.type!=="paywall")return o("unavailable",we(c)??"route"),null;let l=!1;return q=e.subscribe(()=>{l||!G()||(l=!0,r().then(d=>{!(d.type==="unavailable"&&!["funnel_stopped","route_unavailable"].includes(d.reason))&&(d.type!=="paywall"||d.paywallVersionId!==c.paywallVersionId)&&W("route_changed")}).finally(()=>l=!1))}),A||q(),{paywallVersionId:c.paywallVersionId}}(async()=>{try{let[{showPaywall:e},a]=await Promise.all([import("./paywall-LNVEFOAB.js"),Ie()]);if(p.throwIfAborted(),t!=="preparing"||!a)return;let r=n.commerce??N(Y),c=n.locale??Y?.locale;if(!r)return o("unavailable","commerce_missing");if(!c)return o("unavailable","locale_missing");E=a;let l={commerce:r,locale:c},d=await K(l);if(p.throwIfAborted(),t!=="preparing"||(!B(d)&&n.start instanceof Promise&&!b&&await Z,b&&!R(l,b)&&(l=b,d=await K(l)),p.throwIfAborted(),t!=="preparing"))return;if(!B(d))return o("unavailable","plan_unavailable");if(!ie(d,l))return;h=i.ownerDocument.createElement("div"),i.append(h);let v=setTimeout(()=>t==="preparing"&&o("unavailable","timeout"),Ae);te.then(()=>clearTimeout(v));let w=await e(h,se,ce);if(!w.host||p.aborted||t!=="preparing"){w.host?.destroy(),o(p.aborted?"released":"unavailable","error");return}m=w.host,X()}catch(e){o(p.aborted?"released":"unavailable",J(e))}})(),Z.then(async e=>{if(!e)return o("unavailable","gated");let a=e,r=N(a),c=n.commerce??r;if(!R(r&&{...r,intent:void 0},c&&{...c,intent:void 0})||n.locale!==void 0&&a.locale!==n.locale)return o("unavailable","start_mismatch");if(!r)return o("unavailable","commerce_missing");b={commerce:r,locale:a.locale};try{let l=await le,d=l==="pending"?"purchase_pending":l==="found"?"original_purchase":l==="blocked"?"purchase_blocked":void 0;if(d)return o("unavailable",d);if(t!=="preparing")return;if(A&&(I=!1,await n.client.retained()==="pending"))return o("unavailable","purchase_pending");if(E||n.paywallId||n.paywallVersionId||u){let v=await K(b);if(p.throwIfAborted(),t!=="preparing")return;if(u){if(!B(v))return o("unavailable","plan_unavailable");if(!ie(v,b))return}}}catch(l){return o(p.aborted?"released":"unavailable",J(l))}t==="preparing"&&(y=a,Q=me(a),X(),I&&L())},()=>o("unavailable","gated"));let de={get state(){return t},get reason(){return ne},ready:te,get start(){return y},get prediction(){return _?structuredClone(_):void 0},matches:e=>!!y&&me(e)===Q,open(){if(t==="preparing")return"pending";if(t!=="ready"||!g)return!1;if(Date.now()-V>=D)return o("unavailable","expired"),!1;let e=g;return g=null,H(),F("shown"),e(),"shown"},destroy(){ee.abort()}};return ge.set(de,{onClose(e){return t==="closed"?(P(e),()=>{}):(O.add(e),()=>{O.delete(e)})},claim(){H()},async adopt(e,a){let r=e.paywall?.resolution,c=e.paywall&&!e.paywall.quote&&!e.paywall.operation&&!e.paywall.purchaseRequestId&&!(e.paywall.selectionGeneration??0);if(t!=="shown"||!m||!u||!r||!c||e.source.id!==y?.funnelId||e.locale!==y?.locale||!R(e.parameters??{},y?.parameters??{})||!["running","waiting"].includes(e.status)||!$(r,u))return null;let l;try{l=await a.start()}catch{return null}if(t!=="shown"||!m)return l.destroy(),null;f=l,s.options=a.options,s.handoff=a.handoff;for(let[w]of S)S.set(w,l.subscribe?.(w)??(()=>{})),l.view&&P(w,structuredClone(l.view));p.removeEventListener("abort",M),F("adopted"),T(l),O.clear();let d=m,v=h;return m=null,h=null,g=null,new Proxy(d,{get(w,ue){return ue==="destroy"?()=>{w.destroy(),v?.remove()}:Reflect.get(w,ue,w)}})},get modal(){return u?.document.presentation.type!=="inline"},get revealable(){return t==="ready"&&!!g&&Date.now()-V<D},release(){o("released")}}),de}export{Ce as a,Oe as b,Fe as c};
|
package/dist/chunk-WEHUXUXS.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as n,r as t}from"./chunk-GMKLSHXK.js";function u(o,e,a){return n(o,e,a,t)}export{u as a};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as ee}from"./chunk-J6UQGMH5.js";import{b as j}from"./chunk-P5NO4YS3.js";import"./chunk-N3PZMMOO.js";import"./chunk-2LEDTNKQ.js";import{a as Y}from"./chunk-KECKTHAM.js";import{b as X}from"./chunk-5J2CFNYR.js";import"./chunk-K4TQ5REL.js";import"./chunk-W32FI2A2.js";import{f as Z,h as $,i as V,j as B}from"./chunk-A4TLE4OF.js";import"./chunk-3ITNAFAH.js";import"./chunk-2I2S5ZIH.js";import"./chunk-GMKLSHXK.js";import"./chunk-W3B4GT74.js";import"./chunk-Y2ASROJH.js";import"./chunk-XLTR45M5.js";import"./chunk-HYCLLEFU.js";import"./chunk-KSME3N3A.js";import"./chunk-LE32WTZ7.js";import"./chunk-SZZIYCXK.js";import"./chunk-IDDPWGQE.js";import"./chunk-LSHIR6QM.js";import"./chunk-OPUIFAQS.js";import"./chunk-HYX3EDZS.js";import"./chunk-EGFVGCDG.js";import"./chunk-YFLVGOCJ.js";import"./chunk-VILB5M4X.js";import"./chunk-KKKO6GZ5.js";import"./chunk-FRRKTQNZ.js";import"./chunk-MQ5LJEWV.js";import"./chunk-JDIFYMSA.js";import"./chunk-TNPBYYAX.js";import"./chunk-KCN6OGYG.js";import"./chunk-PF6PRPRO.js";import{a as R}from"./chunk-ZDIWOE4Q.js";import"./chunk-FYD7CMS7.js";import"./chunk-SLUA7ABW.js";import"./chunk-Z7ESO2IN.js";import"./chunk-3VUPVXAV.js";import"./chunk-ZS2AOY44.js";import"./chunk-XVCSRZX4.js";import{a as w}from"./chunk-DSPLGTQI.js";import"./chunk-A5KU4MMN.js";import"./chunk-WPFTSHP2.js";import"./chunk-WOT6VMZA.js";function te(S,e){let i=S.ownerDocument,v=(e.locale??i.documentElement.lang).startsWith("zh"),U=$(i),y=i.createElement("dialog"),E=i.createElement("h2"),h=i.createElement("p"),a=i.createElement("button"),f=i.createElement("button"),P=i.createElement("button");E.textContent=v?"购买状态":"Your purchase",E.style.cssText="margin:0;font-size:20px;line-height:1.3",y.setAttribute("aria-label",E.textContent),y.style.cssText="box-sizing:border-box;width:min(640px,calc(100% - 32px));max-height:calc(100dvh - 32px);padding:24px;border:0;border-radius:16px;background:Canvas;color:CanvasText;font:14px/1.5 system-ui,sans-serif",a.textContent="×",a.setAttribute("aria-label",v?"关闭":"Close"),Z(a,{background:"Canvas",text:"CanvasText"}),h.setAttribute("role","status"),P.textContent=v?"查询状态":"Check status";for(let o of[a,f,P])o.type="button";for(let o of[f,P])o.style.cssText="min-height:44px;padding:8px 14px;margin-inline-end:8px;border:1px solid ButtonBorder;border-radius:8px;font:inherit;cursor:pointer";y.append(E,a,h,f,P);let t=!1,s=!1,p=!1,c=e.initialState;function F(o){if(t)return;c=o;let m=c.actions.includes("continue_checkout"),M=e.allowConfirm&&c.actions.includes("confirm");f.hidden=!m&&!M,f.disabled=P.disabled=s,f.textContent=m?v?"继续付款":"Continue checkout":v?"确认购买":"Confirm purchase",h.textContent=p||c.status==="blocked"?v?"暂时无法确认购买状态。请重试。":"We couldn’t check your purchase. Try again.":c.status==="complete"?v?"购买已处理。":"Your purchase has been processed.":m?v?"可以继续原订单付款。":"You can continue your original checkout.":v?"正在核对购买状态…":"Checking your purchase…"}async function N(o){if(!(t||s)){s=!0,p=!1,F(c);try{await o()}catch(m){t||(p=!0,w(e.onError,m))}finally{s=!1,F(e.client.recovery)}}}let I=()=>N(e.refresh),_=e.client.subscribe(F);function C(){t||(t=!0,e.signal.removeEventListener("abort",C),i.removeEventListener("visibilitychange",x),_(),y.remove(),U(),e.onDismiss())}function x(){i.visibilityState==="visible"&&I()}return a.onclick=C,y.addEventListener("cancel",o=>{o.preventDefault(),C()}),P.onclick=()=>{I()},f.onclick=()=>{N(async()=>{c.actions.includes("continue_checkout")?await e.client.continueCheckout(o=>{if(e.signal.throwIfAborted(),!t)return e.onCheckoutUrl?e.onCheckoutUrl(o):i.defaultView?.location.assign(o)}):e.allowConfirm&&c.actions.includes("confirm")&&await e.client.confirm()})},e.signal.addEventListener("abort",C,{once:!0}),i.addEventListener("visibilitychange",x),F(c),e.loading.present(()=>{t||e.signal.aborted||(S.append(y),y.showModal?y.showModal():y.open=!0,a.focus({preventScroll:!0}))}),{destroy:C,refresh:I,get recovery(){let o=c.purchases.filter(m=>!["native","complete"].includes(m.type));return structuredClone(o.length===1?o[0]:{type:"recover",operationId:null,requestId:null})},async prepareFallback(){return{type:"recover",operationId:null,requestId:null}},async review(){},async exitReview(){},get unappliedDrafts(){return new Map}}}var H=new WeakMap,G=new WeakMap,J=new WeakSet;function pe(S,e){let i=e.prepared,v=()=>{i&&!J.has(i)&&j(i)?.release()},U=H.get(e.client);if(U)return v(),U;let y=t=>({...t,requestId:t.requestId??crypto.randomUUID()}),E=e.allowNewPurchase!==!1&&e.start instanceof Promise?e.start:void 0,h=e.allowNewPurchase===!1||!e.start||e.start instanceof Promise?void 0:y(e.start);h&&i?.state==="ready"&&i.matches(h)&&i.open();let a=i&&(h&&(i.state==="preparing"||["shown","closed"].includes(i.state)&&i.matches(h))||E&&["preparing","ready"].includes(i.state))?i:void 0;a?J.add(a):v();let f=a&&j(a);f?.claim();let P=Promise.resolve().then(async()=>{let t=!1,s,p=0,c,F,N=!1,I=()=>{},_=()=>{},C,x=!1,o=!1,m,M=!1,l=e.signal?AbortSignal.any([e.signal,e.client.identitySignal]):e.client.identitySignal,A=()=>{H.get(e.client)===P&&H.delete(e.client),l.removeEventListener("abort",q),I(),_(),a&&J.delete(a),f?.release()};function K(){if(m)return m;let r=new Promise(b=>m=b);return G.set(e.client,r),r.then(()=>{G.get(e.client)===r&&G.delete(e.client)}),H.get(e.client)===P&&H.delete(e.client),m}let u=B(S,e,"funnel",()=>L(),Y);function q(){L()}function L(r=!1){if(!t){if(t=!0,u.finish("dismissed"),s){s.destroy();return}if(r&&C){let b=K();M=!0,C.then(async d=>{d.mode==="run"&&d.status!=="blocked"&&e.client.controller&&e.client.attempt?.requestId===h?.requestId&&await e.client.close()}).catch(()=>{}).finally(()=>{b(),w(e.onDismiss,null)}),A();return}A(),w(e.onDismiss,null)}}let W={destroy:()=>L(),refresh:()=>s?.refresh()??c??Promise.resolve(),get recovery(){return s?.recovery??{type:"recover",operationId:null,requestId:null}},prepareFallback:()=>s?.prepareFallback()??Promise.resolve({type:"recover",operationId:null,requestId:null}),review:(...r)=>s?.review(...r)??Promise.resolve(),exitReview:(...r)=>s?.exitReview(...r)??Promise.resolve(),get unappliedDrafts(){return s?.unappliedDrafts??new Map}};l.addEventListener("abort",q,{once:!0}),f&&(_=f.onClose(()=>{x?t||K():L(!0)}));try{l.throwIfAborted();let r=e.client.controller?.view?.paywall?.resolution,b=r&&"document"in r?r.document:e.loadingDocument;u.start(!0,h?.locale??e.client.attempt?.locale??b?.screen.strings.defaultLocale,b??null);let d=E?u.wait(E.then(k=>k?y(k):null,()=>null),V):Promise.resolve(h??null);d.catch(()=>{}),a?.state==="shown"?(o=!0,u.present(()=>{})):a&&["preparing","ready"].includes(a.state)&&Promise.all([a.ready,d.catch(()=>null)]).then(([k,n])=>{if(k){if(t||!u.active||!n||!a.matches(n)||!f?.revealable)return f?.release();u.present(()=>{a.open()==="shown"?o=!0:f.release()})}});let D=G.get(e.client);if(D&&await u.wait(D),t)return null;if(l.throwIfAborted(),E){let k=await d;if(t)return null;if(l.throwIfAborted(),!k)return u.finish("skipped"),A(),null;h=k}C=h?e.client.start(h):e.client.refresh();let O=await u.wait(C,V);return t?null:(l.throwIfAborted(),await z(O,u))}catch(r){if(M||m?.(),t)return null;throw u.finish("error",r),A(),w(e.onError,r),r}function re(){p++;let r=s;s=void 0,I(),I=()=>{},r?.destroy(),l.addEventListener("abort",q,{once:!0})}function Q(){if(c)return c;if(t||l.aborted)return Promise.resolve();re(),u=B(S,e,"funnel",()=>L(),Y),u.start(!0,e.client.attempt?.locale);let r=Promise.resolve().then(async()=>{try{let d=await e.client.refresh();!t&&!l.aborted&&await z(d,u)}catch(d){!t&&!l.aborted&&(w(e.onError,d),await z({...e.client.recovery,mode:"blocked",status:"blocked"},u))}});c=r;let b=()=>{c===r&&(c=void 0)};return r.then(b,b),r}async function z(r,b){let d=e.client.controller;if(r.mode==="run"&&r.status!=="blocked"&&d)return ne(d,b);if(r.purchases.length||r.status==="blocked"&&x){let D=++p;return s=te(S,{client:e.client,signal:l,loading:u,locale:e.client.attempt?.locale,onCheckoutUrl:e.onCheckoutUrl,onError:e.onError,refresh:Q,initialState:r,allowConfirm:e.allowNewPurchase!==!1,onDismiss(){D===p&&(t=!0,A(),w(e.onDismiss,null))}}),W}return u.finish("skipped"),A(),(o||x)&&(t=!0,w(e.onDismiss,null)),null}async function ne(r,b){l.removeEventListener("abort",q),x=!0;function d(){!t&&!l.aborted&&!N&&F&&e.client.recovery.status==="complete"&&(N=!0,w(e.onComplete,structuredClone(F)))}function D(n){if(l.throwIfAborted(),t)throw new DOMException("Presentation dismissed","AbortError");return e.onCheckoutUrl?e.onCheckoutUrl(n):S.ownerDocument.defaultView?.location.assign(n)}I(),I=e.client.subscribe(d);let O=++p,k=await ee(S,{...e,prepared:a,client:r,signal:l,checkoutNavigation:"after_confirmation",resumeCheckout:n=>e.client.continueCheckout(D,n),terminateCheckout:e.allowNewPurchase===!1?void 0:n=>e.client.terminateCheckout(n),async onCheckoutUrl(n){if(l.throwIfAborted(),t)throw new DOMException("Presentation dismissed","AbortError");let g=e.client.recovery;if((!g.actions.includes("continue_checkout")||!g.purchases.some(T=>T.type==="checkout"&&T.checkoutUrl===n))&&(g=await e.client.refresh(),l.throwIfAborted(),t))throw new DOMException("Presentation dismissed","AbortError");if(X(g)!==n)throw new R("PURCHASE_PENDING","Checkout differs from the original recovery proof");return D(n)},async resolveOfferId(n){if(l.throwIfAborted(),t)throw new DOMException("Presentation dismissed","AbortError");let g=e.client.attempt;if(!g)throw new R("PURCHASE_PENDING","Read the original Start before selecting an offer");let T=await e.resolveOfferId?.(n,g);if(l.throwIfAborted(),t)throw new DOMException("Presentation dismissed","AbortError");if(e.client.attempt?.requestId!==g.requestId)throw new R("PURCHASE_STORAGE_CONFLICT","The original purchase changed while selecting an offer");return T},async resolveSubscriptionChange(n){l.throwIfAborted();let g=e.client.attempt;if(t||!g)throw new R("PURCHASE_PENDING","Read the original Start before selecting a membership");let T=await e.resolveSubscriptionChange?.(n);if(l.throwIfAborted(),t||e.client.attempt?.requestId!==g.requestId)throw new R("PURCHASE_STORAGE_CONFLICT","The original purchase changed while selecting a membership");return T},onPresentationState(n){O===p&&w(e.onPresentationState,n)},onComplete(n){O===p&&(F=n,d())},onError(n){O===p&&(w(e.onError,n),n instanceof R&&(n.status===401||n.status===409&&n.reason==="STATE_CHANGED"&&n.recovery==="recover_operation")&&!l.aborted&&Q().catch(g=>w(e.onError,g)))},onDismiss(n){O===p&&(t=!0,A(),m?.(),w(e.onDismiss,n))}},b);return O!==p||t||l.aborted?(k.destroy(),t||l.aborted?null:W):(s=k,W)}});return H.set(e.client,P),P}export{pe as showFunnelPurchase};
|