@hidemikimura/receipt-html-to-pdf 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  設計と経緯の詳細は docs/design.md。
4
4
 
5
+ ## 0.2.1 — 右端が切れる不具合の修正(2026-09-20)
6
+
7
+ ### 追加
8
+
9
+ - 内容が本文領域より横に広いとき、`onWarning` に `other` の警告を出すようにした(はみ出し量つき)。これまでは右端が黙って切れていた
10
+
11
+ ### 修正
12
+
13
+ - **親文書の `body` マージンが PDF に持ち込まれ、内容が右へずれて右端が切れていた**。iframe に差し込むリセットは収集したスタイルより前に置かれるため、ページ側の `body { margin: … }` に負けていた。`!important` で確実に打ち消すようにした(用紙の余白は `options.page.margin` が受け持つ)
14
+ - `examples/cdn.html` の `#receipt` に `box-sizing: border-box` が無く、`padding` と `border` の分だけ右端が切れていた
15
+
16
+ ### ドキュメント
17
+
18
+ - CDN から読み込む使い方を追加(README / API リファレンス / サイトのクイックスタート / skill)。`dist/` の minify 済みファイルは依存ゼロの単一 ESM なので、jsDelivr や unpkg の URL をそのまま `import` できる
19
+ - `examples/cdn.html` を追加。ファイル 1 つ、ビルドもバンドラーも無しで動く領収証 PDF の例
20
+ - 通常の `<script>` から使う方法(`import * as ReceiptHtmlToPdf` して `window` に載せる)と、モジュールスクリプトの実行順の注意を明記
21
+
5
22
  ## 0.2.0 — シャドウ DOM 対応(2026-09-20)
6
23
 
7
24
  ### 追加
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  **ドキュメント: https://hidemikimura.github.io/receipt-html-to-pdf/** ([デモ](https://hidemikimura.github.io/receipt-html-to-pdf/demo.html) / [API リファレンス](https://hidemikimura.github.io/receipt-html-to-pdf/api.html) / [対応 CSS 一覧](https://hidemikimura.github.io/receipt-html-to-pdf/css.html))
12
12
 
13
- > **v0.2.0** — テキスト・背景・ボーダー・画像・角丸・2D transform・擬似要素・`overflow: hidden`・複数ページ(行を跨がない分割、`break-*`、`thead` / `tfoot` の繰り返し、ヘッダー/フッター)に加え、**シャドウ DOM(Web Components)** に対応。依存ゼロ、minify バンドルは gzip 20KB。
13
+ > **v0.2.1** — テキスト・背景・ボーダー・画像・角丸・2D transform・擬似要素・`overflow: hidden`・複数ページ(行を跨がない分割、`break-*`、`thead` / `tfoot` の繰り返し、ヘッダー/フッター)に加え、**シャドウ DOM(Web Components)** に対応。依存ゼロ、minify バンドルは gzip 20KB。
14
14
  > Chromium / Firefox / WebKit の 3 ブラウザで Playwright テスト(テキスト抽出・ページ分割・画素差分)に合格。対応 CSS は [docs/css-support.md](docs/css-support.md)、設計と経緯は [docs/design.md](docs/design.md)、変更履歴は [CHANGELOG.md](CHANGELOG.md)。
15
15
 
16
16
  ## 使い方
@@ -41,7 +41,7 @@ downloadPdf(pdf, 'receipt.pdf');
41
41
 
42
42
  主なオプション(`ConvertOptions`、型は `types/index.d.ts`): `page: { size, orientation, margin }`、`header` / `footer`(`{{pageNumber}}` `{{totalPages}}`)、`stylesheets: 'inherit' | 'none' | [url または CSS 文字列]`、`mediaPrint`、`fontFallback`、`metadata`、`compress`、`baseUrl`、`onWarning`。
43
43
 
44
- サンプル: [`examples/vanilla.html`](examples/vanilla.html)(`npm run dev` 後に `/examples/vanilla.html`)、[`examples/react.jsx`](examples/react.jsx)、[`examples/lit.js`](examples/lit.js)(シャドウ DOM はそのまま変換できる)。
44
+ サンプル: [`examples/cdn.html`](examples/cdn.html)(CDN から読むだけ、ビルド不要)、[`examples/vanilla.html`](examples/vanilla.html)(`npm run dev` 後に `/examples/vanilla.html`)、[`examples/react.jsx`](examples/react.jsx)、[`examples/lit.js`](examples/lit.js)(シャドウ DOM はそのまま変換できる)。
45
45
 
46
46
  ## インストール
47
47
 
@@ -51,6 +51,22 @@ npm install @hidemikimura/receipt-html-to-pdf
51
51
 
52
52
  `import ... from '@hidemikimura/receipt-html-to-pdf'` でソース(ESM)、`'@hidemikimura/receipt-html-to-pdf/min'` で minify 済み単一ファイル(`npm run build` で生成)を読み込める。
53
53
 
54
+ ### CDN から読み込む(ビルド不要)
55
+
56
+ `dist/` の minify 済みファイルは依存ゼロの単一 ESM なので、CDN の URL をそのまま `import` できる。npm もバンドラーも要らない。
57
+
58
+ ```html
59
+ <script type="module">
60
+ import { registerFont, htmlToPdf, downloadPdf }
61
+ from 'https://cdn.jsdelivr.net/npm/@hidemikimura/receipt-html-to-pdf@0.2.1/dist/receipt-html-to-pdf.min.js';
62
+
63
+ await registerFont({ family: 'BIZ UDPGothic', src: '/fonts/BIZUDPGothic-Regular.ttf' });
64
+ downloadPdf(await htmlToPdf(document.querySelector('#receipt')), 'receipt.pdf');
65
+ </script>
66
+ ```
67
+
68
+ バージョン(`@0.2.1`)は固定すること。unpkg でも同じ。グローバル変数を配るビルド(IIFE / UMD)は用意していないが、`import * as ReceiptHtmlToPdf` して `window` に載せれば `type="module"` でない普通のスクリプトからも呼べる。ファイル 1 つで動く一式は [`examples/cdn.html`](examples/cdn.html)。
69
+
54
70
  ## 開発
55
71
 
56
72
  ```sh
@@ -77,7 +93,7 @@ brew install qpdf # 任意: 生成 PDF の構造
77
93
 
78
94
  CI(`.github/workflows/ci.yml`)は typecheck → 単体テスト → サイズ検査の後、3 ブラウザ並列でブラウザテストを流し、生成された PDF を `qpdf --check` で検証する。
79
95
 
80
- ## 対応範囲(v0.2.0
96
+ ## 対応範囲(v0.2.1
81
97
 
82
98
  | 対応 | 未対応(onWarning で通知) |
83
99
  |---|---|
@@ -125,7 +141,7 @@ npm run site:dev # 組み立てて http://localhost:5174 で表示
125
141
  2. `npm run pack:check` で tarball の内容を確認する(`files` で許可リスト管理。フォント・フィクスチャ・テストは含まれない)
126
142
  3. `npm login`(スコープ `@hidemikimura` の所有者アカウント)
127
143
  4. `npm publish` — `prepublishOnly` が typecheck → 単体テスト → `.d.ts` 生成 → minify ビルド + サイズ検査を自動で流す。`publishConfig.access` が `public` なのでスコープ付きでも無料で公開される
128
- 5. `git tag v0.2.0 && git push --tags`
144
+ 5. `git tag v0.2.1 && git push --tags`
129
145
 
130
146
  ## ライセンス
131
147
 
@@ -1,8 +1,8 @@
1
- /* @hidemikimura/receipt-html-to-pdf v0.2.0 | MIT */
2
- function Pt(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=new DataView(t.buffer,t.byteOffset,t.byteLength),s=n.getUint32(0);if(s===1330926671)throw new Error("CFF outlines (OpenType/CFF) are not supported. Use a TrueType (glyf) font.");if(s===2001684038||s===2001684018)throw new Error("WOFF/WOFF2 are not supported. Use a raw .ttf file.");if(s===1953784678)throw new Error("TrueType collections (.ttc) are not supported. Extract a single face first.");if(s!==65536&&s!==1953658213)throw new Error("Not a TrueType font (bad sfnt version)");let o=n.getUint16(4),r=new Map;for(let b=0;b<o;b++){let T=12+b*16,B=String.fromCharCode(t[T]??0,t[T+1]??0,t[T+2]??0,t[T+3]??0);r.set(B,{offset:n.getUint32(T+8),length:n.getUint32(T+12)})}if(r.has("CFF "))throw new Error("CFF outlines are not supported. Use a TrueType (glyf) font.");let i=r.has("fvar");for(let b of["head","hhea","maxp","hmtx","loca","glyf"])if(!r.has(b))throw new Error(`Font is missing required table: ${b}`);let a=b=>r.get(b),c=a("head"),h=n.getUint16(c.offset+18),p=[n.getInt16(c.offset+36),n.getInt16(c.offset+38),n.getInt16(c.offset+40),n.getInt16(c.offset+42)],f=n.getUint16(c.offset+44),d=n.getInt16(c.offset+50),u=a("hhea"),w=n.getInt16(u.offset+4),y=n.getInt16(u.offset+6),C=n.getInt16(u.offset+8),O=n.getUint16(u.offset+34),R=n.getUint16(a("maxp").offset+4),D=a("hmtx"),L=new Uint16Array(R),j=0;for(let b=0;b<R;b++)b<O&&(j=n.getUint16(D.offset+b*4)),L[b]=j;let z=a("loca"),X=new Uint32Array(R+1);for(let b=0;b<=R;b++)X[b]=d===0?n.getUint16(z.offset+b*2)*2:n.getUint32(z.offset+b*4);let et=r.get("cmap"),$=et?ne(n,et.offset):new Map,l=Math.round(w*.7),m=!1,g=w,x=y,S=w,F=-y,E=(f&1)!==0,k=(f&2)!==0,I=r.get("OS/2");if(I){let b=n.getUint16(I.offset),T=n.getUint16(I.offset+62);if(m=(T&128)!==0,E=E||(T&32)!==0,k=k||(T&1)!==0,g=n.getInt16(I.offset+68),x=n.getInt16(I.offset+70),S=n.getUint16(I.offset+74),F=n.getUint16(I.offset+76),b>=2&&I.length>=90){let B=n.getInt16(I.offset+88);B>0&&(l=B)}}let A=0,N=r.get("post");N&&(A=n.getInt32(N.offset+4)/65536);let W=oe(n,t,r.get("name"))??"Embedded";return{data:t,tables:r,unitsPerEm:h,indexToLocFormat:d,bbox:p,ascender:w,descender:y,lineGap:C,numGlyphs:R,advances:L,loca:X,cmap:$,capHeight:l,italicAngle:A,useTypoMetrics:m,typoAscender:g,typoDescender:x,winAscent:S,winDescent:F,postScriptName:W,bold:E,italic:k,variable:i}}function ne(e,t){let n=e.getUint16(t+2),s=-1,o=-1;for(let a=0;a<n;a++){let c=t+4+a*8,h=e.getUint16(c),p=e.getUint16(c+2),f=e.getUint32(c+4),d=e.getUint16(t+f),u=-1;h===3&&p===10&&d===12?u=4:h===0&&(p===4||p===6)&&d===12?u=3:h===3&&p===1&&d===4?u=2:h===0&&d===4&&(u=1),u>o&&(o=u,s=t+f)}if(s<0)throw new Error("Font has no usable Unicode cmap subtable (format 4 or 12)");let r=new Map,i=e.getUint16(s);if(i===4){let a=e.getUint16(s+6),c=a/2,h=s+14,p=h+a+2,f=p+a,d=f+a;for(let u=0;u<c;u++){let w=e.getUint16(h+u*2),y=e.getUint16(p+u*2),C=e.getInt16(f+u*2),O=e.getUint16(d+u*2);if(y!==65535)for(let R=y;R<=w;R++){let D;if(O===0)D=R+C&65535;else{let L=d+u*2+O+(R-y)*2;if(L+2>e.byteLength)continue;D=e.getUint16(L),D!==0&&(D=D+C&65535)}D!==0&&r.set(R,D)}}}else if(i===12){let a=e.getUint32(s+12),c=s+16;for(let h=0;h<a;h++,c+=12){let p=e.getUint32(c),f=e.getUint32(c+4),d=e.getUint32(c+8);for(let u=p;u<=f&&u-p<65536;u++){let w=d+(u-p);w!==0&&r.set(u,w)}}}return r}function oe(e,t,n){if(!n)return null;let s=e.getUint16(n.offset+2),o=e.getUint16(n.offset+4),r=null;for(let i=0;i<s;i++){let a=n.offset+6+i*12,c=e.getUint16(a),h=e.getUint16(a+6),p=e.getUint16(a+8),f=e.getUint16(a+10);if(h!==6)continue;let d=n.offset+o+f;if(c===1)return Et(String.fromCharCode(...t.subarray(d,d+p)));if(c===3||c===0){let u="";for(let w=0;w+1<p;w+=2)u+=String.fromCharCode(e.getUint16(d+w));r=Et(u)}}return r}function Et(e){return e.replace(/[^\x21-\x7e]/g,"").replace(/[\[\]\(\)\{\}<>\/%#]/g,"")||"Embedded"}function bt(e,t){let n=e.tables.get("glyf"),s=e.loca[t]??0,o=e.loca[t+1]??s;return e.data.subarray(n.offset+s,n.offset+o)}function At(e){if(e.length<10)return[];let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getInt16(0)>=0)return[];let s=[],o=10;for(;;){let r=t.getUint16(o),i=t.getUint16(o+2);if(s.push(i),o+=4,o+=r&1?4:2,r&8?o+=2:r&64?o+=4:r&128&&(o+=8),!(r&32)||o>=e.length)break}return s}var ct=class{constructor(){this.fonts=[]}async register(t){let n=await se(t.src),s=Pt(n),o={family:wt(t.family),displayFamily:t.family,weight:t.weight??400,style:t.style??"normal",parsed:s},r=this.fonts.findIndex(i=>i.family===o.family&&i.weight===o.weight&&i.style===o.style);return r>=0?this.fonts[r]=o:this.fonts.push(o),o}hasFamily(t){let n=wt(t);return this.fonts.some(s=>s.family===n)}match(t,n,s,o){for(let r of t){let i=wt(r),a=this.fonts.filter(c=>c.family===i);if(o!==void 0&&(a=a.filter(c=>c.parsed.cmap.has(o))),!!a.length)return Mt(a,n,s)}return null}anyWithGlyph(t,n,s){let o=this.fonts.filter(r=>r.parsed.cmap.has(t));return o.length?Mt(o,n,s):null}};function Mt(e,t,n){let s=e.filter(h=>h.style===n),o=s.length?s:e,r=o.find(h=>h.weight===t);if(r)return r;let i=[...o].sort((h,p)=>h.weight-p.weight),a=i.filter(h=>h.weight>t),c=i.filter(h=>h.weight<t).reverse();if(t>=400&&t<=500){let h=a.find(p=>p.weight<=500);return h||(c.length?c[0]:a[0])}return t<400?c[0]??a[0]:a[0]??c[0]}function wt(e){return e.trim().replace(/^["']|["']$/g,"").trim().toLowerCase()}function It(e){let t=[],n="",s="";for(let o of e)s?o===s?s="":n+=o:o==='"'||o==="'"?s=o:o===","?(n.trim()&&t.push(n.trim()),n=""):n+=o;return n.trim()&&t.push(n.trim()),t}function Rt(e){if(e==="bold")return 700;if(e==="normal")return 400;let t=parseInt(e,10);return Number.isFinite(t)?t:400}async function se(e){if(e instanceof Uint8Array)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);let t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch font ${e}: ${t.status} ${t.statusText}`);return new Uint8Array(await t.arrayBuffer())}async function St(e,t){let n=document.createElement("iframe");n.setAttribute("aria-hidden","true"),n.style.cssText=`position:fixed;left:-100000px;top:0;width:${t.widthPx}px;height:1000px;border:0;visibility:hidden;pointer-events:none;`,document.body.appendChild(n);let s=n.contentWindow,o=n.contentDocument;if(!s||!o)throw new Error("Failed to create rendering iframe");let r=re(e,t);o.open(),o.write(r),o.close(),he(o,s);let i=()=>{n.style.height=`${Math.max(o.documentElement.scrollHeight,o.body.scrollHeight,100)}px`};return i(),await ue(o),i(),await pe(o),await me(o),ge(o,t.warn??(()=>{})),i(),o.body.offsetHeight,{iframe:n,doc:o,win:s,root:o.body,destroy:()=>n.remove()}}function re(e,t){let n=t.baseUrl??document.baseURI,s=`<base href="${it(n)}">`,o="<style data-rhtp-reset>html,body{margin:0;padding:0;background:transparent}html{-webkit-text-size-adjust:100%}</style>";if(typeof e=="string"){if(/<html[\s>]/i.test(e)){let p=e;return p=/<head[^>]*>/i.test(p)?p.replace(/<head[^>]*>/i,f=>`${f}${s}${o}`):p.replace(/<html[^>]*>/i,f=>`${f}<head>${s}${o}</head>`),t.mediaPrint?de(p):p}let h=Bt(t.stylesheets,t.mediaPrint);return`<!DOCTYPE html><html><head><meta charset="utf-8">${s}${o}${h}</head><body>${e}</body></html>`}let r=Bt(t.stylesheets,t.mediaPrint)+ie(e,t.stylesheets,t.mediaPrint),i=xt(document.documentElement),a=xt(document.body),c=ce(e,t.warn??(()=>{}));return`<!DOCTYPE html><html${i}><head><meta charset="utf-8">${s}${o}${r}</head><body${a}>${c}</body></html>`}function Bt(e,t){if(e==="none")return"";let n=[];if(e==="inherit"){for(let o of document.querySelectorAll('style, link[rel~="stylesheet"]'))if(!o.hasAttribute("data-rhtp-reset"))if(o instanceof HTMLStyleElement){let r=o.textContent??"";n.push(`<style>${t?ot(r):r}</style>`)}else o instanceof HTMLLinkElement&&n.push(`<link rel="stylesheet" href="${it(o.href)}"${o.media?` media="${it(o.media)}"`:""}>`);let s=Tt(document.adoptedStyleSheets);return s&&n.push(`<style>${t?ot(s):s}</style>`),n.join("")}for(let s of e)/^(https?:)?\/\/|^\.{0,2}\/|\.css(\?|$)/i.test(s)&&!s.includes("{")?n.push(`<link rel="stylesheet" href="${it(s)}">`):n.push(`<style>${t?ot(s):s}</style>`);return n.join("")}function ie(e,t,n){if(t!=="inherit")return"";let s=[],o=e.getRootNode();for(;o&&o!==document&&"host"in o;){let r=o,i=[...r.querySelectorAll("style")].map(a=>a.textContent??"").join(`
1
+ /* @hidemikimura/receipt-html-to-pdf v0.2.1 | MIT */
2
+ function Pt(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=new DataView(t.buffer,t.byteOffset,t.byteLength),s=n.getUint32(0);if(s===1330926671)throw new Error("CFF outlines (OpenType/CFF) are not supported. Use a TrueType (glyf) font.");if(s===2001684038||s===2001684018)throw new Error("WOFF/WOFF2 are not supported. Use a raw .ttf file.");if(s===1953784678)throw new Error("TrueType collections (.ttc) are not supported. Extract a single face first.");if(s!==65536&&s!==1953658213)throw new Error("Not a TrueType font (bad sfnt version)");let o=n.getUint16(4),r=new Map;for(let b=0;b<o;b++){let T=12+b*16,B=String.fromCharCode(t[T]??0,t[T+1]??0,t[T+2]??0,t[T+3]??0);r.set(B,{offset:n.getUint32(T+8),length:n.getUint32(T+12)})}if(r.has("CFF "))throw new Error("CFF outlines are not supported. Use a TrueType (glyf) font.");let i=r.has("fvar");for(let b of["head","hhea","maxp","hmtx","loca","glyf"])if(!r.has(b))throw new Error(`Font is missing required table: ${b}`);let a=b=>r.get(b),c=a("head"),h=n.getUint16(c.offset+18),p=[n.getInt16(c.offset+36),n.getInt16(c.offset+38),n.getInt16(c.offset+40),n.getInt16(c.offset+42)],f=n.getUint16(c.offset+44),d=n.getInt16(c.offset+50),u=a("hhea"),w=n.getInt16(u.offset+4),y=n.getInt16(u.offset+6),C=n.getInt16(u.offset+8),O=n.getUint16(u.offset+34),R=n.getUint16(a("maxp").offset+4),D=a("hmtx"),L=new Uint16Array(R),j=0;for(let b=0;b<R;b++)b<O&&(j=n.getUint16(D.offset+b*4)),L[b]=j;let z=a("loca"),X=new Uint32Array(R+1);for(let b=0;b<=R;b++)X[b]=d===0?n.getUint16(z.offset+b*2)*2:n.getUint32(z.offset+b*4);let et=r.get("cmap"),$=et?ne(n,et.offset):new Map,l=Math.round(w*.7),m=!1,g=w,x=y,S=w,F=-y,E=(f&1)!==0,k=(f&2)!==0,I=r.get("OS/2");if(I){let b=n.getUint16(I.offset),T=n.getUint16(I.offset+62);if(m=(T&128)!==0,E=E||(T&32)!==0,k=k||(T&1)!==0,g=n.getInt16(I.offset+68),x=n.getInt16(I.offset+70),S=n.getUint16(I.offset+74),F=n.getUint16(I.offset+76),b>=2&&I.length>=90){let B=n.getInt16(I.offset+88);B>0&&(l=B)}}let M=0,N=r.get("post");N&&(M=n.getInt32(N.offset+4)/65536);let W=oe(n,t,r.get("name"))??"Embedded";return{data:t,tables:r,unitsPerEm:h,indexToLocFormat:d,bbox:p,ascender:w,descender:y,lineGap:C,numGlyphs:R,advances:L,loca:X,cmap:$,capHeight:l,italicAngle:M,useTypoMetrics:m,typoAscender:g,typoDescender:x,winAscent:S,winDescent:F,postScriptName:W,bold:E,italic:k,variable:i}}function ne(e,t){let n=e.getUint16(t+2),s=-1,o=-1;for(let a=0;a<n;a++){let c=t+4+a*8,h=e.getUint16(c),p=e.getUint16(c+2),f=e.getUint32(c+4),d=e.getUint16(t+f),u=-1;h===3&&p===10&&d===12?u=4:h===0&&(p===4||p===6)&&d===12?u=3:h===3&&p===1&&d===4?u=2:h===0&&d===4&&(u=1),u>o&&(o=u,s=t+f)}if(s<0)throw new Error("Font has no usable Unicode cmap subtable (format 4 or 12)");let r=new Map,i=e.getUint16(s);if(i===4){let a=e.getUint16(s+6),c=a/2,h=s+14,p=h+a+2,f=p+a,d=f+a;for(let u=0;u<c;u++){let w=e.getUint16(h+u*2),y=e.getUint16(p+u*2),C=e.getInt16(f+u*2),O=e.getUint16(d+u*2);if(y!==65535)for(let R=y;R<=w;R++){let D;if(O===0)D=R+C&65535;else{let L=d+u*2+O+(R-y)*2;if(L+2>e.byteLength)continue;D=e.getUint16(L),D!==0&&(D=D+C&65535)}D!==0&&r.set(R,D)}}}else if(i===12){let a=e.getUint32(s+12),c=s+16;for(let h=0;h<a;h++,c+=12){let p=e.getUint32(c),f=e.getUint32(c+4),d=e.getUint32(c+8);for(let u=p;u<=f&&u-p<65536;u++){let w=d+(u-p);w!==0&&r.set(u,w)}}}return r}function oe(e,t,n){if(!n)return null;let s=e.getUint16(n.offset+2),o=e.getUint16(n.offset+4),r=null;for(let i=0;i<s;i++){let a=n.offset+6+i*12,c=e.getUint16(a),h=e.getUint16(a+6),p=e.getUint16(a+8),f=e.getUint16(a+10);if(h!==6)continue;let d=n.offset+o+f;if(c===1)return Et(String.fromCharCode(...t.subarray(d,d+p)));if(c===3||c===0){let u="";for(let w=0;w+1<p;w+=2)u+=String.fromCharCode(e.getUint16(d+w));r=Et(u)}}return r}function Et(e){return e.replace(/[^\x21-\x7e]/g,"").replace(/[\[\]\(\)\{\}<>\/%#]/g,"")||"Embedded"}function bt(e,t){let n=e.tables.get("glyf"),s=e.loca[t]??0,o=e.loca[t+1]??s;return e.data.subarray(n.offset+s,n.offset+o)}function Mt(e){if(e.length<10)return[];let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(t.getInt16(0)>=0)return[];let s=[],o=10;for(;;){let r=t.getUint16(o),i=t.getUint16(o+2);if(s.push(i),o+=4,o+=r&1?4:2,r&8?o+=2:r&64?o+=4:r&128&&(o+=8),!(r&32)||o>=e.length)break}return s}var ct=class{constructor(){this.fonts=[]}async register(t){let n=await se(t.src),s=Pt(n),o={family:wt(t.family),displayFamily:t.family,weight:t.weight??400,style:t.style??"normal",parsed:s},r=this.fonts.findIndex(i=>i.family===o.family&&i.weight===o.weight&&i.style===o.style);return r>=0?this.fonts[r]=o:this.fonts.push(o),o}hasFamily(t){let n=wt(t);return this.fonts.some(s=>s.family===n)}match(t,n,s,o){for(let r of t){let i=wt(r),a=this.fonts.filter(c=>c.family===i);if(o!==void 0&&(a=a.filter(c=>c.parsed.cmap.has(o))),!!a.length)return At(a,n,s)}return null}anyWithGlyph(t,n,s){let o=this.fonts.filter(r=>r.parsed.cmap.has(t));return o.length?At(o,n,s):null}};function At(e,t,n){let s=e.filter(h=>h.style===n),o=s.length?s:e,r=o.find(h=>h.weight===t);if(r)return r;let i=[...o].sort((h,p)=>h.weight-p.weight),a=i.filter(h=>h.weight>t),c=i.filter(h=>h.weight<t).reverse();if(t>=400&&t<=500){let h=a.find(p=>p.weight<=500);return h||(c.length?c[0]:a[0])}return t<400?c[0]??a[0]:a[0]??c[0]}function wt(e){return e.trim().replace(/^["']|["']$/g,"").trim().toLowerCase()}function It(e){let t=[],n="",s="";for(let o of e)s?o===s?s="":n+=o:o==='"'||o==="'"?s=o:o===","?(n.trim()&&t.push(n.trim()),n=""):n+=o;return n.trim()&&t.push(n.trim()),t}function Rt(e){if(e==="bold")return 700;if(e==="normal")return 400;let t=parseInt(e,10);return Number.isFinite(t)?t:400}async function se(e){if(e instanceof Uint8Array)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);let t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch font ${e}: ${t.status} ${t.statusText}`);return new Uint8Array(await t.arrayBuffer())}async function St(e,t){let n=document.createElement("iframe");n.setAttribute("aria-hidden","true"),n.style.cssText=`position:fixed;left:-100000px;top:0;width:${t.widthPx}px;height:1000px;border:0;visibility:hidden;pointer-events:none;`,document.body.appendChild(n);let s=n.contentWindow,o=n.contentDocument;if(!s||!o)throw new Error("Failed to create rendering iframe");let r=re(e,t);o.open(),o.write(r),o.close(),de(o,s);let i=()=>{n.style.height=`${Math.max(o.documentElement.scrollHeight,o.body.scrollHeight,100)}px`};return i(),await pe(o),i(),await me(o),await ge(o),ye(o,t.warn??(()=>{})),i(),o.body.offsetHeight,ae(o,t.widthPx,t.warn??(()=>{})),{iframe:n,doc:o,win:s,root:o.body,destroy:()=>n.remove()}}function re(e,t){let n=t.baseUrl??document.baseURI,s=`<base href="${it(n)}">`,o="<style data-rhtp-reset>html,body{margin:0 !important;padding:0 !important;background:transparent}html{-webkit-text-size-adjust:100%}</style>";if(typeof e=="string"){if(/<html[\s>]/i.test(e)){let p=e;return p=/<head[^>]*>/i.test(p)?p.replace(/<head[^>]*>/i,f=>`${f}${s}${o}`):p.replace(/<html[^>]*>/i,f=>`${f}<head>${s}${o}</head>`),t.mediaPrint?ue(p):p}let h=Bt(t.stylesheets,t.mediaPrint);return`<!DOCTYPE html><html><head><meta charset="utf-8">${s}${o}${h}</head><body>${e}</body></html>`}let r=Bt(t.stylesheets,t.mediaPrint)+ie(e,t.stylesheets,t.mediaPrint),i=xt(document.documentElement),a=xt(document.body),c=fe(e,t.warn??(()=>{}));return`<!DOCTYPE html><html${i}><head><meta charset="utf-8">${s}${o}${r}</head><body${a}>${c}</body></html>`}function Bt(e,t){if(e==="none")return"";let n=[];if(e==="inherit"){for(let o of document.querySelectorAll('style, link[rel~="stylesheet"]'))if(!o.hasAttribute("data-rhtp-reset"))if(o instanceof HTMLStyleElement){let r=o.textContent??"";n.push(`<style>${t?ot(r):r}</style>`)}else o instanceof HTMLLinkElement&&n.push(`<link rel="stylesheet" href="${it(o.href)}"${o.media?` media="${it(o.media)}"`:""}>`);let s=Tt(document.adoptedStyleSheets);return s&&n.push(`<style>${t?ot(s):s}</style>`),n.join("")}for(let s of e)/^(https?:)?\/\/|^\.{0,2}\/|\.css(\?|$)/i.test(s)&&!s.includes("{")?n.push(`<link rel="stylesheet" href="${it(s)}">`):n.push(`<style>${t?ot(s):s}</style>`);return n.join("")}function ie(e,t,n){if(t!=="inherit")return"";let s=[],o=e.getRootNode();for(;o&&o!==document&&"host"in o;){let r=o,i=[...r.querySelectorAll("style")].map(a=>a.textContent??"").join(`
3
3
  `)+`
4
- `+Tt(r.adoptedStyleSheets);i.trim()&&s.unshift(i),o=r.host.getRootNode()}return s.map(r=>`<style>${n?ot(r):r}</style>`).join("")}var ae=new Set(["AREA","BASE","BR","COL","EMBED","HR","IMG","INPUT","LINK","META","SOURCE","TRACK","WBR"]);function ce(e,t){let n=e===document.body||e===document.documentElement,s=fe(n?document.body:e);if(!s.length)return n?document.body.innerHTML:e.outerHTML;let o=n?document.body:e;if(typeof o.getHTML!="function")return t({code:"unsupported-css",message:"This browser lacks Element.getHTML(); shadow DOM content cannot be serialized and will be missing from the PDF. Pass an element inside the shadow root instead.",element:e}),n?document.body.innerHTML:e.outerHTML;let r=le(s);try{let i={serializableShadowRoots:!0,shadowRoots:s},a=o.getHTML(i);if(n)return a;let c=e.tagName.toLowerCase();return ae.has(e.tagName)?e.outerHTML:`<${c}${xt(e)}>${a}</${c}>`}finally{r()}}function fe(e){let t=[],n=s=>{s instanceof Element&&s.shadowRoot&&(t.push(s.shadowRoot),n(s.shadowRoot));for(let o of s.children)n(o)};return n(e),t}function le(e){let t=[];for(let n of e){let s=Tt(n.adoptedStyleSheets);if(!s)continue;let o=document.createElement("style");o.setAttribute("data-rhtp-adopted",""),o.textContent=s,n.insertBefore(o,n.firstChild),t.push(o)}return()=>{for(let n of t)n.remove()}}function Tt(e){if(!e||!e.length)return"";let t=[];for(let n of e)try{for(let s of n.cssRules)t.push(s.cssText)}catch{}return t.join(`
5
- `)}function he(e,t){let n=t.customElements,s=t.HTMLElement;if(!n||!s)return;let o=new Set,r=i=>{for(let a of i.querySelectorAll("*"))a.tagName.includes("-")&&!a.hasAttribute("is")&&o.add(a.tagName.toLowerCase()),a.shadowRoot&&r(a.shadowRoot)};r(e);for(let i of o)if(!n.get(i))try{n.define(i,class extends s{})}catch{}}function de(e){return e.replace(/<style([^>]*)>([\s\S]*?)<\/style>/gi,(t,n,s)=>`<style${n}>${ot(s)}</style>`)}function ot(e){let t="",n=0;for(;n<e.length;){let s=/@media\s*([^{]+)\{/g;s.lastIndex=n;let o=s.exec(e);if(!o){t+=e.slice(n);break}t+=e.slice(n,o.index);let r=1,i=s.lastIndex;for(;i<e.length&&r>0;)e[i]==="{"?r++:e[i]==="}"&&r--,i++;let a=o[1].trim(),c=e.slice(s.lastIndex,i-1);/\bprint\b/.test(a)?t+=c:/^\s*(only\s+)?screen\b/.test(a)&&!/\band\b/.test(a)?t+="":t+=e.slice(o.index,i),n=i}return t}function xt(e){let t="";for(let n of e.attributes)/^on/i.test(n.name)||(t+=` ${n.name}="${it(n.value)}"`);return t}function it(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}async function ue(e){let t=[...e.querySelectorAll('link[rel~="stylesheet"]')];await Promise.all(t.map(n=>new Promise(s=>{let o=n;if(o.sheet)return s(void 0);o.addEventListener("load",()=>s(void 0),{once:!0}),o.addEventListener("error",()=>s(void 0),{once:!0}),setTimeout(()=>s(void 0),1e4)})))}async function pe(e){if(e.body.offsetHeight,e.fonts){await e.fonts.ready;let t=[...e.fonts].filter(n=>n.status==="loading").map(n=>n.loaded.catch(()=>{}));t.length&&await Promise.all(t),await e.fonts.ready}}async function me(e){let t=[...e.images];await Promise.all(t.map(n=>n.complete?n.decode().catch(()=>{}):new Promise(s=>{n.addEventListener("load",()=>n.decode().catch(()=>{}).then(s),{once:!0}),n.addEventListener("error",()=>s(void 0),{once:!0}),setTimeout(()=>s(void 0),1e4)})))}function ge(e,t){let n=e.defaultView;if(!n)return;let s=[];for(let i of ye(e.body))for(let a of["before","after"]){let c=n.getComputedStyle(i,`::${a}`),h=c.content;if(!h||h==="none"||h==="normal"||c.display==="none")continue;let p=be(h);if(p===null){t({code:"unsupported-css",message:`::${a} content "${h}" is not supported (only quoted strings are); the pseudo-element is skipped`,element:i,property:"content"});continue}let f=[];for(let d=0;d<c.length;d++){let u=c[d];u==="content"||u.startsWith("-webkit-")||u.startsWith("-moz-")||f.push([u,c.getPropertyValue(u)])}s.push({el:i,pseudo:a,text:p,styles:f})}if(!s.length)return;let o='[data-rhtp-pseudo-host~="before"]::before{content:none!important;display:none!important}[data-rhtp-pseudo-host~="after"]::after{content:none!important;display:none!important}',r=e.createElement("style");r.setAttribute("data-rhtp-pseudo",""),r.textContent=o,e.head.appendChild(r);for(let i of new Set(s.map(a=>a.el.getRootNode()).filter(a=>a!==e))){let a=e.createElement("style");a.setAttribute("data-rhtp-pseudo",""),a.textContent=o,i.appendChild(a)}for(let i of s){let a=e.createElement("span");a.setAttribute("data-rhtp-pseudo",i.pseudo);for(let[h,p]of i.styles)a.style.setProperty(h,p);a.textContent=i.text;let c=(i.el.getAttribute("data-rhtp-pseudo-host")??"").split(" ").filter(Boolean);c.push(i.pseudo),i.el.setAttribute("data-rhtp-pseudo-host",c.join(" ")),i.pseudo==="before"?i.el.insertBefore(a,i.el.firstChild):i.el.appendChild(a)}}function ye(e){let t=[],n=s=>{for(let o of s.querySelectorAll("*"))t.push(o),o.shadowRoot&&n(o.shadowRoot)};return n(e),t}function be(e){let t="",n=0,s=e.trim();for(;n<s.length;){let o=s[n];if(o===" "||o===" "){n++;continue}if(o!=='"'&&o!=="'")return null;let r=o;for(n++;n<s.length&&s[n]!==r;)if(s[n]==="\\"){n++;let i=/^[0-9a-fA-F]{1,6}/.exec(s.slice(n));i?(t+=String.fromCodePoint(parseInt(i[0],16)),n+=i[0].length,s[n]===" "&&n++):(t+=s[n]??"",n++)}else t+=s[n],n++;n++}return t}var _=2.834645669291339,$t={A3:{width:297*_,height:420*_},A4:{width:210*_,height:297*_},A5:{width:148*_,height:210*_},B4:{width:257*_,height:364*_},B5:{width:182*_,height:257*_},Letter:{width:612,height:792},Legal:{width:612,height:1008}};function Y(e){if(typeof e=="number")return e*.75;let t=/^\s*(-?[\d.]+)\s*([a-z%]*)\s*$/i.exec(e);if(!t)throw new Error(`Invalid CSS length: ${e}`);let n=parseFloat(t[1]);switch((t[2]??"").toLowerCase()){case"":case"px":return n*.75;case"pt":return n;case"mm":return n*_;case"cm":return n*_*10;case"in":return n*72;case"pc":return n*12;default:throw new Error(`Unsupported CSS unit: ${e}`)}}function q(e){let t=parseFloat(e);return Number.isFinite(t)?t:0}function st(e){if(!e)return null;let t=e.trim();if(t==="transparent")return{r:0,g:0,b:0,a:0};let n=/^rgba?\(\s*([\d.]+)\s*[, ]\s*([\d.]+)\s*[, ]\s*([\d.]+)\s*(?:[,/]\s*([\d.]+%?)\s*)?\)$/i.exec(t);if(n){let s=n[4]===void 0?1:n[4].endsWith("%")?parseFloat(n[4])/100:parseFloat(n[4]);return{r:tt(parseFloat(n[1])/255),g:tt(parseFloat(n[2])/255),b:tt(parseFloat(n[3])/255),a:tt(s)}}if(n=/^color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s*(?:\/\s*([\d.]+%?)\s*)?\)$/i.exec(t),n){let s=n[4]===void 0?1:n[4].endsWith("%")?parseFloat(n[4])/100:parseFloat(n[4]);return{r:tt(parseFloat(n[1])),g:tt(parseFloat(n[2])),b:tt(parseFloat(n[3])),a:tt(s)}}if(n=/^#([0-9a-f]{3,8})$/i.exec(t),n){let s=n[1];(s.length===3||s.length===4)&&(s=s.split("").map(r=>r+r).join(""));let o=parseInt(s.padEnd(8,"f"),16);return{r:(o>>>24&255)/255,g:(o>>>16&255)/255,b:(o>>>8&255)/255,a:(o&255)/255}}return null}function tt(e){return e<0?0:e>1?1:e}function U(e){if(!Number.isFinite(e))return"0";let t=e.toFixed(3),n=t.includes(".")?t.replace(/\.?0+$/,""):t;return n===""||n==="-0"||n==="-"?"0":n}var we=new Set([32,9,10,13,12,160,12288,8194,8195,8201,8202,8239,8287]);function Ot(e,t,n){let s=e.ownerDocument,o=Te(e.data,t.textTransform),r=s.createRange(),i=$e(s,t),a=[],c=null,h=NaN,p=new Set;for(let f=0;f<o.length;){let d=o.codePointAt(f),u=d>65535?2:1,w=f+u;r.setStart(e,f),r.setEnd(e,Math.min(w,e.data.length));let y=xe(r.getClientRects());if(f=w,!y)continue;let C=Se(d,n,p);if(!C)continue;let{font:O,gid:R,cpForUnicode:D}=C,L=y.top;(!c||c.font!==O||Math.abs(L-h)>.5)&&(c={font:O,baseline:L+i,top:L,bottom:y.bottom,glyphs:[]},h=L,a.push(c)),c.top=Math.min(c.top,L),c.bottom=Math.max(c.bottom,y.bottom);let j=(O.parsed.advances[R]??0)*n.size/O.parsed.unitsPerEm;c.glyphs.push({gid:R,cp:D,x:y.left,advance:j})}return a}function xe(e){let t=null;for(let n of e)n.width>.01&&(!t||n.width>t.width)&&(t=n);return t}function Se(e,t,n){let s=(i,a)=>{let c=i?.parsed.cmap.get(a);return i&&c?{font:i,gid:c,cpForUnicode:e}:null};if(we.has(e))return s(t.primary,e)??s(t.primary,32)??s(t.registry.anyWithGlyph(32,t.weight,t.fstyle),32);let o=s(t.primary,e);if(o||(o=s(t.registry.match(t.families,t.weight,t.fstyle,e),e),o)||(o=s(t.registry.match(t.fallback,t.weight,t.fstyle,e),e),o)||(o=s(t.registry.anyWithGlyph(e,t.weight,t.fstyle),e),o))return o;n.has(e)||(n.add(e),t.warn({code:"missing-glyph",message:`No registered font has a glyph for U+${e.toString(16).toUpperCase().padStart(4,"0")} "${String.fromCodePoint(e)}"; substituted with U+25A1`,element:t.element,text:String.fromCodePoint(e)}));let r=s(t.primary,9633)??s(t.registry.anyWithGlyph(9633,t.weight,t.fstyle),9633);return r?{...r,cpForUnicode:e}:null}function Te(e,t){if(!t||t==="none")return e;let n=e;return t.includes("uppercase")?n=e.toUpperCase():t.includes("lowercase")?n=e.toLowerCase():t.includes("capitalize")&&(n=e.replace(new RegExp("(^|\\s)(\\p{L})","gu"),(s,o,r)=>o+r.toUpperCase())),n.length===e.length?n:e}var Dt=new WeakMap;function $e(e,t){let n=[t.fontFamily,t.fontSize,t.fontWeight,t.fontStyle,t.fontStretch,t.fontVariant,t.fontFeatureSettings].join("|"),s=Dt.get(e);s||(s=new Map,Dt.set(e,s));let o=s.get(n);if(o!==void 0)return o;let r=e.createElement("div");r.setAttribute("data-rhtp-probe",""),r.style.cssText="position:absolute;left:0;top:0;visibility:hidden;white-space:pre;line-height:normal;margin:0;padding:0;border:0;letter-spacing:0;text-indent:0;",r.style.fontFamily=t.fontFamily,r.style.fontSize=t.fontSize,r.style.fontWeight=t.fontWeight,r.style.fontStyle=t.fontStyle,r.style.fontStretch=t.fontStretch,r.style.fontVariant=t.fontVariant,r.style.fontFeatureSettings=t.fontFeatureSettings;let i=e.createTextNode("Ag\u3042");r.appendChild(i);let a=e.createElement("span");a.style.cssText="display:inline-block;width:0;height:0;vertical-align:baseline;margin:0;padding:0;border:0;",r.appendChild(a),e.body.appendChild(r);let c=e.createRange();c.selectNodeContents(i);let h=c.getBoundingClientRect(),f=a.getBoundingClientRect().bottom-h.top;r.remove();let d=Number.isFinite(f)&&f>0?f:parseFloat(t.fontSize)*.8;return s.set(n,d),d}var vt=new Map;function Ct(e,t,n){let s=vt.get(e);return s||(s=Ce(e,t,n).catch(o=>(t({code:"image-failed",message:`Failed to load image ${e}: ${o instanceof Error?o.message:String(o)}`,element:n}),null)),vt.set(e,s)),s}async function Ce(e,t,n){let s=null;try{let y=await fetch(e,{mode:"cors",credentials:"same-origin"});y.ok&&(s=new Uint8Array(await y.arrayBuffer()))}catch{s=null}if(s&&s[0]===255&&s[1]===216){let y=Fe(s);if(y&&y.components===3)return{key:e,width:y.width,height:y.height,jpeg:s,rgb:null,alpha:null}}let o=new Image;o.crossOrigin="anonymous",o.decoding="sync";let r=new Promise((y,C)=>{o.onload=()=>y(void 0),o.onerror=()=>C(new Error("image failed to load"))});if(s){let y=URL.createObjectURL(new Blob([s]));o.src=y;try{await r}finally{URL.revokeObjectURL(y)}}else o.src=e,await r;let i=o.naturalWidth,a=o.naturalHeight;if(!i||!a)throw new Error("image has no intrinsic size");let c=document.createElement("canvas");c.width=i,c.height=a;let h=c.getContext("2d",{willReadFrequently:!0});if(!h)throw new Error("2D canvas unavailable");h.drawImage(o,0,0);let p;try{p=h.getImageData(0,0,i,a)}catch{return t({code:"image-failed",message:`Image ${e} is cross-origin without CORS headers; add crossorigin="anonymous" and Access-Control-Allow-Origin. Skipped.`,element:n}),null}let f=p.data,d=new Uint8Array(i*a*3),u=new Uint8Array(i*a),w=!0;for(let y=0,C=0,O=0;y<f.length;y+=4,C+=3,O++){let R=f[y+3];R===0?d[C]=d[C+1]=d[C+2]=255:(d[C]=f[y],d[C+1]=f[y+1],d[C+2]=f[y+2]),u[O]=R,R!==255&&(w=!1)}return{key:e,width:i,height:a,jpeg:null,rgb:d,alpha:w?null:u}}function Fe(e){let t=2;for(;t+9<e.length;){if(e[t]!==255){t++;continue}let n=e[t+1];if(n===216||n>=208&&n<=215||n===1||n===255){t+=n===255?1:2;continue}let s=e[t+2]<<8|e[t+3];if(n>=192&&n<=195||n>=197&&n<=199||n>=201&&n<=203||n>=205&&n<=207)return{height:e[t+5]<<8|e[t+6],width:e[t+7]<<8|e[t+8],components:e[t+9]};if(n===218)break;t+=2+s}return null}function Nt(e){if(!e||e==="none")return null;let t=Ue(e);if(t.length!==1)return null;let n=/^url\((?:"([^"]*)"|'([^']*)'|([^)]*))\)$/.exec(t[0].trim());return n?n[1]??n[2]??n[3]??null:null}function Ue(e){let t=[],n=0,s="";for(let o of e)o==="("?n++:o===")"&&n--,o===","&&n===0?(t.push(s),s=""):s+=o;return s.trim()&&t.push(s),t}function ft(e,t,n,s,o){let r,i,a=s.trim();if(a==="cover"||a==="contain"){let d=a==="cover"?Math.max(e.w/t,e.h/n):Math.min(e.w/t,e.h/n);r=t*d,i=n*d}else{let[d="auto",u="auto"]=a.split(/\s+/),w=Lt(d,e.w),y=Lt(u,e.h);w===null&&y===null?(r=t,i=n):w===null?(i=y,r=t*i/n):y===null?(r=w,i=n*r/t):(r=w,i=y)}let[c="0%",h="0%"]=o.trim().split(/\s+/),p=e.x+jt(c,e.w-r),f=e.y+jt(h,e.h-i);return{x:p,y:f,w:r,h:i}}function Lt(e,t){return e==="auto"?null:e.endsWith("%")?parseFloat(e)/100*t:parseFloat(e)||0}function jt(e,t){return e==="left"||e==="top"?0:e==="center"?t/2:e==="right"||e==="bottom"?t:e.endsWith("%")?parseFloat(e)/100*t:parseFloat(e)||0}function zt(e){switch(e){case"contain":case"scale-down":return"contain";case"cover":return"cover";case"none":return"auto";default:return"100% 100%"}}var ke=new Set(["SCRIPT","STYLE","NOSCRIPT","TEMPLATE","HEAD","META","LINK","TITLE","BASE","IFRAME","CANVAS","VIDEO","AUDIO","SVG","OBJECT","EMBED"]);function Ee(e){let t=e.shadowRoot;if(t)return[...t.childNodes];if(e.tagName==="SLOT"){let n=e;if(typeof n.assignedNodes=="function")return n.assignedNodes({flatten:!0})}return[...e.childNodes]}var Pe=[["boxShadow",e=>e!=="none"],["textShadow",e=>e!=="none"],["filter",e=>e!=="none"],["backdropFilter",e=>e!=="none"&&e!==""],["writingMode",e=>e.startsWith("vertical")],["outlineStyle",e=>e!=="none"],["clipPath",e=>e!=="none"],["mixBlendMode",e=>e!=="normal"]];async function Ft(e,t){let n=e.ownerDocument.defaultView,s=n.scrollX,o=n.scrollY,r=[],i=r,a=[],c=[],h=[],p=null,f=0,d=new Set,u=new Set;function w(l,m){d.has(l)||(d.add(l),t.warn(m))}async function y(l,m){if(ke.has(l.tagName))return;let g=n.getComputedStyle(l);if(g.display==="none")return;let x=Ae(g.transform);if(x&&"style"in l){let S=l,F=S.getBoundingClientRect(),E=S.style.transform;S.style.transform="none",S.offsetWidth;let k=S.getBoundingClientRect(),[I,A]=Me(g.transformOrigin),N={x:k.left+I+s,y:k.top+A+o},W=r;r=[],await O(l,n.getComputedStyle(l),m);let b=r;r=W,S.style.transform=E,S.offsetWidth,r.push({type:"group",matrix:x,origin:N,items:b,top:F.top+o,bottom:F.bottom+o,z:C(g,m.z),seq:f++});return}await O(l,g,m)}function C(l,m){if(l.position!=="static"&&l.zIndex!=="auto"){let g=parseInt(l.zIndex,10);if(Number.isFinite(g))return g}return m}async function O(l,m,g){let x=C(m,g.z),S=parseFloat(m.opacity),F=g.alpha*(Number.isFinite(S)?S:1),E=m.visibility==="visible"&&F>0;if(m.display!=="contents"&&m.display!=="inline"){let P=l.getBoundingClientRect(),H=P.top+o,K=P.bottom+o;if(P.height>0){let V=m.breakBefore||m.pageBreakBefore,ee=m.breakAfter||m.pageBreakAfter;/^(page|always|left|right|recto|verso)$/.test(V)&&c.push(H),/^(page|always|left|right|recto|verso)$/.test(ee)&&c.push(K);let kt=m.breakInside||m.pageBreakInside;(kt==="avoid"||kt==="avoid-page"||m.display==="table-row"||m.display==="table-header-group"||m.display==="table-footer-group"||l.tagName==="IMG")&&a.push({top:H,bottom:K})}}let k=null;if(m.display==="table"||m.display==="inline-table"){let P=l.getBoundingClientRect();k={top:P.top+o,bottom:P.bottom+o,headTop:0,headBottom:0,headItems:[],footTop:0,footBottom:0,footItems:[]},h.push(k)}let I=p;k&&(p=k);let A=m.display==="table-header-group"&&p&&!p.headItems.length,N=m.display==="table-footer-group"&&p&&!p.footItems.length,W=A||N?r.length:-1,b=m.overflowX!=="visible"||m.overflowY!=="visible",T=null,B=null;if(b&&m.display!=="inline"&&m.display!=="contents"&&l!==e){let P=l.getBoundingClientRect();B=z(P,m,"padding-box",Gt(m,P))}if(E&&m.display!=="contents"){R(l,m);let P=m.display==="inline"?[...l.getClientRects()]:[l.getBoundingClientRect()],H=m.borderCollapse==="collapse"&&/^table/.test(m.display)&&m.display!=="table-caption",K=P.length===1?Gt(m,P[0]):null;for(let V of P)V.width<=0&&V.height<=0||(D(V,m,F,x,K),await L(l,V,m,F,x,K),X(V,m,F,x,H,K));l.tagName==="IMG"&&P[0]&&await j(l,P[0],m,F,x,K)}let v=g.decorations,G=m.textDecorationLine;if(G&&G!=="none"){let P=st(m.textDecorationColor)??st(m.color)??{r:0,g:0,b:0,a:1};v=[...v,{line:G,color:P}]}B&&(T=r,r=[]);let Z={z:x,alpha:F,decorations:v};for(let P of Ee(l))P.nodeType===Node.TEXT_NODE?E&&et(P,l,m,Z):P.nodeType===Node.ELEMENT_NODE&&await y(P,Z);if(B&&T){let P=r.filter(H=>Ie(H,B));r=T,P.length&&r.push({type:"clip",box:B,items:P,top:B.y,bottom:B.y+B.h,z:x,seq:f++})}if((A||N)&&p&&W>=0){let P=l.getBoundingClientRect(),H=r.slice(W);A?(p.headTop=P.top+o,p.headBottom=P.bottom+o,p.headItems=H):(p.footTop=P.top+o,p.footBottom=P.bottom+o,p.footItems=H)}p=I}function R(l,m){for(let[g,x]of Pe){let S=String(m[g]??"");x(S)&&w(`css:${g}`,{code:"unsupported-css",message:`CSS property "${Ht(g)}" is not supported in this version and will be ignored (first seen on <${l.tagName.toLowerCase()}>: ${S})`,element:l,property:Ht(g)})}/^matrix3d/.test(m.transform)&&w("css:transform3d",{code:"unsupported-css",message:"3D transforms are not supported; the element is drawn untransformed",element:l,property:"transform"})}function D(l,m,g,x,S){let F=st(m.backgroundColor);if(!F||F.a<=0)return;let E={type:"rect",x:l.left+s,y:l.top+o,w:l.width,h:l.height,color:at(F,g),z:x,seq:f++};S&&(E.radius=S),r.push(E)}async function L(l,m,g,x,S,F){if(g.backgroundImage==="none")return;let E=Nt(g.backgroundImage);if(!E){w("css:backgroundImage",{code:"unsupported-css",message:`background-image "${g.backgroundImage}" is not supported (only a single url() is); ignored`,element:l,property:"background-image"});return}let k=await Ct(new URL(E,l.ownerDocument.baseURI).href,t.warn,l);if(!k)return;g.backgroundRepeat!=="no-repeat"&&w("css:backgroundRepeat",{code:"unsupported-css",message:`background-repeat "${g.backgroundRepeat}" is not supported; drawn once as no-repeat`,element:l,property:"background-repeat"});let I=z(m,g,g.backgroundClip||"border-box",F),A=z(m,g,g.backgroundOrigin||"padding-box",null),N=ft(A,k.width,k.height,g.backgroundSize,g.backgroundPosition);r.push({type:"image",...N,image:k,clip:I,alpha:x,z:S,seq:f++})}async function j(l,m,g,x,S,F){let E=l.currentSrc||l.src;if(!E)return;let k=await Ct(E,t.warn,l);if(!k)return;let I=z(m,g,"content-box",F),A=ft(I,k.width,k.height,zt(g.objectFit),g.objectPosition);g.objectFit==="scale-down"&&(A.w>k.width||A.h>k.height)&&Object.assign(A,ft(I,k.width,k.height,"auto",g.objectPosition)),r.push({type:"image",...A,image:k,clip:I,alpha:x,z:S,seq:f++})}function z(l,m,g,x){let S=l.left+s,F=l.top+o,E=l.width,k=l.height;if(g==="padding-box"||g==="content-box"){let A=q(m.borderTopWidth),N=q(m.borderRightWidth),W=q(m.borderBottomWidth),b=q(m.borderLeftWidth);S+=b,F+=A,E-=b+N,k-=A+W,x&&(x=x.map(T=>Math.max(0,T-Math.max(A,N,W,b))))}if(g==="content-box"){let A=q(m.paddingTop),N=q(m.paddingRight),W=q(m.paddingBottom),b=q(m.paddingLeft);S+=b,F+=A,E-=b+N,k-=A+W}let I={x:S,y:F,w:Math.max(0,E),h:Math.max(0,k)};return x&&x.some(A=>A>0)&&(I.radius=x),I}function X(l,m,g,x,S,F){let E=l.left+s,k=l.top+o,I=l.width,A=l.height,b=["Top","Right","Bottom","Left"].map(T=>({side:T,width:q(m[`border${T}Width`]),style:m[`border${T}Style`],color:st(m[`border${T}Color`])})).filter(T=>T.width>0&&T.style!=="none"&&T.style!=="hidden"&&T.color&&T.color.a>0);if(b.length){if(F&&F.some(T=>T>0)){let T=b[0];if(b.length===4&&b.every(v=>v.width===T.width&&v.style===T.style&&JSON.stringify(v.color)===JSON.stringify(T.color))){let v=T.width;r.push({type:"stroke-rrect",x:E+v/2,y:k+v/2,w:I-v,h:A-v,radius:F.map(G=>Math.max(0,G-v/2)),width:v,color:at(T.color,g),dash:Wt(T.style,v),z:x,seq:f++});return}w("css:borderRadiusNonUniform",{code:"unsupported-css",message:"border-radius with non-uniform borders is approximated with straight borders",property:"border-radius"})}for(let T of b){let B=T.width,v=at(T.color,g),G=T.side==="Top"||T.side==="Bottom",Z=T.side==="Top"||T.side==="Left"?1:-1,P=T.side==="Top"?k:T.side==="Bottom"?k+A:T.side==="Left"?E:E+I,H=Wt(T.style,B);if(H){let V=S?P:P+B/2*Z;r.push({type:"line",x1:G?E:V,y1:G?V:k,x2:G?E+I:V,y2:G?V:k+A,width:B,color:v,dash:H,z:x,seq:f++});continue}let K=S?P-B/2:Z>0?P:P-B;G?r.push({type:"rect",x:E,y:K,w:I,h:B,color:v,z:x,seq:f++}):r.push({type:"rect",x:K,y:k,w:B,h:A,color:v,z:x,seq:f++})}}}function et(l,m,g,x){let S=l.data;if(!S)return;if(!/\S/.test(S)&&!S.includes("\xA0")){let b=l.ownerDocument.createRange();if(b.selectNodeContents(l),![...b.getClientRects()].some(T=>T.width>0))return}let F=at(st(g.color)??{r:0,g:0,b:0,a:1},x.alpha),E=q(g.fontSize);if(E<=0)return;let k=It(g.fontFamily),I=Rt(g.fontWeight),A=g.fontStyle==="italic"||g.fontStyle==="oblique"?"italic":"normal",N=t.registry.match(k,I,A)??t.registry.match(t.fontFallback,I,A);if(!N){let b=k.join(",");u.has(b)||(u.add(b),t.warn({code:"missing-font",message:`No registered font matches font-family "${g.fontFamily}" and no fallback is available; text will be skipped`,element:m}));return}let W=Ot(l,g,{registry:t.registry,families:k,fallback:t.fontFallback,primary:N,weight:I,fstyle:A,size:E,textMeasure:t.textMeasure,warn:t.warn,element:m});for(let b of W)if(b.glyphs.length){a.push({top:b.top+o,bottom:b.bottom+o}),r.push({type:"text",x:b.glyphs[0]?.x??0,y:b.baseline+o,top:b.top+o,bottom:b.bottom+o,size:E,color:F,font:b.font,glyphs:b.glyphs.map(T=>({...T,x:T.x+s})),z:x.z,seq:f++});for(let T of x.decorations){let B=b.glyphs[0],v=b.glyphs[b.glyphs.length-1];if(!B||!v)continue;let G=B.x+s,Z=v.x+v.advance+s,P=Math.max(1,E/14),H=at(T.color,x.alpha);T.line.includes("underline")&&r.push({type:"rect",x:G,y:b.baseline+o+E*.08,w:Z-G,h:P,color:H,z:x.z,seq:f++}),T.line.includes("line-through")&&r.push({type:"rect",x:G,y:b.baseline+o-E*.3,w:Z-G,h:P,color:H,z:x.z,seq:f++})}}}await y(e,{z:0,alpha:1,decorations:[]}),qt(i);let $=e.getBoundingClientRect().bottom+o;for(let l of i)l.type==="rect"||l.type==="stroke-rrect"||l.type==="image"?$=Math.max($,l.y+l.h):l.type==="line"?$=Math.max($,l.y1,l.y2):(l.type==="text"||l.type==="group"||l.type==="clip")&&($=Math.max($,l.bottom));return{items:i,atoms:a,breaks:c,tables:h,height:$}}function qt(e){e.sort((t,n)=>t.z-n.z||t.seq-n.seq);for(let t of e)(t.type==="group"||t.type==="clip")&&qt(t.items)}function Wt(e,t){return e==="dashed"?[t*3,t*3]:e==="dotted"?[t,t]:null}function Gt(e,t){let n=o=>{let r=o.trim().split(/\s+/)[0]??"0px";return r.endsWith("%")?parseFloat(r)/100*t.width:q(r)},s=[n(e.borderTopLeftRadius),n(e.borderTopRightRadius),n(e.borderBottomRightRadius),n(e.borderBottomLeftRadius)];return s.some(o=>o>0)?s:null}function Ae(e){if(!e||e==="none")return null;let t=/^matrix\(([^)]+)\)$/.exec(e.trim());if(!t)return null;let n=t[1].split(",").map(h=>parseFloat(h));if(n.length!==6||n.some(h=>!Number.isFinite(h)))return null;let[s,o,r,i,a,c]=n;return s===1&&o===0&&r===0&&i===1&&a===0&&c===0?null:[s,o,r,i,a,c]}function Me(e){let t=e.trim().split(/\s+/);return[q(t[0]??"0"),q(t[1]??"0")]}function Ie(e,t){let n,s,o,r;if(e.type==="rect"||e.type==="stroke-rrect"||e.type==="image")n=e.x,s=e.y,o=e.x+e.w,r=e.y+e.h;else if(e.type==="line")n=Math.min(e.x1,e.x2)-e.width,s=Math.min(e.y1,e.y2)-e.width,o=Math.max(e.x1,e.x2)+e.width,r=Math.max(e.y1,e.y2)+e.width;else if(e.type==="text"){let i=e.glyphs[e.glyphs.length-1];n=e.x,s=e.top,o=i?i.x+i.advance:e.x,r=e.bottom}else if(e.type==="clip")n=e.box.x,s=e.box.y,o=e.box.x+e.box.w,r=e.box.y+e.box.h;else return!0;return o>t.x&&n<t.x+t.w&&r>t.y&&s<t.y+t.h}function at(e,t){return t===1?e:{...e,a:e.a*t}}function Ht(e){return e.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}function Re(){return typeof CompressionStream=="function"}async function Xt(e){if(!Re())return null;try{let t=new CompressionStream("deflate"),n=t.writable.getWriter();n.write(e),n.close();let s=await new Response(t.readable).arrayBuffer();return new Uint8Array(s)}catch{return null}}var lt=class{constructor(t){this.id=t}toString(){return`${this.id} 0 R`}},J=class{constructor(t){this.name=t}toString(){let t="/";for(let n of this.name){let s=n.charCodeAt(0);if(s<33||s>126||"#/%()<>[]{}".includes(n))for(let o of new TextEncoder().encode(n))t+="#"+o.toString(16).padStart(2,"0");else t+=n}return t}},Q=class{constructor(t){this.text=t}toString(){return this.text}};function nt(e){if(/^[\x20-\x7e]*$/.test(e))return new Q("("+e.replace(/[\\()]/g,n=>"\\"+n)+")");let t="FEFF";for(let n=0;n<e.length;n++)t+=e.charCodeAt(n).toString(16).padStart(4,"0");return new Q("<"+t+">")}function Vt(e){let t=i=>String(i).padStart(2,"0"),n=-e.getTimezoneOffset(),s=n>=0?"+":"-",o=t(Math.floor(Math.abs(n)/60)),r=t(Math.abs(n)%60);return new Q(`(D:${e.getFullYear()}${t(e.getMonth()+1)}${t(e.getDate())}${t(e.getHours())}${t(e.getMinutes())}${t(e.getSeconds())}${s}${o}'${r}')`)}function ht(e){if(e===null)return"null";if(typeof e=="number")return U(e);if(typeof e=="boolean")return e?"true":"false";if(typeof e=="string")return new J(e).toString();if(e instanceof lt||e instanceof J||e instanceof Q)return e.toString();if(Array.isArray(e))return"["+e.map(ht).join(" ")+"]";let t=[];for(let[n,s]of Object.entries(e))s!==void 0&&t.push(new J(n).toString()+" "+ht(s));return"<< "+t.join(" ")+" >>"}var dt=class{constructor(t={}){this.objects=[null],this.compress=t.compress??!0,this.version=t.version??"1.7"}reserve(){return this.objects.push({value:null}),new lt(this.objects.length-1)}set(t,n,s){this.objects[t.id]={value:n,stream:s}}add(t){let n=this.reserve();return this.set(n,t),n}async addStream(t,n,s={}){let o=this.reserve();return await this.setStream(o,t,n,s),o}async setStream(t,n,s,o={}){let r=s,i={...n};if((o.compress??this.compress)&&!("Filter"in i)){let c=await Xt(s);c&&c.length<s.length&&(r=c,i.Filter="FlateDecode")}i.Length=r.length,this.set(t,i,r)}build(t,n){let s=new TextEncoder,o=[],r=0,i=f=>{let d=typeof f=="string"?s.encode(f):f;o.push(d),r+=d.length};i(ut([s.encode(`%PDF-${this.version}
4
+ `+Tt(r.adoptedStyleSheets);i.trim()&&s.unshift(i),o=r.host.getRootNode()}return s.map(r=>`<style>${n?ot(r):r}</style>`).join("")}function ae(e,t,n){let s=Math.max(e.documentElement.scrollWidth,e.body.scrollWidth),o=s-t;if(o<1)return;let r=i=>Math.round(i/96*25.4*10)/10;n({code:"other",message:`Content is ${Math.round(o)}px (${r(o)}mm) wider than the page content area (${Math.round(s)}px vs ${Math.round(t)}px); the right side will be clipped. Common causes: a fixed width plus padding/border without box-sizing: border-box, or a table that cannot shrink.`})}var ce=new Set(["AREA","BASE","BR","COL","EMBED","HR","IMG","INPUT","LINK","META","SOURCE","TRACK","WBR"]);function fe(e,t){let n=e===document.body||e===document.documentElement,s=le(n?document.body:e);if(!s.length)return n?document.body.innerHTML:e.outerHTML;let o=n?document.body:e;if(typeof o.getHTML!="function")return t({code:"unsupported-css",message:"This browser lacks Element.getHTML(); shadow DOM content cannot be serialized and will be missing from the PDF. Pass an element inside the shadow root instead.",element:e}),n?document.body.innerHTML:e.outerHTML;let r=he(s);try{let i={serializableShadowRoots:!0,shadowRoots:s},a=o.getHTML(i);if(n)return a;let c=e.tagName.toLowerCase();return ce.has(e.tagName)?e.outerHTML:`<${c}${xt(e)}>${a}</${c}>`}finally{r()}}function le(e){let t=[],n=s=>{s instanceof Element&&s.shadowRoot&&(t.push(s.shadowRoot),n(s.shadowRoot));for(let o of s.children)n(o)};return n(e),t}function he(e){let t=[];for(let n of e){let s=Tt(n.adoptedStyleSheets);if(!s)continue;let o=document.createElement("style");o.setAttribute("data-rhtp-adopted",""),o.textContent=s,n.insertBefore(o,n.firstChild),t.push(o)}return()=>{for(let n of t)n.remove()}}function Tt(e){if(!e||!e.length)return"";let t=[];for(let n of e)try{for(let s of n.cssRules)t.push(s.cssText)}catch{}return t.join(`
5
+ `)}function de(e,t){let n=t.customElements,s=t.HTMLElement;if(!n||!s)return;let o=new Set,r=i=>{for(let a of i.querySelectorAll("*"))a.tagName.includes("-")&&!a.hasAttribute("is")&&o.add(a.tagName.toLowerCase()),a.shadowRoot&&r(a.shadowRoot)};r(e);for(let i of o)if(!n.get(i))try{n.define(i,class extends s{})}catch{}}function ue(e){return e.replace(/<style([^>]*)>([\s\S]*?)<\/style>/gi,(t,n,s)=>`<style${n}>${ot(s)}</style>`)}function ot(e){let t="",n=0;for(;n<e.length;){let s=/@media\s*([^{]+)\{/g;s.lastIndex=n;let o=s.exec(e);if(!o){t+=e.slice(n);break}t+=e.slice(n,o.index);let r=1,i=s.lastIndex;for(;i<e.length&&r>0;)e[i]==="{"?r++:e[i]==="}"&&r--,i++;let a=o[1].trim(),c=e.slice(s.lastIndex,i-1);/\bprint\b/.test(a)?t+=c:/^\s*(only\s+)?screen\b/.test(a)&&!/\band\b/.test(a)?t+="":t+=e.slice(o.index,i),n=i}return t}function xt(e){let t="";for(let n of e.attributes)/^on/i.test(n.name)||(t+=` ${n.name}="${it(n.value)}"`);return t}function it(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}async function pe(e){let t=[...e.querySelectorAll('link[rel~="stylesheet"]')];await Promise.all(t.map(n=>new Promise(s=>{let o=n;if(o.sheet)return s(void 0);o.addEventListener("load",()=>s(void 0),{once:!0}),o.addEventListener("error",()=>s(void 0),{once:!0}),setTimeout(()=>s(void 0),1e4)})))}async function me(e){if(e.body.offsetHeight,e.fonts){await e.fonts.ready;let t=[...e.fonts].filter(n=>n.status==="loading").map(n=>n.loaded.catch(()=>{}));t.length&&await Promise.all(t),await e.fonts.ready}}async function ge(e){let t=[...e.images];await Promise.all(t.map(n=>n.complete?n.decode().catch(()=>{}):new Promise(s=>{n.addEventListener("load",()=>n.decode().catch(()=>{}).then(s),{once:!0}),n.addEventListener("error",()=>s(void 0),{once:!0}),setTimeout(()=>s(void 0),1e4)})))}function ye(e,t){let n=e.defaultView;if(!n)return;let s=[];for(let i of be(e.body))for(let a of["before","after"]){let c=n.getComputedStyle(i,`::${a}`),h=c.content;if(!h||h==="none"||h==="normal"||c.display==="none")continue;let p=we(h);if(p===null){t({code:"unsupported-css",message:`::${a} content "${h}" is not supported (only quoted strings are); the pseudo-element is skipped`,element:i,property:"content"});continue}let f=[];for(let d=0;d<c.length;d++){let u=c[d];u==="content"||u.startsWith("-webkit-")||u.startsWith("-moz-")||f.push([u,c.getPropertyValue(u)])}s.push({el:i,pseudo:a,text:p,styles:f})}if(!s.length)return;let o='[data-rhtp-pseudo-host~="before"]::before{content:none!important;display:none!important}[data-rhtp-pseudo-host~="after"]::after{content:none!important;display:none!important}',r=e.createElement("style");r.setAttribute("data-rhtp-pseudo",""),r.textContent=o,e.head.appendChild(r);for(let i of new Set(s.map(a=>a.el.getRootNode()).filter(a=>a!==e))){let a=e.createElement("style");a.setAttribute("data-rhtp-pseudo",""),a.textContent=o,i.appendChild(a)}for(let i of s){let a=e.createElement("span");a.setAttribute("data-rhtp-pseudo",i.pseudo);for(let[h,p]of i.styles)a.style.setProperty(h,p);a.textContent=i.text;let c=(i.el.getAttribute("data-rhtp-pseudo-host")??"").split(" ").filter(Boolean);c.push(i.pseudo),i.el.setAttribute("data-rhtp-pseudo-host",c.join(" ")),i.pseudo==="before"?i.el.insertBefore(a,i.el.firstChild):i.el.appendChild(a)}}function be(e){let t=[],n=s=>{for(let o of s.querySelectorAll("*"))t.push(o),o.shadowRoot&&n(o.shadowRoot)};return n(e),t}function we(e){let t="",n=0,s=e.trim();for(;n<s.length;){let o=s[n];if(o===" "||o===" "){n++;continue}if(o!=='"'&&o!=="'")return null;let r=o;for(n++;n<s.length&&s[n]!==r;)if(s[n]==="\\"){n++;let i=/^[0-9a-fA-F]{1,6}/.exec(s.slice(n));i?(t+=String.fromCodePoint(parseInt(i[0],16)),n+=i[0].length,s[n]===" "&&n++):(t+=s[n]??"",n++)}else t+=s[n],n++;n++}return t}var _=2.834645669291339,$t={A3:{width:297*_,height:420*_},A4:{width:210*_,height:297*_},A5:{width:148*_,height:210*_},B4:{width:257*_,height:364*_},B5:{width:182*_,height:257*_},Letter:{width:612,height:792},Legal:{width:612,height:1008}};function Y(e){if(typeof e=="number")return e*.75;let t=/^\s*(-?[\d.]+)\s*([a-z%]*)\s*$/i.exec(e);if(!t)throw new Error(`Invalid CSS length: ${e}`);let n=parseFloat(t[1]);switch((t[2]??"").toLowerCase()){case"":case"px":return n*.75;case"pt":return n;case"mm":return n*_;case"cm":return n*_*10;case"in":return n*72;case"pc":return n*12;default:throw new Error(`Unsupported CSS unit: ${e}`)}}function q(e){let t=parseFloat(e);return Number.isFinite(t)?t:0}function st(e){if(!e)return null;let t=e.trim();if(t==="transparent")return{r:0,g:0,b:0,a:0};let n=/^rgba?\(\s*([\d.]+)\s*[, ]\s*([\d.]+)\s*[, ]\s*([\d.]+)\s*(?:[,/]\s*([\d.]+%?)\s*)?\)$/i.exec(t);if(n){let s=n[4]===void 0?1:n[4].endsWith("%")?parseFloat(n[4])/100:parseFloat(n[4]);return{r:tt(parseFloat(n[1])/255),g:tt(parseFloat(n[2])/255),b:tt(parseFloat(n[3])/255),a:tt(s)}}if(n=/^color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s*(?:\/\s*([\d.]+%?)\s*)?\)$/i.exec(t),n){let s=n[4]===void 0?1:n[4].endsWith("%")?parseFloat(n[4])/100:parseFloat(n[4]);return{r:tt(parseFloat(n[1])),g:tt(parseFloat(n[2])),b:tt(parseFloat(n[3])),a:tt(s)}}if(n=/^#([0-9a-f]{3,8})$/i.exec(t),n){let s=n[1];(s.length===3||s.length===4)&&(s=s.split("").map(r=>r+r).join(""));let o=parseInt(s.padEnd(8,"f"),16);return{r:(o>>>24&255)/255,g:(o>>>16&255)/255,b:(o>>>8&255)/255,a:(o&255)/255}}return null}function tt(e){return e<0?0:e>1?1:e}function U(e){if(!Number.isFinite(e))return"0";let t=e.toFixed(3),n=t.includes(".")?t.replace(/\.?0+$/,""):t;return n===""||n==="-0"||n==="-"?"0":n}var xe=new Set([32,9,10,13,12,160,12288,8194,8195,8201,8202,8239,8287]);function Ot(e,t,n){let s=e.ownerDocument,o=$e(e.data,t.textTransform),r=s.createRange(),i=Ce(s,t),a=[],c=null,h=NaN,p=new Set;for(let f=0;f<o.length;){let d=o.codePointAt(f),u=d>65535?2:1,w=f+u;r.setStart(e,f),r.setEnd(e,Math.min(w,e.data.length));let y=Se(r.getClientRects());if(f=w,!y)continue;let C=Te(d,n,p);if(!C)continue;let{font:O,gid:R,cpForUnicode:D}=C,L=y.top;(!c||c.font!==O||Math.abs(L-h)>.5)&&(c={font:O,baseline:L+i,top:L,bottom:y.bottom,glyphs:[]},h=L,a.push(c)),c.top=Math.min(c.top,L),c.bottom=Math.max(c.bottom,y.bottom);let j=(O.parsed.advances[R]??0)*n.size/O.parsed.unitsPerEm;c.glyphs.push({gid:R,cp:D,x:y.left,advance:j})}return a}function Se(e){let t=null;for(let n of e)n.width>.01&&(!t||n.width>t.width)&&(t=n);return t}function Te(e,t,n){let s=(i,a)=>{let c=i?.parsed.cmap.get(a);return i&&c?{font:i,gid:c,cpForUnicode:e}:null};if(xe.has(e))return s(t.primary,e)??s(t.primary,32)??s(t.registry.anyWithGlyph(32,t.weight,t.fstyle),32);let o=s(t.primary,e);if(o||(o=s(t.registry.match(t.families,t.weight,t.fstyle,e),e),o)||(o=s(t.registry.match(t.fallback,t.weight,t.fstyle,e),e),o)||(o=s(t.registry.anyWithGlyph(e,t.weight,t.fstyle),e),o))return o;n.has(e)||(n.add(e),t.warn({code:"missing-glyph",message:`No registered font has a glyph for U+${e.toString(16).toUpperCase().padStart(4,"0")} "${String.fromCodePoint(e)}"; substituted with U+25A1`,element:t.element,text:String.fromCodePoint(e)}));let r=s(t.primary,9633)??s(t.registry.anyWithGlyph(9633,t.weight,t.fstyle),9633);return r?{...r,cpForUnicode:e}:null}function $e(e,t){if(!t||t==="none")return e;let n=e;return t.includes("uppercase")?n=e.toUpperCase():t.includes("lowercase")?n=e.toLowerCase():t.includes("capitalize")&&(n=e.replace(new RegExp("(^|\\s)(\\p{L})","gu"),(s,o,r)=>o+r.toUpperCase())),n.length===e.length?n:e}var Dt=new WeakMap;function Ce(e,t){let n=[t.fontFamily,t.fontSize,t.fontWeight,t.fontStyle,t.fontStretch,t.fontVariant,t.fontFeatureSettings].join("|"),s=Dt.get(e);s||(s=new Map,Dt.set(e,s));let o=s.get(n);if(o!==void 0)return o;let r=e.createElement("div");r.setAttribute("data-rhtp-probe",""),r.style.cssText="position:absolute;left:0;top:0;visibility:hidden;white-space:pre;line-height:normal;margin:0;padding:0;border:0;letter-spacing:0;text-indent:0;",r.style.fontFamily=t.fontFamily,r.style.fontSize=t.fontSize,r.style.fontWeight=t.fontWeight,r.style.fontStyle=t.fontStyle,r.style.fontStretch=t.fontStretch,r.style.fontVariant=t.fontVariant,r.style.fontFeatureSettings=t.fontFeatureSettings;let i=e.createTextNode("Ag\u3042");r.appendChild(i);let a=e.createElement("span");a.style.cssText="display:inline-block;width:0;height:0;vertical-align:baseline;margin:0;padding:0;border:0;",r.appendChild(a),e.body.appendChild(r);let c=e.createRange();c.selectNodeContents(i);let h=c.getBoundingClientRect(),f=a.getBoundingClientRect().bottom-h.top;r.remove();let d=Number.isFinite(f)&&f>0?f:parseFloat(t.fontSize)*.8;return s.set(n,d),d}var vt=new Map;function Ct(e,t,n){let s=vt.get(e);return s||(s=Fe(e,t,n).catch(o=>(t({code:"image-failed",message:`Failed to load image ${e}: ${o instanceof Error?o.message:String(o)}`,element:n}),null)),vt.set(e,s)),s}async function Fe(e,t,n){let s=null;try{let y=await fetch(e,{mode:"cors",credentials:"same-origin"});y.ok&&(s=new Uint8Array(await y.arrayBuffer()))}catch{s=null}if(s&&s[0]===255&&s[1]===216){let y=Ue(s);if(y&&y.components===3)return{key:e,width:y.width,height:y.height,jpeg:s,rgb:null,alpha:null}}let o=new Image;o.crossOrigin="anonymous",o.decoding="sync";let r=new Promise((y,C)=>{o.onload=()=>y(void 0),o.onerror=()=>C(new Error("image failed to load"))});if(s){let y=URL.createObjectURL(new Blob([s]));o.src=y;try{await r}finally{URL.revokeObjectURL(y)}}else o.src=e,await r;let i=o.naturalWidth,a=o.naturalHeight;if(!i||!a)throw new Error("image has no intrinsic size");let c=document.createElement("canvas");c.width=i,c.height=a;let h=c.getContext("2d",{willReadFrequently:!0});if(!h)throw new Error("2D canvas unavailable");h.drawImage(o,0,0);let p;try{p=h.getImageData(0,0,i,a)}catch{return t({code:"image-failed",message:`Image ${e} is cross-origin without CORS headers; add crossorigin="anonymous" and Access-Control-Allow-Origin. Skipped.`,element:n}),null}let f=p.data,d=new Uint8Array(i*a*3),u=new Uint8Array(i*a),w=!0;for(let y=0,C=0,O=0;y<f.length;y+=4,C+=3,O++){let R=f[y+3];R===0?d[C]=d[C+1]=d[C+2]=255:(d[C]=f[y],d[C+1]=f[y+1],d[C+2]=f[y+2]),u[O]=R,R!==255&&(w=!1)}return{key:e,width:i,height:a,jpeg:null,rgb:d,alpha:w?null:u}}function Ue(e){let t=2;for(;t+9<e.length;){if(e[t]!==255){t++;continue}let n=e[t+1];if(n===216||n>=208&&n<=215||n===1||n===255){t+=n===255?1:2;continue}let s=e[t+2]<<8|e[t+3];if(n>=192&&n<=195||n>=197&&n<=199||n>=201&&n<=203||n>=205&&n<=207)return{height:e[t+5]<<8|e[t+6],width:e[t+7]<<8|e[t+8],components:e[t+9]};if(n===218)break;t+=2+s}return null}function Nt(e){if(!e||e==="none")return null;let t=ke(e);if(t.length!==1)return null;let n=/^url\((?:"([^"]*)"|'([^']*)'|([^)]*))\)$/.exec(t[0].trim());return n?n[1]??n[2]??n[3]??null:null}function ke(e){let t=[],n=0,s="";for(let o of e)o==="("?n++:o===")"&&n--,o===","&&n===0?(t.push(s),s=""):s+=o;return s.trim()&&t.push(s),t}function ft(e,t,n,s,o){let r,i,a=s.trim();if(a==="cover"||a==="contain"){let d=a==="cover"?Math.max(e.w/t,e.h/n):Math.min(e.w/t,e.h/n);r=t*d,i=n*d}else{let[d="auto",u="auto"]=a.split(/\s+/),w=Lt(d,e.w),y=Lt(u,e.h);w===null&&y===null?(r=t,i=n):w===null?(i=y,r=t*i/n):y===null?(r=w,i=n*r/t):(r=w,i=y)}let[c="0%",h="0%"]=o.trim().split(/\s+/),p=e.x+jt(c,e.w-r),f=e.y+jt(h,e.h-i);return{x:p,y:f,w:r,h:i}}function Lt(e,t){return e==="auto"?null:e.endsWith("%")?parseFloat(e)/100*t:parseFloat(e)||0}function jt(e,t){return e==="left"||e==="top"?0:e==="center"?t/2:e==="right"||e==="bottom"?t:e.endsWith("%")?parseFloat(e)/100*t:parseFloat(e)||0}function zt(e){switch(e){case"contain":case"scale-down":return"contain";case"cover":return"cover";case"none":return"auto";default:return"100% 100%"}}var Ee=new Set(["SCRIPT","STYLE","NOSCRIPT","TEMPLATE","HEAD","META","LINK","TITLE","BASE","IFRAME","CANVAS","VIDEO","AUDIO","SVG","OBJECT","EMBED"]);function Pe(e){let t=e.shadowRoot;if(t)return[...t.childNodes];if(e.tagName==="SLOT"){let n=e;if(typeof n.assignedNodes=="function")return n.assignedNodes({flatten:!0})}return[...e.childNodes]}var Me=[["boxShadow",e=>e!=="none"],["textShadow",e=>e!=="none"],["filter",e=>e!=="none"],["backdropFilter",e=>e!=="none"&&e!==""],["writingMode",e=>e.startsWith("vertical")],["outlineStyle",e=>e!=="none"],["clipPath",e=>e!=="none"],["mixBlendMode",e=>e!=="normal"]];async function Ft(e,t){let n=e.ownerDocument.defaultView,s=n.scrollX,o=n.scrollY,r=[],i=r,a=[],c=[],h=[],p=null,f=0,d=new Set,u=new Set;function w(l,m){d.has(l)||(d.add(l),t.warn(m))}async function y(l,m){if(Ee.has(l.tagName))return;let g=n.getComputedStyle(l);if(g.display==="none")return;let x=Ae(g.transform);if(x&&"style"in l){let S=l,F=S.getBoundingClientRect(),E=S.style.transform;S.style.transform="none",S.offsetWidth;let k=S.getBoundingClientRect(),[I,M]=Ie(g.transformOrigin),N={x:k.left+I+s,y:k.top+M+o},W=r;r=[],await O(l,n.getComputedStyle(l),m);let b=r;r=W,S.style.transform=E,S.offsetWidth,r.push({type:"group",matrix:x,origin:N,items:b,top:F.top+o,bottom:F.bottom+o,z:C(g,m.z),seq:f++});return}await O(l,g,m)}function C(l,m){if(l.position!=="static"&&l.zIndex!=="auto"){let g=parseInt(l.zIndex,10);if(Number.isFinite(g))return g}return m}async function O(l,m,g){let x=C(m,g.z),S=parseFloat(m.opacity),F=g.alpha*(Number.isFinite(S)?S:1),E=m.visibility==="visible"&&F>0;if(m.display!=="contents"&&m.display!=="inline"){let P=l.getBoundingClientRect(),H=P.top+o,K=P.bottom+o;if(P.height>0){let V=m.breakBefore||m.pageBreakBefore,ee=m.breakAfter||m.pageBreakAfter;/^(page|always|left|right|recto|verso)$/.test(V)&&c.push(H),/^(page|always|left|right|recto|verso)$/.test(ee)&&c.push(K);let kt=m.breakInside||m.pageBreakInside;(kt==="avoid"||kt==="avoid-page"||m.display==="table-row"||m.display==="table-header-group"||m.display==="table-footer-group"||l.tagName==="IMG")&&a.push({top:H,bottom:K})}}let k=null;if(m.display==="table"||m.display==="inline-table"){let P=l.getBoundingClientRect();k={top:P.top+o,bottom:P.bottom+o,headTop:0,headBottom:0,headItems:[],footTop:0,footBottom:0,footItems:[]},h.push(k)}let I=p;k&&(p=k);let M=m.display==="table-header-group"&&p&&!p.headItems.length,N=m.display==="table-footer-group"&&p&&!p.footItems.length,W=M||N?r.length:-1,b=m.overflowX!=="visible"||m.overflowY!=="visible",T=null,B=null;if(b&&m.display!=="inline"&&m.display!=="contents"&&l!==e){let P=l.getBoundingClientRect();B=z(P,m,"padding-box",Gt(m,P))}if(E&&m.display!=="contents"){R(l,m);let P=m.display==="inline"?[...l.getClientRects()]:[l.getBoundingClientRect()],H=m.borderCollapse==="collapse"&&/^table/.test(m.display)&&m.display!=="table-caption",K=P.length===1?Gt(m,P[0]):null;for(let V of P)V.width<=0&&V.height<=0||(D(V,m,F,x,K),await L(l,V,m,F,x,K),X(V,m,F,x,H,K));l.tagName==="IMG"&&P[0]&&await j(l,P[0],m,F,x,K)}let v=g.decorations,G=m.textDecorationLine;if(G&&G!=="none"){let P=st(m.textDecorationColor)??st(m.color)??{r:0,g:0,b:0,a:1};v=[...v,{line:G,color:P}]}B&&(T=r,r=[]);let Z={z:x,alpha:F,decorations:v};for(let P of Pe(l))P.nodeType===Node.TEXT_NODE?E&&et(P,l,m,Z):P.nodeType===Node.ELEMENT_NODE&&await y(P,Z);if(B&&T){let P=r.filter(H=>Re(H,B));r=T,P.length&&r.push({type:"clip",box:B,items:P,top:B.y,bottom:B.y+B.h,z:x,seq:f++})}if((M||N)&&p&&W>=0){let P=l.getBoundingClientRect(),H=r.slice(W);M?(p.headTop=P.top+o,p.headBottom=P.bottom+o,p.headItems=H):(p.footTop=P.top+o,p.footBottom=P.bottom+o,p.footItems=H)}p=I}function R(l,m){for(let[g,x]of Me){let S=String(m[g]??"");x(S)&&w(`css:${g}`,{code:"unsupported-css",message:`CSS property "${Ht(g)}" is not supported in this version and will be ignored (first seen on <${l.tagName.toLowerCase()}>: ${S})`,element:l,property:Ht(g)})}/^matrix3d/.test(m.transform)&&w("css:transform3d",{code:"unsupported-css",message:"3D transforms are not supported; the element is drawn untransformed",element:l,property:"transform"})}function D(l,m,g,x,S){let F=st(m.backgroundColor);if(!F||F.a<=0)return;let E={type:"rect",x:l.left+s,y:l.top+o,w:l.width,h:l.height,color:at(F,g),z:x,seq:f++};S&&(E.radius=S),r.push(E)}async function L(l,m,g,x,S,F){if(g.backgroundImage==="none")return;let E=Nt(g.backgroundImage);if(!E){w("css:backgroundImage",{code:"unsupported-css",message:`background-image "${g.backgroundImage}" is not supported (only a single url() is); ignored`,element:l,property:"background-image"});return}let k=await Ct(new URL(E,l.ownerDocument.baseURI).href,t.warn,l);if(!k)return;g.backgroundRepeat!=="no-repeat"&&w("css:backgroundRepeat",{code:"unsupported-css",message:`background-repeat "${g.backgroundRepeat}" is not supported; drawn once as no-repeat`,element:l,property:"background-repeat"});let I=z(m,g,g.backgroundClip||"border-box",F),M=z(m,g,g.backgroundOrigin||"padding-box",null),N=ft(M,k.width,k.height,g.backgroundSize,g.backgroundPosition);r.push({type:"image",...N,image:k,clip:I,alpha:x,z:S,seq:f++})}async function j(l,m,g,x,S,F){let E=l.currentSrc||l.src;if(!E)return;let k=await Ct(E,t.warn,l);if(!k)return;let I=z(m,g,"content-box",F),M=ft(I,k.width,k.height,zt(g.objectFit),g.objectPosition);g.objectFit==="scale-down"&&(M.w>k.width||M.h>k.height)&&Object.assign(M,ft(I,k.width,k.height,"auto",g.objectPosition)),r.push({type:"image",...M,image:k,clip:I,alpha:x,z:S,seq:f++})}function z(l,m,g,x){let S=l.left+s,F=l.top+o,E=l.width,k=l.height;if(g==="padding-box"||g==="content-box"){let M=q(m.borderTopWidth),N=q(m.borderRightWidth),W=q(m.borderBottomWidth),b=q(m.borderLeftWidth);S+=b,F+=M,E-=b+N,k-=M+W,x&&(x=x.map(T=>Math.max(0,T-Math.max(M,N,W,b))))}if(g==="content-box"){let M=q(m.paddingTop),N=q(m.paddingRight),W=q(m.paddingBottom),b=q(m.paddingLeft);S+=b,F+=M,E-=b+N,k-=M+W}let I={x:S,y:F,w:Math.max(0,E),h:Math.max(0,k)};return x&&x.some(M=>M>0)&&(I.radius=x),I}function X(l,m,g,x,S,F){let E=l.left+s,k=l.top+o,I=l.width,M=l.height,b=["Top","Right","Bottom","Left"].map(T=>({side:T,width:q(m[`border${T}Width`]),style:m[`border${T}Style`],color:st(m[`border${T}Color`])})).filter(T=>T.width>0&&T.style!=="none"&&T.style!=="hidden"&&T.color&&T.color.a>0);if(b.length){if(F&&F.some(T=>T>0)){let T=b[0];if(b.length===4&&b.every(v=>v.width===T.width&&v.style===T.style&&JSON.stringify(v.color)===JSON.stringify(T.color))){let v=T.width;r.push({type:"stroke-rrect",x:E+v/2,y:k+v/2,w:I-v,h:M-v,radius:F.map(G=>Math.max(0,G-v/2)),width:v,color:at(T.color,g),dash:Wt(T.style,v),z:x,seq:f++});return}w("css:borderRadiusNonUniform",{code:"unsupported-css",message:"border-radius with non-uniform borders is approximated with straight borders",property:"border-radius"})}for(let T of b){let B=T.width,v=at(T.color,g),G=T.side==="Top"||T.side==="Bottom",Z=T.side==="Top"||T.side==="Left"?1:-1,P=T.side==="Top"?k:T.side==="Bottom"?k+M:T.side==="Left"?E:E+I,H=Wt(T.style,B);if(H){let V=S?P:P+B/2*Z;r.push({type:"line",x1:G?E:V,y1:G?V:k,x2:G?E+I:V,y2:G?V:k+M,width:B,color:v,dash:H,z:x,seq:f++});continue}let K=S?P-B/2:Z>0?P:P-B;G?r.push({type:"rect",x:E,y:K,w:I,h:B,color:v,z:x,seq:f++}):r.push({type:"rect",x:K,y:k,w:B,h:M,color:v,z:x,seq:f++})}}}function et(l,m,g,x){let S=l.data;if(!S)return;if(!/\S/.test(S)&&!S.includes("\xA0")){let b=l.ownerDocument.createRange();if(b.selectNodeContents(l),![...b.getClientRects()].some(T=>T.width>0))return}let F=at(st(g.color)??{r:0,g:0,b:0,a:1},x.alpha),E=q(g.fontSize);if(E<=0)return;let k=It(g.fontFamily),I=Rt(g.fontWeight),M=g.fontStyle==="italic"||g.fontStyle==="oblique"?"italic":"normal",N=t.registry.match(k,I,M)??t.registry.match(t.fontFallback,I,M);if(!N){let b=k.join(",");u.has(b)||(u.add(b),t.warn({code:"missing-font",message:`No registered font matches font-family "${g.fontFamily}" and no fallback is available; text will be skipped`,element:m}));return}let W=Ot(l,g,{registry:t.registry,families:k,fallback:t.fontFallback,primary:N,weight:I,fstyle:M,size:E,textMeasure:t.textMeasure,warn:t.warn,element:m});for(let b of W)if(b.glyphs.length){a.push({top:b.top+o,bottom:b.bottom+o}),r.push({type:"text",x:b.glyphs[0]?.x??0,y:b.baseline+o,top:b.top+o,bottom:b.bottom+o,size:E,color:F,font:b.font,glyphs:b.glyphs.map(T=>({...T,x:T.x+s})),z:x.z,seq:f++});for(let T of x.decorations){let B=b.glyphs[0],v=b.glyphs[b.glyphs.length-1];if(!B||!v)continue;let G=B.x+s,Z=v.x+v.advance+s,P=Math.max(1,E/14),H=at(T.color,x.alpha);T.line.includes("underline")&&r.push({type:"rect",x:G,y:b.baseline+o+E*.08,w:Z-G,h:P,color:H,z:x.z,seq:f++}),T.line.includes("line-through")&&r.push({type:"rect",x:G,y:b.baseline+o-E*.3,w:Z-G,h:P,color:H,z:x.z,seq:f++})}}}await y(e,{z:0,alpha:1,decorations:[]}),qt(i);let $=e.getBoundingClientRect().bottom+o;for(let l of i)l.type==="rect"||l.type==="stroke-rrect"||l.type==="image"?$=Math.max($,l.y+l.h):l.type==="line"?$=Math.max($,l.y1,l.y2):(l.type==="text"||l.type==="group"||l.type==="clip")&&($=Math.max($,l.bottom));return{items:i,atoms:a,breaks:c,tables:h,height:$}}function qt(e){e.sort((t,n)=>t.z-n.z||t.seq-n.seq);for(let t of e)(t.type==="group"||t.type==="clip")&&qt(t.items)}function Wt(e,t){return e==="dashed"?[t*3,t*3]:e==="dotted"?[t,t]:null}function Gt(e,t){let n=o=>{let r=o.trim().split(/\s+/)[0]??"0px";return r.endsWith("%")?parseFloat(r)/100*t.width:q(r)},s=[n(e.borderTopLeftRadius),n(e.borderTopRightRadius),n(e.borderBottomRightRadius),n(e.borderBottomLeftRadius)];return s.some(o=>o>0)?s:null}function Ae(e){if(!e||e==="none")return null;let t=/^matrix\(([^)]+)\)$/.exec(e.trim());if(!t)return null;let n=t[1].split(",").map(h=>parseFloat(h));if(n.length!==6||n.some(h=>!Number.isFinite(h)))return null;let[s,o,r,i,a,c]=n;return s===1&&o===0&&r===0&&i===1&&a===0&&c===0?null:[s,o,r,i,a,c]}function Ie(e){let t=e.trim().split(/\s+/);return[q(t[0]??"0"),q(t[1]??"0")]}function Re(e,t){let n,s,o,r;if(e.type==="rect"||e.type==="stroke-rrect"||e.type==="image")n=e.x,s=e.y,o=e.x+e.w,r=e.y+e.h;else if(e.type==="line")n=Math.min(e.x1,e.x2)-e.width,s=Math.min(e.y1,e.y2)-e.width,o=Math.max(e.x1,e.x2)+e.width,r=Math.max(e.y1,e.y2)+e.width;else if(e.type==="text"){let i=e.glyphs[e.glyphs.length-1];n=e.x,s=e.top,o=i?i.x+i.advance:e.x,r=e.bottom}else if(e.type==="clip")n=e.box.x,s=e.box.y,o=e.box.x+e.box.w,r=e.box.y+e.box.h;else return!0;return o>t.x&&n<t.x+t.w&&r>t.y&&s<t.y+t.h}function at(e,t){return t===1?e:{...e,a:e.a*t}}function Ht(e){return e.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}function Be(){return typeof CompressionStream=="function"}async function Xt(e){if(!Be())return null;try{let t=new CompressionStream("deflate"),n=t.writable.getWriter();n.write(e),n.close();let s=await new Response(t.readable).arrayBuffer();return new Uint8Array(s)}catch{return null}}var lt=class{constructor(t){this.id=t}toString(){return`${this.id} 0 R`}},J=class{constructor(t){this.name=t}toString(){let t="/";for(let n of this.name){let s=n.charCodeAt(0);if(s<33||s>126||"#/%()<>[]{}".includes(n))for(let o of new TextEncoder().encode(n))t+="#"+o.toString(16).padStart(2,"0");else t+=n}return t}},Q=class{constructor(t){this.text=t}toString(){return this.text}};function nt(e){if(/^[\x20-\x7e]*$/.test(e))return new Q("("+e.replace(/[\\()]/g,n=>"\\"+n)+")");let t="FEFF";for(let n=0;n<e.length;n++)t+=e.charCodeAt(n).toString(16).padStart(4,"0");return new Q("<"+t+">")}function Vt(e){let t=i=>String(i).padStart(2,"0"),n=-e.getTimezoneOffset(),s=n>=0?"+":"-",o=t(Math.floor(Math.abs(n)/60)),r=t(Math.abs(n)%60);return new Q(`(D:${e.getFullYear()}${t(e.getMonth()+1)}${t(e.getDate())}${t(e.getHours())}${t(e.getMinutes())}${t(e.getSeconds())}${s}${o}'${r}')`)}function ht(e){if(e===null)return"null";if(typeof e=="number")return U(e);if(typeof e=="boolean")return e?"true":"false";if(typeof e=="string")return new J(e).toString();if(e instanceof lt||e instanceof J||e instanceof Q)return e.toString();if(Array.isArray(e))return"["+e.map(ht).join(" ")+"]";let t=[];for(let[n,s]of Object.entries(e))s!==void 0&&t.push(new J(n).toString()+" "+ht(s));return"<< "+t.join(" ")+" >>"}var dt=class{constructor(t={}){this.objects=[null],this.compress=t.compress??!0,this.version=t.version??"1.7"}reserve(){return this.objects.push({value:null}),new lt(this.objects.length-1)}set(t,n,s){this.objects[t.id]={value:n,stream:s}}add(t){let n=this.reserve();return this.set(n,t),n}async addStream(t,n,s={}){let o=this.reserve();return await this.setStream(o,t,n,s),o}async setStream(t,n,s,o={}){let r=s,i={...n};if((o.compress??this.compress)&&!("Filter"in i)){let c=await Xt(s);c&&c.length<s.length&&(r=c,i.Filter="FlateDecode")}i.Length=r.length,this.set(t,i,r)}build(t,n){let s=new TextEncoder,o=[],r=0,i=f=>{let d=typeof f=="string"?s.encode(f):f;o.push(d),r+=d.length};i(ut([s.encode(`%PDF-${this.version}
6
6
  %`),new Uint8Array([226,227,207,211]),s.encode(`
7
7
  `)]));let a=[];for(let f=1;f<this.objects.length;f++){let d=this.objects[f];if(!d)throw new Error(`PDF object ${f} was reserved but never set`);a[f]=r,i(`${f} 0 obj
8
8
  ${ht(d.value)}
@@ -21,7 +21,7 @@ ${c}
21
21
  %%EOF
22
22
  `),ut(o)}};function ut(e){let t=0;for(let o of e)t+=o.length;let n=new Uint8Array(t),s=0;for(let o of e)n.set(o,s),s+=o.length;return n}var pt=class{constructor(){this.ops=[],this.depth=0}save(){return this.ops.push("q"),this.depth++,this}restore(){if(this.depth<=0)throw new Error("ContentStream: unbalanced Q");return this.ops.push("Q"),this.depth--,this}transform(t,n,s,o,r,i){return this.ops.push(`${U(t)} ${U(n)} ${U(s)} ${U(o)} ${U(r)} ${U(i)} cm`),this}setGState(t){return this.ops.push(`/${t} gs`),this}fillColor(t,n,s){return this.ops.push(`${U(t)} ${U(n)} ${U(s)} rg`),this}strokeColor(t,n,s){return this.ops.push(`${U(t)} ${U(n)} ${U(s)} RG`),this}lineWidth(t){return this.ops.push(`${U(t)} w`),this}dash(t,n=0){return this.ops.push(`[${t.map(U).join(" ")}] ${U(n)} d`),this}lineCap(t){return this.ops.push(`${t} J`),this}rect(t,n,s,o){return this.ops.push(`${U(t)} ${U(n)} ${U(s)} ${U(o)} re`),this}moveTo(t,n){return this.ops.push(`${U(t)} ${U(n)} m`),this}lineTo(t,n){return this.ops.push(`${U(t)} ${U(n)} l`),this}curveTo(t,n,s,o,r,i){return this.ops.push(`${U(t)} ${U(n)} ${U(s)} ${U(o)} ${U(r)} ${U(i)} c`),this}closePath(){return this.ops.push("h"),this}roundedRect(t,n,s,o,r){let a=Math.min(s,o)/2,c=y=>Math.max(0,Math.min(y,a)),h=c(r[0]),p=c(r[1]),f=c(r[2]),d=c(r[3]),u=n+o,w=t+s;return this.moveTo(t+h,u),this.lineTo(w-p,u),p&&this.curveTo(w-p+p*.5523,u,w,u-p+p*.5523,w,u-p),this.lineTo(w,n+f),f&&this.curveTo(w,n+f-f*.5523,w-f+f*.5523,n,w-f,n),this.lineTo(t+d,n),d&&this.curveTo(t+d-d*.5523,n,t,n+d-d*.5523,t,n+d),this.lineTo(t,u-h),h&&this.curveTo(t,u-h+h*.5523,t+h-h*.5523,u,t+h,u),this.closePath()}image(t,n,s,o,r){return this.ops.push(`q ${U(o)} 0 0 ${U(r)} ${U(n)} ${U(s)} cm /${t} Do Q`),this}fill(){return this.ops.push("f"),this}stroke(){return this.ops.push("S"),this}clip(){return this.ops.push("W n"),this}fillRect(t,n,s,o){return this.rect(t,n,s,o).fill()}text(t,n,s,o,r,i={}){let a=[];for(let c of r)typeof c=="string"?c.length&&a.push(`<${c}>`):c!==0&&a.push(U(c));return a.length?(this.ops.push("BT"),this.ops.push(`/${t} ${U(n)} Tf`),i.charSpacing&&this.ops.push(`${U(i.charSpacing)} Tc`),i.rise&&this.ops.push(`${U(i.rise)} Ts`),this.ops.push(`1 0 0 1 ${U(s)} ${U(o)} Tm`),this.ops.push(`[${a.join(" ")}] TJ`),this.ops.push("ET"),this):this}toBytes(){if(this.depth!==0)throw new Error(`ContentStream: ${this.depth} unclosed q`);return new TextEncoder().encode(this.ops.join(`
23
23
  `)+`
24
- `)}};function Yt(e,t){let n=new Set([0]),s=[...t];for(;s.length;){let $=s.pop();if(!($<0||$>=e.numGlyphs||n.has($))){n.add($);for(let l of At(bt(e,$)))n.has(l)||s.push(l)}}let o=[...n].sort(($,l)=>$-l),r=new Map;o.forEach(($,l)=>r.set($,l));let i=o.length,a=[],c=new Uint32Array(i+1),h=0;for(let $=0;$<i;$++){let l=bt(e,o[$]);l.length&&new DataView(l.buffer,l.byteOffset,l.byteLength).getInt16(0)<0&&(l=Be(l,r)),c[$]=h,a.push(l),h+=l.length;let m=(4-h%4)%4;m&&(a.push(new Uint8Array(m)),h+=m)}c[i]=h;let p=ut(a),f=new Uint8Array(c.length*4),d=new DataView(f.buffer);c.forEach(($,l)=>d.setUint32(l*4,$));let u=e.tables.get("hmtx"),w=e.tables.get("hhea"),y=new DataView(e.data.buffer,e.data.byteOffset,e.data.byteLength),C=y.getUint16(w.offset+34),O=new Uint8Array(i*4),R=new DataView(O.buffer);for(let $=0;$<i;$++){let l=o[$],m=l<C?u.offset+l*4+2:u.offset+C*4+(l-C)*2;R.setUint16($*4,e.advances[l]??0),R.setInt16($*4+2,m+2<=e.data.byteLength?y.getInt16(m):0)}let D=mt(e,"head"),L=new DataView(D.buffer);L.setUint32(8,0),L.setInt16(50,1);let j=mt(e,"hhea");new DataView(j.buffer).setUint16(34,i);let z=mt(e,"maxp");new DataView(z.buffer).setUint16(4,i);let X=[["glyf",p],["head",D],["hhea",j],["hmtx",O],["loca",f],["maxp",z]];for(let $ of["cvt ","fpgm","prep"])e.tables.has($)&&X.push([$,mt(e,$)]);return X.sort(($,l)=>$[0]<l[0]?-1:1),{data:De(X),gidMap:r,oldGids:o}}function mt(e,t){let n=e.tables.get(t);if(!n)throw new Error(`missing table ${t}`);return new Uint8Array(e.data.subarray(n.offset,n.offset+n.length))}function Be(e,t){let n=new Uint8Array(e),s=new DataView(n.buffer),o=10;for(;;){let r=s.getUint16(o),i=s.getUint16(o+2);if(s.setUint16(o+2,t.get(i)??0),o+=4,o+=r&1?4:2,r&8?o+=2:r&64?o+=4:r&128&&(o+=8),!(r&32)||o>=n.length)break}return n}function De(e){let t=e.length,n=0;for(;1<<n+1<=t;)n++;let s=(1<<n)*16,o=t*16-s,i=12+t*16,a=[];for(let[f,d]of e)a.push({tag:f,data:d,offset:i,checksum:_t(d)}),i+=d.length+3&-4;let c=new Uint8Array(i),h=new DataView(c.buffer);h.setUint32(0,65536),h.setUint16(4,t),h.setUint16(6,s),h.setUint16(8,n),h.setUint16(10,o),a.forEach((f,d)=>{let u=12+d*16;for(let w=0;w<4;w++)c[u+w]=f.tag.charCodeAt(w);h.setUint32(u+4,f.checksum),h.setUint32(u+8,f.offset),h.setUint32(u+12,f.data.length),c.set(f.data,f.offset)});let p=a.find(f=>f.tag==="head");if(p){let f=_t(c);h.setUint32(p.offset+8,2981146554-f>>>0)}return c}function _t(e){let t=0,n=e.length;for(let s=0;s<n;s+=4){let o=e[s]??0,r=e[s+1]??0,i=e[s+2]??0,a=e[s+3]??0;t=t+((o<<24|r<<16|i<<8|a)>>>0)>>>0}return t}var gt=class{constructor(t,n){this.font=t,this.resourceName=n,this.usedGids=new Map,this.subset=null}addGlyph(t,n){this.usedGids.has(t)||this.usedGids.set(t,n)}cid(t){if(!this.subset)throw new Error("EmbeddedFont: embed() must be called before cid()");return this.subset.gidMap.get(t)??0}finalize(){return this.subset||(this.subset=Yt(this.font,this.usedGids.keys())),this.subset}async embed(t){let n=this.finalize(),s=this.font,o=1e3/s.unitsPerEm,i=`${Oe(this.usedGids)}+${s.postScriptName}`,a=await t.addStream({Length1:n.data.length},n.data),c=4;s.italic&&(c|=64),s.bold&&(c|=1<<18);let h=t.add({Type:"FontDescriptor",FontName:i,Flags:c,FontBBox:s.bbox.map(y=>Math.round(y*o)),ItalicAngle:s.italicAngle,Ascent:Math.round(s.ascender*o),Descent:Math.round(s.descender*o),CapHeight:Math.round(s.capHeight*o),StemV:s.bold?120:80,FontFile2:a}),p=[],f=n.oldGids.map(y=>Math.round((s.advances[y]??0)*o)),d=0;for(;d<f.length;){let y=d;for(;y+1<f.length&&y-d<100;)y++;p.push(d,f.slice(d,y+1)),d=y+1}let u=t.add({Type:"Font",Subtype:"CIDFontType2",BaseFont:i,CIDSystemInfo:{Registry:new Q("(Adobe)"),Ordering:new Q("(Identity)"),Supplement:0},FontDescriptor:h,DW:1e3,W:p,CIDToGIDMap:"Identity"}),w=await t.addStream({},ve(n,this.usedGids));return t.add({Type:"Font",Subtype:"Type0",BaseFont:i,Encoding:"Identity-H",DescendantFonts:[u],ToUnicode:w})}};function Oe(e){let t=2166136261;for(let s of e.keys())t^=s,t=Math.imul(t,16777619)>>>0;let n="";for(let s=0;s<6;s++)n+=String.fromCharCode(65+t%26),t=Math.floor(t/26);return n}function ve(e,t){let n=[];e.oldGids.forEach((r,i)=>{let a=t.get(r);a!==void 0&&n.push(`<${rt(i)}> <${Le(a)}>`)});let s="";for(let r=0;r<n.length;r+=100){let i=n.slice(r,r+100);s+=`${i.length} beginbfchar
24
+ `)}};function Yt(e,t){let n=new Set([0]),s=[...t];for(;s.length;){let $=s.pop();if(!($<0||$>=e.numGlyphs||n.has($))){n.add($);for(let l of Mt(bt(e,$)))n.has(l)||s.push(l)}}let o=[...n].sort(($,l)=>$-l),r=new Map;o.forEach(($,l)=>r.set($,l));let i=o.length,a=[],c=new Uint32Array(i+1),h=0;for(let $=0;$<i;$++){let l=bt(e,o[$]);l.length&&new DataView(l.buffer,l.byteOffset,l.byteLength).getInt16(0)<0&&(l=De(l,r)),c[$]=h,a.push(l),h+=l.length;let m=(4-h%4)%4;m&&(a.push(new Uint8Array(m)),h+=m)}c[i]=h;let p=ut(a),f=new Uint8Array(c.length*4),d=new DataView(f.buffer);c.forEach(($,l)=>d.setUint32(l*4,$));let u=e.tables.get("hmtx"),w=e.tables.get("hhea"),y=new DataView(e.data.buffer,e.data.byteOffset,e.data.byteLength),C=y.getUint16(w.offset+34),O=new Uint8Array(i*4),R=new DataView(O.buffer);for(let $=0;$<i;$++){let l=o[$],m=l<C?u.offset+l*4+2:u.offset+C*4+(l-C)*2;R.setUint16($*4,e.advances[l]??0),R.setInt16($*4+2,m+2<=e.data.byteLength?y.getInt16(m):0)}let D=mt(e,"head"),L=new DataView(D.buffer);L.setUint32(8,0),L.setInt16(50,1);let j=mt(e,"hhea");new DataView(j.buffer).setUint16(34,i);let z=mt(e,"maxp");new DataView(z.buffer).setUint16(4,i);let X=[["glyf",p],["head",D],["hhea",j],["hmtx",O],["loca",f],["maxp",z]];for(let $ of["cvt ","fpgm","prep"])e.tables.has($)&&X.push([$,mt(e,$)]);return X.sort(($,l)=>$[0]<l[0]?-1:1),{data:Oe(X),gidMap:r,oldGids:o}}function mt(e,t){let n=e.tables.get(t);if(!n)throw new Error(`missing table ${t}`);return new Uint8Array(e.data.subarray(n.offset,n.offset+n.length))}function De(e,t){let n=new Uint8Array(e),s=new DataView(n.buffer),o=10;for(;;){let r=s.getUint16(o),i=s.getUint16(o+2);if(s.setUint16(o+2,t.get(i)??0),o+=4,o+=r&1?4:2,r&8?o+=2:r&64?o+=4:r&128&&(o+=8),!(r&32)||o>=n.length)break}return n}function Oe(e){let t=e.length,n=0;for(;1<<n+1<=t;)n++;let s=(1<<n)*16,o=t*16-s,i=12+t*16,a=[];for(let[f,d]of e)a.push({tag:f,data:d,offset:i,checksum:_t(d)}),i+=d.length+3&-4;let c=new Uint8Array(i),h=new DataView(c.buffer);h.setUint32(0,65536),h.setUint16(4,t),h.setUint16(6,s),h.setUint16(8,n),h.setUint16(10,o),a.forEach((f,d)=>{let u=12+d*16;for(let w=0;w<4;w++)c[u+w]=f.tag.charCodeAt(w);h.setUint32(u+4,f.checksum),h.setUint32(u+8,f.offset),h.setUint32(u+12,f.data.length),c.set(f.data,f.offset)});let p=a.find(f=>f.tag==="head");if(p){let f=_t(c);h.setUint32(p.offset+8,2981146554-f>>>0)}return c}function _t(e){let t=0,n=e.length;for(let s=0;s<n;s+=4){let o=e[s]??0,r=e[s+1]??0,i=e[s+2]??0,a=e[s+3]??0;t=t+((o<<24|r<<16|i<<8|a)>>>0)>>>0}return t}var gt=class{constructor(t,n){this.font=t,this.resourceName=n,this.usedGids=new Map,this.subset=null}addGlyph(t,n){this.usedGids.has(t)||this.usedGids.set(t,n)}cid(t){if(!this.subset)throw new Error("EmbeddedFont: embed() must be called before cid()");return this.subset.gidMap.get(t)??0}finalize(){return this.subset||(this.subset=Yt(this.font,this.usedGids.keys())),this.subset}async embed(t){let n=this.finalize(),s=this.font,o=1e3/s.unitsPerEm,i=`${ve(this.usedGids)}+${s.postScriptName}`,a=await t.addStream({Length1:n.data.length},n.data),c=4;s.italic&&(c|=64),s.bold&&(c|=1<<18);let h=t.add({Type:"FontDescriptor",FontName:i,Flags:c,FontBBox:s.bbox.map(y=>Math.round(y*o)),ItalicAngle:s.italicAngle,Ascent:Math.round(s.ascender*o),Descent:Math.round(s.descender*o),CapHeight:Math.round(s.capHeight*o),StemV:s.bold?120:80,FontFile2:a}),p=[],f=n.oldGids.map(y=>Math.round((s.advances[y]??0)*o)),d=0;for(;d<f.length;){let y=d;for(;y+1<f.length&&y-d<100;)y++;p.push(d,f.slice(d,y+1)),d=y+1}let u=t.add({Type:"Font",Subtype:"CIDFontType2",BaseFont:i,CIDSystemInfo:{Registry:new Q("(Adobe)"),Ordering:new Q("(Identity)"),Supplement:0},FontDescriptor:h,DW:1e3,W:p,CIDToGIDMap:"Identity"}),w=await t.addStream({},Le(n,this.usedGids));return t.add({Type:"Font",Subtype:"Type0",BaseFont:i,Encoding:"Identity-H",DescendantFonts:[u],ToUnicode:w})}};function ve(e){let t=2166136261;for(let s of e.keys())t^=s,t=Math.imul(t,16777619)>>>0;let n="";for(let s=0;s<6;s++)n+=String.fromCharCode(65+t%26),t=Math.floor(t/26);return n}function Le(e,t){let n=[];e.oldGids.forEach((r,i)=>{let a=t.get(r);a!==void 0&&n.push(`<${rt(i)}> <${je(a)}>`)});let s="";for(let r=0;r<n.length;r+=100){let i=n.slice(r,r+100);s+=`${i.length} beginbfchar
25
25
  ${i.join(`
26
26
  `)}
27
27
  endbfchar
@@ -38,5 +38,5 @@ endcodespacerange
38
38
  CMapName currentdict /CMap defineresource pop
39
39
  end
40
40
  end
41
- `;return new TextEncoder().encode(o)}function rt(e){return e.toString(16).toUpperCase().padStart(4,"0")}function Le(e){if(e<=65535)return rt(e);let t=e-65536;return rt(55296+(t>>10))+rt(56320+(t&1023))}async function Kt(e,t){let n={Type:"XObject",Subtype:"Image",Width:t.width,Height:t.height,ColorSpace:"DeviceRGB",BitsPerComponent:8};if(t.jpeg)return n.Filter="DCTDecode",e.addStream(n,t.jpeg,{compress:!1});if(!t.rgb)throw new Error("embedImage: image has no pixel data");return t.alpha&&(n.SMask=await e.addStream({Type:"XObject",Subtype:"Image",Width:t.width,Height:t.height,ColorSpace:"DeviceGray",BitsPerComponent:8},t.alpha)),e.addStream(n,t.rgb)}function Jt(e,t){let n=t,s=e.height,o=[...e.atoms].sort((f,d)=>f.top-d.top),r=[...new Set(e.breaks)].sort((f,d)=>f-d),i=.01,a=[],c=0,h=0;for(;c<s-i&&h++<1e4;){let f=[],d=0;for(let C of e.tables)C.headItems.length&&C.headBottom<=c+i&&c<C.bottom-i&&(f.push({table:C,shift:d}),d+=C.headBottom-C.headTop);let u=[],w=0,y=c;for(let C=0;C<4;C++){let O=Math.max(n-d-w,n*.25);y=p(c,O);let R=[],D=0;for(let j of e.tables)j.footItems.length&&j.top<y-i&&j.footTop>=y-i&&j.bottom>y+i&&(R.push({table:j,shift:D}),D+=j.footBottom-j.footTop);let L=R.length===u.length&&R.every((j,z)=>j.table===u[z]?.table);if(u=R,w=D,L)break}a.push({start:c,end:y,heads:f,headShift:d,feet:u,footShift:w}),c=y}return a.length||a.push({start:0,end:Math.max(s,1),heads:[],headShift:0,feet:[],footShift:0}),a;function p(f,d){let u=Math.min(f+d,s);for(let w of r)if(w>f+i&&w<u-i){u=w;break}if(u<s-i){let w=!0,y=0;for(;w&&y++<1e3;){w=!1;for(let C of o){if(C.top>=u)break;C.bottom-C.top>d||C.top<u-i&&C.bottom>u+i&&C.top>f+i&&(u=C.top,w=!0)}}u<=f+i&&(u=Math.min(f+d,s))}return u}}function Qt(e={}){let t=e.size??"A4",n,s;if(typeof t=="string"){let i=$t[t];if(!i)throw new Error(`Unknown page size "${t}". Use one of ${Object.keys($t).join(", ")} or {width, height}.`);n=i.width,s=i.height}else n=Y(t.width),s=Y(t.height);(e.orientation??"portrait")==="landscape"&&n<s&&([n,s]=[s,n]);let o=e.margin??"15mm",r=typeof o=="string"?{top:Y(o),right:Y(o),bottom:Y(o),left:Y(o)}:{top:Y(o.top),right:Y(o.right),bottom:Y(o.bottom),left:Y(o.left)};return{width:n,height:s,...r}}async function Zt(e,t,n){let s=new dt({compress:n.compress}),o=(n.header?.heightPx??0)*.75,r=(n.footer?.heightPx??0)*.75,i=t.width-t.left-t.right,a=t.height-t.top-o,c=t.height-t.top-t.bottom-o-r;if(c<=0)throw new Error("Page content area is empty: margins + header + footer exceed the page height");let h=c/.75,p=Jt(e,h),f=p.length,d=[],u=[];for(let g=0;g<f;g++)d.push(n.header?await n.header.render(g+1,f):null),u.push(n.footer?await n.footer.render(g+1,f):null);let w=new Map,y=new Map,C=g=>{for(let x of g)if(x.type==="text"){let S=w.get(x.font);S||(S=new gt(x.font.parsed,`F${w.size+1}`),w.set(x.font,S));for(let F of x.glyphs)S.addGlyph(F.gid,F.cp)}else x.type==="image"?y.has(x.image.key)||y.set(x.image.key,{name:`Im${y.size+1}`,image:x.image}):(x.type==="group"||x.type==="clip")&&C(x.items)};C(e.items);for(let g of[...d,...u])g&&C(g.items);for(let g of w.values())g.finalize();let O={};for(let g of w.values())O[g.resourceName]=await g.embed(s);let R={};for(let g of y.values())R[g.name]=await Kt(s,g.image);let D=new Map,L={},j=g=>{let x=U(g),S=D.get(x);return S||(S=`GS${D.size+1}`,D.set(x,S),L[S]=s.add({Type:"ExtGState",ca:g,CA:g})),S},z=s.reserve(),X=[];for(let g=0;g<f;g++){let x=p[g],S=new pt,F=new Ut(S,t,w,y,j),E=x.headShift*.75,k=x.footShift*.75;S.save(),S.rect(t.left,a-c+k,i,c-E-k).clip(),F.setOrigin(a-E,x.start),F.render(e.items,x),S.restore();let I=a-E-(x.end-x.start)*.75;for(let b of x.feet){let T=(b.table.footBottom-b.table.footTop)*.75,B=I-b.shift*.75-T;S.save(),S.rect(t.left,B,i,T).clip(),F.setOrigin(B+T,b.table.footTop),F.render(b.table.footItems),S.restore()}for(let b of x.heads){S.save();let T=(b.table.headBottom-b.table.headTop)*.75;S.rect(t.left,a-b.shift*.75-T,i,T).clip(),F.setOrigin(a-b.shift*.75,b.table.headTop),F.render(b.table.headItems),S.restore()}let A=d[g];A&&(S.save(),S.rect(t.left,t.height-t.top-o,i,o).clip(),F.setOrigin(t.height-t.top,0),F.render(A.items),S.restore());let N=u[g];N&&(S.save(),S.rect(t.left,t.bottom,i,r).clip(),F.setOrigin(t.bottom+r,0),F.render(N.items),S.restore());let W=await s.addStream({},S.toBytes());X.push(s.add({Type:"Page",Parent:z,MediaBox:[0,0,t.width,t.height],Resources:{Font:O,XObject:R,ExtGState:L,ProcSet:[new J("PDF"),new J("Text"),new J("ImageC")]},Contents:W}))}s.set(z,{Type:"Pages",Kids:X,Count:X.length});let et=s.add({Type:"Catalog",Pages:z}),$=n.metadata??{},l={Producer:nt("receipt-html-to-pdf"),Creator:nt($.creator??"receipt-html-to-pdf"),CreationDate:Vt($.creationDate??new Date)};$.title&&(l.Title=nt($.title)),$.author&&(l.Author=nt($.author)),$.subject&&(l.Subject=nt($.subject)),$.keywords&&(l.Keywords=nt($.keywords));let m=s.add(l);return s.build(et,m)}function je(e,t){if(e.type==="text"){let s=(e.top+e.bottom)/2;return s>=t.start-.01&&s<t.end-.01}return We(e)>t.start+.01&&ze(e)<t.end-.01}var Ut=class{constructor(t,n,s,o,r){this.cs=t,this.geo=n,this.fonts=s,this.images=o,this.gsName=r,this.pdfTop=n.height-n.top,this.docTop=0,this.curAlpha=1}setOrigin(t,n){this.pdfTop=t,this.docTop=n}X(t){return this.geo.left+t*.75}Y(t){return this.pdfTop-(t-this.docTop)*.75}setAlpha(t){Math.abs(t-this.curAlpha)<.001||(this.cs.setGState(this.gsName(t)),this.curAlpha=t)}radiusPt(t){return(t??[0,0,0,0]).map(n=>n*.75)}clipBox(t){let n=this.cs;t.radius?n.roundedRect(this.X(t.x),this.Y(t.y+t.h),t.w*.75,t.h*.75,this.radiusPt(t.radius)):n.rect(this.X(t.x),this.Y(t.y+t.h),t.w*.75,t.h*.75),n.clip()}render(t,n){let s=this.cs;for(let o of t)if(!(n&&!je(o,n)))if(o.type==="rect"){if(o.w<=0||o.h<=0)continue;s.save(),this.setAlpha(o.color.a),s.fillColor(o.color.r,o.color.g,o.color.b),o.radius?s.roundedRect(this.X(o.x),this.Y(o.y+o.h),o.w*.75,o.h*.75,this.radiusPt(o.radius)).fill():s.fillRect(this.X(o.x),this.Y(o.y+o.h),o.w*.75,o.h*.75),s.restore(),this.curAlpha=1}else if(o.type==="line")s.save(),this.setAlpha(o.color.a),s.strokeColor(o.color.r,o.color.g,o.color.b),s.lineWidth(o.width*.75),o.dash&&s.dash(o.dash.map(r=>r*.75)),s.moveTo(this.X(o.x1),this.Y(o.y1)).lineTo(this.X(o.x2),this.Y(o.y2)).stroke(),s.restore(),this.curAlpha=1;else if(o.type==="stroke-rrect")s.save(),this.setAlpha(o.color.a),s.strokeColor(o.color.r,o.color.g,o.color.b),s.lineWidth(o.width*.75),o.dash&&s.dash(o.dash.map(r=>r*.75)),s.roundedRect(this.X(o.x),this.Y(o.y+o.h),o.w*.75,o.h*.75,this.radiusPt(o.radius)).stroke(),s.restore(),this.curAlpha=1;else if(o.type==="image"){let r=this.images.get(o.image.key);if(!r||o.w<=0||o.h<=0)continue;s.save(),this.setAlpha(o.alpha),o.clip&&this.clipBox(o.clip),s.image(r.name,this.X(o.x),this.Y(o.y+o.h),o.w*.75,o.h*.75),s.restore(),this.curAlpha=1}else if(o.type==="text"){let r=this.fonts.get(o.font),i=Ne(o,r);s.save(),this.setAlpha(o.color.a),s.fillColor(o.color.r,o.color.g,o.color.b),s.text(r.resourceName,o.size*.75,this.X(o.x),this.Y(o.y),i),s.restore(),this.curAlpha=1}else if(o.type==="group"){let[r,i,a,c]=o.matrix,h=this.X(o.origin.x),p=this.Y(o.origin.y),f=r,d=-i,u=-a,w=c,y=h-(f*h+u*p)+o.matrix[4]*.75,C=p-(d*h+w*p)-o.matrix[5]*.75;s.save(),s.transform(f,d,u,w,y,C),this.render(o.items,n),s.restore()}else o.type==="clip"&&(s.save(),this.clipBox(o.box),this.render(o.items,n),s.restore())}};function Ne(e,t){let n=[],s="";for(let o=0;o<e.glyphs.length;o++){let r=e.glyphs[o];s+=rt(t.cid(r.gid));let i=e.glyphs[o+1];if(!i)break;let a=r.x+r.advance,h=-(i.x-a)/e.size*1e3;Math.abs(h)>=.5&&(n.push(s,Math.round(h*10)/10),s="")}return s&&n.push(s),n}function ze(e){return e.type==="rect"||e.type==="stroke-rrect"||e.type==="image"?e.y:e.type==="line"?Math.min(e.y1,e.y2)-e.width/2:(e.type==="group"||e.type==="clip",e.top)}function We(e){return e.type==="rect"||e.type==="stroke-rrect"||e.type==="image"?e.y+e.h:e.type==="line"?Math.max(e.y1,e.y2)+e.width/2:(e.type==="group"||e.type==="clip",e.bottom)}var Pn="0.2.0",yt=new ct;async function An(e){if(!e||!e.family||!e.src)throw new TypeError("registerFont: { family, src } are required");(await yt.register(e)).parsed.variable&&console.warn(`[receipt-html-to-pdf] "${e.family}" is a variable font; only the default instance outlines are embedded. Use static TTF instances for other weights.`)}function Mn(){return yt.fonts.map(e=>({family:e.displayFamily,weight:e.weight,style:e.style,glyphs:e.parsed.numGlyphs}))}async function In(e,t={}){if(typeof document>"u")throw new Error("htmlToPdf must run in a browser (needs DOM layout)");if(yt.fonts.length===0)throw new Error("htmlToPdf: no fonts registered. Call registerFont() with at least one TrueType font first.");let n=t.onWarning??(()=>{}),s=Qt(t.page),o=(s.width-s.left-s.right)/.75,r=await St(e,{widthPx:o,stylesheets:t.stylesheets??"inherit",mediaPrint:t.mediaPrint??!1,baseUrl:t.baseUrl,warn:n}),i={registry:yt,fontFallback:t.fontFallback??[],warn:n,textMeasure:t.textMeasure??"auto"},a={widthPx:o,stylesheets:t.stylesheets??"inherit",mediaPrint:t.mediaPrint??!1,baseUrl:t.baseUrl,warn:n};try{let c=await Ft(r.root,i),h=t.header?await te(t.header,a,i):null,p=t.footer?await te(t.footer,a,i):null,f=await Zt(c,s,{compress:t.compress??!0,metadata:t.metadata,header:h,footer:p});return Ge(f,t.output??"blob")}finally{r.destroy()}}async function te(e,t,n){let s=async(i,a)=>{let c=e.replace(/\{\{\s*pageNumber\s*\}\}/g,String(i)).replace(/\{\{\s*totalPages\s*\}\}/g,String(a)),h=await St(c,t);try{return await Ft(h.root,n)}finally{h.destroy()}},o=await s(1,1),r=new Map([["1/1",o]]);return{heightPx:o.height,render:async(i,a)=>{let c=`${i}/${a}`,h=r.get(c);return h||(h=await s(i,a),r.set(c,h)),h}}}function Ge(e,t){if(t==="uint8array")return e;if(t==="dataurl"){let n="";for(let s=0;s<e.length;s+=32768)n+=String.fromCharCode(...e.subarray(s,s+32768));return"data:application/pdf;base64,"+btoa(n)}return new Blob([e],{type:"application/pdf"})}function Rn(e,t){let n=e instanceof Blob?e:new Blob([e],{type:"application/pdf"}),s=URL.createObjectURL(n),o=document.createElement("a");o.href=s,o.download=t,document.body.appendChild(o),o.click(),o.remove(),setTimeout(()=>URL.revokeObjectURL(s),1e3)}export{Rn as downloadPdf,ot as expandPrintMediaCss,In as htmlToPdf,Mn as listFonts,An as registerFont,Pn as version};
41
+ `;return new TextEncoder().encode(o)}function rt(e){return e.toString(16).toUpperCase().padStart(4,"0")}function je(e){if(e<=65535)return rt(e);let t=e-65536;return rt(55296+(t>>10))+rt(56320+(t&1023))}async function Kt(e,t){let n={Type:"XObject",Subtype:"Image",Width:t.width,Height:t.height,ColorSpace:"DeviceRGB",BitsPerComponent:8};if(t.jpeg)return n.Filter="DCTDecode",e.addStream(n,t.jpeg,{compress:!1});if(!t.rgb)throw new Error("embedImage: image has no pixel data");return t.alpha&&(n.SMask=await e.addStream({Type:"XObject",Subtype:"Image",Width:t.width,Height:t.height,ColorSpace:"DeviceGray",BitsPerComponent:8},t.alpha)),e.addStream(n,t.rgb)}function Jt(e,t){let n=t,s=e.height,o=[...e.atoms].sort((f,d)=>f.top-d.top),r=[...new Set(e.breaks)].sort((f,d)=>f-d),i=.01,a=[],c=0,h=0;for(;c<s-i&&h++<1e4;){let f=[],d=0;for(let C of e.tables)C.headItems.length&&C.headBottom<=c+i&&c<C.bottom-i&&(f.push({table:C,shift:d}),d+=C.headBottom-C.headTop);let u=[],w=0,y=c;for(let C=0;C<4;C++){let O=Math.max(n-d-w,n*.25);y=p(c,O);let R=[],D=0;for(let j of e.tables)j.footItems.length&&j.top<y-i&&j.footTop>=y-i&&j.bottom>y+i&&(R.push({table:j,shift:D}),D+=j.footBottom-j.footTop);let L=R.length===u.length&&R.every((j,z)=>j.table===u[z]?.table);if(u=R,w=D,L)break}a.push({start:c,end:y,heads:f,headShift:d,feet:u,footShift:w}),c=y}return a.length||a.push({start:0,end:Math.max(s,1),heads:[],headShift:0,feet:[],footShift:0}),a;function p(f,d){let u=Math.min(f+d,s);for(let w of r)if(w>f+i&&w<u-i){u=w;break}if(u<s-i){let w=!0,y=0;for(;w&&y++<1e3;){w=!1;for(let C of o){if(C.top>=u)break;C.bottom-C.top>d||C.top<u-i&&C.bottom>u+i&&C.top>f+i&&(u=C.top,w=!0)}}u<=f+i&&(u=Math.min(f+d,s))}return u}}function Qt(e={}){let t=e.size??"A4",n,s;if(typeof t=="string"){let i=$t[t];if(!i)throw new Error(`Unknown page size "${t}". Use one of ${Object.keys($t).join(", ")} or {width, height}.`);n=i.width,s=i.height}else n=Y(t.width),s=Y(t.height);(e.orientation??"portrait")==="landscape"&&n<s&&([n,s]=[s,n]);let o=e.margin??"15mm",r=typeof o=="string"?{top:Y(o),right:Y(o),bottom:Y(o),left:Y(o)}:{top:Y(o.top),right:Y(o.right),bottom:Y(o.bottom),left:Y(o.left)};return{width:n,height:s,...r}}async function Zt(e,t,n){let s=new dt({compress:n.compress}),o=(n.header?.heightPx??0)*.75,r=(n.footer?.heightPx??0)*.75,i=t.width-t.left-t.right,a=t.height-t.top-o,c=t.height-t.top-t.bottom-o-r;if(c<=0)throw new Error("Page content area is empty: margins + header + footer exceed the page height");let h=c/.75,p=Jt(e,h),f=p.length,d=[],u=[];for(let g=0;g<f;g++)d.push(n.header?await n.header.render(g+1,f):null),u.push(n.footer?await n.footer.render(g+1,f):null);let w=new Map,y=new Map,C=g=>{for(let x of g)if(x.type==="text"){let S=w.get(x.font);S||(S=new gt(x.font.parsed,`F${w.size+1}`),w.set(x.font,S));for(let F of x.glyphs)S.addGlyph(F.gid,F.cp)}else x.type==="image"?y.has(x.image.key)||y.set(x.image.key,{name:`Im${y.size+1}`,image:x.image}):(x.type==="group"||x.type==="clip")&&C(x.items)};C(e.items);for(let g of[...d,...u])g&&C(g.items);for(let g of w.values())g.finalize();let O={};for(let g of w.values())O[g.resourceName]=await g.embed(s);let R={};for(let g of y.values())R[g.name]=await Kt(s,g.image);let D=new Map,L={},j=g=>{let x=U(g),S=D.get(x);return S||(S=`GS${D.size+1}`,D.set(x,S),L[S]=s.add({Type:"ExtGState",ca:g,CA:g})),S},z=s.reserve(),X=[];for(let g=0;g<f;g++){let x=p[g],S=new pt,F=new Ut(S,t,w,y,j),E=x.headShift*.75,k=x.footShift*.75;S.save(),S.rect(t.left,a-c+k,i,c-E-k).clip(),F.setOrigin(a-E,x.start),F.render(e.items,x),S.restore();let I=a-E-(x.end-x.start)*.75;for(let b of x.feet){let T=(b.table.footBottom-b.table.footTop)*.75,B=I-b.shift*.75-T;S.save(),S.rect(t.left,B,i,T).clip(),F.setOrigin(B+T,b.table.footTop),F.render(b.table.footItems),S.restore()}for(let b of x.heads){S.save();let T=(b.table.headBottom-b.table.headTop)*.75;S.rect(t.left,a-b.shift*.75-T,i,T).clip(),F.setOrigin(a-b.shift*.75,b.table.headTop),F.render(b.table.headItems),S.restore()}let M=d[g];M&&(S.save(),S.rect(t.left,t.height-t.top-o,i,o).clip(),F.setOrigin(t.height-t.top,0),F.render(M.items),S.restore());let N=u[g];N&&(S.save(),S.rect(t.left,t.bottom,i,r).clip(),F.setOrigin(t.bottom+r,0),F.render(N.items),S.restore());let W=await s.addStream({},S.toBytes());X.push(s.add({Type:"Page",Parent:z,MediaBox:[0,0,t.width,t.height],Resources:{Font:O,XObject:R,ExtGState:L,ProcSet:[new J("PDF"),new J("Text"),new J("ImageC")]},Contents:W}))}s.set(z,{Type:"Pages",Kids:X,Count:X.length});let et=s.add({Type:"Catalog",Pages:z}),$=n.metadata??{},l={Producer:nt("receipt-html-to-pdf"),Creator:nt($.creator??"receipt-html-to-pdf"),CreationDate:Vt($.creationDate??new Date)};$.title&&(l.Title=nt($.title)),$.author&&(l.Author=nt($.author)),$.subject&&(l.Subject=nt($.subject)),$.keywords&&(l.Keywords=nt($.keywords));let m=s.add(l);return s.build(et,m)}function Ne(e,t){if(e.type==="text"){let s=(e.top+e.bottom)/2;return s>=t.start-.01&&s<t.end-.01}return Ge(e)>t.start+.01&&We(e)<t.end-.01}var Ut=class{constructor(t,n,s,o,r){this.cs=t,this.geo=n,this.fonts=s,this.images=o,this.gsName=r,this.pdfTop=n.height-n.top,this.docTop=0,this.curAlpha=1}setOrigin(t,n){this.pdfTop=t,this.docTop=n}X(t){return this.geo.left+t*.75}Y(t){return this.pdfTop-(t-this.docTop)*.75}setAlpha(t){Math.abs(t-this.curAlpha)<.001||(this.cs.setGState(this.gsName(t)),this.curAlpha=t)}radiusPt(t){return(t??[0,0,0,0]).map(n=>n*.75)}clipBox(t){let n=this.cs;t.radius?n.roundedRect(this.X(t.x),this.Y(t.y+t.h),t.w*.75,t.h*.75,this.radiusPt(t.radius)):n.rect(this.X(t.x),this.Y(t.y+t.h),t.w*.75,t.h*.75),n.clip()}render(t,n){let s=this.cs;for(let o of t)if(!(n&&!Ne(o,n)))if(o.type==="rect"){if(o.w<=0||o.h<=0)continue;s.save(),this.setAlpha(o.color.a),s.fillColor(o.color.r,o.color.g,o.color.b),o.radius?s.roundedRect(this.X(o.x),this.Y(o.y+o.h),o.w*.75,o.h*.75,this.radiusPt(o.radius)).fill():s.fillRect(this.X(o.x),this.Y(o.y+o.h),o.w*.75,o.h*.75),s.restore(),this.curAlpha=1}else if(o.type==="line")s.save(),this.setAlpha(o.color.a),s.strokeColor(o.color.r,o.color.g,o.color.b),s.lineWidth(o.width*.75),o.dash&&s.dash(o.dash.map(r=>r*.75)),s.moveTo(this.X(o.x1),this.Y(o.y1)).lineTo(this.X(o.x2),this.Y(o.y2)).stroke(),s.restore(),this.curAlpha=1;else if(o.type==="stroke-rrect")s.save(),this.setAlpha(o.color.a),s.strokeColor(o.color.r,o.color.g,o.color.b),s.lineWidth(o.width*.75),o.dash&&s.dash(o.dash.map(r=>r*.75)),s.roundedRect(this.X(o.x),this.Y(o.y+o.h),o.w*.75,o.h*.75,this.radiusPt(o.radius)).stroke(),s.restore(),this.curAlpha=1;else if(o.type==="image"){let r=this.images.get(o.image.key);if(!r||o.w<=0||o.h<=0)continue;s.save(),this.setAlpha(o.alpha),o.clip&&this.clipBox(o.clip),s.image(r.name,this.X(o.x),this.Y(o.y+o.h),o.w*.75,o.h*.75),s.restore(),this.curAlpha=1}else if(o.type==="text"){let r=this.fonts.get(o.font),i=ze(o,r);s.save(),this.setAlpha(o.color.a),s.fillColor(o.color.r,o.color.g,o.color.b),s.text(r.resourceName,o.size*.75,this.X(o.x),this.Y(o.y),i),s.restore(),this.curAlpha=1}else if(o.type==="group"){let[r,i,a,c]=o.matrix,h=this.X(o.origin.x),p=this.Y(o.origin.y),f=r,d=-i,u=-a,w=c,y=h-(f*h+u*p)+o.matrix[4]*.75,C=p-(d*h+w*p)-o.matrix[5]*.75;s.save(),s.transform(f,d,u,w,y,C),this.render(o.items,n),s.restore()}else o.type==="clip"&&(s.save(),this.clipBox(o.box),this.render(o.items,n),s.restore())}};function ze(e,t){let n=[],s="";for(let o=0;o<e.glyphs.length;o++){let r=e.glyphs[o];s+=rt(t.cid(r.gid));let i=e.glyphs[o+1];if(!i)break;let a=r.x+r.advance,h=-(i.x-a)/e.size*1e3;Math.abs(h)>=.5&&(n.push(s,Math.round(h*10)/10),s="")}return s&&n.push(s),n}function We(e){return e.type==="rect"||e.type==="stroke-rrect"||e.type==="image"?e.y:e.type==="line"?Math.min(e.y1,e.y2)-e.width/2:(e.type==="group"||e.type==="clip",e.top)}function Ge(e){return e.type==="rect"||e.type==="stroke-rrect"||e.type==="image"?e.y+e.h:e.type==="line"?Math.max(e.y1,e.y2)+e.width/2:(e.type==="group"||e.type==="clip",e.bottom)}var Mn="0.2.1",yt=new ct;async function An(e){if(!e||!e.family||!e.src)throw new TypeError("registerFont: { family, src } are required");(await yt.register(e)).parsed.variable&&console.warn(`[receipt-html-to-pdf] "${e.family}" is a variable font; only the default instance outlines are embedded. Use static TTF instances for other weights.`)}function In(){return yt.fonts.map(e=>({family:e.displayFamily,weight:e.weight,style:e.style,glyphs:e.parsed.numGlyphs}))}async function Rn(e,t={}){if(typeof document>"u")throw new Error("htmlToPdf must run in a browser (needs DOM layout)");if(yt.fonts.length===0)throw new Error("htmlToPdf: no fonts registered. Call registerFont() with at least one TrueType font first.");let n=t.onWarning??(()=>{}),s=Qt(t.page),o=(s.width-s.left-s.right)/.75,r=await St(e,{widthPx:o,stylesheets:t.stylesheets??"inherit",mediaPrint:t.mediaPrint??!1,baseUrl:t.baseUrl,warn:n}),i={registry:yt,fontFallback:t.fontFallback??[],warn:n,textMeasure:t.textMeasure??"auto"},a={widthPx:o,stylesheets:t.stylesheets??"inherit",mediaPrint:t.mediaPrint??!1,baseUrl:t.baseUrl,warn:n};try{let c=await Ft(r.root,i),h=t.header?await te(t.header,a,i):null,p=t.footer?await te(t.footer,a,i):null,f=await Zt(c,s,{compress:t.compress??!0,metadata:t.metadata,header:h,footer:p});return He(f,t.output??"blob")}finally{r.destroy()}}async function te(e,t,n){let s=async(i,a)=>{let c=e.replace(/\{\{\s*pageNumber\s*\}\}/g,String(i)).replace(/\{\{\s*totalPages\s*\}\}/g,String(a)),h=await St(c,t);try{return await Ft(h.root,n)}finally{h.destroy()}},o=await s(1,1),r=new Map([["1/1",o]]);return{heightPx:o.height,render:async(i,a)=>{let c=`${i}/${a}`,h=r.get(c);return h||(h=await s(i,a),r.set(c,h)),h}}}function He(e,t){if(t==="uint8array")return e;if(t==="dataurl"){let n="";for(let s=0;s<e.length;s+=32768)n+=String.fromCharCode(...e.subarray(s,s+32768));return"data:application/pdf;base64,"+btoa(n)}return new Blob([e],{type:"application/pdf"})}function Bn(e,t){let n=e instanceof Blob?e:new Blob([e],{type:"application/pdf"}),s=URL.createObjectURL(n),o=document.createElement("a");o.href=s,o.download=t,document.body.appendChild(o),o.click(),o.remove(),setTimeout(()=>URL.revokeObjectURL(s),1e3)}export{Bn as downloadPdf,ot as expandPrintMediaCss,Rn as htmlToPdf,In as listFonts,An as registerFont,Mn as version};
42
42
  //# sourceMappingURL=receipt-html-to-pdf.min.js.map