@sheetxl/query 0.8.0-beta.6 → 0.8.0-beta.9
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.
- package/browser/cjs/index.cjs +42 -40
- package/browser/esm/index.mjs +1054 -888
- package/node/esm/index.mjs +1394 -1225
- package/package.json +3 -3
- package/types/src/encode/encodeCell.d.ts +9 -7
- package/types/src/grep/GrepTypes.d.ts +17 -29
- package/types/src/markdown/appendSections.d.ts +10 -1
- package/types/src/markdown/describeShape.d.ts +30 -0
- package/types/src/markdown/index.d.ts +1 -0
- package/types/src/markdown/renderCell.d.ts +2 -1
- package/types/src/markdown/renderMovable.d.ts +12 -1
package/browser/cjs/index.cjs
CHANGED
|
@@ -1,45 +1,47 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@sheetxl/sdk");var t;(t||={}).Mode={Display:`display`,Value:`value`};function n(e){return Number.isFinite(e)?function(e){let t=e.indexOf(`e`);if(t===-1)return e;let n=e.substring(t+2);return`${e.substring(0,t)}E${e[t+1]}${n.length<2?`0`+n:n}`}(String(Number(e.toPrecision(15)))):String(e)}function r(t,r){if(!Number.isFinite(t))return String(t);if(!r||r===`General`)return n(t);try{let i=e.NumberFormat.getEngine().format(r,t)?.text;return i?i.trim():n(t)}catch{return n(t)}}function i(e,n){let r=n===t.Mode.Value,i=e.getText({hideStringPrefix:!0,useFormattingCategory:r});return i?{match:i,display:e.getText({useFormattingCategory:r})}:null}function a(t){if(t==null)return null;if(typeof t==`string`)return{match:t,display:`'${t}`};if(typeof t==`boolean`){let e=t?`TRUE`:`FALSE`;return{match:e,display:e}}if(typeof t==`number`){let e=n(t);return{match:e,display:e}}if(e.FormulaError.isError(t)){let e=t.getLabel();return{match:e,display:e}}let r=t.toString();return{match:r,display:r}}var o=[`display`,`value`,`raw`,`formula`,`hyperlink`,`numberFormat`,`comment`,`shape`,`chart`,`name`],s=[`display`,`value`,`formula`,`comment`,`shape`,`chart`,`name`],c=(e,t)=>e<=t+3?e:t,l=e=>{if(!e)return null;let t=String(e.toHex?.()??``);if(!t)return e.toString();let n=/^#FF/i.test(t)&&t.length===9?`#${t.slice(3)}`:t,r=e.toString();if(!r)return n;let i=r.toLowerCase().replace(/^#/,``);return i===n.slice(1).toLowerCase()||i===t.slice(1).toLowerCase()?n:`${n} (${r.replace(/\d+\.\d{4,}/g,e=>String(parseFloat(Number(e).toFixed(2))))})`},u=t=>{let n=t.getFill(),r=n.getType();if(r===e.IFill.Type.None)return null;if(r===e.IFill.Type.Pattern){let t=n,r=t.getPatternType();if(r===e.IFill.BuiltInSheetPattern.None)return null;let i=l(t.getForeground());if(r===e.IFill.BuiltInSheetPattern.Solid)return i?`solid ${i}`:`solid`;let a=l(t.getBackground());return[`${r} pattern`,i,a?`on ${a}`:null].filter(Boolean).join(` `)}let i=l(n.getColor?.());return i?`${r} ${i}`:r},d=e=>{let t=p(e);return t.length>0?t.join(` · `):null},f=new Set([`top`,`left`,`bottom`,`right`]),p=e=>{let t=e.getBorders(),n=[[`top`,t.getTop()],[`left`,t.getLeft()],[`bottom`,t.getBottom()],[`right`,t.getRight()],[`horizontal`,t.getHorizontal()],[`vertical`,t.getVertical()],[`diagonalUp`,t.getDiagonalUp()],[`diagonalDown`,t.getDiagonalDown()]],r=new Map;for(let[e,t]of n){let n=t?.getStyle?.();if(!n||n===`none`)continue;let i=l(t?.getColor?.()),a=i?`${n} ${i}`:n,o=r.get(a);o?o.push(e):r.set(a,[e])}let i=[];for(let[e,t]of r){let n=t.length===4&&t.every(e=>f.has(e));i.push(`${n?`outline`:t.join(`+`)} ${e}`)}return i},m=e=>{let t=e.getNumberFormat();return t&&t!==`General`?t:null},h=(e,t)=>{let n=e.getAlignment(),r=t.getAlignment(),i=[];return n.getHorizontal()!==r.getHorizontal()&&i.push(`h ${n.getHorizontal()}`),n.getVertical()!==r.getVertical()&&i.push(`v ${n.getVertical()}`),n.getOverflow()!==r.getOverflow()&&i.push(n.getOverflow()),n.getIndent()!==r.getIndent()&&i.push(`indent ${n.getIndent()}`),n.getRotation()!==r.getRotation()&&i.push(`rotation ${n.getRotation()}`),i.length>0?i.join(` · `):null},g=(e,t)=>{let n=e.getFont(),r=t.getFont(),i=[];n.getBold()!==r.getBold()&&i.push(n.getBold()?`bold`:`not bold`),n.getItalic()!==r.getItalic()&&i.push(n.getItalic()?`italic`:`not italic`),n.getUnderline()!==r.getUnderline()&&i.push(`underline ${n.getUnderline()}`),n.getStrike()!==r.getStrike()&&i.push(n.getStrike()?`strike`:`not strike`),n.getSize()!==r.getSize()&&i.push(`${n.getSize()}pt`),n.getFamily()!==r.getFamily()&&i.push(n.getFamily());let a=l(n.getColor());return a!==l(r.getColor())&&i.push(a??`no color`),i.length>0?i.join(` · `):null},_=e.ICellRange.Feature;function v(t,n,r){let{rowIndex:i,colIndex:a}=n,o=r===`row`,s=o?a:i;if(s===0)return null;let c=t.getRange({rowStart:i,rowEnd:i,colStart:a,colEnd:a}).getSurrounding({contentOnly:!0}).getCoords(),l=o?c.colStart:c.rowStart;if(l<s){let e=b(t,o?i:l,o?l:a);if(e)return e}let u=o?t.getRange({rowStart:i,rowEnd:i,colStart:0,colEnd:a-1}):t.getRange({rowStart:0,rowEnd:i-1,colStart:a,colEnd:a});for(let n of u.entries({features:[_.Contentful],axis:o?e.IRange.Axis.Column:e.IRange.Axis.Row,reverse:!0})){if(n.context.getType()!==e.ScalarType.String)continue;let r=n.context.getCoords();return b(t,r.rowIndex,r.colIndex)}return null}var y=e=>e?`${JSON.stringify(e.text)} (${e.address})`:null;function b(n,r,a){let o=n.getRange({rowStart:r,rowEnd:r,colStart:a,colEnd:a}).getCell();if(o.getType()!==e.ScalarType.String)return null;let s=i(o,t.Mode.Display)?.match;return s?{text:s,address:o.getAddress()}:null}function x(e){let t=e,n=``;do n=String.fromCharCode(65+t%26)+n,t=Math.floor(t/26)-1;while(t>=0);return n}var S=e.ICellRange.Feature;function C(e,n){let r=n?.maxSeries??24,a=n?.maxProfileCells??2e4,o=n?.maxCategories??3,s=e.getRowCount(),c=e.getColumnCount();if(s===1&&c===1)return{shape:`cell`,summary:i(e.getCell(),t.Mode.Display)?.display??`(blank)`,series:[]};let l=e.getRange(),u=l.getCoords(),d=s>=c;if(s===1||c===1)return{shape:`list`,summary:ce(l,o),series:[]};let f=ee(e,d),p=d?c:s,m=d?null:`by row`,h=f.present&&f.inside,g=d&&h?u.rowStart+1:u.rowStart,_=!d&&h?u.colStart+1:u.colStart,v=re(l,d,d?g:_,a),y=d&&v?v.start-1:u.rowEnd,b=!d&&v?v.start-1:u.colEnd,x=y-g+1,S=b-_+1,C=x*S>a,te=C&&d?Math.max(1,Math.floor(a/Math.max(1,S))):x,ne=C&&!d?Math.max(1,Math.floor(a/Math.max(1,x))):S,ie=Math.min(y,g+te-1),ae=Math.min(b,_+ne-1),w=Math.min(p,r),T=[],oe=[];for(let t=0;t<w;t++){let n=d?l.getRangeAt(g,u.colStart+t,ie,u.colStart+t):l.getRangeAt(u.rowStart+t,_,u.rowStart+t,ae);T.push(se(e,d,t,f.names)),oe.push(ce(n,o))}let le=T.length?Math.max(...T.map(e=>e.length)):0,E=T.map((e,t)=>`${e.padEnd(le)} ${oe[t]}`);p>w&&E.push(`…${p-w} more ${d?`columns`:`rows`} not profiled · read them with getStats()`);let D=[m,f.note,v?.note];return C&&D.push(`profiled from the first ${d?`${te} rows`:`${ne} columns`} of ${d?x:S}`),{shape:f.present?`table`:`block`,summary:D.filter(Boolean).join(` · `),series:E}}function ee(e,t){let n=e.getRange(),r=n.getCoords(),i=e.getCell().getTable();if(i){let e=i.getColumns().map(e=>e.getName()),n=i.getRange().getCoords();return{present:!0,inside:!0,note:`${n.rowStart===r.rowStart&&n.rowEnd===r.rowEnd&&n.colStart===r.colStart&&n.colEnd===r.colEnd?``:`part of `}table ${i.getName()}`,names:t?e:null}}let a=t?r.rowStart+1:r.colStart+1,o=T(t?n.getRangeAt(a,r.colStart,r.rowEnd,r.colEnd):n.getRangeAt(r.rowStart,a,r.rowEnd,r.colEnd)),s=t?n.getRangeAt(r.rowStart,r.colStart,r.rowStart,r.colEnd):n.getRangeAt(r.rowStart,r.colStart,r.rowEnd,r.colStart);if(T(s)&&!o)return{present:!0,inside:!0,note:`header `+(t?`row ${r.rowStart+1}`:`column ${x(r.colStart)}`),names:oe(s,e,t)};let c=(t?r.rowStart:r.colStart)-1;if(c>=0&&!T(n)){let i=t?n.getRangeAt(c,r.colStart,c,r.colEnd):n.getRangeAt(r.rowStart,c,r.rowEnd,c);if(T(i))return{present:!0,inside:!1,note:`header ${t?`row ${c+1}`:`column ${x(c)}`} (above this block)`,names:oe(i,e,t)}}return{present:!1,inside:!1,note:`no header detected`,names:null}}var te=3;function ne(e,t=2e4){let n=e.getRowCount(),r=e.getColumnCount();if(n<2||r<2)return null;let i=n>=r,a=e.getCoords(),o=ee({getRowCount:()=>n,getColumnCount:()=>r,getCell:()=>e.getCell(),getRange:()=>e},i),s=o.present&&o.inside;return re(e,i,(i?a.rowStart:a.colStart)+ +!!s,t)}function re(e,t,n,r){let i=e.getCoords(),a=t?i.rowEnd:i.colEnd,o=t?i.colStart:i.rowStart,s=t?i.colEnd:i.rowEnd,c,l=-1,u=e.getCell().getTable(),d=t&&!!u?.isShowTotals()&&u.getRange().getCoords().rowEnd===i.rowEnd;if(d)l=a;else{if(e.getRowCount()*e.getColumnCount()>r)return null;let u=e.getValues(),d=(e,n)=>t?u[e-i.rowStart][n-i.colStart]:u[n-i.rowStart][e-i.colStart],f=s-o+1,p=Array(f).fill(0),m=Array(f).fill(!1);for(let r=n;r<=a;r++){if(r-n>=2){let n=ie(f,e=>d(r,o+e),p,m,e=>t?`${x(o+e)}${r+1}`:`${x(r)}${o+e+1}`);if(n.matches>=2&&2*n.matches>n.candidates){let i=t?e.getRangeAt(r,o,r,s):e.getRangeAt(o,r,s,r);l=r,c={...n,byColumn:t,typed:(i.getCounts([S.Formula])[S.Formula]??0)===0};break}}for(let e=0;e<f;e++){let t=d(r,o+e);typeof t==`number`&&(p[e]+=t,m[e]=!0)}}if(l<0)return null}let f=e.getSheet(),p=[];for(let n=l;n<=a;n++){let r=t?{rowIndex:n,colIndex:i.colStart}:{rowIndex:i.rowStart,colIndex:n},a=w(e,r)??v(f,r,t?`row`:`column`);p.push({index:n,label:a,...n===l&&c?{sums:c}:{}})}let m=e=>t?String(e+1):x(e),h=l===a?`${t?`row`:`column`} ${m(l)}`:`${t?`rows`:`columns`} ${m(l)}:${m(a)}`,g=p.slice(0,te).map(e=>[m(e.index),e.label?JSON.stringify(e.label.text):null,e.sums?ae(e.sums):e.index===l&&d?`table totals`:null].filter(Boolean).join(` `)),_=p.length-g.length;return{byColumn:t,start:l,lines:p,note:`${h} not profiled: ${g.join(` · `)}${_>0?` · +${_} more`:``}`}}function ie(e,t,r,i,a){let o=0,s=0,c=[];for(let l=0;l<e;l++){if(!i[l])continue;s++;let e=t(l),u=r[l];typeof e==`number`&&Math.abs(e-u)<=1e-9*Math.max(1,Math.abs(u))?o++:typeof e==`number`?c.push(`${a(l)} ${n(e)} ≠ Σ ${n(u)}`):c.push(`${a(l)} ${e==null?`blank`:typeof e==`string`?`text`:String(e)}`)}return{matches:o,candidates:s,misses:c}}function ae(e){let t=e.misses.slice(0,3),n=e.misses.length-t.length,r=t.length>0?`; ${t.join(`, `)}${n>0?`, +${n} more`:``}`:``;return`${e.typed?`typed, `:``}= Σ ${e.byColumn?`above`:`to the left`} (${e.matches} of ${e.candidates}${r})`}function w(n,r){let a=n.getRangeAt(r.rowIndex,r.colIndex).getCell();if(a.getType()!==e.ScalarType.String)return null;let o=i(a,t.Mode.Display)?.match;return o?{text:o,address:a.getAddress()}:null}function T(t){let n=t.getStats({onError:`ignore`}),r=n.getCount();return r>0&&(n.getTypedCounts()[e.ScalarType.String]??0)===r}function oe(e,n,r){let a=n.getRange().getCoords(),o=e.getCoords(),s=r?a.colEnd-a.colStart+1:a.rowEnd-a.rowStart+1,c=[];for(let n=0;n<s;n++){let s=r?e.getRangeAt(o.rowStart,a.colStart+n).getCell():e.getRangeAt(a.rowStart+n,o.colStart).getCell();c.push(i(s,t.Mode.Display)?.match??``)}return c}function se(e,t,n,r){let i=e.getRange().getCoords(),a=t?x(i.colStart+n):String(i.rowStart+n+1),o=r?.[n];return o?`${a} ${o}`:a}function ce(t,n=3){let r=t.getStats({onError:`ignore`}),i=r.getTypedCounts(),a=r.getCount(),o=r.getSize(),s=o-a;if(a===0)return`${o} cells, all blank`;let c=t.getCounts([S.Formula])[S.Formula]??0,l=E(t),u=i[e.ScalarType.Number]??0,d=i[e.ScalarType.String]??0,f=i[e.ScalarType.Error]??0,p=[String(a)],m=!1;if(c===a){let e=[...t.getRegions(S.Formula)];if(e.length===1){let t=e[0].getCell().getFormulaText();p.push(`formula`,t||`(uniform)`)}else p.push(`formula`,`${e.length} distinct`)}else if(l===a)p.push(`date`,ue(r,D(t).format));else if(u===a){let e=D(t);p.push(`number`,ue(r,e.format),...de(r,e))}else if(d===a)p.push(`text`,fe(r,n));else{let t=[u?`number ${u}`:null,d?`text ${d}`:null,i[e.ScalarType.Boolean]?`boolean ${i[e.ScalarType.Boolean]}`:null,f?`error ${f}`:null].filter(Boolean);p.push(`mixed`,t.join(` · `)),m=!0}let h=[f>0&&!m?`error ${f}`:null,s>0?`${s} blank`:null,c>0&&c!==a?`${c} formula`:null].filter(Boolean),g=p.filter(Boolean).join(` `);return h.length?`${g} · ${h.join(` · `)}`:g}function le(t,n=3){let r=t.getStats({onError:`ignore`}),i=r.getTypedCounts(),a=[],o=i[e.ScalarType.Number]??0;if(o>0){let e=D(t),n=[ue(r,e.format),...de(r,e)].filter(Boolean);a.push(`Number: ${o} ${n.join(` `)}`.trimEnd())}let s=i[e.ScalarType.String]??0;if(s>0){let e=fe(r,n,e=>typeof e==`string`);a.push(`String: ${s} ${e}`.trimEnd())}let c=i[e.ScalarType.Boolean]??0;if(c>0){let e=fe(r,n,e=>typeof e==`boolean`);a.push(`Boolean: ${c} ${e}`.trimEnd())}return a}function E(t){let n=0;return t.forEach((t,r)=>{r.getInteropType()===e.InteropScalarType.Date&&n++}),n}function D(t){let n=t=>t.getStats({onError:`ignore`}).getTypedCounts()[e.ScalarType.Number]??0,r=new Map,i=0;for(let e of t.getRegions(S.NumberFormat)){let t=e.getRange().getStyle().getNumberFormat(),a=n(e.getRange());i+=a,t&&a>0&&r.set(t,(r.get(t)??0)+a)}let a=n(t)-i;a>0&&r.set(`General`,(r.get(`General`)??0)+a);let o=[...r].sort((e,t)=>t[1]-e[1]||Number(t[0]===`General`)-Number(e[0]===`General`));if(o.length===0)return{format:null,mixed:null};let s=e.NumberFormat.getEngine(),c=e=>{if(e===`General`)return`1`;let t=s.getFormatInfo(e);return t?`${t.isDate?`date`:t.scale}`:`1`},l=o[0][0];return o.every(([e])=>c(e)===c(l))?{format:l===`General`?null:l,mixed:null}:{format:null,mixed:o.map(([e,t])=>`${e} ${t}`).join(` · `)}}function ue(e,t){let n=e.getAggregates({onError:`ignore`});if(n.min===null||n.max===null)return``;let i=r(n.min,t),a=r(n.max,t);return i===a?i:`${i} … ${a}`}function de(e,{format:t,mixed:n}){if(n)return[`mixed formats (${n})`];let i=e.getAggregates({onError:`ignore`}),a=[];return i.sum!==null&&a.push(`Σ ${r(i.sum,t)}`),i.average!==null&&a.push(`x̄ ${r(i.average,t)}`),a}function fe(e,t,n){let r=e.getFrequencies(n?{filterFn:n}:void 0),i=r.getUniqueCount();if(i===0)return``;if(i===r.getTotalCount())return`${i} distinct, no repeats`;let a=Array.from(r.getValueCounts()).slice(0,t);return`${i} unique (${a.map(([e,t])=>`${e} ${t}`).join(` · `)}${i>a.length?` · …`:``})`}var O=e.ICellRange.Feature,pe=e=>(e.rowEnd-e.rowStart+1)*(e.colEnd-e.colStart+1),me=(e,t)=>{let n=Math.min(e.rowEnd,t.rowEnd)-Math.max(e.rowStart,t.rowStart)+1;if(n<=0)return 0;let r=Math.min(e.colEnd,t.colEnd)-Math.max(e.colStart,t.colStart)+1;return r<=0?0:n*r},he=e=>e.toLocaleString(`en-US`),ge=(e,t)=>{let n=`×${he(e.content)}`;return t===`times`||e.styled===e.content?n:`${n} (+${he(e.styled-e.content)} blank)`},_e=t=>{if(t.length===0)return``;let n=e.AddressUtils.rangeToString(t[0]);if(t.length===1)return n;let r=t.length-1;return`${n}, +${r} block${r===1?``:`s`}`};function k(e,t){let n=t?.manyDistinct??20,{sorted:r,top:i,rare:a,more:o}=ve(e,t);if(r.length===0)return``;let s=e=>((e,t)=>{let n=_e(e.blocks);return`${e.label===t?.hideLabel?``:`${e.label} `}${ge(e,t?.countStyle??`cells`)}${n?` ${n}`:``}`})(e,t);if(o===0)return r.map(s).join(` · `);let c=r.reduce((e,t)=>e+t.content,0),l=c>0?r[0].content/c:0,u=[],d=r.length>n?`${r.length} distinct${l<.5?`, no convention`:``}; largest `:``;return u.push(d+i.map(s).join(` · `)),a.length>0&&u.push(`rarest ${a.map(s).join(` · `)}`),u.push(`+${o} more${t?.recovery?` (${t.recovery})`:``}`),u.join(` · `)}function ve(e,t){let n=t?.maxValues??8,r=[...e].sort((e,t)=>t.content-e.content||t.styled-e.styled||(e.label<t.label?-1:1));if(r.length<=n)return{sorted:r,top:r,rare:[],more:0};let i=Math.max(1,Math.floor(n/2)),a=r.slice(0,i),o=[];for(let e=r.length-1;e>=i&&o.length<n-i;e--)r[e].content>0&&o.push(r[e]);return o.reverse(),{sorted:r,top:a,rare:o,more:r.length-a.length-o.length}}var ye=[{name:`family`,project:(e,t)=>A(e.getFont().getFamily(),t?.getFont().getFamily())},{name:`size`,project:(e,t)=>A(e.getFont().getSize(),t?.getFont().getSize(),e=>`${e}pt`)},{name:`bold`,project:(e,t)=>A(e.getFont().getBold(),t?.getFont().getBold()??!1,e=>e?`bold`:`not bold`)},{name:`italic`,project:(e,t)=>A(e.getFont().getItalic(),t?.getFont().getItalic()??!1,e=>e?`italic`:`not italic`)},{name:`underline`,project:(e,t)=>A(e.getFont().getUnderline(),t?.getFont().getUnderline(),e=>String(e))},{name:`strike`,project:(e,t)=>A(e.getFont().getStrike(),t?.getFont().getStrike()??!1,e=>e?`strike`:`not strike`)},{name:`color`,project:(e,t)=>A(l(e.getFont().getColor()),t?l(t.getFont().getColor()):null)}],be=e=>De(e)??`Custom`,xe={name:`category`,project:e=>{let t=m(e);return t===null?null:be(t)}},Se={name:`format`,project:e=>m(e)},Ce=[xe,Se],we=[{name:`color`,project:e=>u(e)}],Te=[{name:`edges`,project:e=>d(e)}],Ee=[{name:`h`,ambiguous:!0,project:(e,t)=>A(e.getAlignment().getHorizontal(),t?.getAlignment().getHorizontal())},{name:`v`,ambiguous:!0,project:(e,t)=>A(e.getAlignment().getVertical(),t?.getAlignment().getVertical())},{name:`overflow`,project:(e,t)=>A(e.getAlignment().getOverflow(),t?.getAlignment().getOverflow())},{name:`indent`,project:(e,t)=>A(e.getAlignment().getIndent(),t?.getAlignment().getIndent()??0,e=>`indent ${e}`)},{name:`rotation`,project:(e,t)=>A(e.getAlignment().getRotation(),t?.getAlignment().getRotation()??0,e=>`rotation ${e}`)}];function A(e,t,n=String){return e==null||t!==void 0&&e===t?null:n(e)}function De(t){if(!t||t===`General`)return null;let n=e.NumberFormat.Builder.parse(t);if(n.category===`General`)return null;let r=n.decimalPlaces;return r==null?n.category:`${n.category} ${r}dp`}var Oe={[O.Font]:ye,[O.NumberFormat]:Ce,[O.Fill]:we,[O.Borders]:Te,[O.Alignment]:Ee},ke=e=>e in Oe;function Ae(e,t,n,r){let i=Oe[t];if(!i)return null;let a=e.getEntireCoords(),o=e.getUsedRange()?.getCoords()??null,s=[...e.getEntireRange().getRegions(t)];if(s.length===0)return null;let c=r?.content??(o?[...e.getEntireRange().getRegions(O.Contentful)].map(e=>e.getCoords()):[]),l=e=>c.reduce((t,n)=>t+me(e,n),0),u=e=>o?me(e,o):0,d=e=>{let t=e.getRange().getStyle(),r=[];for(let e of i){let i=e.project(t,n);i!==null&&r.push(e.ambiguous?`${e.name} ${i}`:i)}return r.join(` · `)},f=new Set,p=new Map;for(let e of s)p.set(e,e.getRange().getStyle()),f.add(d(e));let m=a.rowEnd-a.rowStart+1,h=a.colEnd-a.colStart+1,g=[],_=[],v=[];for(let e of s){let t=e.getCoords();2*(t.rowEnd-t.rowStart+1)>m?g.push(e):2*(t.colEnd-t.colStart+1)>h?_.push(e):v.push(e)}let y=[];y.push(...Le(`columns`,g,d,a,!0)),y.push(...Le(`rows`,_,d,a,!1));let b=v.reduce((e,t)=>e+u(t.getCoords()),0),x=e=>{let t=[];for(let r of v){let i=e.project(p.get(r),n);i!==null&&t.push({...r.getCoords(),key:i,label:i})}let r=new Map;for(let e of function(e){let t=[...e];if(t.length<=1)return t;let n=!0,r=0;for(;r<2;){let e=n;t.sort((t,n)=>t.key<n.key?-1:t.key>n.key?1:e?t.rowStart-n.rowStart||t.rowEnd-n.rowEnd||t.colStart-n.colStart:t.colStart-n.colStart||t.colEnd-n.colEnd||t.rowStart-n.rowStart);let i=[],a=!1;for(let n of t){let t=i[i.length-1];t&&t.key===n.key&&(e?t.rowStart===n.rowStart&&t.rowEnd===n.rowEnd&&t.colEnd+1===n.colStart:t.colStart===n.colStart&&t.colEnd===n.colEnd&&t.rowEnd+1===n.rowStart)?(i[i.length-1]={...t,colEnd:e?n.colEnd:t.colEnd,rowEnd:e?t.rowEnd:n.rowEnd},a=!0):i.push(n)}t=i,r=a?0:r+1,n=!n}return t}(t)){let t=r.get(e.key)??{label:e.label,content:0,styled:0,blocks:[]};t.content+=l(e),t.styled+=u(e),t.blocks.push(e),r.set(e.key,t)}return[...r.values()].map(e=>({...e,blocks:e.blocks.sort((e,t)=>pe(t)-pe(e))}))},S=[];if(t===O.NumberFormat)S.push(...function(e,t,n){let{top:r,rare:i,more:a}=ve(e,n),o=[],s=-1;for(let e of[...r,...i]){e===i[0]&&(s=o.length);let n=ve(t.filter(t=>be(t.label)===e.label),{maxValues:1/0}).sorted,r=n.length===1;if(o.push([e.label,ge(e,`cells`),_e(e.blocks),r?n[0].label:`${n.length} formats`]),!r){for(let e of n.slice(0,Ie))o.push([``,ge(e,`cells`),_e(e.blocks),e.label]);n.length>Ie&&o.push([``,``,``,`…and ${n.length-Ie} more`])}}let c=[0,1,2].map(e=>Math.max(...o.map(t=>t[e].length))),l=o.map(e=>`${e[0].padEnd(c[0])} ${e[1].padEnd(c[1])} ${e[2].padEnd(c[2])} ${e[3]}`.trimEnd());return a>0&&l.splice(s<0?l.length:s,0,`…and ${a} more${n?.recovery?` · ${n.recovery}`:``}`),l}(x(xe),x(Se),r));else for(let e of i){let t=x(e);if(t.length===0)continue;let n=k(t,{...r,hideLabel:e.name});n.length<=Pe?S.push(`${e.name.padEnd(10)}${n}`):S.push(...Fe(e.name,t,r))}return{distinct:f.size,cells:b,normal:n?Ne(t,n):null,tiers:y,attributes:S}}function je(e,t){if(e.length===0)return null;let n=new Map,r=new Map,i=0;for(let t of e){let e=t.getRowCount()*t.getColumnCount(),a=t.getCell(),o=a.getFormulaText({r1c1:!0})??``,s=n.get(o)??{label:o,cells:0,blocks:[]};s.cells+=e,s.blocks.push(t.getCoords()),n.set(o,s);let c=new Set;for(let e of a.getFormula()?.getTokens()??[]){if(e.type!==`function`)continue;let t=String(e.value??e.text??``).toUpperCase();t&&c.add(t)}c.size===0&&(i+=e);for(let t of c)r.set(t,(r.get(t)??0)+e)}let a={...t,countStyle:`times`},o=[...n.values()].map(e=>({label:e.label,content:e.cells,styled:e.cells,blocks:e.blocks.sort((e,t)=>pe(t)-pe(e))})),s=[...r.entries()].map(([e,t])=>({label:e,content:t,styled:t,blocks:[]}));return i>0&&s.push({label:`no function`,content:i,styled:i,blocks:[]}),{distinct:n.size,lines:[`${`distinct`.padEnd(10)}${k(o,a)}`,`${`functions`.padEnd(10)}${k(s,a)}`]}}function Me(e,t){let n=e.getStats({onError:`ignore`}).getTypedCounts(),r=new Map,i=[[`number`,`number`],[`string`,`text`],[`boolean`,`boolean`],[`error`,`error`],[`richData`,`richData`]];for(let[e,t]of i){let i=n[e]??0;i>0&&r.set(t,i)}let a=E(e),o=0;for(let e of t){let t=e.getRange().getStats({onError:`ignore`}).getTypedCounts();o+=e.getRowCount()*e.getColumnCount();for(let[e,n]of i){let i=t[e]??0;i>0&&r.set(n,(r.get(n)??0)-i)}a>0&&(t.number??0)>0&&(a-=E(e.getRange()))}return a>0&&(r.set(`date`,a),r.set(`number`,(r.get(`number`)??0)-a)),o>0&&r.set(`formula`,o),[...r.entries()].filter(([,e])=>e>0).sort((e,t)=>t[1]-e[1])}function Ne(e,t){switch(e){case O.Font:return function(e){let t=e.getFont(),n=[t.getFamily(),`${t.getSize()}pt`],r=l(t.getColor());return r&&n.push(r),t.getBold()&&n.push(`bold`),t.getItalic()&&n.push(`italic`),n.join(` · `)}(t);case O.NumberFormat:{let e=m(t);return e===null?null:`${be(e)} ${e}`}case O.Fill:return u(t);case O.Borders:return d(t);case O.Alignment:{let e=t.getAlignment(),n=[];return e.getHorizontal()!==`general`&&n.push(`h ${e.getHorizontal()}`),e.getVertical()!==`bottom`&&n.push(`v ${e.getVertical()}`),e.getOverflow()!==`visible`&&n.push(String(e.getOverflow())),e.getIndent()&&n.push(`indent ${e.getIndent()}`),e.getRotation()&&n.push(`rotation ${e.getRotation()}`),n.length>0?n.join(` · `):null}default:return null}}var Pe=110;function Fe(e,t,n){let{sorted:r,top:i,rare:a,more:o}=ve(t,n),s=[...i,...a].map(e=>[ge(e,`cells`),_e(e.blocks),e.label]),c=[0,1].map(e=>Math.max(...s.map(t=>t[e].length))),l=s.map(e=>` ${e[0].padEnd(c[0])} ${e[1].padEnd(c[1])} ${e[2]}`);o>0&&l.splice(i.length,0,` …and ${o} more${n?.recovery?` · ${n.recovery}`:``}`);let u=n?.manyDistinct??20;return[r.length>u?`${e.padEnd(10)}${r.length} distinct`:e,...l]}var Ie=6;function Le(t,n,r,i,a){if(n.length===0)return[];let o=new Map;for(let e of n){let t=r(e),n=o.get(t);n?n.push(e):o.set(t,[e])}let s=a?i.colEnd-i.colStart+1:i.rowEnd-i.rowStart+1,c=[];for(let[n,r]of o){let i=0,o=r.map(t=>{let n=t.getCoords();i+=a?n.colEnd-n.colStart+1:n.rowEnd-n.rowStart+1;let r=a?e.AddressUtils.runToString(n.colStart,n.colEnd,!0):e.AddressUtils.runToString(n.rowStart,n.rowEnd,!1),o=a?n.rowStart:n.colStart;return o===0?r:`${r} (from ${a?`row ${o+1}`:`column ${e.AddressUtils.runToString(o,o,!0).split(`:`)[0]}`})`});2*i>s?c.push(`${`sheet`.padEnd(10)}${n||`default`}`):c.push(`${t.padEnd(10)}${o.join(`, `)} ${n||`default`}`)}return c}var Re=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,j=e=>{if(!e)return null;if(typeof e!=`string`)return l(e);let t=e.replace(/^#/,``);return/^[0-9a-f]{6}$/i.test(t)||/^[0-9a-f]{8}$/i.test(t)?`#${(t.length===8&&/^ff/i.test(t)?t.slice(2):t).toUpperCase()}`:e},ze=t=>{if(!t)return null;let n=[],r=(t=>{if(!t)return null;if(typeof t==`string`)return j(t);let n=t.type;if(n===e.IFill.Type.None)return null;if(n===e.IFill.Type.Gradient)return`gradient`;let r=t,i=j(r.foreground??t.color??r.background),a=r.patternType;return[a&&a!==e.IFill.BuiltInSheetPattern.Solid?`${a} pattern`:null,i].filter(Boolean).join(` `)||null})(t.fill);r&&n.push(`fill ${r}`);let i=t.font;if(i){let t=[];(i.weight===void 0?!0===i.bold:i.weight>=600)&&t.push(`bold`),(i.style===void 0?!0===i.italic:i.style===e.IFont.Style.Italic)&&t.push(`italic`),i.strike&&t.push(`strike`),i.underline&&i.underline!==e.IFont.UnderlineStyle.None&&t.push(`underline ${i.underline}`);let r=i.color===`auto`?null:j(i.color);r&&t.push(`text ${r}`),t.length>0&&n.push(t.join(` `))}if(t.numberFormat!==void 0&&t.numberFormat!==null){let r=typeof t.numberFormat==`number`?e.NumberFormat.resolve(t.numberFormat):String(t.numberFormat);r&&n.push(r)}return t.borders&&n.push(`border`),t.alignment&&n.push(`alignment`),n.length>0?n.join(` · `):null},Be=t=>{let n=t.type??e.IConditionalFormat.ColorStopType.Num,r=t.value,i=r==null||r===``?n:`${n} ${r}`,a=j(t.color);return a?`${i} ${a}`:i},Ve=t=>{let n=t.type;if(t.type===e.IConditionalFormat.ScaleType.DataBar){let e=j(t.color);e&&(n+=` ${e}`)}else t.type===e.IConditionalFormat.ScaleType.IconSet&&(t.iconSet&&(n+=` ${t.iconSet}`),t.reverse&&(n+=` reversed`),t.icon?.length&&(n+=` custom icons`));let r=(t.stops??[]).map(Be).join(` → `);return r?`${n} · ${r}`:n},He=`(no rule)`,Ue=e=>{let t=e.getScale(),n=[];if(t)n.push(Ve(t));else{n.push(e.getCondition()?.toString()||He);let t=ze(e.getStyle());t&&n.push(`→ ${t}`)}return e.isStopIfTrue()&&n.push(`· stop if true`),Re(n.join(` `),90)},We=e=>{let t=[e.getCondition()?.toString()||He],n=e.getAlertStyle();return n&&t.push(n),e.isIncludeBlanks()&&t.push(`blanks allowed`),e.isHideDropdown()&&t.push(`no dropdown`),Re(t.join(` · `),90)},Ge=t=>{if(t?.getOperator()?.getName()!==e.ICondition.BuiltInOperatorNames.InSet)return null;let n=t.getParam()?.items;if(!n)return null;if(typeof n==`string`)return n;let r=n.slice(0,20).map(e=>a(e)?.match??``),i=n.length-r.length;return i>0?`${r.join(`, `)}, +${i} more`:r.join(`, `)},Ke=(e,t)=>{if(e.length===0)return null;let n=e.slice(0,3).map(t),r=e.length-n.length;return r>0?`${n.join(` | `)} | +${r} more`:n.join(` | `)},M=e.ICellRange.Feature,N=e=>e.getRange().getStyle(),qe=e=>i(e.getCell(),t.Mode.Display)?.display??null;function Je(e,t){switch(e){case M.Formula:return e=>e.getCell().getFormulaText();case M.Error:return qe;case M.CalcError:return e=>{let t=qe(e)??``,n=e.getCell().getFormulaText();return(n?`${t} ${n}`:t).trim()||null};case M.Merge:return qe;case M.Comments:return e=>{let t=e.getCell().getComments()?.getContent();if(typeof t!=`string`)return null;let n=t.replace(/\s+/g,` `).trim();return n?n.length>60?`${n.slice(0,59)}…`:n:null};case M.Spills:return e=>e.getCell().getSpill()?.getValuesRange().toString()??null;case M.Hyperlink:return e=>e.getCell().getHyperlink()?.getAddress()??null;case M.Table:return e=>e.getCell().getTable()?.getName()??null;case M.Fill:return e=>u(N(e));case M.Borders:return e=>d(N(e));case M.NumberFormat:return e=>m(N(e));case M.Alignment:return t?e=>h(N(e),t):void 0;case M.Font:return t?e=>g(N(e),t):void 0;case M.Protection:return e=>{let t=N(e).getProtection(),n=[];return t.isAlwaysUnlocked()&&n.push(`always unlocked`),t.isShowFormulas()||n.push(`formulas hidden`),n.join(`, `)||null};case M.Unlock:return e=>{let t=[];e.getCell().getProtection().isAlwaysUnlocked()&&t.push(`always unlocked`);let n=e.getRange();for(let e of n.getSheet().getProtectedRanges().getItems({address:n}))t.push(`range ${e.getName()}${e.isUnlocked()?``:` · password`}`);return t.join(`, `)||null};case M.Conditionals:return e=>Ke(e.getRange().getConditionalFormats(),Ue);case M.DataValidations:return e=>Ke(e.getRange().getDataValidations(),We);case M.Contentful:return e=>le(e.getRange()).join(` `)||null;default:return}}function Ye(e,t){let n=e.map(e=>Je(e,t)).filter(e=>!!e);if(n.length!==0)return n.length===1?n[0]:e=>{let t=n.map(t=>t(e)).filter(Boolean);return t.length>0?t.join(` `):null}}var P=class{constructor(){this._lines=[],this._headingOffset=0}setHeadingOffset(e){return this._headingOffset=e,this}_heading(e,t){return this._lines.push(`${`#`.repeat(Math.min(6,e+this._headingOffset))} ${t}`),this}h1(e){return this._heading(1,e)}h2(e){return this._heading(2,e)}h3(e){return this._heading(3,e)}text(e){return this._lines.push(e),this}blank(){return this._lines.push(``),this}bullet(e){return typeof e==`string`?this._lines.push(`- ${e}`):e.forEach(e=>this._lines.push(`- ${e}`)),this}fact(e){return typeof e==`string`?this._lines.push(` ${e}`):e.forEach(e=>this._lines.push(` ${e}`)),this}bold(e){return`**${e}**`}codespan(e){return`\`${e}\``}code(e,t=``){return`\`\`\`${t}\n${e}\n\`\`\``}beginFrame(e){return new Xe(this,e)}_addLines(e){this._lines.push(...e)}toLines(){return[...this._lines]}},Xe=class{constructor(e,t){this._parent=e,this._headers=t,this._indexWidth=0,this._rows=[],this._colWidths=t.map(e=>e.length)}addRow(e,t){let n=e.map(e=>typeof e==`string`?{text:e}:e);return n.forEach((e,t)=>{this._colWidths[t]=Math.max(this._colWidths[t]??0,e.text.length)}),t!==void 0&&(this._indexWidth=Math.max(this._indexWidth,t.length)),this._rows.push({index:t,cells:n}),this}endFrame(){return this._parent._addLines(this._renderLines()),this._parent}_columnAlignment(e){let t=0,n=0;for(let r of this._rows){let i=r.cells[e];i&&i.text&&(n++,i.alignment===`right`&&t++)}return n>0&&2*t>=n?`right`:void 0}_renderLines(){let e=this._indexWidth>0?` `.repeat(this._indexWidth):``,t=this._colWidths.map((e,t)=>this._columnAlignment(t)),n=[];if(this._headers.some(e=>e.length>0)){let r=this._headers.map((e,n)=>Ze(e,this._colWidths[n],t[n])).join(` `);n.push(`${e}${e?` `:``}${r}`.trimEnd())}for(let e of this._rows){let t=e.cells.map((e,t)=>Ze(e.text,this._colWidths[t],e.alignment)).join(` `),r=this._indexWidth>0?(e.index??``).padStart(this._indexWidth)+` `:``;n.push(`${r}${t}`.trimEnd())}return n}},Ze=(e,t,n)=>{if(e.length>=t)return e;let r=t-e.length;return n===`right`?e.padStart(t):n===`center`?` `.repeat(Math.floor(r/2))+e+` `.repeat(Math.ceil(r/2)):e.padEnd(t)};function Qe(e,t,n){let r=c(t.length,n?.maxRegions??200),i=t.length>r?t.slice(0,r):t,a=i.length<t.length;if(i.length===0)return void e.text(`None`);let o=i.map(e=>e.toString()),s=Math.max(...o.map(e=>e.length)),l=i.map(e=>`${e.getRowCount()}×${e.getColumnCount()}`),u=Math.max(...l.map(e=>e.length)),d=n?.profile?n?.maxProfiled??12:0;for(let t=0;t<i.length;t++){let r=i[t],a=n?.payload?.(r),c=r.isClipped()?` ✂ clipped at the query edge — the block continues`:``,f=` ${o[t].padEnd(s)} ${l[t].padEnd(u)}`;if(t<d){let t=C(r,n);if(e.text(`${f} ${t.summary}${c}`),!1===n?.series)continue;for(let n of t.series)e.text(` ${n}`);continue}e.text(a?`${f} ${a}${c}`:`${f}${c}`.trimEnd())}if(d>0&&i.length>d&&e.text(` …${i.length-d} more regions listed but not profiled · profile one with getRange().getStats(), or loop them in code`),a){let i=n?.recovery??`narrow the range, or loop the regions in code — this listing is a report, not the query`;e.text(` …truncated at ${r} of ${t.length} regions · ${i}`)}}function $e(t,n){let r=[...t],i=t.getFeatures(),a=i.join(`, `),o=i.length===1&&i[0]===e.ICellRange.Feature.Contentful,s=t.getRange().getSheet().getWorkbook()?.getStyles().getNormal()??null,c=new P;return c.h1(`Regions — ${a} (${r.length})`),Qe(c,r,{...n,profile:o,payload:o?void 0:Ye(i,s)}),c.toLines().join(`
|
|
2
|
-
`).trimEnd()}function
|
|
3
|
-
`).trimEnd()}var F=e.ICellRange.Feature,rt=[F.Error,F.CalcError,F.Contentful,F.Formula,F.Spills,F.Merge,F.AutoTable,F.Hyperlink,F.Comments,F.NumberFormat,F.Font,F.Fill,F.Borders,F.Alignment,F.Conditionals,F.DataValidations],it=new Map(Object.entries(F).map(([e,t])=>[t,e])),at=e=>it.get(e)??e;function ot(e){let t=new Map(Object.values(F).map(e=>[e.toLowerCase(),e])),n=[];for(let r of e.split(`,`)){let e=r.trim();if(!e)continue;let i=t.get(e.toLowerCase());if(!i)throw Error(`Unknown feature '${e}'. Features: ${Object.values(F).join(`, `)}.`);n.push(i)}return n}var I=e=>`${e.toString()}, ${e.getRowCount()}×${e.getColumnCount()}`,L=t=>e.AddressUtils.sheetNameToString(t)??`Untitled`,R=e=>`wb.getSheet(${JSON.stringify(e.getSheet().getName())})`,st=e=>(e=>{if(!e.includes(`$`))return e;let t=``,n=!1;for(let r of e){if(r===`'`)n=!n;else if(r===`$`&&!n)continue;t+=r}return t})(e.getAddress()),ct=e=>{let t=st(e);return t.includes(`!`)?t:`${L(e.getSheet().getName())}!${t}`},lt=e=>{let t=e.toString();return`${t.includes(`!`)?t:`${L(e.getSheet().getName())}!${t}`}, ${e.getRowCount()}×${e.getColumnCount()}`};function ut(e,t){let n=Me(t,[...t.getRegions(F.Formula)]),r=t.getStats({onError:`ignore`}).getCount();e.h2(`Kind (${r} cell${r===1?``:`s`} · ${n.length} kind${n.length===1?``:`s`})`);for(let[t,r]of n)e.text(` ${t.padEnd(10)}${r}`);n.length===0&&e.fact(`None`),e.blank()}function dt(e,t,n){let r=t.getSheet().getWorkbook()?.getStyles().getNormal()??null,i=n?.features===void 0?null:new Set(typeof n.features==`string`?[n.features]:n.features),a=rt.filter(e=>!i||i.has(e));if(a.length===0)return;let o=t.getCounts(a),s,c=()=>s??=[...t.getSheet().getEntireRange().getRegions(F.Contentful)].map(e=>e.getCoords());for(let i of a){let a=i===F.Contentful?ft(t):[...t.getRegions(i)];if(a.length===0){let t=r&&i!==F.Font?Ne(i,r):null;t&&(e.h2(`${at(i)} (${pt(0,0)})`),e.text(` ${`normal`.padEnd(10)}${t}`),e.blank());continue}let s=!!n?.profile&&i===F.Contentful,l=`${R(t)}.getRegions(${JSON.stringify(i)})`,u=`${l} lists all ${a.length}`,d=ke(i)?Ae(t.getSheet(),i,r,{recovery:u,content:c()}):null,f=i===F.Formula?je(a,{recovery:u}):null,p=d?`${pt(a.length,d.cells)} · ${d.distinct} distinct`:f?`${pt(a.length,o[i])} · ${f.distinct} distinct`:pt(a.length,o[i]);if(e.h2(`${at(i)} (${p})`),d){d.normal&&e.text(` ${`normal`.padEnd(10)}${d.normal}`);for(let t of d.tiers)e.text(` ${t}`);for(let t of d.attributes)e.text(` ${t}`);e.text(` ${`regions`.padEnd(10)}${l}`),e.blank()}else{if(f)for(let t of f.lines)e.text(` ${t}`);i===F.Contentful&&a.sort((e,t)=>t.getRowCount()*t.getColumnCount()-e.getRowCount()*e.getColumnCount()),Qe(e,a,{maxRegions:n?.maxRegions,maxProfiled:n?.maxProfiled,profile:s,series:!1,payload:s?void 0:Je(i,r),recovery:u}),e.blank()}}}var ft=e=>[...e.getRegions([F.Contentful,F.Table])].filter(e=>e.getCell().isContentful()),pt=(e,t)=>`${t} cell${t===1?``:`s`} · ${e} region${e===1?``:`s`}`,mt=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,ht=e=>e.isIFormula?e:null,gt=e=>{let t=e.getScope();return t?`${L(t)}!${e.getName()}`:e.getName()},_t=e=>{let t=e.getAddress();return t.includes(`!`)?t:`${L(e.getSheet().getName())}!${t}`};async function vt(e){let t=ht(e),n;return n=t?`=`+t.getExpression():e.getRanges?.()?.getAddress()??``,t&&await t.isVolatile()&&(n+=` (volatile)`),n.trim()}var yt=new Set([e.FormulaError.Code.Ref,e.FormulaError.Code.Name]),bt=t=>{let n=t.value,r=typeof n==`string`?n:n?.error,i=typeof r==`string`?e.FormulaError.getBuiltInByLabel(r):void 0;return i&&yt.has(i.getCode())?i.getCode()===e.FormulaError.Code.Name?`#NAME?`:`#REF!`:null},xt=new Set,St=e=>{let t=e.value;return typeof t==`object`&&t?.name?t.name:e.text??``};function Ct(e){let t=null;for(let n=0;n<e.length;n++){let r=e[n];if(r.type!==`named`||!r.context)continue;let i=r.context.name?.toUpperCase();if(i!==`LAMBDA`&&(i!==`LET`||r.context.argIndex%2!=0))continue;let a=n+1;for(;a<e.length&&e[a].type===`whitespace`;)a++;if(e[a]?.type!==`separator`)continue;let o=St(r).toLowerCase();o&&(t??=new Set).add(o)}return t??xt}async function z(e,t,n){if(t.length===0)return;let r=new Set;for(let e of n?.symbols??t)r.add(e.getName().toLowerCase());let i=new Map,a=new Set;for(let e of t)i.set(e.getId(),e),e.getScope()&&a.add(e.getName().toLowerCase());let o=await Promise.all(t.map(async e=>{let t=function(e,t){let n=ht(e),r=[];if(n){let e=n.getTokens(),i=null,a=null;for(let n of e){if(n.type===`error`){a??=bt(n);continue}if(n.type!==`named`)continue;let o=St(n);o&&!t.has(o.toLowerCase())&&(i??=Ct(e),i.has(o.toLowerCase())||r.includes(o)||r.push(o))}if(a||r.length>0)return{broken:!0,missing:r,error:r.length>0?`#NAME?: ${r.join(`, `)}`:a};if(!n.isReferenceOnly())return{broken:!1,missing:r,error:``}}let i=null;try{i=e.getRanges?.()??null}catch{return{broken:!0,missing:r,error:`#REF!`}}let a=!i||i.isInvalidAny();return{broken:a,missing:r,error:a?`#REF!`:``}}(e,r),n=ht(e),o=n?await async function(e,t){let n=await e.getDirectDependents(),r=0,i=[],a=new Set,o=[];if(n){let e=n.getCoords(),s=n.getCount();for(let c=0;c<s;c++){let s=n.at(c);if(s.isINamedRange){let e=s;if(a.has(e.getId()))continue;a.add(e.getId());let n=t.get(e.getId());i.push(n?gt(n):e.getName())}else{let t=e[c];r+=(t.rowEnd-t.rowStart+1)*(t.colEnd-t.colStart+1),o.push(_t(s))}}}let s=r+i.length;if(s===0)return{text:`unused`,weight:s};let c=[...i,...o],l=[],u=0;for(let e=0;e<c.length;e++){let t=(l.length>0?2:0)+c[e].length;if(l.length>0&&u+t>60)break;l.push(l.length===0?mt(c[e],60):c[e]),u+=t}let d=c.length-l.length,f=d>0?`, +${d} more`:``;return{text:`${s} · ${l.join(`, `)}${f}`,weight:s}}(n,i):null;o?.weight===0&&!e.getScope()&&a.has(e.getName().toLowerCase())&&(o={...o,text:`unused · shadowed`});let s=e.getComment()??``,c=gt(e);return{name:c,refersTo:await vt(e),dependents:o,hidden:e.isHidden(),comment:mt(s,60),broken:t.broken,error:t.error,sortKey:c.toLowerCase().replace(/'/g,``)}})),s=(e,t)=>{let n=(t.dependents?.weight??0)-(e.dependents?.weight??0);return n===0?e.sortKey.localeCompare(t.sortKey):n},l=[...o.filter(e=>e.broken).sort(s),...o.filter(e=>!e.broken).sort(s)],u=c(l.length,n?.maxNames??200),d=l.length>u?l.slice(0,u):l,f=d.filter(e=>e.broken),p=d.filter(e=>!e.broken);e.h2(`${n?.heading??`Names`} (${o.length})`);let m=(t,n)=>{let r=t.some(e=>e.hidden),i=t.some(e=>e.comment.length>0),a=t.some(e=>e.dependents!==null),o=[`Name`,`Refers To`];n&&o.push(`Error`),a&&o.push(`Dependents`),r&&o.push(`Hidden`),i&&o.push(`Comment`);let s=e.beginFrame(o);for(let e of t){let t=[{text:e.name},{text:e.refersTo}];n&&t.push({text:e.error}),a&&t.push({text:e.dependents?.text??``}),r&&t.push({text:e.hidden?`hidden`:``}),i&&t.push({text:e.comment}),s.addRow(t)}s.endFrame()};if(f.length>0){let t=l.reduce((e,t)=>e+ +!!t.broken,0);e.text(`${t} ${t===1?`does`:`do`} not resolve:`),m(f,!0),e.blank()}if(p.length>0&&m(p,!1),d.length<o.length){let t=n?.recovery??`getByName('Name') renders one in full`;e.text(` …and ${o.length-d.length} more · ${t}`)}e.blank()}function wt(e,t,n){let r=n.getCoords().min,i=[],a=0,o=0;if(n.forEachSpan((e,t)=>{let s=t.getCoords();if(o++,a+=s.max-s.min+1,i.length>=100)return;let c=n.at(s.min-r).getText(),l=n.at(s.max-r).getText();i.push({address:`${c}:${l}`,count:s.max-s.min+1})},{visibility:`hidden`,includeEmpty:!0}),a===0)return;e.h2(`${t} (${a})`);let s=Math.max(...i.map(e=>e.address.length));for(let t of i)e.text(` ${t.address.padEnd(s)} ${t.count}`);o>i.length&&e.text(` …and ${o-i.length} more`),e.blank()}function Tt(e,t,n,r){if(n.length===0)return;let i=n.length>50?n.slice(0,50):n,a=i.map(e=>({address:mt(st(e.getRanges()),40),rule:r(e)}));e.h2(`${t} (${n.length})`);let o=Math.max(...a.map(e=>e.address.length));for(let t of a)e.text(` ${t.address.padEnd(o)} ${t.rule}`.trimEnd());i.length<n.length&&e.text(` …and ${n.length-i.length} more`),e.blank()}function Et(e,t=!1){let n=e.getSheet(),r=e.getCoords(),i=n.getName(),a=[];for(let e of n.getNames().getItems({type:`formula`,includeHidden:!0})??[]){let n=null;try{n=e.getRanges?.()??null}catch{}n?n.getCoords().some(e=>{return(!e.scope||e.scope===i)&&(n=e,(t=r).rowStart<=n.rowEnd&&n.rowStart<=t.rowEnd&&t.colStart<=n.colEnd&&n.colStart<=t.colEnd);var t,n})&&a.push(e):t&&e.getScope()===i&&a.push(e)}return a}async function Dt(e,t){let n=t.getSheet();await z(e,Et(t,!0),{symbols:n.getWorkbook()?.getNames().getItems({includeHidden:!0})??n.getNames().getItems({includeHidden:!0})??[]});let r=t.getColumnHeaders(),i=t.getRowHeaders();wt(e,`Hidden Columns`,r),wt(e,`Hidden Rows`,i);let a=t.getTables();a.length>0&&tt(e,a,t.getCounts([F.Table])[F.Table]??0)}var Ot=`#REF!`,B=e=>{let t=e.getContent();return t.getType()===`chart`&&typeof t.getSeries==`function`?t:null},kt=(t,n)=>`${L(t.getName())}!${e.AddressUtils.rangeToString(n)??``}`,At=(e,t)=>e?kt(e.getSheet(),e.getCoords()):t,V=e=>e.replace(/\s*[\r\n]+\s*/g,` ⏎ `).trim(),jt=(e,t)=>({colStart:Math.min(e.colStart,t.colStart),rowStart:Math.min(e.rowStart,t.rowStart),colEnd:Math.max(e.colEnd,t.colEnd),rowEnd:Math.max(e.rowEnd,t.rowEnd)}),Mt=e=>{if(e.length===0)return null;let t=e[0],n=t.getValuesRange();if(!n)return null;let r=n.getSheet(),i=n.getCoords(),a=e.length===1,o=i.colStart===i.colEnd,s=i.rowStart===i.rowEnd;if(!a&&!o&&!s)return null;let c=o&&s?null:o?`column`:s?`row`:null,l=t.getCategoriesFormula(),u=t.getNameRange(),d=t.getNameFormula()!==null;if(d&&!u?.isSingleCell())return null;let f=i,p=u?.getCoords()??null;for(let n=1;n<e.length;n++){let a=e[n];if(a.getChartType()!==t.getChartType()||a.isSecondaryAxis()!==t.isSecondaryAxis()||a.getCategoriesFormula()!==l)return null;let m=a.getValuesRange();if(!m||m.getSheet()!==r)return null;let h=m.getCoords(),g=h.colStart===f.colStart+1&&h.colEnd===f.colEnd+1&&h.rowStart===i.rowStart&&h.rowEnd===i.rowEnd,_=h.rowStart===f.rowStart+1&&h.rowEnd===f.rowEnd+1&&h.colStart===i.colStart&&h.colEnd===i.colEnd;if(c===null&&(c=g&&o?`column`:_&&s?`row`:null),c===null||(c===`column`?!g:!_)||(f=h,a.getNameFormula()!==null!==d))return null;if(d){let e=a.getNameRange();if(!e?.isSingleCell()||e.getSheet()!==u.getSheet())return null;let t=e.getCoords();if(!(c===`column`?t.colStart===p.colStart+1&&t.rowStart===p.rowStart:t.rowStart===p.rowStart+1&&t.colStart===p.colStart))return null;p=t}}return{values:kt(r,jt(i,f)),by:a?null:c,names:u&&p?kt(u.getSheet(),jt(u.getCoords(),p)):null,categories:At(t.getCategoriesRange(),l)}},Nt=e=>{let t=[],n=[[`name`,e.getNameFormula()],[`values`,e.getValuesFormula()],[`categories`,e.getCategoriesFormula()]];for(let[e,r]of n)r?.includes(Ot)&&t.push(`${e} ${r}`);return t},Pt=e=>{let t=0;for(let n of e)Nt(n).length>0&&t++;return t},Ft=e=>{let t=e.getChartType();return t&&t!==`unknown`?t:null};function It(e){let t=[],n=Ft(e);n&&t.push(n);let r=e.getChartTitle();var i,a;r&&t.push(`"${i=V(r),a=40,i.length>a?`${i.slice(0,a-1)}…`:i}"`);let o=e.getSeries();if(o.length>0){t.push(`${o.length} series`);let n=e.getPivotSource(),r=n?null:Mt(o);n?t.push(`pivot table ${n}`):r&&(t.push(`values ${r.values}`),r.categories&&t.push(`categories ${r.categories}`));let i=Pt(o);i>0&&t.push(`${Ot} in ${i} series`)}return t.length>0?t.join(` · `):null}function Lt(e){let t=[],n=e.getChartTitle();n&&t.push([`title`,`"${V(n)}"`]);let r=e.getSeries();if(r.length===0)return t;let i=e.getPivotSource(),a=i?null:Mt(r);i?t.push([`series`,`${r.length} · from pivot table ${i}`]):a?(t.push([`series`,`${r.length} · ${a.values}${a.by?` by ${a.by}`:``}`]),a.names&&t.push([r.length===1?`name`:`names`,a.names]),a.categories&&t.push([`categories`,a.categories])):t.push([`series`,String(r.length)]);let o=Pt(r);return o>0&&t.push([`broken`,`${Ot} in ${o} series`]),t}var Rt=e=>Ft(e)??``,zt=e=>{let t=e.getTitle(),n=[t?`"${V(t)}"`:`no title`],r=e.getNumberFormat();return r&&r!==`General`&&n.push(`format ${r}`),`${e.getKind()} (${n.join(`, `)})`};function Bt(e,t){let n=Ft(t);e.fact(`Type: chart`+(n?` — ${n}`:``));let r=t.getChartTitle();e.fact(`Title: `+(r?`"${V(r)}"`:`(none)`));let i=t.getSeries(),a=t.getPivotSource();if(a)e.fact(`Series (${i.length}): from pivot table ${a}`);else if(i.length>0){let t=Mt(i);if(t){let n=[`values ${t.values}${t.by?` by ${t.by}`:``}`];t.names&&n.push(`${i.length===1?`name`:`names`} ${t.names}`),t.categories&&n.push(`categories ${t.categories}`),e.fact(`Series (${i.length}): ${n.join(` · `)}`)}else(function(e,t){let n=t.slice(0,c(t.length,12)),r=n.map(e=>{let t=At(e.getValuesRange(),e.getValuesFormula())??`(no values)`,n=At(e.getCategoriesRange(),e.getCategoriesFormula()),r=[`values ${t}`];n&&r.push(`categories ${n}`);let i=At(e.getNameRange(),e.getNameFormula());i&&r.push(`name ${i}`);let a=e.getName();return{name:a?V(a):`(unnamed)`,type:e.isSecondaryAxis()?`${e.getChartType()} · secondary axis`:e.getChartType(),source:r.join(` · `)}});e.fact(`Series (${t.length}):`);let i=Math.max(...r.map(e=>e.name.length)),a=Math.max(...r.map(e=>e.type.length));for(let t of r)e.text(` ${t.name.padEnd(i)} ${t.type.padEnd(a)} ${t.source}`);n.length<t.length&&e.text(` …and ${t.length-n.length} more · getContent().getSeries() on this movable lists every one`)})(e,i)}let o=t.getAxes();o.length>0&&e.fact(`Axes: ${o.map(zt).join(` · `)}`)}var Vt=(e,t)=>e.colStart<=t.colEnd&&t.colStart<=e.colEnd&&e.rowStart<=t.rowEnd&&t.rowStart<=e.rowEnd,Ht=e=>{let t=e.movable.getRange();return`${kt(t.getSheet(),t.getCoords())} "${e.movable.getContent().getName?.()||`(unnamed)`}"${e.direct?``:` (through its dependents)`}`},Ut=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,Wt=e=>e.replace(/[\r\n]+/g,` `).trim(),Gt=e=>e.getShapeType?.()??``,Kt=t=>{let n=t.getRange();return e.AddressUtils.rangeToString(n.getCoords())??n.toString()},qt=(e,t,n)=>{let r=e.replace(/\r\n?|\n/g,` ⏎ `);if(t===null||r.length<=t)return`"${r}"`;let i=r.charCodeAt(t-1),a=i>=55296&&i<=56319?t-1:t;return`"${r.slice(0,a)}…" (+${r.length-a} chars) · full: ${n}`},Jt=({movable:e,text:t})=>qt(t,300,(e=>`${R(e.getRange())}.getRange(${JSON.stringify(Kt(e))}).getMovables()`)(e)),Yt=e=>{let t=e.getContent();return typeof t.getTextFrame==`function`?t.getTextFrame()?.getText()??``:null};function Xt(e){let t=[];for(let n of e){let e=Yt(n)??``;e.trim()!==``&&t.push({movable:n,text:e})}return t.sort((e,t)=>{let n=e.movable.getRange().getCoords(),r=t.movable.getRange().getCoords();return n.rowStart-r.rowStart||n.colStart-r.colStart})}var Zt=e=>e.getType()===`picture`&&e.getResource?.()?.getName()||null,Qt=e=>{let t=e.getContent().getName?.()||`(unnamed)`,n=e.getContent().getDescription(),r=B(e);if(r)return Ut([It(r),n?Wt(n):null,t].filter(Boolean).join(` · `),140);let i=e.getContent(),a=[],o=Zt(i);return o&&a.push(o),n&&a.push(Wt(n)),Ut(a.length>0?`${t} — ${a.join(` · `)}`:t,90)},$t=e=>{let t=e.getContent().getName?.()||`(unnamed)`,n=e.getContent().getDescription();return Ut(n?`${t} — ${Wt(n)}`:t,90)},en=new Map([[`chart`,`Charts`],[`shape`,`Shapes`],[`picture`,`Pictures`],[`slicer`,`Slicers`]]),tn=e=>en.get(e)??`${e.charAt(0).toUpperCase()}${e.slice(1)}s`;function nn(e){let t=new Map;for(let n of e){let e=n.getContent().getType();if(e===`note`)continue;let r=t.get(e);r?r.push(n):t.set(e,[n])}let n=new Map;for(let e of en.keys()){let r=t.get(e);r&&n.set(e,r)}for(let[e,r]of t)n.set(e,r);return n}function rn(e,t){for(let[n,r]of nn(t))an(e,n,r)}function an(e,t,n){let r=Xt(n),i=new Map(r.map(e=>[e.movable,e])),a=[...r.map(e=>e.movable),...n.filter(e=>!i.has(e))],o=a.slice(0,c(a.length,50)),s=o.map(e=>{let t=i.get(e),n=B(e);return{address:Kt(e),preset:n?Rt(n):Gt(e.getContent()),summary:n?$t(e):Qt(e),details:n?Lt(n):[],text:t?Jt(t):``,hidden:e.isHidden()?` (hidden)`:``}});e.h2(`${tn(t)} (${n.length}${r.length>0?` · ${r.length} with text`:``})`);let l=Math.max(...s.map(e=>e.address.length)),u=Math.max(...s.map(e=>e.preset.length)),d=Math.min(40,Math.max(0,...s.filter(e=>e.text).map(e=>e.summary.length)));for(let t of s){let n=u>0?`${t.preset.padEnd(u)} `:``,r=t.text?`${t.summary.padEnd(d)} ${t.text}`:t.summary;e.text(` ${t.address.padEnd(l)} ${n}${r}${t.hidden}`.trimEnd());let i=Math.max(10,...t.details.map(([e])=>e.length+2));for(let[n,r]of t.details)e.text(` ${n.padEnd(i)}${r}`)}if(o.length<a.length){let r=`${R(n[0].getRange())}.getMovables().getItems({ type: ${JSON.stringify(t)} })`;e.text(` …and ${a.length-o.length} more · ${r} reports every one in full`)}e.blank()}function on(t){let n=new P,r=t.getRange(),i=t.getContent(),a=i.getType();n.h1(`Movable — ${lt(r)}`),n.blank(),n.fact(`Name: ${t.getContent().getName?.()||`(unnamed)`}`);let o=B(t);o?Bt(n,o):n.fact(`Type: ${a}`);let s=Zt(i);s&&n.fact(`Content: ${s}`);let c=Gt(i);c&&n.fact(`Shape: ${c}`);let l=i.getTextFrame?.();l&&n.fact(`Text: ${qt(l.getText(),null,``)}`);let u=t.getContent().getDescription();u&&n.fact(`Alt Text: ${Wt(u)}`),n.fact(`Anchor: ${I(r)}, ${(t=>{switch(t){case e.IAnchored.Type.Absolute:return`absolute — stays put when rows or columns move`;case e.IAnchored.Type.OneCell:return`oneCell — moves with the cells, keeps its size`;default:return`twoCell — moves and resizes with the cells`}})(t.getAnchorType?.())}`),n.fact(`Bounds: ${(e=>{let t=e.getBounds();if(!t)return`not laid out`;let n=e=>Math.round(e);return`${n(t.width)}×${n(t.height)} px at (${n(t.x)}, ${n(t.y)})`})(t)}`),t.isHidden()&&n.fact(`Hidden: true — this object is not visible in the UI`);let d=t.getRotation();return d!==0&&n.fact(`Rotation: ${d}°`),n.fact(`Z-Order: ${t.getZIndex()}`),n.blank(),n.text(`Sheet: ${L(r.getSheet().getName())}`),n.toLines().join(`
|
|
4
|
-
`).
|
|
5
|
-
`)
|
|
6
|
-
`)}(e,n);
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@sheetxl/sdk");var t;(t||={}).Mode={Display:`display`,Value:`value`};function n(e){return Number.isFinite(e)?function(e){let t=e.indexOf(`e`);if(t===-1)return e;let n=e.substring(t+2);return`${e.substring(0,t)}E${e[t+1]}${n.length<2?`0`+n:n}`}(String(Number(e.toPrecision(15)))):String(e)}function r(t,r){if(!Number.isFinite(t))return String(t);if(!r||r===`General`)return n(t);try{let i=e.NumberFormat.getEngine().format(r,t)?.text;return i?i.trim():n(t)}catch{return n(t)}}function i(e,n){if(n===t.Mode.Value){let t=a(e.getValue());return t?.match?t:null}let r=e.getText({hideStringPrefix:!0});return r?{match:r,display:e.getText()}:null}function a(t){if(t==null)return null;if(typeof t==`string`)return{match:t,display:`'${t}`};if(typeof t==`boolean`){let e=t?`TRUE`:`FALSE`;return{match:e,display:e}}if(typeof t==`number`){let e=n(t);return{match:e,display:e}}if(e.FormulaError.isError(t)){let e=t.getLabel();return{match:e,display:e}}let r=t.toString();return{match:r,display:r}}var o=[`display`,`value`,`formula`,`hyperlink`,`numberFormat`,`comment`,`shape`,`chart`,`name`],s=[`display`,`formula`,`comment`,`shape`,`chart`,`name`],c=(e,t)=>e<=t+3?e:t,l=e=>{if(!e)return null;let t=String(e.toHex?.()??``);if(!t)return e.toString();let n=/^#FF/i.test(t)&&t.length===9?`#${t.slice(3)}`:t,r=e.toString();if(!r)return n;let i=r.toLowerCase().replace(/^#/,``);return i===n.slice(1).toLowerCase()||i===t.slice(1).toLowerCase()?n:`${n} (${r.replace(/\d+\.\d{4,}/g,e=>String(parseFloat(Number(e).toFixed(2))))})`},u=t=>{let n=t.getFill(),r=n.getType();if(r===e.IFill.Type.None)return null;if(r===e.IFill.Type.Pattern){let t=n,r=t.getPatternType();if(r===e.IFill.BuiltInSheetPattern.None)return null;let i=l(t.getForeground());if(r===e.IFill.BuiltInSheetPattern.Solid)return i?`solid ${i}`:`solid`;let a=l(t.getBackground());return[`${r} pattern`,i,a?`on ${a}`:null].filter(Boolean).join(` `)}let i=l(n.getColor?.());return i?`${r} ${i}`:r},d=e=>{let t=p(e);return t.length>0?t.join(` · `):null},f=new Set([`top`,`left`,`bottom`,`right`]),p=e=>{let t=e.getBorders(),n=[[`top`,t.getTop()],[`left`,t.getLeft()],[`bottom`,t.getBottom()],[`right`,t.getRight()],[`horizontal`,t.getHorizontal()],[`vertical`,t.getVertical()],[`diagonalUp`,t.getDiagonalUp()],[`diagonalDown`,t.getDiagonalDown()]],r=new Map;for(let[e,t]of n){let n=t?.getStyle?.();if(!n||n===`none`)continue;let i=l(t?.getColor?.()),a=i?`${n} ${i}`:n,o=r.get(a);o?o.push(e):r.set(a,[e])}let i=[];for(let[e,t]of r){let n=t.length===4&&t.every(e=>f.has(e));i.push(`${n?`outline`:t.join(`+`)} ${e}`)}return i},m=e=>{let t=e.getNumberFormat();return t&&t!==`General`?t:null},h=(e,t)=>{let n=e.getAlignment(),r=t.getAlignment(),i=[];return n.getHorizontal()!==r.getHorizontal()&&i.push(`h ${n.getHorizontal()}`),n.getVertical()!==r.getVertical()&&i.push(`v ${n.getVertical()}`),n.getOverflow()!==r.getOverflow()&&i.push(n.getOverflow()),n.getIndent()!==r.getIndent()&&i.push(`indent ${n.getIndent()}`),n.getRotation()!==r.getRotation()&&i.push(`rotation ${n.getRotation()}`),i.length>0?i.join(` · `):null},g=(e,t)=>{let n=e.getFont(),r=t.getFont(),i=[];n.getBold()!==r.getBold()&&i.push(n.getBold()?`bold`:`not bold`),n.getItalic()!==r.getItalic()&&i.push(n.getItalic()?`italic`:`not italic`),n.getUnderline()!==r.getUnderline()&&i.push(`underline ${n.getUnderline()}`),n.getStrike()!==r.getStrike()&&i.push(n.getStrike()?`strike`:`not strike`),n.getSize()!==r.getSize()&&i.push(`${n.getSize()}pt`),n.getFamily()!==r.getFamily()&&i.push(n.getFamily());let a=l(n.getColor());return a!==l(r.getColor())&&i.push(a??`no color`),i.length>0?i.join(` · `):null},_=e.ICellRange.Feature;function v(t,n,r){let{rowIndex:i,colIndex:a}=n,o=r===`row`,s=o?a:i;if(s===0)return null;let c=t.getRange({rowStart:i,rowEnd:i,colStart:a,colEnd:a}).getSurrounding({contentOnly:!0}).getCoords(),l=o?c.colStart:c.rowStart;if(l<s){let e=b(t,o?i:l,o?l:a);if(e)return e}let u=o?t.getRange({rowStart:i,rowEnd:i,colStart:0,colEnd:a-1}):t.getRange({rowStart:0,rowEnd:i-1,colStart:a,colEnd:a});for(let n of u.entries({features:[_.Contentful],axis:o?e.IRange.Axis.Column:e.IRange.Axis.Row,reverse:!0})){if(n.context.getType()!==e.ScalarType.String)continue;let r=n.context.getCoords();return b(t,r.rowIndex,r.colIndex)}return null}var y=e=>e?`${JSON.stringify(e.text)} (${e.address})`:null;function b(n,r,a){let o=n.getRange({rowStart:r,rowEnd:r,colStart:a,colEnd:a}).getCell();if(o.getType()!==e.ScalarType.String)return null;let s=i(o,t.Mode.Display)?.match;return s?{text:s,address:o.getAddress()}:null}function x(e){let t=e,n=``;do n=String.fromCharCode(65+t%26)+n,t=Math.floor(t/26)-1;while(t>=0);return n}var S=e.ICellRange.Feature;function C(e,n){let r=n?.maxSeries??24,a=n?.maxProfileCells??2e4,o=n?.maxCategories??3,s=e.getRowCount(),c=e.getColumnCount();if(s===1&&c===1)return{shape:`cell`,summary:i(e.getCell(),t.Mode.Display)?.display??`(blank)`,series:[]};let l=e.getRange(),u=l.getCoords(),d=s>=c;if(s===1||c===1)return{shape:`list`,summary:le(l,o),series:[]};let f=ee(e,d),p=d?c:s,m=d?null:`by row`,h=f.present&&f.inside,g=d&&h?u.rowStart+1:u.rowStart,_=!d&&h?u.colStart+1:u.colStart,v=re(l,d,d?g:_,a),y=d&&v?v.start-1:u.rowEnd,b=!d&&v?v.start-1:u.colEnd,x=y-g+1,S=b-_+1,C=x*S>a,te=C&&d?Math.max(1,Math.floor(a/Math.max(1,S))):x,ne=C&&!d?Math.max(1,Math.floor(a/Math.max(1,x))):S,ie=Math.min(y,g+te-1),ae=Math.min(b,_+ne-1),oe=Math.min(p,r),w=[],se=[];for(let t=0;t<oe;t++){let n=d?l.getRangeAt(g,u.colStart+t,ie,u.colStart+t):l.getRangeAt(u.rowStart+t,_,u.rowStart+t,ae);w.push(ce(e,d,t,f.names)),se.push(le(n,o))}let ue=w.length?Math.max(...w.map(e=>e.length)):0,T=w.map((e,t)=>`${e.padEnd(ue)} ${se[t]}`);p>oe&&T.push(`…${p-oe} more ${d?`columns`:`rows`} not profiled · read them with getStats()`);let E=[m,f.note,v?.note];return C&&E.push(`profiled from the first ${d?`${te} rows`:`${ne} columns`} of ${d?x:S}`),{shape:f.present?`table`:`block`,summary:E.filter(Boolean).join(` · `),series:T}}function ee(e,t){let n=e.getRange(),r=n.getCoords(),i=e.getCell().getTable();if(i){let e=i.getColumns().map(e=>e.getName()),n=i.getRange().getCoords();return{present:!0,inside:!0,note:`${n.rowStart===r.rowStart&&n.rowEnd===r.rowEnd&&n.colStart===r.colStart&&n.colEnd===r.colEnd?``:`part of `}table ${i.getName()}`,names:t?e:null}}let a=t?r.rowStart+1:r.colStart+1,o=w(t?n.getRangeAt(a,r.colStart,r.rowEnd,r.colEnd):n.getRangeAt(r.rowStart,a,r.rowEnd,r.colEnd)),s=t?n.getRangeAt(r.rowStart,r.colStart,r.rowStart,r.colEnd):n.getRangeAt(r.rowStart,r.colStart,r.rowEnd,r.colStart);if(w(s)&&!o)return{present:!0,inside:!0,note:`header `+(t?`row ${r.rowStart+1}`:`column ${x(r.colStart)}`),names:se(s,e,t)};let c=(t?r.rowStart:r.colStart)-1;if(c>=0&&!w(n)){let i=t?n.getRangeAt(c,r.colStart,c,r.colEnd):n.getRangeAt(r.rowStart,c,r.rowEnd,c);if(w(i))return{present:!0,inside:!1,note:`header ${t?`row ${c+1}`:`column ${x(c)}`} (above this block)`,names:se(i,e,t)}}return{present:!1,inside:!1,note:`no header detected`,names:null}}var te=3;function ne(e,t=2e4){let n=e.getRowCount(),r=e.getColumnCount();if(n<2||r<2)return null;let i=n>=r,a=e.getCoords(),o=ee({getRowCount:()=>n,getColumnCount:()=>r,getCell:()=>e.getCell(),getRange:()=>e},i),s=o.present&&o.inside;return re(e,i,(i?a.rowStart:a.colStart)+ +!!s,t)}function re(e,t,n,r){let i=e.getCoords(),a=t?i.rowEnd:i.colEnd,o=t?i.colStart:i.rowStart,s=t?i.colEnd:i.rowEnd,c,l=-1,u=e.getCell().getTable(),d=t&&!!u?.isShowTotals()&&u.getRange().getCoords().rowEnd===i.rowEnd;if(d)l=a;else{if(e.getRowCount()*e.getColumnCount()>r)return null;let u=e.getValues(),d=(e,n)=>t?u[e-i.rowStart][n-i.colStart]:u[n-i.rowStart][e-i.colStart],f=s-o+1,p=Array(f).fill(0),m=Array(f).fill(!1);for(let r=n;r<=a;r++){if(r-n>=2){let n=ie(f,e=>d(r,o+e),p,m,e=>t?`${x(o+e)}${r+1}`:`${x(r)}${o+e+1}`);if(n.matches>=2&&2*n.matches>n.candidates){let i=t?e.getRangeAt(r,o,r,s):e.getRangeAt(o,r,s,r);l=r,c={...n,byColumn:t,typed:(i.getCounts([S.Formula])[S.Formula]??0)===0};break}}for(let e=0;e<f;e++){let t=d(r,o+e);typeof t==`number`&&(p[e]+=t,m[e]=!0)}}if(l<0)return null}let f=e.getSheet(),p=[];for(let n=l;n<=a;n++){let r=t?{rowIndex:n,colIndex:i.colStart}:{rowIndex:i.rowStart,colIndex:n},a=oe(e,r)??v(f,r,t?`row`:`column`);p.push({index:n,label:a,...n===l&&c?{sums:c}:{}})}let m=e=>t?String(e+1):x(e),h=l===a?`${t?`row`:`column`} ${m(l)}`:`${t?`rows`:`columns`} ${m(l)}:${m(a)}`,g=p.slice(0,te).map(e=>[m(e.index),e.label?JSON.stringify(e.label.text):null,e.sums?ae(e.sums):e.index===l&&d?`table totals`:null].filter(Boolean).join(` `)),_=p.length-g.length;return{byColumn:t,start:l,lines:p,note:`${h} not profiled: ${g.join(` · `)}${_>0?` · +${_} more`:``}`}}function ie(e,t,r,i,a){let o=0,s=0,c=[];for(let l=0;l<e;l++){if(!i[l])continue;s++;let e=t(l),u=r[l];typeof e==`number`&&Math.abs(e-u)<=1e-9*Math.max(1,Math.abs(u))?o++:typeof e==`number`?c.push(`${a(l)} ${n(e)} ≠ Σ ${n(u)}`):c.push(`${a(l)} ${e==null?`blank`:typeof e==`string`?`text`:String(e)}`)}return{matches:o,candidates:s,misses:c}}function ae(e){let t=e.misses.slice(0,3),n=e.misses.length-t.length,r=t.length>0?`; ${t.join(`, `)}${n>0?`, +${n} more`:``}`:``;return`${e.typed?`typed, `:``}= Σ ${e.byColumn?`above`:`to the left`} (${e.matches} of ${e.candidates}${r})`}function oe(n,r){let a=n.getRangeAt(r.rowIndex,r.colIndex).getCell();if(a.getType()!==e.ScalarType.String)return null;let o=i(a,t.Mode.Display)?.match;return o?{text:o,address:a.getAddress()}:null}function w(t){let n=t.getStats({onError:`ignore`}),r=n.getCount();return r>0&&(n.getTypedCounts()[e.ScalarType.String]??0)===r}function se(e,n,r){let a=n.getRange().getCoords(),o=e.getCoords(),s=r?a.colEnd-a.colStart+1:a.rowEnd-a.rowStart+1,c=[];for(let n=0;n<s;n++){let s=r?e.getRangeAt(o.rowStart,a.colStart+n).getCell():e.getRangeAt(a.rowStart+n,o.colStart).getCell();c.push(i(s,t.Mode.Display)?.match??``)}return c}function ce(e,t,n,r){let i=e.getRange().getCoords(),a=t?x(i.colStart+n):String(i.rowStart+n+1),o=r?.[n];return o?`${a} ${o}`:a}function le(t,n=3){let r=t.getStats({onError:`ignore`}),i=r.getTypedCounts(),a=r.getCount(),o=r.getSize(),s=o-a;if(a===0)return`${o} cells, all blank`;let c=t.getCounts([S.Formula])[S.Formula]??0,l=T(t),u=i[e.ScalarType.Number]??0,d=i[e.ScalarType.String]??0,f=i[e.ScalarType.Error]??0,p=[String(a)],m=!1;if(c===a){let e=[...t.getRegions(S.Formula)];if(e.length===1){let t=e[0].getCell().getFormulaText();p.push(`formula`,t||`(uniform)`)}else p.push(`formula`,`${e.length} distinct`)}else if(l===a)p.push(`date`,de(r,E(t).format));else if(u===a){let e=E(t);p.push(`number`,de(r,e.format),...fe(r,e))}else if(d===a)p.push(`text`,pe(r,n));else{let t=[u?`number ${u}`:null,d?`text ${d}`:null,i[e.ScalarType.Boolean]?`boolean ${i[e.ScalarType.Boolean]}`:null,f?`error ${f}`:null].filter(Boolean);p.push(`mixed`,t.join(` · `)),m=!0}let h=[f>0&&!m?`error ${f}`:null,s>0?`${s} blank`:null,c>0&&c!==a?`${c} formula`:null].filter(Boolean),g=p.filter(Boolean).join(` `);return h.length?`${g} · ${h.join(` · `)}`:g}function ue(t,n=3){let r=t.getStats({onError:`ignore`}),i=r.getTypedCounts(),a=[],o=i[e.ScalarType.Number]??0;if(o>0){let e=E(t),n=[de(r,e.format),...fe(r,e)].filter(Boolean);a.push(`Number: ${o} ${n.join(` `)}`.trimEnd())}let s=i[e.ScalarType.String]??0;if(s>0){let e=pe(r,n,e=>typeof e==`string`);a.push(`String: ${s} ${e}`.trimEnd())}let c=i[e.ScalarType.Boolean]??0;if(c>0){let e=pe(r,n,e=>typeof e==`boolean`);a.push(`Boolean: ${c} ${e}`.trimEnd())}return a}function T(t){let n=0;return t.forEach((t,r)=>{r.getInteropType()===e.InteropScalarType.Date&&n++}),n}function E(t){let n=t=>t.getStats({onError:`ignore`}).getTypedCounts()[e.ScalarType.Number]??0,r=new Map,i=0;for(let e of t.getRegions(S.NumberFormat)){let t=e.getRange().getStyle().getNumberFormat(),a=n(e.getRange());i+=a,t&&a>0&&r.set(t,(r.get(t)??0)+a)}let a=n(t)-i;a>0&&r.set(`General`,(r.get(`General`)??0)+a);let o=[...r].sort((e,t)=>t[1]-e[1]||Number(t[0]===`General`)-Number(e[0]===`General`));if(o.length===0)return{format:null,mixed:null};let s=e.NumberFormat.getEngine(),c=e=>{if(e===`General`)return`1`;let t=s.getFormatInfo(e);return t?`${t.isDate?`date`:t.scale}`:`1`},l=o[0][0];return o.every(([e])=>c(e)===c(l))?{format:l===`General`?null:l,mixed:null}:{format:null,mixed:o.map(([e,t])=>`${e} ${t}`).join(` · `)}}function de(e,t){let n=e.getAggregates({onError:`ignore`});if(n.min===null||n.max===null)return``;let i=r(n.min,t),a=r(n.max,t);return i===a?i:`${i} … ${a}`}function fe(e,{format:t,mixed:n}){if(n)return[`mixed formats (${n})`];let i=e.getAggregates({onError:`ignore`}),a=[];return i.sum!==null&&a.push(`Σ ${r(i.sum,t)}`),i.average!==null&&a.push(`x̄ ${r(i.average,t)}`),a}function pe(e,t,n){let r=e.getFrequencies(n?{filterFn:n}:void 0),i=r.getUniqueCount();if(i===0)return``;if(i===r.getTotalCount())return`${i} distinct, no repeats`;let a=Array.from(r.getValueCounts()).slice(0,t);return`${i} unique (${a.map(([e,t])=>`${e} ${t}`).join(` · `)}${i>a.length?` · …`:``})`}var D=e.ICellRange.Feature,me=e=>(e.rowEnd-e.rowStart+1)*(e.colEnd-e.colStart+1),he=(e,t)=>{let n=Math.min(e.rowEnd,t.rowEnd)-Math.max(e.rowStart,t.rowStart)+1;if(n<=0)return 0;let r=Math.min(e.colEnd,t.colEnd)-Math.max(e.colStart,t.colStart)+1;return r<=0?0:n*r},ge=e=>e.toLocaleString(`en-US`),_e=(e,t)=>{let n=`×${ge(e.content)}`;return t===`times`||e.styled===e.content?n:`${n} (+${ge(e.styled-e.content)} blank)`},ve=t=>{if(t.length===0)return``;let n=e.AddressUtils.rangeToString(t[0]);if(t.length===1)return n;let r=t.length-1;return`${n}, +${r} block${r===1?``:`s`}`};function O(e,t){let n=t?.manyDistinct??20,{sorted:r,top:i,rare:a,more:o}=ye(e,t);if(r.length===0)return``;let s=e=>((e,t)=>{let n=ve(e.blocks);return`${e.label===t?.hideLabel?``:`${e.label} `}${_e(e,t?.countStyle??`cells`)}${n?` ${n}`:``}`})(e,t);if(o===0)return r.map(s).join(` · `);let c=r.reduce((e,t)=>e+t.content,0),l=c>0?r[0].content/c:0,u=[],d=r.length>n?`${r.length} distinct${l<.5?`, no convention`:``}; largest `:``;return u.push(d+i.map(s).join(` · `)),a.length>0&&u.push(`rarest ${a.map(s).join(` · `)}`),u.push(`+${o} more${t?.recovery?` (${t.recovery})`:``}`),u.join(` · `)}function ye(e,t){let n=t?.maxValues??8,r=[...e].sort((e,t)=>t.content-e.content||t.styled-e.styled||(e.label<t.label?-1:1));if(r.length<=n)return{sorted:r,top:r,rare:[],more:0};let i=Math.max(1,Math.floor(n/2)),a=r.slice(0,i),o=[];for(let e=r.length-1;e>=i&&o.length<n-i;e--)r[e].content>0&&o.push(r[e]);return o.reverse(),{sorted:r,top:a,rare:o,more:r.length-a.length-o.length}}var be=[{name:`family`,project:(e,t)=>k(e.getFont().getFamily(),t?.getFont().getFamily())},{name:`size`,project:(e,t)=>k(e.getFont().getSize(),t?.getFont().getSize(),e=>`${e}pt`)},{name:`bold`,project:(e,t)=>k(e.getFont().getBold(),t?.getFont().getBold()??!1,e=>e?`bold`:`not bold`)},{name:`italic`,project:(e,t)=>k(e.getFont().getItalic(),t?.getFont().getItalic()??!1,e=>e?`italic`:`not italic`)},{name:`underline`,project:(e,t)=>k(e.getFont().getUnderline(),t?.getFont().getUnderline(),e=>String(e))},{name:`strike`,project:(e,t)=>k(e.getFont().getStrike(),t?.getFont().getStrike()??!1,e=>e?`strike`:`not strike`)},{name:`color`,project:(e,t)=>k(l(e.getFont().getColor()),t?l(t.getFont().getColor()):null)}],xe=e=>Oe(e)??`Custom`,Se={name:`category`,project:e=>{let t=m(e);return t===null?null:xe(t)}},Ce={name:`format`,project:e=>m(e)},we=[Se,Ce],Te=[{name:`color`,project:e=>u(e)}],Ee=[{name:`edges`,project:e=>d(e)}],De=[{name:`h`,ambiguous:!0,project:(e,t)=>k(e.getAlignment().getHorizontal(),t?.getAlignment().getHorizontal())},{name:`v`,ambiguous:!0,project:(e,t)=>k(e.getAlignment().getVertical(),t?.getAlignment().getVertical())},{name:`overflow`,project:(e,t)=>k(e.getAlignment().getOverflow(),t?.getAlignment().getOverflow())},{name:`indent`,project:(e,t)=>k(e.getAlignment().getIndent(),t?.getAlignment().getIndent()??0,e=>`indent ${e}`)},{name:`rotation`,project:(e,t)=>k(e.getAlignment().getRotation(),t?.getAlignment().getRotation()??0,e=>`rotation ${e}`)}];function k(e,t,n=String){return e==null||t!==void 0&&e===t?null:n(e)}function Oe(t){if(!t||t===`General`)return null;let n=e.NumberFormat.Builder.parse(t);if(n.category===`General`)return null;let r=n.decimalPlaces;return r==null?n.category:`${n.category} ${r}dp`}var ke={[D.Font]:be,[D.NumberFormat]:we,[D.Fill]:Te,[D.Borders]:Ee,[D.Alignment]:De},Ae=e=>e in ke;function je(e,t,n,r){let i=ke[t];if(!i)return null;let a=e.getEntireCoords(),o=e.getUsedRange()?.getCoords()??null,s=[...e.getEntireRange().getRegions(t)];if(s.length===0)return null;let c=r?.content??(o?[...e.getEntireRange().getRegions(D.Contentful)].map(e=>e.getCoords()):[]),l=e=>c.reduce((t,n)=>t+he(e,n),0),u=e=>o?he(e,o):0,d=e=>{let t=e.getRange().getStyle(),r=[];for(let e of i){let i=e.project(t,n);i!==null&&r.push(e.ambiguous?`${e.name} ${i}`:i)}return r.join(` · `)},f=new Set,p=new Map;for(let e of s)p.set(e,e.getRange().getStyle()),f.add(d(e));let m=a.rowEnd-a.rowStart+1,h=a.colEnd-a.colStart+1,g=[],_=[],v=[];for(let e of s){let t=e.getCoords();2*(t.rowEnd-t.rowStart+1)>m?g.push(e):2*(t.colEnd-t.colStart+1)>h?_.push(e):v.push(e)}let y=[];y.push(...Re(`columns`,g,d,a,!0)),y.push(...Re(`rows`,_,d,a,!1));let b=v.reduce((e,t)=>e+u(t.getCoords()),0),x=e=>{let t=[];for(let r of v){let i=e.project(p.get(r),n);i!==null&&t.push({...r.getCoords(),key:i,label:i})}let r=new Map;for(let e of function(e){let t=[...e];if(t.length<=1)return t;let n=!0,r=0;for(;r<2;){let e=n;t.sort((t,n)=>t.key<n.key?-1:t.key>n.key?1:e?t.rowStart-n.rowStart||t.rowEnd-n.rowEnd||t.colStart-n.colStart:t.colStart-n.colStart||t.colEnd-n.colEnd||t.rowStart-n.rowStart);let i=[],a=!1;for(let n of t){let t=i[i.length-1];t&&t.key===n.key&&(e?t.rowStart===n.rowStart&&t.rowEnd===n.rowEnd&&t.colEnd+1===n.colStart:t.colStart===n.colStart&&t.colEnd===n.colEnd&&t.rowEnd+1===n.rowStart)?(i[i.length-1]={...t,colEnd:e?n.colEnd:t.colEnd,rowEnd:e?t.rowEnd:n.rowEnd},a=!0):i.push(n)}t=i,r=a?0:r+1,n=!n}return t}(t)){let t=r.get(e.key)??{label:e.label,content:0,styled:0,blocks:[]};t.content+=l(e),t.styled+=u(e),t.blocks.push(e),r.set(e.key,t)}return[...r.values()].map(e=>({...e,blocks:e.blocks.sort((e,t)=>me(t)-me(e))}))},S=[];if(t===D.NumberFormat)S.push(...function(e,t,n){let{top:r,rare:i,more:a}=ye(e,n),o=[],s=-1;for(let e of[...r,...i]){e===i[0]&&(s=o.length);let n=ye(t.filter(t=>xe(t.label)===e.label),{maxValues:1/0}).sorted,r=n.length===1;if(o.push([e.label,_e(e,`cells`),ve(e.blocks),r?n[0].label:`${n.length} formats`]),!r){for(let e of n.slice(0,Le))o.push([``,_e(e,`cells`),ve(e.blocks),e.label]);n.length>Le&&o.push([``,``,``,`…and ${n.length-Le} more`])}}let c=[0,1,2].map(e=>Math.max(...o.map(t=>t[e].length))),l=o.map(e=>`${e[0].padEnd(c[0])} ${e[1].padEnd(c[1])} ${e[2].padEnd(c[2])} ${e[3]}`.trimEnd());return a>0&&l.splice(s<0?l.length:s,0,`…and ${a} more${n?.recovery?` · ${n.recovery}`:``}`),l}(x(Se),x(Ce),r));else for(let e of i){let t=x(e);if(t.length===0)continue;let n=O(t,{...r,hideLabel:e.name});n.length<=Fe?S.push(`${e.name.padEnd(10)}${n}`):S.push(...Ie(e.name,t,r))}return{distinct:f.size,cells:b,normal:n?Pe(t,n):null,tiers:y,attributes:S}}function Me(e,t){if(e.length===0)return null;let n=new Map,r=new Map,i=0;for(let t of e){let e=t.getRowCount()*t.getColumnCount(),a=t.getCell(),o=a.getFormulaText({r1c1:!0})??``,s=n.get(o)??{label:o,cells:0,blocks:[]};s.cells+=e,s.blocks.push(t.getCoords()),n.set(o,s);let c=new Set;for(let e of a.getFormula()?.getTokens()??[]){if(e.type!==`function`)continue;let t=String(e.value??e.text??``).toUpperCase();t&&c.add(t)}c.size===0&&(i+=e);for(let t of c)r.set(t,(r.get(t)??0)+e)}let a={...t,countStyle:`times`},o=[...n.values()].map(e=>({label:e.label,content:e.cells,styled:e.cells,blocks:e.blocks.sort((e,t)=>me(t)-me(e))})),s=[...r.entries()].map(([e,t])=>({label:e,content:t,styled:t,blocks:[]}));return i>0&&s.push({label:`no function`,content:i,styled:i,blocks:[]}),{distinct:n.size,lines:[`${`distinct`.padEnd(10)}${O(o,a)}`,`${`functions`.padEnd(10)}${O(s,a)}`]}}function Ne(e,t){let n=e.getStats({onError:`ignore`}).getTypedCounts(),r=new Map,i=[[`number`,`number`],[`string`,`text`],[`boolean`,`boolean`],[`error`,`error`],[`richData`,`richData`]];for(let[e,t]of i){let i=n[e]??0;i>0&&r.set(t,i)}let a=T(e),o=0;for(let e of t){let t=e.getRange().getStats({onError:`ignore`}).getTypedCounts();o+=e.getRowCount()*e.getColumnCount();for(let[e,n]of i){let i=t[e]??0;i>0&&r.set(n,(r.get(n)??0)-i)}a>0&&(t.number??0)>0&&(a-=T(e.getRange()))}return a>0&&(r.set(`date`,a),r.set(`number`,(r.get(`number`)??0)-a)),o>0&&r.set(`formula`,o),[...r.entries()].filter(([,e])=>e>0).sort((e,t)=>t[1]-e[1])}function Pe(e,t){switch(e){case D.Font:return function(e){let t=e.getFont(),n=[t.getFamily(),`${t.getSize()}pt`],r=l(t.getColor());return r&&n.push(r),t.getBold()&&n.push(`bold`),t.getItalic()&&n.push(`italic`),n.join(` · `)}(t);case D.NumberFormat:{let e=m(t);return e===null?null:`${xe(e)} ${e}`}case D.Fill:return u(t);case D.Borders:return d(t);case D.Alignment:{let e=t.getAlignment(),n=[];return e.getHorizontal()!==`general`&&n.push(`h ${e.getHorizontal()}`),e.getVertical()!==`bottom`&&n.push(`v ${e.getVertical()}`),e.getOverflow()!==`visible`&&n.push(String(e.getOverflow())),e.getIndent()&&n.push(`indent ${e.getIndent()}`),e.getRotation()&&n.push(`rotation ${e.getRotation()}`),n.length>0?n.join(` · `):null}default:return null}}var Fe=110;function Ie(e,t,n){let{sorted:r,top:i,rare:a,more:o}=ye(t,n),s=[...i,...a].map(e=>[_e(e,`cells`),ve(e.blocks),e.label]),c=[0,1].map(e=>Math.max(...s.map(t=>t[e].length))),l=s.map(e=>` ${e[0].padEnd(c[0])} ${e[1].padEnd(c[1])} ${e[2]}`);o>0&&l.splice(i.length,0,` …and ${o} more${n?.recovery?` · ${n.recovery}`:``}`);let u=n?.manyDistinct??20;return[r.length>u?`${e.padEnd(10)}${r.length} distinct`:e,...l]}var Le=6;function Re(t,n,r,i,a){if(n.length===0)return[];let o=new Map;for(let e of n){let t=r(e),n=o.get(t);n?n.push(e):o.set(t,[e])}let s=a?i.colEnd-i.colStart+1:i.rowEnd-i.rowStart+1,c=[];for(let[n,r]of o){let i=0,o=r.map(t=>{let n=t.getCoords();i+=a?n.colEnd-n.colStart+1:n.rowEnd-n.rowStart+1;let r=a?e.AddressUtils.runToString(n.colStart,n.colEnd,!0):e.AddressUtils.runToString(n.rowStart,n.rowEnd,!1),o=a?n.rowStart:n.colStart;return o===0?r:`${r} (from ${a?`row ${o+1}`:`column ${e.AddressUtils.runToString(o,o,!0).split(`:`)[0]}`})`});2*i>s?c.push(`${`sheet`.padEnd(10)}${n||`default`}`):c.push(`${t.padEnd(10)}${o.join(`, `)} ${n||`default`}`)}return c}var ze=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,A=e=>{if(!e)return null;if(typeof e!=`string`)return l(e);let t=e.replace(/^#/,``);return/^[0-9a-f]{6}$/i.test(t)||/^[0-9a-f]{8}$/i.test(t)?`#${(t.length===8&&/^ff/i.test(t)?t.slice(2):t).toUpperCase()}`:e},Be=t=>{if(!t)return null;let n=[],r=(t=>{if(!t)return null;if(typeof t==`string`)return A(t);let n=t.type;if(n===e.IFill.Type.None)return null;if(n===e.IFill.Type.Gradient)return`gradient`;let r=t,i=A(r.foreground??t.color??r.background),a=r.patternType;return[a&&a!==e.IFill.BuiltInSheetPattern.Solid?`${a} pattern`:null,i].filter(Boolean).join(` `)||null})(t.fill);r&&n.push(`fill ${r}`);let i=t.font;if(i){let t=[];(i.weight===void 0?!0===i.bold:i.weight>=600)&&t.push(`bold`),(i.style===void 0?!0===i.italic:i.style===e.IFont.Style.Italic)&&t.push(`italic`),i.strike&&t.push(`strike`),i.underline&&i.underline!==e.IFont.UnderlineStyle.None&&t.push(`underline ${i.underline}`);let r=i.color===`auto`?null:A(i.color);r&&t.push(`text ${r}`),t.length>0&&n.push(t.join(` `))}if(t.numberFormat!==void 0&&t.numberFormat!==null){let r=typeof t.numberFormat==`number`?e.NumberFormat.resolve(t.numberFormat):String(t.numberFormat);r&&n.push(r)}return t.borders&&n.push(`border`),t.alignment&&n.push(`alignment`),n.length>0?n.join(` · `):null},Ve=t=>{let n=t.type??e.IConditionalFormat.ColorStopType.Num,r=t.value,i=r==null||r===``?n:`${n} ${r}`,a=A(t.color);return a?`${i} ${a}`:i},He=t=>{let n=t.type;if(t.type===e.IConditionalFormat.ScaleType.DataBar){let e=A(t.color);e&&(n+=` ${e}`)}else t.type===e.IConditionalFormat.ScaleType.IconSet&&(t.iconSet&&(n+=` ${t.iconSet}`),t.reverse&&(n+=` reversed`),t.icon?.length&&(n+=` custom icons`));let r=(t.stops??[]).map(Ve).join(` → `);return r?`${n} · ${r}`:n},Ue=`(no rule)`,We=e=>{let t=e.getScale(),n=[];if(t)n.push(He(t));else{n.push(e.getCondition()?.toString()||Ue);let t=Be(e.getStyle());t&&n.push(`→ ${t}`)}return e.isStopIfTrue()&&n.push(`· stop if true`),ze(n.join(` `),90)},Ge=e=>{let t=[e.getCondition()?.toString()||Ue],n=e.getAlertStyle();return n&&t.push(n),e.isIncludeBlanks()&&t.push(`blanks allowed`),e.isHideDropdown()&&t.push(`no dropdown`),ze(t.join(` · `),90)},Ke=t=>{if(t?.getOperator()?.getName()!==e.ICondition.BuiltInOperatorNames.InSet)return null;let n=t.getParam()?.items;if(!n)return null;if(typeof n==`string`)return n;let r=n.slice(0,20).map(e=>a(e)?.match??``),i=n.length-r.length;return i>0?`${r.join(`, `)}, +${i} more`:r.join(`, `)},qe=(e,t)=>{if(e.length===0)return null;let n=e.slice(0,3).map(t),r=e.length-n.length;return r>0?`${n.join(` | `)} | +${r} more`:n.join(` | `)},j=e.ICellRange.Feature,M=e=>e.getRange().getStyle(),Je=e=>i(e.getCell(),t.Mode.Display)?.display??null;function Ye(e,t){switch(e){case j.Formula:return e=>e.getCell().getFormulaText();case j.Error:return Je;case j.CalcError:return e=>{let t=Je(e)??``,n=e.getCell().getFormulaText();return(n?`${t} ${n}`:t).trim()||null};case j.Merge:return Je;case j.Comments:return e=>{let t=e.getCell().getComments()?.getContent();if(typeof t!=`string`)return null;let n=t.replace(/\s+/g,` `).trim();return n?n.length>60?`${n.slice(0,59)}…`:n:null};case j.Spills:return e=>e.getCell().getSpill()?.getValuesRange().toString()??null;case j.Hyperlink:return e=>e.getCell().getHyperlink()?.getAddress()??null;case j.Table:return e=>e.getCell().getTable()?.getName()??null;case j.Fill:return e=>u(M(e));case j.Borders:return e=>d(M(e));case j.NumberFormat:return e=>m(M(e));case j.Alignment:return t?e=>h(M(e),t):void 0;case j.Font:return t?e=>g(M(e),t):void 0;case j.Protection:return e=>{let t=M(e).getProtection(),n=[];return t.isAlwaysUnlocked()&&n.push(`always unlocked`),t.isShowFormulas()||n.push(`formulas hidden`),n.join(`, `)||null};case j.Unlock:return e=>{let t=[];e.getCell().getProtection().isAlwaysUnlocked()&&t.push(`always unlocked`);let n=e.getRange();for(let e of n.getSheet().getProtectedRanges().getItems({address:n}))t.push(`range ${e.getName()}${e.isUnlocked()?``:` · password`}`);return t.join(`, `)||null};case j.Conditionals:return e=>qe(e.getRange().getConditionalFormats(),We);case j.DataValidations:return e=>qe(e.getRange().getDataValidations(),Ge);case j.Contentful:return e=>ue(e.getRange()).join(` `)||null;default:return}}function Xe(e,t){let n=e.map(e=>Ye(e,t)).filter(e=>!!e);if(n.length!==0)return n.length===1?n[0]:e=>{let t=n.map(t=>t(e)).filter(Boolean);return t.length>0?t.join(` `):null}}var N=class{constructor(){this._lines=[],this._headingOffset=0}setHeadingOffset(e){return this._headingOffset=e,this}_heading(e,t){return this._lines.push(`${`#`.repeat(Math.min(6,e+this._headingOffset))} ${t}`),this}h1(e){return this._heading(1,e)}h2(e){return this._heading(2,e)}h3(e){return this._heading(3,e)}text(e){return this._lines.push(e),this}blank(){return this._lines.push(``),this}bullet(e){return typeof e==`string`?this._lines.push(`- ${e}`):e.forEach(e=>this._lines.push(`- ${e}`)),this}fact(e){return typeof e==`string`?this._lines.push(` ${e}`):e.forEach(e=>this._lines.push(` ${e}`)),this}bold(e){return`**${e}**`}codespan(e){return`\`${e}\``}code(e,t=``){return`\`\`\`${t}\n${e}\n\`\`\``}beginFrame(e){return new Ze(this,e)}_addLines(e){this._lines.push(...e)}toLines(){return[...this._lines]}},Ze=class{constructor(e,t){this._parent=e,this._headers=t,this._indexWidth=0,this._rows=[],this._colWidths=t.map(e=>e.length)}addRow(e,t){let n=e.map(e=>typeof e==`string`?{text:e}:e);return n.forEach((e,t)=>{this._colWidths[t]=Math.max(this._colWidths[t]??0,e.text.length)}),t!==void 0&&(this._indexWidth=Math.max(this._indexWidth,t.length)),this._rows.push({index:t,cells:n}),this}endFrame(){return this._parent._addLines(this._renderLines()),this._parent}_columnAlignment(e){let t=0,n=0;for(let r of this._rows){let i=r.cells[e];i&&i.text&&(n++,i.alignment===`right`&&t++)}return n>0&&2*t>=n?`right`:void 0}_renderLines(){let e=this._indexWidth>0?` `.repeat(this._indexWidth):``,t=this._colWidths.map((e,t)=>this._columnAlignment(t)),n=[];if(this._headers.some(e=>e.length>0)){let r=this._headers.map((e,n)=>Qe(e,this._colWidths[n],t[n])).join(` `);n.push(`${e}${e?` `:``}${r}`.trimEnd())}for(let e of this._rows){let t=e.cells.map((e,t)=>Qe(e.text,this._colWidths[t],e.alignment)).join(` `),r=this._indexWidth>0?(e.index??``).padStart(this._indexWidth)+` `:``;n.push(`${r}${t}`.trimEnd())}return n}},Qe=(e,t,n)=>{if(e.length>=t)return e;let r=t-e.length;return n===`right`?e.padStart(t):n===`center`?` `.repeat(Math.floor(r/2))+e+` `.repeat(Math.ceil(r/2)):e.padEnd(t)};function $e(e,t,n){let r=c(t.length,n?.maxRegions??200),i=t.length>r?t.slice(0,r):t,a=i.length<t.length;if(i.length===0)return void e.text(`None`);let o=i.map(e=>e.toString()),s=Math.max(...o.map(e=>e.length)),l=i.map(e=>`${e.getRowCount()}×${e.getColumnCount()}`),u=Math.max(...l.map(e=>e.length)),d=n?.profile?n?.maxProfiled??12:0;for(let t=0;t<i.length;t++){let r=i[t],a=n?.payload?.(r),c=r.isClipped()?` ✂ clipped at the query edge — the block continues`:``,f=` ${o[t].padEnd(s)} ${l[t].padEnd(u)}`;if(t<d){let t=C(r,n);if(e.text(`${f} ${t.summary}${c}`),!1===n?.series)continue;for(let n of t.series)e.text(` ${n}`);continue}e.text(a?`${f} ${a}${c}`:`${f}${c}`.trimEnd())}if(d>0&&i.length>d&&e.text(` …${i.length-d} more regions listed but not profiled · profile one with getRange().getStats(), or loop them in code`),a){let i=n?.recovery??`narrow the range, or loop the regions in code — this listing is a report, not the query`;e.text(` …truncated at ${r} of ${t.length} regions · ${i}`)}}function et(t,n){let r=[...t],i=t.getFeatures(),a=i.join(`, `),o=i.length===1&&i[0]===e.ICellRange.Feature.Contentful,s=t.getRange().getSheet().getWorkbook()?.getStyles().getNormal()??null,c=new N;return c.h1(`Regions — ${a} (${r.length})`),$e(c,r,{...n,profile:o,payload:o?void 0:Xe(i,s)}),c.toLines().join(`
|
|
2
|
+
`).trimEnd()}function tt(e,t=[]){let n=[...t],r=e.getDescription();r&&n.push([`description`,r]),n.push([`columns`,e.getColumns().map(e=>e.getName()).join(`, `)]),n.push([`headers`,e.isShowHeaders()?`shown`:`hidden`]),n.push([`totals`,e.isShowTotals()?`shown`:`hidden`]);let i=Math.max(10,...n.map(([e])=>e.length+2));return n.map(([e,t])=>`${e.padEnd(i)}${t}`)}function nt(e,t,n){if(t.length===0)return;let r=t.map(e=>{let t=e.getRange();return{table:e,address:t.toString(),size:`${t.getRowCount()}×${t.getColumnCount()}`}}),i=Math.max(...r.map(e=>e.address.length)),a=Math.max(...r.map(e=>e.size.length));e.h2(`Tables (${n} cell${n===1?``:`s`} · ${t.length} table${t.length===1?``:`s`})`);for(let t of r){e.text(` ${t.address.padEnd(i)} ${t.size.padEnd(a)} ${t.table.getName()}`);for(let n of tt(t.table))e.text(` ${n}`)}e.blank()}function rt(e){let t=new N;return t.h1(`Table — ${e.getName()}`),t.fact(tt(e,[[`range`,ut(e.getRange())]])),t.toLines().join(`
|
|
3
|
+
`).trimEnd()}var P=e.ICellRange.Feature,it=[P.Error,P.CalcError,P.Contentful,P.Formula,P.Spills,P.Merge,P.AutoTable,P.Hyperlink,P.Comments,P.NumberFormat,P.Font,P.Fill,P.Borders,P.Alignment,P.Conditionals,P.DataValidations],at=new Map(Object.entries(P).map(([e,t])=>[t,e])),ot=e=>at.get(e)??e;function st(e){let t=new Map(Object.values(P).map(e=>[e.toLowerCase(),e])),n=[];for(let r of e.split(`,`)){let e=r.trim();if(!e)continue;let i=t.get(e.toLowerCase());if(!i)throw Error(`Unknown feature '${e}'. Features: ${Object.values(P).join(`, `)}.`);n.push(i)}return n}var F=e=>`${e.toString()}, ${e.getRowCount()}×${e.getColumnCount()}`,I=t=>e.AddressUtils.sheetNameToString(t)??`Untitled`,L=e=>`wb.getSheet(${JSON.stringify(e.getSheet().getName())})`,ct=e=>(e=>{if(!e.includes(`$`))return e;let t=``,n=!1;for(let r of e){if(r===`'`)n=!n;else if(r===`$`&&!n)continue;t+=r}return t})(e.getAddress()),lt=e=>{let t=ct(e);return t.includes(`!`)?t:`${I(e.getSheet().getName())}!${t}`},ut=e=>{let t=e.toString();return`${t.includes(`!`)?t:`${I(e.getSheet().getName())}!${t}`}, ${e.getRowCount()}×${e.getColumnCount()}`};function dt(e,t){let n=Ne(t,[...t.getRegions(P.Formula)]),r=t.getStats({onError:`ignore`}).getCount();e.h2(`Kind (${r} cell${r===1?``:`s`} · ${n.length} kind${n.length===1?``:`s`})`);for(let[t,r]of n)e.text(` ${t.padEnd(10)}${r}`);n.length===0&&e.fact(`None`),e.blank()}function ft(e,t,n){let r=t.getSheet().getWorkbook()?.getStyles().getNormal()??null,i=n?.features===void 0?null:new Set(typeof n.features==`string`?[n.features]:n.features),a=it.filter(e=>!i||i.has(e));if(a.length===0)return;let o=t.getCounts(a),s,c=()=>s??=[...t.getSheet().getEntireRange().getRegions(P.Contentful)].map(e=>e.getCoords());for(let i of a){let a=i===P.Contentful?pt(t):[...t.getRegions(i)];if(a.length===0){let t=r&&i!==P.Font?Pe(i,r):null;t&&(e.h2(`${ot(i)} (${mt(0,0)})`),e.text(` ${`normal`.padEnd(10)}${t}`),e.blank());continue}let s=!!n?.profile&&i===P.Contentful,l=`${L(t)}.getRegions(${JSON.stringify(i)})`,u=`${l} lists all ${a.length}`,d=Ae(i)?je(t.getSheet(),i,r,{recovery:u,content:c()}):null,f=i===P.Formula?Me(a,{recovery:u}):null,p=d?`${mt(a.length,d.cells)} · ${d.distinct} distinct`:f?`${mt(a.length,o[i])} · ${f.distinct} distinct`:mt(a.length,o[i]);if(e.h2(`${ot(i)} (${p})`),d){d.normal&&e.text(` ${`normal`.padEnd(10)}${d.normal}`);for(let t of d.tiers)e.text(` ${t}`);for(let t of d.attributes)e.text(` ${t}`);e.text(` ${`regions`.padEnd(10)}${l}`),e.blank()}else{if(f)for(let t of f.lines)e.text(` ${t}`);i===P.Contentful&&a.sort((e,t)=>t.getRowCount()*t.getColumnCount()-e.getRowCount()*e.getColumnCount()),$e(e,a,{maxRegions:n?.maxRegions,maxProfiled:n?.maxProfiled,profile:s,series:!1,payload:s?void 0:Ye(i,r),recovery:u}),e.blank()}}}var pt=e=>[...e.getRegions([P.Contentful,P.Table])].filter(e=>e.getCell().isContentful()),mt=(e,t)=>`${t} cell${t===1?``:`s`} · ${e} region${e===1?``:`s`}`,ht=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,gt=e=>e.isIFormula?e:null,_t=e=>{let t=e.getScope();return t?`${I(t)}!${e.getName()}`:e.getName()},vt=e=>{let t=e.getAddress();return t.includes(`!`)?t:`${I(e.getSheet().getName())}!${t}`};async function yt(e){let t=gt(e),n;return n=t?`=`+t.getExpression():e.getRanges?.()?.getAddress()??``,t&&await t.isVolatile()&&(n+=` (volatile)`),n.trim()}var bt=new Set([e.FormulaError.Code.Ref,e.FormulaError.Code.Name]),xt=t=>{let n=t.value,r=typeof n==`string`?n:n?.error,i=typeof r==`string`?e.FormulaError.getBuiltInByLabel(r):void 0;return i&&bt.has(i.getCode())?i.getCode()===e.FormulaError.Code.Name?`#NAME?`:`#REF!`:null},St=new Set,Ct=e=>{let t=e.value;return typeof t==`object`&&t?.name?t.name:e.text??``};function wt(e){let t=null;for(let n=0;n<e.length;n++){let r=e[n];if(r.type!==`named`||!r.context)continue;let i=r.context.name?.toUpperCase();if(i!==`LAMBDA`&&(i!==`LET`||r.context.argIndex%2!=0))continue;let a=n+1;for(;a<e.length&&e[a].type===`whitespace`;)a++;if(e[a]?.type!==`separator`)continue;let o=Ct(r).toLowerCase();o&&(t??=new Set).add(o)}return t??St}async function R(e,t,n){if(t.length===0)return;let r=new Set;for(let e of n?.symbols??t)r.add(e.getName().toLowerCase());let i=new Map,a=new Set;for(let e of t)i.set(e.getId(),e),e.getScope()&&a.add(e.getName().toLowerCase());let o=await Promise.all(t.map(async e=>{let t=function(e,t){let n=gt(e),r=[];if(n){let e=n.getTokens(),i=null,a=null;for(let n of e){if(n.type===`error`){a??=xt(n);continue}if(n.type!==`named`)continue;let o=Ct(n);o&&!t.has(o.toLowerCase())&&(i??=wt(e),i.has(o.toLowerCase())||r.includes(o)||r.push(o))}if(a||r.length>0)return{broken:!0,missing:r,error:r.length>0?`#NAME?: ${r.join(`, `)}`:a};if(!n.isReferenceOnly())return{broken:!1,missing:r,error:``}}let i=null;try{i=e.getRanges?.()??null}catch{return{broken:!0,missing:r,error:`#REF!`}}let a=!i||i.isInvalidAny();return{broken:a,missing:r,error:a?`#REF!`:``}}(e,r),n=gt(e),o=n?await async function(e,t){let n=await e.getDirectDependents(),r=0,i=[],a=new Set,o=[];if(n){let e=n.getCoords(),s=n.getCount();for(let c=0;c<s;c++){let s=n.at(c);if(s.isINamedRange){let e=s;if(a.has(e.getId()))continue;a.add(e.getId());let n=t.get(e.getId());i.push(n?_t(n):e.getName())}else{let t=e[c];r+=(t.rowEnd-t.rowStart+1)*(t.colEnd-t.colStart+1),o.push(vt(s))}}}let s=r+i.length;if(s===0)return{text:`unused`,weight:s};let c=[...i,...o],l=[],u=0;for(let e=0;e<c.length;e++){let t=(l.length>0?2:0)+c[e].length;if(l.length>0&&u+t>60)break;l.push(l.length===0?ht(c[e],60):c[e]),u+=t}let d=c.length-l.length,f=d>0?`, +${d} more`:``;return{text:`${s} · ${l.join(`, `)}${f}`,weight:s}}(n,i):null;o?.weight===0&&!e.getScope()&&a.has(e.getName().toLowerCase())&&(o={...o,text:`unused · shadowed`});let s=e.getComment()??``,c=_t(e);return{name:c,refersTo:await yt(e),dependents:o,hidden:e.isHidden(),comment:ht(s,60),broken:t.broken,error:t.error,sortKey:c.toLowerCase().replace(/'/g,``)}})),s=(e,t)=>{let n=(t.dependents?.weight??0)-(e.dependents?.weight??0);return n===0?e.sortKey.localeCompare(t.sortKey):n},l=[...o.filter(e=>e.broken).sort(s),...o.filter(e=>!e.broken).sort(s)],u=c(l.length,n?.maxNames??200),d=l.length>u?l.slice(0,u):l,f=d.filter(e=>e.broken),p=d.filter(e=>!e.broken);e.h2(`${n?.heading??`Names`} (${o.length})`);let m=(t,n)=>{let r=t.some(e=>e.hidden),i=t.some(e=>e.comment.length>0),a=t.some(e=>e.dependents!==null),o=[`Name`,`Refers To`];n&&o.push(`Error`),a&&o.push(`Dependents`),r&&o.push(`Hidden`),i&&o.push(`Comment`);let s=e.beginFrame(o);for(let e of t){let t=[{text:e.name},{text:e.refersTo}];n&&t.push({text:e.error}),a&&t.push({text:e.dependents?.text??``}),r&&t.push({text:e.hidden?`hidden`:``}),i&&t.push({text:e.comment}),s.addRow(t)}s.endFrame()};if(f.length>0){let t=l.reduce((e,t)=>e+ +!!t.broken,0);e.text(`${t} ${t===1?`does`:`do`} not resolve:`),m(f,!0),e.blank()}if(p.length>0&&m(p,!1),d.length<o.length){let t=n?.recovery??`getByName('Name') renders one in full`;e.text(` …and ${o.length-d.length} more · ${t}`)}e.blank()}function Tt(e,t,n){let r=n.getCoords().min,i=[],a=0,o=0;if(n.forEachSpan((e,t)=>{let s=t.getCoords();if(o++,a+=s.max-s.min+1,i.length>=100)return;let c=n.at(s.min-r).getText(),l=n.at(s.max-r).getText();i.push({address:`${c}:${l}`,count:s.max-s.min+1})},{visibility:`hidden`,includeEmpty:!0}),a===0)return;e.h2(`${t} (${a})`);let s=Math.max(...i.map(e=>e.address.length));for(let t of i)e.text(` ${t.address.padEnd(s)} ${t.count}`);o>i.length&&e.text(` …and ${o-i.length} more`),e.blank()}function Et(t){let n=t.getOutline(),r=[];for(let[t,i]of[[e.IRange.Axis.Row,`rows`],[e.IRange.Axis.Column,`columns`]]){let e=n.getLevelCount(t);if(e===0)continue;let a=n.getGroups(t),o=0;for(let e of a)e.collapsed&&o++;r.push(`${i} ${e} ${e===1?`level`:`levels`}, ${a.length} ${a.length===1?`group`:`groups`}`+(o>0?` (${o} collapsed)`:``))}return r.length>0?r.join(` · `):null}function Dt(e,t,n,r){if(n.length===0)return;let i=n.length>50?n.slice(0,50):n,a=i.map(e=>({address:ht(ct(e.getRanges()),40),rule:r(e)}));e.h2(`${t} (${n.length})`);let o=Math.max(...a.map(e=>e.address.length));for(let t of a)e.text(` ${t.address.padEnd(o)} ${t.rule}`.trimEnd());i.length<n.length&&e.text(` …and ${n.length-i.length} more`),e.blank()}function Ot(e,t=!1){let n=e.getSheet(),r=e.getCoords(),i=n.getName(),a=[];for(let e of n.getNames().getItems({type:`formula`,includeHidden:!0})??[]){let n=null;try{n=e.getRanges?.()??null}catch{}n?n.getCoords().some(e=>{return(!e.scope||e.scope===i)&&(n=e,(t=r).rowStart<=n.rowEnd&&n.rowStart<=t.rowEnd&&t.colStart<=n.colEnd&&n.colStart<=t.colEnd);var t,n})&&a.push(e):t&&e.getScope()===i&&a.push(e)}return a}async function kt(e,t){let n=t.getSheet();await R(e,Ot(t,!0),{symbols:n.getWorkbook()?.getNames().getItems({includeHidden:!0})??n.getNames().getItems({includeHidden:!0})??[]});let r=t.getColumnHeaders(),i=t.getRowHeaders();Tt(e,`Hidden Columns`,r),Tt(e,`Hidden Rows`,i);let a=t.getTables();a.length>0&&nt(e,a,t.getCounts([P.Table])[P.Table]??0)}var At=`#REF!`,z=e=>{let t=e.getContent();return t.getType()===`chart`&&typeof t.getSeries==`function`?t:null},jt=(t,n)=>`${I(t.getName())}!${e.AddressUtils.rangeToString(n)??``}`,Mt=(e,t)=>e?jt(e.getSheet(),e.getCoords()):t,B=e=>e.replace(/\s*[\r\n]+\s*/g,` ⏎ `).trim(),Nt=(e,t)=>({colStart:Math.min(e.colStart,t.colStart),rowStart:Math.min(e.rowStart,t.rowStart),colEnd:Math.max(e.colEnd,t.colEnd),rowEnd:Math.max(e.rowEnd,t.rowEnd)}),Pt=e=>{if(e.length===0)return null;let t=e[0],n=t.getValuesRange();if(!n)return null;let r=n.getSheet(),i=n.getCoords(),a=e.length===1,o=i.colStart===i.colEnd,s=i.rowStart===i.rowEnd;if(!a&&!o&&!s)return null;let c=o&&s?null:o?`column`:s?`row`:null,l=t.getCategoriesFormula(),u=t.getNameRange(),d=t.getNameFormula()!==null;if(d&&!u?.isSingleCell())return null;let f=i,p=u?.getCoords()??null;for(let n=1;n<e.length;n++){let a=e[n];if(a.getChartType()!==t.getChartType()||a.isSecondaryAxis()!==t.isSecondaryAxis()||a.getCategoriesFormula()!==l)return null;let m=a.getValuesRange();if(!m||m.getSheet()!==r)return null;let h=m.getCoords(),g=h.colStart===f.colStart+1&&h.colEnd===f.colEnd+1&&h.rowStart===i.rowStart&&h.rowEnd===i.rowEnd,_=h.rowStart===f.rowStart+1&&h.rowEnd===f.rowEnd+1&&h.colStart===i.colStart&&h.colEnd===i.colEnd;if(c===null&&(c=g&&o?`column`:_&&s?`row`:null),c===null||(c===`column`?!g:!_)||(f=h,a.getNameFormula()!==null!==d))return null;if(d){let e=a.getNameRange();if(!e?.isSingleCell()||e.getSheet()!==u.getSheet())return null;let t=e.getCoords();if(!(c===`column`?t.colStart===p.colStart+1&&t.rowStart===p.rowStart:t.rowStart===p.rowStart+1&&t.colStart===p.colStart))return null;p=t}}return{values:jt(r,Nt(i,f)),by:a?null:c,names:u&&p?jt(u.getSheet(),Nt(u.getCoords(),p)):null,categories:Mt(t.getCategoriesRange(),l)}},Ft=e=>{let t=[],n=[[`name`,e.getNameFormula()],[`values`,e.getValuesFormula()],[`categories`,e.getCategoriesFormula()]];for(let[e,r]of n)r?.includes(At)&&t.push(`${e} ${r}`);return t},It=e=>{let t=0;for(let n of e)Ft(n).length>0&&t++;return t},Lt=e=>{let t=e.getChartType();return t&&t!==`unknown`?t:null};function Rt(e){let t=[],n=Lt(e);n&&t.push(n);let r=e.getChartTitle();var i,a;r&&t.push(`"${i=B(r),a=40,i.length>a?`${i.slice(0,a-1)}…`:i}"`);let o=e.getSeries();if(o.length>0){t.push(`${o.length} series`);let n=e.getPivotSource(),r=n?null:Pt(o);n?t.push(`pivot table ${n}`):r&&(t.push(`values ${r.values}`),r.categories&&t.push(`categories ${r.categories}`));let i=It(o);i>0&&t.push(`${At} in ${i} series`)}return t.length>0?t.join(` · `):null}function zt(e){let t=[],n=e.getChartTitle();n&&t.push([`title`,`"${B(n)}"`]);let r=e.getSeries();if(r.length===0)return t;let i=e.getPivotSource(),a=i?null:Pt(r);i?t.push([`series`,`${r.length} · from pivot table ${i}`]):a?(t.push([`series`,`${r.length} · ${a.values}${a.by?` by ${a.by}`:``}`]),a.names&&t.push([r.length===1?`name`:`names`,a.names]),a.categories&&t.push([`categories`,a.categories])):t.push([`series`,String(r.length)]);let o=It(r);return o>0&&t.push([`broken`,`${At} in ${o} series`]),t}var Bt=e=>Lt(e)??``,Vt=e=>{let t=e.getTitle(),n=[t?`"${B(t)}"`:`no title`],r=e.getNumberFormat();return r&&r!==`General`&&n.push(`format ${r}`),`${e.getKind()} (${n.join(`, `)})`};function Ht(e,t){let n=Lt(t);e.fact(`Type: chart`+(n?` — ${n}`:``));let r=t.getChartTitle();e.fact(`Title: `+(r?`"${B(r)}"`:`(none)`));let i=t.getSeries(),a=t.getPivotSource();if(a)e.fact(`Series (${i.length}): from pivot table ${a}`);else if(i.length>0){let t=Pt(i);if(t){let n=[`values ${t.values}${t.by?` by ${t.by}`:``}`];t.names&&n.push(`${i.length===1?`name`:`names`} ${t.names}`),t.categories&&n.push(`categories ${t.categories}`),e.fact(`Series (${i.length}): ${n.join(` · `)}`)}else(function(e,t){let n=t.slice(0,c(t.length,12)),r=n.map(e=>{let t=Mt(e.getValuesRange(),e.getValuesFormula())??`(no values)`,n=Mt(e.getCategoriesRange(),e.getCategoriesFormula()),r=[`values ${t}`];n&&r.push(`categories ${n}`);let i=Mt(e.getNameRange(),e.getNameFormula());i&&r.push(`name ${i}`);let a=e.getName();return{name:a?B(a):`(unnamed)`,type:e.isSecondaryAxis()?`${e.getChartType()} · secondary axis`:e.getChartType(),source:r.join(` · `)}});e.fact(`Series (${t.length}):`);let i=Math.max(...r.map(e=>e.name.length)),a=Math.max(...r.map(e=>e.type.length));for(let t of r)e.text(` ${t.name.padEnd(i)} ${t.type.padEnd(a)} ${t.source}`);n.length<t.length&&e.text(` …and ${t.length-n.length} more · getContent().getSeries() on this movable lists every one`)})(e,i)}let o=t.getAxes();o.length>0&&e.fact(`Axes: ${o.map(Vt).join(` · `)}`)}var Ut=(e,t)=>e.colStart<=t.colEnd&&t.colStart<=e.colEnd&&e.rowStart<=t.rowEnd&&t.rowStart<=e.rowEnd,Wt=e=>{let t=e.movable.getRange();return`${jt(t.getSheet(),t.getCoords())} "${e.movable.getContent().getName?.()||`(unnamed)`}"${e.direct?``:` (through its dependents)`}`},Gt=(e,t,n)=>{let r=e.replace(/\r\n?|\n/g,` ⏎ `);if(t===null||r.length<=t)return`"${r}"`;let i=r.charCodeAt(t-1),a=i>=55296&&i<=56319?t-1:t,o=`(+${r.length-a} chars)`;return`"${r.slice(0,a)}…" ${n?`${o} · full: ${n}`:o}`},Kt=e=>e.paragraphs.map(e=>e.runs.map(e=>e.text??``).join(``)).join(`
|
|
4
|
+
`).trim(),qt=t=>{if(t.type===e.IShape.Type.Group)return`group`;if(t.type===e.IShape.Type.Picture)return`picture`;let n=t.geometry;return typeof n==`string`?n:n?`custom`:`rect`},Jt=(e,t)=>`${e} ${t}${e===1?``:`s`}`,Yt=(t,n)=>{switch(t.type){case e.IFill.Type.None:return`none`;case e.IFill.Type.Solid:return String(t.color??`solid`);case e.IFill.Type.Gradient:{let e=t,n=(e.stops??[]).map(e=>String(typeof e==`object`&&e&&`color`in e?e.color:e)),r=e.angle===void 0?``:` at ${e.angle}°`;return`${e.gradientType??`linear`} gradient${n.length?` ${n.join(` → `)}`:``}${r}`}case e.IFill.Type.Pattern:{let e=t,n=[e.foreground,e.background].filter(e=>e!==void 0).join(` on `);return`pattern ${e.patternType??``}${n?` ${n}`:``}`.replace(/ +/g,` `).trim()}case e.IFill.Type.Image:{let e=t,r=e.resId===void 0?null:n.getResource(e.resId),i=[e.tile?`tiled`:null,e.sourceRect?`cropped`:null].filter(Boolean);return`image ${r?.getName()||`(no image)`}${i.length?`, ${i.join(`, `)}`:``}`}default:return String(t.type)}},Xt=(t,n)=>{if(t.style===null)return`none`;let r=t.style?.[n]??e.ShapeStyleUtils.defaultStyleRefs(t)[n];return!r||r.index<=0?`none`:`theme style ${r.index}${r.color?`, ${r.color}`:``}`},Zt=(t,n,r)=>{if(!t||t===e.IStroke.LineEndType.None)return null;let i=[n&&n!==e.IStroke.LineEndSize.Medium?`wide ${n}`:null,r&&r!==e.IStroke.LineEndSize.Medium?`long ${r}`:null].filter(Boolean);return i.length?`${t} (${i.join(`, `)})`:t},Qt={top:`top`,center:`middle`,bottom:`bottom`,justify:`justified`,distributed:`distributed`},$t=e=>{if(typeof e==`string`)return e;let t=e.address??e.action??`(no address)`;return e.screenTip?`${t} — "${e.screenTip}"`:t},en=(e,t)=>{if(!e||!e.start&&!e.end)return null;let n=(e,n)=>{if(!n)return null;let r=t().get(n.id);return`${e} → ${r?`"${r}"`:`shape id ${n.id} (not on this sheet)`} (site ${n.index})`};return[n(`start`,e.start),n(`end`,e.end)].filter(Boolean).join(` · `)},tn=(t,n,r,i,a)=>{for(let o of n){let n=[qt(o),o.name||`(unnamed)`];if(o.type===e.IShape.Type.Picture){let e=o.fill?.resId;n.push(e===void 0?`(no image)`:r.getResource(e)?.getName()||`(no image)`)}if(o.text){let e=Kt(o.text);e&&n.push(Gt(e,120,``))}let s=en(o.connectorEnds,i);s&&n.push(s),t.text(`${` `.repeat(a+2)}${n.join(` · `)}`),o.children?.length&&tn(t,o.children,r,i,a+1)}};function nn(t,n){let r=n.toJSON()??{},i=r.type===e.IShape.Type.Group,a=null,o=()=>a??=(e=>{let t=new Map;if(!e)return t;let n=(e,r)=>{e.sourceId!==void 0&&t.set(e.sourceId,r||`(unnamed ${qt(e)})`);for(let t of e.children??[])n(t,t.name)};for(let t of e.getRange().getSheet().getMovables().getItems({type:`shape`})){let e=t.getContent(),r=e.toJSON?.();r&&n(r,e.getName())}return t})(n.getMovable());t.fact(`Shape: ${(t=>{let n=qt(t),r=[];t.type===e.IShape.Type.Group&&r.push(Jt(t.children?.length??0,`member`));let i=t.geometry;return i&&typeof i==`object`&&(r.push(Jt(i.paths.length,`path`)),i.ah?.length&&r.push(Jt(i.ah.length,`handle`))),t.type===e.IShape.Type.Connector&&r.push(`connector`),t.textBox&&r.push(`text box`),r.length>0?`${n} — ${r.join(`, `)}`:n})(r)}`);let s=(e=>{let t=Object.entries(e);return t.length===0?null:t.map(([e,t])=>`${e} ${t}`).join(` · `)})(n.getAdjustments());if(s&&t.fact(`Adjustments: ${s} — the rest at the preset's defaults`),!i){let i=n.getTextFrame();i&&t.fact(`Text: ${Gt(i.getText(),null,``)}`);let a=(t=>{if(!t)return null;let n=[];return t.anchor&&n.push(Qt[t.anchor]??t.anchor),t.anchorCenter&&n.push(`centered`),t.wrap===`none`&&n.push(`no wrap`),t.verticalOverflow!==e.ITextFrame.Overflow.Visible&&t.horizontalOverflow!==e.ITextFrame.Overflow.Visible||n.push(`text may overflow the shape`),t.autoFit===`shape`&&n.push(`shape grows to fit text`),t.autoFit===`normal`&&n.push(`text shrinks to fit`+(t.fontScale===void 0?``:` (${t.fontScale}%)`)),t.vertical&&t.vertical!==e.ITextFrame.WritingMode.Horizontal&&n.push(`vertical (${t.vertical})`),t.columns&&t.columns>1&&n.push(`${t.columns} columns`),t.warp&&n.push(`warped (${t.warp.preset})`),n.length?n.join(` · `):null})(r.text?.body);a&&t.fact(`Text Layout: ${a}`)}r.textLink&&t.fact(`Text Link: ${r.textLink} — the text shows this cell's value`),i&&!r.fill||t.fact(`Fill: ${r.fill?Yt(r.fill,n):Xt(r,`fill`)}`),i&&!r.stroke||t.fact(`Line: ${((t,n)=>{let r=t.stroke,i=Xt(t,`stroke`);if(!r)return i;if(r.fill?.type===e.IFill.Type.None)return`none`;let a=[];typeof r.width==`number`&&a.push(`${r.width} pt`),a.push(r.fill?Yt(r.fill,n):`color from ${i}`),r.dash!==void 0&&r.dash!==e.IStroke.StrokeStyle.Solid&&a.push(`dash ${Array.isArray(r.dash)?r.dash.join(` `):r.dash}`),r.compound&&r.compound!==e.IStroke.Compound.Single&&a.push(`compound ${r.compound}`);let o=Zt(r.headType,r.headWidth,r.headLength);o&&a.push(`head ${o}`);let s=Zt(r.tailType,r.tailWidth,r.tailLength);return s&&a.push(`tail ${s}`),a.join(` · `)})(r,n)}`),r.effects&&t.fact(`Effects: ${r.effects.length?r.effects.map(e=>e.type).join(`, `):`none — the theme style's are turned off`}`),(r.scene3d||r.shape3d)&&t.fact(`3-D: yes`);let c=[r.flipH?`horizontal`:null,r.flipV?`vertical`:null].filter(Boolean);c.length&&t.fact(`Flip: ${c.join(`, `)}`);let l=en(r.connectorEnds,o);l&&t.fact(`Connected: ${l}`),r.title&&t.fact(`Title: ${r.title}`),r.hyperlink&&t.fact(`Hyperlink: ${$t(r.hyperlink)}`),r.hoverHyperlink&&t.fact(`Hover Hyperlink: ${$t(r.hoverHyperlink)}`),r.macro&&t.fact(`Macro: ${r.macro}`);let u=Object.entries(r.locks??{}).filter(([,e])=>e).map(([e])=>e);u.length&&t.fact(`Locks: ${u.join(`, `)}`),i&&r.children?.length&&(t.fact(`Members: ${r.children.length}, in z-order`),tn(t,r.children,n,o,0))}var rn=e=>e.toJSON()?.rotation??0,an=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,on=e=>e.replace(/[\r\n]+/g,` `).trim(),sn=t=>{let n=t.getRange();return e.AddressUtils.rangeToString(n.getCoords())??n.toString()},cn=({movable:e,text:t})=>Gt(t,300,(e=>`${L(e.getRange())}.getRange(${JSON.stringify(sn(e))}).getMovables()`)(e)),ln=e=>{let t=e.getContent();return typeof t.getTextFrame==`function`?t.getTextFrame()?.getText()??``:null};function un(e){let t=[];for(let n of e){let e=ln(n)??``;e.trim()!==``&&t.push({movable:n,text:e})}return t.sort((e,t)=>{let n=e.movable.getRange().getCoords(),r=t.movable.getRange().getCoords();return n.rowStart-r.rowStart||n.colStart-r.colStart})}var dn=e=>e.getType()===`picture`&&e.getResource?.()?.getName()||null,fn=e=>{let t=e.getContent().getName?.()||`(unnamed)`,n=e.getContent().getDescription(),r=z(e);if(r)return an([Rt(r),n?on(n):null,t].filter(Boolean).join(` · `),140);let i=e.getContent(),a=[],o=dn(i);return o&&a.push(o),n&&a.push(on(n)),an(a.length>0?`${t} — ${a.join(` · `)}`:t,90)},pn=e=>{let t=e.getContent().getName?.()||`(unnamed)`,n=e.getContent().getDescription();return an(n?`${t} — ${on(n)}`:t,90)},mn=new Map([[`chart`,`Charts`],[`shape`,`Shapes`],[`picture`,`Pictures`],[`slicer`,`Slicers`]]),hn=e=>mn.get(e)??`${e.charAt(0).toUpperCase()}${e.slice(1)}s`;function gn(e){let t=new Map;for(let n of e){let e=n.getContent().getType();if(e===`note`)continue;let r=t.get(e);r?r.push(n):t.set(e,[n])}let n=new Map;for(let e of mn.keys()){let r=t.get(e);r&&n.set(e,r)}for(let[e,r]of t)n.set(e,r);return n}function _n(e,t){for(let[n,r]of gn(t))vn(e,n,r)}function vn(e,t,n){let r=un(n),i=new Map(r.map(e=>[e.movable,e])),a=[...r.map(e=>e.movable),...n.filter(e=>!i.has(e))],o=a.slice(0,c(a.length,50)),s=o.map(e=>{let t=i.get(e),n=z(e);return{address:sn(e),preset:n?Bt(n):(r=e.getContent(),r.getShapeType?.()??``),summary:n?pn(e):fn(e),details:n?zt(n):[],text:t?cn(t):``,hidden:e.isHidden()?` (hidden)`:``};var r});e.h2(`${hn(t)} (${n.length}${r.length>0?` · ${r.length} with text`:``})`);let l=Math.max(...s.map(e=>e.address.length)),u=Math.max(...s.map(e=>e.preset.length)),d=Math.min(40,Math.max(0,...s.filter(e=>e.text).map(e=>e.summary.length)));for(let t of s){let n=u>0?`${t.preset.padEnd(u)} `:``,r=t.text?`${t.summary.padEnd(d)} ${t.text}`:t.summary;e.text(` ${t.address.padEnd(l)} ${n}${r}${t.hidden}`.trimEnd());let i=Math.max(10,...t.details.map(([e])=>e.length+2));for(let[n,r]of t.details)e.text(` ${n.padEnd(i)}${r}`)}if(o.length<a.length){let r=`${L(n[0].getRange())}.getMovables().getItems({ type: ${JSON.stringify(t)} })`;e.text(` …and ${a.length-o.length} more · ${r} reports every one in full`)}e.blank()}function yn(e){return Sn(e,`Movable`)}function bn(e){let t=e.getMovable();if(t)return Sn(t,`Shape`);let n=new N;return n.h1(`Shape — ${e.getName()||`(unnamed)`}`),n.blank(),nn(n,e),n.toLines().join(`
|
|
5
|
+
`).trimEnd()}var xn=e=>{let t=e.getContent();return!0===t?.isIShape?t:null};function Sn(t,n){let r=new N,i=t.getRange(),a=t.getContent(),o=a.getType(),s=xn(t);r.h1(`${n} — ${ut(i)}`),r.blank(),r.fact(`Name: ${t.getContent().getName?.()||`(unnamed)`}`);let c=z(t);c?Ht(r,c):r.fact(`Type: ${o}`);let l=dn(a);l&&r.fact(`Content: ${l}`),s&&nn(r,s);let u=t.getContent().getDescription();u&&r.fact(`Alt Text: ${on(u)}`),r.fact(`Anchor: ${F(i)}, ${(t=>{switch(t){case e.IAnchored.Type.Absolute:return`absolute — stays put when rows or columns move`;case e.IAnchored.Type.OneCell:return`oneCell — moves with the cells, keeps its size`;default:return`twoCell — moves and resizes with the cells`}})(t.getAnchorType?.())}`),r.fact(`Bounds: ${(e=>{let t=e.getBounds();if(!t)return`not laid out`;let n=e=>Math.round(e);return`${n(t.width)}×${n(t.height)} px at (${n(t.x)}, ${n(t.y)})`})(t)}`),t.isHidden()&&r.fact(`Hidden: true — this object is not visible in the UI`);let d=t.getRotation()||(s?rn(s):0);return d!==0&&r.fact(`Rotation: ${d}°`),r.fact(`Z-Order: ${t.getZIndex()}`),r.blank(),r.text(`Sheet: ${I(i.getSheet().getName())}`),r.toLines().join(`
|
|
6
|
+
`).trimEnd()}var Cn=e=>e.getVisibility()===`visible`,wn=(e,t,n)=>{let r=e.getSheets().getItems({visibility:`veryHidden`}),i=t?.trim();if(!i)return r.filter(e=>n||Cn(e)).map(e=>({sheet:e,address:null}));let a=/^'(.*)'!(.+)$/.exec(i)??/^([^!]+)!(.+)$/.exec(i);if(a){let[,e,t]=a,n=r.find(t=>t.getName()===e);if(!n)throw Error(`Sheet not found: ${e}`);return[{sheet:n,address:t}]}let o=r.find(e=>e.getName()===i);if(o)return[{sheet:o,address:null}];if(/[*?]/.test(i)){let e=(e=>{let t=e.replace(/[.*+?^${}()|[\]\\]/g,e=>e===`*`?`.*`:e===`?`?`.`:`\\${e}`);return RegExp(`^${t}$`)})(i),t=r.filter(t=>e.test(t.getName())&&(n||Cn(t)));if(t.length===0)throw Error(`No sheets match ${JSON.stringify(i)}. Sheets: ${r.map(e=>e.getName()).join(`, `)}`);return t.map(e=>({sheet:e,address:null}))}let s=r.filter(e=>n||Cn(e));try{s[0]?.getRange(i)}catch{throw Error(`Unknown scope ${JSON.stringify(i)}: not a sheet name or a range. Sheets: ${r.map(e=>e.getName()).join(`, `)}`)}return s.map(e=>({sheet:e,address:i}))},Tn=(e,n)=>{switch(n){case`display`:return i(e,t.Mode.Display);case`value`:return i(e,t.Mode.Value);case`formula`:{let t=e.getFormulaText();return t?{match:t,display:t}:null}case`hyperlink`:{let t=e.getHyperlink()?.getAddress()??null;return t?{match:t,display:t}:null}case`numberFormat`:{let t=e.getStyle().getNumberFormat();return t&&t!==`General`?{match:t,display:t}:null}default:return null}},En=[`hyperlink`,`numberFormat`],V=(e,t)=>t&&t.trim()!==``?[{field:e,text:{match:t,display:t}}]:[],Dn=e=>[...V(`comment`,e.getContent()),...e.getReplies().flatMap(e=>V(`comment`,e.getContent()))],On=(e,t)=>{let n=z(e);if(n)return t.includes(`chart`)?[...V(`chart`,n.getChartTitle()),...n.getAxes().flatMap(e=>V(`chart`,e.getTitle())),...n.getSeries().flatMap(e=>e.getNameFormula()===null?V(`chart`,e.getName()):[]),...V(`chart`,e.getContent().getDescription())]:[];let r=ln(e);return r!==null&&t.includes(`shape`)?[...V(`shape`,r),...V(`shape`,e.getContent().getDescription())]:[]},kn=e=>{let t=e.isIFormula?`=${e.getExpression()}`:null,n=t??e.getRanges?.()?.getAddress()??e.getName();return[{field:`name`,text:{match:e.getName(),display:n}},...t?V(`name`,t):[],...V(`name`,e.getComment())]},An=(e,t)=>e.colStart<=t.colEnd&&t.colStart<=e.colEnd&&e.rowStart<=t.rowEnd&&t.rowStart<=e.rowEnd,jn=(e,t)=>{let n=e.getRanges?.()??null;return t.some(({sheet:t,address:r})=>{if(r===null&&e.getScope()===t.getName())return!0;let i=r===null?null:t.getRange(r).getCoords();for(let e=0;e<(n?.length??0);e++){let r=n.at(e);if(r.getSheet()===t&&(!i||An(r.getCoords(),i)))return!0}return!1})},Mn=(e,t)=>e.rowStart-t.rowStart||e.colStart-t.colStart,Nn=(e,t,n)=>{let r=null,i=e=>({range:`${t}!${e.getRange().toString()}`,table:e.getName()});return{resolve(a,o){let s=(e=>e.getTable())(a);if(e===`table`)return s?i(s):void 0;if(r===null){r=[];for(let e of n.getRegions()){let n=e.getCoords();n.rowStart===n.rowEnd&&n.colStart===n.colEnd||r.push({coords:n,address:`${t}!${e.toString()}`})}}let c=r.find(({coords:e})=>o.rowIndex>=e.rowStart&&o.rowIndex<=e.rowEnd&&o.colIndex>=e.colStart&&o.colIndex<=e.colEnd);return c?{range:c.address,...s?{table:s.getName()}:{}}:s?i(s):void 0}}};async function Pn(t,n){if(!n.pattern)throw Error(`grep requires a pattern`);let r=n.fields?.length?n.fields:s,i=n.output??`content`,a=n.maxCount??200,o=!0===n.invert,c=!0===n.hidden,l=(e=>{if(e===void 0||!1===e)return null;if(!0===e)return`contentful`;if(e===`contentful`||e===`table`)return e;throw Error(`Invalid context ${JSON.stringify(e)}: expected 'contentful' or 'table'. Context is the enclosing block, not a line count — a grid has no ±N lines.`)})(n.context),u=(e=>{let t=e.fixedStrings?(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`))(e.pattern):e.pattern;e.word&&(t=`(?<!\\w)(?:${t})(?!\\w)`);let n=e.ignoreCase?`iu`:`u`;try{return new RegExp(t,n)}catch{try{return new RegExp(t,n.replace(`u`,``))}catch(t){throw Error(`Invalid regex ${JSON.stringify(e.pattern)}: ${t instanceof Error?t.message:String(t)}. Use fixedStrings (-F) to search for the literal text.`)}}})(n),d=wn(t,n.scope,c),f=!r.some(e=>En.includes(e)),p=r.includes(`display`)&&r.includes(`value`),m=i===`content`||i===`addresses`,h=[],g=[],_=0,v=0,y=0,b=!1,x=e=>{let t=e.filter((t,n)=>u.test(t.text.match)&&e.findIndex(e=>e.field===t.field&&e.text.display===t.text.display&&u.test(e.text.match))===n);return o?t.length===0&&e.length>0?[e[0]]:null:t.length===0?null:i===`addresses`?t.slice(0,1):t},S=(e,t,n,r,i)=>{if(a>0&&_+v>=a)return b=!0,!1;if(e===`cell`?_++:v++,m)for(let e of r)h.push({sheet:t,address:n,field:e.field,text:e.text.display,...i?{context:i}:{}});return!0};for(let{sheet:t,address:n}of d){if(b)continue;let a=t.getName();y++,await t.getCalculation().ready();let o=n===null?t.getUsedRange():t.getRange(n),s=o&&l&&i===`content`?Nn(l,a,o):null,u={...n===null?{}:{address:n},...c?{}:{ignoreHidden:!0}},d=new Map;if(r.includes(`comment`))for(let e of t.getComments().getItems(u)){let t=e.getRange().getCoords();d.set(`${t.rowStart}:${t.colStart}`,e)}let m=0;o?.forEach((e,t)=>{if(f&&e==null)return;let n=t.getCell(),i=t.getCoords(),o=[],c;for(let e of r){if(e===`comment`){let e=`${i.rowIndex}:${i.colIndex}`,t=d.get(e);t&&(o.push(...Dn(t)),d.delete(e));continue}let t=Tn(n,e);e===`display`&&(c=t?.match??null),t!==null&&(e===`value`&&p&&(c===void 0&&(c=Tn(n,`display`)?.match??null),t.match===c)||o.push({field:e,text:t}))}let l=x(o);if(!l)return;let u=s?.resolve(n,i);if(!S(`cell`,a,t.getAddress(),l,u))return{break:!0};m++},c?void 0:{ignoreHidden:!0});let h=[...d.values()].map(e=>({comment:e,at:e.getRange().getCoords()})).sort((e,t)=>Mn(e.at,t.at));for(let{comment:t,at:n}of h){if(b)break;let r=x(Dn(t));if(!r)continue;let i=s?.resolve(t.getRange().getCell(),{rowIndex:n.rowStart,colIndex:n.colStart});S(`cell`,a,e.AddressUtils.rangeToString(n)??t.getRange().toString(),r,i)&&m++}let _=0;if(!b&&(r.includes(`shape`)||r.includes(`chart`))){let n=t.getMovables().getItems(u).filter(e=>e.getContent().getType()!==`note`).filter(e=>c||!e.isHidden()).map(e=>({movable:e,at:e.getRange().getCoords()})).sort((e,t)=>Mn(e.at,t.at));for(let{movable:t,at:i}of n){let n=x(On(t,r));if(n){if(!S(`object`,a,e.AddressUtils.rangeToString(i)??t.getRange().toString(),n))break;_++}}}(m>0||_>0)&&g.push({sheet:a,cells:m,objects:_})}if(!b&&r.includes(`name`)){let e=!!n.scope?.trim(),r=t.getNames().getItems(c?{includeHidden:!0}:void 0)??[];for(let t of r){if(e&&!jn(t,d))continue;let n=x(kn(t));if(n&&!S(`object`,t.getScope()??``,t.getName(),n))break}}return{pattern:n.pattern,fields:r,scope:n.scope?.trim()||`workbook`,matches:h,cellCount:_,objectCount:v,sheets:g,sheetsSearched:y,sheetsMatched:g.length,truncated:b,output:i}}var Fn=e=>{let t=e.replace(/\s+/g,` `).trim();return t.length>120?`${t.slice(0,119)}…`:t},In=e=>e.sheet?`${e.sheet}!${e.address}`:e.address,Ln=(e,t)=>`${e} ${t}${e===1?``:`s`}`,Rn=(e,t)=>t>0?`${Ln(e,`cell`)} · ${Ln(t,`object`)}`:Ln(e,`cell`),zn=(e,t,n,r)=>{let i=t.map(e=>r?In(e):e.address),a=Math.max(...i.map(e=>e.length)),o=Math.max(...t.map(e=>e.field.length));for(let r=0;r<t.length;r++){let s=t[r];e.push(`${n}${i[r].padEnd(a)} ${s.field.padEnd(o)} ${Fn(s.text)}`)}};function Bn(e){let{pattern:t,fields:n,scope:r,matches:i,cellCount:a,objectCount:o,sheetsSearched:s,sheetsMatched:c}=e,l=[`grep "${t}" · ${r} · fields ${n.join(`,`)} · ${Rn(a,o)} in ${c} of ${s} ${s===1?`sheet`:`sheets`}`];if(e.output===`count`){for(let t of e.sheets)l.push(` ${t.sheet}: ${t.objects>0?Rn(t.cells,t.objects):t.cells}`);let t=o-e.sheets.reduce((e,t)=>e+t.objects,0);t>0&&l.push(` names: ${t}`)}else if(e.output===`sheets`){for(let t of e.sheets)l.push(` ${t.sheet}`);e.sheets.length===0&&l.push(o>0?` no sheets · names only`:` no matches`)}else if(i.length===0)l.push(` no matches`);else if(e.output===`addresses`)for(let e of i)l.push(` ${In(e)}`);else{let e=[],t=new Map;for(let n of i){let r=n.context?.range??``,i=t.get(r);i||(i={key:r,heading:n.context?n.context.table?`${n.context.range} · ${n.context.table}`:n.context.range:null,rows:[]},t.set(r,i),e.push(i)),i.rows.push(n)}for(let t of e)t.heading?(l.push(` ${t.heading}`),zn(l,t.rows,` `,!1)):zn(l,t.rows,` `,!0)}return e.truncated&&l.push(` …truncated at ${Rn(a,o)} · narrow the pattern, or scope the search to one sheet or range`),l.join(`
|
|
7
|
+
`)}var Vn={name:`grep`,description:`Search a workbook's text by pattern: cell contents, and the text that is in no cell — comments, shapes, charts and defined names. Returns grid-anchored matches, each tagged with the layer it matched. Selection by attribute (fills, formats, features) is the regions read, not grep.`,params:[{name:`pattern`,type:`string`,description:`The regular expression to search for (literal with fixedStrings).`,required:!0,positional:0},{name:`fields`,type:`enum[]`,values:o,defaultValue:s,description:`Layers to search: display (number format applied), value (the stored scalar, what getValue() returns — 0.4 behind 40%, dates as serials; duplicate of display suppressed per cell), formula, hyperlink, numberFormat (the format code, e.g. "0.00%"), comment (comments, notes and replies), shape (text on a shape, alt text), chart (title, axis titles, literal series names, alt text), name (defined names and tables: the name, what it refers to, its comment).`},{name:`fixedStrings`,type:`boolean`,alias:`F`,defaultValue:!1,description:`Treat the pattern as a literal string, not a regular expression.`},{name:`ignoreCase`,type:`boolean`,alias:`i`,defaultValue:!1,description:`Case-insensitive matching.`},{name:`word`,type:`boolean`,alias:`w`,defaultValue:!1,description:`Require the match to fall on word boundaries (text edges count as edges).`},{name:`invert`,type:`boolean`,alias:`v`,defaultValue:!1,description:`Report cells and objects where no requested field matched. Only those with text in a requested field are considered — blanks are not findings.`},{name:`scope`,type:`string`,description:`Where to search: a sheet name (globs allowed: "Q*"), a sheet-qualified range (Sheet1!A1:D9), or a bare range applied to every sheet. Defaults to every used range.`},{name:`hidden`,type:`boolean`,defaultValue:!1,description:`Search hidden rows, columns and sheets, which are excluded by default. Naming a hidden sheet in scope always searches it.`},{name:`context`,type:`enum`,values:[`contentful`,`table`],alias:`C`,valueOptional:!0,description:`Annotate and group matches by the block they sit in: contentful (the uniform data region; bare -C means this) or table (enclosing table only). Not a line count — a grid has no ±N lines.`},{name:`maxCount`,type:`number`,alias:`m`,defaultValue:200,description:`Stop after this many matching cells and objects (0 = unlimited). Truncation is always reported, and only when a further match actually exists.`},{name:`output`,type:`enum`,values:[`content`,`addresses`,`count`,`sheets`],defaultValue:`content`,description:`What to return: content (address, layer and text), addresses (one per matched cell), count (per sheet), or sheets (names with a match).`}],run:Pn,render:Bn},Hn=[`IWorkbook`,`ISheet`,`ICellRange`,`ICell`,`IRange`,`ITable`,`IStyle`,`IScript.ScriptContext`],Un=e=>e.slice(e.lastIndexOf(`.`)+1);function H(e,t){if(e.types[t])return t;let n=Object.keys(e.types),r=t.toLowerCase(),i=n.filter(e=>e.toLowerCase()===r);if(i.length===1)return i[0];if(t.includes(`.`))return null;let a=n.filter(e=>Un(e).toLowerCase()===r);return a.length===1?a[0]:null}function Wn(e,t,n){let r=n.replace(/<[\s\S]*$/,``).trim(),i=t.split(`.`);for(let t=i.length-1;t>=0;t--){let n=[...i.slice(0,t),r].join(`.`);if(e.types[n])return n}return null}function Gn(e,t,n,r=new Set){if(r.has(t))return null;r.add(t);let i=e.types[t];if(!i)return null;let a=(i.members??[]).filter(n);if(a.length>0)return{key:t,members:a};for(let a of i.extends??[]){let i=Wn(e,t,a),o=i?Gn(e,i,n,r):null;if(o)return o}return null}function Kn(e,t,n){let r=e.types[t],i=(r.extends??[]).map(n=>{let r=Wn(e,t,n);return{text:n,key:r,memberCount:r?e.types[r].members?.length??0:0}}),a=r.members??[],o=n?.toLowerCase();return{kind:`type`,key:t,entry:r,bases:i,members:o?a.filter(e=>e.name.toLowerCase().includes(o)):a,...n?{filter:n}:{}}}function qn(e,t,n){let r=e=>{let r=t(e).toLowerCase();return r===n?0:r.startsWith(n)?1:2};return e.map((e,t)=>({item:e,order:t,score:r(e)})).sort((e,t)=>e.score-t.score||e.order-t.order).map(e=>e.item)}function Jn(e,t){let n=function(e){return e.trim().replace(/^SheetXL\./,``).replace(/\(\)$/,``).replace(/#/g,`.`)}(t??``);if(!n){let t=Hn.filter(t=>e.types[t]).map(t=>({key:t,entry:e.types[t]}));return{kind:`overview`,total:Object.keys(e.types).length,entryPoints:t}}let r=H(e,n);if(r)return Kn(e,r);let i=n.lastIndexOf(`.`);if(i>0){let t=H(e,n.slice(0,i)),r=n.slice(i+1);if(t&&r){let n=r.toLowerCase(),i=Gn(e,t,e=>e.name===r)??Gn(e,t,e=>e.name.toLowerCase()===n);if(i)return{kind:`member`,key:t,declaredOn:i.key,members:i.members};let a=Kn(e,t,r);if(a.members.length>0)return a}}return function(e,t){let n=t.toLowerCase(),r=[],i=[];for(let[t,a]of Object.entries(e.types)){Un(t).toLowerCase().includes(n)&&r.push(t);for(let e of a.members??[])e.name.toLowerCase().includes(n)&&i.push({key:t,member:e})}let a=qn(r,Un,n),o=qn(i,e=>e.member.name,n);return{kind:`search`,query:t,types:a.slice(0,20),members:o.slice(0,40),omitted:Math.max(0,a.length-20)+Math.max(0,o.length-40)}}(e,i>0?n.slice(i+1):n)}var Yn=[{match:/^(get|set)?(number)?(format|numfmt)s?$/i,relies:[`IStyle`,`setNumberFormat`],hint:"Formatting lives on the style: `getStyle().setNumberFormat('0.00%')`, `getStyle().getNumberFormat()`."}];function Xn(e,t){let n=[],r=new Set,i=new Set,a=t=>{if(i.has(t))return;i.add(t);let o=e.types[t];if(o){for(let e of o.members??[])r.has(e.name)||(r.add(e.name),n.push(e));for(let n of o.extends??[]){let r=Wn(e,t,n);r&&a(r)}}};return a(t),n}function Zn(e,t){let n=e.toLowerCase(),r=t.toLowerCase();if(n===r)return 0;if(n.startsWith(r)||r.startsWith(n))return 1;let i=function(e,t){let n=Array.from({length:t.length+1},(e,t)=>t);for(let r=1;r<=e.length;r++){let i=n[0];n[0]=r;for(let a=1;a<=t.length;a++){let o=n[a];n[a]=Math.min(n[a]+1,n[a-1]+1,i+(e[r-1]===t[a-1]?0:1)),i=o}}return n[t.length]}(n,r);return i<=Math.max(2,Math.floor(.3*n.length))?1+i:null}var Qn=(e,t)=>`${t?`${t}.`:``}${e.signature.replace(/;$/,``)}${e.summary?` — ${e.summary}`:``}`,U=(e,t,n=`${t}s`)=>`${e.toLocaleString(`en-US`)} ${e===1?t:n}`;function $n(e,t){let n=t?`${t} · `:``,r=e.summary?` — ${e.summary}`:``,i=e.deprecated?` (deprecated)`:``;return`- ${n}\`${a=e.signature,a.replace(/;$/,``)}\`${i}${r}`;var a}function er(e,t){let n=t?.command??`api`;switch(e.kind){case`overview`:return function(e,t){let n=[`# SheetXL scripting API — ${U(e.total,`name`)}`,``,`Where a script starts:`];for(let{key:t,entry:r}of e.entryPoints){let e=r.members?` (${U(r.members.length,`member`)})`:``;n.push(`- \`${t}\`${e}${r.summary?` — ${r.summary}`:``}`)}return n.push(``,`\`${t} <Type>\` lists what you can call on a type, one line per member.`,`\`${t} <Type>.<member>\` prints that member's full documentation.`,`\`${t} <word>\` searches type and member names.`,``,"Every type answers, not only the ones above. In a script each name is written `SheetXL.<Type>`."),n.join(`
|
|
8
|
+
`)}(e,n);case`type`:return function(e,t){let{key:n,entry:r,members:i}=e,a=r.members?.length??0,o=[r.kind+(r.typeParams??``)];r.members&&o.push(U(a,`member`)),r.deprecated&&o.push(`deprecated`);let s=[`# ${n} — ${o.join(` · `)}`];if(r.summary&&s.push(r.summary),r.signature&&s.push(``,"```ts",r.signature,"```"),e.bases.length>0){s.push(``);for(let n of e.bases)s.push(n.key?`Also has everything on \`${n.text}\` (${U(n.memberCount,`member`)}): \`${t} ${n.key}\``:`Extends \`${n.text}\`.`)}if(r.members){s.push(``),e.filter&&s.push(`${U(i.length,`member`)} of ${a} matching '${e.filter}':`);for(let e of i)s.push($n(e))}return r.nested&&r.nested.length>0&&!e.filter&&s.push(``,`Nested types — \`${t} ${n}.<name>\`: ${r.nested.join(`, `)}`),s.push(``,r.members?`Full documentation for one member: \`${t} ${n}.<member>\` · scripting.d.ts:${r.lines[0]}-${r.lines[1]}`:`scripting.d.ts:${r.lines[0]}-${r.lines[1]}`),s.join(`
|
|
7
9
|
`)}(e,n);case`member`:return function(e,t){let n=e.members[0].name,r=[`# ${e.key}.${n}`];return e.declaredOn!==e.key&&r.push(`Inherited from \`${e.declaredOn}\`.`),e.members.length>1&&r.push(`${e.members.length} overloads.`),e.members.forEach((t,n)=>{let i=e.sources?.[n]??`${t.summary?`/** ${t.summary} */\n`:``}${t.signature}`;r.push(``,"```ts",i,"```",`scripting.d.ts:${t.lines[0]}-${t.lines[1]}`)}),r.push(``,`Everything on the type: \`${t} ${e.declaredOn}\``),r.join(`
|
|
8
|
-
`)}(e,n);case`search`:return function(e,t){if(e.types.length===0&&e.members.length===0)return`No type or member name contains '${e.query}'. \`${t}\` with no name lists where to start.`;let n=[`# '${e.query}' in the scripting API`];if(e.types.length>0){n.push(``,`Types:`);for(let t of e.types)n.push(`- \`${t}\``)}if(e.members.length>0){n.push(``,`Members:`);for(let{key:t,member:r}of e.members)n.push(
|
|
9
|
-
`)}(e,n)}}async function
|
|
10
|
-
`)}(t,e.lines[0],e.lines[1]))}catch{}return n}var Bn={name:`api`,description:"Look up the scripting API — what you can call on a type, without reading the type definitions. `ICellRange` lists its members, one line each (signature + summary); `ICellRange.setValues` prints that member's full documentation; any other word searches type and member names; no name lists where to start. Answers come from the same declarations `run` type-checks against, so a member listed here exists.",params:[{name:`name`,type:`string`,description:"A type (`ICellRange`), a member (`ICellRange.setValues`), or a word to search for. Omit for the overview. A leading `SheetXL.` is accepted.",positional:0}],run:e=>zn(e?.name),render:Rn},G=e.ICellRange.Feature;async function Vn(e,t,n,r){await Hn(e,t,`precedents`,n,r),await Hn(e,t,`dependents`,n,r)}async function Hn(n,r,a,o,s){let c=a===`precedents`?`Precedents`:`Dependents`,l=await(a===`precedents`?r.getPrecedents():r.getDependents()),u=a===`dependents`&&s?.subject?function(t,n){let r=t.getSheet(),i=r.getWorkbook()?.getSheets().getItems({visibility:e.ISheet.Visibility.VeryHidden})??[r],a=new Map;for(let e=0;e<(n?.length??0);e++){let t=n.at(e);if(t.isINamedRange)continue;let r=a.get(t.getSheet());r?r.push(t.getCoords()):a.set(t.getSheet(),[t.getCoords()])}let o=t.getCoords(),s=[];for(let e of i)for(let t of e.getMovables().getItems({type:`chart`})){let e=B(t);if(!e||e.getPivotSource())continue;let n=null;for(let t of e.getSeries()){for(let e of[t.getValuesRange(),t.getCategoriesRange(),t.getNameRange()]){if(!e)continue;let t=e.getCoords();if(e.getSheet()===r&&Vt(t,o)){n=!0;break}n===null&&a.get(e.getSheet())?.some(e=>Vt(e,t))&&(n=!1)}if(!0===n)break}n!==null&&s.push({movable:t,direct:n})}return s}(s.subject,l):[];if(!l||l.length===0){let e=a===`precedents`?s?.zeroPrecedents:s?.zeroDependents;u.length>0?(n.h2(`${c} (${Un(u.length)})`),n.text(` ${`charts`.padEnd(Gn)}${Wn(u)}`),n.blank()):e&&(n.h2(`${c} (0)`),n.blank());return}let d=await async function(e,t,n){let r=0,i=0,a=0,o=0,s=new Map;for(let e=0;e<t.length;e++){let n=t.at(e);if(n.isINamedRange){o++;continue}a++;let c=n.getCounts([G.Contentful,G.Formula]),l=c[G.Contentful]??0;r+=l,i+=c[G.Formula]??0;let u=n.getSheet()?.getName()??``;s.set(u,(s.get(u)??0)+l)}let{depth:c,capped:l}=await async function(e,t){let n=new Map,r=new Set,i=0,a=!1,o=e=>t===`precedents`?e.getDirectPrecedents():e.getDirectDependents(),s=async e=>{let t=await o(e);if(!t)return 0;let c=0;for(let e=0;e<t.length;e++){let o=t.at(e),l=Qn(o);if(r.has(l))continue;let u=n.get(l);u===void 0&&(++i>qn?(a=!0,u=0):(r.add(l),u=await s(o),r.delete(l),n.set(l,u))),c=Math.max(c,u+1)}return c};return{depth:await s(e),capped:a}}(e,n);return{cells:r,inputs:r-i,areas:a,names:o,depth:c,depthCapped:l,sheets:s,outputs:n===`dependents`?await Yn(t):{ranges:[],cells:0}}}(r,l,a),f=[`${d.cells} ${d.cells===1?`cell`:`cells`}`];a===`precedents`?f.push(`${d.inputs} ${d.inputs===1?`input`:`inputs`}`):f.push(`${d.outputs.cells} ${d.outputs.cells===1?`output`:`outputs`}`),f.push(`depth ${d.depthCapped?`≥ `:``}${d.depth}`),f.push(`${d.areas} ${d.areas===1?`area`:`areas`}`),d.names>0&&f.push(`${d.names} ${d.names===1?`name`:`names`}`),u.length>0&&f.push(Un(u.length)),n.h2(`${c} (${f.join(` · `)})`);let p=s?.home?.getName()??null,m=await async function(e,t,n,r){let i=Math.max(1,r?.maxTreeRows??12),a=e=>t===`precedents`?e.getDirectPrecedents():e.getDirectDependents(),o=[],s=new Map,c=0,l=0,u=!1,d=[],f=(e,t,n)=>{let r=e?.length??0;for(let a=0;a<r&&d.length-p<i-l;a++)d.push({range:e.at(a),parent:t,depth:n});return r},p=0;for(c=f(await a(e),null,0);p<d.length&&l<i;){let{range:e,parent:t,depth:n}=d[p++],r=Qn(e),i={range:e,key:r,depth:n,parent:t,children:[],childCount:0,mark:null,first:null};l++,(t?t.children:o).push(i);let c=t;for(;c&&c.key!==r;)c=c.parent;if(c){i.mark=`circular`,u=!0;continue}let m=s.get(r);m?(i.mark=`repeat`,i.first=m):(s.set(r,i),i.childCount=f(await a(e),i,n+1))}let m=function(e){if(e.isINamedRange||typeof e.getCoords!=`function`)return null;let t=e.getCoords();return`rowIndex`in t?{rowStart:t.rowIndex,rowEnd:t.rowIndex,colStart:t.colIndex,colEnd:t.colIndex}:t}(e),h=[],g=e=>{for(let t of e)h.push(t),g(t.children)};g(o);let _=new Map(h.map((e,t)=>[e,t])),v=c-o.length,y=h.map(e=>{let{address:t,sheet:n,isName:r}=$n(e.range),i;if(e.mark===`circular`)i=`↺ circular`;else if(e.mark===`repeat`)i=_.get(e.first)<_.get(e)?`↑ shown above`:`↓ shown below`;else{i=[er(e.range),Zn(e.range,m)].filter(Boolean).join(` `);let t=e.childCount-e.children.length;t>0&&(v+=t,i=`${i} ▸ ${t} more`)}let a=` `.repeat(e.depth);return{indent:a,sheet:n,isName:r,label:`${a}${t}`,detail:i}}),b=y.filter(e=>!e.isName);if(b.length>0&&b.some(e=>e.sheet!==b[0].sheet))for(let e of y)e.isName||(e.label=`${e.indent}${L(e.sheet)}!${e.label.slice(e.indent.length)}`);let x=[],S=Math.max(...y.map(e=>e.label.length));for(let e of y)x.push(` ${e.label.padEnd(S)} ${e.detail}`.trimEnd());if(u&&x.push(` ↺ circular reference — the chain returns to a cell already on this branch`),v>0){let e=t===`precedents`?`getPrecedents()`:`getDependents()`;x.push(` …${v} ${v===1?`branch`:`branches`} not shown · ${e} → ICellRanges (${n} ${n===1?`area`:`areas`}), flat`)}return{lines:x,shown:new Set(h.map(e=>e.key))}}(r,a,d.areas,o),h=d.outputs.ranges;if(a===`dependents`&&h.some(e=>!m.shown.has(Qn(e)))&&n.text(` ${`outputs`.padEnd(Gn)}${function(e,n){let r=e.ranges.slice(0,Jn).map(e=>{let{address:r,sheet:a}=$n(e);return[n!==null&&a!==n?`${L(a)}!${r}`:r,e.isSingleCell()?i(e.getCell(),t.Mode.Display)?.display??``:`${e.getRowCount()}×${e.getColumnCount()}`,Zn(e)].filter(Boolean).join(` `)}),a=e.ranges.length-r.length;return a>0&&r.push(`+${a} more (getDependents())`),r.join(` · `)}(d.outputs,p)}`),p!==null){let e=[...d.sheets].filter(([e])=>e!==p);if(e.length>0){let t=e.map(([e,t])=>`${L(e)} ${t} ${t===1?`cell`:`cells`}`);n.text(` ${`sheets`.padEnd(Gn)}${t.join(` · `)}`)}}u.length>0&&n.text(` ${`charts`.padEnd(Gn)}${Wn(u)}`);for(let e of m.lines)n.text(e);n.blank()}var Un=e=>`${e} ${e===1?`chart`:`charts`}`;function Wn(e){let t=e.slice(0,Kn).map(Ht),n=e.length-t.length;return n>0&&t.push(`+${n} more`),t.join(` · `)}var Gn=10,Kn=6,qn=2e3,Jn=4;async function Yn(e){let t=new Map,n=await e.getPrecedents(!1);for(let e=0;e<(n?.length??0);e++){let r=n.at(e);if(r.isINamedRange)continue;let i=r.getSheet()?.getName()??``,a=t.get(i)??[];a.push(r.getCoords()),t.set(i,a)}let r=[],i=0;for(let n=0;n<e.length;n++){let a=e.at(n);if(a.isINamedRange)continue;let o=[a.getCoords()];for(let e of t.get(a.getSheet()?.getName()??``)??[])if(o=o.flatMap(t=>Xn(t,e)),o.length===0)break;for(let e of o)i+=(e.rowEnd-e.rowStart+1)*(e.colEnd-e.colStart+1),r.push(a.getSheet().getRange(e))}return{ranges:r,cells:i}}function Xn(e,t){let n=Math.max(e.rowStart,t.rowStart),r=Math.min(e.rowEnd,t.rowEnd),i=Math.max(e.colStart,t.colStart),a=Math.min(e.colEnd,t.colEnd);if(n>r||i>a)return[e];let o=[];return e.rowStart<n&&o.push({...e,rowEnd:n-1}),r<e.rowEnd&&o.push({...e,rowStart:r+1}),e.colStart<i&&o.push({rowStart:n,rowEnd:r,colStart:e.colStart,colEnd:i-1}),a<e.colEnd&&o.push({rowStart:n,rowEnd:r,colStart:a+1,colEnd:e.colEnd}),o}function Zn(t,n){if(t.isINamedRange||!t.isSingleCell())return``;let r=t.getCell();if(r.getType()===e.ScalarType.String)return``;let i=r.getCoords(),a=t.getSheet(),o=[];if(!n||i.rowIndex<n.rowStart||i.rowIndex>n.rowEnd){let e=v(a,i,`row`);e&&o.push(`row ${JSON.stringify(e.text)}`)}if(!n||i.colIndex<n.colStart||i.colIndex>n.colEnd){let e=v(a,i,`column`);e&&o.push(`col ${JSON.stringify(e.text)}`)}return o.join(` `)}function Qn(e){let t=e.isINamedRange?e.getId():null;if(t)return`name:${t}`;let n=e.getCoords();return`${e.getSheet()?.getName()??``}!${n.rowStart},${n.colStart},${n.rowEnd},${n.colEnd}`}function $n(e){let t=e.getSheet()?.getName()??``;if(e.isINamedRange)return{address:e.getName(),sheet:t,isName:!0};let n=e.getAddress(),r=n.lastIndexOf(`!`);return{address:r>=0&&r<n.length-1?n.slice(r+1):n,sheet:t,isName:!1}}function er(e){if(e.isINamedRange){let t=e.getRanges();return t?`name → ${t.getAddress()}`:`name`}if(e.isSingleCell()){let n=e.getCell(),r=i(n,t.Mode.Display),a=n.getFormulaText(),o=r?r.display:`(empty)`;return a?`${o} ${a}`:o}let n=`${e.getRowCount()}×${e.getColumnCount()}`,r=[...e.getRegions(G.Formula)];if(r.length===1&&r[0].getRange().isEqual(e)){let e=r[0].getCell().getFormulaText();if(e)return`${n} ${e}`}return n}var tr={features:e=>ot(e),mode:(e,n)=>function(e,t,n){let r=new Map(Object.values(n).map(e=>[e.toLowerCase(),e])).get(e.trim().toLowerCase());if(!r)throw Error(`Unknown ${t} '${e}'. Values: ${Object.values(n).join(`, `)}.`);return r}(e,n,t.Mode)},nr=Object.keys(tr),rr=e.ICellRange.Feature,ir=[[`formatCells`,`format cells`],[`formatColumns`,`format columns`],[`formatRows`,`format rows`],[`insertColumns`,`insert columns`],[`insertRows`,`insert rows`],[`insertHyperlinks`,`insert hyperlinks`],[`deleteColumns`,`delete columns`],[`deleteRows`,`delete rows`],[`sort`,`sort`],[`autoTable`,`filter`],[`pivotTables`,`pivot tables`],[`objects`,`edit objects`],[`scenarios`,`edit scenarios`]],ar=[[`structure`,`structure`],[`windows`,`windows`]],K=e=>{let t=e.hasPassword()?` · password`:``;return e.isLocked()?`locked${t}`:e.isPaused()?`paused${t} — nothing is refused until resume()`:null},or=e=>{let t=e.getProperties();if(!t)return null;let n=ir.filter(([e])=>!0===t[e]).map(([,e])=>e);return n.length>0?n.join(`, `):null},sr=e=>{let t=e.getProperties();if(!t)return null;let n=ar.filter(([e])=>!0!==t[e]).map(([,e])=>e);return n.length>0?n.join(`, `):null},cr=e=>{let t=K(e);if(!t)return null;let n=sr(e);return n?`${n} ${t}`:t},lr=e=>[...e.getEntireRange().getRegions(rr.Unlock)],ur=e=>{let t=0;for(let n of e){let e=n.getCoords();t+=(e.rowEnd-e.rowStart+1)*(e.colEnd-e.colStart+1)}return t},dr=t=>{let n=null;for(let e of t){let t=e.getCoords();n=n?{rowStart:Math.min(n.rowStart,t.rowStart),colStart:Math.min(n.colStart,t.colStart),rowEnd:Math.max(n.rowEnd,t.rowEnd),colEnd:Math.max(n.colEnd,t.colEnd)}:{...t}}return n?e.AddressUtils.rangeToString(n)??``:``},q=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function fr(e){let t=e.getProtection(),n=K(t);if(!n)return null;let r=lr(e),i=[r.length>0?`${q(ur(r),`editable cell`)} · ${q(r.length,`region`)}`:`no editable cells`,n];return!1===t.getProperties()?.showFormulas&&i.push(`formulas hidden`),{extent:dr(r),detail:i.join(` · `)}}function pr(e,t){let n=t.getProtection(),r=K(n);if(!r)return;e.h2(`Protection (${r})`);let i=e=>` ${e.padEnd(10)}`;e.text(`${i(`allowed`)}${or(n)??`none — only the editable cells take a write`}`),!1===n.getProperties()?.showFormulas&&e.text(`${i(`formulas`)}hidden — a cell reads as a value unless its style shows its formula`);let a=lr(t);if(a.length===0)return e.text(`${i(`editable`)}none — every cell refuses a write`),void e.blank();e.text(`${i(`editable`)}${q(ur(a),`cell`)} · ${q(a.length,`region`)}`),Qe(e,a,{maxRegions:12,payload:Je(rr.Unlock,null),recovery:`${R(t.getEntireRange())}.getRegions("unlock") lists all ${a.length}`}),e.blank()}function mr(e){if(!e.getSheet().getProtection().isLocked())return null;let t=[...e.getRegions(rr.Unlock)],n=e.getRowCount()*e.getColumnCount(),r=ur(t);if(r===0)return`sheet locked — no cell here takes a write`;if(r===n)return`sheet locked — every cell here is editable`;let i=e.getSheet().getProtectedRanges().getItems({address:e}).some(e=>!e.isUnlocked());return`sheet locked — ${r} of ${q(n,`cell`)} editable (${dr(t)})`+(i?` · some behind a range password`:``)}function hr(e){return e.getSheet().getProtection().isLocked()?e.isEditAllowed()?`true — unlocked on a protected sheet`:`false — the sheet is protected and this cell is locked`:null}function gr(e){let t=new P,n=!0===e.isISheetProtection;t.h1(n?`Sheet Protection`:`Workbook Protection`),t.blank();let r=K(e);t.fact(`State: ${r??`not protected`}${e.isReadOnly()?` · read-only`:``}`);let i=r?``:` (when next locked)`;if(n){let n=or(e);(r||n)&&t.fact(`Allowed${i}: ${n??`none — only the editable cells take a write`}`),!1===e.getProperties()?.showFormulas&&t.fact(`Formulas${i}: hidden`),r&&t.fact(`Editable: sheet.getRegions("unlock") lists the cells that take a write`)}else{let n=sr(e);(r||e.getProperties())&&t.fact(`Refused${i}: ${n??`nothing`}`)}return t.toLines().join(`
|
|
11
|
-
`).trimEnd()}function
|
|
12
|
-
`).trimEnd()}var
|
|
13
|
-
`).trimEnd()}var
|
|
14
|
-
`).trimEnd()}function
|
|
15
|
-
`).trimEnd()}function
|
|
16
|
-
`).trimEnd()}function
|
|
17
|
-
`).trimEnd()}var
|
|
18
|
-
`).trimEnd()}var
|
|
19
|
-
`).length,runsInExcel:
|
|
10
|
+
`)}(e,n);case`search`:return function(e,t){if(e.types.length===0&&e.members.length===0)return`No type or member name contains '${e.query}'. \`${t}\` with no name lists where to start.`;let n=[`# '${e.query}' in the scripting API`];if(e.types.length>0){n.push(``,`Types:`);for(let t of e.types)n.push(`- \`${t}\``)}if(e.members.length>0){n.push(``,`Members:`);for(let{key:t,member:r}of e.members)n.push($n(r,t))}return e.omitted>0&&n.push(``,`…and ${U(e.omitted,`more match`,`more matches`)}; a longer word narrows it.`),n.push(``,`\`${t} <Type>\` lists a type's members; \`${t} <Type>.<member>\` prints one in full.`),n.join(`
|
|
11
|
+
`)}(e,n)}}async function tr(t){let n=Jn(await(0,e.getScriptingApi)(),t);if(n.kind===`member`)try{let t=(await(0,e.getScriptingDeclarations)()).split(/\r?\n/);n.sources=n.members.map(e=>function(e,t,n){let r=e.slice(t-1,n),i=Math.min(...r.filter(e=>e.trim()).map(e=>e.length-e.trimStart().length));return r.map(e=>e.slice(Number.isFinite(i)?i:0)).join(`
|
|
12
|
+
`)}(t,e.lines[0],e.lines[1]))}catch{}return n}var nr={name:`api`,description:"Look up the scripting API — what you can call on a type, without reading the type definitions. `ICellRange` lists its members, one line each (signature + summary); `ICellRange.setValues` prints that member's full documentation; any other word searches type and member names; no name lists where to start. Answers come from the same declarations `run` type-checks against, so a member listed here exists.",params:[{name:`name`,type:`string`,description:"A type (`ICellRange`), a member (`ICellRange.setValues`), or a word to search for. Omit for the overview. A leading `SheetXL.` is accepted.",positional:0}],run:e=>tr(e?.name),render:er},W=e.ICellRange.Feature;async function rr(e,t,n,r){await ir(e,t,`precedents`,n,r),await ir(e,t,`dependents`,n,r)}async function ir(n,r,a,o,s){let c=a===`precedents`?`Precedents`:`Dependents`,l=await(a===`precedents`?r.getPrecedents():r.getDependents()),u=a===`dependents`&&s?.subject?function(t,n){let r=t.getSheet(),i=r.getWorkbook()?.getSheets().getItems({visibility:e.ISheet.Visibility.VeryHidden})??[r],a=new Map;for(let e=0;e<(n?.length??0);e++){let t=n.at(e);if(t.isINamedRange)continue;let r=a.get(t.getSheet());r?r.push(t.getCoords()):a.set(t.getSheet(),[t.getCoords()])}let o=t.getCoords(),s=[];for(let e of i)for(let t of e.getMovables().getItems({type:`chart`})){let e=z(t);if(!e||e.getPivotSource())continue;let n=null;for(let t of e.getSeries()){for(let e of[t.getValuesRange(),t.getCategoriesRange(),t.getNameRange()]){if(!e)continue;let t=e.getCoords();if(e.getSheet()===r&&Ut(t,o)){n=!0;break}n===null&&a.get(e.getSheet())?.some(e=>Ut(e,t))&&(n=!1)}if(!0===n)break}n!==null&&s.push({movable:t,direct:n})}return s}(s.subject,l):[];if(!l||l.length===0){let e=a===`precedents`?s?.zeroPrecedents:s?.zeroDependents;u.length>0?(n.h2(`${c} (${ar(u.length)})`),n.text(` ${`charts`.padEnd(sr)}${or(u)}`),n.blank()):e&&(n.h2(`${c} (0)`),n.blank());return}let d=await async function(e,t,n){let r=0,i=0,a=0,o=0,s=new Map;for(let e=0;e<t.length;e++){let n=t.at(e);if(n.isINamedRange){o++;continue}a++;let c=n.getCounts([W.Contentful,W.Formula]),l=c[W.Contentful]??0;r+=l,i+=c[W.Formula]??0;let u=n.getSheet()?.getName()??``;s.set(u,(s.get(u)??0)+l)}let{depth:c,capped:l}=await async function(e,t){let n=new Map,r=new Set,i=0,a=!1,o=e=>t===`precedents`?e.getDirectPrecedents():e.getDirectDependents(),s=async e=>{let t=await o(e);if(!t)return 0;let c=0;for(let e=0;e<t.length;e++){let o=t.at(e),l=mr(o);if(r.has(l))continue;let u=n.get(l);u===void 0&&(++i>lr?(a=!0,u=0):(r.add(l),u=await s(o),r.delete(l),n.set(l,u))),c=Math.max(c,u+1)}return c};return{depth:await s(e),capped:a}}(e,n);return{cells:r,inputs:r-i,areas:a,names:o,depth:c,depthCapped:l,sheets:s,outputs:n===`dependents`?await dr(t):{ranges:[],cells:0}}}(r,l,a),f=[`${d.cells} ${d.cells===1?`cell`:`cells`}`];a===`precedents`?f.push(`${d.inputs} ${d.inputs===1?`input`:`inputs`}`):f.push(`${d.outputs.cells} ${d.outputs.cells===1?`output`:`outputs`}`),f.push(`depth ${d.depthCapped?`≥ `:``}${d.depth}`),f.push(`${d.areas} ${d.areas===1?`area`:`areas`}`),d.names>0&&f.push(`${d.names} ${d.names===1?`name`:`names`}`),u.length>0&&f.push(ar(u.length)),n.h2(`${c} (${f.join(` · `)})`);let p=s?.home?.getName()??null,m=await async function(e,t,n,r){let i=Math.max(1,r?.maxTreeRows??12),a=e=>t===`precedents`?e.getDirectPrecedents():e.getDirectDependents(),o=[],s=new Map,c=0,l=0,u=!1,d=[],f=(e,t,n)=>{let r=e?.length??0;for(let a=0;a<r&&d.length-p<i-l;a++)d.push({range:e.at(a),parent:t,depth:n});return r},p=0;for(c=f(await a(e),null,0);p<d.length&&l<i;){let{range:e,parent:t,depth:n}=d[p++],r=mr(e),i={range:e,key:r,depth:n,parent:t,children:[],childCount:0,mark:null,first:null};l++,(t?t.children:o).push(i);let c=t;for(;c&&c.key!==r;)c=c.parent;if(c){i.mark=`circular`,u=!0;continue}let m=s.get(r);m?(i.mark=`repeat`,i.first=m):(s.set(r,i),i.childCount=f(await a(e),i,n+1))}let m=function(e){if(e.isINamedRange||typeof e.getCoords!=`function`)return null;let t=e.getCoords();return`rowIndex`in t?{rowStart:t.rowIndex,rowEnd:t.rowIndex,colStart:t.colIndex,colEnd:t.colIndex}:t}(e),h=[],g=e=>{for(let t of e)h.push(t),g(t.children)};g(o);let _=new Map(h.map((e,t)=>[e,t])),v=c-o.length,y=h.map(e=>{let{address:t,sheet:n,isName:r}=hr(e.range),i;if(e.mark===`circular`)i=`↺ circular`;else if(e.mark===`repeat`)i=_.get(e.first)<_.get(e)?`↑ shown above`:`↓ shown below`;else{i=[gr(e.range),pr(e.range,m)].filter(Boolean).join(` `);let t=e.childCount-e.children.length;t>0&&(v+=t,i=`${i} ▸ ${t} more`)}let a=` `.repeat(e.depth);return{indent:a,sheet:n,isName:r,label:`${a}${t}`,detail:i}}),b=y.filter(e=>!e.isName);if(b.length>0&&b.some(e=>e.sheet!==b[0].sheet))for(let e of y)e.isName||(e.label=`${e.indent}${I(e.sheet)}!${e.label.slice(e.indent.length)}`);let x=[],S=Math.max(...y.map(e=>e.label.length));for(let e of y)x.push(` ${e.label.padEnd(S)} ${e.detail}`.trimEnd());if(u&&x.push(` ↺ circular reference — the chain returns to a cell already on this branch`),v>0){let e=t===`precedents`?`getPrecedents()`:`getDependents()`;x.push(` …${v} ${v===1?`branch`:`branches`} not shown · ${e} → ICellRanges (${n} ${n===1?`area`:`areas`}), flat`)}return{lines:x,shown:new Set(h.map(e=>e.key))}}(r,a,d.areas,o),h=d.outputs.ranges;if(a===`dependents`&&h.some(e=>!m.shown.has(mr(e)))&&n.text(` ${`outputs`.padEnd(sr)}${function(e,n){let r=e.ranges.slice(0,ur).map(e=>{let{address:r,sheet:a}=hr(e);return[n!==null&&a!==n?`${I(a)}!${r}`:r,e.isSingleCell()?i(e.getCell(),t.Mode.Display)?.display??``:`${e.getRowCount()}×${e.getColumnCount()}`,pr(e)].filter(Boolean).join(` `)}),a=e.ranges.length-r.length;return a>0&&r.push(`+${a} more (getDependents())`),r.join(` · `)}(d.outputs,p)}`),p!==null){let e=[...d.sheets].filter(([e])=>e!==p);if(e.length>0){let t=e.map(([e,t])=>`${I(e)} ${t} ${t===1?`cell`:`cells`}`);n.text(` ${`sheets`.padEnd(sr)}${t.join(` · `)}`)}}u.length>0&&n.text(` ${`charts`.padEnd(sr)}${or(u)}`);for(let e of m.lines)n.text(e);n.blank()}var ar=e=>`${e} ${e===1?`chart`:`charts`}`;function or(e){let t=e.slice(0,cr).map(Wt),n=e.length-t.length;return n>0&&t.push(`+${n} more`),t.join(` · `)}var sr=10,cr=6,lr=2e3,ur=4;async function dr(e){let t=new Map,n=await e.getPrecedents(!1);for(let e=0;e<(n?.length??0);e++){let r=n.at(e);if(r.isINamedRange)continue;let i=r.getSheet()?.getName()??``,a=t.get(i)??[];a.push(r.getCoords()),t.set(i,a)}let r=[],i=0;for(let n=0;n<e.length;n++){let a=e.at(n);if(a.isINamedRange)continue;let o=[a.getCoords()];for(let e of t.get(a.getSheet()?.getName()??``)??[])if(o=o.flatMap(t=>fr(t,e)),o.length===0)break;for(let e of o)i+=(e.rowEnd-e.rowStart+1)*(e.colEnd-e.colStart+1),r.push(a.getSheet().getRange(e))}return{ranges:r,cells:i}}function fr(e,t){let n=Math.max(e.rowStart,t.rowStart),r=Math.min(e.rowEnd,t.rowEnd),i=Math.max(e.colStart,t.colStart),a=Math.min(e.colEnd,t.colEnd);if(n>r||i>a)return[e];let o=[];return e.rowStart<n&&o.push({...e,rowEnd:n-1}),r<e.rowEnd&&o.push({...e,rowStart:r+1}),e.colStart<i&&o.push({rowStart:n,rowEnd:r,colStart:e.colStart,colEnd:i-1}),a<e.colEnd&&o.push({rowStart:n,rowEnd:r,colStart:a+1,colEnd:e.colEnd}),o}function pr(t,n){if(t.isINamedRange||!t.isSingleCell())return``;let r=t.getCell();if(r.getType()===e.ScalarType.String)return``;let i=r.getCoords(),a=t.getSheet(),o=[];if(!n||i.rowIndex<n.rowStart||i.rowIndex>n.rowEnd){let e=v(a,i,`row`);e&&o.push(`row ${JSON.stringify(e.text)}`)}if(!n||i.colIndex<n.colStart||i.colIndex>n.colEnd){let e=v(a,i,`column`);e&&o.push(`col ${JSON.stringify(e.text)}`)}return o.join(` `)}function mr(e){let t=e.isINamedRange?e.getId():null;if(t)return`name:${t}`;let n=e.getCoords();return`${e.getSheet()?.getName()??``}!${n.rowStart},${n.colStart},${n.rowEnd},${n.colEnd}`}function hr(e){let t=e.getSheet()?.getName()??``;if(e.isINamedRange)return{address:e.getName(),sheet:t,isName:!0};let n=e.getAddress(),r=n.lastIndexOf(`!`);return{address:r>=0&&r<n.length-1?n.slice(r+1):n,sheet:t,isName:!1}}function gr(e){if(e.isINamedRange){let t=e.getRanges();return t?`name → ${t.getAddress()}`:`name`}if(e.isSingleCell()){let n=e.getCell(),r=i(n,t.Mode.Display),a=n.getFormulaText(),o=r?r.display:`(empty)`;return a?`${o} ${a}`:o}let n=`${e.getRowCount()}×${e.getColumnCount()}`,r=[...e.getRegions(W.Formula)];if(r.length===1&&r[0].getRange().isEqual(e)){let e=r[0].getCell().getFormulaText();if(e)return`${n} ${e}`}return n}var _r={features:e=>st(e),mode:(e,n)=>function(e,t,n){let r=new Map(Object.values(n).map(e=>[e.toLowerCase(),e])).get(e.trim().toLowerCase());if(!r)throw Error(`Unknown ${t} '${e}'. Values: ${Object.values(n).join(`, `)}.`);return r}(e,n,t.Mode)},vr=Object.keys(_r),yr=e.ICellRange.Feature,br=[[`formatCells`,`format cells`],[`formatColumns`,`format columns`],[`formatRows`,`format rows`],[`insertColumns`,`insert columns`],[`insertRows`,`insert rows`],[`insertHyperlinks`,`insert hyperlinks`],[`deleteColumns`,`delete columns`],[`deleteRows`,`delete rows`],[`sort`,`sort`],[`autoTable`,`filter`],[`pivotTables`,`pivot tables`],[`objects`,`edit objects`],[`scenarios`,`edit scenarios`]],xr=[[`structure`,`structure`],[`windows`,`windows`]],G=e=>{let t=e.hasPassword()?` · password`:``;return e.isLocked()?`locked${t}`:e.isPaused()?`paused${t} — nothing is refused until resume()`:null},Sr=e=>{let t=e.getProperties();if(!t)return null;let n=br.filter(([e])=>!0===t[e]).map(([,e])=>e);return n.length>0?n.join(`, `):null},Cr=e=>{let t=e.getProperties();if(!t)return null;let n=xr.filter(([e])=>!0!==t[e]).map(([,e])=>e);return n.length>0?n.join(`, `):null},wr=e=>{let t=G(e);if(!t)return null;let n=Cr(e);return n?`${n} ${t}`:t},Tr=e=>[...e.getEntireRange().getRegions(yr.Unlock)],Er=e=>{let t=0;for(let n of e){let e=n.getCoords();t+=(e.rowEnd-e.rowStart+1)*(e.colEnd-e.colStart+1)}return t},Dr=t=>{let n=null;for(let e of t){let t=e.getCoords();n=n?{rowStart:Math.min(n.rowStart,t.rowStart),colStart:Math.min(n.colStart,t.colStart),rowEnd:Math.max(n.rowEnd,t.rowEnd),colEnd:Math.max(n.colEnd,t.colEnd)}:{...t}}return n?e.AddressUtils.rangeToString(n)??``:``},K=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function Or(e){let t=e.getProtection(),n=G(t);if(!n)return null;let r=Tr(e),i=[r.length>0?`${K(Er(r),`editable cell`)} · ${K(r.length,`region`)}`:`no editable cells`,n];return!1===t.getProperties()?.showFormulas&&i.push(`formulas hidden`),{extent:Dr(r),detail:i.join(` · `)}}function kr(e,t){let n=t.getProtection(),r=G(n);if(!r)return;e.h2(`Protection (${r})`);let i=e=>` ${e.padEnd(10)}`;e.text(`${i(`allowed`)}${Sr(n)??`none — only the editable cells take a write`}`),!1===n.getProperties()?.showFormulas&&e.text(`${i(`formulas`)}hidden — a cell reads as a value unless its style shows its formula`);let a=Tr(t);if(a.length===0)return e.text(`${i(`editable`)}none — every cell refuses a write`),void e.blank();e.text(`${i(`editable`)}${K(Er(a),`cell`)} · ${K(a.length,`region`)}`),$e(e,a,{maxRegions:12,payload:Ye(yr.Unlock,null),recovery:`${L(t.getEntireRange())}.getRegions("unlock") lists all ${a.length}`}),e.blank()}function Ar(e){if(!e.getSheet().getProtection().isLocked())return null;let t=[...e.getRegions(yr.Unlock)],n=e.getRowCount()*e.getColumnCount(),r=Er(t);if(r===0)return`sheet locked — no cell here takes a write`;if(r===n)return`sheet locked — every cell here is editable`;let i=e.getSheet().getProtectedRanges().getItems({address:e}).some(e=>!e.isUnlocked());return`sheet locked — ${r} of ${K(n,`cell`)} editable (${Dr(t)})`+(i?` · some behind a range password`:``)}function jr(e){return e.getSheet().getProtection().isLocked()?e.isEditAllowed()?`true — unlocked on a protected sheet`:`false — the sheet is protected and this cell is locked`:null}function Mr(e){let t=new N,n=!0===e.isISheetProtection;t.h1(n?`Sheet Protection`:`Workbook Protection`),t.blank();let r=G(e);t.fact(`State: ${r??`not protected`}${e.isReadOnly()?` · read-only`:``}`);let i=r?``:` (when next locked)`;if(n){let n=Sr(e);(r||n)&&t.fact(`Allowed${i}: ${n??`none — only the editable cells take a write`}`),!1===e.getProperties()?.showFormulas&&t.fact(`Formulas${i}: hidden`),r&&t.fact(`Editable: sheet.getRegions("unlock") lists the cells that take a write`)}else{let n=Cr(e);(r||e.getProperties())&&t.fact(`Refused${i}: ${n??`nothing`}`)}return t.toLines().join(`
|
|
13
|
+
`).trimEnd()}function Nr(e){let t=new N,n=e.getRanges();t.h1(`Unlocked Range — ${e.getName()}`),t.blank(),t.fact(`Ranges: ${lt(n)}`),t.fact(`Cells: ${n.size}`),t.fact(`Password: `+(e.hasPassword()?e.isUnlocked()?`set · unlocked for this session`:`set · unlock(password) grants access`:`none`));let r=n.getSheet().getProtection().isLocked();return t.fact(`In force: `+(r?`true — the sheet is protected`:`false — the sheet is not protected, so every cell is editable`)),e.getSecurityDescriptor()&&t.fact(`Security Descriptor: present · not evaluated`),t.toLines().join(`
|
|
14
|
+
`).trimEnd()}var Pr=e.ICellRange.Feature;async function Fr(n,r){let a=n.getSheet().getRange(n.getCoords());n=a.getCell();let o=new N;o.h1(`Cell — ${I(n.getSheet().getName())}!${n.getAddress()}`),o.blank();let s=!!n.getFormulaText(),c=n.getType();(function(n,r){let a=i(r,t.Mode.Display),o=i(r,t.Mode.Value),s=r.getFormulaText(),c=n.toLines().length;if(a||s){if(n.fact(`Type: ${r.getType()}`),a&&n.fact(`Display: ${a.display}`),o&&o.match!==a?.match){let t=function(t){let n=t.getDate();if(!n)return null;let r=(e,t=2)=>String(e).padStart(t,`0`),i=`${r(n.getHours())}:${r(n.getMinutes())}:${r(n.getSeconds())}`;if(!e.NumberFormat.getEngine().isDateFormat(t.getStyle().getNumberFormat()))return t.getValue()<1?i:null;let a=`${r(n.getFullYear(),4)}-${r(n.getMonth()+1)}-${r(n.getDate())}`;return i===`00:00:00`?a:`${a}T${i}`}(r);n.fact(`Value: ${o.display}${t&&t!==a?.match?` (${t})`:``}`)}s&&n.fact(`Formula: ${n.codespan(s)}`)}let l=r.getHyperlink();l&&n.fact(`Hyperlink: ${l.getAddress()}`);let d=r.getSpans(),f=!r.isTopLeft();if(f||d.height>1||d.width>1){let e=r.getRange().toString();n.fact(`Merge: ${e} · ${d.height}×${d.width}`),f&&n.fact(`Merge Anchor: false — this cell is covered; the value lives at the top-left`)}let m=r.getSpill();m&&n.fact(`Spill: ${m.toString()}`),r.isSpillOverflow()&&n.fact(`Spill Overflow: true — the anchor formula is elsewhere`);let _=r.getTable();_&&n.fact(`Table: ${function(e,t){let n=e.getRange().getCoords(),r=[`${e.getName()} (${e.getRange().getAddress()})`],i=e.getColumnAt(t.colIndex-n.colStart);if(i&&r.push(`column ${JSON.stringify(i.getName())}`),e.isShowHeaders()&&t.rowIndex===n.rowStart)r.push(`header row`);else if(e.isShowTotals()&&t.rowIndex===n.rowEnd)r.push(`totals row`);else{let n=e.getDataRange().getCoords();r.push(`data row ${t.rowIndex-n.rowStart+1} of ${n.rowEnd-n.rowStart+1}`)}return r.join(` · `)}(_,r.getCoords())}`);let v=Ot(r.getSheet().getRange(r.getCoords()));v.length>0&&n.fact(`Names: ${v.map(e=>`${e.getName()} (${ct(e.getRanges())})`).join(` · `)}`);let y=jr(r);y&&n.fact(`Editable: ${y}`);let b=r.getErrors();b.length>0&&n.fact(`Errors: ${b.join(`; `)}`);let x=r.getWarnings();x.length>0&&n.fact(`Warnings: ${x.join(`; `)}`);let S=function(e,t){let n=t.getStyle(),r=t.getSheet().getWorkbook()?.getStyles().getNormal()??null,i=n.getNamed().getName(),a=i===(r?.getNamed().getName()??`Normal`),o=n.getNumberFormat(),s=Oe(o),c=s?`${s} ${e.codespan(o)}`:null,l=r?g(n,r):null,d=u(n),f=p(n),m=r?h(n,r):null,_=[a?null:i,c?`format ${c}`:null,l?`font ${l}`:null,d?`fill ${d}`:null,f.length>0?`border ${f.join(`, `)}`:null,m?`align ${m}`:null].filter(Boolean);return _.length>0?_.join(` · `):null}(n,r);S&&n.fact(`Style (effective): ${S}`),n.toLines().length>c&&n.blank()})(o,n);let l=function(t,n){if(!n.getFormulaText()&&n.getType()===e.ScalarType.Null)return null;let r=t.getSurrounding({contentOnly:!0});return r.isSingleCell()?null:r}(a,n);return l&&function(e,t,n){let r=t.getCoords(),i=t.getSheet();e.h2(`Current Region — ${n.getAddress()} · ${n.getRowCount()}×${n.getColumnCount()}`);let a=ne(n),o=e=>{if(!a||a.byColumn!==(e===`row`))return null;let t=e===`row`?r.rowIndex:r.colIndex;if(t<a.start)return null;let n=a.lines.find(e=>e.index===t);if(n?.sums)return`totals, ${ae(n.sums)}`;let i=a.byColumn?`row ${a.start+1}`:`column ${x(a.start)}`;return t===a.start?`totals`:`below the totals ${i}`},s=[[`row`,[String(r.rowIndex+1),y(v(i,r,`row`)),o(`row`)].filter(Boolean).join(` · `)],[`column`,[x(r.colIndex),y(v(i,r,`column`)),o(`column`)].filter(Boolean).join(` · `)]];for(let[t,n]of s)e.text(` ${t.padEnd(7)}${n}`);e.blank()}(o,n,l),function(e,n,r){let a=n.getCoords(),o=r?.getCoords()??Lr(a),s=n.getSheet(),c=s.getRange({rowStart:a.rowIndex,rowEnd:a.rowIndex,colStart:o.colStart,colEnd:o.colEnd}),l=s.getRange({rowStart:o.rowStart,rowEnd:o.rowEnd,colStart:a.colIndex,colEnd:a.colIndex}),u=[Rr(c,`row`,a.colIndex),Rr(l,`column`,a.rowIndex)].filter(e=>e!==null);if(u.length===0)return;let d=u.reduce((e,t)=>t.share>e.share?t:e),f=d.axis===`row`?a.colIndex:a.rowIndex,p=d.segments.filter(e=>e.end>=d.start&&e.start<=d.end),m=d.end-d.start+1,h=d.axis===`row`?s.getRange({rowStart:a.rowIndex,rowEnd:a.rowIndex,colStart:d.start,colEnd:d.end}):s.getRange({rowStart:d.start,rowEnd:d.end,colStart:a.colIndex,colEnd:a.colIndex}),g=d.axis===`row`?`Row`:`Column`;if(e.h2(`Formula ${g} — ${h.getAddress()} · ${d.share} of ${m} consistent`),d.share<m){let n=p.map(e=>{let n=f>=e.start&&f<=e.end,r=e.range.getAddress(),a;if(e.r1c1===null)a=e.range.isSingleCell()?function(e){let n=i(e,t.Mode.Display);return n?`${n.display} typed`:`blank`}(e.range.getCell()):e.end-e.start+1+` cells, no formula`;else{let t=e.range.getCell().getFormulaText();a=`${e.r1c1===d.key?``:`≠ `}${t}`}return{address:r,detail:n?`${a} ← this cell`:a}}),r=Math.max(...n.map(e=>e.address.length)),a=n.slice(0,Ir);for(let t of a)e.text(` ${t.address.padEnd(r)} ${t.detail}`);n.length>a.length&&e.text(` …${n.length-a.length} more · getRegions("formula") on ${h.getAddress()} lists them`)}e.blank()}(o,n,l),await rr(o,n,r,{home:n.getSheet(),subject:a,zeroPrecedents:s,zeroDependents:s||c!==e.ScalarType.Null&&c!==e.ScalarType.String}),o.toLines().join(`
|
|
15
|
+
`).trimEnd()}var Ir=8,Lr=e=>({rowStart:e.rowIndex,rowEnd:e.rowIndex,colStart:e.colIndex,colEnd:e.colIndex});function Rr(e,t,n){if(e.isSingleCell())return null;let r=[];for(let n of e.getRegions(Pr.Formula)){let e=n.getCoords();r.push({start:t===`row`?e.colStart:e.rowStart,end:t===`row`?e.colEnd:e.rowEnd,r1c1:n.getCell().getFormulaText({r1c1:!0})??``,range:n.getRange()})}if(r.length===0)return null;r.sort((e,t)=>e.start-t.start);let i=new Map;for(let e of r)i.set(e.r1c1,(i.get(e.r1c1)??0)+e.end-e.start+1);let a=[...i].sort((e,t)=>t[1]-e[1]);for(let[i,o]of a){if(o<2)break;let a=r.filter(e=>e.r1c1===i),s=a[0].start,c=a[a.length-1].end;if(n<s||n>c)continue;let l=[],u=s;for(let n of r)n.end<s||n.start>c||(n.start>u&&l.push(zr(e,t,u,n.start-1)),l.push(n),u=n.end+1);return{axis:t,segments:l,key:i,share:o,start:s,end:c}}return null}function zr(e,t,n,r){let i=e.getCoords();return{start:n,end:r,r1c1:null,range:e.getSheet().getRange(t===`row`?{rowStart:i.rowStart,rowEnd:i.rowEnd,colStart:n,colEnd:r}:{rowStart:n,rowEnd:r,colStart:i.colStart,colEnd:i.colEnd})}}async function Br(n,r){let a=new N;a.h1(`Cell Range — ${ut(n)}`);let o=Ar(n);o&&a.text(`Protection: ${o}`),a.blank(),dt(a,n),function(e,t,n){if(!1===n?.profile||t.isSingleCell()||!t.isContentful())return;let r=C({getRowCount:()=>t.getRowCount(),getColumnCount:()=>t.getColumnCount(),getCell:()=>t.getCell(),getRange:()=>t},n);e.h2(`Profile`),e.text(r.summary);for(let t of r.series)e.text(` ${t}`);e.blank()}(a,n,r);let s=function(e,n,r){let a=r?.mode??t.Mode.Display,o=r?.maxCells??1e3,{rowStart:s,colStart:c}=n.getCoords(),l=n.getRowHeaders(),u=n.getColumnHeaders(),d=new Map,f=[],p=0,m=!1;n.forEach((e,t)=>{if(p>=o)return m=!0,{break:!0};let n=t.getCell(),r=n.getFormulaText(),s=i(n,a);if(!s&&!r)return;let c={text:(s?.display??``).replace(/\|/g,`\\|`).replace(/[\r\n]+/g,` `),alignment:n.getRenderHorizontalAlignment()},l=n.getSpill();l&&f.push({address:n.getAddress(),valuesRange:l.getValuesRange().toString()});let{rowIndex:u,colIndex:h}=t.getCoords(),g=d.get(u);g||(g=new Map,d.set(u,g)),g.set(h,c),p++});let h=Array.from(d.keys()).sort((e,t)=>e-t),g=new Set;d.forEach(e=>e.forEach((e,t)=>g.add(t)));let _=Array.from(g).sort((e,t)=>e-t);if(h.length===0)return{spills:f};let v=n.getIntersect({rowStart:h[0],rowEnd:h[h.length-1],colStart:_[0],colEnd:_[_.length-1]}),y=`${p} cell${p===1?``:`s`}`,b=v.toString()!==n.toString();e.h2(`Values (${b?`${F(v)} · `:``}${y})`);let x=e.beginFrame(_.map(e=>u.at(e-c).getText()));for(let e of h){let t=d.get(e);x.addRow(_.map(e=>t?.get(e)??{text:``}),l.at(e-s).getText())}return x.endFrame(),m&&e.text(`…truncated at ${o} cells · narrow the address, or summarize the whole range with getStats()`),e.blank(),{spills:f}}(a,n,r);return function(t,n,r){let i=[];for(let t of n.getRegions(e.ICellRange.Feature.Formula)){let e=t.getCell().getFormulaText();if(e&&(i.push({address:t.getAddress(),size:`${t.getRowCount()}×${t.getColumnCount()}`,formula:e}),i.length>=(r?.maxRegions??100)))break}if(i.length===0)return;t.h2(`Formulas`);let a=Math.max(...i.map(e=>e.address.length)),o=Math.max(...i.map(e=>e.size.length));for(let e of i)t.text(` ${e.address.padEnd(a)} ${e.size.padEnd(o)} ${e.formula}`);t.blank()}(a,n,r),function(e,t){if(t.length===0)return;e.h2(`Spills`);let n=Math.max(...t.map(e=>e.address.length));for(let{address:r,valuesRange:i}of t)e.text(` ${r.padEnd(n)} ${i}`);e.blank()}(a,s.spills),await kt(a,n),_n(a,n.getMovables()),Dt(a,`Conditional Formats`,n.getConditionalFormats(),We),Dt(a,`Data Validations`,n.getDataValidations(),Ge),await rr(a,n,r,{home:n.getSheet(),subject:n}),a.toLines().join(`
|
|
16
|
+
`).trimEnd()}function Vr(e){let t=new N,n=e.getRanges();t.h1(`Conditional Format — ${lt(n)}`),t.blank(),t.fact(`Order: ${e.getIndex()+1}`);let r=e.getScale();if(r)t.fact(`Rule: ${He(r)}`);else{let n=e.getCondition();t.fact(`Rule: ${n?.toString()||`none — this rule tests nothing`}`);let r=Be(e.getStyle());r&&t.fact(`Format: ${r}`)}return e.isStopIfTrue()&&t.fact(`Stop If True: true — later rules are not evaluated where this one matches`),t.fact(`Cells: ${n.size}`),t.toLines().join(`
|
|
17
|
+
`).trimEnd()}function Hr(e){let t=new N;t.h1(`Counts`);let n=!1;for(let[r,i]of Object.entries(e))i>0&&(t.fact(`${r}: ${i}`),n=!0);return n||t.fact(`None`),t.toLines().join(`
|
|
18
|
+
`).trimEnd()}function Ur(t){let n=new N,r=t.getRanges();n.h1(`Data Validation — ${lt(r)}`),n.blank();let i=t.getCondition();n.fact(`Rule: ${i?.toString()||`none — anything is accepted here`}`);let a=Ke(i);a&&n.fact(`Allowed: ${a}`),n.fact(`Blanks: `+(t.isIncludeBlanks()?`allowed`:`rejected`));let o=t.getAlertStyle();if(n.fact(`Alert: ${o}${o===e.IDataValidation.AlertStyle.Stop?` — the entry is refused`:` — the entry is accepted anyway`}`),t.isShowAlertMessage()){let e=Wr(t.getAlertTitle(),t.getAlertMessage());e&&n.fact(`Alert Message: ${e}`)}if(t.isShowPromptMessage()){let e=Wr(t.getPromptTitle(),t.getPromptMessage());e&&n.fact(`Prompt: ${e}`)}return t.isHideDropdown()&&n.fact(`Dropdown: hidden`),n.fact(`Cells: ${r.size}`),n.toLines().join(`
|
|
19
|
+
`).trimEnd()}var Wr=(e,t)=>{let n=[e?.trim(),t?.trim()].filter(Boolean);return n.length>0?n.join(` — `):null},Gr=`function`,Kr=`named`,qr=`tableReference`,Jr=`tableColumn`,Yr=`externalReference`,Xr=[[`isReferenceOnly`,`reference-only`],[`isVolatile`,`volatile`]],Zr=(e,t)=>e?` (${I(e)}!${t})`:``;function Qr(e,t,n,r){if(e===`external`)return`another workbook — not resolvable from here`;if(!n)return``;switch(e){case`function`:{let e=n.getCalculation().getFunctions().getByName(t);return e?e.isBuiltIn()?`built-in`:`custom`:`unknown — evaluates to #NAME?`}case`named`:return function(e,t){let n=t.getNames(),r=n.getByName(e)??n.getByName(e,!0);if(r){let e=Zr(r.getScope(),r.getName()),t=r.getRanges?.();return!t||t.isInvalid()?`defined name — reference does not resolve${e}`:`${t.toString()}${e}`}let i=t.getCalculation().getNamedFormulas().getByName(e);return i?`=${i.getExpression()}${Zr(i.getScope(),i.getName())}`:`unknown — evaluates to #NAME?`}(t,n);case`table`:{let e=n.getTables().getByName(t)??n.getWorkbook()?.getSheets().getItems().map(e=>e.getTables().getByName(t)).find(Boolean)??null;return e?((e,t)=>{let n=e.getSheet(),r=e.toString();return!n||t&&n.getName()===t.getName()||r.includes(`!`)?r:`${I(n.getName())}!${r}`})(e.getRange(),n):`unknown — evaluates to #NAME?`}case`column`:{if(!r)return`column of the enclosing table`;let e=n.getTables().getByName(r);if(!e)return`column of ${r}`;let i=t.replace(/^\[|\]$/g,``).trim();return e.getColumns().find(e=>e.getName()===i)?`${r} column`:`no such column in ${r} — evaluates to #REF!`}}return``}async function $r(e,t){let n=t?.maxTokens??200,r=new N,i=(e=>e.isINamed?e:null)(e);if(r.h1(i?`Name — ${_t(i)}`:`Formula`),r.text(r.codespan(`=`+e.getExpression())),r.blank(),i){i.isHidden()&&r.fact(`Hidden: true — not offered in the UI; formulas resolve it normally`);let e=i.getComment();e&&r.fact(`Comment: ${e}`);let t=i.getRanges?.();r.fact(`Refers to: ${t?t.getAddress():`no range — this name holds an expression`}`)}await async function(e,t){let n;try{n=await t.evaluate()}catch(t){e.fact(`Value: did not evaluate — ${t?.message??String(t)}`);return}if((r=n)&&typeof r==`object`&&!0===r.isIRange)return void e.fact(`Value: spills ${n.getRowCount()}×${n.getColumnCount()} — an array result`);var r;let i=a(n);e.fact(`Value: ${i?i.display:`(empty)`}`)}(r,e),r.fact(`Status: ${e.getCalculationStatus()}`),e.isValid()||r.fact(`Valid: false — the text did not parse as a complete expression`);let o=Xr.filter(([t])=>e[t]()).map(([,e])=>e);o.length>0&&r.fact(`Flags: ${o.join(` · `)}`),r.blank();let s=e.getReferences(),c=t?.context??s?.getSheet()??null,l=function(e,t){let n=new Map,r=null;for(let i of e){let e=i.text?.trim();if(!e)continue;let a;switch(i.type){case Gr:a=`function`;break;case Kr:a=`named`;break;case qr:a=`table`,r=e;break;case Jr:a=`column`;break;case Yr:a=`external`;break;default:continue}let o=`${a}${e.toLowerCase()}`,s=n.get(o);s?s.uses++:n.set(o,{kind:a,text:e,uses:1,resolution:Qr(a,e,t,r)})}return[...n.values()]}(e.getTokens(),c);if(l.length>0){r.h2(`Symbols (${l.length})`);let e=r.beginFrame([`Kind`,`Symbol`,`Uses`,`Resolves to`]);for(let t of l)e.addRow([t.kind,t.text,String(t.uses),t.resolution]);e.endFrame(),c||r.text("…no sheet context — pass `context` to resolve these"),r.blank()}if(r.h2(`References`),s&&s.length!==0)for(let e=0;e<s.length;e++)r.text(` ${String(e).padStart(2)} ${s.at(e).getAddress()}`);else r.text(`None`);r.blank(),i&&await async function(e,t){await t.getDirectDependents()||(e.h2(`Dependents (0)`),e.text(` None — no formula references this name`),e.blank()),await rr(e,t)}(r,i);let u=e.getTokens();if(r.h2(`Tokens`),u.length===0)r.text(`None`);else{let e=u.length>n?u.slice(0,n):u,t=r.beginFrame([`#`,`Type`,`Text`,`Enclosing`,`Arg`]);for(let n=0;n<e.length;n++){let r=e[n],i=r.context;t.addRow([{text:String(n),alignment:`right`},r.type??``,r.text??``,i?.name??``,i&&i.argIndex>=0?String(i.argIndex):``])}t.endFrame(),e.length<u.length&&r.text(`…truncated at ${e.length} of ${u.length} tokens · search getTokens() directly`)}return r.toLines().join(`
|
|
20
|
+
`).trimEnd()}var ei=[`Workbook_Open`,`Auto_Open`,`Workbook_BeforeClose`,`Auto_Close`,`Workbook_SheetChange`,`Workbook_BeforeSave`,`Workbook_NewSheet`,`Worksheet_Change`,`Worksheet_SelectionChange`,`Worksheet_Activate`,`Worksheet_BeforeDoubleClick`,`Worksheet_Calculate`],ti=e=>{let t=[];for(let n of ei)RegExp(`(?:Sub|Function)\\s+${n}\\b`,`i`).test(e)&&t.push(n);return t},ni=e=>{try{return e.getFunctions().getItems({type:`autoRun`}).map(e=>e.getName())}catch{return[]}},ri=e=>{let t=e.getScope();return t?!0===t.isISheet?`sheet '${t.getName()}'`:`workbook`:`global`},ii=e=>{let t=(e=>e.getSource()?.trim()??``)(e);return{module:e,name:e.getName(),language:e.getLanguage(),scope:ri(e),body:t,lines:t.length===0?0:t.split(`
|
|
21
|
+
`).length,runsInExcel:ti(t),runsHere:ni(e),executable:!!e.toJSON().compiled}};function ai(e){let t=[],n=e.getModules?.();n&&t.push(...n.getItems({language:null}));for(let n of e.getSheets().getItems())t.push(...n.getModules().getItems({language:null}));return t}function oi(e,t,n){if(t.length===0)return;let r=t.map(ii),i=r.filter(e=>e.lines>0);if(i.length===0)return e.h2(`Code (none)`),e.text(`${r.length} module${r.length===1?``:`s`}, none with any source.`),void e.blank();e.h2(`Code (${i.length} module${i.length===1?``:`s`})`);let a=i.filter(e=>!e.executable);if(a.length>0){let t=[...new Set(a.map(e=>e.language))].sort();e.text(`SheetXL reads ${t.join(` and `)} as source only and never runs it.`),a.length===i.length&&e.text(`Values in this workbook were computed by whatever wrote the file, not by these modules.`),e.blank()}let o=i.filter(e=>e.runsInExcel.length>0||e.runsHere.length>0);if(o.length>0){e.text(e.bold(`Runs on its own:`));for(let t of o)t.runsHere.length>0&&e.fact(`${t.name} · ${t.runsHere.join(`, `)} — SheetXL ran this when the workbook loaded`),t.runsInExcel.length>0&&e.fact(`${t.name} · ${t.runsInExcel.join(`, `)} — Excel runs this on open; SheetXL did not`);e.blank()}let s=n?.maxModules??40,c=i.length>s?i.slice(0,s):i,l=e=>[...e.runsHere,...e.runsInExcel].join(`, `),u=c.some(e=>l(e).length>0),d=[`Module`,`Language`,`Scope`,`Lines`];u&&d.push(`Runs`);let f=e.beginFrame(d);for(let e of c){let t=[{text:e.name},{text:e.language},{text:e.scope},{text:String(e.lines),alignment:`right`}];u&&t.push({text:l(e)}),f.addRow(t)}f.endFrame(),c.length<i.length&&e.text(` …and ${i.length-c.length} more · wb.getModules() renders the full view`),e.blank()}function si(e,t,n,r){n(`Module — ${t.name}`),e.blank();let i=[`language: ${t.language}`,`scope: ${t.scope}`,`lines: ${t.lines===0?`empty`:t.lines}`];if(t.runsHere.length>0&&i.push(`ran on load: ${t.runsHere.join(`, `)}`),t.runsInExcel.length>0&&i.push(`Excel runs on open: ${t.runsInExcel.join(`, `)}`),e.fact(i),e.blank(),t.lines===0)return void e.text(`No source. Excel writes an empty document module for the workbook and for each sheet whether or not anyone wrote code in it.`);t.executable||e.text(`SheetXL reads ${t.language} as source only and never runs it.`),e.blank();let a=r?.maxSourceLines??200,o=t.body.split(`
|
|
20
22
|
`),s=o.length>a?o.slice(0,a):o;e.text(e.code(s.join(`
|
|
21
|
-
`),t.language)),s.length<o.length&&e.text(`…and ${o.length-s.length} more lines · getSource() returns the whole module`)}function
|
|
22
|
-
`).trimEnd()}function
|
|
23
|
-
`).trimEnd();let i=r.map(
|
|
24
|
-
`).trimEnd()}var
|
|
25
|
-
`).trimEnd();let i=new Set(
|
|
26
|
-
`).trimEnd()}var
|
|
23
|
+
`),t.language)),s.length<o.length&&e.text(`…and ${o.length-s.length} more lines · getSource() returns the whole module`)}function ci(e,t){let n=new N;return si(n,ii(e),e=>n.h1(e),t),n.toLines().join(`
|
|
24
|
+
`).trimEnd()}function li(e,t){let n=new N,r=e.getItems({language:null})??[];if(n.h1(`Modules — ${r.length} module${r.length===1?``:`s`}`),n.blank(),r.length===0)return n.text(`None`),n.toLines().join(`
|
|
25
|
+
`).trimEnd();let i=r.map(ii);oi(n,r,t);for(let e of i)e.lines!==0&&(si(n,e,e=>n.h2(e),t),n.blank());return n.toLines().join(`
|
|
26
|
+
`).trimEnd()}var ui=[[`formula`,`Names`],[`table`,`Tables`]];async function di(e,t){let n=new N,r=e.getItems({includeHidden:!0})??[];if(n.h1(`Names — ${r.length} item${r.length===1?``:`s`}`),n.blank(),r.length===0)return n.text(`None`),n.toLines().join(`
|
|
27
|
+
`).trimEnd();let i=new Set(ui.map(([e])=>e));for(let[e,i]of ui)await R(n,r.filter(t=>t.getType()===e),{...t,heading:i,symbols:r});let a=r.filter(e=>!i.has(e.getType())),o=[...new Set(a.map(e=>e.getType()))].sort();for(let e of o)await R(n,a.filter(t=>t.getType()===e),{...t,heading:e,symbols:r});return n.toLines().join(`
|
|
28
|
+
`).trimEnd()}var q=e=>{if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null};function fi(e,t){let n=t?.maxCells??1e3,r=Array.isArray(e)?e:[e],i=new N;if(i.h1(`Records`),i.text(`Count: ${r.length}`),i.blank(),r.length===0)return i.text(`None`),i.toLines().join(`
|
|
27
29
|
`).trimEnd();let a=e=>{let t=[],n=new Set;for(let r of e)for(let e of Object.keys(r??{}))n.has(e)||(n.add(e),t.push(e));return t},o=Math.max(1,a(r).length),s=c(r.length,Math.max(1,Math.floor(n/o))),l=r.length>s?r.slice(0,s):r,u=l.length===r.length?a(r):a(l);if(u.length===0)return i.text(`No fields`),i.toLines().join(`
|
|
28
|
-
`).trimEnd();let d=i.beginFrame(u);for(let e of l)d.addRow(u.map(t=>
|
|
29
|
-
`).trimEnd()}var
|
|
30
|
-
`).trimEnd();let f=a.map(e=>s&&!e.isName?`${
|
|
31
|
-
`).trimEnd()}var
|
|
32
|
-
`).trimEnd()}var
|
|
33
|
-
`).trimEnd()}var
|
|
34
|
-
`).trimEnd()}function
|
|
35
|
-
`).trimEnd();let s=c(i,Math.max(1,Math.floor(n/a))),l=i>s?r.slice(0,s):r,u=o.beginFrame(Array(a).fill(``));for(let e of l)u.addRow(Array.from({length:a},(t,n)=>
|
|
36
|
-
`).trimEnd()}var
|
|
37
|
-
`).trimEnd()}function
|
|
38
|
-
`),i.push({label:`formula`,extent:
|
|
39
|
-
None`:t.slice(0,Q).map(
|
|
30
|
+
`).trimEnd();let d=i.beginFrame(u);for(let e of l)d.addRow(u.map(t=>pi(e?.[t])));return d.endFrame(),l.length<r.length&&i.text(`…truncated at ${l.length} of ${r.length} records · filter, sort or aggregate the array in the expression`),i.toLines().join(`
|
|
31
|
+
`).trimEnd()}var pi=e=>{if(e==null)return{text:``};if(typeof e==`function`)return{text:`[Function]`};if(typeof e==`bigint`||typeof e==`symbol`)return{text:J(String(e))};if(typeof e==`object`){if(e instanceof Date)return{text:e.toISOString()};let t=e;if(!0===t.isFormulaError||!0===t.isIRichData)return{text:J(mi(e))};if(q(e)||Array.isArray(e)){let t;try{t=JSON.stringify(e)??String(e)}catch{t=`[circular]`}return{text:J(t)}}return{text:J(String(e))}}let t=J(mi(e).replace(/[\r\n]+/g,` `));return typeof e==`number`?{text:t,alignment:`right`}:{text:t}},mi=e=>{try{return a(e)?.match??String(e)}catch{return String(e)}},J=e=>e.length>80?`${e.slice(0,79)}…`:e;function hi(e,t){let n=e.length,r=c(n,t?.maxRanges??100),i=Math.min(n,r),a=[];for(let t=0;t<i;t++){let n=e.at(t);a.push({...hr(n),detail:[gr(n),pr(n)].filter(Boolean).join(` `)})}let o=a.filter(e=>!e.isName),s=o.length>0&&o.some(e=>e.sheet!==o[0].sheet),l=o.length>0?o[0].sheet:e.getSheet()?.getName(),u=new N,d=a.length>0&&!s&&!!l;if(u.h1(d?`Ranges — ${I(l)} (${n})`:`Ranges (${n})`),a.length===0)return u.text(`none`),u.toLines().join(`
|
|
32
|
+
`).trimEnd();let f=a.map(e=>s&&!e.isName?`${I(e.sheet)}!${e.address}`:e.address),p=Math.max(...f.map(e=>e.length));for(let e=0;e<a.length;e++)u.text(` ${f[e].padEnd(p)} ${a[e].detail}`.trimEnd());return i<n&&u.text(` …and ${n-i} more · loop the collection in code to see them all`),u.toLines().join(`
|
|
33
|
+
`).trimEnd()}var gi=e=>/<location\b[^>]*?\sref="([^"]*)"/.exec(e.getXML()??``)?.[1]??``;async function _i(t,n){let r=new N,i=t.getSelectedRange(),a=t.getUsedRange();r.h1(`Sheet — ${I(t.getName())}${function(t){let n=t.getWorkbook(),r=``;n&&n.getSelectedSheet()?.getId()===t.getId()&&(r+=` (selected)`);let i=t.getVisibility();return i===e.ISheet.Visibility.Hidden?r+=` (hidden)`:i===e.ISheet.Visibility.VeryHidden&&(r+=` (very hidden)`),t.getProtection().isLocked()&&(r+=` (protected)`),r}(t)}`),r.text(`Used: ${a?F(a):`empty`}`),r.text(`Selection: ${F(i)}`);let o=Et(t);o&&r.text(`Outline: ${o}`),r.blank();let s=a??i;dt(r,s),ft(r,s,{profile:!0,...n});let c=n?.features===void 0?null:typeof n.features==`string`?[n.features]:[...n.features];return c&&!c.some(e=>e===`unlock`||e===`protection`)||kr(r,t),await kt(r,s),function(e,t){if(t.length===0)return;let n=t.map(e=>({address:gi(e),name:e.getName()})),r=Math.max(...n.map(e=>e.address.length));e.h2(`Pivot Tables (${t.length})`);for(let t of n)e.text(r>0?` ${t.address.padEnd(r)} ${t.name}`:` ${t.name}`);e.text(` Read-only — the cells hold the last refresh; getXML() on one is its definition.`),e.blank()}(r,t.getPivotTables().getItems()),_n(r,t.getMovables().getItems()),r.toLines().join(`
|
|
34
|
+
`).trimEnd()}var vi=1e4,yi=[[`numericalCount`,`Numbers`],[`sum`,`Sum`],[`min`,`Min`],[`max`,`Max`],[`average`,`Average`],[`stdDev`,`StdDev`]];function bi(t){let r=new N,i=t.getCoords(),o=i?e.AddressUtils.rangeToString(i):null;r.h1(o?`Stats — ${o}`:`Stats`);let s=t.getTypedCounts();r.fact(`Cells: ${t.getSize()}`),r.fact(`Values: ${t.getCount()}`);let c=s[e.ScalarType.Error]??0;c>0&&r.fact(`Errors: ${c}`);let l=function(e){let t=e.getFrequencies({limit:vi}),n=t.getUniqueCount();if(n===0)return null;if(t.isTruncated())return`${n.toLocaleString(`en-US`)}+ (scan capped at ${vi.toLocaleString(`en-US`)})`;if(n===t.getTotalCount())return`${n.toLocaleString(`en-US`)}, no repeats`;let r=[];for(let[e,n]of t.getValueCounts()){let i=t.getExtent(e);r.push({label:a(e)?.display??``,content:n,styled:n,blocks:i&&xi(i)===n?[i]:[]})}let i={countStyle:`times`,maxValues:8,recovery:`getStats().getFrequencies()`};if(n<=8)return`${n} · ${O(r,i)}`;let o=r.filter(e=>e.content>1);return`${n.toLocaleString(`en-US`)} · repeats ${O(o,i)}`}(t);l&&r.fact(`Distinct: ${l}`);let u=t.getAggregates({onError:`ignore`});for(let[e,t]of yi){let i=u[e];i!=null&&r.fact(`${t}: ${n(i)}`)}let d=[];for(let[t,n]of Object.entries(s))t!==e.ScalarType.Null&&n&&d.push(`${t.charAt(0).toUpperCase()}${t.slice(1)}: ${n}`);return d.length>0&&(r.blank(),r.h2(`Type`),r.fact(d)),r.toLines().join(`
|
|
35
|
+
`).trimEnd()}var xi=e=>(e.rowEnd-e.rowStart+1)*(e.colEnd-e.colStart+1);function Si(e){let t=new N;t.h1(`Style`),t.text(`Named: ${e.getNamed().getName()}`),t.blank();let n=e.toJSON(),r=n?Object.entries(n).filter(([,e])=>e!==void 0):[];if(r.length===0)t.fact(`No direct styling (inherits the named style)`);else for(let[e,n]of r)t.fact(`${e}: ${t.codespan(typeof n==`string`?n:JSON.stringify(n))}`);return t.toLines().join(`
|
|
36
|
+
`).trimEnd()}function Ci(e,t){let n=t?.maxCells??1e3,r=wi(e)?e.getValues():e,i=r.length,a=r.reduce((e,t)=>Math.max(e,t?.length??0),0),o=new N;if(o.h1(`Values`),o.text(`Size: ${i}×${a}`),o.blank(),i===0||a===0)return o.text(`None`),o.toLines().join(`
|
|
37
|
+
`).trimEnd();let s=c(i,Math.max(1,Math.floor(n/a))),l=i>s?r.slice(0,s):r,u=o.beginFrame(Array(a).fill(``));for(let e of l)u.addRow(Array.from({length:a},(t,n)=>Ti(e?.[n])));return u.endFrame(),l.length<i&&o.text(`…truncated at ${l.length} of ${i} rows · slice or aggregate in the expression before returning it`),o.toLines().join(`
|
|
38
|
+
`).trimEnd()}var wi=e=>!!e&&typeof e==`object`&&!0===e.isIRange,Ti=e=>{if(e==null)return{text:``};let t=(a(e)?.display??``).replace(/[\r\n]+/g,` `);return typeof e==`number`?{text:t,alignment:`right`}:{text:t}},Y=e.ICellRange.Feature,Ei=[[Y.Font,`fonts`],[Y.NumberFormat,`formats`],[Y.Fill,`fills`],[Y.Borders,`borders`],[Y.Alignment,`alignments`]];async function Di(t,n){let r=new N;r.h1(`Workbook — ${t.getName()??`Untitled`}`),r.text(`Locale: ${t.getRuntime().getLocale()}`);let i=t.getCalculation();i.getStatus()===e.ICalculation.Status.Off?r.text(`Calculation: off — formulas have not been evaluated; values are as loaded. wb.getCalculation().calculate() evaluates them`):i.getStatus()===e.ICalculation.Status.Error?r.text(`Calculation: error — the engine failed to start; values are as loaded. wb.getCalculation().start() tries again`):i.getCalculationMode()===e.ICalculation.CalculationMode.Manual&&r.text(`Calculation: manual — values are as of the last calculation. wb.getCalculation().calculate() refreshes them`);let a=wr(t.getProtection());a&&r.text(`Protection: ${a}`),r.blank();let o=t.getSheets().getItems({visibility:e.ISheet.Visibility.VeryHidden}),s=t.getSelectedSheet(),c=t.getStyles().getNormal(),l=[];for(let e of o){let t=Oi(e,c);l.push({sheet:e,label:Pi(e,e.getId()===s.getId()),counts:t.counts,lines:t.lines,formulaSignature:t.formulaSignature})}let u=new Map;for(let e of l){if(!e.formulaSignature)continue;let t=u.get(e.formulaSignature);t?t.push(e):u.set(e.formulaSignature,[e])}for(let e of u.values())if(!(e.length<2))for(let t of e){let n=e.filter(e=>e!==t).map(e=>I(e.sheet.getName()));t.lines.push({label:`twin of`,extent:n.join(`, `),detail:``})}let d=l;if(l.length>250){d=l.slice(0,250);let e=l.find(e=>e.sheet.getId()===s.getId());e&&!d.includes(e)&&(d[d.length-1]=e)}r.h2(`Sheets (${l.length})`),r.blank();let f=d.flatMap(e=>e.lines).filter(e=>e.detail),p=Math.max(9,...d.flatMap(e=>e.lines).map(e=>e.label.length))+1,m=Math.max(0,...f.map(e=>e.extent.length))+2;for(let e of d){r.h3(e.label),e.lines.length===0&&r.text(` empty`);for(let t of e.lines){let e=t.detail?` ${t.label.padEnd(p)}${t.extent.padEnd(m)}${t.detail}`:` ${t.label.padEnd(p)}${t.extent}`;r.text(e.trimEnd())}r.blank()}return d.length<l.length&&(r.text(`…and ${l.length-d.length} more sheets · wb.getSheets().getItems() lists all`),r.blank()),Fi(r,`Errors`,l,Y.Error),Fi(r,`Calc Failures`,l,Y.CalcError),Fi(r,`Circular References`,l,Y.Circular),await R(r,t.getNames().getItems({type:`formula`,includeHidden:!0})??[],{maxNames:n?.maxNames??30,recovery:`wb.getNames() renders the full view`,symbols:t.getNames().getItems({includeHidden:!0})??[]}),oi(r,ai(t),n),r.toLines().join(`
|
|
39
|
+
`).trimEnd()}function Oi(e,t){let n=e.getUsedRange();if(!n)return{counts:null,lines:[...Ai(e),...ki(e),...ji(e)],formulaRegions:0,formulaSignature:``};let r=n.getCounts([Y.Contentful,Y.Formula,Y.Error,Y.CalcError,Y.Circular,Y.Table]),i=[],a=pt(n),o=[...n.getRegions(Y.Formula)];if(a.length>0){let e=function(e,t){let n=Ne(e,t);return n.length===0?null:n.map(([e,t])=>`${e} ×${ge(t)}`).join(` · `)}(n,o);i.push({label:`content`,extent:Ni(a),detail:[X(r[Y.Contentful]??0,`cell`),X(a.length,`block`),e,`${L(n)} lists the blocks`].filter(Boolean).join(` · `)})}let s=``;if(o.length>0){let e=new Set,t=[];for(let n of o){let r=n.getCell().getFormulaText({r1c1:!0})??``;e.add(r),t.push(`${n.toString()}${r}`)}s=t.sort().join(`
|
|
40
|
+
`),i.push({label:`formula`,extent:Ni(o),detail:[X(r[Y.Formula]??0,`cell`),X(o.length,`region`),`${e.size} distinct`].join(` · `)})}for(let[e,t]of[[Y.Error,`errors`],[Y.CalcError,`calc failures`],[Y.Circular,`circular`]]){let a=r[e]??0;if(a===0)continue;let o=[...n.getRegions(e)];i.push({label:t,extent:Ni(o),detail:[X(a,`cell`),X(o.length,`region`)].join(` · `)})}let c=n.getTables();c.length>0&&i.push({label:`tables`,extent:Ni(c.map(e=>e.getRange())),detail:[X(r[Y.Table]??0,`cell`),X(c.length,`table`),Mi(c.map(e=>e.getName()))].join(` · `)});let l=e.getPivotTables().getItems();l.length>0&&i.push({label:`pivots`,extent:String(l.length),detail:Mi(l.map(e=>e.getName()))}),i.push(...Ai(e));let u=a.map(e=>e.getCoords()),d=[];for(let[n,r]of Ei){let i=je(e,n,t,{content:u})?.distinct??0;i>0&&d.push(`${r} ${i}`)}return d.length>0&&i.push({label:`style`,extent:n.toString(),detail:d.join(` · `)}),i.push(...ki(e)),i.push(...ji(e)),{counts:r,lines:i,formulaRegions:o.length,formulaSignature:s}}function ki(e){let t=Et(e);return t?[{label:`outline`,extent:``,detail:t}]:[]}function Ai(e){let t=[];for(let[n,r]of gn(e.getMovables().getItems())){let i=un(r),a=n===`chart`?Mi(r.map(fn)):i.length>0?`${i.length} with text`:``;t.push({label:hn(n).toLowerCase(),extent:String(r.length),detail:a});let o=i.slice(0,c(i.length,5));for(let e of o)t.push({label:``,extent:sn(e.movable),detail:cn(e)+(e.movable.isHidden()?` (hidden)`:``)});o.length<i.length&&t.push({label:``,extent:``,detail:`…and ${i.length-o.length} more · wb.getSheet(${JSON.stringify(e.getName())}) quotes every one`})}return t}function ji(e){let t=Or(e);return t?[{label:`protected`,extent:t.extent,detail:t.detail}]:[]}function Mi(e){let t=[],n=0;for(let r of e){let e=(t.length>0?2:0)+r.length;if(t.length>0&&n+e>60)break;t.push(r),n+=e}let r=e.length-t.length;return r>0?`${t.join(`, `)}, +${r} more`:t.join(`, `)}function Ni(t){let n=null;for(let e of t){let t=e.getCoords();n=n?{rowStart:Math.min(n.rowStart,t.rowStart),colStart:Math.min(n.colStart,t.colStart),rowEnd:Math.max(n.rowEnd,t.rowEnd),colEnd:Math.max(n.colEnd,t.colEnd)}:t}return n?e.AddressUtils.rangeToString(n)??``:``}var X=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function Pi(t,n){let r=t.getVisibility(),i=``;return n&&(i+=` (selected)`),r===e.ISheet.Visibility.Hidden?i+=` (hidden)`:r===e.ISheet.Visibility.VeryHidden&&(i+=` (very hidden)`),t.getProtection().isLocked()&&(i+=` (protected)`),`${I(t.getName())}${i}`}function Fi(t,n,r,i){let a=r.reduce((e,t)=>e+(t.counts?.[i]??0),0),o=i===Y.Error?r.flatMap(e=>function(e){let t=[];for(let n of e.getMovables().getItems({type:`chart`})){let e=z(n);if(e)for(let r of e.getSeries()){let e=Ft(r);if(e.length===0)continue;let i=r.getName();t.push({movable:n,detail:`series ${i?`"${B(i)}"`:`(unnamed)`} ${e.join(` · `)}`})}}return t}(e.sheet)):[];if(a===0&&o.length===0)return;let s=[],c=0;for(let e of r){if(!e.counts?.[i])continue;let t=e.sheet.getUsedRange();if(!t)continue;let n=I(e.sheet.getName());for(let e of t.getRegions(i))c++,s.length>=20||s.push({address:`${n}!${e.toString()}`,size:`${e.getRowCount()}×${e.getColumnCount()}`,payload:Ii(e)})}let l=o.slice(0,20);for(let{movable:t,detail:n}of l){let r=t.getRange();s.push({address:`${I(r.getSheet().getName())}!${e.AddressUtils.rangeToString(r.getCoords())??``}`,size:`chart`,payload:`${t.getContent().getName?.()||`(unnamed)`} · ${n}`})}let u=[];a>0&&u.push(String(a)),o.length>0&&u.push(`${o.length} in charts`),t.h2(`${n} (${u.join(` · `)})`);let d=Math.max(0,...s.map(e=>e.address.length)),f=Math.max(0,...s.map(e=>e.size.length));for(let e of s)t.text(` ${e.address.padEnd(d)} ${e.size.padEnd(f)} ${e.payload}`.trimEnd());c>s.length-l.length&&t.text(` …and ${c-(s.length-l.length)} more · getRegions('${i}') on a sheet's used range lists the rest`),o.length>l.length&&t.text(` …and ${o.length-l.length} more in charts · a sheet's report lists its charts under Charts`),t.blank()}function Ii(e){let n=e.getCell(),r=i(n,t.Mode.Display)?.display??``,a=n.getFormulaText();return a?`${r} ${a}`.trim():r}var Z=(e,t)=>!!e&&typeof e==`object`&&!0===e[t],Li={kind:`protectedRanges`,is:e=>Z(e,`isIProtectedRangeCollection`),render:e=>{let t=e.getItems();return t.length===0?`# Unlocked Ranges (0)
|
|
41
|
+
None`:t.slice(0,Q).map(Nr).concat(t.length>Q?[`…and ${t.length-Q} more · render one at a time to see them`]:[]).join(`
|
|
40
42
|
|
|
41
|
-
`)}},Q=20,
|
|
43
|
+
`)}},Q=20,Ri=[{kind:`workbook`,is:e=>Z(e,`isIWorkbook`),render:(e,t)=>Di(e,t)},{kind:`sheet`,is:e=>Z(e,`isISheet`),render:(e,t)=>_i(e,t)},{kind:`cell`,is:e=>Z(e,`isICell`),render:(e,t)=>Fr(e,t)},{kind:`names`,is:e=>Z(e,`isINamedCollection`),render:(e,t)=>di(e,t)},{kind:`modules`,is:e=>Z(e,`isIModuleCollection`),render:(e,t)=>li(e,t)},{kind:`module`,is:e=>Z(e,`isIModule`),render:(e,t)=>ci(e,t)},{kind:`formula`,is:e=>Z(e,`isIFormula`),render:(e,t)=>$r(e,t)},{kind:`table`,is:e=>Z(e,`isITable`),render:e=>rt(e)},{kind:`movable`,is:e=>Z(e,`isIMovable`),render:e=>yn(e)},{kind:`shape`,is:e=>Z(e,`isIShape`),render:e=>bn(e)},{kind:`conditionalFormat`,is:e=>Z(e,`isIConditionalFormat`),render:e=>Vr(e)},{kind:`dataValidation`,is:e=>Z(e,`isIDataValidation`),render:e=>Ur(e)},{kind:`protection`,is:e=>Z(e,`isISheetProtection`)||Z(e,`isIWorkbookProtection`),render:e=>Mr(e)},Li,{kind:`protectedRange`,is:e=>Z(e,`isIProtectedRange`),render:e=>Nr(e)},{kind:`stats`,is:e=>Z(e,`isIRangeStats`),render:e=>bi(e)},{kind:`counts`,is:e=>Z(e,`isICellRangeCounts`),render:e=>Hr(e)},{kind:`style`,is:e=>Z(e,`isIStyle`),render:e=>Si(e)},{kind:`regions`,is:e=>Z(e,`isICellRegions`),render:(e,t)=>et(e,t)},{kind:`cellRange`,is:e=>Z(e,`isICellRange`),render:(e,t)=>Br(e,t)},{kind:`ranges`,is:e=>Z(e,`isICellRanges`),render:(e,t)=>hi(e,t)},{kind:`range`,is:e=>Z(e,`isIRange`),render:(e,t)=>Ci(e,t)},{kind:`values`,is:e=>Array.isArray(e)&&e.length>0&&e.every(e=>Array.isArray(e)),render:(e,t)=>Ci(e,t)},{kind:`records`,is:e=>Array.isArray(e)&&e.length>0&&e.every(q),render:(e,t)=>fi(e,t)},{kind:`record`,is:e=>q(e),render:(e,t)=>fi(e,t)},{kind:`items`,is:e=>Array.isArray(e)&&e.length>0&&e.every(e=>!!$(e)),render:async(e,t)=>{let n=e.length>Q?e.slice(0,Q):e,r=[];for(let e of n)r.push(await $(e).render(e,t));return n.length<e.length&&r.push(`…and ${e.length-n.length} more · render one at a time to see them`),r.join(`
|
|
42
44
|
|
|
43
|
-
`)}}],
|
|
44
|
-
`)}let n=
|
|
45
|
-
`):null},exports.apiTool=
|
|
45
|
+
`)}}],zi=Ri.map(e=>e.kind),Bi=class extends Error{constructor(e){super(e),this.name=`NoRendererError`}};function $(e){for(let t of Ri)if(t.is(e))return t;return null}async function Vi(e,t,n){await e?.getCalculation().ready();let r=$(t),i=t;if(!r&&i&&typeof i==`object`&&!Array.isArray(i)&&typeof i[Symbol.iterator]==`function`){let e=[];for(let t of i)if(e.push(t),e.length>=1e3)break;i=e,r=$(i)}if(!r)throw new Bi(`No markdown renderer for this value. Renderable kinds: ${zi.join(`, `)}.`);return r.render(i,n)}var Hi=[Vn],Ui=[nr];exports.API_ENTRY_POINTS=Hn,Object.defineProperty(exports,"CellEncoding",{enumerable:!0,get:function(){return t}}),exports.GREP_FIELDS=o,exports.GREP_FIELDS_DEFAULT=s,exports.GrepField={Display:`display`,Value:`value`,Formula:`formula`,Hyperlink:`hyperlink`,NumberFormat:`numberFormat`,Comment:`comment`,Shape:`shape`,Chart:`chart`,Name:`name`},exports.MarkdownBuilder=N,exports.MarkdownFrameSection=Ze,exports.NoRendererError=Bi,exports.REFERENCES=Ui,exports.RENDERABLE_KINDS=zi,exports.RENDERERS=Ri,exports.RENDER_OPTION_KEYS=vr,exports.REPORTED_FEATURES=it,exports.TOOLS=Hi,exports.apiPointerFor=function(e,t){let n=/\bon type '(?:SheetXL\.)?([A-Z][\w$]*(?:\.[A-Z][\w$]*)*)'/.exec(e)?.[1];return n?`\`${t} ${n}\` lists its members.`:null},exports.apiSuggestionsFor=function(e,t,n){let r=/Property '([\w$]+)' does not exist on type '(?:SheetXL\.)?([A-Z][\w$]*(?:\.[A-Z][\w$]*)*)'/.exec(t),i=r?null:/(?:^|[.\s])([A-Za-z_$][\w$]*) is not a function/.exec(t),a=r?.[1]??i?.[1];if(!a)return null;let o=[];for(let t of Yn){let[n,r]=t.relies;t.match.test(a)&&e.types[n]?.members?.some(e=>e.name===r)&&o.push(t.hint)}let s=r?H(e,r[2]):null;if(s){let r=Xn(e,s),i=/Did you mean '([\w$]+)'/.exec(t)?.[1],c=r.map(e=>({member:e,score:e.name===i?-1:Zn(a,e.name)})).filter(e=>e.score!==null).sort((e,t)=>e.score-t.score).slice(0,3);if(c.length>0){o.push(`Closest on ${s}:`);for(let{member:e}of c)o.push(` ${Qn(e)}`)}o.push(`\`${n} ${s}\` lists all ${r.length} members.`)}else if(i){let t=Object.entries(e.types).filter(([,e])=>e.members?.some(e=>e.name===a)).map(([e])=>e);if(t.length>0){let e=t.slice(0,3).join(`, `),n=t.length>3?` and ${t.length-3} more`:``;return o.push(`'${a}' is a member of ${e}${n}, not of the object it was called on.`),o.join(`
|
|
46
|
+
`)}let n=Hn.map(t=>H(e,t)).filter(e=>e!==null).flatMap(t=>Xn(e,t).map(e=>({owner:t,member:e,score:Zn(a,e.name)}))).filter(e=>e.score!==null&&e.score>0&&e.score<=2).sort((e,t)=>e.score-t.score).slice(0,3);if(o.length===0&&n.length===0)return null;if(o.unshift(`No SheetXL member is named '${a}'.`),n.length>0){o.push(`Closest:`);for(let{owner:e,member:t}of n)o.push(` ${Qn(t,e)}`)}}return o.length>0?o.join(`
|
|
47
|
+
`):null},exports.apiTool=nr,exports.apiTypeOf=function(e,t){if(!t||typeof t!=`object`&&typeof t!=`function`)return null;let n=[],r=new Set;for(let i=t;i&&i!==Object.prototype;i=Object.getPrototypeOf(i))for(let a of Object.getOwnPropertyNames(i)){if(r.has(a)||!/^isI[A-Z]/.test(a))continue;r.add(a);let i=!1;try{i=!0===t[a]}catch{}let o=i?H(e,a.slice(2)):null;o&&!n.includes(o)&&n.push(o)}if(n.length<=1)return n[0]??null;let i=(t,n=new Set)=>{for(let r of e.types[t].extends??[]){let a=Wn(e,t,r);a&&!n.has(a)&&(n.add(a),i(a,n))}return n},a=new Set;for(let e of n)for(let t of i(e))a.add(t);return n.filter(e=>!a.has(e)).sort((t,n)=>(e.types[n].members?.length??0)-(e.types[t].members?.length??0))[0]??n[0]},exports.appendDependencies=rr,exports.appendKinds=dt,exports.appendModules=oi,exports.appendMovables=_n,exports.appendNames=R,exports.appendRegionList=$e,exports.appendRegions=ft,exports.appendRules=Dt,exports.appendShapeFacts=nn,exports.appendSheetObjects=kt,exports.appendSheetProtection=kr,exports.appendTables=nt,exports.collectModules=ai,exports.collectShapeText=un,exports.contentfulBlocks=pt,exports.countDates=T,exports.describeAlignment=h,exports.describeAllowedValues=Ke,exports.describeAnchor=sn,exports.describeApi=tr,exports.describeBorder=d,exports.describeBorderParts=p,exports.describeCellProtection=jr,exports.describeColor=l,exports.describeConditionalFormat=We,exports.describeDataValidation=Ge,exports.describeExtent=F,exports.describeFill=u,exports.describeFont=g,exports.describeLock=G,exports.describeMovableSummary=fn,exports.describeNode=gr,exports.describeNodeLabel=hr,exports.describeNodeLabels=pr,exports.describeNumberFormat=m,exports.describeOutline=Et,exports.describeQualifiedExtent=ut,exports.describeQualifiedName=_t,exports.describeQualifiedRanges=lt,exports.describeRangeProtection=Ar,exports.describeRanges=ct,exports.describeRuleStyle=Be,exports.describeRules=qe,exports.describeScale=He,exports.describeShapeText=cn,exports.describeSheetCall=L,exports.describeSheetName=I,exports.describeSums=ae,exports.describeTypeHeading=hn,exports.describeWorkbookProtection=wr,exports.detectTotals=ne,exports.encodeCell=i,exports.encodeFormattedNumber=r,exports.encodeNumber=n,exports.encodeScalar=a,exports.findNames=Ot,exports.grep=Pn,exports.grepTool=Vn,exports.groupMovables=gn,exports.isPlainRecord=q,exports.lookupApi=Jn,exports.parseFeatures=st,exports.parseRenderOptions=function(e){let t={};for(let[n,r]of Object.entries(e)){let e=_r[n];if(!e)throw Error(`Unknown report option '${n}'. Options: ${vr.join(`, `)}.`);t[n]=e(r,n)}return t},exports.profileKinds=ue,exports.profileRegion=C,exports.protectionPointerFor=function(e){return e?.name===`ProtectedError`?'`sheet.getProtection()` (`wb.getProtection()` for the workbook) lists what is still allowed; `sheet.getRegions("unlock")` lists the cells that take a write.':null},exports.quoteShapeText=Gt,exports.readShapeText=ln,exports.regionPayload=Ye,exports.regionPayloads=Xe,exports.renderApi=er,exports.renderCell=Fr,exports.renderCellRange=Br,exports.renderConditionalFormat=Vr,exports.renderCounts=Hr,exports.renderDataValidation=Ur,exports.renderFormula=$r,exports.renderGrep=Bn,exports.renderMarkdown=Vi,exports.renderModule=ci,exports.renderModules=li,exports.renderMovable=yn,exports.renderNames=di,exports.renderProtectedRange=Nr,exports.renderProtection=Mr,exports.renderRanges=hi,exports.renderRecords=fi,exports.renderRegions=et,exports.renderResult=async function(e,t,n){if(t===void 0)return{text:void 0,rendered:!0};if(typeof t==`string`)return{text:t,rendered:!0};if(typeof t==`object`&&t)try{return{text:await Vi(e,t,n),rendered:!0}}catch(e){if(!(e instanceof Bi))throw e}return function(e){if(e===null)return{text:`null`,rendered:!0};switch(typeof e){case`number`:case`boolean`:return{text:a(e)?.display??String(e),rendered:!0};case`bigint`:case`symbol`:return{text:String(e),rendered:!0};case`function`:return{text:`[Function]`,rendered:!0}}let t=e;if(!0===t.isFormulaError||!0===t.isIRichData)return{text:a(e)?.display??``,rendered:!0};let n;try{n=String(e)}catch{n=`[object Object]`}return{text:n,rendered:!1}}(t)},exports.renderShape=bn,exports.renderSheet=_i,exports.renderStats=bi,exports.renderStyle=Si,exports.renderTable=rt,exports.renderValues=Ci,exports.renderWorkbook=Di,exports.resolveRenderer=$,exports.shapeRotation=rn,exports.summarizeSheetProtection=Or;
|