@allyhub/sdk 0.16.0 → 0.17.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/CHANGELOG.md +13 -0
- package/dist/node_modules/@allyhub/audio/dist/index.d.ts +1 -0
- package/dist/node_modules/@allyhub/audio/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/audio/dist/place.d.ts +26 -0
- package/dist/node_modules/@allyhub/audio/dist/place.js +2 -0
- package/dist/node_modules/@allyhub/audio/package.json +1 -1
- package/dist/node_modules/@allyhub/chart/package.json +1 -1
- package/dist/node_modules/@allyhub/diagnostics/package.json +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/slides.d.ts +15 -3
- package/dist/node_modules/@allyhub/formats/dist/data/slides.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/items.d.ts +40 -7
- package/dist/node_modules/@allyhub/formats/dist/items.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/schemas.d.ts +4 -0
- package/dist/node_modules/@allyhub/formats/package.json +1 -1
- package/dist/node_modules/@allyhub/image-draw/dist/stage.js +1 -1
- package/dist/node_modules/@allyhub/image-draw/package.json +1 -1
- package/dist/node_modules/@allyhub/image-measure/package.json +1 -1
- package/dist/node_modules/@allyhub/image-sdk/package.json +1 -1
- package/dist/node_modules/@allyhub/measure/package.json +1 -1
- package/dist/node_modules/@allyhub/ooxml/package.json +1 -1
- package/dist/node_modules/@allyhub/piece/dist/layer.d.ts +15 -0
- package/dist/node_modules/@allyhub/piece/dist/page/index.d.ts +1 -0
- package/dist/node_modules/@allyhub/piece/dist/page/index.js +1 -1
- package/dist/node_modules/@allyhub/piece/dist/page/runtimes.d.ts +9 -0
- package/dist/node_modules/@allyhub/piece/dist/page/runtimes.js +2 -0
- package/dist/node_modules/@allyhub/piece/dist/source.d.ts +51 -10
- package/dist/node_modules/@allyhub/piece/dist/source.js +1 -1
- package/dist/node_modules/@allyhub/piece/package.json +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/account.d.ts +0 -6
- package/dist/node_modules/@allyhub/protocol/dist/account.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/events.d.ts +39 -0
- package/dist/node_modules/@allyhub/protocol/dist/events.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/frame.d.ts +3 -0
- package/dist/node_modules/@allyhub/protocol/dist/frame.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/kinds.d.ts +30 -0
- package/dist/node_modules/@allyhub/protocol/dist/kinds.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/tools.d.ts +6 -0
- package/dist/node_modules/@allyhub/protocol/dist/tools.js +1 -1
- package/dist/node_modules/@allyhub/protocol/package.json +1 -1
- package/dist/node_modules/@allyhub/runtimes/package.json +1 -1
- package/dist/node_modules/@allyhub/scenery/package.json +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/coerce.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/engine.d.ts +12 -0
- package/dist/node_modules/@allyhub/sheet/dist/calc/engine.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/functions/criteria.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/functions/date.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/functions/dynamic.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/functions/info.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/functions/logical.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/functions/lookup.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/functions/text.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/formula/parse.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/charts.d.ts +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/charts.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/import.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.js +2 -2
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/write.js +1 -1
- package/dist/node_modules/@allyhub/sheet/package.json +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/animation.d.ts +10 -0
- package/dist/node_modules/@allyhub/slides-core/dist/animation.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/api.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/components.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/model.d.ts +3 -1
- package/dist/node_modules/@allyhub/slides-core/dist/resolve.d.ts +5 -0
- package/dist/node_modules/@allyhub/slides-core/dist/resolve.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/package.json +1 -1
- package/dist/node_modules/@allyhub/video-core/package.json +1 -1
- package/dist/node_modules/@allyhub/video-sdk/dist/free.d.ts +1 -1
- package/dist/node_modules/@allyhub/video-sdk/package.json +1 -1
- package/docs/docs.md +11 -0
- package/docs/layers.md +2 -0
- package/docs/slides.md +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{SHEET_FILE as ie,SHEET_NOTE_AUTHOR as le,SHEET_PICTURE_HEIGHT as W,SHEET_SEPARATOR as fe}from"@allyhub/formats";import{cellName as $,columnLetter as M,contains as z,overlaps as R,rangeName as v,readAddress as ae,readArea as B}from"../address.js";import{rectangles as O}from"../api/rectangles.js";import{chartAfter as ce}from"../chart.js";import{analyse as ue}from"../calc/analyse.js";import{ITERATION_DEFAULTS as he}from"../calc/engine.js";import{FUNCTIONS as de}from"../calc/functions/index.js";import{checkWorkbook as me}from"../check.js";import{writeCsv as pe}from"@allyhub/formats";import{pictureSize as we}from"../files.js";import{isDateCode as N}from"../format.js";import{moveFormula as ge,relativeKey as ke}from"../formula/move.js";import{printFormula as S,sheetPrefix as U}from"../formula/print.js";import{mapNode as V,walk as I}from"../formula/walk.js";import{CellError as _,isoOfSerial as be,readTyped as H,writeTyped as j}from"../values.js";import{joinedRuns as ye,plainRuns as $e}from"../rich.js";import{runsOver as xe}from"./runs.js";import{FormulaCell as q,validName as J}from"../workbook.js";import{writeYaml as Le}from"../write.js";import{readFileFormula as ve}from"./formula.js";import{hasDate as K}from"./numfmt.js";import{placesLine as A,readXlsx as Se}from"./read.js";import{LISTS_SHEET as Ce}from"./write.js";const Y=100,Ee=.5,Z=1462,X=64,G=1e4;export const COMPARE_TOLERANCE=1e-9;const Q=f=>f.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/gu,"")||"rows",b=f=>{for(const e in f)if(Object.hasOwn(f,e))return!1;return!0},F=(f,e)=>`${String(f)} ${e}${f===1?"":"s"}`,C=f=>({row:f.row,col:f.col});function ee(f){return f===""||f.length>255||/^[/\\]|^[A-Za-z]:|\\|\0/u.test(f)?!1:f.split("/").every(e=>e!==""&&e!=="."&&e!=="..")}class Me{cells;starts;first;constructor(e){let o=!0;for(let t=1;t<e.length&&o;t++){const s=e[t-1],l=e[t];s&&l&&(l.row<s.row||l.row===s.row&&l.col<=s.col)&&(o=!1)}if(!o){e.sort((t,s)=>t.row-s.row||t.col-s.col);for(let t=e.length-1;t>0;t--){const s=e[t-1],l=e[t];l&&s?.row===l.row&&s.col===l.col&&e.splice(t-1,1)}}this.cells=e;const n=e[0]?.row??0,i=e[e.length-1]?.row??-1;this.first=n,this.starts=new Int32Array(Math.max(0,i-n+2));let r=0;for(let t=0;t<this.starts.length;t++){for(;r<e.length&&(e[r]?.row??0)<n+t;)r++;this.starts[t]=r}}get(e,o){const n=e-this.first;if(n<0||n>=this.starts.length-1)return;let i=this.starts[n]??0,r=(this.starts[n+1]??0)-1;for(;i<=r;){const t=i+r>>1,s=this.cells[t];if(!s)return;if(s.col===o)return s;s.col<o?i=t+1:r=t-1}}}class te{list=[];add(e){this.list.push(e)}has(e,o){for(const n of this.list)if(z(n,e,o))return!0;return!1}}function oe(f,e){const o=e.toLowerCase();return V(f,n=>n.kind!=="structured"||n.table?.toLowerCase()!==o?n:Object.fromEntries(Object.entries(n).filter(([i])=>i!=="table")))}function Oe(f){const e=new Map;for(const n of f.sheets)for(const i of n.tables)i.totals>0&&e.set(i.name.toLowerCase(),{t:i,sheet:n.name});if(e.size===0)return;const o=(n,i)=>{const r=i.table===void 0?void 0:e.get(i.table.toLowerCase());if(!r||i.thisRow)return;const{t}=r,s=i.sections,l=s.includes("#All");if(!l&&!s.includes("#Totals"))return;const a=y=>t.columns.findIndex(x=>x.name.toLowerCase()===y.toLowerCase()),[c,u]=i.columns,h=c===void 0?0:a(c),p=c===void 0?t.columns.length-1:u===void 0?h:a(u);if(h<0||p<0)return;const m=l?t.ref.top:s.includes("#Data")?t.ref.top+t.headers:s.includes("#Headers")?t.ref.top:t.ref.bottom-t.totals+1,w=t.ref.bottom,d=t.ref.left+Math.min(h,p),g=t.ref.left+Math.max(h,p),k=m!==w||d!==g;return{kind:"ref",...r.sheet===n?{}:{sheet:r.sheet},col:{index:d,abs:!0},row:{index:m,abs:!0},...k?{col2:{index:g,abs:!0},row2:{index:w,abs:!0}}:{},range:k}};for(const n of f.sheets)for(const i of n.cells)i.node&&(i.node=V(i.node,r=>r.kind==="structured"?o(n.name,r)??r:r.kind==="unary"&&r.op==="@"&&r.arg.kind==="ref"&&!r.arg.range?r.arg:r))}const _e=1e3;function ne(f){return f.headers===0?"has no header row":f.columns.length!==f.ref.right-f.ref.left+1||!J(f.name)?"cannot be held as a table":new Set(f.columns.map(e=>e.name.toLowerCase())).size===f.columns.length?void 0:"has two columns of one name"}function D(f,e,o){let n;const i=new Set;I(f,t=>{t.kind==="call"&&(t.name==="LET"||t.name==="LAMBDA")&&t.args.forEach(s=>{s.kind==="name"&&i.add(s.name.toLowerCase())})});const r=t=>i.has(t)||o===void 0||o.names.has(t)||o.tables.has(t);return I(f,t=>{n===void 0&&(t.kind==="call"&&!de.has(t.name)&&(r(t.written.toLowerCase())||(n=`no function ${t.name}`)),t.kind==="name"&&!r(t.name.toLowerCase())&&(n=`no name ${t.name}`),t.kind==="structured"&&t.table!==void 0&&!r(t.table.toLowerCase())&&(n=`no table ${t.table}`),(t.kind==="ref"||t.kind==="name"||t.kind==="error")&&t.sheet!==void 0&&(t.sheet.startsWith("[")?n="it reads another workbook":e.has(t.sheet.toLowerCase())||(n=`no sheet ${t.sheet}`)))}),n}function Ae(f){const e=new Set(f.book.sheets.map(o=>o.name.toLowerCase()));for(const o of f.book.sheets){const n=new Map,i=(t,s)=>{const l=n.get(s),a=$(t);l?l.push(a):n.set(s,[a])},r=[];for(const t of o.cells){if(t.unread!==void 0){i(t,/^\[|[!']\[|\[\d+\]/u.test(t.unread)?"it reads another workbook":`it could not be read: ${t.unread}`);continue}if(!t.node)continue;const s=D(t.node,e,f);s!==void 0?(delete t.node,i(t,s)):(f.carried.set(t,o),t.array&&v(t.array)!==$(t)&&r.push(t))}Te(f,o,r);for(const[t,s]of n)f.lost.push(`${o.name}: ${F(s.length,"formula")} kept as ${s.length===1?"its value":"their values"}, as ${t} (${A(s)})`)}}function Te(f,e,o){if(o.length===0)return;const n=new Set;for(const i of o){const{array:r}=i;if(r)for(const t of e.cells)t!==i&&!t.node&&z(r,t.row,t.col)&&n.add(t)}e.cells=e.cells.filter(i=>!n.has(i));for(const i of n)f.spilled.set(i,e)}function E(f,e){const{value:o}=e;if(!f.book.date1904||typeof o!="number")return o;const n=f.book.looks[e.style]?.format;return N(n)&&n!==void 0&&K(n)?o+Z:o}function P(f,e){if(typeof f!="number"||e===void 0||!N(e)||!K(e)||f<1)return;const o=be(f);return H(o).value===f?o:void 0}const ze=(f,e)=>P(f,e)??j(f??null);function se(f,e){const o=P(f,e);return o!==void 0?o:f==null?null:typeof f=="number"||typeof f=="boolean"?f:j(f)}function Re(f){const e=[];for(let s=0;s<f.length;s++){const l=f[s];if(!l)continue;const a=e[e.length-1];a?.row===l.row&&a.right===l.col-1?(a.right=l.col,a.last=s):e.push({row:l.row,left:l.col,right:l.col,first:s,last:s})}const o=e.map((s,l)=>l),n=s=>{let l=s;for(;o[l]!==l;){const a=o[o[l]??l]??l;o[l]=a,l=a}return l};let i=0,r=0;for(let s=0;s<e.length;s++){const l=e[s];if(l){s>0&&e[s-1]?.row!==l.row&&(i=e[s-1]?.row===l.row-1?r:s,r=s);for(let a=i;a<r;a++){const c=e[a];c?.row===l.row-1&&c.right>=l.left&&c.left<=l.right&&(o[n(s)]=n(a))}}}const t=new Map;return e.forEach((s,l)=>{const a=n(l),c=t.get(a),u=s.right-s.left+1;c?(c.box.top=Math.min(c.box.top,s.row),c.box.bottom=Math.max(c.box.bottom,s.row),c.box.left=Math.min(c.box.left,s.left),c.box.right=Math.max(c.box.right,s.right),c.count+=u,c.runs.push(l)):t.set(a,{box:{top:s.row,bottom:s.row,left:s.left,right:s.right},count:u,runs:[l]})}),[...t.values()].map(s=>({box:s.box,count:s.count,cells:()=>s.runs.flatMap(l=>{const a=e[l];return a?f.slice(a.first,a.last+1):[]})}))}const re=f=>JSON.stringify(f);class Ne{ctx;read;cells;inTables=new te;columnLooks=new Map;rowLooks=new Map;lookDone=new te;tables=[];areas=[];filtered=[];ownLooks=new Map;fileColumns=new Map;pictured=new Map;over=[];keys=new Map;constructor(e,o){this.ctx=e,this.read=o,this.cells=new Me(o.cells)}at(e,o){return this.cells.get(e,o)}look(e){return this.ctx.book.looks[e.style]??{}}runs(e){if(!e.runs||e.node||typeof e.value!="string")return;const o=ye(xe(e.runs,this.look(e),this.ctx.book.font));return o.length===0||$e(o)?void 0:o}code(e){return this.look(e).format}text(e){return e.node?S(e.node):ze(E(this.ctx,e),this.code(e))}baseLooks(){const{read:e}=this,{looks:o}=this.ctx.book;let n=-1;for(const r of e.cells)r.col>n&&(n=r.col);for(const r of e.columns){if(r.style===void 0)continue;const t=o[r.style];if(!(!t||b(t)))for(let s=r.min;s<=Math.min(r.max,n);s++)this.columnLooks.set(s,t)}for(const r of e.rows){const t=r.style===void 0?void 0:o[r.style];t&&!b(t)&&this.rowLooks.set(r.row,t)}const i=(r,t)=>{for(const s in t)if(!(s in r))return!1;return!0};for(const r of e.cells){const t=this.look(r),s=this.columnLooks.get(r.col);s&&!i(t,s)&&this.columnLooks.delete(r.col);const l=this.rowLooks.get(r.row);l&&!i(t,l)&&this.rowLooks.delete(r.row)}}ownLook(e){const o=this.columnLooks.get(e.col),n=this.rowLooks.get(e.row),i=this.look(e),r=i.format!==void 0&&N(i.format);if(!o&&!n&&!r){let a=this.ownLooks.get(e.style);return a||(a={look:i,key:re(i)},this.ownLooks.set(e.style,a)),a}const t={...o,...n},s={};for(const[a,c]of Object.entries(i))JSON.stringify(c)!==JSON.stringify(t[a])&&(s[a]=c);const l=s.format;if(typeof l=="string"){const a=e.node?void 0:P(E(this.ctx,e),l);a!==void 0&&H(a).format===l&&delete s.format}return{look:s,key:re(s)}}keyOf(e,o){if(e.key!==void 0)return e.key;const n=ke(o,e.row,e.col),i=this.keys.get(n);return i!==void 0?e.key=i:(this.keys.set(n,n),e.key=n)}columnFormula(e,o,n){const i=new Map,r=n-o+1;for(let s=o;s<=n;s++){const l=this.at(s,e);if(!l||l.value===void 0&&!l.node||l.value===null&&!l.node)return;if(!l.node)continue;const a=this.keyOf(l,l.node),c=i.get(a);c?c.n+=1:i.set(a,{n:1,cell:l})}let t;for(const s of i.values())(!t||s.n>t.n)&&(t=s);return t&&t.n*2>r?t.cell:void 0}csv(e,o){const n=[];for(let i=0;i<e;i+=G){const r=[];for(let t=i;t<Math.min(e,i+G);t++)r.push(o(t));n.push(pe(r))}return n.join("")}table(e){const{read:o,ctx:n}=this,i=d=>n.lost.push(`${o.name}: table ${e.name} ${d}`),r=e.ref.right-e.ref.left+1,t=ne(e);if(t!==void 0)return i(`${t}, so its cells are kept and it is no table`),!1;const s=e.ref.top,l=s+1;let a=e.ref.bottom-e.totals;if(e.totals===0){let d=s;for(const g of o.cells)g.col>=e.ref.left&&g.col<=e.ref.right&&g.row>d&&(d=g.row);a-d>_e&&(i(`runs ${String(a-d)} empty rows past what it holds, which are left out`),a=d)}e.totals>0&&i("has a totals row, kept as plain cells under it");const c=e.columns.map((d,g)=>a>=l?this.columnFormula(e.ref.left+g,l,a):void 0),u=d=>{const g=c[d];if(!g)return!1;for(let k=l;k<=a;k++)if(this.at(k,e.ref.left+d)?.key!==g.key)return!1;return!0};let h=r;for(;h>1&&u(h-1);)h-=1;const p={},m=this.path(e.name);n.files.set(m,this.csv(a-l+2,d=>{if(d===0)return e.columns.slice(0,h).map(y=>y.name);const g=l+d-1,k=[];for(let y=0;y<h;y++){const x=this.at(g,e.ref.left+y),L=c[y];x?L&&x.key===L.key?k.push(""):x.node?k.push(S(oe(x.node,e.name))):k.push(this.text(x)):k.push("")}return k})),this.inTables.add({...e.ref,bottom:a}),e.columns.forEach((d,g)=>{const k=e.ref.left+g,y=this.columnLook(k,l,a),x=c[g];x?.node&&(y.formula=S(oe(ge(x.node,l-x.row,0),e.name)));const L=this.fileColumns.get(k);L!==void 0&&l<=a&&(y.files=L===W?!0:{height:L}),b(y)||(p[d.name]=y)});const w=new Map;for(const[d,g]of e.filter?.columns??[]){const k=e.columns[d]?.name;k!==void 0&&w.set(k,g)}return(e.filter?.unread??0)>0&&i(`has ${F(e.filter?.unread??0,"filter")} by condition, its rows left as they were hidden`),this.tables.push({name:e.name,at:$({row:s,col:e.ref.left}),rows:m,...e.style!==void 0&&e.style!=="TableStyleMedium2"?{style:e.style}:{},...e.options,...b(p)?{}:{columns:p},...e.filter===void 0?{filter:!1}:w.size>0?{filter:{columns:Object.fromEntries(w)}}:{}}),e.filter?.unread===0&&e.filter.columns.size>0&&this.filtered.push({...e.ref,bottom:a}),this.areas.push({...e.ref,bottom:a}),!0}columnLook(e,o,n){let i,r={};for(let t=o;t<=n;t++){const s=this.at(t,e),l=s?this.ownLook(s):{look:{},key:"{}"};if(i===void 0)i=l.key,r=l.look;else if(i!==l.key)return{}}return b(r)?{}:(this.lookDone.add({top:o,bottom:n,left:e,right:e}),{...r})}path(e){const o=Q(e);let n=`${o}.csv`;for(let i=2;this.ctx.files.has(n)||this.ctx.taken(n);i++)n=`${o}-${String(i)}.csv`;return n}loose(){const e=[],o=[];for(const n of this.read.cells)this.inTables.has(n.row,n.col)||(n.node?e.push(n):n.value!==void 0&&n.value!==null&&o.push(n));return{formulas:e,typed:o}}blockAreas(e,o){const n=[],i=O(o.map(C)),r=s=>!n.some(l=>R(l,s))&&!this.areas.some(l=>R(l,s))&&!i.some(l=>R(l,s)),t=s=>(s.bottom-s.top+1)*(s.right-s.left+1);for(const s of Re(e)){const{box:l}=s;if(!(t(l)<Y)){if(s.count/t(l)>=Ee&&r(l)){n.push(l);continue}for(const a of O(s.cells().map(C)))t(a)>=Y&&r(a)&&n.push(a)}}return n.sort((s,l)=>s.top-l.top||s.left-l.left)}cells_(e){const{formulas:o,typed:n}=this.loose(),i=new Map;for(const c of n){const u=this.runs(c);u&&i.set(c,u)}const r=this.read.cells.filter(c=>this.inTables.has(c.row,c.col)&&this.runs(c)!==void 0);r.length>0&&this.ctx.lost.push(`${this.read.name}: ${F(r.length,"cell")} of rich text in a table, kept as plain text (${A(r.map(c=>$(c)))})`);const t=this.blockAreas(n.filter(c=>!i.has(c)),[...o,...i.keys()]),s=c=>t.some(u=>z(u,c.row,c.col));t.length>0&&(e.blocks=t.map(c=>{const u=this.path(this.read.name);return this.ctx.files.set(u,this.csv(c.bottom-c.top+1,h=>{const p=[];for(let m=c.left;m<=c.right;m++){const w=this.at(c.top+h,m);p.push(w?this.text(w):"")}return p})),{at:$({row:c.top,col:c.left}),rows:u}}));const l=[],a=new Map;for(const c of o){if(!c.node)continue;const u=this.keyOf(c,c.node),h=a.get(u);h?h.push(c):a.set(u,[c])}for(const c of a.values())for(const u of O(c.map(C))){const h=this.at(u.top,u.left);h?.node&&l.push([{row:u.top,col:u.left},v(u),S(h.node)])}for(const c of n){if(t.length>0&&s(c))continue;const u=i.get(c);l.push([C(c),$(c),u?{runs:u}:se(E(this.ctx,c),this.code(c))])}l.sort(([c],[u])=>c.row-u.row||c.col-u.col),l.length>0&&(e.cells=Object.fromEntries(l.map(([,c,u])=>[c,u])))}formats(e){const o=new Map,n=this.lookDone.list.length>0;for(const r of this.read.cells){if(n&&this.lookDone.has(r.row,r.col))continue;const t=this.ownLook(r);if(b(t.look))continue;const s=o.get(t.key);s?s.places.push(C(r)):o.set(t.key,{look:t.look,places:[C(r)]})}const i=[];for(const{look:r,places:t}of o.values())for(const s of O(t))i.push({range:v(s),...r});i.length>0&&(e.format=i)}columns(e){const{read:o}=this,n=new Map;let i=0;for(const t of o.cells)t.col>i&&(i=t.col);const r=[];for(const t of o.columns){if(t.width===void 0&&t.hidden!==!0&&t.level===void 0)continue;const s=t.max-Math.max(t.min,i+1)+1>X?Math.max(i,t.min+X-1):t.max;s<t.max&&r.push(`${M(s+1)}:${M(t.max)}`);const l=t.width!==void 0&&t.width<=0;for(let a=t.min;a<=s;a++)n.set(a,{...t.width===void 0||l?{}:{width:t.width},...t.hidden===!0||l?{hidden:!0}:{},...t.level===void 0?{}:{level:t.level}})}for(const[t,s]of this.columnLooks)n.set(t,{...n.get(t),...s});for(const[t,s]of this.fileColumns)this.tableColumn(t)||n.set(t,{...n.get(t),files:s===W?!0:{height:s}});n.size>0&&(e.columns=Object.fromEntries([...n.keys()].sort((t,s)=>t-s).map(t=>[M(t),n.get(t)??{}]))),r.length>0&&this.ctx.lost.push(`${o.name}: the size of columns ${A(r)}, past those that hold anything`)}tableColumn(e){return this.areas.some(o=>e>=o.left&&e<=o.right)}rows(e){const o={};for(const n of this.read.rows){const i=this.rowLooks.get(n.row),r=this.filtered.some(a=>n.row>a.top&&n.row<=a.bottom),t=n.height!==void 0&&this.pictured.get(n.row)!==n.height?n.height:void 0,s=t!==void 0&&t<=0,l={...t===void 0||s?{}:{height:t},...(n.hidden===!0||s)&&!r?{hidden:!0}:{},...n.level===void 0?{}:{level:n.level},...i};b(l)||(o[String(n.row+1)]=l)}b(o)||(e.rows=o)}assetPath(e,o){const n=t=>{const s=this.ctx.assets.get(t);return s?Ie(s,o.bytes):!this.ctx.taken(t)};if(e!==void 0&&ee(e)&&n(e))return e;const i=Q((o.name??"picture").replace(/\.[A-Za-z0-9]+$/u,""));let r=`${i}.${o.type}`;for(let t=2;!n(r);t++)r=`${i}-${String(t)}.${o.type}`;return r}pictures(){const e=this.over;for(const o of this.read.pictures){const n=this.at(o.row,o.col),i=typeof n?.value=="string"?n.value:"";if(o.y===void 0&&o.descr!==void 0&&ee(o.descr)&&i.split(fe).includes(o.descr)&&o.descr!==void 0){this.ctx.assets.set(o.descr,o.bytes),this.fileColumns.set(o.col,Math.max(this.fileColumns.get(o.col)??0,o.height)),this.pictured.set(o.row,Math.max(this.pictured.get(o.row)??0,o.height));continue}if(o.width<=0||o.height<=0){this.ctx.lost.push(`${this.read.name}: a picture of no size at ${$({row:o.row,col:o.col})}`);continue}const t=this.assetPath(o.descr,o);this.ctx.assets.set(t,o.bytes);const s=we(o.bytes),l=s?.width===o.width&&s.height===o.height;e.push({file:t,at:$({row:o.row,col:o.col}),...o.x===void 0?{}:{x:o.x},...o.y===void 0?{}:{y:o.y},...l?{}:{width:o.width,height:o.height}})}}build(){const{read:e}=this;this.baseLooks(),this.pictures();for(const n of e.tables)this.table(n);const o={name:e.name};return e.state!=="visible"&&(o.hidden=!0),e.gridlines===!1&&(o.gridlines=!1),e.tab!==void 0&&(o.tab=e.tab),e.state==="veryHidden"&&this.ctx.lost.push(`${e.name}: being very hidden; it is hidden`),e.freeze&&(e.freeze.row>0||e.freeze.col>0)&&(o.freeze=$(e.freeze)),this.tables.length>0&&(o.tables=this.tables),this.filter(o),this.columns(o),this.rows(o),this.cells_(o),e.merges.length>0&&(o.merges=e.merges.map(v)),this.formats(o),e.conditional.length>0&&(o.conditional=e.conditional),e.validations.length>0&&(o.validations=e.validations),e.charts.length>0&&(o.charts=e.charts.map(n=>this.chart(n))),this.over.length>0&&(o.pictures=this.over),b(e.links)||(o.links=e.links),e.notes.length>0&&(o.notes=Object.fromEntries(e.notes.map(n=>[n.ref,n.author===void 0||n.author===le?n.text:{text:n.text,author:n.author}]))),e.print&&(o.print=e.print),e.protect===!0&&(o.protect=!0),e.outline&&(o.outline=e.outline),o}chart(e){return ce(e,o=>{const n=this.chartReference(o.replace(/^=/u,""));return o.startsWith("=")?`=${n}`:n})}chartReference(e){const o=e.lastIndexOf("!"),i=(o<0?this.read.name:e.slice(0,o)).replace(/^'|'$/gu,"").replaceAll("''","'"),r=B(e.slice(o+1).replaceAll("$",""));if(!r)return e;const t=this.ctx.book.sheets.find(s=>s.name.toLowerCase()===i.toLowerCase());for(const s of t?.tables??[]){const l=s.ref.top+1,c=r.left===r.right&&r.top===l&&r.bottom===s.ref.bottom&&r.left>=s.ref.left&&r.left<=s.ref.right?s.columns[r.left-s.ref.left]:void 0;if(c&&this.ctx.tables.has(s.name.toLowerCase()))return`${s.name}[${c.name}]`}return`${t===this.read||o<0?"":`${e.slice(0,o)}!`}${v(r)}`}filter(e){const{filter:o}=this.read;if(!o)return;const n={};for(const[i,r]of o.columns)n[M(o.ref.left+i)]=r;e.filter={range:v(o.ref),...b(n)?{}:{columns:n}},o.unread===0&&!b(n)&&this.filtered.push(o.ref)}}const Ie=(f,e)=>f.length===e.length&&f.every((o,n)=>o===e[n]),He=new Set(["_xlnm._FilterDatabase","_xlnm.Print_Area","_xlnm.Print_Titles"]);function je(f){const e={},o=[],n=new Map,{book:i,lost:r}=f,t=new Set(i.sheets.map(u=>u.name.toLowerCase())),s=new Set,l=[];let a;const c=u=>{a=void 0;const h=Pe(u.text);if(h!==void 0)return typeof h=="string"?j(h):h;const p=ve(u.text,!0),m=p.ok?D(p.node,t):"it could not be read";if(!p.ok||m!==void 0||De(p.node)){r.push(`the name ${u.name} (${u.text})${m===void 0?"":`: ${m}`}`);return}return a=p.node,S(p.node)};for(const u of i.names){if(u.name.startsWith("_xlnm.")){He.has(u.name)||r.push(`Excel's name ${u.name}`);continue}if(/^_xl(?:fn|pm|ws|udf)/iu.test(u.name))continue;const h=u.name.toLowerCase(),p=u.sheet===void 0?"":String(u.sheet);if(!J(u.name)||f.tables.has(h)){r.push(`the name ${u.name}, which cannot be held here`);continue}if(s.has(`${p}|${h}`)){r.push(`a second name ${u.name}${p===""?"":` of ${i.sheets[u.sheet??0]?.name??""}`}`);continue}const m=c(u);if(m===void 0)continue;s.add(`${p}|${h}`),f.names.add(h);const w=u.sheet===void 0?void 0:n.get(u.sheet)??{names:{},hidden:[]},d=w?.names??e;d[u.name]=m,u.hidden===!0&&(w?.hidden??o).push(u.name),w&&u.sheet!==void 0&&n.set(u.sheet,w),a&&l.push({held:d,n:u,node:a})}for(const{held:u,n:h,node:p}of l){const m=D(p,t,{names:f.names,tables:f.tables});m!==void 0&&(u[h.name]="=#NAME?",r.push(`the name ${h.name} (${h.text}): ${m}; it holds #NAME?, as in Excel`))}return{names:e,hidden:o,sheets:n}}function Fe(f,e){const o={},n=new Map;for(const[i,r]of Object.entries(e))typeof r=="string"&&r.startsWith("=")&&n.set(r.slice(1).replaceAll("$","").toLowerCase(),i);for(const i of f.book.sheets)for(const r of i.scenarios){const t={};let s=!0;for(const{at:l,value:a}of r.cells){const c=ae(l),u=c&&i.cells.find(m=>m.row===c.row&&m.col===c.col);String(u?.value??"")!==a&&(s=!1);const h=n.get(`${U(i.name)}${l}`.toLowerCase())??n.get(l.toLowerCase()),p=H(a);h===void 0?f.lost.push(`${i.name}: scenario ${r.name}'s cell ${l}, which has no name`):t[h]=typeof p.value=="number"?p.value:a}!s&&!b(t)&&(o[r.name]={...o[r.name],...t})}return o}function De(f){let e=!1;return I(f,o=>{e||=o.kind==="error"&&o.code==="#REF!"}),e}function Pe(f){const e=f.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/u.test(e)?Number(e):/^true$/iu.test(e)?!0:/^false$/iu.test(e)?!1:/^"((?:[^"]|"")*)"$/u.exec(e)?.[1]?.replaceAll('""','"')}const We=new RegExp(`^${Ce.replace(/[.*+?^${}()|[\]\\]/gu,"\\$&")}(?: \\(\\d+\\))?$`,"u");function Be(f){const e=f.sheets.find(r=>r.state==="veryHidden"&&We.test(r.name));if(!e)return;const o=U(e.name).toLowerCase(),n=r=>{const t=r.replace(/^=/u,"");if(!t.toLowerCase().startsWith(o))return;const s=B(t.slice(o.length).replaceAll("$",""));if(!s||s.left!==s.right)return;const l=[];for(let a=s.top;a<=s.bottom;a++){const c=e.cells.find(u=>u.row===a&&u.col===s.left);l.push(typeof c?.value=="string"?c.value:"")}return l};for(const r of f.sheets)r.validations=r.validations.map(t=>{const[s]=t.formula??[],l=t.type==="list"&&typeof s=="string"?n(s):void 0;if(!l)return t;const a={...t,values:l};return delete a.formula,a});const i=f.sheets.indexOf(e);f.sheets=f.sheets.filter(r=>r!==e),f.names=f.names.flatMap(r=>r.sheet===void 0||r.sheet<i?[r]:r.sheet===i?[]:[{...r,sheet:r.sheet-1}])}const T=f=>f instanceof _?f.code:f??null,Ue=new Map([["#SPILL!","#VALUE!"],["#CALC!","#VALUE!"]]);export function sameValue(f,e,o){if(typeof f=="number"&&typeof e=="number")return f===e?!0:Math.abs(f-e)<=Math.max(Math.abs(f),Math.abs(e))*o;if(f instanceof _||e instanceof _){const n=i=>i instanceof _?Ue.get(i.code)??i.code:void 0;return n(f)===n(e)}if(f===null||e===null){const n=f??e;return n===null||n===""||n===0||n===!1}return f===e}function Ve(f,e){const o=[];for(const r of e.sheets)for(const t of r.formulas)t.shared.node&&ue(e,t.shared,r).volatile&&o.push(t);const n=new Set(o),i=[...o];for(;;){const r=i.pop();if(!r)return n;for(const t of f.readers(r.sheet,r.row,r.col))n.has(t)||(n.add(t),i.push(t))}}function qe(f){const e=f.file.iteration;return(e===void 0||e===!0?void 0:e.max_change)??he.max_change}function Je(f,e,o,n){const i={formulas:0,same:0,uncached:0,moving:0,differences:[]},r=Ve(o,e);for(const[t,s]of f.carried){if(!t.node)continue;const l=e.sheet(s.name);if(!l)continue;i.formulas+=1;const a=l.at(t.row,t.col);if(a instanceof q&&r.has(a)){i.moving+=1;continue}const c=E(f,t);if(c===void 0){i.uncached+=1;continue}const u=o.value(l,t.row,t.col);a instanceof q&&o.iterates(a)&&typeof c=="number"&&typeof u=="number"&&Math.abs(c-u)<=qe(e)||sameValue(c,u,n)?i.same+=1:i.differences.push({sheet:s.name,cell:$(t),formula:S(t.node),file:T(c),engine:T(u)})}for(const[t,s]of f.spilled){const l=e.sheet(s.name);if(!l)continue;i.formulas+=1;const a=l.spillAt(t.row,t.col);if(a&&r.has(a)){i.moving+=1;continue}const c=E(f,t),u=o.value(l,t.row,t.col);c===void 0?i.uncached+=1:sameValue(c,u,n)?i.same+=1:i.differences.push({sheet:s.name,cell:$(t),formula:a?`${$(a)}#`:"",file:T(c),engine:T(u)})}return i}function Ke(f,e){const o=new Map,n=[];for(const i of f){const r=e.find(l=>i.startsWith(`${l}: `));if(r===void 0){n.push(i);continue}const t=i.slice(r.length+2),s=o.get(t);s?s.push(r):o.set(t,[r])}for(const[i,r]of o)n.push(r.length===1?`${r[0]??""}: ${i}`:`${i}, on ${String(r.length)} sheets (${A(r)})`);return n}function Ye(f,e,o){const n=o.circularCells();if(n.length===0)return!1;const i=new Map;for(const[s,l]of f.carried)i.set(`${l.name}|${String(s.row)}|${String(s.col)}`,s);let r=0,t=0;for(const s of n){const l=i.get(`${s.sheet.name}|${String(s.row)}|${String(s.col)}`),a=l===void 0?void 0:E(f,l),c=e[s.sheet.index],u=s.shared.source.path??[];if(a===void 0||!c||u[2]!=="cells"){a!==void 0&&(t+=1);continue}const h=se(a,void 0),p=c.cells??={},m=$(s),w=p[m],d=p[String(u[3])],g=d!==null&&typeof d=="object"?d:{};p[m]=w!==null&&typeof w=="object"?{...w,start:h}:{...g,formula:s.text,start:h},r+=1}return t>0&&f.lost.push(`where ${String(t)} cells of a table or a block start iterative calculation: they start from 0`),r>0}export function importXlsx(f,e){const o=Se(f,e.zip);if(Be(o),Oe(o),o.sheets.length===0)throw new Error("It holds no sheets.");const n={book:o,taken:e.taken??(()=>!1),files:new Map,assets:new Map,lost:[...o.lost],tables:new Set(o.sheets.flatMap(m=>m.tables.filter(w=>ne(w)===void 0).map(w=>w.name.toLowerCase()))),names:new Set,carried:new Map,spilled:new Map};o.date1904&&n.lost.push(`the 1904 date system: dates are moved to the 1900 one, ${String(Z)} days on`),(o.font.name!==void 0&&o.font.name!=="Calibri"||o.font.size!==void 0&&o.font.size!==11)&&n.lost.push(`its default font, ${o.font.name??""} ${String(o.font.size??"")}`);const i=je(n);Ae(n);const r=o.sheets.map((m,w)=>{const d=new Ne(n,m).build(),g=i.sheets.get(w);return g&&!b(g.names)&&(d.names=g.names),g&&g.hidden.length>0&&(d.hidden_names=g.hidden),d}),t=Fe(n,i.names),s={title:o.title??e.name,...b(i.names)?{}:{names:i.names},...i.hidden.length>0?{hidden_names:i.hidden}:{},sheets:r,...b(t)?{}:{scenarios:t},...o.iteration===void 0?{}:{iteration:o.iteration}},l=()=>{const m=Le(s),w=new Map([[ie,m],...n.files]);return{files:w,...me({text:m,read:d=>w.get(d),exists:d=>w.has(d)||n.assets.has(d)})}};let a=l();a.calc&&Ye(n,r,a.calc)&&(a=l());const{files:c,workbook:u,calc:h,problems:p}=a;return{files:c,assets:n.assets,lost:Ke(n.lost,o.sheets.map(m=>m.name)),problems:p,compared:u&&h?Je(n,u,h,e.tolerance??COMPARE_TOLERANCE):{formulas:0,same:0,uncached:0,moving:0,differences:[]},sheets:o.sheets.length,tables:n.tables.size}}
|
|
2
|
+
import{SHEET_FILE as le,SHEET_NOTE_AUTHOR as fe,SHEET_PICTURE_HEIGHT as W,SHEET_SEPARATOR as ae}from"@allyhub/formats";import{cellName as $,columnLetter as M,contains as z,overlaps as R,rangeName as C,readAddress as ce,readArea as B}from"../address.js";import{rectangles as O}from"../api/rectangles.js";import{chartAfter as ue}from"../chart.js";import{analyse as he}from"../calc/analyse.js";import{ITERATION_DEFAULTS as de}from"../calc/engine.js";import{FUNCTIONS as me}from"../calc/functions/index.js";import{checkWorkbook as pe}from"../check.js";import{writeCsv as we}from"@allyhub/formats";import{pictureSize as ge}from"../files.js";import{isDateCode as N}from"../format.js";import{moveFormula as ke,relativeKey as be}from"../formula/move.js";import{printFormula as L,sheetPrefix as U}from"../formula/print.js";import{mapNode as V,walk as I}from"../formula/walk.js";import{CellError as _,isoOfSerial as ye,readTyped as j,writeTyped as H}from"../values.js";import{joinedRuns as $e,plainRuns as xe}from"../rich.js";import{runsOver as Le}from"./runs.js";import{FormulaCell as Z,validName as q}from"../workbook.js";import{writeYaml as ve}from"../write.js";import{readFileFormula as Ce}from"./formula.js";import{hasDate as J}from"./numfmt.js";import{placesLine as A,readXlsx as Se}from"./read.js";import{LISTS_SHEET as Ee}from"./write.js";const K=100,Me=.5,Y=1462,X=64,G=1e4;export const COMPARE_TOLERANCE=1e-9;const Q=f=>f.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/gu,"")||"rows",b=f=>{for(const e in f)if(Object.hasOwn(f,e))return!1;return!0},F=(f,e)=>`${String(f)} ${e}${f===1?"":"s"}`,S=f=>({row:f.row,col:f.col});function ee(f){return f===""||f.length>255||/^[/\\]|^[A-Za-z]:|\\|\0/u.test(f)?!1:f.split("/").every(e=>e!==""&&e!=="."&&e!=="..")}class Oe{cells;starts;first;constructor(e){let o=!0;for(let t=1;t<e.length&&o;t++){const s=e[t-1],l=e[t];s&&l&&(l.row<s.row||l.row===s.row&&l.col<=s.col)&&(o=!1)}if(!o){e.sort((t,s)=>t.row-s.row||t.col-s.col);for(let t=e.length-1;t>0;t--){const s=e[t-1],l=e[t];l&&s?.row===l.row&&s.col===l.col&&e.splice(t-1,1)}}this.cells=e;const n=e[0]?.row??0,i=e[e.length-1]?.row??-1;this.first=n,this.starts=new Int32Array(Math.max(0,i-n+2));let r=0;for(let t=0;t<this.starts.length;t++){for(;r<e.length&&(e[r]?.row??0)<n+t;)r++;this.starts[t]=r}}get(e,o){const n=e-this.first;if(n<0||n>=this.starts.length-1)return;let i=this.starts[n]??0,r=(this.starts[n+1]??0)-1;for(;i<=r;){const t=i+r>>1,s=this.cells[t];if(!s)return;if(s.col===o)return s;s.col<o?i=t+1:r=t-1}}}class te{list=[];add(e){this.list.push(e)}has(e,o){for(const n of this.list)if(z(n,e,o))return!0;return!1}}function oe(f){const e=/\.([A-Za-z0-9]+)$/u.exec(f)?.[1]?.toLowerCase();return e==="jpeg"?"jpg":e==="tif"?"tiff":e}function ne(f,e){const o=e.toLowerCase();return V(f,n=>n.kind!=="structured"||n.table?.toLowerCase()!==o||!n.thisRow&&n.columns.length===0&&n.sections.length===0?n:Object.fromEntries(Object.entries(n).filter(([i])=>i!=="table")))}function _e(f){const e=new Map;for(const n of f.sheets)for(const i of n.tables)i.totals>0&&e.set(i.name.toLowerCase(),{t:i,sheet:n.name});if(e.size===0)return;const o=(n,i)=>{const r=i.table===void 0?void 0:e.get(i.table.toLowerCase());if(!r||i.thisRow)return;const{t}=r,s=i.sections,l=s.includes("#All");if(!l&&!s.includes("#Totals"))return;const a=y=>t.columns.findIndex(x=>x.name.toLowerCase()===y.toLowerCase()),[c,u]=i.columns,h=c===void 0?0:a(c),p=c===void 0?t.columns.length-1:u===void 0?h:a(u);if(h<0||p<0)return;const m=l?t.ref.top:s.includes("#Data")?t.ref.top+t.headers:s.includes("#Headers")?t.ref.top:t.ref.bottom-t.totals+1,w=t.ref.bottom,d=t.ref.left+Math.min(h,p),g=t.ref.left+Math.max(h,p),k=m!==w||d!==g;return{kind:"ref",...r.sheet===n?{}:{sheet:r.sheet},col:{index:d,abs:!0},row:{index:m,abs:!0},...k?{col2:{index:g,abs:!0},row2:{index:w,abs:!0}}:{},range:k}};for(const n of f.sheets)for(const i of n.cells)i.node&&(i.node=V(i.node,r=>r.kind==="structured"?o(n.name,r)??r:r.kind==="unary"&&r.op==="@"&&r.arg.kind==="ref"&&!r.arg.range?r.arg:r))}const Ae=1e3;function se(f){return f.headers===0?"has no header row":f.columns.length!==f.ref.right-f.ref.left+1||!q(f.name)?"cannot be held as a table":new Set(f.columns.map(e=>e.name.toLowerCase())).size===f.columns.length?void 0:"has two columns of one name"}function D(f,e,o){let n;const i=new Set;I(f,t=>{t.kind==="call"&&(t.name==="LET"||t.name==="LAMBDA")&&t.args.forEach(s=>{s.kind==="name"&&i.add(s.name.toLowerCase())})});const r=t=>i.has(t)||o===void 0||o.names.has(t)||o.tables.has(t);return I(f,t=>{n===void 0&&(t.kind==="call"&&!me.has(t.name)&&(r(t.written.toLowerCase())||(n=`no function ${t.name}`)),t.kind==="name"&&!r(t.name.toLowerCase())&&(n=`no name ${t.name}`),t.kind==="structured"&&t.table!==void 0&&!r(t.table.toLowerCase())&&(n=`no table ${t.table}`),(t.kind==="ref"||t.kind==="name"||t.kind==="error")&&t.sheet!==void 0&&(t.sheet.startsWith("[")?n="it reads another workbook":e.has(t.sheet.toLowerCase())||(n=`no sheet ${t.sheet}`)))}),n}function Te(f){const e=new Set(f.book.sheets.map(o=>o.name.toLowerCase()));for(const o of f.book.sheets){const n=new Map,i=(t,s)=>{const l=n.get(s),a=$(t);l?l.push(a):n.set(s,[a])},r=[];for(const t of o.cells){if(t.unread!==void 0){i(t,/^\[|[!']\[|\[\d+\]/u.test(t.unread)?"it reads another workbook":`it could not be read: ${t.unread}`);continue}if(!t.node)continue;const s=D(t.node,e,f);s!==void 0?(delete t.node,i(t,s)):(f.carried.set(t,o),t.array&&C(t.array)!==$(t)&&r.push(t))}ze(f,o,r);for(const[t,s]of n)f.lost.push(`${o.name}: ${F(s.length,"formula")} kept as ${s.length===1?"its value":"their values"}, as ${t} (${A(s)})`)}}function ze(f,e,o){if(o.length===0)return;const n=new Set;for(const i of o){const{array:r}=i;if(r)for(const t of e.cells)t!==i&&!t.node&&z(r,t.row,t.col)&&n.add(t)}e.cells=e.cells.filter(i=>!n.has(i));for(const i of n)f.spilled.set(i,e)}function E(f,e){const{value:o}=e;if(!f.book.date1904||typeof o!="number")return o;const n=f.book.looks[e.style]?.format;return N(n)&&n!==void 0&&J(n)?o+Y:o}function P(f,e){if(typeof f!="number"||e===void 0||!N(e)||!J(e)||f<1)return;const o=ye(f);return j(o).value===f?o:void 0}const Re=(f,e)=>P(f,e)??H(f??null);function re(f,e){const o=P(f,e);return o!==void 0?o:f==null?null:typeof f=="number"||typeof f=="boolean"?f:H(f)}function Ne(f){const e=[];for(let s=0;s<f.length;s++){const l=f[s];if(!l)continue;const a=e[e.length-1];a?.row===l.row&&a.right===l.col-1?(a.right=l.col,a.last=s):e.push({row:l.row,left:l.col,right:l.col,first:s,last:s})}const o=e.map((s,l)=>l),n=s=>{let l=s;for(;o[l]!==l;){const a=o[o[l]??l]??l;o[l]=a,l=a}return l};let i=0,r=0;for(let s=0;s<e.length;s++){const l=e[s];if(l){s>0&&e[s-1]?.row!==l.row&&(i=e[s-1]?.row===l.row-1?r:s,r=s);for(let a=i;a<r;a++){const c=e[a];c?.row===l.row-1&&c.right>=l.left&&c.left<=l.right&&(o[n(s)]=n(a))}}}const t=new Map;return e.forEach((s,l)=>{const a=n(l),c=t.get(a),u=s.right-s.left+1;c?(c.box.top=Math.min(c.box.top,s.row),c.box.bottom=Math.max(c.box.bottom,s.row),c.box.left=Math.min(c.box.left,s.left),c.box.right=Math.max(c.box.right,s.right),c.count+=u,c.runs.push(l)):t.set(a,{box:{top:s.row,bottom:s.row,left:s.left,right:s.right},count:u,runs:[l]})}),[...t.values()].map(s=>({box:s.box,count:s.count,cells:()=>s.runs.flatMap(l=>{const a=e[l];return a?f.slice(a.first,a.last+1):[]})}))}const ie=f=>JSON.stringify(f);class Ie{ctx;read;cells;inTables=new te;columnLooks=new Map;rowLooks=new Map;lookDone=new te;tables=[];areas=[];filtered=[];ownLooks=new Map;fileColumns=new Map;pictured=new Map;over=[];keys=new Map;constructor(e,o){this.ctx=e,this.read=o,this.cells=new Oe(o.cells)}at(e,o){return this.cells.get(e,o)}look(e){return this.ctx.book.looks[e.style]??{}}runs(e){if(!e.runs||e.node||typeof e.value!="string")return;const o=$e(Le(e.runs,this.look(e),this.ctx.book.font));return o.length===0||xe(o)?void 0:o}code(e){return this.look(e).format}text(e){return e.node?L(e.node):Re(E(this.ctx,e),this.code(e))}baseLooks(){const{read:e}=this,{looks:o}=this.ctx.book;let n=-1;for(const r of e.cells)r.col>n&&(n=r.col);for(const r of e.columns){if(r.style===void 0)continue;const t=o[r.style];if(!(!t||b(t)))for(let s=r.min;s<=Math.min(r.max,n);s++)this.columnLooks.set(s,t)}for(const r of e.rows){const t=r.style===void 0?void 0:o[r.style];t&&!b(t)&&this.rowLooks.set(r.row,t)}const i=(r,t)=>{for(const s in t)if(!(s in r))return!1;return!0};for(const r of e.cells){const t=this.look(r),s=this.columnLooks.get(r.col);s&&!i(t,s)&&this.columnLooks.delete(r.col);const l=this.rowLooks.get(r.row);l&&!i(t,l)&&this.rowLooks.delete(r.row)}}ownLook(e){const o=this.columnLooks.get(e.col),n=this.rowLooks.get(e.row),i=this.look(e),r=i.format!==void 0&&N(i.format);if(!o&&!n&&!r){let a=this.ownLooks.get(e.style);return a||(a={look:i,key:ie(i)},this.ownLooks.set(e.style,a)),a}const t={...o,...n},s={};for(const[a,c]of Object.entries(i))JSON.stringify(c)!==JSON.stringify(t[a])&&(s[a]=c);const l=s.format;if(typeof l=="string"){const a=e.node?void 0:P(E(this.ctx,e),l);a!==void 0&&j(a).format===l&&delete s.format}return{look:s,key:ie(s)}}keyOf(e,o){if(e.key!==void 0)return e.key;const n=be(o,e.row,e.col),i=this.keys.get(n);return i!==void 0?e.key=i:(this.keys.set(n,n),e.key=n)}columnFormula(e,o,n){const i=new Map,r=n-o+1;for(let s=o;s<=n;s++){const l=this.at(s,e);if(!l||l.value===void 0&&!l.node||l.value===null&&!l.node)return;if(!l.node)continue;const a=this.keyOf(l,l.node),c=i.get(a);c?c.n+=1:i.set(a,{n:1,cell:l})}let t;for(const s of i.values())(!t||s.n>t.n)&&(t=s);return t&&t.n*2>r?t.cell:void 0}csv(e,o){const n=[];for(let i=0;i<e;i+=G){const r=[];for(let t=i;t<Math.min(e,i+G);t++)r.push(o(t));n.push(we(r))}return n.join("")}table(e){const{read:o,ctx:n}=this,i=d=>n.lost.push(`${o.name}: table ${e.name} ${d}`),r=e.ref.right-e.ref.left+1,t=se(e);if(t!==void 0)return i(`${t}, so its cells are kept and it is no table`),!1;const s=e.ref.top,l=s+1;let a=e.ref.bottom-e.totals;if(e.totals===0){let d=s;for(const g of o.cells)g.col>=e.ref.left&&g.col<=e.ref.right&&g.row>d&&(d=g.row);a-d>Ae&&(i(`runs ${String(a-d)} empty rows past what it holds, which are left out`),a=d)}e.totals>0&&i("has a totals row, kept as plain cells under it");const c=e.columns.map((d,g)=>a>=l?this.columnFormula(e.ref.left+g,l,a):void 0),u=d=>{const g=c[d];if(!g)return!1;for(let k=l;k<=a;k++)if(this.at(k,e.ref.left+d)?.key!==g.key)return!1;return!0};let h=r;for(;h>1&&u(h-1);)h-=1;const p={},m=this.path(e.name);n.files.set(m,this.csv(a-l+2,d=>{if(d===0)return e.columns.slice(0,h).map(y=>y.name);const g=l+d-1,k=[];for(let y=0;y<h;y++){const x=this.at(g,e.ref.left+y),v=c[y];x?v&&x.key===v.key?k.push(""):x.node?k.push(L(ne(x.node,e.name))):k.push(this.text(x)):k.push("")}return k})),this.inTables.add({...e.ref,bottom:a}),e.columns.forEach((d,g)=>{const k=e.ref.left+g,y=this.columnLook(k,l,a),x=c[g];x?.node&&(y.formula=L(ne(ke(x.node,l-x.row,0),e.name)));const v=this.fileColumns.get(k);v!==void 0&&l<=a&&(y.files=v===W?!0:{height:v}),b(y)||(p[d.name]=y)});const w=new Map;for(const[d,g]of e.filter?.columns??[]){const k=e.columns[d]?.name;k!==void 0&&w.set(k,g)}return(e.filter?.unread??0)>0&&i(`has ${F(e.filter?.unread??0,"filter")} by condition, its rows left as they were hidden`),this.tables.push({name:e.name,at:$({row:s,col:e.ref.left}),rows:m,...e.style!==void 0&&e.style!=="TableStyleMedium2"?{style:e.style}:{},...e.options,...b(p)?{}:{columns:p},...e.filter===void 0?{filter:!1}:w.size>0?{filter:{columns:Object.fromEntries(w)}}:{}}),e.filter?.unread===0&&e.filter.columns.size>0&&this.filtered.push({...e.ref,bottom:a}),this.areas.push({...e.ref,bottom:a}),!0}columnLook(e,o,n){let i,r={};for(let t=o;t<=n;t++){const s=this.at(t,e),l=s?this.ownLook(s):{look:{},key:"{}"};if(i===void 0)i=l.key,r=l.look;else if(i!==l.key)return{}}return b(r)?{}:(this.lookDone.add({top:o,bottom:n,left:e,right:e}),{...r})}path(e){const o=Q(e);let n=`${o}.csv`;for(let i=2;this.ctx.files.has(n)||this.ctx.taken(n);i++)n=`${o}-${String(i)}.csv`;return n}loose(){const e=[],o=[];for(const n of this.read.cells)this.inTables.has(n.row,n.col)||(n.node?e.push(n):n.value!==void 0&&n.value!==null&&o.push(n));return{formulas:e,typed:o}}blockAreas(e,o){const n=[],i=O(o.map(S)),r=s=>!n.some(l=>R(l,s))&&!this.areas.some(l=>R(l,s))&&!i.some(l=>R(l,s)),t=s=>(s.bottom-s.top+1)*(s.right-s.left+1);for(const s of Ne(e)){const{box:l}=s;if(!(t(l)<K)){if(s.count/t(l)>=Me&&r(l)){n.push(l);continue}for(const a of O(s.cells().map(S)))t(a)>=K&&r(a)&&n.push(a)}}return n.sort((s,l)=>s.top-l.top||s.left-l.left)}cells_(e){const{formulas:o,typed:n}=this.loose(),i=new Map;for(const c of n){const u=this.runs(c);u&&i.set(c,u)}const r=this.read.cells.filter(c=>this.inTables.has(c.row,c.col)&&this.runs(c)!==void 0);r.length>0&&this.ctx.lost.push(`${this.read.name}: ${F(r.length,"cell")} of rich text in a table, kept as plain text (${A(r.map(c=>$(c)))})`);const t=this.blockAreas(n.filter(c=>!i.has(c)),[...o,...i.keys()]),s=c=>t.some(u=>z(u,c.row,c.col));t.length>0&&(e.blocks=t.map(c=>{const u=this.path(this.read.name);return this.ctx.files.set(u,this.csv(c.bottom-c.top+1,h=>{const p=[];for(let m=c.left;m<=c.right;m++){const w=this.at(c.top+h,m);p.push(w?this.text(w):"")}return p})),{at:$({row:c.top,col:c.left}),rows:u}}));const l=[],a=new Map;for(const c of o){if(!c.node)continue;const u=this.keyOf(c,c.node),h=a.get(u);h?h.push(c):a.set(u,[c])}for(const c of a.values())for(const u of O(c.map(S))){const h=this.at(u.top,u.left);h?.node&&l.push([{row:u.top,col:u.left},C(u),L(h.node)])}for(const c of n){if(t.length>0&&s(c))continue;const u=i.get(c);l.push([S(c),$(c),u?{runs:u}:re(E(this.ctx,c),this.code(c))])}l.sort(([c],[u])=>c.row-u.row||c.col-u.col),l.length>0&&(e.cells=Object.fromEntries(l.map(([,c,u])=>[c,u])))}formats(e){const o=new Map,n=this.lookDone.list.length>0;for(const r of this.read.cells){if(n&&this.lookDone.has(r.row,r.col))continue;const t=this.ownLook(r);if(b(t.look))continue;const s=o.get(t.key);s?s.places.push(S(r)):o.set(t.key,{look:t.look,places:[S(r)]})}const i=[];for(const{look:r,places:t}of o.values())for(const s of O(t))i.push({range:C(s),...r});i.length>0&&(e.format=i)}columns(e){const{read:o}=this,n=new Map;let i=0;for(const t of o.cells)t.col>i&&(i=t.col);const r=[];for(const t of o.columns){if(t.width===void 0&&t.hidden!==!0&&t.level===void 0)continue;const s=t.max-Math.max(t.min,i+1)+1>X?Math.max(i,t.min+X-1):t.max;s<t.max&&r.push(`${M(s+1)}:${M(t.max)}`);const l=t.width!==void 0&&t.width<=0;for(let a=t.min;a<=s;a++)n.set(a,{...t.width===void 0||l?{}:{width:t.width},...t.hidden===!0||l?{hidden:!0}:{},...t.level===void 0?{}:{level:t.level}})}for(const[t,s]of this.columnLooks)n.set(t,{...n.get(t),...s});for(const[t,s]of this.fileColumns)this.tableColumn(t)||n.set(t,{...n.get(t),files:s===W?!0:{height:s}});n.size>0&&(e.columns=Object.fromEntries([...n.keys()].sort((t,s)=>t-s).map(t=>[M(t),n.get(t)??{}]))),r.length>0&&this.ctx.lost.push(`${o.name}: the size of columns ${A(r)}, past those that hold anything`)}tableColumn(e){return this.areas.some(o=>e>=o.left&&e<=o.right)}rows(e){const o={};for(const n of this.read.rows){const i=this.rowLooks.get(n.row),r=this.filtered.some(a=>n.row>a.top&&n.row<=a.bottom),t=n.height!==void 0&&this.pictured.get(n.row)!==n.height?n.height:void 0,s=t!==void 0&&t<=0,l={...t===void 0||s?{}:{height:t},...(n.hidden===!0||s)&&!r?{hidden:!0}:{},...n.level===void 0?{}:{level:n.level},...i};b(l)||(o[String(n.row+1)]=l)}b(o)||(e.rows=o)}assetPath(e,o){const n=s=>{const l=this.ctx.assets.get(s);return l?je(l,o.bytes):!this.ctx.taken(s)};if(e!==void 0&&oe(e)===oe(`.${o.type}`)&&ee(e)&&n(e))return e;const r=Q((o.name??"picture").replace(/\.[A-Za-z0-9]+$/u,""));let t=`${r}.${o.type}`;for(let s=2;!n(t);s++)t=`${r}-${String(s)}.${o.type}`;return t}pictures(){const e=this.over;for(const o of this.read.pictures){const n=this.at(o.row,o.col),i=typeof n?.value=="string"?n.value:"";if(o.y===void 0&&o.descr!==void 0&&ee(o.descr)&&i.split(ae).includes(o.descr)&&o.descr!==void 0){this.ctx.assets.set(o.descr,o.bytes),this.fileColumns.set(o.col,Math.max(this.fileColumns.get(o.col)??0,o.height)),this.pictured.set(o.row,Math.max(this.pictured.get(o.row)??0,o.height));continue}if(o.width<=0||o.height<=0){this.ctx.lost.push(`${this.read.name}: a picture of no size at ${$({row:o.row,col:o.col})}`);continue}const t=this.assetPath(o.descr,o);this.ctx.assets.set(t,o.bytes);const s=ge(o.bytes),l=s?.width===o.width&&s.height===o.height;e.push({file:t,at:$({row:o.row,col:o.col}),...o.x===void 0?{}:{x:o.x},...o.y===void 0?{}:{y:o.y},...l?{}:{width:o.width,height:o.height}})}}build(){const{read:e}=this;this.baseLooks(),this.pictures();for(const n of e.tables)this.table(n);const o={name:e.name};return e.state!=="visible"&&(o.hidden=!0),e.gridlines===!1&&(o.gridlines=!1),e.tab!==void 0&&(o.tab=e.tab),e.state==="veryHidden"&&this.ctx.lost.push(`${e.name}: being very hidden; it is hidden`),e.freeze&&(e.freeze.row>0||e.freeze.col>0)&&(o.freeze=$(e.freeze)),this.tables.length>0&&(o.tables=this.tables),this.filter(o),this.columns(o),this.rows(o),this.cells_(o),e.merges.length>0&&(o.merges=e.merges.map(C)),this.formats(o),e.conditional.length>0&&(o.conditional=e.conditional),e.validations.length>0&&(o.validations=e.validations),e.charts.length>0&&(o.charts=e.charts.map(n=>this.chart(n))),this.over.length>0&&(o.pictures=this.over),b(e.links)||(o.links=e.links),e.notes.length>0&&(o.notes=Object.fromEntries(e.notes.map(n=>[n.ref,n.author===void 0||n.author===fe?n.text:{text:n.text,author:n.author}]))),e.print&&(o.print=e.print),e.protect===!0&&(o.protect=!0),e.outline&&(o.outline=e.outline),o}chart(e){return ue(e,o=>{const n=this.chartReference(o.replace(/^=/u,""));return o.startsWith("=")?`=${n}`:n})}chartReference(e){const o=e.lastIndexOf("!"),i=(o<0?this.read.name:e.slice(0,o)).replace(/^'|'$/gu,"").replaceAll("''","'"),r=B(e.slice(o+1).replaceAll("$",""));if(!r)return e;const t=this.ctx.book.sheets.find(s=>s.name.toLowerCase()===i.toLowerCase());for(const s of t?.tables??[]){const l=s.ref.top+1,c=r.left===r.right&&r.top===l&&r.bottom===s.ref.bottom&&r.left>=s.ref.left&&r.left<=s.ref.right?s.columns[r.left-s.ref.left]:void 0;if(c&&this.ctx.tables.has(s.name.toLowerCase()))return L({kind:"structured",table:s.name,sections:[],columns:[c.name],thisRow:!1}).slice(1)}return`${t===this.read||o<0?"":`${e.slice(0,o)}!`}${C(r)}`}filter(e){const{filter:o}=this.read;if(!o)return;const n={};for(const[i,r]of o.columns)n[M(o.ref.left+i)]=r;e.filter={range:C(o.ref),...b(n)?{}:{columns:n}},o.unread===0&&!b(n)&&this.filtered.push(o.ref)}}const je=(f,e)=>f.length===e.length&&f.every((o,n)=>o===e[n]),He=new Set(["_xlnm._FilterDatabase","_xlnm.Print_Area","_xlnm.Print_Titles"]);function Fe(f){const e={},o=[],n=new Map,{book:i,lost:r}=f,t=new Set(i.sheets.map(u=>u.name.toLowerCase())),s=new Set,l=[];let a;const c=u=>{a=void 0;const h=We(u.text);if(h!==void 0)return typeof h=="string"?H(h):h;const p=Ce(u.text,!0),m=p.ok?D(p.node,t):"it could not be read";if(!p.ok||m!==void 0||Pe(p.node)){r.push(`the name ${u.name} (${u.text})${m===void 0?"":`: ${m}`}`);return}return a=p.node,L(p.node)};for(const u of i.names){if(u.name.startsWith("_xlnm.")){He.has(u.name)||r.push(`Excel's name ${u.name}`);continue}if(/^_xl(?:fn|pm|ws|udf)/iu.test(u.name))continue;const h=u.name.toLowerCase(),p=u.sheet===void 0?"":String(u.sheet);if(!q(u.name)||f.tables.has(h)){r.push(`the name ${u.name}, which cannot be held here`);continue}if(s.has(`${p}|${h}`)){r.push(`a second name ${u.name}${p===""?"":` of ${i.sheets[u.sheet??0]?.name??""}`}`);continue}const m=c(u);if(m===void 0)continue;s.add(`${p}|${h}`),f.names.add(h);const w=u.sheet===void 0?void 0:n.get(u.sheet)??{names:{},hidden:[]},d=w?.names??e;d[u.name]=m,u.hidden===!0&&(w?.hidden??o).push(u.name),w&&u.sheet!==void 0&&n.set(u.sheet,w),a&&l.push({held:d,n:u,node:a})}for(const{held:u,n:h,node:p}of l){const m=D(p,t,{names:f.names,tables:f.tables});m!==void 0&&(u[h.name]="=#NAME?",r.push(`the name ${h.name} (${h.text}): ${m}; it holds #NAME?, as in Excel`))}return{names:e,hidden:o,sheets:n}}function De(f,e){const o={},n=new Map;for(const[i,r]of Object.entries(e))typeof r=="string"&&r.startsWith("=")&&n.set(r.slice(1).replaceAll("$","").toLowerCase(),i);for(const i of f.book.sheets)for(const r of i.scenarios){const t={};let s=!0;for(const{at:l,value:a}of r.cells){const c=ce(l),u=c&&i.cells.find(m=>m.row===c.row&&m.col===c.col);String(u?.value??"")!==a&&(s=!1);const h=n.get(`${U(i.name)}${l}`.toLowerCase())??n.get(l.toLowerCase()),p=j(a);h===void 0?f.lost.push(`${i.name}: scenario ${r.name}'s cell ${l}, which has no name`):t[h]=typeof p.value=="number"?p.value:a}!s&&!b(t)&&(o[r.name]={...o[r.name],...t})}return o}function Pe(f){let e=!1;return I(f,o=>{e||=o.kind==="error"&&o.code==="#REF!"}),e}function We(f){const e=f.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/u.test(e)?Number(e):/^true$/iu.test(e)?!0:/^false$/iu.test(e)?!1:/^"((?:[^"]|"")*)"$/u.exec(e)?.[1]?.replaceAll('""','"')}const Be=new RegExp(`^${Ee.replace(/[.*+?^${}()|[\]\\]/gu,"\\$&")}(?: \\(\\d+\\))?$`,"u");function Ue(f){const e=f.sheets.find(r=>r.state==="veryHidden"&&Be.test(r.name));if(!e)return;const o=U(e.name).toLowerCase(),n=r=>{const t=r.replace(/^=/u,"");if(!t.toLowerCase().startsWith(o))return;const s=B(t.slice(o.length).replaceAll("$",""));if(!s||s.left!==s.right)return;const l=[];for(let a=s.top;a<=s.bottom;a++){const c=e.cells.find(u=>u.row===a&&u.col===s.left);l.push(typeof c?.value=="string"?c.value:"")}return l};for(const r of f.sheets)r.validations=r.validations.map(t=>{const[s]=t.formula??[],l=t.type==="list"&&typeof s=="string"?n(s):void 0;if(!l)return t;const a={...t,values:l};return delete a.formula,a});const i=f.sheets.indexOf(e);f.sheets=f.sheets.filter(r=>r!==e),f.names=f.names.flatMap(r=>r.sheet===void 0||r.sheet<i?[r]:r.sheet===i?[]:[{...r,sheet:r.sheet-1}])}const T=f=>f instanceof _?f.code:f??null,Ve=new Map([["#SPILL!","#VALUE!"],["#CALC!","#VALUE!"]]);export function sameValue(f,e,o){if(typeof f=="number"&&typeof e=="number")return f===e?!0:Math.abs(f-e)<=Math.max(Math.abs(f),Math.abs(e))*o;if(f instanceof _||e instanceof _){const n=i=>i instanceof _?Ve.get(i.code)??i.code:void 0;return n(f)===n(e)}if(f===null||e===null){const n=f??e;return n===null||n===""||n===0||n===!1}return f===e}function Ze(f,e){const o=[];for(const r of e.sheets)for(const t of r.formulas)t.shared.node&&he(e,t.shared,r).volatile&&o.push(t);const n=new Set(o),i=[...o];for(;;){const r=i.pop();if(!r)return n;for(const t of f.readers(r.sheet,r.row,r.col))n.has(t)||(n.add(t),i.push(t))}}function qe(f){const e=f.file.iteration;return(e===void 0||e===!0?void 0:e.max_change)??de.max_change}function Je(f,e,o,n){const i={formulas:0,same:0,uncached:0,moving:0,differences:[]},r=Ze(o,e);for(const[t,s]of f.carried){if(!t.node)continue;const l=e.sheet(s.name);if(!l)continue;i.formulas+=1;const a=l.at(t.row,t.col);if(a instanceof Z&&r.has(a)){i.moving+=1;continue}const c=E(f,t);if(c===void 0){i.uncached+=1;continue}const u=o.value(l,t.row,t.col);a instanceof Z&&o.iterates(a)&&typeof c=="number"&&typeof u=="number"&&Math.abs(c-u)<=qe(e)||sameValue(c,u,n)?i.same+=1:i.differences.push({sheet:s.name,cell:$(t),formula:L(t.node),file:T(c),engine:T(u)})}for(const[t,s]of f.spilled){const l=e.sheet(s.name);if(!l)continue;i.formulas+=1;const a=l.spillAt(t.row,t.col);if(a&&r.has(a)){i.moving+=1;continue}const c=E(f,t),u=o.value(l,t.row,t.col);c===void 0?i.uncached+=1:sameValue(c,u,n)?i.same+=1:i.differences.push({sheet:s.name,cell:$(t),formula:a?`${$(a)}#`:"",file:T(c),engine:T(u)})}return i}function Ke(f,e){const o=new Map,n=[];for(const i of f){const r=e.find(l=>i.startsWith(`${l}: `));if(r===void 0){n.push(i);continue}const t=i.slice(r.length+2),s=o.get(t);s?s.push(r):o.set(t,[r])}for(const[i,r]of o)n.push(r.length===1?`${r[0]??""}: ${i}`:`${i}, on ${String(r.length)} sheets (${A(r)})`);return n}function Ye(f,e,o){const n=o.circularCells();if(n.length===0)return!1;const i=new Map;for(const[s,l]of f.carried)i.set(`${l.name}|${String(s.row)}|${String(s.col)}`,s);let r=0,t=0;for(const s of n){const l=i.get(`${s.sheet.name}|${String(s.row)}|${String(s.col)}`),a=l===void 0?void 0:E(f,l),c=e[s.sheet.index],u=s.shared.source.path??[];if(a===void 0||!c||u[2]!=="cells"){a!==void 0&&(t+=1);continue}const h=re(a,void 0),p=c.cells??={},m=$(s),w=p[m],d=p[String(u[3])],g=d!==null&&typeof d=="object"?d:{};p[m]=w!==null&&typeof w=="object"?{...w,start:h}:{...g,formula:s.text,start:h},r+=1}return t>0&&f.lost.push(`where ${String(t)} cells of a table or a block start iterative calculation: they start from 0`),r>0}export function importXlsx(f,e){const o=Se(f,e.zip);if(Ue(o),_e(o),o.sheets.length===0)throw new Error("It holds no sheets.");const n={book:o,taken:e.taken??(()=>!1),files:new Map,assets:new Map,lost:[...o.lost],tables:new Set(o.sheets.flatMap(m=>m.tables.filter(w=>se(w)===void 0).map(w=>w.name.toLowerCase()))),names:new Set,carried:new Map,spilled:new Map};o.date1904&&n.lost.push(`the 1904 date system: dates are moved to the 1900 one, ${String(Y)} days on`),(o.font.name!==void 0&&o.font.name!=="Calibri"||o.font.size!==void 0&&o.font.size!==11)&&n.lost.push(`its default font, ${o.font.name??""} ${String(o.font.size??"")}`);const i=Fe(n);Te(n);const r=o.sheets.map((m,w)=>{const d=new Ie(n,m).build(),g=i.sheets.get(w);return g&&!b(g.names)&&(d.names=g.names),g&&g.hidden.length>0&&(d.hidden_names=g.hidden),d}),t=De(n,i.names),s={title:o.title??e.name,...b(i.names)?{}:{names:i.names},...i.hidden.length>0?{hidden_names:i.hidden}:{},sheets:r,...b(t)?{}:{scenarios:t},...o.iteration===void 0?{}:{iteration:o.iteration}},l=()=>{const m=ve(s),w=new Map([[le,m],...n.files]);return{files:w,...pe({text:m,read:d=>w.get(d),exists:d=>w.has(d)||n.assets.has(d)})}};let a=l();a.calc&&Ye(n,r,a.calc)&&(a=l());const{files:c,workbook:u,calc:h,problems:p}=a;return{files:c,assets:n.assets,lost:Ke(n.lost,o.sheets.map(m=>m.name)),problems:p,compared:u&&h?Je(n,u,h,e.tolerance??COMPARE_TOLERANCE):{formulas:0,same:0,uncached:0,moving:0,differences:[]},sheets:o.sheets.length,tables:n.tables.size}}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{ZipLimitError as Le}from"@allyhub/formats";import{SHEET_FILTER_OPERATORS as Re,SHEET_ICONS as Me,SHEET_MARGINS as ce,SHEET_OPERATORS as _e,SHEET_PAPERS as Pe,SHEET_VALIDATIONS as De}from"@allyhub/formats";import{MAX_COLUMNS as J,MAX_ROWS as Q,cellName as ee,columnLetter as te,readAddress as fe,readArea as q,readAreas as ne}from"../address.js";import{ITERATION_DEFAULTS as he}from"../calc/engine.js";import{SHEET_CHART_DEFAULTS as pe}from"../chart.js";import{moveFormula as je,relativeKey as me}from"../formula/move.js";import{parseFormula as ze}from"../formula/parse.js";import{printFormula as ge}from"../formula/print.js";import{ERR as He,errorOf as Be,serialOfDate as Ve}from"../values.js";import{OFFICE_THEME as Ue,colorOf as P,paletteOf as be,themeColors as We}from"./colors.js";import{chartAnchors as qe,readChart as Xe}from"./charts.js";import{isRangeText as Ge,readFileFormula as oe}from"./formula.js";import{BUILTIN_FORMATS as we}from"./numfmt.js";import{XmlStream as xe}from"./sax.js";import{attr as c,flag as y,numberAttr as $,readXml as ye,readXstring as E,tag as d,tags as v,textOf as O}from"./xml.js";import{RunsCollector as $e,readRuns as ve}from"./runs.js";import{ZipIn as Ze}from"./zip.js";function Je(n){if(y(n,"iterate")!==!0)return;const t=$(n,"iterateCount"),e=$(n,"iterateDelta"),o=t===void 0?void 0:Math.min(32767,Math.max(1,Math.round(t))),r=e===void 0?void 0:Math.max(0,e),s={...o===void 0||o===he.max_iterations?{}:{max_iterations:o},...r===void 0||r===he.max_change?{}:{max_change:r}};return Object.keys(s).length>0?s:!0}const ke=7,Ke=n=>Math.floor((256*n+Math.floor(128/ke))/256*ke),Qe=n=>Math.round(n*4/3),re=5;export function placesLine(n){const t=n.slice(0,re).join(", ");return n.length>re?`${t} and ${String(n.length-re)} more`:t}const X=(n,t,e=`${t}s`)=>`${String(n)} ${n===1?t:e}`;export const GRID_END=`Excel's grid ends at ${te(J-1)}${String(Q)} (${Q.toLocaleString("en-US")} rows, ${J.toLocaleString("en-US")} columns)`;function Ye(n,t){let e=0,o=0;const r=n.length;for(;e<r;e++){const i=n.charCodeAt(e),u=i>=65&&i<=90,a=i>=97&&i<=122;if(!u&&!a)break;o=o*26+(u?i-64:i-96)}if(e===0||e===r)return;let s=0;for(let i=e;i<r;i++){const u=n.charCodeAt(i);if(u<48||u>57)return;s=s*10+u-48}if(s!==0){if(e>3||o>J||s>Q)throw new Error(`${t} has a cell at ${n}, and ${GRID_END}.`);return{row:s-1,col:o-1}}}class et{zip;constructor(t,e){this.zip=new Ze(t,e)}get names(){return this.zip.names}has(t){return this.zip.has(t)}text(t){return this.zip.text(t)}bytes(t){return this.zip.bytesOf(t)}xml(t){const e=this.text(t);return e===void 0?void 0:ye(e)}stream(t,e){const o=this.zip.streamText(t,r=>{e.push(r)});return o&&e.end(),o}rels(t){const e=t.lastIndexOf("/"),o=`${t.slice(0,e+1)}_rels/${t.slice(e+1)}.rels`,r=this.xml(o);return v(d(r?.Relationships)?.Relationship).map(s=>{const i=c(s,"Type")??"",u=c(s,"Target")??"",a=c(s,"TargetMode")==="External";return{id:c(s,"Id")??"",type:i.slice(i.lastIndexOf("/")+1),target:a?u:tt(t,u),external:a}})}count(t){return this.names.filter(e=>t.test(e)).length}}function tt(n,t){if(t.startsWith("/"))return t.slice(1);const e=n.split("/").slice(0,-1);for(const o of t.split("/"))o===".."?e.pop():o!=="."&&e.push(o);return e.join("/")}function nt(n,t,e){const o=[];if(t===void 0)return o;let r,s=0,i=!1;const u={open(a,l){if(a==="si"){r={text:"",runs:new $e};return}if(r){if(s>0||a==="rPh"||a==="phoneticPr"||a==="extLst"){s+=1;return}r.runs.open(a,l)||a==="t"&&(i=!0)}},close(a){if(s>0){s-=1;return}if(a==="si"){if(r){const{runs:l}=r.runs;o.push({text:E(r.text),...l.length>0?{runs:ve(l,e)}:{}})}r=void 0;return}r?.runs.close(a),a==="t"&&(i=!1)},text(a){r&&i&&s===0&&(r.text+=a,r.runs.text(a))}};return n.stream(t,new xe(u)),o}function G(n,t){const e=n[t];if(e===void 0)return!1;const o=c(d(e),"val");return o===void 0||o!=="0"&&o!=="false"}const ot=new Set(["double","singleAccounting","doubleAccounting"]);function rt(n,t,e){const o={},r=(a,l)=>c(d(a?.[l]),"val");if(G(n,"b")&&(o.bold=!0),G(n,"i")&&(o.italic=!0),G(n,"strike")&&(o.strike=!0),G(n,"u")){const a=r(n,"u");o.underline=a!==void 0&&ot.has(a)?a:!0}const s=r(n,"name");s!==void 0&&s!==r(t,"name")&&(o.font=s);const i=r(n,"sz");i!==void 0&&i!==r(t,"sz")&&(o.size=Number(i));const u=P(d(n.color),e);return u!==void 0&&u!==P(d(t?.color),e)&&(o.color=u),o}function st(n,t){const e=d(n.patternFill),o=c(e,"patternType");if(o===void 0||o==="none")return;const r=P(d(e?.fgColor),t),s=P(d(e?.bgColor),t);return o==="solid"&&r!==void 0?r:{pattern:o,...r===void 0?{}:{color:r},...s===void 0?{}:{background:s}}}function Se(n,t){const e={};for(const o of["left","right","top","bottom"]){const r=d(n[o]),s=c(r,"style");if(s===void 0||s==="none")continue;const i=P(d(r?.color),t);e[o]={style:s,...i===void 0?{}:{color:i}}}return Object.keys(e).length===0?void 0:e}function it(n){const t={},e=c(n,"horizontal");e!==void 0&&e!=="general"&&(t.align=e);const o=c(n,"vertical");o!==void 0&&o!=="bottom"&&(t.valign=o),y(n,"wrapText")===!0&&(t.wrap=!0),y(n,"shrinkToFit")===!0&&(t.shrink=!0);const r=$(n,"indent");r!==void 0&&r>0&&(t.indent=r);const s=$(n,"textRotation");return s!==void 0&&s>0&&s<=180&&(t.rotation=s),t}function Ce(n,t){const e={},o=d(n.font);if(o){const f=(b,h)=>{o[b]!==void 0&&(e[h]=G(o,b))};f("b","bold"),f("i","italic"),f("strike","strike"),o.u!==void 0&&(e.underline=G(o,"u"));const g=P(d(o.color),t);g!==void 0&&(e.color=g)}const r=d(d(n.fill)?.patternFill),s=P(d(r?.bgColor),t)??P(d(r?.fgColor),t);s!==void 0&&(e.fill=s);const i=d(n.border),u=i&&Se(i,t);u!==void 0&&(e.border=u);const a=d(n.numFmt),l=c(a,"formatCode")??we[$(a,"numFmtId")??-1];return a&&l!==void 0&&l!==""&&l!=="General"&&(e.format=l),e}function at(n,t){const e=d(n?.styleSheet),o=be(t,e),r=new Map(v(d(e?.numFmts)?.numFmt).map(m=>[$(m,"numFmtId")??-1,c(m,"formatCode")?.replace(/^$/u,"General")??"General"])),s=v(d(e?.fonts)?.font),i=v(d(e?.fills)?.fill),u=v(d(e?.borders)?.border),a=v(d(e?.cellXfs)?.xf),l=s[$(a[0],"fontId")??0],f=new Set;i.some(m=>m.gradientFill!==void 0)&&f.add("gradient fills");const g=v(d(e?.cellStyles)?.cellStyle),b=new Set(a.map(m=>$(m,"xfId")??0)),h=g.filter(m=>$(m,"builtinId")!==0&&b.has($(m,"xfId")??-1)).map(m=>E(c(m,"name")??"")).filter(m=>m!=="");h.length>0&&f.add(`the names of cell styles (${h.slice(0,5).join(", ")}${h.length>5?", …":""}): their looks are kept`);const w=a.map(m=>{const C={},F=s[$(m,"fontId")??0];F&&(Object.assign(C,rt(F,l,o)),F.vertAlign!==void 0&&f.add("superscript and subscript"));const L=i[$(m,"fillId")??0],M=L&&st(L,o);M!==void 0&&(C.fill=M);const _=u[$(m,"borderId")??0],N=_&&Se(_,o);N!==void 0&&(C.border=N),_&&c(d(_.diagonal),"style")!==void 0&&f.add("diagonal borders");const j=d(m.alignment);j&&(Object.assign(C,it(j)),$(j,"textRotation")===255&&f.add("vertical text"));const z=d(m.protection);y(z,"locked")===!1&&(C.locked=!1),y(z,"hidden")===!0&&(C.hide_formula=!0);const D=$(m,"numFmtId")??0,H=r.get(D)??we[D];return H!==void 0&&H!=="General"&&(C.format=H),C}),S=c(d(l?.name),"val"),p=c(d(l?.sz),"val");return{looks:w,dxfs:v(d(e?.dxfs)?.dxf).map(m=>Ce(m,o)),font:{...S===void 0?{}:{name:S},...p===void 0?{}:{size:Number(p)}},lost:[...f]}}const dt=n=>{const t=Number(n);return n.trim()!==""&&Number.isFinite(t)?t:n};function lt(n,t){const e=d(n.customFilters);if(e){const i=v(e.customFilter).map(u=>({operator:c(u,"operator")??"equal",value:dt(E(c(u,"val")??""))}));return i.length===0||i.length>2||i.some(u=>!Re.includes(u.operator))?void 0:{conditions:i,...i.length===2&&y(e,"and")!==!0?{or:!0}:{}}}const o=d(n.top10);if(o){const i=$(o,"val");return i===void 0||i<=0?void 0:{top:{count:i,...y(o,"percent")===!0?{percent:!0}:{},...y(o,"top")===!1?{bottom:!0}:{}}}}const r=c(d(n.dynamicFilter),"type");if(r==="aboveAverage")return{average:"above"};if(r==="belowAverage")return{average:"below"};const s=d(n.colorFilter);if(s){const i=t[$(s,"dxfId")??-1];return y(s,"cellColor")===!1?i?.color?{color:{font:i.color}}:void 0:typeof i?.fill=="string"?{color:{fill:i.fill}}:void 0}}function Te(n,t=[]){const e=new Map;let o=0;for(const r of v(n.filterColumn)){const s=$(r,"colId")??0,i=d(r.filters);if(!i){const a=lt(r,t);a?e.set(s,a):Object.keys(r).some(l=>l!=="colId"&&l!=="hiddenButton")&&(o+=1);continue}if(i.dateGroupItem!==void 0){o+=1;continue}const u=v(i.filter).map(a=>E(c(a,"val")??""));e.set(s,{...u.length===0?{}:{values:u},...y(i,"blank")===!0?{blanks:!0}:{}})}return{columns:e,unread:o}}function ut(n,t=[]){const e=d(n?.table),o=q(c(e,"ref")??""),r=c(e,"displayName")??c(e,"name");if(!o||r===void 0)return;const s=d(e?.tableStyleInfo),i=d(e?.autoFilter);return{name:r,ref:o,headers:$(e,"headerRowCount")??1,totals:$(e,"totalsRowCount")??0,columns:v(d(e?.tableColumns)?.tableColumn).map(u=>({name:E(c(u,"name")??"").trim(),calculated:u.calculatedColumnFormula!==void 0})),style:c(s,"name")??"none",options:{...y(s,"showRowStripes")===!1?{banded_rows:!1}:{},...y(s,"showColumnStripes")===!0?{banded_columns:!0}:{},...y(s,"showFirstColumn")===!0?{first_column:!0}:{},...y(s,"showLastColumn")===!0?{last_column:!0}:{}},...i?{filter:Te(i,t)}:{}}}function se(n){const t=n.trim();if(t==="")return;const e=/^"((?:[^"]|"")*)"$/u.exec(t);if(e)return(e[1]??"").replaceAll('""','"');const o=Number(t);if(!Number.isNaN(o))return o;const r=oe(t,!0);return r.ok?ge(r.node):void 0}const Ee=n=>n!==void 0&&_e.includes(n);function ie(n){const t=c(n,"type")??"num",e=c(n,"val")??(n.f===void 0?void 0:O(n.f)),o=e===void 0?void 0:se(e);return{at:t,...o===void 0?{}:{value:o}}}const ct=Me,ft=n=>{const t=n.formula??n.f;return(Array.isArray(t)?t:t===void 0?[]:[t]).map(O)};function ht(n,t,e,o){const r=c(n,"type")??"",s={range:t,...y(n,"stopIfTrue")===!0?{stop:!0}:{}},i={...e.bold===void 0?{}:{bold:e.bold},...e.italic===void 0?{}:{italic:e.italic},...e.underline===void 0?{}:{underline:e.underline!==!1},...e.strike===void 0?{}:{strike:e.strike},...e.color===void 0?{}:{color:e.color},...typeof e.fill=="string"?{fill:e.fill}:{},...e.border===void 0?{}:{border:e.border},...e.format===void 0?{}:{format:e.format}},u=ft(n);switch(r){case"cellIs":{const a=c(n,"operator"),l=u.flatMap(f=>{const g=se(f);return g===void 0?[]:[g]});return!Ee(a)||l.length===0?`a cellIs rule of ${a??"no operator"}`:{...s,...i,type:"cellIs",operator:a,formula:l}}case"containsText":case"notContainsText":case"beginsWith":case"endsWith":{const a=c(n,"text");return a===void 0?`a ${r} rule with no text`:{...s,...i,type:"containsText",...r==="containsText"?{}:{operator:r==="notContainsText"?"notContains":r},text:E(a)}}case"duplicateValues":case"uniqueValues":return{...s,...i,type:r};case"top10":return{...s,...i,type:"top10",rank:$(n,"rank")??10,...y(n,"percent")===!0?{percent:!0}:{},...y(n,"bottom")===!0?{bottom:!0}:{}};case"aboveAverage":return $(n,"stdDev")!==void 0?"an above or below average rule by standard deviations":{...s,...i,type:"aboveAverage",...y(n,"aboveAverage")===!1?{below:!0}:{},...y(n,"equalAverage")===!0?{equal:!0}:{}};case"expression":{const a=u[0]===void 0?void 0:oe(u[0],!0);return a?.ok?{...s,...i,type:"expression",formula:ge(a.node)}:"an expression rule that cannot be read"}case"dataBar":{const a=d(n.dataBar),l=P(d(a?.color??a?.fillColor),o),[f,g]=v(a?.cfvo).map(ie);return l===void 0?"a data bar with no colour":{...s,type:"dataBar",color:l,...f&&f.at!=="min"?{min:f}:{},...g&&g.at!=="max"?{max:g}:{},...y(a,"showValue")===!1?{show:!1}:{}}}case"colorScale":{const a=d(n.colorScale),l=v(a?.cfvo).map(ie),f=v(a?.color).map(b=>P(b,o)),g=l.flatMap((b,h)=>{const w=f[h];return w===void 0?[]:[{...b,color:w}]});return g.length<2?"a colour scale with too few stops":{...s,type:"colorScale",stops:g.slice(0,3)}}case"iconSet":{const a=d(n.iconSet),l=c(a,"iconSet")??"3TrafficLights1";if(!ct.includes(l))return`the icon set ${l}`;if(a?.cfIcon!==void 0)return"an icon set of icons chosen one by one";const f=v(a?.cfvo).map(ie);return{...s,type:"iconSet",icons:l,...f.length>=3?{stops:f.slice(0,5)}:{},...y(a,"reverse")===!0?{reverse:!0}:{},...y(a,"showValue")===!1?{show:!1}:{}}}default:return`a ${r} rule`}}const Oe={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},Ae=(n,t)=>v(d(n.extLst)?.ext).find(e=>c(e,"uri")?.toUpperCase()===t.toUpperCase());function pt(n,t,e){const o=[],r=[],s=new Set,i=(a,l,f)=>{const g=ht(a,l,f,e);typeof g=="string"?r.push(`${g} on ${l}`):o.push({priority:$(a,"priority")??0,rule:g})};for(const a of v(n.conditionalFormatting)){const l=c(a,"sqref")??"";if(!ne(l)){r.push(`a rule on ${l}`);continue}for(const f of v(a.cfRule)){const g=O(d(d(f.extLst)?.ext)?.id);g!==""&&s.add(g.toUpperCase());const b=$(f,"dxfId");i(f,l,b===void 0?{}:t[b]??{})}}const u=d(Ae(n,Oe.conditional)?.conditionalFormattings);for(const a of v(u?.conditionalFormatting)){const l=O(a.sqref).trim();for(const f of v(a.cfRule)){if(s.has((c(f,"id")??"").toUpperCase())){const b=mt(d(f.dataBar));b!==void 0&&r.push(`a data bar's ${b} on ${l}`);continue}if(!ne(l)){r.push(`a rule on ${l}`);continue}const g=d(f.dxf);i(f,l,g?Ce(g,e):{})}}return{rules:o.sort((a,l)=>a.priority-l.priority).map(a=>a.rule),unread:r}}function mt(n){if(!n)return;const t=[];y(n,"gradient")===!1&&t.push("solid fill"),y(n,"border")===!0&&t.push("border");const e=c(n,"axisPosition");e!==void 0&&e!=="automatic"&&t.push(`axis ${e}`),y(n,"negativeBarColorSameAsPositive")===!0&&t.push("negative bars in its colour");const o=c(d(n.negativeFillColor),"rgb");return o!==void 0&&o.toUpperCase()!=="FFFF0000"&&t.push("negative bars' colour"),c(n,"direction")==="rightToLeft"&&t.push("right to left"),t.length===0?void 0:t.join(", ")}const gt=De;function Ne(n,t,e,o){const r=c(n,"type")??"none";if(r==="none"&&c(n,"prompt")===void 0)return;if(!gt.includes(r)||!ne(t))return`a ${r} rule on ${t}`;const s=/^"((?:[^"]|"")*)"$/u.exec(e.trim()),i=r==="list"&&s?(s[1]??"").replaceAll('""','"').split(","):void 0,u=[e,o].flatMap(w=>{const S=se(w);return S===void 0?[]:[S]}),a=c(n,"operator"),l=w=>Object.fromEntries(Object.entries(w).filter(([,S])=>S!==void 0)),f=l({title:c(n,"promptTitle"),message:c(n,"prompt")}),g=l({style:c(n,"errorStyle"),title:c(n,"errorTitle"),message:c(n,"error")}),b=y(n,"showInputMessage")!==!0,h=y(n,"showErrorMessage")!==!0;return{range:t,type:r,...Ee(a)&&a!=="between"?{operator:a}:{},...i?{values:i}:{formula:u},...y(n,"allowBlank")===!0?{}:{blank:!1},...y(n,"showDropDown")===!0?{dropdown:!1}:{},...b||Object.keys(f).length>0?{prompt:{...f,...b?{show:!1}:{}}}:{},...h||Object.keys(g).length>0?{error:{...g,...h?{show:!1}:{}}}:{}}}function bt(n){const t=[],e=[],o=s=>{typeof s=="string"?e.push(s):s&&t.push(s)};for(const s of v(d(n.dataValidations)?.dataValidation))o(Ne(s,c(s,"sqref")??"",O(s.formula1),O(s.formula2)));const r=d(Ae(n,Oe.validations)?.dataValidations);for(const s of v(r?.dataValidation))o(Ne(s,O(s.sqref).trim(),O(d(s.formula1)?.f),O(d(s.formula2)?.f)));return{rules:t,unread:e}}function wt(n){const t=/^(-?\d{4,})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?)?(?:Z|[+-]\d{2}:?\d{2})?$/u.exec(n)??/^()()()(\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/u.exec(n);if(!t)return;const e=t[1]==="",o=e?1899:Number(t[1]),r=e?12:Number(t[2]),s=e?30:Number(t[3]),i=Number(t[4]??0)*3600+Number(t[5]??0)*60+Number(t[6]??0)+Number(t[7]??0),u=new Date(Date.UTC(o,r-1,s)+i*1e3);if(Number.isNaN(u.getTime()))return;const a=Ve(u);return e?a-Math.floor(a):a}let ae;function Ie(n,t){const e=n.row-t.row,o=n.col-t.col;Object.defineProperty(n,"node",{get:()=>(ae?.cell!==n&&(ae={cell:n,node:je(t.node,e,o)}),ae.node),set:r=>{Object.defineProperty(n,"node",{value:r,writable:!0,enumerable:!0,configurable:!0})},enumerable:!0,configurable:!0}),n.key=t.key}function de(n,t,e){const o=oe(n,t,e);return o.ok?{node:o.node}:{unread:n}}function xt(n){const t=q(n.ref??""),e=l=>{if(l===void 0||l==="")return"";const f=fe(l.replaceAll("$",""));return f?`$${te(f.col)}$${String(f.row+1)}`:void 0},o=e(n.r1),r=e(n.r2);if(!t||o===void 0||o===""||r===void 0)return;const s=n.dt2D==="1"||n.dt2D==="true",i=n.dtr==="1"||n.dtr==="true",u=s?`${o},${r}`:i?`${o},`:`,${o}`,a=ze(`=TABLE(${u})`);return a.ok?{ref:t,node:a.node}:void 0}function yt(n){for(const{ref:t,node:e}of n.dataTables){const o=new Set;for(const r of n.cells)r.row<t.top||r.row>t.bottom||r.col<t.left||r.col>t.right||(r.node=e,Reflect.deleteProperty(r,"unread"),o.add(`${String(r.row)}:${String(r.col)}`));for(let r=t.top;r<=t.bottom;r++)for(let s=t.left;s<=t.right;s++)o.has(`${String(r)}:${String(s)}`)||n.cells.push({row:r,col:s,value:void 0,node:e,style:0})}}class $t{cells=[];rows=[];dataTables=[];outlined=!1;rest=[];xml;masters=new Map;above=new Map;left;strings;palette;name;isRangeName;inData=!1;row=-1;nextRow=0;nextCol=0;cell;target;buffer="";skip=0;constructor(t,e,o,r){this.strings=t,this.palette=e,this.name=o,this.isRangeName=r,this.xml=new xe(this),this.xml.capture=this.rest}open(t,e){if(!this.inData){t==="sheetData"&&(this.inData=!0,this.xml.capture=void 0);return}const o=this.cell;if(o){if(this.skip>0){this.skip+=1;return}switch(t){case"v":this.target="v",this.buffer="";return;case"f":o.f={...e,text:""},this.target="f",this.buffer="";return;case"is":o.inline={text:"",runs:new $e};return;case"t":o.inline&&(this.target="t",this.buffer="");return;case"rPh":case"phoneticPr":case"extLst":this.skip=1;return;default:o.inline?.runs.open(t,e);return}}t==="row"?this.openRow(e):t==="c"&&(this.cell={r:e.r,s:e.s,t:e.t,cm:e.cm,v:void 0,f:void 0,inline:void 0})}close(t){if(!this.inData)return;const e=this.cell;if(!e){t==="sheetData"&&(this.inData=!1,this.xml.capture=this.rest);return}if(this.skip>0){this.skip-=1;return}if(t===this.target){t==="v"?e.v=this.buffer:t==="f"&&e.f?e.f.text=this.buffer:e.inline&&(e.inline.text+=this.buffer,e.inline.runs.text(this.buffer)),this.target=void 0;return}e.inline?.runs.close(t),t==="c"&&(this.cell=void 0,this.readCell(e))}text(t){this.target!==void 0&&this.skip===0&&(this.buffer+=t)}openRow(t){const e=t.r,o=e===void 0?void 0:Number(e);if(o!==void 0&&Number.isInteger(o)&&o>Q)throw new Error(`${this.name} has a row ${e??""}, and ${GRID_END}.`);const r=o!==void 0&&Number.isInteger(o)&&o>0?o-1:this.nextRow;this.row=r,this.nextRow=r+1,this.nextCol=0;const s={row:r},i=t.ht===void 0?void 0:Number(t.ht),u=f=>f==="1"||f==="true";i!==void 0&&Number.isFinite(i)&&u(t.customHeight)&&(s.height=Qe(i)),u(t.hidden)&&(s.hidden=!0);const a=t.s===void 0?void 0:Number(t.s);a!==void 0&&a!==0&&u(t.customFormat)&&(s.style=a);const l=Number(t.outlineLevel??0);l>0&&(s.level=Math.min(7,l),this.outlined=!0),Object.keys(s).length>1&&this.rows.push(s)}value(t,e){const o=t.t??"n";if(o==="inlineStr"){const s=t.inline;if(!s)return{value:t.v===void 0?"":E(t.v)};const{runs:i}=s.runs;return{value:E(s.text),...i.length>0?{runs:ve(i,this.palette)}:{}}}const r=t.v;if(r===void 0)return{value:void 0};switch(o){case"s":{const s=this.strings[Number(r)];return s?{value:s.text,...s.runs?{runs:s.runs}:{}}:{value:""}}case"str":return{value:E(r)};case"b":return{value:r.trim()==="1"||r.trim()==="true"};case"e":return{value:Be(r.trim())??He.VALUE};case"d":return{value:wt(r.trim())??r};default:{if(r.trim()==="")return{value:void 0};const s=Number(r);if(Number.isNaN(s))throw new Error(`${e} says it holds a number and holds ${r}.`);return{value:s}}}}formula(t,e,o,r){const s=t.f;if(s===void 0)return;const i=s.t??"normal",u=s.text;if(i==="dataTable"){const h=xt(s);h?this.dataTables.push(h):r.unread=`a data table's {=TABLE(${s.r1??""})}`;return}if(i==="array"){Object.assign(r,de(u,!0,this.isRangeName));const h=q(s.ref??"");h&&(r.array=h),t.cm!==void 0&&(r.dynamic=!0);return}if(i==="shared"){const h=s.si??"";if(u!==""){const S=de(u,!1,this.isRangeName),p=S.node?me(S.node,e,o):"";this.masters.set(h,{node:S.node,unread:S.unread,row:e,col:o,key:p}),Object.assign(r,S),S.node&&(r.key=p);return}const w=this.masters.get(h);if(!w){r.unread=`a shared formula of a group that has no first cell (${h})`;return}w.node?Ie(r,{node:w.node,row:w.row,col:w.col,key:w.key}):w.unread!==void 0&&(r.unread=w.unread);return}if(u==="")return;const a=de(u,!1,this.isRangeName);if(!a.node){Object.assign(r,a);return}const l=me(a.node,e,o),f=this.left?.row===e?this.left:void 0,g=[this.above.get(o),f].find(h=>h?.key===l);g?Ie(r,g):(r.node=a.node,r.key=l);const b=g??{node:a.node,row:e,col:o,key:l};this.above.set(o,b),this.left=b}readCell(t){const e=t.r===void 0?void 0:Ye(t.r,this.name),o=e?.row??this.row,r=e?.col??this.nextCol;if(r>=J)throw new Error(`${this.name} has a cell past its last column, and ${GRID_END}.`);this.nextCol=r+1;const s=t.r??ee({row:o,col:r}),{value:i,runs:u}=this.value(t,s),a={row:o,col:r,value:i,style:t.s===void 0?0:Number(t.s)||0};u&&(a.runs=u),this.formula(t,o,r,a),this.cells.push(a)}}function vt(n,t){const e=[],o=f=>e.push(`${n}: ${f}`),r=v(d(t.hyperlinks)?.hyperlink).filter(f=>c(f,"tooltip")!==void 0);r.length>0&&o(`the tooltips of ${X(r.length,"link")} (${placesLine(r.map(f=>c(f,"ref")??""))})`),t.sortState!==void 0&&o("a sort");const s=d(t.sheetProtection);y(s,"sheet")===!0&&(c(s,"password")!==void 0||c(s,"hashValue")!==void 0)&&o("its protection's password: it is protected with none"),t.protectedRanges!==void 0&&o("protected ranges");const i=d(t.headerFooter);(i?.evenHeader!==void 0||i?.evenFooter!==void 0||i?.firstHeader!==void 0||i?.firstFooter!==void 0)&&o("its print header and footer of the first or even pages");const u=d(t.printOptions);u&&["gridLines","headings","horizontalCentered","verticalCentered"].some(f=>y(u,f)===!0)&&o("its print options (gridlines, headings, centring)"),t.oleObjects!==void 0&&o("embedded objects"),t.controls!==void 0&&o("form controls"),t.dataConsolidate!==void 0&&o("a consolidation"),t.customSheetViews!==void 0&&o("custom views"),v(d(t.sheetViews)?.sheetView).some(f=>c(d(f.pane),"state")==="split")&&o("a split, not frozen, window");const l=JSON.stringify(t.extLst??"");return l.includes("sparklineGroups")&&o("sparklines"),l.includes("slicerList")&&o("slicers"),e}function kt(n,t){const e=[],o=(s,i,u)=>{const a=n.count(s);a>0&&e.push(X(a,i,u))};n.has("xl/vbaProject.bin")&&e.push("VBA macros"),o(/^xl\/pivotTables\/pivotTable\d*\.xml$/u,"pivot table"),o(/^xl\/chartsheets\/[^/]+\.xml$/u,"chart sheet"),o(/^xl\/dialogsheets\/[^/]+\.xml$/u,"dialog sheet"),o(/^xl\/macrosheets\/[^/]+\.xml$/u,"macro sheet");const r=n.names.filter(s=>s.startsWith("xl/media/")&&!t.has(s)).length;return r>0&&e.push(X(r,"image")),o(/^xl\/embeddings\//u,"embedded object"),o(/^xl\/slicers\/[^/]+\.xml$/u,"slicer part"),o(/^xl\/timelines\/[^/]+\.xml$/u,"timeline part"),o(/^xl\/ctrlProps\/[^/]+\.xml$/u,"form control"),o(/^xl\/activeX\/[^/]+\.xml$/u,"ActiveX control"),o(/^xl\/queryTables\/[^/]+\.xml$/u,"query table"),n.has("xl/connections.xml")&&e.push("data connections"),n.names.some(s=>s.startsWith("xl/richData/"))&&e.push("rich values (data types, pictures in cells)"),n.names.some(s=>/^customXml\/item\d+\.xml$/u.test(s)&&(n.text(s)??"").includes("DataMashup"))&&e.push("Power Query queries"),e}export function readHeaderFooter(n){const t={left:"",center:"",right:""};let e="center",o=new Set;for(let r=0;r<n.length;r++){const s=n[r],i=n[r+1];if(s==="&"&&(i==="L"||i==="C"||i==="R")){e=i==="L"?"left":i==="C"?"center":"right",o=new Set([...o,e]),r+=1;continue}if(s==="&"&&i==="&"){t[e]+="&&",r+=1;continue}t[e]+=s??""}return Object.fromEntries(Object.entries(t).filter(([r,s])=>s!==""||o.has(r)))}const St=new Map(Object.entries(Pe).map(([n,t])=>[t,n]));function Ct(n,t,e){const o={},r=d(n.pageSetup),s=c(r,"orientation");(s==="portrait"||s==="landscape")&&(o.orientation=s);const i=$(r,"paperSize");if(i!==void 0){const p=St.get(i);p?o.paper=p:e.push(`${t}: its paper size, Excel's number ${String(i)}`)}y(d(d(n.sheetPr)?.pageSetUpPr),"fitToPage")===!0&&(o.fit={width:$(r,"fitToWidth")??1,height:$(r,"fitToHeight")??1});const u=$(r,"scale");u!==void 0&&u!==100&&u>=10&&u<=400&&(o.scale=Math.round(u));const a=p=>v(d(n[p])?.brk).filter(m=>y(m,"man")===!0).map(m=>$(m,"id")).filter(m=>m!==void 0&&m>0).sort((m,C)=>m-C),l=a("rowBreaks").map(p=>p+1),f=a("colBreaks").map(p=>te(p));(l.length>0||f.length>0)&&(o.breaks={...l.length>0?{rows:l}:{},...f.length>0?{cols:f}:{}});const g=d(n.pageMargins),b={};for(const p of Object.keys(ce)){const m=$(g,p);m!==void 0&&m!==ce[p]&&(b[p]=m)}Object.keys(b).length>0&&(o.margins=b);const h=d(n.headerFooter),w=O(h?.oddHeader),S=O(h?.oddFooter);return w!==""&&(o.header=readHeaderFooter(E(w))),S!==""&&(o.footer=readHeaderFooter(E(S))),o}function Tt(n,t,e,o,r){const s=n.rels(t),i=new Map;for(const a of s.filter(l=>l.type==="comments")){const l=d(n.xml(a.target)?.comments),f=d(l?.authors)?.author,g=(Array.isArray(f)?f:f===void 0?[]:[f]).map(b=>E(O(b)));for(const b of v(d(l?.commentList)?.comment)){const h=c(b,"ref")??"",w=d(b.text),S=v(w?.r),p=E(S.length>0?S.map(C=>O(C.t)).join(""):O(w?.t)),m=g[$(b,"authorId")??-1];h!==""&&p!==""&&i.set(h,{ref:h,text:p,...m===void 0||m===""?{}:{author:m}})}}let u=0;for(const a of s.filter(l=>l.type==="threadedComment")){const l=d(n.xml(a.target)?.ThreadedComments),f=new Map;for(const g of v(l?.threadedComment)){const b=c(g,"ref")??"",h=E(O(g.text)),w=f.get(b)??{texts:[]};if(w.texts.length===0){const S=o.get(c(g,"personId")??"");S!==void 0&&(w.author=S)}w.texts.push(h),f.set(b,w)}for(const[g,b]of f)u+=1,i.set(g,{ref:g,text:b.texts.join(`
|
|
3
|
-
`),...
|
|
2
|
+
import{ZipLimitError as Re}from"@allyhub/formats";import{SHEET_FILTER_OPERATORS as Me,SHEET_ICONS as _e,SHEET_MARGINS as fe,SHEET_OPERATORS as Pe,SHEET_PAPERS as De,SHEET_VALIDATIONS as je}from"@allyhub/formats";import{MAX_COLUMNS as J,MAX_ROWS as Y,cellName as te,columnLetter as ne,readAddress as he,readArea as U,readAreas as oe}from"../address.js";import{ITERATION_DEFAULTS as pe}from"../calc/engine.js";import{SHEET_CHART_DEFAULTS as me}from"../chart.js";import{moveFormula as ze,relativeKey as ge}from"../formula/move.js";import{parseFormula as He}from"../formula/parse.js";import{printFormula as be}from"../formula/print.js";import{ERR as Be,errorOf as Ve,serialOfDate as Ue}from"../values.js";import{OFFICE_THEME as We,colorOf as P,paletteOf as we,themeColors as qe}from"./colors.js";import{chartAnchors as Xe,readChart as Ge}from"./charts.js";import{isRangeText as Ze,readFileFormula as re}from"./formula.js";import{BUILTIN_FORMATS as xe}from"./numfmt.js";import{XmlStream as ye}from"./sax.js";import{attr as c,flag as x,numberAttr as y,readXml as $e,readXstring as A,tag as d,tags as v,textOf as N}from"./xml.js";import{RunsCollector as ve,readRuns as ke}from"./runs.js";import{ZipIn as Je}from"./zip.js";function Ke(n){if(x(n,"iterate")!==!0)return;const t=y(n,"iterateCount"),e=y(n,"iterateDelta"),o=t===void 0?void 0:Math.min(32767,Math.max(1,Math.round(t))),r=e===void 0?void 0:Math.max(0,e),s={...o===void 0||o===pe.max_iterations?{}:{max_iterations:o},...r===void 0||r===pe.max_change?{}:{max_change:r}};return Object.keys(s).length>0?s:!0}const Se=7,Qe=n=>Math.floor((256*n+Math.floor(128/Se))/256*Se),Ye=n=>Math.round(n*4/3),se=5;export function placesLine(n){const t=n.slice(0,se).join(", ");return n.length>se?`${t} and ${String(n.length-se)} more`:t}const W=(n,t,e=`${t}s`)=>`${String(n)} ${n===1?t:e}`;export const GRID_END=`Excel's grid ends at ${ne(J-1)}${String(Y)} (${Y.toLocaleString("en-US")} rows, ${J.toLocaleString("en-US")} columns)`;function et(n,t){let e=0,o=0;const r=n.length;for(;e<r;e++){const i=n.charCodeAt(e),u=i>=65&&i<=90,a=i>=97&&i<=122;if(!u&&!a)break;o=o*26+(u?i-64:i-96)}if(e===0||e===r)return;let s=0;for(let i=e;i<r;i++){const u=n.charCodeAt(i);if(u<48||u>57)return;s=s*10+u-48}if(s!==0){if(e>3||o>J||s>Y)throw new Error(`${t} has a cell at ${n}, and ${GRID_END}.`);return{row:s-1,col:o-1}}}class tt{zip;constructor(t,e){this.zip=new Je(t,e)}get names(){return this.zip.names}has(t){return this.zip.has(t)}text(t){return this.zip.text(t)}bytes(t){return this.zip.bytesOf(t)}xml(t){const e=this.text(t);return e===void 0?void 0:$e(e)}stream(t,e){const o=this.zip.streamText(t,r=>{e.push(r)});return o&&e.end(),o}rels(t){const e=t.lastIndexOf("/"),o=`${t.slice(0,e+1)}_rels/${t.slice(e+1)}.rels`,r=this.xml(o);return v(d(r?.Relationships)?.Relationship).map(s=>{const i=c(s,"Type")??"",u=c(s,"Target")??"",a=c(s,"TargetMode")==="External";return{id:c(s,"Id")??"",type:i.slice(i.lastIndexOf("/")+1),target:a?u:nt(t,u),external:a}})}count(t){return this.names.filter(e=>t.test(e)).length}}function nt(n,t){if(t.startsWith("/"))return t.slice(1);const e=n.split("/").slice(0,-1);for(const o of t.split("/"))o===".."?e.pop():o!=="."&&e.push(o);return e.join("/")}function ot(n,t,e){const o=[];if(t===void 0)return o;let r,s=0,i=!1;const u={open(a,l){if(a==="si"){r={text:"",runs:new ve};return}if(r){if(s>0||a==="rPh"||a==="phoneticPr"||a==="extLst"){s+=1;return}r.runs.open(a,l)||a==="t"&&(i=!0)}},close(a){if(s>0){s-=1;return}if(a==="si"){if(r){const{runs:l}=r.runs;o.push({text:A(r.text),...l.length>0?{runs:ke(l,e)}:{}})}r=void 0;return}r?.runs.close(a),a==="t"&&(i=!1)},text(a){r&&i&&s===0&&(r.text+=a,r.runs.text(a))}};return n.stream(t,new ye(u)),o}function q(n,t){const e=n[t];if(e===void 0)return!1;const o=c(d(e),"val");return o===void 0||o!=="0"&&o!=="false"}const rt=new Set(["double","singleAccounting","doubleAccounting"]);function st(n,t,e){const o={},r=(a,l)=>c(d(a?.[l]),"val");if(q(n,"b")&&(o.bold=!0),q(n,"i")&&(o.italic=!0),q(n,"strike")&&(o.strike=!0),q(n,"u")){const a=r(n,"u");o.underline=a!==void 0&&rt.has(a)?a:!0}const s=r(n,"name");s!==void 0&&s!==r(t,"name")&&(o.font=s);const i=r(n,"sz");i!==void 0&&i!==r(t,"sz")&&(o.size=Number(i));const u=P(d(n.color),e);return u!==void 0&&u!==P(d(t?.color),e)&&(o.color=u),o}function it(n,t){const e=d(n.patternFill),o=c(e,"patternType");if(o===void 0||o==="none")return;const r=P(d(e?.fgColor),t),s=P(d(e?.bgColor),t);return o==="solid"&&r!==void 0?r:{pattern:o,...r===void 0?{}:{color:r},...s===void 0?{}:{background:s}}}function Ce(n,t){const e={};for(const o of["left","right","top","bottom"]){const r=d(n[o]),s=c(r,"style");if(s===void 0||s==="none")continue;const i=P(d(r?.color),t);e[o]={style:s,...i===void 0?{}:{color:i}}}return Object.keys(e).length===0?void 0:e}function at(n){const t={},e=c(n,"horizontal");e!==void 0&&e!=="general"&&(t.align=e);const o=c(n,"vertical");o!==void 0&&o!=="bottom"&&(t.valign=o),x(n,"wrapText")===!0&&(t.wrap=!0),x(n,"shrinkToFit")===!0&&(t.shrink=!0);const r=y(n,"indent");r!==void 0&&r>0&&(t.indent=r);const s=y(n,"textRotation");return s!==void 0&&s>0&&s<=180&&(t.rotation=s),t}function Te(n,t){const e={},o=d(n.font);if(o){const f=(m,w)=>{o[m]!==void 0&&(e[w]=q(o,m))};f("b","bold"),f("i","italic"),f("strike","strike"),o.u!==void 0&&(e.underline=q(o,"u"));const g=P(d(o.color),t);g!==void 0&&(e.color=g)}const r=d(d(n.fill)?.patternFill),s=P(d(r?.bgColor),t)??P(d(r?.fgColor),t);s!==void 0&&(e.fill=s);const i=d(n.border),u=i&&Ce(i,t);u!==void 0&&(e.border=u);const a=d(n.numFmt),l=c(a,"formatCode")??xe[y(a,"numFmtId")??-1];return a&&l!==void 0&&l!==""&&l!=="General"&&(e.format=l),e}function dt(n,t){const e=d(n?.styleSheet),o=we(t,e),r=new Map(v(d(e?.numFmts)?.numFmt).map(h=>[y(h,"numFmtId")??-1,c(h,"formatCode")?.replace(/^$/u,"General")??"General"])),s=v(d(e?.fonts)?.font),i=v(d(e?.fills)?.fill),u=v(d(e?.borders)?.border),a=v(d(e?.cellXfs)?.xf),l=s[y(a[0],"fontId")??0],f=new Set;i.some(h=>h.gradientFill!==void 0)&&f.add("gradient fills");const g=v(d(e?.cellStyles)?.cellStyle),m=new Set(a.map(h=>y(h,"xfId")??0)),w=g.filter(h=>y(h,"builtinId")!==0&&m.has(y(h,"xfId")??-1)).map(h=>A(c(h,"name")??"")).filter(h=>h!=="");w.length>0&&f.add(`the names of cell styles (${w.slice(0,5).join(", ")}${w.length>5?", …":""}): their looks are kept`);const p=a.map(h=>{const C={},E=s[y(h,"fontId")??0];E&&(Object.assign(C,st(E,l,o)),E.vertAlign!==void 0&&f.add("superscript and subscript"));const M=i[y(h,"fillId")??0],F=M&&it(M,o);F!==void 0&&(C.fill=F);const L=u[y(h,"borderId")??0],D=L&&Ce(L,o);D!==void 0&&(C.border=D),L&&c(d(L.diagonal),"style")!==void 0&&f.add("diagonal borders");const R=d(h.alignment);R&&(Object.assign(C,at(R)),y(R,"textRotation")===255&&f.add("vertical text"));const H=d(h.protection);x(H,"locked")===!1&&(C.locked=!1),x(H,"hidden")===!0&&(C.hide_formula=!0);const B=y(h,"numFmtId")??0,j=r.get(B)??xe[B];return j!==void 0&&j!=="General"&&(C.format=j),C}),$=c(d(l?.name),"val"),k=c(d(l?.sz),"val");return{looks:p,dxfs:v(d(e?.dxfs)?.dxf).map(h=>Te(h,o)),font:{...$===void 0?{}:{name:$},...k===void 0?{}:{size:Number(k)}},lost:[...f]}}const lt=n=>{const t=Number(n);return n.trim()!==""&&Number.isFinite(t)?t:n};function ut(n,t){const e=d(n.customFilters);if(e){const i=v(e.customFilter).map(u=>({operator:c(u,"operator")??"equal",value:lt(A(c(u,"val")??""))}));return i.length===0||i.length>2||i.some(u=>!Me.includes(u.operator))?void 0:{conditions:i,...i.length===2&&x(e,"and")!==!0?{or:!0}:{}}}const o=d(n.top10);if(o){const i=y(o,"val");return i===void 0||i<=0?void 0:{top:{count:i,...x(o,"percent")===!0?{percent:!0}:{},...x(o,"top")===!1?{bottom:!0}:{}}}}const r=c(d(n.dynamicFilter),"type");if(r==="aboveAverage")return{average:"above"};if(r==="belowAverage")return{average:"below"};const s=d(n.colorFilter);if(s){const i=t[y(s,"dxfId")??-1];return x(s,"cellColor")===!1?i?.color?{color:{font:i.color}}:void 0:typeof i?.fill=="string"?{color:{fill:i.fill}}:void 0}}function Ee(n,t=[]){const e=new Map;let o=0;for(const r of v(n.filterColumn)){const s=y(r,"colId")??0,i=d(r.filters);if(!i){const a=ut(r,t);a?e.set(s,a):Object.keys(r).some(l=>l!=="colId"&&l!=="hiddenButton")&&(o+=1);continue}if(i.dateGroupItem!==void 0){o+=1;continue}const u=v(i.filter).map(a=>A(c(a,"val")??""));e.set(s,{...u.length===0?{}:{values:u},...x(i,"blank")===!0?{blanks:!0}:{}})}return{columns:e,unread:o}}function ct(n,t=[]){const e=d(n?.table),o=U(c(e,"ref")??""),r=c(e,"displayName")??c(e,"name");if(!o||r===void 0)return;const s=d(e?.tableStyleInfo),i=d(e?.autoFilter);return{name:r,ref:o,headers:y(e,"headerRowCount")??1,totals:y(e,"totalsRowCount")??0,columns:v(d(e?.tableColumns)?.tableColumn).map(u=>({name:A(c(u,"name")??"").trim(),calculated:u.calculatedColumnFormula!==void 0})),style:c(s,"name")??"none",options:{...x(s,"showRowStripes")===!1?{banded_rows:!1}:{},...x(s,"showColumnStripes")===!0?{banded_columns:!0}:{},...x(s,"showFirstColumn")===!0?{first_column:!0}:{},...x(s,"showLastColumn")===!0?{last_column:!0}:{}},...i?{filter:Ee(i,t)}:{}}}function ie(n){const t=n.trim();if(t==="")return;const e=/^"((?:[^"]|"")*)"$/u.exec(t);if(e)return(e[1]??"").replaceAll('""','"');const o=Number(t);if(!Number.isNaN(o))return o;const r=re(t,!0);return r.ok?be(r.node):void 0}const Oe=n=>n!==void 0&&Pe.includes(n);function ae(n){const t=c(n,"type")??"num",e=c(n,"val")??(n.f===void 0?void 0:N(n.f)),o=e===void 0?void 0:ie(e);return{at:t,...o===void 0?{}:{value:o}}}const ft=_e,ht=n=>{const t=n.formula??n.f;return(Array.isArray(t)?t:t===void 0?[]:[t]).map(N)};function pt(n,t,e,o){const r=c(n,"type")??"",s={range:t,...x(n,"stopIfTrue")===!0?{stop:!0}:{}},i={...e.bold===void 0?{}:{bold:e.bold},...e.italic===void 0?{}:{italic:e.italic},...e.underline===void 0?{}:{underline:e.underline!==!1},...e.strike===void 0?{}:{strike:e.strike},...e.color===void 0?{}:{color:e.color},...typeof e.fill=="string"?{fill:e.fill}:{},...e.border===void 0?{}:{border:e.border},...e.format===void 0?{}:{format:e.format}},u=ht(n);switch(r){case"cellIs":{const a=c(n,"operator"),l=u.flatMap(f=>{const g=ie(f);return g===void 0?[]:[g]});return!Oe(a)||l.length===0?`a cellIs rule of ${a??"no operator"}`:{...s,...i,type:"cellIs",operator:a,formula:l}}case"containsText":case"notContainsText":case"beginsWith":case"endsWith":{const a=c(n,"text");return a===void 0?`a ${r} rule with no text`:{...s,...i,type:"containsText",...r==="containsText"?{}:{operator:r==="notContainsText"?"notContains":r},text:A(a)}}case"duplicateValues":case"uniqueValues":return{...s,...i,type:r};case"top10":return{...s,...i,type:"top10",rank:y(n,"rank")??10,...x(n,"percent")===!0?{percent:!0}:{},...x(n,"bottom")===!0?{bottom:!0}:{}};case"aboveAverage":return y(n,"stdDev")!==void 0?"an above or below average rule by standard deviations":{...s,...i,type:"aboveAverage",...x(n,"aboveAverage")===!1?{below:!0}:{},...x(n,"equalAverage")===!0?{equal:!0}:{}};case"expression":{const a=u[0]===void 0?void 0:re(u[0],!0);return a?.ok?{...s,...i,type:"expression",formula:be(a.node)}:"an expression rule that cannot be read"}case"dataBar":{const a=d(n.dataBar),l=P(d(a?.color??a?.fillColor),o),[f,g]=v(a?.cfvo).map(ae);return l===void 0?"a data bar with no colour":{...s,type:"dataBar",color:l,...f&&f.at!=="min"?{min:f}:{},...g&&g.at!=="max"?{max:g}:{},...x(a,"showValue")===!1?{show:!1}:{}}}case"colorScale":{const a=d(n.colorScale),l=v(a?.cfvo).map(ae),f=v(a?.color).map(m=>P(m,o)),g=l.flatMap((m,w)=>{const p=f[w];return p===void 0?[]:[{...m,color:p}]});return g.length<2?"a colour scale with too few stops":{...s,type:"colorScale",stops:g.slice(0,3)}}case"iconSet":{const a=d(n.iconSet),l=c(a,"iconSet")??"3TrafficLights1";if(!ft.includes(l))return`the icon set ${l}`;if(a?.cfIcon!==void 0)return"an icon set of icons chosen one by one";const f=v(a?.cfvo).map(ae);return{...s,type:"iconSet",icons:l,...f.length>=3?{stops:f.slice(0,5)}:{},...x(a,"reverse")===!0?{reverse:!0}:{},...x(a,"showValue")===!1?{show:!1}:{}}}default:return`a ${r} rule`}}const Ae={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},Ne=(n,t)=>v(d(n.extLst)?.ext).find(e=>c(e,"uri")?.toUpperCase()===t.toUpperCase());function mt(n,t,e){const o=[],r=[],s=new Set,i=(a,l,f)=>{const g=pt(a,l,f,e);typeof g=="string"?r.push(`${g} on ${l}`):o.push({priority:y(a,"priority")??0,rule:g})};for(const a of v(n.conditionalFormatting)){const l=c(a,"sqref")??"";if(!oe(l)){r.push(`a rule on ${l}`);continue}for(const f of v(a.cfRule)){const g=N(d(d(f.extLst)?.ext)?.id);g!==""&&s.add(g.toUpperCase());const m=y(f,"dxfId");i(f,l,m===void 0?{}:t[m]??{})}}const u=d(Ne(n,Ae.conditional)?.conditionalFormattings);for(const a of v(u?.conditionalFormatting)){const l=N(a.sqref).trim();for(const f of v(a.cfRule)){if(s.has((c(f,"id")??"").toUpperCase())){const m=gt(d(f.dataBar));m!==void 0&&r.push(`a data bar's ${m} on ${l}`);continue}if(!oe(l)){r.push(`a rule on ${l}`);continue}const g=d(f.dxf);i(f,l,g?Te(g,e):{})}}return{rules:o.sort((a,l)=>a.priority-l.priority).map(a=>a.rule),unread:r}}function gt(n){if(!n)return;const t=[];x(n,"gradient")===!1&&t.push("solid fill"),x(n,"border")===!0&&t.push("border");const e=c(n,"axisPosition");e!==void 0&&e!=="automatic"&&t.push(`axis ${e}`),x(n,"negativeBarColorSameAsPositive")===!0&&t.push("negative bars in its colour");const o=c(d(n.negativeFillColor),"rgb");return o!==void 0&&o.toUpperCase()!=="FFFF0000"&&t.push("negative bars' colour"),c(n,"direction")==="rightToLeft"&&t.push("right to left"),t.length===0?void 0:t.join(", ")}const bt=je;function Ie(n,t,e,o){const r=c(n,"type")??"none";if(r==="none"&&c(n,"prompt")===void 0)return;if(!bt.includes(r)||!oe(t))return`a ${r} rule on ${t}`;const s=/^"((?:[^"]|"")*)"$/u.exec(e.trim()),i=r==="list"&&s?(s[1]??"").replaceAll('""','"').split(","):void 0,u=[e,o].flatMap(p=>{const $=ie(p);return $===void 0?[]:[$]}),a=c(n,"operator"),l=p=>Object.fromEntries(Object.entries(p).filter(([,$])=>$!==void 0)),f=l({title:c(n,"promptTitle"),message:c(n,"prompt")}),g=l({style:c(n,"errorStyle"),title:c(n,"errorTitle"),message:c(n,"error")}),m=x(n,"showInputMessage")!==!0,w=x(n,"showErrorMessage")!==!0;return{range:t,type:r,...Oe(a)&&a!=="between"?{operator:a}:{},...i?{values:i}:{formula:u},...x(n,"allowBlank")===!0?{}:{blank:!1},...x(n,"showDropDown")===!0?{dropdown:!1}:{},...m||Object.keys(f).length>0?{prompt:{...f,...m?{show:!1}:{}}}:{},...w||Object.keys(g).length>0?{error:{...g,...w?{show:!1}:{}}}:{}}}function wt(n){const t=[],e=[],o=s=>{typeof s=="string"?e.push(s):s&&t.push(s)};for(const s of v(d(n.dataValidations)?.dataValidation))o(Ie(s,c(s,"sqref")??"",N(s.formula1),N(s.formula2)));const r=d(Ne(n,Ae.validations)?.dataValidations);for(const s of v(r?.dataValidation))o(Ie(s,N(s.sqref).trim(),N(d(s.formula1)?.f),N(d(s.formula2)?.f)));return{rules:t,unread:e}}function xt(n){const t=/^(-?\d{4,})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?)?(?:Z|[+-]\d{2}:?\d{2})?$/u.exec(n)??/^()()()(\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/u.exec(n);if(!t)return;const e=t[1]==="",o=e?1899:Number(t[1]),r=e?12:Number(t[2]),s=e?30:Number(t[3]),i=Number(t[4]??0)*3600+Number(t[5]??0)*60+Number(t[6]??0)+Number(t[7]??0),u=new Date(Date.UTC(o,r-1,s)+i*1e3);if(Number.isNaN(u.getTime()))return;const a=Ue(u);return e?a-Math.floor(a):a}let de;function Fe(n,t){const e=n.row-t.row,o=n.col-t.col;Object.defineProperty(n,"node",{get:()=>(de?.cell!==n&&(de={cell:n,node:ze(t.node,e,o)}),de.node),set:r=>{Object.defineProperty(n,"node",{value:r,writable:!0,enumerable:!0,configurable:!0})},enumerable:!0,configurable:!0}),n.key=t.key}function le(n,t,e){const o=re(n,t,e);return o.ok?{node:o.node}:{unread:n}}function yt(n){const t=U(n.ref??""),e=l=>{if(l===void 0||l==="")return"";const f=he(l.replaceAll("$",""));return f?`$${ne(f.col)}$${String(f.row+1)}`:void 0},o=e(n.r1),r=e(n.r2);if(!t||o===void 0||o===""||r===void 0)return;const s=n.dt2D==="1"||n.dt2D==="true",i=n.dtr==="1"||n.dtr==="true",u=s?`${o},${r}`:i?`${o},`:`,${o}`,a=He(`=TABLE(${u})`);return a.ok?{ref:t,node:a.node}:void 0}function $t(n){for(const{ref:t,node:e}of n.dataTables){const o=new Set;for(const r of n.cells)r.row<t.top||r.row>t.bottom||r.col<t.left||r.col>t.right||(r.node=e,Reflect.deleteProperty(r,"unread"),o.add(`${String(r.row)}:${String(r.col)}`));for(let r=t.top;r<=t.bottom;r++)for(let s=t.left;s<=t.right;s++)o.has(`${String(r)}:${String(s)}`)||n.cells.push({row:r,col:s,value:void 0,node:e,style:0})}}class vt{cells=[];rows=[];dataTables=[];outlined=!1;rest=[];xml;masters=new Map;above=new Map;left;strings;palette;name;isRangeName;inData=!1;row=-1;nextRow=0;nextCol=0;cell;target;buffer="";skip=0;constructor(t,e,o,r){this.strings=t,this.palette=e,this.name=o,this.isRangeName=r,this.xml=new ye(this),this.xml.capture=this.rest}open(t,e){if(!this.inData){t==="sheetData"&&(this.inData=!0,this.xml.capture=void 0);return}const o=this.cell;if(o){if(this.skip>0){this.skip+=1;return}switch(t){case"v":this.target="v",this.buffer="";return;case"f":o.f={...e,text:""},this.target="f",this.buffer="";return;case"is":o.inline={text:"",runs:new ve};return;case"t":o.inline&&(this.target="t",this.buffer="");return;case"rPh":case"phoneticPr":case"extLst":this.skip=1;return;default:o.inline?.runs.open(t,e);return}}t==="row"?this.openRow(e):t==="c"&&(this.cell={r:e.r,s:e.s,t:e.t,cm:e.cm,v:void 0,f:void 0,inline:void 0})}close(t){if(!this.inData)return;const e=this.cell;if(!e){t==="sheetData"&&(this.inData=!1,this.xml.capture=this.rest);return}if(this.skip>0){this.skip-=1;return}if(t===this.target){t==="v"?e.v=this.buffer:t==="f"&&e.f?e.f.text=this.buffer:e.inline&&(e.inline.text+=this.buffer,e.inline.runs.text(this.buffer)),this.target=void 0;return}e.inline?.runs.close(t),t==="c"&&(this.cell=void 0,this.readCell(e))}text(t){this.target!==void 0&&this.skip===0&&(this.buffer+=t)}openRow(t){const e=t.r,o=e===void 0?void 0:Number(e);if(o!==void 0&&Number.isInteger(o)&&o>Y)throw new Error(`${this.name} has a row ${e??""}, and ${GRID_END}.`);const r=o!==void 0&&Number.isInteger(o)&&o>0?o-1:this.nextRow;this.row=r,this.nextRow=r+1,this.nextCol=0;const s={row:r},i=t.ht===void 0?void 0:Number(t.ht),u=f=>f==="1"||f==="true";i!==void 0&&Number.isFinite(i)&&u(t.customHeight)&&(s.height=Ye(i)),u(t.hidden)&&(s.hidden=!0);const a=t.s===void 0?void 0:Number(t.s);a!==void 0&&a!==0&&u(t.customFormat)&&(s.style=a);const l=Number(t.outlineLevel??0);l>0&&(s.level=Math.min(7,l),this.outlined=!0),Object.keys(s).length>1&&this.rows.push(s)}value(t,e){const o=t.t??"n";if(o==="inlineStr"){const s=t.inline;if(!s)return{value:t.v===void 0?"":A(t.v)};const{runs:i}=s.runs;return{value:A(s.text),...i.length>0?{runs:ke(i,this.palette)}:{}}}const r=t.v;if(r===void 0)return{value:void 0};switch(o){case"s":{const s=this.strings[Number(r)];return s?{value:s.text,...s.runs?{runs:s.runs}:{}}:{value:""}}case"str":return{value:A(r)};case"b":return{value:r.trim()==="1"||r.trim()==="true"};case"e":return{value:Ve(r.trim())??Be.VALUE};case"d":return{value:xt(r.trim())??r};default:{if(r.trim()==="")return{value:void 0};const s=Number(r);if(Number.isNaN(s))throw new Error(`${e} says it holds a number and holds ${r}.`);return{value:s}}}}formula(t,e,o,r){const s=t.f;if(s===void 0)return;const i=s.t??"normal",u=s.text;if(i==="dataTable"){const w=yt(s);w?this.dataTables.push(w):r.unread=`a data table's {=TABLE(${s.r1??""})}`;return}if(i==="array"){Object.assign(r,le(u,!0,this.isRangeName));const w=U(s.ref??"");w&&(r.array=w),t.cm!==void 0&&(r.dynamic=!0);return}if(i==="shared"){const w=s.si??"";if(u!==""){const $=le(u,!1,this.isRangeName),k=$.node?ge($.node,e,o):"";this.masters.set(w,{node:$.node,unread:$.unread,row:e,col:o,key:k}),Object.assign(r,$),$.node&&(r.key=k);return}const p=this.masters.get(w);if(!p){r.unread=`a shared formula of a group that has no first cell (${w})`;return}p.node?Fe(r,{node:p.node,row:p.row,col:p.col,key:p.key}):p.unread!==void 0&&(r.unread=p.unread);return}if(u==="")return;const a=le(u,!1,this.isRangeName);if(!a.node){Object.assign(r,a);return}const l=ge(a.node,e,o),f=this.left?.row===e?this.left:void 0,g=[this.above.get(o),f].find(w=>w?.key===l);g?Fe(r,g):(r.node=a.node,r.key=l);const m=g??{node:a.node,row:e,col:o,key:l};this.above.set(o,m),this.left=m}readCell(t){const e=t.r===void 0?void 0:et(t.r,this.name),o=e?.row??this.row,r=e?.col??this.nextCol;if(r>=J)throw new Error(`${this.name} has a cell past its last column, and ${GRID_END}.`);this.nextCol=r+1;const s=t.r??te({row:o,col:r}),{value:i,runs:u}=this.value(t,s),a={row:o,col:r,value:i,style:t.s===void 0?0:Number(t.s)||0};u&&(a.runs=u),this.formula(t,o,r,a),this.cells.push(a)}}function kt(n,t){const e=[],o=f=>e.push(`${n}: ${f}`),r=v(d(t.hyperlinks)?.hyperlink).filter(f=>c(f,"tooltip")!==void 0);r.length>0&&o(`the tooltips of ${W(r.length,"link")} (${placesLine(r.map(f=>c(f,"ref")??""))})`),t.sortState!==void 0&&o("a sort");const s=d(t.sheetProtection);x(s,"sheet")===!0&&(c(s,"password")!==void 0||c(s,"hashValue")!==void 0)&&o("its protection's password: it is protected with none"),t.protectedRanges!==void 0&&o("protected ranges");const i=d(t.headerFooter);(i?.evenHeader!==void 0||i?.evenFooter!==void 0||i?.firstHeader!==void 0||i?.firstFooter!==void 0)&&o("its print header and footer of the first or even pages");const u=d(t.printOptions);u&&["gridLines","headings","horizontalCentered","verticalCentered"].some(f=>x(u,f)===!0)&&o("its print options (gridlines, headings, centring)"),t.oleObjects!==void 0&&o("embedded objects"),t.controls!==void 0&&o("form controls"),t.dataConsolidate!==void 0&&o("a consolidation"),t.customSheetViews!==void 0&&o("custom views"),v(d(t.sheetViews)?.sheetView).some(f=>c(d(f.pane),"state")==="split")&&o("a split, not frozen, window");const l=JSON.stringify(t.extLst??"");return l.includes("sparklineGroups")&&o("sparklines"),l.includes("slicerList")&&o("slicers"),e}function St(n,t){const e=[],o=(s,i,u)=>{const a=n.count(s);a>0&&e.push(W(a,i,u))};n.has("xl/vbaProject.bin")&&e.push("VBA macros"),o(/^xl\/pivotTables\/pivotTable\d*\.xml$/u,"pivot table"),o(/^xl\/chartsheets\/[^/]+\.xml$/u,"chart sheet"),o(/^xl\/dialogsheets\/[^/]+\.xml$/u,"dialog sheet"),o(/^xl\/macrosheets\/[^/]+\.xml$/u,"macro sheet");const r=n.names.filter(s=>s.startsWith("xl/media/")&&!t.has(s)).length;return r>0&&e.push(W(r,"image")),o(/^xl\/embeddings\//u,"embedded object"),o(/^xl\/slicers\/[^/]+\.xml$/u,"slicer part"),o(/^xl\/timelines\/[^/]+\.xml$/u,"timeline part"),o(/^xl\/ctrlProps\/[^/]+\.xml$/u,"form control"),o(/^xl\/activeX\/[^/]+\.xml$/u,"ActiveX control"),o(/^xl\/queryTables\/[^/]+\.xml$/u,"query table"),n.has("xl/connections.xml")&&e.push("data connections"),n.names.some(s=>s.startsWith("xl/richData/"))&&e.push("rich values (data types, pictures in cells)"),n.names.some(s=>/^customXml\/item\d+\.xml$/u.test(s)&&(n.text(s)??"").includes("DataMashup"))&&e.push("Power Query queries"),e}export function readHeaderFooter(n){const t={left:"",center:"",right:""};let e="center",o=new Set;for(let r=0;r<n.length;r++){const s=n[r],i=n[r+1];if(s==="&"&&(i==="L"||i==="C"||i==="R")){e=i==="L"?"left":i==="C"?"center":"right",o=new Set([...o,e]),r+=1;continue}if(s==="&"&&i==="&"){t[e]+="&&",r+=1;continue}t[e]+=s??""}return Object.fromEntries(Object.entries(t).filter(([r,s])=>s!==""||o.has(r)))}const Ct=new Map(Object.entries(De).map(([n,t])=>[t,n]));function Tt(n,t,e){const o={},r=d(n.pageSetup),s=c(r,"orientation");(s==="portrait"||s==="landscape")&&(o.orientation=s);const i=y(r,"paperSize");if(i!==void 0){const k=Ct.get(i);k?o.paper=k:e.push(`${t}: its paper size, Excel's number ${String(i)}`)}x(d(d(n.sheetPr)?.pageSetUpPr),"fitToPage")===!0&&(o.fit={width:y(r,"fitToWidth")??1,height:y(r,"fitToHeight")??1});const u=y(r,"scale");u!==void 0&&u!==100&&u>=10&&u<=400&&(o.scale=Math.round(u));const a=k=>v(d(n[k])?.brk).filter(h=>x(h,"man")===!0).map(h=>y(h,"id")).filter(h=>h!==void 0&&h>0).sort((h,C)=>h-C),l=a("rowBreaks").map(k=>k+1),f=a("colBreaks").map(k=>ne(k));(l.length>0||f.length>0)&&(o.breaks={...l.length>0?{rows:l}:{},...f.length>0?{cols:f}:{}});const g=d(n.pageMargins),m={};for(const k of Object.keys(fe)){const h=y(g,k);h!==void 0&&h!==fe[k]&&(m[k]=h)}Object.keys(m).length>0&&(o.margins=m);const w=d(n.headerFooter),p=N(w?.oddHeader),$=N(w?.oddFooter);return p!==""&&(o.header=readHeaderFooter(A(p))),$!==""&&(o.footer=readHeaderFooter(A($))),o}function Et(n,t,e,o,r){const s=n.rels(t),i=new Map;for(const a of s.filter(l=>l.type==="comments")){const l=d(n.xml(a.target)?.comments),f=d(l?.authors)?.author,g=(Array.isArray(f)?f:f===void 0?[]:[f]).map(m=>A(N(m)));for(const m of v(d(l?.commentList)?.comment)){const w=c(m,"ref")??"",p=d(m.text),$=v(p?.r),k=A($.length>0?$.map(C=>N(C.t)).join(""):N(p?.t)),h=g[y(m,"authorId")??-1];w!==""&&k!==""&&i.set(w,{ref:w,text:k,...h===void 0||h===""?{}:{author:h}})}}let u=0;for(const a of s.filter(l=>l.type==="threadedComment")){const l=d(n.xml(a.target)?.ThreadedComments),f=new Map;for(const g of v(l?.threadedComment)){const m=c(g,"ref")??"",w=A(N(g.text)),p=f.get(m)??{texts:[]};if(p.texts.length===0){const $=o.get(c(g,"personId")??"");$!==void 0&&(p.author=$)}p.texts.push(w),f.set(m,p)}for(const[g,m]of f)u+=1,i.set(g,{ref:g,text:m.texts.join(`
|
|
3
|
+
`),...m.author===void 0?{}:{author:m.author}})}return u>0&&r.push(`${e}: ${W(u,"threaded comment")}, kept as notes, replies after the first line`),[...i.values()]}function Ot(n,t,e,o,r,s,i,u,a,l,f,g){const m=new vt(r,s,e,a);if(!n.stream(t,m.xml))throw new Error(`${t} is not in the file.`);$t(m);const w=$e(m.rest.join("")),p=d(w.worksheet);if(!p)throw new Error(`${t} is not a worksheet.`);const $=v(d(p.cols)?.col).map(S=>{const T=y(S,"width"),_=y(S,"style"),O=y(S,"outlineLevel")??0,Z=(y(S,"min")??1)-1,ue=(y(S,"max")??1)-1;if(ue>=J)throw new Error(`${e} sets a column past its last, and ${GRID_END}.`);const ce=x(S,"customWidth"),ee=T===void 0?void 0:Qe(T);return{min:Z,max:ue,...ee!==void 0&&(ce===!0||ce===void 0&&ee!==Le)?{width:ee}:{},...x(S,"hidden")===!0?{hidden:!0}:{},..._===void 0||_===0?{}:{style:_},...O>0?{level:Math.min(7,O)}:{}}}),k=v(d(p.mergeCells)?.mergeCell).flatMap(S=>{const T=U(c(S,"ref")??"");return T?[T]:[]}),h=v(d(p.sheetViews)?.sheetView)[0],C=d(h?.pane);let E;const M=c(C,"state");if(M==="frozen"||M==="frozenSplit"){const S=he(c(h,"topLeftCell")??"A1")??{row:0,col:0};E={row:S.row+(y(C,"ySplit")??0),col:S.col+(y(C,"xSplit")??0)}}const F=n.rels(t),L=F.filter(S=>S.type==="table").flatMap(S=>{const T=ct(n.xml(S.target),i);return T?[T]:[]}),D=P(d(d(p.sheetPr)?.tabColor),s),R=kt(e,p),H=mt(p,i,s),B=wt(p);for(const S of H.unread)R.push(`${e}: a conditional format, ${S}`);for(const S of B.unread)R.push(`${e}: a data validation, ${S}`);const j=d(p.autoFilter),X=U(c(j,"ref")??""),z=j&&X?{ref:X,...Ee(j,i)}:void 0;z&&z.unread>0&&R.push(`${e}: ${W(z.unread,"filter")} by condition on ${c(j,"ref")??""}, its rows left as they were hidden`);const{charts:K,pictures:Q}=It(n,t,e,$,m.rows,R,l,f,g),b={},I=new Map(F.map(S=>[S.id,S]));for(const S of v(d(p.hyperlinks)?.hyperlink)){const T=c(S,"ref");if(T===void 0)continue;const _=c(S,"location"),O=c(S,"id"),Z=O===void 0?void 0:I.get(O)?.target;Z!==void 0?b[T]=_===void 0?Z:`${Z}#${_}`:_!==void 0&&(b[T]=`#${_}`)}const V=d(p.sheetProtection),G=Tt(p,e,R);return{sheet:{name:e,state:o,cells:m.cells,merges:k,...E?{freeze:E}:{},...c(h,"showGridLines")==="0"?{gridlines:!1}:{},...D===void 0?{}:{tab:D},columns:$,rows:m.rows,tables:L,conditional:H.rules,validations:B.rules,scenarios:v(d(p.scenarios)?.scenario).map(S=>({name:c(S,"name")??"",cells:v(S.inputCells).map(T=>({at:c(T,"r")??"",value:c(T,"val")??""}))})),...z?{filter:z}:{},charts:K,links:b,notes:Et(n,t,e,u,R),pictures:Q,...x(V,"sheet")===!0?{protect:!0}:{},...Object.keys(G).length>0?{print:G}:{},...At(d(d(p.sheetPr)?.outlinePr))},lost:R}}function At(n){const t=x(n,"summaryBelow")===!1,e=x(n,"summaryRight")===!1;return t||e?{outline:{...t?{summary_below:!1}:{},...e?{summary_right:!1}:{}}}:{}}const Le=64,Nt=20;function It(n,t,e,o,r,s,i,u,a){const l=p=>o.find($=>p>=$.min&&p<=$.max)?.width??Le,f=new Map(r.map(p=>[p.row,p.height])),g=p=>f.get(p)??Nt,m=[],w=[];for(const p of n.rels(t).filter($=>$.type==="drawing")){const $=Xe(n.xml(p.target),l,g),k=n.rels(p.target);for(const h of $.anchors){const C=k.find(L=>L.id===h.id),E=te(h.at);if(h.width<=0||h.height<=0){s.push(`${e}: the chart at ${E}, of no size`);continue}const M=[],F=Ge(C?n.xml(C.target):void 0,M,u,a);if(typeof F=="string"){s.push(`${e}: the chart at ${E}, as ${F}`);continue}for(const L of M)s.push(`${e}: the chart at ${E} without its ${L}`);m.push({...F,at:E,...h.x===void 0?{}:{x:h.x},...h.y===void 0?{}:{y:h.y},...h.width===me.width?{}:{width:h.width},...h.height===me.height?{}:{height:h.height}})}for(const h of $.pictures){const C=k.find(F=>F.id===h.id),E=C&&!C.external?n.bytes(C.target):void 0;if(!C||!E){s.push(`${e}: the picture at ${te(h.at)}, whose image is not in the file`);continue}i.add(C.target);const M=C.target.slice(C.target.lastIndexOf(".")+1).toLowerCase();w.push({row:h.at.row,col:h.at.col,...h.x===void 0?{}:{x:h.x},...h.y===void 0?{}:{y:h.y},width:h.width,height:h.height,...h.name===void 0?{}:{name:h.name},...h.descr===void 0?{}:{descr:h.descr},bytes:E,type:M})}$.others>0&&s.push(`${e}: ${W($.others,"shape")} of its drawing`)}return{charts:m,pictures:w}}function Ft(n,t,e){for(const o of n){if(o.sheet===void 0)continue;const r=t[o.sheet];if(!r)continue;const s=o.text.split(",").map(i=>i.slice(i.lastIndexOf("!")+1).replaceAll("$",""));if(o.name==="_xlnm.Print_Area"){const[i]=s;s.length>1&&e.push(`${r.name}: its print area's ranges after the first`),i!==void 0&&U(i)&&(r.print={...r.print,area:i})}else if(o.name==="_xlnm.Print_Titles")for(const i of s)/^\d+:\d+$/u.test(i)?r.print={...r.print,title_rows:i}:/^[A-Za-z]+:[A-Za-z]+$/u.test(i)&&(r.print={...r.print,title_cols:i})}}export function readXlsx(n,t){let e;try{e=new tt(n,t)}catch(b){throw b instanceof Re?b:new Error("It is not a zip file, as an .xlsx file is.")}const o=e.rels(""),r=o.find(b=>b.type==="officeDocument")?.target??"xl/workbook.xml";if(r.endsWith(".bin"))throw new Error("It is a binary workbook (.xlsb): save it as .xlsx.");const s=e.xml(r),i=d(s?.workbook);if(!i)throw new Error("It has no workbook part.");const u=e.rels(r),a=b=>u.find(I=>I.type===b)?.target,l=(()=>{const b=a("theme");return b===void 0?void 0:e.text(b)})(),f=l===void 0?We:qe(l),g=a("styles"),m=g===void 0?void 0:e.xml(g),w=dt(m,f),p=we(f,d(m?.styleSheet)),$=ot(e,a("sharedStrings"),p),k=[];for(const b of w.lost)k.push(b);const h=d(i.workbookPr),C=Ke(d(i.calcPr));c(d(i.calcPr),"calcMode")==="manual"&&k.push("manual calculation: it computes as its cells change");const E=d(i.workbookProtection);(x(E,"lockStructure")===!0||x(E,"lockWindows")===!0)&&k.push("the workbook's protection"),i.fileSharing!==void 0&&k.push("its write protection");const M=new Map,F=a("person");if(F!==void 0)for(const b of v(d(e.xml(F)?.personList)?.person))M.set(c(b,"id")??"",A(c(b,"displayName")??""));const L=v(d(i.definedNames)?.definedName).map(b=>{const I=y(b,"localSheetId");return{name:c(b,"name")??"",text:A(N(b)),...I===void 0?{}:{sheet:I},...x(b,"hidden")===!0?{hidden:!0}:{}}}),D=[],R=new Set,H=new Map(u.map(b=>[b.id,b])),B=v(d(i.sheets)?.sheet),j=new Set(B.filter(b=>H.get(c(b,"id")??"")?.type==="worksheet").map(b=>A(c(b,"name")??"").toLowerCase()));for(const[b,I]of B.entries()){const V=H.get(c(I,"id")??""),G=A(c(I,"name")??"");if(V?.type!=="worksheet"){V?.type!=="chartsheet"&&V?.type!=="dialogsheet"&&k.push(`${G}: a sheet of a kind this cannot read`);continue}const S=new Map;for(const O of L)(O.sheet===void 0||O.sheet===b)&&(O.sheet!==void 0||!S.has(O.name.toLowerCase()))&&S.set(O.name.toLowerCase(),Ze(O.text));const T=c(I,"state"),_=Ot(e,V.target,G,T==="hidden"||T==="veryHidden"?T:"visible",$,p,w.dxfs,M,O=>S.get(O.toLowerCase())===!0,R,O=>j.has(O.toLowerCase()),O=>S.has(O.toLowerCase()));D[b]=_.sheet,k.push(..._.lost)}Ft(L,D,k);const X=o.find(b=>b.type==="core-properties")?.target,z=X===void 0?void 0:N(d(e.xml(X)?.coreProperties)?.title).trim(),K=D.filter(b=>b!==void 0),Q=new Map;return D.forEach((b,I)=>{b!==void 0&&Q.set(I,K.indexOf(b))}),{sheets:K,names:L.flatMap(b=>{if(b.sheet===void 0)return[b];const I=Q.get(b.sheet);return I===void 0?[]:[{...b,sheet:I}]}),looks:w.looks,dxfs:w.dxfs,date1904:x(h,"date1904")===!0,font:w.font,...z===void 0||z===""?{}:{title:z},...C===void 0?{}:{iteration:C},lost:[...St(e,R),...k]}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{SHEET_MARGINS as xe,SHEET_NOTE_AUTHOR as ee,SHEET_PAPERS as $e}from"@allyhub/formats";import{MAX_COLUMNS as X,MAX_ROWS as W,cellName as j,columnIndex as te,columnLetter as I,rangeName as M,readAddress as se,readArea as ye}from"../address.js";import{analyse as be}from"../calc/analyse.js";import{ITERATION_DEFAULTS as ne}from"../calc/engine.js";import{parseFormula as ve}from"../formula/parse.js";import{sheetPrefix as q}from"../formula/print.js";import{walk as oe}from"../formula/walk.js";import{fileCells as Se,isPicture as ke,pictureHeight as Ae,pictureSize as re}from"../files.js";import{scenariosByCell as Ee}from"../scenario.js";import{CellError as P,readTyped as Te}from"../values.js";import{FormulaCell as Ce,runsText as _e}from"../workbook.js";import{chartPart as Re,drawingPart as Me}from"./charts.js";import{fileFormula as V,needsArray as G}from"./formula.js";import{GRID_END as Y}from"./read.js";import{Styles as Le,runXml as je}from"./styles.js";import{THEME_XML as Fe}from"./theme.js";import{HEAD as E,NS as T,el as r,xstring as w}from"./xml.js";import{ZipOut as Ie}from"./zip.js";const C={comments:"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",worksheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",styles:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",strings:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",theme:"application/vnd.openxmlformats-officedocument.theme+xml",table:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",metadata:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",core:"application/vnd.openxmlformats-package.core-properties+xml",app:"application/vnd.openxmlformats-officedocument.extended-properties+xml"},k=`${T.rel}/`,ie="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",ae="http://schemas.microsoft.com/office/excel/2006/main",le={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},Oe=191029;export const DEFAULT_TABLE_STYLE="TableStyleMedium2",LISTS_SHEET="AllyHub lists";const De=64,Ne=7,Pe=a=>Math.min(255,Math.floor(a/Ne*256)/256),Ve=a=>Math.min(409.5,a*3/4),z=32767,ze=255,Ue=2e5,Be=r("metadata",{xmlns:T.main,"xmlns:xda":"http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray"},r("metadataTypes",{count:1},r("metadataType",{name:"XLDAPR",minSupportedVersion:12e4,copy:1,pasteAll:1,pasteValues:1,merge:1,splitFirst:1,rowColShift:1,clearFormats:1,clearComments:1,assign:1,coerce:1,cellMeta:1})),r("futureMetadata",{name:"XLDAPR",count:1},r("bk",{},r("extLst",{},r("ext",{uri:"{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}"},r("xda:dynamicArrayProperties",{fDynamic:1,fCollapsed:0}))))),r("cellMetadata",{count:1},r("bk",{},r("rc",{t:1,v:0}))));class He{index=new Map;count=0;place(t){this.count+=1;let s=this.index.get(t);return s===void 0&&(s=this.index.size,this.index.set(t,s)),s}of(t){return this.place(`t${t}`)}rich(t){return this.place(`r${t}`)}write(t){t.write(`${E}<sst xmlns="${T.main}" count="${String(this.count)}" uniqueCount="${String(this.index.size)}">`);for(const s of this.index.keys()){if(s.startsWith("r")){t.write(`<si>${s.slice(1)}</si>`);continue}const e=s.slice(1),n=/^\s|\s$|\n/u.test(e);t.write(`<si><t${n?' xml:space="preserve"':""}>${w(e)}</t></si>`)}t.write("</sst>"),t.end()}}function Xe(a){let t=!1;return a&&oe(a,s=>{(s.kind==="structured"||s.kind==="ref"&&s.sheet!==void 0)&&(t=!0)}),t}function We(a){for(const t in a)if(Object.hasOwn(a,t))return!1;return!0}const qe=a=>r("x",a).slice(2,-2),Ge="Base case";function Ye(a){const t=new Map;for(const n of a.scenarios)for(const o of n.cells)t.set(j(o),o);const s=(n,o)=>r("inputCells",{r:j(n),val:o===null||o instanceof P?"":typeof o=="boolean"?o?"1":"0":String(o)}),e=(n,o)=>r("scenario",{name:n,locked:!0,count:o.length,user:"AllyHub"},o.join(""));return r("scenarios",{current:0,show:0,sqref:[...t.keys()].join(" ")},e(Ge,[...t.values()].map(n=>s(n,n.base))),...a.scenarios.map(n=>e(n.name,n.cells.map(o=>s(o,o.value)))))}function Ze(a,t,s,e){const n=[];let o=0;for(const{row:i,col:d,paths:l,column:c}of Se(a,t)){let f=0;const h=Ae(c);for(const u of l){const m=ke(u)?s?.(u):void 0,x=m&&re(m);if(!m||!x){o+=1;continue}const b=Math.round(x.width/x.height*h);n.push({row:i,col:d,x:f,width:b,height:h,name:u.split("/").pop()??u,path:u,file:`.${x.type==="jpeg"?"jpg":x.type}`,bytes:m}),f+=b+4}}for(const i of a.spec.pictures??[]){const d=se(i.at),l=s?.(i.file),c=l&&re(l);if(!d||!l||!c)continue;const f=c.width/c.height,h=i.width??(i.height===void 0?c.width:i.height*f);n.push({row:d.row,col:d.col,x:i.x??0,y:i.y??0,width:Math.round(h),height:Math.round(i.height??h/f),name:i.file.split("/").pop()??i.file,path:i.file,file:`.${c.type==="jpeg"?"jpg":c.type}`,bytes:l})}return o>0&&e.push(`${a.name}: ${String(o)} file${o===1?"":"s"} in a cell, which stay${o===1?"s":""} a name`),n}class Je{name;columns=[];known=new Map;constructor(t){let s=LISTS_SHEET;for(let e=2;t.sheet(s);e++)s=`${LISTS_SHEET} (${String(e)})`;this.name=s}place(t){const s=JSON.stringify(t);let e=this.known.get(s);e===void 0&&(e=this.columns.length,this.columns.push(t),this.known.set(s,e));const n=I(e);return`${q(this.name)}$${n}$1:$${n}$${String(Math.max(1,t.length))}`}xml(t){const s=[],e=Math.max(0,...this.columns.map(n=>n.length));for(let n=0;n<e;n++){let o=`<row r="${String(n+1)}">`;this.columns.forEach((i,d)=>{const l=i[n];l!==void 0&&(o+=`<c r="${j({row:n,col:d})}" t="s"><v>${String(t.of(l))}</v></c>`)}),s.push(`${o}</row>`)}return`${E}<worksheet xmlns="${T.main}" xmlns:r="${T.rel}"><dimension ref="${M({top:0,left:0,bottom:Math.max(0,e-1),right:Math.max(0,this.columns.length-1)})}"/><sheetViews><sheetView workbookViewId="0"/></sheetViews><sheetFormatPr defaultRowHeight="15"/><sheetData>${s.join("")}</sheetData><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/></worksheet>`}}class Ke{rows=new Int32Array(1024);cols=new Int32Array(1024);size=0;add(t,s){if(this.size===this.rows.length){const e=new Int32Array(this.size*2);e.set(this.rows),this.rows=e;const n=new Int32Array(this.size*2);n.set(this.cols),this.cols=n}this.rows[this.size]=t,this.cols[this.size]=s,this.size+=1}byRow(){const{size:t}=this;if(t===0)return{start:new Uint32Array(1),cols:new Int32Array(0),top:0,used:void 0};let s=1/0,e=-1,n=1/0,o=-1;for(let c=0;c<t;c++){const f=this.rows[c]??0,h=this.cols[c]??0;f<s&&(s=f),f>e&&(e=f),h<n&&(n=h),h>o&&(o=h)}const i=new Uint32Array(e-s+2);for(let c=0;c<t;c++){const f=(this.rows[c]??0)-s+1;i[f]=(i[f]??0)+1}for(let c=1;c<i.length;c++)i[c]=(i[c]??0)+(i[c-1]??0);const d=i.slice(0,-1),l=new Int32Array(t);for(let c=0;c<t;c++){const f=(this.rows[c]??0)-s,h=d[f]??0;l[h]=this.cols[c]??0,d[f]=h+1}return{start:i,cols:l,top:s,used:{top:s,bottom:e,left:n,right:o}}}}function Qe(a,t){if(!a)return!1;let s=!1;const e=t.toLowerCase();return oe(a,n=>{(n.kind==="ref"||n.kind==="name")&&n.sheet!==void 0&&n.sheet.toLowerCase()!==e&&(s=!0)}),s}const et=(a,t)=>`{00000000-0000-4000-8000-${(a*65536+t).toString(16).toUpperCase().padStart(12,"0")}}`;class tt{arrays=!1;sheet;calc;styles;strings;wb;cached;left;lists;index;isTable;isRangeName;hiddenRows;tall;scenarios;drawn;newerRules=[];newerValidations=[];misgiven=new Set;shapes=new Map;groups=new Map;constructor(t,s,e,n,o,i,d,l,c=[],f){this.sheet=t,this.calc=s,this.wb=s.wb,this.styles=e,this.strings=n,this.cached=o,this.left=i,this.lists=d,this.index=l,this.isTable=u=>this.wb.table(u)!==void 0,this.isRangeName=u=>{const m=this.wb.name(u,t)?.formula?.node;return this.isTable(u)||m!==void 0&&G({kind:"unary",op:"-",arg:m})},this.hiddenRows=s.filtered(t),this.scenarios=f,this.drawn=t.charts.length>0||c.length>0;const h=new Map;for(const u of c)u.y===void 0&&h.set(u.row,Math.max(h.get(u.row)??0,u.height));this.tall=h}grid(){const{sheet:t}=this;if(t.lastRow>=W)throw new Error(`${t.name} reaches row ${(t.lastRow+1).toLocaleString("en-US")}, and ${Y}: an Excel file cannot hold it.`);if(t.columnsUsed>X)throw new Error(`${t.name} reaches past column ${I(X-1)}, and ${Y}: an Excel file cannot hold it.`);for(const s of Object.keys(t.spec.rows??{}))if(Number(s)>W)throw new Error(`${t.name} sets row ${s}, and ${Y}: an Excel file cannot hold it.`)}gather(){const{sheet:t}=this,s=new Ke;for(let e=0;e<t.columnsUsed;e++){const[n,o]=t.span(e,0,Number.MAX_SAFE_INTEGER);for(let i=n;i<=o;i++)(t.at(i,e)!==void 0||t.spillAt(i,e))&&s.add(i,e)}for(const{area:e}of t.styledAreas()){const n=(e.bottom-e.top+1)*(e.right-e.left+1);if(n>Ue){this.left.push(`${t.name}!${M(e)}: its look on the cells that hold something, ${String(n)} cells being too many to write empty`);continue}for(let o=e.top;o<=e.bottom;o++)for(let i=e.left;i<=e.right;i++)s.add(o,i)}for(const e of t.keys.keys())s.add(Math.floor(e/16384),e%16384);return s.byRow()}styleOf(t,s){const e=this.sheet.lookAt(t,s);return We(e)?void 0:this.styles.xf(e)}held(t,s){return s.length<=z?s:(this.left.push(`${this.sheet.name}!${t} past Excel's ${String(z)} characters, of its ${String(s.length)}`),s.slice(0,z))}value(t,s,e){return e===null?`<c r="${t}"${v(s)}/>`:typeof e=="number"?`<c r="${t}"${v(s)}><v>${String(e)}</v></c>`:typeof e=="boolean"?`<c r="${t}"${v(s)} t="b"><v>${e?"1":"0"}</v></c>`:e instanceof P?he(e)?`<c r="${t}"${v(s)} t="e"><v>${e.code}</v></c>`:`<c r="${t}"${v(s)} t="s"><v>${String(this.strings.of(e.code))}</v></c>`:`<c r="${t}"${v(s)} t="s"><v>${String(this.strings.of(this.held(t,e)))}</v></c>`}dataTable(t,s,e,n){const o=this.value(t,s,n),{shared:i}=e;if(e.row!==i.row||e.col!==i.col)return o;const d=i.node,l=y=>{if(y===void 0||y.kind==="missing")return null;if(!(y.kind!=="ref"||y.sheet!==void 0||!y.row||!y.col))return j({row:y.row.index,col:y.col.index})},c=d?.kind==="call"?d.args:[],f=l(c[0]),h=l(c[1]);if(f===void 0||h===void 0||f===null&&h===null)return this.left.push(`${this.sheet.name}!${t}: a data table whose inputs a file cannot hold, as its values`),o;const m=this.sheet.fills.find(y=>y.shared===i)?.area??{top:e.row,left:e.col,bottom:e.row,right:e.col},x=f!==null&&h!==null?{dt2D:!0,dtr:!0,r1:f,r2:h}:f!==null?{dtr:!0,r1:f}:{dtr:!1,r1:h??""},b=r("f",{t:"dataTable",ref:M(m),...x});return typeof n=="string"?`<c r="${t}"${v(s)} t="str">${b}<v>${w(n)}</v></c>`:o.includes("<v>")?o.replace("<v>",`${b}<v>`):o.replace("/>",`>${b}</c>`)}table(t){return this.sheet.tableAt(t.row,t.col)?.name}formula(t,s,e){const n=this.calc.value(e.sheet,e.row,e.col),{shared:o}=e,{node:i}=o;if(!i)return`<c r="${t}"${v(s)} t="e"><v>#NAME?</v></c>`;if(i.kind==="call"&&i.name==="TABLE"&&i.args.length<=2)return this.dataTable(t,s,e,n);const d=(o.analysis??=be(this.wb,o)).arguments[0];if(d!==void 0)return this.misgiven.has(o)||(this.misgiven.add(o),this.left.push(`${this.sheet.name}!${t}: a formula's value, not the formula, as ${d.name} is given ${String(d.given)} arguments`)),this.value(t,s,n);let l=this.shapes.get(o);l===void 0&&(l=G(i,this.isRangeName),this.shapes.set(o,l));const c=e.array!==void 0||e.blocked!==void 0||l;let f=c?void 0:this.groups.get(o);f?.written===!1&&(e.row!==f.ref.top||e.col!==f.ref.left)&&(f=void 0);let h,u="";if(f?.written===!0)h=`<f t="shared" si="${String(f.si)}"/>`;else{const m=V(e.moved,{table:this.table(e),isTable:this.isTable,array:c});h=f?`<f t="shared" ref="${M(f.ref)}" si="${String(f.si)}">${w(m)}</f>`:`<f>${w(m)}</f>`,f&&(f.written=!0),c&&(h=this.arrayFormula(e,m))}return c&&(this.arrays=!0,u=' cm="1"'),this.cached?n===null||typeof n=="number"?`<c r="${t}"${v(s)}${u}>${h}<v>${String(n??0)}</v></c>`:typeof n=="boolean"?`<c r="${t}"${v(s)} t="b"${u}>${h}<v>${n?"1":"0"}</v></c>`:n instanceof P?he(n)?`<c r="${t}"${v(s)} t="e"${u}>${h}<v>${n.code}</v></c>`:n.code==="#CYCLE!"?`<c r="${t}"${v(s)}${u}>${h}<v>0</v></c>`:`<c r="${t}"${v(s)} t="e"${u}>${h}<v>#VALUE!</v></c>`:`<c r="${t}"${v(s)} t="str"${u}>${h}<v>${w(this.held(t,n))}</v></c>`:`<c r="${t}"${v(s)}${u}>${h}</c>`}arrayFormula(t,s){const e=t.spill??{top:t.row,left:t.col,bottom:t.row,right:t.col};return`<f t="array" ref="${M(e)}">${w(s)}</f>`}shareFormulas(){const t=new Map;for(const e of this.sheet.formulas){const n=t.get(e.shared);if(!n)t.set(e.shared,{area:{top:e.row,bottom:e.row,left:e.col,right:e.col},first:e,n:1});else{const{area:o}=n;e.row<o.top&&(o.top=e.row),e.row>o.bottom&&(o.bottom=e.row),e.col<o.left&&(o.left=e.col),e.col>o.right&&(o.right=e.col),(e.row<n.first.row||e.row===n.first.row&&e.col<n.first.col)&&(n.first=e),n.n+=1}}let s=0;for(const[e,{area:n,first:o,n:i}]of t)i>1&&o.row===n.top&&o.col===n.left&&!Xe(e.node)&&(this.groups.set(e,{si:s,ref:n,written:!1}),s+=1)}cell(t,s){const e=j({row:t,col:s}),n=this.styleOf(t,s),o=this.sheet.at(t,s);if(o instanceof Ce)return this.formula(e,n,o);const i=typeof o=="string"?this.sheet.runsAt(t,s):void 0;if(i&&_e(i).length<=z){const d=this.sheet.lookAt(t,s);return`<c r="${e}"${v(n)} t="s"><v>${String(this.strings.rich(i.map(l=>je(l,d)).join("")))}</v></c>`}return o===void 0&&this.cached&&this.sheet.spillAt(t,s)?this.value(e,n,this.calc.value(this.sheet,t,s)):this.value(e,n,o??null)}columns(){const{sheet:t}=this,{spec:s}=t,e=new Map,n=new Map;for(const l of t.tables)for(const c of l.columns)c.spec?.width!==void 0&&n.set(l.at.col+c.index,c.spec.width);const o=new Set(n.keys()),i=new Map;for(const[l,c]of Object.entries(s.columns??{})){const f=te(l);f!==void 0&&(i.set(f,c),o.add(f))}for(const l of[...i.keys()])for(const c of[-1,1])l+c>=0&&this.collapsedColumn(l+c)&&o.add(l+c);for(const l of o){const c=i.get(l),f=c?.width??n.get(l),h=ue(c);e.set(l,r("col",{min:l+1,max:l+1,width:Pe(f??De),style:h===void 0?void 0:this.styles.xf(h),hidden:c?.hidden===!0?!0:void 0,customWidth:f===void 0?void 0:!0,outlineLevel:c?.level,collapsed:this.collapsedColumn(l)?!0:void 0}))}const d=[...e.keys()].sort((l,c)=>l-c).map(l=>e.get(l)??"");return d.length===0?"":`<cols>${d.join("")}</cols>`}rowAttrs(t){const s=this.sheet.spec.rows?.[String(t+1)],e=ue(s),n=s?.height??this.tall.get(t);return qe({r:t+1,s:e===void 0?void 0:this.styles.xf(e),customFormat:e===void 0?void 0:!0,ht:n===void 0?void 0:Ve(n),customHeight:n===void 0?void 0:!0,hidden:s?.hidden===!0||this.hiddenRows.has(t)?!0:void 0,outlineLevel:s?.level,collapsed:this.collapsedRow(t)?!0:void 0})}collapsedRow(t){const s=this.sheet.spec.rows??{},e=d=>s[String(d+1)]?.level??0,n=d=>s[String(d+1)]?.hidden===!0||this.hiddenRows.has(d),o=this.sheet.spec.outline?.summary_below===!1?1:-1,i=t+o;return i>=0&&e(i)>e(t)&&n(i)}collapsedColumn(t){const s=this.sheet.spec.columns??{},e=i=>s[I(i)],n=this.sheet.spec.outline?.summary_right===!1?1:-1,o=t+n;return o>=0&&(e(o)?.level??0)>(e(t)?.level??0)&&e(o)?.hidden===!0}rows(t,s){const{sheet:e}=this,n=new Set(this.hiddenRows);for(const f of Object.keys(e.spec.rows??{})){const h=Number(f)-1;n.add(h);for(const u of[-1,1])h+u>=0&&this.collapsedRow(h+u)&&n.add(h+u)}const{start:o,cols:i,top:d}=s;let l=s.used?d:1/0,c=s.used?s.used.bottom:-1;for(const f of n)f<l&&(l=f),f>c&&(c=f);for(let f=Math.max(0,l);f<=c;f++){const h=f-d,u=h>=0&&h<o.length-1?o[h]??0:0,m=h>=0&&h<o.length-1?o[h+1]??0:0;if(u===m&&!n.has(f))continue;if(u===m){t.write(`<row${this.rowAttrs(f)}/>`);continue}const x=i.subarray(u,m).sort();let b=`<row${this.rowAttrs(f)}>`,y=-1;for(const R of x)R!==y&&(y=R,b+=this.cell(f,R));t.write(`${b}</row>`)}}view(t){const{freeze:s}=this.sheet;let e="";if(s&&(s.row>0||s.col>0)){const n=s.row>0&&s.col>0?"bottomRight":s.row>0?"bottomLeft":"topRight";e=r("pane",{xSplit:s.col>0?s.col:void 0,ySplit:s.row>0?s.row:void 0,topLeftCell:j(s),activePane:n,state:"frozen"})}return r("sheetViews",{},r("sheetView",{showGridLines:this.sheet.spec.gridlines===!1?!1:void 0,tabSelected:t?!0:void 0,workbookViewId:0},e))}write(t,s,e){const{sheet:n}=this;this.grid();const o=this.gather();this.shareFormulas();const i=n.tables.map((A,S)=>r("tablePart",{"r:id":`rId${String(S+1)}`})),{print:d}=n.spec,l=d?.fit,c=Object.keys(n.spec.notes??{}).length>0,f=n.spec.outline,h=f?.summary_below===!1||f?.summary_right===!1?r("outlinePr",{summaryBelow:f.summary_below===!1?!1:void 0,summaryRight:f.summary_right===!1?!1:void 0}):"";t.write(`${E}<worksheet xmlns="${T.main}" xmlns:r="${T.rel}">`+(n.spec.tab===void 0&&l===void 0&&h===""?"":r("sheetPr",{},n.spec.tab===void 0?"":r("tabColor",{rgb:`FF${n.spec.tab.slice(1).toUpperCase()}`}),h,l===void 0?"":r("pageSetUpPr",{fitToPage:!0})))+r("dimension",{ref:o.used?M(o.used):"A1"})+this.view(s)+r("sheetFormatPr",{defaultRowHeight:15,outlineLevelRow:ce(n.spec.rows),outlineLevelCol:ce(n.spec.columns)})+this.columns()+"<sheetData>"),this.rows(t,o);const u=i.length+1+(this.drawn?1:0)+(c?2:0);let m=0;const x=Object.entries(n.spec.links??{}).map(([A,S])=>S.startsWith("#")?r("hyperlink",{ref:A,location:S.slice(1)}):r("hyperlink",{ref:A,"r:id":`rId${String(u+m++)}`})),b=n.merges.map(A=>r("mergeCell",{ref:M(A)})),y=n.conditions.map((A,S)=>this.condition(A,S+1)).join(""),R=this.validations();return t.write("</sheetData>"+(n.spec.protect===!0?r("sheetProtection",{sheet:!0,objects:!0,scenarios:!0}):"")+(this.scenarios?Ye(this.scenarios):"")+this.sheetFilter()+(b.length>0?r("mergeCells",{count:b.length},b.join("")):"")+y+R+(x.length>0?r("hyperlinks",{},x.join("")):"")+r("pageMargins",{...xe,...d?.margins})+(d?.orientation!==void 0||d?.paper!==void 0||d?.scale!==void 0||l!==void 0?r("pageSetup",{paperSize:d?.paper===void 0?void 0:$e[d.paper],scale:d?.scale,fitToWidth:l?.width,fitToHeight:l?.height,orientation:d?.orientation}):"")+(d?.header||d?.footer?r("headerFooter",{},d.header?r("oddHeader",{},w(de(d.header))):"",d.footer?r("oddFooter",{},w(de(d.footer))):""):"")+ut(d?.breaks)+(this.drawn?r("drawing",{"r:id":`rId${String(i.length+1)}`}):"")+(c?r("legacyDrawing",{"r:id":`rId${String(i.length+(this.drawn?2:1))}`}):"")+(i.length>0?r("tableParts",{count:i.length},i.join("")):"")+this.extensions()+"</worksheet>"),t.end(),n.tables.map((A,S)=>this.tableXml(A,e+S))}extensions(){const t=[];return this.newerRules.length>0&&t.push(r("ext",{uri:le.conditional,"xmlns:x14":ie},r("x14:conditionalFormattings",{},this.newerRules.join("")))),this.newerValidations.length>0&&t.push(r("ext",{uri:le.validations,"xmlns:x14":ie},r("x14:dataValidations",{count:this.newerValidations.length,"xmlns:xm":ae},this.newerValidations.join("")))),t.length===0?"":r("extLst",{},t.join(""))}bound(t){if(t===void 0)return"";if(typeof t=="number")return String(t);if(!t.startsWith("=")){const e=Te(t);return typeof e.value=="number"&&e.formula===void 0?String(e.value):`"${t.replaceAll('"','""')}"`}const s=ve(t);return s.ok?V(s.node,{isTable:this.isTable,array:!0}):t.slice(1)}cfvo(t,s){const e=t.value===void 0?void 0:typeof t.value=="number"?String(t.value):this.bound(t.value);return s?r("x14:cfvo",{type:t.at},e===void 0?"":r("xm:f",{},w(e))):r("cfvo",{type:t.at,val:e})}crosses(t){return t.some(s=>Qe(s?.node,this.sheet.name))}condition(t,s){const{spec:e}=t,n=e.range,o=e.type!=="dataBar"&&this.crosses(t.formulas),i=(h,u,...m)=>{if(!o){const x=Object.keys(u).length===0?void 0:this.styles.dxf(u);return r("conditionalFormatting",{sqref:n},r("cfRule",{...h,dxfId:x,priority:s,stopIfTrue:e.stop===!0?!0:void 0},...m))}return this.newerRules.push(r("x14:conditionalFormatting",{"xmlns:xm":ae},r("x14:cfRule",{...h,priority:s,stopIfTrue:e.stop===!0?!0:void 0,id:et(this.index,s)},...m.map(x=>x.replace(/^<formula>(.*)<\/formula>$/su,"<xm:f>$1</xm:f>")),Object.keys(u).length===0?"":this.styles.dxfXml(u,"x14:dxf")),r("xm:sqref",{},n))),""},d=rt(e),l=t.areas[0],c=l?j({row:l.top,col:l.left}):"A1",f=h=>r("formula",{},w(h));switch(e.type){case"cellIs":return i({type:"cellIs",operator:e.operator},d,...e.formula.map(h=>f(this.bound(h))));case"containsText":{const h=e.operator??"contains",u=`"${e.text.replaceAll('"','""')}"`,m=h==="contains"?`NOT(ISERROR(SEARCH(${u},${c})))`:h==="notContains"?`ISERROR(SEARCH(${u},${c}))`:h==="beginsWith"?`LEFT(${c},LEN(${u}))=${u}`:`RIGHT(${c},LEN(${u}))=${u}`;return i({type:h==="contains"?"containsText":h==="notContains"?"notContainsText":h,operator:h==="contains"?"containsText":h,text:e.text},d,f(m))}case"duplicateValues":case"uniqueValues":return i({type:e.type},d);case"top10":return i({type:"top10",percent:e.percent===!0?!0:void 0,bottom:e.bottom===!0?!0:void 0,rank:e.rank},d);case"aboveAverage":return i({type:"aboveAverage",aboveAverage:e.below===!0?!1:void 0,equalAverage:e.equal===!0?!0:void 0},d);case"expression":return i({type:"expression"},d,f(this.bound(e.formula.startsWith("=")?e.formula:`=${e.formula}`)));case"dataBar":return i({type:"dataBar"},{},r("dataBar",{showValue:e.show===!1?!1:void 0},this.cfvo(e.min??{at:"min"},!1),this.cfvo(e.max??{at:"max"},!1),r("color",{rgb:fe(e.color)})));case"colorScale":{const h=o?"x14:":"";return i({type:"colorScale"},{},r(`${h}colorScale`,{},...e.stops.map(u=>this.cfvo(u,o)),...e.stops.map(u=>r(`${h}color`,{rgb:fe(u.color)}))))}case"iconSet":{const h=Number.parseInt(e.icons,10),u=e.stops??Array.from({length:h},(m,x)=>({at:"percent",value:Math.round(x*100/h)}));return i({type:"iconSet"},{},r(o?"x14:iconSet":"iconSet",{iconSet:e.icons,showValue:e.show===!1?!1:void 0,reverse:e.reverse===!0?!0:void 0},...u.map(m=>this.cfvo(m,o))))}}}validation(t){const{spec:s}=t;let e="",n=this.crosses(t.formulas);if(s.values){const c=s.values.join(",");c.length>ze||s.values.some(f=>f.includes(",")||f.includes('"'))?(e=this.lists.place(s.values),n=!0):e=`"${c}"`}else e=this.bound(s.formula?.[0]);const o=this.bound(s.formula?.[1]),{error:i,prompt:d}=s;s.multiple===!0&&this.left.push(`${this.sheet.name}!${s.range}: several choices in a cell: its text stays, and Excel's list offers one at a time`);const l={type:s.type,errorStyle:i?.style===void 0||i.style==="stop"?void 0:i.style,operator:s.operator===void 0||s.operator==="between"?void 0:s.operator,allowBlank:s.blank===!1?void 0:!0,showDropDown:s.dropdown===!1?!0:void 0,showInputMessage:d?.show===!1?void 0:!0,showErrorMessage:i?.show===!1||s.multiple===!0?void 0:!0,errorTitle:i?.title,error:i?.message,promptTitle:d?.title,prompt:d?.message};return n?(this.newerValidations.push(r("x14:dataValidation",l,e===""?"":r("x14:formula1",{},r("xm:f",{},w(e))),o===""?"":r("x14:formula2",{},r("xm:f",{},w(o))),r("xm:sqref",{},s.range))),""):r("dataValidation",{...l,sqref:s.range},e===""?"":r("formula1",{},w(e)),o===""?"":r("formula2",{},w(o)))}validations(){const t=this.sheet.validations.map(s=>this.validation(s)).filter(s=>s!=="");return t.length===0?"":r("dataValidations",{count:t.length},t.join(""))}filterColumns(t){return[...t.columns.entries()].sort(([s],[e])=>s-e).map(([s,e])=>it(s-t.area.left,e,n=>this.styles.dxf(n)))}sheetFilter(){const t=this.sheet.filters.find(s=>!s.table);return t?r("autoFilter",{ref:M(t.area)},...this.filterColumns(t)):""}columnFormula(t,s){if(!s?.node)return"";const e=G(s.node,this.isRangeName),n=V(s.node,{table:t.name,isTable:this.isTable,array:e});return r("calculatedColumnFormula",{array:e?!0:void 0},w(n))}tableXml(t,s){const e=t.area,n=M({...e,bottom:Math.max(e.bottom,e.top+1)}),o=t.spec.style??DEFAULT_TABLE_STYLE,i=this.sheet.filters.find(d=>d.table===t);return E+r("table",{xmlns:T.main,id:s,name:t.name,displayName:t.name,ref:n,totalsRowShown:0},i?r("autoFilter",{ref:n},...this.filterColumns(i)):"",r("tableColumns",{count:t.columns.length},t.columns.map((d,l)=>r("tableColumn",{id:l+1,name:d.name},this.columnFormula(t,d.formula))).join("")),r("tableStyleInfo",{name:o==="none"?void 0:o,showFirstColumn:t.spec.first_column===!0,showLastColumn:t.spec.last_column===!0,showRowStripes:t.spec.banded_rows!==!1,showColumnStripes:t.spec.banded_columns===!0}))}}const ce=a=>{let t;for(const s of Object.values(a??{}))s.level!==void 0&&(t=Math.max(t??0,s.level));return t},de=a=>[a.left===void 0?"":`&L${a.left}`,a.center===void 0?"":`&C${a.center}`,a.right===void 0?"":`&R${a.right}`].join(""),st=a=>typeof a=="string"?{text:a,author:ee}:{text:a.text,author:a.author??ee};function nt(a){const t=a.map(([e,n])=>({ref:e,...st(n)})),s=[...new Set(t.map(e=>e.author))];return E+r("comments",{xmlns:T.main},r("authors",{},s.map(e=>r("author",{},w(e))).join("")),r("commentList",{},t.map(e=>r("comment",{ref:e.ref,authorId:s.indexOf(e.author)},r("text",{},r("r",{},r("t",/^\s|\s$|\n/u.test(e.text)?{"xml:space":"preserve"}:{},w(e.text)))))).join("")))}function ot(a){return`<xml xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"><o:shapelayout v:ext="edit"><o:idmap v:ext="edit" data="1"/></o:shapelayout><v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe"><v:stroke joinstyle="miter"/><v:path gradientshapeok="t" o:connecttype="rect"/></v:shapetype>${a.flatMap(([s],e)=>{const n=se(s);return n?[`<v:shape id="_x0000_s${String(1025+e)}" type="#_x0000_t202" style="position:absolute;margin-left:80pt;margin-top:5pt;width:120pt;height:60pt;z-index:${String(e+1)};visibility:hidden" fillcolor="#ffffe1" o:insetmode="auto"><v:fill color2="#ffffe1"/><v:shadow on="t" color="black" obscured="t"/><v:path o:connecttype="none"/><v:textbox style="mso-direction-alt:auto"><div style="text-align:left"></div></v:textbox><x:ClientData ObjectType="Note"><x:MoveWithCells/><x:SizeWithCells/><x:Anchor>${String(n.col+1)}, 15, ${String(n.row)}, 2, ${String(n.col+3)}, 15, ${String(n.row+4)}, 4</x:Anchor><x:AutoFill>False</x:AutoFill><x:Row>${String(n.row)}</x:Row><x:Column>${String(n.col)}</x:Column></x:ClientData></v:shape>`]:[]}).join("")}</xml>`}const fe=a=>`FF${a.slice(1).toUpperCase()}`;function rt(a){if(a.type==="dataBar"||a.type==="colorScale"||a.type==="iconSet")return{};const t={};for(const s of["bold","italic","underline","strike","color","fill","border","format"])a[s]!==void 0&&(t[s]=a[s]);return t}function it(a,t,s){const e=t.values!==void 0||t.blanks!==void 0,{conditions:n,top:o,average:i,color:d}=t,l=e?r("filters",{blank:t.blanks===!0?!0:void 0},(t.values??[]).map(c=>r("filter",{val:c})).join("")):n?r("customFilters",{and:n.length===2&&t.or!==!0?!0:void 0},n.map(c=>r("customFilter",{operator:c.operator==="equal"?void 0:c.operator,val:String(c.value)})).join("")):o?r("top10",{top:o.bottom===!0?!1:void 0,percent:o.percent===!0?!0:void 0,val:o.count}):i?r("dynamicFilter",{type:i==="above"?"aboveAverage":"belowAverage"}):d?.fill!==void 0?r("colorFilter",{dxfId:s({fill:d.fill})}):d?.font!==void 0?r("colorFilter",{dxfId:s({color:d.font}),cellColor:!1}):"";return r("filterColumn",{colId:a},l)}const v=a=>a===void 0?"":` s="${String(a)}"`,at=new Set(["#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#GETTING_DATA"]),he=a=>at.has(a.code),lt=new Set(["width","height","hidden"]);function ue(a){if(!a)return;const t=Object.fromEntries(Object.entries(a).filter(([s])=>!lt.has(s)));return Object.keys(t).length===0?void 0:t}const U=a=>E+r("Relationships",{xmlns:T.pkg},a.map(([t,s,e],n)=>r("Relationship",{Id:`rId${String(n+1)}`,Type:t,Target:s,TargetMode:e})).join(""));function ct(a,t){const s=t.formula?.node;if(s)return V(s,{isTable:n=>a.table(n)!==void 0,array:!0});const{value:e}=t;return e==null?'""':typeof e=="string"?`"${e.replaceAll('"','""')}"`:typeof e=="boolean"?e?"TRUE":"FALSE":e instanceof P?e.code:String(e)}const dt=(a,t)=>a.length===t.length&&a.every((s,e)=>s===t[e]),me=a=>`$${I(a.left)}$${String(a.top+1)}:$${I(a.right)}$${String(a.bottom+1)}`;function ft(a){const t=[],s=(e,n)=>r("definedName",{name:e.name,localSheetId:n,hidden:e.hidden===!0?!0:void 0},w(ct(a,e)));for(const e of a.names.values())t.push(s(e));return a.sheets.forEach((e,n)=>{for(const f of e.names.values())t.push(s(f,n));const o=e.filters.find(f=>!f.table);o&&t.push(r("definedName",{name:"_xlnm._FilterDatabase",localSheetId:n,hidden:!0},w(`${q(e.name)}${me(o.area)}`)));const i=q(e.name),d=e.spec.print,l=d?.area===void 0?void 0:ye(d.area);l&&t.push(r("definedName",{name:"_xlnm.Print_Area",localSheetId:n},w(`${i}${me(l)}`)));const c=[d?.title_cols?.toUpperCase().replace(/([A-Z]+):([A-Z]+)/u,"$$$1:$$$2"),d?.title_rows?.replace(/(\d+):(\d+)/u,"$$$1:$$$2")].flatMap(f=>f===void 0?[]:[`${i}${f}`]);c.length>0&&t.push(r("definedName",{name:"_xlnm.Print_Titles",localSheetId:n},w(c.join(","))))}),t}function ht(a){if(a===void 0)return{};const t=a===!0?{}:a;return{iterate:!0,iterateCount:t.max_iterations??ne.max_iterations,iterateDelta:t.max_change??ne.max_change}}export function writeXlsx(a,t={}){const s=a.wb,e=[];s.checks.length>0&&e.push(`${String(s.checks.length)} check${s.checks.length===1?"":"s"}: a file has no such thing`);const n=Ee(a);e.push(...n.left);const o=new Le,i=new He,d=new Je(s),l=new Ie,c=[["/xl/workbook.xml",C.sheet]],f=Math.max(0,s.sheets.findIndex(p=>p.spec.hidden!==!0));let h=1,u=!1;const m=new Map;let x=0,b=0,y=0;for(const[p,g]of s.sheets.entries()){const B=String(p+1),O=Ze(g,a,t.file,e),D=g.charts.filter(({spec:$})=>[$.categories,...$.series.flatMap(_=>[_.values,_.x])].some(_=>_?.endsWith("#"))).length;D>0&&e.push(`${g.name}: ${String(D)} chart${D===1?"":"s"} on a spill: ${D===1?"it reads":"they read"} the cells the spill covers now, and will not grow with it`);const K=new tt(g,a,o,i,t.cached!==!1,e,d,p,O,n.sheets.find($=>$.sheet===g)),ge=K.write(l.part(`xl/worksheets/sheet${B}.xml`),p===f,h);u||=K.arrays,c.push([`/xl/worksheets/sheet${B}.xml`,C.worksheet]);const L=[];for(const $ of ge){const _=`table${String(h)}.xml`;h+=1,l.add(`xl/tables/${_}`,$),c.push([`/xl/tables/${_}`,C.table]),L.push([`${k}table`,`../tables/${_}`])}if(g.charts.length>0||O.length>0){x+=1;const $=`drawing${String(x)}.xml`;l.add(`xl/drawings/${$}`,Me(g.charts,O)),c.push([`/xl/drawings/${$}`,C.drawing]),L.push([`${k}drawing`,`../drawings/${$}`]);const _=g.charts.map(F=>{b+=1;const N=`chart${String(b)}.xml`;return l.add(`xl/charts/${N}`,Re(a,g,F)),c.push([`/xl/charts/${N}`,C.chart]),[`${k}chart`,`../charts/${N}`]});for(const F of O){const Q=[...m].find(([,we])=>dt(we,F.bytes))?.[0]??`image${String(m.size+1)}${F.file}`;m.set(Q,F.bytes),_.push([`${k}image`,`../media/${Q}`])}l.add(`xl/drawings/_rels/${$}.rels`,U(_))}const H=Object.entries(g.spec.notes??{});if(H.length>0){y+=1;const $=String(y);l.add(`xl/comments${$}.xml`,nt(H)),c.push([`/xl/comments${$}.xml`,C.comments]),l.add(`xl/drawings/vmlDrawing${$}.vml`,ot(H)),L.push([`${k}vmlDrawing`,`../drawings/vmlDrawing${$}.vml`]),L.push([`${k}comments`,`../comments${$}.xml`])}for(const $ of Object.values(g.spec.links??{}))$.startsWith("#")||L.push([`${k}hyperlink`,$,"External"]);L.length>0&&l.add(`xl/worksheets/_rels/sheet${B}.xml.rels`,U(L))}const R=s.sheets.length,A=d.columns.length>0;if(A){const p=`xl/worksheets/sheet${String(R+1)}.xml`;l.add(p,d.xml(i)),c.push([`/${p}`,C.worksheet])}const S=[...s.sheets,...A?[void 0]:[]].map((p,g)=>[`${k}worksheet`,`worksheets/sheet${String(g+1)}.xml`]);S.push([`${k}theme`,"theme/theme1.xml"]),S.push([`${k}styles`,"styles.xml"]),S.push([`${k}sharedStrings`,"sharedStrings.xml"]),u&&(S.push([`${k}sheetMetadata`,"metadata.xml"]),c.push(["/xl/metadata.xml",C.metadata]));const Z=ft(s),J=s.sheets.map((p,g)=>r("sheet",{name:p.name,sheetId:g+1,state:p.spec.hidden===!0?"hidden":void 0,"r:id":`rId${String(g+1)}`}));A&&J.push(r("sheet",{name:d.name,sheetId:R+1,state:"veryHidden","r:id":`rId${String(R+1)}`})),l.add("xl/workbook.xml",E+r("workbook",{xmlns:T.main,"xmlns:r":T.rel},r("workbookPr",{}),r("bookViews",{},r("workbookView",{activeTab:f===0?void 0:f})),r("sheets",{},J.join("")),Z.length>0?r("definedNames",{},Z.join("")):"",r("calcPr",{calcId:Oe,fullCalcOnLoad:!0,...ht(s.file.iteration)}))),l.add("xl/_rels/workbook.xml.rels",U(S)),l.add("xl/styles.xml",E+o.xml()),i.write(l.part("xl/sharedStrings.xml")),l.add("xl/theme/theme1.xml",E+Fe),u&&l.add("xl/metadata.xml",E+Be),l.add("docProps/core.xml",E+r("cp:coreProperties",{"xmlns:cp":"http://schemas.openxmlformats.org/package/2006/metadata/core-properties","xmlns:dc":"http://purl.org/dc/elements/1.1/"},s.title===void 0?"":r("dc:title",{},w(s.title)))),l.add("docProps/app.xml",E+r("Properties",{xmlns:"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"},r("Application",{},"AllyHub"))),l.add("_rels/.rels",U([[`${k}officeDocument`,"xl/workbook.xml"],["http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties","docProps/core.xml"],[`${k}extended-properties`,"docProps/app.xml"]])),c.push(["/xl/styles.xml",C.styles],["/xl/sharedStrings.xml",C.strings],["/xl/theme/theme1.xml",C.theme],["/docProps/core.xml",C.core],["/docProps/app.xml",C.app]);const pe=[...m].sort(([p],[g])=>p.localeCompare(g));for(const[p,g]of pe)l.add(`xl/media/${p}`,g);return l.add("[Content_Types].xml",E+r("Types",{xmlns:T.types},r("Default",{Extension:"rels",ContentType:"application/vnd.openxmlformats-package.relationships+xml"}),r("Default",{Extension:"xml",ContentType:"application/xml"}),y>0?r("Default",{Extension:"vml",ContentType:"application/vnd.openxmlformats-officedocument.vmlDrawing"}):"",[...new Set([...m.keys()].map(p=>p.split(".").pop()??""))].sort().map(p=>r("Default",{Extension:p,ContentType:`image/${p==="jpg"?"jpeg":p}`})).join(""),c.map(([p,g])=>r("Override",{PartName:p,ContentType:g})).join(""))),{bytes:l.finish(),left:e}}function ut(a){const t=(n,o,i)=>o.length===0?"":r(n,{count:o.length,manualBreakCount:o.length},o.map(d=>r("brk",{id:d,max:i,man:!0})).join("")),s=[...new Set(a?.rows??[])].sort((n,o)=>n-o).map(n=>n-1),e=[...new Set((a?.cols??[]).map(n=>te(n.toUpperCase())).filter(n=>n!==void 0&&n>0))].sort((n,o)=>n-o);return t("rowBreaks",s,X-1)+t("colBreaks",e,W-1)}
|
|
2
|
+
import{SHEET_MARGINS as xe,SHEET_NOTE_AUTHOR as ee,SHEET_PAPERS as $e}from"@allyhub/formats";import{MAX_COLUMNS as X,MAX_ROWS as W,cellName as j,columnIndex as te,columnLetter as F,rangeName as M,readAddress as ne,readArea as ye}from"../address.js";import{analyse as be}from"../calc/analyse.js";import{ITERATION_DEFAULTS as se}from"../calc/engine.js";import{parseFormula as ve}from"../formula/parse.js";import{sheetPrefix as q}from"../formula/print.js";import{walk as oe}from"../formula/walk.js";import{fileCells as Se,isPicture as ke,pictureHeight as Ae,pictureSize as re}from"../files.js";import{scenariosByCell as Ee}from"../scenario.js";import{CellError as P,readTyped as Te}from"../values.js";import{FormulaCell as Ce,runsText as _e}from"../workbook.js";import{chartPart as Re,drawingPart as Me}from"./charts.js";import{fileFormula as V,needsArray as G}from"./formula.js";import{GRID_END as Y}from"./read.js";import{Styles as Le,runXml as je}from"./styles.js";import{THEME_XML as Ie}from"./theme.js";import{HEAD as E,NS as T,el as r,xstring as y}from"./xml.js";import{ZipOut as Fe}from"./zip.js";const C={comments:"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",worksheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",styles:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",strings:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",theme:"application/vnd.openxmlformats-officedocument.theme+xml",table:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",metadata:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",core:"application/vnd.openxmlformats-package.core-properties+xml",app:"application/vnd.openxmlformats-officedocument.extended-properties+xml"},k=`${T.rel}/`,ie="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",ae="http://schemas.microsoft.com/office/excel/2006/main",Oe=/\.(tiff?|bmp|emf|wmf)$/iu,De={jpg:"jpeg",emf:"x-emf",wmf:"x-wmf"},le={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},Ne=191029;export const DEFAULT_TABLE_STYLE="TableStyleMedium2",LISTS_SHEET="AllyHub lists";const Pe=64,Ve=7,ze=l=>Math.min(255,Math.floor(l/Ve*256)/256),Ue=l=>Math.min(409.5,l*3/4),z=32767,He=255,Be=2e5,Xe=r("metadata",{xmlns:T.main,"xmlns:xda":"http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray"},r("metadataTypes",{count:1},r("metadataType",{name:"XLDAPR",minSupportedVersion:12e4,copy:1,pasteAll:1,pasteValues:1,merge:1,splitFirst:1,rowColShift:1,clearFormats:1,clearComments:1,assign:1,coerce:1,cellMeta:1})),r("futureMetadata",{name:"XLDAPR",count:1},r("bk",{},r("extLst",{},r("ext",{uri:"{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}"},r("xda:dynamicArrayProperties",{fDynamic:1,fCollapsed:0}))))),r("cellMetadata",{count:1},r("bk",{},r("rc",{t:1,v:0}))));class We{index=new Map;count=0;place(t){this.count+=1;let n=this.index.get(t);return n===void 0&&(n=this.index.size,this.index.set(t,n)),n}of(t){return this.place(`t${t}`)}rich(t){return this.place(`r${t}`)}write(t){t.write(`${E}<sst xmlns="${T.main}" count="${String(this.count)}" uniqueCount="${String(this.index.size)}">`);for(const n of this.index.keys()){if(n.startsWith("r")){t.write(`<si>${n.slice(1)}</si>`);continue}const e=n.slice(1),s=/^\s|\s$|\n/u.test(e);t.write(`<si><t${s?' xml:space="preserve"':""}>${y(e)}</t></si>`)}t.write("</sst>"),t.end()}}function qe(l){let t=!1;return l&&oe(l,n=>{(n.kind==="structured"||n.kind==="ref"&&n.sheet!==void 0)&&(t=!0)}),t}function Ge(l){for(const t in l)if(Object.hasOwn(l,t))return!1;return!0}const Ye=l=>r("x",l).slice(2,-2),Ze="Base case";function Je(l){const t=new Map;for(const s of l.scenarios)for(const o of s.cells)t.set(j(o),o);const n=(s,o)=>r("inputCells",{r:j(s),val:o===null||o instanceof P?"":typeof o=="boolean"?o?"1":"0":String(o)}),e=(s,o)=>r("scenario",{name:s,locked:!0,count:o.length,user:"AllyHub"},o.join(""));return r("scenarios",{current:0,show:0,sqref:[...t.keys()].join(" ")},e(Ze,[...t.values()].map(s=>n(s,s.base))),...l.scenarios.map(s=>e(s.name,s.cells.map(o=>n(o,o.value)))))}function Ke(l,t,n,e){const s=[];let o=0;for(const{row:a,col:c,paths:d,column:f}of Se(l,t)){let h=0;const u=Ae(f);for(const m of d){const g=ke(m)?n?.(m):void 0,w=g&&re(g);if(!g||!w){o+=1;continue}const x=Math.round(w.width/w.height*u);s.push({row:a,col:c,x:h,width:x,height:u,name:m.split("/").pop()??m,path:m,file:`.${w.type==="jpeg"?"jpg":w.type}`,bytes:g}),h+=x+4}}let i=0;for(const a of l.spec.pictures??[]){const c=ne(a.at),d=n?.(a.file);if(!c||!d)continue;const f=re(d),h=f?.type??Oe.exec(a.file)?.[1]?.toLowerCase(),u=a.width!==void 0&&a.height!==void 0?{width:a.width,height:a.height}:void 0,m=f??u;if(h===void 0||m===void 0){i+=1;continue}const g=m.width/m.height,w=a.width??(a.height===void 0?m.width:a.height*g);s.push({row:c.row,col:c.col,x:a.x??0,y:a.y??0,width:Math.round(w),height:Math.round(a.height??w/g),name:a.file.split("/").pop()??a.file,path:a.file,file:`.${h==="jpeg"?"jpg":h==="tif"?"tiff":h}`,bytes:d})}return i>0&&e.push(`${l.name}: ${String(i)} picture${i===1?"":"s"} of a kind a file cannot hold, or with no size given`),o>0&&e.push(`${l.name}: ${String(o)} file${o===1?"":"s"} in a cell, which stay${o===1?"s":""} a name`),s}class Qe{name;columns=[];known=new Map;constructor(t){let n=LISTS_SHEET;for(let e=2;t.sheet(n);e++)n=`${LISTS_SHEET} (${String(e)})`;this.name=n}place(t){const n=JSON.stringify(t);let e=this.known.get(n);e===void 0&&(e=this.columns.length,this.columns.push(t),this.known.set(n,e));const s=F(e);return`${q(this.name)}$${s}$1:$${s}$${String(Math.max(1,t.length))}`}xml(t){const n=[],e=Math.max(0,...this.columns.map(s=>s.length));for(let s=0;s<e;s++){let o=`<row r="${String(s+1)}">`;this.columns.forEach((i,a)=>{const c=i[s];c!==void 0&&(o+=`<c r="${j({row:s,col:a})}" t="s"><v>${String(t.of(c))}</v></c>`)}),n.push(`${o}</row>`)}return`${E}<worksheet xmlns="${T.main}" xmlns:r="${T.rel}"><dimension ref="${M({top:0,left:0,bottom:Math.max(0,e-1),right:Math.max(0,this.columns.length-1)})}"/><sheetViews><sheetView workbookViewId="0"/></sheetViews><sheetFormatPr defaultRowHeight="15"/><sheetData>${n.join("")}</sheetData><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/></worksheet>`}}class et{rows=new Int32Array(1024);cols=new Int32Array(1024);size=0;add(t,n){if(this.size===this.rows.length){const e=new Int32Array(this.size*2);e.set(this.rows),this.rows=e;const s=new Int32Array(this.size*2);s.set(this.cols),this.cols=s}this.rows[this.size]=t,this.cols[this.size]=n,this.size+=1}byRow(){const{size:t}=this;if(t===0)return{start:new Uint32Array(1),cols:new Int32Array(0),top:0,used:void 0};let n=1/0,e=-1,s=1/0,o=-1;for(let d=0;d<t;d++){const f=this.rows[d]??0,h=this.cols[d]??0;f<n&&(n=f),f>e&&(e=f),h<s&&(s=h),h>o&&(o=h)}const i=new Uint32Array(e-n+2);for(let d=0;d<t;d++){const f=(this.rows[d]??0)-n+1;i[f]=(i[f]??0)+1}for(let d=1;d<i.length;d++)i[d]=(i[d]??0)+(i[d-1]??0);const a=i.slice(0,-1),c=new Int32Array(t);for(let d=0;d<t;d++){const f=(this.rows[d]??0)-n,h=a[f]??0;c[h]=this.cols[d]??0,a[f]=h+1}return{start:i,cols:c,top:n,used:{top:n,bottom:e,left:s,right:o}}}}function tt(l,t){if(!l)return!1;let n=!1;const e=t.toLowerCase();return oe(l,s=>{(s.kind==="ref"||s.kind==="name")&&s.sheet!==void 0&&s.sheet.toLowerCase()!==e&&(n=!0)}),n}const nt=(l,t)=>`{00000000-0000-4000-8000-${(l*65536+t).toString(16).toUpperCase().padStart(12,"0")}}`;class st{arrays=!1;sheet;calc;styles;strings;wb;cached;left;lists;index;isTable;isRangeName;hiddenRows;tall;scenarios;drawn;newerRules=[];newerValidations=[];misgiven=new Set;shapes=new Map;groups=new Map;constructor(t,n,e,s,o,i,a,c,d=[],f){this.sheet=t,this.calc=n,this.wb=n.wb,this.styles=e,this.strings=s,this.cached=o,this.left=i,this.lists=a,this.index=c,this.isTable=u=>this.wb.table(u)!==void 0,this.isRangeName=u=>{const m=this.wb.name(u,t)?.formula?.node;return this.isTable(u)||m!==void 0&&G({kind:"unary",op:"-",arg:m})},this.hiddenRows=n.filtered(t),this.scenarios=f,this.drawn=t.charts.length>0||d.length>0;const h=new Map;for(const u of d)u.y===void 0&&h.set(u.row,Math.max(h.get(u.row)??0,u.height));this.tall=h}grid(){const{sheet:t}=this;if(t.lastRow>=W)throw new Error(`${t.name} reaches row ${(t.lastRow+1).toLocaleString("en-US")}, and ${Y}: an Excel file cannot hold it.`);if(t.columnsUsed>X)throw new Error(`${t.name} reaches past column ${F(X-1)}, and ${Y}: an Excel file cannot hold it.`);for(const n of Object.keys(t.spec.rows??{}))if(Number(n)>W)throw new Error(`${t.name} sets row ${n}, and ${Y}: an Excel file cannot hold it.`)}gather(){const{sheet:t}=this,n=new et;for(let e=0;e<t.columnsUsed;e++){const[s,o]=t.span(e,0,Number.MAX_SAFE_INTEGER);for(let i=s;i<=o;i++)(t.at(i,e)!==void 0||t.spillAt(i,e))&&n.add(i,e)}for(const{area:e}of t.styledAreas()){const s=(e.bottom-e.top+1)*(e.right-e.left+1);if(s>Be){this.left.push(`${t.name}!${M(e)}: its look on the cells that hold something, ${String(s)} cells being too many to write empty`);continue}for(let o=e.top;o<=e.bottom;o++)for(let i=e.left;i<=e.right;i++)n.add(o,i)}for(const e of t.keys.keys())n.add(Math.floor(e/16384),e%16384);return n.byRow()}styleOf(t,n){const e=this.sheet.lookAt(t,n);return Ge(e)?void 0:this.styles.xf(e)}held(t,n){return n.length<=z?n:(this.left.push(`${this.sheet.name}!${t} past Excel's ${String(z)} characters, of its ${String(n.length)}`),n.slice(0,z))}value(t,n,e){return e===null?`<c r="${t}"${v(n)}/>`:typeof e=="number"?`<c r="${t}"${v(n)}><v>${String(e)}</v></c>`:typeof e=="boolean"?`<c r="${t}"${v(n)} t="b"><v>${e?"1":"0"}</v></c>`:e instanceof P?he(e)?`<c r="${t}"${v(n)} t="e"><v>${e.code}</v></c>`:`<c r="${t}"${v(n)} t="s"><v>${String(this.strings.of(e.code))}</v></c>`:`<c r="${t}"${v(n)} t="s"><v>${String(this.strings.of(this.held(t,e)))}</v></c>`}dataTable(t,n,e,s){const o=this.value(t,n,s),{shared:i}=e;if(e.row!==i.row||e.col!==i.col)return o;const a=i.node,c=x=>{if(x===void 0||x.kind==="missing")return null;if(!(x.kind!=="ref"||x.sheet!==void 0||!x.row||!x.col))return j({row:x.row.index,col:x.col.index})},d=a?.kind==="call"?a.args:[],f=c(d[0]),h=c(d[1]);if(f===void 0||h===void 0||f===null&&h===null)return this.left.push(`${this.sheet.name}!${t}: a data table whose inputs a file cannot hold, as its values`),o;const m=this.sheet.fills.find(x=>x.shared===i)?.area??{top:e.row,left:e.col,bottom:e.row,right:e.col},g=f!==null&&h!==null?{dt2D:!0,dtr:!0,r1:f,r2:h}:f!==null?{dtr:!0,r1:f}:{dtr:!1,r1:h??""},w=r("f",{t:"dataTable",ref:M(m),...g});return typeof s=="string"?`<c r="${t}"${v(n)} t="str">${w}<v>${y(s)}</v></c>`:o.includes("<v>")?o.replace("<v>",`${w}<v>`):o.replace("/>",`>${w}</c>`)}table(t){return this.sheet.tableAt(t.row,t.col)?.name}formula(t,n,e){const s=this.calc.value(e.sheet,e.row,e.col),{shared:o}=e,{node:i}=o;if(!i)return`<c r="${t}"${v(n)} t="e"><v>#NAME?</v></c>`;if(i.kind==="call"&&i.name==="TABLE"&&i.args.length<=2)return this.dataTable(t,n,e,s);const a=(o.analysis??=be(this.wb,o)).arguments[0];if(a!==void 0)return this.misgiven.has(o)||(this.misgiven.add(o),this.left.push(`${this.sheet.name}!${t}: a formula's value, not the formula, as ${a.name} is given ${String(a.given)} arguments`)),this.value(t,n,s);let c=this.shapes.get(o);c===void 0&&(c=G(i,this.isRangeName),this.shapes.set(o,c));const d=e.array!==void 0||e.blocked!==void 0||c;let f=d?void 0:this.groups.get(o);f?.written===!1&&(e.row!==f.ref.top||e.col!==f.ref.left)&&(f=void 0);let h,u="";if(f?.written===!0)h=`<f t="shared" si="${String(f.si)}"/>`;else{const m=V(e.moved,{table:this.table(e),isTable:this.isTable,array:d});h=f?`<f t="shared" ref="${M(f.ref)}" si="${String(f.si)}">${y(m)}</f>`:`<f>${y(m)}</f>`,f&&(f.written=!0),d&&(h=this.arrayFormula(e,m))}return d&&(this.arrays=!0,u=' cm="1"'),this.cached?s===null||typeof s=="number"?`<c r="${t}"${v(n)}${u}>${h}<v>${String(s??0)}</v></c>`:typeof s=="boolean"?`<c r="${t}"${v(n)} t="b"${u}>${h}<v>${s?"1":"0"}</v></c>`:s instanceof P?he(s)?`<c r="${t}"${v(n)} t="e"${u}>${h}<v>${s.code}</v></c>`:s.code==="#CYCLE!"?`<c r="${t}"${v(n)}${u}>${h}<v>0</v></c>`:`<c r="${t}"${v(n)} t="e"${u}>${h}<v>#VALUE!</v></c>`:`<c r="${t}"${v(n)} t="str"${u}>${h}<v>${y(this.held(t,s))}</v></c>`:`<c r="${t}"${v(n)}${u}>${h}</c>`}arrayFormula(t,n){const e=t.spill??{top:t.row,left:t.col,bottom:t.row,right:t.col};return`<f t="array" ref="${M(e)}">${y(n)}</f>`}shareFormulas(){const t=new Map;for(const e of this.sheet.formulas){const s=t.get(e.shared);if(!s)t.set(e.shared,{area:{top:e.row,bottom:e.row,left:e.col,right:e.col},first:e,n:1});else{const{area:o}=s;e.row<o.top&&(o.top=e.row),e.row>o.bottom&&(o.bottom=e.row),e.col<o.left&&(o.left=e.col),e.col>o.right&&(o.right=e.col),(e.row<s.first.row||e.row===s.first.row&&e.col<s.first.col)&&(s.first=e),s.n+=1}}let n=0;for(const[e,{area:s,first:o,n:i}]of t)i>1&&o.row===s.top&&o.col===s.left&&!qe(e.node)&&(this.groups.set(e,{si:n,ref:s,written:!1}),n+=1)}cell(t,n){const e=j({row:t,col:n}),s=this.styleOf(t,n),o=this.sheet.at(t,n);if(o instanceof Ce)return this.formula(e,s,o);const i=typeof o=="string"?this.sheet.runsAt(t,n):void 0;if(i&&_e(i).length<=z){const a=this.sheet.lookAt(t,n);return`<c r="${e}"${v(s)} t="s"><v>${String(this.strings.rich(i.map(c=>je(c,a)).join("")))}</v></c>`}return o===void 0&&this.cached&&this.sheet.spillAt(t,n)?this.value(e,s,this.calc.value(this.sheet,t,n)):this.value(e,s,o??null)}columns(){const{sheet:t}=this,{spec:n}=t,e=new Map,s=new Map;for(const c of t.tables)for(const d of c.columns)d.spec?.width!==void 0&&s.set(c.at.col+d.index,d.spec.width);const o=new Set(s.keys()),i=new Map;for(const[c,d]of Object.entries(n.columns??{})){const f=te(c);f!==void 0&&(i.set(f,d),o.add(f))}for(const c of[...i.keys()])for(const d of[-1,1])c+d>=0&&this.collapsedColumn(c+d)&&o.add(c+d);for(const c of o){const d=i.get(c),f=d?.width??s.get(c),h=ue(d);e.set(c,r("col",{min:c+1,max:c+1,width:ze(f??Pe),style:h===void 0?void 0:this.styles.xf(h),hidden:d?.hidden===!0?!0:void 0,customWidth:f===void 0?void 0:!0,outlineLevel:d?.level,collapsed:this.collapsedColumn(c)?!0:void 0}))}const a=[...e.keys()].sort((c,d)=>c-d).map(c=>e.get(c)??"");return a.length===0?"":`<cols>${a.join("")}</cols>`}rowAttrs(t){const n=this.sheet.spec.rows?.[String(t+1)],e=ue(n),s=n?.height??this.tall.get(t);return Ye({r:t+1,s:e===void 0?void 0:this.styles.xf(e),customFormat:e===void 0?void 0:!0,ht:s===void 0?void 0:Ue(s),customHeight:s===void 0?void 0:!0,hidden:n?.hidden===!0||this.hiddenRows.has(t)?!0:void 0,outlineLevel:n?.level,collapsed:this.collapsedRow(t)?!0:void 0})}collapsedRow(t){const n=this.sheet.spec.rows??{},e=a=>n[String(a+1)]?.level??0,s=a=>n[String(a+1)]?.hidden===!0||this.hiddenRows.has(a),o=this.sheet.spec.outline?.summary_below===!1?1:-1,i=t+o;return i>=0&&e(i)>e(t)&&s(i)}collapsedColumn(t){const n=this.sheet.spec.columns??{},e=i=>n[F(i)],s=this.sheet.spec.outline?.summary_right===!1?1:-1,o=t+s;return o>=0&&(e(o)?.level??0)>(e(t)?.level??0)&&e(o)?.hidden===!0}rows(t,n){const{sheet:e}=this,s=new Set(this.hiddenRows);for(const f of Object.keys(e.spec.rows??{})){const h=Number(f)-1;s.add(h);for(const u of[-1,1])h+u>=0&&this.collapsedRow(h+u)&&s.add(h+u)}const{start:o,cols:i,top:a}=n;let c=n.used?a:1/0,d=n.used?n.used.bottom:-1;for(const f of s)f<c&&(c=f),f>d&&(d=f);for(let f=Math.max(0,c);f<=d;f++){const h=f-a,u=h>=0&&h<o.length-1?o[h]??0:0,m=h>=0&&h<o.length-1?o[h+1]??0:0;if(u===m&&!s.has(f))continue;if(u===m){t.write(`<row${this.rowAttrs(f)}/>`);continue}const g=i.subarray(u,m).sort();let w=`<row${this.rowAttrs(f)}>`,x=-1;for(const R of g)R!==x&&(x=R,w+=this.cell(f,R));t.write(`${w}</row>`)}}view(t){const{freeze:n}=this.sheet;let e="";if(n&&(n.row>0||n.col>0)){const s=n.row>0&&n.col>0?"bottomRight":n.row>0?"bottomLeft":"topRight";e=r("pane",{xSplit:n.col>0?n.col:void 0,ySplit:n.row>0?n.row:void 0,topLeftCell:j(n),activePane:s,state:"frozen"})}return r("sheetViews",{},r("sheetView",{showGridLines:this.sheet.spec.gridlines===!1?!1:void 0,tabSelected:t?!0:void 0,workbookViewId:0},e))}write(t,n,e){const{sheet:s}=this;this.grid();const o=this.gather();this.shareFormulas();const i=s.tables.map((A,S)=>r("tablePart",{"r:id":`rId${String(S+1)}`})),{print:a}=s.spec,c=a?.fit,d=Object.keys(s.spec.notes??{}).length>0,f=s.spec.outline,h=f?.summary_below===!1||f?.summary_right===!1?r("outlinePr",{summaryBelow:f.summary_below===!1?!1:void 0,summaryRight:f.summary_right===!1?!1:void 0}):"";t.write(`${E}<worksheet xmlns="${T.main}" xmlns:r="${T.rel}">`+(s.spec.tab===void 0&&c===void 0&&h===""?"":r("sheetPr",{},s.spec.tab===void 0?"":r("tabColor",{rgb:`FF${s.spec.tab.slice(1).toUpperCase()}`}),h,c===void 0?"":r("pageSetUpPr",{fitToPage:!0})))+r("dimension",{ref:o.used?M(o.used):"A1"})+this.view(n)+r("sheetFormatPr",{defaultRowHeight:15,outlineLevelRow:ce(s.spec.rows),outlineLevelCol:ce(s.spec.columns)})+this.columns()+"<sheetData>"),this.rows(t,o);const u=i.length+1+(this.drawn?1:0)+(d?2:0);let m=0;const g=Object.entries(s.spec.links??{}).map(([A,S])=>S.startsWith("#")?r("hyperlink",{ref:A,location:S.slice(1)}):r("hyperlink",{ref:A,"r:id":`rId${String(u+m++)}`})),w=s.merges.map(A=>r("mergeCell",{ref:M(A)})),x=s.conditions.map((A,S)=>this.condition(A,S+1)).join(""),R=this.validations();return t.write("</sheetData>"+(s.spec.protect===!0?r("sheetProtection",{sheet:!0,objects:!0,scenarios:!0}):"")+(this.scenarios?Je(this.scenarios):"")+this.sheetFilter()+(w.length>0?r("mergeCells",{count:w.length},w.join("")):"")+x+R+(g.length>0?r("hyperlinks",{},g.join("")):"")+r("pageMargins",{...xe,...a?.margins})+(a?.orientation!==void 0||a?.paper!==void 0||a?.scale!==void 0||c!==void 0?r("pageSetup",{paperSize:a?.paper===void 0?void 0:$e[a.paper],scale:a?.scale,fitToWidth:c?.width,fitToHeight:c?.height,orientation:a?.orientation}):"")+(a?.header||a?.footer?r("headerFooter",{},a.header?r("oddHeader",{},y(de(a.header))):"",a.footer?r("oddFooter",{},y(de(a.footer))):""):"")+pt(a?.breaks)+(this.drawn?r("drawing",{"r:id":`rId${String(i.length+1)}`}):"")+(d?r("legacyDrawing",{"r:id":`rId${String(i.length+(this.drawn?2:1))}`}):"")+(i.length>0?r("tableParts",{count:i.length},i.join("")):"")+this.extensions()+"</worksheet>"),t.end(),s.tables.map((A,S)=>this.tableXml(A,e+S))}extensions(){const t=[];return this.newerRules.length>0&&t.push(r("ext",{uri:le.conditional,"xmlns:x14":ie},r("x14:conditionalFormattings",{},this.newerRules.join("")))),this.newerValidations.length>0&&t.push(r("ext",{uri:le.validations,"xmlns:x14":ie},r("x14:dataValidations",{count:this.newerValidations.length,"xmlns:xm":ae},this.newerValidations.join("")))),t.length===0?"":r("extLst",{},t.join(""))}bound(t){if(t===void 0)return"";if(typeof t=="number")return String(t);if(!t.startsWith("=")){const e=Te(t);return typeof e.value=="number"&&e.formula===void 0?String(e.value):`"${t.replaceAll('"','""')}"`}const n=ve(t);return n.ok?V(n.node,{isTable:this.isTable,array:!0}):t.slice(1)}cfvo(t,n){const e=t.value===void 0?void 0:typeof t.value=="number"?String(t.value):this.bound(t.value);return n?r("x14:cfvo",{type:t.at},e===void 0?"":r("xm:f",{},y(e))):r("cfvo",{type:t.at,val:e})}crosses(t){return t.some(n=>tt(n?.node,this.sheet.name))}condition(t,n){const{spec:e}=t,s=e.range,o=e.type!=="dataBar"&&this.crosses(t.formulas),i=(h,u,...m)=>{if(!o){const g=Object.keys(u).length===0?void 0:this.styles.dxf(u);return r("conditionalFormatting",{sqref:s},r("cfRule",{...h,dxfId:g,priority:n,stopIfTrue:e.stop===!0?!0:void 0},...m))}return this.newerRules.push(r("x14:conditionalFormatting",{"xmlns:xm":ae},r("x14:cfRule",{...h,priority:n,stopIfTrue:e.stop===!0?!0:void 0,id:nt(this.index,n)},...m.map(g=>g.replace(/^<formula>(.*)<\/formula>$/su,"<xm:f>$1</xm:f>")),Object.keys(u).length===0?"":this.styles.dxfXml(u,"x14:dxf")),r("xm:sqref",{},s))),""},a=at(e),c=t.areas[0],d=c?j({row:c.top,col:c.left}):"A1",f=h=>r("formula",{},y(h));switch(e.type){case"cellIs":return i({type:"cellIs",operator:e.operator},a,...e.formula.map(h=>f(this.bound(h))));case"containsText":{const h=e.operator??"contains",u=`"${e.text.replaceAll('"','""')}"`,m=h==="contains"?`NOT(ISERROR(SEARCH(${u},${d})))`:h==="notContains"?`ISERROR(SEARCH(${u},${d}))`:h==="beginsWith"?`LEFT(${d},LEN(${u}))=${u}`:`RIGHT(${d},LEN(${u}))=${u}`;return i({type:h==="contains"?"containsText":h==="notContains"?"notContainsText":h,operator:h==="contains"?"containsText":h,text:e.text},a,f(m))}case"duplicateValues":case"uniqueValues":return i({type:e.type},a);case"top10":return i({type:"top10",percent:e.percent===!0?!0:void 0,bottom:e.bottom===!0?!0:void 0,rank:e.rank},a);case"aboveAverage":return i({type:"aboveAverage",aboveAverage:e.below===!0?!1:void 0,equalAverage:e.equal===!0?!0:void 0},a);case"expression":return i({type:"expression"},a,f(this.bound(e.formula.startsWith("=")?e.formula:`=${e.formula}`)));case"dataBar":return i({type:"dataBar"},{},r("dataBar",{showValue:e.show===!1?!1:void 0},this.cfvo(e.min??{at:"min"},!1),this.cfvo(e.max??{at:"max"},!1),r("color",{rgb:fe(e.color)})));case"colorScale":{const h=o?"x14:":"";return i({type:"colorScale"},{},r(`${h}colorScale`,{},...e.stops.map(u=>this.cfvo(u,o)),...e.stops.map(u=>r(`${h}color`,{rgb:fe(u.color)}))))}case"iconSet":{const h=Number.parseInt(e.icons,10),u=e.stops??Array.from({length:h},(m,g)=>({at:"percent",value:Math.round(g*100/h)}));return i({type:"iconSet"},{},r(o?"x14:iconSet":"iconSet",{iconSet:e.icons,showValue:e.show===!1?!1:void 0,reverse:e.reverse===!0?!0:void 0},...u.map(m=>this.cfvo(m,o))))}}}validation(t){const{spec:n}=t;let e="",s=this.crosses(t.formulas);if(n.values){const d=n.values.join(",");d.length>He||n.values.some(f=>f.includes(",")||f.includes('"'))?(e=this.lists.place(n.values),s=!0):e=`"${d}"`}else e=this.bound(n.formula?.[0]);const o=this.bound(n.formula?.[1]),{error:i,prompt:a}=n;n.multiple===!0&&this.left.push(`${this.sheet.name}!${n.range}: several choices in a cell: its text stays, and Excel's list offers one at a time`);const c={type:n.type,errorStyle:i?.style===void 0||i.style==="stop"?void 0:i.style,operator:n.operator===void 0||n.operator==="between"?void 0:n.operator,allowBlank:n.blank===!1?void 0:!0,showDropDown:n.dropdown===!1?!0:void 0,showInputMessage:a?.show===!1?void 0:!0,showErrorMessage:i?.show===!1||n.multiple===!0?void 0:!0,errorTitle:i?.title,error:i?.message,promptTitle:a?.title,prompt:a?.message};return s?(this.newerValidations.push(r("x14:dataValidation",c,e===""?"":r("x14:formula1",{},r("xm:f",{},y(e))),o===""?"":r("x14:formula2",{},r("xm:f",{},y(o))),r("xm:sqref",{},n.range))),""):r("dataValidation",{...c,sqref:n.range},e===""?"":r("formula1",{},y(e)),o===""?"":r("formula2",{},y(o)))}validations(){const t=this.sheet.validations.map(n=>this.validation(n)).filter(n=>n!=="");return t.length===0?"":r("dataValidations",{count:t.length},t.join(""))}filterColumns(t){return[...t.columns.entries()].sort(([n],[e])=>n-e).map(([n,e])=>lt(n-t.area.left,e,s=>this.styles.dxf(s)))}sheetFilter(){const t=this.sheet.filters.find(n=>!n.table);return t?r("autoFilter",{ref:M(t.area)},...this.filterColumns(t)):""}columnFormula(t,n){if(!n?.node)return"";const e=G(n.node,this.isRangeName),s=V(n.node,{table:t.name,isTable:this.isTable,array:e});return r("calculatedColumnFormula",{array:e?!0:void 0},y(s))}tableXml(t,n){const e=t.area,s=M({...e,bottom:Math.max(e.bottom,e.top+1)}),o=t.spec.style??DEFAULT_TABLE_STYLE,i=this.sheet.filters.find(a=>a.table===t);return E+r("table",{xmlns:T.main,id:n,name:t.name,displayName:t.name,ref:s,totalsRowShown:0},i?r("autoFilter",{ref:s},...this.filterColumns(i)):"",r("tableColumns",{count:t.columns.length},t.columns.map((a,c)=>r("tableColumn",{id:c+1,name:a.name},this.columnFormula(t,a.formula))).join("")),r("tableStyleInfo",{name:o==="none"?void 0:o,showFirstColumn:t.spec.first_column===!0,showLastColumn:t.spec.last_column===!0,showRowStripes:t.spec.banded_rows!==!1,showColumnStripes:t.spec.banded_columns===!0}))}}const ce=l=>{let t;for(const n of Object.values(l??{}))n.level!==void 0&&(t=Math.max(t??0,n.level));return t},de=l=>[l.left===void 0?"":`&L${l.left}`,l.center===void 0?"":`&C${l.center}`,l.right===void 0?"":`&R${l.right}`].join(""),ot=l=>typeof l=="string"?{text:l,author:ee}:{text:l.text,author:l.author??ee};function rt(l){const t=l.map(([e,s])=>({ref:e,...ot(s)})),n=[...new Set(t.map(e=>e.author))];return E+r("comments",{xmlns:T.main},r("authors",{},n.map(e=>r("author",{},y(e))).join("")),r("commentList",{},t.map(e=>r("comment",{ref:e.ref,authorId:n.indexOf(e.author)},r("text",{},r("r",{},r("t",/^\s|\s$|\n/u.test(e.text)?{"xml:space":"preserve"}:{},y(e.text)))))).join("")))}function it(l){return`<xml xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"><o:shapelayout v:ext="edit"><o:idmap v:ext="edit" data="1"/></o:shapelayout><v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe"><v:stroke joinstyle="miter"/><v:path gradientshapeok="t" o:connecttype="rect"/></v:shapetype>${l.flatMap(([n],e)=>{const s=ne(n);return s?[`<v:shape id="_x0000_s${String(1025+e)}" type="#_x0000_t202" style="position:absolute;margin-left:80pt;margin-top:5pt;width:120pt;height:60pt;z-index:${String(e+1)};visibility:hidden" fillcolor="#ffffe1" o:insetmode="auto"><v:fill color2="#ffffe1"/><v:shadow on="t" color="black" obscured="t"/><v:path o:connecttype="none"/><v:textbox style="mso-direction-alt:auto"><div style="text-align:left"></div></v:textbox><x:ClientData ObjectType="Note"><x:MoveWithCells/><x:SizeWithCells/><x:Anchor>${String(s.col+1)}, 15, ${String(s.row)}, 2, ${String(s.col+3)}, 15, ${String(s.row+4)}, 4</x:Anchor><x:AutoFill>False</x:AutoFill><x:Row>${String(s.row)}</x:Row><x:Column>${String(s.col)}</x:Column></x:ClientData></v:shape>`]:[]}).join("")}</xml>`}const fe=l=>`FF${l.slice(1).toUpperCase()}`;function at(l){if(l.type==="dataBar"||l.type==="colorScale"||l.type==="iconSet")return{};const t={};for(const n of["bold","italic","underline","strike","color","fill","border","format"])l[n]!==void 0&&(t[n]=l[n]);return t}function lt(l,t,n){const e=t.values!==void 0||t.blanks!==void 0,{conditions:s,top:o,average:i,color:a}=t,c=e?r("filters",{blank:t.blanks===!0?!0:void 0},(t.values??[]).map(d=>r("filter",{val:d})).join("")):s?r("customFilters",{and:s.length===2&&t.or!==!0?!0:void 0},s.map(d=>r("customFilter",{operator:d.operator==="equal"?void 0:d.operator,val:String(d.value)})).join("")):o?r("top10",{top:o.bottom===!0?!1:void 0,percent:o.percent===!0?!0:void 0,val:o.count}):i?r("dynamicFilter",{type:i==="above"?"aboveAverage":"belowAverage"}):a?.fill!==void 0?r("colorFilter",{dxfId:n({fill:a.fill})}):a?.font!==void 0?r("colorFilter",{dxfId:n({color:a.font}),cellColor:!1}):"";return r("filterColumn",{colId:l},c)}const v=l=>l===void 0?"":` s="${String(l)}"`,ct=new Set(["#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#GETTING_DATA"]),he=l=>ct.has(l.code),dt=new Set(["width","height","hidden"]);function ue(l){if(!l)return;const t=Object.fromEntries(Object.entries(l).filter(([n])=>!dt.has(n)));return Object.keys(t).length===0?void 0:t}const U=l=>E+r("Relationships",{xmlns:T.pkg},l.map(([t,n,e],s)=>r("Relationship",{Id:`rId${String(s+1)}`,Type:t,Target:n,TargetMode:e})).join(""));function ft(l,t){const n=t.formula?.node;if(n)return V(n,{isTable:s=>l.table(s)!==void 0,array:!0});const{value:e}=t;return e==null?'""':typeof e=="string"?`"${e.replaceAll('"','""')}"`:typeof e=="boolean"?e?"TRUE":"FALSE":e instanceof P?e.code:String(e)}const ht=(l,t)=>l.length===t.length&&l.every((n,e)=>n===t[e]),me=l=>`$${F(l.left)}$${String(l.top+1)}:$${F(l.right)}$${String(l.bottom+1)}`;function ut(l){const t=[],n=(e,s)=>r("definedName",{name:e.name,localSheetId:s,hidden:e.hidden===!0?!0:void 0},y(ft(l,e)));for(const e of l.names.values())t.push(n(e));return l.sheets.forEach((e,s)=>{for(const f of e.names.values())t.push(n(f,s));const o=e.filters.find(f=>!f.table);o&&t.push(r("definedName",{name:"_xlnm._FilterDatabase",localSheetId:s,hidden:!0},y(`${q(e.name)}${me(o.area)}`)));const i=q(e.name),a=e.spec.print,c=a?.area===void 0?void 0:ye(a.area);c&&t.push(r("definedName",{name:"_xlnm.Print_Area",localSheetId:s},y(`${i}${me(c)}`)));const d=[a?.title_cols?.toUpperCase().replace(/([A-Z]+):([A-Z]+)/u,"$$$1:$$$2"),a?.title_rows?.replace(/(\d+):(\d+)/u,"$$$1:$$$2")].flatMap(f=>f===void 0?[]:[`${i}${f}`]);d.length>0&&t.push(r("definedName",{name:"_xlnm.Print_Titles",localSheetId:s},y(d.join(","))))}),t}function mt(l){if(l===void 0)return{};const t=l===!0?{}:l;return{iterate:!0,iterateCount:t.max_iterations??se.max_iterations,iterateDelta:t.max_change??se.max_change}}export function writeXlsx(l,t={}){const n=l.wb,e=[];n.checks.length>0&&e.push(`${String(n.checks.length)} check${n.checks.length===1?"":"s"}: a file has no such thing`);const s=Ee(l);e.push(...s.left);const o=new Le,i=new We,a=new Qe(n),c=new Fe,d=[["/xl/workbook.xml",C.sheet]],f=Math.max(0,n.sheets.findIndex(p=>p.spec.hidden!==!0));let h=1,u=!1;const m=new Map;let g=0,w=0,x=0;for(const[p,$]of n.sheets.entries()){const H=String(p+1),O=Ke($,l,t.file,e),D=$.charts.filter(({spec:b})=>[b.categories,...b.series.flatMap(_=>[_.values,_.x])].some(_=>_?.endsWith("#"))).length;D>0&&e.push(`${$.name}: ${String(D)} chart${D===1?"":"s"} on a spill: ${D===1?"it reads":"they read"} the cells the spill covers now, and will not grow with it`);const K=new st($,l,o,i,t.cached!==!1,e,a,p,O,s.sheets.find(b=>b.sheet===$)),ge=K.write(c.part(`xl/worksheets/sheet${H}.xml`),p===f,h);u||=K.arrays,d.push([`/xl/worksheets/sheet${H}.xml`,C.worksheet]);const L=[];for(const b of ge){const _=`table${String(h)}.xml`;h+=1,c.add(`xl/tables/${_}`,b),d.push([`/xl/tables/${_}`,C.table]),L.push([`${k}table`,`../tables/${_}`])}if($.charts.length>0||O.length>0){g+=1;const b=`drawing${String(g)}.xml`;c.add(`xl/drawings/${b}`,Me($.charts,O)),d.push([`/xl/drawings/${b}`,C.drawing]),L.push([`${k}drawing`,`../drawings/${b}`]);const _=$.charts.map(I=>{w+=1;const N=`chart${String(w)}.xml`;return c.add(`xl/charts/${N}`,Re(l,$,I)),d.push([`/xl/charts/${N}`,C.chart]),[`${k}chart`,`../charts/${N}`]});for(const I of O){const Q=[...m].find(([,we])=>ht(we,I.bytes))?.[0]??`image${String(m.size+1)}${I.file}`;m.set(Q,I.bytes),_.push([`${k}image`,`../media/${Q}`])}c.add(`xl/drawings/_rels/${b}.rels`,U(_))}const B=Object.entries($.spec.notes??{});if(B.length>0){x+=1;const b=String(x);c.add(`xl/comments${b}.xml`,rt(B)),d.push([`/xl/comments${b}.xml`,C.comments]),c.add(`xl/drawings/vmlDrawing${b}.vml`,it(B)),L.push([`${k}vmlDrawing`,`../drawings/vmlDrawing${b}.vml`]),L.push([`${k}comments`,`../comments${b}.xml`])}for(const b of Object.values($.spec.links??{}))b.startsWith("#")||L.push([`${k}hyperlink`,b,"External"]);L.length>0&&c.add(`xl/worksheets/_rels/sheet${H}.xml.rels`,U(L))}const R=n.sheets.length,A=a.columns.length>0;if(A){const p=`xl/worksheets/sheet${String(R+1)}.xml`;c.add(p,a.xml(i)),d.push([`/${p}`,C.worksheet])}const S=[...n.sheets,...A?[void 0]:[]].map((p,$)=>[`${k}worksheet`,`worksheets/sheet${String($+1)}.xml`]);S.push([`${k}theme`,"theme/theme1.xml"]),S.push([`${k}styles`,"styles.xml"]),S.push([`${k}sharedStrings`,"sharedStrings.xml"]),u&&(S.push([`${k}sheetMetadata`,"metadata.xml"]),d.push(["/xl/metadata.xml",C.metadata]));const Z=ut(n),J=n.sheets.map((p,$)=>r("sheet",{name:p.name,sheetId:$+1,state:p.spec.hidden===!0?"hidden":void 0,"r:id":`rId${String($+1)}`}));A&&J.push(r("sheet",{name:a.name,sheetId:R+1,state:"veryHidden","r:id":`rId${String(R+1)}`})),c.add("xl/workbook.xml",E+r("workbook",{xmlns:T.main,"xmlns:r":T.rel},r("workbookPr",{}),r("bookViews",{},r("workbookView",{activeTab:f===0?void 0:f})),r("sheets",{},J.join("")),Z.length>0?r("definedNames",{},Z.join("")):"",r("calcPr",{calcId:Ne,fullCalcOnLoad:!0,...mt(n.file.iteration)}))),c.add("xl/_rels/workbook.xml.rels",U(S)),c.add("xl/styles.xml",E+o.xml()),i.write(c.part("xl/sharedStrings.xml")),c.add("xl/theme/theme1.xml",E+Ie),u&&c.add("xl/metadata.xml",E+Xe),c.add("docProps/core.xml",E+r("cp:coreProperties",{"xmlns:cp":"http://schemas.openxmlformats.org/package/2006/metadata/core-properties","xmlns:dc":"http://purl.org/dc/elements/1.1/"},n.title===void 0?"":r("dc:title",{},y(n.title)))),c.add("docProps/app.xml",E+r("Properties",{xmlns:"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"},r("Application",{},"AllyHub"))),c.add("_rels/.rels",U([[`${k}officeDocument`,"xl/workbook.xml"],["http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties","docProps/core.xml"],[`${k}extended-properties`,"docProps/app.xml"]])),d.push(["/xl/styles.xml",C.styles],["/xl/sharedStrings.xml",C.strings],["/xl/theme/theme1.xml",C.theme],["/docProps/core.xml",C.core],["/docProps/app.xml",C.app]);const pe=[...m].sort(([p],[$])=>p.localeCompare($));for(const[p,$]of pe)c.add(`xl/media/${p}`,$);return c.add("[Content_Types].xml",E+r("Types",{xmlns:T.types},r("Default",{Extension:"rels",ContentType:"application/vnd.openxmlformats-package.relationships+xml"}),r("Default",{Extension:"xml",ContentType:"application/xml"}),x>0?r("Default",{Extension:"vml",ContentType:"application/vnd.openxmlformats-officedocument.vmlDrawing"}):"",[...new Set([...m.keys()].map(p=>p.split(".").pop()??""))].sort().map(p=>r("Default",{Extension:p,ContentType:`image/${De[p]??p}`})).join(""),d.map(([p,$])=>r("Override",{PartName:p,ContentType:$})).join(""))),{bytes:c.finish(),left:e}}function pt(l){const t=(s,o,i)=>o.length===0?"":r(s,{count:o.length,manualBreakCount:o.length},o.map(a=>r("brk",{id:a,max:i,man:!0})).join("")),n=[...new Set(l?.rows??[])].sort((s,o)=>s-o).map(s=>s-1),e=[...new Set((l?.cols??[]).map(s=>te(s.toUpperCase())).filter(s=>s!==void 0&&s>0))].sort((s,o)=>s-o);return t("rowBreaks",n,X-1)+t("colBreaks",e,W-1)}
|
|
@@ -184,6 +184,16 @@ export declare function clockOf(slide: {
|
|
|
184
184
|
start?: "auto" | "on-click" | undefined;
|
|
185
185
|
} | undefined;
|
|
186
186
|
} | undefined;
|
|
187
|
+
/** An item drawn live (docs/design/references.md): its playback, as a movie's. */
|
|
188
|
+
item?: {
|
|
189
|
+
playback?: {
|
|
190
|
+
start?: "auto" | "on-click" | undefined;
|
|
191
|
+
trim?: {
|
|
192
|
+
start?: number | undefined;
|
|
193
|
+
end?: number | undefined;
|
|
194
|
+
} | undefined;
|
|
195
|
+
} | undefined;
|
|
196
|
+
} | undefined;
|
|
187
197
|
}[];
|
|
188
198
|
transition?: ResolvedTransition;
|
|
189
199
|
}, first: boolean): SlideClock & {
|