@8sheets/data-grid 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +36 -0
- package/README.md +52 -2
- package/a11y/cell-alt-text.js +1 -0
- package/api/overlay.js +1 -0
- package/api/serialize.js +1 -0
- package/api/skins.js +1 -0
- package/api/style-refs.js +1 -0
- package/api/watermark-xml.js +2 -0
- package/calc/adjust.js +1 -0
- package/calc/cell-set.js +1 -0
- package/calc/compile.js +1 -0
- package/calc/engine.js +1 -0
- package/calc/fill-shape.js +2 -0
- package/calc/functions/array.js +1 -0
- package/calc/functions/database.js +1 -0
- package/calc/functions/date.js +1 -0
- package/calc/functions/engineering.js +1 -0
- package/calc/functions/financial.js +1 -0
- package/calc/functions/helpers.js +1 -0
- package/calc/functions/index.js +1 -0
- package/calc/functions/info.js +1 -0
- package/calc/functions/logical.js +1 -0
- package/calc/functions/lookup.js +1 -0
- package/calc/functions/math.js +1 -0
- package/calc/functions/registry.js +1 -0
- package/calc/functions/stat.js +1 -0
- package/calc/functions/text.js +1 -0
- package/calc/parser.js +3 -0
- package/calc/values.js +1 -0
- package/calcx/ai/client.js +1 -0
- package/calcx/ai/functions.js +15 -0
- package/calcx/ai/settings.js +1 -0
- package/calcx/async.js +1 -0
- package/calcx/culture/format-locale.js +1 -0
- package/calcx/culture/lcid.js +1 -0
- package/calcx/external-read.js +1 -0
- package/calcx/external-write.js +3 -0
- package/calcx/external.js +1 -0
- package/calcx/functions/dynamic.js +1 -0
- package/calcx/functions/ets.js +1 -0
- package/calcx/functions/index.js +1 -0
- package/calcx/functions/misc.js +1 -0
- package/calcx/functions/text.js +1 -0
- package/calcx/functions/xml.js +1 -0
- package/calcx/refresh.js +1 -0
- package/cells/auto-merge.js +1 -0
- package/cells/axis-limits.js +1 -0
- package/cells/axis-ops.js +1 -0
- package/cells/background-xml.js +1 -0
- package/cells/background.js +1 -0
- package/cells/book-css.js +206 -0
- package/cells/book-read.js +1 -0
- package/cells/book-view.js +1 -0
- package/cells/cell-defaults.js +1 -0
- package/cells/cell-extras.js +1 -0
- package/cells/cell-options-ui.js +1 -0
- package/cells/cell-styles-xml.js +1 -0
- package/cells/cf-engine.js +1 -0
- package/cells/cf-file.js +1 -0
- package/cells/cf-paint.js +1 -0
- package/cells/consolidate-links.js +1 -0
- package/cells/docprops-xml.js +2 -0
- package/cells/filter-file.js +1 -0
- package/cells/find-engine.js +2 -0
- package/cells/find.js +1 -0
- package/cells/format-code.js +1 -0
- package/cells/format-panes.js +3 -0
- package/cells/format-tabs.js +102 -0
- package/cells/goto.js +1 -0
- package/cells/header-colors.js +1 -0
- package/cells/mask.js +1 -0
- package/cells/menu-extras.js +1 -0
- package/cells/name-box.js +1 -0
- package/cells/note-xml.js +1 -0
- package/cells/options.js +1 -0
- package/cells/outline-column.js +1 -0
- package/cells/paint.js +1 -0
- package/cells/panes.js +1 -0
- package/cells/rich-data-xml.js +2 -0
- package/cells/rich-data.js +1 -0
- package/cells/rich-runs.js +2 -0
- package/cells/rich-values.js +1 -0
- package/cells/rich-xml.js +1 -0
- package/cells/rounded.js +1 -0
- package/cells/sections.js +2 -0
- package/cells/selection-modes.js +1 -0
- package/cells/style-xml.js +1 -0
- package/cells/text-layout.js +8 -0
- package/cells/undo-group.js +1 -0
- package/cells/validation-alert.js +2 -0
- package/cells/view-options.js +1 -0
- package/cells/view-xml.js +1 -0
- package/celltypes/barcode-tables.js +31 -0
- package/celltypes/barcode.js +2 -0
- package/celltypes/base.js +1 -0
- package/celltypes/cell-buttons.js +1 -0
- package/celltypes/cell-types.js +2 -0
- package/celltypes/data-object.js +1 -0
- package/celltypes/diagonal.js +1 -0
- package/celltypes/dropdowns-more.js +13 -0
- package/celltypes/dropdowns.js +42 -0
- package/celltypes/file-cell.js +2 -0
- package/celltypes/glyphs.js +1 -0
- package/celltypes/persist.js +2 -0
- package/celltypes/range-template.js +2 -0
- package/charts/chartex.js +3 -0
- package/charts/geo/geo-xml.js +1 -0
- package/charts/geo/map-state.js +1 -0
- package/charts/patterns.js +1 -0
- package/core/address.js +1 -0
- package/core/axis.js +1 -0
- package/core/base64.js +1 -0
- package/core/changes.js +1 -0
- package/core/color.js +1 -0
- package/core/cond-format.js +1 -0
- package/core/custom-views.js +1 -0
- package/core/default-names.js +1 -0
- package/core/formula-refs.js +1 -0
- package/core/formula-store.js +1 -0
- package/core/input.js +1 -0
- package/core/math.js +1 -0
- package/core/numfmt.js +1 -0
- package/core/online.js +1 -0
- package/core/protection.js +1 -0
- package/core/regexp.js +1 -0
- package/core/sheet-group.js +1 -0
- package/core/sheet.js +1 -0
- package/core/sparklines.js +1 -0
- package/core/sparse.js +1 -0
- package/core/strings.js +1 -0
- package/core/styles.js +1 -0
- package/core/table-presets.js +7 -0
- package/core/tables.js +2 -0
- package/core/tsv.js +4 -0
- package/core/whatif.js +1 -0
- package/core/workbook.js +1 -0
- package/datasheets/bind.js +1 -0
- package/datasheets/calendar.js +1 -0
- package/datasheets/cross.js +1 -0
- package/datasheets/data-core.js +1 -0
- package/datasheets/data.js +1 -0
- package/datasheets/formula.js +1 -0
- package/datasheets/gantt-paint.js +1 -0
- package/datasheets/gantt-resources.js +1 -0
- package/datasheets/gantt-shapes.js +1 -0
- package/datasheets/gantt.js +1 -0
- package/datasheets/manager.js +1 -0
- package/datasheets/path-binding.js +2 -0
- package/datasheets/persist-writer.js +2 -0
- package/datasheets/persist.js +1 -0
- package/datasheets/query-function.js +1 -0
- package/datasheets/remote.js +3 -0
- package/datasheets/report-entry.js +1 -0
- package/datasheets/report.js +1 -0
- package/datasheets/rules.js +1 -0
- package/datasheets/sort.js +1 -0
- package/datasheets/table-sheet.js +1 -0
- package/datasheets/view.js +3 -0
- package/datasheets/virtual-sheet.js +1 -0
- package/datasheets/window.js +1 -0
- package/extras/getdata/persist.js +2 -0
- package/extras/getdata/rows.js +1 -0
- package/extras/getdata/steps.js +1 -0
- package/i18n/dom.js +1 -0
- package/i18n/en/a11y.js +1 -0
- package/i18n/en/cells.js +1 -0
- package/i18n/en/charts.js +1 -0
- package/i18n/en/common.js +1 -0
- package/i18n/en/datasheets.js +1 -0
- package/i18n/en/format.js +1 -0
- package/i18n/en/misc.js +1 -0
- package/i18n/en/pivot.js +1 -0
- package/i18n/en/proofing.js +1 -0
- package/i18n/en/ribbon.js +1 -0
- package/i18n/en/shapes.js +1 -0
- package/i18n/en/shell.js +1 -0
- package/i18n/en/touch.js +1 -0
- package/i18n/en.js +1 -0
- package/i18n/index.js +1 -0
- package/i18n/key-text.js +1 -0
- package/i18n/languages.js +1 -0
- package/i18n/pl/a11y.js +1 -0
- package/i18n/pl/cells.js +1 -0
- package/i18n/pl/charts.js +1 -0
- package/i18n/pl/common.js +1 -0
- package/i18n/pl/datasheets.js +1 -0
- package/i18n/pl/format.js +1 -0
- package/i18n/pl/misc.js +1 -0
- package/i18n/pl/pivot.js +1 -0
- package/i18n/pl/proofing.js +1 -0
- package/i18n/pl/ribbon.js +1 -0
- package/i18n/pl/shapes.js +1 -0
- package/i18n/pl/shell.js +1 -0
- package/i18n/pl/touch.js +1 -0
- package/i18n/pl.js +1 -0
- package/io/client.js +1 -0
- package/io/crc32.js +1 -0
- package/io/crypto/aes.js +1 -0
- package/io/crypto/agile.js +2 -0
- package/io/crypto/cfb-read.js +1 -0
- package/io/crypto/cfb-write.js +1 -0
- package/io/crypto/dataspaces.js +1 -0
- package/io/crypto/errors.js +1 -0
- package/io/crypto/hash.js +1 -0
- package/io/crypto/index.js +1 -0
- package/io/crypto/package-read.js +1 -0
- package/io/crypto/package-write.js +1 -0
- package/io/crypto/spool.js +1 -0
- package/io/crypto/standard.js +1 -0
- package/io/csv.js +8 -0
- package/io/export-blocks.js +1 -0
- package/io/foreign-parts.js +1 -0
- package/io/foreign-sheets.js +2 -0
- package/io/io.worker.js +1 -0
- package/io/package-paths.js +1 -0
- package/io/plan.js +1 -0
- package/io/text-split.js +3 -0
- package/io/xlsx-read.js +1 -0
- package/io/xlsx-styles.js +2 -0
- package/io/xlsx-tail.js +1 -0
- package/io/xlsx-write.js +2 -0
- package/io/xml-escape.js +1 -0
- package/io/xml-scan.js +1 -0
- package/io/zip-reader.js +1 -0
- package/io/zip-writer.js +1 -0
- package/objects/chart-model.js +1 -0
- package/objects/dml.js +5 -0
- package/objects/drawing-xml.js +1 -0
- package/objects/picture-url.js +1 -0
- package/package.json +57 -4
- package/pivot/engine.js +1 -0
- package/pivot/xml.js +2 -0
- package/print/page-setup.js +1 -0
- package/print/paginate.js +1 -0
- package/print/pdf.js +35 -0
- package/print/render-page.js +3 -0
- package/render/patterns.js +1 -0
- package/shapes/form-xml.js +1 -0
- package/shapes/watermark.js +1 -0
- package/slicers/custom-styles.js +1 -0
- package/slicers/date-filters.js +1 -0
- package/slicers/format.js +2 -0
- package/slicers/pivot-file.js +1 -0
- package/slicers/structured.js +1 -0
- package/slicers/table-file.js +1 -0
- package/slicers/write.js +1 -0
- package/sparklines/colors.js +1 -0
- package/sparklines/data.js +1 -0
- package/sparklines/descriptor.js +1 -0
- package/sparklines/excel-paint.js +1 -0
- package/sparklines/functions.js +1 -0
- package/sparklines/paint-core.js +1 -0
- package/sparklines/paint-measure.js +1 -0
- package/sparklines/paint-other.js +2 -0
- package/sparklines/paint-series.js +1 -0
- package/sparklines/paint.js +1 -0
- package/sparklines/print.js +1 -0
- package/sparklines/rule.js +1 -0
- package/table-view/api.js +1 -0
- package/table-view/cell-editor.js +1 -0
- package/table-view/cell-format.js +1 -0
- package/table-view/chrome.js +1 -0
- package/table-view/client.js +1 -0
- package/table-view/column-drag.js +1 -0
- package/table-view/column-input.js +1 -0
- package/table-view/column-window.js +1 -0
- package/table-view/events.js +1 -0
- package/table-view/files.js +1 -0
- package/table-view/grid-keys.js +2 -0
- package/table-view/index.d.ts +4 -0
- package/table-view/index.js +1 -0
- package/table-view/labels.js +1 -0
- package/table-view/model.js +1 -0
- package/table-view/mount.js +1 -0
- package/table-view/panel.js +1 -0
- package/table-view/pivot.js +1 -0
- package/table-view/public.d.ts +841 -0
- package/table-view/quick-filter.js +1 -0
- package/table-view/reader.worker.js +1 -0
- package/table-view/remote.js +1 -0
- package/table-view/row-cache.js +1 -0
- package/table-view/row-selection.js +1 -0
- package/table-view/table-css.js +1207 -0
- package/table-view/totals.js +1 -0
- package/table-view/version.js +1 -0
- package/table-view/worksheet-table.js +1 -0
- package/ui/dialogs.js +3 -0
- package/ui/dom.js +1 -0
- package/ui/icons.js +1 -0
- package/ui/menu-base.js +1 -0
- package/ui/protection-ui.js +1 -0
- package/ui/ui-scale.js +1 -0
|
@@ -0,0 +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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{CHUNK_MASK as P,CONTENT_MASK as z}from"../core/sheet.js";import{MAX_COLS as E,MAX_ROWS as X}from"../core/address.js";import{getPageSetup as D,paperDimensions as F}from"./page-setup.js";const K=16,I=10,q=100;function L(c){return Math.max(22,String(c+1).length*7+6)}function J(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=U(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 U(c,t,s){for(let n=c.length-1;n>=0;n--){const e=n*(P+1);if(e+P<=t)return-1;const o=c[n];if(o===void 0)continue;const{kinds:i,styles:r}=o;for(let l=P;l>=0;l--)if((i[l]&z)!==0||r!==null&&s(r[l]))return e+l}return-1}function H(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 W=(c,t)=>{const s=c.length-1,n=H(c,t+1)-1;return n<0||n>=s?-1:n};function Y(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?H(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 B=(c,t,s)=>c.offsetOf(s+1)-c.offsetOf(t);function G(c,t,s={}){return new V(c,t,s)}class V{constructor(t,s,n){this.book=t,this.sheet=s,this.setup=n.setup??D(s);const{setup:e}=this;this.paper=F(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),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===E-1)?J(s,t?.styles,n.objectExtent??null):null;this.areas=Z(r,a);let h=0;for(const f of this.areas)f.r1>h&&(h=f.r1);this.headingW=e.headings?L(h):0,this.headingH=e.headings?K:0;const{rows:w,cols:u}=s;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?B(w,this.titleRows[0],this.titleRows[1]):0,this.titleW=this.titleCols?B(u,this.titleCols[0],this.titleCols[1]):0,this.useManualBreaks=!e.fitToPage,this.percent=e.fitToPage?this._fitPercent():Q(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:Y(this.sheet.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:Y(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 q;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=q;for(const l of this.areas){const a=B(s.cols,l.c0,l.c1)+this.headingW,h=B(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(I,i),o(i))return i;let r=I;if(!o(r))return I;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.pageCount=t,this._firsts=this.layouts.map(s=>s.first)}_layoutOf(t){return this.layouts[Math.max(0,H(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);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=B(i.cols,u,f),M=B(i.rows,h,w),b=(this.headingW+x+d)*l,O=(this.headingH+C+M)*l,_=a.x+(r.horizontalCentered?Math.max(0,(a.w-b)/2):0),R=a.y+(r.verticalCentered?Math.max(0,(a.h-O)/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:_,originY:R,contentW:b,contentH:O}}_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=W(n.rows,t),i=W(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(e.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:e.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?e.cols.indexAt(e.cols.offsetOf(t.titleCols.c0)+o):e.cols.indexAt(e.cols.offsetOf(t.c0)+o-t.titleW);return{row:r,col:l}}breakPreview(t){const{sheet:s,setup:n}=this,{rows:e,cols:o}=s,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=H(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,W(h.rows,x)),O=Math.max(b,W(h.rows,C)),_=Math.max(0,W(h.cols,d)),R=Math.max(_,W(h.cols,M));for(let m=b;m<=O;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=_;m<=R;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<=O;m++)for(let y=_;y<=R;y++){const A=h.rows[m],k=h.rows[m+1]-1,v=h.cols[y],N=h.cols[y+1]-1,T=o.offsetOf(v),S=e.offsetOf(A);i.pages.push({index:h.first+this._seq(h,m,y),r0:A,r1:k,c0:v,c1:N,x:T,y:S,w:o.offsetOf(N+1)-T,h:e.offsetOf(k+1)-S})}}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[H(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)),O=Math.min(d.nRows-1,Math.floor((x-M)/i)),_=Math.max(0,Math.floor(f/o)),R=Math.min(d.nCols-1,Math.floor(p/o));for(let m=b;m<=O;m++)for(let y=_;y<=R;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 Q(c){const t=Math.round(Number(c)||100);return Math.min(400,Math.max(10,t))}function Z(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===E-1&&(r=Math.max(t.maxCol,0)),i>=e&&r>=o&&s.push({r0:e,c0:o,r1:i,c1:r})}return s}function et(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=G(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 $(c,n,e)}class ${constructor(t,s,n){this.book=t,this.entries=s,this.pageCount=n,this._firsts=s.map(e=>e.first)}entryOf(t){let s=H(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{V as Pagination,$ as PrintJob,et as createPrintJob,H as lowerBound,G as paginate,J as printedExtent};
|
package/print/pdf.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const W=new TextEncoder,M=65536,J=9999999999,K=128,H=()=>{},j=[];for(let o=0;o<256;o++)j.push(o.toString(16).padStart(2,"0"));const F=o=>j[o>>8&255]+j[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 Y=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]})),L="€\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"]],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<L.length;o++)L[o]!=="\0"&&U.set(L.codePointAt(o),128+o);z.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 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(o,t,e){return tt.test(o)?`Courier${t||e?"-":""}${t?"Bold":""}${e?"Oblique":""}`:Z.test(o)&&!Q.test(o)?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=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=Y.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 N(o){const t=String.fromCodePoint(o).normalize("NFD").codePointAt(0);return U.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 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),g=a+i.getUint16(l+10);let f="";if(h===3||h===0)for(let m=0;m+1<d;m+=2)f+=String.fromCharCode(i.getUint16(g+m));else for(let m=0;m<d;m++)f+=String.fromCharCode(i.getUint8(g+m));const u=c===1?"family":"postscript";(e[u]===void 0||h===3)&&(e[u]=f)}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 u=0;u<s;u++){const m=e+4+u*8,w=t.getUint16(m),x=t.getUint16(m+2),y=e+t.getUint32(m+4),$=t.getUint16(y);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:y,format:$})}if(i===null)throw new Error("Font has no Unicode cmap");const{at:a,format:r}=i;if(r===12){const u=t.getUint32(a+12);return m=>{let w=0,x=u-1;for(;w<=x;){const y=w+x>>>1,$=a+16+y*12;if(m<t.getUint32($))x=y-1;else if(m>t.getUint32($+4))w=y+1;else return t.getUint32($+8)+m-t.getUint32($)}return 0}}if(r===6){const u=t.getUint16(a+6),m=t.getUint16(a+8);return w=>w>=u&&w<u+m?t.getUint16(a+10+(w-u)*2):0}const l=t.getUint16(a+6),h=a+14,c=h+l+2,d=c+l,g=d+l,f=l/2;return u=>{if(u>65535)return 0;let m=0,w=f-1;for(;m<w;){const p=m+w>>>1;t.getUint16(h+p*2)<u?m=p+1:w=p}const x=t.getUint16(c+m*2);if(u<x||u>t.getUint16(h+m*2))return 0;const y=t.getInt16(d+m*2),$=t.getUint16(g+m*2);if($===0)return u+y&65535;const I=t.getUint16(g+m*2+$+(u-x)*2);return I===0?0:I+y&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 p=0;p<this.order.length;p++){const[_,T]=this._glyphRange(this.order[p]);if(T<=0){t.push(null);continue}const k=this.bytes.slice(_,_+T),C=new DataView(k.buffer);if(C.getInt16(0)<0){let S=10;for(;;){const v=C.getUint16(S);if(C.setUint16(S+2,this._newId(C.getUint16(S+2))),S+=4+(v&1?4:2),v&8?S+=2:v&64?S+=4:v&128&&(S+=8),!(v&32))break}}t.push(k)}const e=this.order.length,s=new Uint8Array((e+1)*4),i=new DataView(s.buffer);let n=0;for(let p=0;p<e;p++)i.setUint32(p*4,n),t[p]&&(n+=t[p].length+3&-4);i.setUint32(e*4,n);const a=new Uint8Array(n);for(let p=0;p<e;p++)t[p]&&a.set(t[p],i.getUint32(p*4));const r=new Uint8Array(e*4),l=new DataView(r.buffer);for(let p=0;p<e;p++)l.setUint16(p*4,this._rawAdvance(this.order[p])),l.setInt16(p*4+2,this._rawLsb(this.order[p]));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 g=this._copyTable("maxp");new DataView(g.buffer).setUint16(4,e);const f=[["glyf",a],["head",h],["hhea",d],["hmtx",r],["loca",s],["maxp",g]];for(const p of["cvt ","fpgm","prep"]){const _=this._copyTable(p);_&&f.push([p,_])}f.sort((p,_)=>p[0]<_[0]?-1:1);let u=12+f.length*16;for(const[,p]of f)u+=p.length+3&-4;const m=new Uint8Array(u),w=new DataView(m.buffer),x=f.length,y=31-Math.clz32(x);w.setUint32(0,65536),w.setUint16(4,x),w.setUint16(6,16<<y),w.setUint16(8,y),w.setUint16(10,x*16-(16<<y));let $=12+x*16,I=0;return f.forEach(([p,_],T)=>{const k=12+T*16;for(let C=0;C<4;C++)w.setUint8(k+C,p.charCodeAt(C));w.setUint32(k+4,q(_)),w.setUint32(k+8,$),w.setUint32(k+12,_.length),m.set(_,$),p==="head"&&(I=$),$+=_.length+3&-4}),w.setUint32(I+8,2981146554-q(m)>>>0),m}}function q(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 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"},B=new Map;function E(o){const t=String(o);let e=B.get(t);return e!==void 0||(e=at(t.trim().toLowerCase()),B.size>4096&&B.clear(),B.set(t,e)),e}function at(o){if(o==="transparent")return{r:0,g:0,b:0,a:0,ops:"0 0 0"};let t=ot[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 R{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:E("#000000"),fillText:"#000000",stroke:E("#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.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 R?t.color??"#000000":t,s=E(e);s!==null&&(this.s.fill=s,this.s.fillText=e)}get strokeStyle(){return this.s.strokeText}set strokeStyle(t){const e=t instanceof R?t.color??"#000000":t,s=E(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:g,f}=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+g,r.f=h*n+d*a+f}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))}`}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),g=Math.sin(n),f=p=>{const _=s*Math.cos(p),T=i*Math.sin(p);return[t+_*d-T*g,e+_*g+T*d]},u=p=>{const _=-s*Math.sin(p),T=i*Math.cos(p);return[_*d-T*g,_*g+T*d]},m=Math.max(1,Math.ceil(Math.abs(h)/(Math.PI/2))),w=h/m,x=4/3*Math.tan(w/4),[y,$]=f(a);this.path.length===0?this.moveTo(y,$):this.lineTo(y,$);let I=a;for(let p=0;p<m;p++){const _=I+w,[T,k]=f(I),[C,S]=f(_),[v,V]=u(I),[G,X]=u(_);this.bezierCurveTo(T+x*v,k+x*V,C-x*G,S-x*X,C,S),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 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 R}createRadialGradient(){return new R}createConicGradient(){return new R}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 f of l)h+=f.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 g=e;for(const f of l){this.fonts.add(f.font);const u=f.hScale,m=`${b(r.a*u)} ${b(-r.b*u)} ${b(-r.c)} ${b(r.d)} ${b(this._X(g,s))} ${b(this._Y(g,s))}`;this.ops.push(`BT${i?" 1 Tr":""} /F${f.font.resId} ${d} Tf ${m} Tm <${f.hex}> Tj${i?" 0 Tr":""} ET`),g+=f.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 I=c/a,p=d/r;l-=i*I,h-=n*p,c=s.width*I,d=s.height*p}const g=this.s,f=g.a*c,u=-g.b*c,m=-g.c*d,w=g.d*d,x=this._X(l,h+d),y=this._Y(l,h+d);this.ops.push(`${b(f)} ${b(u)} ${b(m)} ${b(w)} ${b(x)} ${b(y)} cm /Im${s.resId} Do Q`)}}function lt(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 O(o){let t="FEFF";for(let e=0;e<o.length;e++)t+=F(o.charCodeAt(e));return`<${t}>`}function ft(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 wt{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.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
|
|
2
|
+
${e}
|
|
3
|
+
endobj
|
|
4
|
+
`)}async _stream(t,e,s,{deflate:i=this.compress}={}){const n=this._alloc();this.xref[t]=this.offset,await this._w(`${t} 0 obj
|
|
5
|
+
<<${e} /Length ${n} 0 R${i?" /Filter /FlateDecode":""}>>
|
|
6
|
+
stream
|
|
7
|
+
`);const a=this.offset;if(i){const l=new CompressionStream("deflate"),h=l.writable.getWriter(),c=l.readable.getReader(),g=(async()=>{for(;;){const{done:f,value:u}=await c.read();if(f)return;await this._raw(u)}})().catch(f=>{throw h.abort(f).catch(H),f});try{await s(async f=>{await h.ready,await h.write(f)}),await h.close()}catch(f){throw h.abort(f).catch(H),await g.catch(H),f}await g}else await s(l=>this._raw(l));const r=this.offset-a;await this._w(`
|
|
8
|
+
endstream
|
|
9
|
+
endobj
|
|
10
|
+
`),await this._obj(n,String(r))}async _begin(){this.started||(this.started=!0,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 it(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(f=>f.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 f of a)for(const u of this.faces)u.familyKey===f&&u.bold===r&&u.italic===l&&!h.includes(u)&&h.push(u);const c=a[0]??"sans-serif",d=this._stdFont(st(c,r,l)),g=h[0]??d;return e={size:n,faces:h,std:d,hScale:!d.mono&&et.test(c)?.9:1,ascent:g.ascent,descent:g.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=N(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 w=0;w<i.length;w++)if(i[w].gidOf(c)!==0){d=i[w];break}let g,f,u,m=1;if(d!==null)d.resId===0&&(d.resId=this.nextFontRes++,d.objectId=this._alloc()),g=d,f=F(d.use(c)),u=d.width(c);else{let w=U.get(c);w===void 0&&(this.missing.add(c),c=N(c),w=U.get(c)),g=n,f=j[w],u=n.width(c)*a,m=a}(l===null||l.font!==g)&&(l={font:g,hex:"",width:0,hScale:m},r.push(l)),l.hex+=f,l.width+=u*s/1e3}return r}async _writeFonts(){if(this.stdFonts.size>0){this.encodingId=this._alloc();const e=z.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,dt(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}`,f=>P(s,f));const l=pt(t.unicode);await this._stream(n,"",f=>P(W.encode(l),f));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(f=>Math.round(f*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 g=[];for(let f=0;f<t.order.length;f++)g.push(Math.round(t._rawAdvance(t.order[f])*c));await this._obj(r,`<< /Type /Font /Subtype /CIDFontType2 /BaseFont /${h} /CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >> /FontDescriptor ${a} 0 R /CIDToGIDMap /Identity /DW 1000 /W [0 [${g.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=ft(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=mt(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 g=Math.min(65536,a-d),f=new Uint8Array(g);for(let u=0;u<g;u++)f[u]=s[(d+u)*4+3];await c(f)}}),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),g=new Uint8Array(d*3);for(let f=0;f<d;f++){const u=(c+f)*4;g[f*3]=s[u],g[f*3+1]=s[u+1],g[f*3+2]=s[u+2]}await h(g)}})}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 ct(this,t,e),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();const e=this.pendingImages;this.pendingImages=[];for(const c of e)await this._writeImage(c);const s=this._alloc();await this._stream(s,"",c=>P(W.encode(t.ops.join(`
|
|
11
|
+
`)),c));const i=[...t.fonts].map(c=>`/F${c.resId} ${c.objectId} 0 R`).join(" "),n=[...t.images].map(c=>`/Im${c.resId} ${c.objectId} 0 R`).join(" "),a=[...t.alphas].map(c=>`/A${c} << /ca ${b(c/100)} /CA ${b(c/100)} >>`).join(" "),r=`${i?`/Font << ${i} >>`:""}${n?` /XObject << ${n} >>`:""}${a?` /ExtGState << ${a} >>`:""}`,l=this._level(0),h=this._alloc();if(await this._obj(h,`<< /Type /Page /Parent ${l.id} 0 R /MediaBox [0 0 ${b(t.pageWidth)} ${b(t.pageHeight)}] /Contents ${s} 0 R /Resources << ${r} >> >>`),await this._addKid(0,h,1),this.pageCount++,this.offset>J)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<K)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}async finish(){if(this.finished)return;await this.endPage(),await this._begin(),this.finished=!0,await this._writeFonts();const t=await this._closeTree(),e=this._alloc();await this._obj(e,`<< /Type /Catalog /Pages ${t} 0 R /ViewerPreferences << /DisplayDocTitle true >> >>`);const s=this.options,i=lt(s.creationDate??new Date),n=[s.title?`/Title ${O(s.title)}`:"",s.author?`/Author ${O(s.author)}`:"",s.subject?`/Subject ${O(s.subject)}`:"",`/Producer ${O(s.producer??"8sheets")}`,`/CreationDate (${i})`].filter(Boolean).join(" "),a=this._alloc();await this._obj(a,`<< ${n} >>`);const r=this.offset,l=this.nextId;await this._w(`xref
|
|
12
|
+
0 ${l}
|
|
13
|
+
0000000000 65535 f
|
|
14
|
+
`);let h="";for(let d=1;d<l;d++)h+=`${String(this.xref[d]).padStart(10,"0")} 00000 n
|
|
15
|
+
`,h.length>=32768&&(await this._w(h),h="");await this._w(h);const c=gt();await this._w(`trailer
|
|
16
|
+
<< /Size ${l} /Root ${e} 0 R /Info ${a} 0 R /ID [<${c}> <${c}>] >>
|
|
17
|
+
startxref
|
|
18
|
+
${r}
|
|
19
|
+
%%EOF
|
|
20
|
+
`),await this._flush()}}async function P(o,t){for(let e=0;e<o.length;e+=M)await t(o.subarray(e,Math.min(o.length,e+M)))}function dt(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 ut(o){if(o<=65535)return F(o);const t=o-65536;return F(55296+(t>>10))+F(56320+(t&1023))}function pt(o){const t=[],e=[];for(let s=1;s<o.length;s++)o[s]!==void 0&&e.push(`<${F(s)}> <${ut(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
|
+
12 dict begin
|
|
22
|
+
begincmap
|
|
23
|
+
/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def
|
|
24
|
+
/CMapName /Adobe-Identity-UCS def
|
|
25
|
+
/CMapType 2 def
|
|
26
|
+
1 begincodespacerange
|
|
27
|
+
<0000> <FFFF>
|
|
28
|
+
endcodespacerange
|
|
29
|
+
${t.join(`
|
|
30
|
+
`)}
|
|
31
|
+
endcmap
|
|
32
|
+
CMapName currentdict /CMap defineresource pop
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
`}function gt(){const o=new Uint8Array(16);return globalThis.crypto.getRandomValues(o),[...o].map(t=>j[t]).join("")}function mt(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{ct as PdfPageContext,wt as PdfWriter};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{readingDirection as at,visualOrder as ht,wrapsByAlign as dt}from"../cells/text-layout.js";import{gradientPatches as q}from"../cells/paint.js";import{paintWatermarks as ut}from"../shapes/watermark.js";import{BOOL as mt,CHUNK_BITS as Q,CHUNK_MASK as H,EMPTY as K,ERR as tt,ERRORS as gt,KIND_MASK as U,NUM as W,STR as v,FORMULA as et,SPILL as nt}from"../core/sheet.js";import{isBarcodeText as bt,paintBarcodeValue as pt}from"../celltypes/barcode.js";import{printCellType as ot,printEmptyTypedCells as wt}from"../celltypes/cell-types.js";import{FILL_MARK as it,formatGeneral as st,getFormatter as V}from"../core/numfmt.js";import{colName as kt}from"../core/address.js";import{cssFont as E}from"../core/styles.js";import{CondFormats as yt}from"../core/cond-format.js";import{drawCfIcon as Tt,iconSide as xt,monoContext as St,paintCfBar as Dt}from"../cells/cf-paint.js";import{sparklineIndex as At}from"../core/sparklines.js";import{paintSparkline as Ot}from"../sparklines/excel-paint.js";import{isSparklineText as Rt,paintSparklineValue as Ft}from"../sparklines/paint.js";import{paintSparkRulesOnPage as Pt,sparkRuleHidesValue as Ct}from"../sparklines/rule.js";import{preparePicturesForPrint as Mt}from"../sparklines/print.js";import{tableColors as It,tablesOf as zt}from"../core/tables.js";import{paintCustomTable as Nt}from"../slicers/custom-styles.js";import{resolveColor as vt}from"../io/xlsx-styles.js";import{parseHeaderFooter as Lt}from"./page-setup.js";const Wt=2,Ht=6,Et=32,Y="#000000",$=.25,j=10,Bt={hair:.25,thin:.5,dotted:.5,dashed:.5,dashDot:.5,dashDotDot:.5,medium:1,mediumDashed:1,mediumDashDot:1,mediumDashDotDot:1,slantDashDot:1,thick:1.5,double:.5},_t={hair:[.5,.75],dotted:[.5,1.5],dashed:[3,1.5],dashDot:[3,1.5,.75,1.5],dashDotDot:[3,1.5,.75,1.5,.75,1.5],mediumDashed:[4,2],mediumDashDot:[4,2,1,2],mediumDashDotDot:[4,2,1,2,1,2],slantDashDot:[4,1,1,1]},rt=new WeakMap;function J(n){let i=rt.get(n);return i===void 0&&(i=E(n,n.fontSize),rt.set(n,i)),i}function Gt(n,i,l,s){switch(i){case W:return s.numFmt==="General"?st(l):V(s.numFmt).number(l);case v:{const p=n.strings.get(l);return s.numFmt==="General"||s.numFmt==="@"?p:V(s.numFmt).text(p)}case mt:return l?"TRUE":"FALSE";case tt:return gt[l]??"#N/A";default:return""}}class Xt{constructor(i,l,s,p){this.ctx=i,this.book=l,this.sheet=s,this.styles=l.styles.list,this.mono=p.blackAndWhite,this.errors=p.errors,this.cfFrame=null,this.tables=null,this.font="",this.ink="",this.wrapCache=new Map,this.reachX=null}style(i,l){return this.styles[this.sheet.style(i,l)]??this.styles[0]}textStyle(i,l,s,p,o){let t=this.style(i,l);const r=this.cfFrame===null?void 0:this.cfFrame.get(i*16384+l);if(r!==void 0){if(r.icon&&this.icon(r.icon,s,p,o,t),r.hideValue)return null;(r.color||r.numFmt!==void 0||r.bold!==void 0||r.italic!==void 0||r.underline!==void 0||r.strike!==void 0)&&(t={...t,color:r.color??t.color,numFmt:r.numFmt??t.numFmt,bold:r.bold??t.bold,italic:r.italic??t.italic,underline:r.underline??t.underline,strike:r.strike??t.strike})}if(this.tables!==null)for(const h of this.tables){if(i<h.r0||i>h.r1||l<h.c0||l>h.c1||!h._colors)continue;const d=h._colors.format(h,i,l);t={...t,color:t.color??d.color,bold:t.bold||d.bold===!0,italic:t.italic||d.italic===!0},d.underline&&!t.underline&&(t.underline=d.underline),d.strike&&(t.strike=!0);break}return t}icon(i,l,s,p,o){const t=xt(p,1,o.fontSize),r=o.vAlign==="top"?s+1:o.vAlign==="center"?s+(p-t)/2:s+p-t-1;Tt(this.mono?St(this.ctx):this.ctx,i.name,i.level,l+1,r,t),this.ink=""}setFont(i){this.font!==i&&(this.ctx.font=i,this.font=i)}setInk(i){this.ink!==i&&(this.ctx.fillStyle=i,this.ink=i)}reset(){this.font="",this.ink=""}width(i){return this.ctx.measureText(i).width}richLine(i,l,s,p,o,t,r,h,d){const{ctx:T}=this,a=[];let w=0,u=0;l.forEach((k,P)=>{const x=l[P+1]?.at??i.length;if(x<=k.at)return;const D={...s,fontName:k.name??s.fontName,fontSize:k.sz??s.fontSize,bold:k.b??s.bold,italic:k.i??s.italic},I=J(D);this.setFont(I);const N=i.slice(k.at,x).replace(/\n/g," "),M=T.measureText(N).width;a.push({piece:N,font:I,ink:k.color??s.color??"#000000",pw:M}),w+=M,u=Math.max(u,D.fontSize)});const b=s.vAlign??"bottom",C=b==="top"?t+u*1.05:b==="center"?t+(h+u*.72)/2:t+h-3;let F=p==="right"?o+r-d-w:p==="center"||p==="centerContinuous"?o+(r-w)/2:o+d;T.textAlign="left";for(const k of a)this.setFont(k.font),this.setInk(k.ink),T.fillText(k.piece,F,C),F+=k.pw}text(i,l,s,p,o,t,r,h,d,T=!1){const{ctx:a,sheet:w}=this,u=this.reachX===null?this.textStyle(i,l,o,t,h):this.style(i,l);if(u===null)return;if(w.cellTypes!==null&&this.reachX===null&&ot(a,this.book,w,i,l,o,t,r,h)){this.reset();return}if(s===W&&p===0&&w.hideZeros)return;if(u.ext?.pad){const[c,y,R,z]=u.ext.pad;o+=z,t+=c,r=Math.max(0,r-z-y),h=Math.max(0,h-c-R)}let b=Gt(this.book,s,p,u);if(s===tt&&this.errors!=="displayed"&&(b=this.errors==="blank"?"":this.errors==="dash"?"--":"#N/A"),b===""||s===v&&bt(b)&&(w.kind(i,l)&(et|nt))!==0&&pt(a,b,o,t,r,h,1)||s===v&&Rt(b)&&(w.kind(i,l)&(et|nt))!==0&&Ft(a,b,o,t,r,h,1,{ink:u.color??"#000000",snap:!1,mono:this.mono})||w.sparkRules!==null&&Ct(w,i,l))return;const C=J(u);this.setFont(C);let F=u.color??"#000000";s===W&&u.numFmt!=="General"&&(F=V(u.numFmt).color(p)??F),this.setInk(this.mono?"#000000":F);const k=Wt,P=s===v?at(u.readingOrder,b):null;s===v&&!("direction"in a)&&(b=ht(b,P==="rtl")),P==="rtl"&&"direction"in a?(a.direction="rtl",this.pendingDirection=!0):this.pendingDirection&&(a.direction="ltr",this.pendingDirection=!1);const x=u.hAlign??(s===W||P==="rtl"?"right":s===v?"left":"center");if(x==="centerContinuous")for(let c=l+1;(w.kind(i,c)&15)===0&&w.mergeAt(i,c)===null&&this.book.styles.get(w.style(i,c)).hAlign==="centerContinuous";c++)r+=w.cols.sizeOf(c);const D=r-k*2,I=u.fontSize;if(this.reachX!==null&&(u.rotation!==0||u.wrap))return;if(u.rotation!==0){this.rotated(b,u,o,t,r,h);return}if(u.wrap||dt(u)){this.wrapped(b,u,x,o,t,r,h,k,I);return}const N=s===v?this.book.strings.rich?.get(p):void 0;if(N!==void 0&&!this.mono){this.richLine(b,N,u,x,o,t,r,h,k);return}const M=u.vAlign??"bottom";let O;if(M==="top"?O=t+I*1.05:M==="center"?O=t+(h+I*.72)/2:O=t+h-3,b.indexOf(it)>=0){if(this.reachX!==null)return;const c=b.split(it),y=c[0],R=c[1]??" ",z=c.slice(2).join("");a.textAlign="left",y&&a.fillText(y,o+k,O);const L=this.width(y),G=this.width(z);if(R!==" "){const X=this.width(R)||1,Z=Math.floor((D-L-G)/X);Z>0&&a.fillText(R.repeat(Z),o+k+L,O)}a.textAlign="right",z&&a.fillText(z,o+r-k,O),a.textAlign="left";return}let S=this.width(b);if(S>D&&s===W){if(u.numFmt==="General"){let c=10;for(;c>=1&&S>D;)b=st(p,c),S=this.width(b),c--}if(S>D){const c=this.width("#")||1;b="#".repeat(Math.max(1,Math.floor(D/c))),S=c*b.length}}let A=!1;if(u.shrink&&S>D&&D>0&&(this.setFont(E(u,I*(D/S))),S=D,A=!0),u.indent>0){const c=u.indent*Ht;x==="left"?(o+=c,r-=c):x==="right"&&(r-=c)}let e,f=!1,g=o,m=o+r;if(x==="center"||x==="centerContinuous")e=o+(r-S)/2;else if(x==="right")e=o+r-k-S;else if(x==="fill"){const c=Math.max(1,Math.floor(D/(S||1)));b=b.repeat(c),S*=c,e=o+k}else e=o+k;if(this.reachX!==null&&e+S<=this.reachX){A&&this.setFont(C);return}if(S>D||e<o+k)if(T)f=!0;else if(s===v){if(e+S>m){let c=l+1,y=m;for(;y<e+S&&c<=d.c1&&(w.kind(i,c)&15)===0&&w.mergeAt(i,c)===null;)y+=w.cols.sizeOf(c),c++;m=y}if(e<g){let c=l-1,y=g;for(;y>e&&c>=d.c0&&(w.kind(i,c)&15)===0&&w.mergeAt(i,c)===null;)y-=w.cols.sizeOf(c),c--;g=y}f=e+S>m||e<g}else f=!0;a.textAlign="left",f?(a.save(),a.beginPath(),a.rect(g,t,m-g,h),a.clip(),a.fillText(b,e,O),this.decorate(u,e,O,S,I),a.restore()):(a.fillText(b,e,O),(u.underline!==0||u.strike)&&this.decorate(u,e,O,S,I)),A&&this.setFont(C)}decorate(i,l,s,p,o){const{ctx:t}=this,r=Math.max(.5,o/14);if(i.underline!==0){const h=s+o*.14;t.fillRect(l,h,p,r),i.underline===2&&t.fillRect(l,h+r*2,p,r)}i.strike&&t.fillRect(l,s-o*.3,p,r)}wrapLines(i,l,s){const p=`${i}|${Math.round(s)}|${l}`;let o=this.wrapCache.get(p);if(o!==void 0)return o;o=[];for(const t of l.split(`
|
|
2
|
+
`)){let r="";for(const h of t.split(/(?<=\s)/)){const d=r+h;for(r!==""&&this.width(d.trimEnd())>s?(o.push(r.trimEnd()),r=h):r=d;this.width(r.trimEnd())>s&&r.length>1;){let T=r.length-1;for(;T>1&&this.width(r.slice(0,T))>s;)T--;o.push(r.slice(0,T)),r=r.slice(T)}}o.push(r.trimEnd())}return this.wrapCache.size>4096&&this.wrapCache.clear(),this.wrapCache.set(p,o),o}wrapped(i,l,s,p,o,t,r,h,d){const{ctx:T}=this,a=this.wrapLines(J(l),i,t-h*2),w=Math.round(d*1.26),u=a.length*w,b=l.vAlign??"bottom";let C;b==="top"?C=o:b==="center"?C=o+(r-u)/2:C=o+r-u,T.save(),T.beginPath(),T.rect(p,o,t,r),T.clip(),T.textAlign=s==="center"?"center":s==="right"?"right":"left";const F=s==="center"?p+t/2:s==="right"?p+t-h:p+h;for(let k=0;k<a.length;k++){const P=C+k*w+Math.round(w*.8);P+w<o||P-w>o+r||T.fillText(a[k],F,P)}T.restore(),T.textAlign="left"}rotated(i,l,s,p,o,t){const{ctx:r}=this;r.save(),r.beginPath(),r.rect(s,p,o,t),r.clip(),r.translate(s+o/2,p+t/2);const h=l.rotation;if(r.textAlign="center",h===255){const d=l.fontSize*1.1,T=-((i.length-1)*d)/2;for(let a=0;a<i.length;a++)r.fillText(i[a],0,T+a*d)}else{const d=h>90?90-h:h;r.rotate(-d*Math.PI/180),r.fillText(i,0,l.fontSize*.35)}r.restore(),r.textAlign="left"}side(i,l,s,p,o){if(!i)return;const{ctx:t}=this,r=Bt[i.style]??.5;if(t.strokeStyle=this.mono?"#000000":i.color??"#000000",t.lineWidth=r,t.setLineDash(_t[i.style]??[]),t.beginPath(),i.style==="double"){const h=s===o?0:.75,d=s===o?.75:0;t.moveTo(l-h,s-d),t.lineTo(p-h,o-d),t.moveTo(l+h,s+d),t.lineTo(p+h,o+d)}else t.moveTo(l,s),t.lineTo(p,o);t.stroke()}}function lt(n,i,l){const s=new Float64Array(l-i+2);let p=0;for(let o=i;o<=l;o++)s[o-i]=p,p+=n.sizeOf(o);return s[l-i+1]=p,s}function B(n,i,l,s,p){const{ctx:o,sheet:t}=n,{x:r,y:h,r0:d,r1:T,c0:a,c1:w}=i,u=lt(t.cols,a,w),b=lt(t.rows,d,T),C=w-a+1,F=T-d+1,k=u[C],P=b[F];if(k<=0||P<=0)return;if(o.save(),o.beginPath(),o.rect(r,h,k,P),o.clip(),n.reset(),l){o.strokeStyle=Y,o.lineWidth=$,o.setLineDash([]),o.beginPath();for(let e=0;e<=C;e++)e>0&&u[e]===u[e-1]||(o.moveTo(r+u[e],h),o.lineTo(r+u[e],h+P));for(let e=0;e<=F;e++)e>0&&b[e]===b[e-1]||(o.moveTo(r,h+b[e]),o.lineTo(r+k,h+b[e]));o.stroke()}const x=t.mergesInRows(d,T).filter(e=>e.c1>=a&&e.c0<=w),D=x.length>0,I=t.rowStyles!==null||t.colStyles!==null,N=n.styles[0].fill===null&&n.styles[0].borders===null;n.tables=null;const{book:M}=n;if(M.engine&&M.engine.tables.size>0){const e=zt(M,t);e.length>0&&(n.tables=e);for(const f of e){if(f.r1<d||f.r0>T||f.c1<a||f.c0>w)continue;const g=It(f.styleName,M.theme);g&&(f._colors=g,Nt(o,f,g,{ra:d,rb:T,ca:a,cb:w,xs:u,ys:b,ox:r,oy:h,line:.5,noFill:n.mono,setInk:m=>n.setInk(n.mono?"#000000":m)}))}}let O=null;for(let e=a;e<=w;e++){const f=u[e-a+1]-u[e-a];if(f===0)continue;const g=t.columns[e];if(!(g===void 0&&!I&&N))for(let m=d;m<=T;m++){if(!I&&N){const R=g[m>>>Q];if(R===void 0||R.styles===null){m|=H;continue}if(R.styles[m&H]===0)continue}const c=b[m-d+1]-b[m-d];if(c===0)continue;const y=n.style(m,e);y.fill===null&&y.borders===null||D&&t.mergeAt(m,e)!==null||(y.fill!==null&&!n.mono&&(y.gradient?q(y.gradient,r+u[e-a],h+b[m-d],f,c,(R,z,L,G,X)=>{n.setInk(R),o.fillRect(z,L,G,X)}):(n.setInk(ft(y)),o.fillRect(r+u[e-a],h+b[m-d],f,c))),y.borders!==null&&(O??=[]).push(m,e,y.borders))}}const S=e=>{const f=r+t.cols.offsetOf(e.c0)-t.cols.offsetOf(a),g=h+t.rows.offsetOf(e.r0)-t.rows.offsetOf(d);return{x:f,y:g,w:t.cols.offsetOf(e.c1+1)-t.cols.offsetOf(e.c0),h:t.rows.offsetOf(e.r1+1)-t.rows.offsetOf(e.r0)}};for(const e of x){const f=S(e),g=n.style(e.r0,e.c0);(l||g.fill!==null&&!n.mono)&&(g.gradient&&!n.mono?q(g.gradient,f.x,f.y,f.w,f.h,(m,c,y,R,z)=>{n.setInk(m),o.fillRect(c,y,R,z)}):(n.setInk(g.fill!==null&&!n.mono?ft(g):"#ffffff"),o.fillRect(f.x,f.y,f.w,f.h))),l&&(o.strokeStyle=Y,o.lineWidth=$,o.setLineDash([]),o.strokeRect(f.x,f.y,f.w,f.h))}if(n.cfFrame=null,t.cf&&t.cf.length>0){t.cfEval||(t.cfEval=new yt(M,t,f=>vt(f,M.theme??[])));const e=new Map;n.cfFrame=e;for(let f=a;f<=w;f++){const g=u[f-a+1]-u[f-a];for(let m=d;m<=T;m++){const c=t.cfEval.at(m,f);if(c===null)continue;e.set(m*16384+f,c);const y=r+u[f-a],R=h+b[m-d],z=b[m-d+1]-b[m-d];c.noFill&&!n.mono&&(n.setInk("#FFFFFF"),o.fillRect(y,R,g,z)),c.fill&&!n.mono&&(n.setInk(c.fill),o.fillRect(y,R,g,z)),c.bar&&!n.mono&&(Dt(o,c.bar,y,R,g,z,1,!1,!0),n.ink=""),c.borders&&(O??=[]).push(m,f,c.borders)}}}if(O!==null)for(let e=0;e<O.length;e+=3){const f=O[e],g=O[e+1],m=O[e+2],c=r+u[g-a],y=r+u[g-a+1],R=h+b[f-d],z=h+b[f-d+1];n.side(m.t,c,R,y,R),n.side(m.b,c,z,y,z),n.side(m.l,c,R,c,z),n.side(m.r,y,R,y,z),m.d&&m.down&&n.side(m.d,c,R,y,z),m.d&&m.up&&n.side(m.d,c,z,y,R)}for(const e of x){const f=S(e);for(let g=e.c0;g<=e.c1;g++){const m=t.cols.sizeOf(g),c=f.x+t.cols.offsetOf(g)-t.cols.offsetOf(e.c0),y=n.style(e.r0,g).borders;y?.t&&n.side(y.t,c,f.y,c+m,f.y);const R=n.style(e.r1,g).borders;R?.b&&n.side(R.b,c,f.y+f.h,c+m,f.y+f.h)}for(let g=e.r0;g<=e.r1;g++){const m=t.rows.sizeOf(g),c=f.y+t.rows.offsetOf(g)-t.rows.offsetOf(e.r0),y=n.style(g,e.c0).borders;y?.l&&n.side(y.l,f.x,c,f.x,c+m);const R=n.style(g,e.c1).borders;R?.r&&n.side(R.r,f.x+f.w,c,f.x+f.w,c+m)}}if(t.sparklines&&t.sparklines.length>0&&M.engine)for(const[e,f]of At(t)){const g=Math.floor(e/16384),m=e-g*16384;g<d||g>T||m<a||m>w||Ot(o,M.engine,t,f,g,m,r+u[m-a],h+b[g-d],u[m-a+1]-u[m-a],b[g-d+1]-b[g-d],1,{snap:!1,mono:n.mono})}t.sparkRules!==null&&Pt(o,M,t,{r0:d,r1:T,c0:a,c1:w,xs:u,ys:b,ox:r,oy:h,mono:n.mono}),n.reset(),o.textBaseline="alphabetic",o.textAlign="left";const A={c0:a,c1:w};for(let e=a;e<=w;e++){const f=r+u[e-a],g=u[e-a+1]-u[e-a];if(g===0)continue;const m=t.columns[e];if(m!==void 0)for(let c=d;c<=T;c++){const y=m[c>>>Q];if(y===void 0){c|=H;continue}const R=c&H,z=y.kinds[R]&U;if(z===K||D&&t.mergeAt(c,e)!==null)continue;const L=b[c-d+1]-b[c-d];L!==0&&n.text(c,e,z,y.values[R],f,h+b[c-d],g,L,A)}}if(s<a)for(let e=d;e<=T;e++){const f=b[e-d+1]-b[e-d];if(f===0||t.kind(e,a)!==0)continue;let g=0;for(let m=a-1;m>=Math.max(s,a-Et);m--){g+=t.cols.sizeOf(m);const c=t.kind(e,m)&U;if(c!==K){c===v&&t.mergeAt(e,m)===null&&(n.reachX=r,n.text(e,m,c,t.value(e,m),r-g,h+b[e-d],t.cols.sizeOf(m),f,A),n.reachX=null);break}}}for(const e of x){const f=t.kind(e.r0,e.c0)&U;if(f===K)continue;const g=S(e);n.text(e.r0,e.c0,f,t.value(e.r0,e.c0),g.x,g.y,g.w,g.h,A,!0)}t.cellTypes!==null&&wt(n.book,t,d,T,a,w,(e,f)=>{ot(n.ctx,n.book,t,e,f,r+u[f-a],h+b[e-d],u[f-a+1]-u[f-a],b[e-d+1]-b[e-d]),n.reset()}),p&&(n.reset(),p(i),n.reset()),o.restore(),n.reset()}function Kt(n,i,l){const{ctx:s,sheet:p}=n,{headingW:o,headingH:t,titleW:r,titleH:h}=i,d=r+i.bodyW,T=h+i.bodyH;s.strokeStyle=Y,s.lineWidth=$,s.setLineDash([]),n.reset(),s.font=l,s.textBaseline="alphabetic",s.textAlign="center",n.setInk("#000000");const a=3;s.strokeRect(0,0,o+d,t),s.strokeRect(0,0,o,t+T);const w=(b,C,F)=>{let k=F;for(let P=b;P<=C;P++){const x=p.cols.sizeOf(P);x>0&&(s.beginPath(),s.moveTo(k+x,0),s.lineTo(k+x,t),s.stroke(),s.fillText(kt(P),k+x/2,t-a)),k+=x}},u=(b,C,F)=>{let k=F;for(let P=b;P<=C;P++){const x=p.rows.sizeOf(P);x>0&&(s.beginPath(),s.moveTo(0,k+x),s.lineTo(o,k+x),s.stroke(),s.fillText(String(P+1),o/2,k+x-a)),k+=x}};i.titleCols&&w(i.titleCols.c0,i.titleCols.c1,o),w(i.c0,i.c1,o+r),i.titleRows&&u(i.titleRows.r0,i.titleRows.r1,t),u(i.r0,i.r1,t+h),s.textAlign="left"}const _=new Map;function Ut(n){let i=_.get(n);return i===void 0&&(i=Lt(n),_.size>256&&_.clear(),_.set(n,i)),i}function Vt(n,i){switch(n.field){case"page":return String(i.pageNumber+(n.offset??0));case"pages":return String(i.totalPages);case"date":return i.now.toLocaleDateString(i.locale);case"time":return i.now.toLocaleTimeString(i.locale,{hour:"2-digit",minute:"2-digit"});case"file":return i.fileName;case"sheet":return i.sheetName;case"path":return i.filePath;default:return""}}function Yt(n,i){const l=[[]];for(const s of n)(s.field?Vt(s,i):s.text).split(`
|
|
3
|
+
`).forEach((t,r)=>{r>0&&l.push([]),t&&l[l.length-1].push({...s,text:t})});return l}function $t(n,i,l,s,p,o=null){const{setup:t,paper:r}=i,h=t.margins,d=s.pageNumber%2===0,T=x=>t.differentFirst&&s.sheetPage===0?x.first:t.differentOddEven&&d?x.even:x.odd,a=T(t.header),w=T(t.footer);if(!a&&!w)return;const u=s.defaultStyle,b=(t.alignWithMargins?h.left:.7)*72,C=r.width-(t.alignWithMargins?h.right:.7)*72;n.save(),n.textBaseline="alphabetic",n.textAlign="left";const F=(x,D,I,N)=>{const M=x.map(A=>{const e=(A.size??j)*p*(A.script!==0?.66:1),f=E({...u,fontName:A.font??u.fontName,bold:A.bold,italic:A.italic},e);return n.font=f,{run:A,size:e,font:f,width:n.measureText(A.text).width}});let O=0;for(const A of M)O+=A.width;let S=I==="center"?D-O/2:I==="right"?D-O:D;for(const{run:A,size:e,font:f,width:g}of M){n.font=f;const m=t.blackAndWhite?"#000000":A.color??"#000000";n.fillStyle=m;const c=N-(A.script===1?e*.5:A.script===-1?-e*.2:0);n.fillText(A.text,S,c);const y=Math.max(.4,e/14);A.underline&&(n.fillRect(S,c+e*.14,g,y),A.underline===2&&n.fillRect(S,c+e*.14+y*2,g,y)),A.strike&&n.fillRect(S,c-e*.3,g,y),S+=g}},k=x=>{let D=j;return x.length>0&&(D=Math.max(...x.map(I=>I.size??j))),D*p*1.2},P=(x,D,I,N)=>{if(x.length===0)return;const M=Yt(x,s);if(N){let O=h.header*72;for(const S of M){const A=k(S);F(S,D,I,O+A*.8),O+=A}}else{let O=r.height-h.footer*72;for(let S=M.length-1;S>=0;S--){const A=k(M[S]);F(M[S],D,I,O-A*.2),O-=A}}};for(const[x,D]of[[a,!0],[w,!1]]){if(!x)continue;const I=Ut(x),N=o?.[D?"header":"footer"];N!=="L"&&P(I.left,b,"left",D),N!=="C"&&P(I.center,r.width/2,"center",D),N!=="R"&&P(I.right,C,"right",D)}n.restore()}function jt(n,i){n.translate((i.paperW-2*i.originX)/i.scale,0),n.scale(-1,1);const l=Object.prototype.hasOwnProperty.call(n,"fillText"),s=n.fillText;return n.fillText=function(o,t,r){const h=n.measureText(o).width,d=n.textAlign,T=d==="right"||d==="end"?t-h:d==="center"?t-h/2:t;n.save(),n.scale(-1,1),n.textAlign="left",s.call(n,o,-T-h,r),n.restore()},()=>{l?n.fillText=s:delete n.fillText}}function ct(n,i,l,s={}){const{book:p,sheet:o,setup:t}=i,r=p.styles.list[0];n.save(),s.background!==!1&&(n.fillStyle="#ffffff",n.fillRect(0,0,l.paperW,l.paperH)),ut(n,o,l,s.sheetPage??l.index,t);const h={pageNumber:s.pageNumber??l.index+1,totalPages:s.totalPages??i.pageCount,sheetPage:s.sheetPage??l.index,fileName:s.fileName??p.fileName??"",filePath:s.filePath??"",sheetName:o.name,now:s.now??new Date,locale:s.locale,defaultStyle:r};$t(n,i,l,h,t.scaleWithDoc?l.scale:1),n.save(),n.translate(l.originX,l.originY),n.scale(l.scale,l.scale);const d=o.rtl===!0?jt(n,l):null,T=new Xt(n,p,o,t),{headingW:a,headingH:w,titleW:u,titleH:b,titleRows:C,titleCols:F,r0:k,r1:P,c0:x,c1:D,area:I}=l,N=t.gridLines&&!t.draft;t.headings&&Kt(T,l,E(r,r.fontSize));const M=s.objectPainters??null,O=M&&M.length>0?e=>{const f=e.x-o.cols.offsetOf(e.c0),g=e.y-o.rows.offsetOf(e.r0),m={printing:!0,dpr:1,zoom:1,hx:e.x,hy:e.y,cssW:e.x+o.cols.offsetOf(e.c1+1)-o.cols.offsetOf(e.c0),cssH:e.y+o.rows.offsetOf(e.r1+1)-o.rows.offsetOf(e.r0),toScreen:(c,y)=>({x:f+c,y:g+y}),sheet:o};for(const c of M)c(n,m)}:null;if(l.chartBox){if(M){const e={printing:!0,dpr:1,zoom:1,hx:0,hy:0,cssW:l.bodyW,cssH:l.bodyH,toScreen:(f,g)=>({x:f,y:g}),sheet:o,chartBox:l.chartBox};for(const f of M)f(n,e)}n.restore(),n.restore();return}const S=a+u,A=w+b;B(T,{x:S,y:A,r0:k,r1:P,c0:x,c1:D},N,I.c0,O),C&&B(T,{x:S,y:w,r0:C.r0,r1:C.r1,c0:x,c1:D},N,I.c0,O),F&&B(T,{x:a,y:A,r0:k,r1:P,c0:F.c0,c1:F.c1},N,F.c0,O),C&&F&&B(T,{x:a,y:w,r0:C.r0,r1:C.r1,c0:F.c0,c1:F.c1},N,F.c0,O),d?.(),n.restore(),n.restore()}function we(n,i,l,{pxPerPt:s=2,...p}={}){const o=i.at(l);if(o===null)return null;const{page:t,pagination:r}=o;n.width=Math.max(1,Math.round(t.paperW*s)),n.height=Math.max(1,Math.round(t.paperH*s));const h=n.getContext("2d",{alpha:!1});return h.setTransform(s,0,0,s,0,0),ct(h,r,t,{pageNumber:o.pageNumber,totalPages:o.totalPages,sheetPage:o.sheetPage,...p}),o}const Jt=()=>new Promise(n=>setTimeout(n,0)),Zt={gray0625:.0625,gray125:.125,lightGray:.25,mediumGray:.5,darkGray:.75,lightHorizontal:.25,lightVertical:.25,lightDown:.25,lightUp:.25,lightGrid:.44,lightTrellis:.5,darkHorizontal:.5,darkVertical:.5,darkDown:.5,darkUp:.5,darkGrid:.5,darkTrellis:.75};function ft(n){if(!n.pattern)return n.fill;const i=Zt[n.pattern.type]??.5,l=s=>{const p=parseInt(n.pattern.fg.slice(s,s+2),16),o=parseInt(n.fill.slice(s,s+2),16);return Math.round(p*i+o*(1-i)).toString(16).padStart(2,"0")};return`#${l(1)}${l(3)}${l(5)}`}async function ke(n,i,l={}){const{title:s,author:p,subject:o,fonts:t,compress:r,signal:h,onProgress:d,...T}=l,[{PdfWriter:a}]=await Promise.all([import("./pdf.js"),Mt(n)]),w=new a(i,{title:s,author:p,subject:o,fonts:t,compress:r}),u=T.now??new Date;let b=performance.now();for(let C=0;C<n.pageCount;C++){h?.throwIfAborted();const F=n.at(C),{page:k,pagination:P}=F,x=w.beginPage(k.paperW,k.paperH);ct(x,P,k,{...T,now:u,background:!1,pageNumber:F.pageNumber,totalPages:F.totalPages,sheetPage:F.sheetPage}),await w.endPage(),d?.(C+1,n.pageCount),performance.now()-b>12&&(await Jt(),b=performance.now())}return await w.finish(),{pages:w.pageCount,bytes:w.offset,missing:[...w.missing],fontWarnings:w.fontWarnings}}export{Gt as displayText,$t as paintHeaderFooter,we as renderJobPageToCanvas,ct as renderPage,ke as writeJobPdf};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const s={gray0625:["10000000","00000000","00001000","00000000"],gray125:["1000","0000","0010","0000"],lightGray:["1000","0010"],mediumGray:["10","01"],darkGray:["0111","1101"],darkHorizontal:["1111","1111","0000","0000"],darkVertical:["1100"],darkDown:["1100","0110","0011","1001"],darkUp:["0011","0110","1100","1001"],darkGrid:["1100","1100","0011","0011"],darkTrellis:["1111","0110","1111","1001"],lightHorizontal:["1111","0000","0000","0000"],lightVertical:["1000"],lightDown:["1000","0100","0010","0001"],lightUp:["0001","0010","0100","1000"],lightGrid:["1111","1000","1000","1000"],lightTrellis:["1001","0110","0110","1001"]},y=[["Solid",""],["75% Gray","darkGray"],["50% Gray","mediumGray"],["25% Gray","lightGray"],["12.5% Gray","gray125"],["6.25% Gray","gray0625"],["Horizontal Stripe","darkHorizontal"],["Vertical Stripe","darkVertical"],["Reverse Diagonal Stripe","darkDown"],["Diagonal Stripe","darkUp"],["Diagonal Crosshatch","darkGrid"],["Thick Diagonal Crosshatch","darkTrellis"],["Thin Horizontal Stripe","lightHorizontal"],["Thin Vertical Stripe","lightVertical"],["Thin Reverse Diagonal Stripe","lightDown"],["Thin Diagonal Stripe","lightUp"],["Thin Horizontal Crosshatch","lightGrid"],["Thin Diagonal Crosshatch","lightTrellis"]],g=new Map;function p(c,a,r){const i=s[a.type];if(!i)return null;const o=`${a.type}|${a.fg}|${r}`;let t=g.get(o);if(t===void 0){const l=document.createElement("canvas");l.width=i[0].length*r,l.height=i.length*r;const n=l.getContext("2d");n.fillStyle=a.fg,i.forEach((h,d)=>{for(let e=0;e<h.length;e++)h[e]==="1"&&n.fillRect(e*r,d*r,r,r)}),t=c.createPattern(l,"repeat"),g.set(o,t)}return t}export{s as FILL_PATTERNS,y as PATTERN_LABELS,p as patternFill};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{child as O,children as M,parseTree as E,unescapeXml as I}from"../io/xml-scan.js";import{relsPathOf as B,resolveTarget as N}from"../io/package-paths.js";import{XML_HEAD as w,parseXml as z}from"../objects/dml.js";import{escapeMarkup as x,xmlLiteralText as y}from"../io/xml-escape.js";import{parseRels as V}from"../objects/drawing-xml.js";const k="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",q="http://schemas.openxmlformats.org/markup-compatibility/2006",W="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",X="http://schemas.microsoft.com/office/drawing/2010/main",ce="http://schemas.openxmlformats.org/officeDocument/2006/relationships/ctrlProp",xe="http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing",me="application/vnd.ms-excel.controlproperties+xml",fe="application/vnd.openxmlformats-officedocument.vmlDrawing",$={button:{objectType:"Button",label:"Button",vml:"Button"},spin:{objectType:"Spin",label:"Spinner",vml:"Spin"},scroll:{objectType:"Scroll",label:"Scroll Bar",vml:"Scroll"},list:{objectType:"List",label:"List Box",vml:"List"},check:{objectType:"CheckBox",label:"Check Box",vml:"Checkbox"},radio:{objectType:"Radio",label:"Option Button",vml:"Radio"},label:{objectType:"Label",label:"Label",vml:"Label"},group:{objectType:"GBox",label:"Group Box",vml:"GBox"},drop:{objectType:"Drop",label:"Drop Down",ui:"Combo Box",vml:"Drop"}},H=Object.fromEntries(Object.entries($).map(([e,o])=>[o.objectType,e])),b=Object.fromEntries(Object.entries($).map(([e,o])=>[o.vml,e]));function de(e){const o=$[e].objectType;switch(e){case"button":case"label":return{objectType:o,lockText:"1"};case"check":case"radio":return{objectType:o,lockText:"1",noThreeD:"1",...e==="radio"?{firstButton:"1"}:{}};case"group":return{objectType:o,noThreeD:"1"};case"spin":return{objectType:o,dx:"15",inc:"1",max:"100",min:"0",page:"10",val:"0"};case"scroll":return{objectType:o,dx:"15",horiz:"1",inc:"1",max:"100",min:"0",page:"10",val:"0"};case"list":return{objectType:o,dx:"15",noThreeD:"1",sel:"0",val:"0"};default:return{objectType:o,dropStyle:"combo",dx:"15",noThreeD:"1",sel:"0",val:"0",dropLines:"8"}}}function Y(e){return H[e?.objectType]??null}function G(e){const o=z(e),t={...o.root.a};delete t.xmlns;for(const s of Object.keys(t))s.startsWith("xmlns")&&delete t[s];const n=M(O(o.root,"itemLst"),"item").map(s=>s.a.val??"");return{attrs:t,items:n.length?n:void 0}}function he(e){const o=Object.entries(e.attrs).filter(([,n])=>n!=null).map(([n,s])=>` ${n}="${x(s)}"`).join(""),t=e.items?.length?`<itemLst>${e.items.map(n=>`<item val="${x(n)}"/>`).join("")}</itemLst>`:"";return`${w}<formControlPr xmlns="${k}"${o}${t?`>${t}</formControlPr>`:"/>"}`}const U=/<v:(?:shape|rect|roundrect|oval|line)\b[^>]*\bid="_x0000_s(\d+)"[\s\S]*?<\/v:(?:shape|rect|roundrect|oval|line)>/g;function g(e,o){const t=new RegExp(`<x:${o}>([\\s\\S]*?)</x:${o}>`).exec(e);return t?t[1].trim():void 0}function J(e,o){const t=b[o],n={objectType:$[t].objectType},s={FmlaLink:"fmlaLink",FmlaRange:"fmlaRange",Val:"val",Min:"min",Max:"max",Inc:"inc",Page:"page",Dx:"dx",Sel:"sel",DropLines:"dropLines",Checked:"checked",FmlaTxbx:"fmlaTxbx",FmlaMacro:"macro"};for(const[p,m]of Object.entries(s)){const l=g(e,p);l!==void 0&&(n[m]=I(l))}/<x:Horiz\s*\/>/.test(e)&&(n.horiz="1"),/<x:NoThreeD2?\s*\/>/.test(e)&&(n.noThreeD="1"),/<x:FirstButton\s*\/>/.test(e)&&(n.firstButton="1");const r=g(e,"SelType");r&&r!=="Single"&&(n.selType=r.toLowerCase());const a=g(e,"DropStyle");return a&&(n.dropStyle=a.toLowerCase()),n}function K(e){const o=new Map;for(const t of e.matchAll(U)){const n=t[0],s=/ObjectType="(\w+)"/.exec(n)?.[1];!s||!b[s]||o.set(Number(t[1]),{type:b[s],attrs:J(n,s),printObject:g(n,"PrintObject")!=="False",disabled:/<x:Disabled>True/.test(n)||/<x:Disabled\s*\/>/.test(n)})}return o}async function Q(e){const o=e.pipeThrough(new TextDecoderStream).getReader();let t="";const n=1<<20;for(;;){const{value:a,done:p}=await o.read();if(p)break;t+=a,t.length>n*2&&(t=t.slice(-n))}const s=new Map,r=t.lastIndexOf("<controls");if(r<0)return s;for(const a of t.slice(r).matchAll(/<control\b([^>]*)>/g)){const p=/shapeId="(\d+)"/.exec(a[1])?.[1],m=/r:id="([^"]+)"/.exec(a[1])?.[1];p&&m&&s.set(Number(p),{rid:m,name:/name="([^"]*)"/.exec(a[1])?.[1]})}return s}async function ue(e,o){const t=B(o);if(!e.has(t))return null;const n=V(await e.bytes(t)),s=l=>N(o,l),r=n.filter(l=>/\/ctrlProp$/.test(l.type)),a=n.find(l=>/\/vmlDrawing$/.test(l.type));if(r.length===0&&!a)return null;const p=new Map,m=a?s(a.target):null;if(m&&e.has(m))for(const[l,i]of K(await e.text(m)))p.set(l,{...i,vmlPath:m});if(r.length>0){const l=await Q(await e.stream(o)),i=new Map(r.map(d=>[d.id,s(d.target)]));for(const[d,h]of l){const c=i.get(h.rid);if(!c||!e.has(c))continue;const f=G(await e.bytes(c)),u=Y(f.attrs);if(!u)continue;const T=p.get(d);p.set(d,{...T??{},type:u,attrs:f.attrs,items:f.items,path:c,rid:h.rid,vmlPath:m,name:h.name})}}return p.size>0?p:null}const _='<v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><v:stroke joinstyle="miter"/><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"/><v:f eqn="sum @0 1 0"/><v:f eqn="sum 0 0 @1"/><v:f eqn="prod @2 1 2"/><v:f eqn="prod @3 21600 pixelWidth"/><v:f eqn="prod @3 21600 pixelHeight"/><v:f eqn="sum @0 0 1"/><v:f eqn="prod @6 1 2"/><v:f eqn="prod @7 21600 pixelWidth"/><v:f eqn="sum @8 21600 0"/><v:f eqn="prod @7 21600 pixelHeight"/><v:f eqn="sum @10 21600 0"/></v:formulas><v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/><o:lock v:ext="edit" aspectratio="t"/></v:shapetype>';function L(e,o){const t=e.rect,n=`position:absolute;margin-left:${t.x}pt;margin-top:${t.y}pt;width:${t.w}pt;height:${t.h}pt;z-index:${o};visibility:visible`;return`<v:shape id="Picture_x0020_${e.shapeId}" o:spid="_x0000_s${e.shapeId}" type="#_x0000_t75" style="${n}"><v:imagedata o:relid="${x(e.relId)}" o:title=""/><x:ClientData ObjectType="Pict"><x:SizeWithCells/><x:Anchor>${S(e.anchor)}</x:Anchor><x:FmlaPict>${x(e.range)}</x:FmlaPict><x:CF>Pict</x:CF><x:Camera/></x:ClientData></v:shape>`}const P='<v:shapetype id="_x0000_t201" coordsize="21600,21600" o:spt="201" path="m,l,21600r21600,l21600,xe"><v:stroke joinstyle="miter"/><v:path shadowok="f" o:extrusionok="f" strokeok="f" fillok="f" o:connecttype="rect"/><o:lock v:ext="edit" shapetype="t"/></v:shapetype>';function v(e){return Math.round(e/12700)}function S(e){return`${e.from.col}, ${v(e.from.colOff)}, ${e.from.row}, ${v(e.from.rowOff)}, ${e.to.col}, ${v(e.to.colOff)}, ${e.to.row}, ${v(e.to.rowOff)}`}const $e=e=>e?"True":"False";function D(e,o){const t=e.attrs,n=e.rect,s=`position:absolute;margin-left:${n.x}pt;margin-top:${n.y}pt;width:${n.w}pt;height:${n.h}pt;z-index:${o}`,r=[];if(e.moveWithCells===!1&&r.push("<x:MoveWithCells/>"),e.sizeWithCells===!1&&r.push("<x:SizeWithCells/>"),r.push(`<x:Anchor>${S(e.anchor)}</x:Anchor>`),e.print===!1&&r.push("<x:PrintObject>False</x:PrintObject>"),(e.type==="check"||e.type==="radio")&&r.push("<x:AutoFill>False</x:AutoFill>","<x:AutoLine>False</x:AutoLine>","<x:TextVAlign>Center</x:TextVAlign>"),e.type==="button"&&r.push("<x:AutoFill>False</x:AutoFill>","<x:TextHAlign>Center</x:TextHAlign>","<x:TextVAlign>Center</x:TextVAlign>"),(e.type==="label"||e.type==="drop")&&r.push("<x:AutoFill>False</x:AutoFill>"),t.fmlaLink&&r.push(`<x:FmlaLink>${x(t.fmlaLink)}</x:FmlaLink>`),t.fmlaTxbx&&r.push(`<x:FmlaTxbx>${x(t.fmlaTxbx)}</x:FmlaTxbx>`),e.macro&&r.push(`<x:FmlaMacro>${x(e.macro)}</x:FmlaMacro>`),(e.type==="check"||e.type==="radio")&&(t.checked&&t.checked!=="Unchecked"&&t.checked!=="0"&&r.push(`<x:Checked>${t.checked==="Mixed"||t.checked==="2"?2:1}</x:Checked>`),t.noThreeD&&r.push("<x:NoThreeD/>"),t.firstButton&&r.push("<x:FirstButton/>")),e.type==="group"&&t.noThreeD&&r.push("<x:NoThreeD/>"),(e.type==="spin"||e.type==="scroll"||e.type==="list"||e.type==="drop")&&(r.push(`<x:Val>${x(t.val??0)}</x:Val>`,`<x:Min>${x(t.min??0)}</x:Min>`,`<x:Max>${x(t.max??100)}</x:Max>`,`<x:Inc>${x(t.inc??1)}</x:Inc>`,`<x:Page>${x(t.page??10)}</x:Page>`),t.horiz&&r.push("<x:Horiz/>"),r.push(`<x:Dx>${x(t.dx??15)}</x:Dx>`)),e.type==="list"||e.type==="drop"){t.fmlaRange&&r.push(`<x:FmlaRange>${x(t.fmlaRange)}</x:FmlaRange>`),r.push(`<x:Sel>${x(t.sel??0)}</x:Sel>`),t.noThreeD&&r.push("<x:NoThreeD2/>");const i=t.selType??"single";r.push(`<x:SelType>${i[0].toUpperCase()}${i.slice(1)}</x:SelType>`,"<x:LCT>Normal</x:LCT>"),e.type==="drop"&&r.push(`<x:DropStyle>${(t.dropStyle??"combo")[0].toUpperCase()}${(t.dropStyle??"combo").slice(1)}</x:DropStyle>`,`<x:DropLines>${x(t.dropLines??8)}</x:DropLines>`)}let a="";const p=e.type==="button"||e.type==="check"||e.type==="radio"||e.type==="label"||e.type==="group";p&&(a=`<v:textbox style="mso-direction-alt:auto" o:singleclick="f"><div style="text-align:${e.type==="button"?"center":"left"};direction:ltr"><font face="Calibri" size="220" color="auto">${y(e.text??"")}</font></div></v:textbox>`);const m=e.type==="button"?' fillcolor="#f0f0f0 [67]"':e.type==="check"||e.type==="radio"?' filled="f" stroked="f"':e.type==="label"?' filled="f"':"",l=p?'<o:lock v:ext="edit" rotation="t"/>':'<o:lock v:ext="edit" rotation="t" text="t"/>';return`<v:shape id="_x0000_s${e.shapeId}" type="#_x0000_t201" style="${s}"${m} o:insetmode="auto">${l}${a}<x:ClientData ObjectType="${$[e.type].vml}">${r.join("")}</x:ClientData></v:shape>`}function j(e,o,t=[]){const n=e.map((r,a)=>D(r,a+1)).join(""),s=t.map((r,a)=>L(r,e.length+a+1)).join("");return`<xml xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"><o:shapelayout v:ext="edit"><o:idmap v:ext="edit" data="${o}"/></o:shapelayout>${P}${t.length?_:""}${n}${s}</xml>`}function Z(e,o,t,n=[]){let s=e.replace(/<v:(shape|rect|roundrect|oval|line)\b(?:(?!<\/v:\1>)[\s\S])*?<\/v:\1>/g,l=>{const i=/ObjectType="(\w+)"/.exec(l)?.[1];return i==="Pict"&&/<x:Camera\s*\/>/.test(l)||i&&b[i]?"":l});const r=new Set([...o,...n].map(l=>l.shapeId));let a=Math.max(1024,...r);for(const l of s.matchAll(/_x0000_s(\d+)/g))a=Math.max(a,Number(l[1]));s=s.replace(/id="_x0000_s(\d+)"/g,(l,i)=>r.has(Number(i))?`id="_x0000_s${++a}"`:l),o.length&&!/id="_x0000_t201"/.test(s)&&(s=s.replace("</xml>",`${P}</xml>`)),n.length&&!/id="_x0000_t75"/.test(s)&&(s=s.replace("</xml>",`${_}</xml>`)),t!==void 0&&(s=s.replace(/(<o:idmap\b[^>]*data=")([^"]*)(")/,(l,i,d,h)=>{const c=new Set(String(d).split(",").filter(Boolean));for(const f of String(t).split(","))c.add(f);return`${i}${[...c].join(",")}${h}`}));let p=1;for(const l of s.matchAll(/z-index:(\d+)/g))p=Math.max(p,Number(l[1])+1);const m=n.map((l,i)=>L(l,p+o.length+i)).join("");return s.replace("</xml>",`${o.map((l,i)=>D(l,p+i)).join("")}${m}</xml>`)}const F=(e,o)=>`<${e}><xdr:col>${o.col}</xdr:col><xdr:colOff>${Math.round(o.colOff)}</xdr:colOff><xdr:row>${o.row}</xdr:row><xdr:rowOff>${Math.round(o.rowOff)}</xdr:rowOff></${e}>`;function ee(e){const o=e.moveWithCells===!1?"":' moveWithCells="1"',t=e.sizeWithCells===!1?"":' sizeWithCells="1"',n=[' defaultSize="0"',e.print===!1?' print="0"':"",e.locked===!1?' locked="0"':"",e.type==="check"||e.type==="radio"||e.type==="button"||e.type==="label"||e.type==="drop"?' autoFill="0"':"",e.type==="check"||e.type==="radio"?' autoLine="0"':"",' autoPict="0"',e.macro?` macro="${x(e.macro)}"`:"",e.altText?` altText="${y(e.altText)}"`:""].join("");return`<mc:AlternateContent><mc:Choice Requires="x14"><control shapeId="${e.shapeId}" r:id="${x(e.rid)}" name="${x(e.name)}"><controlPr${n}><anchor${o}${t}>${F("from",e.anchor.from)}${F("to",e.anchor.to)}</anchor></controlPr></control></mc:Choice></mc:AlternateContent>`}function te(e){return e.length===0?"":`<mc:AlternateContent xmlns:mc="${q}" xmlns:x14="${k}" xmlns:xdr="${W}"><mc:Choice Requires="x14"><controls>${e.map(ee).join("")}</controls></mc:Choice></mc:AlternateContent>`}function oe(e){return e.replace(/<mc:AlternateContent\b[^>]*>\s*<mc:Choice\b[^>]*>\s*<controls\b[\s\S]*?<\/controls>\s*<\/mc:Choice>\s*(?:<mc:Fallback\b[\s\S]*?<\/mc:Fallback>\s*)?<\/mc:AlternateContent>/,"").replace(/<controls\b[\s\S]*?<\/controls>/,"")}const ne=/<(?:legacyDrawingHF|picture|oleObjects|mc:AlternateContent|controls|webPublishItems|tableParts|extLst)\b|<\/worksheet>/,re=/<(?:webPublishItems|tableParts|extLst)\b|<\/worksheet>/;function R(e,o,t){const n=o.exec(e);return n?e.slice(0,n.index)+t+e.slice(n.index):e+t}async function ye(e,o,t){const{source:n,relsName:s,addRel:r,extraParts:a}=t;let p=oe(e);const m=n?.zip.has(s)?await n.zip.text(s):"";for(const c of o.parts)a.push({path:c.path,xml:c.xml});for(const c of o.newRels)m.includes(`Id="${c.id}"`)||r(c.id,"ctrlProp",c.target,!1);const l=/<legacyDrawing\b[^>]*r:id="([^"]+)"/.exec(p)?.[1];let i=null;if(l){const c=`${m}${(t.pendingRels??[]).join("")}`,f=new RegExp(`<Relationship\\b[^>]*Id="${l}"[^>]*/>`).exec(c),u=f&&/Target="([^"]+)"/.exec(f[0])?.[1];u&&(i=t.resolveTarget(t.part,u))}const d=i?a.find(c=>c.path===i):null,h=o.cameras??[];if(i){const c=d?d.xml:n?.zip.has(i)?await n.zip.text(i):null,f=c?Z(c,o.items,o.idmap,h):j(o.items,o.idmap,h);d?d.xml=f:a.push({path:i,xml:f})}else(o.items.length>0||h.length>0)&&(i=o.vmlPath,a.push({path:i,xml:j(o.items,o.idmap,h)}),m.includes(`Id="${o.vmlRelId}"`)||r(o.vmlRelId,"vmlDrawing",t.relativeTo(t.part,i),!1),p=R(p,ne,`<legacyDrawing r:id="${o.vmlRelId}"/>`));if(h.length>0){const c=i.lastIndexOf("/"),f=`${i.slice(0,c)}/_rels/${i.slice(c+1)}.rels`,T=(n?.zip.has(f)?await n.zip.text(f):`${w}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>`).replace(/<Relationship\b[^>]*Id="rIdCam\d+"[^>]*\/>/g,""),A=h.map(C=>`<Relationship Id="${x(C.relId)}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="${x(t.relativeTo(i,C.imagePath))}"/>`).join("");a.push({path:f,xml:T.replace("</Relationships>",`${A}</Relationships>`)})}return o.items.length>0&&(p=R(p,re,te(o.items))),p}function be(e,o){return new RegExp(`id="_x0000_s${o}"`).test(e)}function ge(e,o){return`<xdr:sp macro="" textlink=""><xdr:nvSpPr><xdr:cNvPr id="${e.id}" name="${y(e.name??"")}" hidden="1"${e.descr?` descr="${y(e.descr)}"`:""}><a:extLst><a:ext uri="{63B3BB69-23CF-44E3-9099-C40C66FF867C}"><a14:compatExt xmlns:a14="${X}" spid="_x0000_s${e.id}"/></a:ext></a:extLst></xdr:cNvPr><xdr:cNvSpPr/></xdr:nvSpPr><xdr:spPr bwMode="auto"><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/><a:ln><a:noFill/></a:ln></xdr:spPr>${o}</xdr:sp>`}export{$ as CONTROL_TYPES,me as CTRL_CONTENT_TYPE,ce as CTRL_REL,X as NS_A14,q as NS_MC,k as NS_X14,W as NS_XDR,fe as VML_CONTENT_TYPE,xe as VML_REL,ye as applyControls,Y as controlTypeOf,te as controlsListXml,he as ctrlPropXml,de as newControlAttrs,j as newVmlXml,G as parseCtrlProp,E as parseTree,K as parseVmlControls,Z as patchVmlControls,ge as placeholderSpXml,ue as readSheetControls,oe as removeControlsList,Q as scanControlsList,L as vmlCameraXml,be as vmlHasShape,D as vmlShapeXml};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{withHeaderPicture as k}from"../api/watermark-xml.js";import{getPageSetup as y,parseHeaderFooter as b}from"../print/page-setup.js";const p=t=>String(t??"").slice(String(t??"").indexOf(",")+1);function m(t){return t.watermarks??[]}function C(t,a){t.watermarks=a.map(e=>({page:"all",x:0,y:0,...e})),t.watermarkImages=null;const r=t.watermarks.length===1&&(t.watermarks[0].page??"all")==="all"?t.watermarks[0]:null,i=r&&/^data:image\/(png|jpeg|gif|bmp);/.test(r.src??"");if(i||t.printWatermark?.linked){const e=y(t);e.header={...e.header,odd:k(e.header.odd,!!i)},t.printWatermark=i?{url:r.src,opacity:1,fit:"center",onScreen:!1,linked:!0,width:r.width,height:r.height}:null,t.printWatermarkChanged=!0,t.pageSetupChanged=!0}}function d(t){const a=t.printWatermark;if(!a?.url)return null;const r=p(a.url);return m(t).some(i=>p(i.src)===r)?null:a}function W(t,a){const r=t.page??"all";return r==="all"||r===""?!0:String(r).split(",").map(i=>Number(i.trim())).includes(a)}const u=new WeakMap;async function I(t,a=H){for(const e of[d(t),...Object.values(t.headerPictures??{})])if(!(!e||e.image))try{e.image=await a(e.url)}catch{e.image=null}const r=m(t);if(r.length===0)return;if(u.has(t)){await u.get(t);return}const i=Promise.all(r.map(async e=>{if(!(e.image||!e.src))try{e.image=await a(e.src)}catch{e.image=null}}));u.set(t,i),await i,u.delete(t)}async function H(t){const a=await fetch(t);return createImageBitmap(await a.blob())}const P=14/15;function S(t,a,r){const i=[],e=d(t);e&&i.push({id:"CH",picture:e});const s=t.headerPictures;if(!s||!r)return i;const n=r.differentFirst&&a===0,o=r.differentOddEven&&(a+1)%2===0,f=n?"FIRST":o?"EVEN":"",l=c=>n?c.first:o?c.even:c.odd,g={L:"left",C:"center",R:"right"};for(const[c,h]of Object.entries(s)){if(c.slice(2)!==f)continue;b(l(c[1]==="H"?r.header:r.footer))[g[c[0]]].some(w=>w.field==="picture")&&i.push({id:c,picture:h})}return i}function j(t,a,r,i,e){const s=e?.margins??{left:.7,right:.7,header:.3,footer:.3};for(const{id:n,picture:o}of S(a,i,e)){if(!o.image)continue;const f=o.width??o.image.width*.75,l=(o.height??o.image.height*.75)*P,g=n[0]==="L"?s.left*72:n[0]==="R"?r.paperW-s.right*72-f:(r.paperW-f)/2,c=n[1]==="H"?s.header*72:r.paperH-s.footer*72-l;t.save(),(o.opacity??1)<1&&(t.globalAlpha*=o.opacity),t.drawImage(o.image,g,c,f,l),t.restore()}for(const n of m(a)){if(!n.image||!W(n,i))continue;const o=n.width??n.image.width*.75,f=n.height??n.image.height*.75;t.drawImage(n.image,n.x??0,n.y??0,o,f)}}export{W as appliesToPage,j as paintWatermarks,I as prepareWatermarks,C as setWatermarks,m as watermarksOf};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EXT as k,NS as W}from"./format.js";import{parseNode as K}from"../pivot/xml.js";import{xmlAttr as _}from"../io/xml-escape.js";import{dxfXml as G,parseDxfs as Y}from"../io/xlsx-tail.js";import{resolveColor as q}from"../io/xlsx-styles.js";import{bandRow as J}from"../core/tables.js";const j="{46F421CA-312F-682f-3DD2-61675219B42D}",U="{A0A4C193-F2C1-4fcb-8827-314CF55A85BB}",V=(e,l)=>e?.c?.find(i=>i.n===l)??null,Q=(e,l)=>e?e.c.filter(i=>i.n===l):[],v=e=>e.slice(e.indexOf(":")+1),Z=["wholeTable","headerRow","totalRow","firstColumn","lastColumn","firstRowStripe","secondRowStripe","firstColumnStripe","secondColumnStripe","firstHeaderCell","lastHeaderCell","firstTotalCell","lastTotalCell"],ee=["wholeTable","pageFieldLabels","pageFieldValues","firstColumnStripe","secondColumnStripe","firstRowStripe","secondRowStripe","firstColumn","headerRow","firstHeaderCell","firstSubtotalColumn","secondSubtotalColumn","thirdSubtotalColumn","blankRow","firstSubtotalRow","secondSubtotalRow","thirdSubtotalRow","firstColumnSubheading","secondColumnSubheading","thirdColumnSubheading","firstRowSubheading","secondRowSubheading","thirdRowSubheading","totalRow","lastColumn"],me=["unselectedItemWithData","selectedItemWithData","unselectedItemWithNoData","selectedItemWithNoData","hoveredUnselectedItemWithData","hoveredSelectedItemWithData","hoveredUnselectedItemWithNoData","hoveredSelectedItemWithNoData"],Se=["selectionLabel","timeLevel","periodLabel1","periodLabel2","selectedTimeBlock","unselectedTimeBlock","selectedTimeBlockSpace"];class te{constructor(){this.tableStyles=[],this.slicerStyles=[],this.timelineStyles=[],this.slicerDxfs=[],this.timelineDxfs=[],this.defaultTableStyle="TableStyleMedium2",this.defaultPivotStyle="PivotStyleLight16",this.defaultSlicerStyle="SlicerStyleLight1",this.defaultTimelineStyle="TimeSlicerStyleLight1",this.dirty=!1,this.version=0}find(l){return this.tableStyles.find(i=>i.name===l)??null}forTables(){return this.tableStyles.filter(l=>l.table)}forPivots(){return this.tableStyles.filter(l=>l.pivot)}setTableStyle(l,i,{table:d=!0,pivot:r=!1,elements:u={}}){const s=Object.entries(u).map(([o,f])=>({type:o,dxfId:le(l,f),...f.size?{size:f.size}:{}})),t={name:i,table:d,pivot:r,elements:s},a=this.tableStyles.findIndex(o=>o.name===i);return a>=0?this.tableStyles[a]=t:this.tableStyles.push(t),this.dirty=!0,this.version++,t}setSlicerStyle(l,i,{whole:d=null,header:r=null,elements:u={}}){this.setTableStyle(l,i,{table:!1,pivot:!1,elements:{...d?{wholeTable:d}:{},...r?{headerRow:r}:{}}});const s={name:i,elements:Object.entries(u).map(([a,o])=>({type:a,dxfId:this.slicerDxfs.push(o)-1}))},t=this.slicerStyles.findIndex(a=>a.name===i);return t>=0?this.slicerStyles[t]=s:this.slicerStyles.push(s),this.dirty=!0,s}setTimelineStyle(l,i,{whole:d=null,header:r=null,elements:u={}}){this.setTableStyle(l,i,{table:!1,pivot:!1,elements:{...d?{wholeTable:d}:{},...r?{headerRow:r}:{}}});const s={name:i,elements:Object.entries(u).map(([a,o])=>({type:a,dxfId:this.timelineDxfs.push(o)-1}))},t=this.timelineStyles.findIndex(a=>a.name===i);return t>=0?this.timelineStyles[t]=s:this.timelineStyles.push(s),this.dirty=!0,s}setDefaultTableStyle(l){return this.defaultTableStyle===l?!1:(this.defaultTableStyle=l,this.dirty=!0,this.version++,!0)}removeStyle(l){this.tableStyles=this.tableStyles.filter(i=>i.name!==l),this.slicerStyles=this.slicerStyles.filter(i=>i.name!==l),this.timelineStyles=this.timelineStyles.filter(i=>i.name!==l),this.dirty=!0,this.version++}savePlan(){return this.dirty?{tableStyles:this.tableStyles,slicerStyles:this.slicerStyles,timelineStyles:this.timelineStyles,slicerDxfs:this.slicerDxfs.map(G),timelineDxfs:this.timelineDxfs.map(G),defaultTableStyle:this.defaultTableStyle,defaultPivotStyle:this.defaultPivotStyle,defaultSlicerStyle:this.defaultSlicerStyle,defaultTimelineStyle:this.defaultTimelineStyle}:null}}function le(e,l){e.dxfs??=[];const{size:i,...d}=l;return e.dxfs.push(d),e.dxfs.length-1}const B=e=>(e?e.c.filter(l=>typeof l!="string"):[]).map(l=>({type:l.a.type,dxfId:Number(l.a.dxfId??-1),...l.a.size?{size:Number(l.a.size)}:{}})).filter(l=>l.dxfId>=0);function he(e,l=[]){const i=new te,d=typeof e=="string"?e:new TextDecoder().decode(e),r=t=>{const a=new RegExp(`<${t}:dxfs\\b[^>]*>([\\s\\S]*?)</${t}:dxfs>`).exec(d);return a?Y(new TextEncoder().encode(`<r><dxfs>${a[1]}</dxfs></r>`),o=>o?q(o,l):null):[]};i.slicerDxfs=r("x14"),i.timelineDxfs=r("x15");const u=K(e),s=V(u,"tableStyles");s&&(i.defaultTableStyle=s.a.defaultTableStyle??i.defaultTableStyle,i.defaultPivotStyle=s.a.defaultPivotStyle??i.defaultPivotStyle,i.tableStyles=Q(s,"tableStyle").map(t=>({name:t.a.name,table:t.a.table!=="0",pivot:t.a.pivot!=="0",elements:B(t)})));for(const t of V(u,"extLst")?.c??[])if(t.a?.uri===k.slicerStyles){const a=t.c.find(o=>v(o.n)==="slicerStyles");a&&(i.defaultSlicerStyle=a.a.defaultSlicerStyle??i.defaultSlicerStyle,i.slicerStyles=a.c.filter(o=>v(o.n)==="slicerStyle").map(o=>({name:o.a.name,elements:B(o.c.find(f=>v(f.n)==="slicerStyleElements"))})))}else if(t.a?.uri===k.timelineStyles){const a=t.c.find(o=>v(o.n)==="timelineStyles");a&&(i.defaultTimelineStyle=a.a.defaultTimelineStyle??i.defaultTimelineStyle,i.timelineStyles=a.c.filter(o=>v(o.n)==="timelineStyle").map(o=>({name:o.a.name,elements:B(o.c.find(f=>v(f.n)==="timelineStyleElements"))})))}return i}const H=(e,l)=>`<${e} type="${l.type}"${l.size?` size="${l.size}"`:""} dxfId="${l.dxfId}"/>`;function be(e,l){if(!l)return e;const i=n=>(l.slicerStyles.find(h=>h.name===n)?.elements.length??0)+(l.timelineStyles.find(h=>h.name===n)?.elements.length??0),d=`<tableStyles count="${l.tableStyles.length}" defaultTableStyle="${_(l.defaultTableStyle)}" defaultPivotStyle="${_(l.defaultPivotStyle)}"${l.tableStyles.length?`>${l.tableStyles.map(n=>`<tableStyle name="${_(n.name)}"${n.table?"":' table="0"'}${n.pivot?"":' pivot="0"'} count="${n.elements.length+i(n.name)}">${n.elements.map(h=>H("tableStyleElement",h)).join("")}</tableStyle>`).join("")}</tableStyles>`:"/>"}`;let r=e;if(/<tableStyles\b/.test(r))r=r.replace(/<tableStyles\b[^>]*?\/>|<tableStyles\b[\s\S]*?<\/tableStyles>/,d);else{const n=/<(?:colors|extLst)\b|<\/styleSheet>/.exec(r);r=`${r.slice(0,n.index)}${/<dxfs\b/.test(r)?"":'<dxfs count="0"/>'}${d}${r.slice(n.index)}`}const u=n=>{r=r.replace(new RegExp(`<ext\\b[^>]*uri="${n.replace(/[{}-]/g,"\\$&")}"[^>]*>[\\s\\S]*?</ext>`),"")};u(k.slicerStyles),u(k.timelineStyles),u(j),u(U);const s=(n,h,b,m)=>m.length?`<ext uri="${n}" xmlns:${h}="${b}"><${h}:dxfs count="${m.length}">${m.join("")}</${h}:dxfs></ext>`:"",t=`${s(j,"x14",W.x14,l.slicerDxfs)}`,a=`${s(U,"x15",W.x15,l.timelineDxfs)}`,o=`<ext uri="${k.slicerStyles}" xmlns:x14="${W.x14}"><x14:slicerStyles defaultSlicerStyle="${_(l.defaultSlicerStyle)}"${l.slicerStyles.length?`>${l.slicerStyles.map(n=>`<x14:slicerStyle name="${_(n.name)}"><x14:slicerStyleElements>${n.elements.map(h=>H("x14:slicerStyleElement",h)).join("")}</x14:slicerStyleElements></x14:slicerStyle>`).join("")}</x14:slicerStyles>`:"/>"}</ext>`,f=`<ext uri="${k.timelineStyles}" xmlns:x15="${W.x15}"><x15:timelineStyles defaultTimelineStyle="${_(l.defaultTimelineStyle)}"${l.timelineStyles.length?`>${l.timelineStyles.map(n=>`<x15:timelineStyle name="${_(n.name)}"><x15:timelineStyleElements>${n.elements.map(h=>H("x15:timelineStyleElement",h)).join("")}</x15:timelineStyleElements></x15:timelineStyle>`).join("")}</x15:timelineStyles>`:"/>"}</ext>`;return/<\/extLst>\s*<\/styleSheet>/.test(r)?r=r.replace(/<\/extLst>(\s*<\/styleSheet>)/,`${t}${o}${a}${f}</extLst>$1`):r=r.replace("</styleSheet>",`<extLst>${t}${o}${a}${f}</extLst></styleSheet>`),r}const O=(e,l,i,d=e.dxfs)=>{const r=l?.elements.find(u=>u.type===i);return r?d?.[r.dxfId]??{}:null},N=e=>{const l=e?.borders;return l?l.b?.color??l.t?.color??l.l?.color??l.r?.color??null:null},ie=["fill","color","bold","italic","underline","strike"],E=(e,l)=>{if(l)for(const i of ie)l[i]!==void 0&&(e[i]=l[i])},X=(e,l,i)=>e%(l+i)<l?0:1;function ye(e,l,i){const d=l?.find(i);if(!d)return null;const r=s=>d.elements.find(t=>t.type===s)?.size??1,u=Object.fromEntries(Z.map(s=>[s,O(e,d,s)]));return se(u,[r("firstRowStripe"),r("secondRowStripe")],[r("firstColumnStripe"),r("secondColumnStripe")],!0)}function se(e,l=[1,1],i=[1,1],d=!1){const r=(t,a,o)=>{const f={},n=t.r0+t.headerRows,h=t.r1-t.totalsRows,b=a>=n&&a<=h;return E(f,e.wholeTable),b&&(t.showColumnStripes&&E(f,X(o-t.c0,i[0],i[1])===0?e.firstColumnStripe:e.secondColumnStripe),t.showRowStripes!==!1&&E(f,X(J(t,a),l[0],l[1])===0?e.firstRowStripe:e.secondRowStripe)),t.showFirstColumn&&o===t.c0&&E(f,e.firstColumn),t.showLastColumn&&o===t.c1&&E(f,e.lastColumn),a<n?(E(f,e.headerRow),o===t.c0&&t.showFirstColumn&&E(f,e.firstHeaderCell),o===t.c1&&t.showLastColumn&&E(f,e.lastHeaderCell)):a>h&&(E(f,e.totalRow),o===t.c0&&t.showFirstColumn&&E(f,e.firstTotalCell),o===t.c1&&t.showLastColumn&&E(f,e.lastTotalCell)),f},u=(t,a,o,f,n)=>{const h=[],b=(R,w,y,T,S)=>{R?.borders&&T>=w&&S>=y&&h.push({borders:R.borders,r0:w,c0:y,r1:T,c1:S})},m=t.r0+t.headerRows,c=t.r1-t.totalsRows;if(b(e.wholeTable,t.r0,t.c0,t.r1,t.c1),t.showColumnStripes&&(e.firstColumnStripe?.borders||e.secondColumnStripe?.borders)){const R=i[0]+i[1];for(let w=t.c0;w<=Math.min(t.c1,n);w+=R)b(e.firstColumnStripe,m,w,c,Math.min(t.c1,w+i[0]-1)),b(e.secondColumnStripe,m,w+i[0],c,Math.min(t.c1,w+R-1))}if(t.showRowStripes!==!1&&(e.firstRowStripe?.borders||e.secondRowStripe?.borders)){const R=l[0]+l[1],w=m+Math.floor(Math.max(0,a-m)/R)*R;for(let y=w;y<=Math.min(c,o);y+=R)b(e.firstRowStripe,y,t.c0,Math.min(c,y+l[0]-1),t.c1),b(e.secondRowStripe,y+l[0],t.c0,Math.min(c,y+R-1),t.c1)}return t.showFirstColumn&&b(e.firstColumn,t.r0,t.c0,t.r1,t.c0),t.showLastColumn&&b(e.lastColumn,t.r0,t.c1,t.r1,t.c1),t.headerRows>0&&(b(e.headerRow,t.r0,t.c0,m-1,t.c1),t.showFirstColumn&&b(e.firstHeaderCell,t.r0,t.c0,m-1,t.c0),t.showLastColumn&&b(e.lastHeaderCell,t.r0,t.c1,m-1,t.c1)),t.totalsRows>0&&(b(e.totalRow,c+1,t.c0,t.r1,t.c1),t.showFirstColumn&&b(e.firstTotalCell,c+1,t.c0,t.r1,t.c0),t.showLastColumn&&b(e.lastTotalCell,c+1,t.c1,t.r1,t.c1)),h},s=e.headerRow;return{format:r,areas:u,custom:d,headerFill:s?.fill??null,headerInk:s?.color??(s?.fill?"#FFFFFF":"#000000"),headerRule:N(s),band:e.firstRowStripe?.fill??null,rule:N(e.wholeTable)??N(e.totalRow),body:e.wholeTable?.fill??null,ink:e.wholeTable?.color??null}}const z={medium:2,mediumDashed:2,mediumDashDot:2,mediumDashDotDot:2,slantDashDot:2,thick:3,double:3};function pe(e,l,i,{ra:d,rb:r,ca:u,cb:s,xs:t,ys:a,ox:o=0,oy:f=0,line:n=1,noFill:h=!1,setInk:b}){const m=Math.max(l.r0,d),c=Math.min(l.r1,r),R=Math.max(l.c0,u),w=Math.min(l.c1,s);for(let S=h?c+1:m;S<=c;S++){const p=a[S-d],x=a[S-d+1]-p;if(x!==0)for(let L=R;L<=w;L++){const $=t[L-u],D=t[L-u+1]-$;if(D===0)continue;const{fill:C}=i.format(l,S,L);C&&(b(C),e.fillRect(o+$,f+p,D,x))}}const y=(S,p,x,L,$)=>{b(S.color);const D=z[S.style]??1,C=$?L-D*n:L;S.style==="double"?(e.fillRect(o+p,f+C,x-p,n),e.fillRect(o+p,f+C+2*n,x-p,n)):e.fillRect(o+p,f+C,x-p,D*n)},T=(S,p,x,L,$)=>{b(S.color);const D=z[S.style]??1,C=$?L-D*n:L;S.style==="double"?(e.fillRect(o+C,f+p,n,x-p),e.fillRect(o+C+2*n,f+p,n,x-p)):e.fillRect(o+C,f+p,D*n,x-p)};for(const S of i.areas(l,m,c,R,w)){if(S.r1<d||S.r0>r||S.c1<u||S.c0>s)continue;const p=Math.max(S.c0,u),x=Math.min(S.c1,s),L=Math.max(S.r0,d),$=Math.min(S.r1,r),D=t[p-u],C=t[x-u+1],P=a[L-d],M=a[$-d+1],A=S.borders;if(A.h)for(let I=L;I<$+(S.r1>$?1:0);I++){const g=a[I-d+1];g!==a[I-d]&&y(A.h,D,C,g,!0)}if(A.v)for(let I=p;I<x+(S.c1>x?1:0);I++){const g=t[I-u+1];g!==t[I-u]&&T(A.v,P,M,g,!0)}A.t&&S.r0>=d&&y(A.t,D,C,P,!1),A.b&&S.r1<=r&&y(A.b,D,C,M,!0),A.l&&S.c0>=u&&T(A.l,P,M,D,!1),A.r&&S.c1<=s&&T(A.r,P,M,C,!0)}}const oe={NONE:0,PAGE_LABEL:1,PAGE_VALUE:2,CORNER:3,HEADER_BLANK:4,COL_CAPTION:5,ROW_CAPTION:6,COL_ITEM:7,COL_SUBTOTAL:8,COL_GRAND:9,DATA_HEADER:10,ROW_ITEM:11,ROW_PARENT:12,ROW_SUBTOTAL:13,ROW_GRAND:14,DATA:15,DATA_PARENT:16,DATA_SUBTOTAL:17,DATA_GRAND_ROW:18,DATA_GRAND_COL:19,PLACEHOLDER:20},F=(e,l,i,d)=>e<=0?l:e===1?i:d;function Re(e,l,i){const d=l?.find(i);return d?ne(Object.fromEntries(ee.map(r=>[r,O(e,d,r)])),!0):null}function ne(e,l=!1){const i=oe,d=e.wholeTable?.borders&&(e.wholeTable.borders.h||e.wholeTable.borders.v)?{...e.wholeTable,borders:{b:e.wholeTable.borders.h??null,r:e.wholeTable.borders.v??null}}:e.wholeTable&&{...e.wholeTable,borders:void 0};return{patch:(u,s,t,a={},o=0)=>{const f={},n=a.colHeaders===!1?null:e.headerRow,h=a.rowHeaders===!1?null:e.firstColumn,b=a.lastColumn===!1?null:e.lastColumn,m={},c=(T,S="tb")=>{T&&(E(f,T),T.borders&&(S.includes("t")&&T.borders.t&&(m.t=T.borders.t),S.includes("b")&&T.borders.b&&(m.b=T.borders.b),S.includes("l")&&T.borders.l&&(m.l=T.borders.l),S.includes("r")&&T.borders.r&&(m.r=T.borders.r)))};u!==i.PAGE_LABEL&&u!==i.PAGE_VALUE&&c(d,"br");const R=m.b,w=m.r;switch(t&4&&c(e.firstColumnStripe,"lr"),t&8&&c(e.secondColumnStripe,"lr"),t&1&&c(e.firstRowStripe),t&2&&c(e.secondRowStripe),u){case i.PAGE_LABEL:c(e.pageFieldLabels,"tblr");break;case i.PAGE_VALUE:c(e.pageFieldValues,"tblr");break;case i.CORNER:c(n),c(h,"lr"),c(e.firstHeaderCell,"tblr");break;case i.HEADER_BLANK:case i.COL_CAPTION:case i.DATA_HEADER:c(n);break;case i.ROW_CAPTION:c(n),c(e.firstHeaderCell,"tblr");break;case i.COL_ITEM:c(n),c(F(s,e.firstColumnSubheading,e.secondColumnSubheading,e.thirdColumnSubheading));break;case i.COL_SUBTOTAL:c(n),c(F(s,e.firstSubtotalColumn,e.secondSubtotalColumn,e.thirdSubtotalColumn),"lr");break;case i.COL_GRAND:c(n),c(b,"lr");break;case i.ROW_ITEM:c(h,"lr");break;case i.ROW_PARENT:c(h,"lr"),c(F(s,e.firstRowSubheading,e.secondRowSubheading,e.thirdRowSubheading));break;case i.ROW_SUBTOTAL:c(h,"lr"),c(F(s,e.firstSubtotalRow,e.secondSubtotalRow,e.thirdSubtotalRow));break;case i.ROW_GRAND:c(h,"lr"),c(e.totalRow);break;case i.DATA_PARENT:c(F(s,e.firstRowSubheading,e.secondRowSubheading,e.thirdRowSubheading));break;case i.DATA_SUBTOTAL:c(F(s,e.firstSubtotalRow,e.secondSubtotalRow,e.thirdSubtotalRow));break;case i.DATA_GRAND_ROW:c(e.totalRow);break;case i.DATA_GRAND_COL:c(b,"lr");break;case i.PLACEHOLDER:c(e.blankRow);break;default:}const y=e.wholeTable?.borders;return y&&o&&(o&1&&y.t&&!m.t&&(m.t=y.t),o&2&&y.b&&(!m.b||m.b===R)&&(m.b=y.b),o&4&&y.l&&!m.l&&(m.l=y.l),o&8&&y.r&&(!m.r||m.r===w)&&(m.r=y.r)),Object.keys(m).length&&(f.borders=m),f},stripe:e.firstRowStripe?.fill??null,custom:l,header:{},sub:{},grand:{},parent:{},page:{}}}function Te(e,l,i,d){const r=l?.slicerStyles.find(n=>n.name===i),u=l?.find(i);if(!r&&!u)return null;const s={...d},t=O(e,u,"wholeTable"),a=O(e,u,"headerRow");t?.fill&&(s.frameFill=t.fill),t?.color&&(s.ink=t.color);const o=N(t);o&&(s.frameLine=o),a?.color&&(s.captionInk=a.color),a?.fill&&(s.captionFill=a.fill);const f=(n,h,b,m)=>{const c=O(e,r,n,l.slicerDxfs);if(!c)return;c.fill&&(s[h]=c.fill),c.color&&(s[b]=c.color);const R=N(c);R&&m&&(s[m]=R)};return f("selectedItemWithData","selFill","selInk","selLine"),f("unselectedItemWithData","fill","itemInk","itemLine"),f("selectedItemWithNoData","selNoFill","selNoInk"),f("unselectedItemWithNoData","noFill","noInk"),s.hoverSelFill=s.selFill,s.hoverSelInk=s.selInk,s.hoverFill=s.fill,s.hoverInk=s.itemInk,f("hoveredSelectedItemWithData","hoverSelFill","hoverSelInk"),f("hoveredUnselectedItemWithData","hoverFill","hoverInk"),s}function we(e,l,i,d){const r=l?.timelineStyles.find(h=>h.name===i),u=l?.find(i);if(!r&&!u)return null;const s={...d},t=O(e,u,"wholeTable"),a=O(e,u,"headerRow");t?.fill&&(s.frameFill=t.fill);const o=N(t);o&&(s.frameLine=o),a?.color&&(s.captionInk=a.color);const f=(h,b)=>{const m=O(e,r,h,l.timelineDxfs);m?.fill&&(s[b]=m.fill)},n=(h,b)=>{const m=O(e,r,h,l.timelineDxfs);m?.color&&(s[b]=m.color)};return f("selectedTimeBlock","selFill"),f("unselectedTimeBlock","blockFill"),f("selectedTimeBlockSpace","selSpaceFill"),n("selectionLabel","labelInk"),n("timeLevel","levelInk"),n("periodLabel1","periodInk"),n("periodLabel2","subPeriodInk"),s}export{te as CustomStyles,ee as PIVOT_ELEMENTS,me as SLICER_ELEMENTS,Z as TABLE_ELEMENTS,Se as TIMELINE_ELEMENTS,le as addDxf,Re as customPivotPattern,Te as customSlicerColors,ye as customTableColors,we as customTimelineColors,ne as elementPivotPattern,se as elementTableColors,pe as paintCustomTable,he as parseCustomStyles,be as patchCustomStyles};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{partsToSerial as c,serialToParts as M}from"../core/numfmt.js";const T=["dateEqual","dateNotEqual","dateOlderThan","dateOlderThanOrEqual","dateNewerThan","dateNewerThanOrEqual"],m=["dateBetween","dateNotBetween"],p=["tomorrow","today","yesterday","nextWeek","thisWeek","lastWeek","nextMonth","thisMonth","lastMonth","nextQuarter","thisQuarter","lastQuarter","nextYear","thisYear","lastYear","yearToDate","Q1","Q2","Q3","Q4","M1","M2","M3","M4","M5","M6","M7","M8","M9","M10","M11","M12"],E=new Set([...T,...m,...p]),y=a=>E.has(a),Q={dateEqual:"Equals...",dateNotEqual:"Does Not Equal...",dateOlderThan:"Before...",dateOlderThanOrEqual:"Before or Equal to...",dateNewerThan:"After...",dateNewerThanOrEqual:"After or Equal to...",dateBetween:"Between...",dateNotBetween:"Not Between...",tomorrow:"Tomorrow",today:"Today",yesterday:"Yesterday",nextWeek:"Next Week",thisWeek:"This Week",lastWeek:"Last Week",nextMonth:"Next Month",thisMonth:"This Month",lastMonth:"Last Month",nextQuarter:"Next Quarter",thisQuarter:"This Quarter",lastQuarter:"Last Quarter",nextYear:"Next Year",thisYear:"This Year",lastYear:"Last Year",yearToDate:"Year to Date",Q1:"Quarter 1",Q2:"Quarter 2",Q3:"Quarter 3",Q4:"Quarter 4",M1:"January",M2:"February",M3:"March",M4:"April",M5:"May",M6:"June",M7:"July",M8:"August",M9:"September",M10:"October",M11:"November",M12:"December"};function d(a=new Date){return c(a.getFullYear(),a.getMonth()+1,a.getDate())}const N=a=>a-(a+6)%7;function q(a,l){const r=M(l),t=r.year,s=Math.floor((r.month-1)/3),n=(h,i)=>[h,i],e=(h,i)=>n(c(h,i,1),i===12?c(h+1,1,1):c(h,i+1,1)),o=(h,i)=>n(c(h,i*3+1,1),i===3?c(h+1,1,1):c(h,(i+1)*3+1,1)),u=N(l);switch(a){case"today":return n(l,l+1);case"tomorrow":return n(l+1,l+2);case"yesterday":return n(l-1,l);case"thisWeek":return n(u,u+7);case"lastWeek":return n(u-7,u);case"nextWeek":return n(u+7,u+14);case"thisMonth":return e(t,r.month);case"lastMonth":return r.month===1?e(t-1,12):e(t,r.month-1);case"nextMonth":return r.month===12?e(t+1,1):e(t,r.month+1);case"thisQuarter":return o(t,s);case"lastQuarter":return s===0?o(t-1,3):o(t,s-1);case"nextQuarter":return s===3?o(t+1,0):o(t,s+1);case"thisYear":return n(c(t,1,1),c(t+1,1,1));case"lastYear":return n(c(t-1,1,1),c(t,1,1));case"nextYear":return n(c(t+1,1,1),c(t+2,1,1));case"yearToDate":return n(c(t,1,1),l+1);default:return null}}function F(a,l=d()){const{type:r}=a,t=Math.floor(Number(a.value)),s=Math.floor(Number(a.value2));switch(r){case"dateEqual":return e=>Math.floor(e)===t;case"dateNotEqual":return e=>Math.floor(e)!==t;case"dateOlderThan":return e=>Math.floor(e)<t;case"dateOlderThanOrEqual":return e=>Math.floor(e)<=t;case"dateNewerThan":return e=>Math.floor(e)>t;case"dateNewerThanOrEqual":return e=>Math.floor(e)>=t;case"dateBetween":return e=>Math.floor(e)>=Math.min(t,s)&&Math.floor(e)<=Math.max(t,s);case"dateNotBetween":return e=>Math.floor(e)<Math.min(t,s)||Math.floor(e)>Math.max(t,s);default:}if(/^Q[1-4]$/.test(r)){const e=Number(r[1])-1;return o=>Math.floor((M(Math.floor(o)).month-1)/3)===e}if(/^M\d+$/.test(r)){const e=Number(r.slice(1));return o=>M(Math.floor(o)).month===e}const n=q(r,l);return n?e=>e>=n[0]&&e<n[1]:()=>!0}function g(a,l,r=d()){const t=new Uint8Array(a.length),s=l.dateFilter?F(l.dateFilter,r):null,[n,e]=l.range??[-1/0,1/0];for(let o=0;o<a.length;o++){const u=a[o];(typeof u!="number"||u<n||u>=e||s&&!s(u))&&(t[o]=1)}return t}function v(a){const r=a.c.find(t=>t.n==="autoFilter")?.c.find(t=>t.n==="filterColumn")?.c.find(t=>t.n==="customFilters")?.c.filter(t=>t.n==="customFilter")??[];return{type:a.a.type,value:r[0]?.a.val,value2:r[1]?.a.val,node:a}}const f={dateEqual:[{val:"a"}],dateNotEqual:[{operator:"notEqual",val:"a"}],dateOlderThan:[{operator:"lessThan",val:"a"}],dateOlderThanOrEqual:[{operator:"lessThanOrEqual",val:"a"}],dateNewerThan:[{operator:"greaterThan",val:"a"}],dateNewerThanOrEqual:[{operator:"greaterThanOrEqual",val:"a"}],dateBetween:[{operator:"greaterThanOrEqual",val:"a"},{operator:"lessThanOrEqual",val:"b"}],dateNotBetween:[{operator:"lessThan",val:"a"},{operator:"greaterThan",val:"b"}]},O="{0605FD5F-26C8-4aeb-8148-2DB25E43C511}",w="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main";function D(a,l,r,t){const s=[],n=(e,o,u,h,i=!0)=>r("filter",{fld:String(l),type:e,evalOrder:"-1",id:String(o),...u},[r("autoFilter",{ref:"A1"},[r("filterColumn",{colId:"0"},[h])]),...i?[r("extLst",{},[r("ext",{uri:O,"xmlns:x15":w},[r("x15:pivotFilter",{useWholeDay:"1"})])])]:[]]);if(a.dateFilter){const e=a.dateFilter;if(e.node)s.push(e.node);else if(f[e.type]){const o=f[e.type].map(({operator:h,val:i})=>r("customFilter",{...h?{operator:h}:{},val:String(i==="a"?e.value:e.value2)})),u=e.type==="dateBetween";s.push(n(e.type,t(),{},r("customFilters",u?{and:"1"}:{},o)))}else s.push(n(e.type,t(),{},r("dynamicFilter",{type:e.type}),!1))}if(a.range){const[e,o]=a.range,u=[r("customFilter",{operator:"greaterThanOrEqual",val:String(e)}),r("customFilter",{operator:"lessThanOrEqual",val:String(Math.floor(o-1))})];a.rangeFilterId=t(),s.push(n("dateBetween",a.rangeFilterId,{},r("customFilters",{and:"1"},u)))}return s}export{p as DATE_FILTERS_DYNAMIC,T as DATE_FILTERS_ONE,m as DATE_FILTERS_TWO,Q as DATE_FILTER_LABELS,D as dateFilterNodes,F as dateFilterTest,g as dateOptionFlags,y as isDateFilterType,v as parseDateFilter,d as todaySerial};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{parseNode as p}from"../pivot/xml.js";import{xmlAttr as D}from"../io/xml-escape.js";import{unescapeXstring as w}from"../io/xml-scan.js";const a={main:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",r:"http://schemas.openxmlformats.org/officeDocument/2006/relationships",mc:"http://schemas.openxmlformats.org/markup-compatibility/2006",x14:"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",x15:"http://schemas.microsoft.com/office/spreadsheetml/2010/11/main",xr10:"http://schemas.microsoft.com/office/spreadsheetml/2016/revision10",xdr:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",a:"http://schemas.openxmlformats.org/drawingml/2006/main",a14:"http://schemas.microsoft.com/office/drawing/2010/main",sle:"http://schemas.microsoft.com/office/drawing/2010/slicer",sle15:"http://schemas.microsoft.com/office/drawing/2012/slicer",tsle:"http://schemas.microsoft.com/office/drawing/2012/timeslicer"},P={slicerCache:"http://schemas.microsoft.com/office/2007/relationships/slicerCache",slicer:"http://schemas.microsoft.com/office/2007/relationships/slicer",timelineCache:"http://schemas.microsoft.com/office/2011/relationships/timelineCache",timeline:"http://schemas.microsoft.com/office/2011/relationships/timeline",drawing:`${a.r}/drawing`},O={slicerCache:"application/vnd.ms-excel.slicerCache+xml",slicer:"application/vnd.ms-excel.slicer+xml",timelineCache:"application/vnd.ms-excel.timelineCache+xml",timeline:"application/vnd.ms-excel.timeline+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml"},h={wbPivotSlicerCaches:"{BBE1A952-AA13-448e-AADC-164F8A28A991}",wbTableSlicerCaches:"{46BE6895-7355-4a93-B00E-2C351335B9C9}",wbTimelineCaches:"{D0CA8CA8-9F24-4464-BF8E-62219DCF47F9}",wsPivotSlicers:"{A8765BA9-456A-4dab-B4F3-ACF838C121DE}",wsTableSlicers:"{3A4CF648-6AED-40f4-86FF-DC5316D8AED3}",wsTimelines:"{7E03D99C-DC04-49d9-9315-930204A7B6E9}",tableSlicerCache:"{2F2917AC-EB37-4324-AD4E-5DD8C200BD13}",hideNoData:"{470722E0-AACD-4C17-9CDC-17EF765DBC7E}",pivotCacheId:"{725AE2AE-9491-48be-B2B4-4EB974FC3084}",slicerStyles:"{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}",timelineStyles:"{9260A510-F301-46a8-8635-F512D64BE5F5}"},B=t=>`@@TAB${t}@@`,b=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
+
`,C=D,d=t=>Object.entries(t).filter(([,i])=>i!=null).map(([i,e])=>` ${i}="${C(e)}"`).join(""),x=(t,i)=>t?.c?.find(e=>e.n===i)??null,v=(t,i)=>t?t.c.filter(e=>e.n===i):[],$=t=>t.slice(t.indexOf(":")+1),f=(t,i)=>t===void 0?i:t==="1"||t==="true";function R(t){const i=d({name:t.name,"xr10:uid":t.uid??void 0,sourceName:t.sourceName,...t.extra??{}}),e=`${b}<slicerCacheDefinition xmlns="${a.x14}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}"${i}>`,n={sortOrder:t.sortOrder&&t.sortOrder!=="ascending"?t.sortOrder:void 0,customListSort:t.customListSort===!1?"0":void 0,crossFilter:t.crossFilter&&t.crossFilter!=="showItemsWithDataAtTop"?t.crossFilter:void 0},r=[];let o="";if(t.kind==="table")r.push(`<x:ext uri="${h.tableSlicerCache}" xmlns:x15="${a.x15}"><x15:tableSlicerCache${d({tableId:t.tableId,column:t.column,...n})}/></x:ext>`);else{const l=(t.pivotTables??[]).map(m=>`<pivotTable${d({tabId:m.tabId,name:m.name})}/>`).join("");o+=`<pivotTables>${l}</pivotTables>`;const c=(t.items??[]).map(m=>`<i${d({x:m.x,s:m.s?"1":void 0,nd:m.nd?"1":void 0})}/>`).join(""),s={pivotCacheId:t.pivotCacheId,...n,showMissing:t.showMissing===!1?"0":void 0};o+=`<data><tabular${d(s)}><items count="${(t.items??[]).length}">${c}</items></tabular></data>`}t.hideNoData&&r.push(`<x:ext uri="${h.hideNoData}" xmlns:x15="${a.x15}"><x15:slicerCacheHideItemsWithNoData/></x:ext>`);for(const l of t.rawExt??[])r.push(l);return`${e}${o}${r.length?`<extLst>${r.join("")}</extLst>`:""}</slicerCacheDefinition>`}function k(t){const i=e=>{const n={name:e.name,"xr10:uid":e.uid??void 0,cache:e.cache,caption:e.caption,startItem:e.startItem?e.startItem:void 0,columnCount:e.columnCount&&e.columnCount!==1?e.columnCount:void 0,showCaption:e.showCaption===!1?"0":void 0,level:e.level?e.level:void 0,style:e.style&&e.style!=="SlicerStyleLight1"?e.style:void 0,lockedPosition:e.lockedPosition?"1":void 0,rowHeight:e.rowHeight??241300,...e.extra??{}};return`<slicer${d(n)}/>`};return`${b}<slicers xmlns="${a.x14}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}">${t.map(i).join("")}</slicers>`}function H(t){const i=(t.pivotTables??[]).map(r=>`<pivotTable${d({tabId:r.tabId,name:r.name})}/>`).join(""),e=(r,o)=>o?`<${r}${d({startDate:o.start,endDate:o.end})}/>`:"",n=d({singleRangeFilterState:t.singleRange===!1?"0":void 0,minimalRefreshVersion:t.minimalRefreshVersion??6,lastRefreshVersion:t.lastRefreshVersion??6,pivotCacheId:t.pivotCacheId,filterType:t.selection?"dateBetween":"unknown",filterId:t.selection?t.filterId:void 0,filterTabId:t.selection?t.filterTabId:void 0,filterPivotName:t.selection?t.filterPivotName:void 0});return`${b}<timelineCacheDefinition xmlns="${a.x15}" xmlns:x15="${a.x15}" xmlns:mc="${a.mc}" mc:Ignorable="xr10" xmlns:xr10="${a.xr10}"${d({name:t.name,"xr10:uid":t.uid??void 0,sourceName:t.sourceName,...t.extra??{}})}><pivotTables>${i}</pivotTables><state${n}>${e("selection",t.selection)}${e("bounds",t.bounds)}</state></timelineCacheDefinition>`}function X(t){const i=e=>`<timeline${d({name:e.name,"xr10:uid":e.uid??void 0,cache:e.cache,caption:e.caption,showHeader:e.showHeader===!1?"0":void 0,showSelectionLabel:e.showSelectionLabel===!1?"0":void 0,showTimeLevel:e.showTimeLevel===!1?"0":void 0,showHorizontalScrollbar:e.showHorizontalScrollbar===!1?"0":void 0,level:e.level??2,selectionLevel:e.selectionLevel??e.level??2,scrollPosition:e.scrollPosition??void 0,style:e.style&&e.style!=="TimeSlicerStyleLight1"?e.style:void 0,...e.extra??{}})}/>`;return`${b}<timelines xmlns="${a.x15}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}">${t.map(i).join("")}</timelines>`}const S={pivot:{choice:`xmlns:a14="${a.a14}" Requires="a14"`,uri:a.sle,inner:t=>`<sle:slicer xmlns:sle="${a.sle}" name="${C(t)}"/>`},table:{choice:`xmlns:sle15="${a.sle15}" Requires="sle15"`,uri:a.sle,inner:t=>`<sle:slicer xmlns:sle="${a.sle}" name="${C(t)}"/>`},timeline:{choice:`xmlns:tsle="${a.tsle}" Requires="tsle"`,uri:a.tsle,inner:t=>`<tsle:timeslicer xmlns:tsle="${a.tsle}" name="${C(t)}"/>`}},T={pivot:"This shape represents a slicer. Slicers are supported in Excel 2010 or later.",table:"This shape represents a table slicer. Table slicers are supported in Excel 2013 or later.",timeline:"Timeline: Works in Excel 2013 or higher. Do not move or resize."};function M({kind:t,name:i,id:e,from:n,to:r,cx:o=1828800,cy:l=2524125}){const c=S[t],s=(m,u)=>`<xdr:${m}><xdr:col>${u.col}</xdr:col><xdr:colOff>${u.colOff}</xdr:colOff><xdr:row>${u.row}</xdr:row><xdr:rowOff>${u.rowOff}</xdr:rowOff></xdr:${m}>`;return`<xdr:twoCellAnchor editAs="absolute">${s("from",n)}${s("to",r)}<mc:AlternateContent xmlns:mc="${a.mc}"><mc:Choice ${c.choice}><xdr:graphicFrame macro=""><xdr:nvGraphicFramePr><xdr:cNvPr id="${e}" name="${C(i)}"/><xdr:cNvGraphicFramePr/></xdr:nvGraphicFramePr><xdr:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/></xdr:xfrm><a:graphic><a:graphicData uri="${c.uri}">${c.inner(i)}</a:graphicData></a:graphic></xdr:graphicFrame></mc:Choice><mc:Fallback xmlns=""><xdr:sp macro="" textlink=""><xdr:nvSpPr><xdr:cNvPr id="0" name=""/><xdr:cNvSpPr><a:spLocks noTextEdit="1"/></xdr:cNvSpPr></xdr:nvSpPr><xdr:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${o}" cy="${l}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:solidFill><a:prstClr val="white"/></a:solidFill><a:ln w="1"><a:solidFill><a:prstClr val="green"/></a:solidFill></a:ln></xdr:spPr><xdr:txBody><a:bodyPr vertOverflow="clip" horzOverflow="clip"/><a:lstStyle/><a:p><a:r><a:rPr lang="en-US" sz="1100"/><a:t>${T[t]}</a:t></a:r></a:p></xdr:txBody></xdr:sp></mc:Fallback></mc:AlternateContent><xdr:clientData/></xdr:twoCellAnchor>`}const j=t=>`${b}<xdr:wsDr xmlns:xdr="${a.xdr}" xmlns:a="${a.a}">${t}</xdr:wsDr>`,g=/<xdr:(twoCellAnchor|oneCellAnchor|absoluteAnchor)\b[\s\S]*?<\/xdr:\1>/g,I=/<(?:\w+:)?(slicer|timeslicer)\b[^>]*\bname="([^"]*)"/;function z(t){const i=[];for(const e of t.matchAll(g)){const n=e[0];if(!/drawing\/20(?:10|12)\/(?:time)?slicer/.test(n))continue;const r=I.exec(n);if(!r)continue;const o=l=>{const c=new RegExp(`<xdr:${l}>\\s*<xdr:col>(\\d+)</xdr:col>\\s*<xdr:colOff>(-?\\d+)</xdr:colOff>\\s*<xdr:row>(\\d+)</xdr:row>\\s*<xdr:rowOff>(-?\\d+)</xdr:rowOff>`).exec(n);return c?{col:Number(c[1]),colOff:Number(c[2]),row:Number(c[3]),rowOff:Number(c[4])}:null};i.push({kind:r[1]==="timeslicer"?"timeline":/Requires="sle15"/.test(n)?"table":"pivot",name:w(r[2]),id:Number(/<xdr:cNvPr\b[^>]*\bid="(\d+)"/.exec(n)?.[1]??0),from:o("from"),to:o("to"),raw:n})}return i}function V(t,{upsert:i=[],remove:e=[]}){const n=new Map(i.map(s=>[s.name,s.xml])),r=new Set(e),o=new Set;let l=t.replace(g,s=>{if(!/drawing\/20(?:10|12)\/(?:time)?slicer/.test(s))return s;const m=I.exec(s);if(!m)return s;const u=w(m[2]);return r.has(u)?"":n.has(u)?(o.add(u),n.get(u)):s});const c=i.filter(s=>!o.has(s.name)).map(s=>s.xml).join("");return c&&(l=l.replace(/<\/(\w+:)?wsDr>\s*$/,s=>`${c}${s}`)),l}const F=new Set(["name","xr10:uid","cache","caption","startItem","columnCount","showCaption","level","style","lockedPosition","rowHeight"]),A=new Set(["name","xr10:uid","cache","caption","showHeader","showSelectionLabel","showTimeLevel","showHorizontalScrollbar","level","selectionLevel","scrollPosition","style"]),N=(t,i)=>{const e={};for(const[n,r]of Object.entries(t))!i.has(n)&&!n.startsWith("xmlns")&&n!=="mc:Ignorable"&&(e[n]=r);return e};function W(t){const i=p(t),e={name:i.a.name,sourceName:i.a.sourceName,uid:i.a["xr10:uid"]??null,kind:"pivot",sortOrder:"ascending",customListSort:!0,crossFilter:"showItemsWithDataAtTop",showMissing:!0,hideNoData:!1,pivotTables:[],items:[],pivotCacheId:null,tableId:null,column:null},n=o=>{o.sortOrder&&(e.sortOrder=o.sortOrder),e.customListSort=f(o.customListSort,!0),o.crossFilter&&(e.crossFilter=o.crossFilter)};for(const o of v(x(i,"pivotTables"),"pivotTable"))e.pivotTables.push({tabId:Number(o.a.tabId),name:o.a.name});const r=x(x(i,"data"),"tabular");if(r){e.pivotCacheId=Number(r.a.pivotCacheId),n(r.a),e.showMissing=f(r.a.showMissing,!0);for(const o of v(x(r,"items"),"i"))e.items.push({x:Number(o.a.x),s:f(o.a.s,!1),nd:f(o.a.nd,!1)})}for(const o of x(i,"extLst")?.c??[])if($(o.n)==="ext")if(o.a.uri===h.tableSlicerCache){const l=o.c.find(c=>$(c.n)==="tableSlicerCache");l&&(e.kind="table",e.tableId=Number(l.a.tableId),e.column=Number(l.a.column),n(l.a))}else o.a.uri===h.hideNoData&&(e.hideNoData=!0);return e}function _(t){const i=p(t);return v(i,"slicer").map(e=>({name:e.a.name,uid:e.a["xr10:uid"]??null,cache:e.a.cache,caption:e.a.caption??e.a.name,startItem:Number(e.a.startItem??0),columnCount:Number(e.a.columnCount??1),showCaption:f(e.a.showCaption,!0),level:Number(e.a.level??0),style:e.a.style??"SlicerStyleLight1",lockedPosition:f(e.a.lockedPosition,!1),rowHeight:Number(e.a.rowHeight??241300),extra:N(e.a,F)}))}function G(t){const i=p(t),e=x(i,"state"),n=r=>{const o=x(e,r);return o?{start:o.a.startDate,end:o.a.endDate}:null};return{name:i.a.name,sourceName:i.a.sourceName,uid:i.a["xr10:uid"]??null,pivotTables:v(x(i,"pivotTables"),"pivotTable").map(r=>({tabId:Number(r.a.tabId),name:r.a.name})),singleRange:f(e?.a.singleRangeFilterState,!0),minimalRefreshVersion:Number(e?.a.minimalRefreshVersion??6),lastRefreshVersion:Number(e?.a.lastRefreshVersion??6),pivotCacheId:Number(e?.a.pivotCacheId??0),filterType:e?.a.filterType??"unknown",filterId:e?.a.filterId!==void 0?Number(e.a.filterId):null,filterTabId:e?.a.filterTabId!==void 0?Number(e.a.filterTabId):null,filterPivotName:e?.a.filterPivotName??null,selection:n("selection"),bounds:n("bounds")}}function q(t){const i=p(t);return v(i,"timeline").map(e=>({name:e.a.name,uid:e.a["xr10:uid"]??null,cache:e.a.cache,caption:e.a.caption??e.a.name,showHeader:f(e.a.showHeader,!0),showSelectionLabel:f(e.a.showSelectionLabel,!0),showTimeLevel:f(e.a.showTimeLevel,!0),showHorizontalScrollbar:f(e.a.showHorizontalScrollbar,!0),level:Number(e.a.level??2),selectionLevel:Number(e.a.selectionLevel??e.a.level??2),scrollPosition:e.a.scrollPosition??null,style:e.a.style??"TimeSlicerStyleLight1",extra:N(e.a,A)}))}function K(t){const i=p(t);for(const e of x(i,"extLst")?.c??[]){if(e.a.uri!==h.pivotCacheId)continue;const n=e.c.find(r=>$(r.n)==="pivotCacheDefinition");if(n?.a.pivotCacheId!==void 0)return Number(n.a.pivotCacheId)}return null}function U(t,i){const e=`<ext uri="${h.pivotCacheId}" xmlns:x14="${a.x14}"><x14:pivotCacheDefinition pivotCacheId="${i}"/></ext>`;return t.includes(h.pivotCacheId)?t.replace(/(<x14:pivotCacheDefinition\b[^>]*\bpivotCacheId=")\d+/,`$1${i}`):/<extLst>/.test(t)?t.replace(/<extLst>/,`<extLst>${e}`):t.replace("</pivotCacheDefinition>",`<extLst>${e}</extLst></pivotCacheDefinition>`)}import{isoToSerial as Y,serialToIso as Z}from"../pivot/xml.js";export{O as CT,h as EXT,a as NS,P as REL,b as XML_HEAD,M as frameXml,Y as isoToSerial,j as newDrawingXml,z as parseFrames,W as parseSlicerCacheXml,_ as parseSlicersXml,G as parseTimelineCacheXml,q as parseTimelinesXml,V as patchDrawingFrames,K as pivotCacheExtId,Z as serialToIso,U as setPivotCacheExtId,R as slicerCacheXml,k as slicersXml,B as tabPlaceholder,H as timelineCacheXml,X as timelinesXml};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const I=0;function F(n,e,r,s){const c=new Set;for(let a=0;a<n.count;a++)c.add(n.parents[a]*r+n.items[a]);const i=[],t=[];for(let a=0;a<e;a++)for(let l=0;l<r;l++)s?.[l]===1||c.has(a*r+l)||(i.push(a),t.push(l));if(i.length===0)return n;const p=n.count+i.length,d=new Int32Array(p),h=new Int32Array(p);return d.set(n.parents.subarray(0,n.count)),h.set(n.items.subarray(0,n.count)),d.set(i,n.count),h.set(t,n.count),{parents:d,items:h,count:p}}function S(n,e){const r=n.spec.conditionalFormats;return r?.length?e("conditionalFormats",{count:String(r.length)},r.map(s=>{const c=[e("reference",{field:"4294967294",count:"1",selected:"0"},[e("x",{v:String(s.dataIndex)})])],i={};if(s.scope==="data")i.scope="data";else if(s.scope==="field"){i.scope="field",i.type=s.type??"row";for(const t of s.fields??[])c.push(e("reference",{field:String(t),count:"0",selected:"0"}))}return i.priority=String(s.priority),e("conditionalFormat",i,[e("pivotAreas",{count:"1"},[e("pivotArea",{type:"data",collapsedLevelsAreSubtotals:"1",fieldPosition:"0"},[e("references",{count:String(c.length)},c)])])])})):null}function x(n){const e=n?.c?.find(r=>r.n==="conditionalFormats");return e?e.c.filter(r=>r.n==="conditionalFormat").map(r=>{const c=r.c.find(t=>t.n==="pivotAreas")?.c.find(t=>t.n==="pivotArea")?.c.find(t=>t.n==="references")?.c.filter(t=>t.n==="reference")??[],i=c.find(t=>t.a.field==="4294967294");return{priority:Number(r.a.priority??0),scope:r.a.scope??"selection",type:r.a.type??"none",dataIndex:Number(i?.c.find(t=>t.n==="x")?.a.v??0),fields:c.filter(t=>t!==i).map(t=>Number(t.a.field))}}):[]}function N(n,e){const{result:r}=n,{layout:s,rows:c,cols:i}=r,t=[],p=(o,g,u,m)=>{let y=-1;for(let f=0;f<=o.node.length;f++)(f===o.node.length||o.type[f]!==0||o.first[f]<=u&&o.level[f]>=u)&&(y>=0&&f-1>y&&m(y,f-1),y=f<o.node.length&&o.type[f]===0&&o.first[f]<=u&&o.level[f]>=u?f:-1)},d=e.row+s.pageRows+s.headerRows,h=e.col+s.labelCols,a=s.colForLevel??[];for(let o=0;o<c.slots.length-1;o++){if(a[o]===void 0||a[o]===a[o+1])continue;const g=e.col+a[o];p(c.lines,c.slots,o,(u,m)=>t.push({r0:d+u,c0:g,r1:d+m,c1:g}))}const l=e.row+s.pageRows+s.colRowBase;for(let o=0;o<i.slots.length-1;o++){const g=l+o;p(i.lines,i.slots,o,(u,m)=>t.push({r0:g,c0:h+u,r1:g,c1:h+m}))}return t}function b(n,e){const r=n.chartFormatIds;if(!r?.length)return null;const s=[];return r.forEach(c=>{n.spec.values.forEach((i,t)=>{s.push(e("chartFormat",{chart:String(c),format:String(t),series:"1"},[e("pivotArea",{type:"data",outline:"0",fieldPosition:"0"},[e("references",{count:"1"},[e("reference",{field:"4294967294",count:"1",selected:"0"},[e("x",{v:String(t)})])])])]))})}),e("chartFormats",{count:String(s.length)},s)}export{S as pivotCfNode,b as pivotChartFormatsNode,N as pivotLabelMerges,x as readPivotCf,F as withNoDataItems};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function D(s,h,o){const{r0:t,c0:c,r1:r,c1:e,headerRows:i,totalsRows:d,columns:R}=s,T=t+i,E=r-d;let a=h.slice(1,-1).trim(),S=!1;a[0]==="@"&&(S=!0,a=a.slice(1).trim());const g=[];if(a!=="")if(a[0]==="["){const l=/\[((?:[^\]']|'.)*)\]/g;let n;for(;(n=l.exec(a))!==null;)g.push(n[1].replace(/'(.)/g,"$1").trim())}else g.push(a.replace(/'(.)/g,"$1").trim());const u=new Set,p=[];for(const l of g){const n=l.toUpperCase();if(n==="#ALL"||n==="#DATA"||n==="#HEADERS"||n==="#TOTALS"||n==="#THIS ROW"){u.add(n),n==="#THIS ROW"&&(S=!0);continue}const f=R.findIndex(b=>b.toUpperCase()===n);if(f<0)return"REF";p.push(c+f)}let A=T,m=E;if(u.has("#ALL"))A=t,m=r;else{const l=u.has("#HEADERS"),n=u.has("#TOTALS"),f=u.has("#DATA");if(l&&i===0||n&&d===0||l&&n&&!f)return"REF";(l||n||f)&&(A=l?t:f?T:r,m=n?r:f?E:t)}const L=p.length?Math.min(...p):c,w=p.length?Math.max(...p):e;if(S){if(o<T||o>E)return"VALUE";A=o,m=o}return{top:A,left:L,bottom:m,right:w}}function F(s,h){if(!h||h.size===0)return s;let o="",t=0;const c=s.length;for(;t<c;){const r=s[t];if(r==='"'||r==="'"){let e=t+1;for(;e<c;){if(s[e]===r){if(s[e+1]!==r)break;e++}e++}o+=s.slice(t,e+1),t=e+1}else if(r==="["){let e=0,i=t;for(;i<c;i++)if(s[i]==="'")i++;else if(s[i]==="[")e++;else if(s[i]==="]"&&--e===0)break;o+=s.slice(t,i+1),t=i+1}else if(/[A-Za-z_\\]/.test(r)){let e=t+1;for(;e<c&&/[A-Za-z0-9_.\\]/.test(s[e]);)e++;const i=s.slice(t,e),d=o[o.length-1],R=h.has(i.toUpperCase())&&s[e]!=="["&&s[e]!=="("&&s[e]!=="!"&&d!=="!";o+=R?`${i}[]`:i,t=e}else o+=r,t++}return o}export{F as expandBareTables,D as resolveStructuredSpec};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readTableFilter as m}from"../cells/filter-file.js";import{escapeMarkup as d}from"../io/xml-escape.js";import{unescapeXml as b,unescapeXstring as p}from"../io/xml-scan.js";const f=/<tableColumn\b[^>]*?\/>|<tableColumn\b[^>]*>[\s\S]*?<\/tableColumn>/g;function w(o){const l=[],t=[];for(const s of o.matchAll(f)){const e=s[0],a=c=>new RegExp(`\\b${c}="([^"]*)"`).exec(e.slice(0,e.indexOf(">")+1))?.[1];l.push(Number(a("id")));const n=a("totalsRowFunction"),u=a("totalsRowLabel"),r=/<totalsRowFormula\b[^>]*>([\s\S]*?)<\/totalsRowFormula>/.exec(e)?.[1];u!==void 0?t.push({label:p(u)}):n&&n!=="none"?t.push(n==="custom"?{fn:n,formula:r!==void 0?b(r):""}:{fn:n}):t.push(null)}return{ids:l,totals:t}}async function F(o,l){for(const t of l){if(!t.part||!o.has(t.part))continue;const{ids:s,totals:e}=w(await o.text(t.part));s.length===t.columns.length&&(t.columnIds=s),!t.totals&&(t.totalsRows>0||e.some(Boolean))&&(t.totals=e),R(t,await o.bytes(t.part))}}function R(o,l){if(!o.filter||o.filter.columns.size>0)return;const t=m(l);if(!t||t.columns.size===0)return;o.filter.columns=t.columns,t.buttons&&(o.filter.buttons=t.buttons),t.sortState&&(o.filter.sortState=t.sortState);const{sheet:s}=o;s.filteredRows??=new Set;for(let e=o.r0+o.headerRows;e<=o.r1-o.totalsRows;e++)s.rows.isHidden(e)&&s.filteredRows.add(e)}const $=(o,l)=>{const t=o.totals?.[l];return t?.fn==="custom"&&t.formula?`<totalsRowFormula>${d(t.formula)}</totalsRowFormula>`:""};function S(o,l){let t=0;return o.replace(f,s=>{const e=s.indexOf(">"),a=s[e-1]==="/",n=s.slice(0,a?e-1:e).replace(/\s(?:totalsRowLabel|totalsRowFunction)="[^"]*"/g,"").trimEnd(),u=a?"":s.slice(e+1,s.lastIndexOf("</tableColumn>")).replace(/<totalsRowFormula\b[^>]*>[\s\S]*?<\/totalsRowFormula>|<totalsRowFormula\b[^>]*\/>/,""),r=l.totals[t]??"",c=l.totalsChild?.[t]??"";t++;const i=`${u}${c}`;return i?`${n}${r}>${i}</tableColumn>`:`${n}${r}/>`})}export{F as loadTableDetails,w as parseTableColumns,S as patchTableColumns,$ as totalsChildXml};
|
package/slicers/write.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EXT as c,NS as x,REL as b,newDrawingXml as C,patchDrawingFrames as h}from"./format.js";import{ensureDrawingElement as T,mergeContentTypes as S}from"../objects/drawing-xml.js";import{escapeMarkup as o}from"../io/xml-escape.js";const y=n=>n.slicers?.removedParts??[];function L(n,r){const s=r.slicers;return s?S(n,s.contentTypes,s.removedParts.map(t=>`/${t}`)):n}function k(n,r){const s=r.slicers;if(!s)return n;const t=s.workbookRels.map(e=>`<Relationship Id="${o(e.id)}" Type="${o(e.type)}" Target="${o(e.target)}"/>`).join("");return n.replace("</Relationships>",`${t}</Relationships>`)}const $=(n,r)=>n.replace(new RegExp(`<ext\\b[^>]*uri="${r.replace(/[{}-]/g,"\\$&")}"[^>]*>[\\s\\S]*?</ext>`),"");function g(n,r,s){const t=s.join("");let e=n;if(t)if(/<\/extLst>\s*$/.test(e.slice(0,e.lastIndexOf(r)))){const l=e.lastIndexOf("</extLst>");e=`${e.slice(0,l)}${t}${e.slice(l)}`}else{const l=e.lastIndexOf(r);e=`${e.slice(0,l)}<extLst>${t}</extLst>${e.slice(l)}`}return e.replace(/<extLst>\s*<\/extLst>/,"")}const p=(n,r)=>r.map(s=>`<${n} xmlns:r="${x.r}" r:id="${o(s)}"/>`).join("");function E(n,r){const s=r.slicers;if(!s)return n;let t=n;for(const i of[c.wbPivotSlicerCaches,c.wbTableSlicerCaches,c.wbTimelineCaches])t=$(t,i);const e=[];s.pivotCaches.length&&e.push(`<ext uri="${c.wbPivotSlicerCaches}" xmlns:x14="${x.x14}"><x14:slicerCaches>${p("x14:slicerCache",s.pivotCaches)}</x14:slicerCaches></ext>`),s.tableCaches.length&&e.push(`<ext uri="${c.wbTableSlicerCaches}" xmlns:x15="${x.x15}"><x15:slicerCaches xmlns:x14="${x.x14}">${p("x14:slicerCache",s.tableCaches)}</x15:slicerCaches></ext>`),s.timelineCaches.length&&e.push(`<ext uri="${c.wbTimelineCaches}" xmlns:x15="${x.x15}"><x15:timelineCacheRefs>${p("x15:timelineCacheRef",s.timelineCaches)}</x15:timelineCacheRefs></ext>`),t=g(t,"</workbook>",e);for(const i of s.removedNames)t=t.replace(new RegExp(`<definedName\\b[^>]*\\bname="${i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}"[^>]*>[^<]*</definedName>`),"");const l=s.names.filter(i=>!t.includes(`name="${o(i)}"`));if(l.length){const i=l.map(d=>`<definedName name="${o(d)}">#N/A</definedName>`).join("");/<\/definedNames>/.test(t)?t=t.replace("</definedNames>",`${i}</definedNames>`):t=t.replace("</sheets>",`</sheets><definedNames>${i}</definedNames>`)}return t.replace(/<definedNames>\s*<\/definedNames>/,"")}function R(n,r){let s=n;for(const e of[c.wsPivotSlicers,c.wsTableSlicers,c.wsTimelines])s=$(s,e);const t=[];return r.pivotIds.length&&t.push(`<ext uri="${c.wsPivotSlicers}" xmlns:x14="${x.x14}"><x14:slicerList>${p("x14:slicer",r.pivotIds)}</x14:slicerList></ext>`),r.tableIds.length&&t.push(`<ext uri="${c.wsTableSlicers}" xmlns:x15="${x.x15}"><x14:slicerList xmlns:x14="${x.x14}">${p("x14:slicer",r.tableIds)}</x14:slicerList></ext>`),r.timelineIds.length&&t.push(`<ext uri="${c.wsTimelines}" xmlns:x15="${x.x15}"><x15:timelineRefs>${p("x15:timelineRef",r.timelineIds)}</x15:timelineRefs></ext>`),g(s,"</worksheet>",t)}async function P({tail:n,index:r,info:s,source:t,extra:e,relsName:l}){const i=e.plan.slicers?.sheets?.[r];if(!i)return n;e.rels.has(l)||e.rels.set(l,[]);const d=e.rels.get(l);for(const a of i.rels)d.push(`<Relationship Id="${o(a.id)}" Type="${o(a.type)}" Target="${o(a.target)}"/>`);let m=R(n,i);const f=i.frames;if(f.upsert.length===0&&f.remove.length===0)return m;const u=s.objects;if(u){const a=e.parts.find(w=>w.path===u.path);return a&&(a.xml=h(typeof a.xml=="string"?a.xml:new TextDecoder().decode(a.xml),f)),m}if(i.drawingExisting){const a=await t.zip.text(i.drawingPath);return e.parts.push({path:i.drawingPath,xml:h(a,f)}),m}return e.parts.push({path:i.drawingPath,xml:C(h("",{upsert:[]})+f.upsert.map(a=>a.xml).join(""))}),d.push(`<Relationship Id="${o(i.drawingRelId)}" Type="${b.drawing}" Target="${o(i.drawingTarget)}"/>`),m=T(m,`<drawing xmlns:r="${x.r}" r:id="${o(i.drawingRelId)}"/>`),m}async function j(n,r,s){const t=r.slicers;if(!t)return;const e=r.sheetRefs??[],l=i=>i.replace(/@@TAB(\d+)@@/g,(d,m)=>String(e[Number(m)]?.sheetId??Number(m)+1));for(const i of t.parts)await n.addBytes(i.name,l(i.xml)),s.add(i.name)}export{P as applySlicerSheet,L as patchSlicerContentTypes,R as patchSlicerSheetTail,E as patchSlicerWorkbook,k as patchSlicerWorkbookRels,y as removedSlicerParts,j as writeSlicerParts};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=new Map("aliceblue f0f8ff antiquewhite faebd7 aqua 00ffff aquamarine 7fffd4 azure f0ffff beige f5f5dc bisque ffe4c4 black 000000 blanchedalmond ffebcd blue 0000ff blueviolet 8a2be2 brown a52a2a burlywood deb887 cadetblue 5f9ea0 chartreuse 7fff00 chocolate d2691e coral ff7f50 cornflowerblue 6495ed cornsilk fff8dc crimson dc143c cyan 00ffff darkblue 00008b darkcyan 008b8b darkgoldenrod b8860b darkgray a9a9a9 darkgreen 006400 darkgrey a9a9a9 darkkhaki bdb76b darkmagenta 8b008b darkolivegreen 556b2f darkorange ff8c00 darkorchid 9932cc darkred 8b0000 darksalmon e9967a darkseagreen 8fbc8f darkslateblue 483d8b darkslategray 2f4f4f darkslategrey 2f4f4f darkturquoise 00ced1 darkviolet 9400d3 deeppink ff1493 deepskyblue 00bfff dimgray 696969 dimgrey 696969 dodgerblue 1e90ff firebrick b22222 floralwhite fffaf0 forestgreen 228b22 fuchsia ff00ff gainsboro dcdcdc ghostwhite f8f8ff gold ffd700 goldenrod daa520 gray 808080 green 008000 greenyellow adff2f grey 808080 honeydew f0fff0 hotpink ff69b4 indianred cd5c5c indigo 4b0082 ivory fffff0 khaki f0e68c lavender e6e6fa lavenderblush fff0f5 lawngreen 7cfc00 lemonchiffon fffacd lightblue add8e6 lightcoral f08080 lightcyan e0ffff lightgoldenrodyellow fafad2 lightgray d3d3d3 lightgreen 90ee90 lightgrey d3d3d3 lightpink ffb6c1 lightsalmon ffa07a lightseagreen 20b2aa lightskyblue 87cefa lightslategray 778899 lightslategrey 778899 lightsteelblue b0c4de lightyellow ffffe0 lime 00ff00 limegreen 32cd32 linen faf0e6 magenta ff00ff maroon 800000 mediumaquamarine 66cdaa mediumblue 0000cd mediumorchid ba55d3 mediumpurple 9370db mediumseagreen 3cb371 mediumslateblue 7b68ee mediumspringgreen 00fa9a mediumturquoise 48d1cc mediumvioletred c71585 midnightblue 191970 mintcream f5fffa mistyrose ffe4e1 moccasin ffe4b5 navajowhite ffdead navy 000080 oldlace fdf5e6 olive 808000 olivedrab 6b8e23 orange ffa500 orangered ff4500 orchid da70d6 palegoldenrod eee8aa palegreen 98fb98 paleturquoise afeeee palevioletred db7093 papayawhip ffefd5 peachpuff ffdab9 peru cd853f pink ffc0cb plum dda0dd powderblue b0e0e6 purple 800080 rebeccapurple 663399 red ff0000 rosybrown bc8f8f royalblue 4169e1 saddlebrown 8b4513 salmon fa8072 sandybrown f4a460 seagreen 2e8b57 seashell fff5ee sienna a0522d silver c0c0c0 skyblue 87ceeb slateblue 6a5acd slategray 708090 slategrey 708090 snow fffafa springgreen 00ff7f steelblue 4682b4 tan d2b48c teal 008080 thistle d8bfd8 tomato ff6347 turquoise 40e0d0 violet ee82ee wheat f5deb3 white ffffff whitesmoke f5f5f5 yellow ffff00 yellowgreen 9acd32".split(" ").reduce((e,f,d,a)=>(d%2===0&&e.push([f,`#${a[d+1]}`]),e),[])),c=["#4472c4","#ed7d31","#a5a5a5","#ffc000","#5b9bd5","#70ad47"],l=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0"),t=e=>[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)];function b(e,f,d){const a=t(e),n=t(f);return`#${l(a[0]+(n[0]-a[0])*d)}${l(a[1]+(n[1]-a[1])*d)}${l(a[2]+(n[2]-a[2])*d)}`}function s(e){const[f,d,a]=t(e);return(.2126*f+.7152*d+.0722*a)/255}function u(e){const f=String(e).trim().toLowerCase();if(f==="")return null;if(f[0]==="#"){const r=f.slice(1);return/^[0-9a-f]+$/.test(r)?r.length===3||r.length===4?`#${[...r].map(i=>i+i).join("")}`:r.length===6||r.length===8?f:null:null}const d=o.get(f);if(d!==void 0)return d;const a=/^rgba?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)\s*(?:[,/]\s*(\d*\.?\d+)\s*)?\)$/.exec(f);if(a){const r=a[4]===void 0?"":l(Number(a[4])*255);return`#${l(Number(a[1]))}${l(Number(a[2]))}${l(Number(a[3]))}${r==="ff"?"":r}`}const n=/^accent\s*([1-6])(?:\s+(\d{1,2}))?$/.exec(f);if(n){const r=c[Number(n[1])-1];return n[2]===void 0?r:b(r,"#ffffff",Number(n[2])/100)}return null}function g(e){const f=l(s(e)*255);return`#${f}${f}${f}${e.length===9?e.slice(7):""}`}export{c as ACCENTS,g as grayOf,s as luminance,b as mixColors,u as normalizeColor,t as rgbOf};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{partsToSerial as k,serialToParts as S}from"../core/numfmt.js";const d=n=>Number.isFinite(n)?Number(n.toPrecision(7)):null;function I(n){const i=new Array(n.length);for(let t=0;t<n.length;t++)i[t]=d(n[t]);return i}function L(n,i){const t=n.length;if(t<=i)return null;const e=Math.max(1,Math.floor((i-2)/2)),r=[0];for(let o=0;o<e;o++){const a=1+Math.floor(o*(t-2)/e),f=1+Math.floor((o+1)*(t-2)/e);let c=-1,s=-1;for(let l=a;l<f;l++){const h=n[l];Number.isNaN(h)||((c<0||h<n[c])&&(c=l),(s<0||h>n[s])&&(s=l))}c<0?r.push(a):c===s?r.push(c):r.push(Math.min(c,s),Math.max(c,s))}return r.push(t-1),r}function N(n){let i=0;const t=new Float64Array(n.length);for(let e=0;e<n.length;e++)Number.isNaN(n[e])||(t[i++]=n[e]);return t.subarray(0,i).sort()}function p(n,i){const t=n.length;if(t===0)return NaN;const e=i*(t-1),r=Math.floor(e);return r+1<t?n[r]+(e-r)*(n[r+1]-n[r]):n[t-1]}function g(n){const i=n.length;let t=0;for(let o=0;o<i;o++)t+=n[o];const e=t/i;let r=0;for(let o=0;o<i;o++)r+=(n[o]-e)**2;return{mean:e,sd:i>1?Math.sqrt(r/(i-1)):0}}const B=["5ns","7ns","tukey","bowley","sigma3"];function F(n,i){const t=N(n),e=t.length;if(e===0)return null;const{mean:r,sd:o}=g(t),a=p(t,.25),f=p(t,.5),c=p(t,.75),s={q1:a,median:f,q3:c,low:t[0],high:t[e-1],mean:r,outliers:[],extremes:[],min:t[0],max:t[e-1]},l=(h,u)=>{for(let b=0;b<e;b++){const m=t[b];m<u[0]||m>u[1]?s.extremes.push(m):(m<h[0]||m>h[1])&&s.outliers.push(m)}};switch(i){case"7ns":s.low=p(t,.02),s.high=p(t,.98),s.hatchLow=p(t,.09),s.hatchHigh=p(t,.91),l([s.low,s.high],[-1/0,1/0]);break;case"tukey":{const h=c-a,u=[a-1.5*h,c+1.5*h];let b=a,m=c;for(let M=0;M<e;M++)t[M]>=u[0]&&t[M]<b&&(b=t[M]),t[M]<=u[1]&&t[M]>m&&(m=t[M]);s.low=b,s.high=m,l(u,[a-3*h,c+3*h]);break}case"bowley":s.hatchLow=p(t,.1),s.hatchHigh=p(t,.9);break;case"sigma3":s.q1=r-o,s.median=r,s.q3=r+o,s.low=Math.max(r-2*o,t[0]),s.high=Math.min(r+2*o,t[e-1]),l([r-2*o,r+2*o],[r-3*o,r+3*o]);break;default:break}return s}function x(n){if(!(n>0)||!Number.isFinite(n))return 1;const i=10**Math.floor(Math.log10(n)),t=n/i;return(t<=1?1:t<=2?2:t<=2.5?2.5:t<=5?5:10)*i}const w=256;function H(n,i,t){const e=N(n),r=e.length;if(r===0)return null;if(!i){const l=[],h=[];for(let u=0;u<r;u++)u>0&&e[u]===e[u-1]?h[h.length-1]++:(l.push(e[u]),h.push(1));if(l.length<=w)return{values:l,counts:h}}let o=t;if(!(o>0)){const{sd:l}=g(e);o=x(l>0?3.5*l/Math.cbrt(r):1)}let a=Math.floor(e[0]/o)*o,f=Math.ceil(e[r-1]/o)*o;for(f<=a&&(f=a+o);(f-a)/o>w;)o=x(o*1.01),a=Math.floor(e[0]/o)*o,f=Math.ceil(e[r-1]/o)*o;const c=Math.max(1,Math.round((f-a)/o)),s=new Array(c).fill(0);for(let l=0;l<r;l++){const h=Math.ceil((e[l]-a)/o-1e-9)-1;s[Math.max(0,Math.min(c-1,h))]++}return{lo:a,width:o,counts:s}}function P(n,i,t){let e=0,r=0,o=0,a=0,f=0,c=!1;for(let s=0;s<n.length;s++){const l=Number.isNaN(n[s])?0:n[s],h=t?.[s],u=h==="="?0:e;h==="-"?e-=Math.abs(l):h==="+"?e+=Math.abs(l):h!=="="&&(e+=l),r=Math.min(r,e),o=Math.max(o,e),s===i&&(a=u,f=e,c=h==="=")}return{from:a,to:f,min:r,max:o,total:c}}function T(n,i){let t=0,e=0,r=1;const o=Math.abs(Number.isNaN(n[i])?0:n[i]);for(let a=0;a<n.length;a++){const f=Math.abs(Number.isNaN(n[a])?0:n[a]);t+=f,a<i&&(e+=f),f>o&&r++}return t===0?{from:0,to:0,share:0,rank:r}:{from:e/t,to:(e+o)/t,share:o/t,rank:r}}function X(n,i,t,e){const r=new Array(e).fill(null),o=Math.min(n.length,i.length);for(let a=0;a<o;a++){const f=i[a];if(Number.isNaN(f)||Number.isNaN(n[a]))continue;const c=Math.floor(n[a])-t;c>=0&&c<e&&(r[c]=(r[c]??0)+f)}return r}const y=n=>n%4===0&&n%100!==0||n%400===0;function q(n,i){return[31,y(n)?29:28,31,30,31,30,31,31,30,31,30,31][i-1]}function _(n,i){const t=k(n,i||1,1),e=i?q(n,i):y(n)?366:365;return{first:t,count:e,weekday:S(t).weekday}}export{B as BOX_CLASSES,F as boxStats,_ as calendarSpan,P as cascadeStep,I as compactList,X as daySums,q as daysInMonth,H as histogramBins,x as niceStep,T as paretoStep,p as quantile,L as reduceIndices,d as short,N as sortedNumbers};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{safeJson as o}from"../io/xml-escape.js";import{mayReach as n}from"../core/online.js";const e="@@8cSP1:",i=32e3,c=t=>t.startsWith(e),l=(t,r)=>`${e}${o({k:t,...r})}`;function s(t){if(!t.startsWith(e))return null;try{const r=JSON.parse(t.slice(e.length));return r!==null&&typeof r=="object"&&typeof r.k=="string"?r:null}catch{return null}}const u=t=>s(t)===null?t:"",f=t=>typeof t=="string"&&(/^data:image\//i.test(t)||/^https:\/\//i.test(t)&&n(t));export{i as MAX_DESCRIPTOR,e as SPARK_PREFIX,f as imageSourceAllowed,c as isSparklineText,s as parseSparkDescriptor,l as sparkDescriptor,u as sparklineDataText};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{parseCellRef as S}from"../core/address.js";import{Arr as z,Ref as T,RefList as R}from"../calc/values.js";import{paintSparklineData as H}from"./paint.js";function M(s,a,r){const{sheet:t}=s,{r0:n,c0:c,r1:f,c1:p}=a.trim(s),i=!r&&((t.rows.hiddenSizes?.size??0)>0||(t.cols.hiddenSizes?.size??0)>0),l=[];for(let d=n;d<=f;d++)if(!(i&&t.rows.isHidden(d)))for(let y=c;y<=p;y++){if(i&&t.cols.isHidden(y))continue;const o=a.read(t,d,y);l.push(typeof o=="number"?o:null)}return l}function k(s,a,r,t,n,c=!0){if(!r)return[];const f=s.template(r,t,n),p=s.legacy;s.legacy=!1;try{let i=f.fn(t,n,a);return i instanceof R&&(i=i.refs[0]),i instanceof T?M(i,s,c):i instanceof z?i.data.map(l=>typeof l=="number"?l:null):typeof i=="number"?[i]:[]}catch{return[]}finally{s.legacy=p}}let v=0;const A=new WeakMap;function W(){v++}function b(s,a,r){const t=v+(a.rows.hiddenSizes?.size??0)*1e6;let n=A.get(r);if(n!==void 0&&n.stamp===t)return n;let c=1/0,f=-1/0;for(const p of r.items){const i=S(p.cell);if(i)for(const l of k(s,a,p.source,i.row,i.col,r.displayHidden===!0))l!==null&&(l<c&&(c=l),l>f&&(f=l))}return n={stamp:t,lo:c,hi:f},A.set(r,n),n}const E={line:"line",column:"column",stacked:"winloss"};function G(s,a,r,t,n,c,f,p,i,l,d,y){const{group:o}=t;let h=t.values??k(a,r,t.source,n,c,o.displayHidden===!0);if(!h.some(e=>e!==null))return;o.displayEmptyCellsAs==="zero"&&(h=h.map(e=>e??0));const m={excelAxis:1,color:o.seriesColor,negativecolor:o.negativeColor,markercolor:o.markerColor,firstcolor:o.firstColor??o.markerColor,lastcolor:o.lastColor??o.markerColor,highcolor:o.highColor??o.markerColor,lowcolor:o.lowColor??o.markerColor,axiscolor:o.axisColor,weight:o.lineWeight};for(const e of["markers","high","low","first","last","negative"])o[e]&&(m[e]=1);if(o.displayXAxis&&(m.axis=1),o.rightToLeft&&(m.rtl=1),o.displayEmptyCellsAs==="span"&&(m.empty="connect"),o.minAxisType==="custom"&&(m.min=o.manualMin),o.maxAxisType==="custom"&&(m.max=o.manualMax),o.minAxisType==="group"||o.maxAxisType==="group"){const e=b(a,r,o);o.minAxisType==="group"&&e.lo<=e.hi&&(m.min=e.lo),o.maxAxisType==="group"&&e.lo<=e.hi&&(m.max=e.hi)}const C={k:E[o.type]??"line",v:h,o:m};if(o.dateAxis&&o.dateRange){const e=k(a,r,o.dateRange,n,c,o.displayHidden===!0),x=[],w=Math.min(e.length,h.length);for(let u=0;u<w;u++)e[u]!==null&&x.push(u);if(x.sort((u,g)=>e[u]-e[g]),x.length>0){const u=e[x[0]];C.v=x.map(g=>h[g]),C.x=x.map(g=>e[g]-u)}}H(s,C,f,p,i,l,d,y)}export{W as invalidateSparklineScales,G as paintSparkline,k as sparklineValues};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{lift as q,raw as _,setCategory as pn}from"../calc/functions/registry.js";import{Arr as v,bool as B,ERR as a,num as U,numberToText as Mn,OMITTED as Cn,Ref as z,RefList as Y,str as F,XlError as T}from"../calc/values.js";import{formatGeneral as X,getFormatter as Kn}from"../core/numfmt.js";import{normalizeColor as nn}from"./colors.js";import{imageSourceAllowed as zn,MAX_DESCRIPTOR as Ln,sparkDescriptor as bn}from"./descriptor.js";import{BOX_CLASSES as Fn,boxStats as Tn,calendarSpan as In,cascadeStep as vn,compactList as tn,daySums as kn,histogramBins as Bn,paretoStep as Dn,reduceIndices as En,short as m}from"./data.js";pn("Sparkline");const Gn=4194304,Hn=[1024,512,256,128,64],Nn=48,$={notInExcel:!0},w={array:!0,notInExcel:!0},N=t=>t===void 0||t===Cn||t===null||t==="";function V(t,n){const e=bn(t,n);if(e.length>Ln)throw a.VALUE;return e}function J(t,n,e,s){if(N(n))return null;const r=n instanceof z||n instanceof Y||n instanceof v?t.scalar(n,e,s):n;if(r instanceof T)throw r;return r===""||r===void 0?null:r}function A(t,n,e,s,r){const o=J(t,n,e,s);if(o===null)return r;const i=U(o);if(!Number.isFinite(i))throw a.NUM;return i}function P(t,n,e,s,r){const o=J(t,n,e,s);return o===null?r:B(o)}function G(t,n,e,s,r){const o=J(t,n,e,s);return o===null?r:F(o)}function M(t){if(N(t))return;const n=nn(F(t));if(n===null)throw a.VALUE;return n}const S=(t,n,e,s)=>M(J(t,n,e,s));function W(t){if(t!==void 0){if(!(t>0&&t<=1))throw a.VALUE;return t}}const y=t=>t?1:void 0,Xn=t=>(t.rows.hiddenSizes?.size??0)>0||(t.cols.hiddenSizes?.size??0)>0||(t.filteredRows?.size??0)>0;function gn(t,n,e){const s=new Int32Array(t);let r=0;for(let o=0;o<t;o++)s[o]=e(n+o)?-1:r++;return{map:s,count:r}}function yn(t,n,e,s){const{sheet:r}=n;let{rows:o,cols:i}=n;if(o*i>65536){const f=t.trim(n);if(o=f.r1-f.r0+1,i=f.c1-f.c0+1,o*i>Gn)throw a.VALUE}let u=null,l=null;if(!s&&Xn(r)){const f=gn(o,n.r0,h=>r.rows.isHidden(h)||r.filteredRows?.has(h)),c=gn(i,n.c0,h=>r.cols.isHidden(h));u=f.map,l=c.map,o=f.count,i=c.count}const d=new Float64Array(o*i).fill(NaN);return t.scan(n,(f,c,h)=>{if(typeof f!="number")return;const E=u===null?c-n.r0:u[c-n.r0],p=l===null?h-n.c0:l[h-n.c0];E<0||p<0||E>=o||p>=i||(d[e?E*i+p:p*o+E]=f)}),d}function jn(t,n){const{rows:e,cols:s,data:r}=t,o=new Float64Array(e*s);for(let i=0;i<e;i++)for(let u=0;u<s;u++){const l=r[i*s+u];o[n?i*s+u:u*e+i]=typeof l=="number"?l:NaN}return o}function C(t,n,e=!1,s=!1){if(n instanceof T)throw n;if(n instanceof z)return yn(t,n,e,s);if(n instanceof v)return jn(n,e);if(n instanceof Y){const r=n.refs.map(u=>yn(t,u,e,s)),o=new Float64Array(r.reduce((u,l)=>u+l.length,0));let i=0;for(const u of r)o.set(u,i),i+=u.length;return o}return N(n)?new Float64Array(0):Float64Array.of(typeof n=="number"?n:typeof n=="boolean"?NaN:Number(U(n)))}function D(t,n){if(N(n))return null;if(n instanceof z||n instanceof v)return t.toArr(n).data;if(n instanceof Y)throw a.VALUE;return[n]}const Sn=t=>(t==null||t instanceof T?"":F(t)).slice(0,Nn);function en(t,n){const e=D(t,n);return e===null?void 0:e.map(s=>N(s)||s instanceof T?null:nn(F(s)))}function sn(t){for(let n=0;n<t.length;n++)if(!Number.isNaN(t[n]))return!0;return!1}function on(t,n){if(n===null)return t;const e=new Float64Array(n.length);for(let s=0;s<n.length;s++)e[s]=t[n[s]];return e}function rn(t,n){for(const e of Hn){const s=bn(t,n(e));if(s.length<=Ln)return s}throw a.VALUE}function un(t,n,e,s,r){if(n instanceof z&&!n.isCell||n instanceof v&&n.data.length>1){const o=t.toArr(n);return new v(o.rows,o.cols,o.data.map(i=>{try{return i instanceof T?i:i===null?a.VALUE:r(U(i))}catch(u){if(u instanceof T)return u;throw u}}))}return r(A(t,n,e,s,NaN))}const qn=new Set(["axis","markers","first","last","high","low","negative","hidden","rtl"]),Yn=new Set(["color","negativecolor","axiscolor","markercolor","firstcolor","lastcolor","highcolor","lowcolor"]);function $n(t){const n={};for(const e of t.split(/[\s,;]+/)){if(e==="")continue;const s=e.indexOf("="),r=(s<0?e:e.slice(0,s)).toLowerCase(),o=s<0?"":e.slice(s+1);if(qn.has(r)){if(!["","0","1","true","false"].includes(o.toLowerCase()))throw a.VALUE;n[r]=o===""||o==="1"||o.toLowerCase()==="true"?1:0}else if(Yn.has(r)){if(n[r]=M(o),n[r]===void 0)throw a.VALUE}else if(r==="empty"){if(!["gap","zero","connect"].includes(o.toLowerCase()))throw a.VALUE;n.empty=o.toLowerCase()}else if(r==="weight"||r==="min"||r==="max"){if(o.toLowerCase()==="auto")continue;const i=o===""?NaN:Number(o);if(!Number.isFinite(i)||r==="weight"&&i<=0)throw a.VALUE;n[r]=i}else throw a.VALUE}return n}function Jn(t,n){const e=Math.min(t.length,n.length),s=[];for(let i=0;i<e;i++)Number.isNaN(t[i])||s.push(i);s.sort((i,u)=>t[i]-t[u]);const r=new Float64Array(s.length),o=new Float64Array(s.length);return s.forEach((i,u)=>{r[u]=t[i],o[u]=n[i]}),{x:r,v:o}}function fn(t,n){_(t,1,6,(e,s,r,o)=>{const i=$n(G(e,s[4],r,o,"")),u=A(e,s[1],r,o,0)===1,l=i.hidden===1;let d=C(e,s[0],u,l);if(!sn(d))return"";let f=null;if(!N(s[2])){const h=C(e,s[2],A(e,s[3],r,o,0)===1,l);({x:f,v:d}=Jn(h,d))}if(i.empty==="zero"&&(d=d.map(h=>Number.isNaN(h)?0:h)),delete i.hidden,!N(s[5])){const h=C(e,s[5],!1,l);let E=1/0,p=-1/0;for(let b=0;b<h.length;b++)h[b]<E&&(E=h[b]),h[b]>p&&(p=h[b]);E<=p&&(i.min??=E,i.max??=p)}const c=f!==null&&f.length>0?f[0]:0;return rn(n,h=>{const E=En(d,h);return{v:tn(on(d,E)),x:f===null?void 0:tn(on(f,E).map(p=>p-c)),o:i}})},w)}fn("SPARK_LINE","line"),fn("SPARK_COLUMN","column"),fn("SPARK_WINLOSS","winloss"),_("SPARK_AREA",1,7,(t,n,e,s)=>{const r=C(t,n[0]);if(!sn(r))return"";const o={lo:A(t,n[1],e,s,void 0),hi:A(t,n[2],e,s,void 0),l1:A(t,n[3],e,s,void 0),l2:A(t,n[4],e,s,void 0),c:S(t,n[5],e,s),n:S(t,n[6],e,s)};if(o.lo!==void 0&&o.hi!==void 0&&o.lo>=o.hi)throw a.VALUE;return rn("area",i=>({v:tn(on(r,En(r,i))),...o}))},w),_("SPARK_PIE",1,255,(t,n,e,s)=>{const r=n[0]instanceof z?!n[0].isCell:n[0]instanceof v||n[0]instanceof Y,o=[];for(let l=1;l<n.length;l++){const d=D(t,n[l]);if(d!==null)for(const f of d)o.push(M(f))}if(!r){const l=A(t,n[0],e,s,0);return V("pie",{s:m(Math.max(0,Math.min(1,l))),c:o.length>0?o:void 0})}const i=C(t,n[0]),u=[];for(let l=0;l<i.length&&u.length<256;l++)i[l]>0&&u.push(m(i[l]));return u.length===0?"":V("pie",{v:u,c:o.length>0?o:void 0})},w);function Rn(t,n){if(N(n))return null;const e=n.rows??1,s=n.cols??1,r=[],o=[];if(e===1||s===1){const d=C(t,n,s>1,!0);for(let f=0;f<d.length;f++)Number.isNaN(d[f])||(r.push(f+1),o.push(d[f]));return{xs:r,ys:o}}const i=e===2&&s>2,u=C(t,n,i,!0),l=u.length/(i?2:s);for(let d=0;d<l;d++){const f=u[d],c=u[l+d];Number.isNaN(f)||Number.isNaN(c)||(r.push(f),o.push(c))}return{xs:r,ys:o}}function Un(t,n){if(t===null)return;const e=t.xs.length,s=Math.max(1,Math.ceil(e/n)),r=[],o=[];for(let i=0;i<e;i+=s)r.push(m(t.xs[i])),o.push(m(t.ys[i]));return{x:r,y:o}}_("SPARK_SCATTER",1,18,(t,n,e,s)=>{const r=Rn(t,n[0]),o=Rn(t,n[1]);if((r===null||r.xs.length===0)&&(o===null||o.xs.length===0))return"";const i=d=>A(t,n[d],e,s,void 0),u=[i(8),i(9),i(10),i(11)],l={x0:i(2),x1:i(3),y0:i(4),y1:i(5),h:i(6),v:i(7),z:u.every(d=>d!==void 0)?u:void 0,tags:y(P(t,n[12],e,s,!1)),nosym:y(!P(t,n[13],e,s,!0)),lines:y(P(t,n[14],e,s,!1)),c1:S(t,n[15],e,s),c2:S(t,n[16],e,s),dash:y(P(t,n[17],e,s,!1))};return rn("scatter",d=>({a:Un(r,d),b:Un(o,d),...l}))},w),q("SPARK_BULLET",3,17,(t,n,e,s,r,o,i,u,l,d,f,c,h,E,p,b,L)=>{const g=U(e);if(!(g>0))throw a.VALUE;const R=O=>N(O)?void 0:U(O);return V("bullet",{m:m(U(t)),t:m(U(n)),x:m(g),g:R(s),b:R(r),f:R(o),u:R(i),c:M(u),vert:y(!N(l)&&B(l)),mc:M(d),tc:M(f),xc:M(c),gc:M(h),bc:M(E),fc:M(p),over:y(!N(b)&&B(b)),size:W(R(L))})},$);const Wn=[1,2,3,4,5,6];_("SPARK_SPREAD",1,7,(t,n,e,s)=>{const r=C(t,n[0]);if(!sn(r))return"";const o=A(t,n[4],e,s,4);if(!Wn.includes(o))throw a.VALUE;let i=A(t,n[2],e,s,void 0),u=A(t,n[3],e,s,void 0),l=0,d=0,f=1/0,c=-1/0;for(const g of r)Number.isNaN(g)||(l+=g,d++,g<f&&(f=g),g>c&&(c=g));if(i??=f,u??=c,u<i)throw a.VALUE;const h=256,E=new Array(h).fill(0),p=u-i;for(const g of r)Number.isNaN(g)||g<i||g>u||E[p===0?0:Math.min(h-1,Math.floor((g-i)/p*h))]++;const b=[],L=[];return E.forEach((g,R)=>{g>0&&(b.push(R),L.push(g))}),V("spread",{at:b,n:L,slots:h,avg:P(t,n[1],e,s,!1)&&p>0?m((l/d-i)/p):void 0,st:o,c:S(t,n[5],e,s),vert:y(P(t,n[6],e,s,!1))})},w),_("SPARK_STACKED",1,13,(t,n,e,s)=>{const r=C(t,n[0]),o=[];let i=0;for(let f=0;f<r.length&&f<256;f++){const c=Number.isNaN(r[f])||r[f]<0?0:r[f];o.push(m(c)),i+=c}if(i===0)return"";const u=D(t,n[2]),l=f=>A(t,n[f],e,s,void 0),d=l(3)??i;if(!(d>0))throw a.VALUE;return V("stacked",{v:o,cs:en(t,n[1]),l:u?.slice(0,o.length).map(Sn),x:m(d),t:[l(4),l(5),l(6),l(7)].map(f=>f===void 0?null:f),c:S(t,n[8],e,s),hl:l(9),vert:y(P(t,n[10],e,s,!1)),tv:y(A(t,n[11],e,s,0)===1),ts:l(12)})},w);const Vn=(t,n)=>q(t,1,4,(e,s,r,o)=>V(n,{v:m(U(e)),c:M(s),noaxis:y(!N(r)&&!B(r)),size:W(N(o)?void 0:U(o))}),$);Vn("SPARK_HBAR","hbar"),Vn("SPARK_VBAR","vbar"),_("SPARK_BOXPLOT",1,10,(t,n,e,s)=>{const r=G(t,n[1],e,s,"5ns").toLowerCase();if(!Fn.includes(r))throw a.VALUE;const o=A(t,n[8],e,s,0);if(o!==0&&o!==1)throw a.VALUE;const i=Tn(C(t,n[0]),r);if(i===null)return"";const u=c=>A(t,n[c],e,s,void 0),l=u(3)??i.min,d=u(4)??i.max;if(d<l)throw a.VALUE;const f=c=>{if(c.length===0)return;const h=Math.max(1,Math.ceil(c.length/128)),E=[];for(let p=0;p<c.length;p+=h)E.push(m(c[p]));return E};return V("boxplot",{q:[i.low,i.q1,i.median,i.q3,i.high].map(m),hatch:i.hatchLow===void 0?void 0:[m(i.hatchLow),m(i.hatchHigh)],out:f(i.outliers),ext:f(i.extremes),avg:P(t,n[2],e,s,!1)?m(i.mean):void 0,lo:m(l),hi:m(d),band:u(5)!==void 0&&u(6)!==void 0?[m(u(5)),m(u(6))]:void 0,c:S(t,n[7],e,s),st:o||void 0,vert:y(P(t,n[9],e,s,!1))})},w);const Q=t=>`${X(Number((t*100).toFixed(1)))}%`;q("SPARK_VARIANCE",1,10,(t,n,e,s,r,o,i,u,l,d)=>{const f=N(e)?-1:U(e),c=N(s)?1:U(s);if(!(f<c))throw a.VALUE;return V("variance",{v:m(U(t)),r:N(n)?0:m(U(n)),lo:m(f),hi:m(c),mk:N(r)?void 0:m(U(r)),u:N(o)?void 0:U(o),l:!N(i)&&B(i)?Q(U(t)):void 0,c:M(u),n:M(l),vert:y(!N(d)&&B(d))})},$);function ln(t,n,e){return s=>{const r=Math.trunc(s)-e;if(!(r>=0&&r<t.length))throw a.VALUE;return n(r)}}_("SPARK_CASCADE",2,10,(t,n,e,s)=>{const r=C(t,n[0]);if(r.length===0)return"";const o=D(t,n[2]),i=D(t,n[8])?.map(f=>N(f)?null:F(f).trim());if(i?.some(f=>f!==null&&!["+","-","="].includes(f)))throw a.VALUE;const u=A(t,n[3],e,s,void 0),l=A(t,n[4],e,s,void 0),d={c:S(t,n[5],e,s),n:S(t,n[6],e,s),vert:y(P(t,n[7],e,s,!1)),tc:S(t,n[9],e,s)};return un(t,n[1],e,s,ln(r,f=>{const c=vn(r,f,i);return V("cascade",{f:m(c.from),t:m(c.to),lo:m(u!==void 0&&u<c.min?u:c.min),hi:m(l!==void 0&&l>c.max?l:c.max),total:y(c.total),end:y(f===0||f===r.length-1),nx:y(f<r.length-1),pv:y(f>0),l:o?.[f]===void 0?void 0:Sn(o[f]),...d})},1))},w),_("SPARK_PARETO",2,12,(t,n,e,s)=>{const r=C(t,n[0]);if(r.length===0)return"";const o=en(t,n[2]),i=A(t,n[6],e,s,0);if(![0,1,2].includes(i))throw a.VALUE;const u=A(t,n[5],e,s,void 0),l={t1:A(t,n[3],e,s,void 0),t2:A(t,n[4],e,s,void 0),vert:y(P(t,n[7],e,s,!1)),c1:S(t,n[8],e,s),c2:S(t,n[9],e,s),lc:S(t,n[10],e,s),size:W(A(t,n[11],e,s,void 0))};return un(t,n[1],e,s,ln(r,d=>{const f=Dn(r,d);return V("pareto",{f:m(f.from),t:m(f.to),c:o?.[d]??void 0,hl:y(u===f.rank),l:i===1?Q(f.to):i===2?Q(f.share):void 0,...l})},1))},w),_("SPARK_LOLLIPOP",3,13,(t,n,e,s)=>{const r=C(t,n[0]),o=C(t,n[1]),i=Math.min(r.length,o.length);if(i===0)return"";const u=p=>{const b=r[p],L=o[p];return Number.isNaN(b)||Number.isNaN(L)?NaN:b===0?L===0?0:Math.sign(L):(L-b)/Math.abs(b)},l=P(t,n[3],e,s,!1);let d=A(t,n[5],e,s,-1),f=A(t,n[6],e,s,1),c=A(t,n[4],e,s,0);if(l){let p=0;for(let b=0;b<i;b++){const L=o[b]-r[b];Math.abs(L)>p&&(p=Math.abs(L))}d=-p||-1,f=p||1,c=0}if(!(d<f))throw a.VALUE;const h={r:m(c),lo:m(d),hi:m(f),u:A(t,n[7],e,s,void 0),c:S(t,n[9],e,s),n:S(t,n[10],e,s),hc:S(t,n[11],e,s),vert:y(P(t,n[12],e,s,!1))},E=P(t,n[8],e,s,!1);return un(t,n[2],e,s,ln(r.subarray(0,i),p=>{const b=l?o[p]-r[p]:u(p);return Number.isNaN(b)?"":V("lollipop",{v:m(b),l:E?l?X(m(b)):Q(b):void 0,...h})},0))},w);function On(t,n,e,s,r,o,i,u){const l=Math.trunc(o);if(!(l>=1900&&l<=9999))throw a.VALUE;const d=In(l,i),f=u instanceof z||u instanceof v?u:null;if(f===null)throw a.VALUE;const c=f.rows===2&&f.cols>2,h=C(t,f,c,!0);if((c?f.rows:f.cols)<2)throw a.VALUE;const E=h.length/(c?f.rows:f.cols),p=h.subarray(0,E),b=h.subarray(E,E*2),L=kn(p,b,d.first,d.count).map(R=>R===null?null:m(R)),g=en(t,n[e+4]);return{d:L,wd:d.weekday,c0:S(t,n[e],s,r),c1:S(t,n[e+1],s,r),c2:S(t,n[e+2],s,r),c3:S(t,n[e+3],s,r),st:g?.filter(R=>R!==null)}}_("SPARK_MONTH",3,8,(t,n,e,s)=>{const r=Math.trunc(A(t,n[1],e,s,0));if(!(r>=1&&r<=12))throw a.VALUE;return V("month",On(t,n,3,e,s,A(t,n[0],e,s,0),r,n[2]))},w),_("SPARK_YEAR",2,7,(t,n,e,s)=>V("year",On(t,n,2,e,s,A(t,n[0],e,s,0),0,n[1])),w),_("SPARK_HISTOGRAM",1,9,(t,n,e,s)=>{const r=P(t,n[1],e,s,!0),o=A(t,n[3],e,s,0),i=Bn(C(t,n[0]),r,o<0?1:o);if(i===null)return"";const u=P(t,n[2],e,s,!1);let l;return u&&(l=i.values?i.values.map(d=>X(m(d))):i.counts.map((d,f)=>X(m(i.lo+(f+1)*i.width)))),V("histogram",{n:i.counts,l,size:W(A(t,n[4],e,s,void 0)),c:S(t,n[5],e,s),ts:A(t,n[6],e,s,void 0),lc:S(t,n[7],e,s),ec:S(t,n[8],e,s)})},w);function Qn(t){if(N(t))return null;const n=/^\s*((?:(?:italic|oblique|bold|normal|[1-9]00)\s+)*)(\d+(?:\.\d+)?)(?:px|pt)?(?:\s+(.+))?$/i.exec(F(t));if(n===null)throw a.VALUE;const e=n[3]?.trim();return{z:Number(n[2]),b:y(/bold|[6-9]00/i.test(n[1])),i:y(/italic|oblique/i.test(n[1])),f:e&&/^["'\w ,.-]{1,64}$/.test(e)?e:void 0}}function Zn(t,n,e,s){const r=[];for(const o of n){const i=D(t,o);if(i!==null){if(i.length%3!==0)throw a.VALUE;for(let u=0;u<i.length;u+=3){const l=U(i[u]),d=U(i[u+1]);if(!(l<d)||l<e||d>s)throw a.VALUE;r.push([m(l),m(d),M(i[u+2])])}}}return r.length>0?r:void 0}_("SPARK_GAUGE",4,64,(t,n,e,s)=>{const r=A(t,n[0],e,s,NaN),o=A(t,n[1],e,s,NaN),i=A(t,n[2],e,s,NaN),u=A(t,n[3],e,s,NaN);if(!(i<u)||Number.isNaN(r)||Number.isNaN(o))throw a.VALUE;const l=A(t,n[13],e,s,0);if(![0,1,2].includes(l))throw a.VALUE;const d=A(t,n[10],e,s,-90),f=A(t,n[11],e,s,90);if(!(d<f))throw a.VALUE;const c=A(t,n[12],e,s,void 0);if(c!==void 0&&!(c>=0&&c<=1))throw a.VALUE;const h=(b,L)=>G(t,n[b],e,s,Mn(L)).slice(0,Nn),E=P(t,n[4],e,s,!0),p=D(t,n[9]);return V("gauge",{t:m(r),v:m(o),lo:m(i),hi:m(u),l:E?[h(5,r),h(6,o),h(7,i),h(8,u)]:void 0,fn:p?.slice(0,4).map(Qn),a0:l===0?d:void 0,a1:l===0?f:void 0,ir:c,ty:l||void 0,bands:Zn(t,n.slice(14),i,u)})},w),_("SPARK_IMAGE",1,11,(t,n,e,s)=>{const r=G(t,n[0],e,s,"");if(r==="")return"";if(!zn(r))throw a.VALUE;const o=A(t,n[2],e,s,0),i=h=>A(t,n[h],e,s,void 0);if(![0,1,2,3].includes(o))throw a.VALUE;const u=i(3),l=i(4);if(o===3&&!(u>0||l>0))throw a.VALUE;const d=A(t,n[9],e,s,1),f=A(t,n[10],e,s,1);if(![0,1,2].includes(d)||![0,1,2].includes(f))throw a.VALUE;const c=[i(5),i(6),i(8),i(7)];return V("image",{src:r,alt:G(t,n[1],e,s,void 0)?.slice(0,256),sz:o||void 0,h:o===3?u:void 0,w:o===3?l:void 0,clip:c.some(h=>h!==void 0)?c.map(h=>h??null):void 0,va:d,ha:f})},w);const xn=15;q("SPARK_PROGRESS",1,5,(t,n,e,s,r)=>{const o=t===null?0:U(t),i=N(n)?0:Math.trunc(U(n));if(!(i>=0&&i<xn))throw a.VALUE;return V("progress",{v:m(Math.max(0,Math.min(1,o))),m:i||void 0,c:M(e),n:M(s),hide:y(!N(r)&&!B(r))})},$);const nt=400,tt=/\{([^{}]{1,96})\}/g,et=256;function dn(t,n){let e=t;for(const s of String(n).split(".").flatMap(r=>r.split(/[[\]]/).filter(Boolean))){if(typeof e=="string"&&/^\s*[{[]/.test(e))try{e=JSON.parse(e)}catch{return}if(e===null||typeof e!="object")return;if(Object.hasOwn(e,s))e=e[s];else{const r=Object.keys(e).find(o=>o.toLowerCase()===s.toLowerCase());if(r===void 0)return;e=e[r]}}return e}function st(t,n,e,s,r){const o={};if(N(n))return o;if(!(n instanceof z)&&!(n instanceof v)){const u=G(t,n,s,r,"").trim();return u===""?o:Pn(u)}if(n instanceof z&&n.isCell&&N(e)){const u=t.read(n.sheet,n.r0,n.c0);if(u instanceof T)throw u;if(typeof u=="string"&&u.trim().startsWith("{"))return Pn(u)}const i=t.toArr(n);if(!N(e))t.toArr(e).data.forEach((l,d)=>{!N(l)&&!(l instanceof T)&&(o[F(l)]=i.data[d]??null)});else if(i.rows===2)for(let u=0;u<i.cols;u++)N(i.get(0,u))||(o[F(i.get(0,u))]=i.get(1,u));else if(i.cols===2)for(let u=0;u<i.rows;u++)N(i.get(u,0))||(o[F(i.get(u,0))]=i.get(u,1));else i.data.forEach((u,l)=>{o[l+1]=u});return o}function Pn(t){let n;try{n=JSON.parse(t)}catch{throw a.VALUE}if(n===null||typeof n!="object")throw a.VALUE;return n}function cn(t,n){return t==null?"":t instanceof T?t.code:typeof t=="number"?n.numFmt==="General"?X(t):Kn(n.numFmt).number(t):typeof t=="boolean"?t?"TRUE":"FALSE":typeof t=="object"?JSON.stringify(t):String(t)}const hn=t=>typeof t=="string"?nn(t)??void 0:void 0;function Z(t){if(!(!t||t.style===void 0))return[{thick:2,medium:1.5}[t.style]??1,hn(t.color)??null]}function it(t,n,e,s){for(const r of n.dataBindings??[]){const o=r.pathAt?.(e,s);if(o)return o}for(const r of t.dataSheets?.reports??[]){if(r.sheet!==n)continue;const o=r.binding?.(e,s);if(o?.field)return o.field}return null}const ot=t=>t.startsWith("@@8c")||/^(?:data:image\/|https:\/\/)/i.test(t);_("SPARK_BLOCK",1,3,(t,n,e,s,r)=>{const o=n[0];if(!(o instanceof z))throw a.VALUE;const{r0:i,c0:u}=o,l=o.rows,d=o.cols;if(l*d>nt)throw a.VALUE;if(o.sheet===r&&e>=i&&e<=o.r1&&s>=u&&s<=o.c1)throw a.REF;const f=st(t,n[1],n[2],e,s),c=o.sheet,{book:h}=t,E=[],p=[];for(let L=0;L<d;L++)E.push(c.cols.isHidden(u+L)?0:c.cols.sizeOf(u+L));for(let L=0;L<l;L++)p.push(c.rows.isHidden(i+L)?0:c.rows.sizeOf(i+L));const b=[];for(let L=0;L<l;L++)for(let g=0;g<d;g++){const R=c.mergeAt(i+L,u+g);if(R!==null&&(R.r0!==i+L||R.c0!==u+g))continue;const O=h.styles.list[c.style(i+L,u+g)]??h.styles.list[0];let k=t.read(c,i+L,u+g);const an=it(h,c,i+L,u+g);if(an!==null){const K=dn(f,an);K!==void 0&&(k=K)}let I;if(typeof k=="string"){const K=/^\{([^{}]{1,96})\}$/.exec(k),x=K===null?void 0:dn(f,K[1].trim());x!==void 0?(k=x,I=cn(x,O)):I=k.replace(tt,(_n,wn)=>{const An=dn(f,wn.trim());return An===void 0?_n:cn(An,O)})}else I=cn(k,O);const H=O.borders,j=H?[Z(H.t),Z(H.r),Z(H.b),Z(H.l)]:null,mn=hn(O.fill);I===""&&mn===void 0&&(j===null||j.every(K=>K===void 0))||b.push({r:L,c:g,rs:R?Math.min(R.r1,o.r1)-R.r0+1:void 0,cs:R?Math.min(R.c1,o.c1)-R.c0+1:void 0,t:I===""?void 0:ot(I)?I:I.slice(0,et),f:mn,i:hn(O.color),b:y(O.bold),it:y(O.italic),u:y(O.underline),w:y(O.wrap),z:O.fontSize===12?void 0:O.fontSize,a:O.hAlign??(typeof k=="number"?"right":void 0),va:O.vAlign,bd:j?.some(K=>K!==void 0)?j.map(K=>K??null):void 0})}return V("block",{w:E,h:p,cells:b})},w),pn("Other");export{xn as PROGRESS_MODES,$n as parseSettings,dn as valueAtPath};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{FONT_FALLBACK as k}from"../core/styles.js";import{grayOf as g,mixColors as v}from"./colors.js";const p={series:"#4472c4",negative:"#c00000",positive:"#548235",marker:"#ed7d31",second:"#a5a5a5",muted:"#d9d9d9",mutedInk:"#7f7f7f",surface:"#ffffff",chart:["#4472c4","#ed7d31","#a5a5a5","#ffc000","#5b9bd5","#70ad47"]},P={series:"#7fa8ec",negative:"#ff7575",positive:"#92d36e",marker:"#ffa45c",second:"#8f8f8f",muted:"#484848",mutedInk:"#a6a6a6",surface:"#1e1e1e",chart:["#7fa8ec","#ffa45c","#b5b5b5","#ffd24d","#86bdf0","#92d36e"]},i={s:1,snap:!0,ink:"#000000",mono:!1,pal:p};function $(e,n,a,r,t){i.s=e,i.snap=n,i.ink=a,i.mono=t,i.pal=r?P:p}const d=e=>i.mono?g(e):e,y=(e,n)=>v(e,i.pal.surface,n),H=e=>i.snap?Math.round(e):e,M=(e=1)=>i.snap?Math.max(1,Math.round(e*i.s)):Math.max(.25,e*i.s),W=(e=1)=>i.snap?Math.max(1,Math.round(e*i.s)):e*i.s;function m(e,n,a,r,t){if(i.snap){let o=Math.round(n),l=Math.round(r),f=Math.round(a),s=Math.round(t);l===o&&r>n&&(l=o+1),s===f&&t>a&&(s=f+1),e.rect(o,f,l-o,s-f)}else e.rect(n,a,r-n,t-a)}function w(e,n,a,r,t,o){e.fillStyle=d(o),e.beginPath(),m(e,n,a,r,t),e.fill()}const L=(e,n,a,r,t)=>({x:e,y:n,w:a,h:r,vertical:!!t,len:t?r:a,thick:t?a:r});function I(e,n,a,r,t,o){const l=Math.min(a,r),f=Math.max(a,r);n.vertical?m(e,n.x+t,n.y+n.h-f,n.x+o,n.y+n.h-l):m(e,n.x+l,n.y+t,n.x+f,n.y+o)}function S(e,n,a,r,t,o,l){e.fillStyle=d(l),e.beginPath(),I(e,n,a,r,t,o),e.fill()}function b(e,n,a,r,t,o,l=M()){const f=l/2,s=i.snap?Math.round(a-f):a-f;S(e,n,s,s+l,r,t,o)}const h=(e,n,a)=>e.vertical?e.x+a:e.x+n,c=(e,n,a)=>e.vertical?e.y+e.h-n:e.y+a;function O(e,n,a,r,t,o,l){e.fillStyle=d(l),e.beginPath(),e.moveTo(h(n,a+t*o,r),c(n,a+t*o,r)),e.lineTo(h(n,a,r-o*.7),c(n,a,r-o*.7)),e.lineTo(h(n,a,r+o*.7),c(n,a,r+o*.7)),e.closePath(),e.fill()}function C(e,n,a,r,t){e.fillStyle=d(t),e.beginPath(),e.arc(n,a,r,0,Math.PI*2),e.fill()}function T({size:e=9,bold:n,italic:a,family:r}){const t=i.snap?Math.max(1,Math.round(e*i.s)):e*i.s;return`${a?"italic ":""}${n?"bold ":""}${t}px ${r?`${r},`:""}${k}`}function F(e,n,a,r,t={}){const o=(t.size??9)*i.s;return o<4||t.maxH!==void 0&&o>t.maxH||(e.font=T(t),t.maxW!==void 0&&e.measureText(n).width>t.maxW)?!1:(e.textAlign=t.align??"center",e.textBaseline=t.base??"middle",e.fillStyle=d(t.color??i.ink),e.fillText(n,a,r),!0)}function K(e,n,a,r,t={}){const o=(t.size??9)*i.s;return o<4||t.maxH!==void 0&&o>t.maxH||(e.font=T(t),t.maxW!==void 0&&e.measureText(n).width>t.maxW)?!1:(e.save(),e.translate(a,r),e.rotate(-Math.PI/2),e.textAlign="center",e.textBaseline="middle",e.fillStyle=d(t.color??i.ink),e.fillText(n,0,0),e.restore(),!0)}function D(e,n,a,r,t,o,l){t>0?(e.moveTo(n+Math.cos(o)*r,a+Math.sin(o)*r),e.arc(n,a,r,o,l),e.arc(n,a,t,l,o,!0),e.closePath()):(e.moveTo(n,a),e.arc(n,a,r,o,l),e.closePath())}function E(e,n,a,r,t,o,l,f){if(!(t>0)||!(r>a))return;const s=n.len/(r-a);if(t*s<3*i.s)return;const x=M();for(let u=Math.ceil(a/t)*t;u<=r+t*1e-9;u+=t)b(e,n,(u-a)*s,o,l,f,x)}function G(e){let n=1/0,a=-1/0;for(let r=0;r<e.length;r++){const t=e[r];t!==null&&(t<n&&(n=t),t>a&&(a=t))}return n<=a?[n,a]:[0,0]}export{d as col,C as dot,F as drawText,K as drawTextUp,i as env,G as extent,w as fillBox,T as fontText,O as frameArrow,S as frameBox,L as frameOf,I as framePath,b as frameTick,h as frameX,c as frameY,W as inset,M as lineWidth,m as pathBox,D as pathSector,H as round,E as scaleTicks,$ as setEnv,y as tint};
|