palbase 0.3.1 → 0.3.3

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.
Files changed (38) hide show
  1. package/LICENSE +11 -5
  2. package/dist/ai/index.js +2 -2
  3. package/dist/backend/engine.js +2 -2
  4. package/dist/backend/env.js +1 -1
  5. package/dist/backend/index.js +3 -3
  6. package/dist/backend/stack.js +1 -1
  7. package/dist/backend/test.js +2 -2
  8. package/dist/chunks/{NTMO2LFH.js → 47V66C2X.js} +2 -2
  9. package/dist/chunks/{L6GKX3XI.js → 4AQYBTIN.js} +2 -2
  10. package/dist/chunks/{XNRYSI7A.js → 4YD2XCGF.js} +1 -1
  11. package/dist/chunks/{XOGEEZNP.js → CJCMQ73A.js} +2 -2
  12. package/dist/chunks/{INXQWVHU.js → CZQ7KIRM.js} +2 -2
  13. package/dist/chunks/{TV7W53F2.js → IXHR57QC.js} +2 -2
  14. package/dist/chunks/{4UPL27ED.js → M5B52IE6.js} +1 -1
  15. package/dist/chunks/{6FQGUDBD.js → NK54UVDI.js} +2 -2
  16. package/dist/chunks/{4MOCDBZP.js → OKZJIY6F.js} +1 -1
  17. package/dist/chunks/{JF7KZUPL.js → P5JIZEPB.js} +2 -2
  18. package/dist/chunks/PB7UKHCY.js +2 -0
  19. package/dist/chunks/{VTNEPJRV.js → PRM2UXWG.js} +1 -1
  20. package/dist/chunks/TJ5SQTW5.js +92 -0
  21. package/dist/chunks/{MJPUCGXY.js → UXRIXHHY.js} +2 -2
  22. package/dist/chunks/{4K4MKD2J.js → YWOS5WH2.js} +2 -2
  23. package/dist/cli.js +153 -132
  24. package/dist/refuse/ai.js +1 -1
  25. package/dist/refuse/backend.js +1 -1
  26. package/dist/refuse/server.js +1 -1
  27. package/dist/server/index.js +2 -2
  28. package/dist/server/testing.js +2 -2
  29. package/dist/web/index.js +2 -2
  30. package/dist/web/palbe.js +2 -2
  31. package/dist/web/paywall.js +2 -2
  32. package/dist/web/vite.js +2 -2
  33. package/package.json +6 -6
  34. package/types/internal/src/modules/purchases.d.ts +77 -4
  35. package/types/internal/src/modules/storage.d.ts +3 -2
  36. package/types/server/src/auth/jwt.d.ts +4 -1
  37. package/dist/chunks/2YUVLZLK.js +0 -87
  38. package/dist/chunks/FVIHTHHV.js +0 -2
@@ -1,87 +0,0 @@
1
- /*! palbase 0.3.1 — Palbase SDK License (see LICENSE) */
2
- import{b as oe}from"./MJPUCGXY.js";var Ht=s=>[...new Uint8Array(s)].map(t=>t.toString(16).padStart(2,"0")).join(""),Nt=s=>`pw-font-${s}`;function ie(s){return(typeof s=="string"?/^asset:([0-9a-f-]{36})$/.exec(s):null)?.[1]}async function Xe(s,t={}){let n={},r=t.fetch??((p,a)=>globalThis.fetch(p,a));return await Promise.all(s.map(async p=>{try{if(!/^https:\/\//.test(p.url))return;let a=await r(p.url,{signal:t.signal,credentials:"omit"});if(!a.ok)return;let f=await a.arrayBuffer();if(f.byteLength!==p.bytes&&p.bytes>0||Ht(await globalThis.crypto.subtle.digest("SHA-256",f))!==p.sha256.toLowerCase())return;let g=Dt(p.kind,new Uint8Array(f));if(g===void 0)return;let h=await It(p,f,g,t);h&&(n[p.id]=h)}catch{}})),n}var F=(s,t,n=0)=>s.length>=n+t.length&&t.every((r,p)=>s[n+p]===r),q=s=>[...s].map(t=>t.charCodeAt(0));function Dt(s,t){switch(s){case"image":return F(t,[137,80,78,71,13,10,26,10])?"image/png":F(t,[255,216,255])?"image/jpeg":F(t,q("RIFF"))&&F(t,q("WEBP"),8)?"image/webp":void 0;case"video":return F(t,q("ftyp"),4)?F(t,q("qt "),8)?"video/quicktime":"video/mp4":F(t,[26,69,223,163])?"video/webm":void 0;case"font":return F(t,q("wOF2"))?"font/woff2":F(t,q("wOFF"))?"font/woff":F(t,q("OTTO"))?"font/otf":F(t,[0,1,0,0])||F(t,q("true"))?"font/ttf":void 0;case"html":return F(t,[80,75,3,4])||F(t,[80,75,5,6])?"application/zip":void 0;default:return}}async function It(s,t,n,r){switch(s.kind){case"image":case"video":return{kind:s.kind,url:URL.createObjectURL(new Blob([t],{type:n}))};case"font":{let p=Nt(s.id),a=globalThis.FontFace,f=r.fonts??globalThis.document?.fonts;if(!a||!f)return;let y=new a(p,t,{display:"block"});return await y.load(),f.add(y),{kind:"font",url:"",family:p}}case"html":{let p=await Jt(new Uint8Array(t)),a=qt(p);return a===void 0?void 0:{kind:"html",url:"",html:a}}}}async function Jt(s){let t=new DataView(s.buffer,s.byteOffset,s.byteLength),n=-1;for(let y=s.length-22;y>=Math.max(0,s.length-22-65535);y--)if(t.getUint32(y,!0)===101010256){n=y;break}if(n<0)throw new Error("not a zip");let r=t.getUint16(n+10,!0),p=t.getUint32(n+16,!0),a=new Map,f=0;for(let y=0;y<r;y++){if(t.getUint32(p,!0)!==33639248)throw new Error("a broken zip");let g=t.getUint16(p+10,!0),h=t.getUint32(p+20,!0),w=t.getUint32(p+24,!0),v=t.getUint16(p+28,!0),M=t.getUint16(p+30,!0),k=t.getUint16(p+32,!0),S=t.getUint32(p+42,!0),b=new TextDecoder().decode(s.subarray(p+46,p+46+v));if(p+=46+v+M+k,b.endsWith("/"))continue;if(b.startsWith("/")||b.split("/").includes(".."))throw new Error("a path leaving the zip");if(f+=w,a.size>=200||f>20971520)throw new Error("a zip too large");let T=S+30+t.getUint16(S+26,!0)+t.getUint16(S+28,!0),C=s.subarray(T,T+h);if(g===0)a.set(b,C);else if(g===8)a.set(b,await Ut(C));else throw new Error("a zip entry compressed another way")}return a}async function Ut(s){let t=new Response(new Uint8Array(s)).body.pipeThrough(new DecompressionStream("deflate-raw"));return new Uint8Array(await new Response(t).arrayBuffer())}var Vt={html:"text/html",css:"text/css",js:"text/javascript",mjs:"text/javascript",json:"application/json",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",webp:"image/webp",gif:"image/gif",svg:"image/svg+xml",mp4:"video/mp4",webm:"video/webm",woff2:"font/woff2",woff:"font/woff",ttf:"font/ttf",otf:"font/otf"};function Ke(s,t){let n=Vt[s.split(".").pop()?.toLowerCase()??""]??"application/octet-stream",r="";for(let p=0;p<t.length;p+=32768)r+=String.fromCharCode(...t.subarray(p,p+32768));return`data:${n};base64,${btoa(r)}`}var Bt="default-src 'none'; img-src data:; media-src data:; font-src data:; style-src 'unsafe-inline' data:; script-src 'unsafe-inline' data:";function qt(s){let t=s.get("index.html");if(!t)return;let n=new TextDecoder().decode(t),r=h=>new TextDecoder().decode(s.get(h)),p=h=>{let w=h.replace(/^\.\//,"").split(/[?#]/)[0];return s.has(w)?w:void 0},a=h=>h.replace(/url\(\s*(['"]?)([^'")]+)\1\s*\)/g,(w,v,M)=>{let k=p(M);return k?`url("${Ke(k,s.get(k))}")`:w}),f=globalThis.DOMParser;if(!f)return;let y=new f().parseFromString(n,"text/html");for(let h of[...y.querySelectorAll('link[rel~="stylesheet"][href]')]){let w=p(h.getAttribute("href")),v=y.createElement("style");v.textContent=w?a(r(w)):"",h.replaceWith(v)}for(let h of[...y.querySelectorAll("style")])h.textContent=a(h.textContent??"");for(let h of[...y.querySelectorAll("[src], [href], [poster]")])for(let w of["src","href","poster"]){let v=h.getAttribute(w);if(v===null)continue;let M=p(v);M?h.setAttribute(w,Ke(M,s.get(M))):/^(https?:)?\/\//i.test(v)&&h.removeAttribute(w)}for(let h of[...y.querySelectorAll("[style]")])h.setAttribute("style",a(h.getAttribute("style")??""));let g=y.createElement("meta");return g.setAttribute("http-equiv","Content-Security-Policy"),g.setAttribute("content",Bt),y.head.prepend(g),`<!doctype html>${y.documentElement.outerHTML}`}var Ye=20,Ge=2048,Ze=256,Wt=/^[A-Za-z][A-Za-z0-9_.-]{0,39}$/,Q=s=>new oe({op:"GetPlacementPaywall",status:0,code:"invalid_attributes",message:s});function Kt(s){let t='"';for(let n=0;n<s.length;n++){let r=s.charCodeAt(n);r===34?t+='\\"':r===92?t+="\\\\":r>=32&&r<=126?t+=s[n]:t+=`\\u${r.toString(16).padStart(4,"0")}`}return`${t}"`}function Qe(s){let t=Object.keys(s??{}).sort((p,a)=>p<a?-1:p>a?1:0);if(t.length===0)return;if(t.length>Ye)throw Q(`${t.length} attributes: at most ${Ye}`);let n=[];for(let p of t){if(!Wt.test(p))throw Q(`the attribute ${JSON.stringify(p)}: a key is a letter, then letters, digits and _ . -, at most 40`);let a=s[p],f;if(typeof a=="string"){if(new TextEncoder().encode(a).length>Ze)throw Q(`the attribute ${JSON.stringify(p)} is over ${Ze} bytes`);f=Kt(a)}else if(typeof a=="number"){if(!Number.isFinite(a))throw Q(`the attribute ${JSON.stringify(p)} is no number`);f=String(Object.is(a,-0)?0:a)}else if(typeof a=="boolean")f=a?"true":"false";else throw Q(`the attribute ${JSON.stringify(p)}: a value is a text, a number or a boolean`);n.push(`"${p}":${f}`)}let r=`{${n.join(",")}}`;if(r.length>Ge)throw Q(`the attributes are ${r.length} bytes: at most ${Ge}`);return r}function _e(s){let t=/^P(\d+)([DWMY])$/.exec(s??"");if(!t)return null;let n=Number(t[1]);if(!Number.isSafeInteger(n)||n<1)return null;switch(t[2]){case"D":return{count:n,unit:"day",months:n*12/365};case"W":return{count:n,unit:"week",months:n*12/52};case"M":return{count:n,unit:"month",months:n};default:return{count:n,unit:"year",months:n*12}}}function et(s){try{return new Intl.NumberFormat("en",{style:"currency",currency:s}).resolvedOptions().maximumFractionDigits??2}catch{return 2}}function tt(s,t,n){let r=s/10**et(t);try{return new Intl.NumberFormat(n,{style:"currency",currency:t}).format(r)}catch{return`${r.toFixed(et(t))} ${t}`}}function Xt(s,t){try{let n=new Intl.NumberFormat(t,{style:"unit",unit:s.unit,unitDisplay:"long"});return s.count>1?n.format(s.count):n.formatToParts(1).filter(p=>p.type==="unit").map(p=>p.value).join("").trim()||n.format(1)}catch{return s.count>1?`${s.count} ${s.unit}s`:s.unit}}var Yt={en:s=>`${s} free`,tr:s=>`${s} \xFCcretsiz`,de:s=>`${s} kostenlos`,es:s=>`${s} gratis`,it:s=>`${s} gratis`,nl:s=>`${s} gratis`,pt:s=>`${s} gr\xE1tis`,sv:s=>`${s} gratis`,da:s=>`${s} gratis`,nb:s=>`${s} gratis`};function Gt(s,t){let n;try{n=new Intl.NumberFormat(t,{style:"unit",unit:s.unit,unitDisplay:"long"}).format(s.count)}catch{n=`${s.count} ${s.unit}${s.count>1?"s":""}`}let r=Yt[t.split("-")[0].toLowerCase()];return r?r(n):n}function Zt(s,t){try{return new Intl.NumberFormat(t,{style:"percent",maximumFractionDigits:0}).format(s)}catch{return`${Math.round(s*100)}%`}}function nt(s,t){let n=new Map,r=new Map;for(let a of s){let f=_e(a.period);if(!f)continue;let y=a.price.amount/f.months;n.set(a.key,y),r.set(a.price.currency,Math.max(r.get(a.price.currency)??0,y))}let p={};for(let a of s){let f={product_name:a.productName,price:tt(a.price.amount,a.price.currency,t)},y=_e(a.period);if(y){f.period=Xt(y,t),f.price_per_month=tt(Math.round(n.get(a.key)),a.price.currency,t);let h=r.get(a.price.currency)??0,w=h>0?Math.floor((1-n.get(a.key)/h)*100)/100:0;w>=.01&&(f.savings=Zt(w,t))}let g=a.intro?.mode==="free_trial"?_e(a.intro.duration):null;g&&(f.trial=Gt(g,t)),p[a.key]=f}return p}var W=(s,t,n)=>`M${s-n} ${t}a${n} ${n} 0 1 0 ${2*n} 0a${n} ${n} 0 1 0 ${-2*n} 0`,ue={ad_free:["M3 7h18v10H3z","M4 4l16 16"],bell:["M6 16v-5a6 6 0 0 1 12 0v5l2 2H4z","M10 21a2 2 0 0 0 4 0"],bolt:["M13 2L4 14h7l-1 8 9-12h-7z"],book:["M5 4h11a3 3 0 0 1 3 3v13H8a3 3 0 0 1-3-3z","M5 17a3 3 0 0 1 3-3h11"],chart:["M3 20h18","M6 20v-8","M11 20V5","M16 20v-6","M21 20V9"],chat:["M4 5h16v11H9l-5 4z"],check:["M5 12l5 5 9-10"],check_circle:[W(12,12,9),"M8 12l3 3 5-6"],clock:[W(12,12,9),"M12 7v5l3 2"],cloud:["M7 18a4 4 0 0 1-.5-7.97A6 6 0 0 1 18 9a4.5 4.5 0 0 1-.5 9z"],crown:["M3 8l4 4 5-7 5 7 4-4-2 11H5z"],download:["M12 4v11","M7 10l5 5 5-5","M4 20h16"],gift:["M3 9h18v4H3z","M5 13v8h14v-8","M12 9v12","M12 9C10 5 6 5 6 7.5S12 9 12 9zm0 0c2-4 6-4 6-1.5S12 9 12 9z"],globe:[W(12,12,9),"M3 12h18","M12 3a14 14 0 0 1 0 18a14 14 0 0 1 0-18z"],heart:["M12 20s-7-4.5-9-9a4.5 4.5 0 0 1 9-3 4.5 4.5 0 0 1 9 3c-2 4.5-9 9-9 9z"],infinity:["M7 9a3 3 0 1 0 0 6c3 0 7-6 10-6a3 3 0 1 1 0 6c-3 0-7-6-10-6z"],lock_open:["M5 11h14v10H5z","M8 11V7a4 4 0 0 1 7.5-2"],music:["M9 18V5l11-2v13",W(6,18,3),W(17,16,3)],people:[W(9,8,3.5),"M2 20a7 7 0 0 1 14 0","M16 4.5a3.5 3.5 0 0 1 0 7","M18 14a6 6 0 0 1 4 6"],person:[W(12,8,4),"M4 21a8 8 0 0 1 16 0"],photo:["M3 5h18v14H3z",W(8.5,9.5,1.5),"M3 17l5-5 4 4 3-3 6 6"],shield:["M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6z"],sparkles:["M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8z","M19 15l.8 2.2L22 18l-2.2.8L19 21l-.8-2.2L16 18l2.2-.8z"],star:["M12 3l2.8 5.7 6.2.9-4.5 4.4 1 6.2L12 17.3l-5.5 2.9 1-6.2L3 9.6l6.2-.9z"],video:["M3 6h12v12H3z","M15 10l6-3v10l-6-3z"],arrow_right:["M4 12h15","M13 6l6 6-6 6"],calendar:["M4 6h16v15H4z","M4 10h16","M8 3v5","M16 3v5"],close:["M6 6l12 12","M18 6L6 18"],lock:["M5 11h14v10H5z","M8 11V7a4 4 0 0 1 8 0v4"],play:["M7 4l13 8-13 8z"],quote:["M5 17c3 0 4-2 4-5V7H4v5h3","M15 17c3 0 4-2 4-5V7h-5v5h3"],trophy:["M7 4h10v5a5 5 0 0 1-10 0z","M7 6H4v2a3 3 0 0 0 3 3","M17 6h3v2a3 3 0 0 1-3 3","M12 14v4","M8 21h8","M9 18h6v3H9z"]};var st="http://www.w3.org/2000/svg";function fe(s,t,n){let r=s.createElementNS(st,"svg");r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("width",String(n)),r.setAttribute("height",String(n)),r.setAttribute("fill","none"),r.setAttribute("stroke","currentColor"),r.setAttribute("stroke-width","2"),r.setAttribute("stroke-linecap","round"),r.setAttribute("stroke-linejoin","round"),r.setAttribute("aria-hidden","true"),r.setAttribute("focusable","false");for(let p of t){let a=s.createElementNS(st,"path");a.setAttribute("d",p),r.append(a)}return r}var he=2,m=(s,t=!1)=>({kind:"value",value:"plain",def:s,required:t}),N=s=>({kind:"value",value:"color",def:s}),rt=s=>({kind:"value",value:"spacing",def:s}),Qt=s=>({kind:"value",value:"radius",def:s}),Y=(s=!1)=>({kind:"text",required:s}),Ee=(s,t=!1)=>({kind:"list",item:s,required:t}),ae=(s,t=!1)=>({kind:"object",item:s,required:t}),ot=(s=!1)=>({kind:"component",required:s}),Le={kind:"components"},it={stack:{axis:m("vertical"),spacing:rt(0),align:m("center"),distribution:m("start"),scroll:m(!1),children:Le},text:{text:Y(),spans:Ee("span"),font:m(),size:m(),weight:m(),line_height:m(),letter_spacing:m(),color:{kind:"value",value:"textColor",def:"text"},align:m("center"),max_lines:m(),uppercase:m(!1)},image:{src:m(void 0,!0),fit:m("fit"),aspect:m(),mask:ae("mask"),overlay:{kind:"value",value:"textColor"},alt:Y(),decorative:m(!1)},icon:{name:m(void 0,!0),color:N("accent"),size:m(24)},video:{src:m(void 0,!0),poster:m(),autoplay:m(!0),loop:m(!0),mute:m(!0),controls:m(!1),fit:m("fill"),aspect:m(),alt:Y()},button:{action:ae("action",!0),content:ot(!0)},purchase_button:{content:ot(!0),package:m()},package:{product:m(void 0,!0),plan:m(void 0,!0),selected:m(!1),children:Le},tabs:{},switch:{},carousel:{pages:Le,peek:m(0),spacing:m(8),loop:m(!1),auto_advance_ms:m(),indicator:ae("indicator"),height:m("")},countdown:{},timeline:{items:Ee("timeline_item",!0),line_color:N("accent"),line_width:m(2),icon_color:N("on_accent"),color:N("text"),spacing:m(16)},features:{items:Ee("feature",!0),icon_color:N("accent"),color:N("text"),spacing:m(12)},spacer:{size:rt()},divider:{color:N("muted"),thickness:m(1)},custom_html:{src:m(void 0,!0),height:m("",!0)}},ee={style:{padding:{kind:"edges"},margin:{kind:"edges"},width:m(""),height:m(""),max_width:m(),background:{kind:"fill"},border:ae("border"),corners:{kind:"corners"},shadow:ae("shadow"),opacity:m(1)},border:{width:m(),color:N("")},shadow:{color:N(""),radius:m(0),x:m(0),y:m(0)},linear:{type:m(""),angle:m(180),stops:m()},radial:{type:m(""),center_x:m(.5),center_y:m(.5),radius:m(.5),stops:m()},image_fill:{type:m(""),src:m(),fit:m("fill")},video_fill:{type:m(""),src:m(),poster:m(),loop:m(!0)},animation:{type:m(""),duration_ms:m(300),delay_ms:m(0),easing:m("ease_out")},action:{type:m(""),url:m(),sheet:m(),package:m()},mask:{shape:m(""),radius:Qt(0),depth:m(16)},span:{text:Y(!0),bold:m(!1),italic:m(!1),underline:m(!1),strikethrough:m(!1),color:N(""),link:m()},timeline_item:{icon:m(void 0,!0),title:Y(!0),text:Y(),color:N("")},feature:{icon:m(void 0,!0),text:Y(!0)},indicator:{style:m("dots"),color:N("muted"),active_color:N("accent"),size:m(8),spacing:m(6)},typography:{font:m("system"),size:m(),weight:m(400),line_height:m(),letter_spacing:m(0),text_style:m("body")}},en={linear:"linear",radial:"radial",image:"image_fill",video:"video_fill"},tn=["top","bottom","leading","trailing"],nn=["top_leading","top_trailing","bottom_leading","bottom_trailing"],Ln=Object.keys(it),sn=/\{\{\s*([^{}]*?)\s*\}\}/g,te=(s,t)=>typeof s=="object"&&s!==null&&Object.hasOwn(s,t),R=s=>typeof s=="object"&&s!==null&&!Array.isArray(s)?s:{},J=s=>Array.isArray(s)?s:[],X=(s,t)=>s??t;function rn(s){let t=Math.floor(s/86400),n=Math.floor(s%86400/3600),r=Math.floor(s%3600/60),p=s%60,a=y=>String(y).padStart(2,"0");return{countdown:t>0?`${t}d ${a(n)}:${a(r)}:${a(p)}`:n>0?`${n}:${a(r)}:${a(p)}`:`${a(r)}:${a(p)}`,days:String(t),hours:a(n),minutes:a(r),seconds:a(p)}}function at(s){let t=[],n=p=>{if(Array.isArray(p))return p.forEach(n);if(typeof p!="object"||p===null)return;let a=p;if(a.type==="package"&&typeof a.product=="string"&&typeof a.plan=="string"){let f=`${a.product}.${a.plan}`;t.includes(f)||t.push(f)}for(let f of Object.keys(a).sort())n(a[f])},r=s;for(let p of["header","root","footer"])n(r[p]);for(let p of Object.keys(R(r.sheets)).sort())n(R(R(r.sheets)[p]).root);return t}function $n(s,t){return new ge(s,t).resolve().tree}function lt(s,t){return new ge(s,t).resolve()}var ge=class{d;opts;lang;texts={};palette;typography={};radii;spacing;packages;selected="";tab="";paths=new WeakMap;tabsShown={};switchesOn={};countdowns={};constructor(t,n){this.d=t,this.opts=n,this.packages=n.packages;let r=R(this.d.locales),p=String(this.d.default_locale??""),a=n.locale;te(r,a)||(a=a.split("-")[0]??"",te(r,a)||(a=p)),this.lang=a;for(let y of[p,a])for(let[g,h]of Object.entries(R(r[y])))typeof h=="string"&&(this.texts[g]=h);let f=R(this.d.theme);this.palette=R(R(f.colors)[n.appearance]);for(let[y,g]of Object.entries(R(f.typography))){let h={};for(let[w,v]of Object.entries(ee.typography)){let M=X(R(g)[w],v.def);M!=null&&(h[w]=M)}this.typography[y]=h}this.radii=R(f.radii),this.spacing=R(f.spacing)}resolve(){let[t,n]=this.initialState();this.tab=t,this.selected=n;let r={selected:n,theme:{colors:this.palette,typography:this.typography,radii:this.radii,spacing:this.spacing}};for(let a of["header","root","footer"]){let f=this.d[a];if(typeof f=="object"&&f!==null){let y=this.component(R(f),a,"",!1);y&&(r[a]=y)}}let p={};if(typeof this.d.sheets=="object"&&this.d.sheets!==null){let a={};for(let[f,y]of Object.entries(R(this.d.sheets))){let g=this.component(R(R(y).root),`sheets.${f}.root`,"",!1);g&&(a[f]=g);let h=this.text(R(y).title,this.packages[this.selected]);h!==null&&(p[f]=h)}r.sheets=a}return{tree:r,pathOf:a=>this.paths.get(a),tabs:this.tabsShown,switches:this.switchesOn,sheetTitles:p,countdowns:this.countdowns,language:this.lang}}switchOn(t,n){return this.opts.switches&&Object.hasOwn(this.opts.switches,n)?this.opts.switches[n]:this.opts.switch?this.opts.switch==="on":t.default===!0}tabShown(t,n){let p=J(t.tabs).map(R).map(f=>String(f.id)),a=this.opts.tabs?.[n];return a!==void 0&&p.includes(a)?a:this.opts.tab?this.opts.tab:typeof t.default=="string"&&t.default!==""?t.default:p[0]??""}initialState(){let t="",n="",r="",p="",a=(y,g)=>{if(Array.isArray(y)){y.forEach((w,v)=>a(w,`${g}[${v}]`));return}if(typeof y!="object"||y===null)return;let h=y;switch(h.type){case"package":{let w=`${h.product}.${h.plan}`;r===""&&(r=w),h.selected===!0&&n===""&&(n=w);break}case"switch":{let w=this.switchOn(h,g),v=w?h.on_package:h.off_package;typeof v=="string"&&p===""&&(p=v),a(w?h.on:h.off,`${g}.${w?"on":"off"}`);return}case"tabs":{let w=this.tabShown(h,g);t===""&&(t=w),J(h.tabs).forEach((v,M)=>{let k=R(v);k.id===w&&(typeof k.package=="string"&&p===""&&(p=k.package),a(k.content,`${g}.tabs[${M}].content`))});return}}for(let w of Object.keys(h).sort())w!=="sheets"&&a(h[w],g===""?w:`${g}.${w}`)};for(let y of["header","root","footer"])a(this.d[y],y);let f=this.opts.selected||p||n||r;return[t,f]}holds(t,n){let r=n||this.selected;for(let[p,a]of Object.entries(t))switch(p){case"selected_package":if(!J(a).includes(this.selected))return!1;break;case"intro_eligible":if((this.opts.eligible??[]).includes(r)!==a)return!1;break;case"platform":if(!J(a).includes(this.opts.platform))return!1;break;case"locale":if(!J(a).includes(this.opts.locale)&&!J(a).includes(this.lang))return!1;break;case"appearance":if(a!==this.opts.appearance)return!1;break;case"tab":if(a!==this.tab)return!1;break}return!0}component(t,n,r,p){if(typeof t.visible=="object"&&t.visible!==null&&!this.holds(R(t.visible),r))return null;let a=String(t.type),f=r,y=p;a==="package"&&(f=`${t.product}.${t.plan}`,y=f===this.selected);let g={type:a};this.paths.set(g,n),te(t,"id")&&(g.id=t.id);let h={...R(t.style)};y&&Object.assign(h,R(R(t.states).selected)),Object.keys(h).length>0&&(g.style=this.style(h)),typeof t.animation=="object"&&t.animation!==null&&(g.animation=this.defaults(R(t.animation),ee.animation));let w=this.packages[f||this.selected];switch(a){case"tabs":return this.tabs(t,g,n,f);case"switch":return this.switchOf(t,g,n,f,y);case"countdown":return this.countdown(t,g,n,f,y);case"purchase_button":{let v=typeof t.package=="string"?t.package:this.selected;g.package=v;let M=this.component(R(t.content),`${n}.content`,v,y);return M?(g.content=M,g):null}case"package":g.product=t.product,g.plan=t.plan,g.selected=y}for(let[v,M]of Object.entries(it[a]??{})){if(a==="package"&&(v==="product"||v==="plan"||v==="selected"))continue;let k=t[v],S=te(t,v);switch(M.kind){case"component":{if(!S)continue;let b=this.component(R(k),`${n}.${v}`,f,y);if(!b&&M.required)return null;b&&(g[v]=b);break}case"components":{let b=[];J(k).forEach((T,C)=>{let K=this.component(R(T),`${n}.${v}[${C}]`,f,y);K&&b.push(K)}),g[v]=b;break}case"text":{let b=this.text(k,w);if(b!==null)g[v]=b;else if(M.required||a==="text"&&v==="text"&&S)return null;break}case"list":{let b=[];for(let T of J(k)){let C=this.item(M.item,R(T),w);C&&b.push(C)}if(a==="text"&&b.length===0&&S)return null;S&&(g[v]=b);break}case"object":{S?g[v]=this.object(R(k),M.item,w):v==="indicator"&&(g[v]=this.object({},M.item,w));break}case"value":{let b=this.value(X(k,M.def),M);b!=null&&b!==""&&(g[v]=b);break}}}return a==="text"&&this.typeStyle(g),g}typeStyle(t){if(typeof t.size!="string"){t.size!==void 0&&t.size!==null&&(t.text_style="body");return}let n=this.typography[t.size];for(let r of["font","weight","line_height","letter_spacing","text_style"])!te(t,r)&&n?.[r]!==void 0&&n?.[r]!==null&&(t[r]=n[r]);t.size=n?.size??null}tabs(t,n,r,p){let a=this.tabShown(t,r);this.tabsShown[r]=a;let f=[];return J(t.tabs).forEach((y,g)=>{let h=R(y),w=h.id===a,v=this.component(R(h.label),`${r}.tabs[${g}].label`,p,w);if(f.push({id:h.id,selected:w,label:v}),w){let M=this.component(R(h.content),`${r}.tabs[${g}].content`,p,!1);M&&(n.content=M)}}),n.tabs=f,typeof t.bar=="object"&&t.bar!==null&&(n.bar=this.style(R(t.bar))),n}switchOf(t,n,r,p,a){let f=this.switchOn(t,r);this.switchesOn[r]=f,n.on=f;let y=this.text(t.label,this.packages[p||this.selected]);y!==null&&(n.label=y),n.tint=this.color(String(X(t.tint,"accent")));let g=f?"on":"off",h=this.component(R(t[g]),`${r}.${g}`,p,a);return h&&(n.content=h),n}countdown(t,n,r,p,a){let f=R(t.target),y=this.opts.now??Date.now(),g;if(typeof f.after_open_seconds=="number"?g=Math.trunc(f.after_open_seconds)-(this.opts.openedSecondsAgo??0):g=Math.trunc((Date.parse(String(f.at))-y)/1e3),g>0){n.state="counting",n.remaining_seconds=g,this.countdowns[r]=g;let h=this.packages,w={};for(let[M,k]of Object.entries(h))w[M]={...k,...rn(g)};this.packages=w;let v=this.component(R(t.counting),`${r}.counting`,p,a);return v&&(n.content=v),this.packages=h,n}if(n.state="ended",n.remaining_seconds=0,typeof t.ended=="object"&&t.ended!==null){let h=this.component(R(t.ended),`${r}.ended`,p,a);h&&(n.content=h)}return n}item(t,n,r){let p={};for(let[a,f]of Object.entries(ee[t]??{})){let y=n[a];if(f.kind==="text"){let g=this.text(y,r);if(g!==null)p[a]=g;else if(f.required)return null}else{let g=f.def,h=this.value(X(y,g),f);h!=null&&(te(n,a)||g!=null&&g!=="")&&(p[a]=h)}}return p}object(t,n,r){return n==="style"?this.style(t):this.item(n,t,r)??{}}defaults(t,n){let r={};for(let[p,a]of Object.entries(n)){let f=X(t[p],a.def);f!=null&&f!==""&&(r[p]=f)}return r}style(t){let n={};for(let[r,p]of Object.entries(t)){let a=ee.style[r];if(!a){n[r]=p;continue}switch(a.kind){case"edges":n[r]=this.sides(p,tn,this.spacing);break;case"corners":n[r]=this.sides(p,nn,this.radii);break;case"fill":n[r]=this.fill(p);break;case"object":{let f=R(p),y={};for(let[g,h]of Object.entries(ee[a.item]??{})){let w=X(f[g],h.def);w!=null&&w!==""&&(y[g]=this.value(w,h))}n[r]=y;break}default:n[r]=p}}return n}sides(t,n,r){let p={};for(let a of n){let f=typeof t=="object"&&t!==null?X(R(t)[a],0):t;p[a]=$e(f,r)}return p}fill(t){if(typeof t=="string")return{type:"color",color:this.color(t)};let n=R(t),r=this.defaults(n,ee[en[String(n.type)]??""]??{});return Array.isArray(n.stops)&&(r.stops=n.stops.map(p=>({color:this.color(String(R(p).color)),at:R(p).at}))),r}value(t,n){if(n.kind!=="value")return t;switch(n.value){case"color":return typeof t=="string"&&t!==""?this.color(t):t;case"textColor":return typeof t=="string"?this.color(t):t==null?t:this.fill(t);case"spacing":return $e(t,this.spacing);case"radius":return $e(t,this.radii);default:return t}}color(t){let n=Object.hasOwn(this.palette,t)?this.palette[t]:void 0;return typeof n=="string"?n:t}text(t,n){let r;if(typeof t=="string")r=t;else if(typeof t=="object"&&t!==null&&!Array.isArray(t)){let a=t.t;r=typeof a=="string"&&Object.hasOwn(this.texts,a)?this.texts[a]:""}else return null;let p=!1;return r=r.replace(sn,(a,f)=>{let y=n&&Object.hasOwn(n,f)?n[f]:void 0;return typeof y!="string"||y===""?(p=!0,""):y}),p||r.trim()===""?null:r}};function $e(s,t){return typeof s=="string"?Object.hasOwn(t,s)?t[s]:null:s}var on={packages:"Choose a plan",close:"Close",restore:"Restore purchases",page:(s,t)=>`${s} of ${t}`},ne={system:'-apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',rounded:'ui-rounded, "SF Pro Rounded", Nunito, "Varela Round", system-ui, -apple-system, sans-serif',serif:'ui-serif, "New York", "Iowan Old Style", Georgia, "Times New Roman", serif',mono:'ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace'},an=new Set(["ar","he","fa","ur","ps","yi","dv","ug","ku","sd"]),ct={ease_out:"cubic-bezier(0.16, 1, 0.3, 1)",ease_in_out:"cubic-bezier(0.65, 0, 0.35, 1)",spring:"cubic-bezier(0.34, 1.56, 0.64, 1)"},ln={start:"flex-start",center:"center",end:"flex-end",stretch:"stretch"},cn={start:"flex-start",center:"center",end:"flex-end",space_between:"space-between",space_around:"space-around",space_evenly:"space-evenly"},dn={stack:["children"],package:["children"],button:["content"],purchase_button:["content"],tabs:["tabs","content"],switch:["content"],carousel:["pages"],countdown:["content"]},pn={package:["selected"],purchase_button:["package"],switch:["on"],countdown:["state","remaining_seconds"]},un=`
3
- :host{display:block;height:100%}
4
- .pw2{position:relative;box-sizing:border-box;display:flex;flex-direction:column;height:100%;overflow:hidden;font-family:${ne.system};font-size:1rem;line-height:1.3;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;text-rendering:optimizeLegibility}
5
- .pw2 *,.pw2 *::before,.pw2 *::after{box-sizing:border-box}
6
- .pw2-head,.pw2-foot{flex:none;display:flex;flex-direction:column;position:relative;z-index:1}
7
- .pw2-head[hidden],.pw2-foot[hidden]{display:none}
8
- .pw2{padding-left:env(safe-area-inset-left,0px);padding-right:env(safe-area-inset-right,0px)}
9
- .pw2-head,.pw2-body.pw2-top{padding-top:env(safe-area-inset-top,0px)}
10
- .pw2-foot,.pw2-body.pw2-bottom{padding-bottom:env(safe-area-inset-bottom,0px)}
11
- .pw2-body{flex:1 1 auto;min-height:0;overflow-y:auto;overflow-x:hidden;display:flex;flex-direction:column;overscroll-behavior:contain;scrollbar-width:none}
12
- .pw2-body::-webkit-scrollbar{display:none}
13
- .pw2-body>.pw-c{flex:1 0 auto}
14
- .pw-c{position:relative;min-width:0}
15
- .pw-c[style*="--pw-bw"]{isolation:isolate}
16
- .pw-c[style*="--pw-bw"]::after{content:"";position:absolute;inset:0;border:var(--pw-bw) solid var(--pw-bc);border-radius:inherit;pointer-events:none;z-index:2}
17
- .pw-stack{display:flex;flex-direction:column}
18
- .pw-stack.h{flex-direction:row}
19
- .pw-stack.z{display:grid}
20
- .pw-stack.z>.pw-c{grid-area:1/1}
21
- .pw-stack.scroll{overflow-y:auto;scrollbar-width:none}
22
- .pw-stack.h.scroll{overflow-x:auto;overflow-y:hidden}
23
- .pw-stack.scroll>.pw-c{flex-shrink:0}
24
- .pw-text{margin:0;overflow-wrap:break-word;white-space:pre-line}
25
- /* A text beside others wraps between its words, never inside one: a price stays whole, what is beside it wraps. */
26
- .pw-stack.h>.pw-text{min-width:min-content}
27
- .pw-text a{color:inherit}
28
- .pw-clamp{display:-webkit-box;-webkit-box-orient:vertical;overflow:hidden}
29
- .pw-grad{-webkit-background-clip:text;background-clip:text;color:transparent!important;-webkit-text-fill-color:transparent}
30
- .pw-icon{display:inline-flex;flex:none}
31
- .pw-icon svg{display:block}
32
- .pw-img{overflow:hidden;flex:none}
33
- .pw-img img,.pw-img video{display:block;width:100%;height:100%}
34
- .pw-img.natural img{height:auto}
35
- .pw-overlay{position:absolute;inset:0;pointer-events:none}
36
- .pw-bgvideo{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;z-index:-1;pointer-events:none}
37
- button.pw-c{font:inherit;color:inherit;background:none;border:0;margin:0;padding:0;cursor:pointer;text-align:inherit;display:flex;flex-direction:column;align-items:stretch;justify-content:center;-webkit-tap-highlight-color:transparent;transition:opacity .15s ease,transform .15s ease}
38
- button.pw-c:active{transform:scale(.98)}
39
- button.pw-c:disabled{cursor:default;opacity:.5}
40
- .pw-pkg{cursor:pointer;display:flex;flex-direction:column;transition:background-color .2s ease,border-color .2s ease,box-shadow .2s ease}
41
- .pw-pkg[aria-disabled=true]{cursor:default;opacity:.55}
42
- :focus-visible{outline:2px solid currentColor;outline-offset:2px}
43
- .pw-features{list-style:none;margin:0;padding:0;display:flex;flex-direction:column}
44
- .pw-feature{display:flex;align-items:center;gap:12px;text-align:start}
45
- .pw-timeline{list-style:none;margin:0;padding:0;display:flex;flex-direction:column}
46
- .pw-step{display:grid;grid-template-columns:auto 1fr;column-gap:14px;position:relative;text-align:start}
47
- .pw-dot{width:32px;height:32px;border-radius:50%;display:grid;place-items:center;position:relative;z-index:1}
48
- .pw-line{position:absolute;left:calc(16px - var(--pw-line-w)/2);top:32px;width:var(--pw-line-w);bottom:calc(-1 * var(--pw-gap))}
49
- .pw-step:last-child .pw-line{display:none}
50
- .pw-step-title{font-weight:600}
51
- .pw-step-text{opacity:.72;font-size:.9375rem;margin-top:2px}
52
- .pw-tabs{display:flex;flex-direction:column;gap:12px}
53
- .pw-tablist{display:flex}
54
- .pw-tab{flex:1 1 0;min-width:0;font:inherit;color:inherit;background:none;border:0;margin:0;padding:0;cursor:pointer;display:flex}
55
- .pw-tab>.pw-c{flex:1 1 auto}
56
- .pw-switch{display:flex;flex-direction:column;gap:12px}
57
- .pw-switchcontent{display:flex;flex-direction:column}
58
- .pw-switchrow{display:flex;align-items:center;justify-content:space-between;gap:12px;text-align:start}
59
- .pw-toggle{flex:none;width:51px;height:31px;border-radius:999px;border:0;padding:2px;cursor:pointer;background:var(--pw-off);transition:background-color .2s ease}
60
- .pw-toggle[aria-checked=true]{background:var(--pw-tint)}
61
- .pw-toggle i{display:block;width:27px;height:27px;border-radius:50%;background:#fff;box-shadow:0 2px 4px #0003;transition:transform .2s ease}
62
- .pw-toggle[aria-checked=true] i{transform:translateX(20px)}
63
- .pw-carousel{display:flex;flex-direction:column;gap:12px;min-width:0}
64
- .pw-track{display:flex;overflow-x:auto;scroll-snap-type:x mandatory;scrollbar-width:none;scroll-behavior:smooth;padding-inline:var(--pw-peek);scroll-padding-inline:var(--pw-peek);gap:var(--pw-gap)}
65
- .pw-track::-webkit-scrollbar{display:none}
66
- .pw-track>.pw-c{flex:none;width:100%;scroll-snap-align:center}
67
- .pw-dots{display:flex;justify-content:center;gap:var(--pw-dot-gap)}
68
- .pw-dots button{border:0;padding:0;cursor:pointer;width:var(--pw-dot);height:var(--pw-dot);border-radius:999px;background:var(--pw-dot-c);transition:width .25s ease,background-color .25s ease}
69
- .pw-dots.bars button{width:calc(var(--pw-dot) * 3)}
70
- .pw-dots button[aria-current=true]{background:var(--pw-dot-on)}
71
- .pw-dots.dots button[aria-current=true]{width:calc(var(--pw-dot) * 2.5)}
72
- .pw-html{display:block;width:100%;border:0;pointer-events:none;background:transparent}
73
- .pw-spacer{flex:1 1 0}
74
- .pw-stack:not(.h):not(.z)>.greedy-h,.pw-pkg>.greedy-h,button.pw-c>.greedy-h{align-self:stretch}
75
- .pw-stack.h>.greedy-h{flex:1 1 0}
76
- .pw-stack.z>.greedy-h{justify-self:stretch}
77
- .pw-stack:not(.h):not(.z)>.greedy-v,.pw-pkg>.greedy-v{flex:1 1 auto}
78
- .pw-stack.h>.greedy-v,.pw-stack.z>.greedy-v{align-self:stretch}
79
- .pw-layer{position:absolute;inset:0;z-index:5;display:flex;flex-direction:column;justify-content:flex-end;background:#0007}
80
- .pw-sheet{max-height:92%;overflow-y:auto;border-radius:16px 16px 0 0;display:flex;flex-direction:column;outline:none;padding-bottom:env(safe-area-inset-bottom,0px)}
81
- .pw-sheet>.pw-c{flex:1 0 auto}
82
- .pw-grab{width:36px;height:5px;border-radius:3px;background:currentColor;opacity:.25;margin:8px auto 0;flex:none}
83
- [data-pw-highlight]{outline:2px solid #2E7CF6!important;outline-offset:-1px}
84
- [data-pw-hover]:not([data-pw-highlight]){outline:1px dashed #2E7CF6aa!important;outline-offset:-1px}
85
- .pw-editing button,.pw-editing .pw-pkg,.pw-editing a{cursor:default}
86
- @media (prefers-reduced-motion:reduce){.pw2 *{transition:none!important;scroll-behavior:auto!important}}
87
- `,ye=s=>{if(typeof s!="string"||s.length>2048)return!1;try{let t=new URL(s);return t.protocol==="https:"&&t.hostname!==""&&t.username===""&&t.password===""}catch{return!1}},fn=s=>`${String(s.product)}.${String(s.plan)}`,Te=s=>{let[t,n]=s.split(".");return{product:t??"",plan:n??""}},_=s=>`${Number(s)||0}px`,gn=s=>`${s/16}rem`,hn=0;function dt(s,t,n){let r=s.ownerDocument,p=r.defaultView,a=`pw${++hn}`,f=r.createElement("div");f.setAttribute("data-palbase-paywall",""),f.style.display="block",f.style.height="100%";let y=f.attachShadow({mode:"open"});yn(r,y,un);let g=r.createElement("div");g.className="pw2";let h=r.createElement("div");h.className="pw2-head";let w=r.createElement("div");w.className="pw2-body";let v=r.createElement("div");v.className="pw2-foot";let M=r.createElement("div");g.append(h,w,v),y.append(g),s.replaceChildren(f);let k={...t},S={openedAt:Date.now(),...t.state},b,T=new Map,C=new Map,K=!1,be=null,ve,Oe=r.defaultView?.ResizeObserver,Fe=typeof Oe=="function"?new Oe(()=>xe()):null;Fe?.observe(g);let Ce=()=>xe();r.fonts?.addEventListener?.("loadingdone",Ce);let je=null,ke=p?.matchMedia?.("(prefers-reduced-motion: reduce)"),re=()=>k.reduceMotion??ke?.matches??!1,j=()=>!!n.editor,le={...on,...n.labels};function G(){let e=S.now??Date.now();b=lt(k.definition,{locale:k.locale,appearance:k.appearance,platform:k.platform??"web",packages:k.packages,eligible:k.eligible??[],...S.selected?{selected:S.selected}:{},tabs:S.tabs??{},switches:S.switches??{},openedSecondsAgo:Math.max(0,Math.floor((e-(S.openedAt??e))/1e3)),now:e});let l=b.tree.theme.colors;g.style.background=l.background??"",g.style.color=l.text??"",g.classList.toggle("pw-editing",j()),g.lang=b.language,g.dir=an.has(b.language.split("-")[0]??"")?"rtl":"ltr",C=new Map,Pe(h,b.tree.header,"vertical"),Pe(w,b.tree.root,"vertical"),Pe(v,b.tree.footer,"vertical"),h.hidden=!b.tree.header,v.hidden=!b.tree.footer,w.classList.toggle("pw2-top",!b.tree.header),w.classList.toggle("pw2-bottom",!b.tree.footer),Ft();for(let[i,o]of T)C.has(i)||o.cleanup.forEach(d=>d());T=C,be&&Be(be);for(let i of T.values())i.type==="custom_html"&&Ve(i.el);xe(),clearTimeout(ve),S.now===void 0&&Object.keys(b.countdowns).length>0&&(ve=setTimeout(G,1e3-Date.now()%1e3+5))}function xe(){for(let e of T.values()){if(e.type!=="text")continue;let l=e.el,i=l.dataset.pwFit??l.style.fontSize;if(!i)continue;l.style.fontSize=i;let o=l.parentElement,d=o&&p?p.getComputedStyle(o):null,c=o&&d?o.clientWidth-parseFloat(d.paddingLeft||"0")-parseFloat(d.paddingRight||"0"):1/0,u=Math.min(l.clientWidth,c);if(!/^\S+$/.test(l.textContent??"")||u<=0||l.scrollWidth<=u+.5){delete l.dataset.pwFit;continue}l.dataset.pwFit=i,l.style.fontSize=`calc(${i} * ${Math.max(.6,u/l.scrollWidth).toFixed(3)})`}}function Pe(e,l,i){let o=l?U(l,i,{inControl:!1,inSheet:!1}):null;V(e,o?[o]:[])}function U(e,l,i){let o=b.pathOf(e)??"",d=yt(e),c=T.get(o),u;if(c&&c.type===e.type&&c.key===d&&c.axis===l&&!C.has(o))u=c;else{let P=wt(e,o,l,i);if(!P)return null;u={el:P.el,type:e.type,key:d,styleKey:"",axis:l,slots:P.slots,cleanup:P.cleanup??[]},u.el.classList.add("pw-c"),u.el.dataset.pwPath=o,u.el.dataset.pwType=e.type,e.id&&(u.el.dataset.pwId=e.id),c&&c.cleanup.forEach(L=>L()),Lt(u.el,e)}let x=`${JSON.stringify(e.style??null)}|${l}`;return u.styleKey!==x&&(He(u.el,e,l),u.styleKey=x),C.set(o,u),St(u,e),_t(u,e,i),u.el}function yt(e){let l=new Set(["style",...dn[e.type]??[],...pn[e.type]??[]]),i={};for(let[o,d]of Object.entries(e))l.has(o)||(i[o]=d);return e.type==="tabs"&&(i.tabs=e.tabs.map(o=>o.id)),e.type==="carousel"&&(i.pages=e.pages.length),e.type==="stack"&&(i.greedy=e.children.some(o=>o.type==="spacer"&&typeof o.size!="number")),(e.type==="image"||e.type==="video"||e.type==="custom_html")&&(i.asset=mt(e)),JSON.stringify(i)}function mt(e){let l=ie(e.src);return l?(k.assets?.[l]?.url??k.assets?.[l]?.html?.length??"none").toString():""}function A(e,l){let i=r.createElement(e);return l&&(i.className=l),i}function wt(e,l,i,o){let d=e;switch(e.type){case"stack":{let c=A("div",`pw-stack${d.axis==="horizontal"?" h":d.axis==="z"?" z":""}${d.scroll?" scroll":""}`);return d.axis!=="z"&&d.children.some(u=>u.type==="spacer"&&typeof u.size!="number")&&c.classList.add(d.axis==="horizontal"?"greedy-h":"greedy-v"),c.style.gap=_(d.spacing),d.axis==="z"?c.style.placeItems=d.align==="stretch"?"stretch":String(d.align??"center"):(c.style.alignItems=ln[String(d.align)]??"center",c.style.justifyContent=cn[String(d.distribution)]??"flex-start"),{el:c,slots:{children:c}}}case"text":return{el:bt(d,o),slots:{}};case"icon":{let c=ue[String(d.name)];if(!c)return null;let u=A("span","pw-icon");return u.style.color=String(d.color??""),u.append(fe(r,c,Number(d.size)||24)),u.setAttribute("aria-hidden","true"),{el:u,slots:{}}}case"image":return kt(d);case"video":return xt(d);case"features":{let c=A("ul","pw-features");c.style.gap=_(d.spacing);for(let u of d.items??[]){let x=A("li","pw-feature"),P=ue[u.icon];if(P){let z=fe(r,P,22);z.style.color=String(d.icon_color),z.style.flex="none",x.append(z)}let L=A("span");L.textContent=u.text,L.style.color=String(d.color),x.append(L),c.append(x)}return{el:c,slots:{}}}case"timeline":{let c=A("ol","pw-timeline");c.style.gap=_(d.spacing),c.style.setProperty("--pw-gap",_(d.spacing)),c.style.setProperty("--pw-line-w",_(d.line_width));for(let u of d.items??[]){let x=A("li","pw-step"),P=A("span","pw-dot");P.style.background=u.color??String(d.line_color),P.style.color=String(d.icon_color);let L=ue[u.icon];L&&P.append(fe(r,L,18)),P.setAttribute("aria-hidden","true");let z=A("span","pw-line");z.style.background=String(d.line_color),z.setAttribute("aria-hidden","true");let D=A("span");D.style.color=String(d.color);let B=A("span","pw-step-title");if(B.textContent=u.title,D.append(B),u.text){let $=A("span","pw-step-text");$.style.display="block",$.textContent=u.text,D.append($)}x.append(P,D,z),c.append(x)}return{el:c,slots:{}}}case"spacer":{let c=A("div","pw-spacer");return c.setAttribute("aria-hidden","true"),typeof d.size=="number"&&(c.style.flex="none",i==="horizontal"?c.style.width=_(d.size):c.style.height=_(d.size)),{el:c,slots:{}}}case"divider":{let c=A("div","pw-divider");return c.setAttribute("role","separator"),c.style.background=String(d.color),c.style.alignSelf="stretch",c.style.flex="none",i==="horizontal"?(c.setAttribute("aria-orientation","vertical"),c.style.width=_(d.thickness)):c.style.height=_(d.thickness),{el:c,slots:{}}}case"button":return Pt(d,o);case"purchase_button":{let c=A("button","pw-buy");return c.type="button",c.addEventListener("click",()=>{Je(c,()=>Ot(c.dataset.package??""))}),{el:c,slots:{content:c}}}case"package":{let c=A("div","pw-pkg");return c.setAttribute("role","radio"),c.addEventListener("click",()=>Se(c)),c.addEventListener("keydown",u=>$t(u,c)),{el:c,slots:{children:c}}}case"tabs":return At(d,l);case"switch":return Mt(d,l);case"carousel":return Rt(d);case"countdown":{let c=A("div","pw-countdown");return c.setAttribute("role","timer"),c.setAttribute("aria-live","off"),{el:c,slots:{content:c}}}case"custom_html":{let c=k.assets?.[ie(d.src)??""];if(!c?.html)return null;let u=A("iframe","pw-html");return u.setAttribute("sandbox","allow-scripts"),u.setAttribute("aria-hidden","true"),u.setAttribute("title",""),u.tabIndex=-1,u.srcdoc=c.html,typeof d.height=="number"?u.style.height=_(d.height):typeof d.height=="string"&&d.height.endsWith("%")?u.style.height=d.height:d.height==="fill"&&(u.style.flex="1 1 0"),u.addEventListener("load",()=>Ve(u)),{el:u,slots:{}}}default:return null}}function bt(e,l){let i=String(e.text_style??"body"),o=l.inControl?"span":i==="large_title"?"h1":i==="title"||i==="title2"?"h2":i==="title3"?"h3":"p",d=A(o,"pw-text");if(l.inControl&&(d.style.display="block"),d.style.fontFamily=vt(e.font),d.style.fontSize=typeof e.size=="number"?gn(e.size):"1rem",typeof e.weight=="number"&&(d.style.fontWeight=String(e.weight)),typeof e.line_height=="number"&&(d.style.lineHeight=String(e.line_height)),typeof e.letter_spacing=="number"&&e.letter_spacing!==0&&(d.style.letterSpacing=_(e.letter_spacing)),d.style.textAlign=String(e.align??"center"),e.uppercase===!0&&(d.style.textTransform="uppercase"),typeof e.max_lines=="number"&&(d.classList.add("pw-clamp"),d.style.setProperty("-webkit-line-clamp",String(e.max_lines))),typeof e.color=="string"?d.style.color=e.color:e.color&&typeof e.color=="object"&&(d.classList.add("pw-grad"),d.style.backgroundImage=Me(e.color)??""),Array.isArray(e.spans))for(let c of e.spans){let u=c.link==="terms"?k.links?.terms:c.link==="privacy"?k.links?.privacy:c.link,x=ye(u)&&!l.inControl,P=A(x?"a":"span");P.textContent=String(c.text),c.bold&&(P.style.fontWeight="700"),c.italic&&(P.style.fontStyle="italic");let L=[c.underline?"underline":"",c.strikethrough?"line-through":""].filter(Boolean).join(" ");L&&(P.style.textDecoration=L),typeof c.color=="string"&&c.color!==""&&(P.style.color=c.color),x&&ye(u)&&(P.href=u,P.target="_blank",P.rel="noopener noreferrer",P.addEventListener("click",z=>{j()||!n.onLink||(z.preventDefault(),n.onLink(u))})),d.append(P)}else d.textContent=String(e.text??"");return d}function vt(e){if(typeof e!="string")return ne.system;let l=ie(e);if(l){let i=k.assets?.[l]?.family;return i?`"${i}", ${ne.system}`:ne.system}return ne[e]??ne.system}function Z(e){let l=ie(e);return l?k.assets?.[l]?.url||void 0:ye(e)?e:void 0}function kt(e){let l=A("div","pw-img");typeof e.aspect=="number"&&(l.style.aspectRatio=String(e.aspect));let i=Z(e.src),o=e.mask;if(o?.shape==="circle")l.style.borderRadius="50%";else if(o?.shape==="rect"&&o.radius)l.style.borderRadius=_(o.radius);else if(o?.shape==="convex")l.style.setProperty("border-end-start-radius",`50% ${_(o.depth)}`),l.style.setProperty("border-end-end-radius",`50% ${_(o.depth)}`);else if(o?.shape==="concave"){let d=`radial-gradient(ellipse 50% ${_(o.depth)} at 50% 100%, transparent 98%, #000 100%)`;l.style.setProperty("-webkit-mask-image",d),l.style.setProperty("mask-image",d)}if(i){let d=A("img");d.src=i,d.decoding="async",d.style.objectFit=e.fit==="fill"?"cover":"contain",e.decorative===!0?(d.alt="",l.setAttribute("aria-hidden","true")):d.alt=String(e.alt??""),d.addEventListener("error",()=>d.style.visibility="hidden"),l.append(d)}if(e.overlay&&typeof e.overlay=="object"){let d=A("div","pw-overlay");d.style.backgroundImage=Me(e.overlay)??"",l.append(d)}return{el:l,slots:{}}}function xt(e){let l=A("div","pw-img");typeof e.aspect=="number"&&(l.style.aspectRatio=String(e.aspect));let i=Z(e.src);if(i){let o=A("video");o.src=i;let d=Z(e.poster);d&&(o.poster=d),o.muted=e.mute!==!1,o.loop=e.loop!==!1,o.playsInline=!0,o.controls=e.controls===!0,o.preload="auto",o.style.objectFit=e.fit==="fit"?"contain":"cover",o.autoplay=e.autoplay!==!1&&!re()&&!j(),typeof e.alt=="string"?o.setAttribute("aria-label",e.alt):o.setAttribute("aria-hidden","true"),l.append(o)}return{el:l,slots:{}}}function Pt(e,l){let i=e.action??{},o,d=i.type==="restore"||i.type==="offer_code";switch(i.type){case"close":l.inSheet?o=()=>pe(null):n.onClose&&(o=()=>n.onClose());break;case"restore":n.onRestore&&(o=()=>n.onRestore());break;case"offer_code":n.onOfferCode&&(k.platform??"web")!=="web"&&(o=()=>n.onOfferCode());break;case"open_url":case"terms":case"privacy":{let u=i.type==="open_url"?i.url:i.type==="terms"?k.links?.terms:k.links?.privacy;ye(u)&&(o=()=>n.onLink?n.onLink(u):void p?.open(u,"_blank","noopener,noreferrer"));break}case"sheet":i.sheet&&(o=()=>pe(i.sheet));break;case"select_package":i.package&&(o=()=>Re(i.package));break}if(!o&&!j())return null;let c=A("button");return c.type="button",i.type==="close"&&c.setAttribute("aria-label",le.close),c.addEventListener("click",()=>{!o||j()||(d?Je(c,o):o())}),{el:c,slots:{content:c}}}function At(e,l){let i=A("div","pw-tabs"),o=A("div","pw-tablist");o.setAttribute("role","tablist");let d=A("div","pw-tabpanel");d.setAttribute("role","tabpanel"),d.id=`${a}-${l}-panel`;let c={content:d},u=e.tabs.map(x=>x.id);return u.forEach((x,P)=>{let L=A("button","pw-tab");L.type="button",L.setAttribute("role","tab"),L.id=`${a}-${l}-tab-${P}`,L.setAttribute("aria-controls",d.id),L.dataset.tab=x,L.addEventListener("click",()=>De(l,x)),L.addEventListener("keydown",z=>{let D=z.key==="ArrowRight"?P+1:z.key==="ArrowLeft"?P-1:z.key==="Home"?0:z.key==="End"?u.length-1:-2;if(D===-2)return;z.preventDefault();let B=u[(D+u.length)%u.length];De(l,B),o.querySelector(`[data-tab="${B}"]`)?.focus()}),o.append(L),c[`label:${x}`]=L}),i.append(o,d),c.bar=o,{el:i,slots:c}}function Mt(e,l){let i=A("div","pw-switch"),o=A("div","pw-switchrow"),d=A("span","pw-switchlabel");d.id=`${a}-${l}-label`;let c=A("button","pw-toggle");c.type="button",c.setAttribute("role","switch"),c.setAttribute("aria-labelledby",d.id),c.append(A("i")),c.addEventListener("click",()=>zt(l,c.getAttribute("aria-checked")!=="true")),o.append(d,c);let u=A("div","pw-switchcontent");return i.append(o,u),{el:i,slots:{content:u,label:d,toggle:c}}}function Rt(e){let l=A("div","pw-carousel");l.setAttribute("role","region"),l.setAttribute("aria-roledescription","carousel");let i=A("div","pw-track");i.tabIndex=0,i.style.setProperty("--pw-peek",_(e.peek)),i.style.setProperty("--pw-gap",_(e.spacing)),typeof e.height=="number"&&(i.style.height=_(e.height));let o=e.indicator??{},d=A("div",`pw-dots ${o.style??"dots"}`);d.style.setProperty("--pw-dot",_(o.size??8)),d.style.setProperty("--pw-dot-gap",_(o.spacing??6)),d.style.setProperty("--pw-dot-c",o.color??"#8888"),d.style.setProperty("--pw-dot-on",o.active_color??"currentColor"),o.style==="none"&&(d.hidden=!0),l.append(i,d);let c=()=>[...i.children].filter($=>$ instanceof(p?.HTMLElement??HTMLElement)),u=()=>{let $=c(),H=i.scrollLeft+i.clientWidth/2,O=0;return $.forEach((I,jt)=>{Math.abs(I.offsetLeft+I.offsetWidth/2-H)<Math.abs(($[O]?.offsetLeft??0)+($[O]?.offsetWidth??0)/2-H)&&(O=jt)}),O},x=$=>{let H=c();if(H.length===0)return;let O=e.loop?($+H.length)%H.length:Math.max(0,Math.min(H.length-1,$)),I=H[O];i.scrollTo?.({left:I.offsetLeft-(i.clientWidth-I.offsetWidth)/2,behavior:re()?"auto":"smooth"}),P(O)},P=$=>{[...d.children].forEach((H,O)=>H.setAttribute("aria-current",String(O===$)))};i.addEventListener("scroll",()=>P(u()),{passive:!0}),i.addEventListener("keydown",$=>{$.key!=="ArrowRight"&&$.key!=="ArrowLeft"||($.preventDefault(),x(u()+($.key==="ArrowRight"?1:-1)))});let L=!1,z=()=>L=!0,D=()=>L=!1;l.addEventListener("pointerenter",z),l.addEventListener("pointerleave",D),l.addEventListener("focusin",z),l.addEventListener("focusout",D);let B=[];if(typeof e.auto_advance_ms=="number"){let $=setInterval(()=>{if(L||re()||j())return;let H=c(),O=u();!e.loop&&O>=H.length-1||x(O+1)},e.auto_advance_ms);B.push(()=>clearInterval($))}return l.pwDots=$=>{d.children.length!==$&&(d.replaceChildren(...Array.from({length:$},(H,O)=>{let I=A("button");return I.type="button",I.setAttribute("aria-label",le.page(O+1,$)),I.addEventListener("click",()=>x(O)),I})),P(u()))},{el:l,slots:{pages:i},cleanup:B}}function St(e,l){let i=l;switch(l.type){case"package":{let o=fn(i),c=!!k.packages[o]?.price;e.el.dataset.package=o,e.el.setAttribute("aria-checked",String(i.selected===!0)),e.el.setAttribute("aria-disabled",String(!c));break}case"purchase_button":{let o=String(i.package);e.el.dataset.package=o,e.el.disabled=K||!k.packages[o]?.price;break}case"switch":{let o=e.slots.toggle;o.setAttribute("aria-checked",String(i.on===!0)),o.style.setProperty("--pw-tint",String(i.tint??"")),o.style.setProperty("--pw-off",`color-mix(in srgb, ${b.tree.theme.colors.muted??"#888888"} 45%, transparent)`),e.slots.label.textContent=String(i.label??""),e.slots.label.hidden=i.label===void 0;break}case"tabs":{for(let o of i.tabs){let d=e.slots[`label:${o.id}`];d.setAttribute("aria-selected",String(o.selected)),d.tabIndex=o.selected?0:-1,o.selected&&e.slots.content.setAttribute("aria-labelledby",d.id)}i.bar&&He(e.slots.bar,{type:"stack",style:i.bar},"vertical");break}}}function _t(e,l,i){let o=l,d={...i,inControl:i.inControl||l.type==="button"||l.type==="purchase_button"||l.type==="package"};switch(l.type){case"stack":case"package":{let c=l.type==="stack"?String(o.axis??"vertical"):"vertical",u=o.children.map(P=>[P,U(P,c,d)]).filter(P=>P[1]!==null),x=u.map(P=>P[1]);V(e.slots.children,x),Et(c,u),l.type==="stack"&&ce(e.el,x);break}case"button":case"purchase_button":{let c=o.content?U(o.content,"vertical",d):null;V(e.slots.content,c?[c]:[]);break}case"countdown":case"switch":{let c=o.content?U(o.content,"vertical",d):null;V(e.slots.content,c?[c]:[]),ce(e.slots.content,c?[c]:[]);break}case"tabs":{for(let u of o.tabs){let x=u.label?U(u.label,"vertical",{...d,inControl:!0}):null;V(e.slots[`label:${u.id}`],x?[x]:[])}let c=o.content?U(o.content,"vertical",d):null;V(e.slots.content,c?[c]:[]),ce(e.slots.content,c?[c]:[]);break}case"carousel":{let c=o.pages.map(u=>U(u,"page",d)).filter(Boolean);c.forEach((u,x)=>{u.setAttribute("role","group"),u.setAttribute("aria-roledescription","slide"),u.setAttribute("aria-label",le.page(x+1,c.length))}),V(e.slots.pages,c),ce(e.slots.pages,c),e.el.pwDots?.(c.length);break}}}function Et(e,l){let i=e==="horizontal"?"width":e==="vertical"?"height":null;if(!i)return;let o=u=>u?i==="width"?u.leading+u.trailing:u.top+u.bottom:0,d=l.filter(([u])=>u.style?.[i]==="fill"),c=Math.max(0,...d.map(([u])=>o(u.style?.padding)+o(u.style?.margin)));for(let[u,x]of d)x.style.flexBasis=_(c-o(u.style?.margin))}function ce(e,l){let i=l.filter(d=>d.dataset.pwType==="package");if(i.length===0){e.getAttribute("role")==="radiogroup"&&e.removeAttribute("role");return}e.setAttribute("role","radiogroup"),e.setAttribute("aria-label",le.packages);let o=i.find(d=>d.getAttribute("aria-checked")==="true")??i[0];for(let d of i)d.tabIndex=d===o?0:-1}function V(e,l){let i=()=>[...e.children].filter(d=>d.dataset?.pwPath!==void 0),o=i();for(let d of o)l.includes(d)||d.remove();o=i(),l.forEach((d,c)=>{o[c]!==d&&(e.insertBefore(d,o[c]??null),o=i())})}let Ae=new WeakMap;function E(e,l,i){e.style.setProperty(l,i),Ae.get(e).push(l)}function He(e,l,i){for(let u of Ae.get(e)??[])e.style.removeProperty(u);Ae.set(e,[]);for(let u of[...e.children])u.classList.contains("pw-bgvideo")&&u.remove();let o=l.style;if(l.type==="image"&&e.classList.toggle("natural",typeof l.aspect!="number"&&(o?.height===void 0||o.height==="fit")),!o)return;let d=(u,x)=>{x&&(E(e,`${u}-block-start`,_(x.top)),E(e,`${u}-block-end`,_(x.bottom)),E(e,`${u}-inline-start`,_(x.leading)),E(e,`${u}-inline-end`,_(x.trailing)))};d("padding",o.padding),d("margin",o.margin),Ne(e,"width",o.width,i),Ne(e,"height",o.height,i),typeof o.max_width=="number"&&E(e,"max-width",_(o.max_width));let c=o.background;if(c){if(c.type==="color")E(e,"background-color",c.color);else if(c.type==="linear"||c.type==="radial")E(e,"background-image",Me(c)??"");else if(c.type==="image"){let u=Z(c.src);u&&(E(e,"background-image",`url("${u.replace(/"/g,"%22")}")`),E(e,"background-size",c.fit==="fit"?"contain":"cover"),E(e,"background-position","center"),E(e,"background-repeat","no-repeat"))}else if(c.type==="video"){let u=Z(c.src);if(u){let x=A("video","pw-bgvideo");x.src=u;let P=Z(c.poster);P&&(x.poster=P),x.muted=!0,x.loop=c.loop!==!1,x.playsInline=!0,x.autoplay=!re()&&!j(),x.setAttribute("aria-hidden","true"),E(e,"isolation","isolate"),e.prepend(x)}}}if(o.border&&l.type==="custom_html"?E(e,"border",`${_(o.border.width)} solid ${o.border.color??"transparent"}`):o.border&&(E(e,"--pw-bw",_(o.border.width)),E(e,"--pw-bc",o.border.color??"transparent")),o.corners){let u=o.corners;E(e,"border-start-start-radius",_(u.top_leading)),E(e,"border-start-end-radius",_(u.top_trailing)),E(e,"border-end-start-radius",_(u.bottom_leading)),E(e,"border-end-end-radius",_(u.bottom_trailing)),(l.type==="image"||l.type==="video"||c?.type==="image"||c?.type==="video")&&E(e,"overflow","hidden")}o.shadow&&E(e,"box-shadow",`${_(o.shadow.x)} ${_(o.shadow.y)} ${_(o.shadow.radius)} ${o.shadow.color}`),typeof o.opacity=="number"&&o.opacity!==1&&E(e,"opacity",String(o.opacity))}function Ne(e,l,i,o){if(i==null||i==="")return;if(o==="page"){l==="height"&&E(e,"height",i==="fill"?"100%":typeof i=="number"?_(i):i==="fit"?"fit-content":String(i));return}let d=o==="horizontal"?"width":o==="vertical"?"height":null;i==="fill"?l===d?(E(e,"flex","1 1 0"),E(e,`min-${l}`,"0")):o==="z"?E(e,l,"100%"):(E(e,"align-self","stretch"),E(e,l,"auto")):i==="fit"?(l===d&&E(e,"flex","0 0 auto"),E(e,l,"fit-content")):(E(e,l,typeof i=="number"?_(i):String(i)),l===d&&E(e,"flex","none"))}function Me(e){let l=i=>i.map(o=>`${o.color} ${(o.at*100).toFixed(2)}%`).join(", ");if(e.type==="linear")return`linear-gradient(${e.angle}deg, ${l(e.stops)})`;if(e.type==="radial"){let i=`${(e.radius*100).toFixed(2)}%`;return`radial-gradient(ellipse ${i} ${i} at ${(e.center_x*100).toFixed(2)}% ${(e.center_y*100).toFixed(2)}%, ${l(e.stops)})`}}function Lt(e,l){let i=l.animation;if(!i||k.animate===!1||re()||typeof e.animate!="function")return;let o=24,c={fade:{opacity:0},slide_up:{opacity:0,transform:`translateY(${o}px)`},slide_down:{opacity:0,transform:`translateY(-${o}px)`},slide_leading:{opacity:0,transform:`translateX(-${o}px)`},slide_trailing:{opacity:0,transform:`translateX(${o}px)`},scale:{opacity:0,transform:"scale(0.92)"}}[i.type];c&&e.animate([c,{opacity:1,transform:"none"}],{duration:i.duration_ms,delay:i.delay_ms,easing:ct[i.easing]??ct.ease_out,fill:"backwards"})}function de(){n.onState?.({...S}),G()}function Re(e){S.selected===e&&b.tree.selected===e||(S.selected=e,de(),n.onSelect?.(Te(e)))}function Se(e){j()||e.getAttribute("aria-disabled")==="true"||Re(e.dataset.package??"")}function $t(e,l){if(e.key===" "||e.key==="Enter"){e.preventDefault(),Se(l);return}let i=e.key==="ArrowDown"||e.key==="ArrowRight"?1:e.key==="ArrowUp"||e.key==="ArrowLeft"?-1:0;if(i===0)return;e.preventDefault();let o=l.closest("[role=radiogroup]"),c=(o?[...o.children].filter(P=>P.dataset.pwType==="package"):[l]).filter(P=>P.getAttribute("aria-disabled")!=="true"),u=c.indexOf(l),x=c[(u+i+c.length)%c.length];x&&(Se(x),(T.get(x.dataset.pwPath??"")?.el??x).focus())}function De(e,l){if(j())return;S.tabs={...S.tabs,[e]:l};let i=Tt(e,l);i&&(S.selected=i),de()}function Tt(e,l){return Ie(e)?.tabs?.find(o=>o.id===l)?.package}function zt(e,l){if(j())return;S.switches={...S.switches,[e]:l};let i=Ie(e),o=l?i?.on_package:i?.off_package;o&&(S.selected=o),de()}function Ie(e){let l=k.definition;for(let i of e.match(/[^.[\]]+/g)??[])l=l?.[/^\d+$/.test(i)?Number(i):i];return l}async function Je(e,l){if(!(j()||K)){K=!0,e.disabled=!0,e.setAttribute("aria-busy","true");try{await l()}finally{K=!1,e.removeAttribute("aria-busy"),e.disabled=!1;for(let i of T.values())i.type==="purchase_button"&&(i.el.disabled=!k.packages[i.el.dataset.package??""]?.price)}}}async function Ot(e){k.packages[e]?.price&&await n.onPurchase(Te(e))}function pe(e){j()&&e!==null&&S.sheet===e||(e&&!S.sheet&&(je=y.activeElement??null),S.sheet=e,de(),e||je?.focus())}function Ft(){let e=S.sheet,l=e?b.tree.sheets?.[e]:void 0;if(!l){M.remove();return}M.className="pw-layer";let i=M.firstElementChild;if(!i){i=A("div","pw-sheet"),i.setAttribute("role","dialog"),i.setAttribute("aria-modal","true"),i.tabIndex=-1;let d=A("div","pw-grab");d.setAttribute("aria-hidden","true"),i.append(d),M.append(i),M.addEventListener("click",c=>{c.target===M&&!j()&&pe(null)}),i.addEventListener("keydown",c=>Ct(c,i))}i.style.background=b.tree.theme.colors.background??"",i.setAttribute("aria-label",b.sheetTitles[e]??"");let o=U(l,"vertical",{inControl:!1,inSheet:!0});V(i,o?[o]:[]),M.isConnected||(g.append(M),queueMicrotask(()=>(Ue(i)[0]??i).focus()))}function Ue(e){return[...e.querySelectorAll('button:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')].filter(l=>!l.hidden)}function Ct(e,l){if(e.key==="Escape"){e.preventDefault(),pe(null);return}if(e.key!=="Tab")return;let i=Ue(l);if(i.length===0){e.preventDefault();return}let o=i[0],d=i[i.length-1],c=y.activeElement;e.shiftKey&&c===o?(e.preventDefault(),d.focus()):!e.shiftKey&&c===d&&(e.preventDefault(),o.focus())}function Ve(e){try{e.contentWindow?.postMessage({type:"palbase.paywall",package:b.tree.selected,locale:b.language,appearance:k.appearance},"*")}catch{}}function Be(e){for(let l of y.querySelectorAll("[data-pw-highlight]"))l.removeAttribute("data-pw-highlight");be=e,e&&T.get(e)?.el.setAttribute("data-pw-highlight","")}let qe=e=>e.composedPath().find(l=>l instanceof(p?.HTMLElement??HTMLElement)&&l.dataset.pwPath!==void 0);g.addEventListener("click",e=>{if(!n.editor)return;let l=qe(e);l&&(e.preventDefault(),e.stopPropagation(),n.editor.onPick(l.dataset.pwPath))},!0),g.addEventListener("pointerover",e=>{if(n.editor){for(let l of y.querySelectorAll("[data-pw-hover]"))l.removeAttribute("data-pw-hover");qe(e)?.setAttribute("data-pw-hover","")}}),g.addEventListener("pointerleave",()=>{for(let e of y.querySelectorAll("[data-pw-hover]"))e.removeAttribute("data-pw-hover")});let We=()=>G();return ke?.addEventListener?.("change",We),G(),{get selected(){return Te(b.tree.selected)},get state(){return{...S}},select(e){Re(e)},update(e){k={...k,...e},e.state&&Object.assign(S,e.state),G()},highlight(e){Be(e)},replay(){for(let e of T.values())e.cleanup.forEach(l=>l());T=new Map;for(let e of[h,w,v])e.replaceChildren();G()},destroy(){clearTimeout(ve),Fe?.disconnect(),r.fonts?.removeEventListener?.("loadingdone",Ce),ke?.removeEventListener?.("change",We);for(let e of T.values())e.cleanup.forEach(l=>l());f.remove()}}}function yn(s,t,n){let r=s.defaultView;try{if(r&&"adoptedStyleSheets"in t&&typeof r.CSSStyleSheet=="function"){let a=new r.CSSStyleSheet;a.replaceSync(n),t.adoptedStyleSheets=[a];return}}catch{}let p=s.createElement("style");p.textContent=n,t.append(p)}var pt={version:"0.3.1"};var ut=`palbase-js/${pt.version}`;var we=class{placement;source;definition;assets;offerings;shown;deps;exposed=!1;constructor(t,n,r,p,a,f,y={}){this.placement=t,this.source=n,this.definition=r,this.assets=y,this.offerings=p,this.shown=a,this.deps=f}packages(t){return nt(vn(this.offerings,at(this.definition),t),t)}render(t,n){let r=n.locale??globalThis.navigator?.language??this.definition.default_locale,p=n.appearance===void 0?wn():void 0,a=this.packages(r),f=dt(t,{definition:this.definition,locale:r,appearance:n.appearance??(p?.matches?"dark":"light"),platform:"web",packages:a,eligible:Object.entries(a).filter(([,h])=>h.trial).map(([h])=>h),links:n.links,assets:this.assets},{onPurchase:async h=>{try{let w=await this.deps.checkout({product:h.product,plan:h.plan,successUrl:n.successUrl,cancelUrl:n.cancelUrl});n.onCheckout?n.onCheckout(w,h):globalThis.location.assign(w)}catch(w){if(!n.onError)throw w;n.onError(w,h)}},onClose:n.onClose,onLink:n.onLink,labels:n.labels}),y=h=>f.update({appearance:h.matches?"dark":"light"});p?.addEventListener?.("change",y),!this.exposed&&this.shown&&(this.exposed=!0,this.deps.expose(this));let g=f.destroy.bind(f);return f.destroy=()=>{p?.removeEventListener?.("change",y),g()},f}};function wn(){try{return globalThis.matchMedia?.("(prefers-color-scheme: dark)")}catch{return}}function bn(s,t){if(!s)return;let n=t.split("-")[0];return s[t]?.name??s[n]?.name??Object.values(s).find(r=>r.name)?.name}function vn(s,t,n){let r=[];for(let p of t){let[a,f]=p.split("."),y=s.products.find(w=>w.key===a),g=y?.channels.web,h=g?.plans.find(w=>w.key===f);!y||!g||!h||r.push({key:p,productName:bn(g.locales,n)??y.key,price:{amount:h.price.amount,currency:h.price.currency},period:h.period,intro:h.intro})}return r}var kn={en:{cta:"Continue",terms:"Terms",privacy:"Privacy"},tr:{cta:"Devam et",terms:"Ko\u015Fullar",privacy:"Gizlilik"},de:{cta:"Weiter",terms:"Bedingungen",privacy:"Datenschutz"},es:{cta:"Continuar",terms:"T\xE9rminos",privacy:"Privacidad"},fr:{cta:"Continuer",terms:"Conditions",privacy:"Confidentialit\xE9"},it:{cta:"Continua",terms:"Termini",privacy:"Privacy"},pt:{cta:"Continuar",terms:"Termos",privacy:"Privacidade"},nl:{cta:"Doorgaan",terms:"Voorwaarden",privacy:"Privacy"},ja:{cta:"\u7D9A\u3051\u308B",terms:"\u5229\u7528\u898F\u7D04",privacy:"\u30D7\u30E9\u30A4\u30D0\u30B7\u30FC"}},ft=s=>({type:"button",action:{type:s},content:{type:"text",text:{t:s},size:"caption",color:"muted"}});function xn(s){let t=s.products.flatMap(n=>(n.channels.web?.plans??[]).map(r=>({product:n.key,plan:r.key}))).slice(0,6);return t.length===0?null:{schema:2,name:"Default",default_locale:"en",locales:kn,theme:{colors:{light:{background:"#FFFFFF",surface:"#F2F2F7",text:"#111114",muted:"#6B6B70",accent:"#111114",on_accent:"#FFFFFF",stroke:"#E5E5EA"},dark:{background:"#000000",surface:"#1C1C1E",text:"#F5F5F7",muted:"#9A9AA0",accent:"#F5F5F7",on_accent:"#000000",stroke:"#2C2C2E"}},typography:{headline:{size:17,weight:600,text_style:"headline"},caption:{size:13,weight:400,text_style:"footnote"}},radii:{card:14},spacing:{sm:8,md:16,lg:24}},root:{type:"stack",spacing:"md",align:"stretch",style:{padding:"lg"},children:[{type:"stack",axis:"horizontal",children:[{type:"spacer"},{type:"button",action:{type:"close"},content:{type:"icon",name:"close",color:"muted",size:22}}]},{type:"spacer"},{type:"stack",spacing:"sm",align:"stretch",children:t.map(({product:n,plan:r})=>({type:"package",product:n,plan:r,style:{padding:"md",corners:"card",background:"surface",border:{width:1,color:"stroke"}},states:{selected:{border:{width:2,color:"accent"}}},children:[{type:"stack",axis:"horizontal",spacing:"sm",children:[{type:"stack",align:"start",spacing:2,children:[{type:"text",text:"{{product_name}}",size:"headline",align:"start"},{type:"text",text:"{{period}}",size:"caption",color:"muted",align:"start"}]},{type:"spacer"},{type:"text",text:"{{price}}",size:"headline"}]}]}))},{type:"purchase_button",style:{padding:"md",corners:"card",background:"accent"},content:{type:"text",text:{t:"cta"},size:"headline",color:"on_accent"}},{type:"stack",axis:"horizontal",spacing:"md",distribution:"center",children:[ft("terms"),ft("privacy")]}]}}}function se(){try{return globalThis.localStorage}catch{return}}function Pn(s){try{let t=se()?.getItem(s);if(!t)return;let n=JSON.parse(t),r=n?.answer;return typeof r!="object"||r===null||typeof r.paywall_id!="string"||typeof r.version!="number"||typeof r.definition!="object"||r.definition===null||typeof r.offerings!="object"||r.definition.schema!==2?void 0:{etag:typeof n.etag=="string"?n.etag:void 0,answer:r}}catch{return}}function me(s,t){try{t?se()?.setItem(s,JSON.stringify(t)):se()?.removeItem(s)}catch{}}var gt=()=>globalThis.crypto?.randomUUID?globalThis.crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,ht;function An(s){let t=`palbase.installation.${s}`;try{let n=se()?.getItem(t);if(n&&/^[A-Za-z0-9._:-]{1,128}$/.test(n))return n;let r=gt();if(se()?.setItem(t,r),se()?.getItem(t)===r)return r}catch{}return ht??=gt(),ht}async function Wn(s,t,n,r,p={}){let{signal:a,fetch:f}=p,y=Qe(p.attributes),g=`palbase.paywall.${t}.${n}`,h=An(t),v={checkout:r,expose:async b=>{if(b.shown)try{let T={paywall_id:b.shown.paywallId,version:b.shown.version,...b.shown.variant!==void 0?{variant:b.shown.variant}:{},...b.shown.ruleId!==void 0?{rule_id:b.shown.ruleId}:{}};await s.recordPaywallExposure({path:{placement:n},headers:{"X-Palbase-Installation":h},body:T})}catch{}}},M=async(b,T)=>new we(n,T,b.definition,b.offerings,{paywallId:b.paywall_id,version:b.version,...b.variant!==void 0?{variant:b.variant}:{},...b.rule_id!==void 0?{ruleId:b.rule_id}:{}},v,await Xe(b.assets??[],{signal:a,...f?{fetch:f}:{}})),k=Pn(g),S;try{S=await s.getPlacementPaywall({path:{placement:n},query:{channel:"web"},headers:{"X-Palbase-Paywall-Schema":2,"X-Palbase-Installation":h,"X-Platform":"web","X-Palbase-SDK":ut,...p.appVersion?{"X-Palbase-Client-Version":p.appVersion}:{},...p.locale?{"Accept-Language":p.locale}:{},...y!==void 0?{"X-Palbase-Attributes":y}:{},...k?.etag?{"If-None-Match":k.etag}:{}},signal:a})}catch(b){if(b instanceof oe&&b.status===404||b instanceof oe&&b.status===400&&b.code.startsWith("invalid_"))return me(g,void 0),ze(s,n,v,a);if(k&&!a?.aborted)return M(k.answer,"cache");throw b}return S.status===200?(me(g,{etag:S.headers.get("etag")??void 0,answer:S.data}),M(S.data,"server")):S.status===304&&k?M(k.answer,"server"):(me(g,void 0),ze(s,n,v,a))}async function ze(s,t,n,r){let p=(await s.getOfferings({query:{channel:"web"},signal:r})).data,a=xn(p);return a?new we(t,"default",a,p,void 0,n):null}export{Nt as a,ie as b,Xe as c,Jt as d,qt as e,Qe as f,_e as g,tt as h,Xt as i,nt as j,ue as k,he as l,Ln as m,rn as n,at as o,$n as p,lt as q,dt as r,we as s,xn as t,Wn as u};
@@ -1,2 +0,0 @@
1
- /*! palbase 0.3.1 — Palbase SDK License (see LICENSE) */
2
- import{a as D}from"./XNRYSI7A.js";import{a as A,b as R,c as b,d as x,e as O,f as j,g as U,h as C,i as L,j as M,k as K,l as $}from"./6FQGUDBD.js";import{a as N,b as I}from"./TV7W53F2.js";import{b as v,d as w}from"./MJPUCGXY.js";var ae=/^pb_[a-z0-9]+_s/;function E(n){if(D())throw new TypeError("palbase/server runs on a server: its secret key never goes into a browser or a mobile app \u2014 apps use palbase/web (or the native SDKs) with the publishable key");if(typeof n.secretKey!="string"||!ae.test(n.secretKey))throw new TypeError("secretKey is the project secret key (pb_<ref>_s\u2026); a publishable key belongs in palbase/web");let e=I(w({baseUrl:n.url,credentials:{secretKey:n.secretKey},fetch:n.fetch,solveProofOfWork:n.solveProofOfWork??!1}),n.retry??N);return{ai:A.client(e),analytics:R.client(e),auth:b.client(e),cache:x.client(e),flags:O.client(e),machines:j.client(e),notify:U.client(e),purchases:C.client(e),realtime:L.client(e),secrets:M.client(e),storage:K.client(e),stores:$.client(e),transport:e,url:new URL(n.url).origin}}var f=class extends Error{code;constructor(e,t){super(t),this.name="WebhookSignatureError",this.code=e}},ue=300,de=/^[0-9]{1,12}$/,le=/^[0-9a-f]{64}$/,W=8,fe=/^whsec_[0-9A-Za-z]{32,}$/,he=1024*1024;async function B(n){if(typeof n.secret!="string"||!fe.test(n.secret))throw new TypeError("secret is the webhook endpoint secret (whsec_\u2026), not an API key");await F(n);let e;try{e=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(z(n.body)))}catch{throw new f("invalid_body","the signed body is not JSON")}if(!be(e))throw new f("invalid_body","the signed body is not a Palbase event (id, type, project_id, created_at, data)");return e}async function F(n){if(typeof n.secret!="string"||n.secret==="")throw new TypeError("secret is the key the request was signed with");let e=z(n.body),{t,v1:r}=H(n),s=await crypto.subtle.importKey("raw",new TextEncoder().encode(n.secret),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),o=new Uint8Array(await crypto.subtle.sign("HMAC",s,we(new TextEncoder().encode(`${t}.`),e))),i=!1;for(let u of r)me(o,ge(u))&&(i=!0);if(!i)throw new f("signature_mismatch","no v1 in Palbase-Signature is this body signed with this secret")}function H(n){let e=n.toleranceSeconds??ue;if(!Number.isFinite(e)||e<0)throw new TypeError(`toleranceSeconds is a number of seconds, 0 or more (got ${String(n.toleranceSeconds)})`);let t=(n.now??Date.now)();if(!Number.isFinite(t))throw new TypeError(`now() returns epoch milliseconds (got ${String(t)})`);let r=n.signature;if(typeof r!="string"||r.trim()==="")throw new f("missing_signature","the request carries no Palbase-Signature header");let s,o=[];for(let i of r.split(",")){let u=i.indexOf("=");if(u<=0)throw new f("malformed_signature","Palbase-Signature is t=<seconds>,v1=<hex>");let c=i.slice(0,u).trim(),a=i.slice(u+1).trim();if(c==="t"){if(s!==void 0||!de.test(a))throw new f("malformed_signature","Palbase-Signature carries one t, in unix seconds");s=a}else if(c==="v1"){if(!le.test(a))throw new f("malformed_signature","a v1 is 64 lowercase hex characters");if(o.length===W)throw new f("malformed_signature",`Palbase-Signature carries at most ${W} v1`);o.push(a)}}if(s===void 0||o.length===0)throw new f("malformed_signature","Palbase-Signature is t=<seconds>,v1=<hex>");if(Math.abs(t/1e3-Number(s))>e)throw new f("stale_timestamp",`the signature's time is more than ${e} s from now: an old delivery sent again is not taken`);return{t:s,v1:o}}async function pe(n,e,t={}){let r=await ye(n,t.maxBytes??he);return B({toleranceSeconds:t.toleranceSeconds,now:t.now,secret:e,signature:n.headers.get("palbase-signature"),body:r})}async function ye(n,e){let t=()=>new f("body_too_large",`the body is larger than ${e} bytes`),r=Number(n.headers.get("content-length")??"NaN");if(Number.isFinite(r)&&r>e)throw t();if(!n.body)return new Uint8Array(0);let s=n.body.getReader(),o=[],i=0;for(;;){let{done:a,value:l}=await s.read();if(a)break;if(i+=l.byteLength,i>e)throw await s.cancel().catch(()=>{}),t();o.push(l)}let u=new Uint8Array(i),c=0;for(let a of o)u.set(a,c),c+=a.byteLength;return u}function z(n){if(typeof n=="string")return new TextEncoder().encode(n);if(n instanceof Uint8Array)return n;if(n instanceof ArrayBuffer)return new Uint8Array(n);throw new TypeError("body is the raw request body (string or bytes): a parsed object is not what was signed \u2014 read the body before any JSON middleware")}function ge(n){let e=new Uint8Array(n.length/2);for(let t=0;t<e.length;t++)e[t]=parseInt(n.slice(t*2,t*2+2),16);return e}function me(n,e){if(n.byteLength!==e.byteLength)return!1;let t=0;for(let r=0;r<n.byteLength;r++)t|=n[r]^e[r];return t===0}function we(n,e){let t=new Uint8Array(n.byteLength+e.byteLength);return t.set(n,0),t.set(e,n.byteLength),t}function be(n){if(typeof n!="object"||n===null)return!1;let e=n;return typeof e.id=="string"&&typeof e.type=="string"&&typeof e.project_id=="string"&&typeof e.created_at=="string"&&"data"in e}var V=60,ke=60,Se=8*1024,ve=1e5;function _(n){let e=n instanceof Uint8Array?n:new Uint8Array(n),t="";for(let r of e)t+=String.fromCharCode(r);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Y(n){let e=n.replace(/[\s=]+/g,"");if(!/^[A-Za-z0-9+/_-]*$/.test(e)||e.length%4===1)return;let t=atob(e.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(e.length/4)*4,"=")),r=new Uint8Array(t.length);for(let s=0;s<t.length;s++)r[s]=t.charCodeAt(s);return r}function J(n){let e=Y(n);if(e)try{let t=JSON.parse(new TextDecoder().decode(e));return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:void 0}catch{return}}var k=class{byKey=new Map;held=0;sweptAt=Number.NEGATIVE_INFINITY;max;constructor(e=ve){this.max=e}spend(e,t){if(t>=e.until)throw new d("proof","the DPoP proof is not taken: it was checked too long ago");let r=this.byKey.get(e.jkt);if(r){this.forgetOld(e.jkt,r,t);let s=r.get(e.jti);if(s!==void 0&&s>t)throw new d("proof","the DPoP proof is not taken: it was used before");s!==void 0&&r.delete(e.jti)&&this.held--}this.held>=this.max&&this.makeRoom(t),r=this.byKey.get(e.jkt),r||(r=new Map,this.byKey.set(e.jkt,r)),r.set(e.jti,e.until),this.held++}forgetOld(e,t,r){for(let[s,o]of t){if(o>r)break;t.delete(s),this.held--}t.size===0&&this.byKey.delete(e)}makeRoom(e){if(e-this.sweptAt>=1e3){this.sweptAt=e;for(let[r,s]of this.byKey){for(let[o,i]of s)i>e||(s.delete(o),this.held--);s.size===0&&this.byKey.delete(r)}this.held=0;for(let r of this.byKey.values())this.held+=r.size}if(this.held<this.max)return;let t=[...this.byKey].sort((r,s)=>s[1].size-r[1].size);for(let[r,s]of t){if(this.held<=this.max*.9)break;this.byKey.delete(r),this.held-=s.size}}};async function Ee(n,e){let t=`{"crv":"P-256","kty":"EC","x":"${n}","y":"${e}"}`;return _(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(t)))}function q(n){try{let e=new URL(n);return e.username!==""||e.password!==""?void 0:`${e.protocol}//${e.host}${e.pathname}`}catch{return}}async function G(n,e,t,r){let s=ie=>{throw new d("proof",`the DPoP proof is not taken: ${ie}`)},o=t.proof;if(!o)return s("there is none (a DPoP-bound token comes with a DPoP header)");if(o.length>Se)return s("it is too long");let i=o.split(".");if(i.length!==3)return s("it is not a JWS of three parts");let u=J(i[0]),c=J(i[1]);if(!u||!c)return s("its header or claims are not base64url JSON");if(u.typ!=="dpop+jwt")return s("its typ is not dpop+jwt");if(u.alg!=="ES256")return s(`it is signed with ${String(u.alg)}; only ES256 is taken`);let a=u.jwk;if(!a||typeof a!="object"||a.kty!=="EC"||a.crv!=="P-256"||typeof a.x!="string"||typeof a.y!="string")return s("its header carries no P-256 public key");if("d"in a)return s("its header carries a private key");if(await Ee(a.x,a.y)!==e)return s("it is signed by a key the token does not name");let l;try{l=await crypto.subtle.importKey("jwk",{kty:"EC",crv:"P-256",x:a.x,y:a.y,ext:!0},{name:"ECDSA",namedCurve:"P-256"},!1,["verify"])}catch{return s("its key is not a P-256 point")}let p=Y(i[2]);if(!p||!await crypto.subtle.verify({name:"ECDSA",hash:"SHA-256"},l,p,new TextEncoder().encode(`${i[0]}.${i[1]}`)).catch(()=>!1))return s("its signature does not verify");if(typeof c.htm!="string"||c.htm.toUpperCase()!==t.method.toUpperCase())return s(`it is for ${String(c.htm)}, not ${t.method}`);let h=typeof c.htu=="string"?q(c.htu):void 0,y=q(t.url);if(!h||!y||h!==y)return s(`it is for ${String(c.htu)}, not ${y??t.url}`);let re=r/1e3;if(typeof c.iat!="number"||Math.abs(c.iat-re)>V)return s("it was not made within a minute of now");let se=_(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(n)));if(c.ath!==se)return s("it is not for this token (ath)");if(typeof c.jti!="string"||c.jti===""||c.jti.length>256)return s("it has no jti (or one longer than 256)");let oe=_(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(c.jti)));return{jkt:e,jti:oe,until:(c.iat+V+ke)*1e3+1}}var d=class extends Error{reason;constructor(e,t){super(t),this.name="TokenError",this.reason=e}},g=class extends Error{constructor(e,t){super(e,t),this.name="AuthUnavailable"}};function _e(n){return async e=>{let t=b.client(w({baseUrl:n.url,credentials:{secretKey:n.secretKey,accessToken:()=>e},fetch:n.fetch}));try{return await t.verifyTokenUser(),!0}catch(r){if(r instanceof v&&r.status===401)return!1;throw r}}}var T={ES256:{kty:"EC",import:{name:"ECDSA",namedCurve:"P-256"},verify:{name:"ECDSA",hash:"SHA-256"}},PS256:{kty:"RSA",import:{name:"RSA-PSS",hash:"SHA-256"},verify:{name:"RSA-PSS",saltLength:32}}},X=60,Te=16*1024,Pe=10*6e4,Ae=5e4,Z=n=>typeof n=="string"&&Object.hasOwn(T,n),P=class{issuer;projectId;fetchImpl;now;maxKeyAgeMs;refetchIntervalMs;fetchTimeoutMs;standing;standingTtlMs;standings=new Map;asking=new Map;keys=new Map;keysUntil=0;lastFetch=Number.NEGATIVE_INFINITY;lastFailure=void 0;inflight=null;seenProofs=new k;constructor(e){let t=new URL(e.issuer);if(t.origin!==e.issuer.replace(/\/$/,""))throw new TypeError(`issuer is the project's origin (https://<ref>.<domain>), not ${e.issuer}`);if(typeof e.projectId!="string"||e.projectId==="")throw new TypeError("projectId is the project id the tokens carry");if(this.issuer=t.origin,this.projectId=e.projectId,this.fetchImpl=e.fetch??globalThis.fetch,this.now=e.now??Date.now,this.maxKeyAgeMs=e.maxKeyAgeMs??60*6e4,this.refetchIntervalMs=e.refetchIntervalMs??3e4,this.fetchTimeoutMs=e.fetchTimeoutMs??5e3,typeof e.standing!="function")throw new TypeError("standing is how the verifier asks whether a token's session stands");this.standing=e.standing,this.standingTtlMs=e.standingTtlMs??15e3}async verify(e,t){if(typeof e!="string"||e.length===0||e.length>Te)throw new d("malformed","the token is not a JWT");let r=e.split(".");if(r.length!==3)throw new d("malformed","the token is not a JWS of three parts");let s=Q(r[0]),o=Q(r[1]);if(!s||!o)throw new d("malformed","the token header or claims are not base64url JSON");let i=s.alg;if(!Z(i))throw new d("algorithm",`the token is signed with ${String(i)}; only ES256 and PS256 are taken`);let u=s.kid;if(typeof u!="string"||u==="")throw new d("malformed","the token header names no kid");let c=await this.key(u);if(!c)throw new d("unknown_key",`no key ${u} in the project's key set`);if(c.alg!==i)throw new d("algorithm",`key ${u} is ${c.alg}, the token says ${i}`);let a=te(r[2]);if(!a)throw new d("malformed","the signature is not base64url");let l=new TextEncoder().encode(`${r[0]}.${r[1]}`);if(!await crypto.subtle.verify(T[c.alg].verify,c.key,a,l).catch(()=>!1))throw new d("signature","the signature does not verify");let m=this.check(o),h=o.cnf,y;if(h!==void 0){if(!t)throw new d("bound","the token is bound to a key (DPoP): it comes with the DPoP scheme and a proof, not as a Bearer");if(typeof h!="object"||h===null||typeof h.jkt!="string"||h.jkt==="")throw new d("bound","the token is bound to a key it does not name (cnf.jkt)");y=await G(e,h.jkt,t,this.now())}else if(t)throw new d("not_bound","the DPoP scheme came with a token bound to no key");if(!await this.stands(e,m.sessionId))throw new d("session_ended","the token's session has ended (signed out, revoked, or its user banned)");return y&&this.seenProofs.spend(y,this.now()),m}async verifyRequest(e){let t=e.headers instanceof Headers?e.headers:xe(e.headers),r=t.get("authorization")??"";if(r==="")return null;let s=/^(bearer|dpop)\s+(\S+)$/i.exec(r);if(!s)throw new d("malformed","the Authorization header is not a Bearer or DPoP token");let o=s[1].toLowerCase()==="dpop",i=new URL(e.url,`http://${t.get("host")??"localhost"}`);return this.verify(s[2],o?{proof:t.get("dpop"),method:e.method,url:ee(t,i)}:void 0)}async stands(e,t){let r=this.now(),s=this.standings.get(t);if(s&&r<s.until)return s.live;let o=this.asking.get(t);o||(o=this.standing(e,t).finally(()=>this.asking.delete(t)),this.asking.set(t,o));let i;try{i=await o}catch(u){throw new g("a session's standing cannot be read now",{cause:u})}return this.standings.delete(t),this.standings.set(t,{live:i,until:this.now()+this.standingTtlMs}),this.standings.size>Ae&&this.standings.delete(this.standings.keys().next().value),i}check(e){if(e.iss!==this.issuer)throw new d("issuer",`the token was issued by ${String(e.iss)}, not this project`);if(!(Array.isArray(e.aud)?e.aud:[e.aud]).includes(this.issuer))throw new d("audience","the token is not meant for this project");if(e.project_id!==this.projectId)throw new d("project","the token names another project");let r=this.now()/1e3;if(typeof e.exp!="number"||e.exp+X<=r)throw new d("expired","the token has expired");if(e.nbf!==void 0&&(typeof e.nbf!="number"||e.nbf-X>r))throw new d("not_yet_valid","the token is not valid yet");if(typeof e.sub!="string"||e.sub===""||typeof e.auth_time!="number")throw new d("not_a_user","the token is not a user's");if(typeof e.session_id!="string"||e.session_id==="")throw new d("not_a_session","the token is no session's");let s=e.custom_claims;if(s!==void 0&&(typeof s!="object"||s===null||s.type!==void 0))throw new d("not_a_session","the token is a custom one (an exchange or an approval), not a session's");return{id:e.sub,email:typeof e.email=="string"?e.email:null,emailVerified:e.email_verified===!0,role:typeof e.role=="string"?e.role:null,sessionId:typeof e.session_id=="string"?e.session_id:null,claims:Object.freeze({...e})}}async key(e){let t=this.now();if(t>=this.keysUntil){let s=this.keys.size>0&&t<this.keysUntil+Pe;if(this.lastFailure!==void 0&&t-this.lastFetch<this.refetchIntervalMs){if(!s)throw new g("the project's key set cannot be read now",{cause:this.lastFailure})}else try{await this.refresh()}catch(o){if(!s)throw o}}let r=this.keys.get(e);return!r&&t-this.lastFetch>=this.refetchIntervalMs&&(await this.refresh(),r=this.keys.get(e)),r}refresh(){if(this.inflight)return this.inflight;let e=this.load().finally(()=>{this.inflight=null});return this.inflight=e,e}async load(){this.lastFetch=this.now();let e,t;try{if(t=await this.fetchImpl(`${this.issuer}/.well-known/jwks.json`,{redirect:"error",headers:{accept:"application/json"},signal:AbortSignal.timeout(this.fetchTimeoutMs)}),!t.ok)throw new Error(`the project's key set answered ${t.status}`);e=await t.json()}catch(o){throw this.lastFailure=o,new g("the project's key set cannot be read now",{cause:o})}this.lastFailure=void 0;let r=new Map;for(let o of Array.isArray(e.keys)?e.keys:[]){let i=o.alg;if(typeof o.kid!="string"||!Z(i))continue;let u=T[i];if(o.kty!==u.kty||o.use!==void 0&&o.use!=="sig")continue;let{d:c,...a}=o;try{r.set(o.kid,{alg:i,key:await crypto.subtle.importKey("jwk",a,u.import,!1,["verify"])})}catch{}}this.keys=r;let s=Oe(t.headers.get("cache-control"))??this.maxKeyAgeMs;this.keysUntil=this.now()+Math.min(Math.max(s,this.refetchIntervalMs),this.maxKeyAgeMs)}};function ee(n,e){let t=n.get("x-forwarded-proto")?.split(",")[0]?.trim().toLowerCase(),r=t==="https"||t==="http"?t:e.protocol.slice(0,-1),s=n.get("host")??e.host;return Re.test(s)?`${r}://${s}${e.pathname}`:""}var Re=/^(?:[a-z0-9-]+(?:\.[a-z0-9-]+)*|\[[0-9a-f:.]+\])(?::[0-9]{1,5})?$/i;function xe(n){let e=new Headers;for(let[t,r]of Object.entries(n))if(r!==void 0)for(let s of Array.isArray(r)?r:[r])e.append(t,s);return e}function Oe(n){let e=/(?:^|,)\s*max-age=(\d+)/i.exec(n??"");return e?Number(e[1])*1e3:void 0}function te(n){if(!/^[A-Za-z0-9_-]*$/.test(n)||n.length%4===1)return null;let e=atob(n.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(n.length/4)*4,"=")),t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}function Q(n){let e=te(n);if(!e)return null;try{let t=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e));return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:null}catch{return null}}function je(n,e,t=Date.now()){let r=Object.hasOwn(n.entitlements,e)?n.entitlements[e]:void 0;return r?.active?r.expires_at===null?!0:Date.parse(r.expires_at)>(typeof t=="number"?t:t.getTime()):!1}var S=class extends Error{receipt;constructor(e){super(`the reservation ${JSON.stringify(e.idempotency_key)} is ${e.status} already: its job is not run again (a new one is a new Idempotency-Key)`),this.name="ReservationSettled",this.receipt=e}};async function Ue(n,e,t,r){let{idempotencyKey:s,amount:o,ttlSeconds:i,metadata:u}=t;if(typeof s!="string"||s==="")throw new TypeError("idempotencyKey names the reservation for good: a retry with it is the same hold, never a second");let c={amount:o,...t.credits!==void 0?{credits:t.credits}:{limit:t.limit},...i!==void 0?{ttl_seconds:i}:{},...u!==void 0?{metadata:u}:{}},a=(await n.purchases.holdSpend({path:{customer_id:e},headers:{"Idempotency-Key":s},body:c})).data;if(a.status!=="held")throw new S(a);let l={customer_id:a.customer,spend_id:a.id},p;try{p=await r(a)}catch(m){throw await n.purchases.releaseSpend({path:l}).catch(()=>{}),m}return await n.purchases.commitSpend({path:l}),p}async function*Ce(n){let e,t=new Set;do{let r=(await n(e)).data;yield r;let s=r.next_cursor??void 0;if(s!==void 0&&t.has(s))throw new Error(`the listing answered a cursor it had answered before (${s})`);s!==void 0&&t.add(s),e=s}while(e)}var Le=/^[A-Za-z_][A-Za-z0-9_]{0,127}$/,Me=/^(PALBASE_|NODE_|BUN_|NPM_|LD_|DYLD_|GIT_|SSH_)|^(PATH|HOME|SHELL|USER|TMPDIR|TMP|TEMP|PWD|IFS|ENV|BASH_ENV|SSL_CERT_FILE|SSL_CERT_DIR|CURL_CA_BUNDLE|REQUESTS_CA_BUNDLE|NO_PROXY|ALL_PROXY|HTTP_PROXY|HTTPS_PROXY|PG\w*)$/i;function ne(n){return!Le.test(n)||Me.test(n)||/_PROXY$/i.test(n)}var Ke=/^(PORT|PALBASE_(URL|PROJECT_ID|REPLICAS|SECRET_KEY|WEBHOOK_SECRET|PLATFORM_SECRET|CONTRACT_OUT|SECRETS|DB_[A-Z0-9_]+))$/;function $e(n){return Ke.test(n)}async function Ne(n={}){let e=n.env??process.env,t=e.PALBASE_SECRETS;if(t===void 0||t==="")return;if(t!=="development"&&t!=="production")throw new TypeError(`PALBASE_SECRETS is development or production, not ${t}`);let r=n.url??e.PALBASE_URL??"",s=n.secretKey??e.PALBASE_SECRET_KEY??"";if(r===""||s==="")throw new TypeError("PALBASE_SECRETS reads the project's Secrets with PALBASE_URL and PALBASE_SECRET_KEY: give both (palbase env:pull writes them)");let o=E({url:new URL(r).origin,secretKey:s,fetch:n.fetch}),{data:i}=await o.secrets.getEnvironmentValues({path:{environment:t}}),u=[],c=[],a=[];for(let[l,p]of Object.entries(i.values)){if(ne(l)){a.push(l);continue}if(e[l]!==void 0&&e[l]!==""){c.push(l);continue}e[l]=p,u.push(l)}return{set:t,loaded:u.sort(),kept:c.sort(),refused:a.sort()}}export{E as a,f as b,B as c,F as d,H as e,pe as f,d as g,g as h,_e as i,P as j,ee as k,je as l,S as m,Ue as n,Ce as o,ne as p,$e as q,Ne as r};