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