@8sheets/data-grid 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/a11y/cell-alt-text.js +1 -1
- package/api/serialize.js +1 -1
- package/api/style-refs.js +1 -1
- package/calc/adjust.js +1 -1
- package/calc/compile.js +1 -1
- package/calc/engine.js +1 -1
- package/calc/functions/array.js +1 -1
- package/calc/functions/database.js +1 -1
- package/calc/functions/date.js +1 -1
- package/calc/functions/engineering.js +1 -1
- package/calc/functions/financial.js +1 -1
- package/calc/functions/helpers.js +1 -1
- package/calc/functions/index.js +3 -2
- package/calc/functions/info.js +1 -1
- package/calc/functions/logical.js +1 -1
- package/calc/functions/lookup.js +1 -1
- package/calc/functions/math.js +1 -1
- package/calc/functions/stat.js +1 -1
- package/calc/functions/text.js +1 -1
- package/calc/parser.js +2 -2
- package/calc/shown-refs.js +1 -0
- package/calc/values.js +1 -1
- package/calcx/calc-control.js +1 -0
- package/calcx/external-read.js +1 -1
- package/calcx/external.js +1 -1
- package/calcx/lang/convert.js +1 -1
- package/cells/axis-ops.js +1 -1
- package/cells/book-css.js +7 -2
- package/cells/cell-styles-xml.js +1 -1
- package/cells/cf-engine.js +1 -1
- package/cells/cf-file.js +1 -1
- package/cells/docprops-xml.js +2 -2
- package/cells/filter-eval.js +1 -0
- package/cells/filter-file.js +1 -1
- package/cells/find-engine.js +2 -2
- package/cells/find.js +1 -1
- package/cells/goto.js +1 -1
- package/cells/link-model.js +1 -0
- package/cells/name-box.js +1 -1
- package/cells/note-box.js +3 -0
- package/cells/options.js +1 -1
- package/cells/outline-column.js +1 -1
- package/cells/protected-menu.js +1 -0
- package/cells/rich-data-xml.js +1 -1
- package/cells/selection-modes.js +1 -1
- package/cells/sheet-views-file.js +2 -0
- package/cells/shift-check.js +1 -1
- package/cells/sort-compare.js +1 -0
- package/cells/ui-kit.js +1 -1
- package/cells/undo-group.js +1 -1
- package/celltypes/dropdowns.js +2 -2
- package/core/address.js +1 -1
- package/core/autofill.js +1 -1
- package/core/axis.js +1 -1
- package/core/cond-format.js +1 -1
- package/core/culture.js +5 -1
- package/core/custom-views.js +1 -1
- package/core/data-tools.js +1 -0
- package/core/date-codes.js +1 -0
- package/core/default-names.js +1 -1
- package/core/edit-ranges.js +1 -0
- package/core/formula-refs.js +1 -1
- package/core/host-rules.js +1 -0
- package/core/input.js +1 -1
- package/core/numfmt.js +1 -1
- package/core/precision.js +1 -0
- package/core/protection.js +1 -1
- package/core/region-input.js +1 -1
- package/core/rule-refs.js +1 -0
- package/core/shared-view.js +1 -0
- package/core/sheet.js +1 -1
- package/core/sparklines.js +1 -1
- package/core/sparse.js +1 -1
- package/core/spills.js +1 -0
- package/core/strings.js +1 -1
- package/core/structure.js +1 -1
- package/core/table-columns.js +1 -0
- package/core/tables.js +2 -2
- package/core/validation-ranges.js +1 -1
- package/core/whatif.js +1 -1
- package/core/workbook.js +1 -1
- package/datasheets/formula.js +1 -1
- package/datasheets/manager.js +1 -1
- package/datasheets/path-binding.js +1 -1
- package/datasheets/persist-writer.js +1 -1
- package/datasheets/persist.js +1 -1
- package/datasheets/report.js +1 -1
- package/extras/getdata/persist.js +2 -2
- package/extras/getdata/rows.js +1 -1
- package/extras/getdata/shared-steps.js +1 -0
- package/extras/getdata/steps-formula.js +1 -0
- package/extras/getdata/steps-more.js +1 -0
- package/extras/getdata/steps-tables.js +1 -0
- package/extras/getdata/steps.js +1 -1
- package/i18n/de/a11y.js +1 -0
- package/i18n/de/cells.js +2 -0
- package/i18n/de/charts.js +1 -0
- package/i18n/de/common.js +1 -0
- package/i18n/de/datasheets.js +1 -0
- package/i18n/de/format.js +1 -0
- package/i18n/de/misc.js +1 -0
- package/i18n/de/pivot.js +1 -0
- package/i18n/de/proofing.js +1 -0
- package/i18n/de/ribbon.js +1 -0
- package/i18n/de/shapes.js +1 -0
- package/i18n/de/shell.js +3 -0
- package/i18n/de/touch.js +1 -0
- package/i18n/de.js +1 -0
- package/i18n/en/cells.js +2 -1
- package/i18n/en/charts.js +1 -1
- package/i18n/en/format.js +1 -1
- package/i18n/en/misc.js +1 -1
- package/i18n/en/pivot.js +1 -1
- package/i18n/en/proofing.js +1 -1
- package/i18n/en/ribbon.js +1 -1
- package/i18n/en/shapes.js +1 -1
- package/i18n/en/shell.js +3 -2
- package/i18n/en/touch.js +1 -1
- package/i18n/es/a11y.js +1 -0
- package/i18n/es/cells.js +2 -0
- package/i18n/es/charts.js +1 -0
- package/i18n/es/common.js +1 -0
- package/i18n/es/datasheets.js +1 -0
- package/i18n/es/format.js +1 -0
- package/i18n/es/misc.js +1 -0
- package/i18n/es/pivot.js +1 -0
- package/i18n/es/proofing.js +1 -0
- package/i18n/es/ribbon.js +1 -0
- package/i18n/es/shapes.js +1 -0
- package/i18n/es/shell.js +3 -0
- package/i18n/es/touch.js +1 -0
- package/i18n/es.js +1 -0
- package/i18n/fr/a11y.js +1 -0
- package/i18n/fr/cells.js +2 -0
- package/i18n/fr/charts.js +1 -0
- package/i18n/fr/common.js +1 -0
- package/i18n/fr/datasheets.js +1 -0
- package/i18n/fr/format.js +1 -0
- package/i18n/fr/misc.js +1 -0
- package/i18n/fr/pivot.js +1 -0
- package/i18n/fr/proofing.js +1 -0
- package/i18n/fr/ribbon.js +1 -0
- package/i18n/fr/shapes.js +1 -0
- package/i18n/fr/shell.js +3 -0
- package/i18n/fr/touch.js +1 -0
- package/i18n/fr.js +1 -0
- package/i18n/index.js +1 -1
- package/i18n/languages.js +1 -1
- package/i18n/pl/cells.js +2 -1
- package/i18n/pl/charts.js +1 -1
- package/i18n/pl/format.js +1 -1
- package/i18n/pl/misc.js +1 -1
- package/i18n/pl/pivot.js +1 -1
- package/i18n/pl/proofing.js +1 -1
- package/i18n/pl/ribbon.js +1 -1
- package/i18n/pl/shapes.js +1 -1
- package/i18n/pl/shell.js +3 -2
- package/i18n/pl/touch.js +1 -1
- package/io/blob-sink.js +1 -0
- package/io/canonical-xml.js +1 -0
- package/io/client.js +1 -1
- package/io/crypto/cfb-build.js +1 -0
- package/io/crypto/cfb-read.js +1 -1
- package/io/crypto/cfb-write.js +1 -1
- package/io/crypto/errors.js +1 -1
- package/io/csv.js +8 -8
- package/io/encoding.js +1 -0
- package/io/foreign-sheets.js +2 -2
- package/io/io.worker.js +1 -1
- package/io/open-package.js +1 -0
- package/io/package-paths.js +1 -1
- package/io/plan.js +1 -1
- package/io/text-split.js +3 -3
- package/io/xls/chart-sheet.js +1 -0
- package/io/xls/chart.js +1 -0
- package/io/xls/crypt.js +1 -0
- package/io/xls/dml-color.js +1 -0
- package/io/xls/drawing.js +1 -0
- package/io/xls/formula.js +1 -0
- package/io/xls/geometry.js +1 -0
- package/io/xls/index.js +1 -0
- package/io/xls/pictures.js +1 -0
- package/io/xls/pivot.js +1 -0
- package/io/xls/props.js +1 -0
- package/io/xls/records.js +1 -0
- package/io/xls/shapes.js +1 -0
- package/io/xls/sheet-ext.js +1 -0
- package/io/xls/sheet.js +1 -0
- package/io/xls/styles.js +1 -0
- package/io/xls/vba.js +1 -0
- package/io/xls/workbook.js +1 -0
- package/io/xlsb/filter.js +1 -0
- package/io/xlsb/formula.js +2 -0
- package/io/xlsb/functions.js +1 -0
- package/io/xlsb/index.js +1 -0
- package/io/xlsb/parts.js +1 -0
- package/io/xlsb/pivot.js +1 -0
- package/io/xlsb/records.js +1 -0
- package/io/xlsb/sheet-ext.js +1 -0
- package/io/xlsb/sheet.js +1 -0
- package/io/xlsb/slicer.js +1 -0
- package/io/xlsb/styles.js +1 -0
- package/io/xlsb/workbook.js +1 -0
- package/io/xlsb/xml.js +2 -0
- package/io/xlsx-read.js +1 -1
- package/io/xlsx-styles.js +2 -2
- package/io/xlsx-tail.js +1 -1
- package/io/xlsx-write.js +2 -2
- package/io/xml-escape.js +1 -1
- package/io/xml-scan.js +2 -2
- package/io/zip-reader.js +1 -1
- package/objects/chart-model.js +1 -1
- package/objects/drawing-xml.js +1 -1
- package/package.json +1 -1
- package/pivot/calc-items.js +1 -0
- package/pivot/engine.js +1 -1
- package/pivot/xml.js +2 -2
- package/print/note-pages.js +2 -0
- package/print/page-setup.js +1 -1
- package/print/paginate.js +1 -1
- package/print/pdf-crypt.js +1 -0
- package/print/pdf-links.js +1 -0
- package/print/pdf-tags.js +1 -0
- package/print/pdf.js +24 -13
- package/print/render-page.js +3 -3
- package/print/shown-notes.js +1 -0
- package/shapes/form-xml.js +1 -1
- package/slicers/custom-styles.js +1 -1
- package/slicers/format.js +1 -1
- package/slicers/structured.js +1 -1
- package/slicers/write.js +1 -1
- package/table-view/files.js +1 -1
- package/table-view/mount.js +1 -1
- package/table-view/version.js +1 -1
- package/ui/dialogs.js +3 -3
- package/ui/icons.js +1 -1
- package/ui/menu-base.js +1 -1
- package/ui/protection-ui.js +1 -1
package/slicers/custom-styles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EXT as k,NS as W}from"./format.js";import{parseNode as K}from"../pivot/xml.js";import{xmlAttr as _}from"../io/xml-escape.js";import{dxfXml as G,parseDxfs as Y}from"../io/xlsx-tail.js";import{resolveColor as q}from"../io/xlsx-styles.js";import{bandRow as J}from"../core/tables.js";const j="{46F421CA-312F-682f-3DD2-61675219B42D}",U="{A0A4C193-F2C1-4fcb-8827-314CF55A85BB}",V=(e,l)=>e?.c?.find(i=>i.n===l)??null,Q=(e,l)=>e?e.c.filter(i=>i.n===l):[],v=e=>e.slice(e.indexOf(":")+1),Z=["wholeTable","headerRow","totalRow","firstColumn","lastColumn","firstRowStripe","secondRowStripe","firstColumnStripe","secondColumnStripe","firstHeaderCell","lastHeaderCell","firstTotalCell","lastTotalCell"],ee=["wholeTable","pageFieldLabels","pageFieldValues","firstColumnStripe","secondColumnStripe","firstRowStripe","secondRowStripe","firstColumn","headerRow","firstHeaderCell","firstSubtotalColumn","secondSubtotalColumn","thirdSubtotalColumn","blankRow","firstSubtotalRow","secondSubtotalRow","thirdSubtotalRow","firstColumnSubheading","secondColumnSubheading","thirdColumnSubheading","firstRowSubheading","secondRowSubheading","thirdRowSubheading","totalRow","lastColumn"],me=["unselectedItemWithData","selectedItemWithData","unselectedItemWithNoData","selectedItemWithNoData","hoveredUnselectedItemWithData","hoveredSelectedItemWithData","hoveredUnselectedItemWithNoData","hoveredSelectedItemWithNoData"],Se=["selectionLabel","timeLevel","periodLabel1","periodLabel2","selectedTimeBlock","unselectedTimeBlock","selectedTimeBlockSpace"];class te{constructor(){this.tableStyles=[],this.slicerStyles=[],this.timelineStyles=[],this.slicerDxfs=[],this.timelineDxfs=[],this.defaultTableStyle="TableStyleMedium2",this.defaultPivotStyle="PivotStyleLight16",this.defaultSlicerStyle="SlicerStyleLight1",this.defaultTimelineStyle="TimeSlicerStyleLight1",this.dirty=!1,this.version=0}find(l){return this.tableStyles.find(i=>i.name===l)??null}forTables(){return this.tableStyles.filter(l=>l.table)}forPivots(){return this.tableStyles.filter(l=>l.pivot)}setTableStyle(l,i,{table:d=!0,pivot:r=!1,elements:u={}}){const s=Object.entries(u).map(([o,f])=>({type:o,dxfId:le(l,f),...f.size?{size:f.size}:{}})),t={name:i,table:d,pivot:r,elements:s},a=this.tableStyles.findIndex(o=>o.name===i);return a>=0?this.tableStyles[a]=t:this.tableStyles.push(t),this.dirty=!0,this.version++,t}setSlicerStyle(l,i,{whole:d=null,header:r=null,elements:u={}}){this.setTableStyle(l,i,{table:!1,pivot:!1,elements:{...d?{wholeTable:d}:{},...r?{headerRow:r}:{}}});const s={name:i,elements:Object.entries(u).map(([a,o])=>({type:a,dxfId:this.slicerDxfs.push(o)-1}))},t=this.slicerStyles.findIndex(a=>a.name===i);return t>=0?this.slicerStyles[t]=s:this.slicerStyles.push(s),this.dirty=!0,s}setTimelineStyle(l,i,{whole:d=null,header:r=null,elements:u={}}){this.setTableStyle(l,i,{table:!1,pivot:!1,elements:{...d?{wholeTable:d}:{},...r?{headerRow:r}:{}}});const s={name:i,elements:Object.entries(u).map(([a,o])=>({type:a,dxfId:this.timelineDxfs.push(o)-1}))},t=this.timelineStyles.findIndex(a=>a.name===i);return t>=0?this.timelineStyles[t]=s:this.timelineStyles.push(s),this.dirty=!0,s}setDefaultTableStyle(l){return this.defaultTableStyle===l?!1:(this.defaultTableStyle=l,this.dirty=!0,this.version++,!0)}removeStyle(l){this.tableStyles=this.tableStyles.filter(i=>i.name!==l),this.slicerStyles=this.slicerStyles.filter(i=>i.name!==l),this.timelineStyles=this.timelineStyles.filter(i=>i.name!==l),this.dirty=!0,this.version++}savePlan(){return this.dirty?{tableStyles:this.tableStyles,slicerStyles:this.slicerStyles,timelineStyles:this.timelineStyles,slicerDxfs:this.slicerDxfs.map(G),timelineDxfs:this.timelineDxfs.map(G),defaultTableStyle:this.defaultTableStyle,defaultPivotStyle:this.defaultPivotStyle,defaultSlicerStyle:this.defaultSlicerStyle,defaultTimelineStyle:this.defaultTimelineStyle}:null}}function le(e,l){e.dxfs??=[];const{size:i,...d}=l;return e.dxfs.push(d),e.dxfs.length-1}const B=e=>(e?e.c.filter(l=>typeof l!="string"):[]).map(l=>({type:l.a.type,dxfId:Number(l.a.dxfId??-1),...l.a.size?{size:Number(l.a.size)}:{}})).filter(l=>l.dxfId>=0);function he(e,l=[]){const i=new te,d=typeof e=="string"?e:new TextDecoder().decode(e),r=t=>{const a=new RegExp(`<${t}:dxfs\\b[^>]*>([\\s\\S]*?)</${t}:dxfs>`).exec(d);return a?Y(new TextEncoder().encode(`<r><dxfs>${a[1]}</dxfs></r>`),o=>o?q(o,l):null):[]};i.slicerDxfs=r("x14"),i.timelineDxfs=r("x15");const u=K(e),s=V(u,"tableStyles");s&&(i.defaultTableStyle=s.a.defaultTableStyle??i.defaultTableStyle,i.defaultPivotStyle=s.a.defaultPivotStyle??i.defaultPivotStyle,i.tableStyles=Q(s,"tableStyle").map(t=>({name:t.a.name,table:t.a.table!=="0",pivot:t.a.pivot!=="0",elements:B(t)})));for(const t of V(u,"extLst")?.c??[])if(t.a?.uri===k.slicerStyles){const a=t.c.find(o=>v(o.n)==="slicerStyles");a&&(i.defaultSlicerStyle=a.a.defaultSlicerStyle??i.defaultSlicerStyle,i.slicerStyles=a.c.filter(o=>v(o.n)==="slicerStyle").map(o=>({name:o.a.name,elements:B(o.c.find(f=>v(f.n)==="slicerStyleElements"))})))}else if(t.a?.uri===k.timelineStyles){const a=t.c.find(o=>v(o.n)==="timelineStyles");a&&(i.defaultTimelineStyle=a.a.defaultTimelineStyle??i.defaultTimelineStyle,i.timelineStyles=a.c.filter(o=>v(o.n)==="timelineStyle").map(o=>({name:o.a.name,elements:B(o.c.find(f=>v(f.n)==="timelineStyleElements"))})))}return i}const H=(e,l)=>`<${e} type="${l.type}"${l.size?` size="${l.size}"`:""} dxfId="${l.dxfId}"/>`;function be(e,l){if(!l)return e;const i=n=>(l.slicerStyles.find(h=>h.name===n)?.elements.length??0)+(l.timelineStyles.find(h=>h.name===n)?.elements.length??0),d=`<tableStyles count="${l.tableStyles.length}" defaultTableStyle="${_(l.defaultTableStyle)}" defaultPivotStyle="${_(l.defaultPivotStyle)}"${l.tableStyles.length?`>${l.tableStyles.map(n=>`<tableStyle name="${_(n.name)}"${n.table?"":' table="0"'}${n.pivot?"":' pivot="0"'} count="${n.elements.length+i(n.name)}">${n.elements.map(h=>H("tableStyleElement",h)).join("")}</tableStyle>`).join("")}</tableStyles>`:"/>"}`;let r=e;if(/<tableStyles\b/.test(r))r=r.replace(/<tableStyles\b[^>]*?\/>|<tableStyles\b[\s\S]*?<\/tableStyles>/,d);else{const n=/<(?:colors|extLst)\b|<\/styleSheet>/.exec(r);r=`${r.slice(0,n.index)}${/<dxfs\b/.test(r)?"":'<dxfs count="0"/>'}${d}${r.slice(n.index)}`}const u=n=>{r=r.replace(new RegExp(`<ext\\b[^>]*uri="${n.replace(/[{}-]/g,"\\$&")}"[^>]*>[\\s\\S]*?</ext>`),"")};u(k.slicerStyles),u(k.timelineStyles),u(j),u(U);const s=(n,h,b,m)=>m.length?`<ext uri="${n}" xmlns:${h}="${b}"><${h}:dxfs count="${m.length}">${m.join("")}</${h}:dxfs></ext>`:"",t=`${s(j,"x14",W.x14,l.slicerDxfs)}`,a=`${s(U,"x15",W.x15,l.timelineDxfs)}`,o=`<ext uri="${k.slicerStyles}" xmlns:x14="${W.x14}"><x14:slicerStyles defaultSlicerStyle="${_(l.defaultSlicerStyle)}"${l.slicerStyles.length?`>${l.slicerStyles.map(n=>`<x14:slicerStyle name="${_(n.name)}"><x14:slicerStyleElements>${n.elements.map(h=>H("x14:slicerStyleElement",h)).join("")}</x14:slicerStyleElements></x14:slicerStyle>`).join("")}</x14:slicerStyles>`:"/>"}</ext>`,f=`<ext uri="${k.timelineStyles}" xmlns:x15="${W.x15}"><x15:timelineStyles defaultTimelineStyle="${_(l.defaultTimelineStyle)}"${l.timelineStyles.length?`>${l.timelineStyles.map(n=>`<x15:timelineStyle name="${_(n.name)}"><x15:timelineStyleElements>${n.elements.map(h=>H("x15:timelineStyleElement",h)).join("")}</x15:timelineStyleElements></x15:timelineStyle>`).join("")}</x15:timelineStyles>`:"/>"}</ext>`;return/<\/extLst>\s*<\/styleSheet>/.test(r)?r=r.replace(/<\/extLst>(\s*<\/styleSheet>)/,`${t}${o}${a}${f}</extLst>$1`):r=r.replace("</styleSheet>",`<extLst>${t}${o}${a}${f}</extLst></styleSheet>`),r}const O=(e,l,i,d=e.dxfs)=>{const r=l?.elements.find(u=>u.type===i);return r?d?.[r.dxfId]??{}:null},N=e=>{const l=e?.borders;return l?l.b?.color??l.t?.color??l.l?.color??l.r?.color??null:null},ie=["fill","color","bold","italic","underline","strike"],E=(e,l)=>{if(l)for(const i of ie)l[i]!==void 0&&(e[i]=l[i])},X=(e,l,i)=>e%(l+i)<l?0:1;function ye(e,l,i){const d=l?.find(i);if(!d)return null;const r=s=>d.elements.find(t=>t.type===s)?.size??1,u=Object.fromEntries(Z.map(s=>[s,O(e,d,s)]));return se(u,[r("firstRowStripe"),r("secondRowStripe")],[r("firstColumnStripe"),r("secondColumnStripe")],!0)}function se(e,l=[1,1],i=[1,1],d=!1){const r=(t,a,o)=>{const f={},n=t.r0+t.headerRows,h=t.r1-t.totalsRows,b=a>=n&&a<=h;return E(f,e.wholeTable),b&&(t.showColumnStripes&&E(f,X(o-t.c0,i[0],i[1])===0?e.firstColumnStripe:e.secondColumnStripe),t.showRowStripes!==!1&&E(f,X(J(t,a),l[0],l[1])===0?e.firstRowStripe:e.secondRowStripe)),t.showFirstColumn&&o===t.c0&&E(f,e.firstColumn),t.showLastColumn&&o===t.c1&&E(f,e.lastColumn),a<n?(E(f,e.headerRow),o===t.c0&&t.showFirstColumn&&E(f,e.firstHeaderCell),o===t.c1&&t.showLastColumn&&E(f,e.lastHeaderCell)):a>h&&(E(f,e.totalRow),o===t.c0&&t.showFirstColumn&&E(f,e.firstTotalCell),o===t.c1&&t.showLastColumn&&E(f,e.lastTotalCell)),f},u=(t,a,o,f,n)=>{const h=[],b=(R,w,y,T,S)=>{R?.borders&&T>=w&&S>=y&&h.push({borders:R.borders,r0:w,c0:y,r1:T,c1:S})},m=t.r0+t.headerRows,c=t.r1-t.totalsRows;if(b(e.wholeTable,t.r0,t.c0,t.r1,t.c1),t.showColumnStripes&&(e.firstColumnStripe?.borders||e.secondColumnStripe?.borders)){const R=i[0]+i[1];for(let w=t.c0;w<=Math.min(t.c1,n);w+=R)b(e.firstColumnStripe,m,w,c,Math.min(t.c1,w+i[0]-1)),b(e.secondColumnStripe,m,w+i[0],c,Math.min(t.c1,w+R-1))}if(t.showRowStripes!==!1&&(e.firstRowStripe?.borders||e.secondRowStripe?.borders)){const R=l[0]+l[1],w=m+Math.floor(Math.max(0,a-m)/R)*R;for(let y=w;y<=Math.min(c,o);y+=R)b(e.firstRowStripe,y,t.c0,Math.min(c,y+l[0]-1),t.c1),b(e.secondRowStripe,y+l[0],t.c0,Math.min(c,y+R-1),t.c1)}return t.showFirstColumn&&b(e.firstColumn,t.r0,t.c0,t.r1,t.c0),t.showLastColumn&&b(e.lastColumn,t.r0,t.c1,t.r1,t.c1),t.headerRows>0&&(b(e.headerRow,t.r0,t.c0,m-1,t.c1),t.showFirstColumn&&b(e.firstHeaderCell,t.r0,t.c0,m-1,t.c0),t.showLastColumn&&b(e.lastHeaderCell,t.r0,t.c1,m-1,t.c1)),t.totalsRows>0&&(b(e.totalRow,c+1,t.c0,t.r1,t.c1),t.showFirstColumn&&b(e.firstTotalCell,c+1,t.c0,t.r1,t.c0),t.showLastColumn&&b(e.lastTotalCell,c+1,t.c1,t.r1,t.c1)),h},s=e.headerRow;return{format:r,areas:u,custom:d,headerFill:s?.fill??null,headerInk:s?.color??(s?.fill?"#FFFFFF":"#000000"),headerRule:N(s),band:e.firstRowStripe?.fill??null,rule:N(e.wholeTable)??N(e.totalRow),body:e.wholeTable?.fill??null,ink:e.wholeTable?.color??null}}const z={medium:2,mediumDashed:2,mediumDashDot:2,mediumDashDotDot:2,slantDashDot:2,thick:3,double:3};function pe(e,l,i,{ra:d,rb:r,ca:u,cb:s,xs:t,ys:a,ox:o=0,oy:f=0,line:n=1,noFill:h=!1,setInk:b}){const m=Math.max(l.r0,d),c=Math.min(l.r1,r),R=Math.max(l.c0,u),w=Math.min(l.c1,s);for(let S=h?c+1:m;S<=c;S++){const p=a[S-d],x=a[S-d+1]-p;if(x!==0)for(let L=R;L<=w;L++){const $=t[L-u],D=t[L-u+1]-$;if(D===0)continue;const{fill:C}=i.format(l,S,L);C&&(b(C),e.fillRect(o+$,f+p,D,x))}}const y=(S,p,x,L,$)=>{b(S.color);const D=z[S.style]??1,C=$?L-D*n:L;S.style==="double"?(e.fillRect(o+p,f+C,x-p,n),e.fillRect(o+p,f+C+2*n,x-p,n)):e.fillRect(o+p,f+C,x-p,D*n)},T=(S,p,x,L,$)=>{b(S.color);const D=z[S.style]??1,C=$?L-D*n:L;S.style==="double"?(e.fillRect(o+C,f+p,n,x-p),e.fillRect(o+C+2*n,f+p,n,x-p)):e.fillRect(o+C,f+p,D*n,x-p)};for(const S of i.areas(l,m,c,R,w)){if(S.r1<d||S.r0>r||S.c1<u||S.c0>s)continue;const p=Math.max(S.c0,u),x=Math.min(S.c1,s),L=Math.max(S.r0,d),$=Math.min(S.r1,r),D=t[p-u],C=t[x-u+1],P=a[L-d],M=a[$-d+1],A=S.borders;if(A.h)for(let I=L;I<$+(S.r1>$?1:0);I++){const g=a[I-d+1];g!==a[I-d]&&y(A.h,D,C,g,!0)}if(A.v)for(let I=p;I<x+(S.c1>x?1:0);I++){const g=t[I-u+1];g!==t[I-u]&&T(A.v,P,M,g,!0)}A.t&&S.r0>=d&&y(A.t,D,C,P,!1),A.b&&S.r1<=r&&y(A.b,D,C,M,!0),A.l&&S.c0>=u&&T(A.l,P,M,D,!1),A.r&&S.c1<=s&&T(A.r,P,M,C,!0)}}const oe={NONE:0,PAGE_LABEL:1,PAGE_VALUE:2,CORNER:3,HEADER_BLANK:4,COL_CAPTION:5,ROW_CAPTION:6,COL_ITEM:7,COL_SUBTOTAL:8,COL_GRAND:9,DATA_HEADER:10,ROW_ITEM:11,ROW_PARENT:12,ROW_SUBTOTAL:13,ROW_GRAND:14,DATA:15,DATA_PARENT:16,DATA_SUBTOTAL:17,DATA_GRAND_ROW:18,DATA_GRAND_COL:19,PLACEHOLDER:20},F=(e,l,i,d)=>e<=0?l:e===1?i:d;function Re(e,l,i){const d=l?.find(i);return d?ne(Object.fromEntries(ee.map(r=>[r,O(e,d,r)])),!0):null}function ne(e,l=!1){const i=oe,d=e.wholeTable?.borders&&(e.wholeTable.borders.h||e.wholeTable.borders.v)?{...e.wholeTable,borders:{b:e.wholeTable.borders.h??null,r:e.wholeTable.borders.v??null}}:e.wholeTable&&{...e.wholeTable,borders:void 0};return{patch:(u,s,t,a={},o=0)=>{const f={},n=a.colHeaders===!1?null:e.headerRow,h=a.rowHeaders===!1?null:e.firstColumn,b=a.lastColumn===!1?null:e.lastColumn,m={},c=(T,S="tb")=>{T&&(E(f,T),T.borders&&(S.includes("t")&&T.borders.t&&(m.t=T.borders.t),S.includes("b")&&T.borders.b&&(m.b=T.borders.b),S.includes("l")&&T.borders.l&&(m.l=T.borders.l),S.includes("r")&&T.borders.r&&(m.r=T.borders.r)))};u!==i.PAGE_LABEL&&u!==i.PAGE_VALUE&&c(d,"br");const R=m.b,w=m.r;switch(t&4&&c(e.firstColumnStripe,"lr"),t&8&&c(e.secondColumnStripe,"lr"),t&1&&c(e.firstRowStripe),t&2&&c(e.secondRowStripe),u){case i.PAGE_LABEL:c(e.pageFieldLabels,"tblr");break;case i.PAGE_VALUE:c(e.pageFieldValues,"tblr");break;case i.CORNER:c(n),c(h,"lr"),c(e.firstHeaderCell,"tblr");break;case i.HEADER_BLANK:case i.COL_CAPTION:case i.DATA_HEADER:c(n);break;case i.ROW_CAPTION:c(n),c(e.firstHeaderCell,"tblr");break;case i.COL_ITEM:c(n),c(F(s,e.firstColumnSubheading,e.secondColumnSubheading,e.thirdColumnSubheading));break;case i.COL_SUBTOTAL:c(n),c(F(s,e.firstSubtotalColumn,e.secondSubtotalColumn,e.thirdSubtotalColumn),"lr");break;case i.COL_GRAND:c(n),c(b,"lr");break;case i.ROW_ITEM:c(h,"lr");break;case i.ROW_PARENT:c(h,"lr"),c(F(s,e.firstRowSubheading,e.secondRowSubheading,e.thirdRowSubheading));break;case i.ROW_SUBTOTAL:c(h,"lr"),c(F(s,e.firstSubtotalRow,e.secondSubtotalRow,e.thirdSubtotalRow));break;case i.ROW_GRAND:c(h,"lr"),c(e.totalRow);break;case i.DATA_PARENT:c(F(s,e.firstRowSubheading,e.secondRowSubheading,e.thirdRowSubheading));break;case i.DATA_SUBTOTAL:c(F(s,e.firstSubtotalRow,e.secondSubtotalRow,e.thirdSubtotalRow));break;case i.DATA_GRAND_ROW:c(e.totalRow);break;case i.DATA_GRAND_COL:c(b,"lr");break;case i.PLACEHOLDER:c(e.blankRow);break;default:}const y=e.wholeTable?.borders;return y&&o&&(o&1&&y.t&&!m.t&&(m.t=y.t),o&2&&y.b&&(!m.b||m.b===R)&&(m.b=y.b),o&4&&y.l&&!m.l&&(m.l=y.l),o&8&&y.r&&(!m.r||m.r===w)&&(m.r=y.r)),Object.keys(m).length&&(f.borders=m),f},stripe:e.firstRowStripe?.fill??null,custom:l,header:{},sub:{},grand:{},parent:{},page:{}}}function Te(e,l,i,d){const r=l?.slicerStyles.find(n=>n.name===i),u=l?.find(i);if(!r&&!u)return null;const s={...d},t=O(e,u,"wholeTable"),a=O(e,u,"headerRow");t?.fill&&(s.frameFill=t.fill),t?.color&&(s.ink=t.color);const o=N(t);o&&(s.frameLine=o),a?.color&&(s.captionInk=a.color),a?.fill&&(s.captionFill=a.fill);const f=(n,h,b,m)=>{const c=O(e,r,n,l.slicerDxfs);if(!c)return;c.fill&&(s[h]=c.fill),c.color&&(s[b]=c.color);const R=N(c);R&&m&&(s[m]=R)};return f("selectedItemWithData","selFill","selInk","selLine"),f("unselectedItemWithData","fill","itemInk","itemLine"),f("selectedItemWithNoData","selNoFill","selNoInk"),f("unselectedItemWithNoData","noFill","noInk"),s.hoverSelFill=s.selFill,s.hoverSelInk=s.selInk,s.hoverFill=s.fill,s.hoverInk=s.itemInk,f("hoveredSelectedItemWithData","hoverSelFill","hoverSelInk"),f("hoveredUnselectedItemWithData","hoverFill","hoverInk"),s}function we(e,l,i,d){const r=l?.timelineStyles.find(h=>h.name===i),u=l?.find(i);if(!r&&!u)return null;const s={...d},t=O(e,u,"wholeTable"),a=O(e,u,"headerRow");t?.fill&&(s.frameFill=t.fill);const o=N(t);o&&(s.frameLine=o),a?.color&&(s.captionInk=a.color);const f=(h,b)=>{const m=O(e,r,h,l.timelineDxfs);m?.fill&&(s[b]=m.fill)},n=(h,b)=>{const m=O(e,r,h,l.timelineDxfs);m?.color&&(s[b]=m.color)};return f("selectedTimeBlock","selFill"),f("unselectedTimeBlock","blockFill"),f("selectedTimeBlockSpace","selSpaceFill"),n("selectionLabel","labelInk"),n("timeLevel","levelInk"),n("periodLabel1","periodInk"),n("periodLabel2","subPeriodInk"),s}export{te as CustomStyles,ee as PIVOT_ELEMENTS,me as SLICER_ELEMENTS,Z as TABLE_ELEMENTS,Se as TIMELINE_ELEMENTS,le as addDxf,Re as customPivotPattern,Te as customSlicerColors,ye as customTableColors,we as customTimelineColors,ne as elementPivotPattern,se as elementTableColors,pe as paintCustomTable,he as parseCustomStyles,be as patchCustomStyles};
|
|
1
|
+
import{EXT as k,NS as W}from"./format.js";import{parseNode as K}from"../pivot/xml.js";import{xmlAttr as _}from"../io/xml-escape.js";import{dxfXml as G,parseDxfs as Y}from"../io/xlsx-tail.js";import{resolveColor as q}from"../io/xlsx-styles.js";import{bandRow as J}from"../core/tables.js";const j="{46F421CA-312F-682f-3DD2-61675219B42D}",U="{A0A4C193-F2C1-4fcb-8827-314CF55A85BB}",V=(e,l)=>e?.c?.find(i=>i.n===l)??null,Q=(e,l)=>e?e.c.filter(i=>i.n===l):[],v=e=>e.slice(e.indexOf(":")+1),Z=["wholeTable","headerRow","totalRow","firstColumn","lastColumn","firstRowStripe","secondRowStripe","firstColumnStripe","secondColumnStripe","firstHeaderCell","lastHeaderCell","firstTotalCell","lastTotalCell"],ee=["wholeTable","pageFieldLabels","pageFieldValues","firstColumnStripe","secondColumnStripe","firstRowStripe","secondRowStripe","firstColumn","headerRow","firstHeaderCell","firstSubtotalColumn","secondSubtotalColumn","thirdSubtotalColumn","blankRow","firstSubtotalRow","secondSubtotalRow","thirdSubtotalRow","firstColumnSubheading","secondColumnSubheading","thirdColumnSubheading","firstRowSubheading","secondRowSubheading","thirdRowSubheading","totalRow","lastColumn"],me=["unselectedItemWithData","selectedItemWithData","unselectedItemWithNoData","selectedItemWithNoData","hoveredUnselectedItemWithData","hoveredSelectedItemWithData","hoveredUnselectedItemWithNoData","hoveredSelectedItemWithNoData"],Se=["selectionLabel","timeLevel","periodLabel1","periodLabel2","selectedTimeBlock","unselectedTimeBlock","selectedTimeBlockSpace"];class te{constructor(){this.tableStyles=[],this.slicerStyles=[],this.timelineStyles=[],this.slicerDxfs=[],this.timelineDxfs=[],this.defaultTableStyle="TableStyleMedium2",this.defaultPivotStyle="PivotStyleLight16",this.defaultSlicerStyle="SlicerStyleLight1",this.defaultTimelineStyle="TimeSlicerStyleLight1",this.dirty=!1,this.version=0}find(l){return this.tableStyles.find(i=>i.name===l)??null}forTables(){return this.tableStyles.filter(l=>l.table)}forPivots(){return this.tableStyles.filter(l=>l.pivot)}setTableStyle(l,i,{table:d=!0,pivot:r=!1,elements:u={}}){const s=Object.entries(u).map(([o,f])=>({type:o,dxfId:le(l,f),...f.size?{size:f.size}:{}})),t={name:i,table:d,pivot:r,elements:s},a=this.tableStyles.findIndex(o=>o.name===i);return a>=0?this.tableStyles[a]=t:this.tableStyles.push(t),this.dirty=!0,this.version++,t}setSlicerStyle(l,i,{whole:d=null,header:r=null,elements:u={}}){this.setTableStyle(l,i,{table:!1,pivot:!1,elements:{...d?{wholeTable:d}:{},...r?{headerRow:r}:{}}});const s={name:i,elements:Object.entries(u).map(([a,o])=>({type:a,dxfId:this.slicerDxfs.push(o)-1}))},t=this.slicerStyles.findIndex(a=>a.name===i);return t>=0?this.slicerStyles[t]=s:this.slicerStyles.push(s),this.dirty=!0,s}setTimelineStyle(l,i,{whole:d=null,header:r=null,elements:u={}}){this.setTableStyle(l,i,{table:!1,pivot:!1,elements:{...d?{wholeTable:d}:{},...r?{headerRow:r}:{}}});const s={name:i,elements:Object.entries(u).map(([a,o])=>({type:a,dxfId:this.timelineDxfs.push(o)-1}))},t=this.timelineStyles.findIndex(a=>a.name===i);return t>=0?this.timelineStyles[t]=s:this.timelineStyles.push(s),this.dirty=!0,s}setDefaultTableStyle(l){return this.defaultTableStyle===l?!1:(this.defaultTableStyle=l,this.dirty=!0,this.version++,!0)}removeStyle(l){this.tableStyles=this.tableStyles.filter(i=>i.name!==l),this.slicerStyles=this.slicerStyles.filter(i=>i.name!==l),this.timelineStyles=this.timelineStyles.filter(i=>i.name!==l),this.dirty=!0,this.version++}savePlan(){return this.dirty?{tableStyles:this.tableStyles,slicerStyles:this.slicerStyles,timelineStyles:this.timelineStyles,slicerDxfs:this.slicerDxfs.map(G),timelineDxfs:this.timelineDxfs.map(G),defaultTableStyle:this.defaultTableStyle,defaultPivotStyle:this.defaultPivotStyle,defaultSlicerStyle:this.defaultSlicerStyle,defaultTimelineStyle:this.defaultTimelineStyle}:null}}function le(e,l){e.dxfs??=[];const{size:i,...d}=l;return e.dxfs.push(d),e.dxfs.length-1}const B=e=>(e?e.c.filter(l=>typeof l!="string"):[]).map(l=>({type:l.a.type,dxfId:Number(l.a.dxfId??-1),...l.a.size?{size:Number(l.a.size)}:{}})).filter(l=>l.dxfId>=0);function he(e,l=[]){const i=new te,d=typeof e=="string"?e:new TextDecoder().decode(e),r=t=>{const a=new RegExp(`<${t}:dxfs\\b[^>]*>([\\s\\S]*?)</${t}:dxfs>`).exec(d);return a?Y(new TextEncoder().encode(`<r><dxfs>${a[1]}</dxfs></r>`),o=>o?q(o,l):null):[]};i.slicerDxfs=r("x14"),i.timelineDxfs=r("x15");const u=K(e),s=V(u,"tableStyles");s&&(i.defaultTableStyle=s.a.defaultTableStyle??i.defaultTableStyle,i.defaultPivotStyle=s.a.defaultPivotStyle??i.defaultPivotStyle,i.tableStyles=Q(s,"tableStyle").map(t=>({name:t.a.name,table:t.a.table!=="0",pivot:t.a.pivot!=="0",elements:B(t)})));for(const t of V(u,"extLst")?.c??[])if(t.a?.uri===k.slicerStyles){const a=t.c.find(o=>v(o.n)==="slicerStyles");a&&(i.defaultSlicerStyle=a.a.defaultSlicerStyle??i.defaultSlicerStyle,i.slicerStyles=a.c.filter(o=>v(o.n)==="slicerStyle").map(o=>({name:o.a.name,elements:B(o.c.find(f=>v(f.n)==="slicerStyleElements"))})))}else if(t.a?.uri===k.timelineStyles){const a=t.c.find(o=>v(o.n)==="timelineStyles");a&&(i.defaultTimelineStyle=a.a.defaultTimelineStyle??i.defaultTimelineStyle,i.timelineStyles=a.c.filter(o=>v(o.n)==="timelineStyle").map(o=>({name:o.a.name,elements:B(o.c.find(f=>v(f.n)==="timelineStyleElements"))})))}return i}const H=(e,l)=>`<${e} type="${l.type}"${l.size?` size="${l.size}"`:""} dxfId="${l.dxfId}"/>`;function be(e,l){if(!l)return e;const i=n=>(l.slicerStyles.find(h=>h.name===n)?.elements.length??0)+(l.timelineStyles.find(h=>h.name===n)?.elements.length??0),d=`<tableStyles count="${l.tableStyles.length}" defaultTableStyle="${_(l.defaultTableStyle)}" defaultPivotStyle="${_(l.defaultPivotStyle)}"${l.tableStyles.length?`>${l.tableStyles.map(n=>`<tableStyle name="${_(n.name)}"${n.table?"":' table="0"'}${n.pivot?"":' pivot="0"'} count="${n.elements.length+i(n.name)}">${n.elements.map(h=>H("tableStyleElement",h)).join("")}</tableStyle>`).join("")}</tableStyles>`:"/>"}`;let r=e;if(/<tableStyles\b/.test(r))r=r.replace(/<tableStyles\b[^>]*?\/>|<tableStyles\b[\s\S]*?<\/tableStyles>/,()=>d);else{const n=/<(?:colors|extLst)\b|<\/styleSheet>/.exec(r);r=`${r.slice(0,n.index)}${/<dxfs\b/.test(r)?"":'<dxfs count="0"/>'}${d}${r.slice(n.index)}`}const u=n=>{r=r.replace(new RegExp(`<ext\\b[^>]*uri="${n.replace(/[{}-]/g,"\\$&")}"[^>]*>[\\s\\S]*?</ext>`),"")};u(k.slicerStyles),u(k.timelineStyles),u(j),u(U);const s=(n,h,b,m)=>m.length?`<ext uri="${n}" xmlns:${h}="${b}"><${h}:dxfs count="${m.length}">${m.join("")}</${h}:dxfs></ext>`:"",t=`${s(j,"x14",W.x14,l.slicerDxfs)}`,a=`${s(U,"x15",W.x15,l.timelineDxfs)}`,o=`<ext uri="${k.slicerStyles}" xmlns:x14="${W.x14}"><x14:slicerStyles defaultSlicerStyle="${_(l.defaultSlicerStyle)}"${l.slicerStyles.length?`>${l.slicerStyles.map(n=>`<x14:slicerStyle name="${_(n.name)}"><x14:slicerStyleElements>${n.elements.map(h=>H("x14:slicerStyleElement",h)).join("")}</x14:slicerStyleElements></x14:slicerStyle>`).join("")}</x14:slicerStyles>`:"/>"}</ext>`,f=`<ext uri="${k.timelineStyles}" xmlns:x15="${W.x15}"><x15:timelineStyles defaultTimelineStyle="${_(l.defaultTimelineStyle)}"${l.timelineStyles.length?`>${l.timelineStyles.map(n=>`<x15:timelineStyle name="${_(n.name)}"><x15:timelineStyleElements>${n.elements.map(h=>H("x15:timelineStyleElement",h)).join("")}</x15:timelineStyleElements></x15:timelineStyle>`).join("")}</x15:timelineStyles>`:"/>"}</ext>`;return/<\/extLst>\s*<\/styleSheet>/.test(r)?r=r.replace(/<\/extLst>\s*<\/styleSheet>/,n=>`${t}${o}${a}${f}${n}`):r=r.replace("</styleSheet>",()=>`<extLst>${t}${o}${a}${f}</extLst></styleSheet>`),r}const O=(e,l,i,d=e.dxfs)=>{const r=l?.elements.find(u=>u.type===i);return r?d?.[r.dxfId]??{}:null},N=e=>{const l=e?.borders;return l?l.b?.color??l.t?.color??l.l?.color??l.r?.color??null:null},ie=["fill","color","bold","italic","underline","strike"],E=(e,l)=>{if(l)for(const i of ie)l[i]!==void 0&&(e[i]=l[i])},X=(e,l,i)=>e%(l+i)<l?0:1;function ye(e,l,i){const d=l?.find(i);if(!d)return null;const r=s=>d.elements.find(t=>t.type===s)?.size??1,u=Object.fromEntries(Z.map(s=>[s,O(e,d,s)]));return se(u,[r("firstRowStripe"),r("secondRowStripe")],[r("firstColumnStripe"),r("secondColumnStripe")],!0)}function se(e,l=[1,1],i=[1,1],d=!1){const r=(t,a,o)=>{const f={},n=t.r0+t.headerRows,h=t.r1-t.totalsRows,b=a>=n&&a<=h;return E(f,e.wholeTable),b&&(t.showColumnStripes&&E(f,X(o-t.c0,i[0],i[1])===0?e.firstColumnStripe:e.secondColumnStripe),t.showRowStripes!==!1&&E(f,X(J(t,a),l[0],l[1])===0?e.firstRowStripe:e.secondRowStripe)),t.showFirstColumn&&o===t.c0&&E(f,e.firstColumn),t.showLastColumn&&o===t.c1&&E(f,e.lastColumn),a<n?(E(f,e.headerRow),o===t.c0&&t.showFirstColumn&&E(f,e.firstHeaderCell),o===t.c1&&t.showLastColumn&&E(f,e.lastHeaderCell)):a>h&&(E(f,e.totalRow),o===t.c0&&t.showFirstColumn&&E(f,e.firstTotalCell),o===t.c1&&t.showLastColumn&&E(f,e.lastTotalCell)),f},u=(t,a,o,f,n)=>{const h=[],b=(R,w,y,T,S)=>{R?.borders&&T>=w&&S>=y&&h.push({borders:R.borders,r0:w,c0:y,r1:T,c1:S})},m=t.r0+t.headerRows,c=t.r1-t.totalsRows;if(b(e.wholeTable,t.r0,t.c0,t.r1,t.c1),t.showColumnStripes&&(e.firstColumnStripe?.borders||e.secondColumnStripe?.borders)){const R=i[0]+i[1];for(let w=t.c0;w<=Math.min(t.c1,n);w+=R)b(e.firstColumnStripe,m,w,c,Math.min(t.c1,w+i[0]-1)),b(e.secondColumnStripe,m,w+i[0],c,Math.min(t.c1,w+R-1))}if(t.showRowStripes!==!1&&(e.firstRowStripe?.borders||e.secondRowStripe?.borders)){const R=l[0]+l[1],w=m+Math.floor(Math.max(0,a-m)/R)*R;for(let y=w;y<=Math.min(c,o);y+=R)b(e.firstRowStripe,y,t.c0,Math.min(c,y+l[0]-1),t.c1),b(e.secondRowStripe,y+l[0],t.c0,Math.min(c,y+R-1),t.c1)}return t.showFirstColumn&&b(e.firstColumn,t.r0,t.c0,t.r1,t.c0),t.showLastColumn&&b(e.lastColumn,t.r0,t.c1,t.r1,t.c1),t.headerRows>0&&(b(e.headerRow,t.r0,t.c0,m-1,t.c1),t.showFirstColumn&&b(e.firstHeaderCell,t.r0,t.c0,m-1,t.c0),t.showLastColumn&&b(e.lastHeaderCell,t.r0,t.c1,m-1,t.c1)),t.totalsRows>0&&(b(e.totalRow,c+1,t.c0,t.r1,t.c1),t.showFirstColumn&&b(e.firstTotalCell,c+1,t.c0,t.r1,t.c0),t.showLastColumn&&b(e.lastTotalCell,c+1,t.c1,t.r1,t.c1)),h},s=e.headerRow;return{format:r,areas:u,custom:d,headerFill:s?.fill??null,headerInk:s?.color??(s?.fill?"#FFFFFF":"#000000"),headerRule:N(s),band:e.firstRowStripe?.fill??null,rule:N(e.wholeTable)??N(e.totalRow),body:e.wholeTable?.fill??null,ink:e.wholeTable?.color??null}}const z={medium:2,mediumDashed:2,mediumDashDot:2,mediumDashDotDot:2,slantDashDot:2,thick:3,double:3};function pe(e,l,i,{ra:d,rb:r,ca:u,cb:s,xs:t,ys:a,ox:o=0,oy:f=0,line:n=1,noFill:h=!1,setInk:b}){const m=Math.max(l.r0,d),c=Math.min(l.r1,r),R=Math.max(l.c0,u),w=Math.min(l.c1,s);for(let S=h?c+1:m;S<=c;S++){const p=a[S-d],x=a[S-d+1]-p;if(x!==0)for(let L=R;L<=w;L++){const $=t[L-u],D=t[L-u+1]-$;if(D===0)continue;const{fill:C}=i.format(l,S,L);C&&(b(C),e.fillRect(o+$,f+p,D,x))}}const y=(S,p,x,L,$)=>{b(S.color);const D=z[S.style]??1,C=$?L-D*n:L;S.style==="double"?(e.fillRect(o+p,f+C,x-p,n),e.fillRect(o+p,f+C+2*n,x-p,n)):e.fillRect(o+p,f+C,x-p,D*n)},T=(S,p,x,L,$)=>{b(S.color);const D=z[S.style]??1,C=$?L-D*n:L;S.style==="double"?(e.fillRect(o+C,f+p,n,x-p),e.fillRect(o+C+2*n,f+p,n,x-p)):e.fillRect(o+C,f+p,D*n,x-p)};for(const S of i.areas(l,m,c,R,w)){if(S.r1<d||S.r0>r||S.c1<u||S.c0>s)continue;const p=Math.max(S.c0,u),x=Math.min(S.c1,s),L=Math.max(S.r0,d),$=Math.min(S.r1,r),D=t[p-u],C=t[x-u+1],P=a[L-d],M=a[$-d+1],A=S.borders;if(A.h)for(let I=L;I<$+(S.r1>$?1:0);I++){const g=a[I-d+1];g!==a[I-d]&&y(A.h,D,C,g,!0)}if(A.v)for(let I=p;I<x+(S.c1>x?1:0);I++){const g=t[I-u+1];g!==t[I-u]&&T(A.v,P,M,g,!0)}A.t&&S.r0>=d&&y(A.t,D,C,P,!1),A.b&&S.r1<=r&&y(A.b,D,C,M,!0),A.l&&S.c0>=u&&T(A.l,P,M,D,!1),A.r&&S.c1<=s&&T(A.r,P,M,C,!0)}}const oe={NONE:0,PAGE_LABEL:1,PAGE_VALUE:2,CORNER:3,HEADER_BLANK:4,COL_CAPTION:5,ROW_CAPTION:6,COL_ITEM:7,COL_SUBTOTAL:8,COL_GRAND:9,DATA_HEADER:10,ROW_ITEM:11,ROW_PARENT:12,ROW_SUBTOTAL:13,ROW_GRAND:14,DATA:15,DATA_PARENT:16,DATA_SUBTOTAL:17,DATA_GRAND_ROW:18,DATA_GRAND_COL:19,PLACEHOLDER:20},F=(e,l,i,d)=>e<=0?l:e===1?i:d;function Re(e,l,i){const d=l?.find(i);return d?ne(Object.fromEntries(ee.map(r=>[r,O(e,d,r)])),!0):null}function ne(e,l=!1){const i=oe,d=e.wholeTable?.borders&&(e.wholeTable.borders.h||e.wholeTable.borders.v)?{...e.wholeTable,borders:{b:e.wholeTable.borders.h??null,r:e.wholeTable.borders.v??null}}:e.wholeTable&&{...e.wholeTable,borders:void 0};return{patch:(u,s,t,a={},o=0)=>{const f={},n=a.colHeaders===!1?null:e.headerRow,h=a.rowHeaders===!1?null:e.firstColumn,b=a.lastColumn===!1?null:e.lastColumn,m={},c=(T,S="tb")=>{T&&(E(f,T),T.borders&&(S.includes("t")&&T.borders.t&&(m.t=T.borders.t),S.includes("b")&&T.borders.b&&(m.b=T.borders.b),S.includes("l")&&T.borders.l&&(m.l=T.borders.l),S.includes("r")&&T.borders.r&&(m.r=T.borders.r)))};u!==i.PAGE_LABEL&&u!==i.PAGE_VALUE&&c(d,"br");const R=m.b,w=m.r;switch(t&4&&c(e.firstColumnStripe,"lr"),t&8&&c(e.secondColumnStripe,"lr"),t&1&&c(e.firstRowStripe),t&2&&c(e.secondRowStripe),u){case i.PAGE_LABEL:c(e.pageFieldLabels,"tblr");break;case i.PAGE_VALUE:c(e.pageFieldValues,"tblr");break;case i.CORNER:c(n),c(h,"lr"),c(e.firstHeaderCell,"tblr");break;case i.HEADER_BLANK:case i.COL_CAPTION:case i.DATA_HEADER:c(n);break;case i.ROW_CAPTION:c(n),c(e.firstHeaderCell,"tblr");break;case i.COL_ITEM:c(n),c(F(s,e.firstColumnSubheading,e.secondColumnSubheading,e.thirdColumnSubheading));break;case i.COL_SUBTOTAL:c(n),c(F(s,e.firstSubtotalColumn,e.secondSubtotalColumn,e.thirdSubtotalColumn),"lr");break;case i.COL_GRAND:c(n),c(b,"lr");break;case i.ROW_ITEM:c(h,"lr");break;case i.ROW_PARENT:c(h,"lr"),c(F(s,e.firstRowSubheading,e.secondRowSubheading,e.thirdRowSubheading));break;case i.ROW_SUBTOTAL:c(h,"lr"),c(F(s,e.firstSubtotalRow,e.secondSubtotalRow,e.thirdSubtotalRow));break;case i.ROW_GRAND:c(h,"lr"),c(e.totalRow);break;case i.DATA_PARENT:c(F(s,e.firstRowSubheading,e.secondRowSubheading,e.thirdRowSubheading));break;case i.DATA_SUBTOTAL:c(F(s,e.firstSubtotalRow,e.secondSubtotalRow,e.thirdSubtotalRow));break;case i.DATA_GRAND_ROW:c(e.totalRow);break;case i.DATA_GRAND_COL:c(b,"lr");break;case i.PLACEHOLDER:c(e.blankRow);break;default:}const y=e.wholeTable?.borders;return y&&o&&(o&1&&y.t&&!m.t&&(m.t=y.t),o&2&&y.b&&(!m.b||m.b===R)&&(m.b=y.b),o&4&&y.l&&!m.l&&(m.l=y.l),o&8&&y.r&&(!m.r||m.r===w)&&(m.r=y.r)),Object.keys(m).length&&(f.borders=m),f},stripe:e.firstRowStripe?.fill??null,custom:l,header:{},sub:{},grand:{},parent:{},page:{}}}function Te(e,l,i,d){const r=l?.slicerStyles.find(n=>n.name===i),u=l?.find(i);if(!r&&!u)return null;const s={...d},t=O(e,u,"wholeTable"),a=O(e,u,"headerRow");t?.fill&&(s.frameFill=t.fill),t?.color&&(s.ink=t.color);const o=N(t);o&&(s.frameLine=o),a?.color&&(s.captionInk=a.color),a?.fill&&(s.captionFill=a.fill);const f=(n,h,b,m)=>{const c=O(e,r,n,l.slicerDxfs);if(!c)return;c.fill&&(s[h]=c.fill),c.color&&(s[b]=c.color);const R=N(c);R&&m&&(s[m]=R)};return f("selectedItemWithData","selFill","selInk","selLine"),f("unselectedItemWithData","fill","itemInk","itemLine"),f("selectedItemWithNoData","selNoFill","selNoInk"),f("unselectedItemWithNoData","noFill","noInk"),s.hoverSelFill=s.selFill,s.hoverSelInk=s.selInk,s.hoverFill=s.fill,s.hoverInk=s.itemInk,f("hoveredSelectedItemWithData","hoverSelFill","hoverSelInk"),f("hoveredUnselectedItemWithData","hoverFill","hoverInk"),s}function we(e,l,i,d){const r=l?.timelineStyles.find(h=>h.name===i),u=l?.find(i);if(!r&&!u)return null;const s={...d},t=O(e,u,"wholeTable"),a=O(e,u,"headerRow");t?.fill&&(s.frameFill=t.fill);const o=N(t);o&&(s.frameLine=o),a?.color&&(s.captionInk=a.color);const f=(h,b)=>{const m=O(e,r,h,l.timelineDxfs);m?.fill&&(s[b]=m.fill)},n=(h,b)=>{const m=O(e,r,h,l.timelineDxfs);m?.color&&(s[b]=m.color)};return f("selectedTimeBlock","selFill"),f("unselectedTimeBlock","blockFill"),f("selectedTimeBlockSpace","selSpaceFill"),n("selectionLabel","labelInk"),n("timeLevel","levelInk"),n("periodLabel1","periodInk"),n("periodLabel2","subPeriodInk"),s}export{te as CustomStyles,ee as PIVOT_ELEMENTS,me as SLICER_ELEMENTS,Z as TABLE_ELEMENTS,Se as TIMELINE_ELEMENTS,le as addDxf,Re as customPivotPattern,Te as customSlicerColors,ye as customTableColors,we as customTimelineColors,ne as elementPivotPattern,se as elementTableColors,pe as paintCustomTable,he as parseCustomStyles,be as patchCustomStyles};
|
package/slicers/format.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{parseNode as p}from"../pivot/xml.js";import{xmlAttr as A}from"../io/xml-escape.js";import{unescapeXstring as I}from"../io/xml-scan.js";const a={main:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",r:"http://schemas.openxmlformats.org/officeDocument/2006/relationships",mc:"http://schemas.openxmlformats.org/markup-compatibility/2006",x14:"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",x15:"http://schemas.microsoft.com/office/spreadsheetml/2010/11/main",xr10:"http://schemas.microsoft.com/office/spreadsheetml/2016/revision10",xdr:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",a:"http://schemas.openxmlformats.org/drawingml/2006/main",a14:"http://schemas.microsoft.com/office/drawing/2010/main",sle:"http://schemas.microsoft.com/office/drawing/2010/slicer",sle15:"http://schemas.microsoft.com/office/drawing/2012/slicer",tsle:"http://schemas.microsoft.com/office/drawing/2012/timeslicer"},k={slicerCache:"http://schemas.microsoft.com/office/2007/relationships/slicerCache",slicer:"http://schemas.microsoft.com/office/2007/relationships/slicer",timelineCache:"http://schemas.microsoft.com/office/2011/relationships/timelineCache",timeline:"http://schemas.microsoft.com/office/2011/relationships/timeline",drawing:`${a.r}/drawing`},H={slicerCache:"application/vnd.ms-excel.slicerCache+xml",slicer:"application/vnd.ms-excel.slicer+xml",timelineCache:"application/vnd.ms-excel.timelineCache+xml",timeline:"application/vnd.ms-excel.timeline+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml"},h={wbPivotSlicerCaches:"{BBE1A952-AA13-448e-AADC-164F8A28A991}",wbTableSlicerCaches:"{46BE6895-7355-4a93-B00E-2C351335B9C9}",wbTimelineCaches:"{D0CA8CA8-9F24-4464-BF8E-62219DCF47F9}",wsPivotSlicers:"{A8765BA9-456A-4dab-B4F3-ACF838C121DE}",wsTableSlicers:"{3A4CF648-6AED-40f4-86FF-DC5316D8AED3}",wsTimelines:"{7E03D99C-DC04-49d9-9315-930204A7B6E9}",tableSlicerCache:"{2F2917AC-EB37-4324-AD4E-5DD8C200BD13}",hideNoData:"{470722E0-AACD-4C17-9CDC-17EF765DBC7E}",pivotCacheId:"{725AE2AE-9491-48be-B2B4-4EB974FC3084}",slicerStyles:"{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}",timelineStyles:"{9260A510-F301-46a8-8635-F512D64BE5F5}"},X=t=>`@@TAB${t}@@`,b=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
-
`,C=A,u=t=>Object.entries(t).filter(([,i])=>i!=null).map(([i,e])=>` ${i}="${C(e)}"`).join(""),f=(t,i)=>t?.c?.find(e=>e.n===i)??null,v=(t,i)=>t?t.c.filter(e=>e.n===i):[],$=t=>t.slice(t.indexOf(":")+1),x=(t,i)=>t===void 0?i:t==="1"||t==="true";function M(t){const i=u({name:t.name,"xr10:uid":t.uid??void 0,sourceName:t.sourceName,...t.extra??{}}),e=`${b}<slicerCacheDefinition xmlns="${a.x14}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}"${i}>`,n={sortOrder:t.sortOrder&&t.sortOrder!=="ascending"?t.sortOrder:void 0,customListSort:t.customListSort===!1?"0":void 0,crossFilter:t.crossFilter&&t.crossFilter!=="showItemsWithDataAtTop"?t.crossFilter:void 0},r=[];let o="";if(t.kind==="table")r.push(`<x:ext uri="${h.tableSlicerCache}" xmlns:x15="${a.x15}"><x15:tableSlicerCache${u({tableId:t.tableId,column:t.column,...n})}/></x:ext>`);else{const l=(t.pivotTables??[]).map(c=>`<pivotTable${u({tabId:c.tabId,name:c.name})}/>`).join("");o+=`<pivotTables>${l}</pivotTables>`;const m=(t.items??[]).map(c=>`<i${u({x:c.x,s:c.s?"1":void 0,nd:c.nd?"1":void 0})}/>`).join(""),s={pivotCacheId:t.pivotCacheId,...n,showMissing:t.showMissing===!1?"0":void 0};o+=`<data><tabular${u(s)}><items count="${(t.items??[]).length}">${m}</items></tabular></data>`}t.hideNoData&&r.push(`<x:ext uri="${h.hideNoData}" xmlns:x15="${a.x15}"><x15:slicerCacheHideItemsWithNoData/></x:ext>`);for(const l of t.rawExt??[])r.push(l);return`${e}${o}${r.length?`<extLst>${r.join("")}</extLst>`:""}</slicerCacheDefinition>`}function j(t){const i=e=>{const n={name:e.name,"xr10:uid":e.uid??void 0,cache:e.cache,caption:e.caption,startItem:e.startItem?e.startItem:void 0,columnCount:e.columnCount&&e.columnCount!==1?e.columnCount:void 0,showCaption:e.showCaption===!1?"0":void 0,level:e.level?e.level:void 0,style:e.style&&e.style!=="SlicerStyleLight1"?e.style:void 0,lockedPosition:e.lockedPosition?"1":void 0,rowHeight:e.rowHeight??241300,...e.extra??{}};return`<slicer${u(n)}/>`};return`${b}<slicers xmlns="${a.x14}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}">${t.map(i).join("")}</slicers>`}function z(t){const i=(t.pivotTables??[]).map(r=>`<pivotTable${u({tabId:r.tabId,name:r.name})}/>`).join(""),e=(r,o)=>o?`<${r}${u({startDate:o.start,endDate:o.end})}/>`:"",n=u({singleRangeFilterState:t.singleRange===!1?"0":void 0,minimalRefreshVersion:t.minimalRefreshVersion??6,lastRefreshVersion:t.lastRefreshVersion??6,pivotCacheId:t.pivotCacheId,filterType:t.selection?"dateBetween":"unknown",filterId:t.selection?t.filterId:void 0,filterTabId:t.selection?t.filterTabId:void 0,filterPivotName:t.selection?t.filterPivotName:void 0});return`${b}<timelineCacheDefinition xmlns="${a.x15}" xmlns:x15="${a.x15}" xmlns:mc="${a.mc}" mc:Ignorable="xr10" xmlns:xr10="${a.xr10}"${u({name:t.name,"xr10:uid":t.uid??void 0,sourceName:t.sourceName,...t.extra??{}})}><pivotTables>${i}</pivotTables><state${n}>${e("selection",t.selection)}${e("bounds",t.bounds)}</state></timelineCacheDefinition>`}function V(t){const i=e=>`<timeline${u({name:e.name,"xr10:uid":e.uid??void 0,cache:e.cache,caption:e.caption,showHeader:e.showHeader===!1?"0":void 0,showSelectionLabel:e.showSelectionLabel===!1?"0":void 0,showTimeLevel:e.showTimeLevel===!1?"0":void 0,showHorizontalScrollbar:e.showHorizontalScrollbar===!1?"0":void 0,level:e.level??2,selectionLevel:e.selectionLevel??e.level??2,scrollPosition:e.scrollPosition??void 0,style:e.style&&e.style!=="TimeSlicerStyleLight1"?e.style:void 0,...e.extra??{}})}/>`;return`${b}<timelines xmlns="${a.x15}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}">${t.map(i).join("")}</timelines>`}const E={pivot:{choice:`xmlns:a14="${a.a14}" Requires="a14"`,uri:a.sle,inner:t=>`<sle:slicer xmlns:sle="${a.sle}" name="${C(t)}"/>`},table:{choice:`xmlns:sle15="${a.sle15}" Requires="sle15"`,uri:a.sle,inner:t=>`<sle:slicer xmlns:sle="${a.sle}" name="${C(t)}"/>`},timeline:{choice:`xmlns:tsle="${a.tsle}" Requires="tsle"`,uri:a.tsle,inner:t=>`<tsle:timeslicer xmlns:tsle="${a.tsle}" name="${C(t)}"/>`}},L={pivot:"This shape represents a slicer. Slicers are supported in Excel 2010 or later.",table:"This shape represents a table slicer. Table slicers are supported in Excel 2013 or later.",timeline:"Timeline: Works in Excel 2013 or higher. Do not move or resize."};function W({kind:t,name:i,id:e,from:n,to:r,cx:o=1828800,cy:l=2524125}){const m=E[t],s=(c,d)=>`<xdr:${c}><xdr:col>${d.col}</xdr:col><xdr:colOff>${d.colOff}</xdr:colOff><xdr:row>${d.row}</xdr:row><xdr:rowOff>${d.rowOff}</xdr:rowOff></xdr:${c}>`;return`<xdr:twoCellAnchor editAs="absolute">${s("from",n)}${s("to",r)}<mc:AlternateContent xmlns:mc="${a.mc}"><mc:Choice ${m.choice}><xdr:graphicFrame macro=""><xdr:nvGraphicFramePr><xdr:cNvPr id="${e}" name="${C(i)}"/><xdr:cNvGraphicFramePr/></xdr:nvGraphicFramePr><xdr:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/></xdr:xfrm><a:graphic><a:graphicData uri="${m.uri}">${m.inner(i)}</a:graphicData></a:graphic></xdr:graphicFrame></mc:Choice><mc:Fallback xmlns=""><xdr:sp macro="" textlink=""><xdr:nvSpPr><xdr:cNvPr id="0" name=""/><xdr:cNvSpPr><a:spLocks noTextEdit="1"/></xdr:cNvSpPr></xdr:nvSpPr><xdr:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${o}" cy="${l}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:solidFill><a:prstClr val="white"/></a:solidFill><a:ln w="1"><a:solidFill><a:prstClr val="green"/></a:solidFill></a:ln></xdr:spPr><xdr:txBody><a:bodyPr vertOverflow="clip" horzOverflow="clip"/><a:lstStyle/><a:p><a:r><a:rPr lang="en-US" sz="1100"/><a:t>${L[t]}</a:t></a:r></a:p></xdr:txBody></xdr:sp></mc:Fallback></mc:AlternateContent><xdr:clientData/></xdr:twoCellAnchor>`}const _=t=>`${b}<xdr:wsDr xmlns:xdr="${a.xdr}" xmlns:a="${a.a}">${t}</xdr:wsDr>`,D=/<xdr:(twoCellAnchor|oneCellAnchor|absoluteAnchor)\b[\s\S]*?<\/xdr:\1>/g,S=/<(?:\w+:)?(slicer|timeslicer)\b[^>]*\bname="([^"]*)"/;function G(t){const i=[];for(const e of t.matchAll(D)){const n=e[0];if(!/drawing\/20(?:10|12)\/(?:time)?slicer/.test(n))continue;const r=S.exec(n);if(!r)continue;const o=m=>{const s=new RegExp(`<xdr:${m}>\\s*<xdr:col>(\\d+)</xdr:col>\\s*<xdr:colOff>(-?\\d+)</xdr:colOff>\\s*<xdr:row>(\\d+)</xdr:row>\\s*<xdr:rowOff>(-?\\d+)</xdr:rowOff>`).exec(n);return s?{col:Number(s[1]),colOff:Number(s[2]),row:Number(s[3]),rowOff:Number(s[4])}:null},l=(m,s,c)=>{const d=new RegExp(`<xdr:${m}\\b[^>]*>`).exec(n)?.[0];if(d===void 0)return null;const w=F=>Number(new RegExp(`\\b${F}="(-?\\d+)"`).exec(d)?.[1]),g=w(s),N=w(c);return Number.isFinite(g)&&Number.isFinite(N)?{[s]:g,[c]:N}:null};i.push({kind:r[1]==="timeslicer"?"timeline":/Requires="sle15"/.test(n)?"table":"pivot",name:I(r[2]),id:Number(/<xdr:cNvPr\b[^>]*\bid="(\d+)"/.exec(n)?.[1]??0),from:o("from"),to:o("to"),pos:e[1]==="absoluteAnchor"?l("pos","x","y"):null,ext:e[1]==="twoCellAnchor"?null:l("ext","cx","cy"),raw:n})}return i}function q(t,{upsert:i=[],remove:e=[]}){const n=new Map(i.map(s=>[s.name,s.xml])),r=new Set(e),o=new Set;let l=t.replace(D,s=>{if(!/drawing\/20(?:10|12)\/(?:time)?slicer/.test(s))return s;const c=S.exec(s);if(!c)return s;const d=I(c[2]);return r.has(d)?"":n.has(d)?(o.add(d),n.get(d)):s});const m=i.filter(s=>!o.has(s.name)).map(s=>s.xml).join("");return m&&(l=l.replace(/<\/(\w+:)?wsDr>\s*$/,s=>`${m}${s}`)),l}const y=new Set(["name","xr10:uid","cache","caption","startItem","columnCount","showCaption","level","style","lockedPosition","rowHeight"]),P=new Set(["name","xr10:uid","cache","caption","showHeader","showSelectionLabel","showTimeLevel","showHorizontalScrollbar","level","selectionLevel","scrollPosition","style"]),T=(t,i)=>{const e={};for(const[n,r]of Object.entries(t))!i.has(n)&&!n.startsWith("xmlns")&&n!=="mc:Ignorable"&&(e[n]=r);return e};function K(t){const i=p(t),e={name:i.a.name,sourceName:i.a.sourceName,uid:i.a["xr10:uid"]??null,kind:"pivot",sortOrder:"ascending",customListSort:!0,crossFilter:"showItemsWithDataAtTop",showMissing:!0,hideNoData:!1,pivotTables:[],items:[],pivotCacheId:null,tableId:null,column:null},n=o=>{o.sortOrder&&(e.sortOrder=o.sortOrder),e.customListSort=x(o.customListSort,!0),o.crossFilter&&(e.crossFilter=o.crossFilter)};for(const o of v(f(i,"pivotTables"),"pivotTable"))e.pivotTables.push({tabId:Number(o.a.tabId),name:o.a.name});const r=f(f(i,"data"),"tabular");if(r){e.pivotCacheId=Number(r.a.pivotCacheId),n(r.a),e.showMissing=x(r.a.showMissing,!0);for(const o of v(f(r,"items"),"i"))e.items.push({x:Number(o.a.x),s:x(o.a.s,!1),nd:x(o.a.nd,!1)})}for(const o of f(i,"extLst")?.c??[])if($(o.n)==="ext")if(o.a.uri===h.tableSlicerCache){const l=o.c.find(m=>$(m.n)==="tableSlicerCache");l&&(e.kind="table",e.tableId=Number(l.a.tableId),e.column=Number(l.a.column),n(l.a))}else o.a.uri===h.hideNoData&&(e.hideNoData=!0);return e}function U(t){const i=p(t);return v(i,"slicer").map(e=>({name:e.a.name,uid:e.a["xr10:uid"]??null,cache:e.a.cache,caption:e.a.caption??e.a.name,startItem:Number(e.a.startItem??0),columnCount:Number(e.a.columnCount??1),showCaption:x(e.a.showCaption,!0),level:Number(e.a.level??0),style:e.a.style??"SlicerStyleLight1",lockedPosition:x(e.a.lockedPosition,!1),rowHeight:Number(e.a.rowHeight??241300),extra:T(e.a,y)}))}function J(t){const i=p(t),e=f(i,"state"),n=r=>{const o=f(e,r);return o?{start:o.a.startDate,end:o.a.endDate}:null};return{name:i.a.name,sourceName:i.a.sourceName,uid:i.a["xr10:uid"]??null,pivotTables:v(f(i,"pivotTables"),"pivotTable").map(r=>({tabId:Number(r.a.tabId),name:r.a.name})),singleRange:x(e?.a.singleRangeFilterState,!0),minimalRefreshVersion:Number(e?.a.minimalRefreshVersion??6),lastRefreshVersion:Number(e?.a.lastRefreshVersion??6),pivotCacheId:Number(e?.a.pivotCacheId??0),filterType:e?.a.filterType??"unknown",filterId:e?.a.filterId!==void 0?Number(e.a.filterId):null,filterTabId:e?.a.filterTabId!==void 0?Number(e.a.filterTabId):null,filterPivotName:e?.a.filterPivotName??null,selection:n("selection"),bounds:n("bounds")}}function Q(t){const i=p(t);return v(i,"timeline").map(e=>({name:e.a.name,uid:e.a["xr10:uid"]??null,cache:e.a.cache,caption:e.a.caption??e.a.name,showHeader:x(e.a.showHeader,!0),showSelectionLabel:x(e.a.showSelectionLabel,!0),showTimeLevel:x(e.a.showTimeLevel,!0),showHorizontalScrollbar:x(e.a.showHorizontalScrollbar,!0),level:Number(e.a.level??2),selectionLevel:Number(e.a.selectionLevel??e.a.level??2),scrollPosition:e.a.scrollPosition??null,style:e.a.style??"TimeSlicerStyleLight1",extra:T(e.a,P)}))}function Y(t){const i=p(t);for(const e of f(i,"extLst")?.c??[]){if(e.a.uri!==h.pivotCacheId)continue;const n=e.c.find(r=>$(r.n)==="pivotCacheDefinition");if(n?.a.pivotCacheId!==void 0)return Number(n.a.pivotCacheId)}return null}function Z(t,i){const e=`<ext uri="${h.pivotCacheId}" xmlns:x14="${a.x14}"><x14:pivotCacheDefinition pivotCacheId="${i}"/></ext>`;return t.includes(h.pivotCacheId)?t.replace(/(<x14:pivotCacheDefinition\b[^>]*\bpivotCacheId=")\d+/,`$1${i}`):/<extLst>/.test(t)?t.replace(/<extLst>/,`<extLst>${e}`):t.replace("</pivotCacheDefinition>",`<extLst>${e}</extLst></pivotCacheDefinition>`)}import{isoToSerial as ie,serialToIso as oe}from"../pivot/xml.js";export{H as CT,h as EXT,a as NS,k as REL,b as XML_HEAD,W as frameXml,ie as isoToSerial,_ as newDrawingXml,G as parseFrames,K as parseSlicerCacheXml,U as parseSlicersXml,J as parseTimelineCacheXml,Q as parseTimelinesXml,q as patchDrawingFrames,Y as pivotCacheExtId,oe as serialToIso,Z as setPivotCacheExtId,M as slicerCacheXml,j as slicersXml,X as tabPlaceholder,z as timelineCacheXml,V as timelinesXml};
|
|
2
|
+
`,C=A,u=t=>Object.entries(t).filter(([,i])=>i!=null).map(([i,e])=>` ${i}="${C(e)}"`).join(""),f=(t,i)=>t?.c?.find(e=>e.n===i)??null,v=(t,i)=>t?t.c.filter(e=>e.n===i):[],$=t=>t.slice(t.indexOf(":")+1),x=(t,i)=>t===void 0?i:t==="1"||t==="true";function M(t){const i=u({name:t.name,"xr10:uid":t.uid??void 0,sourceName:t.sourceName,...t.extra??{}}),e=`${b}<slicerCacheDefinition xmlns="${a.x14}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}"${i}>`,n={sortOrder:t.sortOrder&&t.sortOrder!=="ascending"?t.sortOrder:void 0,customListSort:t.customListSort===!1?"0":void 0,crossFilter:t.crossFilter&&t.crossFilter!=="showItemsWithDataAtTop"?t.crossFilter:void 0},r=[];let o="";if(t.kind==="table")r.push(`<x:ext uri="${h.tableSlicerCache}" xmlns:x15="${a.x15}"><x15:tableSlicerCache${u({tableId:t.tableId,column:t.column,...n})}/></x:ext>`);else{const l=(t.pivotTables??[]).map(c=>`<pivotTable${u({tabId:c.tabId,name:c.name})}/>`).join("");o+=`<pivotTables>${l}</pivotTables>`;const m=(t.items??[]).map(c=>`<i${u({x:c.x,s:c.s?"1":void 0,nd:c.nd?"1":void 0})}/>`).join(""),s={pivotCacheId:t.pivotCacheId,...n,showMissing:t.showMissing===!1?"0":void 0};o+=`<data><tabular${u(s)}><items count="${(t.items??[]).length}">${m}</items></tabular></data>`}t.hideNoData&&r.push(`<x:ext uri="${h.hideNoData}" xmlns:x15="${a.x15}"><x15:slicerCacheHideItemsWithNoData/></x:ext>`);for(const l of t.rawExt??[])r.push(l);return`${e}${o}${r.length?`<extLst>${r.join("")}</extLst>`:""}</slicerCacheDefinition>`}function j(t){const i=e=>{const n={name:e.name,"xr10:uid":e.uid??void 0,cache:e.cache,caption:e.caption,startItem:e.startItem?e.startItem:void 0,columnCount:e.columnCount&&e.columnCount!==1?e.columnCount:void 0,showCaption:e.showCaption===!1?"0":void 0,level:e.level?e.level:void 0,style:e.style&&e.style!=="SlicerStyleLight1"?e.style:void 0,lockedPosition:e.lockedPosition?"1":void 0,rowHeight:e.rowHeight??241300,...e.extra??{}};return`<slicer${u(n)}/>`};return`${b}<slicers xmlns="${a.x14}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}">${t.map(i).join("")}</slicers>`}function z(t){const i=(t.pivotTables??[]).map(r=>`<pivotTable${u({tabId:r.tabId,name:r.name})}/>`).join(""),e=(r,o)=>o?`<${r}${u({startDate:o.start,endDate:o.end})}/>`:"",n=u({singleRangeFilterState:t.singleRange===!1?"0":void 0,minimalRefreshVersion:t.minimalRefreshVersion??6,lastRefreshVersion:t.lastRefreshVersion??6,pivotCacheId:t.pivotCacheId,filterType:t.selection?"dateBetween":"unknown",filterId:t.selection?t.filterId:void 0,filterTabId:t.selection?t.filterTabId:void 0,filterPivotName:t.selection?t.filterPivotName:void 0});return`${b}<timelineCacheDefinition xmlns="${a.x15}" xmlns:x15="${a.x15}" xmlns:mc="${a.mc}" mc:Ignorable="xr10" xmlns:xr10="${a.xr10}"${u({name:t.name,"xr10:uid":t.uid??void 0,sourceName:t.sourceName,...t.extra??{}})}><pivotTables>${i}</pivotTables><state${n}>${e("selection",t.selection)}${e("bounds",t.bounds)}</state></timelineCacheDefinition>`}function V(t){const i=e=>`<timeline${u({name:e.name,"xr10:uid":e.uid??void 0,cache:e.cache,caption:e.caption,showHeader:e.showHeader===!1?"0":void 0,showSelectionLabel:e.showSelectionLabel===!1?"0":void 0,showTimeLevel:e.showTimeLevel===!1?"0":void 0,showHorizontalScrollbar:e.showHorizontalScrollbar===!1?"0":void 0,level:e.level??2,selectionLevel:e.selectionLevel??e.level??2,scrollPosition:e.scrollPosition??void 0,style:e.style&&e.style!=="TimeSlicerStyleLight1"?e.style:void 0,...e.extra??{}})}/>`;return`${b}<timelines xmlns="${a.x15}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}">${t.map(i).join("")}</timelines>`}const E={pivot:{choice:`xmlns:a14="${a.a14}" Requires="a14"`,uri:a.sle,inner:t=>`<sle:slicer xmlns:sle="${a.sle}" name="${C(t)}"/>`},table:{choice:`xmlns:sle15="${a.sle15}" Requires="sle15"`,uri:a.sle,inner:t=>`<sle:slicer xmlns:sle="${a.sle}" name="${C(t)}"/>`},timeline:{choice:`xmlns:tsle="${a.tsle}" Requires="tsle"`,uri:a.tsle,inner:t=>`<tsle:timeslicer xmlns:tsle="${a.tsle}" name="${C(t)}"/>`}},L={pivot:"This shape represents a slicer. Slicers are supported in Excel 2010 or later.",table:"This shape represents a table slicer. Table slicers are supported in Excel 2013 or later.",timeline:"Timeline: Works in Excel 2013 or higher. Do not move or resize."};function W({kind:t,name:i,id:e,from:n,to:r,cx:o=1828800,cy:l=2524125}){const m=E[t],s=(c,d)=>`<xdr:${c}><xdr:col>${d.col}</xdr:col><xdr:colOff>${d.colOff}</xdr:colOff><xdr:row>${d.row}</xdr:row><xdr:rowOff>${d.rowOff}</xdr:rowOff></xdr:${c}>`;return`<xdr:twoCellAnchor editAs="absolute">${s("from",n)}${s("to",r)}<mc:AlternateContent xmlns:mc="${a.mc}"><mc:Choice ${m.choice}><xdr:graphicFrame macro=""><xdr:nvGraphicFramePr><xdr:cNvPr id="${e}" name="${C(i)}"/><xdr:cNvGraphicFramePr/></xdr:nvGraphicFramePr><xdr:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/></xdr:xfrm><a:graphic><a:graphicData uri="${m.uri}">${m.inner(i)}</a:graphicData></a:graphic></xdr:graphicFrame></mc:Choice><mc:Fallback xmlns=""><xdr:sp macro="" textlink=""><xdr:nvSpPr><xdr:cNvPr id="0" name=""/><xdr:cNvSpPr><a:spLocks noTextEdit="1"/></xdr:cNvSpPr></xdr:nvSpPr><xdr:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${o}" cy="${l}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:solidFill><a:prstClr val="white"/></a:solidFill><a:ln w="1"><a:solidFill><a:prstClr val="green"/></a:solidFill></a:ln></xdr:spPr><xdr:txBody><a:bodyPr vertOverflow="clip" horzOverflow="clip"/><a:lstStyle/><a:p><a:r><a:rPr lang="en-US" sz="1100"/><a:t>${L[t]}</a:t></a:r></a:p></xdr:txBody></xdr:sp></mc:Fallback></mc:AlternateContent><xdr:clientData/></xdr:twoCellAnchor>`}const _=t=>`${b}<xdr:wsDr xmlns:xdr="${a.xdr}" xmlns:a="${a.a}">${t}</xdr:wsDr>`,D=/<xdr:(twoCellAnchor|oneCellAnchor|absoluteAnchor)\b[\s\S]*?<\/xdr:\1>/g,S=/<(?:\w+:)?(slicer|timeslicer)\b[^>]*\bname="([^"]*)"/;function G(t){const i=[];for(const e of t.matchAll(D)){const n=e[0];if(!/drawing\/20(?:10|12)\/(?:time)?slicer/.test(n))continue;const r=S.exec(n);if(!r)continue;const o=m=>{const s=new RegExp(`<xdr:${m}>\\s*<xdr:col>(\\d+)</xdr:col>\\s*<xdr:colOff>(-?\\d+)</xdr:colOff>\\s*<xdr:row>(\\d+)</xdr:row>\\s*<xdr:rowOff>(-?\\d+)</xdr:rowOff>`).exec(n);return s?{col:Number(s[1]),colOff:Number(s[2]),row:Number(s[3]),rowOff:Number(s[4])}:null},l=(m,s,c)=>{const d=new RegExp(`<xdr:${m}\\b[^>]*>`).exec(n)?.[0];if(d===void 0)return null;const w=F=>Number(new RegExp(`\\b${F}="(-?\\d+)"`).exec(d)?.[1]),g=w(s),N=w(c);return Number.isFinite(g)&&Number.isFinite(N)?{[s]:g,[c]:N}:null};i.push({kind:r[1]==="timeslicer"?"timeline":/Requires="sle15"/.test(n)?"table":"pivot",name:I(r[2]),id:Number(/<xdr:cNvPr\b[^>]*\bid="(\d+)"/.exec(n)?.[1]??0),from:o("from"),to:o("to"),pos:e[1]==="absoluteAnchor"?l("pos","x","y"):null,ext:e[1]==="twoCellAnchor"?null:l("ext","cx","cy"),raw:n})}return i}function q(t,{upsert:i=[],remove:e=[]}){const n=new Map(i.map(s=>[s.name,s.xml])),r=new Set(e),o=new Set;let l=t.replace(D,s=>{if(!/drawing\/20(?:10|12)\/(?:time)?slicer/.test(s))return s;const c=S.exec(s);if(!c)return s;const d=I(c[2]);return r.has(d)?"":n.has(d)?(o.add(d),n.get(d)):s});const m=i.filter(s=>!o.has(s.name)).map(s=>s.xml).join("");return m&&(l=l.replace(/<\/(\w+:)?wsDr>\s*$/,s=>`${m}${s}`)),l}const y=new Set(["name","xr10:uid","cache","caption","startItem","columnCount","showCaption","level","style","lockedPosition","rowHeight"]),P=new Set(["name","xr10:uid","cache","caption","showHeader","showSelectionLabel","showTimeLevel","showHorizontalScrollbar","level","selectionLevel","scrollPosition","style"]),T=(t,i)=>{const e={};for(const[n,r]of Object.entries(t))!i.has(n)&&!n.startsWith("xmlns")&&n!=="mc:Ignorable"&&(e[n]=r);return e};function K(t){const i=p(t),e={name:i.a.name,sourceName:i.a.sourceName,uid:i.a["xr10:uid"]??null,kind:"pivot",sortOrder:"ascending",customListSort:!0,crossFilter:"showItemsWithDataAtTop",showMissing:!0,hideNoData:!1,pivotTables:[],items:[],pivotCacheId:null,tableId:null,column:null},n=o=>{o.sortOrder&&(e.sortOrder=o.sortOrder),e.customListSort=x(o.customListSort,!0),o.crossFilter&&(e.crossFilter=o.crossFilter)};for(const o of v(f(i,"pivotTables"),"pivotTable"))e.pivotTables.push({tabId:Number(o.a.tabId),name:o.a.name});const r=f(f(i,"data"),"tabular");if(r){e.pivotCacheId=Number(r.a.pivotCacheId),n(r.a),e.showMissing=x(r.a.showMissing,!0);for(const o of v(f(r,"items"),"i"))e.items.push({x:Number(o.a.x),s:x(o.a.s,!1),nd:x(o.a.nd,!1)})}for(const o of f(i,"extLst")?.c??[])if($(o.n)==="ext")if(o.a.uri===h.tableSlicerCache){const l=o.c.find(m=>$(m.n)==="tableSlicerCache");l&&(e.kind="table",e.tableId=Number(l.a.tableId),e.column=Number(l.a.column),n(l.a))}else o.a.uri===h.hideNoData&&(e.hideNoData=!0);return e}function U(t){const i=p(t);return v(i,"slicer").map(e=>({name:e.a.name,uid:e.a["xr10:uid"]??null,cache:e.a.cache,caption:e.a.caption??e.a.name,startItem:Number(e.a.startItem??0),columnCount:Number(e.a.columnCount??1),showCaption:x(e.a.showCaption,!0),level:Number(e.a.level??0),style:e.a.style??"SlicerStyleLight1",lockedPosition:x(e.a.lockedPosition,!1),rowHeight:Number(e.a.rowHeight??241300),extra:T(e.a,y)}))}function J(t){const i=p(t),e=f(i,"state"),n=r=>{const o=f(e,r);return o?{start:o.a.startDate,end:o.a.endDate}:null};return{name:i.a.name,sourceName:i.a.sourceName,uid:i.a["xr10:uid"]??null,pivotTables:v(f(i,"pivotTables"),"pivotTable").map(r=>({tabId:Number(r.a.tabId),name:r.a.name})),singleRange:x(e?.a.singleRangeFilterState,!0),minimalRefreshVersion:Number(e?.a.minimalRefreshVersion??6),lastRefreshVersion:Number(e?.a.lastRefreshVersion??6),pivotCacheId:Number(e?.a.pivotCacheId??0),filterType:e?.a.filterType??"unknown",filterId:e?.a.filterId!==void 0?Number(e.a.filterId):null,filterTabId:e?.a.filterTabId!==void 0?Number(e.a.filterTabId):null,filterPivotName:e?.a.filterPivotName??null,selection:n("selection"),bounds:n("bounds")}}function Q(t){const i=p(t);return v(i,"timeline").map(e=>({name:e.a.name,uid:e.a["xr10:uid"]??null,cache:e.a.cache,caption:e.a.caption??e.a.name,showHeader:x(e.a.showHeader,!0),showSelectionLabel:x(e.a.showSelectionLabel,!0),showTimeLevel:x(e.a.showTimeLevel,!0),showHorizontalScrollbar:x(e.a.showHorizontalScrollbar,!0),level:Number(e.a.level??2),selectionLevel:Number(e.a.selectionLevel??e.a.level??2),scrollPosition:e.a.scrollPosition??null,style:e.a.style??"TimeSlicerStyleLight1",extra:T(e.a,P)}))}function Y(t){const i=p(t);for(const e of f(i,"extLst")?.c??[]){if(e.a.uri!==h.pivotCacheId)continue;const n=e.c.find(r=>$(r.n)==="pivotCacheDefinition");if(n?.a.pivotCacheId!==void 0)return Number(n.a.pivotCacheId)}return null}function Z(t,i){const e=`<ext uri="${h.pivotCacheId}" xmlns:x14="${a.x14}"><x14:pivotCacheDefinition pivotCacheId="${i}"/></ext>`;return t.includes(h.pivotCacheId)?t.replace(/(<x14:pivotCacheDefinition\b[^>]*\bpivotCacheId=")\d+/,`$1${i}`):/<extLst>/.test(t)?t.replace(/<extLst>/,()=>`<extLst>${e}`):t.replace("</pivotCacheDefinition>",()=>`<extLst>${e}</extLst></pivotCacheDefinition>`)}import{isoToSerial as ie,serialToIso as oe}from"../pivot/xml.js";export{H as CT,h as EXT,a as NS,k as REL,b as XML_HEAD,W as frameXml,ie as isoToSerial,_ as newDrawingXml,G as parseFrames,K as parseSlicerCacheXml,U as parseSlicersXml,J as parseTimelineCacheXml,Q as parseTimelinesXml,q as patchDrawingFrames,Y as pivotCacheExtId,oe as serialToIso,Z as setPivotCacheExtId,M as slicerCacheXml,j as slicersXml,X as tabPlaceholder,z as timelineCacheXml,V as timelinesXml};
|
package/slicers/structured.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function C(t,h,r){const{r0:s,c0:a,r1:o,c1:e,headerRows:
|
|
1
|
+
function C(t,h,r){const{r0:s,c0:a,r1:o,c1:e,headerRows:i,totalsRows:d,columns:m}=t,T=s+i,E=o-d;let f=h.slice(1,-1),g=!1;f.trimStart()[0]==="@"&&(g=!0,f=f.trimStart().slice(1));const L=[];if(f.trim()!=="")if(f.trimStart()[0]==="["){const c=/\[((?:[^\]']|'.)*)\]/g;let l;for(;(l=c.exec(f))!==null;)L.push(l[1])}else L.push(f);const u=new Set,p=[];for(const c of L){const l=c.replace(/'(.)/g,"$1").toUpperCase(),n=l.trim();if(c.trim()[0]!=="'"){if(n==="#ALL"||n==="#DATA"||n==="#HEADERS"||n==="#TOTALS"||n==="#THIS ROW"){u.add(n),n==="#THIS ROW"&&(g=!0);continue}}let R=m.findIndex(w=>w.toUpperCase()===l);if(R<0&&(R=m.findIndex(w=>w.toUpperCase()===n)),R<0)return"REF";p.push(a+R)}let A=T,S=E;if(u.has("#ALL"))A=s,S=o;else{const c=u.has("#HEADERS"),l=u.has("#TOTALS"),n=u.has("#DATA");if(c&&i===0||l&&d===0||c&&l&&!n)return"REF";(c||l||n)&&(A=c?s:n?T:o,S=l?o:n?E:s)}const U=p.length?Math.min(...p):a,b=p.length?Math.max(...p):e;if(g){if(r<T||r>E)return"VALUE";A=r,S=r}return{top:A,left:U,bottom:S,right:b}}function D(t,h){if(!h||h.size===0)return t;let r="",s=0;const a=t.length;for(;s<a;){const o=t[s];if(o==='"'||o==="'"){let e=s+1;for(;e<a;){if(t[e]===o){if(t[e+1]!==o)break;e++}e++}r+=t.slice(s,e+1),s=e+1}else if(o==="["){let e=0,i=s;for(;i<a;i++)if(t[i]==="'")i++;else if(t[i]==="[")e++;else if(t[i]==="]"&&--e===0)break;r+=t.slice(s,i+1),s=i+1}else if(/[A-Za-z_\\]/.test(o)){let e=s+1;for(;e<a&&/[A-Za-z0-9_.\\]/.test(t[e]);)e++;const i=t.slice(s,e),d=r[r.length-1],m=h.has(i.toUpperCase())&&t[e]!=="["&&t[e]!=="("&&t[e]!=="!"&&d!=="!";r+=m?`${i}[]`:i,s=e}else r+=o,s++}return r}export{D as expandBareTables,C as resolveStructuredSpec};
|
package/slicers/write.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EXT as c,NS as x,REL as b,newDrawingXml as C,patchDrawingFrames as h}from"./format.js";import{ensureDrawingElement as T,mergeContentTypes as S}from"../objects/drawing-xml.js";import{escapeMarkup as o}from"../io/xml-escape.js";const y=n=>n.slicers?.removedParts??[];function L(n,r){const s=r.slicers;return s?S(n,s.contentTypes,s.removedParts.map(t=>`/${t}`)):n}function k(n,r){const s=r.slicers;if(!s)return n;const t=s.workbookRels.map(e=>`<Relationship Id="${o(e.id)}" Type="${o(e.type)}" Target="${o(e.target)}"/>`).join("");return n.replace("</Relationships>"
|
|
1
|
+
import{EXT as c,NS as x,REL as b,newDrawingXml as C,patchDrawingFrames as h}from"./format.js";import{ensureDrawingElement as T,mergeContentTypes as S}from"../objects/drawing-xml.js";import{escapeMarkup as o}from"../io/xml-escape.js";const y=n=>n.slicers?.removedParts??[];function L(n,r){const s=r.slicers;return s?S(n,s.contentTypes,s.removedParts.map(t=>`/${t}`)):n}function k(n,r){const s=r.slicers;if(!s)return n;const t=s.workbookRels.map(e=>`<Relationship Id="${o(e.id)}" Type="${o(e.type)}" Target="${o(e.target)}"/>`).join("");return n.replace("</Relationships>",()=>`${t}</Relationships>`)}const $=(n,r)=>n.replace(new RegExp(`<ext\\b[^>]*uri="${r.replace(/[{}-]/g,"\\$&")}"[^>]*>[\\s\\S]*?</ext>`),"");function g(n,r,s){const t=s.join("");let e=n;if(t)if(/<\/extLst>\s*$/.test(e.slice(0,e.lastIndexOf(r)))){const l=e.lastIndexOf("</extLst>");e=`${e.slice(0,l)}${t}${e.slice(l)}`}else{const l=e.lastIndexOf(r);e=`${e.slice(0,l)}<extLst>${t}</extLst>${e.slice(l)}`}return e.replace(/<extLst>\s*<\/extLst>/,"")}const p=(n,r)=>r.map(s=>`<${n} xmlns:r="${x.r}" r:id="${o(s)}"/>`).join("");function E(n,r){const s=r.slicers;if(!s)return n;let t=n;for(const i of[c.wbPivotSlicerCaches,c.wbTableSlicerCaches,c.wbTimelineCaches])t=$(t,i);const e=[];s.pivotCaches.length&&e.push(`<ext uri="${c.wbPivotSlicerCaches}" xmlns:x14="${x.x14}"><x14:slicerCaches>${p("x14:slicerCache",s.pivotCaches)}</x14:slicerCaches></ext>`),s.tableCaches.length&&e.push(`<ext uri="${c.wbTableSlicerCaches}" xmlns:x15="${x.x15}"><x15:slicerCaches xmlns:x14="${x.x14}">${p("x14:slicerCache",s.tableCaches)}</x15:slicerCaches></ext>`),s.timelineCaches.length&&e.push(`<ext uri="${c.wbTimelineCaches}" xmlns:x15="${x.x15}"><x15:timelineCacheRefs>${p("x15:timelineCacheRef",s.timelineCaches)}</x15:timelineCacheRefs></ext>`),t=g(t,"</workbook>",e);for(const i of s.removedNames)t=t.replace(new RegExp(`<definedName\\b[^>]*\\bname="${i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}"[^>]*>[^<]*</definedName>`),"");const l=s.names.filter(i=>!t.includes(`name="${o(i)}"`));if(l.length){const i=l.map(d=>`<definedName name="${o(d)}">#N/A</definedName>`).join("");/<\/definedNames>/.test(t)?t=t.replace("</definedNames>",()=>`${i}</definedNames>`):t=t.replace("</sheets>",()=>`</sheets><definedNames>${i}</definedNames>`)}return t.replace(/<definedNames>\s*<\/definedNames>/,"")}function R(n,r){let s=n;for(const e of[c.wsPivotSlicers,c.wsTableSlicers,c.wsTimelines])s=$(s,e);const t=[];return r.pivotIds.length&&t.push(`<ext uri="${c.wsPivotSlicers}" xmlns:x14="${x.x14}"><x14:slicerList>${p("x14:slicer",r.pivotIds)}</x14:slicerList></ext>`),r.tableIds.length&&t.push(`<ext uri="${c.wsTableSlicers}" xmlns:x15="${x.x15}"><x14:slicerList xmlns:x14="${x.x14}">${p("x14:slicer",r.tableIds)}</x14:slicerList></ext>`),r.timelineIds.length&&t.push(`<ext uri="${c.wsTimelines}" xmlns:x15="${x.x15}"><x15:timelineRefs>${p("x15:timelineRef",r.timelineIds)}</x15:timelineRefs></ext>`),g(s,"</worksheet>",t)}async function P({tail:n,index:r,info:s,source:t,extra:e,relsName:l}){const i=e.plan.slicers?.sheets?.[r];if(!i)return n;e.rels.has(l)||e.rels.set(l,[]);const d=e.rels.get(l);for(const a of i.rels)d.push(`<Relationship Id="${o(a.id)}" Type="${o(a.type)}" Target="${o(a.target)}"/>`);let m=R(n,i);const f=i.frames;if(f.upsert.length===0&&f.remove.length===0)return m;const u=s.objects;if(u){const a=e.parts.find(w=>w.path===u.path);return a&&(a.xml=h(typeof a.xml=="string"?a.xml:new TextDecoder().decode(a.xml),f)),m}if(i.drawingExisting){const a=await t.zip.text(i.drawingPath);return e.parts.push({path:i.drawingPath,xml:h(a,f)}),m}return e.parts.push({path:i.drawingPath,xml:C(h("",{upsert:[]})+f.upsert.map(a=>a.xml).join(""))}),d.push(`<Relationship Id="${o(i.drawingRelId)}" Type="${b.drawing}" Target="${o(i.drawingTarget)}"/>`),m=T(m,`<drawing xmlns:r="${x.r}" r:id="${o(i.drawingRelId)}"/>`),m}async function j(n,r,s){const t=r.slicers;if(!t)return;const e=r.sheetRefs??[],l=i=>i.replace(/@@TAB(\d+)@@/g,(d,m)=>String(e[Number(m)]?.sheetId??Number(m)+1));for(const i of t.parts)await n.addBytes(i.name,l(i.xml)),s.add(i.name)}export{P as applySlicerSheet,L as patchSlicerContentTypes,R as patchSlicerSheetTail,E as patchSlicerWorkbook,k as patchSlicerWorkbookRels,y as removedSlicerParts,j as writeSlicerParts};
|
package/table-view/files.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Workbook as
|
|
1
|
+
import{Workbook as B}from"../core/workbook.js";import{BOOL as T,ERR as O,NUM as D,STR as F}from"../core/sheet.js";import{Engine as W}from"../calc/engine.js";import{readCsv as _,CsvWriter as Z}from"../io/csv.js";import{ansiEncoding as H}from"../io/encoding.js";import{buildBlock as U,newBlockBuffers as G}from"../io/export-blocks.js";import{buildPlan as J}from"../io/plan.js";import{writeXlsx as V}from"../io/xlsx-write.js";import{MAX_ROWS as A,MAX_COLS as I,colIndex as q,colName as K}from"../core/address.js";import{changeOutline as Q}from"../core/whatif.js";import{display as Y}from"./model.js";async function he(a,w={},p){if(/\.(?:csv|tsv|txt)$/i.test(a.name)){const e=new B;let n=0;const u={size:a.size,slice:(...s)=>a.slice(...s),stream:()=>a.stream().pipeThrough(new TransformStream({transform(s,t){n+=s.byteLength,t.enqueue(s)}}))};return await _(u,{onProgress:s=>p?.({records:Math.max(0,s-1),loaded:n,total:a.size}),delimiter:w.delimiter||(/\.tsv$/i.test(a.name)?" ":void 0),textColumns:new Set(w.textColumns),fallback:H(globalThis.navigator?.language),preserveIdentifiers:!0,sepLine:!0,addString:s=>e.strings.add(s),styleFor:s=>e.styles.derive(0,{numFmt:s}),onBatch:s=>e.sheet.applyBatch(s)}),{book:e,tables:[]}}const{IoClient:o}=await import("../io/client.js"),f=new o;try{const e=p?await j(a):null,n=await f.open(a,{onProgress:({cells:r})=>p?.({records:e?.columns?Math.floor(r/e.columns):null,loaded:r,total:e?.cells??null})}),{tables:u=[],names:s=[],fullCalcOnLoad:t,manualCalc:c}=f.meta;n.engine=new W(n),n.engine.manual=c,n.engine.precise=f.meta.fullPrecision===!1,n.engine.setNames(s),n.engine.setTables(u.map(r=>({...r,sheet:n.sheets[r.sheetIndex]}))),n.engine.buildGraph({fullCalc:t}),c||await n.engine.whenIdle();const{openZip:m}=await import("../io/zip-reader.js"),h=await m(await f.packageOf(a));if([...h.entries.keys()].some(r=>r.startsWith("customXml/"))){const{DataSheets:r}=await import("../datasheets/manager.js"),y=new r(n);if(await y.load(h))for(const x of y.manager.tables.values())x.autoSync=!1,x.remote=null}return{book:n,tables:u}}finally{f.close()}}async function j(a){try{const{openZip:w}=await import("../io/zip-reader.js"),p=await w(a);let o=0,f=0,e=0;for(const n of p.entries.keys()){if(!/^xl\/worksheets\/[^/]+\.xml$/.test(n))continue;const u=(await p.stream(n)).pipeThrough(new TextDecoderStream).getReader();let s="";for(;s.length<4096&&!/<(?:\w+:)?sheetData/.test(s);){const{done:h,value:r}=await u.read();if(h)break;s+=r}u.cancel().catch(()=>{});const t=s.match(/<(?:\w+:)?dimension\s+ref="\$?([A-Z]+)\$?(\d+)(?::\$?([A-Z]+)\$?(\d+))?"/);if(!t)return null;const c=t[3]?q(t[3])-q(t[1])+1:1,m=t[4]?Number(t[4])-Number(t[2])+1:1;o+=c*m,c*m>e&&(e=c*m,f=c)}return o>1?{cells:o,columns:f}:null}catch{return null}}function ge({book:a,tables:w}){const p=[];return a.sheets.forEach((o,f)=>{if(!(o.hidden||o.isChartSheet)){if(o.kindName==="table"){const e=o.view.spec,n=o.table.byName,u=c=>c.filter(m=>n.has(m.field)),s=u(e.columns).map(({field:c,caption:m,hidden:h,pinned:r,format:y})=>({field:c,caption:m,hidden:h,pinned:r,format:y})),t=s.some(c=>!c.hidden)?{columns:s,search:e.search,sort:u(e.sort),filters:u(e.filters),groups:u(e.groups).map(({field:c})=>({field:c})),total:u(e.totals)[0]??null,collapsed:[...o.view.collapsedPaths]}:null;p.push({name:o.name,sheet:f,native:!0,initialState:t,range:{r0:0,c0:0,r1:o.maxRow,c1:o.maxCol}});return}for(const e of w.filter(n=>n.sheetIndex===f))p.push({name:e.name,sheet:f,headers:e.columns,headerRows:e.headerRows,range:{r0:e.r0,c0:e.c0,r1:e.r1-e.totalsRows,c1:e.c1}});o.maxCol>=0&&o.maxRow>=0&&p.push({name:o.name,sheet:f,whole:!0,range:{r0:0,c0:0,r1:o.maxRow,c1:o.maxCol}})}}),p.sort((o,f)=>+!!o.whole-+!!f.whole)}async function we(a,w,{layout:p=null}={}){const{view:o}=a;if(o.refresh(),p&&w!=="csv")return ne(a,w,p);const f=o.columns,e=[],n={write:t=>{e.push(new Blob([t]))}};if(w==="csv"){const t=new Z(n,",",{bom:!0});await t.batch(f.map((m,h)=>[0,h,m.caption]));let c=[];for(let m=0;m<o.filteredCount;m++)for(let h=0;h<f.length;h++){const r=f[h];c.push([m+1,h,Y(r.col.get(o.perm[m]),r.format)]),c.length===2048&&(await t.batch(c),c=[])}return await t.batch(c),await t.finish(o.filteredCount),new Blob(e,{type:"text/csv;charset=utf-8"})}if(!["xlsx","pdf"].includes(w)||o.filteredCount>=A||f.length>I)throw new Error("The result exceeds the XLSX row limit or the format is unsupported.");const u=new B,s=u.sheet;return s.name="Results",f.forEach((t,c)=>{s.setCell(0,c,F,u.strings.add(t.caption));const m=u.styles.derive(0,{numFmt:t.format});for(let h=0;h<o.filteredCount;h++){const r=o.perm[h],y=t.col.kind(r);if(!y)continue;const x=t.col.get(r),S=y===F?u.strings.add(x):y===T?Number(x):y===O?x.index:x;s.setCell(h+1,c,y,S),m&&y===D&&s.setStyle(h+1,c,m)}}),L(u,s,w)}async function L(a,w,p){const o=[],f={write:u=>{o.push(new Blob([u]))}};if(p==="pdf"){const{createPrintJob:u}=await import("../print/paginate.js"),{writeJobPdf:s}=await import("../print/render-page.js"),t=(await import("../print/page-setup.js")).getPageSetup(w);return t.fitToPage=!0,t.fitToWidth=1,t.fitToHeight=0,await s(u(a,{sheets:[0]}),f,{title:"Results"}),new Blob(o,{type:"application/pdf"})}const e=J(a,{strings:0,styles:0,sheets:0}),n=G();return await V(f,e,{block:(u,s)=>U(w,a.strings,s,n)}),new Blob(o,{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})}const P={bold:!0,fill:"#F2F2F2"},ee={bold:!0,fill:"#F7F7F7"},z={good:{fill:"#D9F2E1",color:"#14532D"},bad:{fill:"#FDE0DD",color:"#8A1C12"},warn:{fill:"#FCEFC9",color:"#6B4A00"},info:{fill:"#DDE9FB",color:"#163D7A"},strong:{bold:!0}},te={gt:"greaterThan",gte:"greaterThanOrEqual",lt:"lessThan",lte:"lessThanOrEqual",equal:"equal",notEqual:"notEqual",between:"between"},X=a=>typeof a=="number"||/^-?\d+(\.\d+)?$/.test(String(a))?String(a):`"${String(a).replace(/"/g,'""')}"`;function oe(a,w,p,o,f){const e=[];for(const n of w??[]){const u={priority:f++};if(n.type==="bar")e.push({...u,type:"dataBar",formulas:[],dataBar:{cfvo:[{type:"min"},{type:"max"}],color:{rgb:"FF638EC6"},showValue:!0}});else if(n.type==="scale")e.push({...u,type:"colorScale",formulas:[],colorScale:{cfvo:[{type:"min"},{type:"percentile",val:"50"},{type:"max"}],colors:[{rgb:"FFF8696B"},{rgb:"FFFFEB84"},{rgb:"FF63BE7B"}]}});else if(n.type==="value"){const s=n.color||n.background?{...n.background&&{fill:n.background},...n.color&&{color:n.color}}:z[n.style]??z.info;a.dxfs??=[],a.dxfs.push(s);const t=a.dxfs.length-1;if(n.op==="contains"){const c=X(String(n.value));e.push({...u,dxfId:t,type:"containsText",operator:"containsText",text:String(n.value),formulas:[`NOT(ISERROR(SEARCH(${c},${o})))`]})}else e.push({...u,dxfId:t,type:"cellIs",operator:te[n.op]??"equal",formulas:[n.value,n.op==="between"?n.value2:void 0].filter(c=>c!==void 0).map(X)})}}return e.length?{sqref:p,rules:e}:null}async function ne(a,w,p){const{view:o,table:f}=a,e=o.columns,n=new Map(p.bands??[]),u=new Map(p.widths??[]),s=new B,t=s.sheet;t.name="Results";const c=s.styles.derive(0,P),m=s.styles.derive(0,ee),h=e.map(d=>s.styles.derive(0,{numFmt:d.format}));let r=0;if([...n.values()].some(Boolean)){let d=0;for(let i=0;i<=e.length;i++){const l=i<e.length?n.get(e[i].field)??"":null,b=n.get(e[d]?.field)??"";if(!(i<e.length&&l===b)){b&&(t.setCell(r,d,F,s.strings.add(b)),i-1>d&&t.addMerge({r0:r,c0:d,r1:r,c1:i-1}));for(let g=d;g<i;g++)t.setStyle(r,g,s.styles.derive(0,{...P,hAlign:"center"}));d=i}}r++}e.forEach((d,i)=>{t.setCell(r,i,F,s.strings.add(d.caption)),t.setStyle(r,i,c)});const y=++r;if(o.count+y+1>=A||e.length>I)throw new Error("The result exceeds the XLSX row limit or the format is unsupported.");const x=(d,i,l,b)=>{if(l==null||l==="")return;const g=typeof l=="number"?D:typeof l=="boolean"?T:typeof l=="string"?F:l?.index!=null?O:F,v=g===F?s.strings.add(String(l?.code??l)):g===T?Number(l):g===O?l.index:l;t.setCell(d,i,g,v),b&&t.setStyle(d,i,b)},S=a.total?.field,E=e.findIndex(d=>d.field===S),R=[],C=r;for(let d=0;d<o.count;d++,r++){const i=o.rowInfo(d);if(i.kind==="record"){a.rowValues(e,i.record).forEach((b,g)=>x(r,g,b,typeof b=="number"?h[g]:0)),R.push(o.spec.hierarchy?i.level:o.spec.groups.length);continue}x(r,0,o.groupCaption(i.node),m);for(let l=1;l<e.length;l++)t.setStyle(r,l,m);if(E>=0&&i.kind==="group"){const l=o.summaryFor(i.node,S);x(r,E,Number.isFinite(l)?l:null,s.styles.derive(m,{numFmt:e[E].format}))}R.push(i.level)}let $=0;R.forEach((d,i)=>{const l=Math.min(7,d);l&&Q(t,"row",C+i,C+i,l),$=Math.max($,l)});const N=r-1;if(p.totals){const{aggregate:d}=await import("../datasheets/view.js"),i=new Map((a.layout??[]).map(l=>[l.field,l.total]));e.forEach((l,b)=>{const g=i.get(l.field),v=g?d(l.col,g,o.perm,0,o.filteredCount):null;t.setStyle(r,b,c),b===0&&!g&&x(r,0,"Total",c),Number.isFinite(v)&&x(r,b,v,s.styles.derive(c,{numFmt:g==="count"?"#,##0":l.format}))}),r++}e.forEach((d,i)=>{const l=u.get(d.field);Number.isFinite(l)&&t.cols.setSize(i,Math.round(l))}),t.colsChanged=!0,t.frozenRows=y,t.viewChanged=!0;const k=[];let M=1;if(N>=C){const d=new Map((a.layout??[]).map(i=>[i.field,i.rules]));e.forEach((i,l)=>{const b=K(l),g=oe(s,d.get(i.field),`${b}${C+1}:${b}${N+1}`,`${b}${C+1}`,M);g&&(k.push(g),M+=g.rules.length)})}return k.length&&(t.cf=k,t.cfChanged=!0),L(s,t,w)}export{we as exportResults,he as openFile,ge as sourcesOf};
|