on-munseo-local 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/MANIFEST.json +453 -214
  2. package/NOTICE.md +22 -0
  3. package/README.md +129 -44
  4. package/licenses/OnFonts-Baekmuk-COPYRIGHT.txt +23 -0
  5. package/licenses/OnFonts-OFL.txt +103 -0
  6. package/licenses/canvaskit/README.md +30 -0
  7. package/licenses/canvaskit/brotli-LICENSE +19 -0
  8. package/licenses/canvaskit/emscripten-LICENSE +102 -0
  9. package/licenses/canvaskit/emscripten-compiler-rt-LICENSE.TXT +311 -0
  10. package/licenses/canvaskit/emscripten-libcxx-LICENSE.TXT +311 -0
  11. package/licenses/canvaskit/emscripten-libcxxabi-LICENSE.TXT +311 -0
  12. package/licenses/canvaskit/emscripten-musl-COPYRIGHT +193 -0
  13. package/licenses/canvaskit/freetype-FTL.TXT +169 -0
  14. package/licenses/canvaskit/freetype-LICENSE.TXT +47 -0
  15. package/licenses/canvaskit/harfbuzz-COPYING +42 -0
  16. package/licenses/canvaskit/icu-LICENSE +568 -0
  17. package/licenses/canvaskit/libjpeg-turbo-LICENSE.md +135 -0
  18. package/licenses/canvaskit/libjpeg-turbo-README.ijg +260 -0
  19. package/licenses/canvaskit/libpng-LICENSE +134 -0
  20. package/licenses/canvaskit/libwebp-COPYING +30 -0
  21. package/licenses/canvaskit/libwebp-PATENTS +23 -0
  22. package/licenses/canvaskit/wuffs-LICENSE +202 -0
  23. package/licenses/canvaskit/zlib-LICENSE +19 -0
  24. package/licenses/canvaskit-BSD-3-Clause.txt +29 -0
  25. package/local/build.json +3 -3
  26. package/local/canvaskit/canvaskit.cjs +265 -0
  27. package/local/canvaskit/canvaskit.wasm +0 -0
  28. package/local/ck2d.js +2 -0
  29. package/local/config.js +1 -1
  30. package/local/fonts/OnBatang-Main.woff2 +0 -0
  31. package/local/fonts/OnBatangChe-Main.woff2 +0 -0
  32. package/local/fonts/OnDotum-Main.woff2 +0 -0
  33. package/local/fonts/OnDotumChe-Main.woff2 +0 -0
  34. package/local/fonts/OnGothic-Main.woff2 +0 -0
  35. package/local/fonts/OnGulim-Main.woff2 +0 -0
  36. package/local/fonts/OnGulimChe-Main.woff2 +0 -0
  37. package/local/fonts/OnHangyeolBatang-Main.woff2 +0 -0
  38. package/local/fonts/OnHangyeolBatangBold-Main.woff2 +0 -0
  39. package/local/fonts/OnHangyeolDotum-Main.woff2 +0 -0
  40. package/local/fonts/OnHangyeolDotumBold-Main.woff2 +0 -0
  41. package/local/fonts/OnHeadline-Ext.woff2 +0 -0
  42. package/local/fonts/OnHeadline-Hanja.woff2 +0 -0
  43. package/local/fonts/OnHeadline-Main.woff2 +0 -0
  44. package/local/fonts/OnJungGothic-Main.woff2 +0 -0
  45. package/local/fonts/OnJungGothic2-Main.woff2 +0 -0
  46. package/local/fonts/OnJungMyeongjo-Main.woff2 +0 -0
  47. package/local/fonts/OnKyunGothic-Main.woff2 +0 -0
  48. package/local/fonts/OnKyunGothic2-Main.woff2 +0 -0
  49. package/local/fonts/OnKyunMyeongjo-Main.woff2 +0 -0
  50. package/local/fonts/OnKyunMyeongjo2-Main.woff2 +0 -0
  51. package/local/fonts/OnMyeongjo-Ext.woff2 +0 -0
  52. package/local/fonts/OnMyeongjo-Hanja.woff2 +0 -0
  53. package/local/fonts/OnMyeongjo-Main.woff2 +0 -0
  54. package/local/fonts/OnSaeMyeongjo2-Main.woff2 +0 -0
  55. package/local/fonts/OnSinMyeongjo-Main.woff2 +0 -0
  56. package/local/fonts/OnTtogothic-Ext.woff2 +0 -0
  57. package/local/fonts/OnTtogothic-Hanja.woff2 +0 -0
  58. package/local/fonts/OnTtogothic-Main.woff2 +0 -0
  59. package/local/fonts/OnTtogothicBold-Main.woff2 +0 -0
  60. package/local/fonts/fonts.json +1 -0
  61. package/local/imgsized.js +2 -0
  62. package/local/main.js +1 -1
  63. package/local/pagefonts.js +2 -0
  64. package/local/setup.js +1 -1
  65. package/package.json +3 -2
  66. package/public/js/gongcheck.js +1 -1
  67. package/public/js/plain_rules.js +1 -1
  68. package/public/js/spellcheck.js +1 -1
  69. package/server/calcwork_worker.js +1 -1
  70. package/server/offwork_worker.js +1 -1
  71. package/server/onform.js +1 -1
  72. package/server/onsvc/core_local.js +1 -1
  73. package/server/onsvc/router.js +1 -1
  74. package/server/onsvc/svgdraw.js +2 -0
  75. package/server/onsvc/worker.js +1 -1
  76. package/server/ontext.js +1 -1
  77. package/server/ontext_hwp.js +1 -1
  78. package/server/ontext_table.js +1 -1
  79. package/server/ontext_tools.js +1 -1
  80. package/server/ontext_zip.js +1 -1
  81. package/server/onwrite.js +1 -1
  82. package/server/onwrite_gov.js +1 -1
  83. package/server/onwrite_numcheck.js +1 -1
  84. package/server/onwrite_review.js +1 -1
  85. package/server/pdfmd.js +1 -1
  86. package/server/zipcap.js +1 -1
  87. package/trial/server/checks.js +1 -1
  88. package/trial/server/mcp_extra.js +1 -1
  89. package/trial/server/mcp_more.js +1 -1
  90. package/trial/web/app/gallery/g01.hwpx +0 -0
  91. package/trial/web/app/gallery/g02.hwpx +0 -0
  92. package/trial/web/app/gallery/g03.hwpx +0 -0
  93. package/trial/web/app/gallery/g04.hwpx +0 -0
  94. package/trial/web/app/gallery/g05.hwpx +0 -0
  95. package/trial/web/app/gallery/g06.hwpx +0 -0
  96. package/trial/web/app/gallery/g07.hwpx +0 -0
  97. package/trial/web/app/gallery/g08.hwpx +0 -0
  98. package/trial/web/app/gallery/g09.hwpx +0 -0
  99. package/trial/web/app/gallery/g10.hwpx +0 -0
  100. package/trial/web/app/gallery/g11.hwpx +0 -0
  101. package/trial/web/app/gallery/g12.hwpx +0 -0
  102. package/trial/web/app/gallery/g13.hwpx +0 -0
  103. package/trial/web/app/gallery/g14.hwpx +0 -0
  104. package/trial/web/app/gallery/g15.hwpx +0 -0
  105. package/trial/web/app/gallery/g16.hwpx +0 -0
  106. package/trial/web/app/gallery/g17.hwpx +0 -0
  107. package/trial/web/app/gallery/g18.hwpx +0 -0
  108. package/trial/web/app/gallery/g19.hwpx +0 -0
  109. package/trial/web/app/gallery/g20.hwpx +0 -0
  110. package/trial/web/app/gallery/g21.hwpx +0 -0
  111. package/trial/web/app/gallery/g22.hwpx +0 -0
  112. package/trial/web/app/gallery/g23.hwpx +0 -0
  113. package/trial/web/app/gallery/g24.hwpx +0 -0
  114. package/trial/web/app/gallery/g25.hwpx +0 -0
  115. package/trial/web/app/gallery/g26.hwpx +0 -0
  116. package/trial/web/app/gallery/g27.hwpx +0 -0
  117. package/trial/web/app/gallery/g28.hwpx +0 -0
  118. package/trial/web/app/gallery/g29.hwpx +0 -0
  119. package/trial/web/app/gallery/g30.hwpx +0 -0
  120. package/trial/web/app/gallery/g31.hwpx +0 -0
  121. package/trial/web/app/gallery/g32.hwpx +0 -0
  122. package/trial/web/app/gallery/g33.hwpx +0 -0
  123. package/trial/web/app/gallery/g34.hwpx +0 -0
  124. package/trial/web/app/gallery/g35.hwpx +0 -0
  125. package/trial/web/app/gallery/g36.hwpx +0 -0
  126. package/trial/web/app/gallery/g37.hwpx +0 -0
  127. package/trial/web/app/gallery/g38.hwpx +0 -0
  128. package/trial/web/app/gallery/g39.hwpx +0 -0
  129. package/trial/web/app/gallery/g40.hwpx +0 -0
  130. package/trial/web/app/gallery/g41.hwpx +0 -0
  131. package/trial/web/app/gallery/g42.hwpx +0 -0
  132. package/trial/web/app/gallery/g43.hwpx +0 -0
  133. package/trial/web/app/gallery/g44.hwpx +0 -0
  134. package/trial/web/app/gallery/g45.hwpx +0 -0
  135. package/trial/web/app/gallery/g46.hwpx +0 -0
  136. package/trial/web/app/gallery/g47.hwpx +0 -0
  137. package/trial/web/app/gallery/g48.hwpx +0 -0
  138. package/trial/web/app/gallery/g49.hwpx +0 -0
  139. package/trial/web/app/gallery/g50.hwpx +0 -0
  140. package/trial/web/app/gallery/g51.hwpx +0 -0
  141. package/trial/web/app/gallery/g52.hwpx +0 -0
  142. package/trial/web/app/gallery/g53.hwpx +0 -0
  143. package/trial/web/app/gallery/g54.hwpx +0 -0
  144. package/trial/web/app/gallery/g55.hwpx +0 -0
  145. package/trial/web/app/gallery/g56.hwpx +0 -0
  146. package/trial/web/app/gallery/g57.hwpx +0 -0
  147. package/trial/web/app/gallery/g58.hwpx +0 -0
  148. package/trial/web/app/gallery/g59.hwpx +0 -0
  149. package/trial/web/app/gallery/g60.hwpx +0 -0
  150. package/trial/web/app/gallery/g61.hwpx +0 -0
  151. package/trial/web/app/gallery/g62.hwpx +0 -0
  152. package/trial/web/app/gallery/g63.hwpx +0 -0
  153. package/trial/web/app/gallery/g64.hwpx +0 -0
  154. package/trial/web/app/gallery/g65.hwpx +0 -0
  155. package/trial/web/app/gallery/g66.hwpx +0 -0
  156. package/trial/web/app/js/refdoc.js +1 -1
package/server/pdfmd.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! On 문서 내 PC 판 · on-munseo — 엔진·코드의 무단 복제·배포·재사용·역공학 금지(이용약관 제5조). 오픈소스 부품은 각 라이선스를 따름 */
2
- import t from"path";import{fileURLToPath as e}from"url";import{tidy as s,styled as n,headingLevel as o,MK as l,litMark as r,litResolve as a}from"./ontext_table.js";const i=t.resolve(t.dirname(e(import.meta.url)),".."),h=t.join(i,"node_modules","pdfjs-dist");let c=null;const f=()=>c||=import("pdfjs-dist/legacy/build/pdf.mjs"),x=t=>{if(!t.length)return 0;const e=[...t].sort(((t,e)=>t-e));return e[e.length>>1]},p=/bold|black|heavy|semibold|semibd|demibold|demi\b|extrab|ultrab|[-,]b$|-sb$|-hv$|_bd$|[-_]bd\b|cmbx|cmssbx|cmb\d|\bbx\d|-medi(ital)?$/i,m=t=>("2"===process.env.PDFMD_DEBUG&&console.error("[pdfmd] 표 아님",t,(new Error).stack.split("\n")[3].trim().slice(0,60)),null),u=t=>String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),g={108:"●",109:"❍",110:"■",111:"□",113:"❑",117:"◆",118:"❖",119:"⬥",158:"·",159:"•",167:"▪",168:"◻",216:"➢",231:"⬅",232:"➔",233:"⬆",234:"⬇",252:"✔",140:"❶",141:"❷",142:"❸",143:"❹",144:"❺"},b={"Œ":140,"Ž":142,"ž":158,"Ÿ":159},M=t=>[...t].map((t=>{let e=b[t]??t.codePointAt(0);return e>=61440&&e<=61695&&(e-=61440),g[e]||t})).join(""),d={zero:"0",one:"1",two:"2",three:"3",four:"4",five:"5",six:"6",seven:"7",eight:"8",nine:"9",hyphen:"-",period:".",comma:",",colon:":",semicolon:";",ampersand:"&",quoteright:"’",quoteleft:"‘",quotedblleft:"“",quotedblright:"”",parenleft:"(",parenright:")",slash:"/",endash:"–",emdash:"—",exclam:"!",question:"?",percent:"%",dollar:"$",space:" "},y=t=>{if(!t||"string"!=typeof t)return null;const e=t.split(".")[0].split("_").map((t=>1===t.length?t:d[t]??(/^uni[0-9A-F]{4}$/.test(t)?String.fromCharCode(parseInt(t.slice(3),16)):null)));if(!e.length||!e.every((t=>null!=t&&""!==t)))return null;const s=e.join("");return/\.(sc|smcp|c2sc)$/i.test(t)?s.toUpperCase():s};function z(t,e,s,n,o=null,l=null){const r=[],a=[];let i=null;for(const[h,c]of t.items.entries()){if(!c.str||!c.str.trim()){if(c.str&&r.length){const t=s.transform(e,c.transform);if(i={w:Math.abs(c.width),x0:t[4],prev:r[r.length-1],g:c.fontName+"|"+Math.round(Math.hypot(t[2],t[3]))},i.w>1.5*(Math.hypot(t[2],t[3])||10)*Math.max(1,c.str.length)){i=null;continue}i.prev.sp="real",i.prev.ws=i}continue}const t=s.transform(e,c.transform),f=Math.hypot(t[2],t[3])||Math.abs(c.height)||10,x=Math.hypot(t[0],t[1]);if(!x||Math.abs(t[1])>.08*Math.abs(t[0])||t[0]<0){if(x&&Math.abs(t[0])<=.08*x&&c.str.trim()&&Math.abs(c.width)>0){const e=Math.hypot(t[2],t[3])||10,s=t[1]/x,o=t[2]/e,l=Math.abs(c.width),r=t[4],i=t[5],h=[r,r+.8*o*e,r-.2*o*e],f=[i,i+s*l];a.push({s:c.str.replace(/\s+/g," ").trim(),x0:Math.min(...h),x1:Math.max(...h),top:Math.min(...f),bot:Math.max(...f),base:Math.max(...f),size:e,rot:!0,bold:p.test(n(c.fontName)),font:n(c.fontName),i:-1})}i=null;continue}const m=c.width,u=t[4],g=t[5];let b=c.str;if(l&&/[\u0000-\u0008\u000e-\u001f]/.test(b)){const t=l(c.fontName);t&&(b=[...b].map((e=>{const s=e.charCodeAt(0);return s>=32||9===s||10===s||13===s?e:y(t[s])??e})).join(""))}if(/^(?:\S )+\S$/.test(b.trim())&&/[가-힣]/.test(b)){const t=b.trim().split(" "),e=t.reduce(((t,e)=>t+(/[가-힣ㆍ]/.test(e)?1:/[0-9]/.test(e)?.55:.5)),0)*f;(Math.abs(m)-e)/(t.length-1)<.2*f&&(b=t.join(""))}const d=n(c.fontName),z={s:(/wingdings(?![-\s]?[23])/i.test(d)?M(b):b).replace(/(^|[^\u1100-\u115f])\u119e/g,"$1ㆍ").replace(/^(?:[A-Z0-9] ){2,}[A-Z0-9?!.:]$/,(t=>t.replace(/ /g,""))).replace(/\s+/g," ").replace(/\.(?: \.){2,}/g,(t=>t.replace(/ /g,""))),x0:u,x1:u+Math.max(m,.1),base:g,size:f,top:g-.82*f,bot:g+.22*f,bold:p.test(d)||!(!o||!o.has(h)),font:d,i:r.length};i&&(Math.abs(g-i.prev.base)<=.3*f&&i.x0>=i.prev.x1-1&&i.x0<=u+1&&(i.next=z),i=null),r.push(z)}{const t=t=>t&&1===t.s.length&&/[^\p{L}\p{N}]/u.test(t.s),e={};for(const s of r){const n=s.ws;n&&n.next&&!t(s)&&!t(n.next)&&n.w<=s.size&&(e[n.g]||=[]).push(n.w)}for(const s of r){const n=s.ws;if(!n||!n.next)continue;const o=n.next.x0-s.x1,l=e[n.g]||[];o>0&&/[.:;,!?)]$/.test(s.s)&&/^[A-Za-z]{2}/.test(n.next.s)||((o<=0||n.w>=.5*o)&&n.w<.25*s.size&&(t(s)||t(n.next))&&(l.length<2||n.w<.75*x(l))||o<=0&&(t(s)||t(n.next)))&&(s.sp="fake")}for(const t of r)delete t.ws}{const t=x(r.map((t=>t.size)));for(const e of r){if(!/^[A-Z]$/.test(e.s)||e.size<2.5*t)continue;const s=r.filter((s=>s!==e&&s.x0>=e.x1-2&&s.x0<=e.x1+1.5*t&&s.top>=e.top-.5*t&&s.top<=e.bot&&s.size<.5*e.size));if(!s.length)continue;const n=s.reduce(((t,e)=>e.top<t.top-1||Math.abs(e.top-t.top)<=1&&e.x0<t.x0?e:t));Object.assign(e,{x0:n.x0-.6*n.size,x1:n.x0,base:n.base,size:n.size,top:n.top,bot:n.bot,sp:void 0})}}const h=new Map,c=(t,e,s)=>t+"\0"+e+","+s,f=r.filter((t=>{const e=Math.floor(t.x0/1.5),s=Math.floor(t.base/1.5);for(let n=-1;n<=1;n++)for(let o=-1;o<=1;o++){const l=h.get(c(t.s,e+n,s+o));if(l&&l.some((e=>Math.abs(e.x0-t.x0)<=1.5&&Math.abs(e.base-t.base)<=1.5&&Math.abs(e.size-t.size)<=.5)))return!1}const n=c(t.s,e,s),o=h.get(n);return o?o.push(t):h.set(n,[t]),!0})),m=new Map,u=t=>Math.round(2*t);for(const t of f)if(t.s.length>1){const e=u(t.base),s=m.get(e);s?s.push(t):m.set(e,[t])}const g=m.size?f.filter((t=>!(t=>{const e=t.s.trim();if(!e||e.length>3)return!1;for(let s=-1;s<=1;s++)for(const n of m.get(u(t.base)+s)||[])if(!(n===t||n.s.trim().length<=e.length||Math.abs(n.base-t.base)>.5||Math.abs(n.size-t.size)>.5)&&(n.s.trimEnd().endsWith(e)&&Math.abs(n.x1-t.x1)<=.5&&t.x0>=n.x0||n.s.trimStart().startsWith(e)&&Math.abs(n.x0-t.x0)<=.5&&t.x1<=n.x1))return!0;return!1})(t))):f;return g.rot=a,g}const w={onequarter:"=",thorn:"+",eth:"(",Thorn:")",onehalf:"[",C138:"]",C0:"−",C1:"·",C2:"×"},v=(t,e,s,n)=>{const o=String(t||"").replace(/^[A-Z]{6}\+/,"");return/^TeXCMMathsSymbols\b/.test(o)?s&&w[s]||null:/^TeXCMMathsItalic\b/.test(o)&&!s?58===e&&":"===n?".":59===e&&";"===n?",":null:null},$=t=>{if(null==t)return null;if("string"==typeof t[0])return t[0].toLowerCase();if(t.length>=3&&"number"==typeof t[0]){const e=ArrayBuffer.isView(t);return"#"+Array.from(t).slice(0,3).map((t=>Math.max(0,Math.min(255,Math.round(e||t>1?t:255*t))).toString(16).padStart(2,"0"))).join("")}return null};function k(t,e,s,n,o=!1){let l=[1,0,0,1,0,0],r=1,a="#000000",i="#000000",h=null,c=1;const f=[],x=[],p=[],m=[],u=[],g=[],b=(t,e)=>s.applyTransform(s.applyTransform([t,e],l),n),M=[],d=(t,e,s)=>{const n=Math.abs(t[0]-e[0]),l=Math.abs(t[1]-e[1]);l<=1&&n>=2?x.push({y:(t[1]+e[1])/2,x0:Math.min(t[0],e[0]),x1:Math.max(t[0],e[0]),w:s}):n<=1&&l>=2?p.push({x:(t[0]+e[0])/2,y0:Math.min(t[1],e[1]),y1:Math.max(t[1],e[1]),w:s}):o&&Math.max(n,l)>=.1&&Math.min(n,l)<=.3&&M.push(n>=l?{h:1,y:(t[1]+e[1])/2,a0:Math.min(t[0],e[0]),a1:Math.max(t[0],e[0]),w:s}:{h:0,x:(t[0]+e[0])/2,a0:Math.min(t[1],e[1]),a1:Math.max(t[1],e[1]),w:s})},y=t=>{if(h){for(const e of h)if(e.rect){const[s,n,o,l]=e.rect,a=b(s,n),h=b(s+o,n+l),f=Math.min(a[0],h[0]),x=Math.max(a[0],h[0]),p=Math.min(a[1],h[1]),u=Math.max(a[1],h[1]),g=x-f,M=u-p;"stroke"!==t&&Math.min(g,M)<=2.5?g>=M?d([f,(p+u)/2],[x,(p+u)/2],M):d([(f+x)/2,p],[(f+x)/2,u],g):"fill"!==t&&(d([f,p],[x,p],r),d([f,u],[x,u],r),d([f,p],[f,u],r),d([x,p],[x,u],r)),"stroke"!==t&&Math.min(g,M)>2.5&&c>.05&&m.push({x0:f,x1:x,y0:p,y1:u,col:i})}else if("fill"!==t){if("both"===t){const t=A(e);t&&c>.05&&m.push({...t,col:i})}for(let t=1;t<e.pts.length;t++)e.curve[t]||d(e.pts[t-1],e.pts[t],r*(Math.sqrt(Math.abs(l[0]*l[3]-l[1]*l[2]))||1))}else{const t=A(e);t&&c>.05&&m.push({...t,col:i})}h=null}};for(let n=0;n<t.fnArray.length;n++){const o=t.fnArray[n],x=t.argsArray[n];switch(o){case e.save:f.push([l,r,a,i,c]);break;case e.restore:f.length&&([l,r,a,i,c]=f.pop());break;case e.transform:l=s.transform(l,x);break;case e.paintFormXObjectBegin:f.push([l,r,a,i,c]),x&&Array.isArray(x[0])&&6===x[0].length&&(l=s.transform(l,x[0]));break;case e.paintFormXObjectEnd:f.length&&([l,r,a,i,c]=f.pop());break;case e.setGState:for(const[t,e]of x&&x[0]||[])"ca"===t&&"number"==typeof e&&(c=e);break;case e.setLineWidth:r=x[0];break;case e.setStrokeRGBColor:a=$(x)||a;break;case e.setFillRGBColor:i=$(x)||i;break;case e.setStrokeGray:a=$([x[0],x[0],x[0]]);break;case e.setFillGray:i=$([x[0],x[0],x[0]]);break;case e.constructPath:{const[t,s]=x;let n=0;h=h||[];let o=null;for(const l of t)l===e.rectangle?(h.push({rect:[s[n],s[n+1],s[n+2],s[n+3]]}),n+=4,o=null):l===e.moveTo?(o={pts:[b(s[n],s[n+1])],curve:[!1]},h.push(o),n+=2):l===e.lineTo?(o||(o={pts:[],curve:[]},h.push(o)),o.pts.push(b(s[n],s[n+1])),o.curve.push(!1),n+=2):l===e.curveTo?(o&&(o.pts.push(b(s[n+4],s[n+5])),o.curve.push(!0)),n+=6):l===e.curveTo2||l===e.curveTo3?(o&&(o.pts.push(b(s[n+2],s[n+3])),o.curve.push(!0)),n+=4):l===e.closePath&&o&&o.pts.length>1&&(o.pts.push(o.pts[0]),o.curve.push(!1));break}case e.stroke:case e.closeStroke:y("stroke");break;case e.fill:case e.eoFill:y("fill");break;case e.fillStroke:case e.eoFillStroke:case e.closeFillStroke:case e.closeEOFillStroke:y("both");break;case e.clip:case e.eoClip:if(h&&1===h.length){const t=h[0];let e=null;if(t.rect){const[s,n,o,l]=t.rect,r=b(s,n),a=b(s+o,n+l);e={x0:Math.min(r[0],a[0]),x1:Math.max(r[0],a[0]),y0:Math.min(r[1],a[1]),y1:Math.max(r[1],a[1])}}else e=A(t,.3);e&&g.push(e)}break;case e.endPath:h=null;break;case e.paintImageXObject:case e.paintInlineImageXObject:case e.paintImageMaskXObject:{const t=b(0,0),e=b(1,1),s=Math.min(t[0],e[0]),n=Math.max(t[0],e[0]),o=Math.min(t[1],e[1]),l=Math.max(t[1],e[1]);n-s>=4&&l-o>=4&&u.push({x0:s,x1:n,y0:o,y1:l});break}}}for(const t of[1,0]){const e=M.filter((e=>e.h===t)).map((e=>({...e,k:t?e.y:e.x}))).sort(((t,e)=>t.k-e.k||t.a0-e.a0));let s=null;const n=()=>{s&&s.n>=3&&s.a1-s.a0>=4&&(t?x:p).push(t?{y:s.k,x0:s.a0,x1:s.a1,w:s.w,dot:!0}:{x:s.k,y0:s.a0,y1:s.a1,w:s.w,dot:!0})};for(const t of e)s&&Math.abs(t.k-s.k)<=.3&&t.a0-s.a1<=3?(s.a1=Math.max(s.a1,t.a1),s.n++):(n(),s={k:t.k,a0:t.a0,a1:t.a1,w:t.w,n:1});n()}return{H:j(x),V:X(p),F:m,I:u,C:g,H0:x,V0:p}}function A(t,e=2.5){if(!t.pts||t.pts.length<4||t.pts.length>6||t.curve.some(Boolean))return null;const s=t.pts.map((t=>t[0])),n=t.pts.map((t=>t[1]));for(let e=1;e<t.pts.length;e++){const t=Math.abs(s[e]-s[e-1]),o=Math.abs(n[e]-n[e-1]);if(t>.5&&o>.5)return null}const o=Math.min(...s),l=Math.max(...s),r=Math.min(...n),a=Math.max(...n);return l-o<=e||a-r<=e?null:t.pts.every((t=>(Math.abs(t[0]-o)<=.5||Math.abs(t[0]-l)<=.5)&&(Math.abs(t[1]-r)<=.5||Math.abs(t[1]-a)<=.5)))?{x0:o,x1:l,y0:r,y1:a}:null}function j(t){t.sort(((t,e)=>t.y-e.y||t.x0-e.x0));const e=[];for(const s of t){const t=e.find((t=>Math.abs(t.y-s.y)<=1.2&&s.x0<=t.x1+2&&s.x1>=t.x0-2));t?(t.x0=Math.min(t.x0,s.x0),t.x1=Math.max(t.x1,s.x1)):e.push({...s})}return e}function X(t){t.sort(((t,e)=>t.x-e.x||t.y0-e.y0));const e=[];for(const s of t){const t=e.find((t=>Math.abs(t.x-s.x)<=1.2&&s.y0<=t.y1+2&&s.y1>=t.y0-2));t?(t.y0=Math.min(t.y0,s.y0),t.y1=Math.max(t.y1,s.y1)):e.push({...s})}return e}const S=(t,e)=>{const s=[...t].sort(((t,e)=>t-e)),n=[];for(const t of s)if(n.length&&t-n[n.length-1].hi<=e){const e=n[n.length-1];e.hi=t,e.sum+=t,e.n++}else n.push({lo:t,hi:t,sum:t,n:1});return n.map((t=>t.sum/t.n))},C=2.5;function B(t,e,s){const n=Math.min(...t.map((t=>t.x0)),...e.map((t=>t.x))),o=Math.max(...t.map((t=>t.x1)),...e.map((t=>t.x))),l=Math.min(...e.map((t=>t.y0)),...t.map((t=>t.y))),r=Math.max(...e.map((t=>t.y1)),...t.map((t=>t.y))),a=S([...e.map((t=>t.x)),n,o,...t.flatMap((t=>[t.x0,t.x1].filter((s=>((t,s)=>e.some((e=>Math.abs(e.x-t)<=C&&s>=e.y0-C&&s<=e.y1+C)))(s,t.y)))))],C),i=S([...t.map((t=>t.y)),l,r,...e.flatMap((e=>[e.y0,e.y1].filter((s=>((e,s)=>t.some((t=>Math.abs(t.y-e)<=C&&s>=t.x0-C&&s<=t.x1+C)))(s,e.x)))))],C);if(a.length<2||i.length<2)return null;const h=i.length-1,c=a.length-1,f=(t,s,n)=>e.some((e=>Math.abs(e.x-t)<=C&&Math.min(e.y1,n)-Math.max(e.y0,s)>=.6*(n-s))),x=(e,s,n)=>t.some((t=>Math.abs(t.y-e)<=C&&Math.min(t.x1,n)-Math.max(t.x0,s)>=.6*(n-s))),p=(t,e)=>t*c+e,m=Array.from({length:h*c},((t,e)=>e)),u=t=>m[t]===t?t:m[t]=u(m[t]);for(let t=0;t<h;t++)for(let e=0;e<c;e++)e+1<c&&!f(a[e+1],i[t],i[t+1])&&(m[u(p(t,e))]=u(p(t,e+1))),t+1<h&&!x(i[t+1],a[e],a[e+1])&&(m[u(p(t,e))]=u(p(t+1,e)));const g=new Map;for(let t=0;t<h;t++)for(let e=0;e<c;e++){const s=u(p(t,e)),n=g.get(s)||{r0:t,r1:t,c0:e,c1:e,its:[]};n.r0=Math.min(n.r0,t),n.r1=Math.max(n.r1,t),n.c0=Math.min(n.c0,e),n.c1=Math.max(n.c1,e),g.set(s,n)}const b=[];for(const t of s){if(t.used)continue;const e=(t.x0+t.x1)/2,s=(t.top+t.bot)/2;if(e<a[0]-1||e>a[c]+1||s<i[0]-1||s>i[h]+1)continue;let n=0;for(;n<c-1&&e>a[n+1];)n++;let o=0;for(;o<h-1&&s>i[o+1];)o++;g.get(u(p(o,n))).its.push(t),b.push(t)}const M=[...g.values()];for(const t of M)t.x0=a[t.c0],t.x1=a[t.c1+1],t.top=i[t.r0],t.bot=i[t.r1+1];return{Xs:a,Ys:i,R:h,C:c,cells:M,inside:b}}const O=/^[\s(]*[-+−–~∼↑↓▲▼△▽]?[$€£₩]?\s?\d[\d,.\s]*(%|[kKMB]|bn)?\)?\**\s*$|^[-–—]$|^n\/?a$/i;function F(t){const e=[];for(let s=0;s<t.R;s++){const n=t.cells.filter((t=>t.r0===s&&t.r1===s));if(n.length<2)continue;const o=n.map((t=>({c:t,ls:t.its.length?xt(t.its.map((t=>({...t})))):[]}))),l=x(o.flatMap((t=>t.ls.map((t=>t.size)))))||10;{const t=[...new Set(n.map((t=>t.c0)))].sort(((t,e)=>t-e)),s=new Map;for(const t of n)for(const e of t.its)s.set(e,t.c0);const r=n.flatMap((t=>t.its)).filter((t=>null!=t.i)).sort(((t,e)=>t.i-e.i)),a=[];let i=null,h=null;for(const t of r){const e=s.get(t);(!i||e<s.get(h)&&t.top>i.top+.5*l)&&(i={top:t.top,bot:t.bot,cols:new Set},a.push(i)),i.top=Math.min(i.top,t.top),i.bot=Math.max(i.bot,t.bot),i.cols.add(e),h=t}const c=a.length>=2&&t.length>=2&&a.every(((t,e)=>!e||t.top>=a[e-1].bot-.2*l))&&a.filter((t=>t.cols.size>=2)).length>=.5*a.length;if(c){for(let t=1;t<a.length;t++){const s=(a[t-1].bot+a[t].top)/2;for(const t of o)e.push({y:s,x0:t.c.x0,x1:t.c.x1,w:0,virt:!0})}continue}}const r=o.filter((t=>t.ls.length>=2&&t.ls.filter((t=>O.test(t.text))).length>=.8*t.ls.length));let a=r.length?S(r.flatMap((t=>t.ls.map((t=>t.top)))),.45*l):[];if(a.length<2){const t=o.filter((t=>t.ls.length));if(t.length>=2&&t.some((t=>t.ls.length>=3))){const e=Math.max(2,Math.ceil(.6*t.length)),s=S(t.flatMap((t=>t.ls.map((t=>t.top)))),.45*l),n=e=>t.filter((t=>t.ls.some((t=>Math.abs(t.top-e)<=.45*l)))).length,o=s.filter((t=>n(t)>=e)),r=s.filter((t=>n(t)<e)),i=/(의|에|에서|을|를|와|과|및|또는|으로|로서|로써|하고|하며|하여|이나|거나|,)$/,h=t=>{if(t.ls.length<2)return!1;const e=t.c.x1-t.c.x0,s=t.ls.slice(0,-1);let n=0,o=0;for(let e=0;e+1<t.ls.length;e++)!/[.:;!?。)]$/.test(t.ls[e].text)&&/^[a-z]/.test(t.ls[e+1].text)&&n++,i.test(t.ls[e].text)&&o++;return n>=.5*s.length||o>=Math.max(1,.25*s.length)||s.filter((t=>t.x1-t.x0>=.85*e)).length>=.6*s.length},c=t=>o.filter((e=>t.ls.some((t=>Math.abs(t.top-e)<=.45*l)))).length>=.8*o.length,f=o.filter((e=>{const s=t.map((t=>(t.ls.find((t=>Math.abs(t.top-e)<=.45*l))||{}).text)).filter(Boolean);return s.length>=2&&s.every((t=>t===s[0]))})).length;o.length>=4&&f<.5*o.length&&r.length<=.2*s.length&&r.every((t=>n(t)<=1))&&t.filter(h).length<=.2*t.length&&t.every((t=>t.ls.length<2||c(t)))&&(a=o)}}if(!(a.length<2)){{const t=o.filter((t=>t.ls.length>=2)).map((t=>{const e=t.c.its.map((t=>t.i)).filter((t=>null!=t));return e.length?[Math.min(...e),Math.max(...e)]:null})).filter(Boolean).sort(((t,e)=>t[0]-e[0]));if(t.length>=2&&t.every(((e,s)=>!s||e[0]>t[s-1][1])))continue}for(let t=1;t<a.length;t++){const s=a[t]-.25*l;for(const t of o)1!==t.ls.length&&e.push({y:s,x0:t.c.x0,x1:t.c.x1,w:0,virt:!0})}}}return e}function D(t){const e=[],s=e=>(t.Ys[e]+t.Ys[e+1])/2,n=e=>t.Ys[e+1]-t.Ys[e],o=e=>{if(e.r1===e.r0||e.c1!==e.c0||!e.its.length)return null;const o=xt(e.its.map((t=>({...t}))));if(o.length!==e.r1-e.r0+1)return null;const l=o.map((t=>{const o=(t.top+t.bot)/2;let l=-1;for(let t=e.r0;t<=e.r1;t++)Math.abs(o-s(t))<=.25*n(t)&&(l=t);return l}));return l.some((t=>t<0))||new Set(l).size!==l.length?null:o.map(((s,n)=>({r0:l[n],r1:l[n],c0:e.c0,c1:e.c1,its:s.its,x0:e.x0,x1:e.x1,top:t.Ys[l[n]],bot:t.Ys[l[n]+1]})))};for(const e of[...t.cells]){const s=o(e);s&&t.cells.splice(t.cells.indexOf(e),1,...s)}const l=e=>{let s=0;for(;s<t.C-1&&e>t.Xs[s+1];)s++;return s};for(const s of t.cells)if(s.c1!==s.c0||s.r1!==s.r0){if(s.c1>s.c0&&s.its.length){const n=[...s.its].sort(((t,e)=>t.x0-e.x0)),o=[];for(const t of n){const e=o[o.length-1];e&&t.x0-e.x1<=1*Math.max(t.size,6)?(e.its.push(t),e.x1=Math.max(e.x1,t.x1)):o.push({x0:t.x0,x1:t.x1,its:[t]})}const r=o.map((t=>l((t.x0+t.x1)/2)));if(o.length>=2&&new Set(r).size===s.c1-s.c0+1&&r.every(((t,e)=>!e||t>r[e-1]))){o.forEach(((n,o)=>e.push({r0:s.r0,r1:s.r1,c0:r[o],c1:r[o],its:n.its,x0:t.Xs[r[o]],x1:t.Xs[r[o]+1],top:s.top,bot:s.bot})));continue}}e.push(s)}else e.push(s);t.cells=e}function T(t,e){const s=t.Xs[0],n=t.Xs[t.C],o=t.Ys[0],l=t.Ys[t.R],r=[],a=[],i=e.filter((t=>t.x0>=s-2&&t.x1<=n+2&&t.y0>=o-2&&t.y1<=l+2&&t.x1-t.x0<.95*(n-s)+4)),h=i.filter((t=>!i.some((e=>e!==t&&e.x0<=t.x0+.5&&e.x1>=t.x1-.5&&e.y0<=t.y0+.5&&e.y1>=t.y1-.5&&(e.x1-e.x0)*(e.y1-e.y0)>(t.x1-t.x0)*(t.y1-t.y0)+1)))),c=(t,e)=>e.some((e=>Math.abs(e-t)<=C));for(const e of h)for(const s of h)e!==s&&(Math.abs(e.x1-s.x0)<=1&&[e.y0,e.y1,s.y0,s.y1].every((e=>c(e,t.Ys)))&&Math.min(e.y1,s.y1)-Math.max(e.y0,s.y0)>=.8*Math.min(e.y1-e.y0,s.y1-s.y0)&&!c(e.x1,t.Xs)&&r.push({x:(e.x1+s.x0)/2,y0:Math.max(e.y0,s.y0),y1:Math.min(e.y1,s.y1),w:0,virt:!0}),Math.abs(e.y1-s.y0)<=1&&[e.x0,e.x1,s.x0,s.x1].every((e=>c(e,t.Xs)))&&Math.min(e.x1,s.x1)-Math.max(e.x0,s.x0)>=.8*Math.min(e.x1-e.x0,s.x1-s.x0)&&!c(e.y1,t.Ys)&&a.push({y:(e.y1+s.y0)/2,x0:Math.max(e.x0,s.x0),x1:Math.min(e.x1,s.x1),w:0,virt:!0}));for(const e of h)if(!(e.x1-e.x0<15||e.y1-e.y0<8)&&[e.x0,e.x1].every((e=>c(e,t.Xs))))for(const s of[e.y0,e.y1])c(s,t.Ys)&&s>o+C&&s<l-C&&a.push({y:s,x0:e.x0,x1:e.x1,w:0,virt:!0});return{v:r,h:a}}function R(t){const e=[];for(let s=0;s<t.C;s++){const n=t.cells.filter((t=>t.c0===s&&t.c1===s&&t.its.length)),o=(t,e)=>{const s=[];for(const n of t){const t=s[s.length-1];t&&/^[가-힣]$/.test(n.text)&&/(^|\s)[가-힣]$/.test(t.text)&&n.x0-t.x1<=2.5*e?(t.x1=n.x1,t.text+=n.text):s.push({...n})}return s},l=n.map((t=>xt(t.its.map((t=>({...t})))).flatMap((e=>o(Q(e),e.size).map((s=>({x0:s.x0,x1:s.x1,sz:e.size,top:t.top,bot:t.bot}))))))),r=l.filter((t=>t.length>=2));if(r.length<2||r.length<.6*n.length||2===r.length&&r[0].length!==r[1].length)continue;const a=x(l.flat().map((t=>t.sz)))||10,i=r.flat(),h=t.Xs[s],c=t.Xs[s+1],f=[...new Set(i.flatMap((t=>[t.x0,t.x1])))].sort(((t,e)=>t-e)),p=[];for(let t=0;t+1<f.length;t++){const e=(f[t]+f[t+1])/2;f[t+1]-f[t]>=.3*a&&e>h+1&&e<c-1&&!i.some((t=>t.x0<e&&t.x1>e))&&p.push(e)}const m=p.filter((t=>r.filter((e=>e.some((e=>e.x1<=t))&&e.some((e=>e.x0>=t)))).length>=.6*r.length));if(!m.length)continue;const u=n.filter(((t,e)=>l[e].length>=2)),g=Math.min(...u.map((t=>t.top))),b=Math.max(...u.map((t=>t.bot)));for(const t of m)e.push({x:t,y0:g,y1:b,w:0,virt:!0})}return e}function E(t){const e=t.filter((t=>t.h)).map((t=>t.h)).sort(((t,e)=>t.y-e.y)),s=t.filter((t=>t.v)).map((t=>t.v)),n=[];if(e.length<3||s.length<2)return[t];for(let t=0;t<e.length;t++)for(let o=t+1;o<e.length;o++){const l=e[t],r=e[o],a=r.y-l.y;if(a>8)break;if(a<1.2)continue;const i=Math.max(l.x0,r.x0),h=Math.min(l.x1,r.x1);h-i<.8*Math.min(l.x1-l.x0,r.x1-r.x0)||s.some((t=>t.x>i-C&&t.x<h+C&&t.y0<l.y+.5&&t.y1>r.y-.5))||s.some((t=>Math.abs(t.y1-l.y)<=C))&&s.some((t=>Math.abs(t.y0-r.y)<=C))&&(n.some((t=>t.b.y>=l.y-.5&&t.a.y<=r.y+.5))||n.push({a:l,b:r}))}if(!n.length)return[t];const o=t=>{let e=0;for(;e<n.length&&t>(n[e].a.y+n[e].b.y)/2;)e++;return e};n.sort(((t,e)=>t.a.y-e.a.y));const l=Array.from({length:n.length+1},(()=>[]));for(const e of t)l[o(e.h?e.h.y:(e.v.y0+e.v.y1)/2)].push(e);return l.filter((t=>t.length))}function P(t,e,s,n=[]){const o=[...t.map((t=>({h:t}))),...e.map((t=>({v:t})))],l=o.map(((t,e)=>e)),r=t=>l[t]===t?t:l[t]=r(l[t]);for(let t=0;t<o.length;t++)for(let e=t+1;e<o.length;e++){const s=o[t],n=o[e];let a=!1;s.h&&n.v?a=n.v.x>=s.h.x0-C&&n.v.x<=s.h.x1+C&&s.h.y>=n.v.y0-C&&s.h.y<=n.v.y1+C:s.v&&n.h&&(a=s.v.x>=n.h.x0-C&&s.v.x<=n.h.x1+C&&n.h.y>=s.v.y0-C&&n.h.y<=s.v.y1+C),a&&(l[r(t)]=r(e)),s.v&&n.v&&s.v.y1-s.v.y0>=30&&Math.abs(s.v.y0-n.v.y0)<=2*C&&Math.abs(s.v.y1-n.v.y1)<=2*C&&(l[r(t)]=r(e))}const a=new Map;o.forEach(((t,e)=>{const s=r(e);a.has(s)||a.set(s,[]),a.get(s).push(t)}));const i=[],h=[];i.boxes=h;for(const t of[...a.values()].flatMap(E)){const e=t.filter((t=>t.h)).map((t=>t.h)),o=t.filter((t=>t.v)).map((t=>t.v));if(o.length>=2){const t=Math.min(...o.map((t=>t.x))),s=Math.max(...o.map((t=>t.x)));for(const[n,l,r]of[[Math.min(...o.map((t=>t.y0))),t=>t.y0,"top"],[Math.max(...o.map((t=>t.y1))),t=>t.y1,"bot"]])o.filter((t=>Math.abs(l(t)-n)<=C&&t.y1-t.y0>=40)).length>=2&&!e.some((e=>Math.abs(e.y-n)<=C&&e.x0<=t+C&&e.x1>=s-C))&&e.push({y:n,x0:t,x1:s,w:0,virt:!0,open:r})}if(e.length<2||o.length<1)continue;if(1===o.length&&e.filter((t=>t.x0<o[0].x-5&&t.x1>o[0].x+5&&t.y>=o[0].y0-C&&t.y<=o[0].y1+C)).length<2)continue;let l=B(e,o,s);if(!l)continue;if(l.Xs[l.C]-l.Xs[0]<20||l.Ys[l.R]-l.Ys[0]<8)continue;{const t=l.Ys[0],n=l.Xs,r=l.C;if(!o.some((t=>Math.abs(t.x-n[0])<=C||Math.abs(t.x-n[r])<=C))&&o.filter((e=>Math.abs(e.y0-t)<=C)).length>=2&&e.some((e=>Math.abs(e.y-t)<=C))){const a=x(l.inside.map((t=>t.size)))||10,i=s.filter((e=>!e.used&&e.bot<=t+1&&e.bot>t-3*a&&e.x1>n[0]&&e.x0<n[r])),h=t=>{for(let e=0;e<r;e++)if(t.x0>=n[e]-1&&t.x1<=n[e+1]+1)return e;return-1};if(i.length&&i.every((t=>h(t)>=0))){const c=x(i.map((t=>t.size))),f=Math.min(...i.map((t=>t.top))),p=s.some((e=>!e.used&&!i.includes(e)&&e.bot>f&&e.top<t&&e.x1>n[0]&&e.x0<n[r])),m=i.every((t=>{const e=h(t),s=(t.x0+t.x1)/2,o=n[e+1]-n[e];return Math.abs(s-(n[e]+n[e+1])/2)<=.3*o}));if(new Set(i.map(h)).size>=2&&t-f<=3*Math.max(c,a)&&!p&&m&&i.every((t=>Math.abs(t.size-a)<=.15*a))){const a=f-.3*c,i=B([...e,{y:a,x0:n[0],x1:n[r],w:0,virt:!0}],o.map((e=>Math.abs(e.y0-t)<=C?{...e,y0:a}:e)),s);i&&(l=i)}}}}const r=F(l);r.length&&(l=B([...e,...r],o,s)||l);const a=T(l,n);(a.v.length||a.h.length)&&(l=B([...e,...r,...a.h],[...o,...a.v],s)||l);const c=R(l);c.length&&(l=B([...e,...r,...a.h],[...o,...a.v,...c],s)||l),D(l);const f=l.cells.filter((t=>t.its.length)),p=new Set(f.map((t=>t.r0))),m=new Set(f.map((t=>t.c0)));1===l.R&&1===l.C&&1===f.length&&h.push({x0:l.Xs[0],x1:l.Xs[1],top:l.Ys[0],bot:l.Ys[1],its:l.inside});const u=1===f.length&&l.C>=2&&(e.some((t=>t.virt&&"top"===t.open))||f[0].c0>0);if(!u&&(f.length<2||p.size<2&&m.size<2))continue;if(1===l.C&&f.length<=3)continue;const g=l.C>=2&&[0,1,2].some((t=>{const e=l.cells.filter((e=>e.r0===t)),s=e.filter((t=>t.its.length&&!O.test(U(t.its))));return e.length>=2&&s.length>=2&&s.length>=.6*e.length}));if((!(f.length<.3*l.cells.length&&l.cells.length>=6)||g)&&!(f.every((t=>O.test(U(t.its))))&&f.length<.7*l.cells.length)){for(const t of l.inside)t.used=!0;i.push({frag:u,top:l.Ys[0],bot:l.Ys[l.R],x0:l.Xs[0],x1:l.Xs[l.C],cells:l.cells,R:l.R,C:l.C,Xs:l.Xs,openTop:e.some((t=>t.virt&&"top"===t.open)),openBot:e.some((t=>t.virt&&"bot"===t.open))})}}return i}function Z(t,e,s,n=[]){const o=(t,e)=>Math.abs(t-e)<=3;let l=t.filter((t=>{return!(!(o=t.col)||/^#(f[a-f]){3}$/.test(o))&&(t.x1-t.x0)*(t.y1-t.y0)<.4*e*s&&!n.some((e=>t.x0<e.x1-2&&t.x1>e.x0+2&&t.y0<e.bot-2&&t.y1>e.top+2));var o}));const r=new Map;for(const t of l)r.set([t.x0,t.x1,t.y0,t.y1].map((t=>Math.round(t))).join(","),t);l=[...r.values()],l=l.filter((t=>l.filter((e=>((t,e)=>e!==t&&e.x0>=t.x0-1&&e.x1<=t.x1+1&&e.y0>=t.y0-1&&e.y1<=t.y1+1)(t,e))).length<2));const a=l.map(((t,e)=>e)),i=t=>a[t]===t?t:a[t]=i(a[t]);for(let t=0;t<l.length;t++)for(let e=t+1;e<l.length;e++){const s=l[t],n=l[e],r=Math.min(s.x1,n.x1)-Math.max(s.x0,n.x0),h=Math.min(s.y1,n.y1)-Math.max(s.y0,n.y0),c=(o(s.x1,n.x0)||o(n.x1,s.x0))&&h>=.5*Math.min(s.y1-s.y0,n.y1-n.y0),f=(o(s.y1,n.y0)||o(n.y1,s.y0))&&r>=.5*Math.min(s.x1-s.x0,n.x1-n.x0);(c||f)&&(a[i(t)]=i(e))}const h=()=>{const t=new Map;return l.forEach(((e,s)=>{const n=i(s);t.has(n)||t.set(n,[]),t.get(n).push(e)})),[...t.values()]},c=t=>({g:t,x0:Math.min(...t.map((t=>t.x0))),x1:Math.max(...t.map((t=>t.x1))),top:Math.min(...t.map((t=>t.y0))),bot:Math.max(...t.map((t=>t.y1))),Xs:S(t.flatMap((t=>[t.x0,t.x1])),3.5),rh:x(t.map((t=>t.y1-t.y0)))}),f=h().filter((t=>t.length>=2)).map(c).sort(((t,e)=>t.top-e.top));for(let t=0;t+1<f.length;t++){const e=f[t],s=f[t+1],n=s.top-e.bot;o(e.x0,s.x0)&&o(e.x1,s.x1)&&e.Xs.length>=3&&s.Xs.length>=3&&(e.Xs.length<=s.Xs.length?e.Xs.every((t=>s.Xs.some((e=>o(t,e))))):s.Xs.every((t=>e.Xs.some((e=>o(t,e))))))&&n>3&&n<=2.6*Math.max(e.rh,s.rh)&&(a[i(l.indexOf(e.g[0]))]=i(l.indexOf(s.g[0])),f[t+1]=c([...e.g,...s.g]),f[t+1].band=!0)}const p=[];for(const t of h()){if(t.length<4)continue;const e=S(t.flatMap((t=>[t.x0,t.x1])),3.5);let s=S(t.flatMap((t=>[t.y0,t.y1])),3.5);if(e.length<3||s.length<3)continue;const n=(t,e)=>{let s=0;for(let n=1;n<e.length;n++)Math.abs(e[n]-t)<Math.abs(e[s]-t)&&(s=n);return s},o=(e,s)=>t.some((t=>t.y0<s-1&&t.y1>e+1)),l=x(t.map((t=>t.y1-t.y0))),r=[s[0]];for(let t=1;t<s.length;t++){const e=s[t]-s[t-1];if(!o(s[t-1],s[t])&&e>1.6*l){const n=Math.round(e/l);for(let o=1;o<n;o++)r.push(s[t-1]+o*e/n)}r.push(s[t])}s=r;const a=e.length-1,i=s.length-1,h=Array.from({length:i},(()=>new Array(a).fill(null))),c=[];for(const o of[...t].sort(((t,e)=>(t.x1-t.x0)*(t.y1-t.y0)-(e.x1-e.x0)*(e.y1-e.y0)))){const t=n(o.x0,e),l=n(o.x1,e)-1,r=n(o.y0,s),a=n(o.y1,s)-1;if(l<t||a<r)continue;let i=!0;for(let e=r;e<=a&&i;e++)for(let s=t;s<=l;s++)if(h[e][s]){i=!1;break}if(!i)continue;const f={r0:r,r1:a,c0:t,c1:l,its:[],col:o.col};c.push(f);for(let e=r;e<=a;e++)for(let s=t;s<=l;s++)h[e][s]=f}for(let t=0;t<i;t++)for(let e=0;e<a;e++)if(!h[t][e]){const s={r0:t,r1:t,c0:e,c1:e,its:[],hole:!0};c.push(s),h[t][e]=s}for(const t of c)t.x0=e[t.c0],t.x1=e[t.c1+1],t.top=s[t.r0],t.bot=s[t.r1+1];p.push({Xs:e,Ys:s,R:i,C:a,cells:c,own:h,n:t.length})}return p}function Y(t,e,s,n,o,l){const r=[];for(const a of Z(t,s,n,o)){const t=a.Xs[0],s=a.Xs[a.C],n=a.Ys[0],o=a.Ys[a.R],i=[];let h=0;for(const r of e){if(r.used)continue;const e=(r.x0+r.x1)/2,c=(r.top+r.bot)/2;if(e<t||e>s||c<n||c>o)continue;(r.x0<t-2*l||r.x1>s+2*l)&&h++;let f=0;for(;f<a.C-1&&e>a.Xs[f+1];)f++;let x=0;for(;x<a.R-1&&c>a.Ys[x+1];)x++;a.own[x][f].its.push(r),i.push(r)}const c=a.cells.filter((t=>t.its.length)),f=new Set;for(let t=0;t<a.R;t++)new Set(a.own[t].filter((t=>t.its.length))).size>=2&&f.add(t);let x=0,p=0;for(let t=0;t<a.R;t++)new Set(a.own[t].filter((t=>!t.hole))).size>=2&&x++;for(let t=0;t<a.C;t++)new Set(a.own.map((e=>e[t])).filter((t=>!t.hole))).size>=2&&p++;const m={size:x>=2||x>=1&&p>=1?2:0},u=c.map((t=>U(t.its)));if(h||m.size<2||c.length<.4*a.cells.length||f.size<2||u.every((t=>O.test(t))))for(const t of a.cells)t.its=[];else{for(const t of i)t.used=!0;r.push({top:n,bot:o,x0:t,x1:s,cells:a.cells,R:a.R,C:a.C,src:"fill",Xs:a.Xs})}}return r}const I=/^[→⇒➔➜➝➞➡▶►▷▸⇨⟶⇢➨➙➛➤➧➭➮➯➱⬅←⇐◀◁]+$/;function U(t,e=null){const o=xt(t.map((t=>({...t})))),l=o.length?Math.max(...o.map((t=>t.x1))):0;if(!e||o.length<2)return s(o.map(((t,e)=>(e?W(o[e-1],t,l,!0):"")+t.text)).join("").replace(/\s+/g," ").trim());const r=e.x1-e.x0-10.2,a=t=>{let e=0;for(let s=0;s<t.its.length;s++){const n=t.its[s],o=n.s.indexOf(" ");if(o>0)return e+(n.x1-n.x0)*o/n.s.length;e=n.x1-t.x0;const l=t.its[s+1];if(!l||"real"===n.sp||l.x0-n.x1>.18*t.size)return e}return e},i=[[o[0]]];for(let t=1;t<o.length;t++){const e=o[t-1],s=o[t],n=r-(e.x1-e.x0);n>=a(s)+.25*e.size?i.push([s]):(i[i.length-1].push(s),s.wsp=n>=.9*e.size)}return i.map((t=>s(n(t.map(((e,s)=>(s?e.wsp?" ":W(t[s-1],e,t[s-1].x1,!0):"")+(e.stext||e.text))).join("").replace(/\s+/g," ").trim(),{cell:!0})))).filter(Boolean).join("\n")}const V=/[을를은는이가의에와과도로서고며여게지다만할된한될른및등터께라면야요월일]$/,G=/^[는를였었았겠됩됨며]/,_=process.env.PDFMD_JOINMARK;let L=null;const N=t=>/[0-9]/.test(t)?"0":/[A-Za-z]/.test(t)?"a":t;function q(t){const e=[];let s="",n=null;for(const o of[...t.its].sort(((t,e)=>t.x0-e.x0))){if(n){const t=o.x0-n.x1,l=Math.min(o.size,n.size);t>l?(e.push(s),s=""):/\s$/.test(s)||/^\s/.test(o.s)||!et(n,t,l,o)||(s+=" ")}s+=o.s,n=o}return e.push(s),e}function H(t,e){const s=e=>t.set(e,(t.get(e)||0)+1),n=e.replace(/\s+/g," ").trim(),o=Array.from(n,N);{const t=n.split(" ");if(t.length>=3&&t.every((t=>1===Array.from(t).length)))return}for(let t=0;t+1<o.length;t++)" "!==o[t]&&" "!==o[t+1]?s("J"+o[t]+o[t+1]):" "!==o[t]&&t+2<o.length&&" "!==o[t+2]&&s("P"+o[t]+o[t+2]);for(const t of n.matchAll(/[가-힣]+/g)){const e=t[0],o=t.index,l=o+e.length;for(let t=0;t+3<=e.length;t++)s("G"+e.slice(t,t+3));for(let t=0;t+1<e.length;t++)s("a"+e[t]),s("b"+e[t+1]);for(let t=0;t+2<e.length;t++)s("n"+e.slice(t,t+2)),s("m"+e.slice(t+1,t+3));o>0&&" "===n[o-1]&&(s("S"+e[0]),e.length>=2&&s("S"+e.slice(0,2))),l<n.length&&" "===n[l]&&(s("E"+e[e.length-1]),e.length>=2&&s("E"+e.slice(-2)))}}function J(t,e,s,n){const o=e.slice(-1),l=s.charAt(0),r=/[가-힣]/.test(o),a=/[가-힣]/.test(l),i=e=>t.get(e)||0;if(r&&a){if(G.test(s))return"";const t=e.match(/[가-힣]+$/)[0],r=s.match(/^[가-힣]+/)[0],a=i("J"+o+l),h=i("P"+o+l),c=(r.length>=2?i("G"+t.slice(-1)+r.slice(0,2)):0)+(t.length>=2?i("G"+t.slice(-2)+r[0]):0),f=!n&&(t.length>=2||r.length>=2)&&i("S"+r.slice(0,2))>0&&i("E"+t.slice(-2))>0,x=c>0&&!f||a>h,p=h>a||f&&0===c;if(n&&x&&!p&&1===e.length&&1===s.length&&V.test(e)&&a<=2)return null;if(x!==p)return x?"":" ";if(x)return c>0&&!f?"":h>=a?" ":"";if(n)return null;const m=i("E"+o),u=i("a"+o),g=i("S"+l),b=i("b"+l);return m+u+g+b>=8&&(m+.3)/(m+u+1)>=.35&&(g+.3)/(g+b+1)>=.35||r.length>=2&&i("S"+r.slice(0,2))>0&&!i("m"+r.slice(0,2))||t.length>=2&&i("E"+t.slice(-2))>0&&!i("n"+t.slice(-2))?" ":null}if("·ㆍ‧".includes(o)||!n&&r&&"ㆍ‧".includes(l))return"";if(n)return null;if(r&&/[0-9]/.test(l))return"제"===o?"":" ";const h=i("J"+N(o)+N(l)),c=i("P"+N(o)+N(l));return(a&&!r&&!/[0-9]/.test(o)||r&&!a&&!/[0-9]/.test(l)&&"("!==l)&&c!==h?c>h?" ":"":null}function W(t,e,s,n=!1){if(t&&L&&!_&&t.text&&e.text&&t.x1>=s-1*t.size){const s=J(L,t.text,e.text,n);if(null!==s)return s}if(!t||!/[가-힣0-9]$/.test(t.text)||!/^[가-힣0-9]/.test(e.text)||!/[가-힣]$/.test(t.text)&&!/^[가-힣]/.test(e.text))return" ";const o=t.x1>=s-1*t.size;return _?o?"⁣":"⁤":!o||!G.test(e.text)&&V.test(t.text)?" ":""}function K(t){const e=new Set,s=new Set;for(const n of t.cells)e.add(n.r0),e.add(n.r1+1),s.add(n.c0),s.add(n.c1+1);const n=[...e].sort(((t,e)=>t-e)),o=[...s].sort(((t,e)=>t-e)),l=new Map(n.map(((t,e)=>[t,e]))),r=new Map(o.map(((t,e)=>[t,e]))),a="clip"===t.src,i=t.cells.map((t=>({r:l.get(t.r0),c:r.get(t.c0),rs:l.get(t.r1+1)-l.get(t.r0),cs:r.get(t.c1+1)-r.get(t.c0),text:U(t.its,a?t:null)}))),h=n.length-1,c=new Array(h).fill(!i.some((t=>t.rs>1||t.cs>1)));for(const t of i)if(t.text)for(let e=t.r;e<t.r+t.rs;e++)c[e]=!1;if(c.some(Boolean)&&!c.every(Boolean))for(const t of i){let e=0;for(let s=t.r;s<t.r+t.rs;s++)c[s]&&e++;e<t.rs&&(t.rs-=e)}const f=[];for(const t of i)c[t.r]&&!c.every(Boolean)||(f[t.r]||=[]).push(t);if(a&&!i.some((t=>t.rs>1||t.cs>1))){const t=f.filter(Boolean).map((t=>t.sort(((t,e)=>t.c-e.c)))),e=Math.max(...t.map((t=>t.length))),s=t=>String(t||"").split("\n").map((t=>t.replace(/\s+/g," ").replace(/\|/g,"|").trim())).join("<br>"),n=t=>"| "+Array.from({length:e},((e,n)=>s(t[n]&&t[n].text))).join(" | ")+" |";if(t.length)return[n(t[0]),"|"+" --- |".repeat(e),...t.slice(1).map(n)].join("\n")}return"<table>"+f.map((t=>t?"<tr>"+t.sort(((t,e)=>t.c-e.c)).map((t=>`<td${t.rs>1?` rowspan="${t.rs}"`:""}${t.cs>1?` colspan="${t.cs}"`:""}>${u(t.text).replace(/\n/g,"<br>").replace(/&lt;(\/?su[bp])&gt;/g,"<$1>")}</td>`)).join("")+"</tr>":"")).join("")+"</table>"}function Q(t){const e=[];let s=null;for(const n of t.its){const o=s&&/[\[[((]\s*$/.test(s.its[s.its.length-1].s)&&/^\s*[\]]))]/.test(n.s);s&&!o&&n.x0-s.x1>Math.max(.8*t.size,5)&&(e.push(s),s=null),s||(s={x0:n.x0,x1:n.x1,its:[]}),s.its.push(n),s.x1=Math.max(s.x1,n.x1)}s&&e.push(s);for(const s of e)s.text=tt(s.its,t.size);return e}const tt=(t,e)=>{let s="",n=null;for(const o of t)n&&!/\s$/.test(s)&&et(n,o.x0-n.x1,e,o)&&(s+=" "),s+=o.s,n=o;return s.replace(/\s+/g," ").trim()},et=(t,e,s,n=null)=>"real"===t.sp||e>(!(/[(\[「『〈《]$/.test(t.s)||n&&/^[)\]」』〉》]/.test(n.s))||n&&/[(\[]$/.test(t.s)&&/^[)\]]/.test(n.s)?.18:.5)*s&&("fake"!==t.sp||e>.4*s),st=/^([•●▪■◦○◆►‣⁃∙·\-–—*\[[□☐]|\(?\d{1,2}[.)]|\(?[a-zA-Z][.)]|\([ivx]+\))$/;function nt(t,e,s=!1){const n=t.filter((t=>t.cs.length>=2));if(s&&1===n.length&&t.length>=3){const s=n[0].cs.map((t=>t.x0));if(t.every((t=>t===n[0]||Math.abs(t.cs[0].x0-s[0])<=.8*e)))return s}if(n.length<2)return null;const o=ot(n,e);let l=S(n.flatMap((t=>t.cs.map((t=>t.x0)))),.7*e).filter((t=>(t=>n.filter((s=>s.cs.some((s=>Math.abs(s.x0-t)<=.7*e)))).length)(t)>=Math.max(2,.34*n.length)));const r=S(n.flatMap((t=>t.cs.slice(1).map((t=>t.x1)))),.7*e).filter((t=>n.filter((s=>s.cs.slice(1).some((s=>Math.abs(s.x1-t)<=.7*e)))).length>=Math.max(2,.4*n.length)));for(const t of r){const s=n.flatMap((s=>s.cs.slice(1).filter((s=>Math.abs(s.x1-t)<=.7*e)))),o=Math.min(...s.map((t=>t.x0)));l.some((s=>Math.abs(s-o)<=2*e||s<t&&s>o))||l.push(o)}return l=[...new Set(l)].sort(((t,e)=>t-e)),o&&o.length>l.length?o:l.length>=2?l:null}function ot(t,e){const s=Math.floor(.15*t.length),n=[...new Set(t.flatMap((t=>t.cs.flatMap((t=>[t.x0,t.x1])))))].sort(((t,e)=>t-e)),o=[];let l=null;for(let r=0;r+1<n.length;r++){const a=(n[r]+n[r+1])/2;t.filter((t=>t.cs.some((t=>t.x0<a&&t.x1>a)))).length<=s||(l&&n[r]-l.x1<.3*e?l.x1=n[r+1]:o.push(l={x0:n[r],x1:n[r+1]}))}if(o.length<2)return null;const r=Math.max(2,Math.ceil(.5*t.length));return o.every((e=>t.filter((t=>t.cs.some((t=>t.x0<e.x1&&t.x1>e.x0)))).length>=r))?o.map((t=>t.x0)):null}function lt(t,e,s=[],n=!1,o=[],l=null){const r=t.map((t=>({l:t,cs:Q(t)}))),a=l||nt(r,e,n);if(!a)return m(1);const i=r.findIndex((t=>t.cs.length>=2&&t.cs.filter((t=>O.test(t.text))).length>=.5*t.cs.length)),h=t=>i<=0?1:t>=i?100:t===i-1?10:1,c=a.length,f=function(t,e,s,n){const o=[];for(let l=1;l<t.length;l++){const r=t[l-1]+.5*s,a=t[l],i=t[l]-.7*s;if(a-r<.3*s){o.push(i);continue}const h=[...new Set([r,a,...e.flatMap((t=>[t.x0,t.x1])).filter((t=>t>r&&t<a))])].sort(((t,e)=>t-e)),c=[];for(let t=0;t+1<h.length;t++){const s=(h[t]+h[t+1])/2,n=e.filter((t=>t.x0<s&&t.x1>s));c.push({a:h[t],b:h[t+1],n:n.length,key:n.reduce(((t,e)=>t+(e.w||1)),0)})}const f=Math.min(...c.map((t=>t.key)));if(Math.min(...c.filter((t=>t.key===f)).map((t=>t.n)))>Math.max(1,.25*n)){o.push(i);continue}const x=[];let p=null;for(const t of c)t.key===f?p?p.b=t.b:x.push(p={a:t.a,b:t.b}):p=null;const m=x.sort(((t,e)=>e.b-e.a-(t.b-t.a)))[0];o.push(m&&m.b-m.a>=.25*s?(m.a+m.b)/2:i)}return o}(a,r.flatMap(((t,e)=>t.l.its.map((t=>({x0:t.x0,x1:t.x1,w:h(e)}))))),e,r.length),p=t=>{let e=0;for(;e<c-1&&t>=f[e];)e++;return e},u=r.map((t=>{const s=Array.from({length:c},(()=>({its:[],span:1})));for(const n of t.l.its){const t=n.x1-n.x0,o=p(n.x0+Math.min(.3*e,t/2));s[o].its.push(n);const l=p(n.x1-Math.min(.5*e,t/2));l>o&&t>2*e&&(s[o].span=Math.max(s[o].span,l-o+1))}return{top:t.l.top,bot:t.l.bot,cells:s.map((e=>({t:tt(e.its,t.l.size),span:e.span,x0:e.its.length?Math.min(...e.its.map((t=>t.x0))):0,x1:e.its.length?Math.max(...e.its.map((t=>t.x1))):0})))}}));"2"===process.env.PDFMD_DEBUG&&console.error("[pdfmd] 표 후보 ds="+i,a.map((t=>t.toFixed(0))).join(","),"S",f.map((t=>t.toFixed(0))).join(","),u.map((t=>t.cells.map((t=>t.t.slice(0,14)+(t.span>1?"{"+t.span+"}":""))).join(" | "))));const g=u.flatMap((t=>t.cells.filter((t=>t.t)))),b=u.filter((t=>t.cells.filter((t=>t.t)).length>=2)).length;if(!n&&(b<2||u.length<2))return m(2);if(n&&(u.length<2||b<2&&!(u.length>=3&&g.every((t=>t.t.length<=60)))))return m(3);const M=u.map((t=>t.cells[0].t)).filter(Boolean);if(M.length>=2&&M.filter((t=>st.test(t))).length>=.8*M.length)return m(4);if(!n&&g.reduce(((t,e)=>t+e.t.length),0)/g.length>28&&c<3)return m(5);if(!n){const t=t=>x(u.map((e=>e.cells[t].t.length)).filter(Boolean));if(2===c&&t(0)>30&&t(1)>30)return m(6);const e=u.some((t=>t.cells.filter((t=>t.t&&!O.test(t.t))).length>=2)),s=u.filter((t=>t.cells[0].t&&!O.test(t.cells[0].t))).length>=.5*u.length;if(!e&&!s)return m(7);if(g.filter((t=>/^[a-z]/.test(t.t))).length>=.5*g.length)return m(8)}{let t=0;for(let e=0;e<c;e++){const s=u.map((t=>t.cells[e])).filter((t=>t.t&&t.t.length>25));if(s.length<3)continue;const n=Math.max(...s.map((t=>t.x1-t.x0)));s.filter((t=>t.x1-t.x0>=.85*n)).length>=.6*s.length&&t++}if(t>=2)return m(9);if(g.filter((t=>/[a-z]-$/.test(t.t))).length>=2)return m(10);const e=Array.from({length:c},((t,e)=>{const s=u.map((t=>t.cells[e].t)).filter(Boolean);return s.length>=2&&s.filter((t=>O.test(t))).length>=.6*s.length})),s=e.some(Boolean)?Math.max(0,u.findIndex((t=>e.some(((e,s)=>e&&t.cells[s].t&&O.test(t.cells[s].t)))))):0;for(let t=0;t<c;t++){const e=u.map((e=>e.cells[t].t));let o=0,l=0;for(let t=s;t+1<e.length;t++)e[t]&&e[t+1]&&e[t].length>=20&&(o++,/[a-z,;'’-]$/.test(e[t])&&/^[a-z(“"‘]/.test(e[t+1])&&l++);if(o>=3&&l>=.4*o||o>=2&&l>=.5*o&&!n)return m(11)}}if(!n&&g.length<.6*u.length*c)return m(12);if(g.length<(n?.5:.4)*u.length*c)return m(13);if(g.filter((t=>/[∂√∑∫≤≥±×÷∣∇∞]|\b(d|dt|dx)\b\s*$/.test(t.t))).length>=2)return m(14);if(g.some((t=>/^(figure|fig\.|chart|photo|image|그림)\s*\d/i.test(t.t)||/(\b(19|20)\d\d\b.*){3}/.test(t.t)||/\((left|right) axis\)/i.test(t.t))))return m(15);if(n&&!u.some((t=>t.cells.filter((t=>t.t&&!O.test(t.t))).length>=2))&&u.filter((t=>t.cells[0].t&&!O.test(t.cells[0].t))).length<.5*u.length)return m(16);const d=u.map((t=>t.cells[c-1].t)).filter(Boolean);if(2===c&&d.length>=2&&d.every((t=>/^([ivxlc]+|\d{1,4})$/i.test(t)))){const t=d.filter((t=>/^\d+$/.test(t))).map(Number);if(t.every(((e,s)=>!s||e>=t[s-1])))return m(17)}const y=Array.from({length:c},((t,e)=>{const s=u.map((t=>t.cells[e].t)).filter(Boolean);return s.length>=2&&s.filter((t=>O.test(t))).length>=.6*s.length})),z=t=>y.some(((e,s)=>e&&t.cells[s].t&&O.test(t.cells[s].t))),w=u.findIndex(z),v=[],$=w>0?w:i;$>=2&&function(t,e,s,n,o){if(e<2)return;const l=Array.from({length:s},(()=>[1/0,-1/0]));for(let s=e-1;s<t.length;s++)t[s].cells.forEach(((t,e)=>{t.t&&1===t.span&&(l[e][0]=Math.min(l[e][0],t.x0),l[e][1]=Math.max(l[e][1],t.x1))}));if(l.some((t=>t[0]===1/0)))return;const r=t=>(l[t][0]+l[t][1])/2;for(let a=0;a<e-1;a++){const e=t[a],i=t[a+1],h=e.cells.map(((t,e)=>({c:t,k:e}))).filter((t=>t.c.t)),c=[];for(const t of h){const{c:a,k:f}=t,x=(a.x0+a.x1)/2;let p=null;const m=(e,s)=>!h.some((n=>n!==t&&n.k>=e&&n.k<=s))&&!c.some((([t,n])=>t<=s&&n>=e)),u=o.find((t=>t.y>e.bot-1&&t.y<i.top+1&&t.x0<=x&&t.x1>=x&&t.x1-t.x0<.95*(l[s-1][1]-l[0][0])));if(u){const t=l.map(((t,e)=>e)).filter((t=>r(t)>=u.x0-2&&r(t)<=u.x1+2));t.length>=2&&t[0]<=f&&t[t.length-1]>=f&&m(t[0],t[t.length-1])&&(p=[t[0],t[t.length-1]])}if(!p)for(let t=0;t<=f;t++)for(let e=Math.max(f,t+1);e<s;e++)Math.abs((l[t][0]+l[e][1])/2-x)>.6*n||a.x0<l[t][0]-n||a.x1>l[e][1]+n||!m(t,e)||(!p||e-t>p[1]-p[0])&&(p=[t,e]);if(!p){c.push([f,f+a.span-1]);continue}const[g,b]=p;c.push(p);for(let t=g;t<=b;t++)t!==f&&(e.cells[t]={t:"",span:1,x0:0,x1:0});e.cells[f]={t:"",span:1,x0:0,x1:0},e.cells[g]={...a,span:b-g+1}}}}(u,$,c,e,o);const k=(t,e)=>{e.cells.forEach(((e,s)=>{if(e.t){const n=t.cells[s];n.t?(n.x0=Math.min(n.x0,e.x0),n.x1=Math.max(n.x1,e.x1)):(n.x0=e.x0,n.x1=e.x1),n.t=(n.t?n.t+" ":"")+e.t,n.span=Math.max(n.span,e.span)}})),t.bot=e.bot},A=(t,e)=>s.some((s=>s>t.bot-1&&s<e.top+1)),j=(()=>{const t=[];for(let e=Math.max(0,w);e+1<u.length;e++)z(u[e])&&z(u[e+1])&&t.push(u[e+1].top-u[e].top);return t.length>=2?x(t):0})();for(let t=0;t<u.length;t++){const s=u[t],n=v[v.length-1];if(!n){v.push(s);continue}const o=s.top-n.bot<.9*e&&!A(n,s);let l;if(y.some(Boolean)&&w>=0)if(t<w){const o=t=>t.cells.filter((t=>t.t)).length<c&&t.cells.some((t=>t.span>1));if(l=!A(n,s)&&s.top-n.bot<1.6*e&&!o(s)&&!o(n)&&!(j&&u[t].top-u[t-1].top>=.9*j),l){k(n,s),n.cells.forEach((t=>{t.span=1}));continue}}else l=!z(s)&&o;else l=o&&!s.cells[0].t;l?k(n,s):v.push(s)}return v.length<2?m(18):($>=2&&function(t,e,s){if(e<2||!t.slice(0,e).some((t=>t.cells.some((t=>t.t&&t.span>1)))))return;const n=(e,s)=>t[e].cells.some(((t,e)=>e<s&&t.t&&e+t.span-1>=s));for(let o=0;o<s;o++){const s=[];let l=!0;for(let r=0;r<e;r++){if(n(r,o)){l=!1;break}if(t[r].cells[o].t)s.push(r);else if(t[r].cells[o].span>1){l=!1;break}}if(!l||1!==s.length||t[s[0]].cells[o].span>1)continue;const r=t[s[0]].cells[o];for(let s=0;s<e;s++)t[s].cells[o]={t:"",span:1,skip:!0};t[0].cells[o]={...r,rs:e}}}(v,v.findIndex((t=>t.top>=u[$].top-.5)),c),{rows:v,C:c})}function rt(t){return"<table>"+t.rows.map((e=>{let n="<tr>",o=0;for(;o<t.C;){const l=e.cells[o],r=Math.min(l.span,t.C-o);l.skip||(n+=`<td${l.rs>1?` rowspan="${l.rs}"`:""}${r>1?` colspan="${r}"`:""}>${u(s(l.t))}</td>`),o+=r}return n+"</tr>"})).join("")+"</table>"}function at(t,e,s,n=[],o=!1){const l=t.filter((t=>t.x1-t.x0>=4*s)).sort(((t,e)=>t.y-e.y||t.x0-e.x0)),r=[];for(const t of l){const e=r[r.length-1];e&&Math.abs(e.y-t.y)<=2&&t.x0-e.x1<=12*s?(e.x0=Math.min(e.x0,t.x0),e.x1=Math.max(e.x1,t.x1)):r.push({...t})}for(let t=r.length-1;t>=0;t--)r[t].x1-r[t].x0<8*s&&r.splice(t,1);const a=new Set,i=[],h=(t,n,o,l)=>e.filter((e=>!e.done&&(e.top+e.bot)/2>t&&(e.top+e.bot)/2<n&&e.x0>=o-2*s&&e.x1<=l+2*s));for(let l=0;l<r.length;l++){if(a.has(l))continue;const c=[l];for(let t=l+1;t<r.length;t++){if(a.has(t))continue;const e=r[c[c.length-1]],n=r[t];Math.min(e.x1,n.x1)-Math.max(e.x0,n.x0)>=.8*Math.min(e.x1-e.x0,n.x1-n.x0)&&n.y-e.y<=40*s&&c.push(t)}const f=c.map((t=>r[t])),x=Math.min(...f.map((t=>t.x0))),p=Math.max(...f.map((t=>t.x1)));if(f.length>=4){const t=f.slice(1).map(((t,e)=>t.y-f[e].y));let e=1,s=1;for(let n=1;n<t.length;n++)e=t[n]>0&&Math.abs(t[n]-t[n-1])<=.08*t[n-1]?e+1:1,s=Math.max(s,e);if(s>=3){c.forEach((t=>a.add(t)));continue}}let m=[],u=null;for(let t=0;t+1<f.length;t++){const e=h(f[t].y,f[t+1].y,x,p);e.length&&!n.some((e=>e.top<f[t+1].y-1&&e.bot>f[t].y+1&&e.x0<p&&e.x1>x))&&(lt(e,s,[],!0)||e.every((t=>Q(t).length>=2)))?u?u.b=t+1:(u={a:t,b:t+1},m.push(u)):u=null}for(const n of m){for(;n.a>0;){const t=h(f[n.a-1].y,f[n.a].y,x,p);if(!t.length||t.length>4||!t.every((t=>t.text.length<=60&&!/^(table|figure|fig\.|tab\.|표|그림)\s*\d/i.test(t.text))))break;n.a--}let l=f[n.a].y,r=f[n.b].y,m=h(l,r,x,p);if(m.length<2)continue;const u=nt(m.map((t=>({l:t,cs:Q(t)}))),s);if(u){const t=e.filter((t=>!t.done&&t.top>r-1&&t.x0>=x-2*s&&t.x1<=p+2*s)).sort(((t,e)=>t.top-e.top));let n=r;for(const e of t){const t=Q(e);if(e.top-n>2.2*s||t.length<2||!t.every((t=>u.some((e=>Math.abs(t.x0-e)<=.9*s))&&t.text.length<=40||O.test(t.text))))break;m.push(e),n=e.bot}r=Math.max(r,n)}const g=lt(m,s,f.slice(n.a,n.b+1).map((t=>t.y)),!0,t.filter((t=>t.y>=l-1&&t.y<=r+1&&t.x1>x&&t.x0<p)));if(g&&!(o&&g.rows.length>n.b-n.a)){for(let t=n.a;t<=n.b;t++)a.add(c[t]);for(const t of m)t.done=!0;i.push({kind:"table",html:rt(g),top:l,bot:r,x0:x,x1:p,src:"rule"})}}}return i}function it(t){if(t.length<6)return[];const e=Math.min(...t.map((t=>t.x0))),s=Math.max(...t.map((t=>t.x1))),n=Math.ceil(s-e)+1,o=new Float64Array(n);for(const s of t)for(let t=Math.max(0,Math.floor(s.x0-e));t<=Math.min(n-1,Math.ceil(s.x1-e));t++)o[t]+=s.bot-s.top;const l=[...o].filter((t=>t>0)).sort(((t,e)=>t-e)),r=l[Math.floor(.6*l.length)]||0,a=o.reduce(((t,e)=>t+e),0),i=[];for(let t=Math.floor(.2*n);t<Math.ceil(.8*n);)if(o[t]<=.2*r){let s=t;for(;s<n&&o[s]<=.2*r;)s++;const l=o.slice(0,t).reduce(((t,e)=>t+e),0);s-t>=6&&l>=.25*a&&a-l>=.25*a&&i.push(e+(t+s)/2),t=s}else t++;return i}function ht(t,e){if(!e.length)return t;const s=[];for(const n of t){const t=e.length+1,o=Array.from({length:t},(()=>[]));for(const t of n.its){let s=0;for(;s<e.length&&(t.x0+t.x1)/2>e[s];)s++;o[s].push(t)}const l=o.filter((t=>t.length));if(l.length<=1)s.push(n);else for(const t of l)s.push({...n,its:t,x0:Math.min(...t.map((t=>t.x0))),x1:Math.max(...t.map((t=>t.x1))),text:tt(t,n.size),parent:n})}return s}const ct=/^[\s(*~∼±+−–-]*\d[\d,.\s]*\s*[A-Za-z%μµ°]{0,4}\.?\)?$/;function ft(t,e){const s=t.map((t=>Q(t)));if(s[0].length<3||s[0].length!==s[1].length)return!1;const n=ot(t.map(((t,e)=>({l:t,cs:s[e]}))),e);if(!n||n.length!==s[0].length)return!1;const o=s.map((t=>t.filter((t=>ct.test(t.text))).length/t.length));return o[0]<=.25&&o[1]>=.75||o[1]<=.25&&o[0]>=.75&&!1}function xt(t){const e=t.sort(((t,e)=>t.base-e.base||t.x0-e.x0)),s=[];for(const t of e){let e=null;for(let n=s.length-1;n>=0&&n>=s.length-6;n--){const o=s[n],l=Math.min(o.bot,t.bot)-Math.max(o.top,t.top),r=Math.min(o.bot-o.top,t.bot-t.top),a=Math.max(o.size,t.size)/Math.min(o.size,t.size);if(!!o.its[0].rot==!!t.rot&&(Math.abs(o.base-t.base)<=.3*Math.min(o.size,t.size)||a<1.8&&l>.55*r&&!o.its.some((e=>e.x0<t.x1-1&&t.x0<e.x1-1)))){e=o;break}}e?(e.its.push(t),e.top=Math.min(e.top,t.top),e.bot=Math.max(e.bot,t.bot),(t.size>1.05*e.size||t.s.length>2)&&(e.base=t.size>=e.size?t.base:e.base,e.size=Math.max(e.size,t.size))):s.push({base:t.base,size:t.size,top:t.top,bot:t.bot,its:[t]})}for(const t of s){if(!t.its.length||!t.its.every((t=>t.s.trim().length<=3)))continue;const e=s.find((e=>e!==t&&e.its.length&&t.size<.8*e.size&&t.bot>e.top+.1*e.size&&t.top<e.top+.3*e.size&&t.its.every((t=>e.its.some((s=>Math.abs(t.x0-s.x1)<=.6*e.size||Math.abs(s.x0-t.x1)<=.6*e.size))))));e&&(e.its.push(...t.its),e.top=Math.min(e.top,t.top),t.its=[])}for(const t of s){if(!t.its.length){t.text="";continue}t.its.sort(((t,e)=>t.x0-e.x0));let e="",s="",n=null,o=!1,r="",a=!1;for(const i of t.its){const h=i.size<.8*t.size?i.base<t.base-.15*t.size?"p":i.base>t.base+.1*t.size?"d":"":"";if(!r||h===r&&!!i.bold===o||(s+=l[r+"1"],r=""),o&&!i.bold&&(s+=l.b1,o=!1),null!=n){const o=i.x0-n.x1,l=i.size<.8*t.size&&i.base<t.base-.15*t.size,r=/[.·…]$/.test(e)&&/^[.·…]/.test(i.s);l||r||/\s$/.test(e)||/^\s/.test(i.s)||!et(n,o,Math.min(i.size,n.size),i)||(e+=" ",s+=" ")}!o&&i.bold&&(s+=l.b0,o=!0),h&&!r&&(s+=l[h+"0"],r=h),e+=i.s,s+=i.s,n=i,(h||i.bold)&&(a=!0)}r&&(s+=l[r+"1"]),o&&(s+=l.b1),t.text=e.replace(/\s+/g," ").trim(),t.stext=a?s.replace(/\s+/g," ").trim():null,t.x0=t.its[0].x0,t.x1=Math.max(...t.its.map((t=>t.x1))),t.its.reduce(((t,e)=>t+e.s.length),0),t.bold=t.its.filter((t=>t.bold)).reduce(((t,e)=>t+e.s.replace(/\s/g,"").length),0)>=.95*t.its.reduce(((t,e)=>t+e.s.replace(/\s/g,"").length),0);const i={};for(const e of t.its){const t=Math.round(2*e.size)/2;i[t]=(i[t]||0)+e.s.length}t.fsize=+Object.entries(i).sort(((t,e)=>e[1]-t[1]))[0][0]}return s.filter((t=>t.text)).sort(((t,e)=>t.top-e.top||t.x0-e.x0))}function pt(t,e=[]){const s=[];for(const n of t){let t=null;for(const o of n.its)t&&(o.x0-t.x1>Math.max(.8*n.size,5)||e.some((e=>t.x1<=e+1&&o.x0>=e-1)))&&(s.push(t),t=null),t||(t={its:[],x0:o.x0,x1:o.x1,top:o.top,bot:o.bot}),t.its.push(o),t.x1=Math.max(t.x1,o.x1),t.top=Math.min(t.top,o.top),t.bot=Math.max(t.bot,o.bot);t&&s.push(t)}return s}function mt(t,e,s=.45*e,n=[],o=!1){if(t.length<=1)return[t];const l=t=>{const e=[...t].sort(((t,e)=>t.top-e.top)),n=[];let o=e[0].bot;const l=Math.max(s,1.35*(t=>{const e=[...t].sort(((t,e)=>t.top-e.top)),s=[];for(let t=0;t<e.length;t++){const n=e[t],o=n.bot-n.top;for(let l=t+1;l<e.length&&l<t+12;l++){const t=e[l],r=t.top-n.bot;if(Math.min(n.x1,t.x1)-Math.max(n.x0,t.x0)>.5*Math.min(n.x1-n.x0,t.x1-t.x0)&&r>-.5&&r<2.5*o){s.push(Math.max(0,r));break}}}return s.length>=3?x(s):0})(t));for(let t=1;t<e.length;t++)e[t].top-o>=l&&n.push({at:(o+e[t].top)/2,w:e[t].top-o}),o=Math.max(o,e[t].bot);return n},r=t=>{const s=(t=>{const s=[...t].sort(((t,e)=>t.x0-e.x0)),o=[];let l=s[0].x1;const r=t=>{const e=t.filter((t=>!t.tbl));if(new Set(e.map((t=>Math.round(t.top)))).size>=3&&e.filter((t=>t.its.reduce(((t,e)=>t+e.s.length),0)>=20)).length>=.6*e.length)return!0;const s=[...e].sort(((t,e)=>t.top-e.top)).map((t=>t.its.map((t=>t.s)).join(" ").trim()));let n=0,o=0;for(let t=0;t+1<s.length;t++)n++,/^[a-z]/.test(s[t+1])&&o++;return n>=4&&o>=.6*n};for(let a=1;a<s.length;a++){const i=s[a].x0-l,h=n.some((t=>t>l-1&&t<s[a].x0+1));let c=i>=Math.max(1.2*e,9)||i>=5&&h;if(!c&&i>=5){const e=(l+s[a].x0)/2,n=t.filter((t=>t.x1<=e)),o=t.filter((t=>t.x0>=e));c=n.length+o.length===t.length&&r(n)&&r(o)}c&&o.push({at:(l+s[a].x0)/2,w:i+(h?100:0)}),l=Math.max(l,s[a].x1)}return o})(t).sort(((t,e)=>e.w-t.w));for(const n of s){const s=t.filter((t=>t.x1<=n.at)),o=t.filter((t=>t.x0>=n.at));if(s.length+o.length!==t.length)continue;const l=Math.max(...s.map((t=>t.x1)))-Math.min(...s.map((t=>t.x0))),r=Math.max(...o.map((t=>t.x1)))-Math.min(...o.map((t=>t.x0))),a=t=>new Set(t.map((t=>Math.round(t.top)))).size,i=t=>{const e=t.filter((t=>!t.tbl)).map((t=>t.its.map((t=>t.s)).join(" ").trim()));return e.length>=3&&e.filter((t=>t.length<=6||/^[\d\s.,%()+-]+$/.test(t))).length>=.75*e.length};if((!i(s)||!i(o))&&a(s)>=2&&a(o)>=2&&l>=6*e&&r>=6*e)return{L:s,R:o,at:n.at}}return null},a=r(t),i=o&&a&&(()=>{const s=Math.min(...t.map((t=>t.top))),n=Math.max(...t.map((t=>t.bot)));for(const o of l(t)){const l=t.filter((t=>(t.top+t.bot)/2<o.at)),a=t.filter((t=>(t.top+t.bot)/2>=o.at));if(!l.length||!a.length||a.some((t=>t.tbl||t.img))||n-o.at>2*(o.at-s))continue;const i=x(l.flatMap((t=>t.its.map((t=>t.size)))));if(!i||i>1.3*e||a.some((t=>t.its.some((t=>t.size>.92*i)))))continue;const h=r(l),c=t=>{const e=new Set(t.map((t=>Math.round((t.top+t.bot)/6)))).size;return e>=3&&t.reduce(((t,e)=>t+e.its.reduce(((t,e)=>t+(e.s.match(/[A-Za-z가-힣\u4e00-\u9fff]/g)||[]).length),0)),0)>=20*e};if(h&&c(h.L)&&c(h.R))return[l,a]}return null})();if(i)return[...mt(i[0],e,s,n,o),...mt(i[1],e,s,n,o)];if("4"===process.env.PDFMD_DEBUG&&console.error("[xy]",t.length,Math.min(...t.map((t=>t.top))).toFixed(0)+"-"+Math.max(...t.map((t=>t.bot))).toFixed(0),a?"x@"+Math.round(a.at):"-"),a){const t=mt(a.L,e,s,n,o),l=mt(a.R,e,s,n,o),r=[],i=t=>t.flatMap((t=>t.its.map((t=>t.size)))),h=t=>[...t].sort(((t,e)=>t.top-e.top||t.x0-e.x0)).map((t=>t.its.map((t=>t.s)).join(""))).join(" ").trim();for(;o&&t.length>1;){const e=t[t.length-1],s=t.slice(0,-1).flat(),n=x(i(s));if(e.some((t=>t.tbl||t.img))||!/^\d{1,3}\s*\S/.test(h(e))||Math.max(...i(e))>.92*n||Math.max(...a.R.map((t=>t.bot)))<Math.min(...e.map((t=>t.top))))break;r.unshift(t.pop())}return[...t,...l,...r]}const h=l(t);if(h.length){const l=h.map((t=>t.at)),a=Array.from({length:l.length+1},(()=>[]));for(const e of t){let t=0;for(;t<l.length&&(e.top+e.bot)/2>l[t];)t++;a[t].push(e)}let i=a.filter((t=>t.length));if(o&&i.length>1){const s=t=>new Set(t.map((t=>Math.round((t.top+t.bot)/6)))).size,n=t=>t.reduce(((t,e)=>t+e.its.reduce(((t,e)=>t+(e.s.match(/[A-Za-z가-힣\u4e00-\u9fff]/g)||[]).length),0)),0),o=t=>t.length&&n(t)>=8*s(t),l=(t,s=Math.max(1.2*e,9))=>{const n=[...t].sort(((t,e)=>t.x0-e.x0)),o=[];let l=n[0].x1;for(let t=1;t<n.length;t++)n[t].x0-l>=s&&o.push([l,n[t].x0]),l=Math.max(l,n[t].x1);return o},a=t=>x(t.flatMap((t=>t.its.map((t=>t.size))))),h=[];for(let s=0;s<i.length;){const n=i[s];let c=[...n],f=[],x=s+1,p=s;for(;x<i.length;x++){const s=i[x],h=i[x-1],m=[...c,...f.flat(),...s],u=r(m);if(!u||m.length>=t.length)break;const g=(t,e)=>t.some((t=>e.includes(t))),b=Math.min(...s.map((t=>t.top)))-Math.max(...h.map((t=>t.bot))),M=Math.min(...s.map((t=>t.x0))),d=Math.max(...s.map((t=>t.x1))),y=l(s),z=l(n,3).find((([t,e])=>t<=u.at&&u.at<=e)),w=l(m,3).find((([t,e])=>t<=u.at&&u.at<=e));if(!(z&&w&&w[1]-w[0]>=.4*(z[1]-z[0])&&l(n).every((([t,e])=>e<=M||t>=d||y.some((([s,n])=>Math.min(e,n)-Math.max(t,s)>0))))&&g(n,u.L)&&g(n,u.R)&&o(n.filter((t=>u.L.includes(t))))&&o(n.filter((t=>u.R.includes(t))))&&b<=3*Math.max(a(h),a(s),e)))break;g(s,u.L)&&g(s,u.R)?(c=m,f=[],p=x):f.push(s)}h.push(c),s=p+1}i=h}if(i.length>1)return i.flatMap((t=>mt(t,e,s,n,o)))}return[t]}const ut=/^[•●▪■◦○◆◇►▸‣⁃∙·❖➢✓✔※□❍❏-]\s*/,gt=/^[•‣⁃]\s*/,bt=/^(\d{1,2}[.)]|[가-하][.)]|\(\d{1,2}\)|\([가-하]\)|[①-⑳]|[a-z][.)]|[IVX]+\.)\s*/,Mt=t=>/^(?:[-–—]\s*)?(?:page\s*)?\d{1,4}(?:\s*(?:of|\/)\s*\d{1,4})?(?:\s*[-–—])?$/i.test(t)||/^[ivxlcdm]{1,6}$/i.test(t);function dt(t,e,s=0,n=!1){const o=xt(t.flatMap((t=>t.its.map((t=>({...t})))))),l=[];let r=null;const a=Math.max(...o.map((t=>t.x1))),i=Math.min(...o.map((t=>t.x0)));for(const t of o){if(r){const o=r.lines[r.lines.length-1],h=t.top-o.bot,c=Math.min(o.bot-o.top,t.bot-t.top),f=t=>t.text.length<=90&&/[A-Z]{3}/.test(t.text)&&t.text===t.text.toUpperCase()&&(t.text.match(/[A-Za-z]/g)||[]).length>=.8*(t.text.match(/[A-Za-z가-힣]/g)||[]).length,x=/[a-z]-$/.test(o.text)||/^[a-z]/.test(t.text);if(!(h>Math.max(.75*c,1.5*s)||Math.abs(t.fsize-o.fsize)>.12*o.fsize||!x&&t.bold!==o.bold&&(t.text.length<90||o.text.length<90)||!x&&f(o)!==f(t)||ut.test(t.text)||/^(\d{1,2}[.)]|[a-z][.)]|\(\d{1,2}\))\s/.test(t.text)&&o.x1<a-4*e||t.x0-i>1.5*e&&t.x0-o.x0>1.5*e&&!ut.test(r.lines[0].text)&&!bt.test(r.lines[0].text)||/[.:!?。」”)]$/.test(o.text)&&o.x1<a-5*e||n&&(ut.test(r.lines[0].text)||bt.test(r.lines[0].text))&&t.x0<r.lines[0].x0-1*e&&h>.75*c&&!x)){r.lines.push(t);continue}l.push(r)}r={lines:[t]}}return r&&l.push(r),l.map((t=>{let e="",s="";for(const n of t.lines){if(!e){e=n.text,s=n.stext||n.text;continue}const o=W(t.lines[t.lines.indexOf(n)-1],n,a);e+=o+n.text,s+=o+(n.stext||n.text)}const n={};for(const e of t.lines)n[e.fsize]=(n[e.fsize]||0)+e.text.length;const o=t.lines[0],l=o.its,r=t=>/^\d{1,4}$/.test(t.s.trim());return{kind:"p",text:e,stext:s,pnum:1===t.lines.length&&l.length>=2&&(r(l[0])&&l[1].x0-l[0].x1>=.9*o.size||r(l[l.length-1])&&l[l.length-1].x0-l[l.length-2].x1>=.9*o.size),wide:t.lines.some((t=>t.its.some(((e,s)=>s&&e.x0-t.its[s-1].x1>=2.5*t.size)))),grid:t.lines.every((t=>t.its.every((t=>t.grid)))),top:t.lines[0].top,bot:t.lines[t.lines.length-1].bot,x0:Math.min(...t.lines.map((t=>t.x0))),x1:Math.max(...t.lines.map((t=>t.x1))),fsize:+Object.entries(n).sort(((t,e)=>e[1]-t[1]))[0][0],bold:t.lines.every((t=>t.bold)),nl:t.lines.length,chars:e.length}}))}async function yt(t,e,{korean:n=!1,tc:o=null,jst:l=null,images:r=!1}={}){const a=t.getViewport({scale:1}).transform,i=t.getViewport({scale:1}).height,h=await t.getOperatorList(),c=o||await t.getTextContent(),f=e=>{try{return t.commonObjs.has(e)&&t.commonObjs.get(e).differences||null}catch{return null}};!function(t,e,s,n,o=null){const l=[];let r=null,a=!1;const i=new Map;for(let s=0;s<t.fnArray.length;s++){const h=t.fnArray[s];if(h===e.setFont)r=t.argsArray[s][0];else if(h===e.showText){const e=r&&n(r),h=r&&o?o(r):"";if(/^([A-Z]{6}\+)?TeXCMMaths/.test(h)){let n=i.get(r);n||i.set(r,n={fname:h,d:e,reps:[]});for(const o of t.argsArray[s][0]||[])o&&"object"==typeof o&&"�"===o.unicode&&n.reps.push(v(h,o.originalCharCode,e&&e[o.originalCharCode],o.unicode)||"�");continue}for(const n of t.argsArray[s][0]||[]){if(!n||"object"!=typeof n||!n.unicode)continue;const t=e&&e[n.originalCharCode],s=!!t&&/\.(sc|smcp|c2sc)$/i.test(t),o="�"===n.unicode&&t?y(t):null;(s||o)&&(a=!0);for(const t of n.unicode)/\s/.test(t)||l.push({ch:t,sc:s,rep:o})}}}if(!a&&!i.size)return;const h={"¼":"=","þ":"+","ð":"(","Þ":")","½":"["};for(const t of s.items){const e=t.str&&i.get(t.fontName);if(!e)continue;const s=/^([A-Z]{6}\+)?TeXCMMathsSymbols\b/.test(e.fname),n=/^([A-Z]{6}\+)?TeXCMMathsItalic\b/.test(e.fname);t.str=[...t.str].map((t=>"�"===t&&e.reps.length?e.reps.shift():s&&h[t]?h[t]:n&&":"===t?".":n&&";"===t?",":t)).join("")}if(!a)return;let c=0;for(const t of s.items){if(!t.str||!t.str.trim()||i.has(t.fontName))continue;let e="",s=!1;for(const n of t.str){if(/\s/.test(n)){e+=n;continue}let t=c;for(;t<l.length&&t<c+24&&l[t].ch!==n;)t++;if(t<l.length&&l[t].ch===n){const o=l[t];if(c=t+1,o.rep&&1===o.rep.length){e+=o.rep,s=!0;continue}if(o.sc&&n.toUpperCase()!==n){e+=n.toUpperCase(),s=!0;continue}}e+=n}s&&(t.str=e)}}(h,e.OPS,c,f,(e=>{try{return t.commonObjs.has(e)&&t.commonObjs.get(e).name||""}catch{return""}}));const p=z(c,a,e.Util,(e=>{try{return t.commonObjs.has(e)&&t.commonObjs.get(e).name||""}catch{return""}}),n?function(t,e,s){const n=[],o=[];let l=0;for(let s=0;s<t.fnArray.length;s++){const r=t.fnArray[s];if(r===e.save)o.push(l);else if(r===e.restore)o.length&&(l=o.pop());else if(r===e.setTextRenderingMode)l=t.argsArray[s][0];else if(r===e.showText)for(const e of t.argsArray[s][0]||[])if(e&&"object"==typeof e&&e.unicode)for(const t of e.unicode)/\s/.test(t)||n.push({ch:t,b:2===l})}const r=new Set;if(!n.some((t=>t.b)))return r;let a=0;return s.items.forEach(((t,e)=>{let s=0,o=0;for(const e of t.str||""){if(/\s/.test(e))continue;let t=a;for(;t<n.length&&t<a+24&&n[t].ch!==e;)t++;t<n.length&&n[t].ch===e&&(s++,n[t].b&&o++,a=t+1)}s&&o>=.5*s&&r.add(e)})),r}(h,e.OPS,c):null,f);if(!p.length)return{blocks:[],sizes:{},chars:0};const m=n||(()=>{let t=0,e=0;for(const s of p)for(const n of s.s)/[가-힣]/.test(n)&&t++,/[A-Za-z가-힣]/.test(n)&&e++;return e>0&&t>=.3*e})(),g=t.getViewport({scale:1}).width,b=[];if(!m&&p.rot)for(const t of p.rot)t.bot-t.top>.25*i||t.x1<.08*g||t.x0>.92*g?b.push(t):p.push(t);if(l&&!o&&m)for(const t of xt([...p]))for(const e of q(t))H(l,e);L=l&&l.size?l:null;let{H:M,V:d,F:w,I:$,C:A,H0:j,V0:X}=k(h,e.OPS,e.Util,a,m);const C=m?function(t,e,s,n,o,l,r){const a=.3,i=[];for(const e of t)if(!(e.x1-e.x0<.5||e.y1-e.y0<.5||(e.x1-e.x0)*(e.y1-e.y0)>.75*l*r)&&(i.some((t=>Math.abs(t.x0-e.x0)<=a&&Math.abs(t.x1-e.x1)<=a&&Math.abs(t.y0-e.y0)<=a&&Math.abs(t.y1-e.y1)<=a))||i.push({...e}),i.length>2500))return null;if(i.length<2)return null;const h=(t,e)=>e.x0>=t.x0-a&&e.x1<=t.x1+a&&e.y0>=t.y0-a&&e.y1<=t.y1+a;for(const t of i)t.depth=i.filter((e=>e!==t&&h(e,t)&&!h(t,e))).length;const c=i.map(((t,e)=>e)),f=t=>c[t]===t?t:c[t]=f(c[t]),p=(t,e,s,n)=>Math.min(e,n)-Math.max(t,s);for(let t=0;t<i.length;t++)for(let e=t+1;e<i.length;e++){const s=i[t],n=i[e];s.depth===n.depth&&((Math.abs(s.x1-n.x0)<=a||Math.abs(n.x1-s.x0)<=a)&&p(s.y0,s.y1,n.y0,n.y1)>.5||(Math.abs(s.y1-n.y0)<=a||Math.abs(n.y1-s.y0)<=a)&&p(s.x0,s.x1,n.x0,n.x1)>.5)&&(c[f(t)]=f(e))}const m=new Map;i.forEach(((t,e)=>{const s=f(e);m.has(s)||m.set(s,[]),m.get(s).push(t)}));const u=[...m.values()].filter((t=>t.length>=2)),g=t=>({x0:Math.min(...t.map((t=>t.x0))),x1:Math.max(...t.map((t=>t.x1))),y0:Math.min(...t.map((t=>t.y0))),y1:Math.max(...t.map((t=>t.y1))),ys:S(t.flatMap((t=>[t.y0,t.y1])),a)}),b=(t,e,n)=>s.filter((e=>Math.abs(e.x-t)<=1.5)).reduce(((t,s)=>t+Math.max(0,Math.min(s.y1,n)-Math.max(s.y0,e))),0);for(let t=0;t<u.length;t++)for(let e=0;e<u.length;e++){const s=u[t],n=u[e];if(t===e||!s.length||!n.length||s[0].depth!==n[0].depth)continue;const o=g(s),l=g(n);if(l.x0<o.x1-a||l.x0-o.x1<20)continue;if(p(o.y0,o.y1,l.y0,l.y1)<.8*Math.min(o.y1-o.y0,l.y1-l.y0))continue;const[r,h]=o.ys.length<=l.ys.length?[o.ys,l.ys]:[l.ys,o.ys];if(r.length<3||r.filter((t=>h.some((e=>Math.abs(t-e)<=a)))).length<.8*r.length)continue;const c=Math.max(o.y0,l.y0),f=Math.min(o.y1,l.y1);b(o.x1,c,f)<.6*(f-c)||b(l.x0,c,f)<.6*(f-c)||i.some((t=>t.depth===s[0].depth&&t.x0<l.x0-a&&t.x1>o.x1+a&&t.y0<f&&t.y1>c))||(s.push(...n),n.length=0)}const M=(t,e)=>{let s=0;for(let n=1;n<e.length;n++)Math.abs(e[n]-t)<Math.abs(e[s]-t)&&(s=n);return s},d=[];for(const t of u){if(t.length<2)continue;const e=S(t.flatMap((t=>[t.x0,t.x1])),a),s=S(t.flatMap((t=>[t.y0,t.y1])),a),n=s.length-1,o=e.length-1;if(n<1||o<1||n*o>4e4)continue;const l=Array.from({length:n},(()=>new Array(o).fill(null))),r=[];let i=!1;for(const n of t){const t=M(n.x0,e),o=M(n.x1,e)-1,a=M(n.y0,s),h=M(n.y1,s)-1;if(o<t||h<a){i=!0;break}const c={r:a,c:t,rs:h-a+1,cs:o-t+1,its:[]};for(let e=a;e<=h&&!i;e++)for(let s=t;s<=o;s++){if(l[e][s]){i=!0;break}l[e][s]=c}r.push(c)}if(i)continue;let h=0;for(let t=1;t<n-1;t++)for(let e=0;e<o;e++)l[t][e]||h++;if(!(h>.3*Math.max(1,n-2)*o)){for(let t=0;t<n;t++)for(let e=0;e<o;e++)if(!l[t][e]){const s={r:t,c:e,rs:1,cs:0,its:[],hole:!0};for(r.push(s);e<o&&!l[t][e];)l[t][e]=s,s.cs++,e++;e--}for(const t of r.filter((t=>t.hole)).sort(((t,e)=>t.r-e.r)))if(!t.dead)for(;;){const e=r.find((e=>e.hole&&!e.dead&&e!==t&&e.c===t.c&&e.cs===t.cs&&e.r===t.r+t.rs));if(!e)break;t.rs+=e.rs,e.dead=!0;for(let s=e.r;s<e.r+e.rs;s++)for(let n=e.c;n<e.c+e.cs;n++)l[s][n]=t}for(let t=r.length-1;t>=0;t--)r[t].dead&&r.splice(t,1);for(const t of r)t.x0=e[t.c],t.x1=e[t.c+t.cs],t.top=s[t.r],t.bot=s[t.r+t.rs];d.push({Xs:e,Ys:s,R:n,C:o,cells:r,own:l,depth:t[0].depth,x0:e[0],x1:e[o],top:s[0],bot:s[n]})}}if(!d.length)return null;const y=(t,e,s)=>{let n=0;for(;n<t.C-1&&e>t.Xs[n+1];)n++;let o=0;for(;o<t.R-1&&s>t.Ys[o+1];)o++;return t.own[o][n]},z=(t,e,s)=>e>=t.x0&&e<=t.x1&&s>=t.top&&s<=t.bot;for(const t of n){if(t.used)continue;const e=(t.x0+t.x1)/2,s=(t.top+t.bot)/2;let n=null;for(const t of d)z(t,e,s)&&(!n||t.depth>n.depth)&&(n=t);n&&(y(n,e,s).its.push(t),t.grid=!0)}for(const t of d){for(const e of d)e.depth>t.depth&&z(t,(e.x0+e.x1)/2,(e.top+e.bot)/2)&&(y(t,(e.x0+e.x1)/2,(e.top+e.bot)/2).nest=!0);for(const e of o){const s=(e.x0+e.x1)/2,n=(e.y0+e.y1)/2;z(t,s,n)&&!d.some((e=>e.depth>t.depth&&z(e,s,n)))&&(y(t,s,n).img=!0)}}const w=[],v=[],$=[],k=t=>t.some(Boolean),A=t=>t.every(Boolean),j=t=>t.its.length>0||t.nest||t.img;for(const t of d){const{Xs:n,Ys:o,R:l,C:r,cells:a}=t,i=(t,e)=>{let s=0;for(let n=1;n<e.length;n++)Math.abs(e[n]-t)<Math.abs(e[s]-t)&&(s=n);return Math.abs(e[s]-t)<=1.5?s:-1},h=Array.from({length:l+1},(()=>new Array(r).fill(!1))),c=Array.from({length:l},(()=>new Array(r+1).fill(!1))),f=d.filter((e=>e.depth>t.depth&&z(t,(e.x0+e.x1)/2,(e.top+e.bot)/2))),p=(t,e,s,n)=>!f.some((o=>t>=o.x0-1&&e<=o.x1+1&&s>=o.top-1&&n<=o.bot+1)),m=(t,e,s)=>{const n=t.map((([t,n])=>[Math.max(t,e),Math.min(n,s)])).filter((([t,e])=>e>t)).sort(((t,e)=>t[0]-e[0]));let o=0,l=-1/0;for(const[t,e]of n)e<=l||(o+=e-Math.max(t,l),l=e);return o},u=h.map((()=>[])),g=Array.from({length:r+1},(()=>[]));for(const s of e){const e=i(s.y,o);e>=0&&s.x1>=t.x0&&s.x0<=t.x1&&p(s.x0,s.x1,s.y,s.y)&&u[e].push([s.x0,s.x1])}for(const e of s){const s=i(e.x,n);s>=0&&e.y1>=t.top&&e.y0<=t.bot&&p(e.x,e.x,e.y0,e.y1)&&g[s].push([e.y0,e.y1])}for(let t=0;t<=l;t++)for(let e=0;e<r;e++)h[t][e]=u[t].length>0&&m(u[t],n[e],n[e+1])>=.5*(n[e+1]-n[e]);for(let t=0;t<l;t++)for(let e=0;e<=r;e++)c[t][e]=g[e].length>0&&m(g[e],o[t],o[t+1])>=.5*(o[t+1]-o[t]);const b=new Array(l).fill(0);for(const t of a)for(let e=t.r;e<t.r+t.rs;e++)b[e]++;const M=Array.from({length:l},((t,e)=>k(c[e])||b[e]>=2&&A(h[e])&&A(h[e+1]))),y=new Array(l+1).fill(!1);for(const t of a)for(let e=t.r+1;e<t.r+t.rs;e++)y[e]=!0;for(let t=0;t<l;){let e=t;for(;e+1<l&&y[e+1];)e++;const s=e-t+1;if(s>1&&A(h[t])&&A(h[e+1])&&a.filter((e=>e.r===t&&e.rs===s)).length>=2)for(let s=t;s<=e;s++)M[s]=!0;t=e+1}const X=(t,e)=>{let s=a.filter((s=>s.r>=t&&s.r<=e)).map((t=>({...t,rs:Math.min(t.rs,e-t.r+1)}))),n=1/0,o=-1/0;for(let s=t;s<=e;s++){for(let t=0;t<=r;t++)c[s][t]&&(n=Math.min(n,t),o=Math.max(o,t));for(const t of[s,s+1])for(let e=0;e<r;e++)h[t][e]&&(n=Math.min(n,e),o=Math.max(o,e+1))}if(Number.isFinite(n)&&(s=s.filter((t=>t.c<o&&t.c+t.cs>n||j(t)))),!s.some(j))return null;const l=[];for(let n=t;n<=e;n++){const t=s.filter((t=>t.r===n));!t.length||t.some(j)||k(h[n])&&k(h[n+1])||l.push(n)}if(l.length){const t=t=>t-l.filter((e=>e<t)).length;s=s.filter((t=>!l.includes(t.r))).map((e=>({...e,r:t(e.r),rs:t(e.r+e.rs)-t(e.r)}))).filter((t=>t.rs>0))}for(let t=Math.max(...s.map((t=>t.c+t.cs)));t>1;){const e=s.filter((e=>e.c===t-1));if(!e.length||e.some(j)||e.length===s.length)break;s=s.filter((e=>e.c!==t-1)).map((e=>e.c+e.cs===t?{...e,cs:e.cs-1}:e)).filter((t=>t.cs>0)),t--}return s.y0=t,s.y1=e,s},S=[];for(let t=0;t<l;){if(!M[t]){t++;continue}let e=t;for(;e+1<l&&M[e+1];)e++;S.push(X(t,e)),t=e+1}for(const t of S){if(!t||!t.some(j))continue;const e=t.filter(j).length<2;if(e&&!(t.some((e=>e.r===t.y0&&e.hole))||!k(h[t.y0])&&c[t.y0].filter(Boolean).length>=2)||e&&new Set(t.flatMap((t=>[t.c,t.c+t.cs]))).size<3)continue;const s=[...new Set(t.flatMap((t=>[t.c,t.c+t.cs])))].sort(((t,e)=>t-e)),l=[...new Set(t.flatMap((t=>[t.r,t.r+t.rs])))].sort(((t,e)=>t-e)),r=new Map(s.map(((t,e)=>[t,e]))),i=new Map(l.map(((t,e)=>[t,e]))),f=t.map((t=>({r0:i.get(t.r),r1:i.get(t.r+t.rs)-1,c0:r.get(t.c),c1:r.get(t.c+t.cs)-1,its:t.its,x0:t.x0,x1:t.x1,top:t.top,bot:t.bot,hole:t.hole})));for(const e of t)for(const t of e.its)t.used=!0;const x=t.y0,p=t.y1,m=t=>o[t+1]-o[t]<8&&!a.some((e=>e.r===t&&j(e)));let u=p;for(;u>x&&!k(h[u])&&m(u-1);)u--;let g=x+1;for(;g<=p&&!k(h[g])&&m(g);)g++;const b=(g>p||k(h[g]))&&!k(h[x])&&c[x].filter(Boolean).length>=2,M=(u<=x||k(h[u]))&&!k(h[p+1])&&c[p].filter(Boolean).length>=2,d=t.some((t=>t.r===x&&t.hole));w.push({top:Math.min(...t.map((t=>t.top))),bot:Math.max(...t.map((t=>t.bot))),x0:Math.min(...t.map((t=>t.x0))),x1:Math.max(...t.map((t=>t.x1))),cells:f,R:l.length-1,C:s.length-1,Xs:s.map((t=>n[t])),src:"clip",openTop:b,openBot:M,holeTop:d,frag:e})}for(let t=0;t<l;t++){if(M[t])continue;const e=a.filter((e=>e.r===t&&e.its.some((t=>!t.used)))).sort(((t,e)=>t.c-e.c));if(e.length<2)continue;const s=e.flatMap((t=>t.its.filter((t=>!t.used)))),n=e.map((t=>U(t.its.filter((t=>!t.used)),t).replace(/\n/g," "))).filter(Boolean).join(" ");for(const t of s)t.used=!0;$.push({text:n,top:Math.min(...s.map((t=>t.top))),bot:Math.max(...s.map((t=>t.bot))),x0:Math.min(...s.map((t=>t.x0))),x1:Math.max(...s.map((t=>t.x1))),fsize:Math.round(2*x(s.map((t=>t.size))))/2,bold:s.every((t=>t.bold))})}v.push({x0:t.x0,x1:t.x1,top:t.top,bot:t.bot})}return{tables:w,areas:v,paras:$}}(A,j,X,p,$,t.getViewport({scale:1}).width,i):null;if(C){const t=(t,e,s,n)=>C.areas.some((o=>t>=o.x0-2&&e<=o.x1+2&&s>=o.top-2&&n<=o.bot+2));M=M.filter((e=>!t(e.x0,e.x1,e.y,e.y))),d=d.filter((e=>!t(e.x,e.x,e.y0,e.y1))),w=w.filter((e=>!t(e.x0,e.x1,e.y0,e.y1)))}const B=P(M,d,p,w);C&&B.push(...C.tables),B.push(...Y(w,p,t.getViewport({scale:1}).width,i,B,x(p.map((t=>t.size)))||10)),B.push(...function(t,e,s,n){const o=[];for(const l of t){const t=e.filter((t=>(t.x0+t.x1)/2>l.x0&&(t.x0+t.x1)/2<l.x1&&(t.y0+t.y1)/2>l.top&&(t.y0+t.y1)/2<l.bot)),r=l.its.filter((t=>!t.used));if(!t.length||!r.length||l.x1-l.x0<.6*s||l.bot-l.top>6*n||xt(r.map((t=>({...t})))).length>2)continue;const a=[...r.map((t=>({x0:t.x0,x1:t.x1,t:t}))),...t.map((t=>({x0:t.x0,x1:t.x1,img:!0})))].sort(((t,e)=>t.x0-e.x0)),i=[];for(const t of a){const e=i[i.length-1];e&&t.x0-e.x1<1.5*n?(e.x1=Math.max(e.x1,t.x1),t.t&&e.its.push(t.t)):i.push({x0:t.x0,x1:t.x1,its:t.t?[t.t]:[],img:!!t.img})}if(i.length<2||!i.some((t=>t.its.length)))continue;const h=[l.x0,...i.slice(1).map(((t,e)=>(i[e].x1+t.x0)/2)),l.x1],c=i.map(((t,e)=>({r0:0,r1:0,c0:e,c1:e,its:t.its,x0:h[e],x1:h[e+1],top:l.top,bot:l.bot})));for(const t of r)t.used=!0;o.push({top:l.top,bot:l.bot,x0:l.x0,x1:l.x1,cells:c,R:1,C:i.length,Xs:h,src:"logo"})}return o}(B.boxes||[],$,t.getViewport({scale:1}).width,x(p.map((t=>t.size)))||10)),B.push(...function(t,e,s=[]){const n=t.filter((t=>t.its.some((t=>!t.used)))).sort(((t,e)=>t.top-e.top||t.x0-e.x0)),o=new Set,l=[],r=(t,e)=>s.filter((s=>!s.used&&(s.top+s.bot)/2>t.top&&(s.top+s.bot)/2<t.bot&&s.x0>=t.x1-1&&s.x1<=e.x0+1));for(const t of n){if(o.has(t))continue;const s=[t];for(const t of n){const n=s[s.length-1];if(t===n||o.has(t)||Math.abs(t.top-n.top)>2||Math.abs(t.bot-n.bot)>2||t.x0<n.x1-1)continue;const l=r(n,t),a=l.length&&l.every((t=>I.test(t.s.replace(/\s/g,""))));(t.x0-n.x1<=3*e||a&&t.x0-n.x1<=10*e)&&(a&&(t.mid=l),s.push(t))}if(s.length<2)continue;const a=[],i=[s[0].x0];let h=0;for(const[t,e]of s.entries()){if(t&&e.x0-s[t-1].x1>1){a.push({r0:0,r1:0,c0:h,c1:h,its:e.mid||[],x0:s[t-1].x1,x1:e.x0,top:e.top,bot:e.bot}),h++,i.push(e.x0);for(const t of e.mid||[])t.used=!0}a.push({r0:0,r1:0,c0:h,c1:h,its:e.its.filter((t=>!t.used)),x0:e.x0,x1:e.x1,top:e.top,bot:e.bot}),h++,i.push(e.x1)}for(const t of s){o.add(t);for(const e of t.its)e.used=!0}l.push({top:Math.min(...s.map((t=>t.top))),bot:Math.max(...s.map((t=>t.bot))),x0:s[0].x0,x1:s[s.length-1].x1,cells:a,R:1,C:h,Xs:i,src:"boxes"})}return l}(B.boxes||[],x(p.map((t=>t.size)))||10,p)),B.push(...function(t,e,s,n){const o=[];for(const l of t){const r=l.its.filter((t=>!t.used));if(!r.length||l.x1-l.x0>.2*s||l.bot-l.top>8*n)continue;const a=e.filter((e=>!e.used&&!r.includes(e)&&!t.some((t=>t!==l&&!(t.x0<=l.x0+1&&t.x1>=l.x1-1&&t.top<=l.top+1&&t.bot>=l.bot-1)&&t.its.includes(e)))&&(e.top+e.bot)/2>l.top-.5*n&&(e.top+e.bot)/2<l.bot+.5*n&&e.x1<=l.x0+2&&e.x0>=l.x0-.5*s));if(!a.length||l.x0-Math.max(...a.map((t=>t.x1)))>3*n)continue;const i=Math.min(...a.map((t=>t.x0))),h=Math.min(l.top,...a.map((t=>t.top))),c=Math.max(l.bot,...a.map((t=>t.bot))),f=[{r0:0,r1:0,c0:0,c1:0,its:a,x0:i,x1:l.x0,top:h,bot:c},{r0:0,r1:0,c0:1,c1:1,its:r,x0:l.x0,x1:l.x1,top:h,bot:c}];for(const t of[...a,...r])t.used=!0;o.push({top:h,bot:c,x0:i,x1:l.x1,cells:f,R:1,C:2,Xs:[i,l.x0,l.x1],src:"seal"})}return o}(B.boxes||[],p,t.getViewport({scale:1}).width,x(p.map((t=>t.size)))||10)),B.push(...function(t,e,s){const n=[];for(const o of t){const t=o.its.filter((t=>!t.used));if(o.x1-o.x0<.6*e||o.bot-o.top>.4*s||t.length<2)continue;const l=xt(t.map((t=>({...t}))));if(l.length<2)continue;let r=0;const a=t=>x(l.slice(t).map((t=>t.fsize)));for(;r<l.length-1&&l[r].fsize>=1.25*a(r+1);)r++;if(!r)continue;const i=(l[r-1].bot+l[r].top)/2,h=[{r0:0,r1:0,c0:0,c1:0,its:l.slice(0,r).flatMap((t=>t.its)),x0:o.x0,x1:o.x1,top:o.top,bot:i},{r0:1,r1:1,c0:0,c1:0,its:l.slice(r).flatMap((t=>t.its)),x0:o.x0,x1:o.x1,top:i,bot:o.bot}];for(const e of t)e.used=!0;n.push({top:o.top,bot:o.bot,x0:o.x0,x1:o.x1,cells:h,R:2,C:1,Xs:[o.x0,o.x1],src:"title"})}return n}(B.boxes||[],t.getViewport({scale:1}).width,i));const O=p.filter((t=>!t.used)),F=x(O.map((t=>t.size)))||x(p.map((t=>t.size)))||10,D=xt(O.map((t=>({...t})))),T=at(M.filter((t=>!B.some((e=>t.y>=e.top-2&&t.y<=e.bot+2&&t.x0>=e.x0-2&&t.x1<=e.x1+2)))),D,F,B,m),R=it(O.filter((t=>!t.used)));{const t=()=>!m;m||T.push(...function(t,e){const s=t.filter((t=>!t.done)).sort(((t,e)=>t.top-e.top||t.x0-e.x0)),n=[];for(let t=0;t<s.length;t++){const o=s[t];if(o.done)continue;const l=Q(o);if(l.length<3||!o.its.every((t=>t.bold))||l.some((t=>t.text.length>40||!/[A-Za-z]{2}/.test(t.text))))continue;const r=l.map((t=>t.x0)),a=.8*e,i=r.length,h=t=>{let e=-1;for(let s=0;s<i;s++)t>=r[s]-a&&(e=s);return e},c=[];let f=o;for(let n=t+1;n<s.length;n++){const t=s[n];if(t.done)continue;if(t.top-f.bot>2.5*Math.max(e,t.size))break;const o=Q(t);if(o.some((t=>h(t.x0)<0||t.x1>(r[h(t.x0)+1]??1/0)+a)))break;c.push(...o.map((e=>({k:h(e.x0),top:t.top,bot:t.bot,text:e.text,l:t})))),f=t}if(new Set(c.map((t=>t.l))).size<4||new Set(c.map((t=>t.k))).size<i)continue;const x=[],p=[],m=Array.from({length:i},((t,e)=>c.filter((t=>t.k===e)).sort(((t,e)=>t.top-e.top))));for(const t of m)for(let s=1;s<t.length;s++)t[s].top-t[s-1].top>.3*e&&p.push(t[s].top-t[s-1].top);const g=p.length?[...p].sort(((t,e)=>t-e))[Math.floor(p.length/4)]:1.2*e;m.forEach(((t,e)=>t.forEach(((s,n)=>{(!n||s.top-t[n-1].top>1.3*g)&&x.push({k:e,y:s.top})}))));const b=S(x.filter((t=>t.k<=1)).map((t=>t.y)),.6*e);if(b.length<2)continue;const M=t=>{let s=0;for(;s+1<b.length&&t>=b[s+1]-.6*e;)s++;return s},d=Array.from({length:b.length},(()=>Array.from({length:i},(()=>[]))));for(const t of c)d[M(t.top)][t.k].push(t.text);if(d.flat().filter((t=>t.length)).length<.5*b.length*i)continue;const y=[];for(let t=0;t<b.length;t++)y.push(d[t].map((t=>t.join(" "))));let z="<table><tr>"+l.map((t=>`<td>${u(t.text)}</td>`)).join("")+"</tr>";for(let t=0;t<b.length;t++){let e=y[t].map((t=>`<td>${u(t)}</td>`));if(!y[t][0]&&t>0)e=e.slice(1);else{let s=1;for(;t+s<b.length&&!y[t+s][0];)s++;s>1&&(e[0]=`<td rowspan="${s}">${u(y[t][0])}</td>`)}z+="<tr>"+e.join("")+"</tr>"}z+="</table>";const w=[o,...new Set(c.map((t=>t.l)))];for(const t of w)t.done=!0;n.push({src:"head",kind:"table",html:z,top:o.top,bot:Math.max(...w.map((t=>t.bot))),x0:Math.min(...w.map((t=>t.x0))),x1:Math.max(...w.map((t=>t.x1)))})}return n}(D,F)),T.push(...function(t,e,n=[],o=()=>!0){const l=ht(t.filter((t=>!t.done)),n).sort(((t,e)=>t.top-e.top||t.x0-e.x0)),r=[],a=[];for(const t of l){const s=a.find((s=>!s.closed&&t.top<s.bot+.3*e&&Math.min(t.x1,s.x1)-Math.max(t.x0,s.x0)>-4*e));if(s)s.ls.push(t),s.bot=Math.max(s.bot,t.bot),s.x0=Math.min(s.x0,t.x0),s.x1=Math.max(s.x1,t.x1);else{for(const s of a)t.top>=s.bot+.3*e&&Math.min(t.x1,s.x1)-Math.max(t.x0,s.x0)>0&&(s.closed=!0);a.push({ls:[t],top:t.top,bot:t.bot,x0:t.x0,x1:t.x1})}}const i=t=>{const s=t.ls.flatMap((t=>Q(t).map((e=>({...e,top:t.top}))))).sort(((t,e)=>t.x0-e.x0)),n=[];for(const t of s){const s=n.find((s=>Math.abs(s.x0-t.x0)<=.8*e||t.x0<s.x1+.6*e&&t.x1>s.x0));s?(s.parts.push(t),s.x0=Math.min(s.x0,t.x0),s.x1=Math.max(s.x1,t.x1)):n.push({x0:t.x0,x1:t.x1,parts:[t]})}return n};a.sort(((t,e)=>t.top-e.top));for(let t=0;t<a.length;){const n=i(a[t]);if(n.length<2){t++;continue}const l=[{b:a[t],f:n}];let h=t+1;const c=(t,e)=>{e.ls.push(...t.ls),e.top=Math.min(e.top,t.top),e.bot=Math.max(e.bot,t.bot),e.x0=Math.min(e.x0,t.x0),e.x1=Math.max(e.x1,t.x1),t.ls=[]};for(;h<a.length;){const t=a[h],s=i(t),n=l[l.length-1].b;if(s.length<2&&l.length>=1){const s=Math.min(...l.map((t=>t.b.x0))),n=Math.max(...l.map((t=>t.b.x1))),o=(t.top+t.bot)/2,r=[...l.map((t=>t.b)),...a.slice(h+1,h+3)].find((s=>s.ls.length&&o>s.top&&o<s.bot&&t.top-s.top<2.6*e));if(r&&t.x0>=s-.5*e&&t.x1<=n+.5*e&&t.bot-t.top<2.6*e){c(t,r);const e=l.find((t=>t.b===r));e&&(e.f=i(r)),h++;continue}}if(s.length<2||t.top-n.bot>2.6*e||Math.min(t.x1,n.x1)-Math.max(t.x0,n.x0)<.5*Math.min(t.x1-t.x0,n.x1-n.x0))break;l.push({b:t,f:s}),h++}const f=l.filter((t=>t.b.ls.length>=2)).length;if(l.length>=3&&f>=2){const n=S(l.flatMap((t=>t.f.map((t=>t.x0)))),.8*e).filter((t=>l.filter((s=>s.f.some((s=>Math.abs(s.x0-t)<=.8*e)))).length>=Math.max(2,.5*l.length)));if(n.length>=2){const a=n.length,i=t=>{let s=0;for(;s<a-1&&t>=n[s+1]-.8*e;)s++;return s},c=l.map((t=>{const e=Array.from({length:a},(()=>[]));for(const s of t.f)for(const t of s.parts)e[i(t.x0)].push(t);return e.map((t=>t.sort(((t,e)=>t.top-e.top||t.x0-e.x0)).map((t=>t.text)).join(" ").trim()))})),f=c.flat().filter(Boolean),x=f.reduce(((t,e)=>t+e.length),0)/Math.max(1,f.length),p=f.filter((t=>(t.match(/[A-Za-z가-힣]/g)||[]).length>=3)).length,m=f.filter((t=>/[∂√∑∫≤≥±×÷=∣]/.test(t))).length,g=c.map((t=>t[a-1])).filter(Boolean),b=g.length>=3&&g.every((t=>/^([ivxlc]+|\d{1,4})(\s+\d{1,4})*$/i.test(t))),M=f.filter((t=>t.length>30)).length;let d=0,y=0;for(let t=0;t<a;t++)for(let e=0;e+1<c.length;e++)c[e][t]&&c[e+1][t]&&(d++,/[a-z,;'’-]$/.test(c[e][t])&&/^[a-z(“"‘]/.test(c[e+1][t])&&y++);if(d>=2&&y>=.4*d){t++;continue}const z=a>=3&&f.length>=.6*c.length*a&&x<=45&&p>=.5*f.length&&m<2&&!b&&M<=.5*f.length&&!c.flat().some((t=>/^(figure|fig\.|table)\s*\d/i.test(t)));"2"===process.env.PDFMD_DEBUG&&console.error("[pdfmd] 띠 표 후보",a,c.length,"okShape",z,{filled:f.length,avg:Math.round(x),letters:p,mathy:m,toc:b,longCells:M},c.slice(0,4).map((t=>t.map((t=>t.slice(0,12))).join(" | "))));const w="<table>"+c.map((t=>"<tr>"+t.map((t=>`<td>${u(s(t))}</td>`)).join("")+"</tr>")).join("")+"</table>";if(z&&o(w)){for(const t of l)for(const e of t.b.ls)if(e.done=!0,e.parent){e.parent.part=(e.parent.part||0)+1;for(const t of e.its)t.tdone=!0}r.push({src:"band",kind:"table",html:w,top:l[0].b.top,bot:l[l.length-1].b.bot,x0:Math.min(...l.map((t=>t.b.x0))),x1:Math.max(...l.map((t=>t.b.x1)))}),t=h;continue}}}t++}return r}(D,F,R,t)),T.push(...function(t,e,s=[],n=()=>!0){const o=ht(t.filter((t=>!t.done)),s).sort(((t,e)=>t.top-e.top||t.x0-e.x0)),l=[];let r=0;for(;r<o.length;){if(Q(o[r]).length<2){r++;continue}let t=r+1;const s=[o[r]];for(;t<o.length&&o[t].top-s[s.length-1].bot<=1.6*e&&Q(o[t]).length>=2;)s.push(o[t]),t++;let a=null;if(1===s.length){const t=Q(s[0]),n=o[r-1],l=t.map((t=>t.x0));t.length>=3&&t.filter((t=>ct.test(t.text))).length>=.75*t.length&&n&&!n.done&&s[0].top-n.bot<=1.6*e&&n.x0>=l[0]-.7*e&&l.every((t=>n.its.some((s=>Math.abs(s.x0-t)<=.7*e))))&&n.its.every(((t,s)=>l.some((s=>Math.abs(t.x0-s)<=.7*e))||s>0&&t.x0-n.its[s-1].x1<.3*e))&&n.its.filter((t=>!ct.test(t.s))).length>=.75*n.its.length&&(a=l)}if(s.length>=3||2===s.length&&ft(s,e)||a){const t=a||nt(s.map((t=>({l:t,cs:Q(t)}))),e),i=o[r-1];t&&i&&!i.done&&s[0].top-i.bot<=1.6*e&&(a||t.filter((t=>i.its.some((s=>Math.abs(s.x0-t)<=.7*e)))).length>=Math.min(3,t.length))&&s.unshift(i);const h=t&&lt(s,e,[],!1,[],a);if(h&&n(rt(h))){for(const t of s)if(t.done=!0,t.parent){t.parent.part=(t.parent.part||0)+1;for(const e of t.its)e.tdone=!0}l.push({src:"free",kind:"table",html:rt(h),top:s[0].top,bot:s[s.length-1].bot,x0:Math.min(...s.map((t=>t.x0))),x1:Math.max(...s.map((t=>t.x1)))})}}r=t}return l}(D,F,R,t))}const E=D.filter((t=>!(t.done||Mt(t.text)&&(t.top<.1*i||t.bot>.88*i)&&!(!m&&/^\d{1,2}$/.test(t.text)&&t.fsize>1.6*F)))),Z=new Set(E.flatMap((t=>t.its.filter((t=>!t.tdone))))),V=pt(E.map((t=>t.its.some((t=>t.tdone))?{...t,its:t.its.filter((t=>!t.tdone))}:t)).filter((t=>t.its.length)),R).filter((t=>t.its.some((t=>Z.has(t))))),G=[],_=[];{const t=[...V].sort(((t,e)=>t.top-e.top));for(let e=0;e<t.length;e++){const s=t[e],n=s.bot-s.top;for(let o=e+1;o<t.length&&o<e+12;o++){const e=t[o],l=e.top-s.bot;if(Math.min(s.x1,e.x1)-Math.max(s.x0,e.x0)>.5*Math.min(s.x1-s.x0,e.x1-e.x0)&&l>-.5&&l<2.5*n){_.push(Math.max(0,l));break}}}}const N=_.length>=3||m?x(_):0,J=[...B.map((t=>({...t,html:K(t)}))),...T,...C?C.paras.map((t=>({...t,para:!0}))):[]].map((t=>({tbl:t,x0:t.x0,x1:t.x1,top:t.top,bot:t.bot,its:[]})));process.env.PDFMD_DEBUG&&console.error("[pdfmd] tables",B.map((t=>`${t.src||"ruled"}@${Math.round(t.top)}-${Math.round(t.bot)}${t.openTop?"^":""}${t.openBot?"v":""}:${t.R}x${t.C}:${U(t.cells.find((t=>t.its.length))?.its||[]).slice(0,12)}`)).join(" ")),process.env.PDFMD_DEBUG&&console.error("[pdfmd] ms",F,"lg",N,"boxes",V.length,"tboxes",J.length,"regions",mt([...V,...J],F,Math.max(.45*F,1.35*N)).map((t=>`${Math.min(...t.map((t=>t.x0))).toFixed(0)}-${Math.max(...t.map((t=>t.x1))).toFixed(0)}:${t.length}`)).slice(0,8).join(" "),T.map((t=>(t.src||"?")+":"+t.html.slice(0,120))));const W=(t,e)=>{const s=t.filter((t=>!t.tbl&&!t.img));if(!s.length)return null;const n=e?s.reduce(((t,e)=>e.top<t.top?e:t)):s.reduce(((t,e)=>e.bot>t.bot?e:t)),o=s.filter((t=>Math.min(t.bot,n.bot)-Math.max(t.top,n.top)>.3*Math.min(t.bot-t.top,n.bot-n.top)&&(e?t.bot<=.1*i:t.top>=.9*i))),l=t.filter((t=>!o.includes(t)));if(!o.length||!l.length||o.length>6)return null;const r=Math.max(...o.map((t=>t.bot-t.top))),a=e?Math.min(...l.map((t=>t.top)))-Math.max(...o.map((t=>t.bot))):Math.min(...o.map((t=>t.top)))-Math.max(...l.map((t=>t.bot))),h=new Set(o.map((t=>Math.round((t.top+t.bot)/2/Math.max(3,.5*r))))).size,c=o.some((t=>o.some((e=>e!==t&&Math.min(t.bot,e.bot)-Math.max(t.top,e.top)>.3*r&&e.x0-t.x1>4*F)))),f=o.map((t=>t.its.map((t=>t.s)).join("").trim()));return(1===f.filter((t=>Mt(t))).length&&f.length>1||!m&&2===f.length&&!f.some((t=>t.length>40)))&&a>=r&&h<=2&&c?{t:o,r:l}:null},tt=t.getViewport({scale:1}).width,et=m?[]:$.filter((t=>R.some((e=>t.x0<e-10&&t.x1>e+10))&&t.x1-t.x0>=30&&t.y1-t.y0>=30&&(t.x1-t.x0)*(t.y1-t.y0)<.5*tt*i&&![...V,...J].some((e=>{const s=(e.x0+e.x1)/2,n=(e.top+e.bot)/2;return s>t.x0&&s<t.x1&&n>t.y0&&n<t.y1})))).map((t=>({img:!0,x0:t.x0,x1:t.x1,top:t.y0,bot:t.y1,its:[]})));let st=[...V,...J,...et];const ot=[],ut=[];{const t=W(st,!0);t&&(ot.push(t.t),st=t.r);const e=W(st,!1);e&&(ut.push(e.t),st=e.r)}const gt=[...b.map((t=>[{its:[t],x0:t.x0,x1:t.x1,top:t.top,bot:t.bot}])),...ot,...mt(st,F,Math.max(.45*F,1.35*N),R,!m),...ut].map((t=>t.filter((t=>!t.img)))).filter((t=>t.length)),bt=[],yt=t=>({x0:Math.min(...t.map((t=>t.x0))),x1:Math.max(...t.map((t=>t.x1))),top:Math.min(...t.map((t=>t.top))),bot:Math.max(...t.map((t=>t.bot))),sz:x(t.flatMap((t=>t.its.map((t=>t.size)))))});for(const t of gt){const e=bt[bt.length-1];if(e&&!e.some((t=>t.tbl))&&!t.some((t=>t.tbl))){const s=yt(e),n=yt(t),o=s.x0-n.x0>2&&s.x0-n.x0<=3*n.sz&&s.bot-s.top<=1.6*s.sz;if((Math.abs(s.x0-n.x0)<=2||o)&&Math.abs(s.sz-n.sz)<=.1*s.sz&&n.top>=s.bot-1&&n.top-s.bot<=.75*n.sz*1.04&&Math.min(s.x1,n.x1)-Math.max(s.x0,n.x0)>.5*Math.min(s.x1-s.x0,n.x1-n.x0)){e.push(...t);continue}}bt.push([...t])}if("3"===process.env.PDFMD_DEBUG)for(const t of bt){const e=yt(t);console.error(`[pdfmd] 영역 y${e.top.toFixed(0)}-${e.bot.toFixed(0)} x${e.x0.toFixed(0)}-${e.x1.toFixed(0)} ${t.length}개 | ${t.map((t=>t.tbl?"[표]":t.its.map((t=>t.s)).join(""))).join(" / ").slice(0,90)}`)}for(const t of bt){const e=t.filter((t=>t.tbl)),s=t.filter((t=>!t.tbl)),n=s.length?dt(s,F,N,!m):[];G.push(...[...n,...e.filter((t=>t.tbl.para)).map((t=>({kind:"p",text:t.tbl.text,grid:!0,top:t.top,bot:t.bot,x0:t.x0,fsize:t.tbl.fsize,bold:t.tbl.bold,nl:1,chars:t.tbl.text.length}))),...e.filter((t=>!t.tbl.para)).map((t=>({kind:"table",html:t.tbl.html,top:t.top,bot:t.bot,x0:t.x0,x1:t.x1,Xs:t.tbl.Xs,openTop:t.tbl.openTop,openBot:t.tbl.openBot,frag:t.tbl.frag,t:t.tbl.cells?t.tbl:null})))].sort(((t,e)=>t.top-e.top)))}const $t={};for(const t of O){const e=Math.round(2*t.size)/2;$t[e]=($t[e]||0)+t.s.length}const kt={};for(const t of p){const e=Math.round(2*t.size)/2;kt[e]=(kt[e]||0)+t.s.length}for(const t of G)t.ph=i;const At=r?function(t,e,s,n,o,l=!0){const r=t.map((t=>({...t})));for(let t=!0;t;){t=!1;for(let e=0;e<r.length&&!t;e++)for(let s=e+1;s<r.length&&!t;s++){const n=r[e],o=r[s],l=Math.min(n.x1,o.x1)-Math.max(n.x0,o.x0),a=Math.min(n.y1,o.y1)-Math.max(n.y0,o.y0);l>=-2&&a>=-2&&(l>.5*Math.min(n.x1-n.x0,o.x1-o.x0)||a>.5*Math.min(n.y1-n.y0,o.y1-o.y0))&&(r[e]={x0:Math.min(n.x0,o.x0),x1:Math.max(n.x1,o.x1),y0:Math.min(n.y0,o.y0),y1:Math.max(n.y1,o.y1)},r.splice(s,1),t=!0)}}const a=[];for(const t of r){const r=Math.max(0,t.x0),i=Math.min(n,t.x1),h=Math.max(0,t.y0),c=Math.min(o,t.y1),f=(i-r)*(c-h);if(i-r<40||c-h<20||f<(l?zt:wt)*n*o)continue;let x=0;for(const t of e){const e=(t.x0+t.x1)/2,s=(t.top+t.bot)/2;e>r&&e<i&&s>h&&s<c&&(x+=(t.x1-t.x0)*(t.bot-t.top))}if(x>vt*f)continue;const p=t=>Math.min(i,t.x1??n)-Math.max(r,t.x0??0)>0,m=t=>t.top<c&&t.bot>h&&(t.x0??0)>=i-2,u=s.find((t=>t.top>=h-2&&p(t)||m(t)))||s.find((t=>t.top>=c-2))||null;a.push({box:[r,h,i,c].map((t=>Math.round(10*t)/10)),before:u})}return a.sort(((t,e)=>t.box[1]-e.box[1]||t.box[0]-e.box[0]))}($,p,G,tt,i,m):[],jt={};for(const t of p){const e=String(t.font||"").replace(/^[A-Z]{6}\+/,"");if(!e)continue;const s=e+"|"+Math.round(2*t.size)/2;jt[s]=(jt[s]||0)+t.s.replace(/\s/g,"").length}return{blocks:G,sizes:$t,allSizes:kt,fonts:jt,chars:p.reduce(((t,e)=>t+e.s.replace(/\s/g,"").length),0),hangul:m,imgs:At}}const zt=.05,wt=.008,vt=.08;function $t(t,e){const s=S([...t.Xs,...e.Xs],3),n=t=>{let e=0;for(let n=1;n<s.length;n++)Math.abs(s[n]-t)<Math.abs(s[e]-t)&&(e=n);return e},o=t=>({...t,c0:n(t.x0),c1:Math.max(n(t.x0),n(t.x1)-1)}),l=t.cells.map(o),r=Math.max(...l.map((t=>t.r1)))+1,a=Math.max(0,...l.flatMap((t=>t.its.map((t=>t.bot)))))+1e3;let i=e.cells.map(o).map((t=>({...t,its:t.its.map((t=>({...t,top:t.top+a,bot:t.bot+a,base:t.base+a})))})));const h=(t,e)=>t.filter((t=>t.r0===e)).sort(((t,e)=>t.c0-e.c0)).map((t=>`${t.c0}-${t.c1}:${U(t.its)}`)).join("|");i.some((t=>0===t.r0))&&i.filter((t=>0===t.r0)).every((t=>0===t.r1))&&h(i,0)===h(l,0)&&/[^|:\d-]/.test(h(i,0))&&(i=i.filter((t=>t.r0>0)).map((t=>({...t,r0:t.r0-1,r1:t.r1-1}))));let c=r;const f=l.filter((t=>t.r1===r-1)),x=i.filter((t=>0===t.r0&&!(t.hole&&!t.its.length))),p=t=>{const e=new Set;for(const s of t)if(s.its.length)for(let t=s.c0;t<=s.c1;t++)e.add(t);return e},m=p(f),u=p(x),g=u.size>0&&u.size<=.5*(s.length-1)&&[...u].every((t=>m.has(t)))&&(u.size<m.size||e.openTop),b=[...m].some((t=>!u.has(t))),M=[...u].some((t=>!m.has(t))),d=x.find((t=>0===t.c0)),y=!!d&&/^([가나다라마바사아자차카타파하]\.|\d{1,2}[.)]|[①-⑳])\s?/.test(U(d.its));if((e.holeTop||t.openBot&&e.openTop||!y&&(g||e.openTop&&b||b&&M)||f.some((t=>0===t.c0&&t.its.length))&&!x.some((t=>0===t.c0&&t.its.length)))&&i.length&&x.length&&x.every((t=>f.some((e=>e.c0===t.c0&&e.c1===t.c1))))){for(const t of x){const e=f.find((e=>e.c0===t.c0&&e.c1===t.c1));e.its=[...e.its,...t.its],e.r1=r-1+t.r1,t.drop=!0}for(const t of i)0===t.r0&&t.hole&&!t.its.length&&(t.drop=!0);c=r-1}i=i.filter((t=>!(t.drop||t.hole&&!t.its.length))).map((t=>({...t,r0:t.r0+c,r1:t.r1+c})));const z=[...l,...i],w=Math.max(...z.map((t=>t.r1)))+1,v=s.length-1;for(let t=r;t<w;t++)for(let e=0;e<v;e++){if(z.some((s=>s.r0<=t&&s.r1>=t&&s.c0<=e&&s.c1>=e)))continue;const n=z.find((s=>s.r1===t-1&&s.c0<=e&&s.c1>=e));n&&!z.some((e=>e!==n&&e.r0<=t&&e.r1>=t&&e.c0<=n.c1&&e.c1>=n.c0))?n.r1=t:z.push({r0:t,r1:t,c0:e,c1:e,its:[],x0:s[e],x1:s[e+1]})}return{...t,cells:z,R:w,C:v,Xs:s,x0:Math.min(t.x0,e.x0),x1:Math.max(t.x1,e.x1),openBot:e.openBot}}function kt(t,e){const s=t=>[...t.matchAll(/<td([^>]*)>(.*?)<\/td>/g)].map((t=>({attr:t[1],t:t[2]}))),n=s(t),o=s(e);return n.length!==o.length||n.some(((t,e)=>t.attr.replace(/rowspan="\d+"/,"")!==o[e].attr.replace(/rowspan="\d+"/,"")))?null:"<tr>"+n.map(((t,e)=>`<td${t.attr}>${[t.t,o[e].t].filter(Boolean).join(" ")}</td>`)).join("")+"</tr>"}export async function pdfBlocksDebug(t){const e=await f(),s=await e.getDocument({data:new Uint8Array(t),isEvalSupported:!1,disableFontFace:!0,verbosity:0}).promise;try{const t=await s.getPage(1);return await yt(t,e)}finally{await s.destroy()}}export async function pdfMarkdown(e,{maxPages:l=400,ocrSlots:i=!1,imageSlots:c=!1,literal:x=!1,deadline:p=0}={}){const m=await f(),u=await m.getDocument({data:new Uint8Array(e),cMapUrl:t.join(h,"cmaps")+"/",cMapPacked:!0,standardFontDataUrl:t.join(h,"standard_fonts")+"/",disableFontFace:!0,isEvalSupported:!1,useSystemFonts:!1,verbosity:0,fontExtraProperties:!0}).promise;try{const t=[],h={},f=[],g={},b=[],M={};let d=!1;try{const t=await u.getMetadata();d=/hancom|hwp|한글|한컴/i.test(`${t.info&&t.info.Producer||""} ${t.info&&t.info.Creator||""}`)}catch{}const y=new Map,w=new Map;let v=null;if(d)for(let t=1;t<=Math.min(u.numPages,l,60)&&!(p&&Date.now()>p);t++){await new Promise((t=>setImmediate(t)));const e=await u.getPage(t),s=await e.getTextContent();w.set(t,s);for(const t of xt(z(s,e.getViewport({scale:1}).transform,m.Util,(()=>""))))for(const e of q(t))H(y,e)}const $=1e6+8*e.length;let k=0,A=null;for(let e=1;e<=Math.min(u.numPages,l);e++){if(p&&Date.now()>p){v=e-1;break}if(k>$){A=e-1;break}await new Promise((t=>setImmediate(t)));const s=await u.getPage(e),n=s.getOperatorList.bind(s);s.getOperatorList=async(...t)=>{const e=await n(...t);return k+=e&&e.fnArray?e.fnArray.length:0,e};const o=await yt(s,m,{korean:d,tc:w.get(e),jst:y,images:c});w.delete(e),s.cleanup(),o.hangul&&(d=!0),b.push(o.imgs||[]),t.push(o.blocks),f.push(o.chars||0);for(const[t,e]of Object.entries(o.fonts||{}))M[t]=(M[t]||0)+e;for(const[t,e]of Object.entries(o.sizes))h[t]=(h[t]||0)+e;for(const[t,e]of Object.entries(o.allSizes||{}))g[t]=(g[t]||0)+e}const j={};for(const e of t)for(const t of e)"p"===t.kind&&t.nl>=2&&!(t.ph&&t.top>.8*t.ph)&&(j[t.fsize]=(j[t.fsize]||0)+t.chars);const X=t=>+(Object.entries(t).sort(((t,e)=>e[1]-t[1]))[0]||[0])[0];let S=X(j)||X(h)||10;{const t=Object.values(j).reduce(((t,e)=>t+e),0),e=Object.values(g).reduce(((t,e)=>t+e),0),s=X(g);e&&t<.3*e&&t<150&&s&&S>=1.6*s&&(S=s)}{const e={},s={};for(const n of t)for(const t of n)"p"===t.kind&&t.chars>=20&&!(t.ph&&t.top>.8*t.ph)&&(e[t.fsize]=(e[t.fsize]||0)+1,t.nl>=2&&(s[t.fsize]=1));const n=X(e);n>S&&(e[n]||0)>=3*Math.max(1,e[S]||0)&&s[n]&&(S=n)}{const e=t.flat().filter((t=>"p"===t.kind&&t.text.trim())),s=e.filter((t=>t.fsize>=1.15*S));if(e.length>4&&s.length>.4*e.length&&s.filter((t=>t.nl>=2&&t.chars>=50)).length>=2){const t={};for(const e of s)t[e.fsize]=(t[e.fsize]||0)+e.chars;S=X(t)||S}}process.env.PDFMD_DEBUG&&console.error("[pdfmd] body",S,"ptally",JSON.stringify(j),"tally",JSON.stringify(h)),L=y.size?y:null,function(t){const e=(t,e)=>"p"===t.kind&&t.ph&&(e?t.top>.88*t.ph:t.bot<.12*t.ph)&&t.text.length<=80,s=t=>t.match(/<tr>.*?<\/tr>/g)||[];let n=null;for(let o=1;o<t.length;o++){const l=t[o-1],r=t[o];let a=l.length-1;for(;a>=0&&e(l[a],!0);)a--;let i=0;for(;i<r.length&&e(r[i],!1);)i++;const h=a>=0?l[a]:n,c=r[i];if(n=null,!(h&&c&&"table"===h.kind&&"table"===c.kind&&h.Xs&&c.Xs))continue;if(h.t&&c.t&&("clip"===h.t.src||"clip"===c.t.src)){const[t,s]=h.Xs.length<=c.Xs.length?[h.Xs,c.Xs]:[c.Xs,h.Xs];if(Math.abs(h.Xs[h.Xs.length-1]-c.Xs[c.Xs.length-1])>3&&Math.abs(h.Xs[0]-c.Xs[0])>3||!t.every((t=>s.some((e=>Math.abs(t-e)<=3)))))continue;const o=t=>t.cells.filter((t=>0===t.r0)).sort(((t,e)=>t.x0-e.x0)).map((t=>U(t.its))).join("|"),l=h.Xs.length===c.Xs.length&&h.Xs.every(((t,e)=>Math.abs(t-c.Xs[e])<=3)),a=t=>new Set(t.cells.filter((t=>t.its.length)).map((t=>t.r0))).size;if(!h.openBot&&!c.t.holeTop&&h.ph&&h.bot<.85*h.ph&&!(l&&a(c.t)>=2&&/[^|\s]/.test(o(c.t))&&o(h.t)===o(c.t)))continue;const f=$t(h.t,c.t);h.t=f,h.html=K(f),h.Xs=f.Xs,h.openBot=f.openBot,h.bot=c.bot,h.frag=!1,r.splice(i,1),r.some((t=>!e(t,!0)&&!e(t,!1)))||(n=h);continue}if(h.Xs.length!==c.Xs.length||!h.html.startsWith("<table")||!c.html.startsWith("<table"))continue;if(!h.Xs.every(((t,e)=>Math.abs(t-c.Xs[e])<=3)))continue;const f=s(h.html),x=s(c.html);if(x.length&&f.length&&x[0]===f[0]&&x.shift(),h.openBot&&c.openTop&&f.length&&x.length){const t=kt(f[f.length-1],x[0]);t&&(f[f.length-1]=t,x.shift())}h.html="<table>"+[...f,...x].join("")+"</table>",h.openBot=c.openBot,h.frag=!1,r.splice(i,1),r.some((t=>!e(t,!0)&&!e(t,!1)))||(n=h)}for(const e of t)for(let t=0;t<e.length;t++){const s=e[t];if("table"!==s.kind||!s.frag||!s.t)continue;const n=s.t.cells.filter((t=>t.its.length)).sort(((t,e)=>t.r0-e.r0||t.c0-e.c0)).map((t=>U(t.its))).join(" ");e[t]={kind:"p",text:n,grid:!0,top:s.top,bot:s.bot,x0:s.x0,fsize:0,bold:!1,nl:1,chars:n.length,ph:s.ph}}}(t);const C={};if(d)for(const e of t)for(const t of e)"p"!==t.kind||t.grid||(C[t.fsize]=(C[t.fsize]||0)+t.chars);const B=d?+(Object.entries(C).sort(((t,e)=>e[1]-t[1]))[0]||[0])[0]:0,O=[],F=x?[]:null,D=r,T=(t,e=t)=>{O.push(t),F&&F.push(e)};for(const[e,l]of t.entries()){i&&f[e]<20&&T(`\x3c!-- ocr:${e+1} --\x3e`);const t=t=>/(\.{3,}|…{2,}|\s)\s*([ivxlc]+|\d{1,4})$/i.test(t),r=l.filter((e=>"p"===e.kind&&t(e.text))).length>=3;let a=!1;for(const t of l)"p"===t.kind&&/^(table of contents|contents|목\s*차|차\s*례)$/i.test(t.text.trim())&&(t.isTocHead=!0);let h=null;const c=(e,s=!1)=>{if("p"!==e.kind)return!1;const n=e.text.trim();if(!s&&/^\d{1,2}$/.test(n)&&1===e.nl&&e.fsize>=2*S)return!0;if(!n||e.nl>3||n.length>160||/^[\d\s.,%()-]+$/.test(n)||r&&t(n))return!1;if(/^(chapter|part|section|appendix|annex|unit|lesson|module)\s+([\dIVXLC]+|[A-Z])\.?$/i.test(n)||/^제\s*\d+\s*[장편부]$/.test(n))return!0;if(ut.test(n)||/[\u0000-\u001f]/.test(n))return!1;if((n.match(/[A-Za-z가-힣]/g)||[]).length<3&&!(e.fsize>=2*S&&1===e.nl&&n.length<=12&&/\d/.test(n)))return!1;if(e.ph&&e.top<.06*e.ph&&1===e.nl&&!e.bold&&e.fsize<=1.6*S)return!1;if(e.ph&&e.top<.075*e.ph&&1===e.nl&&e.fsize<=1.3*S&&(!/^(\d{1,2}(\.\d+)*\.?|[IVX]+\.)\s+\S/.test(n)||!e.bold&&e.fsize<=1.05*S))return!1;if(e.pnum&&e.ph&&(e.top<.1*e.ph||e.top>.85*e.ph))return!1;if(e.ph&&e.top<.08*e.ph&&1===e.nl&&!e.bold&&e.next&&"p"===e.next.kind&&e.next.fsize>=1.3*e.fsize)return!1;if(!s&&1===e.nl&&!e.bold&&/^(chapter|part|section|appendix|unit|lesson|module)\b/i.test(n.replace(/(?<=\b[A-Z]{1,3}) (?=[A-Z])/g,""))&&e.next&&"p"===e.next.kind&&e.next.fsize>=1.1*e.fsize&&e.next.top-e.bot<=3*e.fsize&&!e.next.bold==!e.bold)return!1;if(e.wide&&!e.pnum)return!1;if(e.ph&&e.top>.9*e.ph&&1===e.nl&&e.fsize<=1.05*S)return!1;if((n.match(/\(/g)||[]).length!==(n.match(/\)/g)||[]).length)return!1;if(/^((jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\.?\s+(\d{1,2},?\s+)?\d{4}|\d{4}[.\-/]\s?\d{1,2}([.\-/]\s?\d{1,2})?\.?)$/i.test(n))return!1;if(/-$/.test(n)||/[∗†‡§]/.test(n)&&(/,/.test(n)||(n.match(/[∗†‡§]/g)||[]).length>=2)||(n.match(/,/g)||[]).length>=3&&n.length>40)return!1;if(a&&!e.isTocHead)return!1;if(/^[*∗†‡]\s*\S/.test(n)&&!/^\*\*/.test(n))return!1;if(!s&&e.next&&"p"===e.next.kind&&e.next.nl>=2&&/^[a-z]/.test(e.next.text.trim())&&Math.abs(e.next.fsize-e.fsize)<=.05*e.fsize&&e.next.bold===e.bold&&e.next.top-e.bot<=.9*e.fsize&&e.next.top-e.bot>=-.3*e.fsize)return!1;const o=(n.match(/[A-Za-z]/g)||[]).length,l=(n.match(/[A-Za-z가-힣]/g)||[]).length;if(/^(fig(ure)?|table|tab\.|chart|source|sources|note|notes|photo|image|그림|표|출처|자료|주)\s*[\d.:]/i.test(n))return!1;if(!s&&/^[a-z]/.test(n))return!1;const i=e.next;if(!(i&&i.fsize===e.fsize&&i.bold===e.bold&&i.top-e.bot<=.9*e.fsize)&&/\s(the|a|an|of|to|in|and|or|for|with|on|at|by|from|as|that|which|is|are)$/i.test(n)&&n.split(/\s+/).length>=4)return!1;if(n.length<=90&&/[A-Z]{3}/.test(n)&&n===n.toUpperCase()&&o>=.8*l&&n.split(/\s+/).length>=2&&!/[.,;]$/.test(n)&&e.fsize>=.97*S&&e.nl<=2)return!0;const c=e.fsize/S;if(!s&&!e.bold&&c<1.5&&e.nb){const t=[...e.nb.prev,...e.nb.next],s=e.nb.prev[e.nb.prev.length-1];if(t.length>=4&&s&&"p"===s.kind&&e.top-s.bot>=-1&&e.top-s.bot<=1*e.fsize&&Math.min(s.x1,e.x1)-Math.max(s.x0,e.x0)>0&&t.filter((t=>"p"===t.kind&&t.text.trim().split(/\s+/).length<=3&&t.text.trim().length<=20)).length>=3)return!1}if(c>=1.15)return n.length<=160;if(c>=1.07&&(e.bold||n.length<=80)&&!/[.;]$/.test(n))return!0;if(e.bold&&c>=.95&&n.length<=110&&!/[.,;]$/.test(n)&&!(/:$/.test(n)&&n.length>50))return!0;const f=e.next,x=/^(a|an|the|and|or|of|in|on|at|to|for|by|with|vs\.?|from)$/i;return!!(!s&&1===e.nl&&n.length<=60&&n.split(/\s+/).length<=6&&!/[.,;:!?]$/.test(n)&&n.split(/\s+/).every((t=>x.test(t)||/^[A-Z0-9“"‘'(]/.test(t)))&&/[A-Z][a-z]/.test(n)&&f&&"p"===f.kind&&f.nl>=2&&Math.abs(f.fsize-e.fsize)<=.05*e.fsize&&f.top-e.bot>=1.2*e.fsize&&f.top-e.bot<=4*e.fsize&&Math.abs(f.x0-e.x0)<=1.5*e.fsize)||!!(!s&&1===e.nl&&n.split(/\s+/).length<=5&&!/[.,;:!?]$/.test(n)&&/[A-Za-z]{3}/.test(n)&&f&&"p"===f.kind&&f.fsize>=1.25*e.fsize&&f.nl<=2&&f.chars<=120&&Math.abs(f.x0-e.x0)<=1.5*e.fsize&&f.top-e.bot>=-1&&f.top-e.bot<=2*e.fsize)||!!(!s&&e.bold&&h&&e.nl<=2&&n.length<=60&&!/[.,;:!?]$/.test(n)&&/[A-Z][a-z]/.test(n)&&h.some((t=>t!==e&&t.fsize===e.fsize&&Math.abs(t.x0-e.x0)<=.5*e.fsize&&t.nl<=2)))||!s&&e.bold&&e.nl<=2&&n.length<=60&&!/[.,;:]$/.test(n)&&!!f&&"p"===f.kind&&!f.bold&&f.fsize<=1.15*e.fsize&&f.fsize>=.7*e.fsize&&Math.abs(f.x0-e.x0)<=2*e.fsize&&f.top-e.bot>=0&&f.top-e.bot<=2.5*e.fsize&&(f.text||"").length>=10};for(let t=0;t<l.length;t++)"p"===l[t].kind&&(l[t].next=l.slice(t+1).find((t=>"p"===t.kind)));for(let t=0;t<l.length;t++)"p"===l[t].kind&&(l[t].nb={prev:l.slice(Math.max(0,t-2),t),next:l.slice(t+1,t+3)});h=l.filter((t=>"p"===t.kind&&t.bold&&t.nl<=2&&(t.text||"").trim().length<=60&&c(t)));const x=b[e]||[],p=t=>x.forEach(((s,n)=>{s.before!==t||s.done||(s.done=!0,T(`\x3c!-- img:${e+1}:${n} --\x3e`))}));for(let t=0;t<l.length;t++){const r=l[t];if(x.length&&p(r),"table"===r.kind){T(r.html);continue}let i=s(r.text).trim();if(i)if("5"===process.env.PDFMD_DEBUG&&console.error(`[blk] p${e+1} fs${r.fsize} body${S} b${r.bold?1:0} nl${r.nl} top${Math.round(r.top)}/${Math.round(r.ph||0)} x${Math.round(r.x0)} head${c(r)?1:0} ${i.slice(0,60)}`),d){if(r.grid){T(r.stext?s(n(r.stext,{cell:!0})).trim():i,F&&(r.stext?s(n(D(r.stext),{cell:!0})).trim():D(i)));continue}const t=o(i,r.fsize,B);if(t){T("#".repeat(t)+" "+i,F&&"#".repeat(t)+" "+D(i));continue}let e=String(r.stext||r.text),l=F&&D(e);gt.test(i)&&(e=e.replace(/^([\uFDD0-\uFDD5]*)[•‣⁃]\s*/,"- $1"),F&&(l=l.replace(/^([\uFDD0-\uFDD5]*)[•‣⁃]\s*/,"- $1"))),T(s(n(e)).trim(),F&&s(n(l)).trim())}else if(r.isTocHead)T("# "+i,F&&"# "+D(i)),a=!0;else if(c(r)){(/^([IVXLC]+|\d{1,2})\.$/.test(i)||/^\d{1,2}$/.test(i)&&r.fsize>=2*S&&t+1<l.length&&Math.abs(l[t+1].x0-r.x0)<=.3*r.fsize)&&t+1<l.length&&c(l[t+1])&&l[t+1].top-r.bot<=2.5*r.fsize&&(i+=" "+s(l[t+1].text).trim(),r.bot=l[t+1].bot,t++);const e=t=>{const e=t.text.trim();return/[A-Z]{2}/.test(e)&&e===e.toUpperCase()&&!/[가-힣]/.test(e)},n=t=>e(r)&&e(t)&&t.top-r.bot<=.6*Math.min(r.fsize,t.fsize)&&t.top>=r.top&&Math.min(t.x1,r.x1)-Math.max(t.x0,r.x0)>.3*Math.min(t.x1-t.x0,r.x1-r.x0);for(;;){const s=l[t+1],n=l[t+2];if(!s||!n||"p"!==s.kind||!/^(&|\+|and|or|\/)$/i.test(s.text.trim())||!c(n,!0)||!e(r)||!e(n)||n.top-r.bot>2.5*Math.min(r.fsize,n.fsize)||s.top<r.top||n.top<s.top)break;i+=" "+s.text.trim()+" "+n.text.trim(),r.bot=n.bot,t+=2}for(;t+1<l.length&&c(l[t+1],!0)&&(l[t+1].fsize===r.fsize&&l[t+1].bold===r.bold&&l[t+1].top-r.bot<=1*r.fsize&&l[t+1].top-r.bot>=-.3*r.fsize||n(l[t+1]))&&!/^(\d{1,2}(\.\d+)*\.?|[IVX]+\.|[A-Z]\.)\s/.test(l[t+1].text);)i+=" "+l[t+1].text.trim(),r.bot=l[t+1].bot,t++;T("# "+i,F&&"# "+D(i))}else if(gt.test(i)){const t=i.replace(gt,"");T("- "+t,F&&"- "+D(t))}else T(i,F&&D(i))}x.forEach(((t,s)=>{t.done||T(`\x3c!-- img:${e+1}:${s} --\x3e`)}))}const R={};b.forEach(((t,e)=>{t.length&&(R[e+1]=t.map((t=>t.box)))}));const E={},P={},Z={};for(const[t,e]of Object.entries(M)){const s=t.lastIndexOf("|"),n=t.slice(0,s),o=+t.slice(s+1);E[n]=(E[n]||0)+e,Math.abs(o-S)<=.5&&(P[n]=(P[n]||0)+e),o>=1.3*S&&!/^Type3$/i.test(n)&&(Z[n]=(Z[n]||0)+e)}const Y=Object.entries(E).sort(((t,e)=>e[1]-t[1])).slice(0,6).map((([t,e])=>({name:t,chars:e}))),I=(Object.entries(P).sort(((t,e)=>e[1]-t[1]))[0]||[Y[0]?Y[0].name:""])[0],V=(Object.entries(Z).sort(((t,e)=>e[1]-t[1]))[0]||[""])[0],G=Object.values(P).reduce(((t,e)=>t+e),0),_=Object.entries(P).filter((([t])=>!/^Type3$/i.test(t))).sort(((t,e)=>e[1]-t[1]))[0],N={body:{name:I||"",size:S,..._&&_[1]>=.2*G?{alt:_[0]}:{}},top:Y,...V?{head:{name:V}}:{}},J=null!=A?`\n\n(PDF 글 읽기가 읽을 양 한도에 걸려 앞 ${A}쪽(전체 ${u.numPages}쪽)만 읽었어요 — 나머지 쪽 글은 빠졌어요. 쪽을 나눠 다시 해 주세요)`:"";return{pages:u.numPages,markdown:O.join("\n\n")+J,pageChars:f,fonts:N,...c?{images:R}:{},...F?{literal:a(F.join("\n\n"))+J}:{},...null!=v?{cut:v}:{},...null!=A?{workCut:A}:{}}}finally{await u.destroy()}}export const _dbg={fillGrids:Z,fillTables:Y,gutters:it,splitAt:ht,itemsOf:z,linesOfOps:k,ruledTables:P,gridOf:B,virtualRows:F,textTable:lt,cellsOfLine:Q,ruleOnlyTables:at,toLines:xt,fragments:pt,xycut:mt,paragraphs:dt,statSegs:q,joinStats:H,joinBy:J};
2
+ import t from"path";import{fileURLToPath as e}from"url";import{tidy as s,styled as n,headingLevel as o,MK as l,litMark as r,litResolve as a}from"./ontext_table.js";const i=t.resolve(t.dirname(e(import.meta.url)),".."),h=t.join(i,"node_modules","pdfjs-dist");let c=null;const f=()=>c||=import("pdfjs-dist/legacy/build/pdf.mjs"),x=t=>{if(!t.length)return 0;const e=[...t].sort(((t,e)=>t-e));return e[e.length>>1]},p=/bold|black|heavy|semibold|semibd|demibold|demi\b|extrab|ultrab|[-,]b$|-sb$|-hv$|_bd$|[-_]bd\b|cmbx|cmssbx|cmb\d|\bbx\d|-medi(ital)?$/i,m=t=>("2"===process.env.PDFMD_DEBUG&&console.error("[pdfmd] 표 아님",t,(new Error).stack.split("\n")[3].trim().slice(0,60)),null),u=t=>String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),g={108:"●",109:"❍",110:"■",111:"□",113:"❑",117:"◆",118:"❖",119:"⬥",158:"·",159:"•",167:"▪",168:"◻",216:"➢",231:"⬅",232:"➔",233:"⬆",234:"⬇",252:"✔",140:"❶",141:"❷",142:"❸",143:"❹",144:"❺"},b={"Œ":140,"Ž":142,"ž":158,"Ÿ":159},M=t=>[...t].map((t=>{let e=b[t]??t.codePointAt(0);return e>=61440&&e<=61695&&(e-=61440),g[e]||t})).join(""),d={zero:"0",one:"1",two:"2",three:"3",four:"4",five:"5",six:"6",seven:"7",eight:"8",nine:"9",hyphen:"-",period:".",comma:",",colon:":",semicolon:";",ampersand:"&",quoteright:"’",quoteleft:"‘",quotedblleft:"“",quotedblright:"”",parenleft:"(",parenright:")",slash:"/",endash:"–",emdash:"—",exclam:"!",question:"?",percent:"%",dollar:"$",space:" "},y=t=>{if(!t||"string"!=typeof t)return null;const e=t.split(".")[0].split("_").map((t=>1===t.length?t:d[t]??(/^uni[0-9A-F]{4}$/.test(t)?String.fromCharCode(parseInt(t.slice(3),16)):null)));if(!e.length||!e.every((t=>null!=t&&""!==t)))return null;const s=e.join("");return/\.(sc|smcp|c2sc)$/i.test(t)?s.toUpperCase():s};function z(t,e,s,n,o=null,l=null){const r=[],a=[];let i=null;for(const[h,c]of t.items.entries()){if(!c.str||!c.str.trim()){if(c.str&&r.length){const t=s.transform(e,c.transform);if(i={w:Math.abs(c.width),x0:t[4],prev:r[r.length-1],g:c.fontName+"|"+Math.round(Math.hypot(t[2],t[3]))},i.w>1.5*(Math.hypot(t[2],t[3])||10)*Math.max(1,c.str.length)){i=null;continue}i.prev.sp="real",i.prev.ws=i}continue}const t=s.transform(e,c.transform),f=Math.hypot(t[2],t[3])||Math.abs(c.height)||10,x=Math.hypot(t[0],t[1]);if(!x||Math.abs(t[1])>.08*Math.abs(t[0])||t[0]<0){if(x&&Math.abs(t[0])<=.08*x&&c.str.trim()&&Math.abs(c.width)>0){const e=Math.hypot(t[2],t[3])||10,s=t[1]/x,o=t[2]/e,l=Math.abs(c.width),r=t[4],i=t[5],h=[r,r+.8*o*e,r-.2*o*e],f=[i,i+s*l];a.push({s:c.str.replace(/\s+/g," ").trim(),x0:Math.min(...h),x1:Math.max(...h),top:Math.min(...f),bot:Math.max(...f),base:Math.max(...f),size:e,rot:!0,bold:p.test(n(c.fontName)),font:n(c.fontName),i:-1})}i=null;continue}const m=c.width,u=t[4],g=t[5];let b=c.str;if(l&&/[\u0000-\u0008\u000e-\u001f]/.test(b)){const t=l(c.fontName);t&&(b=[...b].map((e=>{const s=e.charCodeAt(0);return s>=32||9===s||10===s||13===s?e:y(t[s])??e})).join(""))}if(/^(?:\S )+\S$/.test(b.trim())&&/[가-힣]/.test(b)){const t=b.trim().split(" "),e=t.reduce(((t,e)=>t+(/[가-힣ㆍ]/.test(e)?1:/[0-9]/.test(e)?.55:.5)),0)*f;(Math.abs(m)-e)/(t.length-1)<.2*f&&(b=t.join(""))}const d=n(c.fontName),z={s:(/wingdings(?![-\s]?[23])/i.test(d)?M(b):b).replace(/(^|[^\u1100-\u115f])\u119e/g,"$1ㆍ").replace(/^(?:[A-Z0-9] ){2,}[A-Z0-9?!.:]$/,(t=>t.replace(/ /g,""))).replace(/\s+/g," ").replace(/\.(?: \.){2,}/g,(t=>t.replace(/ /g,""))),x0:u,x1:u+Math.max(m,.1),base:g,size:f,top:g-.82*f,bot:g+.22*f,bold:p.test(d)||!(!o||!o.has(h)),font:d,i:r.length};i&&(Math.abs(g-i.prev.base)<=.3*f&&i.x0>=i.prev.x1-1&&i.x0<=u+1&&(i.next=z),i=null),r.push(z)}{const t=t=>t&&1===t.s.length&&/[^\p{L}\p{N}]/u.test(t.s),e={};for(const s of r){const n=s.ws;n&&n.next&&!t(s)&&!t(n.next)&&n.w<=s.size&&(e[n.g]||=[]).push(n.w)}for(const s of r){const n=s.ws;if(!n||!n.next)continue;const o=n.next.x0-s.x1,l=e[n.g]||[];o>0&&/[.:;,!?)]$/.test(s.s)&&/^[A-Za-z]{2}/.test(n.next.s)||((o<=0||n.w>=.5*o)&&n.w<.25*s.size&&(t(s)||t(n.next))&&(l.length<2||n.w<.75*x(l))||o<=0&&(t(s)||t(n.next)))&&(s.sp="fake")}for(const t of r)delete t.ws}{const t=x(r.map((t=>t.size)));for(const e of r){if(!/^[A-Z]$/.test(e.s)||e.size<2.5*t)continue;const s=r.filter((s=>s!==e&&s.x0>=e.x1-2&&s.x0<=e.x1+1.5*t&&s.top>=e.top-.5*t&&s.top<=e.bot&&s.size<.5*e.size));if(!s.length)continue;const n=s.reduce(((t,e)=>e.top<t.top-1||Math.abs(e.top-t.top)<=1&&e.x0<t.x0?e:t));Object.assign(e,{x0:n.x0-.6*n.size,x1:n.x0,base:n.base,size:n.size,top:n.top,bot:n.bot,sp:void 0})}}const h=new Map,c=(t,e,s)=>t+"\0"+e+","+s,f=r.filter((t=>{const e=Math.floor(t.x0/1.5),s=Math.floor(t.base/1.5);for(let n=-1;n<=1;n++)for(let o=-1;o<=1;o++){const l=h.get(c(t.s,e+n,s+o));if(l&&l.some((e=>Math.abs(e.x0-t.x0)<=1.5&&Math.abs(e.base-t.base)<=1.5&&Math.abs(e.size-t.size)<=.5)))return!1}const n=c(t.s,e,s),o=h.get(n);return o?o.push(t):h.set(n,[t]),!0})),m=new Map,u=t=>Math.round(2*t);for(const t of f)if(t.s.length>1){const e=u(t.base),s=m.get(e);s?s.push(t):m.set(e,[t])}const g=m.size?f.filter((t=>!(t=>{const e=t.s.trim();if(!e||e.length>3)return!1;for(let s=-1;s<=1;s++)for(const n of m.get(u(t.base)+s)||[])if(!(n===t||n.s.trim().length<=e.length||Math.abs(n.base-t.base)>.5||Math.abs(n.size-t.size)>.5)&&(n.s.trimEnd().endsWith(e)&&Math.abs(n.x1-t.x1)<=.5&&t.x0>=n.x0||n.s.trimStart().startsWith(e)&&Math.abs(n.x0-t.x0)<=.5&&t.x1<=n.x1))return!0;return!1})(t))):f;return g.rot=a,g}const w={onequarter:"=",thorn:"+",eth:"(",Thorn:")",onehalf:"[",C138:"]",C0:"−",C1:"·",C2:"×"},v=(t,e,s,n)=>{const o=String(t||"").replace(/^[A-Z]{6}\+/,"");return/^TeXCMMathsSymbols\b/.test(o)?s&&w[s]||null:/^TeXCMMathsItalic\b/.test(o)&&!s?58===e&&":"===n?".":59===e&&";"===n?",":null:null},$=t=>{if(null==t)return null;if("string"==typeof t[0])return t[0].toLowerCase();if(t.length>=3&&"number"==typeof t[0]){const e=ArrayBuffer.isView(t);return"#"+Array.from(t).slice(0,3).map((t=>Math.max(0,Math.min(255,Math.round(e||t>1?t:255*t))).toString(16).padStart(2,"0"))).join("")}return null};function k(t,e,s,n,o=!1){let l=[1,0,0,1,0,0],r=1,a="#000000",i="#000000",h=null,c=1;const f=[],x=[],p=[],m=[],u=[],g=[],b=(t,e)=>s.applyTransform(s.applyTransform([t,e],l),n),M=[],d=(t,e,s)=>{const n=Math.abs(t[0]-e[0]),l=Math.abs(t[1]-e[1]);l<=1&&n>=2?x.push({y:(t[1]+e[1])/2,x0:Math.min(t[0],e[0]),x1:Math.max(t[0],e[0]),w:s}):n<=1&&l>=2?p.push({x:(t[0]+e[0])/2,y0:Math.min(t[1],e[1]),y1:Math.max(t[1],e[1]),w:s}):o&&Math.max(n,l)>=.1&&Math.min(n,l)<=.3&&M.push(n>=l?{h:1,y:(t[1]+e[1])/2,a0:Math.min(t[0],e[0]),a1:Math.max(t[0],e[0]),w:s}:{h:0,x:(t[0]+e[0])/2,a0:Math.min(t[1],e[1]),a1:Math.max(t[1],e[1]),w:s})},y=t=>{if(h){for(const e of h)if(e.rect){const[s,n,o,l]=e.rect,a=b(s,n),h=b(s+o,n+l),f=Math.min(a[0],h[0]),x=Math.max(a[0],h[0]),p=Math.min(a[1],h[1]),u=Math.max(a[1],h[1]),g=x-f,M=u-p;"stroke"!==t&&Math.min(g,M)<=2.5?g>=M?d([f,(p+u)/2],[x,(p+u)/2],M):d([(f+x)/2,p],[(f+x)/2,u],g):"fill"!==t&&(d([f,p],[x,p],r),d([f,u],[x,u],r),d([f,p],[f,u],r),d([x,p],[x,u],r)),"stroke"!==t&&Math.min(g,M)>2.5&&c>.05&&m.push({x0:f,x1:x,y0:p,y1:u,col:i})}else if("fill"!==t){if("both"===t){const t=j(e);t&&c>.05&&m.push({...t,col:i})}for(let t=1;t<e.pts.length;t++)e.curve[t]||d(e.pts[t-1],e.pts[t],r*(Math.sqrt(Math.abs(l[0]*l[3]-l[1]*l[2]))||1))}else{const t=j(e);t&&c>.05&&m.push({...t,col:i})}h=null}};for(let n=0;n<t.fnArray.length;n++){const o=t.fnArray[n],x=t.argsArray[n];switch(o){case e.save:f.push([l,r,a,i,c]);break;case e.restore:f.length&&([l,r,a,i,c]=f.pop());break;case e.transform:l=s.transform(l,x);break;case e.paintFormXObjectBegin:f.push([l,r,a,i,c]),x&&Array.isArray(x[0])&&6===x[0].length&&(l=s.transform(l,x[0]));break;case e.paintFormXObjectEnd:f.length&&([l,r,a,i,c]=f.pop());break;case e.setGState:for(const[t,e]of x&&x[0]||[])"ca"===t&&"number"==typeof e&&(c=e);break;case e.setLineWidth:r=x[0];break;case e.setStrokeRGBColor:a=$(x)||a;break;case e.setFillRGBColor:i=$(x)||i;break;case e.setStrokeGray:a=$([x[0],x[0],x[0]]);break;case e.setFillGray:i=$([x[0],x[0],x[0]]);break;case e.constructPath:{const[t,s]=x;let n=0;h=h||[];let o=null;for(const l of t)l===e.rectangle?(h.push({rect:[s[n],s[n+1],s[n+2],s[n+3]]}),n+=4,o=null):l===e.moveTo?(o={pts:[b(s[n],s[n+1])],curve:[!1]},h.push(o),n+=2):l===e.lineTo?(o||(o={pts:[],curve:[]},h.push(o)),o.pts.push(b(s[n],s[n+1])),o.curve.push(!1),n+=2):l===e.curveTo?(o&&(o.pts.push(b(s[n+4],s[n+5])),o.curve.push(!0)),n+=6):l===e.curveTo2||l===e.curveTo3?(o&&(o.pts.push(b(s[n+2],s[n+3])),o.curve.push(!0)),n+=4):l===e.closePath&&o&&o.pts.length>1&&(o.pts.push(o.pts[0]),o.curve.push(!1));break}case e.stroke:case e.closeStroke:y("stroke");break;case e.fill:case e.eoFill:y("fill");break;case e.fillStroke:case e.eoFillStroke:case e.closeFillStroke:case e.closeEOFillStroke:y("both");break;case e.clip:case e.eoClip:if(h&&1===h.length){const t=h[0];let e=null;if(t.rect){const[s,n,o,l]=t.rect,r=b(s,n),a=b(s+o,n+l);e={x0:Math.min(r[0],a[0]),x1:Math.max(r[0],a[0]),y0:Math.min(r[1],a[1]),y1:Math.max(r[1],a[1])}}else e=j(t,.3);e&&g.push(e)}break;case e.endPath:h=null;break;case e.paintImageXObject:case e.paintInlineImageXObject:case e.paintImageMaskXObject:{const t=b(0,0),e=b(1,1),s=Math.min(t[0],e[0]),n=Math.max(t[0],e[0]),o=Math.min(t[1],e[1]),l=Math.max(t[1],e[1]);n-s>=4&&l-o>=4&&u.push({x0:s,x1:n,y0:o,y1:l});break}}}for(const t of[1,0]){const e=M.filter((e=>e.h===t)).map((e=>({...e,k:t?e.y:e.x}))).sort(((t,e)=>t.k-e.k||t.a0-e.a0));let s=null;const n=()=>{s&&s.n>=3&&s.a1-s.a0>=4&&(t?x:p).push(t?{y:s.k,x0:s.a0,x1:s.a1,w:s.w,dot:!0}:{x:s.k,y0:s.a0,y1:s.a1,w:s.w,dot:!0})};for(const t of e)s&&Math.abs(t.k-s.k)<=.3&&t.a0-s.a1<=3?(s.a1=Math.max(s.a1,t.a1),s.n++):(n(),s={k:t.k,a0:t.a0,a1:t.a1,w:t.w,n:1});n()}return{H:A(x),V:X(p),F:m,I:u,C:g,H0:x,V0:p}}function j(t,e=2.5){if(!t.pts||t.pts.length<4||t.pts.length>6||t.curve.some(Boolean))return null;const s=t.pts.map((t=>t[0])),n=t.pts.map((t=>t[1]));for(let e=1;e<t.pts.length;e++){const t=Math.abs(s[e]-s[e-1]),o=Math.abs(n[e]-n[e-1]);if(t>.5&&o>.5)return null}const o=Math.min(...s),l=Math.max(...s),r=Math.min(...n),a=Math.max(...n);return l-o<=e||a-r<=e?null:t.pts.every((t=>(Math.abs(t[0]-o)<=.5||Math.abs(t[0]-l)<=.5)&&(Math.abs(t[1]-r)<=.5||Math.abs(t[1]-a)<=.5)))?{x0:o,x1:l,y0:r,y1:a}:null}function A(t){t.sort(((t,e)=>t.y-e.y||t.x0-e.x0));const e=[];for(const s of t){const t=e.find((t=>Math.abs(t.y-s.y)<=1.2&&s.x0<=t.x1+2&&s.x1>=t.x0-2));t?(t.x0=Math.min(t.x0,s.x0),t.x1=Math.max(t.x1,s.x1)):e.push({...s})}return e}function X(t){t.sort(((t,e)=>t.x-e.x||t.y0-e.y0));const e=[];for(const s of t){const t=e.find((t=>Math.abs(t.x-s.x)<=1.2&&s.y0<=t.y1+2&&s.y1>=t.y0-2));t?(t.y0=Math.min(t.y0,s.y0),t.y1=Math.max(t.y1,s.y1)):e.push({...s})}return e}const S=(t,e)=>{const s=[...t].sort(((t,e)=>t-e)),n=[];for(const t of s)if(n.length&&t-n[n.length-1].hi<=e){const e=n[n.length-1];e.hi=t,e.sum+=t,e.n++}else n.push({lo:t,hi:t,sum:t,n:1});return n.map((t=>t.sum/t.n))},C=2.5;function B(t,e,s){const n=Math.min(...t.map((t=>t.x0)),...e.map((t=>t.x))),o=Math.max(...t.map((t=>t.x1)),...e.map((t=>t.x))),l=Math.min(...e.map((t=>t.y0)),...t.map((t=>t.y))),r=Math.max(...e.map((t=>t.y1)),...t.map((t=>t.y))),a=S([...e.map((t=>t.x)),n,o,...t.flatMap((t=>[t.x0,t.x1].filter((s=>((t,s)=>e.some((e=>Math.abs(e.x-t)<=C&&s>=e.y0-C&&s<=e.y1+C)))(s,t.y)))))],C),i=S([...t.map((t=>t.y)),l,r,...e.flatMap((e=>[e.y0,e.y1].filter((s=>((e,s)=>t.some((t=>Math.abs(t.y-e)<=C&&s>=t.x0-C&&s<=t.x1+C)))(s,e.x)))))],C);if(a.length<2||i.length<2)return null;const h=i.length-1,c=a.length-1,f=(t,s,n)=>e.some((e=>Math.abs(e.x-t)<=C&&Math.min(e.y1,n)-Math.max(e.y0,s)>=.6*(n-s))),x=(e,s,n)=>t.some((t=>Math.abs(t.y-e)<=C&&Math.min(t.x1,n)-Math.max(t.x0,s)>=.6*(n-s))),p=(t,e)=>t*c+e,m=Array.from({length:h*c},((t,e)=>e)),u=t=>m[t]===t?t:m[t]=u(m[t]);for(let t=0;t<h;t++)for(let e=0;e<c;e++)e+1<c&&!f(a[e+1],i[t],i[t+1])&&(m[u(p(t,e))]=u(p(t,e+1))),t+1<h&&!x(i[t+1],a[e],a[e+1])&&(m[u(p(t,e))]=u(p(t+1,e)));const g=new Map;for(let t=0;t<h;t++)for(let e=0;e<c;e++){const s=u(p(t,e)),n=g.get(s)||{r0:t,r1:t,c0:e,c1:e,its:[]};n.r0=Math.min(n.r0,t),n.r1=Math.max(n.r1,t),n.c0=Math.min(n.c0,e),n.c1=Math.max(n.c1,e),g.set(s,n)}const b=[];for(const t of s){if(t.used)continue;const e=(t.x0+t.x1)/2,s=(t.top+t.bot)/2;if(e<a[0]-1||e>a[c]+1||s<i[0]-1||s>i[h]+1)continue;let n=0;for(;n<c-1&&e>a[n+1];)n++;let o=0;for(;o<h-1&&s>i[o+1];)o++;g.get(u(p(o,n))).its.push(t),b.push(t)}const M=[...g.values()];for(const t of M)t.x0=a[t.c0],t.x1=a[t.c1+1],t.top=i[t.r0],t.bot=i[t.r1+1];return{Xs:a,Ys:i,R:h,C:c,cells:M,inside:b}}const O=/^[\s(]*[-+−–~∼↑↓▲▼△▽]?[$€£₩]?\s?\d[\d,.\s]*(%|[kKMB]|bn)?\)?\**\s*$|^[-–—]$|^n\/?a$/i;function F(t){const e=[];for(let s=0;s<t.R;s++){const n=t.cells.filter((t=>t.r0===s&&t.r1===s));if(n.length<2)continue;const o=n.map((t=>({c:t,ls:t.its.length?xt(t.its.map((t=>({...t})))):[]}))),l=x(o.flatMap((t=>t.ls.map((t=>t.size)))))||10;{const t=[...new Set(n.map((t=>t.c0)))].sort(((t,e)=>t-e)),s=new Map;for(const t of n)for(const e of t.its)s.set(e,t.c0);const r=n.flatMap((t=>t.its)).filter((t=>null!=t.i)).sort(((t,e)=>t.i-e.i)),a=[];let i=null,h=null;for(const t of r){const e=s.get(t);(!i||e<s.get(h)&&t.top>i.top+.5*l)&&(i={top:t.top,bot:t.bot,cols:new Set},a.push(i)),i.top=Math.min(i.top,t.top),i.bot=Math.max(i.bot,t.bot),i.cols.add(e),h=t}const c=a.length>=2&&t.length>=2&&a.every(((t,e)=>!e||t.top>=a[e-1].bot-.2*l))&&a.filter((t=>t.cols.size>=2)).length>=.5*a.length;if(c){for(let t=1;t<a.length;t++){const s=(a[t-1].bot+a[t].top)/2;for(const t of o)e.push({y:s,x0:t.c.x0,x1:t.c.x1,w:0,virt:!0})}continue}}const r=o.filter((t=>t.ls.length>=2&&t.ls.filter((t=>O.test(t.text))).length>=.8*t.ls.length));let a=r.length?S(r.flatMap((t=>t.ls.map((t=>t.top)))),.45*l):[];if(a.length<2){const t=o.filter((t=>t.ls.length));if(t.length>=2&&t.some((t=>t.ls.length>=3))){const e=Math.max(2,Math.ceil(.6*t.length)),s=S(t.flatMap((t=>t.ls.map((t=>t.top)))),.45*l),n=e=>t.filter((t=>t.ls.some((t=>Math.abs(t.top-e)<=.45*l)))).length,o=s.filter((t=>n(t)>=e)),r=s.filter((t=>n(t)<e)),i=/(의|에|에서|을|를|와|과|및|또는|으로|로서|로써|하고|하며|하여|이나|거나|,)$/,h=t=>{if(t.ls.length<2)return!1;const e=t.c.x1-t.c.x0,s=t.ls.slice(0,-1);let n=0,o=0;for(let e=0;e+1<t.ls.length;e++)!/[.:;!?。)]$/.test(t.ls[e].text)&&/^[a-z]/.test(t.ls[e+1].text)&&n++,i.test(t.ls[e].text)&&o++;return n>=.5*s.length||o>=Math.max(1,.25*s.length)||s.filter((t=>t.x1-t.x0>=.85*e)).length>=.6*s.length},c=t=>o.filter((e=>t.ls.some((t=>Math.abs(t.top-e)<=.45*l)))).length>=.8*o.length,f=o.filter((e=>{const s=t.map((t=>(t.ls.find((t=>Math.abs(t.top-e)<=.45*l))||{}).text)).filter(Boolean);return s.length>=2&&s.every((t=>t===s[0]))})).length;o.length>=4&&f<.5*o.length&&r.length<=.2*s.length&&r.every((t=>n(t)<=1))&&t.filter(h).length<=.2*t.length&&t.every((t=>t.ls.length<2||c(t)))&&(a=o)}}if(!(a.length<2)){{const t=o.filter((t=>t.ls.length>=2)).map((t=>{const e=t.c.its.map((t=>t.i)).filter((t=>null!=t));return e.length?[Math.min(...e),Math.max(...e)]:null})).filter(Boolean).sort(((t,e)=>t[0]-e[0]));if(t.length>=2&&t.every(((e,s)=>!s||e[0]>t[s-1][1])))continue}for(let t=1;t<a.length;t++){const s=a[t]-.25*l;for(const t of o)1!==t.ls.length&&e.push({y:s,x0:t.c.x0,x1:t.c.x1,w:0,virt:!0})}}}return e}function D(t){const e=[],s=e=>(t.Ys[e]+t.Ys[e+1])/2,n=e=>t.Ys[e+1]-t.Ys[e],o=e=>{if(e.r1===e.r0||e.c1!==e.c0||!e.its.length)return null;const o=xt(e.its.map((t=>({...t}))));if(o.length!==e.r1-e.r0+1)return null;const l=o.map((t=>{const o=(t.top+t.bot)/2;let l=-1;for(let t=e.r0;t<=e.r1;t++)Math.abs(o-s(t))<=.25*n(t)&&(l=t);return l}));return l.some((t=>t<0))||new Set(l).size!==l.length?null:o.map(((s,n)=>({r0:l[n],r1:l[n],c0:e.c0,c1:e.c1,its:s.its,x0:e.x0,x1:e.x1,top:t.Ys[l[n]],bot:t.Ys[l[n]+1]})))};for(const e of[...t.cells]){const s=o(e);s&&t.cells.splice(t.cells.indexOf(e),1,...s)}const l=e=>{let s=0;for(;s<t.C-1&&e>t.Xs[s+1];)s++;return s};for(const s of t.cells)if(s.c1!==s.c0||s.r1!==s.r0){if(s.c1>s.c0&&s.its.length){const n=[...s.its].sort(((t,e)=>t.x0-e.x0)),o=[];for(const t of n){const e=o[o.length-1];e&&t.x0-e.x1<=1*Math.max(t.size,6)?(e.its.push(t),e.x1=Math.max(e.x1,t.x1)):o.push({x0:t.x0,x1:t.x1,its:[t]})}const r=o.map((t=>l((t.x0+t.x1)/2)));if(o.length>=2&&new Set(r).size===s.c1-s.c0+1&&r.every(((t,e)=>!e||t>r[e-1]))){o.forEach(((n,o)=>e.push({r0:s.r0,r1:s.r1,c0:r[o],c1:r[o],its:n.its,x0:t.Xs[r[o]],x1:t.Xs[r[o]+1],top:s.top,bot:s.bot})));continue}}e.push(s)}else e.push(s);t.cells=e}function T(t,e){const s=t.Xs[0],n=t.Xs[t.C],o=t.Ys[0],l=t.Ys[t.R],r=[],a=[],i=e.filter((t=>t.x0>=s-2&&t.x1<=n+2&&t.y0>=o-2&&t.y1<=l+2&&t.x1-t.x0<.95*(n-s)+4)),h=i.filter((t=>!i.some((e=>e!==t&&e.x0<=t.x0+.5&&e.x1>=t.x1-.5&&e.y0<=t.y0+.5&&e.y1>=t.y1-.5&&(e.x1-e.x0)*(e.y1-e.y0)>(t.x1-t.x0)*(t.y1-t.y0)+1)))),c=(t,e)=>e.some((e=>Math.abs(e-t)<=C));for(const e of h)for(const s of h)e!==s&&(Math.abs(e.x1-s.x0)<=1&&[e.y0,e.y1,s.y0,s.y1].every((e=>c(e,t.Ys)))&&Math.min(e.y1,s.y1)-Math.max(e.y0,s.y0)>=.8*Math.min(e.y1-e.y0,s.y1-s.y0)&&!c(e.x1,t.Xs)&&r.push({x:(e.x1+s.x0)/2,y0:Math.max(e.y0,s.y0),y1:Math.min(e.y1,s.y1),w:0,virt:!0}),Math.abs(e.y1-s.y0)<=1&&[e.x0,e.x1,s.x0,s.x1].every((e=>c(e,t.Xs)))&&Math.min(e.x1,s.x1)-Math.max(e.x0,s.x0)>=.8*Math.min(e.x1-e.x0,s.x1-s.x0)&&!c(e.y1,t.Ys)&&a.push({y:(e.y1+s.y0)/2,x0:Math.max(e.x0,s.x0),x1:Math.min(e.x1,s.x1),w:0,virt:!0}));for(const e of h)if(!(e.x1-e.x0<15||e.y1-e.y0<8)&&[e.x0,e.x1].every((e=>c(e,t.Xs))))for(const s of[e.y0,e.y1])c(s,t.Ys)&&s>o+C&&s<l-C&&a.push({y:s,x0:e.x0,x1:e.x1,w:0,virt:!0});return{v:r,h:a}}function R(t){const e=[];for(let s=0;s<t.C;s++){const n=t.cells.filter((t=>t.c0===s&&t.c1===s&&t.its.length)),o=(t,e)=>{const s=[];for(const n of t){const t=s[s.length-1];t&&/^[가-힣]$/.test(n.text)&&/(^|\s)[가-힣]$/.test(t.text)&&n.x0-t.x1<=2.5*e?(t.x1=n.x1,t.text+=n.text):s.push({...n})}return s},l=n.map((t=>xt(t.its.map((t=>({...t})))).flatMap((e=>o(Q(e),e.size).map((s=>({x0:s.x0,x1:s.x1,sz:e.size,top:t.top,bot:t.bot}))))))),r=l.filter((t=>t.length>=2));if(r.length<2||r.length<.6*n.length||2===r.length&&r[0].length!==r[1].length)continue;const a=x(l.flat().map((t=>t.sz)))||10,i=r.flat(),h=t.Xs[s],c=t.Xs[s+1],f=[...new Set(i.flatMap((t=>[t.x0,t.x1])))].sort(((t,e)=>t-e)),p=[];for(let t=0;t+1<f.length;t++){const e=(f[t]+f[t+1])/2;f[t+1]-f[t]>=.3*a&&e>h+1&&e<c-1&&!i.some((t=>t.x0<e&&t.x1>e))&&p.push(e)}const m=p.filter((t=>r.filter((e=>e.some((e=>e.x1<=t))&&e.some((e=>e.x0>=t)))).length>=.6*r.length));if(!m.length)continue;const u=n.filter(((t,e)=>l[e].length>=2)),g=Math.min(...u.map((t=>t.top))),b=Math.max(...u.map((t=>t.bot)));for(const t of m)e.push({x:t,y0:g,y1:b,w:0,virt:!0})}return e}function E(t){const e=t.filter((t=>t.h)).map((t=>t.h)).sort(((t,e)=>t.y-e.y)),s=t.filter((t=>t.v)).map((t=>t.v)),n=[];if(e.length<3||s.length<2)return[t];for(let t=0;t<e.length;t++)for(let o=t+1;o<e.length;o++){const l=e[t],r=e[o],a=r.y-l.y;if(a>8)break;if(a<1.2)continue;const i=Math.max(l.x0,r.x0),h=Math.min(l.x1,r.x1);h-i<.8*Math.min(l.x1-l.x0,r.x1-r.x0)||s.some((t=>t.x>i-C&&t.x<h+C&&t.y0<l.y+.5&&t.y1>r.y-.5))||s.some((t=>Math.abs(t.y1-l.y)<=C))&&s.some((t=>Math.abs(t.y0-r.y)<=C))&&(n.some((t=>t.b.y>=l.y-.5&&t.a.y<=r.y+.5))||n.push({a:l,b:r}))}if(!n.length)return[t];const o=t=>{let e=0;for(;e<n.length&&t>(n[e].a.y+n[e].b.y)/2;)e++;return e};n.sort(((t,e)=>t.a.y-e.a.y));const l=Array.from({length:n.length+1},(()=>[]));for(const e of t)l[o(e.h?e.h.y:(e.v.y0+e.v.y1)/2)].push(e);return l.filter((t=>t.length))}function P(t,e,s,n=[]){const o=[...t.map((t=>({h:t}))),...e.map((t=>({v:t})))],l=o.map(((t,e)=>e)),r=t=>l[t]===t?t:l[t]=r(l[t]);for(let t=0;t<o.length;t++)for(let e=t+1;e<o.length;e++){const s=o[t],n=o[e];let a=!1;s.h&&n.v?a=n.v.x>=s.h.x0-C&&n.v.x<=s.h.x1+C&&s.h.y>=n.v.y0-C&&s.h.y<=n.v.y1+C:s.v&&n.h&&(a=s.v.x>=n.h.x0-C&&s.v.x<=n.h.x1+C&&n.h.y>=s.v.y0-C&&n.h.y<=s.v.y1+C),a&&(l[r(t)]=r(e)),s.v&&n.v&&s.v.y1-s.v.y0>=30&&Math.abs(s.v.y0-n.v.y0)<=2*C&&Math.abs(s.v.y1-n.v.y1)<=2*C&&(l[r(t)]=r(e))}const a=new Map;o.forEach(((t,e)=>{const s=r(e);a.has(s)||a.set(s,[]),a.get(s).push(t)}));const i=[],h=[];i.boxes=h;for(const t of[...a.values()].flatMap(E)){const e=t.filter((t=>t.h)).map((t=>t.h)),o=t.filter((t=>t.v)).map((t=>t.v));if(o.length>=2){const t=Math.min(...o.map((t=>t.x))),s=Math.max(...o.map((t=>t.x)));for(const[n,l,r]of[[Math.min(...o.map((t=>t.y0))),t=>t.y0,"top"],[Math.max(...o.map((t=>t.y1))),t=>t.y1,"bot"]])o.filter((t=>Math.abs(l(t)-n)<=C&&t.y1-t.y0>=40)).length>=2&&!e.some((e=>Math.abs(e.y-n)<=C&&e.x0<=t+C&&e.x1>=s-C))&&e.push({y:n,x0:t,x1:s,w:0,virt:!0,open:r})}if(e.length<2||o.length<1)continue;if(1===o.length&&e.filter((t=>t.x0<o[0].x-5&&t.x1>o[0].x+5&&t.y>=o[0].y0-C&&t.y<=o[0].y1+C)).length<2)continue;let l=B(e,o,s);if(!l)continue;if(l.Xs[l.C]-l.Xs[0]<20||l.Ys[l.R]-l.Ys[0]<8)continue;{const t=l.Ys[0],n=l.Xs,r=l.C;if(!o.some((t=>Math.abs(t.x-n[0])<=C||Math.abs(t.x-n[r])<=C))&&o.filter((e=>Math.abs(e.y0-t)<=C)).length>=2&&e.some((e=>Math.abs(e.y-t)<=C))){const a=x(l.inside.map((t=>t.size)))||10,i=s.filter((e=>!e.used&&e.bot<=t+1&&e.bot>t-3*a&&e.x1>n[0]&&e.x0<n[r])),h=t=>{for(let e=0;e<r;e++)if(t.x0>=n[e]-1&&t.x1<=n[e+1]+1)return e;return-1};if(i.length&&i.every((t=>h(t)>=0))){const c=x(i.map((t=>t.size))),f=Math.min(...i.map((t=>t.top))),p=s.some((e=>!e.used&&!i.includes(e)&&e.bot>f&&e.top<t&&e.x1>n[0]&&e.x0<n[r])),m=i.every((t=>{const e=h(t),s=(t.x0+t.x1)/2,o=n[e+1]-n[e];return Math.abs(s-(n[e]+n[e+1])/2)<=.3*o}));if(new Set(i.map(h)).size>=2&&t-f<=3*Math.max(c,a)&&!p&&m&&i.every((t=>Math.abs(t.size-a)<=.15*a))){const a=f-.3*c,i=B([...e,{y:a,x0:n[0],x1:n[r],w:0,virt:!0}],o.map((e=>Math.abs(e.y0-t)<=C?{...e,y0:a}:e)),s);i&&(l=i)}}}}const r=F(l);r.length&&(l=B([...e,...r],o,s)||l);const a=T(l,n);(a.v.length||a.h.length)&&(l=B([...e,...r,...a.h],[...o,...a.v],s)||l);const c=R(l);c.length&&(l=B([...e,...r,...a.h],[...o,...a.v,...c],s)||l),D(l);const f=l.cells.filter((t=>t.its.length)),p=new Set(f.map((t=>t.r0))),m=new Set(f.map((t=>t.c0)));1===l.R&&1===l.C&&1===f.length&&h.push({x0:l.Xs[0],x1:l.Xs[1],top:l.Ys[0],bot:l.Ys[1],its:l.inside});const u=1===f.length&&l.C>=2&&(e.some((t=>t.virt&&"top"===t.open))||f[0].c0>0);if(!u&&(f.length<2||p.size<2&&m.size<2))continue;if(1===l.C&&f.length<=3)continue;const g=l.C>=2&&[0,1,2].some((t=>{const e=l.cells.filter((e=>e.r0===t)),s=e.filter((t=>t.its.length&&!O.test(U(t.its))));return e.length>=2&&s.length>=2&&s.length>=.6*e.length}));if((!(f.length<.3*l.cells.length&&l.cells.length>=6)||g)&&!(f.every((t=>O.test(U(t.its))))&&f.length<.7*l.cells.length)){for(const t of l.inside)t.used=!0;i.push({frag:u,top:l.Ys[0],bot:l.Ys[l.R],x0:l.Xs[0],x1:l.Xs[l.C],cells:l.cells,R:l.R,C:l.C,Xs:l.Xs,openTop:e.some((t=>t.virt&&"top"===t.open)),openBot:e.some((t=>t.virt&&"bot"===t.open))})}}return i}function Z(t,e,s,n=[]){const o=(t,e)=>Math.abs(t-e)<=3;let l=t.filter((t=>{return!(!(o=t.col)||/^#(f[a-f]){3}$/.test(o))&&(t.x1-t.x0)*(t.y1-t.y0)<.4*e*s&&!n.some((e=>t.x0<e.x1-2&&t.x1>e.x0+2&&t.y0<e.bot-2&&t.y1>e.top+2));var o}));const r=new Map;for(const t of l)r.set([t.x0,t.x1,t.y0,t.y1].map((t=>Math.round(t))).join(","),t);l=[...r.values()],l=l.filter((t=>l.filter((e=>((t,e)=>e!==t&&e.x0>=t.x0-1&&e.x1<=t.x1+1&&e.y0>=t.y0-1&&e.y1<=t.y1+1)(t,e))).length<2));const a=l.map(((t,e)=>e)),i=t=>a[t]===t?t:a[t]=i(a[t]);for(let t=0;t<l.length;t++)for(let e=t+1;e<l.length;e++){const s=l[t],n=l[e],r=Math.min(s.x1,n.x1)-Math.max(s.x0,n.x0),h=Math.min(s.y1,n.y1)-Math.max(s.y0,n.y0),c=(o(s.x1,n.x0)||o(n.x1,s.x0))&&h>=.5*Math.min(s.y1-s.y0,n.y1-n.y0),f=(o(s.y1,n.y0)||o(n.y1,s.y0))&&r>=.5*Math.min(s.x1-s.x0,n.x1-n.x0);(c||f)&&(a[i(t)]=i(e))}const h=()=>{const t=new Map;return l.forEach(((e,s)=>{const n=i(s);t.has(n)||t.set(n,[]),t.get(n).push(e)})),[...t.values()]},c=t=>({g:t,x0:Math.min(...t.map((t=>t.x0))),x1:Math.max(...t.map((t=>t.x1))),top:Math.min(...t.map((t=>t.y0))),bot:Math.max(...t.map((t=>t.y1))),Xs:S(t.flatMap((t=>[t.x0,t.x1])),3.5),rh:x(t.map((t=>t.y1-t.y0)))}),f=h().filter((t=>t.length>=2)).map(c).sort(((t,e)=>t.top-e.top));for(let t=0;t+1<f.length;t++){const e=f[t],s=f[t+1],n=s.top-e.bot;o(e.x0,s.x0)&&o(e.x1,s.x1)&&e.Xs.length>=3&&s.Xs.length>=3&&(e.Xs.length<=s.Xs.length?e.Xs.every((t=>s.Xs.some((e=>o(t,e))))):s.Xs.every((t=>e.Xs.some((e=>o(t,e))))))&&n>3&&n<=2.6*Math.max(e.rh,s.rh)&&(a[i(l.indexOf(e.g[0]))]=i(l.indexOf(s.g[0])),f[t+1]=c([...e.g,...s.g]),f[t+1].band=!0)}const p=[];for(const t of h()){if(t.length<4)continue;const e=S(t.flatMap((t=>[t.x0,t.x1])),3.5);let s=S(t.flatMap((t=>[t.y0,t.y1])),3.5);if(e.length<3||s.length<3)continue;const n=(t,e)=>{let s=0;for(let n=1;n<e.length;n++)Math.abs(e[n]-t)<Math.abs(e[s]-t)&&(s=n);return s},o=(e,s)=>t.some((t=>t.y0<s-1&&t.y1>e+1)),l=x(t.map((t=>t.y1-t.y0))),r=[s[0]];for(let t=1;t<s.length;t++){const e=s[t]-s[t-1];if(!o(s[t-1],s[t])&&e>1.6*l){const n=Math.round(e/l);for(let o=1;o<n;o++)r.push(s[t-1]+o*e/n)}r.push(s[t])}s=r;const a=e.length-1,i=s.length-1,h=Array.from({length:i},(()=>new Array(a).fill(null))),c=[];for(const o of[...t].sort(((t,e)=>(t.x1-t.x0)*(t.y1-t.y0)-(e.x1-e.x0)*(e.y1-e.y0)))){const t=n(o.x0,e),l=n(o.x1,e)-1,r=n(o.y0,s),a=n(o.y1,s)-1;if(l<t||a<r)continue;let i=!0;for(let e=r;e<=a&&i;e++)for(let s=t;s<=l;s++)if(h[e][s]){i=!1;break}if(!i)continue;const f={r0:r,r1:a,c0:t,c1:l,its:[],col:o.col};c.push(f);for(let e=r;e<=a;e++)for(let s=t;s<=l;s++)h[e][s]=f}for(let t=0;t<i;t++)for(let e=0;e<a;e++)if(!h[t][e]){const s={r0:t,r1:t,c0:e,c1:e,its:[],hole:!0};c.push(s),h[t][e]=s}for(const t of c)t.x0=e[t.c0],t.x1=e[t.c1+1],t.top=s[t.r0],t.bot=s[t.r1+1];p.push({Xs:e,Ys:s,R:i,C:a,cells:c,own:h,n:t.length})}return p}function Y(t,e,s,n,o,l){const r=[];for(const a of Z(t,s,n,o)){const t=a.Xs[0],s=a.Xs[a.C],n=a.Ys[0],o=a.Ys[a.R],i=[];let h=0;for(const r of e){if(r.used)continue;const e=(r.x0+r.x1)/2,c=(r.top+r.bot)/2;if(e<t||e>s||c<n||c>o)continue;(r.x0<t-2*l||r.x1>s+2*l)&&h++;let f=0;for(;f<a.C-1&&e>a.Xs[f+1];)f++;let x=0;for(;x<a.R-1&&c>a.Ys[x+1];)x++;a.own[x][f].its.push(r),i.push(r)}const c=a.cells.filter((t=>t.its.length)),f=new Set;for(let t=0;t<a.R;t++)new Set(a.own[t].filter((t=>t.its.length))).size>=2&&f.add(t);let x=0,p=0;for(let t=0;t<a.R;t++)new Set(a.own[t].filter((t=>!t.hole))).size>=2&&x++;for(let t=0;t<a.C;t++)new Set(a.own.map((e=>e[t])).filter((t=>!t.hole))).size>=2&&p++;const m={size:x>=2||x>=1&&p>=1?2:0},u=c.map((t=>U(t.its)));if(h||m.size<2||c.length<.4*a.cells.length||f.size<2||u.every((t=>O.test(t))))for(const t of a.cells)t.its=[];else{for(const t of i)t.used=!0;r.push({top:n,bot:o,x0:t,x1:s,cells:a.cells,R:a.R,C:a.C,src:"fill",Xs:a.Xs})}}return r}const I=/^[→⇒➔➜➝➞➡▶►▷▸⇨⟶⇢➨➙➛➤➧➭➮➯➱⬅←⇐◀◁]+$/;function U(t,e=null){const o=xt(t.map((t=>({...t})))),l=o.length?Math.max(...o.map((t=>t.x1))):0;if(!e||o.length<2)return s(o.map(((t,e)=>(e?W(o[e-1],t,l,!0):"")+t.text)).join("").replace(/\s+/g," ").trim());const r=e.x1-e.x0-10.2,a=t=>{let e=0;for(let s=0;s<t.its.length;s++){const n=t.its[s],o=n.s.indexOf(" ");if(o>0)return e+(n.x1-n.x0)*o/n.s.length;e=n.x1-t.x0;const l=t.its[s+1];if(!l||"real"===n.sp||l.x0-n.x1>.18*t.size)return e}return e},i=[[o[0]]];for(let t=1;t<o.length;t++){const e=o[t-1],s=o[t],n=r-(e.x1-e.x0);n>=a(s)+.25*e.size?i.push([s]):(i[i.length-1].push(s),s.wsp=n>=.9*e.size)}return i.map((t=>s(n(t.map(((e,s)=>(s?e.wsp?" ":W(t[s-1],e,t[s-1].x1,!0):"")+(e.stext||e.text))).join("").replace(/\s+/g," ").trim(),{cell:!0})))).filter(Boolean).join("\n")}const V=/[을를은는이가의에와과도로서고며여게지다만할된한될른및등터께라면야요월일]$/,G=/^[는를였었았겠됩됨며]/,_=process.env.PDFMD_JOINMARK;let L=null;const N=t=>/[0-9]/.test(t)?"0":/[A-Za-z]/.test(t)?"a":t;function H(t){const e=[];let s="",n=null;for(const o of[...t.its].sort(((t,e)=>t.x0-e.x0))){if(n){const t=o.x0-n.x1,l=Math.min(o.size,n.size);t>l?(e.push(s),s=""):/\s$/.test(s)||/^\s/.test(o.s)||!et(n,t,l,o)||(s+=" ")}s+=o.s,n=o}return e.push(s),e}function q(t,e){const s=e=>t.set(e,(t.get(e)||0)+1),n=e.replace(/\s+/g," ").trim(),o=Array.from(n,N);{const t=n.split(" ");if(t.length>=3&&t.every((t=>1===Array.from(t).length)))return}for(let t=0;t+1<o.length;t++)" "!==o[t]&&" "!==o[t+1]?s("J"+o[t]+o[t+1]):" "!==o[t]&&t+2<o.length&&" "!==o[t+2]&&s("P"+o[t]+o[t+2]);for(const t of n.matchAll(/[가-힣]+/g)){const e=t[0],o=t.index,l=o+e.length;for(let t=0;t+3<=e.length;t++)s("G"+e.slice(t,t+3));for(let t=0;t+1<e.length;t++)s("a"+e[t]),s("b"+e[t+1]);for(let t=0;t+2<e.length;t++)s("n"+e.slice(t,t+2)),s("m"+e.slice(t+1,t+3));o>0&&" "===n[o-1]&&(s("S"+e[0]),e.length>=2&&s("S"+e.slice(0,2))),l<n.length&&" "===n[l]&&(s("E"+e[e.length-1]),e.length>=2&&s("E"+e.slice(-2)))}}function J(t,e,s,n){const o=e.slice(-1),l=s.charAt(0),r=/[가-힣]/.test(o),a=/[가-힣]/.test(l),i=e=>t.get(e)||0;if(r&&a){if(G.test(s))return"";const t=e.match(/[가-힣]+$/)[0],r=s.match(/^[가-힣]+/)[0],a=i("J"+o+l),h=i("P"+o+l),c=(r.length>=2?i("G"+t.slice(-1)+r.slice(0,2)):0)+(t.length>=2?i("G"+t.slice(-2)+r[0]):0),f=!n&&(t.length>=2||r.length>=2)&&i("S"+r.slice(0,2))>0&&i("E"+t.slice(-2))>0,x=c>0&&!f||a>h,p=h>a||f&&0===c;if(n&&x&&!p&&1===e.length&&1===s.length&&V.test(e)&&a<=2)return null;if(x!==p)return x?"":" ";if(x)return c>0&&!f?"":h>=a?" ":"";if(n)return null;const m=i("E"+o),u=i("a"+o),g=i("S"+l),b=i("b"+l);return m+u+g+b>=8&&(m+.3)/(m+u+1)>=.35&&(g+.3)/(g+b+1)>=.35||r.length>=2&&i("S"+r.slice(0,2))>0&&!i("m"+r.slice(0,2))||t.length>=2&&i("E"+t.slice(-2))>0&&!i("n"+t.slice(-2))?" ":null}if("·ㆍ‧".includes(o)||!n&&r&&"ㆍ‧".includes(l))return"";if(n)return null;if(r&&/[0-9]/.test(l))return"제"===o?"":" ";const h=i("J"+N(o)+N(l)),c=i("P"+N(o)+N(l));return(a&&!r&&!/[0-9]/.test(o)||r&&!a&&!/[0-9]/.test(l)&&"("!==l)&&c!==h?c>h?" ":"":null}function W(t,e,s,n=!1){if(t&&L&&!_&&t.text&&e.text&&t.x1>=s-1*t.size){const s=J(L,t.text,e.text,n);if(null!==s)return s}if(!t||!/[가-힣0-9]$/.test(t.text)||!/^[가-힣0-9]/.test(e.text)||!/[가-힣]$/.test(t.text)&&!/^[가-힣]/.test(e.text))return" ";const o=t.x1>=s-1*t.size;return _?o?"⁣":"⁤":!o||!G.test(e.text)&&V.test(t.text)?" ":""}function K(t){const e=new Set,s=new Set;for(const n of t.cells)e.add(n.r0),e.add(n.r1+1),s.add(n.c0),s.add(n.c1+1);const n=[...e].sort(((t,e)=>t-e)),o=[...s].sort(((t,e)=>t-e)),l=new Map(n.map(((t,e)=>[t,e]))),r=new Map(o.map(((t,e)=>[t,e]))),a="clip"===t.src,i=t.cells.map((t=>({r:l.get(t.r0),c:r.get(t.c0),rs:l.get(t.r1+1)-l.get(t.r0),cs:r.get(t.c1+1)-r.get(t.c0),text:U(t.its,a?t:null)}))),h=n.length-1,c=new Array(h).fill(!i.some((t=>t.rs>1||t.cs>1)));for(const t of i)if(t.text)for(let e=t.r;e<t.r+t.rs;e++)c[e]=!1;if(c.some(Boolean)&&!c.every(Boolean))for(const t of i){let e=0;for(let s=t.r;s<t.r+t.rs;s++)c[s]&&e++;e<t.rs&&(t.rs-=e)}const f=[];for(const t of i)c[t.r]&&!c.every(Boolean)||(f[t.r]||=[]).push(t);if(a&&!i.some((t=>t.rs>1||t.cs>1))){const t=f.filter(Boolean).map((t=>t.sort(((t,e)=>t.c-e.c)))),e=Math.max(...t.map((t=>t.length))),s=t=>String(t||"").split("\n").map((t=>t.replace(/\s+/g," ").replace(/\|/g,"|").trim())).join("<br>"),n=t=>"| "+Array.from({length:e},((e,n)=>s(t[n]&&t[n].text))).join(" | ")+" |";if(t.length)return[n(t[0]),"|"+" --- |".repeat(e),...t.slice(1).map(n)].join("\n")}return"<table>"+f.map((t=>t?"<tr>"+t.sort(((t,e)=>t.c-e.c)).map((t=>`<td${t.rs>1?` rowspan="${t.rs}"`:""}${t.cs>1?` colspan="${t.cs}"`:""}>${u(t.text).replace(/\n/g,"<br>").replace(/&lt;(\/?su[bp])&gt;/g,"<$1>")}</td>`)).join("")+"</tr>":"")).join("")+"</table>"}function Q(t){const e=[];let s=null;for(const n of t.its){const o=s&&/[\[[((]\s*$/.test(s.its[s.its.length-1].s)&&/^\s*[\]]))]/.test(n.s);s&&!o&&n.x0-s.x1>Math.max(.8*t.size,5)&&(e.push(s),s=null),s||(s={x0:n.x0,x1:n.x1,its:[]}),s.its.push(n),s.x1=Math.max(s.x1,n.x1)}s&&e.push(s);for(const s of e)s.text=tt(s.its,t.size);return e}const tt=(t,e)=>{let s="",n=null;for(const o of t)n&&!/\s$/.test(s)&&et(n,o.x0-n.x1,e,o)&&(s+=" "),s+=o.s,n=o;return s.replace(/\s+/g," ").trim()},et=(t,e,s,n=null)=>"real"===t.sp||e>(!(/[(\[「『〈《]$/.test(t.s)||n&&/^[)\]」』〉》]/.test(n.s))||n&&/[(\[]$/.test(t.s)&&/^[)\]]/.test(n.s)?.18:.5)*s&&("fake"!==t.sp||e>.4*s),st=/^([•●▪■◦○◆►‣⁃∙·\-–—*\[[□☐]|\(?\d{1,2}[.)]|\(?[a-zA-Z][.)]|\([ivx]+\))$/;function nt(t,e,s=!1){const n=t.filter((t=>t.cs.length>=2));if(s&&1===n.length&&t.length>=3){const s=n[0].cs.map((t=>t.x0));if(t.every((t=>t===n[0]||Math.abs(t.cs[0].x0-s[0])<=.8*e)))return s}if(n.length<2)return null;const o=ot(n,e);let l=S(n.flatMap((t=>t.cs.map((t=>t.x0)))),.7*e).filter((t=>(t=>n.filter((s=>s.cs.some((s=>Math.abs(s.x0-t)<=.7*e)))).length)(t)>=Math.max(2,.34*n.length)));const r=S(n.flatMap((t=>t.cs.slice(1).map((t=>t.x1)))),.7*e).filter((t=>n.filter((s=>s.cs.slice(1).some((s=>Math.abs(s.x1-t)<=.7*e)))).length>=Math.max(2,.4*n.length)));for(const t of r){const s=n.flatMap((s=>s.cs.slice(1).filter((s=>Math.abs(s.x1-t)<=.7*e)))),o=Math.min(...s.map((t=>t.x0)));l.some((s=>Math.abs(s-o)<=2*e||s<t&&s>o))||l.push(o)}return l=[...new Set(l)].sort(((t,e)=>t-e)),o&&o.length>l.length?o:l.length>=2?l:null}function ot(t,e){const s=Math.floor(.15*t.length),n=[...new Set(t.flatMap((t=>t.cs.flatMap((t=>[t.x0,t.x1])))))].sort(((t,e)=>t-e)),o=[];let l=null;for(let r=0;r+1<n.length;r++){const a=(n[r]+n[r+1])/2;t.filter((t=>t.cs.some((t=>t.x0<a&&t.x1>a)))).length<=s||(l&&n[r]-l.x1<.3*e?l.x1=n[r+1]:o.push(l={x0:n[r],x1:n[r+1]}))}if(o.length<2)return null;const r=Math.max(2,Math.ceil(.5*t.length));return o.every((e=>t.filter((t=>t.cs.some((t=>t.x0<e.x1&&t.x1>e.x0)))).length>=r))?o.map((t=>t.x0)):null}function lt(t,e,s=[],n=!1,o=[],l=null){const r=t.map((t=>({l:t,cs:Q(t)}))),a=l||nt(r,e,n);if(!a)return m(1);const i=r.findIndex((t=>t.cs.length>=2&&t.cs.filter((t=>O.test(t.text))).length>=.5*t.cs.length)),h=t=>i<=0?1:t>=i?100:t===i-1?10:1,c=a.length,f=function(t,e,s,n){const o=[];for(let l=1;l<t.length;l++){const r=t[l-1]+.5*s,a=t[l],i=t[l]-.7*s;if(a-r<.3*s){o.push(i);continue}const h=[...new Set([r,a,...e.flatMap((t=>[t.x0,t.x1])).filter((t=>t>r&&t<a))])].sort(((t,e)=>t-e)),c=[];for(let t=0;t+1<h.length;t++){const s=(h[t]+h[t+1])/2,n=e.filter((t=>t.x0<s&&t.x1>s));c.push({a:h[t],b:h[t+1],n:n.length,key:n.reduce(((t,e)=>t+(e.w||1)),0)})}const f=Math.min(...c.map((t=>t.key)));if(Math.min(...c.filter((t=>t.key===f)).map((t=>t.n)))>Math.max(1,.25*n)){o.push(i);continue}const x=[];let p=null;for(const t of c)t.key===f?p?p.b=t.b:x.push(p={a:t.a,b:t.b}):p=null;const m=x.sort(((t,e)=>e.b-e.a-(t.b-t.a)))[0];o.push(m&&m.b-m.a>=.25*s?(m.a+m.b)/2:i)}return o}(a,r.flatMap(((t,e)=>t.l.its.map((t=>({x0:t.x0,x1:t.x1,w:h(e)}))))),e,r.length),p=t=>{let e=0;for(;e<c-1&&t>=f[e];)e++;return e},u=r.map((t=>{const s=Array.from({length:c},(()=>({its:[],span:1})));for(const n of t.l.its){const t=n.x1-n.x0,o=p(n.x0+Math.min(.3*e,t/2));s[o].its.push(n);const l=p(n.x1-Math.min(.5*e,t/2));l>o&&t>2*e&&(s[o].span=Math.max(s[o].span,l-o+1))}return{top:t.l.top,bot:t.l.bot,cells:s.map((e=>({t:tt(e.its,t.l.size),span:e.span,x0:e.its.length?Math.min(...e.its.map((t=>t.x0))):0,x1:e.its.length?Math.max(...e.its.map((t=>t.x1))):0})))}}));"2"===process.env.PDFMD_DEBUG&&console.error("[pdfmd] 표 후보 ds="+i,a.map((t=>t.toFixed(0))).join(","),"S",f.map((t=>t.toFixed(0))).join(","),u.map((t=>t.cells.map((t=>t.t.slice(0,14)+(t.span>1?"{"+t.span+"}":""))).join(" | "))));const g=u.flatMap((t=>t.cells.filter((t=>t.t)))),b=u.filter((t=>t.cells.filter((t=>t.t)).length>=2)).length;if(!n&&(b<2||u.length<2))return m(2);if(n&&(u.length<2||b<2&&!(u.length>=3&&g.every((t=>t.t.length<=60)))))return m(3);const M=u.map((t=>t.cells[0].t)).filter(Boolean);if(M.length>=2&&M.filter((t=>st.test(t))).length>=.8*M.length)return m(4);if(!n&&g.reduce(((t,e)=>t+e.t.length),0)/g.length>28&&c<3)return m(5);if(!n){const t=t=>x(u.map((e=>e.cells[t].t.length)).filter(Boolean));if(2===c&&t(0)>30&&t(1)>30)return m(6);const e=u.some((t=>t.cells.filter((t=>t.t&&!O.test(t.t))).length>=2)),s=u.filter((t=>t.cells[0].t&&!O.test(t.cells[0].t))).length>=.5*u.length;if(!e&&!s)return m(7);if(g.filter((t=>/^[a-z]/.test(t.t))).length>=.5*g.length)return m(8)}{let t=0;for(let e=0;e<c;e++){const s=u.map((t=>t.cells[e])).filter((t=>t.t&&t.t.length>25));if(s.length<3)continue;const n=Math.max(...s.map((t=>t.x1-t.x0)));s.filter((t=>t.x1-t.x0>=.85*n)).length>=.6*s.length&&t++}if(t>=2)return m(9);if(g.filter((t=>/[a-z]-$/.test(t.t))).length>=2)return m(10);const e=Array.from({length:c},((t,e)=>{const s=u.map((t=>t.cells[e].t)).filter(Boolean);return s.length>=2&&s.filter((t=>O.test(t))).length>=.6*s.length})),s=e.some(Boolean)?Math.max(0,u.findIndex((t=>e.some(((e,s)=>e&&t.cells[s].t&&O.test(t.cells[s].t)))))):0;for(let t=0;t<c;t++){const e=u.map((e=>e.cells[t].t));let o=0,l=0;for(let t=s;t+1<e.length;t++)e[t]&&e[t+1]&&e[t].length>=20&&(o++,/[a-z,;'’-]$/.test(e[t])&&/^[a-z(“"‘]/.test(e[t+1])&&l++);if(o>=3&&l>=.4*o||o>=2&&l>=.5*o&&!n)return m(11)}}if(!n&&g.length<.6*u.length*c)return m(12);if(g.length<(n?.5:.4)*u.length*c)return m(13);if(g.filter((t=>/[∂√∑∫≤≥±×÷∣∇∞]|\b(d|dt|dx)\b\s*$/.test(t.t))).length>=2)return m(14);if(g.some((t=>/^(figure|fig\.|chart|photo|image|그림)\s*\d/i.test(t.t)||/(\b(19|20)\d\d\b.*){3}/.test(t.t)||/\((left|right) axis\)/i.test(t.t))))return m(15);if(n&&!u.some((t=>t.cells.filter((t=>t.t&&!O.test(t.t))).length>=2))&&u.filter((t=>t.cells[0].t&&!O.test(t.cells[0].t))).length<.5*u.length)return m(16);const d=u.map((t=>t.cells[c-1].t)).filter(Boolean);if(2===c&&d.length>=2&&d.every((t=>/^([ivxlc]+|\d{1,4})$/i.test(t)))){const t=d.filter((t=>/^\d+$/.test(t))).map(Number);if(t.every(((e,s)=>!s||e>=t[s-1])))return m(17)}const y=Array.from({length:c},((t,e)=>{const s=u.map((t=>t.cells[e].t)).filter(Boolean);return s.length>=2&&s.filter((t=>O.test(t))).length>=.6*s.length})),z=t=>y.some(((e,s)=>e&&t.cells[s].t&&O.test(t.cells[s].t))),w=u.findIndex(z),v=[],$=w>0?w:i;$>=2&&function(t,e,s,n,o){if(e<2)return;const l=Array.from({length:s},(()=>[1/0,-1/0]));for(let s=e-1;s<t.length;s++)t[s].cells.forEach(((t,e)=>{t.t&&1===t.span&&(l[e][0]=Math.min(l[e][0],t.x0),l[e][1]=Math.max(l[e][1],t.x1))}));if(l.some((t=>t[0]===1/0)))return;const r=t=>(l[t][0]+l[t][1])/2;for(let a=0;a<e-1;a++){const e=t[a],i=t[a+1],h=e.cells.map(((t,e)=>({c:t,k:e}))).filter((t=>t.c.t)),c=[];for(const t of h){const{c:a,k:f}=t,x=(a.x0+a.x1)/2;let p=null;const m=(e,s)=>!h.some((n=>n!==t&&n.k>=e&&n.k<=s))&&!c.some((([t,n])=>t<=s&&n>=e)),u=o.find((t=>t.y>e.bot-1&&t.y<i.top+1&&t.x0<=x&&t.x1>=x&&t.x1-t.x0<.95*(l[s-1][1]-l[0][0])));if(u){const t=l.map(((t,e)=>e)).filter((t=>r(t)>=u.x0-2&&r(t)<=u.x1+2));t.length>=2&&t[0]<=f&&t[t.length-1]>=f&&m(t[0],t[t.length-1])&&(p=[t[0],t[t.length-1]])}if(!p)for(let t=0;t<=f;t++)for(let e=Math.max(f,t+1);e<s;e++)Math.abs((l[t][0]+l[e][1])/2-x)>.6*n||a.x0<l[t][0]-n||a.x1>l[e][1]+n||!m(t,e)||(!p||e-t>p[1]-p[0])&&(p=[t,e]);if(!p){c.push([f,f+a.span-1]);continue}const[g,b]=p;c.push(p);for(let t=g;t<=b;t++)t!==f&&(e.cells[t]={t:"",span:1,x0:0,x1:0});e.cells[f]={t:"",span:1,x0:0,x1:0},e.cells[g]={...a,span:b-g+1}}}}(u,$,c,e,o);const k=(t,e)=>{e.cells.forEach(((e,s)=>{if(e.t){const n=t.cells[s];n.t?(n.x0=Math.min(n.x0,e.x0),n.x1=Math.max(n.x1,e.x1)):(n.x0=e.x0,n.x1=e.x1),n.t=(n.t?n.t+" ":"")+e.t,n.span=Math.max(n.span,e.span)}})),t.bot=e.bot},j=(t,e)=>s.some((s=>s>t.bot-1&&s<e.top+1)),A=(()=>{const t=[];for(let e=Math.max(0,w);e+1<u.length;e++)z(u[e])&&z(u[e+1])&&t.push(u[e+1].top-u[e].top);return t.length>=2?x(t):0})();for(let t=0;t<u.length;t++){const s=u[t],n=v[v.length-1];if(!n){v.push(s);continue}const o=s.top-n.bot<.9*e&&!j(n,s);let l;if(y.some(Boolean)&&w>=0)if(t<w){const o=t=>t.cells.filter((t=>t.t)).length<c&&t.cells.some((t=>t.span>1));if(l=!j(n,s)&&s.top-n.bot<1.6*e&&!o(s)&&!o(n)&&!(A&&u[t].top-u[t-1].top>=.9*A),l){k(n,s),n.cells.forEach((t=>{t.span=1}));continue}}else l=!z(s)&&o;else l=o&&!s.cells[0].t;l?k(n,s):v.push(s)}return v.length<2?m(18):($>=2&&function(t,e,s){if(e<2||!t.slice(0,e).some((t=>t.cells.some((t=>t.t&&t.span>1)))))return;const n=(e,s)=>t[e].cells.some(((t,e)=>e<s&&t.t&&e+t.span-1>=s));for(let o=0;o<s;o++){const s=[];let l=!0;for(let r=0;r<e;r++){if(n(r,o)){l=!1;break}if(t[r].cells[o].t)s.push(r);else if(t[r].cells[o].span>1){l=!1;break}}if(!l||1!==s.length||t[s[0]].cells[o].span>1)continue;const r=t[s[0]].cells[o];for(let s=0;s<e;s++)t[s].cells[o]={t:"",span:1,skip:!0};t[0].cells[o]={...r,rs:e}}}(v,v.findIndex((t=>t.top>=u[$].top-.5)),c),{rows:v,C:c})}function rt(t){return"<table>"+t.rows.map((e=>{let n="<tr>",o=0;for(;o<t.C;){const l=e.cells[o],r=Math.min(l.span,t.C-o);l.skip||(n+=`<td${l.rs>1?` rowspan="${l.rs}"`:""}${r>1?` colspan="${r}"`:""}>${u(s(l.t))}</td>`),o+=r}return n+"</tr>"})).join("")+"</table>"}function at(t,e,s,n=[],o=!1){const l=t.filter((t=>t.x1-t.x0>=4*s)).sort(((t,e)=>t.y-e.y||t.x0-e.x0)),r=[];for(const t of l){const e=r[r.length-1];e&&Math.abs(e.y-t.y)<=2&&t.x0-e.x1<=12*s?(e.x0=Math.min(e.x0,t.x0),e.x1=Math.max(e.x1,t.x1)):r.push({...t})}for(let t=r.length-1;t>=0;t--)r[t].x1-r[t].x0<8*s&&r.splice(t,1);const a=new Set,i=[],h=(t,n,o,l)=>e.filter((e=>!e.done&&(e.top+e.bot)/2>t&&(e.top+e.bot)/2<n&&e.x0>=o-2*s&&e.x1<=l+2*s));for(let l=0;l<r.length;l++){if(a.has(l))continue;const c=[l];for(let t=l+1;t<r.length;t++){if(a.has(t))continue;const e=r[c[c.length-1]],n=r[t];Math.min(e.x1,n.x1)-Math.max(e.x0,n.x0)>=.8*Math.min(e.x1-e.x0,n.x1-n.x0)&&n.y-e.y<=40*s&&c.push(t)}const f=c.map((t=>r[t])),x=Math.min(...f.map((t=>t.x0))),p=Math.max(...f.map((t=>t.x1)));if(f.length>=4){const t=f.slice(1).map(((t,e)=>t.y-f[e].y));let e=1,s=1;for(let n=1;n<t.length;n++)e=t[n]>0&&Math.abs(t[n]-t[n-1])<=.08*t[n-1]?e+1:1,s=Math.max(s,e);if(s>=3){c.forEach((t=>a.add(t)));continue}}let m=[],u=null;for(let t=0;t+1<f.length;t++){const e=h(f[t].y,f[t+1].y,x,p);e.length&&!n.some((e=>e.top<f[t+1].y-1&&e.bot>f[t].y+1&&e.x0<p&&e.x1>x))&&(lt(e,s,[],!0)||e.every((t=>Q(t).length>=2)))?u?u.b=t+1:(u={a:t,b:t+1},m.push(u)):u=null}for(const n of m){for(;n.a>0;){const t=h(f[n.a-1].y,f[n.a].y,x,p);if(!t.length||t.length>4||!t.every((t=>t.text.length<=60&&!/^(table|figure|fig\.|tab\.|표|그림)\s*\d/i.test(t.text))))break;n.a--}let l=f[n.a].y,r=f[n.b].y,m=h(l,r,x,p);if(m.length<2)continue;const u=nt(m.map((t=>({l:t,cs:Q(t)}))),s);if(u){const t=e.filter((t=>!t.done&&t.top>r-1&&t.x0>=x-2*s&&t.x1<=p+2*s)).sort(((t,e)=>t.top-e.top));let n=r;for(const e of t){const t=Q(e);if(e.top-n>2.2*s||t.length<2||!t.every((t=>u.some((e=>Math.abs(t.x0-e)<=.9*s))&&t.text.length<=40||O.test(t.text))))break;m.push(e),n=e.bot}r=Math.max(r,n)}const g=lt(m,s,f.slice(n.a,n.b+1).map((t=>t.y)),!0,t.filter((t=>t.y>=l-1&&t.y<=r+1&&t.x1>x&&t.x0<p)));if(g&&!(o&&g.rows.length>n.b-n.a)){for(let t=n.a;t<=n.b;t++)a.add(c[t]);for(const t of m)t.done=!0;i.push({kind:"table",html:rt(g),top:l,bot:r,x0:x,x1:p,src:"rule"})}}}return i}function it(t){if(t.length<6)return[];const e=Math.min(...t.map((t=>t.x0))),s=Math.max(...t.map((t=>t.x1))),n=Math.ceil(s-e)+1,o=new Float64Array(n);for(const s of t)for(let t=Math.max(0,Math.floor(s.x0-e));t<=Math.min(n-1,Math.ceil(s.x1-e));t++)o[t]+=s.bot-s.top;const l=[...o].filter((t=>t>0)).sort(((t,e)=>t-e)),r=l[Math.floor(.6*l.length)]||0,a=o.reduce(((t,e)=>t+e),0),i=[];for(let t=Math.floor(.2*n);t<Math.ceil(.8*n);)if(o[t]<=.2*r){let s=t;for(;s<n&&o[s]<=.2*r;)s++;const l=o.slice(0,t).reduce(((t,e)=>t+e),0);s-t>=6&&l>=.25*a&&a-l>=.25*a&&i.push(e+(t+s)/2),t=s}else t++;return i}function ht(t,e){if(!e.length)return t;const s=[];for(const n of t){const t=e.length+1,o=Array.from({length:t},(()=>[]));for(const t of n.its){let s=0;for(;s<e.length&&(t.x0+t.x1)/2>e[s];)s++;o[s].push(t)}const l=o.filter((t=>t.length));if(l.length<=1)s.push(n);else for(const t of l)s.push({...n,its:t,x0:Math.min(...t.map((t=>t.x0))),x1:Math.max(...t.map((t=>t.x1))),text:tt(t,n.size),parent:n})}return s}const ct=/^[\s(*~∼±+−–-]*\d[\d,.\s]*\s*[A-Za-z%μµ°]{0,4}\.?\)?$/;function ft(t,e){const s=t.map((t=>Q(t)));if(s[0].length<3||s[0].length!==s[1].length)return!1;const n=ot(t.map(((t,e)=>({l:t,cs:s[e]}))),e);if(!n||n.length!==s[0].length)return!1;const o=s.map((t=>t.filter((t=>ct.test(t.text))).length/t.length));return o[0]<=.25&&o[1]>=.75||o[1]<=.25&&o[0]>=.75&&!1}function xt(t){const e=t.sort(((t,e)=>t.base-e.base||t.x0-e.x0)),s=[];for(const t of e){let e=null;for(let n=s.length-1;n>=0&&n>=s.length-6;n--){const o=s[n],l=Math.min(o.bot,t.bot)-Math.max(o.top,t.top),r=Math.min(o.bot-o.top,t.bot-t.top),a=Math.max(o.size,t.size)/Math.min(o.size,t.size);if(!!o.its[0].rot==!!t.rot&&(Math.abs(o.base-t.base)<=.3*Math.min(o.size,t.size)||a<1.8&&l>.55*r&&!o.its.some((e=>e.x0<t.x1-1&&t.x0<e.x1-1)))){e=o;break}}e?(e.its.push(t),e.top=Math.min(e.top,t.top),e.bot=Math.max(e.bot,t.bot),(t.size>1.05*e.size||t.s.length>2)&&(e.base=t.size>=e.size?t.base:e.base,e.size=Math.max(e.size,t.size))):s.push({base:t.base,size:t.size,top:t.top,bot:t.bot,its:[t]})}for(const t of s){if(!t.its.length||!t.its.every((t=>t.s.trim().length<=3)))continue;const e=s.find((e=>e!==t&&e.its.length&&t.size<.8*e.size&&t.bot>e.top+.1*e.size&&t.top<e.top+.3*e.size&&t.its.every((t=>e.its.some((s=>Math.abs(t.x0-s.x1)<=.6*e.size||Math.abs(s.x0-t.x1)<=.6*e.size))))));e&&(e.its.push(...t.its),e.top=Math.min(e.top,t.top),t.its=[])}for(const t of s){if(!t.its.length){t.text="";continue}t.its.sort(((t,e)=>t.x0-e.x0));let e="",s="",n=null,o=!1,r="",a=!1;for(const i of t.its){const h=i.size<.8*t.size?i.base<t.base-.15*t.size?"p":i.base>t.base+.1*t.size?"d":"":"";if(!r||h===r&&!!i.bold===o||(s+=l[r+"1"],r=""),o&&!i.bold&&(s+=l.b1,o=!1),null!=n){const o=i.x0-n.x1,l=i.size<.8*t.size&&i.base<t.base-.15*t.size,r=/[.·…]$/.test(e)&&/^[.·…]/.test(i.s);l||r||/\s$/.test(e)||/^\s/.test(i.s)||!et(n,o,Math.min(i.size,n.size),i)||(e+=" ",s+=" ")}!o&&i.bold&&(s+=l.b0,o=!0),h&&!r&&(s+=l[h+"0"],r=h),e+=i.s,s+=i.s,n=i,(h||i.bold)&&(a=!0)}r&&(s+=l[r+"1"]),o&&(s+=l.b1),t.text=e.replace(/\s+/g," ").trim(),t.stext=a?s.replace(/\s+/g," ").trim():null,t.x0=t.its[0].x0,t.x1=Math.max(...t.its.map((t=>t.x1))),t.its.reduce(((t,e)=>t+e.s.length),0),t.bold=t.its.filter((t=>t.bold)).reduce(((t,e)=>t+e.s.replace(/\s/g,"").length),0)>=.95*t.its.reduce(((t,e)=>t+e.s.replace(/\s/g,"").length),0);const i={};for(const e of t.its){const t=Math.round(2*e.size)/2;i[t]=(i[t]||0)+e.s.length}t.fsize=+Object.entries(i).sort(((t,e)=>e[1]-t[1]))[0][0]}return s.filter((t=>t.text)).sort(((t,e)=>t.top-e.top||t.x0-e.x0))}function pt(t,e=[]){const s=[];for(const n of t){let t=null;for(const o of n.its)t&&(o.x0-t.x1>Math.max(.8*n.size,5)||e.some((e=>t.x1<=e+1&&o.x0>=e-1)))&&(s.push(t),t=null),t||(t={its:[],x0:o.x0,x1:o.x1,top:o.top,bot:o.bot}),t.its.push(o),t.x1=Math.max(t.x1,o.x1),t.top=Math.min(t.top,o.top),t.bot=Math.max(t.bot,o.bot);t&&s.push(t)}return s}function mt(t,e,s=.45*e,n=[],o=!1){if(t.length<=1)return[t];const l=t=>{const e=[...t].sort(((t,e)=>t.top-e.top)),n=[];let o=e[0].bot;const l=Math.max(s,1.35*(t=>{const e=[...t].sort(((t,e)=>t.top-e.top)),s=[];for(let t=0;t<e.length;t++){const n=e[t],o=n.bot-n.top;for(let l=t+1;l<e.length&&l<t+12;l++){const t=e[l],r=t.top-n.bot;if(Math.min(n.x1,t.x1)-Math.max(n.x0,t.x0)>.5*Math.min(n.x1-n.x0,t.x1-t.x0)&&r>-.5&&r<2.5*o){s.push(Math.max(0,r));break}}}return s.length>=3?x(s):0})(t));for(let t=1;t<e.length;t++)e[t].top-o>=l&&n.push({at:(o+e[t].top)/2,w:e[t].top-o}),o=Math.max(o,e[t].bot);return n},r=t=>{const s=(t=>{const s=[...t].sort(((t,e)=>t.x0-e.x0)),o=[];let l=s[0].x1;const r=t=>{const e=t.filter((t=>!t.tbl));if(new Set(e.map((t=>Math.round(t.top)))).size>=3&&e.filter((t=>t.its.reduce(((t,e)=>t+e.s.length),0)>=20)).length>=.6*e.length)return!0;const s=[...e].sort(((t,e)=>t.top-e.top)).map((t=>t.its.map((t=>t.s)).join(" ").trim()));let n=0,o=0;for(let t=0;t+1<s.length;t++)n++,/^[a-z]/.test(s[t+1])&&o++;return n>=4&&o>=.6*n};for(let a=1;a<s.length;a++){const i=s[a].x0-l,h=n.some((t=>t>l-1&&t<s[a].x0+1));let c=i>=Math.max(1.2*e,9)||i>=5&&h;if(!c&&i>=5){const e=(l+s[a].x0)/2,n=t.filter((t=>t.x1<=e)),o=t.filter((t=>t.x0>=e));c=n.length+o.length===t.length&&r(n)&&r(o)}c&&o.push({at:(l+s[a].x0)/2,w:i+(h?100:0)}),l=Math.max(l,s[a].x1)}return o})(t).sort(((t,e)=>e.w-t.w));for(const n of s){const s=t.filter((t=>t.x1<=n.at)),o=t.filter((t=>t.x0>=n.at));if(s.length+o.length!==t.length)continue;const l=Math.max(...s.map((t=>t.x1)))-Math.min(...s.map((t=>t.x0))),r=Math.max(...o.map((t=>t.x1)))-Math.min(...o.map((t=>t.x0))),a=t=>new Set(t.map((t=>Math.round(t.top)))).size,i=t=>{const e=t.filter((t=>!t.tbl)).map((t=>t.its.map((t=>t.s)).join(" ").trim()));return e.length>=3&&e.filter((t=>t.length<=6||/^[\d\s.,%()+-]+$/.test(t))).length>=.75*e.length};if((!i(s)||!i(o))&&a(s)>=2&&a(o)>=2&&l>=6*e&&r>=6*e)return{L:s,R:o,at:n.at}}return null},a=r(t),i=o&&a&&(()=>{const s=Math.min(...t.map((t=>t.top))),n=Math.max(...t.map((t=>t.bot)));for(const o of l(t)){const l=t.filter((t=>(t.top+t.bot)/2<o.at)),a=t.filter((t=>(t.top+t.bot)/2>=o.at));if(!l.length||!a.length||a.some((t=>t.tbl||t.img))||n-o.at>2*(o.at-s))continue;const i=x(l.flatMap((t=>t.its.map((t=>t.size)))));if(!i||i>1.3*e||a.some((t=>t.its.some((t=>t.size>.92*i)))))continue;const h=r(l),c=t=>{const e=new Set(t.map((t=>Math.round((t.top+t.bot)/6)))).size;return e>=3&&t.reduce(((t,e)=>t+e.its.reduce(((t,e)=>t+(e.s.match(/[A-Za-z가-힣\u4e00-\u9fff]/g)||[]).length),0)),0)>=20*e};if(h&&c(h.L)&&c(h.R))return[l,a]}return null})();if(i)return[...mt(i[0],e,s,n,o),...mt(i[1],e,s,n,o)];if("4"===process.env.PDFMD_DEBUG&&console.error("[xy]",t.length,Math.min(...t.map((t=>t.top))).toFixed(0)+"-"+Math.max(...t.map((t=>t.bot))).toFixed(0),a?"x@"+Math.round(a.at):"-"),a){const t=mt(a.L,e,s,n,o),l=mt(a.R,e,s,n,o),r=[],i=t=>t.flatMap((t=>t.its.map((t=>t.size)))),h=t=>[...t].sort(((t,e)=>t.top-e.top||t.x0-e.x0)).map((t=>t.its.map((t=>t.s)).join(""))).join(" ").trim();for(;o&&t.length>1;){const e=t[t.length-1],s=t.slice(0,-1).flat(),n=x(i(s));if(e.some((t=>t.tbl||t.img))||!/^\d{1,3}\s*\S/.test(h(e))||Math.max(...i(e))>.92*n||Math.max(...a.R.map((t=>t.bot)))<Math.min(...e.map((t=>t.top))))break;r.unshift(t.pop())}return[...t,...l,...r]}const h=l(t);if(h.length){const l=h.map((t=>t.at)),a=Array.from({length:l.length+1},(()=>[]));for(const e of t){let t=0;for(;t<l.length&&(e.top+e.bot)/2>l[t];)t++;a[t].push(e)}let i=a.filter((t=>t.length));if(o&&i.length>1){const s=t=>new Set(t.map((t=>Math.round((t.top+t.bot)/6)))).size,n=t=>t.reduce(((t,e)=>t+e.its.reduce(((t,e)=>t+(e.s.match(/[A-Za-z가-힣\u4e00-\u9fff]/g)||[]).length),0)),0),o=t=>t.length&&n(t)>=8*s(t),l=(t,s=Math.max(1.2*e,9))=>{const n=[...t].sort(((t,e)=>t.x0-e.x0)),o=[];let l=n[0].x1;for(let t=1;t<n.length;t++)n[t].x0-l>=s&&o.push([l,n[t].x0]),l=Math.max(l,n[t].x1);return o},a=t=>x(t.flatMap((t=>t.its.map((t=>t.size))))),h=[];for(let s=0;s<i.length;){const n=i[s];let c=[...n],f=[],x=s+1,p=s;for(;x<i.length;x++){const s=i[x],h=i[x-1],m=[...c,...f.flat(),...s],u=r(m);if(!u||m.length>=t.length)break;const g=(t,e)=>t.some((t=>e.includes(t))),b=Math.min(...s.map((t=>t.top)))-Math.max(...h.map((t=>t.bot))),M=Math.min(...s.map((t=>t.x0))),d=Math.max(...s.map((t=>t.x1))),y=l(s),z=l(n,3).find((([t,e])=>t<=u.at&&u.at<=e)),w=l(m,3).find((([t,e])=>t<=u.at&&u.at<=e));if(!(z&&w&&w[1]-w[0]>=.4*(z[1]-z[0])&&l(n).every((([t,e])=>e<=M||t>=d||y.some((([s,n])=>Math.min(e,n)-Math.max(t,s)>0))))&&g(n,u.L)&&g(n,u.R)&&o(n.filter((t=>u.L.includes(t))))&&o(n.filter((t=>u.R.includes(t))))&&b<=3*Math.max(a(h),a(s),e)))break;g(s,u.L)&&g(s,u.R)?(c=m,f=[],p=x):f.push(s)}h.push(c),s=p+1}i=h}if(i.length>1)return i.flatMap((t=>mt(t,e,s,n,o)))}return[t]}const ut=/^[•●▪■◦○◆◇►▸‣⁃∙·❖➢✓✔※□❍❏-]\s*/,gt=/^[•‣⁃]\s*/,bt=/^(\d{1,2}[.)]|[가-하][.)]|\(\d{1,2}\)|\([가-하]\)|[①-⑳]|[a-z][.)]|[IVX]+\.)\s*/,Mt=t=>/^(?:[-–—]\s*)?(?:page\s*)?\d{1,4}(?:\s*(?:of|\/)\s*\d{1,4})?(?:\s*[-–—])?$/i.test(t)||/^[ivxlcdm]{1,6}$/i.test(t);function dt(t,e,s=0,n=!1){const o=xt(t.flatMap((t=>t.its.map((t=>({...t})))))),l=[];let r=null;const a=Math.max(...o.map((t=>t.x1))),i=Math.min(...o.map((t=>t.x0)));for(const t of o){if(r){const o=r.lines[r.lines.length-1],h=t.top-o.bot,c=Math.min(o.bot-o.top,t.bot-t.top),f=t=>t.text.length<=90&&/[A-Z]{3}/.test(t.text)&&t.text===t.text.toUpperCase()&&(t.text.match(/[A-Za-z]/g)||[]).length>=.8*(t.text.match(/[A-Za-z가-힣]/g)||[]).length,x=/[a-z]-$/.test(o.text)||/^[a-z]/.test(t.text);if(!(h>Math.max(.75*c,1.5*s)||Math.abs(t.fsize-o.fsize)>.12*o.fsize||!x&&t.bold!==o.bold&&(t.text.length<90||o.text.length<90)||!x&&f(o)!==f(t)||ut.test(t.text)||/^(\d{1,2}[.)]|[a-z][.)]|\(\d{1,2}\))\s/.test(t.text)&&o.x1<a-4*e||t.x0-i>1.5*e&&t.x0-o.x0>1.5*e&&!ut.test(r.lines[0].text)&&!bt.test(r.lines[0].text)||/[.:!?。」”)]$/.test(o.text)&&o.x1<a-5*e||n&&(ut.test(r.lines[0].text)||bt.test(r.lines[0].text))&&t.x0<r.lines[0].x0-1*e&&h>.75*c&&!x)){r.lines.push(t);continue}l.push(r)}r={lines:[t]}}return r&&l.push(r),l.map((t=>{let e="",s="";for(const n of t.lines){if(!e){e=n.text,s=n.stext||n.text;continue}const o=W(t.lines[t.lines.indexOf(n)-1],n,a);e+=o+n.text,s+=o+(n.stext||n.text)}const n={};for(const e of t.lines)n[e.fsize]=(n[e.fsize]||0)+e.text.length;const o=t.lines[0],l=o.its,r=t=>/^\d{1,4}$/.test(t.s.trim());return{kind:"p",text:e,stext:s,pnum:1===t.lines.length&&l.length>=2&&(r(l[0])&&l[1].x0-l[0].x1>=.9*o.size||r(l[l.length-1])&&l[l.length-1].x0-l[l.length-2].x1>=.9*o.size),wide:t.lines.some((t=>t.its.some(((e,s)=>s&&e.x0-t.its[s-1].x1>=2.5*t.size)))),grid:t.lines.every((t=>t.its.every((t=>t.grid)))),top:t.lines[0].top,bot:t.lines[t.lines.length-1].bot,x0:Math.min(...t.lines.map((t=>t.x0))),x1:Math.max(...t.lines.map((t=>t.x1))),fsize:+Object.entries(n).sort(((t,e)=>e[1]-t[1]))[0][0],bold:t.lines.every((t=>t.bold)),nl:t.lines.length,chars:e.length}}))}async function yt(t,e,{korean:n=!1,tc:o=null,jst:l=null,images:r=!1}={}){const a=t.getViewport({scale:1}).transform,i=t.getViewport({scale:1}).height,h=await t.getOperatorList(),c=o||await t.getTextContent(),f=e=>{try{return t.commonObjs.has(e)&&t.commonObjs.get(e).differences||null}catch{return null}};!function(t,e,s,n,o=null){const l=[];let r=null,a=!1;const i=new Map;for(let s=0;s<t.fnArray.length;s++){const h=t.fnArray[s];if(h===e.setFont)r=t.argsArray[s][0];else if(h===e.showText){const e=r&&n(r),h=r&&o?o(r):"";if(/^([A-Z]{6}\+)?TeXCMMaths/.test(h)){let n=i.get(r);n||i.set(r,n={fname:h,d:e,reps:[]});for(const o of t.argsArray[s][0]||[])o&&"object"==typeof o&&"�"===o.unicode&&n.reps.push(v(h,o.originalCharCode,e&&e[o.originalCharCode],o.unicode)||"�");continue}for(const n of t.argsArray[s][0]||[]){if(!n||"object"!=typeof n||!n.unicode)continue;const t=e&&e[n.originalCharCode],s=!!t&&/\.(sc|smcp|c2sc)$/i.test(t),o="�"===n.unicode&&t?y(t):null;(s||o)&&(a=!0);for(const t of n.unicode)/\s/.test(t)||l.push({ch:t,sc:s,rep:o})}}}if(!a&&!i.size)return;const h={"¼":"=","þ":"+","ð":"(","Þ":")","½":"["};for(const t of s.items){const e=t.str&&i.get(t.fontName);if(!e)continue;const s=/^([A-Z]{6}\+)?TeXCMMathsSymbols\b/.test(e.fname),n=/^([A-Z]{6}\+)?TeXCMMathsItalic\b/.test(e.fname);t.str=[...t.str].map((t=>"�"===t&&e.reps.length?e.reps.shift():s&&h[t]?h[t]:n&&":"===t?".":n&&";"===t?",":t)).join("")}if(!a)return;let c=0;for(const t of s.items){if(!t.str||!t.str.trim()||i.has(t.fontName))continue;let e="",s=!1;for(const n of t.str){if(/\s/.test(n)){e+=n;continue}let t=c;for(;t<l.length&&t<c+24&&l[t].ch!==n;)t++;if(t<l.length&&l[t].ch===n){const o=l[t];if(c=t+1,o.rep&&1===o.rep.length){e+=o.rep,s=!0;continue}if(o.sc&&n.toUpperCase()!==n){e+=n.toUpperCase(),s=!0;continue}}e+=n}s&&(t.str=e)}}(h,e.OPS,c,f,(e=>{try{return t.commonObjs.has(e)&&t.commonObjs.get(e).name||""}catch{return""}}));const p=z(c,a,e.Util,(e=>{try{return t.commonObjs.has(e)&&t.commonObjs.get(e).name||""}catch{return""}}),n?function(t,e,s){const n=[],o=[];let l=0;for(let s=0;s<t.fnArray.length;s++){const r=t.fnArray[s];if(r===e.save)o.push(l);else if(r===e.restore)o.length&&(l=o.pop());else if(r===e.setTextRenderingMode)l=t.argsArray[s][0];else if(r===e.showText)for(const e of t.argsArray[s][0]||[])if(e&&"object"==typeof e&&e.unicode)for(const t of e.unicode)/\s/.test(t)||n.push({ch:t,b:2===l})}const r=new Set;if(!n.some((t=>t.b)))return r;let a=0;return s.items.forEach(((t,e)=>{let s=0,o=0;for(const e of t.str||""){if(/\s/.test(e))continue;let t=a;for(;t<n.length&&t<a+24&&n[t].ch!==e;)t++;t<n.length&&n[t].ch===e&&(s++,n[t].b&&o++,a=t+1)}s&&o>=.5*s&&r.add(e)})),r}(h,e.OPS,c):null,f);if(!p.length)return{blocks:[],sizes:{},chars:0};const m=n||(()=>{let t=0,e=0;for(const s of p)for(const n of s.s)/[가-힣]/.test(n)&&t++,/[A-Za-z가-힣]/.test(n)&&e++;return e>0&&t>=.3*e})(),g=t.getViewport({scale:1}).width,b=[];if(!m&&p.rot)for(const t of p.rot)t.bot-t.top>.25*i||t.x1<.08*g||t.x0>.92*g?b.push(t):p.push(t);if(l&&!o&&m)for(const t of xt([...p]))for(const e of H(t))q(l,e);L=l&&l.size?l:null;let{H:M,V:d,F:w,I:$,C:j,H0:A,V0:X}=k(h,e.OPS,e.Util,a,m);const C=m?function(t,e,s,n,o,l,r){const a=.3,i=[];for(const e of t)if(!(e.x1-e.x0<.5||e.y1-e.y0<.5||(e.x1-e.x0)*(e.y1-e.y0)>.75*l*r)&&(i.some((t=>Math.abs(t.x0-e.x0)<=a&&Math.abs(t.x1-e.x1)<=a&&Math.abs(t.y0-e.y0)<=a&&Math.abs(t.y1-e.y1)<=a))||i.push({...e}),i.length>2500))return null;if(i.length<2)return null;const h=(t,e)=>e.x0>=t.x0-a&&e.x1<=t.x1+a&&e.y0>=t.y0-a&&e.y1<=t.y1+a;for(const t of i)t.depth=i.filter((e=>e!==t&&h(e,t)&&!h(t,e))).length;const c=i.map(((t,e)=>e)),f=t=>c[t]===t?t:c[t]=f(c[t]),p=(t,e,s,n)=>Math.min(e,n)-Math.max(t,s);for(let t=0;t<i.length;t++)for(let e=t+1;e<i.length;e++){const s=i[t],n=i[e];s.depth===n.depth&&((Math.abs(s.x1-n.x0)<=a||Math.abs(n.x1-s.x0)<=a)&&p(s.y0,s.y1,n.y0,n.y1)>.5||(Math.abs(s.y1-n.y0)<=a||Math.abs(n.y1-s.y0)<=a)&&p(s.x0,s.x1,n.x0,n.x1)>.5)&&(c[f(t)]=f(e))}const m=new Map;i.forEach(((t,e)=>{const s=f(e);m.has(s)||m.set(s,[]),m.get(s).push(t)}));const u=[...m.values()].filter((t=>t.length>=2)),g=t=>({x0:Math.min(...t.map((t=>t.x0))),x1:Math.max(...t.map((t=>t.x1))),y0:Math.min(...t.map((t=>t.y0))),y1:Math.max(...t.map((t=>t.y1))),ys:S(t.flatMap((t=>[t.y0,t.y1])),a)}),b=(t,e,n)=>s.filter((e=>Math.abs(e.x-t)<=1.5)).reduce(((t,s)=>t+Math.max(0,Math.min(s.y1,n)-Math.max(s.y0,e))),0);for(let t=0;t<u.length;t++)for(let e=0;e<u.length;e++){const s=u[t],n=u[e];if(t===e||!s.length||!n.length||s[0].depth!==n[0].depth)continue;const o=g(s),l=g(n);if(l.x0<o.x1-a||l.x0-o.x1<20)continue;if(p(o.y0,o.y1,l.y0,l.y1)<.8*Math.min(o.y1-o.y0,l.y1-l.y0))continue;const[r,h]=o.ys.length<=l.ys.length?[o.ys,l.ys]:[l.ys,o.ys];if(r.length<3||r.filter((t=>h.some((e=>Math.abs(t-e)<=a)))).length<.8*r.length)continue;const c=Math.max(o.y0,l.y0),f=Math.min(o.y1,l.y1);b(o.x1,c,f)<.6*(f-c)||b(l.x0,c,f)<.6*(f-c)||i.some((t=>t.depth===s[0].depth&&t.x0<l.x0-a&&t.x1>o.x1+a&&t.y0<f&&t.y1>c))||(s.push(...n),n.length=0)}const M=(t,e)=>{let s=0;for(let n=1;n<e.length;n++)Math.abs(e[n]-t)<Math.abs(e[s]-t)&&(s=n);return s},d=[];for(const t of u){if(t.length<2)continue;const e=S(t.flatMap((t=>[t.x0,t.x1])),a),s=S(t.flatMap((t=>[t.y0,t.y1])),a),n=s.length-1,o=e.length-1;if(n<1||o<1||n*o>4e4)continue;const l=Array.from({length:n},(()=>new Array(o).fill(null))),r=[];let i=!1;for(const n of t){const t=M(n.x0,e),o=M(n.x1,e)-1,a=M(n.y0,s),h=M(n.y1,s)-1;if(o<t||h<a){i=!0;break}const c={r:a,c:t,rs:h-a+1,cs:o-t+1,its:[]};for(let e=a;e<=h&&!i;e++)for(let s=t;s<=o;s++){if(l[e][s]){i=!0;break}l[e][s]=c}r.push(c)}if(i)continue;let h=0;for(let t=1;t<n-1;t++)for(let e=0;e<o;e++)l[t][e]||h++;if(!(h>.3*Math.max(1,n-2)*o)){for(let t=0;t<n;t++)for(let e=0;e<o;e++)if(!l[t][e]){const s={r:t,c:e,rs:1,cs:0,its:[],hole:!0};for(r.push(s);e<o&&!l[t][e];)l[t][e]=s,s.cs++,e++;e--}for(const t of r.filter((t=>t.hole)).sort(((t,e)=>t.r-e.r)))if(!t.dead)for(;;){const e=r.find((e=>e.hole&&!e.dead&&e!==t&&e.c===t.c&&e.cs===t.cs&&e.r===t.r+t.rs));if(!e)break;t.rs+=e.rs,e.dead=!0;for(let s=e.r;s<e.r+e.rs;s++)for(let n=e.c;n<e.c+e.cs;n++)l[s][n]=t}for(let t=r.length-1;t>=0;t--)r[t].dead&&r.splice(t,1);for(const t of r)t.x0=e[t.c],t.x1=e[t.c+t.cs],t.top=s[t.r],t.bot=s[t.r+t.rs];d.push({Xs:e,Ys:s,R:n,C:o,cells:r,own:l,depth:t[0].depth,x0:e[0],x1:e[o],top:s[0],bot:s[n]})}}if(!d.length)return null;const y=(t,e,s)=>{let n=0;for(;n<t.C-1&&e>t.Xs[n+1];)n++;let o=0;for(;o<t.R-1&&s>t.Ys[o+1];)o++;return t.own[o][n]},z=(t,e,s)=>e>=t.x0&&e<=t.x1&&s>=t.top&&s<=t.bot;for(const t of n){if(t.used)continue;const e=(t.x0+t.x1)/2,s=(t.top+t.bot)/2;let n=null;for(const t of d)z(t,e,s)&&(!n||t.depth>n.depth)&&(n=t);n&&(y(n,e,s).its.push(t),t.grid=!0)}for(const t of d){for(const e of d)e.depth>t.depth&&z(t,(e.x0+e.x1)/2,(e.top+e.bot)/2)&&(y(t,(e.x0+e.x1)/2,(e.top+e.bot)/2).nest=!0);for(const e of o){const s=(e.x0+e.x1)/2,n=(e.y0+e.y1)/2;z(t,s,n)&&!d.some((e=>e.depth>t.depth&&z(e,s,n)))&&(y(t,s,n).img=!0)}}const w=[],v=[],$=[],k=t=>t.some(Boolean),j=t=>t.every(Boolean),A=t=>t.its.length>0||t.nest||t.img;for(const t of d){const{Xs:n,Ys:o,R:l,C:r,cells:a}=t,i=(t,e)=>{let s=0;for(let n=1;n<e.length;n++)Math.abs(e[n]-t)<Math.abs(e[s]-t)&&(s=n);return Math.abs(e[s]-t)<=1.5?s:-1},h=Array.from({length:l+1},(()=>new Array(r).fill(!1))),c=Array.from({length:l},(()=>new Array(r+1).fill(!1))),f=d.filter((e=>e.depth>t.depth&&z(t,(e.x0+e.x1)/2,(e.top+e.bot)/2))),p=(t,e,s,n)=>!f.some((o=>t>=o.x0-1&&e<=o.x1+1&&s>=o.top-1&&n<=o.bot+1)),m=(t,e,s)=>{const n=t.map((([t,n])=>[Math.max(t,e),Math.min(n,s)])).filter((([t,e])=>e>t)).sort(((t,e)=>t[0]-e[0]));let o=0,l=-1/0;for(const[t,e]of n)e<=l||(o+=e-Math.max(t,l),l=e);return o},u=h.map((()=>[])),g=Array.from({length:r+1},(()=>[]));for(const s of e){const e=i(s.y,o);e>=0&&s.x1>=t.x0&&s.x0<=t.x1&&p(s.x0,s.x1,s.y,s.y)&&u[e].push([s.x0,s.x1])}for(const e of s){const s=i(e.x,n);s>=0&&e.y1>=t.top&&e.y0<=t.bot&&p(e.x,e.x,e.y0,e.y1)&&g[s].push([e.y0,e.y1])}for(let t=0;t<=l;t++)for(let e=0;e<r;e++)h[t][e]=u[t].length>0&&m(u[t],n[e],n[e+1])>=.5*(n[e+1]-n[e]);for(let t=0;t<l;t++)for(let e=0;e<=r;e++)c[t][e]=g[e].length>0&&m(g[e],o[t],o[t+1])>=.5*(o[t+1]-o[t]);const b=new Array(l).fill(0);for(const t of a)for(let e=t.r;e<t.r+t.rs;e++)b[e]++;const M=Array.from({length:l},((t,e)=>k(c[e])||b[e]>=2&&j(h[e])&&j(h[e+1]))),y=new Array(l+1).fill(!1);for(const t of a)for(let e=t.r+1;e<t.r+t.rs;e++)y[e]=!0;for(let t=0;t<l;){let e=t;for(;e+1<l&&y[e+1];)e++;const s=e-t+1;if(s>1&&j(h[t])&&j(h[e+1])&&a.filter((e=>e.r===t&&e.rs===s)).length>=2)for(let s=t;s<=e;s++)M[s]=!0;t=e+1}const X=(t,e)=>{let s=a.filter((s=>s.r>=t&&s.r<=e)).map((t=>({...t,rs:Math.min(t.rs,e-t.r+1)}))),n=1/0,o=-1/0;for(let s=t;s<=e;s++){for(let t=0;t<=r;t++)c[s][t]&&(n=Math.min(n,t),o=Math.max(o,t));for(const t of[s,s+1])for(let e=0;e<r;e++)h[t][e]&&(n=Math.min(n,e),o=Math.max(o,e+1))}if(Number.isFinite(n)&&(s=s.filter((t=>t.c<o&&t.c+t.cs>n||A(t)))),!s.some(A))return null;const l=[];for(let n=t;n<=e;n++){const t=s.filter((t=>t.r===n));!t.length||t.some(A)||k(h[n])&&k(h[n+1])||l.push(n)}if(l.length){const t=t=>t-l.filter((e=>e<t)).length;s=s.filter((t=>!l.includes(t.r))).map((e=>({...e,r:t(e.r),rs:t(e.r+e.rs)-t(e.r)}))).filter((t=>t.rs>0))}for(let t=Math.max(...s.map((t=>t.c+t.cs)));t>1;){const e=s.filter((e=>e.c===t-1));if(!e.length||e.some(A)||e.length===s.length)break;s=s.filter((e=>e.c!==t-1)).map((e=>e.c+e.cs===t?{...e,cs:e.cs-1}:e)).filter((t=>t.cs>0)),t--}return s.y0=t,s.y1=e,s},S=[];for(let t=0;t<l;){if(!M[t]){t++;continue}let e=t;for(;e+1<l&&M[e+1];)e++;S.push(X(t,e)),t=e+1}for(const t of S){if(!t||!t.some(A))continue;const e=t.filter(A).length<2;if(e&&!(t.some((e=>e.r===t.y0&&e.hole))||!k(h[t.y0])&&c[t.y0].filter(Boolean).length>=2)||e&&new Set(t.flatMap((t=>[t.c,t.c+t.cs]))).size<3)continue;const s=[...new Set(t.flatMap((t=>[t.c,t.c+t.cs])))].sort(((t,e)=>t-e)),l=[...new Set(t.flatMap((t=>[t.r,t.r+t.rs])))].sort(((t,e)=>t-e)),r=new Map(s.map(((t,e)=>[t,e]))),i=new Map(l.map(((t,e)=>[t,e]))),f=t.map((t=>({r0:i.get(t.r),r1:i.get(t.r+t.rs)-1,c0:r.get(t.c),c1:r.get(t.c+t.cs)-1,its:t.its,x0:t.x0,x1:t.x1,top:t.top,bot:t.bot,hole:t.hole})));for(const e of t)for(const t of e.its)t.used=!0;const x=t.y0,p=t.y1,m=t=>o[t+1]-o[t]<8&&!a.some((e=>e.r===t&&A(e)));let u=p;for(;u>x&&!k(h[u])&&m(u-1);)u--;let g=x+1;for(;g<=p&&!k(h[g])&&m(g);)g++;const b=(g>p||k(h[g]))&&!k(h[x])&&c[x].filter(Boolean).length>=2,M=(u<=x||k(h[u]))&&!k(h[p+1])&&c[p].filter(Boolean).length>=2,d=t.some((t=>t.r===x&&t.hole));w.push({top:Math.min(...t.map((t=>t.top))),bot:Math.max(...t.map((t=>t.bot))),x0:Math.min(...t.map((t=>t.x0))),x1:Math.max(...t.map((t=>t.x1))),cells:f,R:l.length-1,C:s.length-1,Xs:s.map((t=>n[t])),src:"clip",openTop:b,openBot:M,holeTop:d,frag:e})}for(let t=0;t<l;t++){if(M[t])continue;const e=a.filter((e=>e.r===t&&e.its.some((t=>!t.used)))).sort(((t,e)=>t.c-e.c));if(e.length<2)continue;const s=e.flatMap((t=>t.its.filter((t=>!t.used)))),n=e.map((t=>U(t.its.filter((t=>!t.used)),t).replace(/\n/g," "))).filter(Boolean).join(" ");for(const t of s)t.used=!0;$.push({text:n,top:Math.min(...s.map((t=>t.top))),bot:Math.max(...s.map((t=>t.bot))),x0:Math.min(...s.map((t=>t.x0))),x1:Math.max(...s.map((t=>t.x1))),fsize:Math.round(2*x(s.map((t=>t.size))))/2,bold:s.every((t=>t.bold))})}v.push({x0:t.x0,x1:t.x1,top:t.top,bot:t.bot})}return{tables:w,areas:v,paras:$}}(j,A,X,p,$,t.getViewport({scale:1}).width,i):null;if(C){const t=(t,e,s,n)=>C.areas.some((o=>t>=o.x0-2&&e<=o.x1+2&&s>=o.top-2&&n<=o.bot+2));M=M.filter((e=>!t(e.x0,e.x1,e.y,e.y))),d=d.filter((e=>!t(e.x,e.x,e.y0,e.y1))),w=w.filter((e=>!t(e.x0,e.x1,e.y0,e.y1)))}const B=P(M,d,p,w);C&&B.push(...C.tables),B.push(...Y(w,p,t.getViewport({scale:1}).width,i,B,x(p.map((t=>t.size)))||10)),B.push(...function(t,e,s,n){const o=[];for(const l of t){const t=e.filter((t=>(t.x0+t.x1)/2>l.x0&&(t.x0+t.x1)/2<l.x1&&(t.y0+t.y1)/2>l.top&&(t.y0+t.y1)/2<l.bot)),r=l.its.filter((t=>!t.used));if(!t.length||!r.length||l.x1-l.x0<.6*s||l.bot-l.top>6*n||xt(r.map((t=>({...t})))).length>2)continue;const a=[...r.map((t=>({x0:t.x0,x1:t.x1,t:t}))),...t.map((t=>({x0:t.x0,x1:t.x1,img:!0})))].sort(((t,e)=>t.x0-e.x0)),i=[];for(const t of a){const e=i[i.length-1];e&&t.x0-e.x1<1.5*n?(e.x1=Math.max(e.x1,t.x1),t.t&&e.its.push(t.t)):i.push({x0:t.x0,x1:t.x1,its:t.t?[t.t]:[],img:!!t.img})}if(i.length<2||!i.some((t=>t.its.length)))continue;const h=[l.x0,...i.slice(1).map(((t,e)=>(i[e].x1+t.x0)/2)),l.x1],c=i.map(((t,e)=>({r0:0,r1:0,c0:e,c1:e,its:t.its,x0:h[e],x1:h[e+1],top:l.top,bot:l.bot})));for(const t of r)t.used=!0;o.push({top:l.top,bot:l.bot,x0:l.x0,x1:l.x1,cells:c,R:1,C:i.length,Xs:h,src:"logo"})}return o}(B.boxes||[],$,t.getViewport({scale:1}).width,x(p.map((t=>t.size)))||10)),B.push(...function(t,e,s=[]){const n=t.filter((t=>t.its.some((t=>!t.used)))).sort(((t,e)=>t.top-e.top||t.x0-e.x0)),o=new Set,l=[],r=(t,e)=>s.filter((s=>!s.used&&(s.top+s.bot)/2>t.top&&(s.top+s.bot)/2<t.bot&&s.x0>=t.x1-1&&s.x1<=e.x0+1));for(const t of n){if(o.has(t))continue;const s=[t];for(const t of n){const n=s[s.length-1];if(t===n||o.has(t)||Math.abs(t.top-n.top)>2||Math.abs(t.bot-n.bot)>2||t.x0<n.x1-1)continue;const l=r(n,t),a=l.length&&l.every((t=>I.test(t.s.replace(/\s/g,""))));(t.x0-n.x1<=3*e||a&&t.x0-n.x1<=10*e)&&(a&&(t.mid=l),s.push(t))}if(s.length<2)continue;const a=[],i=[s[0].x0];let h=0;for(const[t,e]of s.entries()){if(t&&e.x0-s[t-1].x1>1){a.push({r0:0,r1:0,c0:h,c1:h,its:e.mid||[],x0:s[t-1].x1,x1:e.x0,top:e.top,bot:e.bot}),h++,i.push(e.x0);for(const t of e.mid||[])t.used=!0}a.push({r0:0,r1:0,c0:h,c1:h,its:e.its.filter((t=>!t.used)),x0:e.x0,x1:e.x1,top:e.top,bot:e.bot}),h++,i.push(e.x1)}for(const t of s){o.add(t);for(const e of t.its)e.used=!0}l.push({top:Math.min(...s.map((t=>t.top))),bot:Math.max(...s.map((t=>t.bot))),x0:s[0].x0,x1:s[s.length-1].x1,cells:a,R:1,C:h,Xs:i,src:"boxes"})}return l}(B.boxes||[],x(p.map((t=>t.size)))||10,p)),B.push(...function(t,e,s,n){const o=[];for(const l of t){const r=l.its.filter((t=>!t.used));if(!r.length||l.x1-l.x0>.2*s||l.bot-l.top>8*n)continue;const a=e.filter((e=>!e.used&&!r.includes(e)&&!t.some((t=>t!==l&&!(t.x0<=l.x0+1&&t.x1>=l.x1-1&&t.top<=l.top+1&&t.bot>=l.bot-1)&&t.its.includes(e)))&&(e.top+e.bot)/2>l.top-.5*n&&(e.top+e.bot)/2<l.bot+.5*n&&e.x1<=l.x0+2&&e.x0>=l.x0-.5*s));if(!a.length||l.x0-Math.max(...a.map((t=>t.x1)))>3*n)continue;const i=Math.min(...a.map((t=>t.x0))),h=Math.min(l.top,...a.map((t=>t.top))),c=Math.max(l.bot,...a.map((t=>t.bot))),f=[{r0:0,r1:0,c0:0,c1:0,its:a,x0:i,x1:l.x0,top:h,bot:c},{r0:0,r1:0,c0:1,c1:1,its:r,x0:l.x0,x1:l.x1,top:h,bot:c}];for(const t of[...a,...r])t.used=!0;o.push({top:h,bot:c,x0:i,x1:l.x1,cells:f,R:1,C:2,Xs:[i,l.x0,l.x1],src:"seal"})}return o}(B.boxes||[],p,t.getViewport({scale:1}).width,x(p.map((t=>t.size)))||10)),B.push(...function(t,e,s){const n=[];for(const o of t){const t=o.its.filter((t=>!t.used));if(o.x1-o.x0<.6*e||o.bot-o.top>.4*s||t.length<2)continue;const l=xt(t.map((t=>({...t}))));if(l.length<2)continue;let r=0;const a=t=>x(l.slice(t).map((t=>t.fsize)));for(;r<l.length-1&&l[r].fsize>=1.25*a(r+1);)r++;if(!r)continue;const i=(l[r-1].bot+l[r].top)/2,h=[{r0:0,r1:0,c0:0,c1:0,its:l.slice(0,r).flatMap((t=>t.its)),x0:o.x0,x1:o.x1,top:o.top,bot:i},{r0:1,r1:1,c0:0,c1:0,its:l.slice(r).flatMap((t=>t.its)),x0:o.x0,x1:o.x1,top:i,bot:o.bot}];for(const e of t)e.used=!0;n.push({top:o.top,bot:o.bot,x0:o.x0,x1:o.x1,cells:h,R:2,C:1,Xs:[o.x0,o.x1],src:"title"})}return n}(B.boxes||[],t.getViewport({scale:1}).width,i));const O=p.filter((t=>!t.used)),F=x(O.map((t=>t.size)))||x(p.map((t=>t.size)))||10,D=xt(O.map((t=>({...t})))),T=at(M.filter((t=>!B.some((e=>t.y>=e.top-2&&t.y<=e.bot+2&&t.x0>=e.x0-2&&t.x1<=e.x1+2)))),D,F,B,m),R=it(O.filter((t=>!t.used)));{const t=()=>!m;m||T.push(...function(t,e){const s=t.filter((t=>!t.done)).sort(((t,e)=>t.top-e.top||t.x0-e.x0)),n=[];for(let t=0;t<s.length;t++){const o=s[t];if(o.done)continue;const l=Q(o);if(l.length<3||!o.its.every((t=>t.bold))||l.some((t=>t.text.length>40||!/[A-Za-z]{2}/.test(t.text))))continue;const r=l.map((t=>t.x0)),a=.8*e,i=r.length,h=t=>{let e=-1;for(let s=0;s<i;s++)t>=r[s]-a&&(e=s);return e},c=[];let f=o;for(let n=t+1;n<s.length;n++){const t=s[n];if(t.done)continue;if(t.top-f.bot>2.5*Math.max(e,t.size))break;const o=Q(t);if(o.some((t=>h(t.x0)<0||t.x1>(r[h(t.x0)+1]??1/0)+a)))break;c.push(...o.map((e=>({k:h(e.x0),top:t.top,bot:t.bot,text:e.text,l:t})))),f=t}if(new Set(c.map((t=>t.l))).size<4||new Set(c.map((t=>t.k))).size<i)continue;const x=[],p=[],m=Array.from({length:i},((t,e)=>c.filter((t=>t.k===e)).sort(((t,e)=>t.top-e.top))));for(const t of m)for(let s=1;s<t.length;s++)t[s].top-t[s-1].top>.3*e&&p.push(t[s].top-t[s-1].top);const g=p.length?[...p].sort(((t,e)=>t-e))[Math.floor(p.length/4)]:1.2*e;m.forEach(((t,e)=>t.forEach(((s,n)=>{(!n||s.top-t[n-1].top>1.3*g)&&x.push({k:e,y:s.top})}))));const b=S(x.filter((t=>t.k<=1)).map((t=>t.y)),.6*e);if(b.length<2)continue;const M=t=>{let s=0;for(;s+1<b.length&&t>=b[s+1]-.6*e;)s++;return s},d=Array.from({length:b.length},(()=>Array.from({length:i},(()=>[]))));for(const t of c)d[M(t.top)][t.k].push(t.text);if(d.flat().filter((t=>t.length)).length<.5*b.length*i)continue;const y=[];for(let t=0;t<b.length;t++)y.push(d[t].map((t=>t.join(" "))));let z="<table><tr>"+l.map((t=>`<td>${u(t.text)}</td>`)).join("")+"</tr>";for(let t=0;t<b.length;t++){let e=y[t].map((t=>`<td>${u(t)}</td>`));if(!y[t][0]&&t>0)e=e.slice(1);else{let s=1;for(;t+s<b.length&&!y[t+s][0];)s++;s>1&&(e[0]=`<td rowspan="${s}">${u(y[t][0])}</td>`)}z+="<tr>"+e.join("")+"</tr>"}z+="</table>";const w=[o,...new Set(c.map((t=>t.l)))];for(const t of w)t.done=!0;n.push({src:"head",kind:"table",html:z,top:o.top,bot:Math.max(...w.map((t=>t.bot))),x0:Math.min(...w.map((t=>t.x0))),x1:Math.max(...w.map((t=>t.x1)))})}return n}(D,F)),T.push(...function(t,e,n=[],o=()=>!0){const l=ht(t.filter((t=>!t.done)),n).sort(((t,e)=>t.top-e.top||t.x0-e.x0)),r=[],a=[];for(const t of l){const s=a.find((s=>!s.closed&&t.top<s.bot+.3*e&&Math.min(t.x1,s.x1)-Math.max(t.x0,s.x0)>-4*e));if(s)s.ls.push(t),s.bot=Math.max(s.bot,t.bot),s.x0=Math.min(s.x0,t.x0),s.x1=Math.max(s.x1,t.x1);else{for(const s of a)t.top>=s.bot+.3*e&&Math.min(t.x1,s.x1)-Math.max(t.x0,s.x0)>0&&(s.closed=!0);a.push({ls:[t],top:t.top,bot:t.bot,x0:t.x0,x1:t.x1})}}const i=t=>{const s=t.ls.flatMap((t=>Q(t).map((e=>({...e,top:t.top}))))).sort(((t,e)=>t.x0-e.x0)),n=[];for(const t of s){const s=n.find((s=>Math.abs(s.x0-t.x0)<=.8*e||t.x0<s.x1+.6*e&&t.x1>s.x0));s?(s.parts.push(t),s.x0=Math.min(s.x0,t.x0),s.x1=Math.max(s.x1,t.x1)):n.push({x0:t.x0,x1:t.x1,parts:[t]})}return n};a.sort(((t,e)=>t.top-e.top));for(let t=0;t<a.length;){const n=i(a[t]);if(n.length<2){t++;continue}const l=[{b:a[t],f:n}];let h=t+1;const c=(t,e)=>{e.ls.push(...t.ls),e.top=Math.min(e.top,t.top),e.bot=Math.max(e.bot,t.bot),e.x0=Math.min(e.x0,t.x0),e.x1=Math.max(e.x1,t.x1),t.ls=[]};for(;h<a.length;){const t=a[h],s=i(t),n=l[l.length-1].b;if(s.length<2&&l.length>=1){const s=Math.min(...l.map((t=>t.b.x0))),n=Math.max(...l.map((t=>t.b.x1))),o=(t.top+t.bot)/2,r=[...l.map((t=>t.b)),...a.slice(h+1,h+3)].find((s=>s.ls.length&&o>s.top&&o<s.bot&&t.top-s.top<2.6*e));if(r&&t.x0>=s-.5*e&&t.x1<=n+.5*e&&t.bot-t.top<2.6*e){c(t,r);const e=l.find((t=>t.b===r));e&&(e.f=i(r)),h++;continue}}if(s.length<2||t.top-n.bot>2.6*e||Math.min(t.x1,n.x1)-Math.max(t.x0,n.x0)<.5*Math.min(t.x1-t.x0,n.x1-n.x0))break;l.push({b:t,f:s}),h++}const f=l.filter((t=>t.b.ls.length>=2)).length;if(l.length>=3&&f>=2){const n=S(l.flatMap((t=>t.f.map((t=>t.x0)))),.8*e).filter((t=>l.filter((s=>s.f.some((s=>Math.abs(s.x0-t)<=.8*e)))).length>=Math.max(2,.5*l.length)));if(n.length>=2){const a=n.length,i=t=>{let s=0;for(;s<a-1&&t>=n[s+1]-.8*e;)s++;return s},c=l.map((t=>{const e=Array.from({length:a},(()=>[]));for(const s of t.f)for(const t of s.parts)e[i(t.x0)].push(t);return e.map((t=>t.sort(((t,e)=>t.top-e.top||t.x0-e.x0)).map((t=>t.text)).join(" ").trim()))})),f=c.flat().filter(Boolean),x=f.reduce(((t,e)=>t+e.length),0)/Math.max(1,f.length),p=f.filter((t=>(t.match(/[A-Za-z가-힣]/g)||[]).length>=3)).length,m=f.filter((t=>/[∂√∑∫≤≥±×÷=∣]/.test(t))).length,g=c.map((t=>t[a-1])).filter(Boolean),b=g.length>=3&&g.every((t=>/^([ivxlc]+|\d{1,4})(\s+\d{1,4})*$/i.test(t))),M=f.filter((t=>t.length>30)).length;let d=0,y=0;for(let t=0;t<a;t++)for(let e=0;e+1<c.length;e++)c[e][t]&&c[e+1][t]&&(d++,/[a-z,;'’-]$/.test(c[e][t])&&/^[a-z(“"‘]/.test(c[e+1][t])&&y++);if(d>=2&&y>=.4*d){t++;continue}const z=a>=3&&f.length>=.6*c.length*a&&x<=45&&p>=.5*f.length&&m<2&&!b&&M<=.5*f.length&&!c.flat().some((t=>/^(figure|fig\.|table)\s*\d/i.test(t)));"2"===process.env.PDFMD_DEBUG&&console.error("[pdfmd] 띠 표 후보",a,c.length,"okShape",z,{filled:f.length,avg:Math.round(x),letters:p,mathy:m,toc:b,longCells:M},c.slice(0,4).map((t=>t.map((t=>t.slice(0,12))).join(" | "))));const w="<table>"+c.map((t=>"<tr>"+t.map((t=>`<td>${u(s(t))}</td>`)).join("")+"</tr>")).join("")+"</table>";if(z&&o(w)){for(const t of l)for(const e of t.b.ls)if(e.done=!0,e.parent){e.parent.part=(e.parent.part||0)+1;for(const t of e.its)t.tdone=!0}r.push({src:"band",kind:"table",html:w,top:l[0].b.top,bot:l[l.length-1].b.bot,x0:Math.min(...l.map((t=>t.b.x0))),x1:Math.max(...l.map((t=>t.b.x1)))}),t=h;continue}}}t++}return r}(D,F,R,t)),T.push(...function(t,e,s=[],n=()=>!0){const o=ht(t.filter((t=>!t.done)),s).sort(((t,e)=>t.top-e.top||t.x0-e.x0)),l=[];let r=0;for(;r<o.length;){if(Q(o[r]).length<2){r++;continue}let t=r+1;const s=[o[r]];for(;t<o.length&&o[t].top-s[s.length-1].bot<=1.6*e&&Q(o[t]).length>=2;)s.push(o[t]),t++;let a=null;if(1===s.length){const t=Q(s[0]),n=o[r-1],l=t.map((t=>t.x0));t.length>=3&&t.filter((t=>ct.test(t.text))).length>=.75*t.length&&n&&!n.done&&s[0].top-n.bot<=1.6*e&&n.x0>=l[0]-.7*e&&l.every((t=>n.its.some((s=>Math.abs(s.x0-t)<=.7*e))))&&n.its.every(((t,s)=>l.some((s=>Math.abs(t.x0-s)<=.7*e))||s>0&&t.x0-n.its[s-1].x1<.3*e))&&n.its.filter((t=>!ct.test(t.s))).length>=.75*n.its.length&&(a=l)}if(s.length>=3||2===s.length&&ft(s,e)||a){const t=a||nt(s.map((t=>({l:t,cs:Q(t)}))),e),i=o[r-1];t&&i&&!i.done&&s[0].top-i.bot<=1.6*e&&(a||t.filter((t=>i.its.some((s=>Math.abs(s.x0-t)<=.7*e)))).length>=Math.min(3,t.length))&&s.unshift(i);const h=t&&lt(s,e,[],!1,[],a);if(h&&n(rt(h))){for(const t of s)if(t.done=!0,t.parent){t.parent.part=(t.parent.part||0)+1;for(const e of t.its)e.tdone=!0}l.push({src:"free",kind:"table",html:rt(h),top:s[0].top,bot:s[s.length-1].bot,x0:Math.min(...s.map((t=>t.x0))),x1:Math.max(...s.map((t=>t.x1)))})}}r=t}return l}(D,F,R,t))}const E=D.filter((t=>!(t.done||Mt(t.text)&&(t.top<.1*i||t.bot>.88*i)&&!(!m&&/^\d{1,2}$/.test(t.text)&&t.fsize>1.6*F)))),Z=new Set(E.flatMap((t=>t.its.filter((t=>!t.tdone))))),V=pt(E.map((t=>t.its.some((t=>t.tdone))?{...t,its:t.its.filter((t=>!t.tdone))}:t)).filter((t=>t.its.length)),R).filter((t=>t.its.some((t=>Z.has(t))))),G=[],_=[];{const t=[...V].sort(((t,e)=>t.top-e.top));for(let e=0;e<t.length;e++){const s=t[e],n=s.bot-s.top;for(let o=e+1;o<t.length&&o<e+12;o++){const e=t[o],l=e.top-s.bot;if(Math.min(s.x1,e.x1)-Math.max(s.x0,e.x0)>.5*Math.min(s.x1-s.x0,e.x1-e.x0)&&l>-.5&&l<2.5*n){_.push(Math.max(0,l));break}}}}const N=_.length>=3||m?x(_):0,J=[...B.map((t=>({...t,html:K(t)}))),...T,...C?C.paras.map((t=>({...t,para:!0}))):[]].map((t=>({tbl:t,x0:t.x0,x1:t.x1,top:t.top,bot:t.bot,its:[]})));process.env.PDFMD_DEBUG&&console.error("[pdfmd] tables",B.map((t=>`${t.src||"ruled"}@${Math.round(t.top)}-${Math.round(t.bot)}${t.openTop?"^":""}${t.openBot?"v":""}:${t.R}x${t.C}:${U(t.cells.find((t=>t.its.length))?.its||[]).slice(0,12)}`)).join(" ")),process.env.PDFMD_DEBUG&&console.error("[pdfmd] ms",F,"lg",N,"boxes",V.length,"tboxes",J.length,"regions",mt([...V,...J],F,Math.max(.45*F,1.35*N)).map((t=>`${Math.min(...t.map((t=>t.x0))).toFixed(0)}-${Math.max(...t.map((t=>t.x1))).toFixed(0)}:${t.length}`)).slice(0,8).join(" "),T.map((t=>(t.src||"?")+":"+t.html.slice(0,120))));const W=(t,e)=>{const s=t.filter((t=>!t.tbl&&!t.img));if(!s.length)return null;const n=e?s.reduce(((t,e)=>e.top<t.top?e:t)):s.reduce(((t,e)=>e.bot>t.bot?e:t)),o=s.filter((t=>Math.min(t.bot,n.bot)-Math.max(t.top,n.top)>.3*Math.min(t.bot-t.top,n.bot-n.top)&&(e?t.bot<=.1*i:t.top>=.9*i))),l=t.filter((t=>!o.includes(t)));if(!o.length||!l.length||o.length>6)return null;const r=Math.max(...o.map((t=>t.bot-t.top))),a=e?Math.min(...l.map((t=>t.top)))-Math.max(...o.map((t=>t.bot))):Math.min(...o.map((t=>t.top)))-Math.max(...l.map((t=>t.bot))),h=new Set(o.map((t=>Math.round((t.top+t.bot)/2/Math.max(3,.5*r))))).size,c=o.some((t=>o.some((e=>e!==t&&Math.min(t.bot,e.bot)-Math.max(t.top,e.top)>.3*r&&e.x0-t.x1>4*F)))),f=o.map((t=>t.its.map((t=>t.s)).join("").trim()));return(1===f.filter((t=>Mt(t))).length&&f.length>1||!m&&2===f.length&&!f.some((t=>t.length>40)))&&a>=r&&h<=2&&c?{t:o,r:l}:null},tt=t.getViewport({scale:1}).width,et=m?[]:$.filter((t=>R.some((e=>t.x0<e-10&&t.x1>e+10))&&t.x1-t.x0>=30&&t.y1-t.y0>=30&&(t.x1-t.x0)*(t.y1-t.y0)<.5*tt*i&&![...V,...J].some((e=>{const s=(e.x0+e.x1)/2,n=(e.top+e.bot)/2;return s>t.x0&&s<t.x1&&n>t.y0&&n<t.y1})))).map((t=>({img:!0,x0:t.x0,x1:t.x1,top:t.y0,bot:t.y1,its:[]})));let st=[...V,...J,...et];const ot=[],ut=[];{const t=W(st,!0);t&&(ot.push(t.t),st=t.r);const e=W(st,!1);e&&(ut.push(e.t),st=e.r)}const gt=[...b.map((t=>[{its:[t],x0:t.x0,x1:t.x1,top:t.top,bot:t.bot}])),...ot,...mt(st,F,Math.max(.45*F,1.35*N),R,!m),...ut].map((t=>t.filter((t=>!t.img)))).filter((t=>t.length)),bt=[],yt=t=>({x0:Math.min(...t.map((t=>t.x0))),x1:Math.max(...t.map((t=>t.x1))),top:Math.min(...t.map((t=>t.top))),bot:Math.max(...t.map((t=>t.bot))),sz:x(t.flatMap((t=>t.its.map((t=>t.size)))))});for(const t of gt){const e=bt[bt.length-1];if(e&&!e.some((t=>t.tbl))&&!t.some((t=>t.tbl))){const s=yt(e),n=yt(t),o=s.x0-n.x0>2&&s.x0-n.x0<=3*n.sz&&s.bot-s.top<=1.6*s.sz;if((Math.abs(s.x0-n.x0)<=2||o)&&Math.abs(s.sz-n.sz)<=.1*s.sz&&n.top>=s.bot-1&&n.top-s.bot<=.75*n.sz*1.04&&Math.min(s.x1,n.x1)-Math.max(s.x0,n.x0)>.5*Math.min(s.x1-s.x0,n.x1-n.x0)){e.push(...t);continue}}bt.push([...t])}if("3"===process.env.PDFMD_DEBUG)for(const t of bt){const e=yt(t);console.error(`[pdfmd] 영역 y${e.top.toFixed(0)}-${e.bot.toFixed(0)} x${e.x0.toFixed(0)}-${e.x1.toFixed(0)} ${t.length}개 | ${t.map((t=>t.tbl?"[표]":t.its.map((t=>t.s)).join(""))).join(" / ").slice(0,90)}`)}for(const t of bt){const e=t.filter((t=>t.tbl)),s=t.filter((t=>!t.tbl)),n=s.length?dt(s,F,N,!m):[];G.push(...[...n,...e.filter((t=>t.tbl.para)).map((t=>({kind:"p",text:t.tbl.text,grid:!0,top:t.top,bot:t.bot,x0:t.x0,fsize:t.tbl.fsize,bold:t.tbl.bold,nl:1,chars:t.tbl.text.length}))),...e.filter((t=>!t.tbl.para)).map((t=>({kind:"table",html:t.tbl.html,top:t.top,bot:t.bot,x0:t.x0,x1:t.x1,Xs:t.tbl.Xs,openTop:t.tbl.openTop,openBot:t.tbl.openBot,frag:t.tbl.frag,t:t.tbl.cells?t.tbl:null})))].sort(((t,e)=>t.top-e.top)))}const $t={};for(const t of O){const e=Math.round(2*t.size)/2;$t[e]=($t[e]||0)+t.s.length}const kt={};for(const t of p){const e=Math.round(2*t.size)/2;kt[e]=(kt[e]||0)+t.s.length}for(const t of G)t.ph=i;const jt=r?function(t,e,s,n,o,l=!0){const r=t.map((t=>({...t})));for(let t=!0;t;){t=!1;for(let e=0;e<r.length&&!t;e++)for(let s=e+1;s<r.length&&!t;s++){const n=r[e],o=r[s],l=Math.min(n.x1,o.x1)-Math.max(n.x0,o.x0),a=Math.min(n.y1,o.y1)-Math.max(n.y0,o.y0);l>=-2&&a>=-2&&(l>.5*Math.min(n.x1-n.x0,o.x1-o.x0)||a>.5*Math.min(n.y1-n.y0,o.y1-o.y0))&&(r[e]={x0:Math.min(n.x0,o.x0),x1:Math.max(n.x1,o.x1),y0:Math.min(n.y0,o.y0),y1:Math.max(n.y1,o.y1)},r.splice(s,1),t=!0)}}const a=[];for(const t of r){const r=Math.max(0,t.x0),i=Math.min(n,t.x1),h=Math.max(0,t.y0),c=Math.min(o,t.y1),f=(i-r)*(c-h);if(i-r<40||c-h<20||f<(l?zt:wt)*n*o)continue;let x=0;for(const t of e){const e=(t.x0+t.x1)/2,s=(t.top+t.bot)/2;e>r&&e<i&&s>h&&s<c&&(x+=(t.x1-t.x0)*(t.bot-t.top))}if(x>vt*f)continue;const p=t=>Math.min(i,t.x1??n)-Math.max(r,t.x0??0)>0,m=t=>t.top<c&&t.bot>h&&(t.x0??0)>=i-2,u=s.find((t=>t.top>=h-2&&p(t)||m(t)))||s.find((t=>t.top>=c-2))||null;a.push({box:[r,h,i,c].map((t=>Math.round(10*t)/10)),before:u})}return a.sort(((t,e)=>t.box[1]-e.box[1]||t.box[0]-e.box[0]))}($,p,G,tt,i,m):[],At={};for(const t of p){const e=String(t.font||"").replace(/^[A-Z]{6}\+/,"");if(!e)continue;const s=e+"|"+Math.round(2*t.size)/2;At[s]=(At[s]||0)+t.s.replace(/\s/g,"").length}return{blocks:G,sizes:$t,allSizes:kt,fonts:At,chars:p.reduce(((t,e)=>t+e.s.replace(/\s/g,"").length),0),hangul:m,imgs:jt,...r?{size:[Math.round(tt),Math.round(i)]}:{}}}const zt=.05,wt=.008,vt=.08;function $t(t,e){const s=S([...t.Xs,...e.Xs],3),n=t=>{let e=0;for(let n=1;n<s.length;n++)Math.abs(s[n]-t)<Math.abs(s[e]-t)&&(e=n);return e},o=t=>({...t,c0:n(t.x0),c1:Math.max(n(t.x0),n(t.x1)-1)}),l=t.cells.map(o),r=Math.max(...l.map((t=>t.r1)))+1,a=Math.max(0,...l.flatMap((t=>t.its.map((t=>t.bot)))))+1e3;let i=e.cells.map(o).map((t=>({...t,its:t.its.map((t=>({...t,top:t.top+a,bot:t.bot+a,base:t.base+a})))})));const h=(t,e)=>t.filter((t=>t.r0===e)).sort(((t,e)=>t.c0-e.c0)).map((t=>`${t.c0}-${t.c1}:${U(t.its)}`)).join("|");i.some((t=>0===t.r0))&&i.filter((t=>0===t.r0)).every((t=>0===t.r1))&&h(i,0)===h(l,0)&&/[^|:\d-]/.test(h(i,0))&&(i=i.filter((t=>t.r0>0)).map((t=>({...t,r0:t.r0-1,r1:t.r1-1}))));let c=r;const f=l.filter((t=>t.r1===r-1)),x=i.filter((t=>0===t.r0&&!(t.hole&&!t.its.length))),p=t=>{const e=new Set;for(const s of t)if(s.its.length)for(let t=s.c0;t<=s.c1;t++)e.add(t);return e},m=p(f),u=p(x),g=u.size>0&&u.size<=.5*(s.length-1)&&[...u].every((t=>m.has(t)))&&(u.size<m.size||e.openTop),b=[...m].some((t=>!u.has(t))),M=[...u].some((t=>!m.has(t))),d=x.find((t=>0===t.c0)),y=!!d&&/^([가나다라마바사아자차카타파하]\.|\d{1,2}[.)]|[①-⑳])\s?/.test(U(d.its));if((e.holeTop||t.openBot&&e.openTop||!y&&(g||e.openTop&&b||b&&M)||f.some((t=>0===t.c0&&t.its.length))&&!x.some((t=>0===t.c0&&t.its.length)))&&i.length&&x.length&&x.every((t=>f.some((e=>e.c0===t.c0&&e.c1===t.c1))))){for(const t of x){const e=f.find((e=>e.c0===t.c0&&e.c1===t.c1));e.its=[...e.its,...t.its],e.r1=r-1+t.r1,t.drop=!0}for(const t of i)0===t.r0&&t.hole&&!t.its.length&&(t.drop=!0);c=r-1}i=i.filter((t=>!(t.drop||t.hole&&!t.its.length))).map((t=>({...t,r0:t.r0+c,r1:t.r1+c})));const z=[...l,...i],w=Math.max(...z.map((t=>t.r1)))+1,v=s.length-1;for(let t=r;t<w;t++)for(let e=0;e<v;e++){if(z.some((s=>s.r0<=t&&s.r1>=t&&s.c0<=e&&s.c1>=e)))continue;const n=z.find((s=>s.r1===t-1&&s.c0<=e&&s.c1>=e));n&&!z.some((e=>e!==n&&e.r0<=t&&e.r1>=t&&e.c0<=n.c1&&e.c1>=n.c0))?n.r1=t:z.push({r0:t,r1:t,c0:e,c1:e,its:[],x0:s[e],x1:s[e+1]})}return{...t,cells:z,R:w,C:v,Xs:s,x0:Math.min(t.x0,e.x0),x1:Math.max(t.x1,e.x1),openBot:e.openBot}}function kt(t,e){const s=t=>[...t.matchAll(/<td([^>]*)>(.*?)<\/td>/g)].map((t=>({attr:t[1],t:t[2]}))),n=s(t),o=s(e);return n.length!==o.length||n.some(((t,e)=>t.attr.replace(/rowspan="\d+"/,"")!==o[e].attr.replace(/rowspan="\d+"/,"")))?null:"<tr>"+n.map(((t,e)=>`<td${t.attr}>${[t.t,o[e].t].filter(Boolean).join(" ")}</td>`)).join("")+"</tr>"}export async function pdfBlocksDebug(t){const e=await f(),s=await e.getDocument({data:new Uint8Array(t),isEvalSupported:!1,disableFontFace:!0,verbosity:0}).promise;try{const t=await s.getPage(1);return await yt(t,e)}finally{await s.destroy()}}export async function pdfMarkdown(e,{maxPages:l=400,ocrSlots:i=!1,imageSlots:c=!1,literal:x=!1,deadline:p=0}={}){const m=await f(),u=await m.getDocument({data:new Uint8Array(e),cMapUrl:t.join(h,"cmaps")+"/",cMapPacked:!0,standardFontDataUrl:t.join(h,"standard_fonts")+"/",disableFontFace:!0,isEvalSupported:!1,useSystemFonts:!1,verbosity:0,fontExtraProperties:!0}).promise;try{const t=[],h={},f=[],g={},b=[],M={},d=[],y=[];let w=!1;try{const t=await u.getMetadata();w=/hancom|hwp|한글|한컴/i.test(`${t.info&&t.info.Producer||""} ${t.info&&t.info.Creator||""}`)}catch{}const v=new Map,$=new Map;let k=null;if(w)for(let t=1;t<=Math.min(u.numPages,l,60)&&!(p&&Date.now()>p);t++){await new Promise((t=>setImmediate(t)));const e=await u.getPage(t),s=await e.getTextContent();$.set(t,s);for(const t of xt(z(s,e.getViewport({scale:1}).transform,m.Util,(()=>""))))for(const e of H(t))q(v,e)}const j=1e6+8*e.length;let A=0,X=null;for(let e=1;e<=Math.min(u.numPages,l);e++){if(p&&Date.now()>p){k=e-1;break}if(A>j){X=e-1;break}await new Promise((t=>setImmediate(t)));const s=await u.getPage(e),n=s.getOperatorList.bind(s);s.getOperatorList=async(...t)=>{const e=await n(...t);return A+=e&&e.fnArray?e.fnArray.length:0,e};const o=await yt(s,m,{korean:w,tc:$.get(e),jst:v,images:c});$.delete(e),s.cleanup(),o.hangul&&(w=!0),b.push(o.imgs||[]),d.push(!!o.hangul),y.push(o.size||null),t.push(o.blocks),f.push(o.chars||0);for(const[t,e]of Object.entries(o.fonts||{}))M[t]=(M[t]||0)+e;for(const[t,e]of Object.entries(o.sizes))h[t]=(h[t]||0)+e;for(const[t,e]of Object.entries(o.allSizes||{}))g[t]=(g[t]||0)+e}const S={};for(const e of t)for(const t of e)"p"===t.kind&&t.nl>=2&&!(t.ph&&t.top>.8*t.ph)&&(S[t.fsize]=(S[t.fsize]||0)+t.chars);const C=t=>+(Object.entries(t).sort(((t,e)=>e[1]-t[1]))[0]||[0])[0];let B=C(S)||C(h)||10;{const t=Object.values(S).reduce(((t,e)=>t+e),0),e=Object.values(g).reduce(((t,e)=>t+e),0),s=C(g);e&&t<.3*e&&t<150&&s&&B>=1.6*s&&(B=s)}{const e={},s={};for(const n of t)for(const t of n)"p"===t.kind&&t.chars>=20&&!(t.ph&&t.top>.8*t.ph)&&(e[t.fsize]=(e[t.fsize]||0)+1,t.nl>=2&&(s[t.fsize]=1));const n=C(e);n>B&&(e[n]||0)>=3*Math.max(1,e[B]||0)&&s[n]&&(B=n)}{const e=t.flat().filter((t=>"p"===t.kind&&t.text.trim())),s=e.filter((t=>t.fsize>=1.15*B));if(e.length>4&&s.length>.4*e.length&&s.filter((t=>t.nl>=2&&t.chars>=50)).length>=2){const t={};for(const e of s)t[e.fsize]=(t[e.fsize]||0)+e.chars;B=C(t)||B}}process.env.PDFMD_DEBUG&&console.error("[pdfmd] body",B,"ptally",JSON.stringify(S),"tally",JSON.stringify(h)),L=v.size?v:null,function(t){const e=(t,e)=>"p"===t.kind&&t.ph&&(e?t.top>.88*t.ph:t.bot<.12*t.ph)&&t.text.length<=80,s=t=>t.match(/<tr>.*?<\/tr>/g)||[];let n=null;for(let o=1;o<t.length;o++){const l=t[o-1],r=t[o];let a=l.length-1;for(;a>=0&&e(l[a],!0);)a--;let i=0;for(;i<r.length&&e(r[i],!1);)i++;const h=a>=0?l[a]:n,c=r[i];if(n=null,!(h&&c&&"table"===h.kind&&"table"===c.kind&&h.Xs&&c.Xs))continue;if(h.t&&c.t&&("clip"===h.t.src||"clip"===c.t.src)){const[t,s]=h.Xs.length<=c.Xs.length?[h.Xs,c.Xs]:[c.Xs,h.Xs];if(Math.abs(h.Xs[h.Xs.length-1]-c.Xs[c.Xs.length-1])>3&&Math.abs(h.Xs[0]-c.Xs[0])>3||!t.every((t=>s.some((e=>Math.abs(t-e)<=3)))))continue;const o=t=>t.cells.filter((t=>0===t.r0)).sort(((t,e)=>t.x0-e.x0)).map((t=>U(t.its))).join("|"),l=h.Xs.length===c.Xs.length&&h.Xs.every(((t,e)=>Math.abs(t-c.Xs[e])<=3)),a=t=>new Set(t.cells.filter((t=>t.its.length)).map((t=>t.r0))).size;if(!h.openBot&&!c.t.holeTop&&h.ph&&h.bot<.85*h.ph&&!(l&&a(c.t)>=2&&/[^|\s]/.test(o(c.t))&&o(h.t)===o(c.t)))continue;const f=$t(h.t,c.t);h.t=f,h.html=K(f),h.Xs=f.Xs,h.openBot=f.openBot,h.bot=c.bot,h.frag=!1,r.splice(i,1),r.some((t=>!e(t,!0)&&!e(t,!1)))||(n=h);continue}if(h.Xs.length!==c.Xs.length||!h.html.startsWith("<table")||!c.html.startsWith("<table"))continue;if(!h.Xs.every(((t,e)=>Math.abs(t-c.Xs[e])<=3)))continue;const f=s(h.html),x=s(c.html);if(x.length&&f.length&&x[0]===f[0]&&x.shift(),h.openBot&&c.openTop&&f.length&&x.length){const t=kt(f[f.length-1],x[0]);t&&(f[f.length-1]=t,x.shift())}h.html="<table>"+[...f,...x].join("")+"</table>",h.openBot=c.openBot,h.frag=!1,r.splice(i,1),r.some((t=>!e(t,!0)&&!e(t,!1)))||(n=h)}for(const e of t)for(let t=0;t<e.length;t++){const s=e[t];if("table"!==s.kind||!s.frag||!s.t)continue;const n=s.t.cells.filter((t=>t.its.length)).sort(((t,e)=>t.r0-e.r0||t.c0-e.c0)).map((t=>U(t.its))).join(" ");e[t]={kind:"p",text:n,grid:!0,top:s.top,bot:s.bot,x0:s.x0,fsize:0,bold:!1,nl:1,chars:n.length,ph:s.ph}}}(t);const O={};if(w)for(const e of t)for(const t of e)"p"!==t.kind||t.grid||(O[t.fsize]=(O[t.fsize]||0)+t.chars);const F=w?+(Object.entries(O).sort(((t,e)=>e[1]-t[1]))[0]||[0])[0]:0,D=[],T=x?[]:null,R=r,E=(t,e=t)=>{D.push(t),T&&T.push(e)};for(const[e,l]of t.entries()){i&&f[e]<20&&E(`\x3c!-- ocr:${e+1} --\x3e`);const t=t=>/(\.{3,}|…{2,}|\s)\s*([ivxlc]+|\d{1,4})$/i.test(t),r=l.filter((e=>"p"===e.kind&&t(e.text))).length>=3;let a=!1;for(const t of l)"p"===t.kind&&/^(table of contents|contents|목\s*차|차\s*례)$/i.test(t.text.trim())&&(t.isTocHead=!0);let h=null;const c=(e,s=!1)=>{if("p"!==e.kind)return!1;const n=e.text.trim();if(!s&&/^\d{1,2}$/.test(n)&&1===e.nl&&e.fsize>=2*B)return!0;if(!n||e.nl>3||n.length>160||/^[\d\s.,%()-]+$/.test(n)||r&&t(n))return!1;if(/^(chapter|part|section|appendix|annex|unit|lesson|module)\s+([\dIVXLC]+|[A-Z])\.?$/i.test(n)||/^제\s*\d+\s*[장편부]$/.test(n))return!0;if(ut.test(n)||/[\u0000-\u001f]/.test(n))return!1;if((n.match(/[A-Za-z가-힣]/g)||[]).length<3&&!(e.fsize>=2*B&&1===e.nl&&n.length<=12&&/\d/.test(n)))return!1;if(e.ph&&e.top<.06*e.ph&&1===e.nl&&!e.bold&&e.fsize<=1.6*B)return!1;if(e.ph&&e.top<.075*e.ph&&1===e.nl&&e.fsize<=1.3*B&&(!/^(\d{1,2}(\.\d+)*\.?|[IVX]+\.)\s+\S/.test(n)||!e.bold&&e.fsize<=1.05*B))return!1;if(e.pnum&&e.ph&&(e.top<.1*e.ph||e.top>.85*e.ph))return!1;if(e.ph&&e.top<.08*e.ph&&1===e.nl&&!e.bold&&e.next&&"p"===e.next.kind&&e.next.fsize>=1.3*e.fsize)return!1;if(!s&&1===e.nl&&!e.bold&&/^(chapter|part|section|appendix|unit|lesson|module)\b/i.test(n.replace(/(?<=\b[A-Z]{1,3}) (?=[A-Z])/g,""))&&e.next&&"p"===e.next.kind&&e.next.fsize>=1.1*e.fsize&&e.next.top-e.bot<=3*e.fsize&&!e.next.bold==!e.bold)return!1;if(e.wide&&!e.pnum)return!1;if(e.ph&&e.top>.9*e.ph&&1===e.nl&&e.fsize<=1.05*B)return!1;if((n.match(/\(/g)||[]).length!==(n.match(/\)/g)||[]).length)return!1;if(/^((jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\.?\s+(\d{1,2},?\s+)?\d{4}|\d{4}[.\-/]\s?\d{1,2}([.\-/]\s?\d{1,2})?\.?)$/i.test(n))return!1;if(/-$/.test(n)||/[∗†‡§]/.test(n)&&(/,/.test(n)||(n.match(/[∗†‡§]/g)||[]).length>=2)||(n.match(/,/g)||[]).length>=3&&n.length>40)return!1;if(a&&!e.isTocHead)return!1;if(/^[*∗†‡]\s*\S/.test(n)&&!/^\*\*/.test(n))return!1;if(!s&&e.next&&"p"===e.next.kind&&e.next.nl>=2&&/^[a-z]/.test(e.next.text.trim())&&Math.abs(e.next.fsize-e.fsize)<=.05*e.fsize&&e.next.bold===e.bold&&e.next.top-e.bot<=.9*e.fsize&&e.next.top-e.bot>=-.3*e.fsize)return!1;const o=(n.match(/[A-Za-z]/g)||[]).length,l=(n.match(/[A-Za-z가-힣]/g)||[]).length;if(/^(fig(ure)?|table|tab\.|chart|source|sources|note|notes|photo|image|그림|표|출처|자료|주)\s*[\d.:]/i.test(n))return!1;if(!s&&/^[a-z]/.test(n))return!1;const i=e.next;if(!(i&&i.fsize===e.fsize&&i.bold===e.bold&&i.top-e.bot<=.9*e.fsize)&&/\s(the|a|an|of|to|in|and|or|for|with|on|at|by|from|as|that|which|is|are)$/i.test(n)&&n.split(/\s+/).length>=4)return!1;if(n.length<=90&&/[A-Z]{3}/.test(n)&&n===n.toUpperCase()&&o>=.8*l&&n.split(/\s+/).length>=2&&!/[.,;]$/.test(n)&&e.fsize>=.97*B&&e.nl<=2)return!0;const c=e.fsize/B;if(!s&&!e.bold&&c<1.5&&e.nb){const t=[...e.nb.prev,...e.nb.next],s=e.nb.prev[e.nb.prev.length-1];if(t.length>=4&&s&&"p"===s.kind&&e.top-s.bot>=-1&&e.top-s.bot<=1*e.fsize&&Math.min(s.x1,e.x1)-Math.max(s.x0,e.x0)>0&&t.filter((t=>"p"===t.kind&&t.text.trim().split(/\s+/).length<=3&&t.text.trim().length<=20)).length>=3)return!1}if(c>=1.15)return n.length<=160;if(c>=1.07&&(e.bold||n.length<=80)&&!/[.;]$/.test(n))return!0;if(e.bold&&c>=.95&&n.length<=110&&!/[.,;]$/.test(n)&&!(/:$/.test(n)&&n.length>50))return!0;const f=e.next,x=/^(a|an|the|and|or|of|in|on|at|to|for|by|with|vs\.?|from)$/i;return!!(!s&&1===e.nl&&n.length<=60&&n.split(/\s+/).length<=6&&!/[.,;:!?]$/.test(n)&&n.split(/\s+/).every((t=>x.test(t)||/^[A-Z0-9“"‘'(]/.test(t)))&&/[A-Z][a-z]/.test(n)&&f&&"p"===f.kind&&f.nl>=2&&Math.abs(f.fsize-e.fsize)<=.05*e.fsize&&f.top-e.bot>=1.2*e.fsize&&f.top-e.bot<=4*e.fsize&&Math.abs(f.x0-e.x0)<=1.5*e.fsize)||!!(!s&&1===e.nl&&n.split(/\s+/).length<=5&&!/[.,;:!?]$/.test(n)&&/[A-Za-z]{3}/.test(n)&&f&&"p"===f.kind&&f.fsize>=1.25*e.fsize&&f.nl<=2&&f.chars<=120&&Math.abs(f.x0-e.x0)<=1.5*e.fsize&&f.top-e.bot>=-1&&f.top-e.bot<=2*e.fsize)||!!(!s&&e.bold&&h&&e.nl<=2&&n.length<=60&&!/[.,;:!?]$/.test(n)&&/[A-Z][a-z]/.test(n)&&h.some((t=>t!==e&&t.fsize===e.fsize&&Math.abs(t.x0-e.x0)<=.5*e.fsize&&t.nl<=2)))||!s&&e.bold&&e.nl<=2&&n.length<=60&&!/[.,;:]$/.test(n)&&!!f&&"p"===f.kind&&!f.bold&&f.fsize<=1.15*e.fsize&&f.fsize>=.7*e.fsize&&Math.abs(f.x0-e.x0)<=2*e.fsize&&f.top-e.bot>=0&&f.top-e.bot<=2.5*e.fsize&&(f.text||"").length>=10};for(let t=0;t<l.length;t++)"p"===l[t].kind&&(l[t].next=l.slice(t+1).find((t=>"p"===t.kind)));for(let t=0;t<l.length;t++)"p"===l[t].kind&&(l[t].nb={prev:l.slice(Math.max(0,t-2),t),next:l.slice(t+1,t+3)});h=l.filter((t=>"p"===t.kind&&t.bold&&t.nl<=2&&(t.text||"").trim().length<=60&&c(t)));const x=b[e]||[],p=t=>x.forEach(((s,n)=>{s.before!==t||s.done||(s.done=!0,E(`\x3c!-- img:${e+1}:${n} --\x3e`))}));for(let t=0;t<l.length;t++){const r=l[t];if(x.length&&p(r),"table"===r.kind){E(r.html);continue}let i=s(r.text).trim();if(i)if("5"===process.env.PDFMD_DEBUG&&console.error(`[blk] p${e+1} fs${r.fsize} body${B} b${r.bold?1:0} nl${r.nl} top${Math.round(r.top)}/${Math.round(r.ph||0)} x${Math.round(r.x0)} head${c(r)?1:0} ${i.slice(0,60)}`),w){if(r.grid){E(r.stext?s(n(r.stext,{cell:!0})).trim():i,T&&(r.stext?s(n(R(r.stext),{cell:!0})).trim():R(i)));continue}const t=o(i,r.fsize,F);if(t){E("#".repeat(t)+" "+i,T&&"#".repeat(t)+" "+R(i));continue}let e=String(r.stext||r.text),l=T&&R(e);gt.test(i)&&(e=e.replace(/^([\uFDD0-\uFDD5]*)[•‣⁃]\s*/,"- $1"),T&&(l=l.replace(/^([\uFDD0-\uFDD5]*)[•‣⁃]\s*/,"- $1"))),E(s(n(e)).trim(),T&&s(n(l)).trim())}else if(r.isTocHead)E("# "+i,T&&"# "+R(i)),a=!0;else if(c(r)){(/^([IVXLC]+|\d{1,2})\.$/.test(i)||/^\d{1,2}$/.test(i)&&r.fsize>=2*B&&t+1<l.length&&Math.abs(l[t+1].x0-r.x0)<=.3*r.fsize)&&t+1<l.length&&c(l[t+1])&&l[t+1].top-r.bot<=2.5*r.fsize&&(i+=" "+s(l[t+1].text).trim(),r.bot=l[t+1].bot,t++);const e=t=>{const e=t.text.trim();return/[A-Z]{2}/.test(e)&&e===e.toUpperCase()&&!/[가-힣]/.test(e)},n=t=>e(r)&&e(t)&&t.top-r.bot<=.6*Math.min(r.fsize,t.fsize)&&t.top>=r.top&&Math.min(t.x1,r.x1)-Math.max(t.x0,r.x0)>.3*Math.min(t.x1-t.x0,r.x1-r.x0);for(;;){const s=l[t+1],n=l[t+2];if(!s||!n||"p"!==s.kind||!/^(&|\+|and|or|\/)$/i.test(s.text.trim())||!c(n,!0)||!e(r)||!e(n)||n.top-r.bot>2.5*Math.min(r.fsize,n.fsize)||s.top<r.top||n.top<s.top)break;i+=" "+s.text.trim()+" "+n.text.trim(),r.bot=n.bot,t+=2}for(;t+1<l.length&&c(l[t+1],!0)&&(l[t+1].fsize===r.fsize&&l[t+1].bold===r.bold&&l[t+1].top-r.bot<=1*r.fsize&&l[t+1].top-r.bot>=-.3*r.fsize||n(l[t+1]))&&!/^(\d{1,2}(\.\d+)*\.?|[IVX]+\.|[A-Z]\.)\s/.test(l[t+1].text);)i+=" "+l[t+1].text.trim(),r.bot=l[t+1].bot,t++;E("# "+i,T&&"# "+R(i))}else if(gt.test(i)){const t=i.replace(gt,"");E("- "+t,T&&"- "+R(t))}else E(i,T&&R(i))}x.forEach(((t,s)=>{t.done||E(`\x3c!-- img:${e+1}:${s} --\x3e`)}))}const P={};b.forEach(((t,e)=>{t.length&&(P[e+1]=t.map((t=>t.box)))}));const Z=Object.keys(P).map(Number).filter((t=>d[t-1])),Y=Object.fromEntries(Object.keys(P).map((t=>[t,y[+t-1]]))),I={},V={},G={};for(const[t,e]of Object.entries(M)){const s=t.lastIndexOf("|"),n=t.slice(0,s),o=+t.slice(s+1);I[n]=(I[n]||0)+e,Math.abs(o-B)<=.5&&(V[n]=(V[n]||0)+e),o>=1.3*B&&!/^Type3$/i.test(n)&&(G[n]=(G[n]||0)+e)}const _=Object.entries(I).sort(((t,e)=>e[1]-t[1])).slice(0,6).map((([t,e])=>({name:t,chars:e}))),N=(Object.entries(V).sort(((t,e)=>e[1]-t[1]))[0]||[_[0]?_[0].name:""])[0],J=(Object.entries(G).sort(((t,e)=>e[1]-t[1]))[0]||[""])[0],W=Object.values(V).reduce(((t,e)=>t+e),0),Q=Object.entries(V).filter((([t])=>!/^Type3$/i.test(t))).sort(((t,e)=>e[1]-t[1]))[0],tt={body:{name:N||"",size:B,...Q&&Q[1]>=.2*W?{alt:Q[0]}:{}},top:_,...J?{head:{name:J}}:{}},et=null!=X?`\n\n(PDF 글 읽기가 읽을 양 한도에 걸려 앞 ${X}쪽(전체 ${u.numPages}쪽)만 읽었어요 — 나머지 쪽 글은 빠졌어요. 쪽을 나눠 다시 해 주세요)`:"";return{pages:u.numPages,markdown:D.join("\n\n")+et,pageChars:f,fonts:tt,...c?{images:P,imgHangul:Z,imgSize:Y,korean:w}:{},...T?{literal:a(T.join("\n\n"))+et}:{},...null!=k?{cut:k}:{},...null!=X?{workCut:X}:{}}}finally{await u.destroy()}}export const _dbg={fillGrids:Z,fillTables:Y,gutters:it,splitAt:ht,itemsOf:z,linesOfOps:k,ruledTables:P,gridOf:B,virtualRows:F,textTable:lt,cellsOfLine:Q,ruleOnlyTables:at,toLines:xt,fragments:pt,xycut:mt,paragraphs:dt,statSegs:H,joinStats:q,joinBy:J};