@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
@@ -1,3 +1,3 @@
1
- import{hasCellTypes as q}from"../core/cell-type-rules.js";import{hasConditionalFormats as ct}from"../core/host-rules.js";import{readingDirection as at,visualOrder as ht,wrapsByAlign as dt}from"../cells/text-layout.js";import{gradientPatches as j}from"../cells/paint.js";import{paintWatermarks as ut}from"../shapes/watermark.js";import{BOOL as mt,CHUNK_BITS as Q,CHUNK_MASK as W,EMPTY as X,ERR as tt,ERRORS as gt,KIND_MASK as $,NUM as L,STR as v,FORMULA as et,SPILL as nt}from"../core/sheet.js";import{isBarcodeText as pt,paintBarcodeValue as bt}from"../celltypes/barcode.js";import{printCellType as ot,printEmptyTypedCells as kt}from"../celltypes/cell-types.js";import{FILL_MARK as it,fitGeneral as wt,formatGeneral as yt,getFormatter as K}from"../core/numfmt.js";import{colName as Tt}from"../core/address.js";import{cssFont as E}from"../core/styles.js";import{CondFormats as xt}from"../core/cond-format.js";import{drawCfIcon as St,iconSide as Dt,monoContext as Ot,paintCfBar as At}from"../cells/cf-paint.js";import{sparklineIndex as Pt}from"../core/sparklines.js";import{paintSparkline as Rt}from"../sparklines/excel-paint.js";import{isSparklineText as Ft,paintSparklineValue as Ct}from"../sparklines/paint.js";import{paintSparkRulesOnPage as Mt,sparkRuleHidesValue as It}from"../sparklines/rule.js";import{preparePicturesForPrint as zt}from"../sparklines/print.js";import{tableColors as Nt,tablesOf as vt}from"../core/tables.js";import{paintCustomTable as Ht}from"../slicers/custom-styles.js";import{resolveColor as Lt}from"../io/xlsx-styles.js";import{parseHeaderFooter as Wt}from"./page-setup.js";import{linkRegion as Et}from"./pdf-links.js";import{paintNotePage as Bt}from"./note-pages.js";const _t=2,Gt=6,Xt=32,U="#000000",Y=.25,V=10,$t={hair:.25,thin:.5,dotted:.5,dashed:.5,dashDot:.5,dashDotDot:.5,medium:1,mediumDashed:1,mediumDashDot:1,mediumDashDotDot:1,slantDashDot:1,thick:1.5,double:.5},Kt={hair:[.5,.75],dotted:[.5,1.5],dashed:[3,1.5],dashDot:[3,1.5,.75,1.5],dashDotDot:[3,1.5,.75,1.5,.75,1.5],mediumDashed:[4,2],mediumDashDot:[4,2,1,2],mediumDashDotDot:[4,2,1,2,1,2],slantDashDot:[4,1,1,1]},st=new WeakMap;function J(t){let s=st.get(t);return s===void 0&&(s=E(t,t.fontSize),st.set(t,s)),s}function Ut(t,s,f,i){switch(s){case L:return i.numFmt==="General"?yt(f):K(i.numFmt).number(f,t.dateOffset);case v:{const b=t.strings.get(f);return i.numFmt==="General"||i.numFmt==="@"?b:K(i.numFmt).text(b)}case mt:return f?"TRUE":"FALSE";case tt:return gt[f]??"#N/A";default:return""}}class Yt{constructor(s,f,i,b){this.ctx=s,this.book=f,this.sheet=i,this.styles=f.styles.list,this.mono=b.blackAndWhite,this.errors=b.errors,this.cfFrame=null,this.tables=null,this.font="",this.ink="",this.wrapCache=new Map,this.reachX=null}style(s,f){return this.styles[this.sheet.style(s,f)]??this.styles[0]}textStyle(s,f,i,b,o){let e=this.style(s,f);const r=this.cfFrame===null?void 0:this.cfFrame.get(s*16384+f);if(r!==void 0){if(r.icon&&this.icon(r.icon,i,b,o,e),r.hideValue)return null;(r.color||r.numFmt!==void 0||r.bold!==void 0||r.italic!==void 0||r.underline!==void 0||r.strike!==void 0)&&(e={...e,color:r.color??e.color,numFmt:r.numFmt??e.numFmt,bold:r.bold??e.bold,italic:r.italic??e.italic,underline:r.underline??e.underline,strike:r.strike??e.strike})}if(this.tables!==null)for(const h of this.tables){if(s<h.r0||s>h.r1||f<h.c0||f>h.c1||!h._colors)continue;const d=h._colors.format(h,s,f);e={...e,color:e.color??d.color,bold:e.bold||d.bold===!0,italic:e.italic||d.italic===!0},d.underline&&!e.underline&&(e.underline=d.underline),d.strike&&(e.strike=!0);break}return e}icon(s,f,i,b,o){const e=Dt(b,1,o.fontSize),r=o.vAlign==="top"?i+1:o.vAlign==="center"?i+(b-e)/2:i+b-e-1;St(this.mono?Ot(this.ctx):this.ctx,s.name,s.level,f+1,r,e),this.ink=""}setFont(s){this.font!==s&&(this.ctx.font=s,this.font=s)}setInk(s){this.ink!==s&&(this.ctx.fillStyle=s,this.ink=s)}reset(){this.font="",this.ink=""}width(s){return this.ctx.measureText(s).width}richLine(s,f,i,b,o,e,r,h,d){const{ctx:x}=this,a=[];let k=0,u=0;f.forEach((T,D)=>{const w=f[D+1]?.at??s.length;if(w<=T.at)return;const S={...i,fontName:T.name??i.fontName,fontSize:T.sz??i.fontSize,bold:T.b??i.bold,italic:T.i??i.italic},P=J(S);this.setFont(P);const z=s.slice(T.at,w).replace(/\n/g," "),F=x.measureText(z).width;a.push({piece:z,font:P,ink:T.color??i.color??"#000000",pw:F}),k+=F,u=Math.max(u,S.fontSize)});const p=i.vAlign??"bottom",M=p==="top"?e+u*1.05:p==="center"?e+(h+u*.72)/2:e+h-3;let I=b==="right"?o+r-d-k:b==="center"||b==="centerContinuous"?o+(r-k)/2:o+d;x.textAlign="left";for(const T of a)this.setFont(T.font),this.setInk(T.ink),x.fillText(T.piece,I,M),I+=T.pw}text(s,f,i,b,o,e,r,h,d,x=!1){const{ctx:a,sheet:k}=this,u=this.reachX===null?this.textStyle(s,f,o,e,h):this.style(s,f);if(u===null)return;if(q(k)&&this.reachX===null&&ot(a,this.book,k,s,f,o,e,r,h)){this.reset();return}if(i===L&&b===0&&k.hideZeros)return;if(u.ext?.pad){const[c,y,R,N]=u.ext.pad;o+=N,e+=c,r=Math.max(0,r-N-y),h=Math.max(0,h-c-R)}let p=Ut(this.book,i,b,u);if(i===tt&&this.errors!=="displayed"&&(p=this.errors==="blank"?"":this.errors==="dash"?"--":"#N/A"),p===""||i===v&&pt(p)&&(k.kind(s,f)&(et|nt))!==0&&bt(a,p,o,e,r,h,1)||i===v&&Ft(p)&&(k.kind(s,f)&(et|nt))!==0&&Ct(a,p,o,e,r,h,1,{ink:u.color??"#000000",snap:!1,mono:this.mono})||k.sparkRules!==null&&It(k,s,f))return;const M=J(u);this.setFont(M);let I=u.color??"#000000";i===L&&u.numFmt!=="General"&&(I=K(u.numFmt).color(b)??I),this.setInk(this.mono?"#000000":I);const T=_t,D=i===v?at(u.readingOrder,p):null;i===v&&!("direction"in a)&&(p=ht(p,D==="rtl")),D==="rtl"&&"direction"in a?(a.direction="rtl",this.pendingDirection=!0):this.pendingDirection&&(a.direction="ltr",this.pendingDirection=!1);const w=u.hAlign??(i===L||D==="rtl"?"right":i===v?"left":"center");if(w==="centerContinuous")for(let c=f+1;(k.kind(s,c)&15)===0&&k.mergeAt(s,c)===null&&this.book.styles.get(k.style(s,c)).hAlign==="centerContinuous";c++)r+=k.cols.sizeOf(c);const S=r-T*2,P=u.fontSize;if(this.reachX!==null&&(u.rotation!==0||u.wrap))return;if(u.rotation!==0){this.rotated(p,u,o,e,r,h);return}if(u.wrap||dt(u)){this.wrapped(p,u,w,o,e,r,h,T,P);return}const z=i===v?this.book.strings.rich?.get(b):void 0;if(z!==void 0&&!this.mono){this.richLine(p,z,u,w,o,e,r,h,T);return}const F=u.vAlign??"bottom";let A;if(F==="top"?A=e+P*1.05:F==="center"?A=e+(h+P*.72)/2:A=e+h-3,p.indexOf(it)>=0){if(this.reachX!==null)return;const c=p.split(it),y=c[0],R=c[1]??" ",N=c.slice(2).join("");a.textAlign="left",y&&a.fillText(y,o+T,A);const H=this.width(y),_=this.width(N);if(R!==" "){const G=this.width(R)||1,Z=Math.floor((S-H-_)/G);Z>0&&a.fillText(R.repeat(Z),o+T+H,A)}a.textAlign="right",N&&a.fillText(N,o+r-T,A),a.textAlign="left";return}let O=this.width(p);if(O>S&&i===L&&(u.numFmt==="General"&&(p=wt(b,c=>this.width(c)<=S),O=this.width(p)),O>S)){const c=this.width("#")||1;p="#".repeat(Math.max(1,Math.floor(S/c))),O=c*p.length}let C=!1;if(u.shrink&&O>S&&S>0&&(this.setFont(E(u,P*(S/O))),O=S,C=!0),u.indent>0){const c=u.indent*Gt;w==="left"?(o+=c,r-=c):w==="right"&&(r-=c)}let n,l=!1,m=o,g=o+r;if(w==="center"||w==="centerContinuous")n=o+(r-O)/2;else if(w==="right")n=o+r-T-O;else if(w==="fill"){const c=Math.max(1,Math.floor(S/(O||1)));p=p.repeat(c),O*=c,n=o+T}else n=o+T;if(this.reachX!==null&&n+O<=this.reachX){C&&this.setFont(M);return}if(O>S||n<o+T)if(x)l=!0;else if(i===v){if(n+O>g){let c=f+1,y=g;for(;y<n+O&&c<=d.c1&&(k.kind(s,c)&15)===0&&k.mergeAt(s,c)===null;)y+=k.cols.sizeOf(c),c++;g=y}if(n<m){let c=f-1,y=m;for(;y>n&&c>=d.c0&&(k.kind(s,c)&15)===0&&k.mergeAt(s,c)===null;)y-=k.cols.sizeOf(c),c--;m=y}l=n+O>g||n<m}else l=!0;a.textAlign="left",l?(a.save(),a.beginPath(),a.rect(m,e,g-m,h),a.clip(),a.fillText(p,n,A),this.decorate(u,n,A,O,P),a.restore()):(a.fillText(p,n,A),(u.underline!==0||u.strike)&&this.decorate(u,n,A,O,P)),C&&this.setFont(M)}decorate(s,f,i,b,o){const{ctx:e}=this,r=Math.max(.5,o/14);if(s.underline!==0){const h=i+o*.14;e.fillRect(f,h,b,r),s.underline===2&&e.fillRect(f,h+r*2,b,r)}s.strike&&e.fillRect(f,i-o*.3,b,r)}wrapLines(s,f,i){const b=`${s}|${Math.round(i)}|${f}`;let o=this.wrapCache.get(b);if(o!==void 0)return o;o=[];for(const e of f.split(`
2
- `)){let r="";for(const h of e.split(/(?<=\s)/)){const d=r+h;for(r!==""&&this.width(d.trimEnd())>i?(o.push(r.trimEnd()),r=h):r=d;this.width(r.trimEnd())>i&&r.length>1;){let x=r.length-1;for(;x>1&&this.width(r.slice(0,x))>i;)x--;o.push(r.slice(0,x)),r=r.slice(x)}}o.push(r.trimEnd())}return this.wrapCache.size>4096&&this.wrapCache.clear(),this.wrapCache.set(b,o),o}wrapped(s,f,i,b,o,e,r,h,d){const{ctx:x}=this,a=this.wrapLines(J(f),s,e-h*2),k=Math.round(d*1.26),u=a.length*k,p=f.vAlign??"bottom";let M;p==="top"?M=o:p==="center"?M=o+(r-u)/2:M=o+r-u,x.save(),x.beginPath(),x.rect(b,o,e,r),x.clip(),x.textAlign=i==="center"?"center":i==="right"?"right":"left";const I=i==="center"?b+e/2:i==="right"?b+e-h:b+h;for(let T=0;T<a.length;T++){const D=M+T*k+Math.round(k*.8);D+k<o||D-k>o+r||x.fillText(a[T],I,D)}x.restore(),x.textAlign="left"}rotated(s,f,i,b,o,e){const{ctx:r}=this;r.save(),r.beginPath(),r.rect(i,b,o,e),r.clip(),r.translate(i+o/2,b+e/2);const h=f.rotation;if(r.textAlign="center",h===255){const d=f.fontSize*1.1,x=-((s.length-1)*d)/2;for(let a=0;a<s.length;a++)r.fillText(s[a],0,x+a*d)}else{const d=h>90?90-h:h;r.rotate(-d*Math.PI/180),r.fillText(s,0,f.fontSize*.35)}r.restore(),r.textAlign="left"}side(s,f,i,b,o){if(!s)return;const{ctx:e}=this,r=$t[s.style]??.5;if(e.strokeStyle=this.mono?"#000000":s.color??"#000000",e.lineWidth=r,e.setLineDash(Kt[s.style]??[]),e.beginPath(),s.style==="double"){const h=i===o?0:.75,d=i===o?.75:0;e.moveTo(f-h,i-d),e.lineTo(b-h,o-d),e.moveTo(f+h,i+d),e.lineTo(b+h,o+d)}else e.moveTo(f,i),e.lineTo(b,o);e.stroke()}}function rt(t,s,f){const i=new Float64Array(f-s+2);let b=0;for(let o=s;o<=f;o++)i[o-s]=b,b+=t.sizeOf(o);return i[f-s+1]=b,i}function Vt(t,s,f,i,b){const{ctx:o,sheet:e}=t,{x:r,y:h,r0:d,r1:x,c0:a,c1:k}=s,u=rt(e.cols,a,k),p=rt(e.rows,d,x),M=k-a+1,I=x-d+1,T=u[M],D=p[I];if(T<=0||D<=0)return;if(o.save(),o.beginPath(),o.rect(r,h,T,D),o.clip(),t.reset(),f){o.strokeStyle=U,o.lineWidth=Y,o.setLineDash([]),o.beginPath();for(let n=0;n<=M;n++)n>0&&u[n]===u[n-1]||(o.moveTo(r+u[n],h),o.lineTo(r+u[n],h+D));for(let n=0;n<=I;n++)n>0&&p[n]===p[n-1]||(o.moveTo(r,h+p[n]),o.lineTo(r+T,h+p[n]));o.stroke()}const w=e.mergesInRows(d,x).filter(n=>n.c1>=a&&n.c0<=k),S=w.length>0,P=e.rowStyles!==null||e.colStyles!==null,z=t.styles[0].fill===null&&t.styles[0].borders===null;t.tables=null;const{book:F}=t;if(F.engine&&F.engine.tables.size>0){const n=vt(F,e);n.length>0&&(t.tables=n);for(const l of n){if(l.r1<d||l.r0>x||l.c1<a||l.c0>k)continue;const m=Nt(l.styleName,F.theme);m&&(l._colors=m,Ht(o,l,m,{ra:d,rb:x,ca:a,cb:k,xs:u,ys:p,ox:r,oy:h,line:.5,noFill:t.mono,setInk:g=>t.setInk(t.mono?"#000000":g)}))}}let A=null;for(let n=a;n<=k;n++){const l=u[n-a+1]-u[n-a];if(l===0)continue;const m=e.columns[n];if(!(m===void 0&&!P&&z))for(let g=d;g<=x;g++){if(!P&&z){const R=m[g>>>Q];if(R===void 0||R.styles===null){g|=W;continue}if(R.styles[g&W]===0)continue}const c=p[g-d+1]-p[g-d];if(c===0)continue;const y=t.style(g,n);y.fill===null&&y.borders===null||S&&e.mergeAt(g,n)!==null||(y.fill!==null&&!t.mono&&(y.gradient?j(y.gradient,r+u[n-a],h+p[g-d],l,c,(R,N,H,_,G)=>{t.setInk(R),o.fillRect(N,H,_,G)}):(t.setInk(ft(y)),o.fillRect(r+u[n-a],h+p[g-d],l,c))),y.borders!==null&&(A??=[]).push(g,n,y.borders))}}const O=n=>{const l=r+e.cols.offsetOf(n.c0)-e.cols.offsetOf(a),m=h+e.rows.offsetOf(n.r0)-e.rows.offsetOf(d);return{x:l,y:m,w:e.cols.offsetOf(n.c1+1)-e.cols.offsetOf(n.c0),h:e.rows.offsetOf(n.r1+1)-e.rows.offsetOf(n.r0)}};for(const n of w){const l=O(n),m=t.style(n.r0,n.c0);(f||m.fill!==null&&!t.mono)&&(m.gradient&&!t.mono?j(m.gradient,l.x,l.y,l.w,l.h,(g,c,y,R,N)=>{t.setInk(g),o.fillRect(c,y,R,N)}):(t.setInk(m.fill!==null&&!t.mono?ft(m):"#ffffff"),o.fillRect(l.x,l.y,l.w,l.h))),f&&(o.strokeStyle=U,o.lineWidth=Y,o.setLineDash([]),o.strokeRect(l.x,l.y,l.w,l.h))}if(t.cfFrame=null,ct(e)){e.cfEval||(e.cfEval=new xt(F,e,l=>Lt(l,F.theme??[])));const n=new Map;t.cfFrame=n;for(let l=a;l<=k;l++){const m=u[l-a+1]-u[l-a];for(let g=d;g<=x;g++){const c=e.cfEval.at(g,l);if(c===null)continue;n.set(g*16384+l,c);const y=r+u[l-a],R=h+p[g-d],N=p[g-d+1]-p[g-d];c.noFill&&!t.mono&&(t.setInk("#FFFFFF"),o.fillRect(y,R,m,N)),c.fill&&!t.mono&&(t.setInk(c.fill),o.fillRect(y,R,m,N)),c.bar&&!t.mono&&(At(o,c.bar,y,R,m,N,1,!1,!0),t.ink=""),c.borders&&(A??=[]).push(g,l,c.borders)}}}if(A!==null)for(let n=0;n<A.length;n+=3){const l=A[n],m=A[n+1],g=A[n+2],c=r+u[m-a],y=r+u[m-a+1],R=h+p[l-d],N=h+p[l-d+1];t.side(g.t,c,R,y,R),t.side(g.b,c,N,y,N),t.side(g.l,c,R,c,N),t.side(g.r,y,R,y,N),g.d&&g.down&&t.side(g.d,c,R,y,N),g.d&&g.up&&t.side(g.d,c,N,y,R)}for(const n of w){const l=O(n);for(let m=n.c0;m<=n.c1;m++){const g=e.cols.sizeOf(m),c=l.x+e.cols.offsetOf(m)-e.cols.offsetOf(n.c0),y=t.style(n.r0,m).borders;y?.t&&t.side(y.t,c,l.y,c+g,l.y);const R=t.style(n.r1,m).borders;R?.b&&t.side(R.b,c,l.y+l.h,c+g,l.y+l.h)}for(let m=n.r0;m<=n.r1;m++){const g=e.rows.sizeOf(m),c=l.y+e.rows.offsetOf(m)-e.rows.offsetOf(n.r0),y=t.style(m,n.c0).borders;y?.l&&t.side(y.l,l.x,c,l.x,c+g);const R=t.style(m,n.c1).borders;R?.r&&t.side(R.r,l.x+l.w,c,l.x+l.w,c+g)}}if(e.sparklines&&e.sparklines.length>0&&F.engine)for(const[n,l]of Pt(e)){const m=Math.floor(n/16384),g=n-m*16384;m<d||m>x||g<a||g>k||Rt(o,F.engine,e,l,m,g,r+u[g-a],h+p[m-d],u[g-a+1]-u[g-a],p[m-d+1]-p[m-d],1,{snap:!1,mono:t.mono})}e.sparkRules!==null&&Mt(o,F,e,{r0:d,r1:x,c0:a,c1:k,xs:u,ys:p,ox:r,oy:h,mono:t.mono}),t.reset(),o.textBaseline="alphabetic",o.textAlign="left";const C={c0:a,c1:k};for(let n=a;n<=k;n++){const l=r+u[n-a],m=u[n-a+1]-u[n-a];if(m===0)continue;const g=e.columns[n];if(g!==void 0)for(let c=d;c<=x;c++){const y=g[c>>>Q];if(y===void 0){c|=W;continue}const R=c&W,N=y.kinds[R]&$;if(N===X||S&&e.mergeAt(c,n)!==null)continue;const H=p[c-d+1]-p[c-d];H!==0&&t.text(c,n,N,y.values[R],l,h+p[c-d],m,H,C)}}if(i<a)for(let n=d;n<=x;n++){const l=p[n-d+1]-p[n-d];if(l===0||e.kind(n,a)!==0)continue;let m=0;for(let g=a-1;g>=Math.max(i,a-Xt);g--){m+=e.cols.sizeOf(g);const c=e.kind(n,g)&$;if(c!==X){c===v&&e.mergeAt(n,g)===null&&(t.reachX=r,t.text(n,g,c,e.value(n,g),r-m,h+p[n-d],e.cols.sizeOf(g),l,C),t.reachX=null);break}}}for(const n of w){const l=e.kind(n.r0,n.c0)&$;if(l===X)continue;const m=O(n);t.text(n.r0,n.c0,l,e.value(n.r0,n.c0),m.x,m.y,m.w,m.h,C,!0)}q(e)&&kt(t.book,e,d,x,a,k,(n,l)=>{ot(t.ctx,t.book,e,n,l,r+u[l-a],h+p[n-d],u[l-a+1]-u[l-a],p[n-d+1]-p[n-d]),t.reset()}),b&&(t.reset(),b(s),t.reset()),o.restore(),t.reset()}function Jt(t,s,f){const{ctx:i,sheet:b}=t,{headingW:o,headingH:e,titleW:r,titleH:h}=s,d=r+s.bodyW,x=h+s.bodyH;i.strokeStyle=U,i.lineWidth=Y,i.setLineDash([]),t.reset(),i.font=f,i.textBaseline="alphabetic",i.textAlign="center",t.setInk("#000000");const a=3;i.strokeRect(0,0,o+d,e),i.strokeRect(0,0,o,e+x);const k=(p,M,I)=>{let T=I;for(let D=p;D<=M;D++){const w=b.cols.sizeOf(D);w>0&&(i.beginPath(),i.moveTo(T+w,0),i.lineTo(T+w,e),i.stroke(),i.fillText(Tt(D),T+w/2,e-a)),T+=w}},u=(p,M,I)=>{let T=I;for(let D=p;D<=M;D++){const w=b.rows.sizeOf(D);w>0&&(i.beginPath(),i.moveTo(0,T+w),i.lineTo(o,T+w),i.stroke(),i.fillText(String(D+1),o/2,T+w-a)),T+=w}};s.titleCols&&k(s.titleCols.c0,s.titleCols.c1,o),k(s.c0,s.c1,o+r),s.titleRows&&u(s.titleRows.r0,s.titleRows.r1,e),u(s.r0,s.r1,e+h),i.textAlign="left"}const B=new Map;function Zt(t){let s=B.get(t);return s===void 0&&(s=Wt(t),B.size>256&&B.clear(),B.set(t,s)),s}function qt(t,s){switch(t.field){case"page":return String(s.pageNumber+(t.offset??0));case"pages":return String(s.totalPages);case"date":return s.now.toLocaleDateString(s.locale);case"time":return s.now.toLocaleTimeString(s.locale,{hour:"2-digit",minute:"2-digit"});case"file":return s.fileName;case"sheet":return s.sheetName;case"path":return s.filePath;default:return""}}function jt(t,s){const f=[[]];for(const i of t)(i.field?qt(i,s):i.text).split(`
3
- `).forEach((e,r)=>{r>0&&f.push([]),e&&f[f.length-1].push({...i,text:e})});return f}function Qt(t,s,f,i,b,o=null){const{setup:e,paper:r}=s,h=e.margins,d=i.pageNumber%2===0,x=w=>e.differentFirst&&i.sheetPage===0?w.first:e.differentOddEven&&d?w.even:w.odd,a=x(e.header),k=x(e.footer);if(!a&&!k)return;const u=i.defaultStyle,p=(e.alignWithMargins?h.left:.7)*72,M=r.width-(e.alignWithMargins?h.right:.7)*72;t.save(),t.textBaseline="alphabetic",t.textAlign="left";const I=(w,S,P,z)=>{const F=w.map(C=>{const n=(C.size??V)*b*(C.script!==0?.66:1),l=E({...u,fontName:C.font??u.fontName,bold:C.bold,italic:C.italic},n);return t.font=l,{run:C,size:n,font:l,width:t.measureText(C.text).width}});let A=0;for(const C of F)A+=C.width;let O=P==="center"?S-A/2:P==="right"?S-A:S;for(const{run:C,size:n,font:l,width:m}of F){t.font=l;const g=e.blackAndWhite?"#000000":C.color??"#000000";t.fillStyle=g;const c=z-(C.script===1?n*.5:C.script===-1?-n*.2:0);t.fillText(C.text,O,c);const y=Math.max(.4,n/14);C.underline&&(t.fillRect(O,c+n*.14,m,y),C.underline===2&&t.fillRect(O,c+n*.14+y*2,m,y)),C.strike&&t.fillRect(O,c-n*.3,m,y),O+=m}},T=w=>{let S=V;return w.length>0&&(S=Math.max(...w.map(P=>P.size??V))),S*b*1.2},D=(w,S,P,z)=>{if(w.length===0)return;const F=jt(w,i);if(z){let A=h.header*72;for(const O of F){const C=T(O);I(O,S,P,A+C*.8),A+=C}}else{let A=r.height-h.footer*72;for(let O=F.length-1;O>=0;O--){const C=T(F[O]);I(F[O],S,P,A-C*.2),A-=C}}};for(const[w,S]of[[a,!0],[k,!1]]){if(!w)continue;const P=Zt(w),z=o?.[S?"header":"footer"];z!=="L"&&D(P.left,p,"left",S),z!=="C"&&D(P.center,r.width/2,"center",S),z!=="R"&&D(P.right,M,"right",S)}t.restore()}function te(t,s){t.translate((s.paperW-2*s.originX)/s.scale,0),t.scale(-1,1);const f=Object.prototype.hasOwnProperty.call(t,"fillText"),i=t.fillText;return t.fillText=function(o,e,r){const h=t.measureText(o).width,d=t.textAlign,x=d==="right"||d==="end"?e-h:d==="center"?e-h/2:e;t.save(),t.scale(-1,1),t.textAlign="left",i.call(t,o,-x-h,r),t.restore()},()=>{f?t.fillText=i:delete t.fillText}}function lt(t,s,f,i={}){const{book:b,sheet:o,setup:e}=s,r=b.styles.list[0];t.save(),i.background!==!1&&(t.fillStyle="#ffffff",t.fillRect(0,0,f.paperW,f.paperH)),ut(t,o,f,i.sheetPage??f.index,e);const h={pageNumber:i.pageNumber??f.index+1,totalPages:i.totalPages??s.pageCount,sheetPage:i.sheetPage??f.index,fileName:i.fileName??b.fileName??"",filePath:i.filePath??"",sheetName:o.name,now:i.now??new Date,locale:i.locale,defaultStyle:r};if(Qt(t,s,f,h,e.scaleWithDoc?f.scale:1),f.noteLines){Bt(t,f),t.restore();return}t.save(),t.translate(f.originX,f.originY),t.scale(f.scale,f.scale);const d=o.rtl===!0?te(t,f):null,x=new Yt(t,b,o,e),{headingW:a,headingH:k,titleW:u,titleH:p,titleRows:M,titleCols:I,r0:T,r1:D,c0:w,c1:S,area:P}=f,z=e.gridLines&&!e.draft;e.headings&&Jt(x,f,E(r,r.fontSize));const F=i.objectPainters??null,A=F&&F.length>0?l=>{const m=l.x-o.cols.offsetOf(l.c0),g=l.y-o.rows.offsetOf(l.r0),c={printing:!0,dpr:1,zoom:1,hx:l.x,hy:l.y,cssW:l.x+o.cols.offsetOf(l.c1+1)-o.cols.offsetOf(l.c0),cssH:l.y+o.rows.offsetOf(l.r1+1)-o.rows.offsetOf(l.r0),toScreen:(y,R)=>({x:m+y,y:g+R}),sheet:o};for(const y of F)y(t,c)}:null;if(f.chartBox){if(F){const l={printing:!0,dpr:1,zoom:1,hx:0,hy:0,cssW:f.bodyW,cssH:f.bodyH,toScreen:(m,g)=>({x:m,y:g}),sheet:o,chartBox:f.chartBox};for(const m of F)m(t,l)}t.restore(),t.restore();return}const O=a+u,C=k+p,n=(l,m)=>{Vt(x,l,z,m,A),t.link&&i.onPlace&&Et(t,b,o,l,i.onPlace)};n({x:O,y:C,r0:T,r1:D,c0:w,c1:S},P.c0),M&&n({x:O,y:k,r0:M.r0,r1:M.r1,c0:w,c1:S},P.c0),I&&n({x:a,y:C,r0:T,r1:D,c0:I.c0,c1:I.c1},I.c0),M&&I&&n({x:a,y:k,r0:M.r0,r1:M.r1,c0:I.c0,c1:I.c1},I.c0),d?.(),t.restore(),t.restore()}function Pe(t,s,f,{pxPerPt:i=2,...b}={}){const o=s.at(f);if(o===null)return null;const{page:e,pagination:r}=o;t.width=Math.max(1,Math.round(e.paperW*i)),t.height=Math.max(1,Math.round(e.paperH*i));const h=t.getContext("2d",{alpha:!1});return h.setTransform(i,0,0,i,0,0),lt(h,r,e,{pageNumber:o.pageNumber,totalPages:o.totalPages,sheetPage:o.sheetPage,...b}),o}const ee=()=>new Promise(t=>setTimeout(t,0)),ne={gray0625:.0625,gray125:.125,lightGray:.25,mediumGray:.5,darkGray:.75,lightHorizontal:.25,lightVertical:.25,lightDown:.25,lightUp:.25,lightGrid:.44,lightTrellis:.5,darkHorizontal:.5,darkVertical:.5,darkDown:.5,darkUp:.5,darkGrid:.5,darkTrellis:.75};function ft(t){if(!t.pattern)return t.fill;const s=ne[t.pattern.type]??.5,f=i=>{const b=parseInt(t.pattern.fg.slice(i,i+2),16),o=parseInt(t.fill.slice(i,i+2),16);return Math.round(b*s+o*(1-s)).toString(16).padStart(2,"0")};return`#${f(1)}${f(3)}${f(5)}`}async function Re(t,s,f={}){const{title:i,author:b,subject:o,fonts:e,compress:r,signal:h,onProgress:d,...x}=f,[{PdfWriter:a}]=await Promise.all([import("./pdf.js"),zt(t)]),k=new a(s,{title:i,author:b,subject:o,fonts:e,compress:r}),u=x.now??new Date;let p=performance.now();const M=new Map,I=(D,w,S)=>{const P=`${t.book.sheets.indexOf(D)}:${w}:${S}`;if(!M.has(P)){const z=t.entries.find(A=>A.sheet===D),F=z?z.pagination.pageAt(w,S):-1;if(M.set(P,F<0?null:`L${M.size}`),F>=0){const A=z.pagination.page(F),O=A.headingH+A.titleH+D.rows.offsetOf(w)-D.rows.offsetOf(A.r0);k.destination(M.get(P),z.first+F,A.paperH-A.originY-O*A.scale)}}return M.get(P)};let T=null;for(let D=0;D<t.pageCount;D++){h?.throwIfAborted();const w=t.at(D),{page:S,pagination:P}=w;P.sheet!==T&&(T=P.sheet,k.bookmark(T.name,D));const z=k.beginPage(S.paperW,S.paperH);lt(z,P,S,{...x,now:u,onPlace:I,background:!1,pageNumber:w.pageNumber,totalPages:w.totalPages,sheetPage:w.sheetPage}),await k.endPage(),d?.(D+1,t.pageCount),performance.now()-p>12&&(await ee(),p=performance.now())}return k.bookmarks.length<2&&(k.bookmarks.length=0),await k.finish(),{pages:k.pageCount,bytes:k.offset,missing:[...k.missing],fontWarnings:k.fontWarnings}}export{Ut as displayText,Qt as paintHeaderFooter,Pe as renderJobPageToCanvas,lt as renderPage,Re as writeJobPdf};
1
+ import{hasCellTypes as j}from"../core/cell-type-rules.js";import{hasConditionalFormats as ct}from"../core/host-rules.js";import{readingDirection as at,visualOrder as ht,wrapsByAlign as dt}from"../cells/text-layout.js";import{gradientPatches as q}from"../cells/paint.js";import{paintWatermarks as ut}from"../shapes/watermark.js";import{BOOL as mt,CHUNK_BITS as Q,CHUNK_MASK as W,EMPTY as X,ERR as tt,ERRORS as gt,KIND_MASK as $,NUM as L,STR as v,FORMULA as et,SPILL as nt}from"../core/sheet.js";import{isBarcodeText as pt,paintBarcodeValue as wt}from"../celltypes/barcode.js";import{printCellType as ot,printEmptyTypedCells as bt}from"../celltypes/cell-types.js";import{FILL_MARK as it,fitGeneral as kt,formatGeneral as yt,getFormatter as K}from"../core/numfmt.js";import{colName as Tt}from"../core/address.js";import{cssFont as E}from"../core/styles.js";import{CondFormats as Ot}from"../core/cond-format.js";import{drawCfIcon as St,iconSide as Pt,monoContext as Dt,paintCfBar as Rt}from"../cells/cf-paint.js";import{sparklineIndex as xt}from"../core/sparklines.js";import{paintSparkline as At}from"../sparklines/excel-paint.js";import{isSparklineText as Ct,paintSparklineValue as Ft}from"../sparklines/paint.js";import{paintSparkRulesOnPage as Mt,sparkRuleHidesValue as zt}from"../sparklines/rule.js";import{preparePicturesForPrint as It}from"../sparklines/print.js";import{tableColors as Nt,tablesOf as vt}from"../core/tables.js";import{paintCustomTable as Ht}from"../slicers/custom-styles.js";import{resolveColor as Lt}from"../io/xlsx-styles.js";import{parseHeaderFooter as Wt}from"./page-setup.js";import{linkRegion as Et}from"./pdf-links.js";import{paintNotePage as _t}from"./note-pages.js";import{paintShownNotes as Bt}from"./shown-notes.js";const Gt=2,Xt=6,$t=32,U="#000000",Y=.25,V=10,Kt={hair:.25,thin:.5,dotted:.5,dashed:.5,dashDot:.5,dashDotDot:.5,medium:1,mediumDashed:1,mediumDashDot:1,mediumDashDotDot:1,slantDashDot:1,thick:1.5,double:.5},Ut={hair:[.5,.75],dotted:[.5,1.5],dashed:[3,1.5],dashDot:[3,1.5,.75,1.5],dashDotDot:[3,1.5,.75,1.5,.75,1.5],mediumDashed:[4,2],mediumDashDot:[4,2,1,2],mediumDashDotDot:[4,2,1,2,1,2],slantDashDot:[4,1,1,1]},st=new WeakMap;function J(t){let i=st.get(t);return i===void 0&&(i=E(t,t.fontSize),st.set(t,i)),i}function Yt(t,i,l,s){switch(i){case L:return s.numFmt==="General"?yt(l):K(s.numFmt).number(l,t.dateOffset);case v:{const p=t.strings.get(l);return s.numFmt==="General"||s.numFmt==="@"?p:K(s.numFmt).text(p)}case mt:return l?"TRUE":"FALSE";case tt:return gt[l]??"#N/A";default:return""}}class Vt{constructor(i,l,s,p){this.ctx=i,this.book=l,this.sheet=s,this.styles=l.styles.list,this.mono=p.blackAndWhite,this.errors=p.errors,this.cfFrame=null,this.tables=null,this.font="",this.ink="",this.wrapCache=new Map,this.reachX=null}style(i,l){return this.styles[this.sheet.style(i,l)]??this.styles[0]}textStyle(i,l,s,p,n){let e=this.style(i,l);const r=this.cfFrame===null?void 0:this.cfFrame.get(i*16384+l);if(r!==void 0){if(r.icon&&this.icon(r.icon,s,p,n,e),r.hideValue)return null;(r.color||r.numFmt!==void 0||r.bold!==void 0||r.italic!==void 0||r.underline!==void 0||r.strike!==void 0)&&(e={...e,color:r.color??e.color,numFmt:r.numFmt??e.numFmt,bold:r.bold??e.bold,italic:r.italic??e.italic,underline:r.underline??e.underline,strike:r.strike??e.strike})}if(this.tables!==null)for(const d of this.tables){if(i<d.r0||i>d.r1||l<d.c0||l>d.c1||!d._colors)continue;const m=d._colors.format(d,i,l);e={...e,color:e.color??m.color,bold:e.bold||m.bold===!0,italic:e.italic||m.italic===!0},m.underline&&!e.underline&&(e.underline=m.underline),m.strike&&(e.strike=!0);break}return e}icon(i,l,s,p,n){const e=Pt(p,1,n.fontSize),r=n.vAlign==="top"?s+1:n.vAlign==="center"?s+(p-e)/2:s+p-e-1;St(this.mono?Dt(this.ctx):this.ctx,i.name,i.level,l+1,r,e),this.ink=""}setFont(i){this.font!==i&&(this.ctx.font=i,this.font=i)}setInk(i){this.ink!==i&&(this.ctx.fillStyle=i,this.ink=i)}reset(){this.font="",this.ink=""}width(i){return this.ctx.measureText(i).width}richLine(i,l,s,p,n,e,r,d,m){const{ctx:y}=this,h=[];let k=0,g=0;l.forEach((b,C)=>{const O=l[C+1]?.at??i.length;if(O<=b.at)return;const D={...s,fontName:b.name??s.fontName,fontSize:b.sz??s.fontSize,bold:b.b??s.bold,italic:b.i??s.italic},z=J(D);this.setFont(z);const N=i.slice(b.at,O).replace(/\n/g," "),R=y.measureText(N).width;h.push({piece:N,font:z,ink:b.color??s.color??"#000000",pw:R}),k+=R,g=Math.max(g,D.fontSize)});const w=s.vAlign??"bottom",F=w==="top"?e+g*1.05:w==="center"?e+(d+g*.72)/2:e+d-3;let M=p==="right"?n+r-m-k:p==="center"||p==="centerContinuous"?n+(r-k)/2:n+m;y.textAlign="left";for(const b of h)this.setFont(b.font),this.setInk(b.ink),y.fillText(b.piece,M,F),M+=b.pw}text(i,l,s,p,n,e,r,d,m,y=!1){const{ctx:h}=this;if(!h.marks){this._text(i,l,s,p,n,e,r,d,m,y);return}const k=y?this.sheet.mergeAt(i,l):null;h.beginCell(i,l,{scope:this.scopeOf(i,l),rows:k?k.r1-k.r0+1:1,cols:k?k.c1-k.c0+1:1}),this._text(i,l,s,p,n,e,r,d,m,y),h.endMark()}scopeOf(i,l){const{titleRows:s,titleCols:p}=this;if(s&&i>=s.r0&&i<=s.r1)return"Column";for(const n of this.tables??[])if(n.headerRows>0&&i===n.r0&&l>=n.c0&&l<=n.c1)return"Column";return p&&l>=p.c0&&l<=p.c1?"Row":null}_text(i,l,s,p,n,e,r,d,m,y){const{ctx:h,sheet:k}=this,g=this.reachX===null?this.textStyle(i,l,n,e,d):this.style(i,l);if(g===null)return;if(j(k)&&this.reachX===null&&ot(h,this.book,k,i,l,n,e,r,d)){this.reset();return}if(s===L&&p===0&&k.hideZeros)return;if(g.ext?.pad){const[c,T,A,I]=g.ext.pad;n+=I,e+=c,r=Math.max(0,r-I-T),d=Math.max(0,d-c-A)}let w=Yt(this.book,s,p,g);if(s===tt&&this.errors!=="displayed"&&(w=this.errors==="blank"?"":this.errors==="dash"?"--":"#N/A"),w===""||s===v&&pt(w)&&(k.kind(i,l)&(et|nt))!==0&&wt(h,w,n,e,r,d,1)||s===v&&Ct(w)&&(k.kind(i,l)&(et|nt))!==0&&Ft(h,w,n,e,r,d,1,{ink:g.color??"#000000",snap:!1,mono:this.mono})||k.sparkRules!==null&&zt(k,i,l))return;const F=J(g);this.setFont(F);let M=g.color??"#000000";s===L&&g.numFmt!=="General"&&(M=K(g.numFmt).color(p)??M),this.setInk(this.mono?"#000000":M);const b=Gt,C=s===v?at(g.readingOrder,w):null;s===v&&!("direction"in h)&&(w=ht(w,C==="rtl")),C==="rtl"&&"direction"in h?(h.direction="rtl",this.pendingDirection=!0):this.pendingDirection&&(h.direction="ltr",this.pendingDirection=!1);const O=g.hAlign??(s===L||C==="rtl"?"right":s===v?"left":"center");if(O==="centerContinuous")for(let c=l+1;(k.kind(i,c)&15)===0&&k.mergeAt(i,c)===null&&this.book.styles.get(k.style(i,c)).hAlign==="centerContinuous";c++)r+=k.cols.sizeOf(c);const D=r-b*2,z=g.fontSize;if(this.reachX!==null&&(g.rotation!==0||g.wrap))return;if(g.rotation!==0){this.rotated(w,g,n,e,r,d);return}if(g.wrap||dt(g)){this.wrapped(w,g,O,n,e,r,d,b,z);return}const N=s===v?this.book.strings.rich?.get(p):void 0;if(N!==void 0&&!this.mono){this.richLine(w,N,g,O,n,e,r,d,b);return}const R=g.vAlign??"bottom";let x;if(R==="top"?x=e+z*1.05:R==="center"?x=e+(d+z*.72)/2:x=e+d-3,w.indexOf(it)>=0){if(this.reachX!==null)return;const c=w.split(it),T=c[0],A=c[1]??" ",I=c.slice(2).join("");h.textAlign="left",T&&h.fillText(T,n+b,x);const H=this.width(T),B=this.width(I);if(A!==" "){const G=this.width(A)||1,Z=Math.floor((D-H-B)/G);Z>0&&h.fillText(A.repeat(Z),n+b+H,x)}h.textAlign="right",I&&h.fillText(I,n+r-b,x),h.textAlign="left";return}let S=this.width(w);if(S>D&&s===L&&(g.numFmt==="General"&&(w=kt(p,c=>this.width(c)<=D),S=this.width(w)),S>D)){const c=this.width("#")||1;w="#".repeat(Math.max(1,Math.floor(D/c))),S=c*w.length}let P=!1;if(g.shrink&&S>D&&D>0&&(this.setFont(E(g,z*(D/S))),S=D,P=!0),g.indent>0){const c=g.indent*Xt;O==="left"?(n+=c,r-=c):O==="right"&&(r-=c)}let o,a=!1,f=n,u=n+r;if(O==="center"||O==="centerContinuous")o=n+(r-S)/2;else if(O==="right")o=n+r-b-S;else if(O==="fill"){const c=Math.max(1,Math.floor(D/(S||1)));w=w.repeat(c),S*=c,o=n+b}else o=n+b;if(this.reachX!==null&&o+S<=this.reachX){P&&this.setFont(F);return}if(S>D||o<n+b)if(y)a=!0;else if(s===v){if(o+S>u){let c=l+1,T=u;for(;T<o+S&&c<=m.c1&&(k.kind(i,c)&15)===0&&k.mergeAt(i,c)===null;)T+=k.cols.sizeOf(c),c++;u=T}if(o<f){let c=l-1,T=f;for(;T>o&&c>=m.c0&&(k.kind(i,c)&15)===0&&k.mergeAt(i,c)===null;)T-=k.cols.sizeOf(c),c--;f=T}a=o+S>u||o<f}else a=!0;h.textAlign="left",a?(h.save(),h.beginPath(),h.rect(f,e,u-f,d),h.clip(),h.fillText(w,o,x),this.decorate(g,o,x,S,z),h.restore()):(h.fillText(w,o,x),(g.underline!==0||g.strike)&&this.decorate(g,o,x,S,z)),P&&this.setFont(F)}decorate(i,l,s,p,n){const{ctx:e}=this,r=Math.max(.5,n/14);if(i.underline!==0){const d=s+n*.14;e.fillRect(l,d,p,r),i.underline===2&&e.fillRect(l,d+r*2,p,r)}i.strike&&e.fillRect(l,s-n*.3,p,r)}wrapLines(i,l,s){const p=`${i}|${Math.round(s)}|${l}`;let n=this.wrapCache.get(p);if(n!==void 0)return n;n=[];for(const e of l.split(`
2
+ `)){let r="";for(const d of e.split(/(?<=\s)/)){const m=r+d;for(r!==""&&this.width(m.trimEnd())>s?(n.push(r.trimEnd()),r=d):r=m;this.width(r.trimEnd())>s&&r.length>1;){let y=r.length-1;for(;y>1&&this.width(r.slice(0,y))>s;)y--;n.push(r.slice(0,y)),r=r.slice(y)}}n.push(r.trimEnd())}return this.wrapCache.size>4096&&this.wrapCache.clear(),this.wrapCache.set(p,n),n}wrapped(i,l,s,p,n,e,r,d,m){const{ctx:y}=this,h=this.wrapLines(J(l),i,e-d*2),k=Math.round(m*1.26),g=h.length*k,w=l.vAlign??"bottom";let F;w==="top"?F=n:w==="center"?F=n+(r-g)/2:F=n+r-g,y.save(),y.beginPath(),y.rect(p,n,e,r),y.clip(),y.textAlign=s==="center"?"center":s==="right"?"right":"left";const M=s==="center"?p+e/2:s==="right"?p+e-d:p+d;for(let b=0;b<h.length;b++){const C=F+b*k+Math.round(k*.8);C+k<n||C-k>n+r||y.fillText(h[b],M,C)}y.restore(),y.textAlign="left"}rotated(i,l,s,p,n,e){const{ctx:r}=this;r.save(),r.beginPath(),r.rect(s,p,n,e),r.clip(),r.translate(s+n/2,p+e/2);const d=l.rotation;if(r.textAlign="center",d===255){const m=l.fontSize*1.1,y=-((i.length-1)*m)/2;for(let h=0;h<i.length;h++)r.fillText(i[h],0,y+h*m)}else{const m=d>90?90-d:d;r.rotate(-m*Math.PI/180),r.fillText(i,0,l.fontSize*.35)}r.restore(),r.textAlign="left"}side(i,l,s,p,n){if(!i)return;const{ctx:e}=this,r=Kt[i.style]??.5;if(e.strokeStyle=this.mono?"#000000":i.color??"#000000",e.lineWidth=r,e.setLineDash(Ut[i.style]??[]),e.beginPath(),i.style==="double"){const d=s===n?0:.75,m=s===n?.75:0;e.moveTo(l-d,s-m),e.lineTo(p-d,n-m),e.moveTo(l+d,s+m),e.lineTo(p+d,n+m)}else e.moveTo(l,s),e.lineTo(p,n);e.stroke()}}function rt(t,i,l){const s=new Float64Array(l-i+2);let p=0;for(let n=i;n<=l;n++)s[n-i]=p,p+=t.sizeOf(n);return s[l-i+1]=p,s}function Jt(t,i,l,s,p){const{ctx:n,sheet:e}=t,{x:r,y:d,r0:m,r1:y,c0:h,c1:k}=i,g=rt(e.cols,h,k),w=rt(e.rows,m,y),F=k-h+1,M=y-m+1,b=g[F],C=w[M];if(b<=0||C<=0)return;if(n.save(),n.beginPath(),n.rect(r,d,b,C),n.clip(),t.reset(),l){n.strokeStyle=U,n.lineWidth=Y,n.setLineDash([]),n.beginPath();for(let o=0;o<=F;o++)o>0&&g[o]===g[o-1]||(n.moveTo(r+g[o],d),n.lineTo(r+g[o],d+C));for(let o=0;o<=M;o++)o>0&&w[o]===w[o-1]||(n.moveTo(r,d+w[o]),n.lineTo(r+b,d+w[o]));n.stroke()}const O=e.mergesInRows(m,y).filter(o=>o.c1>=h&&o.c0<=k),D=O.length>0,z=e.rowStyles!==null||e.colStyles!==null,N=t.styles[0].fill===null&&t.styles[0].borders===null;t.tables=null;const{book:R}=t;if(R.engine&&R.engine.tables.size>0){const o=vt(R,e);o.length>0&&(t.tables=o);for(const a of o){if(a.r1<m||a.r0>y||a.c1<h||a.c0>k)continue;const f=Nt(a.styleName,R.theme);f&&(a._colors=f,Ht(n,a,f,{ra:m,rb:y,ca:h,cb:k,xs:g,ys:w,ox:r,oy:d,line:.5,noFill:t.mono,setInk:u=>t.setInk(t.mono?"#000000":u)}))}}let x=null;for(let o=h;o<=k;o++){const a=g[o-h+1]-g[o-h];if(a===0)continue;const f=e.columns[o];if(!(f===void 0&&!z&&N))for(let u=m;u<=y;u++){if(!z&&N){const A=f[u>>>Q];if(A===void 0||A.styles===null){u|=W;continue}if(A.styles[u&W]===0)continue}const c=w[u-m+1]-w[u-m];if(c===0)continue;const T=t.style(u,o);T.fill===null&&T.borders===null||D&&e.mergeAt(u,o)!==null||(T.fill!==null&&!t.mono&&(T.gradient?q(T.gradient,r+g[o-h],d+w[u-m],a,c,(A,I,H,B,G)=>{t.setInk(A),n.fillRect(I,H,B,G)}):(t.setInk(ft(T)),n.fillRect(r+g[o-h],d+w[u-m],a,c))),T.borders!==null&&(x??=[]).push(u,o,T.borders))}}const S=o=>{const a=r+e.cols.offsetOf(o.c0)-e.cols.offsetOf(h),f=d+e.rows.offsetOf(o.r0)-e.rows.offsetOf(m);return{x:a,y:f,w:e.cols.offsetOf(o.c1+1)-e.cols.offsetOf(o.c0),h:e.rows.offsetOf(o.r1+1)-e.rows.offsetOf(o.r0)}};for(const o of O){const a=S(o),f=t.style(o.r0,o.c0);(l||f.fill!==null&&!t.mono)&&(f.gradient&&!t.mono?q(f.gradient,a.x,a.y,a.w,a.h,(u,c,T,A,I)=>{t.setInk(u),n.fillRect(c,T,A,I)}):(t.setInk(f.fill!==null&&!t.mono?ft(f):"#ffffff"),n.fillRect(a.x,a.y,a.w,a.h))),l&&(n.strokeStyle=U,n.lineWidth=Y,n.setLineDash([]),n.strokeRect(a.x,a.y,a.w,a.h))}if(t.cfFrame=null,ct(e)){e.cfEval||(e.cfEval=new Ot(R,e,a=>Lt(a,R.theme??[])));const o=new Map;t.cfFrame=o;for(let a=h;a<=k;a++){const f=g[a-h+1]-g[a-h];for(let u=m;u<=y;u++){const c=e.cfEval.at(u,a);if(c===null)continue;o.set(u*16384+a,c);const T=r+g[a-h],A=d+w[u-m],I=w[u-m+1]-w[u-m];c.noFill&&!t.mono&&(t.setInk("#FFFFFF"),n.fillRect(T,A,f,I)),c.fill&&!t.mono&&(t.setInk(c.fill),n.fillRect(T,A,f,I)),c.bar&&!t.mono&&(Rt(n,c.bar,T,A,f,I,1,!1,!0),t.ink=""),c.borders&&(x??=[]).push(u,a,c.borders)}}}if(x!==null)for(let o=0;o<x.length;o+=3){const a=x[o],f=x[o+1],u=x[o+2],c=r+g[f-h],T=r+g[f-h+1],A=d+w[a-m],I=d+w[a-m+1];t.side(u.t,c,A,T,A),t.side(u.b,c,I,T,I),t.side(u.l,c,A,c,I),t.side(u.r,T,A,T,I),u.d&&u.down&&t.side(u.d,c,A,T,I),u.d&&u.up&&t.side(u.d,c,I,T,A)}for(const o of O){const a=S(o);for(let f=o.c0;f<=o.c1;f++){const u=e.cols.sizeOf(f),c=a.x+e.cols.offsetOf(f)-e.cols.offsetOf(o.c0),T=t.style(o.r0,f).borders;T?.t&&t.side(T.t,c,a.y,c+u,a.y);const A=t.style(o.r1,f).borders;A?.b&&t.side(A.b,c,a.y+a.h,c+u,a.y+a.h)}for(let f=o.r0;f<=o.r1;f++){const u=e.rows.sizeOf(f),c=a.y+e.rows.offsetOf(f)-e.rows.offsetOf(o.r0),T=t.style(f,o.c0).borders;T?.l&&t.side(T.l,a.x,c,a.x,c+u);const A=t.style(f,o.c1).borders;A?.r&&t.side(A.r,a.x+a.w,c,a.x+a.w,c+u)}}if(e.sparklines&&e.sparklines.length>0&&R.engine)for(const[o,a]of xt(e)){const f=Math.floor(o/16384),u=o-f*16384;f<m||f>y||u<h||u>k||At(n,R.engine,e,a,f,u,r+g[u-h],d+w[f-m],g[u-h+1]-g[u-h],w[f-m+1]-w[f-m],1,{snap:!1,mono:t.mono})}e.sparkRules!==null&&Mt(n,R,e,{r0:m,r1:y,c0:h,c1:k,xs:g,ys:w,ox:r,oy:d,mono:t.mono}),t.reset(),n.textBaseline="alphabetic",n.textAlign="left";const P={c0:h,c1:k};for(let o=h;o<=k;o++){const a=r+g[o-h],f=g[o-h+1]-g[o-h];if(f===0)continue;const u=e.columns[o];if(u!==void 0)for(let c=m;c<=y;c++){const T=u[c>>>Q];if(T===void 0){c|=W;continue}const A=c&W,I=T.kinds[A]&$;if(I===X||D&&e.mergeAt(c,o)!==null)continue;const H=w[c-m+1]-w[c-m];H!==0&&t.text(c,o,I,T.values[A],a,d+w[c-m],f,H,P)}}if(s<h)for(let o=m;o<=y;o++){const a=w[o-m+1]-w[o-m];if(a===0||e.kind(o,h)!==0)continue;let f=0;for(let u=h-1;u>=Math.max(s,h-$t);u--){f+=e.cols.sizeOf(u);const c=e.kind(o,u)&$;if(c!==X){c===v&&e.mergeAt(o,u)===null&&(t.reachX=r,t.text(o,u,c,e.value(o,u),r-f,d+w[o-m],e.cols.sizeOf(u),a,P),t.reachX=null);break}}}for(const o of O){const a=e.kind(o.r0,o.c0)&$;if(a===X)continue;const f=S(o);t.text(o.r0,o.c0,a,e.value(o.r0,o.c0),f.x,f.y,f.w,f.h,P,!0)}j(e)&&bt(t.book,e,m,y,h,k,(o,a)=>{ot(t.ctx,t.book,e,o,a,r+g[a-h],d+w[o-m],g[a-h+1]-g[a-h],w[o-m+1]-w[o-m]),t.reset()}),p&&(t.reset(),p(i),t.reset()),n.restore(),t.reset()}function Zt(t,i,l){const{ctx:s,sheet:p}=t,{headingW:n,headingH:e,titleW:r,titleH:d}=i,m=r+i.bodyW,y=d+i.bodyH;s.strokeStyle=U,s.lineWidth=Y,s.setLineDash([]),t.reset(),s.font=l,s.textBaseline="alphabetic",s.textAlign="center",t.setInk("#000000");const h=3;s.strokeRect(0,0,n+m,e),s.strokeRect(0,0,n,e+y);const k=(w,F,M)=>{let b=M;for(let C=w;C<=F;C++){const O=p.cols.sizeOf(C);O>0&&(s.beginPath(),s.moveTo(b+O,0),s.lineTo(b+O,e),s.stroke(),s.fillText(Tt(C),b+O/2,e-h)),b+=O}},g=(w,F,M)=>{let b=M;for(let C=w;C<=F;C++){const O=p.rows.sizeOf(C);O>0&&(s.beginPath(),s.moveTo(0,b+O),s.lineTo(n,b+O),s.stroke(),s.fillText(String(C+1),n/2,b+O-h)),b+=O}};i.titleCols&&k(i.titleCols.c0,i.titleCols.c1,n),k(i.c0,i.c1,n+r),i.titleRows&&g(i.titleRows.r0,i.titleRows.r1,e),g(i.r0,i.r1,e+d),s.textAlign="left"}const _=new Map;function jt(t){let i=_.get(t);return i===void 0&&(i=Wt(t),_.size>256&&_.clear(),_.set(t,i)),i}function qt(t,i){switch(t.field){case"page":return String(i.pageNumber+(t.offset??0));case"pages":return String(i.totalPages);case"date":return i.now.toLocaleDateString(i.locale);case"time":return i.now.toLocaleTimeString(i.locale,{hour:"2-digit",minute:"2-digit"});case"file":return i.fileName;case"sheet":return i.sheetName;case"path":return i.filePath;default:return""}}function Qt(t,i){const l=[[]];for(const s of t)(s.field?qt(s,i):s.text).split(`
3
+ `).forEach((e,r)=>{r>0&&l.push([]),e&&l[l.length-1].push({...s,text:e})});return l}function te(t,i,l,s,p,n=null){const{setup:e,paper:r}=i,d=e.margins,m=s.pageNumber%2===0,y=O=>e.differentFirst&&s.sheetPage===0?O.first:e.differentOddEven&&m?O.even:O.odd,h=y(e.header),k=y(e.footer);if(!h&&!k)return;const g=s.defaultStyle,w=(e.alignWithMargins?d.left:.7)*72,F=r.width-(e.alignWithMargins?d.right:.7)*72;t.save(),t.textBaseline="alphabetic",t.textAlign="left";const M=(O,D,z,N)=>{const R=O.map(P=>{const o=(P.size??V)*p*(P.script!==0?.66:1),a=E({...g,fontName:P.font??g.fontName,bold:P.bold,italic:P.italic},o);return t.font=a,{run:P,size:o,font:a,width:t.measureText(P.text).width}});let x=0;for(const P of R)x+=P.width;let S=z==="center"?D-x/2:z==="right"?D-x:D;for(const{run:P,size:o,font:a,width:f}of R){t.font=a;const u=e.blackAndWhite?"#000000":P.color??"#000000";t.fillStyle=u;const c=N-(P.script===1?o*.5:P.script===-1?-o*.2:0);t.fillText(P.text,S,c);const T=Math.max(.4,o/14);P.underline&&(t.fillRect(S,c+o*.14,f,T),P.underline===2&&t.fillRect(S,c+o*.14+T*2,f,T)),P.strike&&t.fillRect(S,c-o*.3,f,T),S+=f}},b=O=>{let D=V;return O.length>0&&(D=Math.max(...O.map(z=>z.size??V))),D*p*1.2},C=(O,D,z,N)=>{if(O.length===0)return;const R=Qt(O,s);if(N){let x=d.header*72;for(const S of R){const P=b(S);M(S,D,z,x+P*.8),x+=P}}else{let x=r.height-d.footer*72;for(let S=R.length-1;S>=0;S--){const P=b(R[S]);M(R[S],D,z,x-P*.2),x-=P}}};for(const[O,D]of[[h,!0],[k,!1]]){if(!O)continue;const z=jt(O),N=n?.[D?"header":"footer"];N!=="L"&&C(z.left,w,"left",D),N!=="C"&&C(z.center,r.width/2,"center",D),N!=="R"&&C(z.right,F,"right",D)}t.restore()}function ee(t,i){t.translate((i.paperW-2*i.originX)/i.scale,0),t.scale(-1,1);const l=Object.prototype.hasOwnProperty.call(t,"fillText"),s=t.fillText;return t.fillText=function(n,e,r){const d=t.measureText(n).width,m=t.textAlign,y=m==="right"||m==="end"?e-d:m==="center"?e-d/2:e;t.save(),t.scale(-1,1),t.textAlign="left",s.call(t,n,-y-d,r),t.restore()},()=>{l?t.fillText=s:delete t.fillText}}function lt(t,i,l,s={}){const{book:p,sheet:n,setup:e}=i,r=p.styles.list[0];t.save(),s.background!==!1&&(t.fillStyle="#ffffff",t.fillRect(0,0,l.paperW,l.paperH)),ut(t,n,l,s.sheetPage??l.index,e);const d={pageNumber:s.pageNumber??l.index+1,totalPages:s.totalPages??i.pageCount,sheetPage:s.sheetPage??l.index,fileName:s.fileName??p.fileName??"",filePath:s.filePath??"",sheetName:n.name,now:s.now??new Date,locale:s.locale,defaultStyle:r};if(te(t,i,l,d,e.scaleWithDoc?l.scale:1),l.noteLines){_t(t,l),t.restore();return}t.save(),t.translate(l.originX,l.originY),t.scale(l.scale,l.scale);const m=n.rtl===!0?ee(t,l):null,y=new Vt(t,p,n,e),{headingW:h,headingH:k,titleW:g,titleH:w,titleRows:F,titleCols:M,r0:b,r1:C,c0:O,c1:D,area:z}=l;y.titleRows=F,y.titleCols=M;const N=e.gridLines&&!e.draft;e.headings&&Zt(y,l,E(r,r.fontSize));const R=s.objectPainters??null,x=e.cellComments==="asDisplayed"&&n.comments?.size>0,S=R&&R.length>0||x?f=>{const u=f.x-n.cols.offsetOf(f.c0),c=f.y-n.rows.offsetOf(f.r0),T={printing:!0,dpr:1,zoom:1,hx:f.x,hy:f.y,cssW:f.x+n.cols.offsetOf(f.c1+1)-n.cols.offsetOf(f.c0),cssH:f.y+n.rows.offsetOf(f.r1+1)-n.rows.offsetOf(f.r0),toScreen:(A,I)=>({x:u+A,y:c+I}),sheet:n};for(const A of R??[])A(t,T);x&&Bt(t,n,T.toScreen,f)}:null;if(l.chartBox){if(R){const f={printing:!0,dpr:1,zoom:1,hx:0,hy:0,cssW:l.bodyW,cssH:l.bodyH,toScreen:(u,c)=>({x:u,y:c}),sheet:n,chartBox:l.chartBox};for(const u of R)u(t,f)}t.restore(),t.restore();return}const P=h+g,o=k+w,a=(f,u)=>{s.objectsOnly?(t.save(),t.beginPath(),t.rect(f.x,f.y,n.cols.offsetOf(f.c1+1)-n.cols.offsetOf(f.c0),n.rows.offsetOf(f.r1+1)-n.rows.offsetOf(f.r0)),t.clip(),S?.(f),t.restore()):Jt(y,f,N,u,S),t.link&&s.onPlace&&Et(t,p,n,f,s.onPlace)};a({x:P,y:o,r0:b,r1:C,c0:O,c1:D},z.c0),F&&a({x:P,y:k,r0:F.r0,r1:F.r1,c0:O,c1:D},z.c0),M&&a({x:h,y:o,r0:b,r1:C,c0:M.c0,c1:M.c1},M.c0),F&&M&&a({x:h,y:k,r0:F.r0,r1:F.r1,c0:M.c0,c1:M.c1},M.c0),m?.(),t.restore(),t.restore()}function Ce(t,i,l,{pxPerPt:s=2,...p}={}){const n=i.at(l);if(n===null)return null;const{page:e,pagination:r}=n;t.width=Math.max(1,Math.round(e.paperW*s)),t.height=Math.max(1,Math.round(e.paperH*s));const d=t.getContext("2d",{alpha:!1});return d.setTransform(s,0,0,s,0,0),lt(d,r,e,{pageNumber:n.pageNumber,totalPages:n.totalPages,sheetPage:n.sheetPage,...p}),n}const ne=()=>new Promise(t=>setTimeout(t,0)),oe={gray0625:.0625,gray125:.125,lightGray:.25,mediumGray:.5,darkGray:.75,lightHorizontal:.25,lightVertical:.25,lightDown:.25,lightUp:.25,lightGrid:.44,lightTrellis:.5,darkHorizontal:.5,darkVertical:.5,darkDown:.5,darkUp:.5,darkGrid:.5,darkTrellis:.75};function ft(t){if(!t.pattern)return t.fill;const i=oe[t.pattern.type]??.5,l=s=>{const p=parseInt(t.pattern.fg.slice(s,s+2),16),n=parseInt(t.fill.slice(s,s+2),16);return Math.round(p*i+n*(1-i)).toString(16).padStart(2,"0")};return`#${l(1)}${l(3)}${l(5)}`}async function Fe(t,i,l={}){const{title:s,author:p,subject:n,fonts:e,compress:r,tagged:d=!0,lang:m,openPassword:y,permissionsPassword:h,permissions:k,signal:g,onProgress:w,...F}=l,[{PdfWriter:M}]=await Promise.all([import("./pdf.js"),It(t)]),b=new M(i,{title:s,author:p,subject:n,fonts:e,compress:r,tagged:d,lang:m,openPassword:y,permissionsPassword:h,permissions:k}),C=F.now??new Date;let O=performance.now();const D=new Map,z=(R,x,S)=>{const P=`${t.book.sheets.indexOf(R)}:${x}:${S}`;if(!D.has(P)){const o=t.entries.find(f=>f.sheet===R),a=o?o.pagination.pageAt(x,S):-1;if(D.set(P,a<0?null:`L${D.size}`),a>=0){const f=o.pagination.page(a),u=f.headingH+f.titleH+R.rows.offsetOf(x)-R.rows.offsetOf(f.r0);b.destination(D.get(P),o.first+a,f.paperH-f.originY-u*f.scale)}}return D.get(P)};let N=null;for(let R=0;R<t.pageCount;R++){g?.throwIfAborted();const x=t.at(R),{page:S,pagination:P}=x;P.sheet!==N&&(N=P.sheet,b.bookmark(N.name,R),b.section(N.name));const o=b.beginPage(S.paperW,S.paperH);lt(o,P,S,{...F,now:C,onPlace:z,background:!1,pageNumber:x.pageNumber,totalPages:x.totalPages,sheetPage:x.sheetPage}),await b.endPage(),w?.(R+1,t.pageCount),performance.now()-O>12&&(await ne(),O=performance.now())}return b.bookmarks.length<2&&(b.bookmarks.length=0),await b.finish(),{pages:b.pageCount,bytes:b.offset,missing:[...b.missing],fontWarnings:b.fontWarnings}}export{Yt as displayText,te as paintHeaderFooter,Ce as renderJobPageToCanvas,lt as renderPage,Fe as writeJobPdf};
@@ -0,0 +1 @@
1
+ import{noteBox as O,noteCorner as E,noteDisplayText as N,isThread as $}from"../cells/note-box.js";import{MAX_COLS as M}from"../core/address.js";function g(o){const t=[];for(const[i,e]of o.comments??[]){if(!e.visible||$(e))continue;const a=Math.floor(i/M),s=i-a*M;o.rows.sizeOf(a)===0||o.cols.sizeOf(s)===0||t.push({row:a,col:s,note:e,box:O(o,a,s,e)})}return t}function v(o){let t=-1,i=-1;for(const{box:e}of g(o))t=Math.max(t,o.rows.indexAt(Math.max(0,e.y+e.h-.01))),i=Math.max(i,o.cols.indexAt(Math.max(0,e.x+e.w-.01)));return t<0?null:{r1:t,c1:i}}function z(o,t,i){const e=[];for(const a of String(t).split(/\r?\n/)){let s="";for(const w of a.split(/(?<=\s)/)){let f=w;for(s&&o.measureText((s+f).trimEnd()).width>i&&(e.push(s.trimEnd()),s="");f.length>1&&o.measureText(f.trimEnd()).width>i;){let h=1;for(;h<f.length&&o.measureText(f.slice(0,h+1)).width<=i;)h++;e.push(f.slice(0,h)),f=f.slice(h)}s+=f}e.push(s.trimEnd())}return e}function P(o,t,i,e){const a=t.cols.offsetOf(e.c0),s=t.cols.offsetOf(e.c1+1),w=t.rows.offsetOf(e.r0),f=t.rows.offsetOf(e.r1+1);for(const{row:h,col:k,note:b,box:n}of g(t)){const c=E(t,h,k);if(Math.min(n.x,c.x)>s||n.x+n.w<a||Math.min(n.y,c.y)>f||n.y+n.h<w)continue;const r=b.style??{},l=i(n.x,n.y),p=i(c.x,c.y);o.save(),o.marks&&o.beginParagraph(),o.strokeStyle=r.borderColor??"#808080",o.lineWidth=.75,o.beginPath(),o.moveTo(p.x,p.y),o.lineTo(l.x,Math.min(l.y+n.h,Math.max(l.y,p.y))),o.stroke(),o.fillStyle=r.backColor??"#ffffe1",o.fillRect(l.x,l.y,n.w,n.h),r.borderStyle!=="none"&&(o.lineWidth=r.borderWidth??1,o.strokeRect(l.x,l.y,n.w,n.h)),o.beginPath(),o.rect(l.x,l.y,n.w,n.h),o.clip();const y=r.fontSize??10,S=r.fontName?`"${r.fontName}", Tahoma, sans-serif`:"Tahoma, Verdana, sans-serif";o.font=`${r.italic?"italic ":""}${r.bold?"bold ":""}${y}px ${S}`,o.fillStyle=r.color??"#000000",o.textBaseline="alphabetic",o.textAlign="left";const d=3;let u=l.y+d+y;for(const m of z(o,N(b),n.w-2*d)){if(u-y>l.y+n.h)break;const T=n.w-2*d-o.measureText(m).width,x=l.x+d+(r.align==="center"?T/2:r.align==="right"?T:0);m&&o.fillText(m,x,u),r.underline&&m&&o.fillRect(x,u+1.5,o.measureText(m).width,.75),u+=y*1.2}o.marks&&o.endMark(),o.restore()}}export{P as paintShownNotes,g as shownNotes,v as shownNotesExtent};
@@ -1 +1 @@
1
- import{child as O,children as M,parseTree as E,unescapeXml as I}from"../io/xml-scan.js";import{relsPathOf as B,resolveTarget as N}from"../io/package-paths.js";import{XML_HEAD as w,parseXml as z}from"../objects/dml.js";import{escapeMarkup as x,xmlLiteralText as y}from"../io/xml-escape.js";import{parseRels as V}from"../objects/drawing-xml.js";const k="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",q="http://schemas.openxmlformats.org/markup-compatibility/2006",W="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",X="http://schemas.microsoft.com/office/drawing/2010/main",ce="http://schemas.openxmlformats.org/officeDocument/2006/relationships/ctrlProp",xe="http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing",me="application/vnd.ms-excel.controlproperties+xml",fe="application/vnd.openxmlformats-officedocument.vmlDrawing",$={button:{objectType:"Button",label:"Button",vml:"Button"},spin:{objectType:"Spin",label:"Spinner",vml:"Spin"},scroll:{objectType:"Scroll",label:"Scroll Bar",vml:"Scroll"},list:{objectType:"List",label:"List Box",vml:"List"},check:{objectType:"CheckBox",label:"Check Box",vml:"Checkbox"},radio:{objectType:"Radio",label:"Option Button",vml:"Radio"},label:{objectType:"Label",label:"Label",vml:"Label"},group:{objectType:"GBox",label:"Group Box",vml:"GBox"},drop:{objectType:"Drop",label:"Drop Down",ui:"Combo Box",vml:"Drop"}},H=Object.fromEntries(Object.entries($).map(([e,o])=>[o.objectType,e])),b=Object.fromEntries(Object.entries($).map(([e,o])=>[o.vml,e]));function de(e){const o=$[e].objectType;switch(e){case"button":case"label":return{objectType:o,lockText:"1"};case"check":case"radio":return{objectType:o,lockText:"1",noThreeD:"1",...e==="radio"?{firstButton:"1"}:{}};case"group":return{objectType:o,noThreeD:"1"};case"spin":return{objectType:o,dx:"15",inc:"1",max:"100",min:"0",page:"10",val:"0"};case"scroll":return{objectType:o,dx:"15",horiz:"1",inc:"1",max:"100",min:"0",page:"10",val:"0"};case"list":return{objectType:o,dx:"15",noThreeD:"1",sel:"0",val:"0"};default:return{objectType:o,dropStyle:"combo",dx:"15",noThreeD:"1",sel:"0",val:"0",dropLines:"8"}}}function Y(e){return H[e?.objectType]??null}function G(e){const o=z(e),t={...o.root.a};delete t.xmlns;for(const s of Object.keys(t))s.startsWith("xmlns")&&delete t[s];const n=M(O(o.root,"itemLst"),"item").map(s=>s.a.val??"");return{attrs:t,items:n.length?n:void 0}}function he(e){const o=Object.entries(e.attrs).filter(([,n])=>n!=null).map(([n,s])=>` ${n}="${x(s)}"`).join(""),t=e.items?.length?`<itemLst>${e.items.map(n=>`<item val="${x(n)}"/>`).join("")}</itemLst>`:"";return`${w}<formControlPr xmlns="${k}"${o}${t?`>${t}</formControlPr>`:"/>"}`}const U=/<v:(?:shape|rect|roundrect|oval|line)\b[^>]*\bid="_x0000_s(\d+)"[\s\S]*?<\/v:(?:shape|rect|roundrect|oval|line)>/g;function g(e,o){const t=new RegExp(`<x:${o}>([\\s\\S]*?)</x:${o}>`).exec(e);return t?t[1].trim():void 0}function J(e,o){const t=b[o],n={objectType:$[t].objectType},s={FmlaLink:"fmlaLink",FmlaRange:"fmlaRange",Val:"val",Min:"min",Max:"max",Inc:"inc",Page:"page",Dx:"dx",Sel:"sel",DropLines:"dropLines",Checked:"checked",FmlaTxbx:"fmlaTxbx",FmlaMacro:"macro"};for(const[p,m]of Object.entries(s)){const l=g(e,p);l!==void 0&&(n[m]=I(l))}/<x:Horiz\s*\/>/.test(e)&&(n.horiz="1"),/<x:NoThreeD2?\s*\/>/.test(e)&&(n.noThreeD="1"),/<x:FirstButton\s*\/>/.test(e)&&(n.firstButton="1");const r=g(e,"SelType");r&&r!=="Single"&&(n.selType=r.toLowerCase());const a=g(e,"DropStyle");return a&&(n.dropStyle=a.toLowerCase()),n}function K(e){const o=new Map;for(const t of e.matchAll(U)){const n=t[0],s=/ObjectType="(\w+)"/.exec(n)?.[1];!s||!b[s]||o.set(Number(t[1]),{type:b[s],attrs:J(n,s),printObject:g(n,"PrintObject")!=="False",disabled:/<x:Disabled>True/.test(n)||/<x:Disabled\s*\/>/.test(n)})}return o}async function Q(e){const o=e.pipeThrough(new TextDecoderStream).getReader();let t="";const n=1<<20;for(;;){const{value:a,done:p}=await o.read();if(p)break;t+=a,t.length>n*2&&(t=t.slice(-n))}const s=new Map,r=t.lastIndexOf("<controls");if(r<0)return s;for(const a of t.slice(r).matchAll(/<control\b([^>]*)>/g)){const p=/shapeId="(\d+)"/.exec(a[1])?.[1],m=/r:id="([^"]+)"/.exec(a[1])?.[1];p&&m&&s.set(Number(p),{rid:m,name:/name="([^"]*)"/.exec(a[1])?.[1]})}return s}async function ue(e,o){const t=B(o);if(!e.has(t))return null;const n=V(await e.bytes(t)),s=l=>N(o,l),r=n.filter(l=>/\/ctrlProp$/.test(l.type)),a=n.find(l=>/\/vmlDrawing$/.test(l.type));if(r.length===0&&!a)return null;const p=new Map,m=a?s(a.target):null;if(m&&e.has(m))for(const[l,i]of K(await e.text(m)))p.set(l,{...i,vmlPath:m});if(r.length>0){const l=await Q(await e.stream(o)),i=new Map(r.map(d=>[d.id,s(d.target)]));for(const[d,h]of l){const c=i.get(h.rid);if(!c||!e.has(c))continue;const f=G(await e.bytes(c)),u=Y(f.attrs);if(!u)continue;const T=p.get(d);p.set(d,{...T??{},type:u,attrs:f.attrs,items:f.items,path:c,rid:h.rid,vmlPath:m,name:h.name})}}return p.size>0?p:null}const _='<v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><v:stroke joinstyle="miter"/><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"/><v:f eqn="sum @0 1 0"/><v:f eqn="sum 0 0 @1"/><v:f eqn="prod @2 1 2"/><v:f eqn="prod @3 21600 pixelWidth"/><v:f eqn="prod @3 21600 pixelHeight"/><v:f eqn="sum @0 0 1"/><v:f eqn="prod @6 1 2"/><v:f eqn="prod @7 21600 pixelWidth"/><v:f eqn="sum @8 21600 0"/><v:f eqn="prod @7 21600 pixelHeight"/><v:f eqn="sum @10 21600 0"/></v:formulas><v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/><o:lock v:ext="edit" aspectratio="t"/></v:shapetype>';function L(e,o){const t=e.rect,n=`position:absolute;margin-left:${t.x}pt;margin-top:${t.y}pt;width:${t.w}pt;height:${t.h}pt;z-index:${o};visibility:visible`;return`<v:shape id="Picture_x0020_${e.shapeId}" o:spid="_x0000_s${e.shapeId}" type="#_x0000_t75" style="${n}"><v:imagedata o:relid="${x(e.relId)}" o:title=""/><x:ClientData ObjectType="Pict"><x:SizeWithCells/><x:Anchor>${S(e.anchor)}</x:Anchor><x:FmlaPict>${x(e.range)}</x:FmlaPict><x:CF>Pict</x:CF><x:Camera/></x:ClientData></v:shape>`}const P='<v:shapetype id="_x0000_t201" coordsize="21600,21600" o:spt="201" path="m,l,21600r21600,l21600,xe"><v:stroke joinstyle="miter"/><v:path shadowok="f" o:extrusionok="f" strokeok="f" fillok="f" o:connecttype="rect"/><o:lock v:ext="edit" shapetype="t"/></v:shapetype>';function v(e){return Math.round(e/12700)}function S(e){return`${e.from.col}, ${v(e.from.colOff)}, ${e.from.row}, ${v(e.from.rowOff)}, ${e.to.col}, ${v(e.to.colOff)}, ${e.to.row}, ${v(e.to.rowOff)}`}const $e=e=>e?"True":"False";function D(e,o){const t=e.attrs,n=e.rect,s=`position:absolute;margin-left:${n.x}pt;margin-top:${n.y}pt;width:${n.w}pt;height:${n.h}pt;z-index:${o}`,r=[];if(e.moveWithCells===!1&&r.push("<x:MoveWithCells/>"),e.sizeWithCells===!1&&r.push("<x:SizeWithCells/>"),r.push(`<x:Anchor>${S(e.anchor)}</x:Anchor>`),e.print===!1&&r.push("<x:PrintObject>False</x:PrintObject>"),(e.type==="check"||e.type==="radio")&&r.push("<x:AutoFill>False</x:AutoFill>","<x:AutoLine>False</x:AutoLine>","<x:TextVAlign>Center</x:TextVAlign>"),e.type==="button"&&r.push("<x:AutoFill>False</x:AutoFill>","<x:TextHAlign>Center</x:TextHAlign>","<x:TextVAlign>Center</x:TextVAlign>"),(e.type==="label"||e.type==="drop")&&r.push("<x:AutoFill>False</x:AutoFill>"),t.fmlaLink&&r.push(`<x:FmlaLink>${x(t.fmlaLink)}</x:FmlaLink>`),t.fmlaTxbx&&r.push(`<x:FmlaTxbx>${x(t.fmlaTxbx)}</x:FmlaTxbx>`),e.macro&&r.push(`<x:FmlaMacro>${x(e.macro)}</x:FmlaMacro>`),(e.type==="check"||e.type==="radio")&&(t.checked&&t.checked!=="Unchecked"&&t.checked!=="0"&&r.push(`<x:Checked>${t.checked==="Mixed"||t.checked==="2"?2:1}</x:Checked>`),t.noThreeD&&r.push("<x:NoThreeD/>"),t.firstButton&&r.push("<x:FirstButton/>")),e.type==="group"&&t.noThreeD&&r.push("<x:NoThreeD/>"),(e.type==="spin"||e.type==="scroll"||e.type==="list"||e.type==="drop")&&(r.push(`<x:Val>${x(t.val??0)}</x:Val>`,`<x:Min>${x(t.min??0)}</x:Min>`,`<x:Max>${x(t.max??100)}</x:Max>`,`<x:Inc>${x(t.inc??1)}</x:Inc>`,`<x:Page>${x(t.page??10)}</x:Page>`),t.horiz&&r.push("<x:Horiz/>"),r.push(`<x:Dx>${x(t.dx??15)}</x:Dx>`)),e.type==="list"||e.type==="drop"){t.fmlaRange&&r.push(`<x:FmlaRange>${x(t.fmlaRange)}</x:FmlaRange>`),r.push(`<x:Sel>${x(t.sel??0)}</x:Sel>`),t.noThreeD&&r.push("<x:NoThreeD2/>");const i=t.selType??"single";r.push(`<x:SelType>${i[0].toUpperCase()}${i.slice(1)}</x:SelType>`,"<x:LCT>Normal</x:LCT>"),e.type==="drop"&&r.push(`<x:DropStyle>${(t.dropStyle??"combo")[0].toUpperCase()}${(t.dropStyle??"combo").slice(1)}</x:DropStyle>`,`<x:DropLines>${x(t.dropLines??8)}</x:DropLines>`)}let a="";const p=e.type==="button"||e.type==="check"||e.type==="radio"||e.type==="label"||e.type==="group";p&&(a=`<v:textbox style="mso-direction-alt:auto" o:singleclick="f"><div style="text-align:${e.type==="button"?"center":"left"};direction:ltr"><font face="Calibri" size="220" color="auto">${y(e.text??"")}</font></div></v:textbox>`);const m=e.type==="button"?' fillcolor="#f0f0f0 [67]"':e.type==="check"||e.type==="radio"?' filled="f" stroked="f"':e.type==="label"?' filled="f"':"",l=p?'<o:lock v:ext="edit" rotation="t"/>':'<o:lock v:ext="edit" rotation="t" text="t"/>';return`<v:shape id="_x0000_s${e.shapeId}" type="#_x0000_t201" style="${s}"${m} o:insetmode="auto">${l}${a}<x:ClientData ObjectType="${$[e.type].vml}">${r.join("")}</x:ClientData></v:shape>`}function j(e,o,t=[]){const n=e.map((r,a)=>D(r,a+1)).join(""),s=t.map((r,a)=>L(r,e.length+a+1)).join("");return`<xml xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"><o:shapelayout v:ext="edit"><o:idmap v:ext="edit" data="${o}"/></o:shapelayout>${P}${t.length?_:""}${n}${s}</xml>`}function Z(e,o,t,n=[]){let s=e.replace(/<v:(shape|rect|roundrect|oval|line)\b(?:(?!<\/v:\1>)[\s\S])*?<\/v:\1>/g,l=>{const i=/ObjectType="(\w+)"/.exec(l)?.[1];return i==="Pict"&&/<x:Camera\s*\/>/.test(l)||i&&b[i]?"":l});const r=new Set([...o,...n].map(l=>l.shapeId));let a=Math.max(1024,...r);for(const l of s.matchAll(/_x0000_s(\d+)/g))a=Math.max(a,Number(l[1]));s=s.replace(/id="_x0000_s(\d+)"/g,(l,i)=>r.has(Number(i))?`id="_x0000_s${++a}"`:l),o.length&&!/id="_x0000_t201"/.test(s)&&(s=s.replace("</xml>",`${P}</xml>`)),n.length&&!/id="_x0000_t75"/.test(s)&&(s=s.replace("</xml>",`${_}</xml>`)),t!==void 0&&(s=s.replace(/(<o:idmap\b[^>]*data=")([^"]*)(")/,(l,i,d,h)=>{const c=new Set(String(d).split(",").filter(Boolean));for(const f of String(t).split(","))c.add(f);return`${i}${[...c].join(",")}${h}`}));let p=1;for(const l of s.matchAll(/z-index:(\d+)/g))p=Math.max(p,Number(l[1])+1);const m=n.map((l,i)=>L(l,p+o.length+i)).join("");return s.replace("</xml>",`${o.map((l,i)=>D(l,p+i)).join("")}${m}</xml>`)}const F=(e,o)=>`<${e}><xdr:col>${o.col}</xdr:col><xdr:colOff>${Math.round(o.colOff)}</xdr:colOff><xdr:row>${o.row}</xdr:row><xdr:rowOff>${Math.round(o.rowOff)}</xdr:rowOff></${e}>`;function ee(e){const o=e.moveWithCells===!1?"":' moveWithCells="1"',t=e.sizeWithCells===!1?"":' sizeWithCells="1"',n=[' defaultSize="0"',e.print===!1?' print="0"':"",e.locked===!1?' locked="0"':"",e.type==="check"||e.type==="radio"||e.type==="button"||e.type==="label"||e.type==="drop"?' autoFill="0"':"",e.type==="check"||e.type==="radio"?' autoLine="0"':"",' autoPict="0"',e.macro?` macro="${x(e.macro)}"`:"",e.altText?` altText="${y(e.altText)}"`:""].join("");return`<mc:AlternateContent><mc:Choice Requires="x14"><control shapeId="${e.shapeId}" r:id="${x(e.rid)}" name="${x(e.name)}"><controlPr${n}><anchor${o}${t}>${F("from",e.anchor.from)}${F("to",e.anchor.to)}</anchor></controlPr></control></mc:Choice></mc:AlternateContent>`}function te(e){return e.length===0?"":`<mc:AlternateContent xmlns:mc="${q}" xmlns:x14="${k}" xmlns:xdr="${W}"><mc:Choice Requires="x14"><controls>${e.map(ee).join("")}</controls></mc:Choice></mc:AlternateContent>`}function oe(e){return e.replace(/<mc:AlternateContent\b[^>]*>\s*<mc:Choice\b[^>]*>\s*<controls\b[\s\S]*?<\/controls>\s*<\/mc:Choice>\s*(?:<mc:Fallback\b[\s\S]*?<\/mc:Fallback>\s*)?<\/mc:AlternateContent>/,"").replace(/<controls\b[\s\S]*?<\/controls>/,"")}const ne=/<(?:legacyDrawingHF|picture|oleObjects|mc:AlternateContent|controls|webPublishItems|tableParts|extLst)\b|<\/worksheet>/,re=/<(?:webPublishItems|tableParts|extLst)\b|<\/worksheet>/;function R(e,o,t){const n=o.exec(e);return n?e.slice(0,n.index)+t+e.slice(n.index):e+t}async function ye(e,o,t){const{source:n,relsName:s,addRel:r,extraParts:a}=t;let p=oe(e);const m=n?.zip.has(s)?await n.zip.text(s):"";for(const c of o.parts)a.push({path:c.path,xml:c.xml});for(const c of o.newRels)m.includes(`Id="${c.id}"`)||r(c.id,"ctrlProp",c.target,!1);const l=/<legacyDrawing\b[^>]*r:id="([^"]+)"/.exec(p)?.[1];let i=null;if(l){const c=`${m}${(t.pendingRels??[]).join("")}`,f=new RegExp(`<Relationship\\b[^>]*Id="${l}"[^>]*/>`).exec(c),u=f&&/Target="([^"]+)"/.exec(f[0])?.[1];u&&(i=t.resolveTarget(t.part,u))}const d=i?a.find(c=>c.path===i):null,h=o.cameras??[];if(i){const c=d?d.xml:n?.zip.has(i)?await n.zip.text(i):null,f=c?Z(c,o.items,o.idmap,h):j(o.items,o.idmap,h);d?d.xml=f:a.push({path:i,xml:f})}else(o.items.length>0||h.length>0)&&(i=o.vmlPath,a.push({path:i,xml:j(o.items,o.idmap,h)}),m.includes(`Id="${o.vmlRelId}"`)||r(o.vmlRelId,"vmlDrawing",t.relativeTo(t.part,i),!1),p=R(p,ne,`<legacyDrawing r:id="${o.vmlRelId}"/>`));if(h.length>0){const c=i.lastIndexOf("/"),f=`${i.slice(0,c)}/_rels/${i.slice(c+1)}.rels`,T=(n?.zip.has(f)?await n.zip.text(f):`${w}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>`).replace(/<Relationship\b[^>]*Id="rIdCam\d+"[^>]*\/>/g,""),A=h.map(C=>`<Relationship Id="${x(C.relId)}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="${x(t.relativeTo(i,C.imagePath))}"/>`).join("");a.push({path:f,xml:T.replace("</Relationships>",`${A}</Relationships>`)})}return o.items.length>0&&(p=R(p,re,te(o.items))),p}function be(e,o){return new RegExp(`id="_x0000_s${o}"`).test(e)}function ge(e,o){return`<xdr:sp macro="" textlink=""><xdr:nvSpPr><xdr:cNvPr id="${e.id}" name="${y(e.name??"")}" hidden="1"${e.descr?` descr="${y(e.descr)}"`:""}><a:extLst><a:ext uri="{63B3BB69-23CF-44E3-9099-C40C66FF867C}"><a14:compatExt xmlns:a14="${X}" spid="_x0000_s${e.id}"/></a:ext></a:extLst></xdr:cNvPr><xdr:cNvSpPr/></xdr:nvSpPr><xdr:spPr bwMode="auto"><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/><a:ln><a:noFill/></a:ln></xdr:spPr>${o}</xdr:sp>`}export{$ as CONTROL_TYPES,me as CTRL_CONTENT_TYPE,ce as CTRL_REL,X as NS_A14,q as NS_MC,k as NS_X14,W as NS_XDR,fe as VML_CONTENT_TYPE,xe as VML_REL,ye as applyControls,Y as controlTypeOf,te as controlsListXml,he as ctrlPropXml,de as newControlAttrs,j as newVmlXml,G as parseCtrlProp,E as parseTree,K as parseVmlControls,Z as patchVmlControls,ge as placeholderSpXml,ue as readSheetControls,oe as removeControlsList,Q as scanControlsList,L as vmlCameraXml,be as vmlHasShape,D as vmlShapeXml};
1
+ import{child as O,children as M,parseTree as E,unescapeXml as I}from"../io/xml-scan.js";import{relsPathOf as B,resolveTarget as N}from"../io/package-paths.js";import{XML_HEAD as w,parseXml as z}from"../objects/dml.js";import{escapeMarkup as x,xmlLiteralText as y}from"../io/xml-escape.js";import{parseRels as V}from"../objects/drawing-xml.js";const k="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",q="http://schemas.openxmlformats.org/markup-compatibility/2006",W="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",X="http://schemas.microsoft.com/office/drawing/2010/main",ce="http://schemas.openxmlformats.org/officeDocument/2006/relationships/ctrlProp",xe="http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing",me="application/vnd.ms-excel.controlproperties+xml",fe="application/vnd.openxmlformats-officedocument.vmlDrawing",$={button:{objectType:"Button",label:"Button",vml:"Button"},spin:{objectType:"Spin",label:"Spinner",vml:"Spin"},scroll:{objectType:"Scroll",label:"Scroll Bar",vml:"Scroll"},list:{objectType:"List",label:"List Box",vml:"List"},check:{objectType:"CheckBox",label:"Check Box",vml:"Checkbox"},radio:{objectType:"Radio",label:"Option Button",vml:"Radio"},label:{objectType:"Label",label:"Label",vml:"Label"},group:{objectType:"GBox",label:"Group Box",vml:"GBox"},drop:{objectType:"Drop",label:"Drop Down",ui:"Combo Box",vml:"Drop"}},H=Object.fromEntries(Object.entries($).map(([e,o])=>[o.objectType,e])),b=Object.fromEntries(Object.entries($).map(([e,o])=>[o.vml,e]));function de(e){const o=$[e].objectType;switch(e){case"button":case"label":return{objectType:o,lockText:"1"};case"check":case"radio":return{objectType:o,lockText:"1",noThreeD:"1",...e==="radio"?{firstButton:"1"}:{}};case"group":return{objectType:o,noThreeD:"1"};case"spin":return{objectType:o,dx:"15",inc:"1",max:"100",min:"0",page:"10",val:"0"};case"scroll":return{objectType:o,dx:"15",horiz:"1",inc:"1",max:"100",min:"0",page:"10",val:"0"};case"list":return{objectType:o,dx:"15",noThreeD:"1",sel:"0",val:"0"};default:return{objectType:o,dropStyle:"combo",dx:"15",noThreeD:"1",sel:"0",val:"0",dropLines:"8"}}}function Y(e){return H[e?.objectType]??null}function G(e){const o=z(e),t={...o.root.a};delete t.xmlns;for(const s of Object.keys(t))s.startsWith("xmlns")&&delete t[s];const n=M(O(o.root,"itemLst"),"item").map(s=>s.a.val??"");return{attrs:t,items:n.length?n:void 0}}function he(e){const o=Object.entries(e.attrs).filter(([,n])=>n!=null).map(([n,s])=>` ${n}="${x(s)}"`).join(""),t=e.items?.length?`<itemLst>${e.items.map(n=>`<item val="${x(n)}"/>`).join("")}</itemLst>`:"";return`${w}<formControlPr xmlns="${k}"${o}${t?`>${t}</formControlPr>`:"/>"}`}const U=/<v:(?:shape|rect|roundrect|oval|line)\b[^>]*\bid="_x0000_s(\d+)"[\s\S]*?<\/v:(?:shape|rect|roundrect|oval|line)>/g;function g(e,o){const t=new RegExp(`<x:${o}>([\\s\\S]*?)</x:${o}>`).exec(e);return t?t[1].trim():void 0}function J(e,o){const t=b[o],n={objectType:$[t].objectType},s={FmlaLink:"fmlaLink",FmlaRange:"fmlaRange",Val:"val",Min:"min",Max:"max",Inc:"inc",Page:"page",Dx:"dx",Sel:"sel",DropLines:"dropLines",Checked:"checked",FmlaTxbx:"fmlaTxbx",FmlaMacro:"macro"};for(const[p,m]of Object.entries(s)){const l=g(e,p);l!==void 0&&(n[m]=I(l))}/<x:Horiz\s*\/>/.test(e)&&(n.horiz="1"),/<x:NoThreeD2?\s*\/>/.test(e)&&(n.noThreeD="1"),/<x:FirstButton\s*\/>/.test(e)&&(n.firstButton="1");const r=g(e,"SelType");r&&r!=="Single"&&(n.selType=r.toLowerCase());const a=g(e,"DropStyle");return a&&(n.dropStyle=a.toLowerCase()),n}function K(e){const o=new Map;for(const t of e.matchAll(U)){const n=t[0],s=/ObjectType="(\w+)"/.exec(n)?.[1];!s||!b[s]||o.set(Number(t[1]),{type:b[s],attrs:J(n,s),printObject:g(n,"PrintObject")!=="False",disabled:/<x:Disabled>True/.test(n)||/<x:Disabled\s*\/>/.test(n)})}return o}async function Q(e){const o=e.pipeThrough(new TextDecoderStream).getReader();let t="";const n=1<<20;for(;;){const{value:a,done:p}=await o.read();if(p)break;t+=a,t.length>n*2&&(t=t.slice(-n))}const s=new Map,r=t.lastIndexOf("<controls");if(r<0)return s;for(const a of t.slice(r).matchAll(/<control\b([^>]*)>/g)){const p=/shapeId="(\d+)"/.exec(a[1])?.[1],m=/r:id="([^"]+)"/.exec(a[1])?.[1];p&&m&&s.set(Number(p),{rid:m,name:/name="([^"]*)"/.exec(a[1])?.[1]})}return s}async function ue(e,o){const t=B(o);if(!e.has(t))return null;const n=V(await e.bytes(t)),s=l=>N(o,l),r=n.filter(l=>/\/ctrlProp$/.test(l.type)),a=n.find(l=>/\/vmlDrawing$/.test(l.type));if(r.length===0&&!a)return null;const p=new Map,m=a?s(a.target):null;if(m&&e.has(m))for(const[l,i]of K(await e.text(m)))p.set(l,{...i,vmlPath:m});if(r.length>0){const l=await Q(await e.stream(o)),i=new Map(r.map(d=>[d.id,s(d.target)]));for(const[d,h]of l){const c=i.get(h.rid);if(!c||!e.has(c))continue;const f=G(await e.bytes(c)),u=Y(f.attrs);if(!u)continue;const T=p.get(d);p.set(d,{...T??{},type:u,attrs:f.attrs,items:f.items,path:c,rid:h.rid,vmlPath:m,name:h.name})}}return p.size>0?p:null}const _='<v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><v:stroke joinstyle="miter"/><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"/><v:f eqn="sum @0 1 0"/><v:f eqn="sum 0 0 @1"/><v:f eqn="prod @2 1 2"/><v:f eqn="prod @3 21600 pixelWidth"/><v:f eqn="prod @3 21600 pixelHeight"/><v:f eqn="sum @0 0 1"/><v:f eqn="prod @6 1 2"/><v:f eqn="prod @7 21600 pixelWidth"/><v:f eqn="sum @8 21600 0"/><v:f eqn="prod @7 21600 pixelHeight"/><v:f eqn="sum @10 21600 0"/></v:formulas><v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/><o:lock v:ext="edit" aspectratio="t"/></v:shapetype>';function L(e,o){const t=e.rect,n=`position:absolute;margin-left:${t.x}pt;margin-top:${t.y}pt;width:${t.w}pt;height:${t.h}pt;z-index:${o};visibility:visible`;return`<v:shape id="Picture_x0020_${e.shapeId}" o:spid="_x0000_s${e.shapeId}" type="#_x0000_t75" style="${n}"><v:imagedata o:relid="${x(e.relId)}" o:title=""/><x:ClientData ObjectType="Pict"><x:SizeWithCells/><x:Anchor>${S(e.anchor)}</x:Anchor><x:FmlaPict>${x(e.range)}</x:FmlaPict><x:CF>Pict</x:CF><x:Camera/></x:ClientData></v:shape>`}const P='<v:shapetype id="_x0000_t201" coordsize="21600,21600" o:spt="201" path="m,l,21600r21600,l21600,xe"><v:stroke joinstyle="miter"/><v:path shadowok="f" o:extrusionok="f" strokeok="f" fillok="f" o:connecttype="rect"/><o:lock v:ext="edit" shapetype="t"/></v:shapetype>';function v(e){return Math.round(e/12700)}function S(e){return`${e.from.col}, ${v(e.from.colOff)}, ${e.from.row}, ${v(e.from.rowOff)}, ${e.to.col}, ${v(e.to.colOff)}, ${e.to.row}, ${v(e.to.rowOff)}`}const $e=e=>e?"True":"False";function D(e,o){const t=e.attrs,n=e.rect,s=`position:absolute;margin-left:${n.x}pt;margin-top:${n.y}pt;width:${n.w}pt;height:${n.h}pt;z-index:${o}`,r=[];if(e.moveWithCells===!1&&r.push("<x:MoveWithCells/>"),e.sizeWithCells===!1&&r.push("<x:SizeWithCells/>"),r.push(`<x:Anchor>${S(e.anchor)}</x:Anchor>`),e.print===!1&&r.push("<x:PrintObject>False</x:PrintObject>"),(e.type==="check"||e.type==="radio")&&r.push("<x:AutoFill>False</x:AutoFill>","<x:AutoLine>False</x:AutoLine>","<x:TextVAlign>Center</x:TextVAlign>"),e.type==="button"&&r.push("<x:AutoFill>False</x:AutoFill>","<x:TextHAlign>Center</x:TextHAlign>","<x:TextVAlign>Center</x:TextVAlign>"),(e.type==="label"||e.type==="drop")&&r.push("<x:AutoFill>False</x:AutoFill>"),t.fmlaLink&&r.push(`<x:FmlaLink>${x(t.fmlaLink)}</x:FmlaLink>`),t.fmlaTxbx&&r.push(`<x:FmlaTxbx>${x(t.fmlaTxbx)}</x:FmlaTxbx>`),e.macro&&r.push(`<x:FmlaMacro>${x(e.macro)}</x:FmlaMacro>`),(e.type==="check"||e.type==="radio")&&(t.checked&&t.checked!=="Unchecked"&&t.checked!=="0"&&r.push(`<x:Checked>${t.checked==="Mixed"||t.checked==="2"?2:1}</x:Checked>`),t.noThreeD&&r.push("<x:NoThreeD/>"),t.firstButton&&r.push("<x:FirstButton/>")),e.type==="group"&&t.noThreeD&&r.push("<x:NoThreeD/>"),(e.type==="spin"||e.type==="scroll"||e.type==="list"||e.type==="drop")&&(r.push(`<x:Val>${x(t.val??0)}</x:Val>`,`<x:Min>${x(t.min??0)}</x:Min>`,`<x:Max>${x(t.max??100)}</x:Max>`,`<x:Inc>${x(t.inc??1)}</x:Inc>`,`<x:Page>${x(t.page??10)}</x:Page>`),t.horiz&&r.push("<x:Horiz/>"),r.push(`<x:Dx>${x(t.dx??15)}</x:Dx>`)),e.type==="list"||e.type==="drop"){t.fmlaRange&&r.push(`<x:FmlaRange>${x(t.fmlaRange)}</x:FmlaRange>`),r.push(`<x:Sel>${x(t.sel??0)}</x:Sel>`),t.noThreeD&&r.push("<x:NoThreeD2/>");const i=t.selType??"single";r.push(`<x:SelType>${i[0].toUpperCase()}${i.slice(1)}</x:SelType>`,"<x:LCT>Normal</x:LCT>"),e.type==="drop"&&r.push(`<x:DropStyle>${(t.dropStyle??"combo")[0].toUpperCase()}${(t.dropStyle??"combo").slice(1)}</x:DropStyle>`,`<x:DropLines>${x(t.dropLines??8)}</x:DropLines>`)}let a="";const p=e.type==="button"||e.type==="check"||e.type==="radio"||e.type==="label"||e.type==="group";p&&(a=`<v:textbox style="mso-direction-alt:auto" o:singleclick="f"><div style="text-align:${e.type==="button"?"center":"left"};direction:ltr"><font face="Calibri" size="220" color="auto">${y(e.text??"")}</font></div></v:textbox>`);const m=e.type==="button"?' fillcolor="#f0f0f0 [67]"':e.type==="check"||e.type==="radio"?' filled="f" stroked="f"':e.type==="label"?' filled="f"':"",l=p?'<o:lock v:ext="edit" rotation="t"/>':'<o:lock v:ext="edit" rotation="t" text="t"/>';return`<v:shape id="_x0000_s${e.shapeId}" type="#_x0000_t201" style="${s}"${m} o:insetmode="auto">${l}${a}<x:ClientData ObjectType="${$[e.type].vml}">${r.join("")}</x:ClientData></v:shape>`}function j(e,o,t=[]){const n=e.map((r,a)=>D(r,a+1)).join(""),s=t.map((r,a)=>L(r,e.length+a+1)).join("");return`<xml xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"><o:shapelayout v:ext="edit"><o:idmap v:ext="edit" data="${o}"/></o:shapelayout>${P}${t.length?_:""}${n}${s}</xml>`}function Z(e,o,t,n=[]){let s=e.replace(/<v:(shape|rect|roundrect|oval|line)\b(?:(?!<\/v:\1>)[\s\S])*?<\/v:\1>/g,l=>{const i=/ObjectType="(\w+)"/.exec(l)?.[1];return i==="Pict"&&/<x:Camera\s*\/>/.test(l)||i&&b[i]?"":l});const r=new Set([...o,...n].map(l=>l.shapeId));let a=Math.max(1024,...r);for(const l of s.matchAll(/_x0000_s(\d+)/g))a=Math.max(a,Number(l[1]));s=s.replace(/id="_x0000_s(\d+)"/g,(l,i)=>r.has(Number(i))?`id="_x0000_s${++a}"`:l),o.length&&!/id="_x0000_t201"/.test(s)&&(s=s.replace("</xml>",()=>`${P}</xml>`)),n.length&&!/id="_x0000_t75"/.test(s)&&(s=s.replace("</xml>",()=>`${_}</xml>`)),t!==void 0&&(s=s.replace(/(<o:idmap\b[^>]*data=")([^"]*)(")/,(l,i,d,h)=>{const c=new Set(String(d).split(",").filter(Boolean));for(const f of String(t).split(","))c.add(f);return`${i}${[...c].join(",")}${h}`}));let p=1;for(const l of s.matchAll(/z-index:(\d+)/g))p=Math.max(p,Number(l[1])+1);const m=n.map((l,i)=>L(l,p+o.length+i)).join("");return s.replace("</xml>",`${o.map((l,i)=>D(l,p+i)).join("")}${m}</xml>`)}const F=(e,o)=>`<${e}><xdr:col>${o.col}</xdr:col><xdr:colOff>${Math.round(o.colOff)}</xdr:colOff><xdr:row>${o.row}</xdr:row><xdr:rowOff>${Math.round(o.rowOff)}</xdr:rowOff></${e}>`;function ee(e){const o=e.moveWithCells===!1?"":' moveWithCells="1"',t=e.sizeWithCells===!1?"":' sizeWithCells="1"',n=[' defaultSize="0"',e.print===!1?' print="0"':"",e.locked===!1?' locked="0"':"",e.type==="check"||e.type==="radio"||e.type==="button"||e.type==="label"||e.type==="drop"?' autoFill="0"':"",e.type==="check"||e.type==="radio"?' autoLine="0"':"",' autoPict="0"',e.macro?` macro="${x(e.macro)}"`:"",e.altText?` altText="${y(e.altText)}"`:""].join("");return`<mc:AlternateContent><mc:Choice Requires="x14"><control shapeId="${e.shapeId}" r:id="${x(e.rid)}" name="${x(e.name)}"><controlPr${n}><anchor${o}${t}>${F("from",e.anchor.from)}${F("to",e.anchor.to)}</anchor></controlPr></control></mc:Choice></mc:AlternateContent>`}function te(e){return e.length===0?"":`<mc:AlternateContent xmlns:mc="${q}" xmlns:x14="${k}" xmlns:xdr="${W}"><mc:Choice Requires="x14"><controls>${e.map(ee).join("")}</controls></mc:Choice></mc:AlternateContent>`}function oe(e){return e.replace(/<mc:AlternateContent\b[^>]*>\s*<mc:Choice\b[^>]*>\s*<controls\b[\s\S]*?<\/controls>\s*<\/mc:Choice>\s*(?:<mc:Fallback\b[\s\S]*?<\/mc:Fallback>\s*)?<\/mc:AlternateContent>/,"").replace(/<controls\b[\s\S]*?<\/controls>/,"")}const ne=/<(?:legacyDrawingHF|picture|oleObjects|mc:AlternateContent|controls|webPublishItems|tableParts|extLst)\b|<\/worksheet>/,re=/<(?:webPublishItems|tableParts|extLst)\b|<\/worksheet>/;function R(e,o,t){const n=o.exec(e);return n?e.slice(0,n.index)+t+e.slice(n.index):e+t}async function ye(e,o,t){const{source:n,relsName:s,addRel:r,extraParts:a}=t;let p=oe(e);const m=n?.zip.has(s)?await n.zip.text(s):"";for(const c of o.parts)a.push({path:c.path,xml:c.xml});for(const c of o.newRels)m.includes(`Id="${c.id}"`)||r(c.id,"ctrlProp",c.target,!1);const l=/<legacyDrawing\b[^>]*r:id="([^"]+)"/.exec(p)?.[1];let i=null;if(l){const c=`${m}${(t.pendingRels??[]).join("")}`,f=new RegExp(`<Relationship\\b[^>]*Id="${l}"[^>]*/>`).exec(c),u=f&&/Target="([^"]+)"/.exec(f[0])?.[1];u&&(i=t.resolveTarget(t.part,u))}const d=i?a.find(c=>c.path===i):null,h=o.cameras??[];if(i){const c=d?d.xml:n?.zip.has(i)?await n.zip.text(i):null,f=c?Z(c,o.items,o.idmap,h):j(o.items,o.idmap,h);d?d.xml=f:a.push({path:i,xml:f})}else(o.items.length>0||h.length>0)&&(i=o.vmlPath,a.push({path:i,xml:j(o.items,o.idmap,h)}),m.includes(`Id="${o.vmlRelId}"`)||r(o.vmlRelId,"vmlDrawing",t.relativeTo(t.part,i),!1),p=R(p,ne,`<legacyDrawing r:id="${o.vmlRelId}"/>`));if(h.length>0){const c=i.lastIndexOf("/"),f=`${i.slice(0,c)}/_rels/${i.slice(c+1)}.rels`,T=(n?.zip.has(f)?await n.zip.text(f):`${w}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>`).replace(/<Relationship\b[^>]*Id="rIdCam\d+"[^>]*\/>/g,""),A=h.map(C=>`<Relationship Id="${x(C.relId)}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="${x(t.relativeTo(i,C.imagePath))}"/>`).join("");a.push({path:f,xml:T.replace("</Relationships>",()=>`${A}</Relationships>`)})}return o.items.length>0&&(p=R(p,re,te(o.items))),p}function be(e,o){return new RegExp(`id="_x0000_s${o}"`).test(e)}function ge(e,o){return`<xdr:sp macro="" textlink=""><xdr:nvSpPr><xdr:cNvPr id="${e.id}" name="${y(e.name??"")}" hidden="1"${e.descr?` descr="${y(e.descr)}"`:""}><a:extLst><a:ext uri="{63B3BB69-23CF-44E3-9099-C40C66FF867C}"><a14:compatExt xmlns:a14="${X}" spid="_x0000_s${e.id}"/></a:ext></a:extLst></xdr:cNvPr><xdr:cNvSpPr/></xdr:nvSpPr><xdr:spPr bwMode="auto"><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/><a:ln><a:noFill/></a:ln></xdr:spPr>${o}</xdr:sp>`}export{$ as CONTROL_TYPES,me as CTRL_CONTENT_TYPE,ce as CTRL_REL,X as NS_A14,q as NS_MC,k as NS_X14,W as NS_XDR,fe as VML_CONTENT_TYPE,xe as VML_REL,ye as applyControls,Y as controlTypeOf,te as controlsListXml,he as ctrlPropXml,de as newControlAttrs,j as newVmlXml,G as parseCtrlProp,E as parseTree,K as parseVmlControls,Z as patchVmlControls,ge as placeholderSpXml,ue as readSheetControls,oe as removeControlsList,Q as scanControlsList,L as vmlCameraXml,be as vmlHasShape,D as vmlShapeXml};
@@ -1 +1 @@
1
- import{EXT as k,NS as W}from"./format.js";import{parseNode as K}from"../pivot/xml.js";import{xmlAttr as _}from"../io/xml-escape.js";import{dxfXml as G,parseDxfs as Y}from"../io/xlsx-tail.js";import{resolveColor as q}from"../io/xlsx-styles.js";import{bandRow as J}from"../core/tables.js";const j="{46F421CA-312F-682f-3DD2-61675219B42D}",U="{A0A4C193-F2C1-4fcb-8827-314CF55A85BB}",V=(e,l)=>e?.c?.find(i=>i.n===l)??null,Q=(e,l)=>e?e.c.filter(i=>i.n===l):[],v=e=>e.slice(e.indexOf(":")+1),Z=["wholeTable","headerRow","totalRow","firstColumn","lastColumn","firstRowStripe","secondRowStripe","firstColumnStripe","secondColumnStripe","firstHeaderCell","lastHeaderCell","firstTotalCell","lastTotalCell"],ee=["wholeTable","pageFieldLabels","pageFieldValues","firstColumnStripe","secondColumnStripe","firstRowStripe","secondRowStripe","firstColumn","headerRow","firstHeaderCell","firstSubtotalColumn","secondSubtotalColumn","thirdSubtotalColumn","blankRow","firstSubtotalRow","secondSubtotalRow","thirdSubtotalRow","firstColumnSubheading","secondColumnSubheading","thirdColumnSubheading","firstRowSubheading","secondRowSubheading","thirdRowSubheading","totalRow","lastColumn"],me=["unselectedItemWithData","selectedItemWithData","unselectedItemWithNoData","selectedItemWithNoData","hoveredUnselectedItemWithData","hoveredSelectedItemWithData","hoveredUnselectedItemWithNoData","hoveredSelectedItemWithNoData"],Se=["selectionLabel","timeLevel","periodLabel1","periodLabel2","selectedTimeBlock","unselectedTimeBlock","selectedTimeBlockSpace"];class te{constructor(){this.tableStyles=[],this.slicerStyles=[],this.timelineStyles=[],this.slicerDxfs=[],this.timelineDxfs=[],this.defaultTableStyle="TableStyleMedium2",this.defaultPivotStyle="PivotStyleLight16",this.defaultSlicerStyle="SlicerStyleLight1",this.defaultTimelineStyle="TimeSlicerStyleLight1",this.dirty=!1,this.version=0}find(l){return this.tableStyles.find(i=>i.name===l)??null}forTables(){return this.tableStyles.filter(l=>l.table)}forPivots(){return this.tableStyles.filter(l=>l.pivot)}setTableStyle(l,i,{table:d=!0,pivot:r=!1,elements:u={}}){const s=Object.entries(u).map(([o,f])=>({type:o,dxfId:le(l,f),...f.size?{size:f.size}:{}})),t={name:i,table:d,pivot:r,elements:s},a=this.tableStyles.findIndex(o=>o.name===i);return a>=0?this.tableStyles[a]=t:this.tableStyles.push(t),this.dirty=!0,this.version++,t}setSlicerStyle(l,i,{whole:d=null,header:r=null,elements:u={}}){this.setTableStyle(l,i,{table:!1,pivot:!1,elements:{...d?{wholeTable:d}:{},...r?{headerRow:r}:{}}});const s={name:i,elements:Object.entries(u).map(([a,o])=>({type:a,dxfId:this.slicerDxfs.push(o)-1}))},t=this.slicerStyles.findIndex(a=>a.name===i);return t>=0?this.slicerStyles[t]=s:this.slicerStyles.push(s),this.dirty=!0,s}setTimelineStyle(l,i,{whole:d=null,header:r=null,elements:u={}}){this.setTableStyle(l,i,{table:!1,pivot:!1,elements:{...d?{wholeTable:d}:{},...r?{headerRow:r}:{}}});const s={name:i,elements:Object.entries(u).map(([a,o])=>({type:a,dxfId:this.timelineDxfs.push(o)-1}))},t=this.timelineStyles.findIndex(a=>a.name===i);return t>=0?this.timelineStyles[t]=s:this.timelineStyles.push(s),this.dirty=!0,s}setDefaultTableStyle(l){return this.defaultTableStyle===l?!1:(this.defaultTableStyle=l,this.dirty=!0,this.version++,!0)}removeStyle(l){this.tableStyles=this.tableStyles.filter(i=>i.name!==l),this.slicerStyles=this.slicerStyles.filter(i=>i.name!==l),this.timelineStyles=this.timelineStyles.filter(i=>i.name!==l),this.dirty=!0,this.version++}savePlan(){return this.dirty?{tableStyles:this.tableStyles,slicerStyles:this.slicerStyles,timelineStyles:this.timelineStyles,slicerDxfs:this.slicerDxfs.map(G),timelineDxfs:this.timelineDxfs.map(G),defaultTableStyle:this.defaultTableStyle,defaultPivotStyle:this.defaultPivotStyle,defaultSlicerStyle:this.defaultSlicerStyle,defaultTimelineStyle:this.defaultTimelineStyle}:null}}function le(e,l){e.dxfs??=[];const{size:i,...d}=l;return e.dxfs.push(d),e.dxfs.length-1}const B=e=>(e?e.c.filter(l=>typeof l!="string"):[]).map(l=>({type:l.a.type,dxfId:Number(l.a.dxfId??-1),...l.a.size?{size:Number(l.a.size)}:{}})).filter(l=>l.dxfId>=0);function he(e,l=[]){const i=new te,d=typeof e=="string"?e:new TextDecoder().decode(e),r=t=>{const a=new RegExp(`<${t}:dxfs\\b[^>]*>([\\s\\S]*?)</${t}:dxfs>`).exec(d);return a?Y(new TextEncoder().encode(`<r><dxfs>${a[1]}</dxfs></r>`),o=>o?q(o,l):null):[]};i.slicerDxfs=r("x14"),i.timelineDxfs=r("x15");const u=K(e),s=V(u,"tableStyles");s&&(i.defaultTableStyle=s.a.defaultTableStyle??i.defaultTableStyle,i.defaultPivotStyle=s.a.defaultPivotStyle??i.defaultPivotStyle,i.tableStyles=Q(s,"tableStyle").map(t=>({name:t.a.name,table:t.a.table!=="0",pivot:t.a.pivot!=="0",elements:B(t)})));for(const t of V(u,"extLst")?.c??[])if(t.a?.uri===k.slicerStyles){const a=t.c.find(o=>v(o.n)==="slicerStyles");a&&(i.defaultSlicerStyle=a.a.defaultSlicerStyle??i.defaultSlicerStyle,i.slicerStyles=a.c.filter(o=>v(o.n)==="slicerStyle").map(o=>({name:o.a.name,elements:B(o.c.find(f=>v(f.n)==="slicerStyleElements"))})))}else if(t.a?.uri===k.timelineStyles){const a=t.c.find(o=>v(o.n)==="timelineStyles");a&&(i.defaultTimelineStyle=a.a.defaultTimelineStyle??i.defaultTimelineStyle,i.timelineStyles=a.c.filter(o=>v(o.n)==="timelineStyle").map(o=>({name:o.a.name,elements:B(o.c.find(f=>v(f.n)==="timelineStyleElements"))})))}return i}const H=(e,l)=>`<${e} type="${l.type}"${l.size?` size="${l.size}"`:""} dxfId="${l.dxfId}"/>`;function be(e,l){if(!l)return e;const i=n=>(l.slicerStyles.find(h=>h.name===n)?.elements.length??0)+(l.timelineStyles.find(h=>h.name===n)?.elements.length??0),d=`<tableStyles count="${l.tableStyles.length}" defaultTableStyle="${_(l.defaultTableStyle)}" defaultPivotStyle="${_(l.defaultPivotStyle)}"${l.tableStyles.length?`>${l.tableStyles.map(n=>`<tableStyle name="${_(n.name)}"${n.table?"":' table="0"'}${n.pivot?"":' pivot="0"'} count="${n.elements.length+i(n.name)}">${n.elements.map(h=>H("tableStyleElement",h)).join("")}</tableStyle>`).join("")}</tableStyles>`:"/>"}`;let r=e;if(/<tableStyles\b/.test(r))r=r.replace(/<tableStyles\b[^>]*?\/>|<tableStyles\b[\s\S]*?<\/tableStyles>/,d);else{const n=/<(?:colors|extLst)\b|<\/styleSheet>/.exec(r);r=`${r.slice(0,n.index)}${/<dxfs\b/.test(r)?"":'<dxfs count="0"/>'}${d}${r.slice(n.index)}`}const u=n=>{r=r.replace(new RegExp(`<ext\\b[^>]*uri="${n.replace(/[{}-]/g,"\\$&")}"[^>]*>[\\s\\S]*?</ext>`),"")};u(k.slicerStyles),u(k.timelineStyles),u(j),u(U);const s=(n,h,b,m)=>m.length?`<ext uri="${n}" xmlns:${h}="${b}"><${h}:dxfs count="${m.length}">${m.join("")}</${h}:dxfs></ext>`:"",t=`${s(j,"x14",W.x14,l.slicerDxfs)}`,a=`${s(U,"x15",W.x15,l.timelineDxfs)}`,o=`<ext uri="${k.slicerStyles}" xmlns:x14="${W.x14}"><x14:slicerStyles defaultSlicerStyle="${_(l.defaultSlicerStyle)}"${l.slicerStyles.length?`>${l.slicerStyles.map(n=>`<x14:slicerStyle name="${_(n.name)}"><x14:slicerStyleElements>${n.elements.map(h=>H("x14:slicerStyleElement",h)).join("")}</x14:slicerStyleElements></x14:slicerStyle>`).join("")}</x14:slicerStyles>`:"/>"}</ext>`,f=`<ext uri="${k.timelineStyles}" xmlns:x15="${W.x15}"><x15:timelineStyles defaultTimelineStyle="${_(l.defaultTimelineStyle)}"${l.timelineStyles.length?`>${l.timelineStyles.map(n=>`<x15:timelineStyle name="${_(n.name)}"><x15:timelineStyleElements>${n.elements.map(h=>H("x15:timelineStyleElement",h)).join("")}</x15:timelineStyleElements></x15:timelineStyle>`).join("")}</x15:timelineStyles>`:"/>"}</ext>`;return/<\/extLst>\s*<\/styleSheet>/.test(r)?r=r.replace(/<\/extLst>(\s*<\/styleSheet>)/,`${t}${o}${a}${f}</extLst>$1`):r=r.replace("</styleSheet>",`<extLst>${t}${o}${a}${f}</extLst></styleSheet>`),r}const O=(e,l,i,d=e.dxfs)=>{const r=l?.elements.find(u=>u.type===i);return r?d?.[r.dxfId]??{}:null},N=e=>{const l=e?.borders;return l?l.b?.color??l.t?.color??l.l?.color??l.r?.color??null:null},ie=["fill","color","bold","italic","underline","strike"],E=(e,l)=>{if(l)for(const i of ie)l[i]!==void 0&&(e[i]=l[i])},X=(e,l,i)=>e%(l+i)<l?0:1;function ye(e,l,i){const d=l?.find(i);if(!d)return null;const r=s=>d.elements.find(t=>t.type===s)?.size??1,u=Object.fromEntries(Z.map(s=>[s,O(e,d,s)]));return se(u,[r("firstRowStripe"),r("secondRowStripe")],[r("firstColumnStripe"),r("secondColumnStripe")],!0)}function se(e,l=[1,1],i=[1,1],d=!1){const r=(t,a,o)=>{const f={},n=t.r0+t.headerRows,h=t.r1-t.totalsRows,b=a>=n&&a<=h;return E(f,e.wholeTable),b&&(t.showColumnStripes&&E(f,X(o-t.c0,i[0],i[1])===0?e.firstColumnStripe:e.secondColumnStripe),t.showRowStripes!==!1&&E(f,X(J(t,a),l[0],l[1])===0?e.firstRowStripe:e.secondRowStripe)),t.showFirstColumn&&o===t.c0&&E(f,e.firstColumn),t.showLastColumn&&o===t.c1&&E(f,e.lastColumn),a<n?(E(f,e.headerRow),o===t.c0&&t.showFirstColumn&&E(f,e.firstHeaderCell),o===t.c1&&t.showLastColumn&&E(f,e.lastHeaderCell)):a>h&&(E(f,e.totalRow),o===t.c0&&t.showFirstColumn&&E(f,e.firstTotalCell),o===t.c1&&t.showLastColumn&&E(f,e.lastTotalCell)),f},u=(t,a,o,f,n)=>{const h=[],b=(R,w,y,T,S)=>{R?.borders&&T>=w&&S>=y&&h.push({borders:R.borders,r0:w,c0:y,r1:T,c1:S})},m=t.r0+t.headerRows,c=t.r1-t.totalsRows;if(b(e.wholeTable,t.r0,t.c0,t.r1,t.c1),t.showColumnStripes&&(e.firstColumnStripe?.borders||e.secondColumnStripe?.borders)){const R=i[0]+i[1];for(let w=t.c0;w<=Math.min(t.c1,n);w+=R)b(e.firstColumnStripe,m,w,c,Math.min(t.c1,w+i[0]-1)),b(e.secondColumnStripe,m,w+i[0],c,Math.min(t.c1,w+R-1))}if(t.showRowStripes!==!1&&(e.firstRowStripe?.borders||e.secondRowStripe?.borders)){const R=l[0]+l[1],w=m+Math.floor(Math.max(0,a-m)/R)*R;for(let y=w;y<=Math.min(c,o);y+=R)b(e.firstRowStripe,y,t.c0,Math.min(c,y+l[0]-1),t.c1),b(e.secondRowStripe,y+l[0],t.c0,Math.min(c,y+R-1),t.c1)}return t.showFirstColumn&&b(e.firstColumn,t.r0,t.c0,t.r1,t.c0),t.showLastColumn&&b(e.lastColumn,t.r0,t.c1,t.r1,t.c1),t.headerRows>0&&(b(e.headerRow,t.r0,t.c0,m-1,t.c1),t.showFirstColumn&&b(e.firstHeaderCell,t.r0,t.c0,m-1,t.c0),t.showLastColumn&&b(e.lastHeaderCell,t.r0,t.c1,m-1,t.c1)),t.totalsRows>0&&(b(e.totalRow,c+1,t.c0,t.r1,t.c1),t.showFirstColumn&&b(e.firstTotalCell,c+1,t.c0,t.r1,t.c0),t.showLastColumn&&b(e.lastTotalCell,c+1,t.c1,t.r1,t.c1)),h},s=e.headerRow;return{format:r,areas:u,custom:d,headerFill:s?.fill??null,headerInk:s?.color??(s?.fill?"#FFFFFF":"#000000"),headerRule:N(s),band:e.firstRowStripe?.fill??null,rule:N(e.wholeTable)??N(e.totalRow),body:e.wholeTable?.fill??null,ink:e.wholeTable?.color??null}}const z={medium:2,mediumDashed:2,mediumDashDot:2,mediumDashDotDot:2,slantDashDot:2,thick:3,double:3};function pe(e,l,i,{ra:d,rb:r,ca:u,cb:s,xs:t,ys:a,ox:o=0,oy:f=0,line:n=1,noFill:h=!1,setInk:b}){const m=Math.max(l.r0,d),c=Math.min(l.r1,r),R=Math.max(l.c0,u),w=Math.min(l.c1,s);for(let S=h?c+1:m;S<=c;S++){const p=a[S-d],x=a[S-d+1]-p;if(x!==0)for(let L=R;L<=w;L++){const $=t[L-u],D=t[L-u+1]-$;if(D===0)continue;const{fill:C}=i.format(l,S,L);C&&(b(C),e.fillRect(o+$,f+p,D,x))}}const y=(S,p,x,L,$)=>{b(S.color);const D=z[S.style]??1,C=$?L-D*n:L;S.style==="double"?(e.fillRect(o+p,f+C,x-p,n),e.fillRect(o+p,f+C+2*n,x-p,n)):e.fillRect(o+p,f+C,x-p,D*n)},T=(S,p,x,L,$)=>{b(S.color);const D=z[S.style]??1,C=$?L-D*n:L;S.style==="double"?(e.fillRect(o+C,f+p,n,x-p),e.fillRect(o+C+2*n,f+p,n,x-p)):e.fillRect(o+C,f+p,D*n,x-p)};for(const S of i.areas(l,m,c,R,w)){if(S.r1<d||S.r0>r||S.c1<u||S.c0>s)continue;const p=Math.max(S.c0,u),x=Math.min(S.c1,s),L=Math.max(S.r0,d),$=Math.min(S.r1,r),D=t[p-u],C=t[x-u+1],P=a[L-d],M=a[$-d+1],A=S.borders;if(A.h)for(let I=L;I<$+(S.r1>$?1:0);I++){const g=a[I-d+1];g!==a[I-d]&&y(A.h,D,C,g,!0)}if(A.v)for(let I=p;I<x+(S.c1>x?1:0);I++){const g=t[I-u+1];g!==t[I-u]&&T(A.v,P,M,g,!0)}A.t&&S.r0>=d&&y(A.t,D,C,P,!1),A.b&&S.r1<=r&&y(A.b,D,C,M,!0),A.l&&S.c0>=u&&T(A.l,P,M,D,!1),A.r&&S.c1<=s&&T(A.r,P,M,C,!0)}}const oe={NONE:0,PAGE_LABEL:1,PAGE_VALUE:2,CORNER:3,HEADER_BLANK:4,COL_CAPTION:5,ROW_CAPTION:6,COL_ITEM:7,COL_SUBTOTAL:8,COL_GRAND:9,DATA_HEADER:10,ROW_ITEM:11,ROW_PARENT:12,ROW_SUBTOTAL:13,ROW_GRAND:14,DATA:15,DATA_PARENT:16,DATA_SUBTOTAL:17,DATA_GRAND_ROW:18,DATA_GRAND_COL:19,PLACEHOLDER:20},F=(e,l,i,d)=>e<=0?l:e===1?i:d;function Re(e,l,i){const d=l?.find(i);return d?ne(Object.fromEntries(ee.map(r=>[r,O(e,d,r)])),!0):null}function ne(e,l=!1){const i=oe,d=e.wholeTable?.borders&&(e.wholeTable.borders.h||e.wholeTable.borders.v)?{...e.wholeTable,borders:{b:e.wholeTable.borders.h??null,r:e.wholeTable.borders.v??null}}:e.wholeTable&&{...e.wholeTable,borders:void 0};return{patch:(u,s,t,a={},o=0)=>{const f={},n=a.colHeaders===!1?null:e.headerRow,h=a.rowHeaders===!1?null:e.firstColumn,b=a.lastColumn===!1?null:e.lastColumn,m={},c=(T,S="tb")=>{T&&(E(f,T),T.borders&&(S.includes("t")&&T.borders.t&&(m.t=T.borders.t),S.includes("b")&&T.borders.b&&(m.b=T.borders.b),S.includes("l")&&T.borders.l&&(m.l=T.borders.l),S.includes("r")&&T.borders.r&&(m.r=T.borders.r)))};u!==i.PAGE_LABEL&&u!==i.PAGE_VALUE&&c(d,"br");const R=m.b,w=m.r;switch(t&4&&c(e.firstColumnStripe,"lr"),t&8&&c(e.secondColumnStripe,"lr"),t&1&&c(e.firstRowStripe),t&2&&c(e.secondRowStripe),u){case i.PAGE_LABEL:c(e.pageFieldLabels,"tblr");break;case i.PAGE_VALUE:c(e.pageFieldValues,"tblr");break;case i.CORNER:c(n),c(h,"lr"),c(e.firstHeaderCell,"tblr");break;case i.HEADER_BLANK:case i.COL_CAPTION:case i.DATA_HEADER:c(n);break;case i.ROW_CAPTION:c(n),c(e.firstHeaderCell,"tblr");break;case i.COL_ITEM:c(n),c(F(s,e.firstColumnSubheading,e.secondColumnSubheading,e.thirdColumnSubheading));break;case i.COL_SUBTOTAL:c(n),c(F(s,e.firstSubtotalColumn,e.secondSubtotalColumn,e.thirdSubtotalColumn),"lr");break;case i.COL_GRAND:c(n),c(b,"lr");break;case i.ROW_ITEM:c(h,"lr");break;case i.ROW_PARENT:c(h,"lr"),c(F(s,e.firstRowSubheading,e.secondRowSubheading,e.thirdRowSubheading));break;case i.ROW_SUBTOTAL:c(h,"lr"),c(F(s,e.firstSubtotalRow,e.secondSubtotalRow,e.thirdSubtotalRow));break;case i.ROW_GRAND:c(h,"lr"),c(e.totalRow);break;case i.DATA_PARENT:c(F(s,e.firstRowSubheading,e.secondRowSubheading,e.thirdRowSubheading));break;case i.DATA_SUBTOTAL:c(F(s,e.firstSubtotalRow,e.secondSubtotalRow,e.thirdSubtotalRow));break;case i.DATA_GRAND_ROW:c(e.totalRow);break;case i.DATA_GRAND_COL:c(b,"lr");break;case i.PLACEHOLDER:c(e.blankRow);break;default:}const y=e.wholeTable?.borders;return y&&o&&(o&1&&y.t&&!m.t&&(m.t=y.t),o&2&&y.b&&(!m.b||m.b===R)&&(m.b=y.b),o&4&&y.l&&!m.l&&(m.l=y.l),o&8&&y.r&&(!m.r||m.r===w)&&(m.r=y.r)),Object.keys(m).length&&(f.borders=m),f},stripe:e.firstRowStripe?.fill??null,custom:l,header:{},sub:{},grand:{},parent:{},page:{}}}function Te(e,l,i,d){const r=l?.slicerStyles.find(n=>n.name===i),u=l?.find(i);if(!r&&!u)return null;const s={...d},t=O(e,u,"wholeTable"),a=O(e,u,"headerRow");t?.fill&&(s.frameFill=t.fill),t?.color&&(s.ink=t.color);const o=N(t);o&&(s.frameLine=o),a?.color&&(s.captionInk=a.color),a?.fill&&(s.captionFill=a.fill);const f=(n,h,b,m)=>{const c=O(e,r,n,l.slicerDxfs);if(!c)return;c.fill&&(s[h]=c.fill),c.color&&(s[b]=c.color);const R=N(c);R&&m&&(s[m]=R)};return f("selectedItemWithData","selFill","selInk","selLine"),f("unselectedItemWithData","fill","itemInk","itemLine"),f("selectedItemWithNoData","selNoFill","selNoInk"),f("unselectedItemWithNoData","noFill","noInk"),s.hoverSelFill=s.selFill,s.hoverSelInk=s.selInk,s.hoverFill=s.fill,s.hoverInk=s.itemInk,f("hoveredSelectedItemWithData","hoverSelFill","hoverSelInk"),f("hoveredUnselectedItemWithData","hoverFill","hoverInk"),s}function we(e,l,i,d){const r=l?.timelineStyles.find(h=>h.name===i),u=l?.find(i);if(!r&&!u)return null;const s={...d},t=O(e,u,"wholeTable"),a=O(e,u,"headerRow");t?.fill&&(s.frameFill=t.fill);const o=N(t);o&&(s.frameLine=o),a?.color&&(s.captionInk=a.color);const f=(h,b)=>{const m=O(e,r,h,l.timelineDxfs);m?.fill&&(s[b]=m.fill)},n=(h,b)=>{const m=O(e,r,h,l.timelineDxfs);m?.color&&(s[b]=m.color)};return f("selectedTimeBlock","selFill"),f("unselectedTimeBlock","blockFill"),f("selectedTimeBlockSpace","selSpaceFill"),n("selectionLabel","labelInk"),n("timeLevel","levelInk"),n("periodLabel1","periodInk"),n("periodLabel2","subPeriodInk"),s}export{te as CustomStyles,ee as PIVOT_ELEMENTS,me as SLICER_ELEMENTS,Z as TABLE_ELEMENTS,Se as TIMELINE_ELEMENTS,le as addDxf,Re as customPivotPattern,Te as customSlicerColors,ye as customTableColors,we as customTimelineColors,ne as elementPivotPattern,se as elementTableColors,pe as paintCustomTable,he as parseCustomStyles,be as patchCustomStyles};
1
+ import{EXT as k,NS as W}from"./format.js";import{parseNode as K}from"../pivot/xml.js";import{xmlAttr as _}from"../io/xml-escape.js";import{dxfXml as G,parseDxfs as Y}from"../io/xlsx-tail.js";import{resolveColor as q}from"../io/xlsx-styles.js";import{bandRow as J}from"../core/tables.js";const j="{46F421CA-312F-682f-3DD2-61675219B42D}",U="{A0A4C193-F2C1-4fcb-8827-314CF55A85BB}",V=(e,l)=>e?.c?.find(i=>i.n===l)??null,Q=(e,l)=>e?e.c.filter(i=>i.n===l):[],v=e=>e.slice(e.indexOf(":")+1),Z=["wholeTable","headerRow","totalRow","firstColumn","lastColumn","firstRowStripe","secondRowStripe","firstColumnStripe","secondColumnStripe","firstHeaderCell","lastHeaderCell","firstTotalCell","lastTotalCell"],ee=["wholeTable","pageFieldLabels","pageFieldValues","firstColumnStripe","secondColumnStripe","firstRowStripe","secondRowStripe","firstColumn","headerRow","firstHeaderCell","firstSubtotalColumn","secondSubtotalColumn","thirdSubtotalColumn","blankRow","firstSubtotalRow","secondSubtotalRow","thirdSubtotalRow","firstColumnSubheading","secondColumnSubheading","thirdColumnSubheading","firstRowSubheading","secondRowSubheading","thirdRowSubheading","totalRow","lastColumn"],me=["unselectedItemWithData","selectedItemWithData","unselectedItemWithNoData","selectedItemWithNoData","hoveredUnselectedItemWithData","hoveredSelectedItemWithData","hoveredUnselectedItemWithNoData","hoveredSelectedItemWithNoData"],Se=["selectionLabel","timeLevel","periodLabel1","periodLabel2","selectedTimeBlock","unselectedTimeBlock","selectedTimeBlockSpace"];class te{constructor(){this.tableStyles=[],this.slicerStyles=[],this.timelineStyles=[],this.slicerDxfs=[],this.timelineDxfs=[],this.defaultTableStyle="TableStyleMedium2",this.defaultPivotStyle="PivotStyleLight16",this.defaultSlicerStyle="SlicerStyleLight1",this.defaultTimelineStyle="TimeSlicerStyleLight1",this.dirty=!1,this.version=0}find(l){return this.tableStyles.find(i=>i.name===l)??null}forTables(){return this.tableStyles.filter(l=>l.table)}forPivots(){return this.tableStyles.filter(l=>l.pivot)}setTableStyle(l,i,{table:d=!0,pivot:r=!1,elements:u={}}){const s=Object.entries(u).map(([o,f])=>({type:o,dxfId:le(l,f),...f.size?{size:f.size}:{}})),t={name:i,table:d,pivot:r,elements:s},a=this.tableStyles.findIndex(o=>o.name===i);return a>=0?this.tableStyles[a]=t:this.tableStyles.push(t),this.dirty=!0,this.version++,t}setSlicerStyle(l,i,{whole:d=null,header:r=null,elements:u={}}){this.setTableStyle(l,i,{table:!1,pivot:!1,elements:{...d?{wholeTable:d}:{},...r?{headerRow:r}:{}}});const s={name:i,elements:Object.entries(u).map(([a,o])=>({type:a,dxfId:this.slicerDxfs.push(o)-1}))},t=this.slicerStyles.findIndex(a=>a.name===i);return t>=0?this.slicerStyles[t]=s:this.slicerStyles.push(s),this.dirty=!0,s}setTimelineStyle(l,i,{whole:d=null,header:r=null,elements:u={}}){this.setTableStyle(l,i,{table:!1,pivot:!1,elements:{...d?{wholeTable:d}:{},...r?{headerRow:r}:{}}});const s={name:i,elements:Object.entries(u).map(([a,o])=>({type:a,dxfId:this.timelineDxfs.push(o)-1}))},t=this.timelineStyles.findIndex(a=>a.name===i);return t>=0?this.timelineStyles[t]=s:this.timelineStyles.push(s),this.dirty=!0,s}setDefaultTableStyle(l){return this.defaultTableStyle===l?!1:(this.defaultTableStyle=l,this.dirty=!0,this.version++,!0)}removeStyle(l){this.tableStyles=this.tableStyles.filter(i=>i.name!==l),this.slicerStyles=this.slicerStyles.filter(i=>i.name!==l),this.timelineStyles=this.timelineStyles.filter(i=>i.name!==l),this.dirty=!0,this.version++}savePlan(){return this.dirty?{tableStyles:this.tableStyles,slicerStyles:this.slicerStyles,timelineStyles:this.timelineStyles,slicerDxfs:this.slicerDxfs.map(G),timelineDxfs:this.timelineDxfs.map(G),defaultTableStyle:this.defaultTableStyle,defaultPivotStyle:this.defaultPivotStyle,defaultSlicerStyle:this.defaultSlicerStyle,defaultTimelineStyle:this.defaultTimelineStyle}:null}}function le(e,l){e.dxfs??=[];const{size:i,...d}=l;return e.dxfs.push(d),e.dxfs.length-1}const B=e=>(e?e.c.filter(l=>typeof l!="string"):[]).map(l=>({type:l.a.type,dxfId:Number(l.a.dxfId??-1),...l.a.size?{size:Number(l.a.size)}:{}})).filter(l=>l.dxfId>=0);function he(e,l=[]){const i=new te,d=typeof e=="string"?e:new TextDecoder().decode(e),r=t=>{const a=new RegExp(`<${t}:dxfs\\b[^>]*>([\\s\\S]*?)</${t}:dxfs>`).exec(d);return a?Y(new TextEncoder().encode(`<r><dxfs>${a[1]}</dxfs></r>`),o=>o?q(o,l):null):[]};i.slicerDxfs=r("x14"),i.timelineDxfs=r("x15");const u=K(e),s=V(u,"tableStyles");s&&(i.defaultTableStyle=s.a.defaultTableStyle??i.defaultTableStyle,i.defaultPivotStyle=s.a.defaultPivotStyle??i.defaultPivotStyle,i.tableStyles=Q(s,"tableStyle").map(t=>({name:t.a.name,table:t.a.table!=="0",pivot:t.a.pivot!=="0",elements:B(t)})));for(const t of V(u,"extLst")?.c??[])if(t.a?.uri===k.slicerStyles){const a=t.c.find(o=>v(o.n)==="slicerStyles");a&&(i.defaultSlicerStyle=a.a.defaultSlicerStyle??i.defaultSlicerStyle,i.slicerStyles=a.c.filter(o=>v(o.n)==="slicerStyle").map(o=>({name:o.a.name,elements:B(o.c.find(f=>v(f.n)==="slicerStyleElements"))})))}else if(t.a?.uri===k.timelineStyles){const a=t.c.find(o=>v(o.n)==="timelineStyles");a&&(i.defaultTimelineStyle=a.a.defaultTimelineStyle??i.defaultTimelineStyle,i.timelineStyles=a.c.filter(o=>v(o.n)==="timelineStyle").map(o=>({name:o.a.name,elements:B(o.c.find(f=>v(f.n)==="timelineStyleElements"))})))}return i}const H=(e,l)=>`<${e} type="${l.type}"${l.size?` size="${l.size}"`:""} dxfId="${l.dxfId}"/>`;function be(e,l){if(!l)return e;const i=n=>(l.slicerStyles.find(h=>h.name===n)?.elements.length??0)+(l.timelineStyles.find(h=>h.name===n)?.elements.length??0),d=`<tableStyles count="${l.tableStyles.length}" defaultTableStyle="${_(l.defaultTableStyle)}" defaultPivotStyle="${_(l.defaultPivotStyle)}"${l.tableStyles.length?`>${l.tableStyles.map(n=>`<tableStyle name="${_(n.name)}"${n.table?"":' table="0"'}${n.pivot?"":' pivot="0"'} count="${n.elements.length+i(n.name)}">${n.elements.map(h=>H("tableStyleElement",h)).join("")}</tableStyle>`).join("")}</tableStyles>`:"/>"}`;let r=e;if(/<tableStyles\b/.test(r))r=r.replace(/<tableStyles\b[^>]*?\/>|<tableStyles\b[\s\S]*?<\/tableStyles>/,()=>d);else{const n=/<(?:colors|extLst)\b|<\/styleSheet>/.exec(r);r=`${r.slice(0,n.index)}${/<dxfs\b/.test(r)?"":'<dxfs count="0"/>'}${d}${r.slice(n.index)}`}const u=n=>{r=r.replace(new RegExp(`<ext\\b[^>]*uri="${n.replace(/[{}-]/g,"\\$&")}"[^>]*>[\\s\\S]*?</ext>`),"")};u(k.slicerStyles),u(k.timelineStyles),u(j),u(U);const s=(n,h,b,m)=>m.length?`<ext uri="${n}" xmlns:${h}="${b}"><${h}:dxfs count="${m.length}">${m.join("")}</${h}:dxfs></ext>`:"",t=`${s(j,"x14",W.x14,l.slicerDxfs)}`,a=`${s(U,"x15",W.x15,l.timelineDxfs)}`,o=`<ext uri="${k.slicerStyles}" xmlns:x14="${W.x14}"><x14:slicerStyles defaultSlicerStyle="${_(l.defaultSlicerStyle)}"${l.slicerStyles.length?`>${l.slicerStyles.map(n=>`<x14:slicerStyle name="${_(n.name)}"><x14:slicerStyleElements>${n.elements.map(h=>H("x14:slicerStyleElement",h)).join("")}</x14:slicerStyleElements></x14:slicerStyle>`).join("")}</x14:slicerStyles>`:"/>"}</ext>`,f=`<ext uri="${k.timelineStyles}" xmlns:x15="${W.x15}"><x15:timelineStyles defaultTimelineStyle="${_(l.defaultTimelineStyle)}"${l.timelineStyles.length?`>${l.timelineStyles.map(n=>`<x15:timelineStyle name="${_(n.name)}"><x15:timelineStyleElements>${n.elements.map(h=>H("x15:timelineStyleElement",h)).join("")}</x15:timelineStyleElements></x15:timelineStyle>`).join("")}</x15:timelineStyles>`:"/>"}</ext>`;return/<\/extLst>\s*<\/styleSheet>/.test(r)?r=r.replace(/<\/extLst>\s*<\/styleSheet>/,n=>`${t}${o}${a}${f}${n}`):r=r.replace("</styleSheet>",()=>`<extLst>${t}${o}${a}${f}</extLst></styleSheet>`),r}const O=(e,l,i,d=e.dxfs)=>{const r=l?.elements.find(u=>u.type===i);return r?d?.[r.dxfId]??{}:null},N=e=>{const l=e?.borders;return l?l.b?.color??l.t?.color??l.l?.color??l.r?.color??null:null},ie=["fill","color","bold","italic","underline","strike"],E=(e,l)=>{if(l)for(const i of ie)l[i]!==void 0&&(e[i]=l[i])},X=(e,l,i)=>e%(l+i)<l?0:1;function ye(e,l,i){const d=l?.find(i);if(!d)return null;const r=s=>d.elements.find(t=>t.type===s)?.size??1,u=Object.fromEntries(Z.map(s=>[s,O(e,d,s)]));return se(u,[r("firstRowStripe"),r("secondRowStripe")],[r("firstColumnStripe"),r("secondColumnStripe")],!0)}function se(e,l=[1,1],i=[1,1],d=!1){const r=(t,a,o)=>{const f={},n=t.r0+t.headerRows,h=t.r1-t.totalsRows,b=a>=n&&a<=h;return E(f,e.wholeTable),b&&(t.showColumnStripes&&E(f,X(o-t.c0,i[0],i[1])===0?e.firstColumnStripe:e.secondColumnStripe),t.showRowStripes!==!1&&E(f,X(J(t,a),l[0],l[1])===0?e.firstRowStripe:e.secondRowStripe)),t.showFirstColumn&&o===t.c0&&E(f,e.firstColumn),t.showLastColumn&&o===t.c1&&E(f,e.lastColumn),a<n?(E(f,e.headerRow),o===t.c0&&t.showFirstColumn&&E(f,e.firstHeaderCell),o===t.c1&&t.showLastColumn&&E(f,e.lastHeaderCell)):a>h&&(E(f,e.totalRow),o===t.c0&&t.showFirstColumn&&E(f,e.firstTotalCell),o===t.c1&&t.showLastColumn&&E(f,e.lastTotalCell)),f},u=(t,a,o,f,n)=>{const h=[],b=(R,w,y,T,S)=>{R?.borders&&T>=w&&S>=y&&h.push({borders:R.borders,r0:w,c0:y,r1:T,c1:S})},m=t.r0+t.headerRows,c=t.r1-t.totalsRows;if(b(e.wholeTable,t.r0,t.c0,t.r1,t.c1),t.showColumnStripes&&(e.firstColumnStripe?.borders||e.secondColumnStripe?.borders)){const R=i[0]+i[1];for(let w=t.c0;w<=Math.min(t.c1,n);w+=R)b(e.firstColumnStripe,m,w,c,Math.min(t.c1,w+i[0]-1)),b(e.secondColumnStripe,m,w+i[0],c,Math.min(t.c1,w+R-1))}if(t.showRowStripes!==!1&&(e.firstRowStripe?.borders||e.secondRowStripe?.borders)){const R=l[0]+l[1],w=m+Math.floor(Math.max(0,a-m)/R)*R;for(let y=w;y<=Math.min(c,o);y+=R)b(e.firstRowStripe,y,t.c0,Math.min(c,y+l[0]-1),t.c1),b(e.secondRowStripe,y+l[0],t.c0,Math.min(c,y+R-1),t.c1)}return t.showFirstColumn&&b(e.firstColumn,t.r0,t.c0,t.r1,t.c0),t.showLastColumn&&b(e.lastColumn,t.r0,t.c1,t.r1,t.c1),t.headerRows>0&&(b(e.headerRow,t.r0,t.c0,m-1,t.c1),t.showFirstColumn&&b(e.firstHeaderCell,t.r0,t.c0,m-1,t.c0),t.showLastColumn&&b(e.lastHeaderCell,t.r0,t.c1,m-1,t.c1)),t.totalsRows>0&&(b(e.totalRow,c+1,t.c0,t.r1,t.c1),t.showFirstColumn&&b(e.firstTotalCell,c+1,t.c0,t.r1,t.c0),t.showLastColumn&&b(e.lastTotalCell,c+1,t.c1,t.r1,t.c1)),h},s=e.headerRow;return{format:r,areas:u,custom:d,headerFill:s?.fill??null,headerInk:s?.color??(s?.fill?"#FFFFFF":"#000000"),headerRule:N(s),band:e.firstRowStripe?.fill??null,rule:N(e.wholeTable)??N(e.totalRow),body:e.wholeTable?.fill??null,ink:e.wholeTable?.color??null}}const z={medium:2,mediumDashed:2,mediumDashDot:2,mediumDashDotDot:2,slantDashDot:2,thick:3,double:3};function pe(e,l,i,{ra:d,rb:r,ca:u,cb:s,xs:t,ys:a,ox:o=0,oy:f=0,line:n=1,noFill:h=!1,setInk:b}){const m=Math.max(l.r0,d),c=Math.min(l.r1,r),R=Math.max(l.c0,u),w=Math.min(l.c1,s);for(let S=h?c+1:m;S<=c;S++){const p=a[S-d],x=a[S-d+1]-p;if(x!==0)for(let L=R;L<=w;L++){const $=t[L-u],D=t[L-u+1]-$;if(D===0)continue;const{fill:C}=i.format(l,S,L);C&&(b(C),e.fillRect(o+$,f+p,D,x))}}const y=(S,p,x,L,$)=>{b(S.color);const D=z[S.style]??1,C=$?L-D*n:L;S.style==="double"?(e.fillRect(o+p,f+C,x-p,n),e.fillRect(o+p,f+C+2*n,x-p,n)):e.fillRect(o+p,f+C,x-p,D*n)},T=(S,p,x,L,$)=>{b(S.color);const D=z[S.style]??1,C=$?L-D*n:L;S.style==="double"?(e.fillRect(o+C,f+p,n,x-p),e.fillRect(o+C+2*n,f+p,n,x-p)):e.fillRect(o+C,f+p,D*n,x-p)};for(const S of i.areas(l,m,c,R,w)){if(S.r1<d||S.r0>r||S.c1<u||S.c0>s)continue;const p=Math.max(S.c0,u),x=Math.min(S.c1,s),L=Math.max(S.r0,d),$=Math.min(S.r1,r),D=t[p-u],C=t[x-u+1],P=a[L-d],M=a[$-d+1],A=S.borders;if(A.h)for(let I=L;I<$+(S.r1>$?1:0);I++){const g=a[I-d+1];g!==a[I-d]&&y(A.h,D,C,g,!0)}if(A.v)for(let I=p;I<x+(S.c1>x?1:0);I++){const g=t[I-u+1];g!==t[I-u]&&T(A.v,P,M,g,!0)}A.t&&S.r0>=d&&y(A.t,D,C,P,!1),A.b&&S.r1<=r&&y(A.b,D,C,M,!0),A.l&&S.c0>=u&&T(A.l,P,M,D,!1),A.r&&S.c1<=s&&T(A.r,P,M,C,!0)}}const oe={NONE:0,PAGE_LABEL:1,PAGE_VALUE:2,CORNER:3,HEADER_BLANK:4,COL_CAPTION:5,ROW_CAPTION:6,COL_ITEM:7,COL_SUBTOTAL:8,COL_GRAND:9,DATA_HEADER:10,ROW_ITEM:11,ROW_PARENT:12,ROW_SUBTOTAL:13,ROW_GRAND:14,DATA:15,DATA_PARENT:16,DATA_SUBTOTAL:17,DATA_GRAND_ROW:18,DATA_GRAND_COL:19,PLACEHOLDER:20},F=(e,l,i,d)=>e<=0?l:e===1?i:d;function Re(e,l,i){const d=l?.find(i);return d?ne(Object.fromEntries(ee.map(r=>[r,O(e,d,r)])),!0):null}function ne(e,l=!1){const i=oe,d=e.wholeTable?.borders&&(e.wholeTable.borders.h||e.wholeTable.borders.v)?{...e.wholeTable,borders:{b:e.wholeTable.borders.h??null,r:e.wholeTable.borders.v??null}}:e.wholeTable&&{...e.wholeTable,borders:void 0};return{patch:(u,s,t,a={},o=0)=>{const f={},n=a.colHeaders===!1?null:e.headerRow,h=a.rowHeaders===!1?null:e.firstColumn,b=a.lastColumn===!1?null:e.lastColumn,m={},c=(T,S="tb")=>{T&&(E(f,T),T.borders&&(S.includes("t")&&T.borders.t&&(m.t=T.borders.t),S.includes("b")&&T.borders.b&&(m.b=T.borders.b),S.includes("l")&&T.borders.l&&(m.l=T.borders.l),S.includes("r")&&T.borders.r&&(m.r=T.borders.r)))};u!==i.PAGE_LABEL&&u!==i.PAGE_VALUE&&c(d,"br");const R=m.b,w=m.r;switch(t&4&&c(e.firstColumnStripe,"lr"),t&8&&c(e.secondColumnStripe,"lr"),t&1&&c(e.firstRowStripe),t&2&&c(e.secondRowStripe),u){case i.PAGE_LABEL:c(e.pageFieldLabels,"tblr");break;case i.PAGE_VALUE:c(e.pageFieldValues,"tblr");break;case i.CORNER:c(n),c(h,"lr"),c(e.firstHeaderCell,"tblr");break;case i.HEADER_BLANK:case i.COL_CAPTION:case i.DATA_HEADER:c(n);break;case i.ROW_CAPTION:c(n),c(e.firstHeaderCell,"tblr");break;case i.COL_ITEM:c(n),c(F(s,e.firstColumnSubheading,e.secondColumnSubheading,e.thirdColumnSubheading));break;case i.COL_SUBTOTAL:c(n),c(F(s,e.firstSubtotalColumn,e.secondSubtotalColumn,e.thirdSubtotalColumn),"lr");break;case i.COL_GRAND:c(n),c(b,"lr");break;case i.ROW_ITEM:c(h,"lr");break;case i.ROW_PARENT:c(h,"lr"),c(F(s,e.firstRowSubheading,e.secondRowSubheading,e.thirdRowSubheading));break;case i.ROW_SUBTOTAL:c(h,"lr"),c(F(s,e.firstSubtotalRow,e.secondSubtotalRow,e.thirdSubtotalRow));break;case i.ROW_GRAND:c(h,"lr"),c(e.totalRow);break;case i.DATA_PARENT:c(F(s,e.firstRowSubheading,e.secondRowSubheading,e.thirdRowSubheading));break;case i.DATA_SUBTOTAL:c(F(s,e.firstSubtotalRow,e.secondSubtotalRow,e.thirdSubtotalRow));break;case i.DATA_GRAND_ROW:c(e.totalRow);break;case i.DATA_GRAND_COL:c(b,"lr");break;case i.PLACEHOLDER:c(e.blankRow);break;default:}const y=e.wholeTable?.borders;return y&&o&&(o&1&&y.t&&!m.t&&(m.t=y.t),o&2&&y.b&&(!m.b||m.b===R)&&(m.b=y.b),o&4&&y.l&&!m.l&&(m.l=y.l),o&8&&y.r&&(!m.r||m.r===w)&&(m.r=y.r)),Object.keys(m).length&&(f.borders=m),f},stripe:e.firstRowStripe?.fill??null,custom:l,header:{},sub:{},grand:{},parent:{},page:{}}}function Te(e,l,i,d){const r=l?.slicerStyles.find(n=>n.name===i),u=l?.find(i);if(!r&&!u)return null;const s={...d},t=O(e,u,"wholeTable"),a=O(e,u,"headerRow");t?.fill&&(s.frameFill=t.fill),t?.color&&(s.ink=t.color);const o=N(t);o&&(s.frameLine=o),a?.color&&(s.captionInk=a.color),a?.fill&&(s.captionFill=a.fill);const f=(n,h,b,m)=>{const c=O(e,r,n,l.slicerDxfs);if(!c)return;c.fill&&(s[h]=c.fill),c.color&&(s[b]=c.color);const R=N(c);R&&m&&(s[m]=R)};return f("selectedItemWithData","selFill","selInk","selLine"),f("unselectedItemWithData","fill","itemInk","itemLine"),f("selectedItemWithNoData","selNoFill","selNoInk"),f("unselectedItemWithNoData","noFill","noInk"),s.hoverSelFill=s.selFill,s.hoverSelInk=s.selInk,s.hoverFill=s.fill,s.hoverInk=s.itemInk,f("hoveredSelectedItemWithData","hoverSelFill","hoverSelInk"),f("hoveredUnselectedItemWithData","hoverFill","hoverInk"),s}function we(e,l,i,d){const r=l?.timelineStyles.find(h=>h.name===i),u=l?.find(i);if(!r&&!u)return null;const s={...d},t=O(e,u,"wholeTable"),a=O(e,u,"headerRow");t?.fill&&(s.frameFill=t.fill);const o=N(t);o&&(s.frameLine=o),a?.color&&(s.captionInk=a.color);const f=(h,b)=>{const m=O(e,r,h,l.timelineDxfs);m?.fill&&(s[b]=m.fill)},n=(h,b)=>{const m=O(e,r,h,l.timelineDxfs);m?.color&&(s[b]=m.color)};return f("selectedTimeBlock","selFill"),f("unselectedTimeBlock","blockFill"),f("selectedTimeBlockSpace","selSpaceFill"),n("selectionLabel","labelInk"),n("timeLevel","levelInk"),n("periodLabel1","periodInk"),n("periodLabel2","subPeriodInk"),s}export{te as CustomStyles,ee as PIVOT_ELEMENTS,me as SLICER_ELEMENTS,Z as TABLE_ELEMENTS,Se as TIMELINE_ELEMENTS,le as addDxf,Re as customPivotPattern,Te as customSlicerColors,ye as customTableColors,we as customTimelineColors,ne as elementPivotPattern,se as elementTableColors,pe as paintCustomTable,he as parseCustomStyles,be as patchCustomStyles};
package/slicers/format.js CHANGED
@@ -1,2 +1,2 @@
1
1
  import{parseNode as p}from"../pivot/xml.js";import{xmlAttr as A}from"../io/xml-escape.js";import{unescapeXstring as I}from"../io/xml-scan.js";const a={main:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",r:"http://schemas.openxmlformats.org/officeDocument/2006/relationships",mc:"http://schemas.openxmlformats.org/markup-compatibility/2006",x14:"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",x15:"http://schemas.microsoft.com/office/spreadsheetml/2010/11/main",xr10:"http://schemas.microsoft.com/office/spreadsheetml/2016/revision10",xdr:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",a:"http://schemas.openxmlformats.org/drawingml/2006/main",a14:"http://schemas.microsoft.com/office/drawing/2010/main",sle:"http://schemas.microsoft.com/office/drawing/2010/slicer",sle15:"http://schemas.microsoft.com/office/drawing/2012/slicer",tsle:"http://schemas.microsoft.com/office/drawing/2012/timeslicer"},k={slicerCache:"http://schemas.microsoft.com/office/2007/relationships/slicerCache",slicer:"http://schemas.microsoft.com/office/2007/relationships/slicer",timelineCache:"http://schemas.microsoft.com/office/2011/relationships/timelineCache",timeline:"http://schemas.microsoft.com/office/2011/relationships/timeline",drawing:`${a.r}/drawing`},H={slicerCache:"application/vnd.ms-excel.slicerCache+xml",slicer:"application/vnd.ms-excel.slicer+xml",timelineCache:"application/vnd.ms-excel.timelineCache+xml",timeline:"application/vnd.ms-excel.timeline+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml"},h={wbPivotSlicerCaches:"{BBE1A952-AA13-448e-AADC-164F8A28A991}",wbTableSlicerCaches:"{46BE6895-7355-4a93-B00E-2C351335B9C9}",wbTimelineCaches:"{D0CA8CA8-9F24-4464-BF8E-62219DCF47F9}",wsPivotSlicers:"{A8765BA9-456A-4dab-B4F3-ACF838C121DE}",wsTableSlicers:"{3A4CF648-6AED-40f4-86FF-DC5316D8AED3}",wsTimelines:"{7E03D99C-DC04-49d9-9315-930204A7B6E9}",tableSlicerCache:"{2F2917AC-EB37-4324-AD4E-5DD8C200BD13}",hideNoData:"{470722E0-AACD-4C17-9CDC-17EF765DBC7E}",pivotCacheId:"{725AE2AE-9491-48be-B2B4-4EB974FC3084}",slicerStyles:"{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}",timelineStyles:"{9260A510-F301-46a8-8635-F512D64BE5F5}"},X=t=>`@@TAB${t}@@`,b=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
- `,C=A,u=t=>Object.entries(t).filter(([,i])=>i!=null).map(([i,e])=>` ${i}="${C(e)}"`).join(""),f=(t,i)=>t?.c?.find(e=>e.n===i)??null,v=(t,i)=>t?t.c.filter(e=>e.n===i):[],$=t=>t.slice(t.indexOf(":")+1),x=(t,i)=>t===void 0?i:t==="1"||t==="true";function M(t){const i=u({name:t.name,"xr10:uid":t.uid??void 0,sourceName:t.sourceName,...t.extra??{}}),e=`${b}<slicerCacheDefinition xmlns="${a.x14}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}"${i}>`,n={sortOrder:t.sortOrder&&t.sortOrder!=="ascending"?t.sortOrder:void 0,customListSort:t.customListSort===!1?"0":void 0,crossFilter:t.crossFilter&&t.crossFilter!=="showItemsWithDataAtTop"?t.crossFilter:void 0},r=[];let o="";if(t.kind==="table")r.push(`<x:ext uri="${h.tableSlicerCache}" xmlns:x15="${a.x15}"><x15:tableSlicerCache${u({tableId:t.tableId,column:t.column,...n})}/></x:ext>`);else{const l=(t.pivotTables??[]).map(c=>`<pivotTable${u({tabId:c.tabId,name:c.name})}/>`).join("");o+=`<pivotTables>${l}</pivotTables>`;const m=(t.items??[]).map(c=>`<i${u({x:c.x,s:c.s?"1":void 0,nd:c.nd?"1":void 0})}/>`).join(""),s={pivotCacheId:t.pivotCacheId,...n,showMissing:t.showMissing===!1?"0":void 0};o+=`<data><tabular${u(s)}><items count="${(t.items??[]).length}">${m}</items></tabular></data>`}t.hideNoData&&r.push(`<x:ext uri="${h.hideNoData}" xmlns:x15="${a.x15}"><x15:slicerCacheHideItemsWithNoData/></x:ext>`);for(const l of t.rawExt??[])r.push(l);return`${e}${o}${r.length?`<extLst>${r.join("")}</extLst>`:""}</slicerCacheDefinition>`}function j(t){const i=e=>{const n={name:e.name,"xr10:uid":e.uid??void 0,cache:e.cache,caption:e.caption,startItem:e.startItem?e.startItem:void 0,columnCount:e.columnCount&&e.columnCount!==1?e.columnCount:void 0,showCaption:e.showCaption===!1?"0":void 0,level:e.level?e.level:void 0,style:e.style&&e.style!=="SlicerStyleLight1"?e.style:void 0,lockedPosition:e.lockedPosition?"1":void 0,rowHeight:e.rowHeight??241300,...e.extra??{}};return`<slicer${u(n)}/>`};return`${b}<slicers xmlns="${a.x14}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}">${t.map(i).join("")}</slicers>`}function z(t){const i=(t.pivotTables??[]).map(r=>`<pivotTable${u({tabId:r.tabId,name:r.name})}/>`).join(""),e=(r,o)=>o?`<${r}${u({startDate:o.start,endDate:o.end})}/>`:"",n=u({singleRangeFilterState:t.singleRange===!1?"0":void 0,minimalRefreshVersion:t.minimalRefreshVersion??6,lastRefreshVersion:t.lastRefreshVersion??6,pivotCacheId:t.pivotCacheId,filterType:t.selection?"dateBetween":"unknown",filterId:t.selection?t.filterId:void 0,filterTabId:t.selection?t.filterTabId:void 0,filterPivotName:t.selection?t.filterPivotName:void 0});return`${b}<timelineCacheDefinition xmlns="${a.x15}" xmlns:x15="${a.x15}" xmlns:mc="${a.mc}" mc:Ignorable="xr10" xmlns:xr10="${a.xr10}"${u({name:t.name,"xr10:uid":t.uid??void 0,sourceName:t.sourceName,...t.extra??{}})}><pivotTables>${i}</pivotTables><state${n}>${e("selection",t.selection)}${e("bounds",t.bounds)}</state></timelineCacheDefinition>`}function V(t){const i=e=>`<timeline${u({name:e.name,"xr10:uid":e.uid??void 0,cache:e.cache,caption:e.caption,showHeader:e.showHeader===!1?"0":void 0,showSelectionLabel:e.showSelectionLabel===!1?"0":void 0,showTimeLevel:e.showTimeLevel===!1?"0":void 0,showHorizontalScrollbar:e.showHorizontalScrollbar===!1?"0":void 0,level:e.level??2,selectionLevel:e.selectionLevel??e.level??2,scrollPosition:e.scrollPosition??void 0,style:e.style&&e.style!=="TimeSlicerStyleLight1"?e.style:void 0,...e.extra??{}})}/>`;return`${b}<timelines xmlns="${a.x15}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}">${t.map(i).join("")}</timelines>`}const E={pivot:{choice:`xmlns:a14="${a.a14}" Requires="a14"`,uri:a.sle,inner:t=>`<sle:slicer xmlns:sle="${a.sle}" name="${C(t)}"/>`},table:{choice:`xmlns:sle15="${a.sle15}" Requires="sle15"`,uri:a.sle,inner:t=>`<sle:slicer xmlns:sle="${a.sle}" name="${C(t)}"/>`},timeline:{choice:`xmlns:tsle="${a.tsle}" Requires="tsle"`,uri:a.tsle,inner:t=>`<tsle:timeslicer xmlns:tsle="${a.tsle}" name="${C(t)}"/>`}},L={pivot:"This shape represents a slicer. Slicers are supported in Excel 2010 or later.",table:"This shape represents a table slicer. Table slicers are supported in Excel 2013 or later.",timeline:"Timeline: Works in Excel 2013 or higher. Do not move or resize."};function W({kind:t,name:i,id:e,from:n,to:r,cx:o=1828800,cy:l=2524125}){const m=E[t],s=(c,d)=>`<xdr:${c}><xdr:col>${d.col}</xdr:col><xdr:colOff>${d.colOff}</xdr:colOff><xdr:row>${d.row}</xdr:row><xdr:rowOff>${d.rowOff}</xdr:rowOff></xdr:${c}>`;return`<xdr:twoCellAnchor editAs="absolute">${s("from",n)}${s("to",r)}<mc:AlternateContent xmlns:mc="${a.mc}"><mc:Choice ${m.choice}><xdr:graphicFrame macro=""><xdr:nvGraphicFramePr><xdr:cNvPr id="${e}" name="${C(i)}"/><xdr:cNvGraphicFramePr/></xdr:nvGraphicFramePr><xdr:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/></xdr:xfrm><a:graphic><a:graphicData uri="${m.uri}">${m.inner(i)}</a:graphicData></a:graphic></xdr:graphicFrame></mc:Choice><mc:Fallback xmlns=""><xdr:sp macro="" textlink=""><xdr:nvSpPr><xdr:cNvPr id="0" name=""/><xdr:cNvSpPr><a:spLocks noTextEdit="1"/></xdr:cNvSpPr></xdr:nvSpPr><xdr:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${o}" cy="${l}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:solidFill><a:prstClr val="white"/></a:solidFill><a:ln w="1"><a:solidFill><a:prstClr val="green"/></a:solidFill></a:ln></xdr:spPr><xdr:txBody><a:bodyPr vertOverflow="clip" horzOverflow="clip"/><a:lstStyle/><a:p><a:r><a:rPr lang="en-US" sz="1100"/><a:t>${L[t]}</a:t></a:r></a:p></xdr:txBody></xdr:sp></mc:Fallback></mc:AlternateContent><xdr:clientData/></xdr:twoCellAnchor>`}const _=t=>`${b}<xdr:wsDr xmlns:xdr="${a.xdr}" xmlns:a="${a.a}">${t}</xdr:wsDr>`,D=/<xdr:(twoCellAnchor|oneCellAnchor|absoluteAnchor)\b[\s\S]*?<\/xdr:\1>/g,S=/<(?:\w+:)?(slicer|timeslicer)\b[^>]*\bname="([^"]*)"/;function G(t){const i=[];for(const e of t.matchAll(D)){const n=e[0];if(!/drawing\/20(?:10|12)\/(?:time)?slicer/.test(n))continue;const r=S.exec(n);if(!r)continue;const o=m=>{const s=new RegExp(`<xdr:${m}>\\s*<xdr:col>(\\d+)</xdr:col>\\s*<xdr:colOff>(-?\\d+)</xdr:colOff>\\s*<xdr:row>(\\d+)</xdr:row>\\s*<xdr:rowOff>(-?\\d+)</xdr:rowOff>`).exec(n);return s?{col:Number(s[1]),colOff:Number(s[2]),row:Number(s[3]),rowOff:Number(s[4])}:null},l=(m,s,c)=>{const d=new RegExp(`<xdr:${m}\\b[^>]*>`).exec(n)?.[0];if(d===void 0)return null;const w=F=>Number(new RegExp(`\\b${F}="(-?\\d+)"`).exec(d)?.[1]),g=w(s),N=w(c);return Number.isFinite(g)&&Number.isFinite(N)?{[s]:g,[c]:N}:null};i.push({kind:r[1]==="timeslicer"?"timeline":/Requires="sle15"/.test(n)?"table":"pivot",name:I(r[2]),id:Number(/<xdr:cNvPr\b[^>]*\bid="(\d+)"/.exec(n)?.[1]??0),from:o("from"),to:o("to"),pos:e[1]==="absoluteAnchor"?l("pos","x","y"):null,ext:e[1]==="twoCellAnchor"?null:l("ext","cx","cy"),raw:n})}return i}function q(t,{upsert:i=[],remove:e=[]}){const n=new Map(i.map(s=>[s.name,s.xml])),r=new Set(e),o=new Set;let l=t.replace(D,s=>{if(!/drawing\/20(?:10|12)\/(?:time)?slicer/.test(s))return s;const c=S.exec(s);if(!c)return s;const d=I(c[2]);return r.has(d)?"":n.has(d)?(o.add(d),n.get(d)):s});const m=i.filter(s=>!o.has(s.name)).map(s=>s.xml).join("");return m&&(l=l.replace(/<\/(\w+:)?wsDr>\s*$/,s=>`${m}${s}`)),l}const y=new Set(["name","xr10:uid","cache","caption","startItem","columnCount","showCaption","level","style","lockedPosition","rowHeight"]),P=new Set(["name","xr10:uid","cache","caption","showHeader","showSelectionLabel","showTimeLevel","showHorizontalScrollbar","level","selectionLevel","scrollPosition","style"]),T=(t,i)=>{const e={};for(const[n,r]of Object.entries(t))!i.has(n)&&!n.startsWith("xmlns")&&n!=="mc:Ignorable"&&(e[n]=r);return e};function K(t){const i=p(t),e={name:i.a.name,sourceName:i.a.sourceName,uid:i.a["xr10:uid"]??null,kind:"pivot",sortOrder:"ascending",customListSort:!0,crossFilter:"showItemsWithDataAtTop",showMissing:!0,hideNoData:!1,pivotTables:[],items:[],pivotCacheId:null,tableId:null,column:null},n=o=>{o.sortOrder&&(e.sortOrder=o.sortOrder),e.customListSort=x(o.customListSort,!0),o.crossFilter&&(e.crossFilter=o.crossFilter)};for(const o of v(f(i,"pivotTables"),"pivotTable"))e.pivotTables.push({tabId:Number(o.a.tabId),name:o.a.name});const r=f(f(i,"data"),"tabular");if(r){e.pivotCacheId=Number(r.a.pivotCacheId),n(r.a),e.showMissing=x(r.a.showMissing,!0);for(const o of v(f(r,"items"),"i"))e.items.push({x:Number(o.a.x),s:x(o.a.s,!1),nd:x(o.a.nd,!1)})}for(const o of f(i,"extLst")?.c??[])if($(o.n)==="ext")if(o.a.uri===h.tableSlicerCache){const l=o.c.find(m=>$(m.n)==="tableSlicerCache");l&&(e.kind="table",e.tableId=Number(l.a.tableId),e.column=Number(l.a.column),n(l.a))}else o.a.uri===h.hideNoData&&(e.hideNoData=!0);return e}function U(t){const i=p(t);return v(i,"slicer").map(e=>({name:e.a.name,uid:e.a["xr10:uid"]??null,cache:e.a.cache,caption:e.a.caption??e.a.name,startItem:Number(e.a.startItem??0),columnCount:Number(e.a.columnCount??1),showCaption:x(e.a.showCaption,!0),level:Number(e.a.level??0),style:e.a.style??"SlicerStyleLight1",lockedPosition:x(e.a.lockedPosition,!1),rowHeight:Number(e.a.rowHeight??241300),extra:T(e.a,y)}))}function J(t){const i=p(t),e=f(i,"state"),n=r=>{const o=f(e,r);return o?{start:o.a.startDate,end:o.a.endDate}:null};return{name:i.a.name,sourceName:i.a.sourceName,uid:i.a["xr10:uid"]??null,pivotTables:v(f(i,"pivotTables"),"pivotTable").map(r=>({tabId:Number(r.a.tabId),name:r.a.name})),singleRange:x(e?.a.singleRangeFilterState,!0),minimalRefreshVersion:Number(e?.a.minimalRefreshVersion??6),lastRefreshVersion:Number(e?.a.lastRefreshVersion??6),pivotCacheId:Number(e?.a.pivotCacheId??0),filterType:e?.a.filterType??"unknown",filterId:e?.a.filterId!==void 0?Number(e.a.filterId):null,filterTabId:e?.a.filterTabId!==void 0?Number(e.a.filterTabId):null,filterPivotName:e?.a.filterPivotName??null,selection:n("selection"),bounds:n("bounds")}}function Q(t){const i=p(t);return v(i,"timeline").map(e=>({name:e.a.name,uid:e.a["xr10:uid"]??null,cache:e.a.cache,caption:e.a.caption??e.a.name,showHeader:x(e.a.showHeader,!0),showSelectionLabel:x(e.a.showSelectionLabel,!0),showTimeLevel:x(e.a.showTimeLevel,!0),showHorizontalScrollbar:x(e.a.showHorizontalScrollbar,!0),level:Number(e.a.level??2),selectionLevel:Number(e.a.selectionLevel??e.a.level??2),scrollPosition:e.a.scrollPosition??null,style:e.a.style??"TimeSlicerStyleLight1",extra:T(e.a,P)}))}function Y(t){const i=p(t);for(const e of f(i,"extLst")?.c??[]){if(e.a.uri!==h.pivotCacheId)continue;const n=e.c.find(r=>$(r.n)==="pivotCacheDefinition");if(n?.a.pivotCacheId!==void 0)return Number(n.a.pivotCacheId)}return null}function Z(t,i){const e=`<ext uri="${h.pivotCacheId}" xmlns:x14="${a.x14}"><x14:pivotCacheDefinition pivotCacheId="${i}"/></ext>`;return t.includes(h.pivotCacheId)?t.replace(/(<x14:pivotCacheDefinition\b[^>]*\bpivotCacheId=")\d+/,`$1${i}`):/<extLst>/.test(t)?t.replace(/<extLst>/,`<extLst>${e}`):t.replace("</pivotCacheDefinition>",`<extLst>${e}</extLst></pivotCacheDefinition>`)}import{isoToSerial as ie,serialToIso as oe}from"../pivot/xml.js";export{H as CT,h as EXT,a as NS,k as REL,b as XML_HEAD,W as frameXml,ie as isoToSerial,_ as newDrawingXml,G as parseFrames,K as parseSlicerCacheXml,U as parseSlicersXml,J as parseTimelineCacheXml,Q as parseTimelinesXml,q as patchDrawingFrames,Y as pivotCacheExtId,oe as serialToIso,Z as setPivotCacheExtId,M as slicerCacheXml,j as slicersXml,X as tabPlaceholder,z as timelineCacheXml,V as timelinesXml};
2
+ `,C=A,u=t=>Object.entries(t).filter(([,i])=>i!=null).map(([i,e])=>` ${i}="${C(e)}"`).join(""),f=(t,i)=>t?.c?.find(e=>e.n===i)??null,v=(t,i)=>t?t.c.filter(e=>e.n===i):[],$=t=>t.slice(t.indexOf(":")+1),x=(t,i)=>t===void 0?i:t==="1"||t==="true";function M(t){const i=u({name:t.name,"xr10:uid":t.uid??void 0,sourceName:t.sourceName,...t.extra??{}}),e=`${b}<slicerCacheDefinition xmlns="${a.x14}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}"${i}>`,n={sortOrder:t.sortOrder&&t.sortOrder!=="ascending"?t.sortOrder:void 0,customListSort:t.customListSort===!1?"0":void 0,crossFilter:t.crossFilter&&t.crossFilter!=="showItemsWithDataAtTop"?t.crossFilter:void 0},r=[];let o="";if(t.kind==="table")r.push(`<x:ext uri="${h.tableSlicerCache}" xmlns:x15="${a.x15}"><x15:tableSlicerCache${u({tableId:t.tableId,column:t.column,...n})}/></x:ext>`);else{const l=(t.pivotTables??[]).map(c=>`<pivotTable${u({tabId:c.tabId,name:c.name})}/>`).join("");o+=`<pivotTables>${l}</pivotTables>`;const m=(t.items??[]).map(c=>`<i${u({x:c.x,s:c.s?"1":void 0,nd:c.nd?"1":void 0})}/>`).join(""),s={pivotCacheId:t.pivotCacheId,...n,showMissing:t.showMissing===!1?"0":void 0};o+=`<data><tabular${u(s)}><items count="${(t.items??[]).length}">${m}</items></tabular></data>`}t.hideNoData&&r.push(`<x:ext uri="${h.hideNoData}" xmlns:x15="${a.x15}"><x15:slicerCacheHideItemsWithNoData/></x:ext>`);for(const l of t.rawExt??[])r.push(l);return`${e}${o}${r.length?`<extLst>${r.join("")}</extLst>`:""}</slicerCacheDefinition>`}function j(t){const i=e=>{const n={name:e.name,"xr10:uid":e.uid??void 0,cache:e.cache,caption:e.caption,startItem:e.startItem?e.startItem:void 0,columnCount:e.columnCount&&e.columnCount!==1?e.columnCount:void 0,showCaption:e.showCaption===!1?"0":void 0,level:e.level?e.level:void 0,style:e.style&&e.style!=="SlicerStyleLight1"?e.style:void 0,lockedPosition:e.lockedPosition?"1":void 0,rowHeight:e.rowHeight??241300,...e.extra??{}};return`<slicer${u(n)}/>`};return`${b}<slicers xmlns="${a.x14}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}">${t.map(i).join("")}</slicers>`}function z(t){const i=(t.pivotTables??[]).map(r=>`<pivotTable${u({tabId:r.tabId,name:r.name})}/>`).join(""),e=(r,o)=>o?`<${r}${u({startDate:o.start,endDate:o.end})}/>`:"",n=u({singleRangeFilterState:t.singleRange===!1?"0":void 0,minimalRefreshVersion:t.minimalRefreshVersion??6,lastRefreshVersion:t.lastRefreshVersion??6,pivotCacheId:t.pivotCacheId,filterType:t.selection?"dateBetween":"unknown",filterId:t.selection?t.filterId:void 0,filterTabId:t.selection?t.filterTabId:void 0,filterPivotName:t.selection?t.filterPivotName:void 0});return`${b}<timelineCacheDefinition xmlns="${a.x15}" xmlns:x15="${a.x15}" xmlns:mc="${a.mc}" mc:Ignorable="xr10" xmlns:xr10="${a.xr10}"${u({name:t.name,"xr10:uid":t.uid??void 0,sourceName:t.sourceName,...t.extra??{}})}><pivotTables>${i}</pivotTables><state${n}>${e("selection",t.selection)}${e("bounds",t.bounds)}</state></timelineCacheDefinition>`}function V(t){const i=e=>`<timeline${u({name:e.name,"xr10:uid":e.uid??void 0,cache:e.cache,caption:e.caption,showHeader:e.showHeader===!1?"0":void 0,showSelectionLabel:e.showSelectionLabel===!1?"0":void 0,showTimeLevel:e.showTimeLevel===!1?"0":void 0,showHorizontalScrollbar:e.showHorizontalScrollbar===!1?"0":void 0,level:e.level??2,selectionLevel:e.selectionLevel??e.level??2,scrollPosition:e.scrollPosition??void 0,style:e.style&&e.style!=="TimeSlicerStyleLight1"?e.style:void 0,...e.extra??{}})}/>`;return`${b}<timelines xmlns="${a.x15}" xmlns:mc="${a.mc}" mc:Ignorable="x xr10" xmlns:x="${a.main}" xmlns:xr10="${a.xr10}">${t.map(i).join("")}</timelines>`}const E={pivot:{choice:`xmlns:a14="${a.a14}" Requires="a14"`,uri:a.sle,inner:t=>`<sle:slicer xmlns:sle="${a.sle}" name="${C(t)}"/>`},table:{choice:`xmlns:sle15="${a.sle15}" Requires="sle15"`,uri:a.sle,inner:t=>`<sle:slicer xmlns:sle="${a.sle}" name="${C(t)}"/>`},timeline:{choice:`xmlns:tsle="${a.tsle}" Requires="tsle"`,uri:a.tsle,inner:t=>`<tsle:timeslicer xmlns:tsle="${a.tsle}" name="${C(t)}"/>`}},L={pivot:"This shape represents a slicer. Slicers are supported in Excel 2010 or later.",table:"This shape represents a table slicer. Table slicers are supported in Excel 2013 or later.",timeline:"Timeline: Works in Excel 2013 or higher. Do not move or resize."};function W({kind:t,name:i,id:e,from:n,to:r,cx:o=1828800,cy:l=2524125}){const m=E[t],s=(c,d)=>`<xdr:${c}><xdr:col>${d.col}</xdr:col><xdr:colOff>${d.colOff}</xdr:colOff><xdr:row>${d.row}</xdr:row><xdr:rowOff>${d.rowOff}</xdr:rowOff></xdr:${c}>`;return`<xdr:twoCellAnchor editAs="absolute">${s("from",n)}${s("to",r)}<mc:AlternateContent xmlns:mc="${a.mc}"><mc:Choice ${m.choice}><xdr:graphicFrame macro=""><xdr:nvGraphicFramePr><xdr:cNvPr id="${e}" name="${C(i)}"/><xdr:cNvGraphicFramePr/></xdr:nvGraphicFramePr><xdr:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/></xdr:xfrm><a:graphic><a:graphicData uri="${m.uri}">${m.inner(i)}</a:graphicData></a:graphic></xdr:graphicFrame></mc:Choice><mc:Fallback xmlns=""><xdr:sp macro="" textlink=""><xdr:nvSpPr><xdr:cNvPr id="0" name=""/><xdr:cNvSpPr><a:spLocks noTextEdit="1"/></xdr:cNvSpPr></xdr:nvSpPr><xdr:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${o}" cy="${l}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:solidFill><a:prstClr val="white"/></a:solidFill><a:ln w="1"><a:solidFill><a:prstClr val="green"/></a:solidFill></a:ln></xdr:spPr><xdr:txBody><a:bodyPr vertOverflow="clip" horzOverflow="clip"/><a:lstStyle/><a:p><a:r><a:rPr lang="en-US" sz="1100"/><a:t>${L[t]}</a:t></a:r></a:p></xdr:txBody></xdr:sp></mc:Fallback></mc:AlternateContent><xdr:clientData/></xdr:twoCellAnchor>`}const _=t=>`${b}<xdr:wsDr xmlns:xdr="${a.xdr}" xmlns:a="${a.a}">${t}</xdr:wsDr>`,D=/<xdr:(twoCellAnchor|oneCellAnchor|absoluteAnchor)\b[\s\S]*?<\/xdr:\1>/g,S=/<(?:\w+:)?(slicer|timeslicer)\b[^>]*\bname="([^"]*)"/;function G(t){const i=[];for(const e of t.matchAll(D)){const n=e[0];if(!/drawing\/20(?:10|12)\/(?:time)?slicer/.test(n))continue;const r=S.exec(n);if(!r)continue;const o=m=>{const s=new RegExp(`<xdr:${m}>\\s*<xdr:col>(\\d+)</xdr:col>\\s*<xdr:colOff>(-?\\d+)</xdr:colOff>\\s*<xdr:row>(\\d+)</xdr:row>\\s*<xdr:rowOff>(-?\\d+)</xdr:rowOff>`).exec(n);return s?{col:Number(s[1]),colOff:Number(s[2]),row:Number(s[3]),rowOff:Number(s[4])}:null},l=(m,s,c)=>{const d=new RegExp(`<xdr:${m}\\b[^>]*>`).exec(n)?.[0];if(d===void 0)return null;const w=F=>Number(new RegExp(`\\b${F}="(-?\\d+)"`).exec(d)?.[1]),g=w(s),N=w(c);return Number.isFinite(g)&&Number.isFinite(N)?{[s]:g,[c]:N}:null};i.push({kind:r[1]==="timeslicer"?"timeline":/Requires="sle15"/.test(n)?"table":"pivot",name:I(r[2]),id:Number(/<xdr:cNvPr\b[^>]*\bid="(\d+)"/.exec(n)?.[1]??0),from:o("from"),to:o("to"),pos:e[1]==="absoluteAnchor"?l("pos","x","y"):null,ext:e[1]==="twoCellAnchor"?null:l("ext","cx","cy"),raw:n})}return i}function q(t,{upsert:i=[],remove:e=[]}){const n=new Map(i.map(s=>[s.name,s.xml])),r=new Set(e),o=new Set;let l=t.replace(D,s=>{if(!/drawing\/20(?:10|12)\/(?:time)?slicer/.test(s))return s;const c=S.exec(s);if(!c)return s;const d=I(c[2]);return r.has(d)?"":n.has(d)?(o.add(d),n.get(d)):s});const m=i.filter(s=>!o.has(s.name)).map(s=>s.xml).join("");return m&&(l=l.replace(/<\/(\w+:)?wsDr>\s*$/,s=>`${m}${s}`)),l}const y=new Set(["name","xr10:uid","cache","caption","startItem","columnCount","showCaption","level","style","lockedPosition","rowHeight"]),P=new Set(["name","xr10:uid","cache","caption","showHeader","showSelectionLabel","showTimeLevel","showHorizontalScrollbar","level","selectionLevel","scrollPosition","style"]),T=(t,i)=>{const e={};for(const[n,r]of Object.entries(t))!i.has(n)&&!n.startsWith("xmlns")&&n!=="mc:Ignorable"&&(e[n]=r);return e};function K(t){const i=p(t),e={name:i.a.name,sourceName:i.a.sourceName,uid:i.a["xr10:uid"]??null,kind:"pivot",sortOrder:"ascending",customListSort:!0,crossFilter:"showItemsWithDataAtTop",showMissing:!0,hideNoData:!1,pivotTables:[],items:[],pivotCacheId:null,tableId:null,column:null},n=o=>{o.sortOrder&&(e.sortOrder=o.sortOrder),e.customListSort=x(o.customListSort,!0),o.crossFilter&&(e.crossFilter=o.crossFilter)};for(const o of v(f(i,"pivotTables"),"pivotTable"))e.pivotTables.push({tabId:Number(o.a.tabId),name:o.a.name});const r=f(f(i,"data"),"tabular");if(r){e.pivotCacheId=Number(r.a.pivotCacheId),n(r.a),e.showMissing=x(r.a.showMissing,!0);for(const o of v(f(r,"items"),"i"))e.items.push({x:Number(o.a.x),s:x(o.a.s,!1),nd:x(o.a.nd,!1)})}for(const o of f(i,"extLst")?.c??[])if($(o.n)==="ext")if(o.a.uri===h.tableSlicerCache){const l=o.c.find(m=>$(m.n)==="tableSlicerCache");l&&(e.kind="table",e.tableId=Number(l.a.tableId),e.column=Number(l.a.column),n(l.a))}else o.a.uri===h.hideNoData&&(e.hideNoData=!0);return e}function U(t){const i=p(t);return v(i,"slicer").map(e=>({name:e.a.name,uid:e.a["xr10:uid"]??null,cache:e.a.cache,caption:e.a.caption??e.a.name,startItem:Number(e.a.startItem??0),columnCount:Number(e.a.columnCount??1),showCaption:x(e.a.showCaption,!0),level:Number(e.a.level??0),style:e.a.style??"SlicerStyleLight1",lockedPosition:x(e.a.lockedPosition,!1),rowHeight:Number(e.a.rowHeight??241300),extra:T(e.a,y)}))}function J(t){const i=p(t),e=f(i,"state"),n=r=>{const o=f(e,r);return o?{start:o.a.startDate,end:o.a.endDate}:null};return{name:i.a.name,sourceName:i.a.sourceName,uid:i.a["xr10:uid"]??null,pivotTables:v(f(i,"pivotTables"),"pivotTable").map(r=>({tabId:Number(r.a.tabId),name:r.a.name})),singleRange:x(e?.a.singleRangeFilterState,!0),minimalRefreshVersion:Number(e?.a.minimalRefreshVersion??6),lastRefreshVersion:Number(e?.a.lastRefreshVersion??6),pivotCacheId:Number(e?.a.pivotCacheId??0),filterType:e?.a.filterType??"unknown",filterId:e?.a.filterId!==void 0?Number(e.a.filterId):null,filterTabId:e?.a.filterTabId!==void 0?Number(e.a.filterTabId):null,filterPivotName:e?.a.filterPivotName??null,selection:n("selection"),bounds:n("bounds")}}function Q(t){const i=p(t);return v(i,"timeline").map(e=>({name:e.a.name,uid:e.a["xr10:uid"]??null,cache:e.a.cache,caption:e.a.caption??e.a.name,showHeader:x(e.a.showHeader,!0),showSelectionLabel:x(e.a.showSelectionLabel,!0),showTimeLevel:x(e.a.showTimeLevel,!0),showHorizontalScrollbar:x(e.a.showHorizontalScrollbar,!0),level:Number(e.a.level??2),selectionLevel:Number(e.a.selectionLevel??e.a.level??2),scrollPosition:e.a.scrollPosition??null,style:e.a.style??"TimeSlicerStyleLight1",extra:T(e.a,P)}))}function Y(t){const i=p(t);for(const e of f(i,"extLst")?.c??[]){if(e.a.uri!==h.pivotCacheId)continue;const n=e.c.find(r=>$(r.n)==="pivotCacheDefinition");if(n?.a.pivotCacheId!==void 0)return Number(n.a.pivotCacheId)}return null}function Z(t,i){const e=`<ext uri="${h.pivotCacheId}" xmlns:x14="${a.x14}"><x14:pivotCacheDefinition pivotCacheId="${i}"/></ext>`;return t.includes(h.pivotCacheId)?t.replace(/(<x14:pivotCacheDefinition\b[^>]*\bpivotCacheId=")\d+/,`$1${i}`):/<extLst>/.test(t)?t.replace(/<extLst>/,()=>`<extLst>${e}`):t.replace("</pivotCacheDefinition>",()=>`<extLst>${e}</extLst></pivotCacheDefinition>`)}import{isoToSerial as ie,serialToIso as oe}from"../pivot/xml.js";export{H as CT,h as EXT,a as NS,k as REL,b as XML_HEAD,W as frameXml,ie as isoToSerial,_ as newDrawingXml,G as parseFrames,K as parseSlicerCacheXml,U as parseSlicersXml,J as parseTimelineCacheXml,Q as parseTimelinesXml,q as patchDrawingFrames,Y as pivotCacheExtId,oe as serialToIso,Z as setPivotCacheExtId,M as slicerCacheXml,j as slicersXml,X as tabPlaceholder,z as timelineCacheXml,V as timelinesXml};
@@ -1 +1 @@
1
- function C(t,h,r){const{r0:s,c0:a,r1:o,c1:e,headerRows:n,totalsRows:d,columns:A}=t,T=s+n,E=o-d;let f=h.slice(1,-1),g=!1;f.trimStart()[0]==="@"&&(g=!0,f=f.trimStart().slice(1));const L=[];if(f.trim()!=="")if(f.trimStart()[0]==="["){const c=/\[((?:[^\]']|'.)*)\]/g;let l;for(;(l=c.exec(f))!==null;)L.push(l[1].replace(/'(.)/g,"$1"))}else L.push(f.replace(/'(.)/g,"$1"));const u=new Set,p=[];for(const c of L){const l=c.toUpperCase(),i=l.trim();if(i==="#ALL"||i==="#DATA"||i==="#HEADERS"||i==="#TOTALS"||i==="#THIS ROW"){u.add(i),i==="#THIS ROW"&&(g=!0);continue}let R=A.findIndex(w=>w.toUpperCase()===l);if(R<0&&(R=A.findIndex(w=>w.toUpperCase()===i)),R<0)return"REF";p.push(a+R)}let m=T,S=E;if(u.has("#ALL"))m=s,S=o;else{const c=u.has("#HEADERS"),l=u.has("#TOTALS"),i=u.has("#DATA");if(c&&n===0||l&&d===0||c&&l&&!i)return"REF";(c||l||i)&&(m=c?s:i?T:o,S=l?o:i?E:s)}const U=p.length?Math.min(...p):a,b=p.length?Math.max(...p):e;if(g){if(r<T||r>E)return"VALUE";m=r,S=r}return{top:m,left:U,bottom:S,right:b}}function D(t,h){if(!h||h.size===0)return t;let r="",s=0;const a=t.length;for(;s<a;){const o=t[s];if(o==='"'||o==="'"){let e=s+1;for(;e<a;){if(t[e]===o){if(t[e+1]!==o)break;e++}e++}r+=t.slice(s,e+1),s=e+1}else if(o==="["){let e=0,n=s;for(;n<a;n++)if(t[n]==="'")n++;else if(t[n]==="[")e++;else if(t[n]==="]"&&--e===0)break;r+=t.slice(s,n+1),s=n+1}else if(/[A-Za-z_\\]/.test(o)){let e=s+1;for(;e<a&&/[A-Za-z0-9_.\\]/.test(t[e]);)e++;const n=t.slice(s,e),d=r[r.length-1],A=h.has(n.toUpperCase())&&t[e]!=="["&&t[e]!=="("&&t[e]!=="!"&&d!=="!";r+=A?`${n}[]`:n,s=e}else r+=o,s++}return r}export{D as expandBareTables,C as resolveStructuredSpec};
1
+ function C(t,h,r){const{r0:s,c0:a,r1:o,c1:e,headerRows:i,totalsRows:d,columns:m}=t,T=s+i,E=o-d;let f=h.slice(1,-1),g=!1;f.trimStart()[0]==="@"&&(g=!0,f=f.trimStart().slice(1));const L=[];if(f.trim()!=="")if(f.trimStart()[0]==="["){const c=/\[((?:[^\]']|'.)*)\]/g;let l;for(;(l=c.exec(f))!==null;)L.push(l[1])}else L.push(f);const u=new Set,p=[];for(const c of L){const l=c.replace(/'(.)/g,"$1").toUpperCase(),n=l.trim();if(c.trim()[0]!=="'"){if(n==="#ALL"||n==="#DATA"||n==="#HEADERS"||n==="#TOTALS"||n==="#THIS ROW"){u.add(n),n==="#THIS ROW"&&(g=!0);continue}}let R=m.findIndex(w=>w.toUpperCase()===l);if(R<0&&(R=m.findIndex(w=>w.toUpperCase()===n)),R<0)return"REF";p.push(a+R)}let A=T,S=E;if(u.has("#ALL"))A=s,S=o;else{const c=u.has("#HEADERS"),l=u.has("#TOTALS"),n=u.has("#DATA");if(c&&i===0||l&&d===0||c&&l&&!n)return"REF";(c||l||n)&&(A=c?s:n?T:o,S=l?o:n?E:s)}const U=p.length?Math.min(...p):a,b=p.length?Math.max(...p):e;if(g){if(r<T||r>E)return"VALUE";A=r,S=r}return{top:A,left:U,bottom:S,right:b}}function D(t,h){if(!h||h.size===0)return t;let r="",s=0;const a=t.length;for(;s<a;){const o=t[s];if(o==='"'||o==="'"){let e=s+1;for(;e<a;){if(t[e]===o){if(t[e+1]!==o)break;e++}e++}r+=t.slice(s,e+1),s=e+1}else if(o==="["){let e=0,i=s;for(;i<a;i++)if(t[i]==="'")i++;else if(t[i]==="[")e++;else if(t[i]==="]"&&--e===0)break;r+=t.slice(s,i+1),s=i+1}else if(/[A-Za-z_\\]/.test(o)){let e=s+1;for(;e<a&&/[A-Za-z0-9_.\\]/.test(t[e]);)e++;const i=t.slice(s,e),d=r[r.length-1],m=h.has(i.toUpperCase())&&t[e]!=="["&&t[e]!=="("&&t[e]!=="!"&&d!=="!";r+=m?`${i}[]`:i,s=e}else r+=o,s++}return r}export{D as expandBareTables,C as resolveStructuredSpec};
package/slicers/write.js CHANGED
@@ -1 +1 @@
1
- import{EXT as c,NS as x,REL as b,newDrawingXml as C,patchDrawingFrames as h}from"./format.js";import{ensureDrawingElement as T,mergeContentTypes as S}from"../objects/drawing-xml.js";import{escapeMarkup as o}from"../io/xml-escape.js";const y=n=>n.slicers?.removedParts??[];function L(n,r){const s=r.slicers;return s?S(n,s.contentTypes,s.removedParts.map(t=>`/${t}`)):n}function k(n,r){const s=r.slicers;if(!s)return n;const t=s.workbookRels.map(e=>`<Relationship Id="${o(e.id)}" Type="${o(e.type)}" Target="${o(e.target)}"/>`).join("");return n.replace("</Relationships>",`${t}</Relationships>`)}const $=(n,r)=>n.replace(new RegExp(`<ext\\b[^>]*uri="${r.replace(/[{}-]/g,"\\$&")}"[^>]*>[\\s\\S]*?</ext>`),"");function g(n,r,s){const t=s.join("");let e=n;if(t)if(/<\/extLst>\s*$/.test(e.slice(0,e.lastIndexOf(r)))){const l=e.lastIndexOf("</extLst>");e=`${e.slice(0,l)}${t}${e.slice(l)}`}else{const l=e.lastIndexOf(r);e=`${e.slice(0,l)}<extLst>${t}</extLst>${e.slice(l)}`}return e.replace(/<extLst>\s*<\/extLst>/,"")}const p=(n,r)=>r.map(s=>`<${n} xmlns:r="${x.r}" r:id="${o(s)}"/>`).join("");function E(n,r){const s=r.slicers;if(!s)return n;let t=n;for(const i of[c.wbPivotSlicerCaches,c.wbTableSlicerCaches,c.wbTimelineCaches])t=$(t,i);const e=[];s.pivotCaches.length&&e.push(`<ext uri="${c.wbPivotSlicerCaches}" xmlns:x14="${x.x14}"><x14:slicerCaches>${p("x14:slicerCache",s.pivotCaches)}</x14:slicerCaches></ext>`),s.tableCaches.length&&e.push(`<ext uri="${c.wbTableSlicerCaches}" xmlns:x15="${x.x15}"><x15:slicerCaches xmlns:x14="${x.x14}">${p("x14:slicerCache",s.tableCaches)}</x15:slicerCaches></ext>`),s.timelineCaches.length&&e.push(`<ext uri="${c.wbTimelineCaches}" xmlns:x15="${x.x15}"><x15:timelineCacheRefs>${p("x15:timelineCacheRef",s.timelineCaches)}</x15:timelineCacheRefs></ext>`),t=g(t,"</workbook>",e);for(const i of s.removedNames)t=t.replace(new RegExp(`<definedName\\b[^>]*\\bname="${i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}"[^>]*>[^<]*</definedName>`),"");const l=s.names.filter(i=>!t.includes(`name="${o(i)}"`));if(l.length){const i=l.map(d=>`<definedName name="${o(d)}">#N/A</definedName>`).join("");/<\/definedNames>/.test(t)?t=t.replace("</definedNames>",`${i}</definedNames>`):t=t.replace("</sheets>",`</sheets><definedNames>${i}</definedNames>`)}return t.replace(/<definedNames>\s*<\/definedNames>/,"")}function R(n,r){let s=n;for(const e of[c.wsPivotSlicers,c.wsTableSlicers,c.wsTimelines])s=$(s,e);const t=[];return r.pivotIds.length&&t.push(`<ext uri="${c.wsPivotSlicers}" xmlns:x14="${x.x14}"><x14:slicerList>${p("x14:slicer",r.pivotIds)}</x14:slicerList></ext>`),r.tableIds.length&&t.push(`<ext uri="${c.wsTableSlicers}" xmlns:x15="${x.x15}"><x14:slicerList xmlns:x14="${x.x14}">${p("x14:slicer",r.tableIds)}</x14:slicerList></ext>`),r.timelineIds.length&&t.push(`<ext uri="${c.wsTimelines}" xmlns:x15="${x.x15}"><x15:timelineRefs>${p("x15:timelineRef",r.timelineIds)}</x15:timelineRefs></ext>`),g(s,"</worksheet>",t)}async function P({tail:n,index:r,info:s,source:t,extra:e,relsName:l}){const i=e.plan.slicers?.sheets?.[r];if(!i)return n;e.rels.has(l)||e.rels.set(l,[]);const d=e.rels.get(l);for(const a of i.rels)d.push(`<Relationship Id="${o(a.id)}" Type="${o(a.type)}" Target="${o(a.target)}"/>`);let m=R(n,i);const f=i.frames;if(f.upsert.length===0&&f.remove.length===0)return m;const u=s.objects;if(u){const a=e.parts.find(w=>w.path===u.path);return a&&(a.xml=h(typeof a.xml=="string"?a.xml:new TextDecoder().decode(a.xml),f)),m}if(i.drawingExisting){const a=await t.zip.text(i.drawingPath);return e.parts.push({path:i.drawingPath,xml:h(a,f)}),m}return e.parts.push({path:i.drawingPath,xml:C(h("",{upsert:[]})+f.upsert.map(a=>a.xml).join(""))}),d.push(`<Relationship Id="${o(i.drawingRelId)}" Type="${b.drawing}" Target="${o(i.drawingTarget)}"/>`),m=T(m,`<drawing xmlns:r="${x.r}" r:id="${o(i.drawingRelId)}"/>`),m}async function j(n,r,s){const t=r.slicers;if(!t)return;const e=r.sheetRefs??[],l=i=>i.replace(/@@TAB(\d+)@@/g,(d,m)=>String(e[Number(m)]?.sheetId??Number(m)+1));for(const i of t.parts)await n.addBytes(i.name,l(i.xml)),s.add(i.name)}export{P as applySlicerSheet,L as patchSlicerContentTypes,R as patchSlicerSheetTail,E as patchSlicerWorkbook,k as patchSlicerWorkbookRels,y as removedSlicerParts,j as writeSlicerParts};
1
+ import{EXT as c,NS as x,REL as b,newDrawingXml as C,patchDrawingFrames as h}from"./format.js";import{ensureDrawingElement as T,mergeContentTypes as S}from"../objects/drawing-xml.js";import{escapeMarkup as o}from"../io/xml-escape.js";const y=n=>n.slicers?.removedParts??[];function L(n,r){const s=r.slicers;return s?S(n,s.contentTypes,s.removedParts.map(t=>`/${t}`)):n}function k(n,r){const s=r.slicers;if(!s)return n;const t=s.workbookRels.map(e=>`<Relationship Id="${o(e.id)}" Type="${o(e.type)}" Target="${o(e.target)}"/>`).join("");return n.replace("</Relationships>",()=>`${t}</Relationships>`)}const $=(n,r)=>n.replace(new RegExp(`<ext\\b[^>]*uri="${r.replace(/[{}-]/g,"\\$&")}"[^>]*>[\\s\\S]*?</ext>`),"");function g(n,r,s){const t=s.join("");let e=n;if(t)if(/<\/extLst>\s*$/.test(e.slice(0,e.lastIndexOf(r)))){const l=e.lastIndexOf("</extLst>");e=`${e.slice(0,l)}${t}${e.slice(l)}`}else{const l=e.lastIndexOf(r);e=`${e.slice(0,l)}<extLst>${t}</extLst>${e.slice(l)}`}return e.replace(/<extLst>\s*<\/extLst>/,"")}const p=(n,r)=>r.map(s=>`<${n} xmlns:r="${x.r}" r:id="${o(s)}"/>`).join("");function E(n,r){const s=r.slicers;if(!s)return n;let t=n;for(const i of[c.wbPivotSlicerCaches,c.wbTableSlicerCaches,c.wbTimelineCaches])t=$(t,i);const e=[];s.pivotCaches.length&&e.push(`<ext uri="${c.wbPivotSlicerCaches}" xmlns:x14="${x.x14}"><x14:slicerCaches>${p("x14:slicerCache",s.pivotCaches)}</x14:slicerCaches></ext>`),s.tableCaches.length&&e.push(`<ext uri="${c.wbTableSlicerCaches}" xmlns:x15="${x.x15}"><x15:slicerCaches xmlns:x14="${x.x14}">${p("x14:slicerCache",s.tableCaches)}</x15:slicerCaches></ext>`),s.timelineCaches.length&&e.push(`<ext uri="${c.wbTimelineCaches}" xmlns:x15="${x.x15}"><x15:timelineCacheRefs>${p("x15:timelineCacheRef",s.timelineCaches)}</x15:timelineCacheRefs></ext>`),t=g(t,"</workbook>",e);for(const i of s.removedNames)t=t.replace(new RegExp(`<definedName\\b[^>]*\\bname="${i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}"[^>]*>[^<]*</definedName>`),"");const l=s.names.filter(i=>!t.includes(`name="${o(i)}"`));if(l.length){const i=l.map(d=>`<definedName name="${o(d)}">#N/A</definedName>`).join("");/<\/definedNames>/.test(t)?t=t.replace("</definedNames>",()=>`${i}</definedNames>`):t=t.replace("</sheets>",()=>`</sheets><definedNames>${i}</definedNames>`)}return t.replace(/<definedNames>\s*<\/definedNames>/,"")}function R(n,r){let s=n;for(const e of[c.wsPivotSlicers,c.wsTableSlicers,c.wsTimelines])s=$(s,e);const t=[];return r.pivotIds.length&&t.push(`<ext uri="${c.wsPivotSlicers}" xmlns:x14="${x.x14}"><x14:slicerList>${p("x14:slicer",r.pivotIds)}</x14:slicerList></ext>`),r.tableIds.length&&t.push(`<ext uri="${c.wsTableSlicers}" xmlns:x15="${x.x15}"><x14:slicerList xmlns:x14="${x.x14}">${p("x14:slicer",r.tableIds)}</x14:slicerList></ext>`),r.timelineIds.length&&t.push(`<ext uri="${c.wsTimelines}" xmlns:x15="${x.x15}"><x15:timelineRefs>${p("x15:timelineRef",r.timelineIds)}</x15:timelineRefs></ext>`),g(s,"</worksheet>",t)}async function P({tail:n,index:r,info:s,source:t,extra:e,relsName:l}){const i=e.plan.slicers?.sheets?.[r];if(!i)return n;e.rels.has(l)||e.rels.set(l,[]);const d=e.rels.get(l);for(const a of i.rels)d.push(`<Relationship Id="${o(a.id)}" Type="${o(a.type)}" Target="${o(a.target)}"/>`);let m=R(n,i);const f=i.frames;if(f.upsert.length===0&&f.remove.length===0)return m;const u=s.objects;if(u){const a=e.parts.find(w=>w.path===u.path);return a&&(a.xml=h(typeof a.xml=="string"?a.xml:new TextDecoder().decode(a.xml),f)),m}if(i.drawingExisting){const a=await t.zip.text(i.drawingPath);return e.parts.push({path:i.drawingPath,xml:h(a,f)}),m}return e.parts.push({path:i.drawingPath,xml:C(h("",{upsert:[]})+f.upsert.map(a=>a.xml).join(""))}),d.push(`<Relationship Id="${o(i.drawingRelId)}" Type="${b.drawing}" Target="${o(i.drawingTarget)}"/>`),m=T(m,`<drawing xmlns:r="${x.r}" r:id="${o(i.drawingRelId)}"/>`),m}async function j(n,r,s){const t=r.slicers;if(!t)return;const e=r.sheetRefs??[],l=i=>i.replace(/@@TAB(\d+)@@/g,(d,m)=>String(e[Number(m)]?.sheetId??Number(m)+1));for(const i of t.parts)await n.addBytes(i.name,l(i.xml)),s.add(i.name)}export{P as applySlicerSheet,L as patchSlicerContentTypes,R as patchSlicerSheetTail,E as patchSlicerWorkbook,k as patchSlicerWorkbookRels,y as removedSlicerParts,j as writeSlicerParts};