@allyhub/sdk 0.12.0 → 0.13.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.
Files changed (149) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/node_modules/@allyhub/audio/dist/plan.d.ts +3 -0
  3. package/dist/node_modules/@allyhub/audio/dist/render.js +1 -1
  4. package/dist/node_modules/@allyhub/audio/package.json +1 -1
  5. package/dist/node_modules/@allyhub/chart/dist/chart-file.d.ts +2 -0
  6. package/dist/node_modules/@allyhub/chart/dist/chart-file.js +1 -1
  7. package/dist/node_modules/@allyhub/chart/dist/chart-xml.js +3 -2
  8. package/dist/node_modules/@allyhub/chart/dist/chart.d.ts +5 -12
  9. package/dist/node_modules/@allyhub/chart/dist/chart.js +2 -1
  10. package/dist/node_modules/@allyhub/chart/dist/color.d.ts +37 -0
  11. package/dist/node_modules/@allyhub/chart/dist/color.js +2 -0
  12. package/dist/node_modules/@allyhub/chart/dist/index.d.ts +1 -0
  13. package/dist/node_modules/@allyhub/chart/dist/index.js +1 -1
  14. package/dist/node_modules/@allyhub/chart/dist/svg.js +1 -1
  15. package/dist/node_modules/@allyhub/chart/package.json +1 -1
  16. package/dist/node_modules/@allyhub/diagnostics/package.json +1 -1
  17. package/dist/node_modules/@allyhub/formats/dist/data/deck-code.d.ts +130 -0
  18. package/dist/node_modules/@allyhub/formats/dist/data/deck-code.js +1 -1
  19. package/dist/node_modules/@allyhub/formats/dist/data/gen.d.ts +3 -1
  20. package/dist/node_modules/@allyhub/formats/dist/data/gen.js +1 -1
  21. package/dist/node_modules/@allyhub/formats/dist/data/sheet.d.ts +512 -166
  22. package/dist/node_modules/@allyhub/formats/dist/data/sheet.js +1 -1
  23. package/dist/node_modules/@allyhub/formats/dist/data/slides.d.ts +2523 -136
  24. package/dist/node_modules/@allyhub/formats/dist/data/slides.js +1 -1
  25. package/dist/node_modules/@allyhub/formats/dist/schemas.d.ts +931 -87
  26. package/dist/node_modules/@allyhub/formats/dist/schemas.js +1 -1
  27. package/dist/node_modules/@allyhub/formats/package.json +1 -1
  28. package/dist/node_modules/@allyhub/image-draw/package.json +1 -1
  29. package/dist/node_modules/@allyhub/image-measure/package.json +1 -1
  30. package/dist/node_modules/@allyhub/image-sdk/package.json +1 -1
  31. package/dist/node_modules/@allyhub/measure/package.json +1 -1
  32. package/dist/node_modules/@allyhub/ooxml/dist/color.d.ts +11 -0
  33. package/dist/node_modules/@allyhub/ooxml/dist/color.js +1 -1
  34. package/dist/node_modules/@allyhub/ooxml/dist/ext.d.ts +43 -0
  35. package/dist/node_modules/@allyhub/ooxml/dist/ext.js +1 -1
  36. package/dist/node_modules/@allyhub/ooxml/dist/index.d.ts +2 -1
  37. package/dist/node_modules/@allyhub/ooxml/dist/index.js +1 -1
  38. package/dist/node_modules/@allyhub/ooxml/dist/transform.d.ts +13 -0
  39. package/dist/node_modules/@allyhub/ooxml/dist/transform.js +2 -0
  40. package/dist/node_modules/@allyhub/ooxml/package.json +5 -1
  41. package/dist/node_modules/@allyhub/piece/dist/gen.d.ts +4 -4
  42. package/dist/node_modules/@allyhub/piece/dist/media.d.ts +2 -2
  43. package/dist/node_modules/@allyhub/piece/package.json +1 -1
  44. package/dist/node_modules/@allyhub/protocol/dist/account.d.ts +35 -0
  45. package/dist/node_modules/@allyhub/protocol/dist/account.js +1 -1
  46. package/dist/node_modules/@allyhub/protocol/dist/cloud.d.ts +19 -0
  47. package/dist/node_modules/@allyhub/protocol/dist/cloud.js +1 -1
  48. package/dist/node_modules/@allyhub/protocol/dist/editor.d.ts +35 -20
  49. package/dist/node_modules/@allyhub/protocol/dist/editor.js +1 -1
  50. package/dist/node_modules/@allyhub/protocol/dist/events.d.ts +3 -3
  51. package/dist/node_modules/@allyhub/protocol/dist/frame.d.ts +28 -2
  52. package/dist/node_modules/@allyhub/protocol/dist/frame.js +1 -1
  53. package/dist/node_modules/@allyhub/protocol/dist/jobs.d.ts +6 -6
  54. package/dist/node_modules/@allyhub/protocol/dist/snapshots.d.ts +73 -10
  55. package/dist/node_modules/@allyhub/protocol/dist/snapshots.js +1 -1
  56. package/dist/node_modules/@allyhub/protocol/dist/tools.d.ts +9 -9
  57. package/dist/node_modules/@allyhub/protocol/package.json +1 -1
  58. package/dist/node_modules/@allyhub/runtimes/package.json +1 -1
  59. package/dist/node_modules/@allyhub/scenery/package.json +1 -1
  60. package/dist/node_modules/@allyhub/sheet/dist/annotations.d.ts +14 -0
  61. package/dist/node_modules/@allyhub/sheet/dist/annotations.js +2 -0
  62. package/dist/node_modules/@allyhub/sheet/dist/api/capabilities.js +1 -1
  63. package/dist/node_modules/@allyhub/sheet/dist/api/index.d.ts +1 -1
  64. package/dist/node_modules/@allyhub/sheet/dist/api/index.js +1 -1
  65. package/dist/node_modules/@allyhub/sheet/dist/api/rules.d.ts +24 -0
  66. package/dist/node_modules/@allyhub/sheet/dist/api/rules.js +1 -1
  67. package/dist/node_modules/@allyhub/sheet/dist/api/styles.d.ts +12 -0
  68. package/dist/node_modules/@allyhub/sheet/dist/api/styles.js +1 -1
  69. package/dist/node_modules/@allyhub/sheet/dist/api/workbook.d.ts +3 -1
  70. package/dist/node_modules/@allyhub/sheet/dist/api/workbook.js +1 -1
  71. package/dist/node_modules/@allyhub/sheet/dist/arrange.d.ts +28 -1
  72. package/dist/node_modules/@allyhub/sheet/dist/arrange.js +1 -1
  73. package/dist/node_modules/@allyhub/sheet/dist/data-tools.d.ts +42 -0
  74. package/dist/node_modules/@allyhub/sheet/dist/data-tools.js +2 -0
  75. package/dist/node_modules/@allyhub/sheet/dist/edit.d.ts +43 -2
  76. package/dist/node_modules/@allyhub/sheet/dist/edit.js +1 -1
  77. package/dist/node_modules/@allyhub/sheet/dist/fill.d.ts +10 -0
  78. package/dist/node_modules/@allyhub/sheet/dist/fill.js +1 -1
  79. package/dist/node_modules/@allyhub/sheet/dist/filter.js +1 -1
  80. package/dist/node_modules/@allyhub/sheet/dist/formula/rewrite.d.ts +14 -0
  81. package/dist/node_modules/@allyhub/sheet/dist/formula/rewrite.js +1 -1
  82. package/dist/node_modules/@allyhub/sheet/dist/html.js +10 -10
  83. package/dist/node_modules/@allyhub/sheet/dist/index.d.ts +6 -1
  84. package/dist/node_modules/@allyhub/sheet/dist/index.js +1 -1
  85. package/dist/node_modules/@allyhub/sheet/dist/outline.d.ts +30 -0
  86. package/dist/node_modules/@allyhub/sheet/dist/outline.js +2 -0
  87. package/dist/node_modules/@allyhub/sheet/dist/rich.d.ts +29 -0
  88. package/dist/node_modules/@allyhub/sheet/dist/rich.js +2 -0
  89. package/dist/node_modules/@allyhub/sheet/dist/rules.js +1 -1
  90. package/dist/node_modules/@allyhub/sheet/dist/table-style.d.ts +6 -0
  91. package/dist/node_modules/@allyhub/sheet/dist/table-style.js +1 -1
  92. package/dist/node_modules/@allyhub/sheet/dist/table-styles.js +1 -1
  93. package/dist/node_modules/@allyhub/sheet/dist/workbook.d.ts +5 -1
  94. package/dist/node_modules/@allyhub/sheet/dist/workbook.js +1 -1
  95. package/dist/node_modules/@allyhub/sheet/dist/xlsx/charts.js +1 -1
  96. package/dist/node_modules/@allyhub/sheet/dist/xlsx/import.js +1 -1
  97. package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.d.ts +17 -1
  98. package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.js +2 -2
  99. package/dist/node_modules/@allyhub/sheet/dist/xlsx/runs.d.ts +56 -0
  100. package/dist/node_modules/@allyhub/sheet/dist/xlsx/runs.js +2 -0
  101. package/dist/node_modules/@allyhub/sheet/dist/xlsx/styles.d.ts +6 -0
  102. package/dist/node_modules/@allyhub/sheet/dist/xlsx/styles.js +1 -1
  103. package/dist/node_modules/@allyhub/sheet/dist/xlsx/write.js +1 -1
  104. package/dist/node_modules/@allyhub/sheet/package.json +1 -1
  105. package/dist/node_modules/@allyhub/slides-core/dist/animation.d.ts +117 -21
  106. package/dist/node_modules/@allyhub/slides-core/dist/animation.js +1 -1
  107. package/dist/node_modules/@allyhub/slides-core/dist/api.d.ts +181 -30
  108. package/dist/node_modules/@allyhub/slides-core/dist/api.js +3 -3
  109. package/dist/node_modules/@allyhub/slides-core/dist/capabilities.js +1 -1
  110. package/dist/node_modules/@allyhub/slides-core/dist/chart-api.d.ts +28 -2
  111. package/dist/node_modules/@allyhub/slides-core/dist/chart-api.js +1 -1
  112. package/dist/node_modules/@allyhub/slides-core/dist/check.js +1 -1
  113. package/dist/node_modules/@allyhub/slides-core/dist/enums.d.ts +222 -4
  114. package/dist/node_modules/@allyhub/slides-core/dist/enums.js +1 -1
  115. package/dist/node_modules/@allyhub/slides-core/dist/file.d.ts +6 -0
  116. package/dist/node_modules/@allyhub/slides-core/dist/file.js +3 -3
  117. package/dist/node_modules/@allyhub/slides-core/dist/generated/table-styles.d.ts +3 -0
  118. package/dist/node_modules/@allyhub/slides-core/dist/generated/table-styles.js +2 -0
  119. package/dist/node_modules/@allyhub/slides-core/dist/index.d.ts +3 -0
  120. package/dist/node_modules/@allyhub/slides-core/dist/index.js +1 -1
  121. package/dist/node_modules/@allyhub/slides-core/dist/merge.js +1 -1
  122. package/dist/node_modules/@allyhub/slides-core/dist/model.d.ts +98 -10
  123. package/dist/node_modules/@allyhub/slides-core/dist/numbering.d.ts +6 -0
  124. package/dist/node_modules/@allyhub/slides-core/dist/numbering.js +2 -0
  125. package/dist/node_modules/@allyhub/slides-core/dist/office.d.ts +53 -0
  126. package/dist/node_modules/@allyhub/slides-core/dist/office.js +1 -1
  127. package/dist/node_modules/@allyhub/slides-core/dist/patterns.d.ts +8 -0
  128. package/dist/node_modules/@allyhub/slides-core/dist/patterns.js +2 -0
  129. package/dist/node_modules/@allyhub/slides-core/dist/resolve.d.ts +36 -6
  130. package/dist/node_modules/@allyhub/slides-core/dist/resolve.js +1 -1
  131. package/dist/node_modules/@allyhub/slides-core/dist/script.d.ts +11 -0
  132. package/dist/node_modules/@allyhub/slides-core/dist/script.js +2 -2
  133. package/dist/node_modules/@allyhub/slides-core/dist/sdk.d.ts +1 -1
  134. package/dist/node_modules/@allyhub/slides-core/dist/sdk.js +1 -1
  135. package/dist/node_modules/@allyhub/slides-core/dist/table-style.d.ts +48 -0
  136. package/dist/node_modules/@allyhub/slides-core/dist/table-style.js +2 -0
  137. package/dist/node_modules/@allyhub/slides-core/package.json +1 -1
  138. package/dist/node_modules/@allyhub/video-core/dist/mix-plan.js +1 -1
  139. package/dist/node_modules/@allyhub/video-core/dist/timeline.d.ts +4 -0
  140. package/dist/node_modules/@allyhub/video-core/package.json +1 -1
  141. package/dist/node_modules/@allyhub/video-sdk/package.json +1 -1
  142. package/docs/defaults.md +78 -4
  143. package/docs/image.md +1 -1
  144. package/docs/pictures.md +1 -1
  145. package/docs/project.md +1 -1
  146. package/docs/sheets.md +19 -9
  147. package/docs/slides.md +30 -16
  148. package/docs/speech.md +1 -1
  149. package/package.json +1 -1
@@ -5,6 +5,7 @@ import type { Node } from "../formula/ast.js";
5
5
  import { type Scalar } from "../values.js";
6
6
  import type { CellLook } from "../workbook.js";
7
7
  import { type ReadChart } from "./charts.js";
8
+ import { type ReadRun } from "./runs.js";
8
9
  export interface ReadCell {
9
10
  row: number;
10
11
  col: number;
@@ -22,7 +23,8 @@ export interface ReadCell {
22
23
  dynamic?: boolean;
23
24
  /** Into `looks`. */
24
25
  style: number;
25
- rich?: boolean;
26
+ /** Its rich text's runs, when its string has them. */
27
+ runs?: ReadRun[];
26
28
  }
27
29
  export interface ReadColumn {
28
30
  /** Ends included, from 0. */
@@ -60,9 +62,18 @@ export interface ReadTable {
60
62
  calculated: boolean;
61
63
  }[];
62
64
  style?: string;
65
+ /** Table Style Options, where they are not a new table's. */
66
+ options: TableOptions;
63
67
  /** Its filter buttons; nothing when it has none. */
64
68
  filter?: ReadFilter;
65
69
  }
70
+ /** Table Style Options as sheet.yaml names them, each said only when it is not Excel's default. */
71
+ export interface TableOptions {
72
+ banded_rows?: false;
73
+ banded_columns?: true;
74
+ first_column?: true;
75
+ last_column?: true;
76
+ }
66
77
  /** A Note on a cell. */
67
78
  export interface ReadNote {
68
79
  ref: string;
@@ -120,6 +131,11 @@ export interface ReadSheet {
120
131
  protect?: boolean;
121
132
  /** Page Layout. */
122
133
  print?: SheetPrint;
134
+ /** Outline settings where they are not Excel's own. */
135
+ outline?: {
136
+ summary_below?: false;
137
+ summary_right?: false;
138
+ };
123
139
  }
124
140
  export interface ReadName {
125
141
  name: string;
@@ -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 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]}}
2
+ import{ZipLimitError as Le}from"@allyhub/formats";import{SHEET_FILTER_OPERATORS as Re,SHEET_ICONS as Me,SHEET_MARGINS as ce,SHEET_OPERATORS as _e,SHEET_PAPERS as Pe,SHEET_VALIDATIONS as De}from"@allyhub/formats";import{MAX_COLUMNS as J,MAX_ROWS as Q,cellName as ee,columnLetter as te,readAddress as fe,readArea as q,readAreas as ne}from"../address.js";import{ITERATION_DEFAULTS as he}from"../calc/engine.js";import{SHEET_CHART_DEFAULTS as pe}from"../chart.js";import{moveFormula as je,relativeKey as me}from"../formula/move.js";import{parseFormula as ze}from"../formula/parse.js";import{printFormula as ge}from"../formula/print.js";import{ERR as He,errorOf as Be,serialOfDate as Ve}from"../values.js";import{OFFICE_THEME as Ue,colorOf as P,paletteOf as be,themeColors as We}from"./colors.js";import{chartAnchors as qe,readChart as Xe}from"./charts.js";import{isRangeText as Ge,readFileFormula as oe}from"./formula.js";import{BUILTIN_FORMATS as we}from"./numfmt.js";import{XmlStream as xe}from"./sax.js";import{attr as c,flag as y,numberAttr as $,readXml as ye,readXstring as E,tag as d,tags as v,textOf as O}from"./xml.js";import{RunsCollector as $e,readRuns as ve}from"./runs.js";import{ZipIn as Ze}from"./zip.js";function Je(n){if(y(n,"iterate")!==!0)return;const t=$(n,"iterateCount"),e=$(n,"iterateDelta"),o=t===void 0?void 0:Math.min(32767,Math.max(1,Math.round(t))),r=e===void 0?void 0:Math.max(0,e),s={...o===void 0||o===he.max_iterations?{}:{max_iterations:o},...r===void 0||r===he.max_change?{}:{max_change:r}};return Object.keys(s).length>0?s:!0}const ke=7,Ke=n=>Math.floor((256*n+Math.floor(128/ke))/256*ke),Qe=n=>Math.round(n*4/3),re=5;export function placesLine(n){const t=n.slice(0,re).join(", ");return n.length>re?`${t} and ${String(n.length-re)} more`:t}const X=(n,t,e=`${t}s`)=>`${String(n)} ${n===1?t:e}`;export const GRID_END=`Excel's grid ends at ${te(J-1)}${String(Q)} (${Q.toLocaleString("en-US")} rows, ${J.toLocaleString("en-US")} columns)`;function Ye(n,t){let e=0,o=0;const r=n.length;for(;e<r;e++){const i=n.charCodeAt(e),u=i>=65&&i<=90,a=i>=97&&i<=122;if(!u&&!a)break;o=o*26+(u?i-64:i-96)}if(e===0||e===r)return;let s=0;for(let i=e;i<r;i++){const u=n.charCodeAt(i);if(u<48||u>57)return;s=s*10+u-48}if(s!==0){if(e>3||o>J||s>Q)throw new Error(`${t} has a cell at ${n}, and ${GRID_END}.`);return{row:s-1,col:o-1}}}class et{zip;constructor(t,e){this.zip=new Ze(t,e)}get names(){return this.zip.names}has(t){return this.zip.has(t)}text(t){return this.zip.text(t)}bytes(t){return this.zip.bytesOf(t)}xml(t){const e=this.text(t);return e===void 0?void 0:ye(e)}stream(t,e){const o=this.zip.streamText(t,r=>{e.push(r)});return o&&e.end(),o}rels(t){const e=t.lastIndexOf("/"),o=`${t.slice(0,e+1)}_rels/${t.slice(e+1)}.rels`,r=this.xml(o);return v(d(r?.Relationships)?.Relationship).map(s=>{const i=c(s,"Type")??"",u=c(s,"Target")??"",a=c(s,"TargetMode")==="External";return{id:c(s,"Id")??"",type:i.slice(i.lastIndexOf("/")+1),target:a?u:tt(t,u),external:a}})}count(t){return this.names.filter(e=>t.test(e)).length}}function tt(n,t){if(t.startsWith("/"))return t.slice(1);const e=n.split("/").slice(0,-1);for(const o of t.split("/"))o===".."?e.pop():o!=="."&&e.push(o);return e.join("/")}function nt(n,t,e){const o=[];if(t===void 0)return o;let r,s=0,i=!1;const u={open(a,l){if(a==="si"){r={text:"",runs:new $e};return}if(r){if(s>0||a==="rPh"||a==="phoneticPr"||a==="extLst"){s+=1;return}r.runs.open(a,l)||a==="t"&&(i=!0)}},close(a){if(s>0){s-=1;return}if(a==="si"){if(r){const{runs:l}=r.runs;o.push({text:E(r.text),...l.length>0?{runs:ve(l,e)}:{}})}r=void 0;return}r?.runs.close(a),a==="t"&&(i=!1)},text(a){r&&i&&s===0&&(r.text+=a,r.runs.text(a))}};return n.stream(t,new xe(u)),o}function G(n,t){const e=n[t];if(e===void 0)return!1;const o=c(d(e),"val");return o===void 0||o!=="0"&&o!=="false"}const ot=new Set(["double","singleAccounting","doubleAccounting"]);function rt(n,t,e){const o={},r=(a,l)=>c(d(a?.[l]),"val");if(G(n,"b")&&(o.bold=!0),G(n,"i")&&(o.italic=!0),G(n,"strike")&&(o.strike=!0),G(n,"u")){const a=r(n,"u");o.underline=a!==void 0&&ot.has(a)?a:!0}const s=r(n,"name");s!==void 0&&s!==r(t,"name")&&(o.font=s);const i=r(n,"sz");i!==void 0&&i!==r(t,"sz")&&(o.size=Number(i));const u=P(d(n.color),e);return u!==void 0&&u!==P(d(t?.color),e)&&(o.color=u),o}function st(n,t){const e=d(n.patternFill),o=c(e,"patternType");if(o===void 0||o==="none")return;const r=P(d(e?.fgColor),t),s=P(d(e?.bgColor),t);return o==="solid"&&r!==void 0?r:{pattern:o,...r===void 0?{}:{color:r},...s===void 0?{}:{background:s}}}function Se(n,t){const e={};for(const o of["left","right","top","bottom"]){const r=d(n[o]),s=c(r,"style");if(s===void 0||s==="none")continue;const i=P(d(r?.color),t);e[o]={style:s,...i===void 0?{}:{color:i}}}return Object.keys(e).length===0?void 0:e}function it(n){const t={},e=c(n,"horizontal");e!==void 0&&e!=="general"&&(t.align=e);const o=c(n,"vertical");o!==void 0&&o!=="bottom"&&(t.valign=o),y(n,"wrapText")===!0&&(t.wrap=!0),y(n,"shrinkToFit")===!0&&(t.shrink=!0);const r=$(n,"indent");r!==void 0&&r>0&&(t.indent=r);const s=$(n,"textRotation");return s!==void 0&&s>0&&s<=180&&(t.rotation=s),t}function Ce(n,t){const e={},o=d(n.font);if(o){const f=(b,h)=>{o[b]!==void 0&&(e[h]=G(o,b))};f("b","bold"),f("i","italic"),f("strike","strike"),o.u!==void 0&&(e.underline=G(o,"u"));const g=P(d(o.color),t);g!==void 0&&(e.color=g)}const r=d(d(n.fill)?.patternFill),s=P(d(r?.bgColor),t)??P(d(r?.fgColor),t);s!==void 0&&(e.fill=s);const i=d(n.border),u=i&&Se(i,t);u!==void 0&&(e.border=u);const a=d(n.numFmt),l=c(a,"formatCode")??we[$(a,"numFmtId")??-1];return a&&l!==void 0&&l!==""&&l!=="General"&&(e.format=l),e}function at(n,t){const e=d(n?.styleSheet),o=be(t,e),r=new Map(v(d(e?.numFmts)?.numFmt).map(m=>[$(m,"numFmtId")??-1,c(m,"formatCode")?.replace(/^$/u,"General")??"General"])),s=v(d(e?.fonts)?.font),i=v(d(e?.fills)?.fill),u=v(d(e?.borders)?.border),a=v(d(e?.cellXfs)?.xf),l=s[$(a[0],"fontId")??0],f=new Set;i.some(m=>m.gradientFill!==void 0)&&f.add("gradient fills");const g=v(d(e?.cellStyles)?.cellStyle),b=new Set(a.map(m=>$(m,"xfId")??0)),h=g.filter(m=>$(m,"builtinId")!==0&&b.has($(m,"xfId")??-1)).map(m=>E(c(m,"name")??"")).filter(m=>m!=="");h.length>0&&f.add(`the names of cell styles (${h.slice(0,5).join(", ")}${h.length>5?", …":""}): their looks are kept`);const w=a.map(m=>{const C={},F=s[$(m,"fontId")??0];F&&(Object.assign(C,rt(F,l,o)),F.vertAlign!==void 0&&f.add("superscript and subscript"));const L=i[$(m,"fillId")??0],M=L&&st(L,o);M!==void 0&&(C.fill=M);const _=u[$(m,"borderId")??0],N=_&&Se(_,o);N!==void 0&&(C.border=N),_&&c(d(_.diagonal),"style")!==void 0&&f.add("diagonal borders");const j=d(m.alignment);j&&(Object.assign(C,it(j)),$(j,"textRotation")===255&&f.add("vertical text"));const z=d(m.protection);y(z,"locked")===!1&&(C.locked=!1),y(z,"hidden")===!0&&(C.hide_formula=!0);const D=$(m,"numFmtId")??0,H=r.get(D)??we[D];return H!==void 0&&H!=="General"&&(C.format=H),C}),S=c(d(l?.name),"val"),p=c(d(l?.sz),"val");return{looks:w,dxfs:v(d(e?.dxfs)?.dxf).map(m=>Ce(m,o)),font:{...S===void 0?{}:{name:S},...p===void 0?{}:{size:Number(p)}},lost:[...f]}}const dt=n=>{const t=Number(n);return n.trim()!==""&&Number.isFinite(t)?t:n};function lt(n,t){const e=d(n.customFilters);if(e){const i=v(e.customFilter).map(u=>({operator:c(u,"operator")??"equal",value:dt(E(c(u,"val")??""))}));return i.length===0||i.length>2||i.some(u=>!Re.includes(u.operator))?void 0:{conditions:i,...i.length===2&&y(e,"and")!==!0?{or:!0}:{}}}const o=d(n.top10);if(o){const i=$(o,"val");return i===void 0||i<=0?void 0:{top:{count:i,...y(o,"percent")===!0?{percent:!0}:{},...y(o,"top")===!1?{bottom:!0}:{}}}}const r=c(d(n.dynamicFilter),"type");if(r==="aboveAverage")return{average:"above"};if(r==="belowAverage")return{average:"below"};const s=d(n.colorFilter);if(s){const i=t[$(s,"dxfId")??-1];return y(s,"cellColor")===!1?i?.color?{color:{font:i.color}}:void 0:typeof i?.fill=="string"?{color:{fill:i.fill}}:void 0}}function Te(n,t=[]){const e=new Map;let o=0;for(const r of v(n.filterColumn)){const s=$(r,"colId")??0,i=d(r.filters);if(!i){const a=lt(r,t);a?e.set(s,a):Object.keys(r).some(l=>l!=="colId"&&l!=="hiddenButton")&&(o+=1);continue}if(i.dateGroupItem!==void 0){o+=1;continue}const u=v(i.filter).map(a=>E(c(a,"val")??""));e.set(s,{...u.length===0?{}:{values:u},...y(i,"blank")===!0?{blanks:!0}:{}})}return{columns:e,unread:o}}function ut(n,t=[]){const e=d(n?.table),o=q(c(e,"ref")??""),r=c(e,"displayName")??c(e,"name");if(!o||r===void 0)return;const s=d(e?.tableStyleInfo),i=d(e?.autoFilter);return{name:r,ref:o,headers:$(e,"headerRowCount")??1,totals:$(e,"totalsRowCount")??0,columns:v(d(e?.tableColumns)?.tableColumn).map(u=>({name:E(c(u,"name")??"").trim(),calculated:u.calculatedColumnFormula!==void 0})),style:c(s,"name")??"none",options:{...y(s,"showRowStripes")===!1?{banded_rows:!1}:{},...y(s,"showColumnStripes")===!0?{banded_columns:!0}:{},...y(s,"showFirstColumn")===!0?{first_column:!0}:{},...y(s,"showLastColumn")===!0?{last_column:!0}:{}},...i?{filter:Te(i,t)}:{}}}function se(n){const t=n.trim();if(t==="")return;const e=/^"((?:[^"]|"")*)"$/u.exec(t);if(e)return(e[1]??"").replaceAll('""','"');const o=Number(t);if(!Number.isNaN(o))return o;const r=oe(t,!0);return r.ok?ge(r.node):void 0}const Ee=n=>n!==void 0&&_e.includes(n);function ie(n){const t=c(n,"type")??"num",e=c(n,"val")??(n.f===void 0?void 0:O(n.f)),o=e===void 0?void 0:se(e);return{at:t,...o===void 0?{}:{value:o}}}const ct=Me,ft=n=>{const t=n.formula??n.f;return(Array.isArray(t)?t:t===void 0?[]:[t]).map(O)};function ht(n,t,e,o){const r=c(n,"type")??"",s={range:t,...y(n,"stopIfTrue")===!0?{stop:!0}:{}},i={...e.bold===void 0?{}:{bold:e.bold},...e.italic===void 0?{}:{italic:e.italic},...e.underline===void 0?{}:{underline:e.underline!==!1},...e.strike===void 0?{}:{strike:e.strike},...e.color===void 0?{}:{color:e.color},...typeof e.fill=="string"?{fill:e.fill}:{},...e.border===void 0?{}:{border:e.border},...e.format===void 0?{}:{format:e.format}},u=ft(n);switch(r){case"cellIs":{const a=c(n,"operator"),l=u.flatMap(f=>{const g=se(f);return g===void 0?[]:[g]});return!Ee(a)||l.length===0?`a cellIs rule of ${a??"no operator"}`:{...s,...i,type:"cellIs",operator:a,formula:l}}case"containsText":case"notContainsText":case"beginsWith":case"endsWith":{const a=c(n,"text");return a===void 0?`a ${r} rule with no text`:{...s,...i,type:"containsText",...r==="containsText"?{}:{operator:r==="notContainsText"?"notContains":r},text:E(a)}}case"duplicateValues":case"uniqueValues":return{...s,...i,type:r};case"top10":return{...s,...i,type:"top10",rank:$(n,"rank")??10,...y(n,"percent")===!0?{percent:!0}:{},...y(n,"bottom")===!0?{bottom:!0}:{}};case"aboveAverage":return $(n,"stdDev")!==void 0?"an above or below average rule by standard deviations":{...s,...i,type:"aboveAverage",...y(n,"aboveAverage")===!1?{below:!0}:{},...y(n,"equalAverage")===!0?{equal:!0}:{}};case"expression":{const a=u[0]===void 0?void 0:oe(u[0],!0);return a?.ok?{...s,...i,type:"expression",formula:ge(a.node)}:"an expression rule that cannot be read"}case"dataBar":{const a=d(n.dataBar),l=P(d(a?.color??a?.fillColor),o),[f,g]=v(a?.cfvo).map(ie);return l===void 0?"a data bar with no colour":{...s,type:"dataBar",color:l,...f&&f.at!=="min"?{min:f}:{},...g&&g.at!=="max"?{max:g}:{},...y(a,"showValue")===!1?{show:!1}:{}}}case"colorScale":{const a=d(n.colorScale),l=v(a?.cfvo).map(ie),f=v(a?.color).map(b=>P(b,o)),g=l.flatMap((b,h)=>{const w=f[h];return w===void 0?[]:[{...b,color:w}]});return g.length<2?"a colour scale with too few stops":{...s,type:"colorScale",stops:g.slice(0,3)}}case"iconSet":{const a=d(n.iconSet),l=c(a,"iconSet")??"3TrafficLights1";if(!ct.includes(l))return`the icon set ${l}`;if(a?.cfIcon!==void 0)return"an icon set of icons chosen one by one";const f=v(a?.cfvo).map(ie);return{...s,type:"iconSet",icons:l,...f.length>=3?{stops:f.slice(0,5)}:{},...y(a,"reverse")===!0?{reverse:!0}:{},...y(a,"showValue")===!1?{show:!1}:{}}}default:return`a ${r} rule`}}const Oe={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},Ae=(n,t)=>v(d(n.extLst)?.ext).find(e=>c(e,"uri")?.toUpperCase()===t.toUpperCase());function pt(n,t,e){const o=[],r=[],s=new Set,i=(a,l,f)=>{const g=ht(a,l,f,e);typeof g=="string"?r.push(`${g} on ${l}`):o.push({priority:$(a,"priority")??0,rule:g})};for(const a of v(n.conditionalFormatting)){const l=c(a,"sqref")??"";if(!ne(l)){r.push(`a rule on ${l}`);continue}for(const f of v(a.cfRule)){const g=O(d(d(f.extLst)?.ext)?.id);g!==""&&s.add(g.toUpperCase());const b=$(f,"dxfId");i(f,l,b===void 0?{}:t[b]??{})}}const u=d(Ae(n,Oe.conditional)?.conditionalFormattings);for(const a of v(u?.conditionalFormatting)){const l=O(a.sqref).trim();for(const f of v(a.cfRule)){if(s.has((c(f,"id")??"").toUpperCase())){const b=mt(d(f.dataBar));b!==void 0&&r.push(`a data bar's ${b} on ${l}`);continue}if(!ne(l)){r.push(`a rule on ${l}`);continue}const g=d(f.dxf);i(f,l,g?Ce(g,e):{})}}return{rules:o.sort((a,l)=>a.priority-l.priority).map(a=>a.rule),unread:r}}function mt(n){if(!n)return;const t=[];y(n,"gradient")===!1&&t.push("solid fill"),y(n,"border")===!0&&t.push("border");const e=c(n,"axisPosition");e!==void 0&&e!=="automatic"&&t.push(`axis ${e}`),y(n,"negativeBarColorSameAsPositive")===!0&&t.push("negative bars in its colour");const o=c(d(n.negativeFillColor),"rgb");return o!==void 0&&o.toUpperCase()!=="FFFF0000"&&t.push("negative bars' colour"),c(n,"direction")==="rightToLeft"&&t.push("right to left"),t.length===0?void 0:t.join(", ")}const gt=De;function Ne(n,t,e,o){const r=c(n,"type")??"none";if(r==="none"&&c(n,"prompt")===void 0)return;if(!gt.includes(r)||!ne(t))return`a ${r} rule on ${t}`;const s=/^"((?:[^"]|"")*)"$/u.exec(e.trim()),i=r==="list"&&s?(s[1]??"").replaceAll('""','"').split(","):void 0,u=[e,o].flatMap(w=>{const S=se(w);return S===void 0?[]:[S]}),a=c(n,"operator"),l=w=>Object.fromEntries(Object.entries(w).filter(([,S])=>S!==void 0)),f=l({title:c(n,"promptTitle"),message:c(n,"prompt")}),g=l({style:c(n,"errorStyle"),title:c(n,"errorTitle"),message:c(n,"error")}),b=y(n,"showInputMessage")!==!0,h=y(n,"showErrorMessage")!==!0;return{range:t,type:r,...Ee(a)&&a!=="between"?{operator:a}:{},...i?{values:i}:{formula:u},...y(n,"allowBlank")===!0?{}:{blank:!1},...y(n,"showDropDown")===!0?{dropdown:!1}:{},...b||Object.keys(f).length>0?{prompt:{...f,...b?{show:!1}:{}}}:{},...h||Object.keys(g).length>0?{error:{...g,...h?{show:!1}:{}}}:{}}}function bt(n){const t=[],e=[],o=s=>{typeof s=="string"?e.push(s):s&&t.push(s)};for(const s of v(d(n.dataValidations)?.dataValidation))o(Ne(s,c(s,"sqref")??"",O(s.formula1),O(s.formula2)));const r=d(Ae(n,Oe.validations)?.dataValidations);for(const s of v(r?.dataValidation))o(Ne(s,O(s.sqref).trim(),O(d(s.formula1)?.f),O(d(s.formula2)?.f)));return{rules:t,unread:e}}function wt(n){const t=/^(-?\d{4,})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?)?(?:Z|[+-]\d{2}:?\d{2})?$/u.exec(n)??/^()()()(\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/u.exec(n);if(!t)return;const e=t[1]==="",o=e?1899:Number(t[1]),r=e?12:Number(t[2]),s=e?30:Number(t[3]),i=Number(t[4]??0)*3600+Number(t[5]??0)*60+Number(t[6]??0)+Number(t[7]??0),u=new Date(Date.UTC(o,r-1,s)+i*1e3);if(Number.isNaN(u.getTime()))return;const a=Ve(u);return e?a-Math.floor(a):a}let ae;function Ie(n,t){const e=n.row-t.row,o=n.col-t.col;Object.defineProperty(n,"node",{get:()=>(ae?.cell!==n&&(ae={cell:n,node:je(t.node,e,o)}),ae.node),set:r=>{Object.defineProperty(n,"node",{value:r,writable:!0,enumerable:!0,configurable:!0})},enumerable:!0,configurable:!0}),n.key=t.key}function de(n,t,e){const o=oe(n,t,e);return o.ok?{node:o.node}:{unread:n}}function xt(n){const t=q(n.ref??""),e=l=>{if(l===void 0||l==="")return"";const f=fe(l.replaceAll("$",""));return f?`$${te(f.col)}$${String(f.row+1)}`:void 0},o=e(n.r1),r=e(n.r2);if(!t||o===void 0||o===""||r===void 0)return;const s=n.dt2D==="1"||n.dt2D==="true",i=n.dtr==="1"||n.dtr==="true",u=s?`${o},${r}`:i?`${o},`:`,${o}`,a=ze(`=TABLE(${u})`);return a.ok?{ref:t,node:a.node}:void 0}function yt(n){for(const{ref:t,node:e}of n.dataTables){const o=new Set;for(const r of n.cells)r.row<t.top||r.row>t.bottom||r.col<t.left||r.col>t.right||(r.node=e,Reflect.deleteProperty(r,"unread"),o.add(`${String(r.row)}:${String(r.col)}`));for(let r=t.top;r<=t.bottom;r++)for(let s=t.left;s<=t.right;s++)o.has(`${String(r)}:${String(s)}`)||n.cells.push({row:r,col:s,value:void 0,node:e,style:0})}}class $t{cells=[];rows=[];dataTables=[];outlined=!1;rest=[];xml;masters=new Map;above=new Map;left;strings;palette;name;isRangeName;inData=!1;row=-1;nextRow=0;nextCol=0;cell;target;buffer="";skip=0;constructor(t,e,o,r){this.strings=t,this.palette=e,this.name=o,this.isRangeName=r,this.xml=new xe(this),this.xml.capture=this.rest}open(t,e){if(!this.inData){t==="sheetData"&&(this.inData=!0,this.xml.capture=void 0);return}const o=this.cell;if(o){if(this.skip>0){this.skip+=1;return}switch(t){case"v":this.target="v",this.buffer="";return;case"f":o.f={...e,text:""},this.target="f",this.buffer="";return;case"is":o.inline={text:"",runs:new $e};return;case"t":o.inline&&(this.target="t",this.buffer="");return;case"rPh":case"phoneticPr":case"extLst":this.skip=1;return;default:o.inline?.runs.open(t,e);return}}t==="row"?this.openRow(e):t==="c"&&(this.cell={r:e.r,s:e.s,t:e.t,cm:e.cm,v:void 0,f:void 0,inline:void 0})}close(t){if(!this.inData)return;const e=this.cell;if(!e){t==="sheetData"&&(this.inData=!1,this.xml.capture=this.rest);return}if(this.skip>0){this.skip-=1;return}if(t===this.target){t==="v"?e.v=this.buffer:t==="f"&&e.f?e.f.text=this.buffer:e.inline&&(e.inline.text+=this.buffer,e.inline.runs.text(this.buffer)),this.target=void 0;return}e.inline?.runs.close(t),t==="c"&&(this.cell=void 0,this.readCell(e))}text(t){this.target!==void 0&&this.skip===0&&(this.buffer+=t)}openRow(t){const e=t.r,o=e===void 0?void 0:Number(e);if(o!==void 0&&Number.isInteger(o)&&o>Q)throw new Error(`${this.name} has a row ${e??""}, and ${GRID_END}.`);const r=o!==void 0&&Number.isInteger(o)&&o>0?o-1:this.nextRow;this.row=r,this.nextRow=r+1,this.nextCol=0;const s={row:r},i=t.ht===void 0?void 0:Number(t.ht),u=f=>f==="1"||f==="true";i!==void 0&&Number.isFinite(i)&&u(t.customHeight)&&(s.height=Qe(i)),u(t.hidden)&&(s.hidden=!0);const a=t.s===void 0?void 0:Number(t.s);a!==void 0&&a!==0&&u(t.customFormat)&&(s.style=a);const l=Number(t.outlineLevel??0);l>0&&(s.level=Math.min(7,l),this.outlined=!0),Object.keys(s).length>1&&this.rows.push(s)}value(t,e){const o=t.t??"n";if(o==="inlineStr"){const s=t.inline;if(!s)return{value:t.v===void 0?"":E(t.v)};const{runs:i}=s.runs;return{value:E(s.text),...i.length>0?{runs:ve(i,this.palette)}:{}}}const r=t.v;if(r===void 0)return{value:void 0};switch(o){case"s":{const s=this.strings[Number(r)];return s?{value:s.text,...s.runs?{runs:s.runs}:{}}:{value:""}}case"str":return{value:E(r)};case"b":return{value:r.trim()==="1"||r.trim()==="true"};case"e":return{value:Be(r.trim())??He.VALUE};case"d":return{value:wt(r.trim())??r};default:{if(r.trim()==="")return{value:void 0};const s=Number(r);if(Number.isNaN(s))throw new Error(`${e} says it holds a number and holds ${r}.`);return{value:s}}}}formula(t,e,o,r){const s=t.f;if(s===void 0)return;const i=s.t??"normal",u=s.text;if(i==="dataTable"){const h=xt(s);h?this.dataTables.push(h):r.unread=`a data table's {=TABLE(${s.r1??""})}`;return}if(i==="array"){Object.assign(r,de(u,!0,this.isRangeName));const h=q(s.ref??"");h&&(r.array=h),t.cm!==void 0&&(r.dynamic=!0);return}if(i==="shared"){const h=s.si??"";if(u!==""){const S=de(u,!1,this.isRangeName),p=S.node?me(S.node,e,o):"";this.masters.set(h,{node:S.node,unread:S.unread,row:e,col:o,key:p}),Object.assign(r,S),S.node&&(r.key=p);return}const w=this.masters.get(h);if(!w){r.unread=`a shared formula of a group that has no first cell (${h})`;return}w.node?Ie(r,{node:w.node,row:w.row,col:w.col,key:w.key}):w.unread!==void 0&&(r.unread=w.unread);return}if(u==="")return;const a=de(u,!1,this.isRangeName);if(!a.node){Object.assign(r,a);return}const l=me(a.node,e,o),f=this.left?.row===e?this.left:void 0,g=[this.above.get(o),f].find(h=>h?.key===l);g?Ie(r,g):(r.node=a.node,r.key=l);const b=g??{node:a.node,row:e,col:o,key:l};this.above.set(o,b),this.left=b}readCell(t){const e=t.r===void 0?void 0:Ye(t.r,this.name),o=e?.row??this.row,r=e?.col??this.nextCol;if(r>=J)throw new Error(`${this.name} has a cell past its last column, and ${GRID_END}.`);this.nextCol=r+1;const s=t.r??ee({row:o,col:r}),{value:i,runs:u}=this.value(t,s),a={row:o,col:r,value:i,style:t.s===void 0?0:Number(t.s)||0};u&&(a.runs=u),this.formula(t,o,r,a),this.cells.push(a)}}function vt(n,t){const e=[],o=f=>e.push(`${n}: ${f}`),r=v(d(t.hyperlinks)?.hyperlink).filter(f=>c(f,"tooltip")!==void 0);r.length>0&&o(`the tooltips of ${X(r.length,"link")} (${placesLine(r.map(f=>c(f,"ref")??""))})`),t.sortState!==void 0&&o("a sort");const s=d(t.sheetProtection);y(s,"sheet")===!0&&(c(s,"password")!==void 0||c(s,"hashValue")!==void 0)&&o("its protection's password: it is protected with none"),t.protectedRanges!==void 0&&o("protected ranges");const i=d(t.headerFooter);(i?.evenHeader!==void 0||i?.evenFooter!==void 0||i?.firstHeader!==void 0||i?.firstFooter!==void 0)&&o("its print header and footer of the first or even pages");const u=d(t.printOptions);u&&["gridLines","headings","horizontalCentered","verticalCentered"].some(f=>y(u,f)===!0)&&o("its print options (gridlines, headings, centring)"),t.oleObjects!==void 0&&o("embedded objects"),t.controls!==void 0&&o("form controls"),t.dataConsolidate!==void 0&&o("a consolidation"),t.customSheetViews!==void 0&&o("custom views"),v(d(t.sheetViews)?.sheetView).some(f=>c(d(f.pane),"state")==="split")&&o("a split, not frozen, window");const l=JSON.stringify(t.extLst??"");return l.includes("sparklineGroups")&&o("sparklines"),l.includes("slicerList")&&o("slicers"),e}function kt(n,t){const e=[],o=(s,i,u)=>{const a=n.count(s);a>0&&e.push(X(a,i,u))};n.has("xl/vbaProject.bin")&&e.push("VBA macros"),o(/^xl\/pivotTables\/pivotTable\d*\.xml$/u,"pivot table"),o(/^xl\/chartsheets\/[^/]+\.xml$/u,"chart sheet"),o(/^xl\/dialogsheets\/[^/]+\.xml$/u,"dialog sheet"),o(/^xl\/macrosheets\/[^/]+\.xml$/u,"macro sheet");const r=n.names.filter(s=>s.startsWith("xl/media/")&&!t.has(s)).length;return r>0&&e.push(X(r,"image")),o(/^xl\/embeddings\//u,"embedded object"),o(/^xl\/slicers\/[^/]+\.xml$/u,"slicer part"),o(/^xl\/timelines\/[^/]+\.xml$/u,"timeline part"),o(/^xl\/ctrlProps\/[^/]+\.xml$/u,"form control"),o(/^xl\/activeX\/[^/]+\.xml$/u,"ActiveX control"),o(/^xl\/queryTables\/[^/]+\.xml$/u,"query table"),n.has("xl/connections.xml")&&e.push("data connections"),n.names.some(s=>s.startsWith("xl/richData/"))&&e.push("rich values (data types, pictures in cells)"),n.names.some(s=>/^customXml\/item\d+\.xml$/u.test(s)&&(n.text(s)??"").includes("DataMashup"))&&e.push("Power Query queries"),e}export function readHeaderFooter(n){const t={left:"",center:"",right:""};let e="center",o=new Set;for(let r=0;r<n.length;r++){const s=n[r],i=n[r+1];if(s==="&"&&(i==="L"||i==="C"||i==="R")){e=i==="L"?"left":i==="C"?"center":"right",o=new Set([...o,e]),r+=1;continue}if(s==="&"&&i==="&"){t[e]+="&&",r+=1;continue}t[e]+=s??""}return Object.fromEntries(Object.entries(t).filter(([r,s])=>s!==""||o.has(r)))}const St=new Map(Object.entries(Pe).map(([n,t])=>[t,n]));function Ct(n,t,e){const o={},r=d(n.pageSetup),s=c(r,"orientation");(s==="portrait"||s==="landscape")&&(o.orientation=s);const i=$(r,"paperSize");if(i!==void 0){const p=St.get(i);p?o.paper=p:e.push(`${t}: its paper size, Excel's number ${String(i)}`)}y(d(d(n.sheetPr)?.pageSetUpPr),"fitToPage")===!0&&(o.fit={width:$(r,"fitToWidth")??1,height:$(r,"fitToHeight")??1});const u=$(r,"scale");u!==void 0&&u!==100&&u>=10&&u<=400&&(o.scale=Math.round(u));const a=p=>v(d(n[p])?.brk).filter(m=>y(m,"man")===!0).map(m=>$(m,"id")).filter(m=>m!==void 0&&m>0).sort((m,C)=>m-C),l=a("rowBreaks").map(p=>p+1),f=a("colBreaks").map(p=>te(p));(l.length>0||f.length>0)&&(o.breaks={...l.length>0?{rows:l}:{},...f.length>0?{cols:f}:{}});const g=d(n.pageMargins),b={};for(const p of Object.keys(ce)){const m=$(g,p);m!==void 0&&m!==ce[p]&&(b[p]=m)}Object.keys(b).length>0&&(o.margins=b);const h=d(n.headerFooter),w=O(h?.oddHeader),S=O(h?.oddFooter);return w!==""&&(o.header=readHeaderFooter(E(w))),S!==""&&(o.footer=readHeaderFooter(E(S))),o}function Tt(n,t,e,o,r){const s=n.rels(t),i=new Map;for(const a of s.filter(l=>l.type==="comments")){const l=d(n.xml(a.target)?.comments),f=d(l?.authors)?.author,g=(Array.isArray(f)?f:f===void 0?[]:[f]).map(b=>E(O(b)));for(const b of v(d(l?.commentList)?.comment)){const h=c(b,"ref")??"",w=d(b.text),S=v(w?.r),p=E(S.length>0?S.map(C=>O(C.t)).join(""):O(w?.t)),m=g[$(b,"authorId")??-1];h!==""&&p!==""&&i.set(h,{ref:h,text:p,...m===void 0||m===""?{}:{author:m}})}}let u=0;for(const a of s.filter(l=>l.type==="threadedComment")){const l=d(n.xml(a.target)?.ThreadedComments),f=new Map;for(const g of v(l?.threadedComment)){const b=c(g,"ref")??"",h=E(O(g.text)),w=f.get(b)??{texts:[]};if(w.texts.length===0){const S=o.get(c(g,"personId")??"");S!==void 0&&(w.author=S)}w.texts.push(h),f.set(b,w)}for(const[g,b]of f)u+=1,i.set(g,{ref:g,text:b.texts.join(`
3
+ `),...b.author===void 0?{}:{author:b.author}})}return u>0&&r.push(`${e}: ${X(u,"threaded comment")}, kept as notes, replies after the first line`),[...i.values()]}function Et(n,t,e,o,r,s,i,u,a,l,f){const g=new $t(r,s,e,a);if(!n.stream(t,g.xml))throw new Error(`${t} is not in the file.`);yt(g);const b=ye(g.rest.join("")),h=d(b.worksheet);if(!h)throw new Error(`${t} is not a worksheet.`);const w=v(d(h.cols)?.col).map(k=>{const T=$(k,"width"),R=$(k,"style"),V=$(k,"outlineLevel")??0,A=($(k,"min")??1)-1,le=($(k,"max")??1)-1;if(le>=J)throw new Error(`${e} sets a column past its last, and ${GRID_END}.`);const ue=y(k,"customWidth"),Y=T===void 0?void 0:Ke(T);return{min:A,max:le,...Y!==void 0&&(ue===!0||ue===void 0&&Y!==Fe)?{width:Y}:{},...y(k,"hidden")===!0?{hidden:!0}:{},...R===void 0||R===0?{}:{style:R},...V>0?{level:Math.min(7,V)}:{}}}),S=v(d(h.mergeCells)?.mergeCell).flatMap(k=>{const T=q(c(k,"ref")??"");return T?[T]:[]}),p=v(d(h.sheetViews)?.sheetView)[0],m=d(p?.pane);let C;const F=c(m,"state");if(F==="frozen"||F==="frozenSplit"){const k=fe(c(p,"topLeftCell")??"A1")??{row:0,col:0};C={row:k.row+($(m,"ySplit")??0),col:k.col+($(m,"xSplit")??0)}}const L=n.rels(t),M=L.filter(k=>k.type==="table").flatMap(k=>{const T=ut(n.xml(k.target),i);return T?[T]:[]}),_=P(d(d(h.sheetPr)?.tabColor),s),N=vt(e,h),j=pt(h,i,s),z=bt(h);for(const k of j.unread)N.push(`${e}: a conditional format, ${k}`);for(const k of z.unread)N.push(`${e}: a data validation, ${k}`);const D=d(h.autoFilter),H=q(c(D,"ref")??""),B=D&&H?{ref:H,...Te(D,i)}:void 0;B&&B.unread>0&&N.push(`${e}: ${X(B.unread,"filter")} by condition on ${c(D,"ref")??""}, its rows left as they were hidden`);const{charts:Z,pictures:K}=Nt(n,t,e,w,g.rows,N,l,f),W={},x=new Map(L.map(k=>[k.id,k]));for(const k of v(d(h.hyperlinks)?.hyperlink)){const T=c(k,"ref");if(T===void 0)continue;const R=c(k,"location"),V=c(k,"id"),A=V===void 0?void 0:x.get(V)?.target;A!==void 0?W[T]=R===void 0?A:`${A}#${R}`:R!==void 0&&(W[T]=`#${R}`)}const I=d(h.sheetProtection),U=Ct(h,e,N);return{sheet:{name:e,state:o,cells:g.cells,merges:S,...C?{freeze:C}:{},...c(p,"showGridLines")==="0"?{gridlines:!1}:{},..._===void 0?{}:{tab:_},columns:w,rows:g.rows,tables:M,conditional:j.rules,validations:z.rules,scenarios:v(d(h.scenarios)?.scenario).map(k=>({name:c(k,"name")??"",cells:v(k.inputCells).map(T=>({at:c(T,"r")??"",value:c(T,"val")??""}))})),...B?{filter:B}:{},charts:Z,links:W,notes:Tt(n,t,e,u,N),pictures:K,...y(I,"sheet")===!0?{protect:!0}:{},...Object.keys(U).length>0?{print:U}:{},...Ot(d(d(h.sheetPr)?.outlinePr))},lost:N}}function Ot(n){const t=y(n,"summaryBelow")===!1,e=y(n,"summaryRight")===!1;return t||e?{outline:{...t?{summary_below:!1}:{},...e?{summary_right:!1}:{}}}:{}}const Fe=64,At=20;function Nt(n,t,e,o,r,s,i,u){const a=h=>o.find(w=>h>=w.min&&h<=w.max)?.width??Fe,l=new Map(r.map(h=>[h.row,h.height])),f=h=>l.get(h)??At,g=[],b=[];for(const h of n.rels(t).filter(w=>w.type==="drawing")){const w=qe(n.xml(h.target),a,f),S=n.rels(h.target);for(const p of w.anchors){const m=S.find(M=>M.id===p.id),C=ee(p.at);if(p.width<=0||p.height<=0){s.push(`${e}: the chart at ${C}, of no size`);continue}const F=[],L=Xe(m?n.xml(m.target):void 0,F,u);if(typeof L=="string"){s.push(`${e}: the chart at ${C}, as ${L}`);continue}for(const M of F)s.push(`${e}: the chart at ${C} without its ${M}`);g.push({...L,at:C,...p.x===void 0?{}:{x:p.x},...p.y===void 0?{}:{y:p.y},...p.width===pe.width?{}:{width:p.width},...p.height===pe.height?{}:{height:p.height}})}for(const p of w.pictures){const m=S.find(L=>L.id===p.id),C=m&&!m.external?n.bytes(m.target):void 0;if(!m||!C){s.push(`${e}: the picture at ${ee(p.at)}, whose image is not in the file`);continue}i.add(m.target);const F=m.target.slice(m.target.lastIndexOf(".")+1).toLowerCase();b.push({row:p.at.row,col:p.at.col,...p.x===void 0?{}:{x:p.x},...p.y===void 0?{}:{y:p.y},width:p.width,height:p.height,...p.name===void 0?{}:{name:p.name},...p.descr===void 0?{}:{descr:p.descr},bytes:C,type:F})}w.others>0&&s.push(`${e}: ${X(w.others,"shape")} of its drawing`)}return{charts:g,pictures:b}}function It(n,t,e){for(const o of n){if(o.sheet===void 0)continue;const r=t[o.sheet];if(!r)continue;const s=o.text.split(",").map(i=>i.slice(i.lastIndexOf("!")+1).replaceAll("$",""));if(o.name==="_xlnm.Print_Area"){const[i]=s;s.length>1&&e.push(`${r.name}: its print area's ranges after the first`),i!==void 0&&q(i)&&(r.print={...r.print,area:i})}else if(o.name==="_xlnm.Print_Titles")for(const i of s)/^\d+:\d+$/u.test(i)?r.print={...r.print,title_rows:i}:/^[A-Za-z]+:[A-Za-z]+$/u.test(i)&&(r.print={...r.print,title_cols:i})}}export function readXlsx(n,t){let e;try{e=new et(n,t)}catch(x){throw x instanceof Le?x:new Error("It is not a zip file, as an .xlsx file is.")}const o=e.rels(""),r=o.find(x=>x.type==="officeDocument")?.target??"xl/workbook.xml";if(r.endsWith(".bin"))throw new Error("It is a binary workbook (.xlsb): save it as .xlsx.");const s=e.xml(r),i=d(s?.workbook);if(!i)throw new Error("It has no workbook part.");const u=e.rels(r),a=x=>u.find(I=>I.type===x)?.target,l=(()=>{const x=a("theme");return x===void 0?void 0:e.text(x)})(),f=l===void 0?Ue:We(l),g=a("styles"),b=g===void 0?void 0:e.xml(g),h=at(b,f),w=be(f,d(b?.styleSheet)),S=nt(e,a("sharedStrings"),w),p=[];for(const x of h.lost)p.push(x);const m=d(i.workbookPr),C=Je(d(i.calcPr));c(d(i.calcPr),"calcMode")==="manual"&&p.push("manual calculation: it computes as its cells change");const F=d(i.workbookProtection);(y(F,"lockStructure")===!0||y(F,"lockWindows")===!0)&&p.push("the workbook's protection"),i.fileSharing!==void 0&&p.push("its write protection");const L=new Map,M=a("person");if(M!==void 0)for(const x of v(d(e.xml(M)?.personList)?.person))L.set(c(x,"id")??"",E(c(x,"displayName")??""));const _=v(d(i.definedNames)?.definedName).map(x=>{const I=$(x,"localSheetId");return{name:c(x,"name")??"",text:E(O(x)),...I===void 0?{}:{sheet:I},...y(x,"hidden")===!0?{hidden:!0}:{}}}),N=[],j=new Set,z=new Map(u.map(x=>[x.id,x])),D=v(d(i.sheets)?.sheet),H=new Set(D.filter(x=>z.get(c(x,"id")??"")?.type==="worksheet").map(x=>E(c(x,"name")??"").toLowerCase()));for(const[x,I]of D.entries()){const U=z.get(c(I,"id")??""),k=E(c(I,"name")??"");if(U?.type!=="worksheet"){U?.type!=="chartsheet"&&U?.type!=="dialogsheet"&&p.push(`${k}: a sheet of a kind this cannot read`);continue}const T=new Map;for(const A of _)(A.sheet===void 0||A.sheet===x)&&(A.sheet!==void 0||!T.has(A.name.toLowerCase()))&&T.set(A.name.toLowerCase(),Ge(A.text));const R=c(I,"state"),V=Et(e,U.target,k,R==="hidden"||R==="veryHidden"?R:"visible",S,w,h.dxfs,L,A=>T.get(A.toLowerCase())===!0,j,A=>H.has(A.toLowerCase()));N[x]=V.sheet,p.push(...V.lost)}It(_,N,p);const B=o.find(x=>x.type==="core-properties")?.target,Z=B===void 0?void 0:O(d(e.xml(B)?.coreProperties)?.title).trim(),K=N.filter(x=>x!==void 0),W=new Map;return N.forEach((x,I)=>{x!==void 0&&W.set(I,K.indexOf(x))}),{sheets:K,names:_.flatMap(x=>{if(x.sheet===void 0)return[x];const I=W.get(x.sheet);return I===void 0?[]:[{...x,sheet:I}]}),looks:h.looks,dxfs:h.dxfs,date1904:y(m,"date1904")===!0,font:h.font,...Z===void 0||Z===""?{}:{title:Z},...C===void 0?{}:{iteration:C},lost:[...kt(e,j),...p]}}
@@ -0,0 +1,56 @@
1
+ import type { SheetRun } from "@allyhub/formats";
2
+ import { type Palette } from "./colors.js";
3
+ import type { XmlAttrs } from "./sax.js";
4
+ /** A run as the file says it: its text, and its font's elements by name. */
5
+ export interface RawRun {
6
+ text: string;
7
+ props: Record<string, XmlAttrs> | undefined;
8
+ }
9
+ /** A run's whole font, as the file gives it. */
10
+ export interface RunFont {
11
+ bold: boolean;
12
+ italic: boolean;
13
+ strike: boolean;
14
+ underline: NonNullable<SheetRun["underline"]>;
15
+ size: number | undefined;
16
+ color: string | undefined;
17
+ name: string | undefined;
18
+ script: SheetRun["script"];
19
+ }
20
+ /** A run read: its text, and its font when it has one. */
21
+ export interface ReadRun {
22
+ text: string;
23
+ font?: RunFont;
24
+ }
25
+ /** The runs of an `<si>` or an `<is>` as its elements stream in. */
26
+ export declare class RunsCollector {
27
+ readonly runs: RawRun[];
28
+ private inProps;
29
+ /** Whether the element was a run's: `<r>`, `<rPr>` or what is in it. */
30
+ open(name: string, attrs: XmlAttrs): boolean;
31
+ close(name: string): void;
32
+ /** A `<t>`'s text, the run's it is in. */
33
+ text(text: string): void;
34
+ }
35
+ /** The runs of a string read: their text, and each one's font. */
36
+ export declare function readRuns(raw: readonly RawRun[], p: Palette): ReadRun[];
37
+ /** What a cell's own font is, as a run's is set against it. */
38
+ export interface CellFont {
39
+ bold?: boolean | undefined;
40
+ italic?: boolean | undefined;
41
+ strike?: boolean | undefined;
42
+ underline?: SheetRun["underline"];
43
+ size?: number | undefined;
44
+ color?: string | undefined;
45
+ font?: string | undefined;
46
+ }
47
+ /**
48
+ * sheet.yaml's runs of a string: each says what its font has that the
49
+ * cell's does not. `base` is the workbook's body font, what a cell is in
50
+ * unless its look says.
51
+ */
52
+ export declare function runsOver(runs: readonly ReadRun[], cell: CellFont, base: {
53
+ name?: string | undefined;
54
+ size?: number | undefined;
55
+ }): SheetRun[];
56
+ //# sourceMappingURL=runs.d.ts.map
@@ -0,0 +1,2 @@
1
+ /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
+ import{colorOf as g}from"./colors.js";import{readXstring as z}from"./xml.js";export class RunsCollector{runs=[];inProps=!1;open(i,r){if(i==="r")return this.runs.push({text:"",props:void 0}),!0;const e=this.runs[this.runs.length-1];return i==="rPr"&&e?(e.props={},this.inProps=!0,!0):this.inProps&&e?.props?(e.props[i]=r,!0):!1}close(i){i==="rPr"&&(this.inProps=!1)}text(i){const r=this.runs[this.runs.length-1];r&&(r.text+=i)}}const a=(u,i)=>{const r=u[i];if(r===void 0)return!1;const e=r.val;return e===void 0||e!=="0"&&e!=="false"},b=new Set(["double","singleAccounting","doubleAccounting"]);export function readRuns(u,i){return u.map(({text:r,props:e})=>{const n={text:z(r)};if(!e)return n;const t=e.u,s=t?.val,o=Number(e.sz?.val),l=e.vertAlign?.val;return n.font={bold:a(e,"b"),italic:a(e,"i"),strike:a(e,"strike"),underline:t===void 0||s==="none"?!1:s!==void 0&&b.has(s)?s:!0,size:Number.isFinite(o)&&o>0?o:void 0,color:g(e.color,i),name:e.rFont?.val,script:l==="superscript"||l==="subscript"?l:void 0},n})}export function runsOver(u,i,r){return u.map(({text:e,font:n})=>{const t={text:e};if(!n)return t;const s=(h,m)=>m===(i[h]===!0)?void 0:m,o=s("bold",n.bold);o!==void 0&&(t.bold=o);const l=s("italic",n.italic);l!==void 0&&(t.italic=l);const c=i.underline??!1;n.underline===c||n.underline===!0&&c==="single"||n.underline==="single"&&c===!0||(t.underline=n.underline);const p=s("strike",n.strike);p!==void 0&&(t.strike=p);const d=n.name??r.name;d!==void 0&&d!==(i.font??r.name)&&(t.font=d);const f=n.size??r.size;return f!==void 0&&f!==(i.size??r.size)&&(t.size=f),n.color!==void 0&&n.color.toUpperCase()!==(i.color??"#000000").toUpperCase()&&(t.color=n.color),n.script!==void 0&&(t.script=n.script),t})}
@@ -1,3 +1,4 @@
1
+ import type { SheetRun } from "@allyhub/formats";
1
2
  import type { CellLook } from "../workbook.js";
2
3
  /** The body font of a workbook, whatever its cells say. */
3
4
  export declare const DEFAULT_FONT: {
@@ -10,6 +11,11 @@ export declare const DEFAULT_FONT: {
10
11
  * New Roman") is its first face.
11
12
  */
12
13
  export declare function fontName(name: string): string;
14
+ /**
15
+ * A rich string's run as `<r>`: its font whole, the cell's with the run's
16
+ * over it (`<rPr>`, whose font is `rFont`), or none when it says nothing.
17
+ */
18
+ export declare function runXml(run: SheetRun, cell: CellLook): string;
13
19
  export declare class Styles {
14
20
  private readonly fonts;
15
21
  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 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"}))}}
2
+ import{RUN_FIELDS as x,runLook as y}from"../rich.js";import{FIRST_CUSTOM as v,builtinId as F}from"./numfmt.js";import{NS as I,el as e,xstring as S}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 f=t=>`FF${t.slice(1).toUpperCase()}`;class o{items=[];index=new Map;add(n){const r=this.index.get(n);if(r!==void 0)return r;const i=this.items.length;return this.items.push(n),this.index.set(n,i),i}}function h(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:f(t.color)}),e("name",{val:fontName(t.font??DEFAULT_FONT.name)}),e("family",{val:2}),t.font===void 0?e("scheme",{val:"minor"}):"")}export function runXml(t,n){const r=`<t${/^\s|\s$|\n/u.test(t.text)?' xml:space="preserve"':""}>${S(t.text)}</t>`;if(x.every(s=>t[s]===void 0))return e("r",{},r);const i={...n,...y(t)},{underline:d}=i;return e("r",{},e("rPr",{},i.bold===!0?"<b/>":"",i.italic===!0?"<i/>":"",i.strike===!0?"<strike/>":"",d===!0||d==="single"?"<u/>":d?e("u",{val:d}):"",t.script===void 0?"":e("vertAlign",{val:t.script}),e("sz",{val:i.size??DEFAULT_FONT.size}),i.color===void 0?e("color",{theme:1}):e("color",{rgb:f(i.color)}),e("rFont",{val:fontName(i.font??DEFAULT_FONT.name)}),e("family",{val:2}),i.font===void 0?e("scheme",{val:"minor"}):""),r)}function w(t){const{pattern:n,color:r,background:i}=typeof t=="string"?{pattern:"solid",color:t,background:void 0}:t;return e("fill",{},e("patternFill",{patternType:n},r===void 0?"":e("fgColor",{rgb:f(r)}),i===void 0?n==="solid"?e("bgColor",{indexed:64}):"":e("bgColor",{rgb:f(i)})))}function u(t,n){return n?e(t,{style:n.style},n.color===void 0?e("color",{auto:1}):e("color",{rgb:f(n.color)})):e(t)}function b(t){return e("border",{},u("left",t.left),u("right",t.right),u("top",t.top),u("bottom",t.bottom),e("diagonal"))}function g(t,n="dxf",r){const{underline:i}=t,d=[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:f(t.color)})].join(""),{fill:s,border:l}=t;return e(n,{},d===""?"":e("font",{},d),t.format===void 0||r===void 0?"":e("numFmt",{numFmtId:r,formatCode:t.format}),typeof s=="string"?e("fill",{},e("patternFill",{},e("bgColor",{rgb:f(s)}))):"",l?b(l):"")}const T=t=>t<0?90-t:t;function X(t){const n={horizontal:t.align,vertical:t.valign,textRotation:t.rotation===void 0?void 0:T(t.rotation),wrapText:t.wrap===!0?!0:void 0,indent:t.indent,shrinkToFit:t.shrink===!0?!0:void 0};return Object.values(n).every(r=>r===void 0)?"":e("alignment",n)}function z(t){const n={locked:t.locked===!1?!1:void 0,hidden:t.hide_formula===!0?!0:void 0};return n.locked===void 0&&n.hidden===void 0?"":e("protection",n)}export class Styles{fonts=new o;fills=new o;borders=new o;formats=new Map;xfs=new o;byLook=new Map;dxfs=new o;constructor(){this.fonts.add(h({})),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 r=F(n);if(r!==void 0)return r;let i=this.formats.get(n);return i===void 0&&(i=v+this.formats.size,this.formats.set(n,i)),i}xf(n){const r=JSON.stringify(n),i=this.byLook.get(r);if(i!==void 0)return i;const d=this.format(n.format),s=this.fonts.add(h(n)),l=n.fill===void 0?0:this.fills.add(w(n.fill)),a=n.border===void 0?0:this.borders.add(b(n.border)),c=X(n),m=z(n),p=this.xfs.add(e("xf",{numFmtId:d,fontId:s,fillId:l,borderId:a,xfId:0,applyNumberFormat:d===0?void 0:!0,applyFont:s===0?void 0:!0,applyFill:l===0?void 0:!0,applyBorder:a===0?void 0:!0,applyAlignment:c===""?void 0:!0,applyProtection:m===""?void 0:!0},c,m));return this.byLook.set(r,p),p}dxf(n){return this.dxfs.add(g(n,"dxf",this.format(n.format)))}dxfXml(n,r){return g(n,r,this.format(n.format))}xml(){const n=(i,d)=>e(i,{count:d.length},d.join("")),r=[...this.formats].map(([i,d])=>e("numFmt",{numFmtId:d,formatCode:i}));return e("styleSheet",{xmlns:I.main},r.length>0?n("numFmts",r):"",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 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}}
2
+ import{SHEET_MARGINS as xe,SHEET_NOTE_AUTHOR as ee,SHEET_PAPERS as $e}from"@allyhub/formats";import{MAX_COLUMNS as X,MAX_ROWS as W,cellName as j,columnIndex as te,columnLetter as I,rangeName as M,readAddress as se,readArea as ye}from"../address.js";import{analyse as be}from"../calc/analyse.js";import{ITERATION_DEFAULTS as ne}from"../calc/engine.js";import{parseFormula as ve}from"../formula/parse.js";import{sheetPrefix as q}from"../formula/print.js";import{walk as oe}from"../formula/walk.js";import{fileCells as Se,isPicture as ke,pictureHeight as Ae,pictureSize as re}from"../files.js";import{scenariosByCell as Ee}from"../scenario.js";import{CellError as P,readTyped as Te}from"../values.js";import{FormulaCell as Ce,runsText as _e}from"../workbook.js";import{chartPart as Re,drawingPart as Me}from"./charts.js";import{fileFormula as V,needsArray as G}from"./formula.js";import{GRID_END as Y}from"./read.js";import{Styles as Le,runXml as je}from"./styles.js";import{THEME_XML as Fe}from"./theme.js";import{HEAD as E,NS as T,el as r,xstring as w}from"./xml.js";import{ZipOut as Ie}from"./zip.js";const C={comments:"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",worksheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",styles:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",strings:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",theme:"application/vnd.openxmlformats-officedocument.theme+xml",table:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",metadata:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",core:"application/vnd.openxmlformats-package.core-properties+xml",app:"application/vnd.openxmlformats-officedocument.extended-properties+xml"},k=`${T.rel}/`,ie="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",ae="http://schemas.microsoft.com/office/excel/2006/main",le={conditional:"{78C0D931-6437-407d-A8EE-F0AAD7539E65}",validations:"{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"},Oe=191029;export const DEFAULT_TABLE_STYLE="TableStyleMedium2",LISTS_SHEET="AllyHub lists";const De=64,Ne=7,Pe=a=>Math.min(255,Math.floor(a/Ne*256)/256),Ve=a=>Math.min(409.5,a*3/4),z=32767,ze=255,Ue=2e5,Be=r("metadata",{xmlns:T.main,"xmlns:xda":"http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray"},r("metadataTypes",{count:1},r("metadataType",{name:"XLDAPR",minSupportedVersion:12e4,copy:1,pasteAll:1,pasteValues:1,merge:1,splitFirst:1,rowColShift:1,clearFormats:1,clearComments:1,assign:1,coerce:1,cellMeta:1})),r("futureMetadata",{name:"XLDAPR",count:1},r("bk",{},r("extLst",{},r("ext",{uri:"{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}"},r("xda:dynamicArrayProperties",{fDynamic:1,fCollapsed:0}))))),r("cellMetadata",{count:1},r("bk",{},r("rc",{t:1,v:0}))));class He{index=new Map;count=0;place(t){this.count+=1;let s=this.index.get(t);return s===void 0&&(s=this.index.size,this.index.set(t,s)),s}of(t){return this.place(`t${t}`)}rich(t){return this.place(`r${t}`)}write(t){t.write(`${E}<sst xmlns="${T.main}" count="${String(this.count)}" uniqueCount="${String(this.index.size)}">`);for(const s of this.index.keys()){if(s.startsWith("r")){t.write(`<si>${s.slice(1)}</si>`);continue}const e=s.slice(1),n=/^\s|\s$|\n/u.test(e);t.write(`<si><t${n?' xml:space="preserve"':""}>${w(e)}</t></si>`)}t.write("</sst>"),t.end()}}function Xe(a){let t=!1;return a&&oe(a,s=>{(s.kind==="structured"||s.kind==="ref"&&s.sheet!==void 0)&&(t=!0)}),t}function We(a){for(const t in a)if(Object.hasOwn(a,t))return!1;return!0}const qe=a=>r("x",a).slice(2,-2),Ge="Base case";function Ye(a){const t=new Map;for(const n of a.scenarios)for(const o of n.cells)t.set(j(o),o);const s=(n,o)=>r("inputCells",{r:j(n),val:o===null||o instanceof P?"":typeof o=="boolean"?o?"1":"0":String(o)}),e=(n,o)=>r("scenario",{name:n,locked:!0,count:o.length,user:"AllyHub"},o.join(""));return r("scenarios",{current:0,show:0,sqref:[...t.keys()].join(" ")},e(Ge,[...t.values()].map(n=>s(n,n.base))),...a.scenarios.map(n=>e(n.name,n.cells.map(o=>s(o,o.value)))))}function Ze(a,t,s,e){const n=[];let o=0;for(const{row:i,col:d,paths:l,column:c}of Se(a,t)){let f=0;const h=Ae(c);for(const u of l){const m=ke(u)?s?.(u):void 0,x=m&&re(m);if(!m||!x){o+=1;continue}const b=Math.round(x.width/x.height*h);n.push({row:i,col:d,x:f,width:b,height:h,name:u.split("/").pop()??u,path:u,file:`.${x.type==="jpeg"?"jpg":x.type}`,bytes:m}),f+=b+4}}for(const i of a.spec.pictures??[]){const d=se(i.at),l=s?.(i.file),c=l&&re(l);if(!d||!l||!c)continue;const f=c.width/c.height,h=i.width??(i.height===void 0?c.width:i.height*f);n.push({row:d.row,col:d.col,x:i.x??0,y:i.y??0,width:Math.round(h),height:Math.round(i.height??h/f),name:i.file.split("/").pop()??i.file,path:i.file,file:`.${c.type==="jpeg"?"jpg":c.type}`,bytes:l})}return o>0&&e.push(`${a.name}: ${String(o)} file${o===1?"":"s"} in a cell, which stay${o===1?"s":""} a name`),n}class Je{name;columns=[];known=new Map;constructor(t){let s=LISTS_SHEET;for(let e=2;t.sheet(s);e++)s=`${LISTS_SHEET} (${String(e)})`;this.name=s}place(t){const s=JSON.stringify(t);let e=this.known.get(s);e===void 0&&(e=this.columns.length,this.columns.push(t),this.known.set(s,e));const n=I(e);return`${q(this.name)}$${n}$1:$${n}$${String(Math.max(1,t.length))}`}xml(t){const s=[],e=Math.max(0,...this.columns.map(n=>n.length));for(let n=0;n<e;n++){let o=`<row r="${String(n+1)}">`;this.columns.forEach((i,d)=>{const l=i[n];l!==void 0&&(o+=`<c r="${j({row:n,col:d})}" t="s"><v>${String(t.of(l))}</v></c>`)}),s.push(`${o}</row>`)}return`${E}<worksheet xmlns="${T.main}" xmlns:r="${T.rel}"><dimension ref="${M({top:0,left:0,bottom:Math.max(0,e-1),right:Math.max(0,this.columns.length-1)})}"/><sheetViews><sheetView workbookViewId="0"/></sheetViews><sheetFormatPr defaultRowHeight="15"/><sheetData>${s.join("")}</sheetData><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/></worksheet>`}}class Ke{rows=new Int32Array(1024);cols=new Int32Array(1024);size=0;add(t,s){if(this.size===this.rows.length){const e=new Int32Array(this.size*2);e.set(this.rows),this.rows=e;const n=new Int32Array(this.size*2);n.set(this.cols),this.cols=n}this.rows[this.size]=t,this.cols[this.size]=s,this.size+=1}byRow(){const{size:t}=this;if(t===0)return{start:new Uint32Array(1),cols:new Int32Array(0),top:0,used:void 0};let s=1/0,e=-1,n=1/0,o=-1;for(let c=0;c<t;c++){const f=this.rows[c]??0,h=this.cols[c]??0;f<s&&(s=f),f>e&&(e=f),h<n&&(n=h),h>o&&(o=h)}const i=new Uint32Array(e-s+2);for(let c=0;c<t;c++){const f=(this.rows[c]??0)-s+1;i[f]=(i[f]??0)+1}for(let c=1;c<i.length;c++)i[c]=(i[c]??0)+(i[c-1]??0);const d=i.slice(0,-1),l=new Int32Array(t);for(let c=0;c<t;c++){const f=(this.rows[c]??0)-s,h=d[f]??0;l[h]=this.cols[c]??0,d[f]=h+1}return{start:i,cols:l,top:s,used:{top:s,bottom:e,left:n,right:o}}}}function Qe(a,t){if(!a)return!1;let s=!1;const e=t.toLowerCase();return oe(a,n=>{(n.kind==="ref"||n.kind==="name")&&n.sheet!==void 0&&n.sheet.toLowerCase()!==e&&(s=!0)}),s}const et=(a,t)=>`{00000000-0000-4000-8000-${(a*65536+t).toString(16).toUpperCase().padStart(12,"0")}}`;class tt{arrays=!1;sheet;calc;styles;strings;wb;cached;left;lists;index;isTable;isRangeName;hiddenRows;tall;scenarios;drawn;newerRules=[];newerValidations=[];misgiven=new Set;shapes=new Map;groups=new Map;constructor(t,s,e,n,o,i,d,l,c=[],f){this.sheet=t,this.calc=s,this.wb=s.wb,this.styles=e,this.strings=n,this.cached=o,this.left=i,this.lists=d,this.index=l,this.isTable=u=>this.wb.table(u)!==void 0,this.isRangeName=u=>{const m=this.wb.name(u,t)?.formula?.node;return this.isTable(u)||m!==void 0&&G({kind:"unary",op:"-",arg:m})},this.hiddenRows=s.filtered(t),this.scenarios=f,this.drawn=t.charts.length>0||c.length>0;const h=new Map;for(const u of c)u.y===void 0&&h.set(u.row,Math.max(h.get(u.row)??0,u.height));this.tall=h}grid(){const{sheet:t}=this;if(t.lastRow>=W)throw new Error(`${t.name} reaches row ${(t.lastRow+1).toLocaleString("en-US")}, and ${Y}: an Excel file cannot hold it.`);if(t.columnsUsed>X)throw new Error(`${t.name} reaches past column ${I(X-1)}, and ${Y}: an Excel file cannot hold it.`);for(const s of Object.keys(t.spec.rows??{}))if(Number(s)>W)throw new Error(`${t.name} sets row ${s}, and ${Y}: an Excel file cannot hold it.`)}gather(){const{sheet:t}=this,s=new Ke;for(let e=0;e<t.columnsUsed;e++){const[n,o]=t.span(e,0,Number.MAX_SAFE_INTEGER);for(let i=n;i<=o;i++)(t.at(i,e)!==void 0||t.spillAt(i,e))&&s.add(i,e)}for(const{area:e}of t.styledAreas()){const n=(e.bottom-e.top+1)*(e.right-e.left+1);if(n>Ue){this.left.push(`${t.name}!${M(e)}: its look on the cells that hold something, ${String(n)} cells being too many to write empty`);continue}for(let o=e.top;o<=e.bottom;o++)for(let i=e.left;i<=e.right;i++)s.add(o,i)}for(const e of t.keys.keys())s.add(Math.floor(e/16384),e%16384);return s.byRow()}styleOf(t,s){const e=this.sheet.lookAt(t,s);return We(e)?void 0:this.styles.xf(e)}held(t,s){return s.length<=z?s:(this.left.push(`${this.sheet.name}!${t} past Excel's ${String(z)} characters, of its ${String(s.length)}`),s.slice(0,z))}value(t,s,e){return e===null?`<c r="${t}"${v(s)}/>`:typeof e=="number"?`<c r="${t}"${v(s)}><v>${String(e)}</v></c>`:typeof e=="boolean"?`<c r="${t}"${v(s)} t="b"><v>${e?"1":"0"}</v></c>`:e instanceof P?he(e)?`<c r="${t}"${v(s)} t="e"><v>${e.code}</v></c>`:`<c r="${t}"${v(s)} t="s"><v>${String(this.strings.of(e.code))}</v></c>`:`<c r="${t}"${v(s)} t="s"><v>${String(this.strings.of(this.held(t,e)))}</v></c>`}dataTable(t,s,e,n){const o=this.value(t,s,n),{shared:i}=e;if(e.row!==i.row||e.col!==i.col)return o;const d=i.node,l=y=>{if(y===void 0||y.kind==="missing")return null;if(!(y.kind!=="ref"||y.sheet!==void 0||!y.row||!y.col))return j({row:y.row.index,col:y.col.index})},c=d?.kind==="call"?d.args:[],f=l(c[0]),h=l(c[1]);if(f===void 0||h===void 0||f===null&&h===null)return this.left.push(`${this.sheet.name}!${t}: a data table whose inputs a file cannot hold, as its values`),o;const m=this.sheet.fills.find(y=>y.shared===i)?.area??{top:e.row,left:e.col,bottom:e.row,right:e.col},x=f!==null&&h!==null?{dt2D:!0,dtr:!0,r1:f,r2:h}:f!==null?{dtr:!0,r1:f}:{dtr:!1,r1:h??""},b=r("f",{t:"dataTable",ref:M(m),...x});return typeof n=="string"?`<c r="${t}"${v(s)} t="str">${b}<v>${w(n)}</v></c>`:o.includes("<v>")?o.replace("<v>",`${b}<v>`):o.replace("/>",`>${b}</c>`)}table(t){return this.sheet.tableAt(t.row,t.col)?.name}formula(t,s,e){const n=this.calc.value(e.sheet,e.row,e.col),{shared:o}=e,{node:i}=o;if(!i)return`<c r="${t}"${v(s)} t="e"><v>#NAME?</v></c>`;if(i.kind==="call"&&i.name==="TABLE"&&i.args.length<=2)return this.dataTable(t,s,e,n);const d=(o.analysis??=be(this.wb,o)).arguments[0];if(d!==void 0)return this.misgiven.has(o)||(this.misgiven.add(o),this.left.push(`${this.sheet.name}!${t}: a formula's value, not the formula, as ${d.name} is given ${String(d.given)} arguments`)),this.value(t,s,n);let l=this.shapes.get(o);l===void 0&&(l=G(i,this.isRangeName),this.shapes.set(o,l));const c=e.array!==void 0||e.blocked!==void 0||l;let f=c?void 0:this.groups.get(o);f?.written===!1&&(e.row!==f.ref.top||e.col!==f.ref.left)&&(f=void 0);let h,u="";if(f?.written===!0)h=`<f t="shared" si="${String(f.si)}"/>`;else{const m=V(e.moved,{table:this.table(e),isTable:this.isTable,array:c});h=f?`<f t="shared" ref="${M(f.ref)}" si="${String(f.si)}">${w(m)}</f>`:`<f>${w(m)}</f>`,f&&(f.written=!0),c&&(h=this.arrayFormula(e,m))}return c&&(this.arrays=!0,u=' cm="1"'),this.cached?n===null||typeof n=="number"?`<c r="${t}"${v(s)}${u}>${h}<v>${String(n??0)}</v></c>`:typeof n=="boolean"?`<c r="${t}"${v(s)} t="b"${u}>${h}<v>${n?"1":"0"}</v></c>`:n instanceof P?he(n)?`<c r="${t}"${v(s)} t="e"${u}>${h}<v>${n.code}</v></c>`:n.code==="#CYCLE!"?`<c r="${t}"${v(s)}${u}>${h}<v>0</v></c>`:`<c r="${t}"${v(s)} t="e"${u}>${h}<v>#VALUE!</v></c>`:`<c r="${t}"${v(s)} t="str"${u}>${h}<v>${w(this.held(t,n))}</v></c>`:`<c r="${t}"${v(s)}${u}>${h}</c>`}arrayFormula(t,s){const e=t.spill??{top:t.row,left:t.col,bottom:t.row,right:t.col};return`<f t="array" ref="${M(e)}">${w(s)}</f>`}shareFormulas(){const t=new Map;for(const e of this.sheet.formulas){const n=t.get(e.shared);if(!n)t.set(e.shared,{area:{top:e.row,bottom:e.row,left:e.col,right:e.col},first:e,n:1});else{const{area:o}=n;e.row<o.top&&(o.top=e.row),e.row>o.bottom&&(o.bottom=e.row),e.col<o.left&&(o.left=e.col),e.col>o.right&&(o.right=e.col),(e.row<n.first.row||e.row===n.first.row&&e.col<n.first.col)&&(n.first=e),n.n+=1}}let s=0;for(const[e,{area:n,first:o,n:i}]of t)i>1&&o.row===n.top&&o.col===n.left&&!Xe(e.node)&&(this.groups.set(e,{si:s,ref:n,written:!1}),s+=1)}cell(t,s){const e=j({row:t,col:s}),n=this.styleOf(t,s),o=this.sheet.at(t,s);if(o instanceof Ce)return this.formula(e,n,o);const i=typeof o=="string"?this.sheet.runsAt(t,s):void 0;if(i&&_e(i).length<=z){const d=this.sheet.lookAt(t,s);return`<c r="${e}"${v(n)} t="s"><v>${String(this.strings.rich(i.map(l=>je(l,d)).join("")))}</v></c>`}return o===void 0&&this.cached&&this.sheet.spillAt(t,s)?this.value(e,n,this.calc.value(this.sheet,t,s)):this.value(e,n,o??null)}columns(){const{sheet:t}=this,{spec:s}=t,e=new Map,n=new Map;for(const l of t.tables)for(const c of l.columns)c.spec?.width!==void 0&&n.set(l.at.col+c.index,c.spec.width);const o=new Set(n.keys()),i=new Map;for(const[l,c]of Object.entries(s.columns??{})){const f=te(l);f!==void 0&&(i.set(f,c),o.add(f))}for(const l of[...i.keys()])for(const c of[-1,1])l+c>=0&&this.collapsedColumn(l+c)&&o.add(l+c);for(const l of o){const c=i.get(l),f=c?.width??n.get(l),h=ue(c);e.set(l,r("col",{min:l+1,max:l+1,width:Pe(f??De),style:h===void 0?void 0:this.styles.xf(h),hidden:c?.hidden===!0?!0:void 0,customWidth:f===void 0?void 0:!0,outlineLevel:c?.level,collapsed:this.collapsedColumn(l)?!0:void 0}))}const d=[...e.keys()].sort((l,c)=>l-c).map(l=>e.get(l)??"");return d.length===0?"":`<cols>${d.join("")}</cols>`}rowAttrs(t){const s=this.sheet.spec.rows?.[String(t+1)],e=ue(s),n=s?.height??this.tall.get(t);return qe({r:t+1,s:e===void 0?void 0:this.styles.xf(e),customFormat:e===void 0?void 0:!0,ht:n===void 0?void 0:Ve(n),customHeight:n===void 0?void 0:!0,hidden:s?.hidden===!0||this.hiddenRows.has(t)?!0:void 0,outlineLevel:s?.level,collapsed:this.collapsedRow(t)?!0:void 0})}collapsedRow(t){const s=this.sheet.spec.rows??{},e=d=>s[String(d+1)]?.level??0,n=d=>s[String(d+1)]?.hidden===!0||this.hiddenRows.has(d),o=this.sheet.spec.outline?.summary_below===!1?1:-1,i=t+o;return i>=0&&e(i)>e(t)&&n(i)}collapsedColumn(t){const s=this.sheet.spec.columns??{},e=i=>s[I(i)],n=this.sheet.spec.outline?.summary_right===!1?1:-1,o=t+n;return o>=0&&(e(o)?.level??0)>(e(t)?.level??0)&&e(o)?.hidden===!0}rows(t,s){const{sheet:e}=this,n=new Set(this.hiddenRows);for(const f of Object.keys(e.spec.rows??{})){const h=Number(f)-1;n.add(h);for(const u of[-1,1])h+u>=0&&this.collapsedRow(h+u)&&n.add(h+u)}const{start:o,cols:i,top:d}=s;let l=s.used?d:1/0,c=s.used?s.used.bottom:-1;for(const f of n)f<l&&(l=f),f>c&&(c=f);for(let f=Math.max(0,l);f<=c;f++){const h=f-d,u=h>=0&&h<o.length-1?o[h]??0:0,m=h>=0&&h<o.length-1?o[h+1]??0:0;if(u===m&&!n.has(f))continue;if(u===m){t.write(`<row${this.rowAttrs(f)}/>`);continue}const x=i.subarray(u,m).sort();let b=`<row${this.rowAttrs(f)}>`,y=-1;for(const R of x)R!==y&&(y=R,b+=this.cell(f,R));t.write(`${b}</row>`)}}view(t){const{freeze:s}=this.sheet;let e="";if(s&&(s.row>0||s.col>0)){const n=s.row>0&&s.col>0?"bottomRight":s.row>0?"bottomLeft":"topRight";e=r("pane",{xSplit:s.col>0?s.col:void 0,ySplit:s.row>0?s.row:void 0,topLeftCell:j(s),activePane:n,state:"frozen"})}return r("sheetViews",{},r("sheetView",{showGridLines:this.sheet.spec.gridlines===!1?!1:void 0,tabSelected:t?!0:void 0,workbookViewId:0},e))}write(t,s,e){const{sheet:n}=this;this.grid();const o=this.gather();this.shareFormulas();const i=n.tables.map((A,S)=>r("tablePart",{"r:id":`rId${String(S+1)}`})),{print:d}=n.spec,l=d?.fit,c=Object.keys(n.spec.notes??{}).length>0,f=n.spec.outline,h=f?.summary_below===!1||f?.summary_right===!1?r("outlinePr",{summaryBelow:f.summary_below===!1?!1:void 0,summaryRight:f.summary_right===!1?!1:void 0}):"";t.write(`${E}<worksheet xmlns="${T.main}" xmlns:r="${T.rel}">`+(n.spec.tab===void 0&&l===void 0&&h===""?"":r("sheetPr",{},n.spec.tab===void 0?"":r("tabColor",{rgb:`FF${n.spec.tab.slice(1).toUpperCase()}`}),h,l===void 0?"":r("pageSetUpPr",{fitToPage:!0})))+r("dimension",{ref:o.used?M(o.used):"A1"})+this.view(s)+r("sheetFormatPr",{defaultRowHeight:15,outlineLevelRow:ce(n.spec.rows),outlineLevelCol:ce(n.spec.columns)})+this.columns()+"<sheetData>"),this.rows(t,o);const u=i.length+1+(this.drawn?1:0)+(c?2:0);let m=0;const x=Object.entries(n.spec.links??{}).map(([A,S])=>S.startsWith("#")?r("hyperlink",{ref:A,location:S.slice(1)}):r("hyperlink",{ref:A,"r:id":`rId${String(u+m++)}`})),b=n.merges.map(A=>r("mergeCell",{ref:M(A)})),y=n.conditions.map((A,S)=>this.condition(A,S+1)).join(""),R=this.validations();return t.write("</sheetData>"+(n.spec.protect===!0?r("sheetProtection",{sheet:!0,objects:!0,scenarios:!0}):"")+(this.scenarios?Ye(this.scenarios):"")+this.sheetFilter()+(b.length>0?r("mergeCells",{count:b.length},b.join("")):"")+y+R+(x.length>0?r("hyperlinks",{},x.join("")):"")+r("pageMargins",{...xe,...d?.margins})+(d?.orientation!==void 0||d?.paper!==void 0||d?.scale!==void 0||l!==void 0?r("pageSetup",{paperSize:d?.paper===void 0?void 0:$e[d.paper],scale:d?.scale,fitToWidth:l?.width,fitToHeight:l?.height,orientation:d?.orientation}):"")+(d?.header||d?.footer?r("headerFooter",{},d.header?r("oddHeader",{},w(de(d.header))):"",d.footer?r("oddFooter",{},w(de(d.footer))):""):"")+ut(d?.breaks)+(this.drawn?r("drawing",{"r:id":`rId${String(i.length+1)}`}):"")+(c?r("legacyDrawing",{"r:id":`rId${String(i.length+(this.drawn?2:1))}`}):"")+(i.length>0?r("tableParts",{count:i.length},i.join("")):"")+this.extensions()+"</worksheet>"),t.end(),n.tables.map((A,S)=>this.tableXml(A,e+S))}extensions(){const t=[];return this.newerRules.length>0&&t.push(r("ext",{uri:le.conditional,"xmlns:x14":ie},r("x14:conditionalFormattings",{},this.newerRules.join("")))),this.newerValidations.length>0&&t.push(r("ext",{uri:le.validations,"xmlns:x14":ie},r("x14:dataValidations",{count:this.newerValidations.length,"xmlns:xm":ae},this.newerValidations.join("")))),t.length===0?"":r("extLst",{},t.join(""))}bound(t){if(t===void 0)return"";if(typeof t=="number")return String(t);if(!t.startsWith("=")){const e=Te(t);return typeof e.value=="number"&&e.formula===void 0?String(e.value):`"${t.replaceAll('"','""')}"`}const s=ve(t);return s.ok?V(s.node,{isTable:this.isTable,array:!0}):t.slice(1)}cfvo(t,s){const e=t.value===void 0?void 0:typeof t.value=="number"?String(t.value):this.bound(t.value);return s?r("x14:cfvo",{type:t.at},e===void 0?"":r("xm:f",{},w(e))):r("cfvo",{type:t.at,val:e})}crosses(t){return t.some(s=>Qe(s?.node,this.sheet.name))}condition(t,s){const{spec:e}=t,n=e.range,o=e.type!=="dataBar"&&this.crosses(t.formulas),i=(h,u,...m)=>{if(!o){const x=Object.keys(u).length===0?void 0:this.styles.dxf(u);return r("conditionalFormatting",{sqref:n},r("cfRule",{...h,dxfId:x,priority:s,stopIfTrue:e.stop===!0?!0:void 0},...m))}return this.newerRules.push(r("x14:conditionalFormatting",{"xmlns:xm":ae},r("x14:cfRule",{...h,priority:s,stopIfTrue:e.stop===!0?!0:void 0,id:et(this.index,s)},...m.map(x=>x.replace(/^<formula>(.*)<\/formula>$/su,"<xm:f>$1</xm:f>")),Object.keys(u).length===0?"":this.styles.dxfXml(u,"x14:dxf")),r("xm:sqref",{},n))),""},d=rt(e),l=t.areas[0],c=l?j({row:l.top,col:l.left}):"A1",f=h=>r("formula",{},w(h));switch(e.type){case"cellIs":return i({type:"cellIs",operator:e.operator},d,...e.formula.map(h=>f(this.bound(h))));case"containsText":{const h=e.operator??"contains",u=`"${e.text.replaceAll('"','""')}"`,m=h==="contains"?`NOT(ISERROR(SEARCH(${u},${c})))`:h==="notContains"?`ISERROR(SEARCH(${u},${c}))`:h==="beginsWith"?`LEFT(${c},LEN(${u}))=${u}`:`RIGHT(${c},LEN(${u}))=${u}`;return i({type:h==="contains"?"containsText":h==="notContains"?"notContainsText":h,operator:h==="contains"?"containsText":h,text:e.text},d,f(m))}case"duplicateValues":case"uniqueValues":return i({type:e.type},d);case"top10":return i({type:"top10",percent:e.percent===!0?!0:void 0,bottom:e.bottom===!0?!0:void 0,rank:e.rank},d);case"aboveAverage":return i({type:"aboveAverage",aboveAverage:e.below===!0?!1:void 0,equalAverage:e.equal===!0?!0:void 0},d);case"expression":return i({type:"expression"},d,f(this.bound(e.formula.startsWith("=")?e.formula:`=${e.formula}`)));case"dataBar":return i({type:"dataBar"},{},r("dataBar",{showValue:e.show===!1?!1:void 0},this.cfvo(e.min??{at:"min"},!1),this.cfvo(e.max??{at:"max"},!1),r("color",{rgb:fe(e.color)})));case"colorScale":{const h=o?"x14:":"";return i({type:"colorScale"},{},r(`${h}colorScale`,{},...e.stops.map(u=>this.cfvo(u,o)),...e.stops.map(u=>r(`${h}color`,{rgb:fe(u.color)}))))}case"iconSet":{const h=Number.parseInt(e.icons,10),u=e.stops??Array.from({length:h},(m,x)=>({at:"percent",value:Math.round(x*100/h)}));return i({type:"iconSet"},{},r(o?"x14:iconSet":"iconSet",{iconSet:e.icons,showValue:e.show===!1?!1:void 0,reverse:e.reverse===!0?!0:void 0},...u.map(m=>this.cfvo(m,o))))}}}validation(t){const{spec:s}=t;let e="",n=this.crosses(t.formulas);if(s.values){const c=s.values.join(",");c.length>ze||s.values.some(f=>f.includes(",")||f.includes('"'))?(e=this.lists.place(s.values),n=!0):e=`"${c}"`}else e=this.bound(s.formula?.[0]);const o=this.bound(s.formula?.[1]),{error:i,prompt:d}=s;s.multiple===!0&&this.left.push(`${this.sheet.name}!${s.range}: several choices in a cell: its text stays, and Excel's list offers one at a time`);const l={type:s.type,errorStyle:i?.style===void 0||i.style==="stop"?void 0:i.style,operator:s.operator===void 0||s.operator==="between"?void 0:s.operator,allowBlank:s.blank===!1?void 0:!0,showDropDown:s.dropdown===!1?!0:void 0,showInputMessage:d?.show===!1?void 0:!0,showErrorMessage:i?.show===!1||s.multiple===!0?void 0:!0,errorTitle:i?.title,error:i?.message,promptTitle:d?.title,prompt:d?.message};return n?(this.newerValidations.push(r("x14:dataValidation",l,e===""?"":r("x14:formula1",{},r("xm:f",{},w(e))),o===""?"":r("x14:formula2",{},r("xm:f",{},w(o))),r("xm:sqref",{},s.range))),""):r("dataValidation",{...l,sqref:s.range},e===""?"":r("formula1",{},w(e)),o===""?"":r("formula2",{},w(o)))}validations(){const t=this.sheet.validations.map(s=>this.validation(s)).filter(s=>s!=="");return t.length===0?"":r("dataValidations",{count:t.length},t.join(""))}filterColumns(t){return[...t.columns.entries()].sort(([s],[e])=>s-e).map(([s,e])=>it(s-t.area.left,e,n=>this.styles.dxf(n)))}sheetFilter(){const t=this.sheet.filters.find(s=>!s.table);return t?r("autoFilter",{ref:M(t.area)},...this.filterColumns(t)):""}columnFormula(t,s){if(!s?.node)return"";const e=G(s.node,this.isRangeName),n=V(s.node,{table:t.name,isTable:this.isTable,array:e});return r("calculatedColumnFormula",{array:e?!0:void 0},w(n))}tableXml(t,s){const e=t.area,n=M({...e,bottom:Math.max(e.bottom,e.top+1)}),o=t.spec.style??DEFAULT_TABLE_STYLE,i=this.sheet.filters.find(d=>d.table===t);return E+r("table",{xmlns:T.main,id:s,name:t.name,displayName:t.name,ref:n,totalsRowShown:0},i?r("autoFilter",{ref:n},...this.filterColumns(i)):"",r("tableColumns",{count:t.columns.length},t.columns.map((d,l)=>r("tableColumn",{id:l+1,name:d.name},this.columnFormula(t,d.formula))).join("")),r("tableStyleInfo",{name:o==="none"?void 0:o,showFirstColumn:t.spec.first_column===!0,showLastColumn:t.spec.last_column===!0,showRowStripes:t.spec.banded_rows!==!1,showColumnStripes:t.spec.banded_columns===!0}))}}const ce=a=>{let t;for(const s of Object.values(a??{}))s.level!==void 0&&(t=Math.max(t??0,s.level));return t},de=a=>[a.left===void 0?"":`&L${a.left}`,a.center===void 0?"":`&C${a.center}`,a.right===void 0?"":`&R${a.right}`].join(""),st=a=>typeof a=="string"?{text:a,author:ee}:{text:a.text,author:a.author??ee};function nt(a){const t=a.map(([e,n])=>({ref:e,...st(n)})),s=[...new Set(t.map(e=>e.author))];return E+r("comments",{xmlns:T.main},r("authors",{},s.map(e=>r("author",{},w(e))).join("")),r("commentList",{},t.map(e=>r("comment",{ref:e.ref,authorId:s.indexOf(e.author)},r("text",{},r("r",{},r("t",/^\s|\s$|\n/u.test(e.text)?{"xml:space":"preserve"}:{},w(e.text)))))).join("")))}function ot(a){return`<xml xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"><o:shapelayout v:ext="edit"><o:idmap v:ext="edit" data="1"/></o:shapelayout><v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe"><v:stroke joinstyle="miter"/><v:path gradientshapeok="t" o:connecttype="rect"/></v:shapetype>${a.flatMap(([s],e)=>{const n=se(s);return n?[`<v:shape id="_x0000_s${String(1025+e)}" type="#_x0000_t202" style="position:absolute;margin-left:80pt;margin-top:5pt;width:120pt;height:60pt;z-index:${String(e+1)};visibility:hidden" fillcolor="#ffffe1" o:insetmode="auto"><v:fill color2="#ffffe1"/><v:shadow on="t" color="black" obscured="t"/><v:path o:connecttype="none"/><v:textbox style="mso-direction-alt:auto"><div style="text-align:left"></div></v:textbox><x:ClientData ObjectType="Note"><x:MoveWithCells/><x:SizeWithCells/><x:Anchor>${String(n.col+1)}, 15, ${String(n.row)}, 2, ${String(n.col+3)}, 15, ${String(n.row+4)}, 4</x:Anchor><x:AutoFill>False</x:AutoFill><x:Row>${String(n.row)}</x:Row><x:Column>${String(n.col)}</x:Column></x:ClientData></v:shape>`]:[]}).join("")}</xml>`}const fe=a=>`FF${a.slice(1).toUpperCase()}`;function rt(a){if(a.type==="dataBar"||a.type==="colorScale"||a.type==="iconSet")return{};const t={};for(const s of["bold","italic","underline","strike","color","fill","border","format"])a[s]!==void 0&&(t[s]=a[s]);return t}function it(a,t,s){const e=t.values!==void 0||t.blanks!==void 0,{conditions:n,top:o,average:i,color:d}=t,l=e?r("filters",{blank:t.blanks===!0?!0:void 0},(t.values??[]).map(c=>r("filter",{val:c})).join("")):n?r("customFilters",{and:n.length===2&&t.or!==!0?!0:void 0},n.map(c=>r("customFilter",{operator:c.operator==="equal"?void 0:c.operator,val:String(c.value)})).join("")):o?r("top10",{top:o.bottom===!0?!1:void 0,percent:o.percent===!0?!0:void 0,val:o.count}):i?r("dynamicFilter",{type:i==="above"?"aboveAverage":"belowAverage"}):d?.fill!==void 0?r("colorFilter",{dxfId:s({fill:d.fill})}):d?.font!==void 0?r("colorFilter",{dxfId:s({color:d.font}),cellColor:!1}):"";return r("filterColumn",{colId:a},l)}const v=a=>a===void 0?"":` s="${String(a)}"`,at=new Set(["#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#GETTING_DATA"]),he=a=>at.has(a.code),lt=new Set(["width","height","hidden"]);function ue(a){if(!a)return;const t=Object.fromEntries(Object.entries(a).filter(([s])=>!lt.has(s)));return Object.keys(t).length===0?void 0:t}const U=a=>E+r("Relationships",{xmlns:T.pkg},a.map(([t,s,e],n)=>r("Relationship",{Id:`rId${String(n+1)}`,Type:t,Target:s,TargetMode:e})).join(""));function ct(a,t){const s=t.formula?.node;if(s)return V(s,{isTable:n=>a.table(n)!==void 0,array:!0});const{value:e}=t;return e==null?'""':typeof e=="string"?`"${e.replaceAll('"','""')}"`:typeof e=="boolean"?e?"TRUE":"FALSE":e instanceof P?e.code:String(e)}const dt=(a,t)=>a.length===t.length&&a.every((s,e)=>s===t[e]),me=a=>`$${I(a.left)}$${String(a.top+1)}:$${I(a.right)}$${String(a.bottom+1)}`;function ft(a){const t=[],s=(e,n)=>r("definedName",{name:e.name,localSheetId:n,hidden:e.hidden===!0?!0:void 0},w(ct(a,e)));for(const e of a.names.values())t.push(s(e));return a.sheets.forEach((e,n)=>{for(const f of e.names.values())t.push(s(f,n));const o=e.filters.find(f=>!f.table);o&&t.push(r("definedName",{name:"_xlnm._FilterDatabase",localSheetId:n,hidden:!0},w(`${q(e.name)}${me(o.area)}`)));const i=q(e.name),d=e.spec.print,l=d?.area===void 0?void 0:ye(d.area);l&&t.push(r("definedName",{name:"_xlnm.Print_Area",localSheetId:n},w(`${i}${me(l)}`)));const c=[d?.title_cols?.toUpperCase().replace(/([A-Z]+):([A-Z]+)/u,"$$$1:$$$2"),d?.title_rows?.replace(/(\d+):(\d+)/u,"$$$1:$$$2")].flatMap(f=>f===void 0?[]:[`${i}${f}`]);c.length>0&&t.push(r("definedName",{name:"_xlnm.Print_Titles",localSheetId:n},w(c.join(","))))}),t}function ht(a){if(a===void 0)return{};const t=a===!0?{}:a;return{iterate:!0,iterateCount:t.max_iterations??ne.max_iterations,iterateDelta:t.max_change??ne.max_change}}export function writeXlsx(a,t={}){const s=a.wb,e=[];s.checks.length>0&&e.push(`${String(s.checks.length)} check${s.checks.length===1?"":"s"}: a file has no such thing`);const n=Ee(a);e.push(...n.left);const o=new Le,i=new He,d=new Je(s),l=new Ie,c=[["/xl/workbook.xml",C.sheet]],f=Math.max(0,s.sheets.findIndex(p=>p.spec.hidden!==!0));let h=1,u=!1;const m=new Map;let x=0,b=0,y=0;for(const[p,g]of s.sheets.entries()){const B=String(p+1),O=Ze(g,a,t.file,e),D=g.charts.filter(({spec:$})=>[$.categories,...$.series.flatMap(_=>[_.values,_.x])].some(_=>_?.endsWith("#"))).length;D>0&&e.push(`${g.name}: ${String(D)} chart${D===1?"":"s"} on a spill: ${D===1?"it reads":"they read"} the cells the spill covers now, and will not grow with it`);const K=new tt(g,a,o,i,t.cached!==!1,e,d,p,O,n.sheets.find($=>$.sheet===g)),ge=K.write(l.part(`xl/worksheets/sheet${B}.xml`),p===f,h);u||=K.arrays,c.push([`/xl/worksheets/sheet${B}.xml`,C.worksheet]);const L=[];for(const $ of ge){const _=`table${String(h)}.xml`;h+=1,l.add(`xl/tables/${_}`,$),c.push([`/xl/tables/${_}`,C.table]),L.push([`${k}table`,`../tables/${_}`])}if(g.charts.length>0||O.length>0){x+=1;const $=`drawing${String(x)}.xml`;l.add(`xl/drawings/${$}`,Me(g.charts,O)),c.push([`/xl/drawings/${$}`,C.drawing]),L.push([`${k}drawing`,`../drawings/${$}`]);const _=g.charts.map(F=>{b+=1;const N=`chart${String(b)}.xml`;return l.add(`xl/charts/${N}`,Re(a,g,F)),c.push([`/xl/charts/${N}`,C.chart]),[`${k}chart`,`../charts/${N}`]});for(const F of O){const Q=[...m].find(([,we])=>dt(we,F.bytes))?.[0]??`image${String(m.size+1)}${F.file}`;m.set(Q,F.bytes),_.push([`${k}image`,`../media/${Q}`])}l.add(`xl/drawings/_rels/${$}.rels`,U(_))}const H=Object.entries(g.spec.notes??{});if(H.length>0){y+=1;const $=String(y);l.add(`xl/comments${$}.xml`,nt(H)),c.push([`/xl/comments${$}.xml`,C.comments]),l.add(`xl/drawings/vmlDrawing${$}.vml`,ot(H)),L.push([`${k}vmlDrawing`,`../drawings/vmlDrawing${$}.vml`]),L.push([`${k}comments`,`../comments${$}.xml`])}for(const $ of Object.values(g.spec.links??{}))$.startsWith("#")||L.push([`${k}hyperlink`,$,"External"]);L.length>0&&l.add(`xl/worksheets/_rels/sheet${B}.xml.rels`,U(L))}const R=s.sheets.length,A=d.columns.length>0;if(A){const p=`xl/worksheets/sheet${String(R+1)}.xml`;l.add(p,d.xml(i)),c.push([`/${p}`,C.worksheet])}const S=[...s.sheets,...A?[void 0]:[]].map((p,g)=>[`${k}worksheet`,`worksheets/sheet${String(g+1)}.xml`]);S.push([`${k}theme`,"theme/theme1.xml"]),S.push([`${k}styles`,"styles.xml"]),S.push([`${k}sharedStrings`,"sharedStrings.xml"]),u&&(S.push([`${k}sheetMetadata`,"metadata.xml"]),c.push(["/xl/metadata.xml",C.metadata]));const Z=ft(s),J=s.sheets.map((p,g)=>r("sheet",{name:p.name,sheetId:g+1,state:p.spec.hidden===!0?"hidden":void 0,"r:id":`rId${String(g+1)}`}));A&&J.push(r("sheet",{name:d.name,sheetId:R+1,state:"veryHidden","r:id":`rId${String(R+1)}`})),l.add("xl/workbook.xml",E+r("workbook",{xmlns:T.main,"xmlns:r":T.rel},r("workbookPr",{}),r("bookViews",{},r("workbookView",{activeTab:f===0?void 0:f})),r("sheets",{},J.join("")),Z.length>0?r("definedNames",{},Z.join("")):"",r("calcPr",{calcId:Oe,fullCalcOnLoad:!0,...ht(s.file.iteration)}))),l.add("xl/_rels/workbook.xml.rels",U(S)),l.add("xl/styles.xml",E+o.xml()),i.write(l.part("xl/sharedStrings.xml")),l.add("xl/theme/theme1.xml",E+Fe),u&&l.add("xl/metadata.xml",E+Be),l.add("docProps/core.xml",E+r("cp:coreProperties",{"xmlns:cp":"http://schemas.openxmlformats.org/package/2006/metadata/core-properties","xmlns:dc":"http://purl.org/dc/elements/1.1/"},s.title===void 0?"":r("dc:title",{},w(s.title)))),l.add("docProps/app.xml",E+r("Properties",{xmlns:"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"},r("Application",{},"AllyHub"))),l.add("_rels/.rels",U([[`${k}officeDocument`,"xl/workbook.xml"],["http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties","docProps/core.xml"],[`${k}extended-properties`,"docProps/app.xml"]])),c.push(["/xl/styles.xml",C.styles],["/xl/sharedStrings.xml",C.strings],["/xl/theme/theme1.xml",C.theme],["/docProps/core.xml",C.core],["/docProps/app.xml",C.app]);const pe=[...m].sort(([p],[g])=>p.localeCompare(g));for(const[p,g]of pe)l.add(`xl/media/${p}`,g);return l.add("[Content_Types].xml",E+r("Types",{xmlns:T.types},r("Default",{Extension:"rels",ContentType:"application/vnd.openxmlformats-package.relationships+xml"}),r("Default",{Extension:"xml",ContentType:"application/xml"}),y>0?r("Default",{Extension:"vml",ContentType:"application/vnd.openxmlformats-officedocument.vmlDrawing"}):"",[...new Set([...m.keys()].map(p=>p.split(".").pop()??""))].sort().map(p=>r("Default",{Extension:p,ContentType:`image/${p==="jpg"?"jpeg":p}`})).join(""),c.map(([p,g])=>r("Override",{PartName:p,ContentType:g})).join(""))),{bytes:l.finish(),left:e}}function ut(a){const t=(n,o,i)=>o.length===0?"":r(n,{count:o.length,manualBreakCount:o.length},o.map(d=>r("brk",{id:d,max:i,man:!0})).join("")),s=[...new Set(a?.rows??[])].sort((n,o)=>n-o).map(n=>n-1),e=[...new Set((a?.cols??[]).map(n=>te(n.toUpperCase())).filter(n=>n!==void 0&&n>0))].sort((n,o)=>n-o);return t("rowBreaks",s,X-1)+t("colBreaks",e,W-1)}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allyhub/sheet",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {