palbase 0.3.2 → 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.
- package/dist/ai/index.js +2 -2
- package/dist/backend/engine.js +2 -2
- package/dist/backend/env.js +1 -1
- package/dist/backend/index.js +3 -3
- package/dist/backend/stack.js +1 -1
- package/dist/backend/test.js +2 -2
- package/dist/chunks/{RHQ2NBCI.js → 47V66C2X.js} +2 -2
- package/dist/chunks/{ZEFNZ6DZ.js → 4AQYBTIN.js} +2 -2
- package/dist/chunks/{32BPNFZX.js → 4YD2XCGF.js} +1 -1
- package/dist/chunks/{QRWBXKEM.js → CJCMQ73A.js} +2 -2
- package/dist/chunks/{QD5XLRIJ.js → CZQ7KIRM.js} +2 -2
- package/dist/chunks/{TTKDWRP5.js → IXHR57QC.js} +2 -2
- package/dist/chunks/{QA3GIZMI.js → M5B52IE6.js} +1 -1
- package/dist/chunks/{CNRFJ7AK.js → NK54UVDI.js} +2 -2
- package/dist/chunks/{HJVB6KIR.js → OKZJIY6F.js} +1 -1
- package/dist/chunks/{XUG2RG4F.js → P5JIZEPB.js} +2 -2
- package/dist/chunks/{33DZIPGE.js → PB7UKHCY.js} +2 -2
- package/dist/chunks/{YSZ2RSTS.js → PRM2UXWG.js} +1 -1
- package/dist/chunks/{44SLUFBO.js → TJ5SQTW5.js} +3 -3
- package/dist/chunks/{HHSKJTI6.js → UXRIXHHY.js} +2 -2
- package/dist/chunks/{JFWH2INT.js → YWOS5WH2.js} +2 -2
- package/dist/cli.js +116 -116
- package/dist/refuse/ai.js +1 -1
- package/dist/refuse/backend.js +1 -1
- package/dist/refuse/server.js +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/testing.js +2 -2
- package/dist/web/index.js +2 -2
- package/dist/web/palbe.js +2 -2
- package/dist/web/paywall.js +2 -2
- package/dist/web/vite.js +2 -2
- package/package.json +2 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.3.
|
|
1
|
+
/*! palbase 0.3.3 — Palbase SDK License (see LICENSE) */
|
|
2
2
|
var u="X-PoW-Challenge-ID",c="X-PoW-Nonce";function m(e){if(typeof e!="object"||e===null)return null;let t=e;if(t.error!=="pow_required"||typeof t.challenge!="object"||t.challenge===null)return null;let{id:n,prefix:r,difficulty:o}=t.challenge;return typeof n!="string"||typeof r!="string"||typeof o!="number"||!Number.isInteger(o)||o<0?null:{id:n,prefix:r,difficulty:o}}function d(e){return 8*2**e}var s;async function l(){if(s)return s;let e=globalThis;if(e.process?.versions?.node!==void 0||e.process?.versions?.bun!==void 0)try{let r=(await import("node:crypto")).createHash;if(typeof r=="function")return s=o=>new Uint8Array(r("sha256").update(o).digest()),s}catch{}let t=new TextEncoder;return s=async n=>new Uint8Array(await crypto.subtle.digest("SHA-256",t.encode(n))),s}function p(e){let t=0;for(let n of e){if(n===0){t+=8;continue}return t+Math.clz32(n)-24}return t}var w=4096,g=typeof globalThis.setImmediate=="function"?()=>new Promise(e=>globalThis.setImmediate(e)):()=>new Promise(e=>setTimeout(e,0));async function y(e,t={}){if(e.difficulty>24)throw new Error(`proof-of-work: difficulty ${e.difficulty} is above auth's ceiling of 24`);let n=await l(),r=d(e.difficulty),o=Date.now()+(t.timeLimitMs??12e4);for(let i=0;i<r;i++){if(i%w===0&&i>0){if(await g(),t.signal?.aborted)throw t.signal.reason??new DOMException("proof-of-work aborted","AbortError");if(Date.now()>o)throw new Error(`proof-of-work: gave up on difficulty ${e.difficulty} after ${i} attempts`)}let f=n(e.prefix+i),a=f instanceof Uint8Array?f:await f;if(p(a)>=e.difficulty)return{[u]:e.id,[c]:String(i)}}throw new Error(`proof-of-work: no nonce for difficulty ${e.difficulty} within ${r} attempts`)}export{m as a,y as b};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! palbase 0.3.
|
|
2
|
-
import"./
|
|
1
|
+
/*! palbase 0.3.3 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import"./PRM2UXWG.js";import{realpathSync as Ve}from"node:fs";import{resolve as ue}from"node:path";import wt from"typescript";import{existsSync as Se,readFileSync as Ue}from"node:fs";import{dirname as de,join as pe,relative as qe,resolve as ye,sep as ee}from"node:path";var h=class extends Error{constructor(t){super(t),this.name="ContractAnalysisError"}},W=new Set(["palbase/backend","@palbase/backend","palgres"]),Je=new Set(["Get","Post","Put","Patch","Delete","Query","Upload"]);function Te(e){if(typeof e.createProgram!="function"||typeof e.getDecorators!="function"||typeof e.readConfigFile!="function")throw new h(`the contract is read with TypeScript's compiler API, and the TypeScript given (v${e.version??"unknown"}) has none \u2014 TypeScript 7 is the Go-native compiler, whose package exposes version metadata only`)}function he(e,t){Te(e);let n=pe(t,"tsconfig.json"),r={target:e.ScriptTarget.ES2022,module:e.ModuleKind.ESNext,moduleResolution:e.ModuleResolutionKind.Bundler,experimentalDecorators:!0,allowImportingTsExtensions:!0},s=[];if(Se(n)){let i=e.readConfigFile(n,e.sys.readFile);if(i.error)throw new h(`${n}: ${e.flattenDiagnosticMessageText(i.error.messageText,`
|
|
3
3
|
`)}`);let o=e.parseJsonConfigFileContent(i.config,e.sys,t);r=o.options,s=o.fileNames.filter(a=>/\.d\.[cm]?ts$/.test(a))}return{options:{...r,strictNullChecks:!0,noEmit:!0,skipLibCheck:!0},ambient:s}}function be(e,t,n,r,s){Te(e);let i=e.createProgram([...new Set(n)],r,s);return{ts:e,root:t,program:i,checker:i.getTypeChecker(),packages:new Map}}function $(e,t){let n=ye(t);return!n.includes(`${ee}node_modules${ee}`)&&!/\.d\.[cm]?ts$/.test(n)&&(n===e.root||n.startsWith(e.root+ee))}function v(e,t){return!!t&&$(e,t.getSourceFile().fileName)}function xe(e,t){let n=[],r=de(ye(t)),s=null;for(;;){let i=e.packages.get(r);if(i!==void 0){s=i;break}n.push(r);let o=pe(r,"package.json");if(Se(o)){try{let c=JSON.parse(Ue(o,"utf8")).name;s=typeof c=="string"?c:null}catch{s=null}break}let a=de(r);if(a===r)break;r=a}for(let i of n)e.packages.set(i,s);return s}function te(e,t){if($(e,t))return!1;let n=xe(e,t)??"";return n==="palbase"?/[\\/]types[\\/]backend[\\/]/.test(t):W.has(n)}function we(e,t){if($(e,t))return!1;let n=xe(e,t)??"";return W.has(n)||n==="palbase"||n.startsWith("@palbase/")}function O(e,t){let n=t.getSourceFile(),{line:r}=n.getLineAndCharacterOfPosition(t.getStart(n));return`${qe(e.root,n.fileName)}:${r+1}`}function T(e,t){for(;t;){if(e.isParenthesizedExpression(t)||e.isAsExpression(t)||e.isNonNullExpression(t)||e.isAwaitExpression(t)||e.isTypeAssertionExpression(t)||e.isSatisfiesExpression(t)){t=t.expression;continue}return t}return t}function G(e,t){if(t&&t.flags&e.ts.SymbolFlags.Alias){let n=e.checker.getAliasedSymbol(t);if(n&&n.declarations)return n}return t}function D(e,t){let n=G(e,e.checker.getSymbolAtLocation(t));return n&&(n.valueDeclaration||n.declarations&&n.declarations[0])||null}function me(e,t){let n=t;for(;n&&!e.isImportDeclaration(n)&&!e.isExportDeclaration(n);)n=n.parent;return n&&(e.isImportDeclaration(n)||e.isExportDeclaration(n))&&n.moduleSpecifier&&e.isStringLiteral(n.moduleSpecifier)?n.moduleSpecifier.text:null}function I(e,t){let n=e.ts;if(t=T(n,t),!t)return null;if(n.isPropertyAccessExpression(t)){let i=e.checker.getSymbolAtLocation(t.expression);return i&&(i.declarations||[]).some(a=>n.isNamespaceImport(a)&&W.has(me(n,a)??""))?t.name.text:null}if(!n.isIdentifier(t))return null;let r=e.checker.getSymbolAtLocation(t),s=new Set;for(;r&&!s.has(r);){s.add(r);for(let i of r.declarations||[]){if((n.isImportSpecifier(i)||n.isExportSpecifier(i))&&W.has(me(n,i)??""))return(i.propertyName||i.name).text;if(te(e,i.getSourceFile().fileName))return r.name}if(!(r.flags&n.SymbolFlags.Alias))return null;r=e.checker.getImmediateAliasedSymbol(r)}return null}function ge(e,t){let n=t.expression;return I(e,e.ts.isCallExpression(n)?n.expression:n)}function P(e,t){return t&&(e.isIdentifier(t)||e.isPrivateIdentifier(t)||e.isStringLiteral(t)||e.isNumericLiteral(t))?t.text:null}function Z(e,t){let n=e.ts,r=[];for(let s of t.statements){if(!n.isClassDeclaration(s)||!(n.getDecorators(s)||[]).some(o=>ge(e,o)==="Controller"))continue;if(!s.name)throw new h(`${O(e,s)} \u2014 a @Controller class needs a name \u2014 its routes' errors are bound to it by name`);let i=[];for(let o of s.members)if(!(!n.isMethodDeclaration(o)||!o.body)&&(n.getDecorators(o)||[]).some(a=>Je.has(ge(e,a)??""))){if(P(n,o.name)===null)throw new h(`${O(e,o)} \u2014 a route method needs a plain name; the contract reaches it by name`);i.push(o)}r.push({cls:s,routes:i})}return r}var Qe=new Set([2307,2580,2582,2583,2584,2591,2592,2593,2688,2867,2868,7016]);function We(e){let t=e.getSymbol();return t?.getName()==="Response"&&(t.declarations??[]).length>0&&(t.declarations??[]).every(n=>n.getSourceFile().isDeclarationFile)}function ke(e){let{ts:t,program:n,checker:r}=e,s=!1;return function(o,a){let c=o.getSourceFile().fileName,l=o.name.getText(o.getSourceFile()),u=f=>{throw new h(`${c} \u2014 ${a}.${l}: cannot infer a safe response contract (${f}). Use a named Zod return schema for this response; any/unknown is never emitted as a successful contract.`)};if(!s){let f=[];for(let S of n.getSourceFiles()){if(f.length>=5)break;S.isDeclarationFile||n.isSourceFileFromExternalLibrary(S)||/[\\/]node_modules[\\/]/.test(S.fileName)||we(e,S.fileName)||f.push(...n.getSemanticDiagnostics(S).filter(x=>x.category===t.DiagnosticCategory.Error&&!Qe.has(x.code)))}f.length&&u(t.formatDiagnostics(f.slice(0,5),{getCanonicalFileName:S=>S,getCurrentDirectory:()=>e.root,getNewLine:()=>`
|
|
4
4
|
`})),s=!0}let m=r.getSignatureFromDeclaration(o),g=m&&r.getAwaitedType(r.getReturnTypeOfSignature(m));if(!g)return u("unresolved return type");if(g.flags&(t.TypeFlags.Void|t.TypeFlags.Undefined))return{kind:"void"};if(We(g))return{kind:"raw"};let p=new Set,d=0;function C(f,S){if(++d>2e3||p.size>24)return u(`${S}: contract is too large; name its schema`);let x=f.flags,y=t.TypeFlags;if(x&(y.Any|y.Unknown|y.Never|y.TypeParameter))return u(`${S}: ${r.typeToString(f)}`);let fe=b=>{let w=r.getPropertiesOfType(b);if(!(b.flags&y.Object)||w.length!==1||w[0].name!=="__pg"||!(w[0].flags&t.SymbolFlags.Optional)||r.getIndexInfosOfType(b).length)return!1;let N=r.getTypeOfSymbolAtLocation(w[0],o);return(N.isUnion()?N.types:[N]).every(k=>k.flags&(y.StringLiteral|y.Undefined))};if(f.isIntersection()){let b=f.types.filter(w=>!fe(w));if(b.length===1&&b.length<f.types.length)return C(b[0],S)}if(fe(f))return u(`${S}: unknown PostgreSQL payload; name its response schema`);if(x&y.StringLiteral)return`z.literal(${JSON.stringify(f.value)})`;if(x&y.NumberLiteral)return`z.literal(${JSON.stringify(f.value)})`;if(x&y.BooleanLiteral)return`z.literal(${r.typeToString(f)==="true"})`;if(x&y.String)return"z.string()";if(x&y.TemplateLiteral){let b=f;if(b.types.length>8||!b.types.every(k=>k.flags&y.String))return u(`${S}: template literal requires an explicit schema`);let w=k=>k.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),N="^"+w(b.texts[0]);for(let k of b.texts.slice(1,-1))if(k){let Y=w(k);N+=`(?:(?!${Y})[\\s\\S])*${Y}`}return N+="[\\s\\S]*"+w(b.texts.at(-1))+"$(?![\\s\\S])",N.length>4096?u(`${S}: template pattern is too large`):`z.string().regex(new RegExp(${JSON.stringify(N)}))`}if(x&y.Number)return"z.number().finite()";if(x&y.Boolean)return"z.boolean()";if(x&y.Null)return"z.null()";if(x&y.Undefined)return"z.undefined()";if(p.has(f))return u(`${S}: recursive response`);p.add(f);try{if(f.isUnion()){if(f.types.length>32)return u(`${S}: union has more than 32 alternatives`);let A=f.types.some(M=>M.flags&y.Null),Q=f.types.some(M=>M.flags&y.Undefined),j=f.types.filter(M=>!(M.flags&(y.Null|y.Undefined)));return(j.length===0?A?"z.null()":"z.undefined()":j.length===1?C(j[0],S):`z.union([${j.map(M=>C(M,S)).join(",")}])`)+(A&&j.length?".nullable()":"")+(Q?".optional()":"")}if(r.isTupleType(f))return u(`${S}: tuple requires an explicit schema`);if(r.isArrayType(f)){let A=r.getTypeArguments(f)[0];return A.flags&y.Never?"z.array(z.string()).length(0)":`z.array(${C(A,`${S}[]`)})`}let b=f.isIntersection()&&f.types.every(A=>A.flags&y.Object);if(!(x&y.Object)&&!b||f.getCallSignatures().length||f.getConstructSignatures().length)return u(`${S}: non-JSON type ${r.typeToString(f)}`);let w=f.symbol?.declarations?.[0];if(w&&(t.isClassDeclaration(w)||t.isClassExpression(w)))return u(`${S}: class instance ${r.typeToString(f)}`);let N=r.getPropertiesOfType(f),k=r.getIndexInfosOfType(f);return k.length?k.length!==1||!(k[0].keyType.flags&y.String)||N.length?u(`${S}: mixed or non-string index signature`):`z.record(z.string(), ${C(k[0].type,`${S}.*`)})`:N.length?`z.object({${N.map(A=>{if(A.escapedName.toString().startsWith("__@"))return u(`${S}: symbol property`);let Q=A.getName(),j=C(r.getTypeOfSymbolAtLocation(A,o),`${S}.${Q}`);return`${JSON.stringify(Q)}:${j}${A.flags&t.SymbolFlags.Optional?".optional()":""}`}).join(",")}}).strict()`:u(`${S}: empty structural type`)}finally{p.delete(f)}}return{kind:"expression",expression:C(g,"return")}}}import{resolve as Ge}from"node:path";var ne=Symbol("not a named schema");function Ee(e,t,n,r){let{ts:s}=e,i=r.getSourceFile(),o=r.name.getText(i),a=d=>new h(`${i.fileName} \u2014 ${n}.${o}: ${d}`);function c(d){if(s.isTypeReferenceNode(d)&&d.typeName.getText(i)==="Promise"&&d.typeArguments&&d.typeArguments.length===1)return c(d.typeArguments[0]);if(d.kind===s.SyntaxKind.VoidKeyword||d.kind===s.SyntaxKind.UndefinedKeyword)return null;let C=s.isArrayTypeNode(d)?d.elementType:s.isTypeReferenceNode(d)&&d.typeName.getText(i)==="Array"&&d.typeArguments&&d.typeArguments.length===1?d.typeArguments[0]:void 0,f=l(C??d);return f===ne?f:{...f,isArray:C!==void 0}}function l(d){if(s.isTypeReferenceNode(d)&&!d.typeArguments)return{typeName:d.typeName.getText(i),node:d.typeName};if(s.isTypeReferenceNode(d)&&d.typeArguments&&d.typeArguments.length===1){let C=d.typeName.getText(i);if(/^(z\.)?(infer|output|input)$/.test(C)){let f=d.typeArguments[0];if(s.isTypeQueryNode(f))return{typeName:f.exprName.getText(i),node:f.exprName};if(s.isTypeReferenceNode(f)&&!f.typeArguments)return{typeName:f.typeName.getText(i),node:f.typeName}}}if(d.kind===s.SyntaxKind.VoidKeyword)throw a("void cannot appear inside an array/Promise here");return ne}let u=()=>t(r,n);if(!r.type)return u();let m=c(r.type);if(m===null)return{kind:"void"};if(m===ne)return u();let g=Ze(e,m.node);if(!g)return u();let p=He(e,g.symbol);return p?{kind:"schema",...p,array:m.isArray}:u()}function Ze(e,t){let{ts:n,checker:r}=e,s=r.getSymbolAtLocation(n.isQualifiedName(t)?t.right:t),i=G(e,s);if(!i||!(i.flags&n.SymbolFlags.Variable))return null;let o=i.valueDeclaration;return!o||!n.isVariableDeclaration(o)||!r.getTypeOfSymbolAtLocation(i,o).getProperty("~standard")?null:{symbol:i}}function He(e,t){let n=t.valueDeclaration?.getSourceFile();if(!n||n.isDeclarationFile)return null;let r=e.checker.getSymbolAtLocation(n);if(!r)return null;let s=e.checker.getExportsOfModule(r).filter(i=>G(e,i)===t).map(i=>i.name);return s.length===0?null:{file:Ge(n.fileName),exportName:s.includes(t.name)?t.name:s[0]}}var oe={BadRequest:{code:"bad_request",status:400,codeArg:null},Unauthorized:{code:"unauthorized",status:401,codeArg:1},Forbidden:{code:"forbidden",status:403,codeArg:1},NotFound:{code:"not_found",status:404,codeArg:1},Conflict:{code:"conflict",status:409,codeArg:1},UniqueViolation:{code:"unique_violation",status:409,codeArg:2},SerializationFailure:{code:"serialization_failure",status:409,codeArg:null},DeadlockDetected:{code:"deadlock_detected",status:409,codeArg:null},TooManyRequests:{code:"too_many_requests",status:429,codeArg:null}},Xe=new Set(["HttpError","PalError"]),Ye=[{member:"page",container:null,error:{name:"BadRequest",code:"bad_request",status:400}},{member:"$page",container:null,error:{name:"BadRequest",code:"bad_request",status:400}},{member:"update",container:/^RepositoryOf(\$\d+)?$/,error:{name:"NotFound",code:"not_found",status:404}},{member:"update",container:/^RepositoryOf(\$\d+)?$/,error:{name:"BadRequest",code:"bad_request",status:400}},{member:"updateScoped",container:/^RepositoryOf(\$\d+)?$/,error:{name:"BadRequest",code:"bad_request",status:400}}],et=new Map([["expectOne",0],["expectNone",0],["expectAtLeast",1],["expectAtMost",1]]);function Le(e){let t={...e,ids:new WeakMap,nextId:1,providerSet:null,concrete:null,summaries:new Map,warnings:new Map,statusOf:null,round:0,cyclic:!1,grew:!1};return{analyze(n){let r;for(;t.round+=1,t.cyclic=!1,t.grew=!1,r=xt(t,n),!(!t.cyclic||!t.grew););for(let s of t.summaries.values())s.final=!0;return r},warnings(){return[...t.warnings.values()]}}}function tt(e,t,n){throw new h(`${O(e,t)} \u2014 ${n}`)}function U(e,t){let n=e.ids.get(t);return n||(n=e.nextId++,e.ids.set(t,n)),n}function ce(e,t){return(e.getCombinedModifierFlags(t)&e.ModifierFlags.Static)!==0}function De(e,t){return(e.getCombinedModifierFlags(t)&e.ModifierFlags.Abstract)!==0}function F(e,t){return!!t&&(e.isClassDeclaration(t)||e.isClassExpression(t))}function Pe(e,t){if(!t)return null;if(F(e,t))return t;if((e.isVariableDeclaration(t)||e.isPropertyDeclaration(t)||e.isPropertyAssignment(t))&&t.initializer){let n=T(e,t.initializer);if(e.isClassExpression(n))return n}return null}function nt(e,t){if(t.name)return t.name.text;let n=t.parent;if(n&&(e.isVariableDeclaration(n)||e.isPropertyDeclaration(n)||e.isPropertyAssignment(n))&&n.name&&P(e,n.name))return P(e,n.name)??void 0}function _(e,t){let n=e.ts,r=T(n,t);if(!r)return null;let s=Pe(n,D(e,n.isPropertyAccessExpression(r)?r.name:r));return s&&v(e,s)?s:null}function q(e,t){let n=e.ts,r=(t.heritageClauses||[]).find(i=>i.token===n.SyntaxKind.ExtendsKeyword),s=r&&r.types[0]&&r.types[0].expression;return s?_(e,s):null}function $e(e,t,n){for(let r=q(e,t);r;r=q(e,r))if(r===n)return!0;return!1}function V(e,t,n,r){let s=e.ts;for(let i=t;i;i=q(e,i))for(let o of i.members)if(!(P(s,o.name)!==n||ce(s,o)!==r)){if((s.isMethodDeclaration(o)||s.isGetAccessorDeclaration(o))&&o.body)return{fn:o,owner:i};if(s.isPropertyDeclaration(o)&&o.initializer){let a=T(s,o.initializer);if(s.isArrowFunction(a)||s.isFunctionExpression(a))return{fn:a,owner:i}}}return null}function rt(e){let t=e.ts;if(e.providerSet)return e.providerSet;let n=new Set;for(let r of e.program.getSourceFiles())if($(e,r.fileName)){for(let s of r.statements)if(t.isClassDeclaration(s))for(let i of t.getDecorators(s)||[]){let o=i.expression;if(!t.isCallExpression(o)||I(e,o.expression)!=="Module")continue;let a=T(t,o.arguments[0]);if(!(!a||!t.isObjectLiteralExpression(a)))for(let c of a.properties){if(!t.isPropertyAssignment(c)||P(t,c.name)!=="providers")continue;let l=T(t,c.initializer);if(t.isArrayLiteralExpression(l))for(let u of l.elements){let m=_(e,u);m&&n.add(m)}}}}return e.providerSet=n,n}function Ce(e){let t=e.ts;if(e.concrete)return e.concrete;let n=[],r=s=>{F(t,s)&&!De(t,s)&&n.push(s),t.forEachChild(s,r)};for(let s of e.program.getSourceFiles())$(e,s.fileName)&&r(s);return e.concrete=n,n}function Fe(e,t){let n=t.name?e.checker.getSymbolAtLocation(t.name):t.symbol;return n?e.checker.getDeclaredTypeOfSymbol(n):null}function st(e,t){let n=t&&(t.getSymbol()||t.aliasSymbol),r=n&&(n.declarations||[]).find(s=>F(e.ts,s));return r&&F(e.ts,r)&&v(e,r)?r:null}function re(e,t){return t.type?e.checker.getTypeFromTypeNode(t.type):e.checker.getTypeAtLocation(t.name||t)}function J(e,t,n){let r=e.ts;if(!t)return;if(t.isUnion()){for(let l of t.types)J(e,l,n);return}let s=r.TypeFlags,i=s.StringLike|s.NumberLike|s.BigIntLike|s.BooleanLike|s.EnumLike|s.ESSymbolLike|s.VoidLike|s.Null;if(t.flags&(s.Any|s.Unknown|i))return;let o=t.getSymbol();if(!o)return;let a=(o.declarations||[]).find(l=>F(r,l));if(a&&F(r,a)){if(!v(e,a))return;De(r,a)||n.add(a);for(let l of Ce(e))$e(e,l,a)&&n.add(l);return}if((o.declarations||[]).some(l=>v(e,l)))for(let l of Ce(e)){let u=Fe(e,l);u&&e.checker.isTypeAssignableTo(u,t)&&n.add(l)}}function ae(e,t,n){let r=st(e,t);if(r){let s=rt(e);if(s.has(r)){n.add(r);return}let i=[...s].filter(o=>o!==r&&$e(e,o,r));if(i.length===1){n.add(i[0]);return}}J(e,t,n)}function it(e,t){for(let n=e;n;n=n.parent)if(n===t)return!0;return!1}function Oe(e,t){return t.fn&&it(e,t.fn)?t:{receiver:null,owner:null,fn:null}}function E(e,t,n,r=new Set){let s=e.ts,i=new Set;if(t=T(s,t),!t)return i;let o=`${U(e,t)}@${n.receiver?U(e,n.receiver):0}`;if(r.has(o))return i;r.add(o);let a=c=>{for(let l of c)i.add(l)};if(s.isNewExpression(t)){let c=_(e,t.expression);return c&&i.add(c),i}if(t.kind===s.SyntaxKind.ThisKeyword)return n.receiver&&i.add(n.receiver),i;if(s.isConditionalExpression(t))return a(E(e,t.whenTrue,n,r)),a(E(e,t.whenFalse,n,r)),i;if(s.isBinaryExpression(t)){let c=t.operatorToken.kind,l=s.SyntaxKind;if(c===l.QuestionQuestionToken||c===l.BarBarToken||c===l.AmpersandAmpersandToken)return a(E(e,t.left,n,r)),a(E(e,t.right,n,r)),i;if(c===l.CommaToken||c===l.EqualsToken)return a(E(e,t.right,n,r)),i}if(s.isCallExpression(t)){for(let c of X(e,t,n))for(let l of H(s,c.fn))a(E(e,l,c.ctx,r));if(i.size>0)return i}else if(s.isIdentifier(t)||s.isPropertyAccessExpression(t)){let c=D(e,s.isPropertyAccessExpression(t)?t.name:t);if(c&&s.isVariableDeclaration(c))return c.initializer&&a(E(e,c.initializer,Oe(c,n),r)),(!((s.getCombinedNodeFlags(c)&s.NodeFlags.Const)!==0)||!c.initializer)&&J(e,re(e,c),i),i;if(c&&s.isParameter(c)){let l=re(e,c);return c.parent&&s.isConstructorDeclaration(c.parent)?ae(e,l,i):J(e,l,i),i}if(c&&s.isPropertyDeclaration(c))return c.initializer?a(E(e,c.initializer,{receiver:c.parent,owner:c.parent,fn:null},r)):ae(e,re(e,c),i),i;if(c&&s.isGetAccessorDeclaration(c)&&c.body){for(let l of H(s,c))a(E(e,l,{receiver:c.parent,owner:c.parent,fn:c},r));if(i.size>0)return i}if(c&&s.isPropertyAssignment(c)&&(a(E(e,c.initializer,{receiver:null,owner:null,fn:null},r)),i.size>0))return i}return J(e,e.checker.getTypeAtLocation(t),i),i}function H(e,t){if(e.isArrowFunction(t)&&!e.isBlock(t.body))return[t.body];let n=e.isFunctionLike(t)?t.body:void 0;if(!n)return[];let r=[],s=i=>{if(e.isReturnStatement(i)){i.expression&&r.push(i.expression);return}e.isFunctionLike(i)||F(e,i)||e.forEachChild(i,s)};return e.forEachChild(n,s),r}function Re(e,t){return e.isPropertyAccessExpression(t)?t.name.text:e.isElementAccessExpression(t)&&e.isStringLiteralLike(t.argumentExpression)?t.argumentExpression.text:null}function ze(e,t){return e.isPropertyAccessExpression(t)?t.name:t.argumentExpression}function ot(e,t){let n=e.ts,r=Re(n,t);if(r===null)return[];let s=e.checker.getSymbolAtLocation(ze(n,t)),i=new Map;for(let o of s&&s.declarations||[]){if(!te(e,o.getSourceFile().fileName))continue;let a=o.parent,c=a&&a.name&&n.isIdentifier(a.name)?a.name.text:"";for(let l of Ye)l.member===r&&(!l.container||l.container.test(c))&&i.set(l.error.code,l.error)}return[...i.values()]}function at(e,t){let n=e.checker.getSymbolAtLocation(ze(e.ts,t));return n?(n.declarations||[]).some(r=>v(e,r)):!0}function je(e,t,n){let r=e.ts,s=[];for(let i=t;i;i=q(e,i)){for(let a of i.members){if(!r.isPropertyDeclaration(a)||!a.initializer||ce(r,a))continue;let c=T(r,a.initializer);r.isArrowFunction(c)||r.isFunctionExpression(c)||s.push({fn:a.initializer,ctx:{receiver:n,owner:i,fn:null}})}let o=i.members.find(a=>r.isConstructorDeclaration(a)&&!!a.body);if(o){s.push({fn:o,ctx:{receiver:n,owner:i,fn:o}});break}}return s}function X(e,t,n){let r=e.ts,s=T(r,t.expression);if(s.kind===r.SyntaxKind.SuperKeyword){let c=n.owner&&q(e,n.owner);return c?je(e,c,n.receiver):[]}let i=Re(r,s);if(i!==null){let c=s,l=T(r,c.expression);if(l.kind===r.SyntaxKind.SuperKeyword){let g=n.owner&&q(e,n.owner),p=g&&V(e,g,i,!1);return p?[{fn:p.fn,ctx:{receiver:n.receiver,owner:p.owner,fn:p.fn}}]:[]}let u=r.isIdentifier(l)||r.isPropertyAccessExpression(l)?_(e,l):null;if(u){let g=V(e,u,i,!0);return g?[{fn:g.fn,ctx:{receiver:null,owner:g.owner,fn:g.fn}}]:[]}if(!at(e,c))return[];let m=[];for(let g of E(e,l,n)){let p=V(e,g,i,!1);p&&m.push({fn:p.fn,ctx:{receiver:g,owner:p.owner,fn:p.fn}})}if(m.length>0)return m}let o=e.checker.getResolvedSignature(t),a=o&&o.declaration;if(a&&!r.isJSDocSignature(a)&&a.body&&v(e,a)){let c=a,l=c.parent&&F(r,c.parent)?c.parent:null,u=l&&!ce(r,c)?l:null;return[{fn:c,ctx:{receiver:u,owner:l,fn:c}}]}return[]}function Ne(e,t,n){let r=e.ts,s=T(r,t);if(!s)return[];if(r.isPropertyAccessExpression(s)){let i=D(e,s.name);if(!(i&&v(e,i)&&(r.isMethodDeclaration(i)||r.isPropertyDeclaration(i))))return[];let a=[];for(let c of E(e,s.expression,n)){let l=V(e,c,s.name.text,!1);l&&a.push({fn:l.fn,ctx:{receiver:c,owner:l.owner,fn:l.fn}})}return a}if(r.isIdentifier(s)){let i=D(e,s);if(!i||!v(e,i))return[];if(r.isFunctionDeclaration(i)&&i.body)return[{fn:i,ctx:{receiver:null,owner:null,fn:i}}];if(r.isVariableDeclaration(i)&&i.initializer){let o=T(r,i.initializer);if(r.isArrowFunction(o)||r.isFunctionExpression(o))return[{fn:o,ctx:{receiver:null,owner:null,fn:o}}]}}return[]}function K(e,t,n){let r=e.ts,s=T(r,t);if(!s)return null;if(n==="string"&&(r.isStringLiteral(s)||r.isNoSubstitutionTemplateLiteral(s)))return[s.text];if(n==="number"&&r.isNumericLiteral(s))return[Number(s.text)];let i=e.checker.getTypeAtLocation(s),o=[];for(let a of i.isUnion()?i.types:[i])if(n==="string"&&a.isStringLiteral())o.push(a.value);else if(n==="number"&&a.isNumberLiteral())o.push(a.value);else return null;return o.length>0?[...new Set(o)]:null}function Ae(e,t,n){let r=O(e,t);e.warnings.has(r)||e.warnings.set(r,`${r} \u2014 ${n}`)}function ct(e,t){let n=T(e,t);return!n||e.isIdentifier(n)&&n.text==="undefined"||n.kind===e.SyntaxKind.VoidExpression}function ve(e){let t=e.split(/[^A-Za-z0-9]+/).filter(Boolean).map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join("");return/^[A-Za-z]/.test(t)?t:`E${t}`}function Me(e,t,n,r,s){if(Xe.has(t)){let c=K(e,n[0],"number"),l=K(e,n[1],"string");return!l||!c||c.length!==1?(Ae(e,r,`new ${t}(status, code, \u2026) with a code or status decided at runtime cannot be typed; clients receive it as their untyped case. To type it, give the code and status literal types (or declare it with defineError)`),[]):l.map(u=>({name:s&&l.length===1?s:ve(u),code:u,status:c[0]}))}let i=Object.prototype.hasOwnProperty.call(oe,t)?oe[t]:null;if(!i)return[];let o=[i.code];if(i.codeArg!==null&&n.length>i.codeArg&&!ct(e.ts,n[i.codeArg])&&(o=K(e,n[i.codeArg],"string"),!o))return Ae(e,r,`new ${t}(\u2026) with a code decided at runtime cannot be typed; clients receive it as their untyped case. To type it, give the code a literal type (or declare it with defineError)`),[];let a=o;return a.map(c=>({name:s&&a.length===1?s:c===i.code?t:ve(c),code:c,status:i.status}))}function le(e,t){let n=e.ts,r=t.initializer&&T(n,t.initializer);return r&&n.isCallExpression(r)&&I(e,r.expression)==="defineError"?r:null}function Ie(e,t,n){let r=K(e,n.arguments[0],"string"),s=K(e,n.arguments[1],"number"),i=r&&r.length===1?r[0]:null,o=s&&s.length===1?s[0]:null;return(i===null||o===null)&&tt(e,n,`defineError(...) for "${t.name.getText()}" declares a typed error, so its code and status must be known when the project is built (a literal, or a constant of literal type)`),{name:t.name.getText(),code:i,status:o}}function lt(e,t){let n=null,r=s=>{if(!(n||e.isFunctionLike(s))){if(e.isCallExpression(s)&&s.expression.kind===e.SyntaxKind.SuperKeyword){n=s;return}e.forEachChild(s,r)}};return t.body&&e.forEachChild(t.body,r),n}function Be(e,t,n,r){let s=e.ts,i=(t.heritageClauses||[]).find(d=>d.token===s.SyntaxKind.ExtendsKeyword),o=i&&i.types[0]&&i.types[0].expression;if(!o)return[];let a=t.members.find(d=>s.isConstructorDeclaration(d)&&!!d.body),c=n,l=r;if(a){let d=lt(s,a);if(!d)return[];c=d.arguments,l=d}let u=nt(s,t),m=I(e,o);if(m)return Me(e,m,c,l,u);let g=D(e,o);if(g&&s.isVariableDeclaration(g)){let d=le(e,g);return d?[{...Ie(e,g,d),name:u||g.name.getText()}]:[]}let p=_(e,o);if(p){let d=Be(e,p,c,l);return d.length===1&&u?[{...d[0],name:u}]:d}return[]}function ut(e,t){let n=e.ts,r=t.arguments||[],s=I(e,t.expression);if(s)return Me(e,s,r,t);let i=T(n,t.expression),o=D(e,n.isPropertyAccessExpression(i)?i.name:i);if(!o)return[];if(n.isVariableDeclaration(o)){let c=le(e,o);if(c)return[Ie(e,o,c)]}let a=Pe(n,o);return a&&v(e,a)?Be(e,a,r,t):[]}function z(e,t,n,r,s,i,o=new Set){let a=e.ts;if(t=T(a,t),!t)return;let c=`${U(e,t)}@${n.receiver?U(e,n.receiver):0}`;if(!o.has(c)){if(o.add(c),a.isNewExpression(t)){let l=O(e,t);R(e,r,s,i,ut(e,t).map(u=>({...u,site:l})));return}if(a.isConditionalExpression(t)){z(e,t.whenTrue,n,r,s,i,o),z(e,t.whenFalse,n,r,s,i,o);return}if(a.isBinaryExpression(t)){let l=a.SyntaxKind,u=t.operatorToken.kind;(u===l.QuestionQuestionToken||u===l.BarBarToken)&&z(e,t.left,n,r,s,i,o),z(e,t.right,n,r,s,i,o);return}if(a.isCallExpression(t)){for(let l of X(e,t,n))for(let u of H(a,l.fn))z(e,u,l.ctx,r,s,i,o);return}if(a.isIdentifier(t)||a.isPropertyAccessExpression(t)){let l=D(e,a.isPropertyAccessExpression(t)?t.name:t);if(l&&(a.isVariableDeclaration(l)||a.isPropertyDeclaration(l))&&l.initializer){let u=a.isVariableDeclaration(l)?Oe(l,n):n;z(e,l.initializer,u,r,s,i,o)}}}}function se(e,t){let n=e.ts;if(!n.isFunctionLike(t))return!1;if((n.getCombinedModifierFlags(t)&n.ModifierFlags.Async)!==0)return!0;let r=e.checker.getSignatureFromDeclaration(t);if(!r)return!1;let s=e.checker.getReturnTypeOfSignature(r),i=e.checker.getPromisedTypeOfPromise;return i?i.call(e.checker,s)!==void 0:e.checker.getAwaitedType(s)!==s}function ft(e,t,n){let r=null;for(let s=t.parent;s&&s!==n;s=s.parent)e.isFunctionLike(s)&&(e.getCombinedModifierFlags(s)&e.ModifierFlags.Async)!==0&&(r=s);return r}function dt(e,t,n){for(let r=t.parent;r&&r!==n;r=r.parent)if(e.isAwaitExpression(r)||e.isForOfStatement(r)&&r.awaitModifier)return!0;return!1}function mt(e,t,n,r){for(let s=t.scopes.length-1;s>=0;s--){let i=t.scopes[s],o=ft(e.ts,n,i.node),a=r||o!==null;if(i.kind==="try"){if(!a||dt(e.ts,o||n,i.node))return i.sink}else if(i.kind==="settle"){if(a)return null}else if(i.kind==="catch"&&a&&!i.rethrows)return null}return t.root}function gt(e){let t=e.ts;if(e.statusOf)return e.statusOf;let n=new Map;for(let[s,i]of Object.entries(oe))n.set(i.code,{status:i.status,site:`palbase/backend ${s}`});let r=s=>{if(t.isVariableDeclaration(s)&&t.isIdentifier(s.name)){let i=le(e,s),o=i&&K(e,i.arguments[0],"string"),a=i&&K(e,i.arguments[1],"number");o&&a&&o.length===1&&a.length===1&&!n.has(o[0])&&n.set(o[0],{status:a[0],site:O(e,s)})}t.forEachChild(s,r)};for(let s of e.program.getSourceFiles())$(e,s.fileName)&&r(s);return e.statusOf=n,n}function St(e,t){let n=gt(e),r=n.get(t.code);if(!r){n.set(t.code,{status:t.status,site:t.site});return}if(r.status!==t.status)throw new h(`"${t.code}" is thrown with status ${t.status} (${t.site}) but the code carries status ${r.status} (${r.site}) \u2014 a client matches an error by its code, so one code carries one status. Throw the code's own class, or give the error its own code`)}function R(e,t,n,r,s){for(let o of s)St(e,o);let i=mt(e,t,n,r);if(i)for(let o of s)i.has(o.code)||i.set(o.code,o)}function Ke(e,t,n){if(!n)return!1;let r=!1,s=o=>{let a=!1,c=l=>{a||(e.isIdentifier(l)&&l.text===n?a=!0:e.forEachChild(l,c))};return c(o),a},i=o=>{r||e.isFunctionLike(o)&&o!==t||(e.isThrowStatement(o)&&o.expression&&s(o.expression)?r=!0:e.forEachChild(o,i))};return i(t),r}function pt(e,t){let n=T(e,t);if(n&&(e.isArrowFunction(n)||e.isFunctionExpression(n))){let r=n.parameters[0];return r?e.isIdentifier(r.name)?e.isBlock(n.body)?Ke(e,n.body,r.name.text):!1:!0:!1}return!0}function yt(e,t,n){let r=e.ts;if(!r.isPropertyAccessExpression(t)||t.name.text!==n)return!1;let s=T(r,t.expression);if(!r.isIdentifier(s)||s.text!=="Promise")return!1;let i=D(e,s);return!i||!v(e,i)}function B(e,t,n){let r=e.ts,s=`${U(e,t)}@${n.receiver?U(e,n.receiver):0}`,i=e.summaries.get(s);if(i&&(i.final||i.round===e.round))return i.busy&&(e.cyclic=!0),i.errors;i={errors:i?new Map(i.errors):new Map,busy:!0,round:e.round,final:!1},e.summaries.set(s,i);let o=i.errors.size,a={root:i.errors,scopes:[]};if(r.isFunctionLike(t)){let c=t;for(let l of c.parameters||[])l.initializer&&L(e,l.initializer,n,a);c.body&&L(e,c.body,n,a)}else L(e,t,n,a);return i.busy=!1,i.errors.size!==o&&(e.grew=!0),i.errors}function ie(e,t){return{root:e.root,scopes:[...e.scopes,t]}}function L(e,t,n,r){let s=e.ts;if(s.isTryStatement(t)){let o=new Map;L(e,t.tryBlock,n,ie(r,{kind:"try",node:t.tryBlock,sink:o}));let a=t.catchClause;(!a||(a.variableDeclaration&&s.isIdentifier(a.variableDeclaration.name)?Ke(s,a.block,a.variableDeclaration.name.text):a.variableDeclaration))&&R(e,r,t,!1,[...o.values()]),a&&L(e,a.block,n,r),t.finallyBlock&&L(e,t.finallyBlock,n,r);return}if(s.isThrowStatement(t))t.expression&&z(e,t.expression,n,r,t,!1);else if(s.isCallExpression(t)){let o=T(s,t.expression);if(yt(e,o,"allSettled")){L(e,t.expression,n,r);let u=ie(r,{kind:"settle",node:t});for(let m of t.arguments)L(e,m,n,u);return}let a=s.isPropertyAccessExpression(o)?o.name.text==="catch"?0:o.name.text==="then"&&t.arguments.length>1?1:-1:-1;if(a>=0){let u=o,m=pt(s,t.arguments[a]);L(e,u.expression,n,ie(r,{kind:"catch",node:u.expression,rethrows:m}));for(let g of t.arguments)L(e,g,n,r);return}let c=s.isPropertyAccessExpression(o)?et.get(o.name.text):void 0;c!==void 0&&t.arguments[c]&&z(e,t.arguments[c],n,r,t,!0);let l=ot(e,o);if(l.length>0){let u=O(e,t);R(e,r,t,!0,l.map(m=>({...m,site:u})))}for(let u of X(e,t,n))R(e,r,t,se(e,u.fn),[...B(e,u.fn,u.ctx).values()]);for(let u of t.arguments)for(let m of Ne(e,u,n))R(e,r,u,se(e,m.fn),[...B(e,m.fn,m.ctx).values()])}else if(s.isNewExpression(t)){let o=_(e,t.expression);if(o)for(let a of je(e,o,o))R(e,r,t,!1,[...B(e,a.fn,a.ctx).values()]);for(let a of t.arguments||[])for(let c of Ne(e,a,n))R(e,r,a,se(e,c.fn),[...B(e,c.fn,c.ctx).values()])}else if(s.isPropertyAccessExpression(t)&&!(t.parent&&s.isCallExpression(t.parent)&&t.parent.expression===t)){let o=D(e,t.name);if(o&&s.isGetAccessorDeclaration(o)&&o.body&&v(e,o))for(let a of E(e,t.expression,n)){let c=V(e,a,t.name.text,!1);c&&R(e,r,t,!1,[...B(e,c.fn,{receiver:a,owner:c.owner,fn:c.fn}).values()])}}if(F(s,t))return;let i=s.isFunctionExpression(t)||s.isFunctionDeclaration(t)?{receiver:null,owner:null,fn:t}:n;s.forEachChild(t,o=>L(e,o,i,r))}function _e(e,t,n){let r=e.ts;if(n.has(t))return[];if(n.add(t),I(e,t.expression)==="Resolve")return[t];let s=[];for(let i of X(e,t,{receiver:null,owner:null,fn:null}))for(let o of H(r,i.fn)){let a=T(r,o);r.isCallExpression(a)&&s.push(..._e(e,a,n))}return s}function Tt(e,t){let n=e.ts,r=[];for(let s of t.parameters)for(let i of n.getDecorators(s)||[]){let o=T(n,i.expression);if(n.isCallExpression(o))for(let a of _e(e,o,new Set)){let c=_(e,a.arguments[0]);if(!c)continue;let l=new Set;ae(e,Fe(e,c),l);for(let u of l){let m=V(e,u,"resolve",!1);m&&r.push({fn:m.fn,ctx:{receiver:u,owner:m.owner,fn:m.fn}})}}}return r}function ht(e){return e.charAt(0).toLowerCase()+e.slice(1)}function bt(e,t,n){let r=new Map;for(let i of Tt(e,n))for(let o of B(e,i.fn,i.ctx).values())r.has(o.code)||r.set(o.code,o);for(let i of B(e,n,{receiver:t,owner:t,fn:n}).values())r.has(i.code)||r.set(i.code,i);let s=new Map;for(let i of r.values()){let o=ht(i.name),a=s.get(o);if(a)throw new h(`${t.name.text}.${P(e.ts,n.name)} can throw two errors named "${i.name}" \u2014 "${a.code}" (${a.site}) and "${i.code}" (${i.site}). Every client names an error case after it; give one of them its own defineError`);s.set(o,i)}return[...r.values()].map(({name:i,code:o,status:a})=>({name:i,code:o,status:a}))}function xt(e,t){let n=[];for(let{cls:r,routes:s}of Z(e,t)){let i={};for(let o of s)i[P(e.ts,o.name)]=bt(e,r,o);n.push({className:r.name.text,ops:i})}return n}function _t(e,t,n={}){let r=n.typescript??wt,s=Ve(ue(e)),{options:i,ambient:o}=he(r,s);return kt(be(r,s,[Ve(ue(t)),...o],i))}function kt(e){let t=e.ts,n=ke(e),r=Le(e),s=[],i=e.program.getSourceFiles().filter(a=>$(e,a.fileName)).sort((a,c)=>a.fileName<c.fileName?-1:a.fileName>c.fileName?1:0),o=[];for(let a of i){let c=Z(e,a);if(c.length===0)continue;let l=new Map;for(let{cls:u,routes:m}of c)for(let g of m)try{l.set(`${u.name.text}.${P(t,g.name)}`,Ee(e,n,u.name.text,g))}catch(p){if(!(p instanceof h))throw p;o.push(p.message)}if(!(o.length>0))for(let{className:u,ops:m}of r.analyze(a))for(let[g,p]of Object.entries(m))s.push({file:ue(a.fileName),className:u,method:g,returns:l.get(`${u}.${g}`),throws:p})}if(o.length===1)throw new h(o[0]);if(o.length>1)throw new h(`${o.length} routes have no contract:
|
|
5
5
|
${o.map(a=>`- ${a}`).join(`
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.3.
|
|
2
|
-
import{a as D}from"./32BPNFZX.js";import{a as A,b as R,c as b,d as x,e as O,f as j,g as M,h as U,i as C,j as L,k as K,l as $}from"./CNRFJ7AK.js";import{a as N,b as I}from"./TTKDWRP5.js";import{b as v,d as w}from"./HHSKJTI6.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:M.client(e),purchases:U.client(e),realtime:C.client(e),secrets:L.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))),a=!1;for(let u of r)me(o,ge(u))&&(a=!0);if(!a)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 a of r.split(",")){let u=a.indexOf("=");if(u<=0)throw new f("malformed_signature","Palbase-Signature is t=<seconds>,v1=<hex>");let c=a.slice(0,u).trim(),i=a.slice(u+1).trim();if(c==="t"){if(s!==void 0||!de.test(i))throw new f("malformed_signature","Palbase-Signature carries one t, in unix seconds");s=i}else if(c==="v1"){if(!le.test(i))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(i)}}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=[],a=0;for(;;){let{done:i,value:l}=await s.read();if(i)break;if(a+=l.byteLength,a>e)throw await s.cancel().catch(()=>{}),t();o.push(l)}let u=new Uint8Array(a),c=0;for(let i of o)u.set(i,c),c+=i.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,a]of s)a>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 a=o.split(".");if(a.length!==3)return s("it is not a JWS of three parts");let u=J(a[0]),c=J(a[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 i=u.jwk;if(!i||typeof i!="object"||i.kty!=="EC"||i.crv!=="P-256"||typeof i.x!="string"||typeof i.y!="string")return s("its header carries no P-256 public key");if("d"in i)return s("its header carries a private key");if(await Ee(i.x,i.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:i.x,y:i.y,ext:!0},{name:"ECDSA",namedCurve:"P-256"},!1,["verify"])}catch{return s("its key is not a P-256 point")}let p=Y(a[2]);if(!p||!await crypto.subtle.verify({name:"ECDSA",hash:"SHA-256"},l,p,new TextEncoder().encode(`${a[0]}.${a[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;standingStaleMs;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??1e3,this.standingStaleMs=e.standingStaleMs??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 a=s.alg;if(!Z(a))throw new d("algorithm",`the token is signed with ${String(a)}; 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!==a)throw new d("algorithm",`key ${u} is ${c.alg}, the token says ${a}`);let i=te(r[2]);if(!i)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,i,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",a=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,a)}: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 a;try{a=await o}catch(c){let i=this.standings.get(t),l=this.now();if(i&&l<i.at+this.standingStaleMs)return i.until=Math.min(l+this.standingTtlMs,i.at+this.standingStaleMs),i.live;throw new g("a session's standing cannot be read now",{cause:c})}let u=this.now();return this.standings.delete(t),this.standings.set(t,{live:a,at:u,until:u+this.standingTtlMs}),this.standings.size>Ae&&this.standings.delete(this.standings.keys().next().value),a}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 a=o.alg;if(typeof o.kid!="string"||!Z(a))continue;let u=T[a];if(o.kty!==u.kty||o.use!==void 0&&o.use!=="sig")continue;let{d:c,...i}=o;try{r.set(o.kid,{alg:a,key:await crypto.subtle.importKey("jwk",i,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 Me(n,e,t,r){let{idempotencyKey:s,amount:o,ttlSeconds:a,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},...a!==void 0?{ttl_seconds:a}:{},...u!==void 0?{metadata:u}:{}},i=(await n.purchases.holdSpend({path:{customer_id:e},headers:{"Idempotency-Key":s},body:c})).data;if(i.status!=="held")throw new S(i);let l={customer_id:i.customer,spend_id:i.id},p;try{p=await r(i)}catch(m){throw await n.purchases.releaseSpend({path:l}).catch(()=>{}),m}return await n.purchases.commitSpend({path:l}),p}async function*Ue(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 Ce=/^[A-Za-z_][A-Za-z0-9_]{0,127}$/,Le=/^(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!Ce.test(n)||Le.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:a}=await o.secrets.getEnvironmentValues({path:{environment:t}}),u=[],c=[],i=[];for(let[l,p]of Object.entries(a.values)){if(ne(l)){i.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:i.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,Me as n,Ue as o,ne as p,$e as q,Ne as r};
|
|
1
|
+
/*! palbase 0.3.3 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import{a as D}from"./4YD2XCGF.js";import{a as A,b as R,c as b,d as x,e as O,f as j,g as M,h as U,i as C,j as L,k as K,l as $}from"./NK54UVDI.js";import{a as N,b as I}from"./IXHR57QC.js";import{b as v,d as w}from"./UXRIXHHY.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:M.client(e),purchases:U.client(e),realtime:C.client(e),secrets:L.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))),a=!1;for(let u of r)me(o,ge(u))&&(a=!0);if(!a)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 a of r.split(",")){let u=a.indexOf("=");if(u<=0)throw new f("malformed_signature","Palbase-Signature is t=<seconds>,v1=<hex>");let c=a.slice(0,u).trim(),i=a.slice(u+1).trim();if(c==="t"){if(s!==void 0||!de.test(i))throw new f("malformed_signature","Palbase-Signature carries one t, in unix seconds");s=i}else if(c==="v1"){if(!le.test(i))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(i)}}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=[],a=0;for(;;){let{done:i,value:l}=await s.read();if(i)break;if(a+=l.byteLength,a>e)throw await s.cancel().catch(()=>{}),t();o.push(l)}let u=new Uint8Array(a),c=0;for(let i of o)u.set(i,c),c+=i.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,a]of s)a>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 a=o.split(".");if(a.length!==3)return s("it is not a JWS of three parts");let u=J(a[0]),c=J(a[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 i=u.jwk;if(!i||typeof i!="object"||i.kty!=="EC"||i.crv!=="P-256"||typeof i.x!="string"||typeof i.y!="string")return s("its header carries no P-256 public key");if("d"in i)return s("its header carries a private key");if(await Ee(i.x,i.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:i.x,y:i.y,ext:!0},{name:"ECDSA",namedCurve:"P-256"},!1,["verify"])}catch{return s("its key is not a P-256 point")}let p=Y(a[2]);if(!p||!await crypto.subtle.verify({name:"ECDSA",hash:"SHA-256"},l,p,new TextEncoder().encode(`${a[0]}.${a[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;standingStaleMs;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??1e3,this.standingStaleMs=e.standingStaleMs??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 a=s.alg;if(!Z(a))throw new d("algorithm",`the token is signed with ${String(a)}; 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!==a)throw new d("algorithm",`key ${u} is ${c.alg}, the token says ${a}`);let i=te(r[2]);if(!i)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,i,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",a=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,a)}: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 a;try{a=await o}catch(c){let i=this.standings.get(t),l=this.now();if(i&&l<i.at+this.standingStaleMs)return i.until=Math.min(l+this.standingTtlMs,i.at+this.standingStaleMs),i.live;throw new g("a session's standing cannot be read now",{cause:c})}let u=this.now();return this.standings.delete(t),this.standings.set(t,{live:a,at:u,until:u+this.standingTtlMs}),this.standings.size>Ae&&this.standings.delete(this.standings.keys().next().value),a}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 a=o.alg;if(typeof o.kid!="string"||!Z(a))continue;let u=T[a];if(o.kty!==u.kty||o.use!==void 0&&o.use!=="sig")continue;let{d:c,...i}=o;try{r.set(o.kid,{alg:a,key:await crypto.subtle.importKey("jwk",i,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 Me(n,e,t,r){let{idempotencyKey:s,amount:o,ttlSeconds:a,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},...a!==void 0?{ttl_seconds:a}:{},...u!==void 0?{metadata:u}:{}},i=(await n.purchases.holdSpend({path:{customer_id:e},headers:{"Idempotency-Key":s},body:c})).data;if(i.status!=="held")throw new S(i);let l={customer_id:i.customer,spend_id:i.id},p;try{p=await r(i)}catch(m){throw await n.purchases.releaseSpend({path:l}).catch(()=>{}),m}return await n.purchases.commitSpend({path:l}),p}async function*Ue(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 Ce=/^[A-Za-z_][A-Za-z0-9_]{0,127}$/,Le=/^(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!Ce.test(n)||Le.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:a}=await o.secrets.getEnvironmentValues({path:{environment:t}}),u=[],c=[],i=[];for(let[l,p]of Object.entries(a.values)){if(ne(l)){i.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:i.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,Me as n,Ue as o,ne as p,$e as q,Ne as r};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.3.
|
|
1
|
+
/*! palbase 0.3.3 — Palbase SDK License (see LICENSE) */
|
|
2
2
|
var d=Object.defineProperty;var e=(c,a)=>{for(var b in a)d(c,b,{get:a[b],enumerable:!0})};export{e as a};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! palbase 0.3.
|
|
2
|
-
import{b as oe}from"./HHSKJTI6.js";var Jt=s=>[...new Uint8Array(s)].map(t=>t.toString(16).padStart(2,"0")).join(""),Ut=s=>`pw-font-${s}`;function ie(s){return(typeof s=="string"?/^asset:([0-9a-f-]{36})$/.exec(s):null)?.[1]}async function Ge(s,t={}){let n={},i=t.fetch??((p,l)=>globalThis.fetch(p,l));return await Promise.all(s.map(async p=>{try{if(!/^https:\/\//.test(p.url))return;let l=await i(p.url,{signal:t.signal,credentials:"omit"});if(!l.ok)return;let f=await l.arrayBuffer();if(f.byteLength!==p.bytes&&p.bytes>0||Jt(await globalThis.crypto.subtle.digest("SHA-256",f))!==p.sha256.toLowerCase())return;let g=Vt(p.kind,new Uint8Array(f));if(g===void 0)return;let h=await Bt(p,f,g,t);h&&(n[p.id]=h)}catch{}})),n}var F=(s,t,n=0)=>s.length>=n+t.length&&t.every((i,p)=>s[n+p]===i),q=s=>[...s].map(t=>t.charCodeAt(0));function Vt(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 Bt(s,t,n,i){switch(s.kind){case"image":case"video":return{kind:s.kind,url:URL.createObjectURL(new Blob([t],{type:n}))};case"font":{let p=Ut(s.id),l=globalThis.FontFace,f=i.fonts??globalThis.document?.fonts;if(!l||!f)return;let y=new l(p,t,{display:"block"});return await y.load(),f.add(y),{kind:"font",url:"",family:p}}case"html":{let p=await qt(new Uint8Array(t)),l=Yt(p);return l===void 0?void 0:{kind:"html",url:"",html:l}}}}async function qt(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 i=t.getUint16(n+10,!0),p=t.getUint32(n+16,!0),l=new Map,f=0;for(let y=0;y<i;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),x=t.getUint16(p+32,!0),R=t.getUint32(p+42,!0),b=new TextDecoder().decode(s.subarray(p+46,p+46+v));if(p+=46+v+M+x,b.endsWith("/"))continue;if(b.startsWith("/")||b.split("/").includes(".."))throw new Error("a path leaving the zip");if(f+=w,l.size>=200||f>20971520)throw new Error("a zip too large");let T=R+30+t.getUint16(R+26,!0)+t.getUint16(R+28,!0),C=s.subarray(T,T+h);if(g===0)l.set(b,C);else if(g===8)l.set(b,await Wt(C));else throw new Error("a zip entry compressed another way")}return l}async function Wt(s){let t=new Response(new Uint8Array(s)).body.pipeThrough(new DecompressionStream("deflate-raw"));return new Uint8Array(await new Response(t).arrayBuffer())}var Kt={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 Ye(s,t){let n=Kt[s.split(".").pop()?.toLowerCase()??""]??"application/octet-stream",i="";for(let p=0;p<t.length;p+=32768)i+=String.fromCharCode(...t.subarray(p,p+32768));return`data:${n};base64,${btoa(i)}`}var Xt="default-src 'none'; img-src data:; media-src data:; font-src data:; style-src 'unsafe-inline' data:; script-src 'unsafe-inline' data:";function Yt(s){let t=s.get("index.html");if(!t)return;let n=new TextDecoder().decode(t),i=h=>new TextDecoder().decode(s.get(h)),p=h=>{let w=h.replace(/^\.\//,"").split(/[?#]/)[0];return s.has(w)?w:void 0},l=h=>h.replace(/url\(\s*(['"]?)([^'")]+)\1\s*\)/g,(w,v,M)=>{let x=p(M);return x?`url("${Ye(x,s.get(x))}")`: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?l(i(w)):"",h.replaceWith(v)}for(let h of[...y.querySelectorAll("style")])h.textContent=l(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,Ye(M,s.get(M))):/^(https?:)?\/\//i.test(v)&&h.removeAttribute(w)}for(let h of[...y.querySelectorAll("[style]")])h.setAttribute("style",l(h.getAttribute("style")??""));let g=y.createElement("meta");return g.setAttribute("http-equiv","Content-Security-Policy"),g.setAttribute("content",Xt),y.head.prepend(g),`<!doctype html>${y.documentElement.outerHTML}`}var Ze=20,Qe=2048,et=256,Gt=/^[A-Za-z][A-Za-z0-9_.-]{0,39}$/,Q=s=>new oe({op:"GetPlacementPaywall",status:0,code:"invalid_attributes",message:s});function Zt(s){let t='"';for(let n=0;n<s.length;n++){let i=s.charCodeAt(n);i===34?t+='\\"':i===92?t+="\\\\":i>=32&&i<=126?t+=s[n]:t+=`\\u${i.toString(16).padStart(4,"0")}`}return`${t}"`}function tt(s){let t=Object.keys(s??{}).sort((p,l)=>p<l?-1:p>l?1:0);if(t.length===0)return;if(t.length>Ze)throw Q(`${t.length} attributes: at most ${Ze}`);let n=[];for(let p of t){if(!Gt.test(p))throw Q(`the attribute ${JSON.stringify(p)}: a key is a letter, then letters, digits and _ . -, at most 40`);let l=s[p],f;if(typeof l=="string"){if(new TextEncoder().encode(l).length>et)throw Q(`the attribute ${JSON.stringify(p)} is over ${et} bytes`);f=Zt(l)}else if(typeof l=="number"){if(!Number.isFinite(l))throw Q(`the attribute ${JSON.stringify(p)} is no number`);f=String(Object.is(l,-0)?0:l)}else if(typeof l=="boolean")f=l?"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 i=`{${n.join(",")}}`;if(i.length>Qe)throw Q(`the attributes are ${i.length} bytes: at most ${Qe}`);return i}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 nt(s){try{return new Intl.NumberFormat("en",{style:"currency",currency:s}).resolvedOptions().maximumFractionDigits??2}catch{return 2}}function st(s,t,n){let i=s/10**nt(t);try{return new Intl.NumberFormat(n,{style:"currency",currency:t}).format(i)}catch{return`${i.toFixed(nt(t))} ${t}`}}function Qt(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 en={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 tn(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 i=en[t.split("-")[0].toLowerCase()];return i?i(n):n}function nn(s,t){try{return new Intl.NumberFormat(t,{style:"percent",maximumFractionDigits:0}).format(s)}catch{return`${Math.round(s*100)}%`}}function rt(s,t){let n=new Map,i=new Map;for(let l of s){let f=_e(l.period);if(!f)continue;let y=l.price.amount/f.months;n.set(l.key,y),i.set(l.price.currency,Math.max(i.get(l.price.currency)??0,y))}let p={};for(let l of s){let f={product_name:l.productName,price:st(l.price.amount,l.price.currency,t)},y=_e(l.period);if(y){f.period=Qt(y,t),f.price_per_month=st(Math.round(n.get(l.key)),l.price.currency,t);let h=i.get(l.price.currency)??0,w=h>0?Math.floor((1-n.get(l.key)/h)*100)/100:0;w>=.01&&(f.savings=nn(w,t))}let g=l.intro?.mode==="free_trial"?_e(l.intro.duration):null;g&&(f.trial=tn(g,t)),p[l.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 ot="http://www.w3.org/2000/svg";function fe(s,t,n){let i=s.createElementNS(ot,"svg");i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("width",String(n)),i.setAttribute("height",String(n)),i.setAttribute("fill","none"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),i.setAttribute("aria-hidden","true"),i.setAttribute("focusable","false");for(let p of t){let l=s.createElementNS(ot,"path");l.setAttribute("d",p),i.append(l)}return i}var he=2,m=(s,t=!1)=>({kind:"value",value:"plain",def:s,required:t}),N=s=>({kind:"value",value:"color",def:s}),it=s=>({kind:"value",value:"spacing",def:s}),sn=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}),at=(s=!1)=>({kind:"component",required:s}),Le={kind:"components"},lt={stack:{axis:m("vertical"),spacing:it(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:at(!0)},purchase_button:{content:at(!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:it()},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:sn(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")}},rn={linear:"linear",radial:"radial",image:"image_fill",video:"video_fill"},on=["top","bottom","leading","trailing"],an=["top_leading","top_trailing","bottom_leading","bottom_trailing"],Fn=Object.keys(lt),ln=/\{\{\s*([^{}]*?)\s*\}\}/g,te=(s,t)=>typeof s=="object"&&s!==null&&Object.hasOwn(s,t),S=s=>typeof s=="object"&&s!==null&&!Array.isArray(s)?s:{},J=s=>Array.isArray(s)?s:[],X=(s,t)=>s??t;function cn(s){let t=Math.floor(s/86400),n=Math.floor(s%86400/3600),i=Math.floor(s%3600/60),p=s%60,l=y=>String(y).padStart(2,"0");return{countdown:t>0?`${t}d ${l(n)}:${l(i)}:${l(p)}`:n>0?`${n}:${l(i)}:${l(p)}`:`${l(i)}:${l(p)}`,days:String(t),hours:l(n),minutes:l(i),seconds:l(p)}}function ct(s){let t=[],n=p=>{if(Array.isArray(p))return p.forEach(n);if(typeof p!="object"||p===null)return;let l=p;if(l.type==="package"&&typeof l.product=="string"&&typeof l.plan=="string"){let f=`${l.product}.${l.plan}`;t.includes(f)||t.push(f)}for(let f of Object.keys(l).sort())n(l[f])},i=s;for(let p of["header","root","footer"])n(i[p]);for(let p of Object.keys(S(i.sheets)).sort())n(S(S(i.sheets)[p]).root);return t}function Cn(s,t){return new ge(s,t).resolve().tree}function dt(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 i=S(this.d.locales),p=String(this.d.default_locale??""),l=n.locale;te(i,l)||(l=l.split("-")[0]??"",te(i,l)||(l=p)),this.lang=l;for(let y of[p,l])for(let[g,h]of Object.entries(S(i[y])))typeof h=="string"&&(this.texts[g]=h);let f=S(this.d.theme);this.palette=S(S(f.colors)[n.appearance]);for(let[y,g]of Object.entries(S(f.typography))){let h={};for(let[w,v]of Object.entries(ee.typography)){let M=X(S(g)[w],v.def);M!=null&&(h[w]=M)}this.typography[y]=h}this.radii=S(f.radii),this.spacing=S(f.spacing)}resolve(){let[t,n]=this.initialState();this.tab=t,this.selected=n;let i={selected:n,theme:{colors:this.palette,typography:this.typography,radii:this.radii,spacing:this.spacing}};for(let l of["header","root","footer"]){let f=this.d[l];if(typeof f=="object"&&f!==null){let y=this.component(S(f),l,"",!1);y&&(i[l]=y)}}let p={};if(typeof this.d.sheets=="object"&&this.d.sheets!==null){let l={};for(let[f,y]of Object.entries(S(this.d.sheets))){let g=this.component(S(S(y).root),`sheets.${f}.root`,"",!1);g&&(l[f]=g);let h=this.text(S(y).title,this.packages[this.selected]);h!==null&&(p[f]=h)}i.sheets=l}return{tree:i,pathOf:l=>this.paths.get(l),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(S).map(f=>String(f.id)),l=this.opts.tabs?.[n];return l!==void 0&&p.includes(l)?l:this.opts.tab?this.opts.tab:typeof t.default=="string"&&t.default!==""?t.default:p[0]??""}initialState(){let t="",n="",i="",p="",l=(y,g)=>{if(Array.isArray(y)){y.forEach((w,v)=>l(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}`;i===""&&(i=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),l(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 x=S(v);x.id===w&&(typeof x.package=="string"&&p===""&&(p=x.package),l(x.content,`${g}.tabs[${M}].content`))});return}}for(let w of Object.keys(h).sort())w!=="sheets"&&l(h[w],g===""?w:`${g}.${w}`)};for(let y of["header","root","footer"])l(this.d[y],y);let f=this.opts.selected||p||n||i;return[t,f]}holds(t,n){let i=n||this.selected;for(let[p,l]of Object.entries(t))switch(p){case"selected_package":if(!J(l).includes(this.selected))return!1;break;case"intro_eligible":if((this.opts.eligible??[]).includes(i)!==l)return!1;break;case"platform":if(!J(l).includes(this.opts.platform))return!1;break;case"locale":if(!J(l).includes(this.opts.locale)&&!J(l).includes(this.lang))return!1;break;case"appearance":if(l!==this.opts.appearance)return!1;break;case"tab":if(l!==this.tab)return!1;break}return!0}component(t,n,i,p){if(typeof t.visible=="object"&&t.visible!==null&&!this.holds(S(t.visible),i))return null;let l=String(t.type),f=i,y=p;l==="package"&&(f=`${t.product}.${t.plan}`,y=f===this.selected);let g={type:l};this.paths.set(g,n),te(t,"id")&&(g.id=t.id);let h={...S(t.style)};y&&Object.assign(h,S(S(t.states).selected)),Object.keys(h).length>0&&(g.style=this.style(h)),typeof t.animation=="object"&&t.animation!==null&&(g.animation=this.defaults(S(t.animation),ee.animation));let w=this.packages[f||this.selected];switch(l){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(S(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(lt[l]??{})){if(l==="package"&&(v==="product"||v==="plan"||v==="selected"))continue;let x=t[v],R=te(t,v);switch(M.kind){case"component":{if(!R)continue;let b=this.component(S(x),`${n}.${v}`,f,y);if(!b&&M.required)return null;b&&(g[v]=b);break}case"components":{let b=[];J(x).forEach((T,C)=>{let K=this.component(S(T),`${n}.${v}[${C}]`,f,y);K&&b.push(K)}),g[v]=b;break}case"text":{let b=this.text(x,w);if(b!==null)g[v]=b;else if(M.required||l==="text"&&v==="text"&&R)return null;break}case"list":{let b=[];for(let T of J(x)){let C=this.item(M.item,S(T),w);C&&b.push(C)}if(l==="text"&&b.length===0&&R)return null;R&&(g[v]=b);break}case"object":{R?g[v]=this.object(S(x),M.item,w):v==="indicator"&&(g[v]=this.object({},M.item,w));break}case"value":{let b=this.value(X(x,M.def),M);b!=null&&b!==""&&(g[v]=b);break}}}return l==="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 i of["font","weight","line_height","letter_spacing","text_style"])!te(t,i)&&n?.[i]!==void 0&&n?.[i]!==null&&(t[i]=n[i]);t.size=n?.size??null}tabs(t,n,i,p){let l=this.tabShown(t,i);this.tabsShown[i]=l;let f=[];return J(t.tabs).forEach((y,g)=>{let h=S(y),w=h.id===l,v=this.component(S(h.label),`${i}.tabs[${g}].label`,p,w);if(f.push({id:h.id,selected:w,label:v}),w){let M=this.component(S(h.content),`${i}.tabs[${g}].content`,p,!1);M&&(n.content=M)}}),n.tabs=f,typeof t.bar=="object"&&t.bar!==null&&(n.bar=this.style(S(t.bar))),n}switchOf(t,n,i,p,l){let f=this.switchOn(t,i);this.switchesOn[i]=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(S(t[g]),`${i}.${g}`,p,l);return h&&(n.content=h),n}countdown(t,n,i,p,l){let f=S(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[i]=g;let h=this.packages,w={};for(let[M,x]of Object.entries(h))w[M]={...x,...cn(g)};this.packages=w;let v=this.component(S(t.counting),`${i}.counting`,p,l);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(S(t.ended),`${i}.ended`,p,l);h&&(n.content=h)}return n}item(t,n,i){let p={};for(let[l,f]of Object.entries(ee[t]??{})){let y=n[l];if(f.kind==="text"){let g=this.text(y,i);if(g!==null)p[l]=g;else if(f.required)return null}else{let g=f.def,h=this.value(X(y,g),f);h!=null&&(te(n,l)||g!=null&&g!=="")&&(p[l]=h)}}return p}object(t,n,i){return n==="style"?this.style(t):this.item(n,t,i)??{}}defaults(t,n){let i={};for(let[p,l]of Object.entries(n)){let f=X(t[p],l.def);f!=null&&f!==""&&(i[p]=f)}return i}style(t){let n={};for(let[i,p]of Object.entries(t)){let l=ee.style[i];if(!l){n[i]=p;continue}switch(l.kind){case"edges":n[i]=this.sides(p,on,this.spacing);break;case"corners":n[i]=this.sides(p,an,this.radii);break;case"fill":n[i]=this.fill(p);break;case"object":{let f=S(p),y={};for(let[g,h]of Object.entries(ee[l.item]??{})){let w=X(f[g],h.def);w!=null&&w!==""&&(y[g]=this.value(w,h))}n[i]=y;break}default:n[i]=p}}return n}sides(t,n,i){let p={};for(let l of n){let f=typeof t=="object"&&t!==null?X(S(t)[l],0):t;p[l]=$e(f,i)}return p}fill(t){if(typeof t=="string")return{type:"color",color:this.color(t)};let n=S(t),i=this.defaults(n,ee[rn[String(n.type)]??""]??{});return Array.isArray(n.stops)&&(i.stops=n.stops.map(p=>({color:this.color(String(S(p).color)),at:S(p).at}))),i}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 i;if(typeof t=="string")i=t;else if(typeof t=="object"&&t!==null&&!Array.isArray(t)){let l=t.t;i=typeof l=="string"&&Object.hasOwn(this.texts,l)?this.texts[l]:""}else return null;let p=!1;return i=i.replace(ln,(l,f)=>{let y=n&&Object.hasOwn(n,f)?n[f]:void 0;return typeof y!="string"||y===""?(p=!0,""):y}),p||i.trim()===""?null:i}};function $e(s,t){return typeof s=="string"?Object.hasOwn(t,s)?t[s]:null:s}var dn={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'},pn=1.35,pt=20,un=new Set(["button","purchase_button","package","text"]),fn=new Set(["ar","he","fa","ur","ps","yi","dv","ug","ku","sd"]),ut={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)"},gn={start:"flex-start",center:"center",end:"flex-end",stretch:"stretch"},hn={start:"flex-start",center:"center",end:"flex-end",space_between:"space-between",space_around:"space-around",space_evenly:"space-evenly"},yn={stack:["children"],package:["children"],button:["content"],purchase_button:["content"],tabs:["tabs","content"],switch:["content"],carousel:["pages"],countdown:["content"]},mn={package:["selected"],purchase_button:["package"],switch:["on"],countdown:["state","remaining_seconds"]},wn=`
|
|
1
|
+
/*! palbase 0.3.3 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import{b as oe}from"./UXRIXHHY.js";var Jt=s=>[...new Uint8Array(s)].map(t=>t.toString(16).padStart(2,"0")).join(""),Ut=s=>`pw-font-${s}`;function ie(s){return(typeof s=="string"?/^asset:([0-9a-f-]{36})$/.exec(s):null)?.[1]}async function Ge(s,t={}){let n={},i=t.fetch??((p,l)=>globalThis.fetch(p,l));return await Promise.all(s.map(async p=>{try{if(!/^https:\/\//.test(p.url))return;let l=await i(p.url,{signal:t.signal,credentials:"omit"});if(!l.ok)return;let f=await l.arrayBuffer();if(f.byteLength!==p.bytes&&p.bytes>0||Jt(await globalThis.crypto.subtle.digest("SHA-256",f))!==p.sha256.toLowerCase())return;let g=Vt(p.kind,new Uint8Array(f));if(g===void 0)return;let h=await Bt(p,f,g,t);h&&(n[p.id]=h)}catch{}})),n}var F=(s,t,n=0)=>s.length>=n+t.length&&t.every((i,p)=>s[n+p]===i),q=s=>[...s].map(t=>t.charCodeAt(0));function Vt(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 Bt(s,t,n,i){switch(s.kind){case"image":case"video":return{kind:s.kind,url:URL.createObjectURL(new Blob([t],{type:n}))};case"font":{let p=Ut(s.id),l=globalThis.FontFace,f=i.fonts??globalThis.document?.fonts;if(!l||!f)return;let y=new l(p,t,{display:"block"});return await y.load(),f.add(y),{kind:"font",url:"",family:p}}case"html":{let p=await qt(new Uint8Array(t)),l=Yt(p);return l===void 0?void 0:{kind:"html",url:"",html:l}}}}async function qt(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 i=t.getUint16(n+10,!0),p=t.getUint32(n+16,!0),l=new Map,f=0;for(let y=0;y<i;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),x=t.getUint16(p+32,!0),R=t.getUint32(p+42,!0),b=new TextDecoder().decode(s.subarray(p+46,p+46+v));if(p+=46+v+M+x,b.endsWith("/"))continue;if(b.startsWith("/")||b.split("/").includes(".."))throw new Error("a path leaving the zip");if(f+=w,l.size>=200||f>20971520)throw new Error("a zip too large");let T=R+30+t.getUint16(R+26,!0)+t.getUint16(R+28,!0),C=s.subarray(T,T+h);if(g===0)l.set(b,C);else if(g===8)l.set(b,await Wt(C));else throw new Error("a zip entry compressed another way")}return l}async function Wt(s){let t=new Response(new Uint8Array(s)).body.pipeThrough(new DecompressionStream("deflate-raw"));return new Uint8Array(await new Response(t).arrayBuffer())}var Kt={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 Ye(s,t){let n=Kt[s.split(".").pop()?.toLowerCase()??""]??"application/octet-stream",i="";for(let p=0;p<t.length;p+=32768)i+=String.fromCharCode(...t.subarray(p,p+32768));return`data:${n};base64,${btoa(i)}`}var Xt="default-src 'none'; img-src data:; media-src data:; font-src data:; style-src 'unsafe-inline' data:; script-src 'unsafe-inline' data:";function Yt(s){let t=s.get("index.html");if(!t)return;let n=new TextDecoder().decode(t),i=h=>new TextDecoder().decode(s.get(h)),p=h=>{let w=h.replace(/^\.\//,"").split(/[?#]/)[0];return s.has(w)?w:void 0},l=h=>h.replace(/url\(\s*(['"]?)([^'")]+)\1\s*\)/g,(w,v,M)=>{let x=p(M);return x?`url("${Ye(x,s.get(x))}")`: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?l(i(w)):"",h.replaceWith(v)}for(let h of[...y.querySelectorAll("style")])h.textContent=l(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,Ye(M,s.get(M))):/^(https?:)?\/\//i.test(v)&&h.removeAttribute(w)}for(let h of[...y.querySelectorAll("[style]")])h.setAttribute("style",l(h.getAttribute("style")??""));let g=y.createElement("meta");return g.setAttribute("http-equiv","Content-Security-Policy"),g.setAttribute("content",Xt),y.head.prepend(g),`<!doctype html>${y.documentElement.outerHTML}`}var Ze=20,Qe=2048,et=256,Gt=/^[A-Za-z][A-Za-z0-9_.-]{0,39}$/,Q=s=>new oe({op:"GetPlacementPaywall",status:0,code:"invalid_attributes",message:s});function Zt(s){let t='"';for(let n=0;n<s.length;n++){let i=s.charCodeAt(n);i===34?t+='\\"':i===92?t+="\\\\":i>=32&&i<=126?t+=s[n]:t+=`\\u${i.toString(16).padStart(4,"0")}`}return`${t}"`}function tt(s){let t=Object.keys(s??{}).sort((p,l)=>p<l?-1:p>l?1:0);if(t.length===0)return;if(t.length>Ze)throw Q(`${t.length} attributes: at most ${Ze}`);let n=[];for(let p of t){if(!Gt.test(p))throw Q(`the attribute ${JSON.stringify(p)}: a key is a letter, then letters, digits and _ . -, at most 40`);let l=s[p],f;if(typeof l=="string"){if(new TextEncoder().encode(l).length>et)throw Q(`the attribute ${JSON.stringify(p)} is over ${et} bytes`);f=Zt(l)}else if(typeof l=="number"){if(!Number.isFinite(l))throw Q(`the attribute ${JSON.stringify(p)} is no number`);f=String(Object.is(l,-0)?0:l)}else if(typeof l=="boolean")f=l?"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 i=`{${n.join(",")}}`;if(i.length>Qe)throw Q(`the attributes are ${i.length} bytes: at most ${Qe}`);return i}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 nt(s){try{return new Intl.NumberFormat("en",{style:"currency",currency:s}).resolvedOptions().maximumFractionDigits??2}catch{return 2}}function st(s,t,n){let i=s/10**nt(t);try{return new Intl.NumberFormat(n,{style:"currency",currency:t}).format(i)}catch{return`${i.toFixed(nt(t))} ${t}`}}function Qt(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 en={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 tn(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 i=en[t.split("-")[0].toLowerCase()];return i?i(n):n}function nn(s,t){try{return new Intl.NumberFormat(t,{style:"percent",maximumFractionDigits:0}).format(s)}catch{return`${Math.round(s*100)}%`}}function rt(s,t){let n=new Map,i=new Map;for(let l of s){let f=_e(l.period);if(!f)continue;let y=l.price.amount/f.months;n.set(l.key,y),i.set(l.price.currency,Math.max(i.get(l.price.currency)??0,y))}let p={};for(let l of s){let f={product_name:l.productName,price:st(l.price.amount,l.price.currency,t)},y=_e(l.period);if(y){f.period=Qt(y,t),f.price_per_month=st(Math.round(n.get(l.key)),l.price.currency,t);let h=i.get(l.price.currency)??0,w=h>0?Math.floor((1-n.get(l.key)/h)*100)/100:0;w>=.01&&(f.savings=nn(w,t))}let g=l.intro?.mode==="free_trial"?_e(l.intro.duration):null;g&&(f.trial=tn(g,t)),p[l.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 ot="http://www.w3.org/2000/svg";function fe(s,t,n){let i=s.createElementNS(ot,"svg");i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("width",String(n)),i.setAttribute("height",String(n)),i.setAttribute("fill","none"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),i.setAttribute("aria-hidden","true"),i.setAttribute("focusable","false");for(let p of t){let l=s.createElementNS(ot,"path");l.setAttribute("d",p),i.append(l)}return i}var he=2,m=(s,t=!1)=>({kind:"value",value:"plain",def:s,required:t}),N=s=>({kind:"value",value:"color",def:s}),it=s=>({kind:"value",value:"spacing",def:s}),sn=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}),at=(s=!1)=>({kind:"component",required:s}),Le={kind:"components"},lt={stack:{axis:m("vertical"),spacing:it(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:at(!0)},purchase_button:{content:at(!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:it()},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:sn(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")}},rn={linear:"linear",radial:"radial",image:"image_fill",video:"video_fill"},on=["top","bottom","leading","trailing"],an=["top_leading","top_trailing","bottom_leading","bottom_trailing"],Fn=Object.keys(lt),ln=/\{\{\s*([^{}]*?)\s*\}\}/g,te=(s,t)=>typeof s=="object"&&s!==null&&Object.hasOwn(s,t),S=s=>typeof s=="object"&&s!==null&&!Array.isArray(s)?s:{},J=s=>Array.isArray(s)?s:[],X=(s,t)=>s??t;function cn(s){let t=Math.floor(s/86400),n=Math.floor(s%86400/3600),i=Math.floor(s%3600/60),p=s%60,l=y=>String(y).padStart(2,"0");return{countdown:t>0?`${t}d ${l(n)}:${l(i)}:${l(p)}`:n>0?`${n}:${l(i)}:${l(p)}`:`${l(i)}:${l(p)}`,days:String(t),hours:l(n),minutes:l(i),seconds:l(p)}}function ct(s){let t=[],n=p=>{if(Array.isArray(p))return p.forEach(n);if(typeof p!="object"||p===null)return;let l=p;if(l.type==="package"&&typeof l.product=="string"&&typeof l.plan=="string"){let f=`${l.product}.${l.plan}`;t.includes(f)||t.push(f)}for(let f of Object.keys(l).sort())n(l[f])},i=s;for(let p of["header","root","footer"])n(i[p]);for(let p of Object.keys(S(i.sheets)).sort())n(S(S(i.sheets)[p]).root);return t}function Cn(s,t){return new ge(s,t).resolve().tree}function dt(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 i=S(this.d.locales),p=String(this.d.default_locale??""),l=n.locale;te(i,l)||(l=l.split("-")[0]??"",te(i,l)||(l=p)),this.lang=l;for(let y of[p,l])for(let[g,h]of Object.entries(S(i[y])))typeof h=="string"&&(this.texts[g]=h);let f=S(this.d.theme);this.palette=S(S(f.colors)[n.appearance]);for(let[y,g]of Object.entries(S(f.typography))){let h={};for(let[w,v]of Object.entries(ee.typography)){let M=X(S(g)[w],v.def);M!=null&&(h[w]=M)}this.typography[y]=h}this.radii=S(f.radii),this.spacing=S(f.spacing)}resolve(){let[t,n]=this.initialState();this.tab=t,this.selected=n;let i={selected:n,theme:{colors:this.palette,typography:this.typography,radii:this.radii,spacing:this.spacing}};for(let l of["header","root","footer"]){let f=this.d[l];if(typeof f=="object"&&f!==null){let y=this.component(S(f),l,"",!1);y&&(i[l]=y)}}let p={};if(typeof this.d.sheets=="object"&&this.d.sheets!==null){let l={};for(let[f,y]of Object.entries(S(this.d.sheets))){let g=this.component(S(S(y).root),`sheets.${f}.root`,"",!1);g&&(l[f]=g);let h=this.text(S(y).title,this.packages[this.selected]);h!==null&&(p[f]=h)}i.sheets=l}return{tree:i,pathOf:l=>this.paths.get(l),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(S).map(f=>String(f.id)),l=this.opts.tabs?.[n];return l!==void 0&&p.includes(l)?l:this.opts.tab?this.opts.tab:typeof t.default=="string"&&t.default!==""?t.default:p[0]??""}initialState(){let t="",n="",i="",p="",l=(y,g)=>{if(Array.isArray(y)){y.forEach((w,v)=>l(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}`;i===""&&(i=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),l(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 x=S(v);x.id===w&&(typeof x.package=="string"&&p===""&&(p=x.package),l(x.content,`${g}.tabs[${M}].content`))});return}}for(let w of Object.keys(h).sort())w!=="sheets"&&l(h[w],g===""?w:`${g}.${w}`)};for(let y of["header","root","footer"])l(this.d[y],y);let f=this.opts.selected||p||n||i;return[t,f]}holds(t,n){let i=n||this.selected;for(let[p,l]of Object.entries(t))switch(p){case"selected_package":if(!J(l).includes(this.selected))return!1;break;case"intro_eligible":if((this.opts.eligible??[]).includes(i)!==l)return!1;break;case"platform":if(!J(l).includes(this.opts.platform))return!1;break;case"locale":if(!J(l).includes(this.opts.locale)&&!J(l).includes(this.lang))return!1;break;case"appearance":if(l!==this.opts.appearance)return!1;break;case"tab":if(l!==this.tab)return!1;break}return!0}component(t,n,i,p){if(typeof t.visible=="object"&&t.visible!==null&&!this.holds(S(t.visible),i))return null;let l=String(t.type),f=i,y=p;l==="package"&&(f=`${t.product}.${t.plan}`,y=f===this.selected);let g={type:l};this.paths.set(g,n),te(t,"id")&&(g.id=t.id);let h={...S(t.style)};y&&Object.assign(h,S(S(t.states).selected)),Object.keys(h).length>0&&(g.style=this.style(h)),typeof t.animation=="object"&&t.animation!==null&&(g.animation=this.defaults(S(t.animation),ee.animation));let w=this.packages[f||this.selected];switch(l){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(S(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(lt[l]??{})){if(l==="package"&&(v==="product"||v==="plan"||v==="selected"))continue;let x=t[v],R=te(t,v);switch(M.kind){case"component":{if(!R)continue;let b=this.component(S(x),`${n}.${v}`,f,y);if(!b&&M.required)return null;b&&(g[v]=b);break}case"components":{let b=[];J(x).forEach((T,C)=>{let K=this.component(S(T),`${n}.${v}[${C}]`,f,y);K&&b.push(K)}),g[v]=b;break}case"text":{let b=this.text(x,w);if(b!==null)g[v]=b;else if(M.required||l==="text"&&v==="text"&&R)return null;break}case"list":{let b=[];for(let T of J(x)){let C=this.item(M.item,S(T),w);C&&b.push(C)}if(l==="text"&&b.length===0&&R)return null;R&&(g[v]=b);break}case"object":{R?g[v]=this.object(S(x),M.item,w):v==="indicator"&&(g[v]=this.object({},M.item,w));break}case"value":{let b=this.value(X(x,M.def),M);b!=null&&b!==""&&(g[v]=b);break}}}return l==="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 i of["font","weight","line_height","letter_spacing","text_style"])!te(t,i)&&n?.[i]!==void 0&&n?.[i]!==null&&(t[i]=n[i]);t.size=n?.size??null}tabs(t,n,i,p){let l=this.tabShown(t,i);this.tabsShown[i]=l;let f=[];return J(t.tabs).forEach((y,g)=>{let h=S(y),w=h.id===l,v=this.component(S(h.label),`${i}.tabs[${g}].label`,p,w);if(f.push({id:h.id,selected:w,label:v}),w){let M=this.component(S(h.content),`${i}.tabs[${g}].content`,p,!1);M&&(n.content=M)}}),n.tabs=f,typeof t.bar=="object"&&t.bar!==null&&(n.bar=this.style(S(t.bar))),n}switchOf(t,n,i,p,l){let f=this.switchOn(t,i);this.switchesOn[i]=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(S(t[g]),`${i}.${g}`,p,l);return h&&(n.content=h),n}countdown(t,n,i,p,l){let f=S(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[i]=g;let h=this.packages,w={};for(let[M,x]of Object.entries(h))w[M]={...x,...cn(g)};this.packages=w;let v=this.component(S(t.counting),`${i}.counting`,p,l);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(S(t.ended),`${i}.ended`,p,l);h&&(n.content=h)}return n}item(t,n,i){let p={};for(let[l,f]of Object.entries(ee[t]??{})){let y=n[l];if(f.kind==="text"){let g=this.text(y,i);if(g!==null)p[l]=g;else if(f.required)return null}else{let g=f.def,h=this.value(X(y,g),f);h!=null&&(te(n,l)||g!=null&&g!=="")&&(p[l]=h)}}return p}object(t,n,i){return n==="style"?this.style(t):this.item(n,t,i)??{}}defaults(t,n){let i={};for(let[p,l]of Object.entries(n)){let f=X(t[p],l.def);f!=null&&f!==""&&(i[p]=f)}return i}style(t){let n={};for(let[i,p]of Object.entries(t)){let l=ee.style[i];if(!l){n[i]=p;continue}switch(l.kind){case"edges":n[i]=this.sides(p,on,this.spacing);break;case"corners":n[i]=this.sides(p,an,this.radii);break;case"fill":n[i]=this.fill(p);break;case"object":{let f=S(p),y={};for(let[g,h]of Object.entries(ee[l.item]??{})){let w=X(f[g],h.def);w!=null&&w!==""&&(y[g]=this.value(w,h))}n[i]=y;break}default:n[i]=p}}return n}sides(t,n,i){let p={};for(let l of n){let f=typeof t=="object"&&t!==null?X(S(t)[l],0):t;p[l]=$e(f,i)}return p}fill(t){if(typeof t=="string")return{type:"color",color:this.color(t)};let n=S(t),i=this.defaults(n,ee[rn[String(n.type)]??""]??{});return Array.isArray(n.stops)&&(i.stops=n.stops.map(p=>({color:this.color(String(S(p).color)),at:S(p).at}))),i}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 i;if(typeof t=="string")i=t;else if(typeof t=="object"&&t!==null&&!Array.isArray(t)){let l=t.t;i=typeof l=="string"&&Object.hasOwn(this.texts,l)?this.texts[l]:""}else return null;let p=!1;return i=i.replace(ln,(l,f)=>{let y=n&&Object.hasOwn(n,f)?n[f]:void 0;return typeof y!="string"||y===""?(p=!0,""):y}),p||i.trim()===""?null:i}};function $e(s,t){return typeof s=="string"?Object.hasOwn(t,s)?t[s]:null:s}var dn={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'},pn=1.35,pt=20,un=new Set(["button","purchase_button","package","text"]),fn=new Set(["ar","he","fa","ur","ps","yi","dv","ug","ku","sd"]),ut={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)"},gn={start:"flex-start",center:"center",end:"flex-end",stretch:"stretch"},hn={start:"flex-start",center:"center",end:"flex-end",space_between:"space-between",space_around:"space-around",space_evenly:"space-evenly"},yn={stack:["children"],package:["children"],button:["content"],purchase_button:["content"],tabs:["tabs","content"],switch:["content"],carousel:["pages"],countdown:["content"]},mn={package:["selected"],purchase_button:["package"],switch:["on"],countdown:["state","remaining_seconds"]},wn=`
|
|
3
3
|
:host{display:block;height:100%}
|
|
4
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
5
|
.pw2 *,.pw2 *::before,.pw2 *::after{box-sizing:border-box}
|
|
@@ -89,4 +89,4 @@ button.pw-c:disabled{cursor:default;opacity:.5}
|
|
|
89
89
|
[data-pw-hover]:not([data-pw-highlight]){outline:1px dashed #2E7CF6aa!important;outline-offset:-1px}
|
|
90
90
|
.pw-editing button,.pw-editing .pw-pkg,.pw-editing a{cursor:default}
|
|
91
91
|
@media (prefers-reduced-motion:reduce){.pw2 *{transition:none!important;scroll-behavior:auto!important}}
|
|
92
|
-
`,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}},bn=s=>`${String(s.product)}.${String(s.plan)}`,Te=s=>{let[t,n]=s.split(".");return{product:t??"",plan:n??""}},_=s=>`${Number(s)||0}px`,ft=s=>`${s/16}rem`,vn=0;function gt(s,t,n){let i=s.ownerDocument,p=i.defaultView,l=`pw${++vn}`,f=i.createElement("div");f.setAttribute("data-palbase-paywall",""),f.style.display="block",f.style.height="100%";let y=f.attachShadow({mode:"open"});kn(i,y,wn);let g=i.createElement("div");g.className="pw2";let h=i.createElement("div");h.className="pw2-head";let w=i.createElement("div");w.className="pw2-body";let v=i.createElement("div");v.className="pw2-foot";let M=i.createElement("div");g.append(h,w,v),y.append(g),s.replaceChildren(f);let x={...t},R={openedAt:Date.now(),...t.state},b,T=new Map,C=new Map,K=!1,be=null,ve,Oe=!1,Fe=i.defaultView?.ResizeObserver,Ce=typeof Fe=="function"?new Fe(()=>{g.classList.toggle("pw2-large",Ne()>=pt),xe()}):null;Ce?.observe(g);let He=()=>xe();i.fonts?.addEventListener?.("loadingdone",He);let je=null,ke=p?.matchMedia?.("(prefers-reduced-motion: reduce)"),re=()=>x.reduceMotion??ke?.matches??!1,H=()=>!!n.editor,le={...dn,...n.labels};function G(){let e=R.now??Date.now();b=dt(x.definition,{locale:x.locale,appearance:x.appearance,platform:x.platform??"web",packages:x.packages,eligible:x.eligible??[],...R.selected?{selected:R.selected}:{},tabs:R.tabs??{},switches:R.switches??{},openedSecondsAgo:Math.max(0,Math.floor((e-(R.openedAt??e))/1e3)),now:e});let c=b.tree.theme.colors;g.style.background=c.background??"",g.style.color=c.text??"",g.classList.toggle("pw-editing",H()),g.classList.toggle("pw2-large",Ne()>=pt),g.lang=b.language,g.dir=fn.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),Nt();for(let[o,r]of T)C.has(o)||r.cleanup.forEach(a=>a());T=C,be&&We(be);for(let o of T.values())o.type==="custom_html"&&qe(o.el);xe(),clearTimeout(ve),Oe||=f.isConnected,R.now===void 0&&Object.keys(b.countdowns).length>0&&(ve=setTimeout(()=>{Oe&&!f.isConnected||G()},1e3-Date.now()%1e3+5))}function Ne(){let e=i.documentElement,c=e&&p?parseFloat(p.getComputedStyle(e).fontSize):NaN;return Number.isFinite(c)?c:16}function xe(){let e=[];for(let o of T.values()){if(o.type!=="text")continue;let r=o.el,a=r.dataset.pwFit??r.style.fontSize;if(!a||(r.style.fontSize=a,delete r.dataset.pwFit,!/^\S+$/.test(r.textContent??"")))continue;let d=r.parentElement,u=d&&p?p.getComputedStyle(d):null,k=d&&u?d.clientWidth-parseFloat(u.paddingLeft||"0")-parseFloat(u.paddingRight||"0"):1/0,A=Math.min(r.clientWidth,k);e.push({e:r,base:a,k:A<=0||r.scrollWidth<=A+.5?1:Math.max(.6,A/r.scrollWidth)})}let c=o=>o.closest(".pw-stack.h");for(let o of e){let r=Math.min(o.k,...e.filter(a=>a!==o&&a.base===o.base&&c(a.e)&&c(a.e)===c(o.e)).map(a=>a.k));r>=1||(o.e.dataset.pwFit=o.base,o.e.style.fontSize=`calc(${o.base} * ${r.toFixed(3)})`)}}function Pe(e,c,o){let r=c?U(c,o,{inControl:!1,inSheet:!1,inFooter:e===v}):null;V(e,r?[r]:[])}function U(e,c,o){let r=b.pathOf(e)??"",a=vt(e),d=T.get(r),u;if(d&&d.type===e.type&&d.key===a&&d.axis===c&&!C.has(r))u=d;else{let A=xt(e,r,c,o);if(!A)return null;u={el:A.el,type:e.type,key:a,styleKey:"",axis:c,slots:A.slots,cleanup:A.cleanup??[]},u.el.classList.add("pw-c"),u.el.dataset.pwPath=r,u.el.dataset.pwType=e.type,e.id&&(u.el.dataset.pwId=e.id),d&&d.cleanup.forEach(L=>L()),Ot(u.el,e)}let k=`${JSON.stringify(e.style??null)}|${c}`;return u.styleKey!==k&&(De(u.el,e,c),u.styleKey=k),C.set(r,u),$t(u,e),Tt(u,e,o),u.el}function vt(e){let c=new Set(["style",...yn[e.type]??[],...mn[e.type]??[]]),o={};for(let[r,a]of Object.entries(e))c.has(r)||(o[r]=a);return e.type==="tabs"&&(o.tabs=e.tabs.map(r=>r.id)),e.type==="carousel"&&(o.pages=e.pages.length),e.type==="stack"&&(o.greedy=e.children.some(r=>r.type==="spacer"&&typeof r.size!="number")),(e.type==="image"||e.type==="video"||e.type==="custom_html")&&(o.asset=kt(e)),JSON.stringify(o)}function kt(e){let c=ie(e.src);return c?(x.assets?.[c]?.url??x.assets?.[c]?.html?.length??"none").toString():""}function P(e,c){let o=i.createElement(e);return c&&(o.className=c),o}function xt(e,c,o,r){let a=e;switch(e.type){case"stack":{let d=P("div",`pw-stack${a.axis==="horizontal"?" h":a.axis==="z"?" z":""}${a.scroll?" scroll":""}`);return a.axis!=="z"&&a.children.some(u=>u.type==="spacer"&&typeof u.size!="number")&&d.classList.add(a.axis==="horizontal"?"greedy-h":"greedy-v"),d.style.gap=_(a.spacing),a.axis==="z"?d.style.placeItems=a.align==="stretch"?"stretch":String(a.align??"center"):(d.style.alignItems=gn[String(a.align)]??"center",d.style.justifyContent=hn[String(a.distribution)]??"flex-start"),{el:d,slots:{children:d}}}case"text":return{el:Pt(a,r),slots:{}};case"icon":{let d=ue[String(a.name)];if(!d)return null;let u=P("span","pw-icon");return u.style.color=String(a.color??""),u.append(fe(i,d,Number(a.size)||24)),u.setAttribute("aria-hidden","true"),{el:u,slots:{}}}case"image":return At(a);case"video":return St(a);case"features":{let d=P("ul","pw-features");d.style.gap=_(a.spacing);for(let u of a.items??[]){let k=P("li","pw-feature"),A=ue[u.icon];if(A){let z=fe(i,A,22);z.style.color=String(a.icon_color),z.style.flex="none",k.append(z)}let L=P("span");L.textContent=u.text,L.style.color=String(a.color),k.append(L),d.append(k)}return{el:d,slots:{}}}case"timeline":{let d=P("ol","pw-timeline");d.style.gap=_(a.spacing),d.style.setProperty("--pw-gap",_(a.spacing)),d.style.setProperty("--pw-line-w",_(a.line_width));for(let u of a.items??[]){let k=P("li","pw-step"),A=P("span","pw-dot");A.style.background=u.color??String(a.line_color),A.style.color=String(a.icon_color);let L=ue[u.icon];L&&A.append(fe(i,L,18)),A.setAttribute("aria-hidden","true");let z=P("span","pw-line");z.style.background=String(a.line_color),z.setAttribute("aria-hidden","true");let D=P("span");D.style.color=String(a.color);let B=P("span","pw-step-title");if(B.textContent=u.title,D.append(B),u.text){let $=P("span","pw-step-text");$.style.display="block",$.textContent=u.text,D.append($)}k.append(A,D,z),d.append(k)}return{el:d,slots:{}}}case"spacer":{let d=P("div","pw-spacer");return d.setAttribute("aria-hidden","true"),typeof a.size=="number"&&(d.style.flex="none",o==="horizontal"?d.style.width=_(a.size):d.style.height=_(a.size)),{el:d,slots:{}}}case"divider":{let d=P("div","pw-divider");return d.setAttribute("role","separator"),d.style.background=String(a.color),d.style.alignSelf="stretch",d.style.flex="none",o==="horizontal"?(d.setAttribute("aria-orientation","vertical"),d.style.width=_(a.thickness)):d.style.height=_(a.thickness),{el:d,slots:{}}}case"button":return Rt(a,r);case"purchase_button":{let d=P("button","pw-buy");return d.type="button",d.addEventListener("click",()=>{Ve(d,()=>jt(d.dataset.package??""))}),{el:d,slots:{content:d}}}case"package":{let d=P("div","pw-pkg");return d.setAttribute("role","radio"),d.addEventListener("click",()=>Re(d)),d.addEventListener("keydown",u=>Ft(u,d)),{el:d,slots:{children:d}}}case"tabs":return _t(a,c);case"switch":return Et(a,c);case"carousel":return Lt(a);case"countdown":{let d=P("div","pw-countdown");return d.setAttribute("role","timer"),d.setAttribute("aria-live","off"),{el:d,slots:{content:d}}}case"custom_html":{let d=x.assets?.[ie(a.src)??""];if(!d?.html)return null;let u=P("iframe","pw-html");return u.setAttribute("sandbox","allow-scripts"),u.setAttribute("aria-hidden","true"),u.setAttribute("title",""),u.tabIndex=-1,u.srcdoc=d.html,typeof a.height=="number"?u.style.height=_(a.height):typeof a.height=="string"&&a.height.endsWith("%")?u.style.height=a.height:a.height==="fill"&&(u.style.flex="1 1 0"),u.addEventListener("load",()=>qe(u)),{el:u,slots:{}}}default:return null}}function Pt(e,c){let o=String(e.text_style??"body"),r=c.inControl?"span":o==="large_title"?"h1":o==="title"||o==="title2"?"h2":o==="title3"?"h3":"p",a=P(r,"pw-text");c.inControl&&(a.style.display="block"),a.style.fontFamily=Mt(e.font);let d=typeof e.size=="number"?e.size:16;if(c.inFooter?(a.style.setProperty("--pw-fs",ft(d)),a.style.setProperty("--pw-fs-max",`${Number((d*pn).toFixed(2))}px`)):a.style.fontSize=ft(d),typeof e.weight=="number"&&(a.style.fontWeight=String(e.weight)),typeof e.line_height=="number"&&(a.style.lineHeight=String(e.line_height)),typeof e.letter_spacing=="number"&&e.letter_spacing!==0&&(a.style.letterSpacing=_(e.letter_spacing)),a.style.textAlign=String(e.align??"center"),e.uppercase===!0&&(a.style.textTransform="uppercase"),typeof e.max_lines=="number"&&(a.classList.add("pw-clamp"),a.style.setProperty("-webkit-line-clamp",String(e.max_lines))),typeof e.color=="string"?a.style.color=e.color:e.color&&typeof e.color=="object"&&(a.classList.add("pw-grad"),a.style.backgroundImage=Ae(e.color)??""),Array.isArray(e.spans))for(let u of e.spans){let k=u.link==="terms"?x.links?.terms:u.link==="privacy"?x.links?.privacy:u.link,A=ye(k)&&!c.inControl,L=P(A?"a":"span");L.textContent=String(u.text),u.bold&&(L.style.fontWeight="700"),u.italic&&(L.style.fontStyle="italic");let z=[u.underline?"underline":"",u.strikethrough?"line-through":""].filter(Boolean).join(" ");z&&(L.style.textDecoration=z),typeof u.color=="string"&&u.color!==""&&(L.style.color=u.color),A&&ye(k)&&(L.href=k,L.target="_blank",L.rel="noopener noreferrer",L.addEventListener("click",D=>{H()||!n.onLink||(D.preventDefault(),n.onLink(k))})),a.append(L)}else a.textContent=String(e.text??"");return a}function Mt(e){if(typeof e!="string")return ne.system;let c=ie(e);if(c){let o=x.assets?.[c]?.family;return o?`"${o}", ${ne.system}`:ne.system}return ne[e]??ne.system}function Z(e){let c=ie(e);return c?x.assets?.[c]?.url||void 0:ye(e)?e:void 0}function At(e){let c=P("div","pw-img");typeof e.aspect=="number"&&(c.style.aspectRatio=String(e.aspect));let o=Z(e.src),r=e.mask;if(r?.shape==="circle")c.style.borderRadius="50%";else if(r?.shape==="rect"&&r.radius)c.style.borderRadius=_(r.radius);else if(r?.shape==="convex")c.style.setProperty("border-end-start-radius",`50% ${_(r.depth)}`),c.style.setProperty("border-end-end-radius",`50% ${_(r.depth)}`);else if(r?.shape==="concave"){let a=`radial-gradient(ellipse 50% ${_(r.depth)} at 50% 100%, transparent 98%, #000 100%)`;c.style.setProperty("-webkit-mask-image",a),c.style.setProperty("mask-image",a)}if(o){let a=P("img");a.src=o,a.decoding="async",a.style.objectFit=e.fit==="fill"?"cover":"contain",e.decorative===!0?(a.alt="",c.setAttribute("aria-hidden","true")):a.alt=String(e.alt??""),a.addEventListener("error",()=>a.style.visibility="hidden"),c.append(a)}if(e.overlay&&typeof e.overlay=="object"){let a=P("div","pw-overlay");a.style.backgroundImage=Ae(e.overlay)??"",c.append(a)}return{el:c,slots:{}}}function St(e){let c=P("div","pw-img");typeof e.aspect=="number"&&(c.style.aspectRatio=String(e.aspect));let o=Z(e.src);if(o){let r=P("video");r.src=o;let a=Z(e.poster);a&&(r.poster=a),r.muted=e.mute!==!1,r.loop=e.loop!==!1,r.playsInline=!0,r.controls=e.controls===!0,r.preload="auto",r.style.objectFit=e.fit==="fit"?"contain":"cover",r.autoplay=e.autoplay!==!1&&!re()&&!H(),typeof e.alt=="string"?r.setAttribute("aria-label",e.alt):r.setAttribute("aria-hidden","true"),c.append(r)}return{el:c,slots:{}}}function Rt(e,c){let o=e.action??{},r,a=o.type==="restore"||o.type==="offer_code";switch(o.type){case"close":c.inSheet?r=()=>pe(null):n.onClose&&(r=()=>n.onClose());break;case"restore":n.onRestore&&(r=()=>n.onRestore());break;case"offer_code":n.onOfferCode&&(x.platform??"web")!=="web"&&(r=()=>n.onOfferCode());break;case"open_url":case"terms":case"privacy":{let u=o.type==="open_url"?o.url:o.type==="terms"?x.links?.terms:x.links?.privacy;ye(u)&&(r=()=>n.onLink?n.onLink(u):void p?.open(u,"_blank","noopener,noreferrer"));break}case"sheet":o.sheet&&(r=()=>pe(o.sheet));break;case"select_package":o.package&&(r=()=>Se(o.package));break}if(!r&&!H())return null;let d=P("button");return d.type="button",o.type==="close"&&d.setAttribute("aria-label",le.close),d.addEventListener("click",()=>{!r||H()||(a?Ve(d,r):r())}),{el:d,slots:{content:d}}}function _t(e,c){let o=P("div","pw-tabs"),r=P("div","pw-tablist");r.setAttribute("role","tablist");let a=P("div","pw-tabpanel");a.setAttribute("role","tabpanel"),a.id=`${l}-${c}-panel`;let d={content:a},u=e.tabs.map(k=>k.id);return u.forEach((k,A)=>{let L=P("button","pw-tab");L.type="button",L.setAttribute("role","tab"),L.id=`${l}-${c}-tab-${A}`,L.setAttribute("aria-controls",a.id),L.dataset.tab=k,L.addEventListener("click",()=>Je(c,k)),L.addEventListener("keydown",z=>{let D=z.key==="ArrowRight"?A+1:z.key==="ArrowLeft"?A-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];Je(c,B),r.querySelector(`[data-tab="${B}"]`)?.focus()}),r.append(L),d[`label:${k}`]=L}),o.append(r,a),d.bar=r,{el:o,slots:d}}function Et(e,c){let o=P("div","pw-switch"),r=P("div","pw-switchrow"),a=P("span","pw-switchlabel");a.id=`${l}-${c}-label`;let d=P("button","pw-toggle");d.type="button",d.setAttribute("role","switch"),d.setAttribute("aria-labelledby",a.id),d.append(P("i")),d.addEventListener("click",()=>Ht(c,d.getAttribute("aria-checked")!=="true")),r.append(a,d);let u=P("div","pw-switchcontent");return o.append(r,u),{el:o,slots:{content:u,label:a,toggle:d}}}function Lt(e){let c=P("div","pw-carousel");c.setAttribute("role","region"),c.setAttribute("aria-roledescription","carousel");let o=P("div","pw-track");o.tabIndex=0,o.style.setProperty("--pw-peek",_(e.peek)),o.style.setProperty("--pw-gap",_(e.spacing)),typeof e.height=="number"&&(o.style.minHeight=_(e.height));let r=e.indicator??{},a=P("div",`pw-dots ${r.style??"dots"}`);a.style.setProperty("--pw-dot",_(r.size??8)),a.style.setProperty("--pw-dot-gap",_(r.spacing??6)),a.style.setProperty("--pw-dot-c",r.color??"#8888"),a.style.setProperty("--pw-dot-on",r.active_color??"currentColor"),r.style==="none"&&(a.hidden=!0),c.append(o,a);let d=()=>[...o.children].filter($=>$ instanceof(p?.HTMLElement??HTMLElement)),u=()=>{let $=d(),j=o.scrollLeft+o.clientWidth/2,O=0;return $.forEach((I,It)=>{Math.abs(I.offsetLeft+I.offsetWidth/2-j)<Math.abs(($[O]?.offsetLeft??0)+($[O]?.offsetWidth??0)/2-j)&&(O=It)}),O},k=$=>{let j=d();if(j.length===0)return;let O=e.loop?($+j.length)%j.length:Math.max(0,Math.min(j.length-1,$)),I=j[O];o.scrollTo?.({left:I.offsetLeft-(o.clientWidth-I.offsetWidth)/2,behavior:re()?"auto":"smooth"}),A(O)},A=$=>{[...a.children].forEach((j,O)=>j.setAttribute("aria-current",String(O===$)))};o.addEventListener("scroll",()=>A(u()),{passive:!0}),o.addEventListener("keydown",$=>{$.key!=="ArrowRight"&&$.key!=="ArrowLeft"||($.preventDefault(),k(u()+($.key==="ArrowRight"?1:-1)))});let L=!1,z=()=>L=!0,D=()=>L=!1;c.addEventListener("pointerenter",z),c.addEventListener("pointerleave",D),c.addEventListener("focusin",z),c.addEventListener("focusout",D);let B=[];if(typeof e.auto_advance_ms=="number"){let $=setInterval(()=>{if(L||re()||H())return;let j=d(),O=u();!e.loop&&O>=j.length-1||k(O+1)},e.auto_advance_ms);B.push(()=>clearInterval($))}return c.pwDots=$=>{a.children.length!==$&&(a.replaceChildren(...Array.from({length:$},(j,O)=>{let I=P("button");return I.type="button",I.setAttribute("aria-label",le.page(O+1,$)),I.addEventListener("click",()=>k(O)),I})),A(u()))},{el:c,slots:{pages:o},cleanup:B}}function $t(e,c){let o=c;switch(c.type){case"package":{let r=bn(o),d=!!x.packages[r]?.price;e.el.dataset.package=r,e.el.setAttribute("aria-checked",String(o.selected===!0)),e.el.setAttribute("aria-disabled",String(!d));break}case"purchase_button":{let r=String(o.package);e.el.dataset.package=r,e.el.disabled=K||!x.packages[r]?.price;break}case"switch":{let r=e.slots.toggle;r.setAttribute("aria-checked",String(o.on===!0)),r.style.setProperty("--pw-tint",String(o.tint??"")),r.style.setProperty("--pw-off",`color-mix(in srgb, ${b.tree.theme.colors.muted??"#888888"} 45%, transparent)`),e.slots.label.textContent=String(o.label??""),e.slots.label.hidden=o.label===void 0;break}case"tabs":{for(let r of o.tabs){let a=e.slots[`label:${r.id}`];a.setAttribute("aria-selected",String(r.selected)),a.tabIndex=r.selected?0:-1,r.selected&&e.slots.content.setAttribute("aria-labelledby",a.id)}o.bar&&De(e.slots.bar,{type:"stack",style:o.bar},"vertical");break}}}function Tt(e,c,o){let r=c,a={...o,inControl:o.inControl||c.type==="button"||c.type==="purchase_button"||c.type==="package"};switch(c.type){case"stack":case"package":{let d=c.type==="stack"?String(r.axis??"vertical"):"vertical",u=r.children.map(A=>[A,U(A,d,a)]).filter(A=>A[1]!==null),k=u.map(A=>A[1]);V(e.slots.children,k),zt(d,u),c.type==="stack"&&ce(e.el,k);break}case"button":case"purchase_button":{let d=r.content?U(r.content,"vertical",a):null;V(e.slots.content,d?[d]:[]);break}case"countdown":case"switch":{let d=r.content?U(r.content,"vertical",a):null;V(e.slots.content,d?[d]:[]),ce(e.slots.content,d?[d]:[]);break}case"tabs":{for(let u of r.tabs){let k=u.label?U(u.label,"vertical",{...a,inControl:!0}):null;V(e.slots[`label:${u.id}`],k?[k]:[])}let d=r.content?U(r.content,"vertical",a):null;V(e.slots.content,d?[d]:[]),ce(e.slots.content,d?[d]:[]);break}case"carousel":{let d=r.pages.map(u=>U(u,"page",a)).filter(Boolean);d.forEach((u,k)=>{u.setAttribute("role","group"),u.setAttribute("aria-roledescription","slide"),u.setAttribute("aria-label",le.page(k+1,d.length))}),V(e.slots.pages,d),ce(e.slots.pages,d),e.el.pwDots?.(d.length);break}}}function zt(e,c){let o=e==="horizontal"?"width":e==="vertical"?"height":null;if(!o)return;let r=u=>u?o==="width"?u.leading+u.trailing:u.top+u.bottom:0,a=c.filter(([u])=>u.style?.[o]==="fill"),d=Math.max(0,...a.map(([u])=>r(u.style?.padding)+r(u.style?.margin)));for(let[u,k]of a)k.style.flexBasis=_(d-r(u.style?.margin))}function ce(e,c){let o=c.filter(a=>a.dataset.pwType==="package");if(o.length===0){e.getAttribute("role")==="radiogroup"&&e.removeAttribute("role");return}e.setAttribute("role","radiogroup"),e.setAttribute("aria-label",le.packages);let r=o.find(a=>a.getAttribute("aria-checked")==="true")??o[0];for(let a of o)a.tabIndex=a===r?0:-1}function V(e,c){let o=()=>[...e.children].filter(a=>a.dataset?.pwPath!==void 0),r=o();for(let a of r)c.includes(a)||a.remove();r=o(),c.forEach((a,d)=>{r[d]!==a&&(e.insertBefore(a,r[d]??null),r=o())})}let Me=new WeakMap;function E(e,c,o){e.style.setProperty(c,o),Me.get(e).push(c)}function De(e,c,o){for(let u of Me.get(e)??[])e.style.removeProperty(u);Me.set(e,[]);for(let u of[...e.children])u.classList.contains("pw-bgvideo")&&u.remove();let r=c.style;if(c.type==="image"&&e.classList.toggle("natural",typeof c.aspect!="number"&&(r?.height===void 0||r.height==="fit")),!r)return;let a=(u,k)=>{k&&(E(e,`${u}-block-start`,_(k.top)),E(e,`${u}-block-end`,_(k.bottom)),E(e,`${u}-inline-start`,_(k.leading)),E(e,`${u}-inline-end`,_(k.trailing)))};a("padding",r.padding),a("margin",r.margin),Ie(e,"width",r.width,o),typeof r.height=="number"&&un.has(c.type)?(E(e,"min-height",_(r.height)),o==="vertical"&&E(e,"flex","none")):Ie(e,"height",r.height,o),typeof r.max_width=="number"&&E(e,"max-width",_(r.max_width));let d=r.background;if(d){if(d.type==="color")E(e,"background-color",d.color);else if(d.type==="linear"||d.type==="radial")E(e,"background-image",Ae(d)??"");else if(d.type==="image"){let u=Z(d.src);u&&(E(e,"background-image",`url("${u.replace(/"/g,"%22")}")`),E(e,"background-size",d.fit==="fit"?"contain":"cover"),E(e,"background-position","center"),E(e,"background-repeat","no-repeat"))}else if(d.type==="video"){let u=Z(d.src);if(u){let k=P("video","pw-bgvideo");k.src=u;let A=Z(d.poster);A&&(k.poster=A),k.muted=!0,k.loop=d.loop!==!1,k.playsInline=!0,k.autoplay=!re()&&!H(),k.setAttribute("aria-hidden","true"),E(e,"isolation","isolate"),e.prepend(k)}}}if(r.border&&c.type==="custom_html"?E(e,"border",`${_(r.border.width)} solid ${r.border.color??"transparent"}`):r.border&&(E(e,"--pw-bw",_(r.border.width)),E(e,"--pw-bc",r.border.color??"transparent")),r.corners){let u=r.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)),(c.type==="image"||c.type==="video"||d?.type==="image"||d?.type==="video")&&E(e,"overflow","hidden")}r.shadow&&E(e,"box-shadow",`${_(r.shadow.x)} ${_(r.shadow.y)} ${_(r.shadow.radius)} ${r.shadow.color}`),typeof r.opacity=="number"&&r.opacity!==1&&E(e,"opacity",String(r.opacity))}function Ie(e,c,o,r){if(o==null||o==="")return;if(r==="page"){c==="height"&&E(e,"height",o==="fill"?"100%":typeof o=="number"?_(o):o==="fit"?"fit-content":String(o));return}let a=r==="horizontal"?"width":r==="vertical"?"height":null;o==="fill"?c===a?(E(e,"flex","1 1 0"),E(e,`min-${c}`,"0")):r==="z"?E(e,c,"100%"):(E(e,"align-self","stretch"),E(e,c,"auto")):o==="fit"?(c===a&&E(e,"flex","0 0 auto"),E(e,c,"fit-content")):(E(e,c,typeof o=="number"?_(o):String(o)),c===a&&E(e,"flex","none"))}function Ae(e){let c=o=>o.map(r=>`${r.color} ${(r.at*100).toFixed(2)}%`).join(", ");if(e.type==="linear")return`linear-gradient(${e.angle}deg, ${c(e.stops)})`;if(e.type==="radial"){let o=`${(e.radius*100).toFixed(2)}%`;return`radial-gradient(ellipse ${o} ${o} at ${(e.center_x*100).toFixed(2)}% ${(e.center_y*100).toFixed(2)}%, ${c(e.stops)})`}}function Ot(e,c){let o=c.animation;if(!o||x.animate===!1||re()||typeof e.animate!="function")return;let r=24,d={fade:{opacity:0},slide_up:{opacity:0,transform:`translateY(${r}px)`},slide_down:{opacity:0,transform:`translateY(-${r}px)`},slide_leading:{opacity:0,transform:`translateX(-${r}px)`},slide_trailing:{opacity:0,transform:`translateX(${r}px)`},scale:{opacity:0,transform:"scale(0.92)"}}[o.type];d&&e.animate([d,{opacity:1,transform:"none"}],{duration:o.duration_ms,delay:o.delay_ms,easing:ut[o.easing]??ut.ease_out,fill:"backwards"})}function de(){n.onState?.({...R}),G()}function Se(e){R.selected===e&&b.tree.selected===e||(R.selected=e,de(),n.onSelect?.(Te(e)))}function Re(e){H()||e.getAttribute("aria-disabled")==="true"||Se(e.dataset.package??"")}function Ft(e,c){if(e.key===" "||e.key==="Enter"){e.preventDefault(),Re(c);return}let o=e.key==="ArrowDown"||e.key==="ArrowRight"?1:e.key==="ArrowUp"||e.key==="ArrowLeft"?-1:0;if(o===0)return;e.preventDefault();let r=c.closest("[role=radiogroup]"),d=(r?[...r.children].filter(A=>A.dataset.pwType==="package"):[c]).filter(A=>A.getAttribute("aria-disabled")!=="true"),u=d.indexOf(c),k=d[(u+o+d.length)%d.length];k&&(Re(k),(T.get(k.dataset.pwPath??"")?.el??k).focus())}function Je(e,c){if(H())return;R.tabs={...R.tabs,[e]:c};let o=Ct(e,c);o&&(R.selected=o),de()}function Ct(e,c){return Ue(e)?.tabs?.find(r=>r.id===c)?.package}function Ht(e,c){if(H())return;R.switches={...R.switches,[e]:c};let o=Ue(e),r=c?o?.on_package:o?.off_package;r&&(R.selected=r),de()}function Ue(e){let c=x.definition;for(let o of e.match(/[^.[\]]+/g)??[])c=c?.[/^\d+$/.test(o)?Number(o):o];return c}async function Ve(e,c){if(!(H()||K)){K=!0,e.disabled=!0,e.setAttribute("aria-busy","true");try{await c()}finally{K=!1,e.removeAttribute("aria-busy"),e.disabled=!1;for(let o of T.values())o.type==="purchase_button"&&(o.el.disabled=!x.packages[o.el.dataset.package??""]?.price)}}}async function jt(e){x.packages[e]?.price&&await n.onPurchase(Te(e))}function pe(e){H()&&e!==null&&R.sheet===e||(e&&!R.sheet&&(je=y.activeElement??null),R.sheet=e,de(),e||je?.focus())}function Nt(){let e=R.sheet,c=e?b.tree.sheets?.[e]:void 0;if(!c){M.remove();return}M.className="pw-layer";let o=M.firstElementChild;if(!o){o=P("div","pw-sheet"),o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true"),o.tabIndex=-1;let a=P("div","pw-grab");a.setAttribute("aria-hidden","true"),o.append(a),M.append(o),M.addEventListener("click",d=>{d.target===M&&!H()&&pe(null)}),o.addEventListener("keydown",d=>Dt(d,o))}o.style.background=b.tree.theme.colors.background??"",o.setAttribute("aria-label",b.sheetTitles[e]??"");let r=U(c,"vertical",{inControl:!1,inSheet:!0});V(o,r?[r]:[]),M.isConnected||(g.append(M),queueMicrotask(()=>(Be(o)[0]??o).focus()))}function Be(e){return[...e.querySelectorAll('button:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')].filter(c=>!c.hidden)}function Dt(e,c){if(e.key==="Escape"){e.preventDefault(),pe(null);return}if(e.key!=="Tab")return;let o=Be(c);if(o.length===0){e.preventDefault();return}let r=o[0],a=o[o.length-1],d=y.activeElement;e.shiftKey&&d===r?(e.preventDefault(),a.focus()):!e.shiftKey&&d===a&&(e.preventDefault(),r.focus())}function qe(e){try{e.contentWindow?.postMessage({type:"palbase.paywall",package:b.tree.selected,locale:b.language,appearance:x.appearance},"*")}catch{}}function We(e){for(let c of y.querySelectorAll("[data-pw-highlight]"))c.removeAttribute("data-pw-highlight");be=e,e&&T.get(e)?.el.setAttribute("data-pw-highlight","")}let Ke=e=>e.composedPath().find(c=>c instanceof(p?.HTMLElement??HTMLElement)&&c.dataset.pwPath!==void 0);g.addEventListener("click",e=>{if(!n.editor)return;let c=Ke(e);c&&(e.preventDefault(),e.stopPropagation(),n.editor.onPick(c.dataset.pwPath))},!0),g.addEventListener("pointerover",e=>{if(n.editor){for(let c of y.querySelectorAll("[data-pw-hover]"))c.removeAttribute("data-pw-hover");Ke(e)?.setAttribute("data-pw-hover","")}}),g.addEventListener("pointerleave",()=>{for(let e of y.querySelectorAll("[data-pw-hover]"))e.removeAttribute("data-pw-hover")});let Xe=()=>G();return ke?.addEventListener?.("change",Xe),G(),{get selected(){return Te(b.tree.selected)},get state(){return{...R}},select(e){Se(e)},update(e){x={...x,...e},e.state&&Object.assign(R,e.state),G()},highlight(e){We(e)},replay(){for(let e of T.values())e.cleanup.forEach(c=>c());T=new Map;for(let e of[h,w,v])e.replaceChildren();G()},destroy(){clearTimeout(ve),Ce?.disconnect(),i.fonts?.removeEventListener?.("loadingdone",He),ke?.removeEventListener?.("change",Xe);for(let e of T.values())e.cleanup.forEach(c=>c());f.remove()}}}function kn(s,t,n){let i=s.defaultView;try{if(i&&"adoptedStyleSheets"in t&&typeof i.CSSStyleSheet=="function"){let l=new i.CSSStyleSheet;l.replaceSync(n),t.adoptedStyleSheets=[l];return}}catch{}let p=s.createElement("style");p.textContent=n,t.append(p)}var ht={version:"0.3.2"};var yt=`palbase-js/${ht.version}`;var we=class{placement;source;definition;assets;offerings;shown;deps;exposed=!1;constructor(t,n,i,p,l,f,y={}){this.placement=t,this.source=n,this.definition=i,this.assets=y,this.offerings=p,this.shown=l,this.deps=f}packages(t){return rt(An(this.offerings,ct(this.definition),t),t)}render(t,n){let i=n.locale??globalThis.navigator?.language??this.definition.default_locale,p=n.appearance===void 0?Pn():void 0,l=this.packages(i),f=gt(t,{definition:this.definition,locale:i,appearance:n.appearance??(p?.matches?"dark":"light"),platform:"web",packages:l,eligible:Object.entries(l).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 Pn(){try{return globalThis.matchMedia?.("(prefers-color-scheme: dark)")}catch{return}}function Mn(s,t){if(!s)return;let n=t.split("-")[0];return s[t]?.name??s[n]?.name??Object.values(s).find(i=>i.name)?.name}function An(s,t,n){let i=[];for(let p of t){let[l,f]=p.split("."),y=s.products.find(w=>w.key===l),g=y?.channels.web,h=g?.plans.find(w=>w.key===f);!y||!g||!h||i.push({key:p,productName:Mn(g.locales,n)??y.key,price:{amount:h.price.amount,currency:h.price.currency},period:h.period,intro:h.intro})}return i}var Sn={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"}},mt=s=>({type:"button",action:{type:s},content:{type:"text",text:{t:s},size:"caption",color:"muted"}});function Rn(s){let t=s.products.flatMap(n=>(n.channels.web?.plans??[]).map(i=>({product:n.key,plan:i.key}))).slice(0,6);return t.length===0?null:{schema:2,name:"Default",default_locale:"en",locales:Sn,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:i})=>({type:"package",product:n,plan:i,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:[mt("terms"),mt("privacy")]}]}}}function se(){try{return globalThis.localStorage}catch{return}}function _n(s){try{let t=se()?.getItem(s);if(!t)return;let n=JSON.parse(t),i=n?.answer;return typeof i!="object"||i===null||typeof i.paywall_id!="string"||typeof i.version!="number"||typeof i.definition!="object"||i.definition===null||typeof i.offerings!="object"||i.definition.schema!==2?void 0:{etag:typeof n.etag=="string"?n.etag:void 0,answer:i}}catch{return}}function me(s,t){try{t?se()?.setItem(s,JSON.stringify(t)):se()?.removeItem(s)}catch{}}var wt=()=>globalThis.crypto?.randomUUID?globalThis.crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,bt;function En(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 i=wt();if(se()?.setItem(t,i),se()?.getItem(t)===i)return i}catch{}return bt??=wt(),bt}async function Zn(s,t,n,i,p={}){let{signal:l,fetch:f}=p,y=tt(p.attributes),g=`palbase.paywall.${t}.${n}`,h=En(t),v={checkout:i,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 Ge(b.assets??[],{signal:l,...f?{fetch:f}:{}})),x=_n(g),R;try{R=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":yt,...p.appVersion?{"X-Palbase-Client-Version":p.appVersion}:{},...p.locale?{"Accept-Language":p.locale}:{},...y!==void 0?{"X-Palbase-Attributes":y}:{},...x?.etag?{"If-None-Match":x.etag}:{}},signal:l})}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,l);if(x&&!l?.aborted)return M(x.answer,"cache");throw b}return R.status===200?(me(g,{etag:R.headers.get("etag")??void 0,answer:R.data}),M(R.data,"server")):R.status===304&&x?M(x.answer,"server"):(me(g,void 0),ze(s,n,v,l))}async function ze(s,t,n,i){let p=(await s.getOfferings({query:{channel:"web"},signal:i})).data,l=Rn(p);return l?new we(t,"default",l,p,void 0,n):null}export{Ut as a,ie as b,Ge as c,qt as d,Yt as e,tt as f,_e as g,st as h,Qt as i,rt as j,ue as k,he as l,Fn as m,cn as n,ct as o,Cn as p,dt as q,gt as r,we as s,Rn as t,Zn as u};
|
|
92
|
+
`,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}},bn=s=>`${String(s.product)}.${String(s.plan)}`,Te=s=>{let[t,n]=s.split(".");return{product:t??"",plan:n??""}},_=s=>`${Number(s)||0}px`,ft=s=>`${s/16}rem`,vn=0;function gt(s,t,n){let i=s.ownerDocument,p=i.defaultView,l=`pw${++vn}`,f=i.createElement("div");f.setAttribute("data-palbase-paywall",""),f.style.display="block",f.style.height="100%";let y=f.attachShadow({mode:"open"});kn(i,y,wn);let g=i.createElement("div");g.className="pw2";let h=i.createElement("div");h.className="pw2-head";let w=i.createElement("div");w.className="pw2-body";let v=i.createElement("div");v.className="pw2-foot";let M=i.createElement("div");g.append(h,w,v),y.append(g),s.replaceChildren(f);let x={...t},R={openedAt:Date.now(),...t.state},b,T=new Map,C=new Map,K=!1,be=null,ve,Oe=!1,Fe=i.defaultView?.ResizeObserver,Ce=typeof Fe=="function"?new Fe(()=>{g.classList.toggle("pw2-large",Ne()>=pt),xe()}):null;Ce?.observe(g);let He=()=>xe();i.fonts?.addEventListener?.("loadingdone",He);let je=null,ke=p?.matchMedia?.("(prefers-reduced-motion: reduce)"),re=()=>x.reduceMotion??ke?.matches??!1,H=()=>!!n.editor,le={...dn,...n.labels};function G(){let e=R.now??Date.now();b=dt(x.definition,{locale:x.locale,appearance:x.appearance,platform:x.platform??"web",packages:x.packages,eligible:x.eligible??[],...R.selected?{selected:R.selected}:{},tabs:R.tabs??{},switches:R.switches??{},openedSecondsAgo:Math.max(0,Math.floor((e-(R.openedAt??e))/1e3)),now:e});let c=b.tree.theme.colors;g.style.background=c.background??"",g.style.color=c.text??"",g.classList.toggle("pw-editing",H()),g.classList.toggle("pw2-large",Ne()>=pt),g.lang=b.language,g.dir=fn.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),Nt();for(let[o,r]of T)C.has(o)||r.cleanup.forEach(a=>a());T=C,be&&We(be);for(let o of T.values())o.type==="custom_html"&&qe(o.el);xe(),clearTimeout(ve),Oe||=f.isConnected,R.now===void 0&&Object.keys(b.countdowns).length>0&&(ve=setTimeout(()=>{Oe&&!f.isConnected||G()},1e3-Date.now()%1e3+5))}function Ne(){let e=i.documentElement,c=e&&p?parseFloat(p.getComputedStyle(e).fontSize):NaN;return Number.isFinite(c)?c:16}function xe(){let e=[];for(let o of T.values()){if(o.type!=="text")continue;let r=o.el,a=r.dataset.pwFit??r.style.fontSize;if(!a||(r.style.fontSize=a,delete r.dataset.pwFit,!/^\S+$/.test(r.textContent??"")))continue;let d=r.parentElement,u=d&&p?p.getComputedStyle(d):null,k=d&&u?d.clientWidth-parseFloat(u.paddingLeft||"0")-parseFloat(u.paddingRight||"0"):1/0,A=Math.min(r.clientWidth,k);e.push({e:r,base:a,k:A<=0||r.scrollWidth<=A+.5?1:Math.max(.6,A/r.scrollWidth)})}let c=o=>o.closest(".pw-stack.h");for(let o of e){let r=Math.min(o.k,...e.filter(a=>a!==o&&a.base===o.base&&c(a.e)&&c(a.e)===c(o.e)).map(a=>a.k));r>=1||(o.e.dataset.pwFit=o.base,o.e.style.fontSize=`calc(${o.base} * ${r.toFixed(3)})`)}}function Pe(e,c,o){let r=c?U(c,o,{inControl:!1,inSheet:!1,inFooter:e===v}):null;V(e,r?[r]:[])}function U(e,c,o){let r=b.pathOf(e)??"",a=vt(e),d=T.get(r),u;if(d&&d.type===e.type&&d.key===a&&d.axis===c&&!C.has(r))u=d;else{let A=xt(e,r,c,o);if(!A)return null;u={el:A.el,type:e.type,key:a,styleKey:"",axis:c,slots:A.slots,cleanup:A.cleanup??[]},u.el.classList.add("pw-c"),u.el.dataset.pwPath=r,u.el.dataset.pwType=e.type,e.id&&(u.el.dataset.pwId=e.id),d&&d.cleanup.forEach(L=>L()),Ot(u.el,e)}let k=`${JSON.stringify(e.style??null)}|${c}`;return u.styleKey!==k&&(De(u.el,e,c),u.styleKey=k),C.set(r,u),$t(u,e),Tt(u,e,o),u.el}function vt(e){let c=new Set(["style",...yn[e.type]??[],...mn[e.type]??[]]),o={};for(let[r,a]of Object.entries(e))c.has(r)||(o[r]=a);return e.type==="tabs"&&(o.tabs=e.tabs.map(r=>r.id)),e.type==="carousel"&&(o.pages=e.pages.length),e.type==="stack"&&(o.greedy=e.children.some(r=>r.type==="spacer"&&typeof r.size!="number")),(e.type==="image"||e.type==="video"||e.type==="custom_html")&&(o.asset=kt(e)),JSON.stringify(o)}function kt(e){let c=ie(e.src);return c?(x.assets?.[c]?.url??x.assets?.[c]?.html?.length??"none").toString():""}function P(e,c){let o=i.createElement(e);return c&&(o.className=c),o}function xt(e,c,o,r){let a=e;switch(e.type){case"stack":{let d=P("div",`pw-stack${a.axis==="horizontal"?" h":a.axis==="z"?" z":""}${a.scroll?" scroll":""}`);return a.axis!=="z"&&a.children.some(u=>u.type==="spacer"&&typeof u.size!="number")&&d.classList.add(a.axis==="horizontal"?"greedy-h":"greedy-v"),d.style.gap=_(a.spacing),a.axis==="z"?d.style.placeItems=a.align==="stretch"?"stretch":String(a.align??"center"):(d.style.alignItems=gn[String(a.align)]??"center",d.style.justifyContent=hn[String(a.distribution)]??"flex-start"),{el:d,slots:{children:d}}}case"text":return{el:Pt(a,r),slots:{}};case"icon":{let d=ue[String(a.name)];if(!d)return null;let u=P("span","pw-icon");return u.style.color=String(a.color??""),u.append(fe(i,d,Number(a.size)||24)),u.setAttribute("aria-hidden","true"),{el:u,slots:{}}}case"image":return At(a);case"video":return St(a);case"features":{let d=P("ul","pw-features");d.style.gap=_(a.spacing);for(let u of a.items??[]){let k=P("li","pw-feature"),A=ue[u.icon];if(A){let z=fe(i,A,22);z.style.color=String(a.icon_color),z.style.flex="none",k.append(z)}let L=P("span");L.textContent=u.text,L.style.color=String(a.color),k.append(L),d.append(k)}return{el:d,slots:{}}}case"timeline":{let d=P("ol","pw-timeline");d.style.gap=_(a.spacing),d.style.setProperty("--pw-gap",_(a.spacing)),d.style.setProperty("--pw-line-w",_(a.line_width));for(let u of a.items??[]){let k=P("li","pw-step"),A=P("span","pw-dot");A.style.background=u.color??String(a.line_color),A.style.color=String(a.icon_color);let L=ue[u.icon];L&&A.append(fe(i,L,18)),A.setAttribute("aria-hidden","true");let z=P("span","pw-line");z.style.background=String(a.line_color),z.setAttribute("aria-hidden","true");let D=P("span");D.style.color=String(a.color);let B=P("span","pw-step-title");if(B.textContent=u.title,D.append(B),u.text){let $=P("span","pw-step-text");$.style.display="block",$.textContent=u.text,D.append($)}k.append(A,D,z),d.append(k)}return{el:d,slots:{}}}case"spacer":{let d=P("div","pw-spacer");return d.setAttribute("aria-hidden","true"),typeof a.size=="number"&&(d.style.flex="none",o==="horizontal"?d.style.width=_(a.size):d.style.height=_(a.size)),{el:d,slots:{}}}case"divider":{let d=P("div","pw-divider");return d.setAttribute("role","separator"),d.style.background=String(a.color),d.style.alignSelf="stretch",d.style.flex="none",o==="horizontal"?(d.setAttribute("aria-orientation","vertical"),d.style.width=_(a.thickness)):d.style.height=_(a.thickness),{el:d,slots:{}}}case"button":return Rt(a,r);case"purchase_button":{let d=P("button","pw-buy");return d.type="button",d.addEventListener("click",()=>{Ve(d,()=>jt(d.dataset.package??""))}),{el:d,slots:{content:d}}}case"package":{let d=P("div","pw-pkg");return d.setAttribute("role","radio"),d.addEventListener("click",()=>Re(d)),d.addEventListener("keydown",u=>Ft(u,d)),{el:d,slots:{children:d}}}case"tabs":return _t(a,c);case"switch":return Et(a,c);case"carousel":return Lt(a);case"countdown":{let d=P("div","pw-countdown");return d.setAttribute("role","timer"),d.setAttribute("aria-live","off"),{el:d,slots:{content:d}}}case"custom_html":{let d=x.assets?.[ie(a.src)??""];if(!d?.html)return null;let u=P("iframe","pw-html");return u.setAttribute("sandbox","allow-scripts"),u.setAttribute("aria-hidden","true"),u.setAttribute("title",""),u.tabIndex=-1,u.srcdoc=d.html,typeof a.height=="number"?u.style.height=_(a.height):typeof a.height=="string"&&a.height.endsWith("%")?u.style.height=a.height:a.height==="fill"&&(u.style.flex="1 1 0"),u.addEventListener("load",()=>qe(u)),{el:u,slots:{}}}default:return null}}function Pt(e,c){let o=String(e.text_style??"body"),r=c.inControl?"span":o==="large_title"?"h1":o==="title"||o==="title2"?"h2":o==="title3"?"h3":"p",a=P(r,"pw-text");c.inControl&&(a.style.display="block"),a.style.fontFamily=Mt(e.font);let d=typeof e.size=="number"?e.size:16;if(c.inFooter?(a.style.setProperty("--pw-fs",ft(d)),a.style.setProperty("--pw-fs-max",`${Number((d*pn).toFixed(2))}px`)):a.style.fontSize=ft(d),typeof e.weight=="number"&&(a.style.fontWeight=String(e.weight)),typeof e.line_height=="number"&&(a.style.lineHeight=String(e.line_height)),typeof e.letter_spacing=="number"&&e.letter_spacing!==0&&(a.style.letterSpacing=_(e.letter_spacing)),a.style.textAlign=String(e.align??"center"),e.uppercase===!0&&(a.style.textTransform="uppercase"),typeof e.max_lines=="number"&&(a.classList.add("pw-clamp"),a.style.setProperty("-webkit-line-clamp",String(e.max_lines))),typeof e.color=="string"?a.style.color=e.color:e.color&&typeof e.color=="object"&&(a.classList.add("pw-grad"),a.style.backgroundImage=Ae(e.color)??""),Array.isArray(e.spans))for(let u of e.spans){let k=u.link==="terms"?x.links?.terms:u.link==="privacy"?x.links?.privacy:u.link,A=ye(k)&&!c.inControl,L=P(A?"a":"span");L.textContent=String(u.text),u.bold&&(L.style.fontWeight="700"),u.italic&&(L.style.fontStyle="italic");let z=[u.underline?"underline":"",u.strikethrough?"line-through":""].filter(Boolean).join(" ");z&&(L.style.textDecoration=z),typeof u.color=="string"&&u.color!==""&&(L.style.color=u.color),A&&ye(k)&&(L.href=k,L.target="_blank",L.rel="noopener noreferrer",L.addEventListener("click",D=>{H()||!n.onLink||(D.preventDefault(),n.onLink(k))})),a.append(L)}else a.textContent=String(e.text??"");return a}function Mt(e){if(typeof e!="string")return ne.system;let c=ie(e);if(c){let o=x.assets?.[c]?.family;return o?`"${o}", ${ne.system}`:ne.system}return ne[e]??ne.system}function Z(e){let c=ie(e);return c?x.assets?.[c]?.url||void 0:ye(e)?e:void 0}function At(e){let c=P("div","pw-img");typeof e.aspect=="number"&&(c.style.aspectRatio=String(e.aspect));let o=Z(e.src),r=e.mask;if(r?.shape==="circle")c.style.borderRadius="50%";else if(r?.shape==="rect"&&r.radius)c.style.borderRadius=_(r.radius);else if(r?.shape==="convex")c.style.setProperty("border-end-start-radius",`50% ${_(r.depth)}`),c.style.setProperty("border-end-end-radius",`50% ${_(r.depth)}`);else if(r?.shape==="concave"){let a=`radial-gradient(ellipse 50% ${_(r.depth)} at 50% 100%, transparent 98%, #000 100%)`;c.style.setProperty("-webkit-mask-image",a),c.style.setProperty("mask-image",a)}if(o){let a=P("img");a.src=o,a.decoding="async",a.style.objectFit=e.fit==="fill"?"cover":"contain",e.decorative===!0?(a.alt="",c.setAttribute("aria-hidden","true")):a.alt=String(e.alt??""),a.addEventListener("error",()=>a.style.visibility="hidden"),c.append(a)}if(e.overlay&&typeof e.overlay=="object"){let a=P("div","pw-overlay");a.style.backgroundImage=Ae(e.overlay)??"",c.append(a)}return{el:c,slots:{}}}function St(e){let c=P("div","pw-img");typeof e.aspect=="number"&&(c.style.aspectRatio=String(e.aspect));let o=Z(e.src);if(o){let r=P("video");r.src=o;let a=Z(e.poster);a&&(r.poster=a),r.muted=e.mute!==!1,r.loop=e.loop!==!1,r.playsInline=!0,r.controls=e.controls===!0,r.preload="auto",r.style.objectFit=e.fit==="fit"?"contain":"cover",r.autoplay=e.autoplay!==!1&&!re()&&!H(),typeof e.alt=="string"?r.setAttribute("aria-label",e.alt):r.setAttribute("aria-hidden","true"),c.append(r)}return{el:c,slots:{}}}function Rt(e,c){let o=e.action??{},r,a=o.type==="restore"||o.type==="offer_code";switch(o.type){case"close":c.inSheet?r=()=>pe(null):n.onClose&&(r=()=>n.onClose());break;case"restore":n.onRestore&&(r=()=>n.onRestore());break;case"offer_code":n.onOfferCode&&(x.platform??"web")!=="web"&&(r=()=>n.onOfferCode());break;case"open_url":case"terms":case"privacy":{let u=o.type==="open_url"?o.url:o.type==="terms"?x.links?.terms:x.links?.privacy;ye(u)&&(r=()=>n.onLink?n.onLink(u):void p?.open(u,"_blank","noopener,noreferrer"));break}case"sheet":o.sheet&&(r=()=>pe(o.sheet));break;case"select_package":o.package&&(r=()=>Se(o.package));break}if(!r&&!H())return null;let d=P("button");return d.type="button",o.type==="close"&&d.setAttribute("aria-label",le.close),d.addEventListener("click",()=>{!r||H()||(a?Ve(d,r):r())}),{el:d,slots:{content:d}}}function _t(e,c){let o=P("div","pw-tabs"),r=P("div","pw-tablist");r.setAttribute("role","tablist");let a=P("div","pw-tabpanel");a.setAttribute("role","tabpanel"),a.id=`${l}-${c}-panel`;let d={content:a},u=e.tabs.map(k=>k.id);return u.forEach((k,A)=>{let L=P("button","pw-tab");L.type="button",L.setAttribute("role","tab"),L.id=`${l}-${c}-tab-${A}`,L.setAttribute("aria-controls",a.id),L.dataset.tab=k,L.addEventListener("click",()=>Je(c,k)),L.addEventListener("keydown",z=>{let D=z.key==="ArrowRight"?A+1:z.key==="ArrowLeft"?A-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];Je(c,B),r.querySelector(`[data-tab="${B}"]`)?.focus()}),r.append(L),d[`label:${k}`]=L}),o.append(r,a),d.bar=r,{el:o,slots:d}}function Et(e,c){let o=P("div","pw-switch"),r=P("div","pw-switchrow"),a=P("span","pw-switchlabel");a.id=`${l}-${c}-label`;let d=P("button","pw-toggle");d.type="button",d.setAttribute("role","switch"),d.setAttribute("aria-labelledby",a.id),d.append(P("i")),d.addEventListener("click",()=>Ht(c,d.getAttribute("aria-checked")!=="true")),r.append(a,d);let u=P("div","pw-switchcontent");return o.append(r,u),{el:o,slots:{content:u,label:a,toggle:d}}}function Lt(e){let c=P("div","pw-carousel");c.setAttribute("role","region"),c.setAttribute("aria-roledescription","carousel");let o=P("div","pw-track");o.tabIndex=0,o.style.setProperty("--pw-peek",_(e.peek)),o.style.setProperty("--pw-gap",_(e.spacing)),typeof e.height=="number"&&(o.style.minHeight=_(e.height));let r=e.indicator??{},a=P("div",`pw-dots ${r.style??"dots"}`);a.style.setProperty("--pw-dot",_(r.size??8)),a.style.setProperty("--pw-dot-gap",_(r.spacing??6)),a.style.setProperty("--pw-dot-c",r.color??"#8888"),a.style.setProperty("--pw-dot-on",r.active_color??"currentColor"),r.style==="none"&&(a.hidden=!0),c.append(o,a);let d=()=>[...o.children].filter($=>$ instanceof(p?.HTMLElement??HTMLElement)),u=()=>{let $=d(),j=o.scrollLeft+o.clientWidth/2,O=0;return $.forEach((I,It)=>{Math.abs(I.offsetLeft+I.offsetWidth/2-j)<Math.abs(($[O]?.offsetLeft??0)+($[O]?.offsetWidth??0)/2-j)&&(O=It)}),O},k=$=>{let j=d();if(j.length===0)return;let O=e.loop?($+j.length)%j.length:Math.max(0,Math.min(j.length-1,$)),I=j[O];o.scrollTo?.({left:I.offsetLeft-(o.clientWidth-I.offsetWidth)/2,behavior:re()?"auto":"smooth"}),A(O)},A=$=>{[...a.children].forEach((j,O)=>j.setAttribute("aria-current",String(O===$)))};o.addEventListener("scroll",()=>A(u()),{passive:!0}),o.addEventListener("keydown",$=>{$.key!=="ArrowRight"&&$.key!=="ArrowLeft"||($.preventDefault(),k(u()+($.key==="ArrowRight"?1:-1)))});let L=!1,z=()=>L=!0,D=()=>L=!1;c.addEventListener("pointerenter",z),c.addEventListener("pointerleave",D),c.addEventListener("focusin",z),c.addEventListener("focusout",D);let B=[];if(typeof e.auto_advance_ms=="number"){let $=setInterval(()=>{if(L||re()||H())return;let j=d(),O=u();!e.loop&&O>=j.length-1||k(O+1)},e.auto_advance_ms);B.push(()=>clearInterval($))}return c.pwDots=$=>{a.children.length!==$&&(a.replaceChildren(...Array.from({length:$},(j,O)=>{let I=P("button");return I.type="button",I.setAttribute("aria-label",le.page(O+1,$)),I.addEventListener("click",()=>k(O)),I})),A(u()))},{el:c,slots:{pages:o},cleanup:B}}function $t(e,c){let o=c;switch(c.type){case"package":{let r=bn(o),d=!!x.packages[r]?.price;e.el.dataset.package=r,e.el.setAttribute("aria-checked",String(o.selected===!0)),e.el.setAttribute("aria-disabled",String(!d));break}case"purchase_button":{let r=String(o.package);e.el.dataset.package=r,e.el.disabled=K||!x.packages[r]?.price;break}case"switch":{let r=e.slots.toggle;r.setAttribute("aria-checked",String(o.on===!0)),r.style.setProperty("--pw-tint",String(o.tint??"")),r.style.setProperty("--pw-off",`color-mix(in srgb, ${b.tree.theme.colors.muted??"#888888"} 45%, transparent)`),e.slots.label.textContent=String(o.label??""),e.slots.label.hidden=o.label===void 0;break}case"tabs":{for(let r of o.tabs){let a=e.slots[`label:${r.id}`];a.setAttribute("aria-selected",String(r.selected)),a.tabIndex=r.selected?0:-1,r.selected&&e.slots.content.setAttribute("aria-labelledby",a.id)}o.bar&&De(e.slots.bar,{type:"stack",style:o.bar},"vertical");break}}}function Tt(e,c,o){let r=c,a={...o,inControl:o.inControl||c.type==="button"||c.type==="purchase_button"||c.type==="package"};switch(c.type){case"stack":case"package":{let d=c.type==="stack"?String(r.axis??"vertical"):"vertical",u=r.children.map(A=>[A,U(A,d,a)]).filter(A=>A[1]!==null),k=u.map(A=>A[1]);V(e.slots.children,k),zt(d,u),c.type==="stack"&&ce(e.el,k);break}case"button":case"purchase_button":{let d=r.content?U(r.content,"vertical",a):null;V(e.slots.content,d?[d]:[]);break}case"countdown":case"switch":{let d=r.content?U(r.content,"vertical",a):null;V(e.slots.content,d?[d]:[]),ce(e.slots.content,d?[d]:[]);break}case"tabs":{for(let u of r.tabs){let k=u.label?U(u.label,"vertical",{...a,inControl:!0}):null;V(e.slots[`label:${u.id}`],k?[k]:[])}let d=r.content?U(r.content,"vertical",a):null;V(e.slots.content,d?[d]:[]),ce(e.slots.content,d?[d]:[]);break}case"carousel":{let d=r.pages.map(u=>U(u,"page",a)).filter(Boolean);d.forEach((u,k)=>{u.setAttribute("role","group"),u.setAttribute("aria-roledescription","slide"),u.setAttribute("aria-label",le.page(k+1,d.length))}),V(e.slots.pages,d),ce(e.slots.pages,d),e.el.pwDots?.(d.length);break}}}function zt(e,c){let o=e==="horizontal"?"width":e==="vertical"?"height":null;if(!o)return;let r=u=>u?o==="width"?u.leading+u.trailing:u.top+u.bottom:0,a=c.filter(([u])=>u.style?.[o]==="fill"),d=Math.max(0,...a.map(([u])=>r(u.style?.padding)+r(u.style?.margin)));for(let[u,k]of a)k.style.flexBasis=_(d-r(u.style?.margin))}function ce(e,c){let o=c.filter(a=>a.dataset.pwType==="package");if(o.length===0){e.getAttribute("role")==="radiogroup"&&e.removeAttribute("role");return}e.setAttribute("role","radiogroup"),e.setAttribute("aria-label",le.packages);let r=o.find(a=>a.getAttribute("aria-checked")==="true")??o[0];for(let a of o)a.tabIndex=a===r?0:-1}function V(e,c){let o=()=>[...e.children].filter(a=>a.dataset?.pwPath!==void 0),r=o();for(let a of r)c.includes(a)||a.remove();r=o(),c.forEach((a,d)=>{r[d]!==a&&(e.insertBefore(a,r[d]??null),r=o())})}let Me=new WeakMap;function E(e,c,o){e.style.setProperty(c,o),Me.get(e).push(c)}function De(e,c,o){for(let u of Me.get(e)??[])e.style.removeProperty(u);Me.set(e,[]);for(let u of[...e.children])u.classList.contains("pw-bgvideo")&&u.remove();let r=c.style;if(c.type==="image"&&e.classList.toggle("natural",typeof c.aspect!="number"&&(r?.height===void 0||r.height==="fit")),!r)return;let a=(u,k)=>{k&&(E(e,`${u}-block-start`,_(k.top)),E(e,`${u}-block-end`,_(k.bottom)),E(e,`${u}-inline-start`,_(k.leading)),E(e,`${u}-inline-end`,_(k.trailing)))};a("padding",r.padding),a("margin",r.margin),Ie(e,"width",r.width,o),typeof r.height=="number"&&un.has(c.type)?(E(e,"min-height",_(r.height)),o==="vertical"&&E(e,"flex","none")):Ie(e,"height",r.height,o),typeof r.max_width=="number"&&E(e,"max-width",_(r.max_width));let d=r.background;if(d){if(d.type==="color")E(e,"background-color",d.color);else if(d.type==="linear"||d.type==="radial")E(e,"background-image",Ae(d)??"");else if(d.type==="image"){let u=Z(d.src);u&&(E(e,"background-image",`url("${u.replace(/"/g,"%22")}")`),E(e,"background-size",d.fit==="fit"?"contain":"cover"),E(e,"background-position","center"),E(e,"background-repeat","no-repeat"))}else if(d.type==="video"){let u=Z(d.src);if(u){let k=P("video","pw-bgvideo");k.src=u;let A=Z(d.poster);A&&(k.poster=A),k.muted=!0,k.loop=d.loop!==!1,k.playsInline=!0,k.autoplay=!re()&&!H(),k.setAttribute("aria-hidden","true"),E(e,"isolation","isolate"),e.prepend(k)}}}if(r.border&&c.type==="custom_html"?E(e,"border",`${_(r.border.width)} solid ${r.border.color??"transparent"}`):r.border&&(E(e,"--pw-bw",_(r.border.width)),E(e,"--pw-bc",r.border.color??"transparent")),r.corners){let u=r.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)),(c.type==="image"||c.type==="video"||d?.type==="image"||d?.type==="video")&&E(e,"overflow","hidden")}r.shadow&&E(e,"box-shadow",`${_(r.shadow.x)} ${_(r.shadow.y)} ${_(r.shadow.radius)} ${r.shadow.color}`),typeof r.opacity=="number"&&r.opacity!==1&&E(e,"opacity",String(r.opacity))}function Ie(e,c,o,r){if(o==null||o==="")return;if(r==="page"){c==="height"&&E(e,"height",o==="fill"?"100%":typeof o=="number"?_(o):o==="fit"?"fit-content":String(o));return}let a=r==="horizontal"?"width":r==="vertical"?"height":null;o==="fill"?c===a?(E(e,"flex","1 1 0"),E(e,`min-${c}`,"0")):r==="z"?E(e,c,"100%"):(E(e,"align-self","stretch"),E(e,c,"auto")):o==="fit"?(c===a&&E(e,"flex","0 0 auto"),E(e,c,"fit-content")):(E(e,c,typeof o=="number"?_(o):String(o)),c===a&&E(e,"flex","none"))}function Ae(e){let c=o=>o.map(r=>`${r.color} ${(r.at*100).toFixed(2)}%`).join(", ");if(e.type==="linear")return`linear-gradient(${e.angle}deg, ${c(e.stops)})`;if(e.type==="radial"){let o=`${(e.radius*100).toFixed(2)}%`;return`radial-gradient(ellipse ${o} ${o} at ${(e.center_x*100).toFixed(2)}% ${(e.center_y*100).toFixed(2)}%, ${c(e.stops)})`}}function Ot(e,c){let o=c.animation;if(!o||x.animate===!1||re()||typeof e.animate!="function")return;let r=24,d={fade:{opacity:0},slide_up:{opacity:0,transform:`translateY(${r}px)`},slide_down:{opacity:0,transform:`translateY(-${r}px)`},slide_leading:{opacity:0,transform:`translateX(-${r}px)`},slide_trailing:{opacity:0,transform:`translateX(${r}px)`},scale:{opacity:0,transform:"scale(0.92)"}}[o.type];d&&e.animate([d,{opacity:1,transform:"none"}],{duration:o.duration_ms,delay:o.delay_ms,easing:ut[o.easing]??ut.ease_out,fill:"backwards"})}function de(){n.onState?.({...R}),G()}function Se(e){R.selected===e&&b.tree.selected===e||(R.selected=e,de(),n.onSelect?.(Te(e)))}function Re(e){H()||e.getAttribute("aria-disabled")==="true"||Se(e.dataset.package??"")}function Ft(e,c){if(e.key===" "||e.key==="Enter"){e.preventDefault(),Re(c);return}let o=e.key==="ArrowDown"||e.key==="ArrowRight"?1:e.key==="ArrowUp"||e.key==="ArrowLeft"?-1:0;if(o===0)return;e.preventDefault();let r=c.closest("[role=radiogroup]"),d=(r?[...r.children].filter(A=>A.dataset.pwType==="package"):[c]).filter(A=>A.getAttribute("aria-disabled")!=="true"),u=d.indexOf(c),k=d[(u+o+d.length)%d.length];k&&(Re(k),(T.get(k.dataset.pwPath??"")?.el??k).focus())}function Je(e,c){if(H())return;R.tabs={...R.tabs,[e]:c};let o=Ct(e,c);o&&(R.selected=o),de()}function Ct(e,c){return Ue(e)?.tabs?.find(r=>r.id===c)?.package}function Ht(e,c){if(H())return;R.switches={...R.switches,[e]:c};let o=Ue(e),r=c?o?.on_package:o?.off_package;r&&(R.selected=r),de()}function Ue(e){let c=x.definition;for(let o of e.match(/[^.[\]]+/g)??[])c=c?.[/^\d+$/.test(o)?Number(o):o];return c}async function Ve(e,c){if(!(H()||K)){K=!0,e.disabled=!0,e.setAttribute("aria-busy","true");try{await c()}finally{K=!1,e.removeAttribute("aria-busy"),e.disabled=!1;for(let o of T.values())o.type==="purchase_button"&&(o.el.disabled=!x.packages[o.el.dataset.package??""]?.price)}}}async function jt(e){x.packages[e]?.price&&await n.onPurchase(Te(e))}function pe(e){H()&&e!==null&&R.sheet===e||(e&&!R.sheet&&(je=y.activeElement??null),R.sheet=e,de(),e||je?.focus())}function Nt(){let e=R.sheet,c=e?b.tree.sheets?.[e]:void 0;if(!c){M.remove();return}M.className="pw-layer";let o=M.firstElementChild;if(!o){o=P("div","pw-sheet"),o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true"),o.tabIndex=-1;let a=P("div","pw-grab");a.setAttribute("aria-hidden","true"),o.append(a),M.append(o),M.addEventListener("click",d=>{d.target===M&&!H()&&pe(null)}),o.addEventListener("keydown",d=>Dt(d,o))}o.style.background=b.tree.theme.colors.background??"",o.setAttribute("aria-label",b.sheetTitles[e]??"");let r=U(c,"vertical",{inControl:!1,inSheet:!0});V(o,r?[r]:[]),M.isConnected||(g.append(M),queueMicrotask(()=>(Be(o)[0]??o).focus()))}function Be(e){return[...e.querySelectorAll('button:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')].filter(c=>!c.hidden)}function Dt(e,c){if(e.key==="Escape"){e.preventDefault(),pe(null);return}if(e.key!=="Tab")return;let o=Be(c);if(o.length===0){e.preventDefault();return}let r=o[0],a=o[o.length-1],d=y.activeElement;e.shiftKey&&d===r?(e.preventDefault(),a.focus()):!e.shiftKey&&d===a&&(e.preventDefault(),r.focus())}function qe(e){try{e.contentWindow?.postMessage({type:"palbase.paywall",package:b.tree.selected,locale:b.language,appearance:x.appearance},"*")}catch{}}function We(e){for(let c of y.querySelectorAll("[data-pw-highlight]"))c.removeAttribute("data-pw-highlight");be=e,e&&T.get(e)?.el.setAttribute("data-pw-highlight","")}let Ke=e=>e.composedPath().find(c=>c instanceof(p?.HTMLElement??HTMLElement)&&c.dataset.pwPath!==void 0);g.addEventListener("click",e=>{if(!n.editor)return;let c=Ke(e);c&&(e.preventDefault(),e.stopPropagation(),n.editor.onPick(c.dataset.pwPath))},!0),g.addEventListener("pointerover",e=>{if(n.editor){for(let c of y.querySelectorAll("[data-pw-hover]"))c.removeAttribute("data-pw-hover");Ke(e)?.setAttribute("data-pw-hover","")}}),g.addEventListener("pointerleave",()=>{for(let e of y.querySelectorAll("[data-pw-hover]"))e.removeAttribute("data-pw-hover")});let Xe=()=>G();return ke?.addEventListener?.("change",Xe),G(),{get selected(){return Te(b.tree.selected)},get state(){return{...R}},select(e){Se(e)},update(e){x={...x,...e},e.state&&Object.assign(R,e.state),G()},highlight(e){We(e)},replay(){for(let e of T.values())e.cleanup.forEach(c=>c());T=new Map;for(let e of[h,w,v])e.replaceChildren();G()},destroy(){clearTimeout(ve),Ce?.disconnect(),i.fonts?.removeEventListener?.("loadingdone",He),ke?.removeEventListener?.("change",Xe);for(let e of T.values())e.cleanup.forEach(c=>c());f.remove()}}}function kn(s,t,n){let i=s.defaultView;try{if(i&&"adoptedStyleSheets"in t&&typeof i.CSSStyleSheet=="function"){let l=new i.CSSStyleSheet;l.replaceSync(n),t.adoptedStyleSheets=[l];return}}catch{}let p=s.createElement("style");p.textContent=n,t.append(p)}var ht={version:"0.3.3"};var yt=`palbase-js/${ht.version}`;var we=class{placement;source;definition;assets;offerings;shown;deps;exposed=!1;constructor(t,n,i,p,l,f,y={}){this.placement=t,this.source=n,this.definition=i,this.assets=y,this.offerings=p,this.shown=l,this.deps=f}packages(t){return rt(An(this.offerings,ct(this.definition),t),t)}render(t,n){let i=n.locale??globalThis.navigator?.language??this.definition.default_locale,p=n.appearance===void 0?Pn():void 0,l=this.packages(i),f=gt(t,{definition:this.definition,locale:i,appearance:n.appearance??(p?.matches?"dark":"light"),platform:"web",packages:l,eligible:Object.entries(l).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 Pn(){try{return globalThis.matchMedia?.("(prefers-color-scheme: dark)")}catch{return}}function Mn(s,t){if(!s)return;let n=t.split("-")[0];return s[t]?.name??s[n]?.name??Object.values(s).find(i=>i.name)?.name}function An(s,t,n){let i=[];for(let p of t){let[l,f]=p.split("."),y=s.products.find(w=>w.key===l),g=y?.channels.web,h=g?.plans.find(w=>w.key===f);!y||!g||!h||i.push({key:p,productName:Mn(g.locales,n)??y.key,price:{amount:h.price.amount,currency:h.price.currency},period:h.period,intro:h.intro})}return i}var Sn={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"}},mt=s=>({type:"button",action:{type:s},content:{type:"text",text:{t:s},size:"caption",color:"muted"}});function Rn(s){let t=s.products.flatMap(n=>(n.channels.web?.plans??[]).map(i=>({product:n.key,plan:i.key}))).slice(0,6);return t.length===0?null:{schema:2,name:"Default",default_locale:"en",locales:Sn,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:i})=>({type:"package",product:n,plan:i,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:[mt("terms"),mt("privacy")]}]}}}function se(){try{return globalThis.localStorage}catch{return}}function _n(s){try{let t=se()?.getItem(s);if(!t)return;let n=JSON.parse(t),i=n?.answer;return typeof i!="object"||i===null||typeof i.paywall_id!="string"||typeof i.version!="number"||typeof i.definition!="object"||i.definition===null||typeof i.offerings!="object"||i.definition.schema!==2?void 0:{etag:typeof n.etag=="string"?n.etag:void 0,answer:i}}catch{return}}function me(s,t){try{t?se()?.setItem(s,JSON.stringify(t)):se()?.removeItem(s)}catch{}}var wt=()=>globalThis.crypto?.randomUUID?globalThis.crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,bt;function En(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 i=wt();if(se()?.setItem(t,i),se()?.getItem(t)===i)return i}catch{}return bt??=wt(),bt}async function Zn(s,t,n,i,p={}){let{signal:l,fetch:f}=p,y=tt(p.attributes),g=`palbase.paywall.${t}.${n}`,h=En(t),v={checkout:i,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 Ge(b.assets??[],{signal:l,...f?{fetch:f}:{}})),x=_n(g),R;try{R=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":yt,...p.appVersion?{"X-Palbase-Client-Version":p.appVersion}:{},...p.locale?{"Accept-Language":p.locale}:{},...y!==void 0?{"X-Palbase-Attributes":y}:{},...x?.etag?{"If-None-Match":x.etag}:{}},signal:l})}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,l);if(x&&!l?.aborted)return M(x.answer,"cache");throw b}return R.status===200?(me(g,{etag:R.headers.get("etag")??void 0,answer:R.data}),M(R.data,"server")):R.status===304&&x?M(x.answer,"server"):(me(g,void 0),ze(s,n,v,l))}async function ze(s,t,n,i){let p=(await s.getOfferings({query:{channel:"web"},signal:i})).data,l=Rn(p);return l?new we(t,"default",l,p,void 0,n):null}export{Ut as a,ie as b,Ge as c,qt as d,Yt as e,tt as f,_e as g,st as h,Qt as i,rt as j,ue as k,he as l,Fn as m,cn as n,ct as o,Cn as p,dt as q,gt as r,we as s,Rn as t,Zn as u};
|