1function F(t){const e=t.route??(typeof window<"u"?window.location.pathname:void 0);return{...t,route:e}}function m(t,e={}){if(typeof window>"u")return;const r=F(e);window.posthog&&window.posthog.capture(t,r),window.gtag&&window.gtag("event",t,r)}function X(t){return/^https?:\/\//i.test(t)}function M(t){const e=t?.trim();return e&&X(e)?e:null}function H(t,e){if(typeof window>"u")return;const r=M(t);if(!r)return;m("checkout_opened",{source:e?.source,trigger:e?.trigger,checkoutUrl:r,destination:r,plan:e?.plan,variant:e?.variant,userState:e?.userState,hadPriorSuccessfulRun:e?.hadPriorSuccessfulRun,flowId:e?.flowId});const n=window.LemonSqueezy;if(n&&n.Url&&typeof n.Url.Open=="function"){n.Url.Open(r);return}window.open(r,"_blank","noopener,noreferrer")}const R=["pdf.merge","pdf.split","pdf.compress"],D=[...R,"pdf.ocr","pdf.rotate","pdf.delete_pages","pdf.edit","pdf.to_image","office.convert","pdf.protect.encrypt","pdf.protect.unlock","pdf.redact.verify"],V=[...D],G=new Set(V);function W(t,e){const r=Array.isArray(t)?t:[],i=Array.from(new Set(r.filter(o=>typeof o=="string"))).filter(o=>G.has(o)),a=e==="pro"||e==="trial"?new Set(D):new Set(R);return i.filter(o=>a.has(o))}function v(t){return[...t==="pro"||t==="trial"?D:R]}function Z(t){return t==="pro"?"pro":t==="trial"?"trial":"basic"}function $(t,e){return t==="free"?e==="basic"?"free":null:t==="pro_monthly"||t==="pro_yearly"||t==="pro_lifetime"?e==="pro"||e==="trial"?t:null:t==null||t===""?ee(e):null}function ee(t){return t==="pro"||t==="trial"?"pro_monthly":"free"}const u="localpdf_trial_start",y="localpdf_trial_state",E="localpdf_trial_used",_=4320*60*1e3,te=3600*1e3;let w=null,g=null;const re="localpdf_db",d="trial_store",T="trial_start_time";async function j(){return new Promise((t,e)=>{if(typeof indexedDB>"u")return e(new Error("IndexedDB is not supported"));const r=indexedDB.open(re,1);r.onupgradeneeded=()=>{const n=r.result;n.objectStoreNames.contains(d)||n.createObjectStore(d)},r.onsuccess=()=>t(r.result),r.onerror=()=>e(r.error)})}async function ne(t){try{const e=await j();return new Promise((r,n)=>{const o=e.transaction(d,"readonly").objectStore(d).get(t);o.onsuccess=()=>r(o.result),o.onerror=()=>n(o.error)})}catch{return null}}async function U(t,e){try{const r=await j();return new Promise((n,i)=>{const c=r.transaction(d,"readwrite").objectStore(d).put(e,t);c.onsuccess=()=>n(),c.onerror=()=>i(c.error)})}catch{}}async function ie(){if(typeof window>"u"||!window.indexedDB)return;const t=localStorage.getItem(u),e=await ne(T);if(e===-1){t&&(localStorage.removeItem(u),localStorage.removeItem(y)),localStorage.setItem(E,"true");return}t&&!e?await U(T,Number(t)):!t&&e&&localStorage.setItem(u,String(e))}function l(){if(typeof localStorage>"u")return{isActive:!1,startedAt:null,endsAt:null,daysRemaining:0,hoursRemaining:0,isExpiredButNotTracked:!1,trialAvailable:!0};const t=localStorage.getItem(E)==="true",e=localStorage.getItem(y),r=localStorage.getItem(u);if(t)return{isActive:!1,startedAt:r?Number(r):null,endsAt:r?Number(r)+_:null,daysRemaining:0,hoursRemaining:0,isExpiredButNotTracked:!1,trialAvailable:!1};if(e==="expired")return{isActive:!1,startedAt:r?Number(r):null,endsAt:r?Number(r)+_:null,daysRemaining:0,hoursRemaining:0,isExpiredButNotTracked:!0,trialAvailable:!1};if(!r)return{isActive:!1,startedAt:null,endsAt:null,daysRemaining:0,hoursRemaining:0,isExpiredButNotTracked:!1,trialAvailable:!0};const n=Number(r);if(Number.isNaN(n))return localStorage.removeItem(u),{isActive:!1,startedAt:null,endsAt:null,daysRemaining:0,hoursRemaining:0,isExpiredButNotTracked:!1,trialAvailable:!0};const i=n+_,a=Date.now();if(a>=i)return localStorage.setItem(y,"expired"),{isActive:!1,startedAt:n,endsAt:i,daysRemaining:0,hoursRemaining:0,isExpiredButNotTracked:!0,trialAvailable:!1};const o=i-a;return{isActive:!0,startedAt:n,endsAt:i,daysRemaining:Math.floor(o/(1440*60*1e3)),hoursRemaining:Math.floor(o%(1440*60*1e3)/(3600*1e3)),isExpiredButNotTracked:!1,trialAvailable:!1}}function oe(t){w=t,I()}function I(){if(typeof window>"u")return;g!==null&&(clearTimeout(g),g=null);const t=l();if(t.isExpiredButNotTracked){w?.();return}if(!t.isActive||t.endsAt===null)return;const e=t.endsAt-Date.now();if(e<=0){l().isExpiredButNotTracked&&w?.();return}g=setTimeout(()=>{if(g=null,l().isExpiredButNotTracked){w?.();return}I()},Math.min(e+250,te))}function se(){if(typeof localStorage<"u"&&localStorage.getItem(E)==="true")return l();const t=Date.now();localStorage.setItem(u,String(t)),localStorage.removeItem(y),U(T,t).catch(()=>{});const e=l();return I(),e}function A(){localStorage.removeItem(u),localStorage.removeItem(y),localStorage.setItem(E,"true"),U(T,-1).catch(()=>{})}const N="localpdf_dev_pro_override";function ae(){if(typeof localStorage>"u")return!1;try{return localStorage.getItem(N)==="1"}catch{return!1}}function le(t){if(!(typeof localStorage>"u"))try{t?localStorage.setItem(N,"1"):localStorage.removeItem(N)}catch{}}const f={userId:"local-user",plan:"basic",entitlements:v("basic")},O={userId:"local-user",plan:"pro",entitlements:v("pro")};function b(){return{userId:"local-user",plan:"pro",entitlements:v("trial")}}function C(t,e=!1){const r=e?t:t.replace(/-/g,"+").replace(/_/g,"/"),n=r.padEnd(r.length+(4-r.length%4)%4,"=");return typeof Buffer<"u"?Buffer.from(n,"base64").toString("binary"):atob(n)}function B(t){const e=C(t);if(typeof Buffer<"u")return Buffer.from(e,"binary").toString("utf8");
1const r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return new TextDecoder().decode(r)}class ce{constructor(e,r,n={}){this.storageKey=e,this.jwtPublicKeyPem=r,this.options=n}currentContext=f;realContext=f;listeners=new Set;getContext(){return this.currentContext}isLocalProAvailable(){return this.options.allowLocalPro===!0}isLocalProEnabled(){return this.isLocalProAvailable()&&ae()}setLocalPro(e){return this.isLocalProAvailable()?(le(e),this.currentContext=this.isLocalProEnabled()?O:this.realContext,this.notify(),this.isLocalProEnabled()):!1}setContext(e){this.realContext=e,this.currentContext=this.isLocalProEnabled()?O:e,this.notify()}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){for(const e of this.listeners)e(this.currentContext)}async initialize(){typeof localStorage<"u"&&await ie(),oe(()=>{l().isExpiredButNotTracked&&(m("trial_expired",{source:"trial_watch"}),A(),typeof localStorage<"u"&&!localStorage.getItem(this.storageKey)&&this.setContext(f))}),I();let e=l();e.isExpiredButNotTracked&&(m("trial_expired",{source:"billing_init"}),A(),e=l());const r=typeof localStorage<"u"?localStorage.getItem(this.storageKey):null;if(!r){this.setContext(e.isActive?b():f);return}let n=r,i=await this.verifyToken(n);if(!i){const o=await this.refreshBillingToken(n).catch(()=>null);o&&(i=await this.verifyToken(o),i&&(n=o,typeof localStorage<"u"&&localStorage.setItem(this.storageKey,n)))}if(!i){typeof localStorage<"u"&&localStorage.removeItem(this.storageKey),this.setContext(e.isActive?b():f);return}const a={userId:"local-user",plan:i.plan,entitlements:i.entitlements};(e.isActive||e.isExpiredButNotTracked)&&(m("trial_convert",{trialDaysRemaining:e.daysRemaining,source:"token_verified_init"}),A()),this.setContext(a);try{const o=n.split("."),c=JSON.parse(B(o[1])),h=Math.floor(Date.now()/1e3);typeof c.exp=="number"&&c.exp-h<7200*60&&this.refreshBillingToken(n).then(async S=>{S&&await this.saveToken(S)}).catch(()=>{})}catch{}}async saveToken(e){const r=await this.verifyToken(e);if(!r)return!1;const n=l(),i=n.isActive||n.isExpiredButNotTracked;return typeof localStorage<"u"&&(localStorage.setItem(this.storageKey,e),i&&(m("trial_convert",{trialDaysRemaining:n.daysRemaining,source:"manual_save"}),A())),this.setContext({userId:"local-user",plan:r.plan,entitlements:r.entitlements}),!0}getStoredToken(){return typeof localStorage<"u"?localStorage.getItem(this.storageKey):null}clearToken(){typeof localStorage<"u"&&localStorage.removeItem(this.storageKey);const e=l();this.setContext(e.isActive?b():f)}startTrial(){se(),this.setContext(b())}async refreshBillingToken(e){try{const r=await fetch("/api/billing/restore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:e})});if(!r.ok)return null;const n=await r.json();if(n.success&&typeof n.token=="string")return n.token}catch(r){console.error("Error in refreshBillingToken:",r)}return null}async verifyToken(e){try{if(!this.jwtPublicKeyPem?.trim())return null;const r=e.split(".");if(r.length!==3)return null;const n=JSON.parse(B(r[0])),i=JSON.parse(B(r[1])),a=Uint8Array.from(C(r[2]),x=>x.charCodeAt(0));if(n.alg!=="RS256"||n.typ!=="JWT")return null;const o=Math.floor(Date.now()/1e3);if(typeof i.exp!="number"||i.exp<=o||typeof i.iat!="number"||i.iat>o+300||i.nbf!==void 0&&(typeof i.nbf!="number"||i.nbf>o+300)||i.iss!=="localpdf-billing"||i.aud!=="localpdf-v6"||typeof i.sub!="string"||i.sub.trim().length===0)return null;
1const h=this.jwtPublicKeyPem.replace(/\\n/g,` 2`).replace(/-----BEGIN PUBLIC KEY-----|-----END PUBLIC KEY-----|\s+/g,"");if(!h)return null;const S=Uint8Array.from(C(h,!0),x=>x.charCodeAt(0)),k=globalThis.crypto;if(!k?.subtle)return null;const Y=await k.subtle.importKey("spki",S,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!1,["verify"]),Q=new TextEncoder().encode(`${r[0]}.${r[1]}`);if(!await k.subtle.verify("RSASSA-PKCS1-v1_5",Y,a,Q))return null;const p=Z(i.plan);if(p==="trial"||!$(i.tier,p))return null;const K=W(i.entitlements,p),q=v(p);return{plan:p,entitlements:K.length>0?K:q}}catch{return null}}}const ue=new ce("v6_subscription_jwt",`-----BEGIN PUBLIC KEY----- 3MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5xPX8DuQ2LNTRswlSiYh 4OFJhnzUdnxKz6twJ5uen63ol36kmfHphA6RDrDuFbNl5/zHj6mDHwRCquMHIk5LJ 5ddZQrfl8JxL4eWi1yBvGxpUUDvixmyg+KQSSiwAjI7tiui41tXQyEimLgl5MJtez 6rMBurruU3dfBtcwg2TsoILKl/oA8rymudPCSl3KzJBhnpbunSiuDVU1wVDfvUwkj 7BiFv96QT6N2rYNV0J7E/kkK0ZP3uTibDn8EXtesdnV9LPQkLlXlib+zMvYqk8+1/ 8LS0P1vLRU+fX5y0fY5XvQA236JlnaQgNSrBSdS4ZCIp/ct/DoJksG9W2FHX0z/gf 9gwIDAQAB 10-----END PUBLIC KEY-----`);function J(t,e){const r=document.getElementById(t);if(!r)return;const n=M(r.getAttribute("data-checkout-url")??void 0);r.addEventListener("click",()=>{if(n){H(n,{source:"pricing_page",trigger:t,plan:"pro",variant:e,userState:"local",hadPriorSuccessfulRun:!1,flowId:t});return}console.error("Missing or invalid LemonSqueezy checkout URL"),alert("Billing configuration is missing. Please contact support.")})}J("buy-pro-lifetime","lifetime");J("buy-pro-yearly","yearly");const L=document.getElementById("restore-license-btn"),P=document.getElementById("license-key-input"),s=document.getElementById("restore-status");async function z(){const t=P?.value?.trim();if(!t){s&&(s.className="status-message error",s.textContent="Enter your license key to restore Pro access."),P?.focus();return}L?.toggleAttribute("disabled",!0),s&&(s.className="status-message",s.textContent="Restoring...");try{const e=await fetch("/api/billing/restore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({licenseKey:t})}),r=await e.json();if(e.ok&&r.token){if(!await ue.saveToken(r.token))throw new Error("Failed to verify subscription token locally");s&&(s.className="status-message success",s.textContent="License restored successfully. Redirecting to app..."),setTimeout(()=>{window.location.assign("/app")},1800);return}throw new Error(r.error||"Failed to restore license")}catch(e){s&&(s.className="status-message error",s.textContent=e?.message||"Restore failed")}finally{L?.toggleAttribute("disabled",!1)}}L?.addEventListener("click",z);P?.addEventListener("keydown",t=>{t.key==="Enter"&&(t.preventDefault(),z())});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.