@8sheets/data-grid 1.1.2 → 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 (226) 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/cells/axis-ops.js +1 -1
  28. package/cells/cell-styles-xml.js +1 -1
  29. package/cells/cf-engine.js +1 -1
  30. package/cells/cf-file.js +1 -1
  31. package/cells/docprops-xml.js +2 -2
  32. package/cells/filter-eval.js +1 -0
  33. package/cells/filter-file.js +1 -1
  34. package/cells/find-engine.js +1 -1
  35. package/cells/goto.js +1 -1
  36. package/cells/name-box.js +1 -1
  37. package/cells/note-box.js +3 -0
  38. package/cells/options.js +1 -1
  39. package/cells/outline-column.js +1 -1
  40. package/cells/protected-menu.js +1 -0
  41. package/cells/rich-data-xml.js +1 -1
  42. package/cells/sheet-views-file.js +2 -0
  43. package/cells/shift-check.js +1 -1
  44. package/cells/sort-compare.js +1 -0
  45. package/cells/ui-kit.js +1 -1
  46. package/cells/undo-group.js +1 -1
  47. package/celltypes/dropdowns.js +2 -2
  48. package/core/address.js +1 -1
  49. package/core/autofill.js +1 -1
  50. package/core/axis.js +1 -1
  51. package/core/cond-format.js +1 -1
  52. package/core/culture.js +5 -1
  53. package/core/custom-views.js +1 -1
  54. package/core/data-tools.js +1 -0
  55. package/core/date-codes.js +1 -0
  56. package/core/default-names.js +1 -1
  57. package/core/formula-refs.js +1 -1
  58. package/core/input.js +1 -1
  59. package/core/numfmt.js +1 -1
  60. package/core/precision.js +1 -0
  61. package/core/region-input.js +1 -1
  62. package/core/rule-refs.js +1 -0
  63. package/core/shared-view.js +1 -0
  64. package/core/sheet.js +1 -1
  65. package/core/sparklines.js +1 -1
  66. package/core/sparse.js +1 -1
  67. package/core/spills.js +1 -0
  68. package/core/strings.js +1 -1
  69. package/core/structure.js +1 -1
  70. package/core/table-columns.js +1 -0
  71. package/core/tables.js +2 -2
  72. package/core/validation-ranges.js +1 -1
  73. package/core/whatif.js +1 -1
  74. package/core/workbook.js +1 -1
  75. package/datasheets/formula.js +1 -1
  76. package/datasheets/path-binding.js +1 -1
  77. package/datasheets/persist-writer.js +1 -1
  78. package/datasheets/report.js +1 -1
  79. package/extras/getdata/persist.js +2 -2
  80. package/extras/getdata/rows.js +1 -1
  81. package/extras/getdata/shared-steps.js +1 -0
  82. package/extras/getdata/steps-formula.js +1 -0
  83. package/extras/getdata/steps-more.js +1 -0
  84. package/extras/getdata/steps-tables.js +1 -0
  85. package/extras/getdata/steps.js +1 -1
  86. package/i18n/de/a11y.js +1 -0
  87. package/i18n/de/cells.js +2 -0
  88. package/i18n/de/charts.js +1 -0
  89. package/i18n/de/common.js +1 -0
  90. package/i18n/de/datasheets.js +1 -0
  91. package/i18n/de/format.js +1 -0
  92. package/i18n/de/misc.js +1 -0
  93. package/i18n/de/pivot.js +1 -0
  94. package/i18n/de/proofing.js +1 -0
  95. package/i18n/de/ribbon.js +1 -0
  96. package/i18n/de/shapes.js +1 -0
  97. package/i18n/de/shell.js +3 -0
  98. package/i18n/de/touch.js +1 -0
  99. package/i18n/de.js +1 -0
  100. package/i18n/en/cells.js +2 -1
  101. package/i18n/en/charts.js +1 -1
  102. package/i18n/en/format.js +1 -1
  103. package/i18n/en/misc.js +1 -1
  104. package/i18n/en/pivot.js +1 -1
  105. package/i18n/en/proofing.js +1 -1
  106. package/i18n/en/ribbon.js +1 -1
  107. package/i18n/en/shapes.js +1 -1
  108. package/i18n/en/shell.js +3 -2
  109. package/i18n/en/touch.js +1 -1
  110. package/i18n/es/a11y.js +1 -0
  111. package/i18n/es/cells.js +2 -0
  112. package/i18n/es/charts.js +1 -0
  113. package/i18n/es/common.js +1 -0
  114. package/i18n/es/datasheets.js +1 -0
  115. package/i18n/es/format.js +1 -0
  116. package/i18n/es/misc.js +1 -0
  117. package/i18n/es/pivot.js +1 -0
  118. package/i18n/es/proofing.js +1 -0
  119. package/i18n/es/ribbon.js +1 -0
  120. package/i18n/es/shapes.js +1 -0
  121. package/i18n/es/shell.js +3 -0
  122. package/i18n/es/touch.js +1 -0
  123. package/i18n/es.js +1 -0
  124. package/i18n/fr/a11y.js +1 -0
  125. package/i18n/fr/cells.js +2 -0
  126. package/i18n/fr/charts.js +1 -0
  127. package/i18n/fr/common.js +1 -0
  128. package/i18n/fr/datasheets.js +1 -0
  129. package/i18n/fr/format.js +1 -0
  130. package/i18n/fr/misc.js +1 -0
  131. package/i18n/fr/pivot.js +1 -0
  132. package/i18n/fr/proofing.js +1 -0
  133. package/i18n/fr/ribbon.js +1 -0
  134. package/i18n/fr/shapes.js +1 -0
  135. package/i18n/fr/shell.js +3 -0
  136. package/i18n/fr/touch.js +1 -0
  137. package/i18n/fr.js +1 -0
  138. package/i18n/index.js +1 -1
  139. package/i18n/languages.js +1 -1
  140. package/i18n/pl/cells.js +2 -1
  141. package/i18n/pl/charts.js +1 -1
  142. package/i18n/pl/format.js +1 -1
  143. package/i18n/pl/misc.js +1 -1
  144. package/i18n/pl/pivot.js +1 -1
  145. package/i18n/pl/proofing.js +1 -1
  146. package/i18n/pl/ribbon.js +1 -1
  147. package/i18n/pl/shapes.js +1 -1
  148. package/i18n/pl/shell.js +3 -2
  149. package/i18n/pl/touch.js +1 -1
  150. package/io/blob-sink.js +1 -0
  151. package/io/canonical-xml.js +1 -0
  152. package/io/client.js +1 -1
  153. package/io/crypto/cfb-build.js +1 -0
  154. package/io/crypto/cfb-read.js +1 -1
  155. package/io/crypto/cfb-write.js +1 -1
  156. package/io/crypto/errors.js +1 -1
  157. package/io/csv.js +8 -8
  158. package/io/foreign-sheets.js +2 -2
  159. package/io/io.worker.js +1 -1
  160. package/io/open-package.js +1 -0
  161. package/io/package-paths.js +1 -1
  162. package/io/plan.js +1 -1
  163. package/io/text-split.js +3 -3
  164. package/io/xls/chart-sheet.js +1 -0
  165. package/io/xls/chart.js +1 -0
  166. package/io/xls/crypt.js +1 -0
  167. package/io/xls/dml-color.js +1 -0
  168. package/io/xls/drawing.js +1 -0
  169. package/io/xls/formula.js +1 -0
  170. package/io/xls/geometry.js +1 -0
  171. package/io/xls/index.js +1 -0
  172. package/io/xls/pictures.js +1 -0
  173. package/io/xls/pivot.js +1 -0
  174. package/io/xls/props.js +1 -0
  175. package/io/xls/records.js +1 -0
  176. package/io/xls/shapes.js +1 -0
  177. package/io/xls/sheet-ext.js +1 -0
  178. package/io/xls/sheet.js +1 -0
  179. package/io/xls/styles.js +1 -0
  180. package/io/xls/vba.js +1 -0
  181. package/io/xls/workbook.js +1 -0
  182. package/io/xlsb/filter.js +1 -0
  183. package/io/xlsb/formula.js +2 -0
  184. package/io/xlsb/functions.js +1 -0
  185. package/io/xlsb/index.js +1 -0
  186. package/io/xlsb/parts.js +1 -0
  187. package/io/xlsb/pivot.js +1 -0
  188. package/io/xlsb/records.js +1 -0
  189. package/io/xlsb/sheet-ext.js +1 -0
  190. package/io/xlsb/sheet.js +1 -0
  191. package/io/xlsb/slicer.js +1 -0
  192. package/io/xlsb/styles.js +1 -0
  193. package/io/xlsb/workbook.js +1 -0
  194. package/io/xlsb/xml.js +2 -0
  195. package/io/xlsx-read.js +1 -1
  196. package/io/xlsx-styles.js +2 -2
  197. package/io/xlsx-tail.js +1 -1
  198. package/io/xlsx-write.js +2 -2
  199. package/io/xml-escape.js +1 -1
  200. package/io/xml-scan.js +2 -2
  201. package/io/zip-reader.js +1 -1
  202. package/objects/chart-model.js +1 -1
  203. package/objects/drawing-xml.js +1 -1
  204. package/package.json +1 -1
  205. package/pivot/calc-items.js +1 -0
  206. package/pivot/engine.js +1 -1
  207. package/pivot/xml.js +2 -2
  208. package/print/note-pages.js +2 -2
  209. package/print/page-setup.js +1 -1
  210. package/print/paginate.js +1 -1
  211. package/print/pdf-crypt.js +1 -0
  212. package/print/pdf-tags.js +1 -0
  213. package/print/pdf.js +24 -13
  214. package/print/render-page.js +3 -3
  215. package/print/shown-notes.js +1 -0
  216. package/shapes/form-xml.js +1 -1
  217. package/slicers/custom-styles.js +1 -1
  218. package/slicers/format.js +1 -1
  219. package/slicers/structured.js +1 -1
  220. package/slicers/write.js +1 -1
  221. package/table-view/files.js +1 -1
  222. package/table-view/mount.js +1 -1
  223. package/table-view/version.js +1 -1
  224. package/ui/icons.js +1 -1
  225. package/ui/menu-base.js +1 -1
  226. package/ui/protection-ui.js +1 -1
@@ -0,0 +1 @@
1
+ import{cellRef as K}from"../../core/address.js";import{attrs as h,formulaXml as M,fullRangeText as X,rangeText as H,sqref as W}from"../xlsb/xml.js";import{numberText as z}from"../xlsb/records.js";import{ERROR_TEXT as J}from"../xlsb/formula.js";import{DATE_PARTS as q,DYNAMIC as Q,iconAttrs as N,ICON_SETS as U,OPERATORS as Z,SORT_ON as tt}from"../xlsb/filter.js";import{anchor as L,CFVO as et,DV_OPERATORS as nt,DV_STYLES as ot,DV_TYPES as st,guidText as it,ruleType as B,TEXT_RULES as ut}from"../xlsb/sheet-ext.js";import{MAX_COLS as ct,MAX_ROWS as at,readFormula as D}from"./formula.js";import{cfColor as P}from"./styles.js";function Y({r1:e,c1:o,r2:d,c2:i}){return{r1:e,c1:o,r2:e===0&&d===at-1?1048575:d,c2:o===0&&i===ct-1?16383:i}}const bt=e=>H(Y(e)),G=e=>W(e.map(Y));function Tt(e,o,d){try{const i=e.u32(),f=()=>e.str().replace(/^\0$/,"")||void 0,x=f(),n=f(),s=f(),a=f(),r=[0,1].map(()=>{const t=e.u16();return e.skip(2),{start:e.take(t),size:t}}),p=e.ranges(),g=L(p),v=i&15,[T,$]=r.map(({start:t,size:u})=>u?(e.pos=t,D(e,u,o,g,t+u)):"");return`<dataValidation${h({type:st[v],errorStyle:ot[i>>4&7],operator:v===0||v===3||v===7?void 0:nt[i>>20&15],allowBlank:(i&256)!==0,showDropDown:(i&512)!==0,showInputMessage:(i&262144)!==0,showErrorMessage:(i&524288)!==0,errorTitle:n,error:a,promptTitle:x,prompt:s,sqref:G(p)})}>${T?M("formula1",T.replace(/\0/g,",")):""}${$?M("formula2",$):""}</dataValidation>`}catch{return d(),""}}function wt(e,o,d){const i=[];let f=null,x=null;const n=t=>t?o.dxf(t):void 0,s=(t,u)=>{t.rules.push(u)},a=t=>{const u=t.u8(),c=t.u8(),l=[t.u16(),t.u16()],m=l[0]+l[1],b=t.end-m,w=o.readDxfn(t,b);t.pos=b;const y=L(f.ranges),R=l.filter(k=>k).map(k=>D(t,k,e,y,t.pos+k));s(f,{head:B(u,u===1?0:1,c),kind:u,formulas:R,dxf:w,stop:!0,priority:0,body:""})},r=(t,u,c,l,m)=>{const b=t.u8(),w=t.pos+b,y=t.u16(),R=t.u16();t.pos=w;let k=m;c===8||c>=15&&c<=24||c===25||c===26||c===29||c===30?k=y:c===5&&(k=R);let C=B(u===5?5:u,c,k);if(c===8&&u===2){const j=/(?:SEARCH\(|=)\s*"((?:[^"]|"")*)"/.exec(l[0]??"");j&&ut[y]?C.text=j[1].replace(/""/g,'"'):C={type:"expression"}}return C},p=(t,u)=>{const c=t.u8(),l=t.u16(),m=l?D(t,l,e,u,t.pos+l):void 0,b=!l&&c!==2&&c!==3?t.f64():null;return{type:et[c]??"num",val:c===2||c===3?void 0:m??z(b)}},g=(t,u=!0)=>`<cfvo${h({type:t.type,val:t.val,gte:u?void 0:"0"})}/>`,v=(t,u)=>{t.skip(12);const c=t.u8(),l=t.u8(),m=[t.u16(),t.u16()],b=t.u32();let w="";if(b){const S=t.pos+b;w=o.readDxfn(t,S),t.pos=S}else t.skip(2);const y=L(u.ranges),R=m.filter(S=>S).map(S=>D(t,S,e,y,t.pos+S));t.skip(t.u16());const k=t.u8(),C=t.u16(),j=t.u16(),O={head:r(t,c,j,R,l),kind:c,formulas:R,dxf:w,stop:(k&2)!==0,priority:C,body:""};if(c===3){t.skip(3);const S=t.u8(),A=t.u8();t.skip(1);const F=[];for(let E=0;E<S;E++)F.push(g(p(t,y))),t.skip(8);const I=[];for(let E=0;E<A;E++)t.skip(8),I.push(`<color${P(t)}/>`);O.body=`<colorScale>${F.join("")}${I.join("")}</colorScale>`}else if(c===4){t.skip(3);const S=t.u8(),A=t.u8(),F=t.u8(),I=P(t),E=[p(t,y),p(t,y)];O.body=`<dataBar${h({minLength:A===10?void 0:A,maxLength:F===90?void 0:F,showValue:S&2?void 0:"0"})}>${E.map(_=>g(_)).join("")}<color${I}/></dataBar>`}else if(c===5){t.skip(3);const S=t.u8(),A=t.u16();O.head={type:"top10",rank:A,percent:(S&2)!==0,bottom:(S&1)===0}}else if(c===6){t.skip(3);const S=t.u8(),A=t.u8(),F=t.u8(),I=[];for(let E=0;E<S;E++){const _=p(t,y);I.push(g(_,t.u8()!==0)),t.skip(4)}O.body=`<iconSet${h({iconSet:U[A]==="3TrafficLights1"?void 0:U[A],showValue:F&1?"0":void 0,reverse:(F&4)!==0})}>${I.join("")}</iconSet>`}s(u,O)},T=t=>{t.skip(12);const u=t.u32()!==0,c=i.find(k=>k.id===t.view.getUint16(t.pos,!0)&&!k.newer);if(t.skip(2),x=u?c??null:null,u||!c)return;const l=c.rules[t.u16()];if(!l)return;const m=t.u8(),b=t.u8(),w=t.u16(),y=t.u8();let{dxf:R}=l;if(t.u8()){const k=t.u32();if(k){const C=t.pos+k;R=o.readDxfn(t,C),t.pos=C}else t.skip(2)}l.priority=w,l.stop=(y&2)!==0,l.dxf=R,l.inactive=(y&1)===0,l.head=r(t,l.kind,b,l.formulas,m||l.head.operator),l.kind===1&&(l.head=B(1,0,m))},$=t=>{try{t()}catch{d()}};return{record(t,u){switch(t){case 432:case 2169:{t===2169&&u.skip(12),u.skip(2);const c=u.u16()>>1;return u.skip(8),f={id:c,newer:t===2169,ranges:u.ranges(),rules:[]},i.push(f),x=null,!0}case 433:return f&&$(()=>a(u)),!0;case 2170:return(x??f)&&$(()=>v(u,x??f)),!0;case 2171:return $(()=>T(u)),!0;default:return!1}},finish(){let t=1+Math.max(0,...i.flatMap(c=>c.rules.map(l=>l.priority)));const u=[];for(const c of i){const l=c.rules.filter(m=>!m.inactive).map(m=>{const{type:b,...w}=m.head;return`<cfRule${h({type:b,dxfId:n(m.dxf),priority:m.priority||t++,stopIfTrue:m.stop,...w})}>${m.formulas.map(y=>M("formula",y)).join("")}${m.body}</cfRule>`});l.length&&u.push(`<conditionalFormatting sqref="${G(c.ranges)}">${l.join("")}</conditionalFormatting>`)}return u.join("")}}}function V(e){const o=e.u8(),d=e.u8(),i=e.pos,f={kind:o,operator:Z[d],val:" ",length:0,raw:d};if(o===2)f.val=z(e.rk());else if(o===4)f.val=z(e.f64());else if(o===6)e.skip(4),f.length=e.u8();else if(o===8){const x=e.u8();f.val=e.u8()?J[x]??"#N/A":x?"TRUE":"FALSE"}else o===12?f.operator=void 0:o===14&&(f.operator="notEqual");return e.pos=i+8,f}const lt=e=>{const o=e.take(16);return e.buf.subarray(o,o+16).every(d=>d===0)};function Et(e){const o=new Map,d=new Set;let i=null,f="";return{on:!1,record(x,n){switch(x){case 157:return this.on=!0,!0;case 158:{const s=n.u16(),a=n.u16();if(a&16)return o.set(s,`<top10${h({top:a&32?void 0:"0",percent:(a&64)!==0,val:a>>7})}/>`),!0;const r=[V(n),V(n)].filter(p=>p.kind!==0);for(const p of r)p.length&&(p.val=n.text(p.length));return r.length===1&&r[0].kind===12?o.set(s,'<filters blank="1"/>'):r.length===1&&!r[0].operator&&r[0].kind===6&&!/[*?~]/.test(r[0].val)?o.set(s,`<filters><filter${h({val:r[0].val})}/></filters>`):r.length&&o.set(s,`<customFilters${h({and:r.length>1&&(a&3)===0})}>${r.map(p=>`<customFilter${h({operator:p.operator,val:p.val})}/>`).join("")}</customFilters>`),!0}case 2174:{n.skip(12);const s=n.u16(),a=n.u32()!==0,r=n.u32(),p=n.u32(),g=n.u32(),v=n.u32();n.skip(2),n.skip(4);const T=n.u32();if(i=null,T!==4294967295&&T!==0||!lt(n))return!0;if(r===1||r===2){const $=e.readDxfn(n);o.set(s,`<colorFilter${h({dxfId:$?e.dxf($):void 0,cellColor:r===2?"0":void 0})}/>`)}else if(r===3){const $=n.u32();o.set(s,`<iconFilter${h(N($,n.u32()))}/>`)}else p?o.set(s,`<dynamicFilter${h({type:Q[p]??"null"})}/>`):i={id:s,criteria:g,dates:v,items:[],blank:!1};return a&&(d.add(s),o.has(s)||o.set(s,"")),!0}case 2175:{if(!i)return!1;if(n.skip(12),i.criteria>0){i.criteria--;const s=V(n);s.length&&(s.val=n.text(s.length)),s.kind===12?i.blank=!0:s.kind&&i.items.push(`<filter${h({val:s.val})}/>`)}else if(i.dates>0){i.dates--;const s={year:n.u16(),month:n.u16(),day:n.u32(),hour:n.u16(),minute:n.u16(),second:n.u16()};n.skip(6);const a=n.u32(),r={};q.forEach((p,g)=>{g<=a&&(r[p]=s[p])}),i.items.push(`<dateGroupItem${h({...r,dateTimeGrouping:q[a]??"year"})}/>`)}return o.set(i.id,`<filters${h({blank:i.blank})}>${i.items.join("")}</filters>`),!0}case 2197:{n.skip(12);const s=n.u16(),a={r1:n.u32(),r2:n.u32(),c1:n.u32(),c2:n.u32()},r=n.u32();n.skip(4);const p=s>>3&7;if(p===1||p===3)return!0;const g=[];for(let v=0;v<r&&n.left>=30;v++){const T=n.u16(),$=T>>1&15,t={r1:n.u32(),r2:n.u32(),c1:n.u32(),c2:n.u32()},u=n.u32(),c=n.u32(),l=n.u32(),m=l?n.text(l):void 0;g.push(`<sortCondition${h({descending:(T&1)!==0,sortBy:$===3?tt[3]:void 0,ref:X(t),customList:m,...$===3?N(u,c):{}})}/>`),($===1||$===2)&&g.pop()}return g.length&&(f=`<sortState${h({columnSort:(s&1)!==0,caseSensitive:(s&2)!==0,sortMethod:s&4?"stroke":void 0,ref:X(a)})}>${g.join("")}</sortState>`),this.sortIn=p===2,!0}default:return!1}},text(x){const n=[...o].sort((s,a)=>s[0]-a[0]).map(([s,a])=>`<filterColumn${h({colId:s,hiddenButton:d.has(s)})}>${a}</filterColumn>`).join("")+(this.sortIn?f:"");return`<autoFilter ref="${x}"${n?`>${n}</autoFilter>`:"/>"}`},get sortXml(){return this.sortIn?"":f}}}const ft="{79EAC9E0-BAF9-11CE-8C82-00AA004BA90B}",rt="{00000303-0000-0000-C000-000000000046}",pt=new TextDecoder("windows-1252");function Rt(e){const o=e.range();return e.skip(16),{range:o,...dt(e)}}function dt(e){const o={target:void 0,location:void 0,display:void 0};e.skip(4);const d=e.u32(),i=()=>{const f=e.u32();return f?e.chars(f).replace(/\0[\s\S]*$/,""):""};if(d&16&&(o.display=i()),d&128&&i(),d&1)if(d&256)o.target=i();else{const f=it(e);if(f===ft){const x=e.u32(),n=e.take(x),s=[];for(let a=n;a+1<n+x;a+=2){const r=e.view.getUint16(a,!0);if(r===0)break;s.push(r)}o.target=String.fromCharCode(...s)}else if(f===rt){const x=e.u16(),n=e.u32(),s=e.take(n);let a=pt.decode(e.buf.subarray(s,s+n)).replace(/\0[\s\S]*$/,"");if(e.skip(24),e.u32()){const p=e.u32();e.skip(2),a=e.chars(p>>1)}a="..\\".repeat(x)+a,o.target=/^(?:[a-z]:\\|\\\\)/i.test(a)?`file:///${a}`:a.replace(/\\/g,"/")}else return o}return d&8&&(o.location=i()),o}function At(e){const o=e.u16(),d=e.u8()!==0,i=e.u8()!==0,f=e.u8(),x=e.u8(),n=e.u8(),s=e.text(f),a=n?e.str():"",r=x?e.str():"",g=Array.from({length:o},()=>K(e.u16(),e.u16())).map(v=>`<inputCells${h({r:v,val:e.str()})}/>`);return`<scenario${h({name:s,locked:d,hidden:i,count:o,user:a||void 0,comment:r||void 0})}>${g.join("")}</scenario>`}export{wt as conditionalFormats,Tt as dataValidation,Et as filterReader,Rt as hyperlink,dt as hyperlinkObject,bt as rangeText,At as scenarioXml,G as sqref,Y as widened};
@@ -0,0 +1 @@
1
+ import{escapeMarkup as X,xmlText as Z}from"../xml-escape.js";import{cellRef as N,colName as ke}from"../../core/address.js";import{attrs as p,fullRangeText as B,NS_MAIN as $e,NS_R as ve,XML_HEAD as ye}from"../xlsb/xml.js";import{numberText as m}from"../xlsb/records.js";import{ERROR_TEXT as ie}from"../xlsb/formula.js";import{runsXml as Re}from"../xlsb/styles.js";import{eachRecord as Se,XlsReader as J}from"./records.js";import{deferredTo as Ce,MAX_COLS as L,MAX_ROWS as Le,readFormula as I}from"./formula.js";import{cfColor as Fe}from"./styles.js";import{hex4 as le}from"./workbook.js";import{conditionalFormats as Pe,dataValidation as Me,filterReader as Te,hyperlink as Ve,rangeText as ze,scenarioXml as Ee,sqref as _,widened as Oe}from"./sheet-ext.js";const q=["bottomRight","topRight","bottomLeft","topLeft"],Ne=[void 0,"blank","dash","NA"],je=["sheetProtection","protectedRanges","scenarios","autoFilter","sortState","mergeCells","conditionalFormatting","dataValidations","hyperlinks","printOptions","pageMargins","pageSetup","headerFooter","rowBreaks","colBreaks","cellWatches","ignoredErrors","drawing","legacyDrawing","picture","controls","tableParts"],De=new Set(["protectedRanges","mergeCells","dataValidations","hyperlinks","cellWatches","ignoredErrors","tableParts"]),Ae=new Set([6,513,190,515,638,189,253,516,214,517,519,520,1212,545,566,215,523]),He=new Set([6,513,190,515,638,189,253,516,214,517]),We=new Set([176,177,178,180,181,182,197,240,241,242,244,245,246,247,249,251,256,259,2050,2064,2148]);function G(c){const r=c.buf.slice(c.pos,c.end);return new J(r,0,r.length,c.breaks.map(l=>l-c.pos))}const Xe=c=>`<t${/^\s|\s$|\n/.test(c)?' xml:space="preserve"':""}>${Z(c)}</t>`;async function ot(c,r,l){const{book:u,index:z,styles:v,objects:b}=l,i={view:null,scale:0,pane:"",selections:[],base:8,width:null,height:255,formatFlags:0,cols:[],outlineRows:0,outlineCols:0,tab:"",publish:!0,calcFormats:!0,codeName:void 0,ws:1217,plv:0,plvScale:0,filterMode:!1},w={},C=(t,e)=>(w[t]??=[]).push(e),F={row:0,col:0},k=Te(v),j=Pe(u,v,l.onLost),g={on:!1,password:0,objects:!1,scenarios:!1,allowed:null},$={margins:{},setup:null,print:{},header:"",footer:"",more:null},h={},M=[],E=new Map,O=new Map;let y=null;const T=new Map;let D=-1,A=!1,x=null;const H=new Map;let ce=0;const U=[],re=()=>{const t=i.tab?`<tabColor${i.tab}/>`:"",{ws:e}=i,s=p({applyStyles:(e&32)!==0,summaryBelow:e&64?void 0:"0",summaryRight:e&128?void 0:"0",showOutlineSymbols:void 0}),n=p({autoPageBreaks:e&1?void 0:"0",fitToPage:(e&256)!==0}),a=p({syncHorizontal:(e&4096)!==0,syncVertical:(e&8192)!==0,transitionEvaluation:(e&16384)!==0,transitionEntry:(e&32768)!==0,published:i.publish?void 0:"0",codeName:i.codeName,filterMode:i.filterMode,enableFormatConditionsCalculation:i.calcFormats?void 0:"0"}),o=t+(s?`<outlinePr${s}/>`:"")+(n?`<pageSetUpPr${n}/>`:"");r.add(`${ye}<worksheet xmlns="${$e}" xmlns:r="${ve}">${a||o?`<sheetPr${a}${o?`>${o}</sheetPr>`:"/>"}`:""}${Be(i)}<sheetFormatPr${p({baseColWidth:i.base===8?void 0:i.base,defaultColWidth:i.width===null?void 0:m(i.width/256),defaultRowHeight:m(i.height/20),customHeight:(i.formatFlags&1)!==0,zeroHeight:(i.formatFlags&2)!==0,thickTop:(i.formatFlags&4)!==0,thickBottom:(i.formatFlags&8)!==0,outlineLevelRow:i.outlineRows||void 0,outlineLevelCol:i.outlineCols||void 0})}/>${i.cols.length?`<cols>${i.cols.join("")}</cols>`:""}<sheetData>`)},K=()=>{A&&r.add("</row>"),A=!1},Q=t=>t?p({s:t.flags&128?v.cellXf(t.xf):void 0,customFormat:(t.flags&128)!==0,ht:t.height!==null&&(t.height!==i.height||t.flags&64)?m(t.height/20):void 0,hidden:(t.flags&32)!==0,customHeight:(t.flags&64)!==0,outlineLevel:t.flags&7||void 0,collapsed:(t.flags&16)!==0,thickTop:(t.more&4096)!==0,thickBot:(t.more&8192)!==0,ph:(t.more&16384)!==0}):"",ee=t=>{const e=[...T.keys()].filter(s=>s<t).sort((s,n)=>s-n);for(const s of e){const n=Q(T.get(s));n&&r.add(`<row r="${s+1}"${n}/>`),T.delete(s)}},fe=t=>{t===D&&A||(K(),T.size&&t>D&&ee(t),D=t,r.add(`<row r="${t+1}"${Q(T.get(t))}>`),T.delete(t),A=!0)},R=(t,e,s,n,a)=>{fe(t);const o=v.cellXf(s);r.add(`<c r="${ke(e)}${t+1}"${o?` s="${o}"`:""}${n?` t="${n}"`:""}${a?`>${a}</c>`:"/>"}`)},V=()=>{if(!x)return;const t=x;x=null;let{f:e}=t;if(t.defers){const s=H.get(t.defers.row*L+t.defers.col);s?e=ue(s,t)??e:t.covered||l.onLost()}R(t.row,t.col,t.xf,t.type,e+t.value)},ue=(t,e)=>{const s=e.always?' ca="1"':"";if(t.array)return t.own===e?t.array:"";if(t.si>=0)return t.first===e?`<f t="shared"${s} ref="${t.ref}" si="${t.si}">${X(t.text)}</f>`:`<f t="shared"${s} si="${t.si}"/>`;try{const n=new J(t.bytes);return`<f${s}>${X(I(n,t.size,u,{row:e.row,col:e.col}))}</f>`}catch{return l.onLost(),""}},te=async(t,e,s)=>{let n=!1,a=0,o=!1;await Se(c,u.sheets[z].start,u,(f,d)=>f===2057?n?(a++,d.skip(2),a===1&&e?.(null,d.u16()===32),!0):(n=!0,!0):f===10?a-- >0:a>0?(a===1&&e?.({type:f,r:d}),!0):(f===426?o=!0:f===427&&(o=!1),o||t(f,d),!0),s)};let W=null,se=null;const oe=t=>(e,s)=>{try{t(e,s)}catch{l.onLostPart()}};await te(oe((t,e)=>{if(!Ae.has(t)){if(We.has(t)){t===176&&l.onPivot(se=[]),se?.push({type:t,r:G(e)});return}k.record(t,e)||j.record(t,e)||ge(t,e)}}),(t,e)=>{t?W?.push({type:t.type,r:G(t.r)}):(W=e?[]:null,W&&b.chart(W))}),re(),await te(oe((t,e)=>{t===520?we(e):He.has(t)?(V(),de(t,e)):x&&(t===519?(x.value=`<v>${Z(e.str())}</v>`,V()):t===1212?pe(e):t===545?he(e):t===566?be(e):V())}),null,()=>r.flush());function de(t,e){const s=e.u16(),n=e.u16();if(n>=L)return;switch(t){case 190:for(let o=n;e.left>=4;o++)R(s,o,e.u16(),"","");return;case 189:for(let o=n;e.left>=8;o++){const f=e.u16();R(s,o,f,"",`<v>${m(e.rk())}</v>`)}return;default:}const a=e.u16();switch(t){case 513:R(s,n,a,"","");break;case 515:R(s,n,a,"",`<v>${m(e.f64())}</v>`);break;case 638:R(s,n,a,"",`<v>${m(e.rk())}</v>`);break;case 253:R(s,n,a,"s",`<v>${e.u32()}</v>`);break;case 516:R(s,n,a,"inlineStr",`<is>${Xe(e.str())}</is>`);break;case 214:{const o=e.str(),f=[];for(let d=e.left>=2?e.u16():0;d>0&&e.left>=4;d--)f.push({at:e.u16(),font:v.fontProps(e.u16())});R(s,n,a,"inlineStr",`<is>${Re(o,f)}</is>`);break}case 517:{const o=e.u8();e.u8()?R(s,n,a,"e",`<v>${ie[o]??"#N/A"}</v>`):R(s,n,a,"b",`<v>${o?1:0}</v>`);break}default:xe(e,s,n,a)}}function xe(t,e,s,n){const a=t.take(8),o={row:e,col:s,xf:n,type:"",value:"",f:"",defers:null,always:!1,covered:!1};if(t.buf[a+6]===255&&t.buf[a+7]===255){const S=t.buf[a+2];switch(t.buf[a]){case 0:o.type="str";break;case 1:o.type="b",o.value=`<v>${S?1:0}</v>`;break;case 2:o.type="e",o.value=`<v>${ie[S]??"#N/A"}</v>`;break;default:o.type="str",o.value="<v></v>"}}else o.value=`<v>${m(t.view.getFloat64(a,!0))}</v>`;const f=t.u16();o.always=(f&1)!==0,t.skip(4);const d=t.u16();if(o.defers=Ce(t,d),o.defers)o.covered=U.some(S=>e>=S.r1&&e<=S.r2&&s>=S.c1&&s<=S.c2);else{F.row=e,F.col=s;try{o.f=`<f${o.always?' ca="1"':""}>${X(I(t,d,u,F))}</f>`}catch{l.onLost()}if(o.type!=="str"||o.value){R(e,s,n,o.type,o.f+o.value);return}}x=o,o.defers&&H.has(o.defers.row*L+o.defers.col)&&(o.type!=="str"||o.value)&&V()}function pe(t){const e=t.smallRange();t.skip(2);const s=t.u16(),n=t.buf.slice(t.pos,t.end),a={row:x.row,col:x.col},o=x.defers?x.defers.row*L+x.defers.col:a.row*L+a.col,f={si:-1,text:"",ref:"",first:x,size:s,bytes:n};x.defers??=a,H.set(o,f);try{const d={...a,span:{rows:Math.max(0,e.r2-a.row),cols:Math.max(0,e.c2-a.col)},wraps:!1},S=I(new J(n),s,u,d);!d.wraps&&e.r1>=a.row&&e.c1>=a.col&&Object.assign(f,{si:ce++,text:S,ref:B(e)})}catch{}(x.type!=="str"||x.value)&&V()}function he(t){const e=t.smallRange(),s=t.u16();t.skip(4);const n=t.u16();U.push(e);const a={array:"",own:x};try{a.array=`<f t="array"${s&1?' ca="1"':""} ref="${B(e)}">${X(I(t,n,u,{row:x.row,col:x.col}))}</f>`}catch{l.onLost()}ne(a)}function be(t){const e=t.smallRange(),s=t.u16(),[n,a,o,f]=[t.u16(),t.u16(),t.u16(),t.u16()];U.push(e),ne({own:x,array:`<f${p({t:"dataTable",ref:B(e),dt2D:(s&8)!==0,dtr:(s&4)!==0,r1:s&16?void 0:N(n,a&255),del1:(s&16)!==0,r2:s&8&&!(s&32)?N(o,f&255):void 0,del2:(s&32)!==0,ca:(s&1)!==0})}/>`})}function ne(t){const{defers:e,row:s,col:n}=x;H.set(e?e.row*L+e.col:s*L+n,t),x.defers??={row:s,col:n},(x.type!=="str"||x.value)&&V()}function we(t){const e=t.u16();t.skip(4);const s=t.u16();t.skip(4);const n=t.u8();t.skip(1);const a=t.u16(),o={height:s&32768?null:s&32767,flags:n,xf:a&4095,more:a};e!==D&&T.set(e,o),n&32?O.set(e,0):o.height!==null&&o.height!==i.height&&O.set(e,o.height)}function ge(t,e){switch(t){case 549:{i.formatFlags=e.u16();const s=e.i16();s>0&&(i.height=s);break}case 85:i.base=e.u16();break;case 153:i.width=e.u16();break;case 125:{const s=e.u16(),n=Math.min(e.u16(),L-1),a=n===L-1&&s<n?16383:n,o=e.u16(),f=e.u16(),d=e.u16();if(s>a)break;const S=v.cellXf(f);i.cols.push(`<col${p({min:s+1,max:a+1,width:m(o/256),style:S||void 0,hidden:(d&1)!==0,customWidth:!0,bestFit:(d&4)!==0,phonetic:(d&8)!==0,outlineLevel:d>>8&7||void 0,collapsed:(d&4096)!==0})}/>`);for(let Y=s;Y<=n;Y++)E.set(Y,d&1?0:o);break}case 128:e.skip(4),i.outlineRows=Math.max(0,e.u16()-1),i.outlineCols=Math.max(0,e.u16()-1);break;case 129:i.ws=e.u16();break;case 442:i.codeName=e.str()||void 0;break;case 155:i.filterMode=!0;break;case 2146:{e.skip(12);const s=e.u32(),n=e.u32()&127;if(n>=8&&n<64&&(i.tab=v.color(n)),s>=40&&e.left>=20){const a=e.u32();i.calcFormats=(a&128)!==0,i.publish=(a&256)===0;const o=Fe(e);o&&o!==' auto="1"'&&n!==127&&(i.tab=o)}break}case 574:{const s=e.u16(),n=e.u16(),a=e.u16(),o=e.u16();e.skip(2),i.view={flags:s,top:n,left:a,grid:o,preview:e.left>=4?e.u16():0,normal:e.left>=2?e.u16():0};break}case 160:{const s=e.u16();i.scale=Math.round(s*100/(e.u16()||1));break}case 2187:e.skip(12),i.plvScale=e.u16(),i.plv=e.u16();break;case 65:{const s=e.u16(),n=e.u16(),a=e.u16(),o=e.u16(),f=e.u8(),d=(i.view?.flags&8)!==0;if(!s&&!n)break;i.pane=`<pane${p({xSplit:s||void 0,ySplit:n||void 0,topLeftCell:N(n?a:i.view?.top??0,s?o:i.view?.left??0),activePane:q[f]==="topLeft"?void 0:q[f],state:d?i.view.flags&256?"frozen":"frozenSplit":void 0})}/>`;break}case 29:{const s=e.u8(),n=e.u16(),a=e.u16(),o=e.u16(),f=[];for(let d=e.u16();d>0&&e.left>=6;d--)f.push(e.smallRange());i.selections.push(`<selection${p({pane:q[s]==="topLeft"?void 0:q[s],activeCell:N(n,Math.min(a,L-1)),activeCellId:o||void 0,sqref:_(f)||void 0})}/>`);break}case 13:h.mode=e.i16();break;case 12:h.count=e.u16();break;case 15:h.a1=e.u16()!==0;break;case 17:h.iterate=e.u16()!==0;break;case 16:h.delta=e.f64();break;case 95:h.onSave=e.u16()!==0;break;case 18:g.on=e.u16()!==0;break;case 19:g.password=e.u16();break;case 99:g.objects=e.u16()!==0;break;case 221:g.scenarios=e.u16()!==0;break;case 2151:{e.skip(12),e.u16()===2&&(e.skip(5),e.left>=4&&(g.allowed=e.u32()));break}case 2152:me(e);break;case 38:case 39:case 40:case 41:$.margins[["left","right","top","bottom"][t-38]]=e.f64();break;case 20:$.header=e.left>=3?e.str():"";break;case 21:$.footer=e.left>=3?e.str():"";break;case 131:$.print.horizontalCentered=e.u16()!==0;break;case 132:$.print.verticalCentered=e.u16()!==0;break;case 42:$.print.headings=e.u16()!==0;break;case 43:$.print.gridLines=e.u16()!==0;break;case 161:$.setup=G(e);break;case 2204:{e.skip(12);const s=e.take(16);if(e.buf.subarray(s,s+16).some(o=>o!==0))break;const n=e.u16(),a=[e.u16(),e.u16(),e.u16(),e.u16()];$.more={flags:n,texts:a.map(o=>o?e.str():"")};break}case 27:case 26:{const s=[];for(let a=e.u16();a>0&&e.left>=6;a--){const o=e.u16(),f=e.u16(),d=e.u16();s.push(`<brk${p({id:o,min:f||void 0,max:_e(d,t===27),man:!0})}/>`)}const n=t===27?"rowBreaks":"colBreaks";s.length&&(w[n]=[`<${n} count="${s.length}" manualBreakCount="${s.length}">${s.join("")}</${n}>`]);break}case 229:for(let s=e.u16();s>0&&e.left>=8;s--)C("mergeCells",`<mergeCell ref="${B(Oe(e.range()))}"/>`);break;case 446:{const s=Me(e,u,l.onLost);s&&C("dataValidations",s);break}case 440:{try{M.push(Ve(e))}catch{l.onLostPart()}break}case 2048:{e.skip(2);const s=e.range(),n=e.chars(e.left>>1).replace(/\0[\s\S]*$/,""),a=M.findLast(o=>o.range.r1===s.r1&&o.range.c1===s.c1);a&&(a.tooltip=n);break}case 174:{e.skip(2);const s=e.i16(),n=e.i16(),a=[];for(let o=e.u16();o>0&&e.left>=8;o--)a.push(e.range());y={open:p({current:s>=0?s:void 0,show:n>=0?n:void 0,sqref:a.length?_(a):void 0}),items:[]};break}case 175:try{y?.items.push(Ee(e))}catch{l.onLostPart()}break;case 2156:e.skip(4),C("cellWatches",`<cellWatch r="${N(e.u16(),(e.skip(2),e.u16()))}"/>`);break;case 236:b.drawing(e);break;case 93:b.object(e);break;case 438:b.text(e);break;case 28:b.note(e);break;case 233:b.background(e);break;case 2162:case 2168:l.onTable(t,G(e));break;default:}}function me(t){t.skip(12);const e=t.u16();t.skip(5);const s=t.u16();t.skip(6);const n=Array.from({length:Math.min(s,t.left>>3)},()=>t.range());if(e===3){const a=t.u32();C("ignoredErrors",`<ignoredError${p({sqref:_(n),evalError:(a&1)!==0,emptyCellReference:(a&2)!==0,numberStoredAsText:(a&4)!==0,formulaRange:(a&8)!==0,formula:(a&16)!==0,twoDigitTextYear:(a&32)!==0,unlockedFormula:(a&64)!==0,listDataValidation:(a&128)!==0})}/>`)}else if(e===2){const a=(t.u32()&1)!==0,o=t.u32(),f=t.str();a&&!o?l.onLostPart():C("protectedRanges",`<protectedRange${p({password:le(o&65535),sqref:_(n),name:f})}/>`)}}if(V(),K(),ee(Le),r.add("</sheetData>"),g.on){const t=g.allowed??17408,e=n=>(t>>n&1)!==0,s=n=>e(n)?"0":void 0;w.sheetProtection=[`<sheetProtection${p({password:le(g.password),sheet:!0,objects:g.allowed===null||!e(0)?g.objects:void 0,scenarios:g.allowed===null||!e(1)?g.scenarios:void 0,formatCells:s(2),formatColumns:s(3),formatRows:s(4),insertColumns:s(5),insertRows:s(6),insertHyperlinks:s(7),deleteColumns:s(8),deleteRows:s(9),selectLockedCells:e(10)?void 0:"1",sort:s(11),autoFilter:s(12),pivotTables:s(13),selectUnlockedCells:e(14)?void 0:"1"})}/>`]}y?.items.length&&(w.scenarios=[`<scenarios${y.open}>${y.items.join("")}</scenarios>`]),k.on&&l.filterRange&&(w.autoFilter=[k.text(l.filterRange)]),k.sortXml&&(w.sortState=[k.sortXml]);const ae=j.finish();ae&&(w.conditionalFormatting=[ae]);for(const t of M){const e=t.target?l.rel("hyperlink",t.target,!0):void 0;C("hyperlinks",`<hyperlink${p({ref:ze(t.range),"r:id":e,location:t.location||void 0,tooltip:t.tooltip||void 0,display:t.display||void 0})}/>`)}Ie($,w);const P=await l.finish({cols:E,heights:O,head:i});P.drawing&&(w.drawing=[`<drawing r:id="${P.drawing}"/>`]),P.vml&&(w.legacyDrawing=[`<legacyDrawing r:id="${P.vml}"/>`]),P.picture&&(w.picture=[`<picture r:id="${P.picture}"/>`]),P.controls&&(w.controls=[P.controls]);for(const t of P.tables??[])C("tableParts",`<tablePart r:id="${t}"/>`);for(const t of je){const e=w[t];if(!e?.length)continue;const s=e.join("");De.has(t)?r.add(`<${t}${t==="mergeCells"||t==="dataValidations"||t==="tableParts"?` count="${e.length}"`:""}>${s}</${t}>`):r.add(s)}return r.add("</worksheet>"),await r.flush(!0),{calc:h}}function Be(c){const r=c.view;if(!r)return'<sheetViews><sheetView workbookViewId="0"/></sheetViews>';const{flags:l}=r,u=(c.plv&1)!==0,z=(l&2048)!==0,v=p({showFormulas:(l&1)!==0,showGridLines:l&2?void 0:"0",showRowColHeaders:l&4?void 0:"0",showZeros:l&16?void 0:"0",rightToLeft:(l&64)!==0,tabSelected:(l&512)!==0,showRuler:c.plv&2||!u?void 0:"0",showOutlineSymbols:l&128?void 0:"0",defaultGridColor:l&32?void 0:"0",showWhiteSpace:c.plv&4?"0":void 0,view:u?"pageLayout":z?"pageBreakPreview":void 0,topLeftCell:r.top||r.left?N(r.top,r.left):void 0,colorId:l&32||r.grid>=64?void 0:r.grid,zoomScale:c.scale&&c.scale!==100?c.scale:void 0,zoomScaleNormal:r.normal||void 0,zoomScaleSheetLayoutView:r.preview||void 0,zoomScalePageLayoutView:c.plvScale||void 0,workbookViewId:0}),b=c.pane+c.selections.join("");return`<sheetViews><sheetView${v}${b?`>${b}</sheetView>`:"/>"}</sheetViews>`}function Ie(c,r){const l=p(c.print);l&&(r.printOptions=[`<printOptions${l}/>`]);const u=c.setup;let z=.5,v=.5;if(u){const F=u.u16(),k=u.u16(),j=u.i16(),g=u.u16(),$=u.u16(),h=u.u16(),M=u.u16(),E=u.u16();z=u.f64(),v=u.f64();const O=u.left>=2?u.u16():1,y=(h&4)===0;r.pageSetup=[`<pageSetup${p({paperSize:y&&F>1?F:void 0,scale:y&&k&&k!==100?k:void 0,firstPageNumber:h&128?j:void 0,fitToWidth:g===1?void 0:g,fitToHeight:$===1?void 0:$,pageOrder:h&1?"overThenDown":void 0,orientation:!y||h&64?void 0:h&2?"portrait":"landscape",blackAndWhite:(h&8)!==0,draft:(h&16)!==0,cellComments:h&32?h&512?"atEnd":"asDisplayed":void 0,useFirstPageNumber:(h&128)!==0,errors:Ne[h>>10&3],horizontalDpi:y&&M&&M!==600?M:void 0,verticalDpi:y&&E&&E!==600?E:void 0,copies:y&&O>1?O:void 0})}/>`]}const b=c.margins;(u||Object.keys(b).length)&&(r.pageMargins=[`<pageMargins${p({left:m(b.left??.75),right:m(b.right??.75),top:m(b.top??1),bottom:m(b.bottom??1),header:m(z),footer:m(v)})}/>`]);const i=c.more??{flags:12,texts:["","","",""]},w={oddHeader:c.header,oddFooter:c.footer,evenHeader:i.texts[0],evenFooter:i.texts[1],firstHeader:i.texts[2],firstFooter:i.texts[3]},C=Object.entries(w).map(([F,k])=>k?`<${F}${/^\s|\s$|\n/.test(k)?' xml:space="preserve"':""}>${Z(k)}</${F}>`:"").join("");C&&(r.headerFooter=[`<headerFooter${p({differentOddEven:(i.flags&1)!==0,differentFirst:(i.flags&2)!==0,scaleWithDoc:i.flags&4?void 0:"0",alignWithMargins:i.flags&8?void 0:"0"})}>${C}</headerFooter>`])}function _e(c,r){const[l,u]=r?[255,16383]:[65535,1048575];return c===0||c>=l?u:c}export{G as keep,Ie as pageSlots,ot as writeSheet};
@@ -0,0 +1 @@
1
+ import{escapeMarkup as I}from"../xml-escape.js";import{COLOR_INDEX as E}from"../../core/numfmt.js";import{attrs as p,NS_MAIN as B,XML_HEAD as G}from"../xlsb/xml.js";import{numberText as q}from"../xlsb/records.js";import{alignmentXml as A,BORDER_STYLES as H,BUILTIN_STYLES as Y,colorXml as X,fontBody as w,gradientXml as V,H_ALIGN as O,PATTERNS as _,sideXml as D,stopXml as J,V_ALIGN as N}from"../xlsb/styles.js";const g=i=>i.toString(16).toUpperCase().padStart(2,"0"),R=15,K=new Set([0,1,2,3,4,9,10,11,12,13,14,15,16,17,18,19,20,21,22,45,46,47,48,49]);function S(i,t,e){let n;if(i===0)n=' auto="1"';else if(i===1)n=` indexed="${e&255}"`;else if(i===2)n=` rgb="FF${g(e&255)}${g(e>>8&255)}${g(e>>16&255)}"`;else if(i===3)n=` theme="${e&255}"`;else return"";return t?`${n} tint="${q(t)}"`:n}function Q(i){const t=i.u16(),e=i.i16();return S(t,e/32767,i.u32())}function ft(i){const t=i.u32(),e=i.u32();return S(t,i.f64(),e)}class at{constructor(){this.fonts=[],this.formats=new Map,this.xfs=[],this.named=[],this.namedExt=new Map,this.palette=null,this.fills=['<fill><patternFill patternType="none"/></fill>','<fill><patternFill patternType="gray125"/></fill>'],this.borders=["<border><left/><right/><top/><bottom/><diagonal/></border>"],this.dxfs=[],this.places={fills:new Map(this.fills.map((t,e)=>[t,e])),borders:new Map(this.borders.map((t,e)=>[t,e])),fonts:new Map,dxfs:new Map},this.fontList=[],this.cellXfs=null}color(t){if(t===32767)return"";if(t>=64)return` indexed="${t===65?65:64}"`;const e=t>=8?this.palette?.[t-8]:void 0;return e?` rgb="FF${e}"`:` indexed="${t}"`}rgb(t){return t>=64?t===65||t===78?"FFFFFF":t===64||t===77||t===79?"000000":null:t<8?E[t]:this.palette?.[t-8]??E[t-8]??null}readPalette(t){const e=Math.min(t.u16(),56);this.palette=Array.from({length:e},()=>{const n=`${g(t.u8())}${g(t.u8())}${g(t.u8())}`;return t.skip(1),n})}readFont(t){const e={size:t.u16()/20},n=t.u16();e.italic=(n&2)!==0,e.strike=(n&8)!==0,e.outline=(n&16)!==0,e.shadow=(n&32)!==0,e.condense=(n&64)!==0,e.extend=(n&128)!==0,e.icv=t.u16(),e.bold=t.u16()>=600,e.script=t.u16(),e.underline=t.u8(),e.family=t.u8(),e.charset=t.u8(),t.skip(1),e.name=t.short(),this.fonts.push(e)}font(t){return this.fonts[t>4?t-1:t]??this.fonts[0]}fontProps(t){const e=this.font(t);return e?{...e,color:this.color(e.icv)}:{name:"Arial",size:10,color:""}}readFormat(t){const e=t.u16();this.formats.set(e,t.str())}readXf(t){this.checksum=Z(this.checksum??0,t);const e={font:t.u16(),format:t.u16(),ext:null},n=t.u16();e.locked=(n&1)!==0,e.hidden=(n&2)!==0,e.style=(n&4)!==0,e.quote=(n&8)!==0,e.parent=n>>4;const l=t.u8();e.h=l&7,e.wrap=(l&8)!==0,e.v=l>>4&7,e.justLast=(l&128)!==0,e.rotation=t.u8();const f=t.u8();e.indent=f&15,e.shrink=(f&16)!==0,e.reading=f>>6,e.apply=t.u8()>>2;const s=t.u32(),a=t.u32(),d=t.u16(),r=(m,c)=>({style:m,icv:c});e.left=r(s&15,s>>16&127),e.right=r(s>>4&15,s>>23&127),e.top=r(s>>8&15,a&127),e.bottom=r(s>>12&15,a>>7&127),e.diagonal=r(a>>21&15,a>>14&127),e.down=(s&1073741824)!==0,e.up=(s&2147483648)!==0,e.pattern=a>>>26,e.fore=d&127,e.back=d>>7&127,e.button=(d&16384)!==0,this.xfs.push(e)}readXfCheck(t){t.skip(14);const e=t.u16();this.extended=e===this.xfs.length&&t.u32()===this.checksum}readXfExt(t){if(this.extended===!1)return;t.skip(14);const e=this.xfs[t.u16()];t.skip(2);const n=z(t,t.u16());e&&(e.ext=n)}readStyle(t){const e=t.u16(),n={xf:e&4095,builtin:null,level:0,name:null};e&32768?(n.builtin=t.u8(),n.level=t.u8(),n.name=Y[n.builtin]?.replace("#",n.level+1)??`Style ${n.xf}`):n.name=t.str(),this.named.push(n)}readStyleExt(t){t.skip(12);const e=t.u8();t.skip(1);const n=t.u8(),l=t.u8(),f=t.chars(t.u16());this.namedExt.set(f.toLowerCase(),{builtin:e&1?n:null,level:l,hidden:(e&2)!==0,custom:(e&4)!==0})}place(t,e){const n=this.places[t].get(e);if(n!==void 0)return n;const l=t==="fonts"?this.fontList:this[t];return this.places[t].set(e,l.length),l.push(e),l.length-1}fontPlace(t,e){const n=this.fontProps(t);return e?.text!==void 0&&(n.color=e.text),e?.scheme!==void 0&&(n.scheme=e.scheme),this.place("fonts",`<font>${w(n)}</font>`)}fillPlace(t){const{ext:e}=t;if(e?.gradient)return this.place("fills",e.gradient);if(t.pattern===0)return 0;const n=e?.fg??this.color(t.fore),l=e?.bg??this.color(t.back);return t.pattern===17&&t.fore>=64&&t.back>=64&&!e?.fg&&!e?.bg?1:this.place("fills",`<fill><patternFill patternType="${_[t.pattern]??"solid"}">${X("fgColor",n)}${X("bgColor",l)}</patternFill></fill>`)}borderPlace(t){const e=l=>D(l,t[l].style,t.ext?.[l]??this.color(t[l].icv)),n=`${e("left")}${e("right")}${e("top")}${e("bottom")}${t.up||t.down?e("diagonal"):"<diagonal/>"}`;return this.place("borders",`<border${p({diagonalUp:t.up,diagonalDown:t.down})}>${n}</border>`)}xfXml(t,e){const n=e===null,l=A({horizontal:t.h?O[t.h]:void 0,vertical:t.v!==2?N[t.v]:void 0,textRotation:t.rotation||void 0,wrapText:t.wrap,indent:(t.ext?.indent??t.indent)||void 0,justifyLastLine:t.justLast,shrinkToFit:t.shrink,readingOrder:t.reading||void 0}),f=!t.locked||t.hidden?`<protection${p({locked:t.locked?void 0:"0",hidden:t.hidden})}/>`:"",s=(d,r)=>{const m=(t.apply&r)!==0;return n?m?` ${d}="0"`:"":m?` ${d}="1"`:""},a=`<xf numFmtId="${t.format}" fontId="${this.fontPlace(t.font,t.ext)}" fillId="${this.fillPlace(t)}" borderId="${this.borderPlace(t)}"${n?"":` xfId="${e}"`}${p({quotePrefix:t.quote,pivotButton:t.button})}${s("applyNumberFormat",1)}${s("applyFont",2)}${s("applyFill",16)}${s("applyBorder",8)}${s("applyAlignment",4)}${s("applyProtection",32)}`;return l||f?`${a}>${l}${f}</xf>`:`${a}/>`}finish(){this.fonts.length===0&&this.fonts.push({name:"Arial",size:10,icv:32767}),this.place("fonts",`<font>${w(this.fontProps(0))}</font>`);const t=new Map;this.styleXfs=[];const e=s=>{const a=this.xfs[s];return a?(t.has(s)||(t.set(s,this.styleXfs.length),this.styleXfs.push(this.xfXml(a,null))),t.get(s)):0},n=this.named.find(s=>s.builtin===0)?.xf??0;e(n),this.xfs.forEach((s,a)=>s.style&&e(a)),this.styleXfs.length===0&&this.styleXfs.push('<xf numFmtId="0" fontId="0" fillId="0" borderId="0"/>'),this.cellXfs=[],this.xfPlace=new Map;const l=s=>{const a=this.xfs[s];this.xfPlace.set(s,this.cellXfs.length),this.cellXfs.push(a?this.xfXml(a,a.style?e(s):e(this.xfs[a.parent]?.style?a.parent:n)):'<xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>')};l(R),this.xfs.forEach((s,a)=>a===R?void 0:l(a)),this.namedXml=[];const f=new Set;for(const s of this.named){if(!this.xfs[s.xf]||f.has(s.name.toLowerCase()))continue;f.add(s.name.toLowerCase());const a=this.namedExt.get(s.name.toLowerCase()),d=s.builtin??a?.builtin??null;this.namedXml.push(`<cellStyle${p({name:s.name,xfId:e(s.xf),builtinId:d??void 0,iLevel:d===1||d===2?s.level:void 0,hidden:a?.hidden,customBuiltin:d!==null&&a?.custom})}/>`)}this.namedXml.length||this.namedXml.push('<cellStyle name="Normal" xfId="0" builtinId="0"/>')}cellXf(t){return this.xfPlace.get(t)??0}dxf(t){return this.place("dxfs",t)}xml(){const t=(n,l)=>`<${n} count="${l.length}">${l.join("")}</${n}>`,e=[...this.formats].filter(([n])=>!K.has(n)).map(([n,l])=>`<numFmt numFmtId="${n}" formatCode="${I(l)}"/>`);return`${G}<styleSheet xmlns="${B}">`+(e.length?t("numFmts",e):"")+t("fonts",this.fontList)+t("fills",this.fills)+t("borders",this.borders)+t("cellStyleXfs",this.styleXfs)+t("cellXfs",this.cellXfs)+t("cellStyles",this.namedXml)+t("dxfs",this.dxfs.map(n=>`<dxf>${n}</dxf>`))+'<tableStyles count="0" defaultTableStyle="TableStyleMedium9" defaultPivotStyle="PivotStyleLight16"/></styleSheet>'}readDxfn(t,e=t.end){const n=t.u32(),l=t.u16(),f=o=>(n>>>o&1)!==0,s={partial:!0};let a="";const d={},r={};let m={};const c={},x={};if(n&1<<25)if(l&1){const o=t.pos,u=t.u16(),h=t.str();t.pos=o+Math.max(u,2),a=`<numFmt numFmtId="${this.formatId(h)}" formatCode="${I(h)}"/>`}else{t.skip(1);const o=t.u8();f(19)||(a=`<numFmt numFmtId="${o}" formatCode="${I(this.formats.get(o)??tt[o]??"General")}"/>`)}if(n&1<<26){const o=t.pos,u=t.u8();u&&(s.name=t.text(u)),t.pos=o+64;const h=t.u32(),b=t.u32(),$=t.u16(),y=t.u16(),F=t.u8();t.skip(3);const T=t.u32();t.skip(4);const C=t.u32(),j=t.u32()!==0,U=t.u32()!==0,v=t.u32()!==0;t.pos=o+118,h!==4294967295&&(s.size=h/20),C&2||(s.italic=(b&2)!==0),C&128||(s.strike=(b&128)!==0),!v&&$!==65535&&(s.bold=$>=600),!j&&y!==65535&&(s.script=y),!U&&F!==255&&(s.underline=F),T!==4294967295&&(s.color=this.color(T))}if(n&1<<27){const o=t.u32(),u=t.i32();f(0)||(d.horizontal=O[o&7]),f(2)||(d.wrapText=(o&8)!==0),f(1)||(d.vertical=N[o>>4&7]),f(3)||(d.textRotation=o>>8&255),f(4)||(d.justifyLastLine=(o&128)!==0),f(5)||(u===255||u<-15||u>15?d.indent=o>>16&15:d.relativeIndent=String(u)),f(6)||(d.shrinkToFit=(o&1048576)!==0)}if(n&1<<28){const o=t.u32(),u=t.u32(),h=(b,$,y,F)=>{f($)||(r[b]={style:y,color:this.color(F)})};h("left",10,o&15,o>>16&127),h("right",11,o>>4&15,o>>23&127),h("top",12,o>>8&15,u&127),h("bottom",13,o>>12&15,u>>7&127),(!f(14)||!f(15))&&(m={diagonalDown:!f(14)&&(o&1073741824)!==0,diagonalUp:!f(15)&&(o&2147483648)!==0},r.diagonal={style:u>>21&15,color:this.color(u>>14&127)})}if(n&1<<29){const o=t.u16(),u=t.u16();f(16)||(c.pattern=o>>10),f(17)||(c.fg=this.color(u&127)),f(18)||(c.bg=this.color(u>>7&127))}if(n&1<<30){const o=t.u16();f(8)||(x.locked=o&1?"1":"0"),f(9)||(x.hidden=o&2?"1":"0")}let L="";if(e-t.pos>=8){t.skip(6);const o=z(t,t.u16());o.fg!==void 0&&(c.fg=o.fg),o.bg!==void 0&&(c.bg=o.bg),o.text!==void 0&&(s.color=o.text),o.gradient&&(L=o.gradient);for(const u of["left","right","top","bottom","diagonal"])o[u]!==void 0&&r[u]&&(r[u].color=o[u])}let k=L;!k&&(c.pattern!==void 0||c.fg!==void 0||c.bg!==void 0)&&(k=`<fill><patternFill${(c.pattern===void 0||c.pattern===1)&&c.bg!==void 0||c.pattern===void 0?"":` patternType="${_[c.pattern]??"solid"}"`}>${X("fgColor",c.fg)}${X("bgColor",c.bg)}</patternFill></fill>`);const M=w(s),P=["left","right","top","bottom","diagonal"].map(o=>r[o]?D(o,r[o].style,r[o].color):"").join("");return(M?`<font>${M}</font>`:"")+a+k+A(d)+(P||m.diagonalUp||m.diagonalDown?`<border${p(m)}>${P}</border>`:"")+(Object.keys(x).length?`<protection${p(x)}/>`:"")}formatId(t){for(const[n,l]of this.formats)if(l===t)return n;let e=164;for(;this.formats.has(e);)e++;return this.formats.set(e,t),e}}const W=Uint16Array.from({length:256},(i,t)=>{let e=t<<24;for(let n=0;n<8;n++)e=e&2147483648?e<<1^175:e<<1;return e&65535});function Z(i,t){let e=i;for(let n=t.pos;n<t.end;n++)e=(e<<8^W[e>>>24^t.buf[n]])>>>0;return e}const tt={1:"0",2:"0.00",3:"#,##0",4:"#,##0.00",9:"0%",10:"0.00%",11:"0.00E+00",12:"# ?/?",13:"# ??/??",14:"mm-dd-yy",15:"d-mmm-yy",16:"d-mmm",17:"mmm-yy",18:"h:mm AM/PM",19:"h:mm:ss AM/PM",20:"h:mm",21:"h:mm:ss",22:"m/d/yy h:mm",45:"mm:ss",46:"[h]:mm:ss",47:"mmss.0",48:"##0.0E+0",49:"@"};function z(i,t){const e={};for(let n=0;n<t&&i.left>=4;n++){const l=i.pos,f=i.u16(),s=i.u16();if(s<4)break;const a=Math.min(l+s,i.end),d={4:"fg",5:"bg",7:"top",8:"bottom",9:"left",10:"right",11:"diagonal",13:"text"}[f];if(d){const r=Q(i);r&&(e[d]=r)}else f===6?e.gradient=et(i,a):f===14?e.scheme=s>=6?i.u16():i.u8():f===15&&(e.indent=i.u16());i.pos=a}return e}function et(i,t){const e={type:i.u32(),degree:i.f64(),left:i.f64(),right:i.f64(),top:i.f64(),bottom:i.f64()},n=[];for(let l=i.u32();l>0&&i.pos+22<=t;l--){const f=i.u16(),s=i.u32(),a=i.f64(),d=i.f64();n.push(J(a,S(f,d,s)))}return n.length?V(e,n):void 0}export{H as BORDER_STYLES,at as Styles,ft as cfColor,S as extColor};
package/io/xls/vba.js ADDED
@@ -0,0 +1 @@
1
+ import{buildCfb as p}from"../crypto/cfb-build.js";const h="application/vnd.ms-office.vbaProject",l="http://schemas.microsoft.com/office/2006/relationships/vbaProject";async function m(e,r,i){const s=e.find("_VBA_PROJECT_CUR");if(!s)return!1;const o=[],c=async(t,f)=>{for(const a of e.childrenOf(t)){const n=[...f,a.name];a.type===1?await c(a,n):a.type===2&&o.push({path:n,bytes:await e.read(a)})}};return await c(s,[]),o.some(t=>t.path.length===2&&t.path[0].toUpperCase()==="VBA"&&t.path[1].toUpperCase()==="DIR")?(r.rel(i,l,"xl/vbaProject.bin"),await r.add("xl/vbaProject.bin",h,p(o)),!0):!1}export{m as vbaProject};
@@ -0,0 +1 @@
1
+ import{escapeMarkup as I,xmlText as z}from"../xml-escape.js";import{colName as _,quoteSheetName as D}from"../../core/address.js";import{attrs as x,NS_MAIN as T,NS_R as L,XML_HEAD as R}from"../xlsb/xml.js";import{numberText as O}from"../xlsb/records.js";import{ERROR_TEXT as P}from"../xlsb/formula.js";import{CONTINUE as j,eachRecord as B,XlsReader as F}from"./records.js";import{constant as M,readFormula as W}from"./formula.js";import{cipherOf as X}from"./crypt.js";const $=s=>s?s.toString(16).toUpperCase().padStart(4,"0"):void 0,v=["Consolidate_Area","Auto_Open","Auto_Close","Extract","Database","Criteria","Print_Area","Print_Titles","Recorder","Data_Form","Auto_Activate","Auto_Deactivate","Sheet_Title","_FilterDatabase"];function C(){return Object.assign(new Error("This workbook was made by Excel 95 or an older version. Save it as .xlsx in Excel to open it here."),{code:"old-xls"})}const ie={WORK:0,MACRO:1,CHART:2,MODULE:6};async function re(s,e,r,o,i){const a={sheets:[],names:[],links:[],xti:[],tables:new Map,views:[],calc:"",protection:null,sharing:null,props:"",pivotStreams:[],drawing:[],cipher:null,password:null,theme:null,themeVersion:0,date1904:!1,codeName:void 0},n={saveLinks:!0,hideBorders:!1,precise:!0,calcId:0,protect:0,windows:0,password:0,revisions:0,revisionLock:0};let l=!0,h=null,k=null,w=0,p=null;if(await B(s,0,a,(d,t,S)=>{if(l){if(l=!1,d!==2057||t.left<4||t.u16()!==1536)throw C();return!0}if(d===j)return w===252?r(t,!1):w===235&&a.drawing.push({at:S,size:t.left}),!0;switch(w=d,d){case 10:return!1;case 47:H(a,t,o);break;case 133:{const c=t.u32(),m=t.u8()&3,f=t.u8();a.sheets.push({start:c,state:m>2?0:m,kind:f,name:t.short(),sheetId:a.sheets.length+1,rid:null});break}case 49:e.readFont(t);break;case 1054:e.readFormat(t);break;case 224:e.readXf(t);break;case 2172:e.readXfCheck(t);break;case 2173:e.readXfExt(t);break;case 659:e.readStyle(t);break;case 2194:e.readStyleExt(t);break;case 146:e.readPalette(t);break;case 252:r(t,!0);break;case 235:a.drawing.push({at:S,size:t.left});break;case 34:a.date1904=t.u16()===1;break;case 14:n.precise=t.u16()!==0;break;case 218:{const c=t.u16();n.saveLinks=(c&1)===0,n.hideBorders=(c&256)!==0;break}case 18:n.protect=t.u16();break;case 25:n.windows=t.u16();break;case 19:n.password=t.u16();break;case 431:n.revisionLock=t.u16();break;case 444:n.revisions=t.u16();break;case 449:t.skip(4),n.calcId=t.u32();break;case 442:a.codeName=t.str()||void 0;break;case 91:{const c=t.u16(),m=t.u16(),f=t.u16();a.sharing=x({readOnlyRecommended:c!==0,userName:f&&t.left>0?t.text(f):void 0,reservationPassword:$(m)})||null;break}case 61:{const c=t.i16(),m=t.i16(),f=t.u16(),b=t.u16(),u=t.u16(),E=t.u16(),A=t.u16();t.skip(2);const N=t.u16();a.views.push(x({visibility:u&4?"veryHidden":u&1?"hidden":void 0,minimized:(u&2)!==0,showHorizontalScroll:u&8?void 0:"0",showVerticalScroll:u&16?void 0:"0",showSheetTabs:u&32?void 0:"0",autoFilterDateGrouping:u&64?"0":void 0,xWindow:c,yWindow:m,windowWidth:f,windowHeight:b,tabRatio:N===600?void 0:N})),a.views.length===1&&Object.assign(a,{activeTab:E,firstTab:A});break}case 430:h=U(a,t);break;case 35:h&&G(h,t);break;case 89:{t.skip(2);const c=t.u16();k=null,h?.kind==="book"&&h.cells.set(c,k=[]);break}case 90:{const c=t.u8(),m=t.u8(),f=t.u16();if(!k)break;const b=[];for(let u=m;u<=c&&t.left>0;u++)b.push(K(f,u,M(t)));k.push(`<row r="${f+1}">${b.join("")}</row>`);break}case 23:for(let c=t.u16();c>0&&t.left>=6;c--)a.xti.push({link:t.u16(),first:t.i16(),last:t.i16()});break;case 24:a.names.push(y(t));break;case 2196:{t.skip(12);const c=t.u16(),m=t.u16(),f=t.text(c),b=a.names.find(u=>u.name.toLowerCase()===f.toLowerCase()||u.name.toLowerCase()===`_xlnm.${f}`.toLowerCase());b&&m&&(b.comment=t.text(m));break}case 213:a.pivotStreams.push({id:t.u16(),kind:0,source:null,ranges:[]});break;case 227:a.pivotStreams.length&&(a.pivotStreams.at(-1).kind=t.u16());break;case 81:case 437:case 440:a.pivotStreams.length&&(a.pivotStreams.at(-1).source??=J(d,t));break;case 2198:{t.skip(12),a.themeVersion=t.u32(),p=[t.buf.slice(t.pos,t.end)],a.theme=p;break}case 2175:case 2165:case 2066:p&&(t.skip(12),p.push(t.buf.slice(t.pos,t.end)));break;default:}return d!==2198&&d!==2175&&d!==2165&&d!==2066&&(p=null),!0},i),l)throw C();return a.props=x({date1904:a.date1904,saveExternalLinkValues:n.saveLinks?void 0:"0",showBorderUnselectedTables:n.hideBorders?"0":void 0,codeName:a.codeName}),(n.protect||n.windows||n.revisionLock)&&(a.protection=x({workbookPassword:$(n.password),revisionsPassword:$(n.revisions),lockStructure:n.protect!==0,lockWindows:n.windows!==0,lockRevision:n.revisionLock!==0})),a.calcBase={calcId:n.calcId||void 0,fullPrecision:n.precise?void 0:"0"},a}function H(s,e,r){const o=e.pos;let i=null;for(const a of r){e.pos=o;try{s.cipher=X(e,a),s.password=a;return}catch(n){i=n}}throw i}function V(s){let e=s;return e.startsWith("")&&(e=e.slice(1),e[0]===""?e=`${e[1]==="@"?"\\\\":`${e[1]}:\\`}${e.slice(2)}`:e[0]===""?e=`\\${e.slice(1)}`:e[0]===""?e=e.slice(2):(e[0]===""||e[0]==="\x07"||e[0]==="\b")&&(e=e.slice(1)),e=e.replace(/\u0004/g,"..\\").replace(/\u0003/g,"\\")),/[\u0000-\u001f]/.test(e)?null:/^(?:[a-z]:\\|\\\\)/i.test(e)?`file:///${e}`:/^https?:/i.test(e)?e:e.replace(/\\/g,"/")}function U(s,e){const r=e.u16(),o=e.u16();let i;if(o===1025)i={kind:"self"};else if(o===14849)i={kind:"addin",names:[]};else{const a=e.text(o),n=V(a);i={kind:"book",target:n,index:0,sheets:[],names:[],local:[],refs:[],cells:new Map,missing:n===null||n===""},a.includes("")&&!a.startsWith("")&&(i.missing=!0);for(let l=0;l<r&&e.left>2;l++)i.sheets.push(e.str())}return s.links.push(i),i}function G(s,e){const r=e.u16();if(s.kind==="addin"){e.skip(4),s.names.push(e.short());return}if(s.kind!=="book")return;if(r&24){s.missing=!0;return}const o=e.u16();e.skip(2);const i=e.text(e.u8());s.names.push(r&1?`_xlnm.${v[i.charCodeAt(0)]??i}`:i),s.local.push(o),s.refs.push(e.left>=2?q(e,e.u16(),s.sheets):void 0)}function q(s,e,r){if(e<9)return;const o=s.u8();if(o!==58&&o!==59)return;const i=s.i16(),a=s.i16();if(i<0||r[i]===void 0)return;const n=D(r[i],{last:a>i&&r[a]!==void 0?r[a]:null}),l=(d,t)=>`$${_(t&255)}$${d+1}`;if(o===58){const d=s.u16();return`=${n}!${l(d,s.u16())}`}const[h,k,w,p]=[s.u16(),s.u16(),s.u16(),s.u16()];return`=${n}!${l(h,w)}:${l(k,p)}`}function K(s,e,[r,o]){const i=`${_(e)}${s+1}`;return r==="number"?`<cell r="${i}"><v>${O(o)}</v></cell>`:r==="bool"?`<cell r="${i}" t="b"><v>${o?1:0}</v></cell>`:r==="error"?`<cell r="${i}" t="e"><v>${P[o]??"#N/A"}</v></cell>`:r==="text"&&o!==""?`<cell r="${i}" t="str"><v>${z(o)}</v></cell>`:""}function ce(s){const e=s.names.map((o,i)=>`<definedName${x({name:o,refersTo:s.refs[i],sheetId:s.local[i]?s.local[i]-1:void 0})}/>`),r=[...s.cells].filter(([o,i])=>i.length&&o<s.sheets.length).map(([o,i])=>`<sheetData sheetId="${o}">${i.join("")}</sheetData>`);return`${R}<externalLink xmlns="${T}"><externalBook xmlns:r="${L}" r:id="rId1">`+(s.sheets.length?`<sheetNames>${s.sheets.map(o=>`<sheetName${x({val:o})}/>`).join("")}</sheetNames>`:"")+(e.length?`<definedNames>${e.join("")}</definedNames>`:"")+(r.length?`<sheetDataSet>${r.join("")}</sheetDataSet>`:"")+"</externalBook></externalLink>"}function y(s){const e=s.u16();s.skip(1);const r=s.u8(),o=s.u16();s.skip(2);const i=s.u16();s.skip(4);const a=s.text(r),l=(e&32)!==0?`_xlnm.${v[a.charCodeAt(0)]??a}`:a;return{name:l,itab:i?i-1:void 0,hidden:(e&1)!==0,func:(e&2)!==0,vba:(e&4)!==0,macro:(e&8)!==0,future:/^_xl(?:fn|pm|ws|eta|udf)\./i.test(l),comment:null,bytes:s.buf.slice(s.pos,s.end),size:o}}function ue(s,e){let r=!0;for(;r;){r=!1;for(const o of s.names)if(!(o.future||o.lost)){if(o.size===0){o.lost=!0,o.procedure=!0;continue}try{o.text=W(new F(o.bytes),o.size,s,{row:0,col:0,inName:!0})}catch{o.lost=!0,r=!0,e(o.name)}}}for(const o of s.names)o.bytes=null}function J(s,e){const r=s===81?e.smallRange():null;if(s===440){const i=e.u8();return e.skip(3),{name:`_xlnm.${v[i]??""}`,file:g(e)}}return r?{range:r,file:g(e)}:{name:e.str(),file:g(e)}}function g(s){if(s.left<2)return"";const e=s.u16();return e?s.text(e):""}const Q=[void 0,"hidden","veryHidden"];function le(s,{views:e,links:r,calc:o,caches:i}){const a=s.names.filter(n=>!n.future&&!n.lost&&n.text!==void 0).map(n=>`<definedName${x({name:n.name,comment:n.comment||void 0,function:n.func,vbProcedure:n.vba,xlm:n.macro&&!n.func&&!n.vba?!0:void 0,localSheetId:n.itab,hidden:n.hidden})}>${I(n.text)}</definedName>`);return`${R}<workbook xmlns="${T}" xmlns:r="${L}">`+(s.sharing?`<fileSharing${s.sharing}/>`:"")+(s.props?`<workbookPr${s.props}/>`:"")+(s.protection?`<workbookProtection${s.protection}/>`:"")+(e?`<bookViews>${e}</bookViews>`:"")+`<sheets>${s.sheets.map(n=>`<sheet${x({name:n.name,sheetId:n.sheetId,state:Q[n.state],"r:id":n.rid})}/>`).join("")}</sheets>`+(r.length?`<externalReferences>${r.map(n=>`<externalReference r:id="${n}"/>`).join("")}</externalReferences>`:"")+(a.length?`<definedNames>${a.join("")}</definedNames>`:"")+`<calcPr${o??""}/>`+(i?`<pivotCaches>${i}</pivotCaches>`:"")+"</workbook>"}export{ie as SHEET,ce as externalLinkXml,$ as hex4,C as oldWorkbook,re as readGlobals,ue as readNames,le as workbookXml};
@@ -0,0 +1 @@
1
+ import{attrs as a,fullRangeText as k}from"./xml.js";import{numberText as h}from"./records.js";const y={1:"lessThan",2:void 0,3:"lessThanOrEqual",4:"greaterThan",5:"notEqual",6:"greaterThanOrEqual"},M=["null","aboveAverage","belowAverage",,,,,,"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"],p=["year","month","day","hour","minute","second"],T=["3Arrows","3ArrowsGray","3Flags","3TrafficLights1","3TrafficLights2","3Signs","3Symbols","3Symbols2","4Arrows","4ArrowsGray","4RedToBlack","4Rating","4TrafficLights","5Arrows","5ArrowsGray","5Rating","5Quarters"],A=[void 0,"cellColor","fontColor","icon"],g=(c,r)=>({iconSet:c===4294967295?"NoIcons":T[c],iconId:r===4294967295?void 0:r});function w(){let c="",r=[],d=null,o="",x=!1,u=null,f=null;const m={xml:null,sortXml:null,record(b,e){switch(b){case 161:c=` ref="${k(e.range())}"`,r=[],x=!0;break;case 162:x=!1,m.xml={open:c,columns:r.join("")};break;case 163:{const t=e.u32(),n=e.u16();d=a({colId:t,hiddenButton:(n&1)!==0,showButton:n&2?"0":void 0}),o="";break}case 164:d!==null&&r.push(o?`<filterColumn${d}>${o}</filterColumn>`:`<filterColumn${d}/>`),d=null;break;case 165:o+=`<filters${a({blank:e.u32()!==0})}>`;break;case 166:o+="</filters>";break;case 167:o+=`<filter${a({val:e.str()})}/>`;break;case 168:{const t=e.u32(),n=e.u32();o+=`<colorFilter${a({dxfId:t===4294967295?void 0:t,cellColor:n?void 0:"0"})}/>`;break}case 169:{const t=e.u32();o+=`<iconFilter${a(g(t,e.u32()))}/>`;break}case 170:{const t=e.u8(),n=e.f64(),l=e.f64();o+=`<top10${a({top:t&1?void 0:"0",percent:(t&2)!==0,val:h(n),filterVal:t&4?h(l):void 0})}/>`;break}case 171:{const t=e.u32(),n=e.u8(),l=e.f64(),s=e.f64();o+=`<dynamicFilter${a({type:M[t]??"null",val:n&1?h(l):void 0,maxVal:n&1&&s?h(s):void 0})}/>`;break}case 172:f={and:e.u32()===0,items:[]};break;case 173:o+=`<customFilters${a({and:f.and&&f.items.length>1})}>${f.items.join("")}</customFilters>`,f=null;break;case 174:{const t=e.u8(),n=e.u8(),l=e.f64();let s=" ",i=y[n];t===4?s=h(l):t===6?s=e.str():t===8?s=l?"1":"0":t===14&&(i="notEqual"),f?.items.push(`<customFilter${a({operator:i,val:s})}/>`);break}case 175:{const t={year:e.u16(),month:e.u16(),day:e.u32(),hour:e.u16(),minute:e.u16(),second:e.u16()};e.skip(6);const n=e.u32(),l={};p.forEach((s,i)=>{i<=n&&(l[s]=t[s])}),o+=`<dateGroupItem${a({...l,dateTimeGrouping:p[n]??"year"})}/>`;break}case 530:{const t=e.u16();u={open:a({columnSort:(t&1)!==0,caseSensitive:(t&2)!==0,sortMethod:t&4?"stroke":void 0,ref:k(e.range())}),items:[]};break}case 531:{const t=u?`<sortState${u.open}>${u.items.join("")}</sortState>`:"";x?r.push(t):m.sortXml=t,u=null;break}case 532:{const t=e.u16(),n=t>>1&15,l=k(e.range()),s=e.u32(),i=e.u32(),$=e.left>=4?e.nstr():null;u?.items.push(`<sortCondition${a({descending:(t&1)!==0,sortBy:A[n],ref:l,customList:$||void 0,dxfId:(n===1||n===2)&&s!==4294967295?s:void 0,...n===3?g(s,i):{}})}/>`);break}case 533:break;default:return!1}return!0},text(){if(!m.xml)return"";const{open:b,columns:e}=m.xml;return e?`<autoFilter${b}>${e}</autoFilter>`:`<autoFilter${b}/>`}};return m}export{p as DATE_PARTS,M as DYNAMIC,T as ICON_SETS,y as OPERATORS,A as SORT_ON,w as filterReader,g as iconAttrs};
@@ -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};