@pdfkiln/pdfkiln 1.0.2 → 1.0.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/README.md +1 -1
- package/chromium.json +13 -13
- package/dist/bundle/pdfkiln.cjs +1 -1
- package/dist/bundle/wkhtmltoimage.cjs +1 -1
- package/dist/bundle/wkhtmltopdf.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Drop-in replacement for wkhtmltopdf, powered by Chromium.
|
|
|
7
7
|
- `wkhtmltopdf` and `wkhtmltoimage` accept the command lines of wkhtmltopdf and wkhtmltoimage 0.12.6, with the same options, defaults, messages and exit codes;
|
|
8
8
|
- `pdfkiln` offers its own interface, with modern print defaults (`pdfkiln --help`).
|
|
9
9
|
|
|
10
|
-
The first conversion downloads chrome-headless-shell 156.0.8078.
|
|
10
|
+
The first conversion downloads chrome-headless-shell 156.0.8078.73 (Chrome for Testing, linux64, linux-arm64, mac-arm64, mac-x64, win32, win64), checks its SHA-256, and keeps it in the user's cache: `~/.cache/pdfkiln` (or `$XDG_CACHE_HOME`), `~/Library/Caches/pdfkiln`, `%LOCALAPPDATA%\pdfkiln`. `PDFKILN_CACHE_DIR` changes that folder; `PDFKILN_CHROMIUM` points to a chrome-headless-shell of your own.
|
|
11
11
|
|
|
12
12
|
Chromium's sandbox stays on: run as an unprivileged user. On Ubuntu 23.10 and later, AppArmor restricts the user namespaces it needs; an AppArmor profile for the downloaded binary allows them.
|
|
13
13
|
|
package/chromium.json
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"product": "chrome-headless-shell",
|
|
3
3
|
"channel": "Stable",
|
|
4
|
-
"version": "156.0.8078.
|
|
4
|
+
"version": "156.0.8078.73",
|
|
5
5
|
"source": "https://storage.googleapis.com/chrome-for-testing-public",
|
|
6
6
|
"archives": {
|
|
7
7
|
"linux64": {
|
|
8
8
|
"file": "chrome-headless-shell-linux64.zip",
|
|
9
|
-
"size":
|
|
10
|
-
"sha256": "
|
|
9
|
+
"size": 126938225,
|
|
10
|
+
"sha256": "77eb8d52798efc7a857ab61abcc62a456d8ea9635b02341d06dffee2761768c8"
|
|
11
11
|
},
|
|
12
12
|
"linux-arm64": {
|
|
13
13
|
"file": "chrome-headless-shell-linux-arm64.zip",
|
|
14
|
-
"size":
|
|
15
|
-
"sha256": "
|
|
14
|
+
"size": 126713821,
|
|
15
|
+
"sha256": "98c084708f0f1fa4ed589ad601cc79b437f0cebe60ffc9794af78a085c01a2a7"
|
|
16
16
|
},
|
|
17
17
|
"mac-arm64": {
|
|
18
18
|
"file": "chrome-headless-shell-mac-arm64.zip",
|
|
19
|
-
"size":
|
|
20
|
-
"sha256": "
|
|
19
|
+
"size": 103949688,
|
|
20
|
+
"sha256": "512c7d34cd5b65d617a39a48915b490eed4208a63e9d47b0fd7893e83be85765"
|
|
21
21
|
},
|
|
22
22
|
"mac-x64": {
|
|
23
23
|
"file": "chrome-headless-shell-mac-x64.zip",
|
|
24
|
-
"size":
|
|
25
|
-
"sha256": "
|
|
24
|
+
"size": 109508986,
|
|
25
|
+
"sha256": "be798095cd693357a7a6a0e7a0c4ebd81563e16f51225eb98aacc906d6326519"
|
|
26
26
|
},
|
|
27
27
|
"win32": {
|
|
28
28
|
"file": "chrome-headless-shell-win32.zip",
|
|
29
|
-
"size":
|
|
30
|
-
"sha256": "
|
|
29
|
+
"size": 119029046,
|
|
30
|
+
"sha256": "64f657a50e287c856d2337a19d92ca7383255bd1d0f962bbb9f61874c7e3b5be"
|
|
31
31
|
},
|
|
32
32
|
"win64": {
|
|
33
33
|
"file": "chrome-headless-shell-win64.zip",
|
|
34
|
-
"size":
|
|
35
|
-
"sha256": "
|
|
34
|
+
"size": 125506562,
|
|
35
|
+
"sha256": "e6d26810df71efd0a3dfd0f7246d75d279ebdf8a8ec153d1ac44069657298628"
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
package/dist/bundle/pdfkiln.cjs
CHANGED
|
@@ -226,7 +226,7 @@ You can also empty the whole browser cache with \`npx ${o} clear\` and then run
|
|
|
226
226
|
1. you did not perform an installation before running the script (e.g. \`npx puppeteer browsers install ${s}\`) or
|
|
227
227
|
2. your cache path is incorrectly configured (which is: ${i.cacheDirectory}).
|
|
228
228
|
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.`)}return n}},T3=new WeakMap});async function eD(r){await oq.default.promises.rm(r,bre)}var oq,bre,R3=b(()=>{oq=Ae(require("node:fs"),1);bre={force:!0,recursive:!0,maxRetries:10,retryDelay:100}});function sq(r,e=[]){let t=r.endsWith("=")?r:`${r}=`;return e.filter(i=>i.startsWith(t)).flatMap(i=>i.substring(i.indexOf("=")+1).trim().split(",").map(n=>n.trim())).filter(i=>i)}function aq(r,e){let t=e.endsWith("=")?e:`${e}=`,i=0;for(;i<r.length;)r[i].startsWith(t)?r.splice(i,1):i++;return r}var cq,lq,tD,rD,M3=b(()=>{cq=require("node:fs/promises"),lq=Ae(require("node:os"),1),tD=Ae(require("node:path"),1);dd();je();Ct();$S();E3();R3();rD=class extends op{constructor(e,t){super(e,"chrome",t)}async launch(e={}){return(await this.puppeteer.configuration()).logLevel==="warn"&&process.platform==="darwin"&&process.arch==="x64"&&lq.default.cpus()[0]?.model.includes("Apple")&&console.warn(["\x1B[1m\x1B[43m\x1B[30m","Degraded performance warning:\x1B[0m\x1B[33m","Launching Chrome on Mac Silicon (arm64) from an x64 Node installation results in","Rosetta translating the Chrome binary, even if Chrome is already arm64. This would","result in huge performance issues. To resolve this, you must run Puppeteer with","a version of Node built for arm64."].join(`
|
|
229
|
-
`)),await super.launch(e)}async computeLaunchArguments(e={}){let{ignoreDefaultArgs:t=!1,args:i=[],pipe:n=!1,debuggingPort:o,channel:s,executablePath:a}=e,c=[];t?Array.isArray(t)?c.push(...this.defaultArgs(e).filter(h=>!t.includes(h))):c.push(...i):c.push(...this.defaultArgs(e)),c.some(h=>h.startsWith("--remote-debugging-"))||(n?(ee(!o,"Browser should be launched with either pipe or debugging port - not both."),c.push("--remote-debugging-pipe")):c.push(`--remote-debugging-port=${o||0}`));let l=!1,u=c.findIndex(h=>h.startsWith("--user-data-dir")),d;if(u<0){l=!0;let h=await this.getProfilePath();d=await(0,cq.mkdtemp)(h),c.push(`--user-data-dir=${d}`)}else{let h=c[u].split("=",2)[1];ee(typeof h=="string","`--user-data-dir` is malformed"),d=h}let f=a;return f||(ee(s||!this.puppeteer._isPuppeteerCore,"An `executablePath` or `channel` must be specified for `puppeteer-core`"),f=s?await this.executablePath(s):await this.resolveExecutablePath(e.headless??!0)),{executablePath:f,args:c,isTempUserDataDir:l,userDataDir:d}}async cleanUserDataDir(e,t){if(t.isTemp)try{await eD(e)}catch(i){this.logger(H.error)?.(i)}}defaultArgs(e={}){let t=sq("--disable-features",e.args);e.args&&t.length>0&&aq(e.args,"--disable-features");let i=process.env.PUPPETEER_TEST_EXPERIMENTAL_CHROME_FEATURES==="true",n=sq("--enable-features",e.args);e.args&&n.length>0&&aq(e.args,"--enable-features");let o=["PdfOopif",...n].filter(h=>h!==""),a=["--allow-pre-commit-input","--disable-background-networking","--disable-background-timer-throttling","--disable-backgrounding-occluded-windows","--disable-breakpad","--disable-client-side-phishing-detection","--disable-component-extensions-with-background-pages","--disable-crash-reporter","--disable-default-apps","--disable-dev-shm-usage","--disable-hang-monitor","--disable-infobars","--disable-ipc-flooding-protection","--disable-popup-blocking","--disable-prompt-on-repost","--disable-renderer-backgrounding","--disable-search-engine-choice-screen","--disable-sync","--enable-automation","--export-tagged-pdf","--force-color-profile=srgb","--generate-pdf-document-outline","--metrics-recording-only","--no-first-run","--password-store=basic","--use-mock-keychain",`--disable-features=${["Translate","AcceptCHFrame","MediaRouter","OptimizationHints","WebUIReloadButton","WebUIOmniboxPopup","WebUIOmniboxAimPopup",...i?[]:["ProcessPerSiteUpToMainFrameThreshold","IsolateSandboxedIframes"],...t].filter(h=>h!=="").filter(h=>!o.includes(h)).join(",")}`,`--enable-features=${o.join(",")}`].filter(h=>h!==""),{devtools:c=!1,headless:l=!c,args:u=[],userDataDir:d,enableExtensions:f=!1}=e;return process.env.PUPPETEER_DANGEROUS_NO_SANDBOX==="true"&&!u.includes("--no-sandbox")&&a.push("--no-sandbox"),d&&a.push(`--user-data-dir=${tD.default.posix.isAbsolute(d)||tD.default.win32.isAbsolute(d)?d:tD.default.resolve(d)}`),c&&a.push("--auto-open-devtools-for-tabs"),l&&a.push(l==="shell"?"--headless":"--headless=new","--hide-scrollbars","--mute-audio"),f||a.push("--disable-extensions"),u.every(h=>h.startsWith("-"))&&a.push("about:blank"),a.push(...u),a}async executablePath(e,t=!0){return e?Vh({browser:De.CHROME,channel:D3(e)},t):await this.resolveExecutablePath(void 0,t)}}});var uq,sp,dq,I3,iD,L3=b(()=>{uq=Ae(require("node:fs"),1),sp=require("node:fs/promises"),dq=Ae(require("node:os"),1),I3=Ae(require("node:path"),1);dd();je();Ct();$S();R3();iD=class r extends op{constructor(e,t){super(e,"firefox",t)}static getPreferences(e){return{...e,"fission.webContentIsolationStrategy":0}}async computeLaunchArguments(e={}){let{ignoreDefaultArgs:t=!1,args:i=[],executablePath:n,pipe:o=!1,extraPrefsFirefox:s={},debuggingPort:a=null}=e,c=[];t?Array.isArray(t)?c.push(...this.defaultArgs(e).filter(h=>!t.includes(h))):c.push(...i):c.push(...this.defaultArgs(e)),c.some(h=>h.startsWith("--remote-debugging-"))||(o&&ee(a===null,"Browser should be launched with either pipe or debugging port - not both."),c.push(`--remote-debugging-port=${a||0}`));let l,u=!0,d=c.findIndex(h=>["-profile","--profile"].includes(h));if(d!==-1){if(l=c[d+1],!l)throw new Error("Missing value for profile command line argument");u=!1}else{let h=await this.getProfilePath();l=await(0,sp.mkdtemp)(h),c.push("--profile"),c.push(l)}await J1(De.FIREFOX,{path:l,preferences:r.getPreferences(s)});let f;return this.puppeteer._isPuppeteerCore||n?(ee(n,"An `executablePath` must be specified for `puppeteer-core`"),f=n):f=await this.executablePath(void 0),{isTempUserDataDir:u,userDataDir:l,args:c,executablePath:f}}async cleanUserDataDir(e,t){if(t.isTemp)try{await eD(e)}catch(i){this.logger(H.error)?.(i)}else try{let i=".puppeteer",n=["prefs.js","user.js"],o=await Promise.allSettled(n.map(async s=>{let a=I3.default.join(e,s+i);if(uq.default.existsSync(a)){let c=I3.default.join(e,s);await(0,sp.unlink)(c),await(0,sp.rename)(a,c)}}));for(let s of o)if(s.status==="rejected")throw s.reason}catch(i){this.logger(H.error)?.(i)}}async executablePath(e,t=!0){return await this.resolveExecutablePath(void 0,t)}defaultArgs(e={}){let{devtools:t=!1,headless:i=!t,args:n=[],userDataDir:o=null}=e,s=[];switch(dq.default.platform()){case"darwin":s.push("--foreground");break;case"win32":s.push("--wait-for-browser");break}return o&&(s.push("--profile"),s.push(o)),i&&s.push("--headless"),t&&s.push("--devtools"),n.every(a=>a.startsWith("-"))&&s.push("about:blank"),s.push(...n),s}}});var nD,fq=b(()=>{dd();je();k3();An();A3();M3();L3();nD=class extends YS{#e;#t;configuration;constructor(e){let{configuration:t,...i}=e;super(i),t?this.configuration=t:this.configuration=()=>Promise.resolve({}),this.connect=this.connect.bind(this),this.launch=this.launch.bind(this),this.executablePath=this.executablePath.bind(this),this.defaultArgs=this.defaultArgs.bind(this),this.trimCache=this.trimCache.bind(this)}connect(e){return e.logger??=ta,super.connect(e)}async launch(e={}){e.logger??=ta;let{browser:t=await this.defaultBrowser()}=e;if(this.#t=t,!["chrome","firefox"].includes(t))throw new Error(`Unknown product: ${t}`);return this.#e=this.#r(t,e.logger),await this.#e.launch(e)}#r(e,t){if(this.#e&&this.#e.browser===e)return this.#e;switch(e){case"chrome":return new rD(this,t);case"firefox":return new iD(this,t);default:throw new Error(`Unknown product: ${e}`)}}async executablePath(e){return e===void 0?await this.#r(await this.lastLaunchedBrowser(),ta).executablePath(void 0,!1):typeof e=="string"?await this.#r("chrome",ta).executablePath(e,!1):await this.#r(e.browser??await this.lastLaunchedBrowser(),e.logger??ta).resolveExecutablePath(e.headless,!1)}async browserVersion(){let e=await this.configuration(),t=await this.lastLaunchedBrowser();return e?.[t]?.version??F3[t]}async defaultDownloadPath(){return(await this.configuration()).cacheDirectory}async lastLaunchedBrowser(){return this.#t??await this.defaultBrowser()}async defaultBrowser(){return(await this.configuration()).defaultBrowser??"chrome"}async defaultArgs(e={}){return this.#r(e.browser??await this.lastLaunchedBrowser(),e.logger??ta).defaultArgs(e)}async trimCache(){let e=Di();if(!e)throw new Error("The current platform is not supported.");let t=await this.configuration(),i=t.cacheDirectory,n=await bS({cacheDir:i}),o=[{product:"chrome",browser:De.CHROME,currentBuildId:""},{product:"firefox",browser:De.FIREFOX,currentBuildId:""}];await Promise.all(o.map(async c=>{let l=t?.[c.product]?.version??F3[c.product];c.currentBuildId=await zh(c.browser,e,l)}));let s=new Set(o.map(c=>`${c.browser}_${c.currentBuildId}`)),a=new Set(o.map(c=>c.browser));for(let c of n)a.has(c.browser)&&(s.has(`${c.browser}_${c.buildId}`)||await yS({browser:c.browser,platform:e,cacheDir:i,buildId:c.buildId}))}setFollowSymlinks(e){lt.value.followSymlinks=e}}});function Sre(r,e,t,i){let n=Math.round((t-r)*i),o=Math.round((e-r)*i);return Math.max(0,n-o)}var oD,mq,gq,wre,hq,xre,vre,pq,yq,bq=b(()=>{oD=require("node:child_process"),mq=Ae(require("node:os"),1),gq=require("node:stream");eo();Ii();je();Ot();pr();bt();wre=function(r,e,t){for(var i=arguments.length>2,n=0;n<e.length;n++)t=i?e[n].call(r,t):e[n].call(r);return i?t:void 0},hq=function(r,e,t,i,n,o){function s(y){if(y!==void 0&&typeof y!="function")throw new TypeError("Function expected");return y}for(var a=i.kind,c=a==="getter"?"get":a==="setter"?"set":"value",l=!e&&r?i.static?r:r.prototype:null,u=e||(l?Object.getOwnPropertyDescriptor(l,i.name):{}),d,f=!1,h=t.length-1;h>=0;h--){var p={};for(var m in i)p[m]=m==="access"?{}:i[m];for(var m in i.access)p.access[m]=i.access[m];p.addInitializer=function(y){if(f)throw new TypeError("Cannot add initializers after decoration has completed");o.push(s(y||null))};var g=(0,t[h])(a==="accessor"?{get:u.get,set:u.set}:u[c],p);if(a==="accessor"){if(g===void 0)continue;if(g===null||typeof g!="object")throw new TypeError("Object expected");(d=s(g.get))&&(u.get=d),(d=s(g.set))&&(u.set=d),(d=s(g.init))&&n.unshift(d)}else(d=s(g))&&(a==="field"?n.unshift(d):u[c]=d)}l&&Object.defineProperty(l,i.name,u),f=!0},xre=function(r,e,t){return typeof e=="symbol"&&(e=e.description?"[".concat(e.description,"]"):""),Object.defineProperty(r,"name",{configurable:!0,value:t?"".concat(t," ",e):e})},vre=30,pq=30;yq=(()=>{let r=gq.PassThrough,e=[],t,i,n;return class extends r{static{let s=typeof Symbol=="function"&&Symbol.metadata?Object.create(r[Symbol.metadata]??null):void 0;hq(this,i={value:xre(async function(a){let c=await new Promise(l=>{this.#t.stdin.write(a,l)});c&&console.log(`ffmpeg failed to write: ${c.message}.`)},"#writeFrame")},t,{kind:"method",name:"#writeFrame",static:!1,private:!0,access:{has:a=>#a in a,get:a=>a.#a},metadata:s},null,e),hq(this,null,n,{kind:"method",name:"stop",static:!1,private:!1,access:{has:a=>"stop"in a,get:a=>a.stop},metadata:s},null,e),s&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:s})}#e=wre(this,e);#t;#r=new AbortController;#i;#n;#s;constructor(s,a,c,{ffmpegPath:l,speed:u,scale:d,crop:f,format:h,fps:p,loop:m,delay:g,quality:y,colors:x}={},C){super({allowHalfOpen:!1}),this.#s=C,l??="ffmpeg",h??="webm",p??=pq,m||=-1,g??=-1,y??=vre,x??=256,this.#n=p;let{error:T}=(0,oD.spawnSync)(l);if(T)throw T;let B=[`crop='min(${a},iw):min(${c},ih):0:0'`,`pad=${a}:${c}:0:0`];u&&B.push(`setpts=${1/u}*PTS`),f&&B.push(`crop=${f.width}:${f.height}:${f.x}:${f.y}`),d&&B.push(`scale=iw*${d}:-1:flags=lanczos`);let M=this.#o(h,p,m,g,y,x),E=M.indexOf("-vf");E!==-1&&B.push(M.splice(E,2).at(-1)??""),this.#t=(0,oD.spawn)(l,[["-loglevel","error"],["-avioflags","direct"],["-fpsprobesize","0","-probesize","32","-analyzeduration","0","-fflags","nobuffer"],["-framerate",`${p}`,"-f","image2pipe","-vcodec","png","-i","pipe:0"],["-an"],["-threads","1"],["-b:v","0"],M,["-vf",B.join()],"pipe:1"].flat(),{stdio:["pipe","pipe","pipe"]}),this.#t.stdout.pipe(this),this.#t.stderr.on("data",k=>{this.#s?.(H.ffmpeg)?.(k.toString("utf8"))}),this.#e=s;let{client:D}=this.#e.mainFrame();D.once(mt.Disconnected,()=>{this.stop().catch(k=>{this.#s?.(H.error)?.(k)})});let O;this.#i=WL(xt(D,"Page.screencastFrame").pipe(Du(k=>{D.send("Page.screencastFrameAck",{sessionId:k.sessionId})}),Pn(k=>k.metadata.timestamp!==void 0),Wt(k=>({buffer:Buffer.from(k.data,"base64"),timestamp:k.metadata.timestamp})),GL(2,1),XL(([{timestamp:k,buffer:S},{timestamp:P}])=>(O??=k,Ye(Array(Sre(O,k,P,p)).fill(S)))),Wt(k=>(this.#a(k),[k,performance.now()])),fx(Pf(this.#r.signal,"abort"))),{defaultValue:[Buffer.from([]),performance.now()]})}#o(s,a,c,l,u,d){let f=[["-vcodec","vp9"],["-crf",`${u}`],["-deadline","realtime","-cpu-used",`${Math.min(mq.default.cpus().length/2,8)}`]];switch(s){case"webm":return[...f,["-f","webm"]].flat();case"gif":return a=pq===a?20:"source_fps",c===1/0&&(c=0),l!==-1&&(l/=10),[["-vf",`fps=${a},split[s0][s1];[s0]palettegen=stats_mode=diff:max_colors=${d}[p];[s1][p]paletteuse=dither=bayer`],["-loop",`${c}`],["-final_delay",`${l}`],["-f","gif"]].flat();case"mp4":return[...f,["-movflags","hybrid_fragmented"],["-f","mp4"]].flat()}}get#a(){return i.value}async stop(){if(this.#r.signal.aborted)return;await this.#e._stopScreencast().catch(c=>{this.#s?.(H.error)?.(c)}),this.#r.abort();let[s,a]=await this.#i;await Promise.all(Array(Math.max(1,Math.round(this.#n*(performance.now()-a)/1e3))).fill(s).map(this.#a.bind(this))),this.#t.stdin.end(),await new Promise(c=>{this.#t.once("close",c)})}async[(t=[oa()],n=[oa()],Et)](){await this.stop(),await super[Et]()}}})()});var wq=b(()=>{M3();L3();P3();$S();fq();bq();});var B3=b(()=>{CP();wq();});var xq,UUe,qUe,WUe,zUe,uy,N3=b(()=>{pL();B3();An();B3();lt.value.ScreenRecorder=yq;xq=new nD({isPuppeteerCore:!0}),{connect:UUe,defaultArgs:qUe,executablePath:WUe,launch:zUe}=xq,uy=xq});function vq(r,e){let t=(0,mo.readFileSync)(r),i=a=>new Error(`${r}: ${a}`),n=-1;for(let a=t.length-22;a>=Math.max(0,t.length-22-65535);a--)if(t.readUInt32LE(a)===Ere){n=a;break}if(n<0)throw i("not a zip file");let o=t.readUInt16LE(n+10),s=t.readUInt32LE(n+16);if((o===65535||s===sD)&&n>=20&&t.readUInt32LE(n-20)===Cre){let a=Number(t.readBigUInt64LE(n-12));if(t.readUInt32LE(a)!==kre)throw i("bad Zip64 record");o=Number(t.readBigUInt64LE(a+32)),s=Number(t.readBigUInt64LE(a+48))}(0,mo.mkdirSync)(e,{recursive:!0});for(let a=0,c=s;a<o;a++){if(t.readUInt32LE(c)!==Fre)throw i("bad central directory");let l=t.readUInt16LE(c+4),u=t.readUInt16LE(c+10),d=t.readUInt32LE(c+16),f=t.readUInt32LE(c+20),h=t.readUInt32LE(c+24),p=t.readUInt16LE(c+28),m=t.readUInt16LE(c+30),g=t.readUInt16LE(c+32),y=t.readUInt32LE(c+38),x=t.readUInt32LE(c+42),C=t.toString("utf8",c+46,c+46+p);for(let S=c+46+p;S<c+46+p+m;S+=4+t.readUInt16LE(S+2)){if(t.readUInt16LE(S)!==1)continue;let P=S+4,I=()=>Number(t.readBigUInt64LE((P+=8)-8));h===sD&&(h=I()),f===sD&&(f=I()),x===sD&&(x=I())}c+=46+p+m+g;let T=(0,Ss.normalize)(C);if((0,Ss.isAbsolute)(T)||T.split(/[\\/]/).includes(".."))throw i(`entry outside the archive: ${C}`);let B=(0,Ss.join)(e,T),M=l>>8===3?y>>>16:0,E=M&61440;if(C.endsWith("/")||E===16384){(0,mo.mkdirSync)(B,{recursive:!0});continue}if(t.readUInt32LE(x)!==Are)throw i(`bad local header: ${C}`);let D=x+30+t.readUInt16LE(x+26)+t.readUInt16LE(x+28),O=t.subarray(D,D+f),k=u===0?O:u===8?(0,aD.inflateRawSync)(O):null;if(!k)throw i(`compression method ${u}: ${C}`);if(k.length!==h||(0,aD.crc32)(k)!==d)throw i(`corrupt entry: ${C}`);if((0,mo.mkdirSync)((0,Ss.dirname)(B),{recursive:!0}),E===40960){(0,mo.symlinkSync)(k.toString("utf8"),B);continue}(0,mo.writeFileSync)(B,k),M&511&&Ss.sep==="/"&&(0,mo.chmodSync)(B,M&511)}}var mo,Ss,aD,Ere,Cre,kre,Fre,Are,sD,Sq=b(()=>{"use strict";mo=require("node:fs"),Ss=require("node:path"),aD=require("node:zlib"),Ere=101010256,Cre=117853008,kre=101075792,Fre=33639248,Are=67324752,sD=4294967295});var jo,go,ap=b(()=>{"use strict";jo="1.0.2",go="156.0.8078.47"});function Pre(){return JSON.parse((0,Ei.readFileSync)((0,vr.join)(Fq,"chromium.json"),"utf8"))}function U3(){let{platform:r,arch:e}=process;if(r==="linux"&&e==="x64")return"linux64";if(r==="linux"&&e==="arm64")return"linux-arm64";if(r==="darwin")return e==="arm64"?"mac-arm64":"mac-x64";if(r==="win32")return e==="ia32"?"win32":"win64";throw new Error(`No chrome-headless-shell build for ${r}-${e}`)}function Tre(r=go){return(0,vr.join)(Fq,".cache","chromium",r)}function j3(){try{return typeof require=="function"&&require("node:sea").isSea()}catch{return!1}}function lD(){return process.env.PDFKILN_CACHE_DIR?process.env.PDFKILN_CACHE_DIR:process.platform==="win32"?(0,vr.join)(process.env.LOCALAPPDATA??(0,vr.join)((0,cD.homedir)(),"AppData","Local"),"pdfkiln"):process.platform==="darwin"?(0,vr.join)((0,cD.homedir)(),"Library","Caches","pdfkiln"):(0,vr.join)(process.env.XDG_CACHE_HOME||(0,vr.join)((0,cD.homedir)(),".cache"),"pdfkiln")}function Rre(){if(process.env.PDFKILN_CHROMIUM)return process.env.PDFKILN_CHROMIUM;let r=(0,vr.join)(j3()?(0,vr.dirname)(process.execPath):kq,"chromium",_3()),e=(0,vr.join)(Tre(),`chrome-headless-shell-${U3()}`,_3());for(let i of[r,e])if((0,Ei.existsSync)(i))return i;let t=Ore();return(0,Ei.existsSync)(t)||!j3()?t:r}async function uD(){let r=Rre();if((0,Ei.existsSync)(r)||process.env.PDFKILN_CHROMIUM||j3())return r;let e=Pre(),t=U3(),i=e.archives[t];if(!i)throw new Error(`chromium.json has no archive for ${t}`);let n=`${e.source}/${e.version}/${t}/${i.file}`,o=(0,vr.join)(lD(),"chromium",e.version);process.stderr.write(`pdfkiln: first use, downloading Chromium ${e.version} (${Math.round(i.size/1e6)} MB) into ${o}
|
|
229
|
+
`)),await super.launch(e)}async computeLaunchArguments(e={}){let{ignoreDefaultArgs:t=!1,args:i=[],pipe:n=!1,debuggingPort:o,channel:s,executablePath:a}=e,c=[];t?Array.isArray(t)?c.push(...this.defaultArgs(e).filter(h=>!t.includes(h))):c.push(...i):c.push(...this.defaultArgs(e)),c.some(h=>h.startsWith("--remote-debugging-"))||(n?(ee(!o,"Browser should be launched with either pipe or debugging port - not both."),c.push("--remote-debugging-pipe")):c.push(`--remote-debugging-port=${o||0}`));let l=!1,u=c.findIndex(h=>h.startsWith("--user-data-dir")),d;if(u<0){l=!0;let h=await this.getProfilePath();d=await(0,cq.mkdtemp)(h),c.push(`--user-data-dir=${d}`)}else{let h=c[u].split("=",2)[1];ee(typeof h=="string","`--user-data-dir` is malformed"),d=h}let f=a;return f||(ee(s||!this.puppeteer._isPuppeteerCore,"An `executablePath` or `channel` must be specified for `puppeteer-core`"),f=s?await this.executablePath(s):await this.resolveExecutablePath(e.headless??!0)),{executablePath:f,args:c,isTempUserDataDir:l,userDataDir:d}}async cleanUserDataDir(e,t){if(t.isTemp)try{await eD(e)}catch(i){this.logger(H.error)?.(i)}}defaultArgs(e={}){let t=sq("--disable-features",e.args);e.args&&t.length>0&&aq(e.args,"--disable-features");let i=process.env.PUPPETEER_TEST_EXPERIMENTAL_CHROME_FEATURES==="true",n=sq("--enable-features",e.args);e.args&&n.length>0&&aq(e.args,"--enable-features");let o=["PdfOopif",...n].filter(h=>h!==""),a=["--allow-pre-commit-input","--disable-background-networking","--disable-background-timer-throttling","--disable-backgrounding-occluded-windows","--disable-breakpad","--disable-client-side-phishing-detection","--disable-component-extensions-with-background-pages","--disable-crash-reporter","--disable-default-apps","--disable-dev-shm-usage","--disable-hang-monitor","--disable-infobars","--disable-ipc-flooding-protection","--disable-popup-blocking","--disable-prompt-on-repost","--disable-renderer-backgrounding","--disable-search-engine-choice-screen","--disable-sync","--enable-automation","--export-tagged-pdf","--force-color-profile=srgb","--generate-pdf-document-outline","--metrics-recording-only","--no-first-run","--password-store=basic","--use-mock-keychain",`--disable-features=${["Translate","AcceptCHFrame","MediaRouter","OptimizationHints","WebUIReloadButton","WebUIOmniboxPopup","WebUIOmniboxAimPopup",...i?[]:["ProcessPerSiteUpToMainFrameThreshold","IsolateSandboxedIframes"],...t].filter(h=>h!=="").filter(h=>!o.includes(h)).join(",")}`,`--enable-features=${o.join(",")}`].filter(h=>h!==""),{devtools:c=!1,headless:l=!c,args:u=[],userDataDir:d,enableExtensions:f=!1}=e;return process.env.PUPPETEER_DANGEROUS_NO_SANDBOX==="true"&&!u.includes("--no-sandbox")&&a.push("--no-sandbox"),d&&a.push(`--user-data-dir=${tD.default.posix.isAbsolute(d)||tD.default.win32.isAbsolute(d)?d:tD.default.resolve(d)}`),c&&a.push("--auto-open-devtools-for-tabs"),l&&a.push(l==="shell"?"--headless":"--headless=new","--hide-scrollbars","--mute-audio"),f||a.push("--disable-extensions"),u.every(h=>h.startsWith("-"))&&a.push("about:blank"),a.push(...u),a}async executablePath(e,t=!0){return e?Vh({browser:De.CHROME,channel:D3(e)},t):await this.resolveExecutablePath(void 0,t)}}});var uq,sp,dq,I3,iD,L3=b(()=>{uq=Ae(require("node:fs"),1),sp=require("node:fs/promises"),dq=Ae(require("node:os"),1),I3=Ae(require("node:path"),1);dd();je();Ct();$S();R3();iD=class r extends op{constructor(e,t){super(e,"firefox",t)}static getPreferences(e){return{...e,"fission.webContentIsolationStrategy":0}}async computeLaunchArguments(e={}){let{ignoreDefaultArgs:t=!1,args:i=[],executablePath:n,pipe:o=!1,extraPrefsFirefox:s={},debuggingPort:a=null}=e,c=[];t?Array.isArray(t)?c.push(...this.defaultArgs(e).filter(h=>!t.includes(h))):c.push(...i):c.push(...this.defaultArgs(e)),c.some(h=>h.startsWith("--remote-debugging-"))||(o&&ee(a===null,"Browser should be launched with either pipe or debugging port - not both."),c.push(`--remote-debugging-port=${a||0}`));let l,u=!0,d=c.findIndex(h=>["-profile","--profile"].includes(h));if(d!==-1){if(l=c[d+1],!l)throw new Error("Missing value for profile command line argument");u=!1}else{let h=await this.getProfilePath();l=await(0,sp.mkdtemp)(h),c.push("--profile"),c.push(l)}await J1(De.FIREFOX,{path:l,preferences:r.getPreferences(s)});let f;return this.puppeteer._isPuppeteerCore||n?(ee(n,"An `executablePath` must be specified for `puppeteer-core`"),f=n):f=await this.executablePath(void 0),{isTempUserDataDir:u,userDataDir:l,args:c,executablePath:f}}async cleanUserDataDir(e,t){if(t.isTemp)try{await eD(e)}catch(i){this.logger(H.error)?.(i)}else try{let i=".puppeteer",n=["prefs.js","user.js"],o=await Promise.allSettled(n.map(async s=>{let a=I3.default.join(e,s+i);if(uq.default.existsSync(a)){let c=I3.default.join(e,s);await(0,sp.unlink)(c),await(0,sp.rename)(a,c)}}));for(let s of o)if(s.status==="rejected")throw s.reason}catch(i){this.logger(H.error)?.(i)}}async executablePath(e,t=!0){return await this.resolveExecutablePath(void 0,t)}defaultArgs(e={}){let{devtools:t=!1,headless:i=!t,args:n=[],userDataDir:o=null}=e,s=[];switch(dq.default.platform()){case"darwin":s.push("--foreground");break;case"win32":s.push("--wait-for-browser");break}return o&&(s.push("--profile"),s.push(o)),i&&s.push("--headless"),t&&s.push("--devtools"),n.every(a=>a.startsWith("-"))&&s.push("about:blank"),s.push(...n),s}}});var nD,fq=b(()=>{dd();je();k3();An();A3();M3();L3();nD=class extends YS{#e;#t;configuration;constructor(e){let{configuration:t,...i}=e;super(i),t?this.configuration=t:this.configuration=()=>Promise.resolve({}),this.connect=this.connect.bind(this),this.launch=this.launch.bind(this),this.executablePath=this.executablePath.bind(this),this.defaultArgs=this.defaultArgs.bind(this),this.trimCache=this.trimCache.bind(this)}connect(e){return e.logger??=ta,super.connect(e)}async launch(e={}){e.logger??=ta;let{browser:t=await this.defaultBrowser()}=e;if(this.#t=t,!["chrome","firefox"].includes(t))throw new Error(`Unknown product: ${t}`);return this.#e=this.#r(t,e.logger),await this.#e.launch(e)}#r(e,t){if(this.#e&&this.#e.browser===e)return this.#e;switch(e){case"chrome":return new rD(this,t);case"firefox":return new iD(this,t);default:throw new Error(`Unknown product: ${e}`)}}async executablePath(e){return e===void 0?await this.#r(await this.lastLaunchedBrowser(),ta).executablePath(void 0,!1):typeof e=="string"?await this.#r("chrome",ta).executablePath(e,!1):await this.#r(e.browser??await this.lastLaunchedBrowser(),e.logger??ta).resolveExecutablePath(e.headless,!1)}async browserVersion(){let e=await this.configuration(),t=await this.lastLaunchedBrowser();return e?.[t]?.version??F3[t]}async defaultDownloadPath(){return(await this.configuration()).cacheDirectory}async lastLaunchedBrowser(){return this.#t??await this.defaultBrowser()}async defaultBrowser(){return(await this.configuration()).defaultBrowser??"chrome"}async defaultArgs(e={}){return this.#r(e.browser??await this.lastLaunchedBrowser(),e.logger??ta).defaultArgs(e)}async trimCache(){let e=Di();if(!e)throw new Error("The current platform is not supported.");let t=await this.configuration(),i=t.cacheDirectory,n=await bS({cacheDir:i}),o=[{product:"chrome",browser:De.CHROME,currentBuildId:""},{product:"firefox",browser:De.FIREFOX,currentBuildId:""}];await Promise.all(o.map(async c=>{let l=t?.[c.product]?.version??F3[c.product];c.currentBuildId=await zh(c.browser,e,l)}));let s=new Set(o.map(c=>`${c.browser}_${c.currentBuildId}`)),a=new Set(o.map(c=>c.browser));for(let c of n)a.has(c.browser)&&(s.has(`${c.browser}_${c.buildId}`)||await yS({browser:c.browser,platform:e,cacheDir:i,buildId:c.buildId}))}setFollowSymlinks(e){lt.value.followSymlinks=e}}});function Sre(r,e,t,i){let n=Math.round((t-r)*i),o=Math.round((e-r)*i);return Math.max(0,n-o)}var oD,mq,gq,wre,hq,xre,vre,pq,yq,bq=b(()=>{oD=require("node:child_process"),mq=Ae(require("node:os"),1),gq=require("node:stream");eo();Ii();je();Ot();pr();bt();wre=function(r,e,t){for(var i=arguments.length>2,n=0;n<e.length;n++)t=i?e[n].call(r,t):e[n].call(r);return i?t:void 0},hq=function(r,e,t,i,n,o){function s(y){if(y!==void 0&&typeof y!="function")throw new TypeError("Function expected");return y}for(var a=i.kind,c=a==="getter"?"get":a==="setter"?"set":"value",l=!e&&r?i.static?r:r.prototype:null,u=e||(l?Object.getOwnPropertyDescriptor(l,i.name):{}),d,f=!1,h=t.length-1;h>=0;h--){var p={};for(var m in i)p[m]=m==="access"?{}:i[m];for(var m in i.access)p.access[m]=i.access[m];p.addInitializer=function(y){if(f)throw new TypeError("Cannot add initializers after decoration has completed");o.push(s(y||null))};var g=(0,t[h])(a==="accessor"?{get:u.get,set:u.set}:u[c],p);if(a==="accessor"){if(g===void 0)continue;if(g===null||typeof g!="object")throw new TypeError("Object expected");(d=s(g.get))&&(u.get=d),(d=s(g.set))&&(u.set=d),(d=s(g.init))&&n.unshift(d)}else(d=s(g))&&(a==="field"?n.unshift(d):u[c]=d)}l&&Object.defineProperty(l,i.name,u),f=!0},xre=function(r,e,t){return typeof e=="symbol"&&(e=e.description?"[".concat(e.description,"]"):""),Object.defineProperty(r,"name",{configurable:!0,value:t?"".concat(t," ",e):e})},vre=30,pq=30;yq=(()=>{let r=gq.PassThrough,e=[],t,i,n;return class extends r{static{let s=typeof Symbol=="function"&&Symbol.metadata?Object.create(r[Symbol.metadata]??null):void 0;hq(this,i={value:xre(async function(a){let c=await new Promise(l=>{this.#t.stdin.write(a,l)});c&&console.log(`ffmpeg failed to write: ${c.message}.`)},"#writeFrame")},t,{kind:"method",name:"#writeFrame",static:!1,private:!0,access:{has:a=>#a in a,get:a=>a.#a},metadata:s},null,e),hq(this,null,n,{kind:"method",name:"stop",static:!1,private:!1,access:{has:a=>"stop"in a,get:a=>a.stop},metadata:s},null,e),s&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:s})}#e=wre(this,e);#t;#r=new AbortController;#i;#n;#s;constructor(s,a,c,{ffmpegPath:l,speed:u,scale:d,crop:f,format:h,fps:p,loop:m,delay:g,quality:y,colors:x}={},C){super({allowHalfOpen:!1}),this.#s=C,l??="ffmpeg",h??="webm",p??=pq,m||=-1,g??=-1,y??=vre,x??=256,this.#n=p;let{error:T}=(0,oD.spawnSync)(l);if(T)throw T;let B=[`crop='min(${a},iw):min(${c},ih):0:0'`,`pad=${a}:${c}:0:0`];u&&B.push(`setpts=${1/u}*PTS`),f&&B.push(`crop=${f.width}:${f.height}:${f.x}:${f.y}`),d&&B.push(`scale=iw*${d}:-1:flags=lanczos`);let M=this.#o(h,p,m,g,y,x),E=M.indexOf("-vf");E!==-1&&B.push(M.splice(E,2).at(-1)??""),this.#t=(0,oD.spawn)(l,[["-loglevel","error"],["-avioflags","direct"],["-fpsprobesize","0","-probesize","32","-analyzeduration","0","-fflags","nobuffer"],["-framerate",`${p}`,"-f","image2pipe","-vcodec","png","-i","pipe:0"],["-an"],["-threads","1"],["-b:v","0"],M,["-vf",B.join()],"pipe:1"].flat(),{stdio:["pipe","pipe","pipe"]}),this.#t.stdout.pipe(this),this.#t.stderr.on("data",k=>{this.#s?.(H.ffmpeg)?.(k.toString("utf8"))}),this.#e=s;let{client:D}=this.#e.mainFrame();D.once(mt.Disconnected,()=>{this.stop().catch(k=>{this.#s?.(H.error)?.(k)})});let O;this.#i=WL(xt(D,"Page.screencastFrame").pipe(Du(k=>{D.send("Page.screencastFrameAck",{sessionId:k.sessionId})}),Pn(k=>k.metadata.timestamp!==void 0),Wt(k=>({buffer:Buffer.from(k.data,"base64"),timestamp:k.metadata.timestamp})),GL(2,1),XL(([{timestamp:k,buffer:S},{timestamp:P}])=>(O??=k,Ye(Array(Sre(O,k,P,p)).fill(S)))),Wt(k=>(this.#a(k),[k,performance.now()])),fx(Pf(this.#r.signal,"abort"))),{defaultValue:[Buffer.from([]),performance.now()]})}#o(s,a,c,l,u,d){let f=[["-vcodec","vp9"],["-crf",`${u}`],["-deadline","realtime","-cpu-used",`${Math.min(mq.default.cpus().length/2,8)}`]];switch(s){case"webm":return[...f,["-f","webm"]].flat();case"gif":return a=pq===a?20:"source_fps",c===1/0&&(c=0),l!==-1&&(l/=10),[["-vf",`fps=${a},split[s0][s1];[s0]palettegen=stats_mode=diff:max_colors=${d}[p];[s1][p]paletteuse=dither=bayer`],["-loop",`${c}`],["-final_delay",`${l}`],["-f","gif"]].flat();case"mp4":return[...f,["-movflags","hybrid_fragmented"],["-f","mp4"]].flat()}}get#a(){return i.value}async stop(){if(this.#r.signal.aborted)return;await this.#e._stopScreencast().catch(c=>{this.#s?.(H.error)?.(c)}),this.#r.abort();let[s,a]=await this.#i;await Promise.all(Array(Math.max(1,Math.round(this.#n*(performance.now()-a)/1e3))).fill(s).map(this.#a.bind(this))),this.#t.stdin.end(),await new Promise(c=>{this.#t.once("close",c)})}async[(t=[oa()],n=[oa()],Et)](){await this.stop(),await super[Et]()}}})()});var wq=b(()=>{M3();L3();P3();$S();fq();bq();});var B3=b(()=>{CP();wq();});var xq,UUe,qUe,WUe,zUe,uy,N3=b(()=>{pL();B3();An();B3();lt.value.ScreenRecorder=yq;xq=new nD({isPuppeteerCore:!0}),{connect:UUe,defaultArgs:qUe,executablePath:WUe,launch:zUe}=xq,uy=xq});function vq(r,e){let t=(0,mo.readFileSync)(r),i=a=>new Error(`${r}: ${a}`),n=-1;for(let a=t.length-22;a>=Math.max(0,t.length-22-65535);a--)if(t.readUInt32LE(a)===Ere){n=a;break}if(n<0)throw i("not a zip file");let o=t.readUInt16LE(n+10),s=t.readUInt32LE(n+16);if((o===65535||s===sD)&&n>=20&&t.readUInt32LE(n-20)===Cre){let a=Number(t.readBigUInt64LE(n-12));if(t.readUInt32LE(a)!==kre)throw i("bad Zip64 record");o=Number(t.readBigUInt64LE(a+32)),s=Number(t.readBigUInt64LE(a+48))}(0,mo.mkdirSync)(e,{recursive:!0});for(let a=0,c=s;a<o;a++){if(t.readUInt32LE(c)!==Fre)throw i("bad central directory");let l=t.readUInt16LE(c+4),u=t.readUInt16LE(c+10),d=t.readUInt32LE(c+16),f=t.readUInt32LE(c+20),h=t.readUInt32LE(c+24),p=t.readUInt16LE(c+28),m=t.readUInt16LE(c+30),g=t.readUInt16LE(c+32),y=t.readUInt32LE(c+38),x=t.readUInt32LE(c+42),C=t.toString("utf8",c+46,c+46+p);for(let S=c+46+p;S<c+46+p+m;S+=4+t.readUInt16LE(S+2)){if(t.readUInt16LE(S)!==1)continue;let P=S+4,I=()=>Number(t.readBigUInt64LE((P+=8)-8));h===sD&&(h=I()),f===sD&&(f=I()),x===sD&&(x=I())}c+=46+p+m+g;let T=(0,Ss.normalize)(C);if((0,Ss.isAbsolute)(T)||T.split(/[\\/]/).includes(".."))throw i(`entry outside the archive: ${C}`);let B=(0,Ss.join)(e,T),M=l>>8===3?y>>>16:0,E=M&61440;if(C.endsWith("/")||E===16384){(0,mo.mkdirSync)(B,{recursive:!0});continue}if(t.readUInt32LE(x)!==Are)throw i(`bad local header: ${C}`);let D=x+30+t.readUInt16LE(x+26)+t.readUInt16LE(x+28),O=t.subarray(D,D+f),k=u===0?O:u===8?(0,aD.inflateRawSync)(O):null;if(!k)throw i(`compression method ${u}: ${C}`);if(k.length!==h||(0,aD.crc32)(k)!==d)throw i(`corrupt entry: ${C}`);if((0,mo.mkdirSync)((0,Ss.dirname)(B),{recursive:!0}),E===40960){(0,mo.symlinkSync)(k.toString("utf8"),B);continue}(0,mo.writeFileSync)(B,k),M&511&&Ss.sep==="/"&&(0,mo.chmodSync)(B,M&511)}}var mo,Ss,aD,Ere,Cre,kre,Fre,Are,sD,Sq=b(()=>{"use strict";mo=require("node:fs"),Ss=require("node:path"),aD=require("node:zlib"),Ere=101010256,Cre=117853008,kre=101075792,Fre=33639248,Are=67324752,sD=4294967295});var jo,go,ap=b(()=>{"use strict";jo="1.0.3",go="156.0.8078.73"});function Pre(){return JSON.parse((0,Ei.readFileSync)((0,vr.join)(Fq,"chromium.json"),"utf8"))}function U3(){let{platform:r,arch:e}=process;if(r==="linux"&&e==="x64")return"linux64";if(r==="linux"&&e==="arm64")return"linux-arm64";if(r==="darwin")return e==="arm64"?"mac-arm64":"mac-x64";if(r==="win32")return e==="ia32"?"win32":"win64";throw new Error(`No chrome-headless-shell build for ${r}-${e}`)}function Tre(r=go){return(0,vr.join)(Fq,".cache","chromium",r)}function j3(){try{return typeof require=="function"&&require("node:sea").isSea()}catch{return!1}}function lD(){return process.env.PDFKILN_CACHE_DIR?process.env.PDFKILN_CACHE_DIR:process.platform==="win32"?(0,vr.join)(process.env.LOCALAPPDATA??(0,vr.join)((0,cD.homedir)(),"AppData","Local"),"pdfkiln"):process.platform==="darwin"?(0,vr.join)((0,cD.homedir)(),"Library","Caches","pdfkiln"):(0,vr.join)(process.env.XDG_CACHE_HOME||(0,vr.join)((0,cD.homedir)(),".cache"),"pdfkiln")}function Rre(){if(process.env.PDFKILN_CHROMIUM)return process.env.PDFKILN_CHROMIUM;let r=(0,vr.join)(j3()?(0,vr.dirname)(process.execPath):kq,"chromium",_3()),e=(0,vr.join)(Tre(),`chrome-headless-shell-${U3()}`,_3());for(let i of[r,e])if((0,Ei.existsSync)(i))return i;let t=Ore();return(0,Ei.existsSync)(t)||!j3()?t:r}async function uD(){let r=Rre();if((0,Ei.existsSync)(r)||process.env.PDFKILN_CHROMIUM||j3())return r;let e=Pre(),t=U3(),i=e.archives[t];if(!i)throw new Error(`chromium.json has no archive for ${t}`);let n=`${e.source}/${e.version}/${t}/${i.file}`,o=(0,vr.join)(lD(),"chromium",e.version);process.stderr.write(`pdfkiln: first use, downloading Chromium ${e.version} (${Math.round(i.size/1e6)} MB) into ${o}
|
|
230
230
|
`),(0,Ei.mkdirSync)((0,vr.dirname)(o),{recursive:!0});let s=(0,Ei.mkdtempSync)((0,vr.join)((0,vr.dirname)(o),".download-"));try{let a=await fetch(n);if(!a.ok||!a.body)throw new Error(`${n}: HTTP ${a.status}`);let c=(0,vr.join)(s,i.file),l=(0,Dq.createHash)("sha256"),u=(0,Ei.createWriteStream)(c);for await(let f of Eq.Readable.fromWeb(a.body))l.update(f),u.write(f)||await new Promise(h=>u.once("drain",()=>h()));u.end(),await(0,Cq.finished)(u);let d=l.digest("hex");if(d!==i.sha256)throw new Error(`${n}: SHA-256 mismatch, expected ${i.sha256}, got ${d}`);vq(c,(0,vr.join)(s,"chromium"));try{(0,Ei.renameSync)((0,vr.join)(s,"chromium"),o)}catch(f){if(!(0,Ei.existsSync)(r))throw f}}finally{(0,Ei.rmSync)(s,{recursive:!0,force:!0})}return r}var Dq,Ei,cD,vr,Eq,Cq,Mre,kq,Fq,_3,Ore,q3=b(()=>{"use strict";Dq=require("node:crypto"),Ei=require("node:fs"),cD=require("node:os"),vr=require("node:path"),Eq=require("node:stream"),Cq=require("node:stream/promises");Sq();ap();Mre={},kq=typeof __dirname=="string"?__dirname:Mre.dirname,Fq=(0,vr.resolve)(kq,"..","..");_3=()=>process.platform==="win32"?"chrome-headless-shell.exe":"chrome-headless-shell";Ore=()=>(0,vr.join)(lD(),"chromium",go,`chrome-headless-shell-${U3()}`,_3())});function W3(r){return/as root without --no-sandbox/i.test(r)?"Chromium refuses to run as root with its sandbox on. Run the command as an unprivileged user (or pass --kiln-no-sandbox, not recommended).":/No usable sandbox|namespace|setuid sandbox|zygote/i.test(r)?"Chromium's sandbox could not start: unprivileged user namespaces are unavailable. On Ubuntu 23.10 and later, AppArmor restricts them: install an AppArmor profile for Chromium that allows userns (see the README), or enable kernel.unprivileged_userns_clone. --kiln-no-sandbox works around it, not recommended.":`Chromium did not start: ${r.split(`
|
|
231
231
|
`)[0]}`}function yo(r){try{(0,fy.rmSync)(r,{recursive:!0,force:!0,maxRetries:5,retryDelay:100})}catch{}}function dy(r){if(r)try{process.platform==="win32"?(0,Aq.execFileSync)("taskkill",["/pid",String(r),"/T","/F"],{stdio:"ignore"}):process.kill(-r,"SIGKILL")}catch{}}async function dD(r,e=1e4){let t=Date.now()+e;for(;;)try{(0,fy.rmSync)(r,{recursive:!0,force:!0});return}catch{if(Date.now()>t)return;await new Promise(i=>setTimeout(i,200))}}async function fD(r){let e;try{e=await uD()}catch(c){throw new Ki(`Chromium could not be downloaded: ${c instanceof Error?c.message:String(c)}`)}if(!(0,fy.existsSync)(e))throw new Ki(`Chromium is missing: ${e}`);let t=(0,Pq.join)(r.dir,"chromium"),i=[`--user-data-dir=${t}`,"--force-webrtc-ip-handling-policy=disable_non_proxied_udp","--webrtc-ip-handling-policy=disable_non_proxied_udp"];r.noSandbox&&i.push("--no-sandbox"),r.proxyServer&&i.push(`--proxy-server=${r.proxyServer}`),r.proxyBypassList&&i.push(`--proxy-bypass-list=${r.proxyBypassList}`);let n;try{n=await uy.launch({executablePath:e,headless:"shell",pipe:!0,args:i,env:{...process.env,...r.env},defaultViewport:null,handleSIGINT:!1,handleSIGTERM:!1,handleSIGHUP:!1,protocolTimeout:0})}catch(c){throw yo(t),new Ki(W3(c instanceof Error?c.message:String(c)))}let o=n.process()?.pid,s=!1,a={browser:n,profile:t,async close(){if(a.stopping)return a.stopping;s||(s=!0,process.platform==="win32"?(await Promise.race([n.close().catch(()=>{}),new Promise(c=>setTimeout(c,5e3))]),n.process()?.exitCode===null&&dy(o),await dD(t)):(n.disconnect().catch(()=>{}),dy(o),yo(t)))}};return a}function hD(r,e,t){if(!e)return()=>{};let i=setTimeout(()=>{dy(r.browser.process()?.pid),r.stopping=dD(r.profile).then(t)},e*1e3);return i.unref(),()=>clearTimeout(i)}var Aq,fy,Pq,Ki,Zc=b(()=>{"use strict";Aq=require("node:child_process"),fy=require("node:fs"),Pq=require("node:path");N3();q3();Ki=class extends Error{}});function cp(r){switch(r){case 401:return 204;case 403:return 202;case 404:return 203;case 405:return 202;case 407:return 105;case 418:return 302;default:return r>500?301:r>=400?299:399}}function Tq(r){let e=r.replace(/^net::/,"");return e==="ERR_NAME_NOT_RESOLVED"||e==="ERR_NAME_RESOLUTION_FAILED"||e==="ERR_ADDRESS_INVALID"?3:e==="ERR_CONNECTION_REFUSED"?1:e==="ERR_CONNECTION_CLOSED"||e==="ERR_CONNECTION_RESET"||e==="ERR_EMPTY_RESPONSE"?2:e==="ERR_TIMED_OUT"||e==="ERR_CONNECTION_TIMED_OUT"?4:e==="ERR_ABORTED"?5:e.startsWith("ERR_SSL")||e.startsWith("ERR_CERT")?6:e==="ERR_INTERNET_DISCONNECTED"||e==="ERR_NETWORK_CHANGED"?7:e==="ERR_PROXY_CONNECTION_FAILED"?101:e==="ERR_TUNNEL_CONNECTION_FAILED"?102:e==="ERR_FILE_NOT_FOUND"?203:e==="ERR_ACCESS_DENIED"||e==="ERR_BLOCKED_BY_CLIENT"?201:e==="ERR_UNKNOWN_URL_SCHEME"||e==="ERR_DISALLOWED_URL_SCHEME"?301:99}function fd(r,e,t,i){let n=(()=>{try{return new URL(e).hostname}catch{return""}})();switch(r){case 1:return"Connection refused";case 2:return"Connection closed";case 3:return`Host ${n} not found`;case 4:return"Socket operation timed out";case 6:return"SSL handshake failed";case 204:return"Host requires authentication";case 301:return`Protocol "${e.split(":")[0]??""}" is unknown`;default:return t?`Error downloading ${e} - server replied: ${i}`:"Unknown error"}}function Oq(r,e){if(e){let t=e===404?2:e===401?3:1;return e<1e3?{code:t,line:`Exit with code ${t} due to http error: ${e} ${Lre[e]??""}`}:{code:t,line:`Exit with code ${t} due to network error: ${Ire[e-1e3]??""}`}}return r?{code:0}:{code:1,line:"Exit with code 1, due to unknown error."}}var Ire,Lre,z3=b(()=>{"use strict";Ire={0:"NoError",1:"ConnectionRefusedError",2:"RemoteHostClosedError",3:"HostNotFoundError",4:"TimeoutError",5:"OperationCanceledError",6:"SslHandshakeFailedError",7:"TemporaryNetworkFailureError",99:"UnknownNetworkError",101:"ProxyConnectionRefusedError",102:"ProxyConnectionClosedError",103:"ProxyNotFoundError",104:"ProxyTimeoutError",105:"ProxyAuthenticationRequiredError",199:"UnknownProxyError",201:"ContentAccessDenied",202:"ContentOperationNotPermittedError",203:"ContentNotFoundError",204:"AuthenticationRequiredError",205:"ContentReSendError",299:"UnknownContentError",301:"ProtocolUnknownError",302:"ProtocolInvalidOperationError",399:"ProtocolFailure"};Lre={400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Page not found",405:"Method Not Allowed",500:"Internal Server Error",501:"Not Implemented",503:"Service Unavailable",505:"HTTP Version Not Supported"}});function Nre(r){return r.replace(/(^|[\s,(])screen(?=$|[\s,)])/gi,"$1all").replace(/(^|[\s,(])print(?=$|[\s,)])/gi,`$1all and ${Rq}`)}function _re(r,e,t){return r.replace(/\(\s*(min-|max-)?(width|height)\s*:\s*(-?[0-9.]+)\s*(px|em|rem)?\s*\)/gi,(i,n,o,s,a)=>{let c=Number(s)*(a&&a.toLowerCase()!=="px"?16:1),l=o.toLowerCase()==="width"?e:t,u=(n??"").toLowerCase();return(u==="min-"?l>=c:u==="max-"?l<=c:l===c)?Bre:Rq})}function jre(r){let e="",t=0,i=/@page\b[^{;]*\{/gi;for(let n=i.exec(r);n;n=i.exec(r)){e+=r.slice(t,n.index);let o=1,s=n.index+n[0].length;for(;s<r.length&&o>0;s++)r[s]==="{"?o++:r[s]==="}"&&o--;t=s,i.lastIndex=s}return e+r.slice(t)}function Wre(r){return r.replace(Ure,"").replace(qre,"")}function pD(r,e){let t=e.webkit534Css?Wre(r):r;if(e.mediaViewport||e.screenTypes){let[i,n]=e.mediaViewport??[0,0];t=t.replace(/@media([^{;]+)\{/g,(o,s)=>{let a=e.mediaViewport?_re(s,i,n):s;return e.screenTypes&&(a=Nre(a)),`@media${a}{`})}return e.dropPageRules&&(t=jre(t)),t}function Mq(r){let e=(s,a,c)=>s.replace(/\(\s*(min-|max-)?(width|height)\s*:\s*(-?[0-9.]+)\s*(px|em|rem)?\s*\)/gi,(l,u,d,f,h)=>{let p=Number(f)*(h&&h.toLowerCase()!=="px"?16:1),m=d.toLowerCase()==="width"?a:c,g=(u??"").toLowerCase();return(g==="min-"?m>=p:g==="max-"?m<=p:m===p)?"(min-width: 0px)":"(min-width: 1000000px)"}),t=s=>s.replace(/(^|[\s,(])screen(?=$|[\s,)])/gi,"$1all").replace(/(^|[\s,(])print(?=$|[\s,)])/gi,"$1all and (min-width: 1000000px)"),i=(s,a,c)=>{let l=r.mediaViewport?e(s,a,c):s;return r.screenTypes&&(l=t(l)),l},n=document;if(r.webkit534Css){let s=a=>a.replace(/(?<=^|[;{\s])display\s*:\s*(?:-webkit-)?(?:inline-)?(?:flex|grid)\s*(?:!\s*important\s*)?(?:;\s*|(?=\}|$))/gi,"").replace(/(?<=^|[;{\s])(?!--)[a-z-]+\s*:[^;{}]*\b(?:-webkit-)?(?:calc|var)\([^;{}]*(?:;\s*|(?=\}|$))/gi,"");for(let a of Array.from(n.querySelectorAll("style"))){let c=s(a.textContent??"");c!==a.textContent&&(a.textContent=c)}for(let a of Array.from(n.querySelectorAll("[style]"))){let c=a.getAttribute("style")??"",l=s(c);l!==c&&a.setAttribute("style",l)}}if(r.mediaViewport||r.dropPageRules||r.screenTypes){let[s,a]=r.mediaViewport??[0,0],c=l=>{for(let u=l.length-1;u>=0;u--){let d=l[u];if(r.dropPageRules&&d instanceof CSSPageRule){let f=d.parentRule;f?f.deleteRule(u):d.parentStyleSheet?.deleteRule(u);continue}if((r.mediaViewport||r.screenTypes)&&(d instanceof CSSMediaRule||d instanceof CSSImportRule)){let f=i(d.media.mediaText,s,a);f!==d.media.mediaText&&(d.media.mediaText=f)}if(d instanceof CSSImportRule&&d.styleSheet)try{c(d.styleSheet.cssRules)}catch{}"cssRules"in d&&d.cssRules&&c(d.cssRules)}};for(let l of Array.from(n.styleSheets))try{c(l.cssRules)}catch{}if(r.mediaViewport||r.screenTypes)for(let l of Array.from(n.querySelectorAll("link[media], style[media]"))){let u=i(l.media,s,a);u!==l.media&&(l.media=u)}}if(r.roundFontSizes||r.minimumFontSize){let s=Array.from(n.querySelectorAll("body, body *")),a=s.map(c=>parseFloat(getComputedStyle(c).fontSize));s.forEach((c,l)=>{let u=a[l];r.minimumFontSize&&u<r.minimumFontSize&&(u=r.minimumFontSize),r.roundFontSizes&&(u=Math.round(u)),Math.abs(u-a[l])>.001&&c.style.setProperty("font-size",`${u}px`,"important")})}let o=s=>Math.trunc(s+(s<0?-.01:.01));if(r.wholePixelLineHeights||r.normalLineHeight){let s=Array.from(n.querySelectorAll("body, body *")),a=new Map,c=r.normalLineHeight?n.createElement("canvas").getContext("2d"):null,l=d=>{let f=`${d.fontStyle} ${d.fontWeight} ${d.fontFamily}`,h=a.get(f);if(!h){c.font=`${d.fontStyle} ${d.fontWeight} 1000px ${d.fontFamily}`;let p=c.measureText("x");h=[p.fontBoundingBoxAscent/1e3,p.fontBoundingBoxDescent/1e3],a.set(f,h)}return h},u=s.map(d=>{let f=getComputedStyle(d),h=parseFloat(f.fontSize);if(f.lineHeight==="normal"){if(!r.normalLineHeight||!c)return null;let[m,g]=l(f);return Math.ceil(m*h-.001)+Math.ceil(g*h-.001)}if(!r.wholePixelLineHeights)return null;let p=d.computedStyleMap?.().get("line-height");return p?.unit==="number"?Math.trunc(Math.round(h)*p.value+1e-6):p?.unit==="percent"?Math.trunc(Math.round(h)*p.value/100+1e-6):o(parseFloat(f.lineHeight))});s.forEach((d,f)=>{let h=u[f];h!=null&&d.style.setProperty("line-height",`${h}px`,"important")})}if(r.wholePixelBoxes){let s=["margin-top","margin-bottom","margin-left","margin-right","padding-top","padding-bottom","padding-left","padding-right","text-indent"],a=Array.from(n.querySelectorAll("body, body *")),c=a.map(l=>{let u=getComputedStyle(l);return s.map(d=>parseFloat(u.getPropertyValue(d)))});a.forEach((l,u)=>{s.forEach((d,f)=>{let h=c[u][f];Number.isFinite(h)&&Math.abs(h-o(h))>.001&&l.style.setProperty(d,`${o(h)}px`,"important")})})}if(r.truncateTopMargin&&n.body){let s=n.documentElement,a=getComputedStyle(s),c=s.getBoundingClientRect().top+parseFloat(a.borderTopWidth)+parseFloat(a.paddingTop),l=n.body.getBoundingClientRect().top-c;l>0&&s.style.setProperty("margin-top",`${-l}px`,"important")}if(r.pageTopMargins&&n.body){let s=l=>Math.abs(l.getBoundingClientRect().top+window.scrollY)<.01,a=l=>!parseFloat(l.paddingTop)&&!parseFloat(l.borderTopWidth)&&(l.display!=="table"||l.borderCollapse==="collapse"||!parseFloat(l.borderSpacing.split(" ").pop())),c=l=>{let u=[],d;for(let f of Array.from(l.childNodes)){if(f.nodeType===Node.TEXT_NODE){if(f.textContent?.trim())break;continue}if(!(f instanceof HTMLElement))continue;let h=getComputedStyle(f);if(h.display!=="none"){if(h.cssFloat!=="none"||h.position==="absolute"||h.position==="fixed"){u.push(f);continue}if(h.display.startsWith("inline"))break;if(h.display==="table-row-group"||h.display==="table-header-group"||h.display==="table-row"){c(f);break}if(h.display==="table-cell"){for(let p of Array.from(l.children))a(getComputedStyle(p))&&c(p);break}d=f;break}}d&&(parseFloat(getComputedStyle(d).marginTop)>0&&d.style.setProperty("margin-top","0px","important"),a(getComputedStyle(d))&&c(d));for(let f of u)s(f)&&a(getComputedStyle(f))&&c(f)};c(n.body)}if(r.grayscale&&n.documentElement.style.setProperty("filter","grayscale(100%)","important"),r.noDefaultWidows||r.unsplitRows){let s=n.createElement("style");s.textContent=`@layer pdfkiln-defaults { ${r.noDefaultWidows?"html { orphans: 1; widows: 1 }":""} ${r.unsplitRows?"tr { break-inside: avoid }":""} }`,(n.head??n.documentElement).prepend(s)}if(r.noShrinkToFit&&n.body){let s=a=>{let c=getComputedStyle(a);return c.overflowX==="visible"&&c.overflowY==="visible"};if(s(n.documentElement)&&s(n.body))for(let a of[n.documentElement,n.body])a.style.setProperty("overflow-x","clip","important")}}var Bre,Rq,Ure,qre,Iq=b(()=>{"use strict";Bre="(min-width: 0px)",Rq="(min-width: 1000000px)";Ure=/(?<=^|[;{\s])display\s*:\s*(?:-webkit-)?(?:inline-)?(?:flex|grid)\s*(?:!\s*important\s*)?(?:;\s*|(?=\}|$))/gi,qre=/(?<=^|[;{\s])(?!--)[a-z-]+\s*:[^;{}]*\b(?:-webkit-)?(?:calc|var)\([^;{}]*(?:;\s*|(?=\}|$))/gi});function mD(r){try{return Lq.realpathSync.native(r)}catch{return null}}function H3(r,e=""){let t=zre[(0,yD.extname)(r).toLowerCase()]??"application/octet-stream";return e&&t.startsWith("text/")?`${t}; charset=${e}`:t}function V3(r){try{return(0,Nq.fileURLToPath)(r)}catch{return null}}async function _q(r){try{return await(0,Bq.readFile)(r)}catch{return null}}var Lq,Bq,yD,Nq,gD,zre,jq=b(()=>{"use strict";Lq=require("node:fs"),Bq=require("node:fs/promises"),yD=require("node:path"),Nq=require("node:url");gD=class{constructor(e){this.block=e}block;allowed=new Set;allow(e){let t=mD(e);t&&this.allowed.add(t)}allows(e){if(!this.block)return!0;let t=mD(e);t||(t=e);for(let i="";t!==i;i=t,t=(0,yD.dirname)(t))if(this.allowed.has(t))return!0;return!1}},zre={".html":"text/html",".htm":"text/html",".xhtml":"application/xhtml+xml",".svg":"image/svg+xml",".css":"text/css",".js":"text/javascript",".mjs":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".bmp":"image/bmp",".ico":"image/x-icon",".avif":"image/avif",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject",".txt":"text/plain",".xml":"text/xml",".pdf":"application/pdf"}});function Uq(r){return r.split(".").map(Number)}function Hq(r){if((0,$c.isIP)(r)===4){let[e,t]=Uq(r);return e===0||e===10||e===127||e>=224||e===100&&t>=64&&t<=127||e===169&&t===254||e===172&&t>=16&&t<=31||e===192&&t===168||e===192&&t===0&&Uq(r)[2]===0||e===198&&(t===18||t===19)}if((0,$c.isIP)(r)===6){let e=r.toLowerCase(),t=/^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(e)??/^64:ff9b::(\d+\.\d+\.\d+\.\d+)$/.exec(e);if(t)return Hq(t[1]);if(e==="::"||e==="::1")return!0;let i=parseInt(e.split(":")[0]||"0",16);return(i&65024)===64512||(i&65472)===65152||(i&65280)===65280}return!0}async function Vq(r,e){let t=r.replace(/^\[|\]$/g,""),i=(0,$c.isIP)(t)?[{address:t,family:(0,$c.isIP)(t)}]:await(0,Wq.lookup)(t,{all:!0});if(!e)return i;if(!i.length||i.some(n=>Hq(n.address)))throw new ka(`Blocked access to private address of ${t}`);return i}async function qq(r,e){return(await Vq(r,e))[0]}async function bD(){let r=[],e=new Set,t=(0,hy.createServer)(async(n,o)=>{let s;try{s=new URL(n.url??"")}catch{o.writeHead(400).end();return}try{let a=await qq(s.hostname,!0),c={...n.headers};delete c["proxy-connection"];let l=(0,hy.request)({host:a.address,family:a.family,port:s.port||80,method:n.method,path:s.pathname+s.search,headers:c},u=>{o.writeHead(u.statusCode??502,u.headers),u.pipe(o)});l.on("error",()=>o.destroy()),n.pipe(l)}catch(a){a instanceof ka&&r.push(s.hostname),o.writeHead(a instanceof ka?403:502).end()}});t.on("connection",n=>{e.add(n),n.on("close",()=>e.delete(n))}),t.on("connect",async(n,o,s)=>{let[a,c]=Vre(n.url??"");try{let l=await qq(a,!0),u=(0,$c.connect)({host:l.address,port:Number(c)||443},()=>{o.write(`HTTP/1.1 200 Connection Established\r
|
|
232
232
|
\r
|
|
@@ -226,7 +226,7 @@ You can also empty the whole browser cache with \`npx ${o} clear\` and then run
|
|
|
226
226
|
1. you did not perform an installation before running the script (e.g. \`npx puppeteer browsers install ${s}\`) or
|
|
227
227
|
2. your cache path is incorrectly configured (which is: ${i.cacheDirectory}).
|
|
228
228
|
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.`)}return n}},T3=new WeakMap});async function eD(r){await oq.default.promises.rm(r,bre)}var oq,bre,R3=b(()=>{oq=Ae(require("node:fs"),1);bre={force:!0,recursive:!0,maxRetries:10,retryDelay:100}});function sq(r,e=[]){let t=r.endsWith("=")?r:`${r}=`;return e.filter(i=>i.startsWith(t)).flatMap(i=>i.substring(i.indexOf("=")+1).trim().split(",").map(n=>n.trim())).filter(i=>i)}function aq(r,e){let t=e.endsWith("=")?e:`${e}=`,i=0;for(;i<r.length;)r[i].startsWith(t)?r.splice(i,1):i++;return r}var cq,lq,tD,rD,M3=b(()=>{cq=require("node:fs/promises"),lq=Ae(require("node:os"),1),tD=Ae(require("node:path"),1);dd();je();Ct();$S();E3();R3();rD=class extends op{constructor(e,t){super(e,"chrome",t)}async launch(e={}){return(await this.puppeteer.configuration()).logLevel==="warn"&&process.platform==="darwin"&&process.arch==="x64"&&lq.default.cpus()[0]?.model.includes("Apple")&&console.warn(["\x1B[1m\x1B[43m\x1B[30m","Degraded performance warning:\x1B[0m\x1B[33m","Launching Chrome on Mac Silicon (arm64) from an x64 Node installation results in","Rosetta translating the Chrome binary, even if Chrome is already arm64. This would","result in huge performance issues. To resolve this, you must run Puppeteer with","a version of Node built for arm64."].join(`
|
|
229
|
-
`)),await super.launch(e)}async computeLaunchArguments(e={}){let{ignoreDefaultArgs:t=!1,args:i=[],pipe:n=!1,debuggingPort:o,channel:s,executablePath:a}=e,c=[];t?Array.isArray(t)?c.push(...this.defaultArgs(e).filter(h=>!t.includes(h))):c.push(...i):c.push(...this.defaultArgs(e)),c.some(h=>h.startsWith("--remote-debugging-"))||(n?(ee(!o,"Browser should be launched with either pipe or debugging port - not both."),c.push("--remote-debugging-pipe")):c.push(`--remote-debugging-port=${o||0}`));let l=!1,u=c.findIndex(h=>h.startsWith("--user-data-dir")),d;if(u<0){l=!0;let h=await this.getProfilePath();d=await(0,cq.mkdtemp)(h),c.push(`--user-data-dir=${d}`)}else{let h=c[u].split("=",2)[1];ee(typeof h=="string","`--user-data-dir` is malformed"),d=h}let f=a;return f||(ee(s||!this.puppeteer._isPuppeteerCore,"An `executablePath` or `channel` must be specified for `puppeteer-core`"),f=s?await this.executablePath(s):await this.resolveExecutablePath(e.headless??!0)),{executablePath:f,args:c,isTempUserDataDir:l,userDataDir:d}}async cleanUserDataDir(e,t){if(t.isTemp)try{await eD(e)}catch(i){this.logger(H.error)?.(i)}}defaultArgs(e={}){let t=sq("--disable-features",e.args);e.args&&t.length>0&&aq(e.args,"--disable-features");let i=process.env.PUPPETEER_TEST_EXPERIMENTAL_CHROME_FEATURES==="true",n=sq("--enable-features",e.args);e.args&&n.length>0&&aq(e.args,"--enable-features");let o=["PdfOopif",...n].filter(h=>h!==""),a=["--allow-pre-commit-input","--disable-background-networking","--disable-background-timer-throttling","--disable-backgrounding-occluded-windows","--disable-breakpad","--disable-client-side-phishing-detection","--disable-component-extensions-with-background-pages","--disable-crash-reporter","--disable-default-apps","--disable-dev-shm-usage","--disable-hang-monitor","--disable-infobars","--disable-ipc-flooding-protection","--disable-popup-blocking","--disable-prompt-on-repost","--disable-renderer-backgrounding","--disable-search-engine-choice-screen","--disable-sync","--enable-automation","--export-tagged-pdf","--force-color-profile=srgb","--generate-pdf-document-outline","--metrics-recording-only","--no-first-run","--password-store=basic","--use-mock-keychain",`--disable-features=${["Translate","AcceptCHFrame","MediaRouter","OptimizationHints","WebUIReloadButton","WebUIOmniboxPopup","WebUIOmniboxAimPopup",...i?[]:["ProcessPerSiteUpToMainFrameThreshold","IsolateSandboxedIframes"],...t].filter(h=>h!=="").filter(h=>!o.includes(h)).join(",")}`,`--enable-features=${o.join(",")}`].filter(h=>h!==""),{devtools:c=!1,headless:l=!c,args:u=[],userDataDir:d,enableExtensions:f=!1}=e;return process.env.PUPPETEER_DANGEROUS_NO_SANDBOX==="true"&&!u.includes("--no-sandbox")&&a.push("--no-sandbox"),d&&a.push(`--user-data-dir=${tD.default.posix.isAbsolute(d)||tD.default.win32.isAbsolute(d)?d:tD.default.resolve(d)}`),c&&a.push("--auto-open-devtools-for-tabs"),l&&a.push(l==="shell"?"--headless":"--headless=new","--hide-scrollbars","--mute-audio"),f||a.push("--disable-extensions"),u.every(h=>h.startsWith("-"))&&a.push("about:blank"),a.push(...u),a}async executablePath(e,t=!0){return e?Vh({browser:De.CHROME,channel:D3(e)},t):await this.resolveExecutablePath(void 0,t)}}});var uq,sp,dq,I3,iD,L3=b(()=>{uq=Ae(require("node:fs"),1),sp=require("node:fs/promises"),dq=Ae(require("node:os"),1),I3=Ae(require("node:path"),1);dd();je();Ct();$S();R3();iD=class r extends op{constructor(e,t){super(e,"firefox",t)}static getPreferences(e){return{...e,"fission.webContentIsolationStrategy":0}}async computeLaunchArguments(e={}){let{ignoreDefaultArgs:t=!1,args:i=[],executablePath:n,pipe:o=!1,extraPrefsFirefox:s={},debuggingPort:a=null}=e,c=[];t?Array.isArray(t)?c.push(...this.defaultArgs(e).filter(h=>!t.includes(h))):c.push(...i):c.push(...this.defaultArgs(e)),c.some(h=>h.startsWith("--remote-debugging-"))||(o&&ee(a===null,"Browser should be launched with either pipe or debugging port - not both."),c.push(`--remote-debugging-port=${a||0}`));let l,u=!0,d=c.findIndex(h=>["-profile","--profile"].includes(h));if(d!==-1){if(l=c[d+1],!l)throw new Error("Missing value for profile command line argument");u=!1}else{let h=await this.getProfilePath();l=await(0,sp.mkdtemp)(h),c.push("--profile"),c.push(l)}await J1(De.FIREFOX,{path:l,preferences:r.getPreferences(s)});let f;return this.puppeteer._isPuppeteerCore||n?(ee(n,"An `executablePath` must be specified for `puppeteer-core`"),f=n):f=await this.executablePath(void 0),{isTempUserDataDir:u,userDataDir:l,args:c,executablePath:f}}async cleanUserDataDir(e,t){if(t.isTemp)try{await eD(e)}catch(i){this.logger(H.error)?.(i)}else try{let i=".puppeteer",n=["prefs.js","user.js"],o=await Promise.allSettled(n.map(async s=>{let a=I3.default.join(e,s+i);if(uq.default.existsSync(a)){let c=I3.default.join(e,s);await(0,sp.unlink)(c),await(0,sp.rename)(a,c)}}));for(let s of o)if(s.status==="rejected")throw s.reason}catch(i){this.logger(H.error)?.(i)}}async executablePath(e,t=!0){return await this.resolveExecutablePath(void 0,t)}defaultArgs(e={}){let{devtools:t=!1,headless:i=!t,args:n=[],userDataDir:o=null}=e,s=[];switch(dq.default.platform()){case"darwin":s.push("--foreground");break;case"win32":s.push("--wait-for-browser");break}return o&&(s.push("--profile"),s.push(o)),i&&s.push("--headless"),t&&s.push("--devtools"),n.every(a=>a.startsWith("-"))&&s.push("about:blank"),s.push(...n),s}}});var nD,fq=b(()=>{dd();je();k3();An();A3();M3();L3();nD=class extends YS{#e;#t;configuration;constructor(e){let{configuration:t,...i}=e;super(i),t?this.configuration=t:this.configuration=()=>Promise.resolve({}),this.connect=this.connect.bind(this),this.launch=this.launch.bind(this),this.executablePath=this.executablePath.bind(this),this.defaultArgs=this.defaultArgs.bind(this),this.trimCache=this.trimCache.bind(this)}connect(e){return e.logger??=ta,super.connect(e)}async launch(e={}){e.logger??=ta;let{browser:t=await this.defaultBrowser()}=e;if(this.#t=t,!["chrome","firefox"].includes(t))throw new Error(`Unknown product: ${t}`);return this.#e=this.#r(t,e.logger),await this.#e.launch(e)}#r(e,t){if(this.#e&&this.#e.browser===e)return this.#e;switch(e){case"chrome":return new rD(this,t);case"firefox":return new iD(this,t);default:throw new Error(`Unknown product: ${e}`)}}async executablePath(e){return e===void 0?await this.#r(await this.lastLaunchedBrowser(),ta).executablePath(void 0,!1):typeof e=="string"?await this.#r("chrome",ta).executablePath(e,!1):await this.#r(e.browser??await this.lastLaunchedBrowser(),e.logger??ta).resolveExecutablePath(e.headless,!1)}async browserVersion(){let e=await this.configuration(),t=await this.lastLaunchedBrowser();return e?.[t]?.version??F3[t]}async defaultDownloadPath(){return(await this.configuration()).cacheDirectory}async lastLaunchedBrowser(){return this.#t??await this.defaultBrowser()}async defaultBrowser(){return(await this.configuration()).defaultBrowser??"chrome"}async defaultArgs(e={}){return this.#r(e.browser??await this.lastLaunchedBrowser(),e.logger??ta).defaultArgs(e)}async trimCache(){let e=Di();if(!e)throw new Error("The current platform is not supported.");let t=await this.configuration(),i=t.cacheDirectory,n=await bS({cacheDir:i}),o=[{product:"chrome",browser:De.CHROME,currentBuildId:""},{product:"firefox",browser:De.FIREFOX,currentBuildId:""}];await Promise.all(o.map(async c=>{let l=t?.[c.product]?.version??F3[c.product];c.currentBuildId=await zh(c.browser,e,l)}));let s=new Set(o.map(c=>`${c.browser}_${c.currentBuildId}`)),a=new Set(o.map(c=>c.browser));for(let c of n)a.has(c.browser)&&(s.has(`${c.browser}_${c.buildId}`)||await yS({browser:c.browser,platform:e,cacheDir:i,buildId:c.buildId}))}setFollowSymlinks(e){lt.value.followSymlinks=e}}});function Sre(r,e,t,i){let n=Math.round((t-r)*i),o=Math.round((e-r)*i);return Math.max(0,n-o)}var oD,mq,gq,wre,hq,xre,vre,pq,yq,bq=b(()=>{oD=require("node:child_process"),mq=Ae(require("node:os"),1),gq=require("node:stream");eo();Ii();je();Ot();pr();bt();wre=function(r,e,t){for(var i=arguments.length>2,n=0;n<e.length;n++)t=i?e[n].call(r,t):e[n].call(r);return i?t:void 0},hq=function(r,e,t,i,n,o){function s(y){if(y!==void 0&&typeof y!="function")throw new TypeError("Function expected");return y}for(var a=i.kind,c=a==="getter"?"get":a==="setter"?"set":"value",l=!e&&r?i.static?r:r.prototype:null,u=e||(l?Object.getOwnPropertyDescriptor(l,i.name):{}),d,f=!1,h=t.length-1;h>=0;h--){var p={};for(var m in i)p[m]=m==="access"?{}:i[m];for(var m in i.access)p.access[m]=i.access[m];p.addInitializer=function(y){if(f)throw new TypeError("Cannot add initializers after decoration has completed");o.push(s(y||null))};var g=(0,t[h])(a==="accessor"?{get:u.get,set:u.set}:u[c],p);if(a==="accessor"){if(g===void 0)continue;if(g===null||typeof g!="object")throw new TypeError("Object expected");(d=s(g.get))&&(u.get=d),(d=s(g.set))&&(u.set=d),(d=s(g.init))&&n.unshift(d)}else(d=s(g))&&(a==="field"?n.unshift(d):u[c]=d)}l&&Object.defineProperty(l,i.name,u),f=!0},xre=function(r,e,t){return typeof e=="symbol"&&(e=e.description?"[".concat(e.description,"]"):""),Object.defineProperty(r,"name",{configurable:!0,value:t?"".concat(t," ",e):e})},vre=30,pq=30;yq=(()=>{let r=gq.PassThrough,e=[],t,i,n;return class extends r{static{let s=typeof Symbol=="function"&&Symbol.metadata?Object.create(r[Symbol.metadata]??null):void 0;hq(this,i={value:xre(async function(a){let c=await new Promise(l=>{this.#t.stdin.write(a,l)});c&&console.log(`ffmpeg failed to write: ${c.message}.`)},"#writeFrame")},t,{kind:"method",name:"#writeFrame",static:!1,private:!0,access:{has:a=>#a in a,get:a=>a.#a},metadata:s},null,e),hq(this,null,n,{kind:"method",name:"stop",static:!1,private:!1,access:{has:a=>"stop"in a,get:a=>a.stop},metadata:s},null,e),s&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:s})}#e=wre(this,e);#t;#r=new AbortController;#i;#n;#s;constructor(s,a,c,{ffmpegPath:l,speed:u,scale:d,crop:f,format:h,fps:p,loop:m,delay:g,quality:y,colors:x}={},C){super({allowHalfOpen:!1}),this.#s=C,l??="ffmpeg",h??="webm",p??=pq,m||=-1,g??=-1,y??=vre,x??=256,this.#n=p;let{error:T}=(0,oD.spawnSync)(l);if(T)throw T;let B=[`crop='min(${a},iw):min(${c},ih):0:0'`,`pad=${a}:${c}:0:0`];u&&B.push(`setpts=${1/u}*PTS`),f&&B.push(`crop=${f.width}:${f.height}:${f.x}:${f.y}`),d&&B.push(`scale=iw*${d}:-1:flags=lanczos`);let M=this.#o(h,p,m,g,y,x),E=M.indexOf("-vf");E!==-1&&B.push(M.splice(E,2).at(-1)??""),this.#t=(0,oD.spawn)(l,[["-loglevel","error"],["-avioflags","direct"],["-fpsprobesize","0","-probesize","32","-analyzeduration","0","-fflags","nobuffer"],["-framerate",`${p}`,"-f","image2pipe","-vcodec","png","-i","pipe:0"],["-an"],["-threads","1"],["-b:v","0"],M,["-vf",B.join()],"pipe:1"].flat(),{stdio:["pipe","pipe","pipe"]}),this.#t.stdout.pipe(this),this.#t.stderr.on("data",k=>{this.#s?.(H.ffmpeg)?.(k.toString("utf8"))}),this.#e=s;let{client:D}=this.#e.mainFrame();D.once(mt.Disconnected,()=>{this.stop().catch(k=>{this.#s?.(H.error)?.(k)})});let O;this.#i=WL(xt(D,"Page.screencastFrame").pipe(Du(k=>{D.send("Page.screencastFrameAck",{sessionId:k.sessionId})}),Pn(k=>k.metadata.timestamp!==void 0),Wt(k=>({buffer:Buffer.from(k.data,"base64"),timestamp:k.metadata.timestamp})),GL(2,1),XL(([{timestamp:k,buffer:S},{timestamp:P}])=>(O??=k,Ye(Array(Sre(O,k,P,p)).fill(S)))),Wt(k=>(this.#a(k),[k,performance.now()])),fx(Pf(this.#r.signal,"abort"))),{defaultValue:[Buffer.from([]),performance.now()]})}#o(s,a,c,l,u,d){let f=[["-vcodec","vp9"],["-crf",`${u}`],["-deadline","realtime","-cpu-used",`${Math.min(mq.default.cpus().length/2,8)}`]];switch(s){case"webm":return[...f,["-f","webm"]].flat();case"gif":return a=pq===a?20:"source_fps",c===1/0&&(c=0),l!==-1&&(l/=10),[["-vf",`fps=${a},split[s0][s1];[s0]palettegen=stats_mode=diff:max_colors=${d}[p];[s1][p]paletteuse=dither=bayer`],["-loop",`${c}`],["-final_delay",`${l}`],["-f","gif"]].flat();case"mp4":return[...f,["-movflags","hybrid_fragmented"],["-f","mp4"]].flat()}}get#a(){return i.value}async stop(){if(this.#r.signal.aborted)return;await this.#e._stopScreencast().catch(c=>{this.#s?.(H.error)?.(c)}),this.#r.abort();let[s,a]=await this.#i;await Promise.all(Array(Math.max(1,Math.round(this.#n*(performance.now()-a)/1e3))).fill(s).map(this.#a.bind(this))),this.#t.stdin.end(),await new Promise(c=>{this.#t.once("close",c)})}async[(t=[oa()],n=[oa()],Et)](){await this.stop(),await super[Et]()}}})()});var wq=b(()=>{M3();L3();P3();$S();fq();bq();});var B3=b(()=>{CP();wq();});var xq,jUe,UUe,qUe,WUe,uy,N3=b(()=>{pL();B3();An();B3();lt.value.ScreenRecorder=yq;xq=new nD({isPuppeteerCore:!0}),{connect:jUe,defaultArgs:UUe,executablePath:qUe,launch:WUe}=xq,uy=xq});function vq(r,e){let t=(0,mo.readFileSync)(r),i=a=>new Error(`${r}: ${a}`),n=-1;for(let a=t.length-22;a>=Math.max(0,t.length-22-65535);a--)if(t.readUInt32LE(a)===Ere){n=a;break}if(n<0)throw i("not a zip file");let o=t.readUInt16LE(n+10),s=t.readUInt32LE(n+16);if((o===65535||s===sD)&&n>=20&&t.readUInt32LE(n-20)===Cre){let a=Number(t.readBigUInt64LE(n-12));if(t.readUInt32LE(a)!==kre)throw i("bad Zip64 record");o=Number(t.readBigUInt64LE(a+32)),s=Number(t.readBigUInt64LE(a+48))}(0,mo.mkdirSync)(e,{recursive:!0});for(let a=0,c=s;a<o;a++){if(t.readUInt32LE(c)!==Fre)throw i("bad central directory");let l=t.readUInt16LE(c+4),u=t.readUInt16LE(c+10),d=t.readUInt32LE(c+16),f=t.readUInt32LE(c+20),h=t.readUInt32LE(c+24),p=t.readUInt16LE(c+28),m=t.readUInt16LE(c+30),g=t.readUInt16LE(c+32),y=t.readUInt32LE(c+38),x=t.readUInt32LE(c+42),C=t.toString("utf8",c+46,c+46+p);for(let S=c+46+p;S<c+46+p+m;S+=4+t.readUInt16LE(S+2)){if(t.readUInt16LE(S)!==1)continue;let P=S+4,I=()=>Number(t.readBigUInt64LE((P+=8)-8));h===sD&&(h=I()),f===sD&&(f=I()),x===sD&&(x=I())}c+=46+p+m+g;let T=(0,Ss.normalize)(C);if((0,Ss.isAbsolute)(T)||T.split(/[\\/]/).includes(".."))throw i(`entry outside the archive: ${C}`);let B=(0,Ss.join)(e,T),M=l>>8===3?y>>>16:0,E=M&61440;if(C.endsWith("/")||E===16384){(0,mo.mkdirSync)(B,{recursive:!0});continue}if(t.readUInt32LE(x)!==Are)throw i(`bad local header: ${C}`);let D=x+30+t.readUInt16LE(x+26)+t.readUInt16LE(x+28),O=t.subarray(D,D+f),k=u===0?O:u===8?(0,aD.inflateRawSync)(O):null;if(!k)throw i(`compression method ${u}: ${C}`);if(k.length!==h||(0,aD.crc32)(k)!==d)throw i(`corrupt entry: ${C}`);if((0,mo.mkdirSync)((0,Ss.dirname)(B),{recursive:!0}),E===40960){(0,mo.symlinkSync)(k.toString("utf8"),B);continue}(0,mo.writeFileSync)(B,k),M&511&&Ss.sep==="/"&&(0,mo.chmodSync)(B,M&511)}}var mo,Ss,aD,Ere,Cre,kre,Fre,Are,sD,Sq=b(()=>{"use strict";mo=require("node:fs"),Ss=require("node:path"),aD=require("node:zlib"),Ere=101010256,Cre=117853008,kre=101075792,Fre=33639248,Are=67324752,sD=4294967295});var jo,go,ap=b(()=>{"use strict";jo="1.0.2",go="156.0.8078.47"});function Pre(){return JSON.parse((0,Ei.readFileSync)((0,vr.join)(Fq,"chromium.json"),"utf8"))}function U3(){let{platform:r,arch:e}=process;if(r==="linux"&&e==="x64")return"linux64";if(r==="linux"&&e==="arm64")return"linux-arm64";if(r==="darwin")return e==="arm64"?"mac-arm64":"mac-x64";if(r==="win32")return e==="ia32"?"win32":"win64";throw new Error(`No chrome-headless-shell build for ${r}-${e}`)}function Tre(r=go){return(0,vr.join)(Fq,".cache","chromium",r)}function j3(){try{return typeof require=="function"&&require("node:sea").isSea()}catch{return!1}}function lD(){return process.env.PDFKILN_CACHE_DIR?process.env.PDFKILN_CACHE_DIR:process.platform==="win32"?(0,vr.join)(process.env.LOCALAPPDATA??(0,vr.join)((0,cD.homedir)(),"AppData","Local"),"pdfkiln"):process.platform==="darwin"?(0,vr.join)((0,cD.homedir)(),"Library","Caches","pdfkiln"):(0,vr.join)(process.env.XDG_CACHE_HOME||(0,vr.join)((0,cD.homedir)(),".cache"),"pdfkiln")}function Rre(){if(process.env.PDFKILN_CHROMIUM)return process.env.PDFKILN_CHROMIUM;let r=(0,vr.join)(j3()?(0,vr.dirname)(process.execPath):kq,"chromium",_3()),e=(0,vr.join)(Tre(),`chrome-headless-shell-${U3()}`,_3());for(let i of[r,e])if((0,Ei.existsSync)(i))return i;let t=Ore();return(0,Ei.existsSync)(t)||!j3()?t:r}async function uD(){let r=Rre();if((0,Ei.existsSync)(r)||process.env.PDFKILN_CHROMIUM||j3())return r;let e=Pre(),t=U3(),i=e.archives[t];if(!i)throw new Error(`chromium.json has no archive for ${t}`);let n=`${e.source}/${e.version}/${t}/${i.file}`,o=(0,vr.join)(lD(),"chromium",e.version);process.stderr.write(`pdfkiln: first use, downloading Chromium ${e.version} (${Math.round(i.size/1e6)} MB) into ${o}
|
|
229
|
+
`)),await super.launch(e)}async computeLaunchArguments(e={}){let{ignoreDefaultArgs:t=!1,args:i=[],pipe:n=!1,debuggingPort:o,channel:s,executablePath:a}=e,c=[];t?Array.isArray(t)?c.push(...this.defaultArgs(e).filter(h=>!t.includes(h))):c.push(...i):c.push(...this.defaultArgs(e)),c.some(h=>h.startsWith("--remote-debugging-"))||(n?(ee(!o,"Browser should be launched with either pipe or debugging port - not both."),c.push("--remote-debugging-pipe")):c.push(`--remote-debugging-port=${o||0}`));let l=!1,u=c.findIndex(h=>h.startsWith("--user-data-dir")),d;if(u<0){l=!0;let h=await this.getProfilePath();d=await(0,cq.mkdtemp)(h),c.push(`--user-data-dir=${d}`)}else{let h=c[u].split("=",2)[1];ee(typeof h=="string","`--user-data-dir` is malformed"),d=h}let f=a;return f||(ee(s||!this.puppeteer._isPuppeteerCore,"An `executablePath` or `channel` must be specified for `puppeteer-core`"),f=s?await this.executablePath(s):await this.resolveExecutablePath(e.headless??!0)),{executablePath:f,args:c,isTempUserDataDir:l,userDataDir:d}}async cleanUserDataDir(e,t){if(t.isTemp)try{await eD(e)}catch(i){this.logger(H.error)?.(i)}}defaultArgs(e={}){let t=sq("--disable-features",e.args);e.args&&t.length>0&&aq(e.args,"--disable-features");let i=process.env.PUPPETEER_TEST_EXPERIMENTAL_CHROME_FEATURES==="true",n=sq("--enable-features",e.args);e.args&&n.length>0&&aq(e.args,"--enable-features");let o=["PdfOopif",...n].filter(h=>h!==""),a=["--allow-pre-commit-input","--disable-background-networking","--disable-background-timer-throttling","--disable-backgrounding-occluded-windows","--disable-breakpad","--disable-client-side-phishing-detection","--disable-component-extensions-with-background-pages","--disable-crash-reporter","--disable-default-apps","--disable-dev-shm-usage","--disable-hang-monitor","--disable-infobars","--disable-ipc-flooding-protection","--disable-popup-blocking","--disable-prompt-on-repost","--disable-renderer-backgrounding","--disable-search-engine-choice-screen","--disable-sync","--enable-automation","--export-tagged-pdf","--force-color-profile=srgb","--generate-pdf-document-outline","--metrics-recording-only","--no-first-run","--password-store=basic","--use-mock-keychain",`--disable-features=${["Translate","AcceptCHFrame","MediaRouter","OptimizationHints","WebUIReloadButton","WebUIOmniboxPopup","WebUIOmniboxAimPopup",...i?[]:["ProcessPerSiteUpToMainFrameThreshold","IsolateSandboxedIframes"],...t].filter(h=>h!=="").filter(h=>!o.includes(h)).join(",")}`,`--enable-features=${o.join(",")}`].filter(h=>h!==""),{devtools:c=!1,headless:l=!c,args:u=[],userDataDir:d,enableExtensions:f=!1}=e;return process.env.PUPPETEER_DANGEROUS_NO_SANDBOX==="true"&&!u.includes("--no-sandbox")&&a.push("--no-sandbox"),d&&a.push(`--user-data-dir=${tD.default.posix.isAbsolute(d)||tD.default.win32.isAbsolute(d)?d:tD.default.resolve(d)}`),c&&a.push("--auto-open-devtools-for-tabs"),l&&a.push(l==="shell"?"--headless":"--headless=new","--hide-scrollbars","--mute-audio"),f||a.push("--disable-extensions"),u.every(h=>h.startsWith("-"))&&a.push("about:blank"),a.push(...u),a}async executablePath(e,t=!0){return e?Vh({browser:De.CHROME,channel:D3(e)},t):await this.resolveExecutablePath(void 0,t)}}});var uq,sp,dq,I3,iD,L3=b(()=>{uq=Ae(require("node:fs"),1),sp=require("node:fs/promises"),dq=Ae(require("node:os"),1),I3=Ae(require("node:path"),1);dd();je();Ct();$S();R3();iD=class r extends op{constructor(e,t){super(e,"firefox",t)}static getPreferences(e){return{...e,"fission.webContentIsolationStrategy":0}}async computeLaunchArguments(e={}){let{ignoreDefaultArgs:t=!1,args:i=[],executablePath:n,pipe:o=!1,extraPrefsFirefox:s={},debuggingPort:a=null}=e,c=[];t?Array.isArray(t)?c.push(...this.defaultArgs(e).filter(h=>!t.includes(h))):c.push(...i):c.push(...this.defaultArgs(e)),c.some(h=>h.startsWith("--remote-debugging-"))||(o&&ee(a===null,"Browser should be launched with either pipe or debugging port - not both."),c.push(`--remote-debugging-port=${a||0}`));let l,u=!0,d=c.findIndex(h=>["-profile","--profile"].includes(h));if(d!==-1){if(l=c[d+1],!l)throw new Error("Missing value for profile command line argument");u=!1}else{let h=await this.getProfilePath();l=await(0,sp.mkdtemp)(h),c.push("--profile"),c.push(l)}await J1(De.FIREFOX,{path:l,preferences:r.getPreferences(s)});let f;return this.puppeteer._isPuppeteerCore||n?(ee(n,"An `executablePath` must be specified for `puppeteer-core`"),f=n):f=await this.executablePath(void 0),{isTempUserDataDir:u,userDataDir:l,args:c,executablePath:f}}async cleanUserDataDir(e,t){if(t.isTemp)try{await eD(e)}catch(i){this.logger(H.error)?.(i)}else try{let i=".puppeteer",n=["prefs.js","user.js"],o=await Promise.allSettled(n.map(async s=>{let a=I3.default.join(e,s+i);if(uq.default.existsSync(a)){let c=I3.default.join(e,s);await(0,sp.unlink)(c),await(0,sp.rename)(a,c)}}));for(let s of o)if(s.status==="rejected")throw s.reason}catch(i){this.logger(H.error)?.(i)}}async executablePath(e,t=!0){return await this.resolveExecutablePath(void 0,t)}defaultArgs(e={}){let{devtools:t=!1,headless:i=!t,args:n=[],userDataDir:o=null}=e,s=[];switch(dq.default.platform()){case"darwin":s.push("--foreground");break;case"win32":s.push("--wait-for-browser");break}return o&&(s.push("--profile"),s.push(o)),i&&s.push("--headless"),t&&s.push("--devtools"),n.every(a=>a.startsWith("-"))&&s.push("about:blank"),s.push(...n),s}}});var nD,fq=b(()=>{dd();je();k3();An();A3();M3();L3();nD=class extends YS{#e;#t;configuration;constructor(e){let{configuration:t,...i}=e;super(i),t?this.configuration=t:this.configuration=()=>Promise.resolve({}),this.connect=this.connect.bind(this),this.launch=this.launch.bind(this),this.executablePath=this.executablePath.bind(this),this.defaultArgs=this.defaultArgs.bind(this),this.trimCache=this.trimCache.bind(this)}connect(e){return e.logger??=ta,super.connect(e)}async launch(e={}){e.logger??=ta;let{browser:t=await this.defaultBrowser()}=e;if(this.#t=t,!["chrome","firefox"].includes(t))throw new Error(`Unknown product: ${t}`);return this.#e=this.#r(t,e.logger),await this.#e.launch(e)}#r(e,t){if(this.#e&&this.#e.browser===e)return this.#e;switch(e){case"chrome":return new rD(this,t);case"firefox":return new iD(this,t);default:throw new Error(`Unknown product: ${e}`)}}async executablePath(e){return e===void 0?await this.#r(await this.lastLaunchedBrowser(),ta).executablePath(void 0,!1):typeof e=="string"?await this.#r("chrome",ta).executablePath(e,!1):await this.#r(e.browser??await this.lastLaunchedBrowser(),e.logger??ta).resolveExecutablePath(e.headless,!1)}async browserVersion(){let e=await this.configuration(),t=await this.lastLaunchedBrowser();return e?.[t]?.version??F3[t]}async defaultDownloadPath(){return(await this.configuration()).cacheDirectory}async lastLaunchedBrowser(){return this.#t??await this.defaultBrowser()}async defaultBrowser(){return(await this.configuration()).defaultBrowser??"chrome"}async defaultArgs(e={}){return this.#r(e.browser??await this.lastLaunchedBrowser(),e.logger??ta).defaultArgs(e)}async trimCache(){let e=Di();if(!e)throw new Error("The current platform is not supported.");let t=await this.configuration(),i=t.cacheDirectory,n=await bS({cacheDir:i}),o=[{product:"chrome",browser:De.CHROME,currentBuildId:""},{product:"firefox",browser:De.FIREFOX,currentBuildId:""}];await Promise.all(o.map(async c=>{let l=t?.[c.product]?.version??F3[c.product];c.currentBuildId=await zh(c.browser,e,l)}));let s=new Set(o.map(c=>`${c.browser}_${c.currentBuildId}`)),a=new Set(o.map(c=>c.browser));for(let c of n)a.has(c.browser)&&(s.has(`${c.browser}_${c.buildId}`)||await yS({browser:c.browser,platform:e,cacheDir:i,buildId:c.buildId}))}setFollowSymlinks(e){lt.value.followSymlinks=e}}});function Sre(r,e,t,i){let n=Math.round((t-r)*i),o=Math.round((e-r)*i);return Math.max(0,n-o)}var oD,mq,gq,wre,hq,xre,vre,pq,yq,bq=b(()=>{oD=require("node:child_process"),mq=Ae(require("node:os"),1),gq=require("node:stream");eo();Ii();je();Ot();pr();bt();wre=function(r,e,t){for(var i=arguments.length>2,n=0;n<e.length;n++)t=i?e[n].call(r,t):e[n].call(r);return i?t:void 0},hq=function(r,e,t,i,n,o){function s(y){if(y!==void 0&&typeof y!="function")throw new TypeError("Function expected");return y}for(var a=i.kind,c=a==="getter"?"get":a==="setter"?"set":"value",l=!e&&r?i.static?r:r.prototype:null,u=e||(l?Object.getOwnPropertyDescriptor(l,i.name):{}),d,f=!1,h=t.length-1;h>=0;h--){var p={};for(var m in i)p[m]=m==="access"?{}:i[m];for(var m in i.access)p.access[m]=i.access[m];p.addInitializer=function(y){if(f)throw new TypeError("Cannot add initializers after decoration has completed");o.push(s(y||null))};var g=(0,t[h])(a==="accessor"?{get:u.get,set:u.set}:u[c],p);if(a==="accessor"){if(g===void 0)continue;if(g===null||typeof g!="object")throw new TypeError("Object expected");(d=s(g.get))&&(u.get=d),(d=s(g.set))&&(u.set=d),(d=s(g.init))&&n.unshift(d)}else(d=s(g))&&(a==="field"?n.unshift(d):u[c]=d)}l&&Object.defineProperty(l,i.name,u),f=!0},xre=function(r,e,t){return typeof e=="symbol"&&(e=e.description?"[".concat(e.description,"]"):""),Object.defineProperty(r,"name",{configurable:!0,value:t?"".concat(t," ",e):e})},vre=30,pq=30;yq=(()=>{let r=gq.PassThrough,e=[],t,i,n;return class extends r{static{let s=typeof Symbol=="function"&&Symbol.metadata?Object.create(r[Symbol.metadata]??null):void 0;hq(this,i={value:xre(async function(a){let c=await new Promise(l=>{this.#t.stdin.write(a,l)});c&&console.log(`ffmpeg failed to write: ${c.message}.`)},"#writeFrame")},t,{kind:"method",name:"#writeFrame",static:!1,private:!0,access:{has:a=>#a in a,get:a=>a.#a},metadata:s},null,e),hq(this,null,n,{kind:"method",name:"stop",static:!1,private:!1,access:{has:a=>"stop"in a,get:a=>a.stop},metadata:s},null,e),s&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:s})}#e=wre(this,e);#t;#r=new AbortController;#i;#n;#s;constructor(s,a,c,{ffmpegPath:l,speed:u,scale:d,crop:f,format:h,fps:p,loop:m,delay:g,quality:y,colors:x}={},C){super({allowHalfOpen:!1}),this.#s=C,l??="ffmpeg",h??="webm",p??=pq,m||=-1,g??=-1,y??=vre,x??=256,this.#n=p;let{error:T}=(0,oD.spawnSync)(l);if(T)throw T;let B=[`crop='min(${a},iw):min(${c},ih):0:0'`,`pad=${a}:${c}:0:0`];u&&B.push(`setpts=${1/u}*PTS`),f&&B.push(`crop=${f.width}:${f.height}:${f.x}:${f.y}`),d&&B.push(`scale=iw*${d}:-1:flags=lanczos`);let M=this.#o(h,p,m,g,y,x),E=M.indexOf("-vf");E!==-1&&B.push(M.splice(E,2).at(-1)??""),this.#t=(0,oD.spawn)(l,[["-loglevel","error"],["-avioflags","direct"],["-fpsprobesize","0","-probesize","32","-analyzeduration","0","-fflags","nobuffer"],["-framerate",`${p}`,"-f","image2pipe","-vcodec","png","-i","pipe:0"],["-an"],["-threads","1"],["-b:v","0"],M,["-vf",B.join()],"pipe:1"].flat(),{stdio:["pipe","pipe","pipe"]}),this.#t.stdout.pipe(this),this.#t.stderr.on("data",k=>{this.#s?.(H.ffmpeg)?.(k.toString("utf8"))}),this.#e=s;let{client:D}=this.#e.mainFrame();D.once(mt.Disconnected,()=>{this.stop().catch(k=>{this.#s?.(H.error)?.(k)})});let O;this.#i=WL(xt(D,"Page.screencastFrame").pipe(Du(k=>{D.send("Page.screencastFrameAck",{sessionId:k.sessionId})}),Pn(k=>k.metadata.timestamp!==void 0),Wt(k=>({buffer:Buffer.from(k.data,"base64"),timestamp:k.metadata.timestamp})),GL(2,1),XL(([{timestamp:k,buffer:S},{timestamp:P}])=>(O??=k,Ye(Array(Sre(O,k,P,p)).fill(S)))),Wt(k=>(this.#a(k),[k,performance.now()])),fx(Pf(this.#r.signal,"abort"))),{defaultValue:[Buffer.from([]),performance.now()]})}#o(s,a,c,l,u,d){let f=[["-vcodec","vp9"],["-crf",`${u}`],["-deadline","realtime","-cpu-used",`${Math.min(mq.default.cpus().length/2,8)}`]];switch(s){case"webm":return[...f,["-f","webm"]].flat();case"gif":return a=pq===a?20:"source_fps",c===1/0&&(c=0),l!==-1&&(l/=10),[["-vf",`fps=${a},split[s0][s1];[s0]palettegen=stats_mode=diff:max_colors=${d}[p];[s1][p]paletteuse=dither=bayer`],["-loop",`${c}`],["-final_delay",`${l}`],["-f","gif"]].flat();case"mp4":return[...f,["-movflags","hybrid_fragmented"],["-f","mp4"]].flat()}}get#a(){return i.value}async stop(){if(this.#r.signal.aborted)return;await this.#e._stopScreencast().catch(c=>{this.#s?.(H.error)?.(c)}),this.#r.abort();let[s,a]=await this.#i;await Promise.all(Array(Math.max(1,Math.round(this.#n*(performance.now()-a)/1e3))).fill(s).map(this.#a.bind(this))),this.#t.stdin.end(),await new Promise(c=>{this.#t.once("close",c)})}async[(t=[oa()],n=[oa()],Et)](){await this.stop(),await super[Et]()}}})()});var wq=b(()=>{M3();L3();P3();$S();fq();bq();});var B3=b(()=>{CP();wq();});var xq,jUe,UUe,qUe,WUe,uy,N3=b(()=>{pL();B3();An();B3();lt.value.ScreenRecorder=yq;xq=new nD({isPuppeteerCore:!0}),{connect:jUe,defaultArgs:UUe,executablePath:qUe,launch:WUe}=xq,uy=xq});function vq(r,e){let t=(0,mo.readFileSync)(r),i=a=>new Error(`${r}: ${a}`),n=-1;for(let a=t.length-22;a>=Math.max(0,t.length-22-65535);a--)if(t.readUInt32LE(a)===Ere){n=a;break}if(n<0)throw i("not a zip file");let o=t.readUInt16LE(n+10),s=t.readUInt32LE(n+16);if((o===65535||s===sD)&&n>=20&&t.readUInt32LE(n-20)===Cre){let a=Number(t.readBigUInt64LE(n-12));if(t.readUInt32LE(a)!==kre)throw i("bad Zip64 record");o=Number(t.readBigUInt64LE(a+32)),s=Number(t.readBigUInt64LE(a+48))}(0,mo.mkdirSync)(e,{recursive:!0});for(let a=0,c=s;a<o;a++){if(t.readUInt32LE(c)!==Fre)throw i("bad central directory");let l=t.readUInt16LE(c+4),u=t.readUInt16LE(c+10),d=t.readUInt32LE(c+16),f=t.readUInt32LE(c+20),h=t.readUInt32LE(c+24),p=t.readUInt16LE(c+28),m=t.readUInt16LE(c+30),g=t.readUInt16LE(c+32),y=t.readUInt32LE(c+38),x=t.readUInt32LE(c+42),C=t.toString("utf8",c+46,c+46+p);for(let S=c+46+p;S<c+46+p+m;S+=4+t.readUInt16LE(S+2)){if(t.readUInt16LE(S)!==1)continue;let P=S+4,I=()=>Number(t.readBigUInt64LE((P+=8)-8));h===sD&&(h=I()),f===sD&&(f=I()),x===sD&&(x=I())}c+=46+p+m+g;let T=(0,Ss.normalize)(C);if((0,Ss.isAbsolute)(T)||T.split(/[\\/]/).includes(".."))throw i(`entry outside the archive: ${C}`);let B=(0,Ss.join)(e,T),M=l>>8===3?y>>>16:0,E=M&61440;if(C.endsWith("/")||E===16384){(0,mo.mkdirSync)(B,{recursive:!0});continue}if(t.readUInt32LE(x)!==Are)throw i(`bad local header: ${C}`);let D=x+30+t.readUInt16LE(x+26)+t.readUInt16LE(x+28),O=t.subarray(D,D+f),k=u===0?O:u===8?(0,aD.inflateRawSync)(O):null;if(!k)throw i(`compression method ${u}: ${C}`);if(k.length!==h||(0,aD.crc32)(k)!==d)throw i(`corrupt entry: ${C}`);if((0,mo.mkdirSync)((0,Ss.dirname)(B),{recursive:!0}),E===40960){(0,mo.symlinkSync)(k.toString("utf8"),B);continue}(0,mo.writeFileSync)(B,k),M&511&&Ss.sep==="/"&&(0,mo.chmodSync)(B,M&511)}}var mo,Ss,aD,Ere,Cre,kre,Fre,Are,sD,Sq=b(()=>{"use strict";mo=require("node:fs"),Ss=require("node:path"),aD=require("node:zlib"),Ere=101010256,Cre=117853008,kre=101075792,Fre=33639248,Are=67324752,sD=4294967295});var jo,go,ap=b(()=>{"use strict";jo="1.0.3",go="156.0.8078.73"});function Pre(){return JSON.parse((0,Ei.readFileSync)((0,vr.join)(Fq,"chromium.json"),"utf8"))}function U3(){let{platform:r,arch:e}=process;if(r==="linux"&&e==="x64")return"linux64";if(r==="linux"&&e==="arm64")return"linux-arm64";if(r==="darwin")return e==="arm64"?"mac-arm64":"mac-x64";if(r==="win32")return e==="ia32"?"win32":"win64";throw new Error(`No chrome-headless-shell build for ${r}-${e}`)}function Tre(r=go){return(0,vr.join)(Fq,".cache","chromium",r)}function j3(){try{return typeof require=="function"&&require("node:sea").isSea()}catch{return!1}}function lD(){return process.env.PDFKILN_CACHE_DIR?process.env.PDFKILN_CACHE_DIR:process.platform==="win32"?(0,vr.join)(process.env.LOCALAPPDATA??(0,vr.join)((0,cD.homedir)(),"AppData","Local"),"pdfkiln"):process.platform==="darwin"?(0,vr.join)((0,cD.homedir)(),"Library","Caches","pdfkiln"):(0,vr.join)(process.env.XDG_CACHE_HOME||(0,vr.join)((0,cD.homedir)(),".cache"),"pdfkiln")}function Rre(){if(process.env.PDFKILN_CHROMIUM)return process.env.PDFKILN_CHROMIUM;let r=(0,vr.join)(j3()?(0,vr.dirname)(process.execPath):kq,"chromium",_3()),e=(0,vr.join)(Tre(),`chrome-headless-shell-${U3()}`,_3());for(let i of[r,e])if((0,Ei.existsSync)(i))return i;let t=Ore();return(0,Ei.existsSync)(t)||!j3()?t:r}async function uD(){let r=Rre();if((0,Ei.existsSync)(r)||process.env.PDFKILN_CHROMIUM||j3())return r;let e=Pre(),t=U3(),i=e.archives[t];if(!i)throw new Error(`chromium.json has no archive for ${t}`);let n=`${e.source}/${e.version}/${t}/${i.file}`,o=(0,vr.join)(lD(),"chromium",e.version);process.stderr.write(`pdfkiln: first use, downloading Chromium ${e.version} (${Math.round(i.size/1e6)} MB) into ${o}
|
|
230
230
|
`),(0,Ei.mkdirSync)((0,vr.dirname)(o),{recursive:!0});let s=(0,Ei.mkdtempSync)((0,vr.join)((0,vr.dirname)(o),".download-"));try{let a=await fetch(n);if(!a.ok||!a.body)throw new Error(`${n}: HTTP ${a.status}`);let c=(0,vr.join)(s,i.file),l=(0,Dq.createHash)("sha256"),u=(0,Ei.createWriteStream)(c);for await(let f of Eq.Readable.fromWeb(a.body))l.update(f),u.write(f)||await new Promise(h=>u.once("drain",()=>h()));u.end(),await(0,Cq.finished)(u);let d=l.digest("hex");if(d!==i.sha256)throw new Error(`${n}: SHA-256 mismatch, expected ${i.sha256}, got ${d}`);vq(c,(0,vr.join)(s,"chromium"));try{(0,Ei.renameSync)((0,vr.join)(s,"chromium"),o)}catch(f){if(!(0,Ei.existsSync)(r))throw f}}finally{(0,Ei.rmSync)(s,{recursive:!0,force:!0})}return r}var Dq,Ei,cD,vr,Eq,Cq,Mre,kq,Fq,_3,Ore,q3=b(()=>{"use strict";Dq=require("node:crypto"),Ei=require("node:fs"),cD=require("node:os"),vr=require("node:path"),Eq=require("node:stream"),Cq=require("node:stream/promises");Sq();ap();Mre={},kq=typeof __dirname=="string"?__dirname:Mre.dirname,Fq=(0,vr.resolve)(kq,"..","..");_3=()=>process.platform==="win32"?"chrome-headless-shell.exe":"chrome-headless-shell";Ore=()=>(0,vr.join)(lD(),"chromium",go,`chrome-headless-shell-${U3()}`,_3())});function W3(r){return/as root without --no-sandbox/i.test(r)?"Chromium refuses to run as root with its sandbox on. Run the command as an unprivileged user (or pass --kiln-no-sandbox, not recommended).":/No usable sandbox|namespace|setuid sandbox|zygote/i.test(r)?"Chromium's sandbox could not start: unprivileged user namespaces are unavailable. On Ubuntu 23.10 and later, AppArmor restricts them: install an AppArmor profile for Chromium that allows userns (see the README), or enable kernel.unprivileged_userns_clone. --kiln-no-sandbox works around it, not recommended.":`Chromium did not start: ${r.split(`
|
|
231
231
|
`)[0]}`}function yo(r){try{(0,fy.rmSync)(r,{recursive:!0,force:!0,maxRetries:5,retryDelay:100})}catch{}}function dy(r){if(r)try{process.platform==="win32"?(0,Aq.execFileSync)("taskkill",["/pid",String(r),"/T","/F"],{stdio:"ignore"}):process.kill(-r,"SIGKILL")}catch{}}async function dD(r,e=1e4){let t=Date.now()+e;for(;;)try{(0,fy.rmSync)(r,{recursive:!0,force:!0});return}catch{if(Date.now()>t)return;await new Promise(i=>setTimeout(i,200))}}async function fD(r){let e;try{e=await uD()}catch(c){throw new Ki(`Chromium could not be downloaded: ${c instanceof Error?c.message:String(c)}`)}if(!(0,fy.existsSync)(e))throw new Ki(`Chromium is missing: ${e}`);let t=(0,Pq.join)(r.dir,"chromium"),i=[`--user-data-dir=${t}`,"--force-webrtc-ip-handling-policy=disable_non_proxied_udp","--webrtc-ip-handling-policy=disable_non_proxied_udp"];r.noSandbox&&i.push("--no-sandbox"),r.proxyServer&&i.push(`--proxy-server=${r.proxyServer}`),r.proxyBypassList&&i.push(`--proxy-bypass-list=${r.proxyBypassList}`);let n;try{n=await uy.launch({executablePath:e,headless:"shell",pipe:!0,args:i,env:{...process.env,...r.env},defaultViewport:null,handleSIGINT:!1,handleSIGTERM:!1,handleSIGHUP:!1,protocolTimeout:0})}catch(c){throw yo(t),new Ki(W3(c instanceof Error?c.message:String(c)))}let o=n.process()?.pid,s=!1,a={browser:n,profile:t,async close(){if(a.stopping)return a.stopping;s||(s=!0,process.platform==="win32"?(await Promise.race([n.close().catch(()=>{}),new Promise(c=>setTimeout(c,5e3))]),n.process()?.exitCode===null&&dy(o),await dD(t)):(n.disconnect().catch(()=>{}),dy(o),yo(t)))}};return a}function hD(r,e,t){if(!e)return()=>{};let i=setTimeout(()=>{dy(r.browser.process()?.pid),r.stopping=dD(r.profile).then(t)},e*1e3);return i.unref(),()=>clearTimeout(i)}var Aq,fy,Pq,Ki,Zc=b(()=>{"use strict";Aq=require("node:child_process"),fy=require("node:fs"),Pq=require("node:path");N3();q3();Ki=class extends Error{}});function cp(r){switch(r){case 401:return 204;case 403:return 202;case 404:return 203;case 405:return 202;case 407:return 105;case 418:return 302;default:return r>500?301:r>=400?299:399}}function Tq(r){let e=r.replace(/^net::/,"");return e==="ERR_NAME_NOT_RESOLVED"||e==="ERR_NAME_RESOLUTION_FAILED"||e==="ERR_ADDRESS_INVALID"?3:e==="ERR_CONNECTION_REFUSED"?1:e==="ERR_CONNECTION_CLOSED"||e==="ERR_CONNECTION_RESET"||e==="ERR_EMPTY_RESPONSE"?2:e==="ERR_TIMED_OUT"||e==="ERR_CONNECTION_TIMED_OUT"?4:e==="ERR_ABORTED"?5:e.startsWith("ERR_SSL")||e.startsWith("ERR_CERT")?6:e==="ERR_INTERNET_DISCONNECTED"||e==="ERR_NETWORK_CHANGED"?7:e==="ERR_PROXY_CONNECTION_FAILED"?101:e==="ERR_TUNNEL_CONNECTION_FAILED"?102:e==="ERR_FILE_NOT_FOUND"?203:e==="ERR_ACCESS_DENIED"||e==="ERR_BLOCKED_BY_CLIENT"?201:e==="ERR_UNKNOWN_URL_SCHEME"||e==="ERR_DISALLOWED_URL_SCHEME"?301:99}function fd(r,e,t,i){let n=(()=>{try{return new URL(e).hostname}catch{return""}})();switch(r){case 1:return"Connection refused";case 2:return"Connection closed";case 3:return`Host ${n} not found`;case 4:return"Socket operation timed out";case 6:return"SSL handshake failed";case 204:return"Host requires authentication";case 301:return`Protocol "${e.split(":")[0]??""}" is unknown`;default:return t?`Error downloading ${e} - server replied: ${i}`:"Unknown error"}}function Oq(r,e){if(e){let t=e===404?2:e===401?3:1;return e<1e3?{code:t,line:`Exit with code ${t} due to http error: ${e} ${Lre[e]??""}`}:{code:t,line:`Exit with code ${t} due to network error: ${Ire[e-1e3]??""}`}}return r?{code:0}:{code:1,line:"Exit with code 1, due to unknown error."}}var Ire,Lre,z3=b(()=>{"use strict";Ire={0:"NoError",1:"ConnectionRefusedError",2:"RemoteHostClosedError",3:"HostNotFoundError",4:"TimeoutError",5:"OperationCanceledError",6:"SslHandshakeFailedError",7:"TemporaryNetworkFailureError",99:"UnknownNetworkError",101:"ProxyConnectionRefusedError",102:"ProxyConnectionClosedError",103:"ProxyNotFoundError",104:"ProxyTimeoutError",105:"ProxyAuthenticationRequiredError",199:"UnknownProxyError",201:"ContentAccessDenied",202:"ContentOperationNotPermittedError",203:"ContentNotFoundError",204:"AuthenticationRequiredError",205:"ContentReSendError",299:"UnknownContentError",301:"ProtocolUnknownError",302:"ProtocolInvalidOperationError",399:"ProtocolFailure"};Lre={400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Page not found",405:"Method Not Allowed",500:"Internal Server Error",501:"Not Implemented",503:"Service Unavailable",505:"HTTP Version Not Supported"}});function Nre(r){return r.replace(/(^|[\s,(])screen(?=$|[\s,)])/gi,"$1all").replace(/(^|[\s,(])print(?=$|[\s,)])/gi,`$1all and ${Rq}`)}function _re(r,e,t){return r.replace(/\(\s*(min-|max-)?(width|height)\s*:\s*(-?[0-9.]+)\s*(px|em|rem)?\s*\)/gi,(i,n,o,s,a)=>{let c=Number(s)*(a&&a.toLowerCase()!=="px"?16:1),l=o.toLowerCase()==="width"?e:t,u=(n??"").toLowerCase();return(u==="min-"?l>=c:u==="max-"?l<=c:l===c)?Bre:Rq})}function jre(r){let e="",t=0,i=/@page\b[^{;]*\{/gi;for(let n=i.exec(r);n;n=i.exec(r)){e+=r.slice(t,n.index);let o=1,s=n.index+n[0].length;for(;s<r.length&&o>0;s++)r[s]==="{"?o++:r[s]==="}"&&o--;t=s,i.lastIndex=s}return e+r.slice(t)}function Wre(r){return r.replace(Ure,"").replace(qre,"")}function pD(r,e){let t=e.webkit534Css?Wre(r):r;if(e.mediaViewport||e.screenTypes){let[i,n]=e.mediaViewport??[0,0];t=t.replace(/@media([^{;]+)\{/g,(o,s)=>{let a=e.mediaViewport?_re(s,i,n):s;return e.screenTypes&&(a=Nre(a)),`@media${a}{`})}return e.dropPageRules&&(t=jre(t)),t}function Mq(r){let e=(s,a,c)=>s.replace(/\(\s*(min-|max-)?(width|height)\s*:\s*(-?[0-9.]+)\s*(px|em|rem)?\s*\)/gi,(l,u,d,f,h)=>{let p=Number(f)*(h&&h.toLowerCase()!=="px"?16:1),m=d.toLowerCase()==="width"?a:c,g=(u??"").toLowerCase();return(g==="min-"?m>=p:g==="max-"?m<=p:m===p)?"(min-width: 0px)":"(min-width: 1000000px)"}),t=s=>s.replace(/(^|[\s,(])screen(?=$|[\s,)])/gi,"$1all").replace(/(^|[\s,(])print(?=$|[\s,)])/gi,"$1all and (min-width: 1000000px)"),i=(s,a,c)=>{let l=r.mediaViewport?e(s,a,c):s;return r.screenTypes&&(l=t(l)),l},n=document;if(r.webkit534Css){let s=a=>a.replace(/(?<=^|[;{\s])display\s*:\s*(?:-webkit-)?(?:inline-)?(?:flex|grid)\s*(?:!\s*important\s*)?(?:;\s*|(?=\}|$))/gi,"").replace(/(?<=^|[;{\s])(?!--)[a-z-]+\s*:[^;{}]*\b(?:-webkit-)?(?:calc|var)\([^;{}]*(?:;\s*|(?=\}|$))/gi,"");for(let a of Array.from(n.querySelectorAll("style"))){let c=s(a.textContent??"");c!==a.textContent&&(a.textContent=c)}for(let a of Array.from(n.querySelectorAll("[style]"))){let c=a.getAttribute("style")??"",l=s(c);l!==c&&a.setAttribute("style",l)}}if(r.mediaViewport||r.dropPageRules||r.screenTypes){let[s,a]=r.mediaViewport??[0,0],c=l=>{for(let u=l.length-1;u>=0;u--){let d=l[u];if(r.dropPageRules&&d instanceof CSSPageRule){let f=d.parentRule;f?f.deleteRule(u):d.parentStyleSheet?.deleteRule(u);continue}if((r.mediaViewport||r.screenTypes)&&(d instanceof CSSMediaRule||d instanceof CSSImportRule)){let f=i(d.media.mediaText,s,a);f!==d.media.mediaText&&(d.media.mediaText=f)}if(d instanceof CSSImportRule&&d.styleSheet)try{c(d.styleSheet.cssRules)}catch{}"cssRules"in d&&d.cssRules&&c(d.cssRules)}};for(let l of Array.from(n.styleSheets))try{c(l.cssRules)}catch{}if(r.mediaViewport||r.screenTypes)for(let l of Array.from(n.querySelectorAll("link[media], style[media]"))){let u=i(l.media,s,a);u!==l.media&&(l.media=u)}}if(r.roundFontSizes||r.minimumFontSize){let s=Array.from(n.querySelectorAll("body, body *")),a=s.map(c=>parseFloat(getComputedStyle(c).fontSize));s.forEach((c,l)=>{let u=a[l];r.minimumFontSize&&u<r.minimumFontSize&&(u=r.minimumFontSize),r.roundFontSizes&&(u=Math.round(u)),Math.abs(u-a[l])>.001&&c.style.setProperty("font-size",`${u}px`,"important")})}let o=s=>Math.trunc(s+(s<0?-.01:.01));if(r.wholePixelLineHeights||r.normalLineHeight){let s=Array.from(n.querySelectorAll("body, body *")),a=new Map,c=r.normalLineHeight?n.createElement("canvas").getContext("2d"):null,l=d=>{let f=`${d.fontStyle} ${d.fontWeight} ${d.fontFamily}`,h=a.get(f);if(!h){c.font=`${d.fontStyle} ${d.fontWeight} 1000px ${d.fontFamily}`;let p=c.measureText("x");h=[p.fontBoundingBoxAscent/1e3,p.fontBoundingBoxDescent/1e3],a.set(f,h)}return h},u=s.map(d=>{let f=getComputedStyle(d),h=parseFloat(f.fontSize);if(f.lineHeight==="normal"){if(!r.normalLineHeight||!c)return null;let[m,g]=l(f);return Math.ceil(m*h-.001)+Math.ceil(g*h-.001)}if(!r.wholePixelLineHeights)return null;let p=d.computedStyleMap?.().get("line-height");return p?.unit==="number"?Math.trunc(Math.round(h)*p.value+1e-6):p?.unit==="percent"?Math.trunc(Math.round(h)*p.value/100+1e-6):o(parseFloat(f.lineHeight))});s.forEach((d,f)=>{let h=u[f];h!=null&&d.style.setProperty("line-height",`${h}px`,"important")})}if(r.wholePixelBoxes){let s=["margin-top","margin-bottom","margin-left","margin-right","padding-top","padding-bottom","padding-left","padding-right","text-indent"],a=Array.from(n.querySelectorAll("body, body *")),c=a.map(l=>{let u=getComputedStyle(l);return s.map(d=>parseFloat(u.getPropertyValue(d)))});a.forEach((l,u)=>{s.forEach((d,f)=>{let h=c[u][f];Number.isFinite(h)&&Math.abs(h-o(h))>.001&&l.style.setProperty(d,`${o(h)}px`,"important")})})}if(r.truncateTopMargin&&n.body){let s=n.documentElement,a=getComputedStyle(s),c=s.getBoundingClientRect().top+parseFloat(a.borderTopWidth)+parseFloat(a.paddingTop),l=n.body.getBoundingClientRect().top-c;l>0&&s.style.setProperty("margin-top",`${-l}px`,"important")}if(r.pageTopMargins&&n.body){let s=l=>Math.abs(l.getBoundingClientRect().top+window.scrollY)<.01,a=l=>!parseFloat(l.paddingTop)&&!parseFloat(l.borderTopWidth)&&(l.display!=="table"||l.borderCollapse==="collapse"||!parseFloat(l.borderSpacing.split(" ").pop())),c=l=>{let u=[],d;for(let f of Array.from(l.childNodes)){if(f.nodeType===Node.TEXT_NODE){if(f.textContent?.trim())break;continue}if(!(f instanceof HTMLElement))continue;let h=getComputedStyle(f);if(h.display!=="none"){if(h.cssFloat!=="none"||h.position==="absolute"||h.position==="fixed"){u.push(f);continue}if(h.display.startsWith("inline"))break;if(h.display==="table-row-group"||h.display==="table-header-group"||h.display==="table-row"){c(f);break}if(h.display==="table-cell"){for(let p of Array.from(l.children))a(getComputedStyle(p))&&c(p);break}d=f;break}}d&&(parseFloat(getComputedStyle(d).marginTop)>0&&d.style.setProperty("margin-top","0px","important"),a(getComputedStyle(d))&&c(d));for(let f of u)s(f)&&a(getComputedStyle(f))&&c(f)};c(n.body)}if(r.grayscale&&n.documentElement.style.setProperty("filter","grayscale(100%)","important"),r.noDefaultWidows||r.unsplitRows){let s=n.createElement("style");s.textContent=`@layer pdfkiln-defaults { ${r.noDefaultWidows?"html { orphans: 1; widows: 1 }":""} ${r.unsplitRows?"tr { break-inside: avoid }":""} }`,(n.head??n.documentElement).prepend(s)}if(r.noShrinkToFit&&n.body){let s=a=>{let c=getComputedStyle(a);return c.overflowX==="visible"&&c.overflowY==="visible"};if(s(n.documentElement)&&s(n.body))for(let a of[n.documentElement,n.body])a.style.setProperty("overflow-x","clip","important")}}var Bre,Rq,Ure,qre,Iq=b(()=>{"use strict";Bre="(min-width: 0px)",Rq="(min-width: 1000000px)";Ure=/(?<=^|[;{\s])display\s*:\s*(?:-webkit-)?(?:inline-)?(?:flex|grid)\s*(?:!\s*important\s*)?(?:;\s*|(?=\}|$))/gi,qre=/(?<=^|[;{\s])(?!--)[a-z-]+\s*:[^;{}]*\b(?:-webkit-)?(?:calc|var)\([^;{}]*(?:;\s*|(?=\}|$))/gi});function mD(r){try{return Lq.realpathSync.native(r)}catch{return null}}function H3(r,e=""){let t=zre[(0,yD.extname)(r).toLowerCase()]??"application/octet-stream";return e&&t.startsWith("text/")?`${t}; charset=${e}`:t}function V3(r){try{return(0,Nq.fileURLToPath)(r)}catch{return null}}async function _q(r){try{return await(0,Bq.readFile)(r)}catch{return null}}var Lq,Bq,yD,Nq,gD,zre,jq=b(()=>{"use strict";Lq=require("node:fs"),Bq=require("node:fs/promises"),yD=require("node:path"),Nq=require("node:url");gD=class{constructor(e){this.block=e}block;allowed=new Set;allow(e){let t=mD(e);t&&this.allowed.add(t)}allows(e){if(!this.block)return!0;let t=mD(e);t||(t=e);for(let i="";t!==i;i=t,t=(0,yD.dirname)(t))if(this.allowed.has(t))return!0;return!1}},zre={".html":"text/html",".htm":"text/html",".xhtml":"application/xhtml+xml",".svg":"image/svg+xml",".css":"text/css",".js":"text/javascript",".mjs":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".bmp":"image/bmp",".ico":"image/x-icon",".avif":"image/avif",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject",".txt":"text/plain",".xml":"text/xml",".pdf":"application/pdf"}});function Uq(r){return r.split(".").map(Number)}function Hq(r){if((0,$c.isIP)(r)===4){let[e,t]=Uq(r);return e===0||e===10||e===127||e>=224||e===100&&t>=64&&t<=127||e===169&&t===254||e===172&&t>=16&&t<=31||e===192&&t===168||e===192&&t===0&&Uq(r)[2]===0||e===198&&(t===18||t===19)}if((0,$c.isIP)(r)===6){let e=r.toLowerCase(),t=/^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(e)??/^64:ff9b::(\d+\.\d+\.\d+\.\d+)$/.exec(e);if(t)return Hq(t[1]);if(e==="::"||e==="::1")return!0;let i=parseInt(e.split(":")[0]||"0",16);return(i&65024)===64512||(i&65472)===65152||(i&65280)===65280}return!0}async function Vq(r,e){let t=r.replace(/^\[|\]$/g,""),i=(0,$c.isIP)(t)?[{address:t,family:(0,$c.isIP)(t)}]:await(0,Wq.lookup)(t,{all:!0});if(!e)return i;if(!i.length||i.some(n=>Hq(n.address)))throw new ka(`Blocked access to private address of ${t}`);return i}async function qq(r,e){return(await Vq(r,e))[0]}async function bD(){let r=[],e=new Set,t=(0,hy.createServer)(async(n,o)=>{let s;try{s=new URL(n.url??"")}catch{o.writeHead(400).end();return}try{let a=await qq(s.hostname,!0),c={...n.headers};delete c["proxy-connection"];let l=(0,hy.request)({host:a.address,family:a.family,port:s.port||80,method:n.method,path:s.pathname+s.search,headers:c},u=>{o.writeHead(u.statusCode??502,u.headers),u.pipe(o)});l.on("error",()=>o.destroy()),n.pipe(l)}catch(a){a instanceof ka&&r.push(s.hostname),o.writeHead(a instanceof ka?403:502).end()}});t.on("connection",n=>{e.add(n),n.on("close",()=>e.delete(n))}),t.on("connect",async(n,o,s)=>{let[a,c]=Vre(n.url??"");try{let l=await qq(a,!0),u=(0,$c.connect)({host:l.address,port:Number(c)||443},()=>{o.write(`HTTP/1.1 200 Connection Established\r
|
|
232
232
|
\r
|
|
@@ -226,7 +226,7 @@ You can also empty the whole browser cache with \`npx ${o} clear\` and then run
|
|
|
226
226
|
1. you did not perform an installation before running the script (e.g. \`npx puppeteer browsers install ${s}\`) or
|
|
227
227
|
2. your cache path is incorrectly configured (which is: ${i.cacheDirectory}).
|
|
228
228
|
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.`)}return n}},T3=new WeakMap});async function eD(r){await oq.default.promises.rm(r,bre)}var oq,bre,R3=b(()=>{oq=Ae(require("node:fs"),1);bre={force:!0,recursive:!0,maxRetries:10,retryDelay:100}});function sq(r,e=[]){let t=r.endsWith("=")?r:`${r}=`;return e.filter(i=>i.startsWith(t)).flatMap(i=>i.substring(i.indexOf("=")+1).trim().split(",").map(n=>n.trim())).filter(i=>i)}function aq(r,e){let t=e.endsWith("=")?e:`${e}=`,i=0;for(;i<r.length;)r[i].startsWith(t)?r.splice(i,1):i++;return r}var cq,lq,tD,rD,M3=b(()=>{cq=require("node:fs/promises"),lq=Ae(require("node:os"),1),tD=Ae(require("node:path"),1);dd();je();Ct();$S();E3();R3();rD=class extends op{constructor(e,t){super(e,"chrome",t)}async launch(e={}){return(await this.puppeteer.configuration()).logLevel==="warn"&&process.platform==="darwin"&&process.arch==="x64"&&lq.default.cpus()[0]?.model.includes("Apple")&&console.warn(["\x1B[1m\x1B[43m\x1B[30m","Degraded performance warning:\x1B[0m\x1B[33m","Launching Chrome on Mac Silicon (arm64) from an x64 Node installation results in","Rosetta translating the Chrome binary, even if Chrome is already arm64. This would","result in huge performance issues. To resolve this, you must run Puppeteer with","a version of Node built for arm64."].join(`
|
|
229
|
-
`)),await super.launch(e)}async computeLaunchArguments(e={}){let{ignoreDefaultArgs:t=!1,args:i=[],pipe:n=!1,debuggingPort:o,channel:s,executablePath:a}=e,c=[];t?Array.isArray(t)?c.push(...this.defaultArgs(e).filter(h=>!t.includes(h))):c.push(...i):c.push(...this.defaultArgs(e)),c.some(h=>h.startsWith("--remote-debugging-"))||(n?(ee(!o,"Browser should be launched with either pipe or debugging port - not both."),c.push("--remote-debugging-pipe")):c.push(`--remote-debugging-port=${o||0}`));let l=!1,u=c.findIndex(h=>h.startsWith("--user-data-dir")),d;if(u<0){l=!0;let h=await this.getProfilePath();d=await(0,cq.mkdtemp)(h),c.push(`--user-data-dir=${d}`)}else{let h=c[u].split("=",2)[1];ee(typeof h=="string","`--user-data-dir` is malformed"),d=h}let f=a;return f||(ee(s||!this.puppeteer._isPuppeteerCore,"An `executablePath` or `channel` must be specified for `puppeteer-core`"),f=s?await this.executablePath(s):await this.resolveExecutablePath(e.headless??!0)),{executablePath:f,args:c,isTempUserDataDir:l,userDataDir:d}}async cleanUserDataDir(e,t){if(t.isTemp)try{await eD(e)}catch(i){this.logger(H.error)?.(i)}}defaultArgs(e={}){let t=sq("--disable-features",e.args);e.args&&t.length>0&&aq(e.args,"--disable-features");let i=process.env.PUPPETEER_TEST_EXPERIMENTAL_CHROME_FEATURES==="true",n=sq("--enable-features",e.args);e.args&&n.length>0&&aq(e.args,"--enable-features");let o=["PdfOopif",...n].filter(h=>h!==""),a=["--allow-pre-commit-input","--disable-background-networking","--disable-background-timer-throttling","--disable-backgrounding-occluded-windows","--disable-breakpad","--disable-client-side-phishing-detection","--disable-component-extensions-with-background-pages","--disable-crash-reporter","--disable-default-apps","--disable-dev-shm-usage","--disable-hang-monitor","--disable-infobars","--disable-ipc-flooding-protection","--disable-popup-blocking","--disable-prompt-on-repost","--disable-renderer-backgrounding","--disable-search-engine-choice-screen","--disable-sync","--enable-automation","--export-tagged-pdf","--force-color-profile=srgb","--generate-pdf-document-outline","--metrics-recording-only","--no-first-run","--password-store=basic","--use-mock-keychain",`--disable-features=${["Translate","AcceptCHFrame","MediaRouter","OptimizationHints","WebUIReloadButton","WebUIOmniboxPopup","WebUIOmniboxAimPopup",...i?[]:["ProcessPerSiteUpToMainFrameThreshold","IsolateSandboxedIframes"],...t].filter(h=>h!=="").filter(h=>!o.includes(h)).join(",")}`,`--enable-features=${o.join(",")}`].filter(h=>h!==""),{devtools:c=!1,headless:l=!c,args:u=[],userDataDir:d,enableExtensions:f=!1}=e;return process.env.PUPPETEER_DANGEROUS_NO_SANDBOX==="true"&&!u.includes("--no-sandbox")&&a.push("--no-sandbox"),d&&a.push(`--user-data-dir=${tD.default.posix.isAbsolute(d)||tD.default.win32.isAbsolute(d)?d:tD.default.resolve(d)}`),c&&a.push("--auto-open-devtools-for-tabs"),l&&a.push(l==="shell"?"--headless":"--headless=new","--hide-scrollbars","--mute-audio"),f||a.push("--disable-extensions"),u.every(h=>h.startsWith("-"))&&a.push("about:blank"),a.push(...u),a}async executablePath(e,t=!0){return e?Vh({browser:De.CHROME,channel:D3(e)},t):await this.resolveExecutablePath(void 0,t)}}});var uq,sp,dq,I3,iD,L3=b(()=>{uq=Ae(require("node:fs"),1),sp=require("node:fs/promises"),dq=Ae(require("node:os"),1),I3=Ae(require("node:path"),1);dd();je();Ct();$S();R3();iD=class r extends op{constructor(e,t){super(e,"firefox",t)}static getPreferences(e){return{...e,"fission.webContentIsolationStrategy":0}}async computeLaunchArguments(e={}){let{ignoreDefaultArgs:t=!1,args:i=[],executablePath:n,pipe:o=!1,extraPrefsFirefox:s={},debuggingPort:a=null}=e,c=[];t?Array.isArray(t)?c.push(...this.defaultArgs(e).filter(h=>!t.includes(h))):c.push(...i):c.push(...this.defaultArgs(e)),c.some(h=>h.startsWith("--remote-debugging-"))||(o&&ee(a===null,"Browser should be launched with either pipe or debugging port - not both."),c.push(`--remote-debugging-port=${a||0}`));let l,u=!0,d=c.findIndex(h=>["-profile","--profile"].includes(h));if(d!==-1){if(l=c[d+1],!l)throw new Error("Missing value for profile command line argument");u=!1}else{let h=await this.getProfilePath();l=await(0,sp.mkdtemp)(h),c.push("--profile"),c.push(l)}await J1(De.FIREFOX,{path:l,preferences:r.getPreferences(s)});let f;return this.puppeteer._isPuppeteerCore||n?(ee(n,"An `executablePath` must be specified for `puppeteer-core`"),f=n):f=await this.executablePath(void 0),{isTempUserDataDir:u,userDataDir:l,args:c,executablePath:f}}async cleanUserDataDir(e,t){if(t.isTemp)try{await eD(e)}catch(i){this.logger(H.error)?.(i)}else try{let i=".puppeteer",n=["prefs.js","user.js"],o=await Promise.allSettled(n.map(async s=>{let a=I3.default.join(e,s+i);if(uq.default.existsSync(a)){let c=I3.default.join(e,s);await(0,sp.unlink)(c),await(0,sp.rename)(a,c)}}));for(let s of o)if(s.status==="rejected")throw s.reason}catch(i){this.logger(H.error)?.(i)}}async executablePath(e,t=!0){return await this.resolveExecutablePath(void 0,t)}defaultArgs(e={}){let{devtools:t=!1,headless:i=!t,args:n=[],userDataDir:o=null}=e,s=[];switch(dq.default.platform()){case"darwin":s.push("--foreground");break;case"win32":s.push("--wait-for-browser");break}return o&&(s.push("--profile"),s.push(o)),i&&s.push("--headless"),t&&s.push("--devtools"),n.every(a=>a.startsWith("-"))&&s.push("about:blank"),s.push(...n),s}}});var nD,fq=b(()=>{dd();je();k3();An();A3();M3();L3();nD=class extends YS{#e;#t;configuration;constructor(e){let{configuration:t,...i}=e;super(i),t?this.configuration=t:this.configuration=()=>Promise.resolve({}),this.connect=this.connect.bind(this),this.launch=this.launch.bind(this),this.executablePath=this.executablePath.bind(this),this.defaultArgs=this.defaultArgs.bind(this),this.trimCache=this.trimCache.bind(this)}connect(e){return e.logger??=ta,super.connect(e)}async launch(e={}){e.logger??=ta;let{browser:t=await this.defaultBrowser()}=e;if(this.#t=t,!["chrome","firefox"].includes(t))throw new Error(`Unknown product: ${t}`);return this.#e=this.#r(t,e.logger),await this.#e.launch(e)}#r(e,t){if(this.#e&&this.#e.browser===e)return this.#e;switch(e){case"chrome":return new rD(this,t);case"firefox":return new iD(this,t);default:throw new Error(`Unknown product: ${e}`)}}async executablePath(e){return e===void 0?await this.#r(await this.lastLaunchedBrowser(),ta).executablePath(void 0,!1):typeof e=="string"?await this.#r("chrome",ta).executablePath(e,!1):await this.#r(e.browser??await this.lastLaunchedBrowser(),e.logger??ta).resolveExecutablePath(e.headless,!1)}async browserVersion(){let e=await this.configuration(),t=await this.lastLaunchedBrowser();return e?.[t]?.version??F3[t]}async defaultDownloadPath(){return(await this.configuration()).cacheDirectory}async lastLaunchedBrowser(){return this.#t??await this.defaultBrowser()}async defaultBrowser(){return(await this.configuration()).defaultBrowser??"chrome"}async defaultArgs(e={}){return this.#r(e.browser??await this.lastLaunchedBrowser(),e.logger??ta).defaultArgs(e)}async trimCache(){let e=Di();if(!e)throw new Error("The current platform is not supported.");let t=await this.configuration(),i=t.cacheDirectory,n=await bS({cacheDir:i}),o=[{product:"chrome",browser:De.CHROME,currentBuildId:""},{product:"firefox",browser:De.FIREFOX,currentBuildId:""}];await Promise.all(o.map(async c=>{let l=t?.[c.product]?.version??F3[c.product];c.currentBuildId=await zh(c.browser,e,l)}));let s=new Set(o.map(c=>`${c.browser}_${c.currentBuildId}`)),a=new Set(o.map(c=>c.browser));for(let c of n)a.has(c.browser)&&(s.has(`${c.browser}_${c.buildId}`)||await yS({browser:c.browser,platform:e,cacheDir:i,buildId:c.buildId}))}setFollowSymlinks(e){lt.value.followSymlinks=e}}});function Sre(r,e,t,i){let n=Math.round((t-r)*i),o=Math.round((e-r)*i);return Math.max(0,n-o)}var oD,mq,gq,wre,hq,xre,vre,pq,yq,bq=b(()=>{oD=require("node:child_process"),mq=Ae(require("node:os"),1),gq=require("node:stream");eo();Ii();je();Ot();pr();bt();wre=function(r,e,t){for(var i=arguments.length>2,n=0;n<e.length;n++)t=i?e[n].call(r,t):e[n].call(r);return i?t:void 0},hq=function(r,e,t,i,n,o){function s(y){if(y!==void 0&&typeof y!="function")throw new TypeError("Function expected");return y}for(var a=i.kind,c=a==="getter"?"get":a==="setter"?"set":"value",l=!e&&r?i.static?r:r.prototype:null,u=e||(l?Object.getOwnPropertyDescriptor(l,i.name):{}),d,f=!1,h=t.length-1;h>=0;h--){var p={};for(var m in i)p[m]=m==="access"?{}:i[m];for(var m in i.access)p.access[m]=i.access[m];p.addInitializer=function(y){if(f)throw new TypeError("Cannot add initializers after decoration has completed");o.push(s(y||null))};var g=(0,t[h])(a==="accessor"?{get:u.get,set:u.set}:u[c],p);if(a==="accessor"){if(g===void 0)continue;if(g===null||typeof g!="object")throw new TypeError("Object expected");(d=s(g.get))&&(u.get=d),(d=s(g.set))&&(u.set=d),(d=s(g.init))&&n.unshift(d)}else(d=s(g))&&(a==="field"?n.unshift(d):u[c]=d)}l&&Object.defineProperty(l,i.name,u),f=!0},xre=function(r,e,t){return typeof e=="symbol"&&(e=e.description?"[".concat(e.description,"]"):""),Object.defineProperty(r,"name",{configurable:!0,value:t?"".concat(t," ",e):e})},vre=30,pq=30;yq=(()=>{let r=gq.PassThrough,e=[],t,i,n;return class extends r{static{let s=typeof Symbol=="function"&&Symbol.metadata?Object.create(r[Symbol.metadata]??null):void 0;hq(this,i={value:xre(async function(a){let c=await new Promise(l=>{this.#t.stdin.write(a,l)});c&&console.log(`ffmpeg failed to write: ${c.message}.`)},"#writeFrame")},t,{kind:"method",name:"#writeFrame",static:!1,private:!0,access:{has:a=>#a in a,get:a=>a.#a},metadata:s},null,e),hq(this,null,n,{kind:"method",name:"stop",static:!1,private:!1,access:{has:a=>"stop"in a,get:a=>a.stop},metadata:s},null,e),s&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:s})}#e=wre(this,e);#t;#r=new AbortController;#i;#n;#s;constructor(s,a,c,{ffmpegPath:l,speed:u,scale:d,crop:f,format:h,fps:p,loop:m,delay:g,quality:y,colors:x}={},C){super({allowHalfOpen:!1}),this.#s=C,l??="ffmpeg",h??="webm",p??=pq,m||=-1,g??=-1,y??=vre,x??=256,this.#n=p;let{error:T}=(0,oD.spawnSync)(l);if(T)throw T;let B=[`crop='min(${a},iw):min(${c},ih):0:0'`,`pad=${a}:${c}:0:0`];u&&B.push(`setpts=${1/u}*PTS`),f&&B.push(`crop=${f.width}:${f.height}:${f.x}:${f.y}`),d&&B.push(`scale=iw*${d}:-1:flags=lanczos`);let M=this.#o(h,p,m,g,y,x),E=M.indexOf("-vf");E!==-1&&B.push(M.splice(E,2).at(-1)??""),this.#t=(0,oD.spawn)(l,[["-loglevel","error"],["-avioflags","direct"],["-fpsprobesize","0","-probesize","32","-analyzeduration","0","-fflags","nobuffer"],["-framerate",`${p}`,"-f","image2pipe","-vcodec","png","-i","pipe:0"],["-an"],["-threads","1"],["-b:v","0"],M,["-vf",B.join()],"pipe:1"].flat(),{stdio:["pipe","pipe","pipe"]}),this.#t.stdout.pipe(this),this.#t.stderr.on("data",k=>{this.#s?.(H.ffmpeg)?.(k.toString("utf8"))}),this.#e=s;let{client:D}=this.#e.mainFrame();D.once(mt.Disconnected,()=>{this.stop().catch(k=>{this.#s?.(H.error)?.(k)})});let O;this.#i=WL(xt(D,"Page.screencastFrame").pipe(Du(k=>{D.send("Page.screencastFrameAck",{sessionId:k.sessionId})}),Pn(k=>k.metadata.timestamp!==void 0),Wt(k=>({buffer:Buffer.from(k.data,"base64"),timestamp:k.metadata.timestamp})),GL(2,1),XL(([{timestamp:k,buffer:S},{timestamp:P}])=>(O??=k,Ye(Array(Sre(O,k,P,p)).fill(S)))),Wt(k=>(this.#a(k),[k,performance.now()])),fx(Pf(this.#r.signal,"abort"))),{defaultValue:[Buffer.from([]),performance.now()]})}#o(s,a,c,l,u,d){let f=[["-vcodec","vp9"],["-crf",`${u}`],["-deadline","realtime","-cpu-used",`${Math.min(mq.default.cpus().length/2,8)}`]];switch(s){case"webm":return[...f,["-f","webm"]].flat();case"gif":return a=pq===a?20:"source_fps",c===1/0&&(c=0),l!==-1&&(l/=10),[["-vf",`fps=${a},split[s0][s1];[s0]palettegen=stats_mode=diff:max_colors=${d}[p];[s1][p]paletteuse=dither=bayer`],["-loop",`${c}`],["-final_delay",`${l}`],["-f","gif"]].flat();case"mp4":return[...f,["-movflags","hybrid_fragmented"],["-f","mp4"]].flat()}}get#a(){return i.value}async stop(){if(this.#r.signal.aborted)return;await this.#e._stopScreencast().catch(c=>{this.#s?.(H.error)?.(c)}),this.#r.abort();let[s,a]=await this.#i;await Promise.all(Array(Math.max(1,Math.round(this.#n*(performance.now()-a)/1e3))).fill(s).map(this.#a.bind(this))),this.#t.stdin.end(),await new Promise(c=>{this.#t.once("close",c)})}async[(t=[oa()],n=[oa()],Et)](){await this.stop(),await super[Et]()}}})()});var wq=b(()=>{M3();L3();P3();$S();fq();bq();});var B3=b(()=>{CP();wq();});var xq,jUe,UUe,qUe,WUe,uy,N3=b(()=>{pL();B3();An();B3();lt.value.ScreenRecorder=yq;xq=new nD({isPuppeteerCore:!0}),{connect:jUe,defaultArgs:UUe,executablePath:qUe,launch:WUe}=xq,uy=xq});function vq(r,e){let t=(0,mo.readFileSync)(r),i=a=>new Error(`${r}: ${a}`),n=-1;for(let a=t.length-22;a>=Math.max(0,t.length-22-65535);a--)if(t.readUInt32LE(a)===Ere){n=a;break}if(n<0)throw i("not a zip file");let o=t.readUInt16LE(n+10),s=t.readUInt32LE(n+16);if((o===65535||s===sD)&&n>=20&&t.readUInt32LE(n-20)===Cre){let a=Number(t.readBigUInt64LE(n-12));if(t.readUInt32LE(a)!==kre)throw i("bad Zip64 record");o=Number(t.readBigUInt64LE(a+32)),s=Number(t.readBigUInt64LE(a+48))}(0,mo.mkdirSync)(e,{recursive:!0});for(let a=0,c=s;a<o;a++){if(t.readUInt32LE(c)!==Fre)throw i("bad central directory");let l=t.readUInt16LE(c+4),u=t.readUInt16LE(c+10),d=t.readUInt32LE(c+16),f=t.readUInt32LE(c+20),h=t.readUInt32LE(c+24),p=t.readUInt16LE(c+28),m=t.readUInt16LE(c+30),g=t.readUInt16LE(c+32),y=t.readUInt32LE(c+38),x=t.readUInt32LE(c+42),C=t.toString("utf8",c+46,c+46+p);for(let S=c+46+p;S<c+46+p+m;S+=4+t.readUInt16LE(S+2)){if(t.readUInt16LE(S)!==1)continue;let P=S+4,I=()=>Number(t.readBigUInt64LE((P+=8)-8));h===sD&&(h=I()),f===sD&&(f=I()),x===sD&&(x=I())}c+=46+p+m+g;let T=(0,Ss.normalize)(C);if((0,Ss.isAbsolute)(T)||T.split(/[\\/]/).includes(".."))throw i(`entry outside the archive: ${C}`);let B=(0,Ss.join)(e,T),M=l>>8===3?y>>>16:0,E=M&61440;if(C.endsWith("/")||E===16384){(0,mo.mkdirSync)(B,{recursive:!0});continue}if(t.readUInt32LE(x)!==Are)throw i(`bad local header: ${C}`);let D=x+30+t.readUInt16LE(x+26)+t.readUInt16LE(x+28),O=t.subarray(D,D+f),k=u===0?O:u===8?(0,aD.inflateRawSync)(O):null;if(!k)throw i(`compression method ${u}: ${C}`);if(k.length!==h||(0,aD.crc32)(k)!==d)throw i(`corrupt entry: ${C}`);if((0,mo.mkdirSync)((0,Ss.dirname)(B),{recursive:!0}),E===40960){(0,mo.symlinkSync)(k.toString("utf8"),B);continue}(0,mo.writeFileSync)(B,k),M&511&&Ss.sep==="/"&&(0,mo.chmodSync)(B,M&511)}}var mo,Ss,aD,Ere,Cre,kre,Fre,Are,sD,Sq=b(()=>{"use strict";mo=require("node:fs"),Ss=require("node:path"),aD=require("node:zlib"),Ere=101010256,Cre=117853008,kre=101075792,Fre=33639248,Are=67324752,sD=4294967295});var jo,go,ap=b(()=>{"use strict";jo="1.0.2",go="156.0.8078.47"});function Pre(){return JSON.parse((0,Ei.readFileSync)((0,vr.join)(Fq,"chromium.json"),"utf8"))}function U3(){let{platform:r,arch:e}=process;if(r==="linux"&&e==="x64")return"linux64";if(r==="linux"&&e==="arm64")return"linux-arm64";if(r==="darwin")return e==="arm64"?"mac-arm64":"mac-x64";if(r==="win32")return e==="ia32"?"win32":"win64";throw new Error(`No chrome-headless-shell build for ${r}-${e}`)}function Tre(r=go){return(0,vr.join)(Fq,".cache","chromium",r)}function j3(){try{return typeof require=="function"&&require("node:sea").isSea()}catch{return!1}}function lD(){return process.env.PDFKILN_CACHE_DIR?process.env.PDFKILN_CACHE_DIR:process.platform==="win32"?(0,vr.join)(process.env.LOCALAPPDATA??(0,vr.join)((0,cD.homedir)(),"AppData","Local"),"pdfkiln"):process.platform==="darwin"?(0,vr.join)((0,cD.homedir)(),"Library","Caches","pdfkiln"):(0,vr.join)(process.env.XDG_CACHE_HOME||(0,vr.join)((0,cD.homedir)(),".cache"),"pdfkiln")}function Rre(){if(process.env.PDFKILN_CHROMIUM)return process.env.PDFKILN_CHROMIUM;let r=(0,vr.join)(j3()?(0,vr.dirname)(process.execPath):kq,"chromium",_3()),e=(0,vr.join)(Tre(),`chrome-headless-shell-${U3()}`,_3());for(let i of[r,e])if((0,Ei.existsSync)(i))return i;let t=Ore();return(0,Ei.existsSync)(t)||!j3()?t:r}async function uD(){let r=Rre();if((0,Ei.existsSync)(r)||process.env.PDFKILN_CHROMIUM||j3())return r;let e=Pre(),t=U3(),i=e.archives[t];if(!i)throw new Error(`chromium.json has no archive for ${t}`);let n=`${e.source}/${e.version}/${t}/${i.file}`,o=(0,vr.join)(lD(),"chromium",e.version);process.stderr.write(`pdfkiln: first use, downloading Chromium ${e.version} (${Math.round(i.size/1e6)} MB) into ${o}
|
|
229
|
+
`)),await super.launch(e)}async computeLaunchArguments(e={}){let{ignoreDefaultArgs:t=!1,args:i=[],pipe:n=!1,debuggingPort:o,channel:s,executablePath:a}=e,c=[];t?Array.isArray(t)?c.push(...this.defaultArgs(e).filter(h=>!t.includes(h))):c.push(...i):c.push(...this.defaultArgs(e)),c.some(h=>h.startsWith("--remote-debugging-"))||(n?(ee(!o,"Browser should be launched with either pipe or debugging port - not both."),c.push("--remote-debugging-pipe")):c.push(`--remote-debugging-port=${o||0}`));let l=!1,u=c.findIndex(h=>h.startsWith("--user-data-dir")),d;if(u<0){l=!0;let h=await this.getProfilePath();d=await(0,cq.mkdtemp)(h),c.push(`--user-data-dir=${d}`)}else{let h=c[u].split("=",2)[1];ee(typeof h=="string","`--user-data-dir` is malformed"),d=h}let f=a;return f||(ee(s||!this.puppeteer._isPuppeteerCore,"An `executablePath` or `channel` must be specified for `puppeteer-core`"),f=s?await this.executablePath(s):await this.resolveExecutablePath(e.headless??!0)),{executablePath:f,args:c,isTempUserDataDir:l,userDataDir:d}}async cleanUserDataDir(e,t){if(t.isTemp)try{await eD(e)}catch(i){this.logger(H.error)?.(i)}}defaultArgs(e={}){let t=sq("--disable-features",e.args);e.args&&t.length>0&&aq(e.args,"--disable-features");let i=process.env.PUPPETEER_TEST_EXPERIMENTAL_CHROME_FEATURES==="true",n=sq("--enable-features",e.args);e.args&&n.length>0&&aq(e.args,"--enable-features");let o=["PdfOopif",...n].filter(h=>h!==""),a=["--allow-pre-commit-input","--disable-background-networking","--disable-background-timer-throttling","--disable-backgrounding-occluded-windows","--disable-breakpad","--disable-client-side-phishing-detection","--disable-component-extensions-with-background-pages","--disable-crash-reporter","--disable-default-apps","--disable-dev-shm-usage","--disable-hang-monitor","--disable-infobars","--disable-ipc-flooding-protection","--disable-popup-blocking","--disable-prompt-on-repost","--disable-renderer-backgrounding","--disable-search-engine-choice-screen","--disable-sync","--enable-automation","--export-tagged-pdf","--force-color-profile=srgb","--generate-pdf-document-outline","--metrics-recording-only","--no-first-run","--password-store=basic","--use-mock-keychain",`--disable-features=${["Translate","AcceptCHFrame","MediaRouter","OptimizationHints","WebUIReloadButton","WebUIOmniboxPopup","WebUIOmniboxAimPopup",...i?[]:["ProcessPerSiteUpToMainFrameThreshold","IsolateSandboxedIframes"],...t].filter(h=>h!=="").filter(h=>!o.includes(h)).join(",")}`,`--enable-features=${o.join(",")}`].filter(h=>h!==""),{devtools:c=!1,headless:l=!c,args:u=[],userDataDir:d,enableExtensions:f=!1}=e;return process.env.PUPPETEER_DANGEROUS_NO_SANDBOX==="true"&&!u.includes("--no-sandbox")&&a.push("--no-sandbox"),d&&a.push(`--user-data-dir=${tD.default.posix.isAbsolute(d)||tD.default.win32.isAbsolute(d)?d:tD.default.resolve(d)}`),c&&a.push("--auto-open-devtools-for-tabs"),l&&a.push(l==="shell"?"--headless":"--headless=new","--hide-scrollbars","--mute-audio"),f||a.push("--disable-extensions"),u.every(h=>h.startsWith("-"))&&a.push("about:blank"),a.push(...u),a}async executablePath(e,t=!0){return e?Vh({browser:De.CHROME,channel:D3(e)},t):await this.resolveExecutablePath(void 0,t)}}});var uq,sp,dq,I3,iD,L3=b(()=>{uq=Ae(require("node:fs"),1),sp=require("node:fs/promises"),dq=Ae(require("node:os"),1),I3=Ae(require("node:path"),1);dd();je();Ct();$S();R3();iD=class r extends op{constructor(e,t){super(e,"firefox",t)}static getPreferences(e){return{...e,"fission.webContentIsolationStrategy":0}}async computeLaunchArguments(e={}){let{ignoreDefaultArgs:t=!1,args:i=[],executablePath:n,pipe:o=!1,extraPrefsFirefox:s={},debuggingPort:a=null}=e,c=[];t?Array.isArray(t)?c.push(...this.defaultArgs(e).filter(h=>!t.includes(h))):c.push(...i):c.push(...this.defaultArgs(e)),c.some(h=>h.startsWith("--remote-debugging-"))||(o&&ee(a===null,"Browser should be launched with either pipe or debugging port - not both."),c.push(`--remote-debugging-port=${a||0}`));let l,u=!0,d=c.findIndex(h=>["-profile","--profile"].includes(h));if(d!==-1){if(l=c[d+1],!l)throw new Error("Missing value for profile command line argument");u=!1}else{let h=await this.getProfilePath();l=await(0,sp.mkdtemp)(h),c.push("--profile"),c.push(l)}await J1(De.FIREFOX,{path:l,preferences:r.getPreferences(s)});let f;return this.puppeteer._isPuppeteerCore||n?(ee(n,"An `executablePath` must be specified for `puppeteer-core`"),f=n):f=await this.executablePath(void 0),{isTempUserDataDir:u,userDataDir:l,args:c,executablePath:f}}async cleanUserDataDir(e,t){if(t.isTemp)try{await eD(e)}catch(i){this.logger(H.error)?.(i)}else try{let i=".puppeteer",n=["prefs.js","user.js"],o=await Promise.allSettled(n.map(async s=>{let a=I3.default.join(e,s+i);if(uq.default.existsSync(a)){let c=I3.default.join(e,s);await(0,sp.unlink)(c),await(0,sp.rename)(a,c)}}));for(let s of o)if(s.status==="rejected")throw s.reason}catch(i){this.logger(H.error)?.(i)}}async executablePath(e,t=!0){return await this.resolveExecutablePath(void 0,t)}defaultArgs(e={}){let{devtools:t=!1,headless:i=!t,args:n=[],userDataDir:o=null}=e,s=[];switch(dq.default.platform()){case"darwin":s.push("--foreground");break;case"win32":s.push("--wait-for-browser");break}return o&&(s.push("--profile"),s.push(o)),i&&s.push("--headless"),t&&s.push("--devtools"),n.every(a=>a.startsWith("-"))&&s.push("about:blank"),s.push(...n),s}}});var nD,fq=b(()=>{dd();je();k3();An();A3();M3();L3();nD=class extends YS{#e;#t;configuration;constructor(e){let{configuration:t,...i}=e;super(i),t?this.configuration=t:this.configuration=()=>Promise.resolve({}),this.connect=this.connect.bind(this),this.launch=this.launch.bind(this),this.executablePath=this.executablePath.bind(this),this.defaultArgs=this.defaultArgs.bind(this),this.trimCache=this.trimCache.bind(this)}connect(e){return e.logger??=ta,super.connect(e)}async launch(e={}){e.logger??=ta;let{browser:t=await this.defaultBrowser()}=e;if(this.#t=t,!["chrome","firefox"].includes(t))throw new Error(`Unknown product: ${t}`);return this.#e=this.#r(t,e.logger),await this.#e.launch(e)}#r(e,t){if(this.#e&&this.#e.browser===e)return this.#e;switch(e){case"chrome":return new rD(this,t);case"firefox":return new iD(this,t);default:throw new Error(`Unknown product: ${e}`)}}async executablePath(e){return e===void 0?await this.#r(await this.lastLaunchedBrowser(),ta).executablePath(void 0,!1):typeof e=="string"?await this.#r("chrome",ta).executablePath(e,!1):await this.#r(e.browser??await this.lastLaunchedBrowser(),e.logger??ta).resolveExecutablePath(e.headless,!1)}async browserVersion(){let e=await this.configuration(),t=await this.lastLaunchedBrowser();return e?.[t]?.version??F3[t]}async defaultDownloadPath(){return(await this.configuration()).cacheDirectory}async lastLaunchedBrowser(){return this.#t??await this.defaultBrowser()}async defaultBrowser(){return(await this.configuration()).defaultBrowser??"chrome"}async defaultArgs(e={}){return this.#r(e.browser??await this.lastLaunchedBrowser(),e.logger??ta).defaultArgs(e)}async trimCache(){let e=Di();if(!e)throw new Error("The current platform is not supported.");let t=await this.configuration(),i=t.cacheDirectory,n=await bS({cacheDir:i}),o=[{product:"chrome",browser:De.CHROME,currentBuildId:""},{product:"firefox",browser:De.FIREFOX,currentBuildId:""}];await Promise.all(o.map(async c=>{let l=t?.[c.product]?.version??F3[c.product];c.currentBuildId=await zh(c.browser,e,l)}));let s=new Set(o.map(c=>`${c.browser}_${c.currentBuildId}`)),a=new Set(o.map(c=>c.browser));for(let c of n)a.has(c.browser)&&(s.has(`${c.browser}_${c.buildId}`)||await yS({browser:c.browser,platform:e,cacheDir:i,buildId:c.buildId}))}setFollowSymlinks(e){lt.value.followSymlinks=e}}});function Sre(r,e,t,i){let n=Math.round((t-r)*i),o=Math.round((e-r)*i);return Math.max(0,n-o)}var oD,mq,gq,wre,hq,xre,vre,pq,yq,bq=b(()=>{oD=require("node:child_process"),mq=Ae(require("node:os"),1),gq=require("node:stream");eo();Ii();je();Ot();pr();bt();wre=function(r,e,t){for(var i=arguments.length>2,n=0;n<e.length;n++)t=i?e[n].call(r,t):e[n].call(r);return i?t:void 0},hq=function(r,e,t,i,n,o){function s(y){if(y!==void 0&&typeof y!="function")throw new TypeError("Function expected");return y}for(var a=i.kind,c=a==="getter"?"get":a==="setter"?"set":"value",l=!e&&r?i.static?r:r.prototype:null,u=e||(l?Object.getOwnPropertyDescriptor(l,i.name):{}),d,f=!1,h=t.length-1;h>=0;h--){var p={};for(var m in i)p[m]=m==="access"?{}:i[m];for(var m in i.access)p.access[m]=i.access[m];p.addInitializer=function(y){if(f)throw new TypeError("Cannot add initializers after decoration has completed");o.push(s(y||null))};var g=(0,t[h])(a==="accessor"?{get:u.get,set:u.set}:u[c],p);if(a==="accessor"){if(g===void 0)continue;if(g===null||typeof g!="object")throw new TypeError("Object expected");(d=s(g.get))&&(u.get=d),(d=s(g.set))&&(u.set=d),(d=s(g.init))&&n.unshift(d)}else(d=s(g))&&(a==="field"?n.unshift(d):u[c]=d)}l&&Object.defineProperty(l,i.name,u),f=!0},xre=function(r,e,t){return typeof e=="symbol"&&(e=e.description?"[".concat(e.description,"]"):""),Object.defineProperty(r,"name",{configurable:!0,value:t?"".concat(t," ",e):e})},vre=30,pq=30;yq=(()=>{let r=gq.PassThrough,e=[],t,i,n;return class extends r{static{let s=typeof Symbol=="function"&&Symbol.metadata?Object.create(r[Symbol.metadata]??null):void 0;hq(this,i={value:xre(async function(a){let c=await new Promise(l=>{this.#t.stdin.write(a,l)});c&&console.log(`ffmpeg failed to write: ${c.message}.`)},"#writeFrame")},t,{kind:"method",name:"#writeFrame",static:!1,private:!0,access:{has:a=>#a in a,get:a=>a.#a},metadata:s},null,e),hq(this,null,n,{kind:"method",name:"stop",static:!1,private:!1,access:{has:a=>"stop"in a,get:a=>a.stop},metadata:s},null,e),s&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:s})}#e=wre(this,e);#t;#r=new AbortController;#i;#n;#s;constructor(s,a,c,{ffmpegPath:l,speed:u,scale:d,crop:f,format:h,fps:p,loop:m,delay:g,quality:y,colors:x}={},C){super({allowHalfOpen:!1}),this.#s=C,l??="ffmpeg",h??="webm",p??=pq,m||=-1,g??=-1,y??=vre,x??=256,this.#n=p;let{error:T}=(0,oD.spawnSync)(l);if(T)throw T;let B=[`crop='min(${a},iw):min(${c},ih):0:0'`,`pad=${a}:${c}:0:0`];u&&B.push(`setpts=${1/u}*PTS`),f&&B.push(`crop=${f.width}:${f.height}:${f.x}:${f.y}`),d&&B.push(`scale=iw*${d}:-1:flags=lanczos`);let M=this.#o(h,p,m,g,y,x),E=M.indexOf("-vf");E!==-1&&B.push(M.splice(E,2).at(-1)??""),this.#t=(0,oD.spawn)(l,[["-loglevel","error"],["-avioflags","direct"],["-fpsprobesize","0","-probesize","32","-analyzeduration","0","-fflags","nobuffer"],["-framerate",`${p}`,"-f","image2pipe","-vcodec","png","-i","pipe:0"],["-an"],["-threads","1"],["-b:v","0"],M,["-vf",B.join()],"pipe:1"].flat(),{stdio:["pipe","pipe","pipe"]}),this.#t.stdout.pipe(this),this.#t.stderr.on("data",k=>{this.#s?.(H.ffmpeg)?.(k.toString("utf8"))}),this.#e=s;let{client:D}=this.#e.mainFrame();D.once(mt.Disconnected,()=>{this.stop().catch(k=>{this.#s?.(H.error)?.(k)})});let O;this.#i=WL(xt(D,"Page.screencastFrame").pipe(Du(k=>{D.send("Page.screencastFrameAck",{sessionId:k.sessionId})}),Pn(k=>k.metadata.timestamp!==void 0),Wt(k=>({buffer:Buffer.from(k.data,"base64"),timestamp:k.metadata.timestamp})),GL(2,1),XL(([{timestamp:k,buffer:S},{timestamp:P}])=>(O??=k,Ye(Array(Sre(O,k,P,p)).fill(S)))),Wt(k=>(this.#a(k),[k,performance.now()])),fx(Pf(this.#r.signal,"abort"))),{defaultValue:[Buffer.from([]),performance.now()]})}#o(s,a,c,l,u,d){let f=[["-vcodec","vp9"],["-crf",`${u}`],["-deadline","realtime","-cpu-used",`${Math.min(mq.default.cpus().length/2,8)}`]];switch(s){case"webm":return[...f,["-f","webm"]].flat();case"gif":return a=pq===a?20:"source_fps",c===1/0&&(c=0),l!==-1&&(l/=10),[["-vf",`fps=${a},split[s0][s1];[s0]palettegen=stats_mode=diff:max_colors=${d}[p];[s1][p]paletteuse=dither=bayer`],["-loop",`${c}`],["-final_delay",`${l}`],["-f","gif"]].flat();case"mp4":return[...f,["-movflags","hybrid_fragmented"],["-f","mp4"]].flat()}}get#a(){return i.value}async stop(){if(this.#r.signal.aborted)return;await this.#e._stopScreencast().catch(c=>{this.#s?.(H.error)?.(c)}),this.#r.abort();let[s,a]=await this.#i;await Promise.all(Array(Math.max(1,Math.round(this.#n*(performance.now()-a)/1e3))).fill(s).map(this.#a.bind(this))),this.#t.stdin.end(),await new Promise(c=>{this.#t.once("close",c)})}async[(t=[oa()],n=[oa()],Et)](){await this.stop(),await super[Et]()}}})()});var wq=b(()=>{M3();L3();P3();$S();fq();bq();});var B3=b(()=>{CP();wq();});var xq,jUe,UUe,qUe,WUe,uy,N3=b(()=>{pL();B3();An();B3();lt.value.ScreenRecorder=yq;xq=new nD({isPuppeteerCore:!0}),{connect:jUe,defaultArgs:UUe,executablePath:qUe,launch:WUe}=xq,uy=xq});function vq(r,e){let t=(0,mo.readFileSync)(r),i=a=>new Error(`${r}: ${a}`),n=-1;for(let a=t.length-22;a>=Math.max(0,t.length-22-65535);a--)if(t.readUInt32LE(a)===Ere){n=a;break}if(n<0)throw i("not a zip file");let o=t.readUInt16LE(n+10),s=t.readUInt32LE(n+16);if((o===65535||s===sD)&&n>=20&&t.readUInt32LE(n-20)===Cre){let a=Number(t.readBigUInt64LE(n-12));if(t.readUInt32LE(a)!==kre)throw i("bad Zip64 record");o=Number(t.readBigUInt64LE(a+32)),s=Number(t.readBigUInt64LE(a+48))}(0,mo.mkdirSync)(e,{recursive:!0});for(let a=0,c=s;a<o;a++){if(t.readUInt32LE(c)!==Fre)throw i("bad central directory");let l=t.readUInt16LE(c+4),u=t.readUInt16LE(c+10),d=t.readUInt32LE(c+16),f=t.readUInt32LE(c+20),h=t.readUInt32LE(c+24),p=t.readUInt16LE(c+28),m=t.readUInt16LE(c+30),g=t.readUInt16LE(c+32),y=t.readUInt32LE(c+38),x=t.readUInt32LE(c+42),C=t.toString("utf8",c+46,c+46+p);for(let S=c+46+p;S<c+46+p+m;S+=4+t.readUInt16LE(S+2)){if(t.readUInt16LE(S)!==1)continue;let P=S+4,I=()=>Number(t.readBigUInt64LE((P+=8)-8));h===sD&&(h=I()),f===sD&&(f=I()),x===sD&&(x=I())}c+=46+p+m+g;let T=(0,Ss.normalize)(C);if((0,Ss.isAbsolute)(T)||T.split(/[\\/]/).includes(".."))throw i(`entry outside the archive: ${C}`);let B=(0,Ss.join)(e,T),M=l>>8===3?y>>>16:0,E=M&61440;if(C.endsWith("/")||E===16384){(0,mo.mkdirSync)(B,{recursive:!0});continue}if(t.readUInt32LE(x)!==Are)throw i(`bad local header: ${C}`);let D=x+30+t.readUInt16LE(x+26)+t.readUInt16LE(x+28),O=t.subarray(D,D+f),k=u===0?O:u===8?(0,aD.inflateRawSync)(O):null;if(!k)throw i(`compression method ${u}: ${C}`);if(k.length!==h||(0,aD.crc32)(k)!==d)throw i(`corrupt entry: ${C}`);if((0,mo.mkdirSync)((0,Ss.dirname)(B),{recursive:!0}),E===40960){(0,mo.symlinkSync)(k.toString("utf8"),B);continue}(0,mo.writeFileSync)(B,k),M&511&&Ss.sep==="/"&&(0,mo.chmodSync)(B,M&511)}}var mo,Ss,aD,Ere,Cre,kre,Fre,Are,sD,Sq=b(()=>{"use strict";mo=require("node:fs"),Ss=require("node:path"),aD=require("node:zlib"),Ere=101010256,Cre=117853008,kre=101075792,Fre=33639248,Are=67324752,sD=4294967295});var jo,go,ap=b(()=>{"use strict";jo="1.0.3",go="156.0.8078.73"});function Pre(){return JSON.parse((0,Ei.readFileSync)((0,vr.join)(Fq,"chromium.json"),"utf8"))}function U3(){let{platform:r,arch:e}=process;if(r==="linux"&&e==="x64")return"linux64";if(r==="linux"&&e==="arm64")return"linux-arm64";if(r==="darwin")return e==="arm64"?"mac-arm64":"mac-x64";if(r==="win32")return e==="ia32"?"win32":"win64";throw new Error(`No chrome-headless-shell build for ${r}-${e}`)}function Tre(r=go){return(0,vr.join)(Fq,".cache","chromium",r)}function j3(){try{return typeof require=="function"&&require("node:sea").isSea()}catch{return!1}}function lD(){return process.env.PDFKILN_CACHE_DIR?process.env.PDFKILN_CACHE_DIR:process.platform==="win32"?(0,vr.join)(process.env.LOCALAPPDATA??(0,vr.join)((0,cD.homedir)(),"AppData","Local"),"pdfkiln"):process.platform==="darwin"?(0,vr.join)((0,cD.homedir)(),"Library","Caches","pdfkiln"):(0,vr.join)(process.env.XDG_CACHE_HOME||(0,vr.join)((0,cD.homedir)(),".cache"),"pdfkiln")}function Rre(){if(process.env.PDFKILN_CHROMIUM)return process.env.PDFKILN_CHROMIUM;let r=(0,vr.join)(j3()?(0,vr.dirname)(process.execPath):kq,"chromium",_3()),e=(0,vr.join)(Tre(),`chrome-headless-shell-${U3()}`,_3());for(let i of[r,e])if((0,Ei.existsSync)(i))return i;let t=Ore();return(0,Ei.existsSync)(t)||!j3()?t:r}async function uD(){let r=Rre();if((0,Ei.existsSync)(r)||process.env.PDFKILN_CHROMIUM||j3())return r;let e=Pre(),t=U3(),i=e.archives[t];if(!i)throw new Error(`chromium.json has no archive for ${t}`);let n=`${e.source}/${e.version}/${t}/${i.file}`,o=(0,vr.join)(lD(),"chromium",e.version);process.stderr.write(`pdfkiln: first use, downloading Chromium ${e.version} (${Math.round(i.size/1e6)} MB) into ${o}
|
|
230
230
|
`),(0,Ei.mkdirSync)((0,vr.dirname)(o),{recursive:!0});let s=(0,Ei.mkdtempSync)((0,vr.join)((0,vr.dirname)(o),".download-"));try{let a=await fetch(n);if(!a.ok||!a.body)throw new Error(`${n}: HTTP ${a.status}`);let c=(0,vr.join)(s,i.file),l=(0,Dq.createHash)("sha256"),u=(0,Ei.createWriteStream)(c);for await(let f of Eq.Readable.fromWeb(a.body))l.update(f),u.write(f)||await new Promise(h=>u.once("drain",()=>h()));u.end(),await(0,Cq.finished)(u);let d=l.digest("hex");if(d!==i.sha256)throw new Error(`${n}: SHA-256 mismatch, expected ${i.sha256}, got ${d}`);vq(c,(0,vr.join)(s,"chromium"));try{(0,Ei.renameSync)((0,vr.join)(s,"chromium"),o)}catch(f){if(!(0,Ei.existsSync)(r))throw f}}finally{(0,Ei.rmSync)(s,{recursive:!0,force:!0})}return r}var Dq,Ei,cD,vr,Eq,Cq,Mre,kq,Fq,_3,Ore,q3=b(()=>{"use strict";Dq=require("node:crypto"),Ei=require("node:fs"),cD=require("node:os"),vr=require("node:path"),Eq=require("node:stream"),Cq=require("node:stream/promises");Sq();ap();Mre={},kq=typeof __dirname=="string"?__dirname:Mre.dirname,Fq=(0,vr.resolve)(kq,"..","..");_3=()=>process.platform==="win32"?"chrome-headless-shell.exe":"chrome-headless-shell";Ore=()=>(0,vr.join)(lD(),"chromium",go,`chrome-headless-shell-${U3()}`,_3())});function W3(r){return/as root without --no-sandbox/i.test(r)?"Chromium refuses to run as root with its sandbox on. Run the command as an unprivileged user (or pass --kiln-no-sandbox, not recommended).":/No usable sandbox|namespace|setuid sandbox|zygote/i.test(r)?"Chromium's sandbox could not start: unprivileged user namespaces are unavailable. On Ubuntu 23.10 and later, AppArmor restricts them: install an AppArmor profile for Chromium that allows userns (see the README), or enable kernel.unprivileged_userns_clone. --kiln-no-sandbox works around it, not recommended.":`Chromium did not start: ${r.split(`
|
|
231
231
|
`)[0]}`}function yo(r){try{(0,fy.rmSync)(r,{recursive:!0,force:!0,maxRetries:5,retryDelay:100})}catch{}}function dy(r){if(r)try{process.platform==="win32"?(0,Aq.execFileSync)("taskkill",["/pid",String(r),"/T","/F"],{stdio:"ignore"}):process.kill(-r,"SIGKILL")}catch{}}async function dD(r,e=1e4){let t=Date.now()+e;for(;;)try{(0,fy.rmSync)(r,{recursive:!0,force:!0});return}catch{if(Date.now()>t)return;await new Promise(i=>setTimeout(i,200))}}async function fD(r){let e;try{e=await uD()}catch(c){throw new Ki(`Chromium could not be downloaded: ${c instanceof Error?c.message:String(c)}`)}if(!(0,fy.existsSync)(e))throw new Ki(`Chromium is missing: ${e}`);let t=(0,Pq.join)(r.dir,"chromium"),i=[`--user-data-dir=${t}`,"--force-webrtc-ip-handling-policy=disable_non_proxied_udp","--webrtc-ip-handling-policy=disable_non_proxied_udp"];r.noSandbox&&i.push("--no-sandbox"),r.proxyServer&&i.push(`--proxy-server=${r.proxyServer}`),r.proxyBypassList&&i.push(`--proxy-bypass-list=${r.proxyBypassList}`);let n;try{n=await uy.launch({executablePath:e,headless:"shell",pipe:!0,args:i,env:{...process.env,...r.env},defaultViewport:null,handleSIGINT:!1,handleSIGTERM:!1,handleSIGHUP:!1,protocolTimeout:0})}catch(c){throw yo(t),new Ki(W3(c instanceof Error?c.message:String(c)))}let o=n.process()?.pid,s=!1,a={browser:n,profile:t,async close(){if(a.stopping)return a.stopping;s||(s=!0,process.platform==="win32"?(await Promise.race([n.close().catch(()=>{}),new Promise(c=>setTimeout(c,5e3))]),n.process()?.exitCode===null&&dy(o),await dD(t)):(n.disconnect().catch(()=>{}),dy(o),yo(t)))}};return a}function hD(r,e,t){if(!e)return()=>{};let i=setTimeout(()=>{dy(r.browser.process()?.pid),r.stopping=dD(r.profile).then(t)},e*1e3);return i.unref(),()=>clearTimeout(i)}var Aq,fy,Pq,Ki,Zc=b(()=>{"use strict";Aq=require("node:child_process"),fy=require("node:fs"),Pq=require("node:path");N3();q3();Ki=class extends Error{}});function cp(r){switch(r){case 401:return 204;case 403:return 202;case 404:return 203;case 405:return 202;case 407:return 105;case 418:return 302;default:return r>500?301:r>=400?299:399}}function Tq(r){let e=r.replace(/^net::/,"");return e==="ERR_NAME_NOT_RESOLVED"||e==="ERR_NAME_RESOLUTION_FAILED"||e==="ERR_ADDRESS_INVALID"?3:e==="ERR_CONNECTION_REFUSED"?1:e==="ERR_CONNECTION_CLOSED"||e==="ERR_CONNECTION_RESET"||e==="ERR_EMPTY_RESPONSE"?2:e==="ERR_TIMED_OUT"||e==="ERR_CONNECTION_TIMED_OUT"?4:e==="ERR_ABORTED"?5:e.startsWith("ERR_SSL")||e.startsWith("ERR_CERT")?6:e==="ERR_INTERNET_DISCONNECTED"||e==="ERR_NETWORK_CHANGED"?7:e==="ERR_PROXY_CONNECTION_FAILED"?101:e==="ERR_TUNNEL_CONNECTION_FAILED"?102:e==="ERR_FILE_NOT_FOUND"?203:e==="ERR_ACCESS_DENIED"||e==="ERR_BLOCKED_BY_CLIENT"?201:e==="ERR_UNKNOWN_URL_SCHEME"||e==="ERR_DISALLOWED_URL_SCHEME"?301:99}function fd(r,e,t,i){let n=(()=>{try{return new URL(e).hostname}catch{return""}})();switch(r){case 1:return"Connection refused";case 2:return"Connection closed";case 3:return`Host ${n} not found`;case 4:return"Socket operation timed out";case 6:return"SSL handshake failed";case 204:return"Host requires authentication";case 301:return`Protocol "${e.split(":")[0]??""}" is unknown`;default:return t?`Error downloading ${e} - server replied: ${i}`:"Unknown error"}}function Oq(r,e){if(e){let t=e===404?2:e===401?3:1;return e<1e3?{code:t,line:`Exit with code ${t} due to http error: ${e} ${Lre[e]??""}`}:{code:t,line:`Exit with code ${t} due to network error: ${Ire[e-1e3]??""}`}}return r?{code:0}:{code:1,line:"Exit with code 1, due to unknown error."}}var Ire,Lre,z3=b(()=>{"use strict";Ire={0:"NoError",1:"ConnectionRefusedError",2:"RemoteHostClosedError",3:"HostNotFoundError",4:"TimeoutError",5:"OperationCanceledError",6:"SslHandshakeFailedError",7:"TemporaryNetworkFailureError",99:"UnknownNetworkError",101:"ProxyConnectionRefusedError",102:"ProxyConnectionClosedError",103:"ProxyNotFoundError",104:"ProxyTimeoutError",105:"ProxyAuthenticationRequiredError",199:"UnknownProxyError",201:"ContentAccessDenied",202:"ContentOperationNotPermittedError",203:"ContentNotFoundError",204:"AuthenticationRequiredError",205:"ContentReSendError",299:"UnknownContentError",301:"ProtocolUnknownError",302:"ProtocolInvalidOperationError",399:"ProtocolFailure"};Lre={400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Page not found",405:"Method Not Allowed",500:"Internal Server Error",501:"Not Implemented",503:"Service Unavailable",505:"HTTP Version Not Supported"}});function Nre(r){return r.replace(/(^|[\s,(])screen(?=$|[\s,)])/gi,"$1all").replace(/(^|[\s,(])print(?=$|[\s,)])/gi,`$1all and ${Rq}`)}function _re(r,e,t){return r.replace(/\(\s*(min-|max-)?(width|height)\s*:\s*(-?[0-9.]+)\s*(px|em|rem)?\s*\)/gi,(i,n,o,s,a)=>{let c=Number(s)*(a&&a.toLowerCase()!=="px"?16:1),l=o.toLowerCase()==="width"?e:t,u=(n??"").toLowerCase();return(u==="min-"?l>=c:u==="max-"?l<=c:l===c)?Bre:Rq})}function jre(r){let e="",t=0,i=/@page\b[^{;]*\{/gi;for(let n=i.exec(r);n;n=i.exec(r)){e+=r.slice(t,n.index);let o=1,s=n.index+n[0].length;for(;s<r.length&&o>0;s++)r[s]==="{"?o++:r[s]==="}"&&o--;t=s,i.lastIndex=s}return e+r.slice(t)}function Wre(r){return r.replace(Ure,"").replace(qre,"")}function pD(r,e){let t=e.webkit534Css?Wre(r):r;if(e.mediaViewport||e.screenTypes){let[i,n]=e.mediaViewport??[0,0];t=t.replace(/@media([^{;]+)\{/g,(o,s)=>{let a=e.mediaViewport?_re(s,i,n):s;return e.screenTypes&&(a=Nre(a)),`@media${a}{`})}return e.dropPageRules&&(t=jre(t)),t}function Mq(r){let e=(s,a,c)=>s.replace(/\(\s*(min-|max-)?(width|height)\s*:\s*(-?[0-9.]+)\s*(px|em|rem)?\s*\)/gi,(l,u,d,f,h)=>{let p=Number(f)*(h&&h.toLowerCase()!=="px"?16:1),m=d.toLowerCase()==="width"?a:c,g=(u??"").toLowerCase();return(g==="min-"?m>=p:g==="max-"?m<=p:m===p)?"(min-width: 0px)":"(min-width: 1000000px)"}),t=s=>s.replace(/(^|[\s,(])screen(?=$|[\s,)])/gi,"$1all").replace(/(^|[\s,(])print(?=$|[\s,)])/gi,"$1all and (min-width: 1000000px)"),i=(s,a,c)=>{let l=r.mediaViewport?e(s,a,c):s;return r.screenTypes&&(l=t(l)),l},n=document;if(r.webkit534Css){let s=a=>a.replace(/(?<=^|[;{\s])display\s*:\s*(?:-webkit-)?(?:inline-)?(?:flex|grid)\s*(?:!\s*important\s*)?(?:;\s*|(?=\}|$))/gi,"").replace(/(?<=^|[;{\s])(?!--)[a-z-]+\s*:[^;{}]*\b(?:-webkit-)?(?:calc|var)\([^;{}]*(?:;\s*|(?=\}|$))/gi,"");for(let a of Array.from(n.querySelectorAll("style"))){let c=s(a.textContent??"");c!==a.textContent&&(a.textContent=c)}for(let a of Array.from(n.querySelectorAll("[style]"))){let c=a.getAttribute("style")??"",l=s(c);l!==c&&a.setAttribute("style",l)}}if(r.mediaViewport||r.dropPageRules||r.screenTypes){let[s,a]=r.mediaViewport??[0,0],c=l=>{for(let u=l.length-1;u>=0;u--){let d=l[u];if(r.dropPageRules&&d instanceof CSSPageRule){let f=d.parentRule;f?f.deleteRule(u):d.parentStyleSheet?.deleteRule(u);continue}if((r.mediaViewport||r.screenTypes)&&(d instanceof CSSMediaRule||d instanceof CSSImportRule)){let f=i(d.media.mediaText,s,a);f!==d.media.mediaText&&(d.media.mediaText=f)}if(d instanceof CSSImportRule&&d.styleSheet)try{c(d.styleSheet.cssRules)}catch{}"cssRules"in d&&d.cssRules&&c(d.cssRules)}};for(let l of Array.from(n.styleSheets))try{c(l.cssRules)}catch{}if(r.mediaViewport||r.screenTypes)for(let l of Array.from(n.querySelectorAll("link[media], style[media]"))){let u=i(l.media,s,a);u!==l.media&&(l.media=u)}}if(r.roundFontSizes||r.minimumFontSize){let s=Array.from(n.querySelectorAll("body, body *")),a=s.map(c=>parseFloat(getComputedStyle(c).fontSize));s.forEach((c,l)=>{let u=a[l];r.minimumFontSize&&u<r.minimumFontSize&&(u=r.minimumFontSize),r.roundFontSizes&&(u=Math.round(u)),Math.abs(u-a[l])>.001&&c.style.setProperty("font-size",`${u}px`,"important")})}let o=s=>Math.trunc(s+(s<0?-.01:.01));if(r.wholePixelLineHeights||r.normalLineHeight){let s=Array.from(n.querySelectorAll("body, body *")),a=new Map,c=r.normalLineHeight?n.createElement("canvas").getContext("2d"):null,l=d=>{let f=`${d.fontStyle} ${d.fontWeight} ${d.fontFamily}`,h=a.get(f);if(!h){c.font=`${d.fontStyle} ${d.fontWeight} 1000px ${d.fontFamily}`;let p=c.measureText("x");h=[p.fontBoundingBoxAscent/1e3,p.fontBoundingBoxDescent/1e3],a.set(f,h)}return h},u=s.map(d=>{let f=getComputedStyle(d),h=parseFloat(f.fontSize);if(f.lineHeight==="normal"){if(!r.normalLineHeight||!c)return null;let[m,g]=l(f);return Math.ceil(m*h-.001)+Math.ceil(g*h-.001)}if(!r.wholePixelLineHeights)return null;let p=d.computedStyleMap?.().get("line-height");return p?.unit==="number"?Math.trunc(Math.round(h)*p.value+1e-6):p?.unit==="percent"?Math.trunc(Math.round(h)*p.value/100+1e-6):o(parseFloat(f.lineHeight))});s.forEach((d,f)=>{let h=u[f];h!=null&&d.style.setProperty("line-height",`${h}px`,"important")})}if(r.wholePixelBoxes){let s=["margin-top","margin-bottom","margin-left","margin-right","padding-top","padding-bottom","padding-left","padding-right","text-indent"],a=Array.from(n.querySelectorAll("body, body *")),c=a.map(l=>{let u=getComputedStyle(l);return s.map(d=>parseFloat(u.getPropertyValue(d)))});a.forEach((l,u)=>{s.forEach((d,f)=>{let h=c[u][f];Number.isFinite(h)&&Math.abs(h-o(h))>.001&&l.style.setProperty(d,`${o(h)}px`,"important")})})}if(r.truncateTopMargin&&n.body){let s=n.documentElement,a=getComputedStyle(s),c=s.getBoundingClientRect().top+parseFloat(a.borderTopWidth)+parseFloat(a.paddingTop),l=n.body.getBoundingClientRect().top-c;l>0&&s.style.setProperty("margin-top",`${-l}px`,"important")}if(r.pageTopMargins&&n.body){let s=l=>Math.abs(l.getBoundingClientRect().top+window.scrollY)<.01,a=l=>!parseFloat(l.paddingTop)&&!parseFloat(l.borderTopWidth)&&(l.display!=="table"||l.borderCollapse==="collapse"||!parseFloat(l.borderSpacing.split(" ").pop())),c=l=>{let u=[],d;for(let f of Array.from(l.childNodes)){if(f.nodeType===Node.TEXT_NODE){if(f.textContent?.trim())break;continue}if(!(f instanceof HTMLElement))continue;let h=getComputedStyle(f);if(h.display!=="none"){if(h.cssFloat!=="none"||h.position==="absolute"||h.position==="fixed"){u.push(f);continue}if(h.display.startsWith("inline"))break;if(h.display==="table-row-group"||h.display==="table-header-group"||h.display==="table-row"){c(f);break}if(h.display==="table-cell"){for(let p of Array.from(l.children))a(getComputedStyle(p))&&c(p);break}d=f;break}}d&&(parseFloat(getComputedStyle(d).marginTop)>0&&d.style.setProperty("margin-top","0px","important"),a(getComputedStyle(d))&&c(d));for(let f of u)s(f)&&a(getComputedStyle(f))&&c(f)};c(n.body)}if(r.grayscale&&n.documentElement.style.setProperty("filter","grayscale(100%)","important"),r.noDefaultWidows||r.unsplitRows){let s=n.createElement("style");s.textContent=`@layer pdfkiln-defaults { ${r.noDefaultWidows?"html { orphans: 1; widows: 1 }":""} ${r.unsplitRows?"tr { break-inside: avoid }":""} }`,(n.head??n.documentElement).prepend(s)}if(r.noShrinkToFit&&n.body){let s=a=>{let c=getComputedStyle(a);return c.overflowX==="visible"&&c.overflowY==="visible"};if(s(n.documentElement)&&s(n.body))for(let a of[n.documentElement,n.body])a.style.setProperty("overflow-x","clip","important")}}var Bre,Rq,Ure,qre,Iq=b(()=>{"use strict";Bre="(min-width: 0px)",Rq="(min-width: 1000000px)";Ure=/(?<=^|[;{\s])display\s*:\s*(?:-webkit-)?(?:inline-)?(?:flex|grid)\s*(?:!\s*important\s*)?(?:;\s*|(?=\}|$))/gi,qre=/(?<=^|[;{\s])(?!--)[a-z-]+\s*:[^;{}]*\b(?:-webkit-)?(?:calc|var)\([^;{}]*(?:;\s*|(?=\}|$))/gi});function mD(r){try{return Lq.realpathSync.native(r)}catch{return null}}function H3(r,e=""){let t=zre[(0,yD.extname)(r).toLowerCase()]??"application/octet-stream";return e&&t.startsWith("text/")?`${t}; charset=${e}`:t}function V3(r){try{return(0,Nq.fileURLToPath)(r)}catch{return null}}async function _q(r){try{return await(0,Bq.readFile)(r)}catch{return null}}var Lq,Bq,yD,Nq,gD,zre,jq=b(()=>{"use strict";Lq=require("node:fs"),Bq=require("node:fs/promises"),yD=require("node:path"),Nq=require("node:url");gD=class{constructor(e){this.block=e}block;allowed=new Set;allow(e){let t=mD(e);t&&this.allowed.add(t)}allows(e){if(!this.block)return!0;let t=mD(e);t||(t=e);for(let i="";t!==i;i=t,t=(0,yD.dirname)(t))if(this.allowed.has(t))return!0;return!1}},zre={".html":"text/html",".htm":"text/html",".xhtml":"application/xhtml+xml",".svg":"image/svg+xml",".css":"text/css",".js":"text/javascript",".mjs":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".bmp":"image/bmp",".ico":"image/x-icon",".avif":"image/avif",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject",".txt":"text/plain",".xml":"text/xml",".pdf":"application/pdf"}});function Uq(r){return r.split(".").map(Number)}function Hq(r){if((0,$c.isIP)(r)===4){let[e,t]=Uq(r);return e===0||e===10||e===127||e>=224||e===100&&t>=64&&t<=127||e===169&&t===254||e===172&&t>=16&&t<=31||e===192&&t===168||e===192&&t===0&&Uq(r)[2]===0||e===198&&(t===18||t===19)}if((0,$c.isIP)(r)===6){let e=r.toLowerCase(),t=/^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(e)??/^64:ff9b::(\d+\.\d+\.\d+\.\d+)$/.exec(e);if(t)return Hq(t[1]);if(e==="::"||e==="::1")return!0;let i=parseInt(e.split(":")[0]||"0",16);return(i&65024)===64512||(i&65472)===65152||(i&65280)===65280}return!0}async function Vq(r,e){let t=r.replace(/^\[|\]$/g,""),i=(0,$c.isIP)(t)?[{address:t,family:(0,$c.isIP)(t)}]:await(0,Wq.lookup)(t,{all:!0});if(!e)return i;if(!i.length||i.some(n=>Hq(n.address)))throw new ka(`Blocked access to private address of ${t}`);return i}async function qq(r,e){return(await Vq(r,e))[0]}async function bD(){let r=[],e=new Set,t=(0,hy.createServer)(async(n,o)=>{let s;try{s=new URL(n.url??"")}catch{o.writeHead(400).end();return}try{let a=await qq(s.hostname,!0),c={...n.headers};delete c["proxy-connection"];let l=(0,hy.request)({host:a.address,family:a.family,port:s.port||80,method:n.method,path:s.pathname+s.search,headers:c},u=>{o.writeHead(u.statusCode??502,u.headers),u.pipe(o)});l.on("error",()=>o.destroy()),n.pipe(l)}catch(a){a instanceof ka&&r.push(s.hostname),o.writeHead(a instanceof ka?403:502).end()}});t.on("connection",n=>{e.add(n),n.on("close",()=>e.delete(n))}),t.on("connect",async(n,o,s)=>{let[a,c]=Vre(n.url??"");try{let l=await qq(a,!0),u=(0,$c.connect)({host:l.address,port:Number(c)||443},()=>{o.write(`HTTP/1.1 200 Connection Established\r
|
|
232
232
|
\r
|