@8sheets/data-grid 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/README.md +1 -1
  2. package/a11y/cell-alt-text.js +1 -1
  3. package/api/serialize.js +1 -1
  4. package/api/style-refs.js +1 -1
  5. package/calc/adjust.js +1 -1
  6. package/calc/compile.js +1 -1
  7. package/calc/engine.js +1 -1
  8. package/calc/functions/array.js +1 -1
  9. package/calc/functions/database.js +1 -1
  10. package/calc/functions/date.js +1 -1
  11. package/calc/functions/engineering.js +1 -1
  12. package/calc/functions/financial.js +1 -1
  13. package/calc/functions/helpers.js +1 -1
  14. package/calc/functions/index.js +3 -2
  15. package/calc/functions/info.js +1 -1
  16. package/calc/functions/logical.js +1 -1
  17. package/calc/functions/lookup.js +1 -1
  18. package/calc/functions/math.js +1 -1
  19. package/calc/functions/stat.js +1 -1
  20. package/calc/functions/text.js +1 -1
  21. package/calc/parser.js +2 -2
  22. package/calc/shown-refs.js +1 -0
  23. package/calc/values.js +1 -1
  24. package/calcx/calc-control.js +1 -0
  25. package/calcx/external-read.js +1 -1
  26. package/calcx/external.js +1 -1
  27. package/calcx/lang/convert.js +1 -1
  28. package/cells/axis-ops.js +1 -1
  29. package/cells/book-css.js +7 -2
  30. package/cells/cell-styles-xml.js +1 -1
  31. package/cells/cf-engine.js +1 -1
  32. package/cells/cf-file.js +1 -1
  33. package/cells/docprops-xml.js +2 -2
  34. package/cells/filter-eval.js +1 -0
  35. package/cells/filter-file.js +1 -1
  36. package/cells/find-engine.js +2 -2
  37. package/cells/find.js +1 -1
  38. package/cells/goto.js +1 -1
  39. package/cells/link-model.js +1 -0
  40. package/cells/name-box.js +1 -1
  41. package/cells/note-box.js +3 -0
  42. package/cells/options.js +1 -1
  43. package/cells/outline-column.js +1 -1
  44. package/cells/protected-menu.js +1 -0
  45. package/cells/rich-data-xml.js +1 -1
  46. package/cells/selection-modes.js +1 -1
  47. package/cells/sheet-views-file.js +2 -0
  48. package/cells/shift-check.js +1 -1
  49. package/cells/sort-compare.js +1 -0
  50. package/cells/ui-kit.js +1 -1
  51. package/cells/undo-group.js +1 -1
  52. package/celltypes/dropdowns.js +2 -2
  53. package/core/address.js +1 -1
  54. package/core/autofill.js +1 -1
  55. package/core/axis.js +1 -1
  56. package/core/cond-format.js +1 -1
  57. package/core/culture.js +5 -1
  58. package/core/custom-views.js +1 -1
  59. package/core/data-tools.js +1 -0
  60. package/core/date-codes.js +1 -0
  61. package/core/default-names.js +1 -1
  62. package/core/edit-ranges.js +1 -0
  63. package/core/formula-refs.js +1 -1
  64. package/core/host-rules.js +1 -0
  65. package/core/input.js +1 -1
  66. package/core/numfmt.js +1 -1
  67. package/core/precision.js +1 -0
  68. package/core/protection.js +1 -1
  69. package/core/region-input.js +1 -1
  70. package/core/rule-refs.js +1 -0
  71. package/core/shared-view.js +1 -0
  72. package/core/sheet.js +1 -1
  73. package/core/sparklines.js +1 -1
  74. package/core/sparse.js +1 -1
  75. package/core/spills.js +1 -0
  76. package/core/strings.js +1 -1
  77. package/core/structure.js +1 -1
  78. package/core/table-columns.js +1 -0
  79. package/core/tables.js +2 -2
  80. package/core/validation-ranges.js +1 -1
  81. package/core/whatif.js +1 -1
  82. package/core/workbook.js +1 -1
  83. package/datasheets/formula.js +1 -1
  84. package/datasheets/manager.js +1 -1
  85. package/datasheets/path-binding.js +1 -1
  86. package/datasheets/persist-writer.js +1 -1
  87. package/datasheets/persist.js +1 -1
  88. package/datasheets/report.js +1 -1
  89. package/extras/getdata/persist.js +2 -2
  90. package/extras/getdata/rows.js +1 -1
  91. package/extras/getdata/shared-steps.js +1 -0
  92. package/extras/getdata/steps-formula.js +1 -0
  93. package/extras/getdata/steps-more.js +1 -0
  94. package/extras/getdata/steps-tables.js +1 -0
  95. package/extras/getdata/steps.js +1 -1
  96. package/i18n/de/a11y.js +1 -0
  97. package/i18n/de/cells.js +2 -0
  98. package/i18n/de/charts.js +1 -0
  99. package/i18n/de/common.js +1 -0
  100. package/i18n/de/datasheets.js +1 -0
  101. package/i18n/de/format.js +1 -0
  102. package/i18n/de/misc.js +1 -0
  103. package/i18n/de/pivot.js +1 -0
  104. package/i18n/de/proofing.js +1 -0
  105. package/i18n/de/ribbon.js +1 -0
  106. package/i18n/de/shapes.js +1 -0
  107. package/i18n/de/shell.js +3 -0
  108. package/i18n/de/touch.js +1 -0
  109. package/i18n/de.js +1 -0
  110. package/i18n/en/cells.js +2 -1
  111. package/i18n/en/charts.js +1 -1
  112. package/i18n/en/format.js +1 -1
  113. package/i18n/en/misc.js +1 -1
  114. package/i18n/en/pivot.js +1 -1
  115. package/i18n/en/proofing.js +1 -1
  116. package/i18n/en/ribbon.js +1 -1
  117. package/i18n/en/shapes.js +1 -1
  118. package/i18n/en/shell.js +3 -2
  119. package/i18n/en/touch.js +1 -1
  120. package/i18n/es/a11y.js +1 -0
  121. package/i18n/es/cells.js +2 -0
  122. package/i18n/es/charts.js +1 -0
  123. package/i18n/es/common.js +1 -0
  124. package/i18n/es/datasheets.js +1 -0
  125. package/i18n/es/format.js +1 -0
  126. package/i18n/es/misc.js +1 -0
  127. package/i18n/es/pivot.js +1 -0
  128. package/i18n/es/proofing.js +1 -0
  129. package/i18n/es/ribbon.js +1 -0
  130. package/i18n/es/shapes.js +1 -0
  131. package/i18n/es/shell.js +3 -0
  132. package/i18n/es/touch.js +1 -0
  133. package/i18n/es.js +1 -0
  134. package/i18n/fr/a11y.js +1 -0
  135. package/i18n/fr/cells.js +2 -0
  136. package/i18n/fr/charts.js +1 -0
  137. package/i18n/fr/common.js +1 -0
  138. package/i18n/fr/datasheets.js +1 -0
  139. package/i18n/fr/format.js +1 -0
  140. package/i18n/fr/misc.js +1 -0
  141. package/i18n/fr/pivot.js +1 -0
  142. package/i18n/fr/proofing.js +1 -0
  143. package/i18n/fr/ribbon.js +1 -0
  144. package/i18n/fr/shapes.js +1 -0
  145. package/i18n/fr/shell.js +3 -0
  146. package/i18n/fr/touch.js +1 -0
  147. package/i18n/fr.js +1 -0
  148. package/i18n/index.js +1 -1
  149. package/i18n/languages.js +1 -1
  150. package/i18n/pl/cells.js +2 -1
  151. package/i18n/pl/charts.js +1 -1
  152. package/i18n/pl/format.js +1 -1
  153. package/i18n/pl/misc.js +1 -1
  154. package/i18n/pl/pivot.js +1 -1
  155. package/i18n/pl/proofing.js +1 -1
  156. package/i18n/pl/ribbon.js +1 -1
  157. package/i18n/pl/shapes.js +1 -1
  158. package/i18n/pl/shell.js +3 -2
  159. package/i18n/pl/touch.js +1 -1
  160. package/io/blob-sink.js +1 -0
  161. package/io/canonical-xml.js +1 -0
  162. package/io/client.js +1 -1
  163. package/io/crypto/cfb-build.js +1 -0
  164. package/io/crypto/cfb-read.js +1 -1
  165. package/io/crypto/cfb-write.js +1 -1
  166. package/io/crypto/errors.js +1 -1
  167. package/io/csv.js +8 -8
  168. package/io/encoding.js +1 -0
  169. package/io/foreign-sheets.js +2 -2
  170. package/io/io.worker.js +1 -1
  171. package/io/open-package.js +1 -0
  172. package/io/package-paths.js +1 -1
  173. package/io/plan.js +1 -1
  174. package/io/text-split.js +3 -3
  175. package/io/xls/chart-sheet.js +1 -0
  176. package/io/xls/chart.js +1 -0
  177. package/io/xls/crypt.js +1 -0
  178. package/io/xls/dml-color.js +1 -0
  179. package/io/xls/drawing.js +1 -0
  180. package/io/xls/formula.js +1 -0
  181. package/io/xls/geometry.js +1 -0
  182. package/io/xls/index.js +1 -0
  183. package/io/xls/pictures.js +1 -0
  184. package/io/xls/pivot.js +1 -0
  185. package/io/xls/props.js +1 -0
  186. package/io/xls/records.js +1 -0
  187. package/io/xls/shapes.js +1 -0
  188. package/io/xls/sheet-ext.js +1 -0
  189. package/io/xls/sheet.js +1 -0
  190. package/io/xls/styles.js +1 -0
  191. package/io/xls/vba.js +1 -0
  192. package/io/xls/workbook.js +1 -0
  193. package/io/xlsb/filter.js +1 -0
  194. package/io/xlsb/formula.js +2 -0
  195. package/io/xlsb/functions.js +1 -0
  196. package/io/xlsb/index.js +1 -0
  197. package/io/xlsb/parts.js +1 -0
  198. package/io/xlsb/pivot.js +1 -0
  199. package/io/xlsb/records.js +1 -0
  200. package/io/xlsb/sheet-ext.js +1 -0
  201. package/io/xlsb/sheet.js +1 -0
  202. package/io/xlsb/slicer.js +1 -0
  203. package/io/xlsb/styles.js +1 -0
  204. package/io/xlsb/workbook.js +1 -0
  205. package/io/xlsb/xml.js +2 -0
  206. package/io/xlsx-read.js +1 -1
  207. package/io/xlsx-styles.js +2 -2
  208. package/io/xlsx-tail.js +1 -1
  209. package/io/xlsx-write.js +2 -2
  210. package/io/xml-escape.js +1 -1
  211. package/io/xml-scan.js +2 -2
  212. package/io/zip-reader.js +1 -1
  213. package/objects/chart-model.js +1 -1
  214. package/objects/drawing-xml.js +1 -1
  215. package/package.json +1 -1
  216. package/pivot/calc-items.js +1 -0
  217. package/pivot/engine.js +1 -1
  218. package/pivot/xml.js +2 -2
  219. package/print/note-pages.js +2 -0
  220. package/print/page-setup.js +1 -1
  221. package/print/paginate.js +1 -1
  222. package/print/pdf-crypt.js +1 -0
  223. package/print/pdf-links.js +1 -0
  224. package/print/pdf-tags.js +1 -0
  225. package/print/pdf.js +24 -13
  226. package/print/render-page.js +3 -3
  227. package/print/shown-notes.js +1 -0
  228. package/shapes/form-xml.js +1 -1
  229. package/slicers/custom-styles.js +1 -1
  230. package/slicers/format.js +1 -1
  231. package/slicers/structured.js +1 -1
  232. package/slicers/write.js +1 -1
  233. package/table-view/files.js +1 -1
  234. package/table-view/mount.js +1 -1
  235. package/table-view/version.js +1 -1
  236. package/ui/dialogs.js +3 -3
  237. package/ui/icons.js +1 -1
  238. package/ui/menu-base.js +1 -1
  239. package/ui/protection-ui.js +1 -1
@@ -0,0 +1,2 @@
1
+ import{colName as N,quoteSheetName as b}from"../../core/address.js";import{fixedArity as L,functionName as S}from"./functions.js";import{numberText as A,Reader as g}from"./records.js";const R={maxRow:1048576,maxCol:16384,row:n=>n.u32(),signed:n=>n|0,text:n=>n.lpstr(),arrayBytes:14,memory:n=>n.skip(n.u32()*16),refBytes:6,areaBytes:12,arraySize:n=>[n.u32(),n.u32()],constant(n){switch(n.u8()){case 0:return["number",n.f64()];case 1:return["text",n.lpstr()];case 2:return["bool",n.u8()!==0];case 4:{const c=n.u8();return n.skip(3),["error",c]}default:return[null]}}},v={0:"#NULL!",7:"#DIV/0!",15:"#VALUE!",23:"#REF!",29:"#NAME?",36:"#NUM!",42:"#N/A",43:"#GETTING_DATA"},z={3:"+",4:"-",5:"*",6:"/",7:"^",8:"&",9:"<",10:"<=",11:"=",12:">=",13:">",14:"<>",15:" ",16:",",17:":"},M={0:[],1:["#All"],2:["#Headers"],4:["#Data"],6:["#Headers","#Data"],8:["#Totals"],12:["#Data","#Totals"],16:["#This Row"]},f=n=>{throw new Error(`Formula: ${n}`)},_=n=>n.replace(/[[\]#'@]/g,"'$&");function Y(n,c,s){const t=n.u32(),e=new g(n.buf,n.take(t));e.end=e.pos+t;const o=n.u32(),i=new g(n.buf,n.take(o));return i.end=i.pos+o,j(e,i,c,s,R)}function q(n,c,s){const t=n.u32(),e=n.u32(),o=new g(n.buf,n.take(t));o.end=o.pos+t;const i=new g(n.buf,n.take(e));return i.end=i.pos+e,j(o,i,c,s,R)}function W(n){n.skip(n.u32()),n.skip(n.u32())}function X(n){const c=n.pos,s=n.u32();let t=null;if(s>=5&&n.buf[n.pos]===1){n.skip(1);const e=n.u32();n.skip(s-5);const o=n.u32();t={row:e,col:o>=4?n.u32():0}}return n.pos=c,t}function j(n,c,s,t,e){const o=[];let i="",x="",r="";const a=l=>{o.push(i+l),i=""},p=()=>o.length?o.pop():f("an operand is missing"),h=l=>(o.length<l&&f("an argument is missing"),l===0?[]:o.splice(o.length-l,l)),d=(l,$)=>{const u=`${l}(${x}${$.join(",")}${r})`;x="",r="",a(u)};for(;n.pos<n.end;){const l=n.u8(),$=l&96?l&31|32:l;if(z[$]!==void 0){const u=p(),k=p(),m=i+z[$];i="",o.push(k+m+u);continue}switch($){case 18:o.push(`${i}+${p()}`),i="";break;case 19:o.push(`${i}-${p()}`),i="";break;case 20:o.push(`${p()}${i}%`),i="";break;case 21:{const u=`(${x}${p()}${r})`;x="",r="",a(u);break}case 22:a("");break;case 23:a(`"${e.text(n).replace(/"/g,'""')}"`);break;case 24:a(G(n,c,s));break;case 25:{const u=n.u8();if(u&4)n.skip((n.u16()+1)*2);else if(u&16)n.skip(2),d("SUM",h(1));else if(u&64){const k=n.u8(),m=(k&1?`
2
+ `:" ").repeat(n.u8());k<2?i+=m:k<4?x+=m:k<6&&(r+=m)}else n.skip(2);break}case 28:a(v[n.u8()]??f("an unknown error value"));break;case 29:a(n.u8()?"TRUE":"FALSE");break;case 30:a(String(n.u16()));break;case 31:a(A(n.f64()));break;case 32:n.skip(e.arrayBytes),a(H(c,e));break;case 33:{const u=n.u16();d(S(u)??f(`function ${u}`),h(L(u)??Math.min(o.length,3)));break}case 34:{const u=n.u8(),k=n.u16();k&32768&&f("a macro command");const m=h(u);d(k===255?m.length?m.shift().trim():f("a call without a name"):S(k)??f(`function ${k}`),m);break}case 35:a(I(s,n.u32()));break;case 36:a(w(e.row(n),n.u16()));break;case 37:a(B(n,e));break;case 38:n.skip(6),e.memory(c);break;case 39:case 40:n.skip(6);break;case 41:n.skip(2);break;case 42:n.skip(e.refBytes),a("#REF!");break;case 43:n.skip(e.areaBytes),a("#REF!");break;case 44:a(U(e.row(n),n.u16(),t,e));break;case 45:a(D(n,t,e));break;case 57:{const u=n.u16();a(C(s,u,n.u32()));break}case 58:{const u=F(s,n.u16()),k=e.row(n),m=n.u16();a(u===null?"#REF!":`${u}!${t.inName?U(k,m,t,e):w(k,m)}`);break}case 59:{const u=F(s,n.u16()),k=t.inName?D(n,t,e):B(n,e);a(u===null?"#REF!":`${u}!${k}`);break}case 60:case 61:{const u=F(s,n.u16());n.skip($===60?e.refBytes:e.areaBytes),a(u===null?"#REF!":`${u}!#REF!`);break}default:f(`token ${l.toString(16)}`)}}return o.length!==1&&f("the operands don't add up"),o[0]}function w(n,c){const s=c&16383;return`${c&16384?"":"$"}${N(s)}${c&32768?"":"$"}${n+1}`}function E(n,c,s,t,{maxRow:e,maxCol:o}){const i=p=>`${p&16384?"":"$"}${N(p&16383)}`,x=(p,h)=>`${p&32768?"":"$"}${h+1}`,r=n===0&&c===e-1,a=(s&16383)===0&&(t&16383)===o-1;return a&&r?`${x(s,0)}:${x(t,R.maxRow-1)}`:r?`${i(s)}:${i(t)}`:a?`${x(s,n)}:${x(t,c)}`:`${w(n,s)}:${w(c,t)}`}function B(n,c){const s=c.row(n),t=c.row(n),e=n.u16(),o=n.u16();return E(s,t,e,o,c)}function T(n,c,s,{maxRow:t,maxCol:e,signed:o}){const i=(c&32768)!==0,x=(c&16384)!==0,r=i?((o(n)+s.row)%t+t)%t:n,a=x?((c&16383)+s.col)%e:c&16383;return s.span&&(i&&r+s.span.rows>=t||x&&a+s.span.cols>=e)&&(s.wraps=!0),[r,c&49152|a]}function U(n,c,s,t){const[e,o]=T(n,c,s,t);return w(e,o)}function D(n,c,s){const{maxRow:t,maxCol:e}=s,o=s.row(n),i=s.row(n),x=n.u16(),r=n.u16(),a=t<R.maxRow,p=o===0&&i===t-1&&!(a&&r&32768),h=(x&16383)===0&&(r&16383)===e-1&&!(a&&r&16384),[d,l]=T(o,x,c,s),[$,u]=T(i,r,c,s);return p?E(0,t-1,l,u,s):h?E(d,$,x,r,s):E(d,$,l,u,s)}function F(n,c){const s=n.xti[c]??f("an unknown sheet"),t=n.links[s.link]??f("an unknown link");if(t.missing&&f("a link that isn't here"),t.kind==="self"){if(s.first<0)return null;const e=n.sheets[s.first]?.name,o=n.sheets[s.last]?.name;return e===void 0||o===void 0?null:b(e,{last:o===e?null:o})}if(t.kind==="book"){const e=t.sheets[s.first];if(s.first<0||e===void 0)return null;const o=t.sheets[s.last]??e;return b(e,{book:String(t.index),last:o===e?null:o})}return f("a reference to an add-in")}function I(n,c){const s=n.names[c-1]??f("an unknown name");return s.lost&&!s.procedure&&f("a name that can't be read"),s.name}function C(n,c,s){const t=n.xti[c]??f("an unknown link"),e=n.links[t.link]??f("an unknown link");if(e.missing&&f("a link that isn't here"),e.kind==="self"){const o=I(n,s);if(t.first===-1)return"#REF!";const i=t.first>=0?n.sheets[t.first]?.name:void 0;return i===void 0?o:`${b(i)}!${o}`}if(e.kind==="book"){const o=e.names[s-1]??f("an unknown linked name"),i=t.first>=0?e.sheets[t.first]:void 0;return i===void 0?`[${e.index}]!${o}`:`${b(i,{book:String(e.index)})}!${o}`}return e.kind==="addin"&&e.names?e.names[s-1]??f("an unknown add-in function"):f("an add-in function")}function G(n,c,s){const t=n.u8();if(t===29&&s.pivotName)return s.pivotName(n.u32());t!==25&&f(`token 18 ${t.toString(16)}`),n.skip(2);const e=n.u16(),o=n.u32(),i=n.u16(),x=n.u16();if(e&4096)return"#REF!";if(e&8192)return f("a table in another workbook");const r=s.tables.get(o)??f("an unknown table"),a=e&3,p=M[e>>2&31]??f("unknown table rows"),h=$=>`[${_(r.columns[$]??f("an unknown table column"))}]`,d=p.map($=>`[${$}]`);if(a===0)return d.length===0?`${r.name}[]`:d.length===1?`${r.name}${d[0]}`:`${r.name}[${d.join(",")}]`;const l=a===1?h(i):`${h(i)}:${h(x)}`;return d.length===0&&a===1?`${r.name}${l}`:`${r.name}[${[...d,l].join(",")}]`}function H(n,c){const[s,t]=c.arraySize(n);s*t>n.left&&f("an array that ends too early");const e=[];for(let o=0;o<s;o++){const i=[];for(let x=0;x<t;x++){const[r,a]=c.constant(n);r==="number"?i.push(A(a)):r==="text"?i.push(`"${a.replace(/"/g,'""')}"`):r==="bool"?i.push(a?"TRUE":"FALSE"):r==="error"?i.push(v[a]??f("an unknown error value")):f("an unknown constant")}e.push(i.join(","))}return`{${e.join(";")}}`}export{R as BIFF12,v as ERROR_TEXT,j as decode,X as deferredTo,Y as readFormula,q as readFrtFormula,W as skipFormula};
@@ -0,0 +1 @@
1
+ const T="COUNT IF ISNA ISERROR SUM AVERAGE MIN MAX ROW COLUMN NA NPV STDEV DOLLAR FIXED SIN COS TAN ATAN PI SQRT EXP LN LOG10 ABS INT SIGN ROUND LOOKUP INDEX REPT MID LEN VALUE TRUE FALSE AND OR NOT MOD DCOUNT DSUM DAVERAGE DMIN DMAX DSTDEV VAR DVAR TEXT LINEST TREND LOGEST GROWTH GOTO HALT RETURN PV FV NPER PMT RATE MIRR IRR RAND MATCH DATE TIME DAY MONTH YEAR WEEKDAY HOUR MINUTE SECOND NOW AREAS ROWS COLUMNS OFFSET ABSREF RELREF ARGUMENT SEARCH TRANSPOSE ERROR STEP TYPE ECHO SET.NAME CALLER DEREF WINDOWS - DOCUMENTS ACTIVE.CELL SELECTION RESULT ATAN2 ASIN ACOS CHOOSE HLOOKUP VLOOKUP LINKS INPUT ISREF GET.FORMULA GET.NAME SET.VALUE LOG EXEC CHAR LOWER UPPER PROPER LEFT RIGHT EXACT TRIM REPLACE SUBSTITUTE CODE NAMES DIRECTORY FIND CELL ISERR ISTEXT ISNUMBER ISBLANK T N FOPEN FCLOSE FSIZE FREADLN FREAD FWRITELN FWRITE FPOS DATEVALUE TIMEVALUE SLN SYD DDB GET.DEF REFTEXT TEXTREF INDIRECT REGISTER CALL ADD.BAR ADD.MENU ADD.COMMAND ENABLE.COMMAND CHECK.COMMAND RENAME.COMMAND SHOW.BAR DELETE.MENU DELETE.COMMAND GET.CHART.ITEM DIALOG.BOX CLEAN MDETERM MINVERSE MMULT FILES IPMT PPMT COUNTA CANCEL.KEY FOR WHILE BREAK NEXT INITIATE REQUEST POKE EXECUTE TERMINATE RESTART HELP GET.BAR PRODUCT FACT GET.CELL GET.WORKSPACE GET.WINDOW GET.DOCUMENT DPRODUCT ISNONTEXT GET.NOTE NOTE STDEVP VARP DSTDEVP DVARP TRUNC ISLOGICAL DCOUNTA DELETE.BAR UNREGISTER - - USDOLLAR FINDB SEARCHB REPLACEB LEFTB RIGHTB MIDB LENB ROUNDUP ROUNDDOWN ASC DBCS RANK - - ADDRESS DAYS360 TODAY VDB ELSE ELSE.IF END.IF FOR.CELL MEDIAN SUMPRODUCT SINH COSH TANH ASINH ACOSH ATANH DGET CREATE.OBJECT VOLATILE LAST.ERROR CUSTOM.UNDO CUSTOM.REPEAT FORMULA.CONVERT GET.LINK.INFO TEXT.BOX INFO GROUP GET.OBJECT DB PAUSE - - RESUME FREQUENCY ADD.TOOLBAR DELETE.TOOLBAR - RESET.TOOLBAR EVALUATE GET.TOOLBAR GET.TOOL SPELLING.CHECK ERROR.TYPE APP.TITLE WINDOW.TITLE SAVE.TOOLBAR ENABLE.TOOL PRESS.TOOL REGISTER.ID GET.WORKBOOK AVEDEV BETADIST GAMMALN BETAINV BINOMDIST CHIDIST CHIINV COMBIN CONFIDENCE CRITBINOM EVEN EXPONDIST FDIST FINV FISHER FISHERINV FLOOR GAMMADIST GAMMAINV CEILING HYPGEOMDIST LOGNORMDIST LOGINV NEGBINOMDIST NORMDIST NORMSDIST NORMINV NORMSINV STANDARDIZE ODD PERMUT POISSON TDIST WEIBULL SUMXMY2 SUMX2MY2 SUMX2PY2 CHITEST CORREL COVAR FORECAST FTEST INTERCEPT PEARSON RSQ STEYX SLOPE TTEST PROB DEVSQ GEOMEAN HARMEAN SUMSQ KURT SKEW ZTEST LARGE SMALL QUARTILE PERCENTILE PERCENTRANK MODE TRIMMEAN TINV - MOVIE.COMMAND GET.MOVIE CONCATENATE POWER PIVOT.ADD.DATA GET.PIVOT.TABLE GET.PIVOT.FIELD GET.PIVOT.ITEM RADIANS DEGREES SUBTOTAL SUMIF COUNTIF COUNTBLANK SCENARIO.GET OPTIONS.LISTS.GET ISPMT DATEDIF DATESTRING NUMBERSTRING ROMAN OPEN.DIALOG SAVE.DIALOG VIEW.GET GETPIVOTDATA HYPERLINK PHONETIC AVERAGEA MAXA MINA STDEVPA VARPA STDEVA VARA BAHTTEXT THAIDAYOFWEEK THAIDIGIT THAIMONTHOFYEAR THAINUMSOUND THAINUMSTRING THAISTRINGLENGTH ISTHAIDIGIT ROUNDBAHTDOWN ROUNDBAHTUP THAIYEAR RTD CUBEVALUE CUBEMEMBER CUBEMEMBERPROPERTY CUBERANKEDMEMBER HEX2BIN HEX2DEC HEX2OCT DEC2BIN DEC2HEX DEC2OCT OCT2BIN OCT2HEX OCT2DEC BIN2DEC BIN2OCT BIN2HEX IMSUB IMDIV IMPOWER IMABS IMSQRT IMLN IMLOG2 IMLOG10 IMSIN IMCOS IMEXP IMARGUMENT IMCONJUGATE IMAGINARY IMREAL COMPLEX IMSUM IMPRODUCT SERIESSUM FACTDOUBLE SQRTPI QUOTIENT DELTA GESTEP ISEVEN ISODD MROUND ERF ERFC BESSELJ BESSELK BESSELY BESSELI XIRR XNPV PRICEMAT YIELDMAT INTRATE RECEIVED DISC PRICEDISC YIELDDISC TBILLEQ TBILLPRICE TBILLYIELD PRICE YIELD DOLLARDE DOLLARFR NOMINAL EFFECT CUMPRINC CUMIPMT EDATE EOMONTH YEARFRAC COUPDAYBS COUPDAYS COUPDAYSNC COUPNCD COUPNUM COUPPCD DURATION MDURATION ODDLPRICE ODDLYIELD ODDFPRICE ODDFYIELD RANDBETWEEN WEEKNUM AMORDEGRC AMORLINC - ACCRINT ACCRINTM WORKDAY NETWORKDAYS GCD MULTINOMIAL LCM FVSCHEDULE CUBEKPIMEMBER CUBESET CUBESETCOUNT IFERROR COUNTIFS SUMIFS AVERAGEIF AVERAGEIFS".split(" "),I="..11......0....1111011111112..231100..12333333.32....1.......3.0.33111.1110111.22..1.01..01...00.211.....11.2..1111..214.1....111111.111222.1134.................11112......10022321....1.1..31....33.1311.....4..312211.....0.010...1111113..0.....10......2.1.11...1...33....1.42223313331124324333413131233422222232222224........2222..22....2....11..21.14312......1.......11111111111...3..1......11..222111111111111...4112..112.12222.3.......333..22226622.............2...........2..12....",A=E=>E<T.length&&T[E]!=="-"?T[E]:null,R=E=>I[E]===void 0||I[E]==="."?null:Number(I[E]);export{R as fixedArity,A as functionName};
@@ -0,0 +1 @@
1
+ import{BlobSink as J}from"../blob-sink.js";import{openZip as _}from"../zip-reader.js";import{ZipWriter as Q}from"../zip-writer.js";import{children as S,parseTree as q}from"../xml-scan.js";import{escapeMarkup as B}from"../xml-escape.js";import{relativeTarget as V,relsPathOf as F,resolveTarget as Y}from"../package-paths.js";import{attrs as j,Out as z,XML_HEAD as A}from"./xml.js";import{Reader as ee}from"./records.js";import{readNames as te,readWorkbook as H,workbookXml as ae}from"./workbook.js";import{readStyles as ne}from"./styles.js";import{chartSheetXml as ie,readExternalNames as se,readMetadata as oe,readTable as re,tableXml as ce,writeComments as le,writeExternal as de,writeStrings as me}from"./parts.js";import{pivotTableXml as pe,readPivotCache as fe,writePivotCache as he,writePivotRecords as ke}from"./pivot.js";import{writeSheet as we}from"./sheet.js";import{readSlicerCache as ue,readSlicers as ye,slicersXml as be,workbookRefs as xe}from"./slicer.js";const b="application/vnd.ms-excel.",k="application/vnd.openxmlformats-officedocument.spreadsheetml.",Z=`${b}sheet.binary.macroEnabled.main`,L="http://schemas.openxmlformats.org/officeDocument/2006/relationships",E={worksheet:{kind:"sheet",type:`${k}worksheet+xml`},macrosheet:{kind:"sheet",type:`${k}worksheet+xml`,rel:`${L}/worksheet`},intlmacrosheet:{kind:"sheet",type:`${k}worksheet+xml`,rel:`${L}/worksheet`},dialogsheet:{kind:"sheet",type:`${k}worksheet+xml`,rel:`${L}/worksheet`},chartsheet:{kind:"chartsheet",type:`${k}chartsheet+xml`},styles:{kind:"styles",type:`${k}styles+xml`},sharedStrings:{kind:"strings",type:`${k}sharedStrings+xml`},table:{kind:"table",type:`${k}table+xml`},comments:{kind:"comments",type:`${k}comments+xml`},externalLink:{kind:"external",type:`${k}externalLink+xml`},sheetMetadata:{kind:"metadata",type:`${k}sheetMetadata+xml`},binIndexWs:null,binIndexMs:null,calcChain:null,pivotTable:{kind:"pivot",type:`${k}pivotTable+xml`},pivotCacheDefinition:{kind:"pivotCache",type:`${k}pivotCacheDefinition+xml`},pivotCacheRecords:{kind:"pivotRecords",type:`${k}pivotCacheRecords+xml`},slicer:{kind:"slicer",type:`${b}slicer+xml`},slicerCache:{kind:"slicerCache",type:`${b}slicerCache+xml`},"timeline+xml":{kind:"timeline",type:`${b}timeline+xml`},"timelineCache+xml":{kind:"timelineCache",type:`${b}timelineCache+xml`},queryTable:null,connections:null,tableSingleCells:null,volatileDependencies:null,revisionHeaders:null,revisionLog:null,userNames:null},ve=new Set(["binIndexWs","binIndexMs","calcChain","volatileDependencies"]);async function Be(d){const i=await _(d),s=(await C(i,"")).find(o=>/\/officeDocument$/.test(o.type));return(await H(await i.stream(s.part))).sheets.filter(o=>o.rid).map(o=>({name:o.name,hidden:o.state!==0}))}async function ge(d){const i=q(await d.bytes("[Content_Types].xml")),s=new Map(S(i,"Default").map(a=>[a.a.Extension.toLowerCase(),a.a.ContentType])),r=new Map(S(i,"Override").map(a=>[a.a.PartName.replace(/^\//,"").toLowerCase(),a.a.ContentType])),o=new Map,m=new Set([...d.entries.keys()].map(a=>a.toLowerCase()));for(const a of d.entries.keys()){if(a==="[Content_Types].xml"||a.endsWith("/")||/(?:^|\/)_rels\/[^/]*\.rels$/.test(a))continue;const h=a.slice(a.lastIndexOf(".")+1).toLowerCase(),t=r.get(a.toLowerCase()),f=t??s.get(h)??"application/octet-stream",c=f.startsWith(b)?f.slice(b.length):"";let u={kind:"copy",type:f,override:t!==void 0};if(f===Z?u={kind:t!==void 0||/workbook\.bin$/i.test(a)?"workbook":"copy",type:`${k}sheet.main+xml`}:c in E&&(u=E[c]),u===null){o.set(a,{name:a,kind:"drop",key:c});continue}let x=a;if(u.kind!=="copy"&&/\.bin$/i.test(a)){x=a.replace(/\.bin$/i,".xml");for(let I=2;m.has(x.toLowerCase());I++)x=a.replace(/\.bin$/i,`_${I}.xml`);m.add(x.toLowerCase())}o.set(a,{name:a,target:x,key:c,...u})}const n=[...o.values()].some(a=>a.type==="application/vnd.ms-office.vbaProject");for(const a of o.values())a.kind==="workbook"&&n&&(a.type=`${b}sheet.macroEnabled.main+xml`);return{parts:o,defaults:s,macro:n}}async function C(d,i){const s=F(i);return d.has(s)?S(q(await d.bytes(s)),"Relationship").map(r=>({id:r.a.Id,type:r.a.Type??"",target:r.a.Target??"",external:r.a.TargetMode==="External",part:r.a.TargetMode==="External"?null:Y(i,r.a.Target??"")})):[]}async function Fe(d){const i=await _(d),{parts:s,defaults:r,macro:o}=await ge(i),m=e=>s.get(e)??s.get(i.entry(e)?.name),n={formulas:0,pivots:0,slicers:0,queries:0,links:0,parts:0},a=()=>{n.formulas++};for(const e of s.values())e.kind==="drop"&&(e.key==="connections"||e.key==="queryTable"?n.queries++:ve.has(e.key)||n.parts++);const h=await C(i,""),t=h.find(e=>/\/officeDocument$/.test(e.type)),f=t?m(t.part):void 0;if(!f||!i.has(f.name))throw new Error("This file has no workbook part");f.kind="workbook";const c=await H(await i.stream(f.name)),u=await C(i,f.name),x=new Map(u.map(e=>[e.id,e]));let I=0;for(const e of c.sheets)e.part=e.rid?m(x.get(e.rid)?.part??""):void 0;for(const e of c.links){if(e.kind!=="book")continue;const l=m(x.get(e.rid)?.part??""),p=l?.kind==="external"&&i.has(l.name)?await se(await i.stream(l.name)):null;if(!p||p.kind!==0){e.missing=!0,n.links++,l&&(l.kind="drop");continue}e.index=++I,e.sheets=p.sheets,e.names=p.names,l.link={rid:p.rid,sheets:p.sheets}}for(const e of s.values())if(e.kind==="table"&&(e.table=await re(await i.stream(e.name)),e.table.id!==void 0)){if(e.table.type==="queryTable"){e.table.type=void 0,e.table.connectionId=void 0;for(const l of e.table.columns)l.queryTableFieldId=void 0}c.tables.set(e.table.id,{name:e.table.displayName,columns:e.table.columns.map(l=>l.name)})}const D=[...s.values()].find(e=>e.kind==="styles"),M=D?await ne(await i.stream(D.name)):{xml:null,fonts:[]},P=[...s.values()].find(e=>e.kind==="metadata"),R=P?await oe(await i.stream(P.name)):{xml:"",cells:new Map,values:new Map,lost:!1};R.lost&&n.parts++,te(c,ee,a),await Ce(i,s,m,c,n),await $e(i,s,n);const N=(e,l,p)=>{const y=g=>m(e.find(T=>T.id===g)?.part??""),v=g=>l.filter(T=>y(T)?.filters===g&&y(T).kind!=="drop");return{pivot:v("pivot"),table:v("table"),timelines:p.filter(g=>y(g)&&y(g).kind!=="drop")}},U=c.pivotCaches.filter(e=>{const l=m(x.get(e.rid)?.part??"");return l&&l.kind==="pivotCache"}),O=c.sheets.filter(e=>e.part&&e.part.kind!=="drop"&&i.has(e.part.name)),X=new Map(O.map((e,l)=>[c.sheets.indexOf(e),l])),G=c.names.filter(e=>e.itab===void 0||X.has(e.itab)).map(e=>({...e,itab:e.itab===void 0?void 0:X.get(e.itab)})),W=new J,$=new Q(W),w=async(e,l)=>{await $.add(e.target,async p=>{const y=new z(p),v=await l(y);typeof v=="string"&&y.add(v),await y.flush(!0)},{large:i.entry(e.name).size>1<<27})};await $.addBytes("[Content_Types].xml",Te(s,r)),await K($,"","",h,m);for(const e of s.values()){if(e.kind==="drop")continue;const l=()=>i.stream(e.name);switch(e.kind){case"workbook":await w(e,()=>ae({...c,sheets:O,names:G},U,xe(N(u,c.slicerCaches,c.timelineCaches))));break;case"styles":await w(e,()=>M.xml);break;case"strings":await w(e,async p=>me(await l(),p,M.fonts));break;case"sheet":{const p=c.sheets.findIndex(v=>v.part===e),y=await C(i,e.name);await w(e,async v=>we(await l(),v,{book:c,index:p,fonts:M.fonts,meta:R,onLost:a,onLostLink:()=>n.links++,onLostPart:()=>n.parts++,refs:(g,T)=>N(y,g,T)}));break}case"chartsheet":await w(e,async()=>ie(await l()));break;case"table":await w(e,()=>ce(e.table,c,a));break;case"comments":await w(e,async p=>le(await l(),p,M.fonts));break;case"external":await w(e,async p=>de(await l(),p,e.link??{rid:null,sheets:[]}));break;case"pivotCache":await w(e,async p=>he(await l(),p,c,e.cache));break;case"pivotRecords":await w(e,async p=>ke(await l(),p,e.cache));break;case"pivot":await w(e,async()=>pe(await l()));break;case"slicer":await w(e,()=>be(e.slicers));break;case"slicerCache":await w(e,()=>e.cache.xml);break;case"metadata":await w(e,()=>R.xml);break;case"timeline":await w(e,async()=>e.xml??i.text(e.name));break;default:await $.copyRaw(i,i.entry(e.name),e.target)}await K($,e.name,e.target,await C(i,e.name),m)}return await $.finish(),{blob:W.close(`${k}sheet`),macro:o,lost:n}}async function Ce(d,i,s,r,o){const m=n=>{n.kind="drop"};for(const n of[...i.values()].filter(a=>a.kind==="pivotCache")){n.cache=await fe(await d.stream(n.name),r);const a=n.cache.kind===0&&!n.cache.olap&&!n.cache.unreadable&&n.cache.head!==null;for(const h of await C(d,n.name)){const t=h.external?void 0:s(h.part);t?.kind==="pivotRecords"&&(t.cache=n.cache,a||m(t))}a||m(n)}for(const n of i.values())n.kind==="pivotRecords"&&!n.cache&&m(n),!(n.kind!=="pivot"||(await C(d,n.name)).some(h=>!h.external&&s(h.part)?.kind==="pivotCache"))&&(m(n),o.pivots++)}async function $e(d,i,s){const r=[...i.values()],o=t=>r.filter(f=>f.kind===t),m=new Map,n=new Set(o("pivotCache").map(t=>t.cache.id14)),a=r.some(t=>t.kind==="drop"&&/^pivotCache/.test(t.key));for(const t of o("slicerCache"))t.cache=await ue(await d.stream(t.name)),t.filters=t.cache.kind,t.cache.kind==="olap"||t.cache.kind==="pivot"&&a&&!n.has(t.cache.pivotCacheId)?t.kind="drop":m.set(t.cache.name,t.cache.kind);for(const t of o("slicer")){const f=await ye(await d.stream(t.name));t.slicers=f.filter(c=>m.has(c.cache)),s.slicers+=f.length-t.slicers.length,t.filters=m.get(t.slicers[0]?.cache),t.slicers.length===0&&(t.kind="drop")}if(!a)return;const h=new Set;for(const t of o("timelineCache")){const f=await d.text(t.name),c=/\bpivotCacheId="(\d+)"/.exec(f)?.[1];if(c!==void 0&&n.has(Number(c)))continue;t.kind="drop";const u=/<(?:\w+:)?timelineCacheDefinition\b[^>]*?\bname="([^"]*)"/.exec(f)?.[1];u!==void 0&&h.add(u)}for(const t of o("timeline")){const f=await d.text(t.name);let c=0;t.xml=f.replace(/<(?:\w+:)?timeline\b[^>]*?(?:\/>|>[\s\S]*?<\/(?:\w+:)?timeline>)/g,u=>h.has(/\bcache="([^"]*)"/.exec(u)?.[1])?(s.slicers++,""):(c++,u)),c===0&&(t.kind="drop")}}function Te(d,i){let s="";for(const[r,o]of i)o===Z||o.startsWith(b)&&o.slice(b.length)in E||(s+=`<Default${j({Extension:r,ContentType:o})}/>`);i.has("xml")||(s+='<Default Extension="xml" ContentType="application/xml"/>');for(const r of d.values()){if(r.kind==="drop")continue;const o=r.target.slice(r.target.lastIndexOf(".")+1).toLowerCase();r.kind==="copy"&&!r.override&&i.get(o)===r.type||(s+=`<Override PartName="/${B(r.target)}" ContentType="${B(r.type)}"/>`)}return`${A}<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">${s}</Types>`}async function K(d,i,s,r,o){const m=[];for(const n of r){let a=n.target,{type:h}=n;if(!n.external){const t=o(n.part);if(t?.kind==="drop")continue;t&&t.target!==t.name&&(a=V(s,t.target)),t?.rel&&(h=t.rel)}m.push(`<Relationship${j({Id:n.id,Type:h,Target:a,TargetMode:n.external?"External":void 0})}/>`)}r.length!==0&&await d.addBytes(F(s),`${A}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${m.join("")}</Relationships>`)}export{Be as binarySheets,Fe as xlsbToXlsx};
@@ -0,0 +1 @@
1
+ import{escapeMarkup as y,xmlText as S}from"../xml-escape.js";import{attrs as m,fullRangeText as N,NS_MAIN as k,NS_R as C,XML_HEAD as g}from"./xml.js";import{eachRecord as x,numberText as I,Reader as F}from"./records.js";import{ERROR_TEXT as L,readFormula as A,skipFormula as M}from"./formula.js";import{filterReader as E}from"./filter.js";import{guidText as V}from"./sheet-ext.js";import{readColor as j,richText as T}from"./styles.js";import{colName as D,quoteSheetName as q}from"../../core/address.js";const B=4294967295,$=s=>s===B?void 0:s;async function Z(s,t,u){t.add(`${g}<sst xmlns="${k}">`),await x(s,(n,o)=>{n===19&&t.add(`<si>${T(o,u)}</si>`)},()=>t.flush()),t.add("</sst>"),await t.flush(!0)}const X=[void 0,"average","count","countNums","max","min","sum","stdDev","var","custom"],_={2:"xml",3:"queryTable"};async function ee(s){const t={columns:[],style:"",filter:null},u=E();let n=null;const o=r=>{const e=r.u8(),a=r.pos;return M(r),{array:(e&2)!==0,bytes:r.buf.slice(a,r.pos)}};return await x(s,(r,e)=>{if(!u.record(r,e))switch(r){case 343:{t.range=e.range(),t.type=_[e.u32()],t.id=e.u32(),t.headerRows=e.u32(),t.totalsRows=e.u32();const a=e.u32();t.totalsShown=(a&1)!==0,t.insertRow=(a&4)!==0,t.insertRowShift=(a&8)!==0,t.published=(a&16)!==0,t.dxfs={headerRowDxfId:$(e.u32()),dataDxfId:$(e.u32()),totalsRowDxfId:$(e.u32()),tableBorderDxfId:$(e.u32()),headerRowBorderDxfId:$(e.u32()),totalsRowBorderDxfId:$(e.u32())},t.connectionId=e.u32()||void 0,t.name=e.nstr(),t.displayName=e.nstr()??t.name,t.comment=e.nstr(),t.styles={headerRowCellStyle:e.nstr(),dataCellStyle:e.nstr(),totalsRowCellStyle:e.nstr()};break}case 347:{n={id:e.u32(),total:e.u32()},n.dxfs={headerRowDxfId:$(e.u32()),dataDxfId:$(e.u32()),totalsRowDxfId:$(e.u32())},n.queryTableFieldId=e.u32()||void 0;const a=e.nstr();n.name=e.nstr()??a??`Column${n.id}`,n.uniqueName=t.type&&a!==n.name?a:void 0,n.totalsLabel=e.nstr(),n.styles={headerRowCellStyle:e.nstr(),dataCellStyle:e.nstr(),totalsRowCellStyle:e.nstr()},t.columns.push(n);break}case 351:n&&(n.formula=o(e));break;case 352:n&&(n.totalsFormula=o(e));break;case 513:{const a=e.u16();t.style=`<tableStyleInfo${m({name:e.nstr()||void 0,showFirstColumn:a&1?"1":"0",showLastColumn:a&2?"1":"0",showRowStripes:a&4?"1":"0",showColumnStripes:a&8?"1":"0"})}/>`;break}default:}}),t.filter=u.text()+(u.sortXml??""),t}function te(s,t,u){const n={row:s.range.r1+s.headerRows,col:s.range.c1},o=(e,a)=>{if(!a)return"";try{return`<${e}${a.array?' array="1"':""}>${y(A(new F(a.bytes),t,n))}</${e}>`}catch{return u?.(),""}},r=s.columns.map(e=>{const a=o("calculatedColumnFormula",e.formula)+o("totalsRowFormula",e.totalsFormula),d=`<tableColumn${m({id:e.id,uniqueName:e.uniqueName,name:e.name,totalsRowFunction:X[e.total],totalsRowLabel:e.totalsLabel,queryTableFieldId:e.queryTableFieldId,...e.dxfs,...e.styles})}`;return a?`${d}>${a}</tableColumn>`:`${d}/>`});return`${g}<table xmlns="${k}"${m({id:s.id,name:s.name??s.displayName,displayName:s.displayName,comment:s.comment,ref:N(s.range),tableType:s.type,headerRowCount:s.headerRows===1?void 0:s.headerRows,insertRow:s.insertRow,insertRowShift:s.insertRowShift,totalsRowCount:s.totalsRows||void 0,totalsRowShown:s.totalsShown?void 0:"0",published:s.published,...s.dxfs,...s.styles,connectionId:s.connectionId})}>${s.filter}<tableColumns count="${r.length}">${r.join("")}</tableColumns>${s.style}</table>`}async function se(s,t,u){const n=[];let o=!1,r=null;t.add(`${g}<comments xmlns="${k}">`);const e=()=>{o||(o=!0,t.add(`<authors>${n.join("")}</authors><commentList>`))};await x(s,(a,d)=>{if(a===632)n.push(`<author>${S(d.str())}</author>`);else if(a===635){e();const c=d.u32(),h=d.range(),f=V(d);r={open:m({ref:N(h),authorId:c,guid:/[1-9A-F]/.test(f)?f:void 0}),text:""}}else a===637&&r?r.text=T(d,u):a===636&&r&&(t.add(`<comment${r.open}><text>${r.text}</text></comment>`),r=null)},()=>t.flush()),e(),t.add("</commentList></comments>"),await t.flush(!0)}function O(s,t){const u=s.u8();if(u!==58&&u!==59)return;const n=s.i16(),o=s.i16();if(n<0||t[n]===void 0)return;const r=(f,l)=>`$${D(l&16383)}$${f+1}`,e=q(t[n],{last:o>n&&t[o]!==void 0?t[o]:null});if(u===58){const f=s.u16();return`=${e}!${r(f,s.u16())}`}const[a,d,c,h]=[s.u16(),s.u16(),s.u16(),s.u16()];return`=${e}!${r(a,c)}:${r(d,h)}`}async function ae(s){const t={sheets:[],names:[],kind:0,rid:null};return await x(s,(u,n)=>{if(u===360)t.kind=n.u16(),t.rid=n.nstr();else if(u===359)for(let o=n.u32();o>0;o--)t.sheets.push(n.str());else u===577&&t.names.push(n.str())}),t}async function ne(s,t,u){t.add(`${g}<externalLink xmlns="${k}"><externalBook xmlns:r="${C}" r:id="${y(u.rid??"")}">`),u.sheets.length&&t.add(`<sheetNames>${u.sheets.map(f=>`<sheetName${m({val:f})}/>`).join("")}</sheetNames>`);const n=[];let o=null,r=!1,e=-1,a=!1;const d=()=>{a&&t.add("</row>"),a=!1},c=(f,l,i)=>t.add(`<cell r="${D(f)}${e+1}"${l?` t="${l}"`:""}>${i===null?"":`<v>${i}</v>`}</cell>`),h=()=>{r||(n.length&&t.add(`<definedNames>${n.join("")}</definedNames>`),t.add("<sheetDataSet>"),r=!0)};await x(s,(f,l)=>{switch(f){case 577:o={name:l.str()};break;case 586:if(o){l.skip(2);const i=l.u32();o.sheetId=i===0?void 0:i-1}break;case 585:o&&l.u32()>0&&(o.refersTo=O(l,u.sheets));break;case 587:o&&n.push(`<definedName${m({name:o.name,refersTo:o.refersTo,sheetId:o.sheetId})}/>`),o=null;break;case 363:{h();const i=l.u32(),p=l.u8();t.add(`<sheetData${m({sheetId:i,refreshError:(p&1)!==0})}>`);break}case 364:d(),t.add("</sheetData>");break;case 366:d(),e=l.u32(),t.add(`<row r="${e+1}">`),a=!0;break;case 368:c(l.u32(),"",I(l.f64()));break;case 369:c(l.u32(),"b",l.u8()?1:0);break;case 370:c(l.u32(),"e",L[l.u8()]??"#N/A");break;case 371:c(l.u32(),"str",S(l.str()));break;default:}},()=>t.flush()),r?t.add("</sheetDataSet>"):n.length&&t.add(`<definedNames>${n.join("")}</definedNames>`),t.add("</externalBook></externalLink>"),await t.flush(!0)}const P=["ghostRow","ghostCol","edit","delete","copy","pasteAll","pasteFormulas","pasteValues","pasteFormats","pasteComments","pasteDataValidation","pasteBorders","pasteColWidths","pasteNumberFormats","merge","splitFirst","splitAll","rowColShift","clearAll","clearFormats","clearContents","clearComments","assign",,,,,,"coerce","adjust","cellMeta"],z=new Set(["XLDAPR","XLRICHVALUE"]);async function oe(s){const t=[],u=new Map,n={cells:[],values:[]};let o=null,r=null;await x(s,(l,i)=>{switch(l){case 335:{const p=i.u32(),w=i.u32(),b={};P.forEach((R,v)=>{p&1<<v&&(b[R]=!0)}),t.push({name:i.str(),version:w,on:b});break}case 339:i.skip(4),o=[],u.set(i.str(),o);break;case 340:o=null;break;case 52:o?.push("");break;case 4096:o?.length&&(o[o.length-1]='<ext uri="{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}"><xda:dynamicArrayProperties fDynamic="1" fCollapsed="0"/></ext>');break;case 5002:i.skip(4),o?.length&&(o[o.length-1]=`<ext uri="{3e2802c4-a4d2-4d8b-9148-e3be6c30e623}"><xlrd:rvb i="${i.u32()}"/></ext>`);break;case 337:i.skip(4),r=i.u32()?"cells":"values";break;case 338:r=null;break;case 51:if(r){const p=[];for(let w=i.u32();w>0&&i.left>=8;w--)p.push([i.u32()-1,i.u32()]);n[r].push(p)}break;default:}});const e=new Map,a=t.filter((l,i)=>z.has(l.name)&&e.set(i,e.size+1)),d={cells:new Map,values:new Map,lost:a.length<t.length},c={cells:[],values:[]};for(const l of["cells","values"])n[l].forEach((i,p)=>{const w=i.filter(([b])=>e.has(b));w.length!==0&&(c[l].push(`<bk>${w.map(([b,R])=>`<rc t="${e.get(b)}" v="${R}"/>`).join("")}</bk>`),d[l].set(p+1,c[l].length))});const h=a.map(l=>{const i=(u.get(l.name)??[]).map(p=>p?`<bk><extLst>${p}</extLst></bk>`:"<bk/>");return i.length?`<futureMetadata name="${l.name}" count="${i.length}">${i.join("")}</futureMetadata>`:""}).join(""),f=(l,i)=>i.length?`<${l} count="${i.length}">${i.join("")}</${l}>`:"";return d.xml=`${g}<metadata xmlns="${k}" xmlns:xlrd="http://schemas.microsoft.com/office/spreadsheetml/2017/richdata" xmlns:xda="http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray">`+f("metadataTypes",a.map(l=>`<metadataType${m({name:l.name,minSupportedVersion:l.version,...l.on})}/>`))+`${h}${f("cellMetadata",c.cells)}${f("valueMetadata",c.values)}</metadata>`,d}async function le(s){let t="",u="",n="",o="",r="";return await x(s,(e,a)=>{if(e===651){a.skip(2);const d=j(a),c=a.left>=4?a.str():"";(c||d&&d!==' auto="1"')&&(t=`<sheetPr${m({codeName:c||void 0})}>${d&&d!==' auto="1"'?`<tabColor${d}/>`:""}</sheetPr>`)}else if(e===141){const d=a.u16(),c=a.u32(),h=a.u32();u=`<sheetViews><sheetView${m({tabSelected:(d&1)!==0,zoomScale:c||void 0,workbookViewId:h})}/></sheetViews>`}else if(e===476){const[d,c,h,f,l,i]=Array.from({length:6},()=>I(a.f64()));n=`<pageMargins${m({left:d,right:c,top:h,bottom:f,header:l,footer:i})}/>`}else if(e===652){const d=a.u32();a.skip(16);const c=a.u16();o=`<pageSetup${m({paperSize:d||void 0,orientation:c&4?void 0:c&1?"landscape":"portrait"})}/>`}else e===550&&(r=`<drawing r:id="${y(a.nstr()??"")}"/>`)}),`${g}<chartsheet xmlns="${k}" xmlns:r="${C}">${t}${u||'<sheetViews><sheetView workbookViewId="0"/></sheetViews>'}${n}${o}${r}</chartsheet>`}export{le as chartSheetXml,ae as readExternalNames,oe as readMetadata,ee as readTable,te as tableXml,se as writeComments,ne as writeExternal,Z as writeStrings};
@@ -0,0 +1 @@
1
+ import{xmlAttr as O}from"../xml-escape.js";import{attrs as $,fullRangeText as N,NS_MAIN as M,NS_R as J,offOnly as r,XML_HEAD as L}from"./xml.js";import{eachRecord as B,numberText as C,Reader as K}from"./records.js";import{ERROR_TEXT as W,readFormula as ee,skipFormula as te}from"./formula.js";import{filterReader as ne}from"./filter.js";const q="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",ae=[void 0,"seconds","minutes","hours","days","months","quarters","years"],S=(e,s=2)=>String(e).padStart(s,"0");function j(e,s,o,n,l,d){return o===0?`1899-12-31T${S(n)}:${S(l)}:${S(d)}`:`${S(e,4)}-${S(s)}-${S(o)}T${S(n)}:${S(l)}:${S(d)}`}function _(e,s){const o=Math.floor(e),n=Math.round((e-o)*86400),l=new Date((o+(s?1462:o<60?1:0)-25569)*864e5+n*1e3);return j(l.getUTCFullYear(),l.getUTCMonth()+1,l.getUTCDate(),l.getUTCHours(),l.getUTCMinutes(),l.getUTCSeconds())}const H=e=>j(e.u16(),e.u16(),e.u8(),e.u8(),e.u8(),e.u8());function G(e,s){const o=e>=27?e-7:e;let n,l;switch(o){case 20:n="m";break;case 21:n="n",l=C(s.f64());break;case 22:n="b",l=s.u8()?"1":"0";break;case 23:n="e",l=W[s.u8()]??"#N/A";break;case 24:n="s",l=O(s.str());break;case 25:n="d",l=H(s);break;default:return null}let d="";if(e>=27){const u=s.u16();d=$({u:(u&1)!==0,f:(u&2)!==0,c:u&4?s.nstr():void 0})}return`<${n}${l===void 0?"":` v="${l}"`}${d}/>`}function U(e,s){const o=e.u16();for(let n=e.u32();n>0;n--)if(o===1)s(`<n v="${C(e.f64())}"/>`);else if(o===2)s(`<s v="${O(e.str())}"/>`);else if(o===16)s(`<e v="${W[e.u8()]??"#N/A"}"/>`);else if(o===32)s(`<d v="${H(e)}"/>`);else return}const se=e=>/^[\p{L}_][\p{L}\p{N}_.]*$/u.test(e)?e:`'${e.replace(/'/g,"''")}'`;async function Te(e,s){const o={head:null,kind:-1,source:"",fields:[],recordsRel:null,id14:0,unreadable:!1};await Q(e,s,o,null);for(const n of o.fields)if(n.formula)try{const l=d=>se(o.fields[n.names[d]]?.name??oe());n.head.formula=ee(new K(n.formula),{...s,pivotName:l},{row:0,col:0})}catch{o.unreadable=!0}return o}async function Se(e,s,o,n){s.add(`${L}<pivotCacheDefinition xmlns="${M}" xmlns:r="${J}"${$({"r:id":n.recordsRel||void 0,...n.head})}><cacheSource type="worksheet">${n.source}</cacheSource><cacheFields count="${n.fields.length}">`),await Q(e,o,{...n,fields:[]},s,n.fields),s.add("</cacheFields>"+(n.id14?`<extLst><ext xmlns:x14="${q}" uri="{725AE2AE-9491-48be-B2B4-4EB974FC3084}"><x14:pivotCacheDefinition pivotCacheId="${n.id14}"/></ext></extLst>`:"")+"</pivotCacheDefinition>"),await s.flush(!0)}async function Q(e,s,o,n,l=null){const d=v=>n?.add(v);let u=null,c=!1,p=!1,x=null,f=-1;await B(e,(v,a)=>{switch(v){case 179:{const[h,k,g]=[a.u8(),a.u8(),a.u8()],b=a.u8(),t=a.i32(),i=a.f64(),m=a.u8(),w=a.u32(),F=m&1?a.str():void 0;o.recordsRel=m&2?a.nstr():null,o.head={saveData:r((b&1)!==0),invalid:(b&2)!==0,refreshOnLoad:(b&4)!==0,optimizeMemory:(b&8)!==0,enableRefresh:r((b&16)!==0),backgroundQuery:(b&32)!==0,upgradeOnRefresh:(b&64)!==0,missingItemsLimit:t===-1?void 0:t,refreshedBy:F,refreshedDate:i?C(i):void 0,createdVersion:g||void 0,refreshedVersion:h||void 0,minRefreshableVersion:k||void 0,recordCount:b&1?w:void 0};break}case 185:o.kind=a.u32();break;case 187:{const h=(a.u8()&1)!==0;a.skip(1);const k=a.u8(),g=k&2?a.str():void 0,b=k&1?a.nstr():void 0,t=h?a.str():void 0,i=h?void 0:N(a.range());o.source=`<worksheetSource${$({ref:i,name:t,sheet:g,"r:id":b||void 0})}/>`;break}case 183:{const h=a.u16(),k=a.u32(),g=a.u16();a.skip(8);const b=a.u32(),t=a.str(),i=h&8?a.str():void 0;if(u={name:t,database:(h&4)!==0,numeric:!1,dates:!1},u.head={name:t,caption:i,numFmtId:k===4294967295?void 0:k&65535,databaseField:r(u.database),sqlType:g||void 0},h&256){const m=a.pos;te(a),u.formula=a.buf.slice(m,a.pos)}b&&(u.olap=!0),o.fields.push(u),f++,d(`<cacheField${$(l?.[f]?.head??u.head)}>`);break}case 189:{const h=a.u16(),k=a.u32(),[g,b]=h&256?[a.f64(),a.f64()]:[],t=(h&4)!==0,i=m=>t?_(m,s.date1904):C(m);u.numeric=(h&64)!==0,u.dates=t&&!(h&8),u.count=k,d(`<sharedItems${$({containsSemiMixedTypes:r((h&1)!==0),containsNonDate:r((h&2)!==0),containsDate:t,containsString:r((h&8)!==0),containsBlank:(h&16)!==0,containsMixedTypes:(h&32)!==0,containsNumber:(h&64)!==0,containsInteger:(h&128)!==0,...g===void 0||t&&h&32?{}:t?{minDate:i(g),maxDate:i(b)}:{minValue:i(g),maxValue:i(b)},count:k||void 0,longText:(h&512)!==0})}>`),c=!0;break}case 190:d("</sharedItems>"),c=!1;break;case 219:{const h=a.i32(),k=a.i32();d(`<fieldGroup${$({par:h<0?void 0:h,base:k<0?void 0:k})}>`),p=!0;break}case 220:p&&d("</fieldGroup>"),p=!1;break;case 223:{const h=a.u8(),k=a.u8(),[g,b,t]=[a.f64(),a.f64(),a.f64()],i=(k&4)!==0;p&&d(`<rangePr${$({autoStart:r((k&1)!==0),autoEnd:r((k&2)!==0),groupBy:ae[h],...i?{startDate:_(g,s.date1904),endDate:_(b,s.date1904)}:{startNum:C(g),endNum:C(b)},groupInterval:t===1?void 0:C(t)})}/>`);break}case 225:case 221:c=p,p&&d(`<${v===225?"discretePr":"groupItems"} count="${a.u32()}">`);break;case 226:case 222:p&&d(v===226?"</discretePr>":"</groupItems>"),c=!1;break;case 26:c&&d(`<x v="${a.u32()}"/>`);break;case 191:c&&n&&U(a,d);break;case 253:x=[];break;case 255:x?.push(a.i32());break;case 184:u&&(u.names=x??[]),u&&d("</cacheField>"),x=null,u=null;break;case 243:o.unreadable=!0;break;case 195:o.olap=!0;break;case 1066:a.skip(5),a.left>=4&&(o.id14=a.u32());break;default:v>=20&&v<=32&&c&&n&&d(G(v,a))}},()=>n?.flush())}const oe=()=>{throw new Error("Formula: an unknown field")};async function De(e,s,o){const n=o.fields.filter(c=>c.database);let l=!1;const d=()=>{l&&s.add("</r>"),l=!1};s.add(`${L}<pivotCacheRecords xmlns="${M}"`);let u=!1;await B(e,(c,p)=>{if(c===193)s.add(` count="${p.u32()}">`),u=!0;else if(c===33){d();let x="<r>";for(const f of n)f.count?x+=`<x v="${p.u32()}"/>`:f.numeric?x+=`<n v="${C(p.f64())}"/>`:f.dates?x+=`<d v="${H(p)}"/>`:x+=`<s v="${O(p.str())}"/>`;s.add(`${x}</r>`)}else c===34?(d(),s.add("<r>"),l=!0):l&&c===26?s.add(`<x v="${p.u32()}"/>`):l&&c===191?U(p,x=>s.add(x)):l&&s.add(G(c,p)??"")},()=>s.flush()),d(),s.add(`${u?"":">"}</pivotCacheRecords>`),await s.flush(!0)}const X=[void 0,"default","sum","countA","avg","max","min","product","count","stdDev","stdDevP","var","varP","grand","blank"],ie={1:"axisRow",2:"axisCol",4:"axisPage",8:"axisValues"},de=[void 0,"count","average","max","min","product","countNums","stdDev","stdDevp","var","varp"],le=[void 0,"difference","percent","percentDiff","runTotal","percentOfRow","percentOfCol","percentOfTotal","index"],Y={9:"percentOfParentRow",10:"percentOfParentCol",11:"percentOfParent",12:"percentOfRunningTotal",13:"rankAscending",14:"rankDescending"},ue=["unknown","count","percent","sum","captionEqual","captionNotEqual","captionBeginsWith","captionNotBeginsWith","captionEndsWith","captionNotEndsWith","captionContains","captionNotContains","captionGreaterThan","captionGreaterThanOrEqual","captionLessThan","captionLessThanOrEqual","captionBetween","captionNotBetween","valueEqual","valueNotEqual","valueGreaterThan","valueGreaterThanOrEqual","valueLessThan","valueLessThanOrEqual","valueBetween","valueNotBetween","dateEqual","dateOlderThan","dateNewerThan","dateBetween","tomorrow","today","yesterday","nextWeek","thisWeek","lastWeek","nextMonth","thisMonth","lastMonth","nextQuarter","thisQuarter","lastQuarter","nextYear","thisYear","lastYear","yearToDate","Q1","Q2","Q3","Q4","M1","M2","M3","M4","M5","M6","M7","M8","M9","M10","M11","M12","dateNotEqual","dateOlderThanOrEqual","dateNewerThanOrEqual","dateNotBetween"],z=["sumSubtotal","countASubtotal","avgSubtotal","maxSubtotal","minSubtotal","productSubtotal","countSubtotal","stdDevSubtotal","stdDevPSubtotal","varSubtotal","varPSubtotal"],V=4294967295,Z=e=>e===V||e===0?void 0:e&65535;function ce(e){const s=e.u8(),o=e.u8(),n=e.u8(),l=e.u8(),d=e.u8(),u=e.u8(),c=e.u8(),p=e.u8(),x=e.u8(),f=e.u8();e.skip(2);const v=e.u8(),a=e.u8(),h=e.u8(),k=e.u8(),g=e.i32(),b=e.u16();e.skip(2);const t=e.u32(),i=e.u32(),m=e.str(),w=c&8?e.str():"Values",F=c&16?e.str():void 0,T=x&64?void 0:e.str(),D=x&128?void 0:e.str(),E=c&32?e.str():void 0,A=c&64?e.str():void 0,R=c&128?e.str():void 0,I=p&64?e.str():void 0,P=f&8?e.str():void 0,y=f&4?e.str():void 0;return{name:m,cacheId:i,dataOnRows:v===1,dataPosition:g<0?void 0:g,autoFormatId:b||void 0,applyNumberFormats:p&1?"1":"0",applyBorderFormats:p&8?"1":"0",applyFontFormats:p&2?"1":"0",applyPatternFormats:p&16?"1":"0",applyAlignmentFormats:p&4?"1":"0",applyWidthHeightFormats:p&32?"1":"0",dataCaption:w,grandTotalCaption:F,errorCaption:T,showError:(u&2)!==0,missingCaption:D,showMissing:r((u&4)!==0),pageStyle:E,pivotTableStyle:A,vacatedStyle:R,tag:I,updatedVersion:h||void 0,minRefreshableVersion:k||void 0,showItems:r((o&1)!==0),editData:(o&2)!==0,disableFieldList:(o&4)!==0,showCalcMbrs:r(!(o&16)),visualTotals:r(!(o&32)),showMultipleLabel:r((o&64)!==0),showDataDropDown:r(!(n&1)),showDrill:r(!(n&16)),printDrill:(n&32)!==0,showMemberPropertyTips:r((n&64)!==0),showDataTips:r(!(n&128)),enableWizard:r((d&16)!==0),enableDrill:r((d&32)!==0),enableFieldProperties:r((d&64)!==0),preserveFormatting:r((d&128)!==0),useAutoFormatting:(u&1)!==0,pageWrap:a||void 0,pageOverThenDown:(u&8)!==0,subtotalHiddenItems:(u&16)!==0,rowGrandTotals:r((u&32)!==0),colGrandTotals:r((u&64)!==0),fieldPrintTitles:(u&128)!==0,itemPrintTitles:(c&2)!==0,mergeItem:(c&4)!==0,showDropZones:r(!(d&1)),createdVersion:s||void 0,indent:(l&127)===1?void 0:l&127,showEmptyRow:(d&4)!==0,showEmptyCol:(d&8)!==0,showHeaders:r(!(l&128)),compact:r((x&1)!==0),outline:(x&2)!==0,outlineData:(x&4)!==0,compactData:r((x&8)!==0),published:(x&32)!==0,gridDropZones:(x&16)!==0,immersive:r(!(f&1)),multipleFieldFilters:r(!(f&2)),chartFormat:t||void 0,rowHeaderCaption:y,colHeaderCaption:P,fieldListSortAscending:(f&16)!==0,customListSort:r(!(f&64))}}function re(e){const s=e.u8(),o=e.u16(),n=e.u8(),l=e.u32(),d=e.u32(),u=e.u32(),c=e.i32(),p=n&32?e.str():void 0,x=n&64?e.str():void 0,f=a=>(d&1<<a)!==0,v={name:p,axis:ie[s&7],dataField:(s&8)!==0,subtotalCaption:x,showDropDowns:r(!(n&2)),hiddenLevel:(n&4)!==0,compact:r((n&16)!==0),allDrilled:(n&1)!==0,numFmtId:Z(l),outline:r(f(6)),subtotalTop:r(f(8)),dragToRow:r(f(0)),dragToCol:r(f(1)),multipleItemSelectionAllowed:f(19),dragToPage:r(f(2)),dragToData:r(f(4)),dragOff:r(f(3)),showAll:r(f(5)),insertBlankRow:f(7),serverField:f(9),insertPageBreak:f(11),autoShow:f(14),topAutoShow:r(f(15)),hideNewItems:f(16),measureFilter:f(17),includeNewItemsInFilter:f(18),itemPageCount:u===10?void 0:u,sortType:f(12)?f(13)?"ascending":"descending":void 0,nonAutoSortDefault:f(20),rankBy:c<0?void 0:c,defaultSubtotal:r((o&1)!==0)};return z.forEach((a,h)=>{v[a]=(o&2<<h)!==0}),v}const fe=["none",void 0,"data","all","origin","button","topEnd"],pe={1:"axisRow",2:"axisCol",4:"axisPage",8:"axisValues"},me=["selection","data","field"],he=[void 0,"all","row","column"];function be(e){const s=e.i32(),o=e.u32(),n=u=>(o>>>u&1)!==0,l=pe[o>>>16&15],d={field:s===-1?void 0:s,type:fe[o&255],dataOnly:r(n(8)),labelOnly:n(9),grandRow:n(10),grandCol:n(11),cacheIndex:n(12),outline:r(n(13)),collapsedLevelsAreSubtotals:n(15),axis:l,fieldPosition:l&&l!=="axisValues"?o>>>20&255:void 0};return n(14)&&(d.offset=N(e.range())),{attrs:d,refs:[]}}function xe(e){const s=e.u32();e.skip(4);const o=e.u16(),n=(e.u8()&1)!==0,l={field:s,selected:r(n),defaultSubtotal:(o&2)!==0};return z.forEach((d,u)=>{l[d]=(o&4<<u)!==0}),{attrs:l,items:[]}}const ge=({attrs:e,refs:s})=>{const o=s.map(n=>`<reference${$({field:n.attrs.field,count:n.items.length,...n.attrs})}>${n.items.map(l=>l?`<x v="${l}"/>`:'<x v="0"/>').join("")}</reference>`);return o.length?`<pivotArea${$(e)}><references count="${o.length}">${o.join("")}</references></pivotArea>`:`<pivotArea${$(e)}/>`};async function Ce(e){let s={},o="",n="";const l=[],d={rowFields:[],colFields:[],rowItems:[],colItems:[],pageFields:[],dataFields:[],formats:[],conditionalFormats:[],chartFormats:[],filters:[]};let u=null,c=null,p=null,x=null,f=null,v=null,a=null,h=null;const k=()=>{if(!h)return;const{ext:b,...t}=h;d.dataFields.push(b?`<dataField${$(t)}><extLst><ext xmlns:x14="${q}" uri="{E15A36E0-9728-4e99-A89B-3F7291B0FE68}"><x14:dataField pivotShowAs="${b}"/></ext></extLst></dataField>`:`<dataField${$(t)}/>`),h=null};await B(e,(b,t)=>{if(!a?.reader.record(b,t))switch(b){case 280:s=ce(t);break;case 314:{const i=t.range(),m=N(i),[w,F,T,D,E]=[t.u32(),t.u32(),t.u32(),t.u32(),t.u32()];o=`<location${$({ref:m,firstHeaderRow:w-i.r1,firstDataRow:F-i.r1,firstDataCol:T-i.c1,rowPageCount:D||void 0,colPageCount:E||void 0})}/>`;break}case 285:p={open:re(t),items:[],sort:"",ext:""};break;case 286:{if(!p)break;const i=(p.items.length?`<items count="${p.items.length}">${p.items.join("")}</items>`:"")+p.sort+(p.ext?`<extLst><ext xmlns:x14="${q}" uri="{2946ED86-A175-432a-8AC1-64E0C546D7DE}">${p.ext}</ext></extLst>`:"");l.push(i?`<pivotField${$(p.open)}>${i}</pivotField>`:`<pivotField${$(p.open)}/>`),p=null;break}case 282:{const i=t.u8(),m=t.u16(),w=t.u32(),F=m&16?t.str():void 0;p?.items.push(`<item${$({n:F,t:X[i],h:(m&1)!==0,sd:m&2?"0":void 0,f:(m&4)!==0,m:(m&8)!==0,x:i===0&&w!==V?w:void 0})}/>`);break}case 1061:t.skip(4),p&&t.u32()&&(p.ext='<x14:pivotField fillDownLabels="1"/>');break;case 459:v={refs:[]};break;case 247:u=c?be(t):null;break;case 248:u&&c?.areas.push(ge(u)),u=null;break;case 303:{const i=t.u16()!==0,m=t.u32();c={tag:"format",open:$({action:i?void 0:"blank",dxfId:i&&m!==V?m:void 0}),areas:[]};break}case 558:{const[i,m,w]=[t.u32(),t.u32(),t.u32()];c={tag:"conditionalFormat",open:$({scope:me[i],type:he[m],priority:w}),areas:[]};break}case 481:{const[i,m,w]=[t.u32(),t.u32(),t.u32()];c={tag:"chartFormat",open:$({chart:i,format:m,series:w!==0}),areas:[]};break}case 304:case 482:c?.areas.length&&d[c.tag==="format"?"formats":"chartFormats"].push(`<${c.tag}${c.open}>${c.areas[0]}</${c.tag}>`),c=null;break;case 559:c?.areas.length&&d.conditionalFormats.push(`<conditionalFormat${c.open}><pivotAreas count="${c.areas.length}">${c.areas.join("")}</pivotAreas></conditionalFormat>`),c=null;break;case 251:if(u){u.refs.push(xe(t));break}v&&(v.refs.push({field:t.u32(),items:[]}),t.skip(4));break;case 382:if(u){u.refs.at(-1)?.items.push(t.u32());break}v?.refs.at(-1)?.items.push(t.u32());break;case 460:if(v&&p){const i=v.refs.map(m=>`<reference field="${m.field}" count="${m.items.length}" selected="0">${m.items.map(w=>`<x v="${w}"/>`).join("")}</reference>`);p.sort=`<autoSortScope><pivotArea dataOnly="0" outline="0" fieldPosition="0">${i.length?`<references count="${i.length}">${i.join("")}</references>`:""}</pivotArea></autoSortScope>`}v=null;break;case 309:case 311:for(let i=t.u32();i>0;i--)d[b===309?"rowFields":"colFields"].push(`<field x="${t.i32()}"/>`);break;case 299:x=d.rowItems;break;case 301:x=d.colItems;break;case 300:case 302:x=null;break;case 297:{const i=t.u16(),m=t.u8();t.skip(1);const w=t.u32(),F=t.u32();f={open:$({t:X[m],r:i||void 0,i:F||void 0}),count:w,items:[]};break}case 388:for(let i=f?.count??0;i>0&&t.left>=4;i--){const m=t.u32();f.items.push(m?`<x v="${m}"/>`:"<x/>")}break;case 298:f&&x?.push(f.items.length?`<i${f.open}>${f.items.join("")}</i>`:`<i${f.open}/>`),f=null;break;case 289:{const i=t.i32(),m=t.u32(),w=t.i32(),F=t.u8(),T=F&1?t.str():void 0;d.pageFields.push(`<pageField${$({fld:i,item:m<1048829?m:void 0,hier:w,name:T,cap:F&2?t.str():void 0})}/>`);break}case 293:{k();const i=t.i32(),m=t.u32(),w=t.u32(),F=t.i32(),T=t.u32(),D=t.u32();h={name:t.u8()?t.str():void 0,fld:i,subtotal:de[m],showDataAs:le[w],baseField:F,baseItem:T,numFmtId:Z(D),ext:Y[w]};break}case 1044:t.skip(4),h&&(h.ext=Y[t.u32()]??h.ext);break;case 296:k();break;case 601:{const i=t.i32(),m=t.i32(),w=t.u32();t.skip(4);const F=t.u32(),T=t.i32(),D=t.i32(),E=t.u16(),[A,R,I,P]=[1,2,4,8].map(y=>E&y?t.str():void 0);a={reader:ne(),open:$({fld:i,mpFld:m<0?void 0:m,type:ue[w]??"unknown",evalOrder:"-1",id:F,iMeasureHier:D<0?void 0:D,iMeasureFld:T<0?void 0:T,name:A,description:R,stringValue1:I,stringValue2:P})};break}case 602:a&&d.filters.push(`<filter${a.open}>${a.reader.text()}</filter>`),a=null;break;case 513:{const i=t.u16();n=`<pivotTableStyleInfo${$({name:t.nstr()||void 0,showRowHeaders:i&16?"1":"0",showColHeaders:i&32?"1":"0",showRowStripes:i&4?"1":"0",showColStripes:i&8?"1":"0",showLastColumn:i&2?"1":"0"})}/>`;break}default:}});const g=b=>d[b].length?`<${b} count="${d[b].length}">${d[b].join("")}</${b}>`:"";return`${L}<pivotTableDefinition xmlns="${M}"${$(s)}>${o}`+(l.length?`<pivotFields count="${l.length}">${l.join("")}</pivotFields>`:"")+g("rowFields")+g("rowItems")+g("colFields")+g("colItems")+g("pageFields")+g("dataFields")+g("formats")+g("conditionalFormats")+g("chartFormats")+n+g("filters")+"</pivotTableDefinition>"}export{ie as AXES,de as FUNCTIONS,ae as GROUP_BY,X as ITEM_TYPES,le as SHOW_AS,z as SUBTOTALS,se as fieldName,j as isoDate,Ce as pivotTableXml,Te as readPivotCache,_ as serialIso,Se as writePivotCache,De as writePivotRecords};
@@ -0,0 +1 @@
1
+ const R=268435456,v=new TextDecoder("utf-16le");class m{constructor(t,e=0,s=t.length){this.reset(t),this.pos=e,this.end=s}reset(t){this.buf=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength)}get left(){return this.end-this.pos}take(t){const e=this.pos;if(t<0||e+t>this.end)throw new Error("The file is damaged: a record ends too early");return this.pos=e+t,e}skip(t){this.take(t)}u8(){return this.buf[this.take(1)]}u16(){return this.view.getUint16(this.take(2),!0)}i16(){return this.view.getInt16(this.take(2),!0)}u24(){const t=this.take(3);return this.buf[t]|this.buf[t+1]<<8|this.buf[t+2]<<16}u32(){return this.view.getUint32(this.take(4),!0)}i32(){return this.view.getInt32(this.take(4),!0)}f64(){return this.view.getFloat64(this.take(8),!0)}chars(t){const e=this.take(t*2);if(t>24)return v.decode(this.buf.subarray(e,e+t*2));let s="";for(let i=0;i<t;i++)s+=String.fromCharCode(this.view.getUint16(e+i*2,!0));return s}str(){return this.chars(this.u32())}nstr(){const t=this.u32();return t===4294967295?null:this.chars(t)}lpstr(){return this.chars(this.u16())}rk(){const t=this.take(4),e=this.view.getInt32(t,!0);let s;return e&2?s=e>>2:(x.setInt32(4,e&-4,!0),s=x.getFloat64(0,!0)),e&1?s/100:s}range(){const t=this.u32(),e=this.u32(),s=this.u32(),i=this.u32();return{r1:t,c1:s,r2:e,c2:i}}ranges(){const t=[],e=this.u32();if(e*16>this.left)throw new Error("The file is damaged: a list of ranges ends too early");for(let s=0;s<e;s++)t.push(this.range());return t}}const x=new DataView(new ArrayBuffer(8));function A(u){return Object.is(u,-0)?"0":String(u).replace("e","E")}async function E(u,t,e){const s=u.getReader(),i=new m(new Uint8Array(0));let a=new Uint8Array(0),n=0,d=0;for(;;){const{done:y,value:g}=await s.read();if(y)break;let h=g;if(n>0){const r=n+g.length;if(r>a.length){const o=new Uint8Array(Math.max(r,a.length*2));o.set(a.subarray(0,n)),a=o}if(a.set(g,n),n=r,n<d)continue;h=a.slice(0,n),n=0,d=0}i.reset(h);let l=0;for(;;){let r=l;const o=h.length;if(r>=o)break;let c=h[r++];if(c&128){if(r>=o)break;c=c&127|(h[r++]&127)<<7}let f=0,b=!1;for(let w=0;w<4&&r<o;w++){const p=h[r++];if(f|=(p&127)<<7*w,!(p&128)||w===3){b=!0;break}}if(!b)break;if(f>268435456)throw new Error("The file is damaged: a record is too large");if(r+f>o){d=r+f-l;break}if(i.pos=r,i.end=r+f,l=r+f,t(c,i)===!1){await s.cancel().catch(()=>{}),await e?.();return}}if(l<h.length){const r=h.subarray(l);r.length>a.length&&(a=new Uint8Array(Math.max(r.length*2,4096))),a.set(r),n=r.length}const k=e?.();k!==void 0&&await k}if(n>0)throw new Error("The file is damaged: a part ends inside a record")}export{m as Reader,E as eachRecord,A as numberText};
@@ -0,0 +1 @@
1
+ import{escapeMarkup as B}from"../xml-escape.js";import{attrs as h,formulaXml as O,sqref as b}from"./xml.js";import{numberText as F}from"./records.js";import{readFormula as j,readFrtFormula as _,skipFormula as W}from"./formula.js";import{readColor as A}from"./styles.js";import{ICON_SETS as C}from"./filter.js";const q="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",L="http://schemas.microsoft.com/office/excel/2006/main";function v(n){let c=1/0,r=1/0;for(const l of n)c=Math.min(c,l.r1),r=Math.min(r,l.c1);return Number.isFinite(c)?{row:c,col:r}:{row:0,col:0}}function y(n,c,r){const l=n.u32(),a={ranges:[],formulas:[]};if(l&1)for(let s=n.u32();s>0;s--)n.skip(20);if(l&2)for(let s=n.u32();s>0;s--)n.skip(4),a.ranges.push(...n.ranges());if(l&4){const s=r(a.ranges);for(let x=n.u32();x>0;x--)n.skip(4),a.formulas.push(_(n,c,s))}return l&8&&n.lpstr(),a}function I(n,c){try{return n()}catch{return c(),null}}const S=(n,c)=>c.map(r=>n[r].toString(16).toUpperCase().padStart(2,"0")).join("");function R(n){const c=n.take(16),r=n.buf.subarray(c,c+16);return`{${S(r,[3,2,1,0])}-${S(r,[5,4])}-${S(r,[7,6])}-${S(r,[8,9])}-${S(r,[10,11,12,13,14,15])}}`}const X=[void 0,"whole","decimal","list","date","time","textLength","custom"],z=[void 0,"warning","information"],G=[void 0,"notBetween","equal","notEqual","greaterThan","lessThan","greaterThanOrEqual","lessThanOrEqual"];function oe(n,c,r,l=!1,a=null){let s=[],x=[];try{l&&({ranges:s,formulas:x}=y(n,c,v));const o=n.u32();l||(s=n.ranges());const[$,k,t,e]=[n.nstr(),n.nstr(),n.nstr(),n.nstr()],i=o&15;if(!l){const p=v(s);for(let g=0;g<2;g++){const d=n.u32();n.pos-=4,d?x.push(j(n,c,p)):(W(n),x.push(""))}}const[u="",m=""]=x,f=a??u;return`<dataValidation${h({type:X[i],errorStyle:z[o>>4&7],operator:i===0||i===3||i===7?void 0:G[o>>20&15],allowBlank:(o&256)!==0,showDropDown:(o&512)!==0,showInputMessage:(o&262144)!==0,showErrorMessage:(o&524288)!==0,errorTitle:$,error:k,promptTitle:t,prompt:e,sqref:b(s)})}>${f?O("formula1",f.replace(/\0/g,",")):""}${m?O("formula2",m):""}</dataValidation>`}catch{return r(),""}}const H=[void 0,"between","notBetween","equal","notEqual","greaterThan","lessThan","greaterThanOrEqual","lessThanOrEqual"],V=[["containsText","containsText"],["notContainsText","notContains"],["beginsWith","beginsWith"],["endsWith","endsWith"]],U=["today","yesterday","last7Days","thisWeek","lastWeek","lastMonth","tomorrow","nextWeek","nextMonth","thisMonth"],Y={1:"num",2:"min",3:"max",4:"percent",5:"percentile",7:"formula",8:"autoMin",9:"autoMax"},D=[...C,"3Stars","3Triangles","5Boxes"],M=4294967295;function J(n,c,r){if(n===1)return{type:"cellIs",operator:H[r]};if(n===3)return{type:"colorScale"};if(n===4)return{type:"dataBar"};if(n===5)return{type:"top10",rank:r};if(n===6)return{type:"iconSet"};switch(c){case 7:return{type:"uniqueValues"};case 8:return{type:V[r]?.[0]??"containsText",operator:V[r]?.[1]};case 9:return{type:"containsBlanks"};case 10:return{type:"notContainsBlanks"};case 11:return{type:"containsErrors"};case 12:return{type:"notContainsErrors"};case 15:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:case 24:return{type:"timePeriod",timePeriod:U[r]};case 25:return{type:"aboveAverage",stdDev:r||void 0};case 26:return{type:"aboveAverage",aboveAverage:"0",stdDev:r||void 0};case 27:return{type:"duplicateValues"};case 29:return{type:"aboveAverage",equalAverage:!0};case 30:return{type:"aboveAverage",aboveAverage:"0",equalAverage:!0};default:return{type:"expression"}}}function re(n,c){const r=[],l=[];let a=null,s=null;const x=(t,e)=>{let i=[];e&&({formulas:i}=y(t,n,()=>v(a.ranges)));const u=t.u32(),m=t.u32(),f=t.u32(),p=t.i32(),g=t.u32();t.skip(8);const d=t.u16(),E=[t.u32(),t.u32(),t.u32()];let T=null;e&&(t.skip(4),T=R(t),t.u32()||(T=null));const w=t.nstr();if(!e){const N=v(a.ranges);i=E.filter(P=>P).map(()=>j(t,n,N))}s={kind:u,future:e,id:T,formulas:i,dxfId:f,priority:p,cfvo:[],colors:[],icons:[],settings:{},head:{...J(u,m,g)}},u===5&&Object.assign(s.head,{percent:(d&16)!==0,bottom:(d&8)!==0}),s.head.operator&&u===2&&(s.head.text=w??""),s.stop=(d&2)!==0},o=(t,e="")=>{const i=`<${e}cfvo${h({type:t.type,...e?{}:{val:t.val??void 0},gte:t.gte?void 0:"0"})}`;return e&&t.val!==null?`${i}><xm:f>${B(t.val)}</xm:f></${e}cfvo>`:`${i}/>`},$=(t,e)=>`<${t}${e}/>`,k=()=>{const t=s;if(s=null,!t)return;const{settings:e}=t,i=t.kind===4&&t.future,u=t.kind===6&&t.future;if(!i&&!u){let f=t.formulas.map(d=>O("formula",d)).join("");t.kind===3?f+=`<colorScale>${t.cfvo.map(d=>o(d)).join("")}${t.colors.map(d=>$("color",d)).join("")}</colorScale>`:t.kind===4?f+=`<dataBar${h({minLength:e.min===10?void 0:e.min,maxLength:e.max===90?void 0:e.max,showValue:e.value?void 0:"0"})}>${t.cfvo.map(d=>o(d)).join("")}${t.colors.map(d=>$("color",d)).join("")}</dataBar>`:t.kind===6&&(f+=`<iconSet${h({iconSet:C[e.set]==="3TrafficLights1"?void 0:C[e.set],showValue:e.iconOnly?"0":void 0,reverse:e.reverse})}>${t.cfvo.map(d=>o(d)).join("")}</iconSet>`),t.link&&(f+=`<extLst><ext xmlns:x14="${q}" uri="{B025F937-C7B1-47D3-B67F-A62EFF666E3E}"><x14:id>${t.link}</x14:id></ext></extLst>`);const{type:p,...g}=t.head;a.rules.push(`<cfRule${h({type:p,dxfId:t.dxfId===M?void 0:t.dxfId,priority:t.priority,stopIfTrue:t.stop,...g})}>${f}</cfRule>`);return}let m;if(i){const f=[...t.colors],p=[e.border&&"borderColor",e.negFill&&"negativeFillColor",e.border&&e.negBorder&&"negativeBorderColor",e.axis!==2&&"axisColor"].filter(Boolean);f.length>p.length&&p.unshift("fillColor"),m=`<x14:dataBar${h({minLength:e.min,maxLength:e.max,showValue:e.value?void 0:"0",border:e.border,gradient:e.gradient?void 0:"0",direction:[void 0,"leftToRight","rightToLeft"][e.direction],negativeBarColorSameAsPositive:!e.negFill,negativeBarBorderColorSameAsPositive:e.negBorder?"0":void 0,axisPosition:[void 0,"middle","none"][e.axis]})}>${t.cfvo.map(g=>o(g,"x14:")).join("")}${f.map((g,d)=>p[d]?$(`x14:${p[d]}`,g):"").join("")}</x14:dataBar>`}else m=`<x14:iconSet${h({iconSet:D[e.set]??"3TrafficLights1",showValue:e.iconOnly?"0":void 0,reverse:e.reverse,custom:e.custom})}>${t.cfvo.map(f=>o(f,"x14:")).join("")}${t.icons.map(f=>`<x14:cfIcon${h({iconSet:f.set===M?"NoIcons":D[f.set],iconId:f.set===M?0:f.index})}/>`).join("")}</x14:iconSet>`;a.rules14.push(`<x14:cfRule${h({type:t.head.type,priority:t.id&&i?void 0:t.priority,id:t.id??void 0})}>${m}</x14:cfRule>`)};return{record(t,e){switch(t){case 461:{e.skip(4);const i=e.u32()!==0;return a={ranges:e.ranges(),pivot:i,rules:[],rules14:[]},!0}case 1046:{const{ranges:i}=y(e,n,v);return e.skip(4),a={ranges:i,pivot:e.u32()!==0,rules:[],rules14:[]},!0}case 462:case 1047:return a?.rules.length&&r.push(`<conditionalFormatting${h({pivot:a.pivot,sqref:b(a.ranges)})}>${a.rules.join("")}</conditionalFormatting>`),a?.rules14.length&&l.push(`<x14:conditionalFormatting xmlns:xm="${L}"${h({pivot:a.pivot})}>${a.rules14.join("")}<xm:sqref>${b(a.ranges)}</xm:sqref></x14:conditionalFormatting>`),a=null,!0;case 463:case 1048:if(s=null,a)try{x(e,t===1048)}catch{s=null,c()}return!0;case 464:case 1049:return k(),!0;default:}if(!s)return!1;switch(t){case 471:case 1050:{const i=I(()=>{const g=t===1050?y(e,n,()=>v(a.ranges)).formulas:[],d=e.u32(),E=e.f64();e.skip(4);const T=e.u32()!==0,w=e.u32();return{kind:d,number:E,gte:T,text:t===1050?g[0]:w?j(e,n,v(a.ranges)):void 0}},c);if(!i)return s=null,!0;const{kind:u,number:m,gte:f,text:p}=i;return s.cfvo.push({type:Y[u]??"num",val:u===2||u===3||u>7?null:p??F(m),gte:f}),!0}case 564:return s.colors.push(A(e)),!0;case 1055:return e.skip(4),s.colors.push(A(e)),!0;case 467:return Object.assign(s.settings,{min:e.u8(),max:e.u8(),value:e.u8()!==0}),!0;case 1051:{e.skip(4);const i={min:e.u8(),max:e.u8(),value:e.u8()!==0,direction:e.u8(),axis:e.u8()},u=e.u16();return Object.assign(s.settings,i,{border:(u&1)!==0,gradient:(u&2)!==0,negFill:(u&4)!==0,negBorder:(u&8)!==0}),!0}case 465:{const i=e.u32(),u=e.u16();return Object.assign(s.settings,{set:i,iconOnly:(u&2)!==0,reverse:(u&4)!==0}),!0}case 1052:{e.skip(4);const i=e.u32(),u=e.u16();return Object.assign(s.settings,{set:i,custom:(u&1)!==0,iconOnly:(u&2)!==0,reverse:(u&4)!==0}),!0}case 1112:return e.skip(4),s.icons.push({set:e.u32(),index:e.u32()}),!0;case 1146:return e.skip(4),s.link=R(e),!0;default:return!1}},finish:()=>({main:r.join(""),ext:l.length?`<ext xmlns:x14="${q}" uri="{78C0D931-6437-407d-A8EE-F0AAD7539E65}"><x14:conditionalFormattings>${l.join("")}</x14:conditionalFormattings></ext>`:""})}}const K=["colorSeries","colorNegative","colorAxis","colorMarkers","colorFirst","colorLast","colorHigh","colorLow"];function ie(n,c){const r=[];let l=null;return{record(a,s){if(a===1041){l=null;const x=I(()=>y(s,n,()=>({row:0,col:0})).formulas,c);if(!x)return!0;const o=s.u16(),$=K.map(f=>{const p=A(s);return p?`<x14:${f}${p}/>`:""}),k=s.f64(),t=s.f64(),e=s.f64(),i=s.u32(),u=!(o&10240),m=!(o&20480);return l={open:h({manualMax:u?F(k):void 0,manualMin:m?F(t):void 0,lineWeight:e&&e!==.75?F(e):void 0,type:[void 0,"column","stacked"][i],dateAxis:(o&1)!==0,displayEmptyCellsAs:["zero","gap","span"][o>>1&3],markers:(o&8)!==0,high:(o&16)!==0,low:(o&32)!==0,first:(o&64)!==0,last:(o&128)!==0,negative:(o&256)!==0,displayXAxis:(o&512)!==0,displayHidden:(o&1024)!==0,minAxisType:o&16384?"group":m?"custom":void 0,maxAxisType:o&8192?"group":u?"custom":void 0,rightToLeft:(o&32768)!==0}),body:$.join("")+(o&1&&x[0]?`<xm:f>${B(x[0])}</xm:f>`:""),items:[]},!0}if(a===1043&&l){const x=I(()=>y(s,n,()=>({row:0,col:0})),c);if(!x)return!0;const{ranges:o,formulas:$}=x;return l.items.push(`<x14:sparkline>${$[0]?`<xm:f>${B($[0])}</xm:f>`:""}<xm:sqref>${b(o)}</xm:sqref></x14:sparkline>`),!0}return a===1042&&l?(r.push(`<x14:sparklineGroup${l.open}>${l.body}<x14:sparklines>${l.items.join("")}</x14:sparklines></x14:sparklineGroup>`),l=null,!0):!1},finish:()=>r.length?`<ext xmlns:x14="${q}" uri="{05C60535-1F16-4fd2-B633-F4F36F0B64E0}"><x14:sparklineGroups xmlns:xm="${L}">${r.join("")}</x14:sparklineGroups></ext>`:""}}export{Y as CFVO,G as DV_OPERATORS,z as DV_STYLES,X as DV_TYPES,U as PERIODS,V as TEXT_RULES,v as anchor,re as conditionalFormats,oe as dataValidation,R as guidText,J as ruleType,ie as sparklines};
@@ -0,0 +1 @@
1
+ import{escapeMarkup as V,xmlText as Z}from"../xml-escape.js";import{cellRef as y,colName as fe}from"../../core/address.js";import{attrs as l,fullRangeText as O,NS_MAIN as me,NS_R as pe,rangeText as he,sqref as A,XML_HEAD as ge}from"./xml.js";import{eachRecord as ke,numberText as x}from"./records.js";import{deferredTo as be,ERROR_TEXT as ne,readFormula as q}from"./formula.js";import{readColor as $e,richText as we}from"./styles.js";import{readPassword as oe}from"./workbook.js";import{filterReader as xe}from"./filter.js";import{frtRelId as ae,sheetRefs as ve}from"./slicer.js";import{conditionalFormats as Ce,dataValidation as ie,sparklines as Le}from"./sheet-ext.js";const ce=16384,Re=[void 0,"pageBreakPreview","pageLayout"],W=["bottomRight","topRight","bottomLeft","topLeft"],Se=[void 0,"blank","dash","NA"],Pe=["sheetCalcPr","sheetProtection","protectedRanges","scenarios","autoFilter","sortState","mergeCells","conditionalFormatting","dataValidations","hyperlinks","printOptions","pageMargins","pageSetup","headerFooter","rowBreaks","colBreaks","cellWatches","ignoredErrors","drawing","legacyDrawing","legacyDrawingHF","picture","oleObjects","controls","tableParts","extLst"],le=R=>R?R.toString(16).toUpperCase().padStart(4,"0"):void 0;async function We(R,$,u){const{book:S,fonts:de}=u,p={props:"",dimension:"",views:[],format:"",cols:[]},f={},w=(a,e)=>(f[a]??=[]).push(e),v={row:0,col:0,sheet:u.index},T=xe();let G=!1,Y=0,k=-1,j=-1,z=!1,F=0,D=0,C=null;const J=new Map;let re=0,E=[],b=null,P=null,B=null,H=null,m=null,M=!1,_=null;const K=[],Q=[],I={sparklines:Le(S,u.onLost),cf:Ce(S,u.onLost)},ee=()=>{G||(G=!0,$.add(`${ge}<worksheet xmlns="${me}" xmlns:r="${pe}">${p.props}${p.dimension}`+(p.views.length?`<sheetViews>${p.views.join("")}</sheetViews>`:"")+p.format+(p.cols.length?`<cols>${p.cols.join("")}</cols>`:"")+"<sheetData>"))},te=()=>{z&&$.add("</row>"),z=!1},h=(a,e,t,s)=>{j=a,$.add(`<c r="${fe(a)}${k+1}"${e?` s="${e}"`:""}${t?` t="${t}"`:""}${F?` cm="${F}"`:""}${D?` vm="${D}"`:""}${s?`>${s}</c>`:"/>"}`),F=0,D=0},ue=()=>{if(!C)return;const a=C;C=null,u.onLost(),h(a.col,a.style,a.type,a.value)},N=(a,e,t,s,o)=>{const i=a.u16()&2?' ca="1"':"",c=be(a);if(v.row=k,v.col=e,c){const g=c.row*ce+c.col;if(c.row===k&&c.col===e){C={col:e,style:t,type:s,value:o};return}const r=J.get(g);r===void 0&&!E.some(L=>k>=L.r1&&k<=L.r2&&e>=L.c1&&e<=L.c2)&&u.onLost(),h(e,t,s,r>=0?`<f t="shared"${i} si="${r}"/>${o}`:o);return}let d="";try{d=`<f${i}>${V(q(a,S,v))}</f>`}catch{u.onLost()}d||(F=0),h(e,t,s,d+o)},X=a=>{if(!C)return;const e=C;C=null;let t="",s=-1;const o=k*ce+e.col;try{const n=a(e);t=n.xml,n.shared&&(s=re++,t=t.replace(' si=""',` si="${s}"`))}catch{u.onLost()}J.set(o,s),t||(F=0),h(e.col,e.style,e.type,t+e.value)};await ke(R,(a,e)=>{if(C&&a!==426&&a!==427&&a!==428&&ue(),a<=18||a===62){if(a===0){te(),k=e.u32();const n=e.u32(),i=e.u16(),c=e.u8(),d=e.u8(),g=e.u8();$.add(`<row r="${k+1}"${l({s:d&64?n:void 0,customFormat:(d&64)!==0,ht:i&&(i!==Y||d&32)?x(i/20):void 0,hidden:(d&16)!==0,customHeight:(d&32)!==0,outlineLevel:d&7||void 0,collapsed:(d&8)!==0,thickTop:(c&1)!==0,thickBot:(c&2)!==0,ph:(g&1)!==0})}>`),z=!0,j=-1;return}const t=a>=12&&a<=18,s=t?j+1:e.u32(),o=e.u24();switch(e.skip(1),t?a-11:a){case 1:h(s,o,"","");break;case 2:h(s,o,"",`<v>${x(e.rk())}</v>`);break;case 3:h(s,o,"e",`<v>${ne[e.u8()]??"#N/A"}</v>`);break;case 4:h(s,o,"b",`<v>${e.u8()?1:0}</v>`);break;case 5:h(s,o,"",`<v>${x(e.f64())}</v>`);break;case 6:h(s,o,"inlineStr",`<is>${ye(e.str())}</is>`);break;case 7:h(s,o,"s",`<v>${e.u32()}</v>`);break;case 62:h(s,o,"inlineStr",`<is>${we(e,de)}</is>`);break;case 8:{const n=`<v>${Z(e.str())}</v>`;N(e,s,o,"str",n);break}case 9:{const n=`<v>${x(e.f64())}</v>`;N(e,s,o,"",n);break}case 10:{const n=`<v>${e.u8()?1:0}</v>`;N(e,s,o,"b",n);break}default:{const n=`<v>${ne[e.u8()]??"#N/A"}</v>`;N(e,s,o,"e",n)}}return}if(a===423?M=!0:a===424&&(M=!1),!M&&!T.record(a,e)&&!(I.sparklines.record(a,e)||I.cf.record(a,e)))switch(a){case 49:{F=u.meta.cells.get(e.u32())??0;break}case 50:D=u.meta.values.get(e.u32())??0;break;case 427:{const t=O(e.range());X(s=>(v.row=k,v.col=s.col,{shared:!0,xml:`<f t="shared" ref="${t}" si="">${V(q(e,S,v))}</f>`}));break}case 426:{const t=e.range(),s=O(t);E=E.filter(n=>n.r2>=k),E.push(t);const o=e.u8();X(n=>(v.row=k,v.col=n.col,{xml:`<f t="array"${o&1?' ca="1"':""} ref="${s}">${V(q(e,S,v))}</f>`}));break}case 428:{const t=O(e.range()),s=e.u32(),o=e.u32(),n=e.u32(),i=e.u32(),c=e.u8();X(()=>({xml:`<f${l({t:"dataTable",ref:t,dt2D:(c&2)!==0,dtr:(c&1)!==0,r1:c&4?void 0:y(s,o),del1:(c&4)!==0,r2:c&2&&!(c&8)?y(n,i):void 0,del2:(c&8)!==0,ca:(c&16)!==0})}/>`}));break}case 145:ee();break;case 146:te(),$.add("</sheetData>");break;case 147:{const t=e.u24(),s=$e(e);e.skip(8);const o=e.left>=4?e.str():"",n=s&&s!==' auto="1"'?`<tabColor${s}/>`:"",i=l({applyStyles:(t&32)!==0,summaryBelow:t&64?void 0:"0",summaryRight:t&128?void 0:"0",showOutlineSymbols:t&1024?void 0:"0"}),c=l({autoPageBreaks:t&1?void 0:"0",fitToPage:(t&256)!==0}),d=l({syncHorizontal:(t&4096)!==0,syncVertical:(t&8192)!==0,transitionEvaluation:(t&16384)!==0,transitionEntry:(t&32768)!==0,published:t&8?void 0:"0",codeName:o||void 0,filterMode:(t&65536)!==0,enableFormatConditionsCalculation:t&131072?void 0:"0"}),g=n+(i?`<outlinePr${i}/>`:"")+(c?`<pageSetUpPr${c}/>`:"");(d||g)&&(p.props=g?`<sheetPr${d}>${g}</sheetPr>`:`<sheetPr${d}/>`);break}case 148:p.dimension=`<dimension ref="${O(e.range())}"/>`;break;case 137:{const t=e.u16(),s=e.u32(),o=e.u32(),n=e.u32(),i=e.u8();e.skip(3);const c=e.u16(),d=e.u16(),g=e.u16(),r=e.u16(),L=e.u32();b={open:l({windowProtection:(t&1)!==0,showFormulas:(t&2)!==0,showGridLines:t&4?void 0:"0",showRowColHeaders:t&8?void 0:"0",showZeros:t&16?void 0:"0",rightToLeft:(t&32)!==0,tabSelected:(t&64)!==0,showRuler:t&128?void 0:"0",showOutlineSymbols:t&256?void 0:"0",defaultGridColor:t&512?void 0:"0",showWhiteSpace:t&1024?"0":void 0,view:Re[s],topLeftCell:o||n?y(o,n):void 0,colorId:t&512?void 0:i,zoomScale:c&&c!==100?c:void 0,zoomScaleNormal:d||void 0,zoomScaleSheetLayoutView:g||void 0,zoomScalePageLayoutView:r||void 0,workbookViewId:L}),body:""};break}case 151:{const t=e.f64(),s=e.f64(),o=e.u32(),n=e.u32(),i=e.u32(),c=e.u8();b&&(b.body+=`<pane${l({xSplit:t?x(t):void 0,ySplit:s?x(s):void 0,topLeftCell:y(o,n),activePane:W[i]==="topLeft"?void 0:W[i],state:c&2?"frozen":c&1?"frozenSplit":void 0})}/>`);break}case 152:{const t=e.u32(),s=e.u32(),o=e.u32(),n=e.u32(),i=e.ranges();b&&(b.body+=`<selection${l({pane:W[t]==="topLeft"?void 0:W[t],activeCell:y(s,o),activeCellId:n||void 0,sqref:A(i)||void 0})}/>`);break}case 138:b&&p.views.push(b.body?`<sheetView${b.open}>${b.body}</sheetView>`:`<sheetView${b.open}/>`),b=null;break;case 485:{const t=e.u32(),s=e.u16(),o=e.u16(),n=e.u16(),i=e.u8(),c=e.u8();Y=o,p.format=`<sheetFormatPr${l({baseColWidth:s===8?void 0:s,defaultColWidth:t===4294967295?void 0:x(t/256),defaultRowHeight:x(o/20),customHeight:(n&1)!==0,zeroHeight:(n&2)!==0,thickTop:(n&4)!==0,thickBottom:(n&8)!==0,outlineLevelRow:i||void 0,outlineLevelCol:c||void 0})}/>`;break}case 60:{const t=e.u32(),s=e.u32(),o=e.u32(),n=e.u32(),i=e.u16();p.cols.push(`<col${l({min:t+1,max:s+1,width:x(o/256),style:n||void 0,hidden:(i&1)!==0,customWidth:(i&2)!==0,bestFit:(i&4)!==0,phonetic:(i&8)!==0,outlineLevel:i>>8&7||void 0,collapsed:(i&4096)!==0})}/>`);break}case 663:f.sheetCalcPr=e.u32()&1?['<sheetCalcPr fullCalcOnLoad="1"/>']:[];break;case 678:{const t=e.u32();e.skip(64),B=oe(e,t);break}case 535:{const t=e.u16(),s=Array.from({length:16},()=>e.u32()!==0),o=i=>i?void 0:"1",n=i=>i?"0":void 0;if(!s[0]&&!t&&!B)break;f.sheetProtection=[`<sheetProtection${l({...B??{password:le(t)},sheet:s[0],objects:o(s[1]),scenarios:o(s[2]),formatCells:n(s[3]),formatColumns:n(s[4]),formatRows:n(s[5]),insertColumns:n(s[6]),insertRows:n(s[7]),insertHyperlinks:n(s[8]),deleteColumns:n(s[9]),deleteRows:n(s[10]),selectLockedCells:o(s[11]),sort:n(s[12]),autoFilter:n(s[13]),pivotTables:n(s[14]),selectUnlockedCells:o(s[15])})}/>`];break}case 680:{const t=e.u32();e.ranges(),e.str(),e.skip(e.u32()),H=e.left>=12?oe(e,t):null;break}case 536:{const t=e.u16(),s=e.ranges(),o=e.str();e.left>=4&&e.u32()>0&&!H&&!t?u.onLostPart():w("protectedRanges",`<protectedRange${l({...H??{password:le(t)},sqref:A(s),name:o})}/>`),H=null;break}case 500:{const t=e.u16(),s=e.u16(),o=e.ranges();m={open:l({current:t===65535?void 0:t,show:s===65535?void 0:s,sqref:o.length?A(o):void 0}),items:[],cells:[]};break}case 502:{e.skip(2);const t=e.u32()!==0,s=e.u32()!==0,o=e.str(),n=e.nstr();m&&(m.item=l({name:o,locked:t,hidden:s,user:e.nstr()??void 0,comment:n||void 0}));break}case 504:{const t=y(e.u32(),e.u32());e.skip(8);const s=e.u16();m?.cells.push(`<inputCells${l({r:t,val:e.str(),numFmtId:s||void 0})}/>`);break}case 503:m?.item&&m.items.push(`<scenario${m.item} count="${m.cells.length}">${m.cells.join("")}</scenario>`),m&&(m.cells=[]);break;case 501:m?.items.length&&(f.scenarios=[`<scenarios${m.open}>${m.items.join("")}</scenarios>`]);break;case 176:w("mergeCells",`<mergeCell ref="${O(e.range())}"/>`);break;case 64:{const t=ie(e,S,u.onLost,!1,_);_=null,t&&w("dataValidations",t);break}case 681:_=e.str();break;case 494:{const t=he(e.range()),s=e.nstr(),o=e.str(),n=e.str();w("hyperlinks",`<hyperlink${l({ref:t,"r:id":s||void 0,location:o||void 0,tooltip:n||void 0,display:e.str()||void 0})}/>`);break}case 477:{const t=e.u16(),s=l({horizontalCentered:(t&1)!==0,verticalCentered:(t&2)!==0,headings:(t&4)!==0,gridLines:(t&8)!==0});s&&(f.printOptions=[`<printOptions${s}/>`]);break}case 476:{const[t,s,o,n,i,c]=Array.from({length:6},()=>x(e.f64()));f.pageMargins=[`<pageMargins${l({left:t,right:s,top:o,bottom:n,header:i,footer:c})}/>`];break}case 478:{const t=e.u32(),s=e.u32(),o=e.u32(),n=e.u32(),i=e.u32(),c=e.i32(),d=e.u32(),g=e.u32(),r=e.u16(),L=e.nstr();f.pageSetup=[`<pageSetup${l({paperSize:t>1?t:void 0,scale:s&&s!==100?s:void 0,firstPageNumber:r&128?c:void 0,fitToWidth:d===1?void 0:d,fitToHeight:g===1?void 0:g,pageOrder:r&1?"overThenDown":void 0,orientation:r&64?void 0:r&2?"landscape":"portrait",blackAndWhite:(r&8)!==0,draft:(r&16)!==0,cellComments:r&32?r&256?"atEnd":"asDisplayed":void 0,useFirstPageNumber:(r&128)!==0,errors:Se[r>>9&3],horizontalDpi:o&&o!==600?o:void 0,verticalDpi:n&&n!==600?n:void 0,copies:i>1?i:void 0,"r:id":L||void 0})}/>`];break}case 479:{const t=e.u16(),s=["oddHeader","oddFooter","evenHeader","evenFooter","firstHeader","firstFooter"].map(n=>{const i=e.left>=4?e.nstr():null;return i?`<${n}${/^\s|\s$|\n/.test(i)?' xml:space="preserve"':""}>${Z(i)}</${n}>`:""}),o=l({differentOddEven:(t&1)!==0,differentFirst:(t&2)!==0,scaleWithDoc:t&4?void 0:"0",alignWithMargins:t&8?void 0:"0"});(o||s.some(Boolean))&&(f.headerFooter=[`<headerFooter${o}>${s.join("")}</headerFooter>`]);break}case 392:case 394:P=[];break;case 396:{const t=e.u32(),s=e.u32(),o=e.u32(),n=e.u32();P?.push({manual:n!==0,xml:`<brk${l({id:t,min:s||void 0,max:o,man:n!==0,pt:e.u32()!==0})}/>`});break}case 393:case 395:{const t=a===393?"rowBreaks":"colBreaks";P?.length&&(f[t]=[`<${t} count="${P.length}" manualBreakCount="${P.filter(s=>s.manual).length}">${P.map(s=>s.xml).join("")}</${t}>`]),P=null;break}case 607:w("cellWatches",`<cellWatch r="${y(e.u32(),e.u32())}"/>`);break;case 649:{const t=e.u32();w("ignoredErrors",`<ignoredError${l({sqref:A(e.ranges()),evalError:(t&1)!==0,emptyCellReference:(t&2)!==0,numberStoredAsText:(t&4)!==0,formulaRange:(t&8)!==0,formula:(t&16)!==0,twoDigitTextYear:(t&32)!==0,unlockedFormula:(t&64)!==0,listDataValidation:(t&128)!==0,calculatedColumn:(t&256)!==0})}/>`);break}case 550:case 551:case 552:case 562:{const t={550:"drawing",551:"legacyDrawing",552:"legacyDrawingHF",562:"picture"}[a];f[t]=[`<${t} r:id="${V(e.nstr()??"")}"/>`];break}case 639:{const t=e.u32();e.skip(4);const s=e.u32(),o=e.u16(),n=e.str();if(o&1){u.onLostLink();break}const i=e.nstr();w("oleObjects",`<oleObject${l({progId:n,dvAspect:t===4?"DVASPECT_ICON":void 0,autoLoad:(o&2)!==0,shapeId:s,"r:id":i||void 0})}/>`);break}case 644:{const t=e.u32(),s=e.nstr();w("controls",`<control${l({shapeId:t,"r:id":s??"",name:e.str()||void 0})}/>`);break}case 661:w("tableParts",`<tablePart r:id="${V(e.nstr()??"")}"/>`);break;case 1081:K.push(ae(e));break;case 2089:Q.push(ae(e));break;case 1053:{const t=ie(e,S,u.onLost,!0);t&&w("dataValidations",t);break}default:}},()=>$.flush()),ee(),T.text()&&(f.autoFilter=[T.text()]),T.sortXml&&(f.sortState=[T.sortXml]);const U=I.cf.finish();U.main&&(f.conditionalFormatting=[U.main]);const se=I.sparklines.finish()+U.ext+ve(u.refs(K,Q));se&&(f.extLst=[`<extLst>${se}</extLst>`]);for(const a of Pe){const e=f[a];if(!e?.length)continue;const t=e.join("");if(/^(?:protectedRanges|mergeCells|dataValidations|hyperlinks|cellWatches|ignoredErrors|oleObjects|controls|tableParts)$/.test(a)){const s=a==="mergeCells"||a==="dataValidations"||a==="tableParts"?` count="${e.length}"`:"";$.add(`<${a}${s}>${t}</${a}>`)}else $.add(t)}$.add("</worksheet>"),await $.flush(!0)}const ye=R=>`<t${/^\s|\s$|\n/.test(R)?' xml:space="preserve"':""}>${Z(R)}</t>`;export{We as writeSheet};
@@ -0,0 +1 @@
1
+ import{escapeMarkup as g}from"../xml-escape.js";import{attrs as r,NS_MAIN as $,offOnly as f,XML_HEAD as C}from"./xml.js";import{eachRecord as p}from"./records.js";const x="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",m="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main",A=["none",void 0,"showItemsWithNoData"];function L(n){return n.u32()&8?n.lpstr():null}async function R(n){const e=[];return await p(n,(i,t)=>{if(i!==1083)return;const l=t.u8(),h=t.u32(),s=t.u32(),c=t.u32(),o=t.u32(),a=t.str(),d=t.str(),D=l&2?t.str():void 0,b=l&4?t.str():void 0;e.push({name:a,cache:d,caption:D,startItem:h||void 0,columnCount:s===1?void 0:s,showCaption:f((l&1)!==0),level:c||void 0,style:b,lockedPosition:(l&8)!==0,rowHeight:o})}),e}const B=n=>`${C}<slicers xmlns="${x}" xmlns:x="${$}">${n.map(e=>`<slicer${r(e)}/>`).join("")}</slicers>`;async function I(n){const e={name:"",source:"",kind:"olap",pivotCacheId:0,xml:""};let i="",t="",l="";return await p(n,(h,s)=>{switch(h){case 1077:e.name=s.str(),e.source=s.str();break;case 1085:{const c=[];for(let o=s.u32();o>0;o--){const a=s.u32();c.push(`<pivotTable${r({tabId:a,name:s.str()})}/>`)}i=`<pivotTables>${c.join("")}</pivotTables>`;break}case 1100:{s.skip(4),e.kind="pivot",e.pivotCacheId=s.u32();const c=s.u8();t=`<tabular${r({pivotCacheId:e.pivotCacheId,sortOrder:(c&3)===2?"descending":void 0,customListSort:f((c&16)!==0),showMissing:f((c&32)!==0),crossFilter:A[c>>2&3]})}>`;break}case 1102:{const c=[];for(let o=s.u32();o>0;o--){const a=s.u32(),d=s.u8();c.push(`<i${r({x:a,s:(d&1)!==0,nd:(d&2)!==0})}/>`)}t+=`<items count="${c.length}">${c.join("")}</items>`;break}case 1101:t=`<data>${t}</tabular></data>`;break;case 2077:{s.skip(4),e.kind="table";const c=s.u32(),o=s.u32(),a=s.u8();l=`<extLst><x:ext xmlns:x15="${m}" uri="{2F2917AC-EB37-4324-AD4E-5DD8C200BD13}"><x15:tableSlicerCache${r({tableId:o,column:c,sortOrder:(a&3)===2?"descending":void 0,customListSort:f((a&16)!==0),crossFilter:A[a>>2&3]})}/></x:ext></extLst>`;break}default:}}),e.xml=`${C}<slicerCacheDefinition xmlns="${x}" xmlns:x="${$}"${r({name:e.name,sourceName:e.source})}>${i}${t}${l}</slicerCacheDefinition>`,e}const u=(n,e)=>e.map(i=>`<${n} r:id="${g(i)}"/>`).join("");function S({pivot:n,table:e,timelines:i}){const t=(n.length?`<ext xmlns:x14="${x}" uri="{BBE1A952-AA13-448e-AADC-164F8A28A991}"><x14:slicerCaches>${u("x14:slicerCache",n)}</x14:slicerCaches></ext>`:"")+(e.length?`<ext xmlns:x15="${m}" uri="{46BE6895-7355-4a93-B00E-2C351335B9C9}"><x15:slicerCaches xmlns:x14="${x}">${u("x14:slicerCache",e)}</x15:slicerCaches></ext>`:"")+(i.length?`<ext xmlns:x15="${m}" uri="{D0CA8CA8-9F24-4464-BF8E-62219DCF47F9}"><x15:timelineCacheRefs>${u("x15:timelineCacheRef",i)}</x15:timelineCacheRefs></ext>`:"");return t&&`<extLst>${t}</extLst>`}function v({pivot:n,table:e,timelines:i}){return(n.length?`<ext xmlns:x14="${x}" uri="{A8765BA9-456A-4dab-B4F3-ACF838C121DE}"><x14:slicerList>${u("x14:slicer",n)}</x14:slicerList></ext>`:"")+(e.length?`<ext xmlns:x15="${m}" uri="{3A4CF648-6AED-40f4-86FF-DC5316D8AED3}"><x14:slicerList xmlns:x14="${x}">${u("x14:slicer",e)}</x14:slicerList></ext>`:"")+(i.length?`<ext xmlns:x15="${m}" uri="{7E03D99C-DC04-49d9-9315-930204A7B6E9}"><x15:timelineRefs>${u("x15:timelineRef",i)}</x15:timelineRefs></ext>`:"")}export{L as frtRelId,I as readSlicerCache,R as readSlicers,v as sheetRefs,B as slicersXml,S as workbookRefs};
@@ -0,0 +1 @@
1
+ import{escapeMarkup as w,xmlText as P}from"../xml-escape.js";import{attrs as m,NS_MAIN as _,XML_HEAD as U}from"./xml.js";import{eachRecord as O,numberText as g}from"./records.js";const L=["none","solid","mediumGray","darkGray","lightGray","darkHorizontal","darkVertical","darkDown","darkUp","darkGrid","darkTrellis","lightHorizontal","lightVertical","lightDown","lightUp","lightGrid","lightTrellis","gray125","gray0625"],M=["none","thin","medium","dashed","dotted","thick","double","hair","mediumDashed","dashDot","mediumDashDot","dashDotDot","mediumDashDotDot","slantDashDot"],z=["general","left","center","right","fill","justify","centerContinuous","distributed"],A=["top","center","bottom","justify","distributed"],V={1:"single",2:"double",33:"singleAccounting",34:"doubleAccounting"},Y=["wholeTable","headerRow","totalRow","firstColumn","lastColumn","firstRowStripe","secondRowStripe","firstColumnStripe","secondColumnStripe","firstHeaderCell","lastHeaderCell","firstTotalCell","lastTotalCell","firstSubtotalColumn","secondSubtotalColumn","thirdSubtotalColumn","firstSubtotalRow","secondSubtotalRow","thirdSubtotalRow","blankRow","firstColumnSubheading","secondColumnSubheading","thirdColumnSubheading","firstRowSubheading","secondRowSubheading","thirdRowSubheading","pageFieldLabels","pageFieldValues"],q=["Normal","RowLevel_#","ColLevel_#","Comma","Currency","Percent","Comma [0]","Currency [0]","Hyperlink","Followed Hyperlink","Note","Warning Text",,,,"Title","Heading 1","Heading 2","Heading 3","Heading 4","Input","Output","Calculation","Check Cell","Linked Cell","Total","Good","Bad","Neutral",...[1,2,3,4,5,6].flatMap(e=>[`Accent${e}`,`20% - Accent${e}`,`40% - Accent${e}`,`60% - Accent${e}`]),"Explanatory Text"],k=e=>e.toString(16).toUpperCase().padStart(2,"0");function h(e){const n=e.u8()>>1,t=e.u8(),o=e.i16(),a=e.take(4),[i,r,c,d]=e.buf.subarray(a,a+4);let f;if(n===0)f=' auto="1"';else if(n===1)f=` indexed="${t}"`;else if(n===2)f=` rgb="${k(d)}${k(i)}${k(r)}${k(c)}"`;else if(n===3)f=` theme="${t}"`;else return"";return o?`${f} tint="${g(o/32767)}"`:f}const y=(e,n)=>n?`<${e}${n}/>`:"";function D(e,n="name"){return(e.bold?"<b/>":e.bold===!1&&e.partial?'<b val="0"/>':"")+(e.italic?"<i/>":e.italic===!1&&e.partial?'<i val="0"/>':"")+(e.strike?"<strike/>":e.strike===!1&&e.partial?'<strike val="0"/>':"")+(e.condense?"<condense/>":e.condense===!1&&e.partial?'<condense val="0"/>':"")+(e.extend?"<extend/>":e.extend===!1&&e.partial?'<extend val="0"/>':"")+(e.outline?"<outline/>":"")+(e.shadow?"<shadow/>":"")+(e.underline?e.underline===1?"<u/>":`<u val="${V[e.underline]??"single"}"/>`:e.underline===0&&e.partial?'<u val="none"/>':"")+(e.script?`<vertAlign val="${e.script===1?"superscript":"subscript"}"/>`:e.script===0&&e.partial?'<vertAlign val="baseline"/>':"")+(e.size?`<sz val="${g(e.size)}"/>`:"")+y("color",e.color)+(e.name?`<${n} val="${w(e.name)}"/>`:"")+(e.family?`<family val="${e.family}"/>`:"")+(e.charset?`<charset val="${e.charset}"/>`:"")+(e.scheme?`<scheme val="${e.scheme===1?"major":"minor"}"/>`:"")}const W=e=>`<rPr>${D(e,"rFont")}</rPr>`;function J(e){const n={size:e.u16()/20},t=e.u16();return n.italic=(t&2)!==0,n.strike=(t&8)!==0,n.outline=(t&16)!==0,n.shadow=(t&32)!==0,n.condense=(t&64)!==0,n.extend=(t&128)!==0,n.bold=e.u16()>=600,n.script=e.u16(),n.underline=e.u8(),n.family=e.u8(),n.charset=e.u8(),e.skip(1),n.color=h(e),n.scheme=e.u8(),n.name=e.str(),n}const E=(e,n)=>`<stop position="${g(e)}">${y("color",n)}</stop>`,j=(e,n)=>`<fill><gradientFill${m({type:e.type===1?"path":void 0,degree:e.type===0&&e.degree?g(e.degree):void 0,left:e.left?g(e.left):void 0,right:e.right?g(e.right):void 0,top:e.top?g(e.top):void 0,bottom:e.bottom?g(e.bottom):void 0})}>${n.join("")}</gradientFill></fill>`,N=e=>({type:e.u32(),degree:e.f64(),left:e.f64(),right:e.f64(),top:e.f64(),bottom:e.f64()});function K(e){const n=e.u32(),t=h(e),o=h(e);if(n===40){const a=N(e),i=[];for(let r=e.u32();r>0;r--){const c=h(e);i.push(E(e.f64(),c))}return j(a,i)}return n===0?'<fill><patternFill patternType="none"/></fill>':n===17&&t===' auto="1"'?'<fill><patternFill patternType="gray125"/></fill>':`<fill><patternFill patternType="${L[n]??"solid"}">${y("fgColor",t)}${y("bgColor",o)}</patternFill></fill>`}function H(e,n,t){return n?`<${e} style="${M[n]??"thin"}">${y("color",t)}</${e}>`:`<${e}/>`}function v(e,n){const t=e.u8();return e.skip(1),H(n,t,h(e))}function Q(e){const n=e.u8(),t=v(e,"top"),o=v(e,"bottom"),a=v(e,"left"),i=v(e,"right"),r=v(e,"diagonal");return`<border${m({diagonalUp:(n&2)!==0,diagonalDown:(n&1)!==0})}>${a}${i}${t}${o}${r}</border>`}const B=e=>{const n=m(e);return n?`<alignment${n}/>`:""};function Z(e){const n=e.u16(),t=e.u16(),o=e.u16(),a=e.u16(),i=e.u16(),r=e.u8(),c=e.u8(),d=e.u16(),f=e.u16(),l=n===65535,s=B({horizontal:d&7?z[d&7]:void 0,vertical:(d>>3&7)!==2?A[d>>3&7]:void 0,textRotation:r||void 0,wrapText:(d&64)!==0,indent:c||void 0,justifyLastLine:(d&128)!==0,shrinkToFit:(d&256)!==0,readingOrder:d>>10&3||void 0}),u=(d&4096)!==0,p=(d&8192)!==0,x=!u||p?`<protection${m({locked:u?void 0:"0",hidden:p})}/>`:"",S=b=>(f&b)!==0!==l,$=l?(b,C)=>S(C)?"":` ${b}="0"`:(b,C)=>S(C)?` ${b}="1"`:"",I=`<xf numFmtId="${t}" fontId="${o}" fillId="${a}" borderId="${i}"${l?"":` xfId="${n}"`}${m({quotePrefix:(d&32768)!==0,pivotButton:(d&16384)!==0})}${$("applyNumberFormat",1)}${$("applyFont",2)}${$("applyFill",16)}${$("applyBorder",8)}${$("applyAlignment",4)}${$("applyProtection",32)}`;return s||x?`${I}>${s}${x}</xf>`:`${I}/>`}function ee(e){e.skip(2),e.skip(2);const n=e.u16(),t={partial:!0};let o=!1;const a={};let i=null;const r=[],c={};let d=!1,f=!1;const l={},s={};let u,p;for(let b=0;b<n;b++){const C=e.pos,R=e.u16(),X=e.u16();if(X<4)throw new Error("The file is damaged: a format ends too early");switch(R){case 0:a.pattern=e.u8();break;case 1:a.fg=h(e);break;case 2:a.bg=h(e);break;case 3:i=N(e);break;case 4:{e.skip(2);const F=e.f64();r.push(E(F,h(e)));break}case 5:t.color=h(e),o=!0;break;case 6:case 7:case 8:case 9:case 10:case 11:case 12:{const F=h(e);c[["top","bottom","left","right","diagonal","vertical","horizontal"][R-6]]={style:e.u16(),color:F};break}case 13:d=e.u8()!==0;break;case 14:f=e.u8()!==0;break;case 15:l.horizontal=z[e.u8()];break;case 16:l.vertical=A[e.u8()];break;case 17:l.textRotation=e.u8();break;case 18:l.indent=e.u16();break;case 19:l.readingOrder=e.u8();break;case 20:l.wrapText=e.u8()!==0;break;case 21:l.justifyLastLine=e.u8()!==0;break;case 22:l.shrinkToFit=e.u8()!==0;break;case 24:t.name=e.lpstr(),o=!0;break;case 25:t.bold=e.u16()>=600,o=!0;break;case 26:t.underline=e.u16(),o=!0;break;case 27:t.script=e.u16(),o=!0;break;case 28:t.italic=e.u8()!==0,o=!0;break;case 29:t.strike=e.u8()!==0,o=!0;break;case 30:t.outline=e.u8()!==0,o=!0;break;case 31:t.shadow=e.u8()!==0,o=!0;break;case 32:t.condense=e.u8()!==0,o=!0;break;case 33:t.extend=e.u8()!==0,o=!0;break;case 34:t.charset=e.u8(),o=!0;break;case 35:t.family=e.u8(),o=!0;break;case 36:t.size=e.u32()/20,o=!0;break;case 37:t.scheme=e.u8(),o=!0;break;case 38:p=e.lpstr();break;case 41:u=e.u16();break;case 42:{const F=e.i16();F!==255&&(l.relativeIndent=String(F));break}case 43:s.locked=e.u8()?"1":"0";break;case 44:s.hidden=e.u8()?"1":"0";break;default:}e.pos=C+X}let x="";i?x=j(i,r):(a.pattern!==void 0||a.fg!==void 0||a.bg!==void 0)&&(x=`<fill><patternFill${a.pattern===void 0||a.pattern===1&&a.bg&&!a.fg?"":` patternType="${L[a.pattern]??"solid"}"`}>${y("fgColor",a.fg)}${y("bgColor",a.bg)}</patternFill></fill>`);const S=b=>c[b]?H(b,c[b].style,c[b].color):"",$=["left","right","top","bottom","diagonal","vertical","horizontal"].map(S).join(""),I=p!==void 0||u!==void 0?`<numFmt numFmtId="${u??0}" formatCode="${w(p??"")}"/>`:"";return(o?`<font>${D(t)}</font>`:"")+(p!==void 0?I:"")+x+B(l)+($||d||f?`<border${m({diagonalUp:d,diagonalDown:f})}>${$}</border>`:"")+(Object.keys(s).length?`<protection${m(s)}/>`:"")}async function ae(e){const n=[],t={numFmts:[],fonts:[],fills:[],borders:[],cellStyleXfs:[],cellXfs:[],cellStyles:[],dxfs:[],indexed:[],mru:[],tableStyles:[]};let o=null,a="",i=null,r=!1;await O(e,(f,l)=>{switch(f){case 44:{const s=l.u16();t.numFmts.push(`<numFmt numFmtId="${s}" formatCode="${w(l.str())}"/>`);break}case 43:{const s=J(l);n.push(s),t.fonts.push(`<font>${D(s)}</font>`);break}case 45:t.fills.push(K(l));break;case 46:t.borders.push(Q(l));break;case 626:o=t.cellStyleXfs;break;case 617:o=t.cellXfs;break;case 627:case 618:o=null;break;case 47:o?.push(Z(l));break;case 48:{const s=l.u32(),u=l.u16(),p=l.u8(),x=l.u8(),S=l.nstr()??q[p]?.replace("#",x+1)??`Style ${s}`;t.cellStyles.push(`<cellStyle${m({name:S,xfId:s,builtinId:u&1?p:void 0,iLevel:u&1&&(p===1||p===2)?x:void 0,hidden:(u&2)!==0,customBuiltin:(u&1)!==0&&(u&4)!==0})}/>`);break}case 507:t.dxfs.push(`<dxf>${ee(l)}</dxf>`);break;case 508:{l.skip(4);const s=l.nstr(),u=l.nstr();a=m({defaultTableStyle:s,defaultPivotStyle:u});break}case 510:{const s=l.u16();l.skip(4),i={open:m({name:l.nstr()??"",pivot:G(s&2),table:G(s&4)}),items:[]};break}case 512:{const s=Y[l.u32()],u=l.u32(),p=l.u32();i&&s&&i.items.push(`<tableStyleElement${m({type:s,size:/Stripe$/.test(s)&&u>1?u:void 0,dxfId:p===4294967295?void 0:p})}/>`);break}case 511:i&&t.tableStyles.push(`<tableStyle${i.open} count="${i.items.length}">${i.items.join("")}</tableStyle>`),i=null;break;case 565:r=!0;break;case 566:r=!1;break;case 475:{if(!r)break;const s=l.take(4),[u,p,x]=l.buf.subarray(s,s+3);t.indexed.push(`<rgbColor rgb="00${k(u)}${k(p)}${k(x)}"/>`);break}default:}});const c=(f,l,s="")=>l.length?`<${f} count="${l.length}"${s}>${l.join("")}</${f}>`:"";return{xml:`${U}<styleSheet xmlns="${_}">`+c("numFmts",t.numFmts)+c("fonts",t.fonts.length?t.fonts:['<font><sz val="11"/><name val="Calibri"/></font>'])+c("fills",t.fills.length?t.fills:['<fill><patternFill patternType="none"/></fill>','<fill><patternFill patternType="gray125"/></fill>'])+c("borders",t.borders.length?t.borders:["<border><left/><right/><top/><bottom/><diagonal/></border>"])+c("cellStyleXfs",t.cellStyleXfs.length?t.cellStyleXfs:['<xf numFmtId="0" fontId="0" fillId="0" borderId="0"/>'])+c("cellXfs",t.cellXfs.length?t.cellXfs:['<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>'])+c("cellStyles",t.cellStyles)+`<dxfs count="${t.dxfs.length}">${t.dxfs.join("")}</dxfs><tableStyles count="${t.tableStyles.length}"${a}>${t.tableStyles.join("")}</tableStyles>`+(t.indexed.length?`<colors><indexedColors>${t.indexed.join("")}</indexedColors></colors>`:"")+"</styleSheet>",fonts:n}}const G=e=>e?void 0:"0";function se(e,n){const t=e.u8(),o=e.str();if(!(t&1))return T(o);const a=e.u32(),i=[];for(let r=0;r<a;r++){const c=e.u16();i.push({at:c,font:n[e.u16()]})}return te(o,i)}function te(e,n){const t=n.filter(a=>a.at<e.length);if(t.length===0)return T(e);let o=t[0].at>0?`<r>${T(e.slice(0,t[0].at))}</r>`:"";return t.forEach((a,i)=>{const r=e.slice(a.at,t[i+1]?.at??e.length);r&&(o+=`<r>${a.font?W(a.font):""}${T(r)}</r>`)}),o}const T=e=>`<t${/^\s|\s$|\n/.test(e)?' xml:space="preserve"':""}>${P(e)}</t>`;export{M as BORDER_STYLES,q as BUILTIN_STYLES,z as H_ALIGN,L as PATTERNS,A as V_ALIGN,B as alignmentXml,y as colorXml,D as fontBody,j as gradientXml,h as readColor,ee as readDxf,ae as readStyles,se as richText,W as runProps,te as runsXml,H as sideXml,E as stopXml,T as textXml};
@@ -0,0 +1 @@
1
+ import{escapeMarkup as p}from"../xml-escape.js";import{attrs as u,NS_MAIN as g,NS_R as v,XML_HEAD as $}from"./xml.js";import{eachRecord as y,numberText as S}from"./records.js";import{readFormula as C,skipFormula as N}from"./formula.js";import{frtRelId as w}from"./slicer.js";const b=t=>t?t.toString(16).toUpperCase().padStart(4,"0"):void 0,x=(t,s)=>s?{[`${t}AlgorithmName`]:s.algorithmName,[`${t}HashValue`]:s.hashValue,[`${t}SaltValue`]:s.saltValue,[`${t}SpinCount`]:s.spinCount}:{};function V(t){let s="";for(const d of t)s+=String.fromCharCode(d);return btoa(s)}function k(t,s){const d=()=>{const n=t.u32(),a=t.take(n);return n?V(t.buf.subarray(a,a+n)):void 0},c=d(),o=d(),e=t.nstr();return c?{algorithmName:e,hashValue:c,saltValue:o,spinCount:s}:null}async function O(t){const s={sheets:[],names:[],links:[],xti:[],tables:new Map,views:[],props:"",calc:"",protection:null,sharing:null,pivotCaches:[],slicerCaches:[],timelineCaches:[],date1904:!1};let d=null,c=null;return await y(t,(o,e)=>{switch(o){case 156:{const n=e.u32(),a=e.u32(),i=e.nstr();s.sheets.push({name:e.str(),state:n,rid:i,sheetId:a});break}case 153:{const n=e.u32(),a=e.u32();s.date1904=(n&1)!==0,s.props=u({date1904:s.date1904,showBorderUnselectedTables:n&4?"0":void 0,filterPrivacy:(n&8)!==0,backupFile:(n&64)!==0,saveExternalLinkValues:n&128?"0":void 0,codeName:e.left>=4&&e.str()||void 0,defaultThemeVersion:a||void 0});break}case 158:{const n=e.i32(),a=e.i32(),i=e.u32(),l=e.u32(),r=e.u32(),h=e.u32(),m=e.u32(),f=e.u8();s.views.push(`<workbookView${u({visibility:f&2?"veryHidden":f&1?"hidden":void 0,minimized:(f&4)!==0,showHorizontalScroll:f&8?void 0:"0",showVerticalScroll:f&16?void 0:"0",showSheetTabs:f&32?void 0:"0",xWindow:n,yWindow:a,windowWidth:i,windowHeight:l,tabRatio:r===600?void 0:r,firstSheet:h||void 0,activeTab:m||void 0})}/>`);break}case 157:{const n=e.u32(),a=e.u32(),i=e.u32(),l=e.f64();e.skip(4);const r=e.u16();s.calc=u({calcId:n||void 0,calcMode:a===0?"manual":a===2?"autoNoTable":void 0,fullCalcOnLoad:(r&1)!==0,refMode:r&2?void 0:"R1C1",iterate:(r&4)!==0,iterateCount:i===100||i===0?void 0:i,iterateDelta:l===.001||!(l>0)?void 0:S(l),fullPrecision:r&8?void 0:"0"});break}case 677:{const n=e.u32(),a=e.u32();e.skip(2),d={book:k(e,n),revisions:k(e,a)};break}case 534:{const n=e.u16(),a=e.u16(),i=e.u16();s.protection=u({...x("workbook",d?.book),...x("revisions",d?.revisions),workbookPassword:b(n),revisionsPassword:b(a),lockStructure:(i&1)!==0,lockWindows:(i&2)!==0,lockRevision:(i&4)!==0});break}case 679:{const n=e.u32(),a=e.u16(),i=e.nstr()||void 0;c={readOnly:a,user:i,password:k(e,n)};break}case 548:{const n=e.u16(),a=e.u16();s.sharing=u({readOnlyRecommended:n!==0,userName:e.nstr()||void 0,reservationPassword:b(a),...c?.password??{}});break}case 355:s.links.push({kind:"book",rid:e.nstr(),index:0,sheets:[],names:[]});break;case 357:s.links.push({kind:"self"});break;case 358:s.links.push({kind:"same"});break;case 667:s.links.push({kind:"addin"});break;case 362:for(let n=e.u32();n>0&&e.left>=12;n--)s.xti.push({link:e.u32(),first:e.i32(),last:e.i32()});break;case 39:{const n=e.u32();e.skip(1);const a=e.u32(),i=e.str(),l=e.pos;N(e);const r=e.buf.slice(l,e.pos),h=e.left>=4?e.nstr():null,m=(n&32)!==0;s.names.push({name:m&&!i.startsWith("_xlnm.")?`_xlnm.${i}`:i,itab:a===4294967295?void 0:a,hidden:(n&1)!==0,macro:(n&8)!==0,func:(n&2)!==0,vba:(n&4)!==0,future:(n&131072)!==0||/^_xl(?:fn|pm|ws|eta|udf)\./i.test(i),comment:h,bytes:r});break}case 1072:case 2076:s.slicerCaches.push(w(e));break;case 2085:s.timelineCaches.push(w(e));break;case 386:{const n=e.u32();s.pivotCaches.push({id:n,rid:e.nstr()});break}default:}}),c&&!s.sharing&&(s.sharing=u({readOnlyRecommended:c.readOnly!==0,userName:c.user,...c.password??{}})),s}function W(t,s,d){let c=!0;for(;c;){c=!1;for(const o of t.names)if(!(o.future||o.lost)){if(o.macro&&o.bytes.length>=4&&o.bytes.slice(0,4).every(e=>e===0)){o.lost=!0,o.procedure=!0;continue}try{o.text=C(new s(o.bytes),t,{row:0,col:0,inName:!0})}catch{o.lost=!0,c=!0,d?.(o.name)}}}for(const o of t.names)o.bytes=null}const R=[void 0,"hidden","veryHidden"];function _(t,s=[],d=""){const c=t.names.filter(e=>!e.future&&!e.lost&&e.text!==void 0).map(e=>`<definedName${u({name:e.name,comment:e.comment||void 0,function:e.func,vbProcedure:e.vba,xlm:e.macro&&!e.func&&!e.vba?!0:void 0,localSheetId:e.itab,hidden:e.hidden})}>${p(e.text)}</definedName>`),o=t.links.filter(e=>e.kind==="book"&&!e.missing);return`${$}<workbook xmlns="${g}" xmlns:r="${v}">`+(t.sharing?`<fileSharing${t.sharing}/>`:"")+(t.props?`<workbookPr${t.props}/>`:"")+(t.protection?`<workbookProtection${t.protection}/>`:"")+(t.views.length?`<bookViews>${t.views.join("")}</bookViews>`:"")+`<sheets>${t.sheets.map(e=>`<sheet${u({name:e.name,sheetId:e.sheetId,state:R[e.state],"r:id":e.rid??""})}/>`).join("")}</sheets>`+(o.length?`<externalReferences>${o.map(e=>`<externalReference r:id="${p(e.rid??"")}"/>`).join("")}</externalReferences>`:"")+(c.length?`<definedNames>${c.join("")}</definedNames>`:"")+`<calcPr${t.calc}/>`+(s.length?`<pivotCaches>${s.map(e=>`<pivotCache cacheId="${e.id}" r:id="${p(e.rid)}"/>`).join("")}</pivotCaches>`:"")+`${d}</workbook>`}export{W as readNames,k as readPassword,O as readWorkbook,_ as workbookXml};
package/io/xlsb/xml.js ADDED
@@ -0,0 +1,2 @@
1
+ import{escapeMarkup as f,xmlAttr as u}from"../xml-escape.js";import{cellRef as r,colName as i}from"../../core/address.js";const m=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ `,x="http://schemas.openxmlformats.org/spreadsheetml/2006/main",d="http://schemas.openxmlformats.org/officeDocument/2006/relationships",p=65536,a=new TextEncoder;class ${constructor(t){this.write=t,this.parts=[],this.size=0}add(t){this.parts.push(t),this.size+=t.length}flush(t=!1){if(this.size===0||!t&&this.size<p)return;const n=a.encode(this.parts.join(""));return this.parts=[],this.size=0,this.write(n)}}function y(e){let t="";for(const n of Object.keys(e)){const s=e[n];s==null||s===!1||(t+=` ${n}="${s===!0?"1":typeof s=="number"?s:u(s)}"`)}return t}const g=e=>e?void 0:"0",z=(e,t)=>`<${e}>${f(t)}</${e}>`;function c({r1:e,c1:t,r2:n,c2:s}){if(e===0&&n===1048575)return`${i(t)}:${i(s)}`;if(t===0&&s===16383)return`${e+1}:${n+1}`;const o=r(e,t);return e===n&&t===s?o:`${o}:${r(n,s)}`}function T({r1:e,c1:t,r2:n,c2:s}){const o=r(e,t);return e===n&&t===s?o:`${o}:${r(n,s)}`}const A=e=>e.map(c).join(" ");export{x as NS_MAIN,d as NS_R,$ as Out,m as XML_HEAD,y as attrs,z as formulaXml,T as fullRangeText,g as offOnly,c as rangeText,A as sqref};
package/io/xlsx-read.js CHANGED
@@ -1 +1 @@
1
- import{openZip as we}from"./zip-reader.js";import{child as T,children as N,decodeRange as _,indexOfSeq as ye,nameIs as x,parseAttrs as b,parseTree as P,unescapeOoxml as M,unescapeXml as E,XmlScanner as H}from"./xml-scan.js";import{relsPathOf as G,resolveTarget as C}from"./package-paths.js";import{parseStyles as ge,parseTheme as ee,resolveColor as Z}from"./xlsx-styles.js";import{parseComments as xe,parseDxfs as Te,parseSheetFeatures as Se}from"./xlsx-tail.js";import{readSplitPane as Ne}from"../cells/view-xml.js";import{parseSparklines as ve}from"../core/sparklines.js";import{readSheetFilter as Ie,readTableFilter as _e}from"../cells/filter-file.js";import{readRunProp as ke}from"../cells/rich-xml.js";import{applyCfExt as Re}from"../cells/cf-file.js";import{readSheetViewAttrs as Pe}from"../cells/view-xml.js";import{readExternalLinks as Ce}from"../calcx/external-read.js";import{BOOL as be,EMPTY as z,ERR as Me,ERRORS as Ae,FORMULA as Fe,NUM as te,STR as se}from"../core/sheet.js";import{parseRangeRef as ie,MAX_COLS as B}from"../core/address.js";import{DATE_1904_OFFSET as Le}from"../core/numfmt.js";const F=65536,Oe=16384,ae=65536,U=6,V=new TextEncoder;function Ee(h,e){const t=/^(?:(\d{4}-\d{2}-\d{2})(?:T|(?=Z|$))|T)?(?:(\d{2}):(\d{2})(?::(\d{2}(?:\.\d+)?))?)?(Z|[+-]\d{2}:?\d{2})?$/.exec(h);if(!t||!t[1]&&!t[2])return NaN;const[,s,r="0",i="0",o="0",l]=t;let n=Number(r)*3600+Number(i)*60+Number(o);if(l&&l!=="Z"){const c=Number(l.slice(1,3))*60+Number(l.slice(-2));n-=(l[0]==="-"?-c:c)*60}if(!s)return n/86400;const m=Date.parse(s)/864e5+25569;return(e?m-Le:m<61?m-1:m)+n/86400}async function ne(h,e){const t=h.getReader();for(;;){const{done:s,value:r}=await t.read();if(s)return;const i=e(r);i!==void 0&&await i}}const j=new Float64Array(23);for(let h=0,e=1;h<23;h++,e*=10)j[h]=e;function $(h,e,t){let s=e,r=!1;h[s]===45?(r=!0,s++):h[s]===43&&s++;let i=0,o=0,l=0,n=s<t;for(;s<t;s++){const c=h[s]-48;if(c>=0&&c<=9)i=i*10+c,i!==0&&o++;else break}if(s<t&&h[s]===46)for(s++;s<t;s++){const c=h[s]-48;if(c>=0&&c<=9)i=i*10+c,i!==0&&o++,l++;else break}let m=0;if(s<t&&(h[s]===69||h[s]===101)){s++;let c=!1;for(h[s]===45?(c=!0,s++):h[s]===43&&s++;s<t;s++){const f=h[s]-48;if(f>=0&&f<=9)m=m*10+f;else{n=!1;break}}c&&(m=-m)}else s<t&&(n=!1);const d=m-l;if(n&&o<=15&&d>=-22&&d<=22){const c=d<0?i/j[-d]:i*j[d];return r?-c:c}return Number(_(h,e,t))}class $e{constructor(e){this.sink=e,this.bytes=new Uint8Array(1<<20),this.len=0,this.offsets=new Uint32Array(ae+1),this.count=0,this.total=0,this.rich=null}addRich(e,t){const s=this.bytes.subarray(this.offsets[this.count-1],this.offsets[this.count]),r=new TextDecoder;for(const i of t)i.at=r.decode(s.subarray(0,i.at)).length;(this.rich??=[]).push([e,t])}_reserve(e){if(this.len+e>this.bytes.length){const t=new Uint8Array(Math.max(this.bytes.length*2,this.len+e));t.set(this.bytes.subarray(0,this.len)),this.bytes=t}}appendXml(e,t,s,r){if(!r){for(;t<s&&e[t]<=32;)t++;for(;s>t&&e[s-1]<=32;)s--}let i=!0;for(let o=t;o<s;o++){const l=e[o];if(l===13||l===38||l===95&&e[o+1]===120){i=!1;break}}if(i)this._reserve(s-t),this.bytes.set(e.subarray(t,s),this.len),this.len+=s-t;else{const o=V.encode(M(E(_(e,t,s))));this._reserve(o.length),this.bytes.set(o,this.len),this.len+=o.length}}appendText(e){const t=V.encode(e);this._reserve(t.length),this.bytes.set(t,this.len),this.len+=t.length}finish(){const e=this.total++;if(this.count++,this.count>=this.offsets.length){const t=new Uint32Array(this.offsets.length*2);t.set(this.offsets),this.offsets=t}return this.offsets[this.count]=this.len,e}get pending(){return this.count}flush(){if(this.count===0)return;const e=this.bytes.slice(0,this.len),t=this.offsets.slice(0,this.count+1);this.len=0,this.count=0,this.offsets[0]=0;const{rich:s}=this;return this.rich=null,this.sink.strings(e,t,s)}}const re=new TextDecoder,oe=(h,e,t)=>t>e&&/\bxml:space\s*=\s*['"]preserve['"]/.test(_(h,e,t));class De{constructor(e){this.pages=e,this.inT=!1,this.phonetic=0,this.runs=null,this.run=null,this.inProps=!1}_finish(){const e=this.pages.finish();this.runs!==null&&(this.pages.addRich(e,this.runs),this.runs=null)}open(e,t,s,r,i,o){const l=s-t;this.inProps?this._runProp(e,t,s,r,i):l===1&&e[t]===116?(this.inT=!o&&this.phonetic===0,this.preserveSpace=this.inT&&oe(e,r,i)):l===1&&e[t]===114&&!o&&this.phonetic===0?(this.run={at:this.pages.len-this.pages.offsets[this.pages.count]},(this.runs??=[]).push(this.run)):l===3&&x(e,t,s,"rPh")&&!o?this.phonetic++:l===3&&x(e,t,s,"rPr")&&!o&&this.run!==null?this.inProps=!0:l===2&&o&&x(e,t,s,"si")&&this._finish()}_runProp(e,t,s,r,i){const o=re.decode(e.subarray(t,s)),l={};for(const n of re.decode(e.subarray(r,i)).matchAll(/([\w:]+)="([^"]*)"/g))l[n[1]]=n[2];ke(this.run,o,l)}close(e,t,s){const r=s-t;r===1&&e[t]===116?this.inT=!1:r===2&&x(e,t,s,"si")?this._finish():r===3&&x(e,t,s,"rPh")?this.phonetic--:r===3&&x(e,t,s,"rPr")&&(this.inProps=!1)}text(e,t,s){this.inT&&this.pages.appendXml(e,t,s,this.preserveSpace)}}function He(){return{count:0,rows:new Uint32Array(F),cols:new Uint16Array(F),kinds:new Uint8Array(F),values:new Float64Array(F),styles:new Uint16Array(F),formulas:null,valueMeta:null,rowMeta:null}}class Be{constructor(e){this.ctx=e,this.scanner=null,this.batch=e.nextBatch(),this.row=-1,this.col=-1,this.style=0,this.type=0,this.typeLong=!1,this.kind=z,this.value=0,this.inV=!1,this.inF=!1,this.inT=!1,this.inIs=!1,this.phonetic=0,this.formula=null,this.formulaText="",this.pendingText=null,this.flushes=[],this.sharedByIndex=new Map}open(e,t,s,r,i,o){const l=s-t;if(l===1){const n=e[t];n===99?this._cellOpen(e,r,i,o):n===118?(this.inV=!o,this.type===115&&this.typeLong&&(this.pendingText="")):n===102?this._formulaOpen(e,r,i,o):n===116&&this.inIs&&this.phonetic===0&&(this.inT=!o,this.preserveSpace=this.inT&&oe(e,r,i))}else l===3&&e[t]===114&&e[t+1]===111?this._rowOpen(e,r,i):l===2&&e[t]===105&&e[t+1]===115?(this.inIs=!o,this.pendingText=""):l===3&&x(e,t,s,"rPh")&&!o?this.phonetic++:l===9&&o&&x(e,t,s,"sheetData")&&(this.scanner.stopped=!0)}close(e,t,s){const r=s-t;if(r===1){const i=e[t];i===99?this._commit():i===118?this.inV=!1:i===102?this._formulaClose():i===116&&(this.inT=!1)}else r===2&&e[t]===105&&e[t+1]===115?this.inIs=!1:r===3&&x(e,t,s,"rPh")?this.phonetic--:r===9&&x(e,t,s,"sheetData")&&(this.scanner.stopped=!0)}text(e,t,s){if(this.inV)this._value(e,t,s);else if(this.inF)this.formulaText+=_(e,t,s);else if(this.inT){if(!this.preserveSpace){for(;t<s&&e[t]<=32;)t++;for(;s>t&&e[s-1]<=32;)s--}this.pendingText+=E(_(e,t,s))}}_rowOpen(e,t,s){let r=-1,i=0,o=0,l=!1,n=!1,m=null,d=t,c=-1;for(;d<s;){for(;d<s&&e[d]<=32;)d++;if(d>=s)break;const f=d;for(;d<s&&e[d]!==61;)d++;const w=d;d+=2;const y=d;for(;d<s&&e[d]!==34&&e[d]!==39;)d++;const u=d;d++;const p=w-f;if(p===1&&e[f]===114)c=$(e,y,u)-1;else if(p===1&&e[f]===115)o=$(e,y,u);else if(p===2&&e[f]===104&&e[f+1]===116)r=$(e,y,u);else if(p===6&&x(e,f,w,"hidden"))i=e[y]===49||e[y]===116?1:0;else if(p===12&&x(e,f,w,"customFormat"))l=e[y]===49||e[y]===116;else if(p===12&&x(e,f,w,"customHeight"))n=e[y]===49||e[y]===116;else if(!(p===5&&x(e,f,w,"spans"))){const v=_(e,f,u+1);m=m===null?v:`${m} ${v}`}}if(this.row=c>=0?c:this.row+1,this.col=-1,i||m!==null||l&&o||r>=0&&r!==this.ctx.defaultHeight){const f=this.batch;f.rowMeta===null&&(f.rowMeta=[]),f.rowMeta.push(this.row,r>=0?r:-1,i,l?o:0,n?1:0,m)}}_cellOpen(e,t,s,r){let i=-1,o=0,l=0,n=!1,m=0,d=0,c=t;for(;c<s;){for(;c<s&&e[c]<=32;)c++;if(c>=s)break;const f=e[c],w=e[c+1]===61,y=e[c+1]===109&&e[c+2]===61&&(f===99||f===118);for(;c<s&&e[c]!==61;)c++;if(c+=2,w&&f===114){let u=0,p=e[c];for(;p>=65&&p<=90;)u=u*26+p-64,p=e[++c];i=u-1;let v=0;for(;p>=48&&p<=57;)v=v*10+p-48,p=e[++c];v>0&&(this.row=v-1)}else if(w&&f===115){let u=0,p=e[c];for(;p>=48&&p<=57;)u=u*10+p-48,p=e[++c];o=u}else if(w&&f===116)l=e[c],n=e[c+1]!==34&&e[c+1]!==39;else if(y){let u=0,p=e[c];for(;p>=48&&p<=57;)u=u*10+p-48,p=e[++c];f===99?m=u:d=u}for(;c<s&&e[c]!==34&&e[c]!==39;)c++;c++}this.col=i>=0?i:this.col+1,this.style=o,this.type=l,this.typeLong=n,this.cm=m,this.vm=d,this.kind=z,this.value=0,this.formula=null,this.pendingText=null,r&&this._commit()}_value(e,t,s){if(t!==s)switch(this.type){case 0:case 110:this.kind=te,this.value=$(e,t,s);break;case 115:this.typeLong?this.pendingText=(this.pendingText??"")+E(_(e,t,s)):(this.kind=se,this.value=$(e,t,s));break;case 98:this.kind=be,this.value=e[t]===49||e[t]===116?1:0;break;case 101:{const r=Ae.indexOf(_(e,t,s));this.kind=Me,this.value=r<0?6:r;break}case 100:{const r=_(e,t,s),i=Ee(r,this.ctx.date1904);Number.isFinite(i)?(this.kind=te,this.value=i):this.pendingText=r;break}default:{const r=_(e,t,s);this.pendingText=(this.pendingText??"")+E(r)}}}_formulaOpen(e,t,s,r){const i=b(e,t,s),o={};if(i.t&&(o.t=i.t),i.si!==void 0&&(o.si=Number(i.si)),i.ref&&(o.ref=i.ref),i.ca&&(o.ca=i.ca),i.t==="dataTable")for(const l of["dt2D","dtr","r1","r2","del1","del2"])i[l]!==void 0&&(o[l]=i[l]);else{const l=_(e,t,s).trim();l&&(o.raw=l)}this.formula=o,this.formulaText="",this.inF=!r,r&&o.t==="shared"&&this._resolveShared(o)}_formulaClose(){this.inF=!1;const e=this.formula;e!==null&&(this.formulaText&&(e.f=E(this.formulaText)),e.t==="shared"&&this._resolveShared(e))}_resolveShared(e){if(e.f!==void 0)e.base=this.row*B+this.col,this.sharedByIndex.set(e.si,e);else{const t=this.sharedByIndex.get(e.si);t!==void 0&&(t.child===void 0&&(t.child={t:"shared",si:e.si,sf:t.f,base:t.base}),this.formula=t.child)}}_commit(){let e=this.kind,t=this.value;this.pendingText!==null&&(t=this.ctx.addString(M(this.pendingText)),e=se,this.pendingText=null);const s=this.batch,r=this.formula;if(r!==null&&(r.f!==void 0||r.t==="shared"||r.t==="array"||r.t==="dataTable"))e|=Fe,this.cm!==0&&(r.cm=this.cm),s.formulas===null&&(s.formulas=[]),s.formulas.push([this.row*B+this.col,r]);else if(e===z&&this.style===0)return;this.vm!==0&&(s.valueMeta===null&&(s.valueMeta=[]),s.valueMeta.push([this.row*B+this.col,this.vm]));const i=s.count++;s.rows[i]=this.row,s.cols[i]=this.col,s.kinds[i]=e,s.values[i]=t,s.styles[i]=this.style,this.formula=null,(s.count===F||s.formulas!==null&&s.formulas.length>=Oe)&&(this.flushes.push(s),this.batch=this.ctx.nextBatch())}}function W(h){const e={defaultHeight:16,defaultWidth:65,cols:[],frozenRows:0,frozenCols:0,showGridlines:!0,zoom:1,tabColor:null};return new H({open(s,r,i,o,l){if(x(s,r,i,"outlinePr")){const n=b(s,o,l);e.summaryAbove=n.summaryBelow==="0"||n.summaryBelow==="false",e.outlineAutoStyles=n.applyStyles==="1"||n.applyStyles==="true",e.summaryLeft=n.summaryRight==="0"||n.summaryRight==="false"}else if(x(s,r,i,"tabColor")){const n=b(s,o,l);n.rgb?e.tabColor=`#${n.rgb.slice(-6)}`:e.tabColorRef=n}else if(x(s,r,i,"sheetFormatPr")){const n=b(s,o,l);n.defaultRowHeight&&(e.defaultHeight=Math.round(Number(n.defaultRowHeight))),n.defaultColWidth?e.defaultWidth=le(Number(n.defaultColWidth)):e.defaultWidth=Number(n.baseColWidth??8)*U+5}else if(x(s,r,i,"col")){const n=b(s,o,l),m=[];for(const d of["bestFit","outlineLevel","collapsed","phonetic"])n[d]!==void 0&&m.push(`${d}="${n[d]}"`);e.cols.push({min:Number(n.min)-1,max:Math.min(Number(n.max)-1,B-1),width:n.width!==void 0?le(Number(n.width)):-1,hidden:n.hidden==="1"||n.hidden==="true",style:Number(n.style??0),extra:m.length?m.join(" "):null})}else if(x(s,r,i,"sheetView")){const n=b(s,o,l);(n.showGridLines==="0"||n.showGridLines==="false")&&(e.showGridlines=!1),n.tabSelected==="1"&&(e.tabSelected=!0),(n.rightToLeft==="1"||n.rightToLeft==="true")&&(e.rtl=!0),n.zoomScale&&(e.zoom=Number(n.zoomScale)/100),Pe(n,e)}else if(x(s,r,i,"pane")){const n=b(s,o,l);n.state==="frozen"||n.state==="frozenSplit"?(e.frozenRows=Number(n.ySplit??0),e.frozenCols=Number(n.xSplit??0)):Ne(n,e)}},close(){},text(){}}).feed(V.encode(h)),e}function le(h){return Math.trunc((256*h+Math.trunc(128/U))/256*U)}function lt(h){return Math.trunc(h/U*256)/256}function Ue(h){const e=[];return h.indexOf("mergeCell")<0||new H({open(s,r,i,o,l){if(x(s,r,i,"mergeCell")){const n=ie(b(s,o,l).ref??"");n&&e.push(n)}},close(){},text(){}}).feed(V.encode(h)),e}const Ve=[..."sheetData"].map(h=>h.charCodeAt(0));async function We(h,e,t,s,r){let i=[],o=!1,l=null,n=null,m=null;const d=new TextDecoder,c=g=>{const I=W(g);return s.defaultHeight=I.defaultHeight,n=new Be(s),m=new H(n),n.scanner=m,I},f=async()=>{if(n.flushes.length===0)return;const g=n.flushes;n.flushes=[];for(const I of g)await s.sendCells(t,I)};if(await ne(await h.stream(e),async g=>{if(l!==null){l.push(g);return}if(!o){i.push(g);const I=q(i),L=ye(I,Ve,0);if(L<0){i=[I];return}let A=L;for(;A>0&&I[A]!==60;)A--;const D=d.decode(I.subarray(0,A)),X=c(D);await r.sheetStart(t,{...X,head:D}),o=!0,g=I.subarray(A)}m.feed(g),await f(),m.stopped&&(l=[m.rest.slice()])}),o)await f();else{const g=d.decode(q(i));c(g),await r.sheetStart(t,{...W(g),head:g})}(n.batch.count>0||n.batch.rowMeta!==null)&&await s.sendCells(t,n.batch);const w=l===null?"":d.decode(q(l)),y=Se(w);y.sparklines=ve(w,g=>Z(g,s.theme)),y.filter=Ie(w),Re(y,w,g=>Z(g,s.theme));const{comments:u,links:p,threads:v}=await Xe(h,e);y.threads=v;for(const g of y.hyperlinks)g.rid&&p.has(g.rid)&&(g.target=p.get(g.rid));await r.sheetEnd(t,{merges:Ue(w),tail:w,features:y,comments:u})}function q(h){if(h.length===1)return h[0];let e=0;for(const r of h)e+=r.length;const t=new Uint8Array(e);let s=0;for(const r of h)t.set(r,s),s+=r.length;return t}async function Xe(h,e){const t={comments:[],links:new Map,threads:[]},s=G(e);if(!h.has(s))return t;const r=P(await h.bytes(s));for(const i of N(r,"Relationship"))if(/\/hyperlink$/.test(i.a.Type))t.links.set(i.a.Id,i.a.Target);else if(/\/threadedComment$/.test(i.a.Type)){const o=C(e,i.a.Target);h.has(o)&&(t.threads=N(P(await h.bytes(o)),"threadedComment").map(l=>({id:l.a.id,ref:l.a.ref,personId:l.a.personId,date:l.a.dT??"",text:M(T(l,"text")?.t??""),parentId:l.a.parentId??null,done:l.a.done==="1",mentions:N(T(l,"mentions"),"mention").map(n=>({personId:n.a.mentionpersonId,id:n.a.mentionId,start:Number(n.a.startIndex),length:Number(n.a.length)}))})))}else if(/\/comments$/.test(i.a.Type)){const o=C(e,i.a.Target);h.has(o)&&(t.comments=xe(await h.bytes(o)))}return t}async function Ge(h,e){const t=[];for(let s=0;s<e.length;s++){const r=e[s].part;if(!r)continue;const i=G(r);if(!h.has(i))continue;const o=P(await h.bytes(i));for(const l of N(o,"Relationship")){if(!/\/table$/.test(l.a.Type))continue;const n=C(r,l.a.Target);if(!h.has(n))continue;const m=await h.bytes(n),d=P(m),c=ie(d.a.ref??"");if(!c)continue;const f=T(d,"tableStyleInfo")?.a??{};t.push({id:Number(d.a.id),part:n,source:!0,styleName:M(f.name??null),showRowStripes:f.showRowStripes!=="0",showColumnStripes:f.showColumnStripes==="1",showFirstColumn:f.showFirstColumn==="1",showLastColumn:f.showLastColumn==="1",hasFilter:T(d,"autoFilter")!==void 0,fileFilter:_e(m),name:d.a.displayName??d.a.name,sheetIndex:s,...c,headerRows:d.a.headerRowCount!==void 0?Number(d.a.headerRowCount):1,totalsRows:Number(d.a.totalsRowCount??0),columns:N(T(d,"tableColumns"),"tableColumn").map(w=>M(w.a.name))})}}return t}async function ht(h,e){const t=await we(h),s=P(await t.bytes("_rels/.rels")),r=N(s,"Relationship").find(a=>/officeDocument$/.test(a.a.Type));if(!r)throw new Error("This file has no workbook part");const i=C("",r.a.Target),o=P(await t.bytes(i)),l=G(i),n=P(await t.bytes(l)),m=new Map,d=new Set,c=new Set;let f=null,w=null,y=null;for(const a of N(n,"Relationship")){const S=C(i,a.a.Target);m.set(a.a.Id,S),/\/chartsheet$/.test(a.a.Type)&&d.add(a.a.Id),/\/worksheet$/.test(a.a.Type)&&c.add(a.a.Id),/\/sharedStrings$/.test(a.a.Type)?f=S:/\/styles$/.test(a.a.Type)?w=S:/\/theme$/.test(a.a.Type)&&(y=S)}const u=N(T(o,"sheets"),"sheet").map(a=>({name:M(a.a.name),rid:a.a.id,part:m.get(a.a.id),hidden:a.a.state==="hidden"||a.a.state==="veryHidden",veryHidden:a.a.state==="veryHidden",sheetId:a.a.sheetId,chart:d.has(a.a.id)})),p=new Set(u.map(a=>a.part).filter(Boolean));for(const a of u){if(a.rid||!/^\d+$/.test(a.sheetId))continue;const S="rId"+a.sheetId,O=m.get(S),pe=C(i,`worksheets/sheet${a.sheetId}.xml`);c.has(S)&&O===pe&&t.has(O)&&!p.has(O)&&(a.rid=S,a.part=O,p.add(O))}const v=y&&t.has(y)?ee(await t.bytes(y)):ee(new TextEncoder().encode("<a/>")),g=w&&t.has(w)?ge(await t.bytes(w),v):[],I=Number(T(T(o,"bookViews"),"workbookView")?.a.activeTab??0),L=a=>/^Z_.*\.wvu\.[A-Za-z]+$/.test(a.a.name),A=N(T(o,"definedNames"),"definedName").filter(L).map(a=>({name:a.a.name,text:a.t,localSheetId:Number(a.a.localSheetId)})),D=N(T(o,"customWorkbookViews"),"customWorkbookView").map(a=>({...a.a})),X=N(T(o,"definedNames"),"definedName").filter(a=>a.a.name==="_xlnm.Criteria"||!a.a.name.startsWith("_xlnm.")&&!L(a)).map(a=>({name:a.a.name,text:a.t,localSheetId:a.a.localSheetId!==void 0?Number(a.a.localSheetId):void 0,hidden:a.a.hidden==="1"||void 0,comment:M(a.a.comment)})),he=N(T(o,"definedNames"),"definedName").filter(a=>a.a.name==="_xlnm.Print_Area"||a.a.name==="_xlnm.Print_Titles").map(a=>({name:a.a.name,text:a.t,localSheetId:Number(a.a.localSheetId)})),ce=N(T(o,"definedNames"),"definedName").filter(a=>a.a.name==="_xlnm._FilterDatabase"||a.a.name==="_xlnm.Criteria"||a.a.name==="_xlnm.Extract").map(a=>({name:a.a.name,text:a.t,localSheetId:Number(a.a.localSheetId)})),k=T(o,"calcPr")?.a??{},Y=["1","true"].includes(T(o,"workbookPr")?.a.date1904),de=N(T(o,"pivotCaches"),"pivotCache").reduce((a,S)=>Math.max(a,Number(S.a.cacheId??0)),0),J={};if(w&&t.has(w))for(const a of N(T(P(await t.bytes(w)),"numFmts"),"numFmt"))J[a.a.numFmtId]=a.a.formatCode;const fe=await Ge(t,u),me=w&&t.has(w)?Te(await t.bytes(w),a=>Z(a,v)):[];await e.meta({sheets:u,styles:g,activeTab:I,workbookPart:i,stringsPart:f,stylesPart:w,names:X,maxPivotCacheId:de,numFmts:J,date1904:Y,workbookProtection:T(o,"workbookProtection")?.a??null,fileSharing:T(o,"fileSharing")?.a??null,persons:await Ze(t,n,i),printNames:he,filterNames:ce,viewNames:A,customViews:D,tables:fe,theme:v,themeName:v.themeName,dxfs:me,fullCalcOnLoad:k.fullCalcOnLoad==="1"||k.fullCalcOnLoad==="true",manualCalc:k.calcMode==="manual",calcMode:k.calcMode??"auto",iterate:k.iterate==="1"||k.iterate==="true",iterateCount:k.iterateCount!==void 0?Number(k.iterateCount):100,iterateDelta:k.iterateDelta!==void 0?Number(k.iterateDelta):.001,externalLinks:await Ce(t,o,n,i,{child:T,children:N,resolveTarget:C})});const R=new $e(e);if(f&&t.has(f)){const a=new H(new De(R));await ne(await t.stream(f),S=>{if(a.feed(S),R.pending>=ae||R.len>=1<<22)return R.flush()})}await R.flush(),await e.stringsEnd?.(R.total);const K=new Map,ue={theme:v,date1904:Y,defaultHeight:16,nextBatch:()=>e.recycle?.()??He(),addString(a){let S=K.get(a);return S===void 0&&(R.appendText(a),S=R.finish(),K.set(a,S)),S},async sendCells(a,S){await R.flush(),await e.cells(a,S)}};let Q=0;for(let a=0;a<u.length;a++){if(u[a].chart){await e.sheetStart(a,{...W(""),head:"",chartSheet:!0}),await e.sheetEnd(a,{merges:[],tail:t.has(u[a].part)?new TextDecoder().decode(await t.bytes(u[a].part)):""});continue}if(!u[a].part||!t.has(u[a].part)){await e.sheetStart(a,{...W(""),head:""}),await e.sheetEnd(a,{merges:[],tail:""});continue}await We(t,u[a].part,a,ue,e),Q++}return{zip:t,sheets:u,workbookPart:i,wbRelsPath:l,stringsPart:f,stylesPart:w,sheetsRead:Q}}async function Ze(h,e,t){const s=e?N(e,"Relationship").find(i=>/\/person$/.test(i.a.Type)):null,r=s?C(t,s.a.Target):"xl/persons/person.xml";return h.has(r)?N(P(await h.bytes(r)),"person").map(i=>{const o=M(i.a.displayName);return{displayName:o,id:i.a.id,userId:i.a.userId??o,providerId:i.a.providerId??"None"}}):[]}export{F as BATCH_CELLS,ne as pump,lt as pxToWidth,ht as readXlsx,C as resolveTarget,le as widthToPx};
1
+ import{encodeText as re}from"../core/strings.js";import{openZip as Ne}from"./zip-reader.js";import{child as v,children as N,decodeRange as k,indexOfSeq as _e,nameIs as x,parseAttrs as C,parseTree as L,unescapeOoxml as E,unescapeXml as $,XmlScanner as X}from"./xml-scan.js";import{relsPathOf as q,resolveTarget as A}from"./package-paths.js";import{parseStyles as Pe,parseTheme as oe,resolveColor as D}from"./xlsx-styles.js";import{parseComments as ke,parseDxfs as Re,parseSheetFeatures as Ce,splitCustomViews as Ae,TAIL_ELEMENTS as Me}from"./xlsx-tail.js";import{canonicalXml as Le,declareRelationships as le,respell as he,xmlSpelling as Ee}from"./canonical-xml.js";import{readSplitPane as Fe}from"../cells/view-xml.js";import{parseSparklines as Oe}from"../core/sparklines.js";import{readSheetFilter as be,readTableFilter as He}from"../cells/filter-file.js";import{parseNamedViews as $e,VIEWS_REL as De}from"../cells/sheet-views-file.js";import{readRunProp as ce}from"../cells/rich-xml.js";import{applyCfExt as Ve}from"../cells/cf-file.js";import{readSheetViewAttrs as Be}from"../cells/view-xml.js";import{readExternalLinks as We}from"../calcx/external-read.js";import{BOOL as Ue,EMPTY as Y,ERR as Xe,ERRORS as Ge,FORMULA as Ze,NUM as de,STR as fe}from"../core/sheet.js";import{parseRangeRef as J,MAX_COLS as F,MAX_ROWS as G}from"../core/address.js";import{DATE_1904_OFFSET as je}from"../core/numfmt.js";const H=65536,ze=16384,me=65536,Z=6,ue=new TextEncoder;function qe(h,e){const s=/^(?:(\d{4}-\d{2}-\d{2})(?:T|(?=Z|$))|T)?(?:(\d{2}):(\d{2})(?::(\d{2}(?:\.\d+)?))?)?(Z|[+-]\d{2}:?\d{2})?$/.exec(h);if(!s||!s[1]&&!s[2])return NaN;const[,t,i="0",o="0",a="0",l]=s;let c=Number(i)*3600+Number(o)*60+Number(a);if(l&&l!=="Z"){const n=Number(l.slice(1,3))*60+Number(l.slice(-2));c-=(l[0]==="-"?-n:n)*60}if(!t)return c/86400;const m=Date.parse(t)/864e5+25569;return(e?m-je:m<61?m-1:m)+c/86400}async function pe(h,e){const s=h.getReader();for(;;){const{done:t,value:i}=await s.read();if(t)return;const o=e(i);o!==void 0&&await o}}const K=new Float64Array(23);for(let h=0,e=1;h<23;h++,e*=10)K[h]=e;function V(h,e,s){let t=e,i=!1;h[t]===45?(i=!0,t++):h[t]===43&&t++;let o=0,a=0,l=0,c=t<s;for(;t<s;t++){const n=h[t]-48;if(n>=0&&n<=9)o=o*10+n,o!==0&&a++;else break}if(t<s&&h[t]===46)for(t++;t<s;t++){const n=h[t]-48;if(n>=0&&n<=9)o=o*10+n,o!==0&&a++,l++;else break}let m=0;if(t<s&&(h[t]===69||h[t]===101)){t++;let n=!1;for(h[t]===45?(n=!0,t++):h[t]===43&&t++;t<s;t++){const f=h[t]-48;if(f>=0&&f<=9)m=m*10+f;else{c=!1;break}}n&&(m=-m)}else t<s&&(c=!1);const d=m-l;if(c&&a<=15&&d>=-22&&d<=22){const n=d<0?o/K[-d]:o*K[d];return i?-n:n}return Number(k(h,e,s))}class Ye{constructor(e){this.sink=e,this.bytes=new Uint8Array(1<<20),this.len=0,this.offsets=new Uint32Array(me+1),this.count=0,this.total=0,this.rich=null}addRich(e,s){const t=this.bytes.subarray(this.offsets[this.count-1],this.offsets[this.count]),i=new TextDecoder;for(const o of s)o.at=i.decode(t.subarray(0,o.at)).length;(this.rich??=[]).push([e,s])}_reserve(e){if(this.len+e>this.bytes.length){const s=new Uint8Array(Math.max(this.bytes.length*2,this.len+e));s.set(this.bytes.subarray(0,this.len)),this.bytes=s}}appendXml(e,s,t,i){if(!i){for(;s<t&&e[s]<=32;)s++;for(;t>s&&e[t-1]<=32;)t--}let o=!0;for(let a=s;a<t;a++){const l=e[a];if(l===13||l===38||l===95&&e[a+1]===120){o=!1;break}}if(o)this._reserve(t-s),this.bytes.set(e.subarray(s,t),this.len),this.len+=t-s;else{const a=re(E($(k(e,s,t))));this._reserve(a.length),this.bytes.set(a,this.len),this.len+=a.length}}appendText(e){const s=re(e);this._reserve(s.length),this.bytes.set(s,this.len),this.len+=s.length}finish(){const e=this.total++;if(this.count++,this.count>=this.offsets.length){const s=new Uint32Array(this.offsets.length*2);s.set(this.offsets),this.offsets=s}return this.offsets[this.count]=this.len,e}get pending(){return this.count}flush(){if(this.count===0)return;const e=this.bytes.slice(0,this.len),s=this.offsets.slice(0,this.count+1);this.len=0,this.count=0,this.offsets[0]=0;const{rich:t}=this;return this.rich=null,this.sink.strings(e,s,t)}}const we=new TextDecoder,ye=(h,e,s)=>s>e&&/\bxml:space\s*=\s*['"]preserve['"]/.test(k(h,e,s));class Je{constructor(e){this.pages=e,this.inT=!1,this.phonetic=0,this.runs=null,this.run=null,this.inProps=!1}_finish(){const e=this.pages.finish();this.runs!==null&&(this.pages.addRich(e,this.runs),this.runs=null)}open(e,s,t,i,o,a){const l=t-s;this.inProps?this._runProp(e,s,t,i,o):l===1&&e[s]===116?(this.inT=!a&&this.phonetic===0,this.preserveSpace=this.inT&&ye(e,i,o)):l===1&&e[s]===114&&!a&&this.phonetic===0?(this.run={at:this.pages.len-this.pages.offsets[this.pages.count]},(this.runs??=[]).push(this.run)):l===3&&x(e,s,t,"rPh")&&!a?this.phonetic++:l===3&&x(e,s,t,"rPr")&&!a&&this.run!==null?this.inProps=!0:l===2&&a&&x(e,s,t,"si")&&this._finish()}_runProp(e,s,t,i,o){ce(this.run,we.decode(e.subarray(s,t)),C(e,i,o))}close(e,s,t){const i=t-s;i===1&&e[s]===116?this.inT=!1:i===2&&x(e,s,t,"si")?this._finish():i===3&&x(e,s,t,"rPh")?this.phonetic--:i===3&&x(e,s,t,"rPr")&&(this.inProps=!1)}text(e,s,t){this.inT&&this.pages.appendXml(e,s,t,this.preserveSpace)}}function Ke(){return{count:0,rows:new Uint32Array(H),cols:new Uint16Array(H),kinds:new Uint8Array(H),values:new Float64Array(H),styles:new Uint16Array(H),formulas:null,valueMeta:null,rowMeta:null}}class Qe{constructor(e){this.ctx=e,this.scanner=null,this.batch=e.nextBatch(),this.row=-1,this.col=-1,this.style=0,this.type=0,this.typeLong=!1,this.kind=Y,this.value=0,this.inV=!1,this.inF=!1,this.inT=!1,this.inIs=!1,this.phonetic=0,this.formula=null,this.formulaText="",this.pendingText=null,this.runs=null,this.inProps=!1,this.flushes=[],this.sharedByIndex=new Map}open(e,s,t,i,o,a){const l=t-s;if(this.inProps)ce(this.runs.at(-1),we.decode(e.subarray(s,t)),C(e,i,o));else if(l===1){const c=e[s];c===99?this._cellOpen(e,i,o,a):c===118?(this.inV=!a,this.type===115&&this.typeLong&&(this.pendingText="")):c===102?this._formulaOpen(e,i,o,a):c===116&&this.inIs&&this.phonetic===0?(this.inT=!a,this.preserveSpace=this.inT&&ye(e,i,o)):c===114&&this.inIs&&!a&&this.phonetic===0&&(this.runs??=[]).push({at:E(this.pendingText).length})}else l===3&&e[s]===114&&e[s+1]===111?this._rowOpen(e,i,o):l===2&&e[s]===105&&e[s+1]===115?(this.inIs=!a,this.pendingText=""):l===3&&x(e,s,t,"rPh")&&!a?this.phonetic++:l===3&&x(e,s,t,"rPr")&&!a&&this.runs!==null?this.inProps=!0:l===9&&a&&x(e,s,t,"sheetData")&&(this.scanner.stopped=!0)}close(e,s,t){const i=t-s;if(i===1){const o=e[s];o===99?this._commit():o===118?this.inV=!1:o===102?this._formulaClose():o===116&&(this.inT=!1)}else i===2&&e[s]===105&&e[s+1]===115?this.inIs=!1:i===3&&x(e,s,t,"rPh")?this.phonetic--:i===3&&x(e,s,t,"rPr")?this.inProps=!1:i===9&&x(e,s,t,"sheetData")&&(this.scanner.stopped=!0)}text(e,s,t){if(this.inV)this._value(e,s,t);else if(this.inF)this.formulaText+=k(e,s,t);else if(this.inT){if(!this.preserveSpace){for(;s<t&&e[s]<=32;)s++;for(;t>s&&e[t-1]<=32;)t--}this.pendingText+=$(k(e,s,t))}}_rowOpen(e,s,t){let i=-1,o=0,a=0,l=!1,c=!1,m=null,d=s,n=-1;for(;d<t;){for(;d<t&&e[d]<=32;)d++;if(d>=t)break;const f=d;for(;d<t&&e[d]!==61;)d++;const p=d;d+=2;const w=d;for(;d<t&&e[d]!==34&&e[d]!==39;)d++;const u=d;d++;const y=p-f;if(y===1&&e[f]===114)n=V(e,w,u)-1;else if(y===1&&e[f]===115)a=V(e,w,u);else if(y===2&&e[f]===104&&e[f+1]===116)i=V(e,w,u);else if(y===6&&x(e,f,p,"hidden"))o=e[w]===49||e[w]===116?1:0;else if(y===12&&x(e,f,p,"customFormat"))l=e[w]===49||e[w]===116;else if(y===12&&x(e,f,p,"customHeight"))c=e[w]===49||e[w]===116;else if(!(y===5&&x(e,f,p,"spans"))){const I=k(e,f,u+1);m=m===null?I:`${m} ${I}`}}if(this.row=n>=0?n:this.row+1,this.col=-1,this.row<G&&(o||m!==null||l&&a||i>=0&&(c||i!==this.ctx.defaultHeight))){const f=this.batch;f.rowMeta===null&&(f.rowMeta=[]),f.rowMeta.push(this.row,i>=0?i:-1,o,l&&a<this.ctx.styleCount?a:0,c?1:0,m)}}_cellOpen(e,s,t,i){let o=-1,a=0,l=0,c=!1,m=0,d=0,n=s;for(;n<t;){for(;n<t&&e[n]<=32;)n++;if(n>=t)break;const f=e[n],p=e[n+1]===61,w=e[n+1]===109&&e[n+2]===61&&(f===99||f===118);for(;n<t&&e[n]!==61;)n++;if(n+=2,p&&f===114){let u=0,y=e[n];for(;y>=65&&y<=90;)u=u*26+y-64,y=e[++n];o=u-1;let I=0;for(;y>=48&&y<=57;)I=I*10+y-48,y=e[++n];I>0&&(this.row=I-1)}else if(p&&f===115){let u=0,y=e[n];for(;y>=48&&y<=57;)u=u*10+y-48,y=e[++n];a=u}else if(p&&f===116)l=e[n],c=e[n+1]!==34&&e[n+1]!==39;else if(w){let u=0,y=e[n];for(;y>=48&&y<=57;)u=u*10+y-48,y=e[++n];f===99?m=u:d=u}for(;n<t&&e[n]!==34&&e[n]!==39;)n++;n++}this.col=o>=0?o:this.col+1,this.style=a<this.ctx.styleCount?a:0,this.type=l,this.typeLong=c,this.cm=m,this.vm=d,this.kind=Y,this.value=0,this.formula=null,this.pendingText=null,i&&this._commit()}_value(e,s,t){if(s!==t)switch(this.type){case 0:case 110:this.kind=de,this.value=V(e,s,t);break;case 115:this.typeLong?this.pendingText=(this.pendingText??"")+$(k(e,s,t)):(this.kind=fe,this.value=V(e,s,t));break;case 98:this.kind=Ue,this.value=e[s]===49||e[s]===116?1:0;break;case 101:{const i=Ge.indexOf(k(e,s,t));this.kind=Xe,this.value=i<0?6:i;break}case 100:{const i=k(e,s,t),o=qe(i,this.ctx.date1904);Number.isFinite(o)?(this.kind=de,this.value=o):this.pendingText=i;break}default:{const i=k(e,s,t);this.pendingText=(this.pendingText??"")+$(i)}}}_formulaOpen(e,s,t,i){const o=C(e,s,t),a={};if(o.t&&(a.t=o.t),o.si!==void 0&&(a.si=Number(o.si)),o.ref&&(a.ref=o.ref),o.ca&&(a.ca=o.ca),o.t==="dataTable")for(const l of["dt2D","dtr","r1","r2","del1","del2"])o[l]!==void 0&&(a[l]=o[l]);else{const l=k(e,s,t).trim();l&&(a.raw=l)}this.formula=a,this.formulaText="",this.inF=!i,i&&a.t==="shared"&&this._resolveShared(a)}_formulaClose(){this.inF=!1;const e=this.formula;e!==null&&(this.formulaText&&(e.f=$(this.formulaText)),e.t==="shared"&&this._resolveShared(e))}_resolveShared(e){if(e.f!==void 0)e.base=this.row*F+this.col,this.sharedByIndex.set(e.si,e);else{const s=this.sharedByIndex.get(e.si);s!==void 0&&(s.child===void 0&&(s.child={t:"shared",si:e.si,sf:s.f,base:s.base}),this.formula=s.child)}}_commit(){let e=this.kind,s=this.value;if(this.pendingText!==null&&(s=this.ctx.addString(E(this.pendingText),this.runs),e=fe,this.pendingText=null,this.runs=null),!(this.row<G)||this.col>=F){this.formula=null;return}const t=this.batch,i=this.formula;if(i!==null&&(i.f!==void 0||i.t==="shared"||i.t==="array"||i.t==="dataTable"))e|=Ze,this.cm!==0&&(i.cm=this.cm),t.formulas===null&&(t.formulas=[]),t.formulas.push([this.row*F+this.col,i]);else if(e===Y&&this.style===0)return;this.vm!==0&&(t.valueMeta===null&&(t.valueMeta=[]),t.valueMeta.push([this.row*F+this.col,this.vm]));const o=t.count++;t.rows[o]=this.row,t.cols[o]=this.col,t.kinds[o]=e,t.values[o]=s,t.styles[o]=this.style,this.formula=null,(t.count===H||t.formulas!==null&&t.formulas.length>=ze)&&(this.flushes.push(t),this.batch=this.ctx.nextBatch())}}const b=(h,e,s,t)=>{const i=h===void 0||h===""?NaN:Number(h);return i>=e&&i<=s?i:t};function Q(h,e=1/0,s=[]){let t=null;const i={defaultHeight:16,defaultWidth:65,cols:[],frozenRows:0,frozenCols:0,showGridlines:!0,zoom:1,tabColor:null};return new X({open(a,l,c,m,d){if(x(a,l,c,"outlinePr")){const n=C(a,m,d);i.summaryAbove=n.summaryBelow==="0"||n.summaryBelow==="false",i.outlineAutoStyles=n.applyStyles==="1"||n.applyStyles==="true",i.summaryLeft=n.summaryRight==="0"||n.summaryRight==="false"}else if(x(a,l,c,"tabColor")){const n=C(a,m,d);i.tabColor=D({a:n},s)}else if(x(a,l,c,"sheetFormatPr")){const n=C(a,m,d);i.exactHeight=b(n.defaultRowHeight,0,409.5,16),i.defaultHeight=Math.round(i.exactHeight),n.defaultColWidth?i.defaultWidth=ge(b(n.defaultColWidth,0,256,10)):i.defaultWidth=b(n.baseColWidth??8,0,255,8)*Z+5}else if(x(a,l,c,"col")){const n=C(a,m,d),f=Number(n.min),p=f>=1&&f<=F,w=[];for(const u of["bestFit","outlineLevel","collapsed","phonetic"])n[u]!==void 0&&w.push(`${u}="${n[u]}"`);p&&i.cols.push({min:f-1,max:Math.min(Number(n.max)-1,F-1),width:n.width!==void 0?ge(b(n.width,0,256,10)):-1,hidden:n.hidden==="1"||n.hidden==="true",style:Number(n.style??0)<e?Number(n.style??0):0,extra:w.length?w.join(" "):null})}else if(x(a,l,c,"sheetView")){const n=C(a,m,d);(n.showGridLines==="0"||n.showGridLines==="false")&&(i.showGridlines=!1),n.tabSelected==="1"&&(i.tabSelected=!0),(n.rightToLeft==="1"||n.rightToLeft==="true")&&(i.rtl=!0),n.zoomScale&&(i.zoom=b(n.zoomScale,10,400,100)/100),Be(n,i),t=n.topLeftCell?J(n.topLeftCell):null}else if(x(a,l,c,"pane")){const n=C(a,m,d);if(n.state==="frozen"||n.state==="frozenSplit"){const f=b(n.ySplit??0,0,G-1,0),p=b(n.xSplit??0,0,F-1,0),w=f>0&&t&&t.r0+f<G?t.r0:0,u=p>0&&t&&t.c0+p<F?t.c0:0;Object.assign(i,{frozenRows:w+f,frozenCols:u+p,frozenTop:w,frozenLeft:u})}else Fe(n,i)}},close(){},text(){}}).feed(ue.encode(h)),i}function ge(h){return Math.trunc((256*h+Math.trunc(128/Z))/256*Z)}function _t(h){return Math.trunc(h/Z*256)/256}function et(h){const e=[];return h.indexOf("mergeCell")<0||new X({open(t,i,o,a,l){if(x(t,i,o,"mergeCell")){const c=J(C(t,a,l).ref??"");c&&e.push(c)}},close(){},text(){}}).feed(ue.encode(h)),e}const tt=new RegExp(`<(?:${Me.join("|")}|mc:AlternateContent)\\b|</worksheet>`),st=[..."sheetData"].map(h=>h.charCodeAt(0));async function it(h,e,s,t,i){let o=[],a=!1,l=null,c=null,m=null,d=null;const n=new TextDecoder,f=g=>{const T=Q(g,t.styleCount,t.theme);return t.defaultHeight=T.exactHeight??T.defaultHeight,c=new Qe(t),m=new X(c),c.scanner=m,T},p=async()=>{if(c.flushes.length===0)return;const g=c.flushes;c.flushes=[];for(const T of g)await t.sendCells(s,T)};await pe(await h.stream(e),async g=>{if(l!==null){l.push(g);return}if(!a){o.push(g);const T=ee(o),O=_e(T,st,0);if(O<0){o=[T];return}let M=O;for(;M>0&&T[M]!==60;)M--;const W=n.decode(T.subarray(0,M));d=Ee(W);const U=le(he(W,d)),z=f(U);await i.sheetStart(s,{...z,head:U}),a=!0,g=T.subarray(M)}m.feed(g),await p(),m.stopped&&(l=[m.rest.slice()])});let w;if(a)await p(),w=l===null?"":he(n.decode(ee(l)),d,{hasRoot:!1});else{const g=Le(n.decode(ee(o))).replace(/^([^<]*(?:<\?[\s\S]*?\?>[^<]*)*<worksheet\b[^>]*?)\/>/,"$1></worksheet>"),T=g.search(tt),O=le(T<0?g:g.slice(0,T));w=T<0?"":g.slice(T);const M=f(O);await i.sheetStart(s,{...M,head:O})}(c.batch.count>0||c.batch.rowMeta!==null)&&await t.sendCells(s,c.batch);const u=Ce(w);u.sparklines=Oe(w,g=>D(g,t.theme)),u.filter=be(Ae(w).rest),Ve(u,w,g=>D(g,t.theme));const{comments:y,links:I,threads:B,namedViews:j}=await nt(h,e,g=>D(g,t.theme));u.threads=B;for(const g of u.hyperlinks)g.rid&&I.has(g.rid)&&(g.target=I.get(g.rid));await i.sheetEnd(s,{merges:et(w),tail:w,features:u,comments:y,namedViews:j})}function ee(h){if(h.length===1)return h[0];let e=0;for(const i of h)e+=i.length;const s=new Uint8Array(e);let t=0;for(const i of h)s.set(i,t),t+=i.length;return s}async function nt(h,e,s){const t={comments:[],links:new Map,threads:[],namedViews:[]},i=q(e);if(!h.has(i))return t;const o=L(await h.bytes(i));for(const a of N(o,"Relationship"))if(/\/hyperlink$/.test(a.a.Type))t.links.set(a.a.Id,a.a.Target);else if(a.a.Type===De){const l=A(e,a.a.Target);h.has(l)&&(t.namedViews=$e(await h.bytes(l),s))}else if(/\/threadedComment$/.test(a.a.Type)){const l=A(e,a.a.Target);h.has(l)&&(t.threads=N(L(await h.bytes(l)),"threadedComment").map(c=>({id:c.a.id,ref:c.a.ref,personId:c.a.personId,date:c.a.dT??"",text:E(v(c,"text")?.t??""),parentId:c.a.parentId??null,done:c.a.done==="1",mentions:N(v(c,"mentions"),"mention").map(m=>({personId:m.a.mentionpersonId,id:m.a.mentionId,start:Number(m.a.startIndex),length:Number(m.a.length)}))})))}else if(/\/comments$/.test(a.a.Type)){const l=A(e,a.a.Target);h.has(l)&&(t.comments=ke(await h.bytes(l),s))}return t}async function at(h,e){const s=[];for(let t=0;t<e.length;t++){const i=e[t].part;if(!i)continue;const o=q(i);if(!h.has(o))continue;const a=L(await h.bytes(o));for(const l of N(a,"Relationship")){if(!/\/table$/.test(l.a.Type))continue;const c=A(i,l.a.Target);if(!h.has(c))continue;const m=await h.bytes(c),d=L(m),n=J(d.a.ref??"");if(!n)continue;const f=v(d,"tableStyleInfo")?.a??{};s.push({id:Number(d.a.id),part:c,source:!0,styleName:E(f.name??null),showRowStripes:f.showRowStripes!=="0",showColumnStripes:f.showColumnStripes==="1",showFirstColumn:f.showFirstColumn==="1",showLastColumn:f.showLastColumn==="1",hasFilter:v(d,"autoFilter")!==void 0,fileFilter:He(m),name:d.a.displayName??d.a.name,sheetIndex:t,...n,headerRows:d.a.headerRowCount!==void 0?Number(d.a.headerRowCount):1,totalsRows:Number(d.a.totalsRowCount??0),columns:N(v(d,"tableColumns"),"tableColumn").map(p=>E(p.a.name))})}}return s}async function Pt(h,e){const s=await Ne(h),t=L(await s.bytes("_rels/.rels")),i=N(t,"Relationship").find(r=>/officeDocument$/.test(r.a.Type));if(!i)throw new Error("This file has no workbook part");const o=A("",i.a.Target),a=L(await s.bytes(o)),l=q(o),c=L(await s.bytes(l)),m=new Map,d=new Set,n=new Set;let f=null,p=null,w=null;for(const r of N(c,"Relationship")){const S=A(o,r.a.Target);m.set(r.a.Id,S),/\/chartsheet$/.test(r.a.Type)&&d.add(r.a.Id),/\/worksheet$/.test(r.a.Type)&&n.add(r.a.Id),/\/sharedStrings$/.test(r.a.Type)?f=S:/\/styles$/.test(r.a.Type)?p=S:/\/theme$/.test(r.a.Type)&&(w=S)}const u=N(v(a,"sheets"),"sheet").map(r=>({name:E(r.a.name),rid:r.a.id,part:m.get(r.a.id),hidden:r.a.state==="hidden"||r.a.state==="veryHidden",veryHidden:r.a.state==="veryHidden",sheetId:r.a.sheetId,chart:d.has(r.a.id)})),y=new Set(u.map(r=>r.part).filter(Boolean));for(const r of u){if(r.rid||!/^\d+$/.test(r.sheetId))continue;const S="rId"+r.sheetId,P=m.get(S),Ie=A(o,`worksheets/sheet${r.sheetId}.xml`);n.has(S)&&P===Ie&&s.has(P)&&!y.has(P)&&(r.rid=S,r.part=P,y.add(P))}const I=w&&s.has(w)?oe(await s.bytes(w)):oe(new TextEncoder().encode("<a/>")),B=p&&s.has(p)?Pe(await s.bytes(p),I):[],j=Number(v(v(a,"bookViews"),"workbookView")?.a.activeTab??0),g=N(v(a,"definedNames"),"definedName").filter(r=>r.a.name),T=r=>/^Z_.*\.wvu\.[A-Za-z]+$/.test(r.a.name),O=g.filter(T).map(r=>({name:r.a.name,text:r.t,localSheetId:Number(r.a.localSheetId)})),M=N(v(a,"customWorkbookViews"),"customWorkbookView").map(r=>({...r.a})),W=g.filter(r=>r.a.name==="_xlnm.Criteria"||!r.a.name.startsWith("_xlnm.")&&!T(r)).map(r=>({name:r.a.name,text:r.t,localSheetId:r.a.localSheetId!==void 0?Number(r.a.localSheetId):void 0,hidden:r.a.hidden==="1"||void 0,comment:E(r.a.comment)})),U=g.filter(r=>r.a.name==="_xlnm.Print_Area"||r.a.name==="_xlnm.Print_Titles").map(r=>({name:r.a.name,text:r.t,localSheetId:Number(r.a.localSheetId)})),z=g.filter(r=>r.a.name==="_xlnm._FilterDatabase"||r.a.name==="_xlnm.Criteria"||r.a.name==="_xlnm.Extract").map(r=>({name:r.a.name,text:r.t,localSheetId:Number(r.a.localSheetId)})),te=v(a,"calcPr"),_=te?.a??{},se=["1","true"].includes(v(a,"workbookPr")?.a.date1904),xe=N(v(a,"pivotCaches"),"pivotCache").reduce((r,S)=>Math.max(r,Number(S.a.cacheId??0)),0),ie={};if(p&&s.has(p))for(const r of N(v(L(await s.bytes(p)),"numFmts"),"numFmt"))ie[r.a.numFmtId]=r.a.formatCode;const Te=await at(s,u),Se=p&&s.has(p)?Re(await s.bytes(p),r=>D(r,I)):[];await e.meta({sheets:u,styles:B,activeTab:j,workbookPart:o,stringsPart:f,stylesPart:p,names:W,maxPivotCacheId:xe,numFmts:ie,date1904:se,workbookProtection:v(a,"workbookProtection")?.a??null,fileSharing:v(a,"fileSharing")?.a??null,persons:await rt(s,c,o),printNames:U,filterNames:z,viewNames:O,customViews:M,tables:Te,theme:I,themeName:I.themeName,dxfs:Se,fullCalcOnLoad:!te||_.fullCalcOnLoad==="1"||_.fullCalcOnLoad==="true",manualCalc:_.calcMode==="manual",calcOnSave:_.calcOnSave!=="0"&&_.calcOnSave!=="false",calcMode:_.calcMode??"auto",fullPrecision:_.fullPrecision!=="0"&&_.fullPrecision!=="false",iterate:_.iterate==="1"||_.iterate==="true",iterateCount:_.iterateCount!==void 0?Number(_.iterateCount):100,iterateDelta:_.iterateDelta!==void 0?Number(_.iterateDelta):.001,externalLinks:await We(s,a,c,o,{child:v,children:N,resolveTarget:A})});const R=new Ye(e);if(f&&s.has(f)){const r=new X(new Je(R));await pe(await s.stream(f),S=>{if(r.feed(S),R.pending>=me||R.len>=1<<22)return R.flush()})}await R.flush(),await e.stringsEnd?.(R.total);const ne=new Map,ve={theme:I,date1904:se,styleCount:B.length,defaultHeight:16,nextBatch:()=>e.recycle?.()??Ke(),addString(r,S=null){let P=S===null?ne.get(r):void 0;return P===void 0&&(R.appendText(r),P=R.finish(),S===null?ne.set(r,P):(R.rich??=[]).push([P,S])),P},async sendCells(r,S){await R.flush(),await e.cells(r,S)}};let ae=0;for(let r=0;r<u.length;r++){if(u[r].chart){await e.sheetStart(r,{...Q(""),head:"",chartSheet:!0}),await e.sheetEnd(r,{merges:[],tail:s.has(u[r].part)?new TextDecoder().decode(await s.bytes(u[r].part)):""});continue}if(!u[r].part||!s.has(u[r].part)){await e.sheetStart(r,{...Q(""),head:""}),await e.sheetEnd(r,{merges:[],tail:""});continue}await it(s,u[r].part,r,ve,e),ae++}return{zip:s,sheets:u,workbookPart:o,wbRelsPath:l,stringsPart:f,stylesPart:p,sheetsRead:ae}}async function rt(h,e,s){const t=e?N(e,"Relationship").find(o=>/\/person$/.test(o.a.Type)):null,i=t?A(s,t.a.Target):"xl/persons/person.xml";return h.has(i)?N(L(await h.bytes(i)),"person").map(o=>{const a=E(o.a.displayName);return{displayName:a,id:o.a.id,userId:o.a.userId??a,providerId:o.a.providerId??"None"}}):[]}export{H as BATCH_CELLS,pe as pump,_t as pxToWidth,Pt as readXlsx,A as resolveTarget,ge as widthToPx};
package/io/xlsx-styles.js CHANGED
@@ -1,2 +1,2 @@
1
- import{child as s,children as h,parseTree as v}from"./xml-scan.js";import{escapeMarkup as T}from"./xml-escape.js";import{gradientFillXml as R,parseGradientFill as j,underlineFromFile as E,underlineXml as L}from"../cells/style-xml.js";import{BUILTIN_FORMATS as S}from"../core/numfmt.js";import{defaultStyle as X}from"../core/styles.js";import{newCellStyles as O,newStyleSections as U,patchStyleSections as z,tagNamedStyles as D,withNamedStyles as w}from"../cells/cell-styles-xml.js";import{borderRefs as P,colorAttrs as I,fillRefs as q,fontRefs as B,readStyleRefs as _}from"../api/style-refs.js";const G=["000000","FFFFFF","FF0000","00FF00","0000FF","FFFF00","FF00FF","00FFFF","000000","FFFFFF","FF0000","00FF00","0000FF","FFFF00","FF00FF","00FFFF","800000","008000","000080","808000","800080","008080","C0C0C0","808080","9999FF","993366","FFFFCC","CCFFFF","660066","FF8080","0066CC","CCCCFF","000080","FF00FF","FFFF00","00FFFF","800080","800000","008080","0000FF","00CCFF","CCFFFF","CCFFCC","FFFF99","99CCFF","FF99CC","CC99FF","FFCC99","3366FF","33CCCC","99CC00","FFCC00","FF9900","FF6600","666699","969696","003366","339966","003300","333300","993300","993366","333399","333333"],H=["FFFFFF","000000","E8E8E8","0E2841","156082","E97132","196B24","0F9ED5","A02B93","4EA72E","467886","96607D"];function st(t){const n=v(t),o=s(n,"themeElements"),r=s(o,"clrScheme");if(!r)return H;const a=m=>{const p=s(r,m)?.c[0];return(p?.a.lastClr??p?.a.val??"000000").toUpperCase()},i=["lt1","dk1","lt2","dk2","accent1","accent2","accent3","accent4","accent5","accent6","hlink","folHlink"].map(a);return i.themeName=n.a?.name??null,i}function J(t,n){if(!n)return t;const o=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,a=parseInt(t.slice(4,6),16)/255,i=Math.max(o,r,a),m=Math.min(o,r,a);let c=(i+m)/2;const p=i-m,d=p===0?0:p/(1-Math.abs(2*c-1));let e=0;p!==0&&(i===o?e=((r-a)/p+6)%6:i===r?e=(a-o)/p+2:e=(o-r)/p+4),c=n<0?c*(1+n):c*(1-n)+n;const l=(1-Math.abs(2*c-1))*d,f=l*(1-Math.abs(e%2-1)),u=c-l/2,[F,g,x]=e<1?[l,f,0]:e<2?[f,l,0]:e<3?[0,l,f]:e<4?[0,f,l]:e<5?[f,0,l]:[l,0,f],$=N=>Math.round((N+u)*255).toString(16).padStart(2,"0");return($(F)+$(g)+$(x)).toUpperCase()}function at(t,n){return b(t,n)}function b(t,n){if(!t)return null;const o=t.a;let r=null;if(o.rgb)r=o.rgb.slice(-6).toUpperCase();else if(o.theme!==void 0)r=n[Number(o.theme)]??"000000";else if(o.indexed!==void 0){const a=Number(o.indexed);if(a>=64)return null;r=G[a]}else return null;return"#"+J(r,o.tint?Number(o.tint):0)}function ft(t,n){const o=v(t),r=new Map;for(const e of h(s(o,"numFmts"),"numFmt"))r.set(Number(e.a.numFmtId),e.a.formatCode);const a=h(s(o,"fonts"),"font").map(e=>{const l=F=>s(e,F)?.a.val,f=s(e,"u"),u=F=>{const g=s(e,F);return g!==void 0&&g.a.val!=="0"&&g.a.val!=="false"};return{fontName:l("name")??"Calibri",fontSize:Number(l("sz")??11),bold:u("b"),italic:u("i"),underline:f?E(f.a.val):0,strike:u("strike"),...l("vertAlign")==="superscript"||l("vertAlign")==="subscript"?{vertAlign:l("vertAlign")}:{},color:K(b(s(e,"color"),n))}}),i=h(s(o,"fills"),"fill").map(e=>{const l=s(e,"gradientFill");if(l)return j(l,u=>h(u,"stop").map(F=>({pos:F.a.position,color:s(F,"color")})),u=>b(u,n));const f=s(e,"patternFill");return!f||!f.a.patternType||f.a.patternType==="none"?null:f.a.patternType==="solid"?{fill:b(s(f,"fgColor"),n)??b(s(f,"bgColor"),n)}:{fill:s(f,"bgColor")?.a.indexed==="64"?"#000000":b(s(f,"bgColor"),n)??"#FFFFFF",pattern:{type:f.a.patternType,fg:b(s(f,"fgColor"),n)??"#000000"}}}),m=h(s(o,"borders"),"border").map(e=>{const l=M=>{const y=s(e,M);return!y||!y.a.style||y.a.style==="none"?null:{style:y.a.style,color:b(s(y,"color"),n)??"#000000"}},f=l("left"),u=l("right"),F=l("top"),g=l("bottom"),x=l("diagonal"),$=e.a.diagonalUp==="1"||e.a.diagonalUp==="true",N=e.a.diagonalDown==="1"||e.a.diagonalDown==="true";return x&&($||N)?{l:f,r:u,t:F,b:g,d:x,up:$,down:N}:f||u||F||g?{l:f,r:u,t:F,b:g}:null}),c=e=>b(e,n),p={fonts:h(s(o,"fonts"),"font").map(e=>B(e,s,c)),fills:h(s(o,"fills"),"fill").map(e=>q(e,s,c)),borders:h(s(o,"borders"),"border").map(e=>P(e,s,c))},d=h(s(o,"cellXfs"),"xf").map(e=>{const l=e.a,f=_(p,l),u=s(e,"alignment")?.a??{},F=Number(l.numFmtId??0);return{...X(),...a[Number(l.fontId??0)]??{},fill:i[Number(l.fillId??0)]?.fill??null,...i[Number(l.fillId??0)]?.pattern?{pattern:i[Number(l.fillId??0)].pattern}:{},...i[Number(l.fillId??0)]?.gradient?{gradient:i[Number(l.fillId??0)].gradient}:{},...l.quotePrefix==="1"||l.quotePrefix==="true"?{quotePrefix:!0}:{},borders:m[Number(l.borderId??0)]??null,numFmt:r.get(F)??S[F]??"General",hAlign:u.horizontal&&u.horizontal!=="general"?u.horizontal:null,vAlign:u.vertical??null,wrap:u.wrapText==="1"||u.wrapText==="true",indent:Number(u.indent??0),rotation:Number(u.textRotation??0),shrink:u.shrinkToFit==="1"||u.shrinkToFit==="true",...u.readingOrder==="1"||u.readingOrder==="2"?{readingOrder:Number(u.readingOrder)}:{},...u.justifyLastLine==="1"||u.justifyLastLine==="true"?{justifyLastLine:!0}:{},...s(e,"protection")?.a.locked==="0"?{unlocked:!0}:{},...s(e,"protection")?.a.hidden==="1"?{hiddenFormula:!0}:{},...f?{themeRefs:f}:{}}});return D(d,o)}function K(t){return t==="#000000"?null:t}function Q(t){const n=[];return t.bold&&n.push("<b/>"),t.italic&&n.push("<i/>"),t.strike&&n.push("<strike/>"),t.underline&&n.push(L(t.underline)),t.vertAlign&&n.push(`<vertAlign val="${t.vertAlign}"/>`),n.push(`<sz val="${t.fontSize}"/>`),(t.color||t.themeRefs?.color)&&n.push(`<color ${I(t.themeRefs?.color,t.color)}/>`),n.push(`<name val="${T(t.fontName)}"/>`),t.themeRefs?.font&&n.push(`<scheme val="${t.themeRefs.font}"/>`),`<font>${n.join("")}</font>`}function V(t){return t.gradient?R(t.gradient):t.pattern?`<fill><patternFill patternType="${t.pattern.type}"><fgColor ${I(t.themeRefs?.patternFg,t.pattern.fg)}/><bgColor ${I(t.themeRefs?.fill,t.fill??"#FFFFFF")}/></patternFill></fill>`:t.fill?`<fill><patternFill patternType="solid"><fgColor ${I(t.themeRefs?.fill,t.fill)}/><bgColor indexed="64"/></patternFill></fill>`:'<fill><patternFill patternType="none"/></fill>'}function W(t){const n={left:"l",right:"r",top:"t",bottom:"b",diagonal:"d"},o=(i,m)=>m?`<${i} style="${m.style}"><color ${I(t.themeRefs?.border?.[n[i]],m.color)}/></${i}>`:`<${i}/>`,r=t.borders??{};return`<border${`${r.d&&r.up?' diagonalUp="1"':""}${r.d&&r.down?' diagonalDown="1"':""}`}>${o("left",r.l)}${o("right",r.r)}${o("top",r.t)}${o("bottom",r.b)}${o("diagonal",r.d)}</border>`}function k(t){const n=[];return t.hAlign&&n.push(`horizontal="${t.hAlign}"`),t.vAlign&&n.push(`vertical="${t.vAlign}"`),t.wrap&&n.push('wrapText="1"'),t.indent&&n.push(`indent="${t.indent}"`),t.rotation&&n.push(`textRotation="${t.rotation}"`),t.shrink&&n.push('shrinkToFit="1"'),t.justifyLastLine&&n.push('justifyLastLine="1"'),t.readingOrder&&n.push(`readingOrder="${t.readingOrder}"`),n.length?`<alignment ${n.join(" ")}/>`:""}const Y=new Map(Object.entries(S).map(([t,n])=>[n,Number(t)]));function Z(t,n,o,r,a){const i=`${t.unlocked?' locked="0"':""}${t.hiddenFormula?' hidden="1"':""}`,m=k(t)+(i?`<protection${i}/>`:""),c=`numFmtId="${a}" fontId="${n}" fillId="${o}" borderId="${r}" xfId="${t._xfId??0}"${t.quotePrefix?' quotePrefix="1"':""}${a?' applyNumberFormat="1"':""} applyFont="1" applyFill="1" applyBorder="1"${k(t)?' applyAlignment="1"':""}${i?' applyProtection="1"':""}`;return m?`<xf ${c}>${m}</xf>`:`<xf ${c}/>`}function A(t,n,o=[]){const r={fonts:[],fills:[],borders:[],numFmts:[],xfs:[]},a=new Map,i=new Map,m=new Map,c=new Map;let p=Math.max(n.maxNumFmt+1,164);for(const{id:e,code:l}of o)c.set(l,e),r.numFmts.push(`<numFmt numFmtId="${e}" formatCode="${T(l)}"/>`),p=Math.max(p,e+1);const d=(e,l,f,u)=>{let F=e.get(f);return F===void 0&&(F=u+l.length,l.push(f),e.set(f,F)),F};for(const e of t){const l=d(a,r.fonts,Q(e),n.fonts),f=e.fill?d(i,r.fills,V(e),n.fills):0,u=e.borders?d(m,r.borders,W(e),n.borders):0;let F=Y.get(e.numFmt);F===void 0&&(F=c.get(e.numFmt),F===void 0&&(F=p++,c.set(e.numFmt,F),r.numFmts.push(`<numFmt numFmtId="${F}" formatCode="${T(e.numFmt)}"/>`))),r.xfs.push(Z(e,l,f,u,F))}return r.fmtIds=c,r}function ut(t,n=[],o=null){const r={fonts:0,fills:2,borders:1,maxNumFmt:163},a=w(t,o?.namedStyles??null),i=A(a.styles,r,o?.pivotNumFmts??[]);o&&(o.writtenNumFmts=[...i.fmtIds]);const m=a.finish(i);return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
- <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">${i.numFmts.length?`<numFmts count="${i.numFmts.length}">${i.numFmts.join("")}</numFmts>`:""}<fonts count="${i.fonts.length}">${i.fonts.join("")}</fonts><fills count="${i.fills.length+2}"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill>${i.fills.join("")}</fills><borders count="${i.borders.length+1}"><border><left/><right/><top/><bottom/><diagonal/></border>${i.borders.join("")}</borders>`+U(m)+`<cellXfs count="${i.xfs.length}">${i.xfs.join("")}</cellXfs>`+O(m)+`${n.length?`<dxfs count="${n.length}">${n.join("")}</dxfs>`:""}</styleSheet>`}function C(t,n,o){if(o.length===0)return t;const a=new RegExp(`<${n}\\b([^>]*?)(/?)>`).exec(t);if(!a)return t;const i=/count="(\d+)"/.exec(a[1]),m=(i?Number(i[1]):0)+o.length,c=i?a[1].replace(/count="\d+"/,`count="${m}"`):`${a[1]} count="${m}"`;if(a[2]==="/")return t.replace(a[0],`<${n}${c}>${o.join("")}</${n}>`);const p=t.indexOf(`</${n}>`);return(t.slice(0,p)+o.join("")+t.slice(p)).replace(a[0],`<${n}${c}>`)}function ct(t,n,o=[],r=null){const a=v(new TextEncoder().encode(t)),i={fonts:h(s(a,"fonts"),"font").length,fills:h(s(a,"fills"),"fill").length,borders:h(s(a,"borders"),"border").length,maxNumFmt:h(s(a,"numFmts"),"numFmt").reduce((e,l)=>Math.max(e,Number(l.a.numFmtId)),163)},m=w(n,r?.namedStyles??null),c=A(m.styles,i,r?.pivotNumFmts??[]);r&&(r.writtenNumFmts=[...c.fmtIds]);const p=m.finish(c);let d=z(t,p);return c.numFmts.length&&!/<numFmts\b/.test(d)&&(d=d.replace(/<fonts\b/,'<numFmts count="0"></numFmts><fonts')),d=C(d,"numFmts",c.numFmts),d=C(d,"fonts",c.fonts),d=C(d,"fills",c.fills),d=C(d,"borders",c.borders),d=C(d,"cellXfs",c.xfs),o.length&&(/<dxfs\b/.test(d)||(d=d.replace(/<\/cellStyles>/,'</cellStyles><dxfs count="0"/>')),d=C(d,"dxfs",o)),d}export{ut as buildStylesXml,ft as parseStyles,st as parseTheme,ct as patchStylesXml,at as resolveColor};
1
+ import{child as f,children as p,parseTree as S}from"./xml-scan.js";import{escapeMarkup as T}from"./xml-escape.js";import{gradientFillXml as j,parseGradientFill as L,underlineFromFile as O,underlineXml as z}from"../cells/style-xml.js";import{BUILTIN_FORMATS as v}from"../core/numfmt.js";import{defaultStyle as U}from"../core/styles.js";import{newCellStyles as D,newStyleSections as P,patchStyleSections as q,tagNamedStyles as B,withNamedStyles as w}from"../cells/cell-styles-xml.js";import{borderRefs as _,colorAttrs as I,fillRefs as G,fontRefs as H,readStyleRefs as J}from"../api/style-refs.js";const K=["000000","FFFFFF","FF0000","00FF00","0000FF","FFFF00","FF00FF","00FFFF","000000","FFFFFF","FF0000","00FF00","0000FF","FFFF00","FF00FF","00FFFF","800000","008000","000080","808000","800080","008080","C0C0C0","808080","9999FF","993366","FFFFCC","CCFFFF","660066","FF8080","0066CC","CCCCFF","000080","FF00FF","FFFF00","00FFFF","800080","800000","008080","0000FF","00CCFF","CCFFFF","CCFFCC","FFFF99","99CCFF","FF99CC","CC99FF","FFCC99","3366FF","33CCCC","99CC00","FFCC00","FF9900","FF6600","666699","969696","003366","339966","003300","333300","993300","993366","333399","333333"],Q=["FFFFFF","000000","E8E8E8","0E2841","156082","E97132","196B24","0F9ED5","A02B93","4EA72E","467886","96607D"];function ct(t){const e=S(t),o=f(e,"themeElements"),r=f(o,"clrScheme");if(!r)return Q;const c=u=>{const F=f(r,u)?.c[0];return(F?.a.lastClr??F?.a.val??"000000").toUpperCase()},l=["lt1","dk1","lt2","dk2","accent1","accent2","accent3","accent4","accent5","accent6","hlink","folHlink"].map(c);return l.themeName=e.a?.name??null,l}function V(t,e){if(!e)return t;const o=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,c=parseInt(t.slice(4,6),16)/255,l=Math.max(o,r,c),u=Math.min(o,r,c);let m=(l+u)/2;const F=l-u,h=F===0?0:F/(1-Math.abs(2*m-1));let n=0;F!==0&&(l===o?n=((r-c)/F+6)%6:l===r?n=(c-o)/F+2:n=(o-r)/F+4),m=e<0?m*(1+e):m*(1-e)+e;const i=(1-Math.abs(2*m-1))*h,s=i*(1-Math.abs(n%2-1)),a=m-i/2,[d,g,y]=n<1?[i,s,0]:n<2?[s,i,0]:n<3?[0,i,s]:n<4?[0,s,i]:n<5?[s,0,i]:[i,0,s],$=N=>Math.round((N+a)*255).toString(16).padStart(2,"0");return($(d)+$(g)+$(y)).toUpperCase()}function dt(t,e){return b(t,e)}function b(t,e){if(!t)return null;const o=t.a;let r=null;if(o.theme!==void 0)r=e[Number(o.theme)]??"000000";else if(o.rgb)r=o.rgb.slice(-6).toUpperCase();else if(o.indexed!==void 0){const c=Number(o.indexed);if(c>=64)return null;r=K[c]}else return null;return"#"+V(r,o.tint?Number(o.tint):0)}function ut(t,e){const o=S(t),r=new Map;for(const n of p(f(o,"numFmts"),"numFmt"))r.set(Number(n.a.numFmtId),n.a.formatCode);const c=p(f(o,"fonts"),"font").map(n=>{const i=d=>f(n,d)?.a.val,s=f(n,"u"),a=d=>{const g=f(n,d);return g!==void 0&&g.a.val!=="0"&&g.a.val!=="false"};return{fontName:i("name")??"Calibri",fontSize:Number(i("sz")??11),bold:a("b"),italic:a("i"),underline:s?O(s.a.val):0,strike:a("strike"),...i("vertAlign")==="superscript"||i("vertAlign")==="subscript"?{vertAlign:i("vertAlign")}:{},color:W(b(f(n,"color"),e))}}),l=p(f(o,"fills"),"fill").map(n=>{const i=f(n,"gradientFill");if(i)return L(i,a=>p(a,"stop").map(d=>({pos:d.a.position,color:f(d,"color")})),a=>b(a,e));const s=f(n,"patternFill");return!s||!s.a.patternType||s.a.patternType==="none"?null:s.a.patternType==="solid"?{fill:b(f(s,"fgColor"),e)??b(f(s,"bgColor"),e)}:{fill:f(s,"bgColor")?.a.indexed==="64"?"#000000":b(f(s,"bgColor"),e)??"#FFFFFF",pattern:{type:s.a.patternType,fg:b(f(s,"fgColor"),e)??"#000000"}}}),u=p(f(o,"borders"),"border").map(n=>{const i=X=>{const x=f(n,X);return!x||!x.a.style||x.a.style==="none"?null:{style:x.a.style,color:b(f(x,"color"),e)??"#000000"}},s=i("left"),a=i("right"),d=i("top"),g=i("bottom"),y=i("diagonal"),$=n.a.diagonalUp==="1"||n.a.diagonalUp==="true",N=n.a.diagonalDown==="1"||n.a.diagonalDown==="true";return y&&($||N)?{l:s,r:a,t:d,b:g,d:y,up:$,down:N}:s||a||d||g?{l:s,r:a,t:d,b:g}:null}),m=n=>b(n,e),F={fonts:p(f(o,"fonts"),"font").map(n=>H(n,f,m)),fills:p(f(o,"fills"),"fill").map(n=>G(n,f,m)),borders:p(f(o,"borders"),"border").map(n=>_(n,f,m))},h=p(f(o,"cellXfs"),"xf").map(n=>{const i=n.a,s=J(F,i),a=f(n,"alignment")?.a??{},d=Number(i.numFmtId??0);return{...U(),...c[Number(i.fontId??0)]??{},fill:l[Number(i.fillId??0)]?.fill??null,...l[Number(i.fillId??0)]?.pattern?{pattern:l[Number(i.fillId??0)].pattern}:{},...l[Number(i.fillId??0)]?.gradient?{gradient:l[Number(i.fillId??0)].gradient}:{},...i.quotePrefix==="1"||i.quotePrefix==="true"?{quotePrefix:!0}:{},borders:u[Number(i.borderId??0)]??null,numFmt:r.get(d)??v[d]??"General",hAlign:a.horizontal&&a.horizontal!=="general"?a.horizontal:null,vAlign:a.vertical??null,wrap:a.wrapText==="1"||a.wrapText==="true",indent:Number(a.indent??0),rotation:Number(a.textRotation??0),shrink:a.shrinkToFit==="1"||a.shrinkToFit==="true",...a.readingOrder==="1"||a.readingOrder==="2"?{readingOrder:Number(a.readingOrder)}:{},...a.justifyLastLine==="1"||a.justifyLastLine==="true"?{justifyLastLine:!0}:{},...f(n,"protection")?.a.locked==="0"?{unlocked:!0}:{},...f(n,"protection")?.a.hidden==="1"?{hiddenFormula:!0}:{},...s?{themeRefs:s}:{}}});return B(h,o)}function W(t){return t==="#000000"?null:t}function Y(t){const e=[];return t.bold&&e.push("<b/>"),t.italic&&e.push("<i/>"),t.strike&&e.push("<strike/>"),t.underline&&e.push(z(t.underline)),t.vertAlign&&e.push(`<vertAlign val="${t.vertAlign}"/>`),e.push(`<sz val="${t.fontSize}"/>`),(t.color||t.themeRefs?.color)&&e.push(`<color ${I(t.themeRefs?.color,t.color)}/>`),e.push(`<name val="${T(t.fontName)}"/>`),t.themeRefs?.font&&e.push(`<scheme val="${t.themeRefs.font}"/>`),`<font>${e.join("")}</font>`}function Z(t){return t.gradient?j(t.gradient):t.pattern?`<fill><patternFill patternType="${t.pattern.type}"><fgColor ${I(t.themeRefs?.patternFg,t.pattern.fg)}/><bgColor ${I(t.themeRefs?.fill,t.fill??"#FFFFFF")}/></patternFill></fill>`:t.fill?`<fill><patternFill patternType="solid"><fgColor ${I(t.themeRefs?.fill,t.fill)}/><bgColor indexed="64"/></patternFill></fill>`:'<fill><patternFill patternType="none"/></fill>'}function tt(t){const e={left:"l",right:"r",top:"t",bottom:"b",diagonal:"d"},o=(l,u)=>u?`<${l} style="${u.style}"><color ${I(t.themeRefs?.border?.[e[l]],u.color)}/></${l}>`:`<${l}/>`,r=t.borders??{};return`<border${`${r.d&&r.up?' diagonalUp="1"':""}${r.d&&r.down?' diagonalDown="1"':""}`}>${o("left",r.l)}${o("right",r.r)}${o("top",r.t)}${o("bottom",r.b)}${o("diagonal",r.d)}</border>`}function A(t){const e=[];return t.hAlign&&e.push(`horizontal="${t.hAlign}"`),t.vAlign&&e.push(`vertical="${t.vAlign}"`),t.wrap&&e.push('wrapText="1"'),t.indent&&e.push(`indent="${t.indent}"`),t.rotation&&e.push(`textRotation="${t.rotation}"`),t.shrink&&e.push('shrinkToFit="1"'),t.justifyLastLine&&e.push('justifyLastLine="1"'),t.readingOrder&&e.push(`readingOrder="${t.readingOrder}"`),e.length?`<alignment ${e.join(" ")}/>`:""}const et=new Map(Object.entries(v).map(([t,e])=>[e,Number(t)]));function nt(t,e,o,r,c){const l=`${t.unlocked?' locked="0"':""}${t.hiddenFormula?' hidden="1"':""}`,u=A(t)+(l?`<protection${l}/>`:""),m=`numFmtId="${c}" fontId="${e}" fillId="${o}" borderId="${r}" xfId="${t._xfId??0}"${t.quotePrefix?' quotePrefix="1"':""}${c?' applyNumberFormat="1"':""} applyFont="1" applyFill="1" applyBorder="1"${A(t)?' applyAlignment="1"':""}${l?' applyProtection="1"':""}`;return u?`<xf ${m}>${u}</xf>`:`<xf ${m}/>`}function E(t,e,o=[]){const r={fonts:[],fills:[],borders:[],numFmts:[],xfs:[]},c=new Map,l=new Map,u=new Map,m=new Map;let F=Math.max(e.maxNumFmt+1,164);for(const{id:n,code:i}of o)m.set(i,n),r.numFmts.push(`<numFmt numFmtId="${n}" formatCode="${T(i)}"/>`),F=Math.max(F,n+1);const h=(n,i,s,a)=>{let d=n.get(s);return d===void 0&&(d=a+i.length,i.push(s),n.set(s,d)),d};for(const n of t){const i=h(c,r.fonts,Y(n),e.fonts),s=n.fill?h(l,r.fills,Z(n),e.fills):0,a=n.borders?h(u,r.borders,tt(n),e.borders):0;let d=et.get(n.numFmt);d===void 0&&(d=m.get(n.numFmt),d===void 0&&(d=F++,m.set(n.numFmt,d),r.numFmts.push(`<numFmt numFmtId="${d}" formatCode="${T(n.numFmt)}"/>`))),r.xfs.push(nt(n,i,s,a,d))}return r.fmtIds=m,r}function mt(t,e=[],o=null){const r={fonts:0,fills:2,borders:1,maxNumFmt:163},c=w(t,o?.namedStyles??null),l=E(c.styles,r,o?.pivotNumFmts??[]);o&&(o.writtenNumFmts=[...l.fmtIds]);const u=c.finish(l);return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">${l.numFmts.length?`<numFmts count="${l.numFmts.length}">${l.numFmts.join("")}</numFmts>`:""}<fonts count="${l.fonts.length}">${l.fonts.join("")}</fonts><fills count="${l.fills.length+2}"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill>${l.fills.join("")}</fills><borders count="${l.borders.length+1}"><border><left/><right/><top/><bottom/><diagonal/></border>${l.borders.join("")}</borders>`+P(u)+`<cellXfs count="${l.xfs.length}">${l.xfs.join("")}</cellXfs>`+D(u)+`${e.length?`<dxfs count="${e.length}">${e.join("")}</dxfs>`:""}</styleSheet>`}const M=["numFmts","fonts","fills","borders","cellStyleXfs","cellXfs","cellStyles","dxfs","tableStyles","colors","extLst"],R={fonts:['<font><sz val="12"/><name val="Aptos Narrow"/></font>'],fills:['<fill><patternFill patternType="none"/></fill>','<fill><patternFill patternType="gray125"/></fill>'],borders:["<border><left/><right/><top/><bottom/><diagonal/></border>"]};function k(t,e){let o=t.replace(/<styleSheet\b([^>]*?)\/>/,(r,c)=>`<styleSheet${c}></styleSheet>`);for(const r of e){const c=R[r]??[],l=`<${r} count="${c.length}">${c.join("")}</${r}>`,u=new RegExp(`<${r}\\b[^>]*?(?:/>|>\\s*</${r}>)`).exec(o);if(u)o=o.slice(0,u.index)+l+o.slice(u.index+u[0].length);else if(!new RegExp(`<${r}\\b`).test(o)){const m=o.search(new RegExp(`<(?:${M.slice(M.indexOf(r)+1).join("|")})\\b|</styleSheet>`));o=o.slice(0,m)+l+o.slice(m)}}return o}function C(t,e,o){if(o.length===0)return t;const c=new RegExp(`<${e}\\b([^>]*?)(/?)>`).exec(t);if(!c)return t;const l=c[1].replace(/count="(\d+)"/,(F,h)=>`count="${Number(h)+o.length}"`);if(c[2]==="/")return t.replace(c[0],()=>`<${e}${l}>${o.join("")}</${e}>`);const u=t.indexOf(`</${e}>`);return(t.slice(0,u)+o.join("")+t.slice(u)).replace(c[0],()=>`<${e}${l}>`)}function Ft(t,e,o=[],r=null){const c=k(t,e.length?["fonts","fills","borders","cellXfs"]:[]),l=S(new TextEncoder().encode(c)),u={fonts:p(f(l,"fonts"),"font").length,fills:p(f(l,"fills"),"fill").length,borders:p(f(l,"borders"),"border").length,maxNumFmt:p(f(l,"numFmts"),"numFmt").reduce((a,d)=>Math.max(a,Number(d.a.numFmtId)),163)},m=["cellStyleXfs","cellXfs"].flatMap(a=>p(f(l,a),"xf")),F={};for(const[a,d]of[["fonts","fontId"],["fills","fillId"],["borders","borderId"]]){const g=m.reduce((y,$)=>Math.max(y,Number($.a[d]??0)),0)+1;F[a]=e.length?Array.from({length:Math.max(0,Math.min(g-u[a],1024))},()=>R[a][0]):[],u[a]+=F[a].length}const h=w(e,r?.namedStyles??null),n=E(h.styles,u,r?.pivotNumFmts??[]);r&&(r.writtenNumFmts=[...n.fmtIds]);const i=h.finish(n);let s=q(c,i);return s=k(s,[...n.numFmts.length?["numFmts"]:[],...o.length?["dxfs"]:[]]),s=C(s,"numFmts",n.numFmts),s=C(s,"fonts",[...F.fonts,...n.fonts]),s=C(s,"fills",[...F.fills,...n.fills]),s=C(s,"borders",[...F.borders,...n.borders]),s=C(s,"cellXfs",n.xfs),C(s,"dxfs",o)}export{mt as buildStylesXml,ut as parseStyles,ct as parseTheme,Ft as patchStylesXml,dt as resolveColor};
package/io/xlsx-tail.js CHANGED
@@ -1 +1 @@
1
- import{child as n,children as f,parseTree as y,unescapeOoxml as c}from"./xml-scan.js";import{escapeMarkup as h,xmlAttr as d}from"./xml-escape.js";import{cfvoXml as x,colorAttrs as S,dxfToXml as k,extendRule as v,maskCfBlocks as V,parseDxfList as D}from"../cells/cf-file.js";const T=new TextEncoder,p=e=>e==="1"||e==="true";function P(e){const o=e.replace(/<\/(?:\w+:)?worksheet>\s*$/,"");return y(T.encode(`<root xmlns:r="r" xmlns:x14="x" xmlns:mc="m" xmlns:xm="m" xmlns:xr="x">${o}</root>`))}function A(e){if(!e?.length)return"";const o=t=>String(t).replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;");return`<ignoredErrors>${e.map(t=>`<ignoredError${Object.entries(t).map(([r,i])=>` ${r}="${o(i===!0?"1":i)}"`).join("")}/>`).join("")}</ignoredErrors>`}function F(e){const o={cf:[],validations:[],hyperlinks:[],protection:null};if(!e)return o;let t;try{t=P(e)}catch{return o}for(const a of f(t,"conditionalFormatting")){const u=f(a,"cfRule").map(g=>v(E(g),g));o.cf.push({sqref:a.a.sqref??"",rules:u,...p(a.a.pivot)?{pivot:!0}:{}})}const r=n(t,"dataValidations");for(const a of f(r,"dataValidation"))o.validations.push({sqref:a.a.sqref??"",type:a.a.type??"none",operator:a.a.operator??"between",formula1:n(a,"formula1")?.t??"",formula2:n(a,"formula2")?.t??"",allowBlank:p(a.a.allowBlank),showDropDown:!p(a.a.showDropDown),showError:p(a.a.showErrorMessage),showPrompt:p(a.a.showInputMessage),errorStyle:a.a.errorStyle??"stop",errorTitle:c(a.a.errorTitle??""),error:c(a.a.error??""),promptTitle:c(a.a.promptTitle??""),prompt:c(a.a.prompt??"")});for(const a of f(n(t,"hyperlinks"),"hyperlink"))o.hyperlinks.push({ref:a.a.ref,rid:a.a.id??null,location:a.a.location??null,display:c(a.a.display??null),tooltip:c(a.a.tooltip??null)});const i=n(t,"sheetProtection");i&&(o.protection={...i.a});const l=f(n(t,"customSheetViews"),"customSheetView");l.length&&(o.customSheetViews=l.map(a=>{const u=n(a,"pane"),g=n(a,"selection");return{...a.a,xSplit:u?.a.state==="frozen"?u.a.xSplit:void 0,ySplit:u?.a.state==="frozen"?u.a.ySplit:void 0,activeCell:g?.a.activeCell,sqref:g?.a.sqref}}));const s=n(t,"picture");s&&(o.pictureRid=s.a["r:id"]??s.a.id??null);const m=n(t,"legacyDrawingHF");m&&(o.headerPictureRid=m.a["r:id"]??m.a.id??null);const $=f(n(t,"ignoredErrors"),"ignoredError");$.length&&(o.ignoredErrors=$.map(a=>({...a.a})));const w=n(t,"scenarios");return w&&(o.scenarios={current:Number(w.a.current??0),show:Number(w.a.show??0),items:f(w,"scenario").map(a=>({name:c(a.a.name),user:c(a.a.user??""),comment:c(a.a.comment??""),locked:a.a.locked==="1",hidden:a.a.hidden==="1",cells:f(a,"inputCells").map(u=>({r:u.a.r,val:c(u.a.val??"")}))}))}),o}function E(e){const o=e.a,t={type:o.type,priority:Number(o.priority??0),dxfId:o.dxfId!==void 0?Number(o.dxfId):null,operator:o.operator??null,formulas:f(e,"formula").map(m=>m.t),text:c(o.text??null),rank:o.rank!==void 0?Number(o.rank):null,percent:p(o.percent),bottom:p(o.bottom),aboveAverage:o.aboveAverage===void 0?!0:p(o.aboveAverage),equalAverage:p(o.equalAverage),stdDev:o.stdDev!==void 0?Number(o.stdDev):0,stopIfTrue:p(o.stopIfTrue),timePeriod:o.timePeriod??null},r=m=>f(m,"cfvo").map($=>({type:$.a.type,val:$.a.val??null,gte:$.a.gte===void 0?!0:p($.a.gte)})),i=n(e,"colorScale");i&&(t.colorScale={cfvo:r(i),colors:f(i,"color").map(m=>m.a)});const l=n(e,"dataBar");l&&(t.dataBar={cfvo:r(l),color:n(l,"color")?.a??null,showValue:l.a.showValue===void 0?!0:p(l.a.showValue)});const s=n(e,"iconSet");return s&&(t.iconSet={name:s.a.iconSet??"3TrafficLights1",cfvo:r(s),reverse:p(s.a.reverse),showValue:s.a.showValue===void 0?!0:p(s.a.showValue)}),t}function j(e){let o=`type="${e.type}" priority="${e.priority}"`;e.dxfId!==null&&e.dxfId!==void 0&&(o+=` dxfId="${e.dxfId}"`),e.stopIfTrue&&(o+=' stopIfTrue="1"'),e.operator&&(o+=` operator="${e.operator}"`),e.text!==null&&e.text!==void 0&&(o+=` text="${d(e.text)}"`),e.rank!==null&&e.rank!==void 0&&(o+=` rank="${e.rank}"`),e.percent&&(o+=' percent="1"'),e.bottom&&(o+=' bottom="1"'),e.type==="aboveAverage"&&(e.aboveAverage===!1&&(o+=' aboveAverage="0"'),e.equalAverage&&(o+=' equalAverage="1"'),e.stdDev&&(o+=` stdDev="${e.stdDev}"`)),e.timePeriod&&(o+=` timePeriod="${e.timePeriod}"`);let t=(e.formulas??[]).map(r=>`<formula>${h(r)}</formula>`).join("");return e.colorScale&&(t+=`<colorScale>${x(e.colorScale.cfvo)}${e.colorScale.colors.map(r=>`<color ${S(r)}/>`).join("")}</colorScale>`),e.dataBar&&(t+=`<dataBar${e.dataBar.showValue?"":' showValue="0"'}>${x(e.dataBar.cfvo)}<color ${S(e.dataBar.color)}/></dataBar>`),e.iconSet&&(t+=`<iconSet iconSet="${e.iconSet.name}"${e.iconSet.reverse?' reverse="1"':""}${e.iconSet.showValue?"":' showValue="0"'}>${x(e.iconSet.cfvo)}</iconSet>`),`<cfRule ${o}>${t}</cfRule>`}const X=e=>e.map(o=>`<conditionalFormatting${o.pivot?' pivot="1"':""} sqref="${h(o.sqref)}">${o.rules.map(j).join("")}</conditionalFormatting>`).join("");function C(e){if(e.length===0)return"";const o=e.map(t=>{let r=`type="${t.type}"`;return t.errorStyle&&t.errorStyle!=="stop"&&(r+=` errorStyle="${t.errorStyle}"`),t.operator&&t.operator!=="between"&&(r+=` operator="${t.operator}"`),t.allowBlank&&(r+=' allowBlank="1"'),t.showDropDown===!1&&(r+=' showDropDown="1"'),t.showPrompt&&(r+=' showInputMessage="1"'),t.showError&&(r+=' showErrorMessage="1"'),t.errorTitle&&(r+=` errorTitle="${d(t.errorTitle)}"`),t.error&&(r+=` error="${d(t.error)}"`),t.promptTitle&&(r+=` promptTitle="${d(t.promptTitle)}"`),t.prompt&&(r+=` prompt="${d(t.prompt)}"`),r+=` sqref="${h(t.sqref)}"`,`<dataValidation ${r}>${t.formula1?`<formula1>${h(t.formula1)}</formula1>`:""}${t.formula2?`<formula2>${h(t.formula2)}</formula2>`:""}</dataValidation>`});return`<dataValidations count="${e.length}">${o.join("")}</dataValidations>`}const N=e=>e.length===0?"":`<hyperlinks>${e.map(o=>{let t=`ref="${h(o.ref)}"`;return o.rid&&(t+=` r:id="${h(o.rid)}"`),o.location&&(t+=` location="${h(o.location)}"`),o.display&&(t+=` display="${d(o.display)}"`),o.tooltip&&(t+=` tooltip="${d(o.tooltip)}"`),`<hyperlink ${t}/>`}).join("")}</hyperlinks>`;function O(e){if(!e||e.items.length===0)return"";const o=e.items.map(t=>`<scenario name="${d(t.name)}"${t.locked?' locked="1"':""}${t.hidden?' hidden="1"':""} count="${t.cells.length}" user="${d(t.user||"User")}"${t.comment?` comment="${d(t.comment)}"`:""}>${t.cells.map(r=>`<inputCells r="${r.r}" val="${d(r.val)}"/>`).join("")}</scenario>`).join("");return`<scenarios current="${e.current??0}" show="${e.show??0}">${o}</scenarios>`}function M(e){return e?`<sheetProtection ${Object.entries(e).map(([o,t])=>`${o}="${h(t)}"`).join(" ")}/>`:""}const b=["sheetCalcPr","sheetProtection","protectedRanges","scenarios","autoFilter","sortState","dataConsolidate","customSheetViews","mergeCells","phoneticPr","conditionalFormatting","dataValidations","hyperlinks","printOptions","pageMargins","pageSetup","headerFooter","rowBreaks","colBreaks","customProperties","cellWatches","ignoredErrors","smartTags","drawing","legacyDrawing","legacyDrawingHF","drawingHF","picture","oleObjects","controls","webPublishItems","tableParts","extLst"];function z(e,o,t){const r=new RegExp(`<${o}\\b[^>]*?(?:/>|>[\\s\\S]*?</${o}>)`,"g");let i=e.replace(r,"");if(!t)return i;const l=b.slice(b.indexOf(o)+1).join("|"),s=new RegExp(`<(?:${l})\\b|</worksheet>`).exec(V(i)),m=s?s.index:i.length;return i=i.slice(0,m)+t+i.slice(m),i}function q(e){const o=n(n(e,"r"),"rPr");if(!o)return{};const t={},r=n(o,"sz")?.a.val;r&&r!=="9"&&r!=="10"&&(t.fontSize=Number(r));const i=n(o,"rFont")?.a.val;i&&i!=="Tahoma"&&(t.fontName=i);const l=n(o,"color")?.a.rgb;return l&&(t.color=`#${l.slice(-6)}`),Object.keys(t).length?{style:t}:{}}function L(e){const o=y(e),t=f(n(o,"authors"),"author").map(r=>c(r.t));return f(n(o,"commentList"),"comment").map(r=>{const i=n(r,"text");let l="";for(const s of i.c)s.n==="t"?l+=c(s.t):s.n==="r"&&(l+=c(n(s,"t")?.t??""));return{ref:r.a.ref,author:t[Number(r.a.authorId??0)]??"",text:l,...q(i)}})}const H=(e,o)=>D(y(e),o),U=e=>e.raw??k(e);export{X as cfXml,U as dxfXml,N as hyperlinksXml,A as ignoredErrorsXml,L as parseComments,H as parseDxfs,F as parseSheetFeatures,M as protectionXml,z as replaceElement,j as ruleXml,O as scenariosXml,C as validationsXml};
1
+ import{child as s,children as c,parseTree as y,unescapeOoxml as f}from"./xml-scan.js";import{escapeMarkup as u,xmlAttr as h}from"./xml-escape.js";import{appendSheetExt as E,cfvoXml as S,colorAttrs as V,dxfToXml as T,extendRule as R,maskCfBlocks as v,parseDxfList as A}from"../cells/cf-file.js";const q=new TextEncoder,m=e=>e==="1"||e==="true";function B(e){const t=e.replace(/<\/(?:\w+:)?worksheet>\s*$/,"");return y(q.encode(`<root xmlns:r="r" xmlns:x14="x" xmlns:mc="m" xmlns:xm="m" xmlns:xr="x">${t}</root>`))}function L(e){return e?.length?`<protectedRanges>${e.map(({securityDescriptor:t,...o})=>{const n=Array.isArray(t)?t:[],a=Object.entries(typeof t=="string"?{...o,securityDescriptor:t}:o).map(([i,l])=>` ${i}="${h(String(l))}"`).join("");return n.length?`<protectedRange${a}>${n.map(i=>`<securityDescriptor>${u(i)}</securityDescriptor>`).join("")}</protectedRange>`:`<protectedRange${a}/>`}).join("")}</protectedRanges>`:""}function z(e){if(!e?.length)return"";const t=o=>String(o).replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;");return`<ignoredErrors>${e.map(o=>`<ignoredError${Object.entries(o).map(([n,a])=>` ${n}="${t(a===!0?"1":a)}"`).join("")}/>`).join("")}</ignoredErrors>`}function H(e){const t={cf:[],validations:[],hyperlinks:[],protection:null};if(!e)return t;let o;try{o=B(e)}catch{return t}for(const r of c(o,"conditionalFormatting")){const p=c(r,"cfRule").map($=>R(P($),$));t.cf.push({sqref:r.a.sqref??"",rules:p,...m(r.a.pivot)?{pivot:!0}:{}})}const n=c(s(o,"extLst"),"ext").flatMap(r=>c(s(r,"dataValidations"),"dataValidation")),a=(r,p)=>{const $=s(r,p);return(s($,"f")??$)?.t??""};for(const r of[...c(s(o,"dataValidations"),"dataValidation"),...n])t.validations.push({...n.includes(r)?{ext:!0}:{},...r.a.imeMode?{imeMode:r.a.imeMode}:{},sqref:r.a.sqref??s(r,"sqref")?.t??"",type:r.a.type??"none",operator:r.a.operator??"between",formula1:a(r,"formula1"),formula2:a(r,"formula2"),allowBlank:m(r.a.allowBlank),showDropDown:!m(r.a.showDropDown),showError:m(r.a.showErrorMessage),showPrompt:m(r.a.showInputMessage),errorStyle:r.a.errorStyle??"stop",errorTitle:f(r.a.errorTitle??""),error:f(r.a.error??""),promptTitle:f(r.a.promptTitle??""),prompt:f(r.a.prompt??"")});for(const r of c(s(o,"hyperlinks"),"hyperlink"))t.hyperlinks.push({ref:r.a.ref,rid:r.a.id??null,location:r.a.location??null,display:f(r.a.display??null),tooltip:f(r.a.tooltip??null)});const i=s(o,"sheetProtection");i&&(t.protection={...i.a});const l=c(s(o,"protectedRanges"),"protectedRange");l.length&&(t.protectedRanges=l.map(r=>{const p=c(r,"securityDescriptor").map($=>$.t);return{...r.a,...p.length?{securityDescriptor:p}:{}}}));const d=c(s(o,"customSheetViews"),"customSheetView");d.length&&(t.customSheetViews=d.map(r=>{const p=s(r,"pane"),$=s(r,"selection");return{...r.a,xSplit:p?.a.state==="frozen"?p.a.xSplit:void 0,ySplit:p?.a.state==="frozen"?p.a.ySplit:void 0,activeCell:$?.a.activeCell,sqref:$?.a.sqref}}));const g=s(o,"picture");g&&(t.pictureRid=g.a["r:id"]??g.a.id??null);const w=s(o,"legacyDrawingHF");w&&(t.headerPictureRid=w.a["r:id"]??w.a.id??null);const b=c(s(o,"ignoredErrors"),"ignoredError");b.length&&(t.ignoredErrors=b.map(r=>({...r.a})));const x=s(o,"scenarios");return x&&(t.scenarios={current:Number(x.a.current??0),show:Number(x.a.show??0),items:c(x,"scenario").map(r=>({name:f(r.a.name),user:f(r.a.user??""),comment:f(r.a.comment??""),locked:r.a.locked==="1",hidden:r.a.hidden==="1",cells:c(r,"inputCells").map(p=>({r:p.a.r,val:f(p.a.val??"")}))}))}),t}function P(e){const t=e.a,o={type:t.type,priority:Number(t.priority??0),dxfId:t.dxfId!==void 0?Number(t.dxfId):null,operator:t.operator??null,formulas:c(e,"formula").map(d=>d.t),text:f(t.text??null),rank:t.rank!==void 0?Number(t.rank):null,percent:m(t.percent),bottom:m(t.bottom),aboveAverage:t.aboveAverage===void 0?!0:m(t.aboveAverage),equalAverage:m(t.equalAverage),stdDev:t.stdDev!==void 0?Number(t.stdDev):0,stopIfTrue:m(t.stopIfTrue),timePeriod:t.timePeriod??null},n=d=>c(d,"cfvo").map(g=>({type:g.a.type,val:g.a.val??null,gte:g.a.gte===void 0?!0:m(g.a.gte)})),a=s(e,"colorScale");a&&(o.colorScale={cfvo:n(a),colors:c(a,"color").map(d=>d.a)});const i=s(e,"dataBar");i&&(o.dataBar={cfvo:n(i),color:s(i,"color")?.a??null,showValue:i.a.showValue===void 0?!0:m(i.a.showValue)});const l=s(e,"iconSet");return l&&(o.iconSet={name:l.a.iconSet??"3TrafficLights1",cfvo:n(l),reverse:m(l.a.reverse),showValue:l.a.showValue===void 0?!0:m(l.a.showValue)}),o}function C(e){let t=`type="${e.type}" priority="${e.priority}"`;e.dxfId!==null&&e.dxfId!==void 0&&(t+=` dxfId="${e.dxfId}"`),e.stopIfTrue&&(t+=' stopIfTrue="1"'),e.operator&&(t+=` operator="${e.operator}"`),e.text!==null&&e.text!==void 0&&(t+=` text="${h(e.text)}"`),e.rank!==null&&e.rank!==void 0&&(t+=` rank="${e.rank}"`),e.percent&&(t+=' percent="1"'),e.bottom&&(t+=' bottom="1"'),e.type==="aboveAverage"&&(e.aboveAverage===!1&&(t+=' aboveAverage="0"'),e.equalAverage&&(t+=' equalAverage="1"'),e.stdDev&&(t+=` stdDev="${e.stdDev}"`)),e.timePeriod&&(t+=` timePeriod="${e.timePeriod}"`);let o=(e.formulas??[]).map(n=>`<formula>${u(n)}</formula>`).join("");return e.colorScale&&(o+=`<colorScale>${S(e.colorScale.cfvo)}${e.colorScale.colors.map(n=>`<color ${V(n)}/>`).join("")}</colorScale>`),e.dataBar&&(o+=`<dataBar${e.dataBar.showValue?"":' showValue="0"'}>${S(e.dataBar.cfvo)}<color ${V(e.dataBar.color)}/></dataBar>`),e.iconSet&&(o+=`<iconSet iconSet="${e.iconSet.name}"${e.iconSet.reverse?' reverse="1"':""}${e.iconSet.showValue?"":' showValue="0"'}>${S(e.iconSet.cfvo)}</iconSet>`),`<cfRule ${t}>${o}</cfRule>`}const U=e=>e.map(t=>`<conditionalFormatting${t.pivot?' pivot="1"':""} sqref="${u(t.sqref)}">${t.rules.map(C).join("")}</conditionalFormatting>`).join("");function k(e,t){let o=`type="${e.type}"`;if(e.errorStyle&&e.errorStyle!=="stop"&&(o+=` errorStyle="${e.errorStyle}"`),e.imeMode&&(o+=` imeMode="${u(e.imeMode)}"`),e.operator&&e.operator!=="between"&&(o+=` operator="${e.operator}"`),e.allowBlank&&(o+=' allowBlank="1"'),e.showDropDown===!1&&(o+=' showDropDown="1"'),e.showPrompt&&(o+=' showInputMessage="1"'),e.showError&&(o+=' showErrorMessage="1"'),e.errorTitle&&(o+=` errorTitle="${h(e.errorTitle)}"`),e.error&&(o+=` error="${h(e.error)}"`),e.promptTitle&&(o+=` promptTitle="${h(e.promptTitle)}"`),e.prompt&&(o+=` prompt="${h(e.prompt)}"`),t){const n=(a,i)=>i?`<x14:${a}><xm:f>${u(i)}</xm:f></x14:${a}>`:"";return`<x14:dataValidation ${o}>${n("formula1",e.formula1)}${n("formula2",e.formula2)}<xm:sqref>${u(e.sqref)}</xm:sqref></x14:dataValidation>`}return o+=` sqref="${u(e.sqref)}"`,`<dataValidation ${o}>${e.formula1?`<formula1>${u(e.formula1)}</formula1>`:""}${e.formula2?`<formula2>${u(e.formula2)}</formula2>`:""}</dataValidation>`}const I="{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}";function _(e,t){const o=t.filter(i=>!i.ext),n=t.filter(i=>i.ext),a=j(e,"dataValidations",o.length?`<dataValidations count="${o.length}">${o.map(i=>k(i,!1)).join("")}</dataValidations>`:"").replace(/<ext\b[^>]*>\s*<([\w.-]+:)?dataValidations\b[\s\S]*?<\/\1dataValidations>\s*<\/ext>/,"");return E(a,n.length?`<ext xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" uri="${I}"><x14:dataValidations xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main" count="${n.length}">${n.map(i=>k(i,!0)).join("")}</x14:dataValidations></ext>`:"")}const W=e=>e.length===0?"":`<hyperlinks>${e.map(t=>{let o=`ref="${u(t.ref)}"`;return t.rid&&(o+=` r:id="${u(t.rid)}"`),t.location&&(o+=` location="${u(t.location)}"`),t.display&&(o+=` display="${h(t.display)}"`),t.tooltip&&(o+=` tooltip="${h(t.tooltip)}"`),`<hyperlink ${o}/>`}).join("")}</hyperlinks>`;function G(e){if(!e||e.items.length===0)return"";const t=e.items.map(o=>`<scenario name="${h(o.name)}"${o.locked?' locked="1"':""}${o.hidden?' hidden="1"':""} count="${o.cells.length}" user="${h(o.user||"User")}"${o.comment?` comment="${h(o.comment)}"`:""}>${o.cells.map(n=>`<inputCells r="${n.r}" val="${h(n.val)}"/>`).join("")}</scenario>`).join("");return`<scenarios current="${e.current??0}" show="${e.show??0}">${t}</scenarios>`}function J(e){return e?`<sheetProtection ${Object.entries(e).map(([t,o])=>`${t}="${u(o)}"`).join(" ")}/>`:""}const D=["sheetCalcPr","sheetProtection","protectedRanges","scenarios","autoFilter","sortState","dataConsolidate","customSheetViews","mergeCells","phoneticPr","conditionalFormatting","dataValidations","hyperlinks","printOptions","pageMargins","pageSetup","headerFooter","rowBreaks","colBreaks","customProperties","cellWatches","ignoredErrors","smartTags","drawing","legacyDrawing","legacyDrawingHF","drawingHF","picture","oleObjects","controls","webPublishItems","tableParts","extLst"];function M(e){const t=D.slice(D.indexOf(e)+1);return t.includes("oleObjects")&&t.push("mc:AlternateContent"),new RegExp(`<(?:${t.join("|")})\\b|</worksheet>`)}function K(e){const t=/<customSheetViews\b[^>]*>[\s\S]*?<\/customSheetViews>/.exec(e??"");return t?{rest:e.slice(0,t.index)+e.slice(t.index+t[0].length),views:t[0]}:{rest:e??"",views:""}}const Q=(e,t)=>t?j(e,"customSheetViews",t):e;function j(e,t,o){const n=new RegExp(`<${t}\\b[^>]*?(?:/>|>[\\s\\S]*?</${t}>)`,"g");let a=e.replace(n,"");if(!o)return a;const i=M(t).exec(v(a)),l=i?i.index:a.length;return a=a.slice(0,l)+o+a.slice(l),a}function F(e,t){const o=s(s(e,"r"),"rPr");if(!o)return{};const n={},a=s(o,"sz")?.a.val;a&&a!=="9"&&a!=="10"&&(n.fontSize=Number(a));const i=s(o,"rFont")?.a.val;i&&i!=="Tahoma"&&(n.fontName=i);const l=s(o,"color");return l?.a.rgb&&(n.color=t?t(l):`#${l.a.rgb.slice(-6)}`),Object.keys(n).length?{style:n}:{}}function Y(e,t){const o=y(e),n=c(s(o,"authors"),"author").map(a=>f(a.t));return c(s(o,"commentList"),"comment").map(a=>{const i=s(a,"text");let l="";for(const d of i.c)d.n==="t"?l+=f(d.t):d.n==="r"&&(l+=f(s(d,"t")?.t??""));return{ref:a.a.ref,author:n[Number(a.a.authorId??0)]??"",text:l,...F(i,t)}})}const Z=(e,t)=>A(y(e),t),ee=e=>e.raw??T(e);export{D as TAIL_ELEMENTS,U as cfXml,ee as dxfXml,W as hyperlinksXml,z as ignoredErrorsXml,Y as parseComments,Z as parseDxfs,H as parseSheetFeatures,_ as patchValidations,L as protectedRangesXml,J as protectionXml,j as replaceElement,C as ruleXml,G as scenariosXml,K as splitCustomViews,Q as withCustomViews};