@allyhub/sdk 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/node_modules/@allyhub/audio/package.json +1 -1
- package/dist/node_modules/@allyhub/chart/dist/chart-xml.d.ts +3 -0
- package/dist/node_modules/@allyhub/chart/dist/chart-xml.js +2 -2
- package/dist/node_modules/@allyhub/chart/dist/chart.d.ts +22 -0
- package/dist/node_modules/@allyhub/chart/dist/chart.js +1 -1
- package/dist/node_modules/@allyhub/chart/package.json +1 -1
- package/dist/node_modules/@allyhub/diagnostics/dist/problem.d.ts +7 -0
- package/dist/node_modules/@allyhub/diagnostics/package.json +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/faces.d.ts +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/sheet.d.ts +87 -1
- package/dist/node_modules/@allyhub/formats/dist/data/sheet.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/slides.d.ts +89 -0
- package/dist/node_modules/@allyhub/formats/dist/data/slides.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/note-shape.d.ts +20 -0
- package/dist/node_modules/@allyhub/formats/dist/note-shape.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/schemas.d.ts +50 -0
- package/dist/node_modules/@allyhub/formats/package.json +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/dist/index.d.ts +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/dist/geometry/index.js +1 -1
- package/dist/node_modules/@allyhub/ooxml/package.json +1 -1
- package/dist/node_modules/@allyhub/piece/dist/layer.d.ts +2 -0
- package/dist/node_modules/@allyhub/piece/dist/layout.d.ts +16 -0
- package/dist/node_modules/@allyhub/piece/dist/page/index.d.ts +1 -1
- package/dist/node_modules/@allyhub/piece/dist/page/index.js +1 -1
- package/dist/node_modules/@allyhub/piece/dist/page/locate.d.ts +14 -1
- package/dist/node_modules/@allyhub/piece/dist/page/locate.js +1 -1
- package/dist/node_modules/@allyhub/piece/dist/stage.d.ts +18 -0
- package/dist/node_modules/@allyhub/piece/package.json +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/account.d.ts +140 -0
- package/dist/node_modules/@allyhub/protocol/dist/account.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/auth.d.ts +19 -1
- package/dist/node_modules/@allyhub/protocol/dist/auth.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/cloud.d.ts +157 -0
- package/dist/node_modules/@allyhub/protocol/dist/cloud.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/editor.d.ts +10 -2
- package/dist/node_modules/@allyhub/protocol/dist/editor.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/frame.d.ts +101 -186
- package/dist/node_modules/@allyhub/protocol/dist/frame.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/mail.d.ts +1 -0
- package/dist/node_modules/@allyhub/protocol/dist/mail.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/notes.d.ts +92 -94
- package/dist/node_modules/@allyhub/protocol/dist/notes.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/snapshots.d.ts +17 -0
- package/dist/node_modules/@allyhub/protocol/dist/snapshots.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/teams.d.ts +7 -0
- package/dist/node_modules/@allyhub/protocol/dist/teams.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/tools.d.ts +15 -3
- 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/dist/index.d.ts +2 -2
- package/dist/node_modules/@allyhub/scenery/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/scenery/dist/moire.d.ts +45 -5
- package/dist/node_modules/@allyhub/scenery/dist/moire.js +2 -2
- package/dist/node_modules/@allyhub/scenery/dist/phone.d.ts +4 -3
- package/dist/node_modules/@allyhub/scenery/dist/phone.js +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 +70 -0
- package/dist/node_modules/@allyhub/sheet/dist/calc/engine.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/functions/criteria.d.ts +6 -0
- 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/define.d.ts +3 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/functions/define.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/kernels.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/maths.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/functions/text.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/indexes.d.ts +9 -0
- package/dist/node_modules/@allyhub/sheet/dist/calc/indexes.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/calc/types.d.ts +6 -0
- package/dist/node_modules/@allyhub/sheet/dist/calc/types.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/chart.d.ts +9 -0
- package/dist/node_modules/@allyhub/sheet/dist/chart.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/export.d.ts +0 -8
- package/dist/node_modules/@allyhub/sheet/dist/export.js +2 -4
- package/dist/node_modules/@allyhub/sheet/dist/formula/ast.d.ts +12 -1
- package/dist/node_modules/@allyhub/sheet/dist/formula/move.d.ts +5 -1
- package/dist/node_modules/@allyhub/sheet/dist/formula/move.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/formula/parse.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/formula/print.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/index.d.ts +3 -2
- package/dist/node_modules/@allyhub/sheet/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/inspect.d.ts +12 -2
- package/dist/node_modules/@allyhub/sheet/dist/inspect.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/printed.d.ts +19 -0
- package/dist/node_modules/@allyhub/sheet/dist/printed.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/values.d.ts +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/values.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/workbook.d.ts +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/workbook.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/write.js +15 -15
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/charts.d.ts +6 -2
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/charts.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/formula.js +2 -2
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/import.d.ts +0 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/import.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.d.ts +3 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.js +2 -2
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/sax.d.ts +7 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/sax.js +3 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/styles.d.ts +6 -0
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/styles.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/write.d.ts +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/write.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/xml.d.ts +12 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/xml.js +3 -2
- package/dist/node_modules/@allyhub/sheet/package.json +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/api.d.ts +57 -7
- package/dist/node_modules/@allyhub/slides-core/dist/api.js +2 -2
- package/dist/node_modules/@allyhub/slides-core/dist/capabilities.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/enums.d.ts +24 -0
- package/dist/node_modules/@allyhub/slides-core/dist/enums.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/fact.d.ts +15 -0
- package/dist/node_modules/@allyhub/slides-core/dist/measure.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/model.d.ts +6 -2
- package/dist/node_modules/@allyhub/slides-core/dist/resolve.d.ts +3 -1
- package/dist/node_modules/@allyhub/slides-core/dist/resolve.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/sdk.d.ts +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/sdk.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/package.json +1 -1
- package/dist/node_modules/@allyhub/video-core/dist/piece.d.ts +2 -2
- package/dist/node_modules/@allyhub/video-core/dist/schema.d.ts +2 -2
- package/dist/node_modules/@allyhub/video-core/dist/schema.js +1 -1
- package/dist/node_modules/@allyhub/video-core/package.json +1 -1
- package/dist/node_modules/@allyhub/video-sdk/dist/phone.d.ts +12 -5
- package/dist/node_modules/@allyhub/video-sdk/dist/phone.js +1 -1
- package/dist/node_modules/@allyhub/video-sdk/package.json +1 -1
- package/docs/README.md +4 -0
- package/docs/canvas.md +28 -0
- package/docs/defaults.md +30 -4
- package/docs/docs.md +10 -10
- package/docs/image.md +3 -3
- package/docs/linkedin.md +96 -0
- package/docs/reports.md +89 -0
- package/docs/scenery.md +3 -4
- package/docs/sheets.md +23 -6
- package/docs/slides.md +50 -4
- package/docs/speech.md +1 -1
- package/docs/x.md +73 -0
- package/package.json +1 -1
|
@@ -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 ve}from"@allyhub/formats";import{SHEET_ICONS as Se,SHEET_MARGINS as de,SHEET_OPERATORS as Ce,SHEET_PAPERS as Ee,SHEET_VALIDATIONS as Ne}from"@allyhub/formats";import{MAX_COLUMNS as q,MAX_ROWS as K,cellName as Y,columnLetter as Ae,readAddress as Oe,readArea as G,readAreas as ee}from"../address.js";import{SHEET_CHART_DEFAULTS as ce}from"../chart.js";import{moveFormula as Te,relativeKey as Ie}from"../formula/move.js";import{printFormula as fe}from"../formula/print.js";import{ERR as Le,errorOf as Re,serialOfDate as Me}from"../values.js";import{OFFICE_THEME as Fe,colorOf as F,paletteOf as le,themeColors as De}from"./colors.js";import{chartAnchors as je,readChart as Pe}from"./charts.js";import{isRangeText as ze,readFileFormula as te}from"./formula.js";import{BUILTIN_FORMATS as _e}from"./numfmt.js";import{XmlStream as ue}from"./sax.js";import{attr as u,flag as v,numberAttr as k,readXml as he,readXstring as A,tag as d,tags as x,textOf as E}from"./xml.js";import{ZipIn as He}from"./zip.js";const pe=7,Ve=r=>Math.floor((256*r+Math.floor(128/pe))/256*pe),Ue=r=>Math.round(r*4/3),ne=5;export function placesLine(r){const e=r.slice(0,ne).join(", ");return r.length>ne?`${e} and ${String(r.length-ne)} more`:e}const H=(r,e,t=`${e}s`)=>`${String(r)} ${r===1?e:t}`;export const GRID_END=`Excel's grid ends at ${Ae(q-1)}${String(K)} (${K.toLocaleString("en-US")} rows, ${q.toLocaleString("en-US")} columns)`;function We(r,e){let t=0,n=0;const o=r.length;for(;t<o;t++){const i=r.charCodeAt(t),c=i>=65&&i<=90,a=i>=97&&i<=122;if(!c&&!a)break;n=n*26+(c?i-64:i-96)}if(t===0||t===o)return;let s=0;for(let i=t;i<o;i++){const c=r.charCodeAt(i);if(c<48||c>57)return;s=s*10+c-48}if(s!==0){if(t>3||n>q||s>K)throw new Error(`${e} has a cell at ${r}, and ${GRID_END}.`);return{row:s-1,col:n-1}}}class Be{zip;constructor(e,t){this.zip=new He(e,t)}get names(){return this.zip.names}has(e){return this.zip.has(e)}text(e){return this.zip.text(e)}bytes(e){return this.zip.bytesOf(e)}xml(e){const t=this.text(e);return t===void 0?void 0:he(t)}stream(e,t){const n=this.zip.streamText(e,o=>{t.push(o)});return n&&t.end(),n}rels(e){const t=e.lastIndexOf("/"),n=`${e.slice(0,t+1)}_rels/${e.slice(t+1)}.rels`,o=this.xml(n);return x(d(o?.Relationships)?.Relationship).map(s=>{const i=u(s,"Type")??"",c=u(s,"Target")??"",a=u(s,"TargetMode")==="External";return{id:u(s,"Id")??"",type:i.slice(i.lastIndexOf("/")+1),target:a?c:Xe(e,c),external:a}})}count(e){return this.names.filter(t=>e.test(t)).length}}function Xe(r,e){if(e.startsWith("/"))return e.slice(1);const t=r.split("/").slice(0,-1);for(const n of e.split("/"))n===".."?t.pop():n!=="."&&t.push(n);return t.join("/")}function qe(r,e){const t=[];if(e===void 0)return t;let n,o=0,s=!1;const i={open(c){if(c==="si"){n={text:"",rich:!1};return}if(n){if(o>0||c==="rPh"||c==="phoneticPr"||c==="extLst"){o+=1;return}c==="r"&&(n.rich=!0),c==="t"&&(s=!0)}},close(c){if(o>0){o-=1;return}if(c==="si"){n&&t.push({...n,text:A(n.text)}),n=void 0;return}c==="t"&&(s=!1)},text(c){n&&s&&o===0&&(n.text+=c)}};return r.stream(e,new ue(i)),t}function W(r,e){const t=r[e];if(t===void 0)return!1;const n=u(d(t),"val");return n===void 0||n!=="0"&&n!=="false"}const Ge=new Set(["double","singleAccounting","doubleAccounting"]);function Ze(r,e,t){const n={},o=(a,l)=>u(d(a?.[l]),"val");if(W(r,"b")&&(n.bold=!0),W(r,"i")&&(n.italic=!0),W(r,"strike")&&(n.strike=!0),W(r,"u")){const a=o(r,"u");n.underline=a!==void 0&&Ge.has(a)?a:!0}const s=o(r,"name");s!==void 0&&s!==o(e,"name")&&(n.font=s);const i=o(r,"sz");i!==void 0&&i!==o(e,"sz")&&(n.size=Number(i));const c=F(d(r.color),t);return c!==void 0&&c!==F(d(e?.color),t)&&(n.color=c),n}function Je(r,e){const t=d(r.patternFill),n=u(t,"patternType");if(n===void 0||n==="none")return;const o=F(d(t?.fgColor),e),s=F(d(t?.bgColor),e);return n==="solid"&&o!==void 0?o:{pattern:n,...o===void 0?{}:{color:o},...s===void 0?{}:{background:s}}}function me(r,e){const t={};for(const n of["left","right","top","bottom"]){const o=d(r[n]),s=u(o,"style");if(s===void 0||s==="none")continue;const i=F(d(o?.color),e);t[n]={style:s,...i===void 0?{}:{color:i}}}return Object.keys(t).length===0?void 0:t}function Ke(r){const e={},t=u(r,"horizontal");t!==void 0&&t!=="general"&&(e.align=t);const n=u(r,"vertical");n!==void 0&&n!=="bottom"&&(e.valign=n),v(r,"wrapText")===!0&&(e.wrap=!0),v(r,"shrinkToFit")===!0&&(e.shrink=!0);const o=k(r,"indent");o!==void 0&&o>0&&(e.indent=o);const s=k(r,"textRotation");return s!==void 0&&s>0&&s<=180&&(e.rotation=s),e}function ge(r,e){const t={},n=d(r.font);if(n){const a=(f,p)=>{n[f]!==void 0&&(t[p]=W(n,f))};a("b","bold"),a("i","italic"),a("strike","strike"),n.u!==void 0&&(t.underline=W(n,"u"));const l=F(d(n.color),e);l!==void 0&&(t.color=l)}const o=d(d(r.fill)?.patternFill),s=F(d(o?.bgColor),e)??F(d(o?.fgColor),e);s!==void 0&&(t.fill=s);const i=d(r.border),c=i&&me(i,e);return c!==void 0&&(t.border=c),t}function Qe(r,e){const t=d(r?.styleSheet),n=le(e,t),o=new Map(x(d(t?.numFmts)?.numFmt).map(w=>[k(w,"numFmtId")??-1,u(w,"formatCode")??"General"])),s=x(d(t?.fonts)?.font),i=x(d(t?.fills)?.fill),c=x(d(t?.borders)?.border),a=x(d(t?.cellXfs)?.xf),l=s[k(a[0],"fontId")??0],f=new Set;i.some(w=>w.gradientFill!==void 0)&&f.add("gradient fills");const p=a.map(w=>{const m={},$=s[k(w,"fontId")??0];$&&(Object.assign(m,Ze($,l,n)),$.vertAlign!==void 0&&f.add("superscript and subscript"));const S=i[k(w,"fillId")??0],O=S&&Je(S,n);O!==void 0&&(m.fill=O);const T=c[k(w,"borderId")??0],z=T&&me(T,n);z!==void 0&&(m.border=z),T&&u(d(T.diagonal),"style")!==void 0&&f.add("diagonal borders");const D=d(w.alignment);D&&(Object.assign(m,Ke(D)),k(D,"textRotation")===255&&f.add("vertical text"));const I=k(w,"numFmtId")??0,M=o.get(I)??_e[I];return M!==void 0&&M!=="General"&&(m.format=M),m}),h=u(d(l?.name),"val"),b=u(d(l?.sz),"val");return{looks:p,dxfs:x(d(t?.dxfs)?.dxf).map(w=>ge(w,n)),font:{...h===void 0?{}:{name:h},...b===void 0?{}:{size:Number(b)}},lost:[...f]}}function be(r){const e=new Map;let t=0;for(const n of x(r.filterColumn)){const o=k(n,"colId")??0,s=d(n.filters);if(!s){Object.keys(n).some(c=>c!=="colId"&&c!=="hiddenButton")&&(t+=1);continue}if(s.dateGroupItem!==void 0){t+=1;continue}const i=x(s.filter).map(c=>A(u(c,"val")??""));e.set(o,{...i.length===0?{}:{values:i},...v(s,"blank")===!0?{blanks:!0}:{}})}return{columns:e,unread:t}}function Ye(r){const e=d(r?.table),t=G(u(e,"ref")??""),n=u(e,"displayName")??u(e,"name");if(!t||n===void 0)return;const o=d(e?.tableStyleInfo),s=d(e?.autoFilter);return{name:n,ref:t,headers:k(e,"headerRowCount")??1,totals:k(e,"totalsRowCount")??0,columns:x(d(e?.tableColumns)?.tableColumn).map(i=>({name:A(u(i,"name")??"").trim(),calculated:i.calculatedColumnFormula!==void 0})),style:u(o,"name")??"none",...s?{filter:be(s)}:{}}}function oe(r){const e=r.trim();if(e==="")return;const t=/^"((?:[^"]|"")*)"$/u.exec(e);if(t)return(t[1]??"").replaceAll('""','"');const n=Number(e);if(!Number.isNaN(n))return n;const o=te(e,!0);return o.ok?fe(o.node):void 0}const xe=r=>r!==void 0&&Ce.includes(r);function re(r){const e=u(r,"type")??"num",t=u(r,"val")??(r.f===void 0?void 0:E(r.f)),n=t===void 0?void 0:oe(t);return{at:e,...n===void 0?{}:{value:n}}}const et=Se,tt=r=>{const e=r.formula??r.f;return(Array.isArray(e)?e:e===void 0?[]:[e]).map(E)};function nt(r,e,t,n){const o=u(r,"type")??"",s={range:e,...v(r,"stopIfTrue")===!0?{stop:!0}:{}},i={...t.bold===void 0?{}:{bold:t.bold},...t.italic===void 0?{}:{italic:t.italic},...t.underline===void 0?{}:{underline:t.underline!==!1},...t.strike===void 0?{}:{strike:t.strike},...t.color===void 0?{}:{color:t.color},...typeof t.fill=="string"?{fill:t.fill}:{},...t.border===void 0?{}:{border:t.border}},c=tt(r);switch(o){case"cellIs":{const a=u(r,"operator"),l=c.flatMap(f=>{const p=oe(f);return p===void 0?[]:[p]});return!xe(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=u(r,"text");return a===void 0?`a ${o} rule with no text`:{...s,...i,type:"containsText",...o==="containsText"?{}:{operator:o==="notContainsText"?"notContains":o},text:A(a)}}case"duplicateValues":case"uniqueValues":return{...s,...i,type:o};case"top10":return{...s,...i,type:"top10",rank:k(r,"rank")??10,...v(r,"percent")===!0?{percent:!0}:{},...v(r,"bottom")===!0?{bottom:!0}:{}};case"aboveAverage":return{...s,...i,type:"aboveAverage",...v(r,"aboveAverage")===!1?{below:!0}:{},...v(r,"equalAverage")===!0?{equal:!0}:{}};case"expression":{const a=c[0]===void 0?void 0:te(c[0],!0);return a?.ok?{...s,...i,type:"expression",formula:fe(a.node)}:"an expression rule that cannot be read"}case"dataBar":{const a=d(r.dataBar),l=F(d(a?.color??a?.fillColor),n),[f,p]=x(a?.cfvo).map(re);return l===void 0?"a data bar with no colour":{...s,type:"dataBar",color:l,...f&&f.at!=="min"?{min:f}:{},...p&&p.at!=="max"?{max:p}:{},...v(a,"showValue")===!1?{show:!1}:{}}}case"colorScale":{const a=d(r.colorScale),l=x(a?.cfvo).map(re),f=x(a?.color).map(h=>F(h,n)),p=l.flatMap((h,b)=>{const w=f[b];return w===void 0?[]:[{...h,color:w}]});return p.length<2?"a colour scale with too few stops":{...s,type:"colorScale",stops:p.slice(0,3)}}case"iconSet":{const a=d(r.iconSet),l=u(a,"iconSet")??"3TrafficLights1";if(!et.includes(l))return`the icon set ${l}`;if(a?.cfIcon!==void 0)return"an icon set of icons chosen one by one";const f=x(a?.cfvo).map(re);return{...s,type:"iconSet",icons:l,...f.length>=3?{stops:f.slice(0,5)}:{},...v(a,"reverse")===!0?{reverse:!0}:{},...v(a,"showValue")===!1?{show:!1}:{}}}default:return`a ${o} rule`}}const we={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},ye=(r,e)=>x(d(r.extLst)?.ext).find(t=>u(t,"uri")?.toUpperCase()===e.toUpperCase());function ot(r,e,t){const n=[],o=[],s=new Set,i=(a,l,f)=>{const p=nt(a,l,f,t);typeof p=="string"?o.push(`${p} on ${l}`):n.push({priority:k(a,"priority")??0,rule:p})};for(const a of x(r.conditionalFormatting)){const l=u(a,"sqref")??"";if(!ee(l)){o.push(`a rule on ${l}`);continue}for(const f of x(a.cfRule)){const p=E(d(d(f.extLst)?.ext)?.id);p!==""&&s.add(p.toUpperCase());const h=k(f,"dxfId");i(f,l,h===void 0?{}:e[h]??{})}}const c=d(ye(r,we.conditional)?.conditionalFormattings);for(const a of x(c?.conditionalFormatting)){const l=E(a.sqref).trim();for(const f of x(a.cfRule)){if(s.has((u(f,"id")??"").toUpperCase()))continue;if(!ee(l)){o.push(`a rule on ${l}`);continue}const p=d(f.dxf);i(f,l,p?ge(p,t):{})}}return{rules:n.sort((a,l)=>a.priority-l.priority).map(a=>a.rule),unread:o}}const rt=Ne;function $e(r,e,t,n){const o=u(r,"type")??"none";if(o==="none"&&u(r,"prompt")===void 0)return;if(!rt.includes(o)||!ee(e))return`a ${o} rule on ${e}`;const s=/^"((?:[^"]|"")*)"$/u.exec(t.trim()),i=o==="list"&&s?(s[1]??"").replaceAll('""','"').split(","):void 0,c=[t,n].flatMap(w=>{const m=oe(w);return m===void 0?[]:[m]}),a=u(r,"operator"),l=w=>Object.fromEntries(Object.entries(w).filter(([,m])=>m!==void 0)),f=l({title:u(r,"promptTitle"),message:u(r,"prompt")}),p=l({style:u(r,"errorStyle"),title:u(r,"errorTitle"),message:u(r,"error")}),h=v(r,"showInputMessage")!==!0,b=v(r,"showErrorMessage")!==!0;return{range:e,type:o,...xe(a)&&a!=="between"?{operator:a}:{},...i?{values:i}:{formula:c},...v(r,"allowBlank")===!0?{}:{blank:!1},...v(r,"showDropDown")===!0?{dropdown:!1}:{},...h||Object.keys(f).length>0?{prompt:{...f,...h?{show:!1}:{}}}:{},...b||Object.keys(p).length>0?{error:{...p,...b?{show:!1}:{}}}:{}}}function st(r){const e=[],t=[],n=s=>{typeof s=="string"?t.push(s):s&&e.push(s)};for(const s of x(d(r.dataValidations)?.dataValidation))n($e(s,u(s,"sqref")??"",E(s.formula1),E(s.formula2)));const o=d(ye(r,we.validations)?.dataValidations);for(const s of x(o?.dataValidation))n($e(s,E(s.sqref).trim(),E(d(s.formula1)?.f),E(d(s.formula2)?.f)));return{rules:e,unread:t}}function it(r){const e=/^(-?\d{4,})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?)?(?:Z|[+-]\d{2}:?\d{2})?$/u.exec(r)??/^()()()(\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/u.exec(r);if(!e)return;const t=e[1]==="",n=t?1899:Number(e[1]),o=t?12:Number(e[2]),s=t?30:Number(e[3]),i=Number(e[4]??0)*3600+Number(e[5]??0)*60+Number(e[6]??0)+Number(e[7]??0),c=new Date(Date.UTC(n,o-1,s)+i*1e3);if(Number.isNaN(c.getTime()))return;const a=Me(c);return t?a-Math.floor(a):a}function se(r,e,t){const n=te(r,e,t);return n.ok?{node:n.node}:{unread:r}}class at{cells=[];rows=[];rich=[];outlined=!1;rest=[];xml;masters=new Map;strings;name;isRangeName;inData=!1;row=-1;nextRow=0;nextCol=0;cell;target;buffer="";skip=0;constructor(e,t,n){this.strings=e,this.name=t,this.isRangeName=n,this.xml=new ue(this),this.xml.capture=this.rest}open(e,t){if(!this.inData){e==="sheetData"&&(this.inData=!0,this.xml.capture=void 0);return}const n=this.cell;if(n){if(this.skip>0){this.skip+=1;return}switch(e){case"v":this.target="v",this.buffer="";return;case"f":n.f={...t,text:""},this.target="f",this.buffer="";return;case"is":n.inline={text:"",rich:!1};return;case"r":n.inline&&(n.inline.rich=!0);return;case"t":n.inline&&(this.target="t",this.buffer="");return;case"rPh":case"phoneticPr":case"extLst":this.skip=1;return;default:return}}e==="row"?this.openRow(t):e==="c"&&(this.cell={r:t.r,s:t.s,t:t.t,cm:t.cm,v:void 0,f:void 0,inline:void 0})}close(e){if(!this.inData)return;const t=this.cell;if(!t){e==="sheetData"&&(this.inData=!1,this.xml.capture=this.rest);return}if(this.skip>0){this.skip-=1;return}if(e===this.target){e==="v"?t.v=this.buffer:e==="f"&&t.f?t.f.text=this.buffer:t.inline&&(t.inline.text+=this.buffer),this.target=void 0;return}e==="c"&&(this.cell=void 0,this.readCell(t))}text(e){this.target!==void 0&&this.skip===0&&(this.buffer+=e)}openRow(e){const t=e.r,n=t===void 0?void 0:Number(t);if(n!==void 0&&Number.isInteger(n)&&n>K)throw new Error(`${this.name} has a row ${t??""}, and ${GRID_END}.`);const o=n!==void 0&&Number.isInteger(n)&&n>0?n-1:this.nextRow;this.row=o,this.nextRow=o+1,this.nextCol=0;const s={row:o},i=e.ht===void 0?void 0:Number(e.ht),c=f=>f==="1"||f==="true";i!==void 0&&Number.isFinite(i)&&c(e.customHeight)&&(s.height=Ue(i)),c(e.hidden)&&(s.hidden=!0);const a=e.s===void 0?void 0:Number(e.s);a!==void 0&&a!==0&&c(e.customFormat)&&(s.style=a);const l=Number(e.outlineLevel??0);l>0&&(s.level=Math.min(7,l),this.outlined=!0),Object.keys(s).length>1&&this.rows.push(s)}value(e,t){const n=e.t??"n";if(n==="inlineStr"){const s=e.inline;return s?{value:A(s.text),...s.rich?{rich:!0}:{}}:{value:e.v===void 0?"":A(e.v)}}const o=e.v;if(o===void 0)return{value:void 0};switch(n){case"s":{const s=this.strings[Number(o)];return s?{value:s.text,...s.rich?{rich:!0}:{}}:{value:""}}case"str":return{value:A(o)};case"b":return{value:o.trim()==="1"||o.trim()==="true"};case"e":return{value:Re(o.trim())??Le.VALUE};case"d":return{value:it(o.trim())??o};default:{if(o.trim()==="")return{value:void 0};const s=Number(o);if(Number.isNaN(s))throw new Error(`${t} says it holds a number and holds ${o}.`);return{value:s}}}}formula(e,t,n,o){const s=e.f;if(s===void 0)return;const i=s.t??"normal",c=s.text;if(i==="dataTable"){o.unread=`a data table's {=TABLE(${s.r1??""})}`;return}if(i==="array"){Object.assign(o,se(c,!0,this.isRangeName));const a=G(s.ref??"");a&&(o.array=a),e.cm!==void 0&&(o.dynamic=!0);return}if(i==="shared"){const a=s.si??"";if(c!==""){const f=se(c,!1,this.isRangeName),p=f.node?Ie(f.node,t,n):"";this.masters.set(a,{node:f.node,unread:f.unread,row:t,col:n,key:p}),Object.assign(o,f),f.node&&(o.key=p);return}const l=this.masters.get(a);if(!l){o.unread=`a shared formula of a group that has no first cell (${a})`;return}l.node?(o.node=Te(l.node,t-l.row,n-l.col),o.key=l.key):l.unread!==void 0&&(o.unread=l.unread);return}c!==""&&Object.assign(o,se(c,!1,this.isRangeName))}readCell(e){const t=e.r===void 0?void 0:We(e.r,this.name),n=t?.row??this.row,o=t?.col??this.nextCol;if(o>=q)throw new Error(`${this.name} has a cell past its last column, and ${GRID_END}.`);this.nextCol=o+1;const s=e.r??Y({row:n,col:o}),{value:i,rich:c}=this.value(e,s),a={row:n,col:o,value:i,style:e.s===void 0?0:Number(e.s)||0};c===!0&&(a.rich=!0,this.rich.push(s)),this.formula(e,n,o,a),this.cells.push(a)}}function dt(r,e,t){const n=[],o=p=>n.push(`${r}: ${p}`);t.length>0&&o(`${H(t.length,"cell")} of rich text, kept as plain text (${placesLine(t)})`);const s=x(d(e.hyperlinks)?.hyperlink).filter(p=>u(p,"tooltip")!==void 0);s.length>0&&o(`the tooltips of ${H(s.length,"link")} (${placesLine(s.map(p=>u(p,"ref")??""))})`),e.sortState!==void 0&&o("a sort");const i=d(e.sheetProtection);v(i,"sheet")===!0&&(u(i,"password")!==void 0||u(i,"hashValue")!==void 0)&&o("its protection's password: it is protected with none"),e.protectedRanges!==void 0&&o("protected ranges");const c=d(e.headerFooter);(c?.evenHeader!==void 0||c?.evenFooter!==void 0||c?.firstHeader!==void 0||c?.firstFooter!==void 0)&&o("its print header and footer of the first or even pages");const a=d(e.printOptions);a&&["gridLines","headings","horizontalCentered","verticalCentered"].some(p=>v(a,p)===!0)&&o("its print options (gridlines, headings, centring)"),(e.rowBreaks!==void 0||e.colBreaks!==void 0)&&o("its page breaks"),e.oleObjects!==void 0&&o("embedded objects"),e.controls!==void 0&&o("form controls"),e.dataConsolidate!==void 0&&o("a consolidation"),e.customSheetViews!==void 0&&o("custom views"),x(d(e.sheetViews)?.sheetView).some(p=>u(d(p.pane),"state")==="split")&&o("a split, not frozen, window");const f=JSON.stringify(e.extLst??"");return f.includes("sparklineGroups")&&o("sparklines"),f.includes("slicerList")&&o("slicers"),n}function ct(r,e){const t=[],n=(s,i,c)=>{const a=r.count(s);a>0&&t.push(H(a,i,c))};r.has("xl/vbaProject.bin")&&t.push("VBA macros"),n(/^xl\/pivotTables\/pivotTable\d*\.xml$/u,"pivot table"),n(/^xl\/chartsheets\/[^/]+\.xml$/u,"chart sheet"),n(/^xl\/dialogsheets\/[^/]+\.xml$/u,"dialog sheet"),n(/^xl\/macrosheets\/[^/]+\.xml$/u,"macro sheet");const o=r.names.filter(s=>s.startsWith("xl/media/")&&!e.has(s)).length;return o>0&&t.push(H(o,"image")),n(/^xl\/embeddings\//u,"embedded object"),n(/^xl\/slicers\/[^/]+\.xml$/u,"slicer part"),n(/^xl\/timelines\/[^/]+\.xml$/u,"timeline part"),n(/^xl\/ctrlProps\/[^/]+\.xml$/u,"form control"),n(/^xl\/activeX\/[^/]+\.xml$/u,"ActiveX control"),n(/^xl\/queryTables\/[^/]+\.xml$/u,"query table"),r.has("xl/connections.xml")&&t.push("data connections"),r.names.some(s=>s.startsWith("xl/richData/"))&&t.push("rich values (data types, pictures in cells)"),r.names.some(s=>/^customXml\/item\d+\.xml$/u.test(s)&&(r.text(s)??"").includes("DataMashup"))&&t.push("Power Query queries"),t}export function readHeaderFooter(r){const e={left:"",center:"",right:""};let t="center",n=new Set;for(let o=0;o<r.length;o++){const s=r[o],i=r[o+1];if(s==="&"&&(i==="L"||i==="C"||i==="R")){t=i==="L"?"left":i==="C"?"center":"right",n=new Set([...n,t]),o+=1;continue}if(s==="&"&&i==="&"){e[t]+="&&",o+=1;continue}e[t]+=s??""}return Object.fromEntries(Object.entries(e).filter(([o,s])=>s!==""||n.has(o)))}const ft=new Map(Object.entries(Ee).map(([r,e])=>[e,r]));function lt(r,e,t){const n={},o=d(r.pageSetup),s=u(o,"orientation");(s==="portrait"||s==="landscape")&&(n.orientation=s);const i=k(o,"paperSize");if(i!==void 0){const h=ft.get(i);h?n.paper=h:t.push(`${e}: its paper size, Excel's number ${String(i)}`)}v(d(d(r.sheetPr)?.pageSetUpPr),"fitToPage")===!0&&(n.fit={width:k(o,"fitToWidth")??1,height:k(o,"fitToHeight")??1});const c=d(r.pageMargins),a={};for(const h of Object.keys(de)){const b=k(c,h);b!==void 0&&b!==de[h]&&(a[h]=b)}Object.keys(a).length>0&&(n.margins=a);const l=d(r.headerFooter),f=E(l?.oddHeader),p=E(l?.oddFooter);return f!==""&&(n.header=readHeaderFooter(A(f))),p!==""&&(n.footer=readHeaderFooter(A(p))),n}function ut(r,e,t,n,o){const s=r.rels(e),i=new Map;for(const a of s.filter(l=>l.type==="comments")){const l=d(r.xml(a.target)?.comments),f=d(l?.authors)?.author,p=(Array.isArray(f)?f:f===void 0?[]:[f]).map(h=>A(E(h)));for(const h of x(d(l?.commentList)?.comment)){const b=u(h,"ref")??"",w=d(h.text),m=x(w?.r),$=A(m.length>0?m.map(O=>E(O.t)).join(""):E(w?.t)),S=p[k(h,"authorId")??-1];b!==""&&$!==""&&i.set(b,{ref:b,text:$,...S===void 0||S===""?{}:{author:S}})}}let c=0;for(const a of s.filter(l=>l.type==="threadedComment")){const l=d(r.xml(a.target)?.ThreadedComments),f=new Map;for(const p of x(l?.threadedComment)){const h=u(p,"ref")??"",b=A(E(p.text)),w=f.get(h)??{texts:[]};if(w.texts.length===0){const m=n.get(u(p,"personId")??"");m!==void 0&&(w.author=m)}w.texts.push(b),f.set(h,w)}for(const[p,h]of f)c+=1,i.set(p,{ref:p,text:h.texts.join(`
|
|
3
|
-
`),...
|
|
2
|
+
import{ZipLimitError as Ne}from"@allyhub/formats";import{SHEET_ICONS as Ie,SHEET_MARGINS as fe,SHEET_OPERATORS as Le,SHEET_PAPERS as Me,SHEET_VALIDATIONS as Re}from"@allyhub/formats";import{MAX_COLUMNS as Z,MAX_ROWS as Q,cellName as ee,columnLetter as le,readAddress as ue,readArea as B,readAreas as te}from"../address.js";import{ITERATION_DEFAULTS as he}from"../calc/engine.js";import{SHEET_CHART_DEFAULTS as pe}from"../chart.js";import{moveFormula as Fe,relativeKey as me}from"../formula/move.js";import{parseFormula as De}from"../formula/parse.js";import{printFormula as ge}from"../formula/print.js";import{ERR as je,errorOf as Pe,serialOfDate as _e}from"../values.js";import{OFFICE_THEME as ze,colorOf as D,paletteOf as be,themeColors as He}from"./colors.js";import{chartAnchors as Ve,readChart as Ue}from"./charts.js";import{isRangeText as Be,readFileFormula as ne}from"./formula.js";import{BUILTIN_FORMATS as We}from"./numfmt.js";import{XmlStream as we}from"./sax.js";import{attr as l,flag as v,numberAttr as k,readXml as xe,readXstring as N,tag as d,tags as x,textOf as E}from"./xml.js";import{ZipIn as Xe}from"./zip.js";function qe(r){if(v(r,"iterate")!==!0)return;const e=k(r,"iterateCount"),t=k(r,"iterateDelta"),o=e===void 0?void 0:Math.min(32767,Math.max(1,Math.round(e))),n=t===void 0?void 0:Math.max(0,t),s={...o===void 0||o===he.max_iterations?{}:{max_iterations:o},...n===void 0||n===he.max_change?{}:{max_change:n}};return Object.keys(s).length>0?s:!0}const ye=7,Ge=r=>Math.floor((256*r+Math.floor(128/ye))/256*ye),Ze=r=>Math.round(r*4/3),oe=5;export function placesLine(r){const e=r.slice(0,oe).join(", ");return r.length>oe?`${e} and ${String(r.length-oe)} more`:e}const V=(r,e,t=`${e}s`)=>`${String(r)} ${r===1?e:t}`;export const GRID_END=`Excel's grid ends at ${le(Z-1)}${String(Q)} (${Q.toLocaleString("en-US")} rows, ${Z.toLocaleString("en-US")} columns)`;function Je(r,e){let t=0,o=0;const n=r.length;for(;t<n;t++){const i=r.charCodeAt(t),c=i>=65&&i<=90,a=i>=97&&i<=122;if(!c&&!a)break;o=o*26+(c?i-64:i-96)}if(t===0||t===n)return;let s=0;for(let i=t;i<n;i++){const c=r.charCodeAt(i);if(c<48||c>57)return;s=s*10+c-48}if(s!==0){if(t>3||o>Z||s>Q)throw new Error(`${e} has a cell at ${r}, and ${GRID_END}.`);return{row:s-1,col:o-1}}}class Ke{zip;constructor(e,t){this.zip=new Xe(e,t)}get names(){return this.zip.names}has(e){return this.zip.has(e)}text(e){return this.zip.text(e)}bytes(e){return this.zip.bytesOf(e)}xml(e){const t=this.text(e);return t===void 0?void 0:xe(t)}stream(e,t){const o=this.zip.streamText(e,n=>{t.push(n)});return o&&t.end(),o}rels(e){const t=e.lastIndexOf("/"),o=`${e.slice(0,t+1)}_rels/${e.slice(t+1)}.rels`,n=this.xml(o);return x(d(n?.Relationships)?.Relationship).map(s=>{const i=l(s,"Type")??"",c=l(s,"Target")??"",a=l(s,"TargetMode")==="External";return{id:l(s,"Id")??"",type:i.slice(i.lastIndexOf("/")+1),target:a?c:Qe(e,c),external:a}})}count(e){return this.names.filter(t=>e.test(t)).length}}function Qe(r,e){if(e.startsWith("/"))return e.slice(1);const t=r.split("/").slice(0,-1);for(const o of e.split("/"))o===".."?t.pop():o!=="."&&t.push(o);return t.join("/")}function Ye(r,e){const t=[];if(e===void 0)return t;let o,n=0,s=!1;const i={open(c){if(c==="si"){o={text:"",rich:!1};return}if(o){if(n>0||c==="rPh"||c==="phoneticPr"||c==="extLst"){n+=1;return}c==="r"&&(o.rich=!0),c==="t"&&(s=!0)}},close(c){if(n>0){n-=1;return}if(c==="si"){o&&t.push({...o,text:N(o.text)}),o=void 0;return}c==="t"&&(s=!1)},text(c){o&&s&&n===0&&(o.text+=c)}};return r.stream(e,new we(i)),t}function W(r,e){const t=r[e];if(t===void 0)return!1;const o=l(d(t),"val");return o===void 0||o!=="0"&&o!=="false"}const et=new Set(["double","singleAccounting","doubleAccounting"]);function tt(r,e,t){const o={},n=(a,f)=>l(d(a?.[f]),"val");if(W(r,"b")&&(o.bold=!0),W(r,"i")&&(o.italic=!0),W(r,"strike")&&(o.strike=!0),W(r,"u")){const a=n(r,"u");o.underline=a!==void 0&&et.has(a)?a:!0}const s=n(r,"name");s!==void 0&&s!==n(e,"name")&&(o.font=s);const i=n(r,"sz");i!==void 0&&i!==n(e,"sz")&&(o.size=Number(i));const c=D(d(r.color),t);return c!==void 0&&c!==D(d(e?.color),t)&&(o.color=c),o}function nt(r,e){const t=d(r.patternFill),o=l(t,"patternType");if(o===void 0||o==="none")return;const n=D(d(t?.fgColor),e),s=D(d(t?.bgColor),e);return o==="solid"&&n!==void 0?n:{pattern:o,...n===void 0?{}:{color:n},...s===void 0?{}:{background:s}}}function $e(r,e){const t={};for(const o of["left","right","top","bottom"]){const n=d(r[o]),s=l(n,"style");if(s===void 0||s==="none")continue;const i=D(d(n?.color),e);t[o]={style:s,...i===void 0?{}:{color:i}}}return Object.keys(t).length===0?void 0:t}function ot(r){const e={},t=l(r,"horizontal");t!==void 0&&t!=="general"&&(e.align=t);const o=l(r,"vertical");o!==void 0&&o!=="bottom"&&(e.valign=o),v(r,"wrapText")===!0&&(e.wrap=!0),v(r,"shrinkToFit")===!0&&(e.shrink=!0);const n=k(r,"indent");n!==void 0&&n>0&&(e.indent=n);const s=k(r,"textRotation");return s!==void 0&&s>0&&s<=180&&(e.rotation=s),e}function ke(r,e){const t={},o=d(r.font);if(o){const a=(h,u)=>{o[h]!==void 0&&(t[u]=W(o,h))};a("b","bold"),a("i","italic"),a("strike","strike"),o.u!==void 0&&(t.underline=W(o,"u"));const f=D(d(o.color),e);f!==void 0&&(t.color=f)}const n=d(d(r.fill)?.patternFill),s=D(d(n?.bgColor),e)??D(d(n?.fgColor),e);s!==void 0&&(t.fill=s);const i=d(r.border),c=i&&$e(i,e);return c!==void 0&&(t.border=c),t}function rt(r,e){const t=d(r?.styleSheet),o=be(e,t),n=new Map(x(d(t?.numFmts)?.numFmt).map(m=>[k(m,"numFmtId")??-1,l(m,"formatCode")?.replace(/^$/u,"General")??"General"])),s=x(d(t?.fonts)?.font),i=x(d(t?.fills)?.fill),c=x(d(t?.borders)?.border),a=x(d(t?.cellXfs)?.xf),f=s[k(a[0],"fontId")??0],h=new Set;i.some(m=>m.gradientFill!==void 0)&&h.add("gradient fills");const u=a.map(m=>{const $={},g=s[k(m,"fontId")??0];g&&(Object.assign($,tt(g,f,o)),g.vertAlign!==void 0&&h.add("superscript and subscript"));const S=i[k(m,"fillId")??0],C=S&&nt(S,o);C!==void 0&&($.fill=C);const I=c[k(m,"borderId")??0],M=I&&$e(I,o);M!==void 0&&($.border=M),I&&l(d(I.diagonal),"style")!==void 0&&h.add("diagonal borders");const R=d(m.alignment);R&&(Object.assign($,ot(R)),k(R,"textRotation")===255&&h.add("vertical text"));const j=k(m,"numFmtId")??0,O=n.get(j)??We[j];return O!==void 0&&O!=="General"&&($.format=O),$}),b=l(d(f?.name),"val"),p=l(d(f?.sz),"val");return{looks:u,dxfs:x(d(t?.dxfs)?.dxf).map(m=>ke(m,o)),font:{...b===void 0?{}:{name:b},...p===void 0?{}:{size:Number(p)}},lost:[...h]}}function ve(r){const e=new Map;let t=0;for(const o of x(r.filterColumn)){const n=k(o,"colId")??0,s=d(o.filters);if(!s){Object.keys(o).some(c=>c!=="colId"&&c!=="hiddenButton")&&(t+=1);continue}if(s.dateGroupItem!==void 0){t+=1;continue}const i=x(s.filter).map(c=>N(l(c,"val")??""));e.set(n,{...i.length===0?{}:{values:i},...v(s,"blank")===!0?{blanks:!0}:{}})}return{columns:e,unread:t}}function st(r){const e=d(r?.table),t=B(l(e,"ref")??""),o=l(e,"displayName")??l(e,"name");if(!t||o===void 0)return;const n=d(e?.tableStyleInfo),s=d(e?.autoFilter);return{name:o,ref:t,headers:k(e,"headerRowCount")??1,totals:k(e,"totalsRowCount")??0,columns:x(d(e?.tableColumns)?.tableColumn).map(i=>({name:N(l(i,"name")??"").trim(),calculated:i.calculatedColumnFormula!==void 0})),style:l(n,"name")??"none",...s?{filter:ve(s)}:{}}}function re(r){const e=r.trim();if(e==="")return;const t=/^"((?:[^"]|"")*)"$/u.exec(e);if(t)return(t[1]??"").replaceAll('""','"');const o=Number(e);if(!Number.isNaN(o))return o;const n=ne(e,!0);return n.ok?ge(n.node):void 0}const Se=r=>r!==void 0&&Le.includes(r);function se(r){const e=l(r,"type")??"num",t=l(r,"val")??(r.f===void 0?void 0:E(r.f)),o=t===void 0?void 0:re(t);return{at:e,...o===void 0?{}:{value:o}}}const it=Ie,at=r=>{const e=r.formula??r.f;return(Array.isArray(e)?e:e===void 0?[]:[e]).map(E)};function dt(r,e,t,o){const n=l(r,"type")??"",s={range:e,...v(r,"stopIfTrue")===!0?{stop:!0}:{}},i={...t.bold===void 0?{}:{bold:t.bold},...t.italic===void 0?{}:{italic:t.italic},...t.underline===void 0?{}:{underline:t.underline!==!1},...t.strike===void 0?{}:{strike:t.strike},...t.color===void 0?{}:{color:t.color},...typeof t.fill=="string"?{fill:t.fill}:{},...t.border===void 0?{}:{border:t.border}},c=at(r);switch(n){case"cellIs":{const a=l(r,"operator"),f=c.flatMap(h=>{const u=re(h);return u===void 0?[]:[u]});return!Se(a)||f.length===0?`a cellIs rule of ${a??"no operator"}`:{...s,...i,type:"cellIs",operator:a,formula:f}}case"containsText":case"notContainsText":case"beginsWith":case"endsWith":{const a=l(r,"text");return a===void 0?`a ${n} rule with no text`:{...s,...i,type:"containsText",...n==="containsText"?{}:{operator:n==="notContainsText"?"notContains":n},text:N(a)}}case"duplicateValues":case"uniqueValues":return{...s,...i,type:n};case"top10":return{...s,...i,type:"top10",rank:k(r,"rank")??10,...v(r,"percent")===!0?{percent:!0}:{},...v(r,"bottom")===!0?{bottom:!0}:{}};case"aboveAverage":return{...s,...i,type:"aboveAverage",...v(r,"aboveAverage")===!1?{below:!0}:{},...v(r,"equalAverage")===!0?{equal:!0}:{}};case"expression":{const a=c[0]===void 0?void 0:ne(c[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(r.dataBar),f=D(d(a?.color??a?.fillColor),o),[h,u]=x(a?.cfvo).map(se);return f===void 0?"a data bar with no colour":{...s,type:"dataBar",color:f,...h&&h.at!=="min"?{min:h}:{},...u&&u.at!=="max"?{max:u}:{},...v(a,"showValue")===!1?{show:!1}:{}}}case"colorScale":{const a=d(r.colorScale),f=x(a?.cfvo).map(se),h=x(a?.color).map(b=>D(b,o)),u=f.flatMap((b,p)=>{const m=h[p];return m===void 0?[]:[{...b,color:m}]});return u.length<2?"a colour scale with too few stops":{...s,type:"colorScale",stops:u.slice(0,3)}}case"iconSet":{const a=d(r.iconSet),f=l(a,"iconSet")??"3TrafficLights1";if(!it.includes(f))return`the icon set ${f}`;if(a?.cfIcon!==void 0)return"an icon set of icons chosen one by one";const h=x(a?.cfvo).map(se);return{...s,type:"iconSet",icons:f,...h.length>=3?{stops:h.slice(0,5)}:{},...v(a,"reverse")===!0?{reverse:!0}:{},...v(a,"showValue")===!1?{show:!1}:{}}}default:return`a ${n} rule`}}const Ce={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},Te=(r,e)=>x(d(r.extLst)?.ext).find(t=>l(t,"uri")?.toUpperCase()===e.toUpperCase());function ct(r,e,t){const o=[],n=[],s=new Set,i=(a,f,h)=>{const u=dt(a,f,h,t);typeof u=="string"?n.push(`${u} on ${f}`):o.push({priority:k(a,"priority")??0,rule:u})};for(const a of x(r.conditionalFormatting)){const f=l(a,"sqref")??"";if(!te(f)){n.push(`a rule on ${f}`);continue}for(const h of x(a.cfRule)){const u=E(d(d(h.extLst)?.ext)?.id);u!==""&&s.add(u.toUpperCase());const b=k(h,"dxfId");i(h,f,b===void 0?{}:e[b]??{})}}const c=d(Te(r,Ce.conditional)?.conditionalFormattings);for(const a of x(c?.conditionalFormatting)){const f=E(a.sqref).trim();for(const h of x(a.cfRule)){if(s.has((l(h,"id")??"").toUpperCase()))continue;if(!te(f)){n.push(`a rule on ${f}`);continue}const u=d(h.dxf);i(h,f,u?ke(u,t):{})}}return{rules:o.sort((a,f)=>a.priority-f.priority).map(a=>a.rule),unread:n}}const ft=Re;function Ee(r,e,t,o){const n=l(r,"type")??"none";if(n==="none"&&l(r,"prompt")===void 0)return;if(!ft.includes(n)||!te(e))return`a ${n} rule on ${e}`;const s=/^"((?:[^"]|"")*)"$/u.exec(t.trim()),i=n==="list"&&s?(s[1]??"").replaceAll('""','"').split(","):void 0,c=[t,o].flatMap(m=>{const $=re(m);return $===void 0?[]:[$]}),a=l(r,"operator"),f=m=>Object.fromEntries(Object.entries(m).filter(([,$])=>$!==void 0)),h=f({title:l(r,"promptTitle"),message:l(r,"prompt")}),u=f({style:l(r,"errorStyle"),title:l(r,"errorTitle"),message:l(r,"error")}),b=v(r,"showInputMessage")!==!0,p=v(r,"showErrorMessage")!==!0;return{range:e,type:n,...Se(a)&&a!=="between"?{operator:a}:{},...i?{values:i}:{formula:c},...v(r,"allowBlank")===!0?{}:{blank:!1},...v(r,"showDropDown")===!0?{dropdown:!1}:{},...b||Object.keys(h).length>0?{prompt:{...h,...b?{show:!1}:{}}}:{},...p||Object.keys(u).length>0?{error:{...u,...p?{show:!1}:{}}}:{}}}function lt(r){const e=[],t=[],o=s=>{typeof s=="string"?t.push(s):s&&e.push(s)};for(const s of x(d(r.dataValidations)?.dataValidation))o(Ee(s,l(s,"sqref")??"",E(s.formula1),E(s.formula2)));const n=d(Te(r,Ce.validations)?.dataValidations);for(const s of x(n?.dataValidation))o(Ee(s,E(s.sqref).trim(),E(d(s.formula1)?.f),E(d(s.formula2)?.f)));return{rules:e,unread:t}}function ut(r){const e=/^(-?\d{4,})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?)?(?:Z|[+-]\d{2}:?\d{2})?$/u.exec(r)??/^()()()(\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/u.exec(r);if(!e)return;const t=e[1]==="",o=t?1899:Number(e[1]),n=t?12:Number(e[2]),s=t?30:Number(e[3]),i=Number(e[4]??0)*3600+Number(e[5]??0)*60+Number(e[6]??0)+Number(e[7]??0),c=new Date(Date.UTC(o,n-1,s)+i*1e3);if(Number.isNaN(c.getTime()))return;const a=_e(c);return t?a-Math.floor(a):a}let ie;function Oe(r,e){const t=r.row-e.row,o=r.col-e.col;Object.defineProperty(r,"node",{get:()=>(ie?.cell!==r&&(ie={cell:r,node:Fe(e.node,t,o)}),ie.node),set:n=>{Object.defineProperty(r,"node",{value:n,writable:!0,enumerable:!0,configurable:!0})},enumerable:!0,configurable:!0}),r.key=e.key}function ae(r,e,t){const o=ne(r,e,t);return o.ok?{node:o.node}:{unread:r}}function ht(r){const e=B(r.ref??""),t=f=>{if(f===void 0||f==="")return"";const h=ue(f.replaceAll("$",""));return h?`$${le(h.col)}$${String(h.row+1)}`:void 0},o=t(r.r1),n=t(r.r2);if(!e||o===void 0||o===""||n===void 0)return;const s=r.dt2D==="1"||r.dt2D==="true",i=r.dtr==="1"||r.dtr==="true",c=s?`${o},${n}`:i?`${o},`:`,${o}`,a=De(`=TABLE(${c})`);return a.ok?{ref:e,node:a.node}:void 0}function pt(r){for(const{ref:e,node:t}of r.dataTables){const o=new Set;for(const n of r.cells)n.row<e.top||n.row>e.bottom||n.col<e.left||n.col>e.right||(n.node=t,Reflect.deleteProperty(n,"unread"),o.add(`${String(n.row)}:${String(n.col)}`));for(let n=e.top;n<=e.bottom;n++)for(let s=e.left;s<=e.right;s++)o.has(`${String(n)}:${String(s)}`)||r.cells.push({row:n,col:s,value:void 0,node:t,style:0})}}class mt{cells=[];rows=[];dataTables=[];rich=[];outlined=!1;rest=[];xml;masters=new Map;above=new Map;left;strings;name;isRangeName;inData=!1;row=-1;nextRow=0;nextCol=0;cell;target;buffer="";skip=0;constructor(e,t,o){this.strings=e,this.name=t,this.isRangeName=o,this.xml=new we(this),this.xml.capture=this.rest}open(e,t){if(!this.inData){e==="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(e){case"v":this.target="v",this.buffer="";return;case"f":o.f={...t,text:""},this.target="f",this.buffer="";return;case"is":o.inline={text:"",rich:!1};return;case"r":o.inline&&(o.inline.rich=!0);return;case"t":o.inline&&(this.target="t",this.buffer="");return;case"rPh":case"phoneticPr":case"extLst":this.skip=1;return;default:return}}e==="row"?this.openRow(t):e==="c"&&(this.cell={r:t.r,s:t.s,t:t.t,cm:t.cm,v:void 0,f:void 0,inline:void 0})}close(e){if(!this.inData)return;const t=this.cell;if(!t){e==="sheetData"&&(this.inData=!1,this.xml.capture=this.rest);return}if(this.skip>0){this.skip-=1;return}if(e===this.target){e==="v"?t.v=this.buffer:e==="f"&&t.f?t.f.text=this.buffer:t.inline&&(t.inline.text+=this.buffer),this.target=void 0;return}e==="c"&&(this.cell=void 0,this.readCell(t))}text(e){this.target!==void 0&&this.skip===0&&(this.buffer+=e)}openRow(e){const t=e.r,o=t===void 0?void 0:Number(t);if(o!==void 0&&Number.isInteger(o)&&o>Q)throw new Error(`${this.name} has a row ${t??""}, and ${GRID_END}.`);const n=o!==void 0&&Number.isInteger(o)&&o>0?o-1:this.nextRow;this.row=n,this.nextRow=n+1,this.nextCol=0;const s={row:n},i=e.ht===void 0?void 0:Number(e.ht),c=h=>h==="1"||h==="true";i!==void 0&&Number.isFinite(i)&&c(e.customHeight)&&(s.height=Ze(i)),c(e.hidden)&&(s.hidden=!0);const a=e.s===void 0?void 0:Number(e.s);a!==void 0&&a!==0&&c(e.customFormat)&&(s.style=a);const f=Number(e.outlineLevel??0);f>0&&(s.level=Math.min(7,f),this.outlined=!0),Object.keys(s).length>1&&this.rows.push(s)}value(e,t){const o=e.t??"n";if(o==="inlineStr"){const s=e.inline;return s?{value:N(s.text),...s.rich?{rich:!0}:{}}:{value:e.v===void 0?"":N(e.v)}}const n=e.v;if(n===void 0)return{value:void 0};switch(o){case"s":{const s=this.strings[Number(n)];return s?{value:s.text,...s.rich?{rich:!0}:{}}:{value:""}}case"str":return{value:N(n)};case"b":return{value:n.trim()==="1"||n.trim()==="true"};case"e":return{value:Pe(n.trim())??je.VALUE};case"d":return{value:ut(n.trim())??n};default:{if(n.trim()==="")return{value:void 0};const s=Number(n);if(Number.isNaN(s))throw new Error(`${t} says it holds a number and holds ${n}.`);return{value:s}}}}formula(e,t,o,n){const s=e.f;if(s===void 0)return;const i=s.t??"normal",c=s.text;if(i==="dataTable"){const p=ht(s);p?this.dataTables.push(p):n.unread=`a data table's {=TABLE(${s.r1??""})}`;return}if(i==="array"){Object.assign(n,ae(c,!0,this.isRangeName));const p=B(s.ref??"");p&&(n.array=p),e.cm!==void 0&&(n.dynamic=!0);return}if(i==="shared"){const p=s.si??"";if(c!==""){const $=ae(c,!1,this.isRangeName),g=$.node?me($.node,t,o):"";this.masters.set(p,{node:$.node,unread:$.unread,row:t,col:o,key:g}),Object.assign(n,$),$.node&&(n.key=g);return}const m=this.masters.get(p);if(!m){n.unread=`a shared formula of a group that has no first cell (${p})`;return}m.node?Oe(n,{node:m.node,row:m.row,col:m.col,key:m.key}):m.unread!==void 0&&(n.unread=m.unread);return}if(c==="")return;const a=ae(c,!1,this.isRangeName);if(!a.node){Object.assign(n,a);return}const f=me(a.node,t,o),h=this.left?.row===t?this.left:void 0,u=[this.above.get(o),h].find(p=>p?.key===f);u?Oe(n,u):(n.node=a.node,n.key=f);const b=u??{node:a.node,row:t,col:o,key:f};this.above.set(o,b),this.left=b}readCell(e){const t=e.r===void 0?void 0:Je(e.r,this.name),o=t?.row??this.row,n=t?.col??this.nextCol;if(n>=Z)throw new Error(`${this.name} has a cell past its last column, and ${GRID_END}.`);this.nextCol=n+1;const s=e.r??ee({row:o,col:n}),{value:i,rich:c}=this.value(e,s),a={row:o,col:n,value:i,style:e.s===void 0?0:Number(e.s)||0};c===!0&&(a.rich=!0,this.rich.push(s)),this.formula(e,o,n,a),this.cells.push(a)}}function gt(r,e,t){const o=[],n=u=>o.push(`${r}: ${u}`);t.length>0&&n(`${V(t.length,"cell")} of rich text, kept as plain text (${placesLine(t)})`);const s=x(d(e.hyperlinks)?.hyperlink).filter(u=>l(u,"tooltip")!==void 0);s.length>0&&n(`the tooltips of ${V(s.length,"link")} (${placesLine(s.map(u=>l(u,"ref")??""))})`),e.sortState!==void 0&&n("a sort");const i=d(e.sheetProtection);v(i,"sheet")===!0&&(l(i,"password")!==void 0||l(i,"hashValue")!==void 0)&&n("its protection's password: it is protected with none"),e.protectedRanges!==void 0&&n("protected ranges");const c=d(e.headerFooter);(c?.evenHeader!==void 0||c?.evenFooter!==void 0||c?.firstHeader!==void 0||c?.firstFooter!==void 0)&&n("its print header and footer of the first or even pages");const a=d(e.printOptions);a&&["gridLines","headings","horizontalCentered","verticalCentered"].some(u=>v(a,u)===!0)&&n("its print options (gridlines, headings, centring)"),(e.rowBreaks!==void 0||e.colBreaks!==void 0)&&n("its page breaks"),e.oleObjects!==void 0&&n("embedded objects"),e.controls!==void 0&&n("form controls"),e.dataConsolidate!==void 0&&n("a consolidation"),e.customSheetViews!==void 0&&n("custom views"),x(d(e.sheetViews)?.sheetView).some(u=>l(d(u.pane),"state")==="split")&&n("a split, not frozen, window");const h=JSON.stringify(e.extLst??"");return h.includes("sparklineGroups")&&n("sparklines"),h.includes("slicerList")&&n("slicers"),o}function bt(r,e){const t=[],o=(s,i,c)=>{const a=r.count(s);a>0&&t.push(V(a,i,c))};r.has("xl/vbaProject.bin")&&t.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 n=r.names.filter(s=>s.startsWith("xl/media/")&&!e.has(s)).length;return n>0&&t.push(V(n,"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"),r.has("xl/connections.xml")&&t.push("data connections"),r.names.some(s=>s.startsWith("xl/richData/"))&&t.push("rich values (data types, pictures in cells)"),r.names.some(s=>/^customXml\/item\d+\.xml$/u.test(s)&&(r.text(s)??"").includes("DataMashup"))&&t.push("Power Query queries"),t}export function readHeaderFooter(r){const e={left:"",center:"",right:""};let t="center",o=new Set;for(let n=0;n<r.length;n++){const s=r[n],i=r[n+1];if(s==="&"&&(i==="L"||i==="C"||i==="R")){t=i==="L"?"left":i==="C"?"center":"right",o=new Set([...o,t]),n+=1;continue}if(s==="&"&&i==="&"){e[t]+="&&",n+=1;continue}e[t]+=s??""}return Object.fromEntries(Object.entries(e).filter(([n,s])=>s!==""||o.has(n)))}const wt=new Map(Object.entries(Me).map(([r,e])=>[e,r]));function xt(r,e,t){const o={},n=d(r.pageSetup),s=l(n,"orientation");(s==="portrait"||s==="landscape")&&(o.orientation=s);const i=k(n,"paperSize");if(i!==void 0){const b=wt.get(i);b?o.paper=b:t.push(`${e}: its paper size, Excel's number ${String(i)}`)}v(d(d(r.sheetPr)?.pageSetUpPr),"fitToPage")===!0&&(o.fit={width:k(n,"fitToWidth")??1,height:k(n,"fitToHeight")??1});const c=d(r.pageMargins),a={};for(const b of Object.keys(fe)){const p=k(c,b);p!==void 0&&p!==fe[b]&&(a[b]=p)}Object.keys(a).length>0&&(o.margins=a);const f=d(r.headerFooter),h=E(f?.oddHeader),u=E(f?.oddFooter);return h!==""&&(o.header=readHeaderFooter(N(h))),u!==""&&(o.footer=readHeaderFooter(N(u))),o}function yt(r,e,t,o,n){const s=r.rels(e),i=new Map;for(const a of s.filter(f=>f.type==="comments")){const f=d(r.xml(a.target)?.comments),h=d(f?.authors)?.author,u=(Array.isArray(h)?h:h===void 0?[]:[h]).map(b=>N(E(b)));for(const b of x(d(f?.commentList)?.comment)){const p=l(b,"ref")??"",m=d(b.text),$=x(m?.r),g=N($.length>0?$.map(C=>E(C.t)).join(""):E(m?.t)),S=u[k(b,"authorId")??-1];p!==""&&g!==""&&i.set(p,{ref:p,text:g,...S===void 0||S===""?{}:{author:S}})}}let c=0;for(const a of s.filter(f=>f.type==="threadedComment")){const f=d(r.xml(a.target)?.ThreadedComments),h=new Map;for(const u of x(f?.threadedComment)){const b=l(u,"ref")??"",p=N(E(u.text)),m=h.get(b)??{texts:[]};if(m.texts.length===0){const $=o.get(l(u,"personId")??"");$!==void 0&&(m.author=$)}m.texts.push(p),h.set(b,m)}for(const[u,b]of h)c+=1,i.set(u,{ref:u,text:b.texts.join(`
|
|
3
|
+
`),...b.author===void 0?{}:{author:b.author}})}return c>0&&n.push(`${t}: ${V(c,"threaded comment")}, kept as notes, replies after the first line`),[...i.values()]}function $t(r,e,t,o,n,s,i,c,a,f,h){const u=new mt(n,t,a);if(!r.stream(e,u.xml))throw new Error(`${e} is not in the file.`);pt(u);const b=xe(u.rest.join("")),p=d(b.worksheet);if(!p)throw new Error(`${e} is not a worksheet.`);const m=x(d(p.cols)?.col).map(y=>{const T=k(y,"width"),F=k(y,"style"),_=k(y,"outlineLevel")??0,A=(k(y,"min")??1)-1,de=(k(y,"max")??1)-1;if(de>=Z)throw new Error(`${t} sets a column past its last, and ${GRID_END}.`);const ce=v(y,"customWidth"),Y=T===void 0?void 0:Ge(T);return{min:A,max:de,...Y!==void 0&&(ce===!0||ce===void 0&&Y!==Ae)?{width:Y}:{},...v(y,"hidden")===!0?{hidden:!0}:{},...F===void 0||F===0?{}:{style:F},..._>0?{level:Math.min(7,_)}:{}}}),$=x(d(p.mergeCells)?.mergeCell).flatMap(y=>{const T=B(l(y,"ref")??"");return T?[T]:[]}),g=x(d(p.sheetViews)?.sheetView)[0],S=d(g?.pane);let C;const I=l(S,"state");if(I==="frozen"||I==="frozenSplit"){const y=ue(l(g,"topLeftCell")??"A1")??{row:0,col:0};C={row:y.row+(k(S,"ySplit")??0),col:y.col+(k(S,"xSplit")??0)}}const M=r.rels(e),R=M.filter(y=>y.type==="table").flatMap(y=>{const T=st(r.xml(y.target));return T?[T]:[]}),j=D(d(d(p.sheetPr)?.tabColor),s),O=gt(t,p,u.rich),X=ct(p,i,s),q=lt(p);for(const y of X.unread)O.push(`${t}: a conditional format, ${y}`);for(const y of q.unread)O.push(`${t}: a data validation, ${y}`);const z=d(p.autoFilter),J=B(l(z,"ref")??""),P=z&&J?{ref:J,...ve(z)}:void 0;P&&P.unread>0&&O.push(`${t}: ${V(P.unread,"filter")} by condition on ${l(z,"ref")??""}, its rows left as they were hidden`);const{charts:G,pictures:K}=vt(r,e,t,m,u.rows,O,f,h),U={},w=new Map(M.map(y=>[y.id,y]));for(const y of x(d(p.hyperlinks)?.hyperlink)){const T=l(y,"ref");if(T===void 0)continue;const F=l(y,"location"),_=l(y,"id"),A=_===void 0?void 0:w.get(_)?.target;A!==void 0?U[T]=F===void 0?A:`${A}#${F}`:F!==void 0&&(U[T]=`#${F}`)}const L=d(p.sheetProtection),H=xt(p,t,O);return{sheet:{name:t,state:o,cells:u.cells,merges:$,...C?{freeze:C}:{},...l(g,"showGridLines")==="0"?{gridlines:!1}:{},...j===void 0?{}:{tab:j},columns:m,rows:u.rows,tables:R,conditional:X.rules,validations:q.rules,scenarios:x(d(p.scenarios)?.scenario).map(y=>({name:l(y,"name")??"",cells:x(y.inputCells).map(T=>({at:l(T,"r")??"",value:l(T,"val")??""}))})),...P?{filter:P}:{},charts:G,links:U,notes:yt(r,e,t,c,O),pictures:K,...v(L,"sheet")===!0?{protect:!0}:{},...Object.keys(H).length>0?{print:H}:{}},lost:O}}const Ae=64,kt=20;function vt(r,e,t,o,n,s,i,c){const a=p=>o.find(m=>p>=m.min&&p<=m.max)?.width??Ae,f=new Map(n.map(p=>[p.row,p.height])),h=p=>f.get(p)??kt,u=[],b=[];for(const p of r.rels(e).filter(m=>m.type==="drawing")){const m=Ve(r.xml(p.target),a,h),$=r.rels(p.target);for(const g of m.anchors){const S=$.find(R=>R.id===g.id),C=ee(g.at);if(g.width<=0||g.height<=0){s.push(`${t}: the chart at ${C}, of no size`);continue}const I=[],M=Ue(S?r.xml(S.target):void 0,I,c);if(typeof M=="string"){s.push(`${t}: the chart at ${C}, as ${M}`);continue}for(const R of I)s.push(`${t}: the chart at ${C} without its ${R}`);u.push({...M,at:C,...g.x===void 0?{}:{x:g.x},...g.y===void 0?{}:{y:g.y},...g.width===pe.width?{}:{width:g.width},...g.height===pe.height?{}:{height:g.height}})}for(const g of m.pictures){const S=$.find(M=>M.id===g.id),C=S&&!S.external?r.bytes(S.target):void 0;if(!S||!C){s.push(`${t}: the picture at ${ee(g.at)}, whose image is not in the file`);continue}i.add(S.target);const I=S.target.slice(S.target.lastIndexOf(".")+1).toLowerCase();b.push({row:g.at.row,col:g.at.col,...g.x===void 0?{}:{x:g.x},...g.y===void 0?{}:{y:g.y},width:g.width,height:g.height,...g.name===void 0?{}:{name:g.name},...g.descr===void 0?{}:{descr:g.descr},bytes:C,type:I})}m.others>0&&s.push(`${t}: ${V(m.others,"shape")} of its drawing`)}return{charts:u,pictures:b}}function St(r,e,t){for(const o of r){if(o.sheet===void 0)continue;const n=e[o.sheet];if(!n)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&&t.push(`${n.name}: its print area's ranges after the first`),i!==void 0&&B(i)&&(n.print={...n.print,area:i})}else if(o.name==="_xlnm.Print_Titles")for(const i of s)/^\d+:\d+$/u.test(i)?n.print={...n.print,title_rows:i}:/^[A-Za-z]+:[A-Za-z]+$/u.test(i)&&(n.print={...n.print,title_cols:i})}}export function readXlsx(r,e){let t;try{t=new Ke(r,e)}catch(w){throw w instanceof Ne?w:new Error("It is not a zip file, as an .xlsx file is.")}const o=t.rels(""),n=o.find(w=>w.type==="officeDocument")?.target??"xl/workbook.xml";if(n.endsWith(".bin"))throw new Error("It is a binary workbook (.xlsb): save it as .xlsx.");const s=t.xml(n),i=d(s?.workbook);if(!i)throw new Error("It has no workbook part.");const c=t.rels(n),a=w=>c.find(L=>L.type===w)?.target,f=(()=>{const w=a("theme");return w===void 0?void 0:t.text(w)})(),h=f===void 0?ze:He(f),u=a("styles"),b=u===void 0?void 0:t.xml(u),p=rt(b,h),m=be(h,d(b?.styleSheet)),$=Ye(t,a("sharedStrings")),g=[];for(const w of p.lost)g.push(w);const S=d(i.workbookPr),C=qe(d(i.calcPr)),I=d(i.workbookProtection);(v(I,"lockStructure")===!0||v(I,"lockWindows")===!0)&&g.push("the workbook's protection"),i.fileSharing!==void 0&&g.push("its write protection");const M=new Map,R=a("person");if(R!==void 0)for(const w of x(d(t.xml(R)?.personList)?.person))M.set(l(w,"id")??"",N(l(w,"displayName")??""));const j=x(d(i.definedNames)?.definedName).map(w=>{const L=k(w,"localSheetId");return{name:l(w,"name")??"",text:N(E(w)),...L===void 0?{}:{sheet:L},...v(w,"hidden")===!0?{hidden:!0}:{}}}),O=[],X=new Set,q=new Map(c.map(w=>[w.id,w])),z=x(d(i.sheets)?.sheet),J=new Set(z.filter(w=>q.get(l(w,"id")??"")?.type==="worksheet").map(w=>N(l(w,"name")??"").toLowerCase()));for(const[w,L]of z.entries()){const H=q.get(l(L,"id")??""),y=N(l(L,"name")??"");if(H?.type!=="worksheet"){H?.type!=="chartsheet"&&H?.type!=="dialogsheet"&&g.push(`${y}: a sheet of a kind this cannot read`);continue}const T=new Map;for(const A of j)(A.sheet===void 0||A.sheet===w)&&(A.sheet!==void 0||!T.has(A.name.toLowerCase()))&&T.set(A.name.toLowerCase(),Be(A.text));const F=l(L,"state"),_=$t(t,H.target,y,F==="hidden"||F==="veryHidden"?F:"visible",$,m,p.dxfs,M,A=>T.get(A.toLowerCase())===!0,X,A=>J.has(A.toLowerCase()));O[w]=_.sheet,g.push(..._.lost)}St(j,O,g);const P=o.find(w=>w.type==="core-properties")?.target,G=P===void 0?void 0:E(d(t.xml(P)?.coreProperties)?.title).trim(),K=O.filter(w=>w!==void 0),U=new Map;return O.forEach((w,L)=>{w!==void 0&&U.set(L,K.indexOf(w))}),{sheets:K,names:j.flatMap(w=>{if(w.sheet===void 0)return[w];const L=U.get(w.sheet);return L===void 0?[]:[{...w,sheet:L}]}),looks:p.looks,dxfs:p.dxfs,date1904:v(S,"date1904")===!0,font:p.font,...G===void 0||G===""?{}:{title:G},...C===void 0?{}:{iteration:C},lost:[...bt(t,X),...g]}}
|
|
@@ -14,8 +14,14 @@ export declare class XmlStream {
|
|
|
14
14
|
private buffer;
|
|
15
15
|
private readonly handler;
|
|
16
16
|
private depth;
|
|
17
|
+
/** A piece ended in a CR, which the next may follow with its LF. */
|
|
18
|
+
private cr;
|
|
17
19
|
constructor(handler: XmlHandler);
|
|
18
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Line ends are XML's first (2.11 End-of-Line Handling): a CR LF or a CR
|
|
22
|
+
* is a LF, as Excel reads it; a CR written as stays one.
|
|
23
|
+
*/
|
|
24
|
+
push(piece: string): void;
|
|
19
25
|
end(): void;
|
|
20
26
|
private emitText;
|
|
21
27
|
private run;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
const b={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"};export function unescapeXml(r){return r.includes("&")?r.replace(/&(#x[0-9A-Fa-f]+|#\d+|[A-Za-z]+);/gu,(e,
|
|
2
|
+
const b={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"};export function unescapeXml(r){return r.includes("&")?r.replace(/&(#x[0-9A-Fa-f]+|#\d+|[A-Za-z]+);/gu,(e,n)=>n.startsWith("#x")?String.fromCodePoint(Number.parseInt(n.slice(2),16)):n.startsWith("#")?String.fromCodePoint(Number.parseInt(n.slice(1),10)):b[n]??e):r}const d=r=>{const e=r.indexOf(":");return e<0?r:r.slice(e+1)},p=r=>r===32||r===9||r===10||r===13;function x(r,e,n){let i=0;const t=r.length;for(;i<t&&!p(r.charCodeAt(i));)i++;const f=d(r.slice(0,i)),o={};for(;i<t;){for(;i<t&&p(r.charCodeAt(i));)i++;if(i>=t)break;const h=r.indexOf("=",i);if(h<0)throw new Error(`An attribute of <${f}> has no value.`);const u=r.slice(i,h).trim();let l=h+1;for(;l<t&&p(r.charCodeAt(l));)l++;const a=r[l];if(a!=='"'&&a!=="'")throw new Error(`An attribute of <${f}> is not quoted.`);const s=r.indexOf(a,l+1);if(s<0)throw new Error(`An attribute of <${f}> is not closed.`);u!=="xmlns"&&!u.startsWith("xmlns:")&&(o[d(u)]=unescapeXml(r.slice(l+1,s))),i=s+1}return e.open(f,o,n),f}export class XmlStream{capture;buffer="";handler;depth=0;cr=!1;constructor(e){this.handler=e}push(e){let n=this.cr?`\r${e}`:e;this.cr=n.endsWith("\r"),this.cr&&(n=n.slice(0,-1)),n=n.replace(/\r\n?/gu,`
|
|
3
|
+
`),this.buffer=this.buffer===""?n:this.buffer+n,this.run()}end(){if(this.cr&&(this.cr=!1,this.buffer+=`
|
|
4
|
+
`),this.run(),this.buffer.trim()!=="")throw new Error("The XML ends inside a tag or a comment.");if(this.depth>0)throw new Error("The XML ends before its elements do.")}emitText(e){e!==""&&(this.capture?.push(e),this.handler.text(unescapeXml(e)))}run(){const e=this.buffer,n=e.length;let i=0;for(;;){const t=e.indexOf("<",i);if(t<0){const s=e.lastIndexOf("&"),c=s>=i&&!e.includes(";",s)?s:n;this.emitText(e.slice(i,c)),i=c;break}t>i&&this.emitText(e.slice(i,t)),i=t;const f=e.charCodeAt(t+1);if(Number.isNaN(f))break;if(f===33){if(e.startsWith("<!--",t)){const c=e.indexOf("-->",t+4);if(c<0)break;this.capture?.push(e.slice(t,c+3)),i=c+3;continue}if(e.startsWith("<![CDATA[",t)){const c=e.indexOf("]]>",t+9);if(c<0)break;this.capture?.push(e.slice(t,c+3)),this.handler.text(e.slice(t+9,c)),i=c+3;continue}if(n-t<9)break;const s=e.indexOf(">",t);if(s<0)break;if(e.lastIndexOf("[",s)>t){const c=e.indexOf("]>",t);if(c<0)break;i=c+2}else i=s+1;continue}if(f===63){const s=e.indexOf("?>",t+2);if(s<0)break;this.capture?.push(e.slice(t,s+2)),i=s+2;continue}if(f===47){const s=e.indexOf(">",t+2);if(s<0)break;this.capture?.push(e.slice(t,s+1)),this.depth-=1,this.handler.close(d(e.slice(t+2,s).trim())),i=s+1;continue}let o=t+1,h=0;for(;o<n;o++){const s=e.charCodeAt(o);if(h!==0)s===h&&(h=0);else if(s===34||s===39)h=s;else if(s===62)break}if(o>=n)break;const u=e.charCodeAt(o-1)===47,l=e.slice(t,o+1),a=x(e.slice(t+1,u?o-1:o),this.handler,u);this.capture?.push(l),u?this.handler.close(a):this.depth+=1,i=o+1}this.buffer=i>=n?"":e.slice(i)}}
|
|
@@ -4,6 +4,12 @@ export declare const DEFAULT_FONT: {
|
|
|
4
4
|
readonly name: "Calibri";
|
|
5
5
|
readonly size: 11;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* A font's name as Excel takes one: 31 characters at most, past which it
|
|
9
|
+
* repairs the file. LibreOffice's list of faces ("Liberation Serif;Times
|
|
10
|
+
* New Roman") is its first face.
|
|
11
|
+
*/
|
|
12
|
+
export declare function fontName(name: string): string;
|
|
7
13
|
export declare class Styles {
|
|
8
14
|
private readonly fonts;
|
|
9
15
|
private readonly fills;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{FIRST_CUSTOM as g,builtinId as
|
|
2
|
+
import{FIRST_CUSTOM as g,builtinId as x}from"./numfmt.js";import{NS as y,el as e}from"./xml.js";export const DEFAULT_FONT={name:"Calibri",size:11};export function fontName(t){if(t.length<=31)return t;const n=t.split(/[;,]/u)[0]?.trim()??"";return(n===""?t:n).slice(0,31)}const s=t=>`FF${t.slice(1).toUpperCase()}`;class f{items=[];index=new Map;add(n){const i=this.index.get(n);if(i!==void 0)return i;const r=this.items.length;return this.items.push(n),this.index.set(n,r),r}}function b(t){const{underline:n}=t;return e("font",{},t.bold===!0?"<b/>":"",t.italic===!0?"<i/>":"",t.strike===!0?"<strike/>":"",n===!0||n==="single"?"<u/>":n?e("u",{val:n}):"",e("sz",{val:t.size??DEFAULT_FONT.size}),t.color===void 0?e("color",{theme:1}):e("color",{rgb:s(t.color)}),e("name",{val:fontName(t.font??DEFAULT_FONT.name)}),e("family",{val:2}),t.font===void 0?e("scheme",{val:"minor"}):"")}function F(t){const{pattern:n,color:i,background:r}=typeof t=="string"?{pattern:"solid",color:t,background:void 0}:t;return e("fill",{},e("patternFill",{patternType:n},i===void 0?"":e("fgColor",{rgb:s(i)}),r===void 0?n==="solid"?e("bgColor",{indexed:64}):"":e("bgColor",{rgb:s(r)})))}function o(t,n){return n?e(t,{style:n.style},n.color===void 0?e("color",{auto:1}):e("color",{rgb:s(n.color)})):e(t)}function h(t){return e("border",{},o("left",t.left),o("right",t.right),o("top",t.top),o("bottom",t.bottom),e("diagonal"))}function p(t,n="dxf"){const{underline:i}=t,r=[t.bold===void 0?"":e("b",{val:t.bold}),t.italic===void 0?"":e("i",{val:t.italic}),t.strike===void 0?"":e("strike",{val:t.strike}),i===!0?"<u/>":"",t.color===void 0?"":e("color",{rgb:s(t.color)})].join(""),{fill:d,border:l}=t;return e(n,{},r===""?"":e("font",{},r),typeof d=="string"?e("fill",{},e("patternFill",{},e("bgColor",{rgb:s(d)}))):"",l?h(l):"")}const I=t=>t<0?90-t:t;function v(t){const n={horizontal:t.align,vertical:t.valign,textRotation:t.rotation===void 0?void 0:I(t.rotation),wrapText:t.wrap===!0?!0:void 0,indent:t.indent,shrinkToFit:t.shrink===!0?!0:void 0};return Object.values(n).every(i=>i===void 0)?"":e("alignment",n)}export class Styles{fonts=new f;fills=new f;borders=new f;formats=new Map;xfs=new f;byLook=new Map;dxfs=new f;constructor(){this.fonts.add(b({})),this.fills.add(e("fill",{},e("patternFill",{patternType:"none"}))),this.fills.add(e("fill",{},e("patternFill",{patternType:"gray125"}))),this.borders.add(e("border",{},e("left"),e("right"),e("top"),e("bottom"),e("diagonal"))),this.xfs.add(e("xf",{numFmtId:0,fontId:0,fillId:0,borderId:0,xfId:0}))}format(n){if(n===void 0)return 0;const i=x(n);if(i!==void 0)return i;let r=this.formats.get(n);return r===void 0&&(r=g+this.formats.size,this.formats.set(n,r)),r}xf(n){const i=JSON.stringify(n),r=this.byLook.get(i);if(r!==void 0)return r;const d=this.format(n.format),l=this.fonts.add(b(n)),u=n.fill===void 0?0:this.fills.add(F(n.fill)),a=n.border===void 0?0:this.borders.add(h(n.border)),c=v(n),m=this.xfs.add(e("xf",{numFmtId:d,fontId:l,fillId:u,borderId:a,xfId:0,applyNumberFormat:d===0?void 0:!0,applyFont:l===0?void 0:!0,applyFill:u===0?void 0:!0,applyBorder:a===0?void 0:!0,applyAlignment:c===""?void 0:!0},c));return this.byLook.set(i,m),m}dxf(n){return this.dxfs.add(p(n))}dxfXml(n,i){return p(n,i)}xml(){const n=(r,d)=>e(r,{count:d.length},d.join("")),i=[...this.formats].map(([r,d])=>e("numFmt",{numFmtId:d,formatCode:r}));return e("styleSheet",{xmlns:y.main},i.length>0?n("numFmts",i):"",n("fonts",this.fonts.items),n("fills",this.fills.items),n("borders",this.borders.items),n("cellStyleXfs",[e("xf",{numFmtId:0,fontId:0,fillId:0,borderId:0})]),n("cellXfs",this.xfs.items),n("cellStyles",[e("cellStyle",{name:"Normal",xfId:0,builtinId:0})]),this.dxfs.items.length===0?e("dxfs",{count:0}):n("dxfs",this.dxfs.items),e("tableStyles",{count:0,defaultTableStyle:"TableStyleMedium2",defaultPivotStyle:"PivotStyleLight16"}))}}
|
|
@@ -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 pe,SHEET_NOTE_AUTHOR as K,SHEET_PAPERS as we}from"@allyhub/formats";import{MAX_COLUMNS as Q,MAX_ROWS as ee,cellName as _,columnIndex as xe,columnLetter as D,rangeName as M,readAddress as te,readArea as ge}from"../address.js";import{parseFormula as $e}from"../formula/parse.js";import{sheetPrefix as X}from"../formula/print.js";import{walk as ye}from"../formula/walk.js";import{fileCells as be,isPicture as ve,pictureHeight as Se,pictureSize as se}from"../files.js";import{scenariosByCell as ke}from"../scenario.js";import{CellError as P,readTyped as Ae}from"../values.js";import{FormulaCell as Ce}from"../workbook.js";import{chartPart as Ee,drawingPart as Te}from"./charts.js";import{fileFormula as N,needsArray as B}from"./formula.js";import{GRID_END as W}from"./read.js";import{Styles as Me}from"./styles.js";import{THEME_XML as Re}from"./theme.js";import{HEAD as S,NS as k,el as o,xstring as x}from"./xml.js";import{ZipOut as _e}from"./zip.js";const A={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"},v=`${k.rel}/`,ne="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",oe="http://schemas.microsoft.com/office/excel/2006/main",re={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},je=191029;export const DEFAULT_TABLE_STYLE="TableStyleMedium2",LISTS_SHEET="AllyHub lists";const Le=64,Oe=7,Fe=a=>Math.min(255,Math.floor(a/Oe*256)/256),Ie=a=>Math.min(409.5,a*3/4),q=32767,De=255,Pe=2e5,Ne=o("metadata",{xmlns:k.main,"xmlns:xda":"http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray"},o("metadataTypes",{count:1},o("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})),o("futureMetadata",{name:"XLDAPR",count:1},o("bk",{},o("extLst",{},o("ext",{uri:"{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}"},o("xda:dynamicArrayProperties",{fDynamic:1,fCollapsed:0}))))),o("cellMetadata",{count:1},o("bk",{},o("rc",{t:1,v:0}))));class Ve{index=new Map;count=0;of(t){this.count+=1;let s=this.index.get(t);return s===void 0&&(s=this.index.size,this.index.set(t,s)),s}write(t){t.write(`${S}<sst xmlns="${k.main}" count="${String(this.count)}" uniqueCount="${String(this.index.size)}">`);for(const s of this.index.keys()){const e=/^\s|\s$|\n/u.test(s);t.write(`<si><t${e?' xml:space="preserve"':""}>${x(s)}</t></si>`)}t.write("</sst>"),t.end()}}function ze(a){for(const t in a)if(Object.hasOwn(a,t))return!1;return!0}const He=a=>o("x",a).slice(2,-2),Ue="Base case";function Xe(a){const t=new Map;for(const n of a.scenarios)for(const r of n.cells)t.set(_(r),r);const s=(n,r)=>o("inputCells",{r:_(n),val:r===null||r instanceof P?"":typeof r=="boolean"?r?"1":"0":String(r)}),e=(n,r)=>o("scenario",{name:n,locked:!0,count:r.length,user:"AllyHub"},r.join(""));return o("scenarios",{current:0,show:0,sqref:[...t.keys()].join(" ")},e(Ue,[...t.values()].map(n=>s(n,n.base))),...a.scenarios.map(n=>e(n.name,n.cells.map(r=>s(r,r.value)))))}function Be(a,t,s,e){const n=[];let r=0;for(const{row:l,col:h,paths:c,column:i}of be(a,t)){let d=0;const f=Se(i);for(const m of c){const u=ve(m)?s?.(m):void 0,$=u&&se(u);if(!u||!$){r+=1;continue}const T=Math.round($.width/$.height*f);n.push({row:l,col:h,x:d,width:T,height:f,name:m.split("/").pop()??m,path:m,file:`.${$.type==="jpeg"?"jpg":$.type}`,bytes:u}),d+=T+4}}for(const l of a.spec.pictures??[]){const h=te(l.at),c=s?.(l.file),i=c&&se(c);if(!h||!c||!i)continue;const d=i.width/i.height,f=l.width??(l.height===void 0?i.width:l.height*d);n.push({row:h.row,col:h.col,x:l.x??0,y:l.y??0,width:Math.round(f),height:Math.round(l.height??f/d),name:l.file.split("/").pop()??l.file,path:l.file,file:`.${i.type==="jpeg"?"jpg":i.type}`,bytes:c})}return r>0&&e.push(`${a.name}: ${String(r)} file${r===1?"":"s"} in a cell, which stay${r===1?"s":""} a name`),n}class We{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=D(e);return`${X(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 r=`<row r="${String(n+1)}">`;this.columns.forEach((l,h)=>{const c=l[n];c!==void 0&&(r+=`<c r="${_({row:n,col:h})}" t="s"><v>${String(t.of(c))}</v></c>`)}),s.push(`${r}</row>`)}return`${S}<worksheet xmlns="${k.main}" xmlns:r="${k.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 qe{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,r=-1;for(let i=0;i<t;i++){const d=this.rows[i]??0,f=this.cols[i]??0;d<s&&(s=d),d>e&&(e=d),f<n&&(n=f),f>r&&(r=f)}const l=new Uint32Array(e-s+2);for(let i=0;i<t;i++){const d=(this.rows[i]??0)-s+1;l[d]=(l[d]??0)+1}for(let i=1;i<l.length;i++)l[i]=(l[i]??0)+(l[i-1]??0);const h=l.slice(0,-1),c=new Int32Array(t);for(let i=0;i<t;i++){const d=(this.rows[i]??0)-s,f=h[d]??0;c[f]=this.cols[i]??0,h[d]=f+1}return{start:l,cols:c,top:s,used:{top:s,bottom:e,left:n,right:r}}}}function Ge(a,t){if(!a)return!1;let s=!1;const e=t.toLowerCase();return ye(a,n=>{(n.kind==="ref"||n.kind==="name")&&n.sheet!==void 0&&n.sheet.toLowerCase()!==e&&(s=!0)}),s}const Ye=(a,t)=>`{00000000-0000-4000-8000-${(a*65536+t).toString(16).toUpperCase().padStart(12,"0")}}`;class Ze{arrays=!1;sheet;calc;styles;strings;wb;cached;left;lists;index;isTable;isRangeName;hiddenRows;tall;scenarios;drawn;newerRules=[];newerValidations=[];shapes=new Map;groups=new Map;constructor(t,s,e,n,r,l,h,c,i=[],d){this.sheet=t,this.calc=s,this.wb=s.wb,this.styles=e,this.strings=n,this.cached=r,this.left=l,this.lists=h,this.index=c,this.isTable=m=>this.wb.table(m)!==void 0,this.isRangeName=m=>{const u=this.wb.name(m,t)?.formula?.node;return this.isTable(m)||u!==void 0&&B({kind:"unary",op:"-",arg:u})},this.hiddenRows=s.filtered(t),this.scenarios=d,this.drawn=t.charts.length>0||i.length>0;const f=new Map;for(const m of i)m.y===void 0&&f.set(m.row,Math.max(f.get(m.row)??0,m.height));this.tall=f}grid(){const{sheet:t}=this;if(t.lastRow>=ee)throw new Error(`${t.name} reaches row ${(t.lastRow+1).toLocaleString("en-US")}, and ${W}: an Excel file cannot hold it.`);if(t.columnsUsed>Q)throw new Error(`${t.name} reaches past column ${D(Q-1)}, and ${W}: an Excel file cannot hold it.`);for(const s of Object.keys(t.spec.rows??{}))if(Number(s)>ee)throw new Error(`${t.name} sets row ${s}, and ${W}: an Excel file cannot hold it.`)}gather(){const{sheet:t}=this,s=new qe;for(let e=0;e<t.columnsUsed;e++){const[n,r]=t.span(e,0,Number.MAX_SAFE_INTEGER);for(let l=n;l<=r;l++)(t.at(l,e)!==void 0||t.spillAt(l,e))&&s.add(l,e)}for(const{area:e}of t.styledAreas()){const n=(e.bottom-e.top+1)*(e.right-e.left+1);if(n>Pe){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 r=e.top;r<=e.bottom;r++)for(let l=e.left;l<=e.right;l++)s.add(r,l)}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 ze(e)?void 0:this.styles.xf(e)}held(t,s){return s.length<=q?s:(this.left.push(`${this.sheet.name}!${t} past Excel's ${String(q)} characters, of its ${String(s.length)}`),s.slice(0,q))}value(t,s,e){return e===null?`<c r="${t}"${C(s)}/>`:typeof e=="number"?`<c r="${t}"${C(s)}><v>${String(e)}</v></c>`:typeof e=="boolean"?`<c r="${t}"${C(s)} t="b"><v>${e?"1":"0"}</v></c>`:e instanceof P?ce(e)?`<c r="${t}"${C(s)} t="e"><v>${e.code}</v></c>`:`<c r="${t}"${C(s)} t="s"><v>${String(this.strings.of(e.code))}</v></c>`:`<c r="${t}"${C(s)} t="s"><v>${String(this.strings.of(this.held(t,e)))}</v></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:r}=e,{node:l}=r;if(!l)return`<c r="${t}"${C(s)} t="e"><v>#NAME?</v></c>`;let h=this.shapes.get(r);h===void 0&&(h=B(l,this.isRangeName),this.shapes.set(r,h));const c=e.array!==void 0||e.blocked!==void 0||h;let i=c?void 0:this.groups.get(r);i?.written===!1&&(e.row!==i.ref.top||e.col!==i.ref.left)&&(i=void 0);let d,f="";if(i?.written===!0)d=`<f t="shared" si="${String(i.si)}"/>`;else{const m=N(e.moved,{table:this.table(e),isTable:this.isTable,array:c});d=i?`<f t="shared" ref="${M(i.ref)}" si="${String(i.si)}">${x(m)}</f>`:`<f>${x(m)}</f>`,i&&(i.written=!0),c&&(d=this.arrayFormula(e,m))}return c&&(this.arrays=!0,f=' cm="1"'),this.cached?n===null||typeof n=="number"?`<c r="${t}"${C(s)}${f}>${d}<v>${String(n??0)}</v></c>`:typeof n=="boolean"?`<c r="${t}"${C(s)} t="b"${f}>${d}<v>${n?"1":"0"}</v></c>`:n instanceof P?ce(n)?`<c r="${t}"${C(s)} t="e"${f}>${d}<v>${n.code}</v></c>`:`<c r="${t}"${C(s)}${f}>${d}<v>0</v></c>`:`<c r="${t}"${C(s)} t="str"${f}>${d}<v>${x(this.held(t,n))}</v></c>`:`<c r="${t}"${C(s)}${f}>${d}</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)}">${x(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:r}=n;e.row<r.top&&(r.top=e.row),e.row>r.bottom&&(r.bottom=e.row),e.col<r.left&&(r.left=e.col),e.col>r.right&&(r.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:r,n:l}]of t)l>1&&r.row===n.top&&r.col===n.left&&(this.groups.set(e,{si:s,ref:n,written:!1}),s+=1)}cell(t,s){const e=_({row:t,col:s}),n=this.styleOf(t,s),r=this.sheet.at(t,s);return r instanceof Ce?this.formula(e,n,r):r===void 0&&this.cached&&this.sheet.spillAt(t,s)?this.value(e,n,this.calc.value(this.sheet,t,s)):this.value(e,n,r??null)}columns(){const{sheet:t}=this,{spec:s}=t,e=new Map,n=new Map;for(const c of t.tables)for(const i of c.columns)i.spec?.width!==void 0&&n.set(c.at.col+i.index,i.spec.width);const r=new Set(n.keys()),l=new Map;for(const[c,i]of Object.entries(s.columns??{})){const d=xe(c);d!==void 0&&(l.set(d,i),r.add(d))}for(const c of r){const i=l.get(c),d=i?.width??n.get(c),f=de(i);e.set(c,o("col",{min:c+1,max:c+1,width:Fe(d??Le),style:f===void 0?void 0:this.styles.xf(f),hidden:i?.hidden===!0?!0:void 0,customWidth:d===void 0?void 0:!0,outlineLevel:i?.level}))}const h=[...e.keys()].sort((c,i)=>c-i).map(c=>e.get(c)??"");return h.length===0?"":`<cols>${h.join("")}</cols>`}rowAttrs(t){const s=this.sheet.spec.rows?.[String(t+1)],e=de(s),n=s?.height??this.tall.get(t);return He({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:Ie(n),customHeight:n===void 0?void 0:!0,hidden:s?.hidden===!0||this.hiddenRows.has(t)?!0:void 0,outlineLevel:s?.level})}rows(t,s){const{sheet:e}=this,n=new Set(this.hiddenRows);for(const d of Object.keys(e.spec.rows??{}))n.add(Number(d)-1);const{start:r,cols:l,top:h}=s;let c=s.used?h:1/0,i=s.used?s.used.bottom:-1;for(const d of n)d<c&&(c=d),d>i&&(i=d);for(let d=Math.max(0,c);d<=i;d++){const f=d-h,m=f>=0&&f<r.length-1?r[f]??0:0,u=f>=0&&f<r.length-1?r[f+1]??0:0;if(m===u&&!n.has(d))continue;if(m===u){t.write(`<row${this.rowAttrs(d)}/>`);continue}const $=l.subarray(m,u).sort();let T=`<row${this.rowAttrs(d)}>`,y=-1;for(const b of $)b!==y&&(y=b,T+=this.cell(d,b));t.write(`${T}</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=o("pane",{xSplit:s.col>0?s.col:void 0,ySplit:s.row>0?s.row:void 0,topLeftCell:_(s),activePane:n,state:"frozen"})}return o("sheetViews",{},o("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 r=this.gather();this.shareFormulas();const l=n.tables.map((y,b)=>o("tablePart",{"r:id":`rId${String(b+1)}`})),{print:h}=n.spec,c=h?.fit,i=Object.keys(n.spec.notes??{}).length>0;t.write(`${S}<worksheet xmlns="${k.main}" xmlns:r="${k.rel}">`+(n.spec.tab===void 0&&c===void 0?"":o("sheetPr",{},n.spec.tab===void 0?"":o("tabColor",{rgb:`FF${n.spec.tab.slice(1).toUpperCase()}`}),c===void 0?"":o("pageSetUpPr",{fitToPage:!0})))+o("dimension",{ref:r.used?M(r.used):"A1"})+this.view(s)+o("sheetFormatPr",{defaultRowHeight:15,outlineLevelRow:ie(n.spec.rows),outlineLevelCol:ie(n.spec.columns)})+this.columns()+"<sheetData>"),this.rows(t,r);const d=l.length+1+(this.drawn?1:0)+(i?2:0);let f=0;const m=Object.entries(n.spec.links??{}).map(([y,b])=>b.startsWith("#")?o("hyperlink",{ref:y,location:b.slice(1)}):o("hyperlink",{ref:y,"r:id":`rId${String(d+f++)}`})),u=n.merges.map(y=>o("mergeCell",{ref:M(y)})),$=n.conditions.map((y,b)=>this.condition(y,b+1)).join(""),T=this.validations();return t.write("</sheetData>"+(n.spec.protect===!0?o("sheetProtection",{sheet:!0,objects:!0,scenarios:!0}):"")+(this.scenarios?Xe(this.scenarios):"")+this.sheetFilter()+(u.length>0?o("mergeCells",{count:u.length},u.join("")):"")+$+T+(m.length>0?o("hyperlinks",{},m.join("")):"")+o("pageMargins",{...pe,...h?.margins})+(h?.orientation!==void 0||h?.paper!==void 0||c!==void 0?o("pageSetup",{paperSize:h?.paper===void 0?void 0:we[h.paper],fitToWidth:c?.width,fitToHeight:c?.height,orientation:h?.orientation}):"")+(h?.header||h?.footer?o("headerFooter",{},h.header?o("oddHeader",{},x(ae(h.header))):"",h.footer?o("oddFooter",{},x(ae(h.footer))):""):"")+(this.drawn?o("drawing",{"r:id":`rId${String(l.length+1)}`}):"")+(i?o("legacyDrawing",{"r:id":`rId${String(l.length+(this.drawn?2:1))}`}):"")+(l.length>0?o("tableParts",{count:l.length},l.join("")):"")+this.extensions()+"</worksheet>"),t.end(),n.tables.map((y,b)=>this.tableXml(y,e+b))}extensions(){const t=[];return this.newerRules.length>0&&t.push(o("ext",{uri:re.conditional,"xmlns:x14":ne},o("x14:conditionalFormattings",{},this.newerRules.join("")))),this.newerValidations.length>0&&t.push(o("ext",{uri:re.validations,"xmlns:x14":ne},o("x14:dataValidations",{count:this.newerValidations.length,"xmlns:xm":oe},this.newerValidations.join("")))),t.length===0?"":o("extLst",{},t.join(""))}bound(t){if(t===void 0)return"";if(typeof t=="number")return String(t);if(!t.startsWith("=")){const e=Ae(t);return typeof e.value=="number"&&e.formula===void 0?String(e.value):`"${t.replaceAll('"','""')}"`}const s=$e(t);return s.ok?N(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?o("x14:cfvo",{type:t.at},e===void 0?"":o("xm:f",{},x(e))):o("cfvo",{type:t.at,val:e})}crosses(t){return t.some(s=>Ge(s?.node,this.sheet.name))}condition(t,s){const{spec:e}=t,n=e.range,r=e.type!=="dataBar"&&this.crosses(t.formulas),l=(f,m,...u)=>{if(!r){const $=Object.keys(m).length===0?void 0:this.styles.dxf(m);return o("conditionalFormatting",{sqref:n},o("cfRule",{...f,dxfId:$,priority:s,stopIfTrue:e.stop===!0?!0:void 0},...u))}return this.newerRules.push(o("x14:conditionalFormatting",{"xmlns:xm":oe},o("x14:cfRule",{...f,priority:s,stopIfTrue:e.stop===!0?!0:void 0,id:Ye(this.index,s)},...u.map($=>$.replace(/^<formula>(.*)<\/formula>$/su,"<xm:f>$1</xm:f>")),Object.keys(m).length===0?"":this.styles.dxfXml(m,"x14:dxf")),o("xm:sqref",{},n))),""},h=et(e),c=t.areas[0],i=c?_({row:c.top,col:c.left}):"A1",d=f=>o("formula",{},x(f));switch(e.type){case"cellIs":return l({type:"cellIs",operator:e.operator},h,...e.formula.map(f=>d(this.bound(f))));case"containsText":{const f=e.operator??"contains",m=`"${e.text.replaceAll('"','""')}"`,u=f==="contains"?`NOT(ISERROR(SEARCH(${m},${i})))`:f==="notContains"?`ISERROR(SEARCH(${m},${i}))`:f==="beginsWith"?`LEFT(${i},LEN(${m}))=${m}`:`RIGHT(${i},LEN(${m}))=${m}`;return l({type:f==="contains"?"containsText":f==="notContains"?"notContainsText":f,operator:f==="contains"?"containsText":f,text:e.text},h,d(u))}case"duplicateValues":case"uniqueValues":return l({type:e.type},h);case"top10":return l({type:"top10",percent:e.percent===!0?!0:void 0,bottom:e.bottom===!0?!0:void 0,rank:e.rank},h);case"aboveAverage":return l({type:"aboveAverage",aboveAverage:e.below===!0?!1:void 0,equalAverage:e.equal===!0?!0:void 0},h);case"expression":return l({type:"expression"},h,d(this.bound(e.formula.startsWith("=")?e.formula:`=${e.formula}`)));case"dataBar":return l({type:"dataBar"},{},o("dataBar",{showValue:e.show===!1?!1:void 0},this.cfvo(e.min??{at:"min"},!1),this.cfvo(e.max??{at:"max"},!1),o("color",{rgb:le(e.color)})));case"colorScale":{const f=r?"x14:":"";return l({type:"colorScale"},{},o(`${f}colorScale`,{},...e.stops.map(m=>this.cfvo(m,r)),...e.stops.map(m=>o(`${f}color`,{rgb:le(m.color)}))))}case"iconSet":{const f=Number.parseInt(e.icons,10),m=e.stops??Array.from({length:f},(u,$)=>({at:"percent",value:Math.round($*100/f)}));return l({type:"iconSet"},{},o(r?"x14:iconSet":"iconSet",{iconSet:e.icons,showValue:e.show===!1?!1:void 0,reverse:e.reverse===!0?!0:void 0},...m.map(u=>this.cfvo(u,r))))}}}validation(t){const{spec:s}=t;let e="",n=this.crosses(t.formulas);if(s.values){const i=s.values.join(",");i.length>De||s.values.some(d=>d.includes(",")||d.includes('"'))?(e=this.lists.place(s.values),n=!0):e=`"${i}"`}else e=this.bound(s.formula?.[0]);const r=this.bound(s.formula?.[1]),{error:l,prompt:h}=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 c={type:s.type,errorStyle:l?.style===void 0||l.style==="stop"?void 0:l.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:h?.show===!1?void 0:!0,showErrorMessage:l?.show===!1||s.multiple===!0?void 0:!0,errorTitle:l?.title,error:l?.message,promptTitle:h?.title,prompt:h?.message};return n?(this.newerValidations.push(o("x14:dataValidation",c,e===""?"":o("x14:formula1",{},o("xm:f",{},x(e))),r===""?"":o("x14:formula2",{},o("xm:f",{},x(r))),o("xm:sqref",{},s.range))),""):o("dataValidation",{...c,sqref:s.range},e===""?"":o("formula1",{},x(e)),r===""?"":o("formula2",{},x(r)))}validations(){const t=this.sheet.validations.map(s=>this.validation(s)).filter(s=>s!=="");return t.length===0?"":o("dataValidations",{count:t.length},t.join(""))}filterColumns(t){return[...t.columns.entries()].sort(([s],[e])=>s-e).map(([s,e])=>tt(s-t.area.left,e))}sheetFilter(){const t=this.sheet.filters.find(s=>!s.table);return t?o("autoFilter",{ref:M(t.area)},...this.filterColumns(t)):""}columnFormula(t,s){if(!s?.node)return"";const e=B(s.node,this.isRangeName),n=N(s.node,{table:t.name,isTable:this.isTable,array:e});return o("calculatedColumnFormula",{array:e?!0:void 0},x(n))}tableXml(t,s){const e=t.area,n=M({...e,bottom:Math.max(e.bottom,e.top+1)}),r=t.spec.style??DEFAULT_TABLE_STYLE,l=this.sheet.filters.find(h=>h.table===t);return S+o("table",{xmlns:k.main,id:s,name:t.name,displayName:t.name,ref:n,totalsRowShown:0},l?o("autoFilter",{ref:n},...this.filterColumns(l)):"",o("tableColumns",{count:t.columns.length},t.columns.map((h,c)=>o("tableColumn",{id:c+1,name:h.name},this.columnFormula(t,h.formula))).join("")),r==="none"?o("tableStyleInfo",{showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}):o("tableStyleInfo",{name:r,showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}))}}const ie=a=>{let t;for(const s of Object.values(a??{}))s.level!==void 0&&(t=Math.max(t??0,s.level));return t},ae=a=>[a.left===void 0?"":`&L${a.left}`,a.center===void 0?"":`&C${a.center}`,a.right===void 0?"":`&R${a.right}`].join(""),Je=a=>typeof a=="string"?{text:a,author:K}:{text:a.text,author:a.author??K};function Ke(a){const t=a.map(([e,n])=>({ref:e,...Je(n)})),s=[...new Set(t.map(e=>e.author))];return S+o("comments",{xmlns:k.main},o("authors",{},s.map(e=>o("author",{},x(e))).join("")),o("commentList",{},t.map(e=>o("comment",{ref:e.ref,authorId:s.indexOf(e.author)},o("text",{},o("r",{},o("t",/^\s|\s$|\n/u.test(e.text)?{"xml:space":"preserve"}:{},x(e.text)))))).join("")))}function Qe(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=te(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 le=a=>`FF${a.slice(1).toUpperCase()}`;function et(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"])a[s]!==void 0&&(t[s]=a[s]);return t}function tt(a,t){return o("filterColumn",{colId:a},o("filters",{blank:t.blanks===!0?!0:void 0},(t.values??[]).map(s=>o("filter",{val:s})).join("")))}const C=a=>a===void 0?"":` s="${String(a)}"`,ce=a=>a.code!=="#CYCLE!",st=new Set(["width","height","hidden"]);function de(a){if(!a)return;const t=Object.fromEntries(Object.entries(a).filter(([s])=>!st.has(s)));return Object.keys(t).length===0?void 0:t}const V=a=>S+o("Relationships",{xmlns:k.pkg},a.map(([t,s,e],n)=>o("Relationship",{Id:`rId${String(n+1)}`,Type:t,Target:s,TargetMode:e})).join(""));function nt(a,t){const s=t.formula?.node;if(s)return N(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 ot=(a,t)=>a.length===t.length&&a.every((s,e)=>s===t[e]),he=a=>`$${D(a.left)}$${String(a.top+1)}:$${D(a.right)}$${String(a.bottom+1)}`;function rt(a){const t=[],s=(e,n)=>o("definedName",{name:e.name,localSheetId:n,hidden:e.hidden===!0?!0:void 0},x(nt(a,e)));for(const e of a.names.values())t.push(s(e));return a.sheets.forEach((e,n)=>{for(const d of e.names.values())t.push(s(d,n));const r=e.filters.find(d=>!d.table);r&&t.push(o("definedName",{name:"_xlnm._FilterDatabase",localSheetId:n,hidden:!0},x(`${X(e.name)}${he(r.area)}`)));const l=X(e.name),h=e.spec.print,c=h?.area===void 0?void 0:ge(h.area);c&&t.push(o("definedName",{name:"_xlnm.Print_Area",localSheetId:n},x(`${l}${he(c)}`)));const i=[h?.title_cols?.toUpperCase().replace(/([A-Z]+):([A-Z]+)/u,"$$$1:$$$2"),h?.title_rows?.replace(/(\d+):(\d+)/u,"$$$1:$$$2")].flatMap(d=>d===void 0?[]:[`${l}${d}`]);i.length>0&&t.push(o("definedName",{name:"_xlnm.Print_Titles",localSheetId:n},x(i.join(","))))}),t}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=ke(a);e.push(...n.left);const r=new Me,l=new Ve,h=new We(s),c=new _e,i=[["/xl/workbook.xml",A.sheet]],d=Math.max(0,s.sheets.findIndex(p=>p.spec.hidden!==!0));let f=1,m=!1;const u=new Map;let $=0,T=0,y=0;for(const[p,w]of s.sheets.entries()){const H=String(p+1),O=Be(w,a,t.file,e),F=w.charts.filter(({spec:g})=>[g.categories,...g.series.flatMap(E=>[E.values,E.x])].some(E=>E?.endsWith("#"))).length;F>0&&e.push(`${w.name}: ${String(F)} chart${F===1?"":"s"} on a spill: ${F===1?"it reads":"they read"} the cells the spill covers now, and will not grow with it`);const Z=new Ze(w,a,r,l,t.cached!==!1,e,h,p,O,n.sheets.find(g=>g.sheet===w)),me=Z.write(c.part(`xl/worksheets/sheet${H}.xml`),p===d,f);m||=Z.arrays,i.push([`/xl/worksheets/sheet${H}.xml`,A.worksheet]);const R=[];for(const g of me){const E=`table${String(f)}.xml`;f+=1,c.add(`xl/tables/${E}`,g),i.push([`/xl/tables/${E}`,A.table]),R.push([`${v}table`,`../tables/${E}`])}if(w.charts.length>0||O.length>0){$+=1;const g=`drawing${String($)}.xml`;c.add(`xl/drawings/${g}`,Te(w.charts,O)),i.push([`/xl/drawings/${g}`,A.drawing]),R.push([`${v}drawing`,`../drawings/${g}`]);const E=w.charts.map(L=>{T+=1;const I=`chart${String(T)}.xml`;return c.add(`xl/charts/${I}`,Ee(a,w,L)),i.push([`/xl/charts/${I}`,A.chart]),[`${v}chart`,`../charts/${I}`]});for(const L of O){const J=[...u].find(([,ue])=>ot(ue,L.bytes))?.[0]??`image${String(u.size+1)}${L.file}`;u.set(J,L.bytes),E.push([`${v}image`,`../media/${J}`])}c.add(`xl/drawings/_rels/${g}.rels`,V(E))}const U=Object.entries(w.spec.notes??{});if(U.length>0){y+=1;const g=String(y);c.add(`xl/comments${g}.xml`,Ke(U)),i.push([`/xl/comments${g}.xml`,A.comments]),c.add(`xl/drawings/vmlDrawing${g}.vml`,Qe(U)),R.push([`${v}vmlDrawing`,`../drawings/vmlDrawing${g}.vml`]),R.push([`${v}comments`,`../comments${g}.xml`])}for(const g of Object.values(w.spec.links??{}))g.startsWith("#")||R.push([`${v}hyperlink`,g,"External"]);R.length>0&&c.add(`xl/worksheets/_rels/sheet${H}.xml.rels`,V(R))}const b=s.sheets.length,z=h.columns.length>0;if(z){const p=`xl/worksheets/sheet${String(b+1)}.xml`;c.add(p,h.xml(l)),i.push([`/${p}`,A.worksheet])}const j=[...s.sheets,...z?[void 0]:[]].map((p,w)=>[`${v}worksheet`,`worksheets/sheet${String(w+1)}.xml`]);j.push([`${v}theme`,"theme/theme1.xml"]),j.push([`${v}styles`,"styles.xml"]),j.push([`${v}sharedStrings`,"sharedStrings.xml"]),m&&(j.push([`${v}sheetMetadata`,"metadata.xml"]),i.push(["/xl/metadata.xml",A.metadata]));const G=rt(s),Y=s.sheets.map((p,w)=>o("sheet",{name:p.name,sheetId:w+1,state:p.spec.hidden===!0?"hidden":void 0,"r:id":`rId${String(w+1)}`}));z&&Y.push(o("sheet",{name:h.name,sheetId:b+1,state:"veryHidden","r:id":`rId${String(b+1)}`})),c.add("xl/workbook.xml",S+o("workbook",{xmlns:k.main,"xmlns:r":k.rel},o("workbookPr",{}),o("bookViews",{},o("workbookView",{activeTab:d===0?void 0:d})),o("sheets",{},Y.join("")),G.length>0?o("definedNames",{},G.join("")):"",o("calcPr",{calcId:je,fullCalcOnLoad:!0}))),c.add("xl/_rels/workbook.xml.rels",V(j)),c.add("xl/styles.xml",S+r.xml()),l.write(c.part("xl/sharedStrings.xml")),c.add("xl/theme/theme1.xml",S+Re),m&&c.add("xl/metadata.xml",S+Ne),c.add("docProps/core.xml",S+o("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?"":o("dc:title",{},x(s.title)))),c.add("docProps/app.xml",S+o("Properties",{xmlns:"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"},o("Application",{},"AllyHub"))),c.add("_rels/.rels",V([[`${v}officeDocument`,"xl/workbook.xml"],["http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties","docProps/core.xml"],[`${v}extended-properties`,"docProps/app.xml"]])),i.push(["/xl/styles.xml",A.styles],["/xl/sharedStrings.xml",A.strings],["/xl/theme/theme1.xml",A.theme],["/docProps/core.xml",A.core],["/docProps/app.xml",A.app]);const fe=[...u].sort(([p],[w])=>p.localeCompare(w));for(const[p,w]of fe)c.add(`xl/media/${p}`,w);return c.add("[Content_Types].xml",S+o("Types",{xmlns:k.types},o("Default",{Extension:"rels",ContentType:"application/vnd.openxmlformats-package.relationships+xml"}),o("Default",{Extension:"xml",ContentType:"application/xml"}),y>0?o("Default",{Extension:"vml",ContentType:"application/vnd.openxmlformats-officedocument.vmlDrawing"}):"",[...new Set([...u.keys()].map(p=>p.split(".").pop()??""))].sort().map(p=>o("Default",{Extension:p,ContentType:`image/${p==="jpg"?"jpeg":p}`})).join(""),i.map(([p,w])=>o("Override",{PartName:p,ContentType:w})).join(""))),{bytes:c.finish(),left:e}}
|
|
2
|
+
import{SHEET_MARGINS as we,SHEET_NOTE_AUTHOR as K,SHEET_PAPERS as xe}from"@allyhub/formats";import{MAX_COLUMNS as Q,MAX_ROWS as ee,cellName as R,columnIndex as $e,columnLetter as D,rangeName as M,readAddress as te,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 X}from"../formula/print.js";import{walk as se}from"../formula/walk.js";import{fileCells as Se,isPicture as ke,pictureHeight as Ae,pictureSize as oe}from"../files.js";import{scenariosByCell as Ee}from"../scenario.js";import{CellError as N,readTyped as Te}from"../values.js";import{FormulaCell as Ce}from"../workbook.js";import{chartPart as Me,drawingPart as _e}from"./charts.js";import{fileFormula as P,needsArray as B}from"./formula.js";import{GRID_END as W}from"./read.js";import{Styles as Re}from"./styles.js";import{THEME_XML as Le}from"./theme.js";import{HEAD as A,NS as E,el as o,xstring as x}from"./xml.js";import{ZipOut as je}from"./zip.js";const T={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=`${E.rel}/`,re="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",ie="http://schemas.microsoft.com/office/excel/2006/main",ae={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},Ie=191029;export const DEFAULT_TABLE_STYLE="TableStyleMedium2",LISTS_SHEET="AllyHub lists";const Oe=64,Fe=7,De=i=>Math.min(255,Math.floor(i/Fe*256)/256),Ne=i=>Math.min(409.5,i*3/4),q=32767,Pe=255,Ve=2e5,ze=o("metadata",{xmlns:E.main,"xmlns:xda":"http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray"},o("metadataTypes",{count:1},o("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})),o("futureMetadata",{name:"XLDAPR",count:1},o("bk",{},o("extLst",{},o("ext",{uri:"{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}"},o("xda:dynamicArrayProperties",{fDynamic:1,fCollapsed:0}))))),o("cellMetadata",{count:1},o("bk",{},o("rc",{t:1,v:0}))));class Ue{index=new Map;count=0;of(t){this.count+=1;let n=this.index.get(t);return n===void 0&&(n=this.index.size,this.index.set(t,n)),n}write(t){t.write(`${A}<sst xmlns="${E.main}" count="${String(this.count)}" uniqueCount="${String(this.index.size)}">`);for(const n of this.index.keys()){const e=/^\s|\s$|\n/u.test(n);t.write(`<si><t${e?' xml:space="preserve"':""}>${x(n)}</t></si>`)}t.write("</sst>"),t.end()}}function He(i){let t=!1;return i&&se(i,n=>{(n.kind==="structured"||n.kind==="ref"&&n.sheet!==void 0)&&(t=!0)}),t}function Xe(i){for(const t in i)if(Object.hasOwn(i,t))return!1;return!0}const Be=i=>o("x",i).slice(2,-2),We="Base case";function qe(i){const t=new Map;for(const s of i.scenarios)for(const r of s.cells)t.set(R(r),r);const n=(s,r)=>o("inputCells",{r:R(s),val:r===null||r instanceof N?"":typeof r=="boolean"?r?"1":"0":String(r)}),e=(s,r)=>o("scenario",{name:s,locked:!0,count:r.length,user:"AllyHub"},r.join(""));return o("scenarios",{current:0,show:0,sqref:[...t.keys()].join(" ")},e(We,[...t.values()].map(s=>n(s,s.base))),...i.scenarios.map(s=>e(s.name,s.cells.map(r=>n(r,r.value)))))}function Ge(i,t,n,e){const s=[];let r=0;for(const{row:a,col:h,paths:l,column:c}of Se(i,t)){let d=0;const f=Ae(c);for(const u of l){const m=ke(u)?n?.(u):void 0,$=m&&oe(m);if(!m||!$){r+=1;continue}const S=Math.round($.width/$.height*f);s.push({row:a,col:h,x:d,width:S,height:f,name:u.split("/").pop()??u,path:u,file:`.${$.type==="jpeg"?"jpg":$.type}`,bytes:m}),d+=S+4}}for(const a of i.spec.pictures??[]){const h=te(a.at),l=n?.(a.file),c=l&&oe(l);if(!h||!l||!c)continue;const d=c.width/c.height,f=a.width??(a.height===void 0?c.width:a.height*d);s.push({row:h.row,col:h.col,x:a.x??0,y:a.y??0,width:Math.round(f),height:Math.round(a.height??f/d),name:a.file.split("/").pop()??a.file,path:a.file,file:`.${c.type==="jpeg"?"jpg":c.type}`,bytes:l})}return r>0&&e.push(`${i.name}: ${String(r)} file${r===1?"":"s"} in a cell, which stay${r===1?"s":""} a name`),s}class Ye{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=D(e);return`${X(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 r=`<row r="${String(s+1)}">`;this.columns.forEach((a,h)=>{const l=a[s];l!==void 0&&(r+=`<c r="${R({row:s,col:h})}" t="s"><v>${String(t.of(l))}</v></c>`)}),n.push(`${r}</row>`)}return`${A}<worksheet xmlns="${E.main}" xmlns:r="${E.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 Ze{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,r=-1;for(let c=0;c<t;c++){const d=this.rows[c]??0,f=this.cols[c]??0;d<n&&(n=d),d>e&&(e=d),f<s&&(s=f),f>r&&(r=f)}const a=new Uint32Array(e-n+2);for(let c=0;c<t;c++){const d=(this.rows[c]??0)-n+1;a[d]=(a[d]??0)+1}for(let c=1;c<a.length;c++)a[c]=(a[c]??0)+(a[c-1]??0);const h=a.slice(0,-1),l=new Int32Array(t);for(let c=0;c<t;c++){const d=(this.rows[c]??0)-n,f=h[d]??0;l[f]=this.cols[c]??0,h[d]=f+1}return{start:a,cols:l,top:n,used:{top:n,bottom:e,left:s,right:r}}}}function Je(i,t){if(!i)return!1;let n=!1;const e=t.toLowerCase();return se(i,s=>{(s.kind==="ref"||s.kind==="name")&&s.sheet!==void 0&&s.sheet.toLowerCase()!==e&&(n=!0)}),n}const Ke=(i,t)=>`{00000000-0000-4000-8000-${(i*65536+t).toString(16).toUpperCase().padStart(12,"0")}}`;class Qe{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,r,a,h,l,c=[],d){this.sheet=t,this.calc=n,this.wb=n.wb,this.styles=e,this.strings=s,this.cached=r,this.left=a,this.lists=h,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&&B({kind:"unary",op:"-",arg:m})},this.hiddenRows=n.filtered(t),this.scenarios=d,this.drawn=t.charts.length>0||c.length>0;const f=new Map;for(const u of c)u.y===void 0&&f.set(u.row,Math.max(f.get(u.row)??0,u.height));this.tall=f}grid(){const{sheet:t}=this;if(t.lastRow>=ee)throw new Error(`${t.name} reaches row ${(t.lastRow+1).toLocaleString("en-US")}, and ${W}: an Excel file cannot hold it.`);if(t.columnsUsed>Q)throw new Error(`${t.name} reaches past column ${D(Q-1)}, and ${W}: an Excel file cannot hold it.`);for(const n of Object.keys(t.spec.rows??{}))if(Number(n)>ee)throw new Error(`${t.name} sets row ${n}, and ${W}: an Excel file cannot hold it.`)}gather(){const{sheet:t}=this,n=new Ze;for(let e=0;e<t.columnsUsed;e++){const[s,r]=t.span(e,0,Number.MAX_SAFE_INTEGER);for(let a=s;a<=r;a++)(t.at(a,e)!==void 0||t.spillAt(a,e))&&n.add(a,e)}for(const{area:e}of t.styledAreas()){const s=(e.bottom-e.top+1)*(e.right-e.left+1);if(s>Ve){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 r=e.top;r<=e.bottom;r++)for(let a=e.left;a<=e.right;a++)n.add(r,a)}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 Xe(e)?void 0:this.styles.xf(e)}held(t,n){return n.length<=q?n:(this.left.push(`${this.sheet.name}!${t} past Excel's ${String(q)} characters, of its ${String(n.length)}`),n.slice(0,q))}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 N?fe(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 r=this.value(t,n,s),{shared:a}=e;if(e.row!==a.row||e.col!==a.col)return r;const h=a.node,l=p=>{if(p===void 0||p.kind==="missing")return null;if(!(p.kind!=="ref"||p.sheet!==void 0||!p.row||!p.col))return R({row:p.row.index,col:p.col.index})},c=h?.kind==="call"?h.args:[],d=l(c[0]),f=l(c[1]);if(d===void 0||f===void 0||d===null&&f===null)return this.left.push(`${this.sheet.name}!${t}: a data table whose inputs a file cannot hold, as its values`),r;const m=this.sheet.fills.find(p=>p.shared===a)?.area??{top:e.row,left:e.col,bottom:e.row,right:e.col},$=d!==null&&f!==null?{dt2D:!0,dtr:!0,r1:d,r2:f}:d!==null?{dtr:!0,r1:d}:{dtr:!1,r1:f??""},S=o("f",{t:"dataTable",ref:M(m),...$});return typeof s=="string"?`<c r="${t}"${v(n)} t="str">${S}<v>${x(s)}</v></c>`:r.includes("<v>")?r.replace("<v>",`${S}<v>`):r.replace("/>",`>${S}</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:r}=e,{node:a}=r;if(!a)return`<c r="${t}"${v(n)} t="e"><v>#NAME?</v></c>`;if(a.kind==="call"&&a.name==="TABLE"&&a.args.length<=2)return this.dataTable(t,n,e,s);const h=(r.analysis??=be(this.wb,r)).arguments[0];if(h!==void 0)return this.misgiven.has(r)||(this.misgiven.add(r),this.left.push(`${this.sheet.name}!${t}: a formula's value, not the formula, as ${h.name} is given ${String(h.given)} arguments`)),this.value(t,n,s);let l=this.shapes.get(r);l===void 0&&(l=B(a,this.isRangeName),this.shapes.set(r,l));const c=e.array!==void 0||e.blocked!==void 0||l;let d=c?void 0:this.groups.get(r);d?.written===!1&&(e.row!==d.ref.top||e.col!==d.ref.left)&&(d=void 0);let f,u="";if(d?.written===!0)f=`<f t="shared" si="${String(d.si)}"/>`;else{const m=P(e.moved,{table:this.table(e),isTable:this.isTable,array:c});f=d?`<f t="shared" ref="${M(d.ref)}" si="${String(d.si)}">${x(m)}</f>`:`<f>${x(m)}</f>`,d&&(d.written=!0),c&&(f=this.arrayFormula(e,m))}return c&&(this.arrays=!0,u=' cm="1"'),this.cached?s===null||typeof s=="number"?`<c r="${t}"${v(n)}${u}>${f}<v>${String(s??0)}</v></c>`:typeof s=="boolean"?`<c r="${t}"${v(n)} t="b"${u}>${f}<v>${s?"1":"0"}</v></c>`:s instanceof N?fe(s)?`<c r="${t}"${v(n)} t="e"${u}>${f}<v>${s.code}</v></c>`:s.code==="#CYCLE!"?`<c r="${t}"${v(n)}${u}>${f}<v>0</v></c>`:`<c r="${t}"${v(n)} t="e"${u}>${f}<v>#VALUE!</v></c>`:`<c r="${t}"${v(n)} t="str"${u}>${f}<v>${x(this.held(t,s))}</v></c>`:`<c r="${t}"${v(n)}${u}>${f}</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)}">${x(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:r}=s;e.row<r.top&&(r.top=e.row),e.row>r.bottom&&(r.bottom=e.row),e.col<r.left&&(r.left=e.col),e.col>r.right&&(r.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:r,n:a}]of t)a>1&&r.row===s.top&&r.col===s.left&&!He(e.node)&&(this.groups.set(e,{si:n,ref:s,written:!1}),n+=1)}cell(t,n){const e=R({row:t,col:n}),s=this.styleOf(t,n),r=this.sheet.at(t,n);return r instanceof Ce?this.formula(e,s,r):r===void 0&&this.cached&&this.sheet.spillAt(t,n)?this.value(e,s,this.calc.value(this.sheet,t,n)):this.value(e,s,r??null)}columns(){const{sheet:t}=this,{spec:n}=t,e=new Map,s=new Map;for(const l of t.tables)for(const c of l.columns)c.spec?.width!==void 0&&s.set(l.at.col+c.index,c.spec.width);const r=new Set(s.keys()),a=new Map;for(const[l,c]of Object.entries(n.columns??{})){const d=$e(l);d!==void 0&&(a.set(d,c),r.add(d))}for(const l of r){const c=a.get(l),d=c?.width??s.get(l),f=he(c);e.set(l,o("col",{min:l+1,max:l+1,width:De(d??Oe),style:f===void 0?void 0:this.styles.xf(f),hidden:c?.hidden===!0?!0:void 0,customWidth:d===void 0?void 0:!0,outlineLevel:c?.level}))}const h=[...e.keys()].sort((l,c)=>l-c).map(l=>e.get(l)??"");return h.length===0?"":`<cols>${h.join("")}</cols>`}rowAttrs(t){const n=this.sheet.spec.rows?.[String(t+1)],e=he(n),s=n?.height??this.tall.get(t);return Be({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:Ne(s),customHeight:s===void 0?void 0:!0,hidden:n?.hidden===!0||this.hiddenRows.has(t)?!0:void 0,outlineLevel:n?.level})}rows(t,n){const{sheet:e}=this,s=new Set(this.hiddenRows);for(const d of Object.keys(e.spec.rows??{}))s.add(Number(d)-1);const{start:r,cols:a,top:h}=n;let l=n.used?h:1/0,c=n.used?n.used.bottom:-1;for(const d of s)d<l&&(l=d),d>c&&(c=d);for(let d=Math.max(0,l);d<=c;d++){const f=d-h,u=f>=0&&f<r.length-1?r[f]??0:0,m=f>=0&&f<r.length-1?r[f+1]??0:0;if(u===m&&!s.has(d))continue;if(u===m){t.write(`<row${this.rowAttrs(d)}/>`);continue}const $=a.subarray(u,m).sort();let S=`<row${this.rowAttrs(d)}>`,p=-1;for(const b of $)b!==p&&(p=b,S+=this.cell(d,b));t.write(`${S}</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=o("pane",{xSplit:n.col>0?n.col:void 0,ySplit:n.row>0?n.row:void 0,topLeftCell:R(n),activePane:s,state:"frozen"})}return o("sheetViews",{},o("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 r=this.gather();this.shareFormulas();const a=s.tables.map((p,b)=>o("tablePart",{"r:id":`rId${String(b+1)}`})),{print:h}=s.spec,l=h?.fit,c=Object.keys(s.spec.notes??{}).length>0;t.write(`${A}<worksheet xmlns="${E.main}" xmlns:r="${E.rel}">`+(s.spec.tab===void 0&&l===void 0?"":o("sheetPr",{},s.spec.tab===void 0?"":o("tabColor",{rgb:`FF${s.spec.tab.slice(1).toUpperCase()}`}),l===void 0?"":o("pageSetUpPr",{fitToPage:!0})))+o("dimension",{ref:r.used?M(r.used):"A1"})+this.view(n)+o("sheetFormatPr",{defaultRowHeight:15,outlineLevelRow:le(s.spec.rows),outlineLevelCol:le(s.spec.columns)})+this.columns()+"<sheetData>"),this.rows(t,r);const d=a.length+1+(this.drawn?1:0)+(c?2:0);let f=0;const u=Object.entries(s.spec.links??{}).map(([p,b])=>b.startsWith("#")?o("hyperlink",{ref:p,location:b.slice(1)}):o("hyperlink",{ref:p,"r:id":`rId${String(d+f++)}`})),m=s.merges.map(p=>o("mergeCell",{ref:M(p)})),$=s.conditions.map((p,b)=>this.condition(p,b+1)).join(""),S=this.validations();return t.write("</sheetData>"+(s.spec.protect===!0?o("sheetProtection",{sheet:!0,objects:!0,scenarios:!0}):"")+(this.scenarios?qe(this.scenarios):"")+this.sheetFilter()+(m.length>0?o("mergeCells",{count:m.length},m.join("")):"")+$+S+(u.length>0?o("hyperlinks",{},u.join("")):"")+o("pageMargins",{...we,...h?.margins})+(h?.orientation!==void 0||h?.paper!==void 0||l!==void 0?o("pageSetup",{paperSize:h?.paper===void 0?void 0:xe[h.paper],fitToWidth:l?.width,fitToHeight:l?.height,orientation:h?.orientation}):"")+(h?.header||h?.footer?o("headerFooter",{},h.header?o("oddHeader",{},x(ce(h.header))):"",h.footer?o("oddFooter",{},x(ce(h.footer))):""):"")+(this.drawn?o("drawing",{"r:id":`rId${String(a.length+1)}`}):"")+(c?o("legacyDrawing",{"r:id":`rId${String(a.length+(this.drawn?2:1))}`}):"")+(a.length>0?o("tableParts",{count:a.length},a.join("")):"")+this.extensions()+"</worksheet>"),t.end(),s.tables.map((p,b)=>this.tableXml(p,e+b))}extensions(){const t=[];return this.newerRules.length>0&&t.push(o("ext",{uri:ae.conditional,"xmlns:x14":re},o("x14:conditionalFormattings",{},this.newerRules.join("")))),this.newerValidations.length>0&&t.push(o("ext",{uri:ae.validations,"xmlns:x14":re},o("x14:dataValidations",{count:this.newerValidations.length,"xmlns:xm":ie},this.newerValidations.join("")))),t.length===0?"":o("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?P(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?o("x14:cfvo",{type:t.at},e===void 0?"":o("xm:f",{},x(e))):o("cfvo",{type:t.at,val:e})}crosses(t){return t.some(n=>Je(n?.node,this.sheet.name))}condition(t,n){const{spec:e}=t,s=e.range,r=e.type!=="dataBar"&&this.crosses(t.formulas),a=(f,u,...m)=>{if(!r){const $=Object.keys(u).length===0?void 0:this.styles.dxf(u);return o("conditionalFormatting",{sqref:s},o("cfRule",{...f,dxfId:$,priority:n,stopIfTrue:e.stop===!0?!0:void 0},...m))}return this.newerRules.push(o("x14:conditionalFormatting",{"xmlns:xm":ie},o("x14:cfRule",{...f,priority:n,stopIfTrue:e.stop===!0?!0:void 0,id:Ke(this.index,n)},...m.map($=>$.replace(/^<formula>(.*)<\/formula>$/su,"<xm:f>$1</xm:f>")),Object.keys(u).length===0?"":this.styles.dxfXml(u,"x14:dxf")),o("xm:sqref",{},s))),""},h=st(e),l=t.areas[0],c=l?R({row:l.top,col:l.left}):"A1",d=f=>o("formula",{},x(f));switch(e.type){case"cellIs":return a({type:"cellIs",operator:e.operator},h,...e.formula.map(f=>d(this.bound(f))));case"containsText":{const f=e.operator??"contains",u=`"${e.text.replaceAll('"','""')}"`,m=f==="contains"?`NOT(ISERROR(SEARCH(${u},${c})))`:f==="notContains"?`ISERROR(SEARCH(${u},${c}))`:f==="beginsWith"?`LEFT(${c},LEN(${u}))=${u}`:`RIGHT(${c},LEN(${u}))=${u}`;return a({type:f==="contains"?"containsText":f==="notContains"?"notContainsText":f,operator:f==="contains"?"containsText":f,text:e.text},h,d(m))}case"duplicateValues":case"uniqueValues":return a({type:e.type},h);case"top10":return a({type:"top10",percent:e.percent===!0?!0:void 0,bottom:e.bottom===!0?!0:void 0,rank:e.rank},h);case"aboveAverage":return a({type:"aboveAverage",aboveAverage:e.below===!0?!1:void 0,equalAverage:e.equal===!0?!0:void 0},h);case"expression":return a({type:"expression"},h,d(this.bound(e.formula.startsWith("=")?e.formula:`=${e.formula}`)));case"dataBar":return a({type:"dataBar"},{},o("dataBar",{showValue:e.show===!1?!1:void 0},this.cfvo(e.min??{at:"min"},!1),this.cfvo(e.max??{at:"max"},!1),o("color",{rgb:de(e.color)})));case"colorScale":{const f=r?"x14:":"";return a({type:"colorScale"},{},o(`${f}colorScale`,{},...e.stops.map(u=>this.cfvo(u,r)),...e.stops.map(u=>o(`${f}color`,{rgb:de(u.color)}))))}case"iconSet":{const f=Number.parseInt(e.icons,10),u=e.stops??Array.from({length:f},(m,$)=>({at:"percent",value:Math.round($*100/f)}));return a({type:"iconSet"},{},o(r?"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,r))))}}}validation(t){const{spec:n}=t;let e="",s=this.crosses(t.formulas);if(n.values){const c=n.values.join(",");c.length>Pe||n.values.some(d=>d.includes(",")||d.includes('"'))?(e=this.lists.place(n.values),s=!0):e=`"${c}"`}else e=this.bound(n.formula?.[0]);const r=this.bound(n.formula?.[1]),{error:a,prompt:h}=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 l={type:n.type,errorStyle:a?.style===void 0||a.style==="stop"?void 0:a.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:h?.show===!1?void 0:!0,showErrorMessage:a?.show===!1||n.multiple===!0?void 0:!0,errorTitle:a?.title,error:a?.message,promptTitle:h?.title,prompt:h?.message};return s?(this.newerValidations.push(o("x14:dataValidation",l,e===""?"":o("x14:formula1",{},o("xm:f",{},x(e))),r===""?"":o("x14:formula2",{},o("xm:f",{},x(r))),o("xm:sqref",{},n.range))),""):o("dataValidation",{...l,sqref:n.range},e===""?"":o("formula1",{},x(e)),r===""?"":o("formula2",{},x(r)))}validations(){const t=this.sheet.validations.map(n=>this.validation(n)).filter(n=>n!=="");return t.length===0?"":o("dataValidations",{count:t.length},t.join(""))}filterColumns(t){return[...t.columns.entries()].sort(([n],[e])=>n-e).map(([n,e])=>ot(n-t.area.left,e))}sheetFilter(){const t=this.sheet.filters.find(n=>!n.table);return t?o("autoFilter",{ref:M(t.area)},...this.filterColumns(t)):""}columnFormula(t,n){if(!n?.node)return"";const e=B(n.node,this.isRangeName),s=P(n.node,{table:t.name,isTable:this.isTable,array:e});return o("calculatedColumnFormula",{array:e?!0:void 0},x(s))}tableXml(t,n){const e=t.area,s=M({...e,bottom:Math.max(e.bottom,e.top+1)}),r=t.spec.style??DEFAULT_TABLE_STYLE,a=this.sheet.filters.find(h=>h.table===t);return A+o("table",{xmlns:E.main,id:n,name:t.name,displayName:t.name,ref:s,totalsRowShown:0},a?o("autoFilter",{ref:s},...this.filterColumns(a)):"",o("tableColumns",{count:t.columns.length},t.columns.map((h,l)=>o("tableColumn",{id:l+1,name:h.name},this.columnFormula(t,h.formula))).join("")),r==="none"?o("tableStyleInfo",{showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}):o("tableStyleInfo",{name:r,showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}))}}const le=i=>{let t;for(const n of Object.values(i??{}))n.level!==void 0&&(t=Math.max(t??0,n.level));return t},ce=i=>[i.left===void 0?"":`&L${i.left}`,i.center===void 0?"":`&C${i.center}`,i.right===void 0?"":`&R${i.right}`].join(""),et=i=>typeof i=="string"?{text:i,author:K}:{text:i.text,author:i.author??K};function tt(i){const t=i.map(([e,s])=>({ref:e,...et(s)})),n=[...new Set(t.map(e=>e.author))];return A+o("comments",{xmlns:E.main},o("authors",{},n.map(e=>o("author",{},x(e))).join("")),o("commentList",{},t.map(e=>o("comment",{ref:e.ref,authorId:n.indexOf(e.author)},o("text",{},o("r",{},o("t",/^\s|\s$|\n/u.test(e.text)?{"xml:space":"preserve"}:{},x(e.text)))))).join("")))}function nt(i){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>${i.flatMap(([n],e)=>{const s=te(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 de=i=>`FF${i.slice(1).toUpperCase()}`;function st(i){if(i.type==="dataBar"||i.type==="colorScale"||i.type==="iconSet")return{};const t={};for(const n of["bold","italic","underline","strike","color","fill","border"])i[n]!==void 0&&(t[n]=i[n]);return t}function ot(i,t){return o("filterColumn",{colId:i},o("filters",{blank:t.blanks===!0?!0:void 0},(t.values??[]).map(n=>o("filter",{val:n})).join("")))}const v=i=>i===void 0?"":` s="${String(i)}"`,rt=new Set(["#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#GETTING_DATA"]),fe=i=>rt.has(i.code),it=new Set(["width","height","hidden"]);function he(i){if(!i)return;const t=Object.fromEntries(Object.entries(i).filter(([n])=>!it.has(n)));return Object.keys(t).length===0?void 0:t}const V=i=>A+o("Relationships",{xmlns:E.pkg},i.map(([t,n,e],s)=>o("Relationship",{Id:`rId${String(s+1)}`,Type:t,Target:n,TargetMode:e})).join(""));function at(i,t){const n=t.formula?.node;if(n)return P(n,{isTable:s=>i.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 N?e.code:String(e)}const lt=(i,t)=>i.length===t.length&&i.every((n,e)=>n===t[e]),ue=i=>`$${D(i.left)}$${String(i.top+1)}:$${D(i.right)}$${String(i.bottom+1)}`;function ct(i){const t=[],n=(e,s)=>o("definedName",{name:e.name,localSheetId:s,hidden:e.hidden===!0?!0:void 0},x(at(i,e)));for(const e of i.names.values())t.push(n(e));return i.sheets.forEach((e,s)=>{for(const d of e.names.values())t.push(n(d,s));const r=e.filters.find(d=>!d.table);r&&t.push(o("definedName",{name:"_xlnm._FilterDatabase",localSheetId:s,hidden:!0},x(`${X(e.name)}${ue(r.area)}`)));const a=X(e.name),h=e.spec.print,l=h?.area===void 0?void 0:ye(h.area);l&&t.push(o("definedName",{name:"_xlnm.Print_Area",localSheetId:s},x(`${a}${ue(l)}`)));const c=[h?.title_cols?.toUpperCase().replace(/([A-Z]+):([A-Z]+)/u,"$$$1:$$$2"),h?.title_rows?.replace(/(\d+):(\d+)/u,"$$$1:$$$2")].flatMap(d=>d===void 0?[]:[`${a}${d}`]);c.length>0&&t.push(o("definedName",{name:"_xlnm.Print_Titles",localSheetId:s},x(c.join(","))))}),t}function dt(i){if(i===void 0)return{};const t=i===!0?{}:i;return{iterate:!0,iterateCount:t.max_iterations??ne.max_iterations,iterateDelta:t.max_change??ne.max_change}}export function writeXlsx(i,t={}){const n=i.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(i);e.push(...s.left);const r=new Re,a=new Ue,h=new Ye(n),l=new je,c=[["/xl/workbook.xml",T.sheet]],d=Math.max(0,n.sheets.findIndex(g=>g.spec.hidden!==!0));let f=1,u=!1;const m=new Map;let $=0,S=0,p=0;for(const[g,w]of n.sheets.entries()){const U=String(g+1),I=Ge(w,i,t.file,e),O=w.charts.filter(({spec:y})=>[y.categories,...y.series.flatMap(C=>[C.values,C.x])].some(C=>C?.endsWith("#"))).length;O>0&&e.push(`${w.name}: ${String(O)} chart${O===1?"":"s"} on a spill: ${O===1?"it reads":"they read"} the cells the spill covers now, and will not grow with it`);const Z=new Qe(w,i,r,a,t.cached!==!1,e,h,g,I,s.sheets.find(y=>y.sheet===w)),pe=Z.write(l.part(`xl/worksheets/sheet${U}.xml`),g===d,f);u||=Z.arrays,c.push([`/xl/worksheets/sheet${U}.xml`,T.worksheet]);const _=[];for(const y of pe){const C=`table${String(f)}.xml`;f+=1,l.add(`xl/tables/${C}`,y),c.push([`/xl/tables/${C}`,T.table]),_.push([`${k}table`,`../tables/${C}`])}if(w.charts.length>0||I.length>0){$+=1;const y=`drawing${String($)}.xml`;l.add(`xl/drawings/${y}`,_e(w.charts,I)),c.push([`/xl/drawings/${y}`,T.drawing]),_.push([`${k}drawing`,`../drawings/${y}`]);const C=w.charts.map(j=>{S+=1;const F=`chart${String(S)}.xml`;return l.add(`xl/charts/${F}`,Me(i,w,j)),c.push([`/xl/charts/${F}`,T.chart]),[`${k}chart`,`../charts/${F}`]});for(const j of I){const J=[...m].find(([,ge])=>lt(ge,j.bytes))?.[0]??`image${String(m.size+1)}${j.file}`;m.set(J,j.bytes),C.push([`${k}image`,`../media/${J}`])}l.add(`xl/drawings/_rels/${y}.rels`,V(C))}const H=Object.entries(w.spec.notes??{});if(H.length>0){p+=1;const y=String(p);l.add(`xl/comments${y}.xml`,tt(H)),c.push([`/xl/comments${y}.xml`,T.comments]),l.add(`xl/drawings/vmlDrawing${y}.vml`,nt(H)),_.push([`${k}vmlDrawing`,`../drawings/vmlDrawing${y}.vml`]),_.push([`${k}comments`,`../comments${y}.xml`])}for(const y of Object.values(w.spec.links??{}))y.startsWith("#")||_.push([`${k}hyperlink`,y,"External"]);_.length>0&&l.add(`xl/worksheets/_rels/sheet${U}.xml.rels`,V(_))}const b=n.sheets.length,z=h.columns.length>0;if(z){const g=`xl/worksheets/sheet${String(b+1)}.xml`;l.add(g,h.xml(a)),c.push([`/${g}`,T.worksheet])}const L=[...n.sheets,...z?[void 0]:[]].map((g,w)=>[`${k}worksheet`,`worksheets/sheet${String(w+1)}.xml`]);L.push([`${k}theme`,"theme/theme1.xml"]),L.push([`${k}styles`,"styles.xml"]),L.push([`${k}sharedStrings`,"sharedStrings.xml"]),u&&(L.push([`${k}sheetMetadata`,"metadata.xml"]),c.push(["/xl/metadata.xml",T.metadata]));const G=ct(n),Y=n.sheets.map((g,w)=>o("sheet",{name:g.name,sheetId:w+1,state:g.spec.hidden===!0?"hidden":void 0,"r:id":`rId${String(w+1)}`}));z&&Y.push(o("sheet",{name:h.name,sheetId:b+1,state:"veryHidden","r:id":`rId${String(b+1)}`})),l.add("xl/workbook.xml",A+o("workbook",{xmlns:E.main,"xmlns:r":E.rel},o("workbookPr",{}),o("bookViews",{},o("workbookView",{activeTab:d===0?void 0:d})),o("sheets",{},Y.join("")),G.length>0?o("definedNames",{},G.join("")):"",o("calcPr",{calcId:Ie,fullCalcOnLoad:!0,...dt(n.file.iteration)}))),l.add("xl/_rels/workbook.xml.rels",V(L)),l.add("xl/styles.xml",A+r.xml()),a.write(l.part("xl/sharedStrings.xml")),l.add("xl/theme/theme1.xml",A+Le),u&&l.add("xl/metadata.xml",A+ze),l.add("docProps/core.xml",A+o("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?"":o("dc:title",{},x(n.title)))),l.add("docProps/app.xml",A+o("Properties",{xmlns:"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"},o("Application",{},"AllyHub"))),l.add("_rels/.rels",V([[`${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",T.styles],["/xl/sharedStrings.xml",T.strings],["/xl/theme/theme1.xml",T.theme],["/docProps/core.xml",T.core],["/docProps/app.xml",T.app]);const me=[...m].sort(([g],[w])=>g.localeCompare(w));for(const[g,w]of me)l.add(`xl/media/${g}`,w);return l.add("[Content_Types].xml",A+o("Types",{xmlns:E.types},o("Default",{Extension:"rels",ContentType:"application/vnd.openxmlformats-package.relationships+xml"}),o("Default",{Extension:"xml",ContentType:"application/xml"}),p>0?o("Default",{Extension:"vml",ContentType:"application/vnd.openxmlformats-officedocument.vmlDrawing"}):"",[...new Set([...m.keys()].map(g=>g.split(".").pop()??""))].sort().map(g=>o("Default",{Extension:g,ContentType:`image/${g==="jpg"?"jpeg":g}`})).join(""),c.map(([g,w])=>o("Override",{PartName:g,ContentType:w})).join(""))),{bytes:l.finish(),left:e}}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/** Text as an ST_Xstring, then escaped for XML. */
|
|
2
2
|
export declare function xstring(text: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* An attribute's value: an XML reader makes a line break or a tab in one a
|
|
5
|
+
* space (3.3.3 Attribute-Value Normalization), so they are written as
|
|
6
|
+
* Excel writes them, _x000a_ (a table's column "Also LONG\nBUT TWO LINES",
|
|
7
|
+
* which Excel otherwise repairs as no longer its header's text).
|
|
8
|
+
*/
|
|
9
|
+
export declare const xattr: (text: string) => string;
|
|
3
10
|
/** What an ST_Xstring says. */
|
|
4
11
|
export declare const readXstring: (text: string) => string;
|
|
5
12
|
export type Attrs = Record<string, string | number | boolean | undefined>;
|
|
@@ -15,7 +22,11 @@ export declare const NS: {
|
|
|
15
22
|
};
|
|
16
23
|
/** An element or an attribute as the parser gives it. */
|
|
17
24
|
export type Tag = Record<string, unknown>;
|
|
18
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* A part's root element. Line ends are XML's first (2.11 End-of-Line
|
|
27
|
+
* Handling): a CR LF or a CR in the text is a LF, as Excel reads it; a CR
|
|
28
|
+
* written as or _x000D_ stays one.
|
|
29
|
+
*/
|
|
19
30
|
export declare function readXml(text: string): Tag;
|
|
20
31
|
export declare const tags: (v: unknown) => Tag[];
|
|
21
32
|
export declare const tag: (v: unknown) => Tag | undefined;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{XMLParser as
|
|
3
|
-
`,NS={main:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",rel:"http://schemas.openxmlformats.org/officeDocument/2006/relationships",pkg:"http://schemas.openxmlformats.org/package/2006/relationships",types:"http://schemas.openxmlformats.org/package/2006/content-types",drawing:"http://schemas.openxmlformats.org/drawingml/2006/main"};const u=new Set(["c","row","col","cols","si","r","rPh","sheet","definedName","font","fill","border","numFmt","xf","Relationship","Override","Default","mergeCell","tablePart","tableColumn","sheetView","pane","selection","conditionalFormatting","dataValidation","hyperlink","rgbColor","brk","filterColumn","externalReference","gsd"]),d=new
|
|
2
|
+
import{XMLParser as c}from"fast-xml-parser";const l={"&":"&","<":"<",">":">",'"':"""},p=e=>e<32&&e!==9&&e!==10||e===65534||e===65535||e>=55296&&e<=57343,i=e=>e.toString(16).toUpperCase().padStart(4,"0");export function xstring(e){const t=e.replace(/_(?=x[0-9A-Fa-f]{4}_)/gu,"_x005F_");let r="";for(const n of t){const o=n.codePointAt(0)??0;r+=n.length===1&&p(o)?`_x${i(o)}_`:n}return r.replace(/[&<>"]/gu,n=>l[n]??n)}export const xattr=e=>xstring(e).replace(/[\t\n\r]/gu,t=>`_x${i(t.charCodeAt(0))}_`),readXstring=e=>e.includes("_x")?e.replace(/_x([0-9A-Fa-f]{4})_/gu,(t,r)=>String.fromCharCode(Number.parseInt(r,16))):e;export function el(e,t={},...r){let n="";for(const[f,s]of Object.entries(t))s!==void 0&&(n+=` ${f}="${xattr(typeof s=="boolean"?s?"1":"0":String(s))}"`);const o=r.join("");return o===""?`<${e}${n}/>`:`<${e}${n}>${o}</${e}>`}export const HEAD=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
3
|
+
`,NS={main:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",rel:"http://schemas.openxmlformats.org/officeDocument/2006/relationships",pkg:"http://schemas.openxmlformats.org/package/2006/relationships",types:"http://schemas.openxmlformats.org/package/2006/content-types",drawing:"http://schemas.openxmlformats.org/drawingml/2006/main"};const u=new Set(["c","row","col","cols","si","r","rPh","sheet","definedName","font","fill","border","numFmt","xf","Relationship","Override","Default","mergeCell","tablePart","tableColumn","sheetView","pane","selection","conditionalFormatting","dataValidation","hyperlink","rgbColor","brk","filterColumn","externalReference","gsd"]),d=new c({ignoreAttributes:!1,attributeNamePrefix:"",removeNSPrefix:!0,trimValues:!1,parseTagValue:!1,parseAttributeValue:!1,processEntities:!0,htmlEntities:!0,textNodeName:"#text",isArray:(e,t,r,n)=>!n&&u.has(e)});export function readXml(e){return d.parse(e.replace(/\r\n?/gu,`
|
|
4
|
+
`))}const a=e=>typeof e=="object"?e:{};export const tags=e=>Array.isArray(e)?e.map(a):e===void 0?[]:[a(e)],tag=e=>{const t=Array.isArray(e)?e[0]:e;return t===void 0?void 0:a(t)};export function textOf(e){if(typeof e=="string")return e;if(e==null)return"";if(Array.isArray(e))return e.map(textOf).join("");const t=e["#text"];return typeof t=="string"?t:""}export const attr=(e,t)=>{const r=e?.[t];return typeof r=="string"?r:void 0},numberAttr=(e,t)=>{const r=attr(e,t);if(r===void 0||r==="")return;const n=Number(r);return Number.isFinite(n)?n:void 0},flag=(e,t)=>{const r=attr(e,t);return r===void 0?void 0:r==="1"||r==="true"};
|