@8sheets/data-grid 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/a11y/cell-alt-text.js +1 -1
- package/api/serialize.js +1 -1
- package/api/style-refs.js +1 -1
- package/calc/adjust.js +1 -1
- package/calc/compile.js +1 -1
- package/calc/engine.js +1 -1
- package/calc/functions/array.js +1 -1
- package/calc/functions/database.js +1 -1
- package/calc/functions/date.js +1 -1
- package/calc/functions/engineering.js +1 -1
- package/calc/functions/financial.js +1 -1
- package/calc/functions/helpers.js +1 -1
- package/calc/functions/index.js +3 -2
- package/calc/functions/info.js +1 -1
- package/calc/functions/logical.js +1 -1
- package/calc/functions/lookup.js +1 -1
- package/calc/functions/math.js +1 -1
- package/calc/functions/stat.js +1 -1
- package/calc/functions/text.js +1 -1
- package/calc/parser.js +2 -2
- package/calc/shown-refs.js +1 -0
- package/calc/values.js +1 -1
- package/calcx/calc-control.js +1 -0
- package/calcx/external-read.js +1 -1
- package/calcx/external.js +1 -1
- package/cells/axis-ops.js +1 -1
- package/cells/cell-styles-xml.js +1 -1
- package/cells/cf-engine.js +1 -1
- package/cells/cf-file.js +1 -1
- package/cells/docprops-xml.js +2 -2
- package/cells/filter-eval.js +1 -0
- package/cells/filter-file.js +1 -1
- package/cells/find-engine.js +1 -1
- package/cells/goto.js +1 -1
- package/cells/name-box.js +1 -1
- package/cells/note-box.js +3 -0
- package/cells/options.js +1 -1
- package/cells/outline-column.js +1 -1
- package/cells/protected-menu.js +1 -0
- package/cells/rich-data-xml.js +1 -1
- package/cells/sheet-views-file.js +2 -0
- package/cells/shift-check.js +1 -1
- package/cells/sort-compare.js +1 -0
- package/cells/ui-kit.js +1 -1
- package/cells/undo-group.js +1 -1
- package/celltypes/dropdowns.js +2 -2
- package/core/address.js +1 -1
- package/core/autofill.js +1 -1
- package/core/axis.js +1 -1
- package/core/cond-format.js +1 -1
- package/core/culture.js +5 -1
- package/core/custom-views.js +1 -1
- package/core/data-tools.js +1 -0
- package/core/date-codes.js +1 -0
- package/core/default-names.js +1 -1
- package/core/formula-refs.js +1 -1
- package/core/input.js +1 -1
- package/core/numfmt.js +1 -1
- package/core/precision.js +1 -0
- package/core/region-input.js +1 -1
- package/core/rule-refs.js +1 -0
- package/core/shared-view.js +1 -0
- package/core/sheet.js +1 -1
- package/core/sparklines.js +1 -1
- package/core/sparse.js +1 -1
- package/core/spills.js +1 -0
- package/core/strings.js +1 -1
- package/core/structure.js +1 -1
- package/core/table-columns.js +1 -0
- package/core/tables.js +2 -2
- package/core/validation-ranges.js +1 -1
- package/core/whatif.js +1 -1
- package/core/workbook.js +1 -1
- package/datasheets/formula.js +1 -1
- package/datasheets/path-binding.js +1 -1
- package/datasheets/persist-writer.js +1 -1
- package/datasheets/report.js +1 -1
- package/extras/getdata/persist.js +2 -2
- package/extras/getdata/rows.js +1 -1
- package/extras/getdata/shared-steps.js +1 -0
- package/extras/getdata/steps-formula.js +1 -0
- package/extras/getdata/steps-more.js +1 -0
- package/extras/getdata/steps-tables.js +1 -0
- package/extras/getdata/steps.js +1 -1
- package/i18n/de/a11y.js +1 -0
- package/i18n/de/cells.js +2 -0
- package/i18n/de/charts.js +1 -0
- package/i18n/de/common.js +1 -0
- package/i18n/de/datasheets.js +1 -0
- package/i18n/de/format.js +1 -0
- package/i18n/de/misc.js +1 -0
- package/i18n/de/pivot.js +1 -0
- package/i18n/de/proofing.js +1 -0
- package/i18n/de/ribbon.js +1 -0
- package/i18n/de/shapes.js +1 -0
- package/i18n/de/shell.js +3 -0
- package/i18n/de/touch.js +1 -0
- package/i18n/de.js +1 -0
- package/i18n/en/cells.js +2 -1
- package/i18n/en/charts.js +1 -1
- package/i18n/en/format.js +1 -1
- package/i18n/en/misc.js +1 -1
- package/i18n/en/pivot.js +1 -1
- package/i18n/en/proofing.js +1 -1
- package/i18n/en/ribbon.js +1 -1
- package/i18n/en/shapes.js +1 -1
- package/i18n/en/shell.js +3 -2
- package/i18n/en/touch.js +1 -1
- package/i18n/es/a11y.js +1 -0
- package/i18n/es/cells.js +2 -0
- package/i18n/es/charts.js +1 -0
- package/i18n/es/common.js +1 -0
- package/i18n/es/datasheets.js +1 -0
- package/i18n/es/format.js +1 -0
- package/i18n/es/misc.js +1 -0
- package/i18n/es/pivot.js +1 -0
- package/i18n/es/proofing.js +1 -0
- package/i18n/es/ribbon.js +1 -0
- package/i18n/es/shapes.js +1 -0
- package/i18n/es/shell.js +3 -0
- package/i18n/es/touch.js +1 -0
- package/i18n/es.js +1 -0
- package/i18n/fr/a11y.js +1 -0
- package/i18n/fr/cells.js +2 -0
- package/i18n/fr/charts.js +1 -0
- package/i18n/fr/common.js +1 -0
- package/i18n/fr/datasheets.js +1 -0
- package/i18n/fr/format.js +1 -0
- package/i18n/fr/misc.js +1 -0
- package/i18n/fr/pivot.js +1 -0
- package/i18n/fr/proofing.js +1 -0
- package/i18n/fr/ribbon.js +1 -0
- package/i18n/fr/shapes.js +1 -0
- package/i18n/fr/shell.js +3 -0
- package/i18n/fr/touch.js +1 -0
- package/i18n/fr.js +1 -0
- package/i18n/index.js +1 -1
- package/i18n/languages.js +1 -1
- package/i18n/pl/cells.js +2 -1
- package/i18n/pl/charts.js +1 -1
- package/i18n/pl/format.js +1 -1
- package/i18n/pl/misc.js +1 -1
- package/i18n/pl/pivot.js +1 -1
- package/i18n/pl/proofing.js +1 -1
- package/i18n/pl/ribbon.js +1 -1
- package/i18n/pl/shapes.js +1 -1
- package/i18n/pl/shell.js +3 -2
- package/i18n/pl/touch.js +1 -1
- package/io/blob-sink.js +1 -0
- package/io/canonical-xml.js +1 -0
- package/io/client.js +1 -1
- package/io/crypto/cfb-build.js +1 -0
- package/io/crypto/cfb-read.js +1 -1
- package/io/crypto/cfb-write.js +1 -1
- package/io/crypto/errors.js +1 -1
- package/io/csv.js +8 -8
- package/io/foreign-sheets.js +2 -2
- package/io/io.worker.js +1 -1
- package/io/open-package.js +1 -0
- package/io/package-paths.js +1 -1
- package/io/plan.js +1 -1
- package/io/text-split.js +3 -3
- package/io/xls/chart-sheet.js +1 -0
- package/io/xls/chart.js +1 -0
- package/io/xls/crypt.js +1 -0
- package/io/xls/dml-color.js +1 -0
- package/io/xls/drawing.js +1 -0
- package/io/xls/formula.js +1 -0
- package/io/xls/geometry.js +1 -0
- package/io/xls/index.js +1 -0
- package/io/xls/pictures.js +1 -0
- package/io/xls/pivot.js +1 -0
- package/io/xls/props.js +1 -0
- package/io/xls/records.js +1 -0
- package/io/xls/shapes.js +1 -0
- package/io/xls/sheet-ext.js +1 -0
- package/io/xls/sheet.js +1 -0
- package/io/xls/styles.js +1 -0
- package/io/xls/vba.js +1 -0
- package/io/xls/workbook.js +1 -0
- package/io/xlsb/filter.js +1 -0
- package/io/xlsb/formula.js +2 -0
- package/io/xlsb/functions.js +1 -0
- package/io/xlsb/index.js +1 -0
- package/io/xlsb/parts.js +1 -0
- package/io/xlsb/pivot.js +1 -0
- package/io/xlsb/records.js +1 -0
- package/io/xlsb/sheet-ext.js +1 -0
- package/io/xlsb/sheet.js +1 -0
- package/io/xlsb/slicer.js +1 -0
- package/io/xlsb/styles.js +1 -0
- package/io/xlsb/workbook.js +1 -0
- package/io/xlsb/xml.js +2 -0
- package/io/xlsx-read.js +1 -1
- package/io/xlsx-styles.js +2 -2
- package/io/xlsx-tail.js +1 -1
- package/io/xlsx-write.js +2 -2
- package/io/xml-escape.js +1 -1
- package/io/xml-scan.js +2 -2
- package/io/zip-reader.js +1 -1
- package/objects/chart-model.js +1 -1
- package/objects/drawing-xml.js +1 -1
- package/package.json +1 -1
- package/pivot/calc-items.js +1 -0
- package/pivot/engine.js +1 -1
- package/pivot/xml.js +2 -2
- package/print/note-pages.js +2 -2
- package/print/page-setup.js +1 -1
- package/print/paginate.js +1 -1
- package/print/pdf-crypt.js +1 -0
- package/print/pdf-tags.js +1 -0
- package/print/pdf.js +24 -13
- package/print/render-page.js +3 -3
- package/print/shown-notes.js +1 -0
- package/shapes/form-xml.js +1 -1
- package/slicers/custom-styles.js +1 -1
- package/slicers/format.js +1 -1
- package/slicers/structured.js +1 -1
- package/slicers/write.js +1 -1
- package/table-view/files.js +1 -1
- package/table-view/mount.js +1 -1
- package/table-view/version.js +1 -1
- package/ui/icons.js +1 -1
- package/ui/menu-base.js +1 -1
- package/ui/protection-ui.js +1 -1
package/datasheets/report.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BOOL as ft,EMPTY as $,ERR as Z,FORMULA as J,KIND_MASK as ut,NUM as B,SPILL as pt,STR as E}from"../core/sheet.js";import{cellRef as N,colName as H,colIndex as wt,MAX_COLS as P,MAX_ROWS as L,parseRangeRef as Y,rangeRef as dt,sheetPrefix as gt}from"../core/address.js";import{rangesOf as mt}from"../core/cond-format.js";import{translateFormula as yt}from"../core/formula-refs.js";import{getPageSetup as _t}from"../print/page-setup.js";import{paginate as V}from"../print/paginate.js";import{getFormatter as j}from"../core/numfmt.js";import{ERR as Ct,XlError as bt}from"../calc/values.js";import{aggregate as Q,formulaHelper as q,groupKeys as tt,TableView as et}from"./view.js";import{sortByF64 as kt}from"./sort.js";import{Axis as st}from"../core/axis.js";import{t as A}from"../i18n/index.js";const Rt=["group","list","summary","param","static","chart"],M=(g,t)=>g*P+t,U=new Int32Array(0),G=-2,St=8e3;class O{constructor(t,s,e,l=null,a=void 0){this.parent=t,this.table=s,this.rows=e,this.node=l,this.value=a,this.first=-1,this.last=-1,this.resolved=null}}class T extends Error{}class ht{constructor(t,s,e={}){this.manager=t,this.sheet=s,this.bindings=new Map,this.params=new Map,this.filters=[],this.titleRows=e.titleRows??null,this.pageSetup=e.pageSetup??null,this.defaultTable=e.table??null,this.name=e.name??s.name,this.output=null,this.mode=e.mode??"design",this.pagination=e.pagination??null,this.layout=e.layout??null,this.dataEntry=e.dataEntry??null,this.charts=e.charts??[],this.pictures=e.pictures??[],this.states=e.states??null,this.measure=e.measure??null,this.showHiddenRows=e.showHiddenRows===!0,this.showHiddenCols=e.showHiddenCols===!0,this.listeners=new Map,s.report=this}setBinding(t,s,e){const l=e.type;if(!Rt.includes(l))throw new T(`Unknown binding type: ${l}`);const a={table:this.defaultTable,expand:l==="group"||l==="list"?"vertical":"none",agg:"sum",sort:l==="group"?"asc":null,...e,row:t,col:s};return this.bindings.set(M(t,s),a),a}binding(t,s){return this.bindings.get(M(t,s))??null}removeBinding(t,s){this.bindings.delete(M(t,s))}static markerText(t){switch(t.type){case"group":return`[${t.field}]`;case"list":return`=[${t.field}]`;case"summary":return`${t.agg??"sum"}[${t.field}]`;case"chart":return`chart[${t.chartType??"line"}]`;default:return`{${t.param}}`}}writeMarkers(t){t.sheet===this.sheet&&t.transact("report binding",s=>{for(const e of this.bindings.values())e.type!=="static"&&(s.saveCell(e.row,e.col),this.sheet.setFormula(e.row,e.col,null),this.sheet.setCell(e.row,e.col,E,t.strings.add(ht.markerText(e))))})}addParam(t,s={}){this.params.set(t,{name:t,caption:s.caption??t,type:s.type??"string",value:s.value??null,options:s.options??null})}setParam(t,s){const e=this.params.get(t);if(!e)throw new T(A("No parameter named {name}.",{name:t}));e.value=s}on(t,s){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(s),()=>this.listeners.get(t).delete(s)}fire(t,s){let e=!0;for(const l of this.listeners.get(t)??[])l(s)===!1&&(e=!1);return e}addFilter(t){this.filters.push(t)}generate(t,{target:s=null,name:e=null,params:l=null,measure:a=null}={}){if(l)for(const[o,n]of Object.entries(l))this.setParam(o,n);a&&(this.measure=a),this.fire("stage",{stage:"start"});const f=new xt(this,t).run(s,e);return this.fire("stage",{stage:"done",result:f}),f}async generateAsync(t,s){return await new Promise(e=>setTimeout(e,0)),this.generate(t,s)}toJSON(){return{name:this.name,sheet:this.sheet.name,table:this.defaultTable,bindings:[...this.bindings.values()].map(t=>({...t})),params:[...this.params.values()],filters:this.filters,titleRows:this.titleRows,pageSetup:this.pageSetup,output:this.output?.name??null,mode:this.mode,pagination:this.pagination,layout:this.layout,dataEntry:this.dataEntry,charts:this.charts,pictures:this.pictures,states:this.states,showHiddenRows:this.showHiddenRows,showHiddenCols:this.showHiddenCols}}}const nt=(g,t)=>`${g.name}|${t.formula??t.field}|${t.by??""}|${t.size??""}|${t.bins?JSON.stringify(t.bins):""}`,vt=g=>{let t=0;for(let s=g.parent;s!==null;s=s.parent)t++;return t};class rt{constructor(t,s,e,l){this.binding=t,this.a=s,this.b=e,this.parent=l,this.children=[],this.members=[]}}class xt{constructor(t,s){this.t=t,this.book=s,this.manager=t.manager,this.sheet=t.sheet,this.roots=new Map,this.keyCache=new Map,this.helperViews=new Map,this.cellInfo=new Map,this.groupMerges=[],this.collapses=[],this.overlay=null,this.breaks=[],this.formulas=[],this.memberColumns=new Map,this.rowCap=1024,this.rowTpl=new Int32Array(this.rowCap),this.rowCtx=new Int32Array(this.rowCap),this.rowRec=new Int32Array(this.rowCap),this.rowCount=0,this.contexts=[],this.colOut=[]}_table(t){if(!t)throw new T(A("A binding needs a table."));return this.manager.table(t)}_templateExtent(){const{sheet:t}=this;let s=t.maxRow,e=t.maxCol;for(const l of this.t.bindings.values())l.row>s&&(s=l.row),l.col>e&&(e=l.col);for(const l of t.merges)l.r1>s&&(s=l.r1),l.c1>e&&(e=l.c1);return{maxRow:s,maxCol:e}}_buildTree(t,s){const e=t==="vertical",l=i=>e?i.row:i.col,a=i=>e?i.col:i.row,f=[...this.t.bindings.values()].filter(i=>(i.type==="group"||i.type==="list")&&i.expand===t);f.sort((i,u)=>a(i)-a(u)||l(i)-l(u));const o=new rt(null,0,e?s.maxRow:s.maxCol,null),n=new Map,c=i=>{if(i.span>1)return l(i)+i.span-1;const u=this.sheet.mergeAt(i.row,i.col);return u?e?u.r1:u.c1:l(i)},r=i=>{if(i.parent==="none")return o;if(i.parent){const p=n.get(M(i.parent.row,i.parent.col));if(p)return p}let u=o;for(const p of n.values())a(p.binding)>=a(i)||l(i)<p.a||l(i)>p.b||p.a>=u.a&&(u===o||a(p.binding)>=a(u.binding))&&(u=p);return u};for(const i of f){const u=r(i);if(i.type==="list"&&u!==o&&u.binding.type==="list"&&l(u.binding)===l(i)&&u.binding.table===i.table){u.members.push(i);continue}if(i.type==="list"){const w=u.children.find(m=>m.binding.type==="list"&&l(m.binding)===l(i)&&m.binding.table===i.table);if(w){w.members.push(i);continue}}const p=new rt(i,l(i),c(i),u);u.children.push(p),n.set(M(i.row,i.col),p)}const h=i=>{i.children.sort((u,p)=>u.a-p.a);for(const u of i.children)h(u),i!==o&&u.b>i.b&&(i.b=u.b),i!==o&&u.a<i.a&&(i.a=u.a);for(let u=1;u<i.children.length;u++)if(i.children[u].a<=i.children[u-1].b){const p=i.children[u].binding,w=i.children[u-1].binding;throw new T(A("The cells {first} and {second} expand over the same rows but neither is the other's parent.",{first:N(p.row,p.col),second:N(w.row,w.col)}))}};return h(o),o}_rootRows(t){let s=this.roots.get(t);if(s!==void 0)return s;const e=this.t.filters.filter(a=>this.manager.table(a.table??this.t.defaultTable)===t).map(a=>this._resolveFilter(a)),l=new et(t,{columns:[],filters:e});return s=l.filtered.slice(0,l.filteredCount),l.dispose(),this.roots.set(t,s),s}_resolveFilter(t){const s={...t};if(t.param&&(s.value=this._param(t.param)),t.param2&&(s.value2=this._param(t.param2)),t.valuesParam){const e=this._param(t.valuesParam);s.values=Array.isArray(e)?e:[e],s.op=s.op??"in"}return s}_param(t){const s=this.t.params.get(t);if(!s)throw new T(A("No parameter named {name}.",{name:t}));return s.value}_filterActive(t){if(t.param&&(this._param(t.param)===null||this._param(t.param)===""))return!1;if(t.valuesParam){const s=this._param(t.valuesParam);if(s===null||s===""||Array.isArray(s)&&s.length===0)return!1}return!0}_rowsIn(t,s){if(t===null)return this._rootRows(s);if(t.table===s)return t.rows;t.resolved===null&&(t.resolved=new Map);let e=t.resolved.get(s);return e!==void 0||(e=this._crossRows(t,s),t.resolved.set(s,e)),e}_crossRows(t,s){for(let e=t;e!==null;e=e.parent){if(e.table===s)return e.rows;if(e.table===null)continue;const l=e.node?.binding.link;if(l)return this._joinRows(e,s,l.from,l.to);const a=this.manager.relationshipBetween(e.table,s);if(!a)continue;const f=this._rootMask(s);if(a.to===e.table){const{starts:r,rows:h}=a.children();let i=0;for(let w=0;w<e.rows.length;w++)i+=r[e.rows[w]+1]-r[e.rows[w]];const u=new Int32Array(i);let p=0;for(let w=0;w<e.rows.length;w++){const m=e.rows[w];for(let C=r[m];C<r[m+1];C++)(f===null||f[h[C]]===1)&&(u[p++]=h[C])}return p===i?u:u.slice(0,p)}const o=a.parents(),n=new Uint8Array(s.rowCount),c=[];for(let r=0;r<e.rows.length;r++){const h=o[e.rows[r]];h>=0&&n[h]===0&&(f===null||f[h]===1)&&(n[h]=1,c.push(h))}return Int32Array.from(c)}return this._rootRows(s)}_rootMask(t){if(!this.t.filters.some(e=>this.manager.table(e.table??this.t.defaultTable)===t))return null;const s=new Uint8Array(t.rowCount);for(const e of this._rootRows(t))s[e]=1;return s}_joinRows(t,s,e,l){const a=new Set,f=t.table.column(e);for(let r=0;r<t.rows.length;r++)a.add(String(f.get(t.rows[r])));const o=s.column(l),n=this._rootRows(s),c=[];for(let r=0;r<n.length;r++)a.has(String(o.get(n[r])))&&c.push(n[r]);return Int32Array.from(c)}_helperView(t){let s=this.helperViews.get(t);return s===void 0&&(s=new et(t,{columns:[]}),this.helperViews.set(t,s)),s}_prepareRows(t,s,e,l=null){let a=t;const f=(s.filters??[]).filter(o=>this._filterActive(o)).map(o=>this._resolveFilter(o));if(f.length>0||s.filter){const o=this._helperView(e),n=new Uint8Array(e.rowCount);for(let h=0;h<a.length;h++)n[a[h]]=1;for(const h of f)o._applyCondition(h,n,e.rowCount);s.filter&&this._applyFilterTree(s.filter,n,e,o,l);const c=new Int32Array(a.length);let r=0;for(let h=0;h<a.length;h++)n[a[h]]===1&&(c[r++]=a[h]);a=c.subarray(0,r)}if(s.sortFormula)a=a===t?t.slice():a,this._helperView(e)._sortColumn(a,a.length,q(e,s.sortFormula),s.sort==="desc");else if(s.sort||s.sortBy){const o=e.column(s.sortBy??s.field);o&&(a=a===t?t.slice():a,this._helperView(e)._sortColumn(a,a.length,o,s.sort==="desc"))}return a}_applyFilterTree(t,s,e,l,a){const f=e.rowCount;if(t.and){for(const n of t.and)this._applyFilterTree(n,s,e,l,a);return}if(t.or){const n=new Uint8Array(f);for(const c of t.or){const r=s.slice();this._applyFilterTree(c,r,e,l,a);for(let h=0;h<f;h++)n[h]|=r[h]}s.set(n);return}if(t.param!==void 0&&!this._filterActive(t))return;const o=this._resolveFilter(t);if(t.cell){const n=this.t.binding(t.cell.row,t.cell.col);for(let c=a;c!=null;c=c.parent)if(c.node?.binding===n&&c.rows.length>0){o.value=c.table.column(n.field).get(c.rows[0]);break}}if(t.join){const n=this._table(t.join.table),c=n.column(t.join.field),r=a?this._rowsIn(a,n):this._rootRows(n),h=new Set;for(let i=0;i<r.length;i++)h.add(c.get(r[i]));o.op="in",o.values=[...h]}l._applyCondition(o,s,f)}_partition(t,s,e,l=null){const a=this._prepareRows(t,{...s,sort:null,sortBy:null,sortFormula:null},e,l),f=nt(e,s);let o=this.keyCache.get(f);if(o===void 0){if(o=tt(e,s),o===null)throw new T(A("No field {field} in {table}.",{field:s.field,table:e.name}));this.keyCache.set(f,o)}const n=a===t?t.slice():a;s.sort&&Tt(n,o,s.sort==="desc");const c=[],r=s.sort?null:new Map;let h=0;const i=n.length;if(s.sort)for(;h<i;){const u=o[n[h]];let p=h+1;if(u===u)for(;p<i&&o[n[p]]===u;)p++;else for(;p<i&&o[n[p]]!==o[n[p]];)p++;c.push(n.subarray(h,p)),h=p}else{for(;h<i;h++){const u=o[n[h]],p=u!==u?"blank":u,w=r.get(p);w?w.push(n[h]):r.set(p,[n[h]])}for(const u of r.values())c.push(Int32Array.from(u))}return this._orderGroups(c,s,e)}_orderGroups(t,s,e){if(s.sortList){const l=s.formula?q(e,s.formula):e.column(s.field),a=new Map(s.sortList.map((o,n)=>[String(o).toLowerCase(),n])),f=o=>a.get(String(l.get(o[0])).toLowerCase())??1/0;return t.map((o,n)=>[o,f(o),n]).sort((o,n)=>o[1]-n[1]||o[2]-n[2]).map(o=>o[0])}if(s.sortCell){const l=this.t.binding(s.sortCell.row,s.sortCell.col),a=l&&l.field?e.column(l.field):null;if(a){const f=s.sort==="desc"?-1:1,o=n=>Q(a,l.agg??"sum",n,0,n.length);return t.map(n=>[n,o(n)]).sort((n,c)=>f*(n[1]-c[1])).map(n=>n[0])}}return t}_paginateRows(){const{t}=this,s=t.pagination,e=new Set,l=new Set;for(const n of t.bindings.values())n.pageBefore&&e.add(n.row),n.pageAfter&&l.add(n.row);if(e.size>0||l.size>0)for(let n=0;n<this.rowCount;n++){const c=this.rowTpl[n];e.has(c)&&n>0&&this.breaks.push(n),l.has(c)&&this.breaks.push(n+1)}const a=s?.endRows??null,f=t.titleRows?t.titleRows.r1-t.titleRows.r0+1:0;let o=s?.rowsPerPage>0?s.rowsPerPage:0;if(a&&o===0){const n=V(this.book,this.sheet).box.h,c=a.r1-a.r0+1;o=Math.max(1,Math.floor(n/this.sheet.rows.defaultSize)-f-c)}if(a)this._repeatEndRows(a,o,f);else if(o>0)for(const n of this._rowPageStarts(this.rowCount,o,f,new Set(this.breaks)))this.breaks.push(n);this.pageStartSet=new Set(this.breaks)}_rowPageStarts(t,s,e,l){const a=[];for(const i of this.contexts)i.node?.binding?.keepTogether&&i.first!==void 0&&i.last>i.first&&a.push(i);a.sort((i,u)=>i.first-u.first);const f=[];let o=0,n=e+s,c=0;const r=[...l].sort((i,u)=>i-u);let h=0;for(;o+n<t;){let i=o+n;for(;h<r.length&&r[h]<=o;)h++;for(h<r.length&&r[h]<i&&(i=r[h]);c<a.length&&a[c].last<i;)c++;c<a.length&&a[c].first<i&&a[c].first>o&&a[c].last>=i&&(i=a[c].first),f.push(i),o=i,n=s}return f}_repeatEndRows(t,s,e){const l=this.rowCount,{rowTpl:a,rowCtx:f,rowRec:o}=this,n=[],c=[];for(let d=0;d<l;d++)(a[d]>=t.r0&&a[d]<=t.r1?c:n).push(d);if(c.length===0||n.length===0)return;const r=new Int32Array(l).fill(-1);n.forEach((d,_)=>{r[d]=_});const h=new Set;for(const d of this.breaks){let _=d;for(;_<l&&r[_]<0;)_++;_<l&&h.add(r[_])}const i=this.contexts.map(d=>[d.first,d.last]);for(const d of this.contexts){if(d.first===void 0||d.first<0)continue;let _=d.first;for(;_<l&&r[_]<0;)_++;let v=d.last;for(;v>0&&r[v]<0;)v--;d.first=_<l?r[_]:0,d.last=v>=0&&r[v]>=0?r[v]:d.first}const u=s>0?this._rowPageStarts(n.length,s,e,h):[...h].sort((d,_)=>d-_);i.forEach(([d,_],v)=>{this.contexts[v].first=d,this.contexts[v].last=_});const p=n.length+c.length*(u.length+1),w=new Int32Array(p),m=new Int32Array(p),C=new Int32Array(p),k=new Int32Array(l).fill(-1),R=[];let S=0,y=0;const x=()=>{c.forEach(d=>{w[S]=a[d],m[S]=f[d],C[S]=o[d],k[d]<0&&(k[d]=S),S++})};n.forEach((d,_)=>{y<u.length&&u[y]===_&&(x(),R.push(S),y++),w[S]=a[d],m[S]=f[d],C[S]=o[d],k[d]=S,S++}),x(),this.rowTpl=w,this.rowCtx=m,this.rowRec=C,this.rowCount=p,this.rowCap=p,this.breaks=R;const b=d=>d>=0&&d<l&&k[d]>=0?k[d]:d;for(const d of this.contexts)d.first!==void 0&&(d.first=b(d.first)),d.last!==void 0&&(d.last=b(d.last));for(const d of this.collapses)d.row=b(d.row),d.from=b(d.from),d.to=b(d.to);for(const d of this.groupMerges)d.r0=b(d.r0),d.r1=b(d.r1);this.overlay&&(this.overlay=new Map([...this.overlay].map(([d,_])=>[b(d),_])))}_paginateCols(){const{t}=this,s=t.pagination;this.colBreaks=[];const e=new Set,l=new Set;for(const p of t.bindings.values())p.colPageBefore&&e.add(p.col),p.colPageAfter&&l.add(p.col);const a=s?.endCols??null,f=p=>a&&p.tpl>=a.c0&&p.tpl<=a.c1,o=a?this.colOut.filter(f):[],n=a?this.colOut.filter(p=>!f(p)):this.colOut,c=s?.colsPerPage>0?s.colsPerPage:0,r=[],h=s?.titleCols?s.titleCols.c1-s.titleCols.c0+1:0;let i=0,u=h+c;n.forEach((p,w)=>{w>0&&(c>0&&i>=u||e.has(p.tpl)||l.has(n[w-1].tpl))&&(r.push(...o),this.colBreaks.push(r.length),i=0,u=c),r.push(p),i++}),r.push(...o),this.colOut=r}_pushRow(t,s,e){if(this.rowCount===this.rowCap){const a=this.rowCap*2,f=o=>{const n=new Int32Array(a);return n.set(o),n};this.rowTpl=f(this.rowTpl),this.rowCtx=f(this.rowCtx),this.rowRec=f(this.rowRec),this.rowCap=a}if(this.rowCount>=L)throw new T(A("The report needs more than {count} rows. Add a filter.",{count:L}));const l=this.rowCount++;return this.rowTpl[l]=t,this.rowCtx[l]=s,this.rowRec[l]=e,l}_newContext(t){return this.contexts.push(t),t.index=this.contexts.length-1,t}_emitBand(t,s,e,l,a){let f=e;const o=t.children;let n=0;for(;f<=l;){for(;n<o.length&&o[n].b<f;)n++;const c=n<o.length&&o[n].a===f?o[n]:null;if(c!==null){const r=this._expandNode(c,s);f=c.b+1+(r??0)}else this._pushRow(f,s.index,a),f++}}_expandNode(t,s){const e=t.binding,l=this._table(e.table),a=this._rowsIn(s,l),f=c=>e.fillTo>1?(e.fillTo-c%e.fillTo)%e.fillTo:0;if(e.type==="group"){let c=this._partition(a,e,l,s);e.spillMode==="none"&&(c=c.slice(0,1));const r=e.merge===!0||this.sheet.mergeAt(e.row,e.col)!==null,h=c.length;for(let i=0;i<h;i++){const u=this._newContext(new O(s,l,c[i],t));u.ordinal=i+1,u.first=this.rowCount,this._emitBand(t,u,t.a,t.b,-1),u.last=this.rowCount-1,r&&u.last>u.first&&this.groupMerges.push({binding:e,r0:u.first,r1:u.last}),e.collapse&&u.last>u.first&&this.collapses.push({binding:e,row:u.first,from:u.first+1,to:u.last,depth:vt(u),collapsed:e.initial==="collapsed"}),e.pageBreak&&i<h-1&&this.breaks.push(this.rowCount)}for(let i=f(h);i>0;i--){const u=this._newContext(new O(s,l,U,t));u.first=this.rowCount,this._emitBand(t,u,t.a,t.b,G),u.last=this.rowCount-1}return 0}let o=this._prepareRows(a,e,l,s);e.spillMode==="none"&&(o=o.subarray(0,1));const n=e.pageEvery??0;if(t.a===t.b&&t.children.length===0){const c=this._newContext(new O(s,l,o,t));if(c.first=this.rowCount,e.spillMode==="overwrite"){const r=o.length;for(let h=0;h<r;h++){const i=this._pushRow(t.a+h,c.index,o[h]);this.overlay===null&&(this.overlay=new Map),this.overlay.set(i,t.a)}return c.last=this.rowCount-1,Math.max(0,r-1)}for(let r=0;r<o.length;r++)this._pushRow(t.a,c.index,o[r]),n>0&&(r+1)%n===0&&r+1<o.length&&this.breaks.push(this.rowCount);for(let r=f(o.length);r>0;r--)this._pushRow(t.a,c.index,G);return c.last=this.rowCount-1,0}for(let c=0;c<o.length;c++){const r=o.subarray(c,c+1),h=this._newContext(new O(s,l,r,t));h.ordinal=c+1,h.first=this.rowCount,this._emitBand(t,h,t.a,t.b,o[c]),h.last=this.rowCount-1,n>0&&(c+1)%n===0&&c+1<o.length&&this.breaks.push(this.rowCount)}return 0}_expandColumns(t,s,e,l){let a=e,f=0;const o=t.children;for(;a<=l;){for(;f<o.length&&o[f].b<a;)f++;const n=f<o.length&&o[f].a===a?o[f]:null;if(n!==null)this._expandColumnNode(n,s),a=n.b+1;else{if(this.colOut.length>=P)throw new T(A("The report needs more than {count} columns. Add a filter.",{count:P}));this.colOut.push({tpl:a,ctx:s}),a++}}}_expandColumnNode(t,s){const e=t.binding,l=this._table(e.table),a=this._colRows(s,l);let f=e.type==="group"?this._partition(a,e,l):Array.from(this._prepareRows(a,e,l),n=>Int32Array.of(n));e.spillMode==="none"&&(f=f.slice(0,1));const o=e.fillTo>1?(e.fillTo-f.length%e.fillTo)%e.fillTo:0;for(let n=0;n<o;n++)f.push(U);for(const n of f){const c=new O(s,l,n,t);c.first=this.colOut.length,this._expandColumns(t,c,t.a,t.b),c.last=this.colOut.length-1}}_colRows(t,s){return t===null||t.table===null?this._rootRows(s):this._rowsIn(t,s)}run(t,s){const{book:e,t:l}=this,a=this._templateExtent();this.extent=a;const f=this._buildTree("vertical",a),o=this._buildTree("horizontal",a),n=this._newContext(new O(null,null,U,null));n.first=0,this._emitBand(f,n,0,a.maxRow,-1),n.last=this.rowCount-1;const c=new O(null,null,U,null);this._expandColumns(o,c,0,a.maxCol),this._paginateRows(),this._paginateCols();const r=t??e.addSheet(s??`${l.name} Report`);this.outSheet=r,r.reportWriting=!0;const h=r.formulas.size>0;this._clear(r),this._writeGeometry(r),this._writeCells(r),this._writeMerges(r),this._writeSheetRules(r),this._writePageSetup(r),this._writeFormulas(r),this._applyAutoFit(r),l.layout&&this._applyLayoutSetting(r),this._saveMap(r),h&&e.engine?.rebuild(),r.reportWriting=!1,r.revision++,l.output=r;for(const i of this.helperViews.values())i.dispose();return{sheet:r,rows:this.rowCount,cols:this.colOut.length,pages:Et(e,r)}}_clear(t){t.columns=[],t.formulas=new Map,t.maxRow=-1,t.maxCol=-1,t.merges=[],t.mergeIndex=null,t.spills=null,t.rowStyles=null,t.colStyles=null,t.pageSetup=void 0,t.cf=void 0,t.cfEval=void 0,t.validations=void 0,t.sparklines=void 0,t.rows=new st(L,this.sheet.rows.defaultSize),t.cols=new st(P,this.sheet.cols.defaultSize),t.colsChanged=!0,t.viewChanged=!0}_writeGeometry(t){const{sheet:s}=this,{colOut:e,rowTpl:l,rowCount:a}=this;if(s.cols.sizes!==null)for(let o=0;o<e.length;o++){const n=s.cols.sizeOf(e[o].tpl);s.cols.isHidden(e[o].tpl)||(n!==t.cols.defaultSize||t.cols.isCustom(o))&&t.cols.setSize(o,n)}if(s.rows.sizes!==null)for(let o=0;o<a;o++){const n=l[o];s.rows.isCustom(n)&&!s.rows.isHidden(n)&&t.rows.setSize(o,s.rows.sizeOf(n))}if(!this.t.showHiddenRows&&s.rows.hiddenSizes?.size>0)for(let o=0;o<a;o++)s.rows.isHidden(l[o])&&t.rows.setHidden(o,!0);!this.t.showHiddenCols&&s.cols.hiddenSizes?.size>0&&e.forEach((o,n)=>{s.cols.isHidden(o.tpl)&&t.cols.setHidden(n,!0)}),s.colStyles&&(t.colStyles=new Map,e.forEach((o,n)=>{const c=s.colStyles.get(o.tpl);c!==void 0&&t.colStyles.set(n,c)}))}_writeCells(t){const{colOut:s,rowCount:e,rowTpl:l,rowCtx:a,rowRec:f,sheet:o,contexts:n}=this,{strings:c}=this.book,{bindings:r}=this.t,{overlay:h}=this,i=o.formulas.size>0,u=new Map;s.forEach((w,m)=>{u.has(w.tpl)||u.set(w.tpl,m)});const p=(w,m)=>{const C=M(w,m),k=r.get(C)??null,R=k!==null&&k.type==="static"?null:k,S=o.kind(w,m),y={binding:R,options:k!==null&&k.type==="static"?k:null,kind:S&~pt,value:o.value(w,m),style:o.cellStyle(w,m),table:R&&R.table?this._table(R.table):null,col:null,formula:S&J?o.formula(w,m):null,merged:o.mergeAt(w,m)};if(R&&R.type!=="param"&&R.type!=="chart"){if(y.col=R.formula?q(y.table,R.formula):y.table?.column(R.field)??null,!y.col&&!(R.type==="summary"&&R.agg==="countAll"))throw new T(A("No field {field} in {table}.",{field:R.field,table:R.table}));y.col&&y.table.ensure(y.col),R.collapse&&(y.style=this.book.styles.derive(y.style,{indent:1,hAlign:"left"})),R.format?y.style=this.book.styles.derive(y.style,{numFmt:R.format}):y.col&&y.col.format!=="General"&&(y.style===0||this.book.styles.get(y.style).numFmt==="General")&&(y.style=this.book.styles.derive(y.style,{numFmt:y.col.format}))}return y};for(let w=0;w<s.length;w++){const{tpl:m,ctx:C}=s[w];let k=-1;const R=[],S=u.get(m)===w;for(let y=0;y<e;y++){let x=l[y];if(h!==null){const _=h.get(y);_!==void 0&&r.get(M(_,m))?.type==="list"&&(x=_)}let b=R[x];b===void 0&&(b=p(x,m),R[x]=b);const d=b.binding;if(d===null){const _=b.options;if(_!==null){if(_.pin)continue;const v=_.autoExpand??"both";if((v==="none"||v==="horizontal")&&b.seen||(v==="none"||v==="vertical")&&!S)continue;b.seen=!0}if(b.formula){i&&this.formulas.push({or:y,oc:w,tr:x,tc:m,info:b.formula,ctx:n[a[y]],colCtx:C,style:b.style});continue}b.kind!==$&&t.setCell(y,w,b.kind,b.value),b.style!==0&&t.setStyle(y,w,b.style);continue}switch(b.style!==0&&t.setStyle(y,w,b.style),d.type){case"param":lt(t,y,w,this._param(d.param),c);break;case"list":{const _=d.expand==="horizontal"?this._recordAcross(C,b.table):this._recordFor(n[a[y]],f[y],b.table);_>=0&&it(t,y,w,b.col,_);break}case"group":{const _=this._groupContext(n[a[y]],C,d);if(_===null)break;if(_.index!==void 0&&!d.repeat){if(_.index===k&&!(d.repeatOnPage&&this.pageStartSet.has(y)))break;k=_.index}this._writeGroupValue(t,y,w,d,b,_);break}case"chart":this._writeChartCell(t,y,w,d,n[a[y]]);break;default:{if(f[y]===G)break;const _=this._summaryRows(n[a[y]],C,b.table,d,f[y]),v=b.col?Q(b.col,d.agg??"sum",_,0,_.length):d.agg==="countAll"?_.length:NaN;v===v&&t.setCell(y,w,B,v)}}}}}_writeChartCell(t,s,e,l,a){if(!l.source)return;const o=(this.tplRows??(this.tplRows=this._rowsByTemplate())).get(l.source.row),n=this.colOut.findIndex(u=>u.tpl===l.source.col);if(!o||n<0)return;const c=ot(o,a.first,a.last);if(c.length===0)return;const r=c[0][0],h=c[c.length-1][1];t.sparklines||(t.sparklines=[],t.sparklinesChanged=!0),this.sparkGroups||(this.sparkGroups=new Map);let i=this.sparkGroups.get(l);i||(i={type:l.chartType??"line",markers:!1,high:!1,low:!1,first:!1,last:!1,negative:l.chartType==="winloss",lineWeight:1,seriesColor:l.color??"#2f6fb3",negativeColor:"#c42b1c",markerColor:"#107c41",items:[]},this.sparkGroups.set(l,i),t.sparklines.push(i)),i.items.push({source:`${gt(t.name)}${H(n)}${r+1}:${H(n)}${h+1}`,cell:N(s,e)})}_rowsByTemplate(){const t=new Map;for(let s=0;s<this.rowCount;s++){const e=this.rowTpl[s];let l=t.get(e);l===void 0&&(l=[],t.set(e,l)),l.push(s)}return t}_writeSheetRules(t){const{sheet:s,colOut:e}=this,l=this.tplRows??(this.tplRows=this._rowsByTemplate()),a=new Map;e.forEach((o,n)=>{a.has(o.tpl)||a.set(o.tpl,[]),a.get(o.tpl).push(n)});const f=o=>{const n=[];for(const c of mt(o)){const r=[];for(let i=c.r0;i<=c.r1&&i<=this.extent.maxRow;i++)for(const u of l.get(i)??[])r.push(u);r.sort((i,u)=>i-u);const h=[];for(let i=c.c0;i<=c.c1&&i<=this.extent.maxCol;i++)for(const u of a.get(i)??[])h.push(u);h.sort((i,u)=>i-u);for(const[i,u]of at(r))for(const[p,w]of at(h))n.push(dt({r0:i,c0:p,r1:u,c1:w}))}return n.join(" ")};s.cf&&s.cf.length>0&&(t.cf=s.cf.map(({_ranges:o,...n})=>({...n,sqref:f(n.sqref)})).filter(o=>o.sqref),t.cfChanged=!0),s.validations&&s.validations.length>0&&(t.validations=s.validations.map(({_ranges:o,...n})=>({...n,sqref:f(n.sqref)})).filter(o=>o.sqref),t.validationsChanged=!0);for(const o of this.t.bindings.values()){if(o.type!=="static"||!o.pin)continue;const n=s.kind(o.row,o.col),c=o.pin==="column"?l.get(o.row)?.[0]??o.row:o.row,r=o.pin==="row"?a.get(o.col)?.[0]??o.col:o.col;(n&7)!==$&&t.setCell(c,r,n&7,s.value(o.row,o.col));const h=s.cellStyle(o.row,o.col);h&&t.setStyle(c,r,h)}}_applyAutoFit(t){const s=[...this.t.bindings.values()].filter(i=>i.autoFit);if(s.length===0)return;const e=this.t.measure??(i=>i.length*6.4),{colOut:l,rowTpl:a,rowCount:f,sheet:o}=this,{strings:n,styles:c}=this.book,r=(i,u)=>{const p=t.kind(i,u)&7;if(p===0)return"";if(p===E)return n.get(t.value(i,u));if(p===B){const w=c.get(t.style(i,u)).numFmt;return w&&w!=="General"?j(w).number(t.value(i,u)):String(t.value(i,u))}return"TRUE"},h=Math.min(f,1e5);for(const i of s)if(i.autoFit==="column")l.forEach((u,p)=>{if(u.tpl!==i.col)return;let w=o.cols.sizeOf(i.col);for(let m=0;m<h;m++)a[m]===i.row&&(w=Math.max(w,e(r(m,p))+8));w!==t.cols.sizeOf(p)&&t.cols.setSize(p,Math.ceil(w))});else{const u=l.findIndex(m=>m.tpl===i.col);if(u<0)continue;const p=Math.max(10,t.cols.sizeOf(u)-6),w=t.rows.defaultSize;for(let m=0;m<h;m++){if(a[m]!==i.row)continue;const C=Math.ceil(e(r(m,u))/p),k=Math.max(o.rows.sizeOf(i.row),C*w);k!==t.rows.sizeOf(m)&&t.rows.setSize(m,k)}}}_applyLayoutSetting(t){const{type:s,count:e,repeat:l=0}=this.t.layout;if(!(e>l))return;const a=[],f=t.maxRow,o=t.maxCol;for(let c=0;c<=f;c++)for(let r=0;r<=o;r++){const h=t.kind(c,r)&15,i=t.cellStyle(c,r);(h!==0||i!==0)&&a.push(c,r,h,t.value(c,r),i)}const n=e-l;t.columns=[],t.maxRow=-1,t.maxCol=-1;for(let c=0;c<a.length;c+=5){const[r,h,i,u,p]=[a[c],a[c+1],a[c+2],a[c+3],a[c+4]],w=(m,C)=>{i!==0&&t.setCell(m,C,i,u),p!==0&&t.setStyle(m,C,p)};if(s==="row"){const m=o+1;if(r<l){const C=Math.max(1,Math.ceil((f+1-l)/n));for(let k=0;k<C;k++)w(r,h+k*m)}else{const C=Math.floor((r-l)/n);w(l+(r-l)%n,h+C*m)}}else{const m=f+1;if(h<l){const C=Math.max(1,Math.ceil((o+1-l)/n));for(let k=0;k<C;k++)w(r+k*m,h)}else{const C=Math.floor((h-l)/n);w(r+C*m,l+(h-l)%n)}}}}_saveMap(t){const{rowTpl:s,rowRec:e,rowCtx:l,rowCount:a,colOut:f,contexts:o,collapses:n}=this,c=new Map;f.forEach((h,i)=>{c.has(h.tpl)||c.set(h.tpl,i)});const r=n.map(h=>({...h,col:c.get(h.binding.col)??0}));t.reportMap={template:this.t,rowTpl:s.subarray(0,a),rowRec:e.subarray(0,a),rowCtx:l.subarray(0,a),contexts:o,colTpl:f.map(h=>h.tpl),collapses:r,overlay:this.overlay,book:this.book,layout:this.t.layout??null},r.some(h=>h.collapsed)&&ct(t)}_groupContext(t,s,e){for(let l=t;l!==null;l=l.parent)if(l.node?.binding===e)return l;for(let l=s;l!==null;l=l.parent)if(l.node?.binding===e)return l;return null}_writeGroupValue(t,s,e,l,a,f){const o=f.rows.length>0?f.rows[0]:-1;if(o<0)return;const n=a.col.get(o);if(l.bins){const c=l.bins.find(r=>typeof n=="number"&&(r.min===void 0||n>=r.min)&&(r.max===void 0||n<r.max));t.setCell(s,e,E,this.book.strings.add(c?.name??"(other)"))}else if(typeof n=="number"&&l.by&&l.by!=="value")t.setCell(s,e,E,this.book.strings.add(Ot(n,l.by)));else if(typeof n=="number"&&l.size>0){const c=Math.floor(n/l.size)*l.size;t.setCell(s,e,E,this.book.strings.add(`${c} to ${c+l.size}`))}else it(t,s,e,a.col,o)}_recordAcross(t,s){for(let e=t;e!==null&&e.node!==null;e=e.parent)if(e.table===s)return e.rows.length>0?e.rows[0]:-1;return-1}_recordFor(t,s,e){if(s===G)return-1;if(s>=0&&(t.table===e||t.table===null))return s;for(let a=t;a!==null;a=a.parent)if(a.table===e&&a.rows.length>0)return s>=0&&a===t?s:a.rows[0];const l=this._rowsIn(t,e);return l.length>0?l[0]:-1}_summaryRows(t,s,e,l,a){let f=t.table===e&&a>=0?Int32Array.of(a):this._rowsIn(t.table===null?null:t,e);for(let o=s;o!==null&&o.node!==null;o=o.parent){const n=o.node.binding;if(o.table!==e)continue;const c=nt(e,n);let r=this.keyCache.get(c);r===void 0&&(r=tt(e,n),this.keyCache.set(c,r));const h=r[o.rows[0]],i=new Int32Array(f.length);let u=0;for(let p=0;p<f.length;p++){const w=r[f[p]];(w===h||w!==w&&h!==h)&&(i[u++]=f[p])}f=i.subarray(0,u)}return l.filters?.length&&(f=this._prepareRows(f,{...l,sort:null,sortBy:null},e)),f}_writeMerges(t){const{sheet:s,rowTpl:e,rowCtx:l,rowCount:a,colOut:f,groupMerges:o}=this,n=new Map;f.forEach((r,h)=>{n.has(r.tpl)||n.set(r.tpl,[]),n.get(r.tpl).push(h)});const c=new Set;for(const r of o){const{binding:h,r0:i,r1:u}=r,p=s.mergeAt(h.row,h.col),w=p?p.c0:h.col,m=p?p.c1:h.col;p&&c.add(p);const C=[];let k=i;if(h.repeatOnPage)for(let R=i+1;R<=u;R++)this.pageStartSet.has(R)&&(C.push([k,R-1]),k=R);C.push([k,u]);for(const R of n.get(w)??[]){const S=R+(m-w);for(const[y,x]of C)(x>y||S>R)&&t.addMerge({r0:y,c0:R,r1:x,c1:S})}}for(const r of s.merges){if(c.has(r)||this.t.bindings.has(M(r.r0,r.c0))){const i=this.t.bindings.get(M(r.r0,r.c0));if(i&&(i.type==="group"||i.type==="list")&&i.expand==="vertical")continue}if(c.has(r))continue;const h=r.r1-r.r0;for(let i=0;i<a;i++){if(e[i]!==r.r0||i+h>=a)continue;let u=!0;for(let p=1;p<=h;p++)(e[i+p]!==r.r0+p||l[i+p]!==l[i])&&(u=!1);if(u)for(const p of n.get(r.c0)??[]){const w=p+(r.c1-r.c0);w<f.length&&t.addMerge({r0:i,c0:p,r1:i+h,c1:w})}}}}_writePageSetup(t){const{t:s,rowTpl:e,rowCount:l}=this,a=_t(t),f=this.sheet.pageSetup;if(f)for(const n of["orientation","paperSize","paperWidth","paperHeight","scale","fitToPage","fitToWidth","fitToHeight","horizontalCentered","verticalCentered","header","footer","headings","gridLines","margins"])f[n]!==void 0&&(a[n]=f[n]);s.pageSetup&&Object.assign(a,s.pageSetup);const o=s.pagination;if(o?.order&&(a.pageOrder=o.order),a.rowBreaks=[...new Set(this.breaks)].filter(n=>n>0&&n<l).sort((n,c)=>n-c),a.colBreaks=[...new Set(this.colBreaks)].filter(n=>n>0&&n<this.colOut.length).sort((n,c)=>n-c),o?.titleCols){let n=-1,c=-1;this.colOut.forEach((r,h)=>{r.tpl>=o.titleCols.c0&&r.tpl<=o.titleCols.c1&&(n<0||h===c+1)&&(n<0&&(n=h),c=h)}),n>=0&&(a.titleCols={c0:n,c1:c})}if(s.titleRows){let n=-1,c=-1;for(let r=0;r<l;r++){const h=e[r];if(h>=s.titleRows.r0&&h<=s.titleRows.r1)n<0&&(n=r),c=r;else if(n>=0)break}n>=0&&(a.titleRows={r0:n,r1:c})}t.pageSetupChanged=!0}_writeFormulas(t){if(this.formulas.length===0)return;const{rowTpl:s,rowCount:e,colOut:l}=this,a=new Map;for(let r=0;r<e;r++){const h=s[r];let i=a.get(h);i===void 0&&(i=[],a.set(h,i)),i.push(r)}const f=new Map;l.forEach((r,h)=>{f.has(r.tpl)||f.set(r.tpl,[]),f.get(r.tpl).push(h)});const o=new Uint32Array(this.formulas.length),n=new Uint16Array(this.formulas.length);this.formulas.forEach((r,h)=>{const{or:i,oc:u,tr:p,tc:w,info:m,ctx:C,style:k}=r,R=m.f??yt(m.sf,p-Math.floor(m.base/P),w-m.base%P),S=this._reportFunctions(R,i,C),y=Mt(S,(x,b,d,_)=>{const v=a.get(b),z=f.get(_);if(!v||!z)return null;const W=b===p?[[i,i]]:ot(v,C.first,C.last);if(W.length===0)return"#REF!";let I,F;return _===w?(I=u,F=u):(I=z[0],F=z[z.length-1]),W.map(([D,K])=>{const X=`${d}${H(I)}${x}${D+1}`;return D===K&&I===F?X:`${X}:${d}${H(F)}${x}${K+1}`}).join(",")});if(y.length>St){t.setCell(i,u,Z,Ct.REF.index),k!==0&&t.setStyle(i,u,k),o[h]=i,n[h]=u;return}t.setCell(i,u,J|$,0),t.setFormula(i,u,{f:y,typed:!0}),k!==0&&t.setStyle(i,u,k),o[h]=i,n[h]=u}),this.book.engine?.cellsChanged(t,o,n,o.length),this.book.formulasEdited=!0;const c=this.book.engine;c&&this.formulas.forEach(r=>{if(this.t.bindings.get(M(r.tr,r.tc))?.preserveFormula!==!1)return;const i=c.read(t,r.or,r.oc);t.setFormula(r.or,r.oc,null),t.setCell(r.or,r.oc,$,0),lt(t,r.or,r.oc,i,this.book.strings)})}_reportFunctions(t,s,e){if(!/RPT_/i.test(t))return t;const l=n=>this._measureCell(f(n),s,e),a=n=>{const c=n.trim();for(const r of this.t.bindings.values())if(r.alias===c)return N(r.row,r.col);return c},f=a,o=n=>n==null?'""':String(n);return t.replace(/RPT_RANK\(\s*([^()]+?)\s*\)/gi,(n,c)=>{const r=l(c);return r?o(1+r.values.filter(h=>h>r.current).length):'""'}).replace(/RPT_PROPORTION\(\s*([^()]+?)\s*\)/gi,(n,c)=>{const r=l(c),h=r?r.values.reduce((i,u)=>i+u,0):0;return r&&h!==0?o(r.current/h):'""'}).replace(/RPT_CUMULATIVE\(\s*([^()]+?)\s*\)/gi,(n,c)=>{const r=l(c);return r?o(r.values.slice(0,r.at+1).reduce((h,i)=>h+i,0)):'""'}).replace(/RPT_(MOM|YOY)\(\s*([^()]+?)\s*\)/gi,(n,c,r)=>{const h=l(r);if(!h)return'""';const i=c.toUpperCase()==="MOM"?1:{month:12,quarter:4,year:1,week:52}[h.by]??12,u=h.values[h.at-i];return u===void 0||u===0?'""':o((h.current-u)/u)}).replace(/RPT_VALUE\(\s*([^()]+?)\s*\)/gi,(n,c)=>a(c)).replace(/RPT_PARAM\(\s*"([^"]+)"\s*\)/gi,(n,c)=>{const r=this._param(c);return typeof r=="number"?String(r):`"${String(r??"").replace(/"/g,'""')}"`}).replace(/RPT_INDEX\(\s*([^()]+?)\s*\)/gi,(n,c)=>{const r=Y(a(c).replace(/\$/g,"")),h=r?this.t.binding(r.r0,r.c0):null;for(let i=e;i!==null;i=i.parent)if(i.node?.binding===h)return String(i.ordinal??1);return"1"}).replace(/RPT_PAGES\(\s*(TRUE)?\s*\)/gi,(n,c)=>{const r=this._pageStarts();if(!c)return String(r.length);const h=this._topContext(e);return String(r.filter(i=>i>=h.first&&i<=h.last).length||1)}).replace(/RPT_PAGE\(\s*(TRUE)?\s*\)/gi,(n,c)=>{const r=this._pageStarts();let h=0;for(let p=0;p<r.length;p++)r[p]<=s&&(h=p);if(!c)return String(h+1);const i=this._topContext(e);let u=0;for(;u<h&&r[u]<i.first;)u++;return String(h-u+1)})}_topContext(t){let s=t;for(let e=t;e!=null&&e.node;e=e.parent)s=e;return s}_measureCell(t,s,e){const l=Y(t.replace(/\$/g,""));if(!l)return null;const a=this.outSheet,f=this.colOut.findIndex(p=>p.tpl===l.c0);if(f<0)return null;let o=e;for(;o&&!o.node&&o.parent;)o=o.parent;const n=o?.node?.binding?.type==="list"?o:o?.parent??o,c=n?.first??0,r=n?.last??this.rowCount-1,h=[];let i=-1,u=1/0;for(let p=c;p<=r;p++){if(this.rowTpl[p]!==l.r0||(a.kind(p,f)&ut)!==B)continue;const m=Math.abs(p-s);(p<=s||i<0)&&m<u&&(u=m,i=h.length),h.push(a.value(p,f))}return i<0||h.length===0?null:{values:h,at:i,current:h[i],by:o?.node?.binding?.by??null}}_pageStarts(){if(this.pageStarts)return this.pageStarts;const t=V(this.book,this.outSheet),s=[];for(let e=0;e<t.pageCount;e++)s.push(t.page(e).r0);return this.pageStarts=s,s}}function ot(g,t,s){const e=[];let l=0,a=g.length;if(t>=0)for(;l<a;){const f=l+a>>>1;g[f]<t?l=f+1:a=f}for(let f=l;f<g.length;f++){const o=g[f];if(t>=0&&o>s)break;const n=e[e.length-1];n&&n[1]===o-1?n[1]=o:e.push([o,o])}return e}function Mt(g,t){let s="",e=0;const l=g.length,a=/(\$?)([A-Za-z]{1,3})(\$?)(\d+)(?::(\$?)([A-Za-z]{1,3})(\$?)(\d+))?/y;for(;e<l;){const f=g[e];if(f==='"'){let c=e+1;for(;c<l;)if(g[c]==='"')if(g[c+1]==='"')c+=2;else break;else c++;s+=g.slice(e,c+1),e=c+1;continue}if(f==="'"){const c=g.indexOf("'!",e+1);if(c>=0){const r=/^\$?[A-Za-z]{1,3}\$?\d+(:\$?[A-Za-z]{1,3}\$?\d+)?/.exec(g.slice(c+2)),h=c+2+(r?r[0].length:0);s+=g.slice(e,h),e=h;continue}}a.lastIndex=e;const o=e>0?g[e-1]:"",n=/[A-Za-z0-9_.!$]/.test(o)?null:a.exec(g);if(n){const c=g[e+n[0].length]??"";if(!/[A-Za-z0-9_.(!]/.test(c)){const r=(i,u,p,w)=>t(p,Number(w)-1,i,wt(u.toUpperCase())),h=r(n[1],n[2],n[3],n[4]);if(n[6]===void 0)s+=h??n[0];else{const i=r(n[5],n[6],n[7],n[8]);s+=h===null||i===null?n[0]:`${h.split(/[:,]/)[0]}:${i.split(/[:,]/).pop()}`}e+=n[0].length;continue}}s+=f,e++}return s}function Tt(g,t,s){const e=new Float64Array(g.length);for(let f=0;f<g.length;f++)e[f]=t[g[f]];const l=new Int32Array(g.length);for(let f=0;f<g.length;f++)l[f]=f;kt(l,g.length,e,s);const a=new Int32Array(g.length);for(let f=0;f<g.length;f++)a[f]=g[l[f]];g.set(a)}const At=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Ot(g,t){const e=j("yyyy-mm").number(Math.floor(g)),l=Number(e.slice(0,4)),a=Number(e.slice(5,7));switch(t){case"year":return String(l);case"quarter":return`Q${Math.floor((a-1)/3)+1} ${l}`;case"month":return`${At[a-1]} ${l}`;default:return j("yyyy-mm-dd").number(Math.floor(g))}}function it(g,t,s,e,l){const a=e.kind(l);a!==$&&g.setCell(t,s,a,e.raw(l))}function lt(g,t,s,e,l){e==null||e===""||(typeof e=="number"?g.setCell(t,s,B,e):typeof e=="boolean"?g.setCell(t,s,ft,e?1:0):e instanceof bt?g.setCell(t,s,Z,e.index):g.setCell(t,s,E,l.add(Array.isArray(e)?e.join(", "):String(e))))}function at(g){const t=[];for(const s of g){const e=t[t.length-1];e&&(e[1]===s||e[1]===s-1)?e[1]=s:t.push([s,s])}return t}function ct(g){const t=g.reportMap;if(t){for(const s of t.collapses)for(let e=s.from;e<=s.to;e++)g.rows.setHidden(e,!1);for(const s of t.collapses)if(s.collapsed)for(let e=s.from;e<=s.to;e++)g.rows.setHidden(e,!0);g.revision++}}function jt(g,t,s,e=void 0,l=!1){const a=g.reportMap;if(!a)return!1;const f=a.collapses.find(n=>n.row===t&&(s===void 0||n.col===s));if(!f)return!1;const o=e===void 0?!f.collapsed:e==="collapsed"||e===!0;if(f.collapsed=o,l)for(const n of a.collapses)n.from>=f.from&&n.to<=f.to&&(n.collapsed=o);return ct(g),!0}function Et(g,t,s={}){return V(g,t,s).pageCount}export{Rt as BINDING_TYPES,T as ReportError,ht as ReportTemplate,ct as applyCollapses,Et as reportPages,jt as toggleCollapse};
|
|
1
|
+
import{BOOL as ft,EMPTY as $,ERR as Z,FORMULA as J,KIND_MASK as ut,NUM as B,SPILL as pt,STR as E}from"../core/sheet.js";import{cellRef as N,colName as H,colIndex as wt,MAX_COLS as P,MAX_ROWS as L,parseRangeRef as Y,rangeRef as dt,sheetPrefix as gt}from"../core/address.js";import{rangesOf as mt}from"../core/cond-format.js";import{translateFormula as yt}from"../core/formula-refs.js";import{getPageSetup as _t}from"../print/page-setup.js";import{paginate as V}from"../print/paginate.js";import{getFormatter as j}from"../core/numfmt.js";import{ERR as Ct,XlError as bt}from"../calc/values.js";import{aggregate as Q,formulaHelper as q,groupKeys as tt,TableView as et}from"./view.js";import{sortByF64 as kt}from"./sort.js";import{Axis as st}from"../core/axis.js";import{t as A}from"../i18n/index.js";const Rt=["group","list","summary","param","static","chart"],M=(g,t)=>g*P+t,U=new Int32Array(0),G=-2,St=8e3;class O{constructor(t,s,e,l=null,a=void 0){this.parent=t,this.table=s,this.rows=e,this.node=l,this.value=a,this.first=-1,this.last=-1,this.resolved=null}}class T extends Error{}class ht{constructor(t,s,e={}){this.manager=t,this.sheet=s,this.bindings=new Map,this.params=new Map,this.filters=[],this.titleRows=e.titleRows??null,this.pageSetup=e.pageSetup??null,this.defaultTable=e.table??null,this.name=e.name??s.name,this.output=null,this.mode=e.mode??"design",this.pagination=e.pagination??null,this.layout=e.layout??null,this.dataEntry=e.dataEntry??null,this.charts=e.charts??[],this.pictures=e.pictures??[],this.states=e.states??null,this.measure=e.measure??null,this.showHiddenRows=e.showHiddenRows===!0,this.showHiddenCols=e.showHiddenCols===!0,this.listeners=new Map,s.report=this}setBinding(t,s,e){const l=e.type;if(!Rt.includes(l))throw new T(`Unknown binding type: ${l}`);const a={table:this.defaultTable,expand:l==="group"||l==="list"?"vertical":"none",agg:"sum",sort:l==="group"?"asc":null,...e,row:t,col:s};return this.bindings.set(M(t,s),a),a}binding(t,s){return this.bindings.get(M(t,s))??null}removeBinding(t,s){this.bindings.delete(M(t,s))}static markerText(t){switch(t.type){case"group":return`[${t.field}]`;case"list":return`=[${t.field}]`;case"summary":return`${t.agg??"sum"}[${t.field}]`;case"chart":return`chart[${t.chartType??"line"}]`;default:return`{${t.param}}`}}writeMarkers(t){t.sheet===this.sheet&&t.transact("report binding",s=>{for(const e of this.bindings.values())e.type!=="static"&&(s.saveCell(e.row,e.col),this.sheet.setFormula(e.row,e.col,null),this.sheet.setCell(e.row,e.col,E,t.strings.add(ht.markerText(e))))})}addParam(t,s={}){this.params.set(t,{name:t,caption:s.caption??t,type:s.type??"string",value:s.value??null,options:s.options??null})}setParam(t,s){const e=this.params.get(t);if(!e)throw new T(A("No parameter named {name}.",{name:t}));e.value=s}on(t,s){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(s),()=>this.listeners.get(t).delete(s)}fire(t,s){let e=!0;for(const l of this.listeners.get(t)??[])l(s)===!1&&(e=!1);return e}addFilter(t){this.filters.push(t)}generate(t,{target:s=null,name:e=null,params:l=null,measure:a=null}={}){if(l)for(const[o,n]of Object.entries(l))this.setParam(o,n);a&&(this.measure=a),this.fire("stage",{stage:"start"});const f=new xt(this,t).run(s,e);return this.fire("stage",{stage:"done",result:f}),f}async generateAsync(t,s){return await new Promise(e=>setTimeout(e,0)),this.generate(t,s)}toJSON(){return{name:this.name,sheet:this.sheet.name,table:this.defaultTable,bindings:[...this.bindings.values()].map(t=>({...t})),params:[...this.params.values()],filters:this.filters,titleRows:this.titleRows,pageSetup:this.pageSetup,output:this.output?.name??null,mode:this.mode,pagination:this.pagination,layout:this.layout,dataEntry:this.dataEntry,charts:this.charts,pictures:this.pictures,states:this.states,showHiddenRows:this.showHiddenRows,showHiddenCols:this.showHiddenCols}}}const nt=(g,t)=>`${g.name}|${t.formula??t.field}|${t.by??""}|${t.size??""}|${t.bins?JSON.stringify(t.bins):""}`,vt=g=>{let t=0;for(let s=g.parent;s!==null;s=s.parent)t++;return t};class rt{constructor(t,s,e,l){this.binding=t,this.a=s,this.b=e,this.parent=l,this.children=[],this.members=[]}}class xt{constructor(t,s){this.t=t,this.book=s,this.manager=t.manager,this.sheet=t.sheet,this.roots=new Map,this.keyCache=new Map,this.helperViews=new Map,this.cellInfo=new Map,this.groupMerges=[],this.collapses=[],this.overlay=null,this.breaks=[],this.formulas=[],this.memberColumns=new Map,this.rowCap=1024,this.rowTpl=new Int32Array(this.rowCap),this.rowCtx=new Int32Array(this.rowCap),this.rowRec=new Int32Array(this.rowCap),this.rowCount=0,this.contexts=[],this.colOut=[]}_table(t){if(!t)throw new T(A("A binding needs a table."));return this.manager.table(t)}_templateExtent(){const{sheet:t}=this;let s=t.maxRow,e=t.maxCol;for(const l of this.t.bindings.values())l.row>s&&(s=l.row),l.col>e&&(e=l.col);for(const l of t.merges)l.r1>s&&(s=l.r1),l.c1>e&&(e=l.c1);return{maxRow:s,maxCol:e}}_buildTree(t,s){const e=t==="vertical",l=i=>e?i.row:i.col,a=i=>e?i.col:i.row,f=[...this.t.bindings.values()].filter(i=>(i.type==="group"||i.type==="list")&&i.expand===t);f.sort((i,u)=>a(i)-a(u)||l(i)-l(u));const o=new rt(null,0,e?s.maxRow:s.maxCol,null),n=new Map,c=i=>{if(i.span>1)return l(i)+i.span-1;const u=this.sheet.mergeAt(i.row,i.col);return u?e?u.r1:u.c1:l(i)},r=i=>{if(i.parent==="none")return o;if(i.parent){const p=n.get(M(i.parent.row,i.parent.col));if(p)return p}let u=o;for(const p of n.values())a(p.binding)>=a(i)||l(i)<p.a||l(i)>p.b||p.a>=u.a&&(u===o||a(p.binding)>=a(u.binding))&&(u=p);return u};for(const i of f){const u=r(i);if(i.type==="list"&&u!==o&&u.binding.type==="list"&&l(u.binding)===l(i)&&u.binding.table===i.table){u.members.push(i);continue}if(i.type==="list"){const w=u.children.find(m=>m.binding.type==="list"&&l(m.binding)===l(i)&&m.binding.table===i.table);if(w){w.members.push(i);continue}}const p=new rt(i,l(i),c(i),u);u.children.push(p),n.set(M(i.row,i.col),p)}const h=i=>{i.children.sort((u,p)=>u.a-p.a);for(const u of i.children)h(u),i!==o&&u.b>i.b&&(i.b=u.b),i!==o&&u.a<i.a&&(i.a=u.a);for(let u=1;u<i.children.length;u++)if(i.children[u].a<=i.children[u-1].b){const p=i.children[u].binding,w=i.children[u-1].binding;throw new T(A("The cells {first} and {second} expand over the same rows but neither is the other's parent.",{first:N(p.row,p.col),second:N(w.row,w.col)}))}};return h(o),o}_rootRows(t){let s=this.roots.get(t);if(s!==void 0)return s;const e=this.t.filters.filter(a=>this.manager.table(a.table??this.t.defaultTable)===t).map(a=>this._resolveFilter(a)),l=new et(t,{columns:[],filters:e});return s=l.filtered.slice(0,l.filteredCount),l.dispose(),this.roots.set(t,s),s}_resolveFilter(t){const s={...t};if(t.param&&(s.value=this._param(t.param)),t.param2&&(s.value2=this._param(t.param2)),t.valuesParam){const e=this._param(t.valuesParam);s.values=Array.isArray(e)?e:[e],s.op=s.op??"in"}return s}_param(t){const s=this.t.params.get(t);if(!s)throw new T(A("No parameter named {name}.",{name:t}));return s.value}_filterActive(t){if(t.param&&(this._param(t.param)===null||this._param(t.param)===""))return!1;if(t.valuesParam){const s=this._param(t.valuesParam);if(s===null||s===""||Array.isArray(s)&&s.length===0)return!1}return!0}_rowsIn(t,s){if(t===null)return this._rootRows(s);if(t.table===s)return t.rows;t.resolved===null&&(t.resolved=new Map);let e=t.resolved.get(s);return e!==void 0||(e=this._crossRows(t,s),t.resolved.set(s,e)),e}_crossRows(t,s){for(let e=t;e!==null;e=e.parent){if(e.table===s)return e.rows;if(e.table===null)continue;const l=e.node?.binding.link;if(l)return this._joinRows(e,s,l.from,l.to);const a=this.manager.relationshipBetween(e.table,s);if(!a)continue;const f=this._rootMask(s);if(a.to===e.table){const{starts:r,rows:h}=a.children();let i=0;for(let w=0;w<e.rows.length;w++)i+=r[e.rows[w]+1]-r[e.rows[w]];const u=new Int32Array(i);let p=0;for(let w=0;w<e.rows.length;w++){const m=e.rows[w];for(let C=r[m];C<r[m+1];C++)(f===null||f[h[C]]===1)&&(u[p++]=h[C])}return p===i?u:u.slice(0,p)}const o=a.parents(),n=new Uint8Array(s.rowCount),c=[];for(let r=0;r<e.rows.length;r++){const h=o[e.rows[r]];h>=0&&n[h]===0&&(f===null||f[h]===1)&&(n[h]=1,c.push(h))}return Int32Array.from(c)}return this._rootRows(s)}_rootMask(t){if(!this.t.filters.some(e=>this.manager.table(e.table??this.t.defaultTable)===t))return null;const s=new Uint8Array(t.rowCount);for(const e of this._rootRows(t))s[e]=1;return s}_joinRows(t,s,e,l){const a=new Set,f=t.table.column(e);for(let r=0;r<t.rows.length;r++)a.add(String(f.get(t.rows[r])));const o=s.column(l),n=this._rootRows(s),c=[];for(let r=0;r<n.length;r++)a.has(String(o.get(n[r])))&&c.push(n[r]);return Int32Array.from(c)}_helperView(t){let s=this.helperViews.get(t);return s===void 0&&(s=new et(t,{columns:[]}),this.helperViews.set(t,s)),s}_prepareRows(t,s,e,l=null){let a=t;const f=(s.filters??[]).filter(o=>this._filterActive(o)).map(o=>this._resolveFilter(o));if(f.length>0||s.filter){const o=this._helperView(e),n=new Uint8Array(e.rowCount);for(let h=0;h<a.length;h++)n[a[h]]=1;for(const h of f)o._applyCondition(h,n,e.rowCount);s.filter&&this._applyFilterTree(s.filter,n,e,o,l);const c=new Int32Array(a.length);let r=0;for(let h=0;h<a.length;h++)n[a[h]]===1&&(c[r++]=a[h]);a=c.subarray(0,r)}if(s.sortFormula)a=a===t?t.slice():a,this._helperView(e)._sortColumn(a,a.length,q(e,s.sortFormula),s.sort==="desc");else if(s.sort||s.sortBy){const o=e.column(s.sortBy??s.field);o&&(a=a===t?t.slice():a,this._helperView(e)._sortColumn(a,a.length,o,s.sort==="desc"))}return a}_applyFilterTree(t,s,e,l,a){const f=e.rowCount;if(t.and){for(const n of t.and)this._applyFilterTree(n,s,e,l,a);return}if(t.or){const n=new Uint8Array(f);for(const c of t.or){const r=s.slice();this._applyFilterTree(c,r,e,l,a);for(let h=0;h<f;h++)n[h]|=r[h]}s.set(n);return}if(t.param!==void 0&&!this._filterActive(t))return;const o=this._resolveFilter(t);if(t.cell){const n=this.t.binding(t.cell.row,t.cell.col);for(let c=a;c!=null;c=c.parent)if(c.node?.binding===n&&c.rows.length>0){o.value=c.table.column(n.field).get(c.rows[0]);break}}if(t.join){const n=this._table(t.join.table),c=n.column(t.join.field),r=a?this._rowsIn(a,n):this._rootRows(n),h=new Set;for(let i=0;i<r.length;i++)h.add(c.get(r[i]));o.op="in",o.values=[...h]}l._applyCondition(o,s,f)}_partition(t,s,e,l=null){const a=this._prepareRows(t,{...s,sort:null,sortBy:null,sortFormula:null},e,l),f=nt(e,s);let o=this.keyCache.get(f);if(o===void 0){if(o=tt(e,s),o===null)throw new T(A("No field {field} in {table}.",{field:s.field,table:e.name}));this.keyCache.set(f,o)}const n=a===t?t.slice():a;s.sort&&Tt(n,o,s.sort==="desc");const c=[],r=s.sort?null:new Map;let h=0;const i=n.length;if(s.sort)for(;h<i;){const u=o[n[h]];let p=h+1;if(u===u)for(;p<i&&o[n[p]]===u;)p++;else for(;p<i&&o[n[p]]!==o[n[p]];)p++;c.push(n.subarray(h,p)),h=p}else{for(;h<i;h++){const u=o[n[h]],p=u!==u?"blank":u,w=r.get(p);w?w.push(n[h]):r.set(p,[n[h]])}for(const u of r.values())c.push(Int32Array.from(u))}return this._orderGroups(c,s,e)}_orderGroups(t,s,e){if(s.sortList){const l=s.formula?q(e,s.formula):e.column(s.field),a=new Map(s.sortList.map((o,n)=>[String(o).toLowerCase(),n])),f=o=>a.get(String(l.get(o[0])).toLowerCase())??1/0;return t.map((o,n)=>[o,f(o),n]).sort((o,n)=>o[1]-n[1]||o[2]-n[2]).map(o=>o[0])}if(s.sortCell){const l=this.t.binding(s.sortCell.row,s.sortCell.col),a=l&&l.field?e.column(l.field):null;if(a){const f=s.sort==="desc"?-1:1,o=n=>Q(a,l.agg??"sum",n,0,n.length);return t.map(n=>[n,o(n)]).sort((n,c)=>f*(n[1]-c[1])).map(n=>n[0])}}return t}_paginateRows(){const{t}=this,s=t.pagination,e=new Set,l=new Set;for(const n of t.bindings.values())n.pageBefore&&e.add(n.row),n.pageAfter&&l.add(n.row);if(e.size>0||l.size>0)for(let n=0;n<this.rowCount;n++){const c=this.rowTpl[n];e.has(c)&&n>0&&this.breaks.push(n),l.has(c)&&this.breaks.push(n+1)}const a=s?.endRows??null,f=t.titleRows?t.titleRows.r1-t.titleRows.r0+1:0;let o=s?.rowsPerPage>0?s.rowsPerPage:0;if(a&&o===0){const n=V(this.book,this.sheet).box.h,c=a.r1-a.r0+1;o=Math.max(1,Math.floor(n/this.sheet.rows.defaultSize)-f-c)}if(a)this._repeatEndRows(a,o,f);else if(o>0)for(const n of this._rowPageStarts(this.rowCount,o,f,new Set(this.breaks)))this.breaks.push(n);this.pageStartSet=new Set(this.breaks)}_rowPageStarts(t,s,e,l){const a=[];for(const i of this.contexts)i.node?.binding?.keepTogether&&i.first!==void 0&&i.last>i.first&&a.push(i);a.sort((i,u)=>i.first-u.first);const f=[];let o=0,n=e+s,c=0;const r=[...l].sort((i,u)=>i-u);let h=0;for(;o+n<t;){let i=o+n;for(;h<r.length&&r[h]<=o;)h++;for(h<r.length&&r[h]<i&&(i=r[h]);c<a.length&&a[c].last<i;)c++;c<a.length&&a[c].first<i&&a[c].first>o&&a[c].last>=i&&(i=a[c].first),f.push(i),o=i,n=s}return f}_repeatEndRows(t,s,e){const l=this.rowCount,{rowTpl:a,rowCtx:f,rowRec:o}=this,n=[],c=[];for(let d=0;d<l;d++)(a[d]>=t.r0&&a[d]<=t.r1?c:n).push(d);if(c.length===0||n.length===0)return;const r=new Int32Array(l).fill(-1);n.forEach((d,_)=>{r[d]=_});const h=new Set;for(const d of this.breaks){let _=d;for(;_<l&&r[_]<0;)_++;_<l&&h.add(r[_])}const i=this.contexts.map(d=>[d.first,d.last]);for(const d of this.contexts){if(d.first===void 0||d.first<0)continue;let _=d.first;for(;_<l&&r[_]<0;)_++;let v=d.last;for(;v>0&&r[v]<0;)v--;d.first=_<l?r[_]:0,d.last=v>=0&&r[v]>=0?r[v]:d.first}const u=s>0?this._rowPageStarts(n.length,s,e,h):[...h].sort((d,_)=>d-_);i.forEach(([d,_],v)=>{this.contexts[v].first=d,this.contexts[v].last=_});const p=n.length+c.length*(u.length+1),w=new Int32Array(p),m=new Int32Array(p),C=new Int32Array(p),k=new Int32Array(l).fill(-1),R=[];let S=0,y=0;const x=()=>{c.forEach(d=>{w[S]=a[d],m[S]=f[d],C[S]=o[d],k[d]<0&&(k[d]=S),S++})};n.forEach((d,_)=>{y<u.length&&u[y]===_&&(x(),R.push(S),y++),w[S]=a[d],m[S]=f[d],C[S]=o[d],k[d]=S,S++}),x(),this.rowTpl=w,this.rowCtx=m,this.rowRec=C,this.rowCount=p,this.rowCap=p,this.breaks=R;const b=d=>d>=0&&d<l&&k[d]>=0?k[d]:d;for(const d of this.contexts)d.first!==void 0&&(d.first=b(d.first)),d.last!==void 0&&(d.last=b(d.last));for(const d of this.collapses)d.row=b(d.row),d.from=b(d.from),d.to=b(d.to);for(const d of this.groupMerges)d.r0=b(d.r0),d.r1=b(d.r1);this.overlay&&(this.overlay=new Map([...this.overlay].map(([d,_])=>[b(d),_])))}_paginateCols(){const{t}=this,s=t.pagination;this.colBreaks=[];const e=new Set,l=new Set;for(const p of t.bindings.values())p.colPageBefore&&e.add(p.col),p.colPageAfter&&l.add(p.col);const a=s?.endCols??null,f=p=>a&&p.tpl>=a.c0&&p.tpl<=a.c1,o=a?this.colOut.filter(f):[],n=a?this.colOut.filter(p=>!f(p)):this.colOut,c=s?.colsPerPage>0?s.colsPerPage:0,r=[],h=s?.titleCols?s.titleCols.c1-s.titleCols.c0+1:0;let i=0,u=h+c;n.forEach((p,w)=>{w>0&&(c>0&&i>=u||e.has(p.tpl)||l.has(n[w-1].tpl))&&(r.push(...o),this.colBreaks.push(r.length),i=0,u=c),r.push(p),i++}),r.push(...o),this.colOut=r}_pushRow(t,s,e){if(this.rowCount===this.rowCap){const a=this.rowCap*2,f=o=>{const n=new Int32Array(a);return n.set(o),n};this.rowTpl=f(this.rowTpl),this.rowCtx=f(this.rowCtx),this.rowRec=f(this.rowRec),this.rowCap=a}if(this.rowCount>=L)throw new T(A("The report needs more than {count} rows. Add a filter.",{count:L}));const l=this.rowCount++;return this.rowTpl[l]=t,this.rowCtx[l]=s,this.rowRec[l]=e,l}_newContext(t){return this.contexts.push(t),t.index=this.contexts.length-1,t}_emitBand(t,s,e,l,a){let f=e;const o=t.children;let n=0;for(;f<=l;){for(;n<o.length&&o[n].b<f;)n++;const c=n<o.length&&o[n].a===f?o[n]:null;if(c!==null){const r=this._expandNode(c,s);f=c.b+1+(r??0)}else this._pushRow(f,s.index,a),f++}}_expandNode(t,s){const e=t.binding,l=this._table(e.table),a=this._rowsIn(s,l),f=c=>e.fillTo>1?(e.fillTo-c%e.fillTo)%e.fillTo:0;if(e.type==="group"){let c=this._partition(a,e,l,s);e.spillMode==="none"&&(c=c.slice(0,1));const r=e.merge===!0||this.sheet.mergeAt(e.row,e.col)!==null,h=c.length;for(let i=0;i<h;i++){const u=this._newContext(new O(s,l,c[i],t));u.ordinal=i+1,u.first=this.rowCount,this._emitBand(t,u,t.a,t.b,-1),u.last=this.rowCount-1,r&&u.last>u.first&&this.groupMerges.push({binding:e,r0:u.first,r1:u.last}),e.collapse&&u.last>u.first&&this.collapses.push({binding:e,row:u.first,from:u.first+1,to:u.last,depth:vt(u),collapsed:e.initial==="collapsed"}),e.pageBreak&&i<h-1&&this.breaks.push(this.rowCount)}for(let i=f(h);i>0;i--){const u=this._newContext(new O(s,l,U,t));u.first=this.rowCount,this._emitBand(t,u,t.a,t.b,G),u.last=this.rowCount-1}return 0}let o=this._prepareRows(a,e,l,s);e.spillMode==="none"&&(o=o.subarray(0,1));const n=e.pageEvery??0;if(t.a===t.b&&t.children.length===0){const c=this._newContext(new O(s,l,o,t));if(c.first=this.rowCount,e.spillMode==="overwrite"){const r=o.length;for(let h=0;h<r;h++){const i=this._pushRow(t.a+h,c.index,o[h]);this.overlay===null&&(this.overlay=new Map),this.overlay.set(i,t.a)}return c.last=this.rowCount-1,Math.max(0,r-1)}for(let r=0;r<o.length;r++)this._pushRow(t.a,c.index,o[r]),n>0&&(r+1)%n===0&&r+1<o.length&&this.breaks.push(this.rowCount);for(let r=f(o.length);r>0;r--)this._pushRow(t.a,c.index,G);return c.last=this.rowCount-1,0}for(let c=0;c<o.length;c++){const r=o.subarray(c,c+1),h=this._newContext(new O(s,l,r,t));h.ordinal=c+1,h.first=this.rowCount,this._emitBand(t,h,t.a,t.b,o[c]),h.last=this.rowCount-1,n>0&&(c+1)%n===0&&c+1<o.length&&this.breaks.push(this.rowCount)}return 0}_expandColumns(t,s,e,l){let a=e,f=0;const o=t.children;for(;a<=l;){for(;f<o.length&&o[f].b<a;)f++;const n=f<o.length&&o[f].a===a?o[f]:null;if(n!==null)this._expandColumnNode(n,s),a=n.b+1;else{if(this.colOut.length>=P)throw new T(A("The report needs more than {count} columns. Add a filter.",{count:P}));this.colOut.push({tpl:a,ctx:s}),a++}}}_expandColumnNode(t,s){const e=t.binding,l=this._table(e.table),a=this._colRows(s,l);let f=e.type==="group"?this._partition(a,e,l):Array.from(this._prepareRows(a,e,l),n=>Int32Array.of(n));e.spillMode==="none"&&(f=f.slice(0,1));const o=e.fillTo>1?(e.fillTo-f.length%e.fillTo)%e.fillTo:0;for(let n=0;n<o;n++)f.push(U);for(const n of f){const c=new O(s,l,n,t);c.first=this.colOut.length,this._expandColumns(t,c,t.a,t.b),c.last=this.colOut.length-1}}_colRows(t,s){return t===null||t.table===null?this._rootRows(s):this._rowsIn(t,s)}run(t,s){const{book:e,t:l}=this,a=this._templateExtent();this.extent=a;const f=this._buildTree("vertical",a),o=this._buildTree("horizontal",a),n=this._newContext(new O(null,null,U,null));n.first=0,this._emitBand(f,n,0,a.maxRow,-1),n.last=this.rowCount-1;const c=new O(null,null,U,null);this._expandColumns(o,c,0,a.maxCol),this._paginateRows(),this._paginateCols();const r=t??e.addSheet(s??`${l.name} Report`);this.outSheet=r,r.reportWriting=!0;const h=r.formulas.size>0;this._clear(r),this._writeGeometry(r),this._writeCells(r),this._writeMerges(r),this._writeSheetRules(r),this._writePageSetup(r),this._writeFormulas(r),this._applyAutoFit(r),l.layout&&this._applyLayoutSetting(r),this._saveMap(r),h&&e.engine?.rebuild(),r.reportWriting=!1,r.revision++,l.output=r;for(const i of this.helperViews.values())i.dispose();return{sheet:r,rows:this.rowCount,cols:this.colOut.length,pages:Et(e,r)}}_clear(t){t.columns=[],t.formulas=new Map,t.maxRow=-1,t.maxCol=-1,t.merges=[],t.mergeIndex=null,t.spills=null,t.rowStyles=null,t.colStyles=null,t.pageSetup=void 0,t.cf=void 0,t.cfEval=void 0,t.validations=void 0,t.sparklines=void 0,t.rows=new st(L,this.sheet.rows.defaultSize),t.cols=new st(P,this.sheet.cols.defaultSize),t.colsChanged=!0,t.viewChanged=!0}_writeGeometry(t){const{sheet:s}=this,{colOut:e,rowTpl:l,rowCount:a}=this;if(s.cols.sizes!==null)for(let o=0;o<e.length;o++){const n=s.cols.sizeOf(e[o].tpl);s.cols.isHidden(e[o].tpl)||(n!==t.cols.defaultSize||t.cols.isCustom(o))&&t.cols.setSize(o,n)}if(s.rows.sizes!==null)for(let o=0;o<a;o++){const n=l[o];s.rows.isCustom(n)&&!s.rows.isHidden(n)&&t.rows.setSize(o,s.rows.sizeOf(n))}if(!this.t.showHiddenRows&&s.rows.hiddenSizes?.size>0)for(let o=0;o<a;o++)s.rows.isHidden(l[o])&&t.rows.setHidden(o,!0);!this.t.showHiddenCols&&s.cols.hiddenSizes?.size>0&&e.forEach((o,n)=>{s.cols.isHidden(o.tpl)&&t.cols.setHidden(n,!0)}),s.colStyles&&(t.colStyles=new Map,e.forEach((o,n)=>{const c=s.colStyles.get(o.tpl);c!==void 0&&t.colStyles.set(n,c)}))}_writeCells(t){const{colOut:s,rowCount:e,rowTpl:l,rowCtx:a,rowRec:f,sheet:o,contexts:n}=this,{strings:c}=this.book,{bindings:r}=this.t,{overlay:h}=this,i=o.formulas.size>0,u=new Map;s.forEach((w,m)=>{u.has(w.tpl)||u.set(w.tpl,m)});const p=(w,m)=>{const C=M(w,m),k=r.get(C)??null,R=k!==null&&k.type==="static"?null:k,S=o.kind(w,m),y={binding:R,options:k!==null&&k.type==="static"?k:null,kind:S&~pt,value:o.value(w,m),style:o.cellStyle(w,m),table:R&&R.table?this._table(R.table):null,col:null,formula:S&J?o.formula(w,m):null,merged:o.mergeAt(w,m)};if(R&&R.type!=="param"&&R.type!=="chart"){if(y.col=R.formula?q(y.table,R.formula):y.table?.column(R.field)??null,!y.col&&!(R.type==="summary"&&R.agg==="countAll"))throw new T(A("No field {field} in {table}.",{field:R.field,table:R.table}));y.col&&y.table.ensure(y.col),R.collapse&&(y.style=this.book.styles.derive(y.style,{indent:1,hAlign:"left"})),R.format?y.style=this.book.styles.derive(y.style,{numFmt:R.format}):y.col&&y.col.format!=="General"&&(y.style===0||this.book.styles.get(y.style).numFmt==="General")&&(y.style=this.book.styles.derive(y.style,{numFmt:y.col.format}))}return y};for(let w=0;w<s.length;w++){const{tpl:m,ctx:C}=s[w];let k=-1;const R=[],S=u.get(m)===w;for(let y=0;y<e;y++){let x=l[y];if(h!==null){const _=h.get(y);_!==void 0&&r.get(M(_,m))?.type==="list"&&(x=_)}let b=R[x];b===void 0&&(b=p(x,m),R[x]=b);const d=b.binding;if(d===null){const _=b.options;if(_!==null){if(_.pin)continue;const v=_.autoExpand??"both";if((v==="none"||v==="horizontal")&&b.seen||(v==="none"||v==="vertical")&&!S)continue;b.seen=!0}if(b.formula){i&&this.formulas.push({or:y,oc:w,tr:x,tc:m,info:b.formula,ctx:n[a[y]],colCtx:C,style:b.style});continue}b.kind!==$&&t.setCell(y,w,b.kind,b.value),b.style!==0&&t.setStyle(y,w,b.style);continue}switch(b.style!==0&&t.setStyle(y,w,b.style),d.type){case"param":lt(t,y,w,this._param(d.param),c);break;case"list":{const _=d.expand==="horizontal"?this._recordAcross(C,b.table):this._recordFor(n[a[y]],f[y],b.table);_>=0&&it(t,y,w,b.col,_);break}case"group":{const _=this._groupContext(n[a[y]],C,d);if(_===null)break;if(_.index!==void 0&&!d.repeat){if(_.index===k&&!(d.repeatOnPage&&this.pageStartSet.has(y)))break;k=_.index}this._writeGroupValue(t,y,w,d,b,_);break}case"chart":this._writeChartCell(t,y,w,d,n[a[y]]);break;default:{if(f[y]===G)break;const _=this._summaryRows(n[a[y]],C,b.table,d,f[y]),v=b.col?Q(b.col,d.agg??"sum",_,0,_.length):d.agg==="countAll"?_.length:NaN;v===v&&t.setCell(y,w,B,v)}}}}}_writeChartCell(t,s,e,l,a){if(!l.source)return;const o=(this.tplRows??(this.tplRows=this._rowsByTemplate())).get(l.source.row),n=this.colOut.findIndex(u=>u.tpl===l.source.col);if(!o||n<0)return;const c=ot(o,a.first,a.last);if(c.length===0)return;const r=c[0][0],h=c[c.length-1][1];t.sparklines||(t.sparklines=[],t.sparklinesChanged=!0),this.sparkGroups||(this.sparkGroups=new Map);let i=this.sparkGroups.get(l);i||(i={type:l.chartType??"line",markers:!1,high:!1,low:!1,first:!1,last:!1,negative:l.chartType==="winloss",lineWeight:1,seriesColor:l.color??"#2f6fb3",negativeColor:"#c42b1c",markerColor:"#107c41",items:[]},this.sparkGroups.set(l,i),t.sparklines.push(i)),i.items.push({source:`${gt(t.name)}${H(n)}${r+1}:${H(n)}${h+1}`,cell:N(s,e)})}_rowsByTemplate(){const t=new Map;for(let s=0;s<this.rowCount;s++){const e=this.rowTpl[s];let l=t.get(e);l===void 0&&(l=[],t.set(e,l)),l.push(s)}return t}_writeSheetRules(t){const{sheet:s,colOut:e}=this,l=this.tplRows??(this.tplRows=this._rowsByTemplate()),a=new Map;e.forEach((o,n)=>{a.has(o.tpl)||a.set(o.tpl,[]),a.get(o.tpl).push(n)});const f=o=>{const n=[];for(const c of mt(o)){const r=[];for(let i=c.r0;i<=c.r1&&i<=this.extent.maxRow;i++)for(const u of l.get(i)??[])r.push(u);r.sort((i,u)=>i-u);const h=[];for(let i=c.c0;i<=c.c1&&i<=this.extent.maxCol;i++)for(const u of a.get(i)??[])h.push(u);h.sort((i,u)=>i-u);for(const[i,u]of at(r))for(const[p,w]of at(h))n.push(dt({r0:i,c0:p,r1:u,c1:w}))}return n.join(" ")};s.cf&&s.cf.length>0&&(t.cf=s.cf.map(({_ranges:o,...n})=>({...n,sqref:f(n.sqref)})).filter(o=>o.sqref),t.cfChanged=!0),s.validations&&s.validations.length>0&&(t.validations=s.validations.map(({_ranges:o,...n})=>({...n,sqref:f(n.sqref)})).filter(o=>o.sqref),t.validationsChanged=!0);for(const o of this.t.bindings.values()){if(o.type!=="static"||!o.pin)continue;const n=s.kind(o.row,o.col),c=o.pin==="column"?l.get(o.row)?.[0]??o.row:o.row,r=o.pin==="row"?a.get(o.col)?.[0]??o.col:o.col;(n&7)!==$&&t.setCell(c,r,n&7,s.value(o.row,o.col));const h=s.cellStyle(o.row,o.col);h&&t.setStyle(c,r,h)}}_applyAutoFit(t){const s=[...this.t.bindings.values()].filter(i=>i.autoFit);if(s.length===0)return;const e=this.t.measure??(i=>i.length*6.4),{colOut:l,rowTpl:a,rowCount:f,sheet:o}=this,{strings:n,styles:c}=this.book,r=(i,u)=>{const p=t.kind(i,u)&7;if(p===0)return"";if(p===E)return n.get(t.value(i,u));if(p===B){const w=c.get(t.style(i,u)).numFmt;return w&&w!=="General"?j(w).number(t.value(i,u)):String(t.value(i,u))}return"TRUE"},h=Math.min(f,1e5);for(const i of s)if(i.autoFit==="column")l.forEach((u,p)=>{if(u.tpl!==i.col)return;let w=o.cols.sizeOf(i.col);for(let m=0;m<h;m++)a[m]===i.row&&(w=Math.max(w,e(r(m,p))+8));w!==t.cols.sizeOf(p)&&t.cols.setSize(p,Math.ceil(w))});else{const u=l.findIndex(m=>m.tpl===i.col);if(u<0)continue;const p=Math.max(10,t.cols.sizeOf(u)-6),w=t.rows.defaultSize;for(let m=0;m<h;m++){if(a[m]!==i.row)continue;const C=Math.ceil(e(r(m,u))/p),k=Math.max(o.rows.sizeOf(i.row),C*w);k!==t.rows.sizeOf(m)&&t.rows.setSize(m,k)}}}_applyLayoutSetting(t){const{type:s,count:e,repeat:l=0}=this.t.layout;if(!(e>l))return;const a=[],f=t.maxRow,o=t.maxCol;for(let c=0;c<=f;c++)for(let r=0;r<=o;r++){const h=t.kind(c,r)&15,i=t.cellStyle(c,r);(h!==0||i!==0)&&a.push(c,r,h,t.value(c,r),i)}const n=e-l;t.columns=[],t.maxRow=-1,t.maxCol=-1;for(let c=0;c<a.length;c+=5){const[r,h,i,u,p]=[a[c],a[c+1],a[c+2],a[c+3],a[c+4]],w=(m,C)=>{i!==0&&t.setCell(m,C,i,u),p!==0&&t.setStyle(m,C,p)};if(s==="row"){const m=o+1;if(r<l){const C=Math.max(1,Math.ceil((f+1-l)/n));for(let k=0;k<C;k++)w(r,h+k*m)}else{const C=Math.floor((r-l)/n);w(l+(r-l)%n,h+C*m)}}else{const m=f+1;if(h<l){const C=Math.max(1,Math.ceil((o+1-l)/n));for(let k=0;k<C;k++)w(r+k*m,h)}else{const C=Math.floor((h-l)/n);w(r+C*m,l+(h-l)%n)}}}}_saveMap(t){const{rowTpl:s,rowRec:e,rowCtx:l,rowCount:a,colOut:f,contexts:o,collapses:n}=this,c=new Map;f.forEach((h,i)=>{c.has(h.tpl)||c.set(h.tpl,i)});const r=n.map(h=>({...h,col:c.get(h.binding.col)??0}));t.reportMap={template:this.t,rowTpl:s.subarray(0,a),rowRec:e.subarray(0,a),rowCtx:l.subarray(0,a),contexts:o,colTpl:f.map(h=>h.tpl),collapses:r,overlay:this.overlay,book:this.book,layout:this.t.layout??null},r.some(h=>h.collapsed)&&ct(t)}_groupContext(t,s,e){for(let l=t;l!==null;l=l.parent)if(l.node?.binding===e)return l;for(let l=s;l!==null;l=l.parent)if(l.node?.binding===e)return l;return null}_writeGroupValue(t,s,e,l,a,f){const o=f.rows.length>0?f.rows[0]:-1;if(o<0)return;const n=a.col.get(o);if(l.bins){const c=l.bins.find(r=>typeof n=="number"&&(r.min===void 0||n>=r.min)&&(r.max===void 0||n<r.max));t.setCell(s,e,E,this.book.strings.add(c?.name??"(other)"))}else if(typeof n=="number"&&l.by&&l.by!=="value")t.setCell(s,e,E,this.book.strings.add(Ot(n,l.by)));else if(typeof n=="number"&&l.size>0){const c=Math.floor(n/l.size)*l.size;t.setCell(s,e,E,this.book.strings.add(`${c} to ${c+l.size}`))}else it(t,s,e,a.col,o)}_recordAcross(t,s){for(let e=t;e!==null&&e.node!==null;e=e.parent)if(e.table===s)return e.rows.length>0?e.rows[0]:-1;return-1}_recordFor(t,s,e){if(s===G)return-1;if(s>=0&&(t.table===e||t.table===null))return s;for(let a=t;a!==null;a=a.parent)if(a.table===e&&a.rows.length>0)return s>=0&&a===t?s:a.rows[0];const l=this._rowsIn(t,e);return l.length>0?l[0]:-1}_summaryRows(t,s,e,l,a){let f=t.table===e&&a>=0?Int32Array.of(a):this._rowsIn(t.table===null?null:t,e);for(let o=s;o!==null&&o.node!==null;o=o.parent){const n=o.node.binding;if(o.table!==e)continue;const c=nt(e,n);let r=this.keyCache.get(c);r===void 0&&(r=tt(e,n),this.keyCache.set(c,r));const h=r[o.rows[0]],i=new Int32Array(f.length);let u=0;for(let p=0;p<f.length;p++){const w=r[f[p]];(w===h||w!==w&&h!==h)&&(i[u++]=f[p])}f=i.subarray(0,u)}return l.filters?.length&&(f=this._prepareRows(f,{...l,sort:null,sortBy:null},e)),f}_writeMerges(t){const{sheet:s,rowTpl:e,rowCtx:l,rowCount:a,colOut:f,groupMerges:o}=this,n=new Map;f.forEach((r,h)=>{n.has(r.tpl)||n.set(r.tpl,[]),n.get(r.tpl).push(h)});const c=new Set;for(const r of o){const{binding:h,r0:i,r1:u}=r,p=s.mergeAt(h.row,h.col),w=p?p.c0:h.col,m=p?p.c1:h.col;p&&c.add(p);const C=[];let k=i;if(h.repeatOnPage)for(let R=i+1;R<=u;R++)this.pageStartSet.has(R)&&(C.push([k,R-1]),k=R);C.push([k,u]);for(const R of n.get(w)??[]){const S=R+(m-w);for(const[y,x]of C)(x>y||S>R)&&t.addMerge({r0:y,c0:R,r1:x,c1:S})}}for(const r of s.merges){if(c.has(r)||this.t.bindings.has(M(r.r0,r.c0))){const i=this.t.bindings.get(M(r.r0,r.c0));if(i&&(i.type==="group"||i.type==="list")&&i.expand==="vertical")continue}if(c.has(r))continue;const h=r.r1-r.r0;for(let i=0;i<a;i++){if(e[i]!==r.r0||i+h>=a)continue;let u=!0;for(let p=1;p<=h;p++)(e[i+p]!==r.r0+p||l[i+p]!==l[i])&&(u=!1);if(u)for(const p of n.get(r.c0)??[]){const w=p+(r.c1-r.c0);w<f.length&&t.addMerge({r0:i,c0:p,r1:i+h,c1:w})}}}}_writePageSetup(t){const{t:s,rowTpl:e,rowCount:l}=this,a=_t(t),f=this.sheet.pageSetup;if(f)for(const n of["orientation","paperSize","paperWidth","paperHeight","scale","fitToPage","fitToWidth","fitToHeight","horizontalCentered","verticalCentered","header","footer","headings","gridLines","margins"])f[n]!==void 0&&(a[n]=f[n]);s.pageSetup&&Object.assign(a,s.pageSetup);const o=s.pagination;if(o?.order&&(a.pageOrder=o.order),a.rowBreaks=[...new Set(this.breaks)].filter(n=>n>0&&n<l).sort((n,c)=>n-c),a.colBreaks=[...new Set(this.colBreaks)].filter(n=>n>0&&n<this.colOut.length).sort((n,c)=>n-c),o?.titleCols){let n=-1,c=-1;this.colOut.forEach((r,h)=>{r.tpl>=o.titleCols.c0&&r.tpl<=o.titleCols.c1&&(n<0||h===c+1)&&(n<0&&(n=h),c=h)}),n>=0&&(a.titleCols={c0:n,c1:c})}if(s.titleRows){let n=-1,c=-1;for(let r=0;r<l;r++){const h=e[r];if(h>=s.titleRows.r0&&h<=s.titleRows.r1)n<0&&(n=r),c=r;else if(n>=0)break}n>=0&&(a.titleRows={r0:n,r1:c})}t.pageSetupChanged=!0}_writeFormulas(t){if(this.formulas.length===0)return;const{rowTpl:s,rowCount:e,colOut:l}=this,a=new Map;for(let r=0;r<e;r++){const h=s[r];let i=a.get(h);i===void 0&&(i=[],a.set(h,i)),i.push(r)}const f=new Map;l.forEach((r,h)=>{f.has(r.tpl)||f.set(r.tpl,[]),f.get(r.tpl).push(h)});const o=new Uint32Array(this.formulas.length),n=new Uint16Array(this.formulas.length);this.formulas.forEach((r,h)=>{const{or:i,oc:u,tr:p,tc:w,info:m,ctx:C,style:k}=r,R=m.f??yt(m.sf,p-Math.floor(m.base/P),w-m.base%P),S=this._reportFunctions(R,i,C),y=Mt(S,(x,b,d,_)=>{const v=a.get(b),z=f.get(_);if(!v||!z)return null;const W=b===p?[[i,i]]:ot(v,C.first,C.last);if(W.length===0)return"#REF!";let I,F;return _===w?(I=u,F=u):(I=z[0],F=z[z.length-1]),W.map(([D,K])=>{const X=`${d}${H(I)}${x}${D+1}`;return D===K&&I===F?X:`${X}:${d}${H(F)}${x}${K+1}`}).join(",")});if(y.length>St){t.setCell(i,u,Z,Ct.REF.index),k!==0&&t.setStyle(i,u,k),o[h]=i,n[h]=u;return}t.setCell(i,u,J|$,0),t.setFormula(i,u,{f:y,typed:!0}),k!==0&&t.setStyle(i,u,k),o[h]=i,n[h]=u}),this.book.engine?.cellsChanged(t,o,n,o.length),this.book.formulasEdited=!0;const c=this.book.engine;c&&this.formulas.forEach(r=>{if(this.t.bindings.get(M(r.tr,r.tc))?.preserveFormula!==!1)return;const i=c.read(t,r.or,r.oc);t.setFormula(r.or,r.oc,null),t.setCell(r.or,r.oc,$,0),lt(t,r.or,r.oc,i,this.book.strings)})}_reportFunctions(t,s,e){if(!/RPT_/i.test(t))return t;const l=n=>this._measureCell(f(n),s,e),a=n=>{const c=n.trim();for(const r of this.t.bindings.values())if(r.alias===c)return N(r.row,r.col);return c},f=a,o=n=>n==null?'""':String(typeof n=="number"?Number(n.toPrecision(15)):n);return t.replace(/RPT_RANK\(\s*([^()]+?)\s*\)/gi,(n,c)=>{const r=l(c);return r?o(1+r.values.filter(h=>h>r.current).length):'""'}).replace(/RPT_PROPORTION\(\s*([^()]+?)\s*\)/gi,(n,c)=>{const r=l(c),h=r?r.values.reduce((i,u)=>i+u,0):0;return r&&h!==0?o(r.current/h):'""'}).replace(/RPT_CUMULATIVE\(\s*([^()]+?)\s*\)/gi,(n,c)=>{const r=l(c);return r?o(r.values.slice(0,r.at+1).reduce((h,i)=>h+i,0)):'""'}).replace(/RPT_(MOM|YOY)\(\s*([^()]+?)\s*\)/gi,(n,c,r)=>{const h=l(r);if(!h)return'""';const i=c.toUpperCase()==="MOM"?1:{month:12,quarter:4,year:1,week:52}[h.by]??12,u=h.values[h.at-i];return u===void 0||u===0?'""':o((h.current-u)/u)}).replace(/RPT_VALUE\(\s*([^()]+?)\s*\)/gi,(n,c)=>a(c)).replace(/RPT_PARAM\(\s*"([^"]+)"\s*\)/gi,(n,c)=>{const r=this._param(c);return typeof r=="number"?String(r):`"${String(r??"").replace(/"/g,'""')}"`}).replace(/RPT_INDEX\(\s*([^()]+?)\s*\)/gi,(n,c)=>{const r=Y(a(c).replace(/\$/g,"")),h=r?this.t.binding(r.r0,r.c0):null;for(let i=e;i!==null;i=i.parent)if(i.node?.binding===h)return String(i.ordinal??1);return"1"}).replace(/RPT_PAGES\(\s*(TRUE)?\s*\)/gi,(n,c)=>{const r=this._pageStarts();if(!c)return String(r.length);const h=this._topContext(e);return String(r.filter(i=>i>=h.first&&i<=h.last).length||1)}).replace(/RPT_PAGE\(\s*(TRUE)?\s*\)/gi,(n,c)=>{const r=this._pageStarts();let h=0;for(let p=0;p<r.length;p++)r[p]<=s&&(h=p);if(!c)return String(h+1);const i=this._topContext(e);let u=0;for(;u<h&&r[u]<i.first;)u++;return String(h-u+1)})}_topContext(t){let s=t;for(let e=t;e!=null&&e.node;e=e.parent)s=e;return s}_measureCell(t,s,e){const l=Y(t.replace(/\$/g,""));if(!l)return null;const a=this.outSheet,f=this.colOut.findIndex(p=>p.tpl===l.c0);if(f<0)return null;let o=e;for(;o&&!o.node&&o.parent;)o=o.parent;const n=o?.node?.binding?.type==="list"?o:o?.parent??o,c=n?.first??0,r=n?.last??this.rowCount-1,h=[];let i=-1,u=1/0;for(let p=c;p<=r;p++){if(this.rowTpl[p]!==l.r0||(a.kind(p,f)&ut)!==B)continue;const m=Math.abs(p-s);(p<=s||i<0)&&m<u&&(u=m,i=h.length),h.push(a.value(p,f))}return i<0||h.length===0?null:{values:h,at:i,current:h[i],by:o?.node?.binding?.by??null}}_pageStarts(){if(this.pageStarts)return this.pageStarts;const t=V(this.book,this.outSheet),s=[];for(let e=0;e<t.pageCount;e++)s.push(t.page(e).r0);return this.pageStarts=s,s}}function ot(g,t,s){const e=[];let l=0,a=g.length;if(t>=0)for(;l<a;){const f=l+a>>>1;g[f]<t?l=f+1:a=f}for(let f=l;f<g.length;f++){const o=g[f];if(t>=0&&o>s)break;const n=e[e.length-1];n&&n[1]===o-1?n[1]=o:e.push([o,o])}return e}function Mt(g,t){let s="",e=0;const l=g.length,a=/(\$?)([A-Za-z]{1,3})(\$?)(\d+)(?::(\$?)([A-Za-z]{1,3})(\$?)(\d+))?/y;for(;e<l;){const f=g[e];if(f==='"'){let c=e+1;for(;c<l;)if(g[c]==='"')if(g[c+1]==='"')c+=2;else break;else c++;s+=g.slice(e,c+1),e=c+1;continue}if(f==="'"){const c=g.indexOf("'!",e+1);if(c>=0){const r=/^\$?[A-Za-z]{1,3}\$?\d+(:\$?[A-Za-z]{1,3}\$?\d+)?/.exec(g.slice(c+2)),h=c+2+(r?r[0].length:0);s+=g.slice(e,h),e=h;continue}}a.lastIndex=e;const o=e>0?g[e-1]:"",n=/[A-Za-z0-9_.!$]/.test(o)?null:a.exec(g);if(n){const c=g[e+n[0].length]??"";if(!/[A-Za-z0-9_.(!]/.test(c)){const r=(i,u,p,w)=>t(p,Number(w)-1,i,wt(u.toUpperCase())),h=r(n[1],n[2],n[3],n[4]);if(n[6]===void 0)s+=h??n[0];else{const i=r(n[5],n[6],n[7],n[8]);s+=h===null||i===null?n[0]:`${h.split(/[:,]/)[0]}:${i.split(/[:,]/).pop()}`}e+=n[0].length;continue}}s+=f,e++}return s}function Tt(g,t,s){const e=new Float64Array(g.length);for(let f=0;f<g.length;f++)e[f]=t[g[f]];const l=new Int32Array(g.length);for(let f=0;f<g.length;f++)l[f]=f;kt(l,g.length,e,s);const a=new Int32Array(g.length);for(let f=0;f<g.length;f++)a[f]=g[l[f]];g.set(a)}const At=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Ot(g,t){const e=j("yyyy-mm").number(Math.floor(g)),l=Number(e.slice(0,4)),a=Number(e.slice(5,7));switch(t){case"year":return String(l);case"quarter":return`Q${Math.floor((a-1)/3)+1} ${l}`;case"month":return`${At[a-1]} ${l}`;default:return j("yyyy-mm-dd").number(Math.floor(g))}}function it(g,t,s,e,l){const a=e.kind(l);a!==$&&g.setCell(t,s,a,e.raw(l))}function lt(g,t,s,e,l){e==null||e===""||(typeof e=="number"?g.setCell(t,s,B,e):typeof e=="boolean"?g.setCell(t,s,ft,e?1:0):e instanceof bt?g.setCell(t,s,Z,e.index):g.setCell(t,s,E,l.add(Array.isArray(e)?e.join(", "):String(e))))}function at(g){const t=[];for(const s of g){const e=t[t.length-1];e&&(e[1]===s||e[1]===s-1)?e[1]=s:t.push([s,s])}return t}function ct(g){const t=g.reportMap;if(t){for(const s of t.collapses)for(let e=s.from;e<=s.to;e++)g.rows.setHidden(e,!1);for(const s of t.collapses)if(s.collapsed)for(let e=s.from;e<=s.to;e++)g.rows.setHidden(e,!0);g.revision++}}function jt(g,t,s,e=void 0,l=!1){const a=g.reportMap;if(!a)return!1;const f=a.collapses.find(n=>n.row===t&&(s===void 0||n.col===s));if(!f)return!1;const o=e===void 0?!f.collapsed:e==="collapsed"||e===!0;if(f.collapsed=o,l)for(const n of a.collapses)n.from>=f.from&&n.to<=f.to&&(n.collapsed=o);return ct(g),!0}function Et(g,t,s={}){return V(g,t,s).pageCount}export{Rt as BINDING_TYPES,T as ReportError,ht as ReportTemplate,ct as applyCollapses,Et as reportPages,jt as toggleCollapse};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{CUSTOM_XML_CONTENT_TYPE as
|
|
2
|
-
<queries xmlns="${h}" version="1">${t}</queries>`}function
|
|
1
|
+
import{CUSTOM_XML_CONTENT_TYPE as T,CUSTOM_XML_REL as S,customXmlNames as b}from"../../celltypes/persist.js";import{escapeRegExp as d}from"../../core/regexp.js";import{TEXT_ENCODINGS as _}from"../../io/encoding.js";import{children as M,parseTree as N,unescapeOoxml as O}from"../../io/xml-scan.js";import{xmlText as R}from"../../io/xml-escape.js";import{cleanMoreStep as A}from"./steps-more.js";import{cleanTableStep as P}from"./steps-tables.js";import{STEP_OPS as I,COLUMN_TYPES as j,FILTER_OPS as X,MAX_DELIMITER as $}from"./steps.js";const h="urn:8sheets:getdata:1",i="customXml/",p="queries8c.xml",q="rId8cGetData",U=4*1024*1024,v=256,D=256,y=16384,L=1024,C=8192,Q=32767,k=new Set(["csv","json","xml","web","table","range","workbook"]),F=new Set(["auto","csv","json","xml","html"]),Y=new Set(Object.keys(_)),G=new Set([",",";"," ","|"]),o=(e,t=L)=>typeof e=="string"&&e.length<=t?e:null;function B(e){const t=o(e,C);if(!t)return null;let n;try{n=new URL(t)}catch{return null}return n.protocol!=="http:"&&n.protocol!=="https:"||n.username||n.password?null:n.href}function H(e){if(e===null||typeof e!="object"||!k.has(e.type))return null;const t={type:e.type},n=o(e.fileName);if(n&&(t.fileName=n),e.type==="web"){if(t.url=B(e.url),!t.url)return null;t.format=F.has(e.format)?e.format:"auto"}if(e.type==="table"&&(t.table=o(e.table),!t.table)||e.type==="range"&&(t.sheet=o(e.sheet),t.ref=o(e.ref),!t.sheet||!t.ref)||e.type==="workbook"&&(t.sheet=o(e.sheet),!t.sheet))return null;(G.has(e.delimiter)||typeof e.delimiter=="string"&&e.delimiter.length===1&&!/["\r\n]/.test(e.delimiter))&&(t.delimiter=e.delimiter),e.detectTypes===!1&&(t.detectTypes=!1),Number.isInteger(e.tableIndex)&&e.tableIndex>=0&&(t.tableIndex=e.tableIndex),Y.has(e.encoding)&&(t.encoding=e.encoding);const s=o(e.recordsPath);s&&(t.recordsPath=s);const l=o(e.recordPath);return l&&(t.recordPath=l),e.ndjson===!0&&(t.ndjson=!0),t}function J(e){if(e===null||typeof e!="object"||!I.includes(e.op))return null;const{op:t}=e;switch(t){case"promoteHeaders":return{op:t};case"chooseColumns":{if(!Array.isArray(e.names)||e.names.length>y)return null;const n=e.names.map(s=>o(s));return n.includes(null)?null:{op:t,names:n}}case"splitColumn":{const n=o(e.column),s=typeof e.delimiter=="string"&&e.delimiter.length>=1&&e.delimiter.length<=$?e.delimiter:null,l=Number.isInteger(e.parts)&&e.parts>=1&&e.parts<=100?e.parts:null;return n!==null&&s!==null&&l!==null?{op:t,column:n,delimiter:s,parts:l}:null}case"rename":{const n=o(e.from),s=o(e.to);return n!==null&&s?{op:t,from:n,to:s}:null}case"changeType":{const n=o(e.column);return n!==null&&Object.hasOwn(j,e.to)?{op:t,column:n,to:e.to}:null}case"filterRows":{const n=o(e.column);return n===null||!Object.hasOwn(X,e.test)?null:{op:t,column:n,test:e.test,value:o(e.value)??""}}case"removeDuplicates":{if(e.columns===null||e.columns===void 0)return{op:t,columns:null};if(!Array.isArray(e.columns)||e.columns.length>y)return null;const n=e.columns.map(s=>o(s));return n.includes(null)?null:{op:t,columns:n}}case"sort":{const n=o(e.column);return n!==null?{op:t,column:n,desc:e.desc===!0}:null}default:return A(e)??P(e)}}function g(e){if(e===null||typeof e!="object")return null;const t=o(e.id,64),n=o(e.name,255),s=H(e.source);if(!t||!n||!s||!Array.isArray(e.steps)||e.steps.length>D)return null;const l=e.steps.map(J);if(l.includes(null))return null;const r={id:t,name:n,source:s,steps:l},c=o(e.table);return c&&(r.table=c),e.connectionOnly===!0&&!c&&(r.connectionOnly=!0),Number.isInteger(e.refreshMinutes)&&e.refreshMinutes>=1&&e.refreshMinutes<=Q&&(r.refreshMinutes=e.refreshMinutes),r}function W(e){if(!e?.length)return null;const t=e.map(n=>{const s=g(n);return s?`<query>${R(JSON.stringify(s))}</query>`:""}).join("");return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
+
<queries xmlns="${h}" version="1">${t}</queries>`}function K(e){let t;try{t=N(new TextEncoder().encode(e))}catch{return{queries:[],rejected:1}}const n=[];let s=0;const l=new Set;for(const r of M(t,"query").slice(0,v)){let c=null;try{c=JSON.parse(O(r.t))}catch{}const u=g(c);u&&!l.has(u.id)?(l.add(u.id),n.push(u)):s++}return{queries:n,rejected:s}}function V(e){const t=W(e);return t===null?null:{path:`${i}${p}`,xml:t,override:{partName:`/${i}${p}`,contentType:T},relationship:{id:q,type:S,target:`/${i}${p}`}}}const le=e=>{const t=V(e.getDataQueries);return t?[t]:[]};async function x(e){const t=[];for(const n of b(e,U)){const s=await e.text(n);s.includes(h)&&t.push({name:n,text:s})}return t}async function re(e){const t=[];let n=0;for(const s of await x(e)){const l=K(s.text);t.push(...l.queries),n+=l.rejected}return{queries:t,rejected:n}}async function ue(e,t,n,s){let l=t,r=n;const c=u=>{l=l.replace(new RegExp(`<Override\\b[^>]*PartName="/${d(u)}"[^>]*/>`,"g"),"")};for(const{name:u}of await x(e)){s.add(u),c(u);const a=u.slice(i.length);r=r.replace(new RegExp(`<Relationship\\b[^>]*Target="[^"]*${d(i+a)}"[^>]*/>`,"g"),"");const f=`${i}_rels/${a}.rels`;if(e.has(f)){s.add(f);for(const E of(await e.text(f)).matchAll(/Target="([^"]+)"/g)){const m=`${i}${E[1].split("/").pop()}`;e.has(m)&&(s.add(m),c(m))}}}return{types:l,rels:r}}export{Q as MAX_REFRESH_MINUTES,h as QUERIES_NS,B as cleanUrl,ue as dropQueryParts,le as getDataPackage,K as parseQueries,V as queriesPart,W as queriesXml,re as readQueries,x as readQueryParts,g as sanitizeQuery};
|
package/extras/getdata/rows.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ERRORS as
|
|
1
|
+
import{ERRORS as k,BOOL as d,EMPTY as y,ERR as f,KIND_MASK as w,NUM as R,STR as u}from"../../core/sheet.js";import{formatGeneral as x,getFormatter as v}from"../../core/numfmt.js";import{t as U}from"../../i18n/index.js";const g=4096,_=1<<21,C=16384,N=32767,F=255,L=49152;function O(r,t,s){const n=new r(U(t,s));return n.i18n={key:t,params:s},n}const M=r=>`Column${r+1}`;class z{constructor(t=[]){this.list=t,this.map=new Map(t.map((s,n)=>[s,n+1]))}id(t){if(!t||t==="General")return 0;let s=this.map.get(t);return s===void 0&&(this.list.push(t),s=this.list.length,this.map.set(t,s)),s}code(t){return t===0?"General":this.list[t-1]}}function A(r,t,s,n=[]){const i=r*t;return{rows:r,cols:t,columns:s,strings:n,kinds:new Uint8Array(i),values:new Float64Array(i),styles:new Uint16Array(i)}}const X=r=>Math.max(1,Math.min(g,Math.floor(_/Math.max(1,r))));function S(r,t){if(t===r.rows)return r;const s=t*r.cols;return{...r,rows:t,kinds:r.kinds.slice(0,s),values:r.values.slice(0,s),styles:r.styles.slice(0,s)}}function B(r,t,s){const n=r.kinds[t]&w,i=r.values[t];switch(n){case y:return"";case u:return r.strings[i];case d:return i?"TRUE":"FALSE";case f:return k[i]??"#N/A";default:{const e=r.styles[t];if(e===0||!s)return x(i);try{return v(s.code(e)).number(i).replace(/\u0001.?\u0001/g," ")}catch{return x(i)}}}}function G(r){const t=new Set;return r.map((s,n)=>{const i=String(s??"").replace(/\s+/g," ").trim().slice(0,F-8)||M(n);let e=i;for(let o=1;t.has(e.toLowerCase());o++)e=`${i}_${o}`;return t.add(e.toLowerCase()),e})}class ${constructor(){this.names=[],this.columns=[],this.nextRow=-1,this.cur=null,this.capacity=0,this.used=0,this.incoming=[],this.remap=new Int32Array(0)}_ensureColumns(t){const s=Math.max(t,this.names.length);if(this.columns.length>=s&&this.columnsFrom===this.names)return;const n=Math.max(s,this.columns.length),i=new Array(n);for(let e=0;e<n;e++)i[e]=this.names[e]??this.columns[e]??M(e);this.columns=i,this.columnsFrom=this.names}_capacityFor(t){return Math.max(16,Math.min(g,Math.floor(_/t)))}_open(t){this._ensureColumns(t);const s=Math.max(this.columns.length,1);this.capacity=this._capacityFor(s),this.cur=A(this.capacity,s,this.columns),this.used=0,this.remap.fill(-1)}_widen(t){this._ensureColumns(t);const s=this.cur,n=Math.max(this.columns.length,1),i=Math.max(this._capacityFor(n),this.used+1),e=A(i,n,this.columns,s.strings);for(let o=0;o<this.used;o++){const h=o*s.cols,l=o*n;e.kinds.set(s.kinds.subarray(h,h+s.cols),l),e.values.set(s.values.subarray(h,h+s.cols),l),e.styles.set(s.styles.subarray(h,h+s.cols),l)}this.cur=e,this.capacity=i}_take(t){const s=S(this.cur,t);return s.columns=this.columns,this.nextRow+=t,this.cur=null,this.used=0,s}*push(t,s,n){n&&(this.names=n),this.incoming=s,this.remap=this.remap.length>=s.length?this.remap.fill(-1):new Int32Array(s.length).fill(-1),this.cur!==null&&(this.names.length>this.cur.cols?this._widen(this.names.length):this._ensureColumns(this.cur.cols));for(let i=0;i<t.count;i++){const e=t.cols[i];if(e>=C)continue;const o=t.rows[i];this.nextRow<0&&(this.nextRow=o),this.cur===null&&this._open(e+1);let h=o-this.nextRow;for(;h>=this.capacity;)yield this._take(this.capacity),this._open(e+1),h=o-this.nextRow;e>=this.cur.cols&&this._widen(e+1);const l=this.cur,c=h*l.cols+e,p=t.kinds[i]&w;if(l.kinds[c]=p,l.styles[c]=t.styles[i],p===u){const m=t.values[i];let a=this.remap[m];a===-1&&(a=l.strings.length,l.strings.push(s[m]),this.remap[m]=a),l.values[c]=a}else l.values[c]=t.values[i];h>=this.used&&(this.used=h+1)}}*end(){this.cur!==null&&this.used>0&&(yield this._take(this.used)),this.cur=null}}class K{constructor(t=65536){this.capacity=t,this.rows=new Uint32Array(t),this.cols=new Uint16Array(t),this.kinds=new Uint8Array(t),this.values=new Float64Array(t),this.styles=new Uint16Array(t),this.count=0,this.strings=[],this.index=new Map}get full(){return this.count>=L}_grow(){const t=this.capacity*2,s=(n,i)=>{const e=new n(t);return e.set(i),e};this.rows=s(Uint32Array,this.rows),this.cols=s(Uint16Array,this.cols),this.kinds=s(Uint8Array,this.kinds),this.values=s(Float64Array,this.values),this.styles=s(Uint16Array,this.styles),this.capacity=t}add(t,s,n,i,e=0){this.count===this.capacity&&this._grow();const o=this.count++;this.rows[o]=t,this.cols[o]=s,this.kinds[o]=n,this.values[o]=i,this.styles[o]=e}addText(t,s,n){let i=this.index.get(n);i===void 0&&(i=this.strings.length,this.strings.push(n),this.index.set(n,i)),this.add(t,s,u,i)}reset(){this.count=0,this.strings=[],this.index=new Map}}export{d as BOOL,F as COLUMN_NAME_LIMIT,K as CellCollector,y as EMPTY,f as ERR,z as Formats,_ as MATRIX_CELLS,g as MATRIX_ROWS,C as MAX_COLUMNS,R as NUM,$ as RowAssembler,u as STR,N as TEXT_LIMIT,B as cellText,G as cleanColumnNames,M as columnName,A as newBatch,X as rowsFor,S as trimBatch,O as wordedError};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{parseInput as m}from"../../core/input.js";import{partsToSerial as i}from"../../core/numfmt.js";import{NUM as d,wordedError as l}from"./rows.js";const N=2;class c extends Error{}const v=(n,r,t,e)=>{const{cols:s}=n,o=r*s,a=e*t.cols;for(let u=0;u<s;u++)t.kinds[a+u]=n.kinds[o+u],t.values[a+u]=n.values[o+u],t.styles[a+u]=n.styles[o+u]};class x{constructor(r){this.names=r,this.columns=null,this.at=[],this.seen=new Array(r.length).fill(!1)}resolve(r){if(r===this.columns)return this.at;this.columns=r;const t=new Map;return r.forEach((e,s)=>{t.has(e)||t.set(e,s)}),this.at=this.names.map((e,s)=>{const o=t.get(e)??-1;return o>=0&&(this.seen[s]=!0),o}),this.at}check(r){if(!r)return;const t=this.names.filter((e,s)=>!this.seen[s]);if(t.length)throw l(c,"Column not found: {names}. The source may have changed; edit the query.",{names:t.join(", ")})}}const f=/^(\d{1,2})[./-](\d{1,2})[./-](\d{4})(?:[ T](\d{1,2}):(\d{2})(?::(\d{2}))?)?$/,h=/^(\d{4})-(\d{1,2})-(\d{1,2})[ T](\d{1,2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/;function g(n){const r=n.trim();let t=h.exec(r);if(t)return{value:i(Number(t[1]),Number(t[2]),Number(t[3]))+(Number(t[4])*3600+Number(t[5])*60+Number(t[6]??0))/86400,format:"yyyy-mm-dd hh:mm"};const e=m(r);if(e.kind===d&&e.format&&/[ymd]/i.test(e.format))return{value:e.value,format:e.format};if(t=f.exec(r),t){const s=Number(t[2]),o=Number(t[1]);if(s>=1&&s<=12&&o>=1&&o<=31){const a=i(Number(t[3]),s,o);return t[4]!==void 0?{value:a+(Number(t[4])*3600+Number(t[5])*60+Number(t[6]??0))/86400,format:"yyyy-mm-dd hh:mm"}:{value:a,format:"yyyy-mm-dd"}}}return null}function E(n){const r=n.trim(),t=m(r);if(t.kind===d)return{value:t.value,format:t.format??null};const e=r.replace(/[\s ]/g,"");return/^[+-]?\d+,\d+$/.test(e)?{value:Number(e.replace(",",".")),format:null}:/^[+-]?\d+$/.test(e)?{value:Number(e),format:null}:null}class T{constructor(){this.keys=[],this.at=new Map}of(r){return r.map(t=>{let e=this.at.get(t);return e===void 0&&(e=this.keys.push(t)-1,this.at.set(t,e)),e})}}export{x as ColumnLookup,T as Places,c as StepError,N as VALUE_ERROR,v as copyRowsOf,g as textToDate,E as textToNumber};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{CHUNK_BITS as N,CHUNK_MASK as T,CHUNK_SIZE as p,Sheet as S}from"../../core/sheet.js";import{colName as y}from"../../core/address.js";import{StringTable as R}from"../../core/strings.js";import{Engine as k}from"../../calc/engine.js";import{formulaEntryLimit as F,toFileFormula as b}from"../../calc/parser.js";import{Arr as I,ERR as g,Lambda as U,Ref as M,RefList as _,XlError as A}from"../../calc/values.js";import{BOOL as x,ERR as D,NUM as H,STR as v,TEXT_LIMIT as K,wordedError as h}from"./rows.js";import{StepError as d}from"./shared-steps.js";import{Rearrange as X}from"./steps-more.js";import{setFormulaStage as B}from"./steps.js";const L=()=>{const i=new k({sheets:[],strings:new R,dateOffset:0});return i.legacy=!0,i},P=/\b(?:ROW|COLUMN|OFFSET|INDIRECT|CELL|SHEET|SHEETS|FORMULATEXT|ISFORMULA|GETPIVOTDATA)\s*\(/i,O=(i,e)=>!i.invalid&&!i.external&&i.names.length===0&&i.tables.length===0&&i.refs.every(t=>!t.sheet&&t.r0===0&&t.r1===0&&!t.rAbs0&&!t.rAbs1&&t.cAbs0&&t.cAbs1&&t.c1<e),V=/\[@?\[?\s*([^[\]]+?)\s*\]?\]/g,W=(i,e)=>i.split(/("(?:[^"]|"")*"?)/).map((t,a)=>a%2?t:e(t)).join("");function ne(i,e){const t=i.trim().replace(/^=/,""),a=[],c=(f,E)=>{const w=e.find(C=>C.toLowerCase()===f.toLowerCase());if(w===void 0)throw h(d,"There is no column {name}.",{name:f});let u=a.indexOf(w);return u<0&&(u=a.push(w)-1),E(u)},s=f=>b(W(t,E=>E.replace(V,(w,u)=>c(u,f))));if(P.test(t.replace(/"(?:[^"]|"")*"?/g,'""')))throw h(d,"A custom column works out each row by itself, so it can't use ROW, OFFSET, INDIRECT and the like.");const l=s(f=>`$${y(f)}1`),o=F(l);if(o)throw h(d,o);const m=L(),n=m.template(s(()=>"1"),0,e.length),r=m.template(l,0,e.length);if(t===""||r.invalid)throw h(d,"The formula is not valid.");if(n.refs.length>0||!O(r,a.length))throw h(d,"The formula can only use the query's columns, as [Name].");return{formula:l,columns:a}}class ${constructor(e,t,a){this.count=t,this.formats=a,this.engine=L(),this.sheet=new S("__row"),this.sheet.maxCol=t-1;const c=this.engine.template(e,0,t);this.fn=O(c,t)?c.fn:()=>g.NAME,this.batch=null}start(e,t){if(this.batch===e)return;this.batch=e;const{sheet:a,engine:c}=this,s=new R;c.book.strings=s,c.book.dateOffset=this.formats.dateOffset??0,a.maxRow=e.rows-1;for(let l=0;l<this.count;l++){const o=t[l],m=[];for(let n=0;n<e.rows;n+=p)m.push({kinds:new Uint8Array(p),values:new Float64Array(p),styles:null});for(let n=0;n<e.rows&&o>=0&&o<e.cols;n++){const r=n*e.cols+o,f=m[n>>N];f.kinds[n&T]=e.kinds[r],f.values[n&T]=e.kinds[r]===v?s.add(e.strings[e.values[r]]):e.values[r]}a.columns[l]=m}}value(e){const{engine:t,sheet:a,count:c}=this;let s;try{s=this.fn(e,c,a),(s instanceof M||s instanceof _)&&(s=t.refAuto(s,e,c))}catch(l){return l instanceof A?l:g.VALUE}return s instanceof I&&(s=s.data[0]),s instanceof U?g.CALC:typeof s=="number"&&!Number.isFinite(s)?g.NUM:s??null}}function j({formula:i,columns:e,to:t},a){const c=new $(i,e.length,a);return new X(e,s=>({names:[...s,t],from:[...s.map((l,o)=>o),-1]}),(s,l,o,m,n)=>{c.start(s,m);const r=c.value(l);r===null||r===""||(typeof r=="number"?(o.kinds[n]=H,o.values[n]=r):typeof r=="boolean"?(o.kinds[n]=x,o.values[n]=Number(r)):r instanceof A?(o.kinds[n]=D,o.values[n]=r.index):(o.kinds[n]=v,o.values[n]=o.strings.push(String(r).slice(0,K))-1))})}B(j);export{ne as compileFormula};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{formatNumber as Z,partsToSerial as b,serialToParts as ut}from"../../core/numfmt.js";import{BOOL as at,cellText as L,cleanColumnNames as j,EMPTY as f,ERR as E,newBatch as T,NUM as g,rowsFor as tt,STR as m,TEXT_LIMIT as G,trimBatch as q,wordedError as D}from"./rows.js";import{ColumnLookup as N,copyRowsOf as ct,Places as et,StepError as U,textToNumber as st,VALUE_ERROR as nt}from"./shared-steps.js";import{MAX_COLS as _,MAX_ROWS as P}from"../../core/address.js";const ht={trim:"Trim",clean:"Clean",lower:"lowercase",upper:"UPPERCASE",proper:"Capitalize Each Word",length:"Length",first:"First Characters…",last:"Last Characters…",before:"Text Before Delimiter…",after:"Text After Delimiter…",prefix:"Add Prefix…",suffix:"Add Suffix…"},dt={round:"Round…",roundUp:"Round Up",roundDown:"Round Down",abs:"Absolute Value",add:"Add…",subtract:"Subtract…",multiply:"Multiply…",divide:"Divide…",percent:"Percentage…"},ft={dateOnly:"Date Only",timeOnly:"Time Only",year:"Year",quarter:"Quarter",month:"Month",monthName:"Month Name",week:"Week of Year",day:"Day",weekday:"Day of Week",weekdayName:"Name of Day",hour:"Hour",minute:"Minute",second:"Second",startOfYear:"Start of Year",startOfMonth:"Start of Month",endOfMonth:"End of Month",age:"Days to Today"},mt={first:"count",last:"count",before:"text",after:"text",prefix:"text",suffix:"text",round:"integer",add:"number",subtract:"number",multiply:"number",divide:"number",percent:"number"},ot={sum:"Sum",average:"Average",min:"Min",max:"Max",count:"Count Rows",countValues:"Count Values",distinct:"Count Distinct Values",first:"First Value",join:"All Values, Joined"},pt=["keepFirst","keepLast","removeFirst","removeLast","alternate","removeBlank","removeErrors","keepErrors"],kt=e=>e.replace(/^[\s ]+|[\s ]+$/g,""),yt=e=>e.toLowerCase().replace(/(^|[^\p{L}\p{N}'’])(\p{L})/gu,(t,s,n)=>s+n.toUpperCase()),J=e=>Array.from(e),gt={trim:kt,clean:e=>e.replace(/[\u0000-\u001f\u007f]/g,""),lower:e=>e.toLowerCase(),upper:e=>e.toUpperCase(),proper:yt,length:e=>J(e).length,first:(e,t)=>J(e).slice(0,t).join(""),last:(e,t)=>t===0?"":J(e).slice(-t).join(""),before:(e,t)=>e.includes(t)?e.slice(0,e.indexOf(t)):e,after:(e,t)=>e.includes(t)?e.slice(e.indexOf(t)+t.length):"",prefix:(e,t)=>t+e,suffix:(e,t)=>e+t},vt=(e,t)=>{const s=10**t,n=Number((Math.abs(e)*s).toPrecision(15));return Math.sign(e)*Math.round(n)/s},wt={round:vt,roundUp:e=>Math.ceil(e),roundDown:e=>Math.floor(e),abs:Math.abs,add:(e,t)=>e+t,subtract:(e,t)=>e-t,multiply:(e,t)=>e*t,divide:(e,t)=>e/t,percent:(e,t)=>e*t/100},X="yyyy-mm-dd",F=(e,t,s)=>b(e,t,s),xt={dateOnly:e=>[Math.floor(e),X],timeOnly:e=>[e-Math.floor(e),"hh:mm:ss"],year:(e,t)=>[t.year],quarter:(e,t)=>[Math.ceil(t.month/3)],month:(e,t)=>[t.month],monthName:e=>[Z("mmmm",e)],week:(e,t)=>{const s=F(t.year,1,1);return[Math.floor((Math.floor(e)-s+(s-1)%7)/7)+1]},day:(e,t)=>[t.day],weekday:e=>[(Math.floor(e)+6)%7+1],weekdayName:e=>[Z("dddd",e)],hour:(e,t)=>[t.hour],minute:(e,t)=>[t.minute],second:(e,t)=>[t.second],startOfYear:(e,t)=>[F(t.year,1,1),X],startOfMonth:(e,t)=>[F(t.year,t.month,1),X],endOfMonth:(e,t)=>[(t.month===12?F(t.year+1,1,1):F(t.year,t.month+1,1))-1,X],age:(e,t,s)=>[s-Math.floor(e)]},Mt=new Set(["dateOnly","startOfYear","startOfMonth","endOfMonth"]);class Y{constructor(t,s,n){this.lookup=new N([t]),this.formats=s,this.change=n,this.saw=!1}*push(t){this.saw=!0;const s=this.lookup.resolve(t.columns)[0];if(s<0||s>=t.cols){yield t;return}const n={...t,kinds:t.kinds.slice(),values:t.values.slice(),styles:t.styles.slice()},{formats:o}=this;let i=null;for(let r=0,l=s;r<t.rows;r++,l+=t.cols){const u=this.change(t,l);u!==void 0&&(u===null?(n.kinds[l]=f,n.styles[l]=0):typeof u.value=="string"?(i===null&&(i=t.strings.slice(),n.strings=i),n.kinds[l]=m,n.values[l]=i.push(u.value.slice(0,G))-1,n.styles[l]=0):u.error||!Number.isFinite(u.value)?(n.kinds[l]=E,n.values[l]=nt,n.styles[l]=0):(n.kinds[l]=g,n.values[l]=u.value,n.styles[l]=u.keep?t.styles[l]:o.id(u.format??null)))}yield n}*end(){this.lookup.check(this.saw)}}const lt={error:!0};function Et({column:e,find:t,replace:s,whole:n},o){const i=st(t)?.value??null,r=st(s),l=s===""?null:r?{value:r.value,keep:!0}:{value:s};return new Y(e,o,(u,h)=>{const c=u.kinds[h];if(c===f)return t===""?l??void 0:void 0;if(c===m){const a=u.strings[u.values[h]];return n||t===""?a===t?s===""?null:{value:s}:void 0:a.includes(t)?{value:a.split(t).join(s)}:void 0}if(c===g)return i!==null&&u.values[h]===i?l:void 0})}function St({column:e,fn:t,value:s},n){const o=gt[t];return new Y(e,n,(i,r)=>{const l=i.kinds[r];if(l===f||l===E)return;const u=o(L(i,r,n),s);return u===""?null:{value:u}})}function Ot({column:e,fn:t,value:s},n){const o=wt[t];return new Y(e,n,(i,r)=>{const l=i.kinds[r];if(!(l===f||l===E))return l===g?{value:o(i.values[r],s),keep:!0}:lt})}function At({column:e,fn:t},s){const n=xt[t],o=new Date,i=b(o.getFullYear(),o.getMonth()+1,o.getDate());return new Y(e,s,(r,l)=>{const u=r.kinds[l];if(u===f||u===E)return;const h=s.dateOffset??0,c=r.values[l]+h;if(u!==g||c<0||c>=2958466)return lt;const[a,d]=n(c,ut(c),i);return{value:Mt.has(t)?a-h:a,format:d}})}class Tt{constructor({column:t,up:s}){this.lookup=new N([t]),this.up=s===!0,this.last=null,this.held=[],this.total=0,this.saw=!1}*push(t){if(this.saw=!0,this.up){if(this.lookup.resolve(t.columns),this.total+=t.rows,this.total>P)throw D(U,"Filling up needs all its rows in memory, and this query passed {rows} rows there. Filter first.",{rows:P.toLocaleString("en-US")});this.held.push(t);return}yield this._fill(t)}_fill(t){const s=this.lookup.resolve(t.columns)[0];if(s<0||s>=t.cols)return t;const n={...t,kinds:t.kinds.slice(),values:t.values.slice(),styles:t.styles.slice(),strings:t.strings},o=this.up?t.rows-1:0,i=this.up?-1:1;let r=null,l=-1;for(let u=0,h=o;u<t.rows;u++,h+=i){const c=h*t.cols+s,a=t.kinds[c];if(a!==f&&!(a===m&&t.strings[t.values[c]]==="")){this.last={kind:a,value:a===m?t.strings[t.values[c]]:t.values[c],style:t.styles[c]},l=a===m?t.values[c]:-1;continue}this.last!==null&&(this.last.kind===m&&l<0&&(r??=t.strings.slice(),n.strings=r,l=r.push(this.last.value)-1),n.kinds[c]=this.last.kind,n.values[c]=this.last.kind===m?l:this.last.value,n.styles[c]=this.last.style)}return n}*end(){this.lookup.check(this.saw);const t=this.held.reverse().map(s=>this._fill(s)).reverse();this.held=[],yield*t}}class ${constructor(t,s,n=null){this.lookup=new N(t),this.plan=s,this.fill=n,this.lastIn=null,this.made=null,this.places=new et,this.names=[],this.saw=!1}_make(t,s){const{names:n,from:o}=this.plan(t,s),i=new Set,r=o.map(c=>c<0?"new":i.has(c)?`copy${c}`:(i.add(c),c)),l=this.places.of(r),u=this.places.keys.length;if(u>_)throw D(U,"This step would make more than {count} columns.",{count:_.toLocaleString("en-US")});const h=new Array(u).fill(-1);l.forEach((c,a)=>{h[c]=o[a],this.names[c]=n[a]}),this.made={names:j(this.names),from:h,added:this.places.at.get("new")??-1}}*push(t){this.saw=!0;const s=this.lookup.resolve(t.columns);t.columns!==this.lastIn&&(this.lastIn=t.columns,this._make(t.columns,s));const{names:n,from:o,added:i}=this.made,r=T(t.rows,n.length,n,this.fill?t.strings.slice():t.strings);for(let l=0;l<t.rows;l++){const u=l*t.cols,h=l*r.cols;for(let c=0;c<o.length;c++){const a=o[c];a<0||a>=t.cols||(r.kinds[h+c]=t.kinds[u+a],r.values[h+c]=t.values[u+a],r.styles[h+c]=t.styles[u+a])}this.fill?.(t,l,r,s,l*r.cols+i)}yield r}*end(){this.lookup.check(this.saw)}}const S=e=>e.map((t,s)=>s);function Nt({names:e}){return new $(e,(t,s)=>{const n=S(t).filter(o=>!s.includes(o));return{names:n.map(o=>t[o]),from:n}})}function _t({column:e,to:t}){return new $([e],(s,n)=>({names:[...s,t],from:[...S(s),n[0]]}))}function Rt({columns:e,delimiter:t,to:s},n){return new $(e,(o,i)=>{const r=i.filter(d=>d>=0),l=r.length?Math.min(...r):o.length,u=S(o).filter(d=>d===l||!r.includes(d)),h=l<o.length?u.indexOf(l):u.length,c=u.map(d=>o[d]);c[h]=s;const a=u.slice();return a[h]=-1,{names:c,from:a}},(o,i,r,l,u)=>{const h=i*o.cols,c=l.map(a=>a<0||a>=o.cols||o.kinds[h+a]===f?"":L(o,h+a,n)).join(t);c!==""&&(r.kinds[u]=m,r.values[u]=r.strings.push(c.slice(0,G))-1)})}function Ct({to:e,start:t,step:s}){let n=t;return new $([],o=>({names:[...o,e],from:[...S(o),-1]}),(o,i,r,l,u)=>{r.kinds[u]=g,r.values[u]=n,n+=s})}class Lt{constructor({what:t,count:s=0,skip:n=0}){this.what=t,this.count=s,this.skip=n,this.at=0,this.held=[],this.heldRows=0}_pick(t,s){const n=T(t.rows,t.cols,t.columns,t.strings);let o=0;for(let i=0;i<t.rows;i++)s(i)&&ct(t,i,n,o++);return q(n,o)}*push(t){const{what:s,count:n}=this,o=this.at;this.at+=t.rows;const i=l=>{for(let u=l*t.cols,h=0;h<t.cols;h++,u++)if(t.kinds[u]!==f&&!(t.kinds[u]===m&&t.strings[t.values[u]]===""))return!1;return!0},r=l=>{for(let u=l*t.cols,h=0;h<t.cols;h++,u++)if(t.kinds[u]===E)return!0;return!1};switch(s){case"keepFirst":yield this._pick(t,l=>o+l<n);break;case"removeFirst":yield this._pick(t,l=>o+l>=n);break;case"alternate":yield this._pick(t,l=>(o+l)%(n+this.skip)>=n);break;case"removeBlank":yield this._pick(t,l=>!i(l));break;case"removeErrors":yield this._pick(t,l=>!r(l));break;case"keepErrors":yield this._pick(t,r);break;default:for(this.held.push(t),this.heldRows+=t.rows;this.held.length>1&&this.heldRows-this.held[0].rows>=n;){const l=this.held.shift();this.heldRows-=l.rows,yield s==="removeLast"?l:q(l,0)}}}*end(){let t=this.heldRows;for(const s of this.held){const n=t-s.rows,o=Math.max(0,Math.min(s.rows,this.count-n));yield this._pick(s,this.what==="removeLast"?i=>i<s.rows-o:i=>i>=s.rows-o),t=n}this.held=[]}}const K=(e,t)=>e.kinds[t]===m?`s${e.strings[e.values[t]]}`:e.kinds[t]===f?"":`${e.kinds[t]}:${e.values[t]}`,B=(e,t)=>({kind:e.kinds[t],value:e.kinds[t]===m?e.strings[e.values[t]]:e.values[t],style:e.styles[t]}),R={kind:f,value:0,style:0};class it{constructor(t){this.fn=t,this.n=0,this.sum=0,this.best=null,this.style=0,this.error=null,this.set=t==="distinct"?new Set:null,this.text=null}add(t,s,n){const{fn:o}=this;if(o==="count"){this.n++;return}const i=s<0?f:t.kinds[s];if(i!==f)if(o==="distinct")this.set.add(K(t,s));else if(o==="join")this.text===null?this.text=L(t,s,n):this.text.length<G&&(this.text+=`, ${L(t,s,n)}`);else if(o==="countValues")this.n++;else if(o==="first")this.best??=B(t,s);else if(i===E)this.error??=B(t,s);else if(o==="min"||o==="max"){const r=B(t,s),l=(u,h)=>u.kind!==h.kind?u.kind<h.kind:u.value<h.value;(this.best===null||(o==="min"?l(r,this.best):l(this.best,r)))&&(this.best=r)}else i===g?(this.n++,this.sum+=t.values[s],this.style||=t.styles[s]):i!==at&&(this.error??={kind:E,value:nt,style:0})}result(){if(this.error)return this.error;switch(this.fn){case"count":case"countValues":return{kind:g,value:this.n,style:0};case"distinct":return{kind:g,value:this.set.size,style:0};case"join":return this.text!==null?{kind:m,value:this.text.slice(0,G),style:0}:R;case"sum":return this.n?{kind:g,value:this.sum,style:this.style}:R;case"average":return this.n?{kind:g,value:this.sum/this.n,style:this.style}:R;default:return this.best??R}}}function*rt(e,t,s){t.length===0&&(yield T(0,e.length,e));const n=tt(e.length);for(let o=0;o<t.length;o+=n){const i=Math.min(n,t.length-o),r=T(i,e.length,e),l=new Map;for(let u=0;u<i;u++){const h=u*e.length;s(t[o+u],(c,a)=>{if(!a||a.kind===f)return;const d=h+c;if(r.kinds[d]=a.kind,r.styles[d]=a.style,a.kind===m){let k=l.get(a.value);k===void 0&&(k=r.strings.push(a.value)-1,l.set(a.value,k)),r.values[d]=k}else r.values[d]=a.value})}yield r}}const z=P;class Dt{constructor({by:t,values:s},n){this.by=t,this.values=s,this.formats=n,this.lookup=new N([...t,...s.filter(o=>o.fn!=="count").map(o=>o.column)]),this.groups=new Map,this.saw=!1}*push(t){this.saw=!0;const s=this.lookup.resolve(t.columns),n=this.by.length,o=l=>l>=0&&l<t.cols?l:-1;let i=n;const r=this.values.map(l=>l.fn==="count"?-1:o(s[i++]));for(let l=0;l<t.rows;l++){const u=l*t.cols;let h="";for(let a=0;a<n;a++)h+=`${o(s[a])<0?"":K(t,u+s[a])}\0`;let c=this.groups.get(h);if(c===void 0){if(this.groups.size>=z)throw D(U,"Group By found more than {rows} groups.",{rows:z.toLocaleString("en-US")});c={cells:s.slice(0,n).map(a=>o(a)<0?R:B(t,u+a)),totals:this.values.map(a=>new it(a.fn))},this.groups.set(h,c)}for(let a=0;a<c.totals.length;a++)c.totals[a].add(t,r[a]<0?-1:u+r[a],this.formats)}}*end(){this.lookup.check(this.saw);const t=j([...this.by,...this.values.map(n=>n.to)]),s=[...this.groups.values()];this.groups.clear(),yield*rt(t,s,(n,o)=>{n.cells.forEach((i,r)=>o(r,i)),n.totals.forEach((i,r)=>o(n.cells.length+r,i.result()))})}}class Ut{constructor({column:t,values:s,fn:n},o){this.lookup=new N([t,s]),this.fn=n,this.formats=o,this.names=new Map,this.rows=new Map,this.rest=[],this.saw=!1}*push(t){this.saw=!0;const[s,n]=this.lookup.resolve(t.columns),o=S(t.columns).filter(i=>i!==s&&i!==n);o.length>this.rest.length&&(this.rest=o.map(i=>t.columns[i]));for(let i=0;i<t.rows;i++){const r=i*t.cols;let l="";for(const d of o)l+=`${d<t.cols?K(t,r+d):""}\0`;l=l.replace(/\u0000+$/,"");let u=this.rows.get(l);if(u===void 0){if(this.rows.size>=z)throw D(U,"Group By found more than {rows} groups.",{rows:z.toLocaleString("en-US")});u={cells:o.map(d=>d<t.cols?B(t,r+d):R),totals:new Map},this.rows.set(l,u)}const h=s>=0&&s<t.cols&&t.kinds[r+s]!==f?L(t,r+s,this.formats):"";let c=this.names.get(h);if(c===void 0){if(c=this.names.size,c+this.rest.length>=_)throw D(U,"This step would make more than {count} columns.",{count:_.toLocaleString("en-US")});this.names.set(h,c)}let a=u.totals.get(c);a===void 0&&u.totals.set(c,a=new it(this.fn)),a.add(t,n>=0&&n<t.cols?r+n:-1,this.formats)}}*end(){this.lookup.check(this.saw);const t=j([...this.rest,...this.names.keys()]),s=[...this.rows.values()];this.rows.clear();const n=this.rest.length;yield*rt(t,s,(o,i)=>{o.cells.forEach((r,l)=>i(l,r));for(const[r,l]of o.totals)i(n+r,l.result())})}}class Ft{constructor({columns:t,others:s,attribute:n,value:o}){this.names=t,this.others=s===!0,this.attribute=n,this.value=o,this.lookup=new N(t),this.places=new et,this.columnNames=[],this.saw=!1,this.lastIn=null,this.made=null}*push(t){this.saw=!0;const s=this.lookup.resolve(t.columns);if(t.columns!==this.lastIn){this.lastIn=t.columns;const x=new Set(s),M=S(t.columns).filter(y=>x.has(y)!==this.others),v=S(t.columns).filter(y=>!M.includes(y)),O=this.places.of([...v,"attribute","value"]);[...v.map(y=>t.columns[y]),this.attribute,this.value].forEach((y,V)=>{this.columnNames[O[V]]=y}),this.made={turned:M,kept:v,to:O,names:j(this.columnNames)}}const{turned:n,kept:o,to:i,names:r}=this.made,[l,u]=i.slice(o.length),h=r.length,c=t.strings.slice(),a=n.map(x=>c.push(t.columns[x])-1),d=tt(h);let k=T(d,h,r,c),I=0;for(let x=0;x<t.rows;x++){const M=x*t.cols;for(let v=0;v<n.length;v++){const O=n[v];if(O>=t.cols||t.kinds[M+O]===f)continue;const y=I*h,V=(A,C)=>{A>=t.cols||(k.kinds[y+C]=t.kinds[M+A],k.values[y+C]=t.values[M+A],k.styles[y+C]=t.styles[M+A])};o.forEach((A,C)=>V(A,i[C])),k.kinds[y+l]=m,k.values[y+l]=a[v],V(O,u),++I===d&&(yield k,k=T(d,h,r,c),I=0)}}yield q(k,I)}*end(){this.lookup.check(this.saw)}}const Yt={replaceValues:Et,changeText:St,changeNumber:Ot,changeDate:At,fill:e=>new Tt(e),removeColumns:Nt,duplicateColumn:_t,mergeColumns:Rt,addIndex:Ct,keepRows:e=>new Lt(e),groupBy:(e,t)=>new Dt(e,t),pivot:(e,t)=>new Ut(e,t),unpivot:e=>new Ft(e)},Bt=P,It=1024,p=(e,t=It)=>typeof e=="string"&&e.length<=t,w=e=>p(e)&&e!=="",H=e=>Array.isArray(e)&&e.length>0&&e.length<=_&&e.every(t=>p(t)),W=(e,t=0)=>Number.isInteger(e)&&e>=t&&e<=Bt,Q=e=>typeof e=="number"&&Number.isFinite(e);function Vt(e,t){switch(mt[e]){case"count":return W(t);case"text":return w(t);case"integer":return Number.isInteger(t)&&Math.abs(t)<=15;case"number":return Q(t)&&!(e==="divide"&&t===0);default:return t===void 0}}function $t(e){const{op:t,column:s}=e,n=o=>p(s)&&Object.hasOwn(o,e.fn)&&Vt(e.fn,e.value)?{op:t,column:s,fn:e.fn,...e.value===void 0?{}:{value:e.value}}:null;switch(t){case"replaceValues":return p(s)&&p(e.find)&&p(e.replace)?{op:t,column:s,find:e.find,replace:e.replace,whole:e.whole===!0}:null;case"changeText":return n(ht);case"changeNumber":return n(dt);case"changeDate":return n(ft);case"fill":return p(s)?{op:t,column:s,up:e.up===!0}:null;case"removeColumns":return H(e.names)?{op:t,names:[...e.names]}:null;case"duplicateColumn":return p(s)&&w(e.to)?{op:t,column:s,to:e.to}:null;case"mergeColumns":return H(e.columns)&&p(e.delimiter)&&w(e.to)?{op:t,columns:[...e.columns],delimiter:e.delimiter,to:e.to}:null;case"addFormula":return w(e.to)&&p(e.formula,8192)&&e.formula!==""&&Array.isArray(e.columns)&&e.columns.length<=_&&e.columns.every(o=>p(o))?{op:t,to:e.to,formula:e.formula,columns:[...e.columns]}:null;case"addIndex":return w(e.to)&&Q(e.start)&&Q(e.step)?{op:t,to:e.to,start:e.start,step:e.step}:null;case"keepRows":return pt.includes(e.what)?["keepFirst","keepLast","removeFirst","removeLast"].includes(e.what)?W(e.count)?{op:t,what:e.what,count:e.count}:null:e.what==="alternate"?W(e.count,1)&&W(e.skip,1)?{op:t,what:e.what,count:e.count,skip:e.skip}:null:{op:t,what:e.what}:null;case"groupBy":{const o=Array.isArray(e.values)&&e.values.length>0&&e.values.length<=256&&e.values.every(i=>i!==null&&typeof i=="object"&&Object.hasOwn(ot,i.fn)&&w(i.to)&&(i.fn==="count"||p(i.column)))?e.values.map(i=>({fn:i.fn,to:i.to,...i.fn==="count"?{}:{column:i.column}})):null;return o&&H(e.by)?{op:t,by:[...e.by],values:o}:null}case"pivot":return p(s)&&p(e.values)&&Object.hasOwn(ot,e.fn)?{op:t,column:s,values:e.values,fn:e.fn}:null;case"unpivot":return H(e.columns)&&w(e.attribute)&&w(e.value)?{op:t,columns:[...e.columns],others:e.others===!0,attribute:e.attribute,value:e.value}:null;default:return null}}export{ot as AGGREGATES,mt as CHANGE_VALUES,ft as DATE_CHANGES,Yt as MORE_STAGES,dt as NUMBER_CHANGES,pt as ROW_STEPS,$ as Rearrange,ht as TEXT_CHANGES,$t as cleanMoreStep,Vt as validChange};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{cleanColumnNames as _,EMPTY as m,newBatch as g,rowsFor as A,STR as q,trimBatch as E,wordedError as w}from"./rows.js";import{ColumnLookup as N,Places as b,StepError as y}from"./shared-steps.js";import{MAX_COLS as x}from"../../core/address.js";const L={left:"All rows of this query, matching rows of the table",inner:"Only matching rows",right:"All rows of the table, matching rows of this query",full:"All rows of both",leftAnti:"Only rows of this query without a match",rightAnti:"Only rows of the table without a match"},M=(n,t)=>[...new Map(n.filter(e=>(e.op==="append"||e.op==="join")&&e[t]).map(e=>[e[t].toUpperCase(),e[t]])).values()],B=n=>M(n,"table"),J=n=>M(n,"query"),j=n=>`query:${n}`;function T(n,{table:t,query:e}){const s=n?.get((e?j(e):t).toUpperCase());if(!s&&e)throw w(y,'This workbook no longer has a query named "{name}".',{name:e});if(!s)throw w(y,'This workbook no longer has a table named "{name}".',{name:t});return s}function k(n,t,e,s,l,h){const r=t*n.cols;for(let a=0;a<e.length;a++){const o=e[a];if(o<0||o>=n.cols)continue;const i=n.kinds[r+o];if(i===m)continue;if(s.kinds[l+a]=i,s.styles[l+a]=n.styles[r+o],i!==q){s.values[l+a]=n.values[r+o];continue}const c=n.strings[n.values[r+o]];let u=h.get(c);u===void 0&&(u=s.strings.push(c)-1,h.set(c,u)),s.values[l+a]=u}}class v{constructor(t,e){this.input=T(e,t),this.columns=null}*push(t){(this.columns===null||t.columns.length>this.columns.length)&&(this.columns=t.columns),yield t}*end(){const t=this.columns??[],e=new Map(t.map((o,i)=>[o.toLowerCase(),i])),s=this.input.columns.map(o=>e.get(o.toLowerCase())??-1),l=[...t];s.forEach((o,i)=>{o<0&&(s[i]=l.push(this.input.columns[i])-1)});const h=l.map((o,i)=>s.indexOf(i)),r=_(l),a=A(r.length);for(const o of this.input.batches)for(let i=0;i<o.rows;i+=a){const c=g(Math.min(a,o.rows-i),r.length,r),u=new Map;for(let p=0;p<c.rows;p++)k(o,i+p,h,c,p*c.cols,u);yield c}}}class ${constructor(t,e){const{kind:s,left:l,right:h,add:r}=t;this.input=T(e,t),this.kind=s,this.lookup=new N(l);const a=o=>o.map(i=>{const c=this.input.columns.findIndex(u=>u===i);if(c<0)throw w(y,"Column not found: {names}. The source may have changed; edit the query.",{names:i});return c});this.keys=a(h),this.add=s==="leftAnti"?[]:a(r),this.index=new Map,this.input.batches.forEach((o,i)=>{for(let c=0;c<o.rows;c++){const u=this._key(o,c,this.keys);if(u===null)continue;const p=this.index.get(u);p?p.push(i,c):this.index.set(u,[i,c])}}),this.used=s==="right"||s==="full"||s==="rightAnti"?this.input.batches.map(o=>new Uint8Array(o.rows)):null,this.places=new b,this.columnNames=[],this.names=null,this.lastIn=null,this.saw=!1}_key(t,e,s){let l="",h=!1;for(const r of s){const a=e*t.cols+r,o=r>=0&&r<t.cols?t.kinds[a]:m;o!==m&&(h=!0),l+=o===m?"\0":o===q?`s${t.strings[t.values[a]]}\0`:`${o}:${t.values[a]}\0`}return h?l:null}_columnsFor(t){if(t===this.lastIn)return;this.lastIn=t;const e=this.add.map(l=>this.input.columns[l]);if(t.length+e.length>x)throw w(y,"This step would make more than {count} columns.",{count:x.toLocaleString("en-US")});const s=this.places.of([...t.keys(),...this.add.map(l=>`added${l}`)]);[...t,...e].forEach((l,h)=>{this.columnNames[s[h]]=l}),this.names=_(this.columnNames),this.own=new Array(this.names.length).fill(-1),this.other=new Array(this.names.length).fill(-1),t.forEach((l,h)=>{this.own[s[h]]=h}),this.add.forEach((l,h)=>{this.other[s[t.length+h]]=l})}*push(t){this.saw=!0,this._columnsFor(t.columns);const e=this.lookup.resolve(t.columns),{kind:s,names:l,used:h}=this,r=l.length,a=A(r),o=()=>({out:g(a,r,l),known:new Map,n:0});let i=o();const c=s==="leftAnti"||s==="rightAnti";for(let u=0;u<t.rows;u++){const p=this._key(t,u,e),f=p===null?void 0:this.index.get(p);if(f&&h)for(let d=0;d<f.length;d+=2)h[f[d]][f[d+1]]=1;if(c?s==="rightAnti"||f:!f&&(s==="inner"||s==="right"))continue;const I=c||!f?1:f.length/2;for(let d=0;d<I;d++){const S=i.n*r;k(t,u,this.own,i.out,S,i.known),f&&k(this.input.batches[f[2*d]],f[2*d+1],this.other,i.out,S,i.known),++i.n===a&&(yield i.out,i=o())}}yield E(i.out,i.n)}*end(){if(this.lookup.check(this.saw),this.used===null)return;this.names===null&&this._columnsFor([]);const t=this.names.length,e=A(t);let s=g(e,t,this.names),l=new Map,h=0;for(let r=0;r<this.input.batches.length;r++){const a=this.input.batches[r];for(let o=0;o<a.rows;o++)this.used[r][o]||(k(a,o,this.other,s,h*t,l),!(++h<e)&&(yield s,s=g(e,t,this.names),l=new Map,h=0))}yield E(s,h)}}const P={append:(n,t,e)=>new v(n,e),join:(n,t,e)=>new $(n,e)},C=n=>typeof n=="string"&&n.length<=1024,O=(n,t)=>Array.isArray(n)&&n.length>=t&&n.length<=x&&n.every(C);function D(n){const t=s=>C(s)&&s!=="";if(!t(n.table)&&!t(n.query))return null;const e=t(n.query)?{query:n.query}:{table:n.table};return n.op==="append"?{op:"append",...e}:n.op!=="join"||!Object.hasOwn(L,n.kind)||!O(n.left,1)||!O(n.right,1)||n.left.length!==n.right.length||!O(n.add,0)?null:{op:"join",...e,kind:n.kind,left:[...n.left],right:[...n.right],add:[...n.add]}}export{L as JOIN_KINDS,P as TABLE_STAGES,D as cleanTableStep,J as queriesOfSteps,j as queryInput,B as tablesOfSteps};
|
package/extras/getdata/steps.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parseInput as P}from"../../core/input.js";import{partsToSerial as H}from"../../core/numfmt.js";import{cellText as U,cleanColumnNames as D,columnName as G,EMPTY as p,BOOL as S,ERR as A,MATRIX_ROWS as K,newBatch as _,NUM as C,STR as M,trimBatch as Y,wordedError as W}from"./rows.js";import{MAX_ROWS as z}from"../../core/address.js";import{t as y}from"../../i18n/index.js";const $=2,xs=["promoteHeaders","chooseColumns","rename","changeType","filterRows","removeDuplicates","sort","splitColumn"],Cs=256,J={text:"Text",number:"Number",date:"Date",bool:"True/False"},Q={equals:"equals",notEquals:"does not equal",contains:"contains",notContains:"does not contain",beginsWith:"begins with",endsWith:"ends with",gt:"is greater than",gte:"is greater than or equal to",lt:"is less than",lte:"is less than or equal to",isBlank:"is blank",notBlank:"is not blank"};class E extends Error{}function Ms(c){switch(c.op){case"promoteHeaders":return y("Use first row as headers");case"chooseColumns":return y("Choose {count} columns",{count:c.names.length});case"rename":return y('Rename "{from}" to "{to}"',{from:c.from,to:c.to});case"changeType":return y('"{column}" as {type}',{column:c.column,type:y(J[c.to]??c.to)});case"filterRows":{const s=y(Q[c.test]??c.test);return c.test==="isBlank"||c.test==="notBlank"?y('Keep "{column}" {test}',{column:c.column,test:s}):y('Keep "{column}" {test} "{value}"',{column:c.column,test:s,value:c.value})}case"removeDuplicates":return c.columns?y("Remove duplicates in {count} columns",{count:c.columns.length}):y("Remove duplicates");case"sort":return c.desc?y('Sort "{column}" Z to A',{column:c.column}):y('Sort "{column}" A to Z',{column:c.column});case"splitColumn":return y('Split "{column}" by "{delimiter}" into {count}',{column:c.column,delimiter:c.delimiter===" "?"Tab":c.delimiter,count:c.parts});default:return c.op}}const X=(c,s,t,n)=>{const{cols:i}=c,o=s*i,l=n*t.cols;for(let e=0;e<i;e++)t.kinds[l+e]=c.kinds[o+e],t.values[l+e]=c.values[o+e],t.styles[l+e]=c.styles[o+e]};class R{constructor(s){this.names=s,this.columns=null,this.at=[],this.seen=new Array(s.length).fill(!1)}resolve(s){if(s===this.columns)return this.at;this.columns=s;const t=new Map;return s.forEach((n,i)=>{t.has(n)||t.set(n,i)}),this.at=this.names.map((n,i)=>{const o=t.get(n)??-1;return o>=0&&(this.seen[i]=!0),o}),this.at}check(s){if(!s)return;const t=this.names.filter((n,i)=>!this.seen[i]);if(t.length)throw W(E,"Column not found: {names}. The source may have changed; edit the query.",{names:t.join(", ")})}}class b{constructor(){this.names=null,this.columns=null,this.lastIn=null}_columnsFor(s){if(s.columns===this.lastIn&&this.columns)return this.columns;this.lastIn=s.columns;const t=Math.max(s.cols,this.names.length),n=this.names.slice();for(let i=this.names.length;i<t;i++)n.push(G(i));return this.columns=D(n),this.columns}*push(s){if(this.names===null){if(s.rows===0)return;const t=[];for(let i=0;i<s.cols;i++)t.push(U(s,i,null));if(this.names=D(t),s.rows===1)return;const n=s.rows-1;yield{...s,rows:n,columns:this._columnsFor(s),kinds:s.kinds.subarray(s.cols),values:s.values.subarray(s.cols),styles:s.styles.subarray(s.cols)};return}yield{...s,columns:this._columnsFor(s)}}*end(){}}class ss{constructor({names:s}){this.lookup=new R(s),this.names=s,this.saw=!1}*push(s){this.saw=!0;const t=this.lookup.resolve(s.columns),n=_(s.rows,this.names.length,this.names,s.strings);for(let i=0;i<s.rows;i++){const o=i*s.cols,l=i*n.cols;for(let e=0;e<t.length;e++){const r=t[e];r<0||r>=s.cols||(n.kinds[l+e]=s.kinds[o+r],n.values[l+e]=s.values[o+r],n.styles[l+e]=s.styles[o+r])}}yield n}*end(){this.lookup.check(this.saw)}}class ts{constructor({column:s,delimiter:t,parts:n},i){this.lookup=new R([s]),this.column=s,this.delimiter=t||",",this.parts=Math.max(1,Math.min(100,Math.round(n)||2)),this.formats=i,this.lastIn=null,this.names=null,this.saw=!1}*push(s){this.saw=!0;const t=this.lookup.resolve(s.columns)[0];if(t<0||t>=s.cols){yield s;return}if(s.columns!==this.lastIn){this.lastIn=s.columns;const l=Array.from({length:this.parts},(e,r)=>`${this.column}.${r+1}`);this.names=D([...s.columns.slice(0,t),...l,...s.columns.slice(t+1)])}const n=s.cols-1+this.parts,i=s.strings.slice(),o=_(s.rows,n,this.names,i);for(let l=0;l<s.rows;l++){const e=l*s.cols,r=l*n;for(let h=0;h<s.cols;h++){if(h===t)continue;const m=r+(h<t?h:h-1+this.parts);o.kinds[m]=s.kinds[e+h],o.values[m]=s.values[e+h],o.styles[m]=s.styles[e+h]}if(s.kinds[e+t]===p)continue;const u=U(s,e+t,this.formats).split(this.delimiter);(u.length>this.parts?[...u.slice(0,this.parts-1),u.slice(this.parts-1).join(this.delimiter)]:u).forEach((h,m)=>{if(h==="")return;const g=r+t+m;o.kinds[g]=M,o.values[g]=i.push(h)-1})}yield o}*end(){this.lookup.check(this.saw)}}class es{constructor({from:s,to:t}){this.from=s,this.to=t,this.lastIn=null,this.out=null,this.found=!1,this.saw=!1}*push(s){if(this.saw=!0,s.columns!==this.lastIn){this.lastIn=s.columns;const t=s.columns.indexOf(this.from);t>=0&&(this.found=!0),this.out=t<0?s.columns:s.columns.map((n,i)=>i===t?this.to:n)}yield{...s,columns:this.out}}*end(){if(this.saw&&!this.found)throw W(E,"Column not found: {names}. The source may have changed; edit the query.",{names:this.from})}}const ns=/^(\d{1,2})[./-](\d{1,2})[./-](\d{4})(?:[ T](\d{1,2}):(\d{2})(?::(\d{2}))?)?$/,os=/^(\d{4})-(\d{1,2})-(\d{1,2})[ T](\d{1,2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/;function ls(c){const s=c.trim();let t=os.exec(s);if(t)return{value:H(Number(t[1]),Number(t[2]),Number(t[3]))+(Number(t[4])*3600+Number(t[5])*60+Number(t[6]??0))/86400,format:"yyyy-mm-dd hh:mm"};const n=P(s);if(n.kind===C&&n.format&&/[ymd]/i.test(n.format))return{value:n.value,format:n.format};if(t=ns.exec(s),t){const i=Number(t[2]),o=Number(t[1]);if(i>=1&&i<=12&&o>=1&&o<=31){const l=H(Number(t[3]),i,o);return t[4]!==void 0?{value:l+(Number(t[4])*3600+Number(t[5])*60+Number(t[6]??0))/86400,format:"yyyy-mm-dd hh:mm"}:{value:l,format:"yyyy-mm-dd"}}}return null}function Z(c){const s=c.trim(),t=P(s);if(t.kind===C)return{value:t.value,format:t.format??null};const n=s.replace(/[\s ]/g,"");return/^[+-]?\d+,\d+$/.test(n)?{value:Number(n.replace(",",".")),format:null}:/^[+-]?\d+$/.test(n)?{value:Number(n),format:null}:null}class rs{constructor({column:s,to:t},n){this.lookup=new R([s]),this.to=t,this.formats=n,this.saw=!1}*push(s){this.saw=!0;const t=this.lookup.resolve(s.columns)[0];if(t<0||t>=s.cols){yield s;return}const{formats:n,to:i}=this,o={...s,kinds:s.kinds.slice(),values:s.values.slice(),styles:s.styles.slice(),strings:s.strings};let l=null;const e=r=>(l===null&&(l=s.strings.slice(),o.strings=l),l.push(r),l.length-1);for(let r=0,u=t;r<s.rows;r++,u+=s.cols){const d=s.kinds[u];if(d===p||d===A)continue;const h=s.values[u];if(i==="text"){if(d===M)continue;o.values[u]=e(U(s,u,n)),o.kinds[u]=M,o.styles[u]=0}else if(i==="number"){if(d===C){o.styles[u]=/[ymdhs]/i.test(n.code(s.styles[u]))?0:s.styles[u];continue}if(d===S){o.kinds[u]=C,o.values[u]=h;continue}const m=Z(s.strings[h]);m===null?(o.kinds[u]=A,o.values[u]=$):(o.kinds[u]=C,o.values[u]=m.value,o.styles[u]=n.id(m.format))}else if(i==="date"){if(d===C){o.styles[u]=n.id("yyyy-mm-dd");continue}const m=d===M?ls(s.strings[h]):null;m===null?(o.kinds[u]=A,o.values[u]=$):(o.kinds[u]=C,o.values[u]=m.value,o.styles[u]=n.id(m.format))}else if(i==="bool"){if(d===S)continue;if(d===C){o.kinds[u]=S,o.values[u]=h!==0?1:0,o.styles[u]=0;continue}const m=s.strings[h].trim().toLowerCase();m==="true"||m==="false"?(o.kinds[u]=S,o.values[u]=m==="true"?1:0):(o.kinds[u]=A,o.values[u]=$)}}yield o}*end(){this.lookup.check(this.saw)}}function is({test:c,value:s}){const t=String(s??""),n=t.toLowerCase(),i=Z(t)?.value??null,o=(l,e,r)=>{if(i!==null&&l===C)return e<i?-1:e>i?1:0;const u=(r??"").toLowerCase();return u<n?-1:u>n?1:0};switch(c){case"equals":return(l,e,r)=>o(l,e,r)===0;case"notEquals":return(l,e,r)=>o(l,e,r)!==0;case"contains":return(l,e,r)=>(r??"").toLowerCase().includes(n);case"notContains":return(l,e,r)=>!(r??"").toLowerCase().includes(n);case"beginsWith":return(l,e,r)=>(r??"").toLowerCase().startsWith(n);case"endsWith":return(l,e,r)=>(r??"").toLowerCase().endsWith(n);case"gt":return(l,e,r)=>l!==p&&o(l,e,r)>0;case"gte":return(l,e,r)=>l!==p&&o(l,e,r)>=0;case"lt":return(l,e,r)=>l!==p&&o(l,e,r)<0;case"lte":return(l,e,r)=>l!==p&&o(l,e,r)<=0;case"isBlank":return(l,e,r)=>l===p||r==="";case"notBlank":return(l,e,r)=>l!==p&&r!=="";default:throw new E(`Unknown filter: ${c}`)}}class cs{constructor(s,t){this.lookup=new R([s.column]),this.test=is(s),this.formats=t,this.saw=!1}*push(s){this.saw=!0;const t=this.lookup.resolve(s.columns)[0],n=_(s.rows,s.cols,s.columns,s.strings);let i=0;for(let o=0;o<s.rows;o++){let l;if(t<0||t>=s.cols)l=this.test(p,0,"");else{const e=o*s.cols+t,r=s.kinds[e];l=this.test(r,s.values[e],r===p?"":r===M?s.strings[s.values[e]]:U(s,e,this.formats))}l&&X(s,o,n,i++)}yield Y(n,i)}*end(){this.lookup.check(this.saw)}}class us{constructor(){this.size=0,this.table=new Uint32Array(65536),this.mask=32767}add(s,t){s===0&&t===0&&(t=1);let n=t&this.mask;const i=this.table;for(;;){const o=i[n*2],l=i[n*2+1];if(o===0&&l===0)break;if(o===s&&l===t)return!1;n=n+1&this.mask}return i[n*2]=s,i[n*2+1]=t,this.size++,this.size*2>this.mask&&this._grow(),!0}_grow(){const s=this.table,t=new Uint32Array(s.length*2),n=t.length/2-1;for(let i=0;i<s.length;i+=2){const o=s[i],l=s[i+1];if(o===0&&l===0)continue;let e=l&n;for(;t[e*2]!==0||t[e*2+1]!==0;)e=e+1&n;t[e*2]=o,t[e*2+1]=l}this.table=t,this.mask=n}}const j=new Float64Array(1),q=new Uint32Array(j.buffer);class as{constructor({columns:s}){this.names=s??null,this.lookup=s?new R(s):null,this.seen=new us,this.saw=!1}*push(s){this.saw=!0;const t=this.lookup?this.lookup.resolve(s.columns):null,n=t?t.length:s.cols,i=_(s.rows,s.cols,s.columns,s.strings);let o=0;for(let l=0;l<s.rows;l++){let e=2166136261,r=2654435761;const u=l*s.cols;let d=-1;for(let h=0;h<n;h++){const m=t?t[h]:h;m>=0&&m<s.cols&&s.kinds[u+m]!==p&&(d=h)}for(let h=0;h<=d;h++){const m=t?t[h]:h,g=u+m,a=m>=0&&m<s.cols?s.kinds[g]:p;if(e=Math.imul(e^a,16777619),r=Math.imul(r^a+31,2246822507),a!==p){if(a===M){const w=s.strings[s.values[g]];for(let f=0;f<w.length;f++){const k=w.charCodeAt(f);e=Math.imul(e^k,16777619),r=Math.imul(r^k,3266489909),r=r<<13|r>>>19}}else j[0]=s.values[g]===0?0:s.values[g],e=Math.imul(e^q[0],16777619),e=Math.imul(e^q[1],16777619),r=Math.imul(r^q[0],3266489909),r=Math.imul(r^q[1],2246822507),r=r<<13|r>>>19;e=Math.imul(e^255,16777619)}}this.seen.add(e>>>0,r>>>0)&&X(s,l,i,o++)}yield Y(i,o)}*end(){this.lookup?.check(this.saw)}}const hs=new Intl.Collator("en",{sensitivity:"accent",numeric:!1}),ms={[C]:0,[M]:1,[S]:2,[A]:3};class fs{constructor({column:s,desc:t}){this.lookup=new R([s]),this.desc=!!t,this.batches=[],this.total=0,this.saw=!1}*push(s){if(this.saw=!0,this.lookup.resolve(s.columns),this.total+=s.rows,this.total>z)throw W(E,"Sorting needs all its rows in memory, and this query passed {rows} rows at the sort. Filter first, or sort after loading.",{rows:z.toLocaleString("en-US")});this.batches.push(s)}*end(){this.lookup.check(this.saw);const{batches:s,total:t,desc:n}=this;if(this.batches=[],t===0){s.length&&(yield s[s.length-1]);return}const i=new Uint32Array(t),o=new Uint32Array(t),l=new Uint8Array(t),e=new Float64Array(t),r=new Array(t);let u=0;s.forEach((a,w)=>{const f=this.lookup.resolve(a.columns)[0];for(let k=0;k<a.rows;k++,u++){i[u]=k,o[u]=w;const v=k*a.cols+f,T=f>=0&&f<a.cols?a.kinds[v]:p;l[u]=T===p?255:ms[T]??4,T===M?r[u]=a.strings[a.values[v]]:T!==p&&(e[u]=a.values[v])}});const d=new Uint32Array(t);for(let a=0;a<t;a++)d[a]=a;const h=n?-1:1;d.sort((a,w)=>{const f=l[a],k=l[w];if(f===255||k===255)return f===k?a-w:f===255?1:-1;if(f!==k)return(f-k)*h;if(f===1){const v=hs.compare(r[a],r[w]);return v!==0?v*h:a-w}return e[a]!==e[w]?(e[a]<e[w]?-1:1)*h:a-w});let m=s[0].columns;for(const a of s)a.columns.length>m.length&&(m=a.columns);const g=m.length;for(let a=0;a<t;a+=K){const w=Math.min(K,t-a),f=_(w,g,m),k=new Map;for(let v=0;v<w;v++){const T=d[a+v],N=s[o[T]],I=i[T]*N.cols,O=v*g,V=Math.min(N.cols,g);for(let x=0;x<V;x++){const B=N.kinds[I+x];if(B!==p)if(f.kinds[O+x]=B,f.styles[O+x]=N.styles[I+x],B===M){const F=N.strings[N.values[I+x]];let L=k.get(F);L===void 0&&(L=f.strings.length,f.strings.push(F),k.set(F,L)),f.values[O+x]=L}else f.values[O+x]=N.values[I+x]}}yield f}}}function ds(c,s){switch(c.op){case"promoteHeaders":return new b;case"chooseColumns":return new ss(c);case"rename":return new es(c);case"changeType":return new rs(c,s);case"filterRows":return new cs(c,s);case"removeDuplicates":return new as(c);case"sort":return new fs(c);case"splitColumn":return new ts(c,s);default:throw new E(`Unknown step: ${c.op}`)}}class ps{constructor(s,t){this.stages=s.map(n=>ds(n,t))}*_through(s,t){if(s===this.stages.length){yield t;return}for(const n of this.stages[s].push(t))yield*this._through(s+1,n)}*push(s){yield*this._through(0,s)}*end(){for(let s=0;s<this.stages.length;s++)for(const t of this.stages[s].end())yield*this._through(s+1,t)}}function Ts(c,s,t,n=1/0){const i=new ps(s,t),o=[];let l=0,e=c[0]?.columns??[];const r=u=>{e=u.columns,l<n&&o.push(u),l+=u.rows};for(const u of c)for(const d of i.push(u))r(d);for(const u of i.end())r(u);return{batches:o,columns:e,rows:l}}export{J as COLUMN_TYPES,Q as FILTER_OPS,Cs as MAX_DELIMITER,ps as Pipeline,xs as STEP_OPS,E as StepError,Ms as describeStep,Ts as runSteps};
|
|
1
|
+
import{cellText as q,cleanColumnNames as G,columnName as Z,EMPTY as w,BOOL as M,ERR as _,MATRIX_ROWS as j,newBatch as O,NUM as S,STR as C,trimBatch as $,wordedError as K}from"./rows.js";import{ColumnLookup as R,copyRowsOf as X,StepError as E,textToDate as Q,textToNumber as z,VALUE_ERROR as W}from"./shared-steps.js";import{AGGREGATES as b,DATE_CHANGES as tt,MORE_STAGES as H,NUMBER_CHANGES as st,TEXT_CHANGES as et}from"./steps-more.js";import{TABLE_STAGES as P}from"./steps-tables.js";import{MAX_ROWS as J}from"../../core/address.js";import{t as m}from"../../i18n/index.js";const Et=["promoteHeaders","chooseColumns","rename","changeType","filterRows","removeDuplicates","sort","splitColumn","addFormula",...Object.keys(H),...Object.keys(P)],Mt=256,nt={text:"Text",number:"Number",date:"Date",bool:"True/False"},ot={equals:"equals",notEquals:"does not equal",contains:"contains",notContains:"does not contain",beginsWith:"begins with",endsWith:"ends with",gt:"is greater than",gte:"is greater than or equal to",lt:"is less than",lte:"is less than or equal to",isBlank:"is blank",notBlank:"is not blank"},lt=(s,t)=>m(s[t.fn]).replace(/…$/,"");function rt(s){const{column:t}=s;switch(s.op){case"replaceValues":return m('Replace "{find}" with "{replace}" in "{column}"',{column:t,find:s.find,replace:s.replace});case"changeText":case"changeNumber":case"changeDate":{const e=lt(s.op==="changeText"?et:s.op==="changeNumber"?st:tt,s);return s.value===void 0?m('"{column}": {change}',{column:t,change:e}):m('"{column}": {change} {value}',{column:t,change:e,value:s.value})}case"fill":return s.up?m('Fill up "{column}"',{column:t}):m('Fill down "{column}"',{column:t});case"removeColumns":return m("Remove {count} columns",{count:s.names.length});case"duplicateColumn":return m('Duplicate "{column}" as "{name}"',{column:t,name:s.to});case"mergeColumns":return m('Merge {count} columns into "{name}"',{count:s.columns.length,name:s.to});case"addFormula":return m('Custom column "{name}"',{name:s.to});case"addIndex":return m('Index column "{name}"',{name:s.to});case"keepRows":return m(`rows|${s.what}`,{count:s.count??0,skip:s.skip??0});case"groupBy":return m("Group by {names}",{names:s.by.join(", ")});case"pivot":return m('Pivot "{column}" with {change} of "{values}"',{column:t,change:m(b[s.fn]),values:s.values});case"append":return s.query?m("Append query {name}",{name:s.query}):m("Append table {name}",{name:s.table});case"join":return s.query?m("Join with query {name}",{name:s.query}):m("Join with table {name}",{name:s.table});case"unpivot":return s.others?m("Unpivot the other columns"):m("Unpivot {count} columns",{count:s.columns.length});default:return null}}function _t(s){switch(s.op){case"promoteHeaders":return m("Use first row as headers");case"chooseColumns":return m("Choose {count} columns",{count:s.names.length});case"rename":return m('Rename "{from}" to "{to}"',{from:s.from,to:s.to});case"changeType":return m('"{column}" as {type}',{column:s.column,type:m(nt[s.to]??s.to)});case"filterRows":{const t=m(ot[s.test]??s.test);return s.test==="isBlank"||s.test==="notBlank"?m('Keep "{column}" {test}',{column:s.column,test:t}):m('Keep "{column}" {test} "{value}"',{column:s.column,test:t,value:s.value})}case"removeDuplicates":return s.columns?m("Remove duplicates in {count} columns",{count:s.columns.length}):m("Remove duplicates");case"sort":return s.desc?m('Sort "{column}" Z to A',{column:s.column}):m('Sort "{column}" A to Z',{column:s.column});case"splitColumn":return m('Split "{column}" by "{delimiter}" into {count}',{column:s.column,delimiter:s.delimiter===" "?"Tab":s.delimiter,count:s.parts});default:return rt(s)??s.op}}class it{constructor(){this.names=null,this.columns=null,this.lastIn=null}_columnsFor(t){if(t.columns===this.lastIn&&this.columns)return this.columns;this.lastIn=t.columns;const e=Math.max(t.cols,this.names.length),i=this.names.slice();for(let c=this.names.length;c<e;c++)i.push(Z(c));return this.columns=G(i),this.columns}*push(t){if(this.names===null){if(t.rows===0)return;const e=[];for(let c=0;c<t.cols;c++)e.push(q(t,c,null));if(this.names=G(e),t.rows===1)return;const i=t.rows-1;yield{...t,rows:i,columns:this._columnsFor(t),kinds:t.kinds.subarray(t.cols),values:t.values.subarray(t.cols),styles:t.styles.subarray(t.cols)};return}yield{...t,columns:this._columnsFor(t)}}*end(){}}class ct{constructor({names:t}){this.lookup=new R(t),this.names=t,this.saw=!1}*push(t){this.saw=!0;const e=this.lookup.resolve(t.columns),i=O(t.rows,this.names.length,this.names,t.strings);for(let c=0;c<t.rows;c++){const r=c*t.cols,l=c*i.cols;for(let n=0;n<e.length;n++){const o=e[n];o<0||o>=t.cols||(i.kinds[l+n]=t.kinds[r+o],i.values[l+n]=t.values[r+o],i.styles[l+n]=t.styles[r+o])}}yield i}*end(){this.lookup.check(this.saw)}}class at{constructor({column:t,delimiter:e,parts:i},c){this.lookup=new R([t]),this.column=t,this.delimiter=e||",",this.parts=Math.max(1,Math.min(100,Math.round(i)||2)),this.formats=c,this.lastIn=null,this.names=null,this.saw=!1}*push(t){this.saw=!0;const e=this.lookup.resolve(t.columns)[0];if(e<0||e>=t.cols){yield t;return}if(t.columns!==this.lastIn){this.lastIn=t.columns;const l=Array.from({length:this.parts},(n,o)=>`${this.column}.${o+1}`);this.names=G([...t.columns.slice(0,e),...l,...t.columns.slice(e+1)])}const i=t.cols-1+this.parts,c=t.strings.slice(),r=O(t.rows,i,this.names,c);for(let l=0;l<t.rows;l++){const n=l*t.cols,o=l*i;for(let u=0;u<t.cols;u++){if(u===e)continue;const f=o+(u<e?u:u-1+this.parts);r.kinds[f]=t.kinds[n+u],r.values[f]=t.values[n+u],r.styles[f]=t.styles[n+u]}if(t.kinds[n+e]===w)continue;const a=q(t,n+e,this.formats).split(this.delimiter);(a.length>this.parts?[...a.slice(0,this.parts-1),a.slice(this.parts-1).join(this.delimiter)]:a).forEach((u,f)=>{if(u==="")return;const y=o+e+f;r.kinds[y]=C,r.values[y]=c.push(u)-1})}yield r}*end(){this.lookup.check(this.saw)}}class ut{constructor({from:t,to:e}){this.from=t,this.to=e,this.lastIn=null,this.out=null,this.found=!1,this.saw=!1}*push(t){if(this.saw=!0,t.columns!==this.lastIn){this.lastIn=t.columns;const e=t.columns.indexOf(this.from);e>=0&&(this.found=!0),this.out=e<0?t.columns:t.columns.map((i,c)=>c===e?this.to:i)}yield{...t,columns:this.out}}*end(){if(this.saw&&!this.found)throw K(E,"Column not found: {names}. The source may have changed; edit the query.",{names:this.from})}}class ht{constructor({column:t,to:e},i){this.lookup=new R([t]),this.to=e,this.formats=i,this.saw=!1}*push(t){this.saw=!0;const e=this.lookup.resolve(t.columns)[0];if(e<0||e>=t.cols){yield t;return}const{formats:i,to:c}=this,r={...t,kinds:t.kinds.slice(),values:t.values.slice(),styles:t.styles.slice(),strings:t.strings};let l=null;const n=o=>(l===null&&(l=t.strings.slice(),r.strings=l),l.push(o),l.length-1);for(let o=0,a=e;o<t.rows;o++,a+=t.cols){const d=t.kinds[a];if(d===w||d===_)continue;const u=t.values[a];if(c==="text"){if(d===C)continue;r.values[a]=n(q(t,a,i)),r.kinds[a]=C,r.styles[a]=0}else if(c==="number"){if(d===S){r.styles[a]=/[ymdhs]/i.test(i.code(t.styles[a]))?0:t.styles[a];continue}if(d===M){r.kinds[a]=S,r.values[a]=u;continue}const f=z(t.strings[u]);f===null?(r.kinds[a]=_,r.values[a]=W):(r.kinds[a]=S,r.values[a]=f.value,r.styles[a]=i.id(f.format))}else if(c==="date"){if(d===S){r.styles[a]=i.id("yyyy-mm-dd");continue}const f=d===C?Q(t.strings[u]):null;f===null?(r.kinds[a]=_,r.values[a]=W):(r.kinds[a]=S,r.values[a]=f.value,r.styles[a]=i.id(f.format))}else if(c==="bool"){if(d===M)continue;if(d===S){r.kinds[a]=M,r.values[a]=u!==0?1:0,r.styles[a]=0;continue}const f=t.strings[u].trim().toLowerCase();f==="true"||f==="false"?(r.kinds[a]=M,r.values[a]=f==="true"?1:0):(r.kinds[a]=_,r.values[a]=W)}}yield r}*end(){this.lookup.check(this.saw)}}function mt({test:s,value:t}){const e=String(t??""),i=e.toLowerCase(),c=z(e)?.value??null,r=(l,n,o)=>{if(c!==null&&l===S)return n<c?-1:n>c?1:0;const a=(o??"").toLowerCase();return a<i?-1:a>i?1:0};switch(s){case"equals":return(l,n,o)=>r(l,n,o)===0;case"notEquals":return(l,n,o)=>r(l,n,o)!==0;case"contains":return(l,n,o)=>(o??"").toLowerCase().includes(i);case"notContains":return(l,n,o)=>!(o??"").toLowerCase().includes(i);case"beginsWith":return(l,n,o)=>(o??"").toLowerCase().startsWith(i);case"endsWith":return(l,n,o)=>(o??"").toLowerCase().endsWith(i);case"gt":return(l,n,o)=>l!==w&&r(l,n,o)>0;case"gte":return(l,n,o)=>l!==w&&r(l,n,o)>=0;case"lt":return(l,n,o)=>l!==w&&r(l,n,o)<0;case"lte":return(l,n,o)=>l!==w&&r(l,n,o)<=0;case"isBlank":return(l,n,o)=>l===w||o==="";case"notBlank":return(l,n,o)=>l!==w&&o!=="";default:throw new E(`Unknown filter: ${s}`)}}class ft{constructor(t,e){this.lookup=new R([t.column]),this.test=mt(t),this.formats=e,this.saw=!1}*push(t){this.saw=!0;const e=this.lookup.resolve(t.columns)[0],i=O(t.rows,t.cols,t.columns,t.strings);let c=0;for(let r=0;r<t.rows;r++){let l;if(e<0||e>=t.cols)l=this.test(w,0,"");else{const n=r*t.cols+e,o=t.kinds[n];l=this.test(o,t.values[n],o===w?"":o===C?t.strings[t.values[n]]:q(t,n,this.formats))}l&&X(t,r,i,c++)}yield $(i,c)}*end(){this.lookup.check(this.saw)}}class dt{constructor(){this.size=0,this.table=new Uint32Array(65536),this.mask=32767}add(t,e){t===0&&e===0&&(e=1);let i=e&this.mask;const c=this.table;for(;;){const r=c[i*2],l=c[i*2+1];if(r===0&&l===0)break;if(r===t&&l===e)return!1;i=i+1&this.mask}return c[i*2]=t,c[i*2+1]=e,this.size++,this.size*2>this.mask&&this._grow(),!0}_grow(){const t=this.table,e=new Uint32Array(t.length*2),i=e.length/2-1;for(let c=0;c<t.length;c+=2){const r=t[c],l=t[c+1];if(r===0&&l===0)continue;let n=l&i;for(;e[n*2]!==0||e[n*2+1]!==0;)n=n+1&i;e[n*2]=r,e[n*2+1]=l}this.table=e,this.mask=i}}const V=new Float64Array(1),L=new Uint32Array(V.buffer);class pt{constructor({columns:t}){this.names=t??null,this.lookup=t?new R(t):null,this.seen=new dt,this.saw=!1}*push(t){this.saw=!0;const e=this.lookup?this.lookup.resolve(t.columns):null,i=e?e.length:t.cols,c=O(t.rows,t.cols,t.columns,t.strings);let r=0;for(let l=0;l<t.rows;l++){let n=2166136261,o=2654435761;const a=l*t.cols;let d=-1;for(let u=0;u<i;u++){const f=e?e[u]:u;f>=0&&f<t.cols&&t.kinds[a+f]!==w&&(d=u)}for(let u=0;u<=d;u++){const f=e?e[u]:u,y=a+f,h=f>=0&&f<t.cols?t.kinds[y]:w;if(n=Math.imul(n^h,16777619),o=Math.imul(o^h+31,2246822507),h!==w){if(h===C){const g=t.strings[t.values[y]];for(let p=0;p<g.length;p++){const k=g.charCodeAt(p);n=Math.imul(n^k,16777619),o=Math.imul(o^k,3266489909),o=o<<13|o>>>19}}else V[0]=t.values[y]===0?0:t.values[y],n=Math.imul(n^L[0],16777619),n=Math.imul(n^L[1],16777619),o=Math.imul(o^L[0],3266489909),o=Math.imul(o^L[1],2246822507),o=o<<13|o>>>19;n=Math.imul(n^255,16777619)}}this.seen.add(n>>>0,o>>>0)&&X(t,l,c,r++)}yield $(c,r)}*end(){this.lookup?.check(this.saw)}}const wt=new Intl.Collator("en",{sensitivity:"accent",numeric:!1}),gt={[S]:0,[C]:1,[M]:2,[_]:3};class kt{constructor({column:t,desc:e}){this.lookup=new R([t]),this.desc=!!e,this.batches=[],this.total=0,this.saw=!1}*push(t){if(this.saw=!0,this.lookup.resolve(t.columns),this.total+=t.rows,this.total>J)throw K(E,"Sorting needs all its rows in memory, and this query passed {rows} rows at the sort. Filter first, or sort after loading.",{rows:J.toLocaleString("en-US")});this.batches.push(t)}*end(){this.lookup.check(this.saw);const{batches:t,total:e,desc:i}=this;if(this.batches=[],e===0){t.length&&(yield t[t.length-1]);return}const c=new Uint32Array(e),r=new Uint32Array(e),l=new Uint8Array(e),n=new Float64Array(e),o=new Array(e);let a=0;t.forEach((h,g)=>{const p=this.lookup.resolve(h.columns)[0];for(let k=0;k<h.rows;k++,a++){c[a]=k,r[a]=g;const v=k*h.cols+p,A=p>=0&&p<h.cols?h.kinds[v]:w;l[a]=A===w?255:gt[A]??4,A===C?o[a]=h.strings[h.values[v]]:A!==w&&(n[a]=h.values[v])}});const d=new Uint32Array(e);for(let h=0;h<e;h++)d[h]=h;const u=i?-1:1;d.sort((h,g)=>{const p=l[h],k=l[g];if(p===255||k===255)return p===k?h-g:p===255?1:-1;if(p!==k)return(p-k)*u;if(p===1){const v=wt.compare(o[h],o[g]);return v!==0?v*u:h-g}return n[h]!==n[g]?(n[h]<n[g]?-1:1)*u:h-g});let f=t[0].columns;for(const h of t)h.columns.length>f.length&&(f=h.columns);const y=f.length;for(let h=0;h<e;h+=j){const g=Math.min(j,e-h),p=O(g,y,f),k=new Map;for(let v=0;v<g;v++){const A=d[h+v],T=t[r[A]],F=c[A]*T.cols,I=v*y,Y=Math.min(T.cols,y);for(let x=0;x<Y;x++){const B=T.kinds[F+x];if(B!==w)if(p.kinds[I+x]=B,p.styles[I+x]=T.styles[F+x],B===C){const D=T.strings[T.values[F+x]];let U=k.get(D);U===void 0&&(U=p.strings.length,p.strings.push(D),k.set(D,U)),p.values[I+x]=U}else p.values[I+x]=T.values[F+x]}}yield p}}}function yt(s,t,e){switch(s.op){case"promoteHeaders":return new it;case"chooseColumns":return new ct(s);case"rename":return new ut(s);case"changeType":return new ht(s,t);case"filterRows":return new ft(s,t);case"removeDuplicates":return new pt(s);case"sort":return new kt(s);case"splitColumn":return new at(s,t);case"addFormula":if(N===null)throw new E("Custom columns aren't loaded");return N(s,t);default:if(Object.hasOwn(P,s.op))return P[s.op](s,t,e);if(Object.hasOwn(H,s.op))return H[s.op](s,t);throw new E(`Unknown step: ${s.op}`)}}let N=null;function Ot(s){N=s}async function Ft(s){N===null&&s.some(t=>t.op==="addFormula")&&await import("./steps-formula.js")}class vt{constructor(t,e,i=null){this.stages=t.map(c=>yt(c,e,i))}*_through(t,e){if(t===this.stages.length){yield e;return}for(const i of this.stages[t].push(e))yield*this._through(t+1,i)}*push(t){yield*this._through(0,t)}*end(){for(let t=0;t<this.stages.length;t++)for(const e of this.stages[t].end())yield*this._through(t+1,e)}}function It(s,t,e,i=1/0,c=null){const r=new vt(t,e,c),l=[];let n=0,o=s[0]?.columns??[];const a=d=>{o=d.columns,n<i&&l.push(d),n+=d.rows};for(const d of s)for(const u of r.push(d))a(u);for(const d of r.end())a(d);return{batches:l,columns:o,rows:n}}export{nt as COLUMN_TYPES,ot as FILTER_OPS,Mt as MAX_DELIMITER,vt as Pipeline,Et as STEP_OPS,E as StepError,_t as describeStep,Ft as loadSteps,It as runSteps,Ot as setFormulaStage};
|
package/i18n/de/a11y.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e={"{range} merged":"{range} verbunden","picture: {alt}":"Bild: {alt}",picture:"Bild",blank:"leer","error {code}":"Fehler {code}","formula {formula}":"Formel {formula}","link to {target}":"Link zu {target}","note: {text}":"Notiz: {text}","comment: {text}":"Kommentar: {text}","{count} replies":{one:"{count} Antwort",other:"{count} Antworten"},resolved:"gelöst","has a drop-down list":"hat eine Dropdownliste","input message: {text}":"Eingabemeldung: {text}",locked:"gesperrt","{from} to {to}":"{from} bis {to}","{count} ranges selected":{one:"{count} Bereich ausgewählt",other:"{count} Bereiche ausgewählt"},"Entire sheet selected":"Gesamtes Blatt ausgewählt","Column {name} selected":"Spalte {name} ausgewählt","Columns {name} selected":"Spalten {name} ausgewählt","Row {name} selected":"Zeile {name} ausgewählt","Rows {name} selected":"Zeilen {name} ausgewählt","{range} selected, {rows} by {columns}":"{range} ausgewählt, {rows} mal {columns}","{count} columns":{one:"{count} Spalte",other:"{count} Spalten"},"object|chart":"Diagramm","object|picture":"Bild","object|shape":"Form","object|text box":"Textfeld","object|group":"Gruppe","object|connector":"Verbinder","object|object":"Objekt","object|form control":"Formularsteuerelement","object|media":"Medien","object|slicer":"Datenschnitt","title {text}":"Titel {text}","alt text: {text}":"Alternativtext: {text}",decorative:"dekorativ","no alt text":"kein Alternativtext","{index} of {count}":"{index} von {count}","This sheet has no objects.":"Dieses Blatt enthält keine Objekte.","Sheet {name}, {cell}":"Blatt {name}, {cell}","Sheet {name}, {index} of {count}":"Blatt {name}, {index} von {count}","Editing {cell}":"{cell} wird bearbeitet","Formula bar, editing {cell}":"Bearbeitungsleiste, {cell} wird bearbeitet","Cell Alt Text…":"Alternativtext der Zelle…","Cell Alt Text":"Alternativtext der Zelle","Alternative text":"Alternativtext",'A screen reader says this instead of the cell\'s text. Write {value} where the shown value goes, as in "{value} dollars". Leave it empty to read the cell as it is.':"Die Sprachausgabe liest dies anstelle des Zelltexts vor. Schreiben Sie {value} an die Stelle des angezeigten Werts, z. B. „{value} Euro“. Lassen Sie das Feld leer, um die Zelle unverändert vorzulesen.","KeyTips on. Type the letters of a tab or a button. Escape goes back.":"Zugriffstasteninfos ein. Geben Sie die Buchstaben einer Registerkarte oder Schaltfläche ein. Esc geht zurück.","KeyTips off":"Zugriffstasteninfos aus","{tab} tab":"Registerkarte „{tab}“",Accessibility:"Barrierefreiheit","Inspection Results":"Prüfungsergebnisse","Additional Information":"Zusätzliche Informationen","Recommended Actions":"Empfohlene Aktionen","Why Fix:":"Gründe für die Behebung:","How to Fix:":"Anleitung zur Behebung:","Keep accessibility checker running while I work":"Barrierefreiheitsprüfung während der Arbeit ausführen","No accessibility issues found. People with disabilities should have no trouble reading this workbook.":"Keine Barrierefreiheitsprobleme gefunden. Menschen mit Behinderungen sollten diese Arbeitsmappe problemlos lesen können.","{label}, {count} items":{one:"{label}, {count} Element",other:"{label}, {count} Elemente"},"{name} ({sheet})":"{name} ({sheet})","{name} selected on {sheet}":"{name} auf {sheet} ausgewählt","Accessibility: Checking…":"Barrierefreiheit: Wird überprüft…","Accessibility: Good to go":"Barrierefreiheit: Keine Probleme","Accessibility: Investigate":"Barrierefreiheit: Untersuchen","a11y|Errors":"Fehler","a11y|Warnings":"Warnungen","a11y|Tips":"Tipps","Add a description":"Beschreibung hinzufügen","Use the first row as headers":"Erste Zeile als Überschriften verwenden","Use automatic colors":"Automatische Farben verwenden","Unmerge cells":"Zellverbund aufheben","Edit the link":"Link bearbeiten","Rename the sheet":"Blatt umbenennen",'"{name}" can\'t be used as a sheet name.':"„{name}“ kann nicht als Blattname verwendet werden.","Missing table header":"Fehlende Tabellenüberschrift","Hard-to-read text contrast":"Schwer lesbarer Textkontrast","Unclear hyperlink text":"Unklarer Hyperlinktext","Default sheet names":"Standardblattnamen","Blank rows or columns in a table":"Leere Zeilen oder Spalten in einer Tabelle","Alternative text helps people who use a screen reader understand what's important in pictures, charts, shapes and other objects.":"Alternativtext hilft Personen, die eine Sprachausgabe verwenden, zu verstehen, was in Bildern, Diagrammen, Formen und anderen Objekten wichtig ist.","Select the object, then add a description of what it shows, or mark it as decorative if it adds nothing to the content.":"Wählen Sie das Objekt aus, und fügen Sie eine Beschreibung des Dargestellten hinzu, oder markieren Sie es als dekorativ, wenn es nichts zum Inhalt beiträgt.","Header rows tell people who use a screen reader what each column holds while they move through a table.":"Kopfzeilen teilen Personen, die eine Sprachausgabe verwenden, mit, was jede Spalte enthält, während sie sich durch eine Tabelle bewegen.","Turn on the table's header row and give each column a short, unique name.":"Aktivieren Sie die Kopfzeile der Tabelle, und geben Sie jeder Spalte einen kurzen, eindeutigen Namen.","Text with too little contrast against its background is hard to read for people with low vision or color blindness, and on any screen in bright light.":"Text mit zu geringem Kontrast zum Hintergrund ist für Personen mit Sehschwäche oder Farbenblindheit schwer lesbar, ebenso auf jedem Bildschirm bei hellem Licht.","Use a darker text color on a light fill, or a lighter one on a dark fill, for a contrast of at least 4.5:1, or 3:1 for large text.":"Verwenden Sie eine dunklere Textfarbe auf heller Füllung oder eine hellere auf dunkler Füllung für einen Kontrast von mindestens 4,5:1 oder 3:1 bei großem Text.","Screen readers lose their place in merged cells, and sorting and filtering don't work across them.":"Sprachausgaben verlieren in verbundenen Zellen die Orientierung, und Sortieren und Filtern funktionieren darin nicht.","Unmerge the cells, and use Center Across Selection where the merge was only for alignment.":"Heben Sie den Zellverbund auf, und verwenden Sie „Über Auswahl zentrieren“, wenn der Verbund nur der Ausrichtung diente.","People who use a screen reader often scan a list of links, so each link's text has to say where it goes.":"Personen, die eine Sprachausgabe verwenden, gehen oft eine Liste von Links durch, daher muss der Text jedes Links sagen, wohin er führt.",'Change the cell\'s text so that it describes the destination, instead of a bare web address or words such as "click here".':"Ändern Sie den Text der Zelle so, dass er das Ziel beschreibt, statt einer bloßen Webadresse oder Wörtern wie „hier klicken“.","Sheet names that say what a sheet holds make a workbook easier to find one's way in, for everyone.":"Blattnamen, die den Inhalt eines Blatts nennen, erleichtern allen die Orientierung in einer Arbeitsmappe.","Rename the sheet with a short name that describes its content.":"Geben Sie dem Blatt einen kurzen Namen, der seinen Inhalt beschreibt.","Empty rows and columns used for spacing make a screen reader announce a table as ending where it doesn't.":"Leere Zeilen und Spalten, die als Abstand dienen, führen dazu, dass eine Sprachausgabe das Ende einer Tabelle meldet, wo sie nicht endet.","Delete the empty rows or columns, and use row height or column width for spacing instead.":"Löschen Sie die leeren Zeilen oder Spalten, und verwenden Sie stattdessen Zeilenhöhe oder Spaltenbreite für Abstände."};export{e as default};
|