@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{child as i,children as B,unescapeOoxml as te,unescapeXml as Ge}from"../io/xml-scan.js";import{escapeMarkup as U,xmlLiteralText as we,xmlText as Y}from"../io/xml-escape.js";import{colName as ve,MAX_COLS as ze,MAX_ROWS as ke,parseRangeRef as re,quoteSheetName as We}from"../core/address.js";import{CHARTEX_LAYOUT as Ne,chartExAxes as _e,writeChartExPart as Ve}from"../charts/chartex.js";import{NS as _,XML_HEAD as qe,parseSpPr as S,parseTextBody as E,parseXml as Le,plainText as ge,schemeColor as j,toBool as F,toNum as T,writeSpPr as D,writeTextBody as G}from"./dml.js";const ye=ke,V={varyColors:"b",marker:"b",smooth:"b",wireframe:"b",showNegBubbles:"b",bubble3D:"b",invertIfNegative:"b",gapWidth:"n",overlap:"n",gapDepth:"n",firstSliceAng:"n",holeSize:"n",bubbleScale:"n",splitPos:"n",secondPieSize:"n",explosion:"n",barDir:"s",grouping:"s",shape:"s",ofPieType:"s",splitType:"s",radarStyle:"s",scatterStyle:"s",sizeRepresents:"s"},se=e=>{const r=V[e.n];return r==="b"?F(e.a.val,!0):r==="n"?T(e.a.val):e.a.val},l=(e,r)=>r==null?"":`<c:${e} val="${typeof r=="boolean"?r?1:0:U(r)}"/>`,L=(e,r)=>i(e,r)?.a.val,w=(e,r,t)=>T(L(e,r),t),R=(e,r,t)=>{const s=i(e,r);return s?F(s.a.val,!0):t},Xe={barChart:["barDir","grouping","varyColors","ser","dLbls","gapWidth","overlap","serLines","axId","extLst"],bar3DChart:["barDir","grouping","varyColors","ser","dLbls","gapWidth","gapDepth","shape","axId","extLst"],lineChart:["grouping","varyColors","ser","dLbls","dropLines","hiLowLines","upDownBars","marker","smooth","axId","extLst"],line3DChart:["grouping","varyColors","ser","dLbls","dropLines","gapDepth","axId","extLst"],stockChart:["ser","dLbls","dropLines","hiLowLines","upDownBars","axId","extLst"],radarChart:["radarStyle","varyColors","ser","dLbls","axId","extLst"],scatterChart:["scatterStyle","varyColors","ser","dLbls","axId","extLst"],pieChart:["varyColors","ser","dLbls","firstSliceAng","extLst"],pie3DChart:["varyColors","ser","dLbls","extLst"],doughnutChart:["varyColors","ser","dLbls","firstSliceAng","holeSize","extLst"],ofPieChart:["ofPieType","varyColors","ser","dLbls","gapWidth","splitType","splitPos","custSplit","secondPieSize","serLines","extLst"],areaChart:["grouping","varyColors","ser","dLbls","dropLines","axId","extLst"],area3DChart:["grouping","varyColors","ser","dLbls","dropLines","gapDepth","axId","extLst"],bubbleChart:["varyColors","ser","dLbls","bubble3D","bubbleScale","showNegBubbles","sizeRepresents","axId","extLst"],surfaceChart:["wireframe","ser","bandFmts","axId","extLst"],surface3DChart:["wireframe","ser","bandFmts","axId","extLst"]},$e={barChart:"bar",bar3DChart:"bar",lineChart:"line",line3DChart:"line",stockChart:"stock",radarChart:"radar",scatterChart:"scatter",pieChart:"pie",pie3DChart:"pie",doughnutChart:"doughnut",ofPieChart:"ofPie",areaChart:"area",area3DChart:"area",bubbleChart:"bubble",surfaceChart:"surface",surface3DChart:"surface"},q={bar:["idx","order","tx","spPr","invertIfNegative","pictureOptions","dPt","dLbls","trendline","errBars","cat","val","shape","extLst"],line:["idx","order","tx","spPr","marker","dPt","dLbls","trendline","errBars","cat","val","smooth","extLst"],stock:["idx","order","tx","spPr","marker","dPt","dLbls","trendline","errBars","cat","val","smooth","extLst"],scatter:["idx","order","tx","spPr","marker","dPt","dLbls","trendline","errBars","xVal","yVal","smooth","extLst"],area:["idx","order","tx","spPr","pictureOptions","dPt","dLbls","trendline","errBars","cat","val","extLst"],pie:["idx","order","tx","spPr","explosion","dPt","dLbls","cat","val","extLst"],bubble:["idx","order","tx","spPr","invertIfNegative","dPt","dLbls","trendline","errBars","xVal","yVal","bubbleSize","bubble3D","extLst"],radar:["idx","order","tx","spPr","marker","dPt","dLbls","cat","val","extLst"],surface:["idx","order","tx","spPr","cat","val","extLst"]};q.doughnut=q.pie,q.ofPie=q.pie;function K(e,r){const t=Math.min(w(e,"ptCount",0),ye),s=new Array(t).fill(null);for(const a of B(e,"pt")){const n=T(a.a.idx,-1);if(n<0||n>=ye)continue;const d=te(i(a,"v")?.t??"");n>=s.length&&(s.length=n+1),s[n]=r?T(d,null):d,r&&d[0]==="#"&&(d==="#N/A"?(s.na??=new Set).add(n):s[n]=0)}for(let a=0;a<s.length;a++)s[a]===void 0&&(s[a]=null);return s}function Ce(e,r){const t=i(e,"extLst");return!t||!r?{}:e.c[0]===t?{refExtFirst:r.raw(t)}:{refExt:r.raw(t)}}function X(e,r){if(!e)return null;for(const t of e.c)switch(t.n){case"numRef":{const s=i(t,"numCache"),a=K(s,!0);return{kind:"num",ref:i(t,"f")?.t??"",cache:a,na:a.na,formatCode:i(s,"formatCode")?.t??"General",...Ce(t,r)}}case"strRef":return{kind:"str",ref:i(t,"f")?.t??"",cache:K(i(t,"strCache"),!1),...Ce(t,r)};case"numLit":return{kind:"num",ref:null,cache:K(t,!0),formatCode:i(t,"formatCode")?.t??"General"};case"strLit":return{kind:"str",ref:null,cache:K(t,!1)};case"multiLvlStrRef":{const s=i(t,"multiLvlStrCache"),a=B(s,"lvl").map(n=>{const d=w(s,"ptCount",0),u=new Array(d).fill(null);for(const c of B(n,"pt"))u[T(c.a.idx,0)]=te(i(c,"v")?.t??"");return u});return{kind:"multi",ref:i(t,"f")?.t??"",cache:a[0]??[],levels:a}}case"v":return{kind:"str",ref:null,cache:[te(t.t)]};default:}return null}function Z(e,r){if(!e)return;const t=i(e,"manualLayout");return t?{target:L(t,"layoutTarget")??"outer",xMode:L(t,"xMode")??"factor",yMode:L(t,"yMode")??"factor",x:w(t,"x"),y:w(t,"y"),w:w(t,"w"),h:w(t,"h"),raw:r.raw(e)}:{raw:r.raw(e)}}function Se(e,r){if(e)return{symbol:L(e,"symbol"),size:w(e,"size"),spPr:S(i(e,"spPr"),r)}}const Re=["showLegendKey","showVal","showCatName","showSerName","showPercent","showBubbleSize"];function Te(e,r,t){const s=i(e,"numFmt");s&&(t.numFmt={code:s.a.formatCode,linked:F(s.a.sourceLinked,!1)}),t.spPr=S(i(e,"spPr"),r),t.txPr=E(i(e,"txPr"),r),t.pos=L(e,"dLblPos");for(const d of Re){const u=R(e,d);u!==void 0&&(t[d]=u)}const a=i(e,"separator");a&&(t.separator=a.t);const n=i(e,"extLst");return n&&(t.extLst=r.raw(n)),t}function De(e,r){if(!e)return;const t={labels:[]};for(const s of B(e,"dLbl")){const a={idx:w(s,"idx",0)};if(R(s,"delete"))a.delete=!0;else{const n=i(s,"tx");n&&(a.tx=E(i(n,"rich"),r),a.txSource=X(n,r),a.txRaw=r.raw(n)),a.layout=Z(i(s,"layout"),r),Te(s,r,a)}t.labels.push(a)}if(R(e,"delete"))t.delete=!0;else{Te(e,r,t);const s=R(e,"showLeaderLines");s!==void 0&&(t.showLeaderLines=s);const a=i(e,"leaderLines");a&&(t.leaderLines=r.raw(a))}return t}function He(e,r){const t={idx:w(e,"idx",0),rawParts:{}};for(const s of e.c)s.n!=="idx"&&(s.n==="spPr"?t.spPr=S(s,r):s.n==="marker"?t.marker=Se(s,r):V[s.n]?t[s.n]=se(s):t.rawParts[s.n]=r.raw(s));return t}function Ye(e,r){const t=i(e,"name"),s=i(e,"trendlineLbl"),a=i(e,"extLst");return{name:t?t.t:void 0,spPr:S(i(e,"spPr"),r),type:L(e,"trendlineType")??"linear",order:w(e,"order"),period:w(e,"period"),forward:w(e,"forward"),backward:w(e,"backward"),intercept:w(e,"intercept"),dispRSqr:R(e,"dispRSqr"),dispEq:R(e,"dispEq"),lblRaw:s?r.raw(s):void 0,extLst:a?r.raw(a):void 0}}function Ke(e,r){const t=i(e,"extLst");return{dir:L(e,"errDir"),barType:L(e,"errBarType")??"both",valType:L(e,"errValType")??"fixedVal",noEndCap:R(e,"noEndCap",!1),plus:X(i(e,"plus"),r),minus:X(i(e,"minus"),r),val:w(e,"val"),spPr:S(i(e,"spPr"),r),extLst:t?r.raw(t):void 0}}function Ze(e,r){const t={idx:w(e,"idx",0),order:w(e,"order",0),rawParts:{},dPts:[],trendlines:[],errBars:[]};for(const s of e.c)switch(s.n){case"idx":case"order":break;case"tx":t.name=X(s,r);break;case"spPr":t.spPr=S(s,r);break;case"marker":t.marker=Se(s,r);break;case"dPt":t.dPts.push(He(s,r));break;case"dLbls":t.dLbls=De(s,r);break;case"trendline":t.trendlines.push(Ye(s,r));break;case"errBars":t.errBars.push(Ke(s,r));break;case"cat":case"val":case"xVal":case"yVal":case"bubbleSize":t[s.n]=X(s,r);break;case"shape":t.rawParts.shape=r.raw(s);break;default:V[s.n]?t[s.n]=se(s):t.rawParts[s.n]=r.raw(s)}return t}const ae=(e,r)=>e?{spPr:S(i(e,"spPr"),r),raw:r.raw(e)}:void 0;function Je(e,r){const t={tag:e.n,type:$e[e.n],is3D:/3D/.test(e.n),series:[],axIds:[],rawParts:{}};for(const s of e.c)switch(s.n){case"ser":t.series.push(Ze(s,r));break;case"axId":t.axIds.push(s.a.val);break;case"dLbls":t.dLbls=De(s,r);break;case"hiLowLines":case"dropLines":case"serLines":t[s.n]=ae(s,r);break;case"upDownBars":t.upDownBars={gapWidth:w(s,"gapWidth",150),up:S(i(i(s,"upBars"),"spPr"),r),down:S(i(i(s,"downBars"),"spPr"),r),raw:r.raw(s)};break;case"bandFmts":t.bandFmts=B(s,"bandFmt").map(a=>({idx:w(a,"idx",0),spPr:S(i(a,"spPr"),r)})),t.rawParts.bandFmts=r.raw(s);break;default:V[s.n]?t[s.n]=se(s):t.rawParts[s.n]=r.raw(s)}return t}function Me(e,r){if(!e)return;const t=i(e,"tx"),s=E(i(t,"rich"),r),a=t&&i(t,"strRef")?X(t,r):void 0,n=i(e,"extLst");return{text:s?ge(s):a?.cache[0]??void 0,rich:s,source:a,overlay:R(e,"overlay",!1),layout:Z(i(e,"layout"),r),spPr:S(i(e,"spPr"),r),txPr:E(i(e,"txPr"),r),extLst:n?r.raw(n):void 0}}const Ae={catAx:"cat",valAx:"val",dateAx:"date",serAx:"ser"},Qe=new Set(["axId","scaling","delete","axPos","majorGridlines","minorGridlines","title","numFmt","majorTickMark","minorTickMark","tickLblPos","spPr","txPr","crossAx","crosses","crossesAt","crossBetween","auto","lblAlgn","lblOffset","tickLblSkip","tickMarkSkip","noMultiLvlLbl","majorUnit","minorUnit","baseTimeUnit","majorTimeUnit","minorTimeUnit","dispUnits"]);function et(e,r){const t=i(e,"scaling"),s=i(e,"numFmt"),a=i(e,"dispUnits"),n={kind:Ae[e.n],id:L(e,"axId"),scaling:{logBase:w(t,"logBase"),orientation:L(t,"orientation"),max:w(t,"max"),min:w(t,"min")},delete:R(e,"delete",!1),pos:L(e,"axPos"),majorGridlines:ae(i(e,"majorGridlines"),r),minorGridlines:ae(i(e,"minorGridlines"),r),title:Me(i(e,"title"),r),numFmt:s?{code:s.a.formatCode,linked:F(s.a.sourceLinked,!1)}:void 0,majorTickMark:L(e,"majorTickMark"),minorTickMark:L(e,"minorTickMark"),tickLblPos:L(e,"tickLblPos"),spPr:S(i(e,"spPr"),r),txPr:E(i(e,"txPr"),r),crossAx:L(e,"crossAx"),crosses:L(e,"crosses"),crossesAt:w(e,"crossesAt"),crossBetween:L(e,"crossBetween"),auto:R(e,"auto"),lblAlgn:L(e,"lblAlgn"),lblOffset:w(e,"lblOffset"),tickLblSkip:w(e,"tickLblSkip"),tickMarkSkip:w(e,"tickMarkSkip"),noMultiLvlLbl:R(e,"noMultiLvlLbl"),majorUnit:w(e,"majorUnit"),minorUnit:w(e,"minorUnit"),baseTimeUnit:L(e,"baseTimeUnit"),majorTimeUnit:L(e,"majorTimeUnit"),minorTimeUnit:L(e,"minorTimeUnit"),rawParts:{}};a&&(n.dispUnits={builtIn:L(a,"builtInUnit"),custom:w(a,"custUnit"),raw:r.raw(a)});for(const d of e.c)Qe.has(d.n)||(n.rawParts[d.n]=r.raw(d));return n}function tt(e,r){if(!e)return;const t=i(e,"extLst");return{pos:L(e,"legendPos")??"r",entries:B(e,"legendEntry").map(s=>({idx:w(s,"idx",0),delete:R(s,"delete",!1),txPr:E(i(s,"txPr"),r)})),layout:Z(i(e,"layout"),r),overlay:R(e,"overlay",!1),spPr:S(i(e,"spPr"),r),txPr:E(i(e,"txPr"),r),extLst:t?r.raw(t):void 0}}function Be(e){if(e.length===0)return"unknown";if(e.some(s=>s.type==="stock"))return"stock";const r=s=>s.type==="bar"?s.barDir==="bar"?"bar":"column":s.type,t=r(e[0]);return e.every(s=>r(s)===t)?t:"combo"}function St(e){const r=Le(e),t=r.root,s=i(t,"chart"),a=i(s,"plotArea"),n={kind:"chart",source:r.text(),rootOpen:r.openTag(t),dirty:!1,date1904:R(t,"date1904"),lang:L(t,"lang"),roundedCorners:R(t,"roundedCorners"),style:w(t,"style"),spPr:S(i(t,"spPr"),r),txPr:E(i(t,"txPr"),r),spaceRaw:{},chartRaw:{},plotRaw:{},title:Me(i(s,"title"),r),autoTitleDeleted:R(s,"autoTitleDeleted",!1),legend:tt(i(s,"legend"),r),plotVisOnly:R(s,"plotVisOnly",!0),dispBlanksAs:L(s,"dispBlanksAs")??"zero",showDLblsOverMax:R(s,"showDLblsOverMax"),plotLayout:Z(i(a,"layout"),r),plotSpPr:S(i(a,"spPr"),r),groups:[],axes:[]},d=new Set(["date1904","lang","roundedCorners","style","chart","spPr","txPr"]);for(const c of t.c)if(!d.has(c.n)&&(n.spaceRaw[c.n]=r.raw(c),c.n==="AlternateContent"&&n.style===void 0)){const f=i(i(c,"Fallback"),"style");f&&(n.style=T(f.a.val))}const u=new Set(["title","autoTitleDeleted","legend","plotVisOnly","dispBlanksAs","showDLblsOverMax","plotArea"]);if(s)for(const c of s.c)u.has(c.n)||(n.chartRaw[c.n]=r.raw(c));if(a)for(const c of a.c)$e[c.n]?n.groups.push(Je(c,r)):Ae[c.n]?n.axes.push(et(c,r)):c.n!=="layout"&&c.n!=="spPr"&&(n.plotRaw[c.n]=r.raw(c));return n.type=Be(n.groups),n.grouping=n.groups[0]?.grouping,n}function J(e,r,t){let s=`<c:ptCount val="${e.length}"/>`;for(let a=0;a<e.length;a++){const n=e[a];if(n==null){t?.has(a)&&(s+=`<c:pt idx="${a}"><c:v>#N/A</c:v></c:pt>`);continue}s+=`<c:pt idx="${a}"><c:v>${r?n:Y(n)}</c:v></c:pt>`}return s}function ne(e){if(!e)return"";if(e.kind==="multi"){const r=(e.levels??[e.cache]).map(t=>{let s="";return t.forEach((a,n)=>{a!=null&&(s+=`<c:pt idx="${n}"><c:v>${Y(a)}</c:v></c:pt>`)}),s?`<c:lvl>${s}</c:lvl>`:"<c:lvl/>"}).join("");return`<c:multiLvlStrRef><c:f>${U(e.ref)}</c:f><c:multiLvlStrCache><c:ptCount val="${e.cache.length}"/>${r}</c:multiLvlStrCache></c:multiLvlStrRef>`}if(e.kind==="num"){const r=`<c:formatCode>${U(e.formatCode??"General")}</c:formatCode>`;return e.ref?`<c:numRef>${e.refExtFirst??""}<c:f>${U(e.ref)}</c:f><c:numCache>${r}${J(e.cache,!0,e.na)}</c:numCache>${e.refExt??""}</c:numRef>`:`<c:numLit>${r}${J(e.cache,!0)}</c:numLit>`}return e.ref?`<c:strRef>${e.refExtFirst??""}<c:f>${U(e.ref)}</c:f><c:strCache>${J(e.cache,!1)}</c:strCache>${e.refExt??""}</c:strRef>`:`<c:strLit>${J(e.cache,!1)}</c:strLit>`}const ie=(e,r)=>r?`<c:${e}>${ne(r)}</c:${e}>`:"";function rt(e){return e?e.ref?`<c:tx>${ne(e)}</c:tx>`:`<c:tx><c:v>${Y(e.cache[0]??"")}</c:v></c:tx>`:""}function Q(e){return e?e.raw?e.raw:e.x===void 0&&e.w===void 0?"<c:layout/>":`<c:layout><c:manualLayout>${l("layoutTarget",e.target)}${l("xMode",e.xMode)}${l("yMode",e.yMode)}${l("x",e.x)}${l("y",e.y)}${l("w",e.w)}${l("h",e.h)}</c:manualLayout></c:layout>`:""}function Ie(e){return e?`<c:marker>${l("symbol",e.symbol)}${l("size",e.size)}${D(e.spPr)}</c:marker>`:""}function Oe(e){let r="";e.numFmt&&(r+=`<c:numFmt formatCode="${U(e.numFmt.code)}" sourceLinked="${e.numFmt.linked?1:0}"/>`),r+=D(e.spPr),e.txPr&&(r+=G("c:txPr",e.txPr)),r+=l("dLblPos",e.pos);for(const t of Re)r+=l(t,e[t]??!1);return e.separator!==void 0&&(r+=`<c:separator>${we(e.separator)}</c:separator>`),r}function Ee(e){if(!e)return"";let r="<c:dLbls>";for(const t of e.labels??[])r+=`<c:dLbl>${l("idx",t.idx)}`,t.delete?r+=l("delete",!0):r+=`${Q(t.layout)}${t.txRaw??""}${Oe(t)}${t.extLst??""}`,r+="</c:dLbl>";return e.delete?r+=l("delete",!0):(r+=Oe(e),r+=l("showLeaderLines",e.showLeaderLines),r+=e.leaderLines??"",r+=e.extLst??""),`${r}</c:dLbls>`}function st(e){const r=e.rawParts??{};return`<c:dPt>${l("idx",e.idx)}${l("invertIfNegative",e.invertIfNegative)}${Ie(e.marker)}${l("bubble3D",e.bubble3D)}${l("explosion",e.explosion)}${D(e.spPr)}${r.pictureOptions??""}${r.extLst??""}</c:dPt>`}function at(e){return`<c:trendline>${e.name!==void 0?`<c:name>${we(e.name)}</c:name>`:""}${D(e.spPr)}${l("trendlineType",e.type)}${l("order",e.order)}${l("period",e.period)}${l("forward",e.forward)}${l("backward",e.backward)}${l("intercept",e.intercept)}${l("dispRSqr",e.dispRSqr??!1)}${l("dispEq",e.dispEq??!1)}${e.lblRaw??""}${e.extLst??""}</c:trendline>`}function nt(e){return`<c:errBars>${l("errDir",e.dir)}${l("errBarType",e.barType)}${l("errValType",e.valType)}${l("noEndCap",e.noEndCap)}${ie("plus",e.plus)}${ie("minus",e.minus)}${l("val",e.val)}${D(e.spPr)}${e.extLst??""}</c:errBars>`}function it(e,r){return`<c:ser>${(q[r]??q.bar).map(a=>{switch(a){case"idx":return l("idx",e.idx);case"order":return l("order",e.order);case"tx":return rt(e.name);case"spPr":return D(e.spPr);case"marker":return Ie(e.marker);case"dPt":return e.dPts.map(st).join("");case"dLbls":return Ee(e.dLbls);case"trendline":return e.trendlines.map(at).join("");case"errBars":return e.errBars.map(nt).join("");case"cat":case"val":case"xVal":case"yVal":case"bubbleSize":return ie(a,e[a]);default:return e.rawParts[a]??(V[a]?l(a,e[a]):"")}}).join("")}</c:ser>`}function lt(e){const t=Xe[e.tag].map(s=>{switch(s){case"ser":return e.series.map(a=>it(a,e.type)).join("");case"axId":return e.axIds.map(a=>l("axId",a)).join("");case"dLbls":return Ee(e.dLbls);case"hiLowLines":case"dropLines":case"serLines":return e[s]?e[s].raw??`<c:${s}>${D(e[s].spPr)}</c:${s}>`:"";case"upDownBars":return e.upDownBars?e.upDownBars.raw?e.upDownBars.raw:`<c:upDownBars>${l("gapWidth",e.upDownBars.gapWidth)}<c:upBars>${D(e.upDownBars.up)}</c:upBars><c:downBars>${D(e.upDownBars.down)}</c:downBars></c:upDownBars>`:"";default:return V[s]?l(s,e[s]):e.rawParts[s]??""}});return`<c:${e.tag}>${t.join("")}</c:${e.tag}>`}function je(e){if(!e)return"";let r="",t=e.txPr;if(e.rich)r=`<c:tx>${G("c:rich",e.rich)}</c:tx>`;else if(e.source)r=`<c:tx>${ne(e.source)}</c:tx>`;else if(e.text!==void 0){const s=t?.paras?.[0]?.defRPr;r=`<c:tx>${G("c:rich",{bodyPr:t?.bodyPr??{},paras:[{defRPr:s,runs:[{text:e.text,...s}]}]})}</c:tx>`,t=void 0}return`<c:title>${r}${Q(e.layout)}${l("overlay",e.overlay??!1)}${D(e.spPr)}${t?G("c:txPr",t):""}${e.extLst??""}</c:title>`}function ot(e){const r={cat:"catAx",val:"valAx",date:"dateAx",ser:"serAx"}[e.kind],t=e.scaling??{},s=n=>e[n]?e[n].raw??`<c:${n}>${D(e[n].spPr)}</c:${n}>`:"";let a=`<c:${r}>${l("axId",e.id)}<c:scaling>${l("logBase",t.logBase)}${l("orientation",t.orientation??"minMax")}${l("max",t.max)}${l("min",t.min)}</c:scaling>`;return a+=l("delete",e.delete??!1),a+=l("axPos",e.pos),a+=s("majorGridlines"),a+=s("minorGridlines"),a+=je(e.title),e.numFmt&&(a+=`<c:numFmt formatCode="${U(e.numFmt.code)}" sourceLinked="${e.numFmt.linked?1:0}"/>`),a+=l("majorTickMark",e.majorTickMark)+l("minorTickMark",e.minorTickMark)+l("tickLblPos",e.tickLblPos),a+=D(e.spPr),e.txPr&&(a+=G("c:txPr",e.txPr)),a+=l("crossAx",e.crossAx),e.crossesAt!==void 0?a+=l("crossesAt",e.crossesAt):a+=l("crosses",e.crosses),e.kind==="val"&&(a+=l("crossBetween",e.crossBetween)+l("majorUnit",e.majorUnit)+l("minorUnit",e.minorUnit)+(e.dispUnits?.raw??"")),e.kind==="cat"&&(a+=l("auto",e.auto)+l("lblAlgn",e.lblAlgn)+l("lblOffset",e.lblOffset)+l("tickLblSkip",e.tickLblSkip)+l("tickMarkSkip",e.tickMarkSkip)+l("noMultiLvlLbl",e.noMultiLvlLbl)),e.kind==="date"&&(a+=l("auto",e.auto)+l("lblOffset",e.lblOffset)+l("baseTimeUnit",e.baseTimeUnit)+l("majorUnit",e.majorUnit)+l("majorTimeUnit",e.majorTimeUnit)+l("minorUnit",e.minorUnit)+l("minorTimeUnit",e.minorTimeUnit)),e.kind==="ser"&&(a+=l("tickLblSkip",e.tickLblSkip)+l("tickMarkSkip",e.tickMarkSkip)),a+=Object.values(e.rawParts??{}).join(""),`${a}</c:${r}>`}function ct(e){if(!e)return"";const r=(e.entries??[]).map(t=>`<c:legendEntry>${l("idx",t.idx)}${t.delete?l("delete",!0):t.txPr?G("c:txPr",t.txPr):""}</c:legendEntry>`).join("");return`<c:legend>${l("legendPos",e.pos)}${r}${Q(e.layout)}${l("overlay",e.overlay??!1)}${D(e.spPr)}${e.txPr?G("c:txPr",e.txPr):""}${e.extLst??""}</c:legend>`}function ut(e){let r=e.rootOpen??`<c:chartSpace xmlns:c="${_.c}" xmlns:a="${_.a}" xmlns:r="${_.r}">`;for(const[t,s]of[["c",_.c],["a",_.a],["r",_.r]])new RegExp(`xmlns:${t}=`).test(r)||(r=r.replace(/>$/,` xmlns:${t}="${s}">`));return r}function Rt(e){const r=e.spaceRaw??{},t=e.chartRaw??{},s=e.plotRaw??{};let a=`${qe}${ut(e)}`;return a+=l("date1904",e.date1904)+l("lang",e.lang)+l("roundedCorners",e.roundedCorners??!1),r.AlternateContent?a+=r.AlternateContent:a+=l("style",e.style),a+=(r.clrMapOvr??"")+(r.pivotSource??"")+(r.protection??""),a+="<c:chart>",a+=je(e.title),a+=l("autoTitleDeleted",e.autoTitleDeleted??!1),a+=(t.pivotFmts??"")+(t.view3D??"")+(t.floor??"")+(t.sideWall??"")+(t.backWall??""),a+=`<c:plotArea>${Q(e.plotLayout??{})}`,a+=e.groups.map(lt).join(""),a+=e.axes.map(ot).join(""),a+=s.dTable??"",a+=D(e.plotSpPr),a+=s.extLst??"",a+="</c:plotArea>",a+=ct(e.legend),a+=l("plotVisOnly",e.plotVisOnly??!0),a+=l("dispBlanksAs",e.dispBlanksAs??"gap"),a+=l("showDLblsOverMax",e.showDLblsOverMax),a+=t.extLst??"",a+="</c:chart>",a+=D(e.spPr),e.txPr&&(a+=G("c:txPr",e.txPr)),a+=(r.externalData??"")+(r.printSettings??"")+(r.userShapes??"")+(r.extLst??""),`${a}</c:chartSpace>`}const ft={treemap:"treemap",sunburst:"sunburst",boxWhisker:"boxWhisker",waterfall:"waterfall",funnel:"funnel",regionMap:"map",clusteredColumn:"histogram",paretoLine:"pareto"};function pt(e,r){if(!e)return;const t=E(i(i(e,"tx"),"rich"),r),s=i(i(i(e,"tx"),"txData"),"v")?.t;return{text:t?ge(t):s,rich:t,overlay:F(e.a.overlay,!1)}}function Tt(e){const r=Le(e),t=r.root,s=new Map;for(const p of B(i(t,"chartData"),"data")){const v={strDims:[],numDims:[]};for(const h of p.c){if(h.n!=="strDim"&&h.n!=="numDim")continue;const g=B(h,"lvl").map(C=>{const M=new Array(T(C.a.ptCount,0)).fill(null);for(const o of B(C,"pt"))M[T(o.a.idx,0)]=h.n==="numDim"?T(o.t,null):o.t;return{values:M,formatCode:C.a.formatCode}}),b={type:h.a.type,ref:i(h,"f")?.t??"",levels:g};(h.n==="strDim"?v.strDims:v.numDims).push(b)}s.set(p.a.id,v)}const a=i(t,"chart"),n=i(a,"plotArea"),d=i(n,"plotAreaRegion"),u=B(d,"series").map(p=>{const v=i(p,"dataId")?.a.val,h=s.get(v)??{strDims:[],numDims:[]},g=i(p,"layoutPr"),b=i(g,"binning"),C=i(g,"statistics"),M=i(g,"visibility"),o=B(i(g,"subtotals"),"idx").map(m=>T(m.a.val,0)),P=i(p,"tx");return{layoutId:p.a.layoutId,hidden:F(p.a.hidden,!1),name:i(i(P,"txData"),"v")?.t??"",nameRef:i(i(P,"txData"),"f")?.t??"",spPr:S(i(p,"spPr"),r),dataPts:B(p,"dataPt").map(m=>({idx:T(m.a.idx,0),spPr:S(i(m,"spPr"),r)})),dataLabels:i(p,"dataLabels")?{pos:i(p,"dataLabels").a.pos,visibility:i(i(p,"dataLabels"),"visibility")?.a}:void 0,levels:h.strDims[0]?.levels.map(m=>m.values)??[],catRef:h.strDims[0]?.ref??"",values:h.numDims[0]?.levels[0]?.values??[],valRef:h.numDims[0]?.ref??"",formatCode:h.numDims[0]?.levels[0]?.formatCode??"General",binning:b?{intervalClosed:b.a.intervalClosed??"r",underflow:b.a.underflow,overflow:b.a.overflow,binSize:T(i(b,"binSize")?.a.val),binCount:T(i(b,"binCount")?.a.val)}:void 0,quartileMethod:C?.a.quartileMethod??"exclusive",aggregation:i(g,"aggregation")?!0:void 0,visibility:M?{...M.a}:void 0,subtotals:o}}),c=u.find(p=>p.layoutId!=="paretoLine")??u[0];let f=ft[c?.layoutId]??"unknown";u.some(p=>p.layoutId==="paretoLine")&&(f="pareto");const x=i(a,"legend");return{kind:"chartex",type:f,source:r.text(),rootOpen:r.openTag(t),dirty:!1,title:pt(i(a,"title"),r),legend:x?{pos:x.a.pos??"t",overlay:F(x.a.overlay,!1)}:void 0,series:u,spPr:S(i(t,"spPr"),r),axes:B(n,"axis").map(p=>({id:p.a.id,hidden:F(p.a.hidden,!1),kind:i(p,"catScaling")?"cat":"val",gapWidth:i(p,"catScaling")?.a.gapWidth,min:T(i(p,"valScaling")?.a.min),max:T(i(p,"valScaling")?.a.max),majorGridlines:!!i(p,"majorGridlines"),numFmt:i(p,"numFmt")?.a.formatCode}))}}const Dt=e=>Ve(e);function le(e){if(!e)return null;const r=e.trim();if(r.startsWith("(")&&r.endsWith(")")){const n=dt(r.slice(1,-1)).map(le);return n.every(Boolean)?n.flat():null}const t=r.lastIndexOf("!");if(t<0)return re(r)?[{sheet:null,range:r}]:null;let s=r.slice(0,t);const a=r.slice(t+1);return s[0]==="'"&&s.endsWith("'")&&(s=s.slice(1,-1).replace(/''/g,"'")),s.includes("[")||!re(a)?null:[{sheet:s,range:a}]}function dt(e){const r=[];let t=!1,s=0;for(let a=0;a<e.length;a++)e[a]==="'"?t=!t:e[a]===","&&!t&&(r.push(e.slice(s,a)),s=a+1);return r.push(e.slice(s)),r}function*oe(e){e.title?.source&&(yield e.title.source);for(const r of e.axes??[])r.title?.source&&(yield r.title.source);for(const r of e.groups??[])for(const t of r.series){for(const s of["name","cat","val","xVal","yVal","bubbleSize"])t[s]&&(yield t[s]);for(const s of t.errBars)s.plus&&(yield s.plus),s.minus&&(yield s.minus)}}function ce(e,r){const t=new Array(r.length);if(e.kind==="num")for(let s=0;s<r.length;s++){const a=r[s];typeof a=="number"?t[s]=Number.isFinite(a)?a:null:typeof a=="boolean"?t[s]=a?1:0:a==null||a===""?t[s]=null:a==="#N/A"?(t[s]=null,(t.na??=new Set).add(s)):t[s]=0}else for(let s=0;s<r.length;s++){const a=r[s];t[s]=a==null?null:String(a)}return t}const ue=(e,r)=>{if(e.length!==r.length)return!1;for(let t=0;t<e.length;t++)if(e[t]!==r[t])return!1;return!0};function Mt(e,r){if(!r||e.spaceRaw?.pivotSource)return!1;const t=a=>{const n=le(a);if(!n)return r.named?r.named(a):null;let d=null;for(const u of n){const c=r(u.sheet,u.range);if(!c)return null;d=d===null?c:d.concat(c)}return d};if(e.kind==="chartex")return xt(e,t);let s=!1;for(const a of oe(e)){if(!a.ref||a.kind==="multi")continue;const n=t(a.ref);if(n===null)continue;const d=ce(a,n);(!ue(a.cache,d)||a.na?.size!==d.na?.size)&&(a.cache=d,a.na=d.na,s=!0)}return s&&mt(e),s}function xt(e,r){let t=!1;for(const s of e.series){if(s.valRef){const a=r(s.valRef);if(a){const n=ce({kind:"num"},a);ue(s.values,n)||(s.values=n,t=!0)}}if(s.catRef){const a=r(s.catRef);if(a){const n=s.values.length?Math.max(1,Math.round(a.length/s.values.length)):1,d=ce({kind:"str"},a),u=[];for(let c=n-1;c>=0;c--){const f=[];for(let x=c;x<d.length;x+=n)f.push(d[x]);u.push(f)}(u.length!==(s.levels?.length??0)||u.some((c,f)=>!ue(s.levels[f],c)))&&(s.levels=u,t=!0)}}}return t}function mt(e){const r=t=>{t?.source&&(t.text=t.source.cache[0]??void 0)};r(e.title);for(const t of e.axes??[])r(t.title)}function At(e){const r=new Map;for(const t of oe(e))t.ref&&r.set(t.ref,t);return e.source.replace(/(<(\w+:)?f>)([^<]*)(<\/(?:\w+:)?f>\s*)<((?:\w+:)?)(numCache|strCache)\b[^>]*>[\s\S]*?<\/\5\6>/g,(t,s,a,n,d,u,c)=>{const f=r.get(Ge(n));if(!f||f.kind==="multi")return t;const x=u;let p=`<${x}ptCount val="${f.cache.length}"/>`;c==="numCache"&&(p=`<${x}formatCode>${U(f.formatCode??"General")}</${x}formatCode>${p}`);for(let v=0;v<f.cache.length;v++){const h=f.cache[v];h!=null&&(p+=`<${x}pt idx="${v}"><${x}v>${c==="numCache"?h:Y(h)}</${x}v></${x}pt>`)}return`${s}${n}${d}<${x}${c}>${p}</${x}${c}>`})}function Bt(e,r){let t=!1;if(e.kind==="chartex"){for(const s of e.series)for(const a of["catRef","valRef","nameRef"]){if(!s[a])continue;const n=r(s[a]);n!==s[a]&&(s[a]=n,t=!0)}return t&&(e.dirty=!0),t}if(e.kind!=="chart")return!1;for(const s of oe(e)){if(!s.ref)continue;const a=r(s.ref);a!==s.ref&&(s.ref=a,t=!0)}return t&&(e.dirty=!0),t}const fe=e=>We(e);function pe({r0:e,c0:r,r1:t,c1:s}){const a=`$${ve(r)}$${e+1}`;return e===t&&r===s?a:`${a}:$${ve(s)}$${t+1}`}function It(e,r,t,s,a){const n=le(e);if(!n)return e;const d=n.map(u=>{if(u.sheet!==null&&u.sheet!==r)return`${fe(u.sheet)}!${u.range}`;const c=u.sheet===null?"":`${fe(u.sheet)}!`,f=re(u.range),[x,p]=t==="row"?[f.r0,f.r1]:[f.c0,f.c1],v=t==="row"?ke:ze;let h=x,g=p;if(a>0)x>=s&&(h=Math.min(x+a,v-1)),p>=s&&(g=Math.min(p+a,v-1));else{const C=-a;if(x>=s+C?h=x-C:x>=s&&(h=s),p>=s+C?g=p-C:p>=s&&(g=s-1),h>g)return`${c}#REF!`}const b=t==="row"?{...f,r0:h,r1:g}:{...f,c0:h,c1:g};return`${c}${pe(b)}`});return d.length===1?d[0]:`(${d.join(",")})`}const H=j("tx1",["lumMod",65e3],["lumOff",35e3]),de=j("tx1",["lumMod",15e3],["lumOff",85e3]),ee=j("tx1",["lumMod",25e3],["lumOff",75e3]),xe=(e,r={})=>({bodyPr:r.rot!==void 0?{rot:r.rot,vert:"horz"}:{},paras:[{runs:[],defRPr:{size:e,bold:r.bold??!1,color:H},endRPr:{size:10}}]}),y=e=>({type:"solid",color:e}),Ue=[[],[["lumMod",6e4]],[["lumMod",8e4],["lumOff",2e4]],[["lumMod",8e4]],[["lumMod",6e4],["lumOff",4e4]],[["lumMod",5e4]],[["lumMod",7e4],["lumOff",3e4]],[["lumMod",7e4]],[["lumMod",5e4],["lumOff",5e4]]];function ht(e){const r=Math.max(0,e);return j(`accent${r%6+1}`,...Ue[Math.floor(r/6)%Ue.length])}const z=ht;function me(e,r,t,s,a={}){return{kind:e,id:r,crossAx:t,pos:s,scaling:{orientation:"minMax"},delete:!1,numFmt:{code:"General",linked:e!=="cat"},majorTickMark:"none",minorTickMark:"none",tickLblPos:"nextTo",spPr:e==="val"&&!(s==="b"||s==="t")?{fill:{type:"none"},line:{fill:{type:"none"}}}:{fill:{type:"none"},line:{w:.75,fill:y(ee),join:"round"}},txPr:xe(9,{rot:-6e7}),crosses:"autoZero",rawParts:{},...a}}const N=(e,r,t,s={})=>me("val",e,r,t,{majorGridlines:{spPr:{line:{w:.75,fill:y(de),join:"round"}}},crossBetween:"between",...s}),he=(e,r,t,s={})=>me("cat",e,r,t,{auto:!0,lblAlgn:"ctr",lblOffset:100,noMultiLvlLbl:!1,...s}),bt=new Set(["treemap","sunburst","histogram","pareto","boxWhisker","waterfall","funnel","map"]),Ot=["column","columnStacked","columnPercent","bar","barStacked","barPercent","line","lineMarkers","lineStacked","linePercent","area","areaStacked","areaPercent","pie","doughnut","ofPie","barOfPie","scatter","scatterLines","scatterSmooth","bubble","radar","radarMarkers","radarFilled","stock","combo","surface","surfaceWire","treemap","sunburst","histogram","pareto","boxWhisker","waterfall","funnel","map"];function Pt(e){const r=e.length,t=e[0]?.length??0,s=x=>typeof x=="string"&&x!=="",a=x=>x==null||x==="",n=e[0]?.[0];let d=!1;for(let x=1;x<t;x++)s(e[0][x])&&(d=!0);let u=t>1;for(let x=d||a(n)?1:0;x<r;x++)!s(e[x][0])&&!a(e[x][0])&&(u=!1);a(n)&&r>1&&t>1&&(d=!0,u=!0),t===1&&s(n)&&(d=!0),r===1&&s(n)&&(u=!0);const c=r-(d?1:0),f=t-(u?1:0);return{headerRow:d,headerCol:u,byRows:f>c,dataRows:c,dataCols:f}}function Et(e,r,t,s,{byRows:a}={}){const n=t.r1-t.r0+1,d=t.c1-t.c0+1,u=s(r,pe(t),{includeHidden:!0})??[],c=[];for(let b=0;b<n;b++)c.push(u.slice(b*d,(b+1)*d));const f=Pt(c);a!==void 0&&(f.byRows=a);const x=fe(r),p=(b,C,M,o)=>`${x}!${pe({r0:b,c0:C,r1:M,c1:o})}`;if(e==="treemap"||e==="sunburst")return kt(e,c,f,t,p);const v=t.r0+(f.headerRow?1:0),h=t.c0+(f.headerCol?1:0),g=[];if(f.byRows)for(let b=v;b<=t.r1;b++)g.push({nameRef:f.headerCol?p(b,t.c0,b,t.c0):null,nameText:f.headerCol?c[b-t.r0][0]:null,catRef:f.headerRow?p(t.r0,h,t.r0,t.c1):null,valRef:p(b,h,b,t.c1),vals:c[b-t.r0].slice(h-t.c0),cats:f.headerRow?c[0].slice(h-t.c0):null});else for(let b=h;b<=t.c1;b++){const C=c.map(o=>o[b-t.c0]),M=f.headerRow?1:0;g.push({nameRef:f.headerRow?p(t.r0,b,t.r0,b):null,nameText:f.headerRow?C[0]:null,catRef:f.headerCol?p(v,t.c0,t.r1,t.c0):null,valRef:p(v,b,t.r1,b),vals:C.slice(M),cats:f.headerCol?c.slice(M).map(o=>o[0]):null})}return vt(e,g)}const be=e=>(e??[]).map(r=>typeof r=="number"?r:typeof r=="boolean"?r?1:0:r==null||r===""||typeof r=="string"&&r[0]==="#"?null:0),Pe=e=>(e??[]).map(r=>r==null?null:String(r));function W(e){return e.catRef?(e.cats??[]).every(t=>typeof t=="number")?{kind:"num",ref:e.catRef,cache:be(e.cats),formatCode:"General"}:{kind:"str",ref:e.catRef,cache:Pe(e.cats)}:void 0}const I=(e,r)=>({kind:"num",ref:e,cache:be(r),formatCode:"General"}),wt=new Set(["pie","doughnut","ofPie","barOfPie","surface","surfaceWire"]);function vt(e,r){if(bt.has(e))return Fe(e,r);const t={kind:"chart",type:e,dirty:!0,date1904:!1,lang:"en-US",roundedCorners:!1,style:2,spaceRaw:{},chartRaw:{},plotRaw:{},title:{text:void 0,overlay:!1,txPr:xe(14,{rot:0}),spPr:{fill:{type:"none"},line:{fill:{type:"none"}}}},autoTitleDeleted:!1,legend:r.length===1&&!wt.has(e)?void 0:{pos:"b",entries:[],overlay:!1,spPr:{fill:{type:"none"},line:{fill:{type:"none"}}},txPr:xe(9,{rot:0})},plotVisOnly:!0,dispBlanksAs:"gap",plotLayout:{},plotSpPr:{fill:{type:"none"},line:{fill:{type:"none"}}},spPr:{fill:y(j("bg1")),line:{w:.75,cap:"flat",fill:y(de),join:"round"}},txPr:{bodyPr:{},paras:[{runs:[],defRPr:{}}]},groups:[],axes:[]},s=(o,P)=>{const m={idx:P,order:P,rawParts:{},dPts:[],trendlines:[],errBars:[]};return o.nameRef&&(m.name={kind:"str",ref:o.nameRef,cache:[o.nameText===null||o.nameText===void 0?"":String(o.nameText)]}),m},a="111111111",n="222222222",d="333333333",u=(o,P,m,$=[a,n])=>({tag:"barChart",type:"bar",barDir:o,grouping:P,varyColors:!1,gapWidth:P==="clustered"?219:150,overlap:P==="clustered"?-27:100,axIds:$,rawParts:{},series:m.map((k,A)=>({...s(k,k.at??A),spPr:{fill:y(z(k.at??A)),line:{fill:{type:"none"}}},invertIfNegative:!1,cat:W(k),val:I(k.valRef,k.vals)}))}),c=o=>({line:{w:2.25,cap:"rnd",fill:y(z(o)),join:"round"}}),f={symbol:"none"},x=o=>({symbol:"circle",size:5,spPr:{fill:y(z(o)),line:{w:.75,fill:y(z(o))}}}),p=(o,P,m,$=[a,n])=>({tag:"lineChart",type:"line",grouping:o,varyColors:!1,marker:!0,axIds:$,rawParts:{},series:P.map((k,A)=>{const O=k.at??A;return{...s(k,O),spPr:c(O),marker:m?x(O):f,cat:W(k),val:I(k.valRef,k.vals),smooth:!1}})}),v=(o,P)=>{const m={...s(o,P),cat:W(o),val:I(o.valRef,o.vals)};return m.dPts=(o.vals??[]).map(($,k)=>({idx:k,bubble3D:!1,spPr:{fill:y(z(k)),line:{w:.75,fill:y(j("lt1"))}},rawParts:{}})),m},h=(o=!1)=>{t.axes.push(he(a,n,o?"l":"b")),t.axes.push(N(n,a,o?"b":"l"))},g=/^(column|bar)(Stacked|Percent)?$/.exec(e),b=/^line(Markers|Stacked|Percent)?$/.exec(e),C=/^area(Stacked|Percent)?$/.exec(e),M={numFmt:{code:"0%",linked:!0}};if(g){const o=g[2]==="Stacked"?"stacked":g[2]==="Percent"?"percentStacked":"clustered";t.groups.push(u(g[1]==="column"?"col":"bar",o,r)),h(g[1]==="bar"),o==="percentStacked"&&Object.assign(t.axes[1],M)}else if(b){const o=b[1]==="Stacked"?"stacked":b[1]==="Percent"?"percentStacked":"standard";t.groups.push(p(o,r,b[1]==="Markers")),h(),o==="percentStacked"&&Object.assign(t.axes[1],M)}else if(C){const o=C[1]==="Stacked"?"stacked":C[1]==="Percent"?"percentStacked":"standard";t.groups.push({tag:"areaChart",type:"area",grouping:o,varyColors:!1,axIds:[a,n],rawParts:{},series:r.map((P,m)=>({...s(P,m),spPr:{fill:y(z(m)),line:{fill:{type:"none"}}},cat:W(P),val:I(P.valRef,P.vals)}))}),h(),t.axes[1].crossBetween="midCat",o==="percentStacked"&&Object.assign(t.axes[1],M)}else if(e==="pie")t.groups.push({tag:"pieChart",type:"pie",varyColors:!0,firstSliceAng:0,axIds:[],rawParts:{},series:r.slice(0,1).map(v)});else if(e==="doughnut")t.groups.push({tag:"doughnutChart",type:"doughnut",varyColors:!0,firstSliceAng:0,holeSize:75,axIds:[],rawParts:{},series:r.map(v)});else if(e==="ofPie"||e==="barOfPie")t.groups.push({tag:"ofPieChart",type:"ofPie",ofPieType:e==="ofPie"?"pie":"bar",varyColors:!0,gapWidth:100,splitType:"pos",secondPieSize:75,axIds:[],rawParts:{},serLines:{spPr:{line:{w:.75,fill:y(ee)}}},series:r.slice(0,1).map(v)});else if(/^scatter/.test(e)){const o=e!=="scatter",P=e==="scatterSmooth",m=r.length>1&&!r[0].catRef?r[0]:null,$=m?r.slice(1):r;t.groups.push({tag:"scatterChart",type:"scatter",scatterStyle:P?"smoothMarker":"lineMarker",varyColors:!1,axIds:[a,n],rawParts:{},series:$.map((k,A)=>{let O;return m?O=I(m.valRef,m.vals):k.catRef&&(O=W(k)),{...s(k,A),spPr:o?c(A):{line:{w:2.25,fill:{type:"none"}}},marker:P&&o?f:x(A),xVal:O,yVal:I(k.valRef,k.vals),smooth:P}})}),t.axes.push(N(a,n,"b",{crossBetween:"midCat",spPr:{fill:{type:"none"},line:{w:.75,fill:y(ee)}}})),t.axes.push(N(n,a,"l",{crossBetween:"midCat"}))}else if(e==="bubble"){const o=[];for(let P=0;P+2<r.length||P===0;P+=3){const m=r[P],$=r[P+1]??m,k=r[P+2]??$;o.push({...s($,o.length),spPr:{fill:{type:"solid",color:{...z(o.length),mods:[["alpha",75e3]]}},line:{fill:{type:"none"}}},invertIfNegative:!1,xVal:I(m.valRef,m.vals),yVal:I($.valRef,$.vals),bubbleSize:I(k.valRef,k.vals),bubble3D:!1})}t.groups.push({tag:"bubbleChart",type:"bubble",varyColors:!1,bubbleScale:100,showNegBubbles:!1,axIds:[a,n],rawParts:{},series:o}),t.axes.push(N(a,n,"b",{crossBetween:"midCat",spPr:{fill:{type:"none"},line:{w:.75,fill:y(ee)}}})),t.axes.push(N(n,a,"l",{crossBetween:"midCat"}))}else if(/^radar/.test(e)){const o=e==="radarFilled",P=e==="radarMarkers";t.groups.push({tag:"radarChart",type:"radar",radarStyle:o?"filled":"marker",varyColors:!1,axIds:[a,n],rawParts:{},series:r.map((m,$)=>({...s(m,$),spPr:o?{fill:y(z($)),line:{fill:{type:"none"}}}:c($),marker:P?x($):f,cat:W(m),val:I(m.valRef,m.vals)}))}),t.axes.push(he(a,n,"b",{majorGridlines:{spPr:{line:{w:.75,fill:y(de)}}}})),t.axes.push(N(n,a,"l"))}else if(e==="stock"){const o=(A,O)=>({...s(A,O),spPr:{line:{w:2.25,fill:{type:"none"}}},marker:f,cat:W(A),val:I(A.valRef,A.vals),smooth:!1}),P=r.slice(0,4),m=P.map(o),$=m[m.length-1];P.length===3&&($.marker={symbol:"dot",size:5,spPr:{fill:y(j("tx1")),line:{fill:y(j("tx1"))}}});const k={tag:"stockChart",type:"stock",axIds:[a,n],rawParts:{},series:m,hiLowLines:{spPr:{line:{w:.75,fill:y(H)}}}};P.length===4&&(k.upDownBars={gapWidth:150,up:{fill:y(j("lt1")),line:{w:.75,fill:y(H)}},down:{fill:y(H),line:{w:.75,fill:y(H)}}}),t.groups.push(k),h()}else if(e==="combo"){const o=r.map(($,k)=>({...$,at:k})),P=o.length>1?o.slice(0,-1):o,m=o.length>1?o.slice(-1):[];t.groups.push(u("col","clustered",P)),m.length&&t.groups.push(p("standard",m,!1)),h()}else if(e==="surface"||e==="surfaceWire")t.groups.push({tag:"surfaceChart",type:"surface",wireframe:e==="surfaceWire",axIds:[a,n,d],rawParts:{},series:r.map((o,P)=>({...s(o,P),cat:W(o),val:I(o.valRef,o.vals)}))}),t.axes.push(he(a,n,"b")),t.axes.push(N(n,a,"l",{crossBetween:"midCat"})),t.axes.push(me("ser",d,a,"b"));else throw new Error(`Unknown chart type: ${e}`);return t.type=Be(t.groups),e==="combo"&&(t.type="combo"),t.grouping=t.groups[0]?.grouping,t}function kt(e,r,t,s,a){const n=t.headerRow?1:0,d=r[0]?.length??0;let u=0;for(;u<d-1&&r.slice(n).every(v=>typeof v[u]=="string"||v[u]===null);)u++;const c=s.r0+n,f=s.c0+u,x=[];for(let v=u-1;v>=0;v--)x.push(Pe(r.slice(n).map(h=>h[v])));const p=Fe(e,[{nameText:t.headerRow?r[0][u]:null,nameRef:t.headerRow?a(s.r0,f,s.r0,f):null,valRef:a(c,f,s.r1,f),vals:r.slice(n).map(v=>v[u]),catRef:u?a(c,s.c0,s.r1,s.c0+u-1):""}]);return p.series[0].levels=x,p}function Fe(e,r){const t=r[0]??{vals:[],valRef:""},s=[];return t.cats&&s.push(Pe(t.cats)),{kind:"chartex",type:e,dirty:!0,title:{text:t.nameText?String(t.nameText):void 0,overlay:!1},legend:e==="treemap"||e==="waterfall"?{pos:"t",overlay:!1}:e==="map"?{pos:"r",overlay:!1}:void 0,axes:_e(e),series:[{layoutId:Ne[e],name:t.nameText?String(t.nameText):"",nameRef:t.nameRef??"",levels:s,catRef:t.catRef??"",values:be(t.vals),valRef:t.valRef,formatCode:"General",quartileMethod:"exclusive",aggregation:e==="pareto"&&s.length?!0:void 0,subtotals:[],dataPts:[]}]}}const jt={width:360,height:216};export{jt as CHART_DEFAULT_SIZE,Ot as CHART_TYPES,pe as absRange,vt as createChart,Et as createChartFromRange,ht as paletteColor,St as parseChart,Tt as parseChartEx,le as parseChartRef,Ze as parseSeries,At as patchChartCaches,Pt as planSeries,fe as quoteSheet,Mt as refreshChartData,Bt as rewriteChartRefs,It as shiftChartRef,Rt as writeChart,Dt as writeChartEx,it as writeSeries};
|
package/objects/dml.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{XmlScanner as L,child as c,children as C,decodeRange as v,parseAttrs as I,unescapeXml as B}from"../io/xml-scan.js";import{patternStyle as G}from"../charts/patterns.js";import{escapeMarkup as h,xmlLiteralText as H}from"../io/xml-escape.js";const m=12700,A='Calibri, Carlito, "Helvetica Neue", Arial, sans-serif',at={a:"http://schemas.openxmlformats.org/drawingml/2006/main",c:"http://schemas.openxmlformats.org/drawingml/2006/chart",cx:"http://schemas.microsoft.com/office/drawing/2014/chartex",r:"http://schemas.openxmlformats.org/officeDocument/2006/relationships",xdr:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",mc:"http://schemas.openxmlformats.org/markup-compatibility/2006",cx1:"http://schemas.microsoft.com/office/drawing/2015/9/8/chartex",cx2:"http://schemas.microsoft.com/office/drawing/2015/10/21/chartex",cx4:"http://schemas.microsoft.com/office/drawing/2016/5/10/chartex"},st=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
+
`,_=new TextEncoder,k=new TextDecoder;function z(t){const e=typeof t=="string"?_.encode(t):t,r={n:"#root",a:{},c:[],t:"",s:0,e:e.length,o:0},a=[r];return new L({open(n,o,i,f,u,d){const p=d?u+2:u+1,g={n:v(n,o,i),a:I(n,f,u),c:[],t:"",s:n.lastIndexOf(60,o),e:p,o:p};a[a.length-1].c.push(g),d||a.push(g)},close(n,o,i){a.length>1&&(a.pop().e=n.indexOf(62,i)+1)},text(n,o,i){a[a.length-1].t+=B(v(n,o,i))}}).feed(e),{root:r.c[0]??r,raw:n=>k.decode(e.subarray(n.s,n.e)),openTag:n=>k.decode(e.subarray(n.s,n.o)),text:()=>k.decode(e)}}const l=(t,e=void 0)=>{if(t==null||t==="")return e;const r=Number.parseFloat(t);return Number.isFinite(r)?r:e},x=(t,e=void 0)=>t===void 0?e:t!=="0"&&t!=="false",R={dk1:"000000",lt1:"FFFFFF",dk2:"0E2841",lt2:"E8E8E8",accent1:"156082",accent2:"E97132",accent3:"196B24",accent4:"0F9ED5",accent5:"A02B93",accent6:"4EA72E",hlink:"467886",folHlink:"96607D",majorFont:"Calibri Light",minorFont:"Calibri"},N={tx1:"dk1",tx2:"dk2",bg1:"lt1",bg2:"lt2"};function ot(t){const e={...R},r=c(z(t).root,"themeElements"),a=c(r,"clrScheme");if(a)for(const i of a.c){const f=i.c[0];if(!f)continue;const u=f.n==="sysClr"?f.a.lastClr:f.a.val;u&&(e[i.n]=u)}const s=c(r,"fontScheme"),n=c(c(s,"majorFont"),"latin")?.a.typeface,o=c(c(s,"minorFont"),"latin")?.a.typeface;return n&&(e.majorFont=n),o&&(e.minorFont=o),e}const j=new Set(["srgbClr","schemeClr","sysClr","prstClr","hslClr","scrgbClr"]),X={black:"000000",white:"FFFFFF",red:"FF0000",green:"008000",lime:"00FF00",blue:"0000FF",yellow:"FFFF00",cyan:"00FFFF",aqua:"00FFFF",magenta:"FF00FF",fuchsia:"FF00FF",gray:"808080",grey:"808080",silver:"C0C0C0",maroon:"800000",navy:"000080",olive:"808000",purple:"800080",teal:"008080",orange:"FFA500",pink:"FFC0CB",brown:"A52A2A",gold:"FFD700",ltGray:"D3D3D3",dkGray:"A9A9A9"};function y(t){if(!t)return null;const e=j.has(t.n)?t:t.c.find(a=>j.has(a.n));if(!e)return null;const r=e.c.map(a=>[a.n,l(a.a.val,0)]);switch(e.n){case"srgbClr":return{rgb:e.a.val,mods:r};case"schemeClr":return{scheme:e.a.val,mods:r};case"sysClr":return{rgb:e.a.lastClr??(e.a.val==="window"?"FFFFFF":"000000"),sys:e.a.val,mods:r};case"prstClr":return{rgb:X[e.a.val]??"000000",prst:e.a.val,mods:r};case"hslClr":{const[a,s,n]=T(l(e.a.hue,0)/6e4/360,l(e.a.sat,0)/1e5,l(e.a.lum,0)/1e5);return{rgb:S(a,s,n),mods:r}}default:{const a=s=>Math.round(Math.min(1,Math.max(0,l(e.a[s],0)/1e5))**.45454545454545453*255);return{rgb:S(a("r"),a("g"),a("b")),mods:r}}}}const S=(t,e,r)=>[t,e,r].map(a=>Math.round(a).toString(16).padStart(2,"0")).join("").toUpperCase();function q(t,e,r){const a=t/255,s=e/255,n=r/255,o=Math.max(a,s,n),i=Math.min(a,s,n),f=(o+i)/2;if(o===i)return[0,0,f];const u=o-i,d=f>.5?u/(2-o-i):u/(o+i);let p;return o===a?p=(s-n)/u+(s<n?6:0):o===s?p=(n-a)/u+2:p=(a-s)/u+4,[p/6,d,f]}function T(t,e,r){if(e===0)return[r*255,r*255,r*255];const a=r<.5?r*(1+e):r+e-r*e,s=2*r-a,n=o=>{let i=o;return i<0&&(i+=1),i>1&&(i-=1),i<1/6?s+(a-s)*6*i:i<1/2?a:i<2/3?s+(a-s)*(2/3-i)*6:s};return[n(t+1/3)*255,n(t)*255,n(t-1/3)*255]}const $=t=>{const e=t/255;return e<=.04045?e/12.92:((e+.055)/1.055)**2.4},b=t=>{const e=t<=.0031308?t*12.92:1.055*t**.4166666666666667-.055;return Math.max(0,Math.min(255,e*255))};function M(t,e=R,r=null){if(!t)return null;let a=t.rgb;t.scheme&&(t.scheme==="phClr"?a=r??"000000":a=e[N[t.scheme]??t.scheme]??"000000"),a&&a[0]==="#"&&(a=a.slice(1)),/^[0-9a-fA-F]{6}$/.test(a??"")||(a="000000");let s=parseInt(a.slice(0,2),16),n=parseInt(a.slice(2,4),16),o=parseInt(a.slice(4,6),16),i=1;for(const[f,u]of t.mods??[]){const d=u/1e5;switch(f){case"alpha":i=d;break;case"alphaMod":i*=d;break;case"alphaOff":i+=d;break;case"shade":s=b($(s)*d),n=b($(n)*d),o=b($(o)*d);break;case"tint":s=b($(s)*d+(1-d)),n=b($(n)*d+(1-d)),o=b($(o)*d+(1-d));break;case"comp":s=255-s,n=255-n,o=255-o;break;case"inv":s=255-s,n=255-n,o=255-o;break;case"gray":s=n=o=.2126*s+.7152*n+.0722*o;break;case"gamma":s=b(s/255),n=b(n/255),o=b(o/255);break;case"invGamma":s=$(s)*255,n=$(n)*255,o=$(o)*255;break;case"lumMod":case"lumOff":case"satMod":case"satOff":case"hueMod":case"hueOff":{let[p,g,w]=q(s,n,o);f==="lumMod"?w*=d:f==="lumOff"?w+=d:f==="satMod"?g*=d:f==="satOff"?g+=d:f==="hueMod"?p*=d:p+=u/6e4/360,[s,n,o]=T((p%1+1)%1,Math.min(1,Math.max(0,g)),Math.min(1,Math.max(0,w)));break}default:}}return i>=1?`#${S(s,n,o)}`:`rgba(${Math.round(s)},${Math.round(n)},${Math.round(o)},${Math.max(0,i).toFixed(3)})`}const it=(t,...e)=>({scheme:t,mods:e});function F(t){if(!t)return"";const e=(t.mods??[]).map(([a,s])=>`<a:${a} val="${s}"/>`).join(""),r=(a,s)=>e?`<a:${a} ${s}>${e}</a:${a}>`:`<a:${a} ${s}/>`;return t.scheme?r("schemeClr",`val="${h(t.scheme)}"`):t.sys?r("sysClr",`val="${h(t.sys)}" lastClr="${h(t.rgb)}"`):t.prst?r("prstClr",`val="${h(t.prst)}"`):r("srgbClr",`val="${h(t.rgb)}"`)}function E(t){if(t)for(const e of t.c)switch(e.n){case"noFill":return{type:"none"};case"solidFill":return{type:"solid",color:y(e)};case"gradFill":{const r=C(c(e,"gsLst"),"gs").map(n=>({pos:l(n.a.pos,0)/1e5,color:y(n)})),a=c(e,"lin"),s=c(e,"path");return{type:"grad",stops:r,angle:l(a?.a.ang,0)/6e4,path:s?s.a.path??"circle":null}}case"pattFill":return{type:"pattern",prst:e.a.prst,fg:y(c(e,"fgClr")),bg:y(c(e,"bgClr"))};case"blipFill":{const r=c(e,"blip");return{type:"blip",embed:r?.a.embed,link:r?.a.link,tile:!!c(e,"tile")}}case"grpFill":return{type:"group"};default:}}function U(t){if(!t)return;const e=a=>a?{type:a.a.type??"none",w:a.a.w??"med",len:a.a.len??"med"}:void 0,r={w:t.a.w!==void 0?l(t.a.w,9525)/m:void 0,cap:t.a.cap,cmpd:t.a.cmpd,fill:E(t),dash:c(t,"prstDash")?.a.val,head:e(c(t,"headEnd")),tail:e(c(t,"tailEnd"))};return c(t,"round")?r.join="round":c(t,"bevel")?r.join="bevel":c(t,"miter")&&(r.join="miter"),r}function W(t){if(!t)return;const e=c(t,"off"),r=c(t,"ext"),a=c(t,"chOff"),s=c(t,"chExt");return{rot:l(t.a.rot,0)/6e4,flipH:x(t.a.flipH,!1),flipV:x(t.a.flipV,!1),x:l(e?.a.x,0),y:l(e?.a.y,0),cx:l(r?.a.cx,0),cy:l(r?.a.cy,0),...a||s?{chX:l(a?.a.x,0),chY:l(a?.a.y,0),chCx:l(s?.a.cx,0),chCy:l(s?.a.cy,0)}:{}}}function V(t){const e=c(t,"prstGeom");if(e){const a={};for(const s of C(c(e,"avLst"),"gd")){const n=/val\s+(-?\d+)/.exec(s.a.fmla??"");n&&(a[s.a.name]=Number(n[1]))}return{prst:e.a.prst,av:a}}const r=c(t,"custGeom");if(r)return{custom:!0,paths:C(c(r,"pathLst"),"path").map(s=>({w:l(s.a.w,0),h:l(s.a.h,0),fill:s.a.fill,stroke:x(s.a.stroke,!0),cmds:s.c.map(n=>({op:n.n,pts:C(n,"pt").map(o=>[l(o.a.x,0),l(o.a.y,0)]),wR:l(n.a.wR,0),hR:l(n.a.hR,0),stAng:l(n.a.stAng,0)/6e4,swAng:l(n.a.swAng,0)/6e4}))}))}}function ct(t,e){if(t)return{fill:E(t),line:U(c(t,"ln")),xfrm:W(c(t,"xfrm")),geom:V(t),effects:J(c(t,"effectLst"),c(t,"sp3d")),raw:e?e.raw(t):void 0}}function J(t,e){if(!t&&!e)return;const r={},a=c(e,"bevelT");if(e&&a&&(r.bevel={w:l(a.a.w,76200)/m,h:l(a.a.h,76200)/m,prst:a.a.prst}),!t)return Object.keys(r).length?r:void 0;const s=c(t,"reflection");s&&(r.reflection={stA:l(s.a.stA,1e5)/1e3,endA:l(s.a.endA,0)/1e3,endPos:l(s.a.endPos,1e5)/1e3,dist:l(s.a.dist,0)/m,blur:l(s.a.blurRad,0)/m});const n=c(t,"outerShdw");n&&(r.shadow={blur:l(n.a.blurRad,0)/m,dist:l(n.a.dist,0)/m,dir:l(n.a.dir,0)/6e4,color:y(n)});const o=c(t,"innerShdw");o&&(r.innerShadow={blur:l(o.a.blurRad,0)/m,dist:l(o.a.dist,0)/m,dir:l(o.a.dir,0)/6e4,color:y(o)});const i=c(t,"glow");i&&(r.glow={rad:l(i.a.rad,0)/m,color:y(i)});const f=c(t,"softEdge");return f&&(r.softEdge={rad:l(f.a.rad,0)/m}),Object.keys(r).length?r:void 0}function lt(t){if(!t)return"";const e=a=>Math.round((a??0)*m);let r="";return t.glow&&(r+=`<a:glow rad="${e(t.glow.rad)}">${F(t.glow.color)}</a:glow>`),t.innerShadow&&(r+=`<a:innerShdw blurRad="${e(t.innerShadow.blur)}" dist="${e(t.innerShadow.dist)}" dir="${Math.round((t.innerShadow.dir??0)*6e4)}">${F(t.innerShadow.color)}</a:innerShdw>`),t.shadow&&(r+=`<a:outerShdw blurRad="${e(t.shadow.blur)}" dist="${e(t.shadow.dist)}" dir="${Math.round((t.shadow.dir??0)*6e4)}" algn="ctr" rotWithShape="0">${F(t.shadow.color)}</a:outerShdw>`),t.reflection&&(r+=`<a:reflection blurRad="${e(t.reflection.blur)}" stA="${Math.round((t.reflection.stA??50)*1e3)}" endA="${Math.round((t.reflection.endA??0)*1e3)}" endPos="${Math.round((t.reflection.endPos??50)*1e3)}" dist="${e(t.reflection.dist)}" dir="5400000" sy="-100000" algn="bl" rotWithShape="0"/>`),t.softEdge&&(r+=`<a:softEdge rad="${e(t.softEdge.rad)}"/>`),r?`<a:effectLst>${r}</a:effectLst>`:""}function O(t){if(!t)return"";switch(t.type){case"none":return"<a:noFill/>";case"solid":return`<a:solidFill>${F(t.color)}</a:solidFill>`;case"grad":return`<a:gradFill><a:gsLst>${t.stops.map(e=>`<a:gs pos="${Math.round(e.pos*1e5)}">${F(e.color)}</a:gs>`).join("")}</a:gsLst>${t.path?`<a:path path="${h(t.path)}"><a:fillToRect l="50000" t="50000" r="50000" b="50000"/></a:path>`:`<a:lin ang="${Math.round((t.angle??0)*6e4)}" scaled="0"/>`}</a:gradFill>`;case"blip":return`<a:blipFill><a:blip r:embed="${h(t.embed)}"/>${t.tile?"<a:tile/>":"<a:stretch><a:fillRect/></a:stretch>"}</a:blipFill>`;case"pattern":return`<a:pattFill prst="${h(t.prst)}"><a:fgClr>${F(t.fg)}</a:fgClr><a:bgClr>${F(t.bg)}</a:bgClr></a:pattFill>`;default:return""}}function K(t){if(!t)return"";const e=`${t.w!==void 0?` w="${Math.round(t.w*m)}"`:""}${t.cap?` cap="${h(t.cap)}"`:""}${t.cmpd?` cmpd="${h(t.cmpd)}"`:""}`,r=(n,o)=>o?`<a:${n} type="${h(o.type)}" w="${h(o.w??"med")}" len="${h(o.len??"med")}"/>`:"",a=t.join?t.join==="miter"?'<a:miter lim="800000"/>':`<a:${t.join}/>`:"",s=t.dash?`<a:prstDash val="${h(t.dash)}"/>`:"";return`<a:ln${e}>${O(t.fill)}${s}${a}${r("headEnd",t.head)}${r("tailEnd",t.tail)}</a:ln>`}function ft(t,e="c:spPr",r=""){return t?t.raw?t.raw:`<${e}>${r}${O(t.fill)}${K(t.line)}${t.tail??""}</${e}>`:r?`<${e}>${r}</${e}>`:""}function P(t){if(!t)return;const e=E(t),r={};t.a.sz!==void 0&&(r.size=l(t.a.sz)/100),t.a.b!==void 0&&(r.bold=x(t.a.b)),t.a.i!==void 0&&(r.italic=x(t.a.i)),t.a.u!==void 0&&(r.underline=t.a.u!=="none"),t.a.strike!==void 0&&(r.strike=t.a.strike!=="noStrike"),e?.type==="solid"&&(r.color=e.color);const a=c(t,"latin")?.a.typeface;return a&&(r.font=a),r}function dt(t,e){if(!t)return;const r=c(t,"bodyPr"),a={};if(r){const n=r.a;n.rot!==void 0&&(a.rot=l(n.rot)),n.vert!==void 0&&(a.vert=n.vert),n.anchor!==void 0&&(a.anchor=n.anchor),n.anchorCtr!==void 0&&(a.anchorCtr=x(n.anchorCtr)),n.wrap!==void 0&&(a.wrap=n.wrap);for(const o of["lIns","tIns","rIns","bIns"])n[o]!==void 0&&(a[o]=l(n[o])/m)}const s=C(t,"p").map(n=>{const o=c(n,"pPr"),i=[];for(const p of n.c)p.n==="r"||p.n==="fld"?i.push({text:c(p,"t")?.t??"",...P(c(p,"rPr"))}):p.n==="br"&&i.push({text:`
|
|
3
|
+
`,...P(c(p,"rPr"))});const f={runs:i};o?.a.algn&&(f.align=o.a.algn);const u=P(c(o,"defRPr"));u&&(f.defRPr=u);const d=P(c(n,"endParaRPr"));return d&&(f.endRPr=d),f});return{bodyPr:a,paras:s,raw:e?e.raw(t):void 0}}const ut=t=>t?t.paras.map(e=>e.runs.map(r=>r.text).join("")).join(`
|
|
4
|
+
`):"";function D(t,e){if(!e)return"";const r=[];e.size!==void 0&&r.push(`sz="${Math.round(e.size*100)}"`),e.bold!==void 0&&r.push(`b="${e.bold?1:0}"`),e.italic!==void 0&&r.push(`i="${e.italic?1:0}"`),e.underline!==void 0&&r.push(`u="${e.underline?"sng":"none"}"`);const a=`${e.color?`<a:solidFill>${F(e.color)}</a:solidFill>`:""}${e.font?`<a:latin typeface="${h(e.font)}"/>`:""}`;return a?`<a:${t}${r.length?` ${r.join(" ")}`:""}>${a}</a:${t}>`:`<a:${t}${r.length?` ${r.join(" ")}`:""}/>`}function pt(t,e){if(e?.raw)return e.raw;const r=e?.bodyPr??{},a=[];for(const n of["rot","vert","wrap","anchor"])r[n]!==void 0&&a.push(`${n}="${h(r[n])}"`);for(const n of["lIns","tIns","rIns","bIns"])r[n]!==void 0&&a.push(`${n}="${Math.round(r[n]*m)}"`);const s=(e?.paras?.length?e.paras:[{runs:[]}]).map(n=>{const i=n.align||n.defRPr?`<a:pPr${n.align?` algn="${h(n.align)}"`:""}>${D("defRPr",n.defRPr)}</a:pPr>`:"",f=n.runs.map(u=>{if(u.text===`
|
|
5
|
+
`)return"<a:br/>";const{text:d,...p}=u;return`<a:r>${D("rPr",{...p})}<a:t>${H(d)}</a:t></a:r>`}).join("");return`<a:p>${i}${f}${D("endParaRPr",n.endRPr)}</a:p>`}).join("");return`<${t}><a:bodyPr${a.length?` ${a.join(" ")}`:""}/><a:lstStyle/>${s}</${t}>`}const Y={sysDot:[1,1],sysDash:[3,1],dot:[1,3],dash:[4,3],lgDash:[8,3],dashDot:[4,3,1,3],lgDashDot:[8,3,1,3],lgDashDotDot:[8,3,1,3,1,3],sysDashDot:[3,1,1,1],sysDashDotDot:[3,1,1,1,1,1]},Q=(t,e)=>(Y[t]??[]).map(r=>r*e);function Z(t,e,r,a,s=null){if(!e||e.type==="none"||e.type==="group")return null;if(e.type==="solid")return M(e.color,r,s);if(e.type==="pattern")return G(t,e.prst,M(e.fg,r,s),e.bg?M(e.bg,r,s):null);if(e.type==="blip")return tt(t,e,a);if(e.type==="grad"&&e.stops.length>0){const{x:n,y:o,w:i,h:f}=a;let u;if(e.path)u=t.createRadialGradient(n+i/2,o+f/2,0,n+i/2,o+f/2,Math.hypot(i,f)/2);else{const d=e.angle*Math.PI/180,p=Math.cos(d),g=Math.sin(d),w=(Math.abs(p)*i+Math.abs(g)*f)/2;u=t.createLinearGradient(n+i/2-p*w,o+f/2-g*w,n+i/2+p*w,o+f/2+g*w)}for(const d of e.stops)u.addColorStop(Math.min(1,Math.max(0,d.pos)),M(d.color,r,s));return u}return null}function tt(t,e,r){const a=t.blipImages?.get(e.embed);if(!a||!t.createPattern)return null;const s=t.createPattern(a,e.tile?"repeat":"no-repeat");return s?.setTransform&&!e.tile&&typeof DOMMatrix<"u"?s.setTransform(new DOMMatrix([r.w/a.width,0,0,r.h/a.height,r.x,r.y])):s?.setTransform&&typeof DOMMatrix<"u"&&s.setTransform(new DOMMatrix([1,0,0,1,r.x,r.y])),s}function ht(t,e,r,a=null,s=null){let n=a;if(e?.fill){if(e.fill.type==="none")return!1;e.fill.type==="solid"?n=M(e.fill.color,r,s):e.fill.type==="grad"&&e.fill.stops.length>0&&(n=t.strokeBox?Z(t,e.fill,r,t.strokeBox,s):M(e.fill.stops[0].color,r,s))}if(!n)return!1;const o=e?.w??.75;return t.strokeStyle=n,t.lineWidth=o,t.setLineDash(Q(e?.dash,o)),t.lineCap=e?.cap==="rnd"?"round":e?.cap==="sq"?"square":"butt",t.lineJoin=e?.join==="bevel"?"bevel":e?.join==="miter"?"miter":"round",!0}function mt(t){const e=t.font&&t.font[0]!=="+"?`"${t.font}",${A}`:A;return`${t.italic?"italic ":""}${t.bold?"bold ":""}${t.size}px ${e}`}export{R as DEFAULT_THEME,m as EMU_PER_PX,A as FONT_STACK,at as NS,st as XML_HEAD,ht as applyStroke,mt as cssFontOf,Q as dashPattern,Z as fillStyleOf,y as parseColor,E as parseFill,U as parseLine,P as parseRunProps,ct as parseSpPr,dt as parseTextBody,ot as parseTheme,W as parseXfrm,z as parseXml,ut as plainText,M as resolveColor,it as schemeColor,x as toBool,l as toNum,F as writeColor,lt as writeEffects,O as writeFill,K as writeLine,ft as writeSpPr,pt as writeTextBody};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{child as l,children as Z}from"../io/xml-scan.js";import{escapeMarkup as x,xmlLiteralText as k}from"../io/xml-escape.js";import{relativeTarget as ee,relsPathOf as R,resolveTarget as b}from"../io/package-paths.js";import{NS as d,XML_HEAD as M,parseColor as te,parseFill as re,parseSpPr as N,parseTextBody as ne,parseXml as H,parseXfrm as V,toBool as X,toNum as m,writeColor as I,writeFill as ae,writeLine as ce,writeSpPr as ie,writeTextBody as j}from"./dml.js";import{chartExRequires as se}from"../charts/chartex.js";import{parseChart as oe,parseChartEx as le}from"./chart-model.js";const fe={drawing:`${d.r}/drawing`,chart:`${d.r}/chart`,image:`${d.r}/image`,chartEx:"http://schemas.microsoft.com/office/2014/relationships/chartEx",hyperlink:`${d.r}/hyperlink`},Me={drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",chartEx:"application/vnd.ms-office.chartex+xml"},_={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",bmp:"image/bmp",tif:"image/tiff",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp",emf:"image/x-emf",wmf:"image/x-wmf"};function He(e){switch(e){case"image/jpeg":return"jpeg";case"image/gif":return"gif";case"image/bmp":return"bmp";case"image/tiff":return"tiff";case"image/svg+xml":return"svg";case"image/webp":return"webp";default:return"png"}}const C={twoCellAnchor:"twoCell",oneCellAnchor:"oneCell",absoluteAnchor:"absolute"},B=new Set(["sp","pic","cxnSp","grpSp","graphicFrame","contentPart"]);function O(e){if(e)return{col:m(l(e,"col")?.t,0),colOff:m(l(e,"colOff")?.t,0),row:m(l(e,"row")?.t,0),rowOff:m(l(e,"rowOff")?.t,0)}}function pe(e,t){const n={type:t};if(t==="twoCell")n.editAs=e.a.editAs??"twoCell",n.from=O(l(e,"from")),n.to=O(l(e,"to"));else if(t==="oneCell")n.from=O(l(e,"from"));else{const c=l(e,"pos");n.pos={x:m(c?.a.x,0),y:m(c?.a.y,0)}}const r=l(e,"ext");return r&&(n.ext={cx:m(r.a.cx,0),cy:m(r.a.cy,0)}),n}function v(e,t){const n=l(e,t),r=l(n,"cNvPr");return{id:m(r?.a.id,0),name:r?.a.name??"",descr:r?.a.descr,title:r?.a.title,hidden:X(r?.a.hidden,!1),...(l(r,"extLst")?.c??[]).some(c=>l(c,"decorative")&&l(c,"decorative").a.val!=="0")?{decorative:!0}:{}}}function S(e){if(e)return{idx:m(e.a.idx,0),color:te(e)}}function z(e){if(e)return{lnRef:S(l(e,"lnRef")),fillRef:S(l(e,"fillRef")),effectRef:S(l(e,"effectRef")),fontRef:S(l(e,"fontRef"))}}function xe(e,t){const n=N(l(e,"spPr"),t)??{},r=X(l(l(e,"nvSpPr"),"cNvSpPr")?.a.txBox,!1),c=l(e,"txBody");return{kind:r?"textbox":"shape",...v(e,"nvSpPr"),xfrm:n.xfrm,rot:n.xfrm?.rot??0,flipH:n.xfrm?.flipH??!1,flipV:n.xfrm?.flipV??!1,geom:n.geom,fill:n.fill,line:n.line,style:z(l(e,"style")),text:ne(c,t),macro:e.a.macro,textlink:e.a.textlink}}function de(e,t){const n=N(l(e,"spPr"),t)??{};return{kind:"connector",...v(e,"nvCxnSpPr"),xfrm:n.xfrm,rot:n.xfrm?.rot??0,flipH:n.xfrm?.flipH??!1,flipV:n.xfrm?.flipV??!1,geom:n.geom,line:n.line,fill:n.fill,style:z(l(e,"style"))}}function q(e,t){const n=l(e,"blipFill"),r=l(n,"blip"),c=l(n,"srcRect"),a=N(l(e,"spPr"),t)??{},i=c?{l:m(c.a.l,0)/1e5,t:m(c.a.t,0)/1e5,r:m(c.a.r,0)/1e5,b:m(c.a.b,0)/1e5}:void 0;return{kind:"picture",...v(e,"nvPicPr"),embed:r?.a.embed,link:r?.a.link,crop:i,xfrm:a.xfrm,rot:a.xfrm?.rot??0,flipH:a.xfrm?.flipH??!1,flipV:a.xfrm?.flipV??!1,geom:a.geom,line:a.line}}function me(e,t){const n=l(e,"grpSpPr"),r=V(l(n,"xfrm")),c=[];for(const a of e.c)if(B.has(a.n)){const i=A(a,t);i&&c.push(i)}return{kind:"group",...v(e,"nvGrpSpPr"),xfrm:r,rot:r?.rot??0,flipH:r?.flipH??!1,flipV:r?.flipV??!1,fill:re(n),children:c}}function ue(e){const t=l(l(e,"graphic"),"graphicData"),n=l(t,"chart"),r=v(e,"nvGraphicFramePr"),c=V(l(e,"xfrm"));return n?{kind:/chartex/.test(t.a.uri??"")?"chartex":"chart",...r,xfrm:c,rel:n.a.id}:{kind:"unknown",...r,xfrm:c,uri:t?.a.uri}}function A(e,t){switch(e.n){case"sp":return xe(e,t);case"cxnSp":return de(e,t);case"pic":return q(e,t);case"grpSp":return me(e,t);case"graphicFrame":return ue(e);case"contentPart":return{kind:"unknown",rel:e.a.id};default:return null}}function $e(e,t){const n=l(e,"Choice"),r=l(e,"Fallback"),c=u=>u?.c.find(g=>B.has(g.n)),a=c(n),i=a?A(a,t):null;if(i&&i.kind!=="unknown")return i;const s=c(r),p=s?A(s,t):null;return F(i?{...i,visual:p}:{kind:"unknown",visual:p,...p?{id:p.id,name:p.name}:{}})}function F(e){if(e.kind!=="unknown"||e.visual?.kind!=="picture")return e;const t=e.uri??"";return/drawingml\/2006\/diagram/.test(t)||(e.media=/model3d/i.test(t)?"model3d":/audio|sound/i.test(t)?"audio":/video|movie|media/i.test(t)?"video":"media"),e}function he(e,t,n,r){const c=l(t,"Fallback");if(!e||e.visual||!c||c===n)return;const i=c.c.find(s=>C[s.n])?.c.find(s=>s.n==="pic");i&&(e.visual=q(i,r),F(e))}function we(e,t){return e.replace(/<((?:\w+:)?)(twoCellAnchor|oneCellAnchor|absoluteAnchor)\b[\s\S]*?<\/\1\2>/g,(n,r)=>{const c=(i,s)=>`<${r}${i}><${r}col>${s.col}</${r}col><${r}colOff>${f(s.colOff)}</${r}colOff><${r}row>${s.row}</${r}row><${r}rowOff>${f(s.rowOff)}</${r}rowOff></${r}${i}>`;let a=n;return t.from&&(a=a.replace(new RegExp(`<${r}from>[\\s\\S]*?</${r}from>`),()=>c("from",t.from))),t.to&&(a=a.replace(new RegExp(`<${r}to>[\\s\\S]*?</${r}to>`),()=>c("to",t.to))),t.ext&&(a=a.replace(new RegExp(`<${r}ext\\b[^>]*/>`),()=>`<${r}ext cx="${f(t.ext.cx)}" cy="${f(t.ext.cy)}"/>`)),t.pos&&(a=a.replace(new RegExp(`<${r}pos\\b[^>]*/>`),()=>`<${r}pos x="${f(t.pos.x)}" y="${f(t.pos.y)}"/>`)),a})}function ge(e,{path:t=null,rels:n=[]}={}){const r=H(e),c=r.root,a=[],i=(s,p)=>{const u=C[s.n],g=pe(s,u),h=s.c.find(y=>B.has(y.n)||y.n==="AlternateContent");let o;if(h?.n==="AlternateContent"?o=$e(h,r):h?o=A(h,r):o={kind:"unknown"},/drawing\/20(?:10|12)\/(?:time)?slicer/.test(o.uri??"")){a.push({kind:"foreign",raw:r.raw(p??s)});return}o.anchor=g,o.raw=r.raw(p??s),o.rawContent=h?r.raw(h):"";const w=l(s,"clientData");o.clientData=w?r.raw(w):void 0,o.wrapped=!!p,a.push(o)};for(const s of c.c)if(C[s.n])i(s,null);else if(s.n==="AlternateContent"){const p=l(s,"Choice")??l(s,"Fallback"),u=p?.c.find(g=>C[g.n]);u?(i(u,s),he(a[a.length-1],s,p,r)):a.push({kind:"foreign",raw:r.raw(s)})}else a.push({kind:"foreign",raw:r.raw(s)});return{path:t,rels:n,rootOpen:r.openTag(c),objects:a}}function L(e){const t=H(e);return Z(t.root,"Relationship").map(n=>({id:n.a.Id,type:n.a.Type,target:n.a.Target,targetMode:n.a.TargetMode}))}function ye(e){const t=e.map(n=>`<Relationship Id="${x(n.id)}" Type="${x(n.type)}" Target="${x(n.target)}"${n.targetMode?` TargetMode="${x(n.targetMode)}"`:""}/>`).join("");return`${M}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${t}</Relationships>`}const f=e=>Math.round(e);function D(e,t){return`<xdr:${e}><xdr:col>${t.col}</xdr:col><xdr:colOff>${f(t.colOff)}</xdr:colOff><xdr:row>${t.row}</xdr:row><xdr:rowOff>${f(t.rowOff)}</xdr:rowOff></xdr:${e}>`}function be(e){return e.type==="twoCell"?[`<xdr:twoCellAnchor${e.editAs&&e.editAs!=="twoCell"?` editAs="${x(e.editAs)}"`:""}>${D("from",e.from)}${D("to",e.to)}`,"</xdr:twoCellAnchor>"]:e.type==="oneCell"?[`<xdr:oneCellAnchor>${D("from",e.from)}<xdr:ext cx="${f(e.ext.cx)}" cy="${f(e.ext.cy)}"/>`,"</xdr:oneCellAnchor>"]:[`<xdr:absoluteAnchor><xdr:pos x="${f(e.pos.x)}" y="${f(e.pos.y)}"/><xdr:ext cx="${f(e.ext.cx)}" cy="${f(e.ext.cy)}"/>`,"</xdr:absoluteAnchor>"]}function ve(e,t){return e.replace(/(<(\w+:)?spPr\b[^>]*>)([\s\S]*?)(<\/\2spPr>)/,(n,r,c,a,i)=>{const s=/<a:(?:prstGeom|custGeom)\b[\s\S]*?<\/a:(?:prstGeom|custGeom)>|<a:prstGeom\b[^>]*\/>/.exec(a)?.[0]??"",p=/<a:xfrm\b[\s\S]*?<\/a:xfrm>/.exec(a)?.[0]??"",u=/<a:(?:effectLst|effectDag|scene3d|sp3d|extLst)\b[\s\S]*$/.exec(a)?.[0]??"";return`${r}${p}${s}${t.fill?ae(t.fill):""}${t.line?ce(t.line):""}${u}${i}`})}function Pe(e,t){return e.replace(/(<(?:[\w]+:)?off\s+x=")-?\d+("\s+y=")-?\d+("\s*\/>\s*<(?:[\w]+:)?ext\s+cx=")\d+("\s+cy=")\d+(")/,(n,r,c,a,i,s)=>`${r}${f(t.x)}${c}${f(t.y)}${a}${f(t.cx)}${i}${f(t.cy)}${s}`)}function ke(e,t){const n=j("xdr:txBody",{...t,raw:void 0});return/<(?:\w+:)?txBody\b/.test(e)?e.replace(/<((?:\w+:)?)txBody\b[\s\S]*?<\/\1txBody>/,()=>n):e.replace(/<\/((?:\w+:)?)sp>\s*$/,r=>`${n}${r}`)}const G='<a:ext uri="{C183D7F6-B498-43B3-948B-1728B52AA6E4}"><adec:decorative xmlns:adec="http://schemas.microsoft.com/office/drawing/2017/decorative" val="1"/></a:ext>',Y=e=>`${e.descr?` descr="${k(e.descr)}"`:""}${e.title?` title="${k(e.title)}"`:""}`,E=e=>`<xdr:cNvPr id="${e.id}" name="${k(e.name??"")}"${Y(e)}${e.decorative?`><a:extLst>${G}</a:extLst></xdr:cNvPr>`:"/>"}`;function J(e,t){return e.replace(/<((?:\w+:)?)cNvPr\b([^>]*?)(?:\/>|>([\s\S]*?)<\/\1cNvPr>)/,(n,r,c,a="")=>{let i=c.replace(/\s(?:descr|title)="[^"]*"/g,"").replace(/\sname="[^"]*"/,` name="${k(t.name??"")}"`);i+=Y(t);let s=a.replace(/<a:ext uri="\{C183D7F6-B498-43B3-948B-1728B52AA6E4\}">[\s\S]*?<\/a:ext>/,"");return t.decorative&&(s=/<a:extLst>/.test(s)?s.replace("</a:extLst>",`${G}</a:extLst>`):`${s}<a:extLst>${G}</a:extLst>`),s=s.replace(/<a:extLst>\s*<\/a:extLst>/,""),s?`<${r}cNvPr${i}>${s}</${r}cNvPr>`:`<${r}cNvPr${i}/>`})}function W(e,t){return`<a:xfrm${`${e.rot?` rot="${Math.round(e.rot*6e4)}"`:""}${e.flipH?' flipH="1"':""}${e.flipV?' flipV="1"':""}`}><a:off x="${f(t.x)}" y="${f(t.y)}"/><a:ext cx="${f(t.cx)}" cy="${f(t.cy)}"/></a:xfrm>`}function Re(e){const t=Object.entries(e?.av??{}).map(([n,r])=>`<a:gd name="${x(n)}" fmla="val ${r}"/>`).join("");return`<a:prstGeom prst="${x(e?.prst??"rect")}"><a:avLst>${t}</a:avLst></a:prstGeom>`}function K(e){if(!e)return"";const t=(r,c)=>c?`<a:${r} idx="${c.idx??0}">${I(c.color)}</a:${r}>`:`<a:${r} idx="0"/>`,n=e.fontRef?`<a:fontRef idx="minor">${I(e.fontRef.color)}</a:fontRef>`:'<a:fontRef idx="minor"/>';return`<xdr:style>${t("lnRef",e.lnRef)}${t("fillRef",e.fillRef)}${t("effectRef",e.effectRef)}${n}</xdr:style>`}function Ce(e,t){const n=ie({fill:e.fill,line:e.line},"xdr:spPr",`${W(e,t)}${Re(e.geom)}`),r=e.text?j("xdr:txBody",{...e.text,raw:void 0}):"";if(e.kind==="connector")return`<xdr:cxnSp macro=""><xdr:nvCxnSpPr>${E(e)}<xdr:cNvCxnSpPr/></xdr:nvCxnSpPr>${n}${K(e.style)}</xdr:cxnSp>`;const c=e.kind==="textbox"?' txBox="1"':"";return`<xdr:sp macro="" textlink=""><xdr:nvSpPr>${E(e)}<xdr:cNvSpPr${c}/></xdr:nvSpPr>${n}${K(e.style)}${r}</xdr:sp>`}function Se(e,t){const n=e.crop,r=n?`<a:srcRect l="${Math.round((n.l??0)*1e5)}" t="${Math.round((n.t??0)*1e5)}" r="${Math.round((n.r??0)*1e5)}" b="${Math.round((n.b??0)*1e5)}"/>`:"";return`<xdr:pic><xdr:nvPicPr>${E(e)}<xdr:cNvPicPr><a:picLocks noChangeAspect="1"/></xdr:cNvPicPr></xdr:nvPicPr><xdr:blipFill><a:blip xmlns:r="${d.r}" r:embed="${x(e.embed)}"/>${r}<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr>${W(e,t)}<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic>`}function Ae(e){const t=n=>`<xdr:graphicFrame macro=""><xdr:nvGraphicFramePr>${E(e)}<xdr:cNvGraphicFramePr/></xdr:nvGraphicFramePr><xdr:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/></xdr:xfrm><a:graphic>${n}</a:graphic></xdr:graphicFrame>`;if(e.kind==="chartex"){const n=t(`<a:graphicData uri="${d.cx}"><cx:chart xmlns:cx="${d.cx}" xmlns:r="${d.r}" r:id="${x(e.rel)}"/></a:graphicData>`),r=se(e.model?.type);return`<mc:AlternateContent xmlns:mc="${d.mc}"><mc:Choice xmlns:${r}="${d[r]}" Requires="${r}">${n}</mc:Choice><mc:Fallback><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="0" cy="0"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr><xdr:txBody><a:bodyPr/><a:lstStyle/><a:p><a:r><a:t>This chart isn't available in your version of Excel.</a:t></a:r></a:p></xdr:txBody></xdr:sp></mc:Fallback></mc:AlternateContent>`}return t(`<a:graphicData uri="${d.c}"><c:chart xmlns:c="${d.c}" xmlns:r="${d.r}" r:id="${x(e.rel)}"/></a:graphicData>`)}function Ee(e,t){if(e.kind==="foreign")return e.raw;const n=e.touched?.names===!0;if(e.raw&&!e.moved&&!e.textEdited&&!e.formatEdited)return n?J(e.raw,e):e.raw;if(e.media&&e.raw)return we(e.raw,e.anchor);const[r,c]=be(e.anchor),a=e.clientData??"<xdr:clientData/>";let i;e.rawContent!==void 0?(i=e.moved&&e.kind!=="chart"&&e.kind!=="chartex"&&!e.smartArt?Pe(e.rawContent,t):e.rawContent,e.textEdited&&e.text&&(i=ke(i,e.text)),e.formatEdited&&(i=ve(i,e)),n&&(i=J(i,e))):e.kind==="picture"?i=Se(e,t):e.kind==="chart"||e.kind==="chartex"?i=Ae(e):i=Ce(e,t);const s=`${r}${i}${a}${c}`;return e.wrapped&&e.raw?e.raw.replace(/<((?:\w+:)?)(twoCellAnchor|oneCellAnchor|absoluteAnchor)\b[\s\S]*?<\/\1\2>/,()=>s):s}function Ve(e,t){let n=e.rootOpen??`<xdr:wsDr xmlns:xdr="${d.xdr}" xmlns:a="${d.a}">`;for(const[a,i]of[["xdr",d.xdr],["a",d.a]])new RegExp(`xmlns:${a}=`).test(n)||(n=n.replace(/>$/,` xmlns:${a}="${i}">`));const r=n.replace(/^<([^\s>]+)[\s\S]*$/,"</$1>");let c="";for(const a of e.objects){const i=a.kind==="foreign"?null:t(a);c+=Ee(a,i)}return`${M}${n}${c}${r}`}async function Xe(e,t){const n=e.zip?e:{zip:e},{zip:r}=n,c=R(t);if(!r.has(c))return null;const a=L(await r.bytes(c)).find(o=>o.type===fe.drawing||/\/drawing$/.test(o.type));if(!a)return null;const i=b(t,a.target);if(!r.has(i))return null;const s=R(i),p=r.has(s)?L(await r.bytes(s)):[],u=ge(await r.bytes(i),{path:i,rels:p});u.sheetRelId=a.id;const g=new Map(p.map(o=>[o.id,o])),h=async o=>{if(o.kind==="group"){for(const w of o.children??[])await h(w);return}if(o.kind==="chart"||o.kind==="chartex"){const w=g.get(o.rel);if(!w||(o.chartPath=b(i,w.target),!r.has(o.chartPath)))return;const y=await r.bytes(o.chartPath);try{o.model=o.kind==="chart"?oe(y):le(y)}catch($){o.modelError=$.message}const P=R(o.chartPath);r.has(P)&&(o.chartRels=L(await r.bytes(P)).map($=>({...$,path:$.targetMode==="External"?null:b(o.chartPath,$.target)})),o.loadRelBlob=async $=>{const Q=await n.zip.stream($.path),U=$.path.split(".").pop().toLowerCase(),T=await new Response(Q).blob();return T.type?T:new Blob([T],{type:_[U]??""})})}else if(o.kind==="picture"&&o.embed){const w=g.get(o.embed);if(!w)return;o.mediaPath=b(i,w.target),o.loadBlob=async()=>{const y=await n.zip.stream(o.mediaPath),P=o.mediaPath.split(".").pop().toLowerCase(),$=await new Response(y).blob();return $.type?$:new Blob([$],{type:_[P]??""})}}o.visual&&await h(o.visual)};for(const o of u.objects)o.kind!=="foreign"&&await h(o);return u}const Te=/<(?:legacyDrawing|legacyDrawingHF|drawingHF|picture|oleObjects|controls|webPublishItems|tableParts|extLst)\b|<\/worksheet>/;function Ie(e,t){if(/<drawing\b/.test(e))return e;const n=Te.exec(e);return n?e.slice(0,n.index)+t+e.slice(n.index):e+t}function je(e,t){const n=e||ye([]);return n.includes(`Id="${t.id}"`)?n:n.replace("</Relationships>",`<Relationship Id="${x(t.id)}" Type="${x(t.type)}" Target="${x(t.target)}"/></Relationships>`)}function _e(e,t=[],n=[]){let r=e;for(const a of n)r=r.replace(new RegExp(`<Override\\b[^>]*PartName="${a.replace(/[.*+?^\${}()|[\]\\/]/g,"\\$&")}"[^>]*/>`),"");let c="";for(const a of t)a.partName?r.includes(`PartName="${a.partName}"`)||(c+=`<Override PartName="${x(a.partName)}" ContentType="${x(a.contentType)}"/>`):new RegExp(`<Default\\b[^>]*Extension="${a.extension}"`,"i").test(r)||(r=r.replace(/(<Types\b[^>]*>)/,`$1<Default Extension="${x(a.extension)}" ContentType="${x(a.contentType)}"/>`));return r.replace("</Types>",`${c}</Types>`)}export{Me as CONTENT_TYPE,_ as IMAGE_TYPES,fe as REL,Ie as ensureDrawingElement,He as extensionForType,_e as mergeContentTypes,je as mergeRelationship,ge as parseDrawing,L as parseRels,Xe as readSheetDrawing,ee as relativeTarget,R as relsPathOf,b as resolveTarget,Ve as writeDrawing,ye as writeRels};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as s}from"../i18n/index.js";const c=50*1024*1024;function l(r){const t=r,e=(a,o)=>[...o].every((i,h)=>t[a+h]===i.charCodeAt(0));if(t.length>=8&&t[0]===137&&e(1,"PNG"))return"image/png";if(t.length>=3&&t[0]===255&&t[1]===216&&t[2]===255)return"image/jpeg";if(t.length>=6&&e(0,"GIF8"))return"image/gif";if(t.length>=12&&e(0,"RIFF")&&e(8,"WEBP"))return"image/webp";if(t.length>=2&&e(0,"BM"))return"image/bmp";const n=new TextDecoder().decode(t.subarray(0,1024)).replace(/^/,"").trimStart();return/^(?:<\?xml[^>]*>\s*)?(?:<!--[\s\S]*?-->\s*|<!DOCTYPE[^>]*>\s*)*<svg\b/i.test(n)?"image/svg+xml":null}function u(r){let t;try{t=new URL(String(r).trim())}catch{return s("Enter a web address that starts with https:// or http://.")}return/^(?:https?|data):$/.test(t.protocol)?null:s("Enter a web address that starts with https:// or http://.")}async function p(r,t=globalThis.fetch){const e=u(r);if(e)throw new Error(e);let n;try{n=await t(String(r).trim(),{mode:"cors",credentials:"omit",referrerPolicy:"no-referrer"})}catch{throw new Error(s("The picture couldn't be downloaded. Check the address; the site may also not let other pages use its pictures."))}if(!n.ok)throw new Error(s("The picture couldn't be downloaded: the site answered {status}.",{status:n.status}));const a=new Uint8Array(await n.arrayBuffer());if(a.length>c)throw new Error(s("The picture is larger than 50 MB."));const o=l(a);if(o===null)throw new Error(s("That address isn't a picture this app can show."));return new Blob([a],{type:o})}export{p as fetchPicture,u as pictureUrlProblem,l as sniffImageType};
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@8sheets/data-grid",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
|
+
"homepage": "https://8sheets.com",
|
|
6
|
+
"author": "8cells",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"description": "Data grid for the web: open CSV and Excel files or pass records, then search, filter, sort, group, total, pivot and export to CSV, Excel or PDF. Worker-backed, a million rows, server data sources.",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"data-grid",
|
|
13
|
+
"datagrid",
|
|
14
|
+
"grid",
|
|
15
|
+
"table",
|
|
16
|
+
"data-table",
|
|
17
|
+
"csv",
|
|
18
|
+
"xlsx",
|
|
19
|
+
"excel",
|
|
20
|
+
"pivot-table",
|
|
21
|
+
"filter",
|
|
22
|
+
"group-by",
|
|
23
|
+
"virtual-scroll"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./table-view/index.d.ts",
|
|
29
|
+
"default": "./table-view/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"main": "./table-view/index.js",
|
|
34
|
+
"types": "./table-view/index.d.ts",
|
|
35
|
+
"sideEffects": true,
|
|
36
|
+
"files": [
|
|
37
|
+
"a11y",
|
|
38
|
+
"api",
|
|
39
|
+
"calc",
|
|
40
|
+
"calcx",
|
|
41
|
+
"cells",
|
|
42
|
+
"celltypes",
|
|
43
|
+
"charts",
|
|
44
|
+
"core",
|
|
45
|
+
"datasheets",
|
|
46
|
+
"extras",
|
|
47
|
+
"i18n",
|
|
48
|
+
"io",
|
|
49
|
+
"objects",
|
|
50
|
+
"pivot",
|
|
51
|
+
"print",
|
|
52
|
+
"render",
|
|
53
|
+
"shapes",
|
|
54
|
+
"slicers",
|
|
55
|
+
"sparklines",
|
|
56
|
+
"table-view",
|
|
57
|
+
"ui"
|
|
58
|
+
]
|
|
59
|
+
}
|
package/pivot/engine.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{withNoDataItems as Zt}from"../slicers/pivot-file.js";import{dateOptionFlags as te}from"../slicers/date-filters.js";import{BOOL as at,CHUNK_BITS as Tt,CHUNK_MASK as Ct,EMPTY as K,ERR as ct,ERRORS as Dt,KIND_MASK as Ft,NUM as B,STR as Z}from"../core/sheet.js";import{formatGeneral as St,getFormatter as Vt,partsToSerial as ee,serialToParts as pt}from"../core/numfmt.js";import{MAX_COLS as se,MAX_ROWS as ne}from"../core/address.js";import{compareText as Ut,ERR as P,ERR_BY_INDEX as Rt,numberToText as re,XlError as $}from"../calc/values.js";import{FUNCS as oe}from"../calc/functions/registry.js";import"../calc/functions/index.js";import{t as G}from"../i18n/index.js";const x=-2,Ke=["sum","count","average","max","min","product","countNums","stdDev","stdDevp","var","varp"],kt={sum:"Sum",count:"Count",average:"Average",max:"Max",min:"Min",product:"Product",countNums:"Count Numbers",stdDev:"StdDev",stdDevp:"StdDevp",var:"Var",varp:"Varp"},le={...kt,countNums:"Count"};function xt(c,t){switch(c){case"count":case"countNums":return G("pivot|Count of {field}",{field:t});case"average":return G("pivot|Average of {field}",{field:t});case"max":return G("pivot|Max of {field}",{field:t});case"min":return G("pivot|Min of {field}",{field:t});case"product":return G("pivot|Product of {field}",{field:t});case"stdDev":return G("pivot|StdDev of {field}",{field:t});case"stdDevp":return G("pivot|StdDevp of {field}",{field:t});case"var":return G("pivot|Var of {field}",{field:t});case"varp":return G("pivot|Varp of {field}",{field:t});default:return G("pivot|Sum of {field}",{field:t})}}const je=[["normal","No Calculation"],["percentOfTotal","% of Grand Total"],["percentOfCol","% of Column Total"],["percentOfRow","% of Row Total"],["percent","% Of"],["percentOfParentRow","% of Parent Row Total"],["percentOfParentCol","% of Parent Column Total"],["percentOfParent","% of Parent Total"],["difference","Difference From"],["percentDiff","% Difference From"],["runTotal","Running Total In"],["percentOfRunningTotal","% Running Total In"],["rankAscending","Rank Smallest to Largest"],["rankDescending","Rank Largest to Smallest"],["index","Index"]],ie=new Set(["percent","percentOfParent","difference","percentDiff","runTotal","percentOfRunningTotal","rankAscending","rankDescending"]),Ye=c=>ie.has(c),Xe=c=>c==="percent"||c==="difference"||c==="percentDiff",ae=new Set(["percentOfTotal","percentOfCol","percentOfRow","percent","percentOfParentRow","percentOfParentCol","percentOfParent","percentDiff","percentOfRunningTotal"]),Qe=["captionEqual","captionNotEqual","captionBeginsWith","captionNotBeginsWith","captionEndsWith","captionNotEndsWith","captionContains","captionNotContains","captionGreaterThan","captionGreaterThanOrEqual","captionLessThan","captionLessThanOrEqual","captionBetween","captionNotBetween"],ze=["valueEqual","valueNotEqual","valueGreaterThan","valueGreaterThanOrEqual","valueLessThan","valueLessThanOrEqual","valueBetween","valueNotBetween"],E={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},X=0,lt=1,st=2,mt=3,Je={ITEM:X,SUBTOTAL:lt,GRAND:st,BLANK:mt},Pt=1<<23,ce=1<<24,Lt="";class S extends Error{constructor(t,e){super(G(t,e))}}function ut(c){if(c==null)return"blank";switch(typeof c){case"number":return`n${c}`;case"string":return`s${c.toLowerCase()}`;case"boolean":return c?"b1":"b0";default:return`e${c.code}`}}const Bt=c=>c===null?4:typeof c=="number"?0:typeof c=="string"?1:typeof c=="boolean"?2:3,ue=[["sun","mon","tue","wed","thu","fri","sat"],["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"],["january","february","march","april","may","june","july","august","september","october","november","december"]].map(c=>new Map(c.map((t,e)=>[t,e])));function fe(c){let t=ue,e=!1;for(const s of c){if(typeof s!="string")continue;e=!0;const n=s.toLowerCase();if(t=t.filter(o=>o.has(n)),t.length===0)return null}return e?t[0]:null}const $t=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Gt=[31,29,31,30,31,30,31,31,30,31,30,31],he=["seconds","minutes","hours","days","months","quarters","years"],de={seconds:"Seconds",minutes:"Minutes",hours:"Hours",days:"Days",months:"Months",quarters:"Quarters",years:"Years"};function pe(c,t){let e=0;for(let s=0;s<c-1;s++)e+=Gt[s];return e+t-1}function me(c,t,e){switch(c){case"years":{const s=[];for(let n=t;n<=e;n++)s.push(String(n));return s}case"quarters":return["Qtr1","Qtr2","Qtr3","Qtr4"];case"months":return $t;case"days":{const s=[];return Gt.forEach((n,o)=>{for(let r=1;r<=n;r++)s.push(`${r}-${$t[o]}`)}),s}case"hours":{const s=[];for(let n=0;n<24;n++)s.push(`${n%12===0?12:n%12} ${n<12?"AM":"PM"}`);return s}default:{const s=[];for(let n=0;n<60;n++)s.push(`:${n<10?"0":""}${n}`);return s}}}function we(c,t,e){switch(c){case"years":return t.year-e;case"quarters":return Math.floor((t.month-1)/3);case"months":return t.month-1;case"days":return pe(t.month,t.day);case"hours":return Math.floor(t.ms/36e5);case"minutes":return Math.floor(t.ms/6e4)%60;default:return Math.floor(t.ms/1e3)%60}}class ft{constructor(t,e,s){this.cache=t,this.index=e,this.name=s,this.numFmt="General",this.isDate=!1,this.kinds=null,this.uniformKind=K,this.nums=null,this.strs=null,this.shared=null,this.rawIds=null,this.ids=null,this.items=null,this.group=null,this.base=-1,this.par=-1,this.formula=null,this.calc=null,this.removed=!1,this.xml=null,this._keys=null,this._rank=null}get isVirtual(){return this.base>=0||this.formula!==null}get isCalculated(){return this.formula!==null}reset(){this.shared=null,this.rawIds=null,this.invalidate()}invalidate(){this.ids=null,this.items=null,this._keys=null,this._rank=null}ensureRaw(){if(this.rawIds!==null)return this;if(this.base>=0){const l=this.cache.fields[this.base].ensureRaw();return this.rawIds=l.rawIds,this.shared=l.shared,this}const t=this.cache.recordCount,e=new Int32Array(t),s=[],{kinds:n,nums:o,strs:r}=this;if(r!==null)ye(this.cache,r,null,null,t,e,s);else if(o!==null&&n===null&&this.uniformKind===B){const l=new Map;let i=NaN,u=-1;for(let f=0;f<t;f++){const w=o[f];if(w!==i){let p=l.get(w);p===void 0&&(p=s.length,s.push(w),l.set(w,p)),i=w,u=p}e[f]=u}}else n!==null?Ae(this.cache,n,o,t,e,s):t>0&&s.push(null);return this.rawIds=e,this.shared=s,this}ensure(){if(this.ids!==null)return this;if(this.ensureRaw(),this.group===null)return this.ids=this.rawIds,this.items=this.shared,this;const{map:t,labels:e}=be(this),s=this.rawIds,n=s.length,o=new Int32Array(n);for(let r=0;r<n;r++)o[r]=t[s[r]];return this.ids=o,this.items=e,this.groupMap=t,this}ensureColumn(){if(this.nums!==null||this.strs!==null||this.rawIds===null)return this;if(this.base>=0)return this;const t=this.rawIds.length,e=new Uint8Array(t),s=new Float64Array(t),n=this.rawIds,o=this.shared,r=new Uint8Array(o.length),l=new Float64Array(o.length);o.forEach((i,u)=>{typeof i=="number"?(r[u]=B,l[u]=i):typeof i=="string"?r[u]=Z:typeof i=="boolean"?(r[u]=at,l[u]=i?1:0):i instanceof $&&(r[u]=ct,l[u]=i.index)});for(let i=0;i<t;i++){const u=n[i];e[i]=r[u],s[i]=l[u]}return this.kinds=e,this.nums=s,this}get keyIndex(){if(this._keys===null){this.ensure();const t=new Map;this.items.forEach((e,s)=>{const n=ut(e);t.has(n)||t.set(n,s)}),this._keys=t}return this._keys}keyOf(t){return ut(this.items[t])}labelOf(t){return this.labelOfValue(this.items[t])}labelOfValue(t){return t==null?"(blank)":typeof t=="string"?t:typeof t=="number"?this.numFmt!=="General"?Vt(this.numFmt).number(t):St(t):typeof t=="boolean"?t?"TRUE":"FALSE":t.code}rank(){if(this._rank!==null)return this._rank;this.ensure();const{items:t}=this,e=new Int32Array(t.length);if(this.group!==null&&this.group.kind!=="discrete")for(let s=0;s<e.length;s++)e[s]=s;else{const s=fe(t),n=Array.from(t.keys());n.sort((o,r)=>ge(t[o],t[r],s)),n.forEach((o,r)=>{e[o]=r})}return this._rank=e,e}}function ge(c,t,e){const s=Bt(c),n=Bt(t);return s!==n?s-n:s===0?c-t:s===1?e!==null?e.get(c.toLowerCase())-e.get(t.toLowerCase()):Ut(c,t):s===2?c===t?0:c?1:-1:s===3?c.index-t.index:0}function ye(c,t,e,s,n,o,r){let l=-1;for(let f=0;f<n;f++)t[f]>l&&(l=t[f]);const i=new Int32Array(l+1).fill(-1),u=new Map;for(let f=0;f<n;f++){const w=t[f];let p=i[w];if(p<0){const h=c.getString(w),a=h.toLowerCase();p=u.get(a),p===void 0&&(p=r.length,r.push(h),u.set(a,p)),i[w]=p}o[f]=p}}function Ae(c,t,e,s,n,o){const r=new Map,l=new Map,i=new Map,u=new Map;let f=-1;for(let w=0;w<s;w++){const p=t[w];let h;if(p===B){const a=e[w];h=r.get(a),h===void 0&&(h=o.length,o.push(a),r.set(a,h))}else if(p===Z){const a=e[w];if(h=i.get(a),h===void 0){const d=c.getString(a),m=d.toLowerCase();h=l.get(m),h===void 0&&(h=o.length,o.push(d),l.set(m,h)),i.set(a,h)}}else if(p===K)f<0&&(f=o.length,o.push(null)),h=f;else{const a=p*100+e[w];h=u.get(a),h===void 0&&(h=o.length,o.push(p===at?e[w]!==0:Rt[e[w]]??P.NA),u.set(a,h))}n[w]=h}}function be(c){const t=c.group,e=c.shared,s=new Int32Array(e.length);if(t.kind==="date"){const l=pt(t.start),i=pt(t.end),u=`<${Wt(t.start)}`,f=`>${Wt(t.end+1)}`,w=me(t.part,l.year,i.year);let p=[u,...w,f];t.labels&&t.labels.length===p.length&&(p=t.labels);for(let h=0;h<e.length;h++){const a=e[h];typeof a!="number"||a<t.start?s[h]=0:a>=t.end+1?s[h]=p.length-1:s[h]=1+we(t.part,pt(a),l.year)}return{map:s,labels:p}}if(t.kind==="bins"){const{start:l,end:i,interval:u}=t,f=Math.max(1,Math.ceil((i-l)/u-1e-9)),w=[`<${bt(l)}`];for(let h=0;h<f;h++){const a=l+h*u,d=t.integer?Math.max(a+u-1,h===f-1?i:0):a+u;w.push(`${bt(a)}-${bt(d)}`)}w.push(`>${bt(i)}`);const p=t.labels&&t.labels.length===w.length?t.labels:w;for(let h=0;h<e.length;h++){const a=e[h];typeof a!="number"||a<l?s[h]=0:a>i?s[h]=f+1:s[h]=1+Math.min(f-1,Math.floor((a-l)/u+1e-9))}return{map:s,labels:p}}const n=t.groups.map(l=>l.name),o=new Map;t.groups.forEach((l,i)=>{for(const u of l.keys)o.set(u,i)});const r=new Map;for(let l=0;l<e.length;l++){const i=ut(e[l]);let u=o.get(i);u===void 0&&(u=r.get(i),u===void 0&&(u=n.length,n.push(e[l]),r.set(i,u))),s[l]=u}return{map:s,labels:n}}const bt=c=>re(Number(c.toPrecision(12)));function Wt(c){const t=pt(c);return`${t.month}/${t.day}/${t.year}`}class ve{constructor(){this.list=[],this.index=new Map}get size(){return this.list.length}get(t){return this.list[t]??""}add(t){let e=this.index.get(t);return e===void 0&&(e=this.list.length,this.list.push(t),this.index.set(t,e)),e}}function _e(c,t,e,s,n,o){const r=c.columns[t];if(r===void 0)return;const l=e+s;for(let i=e>>>Tt;i<=l-1>>>Tt;i++){const u=r[i];if(u===void 0)continue;const f=i<<Tt,w=Math.max(e,f)&Ct,p=Math.min(l-1,f+Ct)&Ct,h=f-e,a=u.kinds,d=u.values;for(let m=w;m<=p;m++)n[h+m]=a[m]&Ft,o[h+m]=d[m]}}class gt{constructor(){this.fields=[],this.recordCount=0,this.strings=new ve,this.source=null,this.generation=0,this.xml=null,this.id=0,this.needsRefresh=!1}getString(t){return this.strings.get(t)}field(t){if(typeof t=="number")return this.fields[t];const e=String(t).toLowerCase();return this.fields.find(s=>s.name.toLowerCase()===e&&!s.removed)}fieldIndex(t){if(typeof t=="number")return t;const e=this.field(t);if(!e)throw new S("Unknown field: {name}",{name:t});return e.index}static fromSheet(t,e,s){const n=new gt;return n.strings=t.strings,n.source={type:"range",book:t,sheet:e,range:s},n.refresh(),n}static fromTable(t,e){const s=new gt;return s.strings=t.strings,s.source={type:"table",book:t,table:e},s.refresh(),s}static fromRows(t,e){const s=new gt,n=e.length;return s.recordCount=n,t.forEach((o,r)=>{const l=new Uint8Array(n),i=new Float64Array(n);for(let f=0;f<n;f++){const w=e[f][r];typeof w=="number"?(l[f]=B,i[f]=w):typeof w=="string"?(l[f]=Z,i[f]=s.strings.add(w)):typeof w=="boolean"?(l[f]=at,i[f]=w?1:0):w instanceof $&&(l[f]=ct,i[f]=w.index)}const u=new ft(s,r,o);Ht(u,l,i,n),s.fields.push(u)}),s}static fromColumns(t,e,s){const n=new gt;return s&&(n.strings=s),n.recordCount=e,t.forEach((o,r)=>{const l=new ft(n,r,o.name);l.kinds=o.kinds??null,l.nums=o.nums??null,l.strs=o.strs??null,l.uniformKind=o.strs?Z:o.kinds?K:B,o.numFmt&&qt(l,o.numFmt),n.fields.push(l)}),n}refresh(){const t=this.source;if(t===null){for(const p of this.fields)p.invalidate();return this.generation++,!1}const{book:e}=t;this.strings=e.strings;let s,n,o,r,l;if(t.type==="table"){const p=t.table;s=p.sheet??e.sheets[p.sheetIndex],n=p.r0,o=p.c0,r=p.r1-(p.totalsRows??0),l=p.c1}else{if({sheet:s}=t,typeof s=="string"&&(s=e.sheets.find(p=>p.name===t.sheet)),!s)throw new S("The PivotTable source sheet no longer exists.");({r0:n,c0:o,r1:r,c1:l}=t.range),r=Math.min(r,s.maxRow),l=Math.min(l,s.maxCol)}if(r<=n)throw new S("The PivotTable source needs a header row and at least one row of data.");const i=r-n,u=new Map,f=[];for(let p=o;p<=l;p++){const h=Te(e,s,n,p);if(h==="")throw new S("The PivotTable field name is not valid: every source column needs a header.");const a=h.toLowerCase(),d=(u.get(a)??0)+1;u.set(a,d),f.push(d>1?`${h}${d}`:h)}const w=new Map(this.fields.filter(p=>!p.isVirtual).map(p=>[p.name.toLowerCase(),p]));this.recordCount=i,f.forEach((p,h)=>{let a=w.get(p.toLowerCase());a?w.delete(p.toLowerCase()):(a=new ft(this,this.fields.length,p),this.fields.push(a));const d=o+h,m=new Uint8Array(i),A=new Float64Array(i);_e(s,d,n+1,i,m,A),Ht(a,m,A,i),a.removed=!1,a.reset();for(let g=0;g<i;g++)if(m[g]!==K){qt(a,e.styles.get(s.style(n+1+g,d)).numFmt);break}});for(const p of w.values())p.removed=!0,p.kinds=null,p.nums=null,p.strs=null,p.uniformKind=K,p.reset();for(const p of this.fields)p.isVirtual&&p.reset();return this._rescaleGroups(),this.generation++,this.needsRefresh=!1,!0}_rescaleGroups(){for(const t of this.fields){const e=t.group;if(t.base>=0||t.removed||e===null||e.kind==="discrete"||!(e.autoStart||e.autoEnd))continue;let s;try{s=this._numericRange(t)}catch{continue}for(let n=t;n;n=n.par>=0?this.fields[n.par]:null){const o=n.group;o.autoStart&&(o.start=e.kind==="date"?Math.floor(s.min):s.min),o.autoEnd&&(o.end=e.kind==="date"?Math.floor(s.max):s.max),o.labels=void 0}}}addCalculatedField(t,e){const s=new ft(this,this.fields.length,this._uniqueName(t));return s.formula=e.replace(/^\s*=\s*/,""),s.calc=Nt(s.formula,this),this.fields.push(s),s.index}updateCalculatedField(t,e){const s=this.fields[t],n=e.replace(/^\s*=\s*/,"");s.calc=Nt(n,this),s.formula=n,this.generation++}_uniqueName(t){let e=t,s=2;for(;this.fields.some(n=>n.name.toLowerCase()===e.toLowerCase());)e=`${t}${s++}`;return e}_numericRange(t){t.ensureRaw();let e=1/0,s=-1/0,n=!0;for(const o of t.shared){if(typeof o!="number")throw new S("Cannot group that selection.");o<e&&(e=o),o>s&&(s=o),Number.isInteger(o)||(n=!1)}if(e===1/0)throw new S("Cannot group that selection.");return{min:e,max:s,integer:n}}groupDates(t,e,{start:s,end:n}={}){const o=this.fields[t];if(o.isCalculated||o.base>=0)throw new S("Cannot group that selection.");const{min:r,max:l}=this._numericRange(o),i=he.filter(p=>e.includes(p));if(i.length===0)throw new S("Choose at least one grouping unit.");this.ungroup(t);const u={start:s??Math.floor(r),end:n??Math.floor(l)};o.group={kind:"date",part:i[0],...u,autoStart:s===void 0,autoEnd:n===void 0},o.invalidate();const f=[t];let w=o;for(const p of i.slice(1)){const h=new ft(this,this.fields.length,this._uniqueName(de[p]));h.base=t,h.group={kind:"date",part:p,...u,autoStart:s===void 0,autoEnd:n===void 0},this.fields.push(h),w.par=h.index,w=h,f.unshift(h.index)}return f}groupNumbers(t,{start:e,end:s,interval:n=10}={}){const o=this.fields[t];if(o.isCalculated||o.base>=0)throw new S("Cannot group that selection.");if(!(n>0))throw new S("The grouping interval must be greater than zero.");const{min:r,max:l,integer:i}=this._numericRange(o);this.ungroup(t);const u=e??r,f=s??l;if(f<=u)throw new S("The ending value must be greater than the starting value.");return o.group={kind:"bins",start:u,end:f,interval:n,integer:i&&Number.isInteger(u)&&Number.isInteger(n),autoStart:e===void 0,autoEnd:s===void 0},o.invalidate(),t}groupText(t,e,s){const n=this.fields[t];if(n.isCalculated)throw new S("Cannot group that selection.");n.ensureRaw();let o=n.par>=0?this.fields[n.par]:null;if(o&&o.group?.kind!=="discrete")throw new S("Cannot group that selection.");return o?(o.group.groups.push(...e),o.invalidate(),o.index):(o=new ft(this,this.fields.length,this._uniqueName(s??`${n.name}2`)),o.base=t,o.group={kind:"discrete",groups:e.map(r=>({name:r.name,keys:[...r.keys]}))},this.fields.push(o),n.par=o.index,o.index)}ungroup(t){const e=this.fields[t];if(e.base>=0&&e.group?.kind==="discrete"){this.fields[e.base].par=-1,e.removed=!0,e.group={kind:"discrete",groups:[]},e.invalidate();return}e.group=null,e.invalidate();let s=e.par;for(e.par=-1;s>=0;){const n=this.fields[s];n.removed=!0,s=n.par,n.par=-1}}}function qt(c,t){c.numFmt=t??"General";try{c.isDate=c.numFmt!=="General"&&Vt(c.numFmt).isDate===!0}catch{c.isDate=!1}}function Te(c,t,e,s){const n=t.kind(e,s)&Ft,o=t.value(e,s);return n===Z?c.strings.get(o).trim():n===B?St(o):n===at?o?"TRUE":"FALSE":n===ct?Dt[o]??"":""}function Ht(c,t,e,s){let n=0,o=0;for(let r=0;r<s;r++){const l=t[r];l===B?n++:l===Z&&o++}if(c.strs=null,c.kinds=null,c.nums=null,n===s&&s>0)c.uniformKind=B,c.nums=e;else if(o===s&&s>0){c.uniformKind=Z;const r=new Int32Array(s);for(let l=0;l<s;l++)r[l]=e[l];c.strs=r}else c.uniformKind=K,c.kinds=t,c.nums=e}const Ce=["<=",">=","<>","+","-","*","/","^","%","(",")",",","=","<",">","&"];function Re(c){const t=[];let e=0;for(;e<c.length;){const s=c[e];if(s<=" ")e++;else if(s>="0"&&s<="9"||s==="."&&c[e+1]>="0"&&c[e+1]<="9"){const n=/^(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/.exec(c.slice(e));t.push({t:"num",v:Number(n[0])}),e+=n[0].length}else if(s==="'"||s==='"'){let n=e+1,o="";for(;;){if(n>=c.length)throw new S("The formula has an unmatched quote.");if(c[n]===s){if(c[n+1]!==s)break;n++}o+=c[n++]}t.push({t:s==="'"?"name":"str",v:o}),e=n+1}else if(/[\p{L}_\\]/u.test(s)){const n=/^[\p{L}\p{N}_.\\]+/u.exec(c.slice(e));t.push({t:"name",v:n[0],bare:!0}),e+=n[0].length}else{const n=Ce.find(o=>c.startsWith(o,e));if(!n)throw new S("The formula has an unexpected character: {char}",{char:s});t.push({t:"op",v:n}),e+=n.length}}return t}const Kt=c=>c instanceof $?c:null,F=c=>{if(typeof c=="number")return c;if(typeof c=="boolean")return c?1:0;if(c===null)return 0;if(c instanceof $)throw c;const t=Number(c);if(typeof c=="string"&&c.trim()!==""&&!Number.isNaN(t))return t;throw P.VALUE},jt={IF:c=>{const t=c[0]();if(Kt(t))throw t;return(typeof t=="number"?t!==0:t===!0)?c[1]?c[1]():!0:c[2]?c[2]():!1},IFERROR:c=>{try{const t=c[0]();return Kt(t)?c[1]():t}catch(t){if(t instanceof $)return c[1]();throw t}},AND:c=>c.every(t=>F(t())!==0),OR:c=>c.some(t=>F(t())!==0),NOT:c=>F(c[0]())===0,SUM:c=>c.reduce((t,e)=>t+F(e()),0),MIN:c=>Math.min(...c.map(t=>F(t()))),MAX:c=>Math.max(...c.map(t=>F(t()))),AVERAGE:c=>c.reduce((t,e)=>t+F(e()),0)/c.length,COUNT:c=>c.length,TRUE:()=>!0,FALSE:()=>!1};function Nt(c,t){const e=Re(c);let s=0;const n=new Set,o=g=>e[s]?.t==="op"&&e[s].v===g,r=()=>new S("The formula is not valid."),l=g=>{const y=t.fields.find(b=>b.name.toLowerCase()===g.v.toLowerCase()&&!b.isCalculated),v=t.fields.find(b=>b.name.toLowerCase()===g.v.toLowerCase()&&b.isCalculated);if(v){for(const b of v.calc.refs)n.add(b);return b=>v.calc.fn(b)}if(!y)throw new S("The formula refers to an unknown field: {name}",{name:g.v});n.add(y.index);const _=y.index;return b=>b(_)},i=()=>{const g=e[s];if(!g)throw r();if(g.t==="num"){s++;const y=g.v;return()=>y}if(g.t==="str"){s++;const y=g.v;return()=>y}if(g.t==="name"){if(s++,g.bare&&o("(")){s++;const y=[];if(!o(")"))for(y.push(a());o(",");)s++,y.push(a());if(!o(")"))throw r();return s++,d(g.v.toUpperCase(),y)}if(g.bare&&m.has(g.v.toUpperCase())&&!t.field(g.v)){const y=jt[g.v.toUpperCase()];return()=>y([])}return l(g)}if(o("(")){s++;const y=a();if(!o(")"))throw r();return s++,y}throw r()},u=()=>{let g=i();for(;o("%");){s++;const y=g;g=v=>F(y(v))/100}return g},f=()=>{if(o("-")){s++;const g=f();return y=>-F(g(y))}return o("+")?(s++,f()):u()},w=()=>{let g=f();for(;o("^");){s++;const y=g,v=f();g=_=>{const b=F(y(_))**F(v(_));if(!Number.isFinite(b))throw P.NUM;return b}}return g},p=()=>{let g=w();for(;o("*")||o("/");){const y=e[s++].v,v=g,_=w();g=y==="*"?b=>F(v(b))*F(_(b)):b=>{const L=F(_(b));if(L===0)throw P.DIV0;return F(v(b))/L}}return g},h=()=>{let g=p();for(;o("+")||o("-");){const y=e[s++].v,v=g,_=p();g=y==="+"?b=>F(v(b))+F(_(b)):b=>F(v(b))-F(_(b))}return g},a=()=>{let g=h();for(;e[s]?.t==="op"&&["=","<>","<",">","<=",">="].includes(e[s].v);){const y=e[s++].v,v=g,_=h();g=b=>{const L=F(v(b)),R=F(_(b));switch(y){case"=":return L===R;case"<>":return L!==R;case"<":return L<R;case">":return L>R;case"<=":return L<=R;default:return L>=R}}}return g},d=(g,y)=>{const v=jt[g];if(v)return b=>v(y.map(L=>()=>L(b)));const _=oe.get(g);if(!_||_.kind!=="lift")throw new S("The formula uses a function a calculated field can't call: {name}",{name:g});if(y.length<_.min||y.length>_.max)throw r();return b=>{const L=y.map(R=>R(b));for(const R of L)if(R instanceof $)throw R;return _.fn(...L)}},m=new Set(["TRUE","FALSE"]),A=a();if(s<e.length)throw r();return{fn:A,refs:[...n]}}const ke={sum:"sum",average:"sum",count:"",countNums:"",max:"mm",min:"mm",product:"prod",stdDev:"var",stdDevp:"var",var:"var",varp:"var"};class Et{constructor(t,e){this.size=t,this.cnt=new Int32Array(t),this.num=new Int32Array(t),this.sum=e.sum?new Float64Array(t):null,this.min=e.mm?new Float64Array(t).fill(1/0):null,this.max=e.mm?new Float64Array(t).fill(-1/0):null,this.prod=e.prod?new Float64Array(t).fill(1):null,this.mean=e.var?new Float64Array(t):null,this.m2=e.var?new Float64Array(t):null,this.err=null}merge(t,e,s){const n=e.cnt[s];if(n===0)return;this.cnt[t]+=n;const o=e.num[s],r=this.num[t];if(this.num[t]=r+o,e.err!==null&&e.err[s]!==0&&(this.err===null&&(this.err=new Int8Array(this.size)),this.err[t]===0&&(this.err[t]=e.err[s])),o!==0&&(this.sum!==null&&(this.sum[t]+=e.sum[s]),this.min!==null&&(e.min[s]<this.min[t]&&(this.min[t]=e.min[s]),e.max[s]>this.max[t]&&(this.max[t]=e.max[s])),this.prod!==null&&(this.prod[t]*=e.prod[s]),this.mean!==null)){const l=e.mean[s]-this.mean[t],i=r+o;this.m2[t]+=e.m2[s]+l*l*r*o/i,this.mean[t]+=l*o/i}}value(t,e){const s=this.cnt[t];if(s===0)return null;if(e==="count")return s;if(e==="countNums")return this.num[t];if(this.err!==null&&this.err[t]!==0)return Rt[this.err[t]-1];const n=this.num[t];switch(e){case"sum":return this.sum[t];case"average":return n===0?P.DIV0:this.sum[t]/n;case"max":return n===0?0:this.max[t];case"min":return n===0?0:this.min[t];case"product":return n===0?0:this.prod[t];case"stdDev":return n<2?P.DIV0:Math.sqrt(this.m2[t]/(n-1));case"stdDevp":return n<1?P.DIV0:Math.sqrt(this.m2[t]/n);case"var":return n<2?P.DIV0:this.m2[t]/(n-1);case"varp":return n<1?P.DIV0:this.m2[t]/n;default:return null}}}function xe(c,t,e,s){const{cnt:n,num:o}=c;t.base<0&&t.ensureColumn();const{kinds:r,nums:l}=t;if(l===null||t.base>=0){for(let a=0;a<s;a++){const d=e[a];d>=0&&n[d]++}return}if(r===null){for(let a=0;a<s;a++){const d=e[a];d>=0&&n[d]++}o.set(n)}else for(let a=0;a<s;a++){const d=e[a];if(d<0)continue;const m=r[a];m!==K&&(n[d]++,m===B?o[d]++:m===ct&&(c.err===null&&(c.err=new Int8Array(c.size)),c.err[d]===0&&(c.err[d]=l[a]+1)))}const{sum:i,min:u,max:f,prod:w,mean:p,m2:h}=c;if(i!==null)if(r===null)for(let a=0;a<s;a++){const d=e[a];d>=0&&(i[d]+=l[a])}else for(let a=0;a<s;a++){const d=e[a];d>=0&&r[a]===B&&(i[d]+=l[a])}if(u!==null)for(let a=0;a<s;a++){const d=e[a];if(d<0||r!==null&&r[a]!==B)continue;const m=l[a];m<u[d]&&(u[d]=m),m>f[d]&&(f[d]=m)}if(w!==null)for(let a=0;a<s;a++){const d=e[a];d>=0&&(r===null||r[a]===B)&&(w[d]*=l[a])}if(p!==null){const a=new Int32Array(c.size);for(let d=0;d<s;d++){const m=e[d];if(m<0||r!==null&&r[d]!==B)continue;const A=++a[m],g=l[d]-p[m];p[m]+=g/A,h[m]+=g*(l[d]-p[m])}}}class Le{constructor(t,e,s){this.fields=e,this.slots=s,this.k=e.length,this.leaf=null,this.nLeaves=1,this.levelBase=[1],this.nNodes=1,this.parent=new Int32Array([-1]),this.item=new Int32Array([-1]),this.depth=new Uint8Array(1),this.cache=t,this.alive=null,this.childStart=null,this.childList=null,this.pos=null,this._childIndex=null,this.lines=null}leafNode(t){return this.k===0?0:this.levelBase[this.k-1]+t}ancestorAt(t,e){let s=t;for(;this.depth[s]>e;)s=this.parent[s];return this.depth[s]===e?s:-1}fieldAt(t){return this.cache.fields[this.fields[t-1]]}children(t){return this.childList.subarray(this.childStart[t],this.childStart[t+1])}findChild(t,e){if(this._childIndex===null){const s=new Map;this.stride=1;for(const n of this.fields)this.stride=Math.max(this.stride,this.cache.fields[n].items.length+1);for(let n=1;n<this.nNodes;n++)this.alive[n]&&s.set(this.parent[n]*this.stride+this.item[n],n);this._childIndex=s}return this._childIndex.get(t*this.stride+e)??-1}pathKeys(t){const e=[];for(let s=t;s>0;s=this.parent[s])e.push(this.fieldAt(this.depth[s]).keyOf(this.item[s]));return e.reverse()}peer(t,e,s){if(s<0)return-1;if(this.depth[t]===e)return s;const n=[];for(let r=t;this.depth[r]>e;r=this.parent[r])n.push(this.item[r]);let o=s;for(let r=n.length-1;r>=0&&o>=0;r--)o=this.findChild(o,n[r]);return o}}function Yt(c,t,e,s,n,o=null){const r=new Le(c,t,e),l=t.length;if(l===0)return r;let i=null,u=1;const f=[];for(let h=0;h<l;h++){const a=c.fields[t[h]].ensure(),d=a.ids,m=a.items.length,A=u*m,g=new Int32Array(s),y=Math.min(A,Math.max(s,1)),v=new Int32Array(y),_=new Int32Array(y);let b=0;if(A<=Pt){const D=new Int32Array(A).fill(-1);if(i===null)for(let C=0;C<s;C++){if(n!==null&&n[C]===0){g[C]=-1;continue}const N=d[C];let U=D[N];U<0&&(U=b++,D[N]=U,_[U]=N),g[C]=U}else for(let C=0;C<s;C++){const N=i[C];if(N<0){g[C]=-1;continue}const U=N*m+d[C];let I=D[U];I<0&&(I=b++,D[U]=I,v[I]=N,_[I]=d[C]),g[C]=I}}else{const D=new Map;for(let C=0;C<s;C++){const N=i===null?0:i[C];if(N<0||i===null&&n!==null&&n[C]===0){g[C]=-1;continue}const U=N*m+d[C];let I=D.get(U);I===void 0&&(I=b++,D.set(U,I),v[I]=N,_[I]=d[C]),g[C]=I}}const L=o?.(t[h]),R=L?Zt({parents:v,items:_,count:b},u,m,L.hide):{parents:v,items:_,count:b};f.push(R),i=g,u=Math.max(R.count,1)}r.leaf=i,r.nLeaves=f[l-1].count;let w=1;const p=[];for(const h of f)p.push(w),w+=h.count;return r.levelBase=p,r.nNodes=w,r.parent=new Int32Array(w),r.item=new Int32Array(w),r.depth=new Uint8Array(w),r.parent[0]=-1,r.item[0]=-1,f.forEach((h,a)=>{const d=p[a],m=a===0?0:p[a-1];for(let A=0;A<h.count;A++)r.parent[d+A]=a===0?0:m+h.parents[A],r.item[d+A]=h.items[A],r.depth[d+A]=a+1}),r}class Ne{constructor(t=1024){this.count=0,this.capacity=t,this.rows=new Int32Array(t),this.cols=new Int32Array(t),this.kinds=new Uint8Array(t),this.values=new Float64Array(t),this.roles=new Uint8Array(t),this.levels=new Uint8Array(t),this.formats=new Uint16Array(t),this.texts=[],this._textIndex=new Map,this.formatList=["General"],this._formatIndex=new Map([["General",0]])}_grow(){const t=this.capacity*2,e=(s,n)=>{const o=new s(t);return o.set(n),o};this.rows=e(Int32Array,this.rows),this.cols=e(Int32Array,this.cols),this.kinds=e(Uint8Array,this.kinds),this.values=e(Float64Array,this.values),this.roles=e(Uint8Array,this.roles),this.levels=e(Uint8Array,this.levels),this.formats=e(Uint16Array,this.formats),this.capacity=t}format(t){let e=this._formatIndex.get(t);return e===void 0&&(e=this.formatList.length,this.formatList.push(t),this._formatIndex.set(t,e)),e}text(t){let e=this._textIndex.get(t);return e===void 0&&(e=this.texts.length,this.texts.push(t),this._textIndex.set(t,e)),e}push(t,e,s,n,o,r=0,l=0){this.count===this.capacity&&this._grow();const i=this.count++;this.rows[i]=t,this.cols[i]=e,this.kinds[i]=s,this.values[i]=n,this.roles[i]=o,this.levels[i]=r,this.formats[i]=l}pushValue(t,e,s,n,o=0,r=0){s==null?this.push(t,e,K,0,n,o,r):typeof s=="number"?this.push(t,e,B,s,n,o,r):typeof s=="string"?this.push(t,e,Z,this.text(s),n,o,r):typeof s=="boolean"?this.push(t,e,at,s?1:0,n,o,r):this.push(t,e,ct,s.index,n,o,r)}valueAt(t){switch(this.kinds[t]){case B:return this.values[t];case Z:return this.texts[this.values[t]];case at:return this.values[t]!==0;case ct:return Dt[this.values[t]]??"#N/A";default:return null}}}function Xt(c){const t=c.replace(/[.+^${}()|[\]\\*?~]/g,e=>e==="*"?".*":e==="?"?".":`\\${e}`);return new RegExp(`^${t}$`,"is")}const Qt=c=>c.replace(/[.+^${}()|[\]\\]/g,"\\$&");function Ee(c){const{op:t}=c,e=String(c.value??""),s=String(c.value2??""),n=e.split(/([*?])/).map(r=>r==="*"?".*":r==="?"?".":Qt(r)).join(""),o=(r,l,i)=>{const u=typeof l=="number"?l:Number.NaN,f=i.trim()===""?Number.NaN:Number(i);return!Number.isNaN(u)&&!Number.isNaN(f)?u-f:Ut(r,i)};switch(t){case"captionEqual":{const r=Xt(e);return l=>r.test(l)}case"captionNotEqual":{const r=Xt(e);return l=>!r.test(l)}case"captionBeginsWith":{const r=new RegExp(`^${n}`,"is");return l=>r.test(l)}case"captionNotBeginsWith":{const r=new RegExp(`^${n}`,"is");return l=>!r.test(l)}case"captionEndsWith":{const r=new RegExp(`${n}$`,"is");return l=>r.test(l)}case"captionNotEndsWith":{const r=new RegExp(`${n}$`,"is");return l=>!r.test(l)}case"captionContains":{const r=new RegExp(n,"is");return l=>r.test(l)}case"captionNotContains":{const r=new RegExp(n,"is");return l=>!r.test(l)}case"captionGreaterThan":return(r,l)=>o(r,l,e)>0;case"captionGreaterThanOrEqual":return(r,l)=>o(r,l,e)>=0;case"captionLessThan":return(r,l)=>o(r,l,e)<0;case"captionLessThanOrEqual":return(r,l)=>o(r,l,e)<=0;case"captionBetween":return(r,l)=>o(r,l,e)>=0&&o(r,l,s)<=0;case"captionNotBetween":return(r,l)=>o(r,l,e)<0||o(r,l,s)>0;default:return()=>!0}}function Oe(c){const t=Number(c.value),e=Number(c.value2);switch(c.op){case"valueEqual":return s=>s===t;case"valueNotEqual":return s=>s!==t;case"valueGreaterThan":return s=>s>t;case"valueGreaterThanOrEqual":return s=>s>=t;case"valueLessThan":return s=>s<t;case"valueLessThanOrEqual":return s=>s<=t;case"valueBetween":return s=>s>=Math.min(t,e)&&s<=Math.max(t,e);case"valueNotBetween":return s=>s<Math.min(t,e)||s>Math.max(t,e);default:return()=>!0}}function wt(c,t){if(!t)return null;const e=t.hidden&&t.hidden.length>0;if(!e&&!t.labelFilter)return null;c.ensure();const s=new Uint8Array(c.items.length);if(e){const n=c.keyIndex;for(const o of t.hidden){const r=n.get(o);r!==void 0&&(s[r]=1)}}if(t.labelFilter){const n=Ee(t.labelFilter);c.items.forEach((o,r)=>{n(c.labelOfValue(o),o)||(s[r]=1)})}return s}function zt(c,t){return c.ensureRaw(),te(c.shared,t)}class Ie{constructor(t,e){this.rows=t,this.cols=e,this.dense=t*e<=ce,this.map=this.dense?null:new Map,this.size=this.dense?t*e:0}ensure(t,e){const s=t*this.cols+e;if(this.dense)return s;let n=this.map.get(s);return n===void 0&&(n=this.size++,this.map.set(s,n)),n}get(t,e){const s=t*this.cols+e;return this.dense?s:this.map.get(s)??-1}}class Me{constructor(t){this.pivot=t,this.cache=t.cache,this.spec=t.spec,this._aggregate(),this._arrange()}opts(t){return this.spec.fieldOptions[t]??null}_resolveData(){const{cache:t,spec:e}=this,s=new Map,n=(r,l)=>{let i=s.get(r);i===void 0&&(i={sum:!1,mm:!1,prod:!1,var:!1},s.set(r,i));const u=ke[l];u&&(i[u]=!0)},o=new Set;for(const r of Object.keys(e.fieldOptions)){const l=e.fieldOptions[r].subtotals;if(Array.isArray(l))for(const i of l)o.add(i)}this.data=e.values.map((r,l)=>{const i=t.fields[r.field],u={index:l,field:r.field,name:r.name,agg:r.agg,showAs:r.showAs??null,numFmt:r.numFmt??null,calc:null};if(i.isCalculated){u.calc=i.calc??(i.calc=Nt(i.formula,t));for(const f of u.calc.refs)n(f,"sum")}else{n(r.field,r.agg);for(const f of o)n(r.field,f)}return u}),this.needs=s}_recordMask(t){const{spec:e,cache:s}=this;let n=null;for(const o of Object.keys(e.fieldOptions)){const r=s.fields[o];if(!r||r.removed||r.isCalculated)continue;const l=wt(r,e.fieldOptions[o]);if(l!==null){n===null&&(n=new Uint8Array(t).fill(1));const i=r.ensure().ids;for(let u=0;u<t;u++)l[i[u]]===1&&(n[u]=0)}if(e.fieldOptions[o].range||e.fieldOptions[o].dateFilter){n===null&&(n=new Uint8Array(t).fill(1));const i=zt(r,e.fieldOptions[o]),u=r.rawIds;for(let f=0;f<t;f++)i[u[f]]===1&&(n[f]=0)}}return n}_aggregate(){const{cache:t,spec:e}=this,s=t.recordCount;this._resolveData();const n=this.data.length,o=y=>y.filter(v=>v!==x||n>1);let r=o(e.rows),l=o(e.cols);n>1&&!r.includes(x)&&!l.includes(x)&&(l=[...l,x]),r=r.filter(y=>y===x||!t.fields[y].removed),l=l.filter(y=>y===x||!t.fields[y].removed);const i=this._recordMask(s);this.mask=i;const u=y=>{const v=e.fieldOptions[y];return v?.showAll?{hide:wt(t.fields[y],v)}:null},f=Yt(t,r.filter(y=>y!==x),r,s,i,u),w=Yt(t,l.filter(y=>y!==x),l,s,i,u);this.rows=f,this.cols=w;let p,h,a,d;const m=f.nLeaves,A=w.nLeaves;if(f.leaf!==null&&w.leaf!==null){const y=f.leaf,v=w.leaf;p=new Int32Array(s);const _=m*A,b=Math.min(_,Math.max(s,1));if(h=new Int32Array(b),a=new Int32Array(b),d=0,_<=Pt){const L=new Int32Array(_).fill(-1);for(let R=0;R<s;R++){const D=y[R];if(D<0){p[R]=-1;continue}const C=D*A+v[R];let N=L[C];N<0&&(N=d++,L[C]=N,h[N]=D,a[N]=v[R]),p[R]=N}}else{const L=new Map;for(let R=0;R<s;R++){const D=y[R];if(D<0){p[R]=-1;continue}const C=D*A+v[R];let N=L.get(C);N===void 0&&(N=d++,L.set(C,N),h[N]=D,a[N]=v[R]),p[R]=N}}}else if(f.leaf!==null||w.leaf!==null){p=f.leaf??w.leaf,d=f.leaf!==null?m:A;const y=new Int32Array(d);for(let _=0;_<d;_++)y[_]=_;const v=new Int32Array(d);h=f.leaf!==null?y:v,a=f.leaf!==null?v:y}else{if(p=new Int32Array(s),d=1,i!==null)for(let y=0;y<s;y++)i[y]===0&&(p[y]=-1);h=new Int32Array(1),a=new Int32Array(1)}this.cellCount=d,this.cellRow=h,this.cellCol=a,this.cells=p;const g=new Map;for(const[y,v]of this.needs){const _=new Et(d,v);xe(_,t.fields[y],p,s),g.set(y,_)}this.leafAccs=g,this._applyValueFilters(),this._rollUp()}_slotValue(t,e,s,n){if(t.calc!==null){let o=!1;const r=l=>{const i=e.get(l);if(i.cnt[s]!==0&&(o=!0),i.err!==null&&i.err[s]!==0)throw Rt[i.err[s]-1];return i.sum[s]};try{const l=t.calc.fn(r);return o?typeof l=="number"?Number.isFinite(l)?l:P.NUM:typeof l=="boolean"?l?1:0:l instanceof $?l:P.VALUE:null}catch(l){if(l instanceof $)return l;throw l}}return e.get(t.field).value(s,n??t.agg)}_applyValueFilters(){const{rows:t,cols:e,data:s}=this;this.rowDead=new Uint8Array(t.nNodes),this.colDead=new Uint8Array(e.nNodes);const n=(o,r,l)=>{for(let i=1;i<=o.k;i++){const u=o.fields[i-1],f=this.opts(u);if(!f||!f.valueFilter&&!f.top)continue;const w=f.valueFilter??f.top,p=s[w.data??0];if(!p)continue;const h=this._nodeAccs(o,p,l),a=o.levelBase[i-1],d=i<o.k?o.levelBase[i]:o.nNodes,m=new Map;for(let A=a;A<d;A++){if(r[A]||r[o.parent[A]]){r[A]=1;continue}const g=o.parent[A];let y=m.get(g);y===void 0&&(y=[],m.set(g,y)),y.push(A)}for(const A of m.values()){const g=y=>{const v=this._slotValue(p,h,y,null);return typeof v=="number"?v:null};if(f.valueFilter){const y=Oe(f.valueFilter);for(const v of A){const _=g(v);(_===null||!y(_))&&(r[v]=1)}}if(f.top){const y=A.filter(v=>!r[v]);for(const v of Fe(y,g,f.top,!0))r[v]=1}}for(let A=d;A<o.nNodes;A++)r[o.parent[A]]&&(r[A]=1)}};n(t,this.rowDead,!0),n(e,this.colDead,!1)}_nodeAccs(t,e,s){const n=e.calc!==null?e.calc.refs:[e.field],o=new Map;for(const a of n)o.set(a,new Et(t.nNodes,this.needs.get(a)));const r=[...o.entries()].map(([a,d])=>[d,this.leafAccs.get(a)]),{cellRow:l,cellCol:i,rows:u,cols:f,rowDead:w,colDead:p}=this,h=s?l:i;for(let a=0;a<this.cellCount;a++){const d=u.leafNode(l[a]),m=f.leafNode(i[a]);if(w[d]||p[m])continue;let A=t.leafNode(h[a]);for(;A>=0;){for(const[g,y]of r)g.merge(A,y,a);A=t.parent[A]}}return o}_rollUp(){const{rows:t,cols:e,cellRow:s,cellCol:n,rowDead:o,colDead:r,cellCount:l}=this,i=new Uint8Array(t.nNodes),u=new Uint8Array(e.nNodes),f=new Ie(t.nNodes,e.nNodes),w=t.parent,p=e.parent,h=new Uint8Array(l);for(let g=0;g<l;g++){const y=t.leafNode(s[g]),v=e.leafNode(n[g]);if(!(o[y]||r[v])){h[g]=1;for(let _=y;_>=0;_=w[_])if(i[_]=1,!f.dense)for(let b=v;b>=0;b=p[b])f.ensure(_,b);for(let _=v;_>=0;_=p[_])u[_]=1}}t.alive=i,e.alive=u;const a=new Map,d=[];for(const[g,y]of this.needs){const v=new Et(Math.max(f.size,1),y);a.set(g,v),d.push([v,this.leafAccs.get(g)])}const m=f.dense,A=f.cols;for(let g=0;g<l;g++){if(h[g]===0)continue;const y=t.leafNode(s[g]),v=e.leafNode(n[g]);for(let _=y;_>=0;_=w[_])for(let b=v;b>=0;b=p[b]){const L=m?_*A+b:f.get(_,b);for(let R=0;R<d.length;R++)d[R][0].merge(L,d[R][1],g)}}this.slots=f,this.accs=a,this.cells=null,t.leaf=null,e.leaf=null}raw(t,e,s,n=null){if(e<0||s<0)return null;const o=this.slots.get(e,s);return o<0?null:this._slotValue(t,this.accs,o,n)}_baseLoc(t){if(t._loc!==void 0)return t._loc;const e=t.showAs?.baseField;let s=null;if(e!=null&&e>=0){let n=this.rows.fields.indexOf(e);n>=0?s={tree:this.rows,isRow:!0,depth:n+1}:(n=this.cols.fields.indexOf(e),n>=0&&(s={tree:this.cols,isRow:!1,depth:n+1}))}return t._loc=s,s}show(t,e,s,n=null){const o=t.showAs?.type;if(!o||o==="normal")return this.raw(t,e,s,n);const r=this.raw(t,e,s,n);if(r instanceof $)return r;const l=(m,A)=>this.raw(t,m,A,n),i=m=>m instanceof $?m:r===null?m===null?null:0:m===null||m===0?P.DIV0:r/m;switch(o){case"percentOfTotal":return i(l(0,0));case"percentOfCol":return i(l(0,s));case"percentOfRow":return i(l(e,0));case"percentOfParentRow":return i(e===0?r:l(this.rows.parent[e],s));case"percentOfParentCol":return i(s===0?r:l(e,this.cols.parent[s]));case"index":{const m=l(0,0),A=l(e,0),g=l(0,s);return[m,A,g].some(y=>y instanceof $)?P.VALUE:!A||!g?P.DIV0:(r??0)*m/(A*g)}default:}const u=this._baseLoc(t);if(u===null)return P.NA;const{tree:f,isRow:w,depth:p}=u,h=w?e:s;if(f.depth[h]<p)return null;const a=m=>w?l(m,s):l(e,m),d=f.ancestorAt(h,p);switch(o){case"percentOfParent":return i(a(d));case"percent":case"difference":case"percentDiff":{const m=this._baseSibling(t,f,d,p);if(m==="missing")return P.NA;if(m===-1)return o==="percent"?r===null?null:1:null;const A=a(f.peer(h,p,m));return m===d?o==="percent"?r===null?null:1:null:A instanceof $?A:o==="difference"?r===null&&A===null?null:(r??0)-(A??0):r===null||A===null?null:A===0?P.DIV0:o==="percent"?r/A:(r-A)/A}case"runTotal":case"percentOfRunningTotal":{const m=this._running(t,f,w,p,h,w?s:e,d,n);if(m instanceof $||o==="runTotal")return m;const A=f.children(f.parent[d]),g=this._running(t,f,w,p,h,w?s:e,A[A.length-1],n);return g instanceof $?g:g===0?P.DIV0:m/g}case"rankAscending":case"rankDescending":return r===null?null:this._rank(t,f,w,p,h,w?s:e,r,o==="rankAscending",n);default:return r}}_baseSibling(t,e,s,n){const o=t.showAs.baseItem,r=e.parent[s];if(o==="prev"||o==="next"){const f=e.children(r),w=e.pos[s]+(o==="prev"?-1:1);return w>=0&&w<f.length?f[w]:-1}const i=e.fieldAt(n).keyIndex.get(o);if(i===void 0)return"missing";const u=e.findChild(r,i);return u<0?"missing":u}_running(t,e,s,n,o,r,l,i){t._run===void 0&&(t._run=new Map);let u=t._run.get(i);u===void 0&&(u=new Map,t._run.set(i,u));const f=e.children(e.parent[l]),w=e.pos[l],p=s?this.cols.nNodes:this.rows.nNodes;let h=w,a=0;for(;h>=0;){const d=e.peer(o,n,f[h]),m=d>=0?u.get(d*p+r):void 0;if(m!==void 0){a=m;break}h--}for(let d=h+1;d<=w;d++){const m=e.peer(o,n,f[d]);if(m<0)continue;const A=s?this.raw(t,m,r,i):this.raw(t,r,m,i);if(A instanceof $)return A;typeof A=="number"&&(a+=A),u.set(m*p+r,a)}return a}_rank(t,e,s,n,o,r,l,i,u){t._ranks===void 0&&(t._ranks=new Map);const f=e.ancestorAt(o,n),w=e.pathKeys(o).slice(n).join(Lt),p=`${e.parent[f]}|${r}|${w}`;let h=t._ranks.get(p);if(h===void 0){const m=[];for(const A of e.children(e.parent[f])){const g=e.peer(o,n,A);if(g<0)continue;const y=s?this.raw(t,g,r,u):this.raw(t,r,g,u);typeof y=="number"&&m.push(y)}h=Float64Array.from(m).sort(),t._ranks.set(p,h)}let a=0,d=h.length;if(i){for(;a<d;){const m=a+d>>1;h[m]<l?a=m+1:d=m}return a+1}for(;a<d;){const m=a+d>>1;h[m]<=l?a=m+1:d=m}return h.length-a+1}_arrange(){for(const t of this.data)t._run=void 0,t._ranks=void 0;this._buildChildren(this.rows,!0),this._buildChildren(this.cols,!1),this.rows.lines=this._buildLines(this.rows,!0),this.cols.lines=this._buildLines(this.cols,!1),this._layout()}rearrange(){return this._arrange(),this}_buildChildren(t,e){const{nNodes:s,parent:n,alive:o}=t,r=new Int32Array(s+1);for(let u=1;u<s;u++)o[u]&&r[n[u]+1]++;for(let u=0;u<s;u++)r[u+1]+=r[u];const l=new Int32Array(r[s]),i=r.slice();for(let u=1;u<s;u++)o[u]&&(l[i[n[u]]++]=u);t.childStart=r,t.childList=l,t.pos=new Int32Array(s),t._childIndex=null;for(let u=0;u<t.k;u++){const f=this._sortCompare(t,u+1,e),w=u===0?0:t.levelBase[u-1],p=u===0?1:t.levelBase[u];for(let h=w;h<p;h++){const a=r[h],d=r[h+1];if(d-a>1){const m=Array.from(l.subarray(a,d));m.sort(f),l.set(m,a)}for(let m=a;m<d;m++)t.pos[l[m]]=m-a}}}_sortCompare(t,e,s){const n=t.fields[e-1],o=this.cache.fields[n].ensure(),r=o.rank(),{item:l}=t,i=this.opts(n)?.sort;if((!i||i.order==="asc"||i.order===void 0)&&(!i||i.data===void 0||i.data===null))return(d,m)=>r[l[d]]-r[l[m]];if(i.order==="manual"){const d=i.keys??[],m=new Map(d.map((g,y)=>[g,y])),A=new Float64Array(o.items.length);return o.items.forEach((g,y)=>{const v=m.get(ut(g));A[y]=v===void 0?d.length+r[y]:v}),(g,y)=>A[l[g]]-A[l[y]]}const u=i.order==="desc"?-1:1;if(i.data===void 0||i.data===null)return(d,m)=>u*(r[l[d]]-r[l[m]]);const f=this.data[i.data];if(!f)return(d,m)=>r[l[d]]-r[l[m]];let w=0;if(i.path){const d=s?this.cols:this.rows;this._ensureItems(d);for(let m=0;m<i.path.length&&w>=0;m++){const g=d.fieldAt(m+1).keyIndex.get(i.path[m]);w=g===void 0?-1:d.findChild(w,g)}}const p=d=>{const m=s?this.raw(f,d,w):this.raw(f,w,d);return typeof m=="number"?m:null},h=new Map,a=d=>{let m=h.get(d);return m===void 0&&(m=p(d),h.set(d,m)),m};return(d,m)=>{const A=a(d),g=a(m);return A===null||g===null?A===g?r[l[d]]-r[l[m]]:A===null?1:-1:A===g?r[l[d]]-r[l[m]]:u*(A-g)}}_ensureItems(t){for(const e of t.fields)this.cache.fields[e].ensure()}_form(t){return this.opts(t)?.layout??this.spec.layout}_isCollapsed(t,e,s){const n=t.depth[e],o=s[n];return o===null?!1:!!(o.items!==null&&o.items.has(t.fieldAt(n).keyOf(t.item[e]))||o.paths!==null&&o.paths.has(t.pathKeys(e).join(Lt)))}_buildLines(t,e){const{slots:s}=t,n=this.data.length,o={node:[],data:[],type:[],level:[],first:[],func:[],top:[],parentLine:[]},r=(h,a,d,m,A,g,y,v)=>{o.node.push(h),o.data.push(a),o.type.push(d),o.level.push(m),o.first.push(A),o.func.push(g),o.top.push(y?1:0),o.parentLine.push(v?1:0)},l=s.length-1,i=h=>e?s[h]===x?this.spec.layout:this._form(s[h]):"tabular",u=[null];for(let h=1;h<=t.k;h++){const a=this.opts(t.fields[h-1]),d=a?.collapsedItems?.length?new Set(a.collapsedItems):null,m=a?.collapsed?.length?new Set(a.collapsed):null;u.push(d||m?{items:d,paths:m}:null)}const f=h=>this.opts(h)?.subtotalTop??this.spec.subtotalTop,w=(h,a,d,m)=>{const A=s[a];if(A===x){for(let _=0;_<n;_++){const b=_===0&&m!==-1?m:a;a===l?r(h,_,X,a,b,null,!1,!1):i(a)==="tabular"?w(h,a+1,_,b):(r(h,_,X,a,b,null,!1,!0),o.noValues??=new Set,o.noValues.add(o.node.length-1),w(h,a+1,_,-1))}return}const g=t.children(h),y=this.opts(A),v=y?.blankLine===!0&&e;for(let _=0;_<g.length;_++){const b=g[_],L=_===0&&m!==-1?m:a;if(a===l){r(b,d,X,a,L,null,!1,!1);continue}const R=i(a),D=d<0&&s.indexOf(x,a+1)>=0;if(this._isCollapsed(t,b,u)){if(D)for(let z=0;z<n;z++)r(b,z,X,a,z===0?L:a,null,!1,R!=="tabular");else r(b,d,X,a,L,null,!1,R!=="tabular");o.collapsed??=new Set,o.collapsed.add(b),v&&r(b,d,mt,a,a,null,!1,!1);continue}const C=y?.subtotals??"auto",N=Array.isArray(C),U=C!=="none"&&!(N&&C.length===0),I=R!=="tabular"&&!D&&!N&&U&&f(A);if(R==="tabular"?w(b,a+1,d,L):(r(b,d,X,a,L,null,I,!0),I||(o.noValues??=new Set,o.noValues.add(o.node.length-1)),w(b,a+1,d,-1)),!I&&U&&!(a+1===l&&s[a+1]===x&&!N)){const yt=N?C:[null];if(D)for(let tt=0;tt<n;tt++)for(const vt of yt)r(b,tt,lt,a,a,vt,!1,!1);else for(const tt of yt)r(b,d,lt,a,a,tt,!1,!1)}v&&r(b,d,mt,a,a,null,!1,!1)}};if(s.length===0)return r(0,-1,X,-1,0,null,!1,!1),o;if(w(0,0,-1,-1),t.k>0&&(e?this.spec.grandRow:this.spec.grandCol))if(s.includes(x))for(let h=0;h<n;h++)r(0,h,st,0,0,null,!1,!1);else r(0,-1,st,0,0,null,!1,!1);return o}fieldCaption(t){return t===x?this.spec.dataCaption:this.opts(t)?.caption??this.cache.fields[t].name}itemCaption(t,e){const s=t.fieldAt(t.depth[e]),n=t.item[e],o=this.opts(s.index)?.itemCaptions;if(o){const r=o[s.keyOf(n)];if(r!==void 0)return r}return null}_labelValue(t,e){const s=this.itemCaption(t,e);if(s!==null)return s;const n=t.fieldAt(t.depth[e]).items[t.item[e]];return n??"(blank)"}_labelText(t,e){const s=this.itemCaption(t,e);return s!==null?s:t.fieldAt(t.depth[e]).labelOf(t.item[e])}_subtotalLabel(t,e,s){const n=this._labelText(t,e.node[s]),o=e.data[s],r=e.func[s];return r!==null&&o>=0?`${n} ${kt[r]} of ${this.data[o].name}`:r!==null?`${n} ${kt[r]}`:o>=0?`${n} ${this.data[o].name}`:`${n} Total`}_pageValue(t){const e=this.cache.fields[t].ensure(),s=wt(e,this.opts(t));if(s===null)return{text:"(All)",value:"(All)"};let n=0,o=-1;for(let r=0;r<s.length;r++)s[r]===0&&(n++,o=r);return n===s.length?{text:"(All)",value:"(All)"}:n===1?{text:e.labelOf(o),value:e.items[o]??"(blank)"}:{text:"(Multiple Items)",value:"(Multiple Items)"}}_layout(){const{spec:t,rows:e,cols:s,data:n}=this,o=new Ne;this.buffer=o;const r=n.length,l=t.filters.filter(T=>!this.cache.fields[T].removed),i=l.length>0?l.length+1:0,u=e.slots.length===0&&s.slots.length===0&&r===0;l.forEach((T,k)=>{o.pushValue(k,0,this.fieldCaption(T),E.PAGE_LABEL);const O=this.cache.fields[T],W=this._pageValue(T);o.pushValue(k,1,W.value,E.PAGE_VALUE,0,typeof W.value=="number"?o.format(O.numFmt):0)});const f=[],w=[];let p=0;if(e.slots.length>0){let T=0,k=0;for(let W=0;W<e.slots.length;W++)f.push(T),w.push(k),(e.slots[W]===x?t.layout:this._form(e.slots[W]))==="compact"?k++:(T++,k=0);p=(e.slots[e.slots.length-1]===x?t.layout:this._form(e.slots[e.slots.length-1]))==="compact"?T+1:T}else r<=1&&s.slots.length>0&&!(s.slots.length===1&&s.slots[0]===x)&&(p=1);const h=e.lines,a=s.lines,d=a.node.length,m=h.node.length,A=s.slots.length===1&&s.slots[0]===x,g=A&&!t.hideValuesRow&&e.slots.length>0,y=s.slots.length>0&&(!A||g),v=u?0:y?1+s.slots.length:1,_=y?t.layout==="compact"?1:s.slots.length:0,b=p+Math.max(r>0||y?d:0,_),L=r>0||e.slots.length>0?m:0,R=i,D=new Uint8Array(v*Math.max(b,1)),C=(T,k,O,W,H=0,V=0)=>{o.pushValue(R+T,k,O,W,V,H),D[T*b+k]=1},N=T=>t.layout==="compact"?null:T.map(k=>this.fieldCaption(k));u&&o.pushValue(R,0,t.name,E.PLACEHOLDER);const U=v-1;if(e.slots.length>0){const T=N(e.slots);T===null?C(U,0,t.rowCaption??G("Row Labels"),E.ROW_CAPTION):e.slots.forEach((k,O)=>{(k===x?t.layout:this._form(k))==="compact"&&O>0&&f[O]===f[O-1]||D[U*b+f[O]]||C(U,f[O],T[O],E.ROW_CAPTION)})}if(y){r===1&&e.slots.length>0&&C(0,0,n[0].name,E.CORNER);const T=N(s.slots);g?C(0,p,t.dataCaption,E.COL_CAPTION):T===null?C(0,p,t.colCaption??G("Column Labels"),E.COL_CAPTION):T.forEach((k,O)=>C(0,p+O,k,E.COL_CAPTION))}else r===1&&!A&&!e.slots.includes(x)&&C(0,p,n[0].name,E.DATA_HEADER);const I=y?1:0;if(r>0||y)for(let T=0;T<d;T++){const k=a.type[T],O=p+T,W=a.node[T];if(k===st){const V=a.data[T],ht=V>=0?`Total ${n[V].name}`:t.grandCaption??G("Grand Total");C(I,O,ht,E.COL_GRAND);continue}if(k===lt){C(I+a.level[T],O,this._subtotalLabel(s,a,T),E.COL_SUBTOTAL);continue}const H=a.level[T];for(let V=a.first[T];V<=H;V++){if(V<0||V>=s.slots.length)continue;if(s.slots[V]===x){const j=a.data[T];j>=0&&C(I+V,O,n[j].name,E.DATA_HEADER)}else{const j=Ot(s.slots,V),J=s.ancestorAt(W,j);if(V===H&&a.collapsed?.has(J))C(I+V,O,`${this._labelText(s,J)} Total`,E.COL_ITEM);else{const At=this._labelValue(s,J);C(I+V,O,At,E.COL_ITEM,typeof At=="number"?o.format(s.fieldAt(j).numFmt):0,t.showExpandButtons&&j<s.k?1:0)}}}}for(let T=0;T<v;T++)for(let k=0;k<b;k++)D[T*b+k]===0&&o.push(R+T,k,K,0,E.HEADER_BLANK);const z=R+v,yt=n.map(T=>{const k=T.numFmt??De(T);return o.format(k)}),tt=h.noValues??null,vt=T=>e.slots[T];for(let T=0;T<L;T++){const k=z+T,O=h.type[T];if(O===mt)continue;const W=h.node[T],H=h.level[T],V=h.parentLine[T]===1;let ht=E.ROW_ITEM,j=E.DATA;O===lt?(ht=E.ROW_SUBTOTAL,j=E.DATA_SUBTOTAL):O===st?(ht=E.ROW_GRAND,j=E.DATA_GRAND_ROW):V&&(j=E.DATA_PARENT);const J=Math.max(H,0);if(p>0)if(e.slots.length===0)r===1&&o.pushValue(k,0,n[0].name,E.ROW_ITEM);else if(O===st){const q=h.data[T];o.pushValue(k,0,q>=0?`Total ${n[q].name}`:t.grandCaption??G("Grand Total"),E.ROW_GRAND);for(let M=1;M<p;M++)o.push(k,M,K,0,E.ROW_GRAND)}else if(O===lt){const q=f[H];for(let M=0;M<p;M++)M===q?o.pushValue(k,M,this._subtotalLabel(e,h,T),E.ROW_SUBTOTAL,w[H]):o.push(k,M,K,0,E.ROW_SUBTOTAL)}else{const q=this._labelStart(h,T,e);for(let M=q;M<=H;M++){const dt=vt(M),nt=f[M],rt=M===H&&V?E.ROW_PARENT:E.ROW_ITEM;if(dt===x){const Q=h.data[T];Q>=0&&o.pushValue(k,nt,n[Q].name,rt,w[M])}else{const Q=Ot(e.slots,M),ot=e.ancestorAt(W,Q),Y=t.showExpandButtons&&Q<e.k?1:0;if(M===H&&h.collapsed?.has(ot)&&this._form(dt)==="tabular")o.pushValue(k,nt,`${this._labelText(e,ot)} Total`,rt,w[M]+Y);else{const et=this._labelValue(e,ot),Jt=typeof et=="number"?o.format(e.fieldAt(Q).numFmt):0;o.pushValue(k,nt,et,rt,w[M]+Y,Jt)}}}}if(r===0||tt!==null&&tt.has(T))continue;const _t=h.data[T],At=h.func[T];for(let q=0;q<d;q++){const M=a.type[q];if(M===mt)continue;const dt=a.data[q],nt=_t>=0?_t:dt>=0?dt:r===1?0:-1;if(nt<0)continue;const rt=n[nt],Q=At??a.func[q],ot=this.show(rt,W,a.node[q],Q);let Y=j;O!==st&&M===st?Y=E.DATA_GRAND_COL:O===X&&!V&&M===lt&&(Y=E.DATA);const it=p+q,et=Q&&Q!==rt.agg&&!rt.numFmt?0:yt[nt];ot===null?t.showMissing===!1?o.pushValue(k,it,0,Y,J,et):t.emptyText!==""?o.pushValue(k,it,t.emptyText,Y,J,et):Y!==E.DATA&&o.push(k,it,K,0,Y,J,et):ot instanceof $&&t.errorText!==null?o.pushValue(k,it,t.errorText,Y,J,et):o.pushValue(k,it,ot,Y,J,et)}}const It=u?R+1:z+L,Mt=Math.max(b,l.length>0?2:0,u?1:0);if(It>ne||Mt>se)throw new S("The PivotTable is too large for a worksheet.");this.layout={cells:o,rows:It,cols:Mt,bodyCols:b,pageRows:i,pageFields:l,headerRows:v,labelCols:p,bodyTop:z,dataRows:L,colForLevel:f,indentForLevel:w,colRowBase:I,firstHeaderRow:u||y?1:r>1?0:1,firstDataRow:u?1:v,firstDataCol:p}}_labelStart(t,e,s){const n=t.level[e],o=t.first[e];if(o===0)return 0;for(let r=0;r<o;r++){const l=s.slots[r];if(l!==x&&this.opts(l)?.repeatLabels||l!==x&&this.spec.repeatLabels&&this._form(l)!=="compact")return r}return Math.min(o,n)}toRows(){const{cells:t,rows:e,cols:s}=this.layout,n=[];for(let o=0;o<e;o++)n.push(new Array(s).fill(null));for(let o=0;o<t.count;o++)n[t.rows[o]][t.cols[o]]=t.valueAt(o);return n}hitTest(t,e){const s=this.layout,{spec:n,rows:o,cols:r}=this;if(t<s.pageRows-1){const i=s.pageFields[t];return i!==void 0&&e===1?{kind:"pageFilter",field:i}:null}const l=t-s.pageRows;if(l<0||t>=s.rows)return null;if(l===s.headerRows-1&&e<s.labelCols&&o.fields.length>0){const i=n.layout==="compact"?o.fields:o.slots.filter((u,f)=>u!==x&&s.colForLevel[f]===e);if(i.length>0)return{kind:"filter",axis:"row",fields:i}}if(l===0&&e>=s.labelCols&&r.fields.length>0&&s.colRowBase===1){const i=n.layout==="compact"?e===s.labelCols?r.fields:[]:r.slots.filter((u,f)=>u!==x&&f===e-s.labelCols);if(i.length>0)return{kind:"filter",axis:"col",fields:i}}if(l>=s.headerRows&&e<s.labelCols){const i=this._rowLabelAt(l-s.headerRows,e);if(i!==null)return i}if(l>=s.colRowBase&&l<s.headerRows&&e>=s.labelCols){const i=this._colLabelAt(e-s.labelCols,l-s.colRowBase);if(i!==null)return i}return l>=s.headerRows&&e>=s.labelCols?{kind:"value",rowLine:l-s.headerRows,colLine:e-s.labelCols}:null}_rowLabelAt(t,e){const{rows:s}=this,n=s.lines;if(t>=n.node.length||n.type[t]!==X)return null;const o=this.layout.colForLevel;for(let r=n.level[t];r>=this._labelStart(n,t,s);r--)if(o[r]===e)return this._labelHit(s,n,t,r,"row");return null}_colLabelAt(t,e){const{cols:s}=this,n=s.lines;return t>=n.node.length||n.type[t]!==X||e<n.first[t]||e>n.level[t]?null:this._labelHit(s,n,t,e,"col")}_labelHit(t,e,s,n,o){const r=t.slots[n];if(r===x||r===void 0)return null;const l=Ot(t.slots,n),i=t.ancestorAt(e.node[s],l),u=l<t.k;return{kind:"label",axis:o,node:i,field:r,path:t.pathKeys(i),expandable:u,collapsed:u&&e.collapsed?.has(i)===!0}}togglesIn(t,e,s,n){const o=[],r=this.layout,{rows:l,cols:i}=this;if(this.spec.showExpandButtons===!1)return o;if(l.k>1)for(let u=Math.max(t,r.bodyTop);u<=Math.min(s,r.rows-1);u++)for(let f=e;f<=Math.min(n,r.labelCols-1);f++){const w=this._rowLabelAt(u-r.bodyTop,f);w!==null&&w.expandable&&o.push({row:u,col:f,collapsed:w.collapsed,indent:this._levelIndent(w)})}if(i.k>1){const u=r.pageRows+r.colRowBase;for(let f=Math.max(t,u);f<=Math.min(s,r.pageRows+r.headerRows-1);f++)for(let w=Math.max(e,r.labelCols);w<=Math.min(n,r.cols-1);w++){const p=this._colLabelAt(w-r.labelCols,f-u);p!==null&&p.expandable&&o.push({row:f,col:w,collapsed:p.collapsed,indent:0})}}return o}_levelIndent(t){const e=this.rows.slots.indexOf(t.field);return e>=0?this.layout.indentForLevel[e]:0}filterButtons(){const t=this.layout,{rows:e,cols:s,spec:n}=this,o=[];if(t.pageFields.forEach((r,l)=>o.push({row:l,col:1,axis:"page",fields:[r]})),e.fields.length>0&&n.showFieldHeaders!==!1){const r=t.pageRows+t.headerRows-1;n.layout==="compact"?o.push({row:r,col:0,axis:"row",fields:e.fields}):e.slots.forEach((l,i)=>{l!==x&&(i===0||t.colForLevel[i]!==t.colForLevel[i-1])&&o.push({row:r,col:t.colForLevel[i],axis:"row",fields:[l]})})}if(s.fields.length>0&&n.showFieldHeaders!==!1&&t.colRowBase===1){const r=t.pageRows;n.layout==="compact"?o.push({row:r,col:t.labelCols,axis:"col",fields:s.fields}):s.slots.forEach((l,i)=>{l!==x&&o.push({row:r,col:t.labelCols+i,axis:"col",fields:[l]})})}return o}}function Ot(c,t){let e=0;for(let s=0;s<=t;s++)c[s]!==x&&e++;return e}function De(c){const t=c.showAs?.type;return ae.has(t)?"0.00%":t==="index"?"0.00":"General"}function Fe(c,t,e,s){const n=e.count??10,o=e.by??"items",r=e.bottom===!0,l=c.map(u=>[u,t(u)]).filter(u=>u[1]!==null);l.sort((u,f)=>r?u[1]-f[1]:f[1]-u[1]);const i=new Set;if(o==="items"){if(l.length>0&&n>0){const u=l[Math.min(n,l.length)-1][1];for(const[f,w]of l)(r?w<=u:w>=u)&&i.add(f)}}else{const u=l.reduce((p,h)=>p+h[1],0),f=o==="percent"?u*n/100:n;let w=0;for(const[p,h]of l)if(i.add(p),w+=h,w>=f)break}return s?c.filter(u=>!i.has(u)):c.filter(u=>i.has(u))}function Se(c){return{name:"PivotTable1",rows:[],cols:[],values:[],filters:[],fieldOptions:{},layout:"compact",subtotalTop:!0,grandRow:!0,grandCol:!0,repeatLabels:!1,rowCaption:null,colCaption:null,dataCaption:G("Values"),grandCaption:null,emptyText:"",errorText:null,style:{name:"PivotStyleLight16",rowHeaders:!0,colHeaders:!0,rowStripes:!1,colStripes:!1,lastColumn:!0},showExpandButtons:!0,showFieldHeaders:!0,hideValuesRow:!0,...c}}class Ze{constructor(t,e={}){this.cache=t,this.spec=Se(e),this.result=null,this.listeners=new Set,this.anchor=null,this.xml=null,this.dirty=!0}onChange(t){return this.listeners.add(t),()=>this.listeners.delete(t)}_emit(){this.dirty=!0;for(const t of this.listeners)t(this)}update(){if(this.cache.needsRefresh){if(this.cache.source===null)throw new S("The PivotTable report was saved without the underlying data. Its source is not available.");this.cache.refresh()}return this._dropRemoved(),this.result=new Me(this),this._emit(),this.result}rearrange(){return this.result===null?this.update():(this.result.rearrange(),this._emit(),this.result)}refresh(){return this.cache.refresh(),this.update()}_dropRemoved(){const{spec:t,cache:e}=this,s=n=>n===x||!e.fields[n]?.removed;t.rows=t.rows.filter(s),t.cols=t.cols.filter(s),t.filters=t.filters.filter(s),t.values=t.values.filter(n=>s(n.field))}options(t){const{fieldOptions:e}=this.spec;let s=e[t];return s===void 0&&(s={},e[t]=s),s}defaultAgg(t){const e=this.cache.fields[t];return e.isCalculated?"sum":e.base>=0||e.isDate?"count":this._allNumeric(e)?"sum":"count"}_allNumeric(t){return t.strs!==null?!1:t.rawIds!==null?t.shared.every(e=>typeof e=="number"):t.kinds===null?t.nums!==null:t.kinds.every(e=>e===B)}uniqueDataName(t,e=-1){let s=t,n=2;const o=r=>this.spec.values.some((l,i)=>i!==e&&l.name.toLowerCase()===r.toLowerCase());for(;o(s);)s=`${t}${n++}`;return s}addValue(t,e=this.defaultAgg(t),s=this.spec.values.length){const n=this.cache.fields[t],o=xt(n.isCalculated?"sum":e,n.name);return this.spec.values.splice(s,0,{field:t,agg:e,name:this.uniqueDataName(o)}),this.spec.values.length>1&&!this.spec.rows.includes(x)&&!this.spec.cols.includes(x)&&this.spec.cols.push(x),this.spec.values.length-1}setValueAgg(t,e){const s=this.spec.values[t],n=this.cache.fields[s.field],o=[xt(s.agg,n.name),`${le[s.agg]} of ${n.name}`].some(r=>new RegExp(`^${Qt(r)}\\d*$`).test(s.name));s.agg=e,o&&(s.name=this.uniqueDataName(xt(e,n.name),t))}place(t,e,s){const{spec:n}=this;for(const r of["rows","cols","filters"])n[r]=n[r].filter(l=>l!==t);if(t===x&&e==="filters")return;const o=n[e];s===void 0||s>o.length?o.push(t):o.splice(s,0,t)}removeFromLayout(t){const{spec:e}=this;for(const s of["rows","cols","filters"])e[s]=e[s].filter(n=>n!==t);e.values=e.values.filter(s=>s.field!==t),e.values.length<=1&&(e.rows=e.rows.filter(s=>s!==x),e.cols=e.cols.filter(s=>s!==x))}removeValue(t){const{spec:e}=this;e.values.splice(t,1),e.values.length<=1&&(e.rows=e.rows.filter(s=>s!==x),e.cols=e.cols.filter(s=>s!==x))}moveValue(t,e){const s=this.spec.values,[n]=s.splice(t,1);s.splice(Math.max(0,Math.min(e,s.length)),0,n)}isUsed(t){const{spec:e}=this;return e.rows.includes(t)||e.cols.includes(t)||e.filters.includes(t)||e.values.some(s=>s.field===t)}itemsOf(t){const e=this.cache.fields[t].ensure(),s=e.rank(),n=wt(e,{hidden:this.spec.fieldOptions[t]?.hidden})??new Uint8Array(e.items.length),o=new Array(e.items.length);for(let r=0;r<o.length;r++)o[s[r]]={id:r,key:ut(e.items[r]),label:e.labelOf(r),value:e.items[r],hidden:n[r]===1};return o}itemsWithData(t){const e=this.cache.fields[t].ensure(),s=new Uint8Array(e.items.length),n=this.cache.recordCount,o=[];for(const l of Object.keys(this.spec.fieldOptions)){if(Number(l)===t)continue;const i=this.cache.fields[l];if(!i||i.removed||i.isCalculated)continue;const u=wt(i,this.spec.fieldOptions[l]);if(u!==null&&o.push([i.ensure().ids,u]),this.spec.fieldOptions[l].range||this.spec.fieldOptions[l].dateFilter){const f=zt(i,this.spec.fieldOptions[l]);o.push([i.rawIds,f])}}const{ids:r}=e;t:for(let l=0;l<n;l++){for(let i=0;i<o.length;i++)if(o[i][1][o[i][0][l]]===1)continue t;s[r[l]]=1}return s}setHidden(t,e){const s=this.options(t);s.hidden=[...e]}clearFilters(t){const e=this.options(t);delete e.hidden,delete e.labelFilter,delete e.valueFilter,delete e.top,delete e.range,delete e.dateFilter}hasFilter(t){const e=this.spec.fieldOptions[t];return!!e&&(e.hidden&&e.hidden.length>0||!!e.labelFilter||!!e.valueFilter||!!e.top||!!e.range||!!e.dateFilter)}toggleCollapse(t){const e=this.options(t.field),s=t.path.join(Lt),n=new Set(e.collapsed??[]),o=t.path[t.path.length-1];return t.collapsed?(n.delete(s),e.collapsedItems&&(e.collapsedItems=e.collapsedItems.filter(r=>r!==o))):n.add(s),e.collapsed=[...n],this.rearrange()}setFieldCollapsed(t,e){const s=this.options(t);s.collapsed=[];const n=this.cache.fields[t].ensure();return s.collapsedItems=e?n.items.map(o=>ut(o)):[],this.rearrange()}}export{Ke as AGGS,kt as AGG_LABEL,Ne as CellBuffer,Qe as LABEL_FILTERS,Je as LINE,gt as PivotCache,S as PivotError,ft as PivotField,Me as PivotResult,Ze as PivotTable,E as ROLE,je as SHOW_AS,x as VALUES,ze as VALUE_FILTERS,qt as applyNumFmt,Nt as compileCalc,wt as hiddenItemFlags,ut as itemKey,ee as partsToSerial,pt as serialToParts,Ye as showAsNeedsBaseField,Xe as showAsNeedsBaseItem,Ht as storeColumn,xt as valueFieldName};
|
package/pivot/xml.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{pivotCfNode as $e,pivotChartFormatsNode as _e}from"../slicers/pivot-file.js";import{dateFilterNodes as qe,isDateFilterType as He,parseDateFilter as Ve}from"../slicers/date-filters.js";import{MAX_COLS as Ge,parseRangeRef as de,rangeRef as fe}from"../core/address.js";import{BUILTIN_FORMATS as K,partsToSerial as Xe,serialToParts as je}from"../core/numfmt.js";import{BOOL as Ue,EMPTY as We,ERR as Ke,ERRORS as Ye,NUM as pe,STR as Je}from"../core/sheet.js";import{decodeRange as L,unescapeXml as Qe,unescapeXstring as he,XmlScanner as me}from"../io/xml-scan.js";import{escapeMarkup as Y,xmlAttr as ge}from"../io/xml-escape.js";import{relsPathOf as Ze,resolveTarget as ze}from"../io/package-paths.js";import{ERR_BY_CODE as we,ERR_BY_INDEX as be,XlError as et}from"../calc/values.js";import{applyNumFmt as J,itemKey as $,LINE as j,PivotCache as tt,PivotField as nt,PivotTable as st,storeColumn as at,VALUES as Q,compileCalc as ot,valueFieldName as rt}from"./engine.js";const Z="http://schemas.openxmlformats.org/spreadsheetml/2006/main",V="http://schemas.openxmlformats.org/officeDocument/2006/relationships",z="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",it="{E15A36E0-9728-4e99-A89B-3F7291B0FE68}",lt="{962EF5D1-5CA2-4c93-8EF4-DBF5C05439D2}",ct="{2946ED86-A175-432a-8AC1-64E0C546D7DE}",ee={table:"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",definition:"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml",records:"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml"},_={table:`${V}/pivotTable`,definition:`${V}/pivotCacheDefinition`,records:`${V}/pivotCacheRecords`},xe=1048828,ye=1048829,ve=4294967294,ut=new Set(["percentOfParent","percentOfParentRow","percentOfParentCol","percentOfRunningTotal","rankAscending","rankDescending"]),te={sum:"sumSubtotal",count:"countASubtotal",average:"avgSubtotal",max:"maxSubtotal",min:"minSubtotal",product:"productSubtotal",countNums:"countSubtotal",stdDev:"stdDevSubtotal",stdDevp:"stdDevPSubtotal",var:"varSubtotal",varp:"varPSubtotal"},Fe={sum:"sum",count:"countA",average:"avg",max:"max",min:"min",product:"product",countNums:"count",stdDev:"stdDev",stdDevp:"stdDevP",var:"var",varp:"varP"},m=(t,e={},s=[])=>({n:t,a:e,c:s,t:""}),b=(t,e)=>t?.c.find(s=>s.n===e)??null,A=(t,e)=>t?t.c.filter(s=>s.n===e):[],T=(t,e)=>t===void 0?e:t==="1"||t==="true";function Se(t,e,s){const a={};let n=e;for(;n<s;){for(;n<s&&t[n]<=32;)n++;if(n>=s)break;const l=n;for(;n<s&&t[n]!==61&&t[n]>32;)n++;const o=n;for(;n<s&&t[n]!==34&&t[n]!==39;)n++;if(n>=s)break;const c=t[n++],r=n,i=t.indexOf(c,n),u=i<0||i>s?s:i;a[L(t,l,o)]=he(L(t,r,u)),n=u+1}return a}function dt(t,e,s){let a=e;for(;a>0&&t[a-1]!==60;)a--;return L(t,a,s)}function ne(t,e=[]){e.push("<",t.n);for(const s of Object.keys(t.a)){const a=t.a[s];a!=null&&e.push(" ",s,'="',ge(a),'"')}if(t.c.length===0&&t.t==="")return e.push("/>"),e;e.push(">"),t.t&&e.push(Y(t.t));for(const s of t.c)typeof s=="string"?e.push(s):ne(s,e);return e.push("</",t.n,">"),e}const ft=new Set(["s","n","d","b","e","m"]);function Te(t,e){switch(t){case"n":return Number(e.v);case"s":return e.v??"";case"d":return U(e.v);case"b":return e.v==="1"||e.v==="true";case"e":return we.get(e.v)??be[6];default:return null}}class Ie{constructor(){this.root=m("#root"),this.stack=[this.root],this.shared=null,this.sharedDepth=0,this.scanner=new me(this)}feed(e){this.scanner.feed(e)}finish(){return this.root.c[0]??null}open(e,s,a,n,l,o){const c=this.stack[this.stack.length-1];if(this.shared!==null&&c===this.shared){const i=L(e,s,a);if(ft.has(i)){const u=Se(e,n,l);c.items.push(Te(i,u)),o||this.sharedDepth++;return}}if(this.sharedDepth>0){o||this.sharedDepth++;return}const r=m(dt(e,s,a),Se(e,n,l));r.n==="sharedItems"&&(r.items=[],this.shared=r),c.c.push(r),o?r.n==="sharedItems"&&(this.shared=null):this.stack.push(r)}close(){if(this.sharedDepth>0){this.sharedDepth--;return}this.stack.pop()===this.shared&&(this.shared=null),this.stack.length===0&&this.stack.push(this.root)}text(e,s,a){if(this.sharedDepth>0)return;let n=!0;for(let l=s;l<a;l++)if(e[l]>32){n=!1;break}n||(this.stack[this.stack.length-1].t+=Qe(L(e,s,a)))}}function Ne(t){const e=new Ie;return e.feed(typeof t=="string"?new TextEncoder().encode(t):t),e.finish()}async function Ce(t,e){if(t instanceof Uint8Array)e.feed(t);else if(t.getReader){const s=t.getReader();for(;;){const{done:a,value:n}=await s.read();if(a)break;e.feed(n)}}else for await(const s of t)e.feed(s);return e.finish()}function U(t){const e=/^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}):(\d{2})(\.\d+)?)?/.exec(t??"");if(!e)return 0;const s=Xe(Number(e[1]),Number(e[2]),Number(e[3]));return e[4]===void 0?s:s+(Number(e[4])*3600+Number(e[5])*60+Number(e[6])+Number(e[7]??0))/86400}const q=(t,e=2)=>String(t).padStart(e,"0");function H(t){const e=je(t),s=Math.floor(e.ms/1e3);return`${q(e.year,4)}-${q(e.month)}-${q(e.day)}T${q(Math.floor(s/3600))}:${q(Math.floor(s/60)%60)}:${q(s%60)}`}class pt{constructor(e){this.positions=e.fields.filter(a=>a.a.databaseField===void 0||T(a.a.databaseField,!0));const s=e.c?Number(e.a.recordCount??1024):1024;this.capacity=Math.max(s,16),this.count=0,this.columns=this.positions.map(()=>({ids:null,kinds:null,nums:null})),this.pool=new Map,this.strings=[],this.at=-1,this.scanner=new me(this),this.inRecord=!1}feed(e){this.scanner.feed(e)}_grow(){this.capacity*=2;const e=(s,a)=>{if(a===null)return null;const n=new s(this.capacity);return n.set(a),n};for(const s of this.columns)s.ids=e(Int32Array,s.ids),s.kinds=e(Uint8Array,s.kinds),s.nums=e(Float64Array,s.nums)}open(e,s,a,n,l){if(a-s!==1)return;const o=e[s];if(o===114){this.count===this.capacity&&this._grow(),this.count++,this.at=0;return}if(this.at<0)return;const c=this.at++,r=this.columns[c];if(r===void 0)return;const i=this.count-1;if(o===120){r.ids===null&&(r.ids=new Int32Array(this.capacity));let d=0,h=Ee(e,n,l);if(h>=0)for(;h<l;h++){const g=e[h]-48;if(g<0||g>9)break;d=d*10+g}r.ids[i]=d;return}if(r.kinds===null&&(r.kinds=new Uint8Array(this.capacity),r.nums=new Float64Array(this.capacity)),o===109)return;const u=Ee(e,n,l);if(u<0)return;let p=u;const f=e[u-1];for(;p<l&&e[p]!==f;)p++;switch(o){case 110:r.kinds[i]=pe,r.nums[i]=Number(L(e,u,p));break;case 115:{const d=he(L(e,u,p));let h=this.pool.get(d);h===void 0&&(h=this.strings.length,this.strings.push(d),this.pool.set(d,h)),r.kinds[i]=Je,r.nums[i]=h;break}case 100:r.kinds[i]=pe,r.nums[i]=U(L(e,u,p)),r.dates=!0;break;case 98:r.kinds[i]=Ue,r.nums[i]=e[u]===49||e[u]===116?1:0;break;case 101:{const d=we.get(L(e,u,p));r.kinds[i]=Ke,r.nums[i]=d?d.index:6;break}default:}}close(e,s,a){a-s===1&&e[s]===114&&(this.at=-1)}text(){}finish(){return this}}function Ee(t,e,s){for(let a=e;a<s-2;a++)if(t[a]===118&&t[a+1]===61&&t[a-1]<=32)return a+3;return-1}async function ht(t){const e=await Ce(t,new Ie),s=b(e,"cacheFields");return{root:e,fields:s?A(s,"cacheField"):[],a:e.a,c:e.c}}async function mt(t,e){return Ce(t,new pt(e))}function Re(t){const e=b(t,"groupItems");return e?e.c.map(s=>Te(s.n,s.a)):[]}function gt(t,e){const s=Number(t.numFmtId??0);return K[s]??e?.(s)??"General"}function wt(t,e,{numFmtOf:s}={}){const a=new tt,{fields:n}=t;a.xml={root:t.root},a.needsRefresh=e==null;const l=e?e.count:0;a.recordCount=l,e&&(a.strings.list=e.strings,a.strings.index=e.pool);let o=0;n.forEach((c,r)=>{const i=new nt(a,r,c.a.name??`Field${r+1}`);i.xml={node:c},J(i,gt(c.a,s));const u=b(c,"sharedItems"),p=u?.items??[],f=c.a.databaseField===void 0||T(c.a.databaseField,!0);if(u&&T(u.a.containsDate,!1)&&i.numFmt==="General"&&J(i,"m/d/yyyy"),c.a.formula!==void 0)i.formula=c.a.formula;else if(f&&e){const d=e.columns[o];d?.ids?(i.rawIds=d.ids.subarray(0,l),i.shared=p.slice()):d?.kinds&&(at(i,d.kinds.subarray(0,l),d.nums.subarray(0,l),l),d.dates&&i.numFmt==="General"&&J(i,"m/d/yyyy"))}else f&&(i.shared=p.slice(),i.rawIds=new Int32Array(0));f&&o++,a.fields.push(i)}),n.forEach((c,r)=>{const i=b(c,"fieldGroup");if(!i)return;const u=a.fields[r],p=i.a.base!==void 0?Number(i.a.base):r;i.a.par!==void 0&&(u.par=Number(i.a.par)),p!==r&&(u.base=p);const f=b(i,"rangePr"),d=b(i,"discretePr"),h=Re(i);if(f){const g=f.a.groupBy??"range",w=T(f.a.autoStart,!0),x=T(f.a.autoEnd,!0);if(g==="range"){const v=Number(f.a.startNum??0),y=Number(f.a.endNum??0),F=Number(f.a.groupInterval??1),S=h.length>1&&/^-?\d+--?\d+$/.test(String(h[1]))&&Number.isInteger(v)&&Number.isInteger(F)&&Number(String(h[1]).match(/^-?\d+-(-?\d+)$/)?.[1])===v+F-1;u.group={kind:"bins",start:v,end:y,interval:F,integer:S,autoStart:w,autoEnd:x,labels:h}}else u.group={kind:"date",part:g,start:Math.floor(U(f.a.startDate)),end:Math.floor(U(f.a.endDate))-1,autoStart:w,autoEnd:x,labels:h}}else if(d&&p!==r){const g=a.fields[p],w=A(d,"x").map(F=>Number(F.a.v??0)),x=h.map(()=>[]),v=b(n[p],"sharedItems")?.items??g.shared??[];w.forEach((F,S)=>{x[F]&&x[F].push($(v[S]??null))});const y=[];h.forEach((F,S)=>{x[S].length===1&&x[S][0]===$(F)||y.push({name:String(F),keys:x[S]})}),u.group={kind:"discrete",groups:y}}});for(const c of a.fields)if(c.formula!==null)try{c.calc=ot(c.formula,a)}catch{c.calc={fn:()=>{throw be[4]},refs:[]}}return a}function se(t,e){const s=t.fields[e].xml?.node,a=s?b(s,"fieldGroup"):null,n=a?Re(a):[];return n.length>0?n:(s?b(s,"sharedItems"):null)?.items??[]}function bt(t){const e=t.a.type??"",s=b(b(t,"autoFilter"),"filterColumn");if(e==="count"||e==="percent"||e==="sum"){const a=b(s,"top10");return a?{top:{count:Number(a.a.val??10),by:e==="count"?"items":e,bottom:a.a.top==="0"||a.a.top==="false",data:Number(t.a.iMeasureFld??0)}}:null}if(He(e))return{dateFilter:Ve(t)};if(e.startsWith("caption"))return{labelFilter:{op:e,value:t.a.stringValue1??"",value2:t.a.stringValue2??""}};if(e.startsWith("value")){const a=A(b(s,"customFilters"),"customFilter");return a.length===0?null:{valueFilter:{op:e,data:Number(t.a.iMeasureFld??0),value:Number(a[0].a.val),value2:a[1]?Number(a[1].a.val):void 0}}}return null}function xt(t){for(const e of A(b(t,"extLst"),"ext")){const s=b(e,"x14:pivotTableDefinition");if(s)return s}return null}function yt(t,e){const s=t?b(t,"extLst"):null,a=[];let n=!1;for(const l of s?.c??[]){const o=b(l,"x14:pivotTableDefinition");if(!o){a.push(l);continue}n=!0;const c={...o.a};delete c.hideValuesRow,e&&(c.hideValuesRow="1"),a.push(m("ext",l.a,l.c.map(r=>r===o?m(o.n,c,o.c):r)))}return!n&&e&&a.push(m("ext",{uri:lt,"xmlns:x14":z},[m("x14:pivotTableDefinition",{hideValuesRow:"1"})])),a.length>0?m("extLst",{},a):null}function vt(t,e,{numFmtOf:s,sheet:a}={}){const n={name:t.a.name??"PivotTable1",fieldOptions:{},rows:A(b(t,"rowFields"),"field").map(d=>Number(d.a.x)),cols:A(b(t,"colFields"),"field").map(d=>Number(d.a.x)),filters:[],values:[],grandRow:T(t.a.colGrandTotals,!0),grandCol:T(t.a.rowGrandTotals,!0),rowCaption:t.a.rowHeaderCaption??null,colCaption:t.a.colHeaderCaption??null,dataCaption:t.a.dataCaption??"Values",grandCaption:t.a.grandTotalCaption??null,emptyText:T(t.a.showMissing,!0)?t.a.missingCaption??"":"",showMissing:T(t.a.showMissing,!0),errorText:T(t.a.showError,!1)?t.a.errorCaption??"":null,showExpandButtons:T(t.a.showDrill,!0),showFieldHeaders:T(t.a.showHeaders,!0),hideValuesRow:T(xt(t)?.a.hideValuesRow,!1)},l=A(b(t,"pivotFields"),"pivotField"),o={root:t,fields:l,itemAttrs:[],pageFields:new Map,rawFilters:[]},c=[];l.forEach((d,h)=>{const g={},w=se(e,h),x=A(b(d,"items"),"item"),v=[],y=[],F=[],S={},C=new Map;for(const N of x){if(N.a.t!==void 0&&N.a.t!=="data")continue;const R=Number(N.a.x??0),k=$(w[R]??null);F.push(k),C.set(k,N.a),T(N.a.h,!1)&&v.push(k),N.a.sd!==void 0&&!T(N.a.sd,!0)&&y.push(k),N.a.n!==void 0&&(S[k]=N.a.n)}o.itemAttrs[h]=C,v.length&&(g.hidden=v),y.length&&(g.collapsedItems=y),Object.keys(S).length&&(g.itemCaptions=S),d.a.name!==void 0&&(g.caption=d.a.name);const D=d.a.sortType??"manual";if(D==="ascending"||D==="descending"){g.sort={order:D==="ascending"?"asc":"desc"};const N=b(b(d,"autoSortScope"),"pivotArea"),R=b(b(N,"references"),"reference");R&&Number(R.a.field)===ve&&(g.sort.data=Number(b(R,"x")?.a.v??0))}else F.length>0&&d.a.axis&&(g.sort={order:"manual",keys:F});const B=Object.entries(te).filter(([,N])=>T(d.a[N],!1)).map(([N])=>N);B.length>0?g.subtotals=B:T(d.a.defaultSubtotal,!0)||(g.subtotals="none"),d.a.subtotalTop!==void 0&&(g.subtotalTop=T(d.a.subtotalTop,!0)),T(d.a.insertBlankRow,!1)&&(g.blankLine=!0),d.a.axis&&T(d.a.showAll,!0)&&(g.showAll=!0),T(d.a.insertPageBreak,!1)&&(g.pageBreak=!0);for(const N of A(b(d,"extLst"),"ext"))T(b(N,"x14:pivotField")?.a.fillDownLabels,!1)&&(g.repeatLabels=!0);if(d.a.axis==="axisRow"||d.a.axis==="axisCol"){const N=T(d.a.compact,!0)?"compact":T(d.a.outline,!0)?"outline":"tabular";c.push([h,N])}Object.keys(g).length>0&&(n.fieldOptions[h]=g)});const r=new Map;for(const[,d]of c)r.set(d,(r.get(d)??0)+1);n.layout=[...r.entries()].sort((d,h)=>h[1]-d[1])[0]?.[0]??"compact";for(const[d,h]of c)h!==n.layout&&(n.fieldOptions[d]??={},n.fieldOptions[d].layout=h);for(const d of A(b(t,"pageFields"),"pageField")){const h=Number(d.a.fld);if(n.filters.push(h),o.pageFields.set(h,d.a),d.a.item!==void 0){const g=A(b(l[h],"items"),"item"),w=g[Number(d.a.item)],x=se(e,h);if(w){const v=$(x[Number(w.a.x??0)]??null),y=[];for(const F of g){if(F.a.t!==void 0&&F.a.t!=="data")continue;const S=$(x[Number(F.a.x??0)]??null);S!==v&&y.push(S)}n.fieldOptions[h]??={},n.fieldOptions[h].hidden=y}}}for(const d of A(b(t,"dataFields"),"dataField")){const h=Number(d.a.fld),g={field:h,name:d.a.name??rt(d.a.subtotal??"sum",e.fields[h].name),agg:d.a.subtotal??"sum",xml:d};let w=d.a.showDataAs??"normal";const x=b(b(d,"extLst"),"ext"),v=x?b(x,"x14:dataField"):null;if(v?.a.pivotShowAs&&(w=v.a.pivotShowAs),w!=="normal"&&(g.showAs={type:w},d.a.baseField!==void 0&&(g.showAs.baseField=Number(d.a.baseField)),d.a.baseItem!==void 0)){const y=Number(d.a.baseItem);if(y===xe)g.showAs.baseItem="prev";else if(y===ye)g.showAs.baseItem="next";else{const F=g.showAs.baseField,S=A(b(l[F],"items"),"item"),C=se(e,F),D=S[y];g.showAs.baseItem=D?$(C[Number(D.a.x??0)]??null):"prev"}}if(d.a.numFmtId!==void 0){const y=Number(d.a.numFmtId),F=K[y]??s?.(y);F&&(g.numFmt=F)}n.values.push(g)}for(const d of A(b(t,"filters"),"filter")){const h=bt(d),g=Number(d.a.fld);if(h===null){o.rawFilters.push(d);continue}n.fieldOptions[g]??={},Object.assign(n.fieldOptions[g],h)}T(t.a.mergeItem,!1)&&(n.mergeLabels=!0);const i=b(t,"pivotTableStyleInfo");i&&(n.style={name:i.a.name??"PivotStyleLight16",rowHeaders:T(i.a.showRowHeaders,!0),colHeaders:T(i.a.showColHeaders,!0),rowStripes:T(i.a.showRowStripes,!1),colStripes:T(i.a.showColStripes,!1),lastColumn:T(i.a.showLastColumn,!0)});const u=new st(e,n);u.xml=o,u.dirty=!1;const p=b(t,"location"),f=p?de(p.a.ref??""):null;if(f){const d=n.filters.length>0?n.filters.length+1:0;u.anchor={sheet:a??null,row:Math.max(0,f.r0-d),col:f.c0},u.renderedRange={r0:u.anchor.row,c0:f.c0,r1:f.r1,c1:f.c1}}return u}async function ae(t,e){const s=Ze(e);if(!t.has(s))return[];const a=Ne(await t.bytes(s));return A(a,"Relationship").map(n=>({id:n.a.Id,type:n.a.Type,target:ze(e,n.a.Target??"")}))}async function zt(t,{sheets:e,book:s,tables:a=[],numFmtOf:n,readRecords:l=!0}){const o=new Map,c=[];for(const{part:r,sheet:i}of e)for(const u of await ae(t,r)){if(u.type!==_.table||!t.has(u.target))continue;const p=Ne(await t.bytes(u.target)),d=(await ae(t,u.target)).find(w=>w.type===_.definition);if(!d||!t.has(d.target))continue;let h=o.get(d.target);if(h===void 0){const w=await ht(await t.stream(d.target)),v=(await ae(t,d.target)).find(F=>F.type===_.records);let y=null;l&&v&&t.has(v.target)&&(y=await mt(await t.stream(v.target),w)),h=wt(w,y,{numFmtOf:n}),h.part=d.target,h.id=p.a.cacheId!==void 0?Number(p.a.cacheId):0,Ft(h,w,s,a),o.set(d.target,h)}const g=vt(p,h,{numFmtOf:n,sheet:i});g.part=u.target,c.push(g)}return{caches:[...o.values()],pivots:c}}function Ft(t,e,s,a){if(!s)return;const n=b(b(e.root,"cacheSource"),"worksheetSource");if(!n)return;if(n.a.name!==void 0){const c=a.find(r=>r.name?.toLowerCase()===n.a.name.toLowerCase());c&&(t.source={type:"table",book:s,table:c});return}const l=de(n.a.ref??""),o=s.sheets.find(c=>c.name===n.a.sheet);l&&o&&(t.source={type:"range",book:s,sheet:o,range:l})}const W=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
+
`,oe=new TextEncoder;function ke(t){for(const[e,s]of Object.entries(K))if(s===t)return Number(e);return null}function re(t,e){if(t==null)return"<m/>";switch(typeof t){case"number":return e?`<d v="${H(t)}"/>`:`<n v="${t}"/>`;case"string":return`<s v="${ge(t)}"/>`;case"boolean":return`<b v="${t?1:0}"/>`;default:return`<e v="${Y(t.code)}"/>`}}function Ae(t,e){const{hasNum:s,hasInt:a,hasText:n,hasBlank:l,hasOther:o,min:c,max:r,longText:i}=e,u=t.isDate&&s&&!n&&!o,p={};return!n&&!l&&!o&&(p.containsSemiMixedTypes="0"),u&&!l&&(p.containsNonDate="0"),u&&(p.containsDate="1"),n||(p.containsString="0"),l&&(p.containsBlank="1"),(s?1:0)+(n?1:0)+(o?1:0)>1&&(p.containsMixedTypes="1"),s&&!u&&(p.containsNumber="1",a&&(p.containsInteger="1"),p.minValue=String(c),p.maxValue=String(r)),u&&(p.minDate=H(c),p.maxDate=H(Math.floor(r)+1)),i&&(p.longText="1"),{attrs:p,date:u}}function St(t){const e={hasNum:!1,hasInt:!0,hasText:!1,hasBlank:!1,hasOther:!1,min:1/0,max:-1/0,longText:!1};for(const s of t)typeof s=="number"?(e.hasNum=!0,Number.isInteger(s)||(e.hasInt=!1),s<e.min&&(e.min=s),s>e.max&&(e.max=s)):typeof s=="string"?(e.hasText=!0,s.length>255&&(e.longText=!0)):s==null?e.hasBlank=!0:e.hasOther=!0;return e}function Tt(t){const e={hasNum:t.length>0,hasInt:!0,hasText:!1,hasBlank:!1,hasOther:!1,min:1/0,max:-1/0,longText:!1};for(let s=0;s<t.length;s++){const a=t[s];a<e.min&&(e.min=a),a>e.max&&(e.max=a),e.hasInt&&Math.floor(a)!==a&&(e.hasInt=!1)}return e}function De(t){return t.ensureColumn(),t.rawIds!==null?!0:!(t.nums!==null&&t.kinds===null)}function It(t,e){const s=e.group;if(s===null)return e.par>=0?m("fieldGroup",{par:String(e.par)}):null;e.ensure();const a={};e.par>=0&&(a.par=String(e.par)),a.base=String(e.base>=0?e.base:e.index);const n=[],l=e.items.map(c=>re(c,!1)).join("");if(s.kind==="date"){const c={groupBy:s.part,startDate:H(s.start),endDate:H(s.end+1)};s.autoStart||(c.autoStart="0"),s.autoEnd||(c.autoEnd="0"),n.push(m("rangePr",c))}else if(s.kind==="bins"){const c={startNum:String(s.start),endNum:String(s.end),groupInterval:String(s.interval)};s.autoStart||(c.autoStart="0"),s.autoEnd||(c.autoEnd="0"),n.push(m("rangePr",c))}else{const c=e.groupMap,r=m("discretePr",{count:String(c.length)});for(let i=0;i<c.length;i++)r.c.push(m("x",{v:String(c[i])}));n.push(r)}const o=m("groupItems",{count:String(e.items.length)});return o.c.push(l),n.push(o),m("fieldGroup",a,n)}function Nt(t,e,s){const a=e.xml?.node??null,n={...a?.a??{}};if(n.name=e.name,n.numFmtId===void 0){const c=e.numFmt!=="General"?ke(e.numFmt)??s.numFmtId?.(e.numFmt)??(e.isDate?14:0):0;n.numFmtId=String(c)}const l=[];if(e.isCalculated)n.formula=e.formula,n.databaseField="0",delete n.uniqueList;else if(e.base>=0)n.databaseField="0";else if(t.recordCount===0&&a&&b(a,"sharedItems")){const c=b(a,"sharedItems"),r=m("sharedItems",{...c.a}),i=T(c.a.containsDate,!1);c.items.length>0&&r.c.push(c.items.map(u=>re(u,i&&typeof u=="number")).join("")),l.push(r)}else if(De(e)){e.ensureRaw();const{attrs:c,date:r}=Ae(e,St(e.shared)),i=m("sharedItems",{...c,count:String(e.shared.length)});i.c.push(e.shared.map(u=>re(u,r&&typeof u=="number")).join("")),l.push(i)}else{const{attrs:c}=Ae(e,Tt(e.nums));l.push(m("sharedItems",c))}const o=It(t,e);if(o&&l.push(o),a)for(const c of a.c)c.n!=="sharedItems"&&c.n!=="fieldGroup"&&l.push(c);return m("cacheField",n,l)}function Ct(t,{recordsRel:e=null,numFmtId:s,refreshOnLoad:a=!0,sourceSheetName:n}={}){const l=t.xml?.root??null,o={...l?.a??{}};o.xmlns??=Z,o["xmlns:r"]??=V,e?o["r:id"]=e:delete o["r:id"],a&&(o.refreshOnLoad="1"),o.refreshedBy??="8sheets",o.refreshedDate=String(Et()),o.createdVersion??="6",o.refreshedVersion??="6",o.minRefreshableVersion??="3",o.recordCount=String(t.recordCount),e?delete o.saveData:o.saveData="0";const c=[],r=l?b(l,"cacheSource"):null;c.push(Rt(t,r,n));const i=m("cacheFields",{count:"0"}),u=t.fields;for(const p of u)i.c.push(Nt(t,p,{numFmtId:s}));if(i.a.count=String(u.length),c.push(i),l)for(const p of l.c)p.n!=="cacheSource"&&p.n!=="cacheFields"&&c.push(p);return W+ne(m("pivotCacheDefinition",o,c)).join("")}function Et(){return Math.round((Date.now()/864e5+25569)*1e5)/1e5}function Rt(t,e,s){const a=t.source;if(a===null)return e??m("cacheSource",{type:"worksheet"},[m("worksheetSource",{ref:"A1",sheet:"Sheet1"})]);const n={};if(a.type==="table")n.name=a.table.name;else{const i=a.range,u=s??(typeof a.sheet=="string"?a.sheet:a.sheet.name);n.ref=fe({r0:i.r0,c0:i.c0,r1:i.r1,c1:Math.min(i.c1,Ge-1)}),n.sheet=u}const l=e?{...e.a}:{type:"worksheet"},o=e?e.c.filter(i=>i.n!=="worksheetSource"):[],c=e?b(e,"worksheetSource"):null,r=c?{...c.a,...n}:n;return a.type==="table"&&(delete r.ref,delete r.sheet),m("cacheSource",l,[m("worksheetSource",r),...o])}const kt=4096;async function Oe(t,e){const s=t.recordCount,a=[];for(const l of t.fields)l.isVirtual||(De(l)?(l.ensureRaw(),a.push(At(l.rawIds))):a.push(Dt(l.nums,l.isDate)));await e(oe.encode(`${W}<pivotCacheRecords xmlns="${Z}" xmlns:r="${V}" count="${s}">`));const n=[];for(let l=0;l<s;l++){n.push("<r>");for(let o=0;o<a.length;o++)n.push(a[o](l));n.push("</r>"),(l+1)%kt===0&&(await e(oe.encode(n.join(""))),n.length=0)}n.push("</pivotCacheRecords>"),await e(oe.encode(n.join("")))}function At(t){return e=>`<x v="${t[e]}"/>`}function Dt(t,e){return e?s=>`<d v="${H(t[s])}"/>`:s=>`<n v="${t[s]}"/>`}async function en(t){const e="application/xml";let s=new Blob([],{type:e}),a=[],n=0;return await Oe(t,l=>{a.push(l),n+=l.length,n>=1<<24&&(s=new Blob([s,...a],{type:e}),a=[],n=0)}),new Blob([s,...a],{type:e})}const Le=["location","pivotFields","rowFields","rowItems","colFields","colItems","pageFields","dataFields","formats","conditionalFormats","chartFormats","pivotHierarchies","pivotTableStyleInfo","filters","rowHierarchiesUsage","colHierarchiesUsage","extLst"];function Ot(t,e){const s=t.cache.fields[e].ensure(),a=s.rank(),n=Array.from(s.items.keys()),o=t.spec.fieldOptions[e]?.sort;if(o?.order==="manual"){const r=new Map((o.keys??[]).map((p,f)=>[p,f])),i=r.size,u=p=>r.get($(s.items[p]))??i+a[p];n.sort((p,f)=>u(p)-u(f))}else o?.order==="desc"&&(o.data===void 0||o.data===null)?n.sort((r,i)=>a[i]-a[r]):n.sort((r,i)=>a[r]-a[i]);const c=new Int32Array(n.length);return n.forEach((r,i)=>{c[r]=i}),{order:n,position:c}}function Lt(t){return t.group!==null||t.base>=0}function Pt(t,e){return t.spec.fieldOptions[e]?.layout??t.spec.layout}const Bt=["axis","dataField","compact","outline","subtotalTop","sortType","defaultSubtotal","insertBlankRow","name","showDropDowns","dragToRow","dragToCol","dragToPage",...Object.values(te)];function Mt(t,e,s){const{spec:a,cache:n}=t,l=n.fields[e],o=a.fieldOptions[e]??{},c=t.xml?.fields?.[e]??null,r={...c?.a??{}};for(const S of Bt)delete r[S];o.caption!==void 0&&(r.name=o.caption);const i=a.rows.includes(e),u=a.cols.includes(e),p=a.filters.includes(e),f=a.values.some(S=>S.field===e);i?r.axis="axisRow":u?r.axis="axisCol":p&&(r.axis="axisPage"),f&&(r.dataField="1");const d=Pt(t,e);d!=="compact"&&(r.compact="0"),d==="tabular"&&(r.outline="0"),l.isCalculated&&(r.dragToRow="0",r.dragToCol="0",r.dragToPage="0"),r.showAll=o.showAll?"1":"0",o.pageBreak?r.insertPageBreak="1":delete r.insertPageBreak,(o.subtotalTop??a.subtotalTop)===!1&&(i||u)&&(r.subtotalTop="0"),o.blankLine&&(r.insertBlankRow="1"),o.sort?.order==="asc"?r.sortType="ascending":o.sort?.order==="desc"&&(r.sortType="descending");const h=o.subtotals??"auto",g=i||u||p,w=(o.hidden?.length??0)>0,x=g||Lt(l)||w||!!(o.range||o.dateFilter);if((l.isCalculated||h==="none"||Array.isArray(h)||l.base>=0&&!g)&&(r.defaultSubtotal="0"),Array.isArray(h))for(const S of h)r[te[S]]="1";const v=[];if(x&&!l.isCalculated){const{order:S}=s(e),C=m("items",{}),D=new Set(o.hidden??[]),B=new Set(o.collapsedItems??[]),N=t.xml?.itemAttrs?.[e]??null,R=o.itemCaptions??null;for(const k of S){const P=l.keyOf(k),O={...N?.get(P)??{}};delete O.h,delete O.sd,delete O.n,O.x=String(k),D.has(P)&&(O.h="1"),B.has(P)&&(O.sd="0"),R&&R[P]!==void 0&&(O.n=R[P]),C.c.push(m("item",O))}if((g||w||o.range||o.dateFilter)&&r.defaultSubtotal===void 0&&C.c.push(m("item",{t:"default"})),Array.isArray(h))for(const k of h)C.c.push(m("item",{t:Fe[k]}));C.a.count=String(C.c.length),v.push(C)}if(o.sort?.data!==void 0&&o.sort?.data!==null&&(o.sort.order==="asc"||o.sort.order==="desc")&&v.push(m("autoSortScope",{},[m("pivotArea",{dataOnly:"0",outline:"0",fieldPosition:"0"},[m("references",{count:"1"},[m("reference",{field:String(ve),count:"1",selected:"0"},[m("x",{v:String(o.sort.data)})])])])])),c)for(const S of c.c)S.n!=="items"&&S.n!=="autoSortScope"&&S.n!=="extLst"&&v.push(S);const y=o.repeatLabels===!0||a.repeatLabels===!0&&i&&d!=="compact",F=$t(c,y);return F&&v.push(F),m("pivotField",r,v)}function $t(t,e){const s=[];let a=!1;for(const n of A(t?b(t,"extLst"):null,"ext")){const l=b(n,"x14:pivotField");if(!l){s.push(n);continue}a=!0;const o={...l.a};delete o.fillDownLabels,e&&(o.fillDownLabels="1"),s.push(m("ext",n.a,n.c.map(c=>c===l?m(l.n,o,l.c):c)))}return!a&&e&&s.push(m("ext",{uri:ct,"xmlns:x14":z},[m("x14:pivotField",{fillDownLabels:"1"})])),s.length>0?m("extLst",{},s):null}function Pe(t,e,s,a){const n=s.lines,l=m(t,{}),{slots:o}=s;let c=[];for(let r=0;r<n.node.length;r++){const i=n.type[r],u=n.level[r],p={},f=[];if(o.length===0){l.c.push(m("i",{}));continue}if(i===j.GRAND){p.t="grand";const w=n.data[r];w>0&&(p.i=String(w));const x=m("i",p,[m("x",w>0?{v:String(w)}:{})]);l.c.push(x),c=[];continue}i===j.BLANK?p.t="blank":i===j.SUBTOTAL&&(p.t=n.func[r]?Fe[n.func[r]]:"default");let d=0;for(let w=0;w<=u;w++)if(o[w]===Q)f.push(n.data[r]>=0?n.data[r]:0);else{d++;const x=s.ancestorAt(n.node[r],d);f.push(a(o[w]).position[s.item[x]])}n.data[r]>0&&(p.i=String(n.data[r]));let h=0;if(i===j.ITEM)for(;h<f.length-1&&h<c.length&&c[h]===f[h];)h++;h>0&&(p.r=String(h));const g=m("i",p);for(let w=h;w<f.length;w++)g.c.push(m("x",f[w]===0?{}:{v:String(f[w])}));l.c.push(g),c=f}return l.c.length===0&&l.c.push(m("i",{})),l.a.count=String(l.c.length),l}function _t(t,e){const{spec:s}=t,a=[];let n=1;const l=(c,r,i,u)=>m("filter",{fld:String(c),type:r,evalOrder:"-1",id:String(n++),...i},[m("autoFilter",{ref:"A1"},[m("filterColumn",{colId:"0"},[u])])]),o=(c,r)=>m("customFilters",r?{and:"1"}:{},c.map(i=>m("customFilter",i)));for(const c of e){const r=s.fieldOptions[c];if(r){if(r.labelFilter){const i=r.labelFilter,u=String(i.value??""),p=String(i.value2??""),f={stringValue1:u};(i.op==="captionBetween"||i.op==="captionNotBetween")&&(f.stringValue2=p);const d={captionEqual:()=>o([{val:u}]),captionNotEqual:()=>o([{operator:"notEqual",val:u}]),captionBeginsWith:()=>o([{val:`${u}*`}]),captionNotBeginsWith:()=>o([{operator:"notEqual",val:`${u}*`}]),captionEndsWith:()=>o([{val:`*${u}`}]),captionNotEndsWith:()=>o([{operator:"notEqual",val:`*${u}`}]),captionContains:()=>o([{val:`*${u}*`}]),captionNotContains:()=>o([{operator:"notEqual",val:`*${u}*`}]),captionGreaterThan:()=>o([{operator:"greaterThan",val:u}]),captionGreaterThanOrEqual:()=>o([{operator:"greaterThanOrEqual",val:u}]),captionLessThan:()=>o([{operator:"lessThan",val:u}]),captionLessThanOrEqual:()=>o([{operator:"lessThanOrEqual",val:u}]),captionBetween:()=>o([{operator:"greaterThanOrEqual",val:u},{operator:"lessThanOrEqual",val:p}],!0),captionNotBetween:()=>o([{operator:"lessThan",val:u},{operator:"greaterThan",val:p}])}[i.op];d&&a.push(l(c,i.op,f,d()))}if(r.valueFilter){const i=r.valueFilter,u=String(i.value),p=String(i.value2??""),f={valueEqual:[[{val:u}]],valueNotEqual:[[{operator:"notEqual",val:u}]],valueGreaterThan:[[{operator:"greaterThan",val:u}]],valueGreaterThanOrEqual:[[{operator:"greaterThanOrEqual",val:u}]],valueLessThan:[[{operator:"lessThan",val:u}]],valueLessThanOrEqual:[[{operator:"lessThanOrEqual",val:u}]],valueBetween:[[{operator:"greaterThanOrEqual",val:u},{operator:"lessThanOrEqual",val:p}],!0],valueNotBetween:[[{operator:"lessThan",val:u},{operator:"greaterThan",val:p}]]}[i.op];f&&a.push(l(c,i.op,{iMeasureFld:String(i.data??0)},o(f[0],f[1]===!0)))}if(a.push(...qe(r,c,m,()=>n++)),r.top){const i=r.top,u={val:String(i.count??10),filterVal:String(i.count??10)};i.by==="percent"&&(u.percent="1"),i.bottom&&(u.top="0");const p=i.by==="percent"?"percent":i.by==="sum"?"sum":"count";a.push(l(c,p,{iMeasureFld:String(i.data??0)},m("top10",u)))}}}return a}function qt(t,e,s,a){const n=e.xml??null,l={...n?.a??{}};l.name=e.name,l.fld=String(e.field),e.agg&&e.agg!=="sum"?l.subtotal=e.agg:delete l.subtotal,delete l.showDataAs;const o=e.showAs?.type??"normal",c=n?n.c.filter(g=>g.n!=="extLst"):[];let r=null;ut.has(o)?r=o:o!=="normal"&&(l.showDataAs=o);const i=e.showAs?.baseField??0;l.baseField=String(i>=0?i:0);let u=0;const p=e.showAs?.baseItem;if(p==="prev")u=xe;else if(p==="next")u=ye;else if(p!==void 0&&e.showAs?.baseField>=0){const g=t.cache.fields[e.showAs.baseField].ensure(),w=g.keyIndex.get(p);w!==void 0&&(u=s(g.index).position[w])}l.baseItem=String(u);const f=e.numFmt??(o!=="normal"&&!o.startsWith("rank")&&o!=="difference"&&o!=="runTotal"?o==="index"?"0.00":"0.00%":null);if(f){const g=ke(f)??a.numFmtId?.(f);g!=null&&(l.numFmtId=String(g))}else delete l.numFmtId;const d=[],h=n?b(n,"extLst"):null;if(h)for(const g of h.c)if(b(g,"x14:dataField")){const w={...b(g,"x14:dataField").a};delete w.pivotShowAs,r&&(w.pivotShowAs=r),d.push(m("ext",g.a,[m("x14:dataField",w)])),r=null}else d.push(g);return r&&d.push(m("ext",{uri:it,"xmlns:x14":z},[m("x14:dataField",{pivotShowAs:r})])),d.length&&c.push(m("extLst",{},d)),m("dataField",l,c)}function Ht(t,{cacheId:e,numFmtId:s}={}){const a=t.result??t.update(),{spec:n,cache:l}=t,{layout:o,rows:c,cols:r}=a,i=new Map,u=I=>{let E=i.get(I);return E===void 0&&(E=Ot(t,I),i.set(I,E)),E},p=t.xml?.root??null,f={...p?.a??{}};f.xmlns??=Z,f.name=n.name,f.cacheId=String(e??l.id??1),f.applyNumberFormats??="0",f.applyBorderFormats??="0",f.applyFontFormats??="0",f.applyPatternFormats??="0",f.applyAlignmentFormats??="0",f.applyWidthHeightFormats??="1",f.dataCaption=n.dataCaption,f.updatedVersion??="6",f.minRefreshableVersion??="3",f.useAutoFormatting??="1",f.itemPrintTitles??="1",f.createdVersion??="6",f.indent??="0",n.mergeLabels?f.mergeItem="1":delete f.mergeItem,t.fileAttrs&&Object.assign(f,t.fileAttrs);const d=(I,E,G)=>{E===G?delete f[I]:f[I]=E?"1":"0"};d("compact",n.layout==="compact",!0),d("compactData",n.layout==="compact",!0),f.outline=n.layout==="tabular"?f.outline??"1":"1",f.outlineData=n.layout==="tabular"?f.outlineData??"1":"1",d("colGrandTotals",n.grandRow,!0),d("rowGrandTotals",n.grandCol,!0),n.rowCaption!=null?f.rowHeaderCaption=n.rowCaption:delete f.rowHeaderCaption,n.colCaption!=null?f.colHeaderCaption=n.colCaption:delete f.colHeaderCaption,n.grandCaption!=null?f.grandTotalCaption=n.grandCaption:delete f.grandTotalCaption,n.emptyText!==""&&n.showMissing!==!1?f.missingCaption=n.emptyText:delete f.missingCaption,n.showMissing===!1?f.showMissing="0":delete f.showMissing,n.errorText!==null?(f.showError="1",f.errorCaption=n.errorText):(delete f.showError,delete f.errorCaption),c.slots.includes(Q)?(f.dataOnRows="1",f.dataPosition=String(c.slots.indexOf(Q))):(delete f.dataOnRows,delete f.dataPosition);const h=Object.keys(n.fieldOptions).map(Number),g=h.some(I=>{const E=n.fieldOptions[I];return(E.labelFilter?1:0)+(E.valueFilter?1:0)+(E.top?1:0)>1});f.multipleFieldFilters=g?"1":"0";const w=t.anchor??{row:0,col:0},x=w.row+o.pageRows,v={ref:fe({r0:x,c0:w.col,r1:w.row+o.rows-1,c1:w.col+Math.max(o.bodyCols,1)-1}),firstHeaderRow:String(o.firstHeaderRow),firstDataRow:String(o.firstDataRow),firstDataCol:String(o.firstDataCol)};n.filters.length>0&&(v.rowPageCount=String(n.filters.length),v.colPageCount="1");const y=new Map;y.set("location",m("location",v));const F=m("pivotFields",{count:String(l.fields.length)});for(let I=0;I<l.fields.length;I++)F.c.push(Mt(t,I,u));y.set("pivotFields",F);const S=(I,E)=>m(I,{count:String(E.length)},E.map(G=>m("field",{x:String(G)})));if(c.slots.length>0&&y.set("rowFields",S("rowFields",c.slots)),y.set("rowItems",Pe("rowItems",a,c,u)),r.slots.length>0&&y.set("colFields",S("colFields",r.slots)),y.set("colItems",Pe("colItems",a,r,u)),n.filters.length>0){const I=m("pageFields",{count:String(n.filters.length)});for(const E of n.filters){const X={...t.xml?.pageFields?.get(E)??{},fld:String(E)};delete X.item,X.hier??="-1";const le=l.fields[E].ensure(),ce=n.fieldOptions[E]?.hidden??[];if(ce.length===le.items.length-1){const Be=new Set(ce),ue=u(E).order.findIndex(Me=>!Be.has(le.keyOf(Me)));ue>=0&&(X.item=String(ue))}I.c.push(m("pageField",X))}y.set("pageFields",I)}n.values.length>0&&y.set("dataFields",m("dataFields",{count:String(n.values.length)},n.values.map(I=>qt(t,I,u,{numFmtId:s}))));const C=n.style,D=p?b(p,"pivotTableStyleInfo"):null;y.set("pivotTableStyleInfo",m("pivotTableStyleInfo",{...D?.a??{},name:C.name,showRowHeaders:C.rowHeaders?"1":"0",showColHeaders:C.colHeaders?"1":"0",showRowStripes:C.rowStripes?"1":"0",showColStripes:C.colStripes?"1":"0",showLastColumn:C.lastColumn===!1?"0":"1"}));const B=_t(t,h),N=t.xml?.rawFilters??[],R=[...B,...N];R.length>0&&y.set("filters",m("filters",{count:String(R.length)},R));const k=$e(t,m);k&&y.set("conditionalFormats",k);const P=_e(t,m);P&&y.set("chartFormats",P);const O=yt(p,n.hideValuesRow);O&&y.set("extLst",O);const M=[];for(const I of Le)if(y.has(I))M.push(y.get(I));else if(p&&!Vt.has(I)){const E=b(p,I);E&&M.push(E)}if(p)for(const I of p.c)Le.includes(I.n)||M.splice(M.length-(M[M.length-1]?.n==="extLst"?1:0),0,I);return W+ne(m("pivotTableDefinition",f,M)).join("")}const Vt=new Set(["extLst","location","pivotFields","rowFields","rowItems","colFields","colItems","pageFields","dataFields","pivotTableStyleInfo","filters"]);function ie(t,e){for(let s=1;;s++){const a=e(s);if(!t.has(a))return t.add(a),a}}function tn(t){const e=t.map(s=>`<Relationship Id="${s.id}" Type="${s.type}" Target="${Y(s.target)}"/>`).join("");return`${W}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${e}</Relationships>`}function nn(t,{existing:e=[],saveRecords:s=!0,numFmtId:a,refreshOnLoad:n=!0,firstCacheId:l=1}={}){const o=new Set(e),c=[],r=[],i=[],u=[],p=new Map;let f=l;const d=x=>{c.push(x),i.push({partName:`/${x.name}`,contentType:x.contentType})},h=t.filter(x=>x.dirty||!x.part),g=[],w=new Set(t.filter(x=>!h.includes(x)).map(x=>x.cache));for(const x of h){const{cache:v}=x;x.part&&g.push(x.part),v.part&&!w.has(v)&&(g.push(v.part),v.part=null);let y=p.get(v);if(y===void 0){const S=f++,C=ie(o,R=>`xl/pivotCache/pivotCacheDefinition${R}.xml`);v.id=S;let D=null;if(s&&v.recordCount>0){const R=ie(o,k=>`xl/pivotCache/pivotCacheRecords${k}.xml`);D="rId1",r.push({from:C,id:D,type:_.records,target:`/${R}`}),d({name:R,contentType:ee.records,large:!0,produce:k=>Oe(v,k)})}const N={name:C,contentType:ee.definition,xml:null};d(N),y={cacheId:S,defName:C,defPart:N,recordsRel:D},p.set(v,y),u.push({cacheId:S,target:`/${C}`,type:_.definition})}x.result||x.update();const F=ie(o,S=>`xl/pivotTables/pivotTable${S}.xml`);d({name:F,contentType:ee.table,xml:Ht(x,{cacheId:y.cacheId,numFmtId:a})}),r.push({from:F,id:"rId1",type:_.definition,target:`/${y.defName}`}),r.push({from:null,sheet:x.anchor?.sheet??null,id:null,type:_.table,target:`/${F}`}),x.part=F}for(const[x,v]of p)v.defPart.xml=Ct(x,{recordsRel:v.recordsRel,numFmtId:a,refreshOnLoad:n});return{parts:c,relationships:r,contentTypes:i,replaced:g,workbook:{pivotCaches:u,pivotCachesXml(x){return u.length===0?"":`<pivotCaches>${u.map(v=>`<pivotCache cacheId="${v.cacheId}" r:id="${x(v.cacheId)}"/>`).join("")}</pivotCaches>`}}}}export{ee as CONTENT_TYPE,pt as CacheRecordsReader,We as EMPTY,Ye as ERRORS,Ie as NodeReader,_ as REL_TYPE,et as XlError,nn as buildPivotPackage,Ct as cacheDefinitionXml,wt as cacheFromXml,U as isoToSerial,Ne as parseNode,vt as pivotFromXml,Ht as pivotTableXml,ht as readCacheDefinition,mt as readCacheRecords,zt as readPivotParts,en as recordsBlob,tn as relationshipsXml,H as serialToIso,ne as serializeNode,Oe as writeCacheRecords};
|