@8sheets/data-grid 1.1.2 → 1.2.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.
- package/README.md +1 -1
- package/a11y/cell-alt-text.js +1 -1
- package/api/serialize.js +1 -1
- package/api/style-refs.js +1 -1
- package/calc/adjust.js +1 -1
- package/calc/compile.js +1 -1
- package/calc/engine.js +1 -1
- package/calc/functions/array.js +1 -1
- package/calc/functions/database.js +1 -1
- package/calc/functions/date.js +1 -1
- package/calc/functions/engineering.js +1 -1
- package/calc/functions/financial.js +1 -1
- package/calc/functions/helpers.js +1 -1
- package/calc/functions/index.js +3 -2
- package/calc/functions/info.js +1 -1
- package/calc/functions/logical.js +1 -1
- package/calc/functions/lookup.js +1 -1
- package/calc/functions/math.js +1 -1
- package/calc/functions/stat.js +1 -1
- package/calc/functions/text.js +1 -1
- package/calc/parser.js +2 -2
- package/calc/shown-refs.js +1 -0
- package/calc/values.js +1 -1
- package/calcx/calc-control.js +1 -0
- package/calcx/external-read.js +1 -1
- package/calcx/external.js +1 -1
- package/cells/axis-ops.js +1 -1
- package/cells/cell-styles-xml.js +1 -1
- package/cells/cf-engine.js +1 -1
- package/cells/cf-file.js +1 -1
- package/cells/docprops-xml.js +2 -2
- package/cells/filter-eval.js +1 -0
- package/cells/filter-file.js +1 -1
- package/cells/find-engine.js +1 -1
- package/cells/goto.js +1 -1
- package/cells/name-box.js +1 -1
- package/cells/note-box.js +3 -0
- package/cells/options.js +1 -1
- package/cells/outline-column.js +1 -1
- package/cells/protected-menu.js +1 -0
- package/cells/rich-data-xml.js +1 -1
- package/cells/sheet-views-file.js +2 -0
- package/cells/shift-check.js +1 -1
- package/cells/sort-compare.js +1 -0
- package/cells/ui-kit.js +1 -1
- package/cells/undo-group.js +1 -1
- package/celltypes/dropdowns.js +2 -2
- package/core/address.js +1 -1
- package/core/autofill.js +1 -1
- package/core/axis.js +1 -1
- package/core/cond-format.js +1 -1
- package/core/culture.js +5 -1
- package/core/custom-views.js +1 -1
- package/core/data-tools.js +1 -0
- package/core/date-codes.js +1 -0
- package/core/default-names.js +1 -1
- package/core/formula-refs.js +1 -1
- package/core/input.js +1 -1
- package/core/numfmt.js +1 -1
- package/core/precision.js +1 -0
- package/core/region-input.js +1 -1
- package/core/rule-refs.js +1 -0
- package/core/shared-view.js +1 -0
- package/core/sheet.js +1 -1
- package/core/sparklines.js +1 -1
- package/core/sparse.js +1 -1
- package/core/spills.js +1 -0
- package/core/strings.js +1 -1
- package/core/structure.js +1 -1
- package/core/table-columns.js +1 -0
- package/core/tables.js +2 -2
- package/core/validation-ranges.js +1 -1
- package/core/whatif.js +1 -1
- package/core/workbook.js +1 -1
- package/datasheets/formula.js +1 -1
- package/datasheets/path-binding.js +1 -1
- package/datasheets/persist-writer.js +1 -1
- package/datasheets/report.js +1 -1
- package/extras/getdata/persist.js +2 -2
- package/extras/getdata/rows.js +1 -1
- package/extras/getdata/shared-steps.js +1 -0
- package/extras/getdata/steps-formula.js +1 -0
- package/extras/getdata/steps-more.js +1 -0
- package/extras/getdata/steps-tables.js +1 -0
- package/extras/getdata/steps.js +1 -1
- package/i18n/de/a11y.js +1 -0
- package/i18n/de/cells.js +2 -0
- package/i18n/de/charts.js +1 -0
- package/i18n/de/common.js +1 -0
- package/i18n/de/datasheets.js +1 -0
- package/i18n/de/format.js +1 -0
- package/i18n/de/misc.js +1 -0
- package/i18n/de/pivot.js +1 -0
- package/i18n/de/proofing.js +1 -0
- package/i18n/de/ribbon.js +1 -0
- package/i18n/de/shapes.js +1 -0
- package/i18n/de/shell.js +3 -0
- package/i18n/de/touch.js +1 -0
- package/i18n/de.js +1 -0
- package/i18n/en/cells.js +2 -1
- package/i18n/en/charts.js +1 -1
- package/i18n/en/format.js +1 -1
- package/i18n/en/misc.js +1 -1
- package/i18n/en/pivot.js +1 -1
- package/i18n/en/proofing.js +1 -1
- package/i18n/en/ribbon.js +1 -1
- package/i18n/en/shapes.js +1 -1
- package/i18n/en/shell.js +3 -2
- package/i18n/en/touch.js +1 -1
- package/i18n/es/a11y.js +1 -0
- package/i18n/es/cells.js +2 -0
- package/i18n/es/charts.js +1 -0
- package/i18n/es/common.js +1 -0
- package/i18n/es/datasheets.js +1 -0
- package/i18n/es/format.js +1 -0
- package/i18n/es/misc.js +1 -0
- package/i18n/es/pivot.js +1 -0
- package/i18n/es/proofing.js +1 -0
- package/i18n/es/ribbon.js +1 -0
- package/i18n/es/shapes.js +1 -0
- package/i18n/es/shell.js +3 -0
- package/i18n/es/touch.js +1 -0
- package/i18n/es.js +1 -0
- package/i18n/fr/a11y.js +1 -0
- package/i18n/fr/cells.js +2 -0
- package/i18n/fr/charts.js +1 -0
- package/i18n/fr/common.js +1 -0
- package/i18n/fr/datasheets.js +1 -0
- package/i18n/fr/format.js +1 -0
- package/i18n/fr/misc.js +1 -0
- package/i18n/fr/pivot.js +1 -0
- package/i18n/fr/proofing.js +1 -0
- package/i18n/fr/ribbon.js +1 -0
- package/i18n/fr/shapes.js +1 -0
- package/i18n/fr/shell.js +3 -0
- package/i18n/fr/touch.js +1 -0
- package/i18n/fr.js +1 -0
- package/i18n/index.js +1 -1
- package/i18n/languages.js +1 -1
- package/i18n/pl/cells.js +2 -1
- package/i18n/pl/charts.js +1 -1
- package/i18n/pl/format.js +1 -1
- package/i18n/pl/misc.js +1 -1
- package/i18n/pl/pivot.js +1 -1
- package/i18n/pl/proofing.js +1 -1
- package/i18n/pl/ribbon.js +1 -1
- package/i18n/pl/shapes.js +1 -1
- package/i18n/pl/shell.js +3 -2
- package/i18n/pl/touch.js +1 -1
- package/io/blob-sink.js +1 -0
- package/io/canonical-xml.js +1 -0
- package/io/client.js +1 -1
- package/io/crypto/cfb-build.js +1 -0
- package/io/crypto/cfb-read.js +1 -1
- package/io/crypto/cfb-write.js +1 -1
- package/io/crypto/errors.js +1 -1
- package/io/csv.js +8 -8
- package/io/foreign-sheets.js +2 -2
- package/io/io.worker.js +1 -1
- package/io/open-package.js +1 -0
- package/io/package-paths.js +1 -1
- package/io/plan.js +1 -1
- package/io/text-split.js +3 -3
- package/io/xls/chart-sheet.js +1 -0
- package/io/xls/chart.js +1 -0
- package/io/xls/crypt.js +1 -0
- package/io/xls/dml-color.js +1 -0
- package/io/xls/drawing.js +1 -0
- package/io/xls/formula.js +1 -0
- package/io/xls/geometry.js +1 -0
- package/io/xls/index.js +1 -0
- package/io/xls/pictures.js +1 -0
- package/io/xls/pivot.js +1 -0
- package/io/xls/props.js +1 -0
- package/io/xls/records.js +1 -0
- package/io/xls/shapes.js +1 -0
- package/io/xls/sheet-ext.js +1 -0
- package/io/xls/sheet.js +1 -0
- package/io/xls/styles.js +1 -0
- package/io/xls/vba.js +1 -0
- package/io/xls/workbook.js +1 -0
- package/io/xlsb/filter.js +1 -0
- package/io/xlsb/formula.js +2 -0
- package/io/xlsb/functions.js +1 -0
- package/io/xlsb/index.js +1 -0
- package/io/xlsb/parts.js +1 -0
- package/io/xlsb/pivot.js +1 -0
- package/io/xlsb/records.js +1 -0
- package/io/xlsb/sheet-ext.js +1 -0
- package/io/xlsb/sheet.js +1 -0
- package/io/xlsb/slicer.js +1 -0
- package/io/xlsb/styles.js +1 -0
- package/io/xlsb/workbook.js +1 -0
- package/io/xlsb/xml.js +2 -0
- package/io/xlsx-read.js +1 -1
- package/io/xlsx-styles.js +2 -2
- package/io/xlsx-tail.js +1 -1
- package/io/xlsx-write.js +2 -2
- package/io/xml-escape.js +1 -1
- package/io/xml-scan.js +2 -2
- package/io/zip-reader.js +1 -1
- package/objects/chart-model.js +1 -1
- package/objects/drawing-xml.js +1 -1
- package/package.json +1 -1
- package/pivot/calc-items.js +1 -0
- package/pivot/engine.js +1 -1
- package/pivot/xml.js +2 -2
- package/print/note-pages.js +2 -2
- package/print/page-setup.js +1 -1
- package/print/paginate.js +1 -1
- package/print/pdf-crypt.js +1 -0
- package/print/pdf-tags.js +1 -0
- package/print/pdf.js +24 -13
- package/print/render-page.js +3 -3
- package/print/shown-notes.js +1 -0
- package/shapes/form-xml.js +1 -1
- package/slicers/custom-styles.js +1 -1
- package/slicers/format.js +1 -1
- package/slicers/structured.js +1 -1
- package/slicers/write.js +1 -1
- package/table-view/files.js +1 -1
- package/table-view/mount.js +1 -1
- package/table-view/version.js +1 -1
- package/ui/icons.js +1 -1
- package/ui/menu-base.js +1 -1
- package/ui/protection-ui.js +1 -1
package/print/page-setup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{colName as x,MAX_COLS as b,MAX_ROWS as T,parseRangeRef as C,quoteSheetName as J}from"../core/address.js";import{unescapeOoxml as Z,unescapeXml as F}from"../io/xml-scan.js";import{escapeMarkup as _,xmlText as K}from"../io/xml-escape.js";const c=72,f=72/25.4,N={1:{name:"Letter",w:8.5*c,h:11*c,common:!0},2:{name:"Letter Small",w:8.5*c,h:11*c},3:{name:"Tabloid",w:11*c,h:17*c,common:!0},4:{name:"Ledger",w:11*c,h:17*c,wide:!0,common:!0},5:{name:"Legal",w:8.5*c,h:14*c,common:!0},6:{name:"Statement",w:5.5*c,h:8.5*c,common:!0},7:{name:"Executive",w:7.25*c,h:10.5*c,common:!0},8:{name:"A3",w:297*f,h:420*f,common:!0},9:{name:"A4",w:210*f,h:297*f,common:!0},10:{name:"A4 Small",w:210*f,h:297*f},11:{name:"A5",w:148*f,h:210*f,common:!0},12:{name:"B4 (JIS)",w:257*f,h:364*f,common:!0},13:{name:"B5 (JIS)",w:182*f,h:257*f,common:!0},14:{name:"Folio",w:8.5*c,h:13*c},15:{name:"Quarto",w:215*f,h:275*f},16:{name:"10 x 14 in",w:10*c,h:14*c},17:{name:"11 x 17 in",w:11*c,h:17*c},18:{name:"Note",w:8.5*c,h:11*c},19:{name:"Envelope #9",w:3.875*c,h:8.875*c},20:{name:"Envelope #10",w:4.125*c,h:9.5*c,common:!0},21:{name:"Envelope #11",w:4.5*c,h:10.375*c},22:{name:"Envelope #12",w:4.75*c,h:11*c},23:{name:"Envelope #14",w:5*c,h:11.5*c},24:{name:"C",w:17*c,h:22*c},25:{name:"D",w:22*c,h:34*c},26:{name:"E",w:34*c,h:44*c},27:{name:"Envelope DL",w:110*f,h:220*f,common:!0},28:{name:"Envelope C5",w:162*f,h:229*f,common:!0},29:{name:"Envelope C3",w:324*f,h:458*f},30:{name:"Envelope C4",w:229*f,h:324*f},31:{name:"Envelope C6",w:114*f,h:162*f},32:{name:"Envelope C65",w:114*f,h:229*f},33:{name:"B4 (ISO)",w:250*f,h:353*f},34:{name:"Envelope B5",w:176*f,h:250*f},35:{name:"Envelope B6",w:125*f,h:176*f},36:{name:"Envelope Italy",w:110*f,h:230*f},37:{name:"Envelope Monarch",w:3.875*c,h:7.5*c},38:{name:"Envelope 6 3/4",w:3.625*c,h:6.5*c},39:{name:"US Standard Fanfold",w:11*c,h:14.875*c,wide:!0},40:{name:"German Standard Fanfold",w:8.5*c,h:12*c},41:{name:"German Legal Fanfold",w:8.5*c,h:13*c},42:{name:"ISO B4",w:250*f,h:353*f},43:{name:"Japanese Postcard",w:100*f,h:148*f},66:{name:"A2",w:420*f,h:594*f,common:!0},70:{name:"A6",w:105*f,h:148*f,common:!0}},he={normal:{name:"Normal",left:.7,right:.7,top:.75,bottom:.75,header:.3,footer:.3},wide:{name:"Wide",left:1,right:1,top:1,bottom:1,header:.5,footer:.5},narrow:{name:"Narrow",left:.25,right:.25,top:.75,bottom:.75,header:.3,footer:.3}};function A(){return{paperSize:null,paperWidth:null,paperHeight:null,orientation:"default",scale:100,fitToPage:!1,fitToWidth:1,fitToHeight:1,firstPageNumber:1,useFirstPageNumber:!1,pageOrder:"downThenOver",blackAndWhite:!1,draft:!1,cellComments:"none",errors:"displayed",margins:{left:.7,right:.7,top:.75,bottom:.75,header:.3,footer:.3},horizontalCentered:!1,verticalCentered:!1,headings:!1,gridLines:!1,header:{odd:"",even:"",first:""},footer:{odd:"",even:"",first:""},differentOddEven:!1,differentFirst:!1,scaleWithDoc:!0,alignWithMargins:!0,rowBreaks:[],colBreaks:[],printAreas:[],titleRows:null,titleCols:null,extra:{pageSetup:{},printOptions:{},headerFooter:{}}}}function ue(e){return e.pageSetup||(e.pageSetup=A()),e.pageSetup}function pe(e){return structuredClone(e)}function Q(e=globalThis.navigator?.language??"en-US"){const r=/[-_]([A-Za-z]{2})\b/.exec(e)?.[1]?.toUpperCase();return["US","CA","MX","PH","CL","CO","VE"].includes(r)?1:9}const z=e=>{const r=/^\s*([0-9.]+)\s*(mm|cm|in|pt|pc|pi)?\s*$/.exec(e??"");if(!r)return null;const t={mm:f,cm:10*f,in:c,pt:1,pc:12,pi:12};return Number(r[1])*(t[r[2]??"in"]??c)};function ge(e,r=Q()){const t=e.paperSize===null||!N[e.paperSize];let n,o,i;const s=z(e.paperWidth),l=z(e.paperHeight);if(t&&s!==null&&l!==null)n=s,o=l,i="Custom";else{const d=N[e.paperSize]??N[r]??N[9];n=d.w,o=d.h,i=d.name,d.wide&&([n,o]=[o,n])}return e.orientation==="landscape"&&([n,o]=[o,n]),{width:n,height:o,name:i}}const W=e=>{const r={};for(const t of(e??"").matchAll(/([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g))t[1]==="xmlns"||t[1].startsWith("xmlns:")||(r[t[1]]=F(t[2]??t[3]??""));return r},D=e=>new RegExp(`<((?:[\\w.-]+:)?)${e}\\b([^>]*?)(?:/>|>([\\s\\S]*?)</\\1${e}\\s*>)`),V=e=>new RegExp(D(e).source,"g"),w=(e,r)=>{const t=D(r).exec(e);return t?{attrs:W(t[2]),inner:t[3]??"",at:t.index,end:t.index+t[0].length}:null},u=e=>e==="1"||e==="true",$=(e,r)=>{const t=Number(e);return e===void 0||e===""||!Number.isFinite(t)?r:t},B=(e,r)=>{const t={};for(const n of Object.keys(e))r.includes(n)||(t[n]=e[n]);return t},Y=["paperSize","paperWidth","paperHeight","scale","firstPageNumber","fitToWidth","fitToHeight","pageOrder","orientation","blackAndWhite","draft","cellComments","errors","useFirstPageNumber"],ee=["horizontalCentered","verticalCentered","headings","gridLines","gridLinesSet"],te=["differentOddEven","differentFirst","scaleWithDoc","alignWithMargins"];function j(e,r,t){const n=w(e,r);if(!n)return[];const o=[];for(const i of n.inner.matchAll(/<(?:[\w.-]+:)?brk\b([^>]*?)\/?>/g)){const s=W(i[1]),l=Number(s.id);u(s.man)&&Number.isInteger(l)&&l>0&&l<t&&o.push(l)}return[...new Set(o)].sort((i,s)=>i-s)}const S=(e,r)=>{const t=w(e,r);return t?Z(F(t.inner)):""};function we(e,r){const t=A(),n=w(e??"","pageSetUpPr");n&&(t.fitToPage=u(n.attrs.fitToPage));const o=r??"",i=w(o,"pageMargins");if(i)for(const a of Object.keys(t.margins))t.margins[a]=$(i.attrs[a],t.margins[a]);const s=w(o,"printOptions");s&&(t.horizontalCentered=u(s.attrs.horizontalCentered),t.verticalCentered=u(s.attrs.verticalCentered),t.headings=u(s.attrs.headings),t.gridLines=u(s.attrs.gridLines),t.extra.printOptions=B(s.attrs,ee),s.attrs.gridLinesSet!==void 0&&(t.extra.printOptions.gridLinesSet=s.attrs.gridLinesSet));const l=w(o,"pageSetup");if(l){const a=l.attrs;t.paperSize=a.paperSize!==void 0?$(a.paperSize,null):null,t.paperWidth=a.paperWidth??null,t.paperHeight=a.paperHeight??null,t.scale=$(a.scale,100),t.firstPageNumber=$(a.firstPageNumber,1),t.useFirstPageNumber=u(a.useFirstPageNumber),t.fitToWidth=$(a.fitToWidth,1),t.fitToHeight=$(a.fitToHeight,1),t.pageOrder=a.pageOrder==="overThenDown"?"overThenDown":"downThenOver",t.orientation=a.orientation==="landscape"||a.orientation==="portrait"?a.orientation:"default",t.blackAndWhite=u(a.blackAndWhite),t.draft=u(a.draft),t.cellComments=a.cellComments??"none",t.errors=a.errors??"displayed",t.extra.pageSetup=B(a,Y)}const d=w(o,"headerFooter");if(d){const a=d.attrs;t.differentOddEven=u(a.differentOddEven),t.differentFirst=u(a.differentFirst),t.scaleWithDoc=a.scaleWithDoc===void 0?!0:u(a.scaleWithDoc),t.alignWithMargins=a.alignWithMargins===void 0?!0:u(a.alignWithMargins),t.extra.headerFooter=B(a,te),t.header={odd:S(d.inner,"oddHeader"),even:S(d.inner,"evenHeader"),first:S(d.inner,"firstHeader")},t.footer={odd:S(d.inner,"oddFooter"),even:S(d.inner,"evenFooter"),first:S(d.inner,"firstFooter")}}return t.rowBreaks=j(o,"rowBreaks",T),t.colBreaks=j(o,"colBreaks",b),t}const R=e=>e.filter(([,r])=>r!=null).map(([r,t])=>` ${r}="${_(t)}"`).join(""),g=e=>e?"1":null;function P(e,r){if(!r)return"";const t=/^\s|\s$|\n/.test(r)?' xml:space="preserve"':"";return`<${e}${t}>${K(r)}</${e}>`}function y(e,r,t){if(!r||r.length===0)return"";const n=r.map(o=>`<brk id="${o}" max="${t}" man="1"/>`).join("");return`<${e} count="${r.length}" manualBreakCount="${r.length}">${n}</${e}>`}function ne(e){const r=A(),t=R([["horizontalCentered",g(e.horizontalCentered)],["verticalCentered",g(e.verticalCentered)],["headings",g(e.headings)],["gridLines",g(e.gridLines)],...Object.entries(e.extra?.printOptions??{})]),n=e.margins,o=R([["paperSize",e.paperSize],["paperHeight",e.paperHeight],["paperWidth",e.paperWidth],["scale",e.scale!==r.scale?e.scale:null],["firstPageNumber",e.useFirstPageNumber||e.firstPageNumber!==r.firstPageNumber?e.firstPageNumber:null],["fitToWidth",e.fitToWidth!==r.fitToWidth?e.fitToWidth:null],["fitToHeight",e.fitToHeight!==r.fitToHeight?e.fitToHeight:null],["pageOrder",e.pageOrder!==r.pageOrder?e.pageOrder:null],["orientation",e.orientation!=="default"?e.orientation:null],["blackAndWhite",g(e.blackAndWhite)],["draft",g(e.draft)],["cellComments",e.cellComments!=="none"?e.cellComments:null],["useFirstPageNumber",g(e.useFirstPageNumber)],["errors",e.errors!=="displayed"?e.errors:null],...Object.entries(e.extra?.pageSetup??{})]),i=[P("oddHeader",e.header.odd),P("oddFooter",e.footer.odd),P("evenHeader",e.header.even),P("evenFooter",e.footer.even),P("firstHeader",e.header.first),P("firstFooter",e.footer.first)].join(""),s=R([["differentOddEven",g(e.differentOddEven)],["differentFirst",g(e.differentFirst)],["scaleWithDoc",e.scaleWithDoc?null:"0"],["alignWithMargins",e.alignWithMargins?null:"0"],...Object.entries(e.extra?.headerFooter??{})]);return[t?`<printOptions${t}/>`:"",`<pageMargins left="${n.left}" right="${n.right}" top="${n.top}" bottom="${n.bottom}" header="${n.header}" footer="${n.footer}"/>`,o?`<pageSetup${o}/>`:"",i||s?`<headerFooter${s}>${i}</headerFooter>`:"",y("rowBreaks",e.rowBreaks,b-1),y("colBreaks",e.colBreaks,T-1)].join("")}const re=["printOptions","pageMargins","pageSetup","headerFooter","rowBreaks","colBreaks"],oe=/<(?:[\w.-]+:)?(?:customProperties|cellWatches|ignoredErrors|smartTags|drawing|legacyDrawing|legacyDrawingHF|drawingHF|picture|oleObjects|controls|webPublishItems|tableParts|extLst|AlternateContent)\b|<\/(?:[\w.-]+:)?worksheet\s*>/;function ie(e,r){let t=e??"</worksheet>",n=-1;for(const i of re){const s=V(i);t=t.replace(s,(l,d,a,m,h)=>((n<0||h<n)&&(n=h),""))}const o=ne(r);if(n<0||n>t.length){const i=oe.exec(t);n=i?i.index:t.length}return t.slice(0,n)+o+t.slice(n)}function xe(e,r){const t=A(),{pageSetup:n={},headerFooter:o={}}=r.extra??{},i={};for(const s of["usePrinterDefaults","copies","horizontalDpi","verticalDpi","r:id"])n[s]!==void 0&&(i[s]=n[s]);return ie(e,{...r,scale:t.scale,fitToWidth:t.fitToWidth,fitToHeight:t.fitToHeight,pageOrder:t.pageOrder,cellComments:t.cellComments,errors:t.errors,horizontalCentered:!1,verticalCentered:!1,headings:!1,gridLines:!1,rowBreaks:[],colBreaks:[],extra:{pageSetup:i,printOptions:{},headerFooter:o}})}function $e(e,r){const t=/<((?:[\w.-]+:)?)pageSetUpPr\b([^>]*?)\/>/.exec(e);if(t){const l=t[2].replace(/\s*fitToPage\s*=\s*(?:"[^"]*"|'[^']*')/,""),d=r.fitToPage?` fitToPage="1"${l}`:l;return d.trim()?`${e.slice(0,t.index)}<${t[1]}pageSetUpPr${d}/>${e.slice(t.index+t[0].length)}`:e.slice(0,t.index)+e.slice(t.index+t[0].length)}if(!r.fitToPage)return e;const n=/<\/((?:[\w.-]+:)?)sheetPr\s*>/.exec(e);if(n)return`${e.slice(0,n.index)}<${n[1]}pageSetUpPr fitToPage="1"/>${e.slice(n.index)}`;const o=/<((?:[\w.-]+:)?)sheetPr\b([^>]*?)\/>/.exec(e);if(o)return`${e.slice(0,o.index)}<${o[1]}sheetPr${o[2]}><${o[1]}pageSetUpPr fitToPage="1"/></${o[1]}sheetPr>${e.slice(o.index+o[0].length)}`;const i=/<((?:[\w.-]+:)?)worksheet\b[^>]*>/.exec(e);if(!i)return e;const s=i.index+i[0].length;return`${e.slice(0,s)}<${i[1]}sheetPr><${i[1]}pageSetUpPr fitToPage="1"/></${i[1]}sheetPr>${e.slice(s)}`}const E="_xlnm.Print_Area",O="_xlnm.Print_Titles";function U(e){const r=[];let t=!1,n=0;for(let o=0;o<e.length;o++){const i=e[o];i==="'"?t=!t:i===","&&!t&&(r.push(e.slice(n,o)),n=o+1)}return r.push(e.slice(n)),r.map(o=>o.trim().replace(/^\(|\)$/g,"")).filter(Boolean)}const v=e=>{const r=e.lastIndexOf("!");return r<0?e:e.slice(r+1)},H=e=>e.c0===0&&e.c1===b-1,I=e=>e.r0===0&&e.r1===T-1;function ae(e){const r=[];for(const t of U(e??"")){const n=C(v(t));n&&r.push(n)}return r}function se(e){const r={titleRows:null,titleCols:null};for(const t of U(e??"")){const n=C(v(t));n&&(H(n)?r.titleRows={r0:n.r0,r1:n.r1}:I(n)&&(r.titleCols={c0:n.c0,c1:n.c1}))}return r}function Se(e){const r=[];for(const t of(e??"").matchAll(/<(?:[\w.-]+:)?definedName\b([^>]*)>([\s\S]*?)<\/(?:[\w.-]+:)?definedName\s*>/g)){const n=W(t[1]);n.name!==E&&n.name!==O||n.localSheetId!==void 0&&r.push({name:n.name,localSheetId:Number(n.localSheetId),text:F(t[2])})}return r}function Pe(e,r,t){for(const n of r??[])n.localSheetId===t&&(n.name===E?e.printAreas=ae(n.text):n.name===O&&Object.assign(e,se(n.text)));return e}function ce(e){if(I(e))return`$${x(e.c0)}:$${x(e.c1)}`;if(H(e))return`$${e.r0+1}:$${e.r1+1}`;const r=`$${x(e.c0)}$${e.r0+1}`;return e.r0===e.r1&&e.c0===e.c1?r:`${r}:$${x(e.c1)}$${e.r1+1}`}function ke(e){const r=[];return e.forEach((t,n)=>{const o=t.pageSetup;if(!o)return;const i=J(t.name);o.printAreas.length>0&&r.push({name:E,localSheetId:n,text:o.printAreas.map(l=>`${i}!${ce(l)}`).join(",")});const s=[];o.titleCols&&s.push(`${i}!$${x(o.titleCols.c0)}:$${x(o.titleCols.c1)}`),o.titleRows&&s.push(`${i}!$${o.titleRows.r0+1}:$${o.titleRows.r1+1}`),s.length>0&&r.push({name:O,localSheetId:n,text:s.join(",")})}),r}function be(e,r){const t=/<((?:[\w.-]+:)?)definedName\b([^>]*)>[\s\S]*?<\/\1definedName\s*>/g;let n=e.replace(t,(l,d,a)=>{const m=W(a).name;return m===E||m===O?"":l});const o=r.map(l=>`<definedName name="${l.name}" localSheetId="${l.localSheetId}">${_(l.text)}</definedName>`).join(""),i=/<((?:[\w.-]+:)?)definedNames\b[^>]*>([\s\S]*?)<\/\1definedNames\s*>/.exec(n);if(i){const l=i[2]+o,d=l.trim()?`<${i[1]}definedNames>${l}</${i[1]}definedNames>`:"";return n.slice(0,i.index)+d+n.slice(i.index+i[0].length)}if(!o)return n;let s=-1;for(const l of[/<\/(?:[\w.-]+:)?sheets\s*>/,/<\/(?:[\w.-]+:)?functionGroups\s*>/,/<(?:[\w.-]+:)?functionGroups\b[^>]*\/>/,/<\/(?:[\w.-]+:)?externalReferences\s*>/]){const d=l.exec(n);d&&(s=Math.max(s,d.index+d[0].length))}return s<0||(n=`${n.slice(0,s)}<definedNames>${o}</definedNames>${n.slice(s)}`),n}const X={P:"page",N:"pages",D:"date",T:"time",F:"file",A:"sheet",Z:"path",G:"picture"},G=()=>({font:null,size:null,bold:!1,italic:!1,underline:0,strike:!1,script:0,color:null});function Te(e){const r={left:[],center:[],right:[]};let t=r.center,n=G(),o="";const i=()=>{o&&t.push({...n,text:o}),o=""},s=e??"";for(let l=0;l<s.length;l++){const d=s[l];if(d!=="&"){o+=d;continue}const a=s[++l];if(a===void 0)break;if(a==="&"){o+="&";continue}if(a==="L"||a==="C"||a==="R"){i(),t=a==="L"?r.left:a==="C"?r.center:r.right,n=G();continue}if(X[a]){i();const m={...n,field:X[a],offset:0};if(a==="P"){const h=/^[+-]\d+/.exec(s.slice(l+1,l+8));h&&(m.offset=Number(h[0]),l+=h[0].length)}t.push(m);continue}if(a==='"'){i();const m=s.indexOf('"',l+1),h=m<0?s.slice(l+1):s.slice(l+1,m);l=m<0?s.length:m;const[p,k=""]=h.split(",");n={...n},p&&p!=="-"&&(n.font=p.trim()),n.bold=/bold|fett|gras|pogrub/i.test(k),n.italic=/italic|oblique|kursywa/i.test(k);continue}if(a>="0"&&a<="9"){i();let m=l;for(;m+1<s.length&&m-l<2&&s[m+1]>="0"&&s[m+1]<="9";)m++;n={...n,size:Number(s.slice(l,m+1))},l=m;continue}if(a==="K"){i();const m=s.slice(l+1,l+7);n={...n,color:/^[0-9A-Fa-f]{6}$/.test(m)?`#${m}`:null},l+=m.length;continue}i(),n={...n},a==="B"?n.bold=!n.bold:a==="I"?n.italic=!n.italic:a==="U"?n.underline=n.underline===1?0:1:a==="E"?n.underline=n.underline===2?0:2:a==="S"?n.strike=!n.strike:a==="X"?n.script=n.script===1?0:1:a==="Y"&&(n.script=n.script===-1?0:-1)}return i(),r}function Ce({left:e="",center:r="",right:t=""}={}){return`${e?`&L${e}`:""}${r?`&C${r}`:""}${t?`&R${t}`:""}`}function Ne(e,r){e.printAreas=r.map(({r0:t,c0:n,r1:o,c1:i})=>({r0:t,c0:n,r1:o,c1:i}))}function Ae(e,r){let t={r0:r.r0,c0:r.c0,r1:r.r1,c1:r.c1};const n=(o,i)=>o.c0===i.c0&&o.c1===i.c1&&o.r0<=i.r1+1&&i.r0<=o.r1+1||o.r0===i.r0&&o.r1===i.r1&&o.c0<=i.c1+1&&i.c0<=o.c1+1;for(let o=!0;o;){o=!1;const i=e.printAreas.findIndex(s=>n(s,t));if(i>=0){const s=e.printAreas.splice(i,1)[0];t={r0:Math.min(s.r0,t.r0),c0:Math.min(s.c0,t.c0),r1:Math.max(s.r1,t.r1),c1:Math.max(s.c1,t.c1)},o=!0}}e.printAreas.push(t)}const q=(e,r)=>{e.includes(r)||(e.push(r),e.sort((t,n)=>t-n))};function We(e,r,t){r>0&&q(e.rowBreaks,r),t>0&&q(e.colBreaks,t)}function Ee(e,r,t){e.rowBreaks=e.rowBreaks.filter(n=>n!==r),e.colBreaks=e.colBreaks.filter(n=>n!==t)}function Oe(e){e.rowBreaks=[],e.colBreaks=[]}const L=(e,r,t)=>e<r?e:e+t;function M(e,r,t,n){if(n>0)return[L(e,t,n),L(r,t,n)];const o=t-n;if(e>=t&&r<o)return null;const i=e<t?e:e<o?t:e+n,s=r<t?r:r<o?t-1:r+n;return[i,s]}const le=(e,r,t)=>e===0&&r===t-1;function ve(e,r){const{axis:t,at:n,n:o}=r,i=t==="row",s=i?T:b,l=a=>{const m=[];for(const h of a){if(o<0&&h>=n&&h<n-o)continue;const p=L(h,n,o);p>0&&p<s&&m.push(p)}return m};i?e.rowBreaks=l(e.rowBreaks):e.colBreaks=l(e.colBreaks);const d=[];for(const a of e.printAreas){const m=i?a.r0:a.c0,h=i?a.r1:a.c1;if(le(m,h,s)){d.push(a);continue}const p=M(m,h,n,o);if(!p)continue;const k=Math.min(p[1],s-1);d.push(i?{...a,r0:p[0],r1:k}:{...a,c0:p[0],c1:k})}if(e.printAreas=d,i&&e.titleRows){const a=M(e.titleRows.r0,e.titleRows.r1,n,o);e.titleRows=a?{r0:a[0],r1:Math.min(a[1],s-1)}:null}if(!i&&e.titleCols){const a=M(e.titleCols.c0,e.titleCols.c1,n,o);e.titleCols=a?{c0:a[0],c1:Math.min(a[1],s-1)}:null}return e}function Fe(e){const r=C(v(e??""));return r&&H(r)?{r0:r.r0,r1:r.r1}:null}function Be(e){const r=C(v(e??""));return r&&I(r)?{c0:r.c0,c1:r.c1}:null}export{he as MARGIN_PRESETS,N as PAPER_SIZES,Ae as addToPrintArea,Pe as applyPrintNames,Ce as buildHeaderFooter,pe as clonePageSetup,A as defaultPageSetup,Q as defaultPaperSize,ue as getPageSetup,We as insertBreakAt,ne as pageSetupElementsXml,ge as paperDimensions,Te as parseHeaderFooter,ae as parsePrintArea,se as parsePrintTitles,Be as parseTitleCols,Fe as parseTitleRows,xe as patchChartSheetPageSetup,be as patchWorkbookPrintNames,$e as patchWorksheetHead,ie as patchWorksheetTail,ke as printNameEntries,Se as readPrintNamesXml,we as readWorksheetPageSetup,Ee as removeBreakAt,Oe as resetBreaks,Ne as setPrintArea,ve as shiftPageSetup};
|
|
1
|
+
import{colName as $,MAX_COLS as A,MAX_ROWS as C,parseRangeRef as N,quoteSheetName as K}from"../core/address.js";import{unescapeOoxml as Q,unescapeXml as F}from"../io/xml-scan.js";import{escapeMarkup as z,xmlText as Y}from"../io/xml-escape.js";import{splitCustomViews as D,withCustomViews as ee}from"../io/xlsx-tail.js";const c=72,f=72/25.4,E={1:{name:"Letter",w:8.5*c,h:11*c,common:!0},2:{name:"Letter Small",w:8.5*c,h:11*c},3:{name:"Tabloid",w:11*c,h:17*c,common:!0},4:{name:"Ledger",w:11*c,h:17*c,wide:!0,common:!0},5:{name:"Legal",w:8.5*c,h:14*c,common:!0},6:{name:"Statement",w:5.5*c,h:8.5*c,common:!0},7:{name:"Executive",w:7.25*c,h:10.5*c,common:!0},8:{name:"A3",w:297*f,h:420*f,common:!0},9:{name:"A4",w:210*f,h:297*f,common:!0},10:{name:"A4 Small",w:210*f,h:297*f},11:{name:"A5",w:148*f,h:210*f,common:!0},12:{name:"B4 (JIS)",w:257*f,h:364*f,common:!0},13:{name:"B5 (JIS)",w:182*f,h:257*f,common:!0},14:{name:"Folio",w:8.5*c,h:13*c},15:{name:"Quarto",w:215*f,h:275*f},16:{name:"10 x 14 in",w:10*c,h:14*c},17:{name:"11 x 17 in",w:11*c,h:17*c},18:{name:"Note",w:8.5*c,h:11*c},19:{name:"Envelope #9",w:3.875*c,h:8.875*c},20:{name:"Envelope #10",w:4.125*c,h:9.5*c,common:!0},21:{name:"Envelope #11",w:4.5*c,h:10.375*c},22:{name:"Envelope #12",w:4.75*c,h:11*c},23:{name:"Envelope #14",w:5*c,h:11.5*c},24:{name:"C",w:17*c,h:22*c},25:{name:"D",w:22*c,h:34*c},26:{name:"E",w:34*c,h:44*c},27:{name:"Envelope DL",w:110*f,h:220*f,common:!0},28:{name:"Envelope C5",w:162*f,h:229*f,common:!0},29:{name:"Envelope C3",w:324*f,h:458*f},30:{name:"Envelope C4",w:229*f,h:324*f},31:{name:"Envelope C6",w:114*f,h:162*f},32:{name:"Envelope C65",w:114*f,h:229*f},33:{name:"B4 (ISO)",w:250*f,h:353*f},34:{name:"Envelope B5",w:176*f,h:250*f},35:{name:"Envelope B6",w:125*f,h:176*f},36:{name:"Envelope Italy",w:110*f,h:230*f},37:{name:"Envelope Monarch",w:3.875*c,h:7.5*c},38:{name:"Envelope 6 3/4",w:3.625*c,h:6.5*c},39:{name:"US Standard Fanfold",w:11*c,h:14.875*c,wide:!0},40:{name:"German Standard Fanfold",w:8.5*c,h:12*c},41:{name:"German Legal Fanfold",w:8.5*c,h:13*c},42:{name:"ISO B4",w:250*f,h:353*f},43:{name:"Japanese Postcard",w:100*f,h:148*f},66:{name:"A2",w:420*f,h:594*f,common:!0},70:{name:"A6",w:105*f,h:148*f,common:!0}},xe={normal:{name:"Normal",left:.7,right:.7,top:.75,bottom:.75,header:.3,footer:.3},wide:{name:"Wide",left:1,right:1,top:1,bottom:1,header:.5,footer:.5},narrow:{name:"Narrow",left:.25,right:.25,top:.75,bottom:.75,header:.3,footer:.3}};function T(){return{paperSize:null,paperWidth:null,paperHeight:null,orientation:"default",scale:100,fitToPage:!1,fitToWidth:1,fitToHeight:1,firstPageNumber:1,useFirstPageNumber:!1,pageOrder:"downThenOver",blackAndWhite:!1,draft:!1,cellComments:"none",errors:"displayed",margins:{left:.7,right:.7,top:.75,bottom:.75,header:.3,footer:.3},horizontalCentered:!1,verticalCentered:!1,headings:!1,gridLines:!1,header:{odd:"",even:"",first:""},footer:{odd:"",even:"",first:""},differentOddEven:!1,differentFirst:!1,scaleWithDoc:!0,alignWithMargins:!0,rowBreaks:[],colBreaks:[],printAreas:[],titleRows:null,titleCols:null,extra:{pageSetup:{},printOptions:{},headerFooter:{}}}}function $e(e){return e.pageSetup||(e.pageSetup=T()),e.pageSetup}function Se(e){return structuredClone(e)}function te(e=globalThis.navigator?.language??"en-US"){const n=/[-_]([A-Za-z]{2})\b/.exec(e)?.[1]?.toUpperCase();return["US","CA","MX","PH","CL","CO","VE"].includes(n)?1:9}const j=e=>{const n=/^\s*([0-9.]+)\s*(mm|cm|in|pt|pc|pi)?\s*$/.exec(e??"");if(!n)return null;const t={mm:f,cm:10*f,in:c,pt:1,pc:12,pi:12};return Number(n[1])*(t[n[2]??"in"]??c)};function Pe(e,n=te()){const t=e.paperSize===null||!E[e.paperSize];let r,o,i;const s=j(e.paperWidth),l=j(e.paperHeight);if(t&&s!==null&&l!==null)r=s,o=l,i="Custom";else{const d=E[e.paperSize]??E[n]??E[9];r=d.w,o=d.h,i=d.name,d.wide&&([r,o]=[o,r])}return e.orientation==="landscape"&&([r,o]=[o,r]),{width:r,height:o,name:i}}const W=e=>{const n={};for(const t of(e??"").matchAll(/([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g))t[1]==="xmlns"||t[1].startsWith("xmlns:")||(n[t[1]]=F(t[2]??t[3]??""));return n},y=e=>new RegExp(`<((?:[\\w.-]+:)?)${e}\\b([^>]*?)(?:/>|>([\\s\\S]*?)</\\1${e}\\s*>)`),ne=e=>new RegExp(y(e).source,"g"),x=(e,n)=>{const t=y(n).exec(e);return t?{attrs:W(t[2]),inner:t[3]??"",at:t.index,end:t.index+t[0].length}:null},h=e=>e==="1"||e==="true",S=(e,n)=>{const t=Number(e);return e===void 0||e===""||!Number.isFinite(t)?n:t},B=(e,n)=>{const t={};for(const r of Object.keys(e))n.includes(r)||(t[r]=e[r]);return t},re=["paperSize","paperWidth","paperHeight","scale","firstPageNumber","fitToWidth","fitToHeight","pageOrder","orientation","blackAndWhite","draft","cellComments","errors","useFirstPageNumber"],oe=["horizontalCentered","verticalCentered","headings","gridLines","gridLinesSet"],ie=["differentOddEven","differentFirst","scaleWithDoc","alignWithMargins"];function U(e,n,t){const r=x(e,n);if(!r)return[];const o=[];for(const i of r.inner.matchAll(/<(?:[\w.-]+:)?brk\b([^>]*?)\/?>/g)){const s=W(i[1]),l=Number(s.id);h(s.man)&&Number.isInteger(l)&&l>0&&l<t&&o.push(l)}return[...new Set(o)].sort((i,s)=>i-s)}const P=(e,n)=>{const t=x(e,n);return t?Q(F(t.inner)):""};function ke(e,n){const t=T(),r=x(e??"","pageSetUpPr");r&&(t.fitToPage=h(r.attrs.fitToPage));const o=D(n).rest,i=x(o,"pageMargins");if(i)for(const a of Object.keys(t.margins))t.margins[a]=S(i.attrs[a],t.margins[a]);const s=x(o,"printOptions");s&&(t.horizontalCentered=h(s.attrs.horizontalCentered),t.verticalCentered=h(s.attrs.verticalCentered),t.headings=h(s.attrs.headings),t.gridLines=h(s.attrs.gridLines),t.extra.printOptions=B(s.attrs,oe),s.attrs.gridLinesSet!==void 0&&(t.extra.printOptions.gridLinesSet=s.attrs.gridLinesSet));const l=x(o,"pageSetup");if(l){const a=l.attrs;t.paperSize=a.paperSize!==void 0?S(a.paperSize,null):null,t.paperWidth=a.paperWidth??null,t.paperHeight=a.paperHeight??null,t.scale=S(a.scale,100),t.firstPageNumber=S(a.firstPageNumber,1),t.useFirstPageNumber=h(a.useFirstPageNumber),t.fitToWidth=S(a.fitToWidth,1),t.fitToHeight=S(a.fitToHeight,1),t.pageOrder=a.pageOrder==="overThenDown"?"overThenDown":"downThenOver",t.orientation=a.orientation==="landscape"||a.orientation==="portrait"?a.orientation:"default",t.blackAndWhite=h(a.blackAndWhite),t.draft=h(a.draft),t.cellComments=a.cellComments??"none",t.errors=a.errors??"displayed",t.extra.pageSetup=B(a,re)}const d=x(o,"headerFooter");if(d){const a=d.attrs;t.differentOddEven=h(a.differentOddEven),t.differentFirst=h(a.differentFirst),t.scaleWithDoc=a.scaleWithDoc===void 0?!0:h(a.scaleWithDoc),t.alignWithMargins=a.alignWithMargins===void 0?!0:h(a.alignWithMargins),t.extra.headerFooter=B(a,ie),t.header={odd:P(d.inner,"oddHeader"),even:P(d.inner,"evenHeader"),first:P(d.inner,"firstHeader")},t.footer={odd:P(d.inner,"oddFooter"),even:P(d.inner,"evenFooter"),first:P(d.inner,"firstFooter")}}return t.rowBreaks=U(o,"rowBreaks",C),t.colBreaks=U(o,"colBreaks",A),t}const R=e=>e.filter(([,n])=>n!=null).map(([n,t])=>` ${n}="${z(t)}"`).join(""),w=e=>e?"1":null;function k(e,n){if(!n)return"";const t=/^\s|\s$|\n/.test(n)?' xml:space="preserve"':"";return`<${e}${t}>${Y(n)}</${e}>`}function X(e,n,t){if(!n||n.length===0)return"";const r=n.map(o=>`<brk id="${o}" max="${t}" man="1"/>`).join("");return`<${e} count="${n.length}" manualBreakCount="${n.length}">${r}</${e}>`}function ae(e){const n=T(),t=R([["horizontalCentered",w(e.horizontalCentered)],["verticalCentered",w(e.verticalCentered)],["headings",w(e.headings)],["gridLines",w(e.gridLines)],...Object.entries(e.extra?.printOptions??{})]),r=e.margins,o=R([["paperSize",e.paperSize],["paperHeight",e.paperHeight],["paperWidth",e.paperWidth],["scale",e.scale!==n.scale?e.scale:null],["firstPageNumber",e.useFirstPageNumber||e.firstPageNumber!==n.firstPageNumber?e.firstPageNumber:null],["fitToWidth",e.fitToWidth!==n.fitToWidth?e.fitToWidth:null],["fitToHeight",e.fitToHeight!==n.fitToHeight?e.fitToHeight:null],["pageOrder",e.pageOrder!==n.pageOrder?e.pageOrder:null],["orientation",e.orientation!=="default"?e.orientation:null],["blackAndWhite",w(e.blackAndWhite)],["draft",w(e.draft)],["cellComments",e.cellComments!=="none"?e.cellComments:null],["useFirstPageNumber",w(e.useFirstPageNumber)],["errors",e.errors!=="displayed"?e.errors:null],...Object.entries(e.extra?.pageSetup??{})]),i=[k("oddHeader",e.header.odd),k("oddFooter",e.footer.odd),k("evenHeader",e.header.even),k("evenFooter",e.footer.even),k("firstHeader",e.header.first),k("firstFooter",e.footer.first)].join(""),s=R([["differentOddEven",w(e.differentOddEven)],["differentFirst",w(e.differentFirst)],["scaleWithDoc",e.scaleWithDoc?null:"0"],["alignWithMargins",e.alignWithMargins?null:"0"],...Object.entries(e.extra?.headerFooter??{})]);return[t?`<printOptions${t}/>`:"",`<pageMargins left="${r.left}" right="${r.right}" top="${r.top}" bottom="${r.bottom}" header="${r.header}" footer="${r.footer}"/>`,o?`<pageSetup${o}/>`:"",i||s?`<headerFooter${s}>${i}</headerFooter>`:"",X("rowBreaks",e.rowBreaks,A-1),X("colBreaks",e.colBreaks,C-1)].join("")}const se=["printOptions","pageMargins","pageSetup","headerFooter","rowBreaks","colBreaks"],le=/<(?:[\w.-]+:)?(?:customProperties|cellWatches|ignoredErrors|smartTags|drawing|legacyDrawing|legacyDrawingHF|drawingHF|picture|oleObjects|controls|webPublishItems|tableParts|extLst|AlternateContent)\b|<\/(?:[\w.-]+:)?worksheet\s*>/;function ce(e,n){const{rest:t,views:r}=D(e??"</worksheet>");let o=t,i=-1;for(const l of se){const d=ne(l);o=o.replace(d,(a,m,u,g,p)=>((i<0||p<i)&&(i=p),""))}const s=ae(n);if(i<0||i>o.length){const l=le.exec(o);i=l?l.index:o.length}return ee(o.slice(0,i)+s+o.slice(i),r)}function be(e,n){const t=T(),{pageSetup:r={},headerFooter:o={}}=n.extra??{},i={};for(const s of["usePrinterDefaults","copies","horizontalDpi","verticalDpi","r:id"])r[s]!==void 0&&(i[s]=r[s]);return ce(e,{...n,scale:t.scale,fitToWidth:t.fitToWidth,fitToHeight:t.fitToHeight,pageOrder:t.pageOrder,cellComments:t.cellComments,errors:t.errors,horizontalCentered:!1,verticalCentered:!1,headings:!1,gridLines:!1,rowBreaks:[],colBreaks:[],extra:{pageSetup:i,printOptions:{},headerFooter:o}})}function Te(e,n){const t=/<((?:[\w.-]+:)?)pageSetUpPr\b([^>]*?)\/>/.exec(e);if(t){const l=t[2].replace(/\s*fitToPage\s*=\s*(?:"[^"]*"|'[^']*')/,""),d=n.fitToPage?` fitToPage="1"${l}`:l;return d.trim()?`${e.slice(0,t.index)}<${t[1]}pageSetUpPr${d}/>${e.slice(t.index+t[0].length)}`:e.slice(0,t.index)+e.slice(t.index+t[0].length)}if(!n.fitToPage)return e;const r=/<\/((?:[\w.-]+:)?)sheetPr\s*>/.exec(e);if(r)return`${e.slice(0,r.index)}<${r[1]}pageSetUpPr fitToPage="1"/>${e.slice(r.index)}`;const o=/<((?:[\w.-]+:)?)sheetPr\b([^>]*?)\/>/.exec(e);if(o)return`${e.slice(0,o.index)}<${o[1]}sheetPr${o[2]}><${o[1]}pageSetUpPr fitToPage="1"/></${o[1]}sheetPr>${e.slice(o.index+o[0].length)}`;const i=/<((?:[\w.-]+:)?)worksheet\b[^>]*>/.exec(e);if(!i)return e;const s=i.index+i[0].length;return`${e.slice(0,s)}<${i[1]}sheetPr><${i[1]}pageSetUpPr fitToPage="1"/></${i[1]}sheetPr>${e.slice(s)}`}const b="_xlnm.Print_Area",v="_xlnm.Print_Titles";function G(e){const n=[];let t=!1,r=0;for(let o=0;o<e.length;o++){const i=e[o];i==="'"?t=!t:i===","&&!t&&(n.push(e.slice(r,o)),r=o+1)}return n.push(e.slice(r)),n.map(o=>o.trim().replace(/^\(|\)$/g,"")).filter(Boolean)}const O=e=>{const n=e.lastIndexOf("!");return n<0?e:e.slice(n+1)},I=e=>e.c0===0&&e.c1===A-1,H=e=>e.r0===0&&e.r1===C-1,fe=/^(?:(?:'(?:[^']|'')*'|[^'"(){},+*/&<>=!\s]+)!)?[$A-Za-z0-9:]+$/;function q(e){const n=[];for(const t of G(e??"")){const r=fe.test(t)?N(O(t)):null;if(!r)return null;n.push(r)}return n}function de(e){const n={titleRows:null,titleCols:null};for(const t of G(e??"")){const r=N(O(t));r&&(I(r)?n.titleRows={r0:r.r0,r1:r.r1}:H(r)&&(n.titleCols={c0:r.c0,c1:r.c1}))}return n}function Ae(e){const n=[];for(const t of(e??"").matchAll(/<(?:[\w.-]+:)?definedName\b([^>]*)>([\s\S]*?)<\/(?:[\w.-]+:)?definedName\s*>/g)){const r=W(t[1]);r.name!==b&&r.name!==v||r.localSheetId!==void 0&&n.push({name:r.name,localSheetId:Number(r.localSheetId),text:F(t[2])})}return n}function Ce(e,n,t){for(const r of n??[])r.localSheetId===t&&(r.name===b?e.printAreas=q(r.text)??[]:r.name===v&&Object.assign(e,de(r.text)));return e}function me(e){if(H(e))return`$${$(e.c0)}:$${$(e.c1)}`;if(I(e))return`$${e.r0+1}:$${e.r1+1}`;const n=`$${$(e.c0)}$${e.r0+1}`;return e.r0===e.r1&&e.c0===e.c1?n:`${n}:$${$(e.c1)}$${e.r1+1}`}function Ne(e,n){const t=e?.find(r=>r.name===b&&r.localSheetId===n)?.text;return t&&q(t)===null?t:null}function Ee(e){const n=[];return e.forEach((t,r)=>{const o=t.pageSetup??(t.printAreaFormula?T():null);if(!o)return;const i=K(t.name);o.printAreas.length>0?n.push({name:b,localSheetId:r,text:o.printAreas.map(l=>`${i}!${me(l)}`).join(",")}):t.printAreaFormula&&n.push({name:b,localSheetId:r,text:t.printAreaFormula});const s=[];o.titleCols&&s.push(`${i}!$${$(o.titleCols.c0)}:$${$(o.titleCols.c1)}`),o.titleRows&&s.push(`${i}!$${o.titleRows.r0+1}:$${o.titleRows.r1+1}`),s.length>0&&n.push({name:v,localSheetId:r,text:s.join(",")})}),n}function We(e,n){const t=/<((?:[\w.-]+:)?)definedName\b([^>]*)>[\s\S]*?<\/\1definedName\s*>/g;let r=e.replace(t,(l,d,a)=>{const m=W(a).name;return m===b||m===v?"":l});const o=n.map(l=>`<definedName name="${l.name}" localSheetId="${l.localSheetId}">${z(l.text)}</definedName>`).join(""),i=/<((?:[\w.-]+:)?)definedNames\b[^>]*>([\s\S]*?)<\/\1definedNames\s*>/.exec(r);if(i){const l=i[2]+o,d=l.trim()?`<${i[1]}definedNames>${l}</${i[1]}definedNames>`:"";return r.slice(0,i.index)+d+r.slice(i.index+i[0].length)}if(!o)return r;let s=-1;for(const l of[/<\/(?:[\w.-]+:)?sheets\s*>/,/<\/(?:[\w.-]+:)?functionGroups\s*>/,/<(?:[\w.-]+:)?functionGroups\b[^>]*\/>/,/<\/(?:[\w.-]+:)?externalReferences\s*>/]){const d=l.exec(r);d&&(s=Math.max(s,d.index+d[0].length))}return s<0||(r=`${r.slice(0,s)}<definedNames>${o}</definedNames>${r.slice(s)}`),r}const Z={P:"page",N:"pages",D:"date",T:"time",F:"file",A:"sheet",Z:"path",G:"picture"},J=()=>({font:null,size:null,bold:!1,italic:!1,underline:0,strike:!1,script:0,color:null});function ve(e){const n={left:[],center:[],right:[]};let t=n.center,r=J(),o="";const i=()=>{o&&t.push({...r,text:o}),o=""},s=e??"";for(let l=0;l<s.length;l++){const d=s[l];if(d!=="&"){o+=d;continue}const a=s[++l];if(a===void 0)break;if(a==="&"){o+="&";continue}if(a==="L"||a==="C"||a==="R"){i(),t=a==="L"?n.left:a==="C"?n.center:n.right,r=J();continue}if(Z[a]){i();const m={...r,field:Z[a],offset:0};if(a==="P"){const u=/^[+-]\d+/.exec(s.slice(l+1,l+8));u&&(m.offset=Number(u[0]),l+=u[0].length)}t.push(m);continue}if(a==='"'){i();const m=s.indexOf('"',l+1),u=m<0?s.slice(l+1):s.slice(l+1,m);l=m<0?s.length:m;const[g,p=""]=u.split(",");r={...r},g&&g!=="-"&&(r.font=g.trim()),r.bold=/bold|fett|gras|pogrub/i.test(p),r.italic=/italic|oblique|kursywa/i.test(p);continue}if(a>="0"&&a<="9"){i();let m=l;for(;m+1<s.length&&m-l<2&&s[m+1]>="0"&&s[m+1]<="9";)m++;r={...r,size:Number(s.slice(l,m+1))},l=m;continue}if(a==="K"){i();const m=s.slice(l+1,l+7);r={...r,color:/^[0-9A-Fa-f]{6}$/.test(m)?`#${m}`:null},l+=m.length;continue}i(),r={...r},a==="B"?r.bold=!r.bold:a==="I"?r.italic=!r.italic:a==="U"?r.underline=r.underline===1?0:1:a==="E"?r.underline=r.underline===2?0:2:a==="S"?r.strike=!r.strike:a==="X"?r.script=r.script===1?0:1:a==="Y"&&(r.script=r.script===-1?0:-1)}return i(),n}function Oe({left:e="",center:n="",right:t=""}={}){return`${e?`&L${e}`:""}${n?`&C${n}`:""}${t?`&R${t}`:""}`}function Fe(e,n){e.printAreas=n.map(({r0:t,c0:r,r1:o,c1:i})=>({r0:t,c0:r,r1:o,c1:i}))}function Be(e,n){let t={r0:n.r0,c0:n.c0,r1:n.r1,c1:n.c1};const r=(o,i)=>o.c0===i.c0&&o.c1===i.c1&&o.r0<=i.r1+1&&i.r0<=o.r1+1||o.r0===i.r0&&o.r1===i.r1&&o.c0<=i.c1+1&&i.c0<=o.c1+1;for(let o=!0;o;){o=!1;const i=e.printAreas.findIndex(s=>r(s,t));if(i>=0){const s=e.printAreas.splice(i,1)[0];t={r0:Math.min(s.r0,t.r0),c0:Math.min(s.c0,t.c0),r1:Math.max(s.r1,t.r1),c1:Math.max(s.c1,t.c1)},o=!0}}e.printAreas.push(t)}const V=(e,n)=>{e.includes(n)||(e.push(n),e.sort((t,r)=>t-r))};function Re(e,n,t){n>0&&V(e.rowBreaks,n),t>0&&V(e.colBreaks,t)}function Ie(e,n,t){e.rowBreaks=e.rowBreaks.filter(r=>r!==n),e.colBreaks=e.colBreaks.filter(r=>r!==t)}function He(e){e.rowBreaks=[],e.colBreaks=[]}const L=(e,n,t)=>e<n?e:e+t;function M(e,n,t,r){if(r>0)return[L(e,t,r),L(n,t,r)];const o=t-r;if(e>=t&&n<o)return null;const i=e<t?e:e<o?t:e+r,s=n<t?n:n<o?t-1:n+r;return[i,s]}const ue=(e,n,t)=>e===0&&n===t-1;function Le(e,n){const{axis:t,at:r,n:o}=n,i=t==="row",s=i?C:A,l=a=>{const m=[];for(const u of a){if(o<0&&u>=r&&u<r-o)continue;const g=L(u,r,o);g>0&&g<s&&m.push(g)}return m};n.span||(i?e.rowBreaks=l(e.rowBreaks):e.colBreaks=l(e.colBreaks));const d=[];for(const a of e.printAreas){const m=i?a.r0:a.c0,u=i?a.r1:a.c1;if(n.span&&(i?a.c0<n.span[0]||a.c1>n.span[1]:a.r0<n.span[0]||a.r1>n.span[1])||ue(m,u,s)){d.push(a);continue}const p=M(m,u,r,o);if(!p)continue;const _=Math.min(p[1],s-1);d.push(i?{...a,r0:p[0],r1:_}:{...a,c0:p[0],c1:_})}if(e.printAreas=d,n.span)return e;if(i&&e.titleRows){const a=M(e.titleRows.r0,e.titleRows.r1,r,o);e.titleRows=a?{r0:a[0],r1:Math.min(a[1],s-1)}:null}if(!i&&e.titleCols){const a=M(e.titleCols.c0,e.titleCols.c1,r,o);e.titleCols=a?{c0:a[0],c1:Math.min(a[1],s-1)}:null}return e}function Me(e){const n=N(O(e??""));return n&&I(n)?{r0:n.r0,r1:n.r1}:null}function _e(e){const n=N(O(e??""));return n&&H(n)?{c0:n.c0,c1:n.c1}:null}export{xe as MARGIN_PRESETS,E as PAPER_SIZES,Be as addToPrintArea,Ce as applyPrintNames,Oe as buildHeaderFooter,Se as clonePageSetup,T as defaultPageSetup,te as defaultPaperSize,$e as getPageSetup,Re as insertBreakAt,ae as pageSetupElementsXml,Pe as paperDimensions,ve as parseHeaderFooter,q as parsePrintArea,de as parsePrintTitles,_e as parseTitleCols,Me as parseTitleRows,be as patchChartSheetPageSetup,We as patchWorkbookPrintNames,Te as patchWorksheetHead,ce as patchWorksheetTail,Ne as printAreaFormula,Ee as printNameEntries,Ae as readPrintNamesXml,ke as readWorksheetPageSetup,Ie as removeBreakAt,He as resetBreaks,Fe as setPrintArea,Le as shiftPageSetup};
|
package/print/paginate.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{notePages as z}from"./note-pages.js";import{CHUNK_MASK as B,CONTENT_MASK as D}from"../core/sheet.js";import{MAX_COLS as E,MAX_ROWS as X}from"../core/address.js";import{getPageSetup as L,paperDimensions as F}from"./page-setup.js";const K=16,A=10,Y=100;function J(c){return Math.max(22,String(c+1).length*7+6)}function U(c,t,s=null){let e=-1,n=-1;const o=t?.list,i=r=>{if(r===0||!o)return!1;const l=o[r];return l!==void 0&&(l.fill!==null||l.borders!==null)};for(let r=c.columns.length-1;r>=0;r--){const l=c.columns[r];if(l===void 0)continue;const a=G(l,e,i);a<0||(a>e&&(e=a),r>n&&(n=r))}s&&(s.r1>e&&(e=s.r1),s.c1>n&&(n=s.c1));for(const r of c.merges??[])r.r0<=e&&r.c0<=n&&(r.r1>e&&(e=r.r1),r.c1>n&&(n=r.c1));return{maxRow:e,maxCol:n}}function G(c,t,s){for(let e=c.length-1;e>=0;e--){const n=e*(B+1);if(n+B<=t)return-1;const o=c[e];if(o===void 0)continue;const{kinds:i,styles:r}=o;for(let l=B;l>=0;l--)if((i[l]&D)!==0||r!==null&&s(r[l]))return n+l}return-1}function R(c,t,s=c.length){let e=0,n=s;for(;e<n;){const o=e+n>>>1;c[o]<t?e=o+1:n=o}return e}const H=(c,t)=>{const s=c.length-1,e=R(c,t+1)-1;return e<0||e>=s?-1:e};function q(c,t,s,e,n,o,i,r=1/0){let l=new Int32Array(64),a=0;const h=p=>{if(a===l.length){const x=new Int32Array(l.length*2);x.set(l),l=x}l[a++]=p},w=c.offsetOf(s+1);let u=t,f=i?R(i,t+1):0;const m=i?i.length:0;for(;u<=s;){const p=c.offsetOf(u);if(w-p<=0)break;if(a>=r)return null;h(u);const x=n!==null&&u>n[1],b=Math.max(1,x?e-o:e);let d;for(w-p<=b?d=s+1:(d=c.indexAt(p+b),d<=u&&(d=u+1),d>s+1&&(d=s+1));f<m&&i[f]<=u;)f++;f<m&&i[f]<d&&(d=i[f]),u=d}return h(s+1),l.slice(0,a)}const W=(c,t,s)=>c.offsetOf(s+1)-c.offsetOf(t);function V(c,t,s={}){return new Q(c,t,s)}class Q{constructor(t,s,e){this.book=t,this.sheet=s,this.cols=e.cols??s.cols,this.setup=e.setup??L(s);const{setup:n}=this;this.paper=F(s.isChartSheet&&n.orientation==="default"?{...n,orientation:"landscape"}:n,e.fallbackPaper);const o=n.margins;if(this.box={x:o.left*72,y:o.top*72,w:Math.max(1,this.paper.width-(o.left+o.right)*72),h:Math.max(1,this.paper.height-(o.top+o.bottom)*72)},s.isChartSheet){this.areas=[],this.percent=100,this.scale=1,this.headingW=0,this.headingH=0,this.layouts=[],this._firsts=[],this.pageCount=1;return}const i=e.areas??(e.ignorePrintArea?[]:n.printAreas),r=i.length===0&&!e.ignorePrintArea?s.defaultPrintAreas?.()??i:i,a=r.length===0||r.some(f=>f.r0===0&&f.r1===X-1||f.c0===0&&f.c1===E-1)?U(s,t?.styles,e.objectExtent??null):null;this.areas=$(r,a),this.givenAreas=r.length>0?this.areas:null;let h=0;for(const f of this.areas)f.r1>h&&(h=f.r1);this.headingW=n.headings?J(h):0,this.headingH=n.headings?K:0;const{rows:w}=s,{cols:u}=this;this.titleRows=n.titleRows?[n.titleRows.r0,n.titleRows.r1]:null,this.titleCols=n.titleCols?[n.titleCols.c0,n.titleCols.c1]:null,this.titleH=this.titleRows?W(w,this.titleRows[0],this.titleRows[1]):0,this.titleW=this.titleCols?W(u,this.titleCols[0],this.titleCols[1]):0,this.useManualBreaks=!n.fitToPage,this.percent=n.fitToPage?this._fitPercent():Z(n.scale),this.scale=this.percent/100,this._layout()}_roomW(t){return this.box.w/t-this.headingW}_roomH(t){return this.box.h/t-this.headingH}_colBands(t,s,e=1/0){const n=this._roomW(s),o=this.titleCols!==null&&this.titleW<n?this.titleCols:null;return{title:o,starts:q(this.cols,t.c0,t.c1,n,o,this.titleW,this.useManualBreaks?this.setup.colBreaks:null,e)}}_rowBands(t,s,e=1/0){const n=this._roomH(s),o=this.titleRows!==null&&this.titleH<n?this.titleRows:null;return{title:o,starts:q(this.sheet.rows,t.r0,t.r1,n,o,this.titleH,this.useManualBreaks?this.setup.rowBreaks:null,e)}}bandsOver(t,s,e){const n=t==="col"?{c0:s,c1:e}:{r0:s,r1:e};return t==="col"?this._colBands(n,this.scale):this._rowBands(n,this.scale)}_fitPercent(){const{setup:t,sheet:s}=this,e=t.fitToWidth>0?t.fitToWidth:1/0,n=t.fitToHeight>0?t.fitToHeight:1/0;if(e===1/0&&n===1/0)return Y;const o=l=>this.areas.every(a=>(e===1/0||this._colBands(a,l/100,e).starts!==null)&&(n===1/0||this._rowBands(a,l/100,n).starts!==null));let i=Y;for(const l of this.areas){const a=W(this.cols,l.c0,l.c1)+this.headingW,h=W(s.rows,l.r0,l.r1)+this.headingH;e!==1/0&&a>0&&(i=Math.min(i,Math.ceil(100*e*this.box.w/a))),n!==1/0&&h>0&&(i=Math.min(i,Math.ceil(100*n*this.box.h/h)))}if(i=Math.max(A,i),o(i))return i;let r=A;if(!o(r))return A;for(;i-r>1;){const l=r+i>>>1;o(l)?r=l:i=l}return r}_layout(){this.layouts=[];let t=0;for(let s=0;s<this.areas.length;s++){const e=this.areas[s],n=this._rowBands(e,this.scale),o=this._colBands(e,this.scale),i=n.starts.length-1,r=o.starts.length-1,l=i*r;l!==0&&(this.layouts.push({area:e,areaIndex:s,rows:n.starts,cols:o.starts,titleRows:n.title,titleCols:o.title,nRows:i,nCols:r,first:t,count:l}),t+=l)}this.cellPages=t,this.notes=this.setup.cellComments==="atEnd"?z(this.book,this.sheet,this.givenAreas,this.box):[],this.pageCount=t+this.notes.length,this._firsts=this.layouts.map(s=>s.first)}_layoutOf(t){return this.layouts[Math.max(0,R(this._firsts,t+1)-1)]}_seq(t,s,e){return this.setup.pageOrder==="overThenDown"?s*t.nCols+e:e*t.nRows+s}page(t){if(t<0||t>=this.pageCount)return null;if(this.sheet.isChartSheet)return this._chartPage(t);if(t>=this.cellPages)return this._notePage(t);const s=this._layoutOf(t),e=t-s.first;let n,o;this.setup.pageOrder==="overThenDown"?(n=Math.floor(e/s.nCols),o=e%s.nCols):(o=Math.floor(e/s.nRows),n=e%s.nRows);const{sheet:i,setup:r,scale:l,box:a}=this,h=s.rows[n],w=s.rows[n+1]-1,u=s.cols[o],f=s.cols[o+1]-1,m=s.titleRows!==null&&h>s.titleRows[1]?{r0:s.titleRows[0],r1:s.titleRows[1]}:null,p=s.titleCols!==null&&u>s.titleCols[1]?{c0:s.titleCols[0],c1:s.titleCols[1]}:null,x=p?this.titleW:0,b=m?this.titleH:0,d=W(this.cols,u,f),C=W(i.rows,h,w),M=(this.headingW+x+d)*l,_=(this.headingH+b+C)*l,O=a.x+(r.horizontalCentered?Math.max(0,(a.w-M)/2):0),P=a.y+(r.verticalCentered?Math.max(0,(a.h-_)/2):0);return{index:t,areaIndex:s.areaIndex,area:s.area,rowBand:n,colBand:o,r0:h,r1:w,c0:u,c1:f,titleRows:m,titleCols:p,titleW:x,titleH:b,bodyW:d,bodyH:C,headingW:this.headingW,headingH:this.headingH,scale:l,paperW:this.paper.width,paperH:this.paper.height,originX:O,originY:P,contentW:M,contentH:_}}_notePage(t){const{box:s}=this;return{...this._chartPage(t),chartBox:void 0,noteLines:this.notes[t-this.cellPages],originX:s.x,originY:s.y,bodyW:s.w,bodyH:s.h}}_chartPage(t){const{box:s,paper:e}=this;return{index:t,chartBox:{x:3,y:3,w:Math.max(1,s.w-7),h:Math.max(1,s.h-7)},areaIndex:0,area:{r0:0,c0:0,r1:0,c1:0},rowBand:0,colBand:0,r0:0,r1:0,c0:0,c1:0,titleRows:null,titleCols:null,titleW:0,titleH:0,bodyW:s.w,bodyH:s.h,headingW:0,headingH:0,scale:1,paperW:e.width,paperH:e.height,originX:s.x,originY:s.y,contentW:s.w,contentH:s.h}}pageAt(t,s){for(const e of this.layouts){const{area:n}=e;if(t<n.r0||t>n.r1||s<n.c0||s>n.c1)continue;const o=H(e.rows,t),i=H(e.cols,s);if(!(o<0||i<0))return e.first+this._seq(e,o,i)}return-1}cellOnPage(t,s,e){const{sheet:n}=this,o=(l,a,h,w,u,f,m)=>a>=h&&a<=w?m+f+l.offsetOf(a)-l.offsetOf(h):u&&a>=u[0]&&a<=u[1]?m+l.offsetOf(a)-l.offsetOf(u[0]):null,i=o(n.rows,s,t.r0,t.r1,t.titleRows&&[t.titleRows.r0,t.titleRows.r1],t.titleH,t.headingH),r=o(this.cols,e,t.c0,t.c1,t.titleCols&&[t.titleCols.c0,t.titleCols.c1],t.titleW,t.headingW);return r===null||i===null?null:{x:t.originX+r*t.scale,y:t.originY+i*t.scale,w:this.cols.sizeOf(e)*t.scale,h:n.rows.sizeOf(s)*t.scale}}cellAtPoint(t,s,e){const{sheet:n}=this,o=(s-t.originX)/t.scale-t.headingW,i=(e-t.originY)/t.scale-t.headingH;if(o<0||i<0||o>=t.titleW+t.bodyW||i>=t.titleH+t.bodyH)return null;const r=i<t.titleH?n.rows.indexAt(n.rows.offsetOf(t.titleRows.r0)+i):n.rows.indexAt(n.rows.offsetOf(t.r0)+i-t.titleH),l=o<t.titleW?this.cols.indexAt(this.cols.offsetOf(t.titleCols.c0)+o):this.cols.indexAt(this.cols.offsetOf(t.c0)+o-t.titleW);return{row:r,col:l}}breakPreview(t){const{sheet:s,setup:e}=this,{rows:n}=s,{cols:o}=this,i={scale:this.scale,percent:this.percent,areas:[],rowBreaks:[],colBreaks:[],pages:[]},r=this.useManualBreaks?e.rowBreaks:[],l=this.useManualBreaks?e.colBreaks:[],a=(h,w)=>{const u=R(h,w);return u<h.length&&h[u]===w};for(const h of this.layouts){const{area:w}=h,u=o.offsetOf(w.c0),f=o.offsetOf(w.c1+1),m=n.offsetOf(w.r0),p=n.offsetOf(w.r1+1);i.areas.push({...w,x:u,y:m,w:f-u,h:p-m});const x=Math.max(t.r0,w.r0),b=Math.min(t.r1,w.r1),d=Math.max(t.c0,w.c0),C=Math.min(t.c1,w.c1);if(x>b||d>C)continue;const M=Math.max(0,H(h.rows,x)),_=Math.max(M,H(h.rows,b)),O=Math.max(0,H(h.cols,d)),P=Math.max(O,H(h.cols,C));for(let g=M;g<=_;g++){const y=h.rows[g];g!==0&&i.rowBreaks.push({row:y,y:n.offsetOf(y),x0:u,x1:f,manual:a(r,y)})}for(let g=O;g<=P;g++){const y=h.cols[g];g!==0&&i.colBreaks.push({col:y,x:o.offsetOf(y),y0:m,y1:p,manual:a(l,y)})}for(let g=M;g<=_;g++)for(let y=O;y<=P;y++){const I=h.rows[g],k=h.rows[g+1]-1,v=h.cols[y],N=h.cols[y+1]-1,T=o.offsetOf(v),S=n.offsetOf(I);i.pages.push({index:h.first+this._seq(h,g,y),r0:I,r1:k,c0:v,c1:N,x:T,y:S,w:o.offsetOf(N+1)-T,h:n.offsetOf(k+1)-S})}}return i}pageLayoutView({gap:t=18}={}){const{paper:s}=this,e=s.width,n=s.height,o=e+t,i=n+t,r=[];let l=0,a=0;for(const f of this.layouts)r.push({layout:f,y:l}),l+=f.nRows*i,a=Math.max(a,f.nCols*o-t);const h=Math.max(0,l-t);return{width:a,height:h,rectOf:f=>{const m=this.page(f);if(!m)return null;const p=r[R(this._firsts,f+1)-1];return{index:f,x:m.colBand*o,y:p.y+m.rowBand*i,w:e,h:n}},visible:(f,m,p,x)=>{const b=[];for(const{layout:d,y:C}of r){const M=Math.max(0,Math.floor((m-C)/i)),_=Math.min(d.nRows-1,Math.floor((x-C)/i)),O=Math.max(0,Math.floor(f/o)),P=Math.min(d.nCols-1,Math.floor(p/o));for(let g=M;g<=_;g++)for(let y=O;y<=P;y++)b.push({index:d.first+this._seq(d,g,y),x:y*o,y:C+g*i,w:e,h:n})}return b}}}}function Z(c){const t=Math.round(Number(c)||100);return Math.min(400,Math.max(10,t))}function $(c,t){const s=[];if(c.length===0)return t.maxRow>=0&&t.maxCol>=0&&s.push({r0:0,c0:0,r1:t.maxRow,c1:t.maxCol}),s;for(const e of c){let{r0:n,c0:o,r1:i,c1:r}=e;n===0&&i===X-1&&(i=Math.max(t.maxRow,0)),o===0&&r===E-1&&(r=Math.max(t.maxCol,0)),i>=n&&r>=o&&s.push({r0:n,c0:o,r1:i,c1:r})}return s}function ot(c,t={}){let s;Array.isArray(t.sheets)?s=t.sheets:t.sheets==="all"?s=c.sheets.map((i,r)=>i.hidden?-1:r).filter(i=>i>=0):s=[c.activeSheet];const e=[];let n=0,o=1;for(const i of s){const r=c.sheets[i],l=V(c,r,{setup:t.setups?.get(r),areas:i===c.activeSheet?t.areas:void 0,ignorePrintArea:t.ignorePrintArea,objectExtent:t.objectExtents?.get(r),fallbackPaper:t.fallbackPaper});l.setup.useFirstPageNumber&&(o=l.setup.firstPageNumber),e.push({sheet:r,sheetIndex:i,pagination:l,first:n,firstNumber:o}),n+=l.pageCount,o+=l.pageCount}return new j(c,e,n)}class j{constructor(t,s,e){this.book=t,this.entries=s,this.pageCount=e,this._firsts=s.map(n=>n.first)}entryOf(t){let s=R(this._firsts,t+1)-1;for(;s>0&&this.entries[s].pagination.pageCount===0;)s--;return this.entries[Math.max(0,s)]}at(t){if(t<0||t>=this.pageCount)return null;const s=this.entryOf(t),e=t-s.first;return{index:t,sheet:s.sheet,sheetIndex:s.sheetIndex,pagination:s.pagination,page:s.pagination.page(e),sheetPage:e,pageNumber:s.firstNumber+e,totalPages:this.pageCount}}firstPageOf(t){const s=this.entries.find(e=>e.sheetIndex===t);return s&&s.pagination.pageCount>0?s.first:-1}}export{Q as Pagination,j as PrintJob,ot as createPrintJob,R as lowerBound,V as paginate,U as printedExtent};
|
|
1
|
+
import{shownNotesExtent as D}from"./shown-notes.js";import{notePages as F}from"./note-pages.js";import{CHUNK_MASK as B,CONTENT_MASK as z}from"../core/sheet.js";import{MAX_COLS as S,MAX_ROWS as X}from"../core/address.js";import{getPageSetup as L,paperDimensions as K}from"./page-setup.js";const J=16,A=10,Y=100;function U(c){return Math.max(22,String(c+1).length*7+6)}const G=(c,t)=>c&&t?{r1:Math.max(c.r1,t.r1),c1:Math.max(c.c1,t.c1)}:c??t??null;function V(c,t,s=null){let n=-1,e=-1;const o=t?.list,i=r=>{if(r===0||!o)return!1;const l=o[r];return l!==void 0&&(l.fill!==null||l.borders!==null)};for(let r=c.columns.length-1;r>=0;r--){const l=c.columns[r];if(l===void 0)continue;const a=Q(l,n,i);a<0||(a>n&&(n=a),r>e&&(e=r))}s&&(s.r1>n&&(n=s.r1),s.c1>e&&(e=s.c1));for(const r of c.merges??[])r.r0<=n&&r.c0<=e&&(r.r1>n&&(n=r.r1),r.c1>e&&(e=r.c1));return{maxRow:n,maxCol:e}}function Q(c,t,s){for(let n=c.length-1;n>=0;n--){const e=n*(B+1);if(e+B<=t)return-1;const o=c[n];if(o===void 0)continue;const{kinds:i,styles:r}=o;for(let l=B;l>=0;l--)if((i[l]&z)!==0||r!==null&&s(r[l]))return e+l}return-1}function R(c,t,s=c.length){let n=0,e=s;for(;n<e;){const o=n+e>>>1;c[o]<t?n=o+1:e=o}return n}const H=(c,t)=>{const s=c.length-1,n=R(c,t+1)-1;return n<0||n>=s?-1:n};function q(c,t,s,n,e,o,i,r=1/0){let l=new Int32Array(64),a=0;const h=p=>{if(a===l.length){const x=new Int32Array(l.length*2);x.set(l),l=x}l[a++]=p},w=c.offsetOf(s+1);let u=t,f=i?R(i,t+1):0;const g=i?i.length:0;for(;u<=s;){const p=c.offsetOf(u);if(w-p<=0)break;if(a>=r)return null;h(u);const x=e!==null&&u>e[1],C=Math.max(1,x?n-o:n);let d;for(w-p<=C?d=s+1:(d=c.indexAt(p+C),d<=u&&(d=u+1),d>s+1&&(d=s+1));f<g&&i[f]<=u;)f++;f<g&&i[f]<d&&(d=i[f]),u=d}return h(s+1),l.slice(0,a)}const W=(c,t,s)=>c.offsetOf(s+1)-c.offsetOf(t);function Z(c,t,s={}){return new $(c,t,s)}class ${constructor(t,s,n){this.book=t,this.sheet=s,this.cols=n.cols??s.cols,this.setup=n.setup??L(s);const{setup:e}=this;this.paper=K(s.isChartSheet&&e.orientation==="default"?{...e,orientation:"landscape"}:e,n.fallbackPaper);const o=e.margins;if(this.box={x:o.left*72,y:o.top*72,w:Math.max(1,this.paper.width-(o.left+o.right)*72),h:Math.max(1,this.paper.height-(o.top+o.bottom)*72)},s.isChartSheet){this.areas=[],this.percent=100,this.scale=1,this.headingW=0,this.headingH=0,this.layouts=[],this._firsts=[],this.pageCount=1;return}const i=n.areas??(n.ignorePrintArea?[]:e.printAreas.length===0&&s.printAreaFormula&&t?.engine?t.engine.rangesOf(s.printAreaFormula,s).filter(f=>f.sheet===s):e.printAreas),r=i.length===0&&!n.ignorePrintArea?s.defaultPrintAreas?.()??i:i,a=r.length===0||r.some(f=>f.r0===0&&f.r1===X-1||f.c0===0&&f.c1===S-1)?V(s,t?.styles,G(n.objectExtent,this.setup.cellComments==="asDisplayed"?D(s):null)):null;this.areas=tt(r,a),this.givenAreas=r.length>0?this.areas:null;let h=0;for(const f of this.areas)f.r1>h&&(h=f.r1);this.headingW=e.headings?U(h):0,this.headingH=e.headings?J:0;const{rows:w}=s,{cols:u}=this;this.titleRows=e.titleRows?[e.titleRows.r0,e.titleRows.r1]:null,this.titleCols=e.titleCols?[e.titleCols.c0,e.titleCols.c1]:null,this.titleH=this.titleRows?W(w,this.titleRows[0],this.titleRows[1]):0,this.titleW=this.titleCols?W(u,this.titleCols[0],this.titleCols[1]):0,this.useManualBreaks=!e.fitToPage,this.percent=e.fitToPage?this._fitPercent():j(e.scale),this.scale=this.percent/100,this._layout()}_roomW(t){return this.box.w/t-this.headingW}_roomH(t){return this.box.h/t-this.headingH}_colBands(t,s,n=1/0){const e=this._roomW(s),o=this.titleCols!==null&&this.titleW<e?this.titleCols:null;return{title:o,starts:q(this.cols,t.c0,t.c1,e,o,this.titleW,this.useManualBreaks?this.setup.colBreaks:null,n)}}_rowBands(t,s,n=1/0){const e=this._roomH(s),o=this.titleRows!==null&&this.titleH<e?this.titleRows:null;return{title:o,starts:q(this.sheet.rows,t.r0,t.r1,e,o,this.titleH,this.useManualBreaks?this.setup.rowBreaks:null,n)}}bandsOver(t,s,n){const e=t==="col"?{c0:s,c1:n}:{r0:s,r1:n};return t==="col"?this._colBands(e,this.scale):this._rowBands(e,this.scale)}_fitPercent(){const{setup:t,sheet:s}=this,n=t.fitToWidth>0?t.fitToWidth:1/0,e=t.fitToHeight>0?t.fitToHeight:1/0;if(n===1/0&&e===1/0)return Y;const o=l=>this.areas.every(a=>(n===1/0||this._colBands(a,l/100,n).starts!==null)&&(e===1/0||this._rowBands(a,l/100,e).starts!==null));let i=Y;for(const l of this.areas){const a=W(this.cols,l.c0,l.c1)+this.headingW,h=W(s.rows,l.r0,l.r1)+this.headingH;n!==1/0&&a>0&&(i=Math.min(i,Math.ceil(100*n*this.box.w/a))),e!==1/0&&h>0&&(i=Math.min(i,Math.ceil(100*e*this.box.h/h)))}if(i=Math.max(A,i),o(i))return i;let r=A;if(!o(r))return A;for(;i-r>1;){const l=r+i>>>1;o(l)?r=l:i=l}return r}_layout(){this.layouts=[];let t=0;for(let s=0;s<this.areas.length;s++){const n=this.areas[s],e=this._rowBands(n,this.scale),o=this._colBands(n,this.scale),i=e.starts.length-1,r=o.starts.length-1,l=i*r;l!==0&&(this.layouts.push({area:n,areaIndex:s,rows:e.starts,cols:o.starts,titleRows:e.title,titleCols:o.title,nRows:i,nCols:r,first:t,count:l}),t+=l)}this.cellPages=t,this.notes=this.setup.cellComments==="atEnd"?F(this.book,this.sheet,this.givenAreas,this.box):[],this.pageCount=t+this.notes.length,this._firsts=this.layouts.map(s=>s.first)}_layoutOf(t){return this.layouts[Math.max(0,R(this._firsts,t+1)-1)]}_seq(t,s,n){return this.setup.pageOrder==="overThenDown"?s*t.nCols+n:n*t.nRows+s}page(t){if(t<0||t>=this.pageCount)return null;if(this.sheet.isChartSheet)return this._chartPage(t);if(t>=this.cellPages)return this._notePage(t);const s=this._layoutOf(t),n=t-s.first;let e,o;this.setup.pageOrder==="overThenDown"?(e=Math.floor(n/s.nCols),o=n%s.nCols):(o=Math.floor(n/s.nRows),e=n%s.nRows);const{sheet:i,setup:r,scale:l,box:a}=this,h=s.rows[e],w=s.rows[e+1]-1,u=s.cols[o],f=s.cols[o+1]-1,g=s.titleRows!==null&&h>s.titleRows[1]?{r0:s.titleRows[0],r1:s.titleRows[1]}:null,p=s.titleCols!==null&&u>s.titleCols[1]?{c0:s.titleCols[0],c1:s.titleCols[1]}:null,x=p?this.titleW:0,C=g?this.titleH:0,d=W(this.cols,u,f),M=W(i.rows,h,w),b=(this.headingW+x+d)*l,_=(this.headingH+C+M)*l,O=a.x+(r.horizontalCentered?Math.max(0,(a.w-b)/2):0),P=a.y+(r.verticalCentered?Math.max(0,(a.h-_)/2):0);return{index:t,areaIndex:s.areaIndex,area:s.area,rowBand:e,colBand:o,r0:h,r1:w,c0:u,c1:f,titleRows:g,titleCols:p,titleW:x,titleH:C,bodyW:d,bodyH:M,headingW:this.headingW,headingH:this.headingH,scale:l,paperW:this.paper.width,paperH:this.paper.height,originX:O,originY:P,contentW:b,contentH:_}}_notePage(t){const{box:s}=this;return{...this._chartPage(t),chartBox:void 0,noteLines:this.notes[t-this.cellPages],originX:s.x,originY:s.y,bodyW:s.w,bodyH:s.h}}_chartPage(t){const{box:s,paper:n}=this;return{index:t,chartBox:{x:3,y:3,w:Math.max(1,s.w-7),h:Math.max(1,s.h-7)},areaIndex:0,area:{r0:0,c0:0,r1:0,c1:0},rowBand:0,colBand:0,r0:0,r1:0,c0:0,c1:0,titleRows:null,titleCols:null,titleW:0,titleH:0,bodyW:s.w,bodyH:s.h,headingW:0,headingH:0,scale:1,paperW:n.width,paperH:n.height,originX:s.x,originY:s.y,contentW:s.w,contentH:s.h}}pageAt(t,s){for(const n of this.layouts){const{area:e}=n;if(t<e.r0||t>e.r1||s<e.c0||s>e.c1)continue;const o=H(n.rows,t),i=H(n.cols,s);if(!(o<0||i<0))return n.first+this._seq(n,o,i)}return-1}cellOnPage(t,s,n){const{sheet:e}=this,o=(l,a,h,w,u,f,g)=>a>=h&&a<=w?g+f+l.offsetOf(a)-l.offsetOf(h):u&&a>=u[0]&&a<=u[1]?g+l.offsetOf(a)-l.offsetOf(u[0]):null,i=o(e.rows,s,t.r0,t.r1,t.titleRows&&[t.titleRows.r0,t.titleRows.r1],t.titleH,t.headingH),r=o(this.cols,n,t.c0,t.c1,t.titleCols&&[t.titleCols.c0,t.titleCols.c1],t.titleW,t.headingW);return r===null||i===null?null:{x:t.originX+r*t.scale,y:t.originY+i*t.scale,w:this.cols.sizeOf(n)*t.scale,h:e.rows.sizeOf(s)*t.scale}}cellAtPoint(t,s,n){const{sheet:e}=this,o=(s-t.originX)/t.scale-t.headingW,i=(n-t.originY)/t.scale-t.headingH;if(o<0||i<0||o>=t.titleW+t.bodyW||i>=t.titleH+t.bodyH)return null;const r=i<t.titleH?e.rows.indexAt(e.rows.offsetOf(t.titleRows.r0)+i):e.rows.indexAt(e.rows.offsetOf(t.r0)+i-t.titleH),l=o<t.titleW?this.cols.indexAt(this.cols.offsetOf(t.titleCols.c0)+o):this.cols.indexAt(this.cols.offsetOf(t.c0)+o-t.titleW);return{row:r,col:l}}breakPreview(t){const{sheet:s,setup:n}=this,{rows:e}=s,{cols:o}=this,i={scale:this.scale,percent:this.percent,areas:[],rowBreaks:[],colBreaks:[],pages:[]},r=this.useManualBreaks?n.rowBreaks:[],l=this.useManualBreaks?n.colBreaks:[],a=(h,w)=>{const u=R(h,w);return u<h.length&&h[u]===w};for(const h of this.layouts){const{area:w}=h,u=o.offsetOf(w.c0),f=o.offsetOf(w.c1+1),g=e.offsetOf(w.r0),p=e.offsetOf(w.r1+1);i.areas.push({...w,x:u,y:g,w:f-u,h:p-g});const x=Math.max(t.r0,w.r0),C=Math.min(t.r1,w.r1),d=Math.max(t.c0,w.c0),M=Math.min(t.c1,w.c1);if(x>C||d>M)continue;const b=Math.max(0,H(h.rows,x)),_=Math.max(b,H(h.rows,C)),O=Math.max(0,H(h.cols,d)),P=Math.max(O,H(h.cols,M));for(let m=b;m<=_;m++){const y=h.rows[m];m!==0&&i.rowBreaks.push({row:y,y:e.offsetOf(y),x0:u,x1:f,manual:a(r,y)})}for(let m=O;m<=P;m++){const y=h.cols[m];m!==0&&i.colBreaks.push({col:y,x:o.offsetOf(y),y0:g,y1:p,manual:a(l,y)})}for(let m=b;m<=_;m++)for(let y=O;y<=P;y++){const I=h.rows[m],k=h.rows[m+1]-1,v=h.cols[y],N=h.cols[y+1]-1,T=o.offsetOf(v),E=e.offsetOf(I);i.pages.push({index:h.first+this._seq(h,m,y),r0:I,r1:k,c0:v,c1:N,x:T,y:E,w:o.offsetOf(N+1)-T,h:e.offsetOf(k+1)-E})}}return i}pageLayoutView({gap:t=18}={}){const{paper:s}=this,n=s.width,e=s.height,o=n+t,i=e+t,r=[];let l=0,a=0;for(const f of this.layouts)r.push({layout:f,y:l}),l+=f.nRows*i,a=Math.max(a,f.nCols*o-t);const h=Math.max(0,l-t);return{width:a,height:h,rectOf:f=>{const g=this.page(f);if(!g)return null;const p=r[R(this._firsts,f+1)-1];return{index:f,x:g.colBand*o,y:p.y+g.rowBand*i,w:n,h:e}},visible:(f,g,p,x)=>{const C=[];for(const{layout:d,y:M}of r){const b=Math.max(0,Math.floor((g-M)/i)),_=Math.min(d.nRows-1,Math.floor((x-M)/i)),O=Math.max(0,Math.floor(f/o)),P=Math.min(d.nCols-1,Math.floor(p/o));for(let m=b;m<=_;m++)for(let y=O;y<=P;y++)C.push({index:d.first+this._seq(d,m,y),x:y*o,y:M+m*i,w:n,h:e})}return C}}}}function j(c){const t=Math.round(Number(c)||100);return Math.min(400,Math.max(10,t))}function tt(c,t){const s=[];if(c.length===0)return t.maxRow>=0&&t.maxCol>=0&&s.push({r0:0,c0:0,r1:t.maxRow,c1:t.maxCol}),s;for(const n of c){let{r0:e,c0:o,r1:i,c1:r}=n;e===0&&i===X-1&&(i=Math.max(t.maxRow,0)),o===0&&r===S-1&&(r=Math.max(t.maxCol,0)),i>=e&&r>=o&&s.push({r0:e,c0:o,r1:i,c1:r})}return s}function lt(c,t={}){let s;Array.isArray(t.sheets)?s=t.sheets:t.sheets==="all"?s=c.sheets.map((i,r)=>i.hidden?-1:r).filter(i=>i>=0):s=[c.activeSheet];const n=[];let e=0,o=1;for(const i of s){const r=c.sheets[i],l=Z(c,r,{setup:t.setups?.get(r),areas:i===c.activeSheet?t.areas:void 0,ignorePrintArea:t.ignorePrintArea,objectExtent:t.objectExtents?.get(r),fallbackPaper:t.fallbackPaper});l.setup.useFirstPageNumber&&(o=l.setup.firstPageNumber),n.push({sheet:r,sheetIndex:i,pagination:l,first:e,firstNumber:o}),e+=l.pageCount,o+=l.pageCount}return new st(c,n,e)}class st{constructor(t,s,n){this.book=t,this.entries=s,this.pageCount=n,this._firsts=s.map(e=>e.first)}entryOf(t){let s=R(this._firsts,t+1)-1;for(;s>0&&this.entries[s].pagination.pageCount===0;)s--;return this.entries[Math.max(0,s)]}at(t){if(t<0||t>=this.pageCount)return null;const s=this.entryOf(t),n=t-s.first;return{index:t,sheet:s.sheet,sheetIndex:s.sheetIndex,pagination:s.pagination,page:s.pagination.page(n),sheetPage:n,pageNumber:s.firstNumber+n,totalPages:this.pageCount}}firstPageOf(t){const s=this.entries.find(n=>n.sheetIndex===t);return s&&s.pagination.pageCount>0?s.first:-1}}export{$ as Pagination,st as PrintJob,lt as createPrintJob,R as lowerBound,Z as paginate,V as printedExtent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{cbcEncryptRaw as l,importAesKey as p}from"../io/crypto/aes.js";import{concat as f,hashBytes as U}from"../io/crypto/hash.js";const H=127,x=new Uint8Array(16),c=e=>globalThis.crypto.getRandomValues(new Uint8Array(e)),O=/[\u00ad\u034f\u1806\u180b-\u180d\u200b-\u200d\u2060\ufe00-\ufe0f\ufeff]/g,_=/[\u00a0\u1680\u2000-\u200a\u202f\u205f\u3000]/g,E=e=>new TextEncoder().encode(String(e??"").replace(O,"").replace(_," ").normalize("NFKC")).subarray(0,H);async function F(e,t,s=new Uint8Array(0)){let n=U("SHA-256",e,t,s);for(let i=1;;i++){const u=f(e,n,s),h=new Uint8Array(u.length*64);for(let r=0;r<64;r++)h.set(u,r*u.length);const a=await l(await p(n.slice(0,16)),n.slice(16,32),h);let y=0;for(let r=0;r<16;r++)y+=a[r];if(n=U(["SHA-256","SHA-384","SHA-512"][y%3],a),i>=64&&a[a.length-1]<=i-32)return n.slice(0,32)}}const o=e=>[...e].map(t=>t.toString(16).padStart(2,"0")).join("");function B({print:e=!0,copy:t=!0,edit:s=!0}={}){let n=-4;return e||(n&=-2053),t||(n&=-17),s||(n&=-1321),n}async function P({openPassword:e="",permissionsPassword:t="",permissions:s={}}){const n=c(32),i=E(e),u=t?E(t):c(32),h=async(A,g)=>{const m=c(8),C=c(8),k=f(await F(A,m,g),m,C),$=await p(await F(A,C,g));return[k,await l($,x,n)]},[a,y]=await h(i,new Uint8Array(0)),[r,b]=await h(u,a),d=B(s),w=c(16);new DataView(w.buffer).setInt32(0,d,!0),w.set([255,255,255,255,84,97,100,98],4);const S=await p(n),v=await l(S,x,w);return{aes:S,dict:`<< /Filter /Standard /V 5 /R 6 /Length 256 /P ${d} /O <${o(r)}> /U <${o(a)}> /OE <${o(b)}> /UE <${o(y)}> /Perms <${o(v)}> /CF << /StdCF << /Type /CryptFilter /CFM /AESV3 /AuthEvent /DocOpen /Length 32 >> >> /StmF /StdCF /StrF /StdCF >>`}}async function R({aes:e},t){const s=c(16);return f(s,new Uint8Array(await globalThis.crypto.subtle.encrypt({name:"AES-CBC",iv:s},e,t)))}const D=async(e,t)=>`<${o(await R(e,t))}>`;class I{constructor({aes:t}){this.aes=t,this.iv=c(16),this.started=!1,this.rest=new Uint8Array(0)}_start(t){return this.started?t:(this.started=!0,f(this.first,t))}async push(t){this.started||(this.first=this.iv);const s=this.rest.length?f(this.rest,t):t,n=s.length-s.length%16;if(this.rest=s.slice(n),n===0)return this._start(new Uint8Array(0));const i=await l(this.aes,this.iv,s.subarray(0,n));return this.iv=i.slice(-16),this._start(i)}async end(){const t=16-this.rest.length%16,s=new Uint8Array(this.rest.length+t).fill(t);return s.set(this.rest),this.started||(this.first=this.iv),this._start(await l(this.aes,this.iv,s))}}export{I as StreamCipher,R as encryptBytes,D as encryptedString,P as newPdfEncryption,B as permissionBits};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const I=64,P=g=>{let e="FEFF";for(let o=0;o<g.length;o++)e+=g.charCodeAt(o).toString(16).padStart(4,"0");return`<${e}>`};class j{constructor(e){this.ops=e,this.items=[],this.open=null,e.push("/Artifact BMC")}_leaveArtifact(){const{ops:e}=this;e[e.length-1]==="/Artifact BMC"?e.pop():e.push("EMC")}begin(e){return this.open?!1:(this._leaveArtifact(),this.open={...e,mcid:this.items.length},this.ops.push(`/${e.tag} <</MCID ${this.open.mcid}>> BDC`),this.at=this.ops.length,!0)}end(){this.open&&(this.ops.length===this.at?this.ops.pop():(this.ops.push("EMC"),this.items.push(this.open)),this.open=null,this.ops.push("/Artifact BMC"))}close(){this.end(),this._leaveArtifact()}}class C{constructor(e,{lang:o=""}={}){this.writer=e,this.lang=o,this.rootId=e._alloc(),this.documentId=e._alloc(),this.sections=[],this.parents=[]}section(e){this.sections.push({id:this.writer._alloc(),title:e,kids:[]})}async page(e,o){const{writer:n}=this;this.sections.length===0&&this.section("");const h=this.sections.at(-1),d=new Array(o.items.length),s=new Map,p=[],$=new Set;for(const t of o.items){if(t.row===void 0){const f=n._alloc();d[t.mcid]=f,await n._packed(f,`<< /S /${t.tag} /P ${h.id} 0 R /Pg ${e} 0 R /K ${t.mcid}${t.alt===void 0?"":` /Alt ${P(t.alt)}`} >>`),p.push(f);continue}let a=s.get(t.row);a===void 0&&s.set(t.row,a=new Map);const l=a.get(t.col);l===void 0?a.set(t.col,{...t,mcids:[t.mcid]}):l.mcids.push(t.mcid),$.add(t.col)}const u=[...$].sort((t,a)=>t-a),m=new Map,w=[],_=s.size>0?n._alloc():0;for(const t of[...s.keys()].sort((a,l)=>a-l)){const a=n._alloc(),l=[],f=s.get(t);let R=-1;for(const r of u){const i=f.get(r);if(!i){if(r<=R||m.get(r)>=t)continue;const c=n._alloc();await n._packed(c,`<< /S /TD /P ${a} 0 R >>`),l.push(c);continue}if(i.cols>1&&(R=Math.max(R,r+i.cols-1)),i.rows>1)for(const c of u)c>=r&&c<r+i.cols&&m.set(c,t+i.rows-1);const k=n._alloc();for(const c of i.mcids)d[c]=k;const T=u.filter(c=>c>=r&&c<r+i.cols).length,A=i.rows>1?[...s.keys()].filter(c=>c>=t&&c<t+i.rows).length:1,M=[i.scope?`/Scope /${i.scope}`:"",A>1?`/RowSpan ${A}`:"",T>1?`/ColSpan ${T}`:""].filter(Boolean).join(" ");await n._packed(k,`<< /S /${i.tag} /P ${a} 0 R /Pg ${e} 0 R /K ${i.mcids.length===1?i.mcids[0]:`[${i.mcids.join(" ")}]`}${M?` /A << /O /Table ${M} >>`:""} >>`),l.push(k)}await n._packed(a,`<< /S /TR /P ${_} 0 R /K [${l.map(r=>`${r} 0 R`).join(" ")}] >>`),w.push(a)}w.length>0&&(await n._packed(_,`<< /S /Table /P ${h.id} 0 R /K [${w.map(t=>`${t} 0 R`).join(" ")}] >>`),h.kids.push(_)),h.kids.push(...p);const S=n._alloc();return await n._packed(S,`[${d.map(t=>t===void 0?"null":`${t} 0 R`).join(" ")}]`),this.parents.push(S),` /StructParents ${this.parents.length-1} /Tabs /S`}async finish(e){const{writer:o}=this,n=this.sections.filter(s=>s.kids.length>0);for(const s of n)await o._packed(s.id,`<< /S /Sect /P ${this.documentId} 0 R${s.title?` /T ${P(s.title)}`:""} /K [${s.kids.map(p=>`${p} 0 R`).join(" ")}] >>`);await o._packed(this.documentId,`<< /S /Document /P ${this.rootId} 0 R /K [${n.map(s=>`${s.id} 0 R`).join(" ")}] >>`);const h=[];for(let s=0;s<this.parents.length;s+=64){const p=this.parents.slice(s,s+64),$=o._alloc();await o._packed($,`<< /Limits [${s} ${s+p.length-1}] /Nums [${p.map((u,m)=>`${s+m} ${u} 0 R`).join(" ")}] >>`),h.push($)}const d=o._alloc();return await o._packed(d,`<< /Kids [${h.map(s=>`${s} 0 R`).join(" ")}] >>`),await o._packed(this.rootId,`<< /Type /StructTreeRoot /K ${this.documentId} 0 R /ParentTree ${d} 0 R /ParentTreeNextKey ${this.parents.length} >>`),` /MarkInfo << /Marked true >> /StructTreeRoot ${this.rootId} 0 R${this.lang?` /Lang ${await e(this.lang)}`:""}`}}export{j as PageMarks,C as Structure};
|
package/print/pdf.js
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
|
-
const W=new TextEncoder,M=65536,Y=9999999999,J=128,L=()=>{},j=[];for(let a=0;a<256;a++)j.push(a.toString(16).padStart(2,"0"));const F=a=>j[a>>8&255]+j[a&255],b=a=>String(Math.round(a*1e3)/1e3+0),A=a=>Array(10).fill(a),R={Helvetica:[278,278,355,556,556,889,667,191,333,333,389,584,278,333,278,278,...A(556),278,278,584,584,584,556,1015,667,667,722,722,667,611,778,722,278,500,667,556,833,722,778,667,778,722,667,611,722,667,944,667,667,611,278,278,278,469,556,333,556,556,500,556,556,278,556,556,222,222,500,222,833,556,556,556,556,333,500,278,556,500,722,500,500,500,334,260,334,584],"Helvetica-Bold":[278,333,474,556,556,889,722,238,333,333,389,584,278,333,278,278,...A(556),333,333,584,584,584,611,975,722,722,722,722,667,611,778,722,278,556,722,611,833,722,778,667,778,722,667,611,722,667,944,667,667,611,333,278,333,584,556,333,556,611,556,611,556,333,611,611,278,278,556,278,889,611,611,611,611,389,556,333,611,556,778,556,556,500,389,280,389,584],"Times-Roman":[250,333,408,500,500,833,778,180,333,333,500,564,250,333,250,278,...A(500),278,278,564,564,564,444,921,722,667,667,722,611,556,722,722,333,389,722,611,889,722,722,556,722,667,556,611,722,722,944,722,722,611,333,278,333,469,500,333,444,500,444,500,444,333,500,500,278,278,500,278,778,500,500,500,500,333,389,278,500,500,722,500,500,444,480,200,480,541],"Times-Bold":[250,333,555,500,500,1e3,833,278,333,333,500,570,250,333,250,278,...A(500),333,333,570,570,570,500,930,722,667,722,722,667,611,778,778,389,500,778,667,944,722,778,611,778,722,556,667,722,722,1e3,722,722,667,333,278,333,581,500,333,500,556,444,556,444,333,500,556,278,333,556,278,833,556,500,556,556,444,389,333,556,500,722,500,500,444,394,220,394,520],"Times-Italic":[250,333,420,500,500,833,778,214,333,333,500,675,250,333,250,278,...A(500),333,333,675,675,675,500,920,611,611,667,722,611,611,722,722,333,444,667,556,833,667,722,611,722,611,500,556,722,611,833,611,556,556,389,278,389,422,500,333,500,500,444,500,444,278,500,500,278,278,444,278,722,500,500,500,500,389,389,278,500,444,667,444,444,389,400,275,400,541],"Times-BoldItalic":[250,389,555,500,500,833,778,278,333,333,500,570,250,333,250,278,...A(500),333,333,570,570,570,500,832,667,667,667,722,667,667,722,778,389,500,667,611,889,722,722,611,722,667,556,611,722,667,889,667,611,611,333,278,333,570,500,333,500,500,444,500,444,333,500,556,278,278,500,278,778,556,500,500,500,389,389,278,556,444,667,500,444,389,348,220,348,570]};R["Helvetica-Oblique"]=R.Helvetica,R["Helvetica-BoldOblique"]=R["Helvetica-Bold"];const K=new Map(Object.entries({"€":[556,500],"–":[556,500],"—":[1e3,1e3],"…":[1e3,1e3],"•":[350,350],"‘":[222,333],"’":[222,333],"‚":[222,333],"“":[333,444],"”":[333,444],"„":[333,444],"†":[556,500],"‡":[556,500],"‰":[1e3,1e3],"‹":[333,333],"›":[333,333],ƒ:[556,500],"™":[1e3,980],"ˆ":[333,333],"˜":[333,333],"¡":[333,333],"¢":[556,500],"£":[556,500],"¤":[556,500],"¥":[556,500],"¦":[260,200],"§":[556,500],"¨":[333,333],"©":[737,760],ª:[370,276],"«":[556,500],"¬":[584,564],"®":[737,760],"¯":[333,333],"°":[400,400],"±":[584,564],"²":[333,300],"³":[333,300],"´":[333,333],µ:[556,500],"¶":[537,453],"·":[278,250],"¸":[333,333],"¹":[333,300],º:[365,310],"»":[556,500],"¼":[834,750],"½":[834,750],"¾":[834,750],"¿":[611,444],"×":[584,564],"÷":[584,564],Æ:[1e3,889],æ:[889,667],Œ:[1e3,889],œ:[944,722],Ø:[778,722],ø:[611,500],ß:[611,500],Ð:[722,722],ð:[556,500],Þ:[667,556],þ:[556,500]})),H="€\0‚ƒ„…†‡ˆ‰Š‹Œ\0Ž\0\0‘’“”•–—˜™š›œ\0žŸ",z=[["ą","aogonek"],["Ą","Aogonek"],["ć","cacute"],["Ć","Cacute"],["ę","eogonek"],["Ę","Eogonek"],["ł","lslash"],["Ł","Lslash"],["ń","nacute"],["Ń","Nacute"],["ś","sacute"],["Ś","Sacute"],["ź","zacute"],["Ź","Zacute"],["ż","zdotaccent"],["Ż","Zdotaccent"],["č","ccaron"],["Č","Ccaron"],["ě","ecaron"],["Ě","Ecaron"],["ř","rcaron"],["Ř","Rcaron"],["ů","uring"],["Ů","Uring"],["ő","ohungarumlaut"],["Ő","Ohungarumlaut"],["ű","uhungarumlaut"],["Ű","Uhungarumlaut"],["ň","ncaron"],["ď","dcaron"],["ť","tcaron"]],y=new Map;for(let a=32;a<127;a++)y.set(a,a);for(let a=161;a<=255;a++)y.set(a,a);for(let a=0;a<H.length;a++)H[a]!=="\0"&&y.set(H.codePointAt(a),128+a);z.forEach(([a],t)=>y.set(a.codePointAt(0),t+1));for(const a of[160,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288])y.set(a,32);for(const a of[8208,8209,173])y.set(a,45);y.set(8722,150),y.set(8213,151);const Z=/times|georgia|cambria|garamond|palatino|book antiqua|constantia|baskerville|bookman|century|minion|serif$/,Q=/sans|gothic/,tt=/courier|consolas|menlo|monaco|lucida console|lucida sans typewriter|mono/,et=/aptos narrow|calibri|carlito|arial narrow|corbel|candara/;function st(a,t,e){return tt.test(a)?`Courier${t||e?"-":""}${t?"Bold":""}${e?"Oblique":""}`:Z.test(a)&&!Q.test(a)?t?e?"Times-BoldItalic":"Times-Bold":e?"Times-Italic":"Times-Roman":`Helvetica${t||e?"-":""}${t?"Bold":""}${e?"Oblique":""}`}class it{constructor(t,e,s){this.name=t,this.resId=e,this.objectId=s,this.mono=t.startsWith("Courier"),this.serif=t.startsWith("Times"),this.table=R[t]??null,this.ascent=this.mono?.629:this.serif?.683:.718,this.descent=this.mono?.157:this.serif?.217:.207,this.widths=new Map}width(t){if(this.mono)return 600;if(t>=32&&t<127)return this.table[t-32];let e=this.widths.get(t);return e===void 0&&(e=this._extraWidth(t),this.widths.set(t,e)),e}_extraWidth(t){const e=String.fromCodePoint(t),s=K.get(e);if(s)return s[this.serif?1:0];if(e==="ł")return this.table[76];if(e==="Ł")return this.table[44];const i=y.get(t);if(i===32)return this.table[0];if(i===45)return this.table[13];const n=e.normalize("NFD").codePointAt(0);return n>=32&&n<127?this.table[n-32]:this.serif?500:556}}function N(a){const t=String.fromCodePoint(a).normalize("NFD").codePointAt(0);return y.has(t)?t:63}class nt{constructor(t,e={}){this.bytes=ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.tables=this._openFace(e.postscriptName);for(const r of["head","hhea","hmtx","maxp","cmap","loca","glyf"])if(!this.tables.has(r))throw new Error(`Font has no ${r} table, so it isn't TrueType`);const s=this.view,i=this.tables.get("head").offset,n=this.tables.get("hhea").offset;this.unitsPerEm=s.getUint16(i+18)||1e3,this.bbox=[s.getInt16(i+36),s.getInt16(i+38),s.getInt16(i+40),s.getInt16(i+42)];const o=s.getUint16(i+44);this.longLoca=s.getInt16(i+50)!==0,this.ascentUnits=s.getInt16(n+4),this.descentUnits=s.getInt16(n+6),this.numHMetrics=s.getUint16(n+34),this.numGlyphs=s.getUint16(this.tables.get("maxp").offset+4),this.italicAngle=this.tables.has("post")?s.getInt32(this.tables.get("post").offset+4)/65536:0,this.capHeightUnits=this.ascentUnits;const h=this.tables.get("OS/2");if(h){if((s.getUint16(h.offset+8)&15)===2)throw new Error("Font license forbids embedding");s.getUint16(h.offset)>=2&&h.length>=90&&(this.capHeightUnits=s.getInt16(h.offset+88)||this.ascentUnits)}const f=this._names();this.family=e.family??f.family??"Embedded",this.postscriptName=(f.postscript??this.family).replace(/[^A-Za-z0-9-]/g,""),this.bold=e.bold??(o&1)!==0,this.italic=e.italic??(o&2)!==0,this.scale=1e3/this.unitsPerEm,this.ascent=this.ascentUnits/this.unitsPerEm,this.descent=-this.descentUnits/this.unitsPerEm,this.lookup=this._cmap(),this.gids=new Map,this.order=[0],this.newIds=new Map([[0,0]]),this.unicode=[],this.resId=0,this.objectId=0}_openFace(t){const e=this.view,s=e.getUint32(0);if(s===1330926671)throw new Error("OpenType/CFF fonts are not supported");if(s===1953784678){const i=e.getUint32(8);let n=null;for(let o=0;o<i;o++){const h=this._directory(e.getUint32(12+o*4));if(n===null&&(n=h),t&&this._names(h).postscript===t)return h}if(n===null)throw new Error("Empty font collection");return n}if(s!==65536&&s!==1953658213)throw new Error("Not a TrueType font");return this._directory(0)}_directory(t){const e=this.view,s=e.getUint16(t+4),i=new Map;for(let n=0;n<s;n++){const o=t+12+n*16,h=String.fromCharCode(e.getUint8(o),e.getUint8(o+1),e.getUint8(o+2),e.getUint8(o+3));i.set(h,{offset:e.getUint32(o+8),length:e.getUint32(o+12)})}return i}_names(t=this.tables){const e={},s=t.get("name");if(!s)return e;const i=this.view,n=i.getUint16(s.offset+2),o=s.offset+i.getUint16(s.offset+4);for(let h=0;h<n;h++){const f=s.offset+6+h*12,r=i.getUint16(f),l=i.getUint16(f+6);if(l!==1&&l!==6)continue;const c=i.getUint16(f+8),u=o+i.getUint16(f+10);let d="";if(r===3||r===0)for(let m=0;m+1<c;m+=2)d+=String.fromCharCode(i.getUint16(u+m));else for(let m=0;m<c;m++)d+=String.fromCharCode(i.getUint8(u+m));const p=l===1?"family":"postscript";(e[p]===void 0||r===3)&&(e[p]=d)}return e}_cmap(){const t=this.view,e=this.tables.get("cmap").offset,s=t.getUint16(e+2);let i=null,n=-1;for(let p=0;p<s;p++){const m=e+4+p*8,w=t.getUint16(m),x=t.getUint16(m+2),U=e+t.getUint32(m+4),$=t.getUint16(U);if($!==4&&$!==12&&$!==6)continue;let I=-1;w===3&&x===10?I=4:w===0&&$===12?I=3:w===3&&x===1?I=2:w===0&&(I=1),I>n&&(n=I,i={at:U,format:$})}if(i===null)throw new Error("Font has no Unicode cmap");const{at:o,format:h}=i;if(h===12){const p=t.getUint32(o+12);return m=>{let w=0,x=p-1;for(;w<=x;){const U=w+x>>>1,$=o+16+U*12;if(m<t.getUint32($))x=U-1;else if(m>t.getUint32($+4))w=U+1;else return t.getUint32($+8)+m-t.getUint32($)}return 0}}if(h===6){const p=t.getUint16(o+6),m=t.getUint16(o+8);return w=>w>=p&&w<p+m?t.getUint16(o+10+(w-p)*2):0}const f=t.getUint16(o+6),r=o+14,l=r+f+2,c=l+f,u=c+f,d=f/2;return p=>{if(p>65535)return 0;let m=0,w=d-1;for(;m<w;){const g=m+w>>>1;t.getUint16(r+g*2)<p?m=g+1:w=g}const x=t.getUint16(l+m*2);if(p<x||p>t.getUint16(r+m*2))return 0;const U=t.getInt16(c+m*2),$=t.getUint16(u+m*2);if($===0)return p+U&65535;const I=t.getUint16(u+m*2+$+(p-x)*2);return I===0?0:I+U&65535}}gidOf(t){let e=this.gids.get(t);return e===void 0&&(e=this.lookup(t),e>=this.numGlyphs&&(e=0),this.gids.set(t,e)),e}_rawAdvance(t){const e=this.tables.get("hmtx").offset;return this.view.getUint16(e+Math.min(t,this.numHMetrics-1)*4)}_rawLsb(t){const e=this.tables.get("hmtx").offset;return t<this.numHMetrics?this.view.getInt16(e+t*4+2):this.view.getInt16(e+this.numHMetrics*4+(t-this.numHMetrics)*2)}width(t){return this._rawAdvance(this.gidOf(t))*this.scale}_newId(t){let e=this.newIds.get(t);return e===void 0&&(e=this.order.length,this.order.push(t),this.newIds.set(t,e)),e}use(t){const e=this._newId(this.gidOf(t));return this.unicode[e]===void 0&&(this.unicode[e]=t),e}_glyphRange(t){const e=this.tables.get("loca").offset,s=this.tables.get("glyf").offset,i=this.view,n=this.longLoca?i.getUint32(e+t*4):i.getUint16(e+t*2)*2,o=this.longLoca?i.getUint32(e+(t+1)*4):i.getUint16(e+(t+1)*2)*2;return[s+n,o-n]}_copyTable(t){const e=this.tables.get(t);return e?this.bytes.slice(e.offset,e.offset+e.length):null}subset(){const t=[];for(let g=0;g<this.order.length;g++){const[_,T]=this._glyphRange(this.order[g]);if(T<=0){t.push(null);continue}const S=this.bytes.slice(_,_+T),k=new DataView(S.buffer);if(k.getInt16(0)<0){let C=10;for(;;){const v=k.getUint16(C);if(k.setUint16(C+2,this._newId(k.getUint16(C+2))),C+=4+(v&1?4:2),v&8?C+=2:v&64?C+=4:v&128&&(C+=8),!(v&32))break}}t.push(S)}const e=this.order.length,s=new Uint8Array((e+1)*4),i=new DataView(s.buffer);let n=0;for(let g=0;g<e;g++)i.setUint32(g*4,n),t[g]&&(n+=t[g].length+3&-4);i.setUint32(e*4,n);const o=new Uint8Array(n);for(let g=0;g<e;g++)t[g]&&o.set(t[g],i.getUint32(g*4));const h=new Uint8Array(e*4),f=new DataView(h.buffer);for(let g=0;g<e;g++)f.setUint16(g*4,this._rawAdvance(this.order[g])),f.setInt16(g*4+2,this._rawLsb(this.order[g]));const r=this._copyTable("head"),l=new DataView(r.buffer);l.setUint32(8,0),l.setInt16(50,1);const c=this._copyTable("hhea");new DataView(c.buffer).setUint16(34,e);const u=this._copyTable("maxp");new DataView(u.buffer).setUint16(4,e);const d=[["glyf",o],["head",r],["hhea",c],["hmtx",h],["loca",s],["maxp",u]];for(const g of["cvt ","fpgm","prep"]){const _=this._copyTable(g);_&&d.push([g,_])}d.sort((g,_)=>g[0]<_[0]?-1:1);let p=12+d.length*16;for(const[,g]of d)p+=g.length+3&-4;const m=new Uint8Array(p),w=new DataView(m.buffer),x=d.length,U=31-Math.clz32(x);w.setUint32(0,65536),w.setUint16(4,x),w.setUint16(6,16<<U),w.setUint16(8,U),w.setUint16(10,x*16-(16<<U));let $=12+x*16,I=0;return d.forEach(([g,_],T)=>{const S=12+T*16;for(let k=0;k<4;k++)w.setUint8(S+k,g.charCodeAt(k));w.setUint32(S+4,q(_)),w.setUint32(S+8,$),w.setUint32(S+12,_.length),m.set(_,$),g==="head"&&(I=$),$+=_.length+3&-4}),w.setUint32(I+8,2981146554-q(m)>>>0),m}}function q(a){let t=0;const e=a.length;for(let s=0;s<e;s+=4){const i=(a[s]<<24|(a[s+1]??0)<<16|(a[s+2]??0)<<8|(a[s+3]??0))>>>0;t=t+i>>>0}return t}const ot={black:"000000",white:"ffffff",red:"ff0000",green:"008000",blue:"0000ff",yellow:"ffff00",orange:"ffa500",purple:"800080",gray:"808080",grey:"808080",silver:"c0c0c0",maroon:"800000",navy:"000080",teal:"008080",olive:"808000",lime:"00ff00",aqua:"00ffff",cyan:"00ffff",fuchsia:"ff00ff",magenta:"ff00ff",pink:"ffc0cb",brown:"a52a2a",lightgray:"d3d3d3",lightgrey:"d3d3d3",darkgray:"a9a9a9",darkgrey:"a9a9a9"},E=new Map;function O(a){const t=String(a);let e=E.get(t);return e!==void 0||(e=at(t.trim().toLowerCase()),E.size>4096&&E.clear(),E.set(t,e)),e}function at(a){if(a==="transparent")return{r:0,g:0,b:0,a:0,ops:"0 0 0"};let t=ot[a]??null;t===null&&a[0]==="#"&&(t=a.slice(1),(t.length===3||t.length===4)&&(t=[...t].map(h=>h+h).join("")));let e,s,i,n=1;if(t!==null){if(!/^[0-9a-f]{6}([0-9a-f]{2})?$/.test(t))return null;e=parseInt(t.slice(0,2),16),s=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16),t.length===8&&(n=parseInt(t.slice(6,8),16)/255)}else{const h=/^rgba?\(\s*([\d.]+%?)[\s,]+([\d.]+%?)[\s,]+([\d.]+%?)(?:[\s,/]+([\d.]+%?))?\s*\)$/.exec(a);if(!h)return null;const f=r=>r.endsWith("%")?parseFloat(r)*2.55:parseFloat(r);e=f(h[1]),s=f(h[2]),i=f(h[3]),h[4]!==void 0&&(n=h[4].endsWith("%")?parseFloat(h[4])/100:parseFloat(h[4]))}const o=h=>b(Math.min(255,Math.max(0,h))/255);return{r:e,g:s,b:i,a:n,ops:`${o(e)} ${o(s)} ${o(i)}`}}class D{constructor(){this.color=null}addColorStop(t,e){this.color===null&&(this.color=e)}}const ht=()=>({a:1,b:0,c:0,d:1,e:0,f:0,fill:O("#000000"),fillText:"#000000",stroke:O("#000000"),strokeText:"#000000",lineWidth:1,lineCap:"butt",lineJoin:"miter",miterLimit:10,dash:[],dashOffset:0,alpha:1,font:"10px sans-serif",spec:null,textAlign:"start",textBaseline:"alphabetic"}),rt=()=>({fill:null,stroke:null,width:1,dash:"[] 0",cap:0,join:0,miter:10,alpha:1});class ct{constructor(t,e,s){this.writer=t,this.canvas={width:e,height:s},this.pageWidth=e,this.pageHeight=s,this.ops=[],this.fonts=new Set,this.images=new Set,this.alphas=new Set,this.links=[],this.s=ht(),this.stack=[],this.emitted=rt(),this.emittedStack=[],this.path=[],this.cx=0,this.cy=0,this.imageSmoothingEnabled=!0,this.globalCompositeOperation="source-over",this.shadowBlur=0,this.shadowColor="transparent",this.shadowOffsetX=0,this.shadowOffsetY=0,this.fontKerning="auto",this.direction="ltr"}save(){this.stack.push({...this.s}),this.emittedStack.push({...this.emitted}),this.ops.push("q")}restore(){this.stack.length!==0&&(this.s=this.stack.pop(),this.emitted=this.emittedStack.pop(),this.ops.push("Q"))}get fillStyle(){return this.s.fillText}set fillStyle(t){const e=t instanceof D?t.color??"#000000":t,s=O(e);s!==null&&(this.s.fill=s,this.s.fillText=e)}get strokeStyle(){return this.s.strokeText}set strokeStyle(t){const e=t instanceof D?t.color??"#000000":t,s=O(e);s!==null&&(this.s.stroke=s,this.s.strokeText=e)}get lineWidth(){return this.s.lineWidth}set lineWidth(t){t>0&&(this.s.lineWidth=t)}get lineCap(){return this.s.lineCap}set lineCap(t){this.s.lineCap=t}get lineJoin(){return this.s.lineJoin}set lineJoin(t){this.s.lineJoin=t}get miterLimit(){return this.s.miterLimit}set miterLimit(t){this.s.miterLimit=t}get lineDashOffset(){return this.s.dashOffset}set lineDashOffset(t){this.s.dashOffset=t}get globalAlpha(){return this.s.alpha}set globalAlpha(t){t>=0&&t<=1&&(this.s.alpha=t)}get textAlign(){return this.s.textAlign}set textAlign(t){this.s.textAlign=t}get textBaseline(){return this.s.textBaseline}set textBaseline(t){this.s.textBaseline=t}get font(){return this.s.font}set font(t){this.s.font=t,this.s.spec=null}setLineDash(t){this.s.dash=t.slice()}getLineDash(){return this.s.dash.slice()}translate(t,e){const s=this.s;s.e+=s.a*t+s.c*e,s.f+=s.b*t+s.d*e}scale(t,e){const s=this.s;s.a*=t,s.b*=t,s.c*=e,s.d*=e}rotate(t){const e=Math.cos(t),s=Math.sin(t);this.transform(e,s,-s,e,0,0)}transform(t,e,s,i,n,o){const h=this.s,{a:f,b:r,c:l,d:c,e:u,f:d}=h;h.a=f*t+l*e,h.b=r*t+c*e,h.c=f*s+l*i,h.d=r*s+c*i,h.e=f*n+l*o+u,h.f=r*n+c*o+d}setTransform(t,e,s,i,n,o){const h=this.s;typeof t=="object"&&t!==null&&({a:t,b:e,c:s,d:i,e:n,f:o}=t),h.a=t,h.b=e,h.c=s,h.d=i,h.e=n,h.f=o}resetTransform(){this.setTransform(1,0,0,1,0,0)}getTransform(){const{a:t,b:e,c:s,d:i,e:n,f:o}=this.s;return{a:t,b:e,c:s,d:i,e:n,f:o}}_X(t,e){const s=this.s;return s.a*t+s.c*e+s.e}_Y(t,e){const s=this.s;return this.pageHeight-(s.b*t+s.d*e+s.f)}_pt(t,e){return`${b(this._X(t,e))} ${b(this._Y(t,e))}`}link(t,e,s,i,n){const o=[this._X(t,e),this._X(t+s,e+i)],h=[this._Y(t,e),this._Y(t+s,e+i)];this.links.push({...n,rect:[Math.min(...o),Math.min(...h),Math.max(...o),Math.max(...h)].map(b).join(" ")})}beginPath(){this.path=[]}moveTo(t,e){this.path.push(`${this._pt(t,e)} m`),this.cx=t,this.cy=e}lineTo(t,e){this.path.push(`${this._pt(t,e)} ${this.path.length===0?"m":"l"}`),this.cx=t,this.cy=e}closePath(){this.path.length>0&&this.path.push("h")}bezierCurveTo(t,e,s,i,n,o){this.path.length===0&&this.moveTo(t,e),this.path.push(`${this._pt(t,e)} ${this._pt(s,i)} ${this._pt(n,o)} c`),this.cx=n,this.cy=o}quadraticCurveTo(t,e,s,i){this.path.length===0&&this.moveTo(t,e);const{cx:n,cy:o}=this;this.bezierCurveTo(n+2/3*(t-n),o+2/3*(e-o),s+2/3*(t-s),i+2/3*(e-i),s,i)}rect(t,e,s,i){const n=this.s;n.b===0&&n.c===0?this.path.push(`${this._pt(t,e)} ${b(n.a*s)} ${b(-n.d*i)} re`):this.path.push(`${this._pt(t,e)} m ${this._pt(t+s,e)} l ${this._pt(t+s,e+i)} l ${this._pt(t,e+i)} l h`),this.cx=t,this.cy=e}roundRect(t,e,s,i,n=0){const o=Math.min(Math.abs(Array.isArray(n)?Number(n[0])||0:Number(n)||0),Math.abs(s)/2,Math.abs(i)/2);if(o===0){this.rect(t,e,s,i);return}this.moveTo(t+o,e),this.lineTo(t+s-o,e),this.quadraticCurveTo(t+s,e,t+s,e+o),this.lineTo(t+s,e+i-o),this.quadraticCurveTo(t+s,e+i,t+s-o,e+i),this.lineTo(t+o,e+i),this.quadraticCurveTo(t,e+i,t,e+i-o),this.lineTo(t,e+o),this.quadraticCurveTo(t,e,t+o,e),this.closePath()}arc(t,e,s,i,n,o=!1){this.ellipse(t,e,s,s,0,i,n,o)}ellipse(t,e,s,i,n,o,h,f=!1){let r=h-o;const l=Math.PI*2;!f&&r<0&&(r=r%l+l),f&&r>0&&(r=r%l-l),Math.abs(h-o)>=l&&(r=f?-l:l);const c=Math.cos(n),u=Math.sin(n),d=g=>{const _=s*Math.cos(g),T=i*Math.sin(g);return[t+_*c-T*u,e+_*u+T*c]},p=g=>{const _=-s*Math.sin(g),T=i*Math.cos(g);return[_*c-T*u,_*u+T*c]},m=Math.max(1,Math.ceil(Math.abs(r)/(Math.PI/2))),w=r/m,x=4/3*Math.tan(w/4),[U,$]=d(o);this.path.length===0?this.moveTo(U,$):this.lineTo(U,$);let I=o;for(let g=0;g<m;g++){const _=I+w,[T,S]=d(I),[k,C]=d(_),[v,V]=p(I),[G,X]=p(_);this.bezierCurveTo(T+x*v,S+x*V,k-x*G,C-x*X,k,C),I=_}}_applyAlpha(t){const e=Math.round(this.s.alpha*t*100);e!==Math.round(this.emitted.alpha*100)&&(this.emitted.alpha=e/100,this.alphas.add(e),this.ops.push(`/A${e} gs`))}_applyFill(){const t=this.s.fill;this._applyAlpha(t.a),this.emitted.fill!==t.ops&&(this.emitted.fill=t.ops,this.ops.push(`${t.ops} rg`))}_applyStroke(){const{s:t,emitted:e,ops:s}=this;this._applyAlpha(t.stroke.a),e.stroke!==t.stroke.ops&&(e.stroke=t.stroke.ops,s.push(`${t.stroke.ops} RG`));const i=Math.sqrt(Math.abs(t.a*t.d-t.b*t.c))||1,n=t.lineWidth*i;e.width!==n&&(e.width=n,s.push(`${b(n)} w`));const o=`[${t.dash.map(r=>b(r*i)).join(" ")}] ${b(t.dashOffset*i)}`;e.dash!==o&&(e.dash=o,s.push(`${o} d`));const h=t.lineCap==="round"?1:t.lineCap==="square"?2:0;e.cap!==h&&(e.cap=h,s.push(`${h} J`));const f=t.lineJoin==="round"?1:t.lineJoin==="bevel"?2:0;e.join!==f&&(e.join=f,s.push(`${f} j`)),e.miter!==t.miterLimit&&(e.miter=t.miterLimit,s.push(`${b(t.miterLimit)} M`))}fill(t){this.path.length!==0&&(this._applyFill(),this.ops.push(`${this.path.join(" ")} ${t==="evenodd"?"f*":"f"}`))}stroke(){this.path.length!==0&&(this._applyStroke(),this.ops.push(`${this.path.join(" ")} S`))}clip(t){this.ops.push(`${this.path.length?`${this.path.join(" ")} `:"0 0 0 0 re "}${t==="evenodd"?"W*":"W"} n`)}fillRect(t,e,s,i){this._applyFill();const n=this.s;n.b===0&&n.c===0?this.ops.push(`${this._pt(t,e)} ${b(n.a*s)} ${b(-n.d*i)} re f`):this.ops.push(`${this._pt(t,e)} m ${this._pt(t+s,e)} l ${this._pt(t+s,e+i)} l ${this._pt(t,e+i)} l h f`)}strokeRect(t,e,s,i){const n=this.path;this.path=[],this.rect(t,e,s,i),this.stroke(),this.path=n}clearRect(t,e,s,i){this.ops.push("q 1 1 1 rg");const n=this.s;n.b===0&&n.c===0?this.ops.push(`${this._pt(t,e)} ${b(n.a*s)} ${b(-n.d*i)} re f`):this.ops.push(`${this._pt(t,e)} m ${this._pt(t+s,e)} l ${this._pt(t+s,e+i)} l ${this._pt(t,e+i)} l h f`),this.ops.push("Q")}createLinearGradient(){return new D}createRadialGradient(){return new D}createConicGradient(){return new D}createPattern(){return null}_spec(){const t=this.s;return t.spec===null&&(t.spec=this.writer._fontSpec(t.font)),t.spec}measureText(t){const e=this._spec(),s=this.writer._measure(String(t),e),i=e.size*e.ascent,n=e.size*e.descent;return{width:s,actualBoundingBoxLeft:0,actualBoundingBoxRight:s,actualBoundingBoxAscent:i,actualBoundingBoxDescent:n,fontBoundingBoxAscent:i,fontBoundingBoxDescent:n}}fillText(t,e,s){this._text(String(t),e,s,!1)}strokeText(t,e,s){this._text(String(t),e,s,!0)}_text(t,e,s,i){if(t==="")return;const n=this._spec(),{writer:o,s:h}=this,f=o._runs(t,n);let r=0;for(const d of f)r+=d.width;const l=h.textAlign;switch(l==="center"?e-=r/2:(l==="right"||l==="end")&&(e-=r),h.textBaseline){case"top":s+=n.size*n.ascent;break;case"hanging":s+=n.size*n.ascent*.8;break;case"middle":s+=n.size*(n.ascent-n.descent)/2;break;case"bottom":case"ideographic":s-=n.size*n.descent;break;default:}i?this._applyStroke():this._applyFill();const c=b(n.size);let u=e;for(const d of f){this.fonts.add(d.font);const p=d.hScale,m=`${b(h.a*p)} ${b(-h.b*p)} ${b(-h.c)} ${b(h.d)} ${b(this._X(u,s))} ${b(this._Y(u,s))}`;this.ops.push(`BT${i?" 1 Tr":""} /F${d.font.resId} ${c} Tf ${m} Tm <${d.hex}> Tj${i?" 0 Tr":""} ET`),u+=d.width}}drawImage(t,...e){const s=this.writer._image(t);if(s===null)return;this.images.add(s);let i=0,n=0,o=s.width,h=s.height,f,r,l,c;if(e.length>=8?[i,n,o,h,f,r,l,c]=e:e.length>=4?[f,r,l,c]=e:([f,r]=e,l=s.width,c=s.height),this._applyAlpha(1),this.ops.push("q"),e.length>=8){const $=this.path;this.path=[],this.rect(f,r,l,c),this.ops.push(`${this.path.join(" ")} W n`),this.path=$;const I=l/o,g=c/h;f-=i*I,r-=n*g,l=s.width*I,c=s.height*g}const u=this.s,d=u.a*l,p=-u.b*l,m=-u.c*c,w=u.d*c,x=this._X(f,r+c),U=this._Y(f,r+c);this.ops.push(`${b(d)} ${b(p)} ${b(m)} ${b(w)} ${b(x)} ${b(U)} cm /Im${s.resId} Do Q`)}}function lt(a){const t=(e,s=2)=>String(e).padStart(s,"0");return`D:${t(a.getUTCFullYear(),4)}${t(a.getUTCMonth()+1)}${t(a.getUTCDate())}${t(a.getUTCHours())}${t(a.getUTCMinutes())}${t(a.getUTCSeconds())}Z`}function B(a){let t="FEFF";for(let e=0;e<a.length;e++)t+=F(a.charCodeAt(e));return`<${t}>`}function ft(a){return`(${[...a].map(e=>/[!-~]/.test(e)?e:encodeURIComponent(e.isWellFormed?.()===!1?"�":e)).join("").replace(/[\\()]/g,"\\$&")})`}function dt(a){let t=2;for(;t+9<a.length;){if(a[t]!==255){t++;continue}const e=a[t+1];if(e>=192&&e<=207&&e!==196&&e!==200&&e!==204)return{height:a[t+5]<<8|a[t+6],width:a[t+7]<<8|a[t+8],components:a[t+9]};t+=2+(a[t+2]<<8|a[t+3])}return null}class bt{constructor(t,e={}){this.sink=t,this.options=e,this.compress=e.compress!==!1&&typeof CompressionStream<"u",this.offset=0,this.buffer=new Uint8Array(M),this.pos=0,this.xref=new Float64Array(1024),this.nextId=1,this.started=!1,this.finished=!1,this.page=null,this.pageCount=0,this.pageIds=[],this.dests=new Map,this.bookmarks=[],this.levels=[],this.faces=[],this.stdFonts=new Map,this.encodingId=0,this.nextFontRes=1,this.nextImageRes=1,this.imageIds=new WeakMap,this.pendingImages=[],this.specs=new Map,this.missing=new Set,this.fontWarnings=[];for(const s of e.fonts??[])this.registerFont(s)}registerFont(t){try{const e=new nt(t.bytes,t);return e.familyKey=e.family.toLowerCase(),this.faces.push(e),this.specs.clear(),!0}catch(e){return this.fontWarnings.push(`${t.family??"font"}: ${e.message}`),!1}}async _raw(t){const e=t.length;if(this.offset+=e,e>=M/2){await this._flush(),await this.sink.write(t);return}this.pos+e>M&&await this._flush(),this.buffer.set(t,this.pos),this.pos+=e}async _flush(){if(this.pos===0)return;const t=this.buffer.slice(0,this.pos);this.pos=0,await this.sink.write(t)}_w(t){return this._raw(W.encode(t))}_alloc(){const t=this.nextId++;if(t>=this.xref.length){const e=new Float64Array(this.xref.length*2);e.set(this.xref),this.xref=e}return t}async _obj(t,e){this.xref[t]=this.offset,await this._w(`${t} 0 obj
|
|
1
|
+
import{encryptedString as J,newPdfEncryption as Z,StreamCipher as Q}from"./pdf-crypt.js";import{PageMarks as tt,Structure as et}from"./pdf-tags.js";const M=new TextEncoder,j=65536,st=9999999999,it=128,B=200,L=9,N=16384,H=()=>{},v=[];for(let o=0;o<256;o++)v.push(o.toString(16).padStart(2,"0"));const R=o=>v[o>>8&255]+v[o&255],b=o=>String(Math.round(o*1e3)/1e3+0),A=o=>Array(10).fill(o),D={Helvetica:[278,278,355,556,556,889,667,191,333,333,389,584,278,333,278,278,...A(556),278,278,584,584,584,556,1015,667,667,722,722,667,611,778,722,278,500,667,556,833,722,778,667,778,722,667,611,722,667,944,667,667,611,278,278,278,469,556,333,556,556,500,556,556,278,556,556,222,222,500,222,833,556,556,556,556,333,500,278,556,500,722,500,500,500,334,260,334,584],"Helvetica-Bold":[278,333,474,556,556,889,722,238,333,333,389,584,278,333,278,278,...A(556),333,333,584,584,584,611,975,722,722,722,722,667,611,778,722,278,556,722,611,833,722,778,667,778,722,667,611,722,667,944,667,667,611,333,278,333,584,556,333,556,611,556,611,556,333,611,611,278,278,556,278,889,611,611,611,611,389,556,333,611,556,778,556,556,500,389,280,389,584],"Times-Roman":[250,333,408,500,500,833,778,180,333,333,500,564,250,333,250,278,...A(500),278,278,564,564,564,444,921,722,667,667,722,611,556,722,722,333,389,722,611,889,722,722,556,722,667,556,611,722,722,944,722,722,611,333,278,333,469,500,333,444,500,444,500,444,333,500,500,278,278,500,278,778,500,500,500,500,333,389,278,500,500,722,500,500,444,480,200,480,541],"Times-Bold":[250,333,555,500,500,1e3,833,278,333,333,500,570,250,333,250,278,...A(500),333,333,570,570,570,500,930,722,667,722,722,667,611,778,778,389,500,778,667,944,722,778,611,778,722,556,667,722,722,1e3,722,722,667,333,278,333,581,500,333,500,556,444,556,444,333,500,556,278,333,556,278,833,556,500,556,556,444,389,333,556,500,722,500,500,444,394,220,394,520],"Times-Italic":[250,333,420,500,500,833,778,214,333,333,500,675,250,333,250,278,...A(500),333,333,675,675,675,500,920,611,611,667,722,611,611,722,722,333,444,667,556,833,667,722,611,722,611,500,556,722,611,833,611,556,556,389,278,389,422,500,333,500,500,444,500,444,278,500,500,278,278,444,278,722,500,500,500,500,389,389,278,500,444,667,444,444,389,400,275,400,541],"Times-BoldItalic":[250,389,555,500,500,833,778,278,333,333,500,570,250,333,250,278,...A(500),333,333,570,570,570,500,832,667,667,667,722,667,667,722,778,389,500,667,611,889,722,722,611,722,667,556,611,722,667,889,667,611,611,333,278,333,570,500,333,500,500,444,500,444,333,500,556,278,278,500,278,778,556,500,500,500,389,389,278,556,444,667,500,444,389,348,220,348,570]};D["Helvetica-Oblique"]=D.Helvetica,D["Helvetica-BoldOblique"]=D["Helvetica-Bold"];const nt=new Map(Object.entries({"€":[556,500],"–":[556,500],"—":[1e3,1e3],"…":[1e3,1e3],"•":[350,350],"‘":[222,333],"’":[222,333],"‚":[222,333],"“":[333,444],"”":[333,444],"„":[333,444],"†":[556,500],"‡":[556,500],"‰":[1e3,1e3],"‹":[333,333],"›":[333,333],ƒ:[556,500],"™":[1e3,980],"ˆ":[333,333],"˜":[333,333],"¡":[333,333],"¢":[556,500],"£":[556,500],"¤":[556,500],"¥":[556,500],"¦":[260,200],"§":[556,500],"¨":[333,333],"©":[737,760],ª:[370,276],"«":[556,500],"¬":[584,564],"®":[737,760],"¯":[333,333],"°":[400,400],"±":[584,564],"²":[333,300],"³":[333,300],"´":[333,333],µ:[556,500],"¶":[537,453],"·":[278,250],"¸":[333,333],"¹":[333,300],º:[365,310],"»":[556,500],"¼":[834,750],"½":[834,750],"¾":[834,750],"¿":[611,444],"×":[584,564],"÷":[584,564],Æ:[1e3,889],æ:[889,667],Œ:[1e3,889],œ:[944,722],Ø:[778,722],ø:[611,500],ß:[611,500],Ð:[722,722],ð:[556,500],Þ:[667,556],þ:[556,500]})),z="€\0‚ƒ„…†‡ˆ‰Š‹Œ\0Ž\0\0‘’“”•–—˜™š›œ\0žŸ",q=[["ą","aogonek"],["Ą","Aogonek"],["ć","cacute"],["Ć","Cacute"],["ę","eogonek"],["Ę","Eogonek"],["ł","lslash"],["Ł","Lslash"],["ń","nacute"],["Ń","Nacute"],["ś","sacute"],["Ś","Sacute"],["ź","zacute"],["Ź","Zacute"],["ż","zdotaccent"],["Ż","Zdotaccent"],["č","ccaron"],["Č","Ccaron"],["ě","ecaron"],["Ě","Ecaron"],["ř","rcaron"],["Ř","Rcaron"],["ů","uring"],["Ů","Uring"],["ő","ohungarumlaut"],["Ő","Ohungarumlaut"],["ű","uhungarumlaut"],["Ű","Uhungarumlaut"],["ň","ncaron"],["ď","dcaron"],["ť","tcaron"]],U=new Map;for(let o=32;o<127;o++)U.set(o,o);for(let o=161;o<=255;o++)U.set(o,o);for(let o=0;o<z.length;o++)z[o]!=="\0"&&U.set(z.codePointAt(o),128+o);q.forEach(([o],t)=>U.set(o.codePointAt(0),t+1));for(const o of[160,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288])U.set(o,32);for(const o of[8208,8209,173])U.set(o,45);U.set(8722,150),U.set(8213,151);const at=/times|georgia|cambria|garamond|palatino|book antiqua|constantia|baskerville|bookman|century|minion|serif$/,ot=/sans|gothic/,rt=/courier|consolas|menlo|monaco|lucida console|lucida sans typewriter|mono/,ht=/aptos narrow|calibri|carlito|arial narrow|corbel|candara/;function ct(o,t,e){return rt.test(o)?`Courier${t||e?"-":""}${t?"Bold":""}${e?"Oblique":""}`:at.test(o)&&!ot.test(o)?t?e?"Times-BoldItalic":"Times-Bold":e?"Times-Italic":"Times-Roman":`Helvetica${t||e?"-":""}${t?"Bold":""}${e?"Oblique":""}`}class lt{constructor(t,e,s){this.name=t,this.resId=e,this.objectId=s,this.mono=t.startsWith("Courier"),this.serif=t.startsWith("Times"),this.table=D[t]??null,this.ascent=this.mono?.629:this.serif?.683:.718,this.descent=this.mono?.157:this.serif?.217:.207,this.widths=new Map}width(t){if(this.mono)return 600;if(t>=32&&t<127)return this.table[t-32];let e=this.widths.get(t);return e===void 0&&(e=this._extraWidth(t),this.widths.set(t,e)),e}_extraWidth(t){const e=String.fromCodePoint(t),s=nt.get(e);if(s)return s[this.serif?1:0];if(e==="ł")return this.table[76];if(e==="Ł")return this.table[44];const i=U.get(t);if(i===32)return this.table[0];if(i===45)return this.table[13];const n=e.normalize("NFD").codePointAt(0);return n>=32&&n<127?this.table[n-32]:this.serif?500:556}}function V(o){const t=String.fromCodePoint(o).normalize("NFD").codePointAt(0);return U.has(t)?t:63}class ft{constructor(t,e={}){this.bytes=ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.tables=this._openFace(e.postscriptName);for(const h of["head","hhea","hmtx","maxp","cmap","loca","glyf"])if(!this.tables.has(h))throw new Error(`Font has no ${h} table, so it isn't TrueType`);const s=this.view,i=this.tables.get("head").offset,n=this.tables.get("hhea").offset;this.unitsPerEm=s.getUint16(i+18)||1e3,this.bbox=[s.getInt16(i+36),s.getInt16(i+38),s.getInt16(i+40),s.getInt16(i+42)];const a=s.getUint16(i+44);this.longLoca=s.getInt16(i+50)!==0,this.ascentUnits=s.getInt16(n+4),this.descentUnits=s.getInt16(n+6),this.numHMetrics=s.getUint16(n+34),this.numGlyphs=s.getUint16(this.tables.get("maxp").offset+4),this.italicAngle=this.tables.has("post")?s.getInt32(this.tables.get("post").offset+4)/65536:0,this.capHeightUnits=this.ascentUnits;const r=this.tables.get("OS/2");if(r){if((s.getUint16(r.offset+8)&15)===2)throw new Error("Font license forbids embedding");s.getUint16(r.offset)>=2&&r.length>=90&&(this.capHeightUnits=s.getInt16(r.offset+88)||this.ascentUnits)}const l=this._names();this.family=e.family??l.family??"Embedded",this.postscriptName=(l.postscript??this.family).replace(/[^A-Za-z0-9-]/g,""),this.bold=e.bold??(a&1)!==0,this.italic=e.italic??(a&2)!==0,this.scale=1e3/this.unitsPerEm,this.ascent=this.ascentUnits/this.unitsPerEm,this.descent=-this.descentUnits/this.unitsPerEm,this.lookup=this._cmap(),this.gids=new Map,this.order=[0],this.newIds=new Map([[0,0]]),this.unicode=[],this.resId=0,this.objectId=0}_openFace(t){const e=this.view,s=e.getUint32(0);if(s===1330926671)throw new Error("OpenType/CFF fonts are not supported");if(s===1953784678){const i=e.getUint32(8);let n=null;for(let a=0;a<i;a++){const r=this._directory(e.getUint32(12+a*4));if(n===null&&(n=r),t&&this._names(r).postscript===t)return r}if(n===null)throw new Error("Empty font collection");return n}if(s!==65536&&s!==1953658213)throw new Error("Not a TrueType font");return this._directory(0)}_directory(t){const e=this.view,s=e.getUint16(t+4),i=new Map;for(let n=0;n<s;n++){const a=t+12+n*16,r=String.fromCharCode(e.getUint8(a),e.getUint8(a+1),e.getUint8(a+2),e.getUint8(a+3));i.set(r,{offset:e.getUint32(a+8),length:e.getUint32(a+12)})}return i}_names(t=this.tables){const e={},s=t.get("name");if(!s)return e;const i=this.view,n=i.getUint16(s.offset+2),a=s.offset+i.getUint16(s.offset+4);for(let r=0;r<n;r++){const l=s.offset+6+r*12,h=i.getUint16(l),c=i.getUint16(l+6);if(c!==1&&c!==6)continue;const d=i.getUint16(l+8),f=a+i.getUint16(l+10);let u="";if(h===3||h===0)for(let m=0;m+1<d;m+=2)u+=String.fromCharCode(i.getUint16(f+m));else for(let m=0;m<d;m++)u+=String.fromCharCode(i.getUint8(f+m));const p=c===1?"family":"postscript";(e[p]===void 0||h===3)&&(e[p]=u)}return e}_cmap(){const t=this.view,e=this.tables.get("cmap").offset,s=t.getUint16(e+2);let i=null,n=-1;for(let p=0;p<s;p++){const m=e+4+p*8,g=t.getUint16(m),_=t.getUint16(m+2),I=e+t.getUint32(m+4),$=t.getUint16(I);if($!==4&&$!==12&&$!==6)continue;let y=-1;g===3&&_===10?y=4:g===0&&$===12?y=3:g===3&&_===1?y=2:g===0&&(y=1),y>n&&(n=y,i={at:I,format:$})}if(i===null)throw new Error("Font has no Unicode cmap");const{at:a,format:r}=i;if(r===12){const p=t.getUint32(a+12);return m=>{let g=0,_=p-1;for(;g<=_;){const I=g+_>>>1,$=a+16+I*12;if(m<t.getUint32($))_=I-1;else if(m>t.getUint32($+4))g=I+1;else return t.getUint32($+8)+m-t.getUint32($)}return 0}}if(r===6){const p=t.getUint16(a+6),m=t.getUint16(a+8);return g=>g>=p&&g<p+m?t.getUint16(a+10+(g-p)*2):0}const l=t.getUint16(a+6),h=a+14,c=h+l+2,d=c+l,f=d+l,u=l/2;return p=>{if(p>65535)return 0;let m=0,g=u-1;for(;m<g;){const w=m+g>>>1;t.getUint16(h+w*2)<p?m=w+1:g=w}const _=t.getUint16(c+m*2);if(p<_||p>t.getUint16(h+m*2))return 0;const I=t.getInt16(d+m*2),$=t.getUint16(f+m*2);if($===0)return p+I&65535;const y=t.getUint16(f+m*2+$+(p-_)*2);return y===0?0:y+I&65535}}gidOf(t){let e=this.gids.get(t);return e===void 0&&(e=this.lookup(t),e>=this.numGlyphs&&(e=0),this.gids.set(t,e)),e}_rawAdvance(t){const e=this.tables.get("hmtx").offset;return this.view.getUint16(e+Math.min(t,this.numHMetrics-1)*4)}_rawLsb(t){const e=this.tables.get("hmtx").offset;return t<this.numHMetrics?this.view.getInt16(e+t*4+2):this.view.getInt16(e+this.numHMetrics*4+(t-this.numHMetrics)*2)}width(t){return this._rawAdvance(this.gidOf(t))*this.scale}_newId(t){let e=this.newIds.get(t);return e===void 0&&(e=this.order.length,this.order.push(t),this.newIds.set(t,e)),e}use(t){const e=this._newId(this.gidOf(t));return this.unicode[e]===void 0&&(this.unicode[e]=t),e}_glyphRange(t){const e=this.tables.get("loca").offset,s=this.tables.get("glyf").offset,i=this.view,n=this.longLoca?i.getUint32(e+t*4):i.getUint16(e+t*2)*2,a=this.longLoca?i.getUint32(e+(t+1)*4):i.getUint16(e+(t+1)*2)*2;return[s+n,a-n]}_copyTable(t){const e=this.tables.get(t);return e?this.bytes.slice(e.offset,e.offset+e.length):null}subset(){const t=[];for(let w=0;w<this.order.length;w++){const[x,k]=this._glyphRange(this.order[w]);if(k<=0){t.push(null);continue}const S=this.bytes.slice(x,x+k),T=new DataView(S.buffer);if(T.getInt16(0)<0){let C=10;for(;;){const F=T.getUint16(C);if(T.setUint16(C+2,this._newId(T.getUint16(C+2))),C+=4+(F&1?4:2),F&8?C+=2:F&64?C+=4:F&128&&(C+=8),!(F&32))break}}t.push(S)}const e=this.order.length,s=new Uint8Array((e+1)*4),i=new DataView(s.buffer);let n=0;for(let w=0;w<e;w++)i.setUint32(w*4,n),t[w]&&(n+=t[w].length+3&-4);i.setUint32(e*4,n);const a=new Uint8Array(n);for(let w=0;w<e;w++)t[w]&&a.set(t[w],i.getUint32(w*4));const r=new Uint8Array(e*4),l=new DataView(r.buffer);for(let w=0;w<e;w++)l.setUint16(w*4,this._rawAdvance(this.order[w])),l.setInt16(w*4+2,this._rawLsb(this.order[w]));const h=this._copyTable("head"),c=new DataView(h.buffer);c.setUint32(8,0),c.setInt16(50,1);const d=this._copyTable("hhea");new DataView(d.buffer).setUint16(34,e);const f=this._copyTable("maxp");new DataView(f.buffer).setUint16(4,e);const u=[["glyf",a],["head",h],["hhea",d],["hmtx",r],["loca",s],["maxp",f]];for(const w of["cvt ","fpgm","prep"]){const x=this._copyTable(w);x&&u.push([w,x])}u.sort((w,x)=>w[0]<x[0]?-1:1);let p=12+u.length*16;for(const[,w]of u)p+=w.length+3&-4;const m=new Uint8Array(p),g=new DataView(m.buffer),_=u.length,I=31-Math.clz32(_);g.setUint32(0,65536),g.setUint16(4,_),g.setUint16(6,16<<I),g.setUint16(8,I),g.setUint16(10,_*16-(16<<I));let $=12+_*16,y=0;return u.forEach(([w,x],k)=>{const S=12+k*16;for(let T=0;T<4;T++)g.setUint8(S+T,w.charCodeAt(T));g.setUint32(S+4,X(x)),g.setUint32(S+8,$),g.setUint32(S+12,x.length),m.set(x,$),w==="head"&&(y=$),$+=x.length+3&-4}),g.setUint32(y+8,2981146554-X(m)>>>0),m}}function X(o){let t=0;const e=o.length;for(let s=0;s<e;s+=4){const i=(o[s]<<24|(o[s+1]??0)<<16|(o[s+2]??0)<<8|(o[s+3]??0))>>>0;t=t+i>>>0}return t}const dt={black:"000000",white:"ffffff",red:"ff0000",green:"008000",blue:"0000ff",yellow:"ffff00",orange:"ffa500",purple:"800080",gray:"808080",grey:"808080",silver:"c0c0c0",maroon:"800000",navy:"000080",teal:"008080",olive:"808000",lime:"00ff00",aqua:"00ffff",cyan:"00ffff",fuchsia:"ff00ff",magenta:"ff00ff",pink:"ffc0cb",brown:"a52a2a",lightgray:"d3d3d3",lightgrey:"d3d3d3",darkgray:"a9a9a9",darkgrey:"a9a9a9"},O=new Map;function W(o){const t=String(o);let e=O.get(t);return e!==void 0||(e=ut(t.trim().toLowerCase()),O.size>4096&&O.clear(),O.set(t,e)),e}function ut(o){if(o==="transparent")return{r:0,g:0,b:0,a:0,ops:"0 0 0"};let t=dt[o]??null;t===null&&o[0]==="#"&&(t=o.slice(1),(t.length===3||t.length===4)&&(t=[...t].map(r=>r+r).join("")));let e,s,i,n=1;if(t!==null){if(!/^[0-9a-f]{6}([0-9a-f]{2})?$/.test(t))return null;e=parseInt(t.slice(0,2),16),s=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16),t.length===8&&(n=parseInt(t.slice(6,8),16)/255)}else{const r=/^rgba?\(\s*([\d.]+%?)[\s,]+([\d.]+%?)[\s,]+([\d.]+%?)(?:[\s,/]+([\d.]+%?))?\s*\)$/.exec(o);if(!r)return null;const l=h=>h.endsWith("%")?parseFloat(h)*2.55:parseFloat(h);e=l(r[1]),s=l(r[2]),i=l(r[3]),r[4]!==void 0&&(n=r[4].endsWith("%")?parseFloat(r[4])/100:parseFloat(r[4]))}const a=r=>b(Math.min(255,Math.max(0,r))/255);return{r:e,g:s,b:i,a:n,ops:`${a(e)} ${a(s)} ${a(i)}`}}class E{constructor(){this.color=null}addColorStop(t,e){this.color===null&&(this.color=e)}}const pt=()=>({a:1,b:0,c:0,d:1,e:0,f:0,fill:W("#000000"),fillText:"#000000",stroke:W("#000000"),strokeText:"#000000",lineWidth:1,lineCap:"butt",lineJoin:"miter",miterLimit:10,dash:[],dashOffset:0,alpha:1,font:"10px sans-serif",spec:null,textAlign:"start",textBaseline:"alphabetic"}),gt=()=>({fill:null,stroke:null,width:1,dash:"[] 0",cap:0,join:0,miter:10,alpha:1});class mt{constructor(t,e,s){this.writer=t,this.canvas={width:e,height:s},this.pageWidth=e,this.pageHeight=s,this.ops=[],this.fonts=new Set,this.images=new Set,this.alphas=new Set,this.links=[],this.marks=null,this.s=pt(),this.stack=[],this.emitted=gt(),this.emittedStack=[],this.path=[],this.cx=0,this.cy=0,this.imageSmoothingEnabled=!0,this.globalCompositeOperation="source-over",this.shadowBlur=0,this.shadowColor="transparent",this.shadowOffsetX=0,this.shadowOffsetY=0,this.fontKerning="auto",this.direction="ltr"}save(){this.stack.push({...this.s}),this.emittedStack.push({...this.emitted}),this.ops.push("q")}restore(){this.stack.length!==0&&(this.s=this.stack.pop(),this.emitted=this.emittedStack.pop(),this.ops.push("Q"))}get fillStyle(){return this.s.fillText}set fillStyle(t){const e=t instanceof E?t.color??"#000000":t,s=W(e);s!==null&&(this.s.fill=s,this.s.fillText=e)}get strokeStyle(){return this.s.strokeText}set strokeStyle(t){const e=t instanceof E?t.color??"#000000":t,s=W(e);s!==null&&(this.s.stroke=s,this.s.strokeText=e)}get lineWidth(){return this.s.lineWidth}set lineWidth(t){t>0&&(this.s.lineWidth=t)}get lineCap(){return this.s.lineCap}set lineCap(t){this.s.lineCap=t}get lineJoin(){return this.s.lineJoin}set lineJoin(t){this.s.lineJoin=t}get miterLimit(){return this.s.miterLimit}set miterLimit(t){this.s.miterLimit=t}get lineDashOffset(){return this.s.dashOffset}set lineDashOffset(t){this.s.dashOffset=t}get globalAlpha(){return this.s.alpha}set globalAlpha(t){t>=0&&t<=1&&(this.s.alpha=t)}get textAlign(){return this.s.textAlign}set textAlign(t){this.s.textAlign=t}get textBaseline(){return this.s.textBaseline}set textBaseline(t){this.s.textBaseline=t}get font(){return this.s.font}set font(t){this.s.font=t,this.s.spec=null}setLineDash(t){this.s.dash=t.slice()}getLineDash(){return this.s.dash.slice()}translate(t,e){const s=this.s;s.e+=s.a*t+s.c*e,s.f+=s.b*t+s.d*e}scale(t,e){const s=this.s;s.a*=t,s.b*=t,s.c*=e,s.d*=e}rotate(t){const e=Math.cos(t),s=Math.sin(t);this.transform(e,s,-s,e,0,0)}transform(t,e,s,i,n,a){const r=this.s,{a:l,b:h,c,d,e:f,f:u}=r;r.a=l*t+c*e,r.b=h*t+d*e,r.c=l*s+c*i,r.d=h*s+d*i,r.e=l*n+c*a+f,r.f=h*n+d*a+u}setTransform(t,e,s,i,n,a){const r=this.s;typeof t=="object"&&t!==null&&({a:t,b:e,c:s,d:i,e:n,f:a}=t),r.a=t,r.b=e,r.c=s,r.d=i,r.e=n,r.f=a}resetTransform(){this.setTransform(1,0,0,1,0,0)}getTransform(){const{a:t,b:e,c:s,d:i,e:n,f:a}=this.s;return{a:t,b:e,c:s,d:i,e:n,f:a}}_X(t,e){const s=this.s;return s.a*t+s.c*e+s.e}_Y(t,e){const s=this.s;return this.pageHeight-(s.b*t+s.d*e+s.f)}_pt(t,e){return`${b(this._X(t,e))} ${b(this._Y(t,e))}`}link(t,e,s,i,n){const a=[this._X(t,e),this._X(t+s,e+i)],r=[this._Y(t,e),this._Y(t+s,e+i)];this.links.push({...n,rect:[Math.min(...a),Math.min(...r),Math.max(...a),Math.max(...r)].map(b).join(" ")})}beginCell(t,e,{scope:s=null,rows:i=1,cols:n=1}={}){this.marks?.begin({tag:s?"TH":"TD",row:t,col:e,scope:s,rows:i,cols:n})}beginFigure(t){return this.marks?.begin({tag:"Figure",alt:t})??!1}beginParagraph(){this.marks?.begin({tag:"P"})}endMark(){this.marks?.end()}beginPath(){this.path=[]}moveTo(t,e){this.path.push(`${this._pt(t,e)} m`),this.cx=t,this.cy=e}lineTo(t,e){this.path.push(`${this._pt(t,e)} ${this.path.length===0?"m":"l"}`),this.cx=t,this.cy=e}closePath(){this.path.length>0&&this.path.push("h")}bezierCurveTo(t,e,s,i,n,a){this.path.length===0&&this.moveTo(t,e),this.path.push(`${this._pt(t,e)} ${this._pt(s,i)} ${this._pt(n,a)} c`),this.cx=n,this.cy=a}quadraticCurveTo(t,e,s,i){this.path.length===0&&this.moveTo(t,e);const{cx:n,cy:a}=this;this.bezierCurveTo(n+2/3*(t-n),a+2/3*(e-a),s+2/3*(t-s),i+2/3*(e-i),s,i)}rect(t,e,s,i){const n=this.s;n.b===0&&n.c===0?this.path.push(`${this._pt(t,e)} ${b(n.a*s)} ${b(-n.d*i)} re`):this.path.push(`${this._pt(t,e)} m ${this._pt(t+s,e)} l ${this._pt(t+s,e+i)} l ${this._pt(t,e+i)} l h`),this.cx=t,this.cy=e}roundRect(t,e,s,i,n=0){const a=Math.min(Math.abs(Array.isArray(n)?Number(n[0])||0:Number(n)||0),Math.abs(s)/2,Math.abs(i)/2);if(a===0){this.rect(t,e,s,i);return}this.moveTo(t+a,e),this.lineTo(t+s-a,e),this.quadraticCurveTo(t+s,e,t+s,e+a),this.lineTo(t+s,e+i-a),this.quadraticCurveTo(t+s,e+i,t+s-a,e+i),this.lineTo(t+a,e+i),this.quadraticCurveTo(t,e+i,t,e+i-a),this.lineTo(t,e+a),this.quadraticCurveTo(t,e,t+a,e),this.closePath()}arc(t,e,s,i,n,a=!1){this.ellipse(t,e,s,s,0,i,n,a)}ellipse(t,e,s,i,n,a,r,l=!1){let h=r-a;const c=Math.PI*2;!l&&h<0&&(h=h%c+c),l&&h>0&&(h=h%c-c),Math.abs(r-a)>=c&&(h=l?-c:c);const d=Math.cos(n),f=Math.sin(n),u=w=>{const x=s*Math.cos(w),k=i*Math.sin(w);return[t+x*d-k*f,e+x*f+k*d]},p=w=>{const x=-s*Math.sin(w),k=i*Math.cos(w);return[x*d-k*f,x*f+k*d]},m=Math.max(1,Math.ceil(Math.abs(h)/(Math.PI/2))),g=h/m,_=4/3*Math.tan(g/4),[I,$]=u(a);this.path.length===0?this.moveTo(I,$):this.lineTo(I,$);let y=a;for(let w=0;w<m;w++){const x=y+g,[k,S]=u(y),[T,C]=u(x),[F,G]=p(y),[Y,K]=p(x);this.bezierCurveTo(k+_*F,S+_*G,T-_*Y,C-_*K,T,C),y=x}}_applyAlpha(t){const e=Math.round(this.s.alpha*t*100);e!==Math.round(this.emitted.alpha*100)&&(this.emitted.alpha=e/100,this.alphas.add(e),this.ops.push(`/A${e} gs`))}_applyFill(){const t=this.s.fill;this._applyAlpha(t.a),this.emitted.fill!==t.ops&&(this.emitted.fill=t.ops,this.ops.push(`${t.ops} rg`))}_applyStroke(){const{s:t,emitted:e,ops:s}=this;this._applyAlpha(t.stroke.a),e.stroke!==t.stroke.ops&&(e.stroke=t.stroke.ops,s.push(`${t.stroke.ops} RG`));const i=Math.sqrt(Math.abs(t.a*t.d-t.b*t.c))||1,n=t.lineWidth*i;e.width!==n&&(e.width=n,s.push(`${b(n)} w`));const a=`[${t.dash.map(h=>b(h*i)).join(" ")}] ${b(t.dashOffset*i)}`;e.dash!==a&&(e.dash=a,s.push(`${a} d`));const r=t.lineCap==="round"?1:t.lineCap==="square"?2:0;e.cap!==r&&(e.cap=r,s.push(`${r} J`));const l=t.lineJoin==="round"?1:t.lineJoin==="bevel"?2:0;e.join!==l&&(e.join=l,s.push(`${l} j`)),e.miter!==t.miterLimit&&(e.miter=t.miterLimit,s.push(`${b(t.miterLimit)} M`))}fill(t){this.path.length!==0&&(this._applyFill(),this.ops.push(`${this.path.join(" ")} ${t==="evenodd"?"f*":"f"}`))}stroke(){this.path.length!==0&&(this._applyStroke(),this.ops.push(`${this.path.join(" ")} S`))}clip(t){this.ops.push(`${this.path.length?`${this.path.join(" ")} `:"0 0 0 0 re "}${t==="evenodd"?"W*":"W"} n`)}fillRect(t,e,s,i){this._applyFill();const n=this.s;n.b===0&&n.c===0?this.ops.push(`${this._pt(t,e)} ${b(n.a*s)} ${b(-n.d*i)} re f`):this.ops.push(`${this._pt(t,e)} m ${this._pt(t+s,e)} l ${this._pt(t+s,e+i)} l ${this._pt(t,e+i)} l h f`)}strokeRect(t,e,s,i){const n=this.path;this.path=[],this.rect(t,e,s,i),this.stroke(),this.path=n}clearRect(t,e,s,i){this.ops.push("q 1 1 1 rg");const n=this.s;n.b===0&&n.c===0?this.ops.push(`${this._pt(t,e)} ${b(n.a*s)} ${b(-n.d*i)} re f`):this.ops.push(`${this._pt(t,e)} m ${this._pt(t+s,e)} l ${this._pt(t+s,e+i)} l ${this._pt(t,e+i)} l h f`),this.ops.push("Q")}createLinearGradient(){return new E}createRadialGradient(){return new E}createConicGradient(){return new E}createPattern(){return null}_spec(){const t=this.s;return t.spec===null&&(t.spec=this.writer._fontSpec(t.font)),t.spec}measureText(t){const e=this._spec(),s=this.writer._measure(String(t),e),i=e.size*e.ascent,n=e.size*e.descent;return{width:s,actualBoundingBoxLeft:0,actualBoundingBoxRight:s,actualBoundingBoxAscent:i,actualBoundingBoxDescent:n,fontBoundingBoxAscent:i,fontBoundingBoxDescent:n}}fillText(t,e,s){this._text(String(t),e,s,!1)}strokeText(t,e,s){this._text(String(t),e,s,!0)}_text(t,e,s,i){if(t==="")return;const n=this._spec(),{writer:a,s:r}=this,l=a._runs(t,n);let h=0;for(const u of l)h+=u.width;const c=r.textAlign;switch(c==="center"?e-=h/2:(c==="right"||c==="end")&&(e-=h),r.textBaseline){case"top":s+=n.size*n.ascent;break;case"hanging":s+=n.size*n.ascent*.8;break;case"middle":s+=n.size*(n.ascent-n.descent)/2;break;case"bottom":case"ideographic":s-=n.size*n.descent;break;default:}i?this._applyStroke():this._applyFill();const d=b(n.size);let f=e;for(const u of l){this.fonts.add(u.font);const p=u.hScale,m=`${b(r.a*p)} ${b(-r.b*p)} ${b(-r.c)} ${b(r.d)} ${b(this._X(f,s))} ${b(this._Y(f,s))}`;this.ops.push(`BT${i?" 1 Tr":""} /F${u.font.resId} ${d} Tf ${m} Tm <${u.hex}> Tj${i?" 0 Tr":""} ET`),f+=u.width}}drawImage(t,...e){const s=this.writer._image(t);if(s===null)return;this.images.add(s);let i=0,n=0,a=s.width,r=s.height,l,h,c,d;if(e.length>=8?[i,n,a,r,l,h,c,d]=e:e.length>=4?[l,h,c,d]=e:([l,h]=e,c=s.width,d=s.height),this._applyAlpha(1),this.ops.push("q"),e.length>=8){const $=this.path;this.path=[],this.rect(l,h,c,d),this.ops.push(`${this.path.join(" ")} W n`),this.path=$;const y=c/a,w=d/r;l-=i*y,h-=n*w,c=s.width*y,d=s.height*w}const f=this.s,u=f.a*c,p=-f.b*c,m=-f.c*d,g=f.d*d,_=this._X(l,h+d),I=this._Y(l,h+d);this.ops.push(`${b(u)} ${b(p)} ${b(m)} ${b(g)} ${b(_)} ${b(I)} cm /Im${s.resId} Do Q`)}}function wt(o){const t=(e,s=2)=>String(e).padStart(s,"0");return`D:${t(o.getUTCFullYear(),4)}${t(o.getUTCMonth()+1)}${t(o.getUTCDate())}${t(o.getUTCHours())}${t(o.getUTCMinutes())}${t(o.getUTCSeconds())}Z`}function bt(o){const t=new Uint8Array(2+o.length*2);t.set([254,255]);for(let e=0;e<o.length;e++)t[2+e*2]=o.charCodeAt(e)>>8,t[3+e*2]=o.charCodeAt(e)&255;return t}const _t=o=>[...o].map(t=>/[!-~]/.test(t)?t:encodeURIComponent(t.isWellFormed?.()===!1?"�":t)).join("");function $t(o){let t=2;for(;t+9<o.length;){if(o[t]!==255){t++;continue}const e=o[t+1];if(e>=192&&e<=207&&e!==196&&e!==200&&e!==204)return{height:o[t+5]<<8|o[t+6],width:o[t+7]<<8|o[t+8],components:o[t+9]};t+=2+(o[t+2]<<8|o[t+3])}return null}class St{constructor(t,e={}){this.sink=t,this.options=e,this.compress=e.compress!==!1&&typeof CompressionStream<"u",this.offset=0,this.buffer=new Uint8Array(j),this.pos=0,this.xref=new Float64Array(1024),this.nextId=1,this.started=!1,this.finished=!1,this.page=null,this.pageCount=0,this.pageIds=[],this.dests=new Map,this.bookmarks=[],this.levels=[],this.faces=[],this.stdFonts=new Map,this.encodingId=0,this.nextFontRes=1,this.nextImageRes=1,this.imageIds=new WeakMap,this.pendingImages=[],this.specs=new Map,this.packed=null,this.structure=e.tagged?new et(this,{lang:e.lang}):null,this.crypt=null,this.missing=new Set,this.fontWarnings=[];for(const s of e.fonts??[])this.registerFont(s)}registerFont(t){try{const e=new ft(t.bytes,t);return e.familyKey=e.family.toLowerCase(),this.faces.push(e),this.specs.clear(),!0}catch(e){return this.fontWarnings.push(`${t.family??"font"}: ${e.message}`),!1}}async _raw(t){const e=t.length;if(this.offset+=e,e>=j/2){await this._flush(),await this.sink.write(t);return}this.pos+e>j&&await this._flush(),this.buffer.set(t,this.pos),this.pos+=e}async _flush(){if(this.pos===0)return;const t=this.buffer.slice(0,this.pos);this.pos=0,await this.sink.write(t)}_w(t){return this._raw(M.encode(t))}_alloc(){const t=this.nextId++;if(t>=this.xref.length){const e=new Float64Array(this.xref.length*2);e.set(this.xref),this.xref=e}return t}async _obj(t,e){this.xref[t]=this.offset,await this._w(`${t} 0 obj
|
|
2
2
|
${e}
|
|
3
3
|
endobj
|
|
4
|
-
`)}
|
|
5
|
-
|
|
4
|
+
`)}_text(t){return this._string(bt(t))}_ascii(t){return this.crypt?this._string(M.encode(t)):`(${t.replace(/[\\()]/g,"\\$&")})`}_string(t){if(this.crypt)return J(this.crypt,t);let e="";for(const s of t)e+=v[s];return`<${e}>`}async _packed(t,e){this.packed??={id:this._alloc(),ids:[],offsets:[],text:""};const{packed:s}=this;this.xref[t]=-(s.id*B+s.ids.length)-1,s.ids.push(t),s.offsets.push(s.text.length),s.text+=`${e}
|
|
5
|
+
`,s.ids.length===B&&await this._flushPacked()}async _flushPacked(){const{packed:t}=this;if(t===null)return;this.packed=null;const e=t.ids.map((s,i)=>`${s} ${t.offsets[i]}`).join(" ")+`
|
|
6
|
+
`;await this._stream(t.id,` /Type /ObjStm /N ${t.ids.length} /First ${e.length}`,s=>P(M.encode(e+t.text),s))}async _stream(t,e,s,{deflate:i=this.compress,encrypt:n=!0}={}){const a=this.crypt&&n?new Q(this.crypt):null,r=a?async d=>this._raw(await a.push(d)):d=>this._raw(d),l=this._alloc();this.xref[t]=this.offset,await this._w(`${t} 0 obj
|
|
7
|
+
<<${e} /Length ${l} 0 R${i?" /Filter /FlateDecode":""}>>
|
|
6
8
|
stream
|
|
7
|
-
`);const
|
|
9
|
+
`);const h=this.offset;if(i){const d=new CompressionStream("deflate"),f=d.writable.getWriter(),u=d.readable.getReader(),m=(async()=>{for(;;){const{done:g,value:_}=await u.read();if(g)return;await r(_)}})().catch(g=>{throw f.abort(g).catch(H),g});try{await s(async g=>{await f.ready,await f.write(g)}),await f.close()}catch(g){throw f.abort(g).catch(H),await m.catch(H),g}await m}else await s(r);a&&await this._raw(await a.end());const c=this.offset-h;await this._w(`
|
|
8
10
|
endstream
|
|
9
11
|
endobj
|
|
10
|
-
`),await this._obj(
|
|
11
|
-
`)),
|
|
12
|
-
0 ${
|
|
12
|
+
`),await this._obj(l,String(c))}async _begin(){if(this.started)return;this.started=!0;const{openPassword:t,permissionsPassword:e,permissions:s}=this.options;(t||e)&&(this.crypt=await Z({openPassword:t,permissionsPassword:e,permissions:s})),await this._raw(new Uint8Array([37,80,68,70,45,49,46,55,10,37,226,227,207,211,10]))}_stdFont(t){let e=this.stdFonts.get(t);return e===void 0&&(e=new lt(t,this.nextFontRes++,this._alloc()),this.stdFonts.set(t,e)),e}_fontSpec(t){let e=this.specs.get(t);if(e!==void 0)return e;const s=/([\d.]+)(px|pt)\s+(.*)$/.exec(t),i=s?t.slice(0,s.index):"",n=s?Number(s[1])*(s[2]==="pt"?4/3:1):10,a=(s?s[3]:"sans-serif").split(",").map(u=>u.trim().replace(/^["']|["']$/g,"").toLowerCase()).filter(Boolean),r=/\bbold\b|\b[6-9]00\b/.test(i),l=/\b(italic|oblique)\b/.test(i),h=[];for(const u of a)for(const p of this.faces)p.familyKey===u&&p.bold===r&&p.italic===l&&!h.includes(p)&&h.push(p);const c=a[0]??"sans-serif",d=this._stdFont(ct(c,r,l)),f=h[0]??d;return e={size:n,faces:h,std:d,hScale:!d.mono&&ht.test(c)?.9:1,ascent:f.ascent,descent:f.descent},this.specs.set(t,e),e}_measure(t,e){const{size:s,faces:i,std:n,hScale:a}=e;let r=0;for(const l of t){let h=l.codePointAt(0);h<32&&(h=32);let c=null;for(let d=0;d<i.length;d++)if(i[d].gidOf(h)!==0){c=i[d];break}if(c!==null){r+=c.width(h);continue}U.has(h)||(h=V(h)),r+=n.width(h)*a}return r*s/1e3}_runs(t,e){const{size:s,faces:i,std:n,hScale:a}=e,r=[];let l=null;for(const h of t){let c=h.codePointAt(0);c<32&&(c=32);let d=null;for(let g=0;g<i.length;g++)if(i[g].gidOf(c)!==0){d=i[g];break}let f,u,p,m=1;if(d!==null)d.resId===0&&(d.resId=this.nextFontRes++,d.objectId=this._alloc()),f=d,u=R(d.use(c)),p=d.width(c);else{let g=U.get(c);g===void 0&&(this.missing.add(c),c=V(c),g=U.get(c)),f=n,u=v[g],p=n.width(c)*a,m=a}(l===null||l.font!==f)&&(l={font:f,hex:"",width:0,hScale:m},r.push(l)),l.hex+=u,l.width+=p*s/1e3}return r}async _writeFonts(){if(this.stdFonts.size>0){this.encodingId=this._alloc();const e=q.map(([,s])=>`/${s}`).join(" ");await this._obj(this.encodingId,`<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [1 ${e}] >>`);for(const s of this.stdFonts.values())await this._obj(s.objectId,`<< /Type /Font /Subtype /Type1 /BaseFont /${s.name} /Encoding ${this.encodingId} 0 R >>`)}let t=0;for(const e of this.faces)e.objectId!==0&&await this._writeFace(e,xt(t++))}async _writeFace(t,e){const s=t.subset(),i=this._alloc(),n=this._alloc(),a=this._alloc(),r=this._alloc();await this._stream(i,` /Length1 ${s.length}`,u=>P(s,u));const l=It(t.unicode);await this._stream(n,"",u=>P(M.encode(l),u));const h=`${e}+${t.postscriptName}`,c=t.scale,d=4|(t.italic?64:0)|(t.bold?1<<18:0);await this._obj(a,`<< /Type /FontDescriptor /FontName /${h} /Flags ${d} /FontBBox [${t.bbox.map(u=>Math.round(u*c)).join(" ")}] /ItalicAngle ${b(t.italicAngle)} /Ascent ${Math.round(t.ascentUnits*c)} /Descent ${Math.round(t.descentUnits*c)} /CapHeight ${Math.round(t.capHeightUnits*c)} /StemV ${t.bold?140:80} /FontFile2 ${i} 0 R >>`);const f=[];for(let u=0;u<t.order.length;u++)f.push(Math.round(t._rawAdvance(t.order[u])*c));await this._obj(r,`<< /Type /Font /Subtype /CIDFontType2 /BaseFont /${h} /CIDSystemInfo << /Registry ${await this._ascii("Adobe")} /Ordering ${await this._ascii("Identity")} /Supplement 0 >> /FontDescriptor ${a} 0 R /CIDToGIDMap /Identity /DW 1000 /W [0 [${f.join(" ")}]] >>`),await this._obj(t.objectId,`<< /Type /Font /Subtype /Type0 /BaseFont /${h} /Encoding /Identity-H /DescendantFonts [${r} 0 R] /ToUnicode ${n} 0 R >>`)}_image(t){const e=this.imageIds.get(t);if(e!==void 0)return e;let s;if(t.jpeg){const i=$t(t.jpeg);if(i===null)return null;s={kind:"jpeg",bytes:t.jpeg,...i}}else if(t.rgba||t.data)s={kind:"rgba",rgba:t.rgba??t.data,width:t.width,height:t.height};else{const i=kt(t);if(i===null)return null;s={kind:"rgba",rgba:i.data,width:i.width,height:i.height}}return s.resId=this.nextImageRes++,s.objectId=this._alloc(),this.imageIds.set(t,s),this.pendingImages.push(s),s}async _writeImage(t){const e=`/Type /XObject /Subtype /Image /Width ${t.width} /Height ${t.height} /BitsPerComponent 8`;if(t.kind==="jpeg"){const s=t.components===1?"/DeviceGray":t.components===4?"/DeviceCMYK":"/DeviceRGB",i=t.components===4?" /Decode [1 0 1 0 1 0 1 0]":"";await this._stream(t.objectId,` ${e} /ColorSpace ${s}${i} /Filter /DCTDecode`,n=>P(t.bytes,n),{deflate:!1})}else{const{rgba:s,width:i,height:n}=t,a=i*n;let r=!0;for(let h=3;h<a*4;h+=4)if(s[h]!==255){r=!1;break}let l="";if(!r){const h=this._alloc();await this._stream(h,` /Type /XObject /Subtype /Image /Width ${i} /Height ${n} /BitsPerComponent 8 /ColorSpace /DeviceGray`,async c=>{for(let d=0;d<a;d+=65536){const f=Math.min(65536,a-d),u=new Uint8Array(f);for(let p=0;p<f;p++)u[p]=s[(d+p)*4+3];await c(u)}}),l=` /SMask ${h} 0 R`}await this._stream(t.objectId,` ${e} /ColorSpace /DeviceRGB${l}`,async h=>{for(let c=0;c<a;c+=65536){const d=Math.min(65536,a-c),f=new Uint8Array(d*3);for(let u=0;u<d;u++){const p=(c+u)*4;f[u*3]=s[p],f[u*3+1]=s[p+1],f[u*3+2]=s[p+2]}await h(f)}})}t.rgba=null,t.bytes=null}beginPage(t,e){if(this.page!==null)throw new Error("Call endPage before the next beginPage");if(this.finished)throw new Error("The document is finished");return this.page=new mt(this,t,e),this.structure&&(this.page.marks=new tt(this.page.ops)),this.page}async endPage(){const t=this.page;if(t===null)return;for(this.page=null,await this._begin();t.stack.length>0;)t.restore();t.marks?.close();const e=this.pendingImages;this.pendingImages=[];for(const f of e)await this._writeImage(f);const s=this._alloc();await this._stream(s,"",f=>P(M.encode(t.ops.join(`
|
|
13
|
+
`)),f));const i=[...t.fonts].map(f=>`/F${f.resId} ${f.objectId} 0 R`).join(" "),n=[...t.images].map(f=>`/Im${f.resId} ${f.objectId} 0 R`).join(" "),a=[...t.alphas].map(f=>`/A${f} << /ca ${b(f/100)} /CA ${b(f/100)} >>`).join(" "),r=`${i?`/Font << ${i} >>`:""}${n?` /XObject << ${n} >>`:""}${a?` /ExtGState << ${a} >>`:""}`,l=[];for(const f of t.links){const u=this._alloc(),p=f.uri===void 0?`/Dest /${f.dest}`:`/A << /S /URI /URI ${await this._ascii(_t(f.uri))} >>`;await this._obj(u,`<< /Type /Annot /Subtype /Link /Rect [${f.rect}] /Border [0 0 0] /F 4 ${p} >>`),l.push(`${u} 0 R`)}const h=this._level(0),c=this._alloc();this.pageIds.push(c);const d=t.marks?await this.structure.page(c,t.marks):"";if(await this._obj(c,`<< /Type /Page /Parent ${h.id} 0 R /MediaBox [0 0 ${b(t.pageWidth)} ${b(t.pageHeight)}] /Contents ${s} 0 R${l.length?` /Annots [${l.join(" ")}]`:""}${d} /Resources << ${r} >> >>`),await this._addKid(0,c,1),this.pageCount++,this.offset>st)throw new Error("PDF exceeds the classic xref limit of 10 GB")}_level(t){let e=this.levels[t];return e===void 0&&(e={id:this._alloc(),kids:[],count:0},this.levels[t]=e),e}async _addKid(t,e,s){const i=this._level(t);if(i.kids.push(e),i.count+=s,i.kids.length<it)return;const n=this._level(t+1);await this._writeNode(i,n.id),this.levels[t]=void 0,await this._addKid(t+1,i.id,i.count)}_writeNode(t,e){const s=e===null?"":` /Parent ${e} 0 R`;return this._obj(t.id,`<< /Type /Pages${s} /Kids [${t.kids.map(i=>`${i} 0 R`).join(" ")}] /Count ${t.count} >>`)}async _closeTree(){let t=Math.max(0,this.levels.length-1);for(;t>0&&this.levels[t]===void 0;)t--;for(let s=0;s<t;s++){const i=this.levels[s];if(i===void 0||i.kids.length===0)continue;const n=this._level(s+1);await this._writeNode(i,n.id),n.kids.push(i.id),n.count+=i.count}const e=this._level(t);return await this._writeNode(e,null),e.id}destination(t,e,s){this.dests.set(t,{page:e,top:s})}bookmark(t,e){this.bookmarks.push({title:t,page:e})}section(t){this.structure?.section(t)}async _writeNavigation(){let t="";const e=[...this.dests].filter(([,i])=>this.pageIds[i.page]!==void 0);if(e.length>0){const i=this._alloc();await this._obj(i,`<< ${e.map(([n,a])=>`/${n} [${this.pageIds[a.page]} 0 R /XYZ null ${b(a.top)} null]`).join(" ")} >>`),t+=` /Dests ${i} 0 R`}const s=this.bookmarks.filter(i=>this.pageIds[i.page]!==void 0);if(s.length>0){const i=this._alloc(),n=s.map(()=>this._alloc());for(let a=0;a<s.length;a++){const r=`${a>0?` /Prev ${n[a-1]} 0 R`:""}${a+1<n.length?` /Next ${n[a+1]} 0 R`:""}`;await this._obj(n[a],`<< /Title ${await this._text(s[a].title)} /Parent ${i} 0 R${r} /Dest [${this.pageIds[s[a].page]} 0 R /Fit] >>`)}await this._obj(i,`<< /Type /Outlines /First ${n[0]} 0 R /Last ${n.at(-1)} 0 R /Count ${n.length} >>`),t+=` /Outlines ${i} 0 R`}return t}async finish(){if(this.finished)return;await this.endPage(),await this._begin(),this.finished=!0,await this._writeFonts();const t=await this._closeTree();let e=await this._writeNavigation();this.structure&&(e+=await this.structure.finish(p=>this._ascii(p))),this.crypt&&(e+=" /Extensions << /ADBE << /BaseVersion /1.7 /ExtensionLevel 8 >> >>");const s=this._alloc();await this._obj(s,`<< /Type /Catalog /Pages ${t} 0 R${e} /ViewerPreferences << /DisplayDocTitle true >> >>`);const i=this.options,n=wt(i.creationDate??new Date),a=[i.title?`/Title ${await this._text(i.title)}`:"",i.author?`/Author ${await this._text(i.author)}`:"",i.subject?`/Subject ${await this._text(i.subject)}`:"",`/Producer ${await this._text(i.producer??"8sheets")}`,`/CreationDate ${await this._ascii(n)}`].filter(Boolean).join(" "),r=this._alloc();await this._obj(r,`<< ${a} >>`),await this._flushPacked();let l="";if(this.crypt){const p=this._alloc();await this._obj(p,this.crypt.dict),l=` /Encrypt ${p} 0 R`}const h=Ut(),c=` /Root ${s} 0 R /Info ${r} 0 R /ID [<${h}> <${h}>]${l}`;if(this.structure){await this._xrefStream(c);return}const d=this.offset,f=this.nextId;await this._w(`xref
|
|
14
|
+
0 ${f}
|
|
13
15
|
0000000000 65535 f
|
|
14
|
-
`);let
|
|
15
|
-
`,
|
|
16
|
-
<< /Size ${
|
|
16
|
+
`);let u="";for(let p=1;p<f;p++)u+=`${String(this.xref[p]).padStart(10,"0")} 00000 n
|
|
17
|
+
`,u.length>=32768&&(await this._w(u),u="");await this._w(u),await this._w(`trailer
|
|
18
|
+
<< /Size ${f}${c} >>
|
|
17
19
|
startxref
|
|
18
|
-
${
|
|
20
|
+
${d}
|
|
19
21
|
%%EOF
|
|
20
|
-
`),await this._flush()}
|
|
22
|
+
`),await this._flush()}async _xrefStream(t){const e=this._alloc(),s=this.offset;this.xref[e]=s;const{nextId:i}=this,n=[],a=async l=>{for(let h=0;h<i;h+=N){const c=Math.min(N,i-h),d=new Uint8Array(c*L),f=new DataView(d.buffer);for(let u=0;u<c;u++){const p=this.xref[h+u],m=u*L;if(p<0){const g=-p-1;d[m]=2,f.setUint32(m+3,Math.floor(g/B)),f.setUint16(m+7,g%B)}else p>0?(d[m]=1,f.setUint16(m+1,Math.floor(p/4294967296)),f.setUint32(m+3,p>>>0)):h+u===0&&f.setUint16(m+7,65535)}await l(d)}};if(this.compress){const l=new CompressionStream("deflate"),h=l.writable.getWriter(),c=(async()=>{const d=l.readable.getReader();for(;;){const{done:f,value:u}=await d.read();if(f)return;n.push(u)}})();await a(async d=>{await h.ready,await h.write(d)}),await h.close(),await c}const r=this.compress?n.reduce((l,h)=>l+h.length,0):i*L;if(await this._w(`${e} 0 obj
|
|
23
|
+
<< /Type /XRef /Size ${i} /W [1 6 2]${t} /Length ${r}${this.compress?" /Filter /FlateDecode":""} >>
|
|
24
|
+
stream
|
|
25
|
+
`),this.compress)for(const l of n)await this._raw(l);else await a(l=>this._raw(l));await this._w(`
|
|
26
|
+
endstream
|
|
27
|
+
endobj
|
|
28
|
+
startxref
|
|
29
|
+
${s}
|
|
30
|
+
%%EOF
|
|
31
|
+
`),await this._flush()}}async function P(o,t){for(let e=0;e<o.length;e+=j)await t(o.subarray(e,Math.min(o.length,e+j)))}function xt(o){let t="",e=o;for(let s=0;s<6;s++)t=String.fromCharCode(65+e%26)+t,e=Math.floor(e/26);return t}function yt(o){if(o<=65535)return R(o);const t=o-65536;return R(55296+(t>>10))+R(56320+(t&1023))}function It(o){const t=[],e=[];for(let s=1;s<o.length;s++)o[s]!==void 0&&e.push(`<${R(s)}> <${yt(o[s])}>`);for(let s=0;s<e.length;s+=100){const i=e.slice(s,s+100);t.push(`${i.length} beginbfchar`,...i,"endbfchar")}return`/CIDInit /ProcSet findresource begin
|
|
21
32
|
12 dict begin
|
|
22
33
|
begincmap
|
|
23
34
|
/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def
|
|
@@ -32,4 +43,4 @@ endcmap
|
|
|
32
43
|
CMapName currentdict /CMap defineresource pop
|
|
33
44
|
end
|
|
34
45
|
end
|
|
35
|
-
`}function
|
|
46
|
+
`}function Ut(){const o=new Uint8Array(16);return globalThis.crypto.getRandomValues(o),[...o].map(t=>v[t]).join("")}function kt(o){const t=o.naturalWidth??o.videoWidth??o.width,e=o.naturalHeight??o.videoHeight??o.height;if(!t||!e)return null;try{const i=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(t,e):Object.assign(document.createElement("canvas"),{width:t,height:e})).getContext("2d");return i.drawImage(o,0,0),i.getImageData(0,0,t,e)}catch{return null}}export{mt as PdfPageContext,St as PdfWriter};
|