@8sheets/data-grid 1.0.2 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/api/serialize.js +1 -1
- package/api/theme-core.js +2 -0
- 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/financial.js +1 -1
- package/calc/functions/helpers.js +1 -1
- 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 +3 -3
- package/calc/values.js +1 -1
- package/calcx/async.js +1 -1
- package/calcx/culture/custom.js +1 -0
- package/calcx/culture/format-locale.js +1 -1
- package/calcx/culture/separators.js +1 -0
- package/calcx/functions/dynamic.js +1 -1
- package/calcx/functions/ets.js +1 -1
- package/calcx/functions/misc.js +1 -1
- package/calcx/lang/convert.js +1 -0
- package/cells/axis-ops.js +1 -1
- package/cells/block.js +1 -0
- package/cells/book-css.js +2 -2
- package/cells/cell-defaults.js +1 -1
- package/cells/cf-engine.js +1 -1
- package/cells/consolidate-links.js +1 -1
- package/cells/find-engine.js +2 -2
- package/cells/format-panes.js +3 -3
- package/cells/format-tabs.js +2 -2
- package/cells/outline-column.js +1 -1
- package/cells/panes.js +1 -1
- package/cells/rich-runs.js +2 -2
- package/cells/rich-values.js +1 -1
- package/cells/selection-modes.js +1 -1
- package/cells/shift-check.js +1 -0
- package/cells/table-rows.js +1 -0
- package/cells/text-layout.js +9 -8
- package/cells/ui-kit.js +15 -0
- package/cells/view-options.js +1 -1
- package/celltypes/cell-types.js +2 -2
- package/celltypes/diagonal.js +1 -1
- package/celltypes/dropdowns.js +3 -2
- package/celltypes/file-cell.js +2 -2
- package/celltypes/range-template.js +2 -2
- package/core/autofill.js +1 -1
- package/core/axis-styles.js +1 -0
- package/core/axis.js +1 -1
- package/core/cell-type-rules.js +1 -0
- package/core/changes.js +1 -1
- package/core/cond-format.js +1 -1
- package/core/culture.js +1 -0
- package/core/formula-refs.js +1 -1
- package/core/input.js +1 -1
- package/core/merge.js +1 -0
- package/core/numfmt.js +1 -1
- package/core/region-input.js +1 -0
- package/core/row-fit.js +1 -0
- package/core/sheet.js +1 -1
- package/core/sparse.js +1 -1
- package/core/structure.js +1 -0
- package/core/styles.js +1 -1
- package/core/tables.js +2 -2
- package/core/validation-ranges.js +1 -0
- package/core/whatif.js +1 -1
- package/core/workbook.js +1 -1
- package/datasheets/data-core.js +1 -1
- package/datasheets/gantt-paint.js +1 -1
- package/datasheets/manager.js +1 -1
- package/datasheets/path-binding.js +2 -2
- package/datasheets/rules.js +1 -1
- package/datasheets/view.js +2 -2
- package/i18n/dom.js +1 -1
- package/i18n/en/cells.js +1 -1
- package/i18n/en/format.js +1 -1
- package/i18n/en/misc.js +1 -1
- package/i18n/en/shell.js +2 -2
- package/i18n/pl/cells.js +1 -1
- package/i18n/pl/format.js +1 -1
- package/i18n/pl/misc.js +1 -1
- package/i18n/pl/shell.js +2 -2
- package/io/client.js +1 -1
- package/io/csv.js +8 -8
- package/io/plan.js +1 -1
- package/io/text-split.js +3 -3
- package/io/xlsx-read.js +1 -1
- package/io/xlsx-write.js +1 -1
- package/io/xml-scan.js +2 -1
- package/io/zip-reader.js +1 -1
- package/objects/chart-model.js +1 -1
- package/package.json +1 -1
- package/pivot/engine.js +1 -1
- package/pivot/xml.js +2 -2
- package/print/paginate.js +1 -1
- package/print/render-page.js +3 -3
- package/slicers/format.js +2 -2
- package/slicers/structured.js +1 -1
- package/table-view/api.js +1 -1
- package/table-view/cell-editor.js +2 -1
- package/table-view/chart.js +1 -0
- package/table-view/column-drag.js +1 -1
- package/table-view/context-menu.js +1 -0
- package/table-view/editors.js +1 -0
- package/table-view/events.js +1 -1
- package/table-view/files.js +1 -1
- package/table-view/fill-handle.js +1 -0
- package/table-view/filter-builder.js +1 -0
- package/table-view/find.js +1 -0
- package/table-view/grid-keys.js +2 -2
- package/table-view/labels-de.js +1 -0
- package/table-view/labels-es.js +1 -0
- package/table-view/labels-fr.js +1 -0
- package/table-view/labels-ja.js +1 -0
- package/table-view/labels.js +1 -1
- package/table-view/model.js +1 -1
- package/table-view/mount.js +1 -1
- package/table-view/panel.js +1 -1
- package/table-view/pivot-spec.js +1 -0
- package/table-view/pivot.js +1 -1
- package/table-view/public.d.ts +277 -28
- package/table-view/reader.worker.js +1 -1
- package/table-view/remote.js +1 -1
- package/table-view/row-drag.js +1 -0
- package/table-view/sparkline.js +1 -0
- package/table-view/state-check.js +1 -0
- package/table-view/table-css.js +380 -0
- package/table-view/version.js +1 -1
- package/ui/dialogs.js +3 -3
- package/ui/menu-base.js +1 -1
- package/ui/protection-ui.js +1 -1
package/calc/parser.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{colIndex as
|
|
2
|
-
`||
|
|
3
|
-
`||s[e]==="\r"||s[e]===" ");)e++;o("ws",null,l,e);continue}if(i==='"'){const l=e;let a="";for(e++;;){if(e>=n)throw new f("Unterminated string");if(s[e]==='"'){if(s[e+1]==='"'){a+='"',e+=2;continue}e++;break}a+=s[e++]}o("str",a,l,e);continue}if(i==="'"||i==="["){const l=v(s,e);if(l){o("sheet",l.value,e,l.end),e=l.end;continue}if(i==="["){const a=R(s,e);o("table",{name:null,spec:s.slice(e,a)},e,a),e=a;continue}throw new f("Unexpected quote")}if(i==="#"){const l=p(K,s,e);l?(o("err",w.get(l[0].toUpperCase()),e,e+l[0].length),e+=l[0].length):(o("op","#",e,e+1),e++);continue}if(i>="0"&&i<="9"||i==="."||i==="$"||/[A-Za-z_\\\u0080-]/.test(i)){let l=p(Y,s,e);if(l&&!N(s[e+l[0].length])){o("rows",{a0:l[1]==="$",r0:Number(l[2])-1,a1:l[3]==="$",r1:Number(l[4])-1},e,e+l[0].length),e+=l[0].length;continue}if(l=p(X,s,e),l&&!N(s[e+l[0].length])&&s[e+l[0].length]!=="("&&s[e+l[0].length]!=="!"){const a=O(l[2]),r=O(l[4]);if(a<S&&r<S){o("cols",{a0:l[1]==="$",c0:a,a1:l[3]==="$",c1:r},e,e+l[0].length),e+=l[0].length;continue}}if(l=p(W,s,e),l){const a=s[e+l[0].length];if(!N(a)&&a!=="("&&a!=="!"&&a!=="["){const r=I(l[0]);if(r){o("cell",r,e,e+l[0].length),e+=l[0].length;continue}}else if(a==="."&&i==="$"){const r=p(/[A-Za-z0-9_.\\?\u0080-]*/y,s,e+l[0].length),h=e+l[0].length+r[0].length;o(s[h]==="["?"table":"name",s[h]==="["?{name:s.slice(e,h),spec:s.slice(h,R(s,h))}:s.slice(e,h),e,s[h]==="["?R(s,h):h),e=t[t.length-1].e;continue}}if(i>="0"&&i<="9"||i==="."){if(l=p(x,s,e),!l)throw new f("Bad number");o("num",Number(l[0]),e,e+l[0].length),e+=l[0].length;continue}if(l=p(z,s,e),l){const a=e+l[0].length,r=s[a];if(r==="!"||r===":"&&Z(s,a)){const h=v(s,e);if(h){o("sheet",h.value,e,h.end),e=h.end;continue}}if(r==="(")o("func",l[0].replace(L,"").toUpperCase(),e,a);else if(r==="["){const h=R(s,a);o("table",{name:l[0],spec:s.slice(a,h)},e,h),e=h;continue}else o("name",l[0].replace(L,""),e,a);e=a;continue}}const c=s.slice(e,e+2);if(c==="<="||c===">="||c==="<>"){o("op",c,e,e+2),e+=2;continue}if("+-*/^&=<>%(),;:{}@".includes(i)){o("op",i,e,e+1),e++;continue}throw new f(`Unexpected character ${i}`)}return t}function Z(s,t){return/^:'?[^'!:]+'?!/.exec(s.slice(t,t+64))!==null}function R(s,t){let e=0;for(let n=t;n<s.length;n++){if(s[n]==="'"&&s[n+1]!==void 0){n++;continue}if(s[n]==="[")e++;else if(s[n]==="]"&&(e--,e===0))return n+1}throw new f("Unterminated [")}function v(s,t){let e=t,n=null;const o=()=>{if(s[e]==="'"){let r="";for(e++;;){if(e>=s.length)return null;if(s[e]==="'"){if(s[e+1]==="'"){r+="'",e+=2;continue}return e++,r}r+=s[e++]}}const a=e;for(;e<s.length&&!'!:,()+-*/^&=<>%{}; "'.includes(s[e]);)e++;return e>a?s.slice(a,e):null};if(s[e]==="["){const a=s.indexOf("]",e);if(a<0)return null;n=s.slice(e+1,a),e=a+1}let i=o();if(i===null)return null;const c=/\[([^\]]+)\](.*)$/.exec(i);c&&(n=c[1],i=c[2]);let l=null;return s[e]===":"&&(e++,l=o(),l===null)||s[e]!=="!"?null:(e++,{value:{book:n,sheet:i,sheet2:l},end:e})}function I(s){let t=0;const e=s[t]==="$";e&&t++;const n=t;for(;/[A-Za-z]/.test(s[t]);)t++;const o=O(s.slice(n,t)),i=s[t]==="$";i&&t++;const c=Number(s.slice(t))-1;return o>=S||c>=V?null:{r:c,c:o,rAbs:i,cAbs:e}}const Q=new Set(["=","<>","<",">","<=",">="]),E=s=>s===0,D=new Map(Object.entries({PHONETIC:E,ROW:E,COLUMN:E,AREAS:E,COUNTBLANK:E,COUNTIF:E,SUMIF:s=>s===0||s===2,AVERAGEIF:s=>s===0||s===2,COUNTIFS:s=>s%2===0,SUMIFS:s=>s===0||s%2===1,AVERAGEIFS:s=>s===0||s%2===1,MAXIFS:s=>s===0||s%2===1,MINIFS:s=>s===0||s%2===1,SUBTOTAL:s=>s>=1,RANK:s=>s===1,"RANK.EQ":s=>s===1,"RANK.AVG":s=>s===1,AGGREGATE:(s,t)=>t>=5&&s>=4}));for(const s of["DAVERAGE","DCOUNT","DCOUNTA","DGET","DMAX","DMIN","DPRODUCT","DSTDEV","DSTDEVP","DSUM","DVAR","DVARP"])D.set(s,E);const F=s=>s.t==="lit"||s.t==="array"||s.t==="neg"||s.t==="pct"||s.t==="bin"||s.t==="paren"&&F(s.e);let M=null,_=-1;const J=s=>(_!==T.size&&(M=new Set(y.filter(t=>t!=="Barcode"&&t!=="Sparkline").flatMap(t=>H(t))),_=T.size),M.has(s));function j(s,t){const e=J(s)?T.get(s):null,n=t.length,o=n===1&&t[0].t==="omit";if(e&&!o&&(n<e.min||n>e.max))throw new f(`${s} has the wrong number of arguments`);const i=D.get(s);if(i&&t.forEach((c,l)=>{if(i(l,n)&&F(c))throw new f(`${s} needs a reference`)}),s==="IFS"&&n%2===1)throw new f("IFS needs pairs of tests and values");if(s==="SORTBY"&&n>2&&n%2===0)throw new f("SORTBY needs a sort order after each array but the last");if(s==="LAMBDA"&&t.slice(0,-1).some(c=>c.t!=="name"||c.sheet))throw new f("LAMBDA parameters must be names")}class pe{constructor(t,e=0,n=0){this.toks=t,this.i=0,this.baseRow=e,this.baseCol=n}peek(){return this.toks[this.i]}skipWs(){for(;this.toks[this.i]?.t==="ws";)this.i++}isOp(t){this.skipWs();const e=this.toks[this.i];return e!==void 0&&e.t==="op"&&e.v===t}eat(t){if(!this.isOp(t))throw new f(`Expected ${t}`);this.i++}parse(){const t=this.expr();if(this.skipWs(),this.i<this.toks.length)throw new f("Unexpected text after the formula");return t}expr(){return this.compare()}compare(){let t=this.concat();for(;;){this.skipWs();const e=this.peek();if(e?.t==="op"&&Q.has(e.v))this.i++,t={t:"bin",op:e.v,l:t,r:this.concat()};else return t}}concat(){let t=this.add();for(;this.isOp("&");)this.i++,t={t:"bin",op:"&",l:t,r:this.add()};return t}add(){let t=this.mul();for(;;)if(this.isOp("+"))this.i++,t={t:"bin",op:"+",l:t,r:this.mul()};else if(this.isOp("-"))this.i++,t={t:"bin",op:"-",l:t,r:this.mul()};else return t}mul(){let t=this.pow();for(;;)if(this.isOp("*"))this.i++,t={t:"bin",op:"*",l:t,r:this.pow()};else if(this.isOp("/"))this.i++,t={t:"bin",op:"/",l:t,r:this.pow()};else return t}pow(){let t=this.unary();for(;this.isOp("^");)this.i++,t={t:"bin",op:"^",l:t,r:this.unary()};return t}unary(){return this.isOp("-")?(this.i++,{t:"neg",e:this.unary()}):this.isOp("+")?(this.i++,this.unary()):this.isOp("@")?(this.i++,{t:"implicit",e:this.unary()}):this.postfix()}postfix(){let t=this.refExpr();for(;;)if(this.isOp("%"))this.i++,t={t:"pct",e:t};else if(this.peek()?.t==="op"&&this.peek().v==="#")this.i++,t={t:"spillRef",e:t};else return t}refExpr(){let t=this.rangeExpr();for(;;){const e=this.i;if(this.peek()?.t==="ws"){this.skipWs();const n=this.peek();if(n&&this.startsPrimary(n)){t={t:"intersect",l:t,r:this.rangeExpr()};continue}this.i=e}return t}}startsPrimary(t){return t.t==="op"?t.v==="(":t.t==="cell"||t.t==="cols"||t.t==="rows"||t.t==="name"||t.t==="func"||t.t==="sheet"||t.t==="table"}rangeExpr(){let t=this.trimmed(this.primary());for(;this.peek()?.t==="op"&&this.peek().v===":";){const e=this.toks[this.i++],n=this.primary();t=k(t,n),e.trim&&(t=m(t,e.trim)),t=this.trimmed(t)}return t}trimmed(t){const e=this.pendingTrim;return this.pendingTrim=null,e?m(t,e):t}cellNode(t,e=null){return{t:"cell",sheet:e,rAbs:t.rAbs,cAbs:t.cAbs,r:t.rAbs?t.r:t.r-this.baseRow,c:t.cAbs?t.c:t.c-this.baseCol}}rowsNode(t,e=null){return{t:"rows",sheet:e,a0:t.a0,a1:t.a1,r0:t.a0?t.r0:t.r0-this.baseRow,r1:t.a1?t.r1:t.r1-this.baseRow}}colsNode(t,e=null){return{t:"cols",sheet:e,a0:t.a0,a1:t.a1,c0:t.a0?t.c0:t.c0-this.baseCol,c1:t.a1?t.c1:t.c1-this.baseCol}}primary(){this.skipWs();const t=this.peek();if(t===void 0)throw new f("Unexpected end of formula");switch(this.i++,t.t){case"num":return{t:"lit",v:t.v};case"str":return{t:"lit",v:t.v};case"err":{const e=this.peek();if(t.v===w.get("#REF!")&&e&&e.s===t.e&&(e.t==="cell"||e.t==="rows"||e.t==="cols"||e.t==="name")){this.i++;const n=this.peek(),o=this.toks[this.i+1];n?.t==="op"&&n.v===":"&&n.s===e.e&&o&&o.s===n.e&&(o.t==="cell"||o.t==="name")&&(this.i+=2)}return{t:"lit",v:t.v}}case"cell":return this.cellNode(t.v);case"rows":return this.pendingTrim=t.trim??null,this.rowsNode(t.v);case"cols":return this.pendingTrim=t.trim??null,this.colsNode(t.v);case"table":return{t:"table",name:t.v.name,spec:t.v.spec};case"sheet":{const e=this.peek();if(e===void 0)throw new f("Expected a reference");if(this.i++,e.t==="cell"){let n=this.cellNode(e.v,t.v);if(this.peek()?.t==="op"&&this.peek().v===":"&&this.toks[this.i+1]?.t==="cell"){const o=this.toks[this.i++],i=this.toks[this.i++];n=k(n,this.cellNode(i.v,t.v)),o.trim&&(n=m(n,o.trim))}return n}if(e.t==="rows")return this.pendingTrim=e.trim??null,this.rowsNode(e.v,t.v);if(e.t==="cols")return this.pendingTrim=e.trim??null,this.colsNode(e.v,t.v);if(e.t==="name")return{t:"name",name:e.v,sheet:t.v};if(e.t==="err")return{t:"lit",v:e.v};if(e.t==="func")return this.i--,this.primary();throw new f("Expected a reference after the sheet name")}case"name":{const e=t.v.toUpperCase();if(e==="TRUE")return{t:"lit",v:!0};if(e==="FALSE")return{t:"lit",v:!1};const n=/^\$?([A-Za-z]{1,3})\$?([1-9][0-9]{0,6})\.(.+)$/.exec(t.v),o=n?I(`$${n[1]}$${n[2]}`):null;return o?{t:"call",name:"_FV",args:[this.cellNode(o),...n[3].split(".").map(i=>({t:"lit",v:i}))]}:{t:"name",name:t.v}}case"func":return this.call(t.v);case"op":if(t.v==="("){const e=this.expr(),n=[e];for(;this.isOp(",");)this.i++,n.push(this.expr());return this.eat(")"),n.length===1?{t:"paren",e}:{t:"union",items:n}}if(t.v==="{")return this.arrayLiteral();throw new f(`Unexpected ${t.v}`);default:throw new f("Unexpected token")}}call(t){let e=this._callArgs(t);if((t==="_FV"||t==="FIELDVALUE")&&e.t==="call"&&e.args.length===2){const n=e.args[0];n?.t==="call"&&(n.name==="_FV"||n.name==="FIELDVALUE")&&n.args.length>=2&&(e={t:"call",name:"_FV",args:[...n.args,e.args[1]]})}if(t==="CALL"||t==="REGISTER.ID")throw new f(`${t} can't be used in a worksheet formula`);return e.t==="call"&&j(t,e.args),e}_callArgs(t){this.eat("(");const e=[];if(this.isOp(")")){this.i++;const n={t:"call",name:t,args:e};return this.afterCall(n)}for(;;){if(this.skipWs(),this.isOp(",")||this.isOp(")")?e.push({t:"omit"}):e.push(this.expr()),this.isOp(",")){this.i++;continue}this.eat(")");break}return this.afterCall({t:"call",name:t,args:e})}afterCall(t){let e=t;for(;this.peek()?.t==="op"&&this.peek().v==="(";){this.i++;const n=[];if(this.isOp(")"))this.i++;else for(;;){if(this.skipWs(),this.isOp(",")||this.isOp(")")?n.push({t:"omit"}):n.push(this.expr()),this.isOp(",")){this.i++;continue}this.eat(")");break}e={t:"apply",fn:e,args:n}}return e}arrayLiteral(){const t=[[]];for(;;){this.skipWs();let e=!1;for(;this.isOp("-")||this.isOp("+");)this.peek().v==="-"&&(e=!e),this.i++;this.skipWs();const n=this.peek();if(n===void 0)throw new f("Unterminated array");if(this.i++,n.t==="num")t[t.length-1].push(e?-n.v:n.v);else if(n.t==="str"||n.t==="err")t[t.length-1].push(n.v);else if(n.t==="name"&&/^(true|false)$/i.test(n.v))t[t.length-1].push(n.v.toUpperCase()==="TRUE");else throw new f("Arrays can hold only constants");if(this.isOp(","))this.i++;else if(this.isOp(";"))this.i++,t.push([]);else{this.eat("}");break}}return{t:"array",rows:t}}}function k(s,t){return s.t==="cell"&&t.t==="cell"?{t:"range",sheet:s.sheet??t.sheet,a:s,b:t}:{t:"rangeOp",l:s,r:t}}function Ee(s,t,e){let n="";for(let o=0;o<s.length;o++){const i=s[o];switch(i.t){case"cell":{const c=i.v;n+=`R${c.rAbs?c.r:`[${c.r-t}]`}C${c.cAbs?c.c:`[${c.c-e}]`}`;break}case"rows":{const c=i.v;n+=`R${c.a0?c.r0:`[${c.r0-t}]`}:R${c.a1?c.r1:`[${c.r1-t}]`}`;break}case"cols":{const c=i.v;n+=`C${c.a0?c.c0:`[${c.c0-e}]`}:C${c.a1?c.c1:`[${c.c1-e}]`}`;break}case"num":case"func":n+=`${i.t==="num"?"":"~"}${i.v}`;break;case"op":n+=i.v;break;case"ws":n+=" ";break;case"str":n+=JSON.stringify(i.v);break;case"name":n+=`${i.v}`;break;case"err":n+=i.v.code;break;default:n+=`${JSON.stringify(i.v)}`}}return n}const q=new Set(["FILTER","SORT","PY"]),ee=new Set("_TRO_ALL _TRO_LEADING _TRO_TRAILING DETECTLANGUAGE ENCODEURL STOCKHISTORY TRANSLATE ACOT ACOTH AGGREGATE ARABIC ARRAYTOTEXT ANCHORARRAY BASE BETA.DIST BETA.INV BINOM.DIST BINOM.DIST.RANGE BINOM.INV BITAND BITLSHIFT BITOR BITRSHIFT BITXOR BYCOL BYROW CEILING.MATH CEILING.PRECISE CHISQ.DIST CHISQ.DIST.RT CHISQ.INV CHISQ.INV.RT CHISQ.TEST CHOOSECOLS CHOOSEROWS COMBINA CONCAT CONFIDENCE.NORM CONFIDENCE.T COT COTH COVARIANCE.P COVARIANCE.S CSC CSCH DAYS DECIMAL DROP ECMA.CEILING ERF.PRECISE ERFC.PRECISE EXPAND EXPON.DIST F.DIST F.DIST.RT F.INV F.INV.RT F.TEST FIELDVALUE FILTERXML FLOOR.MATH FLOOR.PRECISE FORECAST.ETS FORECAST.ETS.CONFINT FORECAST.ETS.SEASONALITY FORECAST.ETS.STAT FORECAST.LINEAR FORMULATEXT GAMMA GAMMA.DIST GAMMA.INV GAMMALN.PRECISE GAUSS GROUPBY HSTACK HYPGEOM.DIST IFNA IFS IMAGE IMCOSH IMCOT IMCSC IMCSCH IMSEC IMSECH IMSINH IMTAN ISFORMULA ISO.CEILING ISOMITTED ISOWEEKNUM LAMBDA LET LOGNORM.DIST LOGNORM.INV MAKEARRAY MAP MAXIFS MINIFS MODE.MULT MODE.SNGL MUNIT NEGBINOM.DIST NETWORKDAYS.INTL NORM.DIST NORM.INV NORM.S.DIST NORM.S.INV NUMBERVALUE PDURATION PERCENTILE.EXC PERCENTILE.INC PERCENTOF PERCENTRANK.EXC PERCENTRANK.INC PERMUTATIONA PHI PIVOTBY POISSON.DIST QUARTILE.EXC QUARTILE.INC QUERYSTRING RANDARRAY RANK.AVG RANK.EQ REDUCE REGEXEXTRACT REGEXREPLACE REGEXTEST RRI SCAN SEC SECH SEQUENCE SHEET SHEETS SINGLE SKEW.P SORTBY STDEV.P STDEV.S SWITCH T.DIST T.DIST.2T T.DIST.RT T.INV T.INV.2T T.TEST TAKE TEXTAFTER TEXTBEFORE TEXTJOIN TEXTSPLIT TOCOL TOROW TRIMRANGE UNICHAR UNICODE UNIQUE VALUETOTEXT VAR.P VAR.S VSTACK WEBSERVICE WEIBULL.DIST WORKDAY.INTL WRAPCOLS WRAPROWS XLOOKUP XMATCH XOR Z.TEST".split(" ")),te=new Set(["BYCOL","BYROW","GROUPBY","MAKEARRAY","MAP","PIVOTBY","REDUCE","SCAN"]);function Ae(s,t){if(s.indexOf("[")<0)return s;let e;try{e=$(s)}catch{return s}let n="",o=0;for(const i of e){if(i.t!=="table")continue;const c=i.v.name??t()?.name;if(!c)continue;const l=i.v.spec.slice(1,-1).trim();let a=i.v.spec;if(l[0]==="@"){const r=l.slice(1).trim().replace(/^\[|\]$/g,"");a=r?`[[#This Row],[${r}]]`:"[#This Row]"}n+=`${s.slice(o,i.s)}${c}${a}`,o=i.e}return n+s.slice(o)}function se(s){if(s.t==="name"){const t=/^(\$?[A-Za-z]{1,3}\$?[1-9][0-9]{0,6})\.(.+)$/.exec(s.v);return!t||!I(t[1])||t[2].split(".").some(e=>e==="")?null:{cell:t[1],fields:t[2].split(".")}}if(s.t==="table"&&s.v.name){const t=/^(\$?[A-Za-z]{1,3}\$?[1-9][0-9]{0,6})\.((?:[A-Za-z_][\w]*\.)*)$/.exec(s.v.name),e=/^\[([^[\]]+)\]$/.exec(s.v.spec);return!t||!e||!I(t[1])?null:{cell:t[1],fields:[...t[2].split(".").filter(Boolean),e[1]]}}return null}const ne=String.raw`(?:(?:'(?:[^']|'')*'|${B})!)?\$?[A-Za-z]{1,3}\$?[0-9]+(?:\.(?:[A-Za-z_]\w*|\[[^\]]*\]))*`,ie=new RegExp(String.raw`_FV\((${ne}),"((?:[^"]|"")*)"\)`,"g");function re(s){let t=s;for(let e=0;e<8&&t.indexOf("_FV(")>=0;e++){const n=t.replace(ie,(o,i,c)=>{const l=c.replace(/""/g,'"');return/^[A-Za-z_]\w*$/.test(l)?`${i}.${l}`:/[[\]]/.test(l)?o:`${i}.[${l}]`});if(n===t)break;t=n}return t}function Te(s){let t=s.indexOf("#This Row")<0?s:s.replace(/\[\[#This Row\],\[([^\]]+)\]\]/g,(e,n)=>/^[\w.]+$/.test(n)?`[@${n}]`:`[@[${n}]]`);return t.indexOf("_FV(")>=0&&(t=re(t)),t.indexOf("_xl")<0?t:(t.indexOf("_TRO_")>=0&&(t=ae(t)),t.replace(/_xlfn\.SINGLE\(([^()]*)\)/g,"@$1").replace(/_xlfn\.ANCHORARRAY\(([^()]*)\)/g,"$1#").replace(/_xlfn\._xlws\.|_xlfn\.|_xlws\.|_xlpm\.|_xludf\.|_xleta\./g,""))}function Re(s,t=null){if(!/[A-Za-z]/.test(s))return s;s=ce(s);let e;try{e=$(s)}catch{return s}const n=le(e);let o="",i=0;const c=[],l=[];for(let a=0;a<e.length;a++){const r=e[a];r.t==="op"&&r.v==="("?c.push(l.pop()===!0):r.t==="op"&&r.v===")"&&c.pop(),r.t==="func"&&l.push(te.has(r.v)||c.includes(!0));const h=se(r);if(h!==null){const u=e[a-1]?.t==="sheet"&&e[a-1].s>=i?e[a-1].s:r.s,A=s.slice(u,r.s)+h.cell;o+=s.slice(i,u)+h.fields.reduce((G,P)=>`_FV(${G},"${P.replace(/"/g,'""')}")`,A),i=r.e}else if(r.t==="name"&&c.includes(!0)&&!n.has(r.v.toUpperCase())&&g(r.v.toUpperCase()))o+=`${s.slice(i,r.s)}_xleta.${r.v.toUpperCase()}`,i=r.e;else if(r.t==="func")o+=s.slice(i,r.s),n.has(r.v)?o+=`_xlpm.${s.slice(r.s,r.e)}`:q.has(r.v)?o+=`_xlfn._xlws.${r.v}`:ee.has(r.v)?o+=`_xlfn.${r.v}`:o+=!g(r.v)&&t?.get(r.v)?.name?t.get(r.v).name:r.v,i=r.e;else if(r.t==="name"&&n.has(r.v.toUpperCase()))o+=`${s.slice(i,r.s)}_xlpm.${r.v}`,i=r.e;else if(r.t==="op"&&r.v==="@"){const u=e[a+1];u&&(u.t==="cell"||u.t==="name")&&(o+=`${s.slice(i,r.s)}_xlfn.SINGLE(${s.slice(u.s,u.e)})`,i=u.e,a++)}else r.t==="cell"&&e[a+1]?.t==="op"&&e[a+1].v==="#"&&(o+=`${s.slice(i,r.s)}_xlfn.ANCHORARRAY(${s.slice(r.s,r.e)})`,i=e[a+1].e,a++)}return o+s.slice(i)}function le(s){const t=new Set;for(let e=0;e<s.length;e++){const n=s[e];if(n.t!=="func"||n.v!=="LET"&&n.v!=="LAMBDA")continue;let o=0,i=0,c=!0;const l=[];for(let r=e+1;r<s.length;r++){const h=s[r];if(h.t!=="ws"){if(h.t==="op"&&(h.v==="("||h.v==="{")){if(o++,o===1){c=!0;continue}}else if(h.t==="op"&&(h.v===")"||h.v==="}")){if(o--,o===0)break}else if(h.t==="op"&&h.v===","&&o===1){i++,c=!0;continue}c&&o>=1&&(l.push({argIndex:i,token:h,next:s[r+1]}),c=!1)}}const a=i+1;for(const r of l){if(r.token.t!=="name"||!(r.next===void 0||r.next.t==="ws"||r.next.t==="op"&&(r.next.v===","||r.next.v===")")))continue;(n.v==="LET"?r.argIndex%2===0&&r.argIndex<a-1:r.argIndex<a-1)&&t.add(r.token.v.toUpperCase())}}return t}const oe=String.raw`(?:'(?:[^']|'')+'|[A-Za-z_À-][\w.À-]*)!`,U=String.raw`\$?[A-Za-z]{1,3}\$?\d{1,7}|\$?[A-Za-z]{1,3}|\$?\d{1,7}`,b=new RegExp(String.raw`(?<![\w.$!'])((?:${oe})?(?:${U}))(\.?):(\.?)(${U})(?![\w(!])`,"g");function C(s,t){let e="",n=0;const o=/"(?:[^"]|"")*"/g;for(let i=o.exec(s);i!==null;i=o.exec(s))e+=t(s.slice(n,i.index),n)+i[0],n=i.index+i[0].length;return e+t(s.slice(n),n)}const m=(s,t)=>({t:"call",name:`_TRO_${t}`,args:[s]});function ce(s){return s.indexOf(".:")<0&&s.indexOf(":.")<0?s:C(s,t=>t.replace(b,(e,n,o,i,c)=>!o&&!i?e:`_xlfn._TRO_${o&&i?"ALL":o?"LEADING":"TRAILING"}(${n}:${c})`))}function ae(s){return C(s,t=>t.replace(/(?:_xlfn\.)?_TRO_(ALL|LEADING|TRAILING)\(((?:'(?:[^']|'')*'|[^()'])*)\)/g,(e,n,o)=>{const i=o.lastIndexOf(":");if(i<0)return e;const c=n!=="TRAILING"?".":"",l=n!=="LEADING"?".":"";return`${o.slice(0,i)}${c}:${l}${o.slice(i+1)}`}))}export{f as FormulaSyntaxError,pe as Parser,Ae as expandStructured,Ee as templateKey,Te as toDisplayFormula,Re as toFileFormula,$ as tokenize,ce as trimRefsToFile};
|
|
1
|
+
import{colIndex as d,MAX_COLS as N,MAX_ROWS as y,PLAIN_SHEET as B}from"../core/address.js";import{ERR_BY_CODE as L}from"./values.js";import{CATEGORIES as H,categoryFunctions as W,FUNCS as I}from"./functions/registry.js";const $=t=>I.has(t);class h extends Error{}function Te(t){if(t.length>8192)return"A formula cannot contain more than 8,192 characters.";if(t.length<130||!t.includes('"')&&!t.includes("("))return null;let e;try{e=R(t)}catch(c){if(c instanceof h)return null;throw c}const n=[];let s=0;for(let c=0;c<e.length;c++){const r=e[c];if(r.t==="str"&&r.v.length>255)return"Text values in formulas are limited to 255 characters.";if(r.t==="op")if(r.v==="("){const o=e[c-1]?.t==="func";if(n.push(o),o&&++s>64)return"A formula cannot nest more than 64 levels of functions."}else r.v===")"&&n.pop()&&s--}return null}const X=/\$?[A-Za-z]{1,3}\$?[1-9][0-9]{0,6}/y,Y=/(\$?)([A-Za-z]{1,3}):(\$?)([A-Za-z]{1,3})/y,z=/(\$?)([1-9][0-9]{0,6}):(\$?)([1-9][0-9]{0,6})/y,K=/(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y,Z=/[A-Za-z_\\\u0080-][A-Za-z0-9_.\\?\u0080-]*/y,Q=/#(?:NULL!|DIV\/0!|VALUE!|REF!|NAME\?|NUM!|N\/A|GETTING_DATA|SPILL!|CALC!|BUSY!|CONNECT!|BLOCKED!|FIELD!|UNKNOWN!)/iy,v=/^(?:_xlfn\._xlws\.|_xlfn\.|_xlws\.|_xlpm\.|_xludf\.|_xleta\.)/i,C=t=>t!==void 0&&/[A-Za-z0-9_.\u0080-]/.test(t);function p(t,e,n){return t.lastIndex=n,t.exec(e)}function R(t,e=!1){if(t.indexOf(".:")<0&&t.indexOf(":.")<0)return m(t,e);const n=new Set,s=new Map;if(w(t,(a,l)=>{for(const i of a.matchAll(P)){const[,f,u,A]=i;if(!u&&!A)continue;const T=l+i.index+f.length+u.length;u&&n.add(T-1),A&&n.add(T+1),s.set(T,u&&A?"ALL":u?"LEADING":"TRAILING")}return a}),n.size===0)return m(t,e);let c="";const r=[];for(let a=0;a<t.length;a++)n.has(a)||(r.push(a),c+=t[a]);r.push(t.length);const o=m(c,e);for(const a of o){const l=r[a.s],i=a.e>0?r[a.e-1]+1:0;for(const[f,u]of s)f>=l&&f<i&&(a.trim=u);a.s=l,a.e=i}return o}function m(t,e){const n=[];let s=0;const c=t.length,r=(o,a,l,i)=>n.push({t:o,v:a,s:l,e:i});for(;s<c;){const o=t[s];if(o===" "||o===`
|
|
2
|
+
`||o==="\r"||o===" "){const l=s;for(;s<c&&(t[s]===" "||t[s]===`
|
|
3
|
+
`||t[s]==="\r"||t[s]===" ");)s++;r("ws",null,l,s);continue}if(o==='"'){const l=s;let i="";for(s++;;){if(s>=c)throw new h("Unterminated string");if(t[s]==='"'){if(t[s+1]==='"'){i+='"',s+=2;continue}s++;break}i+=t[s++]}r("str",i,l,s);continue}if(o==="'"||o==="["){const l=F(t,s);if(l){r("sheet",l.value,s,l.end),s=l.end;continue}if(o==="["){const i=O(t,s);r("table",{name:null,spec:t.slice(s,i)},s,i),s=i;continue}throw new h("Unexpected quote")}if(o==="#"){const l=p(Q,t,s);l?(r("err",L.get(l[0].toUpperCase()),s,s+l[0].length),s+=l[0].length):(r("op","#",s,s+1),s++);continue}if(o>="0"&&o<="9"||o==="."||o==="$"||/[A-Za-z_\\\u0080-]/.test(o)){let l=p(z,t,s);if(l&&!C(t[s+l[0].length])){r("rows",{a0:l[1]==="$",r0:Number(l[2])-1,a1:l[3]==="$",r1:Number(l[4])-1},s,s+l[0].length),s+=l[0].length;continue}if(l=p(Y,t,s),l&&!C(t[s+l[0].length])&&t[s+l[0].length]!=="("&&t[s+l[0].length]!=="!"){const i=d(l[2]),f=d(l[4]);if(i<N&&f<N){r("cols",{a0:l[1]==="$",c0:i,a1:l[3]==="$",c1:f},s,s+l[0].length),s+=l[0].length;continue}}if(l=p(X,t,s),l){const i=t[s+l[0].length];if(!C(i)&&i!=="("&&i!=="!"&&i!=="["){const f=S(l[0]);if(f){r("cell",f,s,s+l[0].length),s+=l[0].length;continue}}else if(i==="."&&o==="$"){const f=p(/[A-Za-z0-9_.\\?\u0080-]*/y,t,s+l[0].length),u=s+l[0].length+f[0].length;r(t[u]==="["?"table":"name",t[u]==="["?{name:t.slice(s,u),spec:t.slice(u,O(t,u))}:t.slice(s,u),s,t[u]==="["?O(t,u):u),s=n[n.length-1].e;continue}}if(o>="0"&&o<="9"||o==="."){if(l=p(K,t,s),!l)throw new h("Bad number");r("num",Number(l[0]),s,s+l[0].length),s+=l[0].length;continue}if(l=p(Z,t,s),l){const i=s+l[0].length,f=t[i];if(f==="!"||f===":"&&x(t,i)){const u=F(t,s);if(u){r("sheet",u.value,s,u.end),s=u.end;continue}}if(f==="("){const u=/^_xludf\./i.test(l[0])?l[0]:l[0].replace(v,"");r("func",u.toUpperCase(),s,i)}else if(f==="["){const u=O(t,i);r("table",{name:l[0],spec:t.slice(i,u)},s,u),s=u;continue}else r("name",l[0].replace(v,""),s,i);s=i;continue}}const a=t.slice(s,s+2);if(a==="<="||a===">="||a==="<>"){r("op",a,s,s+2),s+=2;continue}if("+-*/^&=<>%(),;:{}@".includes(o)){r("op",o,s,s+1),s++;continue}if(o==="!"&&e){s++;continue}throw new h(`Unexpected character ${o}`)}return n}function x(t,e){return/^:'?[^'!:]+'?!/.exec(t.slice(e,e+64))!==null}function O(t,e){let n=0;for(let s=e;s<t.length;s++){if(t[s]==="'"&&t[s+1]!==void 0){s++;continue}if(t[s]==="[")n++;else if(t[s]==="]"&&(n--,n===0))return s+1}throw new h("Unterminated [")}function F(t,e){let n=e,s=null;const c=()=>{if(t[n]==="'"){let f="";for(n++;;){if(n>=t.length)return null;if(t[n]==="'"){if(t[n+1]==="'"){f+="'",n+=2;continue}return n++,f}f+=t[n++]}}const i=n;for(;n<t.length&&!'!:,()+-*/^&=<>%{}; "'.includes(t[n]);)n++;return n>i?t.slice(i,n):null};if(t[n]==="["){const i=t.indexOf("]",n);if(i<0)return null;s=t.slice(n+1,i),n=i+1}const r=t[n]==="'";let o=c();if(o===null)return null;const a=/\[([^\]]+)\](.*)$/.exec(o);a&&(s=a[1],o=a[2]);let l=null;if(t[n]===":"){if(n++,r&&t[n]==="'")throw new h("Quote the whole 3-D sheet span");if(l=c(),l===null)return null}else if(r&&o.includes(":")){const i=o.indexOf(":");l=o.slice(i+1),o=o.slice(0,i)}return t[n]!=="!"?null:(n++,{value:{book:s,sheet:o,sheet2:l},end:n})}function S(t){let e=0;const n=t[e]==="$";n&&e++;const s=e;for(;/[A-Za-z]/.test(t[e]);)e++;const c=d(t.slice(s,e)),r=t[e]==="$";r&&e++;const o=Number(t.slice(e))-1;return c>=N||o>=y?null:{r:o,c,rAbs:r,cAbs:n}}const J=new Set(["=","<>","<",">","<=",">="]),E=t=>t===0,D=new Map(Object.entries({PHONETIC:E,ROW:E,COLUMN:E,AREAS:E,COUNTBLANK:E,COUNTIF:E,SUMIF:t=>t===0||t===2,AVERAGEIF:t=>t===0||t===2,COUNTIFS:t=>t%2===0,SUMIFS:t=>t===0||t%2===1,AVERAGEIFS:t=>t===0||t%2===1,MAXIFS:t=>t===0||t%2===1,MINIFS:t=>t===0||t%2===1,SUBTOTAL:t=>t>=1,RANK:t=>t===1,"RANK.EQ":t=>t===1,"RANK.AVG":t=>t===1,AGGREGATE:(t,e)=>e>=5&&t>=4}));for(const t of["DAVERAGE","DCOUNT","DCOUNTA","DGET","DMAX","DMIN","DPRODUCT","DSTDEV","DSTDEVP","DSUM","DVAR","DVARP"])D.set(t,E);const M=t=>t.t==="lit"||t.t==="array"||t.t==="neg"||t.t==="pct"||t.t==="bin"||t.t==="paren"&&M(t.e);let _=null,U=-1;const j=t=>(U!==I.size&&(_=new Set(H.filter(e=>e!=="Barcode"&&e!=="Sparkline").flatMap(e=>W(e))),U=I.size),_.has(t));function q(t,e){const n=j(t)?I.get(t):null,s=e.length,c=s===1&&e[0].t==="omit";if(n&&!c&&(s<n.min||s>n.max))throw new h(`${t} has the wrong number of arguments`);const r=D.get(t);if(r&&e.forEach((o,a)=>{if(r(a,s)&&M(o))throw new h(`${t} needs a reference`)}),t==="IFS"&&s%2===1)throw new h("IFS needs pairs of tests and values");if(t==="SORTBY"&&s>2&&s%2===0)throw new h("SORTBY needs a sort order after each array but the last");if(t==="LAMBDA"&&e.slice(0,-1).some(o=>o.t!=="name"||o.sheet))throw new h("LAMBDA parameters must be names")}class k{constructor(e,n=0,s=0){this.toks=e,this.i=0,this.baseRow=n,this.baseCol=s}peek(){return this.toks[this.i]}skipWs(){for(;this.toks[this.i]?.t==="ws";)this.i++}isOp(e){this.skipWs();const n=this.toks[this.i];return n!==void 0&&n.t==="op"&&n.v===e}eat(e){if(!this.isOp(e))throw new h(`Expected ${e}`);this.i++}parse(e=!1){const n=e?this.union():this.expr();if(this.skipWs(),this.i<this.toks.length)throw new h("Unexpected text after the formula");return n}union(e=this.expr()){if(!this.isOp(","))return e;const n=[e];do this.i++,n.push(this.expr());while(this.isOp(","));return{t:"union",items:n}}expr(){return this.compare()}compare(){let e=this.concat();for(;;){this.skipWs();const n=this.peek();if(n?.t==="op"&&J.has(n.v))this.i++,e={t:"bin",op:n.v,l:e,r:this.concat()};else return e}}concat(){let e=this.add();for(;this.isOp("&");)this.i++,e={t:"bin",op:"&",l:e,r:this.add()};return e}add(){let e=this.mul();for(;;)if(this.isOp("+"))this.i++,e={t:"bin",op:"+",l:e,r:this.mul()};else if(this.isOp("-"))this.i++,e={t:"bin",op:"-",l:e,r:this.mul()};else return e}mul(){let e=this.pow();for(;;)if(this.isOp("*"))this.i++,e={t:"bin",op:"*",l:e,r:this.pow()};else if(this.isOp("/"))this.i++,e={t:"bin",op:"/",l:e,r:this.pow()};else return e}pow(){let e=this.unary();for(;this.isOp("^");)this.i++,e={t:"bin",op:"^",l:e,r:this.unary()};return e}unary(){return this.isOp("-")?(this.i++,{t:"neg",e:this.unary()}):this.isOp("+")?(this.i++,this.unary()):this.isOp("@")?(this.i++,{t:"implicit",e:this.unary()}):this.postfix()}postfix(){let e=this.refExpr();for(;;)if(this.isOp("%"))this.i++,e={t:"pct",e};else if(this.peek()?.t==="op"&&this.peek().v==="#")this.i++,e={t:"spillRef",e};else return e}refExpr(){let e=this.rangeExpr();for(;;){const n=this.i;if(this.peek()?.t==="ws"){this.skipWs();const s=this.peek();if(s&&this.startsPrimary(s)){e={t:"intersect",l:e,r:this.rangeExpr()};continue}this.i=n}return e}}startsPrimary(e){return e.t==="op"?e.v==="(":e.t==="cell"||e.t==="cols"||e.t==="rows"||e.t==="name"||e.t==="func"||e.t==="sheet"||e.t==="table"}rangeExpr(){let e=this.trimmed(this.primary());for(;this.peek()?.t==="op"&&this.peek().v===":";){const n=this.toks[this.i++],s=this.primary();e=b(e,s),n.trim&&(e=g(e,n.trim)),e=this.trimmed(e)}return e}trimmed(e){const n=this.pendingTrim;return this.pendingTrim=null,n?g(e,n):e}cellNode(e,n=null){return{t:"cell",sheet:n,rAbs:e.rAbs,cAbs:e.cAbs,r:e.rAbs?e.r:e.r-this.baseRow,c:e.cAbs?e.c:e.c-this.baseCol}}rowsNode(e,n=null){return{t:"rows",sheet:n,a0:e.a0,a1:e.a1,r0:e.a0?e.r0:e.r0-this.baseRow,r1:e.a1?e.r1:e.r1-this.baseRow}}colsNode(e,n=null){return{t:"cols",sheet:n,a0:e.a0,a1:e.a1,c0:e.a0?e.c0:e.c0-this.baseCol,c1:e.a1?e.c1:e.c1-this.baseCol}}primary(){this.skipWs();const e=this.peek();if(e===void 0)throw new h("Unexpected end of formula");switch(this.i++,e.t){case"num":return{t:"lit",v:e.v};case"str":return{t:"lit",v:e.v};case"err":{const n=this.peek();if(e.v===L.get("#REF!")&&n&&n.s===e.e&&(n.t==="cell"||n.t==="rows"||n.t==="cols"||n.t==="name")){this.i++;const s=this.peek(),c=this.toks[this.i+1];s?.t==="op"&&s.v===":"&&s.s===n.e&&c&&c.s===s.e&&(c.t==="cell"||c.t==="name")&&(this.i+=2)}return{t:"lit",v:e.v}}case"cell":return this.cellNode(e.v);case"rows":return this.pendingTrim=e.trim??null,this.rowsNode(e.v);case"cols":return this.pendingTrim=e.trim??null,this.colsNode(e.v);case"table":return{t:"table",name:e.v.name,spec:e.v.spec};case"sheet":{const n=this.peek();if(n===void 0)throw new h("Expected a reference");if(this.i++,n.t==="cell"){let s=this.cellNode(n.v,e.v);if(this.peek()?.t==="op"&&this.peek().v===":"&&this.toks[this.i+1]?.t==="cell"){const c=this.toks[this.i++],r=this.toks[this.i++];s=b(s,this.cellNode(r.v,e.v)),c.trim&&(s=g(s,c.trim))}return s}if(n.t==="rows")return this.pendingTrim=n.trim??null,this.rowsNode(n.v,e.v);if(n.t==="cols")return this.pendingTrim=n.trim??null,this.colsNode(n.v,e.v);if(n.t==="name")return{t:"name",name:n.v,sheet:e.v};if(n.t==="err")return{t:"lit",v:n.v};if(n.t==="func")return this.i--,this.primary();throw new h("Expected a reference after the sheet name")}case"name":{const n=e.v.toUpperCase();if(n==="TRUE")return{t:"lit",v:!0};if(n==="FALSE")return{t:"lit",v:!1};const s=/^\$?([A-Za-z]{1,3})\$?([1-9][0-9]{0,6})\.(.+)$/.exec(e.v),c=s?S(`$${s[1]}$${s[2]}`):null;return c?{t:"call",name:"_FV",args:[this.cellNode(c),...s[3].split(".").map(r=>({t:"lit",v:r}))]}:{t:"name",name:e.v}}case"func":return this.call(e.v);case"op":if(e.v==="("){const n=this.expr(),s=this.union(n);return this.eat(")"),s===n?{t:"paren",e:n}:s}if(e.v==="{")return this.arrayLiteral();throw new h(`Unexpected ${e.v}`);default:throw new h("Unexpected token")}}call(e){let n=this._callArgs(e);if((e==="_FV"||e==="FIELDVALUE")&&n.t==="call"&&n.args.length===2){const s=n.args[0];s?.t==="call"&&(s.name==="_FV"||s.name==="FIELDVALUE")&&s.args.length>=2&&(n={t:"call",name:"_FV",args:[...s.args,n.args[1]]})}if(e==="CALL"||e==="REGISTER.ID")throw new h(`${e} can't be used in a worksheet formula`);return n.t==="call"&&q(e,n.args),n}_callArgs(e){this.eat("(");const n=[];if(this.isOp(")")){this.i++;const s={t:"call",name:e,args:n};return this.afterCall(s)}for(;;){if(this.skipWs(),this.isOp(",")||this.isOp(")")?n.push({t:"omit"}):n.push(this.expr()),this.isOp(",")){this.i++;continue}this.eat(")");break}return this.afterCall({t:"call",name:e,args:n})}afterCall(e){let n=e;for(;this.peek()?.t==="op"&&this.peek().v==="(";){this.i++;const s=[];if(this.isOp(")"))this.i++;else for(;;){if(this.skipWs(),this.isOp(",")||this.isOp(")")?s.push({t:"omit"}):s.push(this.expr()),this.isOp(",")){this.i++;continue}this.eat(")");break}n={t:"apply",fn:n,args:s}}return n}arrayLiteral(){const e=[[]];for(;;){this.skipWs();let n=!1;for(;this.isOp("-")||this.isOp("+");)this.peek().v==="-"&&(n=!n),this.i++;this.skipWs();const s=this.peek();if(s===void 0)throw new h("Unterminated array");if(this.i++,s.t==="num")e[e.length-1].push(n?-s.v:s.v);else if(s.t==="str"||s.t==="err")e[e.length-1].push(s.v);else if(s.t==="name"&&/^(true|false)$/i.test(s.v))e[e.length-1].push(s.v.toUpperCase()==="TRUE");else throw new h("Arrays can hold only constants");if(this.isOp(","))this.i++;else if(this.isOp(";"))this.i++,e.push([]);else{this.eat("}");break}}return{t:"array",rows:e}}}function b(t,e){return t.t==="cell"&&e.t==="cell"?{t:"range",sheet:t.sheet??e.sheet,a:t,b:e}:{t:"rangeOp",l:t,r:e}}function Re(t,e,n){let s="";for(let c=0;c<t.length;c++){const r=t[c];switch(r.t){case"cell":{const o=r.v;s+=`R${o.rAbs?o.r:`[${o.r-e}]`}C${o.cAbs?o.c:`[${o.c-n}]`}`;break}case"rows":{const o=r.v;s+=`R${o.a0?o.r0:`[${o.r0-e}]`}:R${o.a1?o.r1:`[${o.r1-e}]`}`;break}case"cols":{const o=r.v;s+=`C${o.a0?o.c0:`[${o.c0-n}]`}:C${o.a1?o.c1:`[${o.c1-n}]`}`;break}case"num":case"func":s+=`${r.t==="num"?"":"~"}${r.v}`;break;case"op":s+=r.v;break;case"ws":s+=" ";break;case"str":s+=JSON.stringify(r.v);break;case"name":s+=`${r.v}`;break;case"err":s+=r.v.code;break;default:s+=`${JSON.stringify(r.v)}`}}return s}const ee=new Set(["FILTER","SORT","PY"]),te=new Set("_TRO_ALL _TRO_LEADING _TRO_TRAILING DETECTLANGUAGE ENCODEURL STOCKHISTORY TRANSLATE ACOT ACOTH AGGREGATE ARABIC ARRAYTOTEXT ANCHORARRAY BASE BETA.DIST BETA.INV BINOM.DIST BINOM.DIST.RANGE BINOM.INV BITAND BITLSHIFT BITOR BITRSHIFT BITXOR BYCOL BYROW CEILING.MATH CEILING.PRECISE CHISQ.DIST CHISQ.DIST.RT CHISQ.INV CHISQ.INV.RT CHISQ.TEST CHOOSECOLS CHOOSEROWS COMBINA CONCAT CONFIDENCE.NORM CONFIDENCE.T COT COTH COVARIANCE.P COVARIANCE.S CSC CSCH DAYS DECIMAL DROP ECMA.CEILING ERF.PRECISE ERFC.PRECISE EXPAND EXPON.DIST F.DIST F.DIST.RT F.INV F.INV.RT F.TEST FIELDVALUE FILTERXML FLOOR.MATH FLOOR.PRECISE FORECAST.ETS FORECAST.ETS.CONFINT FORECAST.ETS.SEASONALITY FORECAST.ETS.STAT FORECAST.LINEAR FORMULATEXT GAMMA GAMMA.DIST GAMMA.INV GAMMALN.PRECISE GAUSS GROUPBY HSTACK HYPGEOM.DIST IFNA IFS IMAGE IMCOSH IMCOT IMCSC IMCSCH IMSEC IMSECH IMSINH IMTAN ISFORMULA ISO.CEILING ISOMITTED ISOWEEKNUM LAMBDA LET LOGNORM.DIST LOGNORM.INV MAKEARRAY MAP MAXIFS MINIFS MODE.MULT MODE.SNGL MUNIT NEGBINOM.DIST NETWORKDAYS.INTL NORM.DIST NORM.INV NORM.S.DIST NORM.S.INV NUMBERVALUE PDURATION PERCENTILE.EXC PERCENTILE.INC PERCENTOF PERCENTRANK.EXC PERCENTRANK.INC PERMUTATIONA PHI PIVOTBY POISSON.DIST QUARTILE.EXC QUARTILE.INC QUERYSTRING RANDARRAY RANK.AVG RANK.EQ REDUCE REGEXEXTRACT REGEXREPLACE REGEXTEST RRI SCAN SEC SECH SEQUENCE SHEET SHEETS SINGLE SKEW.P SORTBY STDEV.P STDEV.S SWITCH T.DIST T.DIST.2T T.DIST.RT T.INV T.INV.2T T.TEST TAKE TEXTAFTER TEXTBEFORE TEXTJOIN TEXTSPLIT TOCOL TOROW TRIMRANGE UNICHAR UNICODE UNIQUE VALUETOTEXT VAR.P VAR.S VSTACK WEBSERVICE WEIBULL.DIST WORKDAY.INTL WRAPCOLS WRAPROWS XLOOKUP XMATCH XOR Z.TEST".split(" ")),se=new Set(["BYCOL","BYROW","GROUPBY","MAKEARRAY","MAP","PIVOTBY","REDUCE","SCAN"]);function Ie(t,e){if(t.indexOf("[")<0)return t;let n;try{n=R(t)}catch{return t}let s="",c=0;for(const r of n){if(r.t!=="table")continue;const o=r.v.name??e()?.name;if(!o)continue;const a=r.v.spec.slice(1,-1).trim();let l=r.v.spec;if(a[0]==="@"){const i=a.slice(1).trim().replace(/^\[|\]$/g,"");l=i?`[[#This Row],[${i}]]`:"[#This Row]"}s+=`${t.slice(c,r.s)}${o}${l}`,c=r.e}return s+t.slice(c)}function ne(t){if(t.t==="name"){const e=/^(\$?[A-Za-z]{1,3}\$?[1-9][0-9]{0,6})\.(.+)$/.exec(t.v);return!e||!S(e[1])||e[2].split(".").some(n=>n==="")?null:{cell:e[1],fields:e[2].split(".")}}if(t.t==="table"&&t.v.name){const e=/^(\$?[A-Za-z]{1,3}\$?[1-9][0-9]{0,6})\.((?:[A-Za-z_][\w]*\.)*)$/.exec(t.v.name),n=/^\[([^[\]]+)\]$/.exec(t.v.spec);return!e||!n||!S(e[1])?null:{cell:e[1],fields:[...e[2].split(".").filter(Boolean),n[1]]}}return null}const ie=String.raw`(?:(?:'(?:[^']|'')*'|${B})!)?\$?[A-Za-z]{1,3}\$?[0-9]+(?:\.(?:[A-Za-z_]\w*|\[[^\]]*\]))*`,re=new RegExp(String.raw`_FV\((${ie})\s*,\s*"((?:[^"]|"")*)"(?:\s*,\s*(?:TRUE|FALSE))?\s*\)`,"g");function oe(t){let e=t;for(let n=0;n<8&&e.indexOf("_FV(")>=0;n++){const s=e.replace(re,(c,r,o)=>{const a=o.replace(/""/g,'"');return/^[A-Za-z_]\w*$/.test(a)?`${r}.${a}`:/[[\]]/.test(a)?c:`${r}.[${a}]`});if(s===e)break;e=s}return e}function le(t){let e;try{e=R(t)}catch(c){if(c instanceof h)return t;throw c}const n=[],s=[];for(let c=0;c<e.length;c++){const r=e[c];if(r.t==="op"){if(r.v==="(")n.push(c);else if(r.v===")"){const o=n.pop(),a=e[o-1];if(a?.t!=="func"||t.slice(a.s,a.e).toUpperCase()!=="_XLFN.SINGLE")continue;const l=new k(e);l.i=o+1;try{l.unary()}catch(f){if(f instanceof h)continue;throw f}const i=l.i!==c;s.push([a.s,e[o].e,i?"@(":"@"],[r.s,r.e,i?")":""])}}}for(const[c,r,o]of s.sort((a,l)=>l[0]-a[0]))t=t.slice(0,c)+o+t.slice(r);return t}function Oe(t){let e=t.indexOf("#This Row")<0?t:t.replace(/\[\[#This Row\],\[([^\]]+)\]\]/g,(n,s)=>/^[\w.]+$/.test(s)?`[@${s}]`:`[@[${s}]]`);return e.indexOf("_FV(")>=0&&(e=oe(e)),e.indexOf("_xl")<0?e:(e.indexOf("_TRO_")>=0&&(e=he(e)),e.includes("_xlfn.SINGLE(")&&(e=le(e)),e.replace(/_xlfn\.ANCHORARRAY\(([^()]*)\)/g,"$1#").replace(/_xlfn\._xlws\.|_xlfn\.|_xlws\.|_xlpm\.|_xludf\.|_xleta\./g,""))}function ce(t,e){const n=[],s=new k(e);for(let r=0;r<e.length;r++){const o=e[r];if(o.t!=="op"||o.v!=="@")continue;s.i=r+1,s.unary();let a=s.i-1;for(;e[a].t==="ws";)a--;n.push([o.s,o.e,"_xlfn.SINGLE("],[e[a].e,e[a].e,")"])}let c=t;for(const[r,o,a]of n.sort((l,i)=>i[0]-l[0]))c=c.slice(0,r)+a+c.slice(o);return c}function Se(t,e=null){if(!/[A-Za-z@]/.test(t))return t;t=ue(t);let n;try{n=R(t),n.some(l=>l.t==="op"&&l.v==="@")&&(t=ce(t,n),n=R(t))}catch(l){if(l instanceof h)return t;throw l}const s=ae(n);let c="",r=0;const o=[],a=[];for(let l=0;l<n.length;l++){const i=n[l];i.t==="op"&&i.v==="("?o.push(a.pop()===!0):i.t==="op"&&i.v===")"&&o.pop(),i.t==="func"&&a.push(se.has(i.v)||o.includes(!0));const f=ne(i);if(f!==null){const u=n[l-1]?.t==="sheet"&&n[l-1].s>=r?n[l-1].s:i.s,A=t.slice(u,i.s)+f.cell.toUpperCase();c+=t.slice(r,u)+f.fields.reduce((T,V)=>`_FV(${T},"${V.replace(/"/g,'""')}")`,A),r=i.e}else if(i.t==="name"&&o.includes(!0)&&!s.has(i.v.toUpperCase())&&$(i.v.toUpperCase()))c+=`${t.slice(r,i.s)}_xleta.${i.v.toUpperCase()}`,r=i.e;else if(i.t==="func")c+=t.slice(r,i.s),s.has(i.v)?c+=`_xlpm.${t.slice(i.s,i.e)}`:ee.has(i.v)?c+=`_xlfn._xlws.${i.v}`:te.has(i.v)?c+=`_xlfn.${i.v}`:c+=!$(i.v)&&e?.get(i.v)?.name?e.get(i.v).name:i.v,r=i.e;else if(i.t==="name"&&s.has(i.v.toUpperCase()))c+=`${t.slice(r,i.s)}_xlpm.${i.v}`,r=i.e;else if(i.t==="cell"&&n[l+1]?.t==="op"&&n[l+1].v==="#"){const u=n[l-1]?.t==="sheet"?n[l-1].s:i.s;c+=`${t.slice(r,u)}_xlfn.ANCHORARRAY(${t.slice(u,i.s)}${t.slice(i.s,i.e).toUpperCase()})`,r=n[l+1].e,l++}else(i.t==="cell"||i.t==="cols")&&(c+=t.slice(r,i.s)+t.slice(i.s,i.e).toUpperCase(),r=i.e)}return c+t.slice(r)}function ae(t){const e=new Set;for(let n=0;n<t.length;n++){const s=t[n];if(s.t!=="func"||s.v!=="LET"&&s.v!=="LAMBDA")continue;let c=0,r=0,o=!0;const a=[];for(let i=n+1;i<t.length;i++){const f=t[i];if(f.t!=="ws"){if(f.t==="op"&&(f.v==="("||f.v==="{")){if(c++,c===1){o=!0;continue}}else if(f.t==="op"&&(f.v===")"||f.v==="}")){if(c--,c===0)break}else if(f.t==="op"&&f.v===","&&c===1){r++,o=!0;continue}o&&c>=1&&(a.push({argIndex:r,token:f,next:t[i+1]}),o=!1)}}const l=r+1;for(const i of a){if(i.token.t!=="name"||!(i.next===void 0||i.next.t==="ws"||i.next.t==="op"&&(i.next.v===","||i.next.v===")")))continue;(s.v==="LET"?i.argIndex%2===0&&i.argIndex<l-1:i.argIndex<l-1)&&e.add(i.token.v.toUpperCase())}}return e}const fe=String.raw`(?:'(?:[^']|'')+'|[A-Za-z_À-][\w.À-]*)!`,G=String.raw`\$?[A-Za-z]{1,3}\$?\d{1,7}|\$?[A-Za-z]{1,3}|\$?\d{1,7}`,P=new RegExp(String.raw`(?<![\w.$!'])((?:${fe})?(?:${G}))(\.?):(\.?)(${G})(?![\w(!])`,"g");function w(t,e){let n="",s=0;const c=/"(?:[^"]|"")*"/g;for(let r=c.exec(t);r!==null;r=c.exec(t))n+=e(t.slice(s,r.index),s)+r[0],s=r.index+r[0].length;return n+e(t.slice(s),s)}const g=(t,e)=>({t:"call",name:`_TRO_${e}`,args:[t]});function ue(t){return t.indexOf(".:")<0&&t.indexOf(":.")<0?t:w(t,e=>e.replace(P,(n,s,c,r,o)=>!c&&!r?n:`_xlfn._TRO_${c&&r?"ALL":c?"LEADING":"TRAILING"}(${s}:${o})`))}function he(t){return w(t,e=>e.replace(/(?:_xlfn\.)?_TRO_(ALL|LEADING|TRAILING)\(((?:'(?:[^']|'')*'|[^()'])*)\)/g,(n,s,c)=>{const r=c.lastIndexOf(":");if(r<0)return n;const o=s!=="TRAILING"?".":"",a=s!=="LEADING"?".":"";return`${c.slice(0,r)}${o}:${a}${c.slice(r+1)}`}))}export{h as FormulaSyntaxError,k as Parser,Ie as expandStructured,Te as formulaEntryLimit,Re as templateKey,Oe as toDisplayFormula,Se as toFileFormula,R as tokenize,ue as trimRefsToFile};
|
package/calc/values.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{NUM as g}from"../core/sheet.js";import{parseInput as N}from"../core/input.js";class s{constructor(e,n){this.code=e,this.index=n}toString(){return this.code}}const
|
|
1
|
+
import{NUM as g}from"../core/sheet.js";import{parseInput as N}from"../core/input.js";class s{constructor(e,n){this.code=e,this.index=n}toString(){return this.code}}const u={NULL:new s("#NULL!",0),DIV0:new s("#DIV/0!",1),VALUE:new s("#VALUE!",2),REF:new s("#REF!",3),NAME:new s("#NAME?",4),NUM:new s("#NUM!",5),NA:new s("#N/A",6),GETTING:new s("#GETTING_DATA",7),SPILL:new s("#SPILL!",8),CALC:new s("#CALC!",9),BUSY:new s("#BUSY!",10),CONNECT:new s("#CONNECT!",11),BLOCKED:new s("#BLOCKED!",12),FIELD:new s("#FIELD!",13),UNKNOWN:new s("#UNKNOWN!",14)},L=Object.values(u),I=new Map(L.map(t=>[t.code,t]));class ${constructor(e,n,i,r,o){this.sheet=e,this.r0=n,this.c0=i,this.r1=r,this.c1=o}get rows(){return this.r1-this.r0+1}get cols(){return this.c1-this.c0+1}get isCell(){return this.r0===this.r1&&this.c0===this.c1}}class S{constructor(e){this.refs=e}}class f{constructor(e,n,i,r=e,o=n){this.rows=e,this.cols=n,this.data=i,this.spillRows=r,this.spillCols=o}get(e,n){return this.data[e*this.cols+n]}static of2D(e){const n=e.reduce((r,o)=>Math.max(r,o.length),0),i=[];for(const r of e)for(let o=0;o<n;o++)i.push(o<r.length?r[o]:u.NA);return new f(e.length,n,i)}static column(e){return new f(e.length,1,e)}static row(e){return new f(1,e.length,e)}static filled(e,n,i){return new f(e,n,new Array(e*n).fill(i))}}class b extends f{}class D{constructor(e,n,i,r){this.params=e,this.body=n,this.frame=i,this.optional=r}}class l{constructor(e,n){this.rich=e,this.index=n}get text(){return this.rich.view(this.index)?.text??""}equals(e){return e instanceof l&&e.rich===this.rich&&(e.index===this.index||this.rich.sameValue(this.index,e.index))}toString(){return this.text}toJSON(){return this.text}}const a=Symbol("omitted");function M(t){if(Number.isInteger(t)&&Math.abs(t)<1e15)return String(t);if(!Number.isFinite(t))return u.NUM.code;const e=t<0,n=Math.abs(t).toExponential(14),i=n.indexOf("e"),r=(n[0]+n.slice(2,i)).replace(/0+$/,"")||"0",o=Number(n.slice(i+1));let c;if(o>=0){const h=r.length>o+1?r.slice(0,o+1):r.padEnd(o+1,"0"),p=r.length>o+1?r.slice(o+1):"";c=p?`${h}.${p}`:h}else c=`0.${"0".repeat(-o-1)}${r}`;if(c.length>20){const h=Math.abs(o);c=`${r.length>1?`${r[0]}.${r.slice(1)}`:r}E${o<0?"-":"+"}${h<10?"0":""}${h}`}return e?`-${c}`:c}function U(t,e=0){if(/^\s*[\t\r\n]|[\t\r\n]\s*$/.test(t))return null;const n=t.trim();if(n==="")return null;const i=N(n,void 0,e);return i.kind===g?i.value:null}function V(t,e){if(t<0&&!Number.isInteger(e)){const n=1/e,i=Math.round(n);if(Math.abs(n-i)<1e-9&&Math.abs(i)%2===1)return-((-t)**e)}return t**e}const F=Object.freeze({rejected:!0});function d(t){if(typeof t=="number")return t;if(t==null||t===a)return 0;if(typeof t=="boolean")return t?1:0;if(typeof t=="string"){const e=U(t);if(e===null)throw u.VALUE;return e}if(t instanceof s)throw t;if(t instanceof f)return d(t.data[0]);throw u.VALUE}function y(t){if(typeof t=="string")return t;if(typeof t=="number")return M(t);if(t==null||t===a)return"";if(typeof t=="boolean")return t?"TRUE":"FALSE";if(t instanceof s)throw t;if(t instanceof f)return y(t.data[0]);throw u.VALUE}function C(t){if(typeof t=="boolean")return t;if(typeof t=="number")return t!==0;if(t==null||t===a)return!1;if(typeof t=="string"){const e=t.trim().toUpperCase();if(e==="TRUE")return!0;if(e==="FALSE")return!1;throw u.VALUE}if(t instanceof s)throw t;if(t instanceof f)return C(t.data[0]);throw u.VALUE}const B=t=>Math.trunc(d(t)),Y=t=>t===a||t===void 0,k=(t,e)=>t===a||t===void 0?e:t;function G(t){if(!Number.isFinite(t))throw u.NUM;return t}const x=t=>typeof t=="number"?0:typeof t=="string"?1:typeof t=="boolean"?2:3,A=new Intl.Collator("en",{sensitivity:"accent",numeric:!1}),m=' !"#$%&()*,./:;?@[\\]^_`{|}~+<=>';function T(t,e,n){const i=Math.min(t.length,e.length);for(let r=0;r<i;r++){if(t[r]===e[r])continue;const o=m.indexOf(t[r]),c=m.indexOf(e[r]);if(o>=0&&c>=0)return o<c?-1:1;if(o>=0||c>=0)return o>=0?-1:1;break}return n.compare(t,e)||(t<e?-1:t>e?1:0)}const w=t=>t.includes("-")||t.includes("'")?t.replace(/['-]/g,""):t;function E(t,e,n=A){if(t===e)return 0;const i=t.toLowerCase(),r=e.toLowerCase();if(i===r)return 0;const o=T(w(i),w(r),n);return o!==0?o:i.length!==r.length?i.length<r.length?-1:1:i<r?-1:1}function K(t,e){if(t instanceof l||e instanceof l)return t instanceof l?e instanceof l?t.equals(e)?0:E(t.text,e.text)||(t.index<e.index?-1:1):1:-1;if(t==null){if(e==null)return 0;t=typeof e=="number"?0:typeof e=="string"?"":!1}else e==null&&(e=typeof t=="number"?0:typeof t=="string"?"":!1);const n=x(t),i=x(e);return n!==i?n<i?-1:1:n===0?t===e||Math.abs(t-e)<=Math.abs(t)*1e-13&&Number(t.toPrecision(15))===Number(e.toPrecision(15))?0:t<e?-1:1:n===1?E(t,e):t===e?0:t?1:-1}export{f as Arr,u as ERR,I as ERR_BY_CODE,L as ERR_BY_INDEX,D as Lambda,a as OMITTED,F as REJECTED,$ as Ref,b as RefArray,S as RefList,l as RichValue,s as XlError,C as bool,G as checked,E as compareText,K as compareValues,B as int,Y as isOmitted,d as num,M as numberToText,k as opt,V as power,y as str,U as textToNumber};
|
package/calcx/async.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ERR as
|
|
1
|
+
import{ERR as y,XlError as v}from"../calc/values.js";const M=2e4;class x{constructor(e){this.engine=e,this.results=new Map,this.running=new Map,this.waiters=[],this.changed=new Map,this.flushQueued=!1,this.trimming=!1,this.loading=new Map,this.timers=new Map,this.fixed=new Map,this.onLoading=null}get pendingCalls(){return this.running.size}async settled(){for(;;)if(this.engine.manual||await this.engine.whenIdle(),this.running.size||this.flushQueued)await new Promise(e=>this.waiters.push(e));else if(this.engine.manual||!this.engine.pending&&!this.engine.running&&this.engine.graphReady)return}enqueue(e){for(const[n,t]of e)this.changed.set(n,t);this.flushQueued||(this.flushQueued=!0,queueMicrotask(()=>{const n=this.changed;if(this.changed=new Map,this.flushQueued=!1,this.refresh(n.values()),!this.running.size&&!this.flushQueued)for(const t of this.waiters.splice(0))t();this.results.size>M&&!this.trimming&&this.trimAfterCalculation()}))}async trimAfterCalculation(){if(this.trimming=!0,await this.settled(),!this.running.size&&!this.flushQueued&&(this.engine.manual||!this.engine.pending)){const e=this.results.keys();for(;this.results.size>M;)this.results.delete(e.next().value)}this.trimming=!1}refresh(e){const{engine:n}=this,t=new Map;for(const[s,h,r]of e){if(!n.book.sheets.includes(s)&&!s.isScratch)continue;let u=t.get(s);u===void 0&&(u=[],t.set(s,u)),u.push(h,r)}for(const[s,h]of t){const r=h.length/2,u=new Uint32Array(r),o=new Uint32Array(r);for(let l=0;l<r;l++)u[l]=h[l*2],o[l]=h[l*2+1];if(n.cellsChanged(s,u,o,r),n.manual){for(let l=0;l<r;l++)n.read(s,u[l],o[l]);n.onChange?.()}}}store(e,n){this.results.set(e,{value:n})}}const z=new WeakMap;function k(a){let e=z.get(a);return e===void 0&&(e=new x(a),z.set(a,e)),e}const A=(a,e,n)=>`${a.uid}:${e}:${n}`;function L(a,{name:e,key:n,row:t,col:s,sheet:h,run:r,loading:u=y.GETTING,toValue:o=i=>i,onError:l=i=>i instanceof v?i:y.VALUE}){const i=k(a),c=`${e}\0${n}`,w=i.results.get(c);if(w!==void 0)return w.value;let d=i.running.get(c);if(d!==void 0)return d.set(A(h,t,s),[h,t,s]),u;d=new Map([[A(h,t,s),[h,t,s]]]),i.running.set(c,d),i.onLoading?.(i.running.size);const m=f=>{i.running.get(c)===d&&(i.store(c,f),i.running.delete(c),i.onLoading?.(i.running.size),i.enqueue(d))};let g;try{g=r()}catch(f){g=Promise.reject(f)}return Promise.resolve(g).then(f=>{let p;try{p=o(f)}catch(Q){p=l(Q)}m(p)},f=>m(l(f))),u}function S(a,e,{running:n=!0}={}){const t=k(a),{results:s}=t;if(n){let r=!1;for(const[u,o]of t.running)(e===void 0||u.startsWith(e+"\0"))&&(t.running.delete(u),t.enqueue(o),r=!0);r&&t.onLoading?.(t.running.size)}if(e===void 0){s.clear();return}const h=`${e}\0`;for(const r of s.keys())r.startsWith(h)&&s.delete(r)}export{L as asyncCall,k as asyncState,S as clearAsyncResults};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r=new Map;function o(e,t,n="en-US"){if(typeof e!="string"||e==="")throw new Error("A culture needs a name");if(t.months&&t.months.length!==12)throw new Error("months needs 12 names");if(t.days&&t.days.length!==7)throw new Error("days needs 7 names");r.set(e.toLowerCase(),{tag:e,fields:t,parent:n})}const s=e=>r.get(String(e).toLowerCase())??null,u=()=>[...r.values()].map(e=>e.tag);function a(e){return r.delete(String(e).toLowerCase())}export{s as customCulture,u as customCultures,o as defineCulture,a as removeCulture};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LCID_TAGS as z}from"./lcid.js";const C=new Map,N={ja:["午前","午後"],ko:["오전","오후"],zh:["上午","下午"]},
|
|
1
|
+
import{LCID_TAGS as z}from"./lcid.js";const C=new Map,N={ja:["午前","午後"],ko:["오전","오후"],zh:["上午","下午"]},T={es:{shortMonths:["ene.","feb.","mar.","abr.","may.","jun.","jul.","ago.","sep.","oct.","nov.","dic."],shortDays:["do.","lu.","ma.","mi.","ju.","vi.","sá."]},pl:{shortDays:["niedz.","pon.","wt.","śr.","czw.","pt.","sob."]},ru:{shortDays:["Вс","Пн","Вт","Ср","Чт","Пт","Сб"]},de:{shortDays:["So","Mo","Di","Mi","Do","Fr","Sa"]},cs:{shortMonths:["I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII"]},sv:{shortDays:[,,,,"tor"]},he:{shortDays:["יום א","יום ב","יום ג","יום ד","יום ה","יום ו"]},ar:{shortDays:[,"الإثنين"],days:[,"الإثنين"]}},A={"pt-PT":{shortDays:["domingo","segunda","terça","quarta","quinta","sexta","sábado"],shortMonths:["jan","fev","mar","abr","mai","jun","jul","ago","set","out","nov","dez"]}},E=(e,n)=>n?e.map((t,o)=>n[o]??t):e;function H(e){let n=C.get(e);if(n!==void 0)return n;const t=[],o=[],s=[],r=[],l=[],a=c=>new Intl.DateTimeFormat(e,{...c,timeZone:"UTC",calendar:"gregory"}),u=a({month:"long"}),d=a({day:"numeric",month:"long"}),h=a({month:"short"}),y=a({weekday:"long"}),x=a({weekday:"short"});for(let c=0;c<12;c++){const f=new Date(Date.UTC(2024,c,15));t.push(u.format(f)),o.push(d.formatToParts(f).find(D=>D.type==="month").value),s.push(h.format(f))}for(let c=0;c<7;c++){const f=new Date(Date.UTC(2024,0,7+c));r.push(y.format(f)),l.push(x.format(f))}const i=e.split("-")[0],p=A[e]??T[i];return n={tag:e,months:t,monthsWithDay:o,shortMonths:E(s,p?.shortMonths),days:E(r,p?.days),shortDays:E(l,p?.shortDays),am:N[i]?.[0]??"AM",pm:N[i]?.[1]??"PM"},C.set(e,n),n}function Z(e){const n=/^\$([^-]*)(?:-(.*))?$/.exec(e);if(n===null)return null;const t={currency:n[1]||null,tag:null,calendar:0,numerals:0,gannen:!1,system:null},o=n[2];if(o===void 0||o==="")return t;const s=o.toLowerCase();if(s==="x-sysdate")t.system="date";else if(s==="x-systime")t.system="time";else if(/^[0-9a-f]{1,8}$/i.test(o)){const r=parseInt(o,16);(r&65535)===63488?t.system="date":(r&65535)===62464?t.system="time":(t.numerals=r>>>24&255,t.calendar=r>>>16&255,t.tag=z[r&65535]??null)}else{t.gannen=/-x-gannen$/i.test(o),t.tag=o.replace(/-x-.*$/i,"");try{Intl.getCanonicalLocales(t.tag)}catch{t.tag=null}}return t}const L=[{start:0,name:"明治",abbreviation:"明",symbol:"M",firstYear:1868},{start:4595,name:"大正",abbreviation:"大",symbol:"T",firstYear:1912},{start:9856,name:"昭和",abbreviation:"昭",symbol:"S",firstYear:1926},{start:32516,name:"平成",abbreviation:"平",symbol:"H",firstYear:1989},{start:43586,name:"令和",abbreviation:"令",symbol:"R",firstYear:2019}];function q(e){return e.map(n=>{const[t,o,s]=n.start.split("-").map(Number),r=Date.UTC(t,o-1,s)/864e5+25569;return{...n,start:r<61?r-1:r,firstYear:t}}).sort((n,t)=>n.start-t.start)}function K(e,n){if(n?.eras)return n.eras;const t=e?.tag??n?.tag??null;return e?.calendar===3||t&&t.split("-")[0]==="ja"?L:null}function Q(e,n){let t=e[0];for(const o of e)n>=o.start&&(t=o);return t}const P=1948439,v=2415019;function O(e){const n=Math.floor(e),t=(n<60?n+1:n)+v-P,o=Math.floor(t/10631);let s=t-o*10631,r=0;for(;;){const a=_(r+1)?355:354;if(s<a)break;s-=a,r++}let l=0;for(;;){const a=l%2===0||l===11&&_(r+1)?30:29;if(s<a)break;s-=a,l++}return{year:o*30+r+1,month:l+1,day:s+1}}const k=new Set([2,5,7,10,13,15,18,21,24,26,29]),_=e=>k.has((e-1)%30+1),R=["محرم","صفر","ربيع الأول","ربيع الثاني","جمادى الأولى","جمادى الثانية","رجب","شعبان","رمضان","شوال","ذو القعدة","ذو الحجة"],$=e=>(7*e+1)%19<7;function m(e){const n=Math.floor((235*e-234)/19),t=12084+13753*n;let o=n*29+Math.floor(t/25920);return 3*(o+1)%7<3&&o++,o}function b(e){const n=m(e-1),t=m(e);return m(e+1)-t===356?2:t-n===382?1:0}const Y=e=>m(e+1)+b(e+1)-m(e)-b(e),g=-1373427,F=693594;function W(e){const n=Math.floor(e),t=(n<60?n+1:n)+F;let o=Math.floor((t-g)/365.2468)+1;for(;g+m(o)+b(o)>t;)o--;for(;g+m(o+1)+b(o+1)<=t;)o++;let s=t-(g+m(o)+b(o));const r=Y(o),l=$(o),a=[30,r%10===5?30:29,r%10===3?29:30,29,30];l?a.push(30,29):a.push(29),a.push(30,29,30,29,30,29);let u=0;for(;s>=a[u];)s-=a[u],u++;return{year:o,month:u+1,day:s+1,leap:l}}const B=["תשרי","חשון","כסלו","טבת","שבט","אדר","ניסן","אייר","סיון","תמוז","אב","אלול"],J=["תשרי","חשון","כסלו","טבת","שבט","אדר א","אדר ב","ניסן","אייר","סיון","תמוז","אב","אלול"];function tt(e,n,t,o){switch(e){case 6:case"hijri":{const s=O(n);return{...s,monthName:o===null||o.startsWith("ar")?R[s.month-1]:null}}case 7:return{year:t.year+543,month:t.month,day:t.day};case 5:return{year:t.year+2333,month:t.month,day:t.day};case 8:{const s=W(n),r=s.leap?J:B;return{...s,monthName:o?.startsWith("he")?r[s.month-1]:null}}default:return null}}const et=()=>H("ar-SA"),M="0123456789",j={ja:{1:"〇一二三四五六七八九",2:"〇壱弐参四伍六七八九",3:M},"zh-CN":{1:"○一二三四五六七八九",2:"零壹贰叁肆伍陆柒捌玖",3:M},zh:{1:"○一二三四五六七八九",2:"零壹貳參肆伍陸柒捌玖",3:M},ko:{1:"0一二三四五六七八九",2:"零壹貳參四伍六七八九",3:M}};function nt(e,n){if(!n)return null;const t=n.split("-")[0];return j[n==="zh-CN"||n==="zh-SG"?"zh-CN":t]?.[e]??null}const U={ja:{1:{small:"十百千",big:"万億兆",dropOne:!0},2:{small:"拾百阡",big:"万億兆"},3:{small:"十百千",big:"万億兆",dropOne:!0}},ko:{1:{small:"十百千",big:"万億兆"}},"zh-CN":{1:{small:"十百千",big:"万亿兆",zeroes:!0},2:{small:"拾佰仟",big:"万亿兆",zeroes:!0}}};function ot(e,n,t){if(!t)return null;const o=t.split("-")[0],s=t==="zh-CN"||t==="zh-SG"?"zh-CN":o,r=U[s]?.[n],l=j[s]?.[n];if(!r||!l)return null;const a=/^(\d+)(\.\d+)?$/.exec(e);if(a===null)return null;const u=[...l],d=a[1];if(/^0+$/.test(d))return u[0]+(a[2]?`.${[...a[2].slice(1)].map(i=>u[Number(i)]).join("")}`:"");let h="",y=!1;const x=Math.ceil(d.length/4);for(let i=0;i<x;i++){const p=d.length-(x-1-i)*4,c=d.slice(Math.max(0,p-4),p);let f=!1;for(let I=0;I<c.length;I++){const w=Number(c[I]),S=c.length-1-I;if(w===0){y=h!==""||f;continue}y&&r.zeroes&&(h+=u[0]),y=!1,S>0&&w===1&&r.dropOne||(h+=u[w]),S>0&&(h+=[...r.small][S-1]),f=!0}const D=x-1-i;f&&D>0&&(h+=[...r.big][D-1])}return h+(a[2]?`.${[...a[2].slice(1)].map(i=>u[Number(i)]).join("")}`:"")}const X={2:1632,3:1776,4:2406,5:2534,6:2662,7:2790,8:2918,10:3174,11:3302,12:3430,13:3664,14:3792,15:3872,16:4160,18:6112,19:6160};function st(e){if(e===9)return"0௧௨௩௪௫௬௭௮௯";if(e===17)return"0፩፪፫፬፭፮፯፰፱";const n=X[e];return n===void 0?null:Array.from({length:10},(t,o)=>String.fromCodePoint(n+o)).join("")}function rt(e,n){const t=[...n];let o="";for(let s=0;s<e.length;s++){const r=e.charCodeAt(s);o+=r>=48&&r<=57?t[r-48]:e[s]}return o}export{tt as calendarParts,nt as dbnumDigits,ot as dbnumPlaces,Q as eraAt,K as erasOf,et as hijriLocale,H as localeData,rt as mapDigits,st as numeralDigits,Z as parseLocaleBracket,q as preparedEras};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={fr:[".",";"],es:["\\",";"],pl:["\\",";"],pt:["\\",";"],nl:["\\",";"],sv:["\\",";"],cs:["\\",";"],da:["\\",";"],fi:["\\",";"],hu:["\\",";"],it:["\\","."],nb:["\\","."],no:["\\","."],nn:["\\","."],ru:[";",":"],tr:[";","\\"],de:[".",";"],en:[",",";"],ja:[",",";"],ko:[",",";"],zh:[",",";"]};function t(o,a){const n=o.split("-")[0].toLowerCase(),r=e[n];return r&&!(a===","&&r[0]===",")?{arrayColSep:r[0],arrayRowSep:r[1]}:a===","?{arrayColSep:"\\",arrayRowSep:";"}:{arrayColSep:",",arrayRowSep:";"}}export{t as arraySeparatorsOf};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{raw as
|
|
1
|
+
import{raw as it,setCategory as At}from"../../calc/functions/registry.js";import{Arr as j,compareValues as W,ERR as H,Lambda as ht,num as dt,OMITTED as yt,XlError as Z}from"../../calc/values.js";const ct=t=>t!==void 0&&t!==yt,q=(t,n,r,c,f)=>{if(!ct(n))return f;const e=t.scalar(n,r,c);if(e instanceof Z)throw e;return e===null?f:dt(e)};function wt(t,n,r){const c=n instanceof ht?[n]:n instanceof j?n.data:null;if(c===null||c.length===0)throw H.VALUE;return c.map((f,e)=>{if(!(f instanceof ht))throw f instanceof Z?f:H.VALUE;return{fn:f,label:r[e]??f.label??"CUSTOM"}})}function gt(t){if(t.rows<2)return!1;for(let n=0;n<t.cols;n++){const r=t.get(0,n),c=t.get(1,n);if(typeof r=="string"&&typeof c=="number")return!0}return!1}function x(t,n,r){const c=new Array(t.rows-r);for(let f=r;f<t.rows;f++)c[f-r]=t.get(f,n);return c}const bt=t=>t===null?"":typeof t=="string"?`s${t.toLowerCase()}`:`${typeof t}${t}`;function lt(t,n,r,c,f,e,u,w){const a=j.column(r.map(A=>c[A])),p=(n.native?n.native.min:n.params.length)>=2?[a,j.column(f)]:[a],y=t.invoke(n,p,e,u,w);return y instanceof j?y.data[0]:y}function at(t,n,r,c){return ct(n)?t.toArr(n).data.map(e=>{if(e instanceof Z)throw e;return Math.trunc(dt(e))}).filter(e=>e!==0):[]}function ft(t,n){const r={key:null,rows:n,children:new Map};for(const c of n){let f=r;for(let e=0;e<t.length;e++){const u=t[e][c],w=bt(u);let a=f.children.get(w);a===void 0&&(a={key:u,rows:[],children:new Map},f.children.set(w,a)),a.rows.push(c),f=a}}return r}const D=t=>t??"";function pt(t,n,r,c,f){const e=Array.from({length:r},(w,a)=>a);if(!ct(n))return e;const u=t.toArr(n);if(u.rows*u.cols<r)throw H.VALUE;return e.filter(w=>{const a=u.data[w];if(a instanceof Z)throw a;return a===!0||typeof a=="number"&&a!==0})}function ut(t,n,r,c){const f=r<0,e=Math.abs(r),u=[],w=(a,b,p)=>{const y=[...a.children.values()];c(y,p);for(const A of y){const U=[...b,A.key];if(p+1===n)u.push({path:U,rows:A.rows,level:p+1});else{const K=e>=2&&p+1<n&&p+2<=e;K&&f&&u.push({path:U,rows:A.rows,level:p+1,total:!0}),w(A,U,p+1),K&&!f&&u.push({path:U,rows:A.rows,level:p+1,total:!0})}}};if(w(t,[],0),e>=1){const a={path:[],rows:t.rows,level:0,total:!0};f?u.unshift(a):u.push(a)}return u}At("Lookup & Reference"),it("GROUPBY",3,8,(t,n,r,c,f)=>{const e=t.toArr(n[0]),u=t.toArr(n[1]);if(e.rows!==u.rows)return H.VALUE;const w=wt(t,n[2],[]),a=q(t,n[3],r,c,null),b=a===null?gt(u):a===1||a===3,p=a===2||a===3,y=b?1:0,A=e.rows-y;if(A<=0)return H.CALC;const U=q(t,n[4],r,c,1),K=at(t,n[5],r,c),ot=pt(t,n[6],A,r,c),tt=q(t,n[7],r,c,0);if(tt!==0&&tt!==1)return H.VALUE;const M=e.cols,z=Array.from({length:M},(l,s)=>x(e,s,y)),_=Array.from({length:u.cols},(l,s)=>x(u,s,y));for(const l of z)for(const s of l)if(s instanceof Z)return s;const $=_.length,R=w.length,P=$*R,J=ft(z,ot),G=new Map,B=l=>{let s=G.get(l);if(s===void 0){s=[];for(let g=0;g<$;g++)for(const{fn:k}of w)s.push(lt(t,k,l.rows,_[g],_[g],r,c,f));G.set(l,s)}return s},T=ut(J,M,U,(l,s)=>{const g=K.find(E=>Math.abs(E)===s+1),k=K.find(E=>Math.abs(E)>M),d=g!==void 0&&g<0?-1:1;if(l.sort((E,N)=>d*W(E.key,N.key)),k!==void 0&&s===M-1){const E=Math.abs(k)-M-1,N=k<0?-1:1,st=o=>{const h=E>=0&&E<P?B({rows:o.rows}):null;return h?h[E]:null},i=new Map(l.map(o=>[o,st(o)]));l.sort((o,h)=>N*W(i.get(o),i.get(h)))}}),F=R>1?1:0,S=F+(p?1:0),O=M+P,L=new Array((T.length+S)*O).fill("");if(F)for(let l=0;l<$;l++)for(let s=0;s<R;s++)L[M+l*R+s]=w[s].label;if(p){const l=F*O;for(let s=0;s<M;s++)L[l+s]=b?D(e.get(0,s)):`Row Field ${s+1}`;for(let s=0;s<$;s++)for(let g=0;g<R;g++)L[l+M+s*R+g]=b?D(u.get(0,s)):`Value ${s+1}`}const nt=T.some(l=>l.total&&l.level>0);return T.forEach((l,s)=>{const g=(s+S)*O;if(l.level===0)L[g]=nt?"Grand Total":"Total";else{for(let d=0;d<l.path.length;d++)L[g+d]=D(l.path[d]);l.total&&(L[g+l.path.length-1]=l.path[l.path.length-1])}const k=B(l);for(let d=0;d<P;d++)L[g+M+d]=k[d]===null?0:k[d]}),new j(T.length+S,O,L)},{array:!0}),it("PIVOTBY",4,11,(t,n,r,c,f)=>{const e=t.toArr(n[0]),u=t.toArr(n[1]),w=t.toArr(n[2]);if(e.rows!==w.rows||u.rows!==w.rows)return H.VALUE;const a=wt(t,n[3],[]),b=q(t,n[4],r,c,null),p=b===null?gt(w):b===1||b===3,y=b===2||b===3,A=p?1:0,U=e.rows-A;if(U<=0)return H.CALC;const K=q(t,n[5],r,c,1),ot=at(t,n[6],r,c),tt=q(t,n[7],r,c,1),M=at(t,n[8],r,c),z=pt(t,n[9],U,r,c),_=Array.from({length:e.cols},(i,o)=>x(e,o,A)),$=Array.from({length:u.cols},(i,o)=>x(u,o,A)),R=Array.from({length:w.cols},(i,o)=>x(w,o,A)),P=(i,o)=>(h,m)=>{const V=i.find(C=>Math.abs(C)===m+1),rt=V!==void 0&&V<0?-1:1;h.sort((C,et)=>rt*W(C.key,et.key));const Y=i.find(C=>Math.abs(C)>o);if(Y===void 0||m!==o-1)return;const v=R[Math.abs(Y)-o-1];if(v===void 0)return;const{fn:X}=a[0],Q=new Map(h.map(C=>[C,lt(t,X,C.rows,v,v,r,c,f)])),mt=Y<0?-1:1;h.sort((C,et)=>mt*W(Q.get(C),Q.get(et)))},J=ut(ft(_,z),_.length,K,P(ot,_.length)),G=ut(ft($,z),$.length,tt,P(M,$.length)),B=R.length,I=a.length,T=_.length,F=$.length,S=B*I,O=y?1:0,L=I>1?1:0,nt=y||B>1?1:0,l=O+F+L+nt,s=T+G.length*S,g=l+J.length,k=new Array(g*s).fill(""),d=(i,o,h)=>{k[i*s+o]=h};if(y){let i=T;if(F===1){let o=-1;G.forEach((h,m)=>{h.level===1&&(o<0||W(h.path[0],G[o].path[0])<0)&&(o=m)}),o>=0&&(i+=o*S)}for(let o=0;o<F;o++)d(0,i+o,p?D(u.get(0,o)):`Col Field ${o+1}`);for(let o=0;o<T;o++)d(l-1,o,p?D(e.get(0,o)):`Row Field ${o+1}`)}const E=i=>i.some(o=>o.total&&o.level>0),N=E(G)?"Grand Total":"Total",st=E(J)?"Grand Total":"Total";return G.forEach((i,o)=>{for(let h=0;h<S;h++){const m=T+o*S+h;if(i.level===0)d(O,m,N);else for(let V=0;V<i.path.length;V++)d(O+V,m,D(i.path[V]));if(L&&d(O+F,m,a[h%I].label),nt){const V=Math.floor(h/I);d(l-1,m,p?D(w.get(0,V)):`Value ${V+1}`)}}}),J.forEach((i,o)=>{const h=l+o;if(i.level===0)d(h,0,st);else for(let m=0;m<i.path.length;m++)d(h,m,D(i.path[m]));G.forEach((m,V)=>{if(m.level===0&&B>1)return;const rt=new Set(m.rows),Y=i.rows.filter(v=>rt.has(v));if(Y.length!==0)for(let v=0;v<B;v++)for(let X=0;X<I;X++){const Q=lt(t,a[X].fn,Y,R[v],R[v],r,c,f);d(h,T+V*S+v*I+X,Q===null?0:Q)}})}),new j(g,s,k)},{array:!0});
|
package/calcx/functions/ets.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{raw as
|
|
1
|
+
import{raw as b,setCategory as z}from"../../calc/functions/registry.js";import{normInv as D}from"../../calc/functions/stat.js";import{Arr as V,ERR as m,num as w,OMITTED as X,XlError as U}from"../../calc/values.js";import{partsToSerial as R,serialToParts as q}from"../../core/numfmt.js";const N=n=>n!==void 0&&n!==X;function T(n,t){return n.toArr(t).data.map(o=>{if(o instanceof U)throw o;if(typeof o=="number")return o;if(o===null)return null;throw m.VALUE})}const Y={1:n=>n.reduce((t,e)=>t+e,0)/n.length,2:n=>n.length,3:n=>n.length,4:n=>Math.max(...n),5:n=>{const t=[...n].sort((o,s)=>o-s),e=t.length>>1;return t.length%2?t[e]:(t[e-1]+t[e])/2},6:n=>Math.min(...n),7:n=>n.reduce((t,e)=>t+e,0)};function B(n,t){if(!n.every(r=>Number.isInteger(r)&&r>=0&&r+t<=2958465))return null;const e=n.map(r=>q(r,t)),o=(r,u)=>R(r,u+1,1)-R(r,u,1),s=e[0].day,a=e.every(({year:r,month:u,day:h})=>h===o(r,u));return!a&&!e.every(({day:r})=>r===s)?null:r=>{const{year:u,month:h,day:p}=q(r,t),f=o(u,h),M=a?f:Math.min(s,f);return u*12+h+(p-M+r-Math.floor(r))/f}}function F(n){let t=1/0;for(let e=1;e<n.length;e++)t=Math.min(t,n[e]-n[e-1]);return t<=0?null:n.every(e=>{const o=(e-n[0])/t;return Math.abs(o-Math.round(o))<=1e-9})?t:null}function L(n,t,e,o,s){if(n.length!==t.length)throw m.NA;if(n.length<2)throw m.NA;const a=new Map;for(let i=0;i<t.length;i++){const g=t[i];if(g===null)throw m.NUM;a.has(g)||a.set(g,[]),n[i]!==null&&a.get(g).push(n[i])}const r=Y[o];if(r===void 0)throw m.NUM;const u=[...a.keys()].sort((i,g)=>i-g);if(u.length<2)throw m.NUM;let h=u,p=F(u),f=i=>i;if(p===null){if(f=B(u,s),f===null)throw m.NUM;if(h=u.map(f),p=F(h),p===null)throw m.NUM}const M=h[0],l=Math.round((h[h.length-1]-M)/p)+1,c=new Array(l).fill(null);for(let i=0;i<u.length;i++){const g=a.get(u[i]);g.length>0&&(c[Math.round((h[i]-M)/p)]=r(g))}for(let i=0;i<l;i++){if(c[i]!==null)continue;if(e===0){c[i]=0;continue}let g=i;for(;g<l&&c[g]===null;)g++;const y=i>0?c[i-1]:c[g],A=g<l?c[g]:y,S=g-i+1;for(let E=i;E<g;E++)c[E]=y+(A-y)*(E-i+1)/S;i=g-1}return{y:c,start:M,step:p,position:f}}function G(n){const t=n.length,e=(t-1)/2,o=n.reduce((r,u)=>r+u,0)/t;let s=0,a=0;for(let r=0;r<t;r++)s+=(r-e)*(n[r]-o),a+=(r-e)*(r-e);return a===0?0:s/a}function P(n){const t=n.length;if(t<6)return 0;const e=G(n),o=(t-1)/2,s=n.reduce((l,c)=>l+c,0)/t,a=n.map((l,c)=>l-(s+e*(c-o))),r=a.reduce((l,c)=>l+c*c,0);if(r<1e-12)return 0;const u=Math.floor(t/2),h=[1];for(let l=1;l<=u;l++){let c=0;for(let i=l;i<t;i++)c+=a[i]*a[i-l];h[l]=c/r}const p=1.96/Math.sqrt(t);let f=0,M=p;for(let l=2;l<=u;l++)h[l]>=h[l-1]&&(l===u||h[l]>=h[l+1])&&h[l]>M&&(f=l,M=h[l]);return f}function H(n,t){const e=n.length,o=new Array(Math.max(t,1)).fill(0);if(t>1){const a=Math.max(0,Math.floor(t/2)-1),r=Math.min(5,Math.floor(e/t)),u=Math.floor(r/2),h=new Array(t).fill(0);if(u>0){const c=(r-u)*t;for(let i=0;i<t;i++){let g=0,y=0;for(let A=0;A<u;A++)g+=n[i+A*t],y+=n[i+(r-u+A)*t];h[i]=(y-g)/u/c}}const p=Math.max(1,Math.min(3,r-2,Math.floor((e-a)/t))),f=new Array(t).fill(0),M=new Array(t).fill(0);let l=0;for(let c=a;c<a+p*t;c++)f[c%t]+=n[c]-l,M[c%t]++,l+=h[(c-a)%t];for(let c=0;c<t;c++)o[c]=M[c]>0?f[c]/M[c]:0}const s=G(n.map((a,r)=>a-(t>1?o[r%t]:0)));return{level:n[0]-s-o[0],trend:s,season:o}}const J=(n,t=1)=>n<12?n:Math.min(Math.max(10,2*t),Math.floor(n*.4));function K(n,t,e,o,s){const a=n.length,r=H(n,t);let{level:u,trend:h}=r;const p=[...r.season],f=t>1,M=a-J(a,t);let l=0,c=0,i=0,g=0,y=0,A=0;for(let S=0;S<a;S++){const E=f?S%t:0,C=u+h+p[E],d=n[S]-C;if(A+=d*d,(S<M||M===0)&&(y+=d*d),S>=M){l+=d*d,c+=Math.abs(d);const I=(Math.abs(n[S])+Math.abs(C))/2;I!==0&&(i+=Math.abs(d)/I),g++}u+=h+e*d,h+=o*d,f&&(p[E]+=s*d)}return{level:u,trend:h,season:p,sse:l,sae:c,sape:i,count:g,trainError:y,allSquared:A,n:a,from:M}}const Q=[[.002,.001],[.126,.001],[.25,.001],[.5,.001],[.75,.001],[.9,.001],[.998,.899]].map(([n,t])=>[n,t,0]),W=[[.126,.001,.001],[.251,.001,.001],[.501,.001,.001],[.751,.001,.001],[.002,.001,.125],[.002,.001,.25],[.002,.001,.75],[.251,.001,.25],[.25,.001,.749],[.9,.001,.099],[.5,.001,.499],[.75,.001,.249],[.1,.001,.899],[.998,.099,.001],[.5,.25,.001]];function O(n,t){let e=null;for(const[o,s,a]of t>1?W:Q){const r=K(n,t,o,s,a);(e===null||r.trainError<e.trainError-1e-12)&&(e={alpha:o,beta:s,gamma:a,...r})}return e}function k(n,t,e,o,s){const a=T(n,t[s]),r=T(n,t[s+1]),u=N(t[s+2])?n.scalar(t[s+2],e,o):1,h=N(t[s+3])?Math.trunc(w(n.scalar(t[s+3],e,o))):1,p=N(t[s+4])?Math.trunc(w(n.scalar(t[s+4],e,o))):1;if(h!==0&&h!==1)throw m.NUM;const f=L(a,r,h,p,n.book.dateOffset),M=u===null?1:Math.trunc(w(u));if(M<0||M>8760)throw m.NUM;const l=M===1?P(f.y):M;if(l>1&&f.y.length<2*l)throw m.NUM;return{...f,m:l<=1?1:l}}const Z=(n,t,e)=>n.level+e*n.trend+(t>1?n.season[(n.n+e-1)%t]:0),j=(n,t)=>{const e=t.position(n),o=(e-t.start-(t.y.length-1)*t.step)/t.step;if(o<=0&&e<t.start)throw m.NUM;return Math.ceil(o-1e-9)},v=(n,t,e,o,s)=>{const a=n.toArr(t),r=a.data.map(u=>{if(u instanceof U)return u;try{return s(w(u))}catch(h){if(h instanceof U)return h;throw h}});return r.length===1?r[0]:new V(a.rows,a.cols,r)};z("Statistical"),b("FORECAST.ETS",3,6,(n,t,e,o)=>{const s=k(n,t,e,o,1),a=O(s.y,s.m);return v(n,t[0],e,o,r=>Z(a,s.m,j(r,s)))},{array:!0}),b("FORECAST.ETS.SEASONALITY",2,4,(n,t,e,o)=>{const s=T(n,t[0]),a=T(n,t[1]),r=N(t[2])?Math.trunc(w(n.scalar(t[2],e,o))):1,u=N(t[3])?Math.trunc(w(n.scalar(t[3],e,o))):1;return P(L(s,a,r,u,n.book.dateOffset).y)},{array:!0}),b("FORECAST.ETS.CONFINT",3,7,(n,t,e,o)=>{const s=N(t[3])?w(n.scalar(t[3],e,o)):.95;if(s<=0||s>=1)return m.NUM;const a=k(n,[t[0],t[1],t[2],t[4],t[5],t[6]],e,o,1),r=O(a.y,a.m),u=Math.sqrt(r.allSquared/r.n),h=-D((1-s)/2);return v(n,t[0],e,o,p=>{const f=j(p,a);let M=1;for(let l=1;l<f;l++){const c=r.alpha+l*r.beta+(a.m>1&&l%a.m===0?r.gamma:0);M+=c*c}return h*u*Math.sqrt(M)})},{array:!0}),b("FORECAST.ETS.STAT",3,6,(n,t,e,o)=>{const s=k(n,[null,t[0],t[1],t[3],t[4],t[5]],e,o,1),a=Math.trunc(w(n.scalar(t[2],e,o))),r=O(s.y,s.m),{sse:u,sae:h,sape:p,count:f,from:M}=r,l=M===0?s.y.length:M;let c=0;for(let i=1;i<l;i++)c+=Math.abs(s.y[i]-s.y[i-1]);switch(c/=l-1,a){case 1:return r.alpha;case 2:return r.beta;case 3:return s.m>1?r.gamma:2220446049250313e-31;case 4:return h/f/c;case 5:return p/f;case 6:return h/f;case 7:return Math.sqrt(u/f);case 8:return s.step;default:return m.NUM}},{array:!0});
|
package/calcx/functions/misc.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{alias as
|
|
1
|
+
import{alias as S,FUNCS as g,lift as B,raw as l,setCategory as u}from"../../calc/functions/registry.js";import{Arr as R,ERR as i,ERR_BY_CODE as P,num as L,OMITTED as N,Ref as Y,RichValue as V,str as h,XlError as m}from"../../calc/values.js";import{fieldValue as K}from"../../cells/rich-values.js";import{asyncCall as k}from"../async.js";import{mayReach as F}from"../../core/online.js";const T=r=>r!==void 0&&r!==N,y=new Map;function j(r,e){e?y.set(r,e):y.delete(r)}const M=(r,e,f,n)=>l(r,e,f,()=>n);u("Other");const D={keepImportedResult:!0};for(const r of["CUBEVALUE","CUBEMEMBER","CUBEMEMBERPROPERTY","CUBERANKEDMEMBER","CUBESET","CUBESETCOUNT"])l(r,1,255,()=>i.NA,D);l("CUBEKPIMEMBER",3,4,(r,e,f,n)=>typeof r.scalar(e[2],f,n)=="number"?i.NA:i.VALUE,D),M("RTD",2,255,i.NA),M("CALL",1,255,i.VALUE),M("REGISTER.ID",2,3,i.VALUE),u("Math & Trig"),B("ECMA.CEILING",2,2,(r,e)=>{const f=L(r),n=L(e);if(n===0)return 0;if(f>0&&n<0)throw i.NUM;return Math.ceil(f/n-1e-12)*n}),u("Lookup & Reference");function I(r,e){return r===null||typeof r!="object"?r:r.error?P.get(r.error)??i.VALUE:r.entity!==void 0?new V(e,r.entity):R.of2D(r.rows.map(f=>f.map(n=>I(n,e))))}function w(r,e,f,n,c,a){const E=[];for(let t=1;t<e.length;t++){const s=r.scalar(e[t],f,n);if(s instanceof m)return s;if(a&&t===e.length-1&&t>1&&typeof s=="boolean")break;E.push(h(s))}const p=t=>{if(t instanceof V)return I(K(t.rich,t.index,E),t.rich);if(!a||typeof t!="string"||!/^\s*[{[]/.test(t))return i.FIELD;try{return g.get("PROPERTY").fn(t,E.join("."))}catch(s){return s instanceof m?s:i.FIELD}},A=(t,s,C)=>p(r.read(t,s,C)),o=e[0];if(o instanceof Y){const t=o.sheet??c;if(o.isCell)return A(t,o.r0,o.c0);if(o.rows*o.cols>1e6)return i.VALUE;const s=[];for(let C=o.r0;C<=o.r1;C++)for(let U=o.c0;U<=o.c1;U++){const O=A(t,C,U);s.push(O instanceof R?O.data[0]:O)}return new R(o.rows,o.cols,s)}return o instanceof R?new R(o.rows,o.cols,o.data.map(p)):p(o)}l("FIELDVALUE",2,2,(r,e,f,n,c)=>w(r,e,f,n,c,!1),{refResult:!0}),l("_FV",2,255,(r,e,f,n,c)=>w(r,e,f,n,c,!0)),u("Other"),l("PY",2,255,()=>i.BLOCKED,{frozen:!0}),u("Lookup & Reference"),B("IMAGE",1,5,(r,e,f,n,c)=>{const a=h(r);if(!/^https:\/\//i.test(a))throw i.VALUE;if(!F(a))throw i.BLOCKED;const E=T(f)?Math.trunc(L(f)):0;if(E<0||E>3)throw i.VALUE;if(E===3&&!(T(n)&&L(n)>0)&&!(T(c)&&L(c)>0))throw i.VALUE;return T(e)?h(e):""});const d=(r,e,f)=>l(r,e,f,(n,c,a,E,p)=>{const A=y.get(r);if(A===void 0)return r==="STOCKHISTORY"?i.CONNECT:i.BLOCKED;const o=[];for(const t of c){const s=t===N?null:n.scalar(t,a,E);if(s instanceof m)return s;o.push(s)}return k(n,{name:r,key:JSON.stringify(o),row:a,col:E,sheet:p,run:()=>A(...o),toValue:t=>Array.isArray(t)?R.of2D(t.map(s=>Array.isArray(s)?s:[s])):t,onError:()=>i.CONNECT})});u("Information"),S("ERRORTYPE","ERROR.TYPE"),u("Text"),d("TRANSLATE",1,3),d("DETECTLANGUAGE",1,1),u("Financial"),d("STOCKHISTORY",2,255);export{j as setServiceHandler};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const L=new Map;let p=null;function W(e,n){const r=e.toLowerCase(),s=n.parent?L.get(n.parent.toLowerCase()):null;L.set(r,y(r,n,s)),p?.code===r&&(p=L.get(r))}function y(e,n,r){const s={...r?.source.functions??{},...n.functions??{}},u={...r?.source.errors??{},...n.errors??{}},f={...r?.source.booleans??{},...n.booleans??{}},i={...r?.source.structured??{},...n.structured??{}},h=d=>new Map(Object.entries(d).map(([t,l])=>[l.toUpperCase(),t]));return{code:e,name:n.name??e,source:{functions:s,errors:u,booleans:f,structured:i},fnToLocal:new Map(Object.entries(s)),fnToEnglish:h(s),errToLocal:new Map(Object.entries(u).map(([d,t])=>[d.toUpperCase(),t])),errToEnglish:h(u),boolToLocal:new Map(Object.entries(f)),boolToEnglish:h(f),structToLocal:new Map(Object.entries(i).map(([d,t])=>[d.toUpperCase(),t])),structToEnglish:h(i)}}const v=()=>[...L.values()].map(e=>({code:e.code,name:e.name}));function B(e){if(!e||e.toLowerCase()==="en")return p=null,!0;const n=L.get(e.toLowerCase());return n===void 0?!1:(p=n,!0)}const X=()=>p?.code??"en",b="_XLL.",g=new Set,A=e=>{for(const n of g)if(n(e))return!0;return!1};function z(e){return g.add(e),()=>g.delete(e)}function S(e,n){let r=n;for(;r.startsWith(b);)r=r.slice(b.length);if(e.fnToLocal.has(r))return!1;const s=e.fnToEnglish.get(r);return s!==void 0&&s!==r}function E(e,n){const r=n.toUpperCase();return S(e,r)?`_xll.${n}`:e.fnToLocal.get(r)??n}function j(e,n){const r=n.toUpperCase();return r.startsWith(b)&&S(e,r)?n.slice(b.length):e.fnToEnglish.get(r)??n}const H=e=>p?E(p,e):e,P=e=>(p?j(p,e):e).toUpperCase(),Q=e=>p?.errToLocal.get(e.toUpperCase())??e,$=e=>{const n=e?"TRUE":"FALSE";return p?.boolToLocal.get(n)??n},O=Object.freeze({decimal:".",listSep:",",arrayColSep:",",arrayRowSep:";"}),m=e=>e>="0"&&e<="9",_=/[\p{L}_\\]/u,D=/[\p{L}\p{N}_.\\?]/u;function F(e,n,r){let s=n+1;for(;s<e.length;)if(e[s]===r)if(e[s+1]===r)s+=2;else return s+1;else s++;return s}function M(e,n,r,s){if(/^\[\d+\]/.test(e)&&!e.includes("#"))return e;let u="",f=0,i=0;for(;i<e.length;){const h=e[i];if(h==="'"&&e[i+1]!==void 0)u+=h+e[i+1],i+=2;else if(h==="["){if(f++,u+=h,i++,e[i]==="#"){const d=e.indexOf("]",i),t=e.slice(i,d<0?e.length:d),l=s?n?s.structToLocal.get(t.toUpperCase()):s.structToEnglish.get(t.toUpperCase()):void 0;u+=l??t,i+=t.length}}else h==="]"?(f--,u+=h,i++):f===1&&h===(n?",":r)?(u+=n?r:",",i++):(u+=h,i++)}return u}function R(e,n,r,s){const{decimal:u,listSep:f,arrayColSep:i,arrayRowSep:h}=r,d=e.length;let t="",l=0,T=0;for(;l<d;){const c=e[l];if(c==='"'||c==="'"){const a=F(e,l,c);t+=e.slice(l,a),l=a}else if(c==="["){let a=0,o=l;for(;o<d;o++)if(e[o]==="'")o++;else if(e[o]==="[")a++;else if(e[o]==="]"&&(a--,a===0))break;t+=M(e.slice(l,o+1),n,f,s),l=o+1}else if(c==="{")T++,t+=c,l++;else if(c==="}")T--,t+=c,l++;else if(c==="#"){const a=/^#[^\s,;:()+\-*^&=<>{}\\|]*[!?]?/u.exec(e.slice(l,l+40));let o=null;if(a&&s){const w=n?s.errToLocal:s.errToEnglish;for(let C=a[0].length;C>1;C--){const U=w.get(a[0].slice(0,C).toUpperCase());if(U!==void 0){o={len:C,swapped:U};break}}}o?(t+=o.swapped,l+=o.len):(t+=c,l++)}else if(m(c)||c===(n?".":u)&&m(e[l+1]??"")){const a=n?".":u;let o=l;for(;o<d&&m(e[o]);)o++;if(e[o]===a)for(o++;o<d&&m(e[o]);)o++;if((e[o]==="e"||e[o]==="E")&&(m(e[o+1]??"")||(e[o+1]==="+"||e[o+1]==="-")&&m(e[o+2]??"")))for(o+=2;o<d&&m(e[o]);)o++;const w=e.slice(l,o);t+=a===(n?u:".")?w:w.replace(a,n?u:"."),l=o}else if(_.test(c)&&!(c==="\\"&&T>0)){let a=l+1;for(;a<d&&D.test(e[a]);)a++;const o=e.slice(l,a),w=e[a];if(s&&w==="(")A(o.toUpperCase())?t+=o:t+=n?E(s,o):j(s,o);else if(s&&w!=="!"&&w!=="["){const C=o.toUpperCase(),U=n?s.boolToLocal.get(C):s.boolToEnglish.get(C);t+=U??o}else t+=o;l=a}else n?(c===","?t+=T>0?i:f:c===";"&&T>0?t+=h:t+=c,l++):(T>0&&c===i?t+=",":T>0&&c===h?t+=";":T===0&&c===f?t+=",":t+=c,l++)}return t}const N=e=>e.decimal==="."&&e.listSep===","&&e.arrayColSep===","&&e.arrayRowSep===";";function G(e,n=O){return p===null&&N(n)?e:R(e,!0,n,p)}function I(e,n=O){return p===null&&N(n)?e:R(e,!1,n,p)}function J(e,n,r=40){const s=e.toUpperCase(),u=[];for(const f of n){if(f.startsWith("_"))continue;const i=p?E(p,f):f;i.toUpperCase().startsWith(s)&&u.push({local:i,english:f})}return u.sort((f,i)=>f.local.localeCompare(i.local)),u.slice(0,r)}export{O as STANDARD_SEPARATORS,z as addDefinedNameCheck,v as availableLanguages,J as completeFunctionName,P as englishFunctionName,I as formulaFromUser,X as formulaLanguage,G as formulaToUser,$ as localBooleanText,Q as localErrorText,H as localFunctionName,W as registerLanguage,B as setFormulaLanguage};
|
package/cells/axis-ops.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{selectedSheets as C}from"../core/sheet-group.js";import{openFormatCells as O,promptNumber as F}from"../ui/dialogs.js";import{guardOption as R}from"../ui/protection-ui.js";import{MAX_COLS as
|
|
1
|
+
import{selectedSheets as C}from"../core/sheet-group.js";import{openFormatCells as O,promptNumber as F}from"../ui/dialogs.js";import{guardOption as R}from"../ui/protection-ui.js";import{MAX_COLS as H,MAX_ROWS as z}from"../core/address.js";import{CHUNK_BITS as T}from"../core/sheet.js";import{wrapsByAlign as _}from"./text-layout.js";import{canResize as b}from"./axis-limits.js";import{setAxisSizing as I}from"./panes.js";import{openTrackSize as y}from"./cell-options-ui.js";import{openHeaderColors as v}from"./header-colors.js";const h=o=>o==="col"?"cols":"rows";function U(o){const t=o.grid.selection.ranges[0];t.c0===0&&t.c1===H-1?v(o,"row",t.r0,t.r1):v(o,"col",t.c0,t.c1)}function g(o,t,s){return()=>{const n=o[t];return o[t]=s,t==="cols"&&(o.colsChanged=!0),o.revision++,g(o,t,n)}}function w(o,t){const{book:s,grid:n}=o;t==="col"&&(s.sheet.colsChanged=!0),s.dirty=!0,o.objects?.geometryChanged?.(),n.invalidate()}function B(o,t){const{sheet:s,styles:n}=o.book,e=new Set,c=new Map,l=r=>{let i=c.get(r);if(i===void 0){const f=n.get(r);i=!!(f.wrap||_(f)),c.set(r,i)}return i};o:for(const r of t.slice(0,256)){const i=s.columns[r];if(i===void 0)continue;const f=s.colStyles?.get(r)??0;for(let d=0;d<i.length;d++){const a=i[d];if(a!==void 0)for(let u=0;u<a.kinds.length;u++){if(a.kinds[u]===0)continue;const m=a.styles===null||a.styles[u]===0?f:a.styles[u];if(!(m===0||!l(m))&&(e.add((d<<T)+u),e.size>=j))break o}}}for(const r of e)o.commands._growRow(r);return e.size>0}const j=2e3;function k(o,t,s){const n=o.book.sheet,e=n.rows.reshaped();if(!B(o,t))return s;const c=(l,r)=>()=>{const i=l(),f=r();return c(f,i)};return c(g(n,"rows",e),s)}function A(o,t,s){let n=!1;o.guardHint={option:t==="col"?"formatColumns":"formatRows"};try{o.transact("axis",()=>{const e=s();return n=!0,e})}finally{o.guardHint=null}return n}function p(o,t,s,n=null){const{book:e}=o,c=e.sheet,l=h(t);A(e,t,()=>{const i=c[l].reshaped();s(),c.revision++;const f=g(c,l,i);return n!==null&&t==="col"?k(o,n,f):f})&&(w(o,t),n!==null&&e.collab?.changed?.())}const x=(o,t)=>o==="col"?t.r0===0&&t.r1===z-1:t.c0===0&&t.c1===H-1,S=(o,t)=>o==="col"?[t.c0,t.c1]:[t.r0,t.r1];function oo(o,t){const s=t.map(e=>S(o,e)).sort((e,c)=>e[0]-c[0]),n=[];for(const[e,c]of s){const l=n[n.length-1];l&&e<=l[1]+1?l[1]=Math.max(l[1],c):n.push([e,c])}return n}function M(o,t,s){const n=new Set,e=t==="col"?H-1:z-1;for(const c of s.ranges){const[l,r]=S(t,c),i=t==="col"?o.maxCol:o.maxRow,f=r>=e?Math.max(l,i):r;for(let d=l;d<=f;d++)n.add(d)}return[...n]}function D(o,t,s,n){const e=[];let c=!1;for(const l of n.ranges){if(!x(t,l))continue;const[r,i]=S(t,l);s>=r&&s<=i&&(c=!0);const f=Math.min(i,r+2e4);for(let d=r;d<=f;d++)e.push(d)}return c?e:[s]}function to(o,t,s,n){const e=D(o,t,s,n),c=o[h(t)];return{list:e,saved:c.reshaped(),starts:e.map(l=>c.sizeOf(l))}}function eo(o,t,s,n){const e=o[h(t)];for(const c of s.group.list)e.isHidden(c)&&e.setHidden(c,!1),e.setSize(c,n)}function no(o,t){const{book:s}=o,n=s.sheet,e=t.type==="colResize"?"col":"row",c=h(e),l=n[c],{list:r,starts:i,saved:f}=t.group;if(!A(s,e,()=>{r.forEach((u,m)=>{l.sizeOf(u)===0&&!l.isHidden(u)&&(i[m]>0&&l.setSize(u,i[m]),l.setHidden(u,!0))});const a=g(n,c,f);return e==="col"?k(o,r,a):a})){X(o,t);return}w(o,e),e==="col"&&s.collab?.changed?.()}function so(o,t,s){if(!R(o,t==="row"?"formatRows":"formatColumns"))return;const n=o.book.sheet,e=n[h(t)],c=M(n,t,o.grid.selection).filter(r=>b(n,t,r)),l=C(o.book);if(l.length>1){const r=h(t);o.book.transact("axis",()=>{const i=l.map(d=>{const a=d[r].reshaped();for(const m of c)b(d,t,m)&&(s===0?d[r].setHidden(m,!0):(d[r].setHidden(m,!1),d[r].setSize(m,s)));d.revision++,r==="cols"&&(d.colsChanged=!0);const u=g(d,r,a);return t==="col"&&d===n?k(o,c,u):u}),f=d=>()=>f(d.map(a=>a()));return f(i)}),w(o,t),t==="col"&&o.book.collab?.changed?.();return}p(o,t,()=>{for(const r of c)s===0?e.setHidden(r,!0):(e.setHidden(r,!1),e.setSize(r,s))},t==="col"?c:null)}function ro(o,t,s){if(!R(o,t==="row"?"formatRows":"formatColumns"))return;const n=o.book.sheet,e=n[h(t)];p(o,t,()=>{for(const c of o.grid.selection.ranges){const[l,r]=S(t,c);if(s)for(let i=l;i<=r;i++)e.setHidden(i,!0);else if(e.hiddenSizes)for(const i of[...e.hiddenSizes.keys()])i<l||i>r||t==="row"&&n.filteredRows?.has(i)||e.setHidden(i,!1)}})}function W(o,t){const{book:s,commands:n,grid:e}=o,c=s.sheet,l=M(c,t,e.selection);if(t==="row"){n.fitAxis("row",l);return}const r=e.selection.ranges[e.selection.ranges.length-1];n.fitAxis("col",l,x("col",r)?null:r)}const E=o=>o<=5?0:Math.round((o-5)/6*100)/100,L=o=>o<=0?0:Math.round(o*6+5);function N(o){const{book:t,grid:s}=o,n=t.sheet;F(o,"Standard Width","Standard column width:",E(n.cols.defaultSize),0,255,e=>{const c=C(t);t.transact("axis",()=>{const l=c.map(i=>{const f=i.cols;return i.cols=f.reshaped(f.count,Math.max(1,L(e))),i.standardWidthChanged=!0,g(i,"cols",f)}),r=i=>()=>r(i.map(f=>f()));return r(l)}),w(o,"col"),s.invalidate()})}function co(o){const t=o.commands;return{items:[["Row Height…",()=>y(o,"row")],["AutoFit Row Height",()=>W(o,"row")],null,["Column Width…",()=>y(o,"col")],["AutoFit Selection",()=>W(o,"col")],["Standard Width…",()=>N(o)],null,["Hide & Unhide",()=>{},{items:()=>({items:[["Hide Rows",()=>t.setHidden("row",!0)],["Hide Columns",()=>t.setHidden("col",!0)],null,["Unhide Rows",()=>t.setHidden("row",!1)],["Unhide Columns",()=>t.setHidden("col",!1)]]})}],null,["Header Color…",()=>U(o)],["Format Cells…",()=>O(o),{kbd:"⌘1"}]]}}function X(o,t){const s=o.book.sheet,n=t.type==="colResize"?"col":"row";s[h(n)]=t.group.saved,s.revision++;for(const[e,c]of t.sizing??[])I(s,n,e,c);o.objects?.geometryChanged?.(),o.grid.invalidate()}export{p as axisStep,b as canResize,X as cancelAxisDrag,L as charsToWidth,to as dragGroup,eo as dragSize,no as endAxisDrag,W as fitSelected,co as formatMenu,ro as hideSelected,N as openStandardWidth,D as selectedAround,oo as selectedSpans,so as setSelectedSize,E as widthToChars};
|
package/cells/block.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EMPTY as M,FORMULA as g,SPILL as R}from"../core/sheet.js";import{MAX_COLS as F,MAX_ROWS as I}from"../core/address.js";import{formulaText as A}from"../core/formula-refs.js";import{CellLog as C}from"../core/workbook.js";const L=t=>t.r0===0&&t.r1===I-1,O=t=>t.c0===0&&t.c1===F-1,P=(t,n)=>t.r0<=n.r1&&t.r1>=n.r0&&t.c0<=n.c1&&t.c1>=n.c0,U=(t,n)=>t.r0>=n.r0&&t.r1<=n.r1&&t.c0>=n.c0&&t.c1<=n.c1,_=(t,n)=>t.r0===n.r0&&t.r1===n.r1&&t.c0===n.c0&&t.c1===n.c1,z=(t,n,s)=>t>=s.r0&&t<=s.r1&&n>=s.c0&&n<=s.c1;function E(t,n){const s=t.selectedSheets?.size>1?t.selectedSheets:[t.sheet];for(const e of s)if(!(!e.spills||e.protection&&e!==t.sheet)){for(const r of e.spills.values())if(r.fixed&&n.some(o=>P(o,r))&&!n.some(o=>U(r,o)))return!0}return!1}function H(t,n){return{r0:t.r0,c0:t.c0,r1:L(t)?Math.min(t.r1,Math.max(n.maxRow,t.r0)):t.r1,c1:O(t)?Math.min(t.c1,Math.max(n.maxCol,t.c0)):t.c1}}function Y(t,n){const s=new Int32Array(n-t+1);for(let e=0;e<s.length;e++)s[e]=t+e;return s}function j(t,n){for(const s of[...t.formulas.keys()])n.styles.get(t.styles[s]).hiddenFormula&&(t.kinds[s]&=~g,t.formulas.delete(s));return t}function q(t,n,s){const e=n.length,r=s.length,o=e*r,l=new Uint8Array(o),c=new Float64Array(o),i=new Uint16Array(o),u=new Uint16Array(o),S=new Map,k=t.rowStyles!==null||t.colStyles!==null;for(let p=0;p<r;p++){const x=s[p],a=t.columns[x];if(!(a===void 0&&!k))for(let d=0;d<e;d++){const h=n[d],f=d*r+p,m=a===void 0?void 0:a[h>>>10];if(m!==void 0){const y=h&1023;if(l[f]=m.kinds[y],c[f]=m.values[y],m.styles!==null&&(u[f]=m.styles[y]),l[f]&g){const w=t.formula(h,x);w&&S.set(f,{info:w,text:A(w,h,x)})}}i[f]=u[f]!==0||!k?u[f]:t.style(h,x)}}return{sheet:t,rows:n,cols:s,h:e,w:r,kinds:l,values:c,styles:i,own:u,formulas:S}}function D(t,n){const s=[],e=n.length,r=t.length;let o=null;for(let l=0;l<e;l++){const c=t[l%r],i=n[l];o!==null&&c===o.s+o.n&&i===o.t+o.n?o.n++:(o={s:c,t:i,n:1},s.push(o))}return s}function G(t,n,s){const e=[];for(const r of t)for(const o of n){const l=s?{r0:o.s,r1:o.s+o.n-1,c0:r.s,c1:r.s+r.n-1}:{r0:r.s,r1:r.s+r.n-1,c0:o.s,c1:o.s+o.n-1};e.push({source:l,target:{r0:r.t,r1:r.t+r.n-1,c0:o.t,c1:o.t+o.n-1},transpose:s})}return e}function J(t,n){const{source:s,target:e}=n;return n.transpose?{r0:e.r0+t.c0-s.c0,r1:e.r0+t.c1-s.c0,c0:e.c0+t.r0-s.r0,c1:e.c0+t.r1-s.r0}:{r0:e.r0+t.r0-s.r0,r1:e.r0+t.r1-s.r0,c0:e.c0+t.c0-s.c0,c1:e.c0+t.c1-s.c0}}function K(t){let n=1/0,s=1/0,e=-1,r=-1;for(const o of t)o.r0<n&&(n=o.r0),o.c0<s&&(s=o.c0),o.r1>e&&(e=o.r1),o.c1>r&&(r=o.c1);return{r0:n,c0:s,r1:e,c1:r}}function W(t){const n=t.filter(Boolean);return s=>{const e=[];for(let r=n.length-1;r>=0;r--)e.push(n[r](s));return W(e)}}class N{constructor(n,s){this.book=n,this.sheet=s,this.log=new C}save(n,s){this.log.push(this.sheet,n,s)}undo(){const{book:n,sheet:s,log:e}=this;if(e.count===0)return null;const r=o=>()=>{const l=new C;for(let c=o.count-1;c>=0;c--){const i=o.rows[c],u=o.cols[c];l.push(s,i,u),s.setCell(i,u,o.kinds[c],o.values[c]),s.setStyle(i,u,o.styles[c]),s.setFormula(i,u,o.kinds[c]&g?o.formulas.get(c):null)}return s.revision++,n.engine?.cellsChanged(s,o.rows,o.cols,o.count),r(l)};return this.notify(),r(e)}notify(){const{log:n,sheet:s,book:e}=this;s.revision++,e.engine?.cellsChanged(s,n.rows,n.cols,n.count)}}function Q(t){const n=new WeakSet,s=new WeakSet;return t.columns=t.columns.slice(),{sheet:t,saveCell(e,r){let o=t.columns[r];if(o===void 0)return;n.has(o)||(o=o.slice(),t.columns[r]=o,n.add(o));const l=e>>>10,c=o[l];if(c===void 0||s.has(c))return;const i={kinds:c.kinds.slice(),values:c.values.slice(),styles:c.styles?c.styles.slice():null};o[l]=i,s.add(i)}}}export{M as EMPTY,N as ForeignLog,R as SPILL,W as allUndo,K as boundsOf,z as cellInRect,E as changesPartOfArray,Q as cowTx,A as formulaText,Y as indexRange,L as isWholeCols,O as isWholeRows,J as mapRect,q as readBlock,U as rectInside,G as rectPairs,P as rectsTouch,_ as sameRect,D as segmentsOf,H as usedPart,j as withoutHiddenFormulas};
|
package/cells/book-css.js
CHANGED
|
@@ -167,8 +167,8 @@ const r=`
|
|
|
167
167
|
#app.bk-fx-expanded #formula-input { height: 72px; }
|
|
168
168
|
|
|
169
169
|
.bk-note { position: absolute; z-index: 6; border: 1px solid #808080; background: #ffffe1; color: #000; box-shadow: 1px 2px 6px rgba(0, 0, 0, 0.3); padding: 2px 3px; white-space: pre-wrap; overflow: hidden; cursor: move; font-size: 10px; line-height: 1.25; }
|
|
170
|
-
.bk-note-edit { padding: 4px 5px; border-style: dashed !important; }
|
|
171
|
-
.bk-note-text { display: block; width: 100%; height: 100%; resize: none; outline: 0; padding: 0; background: transparent; color: inherit; cursor: text; user-select: text; }
|
|
170
|
+
.bk-note-edit { display: flex; flex-direction: column; padding: 4px 5px; border-style: dashed !important; }
|
|
171
|
+
.bk-note-text { flex: 1; min-height: 0; display: block; width: 100%; height: 100%; resize: none; outline: 0; padding: 0; background: transparent; color: inherit; cursor: text; user-select: text; }
|
|
172
172
|
.bk-note-body { height: 100%; overflow: hidden; pointer-events: none; }
|
|
173
173
|
.bk-note-grip { position: absolute; right: 0; bottom: 0; width: 8px; height: 8px; cursor: nwse-resize; background: linear-gradient(135deg, transparent 50%, #808080 50%); }
|
|
174
174
|
.bk-mentions { position: fixed; z-index: 50; min-width: 150px; max-height: 40vh; overflow-y: auto; padding: 5px; border-radius: 8px; background: var(--menu); color: var(--ink); box-shadow: var(--shadow); }
|
package/cells/cell-defaults.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BOOL as
|
|
1
|
+
import{BOOL as m,EMPTY as v,ERR as z,ERRORS as T,NUM as k,STR as g}from"../core/sheet.js";import{registerSparseMap as E,sparseKey as C}from"../core/sparse.js";import{registerSection as Y}from"./sections.js";E("cellDefaults");const y=16384;function O(e,r,s,f,o){if(o.f===void 0)return typeof o.v=="number"?{kind:k,value:o.v}:typeof o.v=="boolean"?{kind:m,value:o.v?1:0}:{kind:g,value:e.strings.add(String(o.v))};const{engine:n}=e;if(!n)return{kind:v,value:0};try{const l=n.template(o.f,s,f).fn(s,f,r),t=l?.sheet?n.refAuto(l,s,f):l;return typeof t=="number"?{kind:k,value:t}:typeof t=="boolean"?{kind:m,value:t?1:0}:typeof t=="string"?{kind:g,value:e.strings.add(t)}:t&&t.code!==void 0?{kind:z,value:Math.max(0,T.indexOf(t.code))}:{kind:v,value:0}}catch{return{kind:v,value:0}}}function B(e,r,s,f,o,n,l,t,i,a,u){const{book:p,dpr:M}=e;for(const[x,R]of s.cellDefaults){const c=Math.floor(x/y),d=x-c*y;if(c<o||c>n||d<l||d>t||s.kind(c,d)!==0)continue;const{kind:D,value:S}=O(p,s,c,d,R);if(D===v)continue;const b=Math.round(f.x*M+(e.displayCols.offsetOf(d)-f.originX)*i),A=Math.round(f.y*M+(s.rows.offsetOf(c)-f.originY)*i),h=Math.round(e.displayCols.sizeOf(d)*i),w=Math.round(s.rows.sizeOf(c)*i);h>0&&w>0&&e._paintText(r,c,d,D,S,b,A,h,w,i,l,t,a,u)}}function H(e,r,s){const{book:f,grid:o}=e,n=f.sheet;f.guardHint={ranges:r},f.transact("entry",()=>{const l=n.cellDefaults??null,t=new Map(l??[]);for(const a of r)for(let u=a.r0;u<=Math.min(a.r1,a.r0+1e5);u++)for(let p=a.c0;p<=Math.min(a.c1,a.c0+1e3);p++)s===void 0?t.delete(C(u,p)):t.set(C(u,p),s);n.cellDefaults=t.size>0?t:null,n.cellTypesChanged=!0;const i=a=>()=>{const u=n.cellDefaults;return n.cellDefaults=a,n.cellTypesChanged=!0,i(u)};return i(l)}),o.invalidate()}function I(e){for(const r of e.sheets){if(!r.cellDefaults)continue;const s=new Map;for(const[f,o]of r.cellDefaults){const n=Math.floor(f/y),l=f-n*y;if(r.kind(n,l)!==0)continue;const t=O(e,r,n,l,o);t.kind!==v&&(r._ensure(n,l),n>r.maxRow&&(r.maxRow=n),l>r.maxCol&&(r.maxCol=l),s.set(f,t))}r.defaultsForSave=s.size>0?s:null}}const F=e=>typeof e=="number"||typeof e=="boolean"||typeof e=="string";Y("cellDefaults",{sheet:{save(e){return e.cellDefaults?.size>0?[...e.cellDefaults]:void 0},load(e,r,s){if(!Array.isArray(r))return;const f=r.filter(o=>Array.isArray(o)&&Number.isInteger(o[0])&&o[1]&&(typeof o[1].f=="string"||F(o[1].v)));e.cellDefaults=f.length>0?new Map(f):null;for(const[o,n]of f){const l=Math.floor(o/y),t=o-l*y,i=e.kind(l,t)&7;if(i===v)continue;(n.f!==void 0||(i===k?e.value(l,t)===n.v:i===g?s.strings.get(e.value(l,t))===String(n.v):i===m))&&!(e.kind(l,t)&8)&&e.setCell(l,t,0,0)}}}});export{O as defaultValueAt,B as paintCellDefaults,I as prepareDefaultsForSave,H as setCellDefaults};
|