@sheetxl/query 0.7.28-beta.2 → 0.7.28-beta.4

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.
@@ -1,5 +1,5 @@
1
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`],s=[`display`,`value`,`formula`],c=e=>e.getVisibility()===`visible`,l=(e,t,n)=>{let r=e.getSheets().getItems({visibility:`veryHidden`}),i=t?.trim();if(!i)return r.filter(e=>n||c(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||c(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||c(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}))},u=(e,n)=>{switch(n){case`display`:return i(e,t.Mode.Display);case`value`:return i(e,t.Mode.Value);case`raw`:return a(e.getValue());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}},d=[`hyperlink`,`numberFormat`],f=(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 p(e,t){if(!t.pattern)throw Error(`grep requires a pattern`);let n=t.fields?.length?t.fields:s,r=t.output??`content`,i=t.maxCount??200,a=!0===t.invert,o=!0===t.hidden,c=(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.`)})(t.context),p=(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.`)}}})(t),m=l(e,t.scope,o),h=!n.some(e=>d.includes(e)),g=n.includes(`display`)&&n.includes(`value`),_=r===`content`||r===`addresses`,v=[],y=[],b=0,x=0,S=!1;for(let{sheet:e,address:t}of m){if(S)continue;let s=e.getName();x++,await e.getCalculation().ready();let l=t===null?e.getUsedRange():e.getRange(t);if(!l)continue;let d=c&&r===`content`?f(c,s,l):null,m=0;l.forEach((e,t)=>{if(h&&e==null)return;let o=t.getCell(),c=[],l,f=null;for(let e of n){let t=u(o,e);if(e===`display`&&(l=t?.match??null),t!==null&&(e!==`value`||!g||(l===void 0&&(l=u(o,`display`)?.match??null),t.match!==l))&&(f===null&&(f={field:e,text:t.display}),p.test(t.match)&&(c.push({field:e,text:t.display}),r===`addresses`&&!a)))break}if(!(a?c.length>0||f===null:c.length===0)){if(i>0&&b>=i)return S=!0,{break:!0};if(b++,m++,_){let e=a?[f]:r===`addresses`?c.slice(0,1):c,n=d?.resolve(o,t.getCoords()),i=t.getAddress();for(let t of e)v.push({sheet:s,address:i,field:t.field,text:t.text,...n?{context:n}:{}})}}},o?void 0:{ignoreHidden:!0}),m>0&&y.push({sheet:s,cells:m})}return{pattern:t.pattern,fields:n,scope:t.scope?.trim()||`workbook`,matches:v,cellCount:b,sheets:y,sheetsSearched:x,sheetsMatched:y.length,truncated:S,output:r}}var m=e=>{let t=e.replace(/\s+/g,` `).trim();return t.length>120?`${t.slice(0,119)}…`:t},h=(e,t,n,r)=>{let i=t.map(e=>r?`${e.sheet}!${e.address}`: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)} ${m(s.text)}`)}};function g(e){let{pattern:t,fields:n,scope:r,matches:i,cellCount:a,sheetsSearched:o,sheetsMatched:s}=e,c=[`grep "${t}" · ${r} · fields ${n.join(`,`)} · ${a} ${a===1?`cell`:`cells`} in ${s} of ${o} ${o===1?`sheet`:`sheets`}`];if(e.output===`count`)for(let t of e.sheets)c.push(` ${t.sheet}: ${t.cells}`);else if(e.output===`sheets`){for(let t of e.sheets)c.push(` ${t.sheet}`);e.sheets.length===0&&c.push(` no matches`)}else if(i.length===0)c.push(` no matches`);else if(e.output===`addresses`)for(let e of i)c.push(` ${e.sheet}!${e.address}`);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?(c.push(` ${t.heading}`),h(c,t.rows,` `,!1)):h(c,t.rows,` `,!0)}return e.truncated&&c.push(` …truncated at ${a} ${a===1?`cell`:`cells`} · narrow the pattern, or scope the search to one sheet or range`),c.join(`
2
- `)}var _={name:`grep`,description:`Search cell contents by pattern across a workbook. Returns grid-anchored matches, each tagged with the cell 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:`Cell layers to search: display (number format applied), value (as the formula bar shows it; duplicate of display suppressed per cell), raw (the stored scalar — dates as serials), formula, hyperlink, numberFormat (the format code, e.g. "0.00%").`},{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 where no requested field matched. Only cells 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 (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:p,render:g},v=(e,t)=>e<=t+3?e:t,y=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))))})`},b=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=y(t.getForeground());if(r===e.IFill.BuiltInSheetPattern.Solid)return i?`solid ${i}`:`solid`;let a=y(t.getBackground());return[`${r} pattern`,i,a?`on ${a}`:null].filter(Boolean).join(` `)}let i=y(n.getColor?.());return i?`${r} ${i}`:r},x=e=>{let t=C(e);return t.length>0?t.join(` · `):null},S=new Set([`top`,`left`,`bottom`,`right`]),C=e=>{let t=e.getBorder(),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=y(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=>S.has(e));i.push(`${n?`outline`:t.join(`+`)} ${e}`)}return i},w=e=>{let t=e.getNumberFormat();return t&&t!==`General`?t:null},T=(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},E=(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=y(n.getColor());return a!==y(r.getColor())&&i.push(a??`no color`),i.length>0?i.join(` · `):null},D=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,O=e=>{if(!e)return null;if(typeof e!=`string`)return y(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},k=t=>{if(!t)return null;let n=[],r=(t=>{if(!t)return null;if(typeof t==`string`)return O(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=O(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:O(i.color);r&&t.push(`text ${r}`),t.length>0&&n.push(t.join(` `))}if(t.numberFormat!==void 0&&t.numberFormat!==null){let e=typeof t.numberFormat==`number`?`numFmt ${t.numberFormat}`:String(t.numberFormat);e&&n.push(e)}return t.border&&n.push(`border`),t.alignment&&n.push(`alignment`),n.length>0?n.join(` · `):null},ee=t=>{let n=t.type??e.IConditionalFormat.ColorStopType.Num,r=t.value,i=r==null||r===``?n:`${n} ${r}`,a=O(t.color);return a?`${i} ${a}`:i},te=t=>{let n=t.type;if(t.type===e.IConditionalFormat.ScaleType.DataBar){let e=O(t.color);e&&(n+=` ${e}`)}else t.type===e.IConditionalFormat.ScaleType.IconSet&&(t.iconSet&&(n+=` ${t.iconSet}`),t.reverse&&(n+=` reversed`));let r=(t.stops??[]).map(ee).join(` → `);return r?`${n} · ${r}`:n},ne=`(no rule)`,re=e=>{let t=e.getScale(),n=[];if(t)n.push(te(t));else{n.push(e.getCondition()?.toString()||ne);let t=k(e.getStyle());t&&n.push(`→ ${t}`)}return e.isStopIfTrue()&&n.push(`· stop if true`),D(n.join(` `),90)},ie=e=>{let t=[e.getCondition()?.toString()||ne],n=e.getAlertStyle();return n&&t.push(n),e.isIncludeBlanks()&&t.push(`blanks allowed`),e.isHideDropdown()&&t.push(`no dropdown`),D(t.join(` · `),90)},ae=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(`, `)},A=(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;function M(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:`cell · ${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:`list · ${ce(l,o)}`,series:[]};let f=function(e,t){let n=e.getRange(),r=n.getCoords(),i=e.getCell().getTable();if(i){let e=i.getColumns().map(e=>e.getName());return{present:!0,inside:!0,note:`table "${i.getName()}"`,names:t?e:null}}let a=t?r.rowStart+1:r.colStart+1,o=N(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(N(s)&&!o)return{present:!0,inside:!0,note:`header `+(t?`row ${r.rowStart+1}`:`column ${me(r.colStart)}`),names:oe(s,e,t)};let c=(t?r.rowStart:r.colStart)-1;if(c>=0&&!N(n)){let i=t?n.getRangeAt(c,r.colStart,c,r.colEnd):n.getRangeAt(r.rowStart,c,r.rowEnd,c);if(N(i))return{present:!0,inside:!1,note:`header ${t?`row ${c+1}`:`column ${me(c)}`} (above this block)`,names:oe(i,e,t)}}return{present:!1,inside:!1,note:`no header detected`,names:null}}(e,d),p=d?c:s,m=d?``:` · by row`,h=f.present&&f.inside,g=d&&h?u.rowStart+1:u.rowStart,_=!d&&h?u.colStart+1:u.colStart,v=u.rowEnd-g+1,y=u.colEnd-_+1,b=v*y>a,x=b&&d?Math.max(1,Math.floor(a/Math.max(1,y))):v,S=b&&!d?Math.max(1,Math.floor(a/Math.max(1,v))):y,C=Math.min(u.rowEnd,g+x-1),w=Math.min(u.colEnd,_+S-1),T=Math.min(p,r),E=[],D=[];for(let t=0;t<T;t++){let n=d?l.getRangeAt(g,u.colStart+t,C,u.colStart+t):l.getRangeAt(u.rowStart+t,_,u.rowStart+t,w);E.push(se(e,d,t,f.names)),D.push(ce(n,o))}let O=E.length?Math.max(...E.map(e=>e.length)):0,k=E.map((e,t)=>`${e.padEnd(O)} ${D[t]}`);p>T&&k.push(`…${p-T} more ${d?`columns`:`rows`} not profiled · read them with getStats()`);let ee=[f.present?`table${m}`:`block${m}`,f.note];return b&&ee.push(`profiled from the first ${d?`${x} rows`:`${S} columns`} of ${d?v:y}`),{shape:f.present?`table`:`block`,summary:ee.filter(Boolean).join(` · `),series:k}}function N(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?me(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([j.Formula])[j.Formula]??0,l=ue(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(j.Formula)];if(e.length===1){let t=e[0].getCell().getFormulaText();p.push(`formula`,t?`=${t}`:`(uniform)`)}else p.push(`formula`,`${e.length} distinct`)}else if(l===a)p.push(`date`,de(r,t));else if(u===a)p.push(`number`,de(r,t),...fe(r,t));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 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=[de(r,t),...fe(r,t)].filter(Boolean);a.push(`Number: ${o} ${e.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 ue(t){let n=0;return t.forEach((t,r)=>{r.getInteropType()===e.InteropScalarType.Date&&n++}),n}function de(e,t){let n=e.getAggregates({onError:`ignore`});if(n.min===null||n.max===null)return``;let i=t.getStyle().getNumberFormat(),a=r(n.min,i),o=r(n.max,i);return a===o?a:`${a} … ${o}`}function fe(e,t){let n=e.getAggregates({onError:`ignore`}),i=t.getStyle().getNumberFormat(),a=[];return n.sum!==null&&a.push(`Σ ${r(n.sum,i)}`),n.average!==null&&a.push(`x̄ ${r(n.average,i)}`),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?` · …`:``})`}function me(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 P=e.ICellRange.Feature,F=e=>e.getRange().getStyle(),he=e=>i(e.getCell(),t.Mode.Display)?.display??null;function ge(e,t){switch(e){case P.Formula:return e=>{let t=e.getCell().getFormulaText();return t?`=${t}`:null};case P.Error:return he;case P.CalcError:return e=>{let t=he(e)??``,n=e.getCell().getFormulaText();return(n?`${t} =${n}`:t).trim()||null};case P.Merge:return he;case P.Comments:return e=>{let t=e.getCell().getComments()?.content;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 P.Spills:return e=>e.getCell().getSpill()?.getValuesRange().toString()??null;case P.Hyperlink:return e=>e.getCell().getHyperlink()?.getAddress()??null;case P.Table:return e=>e.getCell().getTable()?.getName()??null;case P.Fill:return e=>b(F(e));case P.Border:return e=>x(F(e));case P.NumberFormat:return e=>w(F(e));case P.Alignment:return t?e=>T(F(e),t):void 0;case P.Font:return t?e=>E(F(e),t):void 0;case P.Conditionals:return e=>A(e.getRange().getConditionalFormats(),re);case P.DataValidations:return e=>A(e.getRange().getDataValidations(),ie);case P.Contentful:return e=>le(e.getRange()).join(` `)||null;default:return}}function _e(e,t){let n=e.map(e=>ge(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 I=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 ve(this,e)}_addLines(e){this._lines.push(...e)}toLines(){return[...this._lines]}},ve=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)=>ye(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)=>ye(e.text,this._colWidths[t],e.alignment)).join(` `),r=this._indexWidth>0?(e.index??``).padStart(this._indexWidth)+` `:``;n.push(`${r}${t}`.trimEnd())}return n}},ye=(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 be(e,t,n){let r=v(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)),c=i.map(e=>`${e.getRowCount()}×${e.getColumnCount()}`),l=Math.max(...c.map(e=>e.length)),u=n?.profile?n?.maxProfiled??12:0;for(let t=0;t<i.length;t++){let r=i[t],a=n?.payload?.(r),d=r.isClipped()?` ✂ clipped at the query edge — the block continues`:``,f=` ${o[t].padEnd(s)} ${c[t].padEnd(l)}`;if(t<u){let t=M(r,n);e.text(`${f} ${t.summary}${d}`);for(let n of t.series)e.text(` ${n}`);continue}e.text(a?`${f} ${a}${d}`:`${f}${d}`.trimEnd())}if(u>0&&i.length>u&&e.text(` …${i.length-u} 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 xe(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 I;return c.h1(`Regions — ${a} (${r.length})`),be(c,r,{...n,profile:o,payload:o?void 0:_e(i,s)}),c.toLines().join(`
2
+ `)}var _={name:`grep`,description:`Search cell contents by pattern across a workbook. Returns grid-anchored matches, each tagged with the cell 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:`Cell layers to search: display (number format applied), value (as the formula bar shows it; duplicate of display suppressed per cell), raw (the stored scalar — dates as serials), formula, hyperlink, numberFormat (the format code, e.g. "0.00%").`},{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 where no requested field matched. Only cells 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 (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:p,render:g},v=(e,t)=>e<=t+3?e:t,y=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))))})`},b=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=y(t.getForeground());if(r===e.IFill.BuiltInSheetPattern.Solid)return i?`solid ${i}`:`solid`;let a=y(t.getBackground());return[`${r} pattern`,i,a?`on ${a}`:null].filter(Boolean).join(` `)}let i=y(n.getColor?.());return i?`${r} ${i}`:r},x=e=>{let t=C(e);return t.length>0?t.join(` · `):null},S=new Set([`top`,`left`,`bottom`,`right`]),C=e=>{let t=e.getBorder(),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=y(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=>S.has(e));i.push(`${n?`outline`:t.join(`+`)} ${e}`)}return i},w=e=>{let t=e.getNumberFormat();return t&&t!==`General`?t:null},T=(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},E=(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=y(n.getColor());return a!==y(r.getColor())&&i.push(a??`no color`),i.length>0?i.join(` · `):null},D=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,O=e=>{if(!e)return null;if(typeof e!=`string`)return y(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},k=t=>{if(!t)return null;let n=[],r=(t=>{if(!t)return null;if(typeof t==`string`)return O(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=O(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:O(i.color);r&&t.push(`text ${r}`),t.length>0&&n.push(t.join(` `))}if(t.numberFormat!==void 0&&t.numberFormat!==null){let e=typeof t.numberFormat==`number`?`numFmt ${t.numberFormat}`:String(t.numberFormat);e&&n.push(e)}return t.border&&n.push(`border`),t.alignment&&n.push(`alignment`),n.length>0?n.join(` · `):null},ee=t=>{let n=t.type??e.IConditionalFormat.ColorStopType.Num,r=t.value,i=r==null||r===``?n:`${n} ${r}`,a=O(t.color);return a?`${i} ${a}`:i},te=t=>{let n=t.type;if(t.type===e.IConditionalFormat.ScaleType.DataBar){let e=O(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(ee).join(` → `);return r?`${n} · ${r}`:n},ne=`(no rule)`,re=e=>{let t=e.getScale(),n=[];if(t)n.push(te(t));else{n.push(e.getCondition()?.toString()||ne);let t=k(e.getStyle());t&&n.push(`→ ${t}`)}return e.isStopIfTrue()&&n.push(`· stop if true`),D(n.join(` `),90)},ie=e=>{let t=[e.getCondition()?.toString()||ne],n=e.getAlertStyle();return n&&t.push(n),e.isIncludeBlanks()&&t.push(`blanks allowed`),e.isHideDropdown()&&t.push(`no dropdown`),D(t.join(` · `),90)},ae=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(`, `)},A=(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;function M(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:`cell · ${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:`list · ${ce(l,o)}`,series:[]};let f=function(e,t){let n=e.getRange(),r=n.getCoords(),i=e.getCell().getTable();if(i){let e=i.getColumns().map(e=>e.getName());return{present:!0,inside:!0,note:`table "${i.getName()}"`,names:t?e:null}}let a=t?r.rowStart+1:r.colStart+1,o=N(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(N(s)&&!o)return{present:!0,inside:!0,note:`header `+(t?`row ${r.rowStart+1}`:`column ${me(r.colStart)}`),names:oe(s,e,t)};let c=(t?r.rowStart:r.colStart)-1;if(c>=0&&!N(n)){let i=t?n.getRangeAt(c,r.colStart,c,r.colEnd):n.getRangeAt(r.rowStart,c,r.rowEnd,c);if(N(i))return{present:!0,inside:!1,note:`header ${t?`row ${c+1}`:`column ${me(c)}`} (above this block)`,names:oe(i,e,t)}}return{present:!1,inside:!1,note:`no header detected`,names:null}}(e,d),p=d?c:s,m=d?``:` · by row`,h=f.present&&f.inside,g=d&&h?u.rowStart+1:u.rowStart,_=!d&&h?u.colStart+1:u.colStart,v=u.rowEnd-g+1,y=u.colEnd-_+1,b=v*y>a,x=b&&d?Math.max(1,Math.floor(a/Math.max(1,y))):v,S=b&&!d?Math.max(1,Math.floor(a/Math.max(1,v))):y,C=Math.min(u.rowEnd,g+x-1),w=Math.min(u.colEnd,_+S-1),T=Math.min(p,r),E=[],D=[];for(let t=0;t<T;t++){let n=d?l.getRangeAt(g,u.colStart+t,C,u.colStart+t):l.getRangeAt(u.rowStart+t,_,u.rowStart+t,w);E.push(se(e,d,t,f.names)),D.push(ce(n,o))}let O=E.length?Math.max(...E.map(e=>e.length)):0,k=E.map((e,t)=>`${e.padEnd(O)} ${D[t]}`);p>T&&k.push(`…${p-T} more ${d?`columns`:`rows`} not profiled · read them with getStats()`);let ee=[f.present?`table${m}`:`block${m}`,f.note];return b&&ee.push(`profiled from the first ${d?`${x} rows`:`${S} columns`} of ${d?v:y}`),{shape:f.present?`table`:`block`,summary:ee.filter(Boolean).join(` · `),series:k}}function N(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?me(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([j.Formula])[j.Formula]??0,l=ue(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(j.Formula)];if(e.length===1){let t=e[0].getCell().getFormulaText();p.push(`formula`,t?`=${t}`:`(uniform)`)}else p.push(`formula`,`${e.length} distinct`)}else if(l===a)p.push(`date`,de(r,t));else if(u===a)p.push(`number`,de(r,t),...fe(r,t));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 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=[de(r,t),...fe(r,t)].filter(Boolean);a.push(`Number: ${o} ${e.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 ue(t){let n=0;return t.forEach((t,r)=>{r.getInteropType()===e.InteropScalarType.Date&&n++}),n}function de(e,t){let n=e.getAggregates({onError:`ignore`});if(n.min===null||n.max===null)return``;let i=t.getStyle().getNumberFormat(),a=r(n.min,i),o=r(n.max,i);return a===o?a:`${a} … ${o}`}function fe(e,t){let n=e.getAggregates({onError:`ignore`}),i=t.getStyle().getNumberFormat(),a=[];return n.sum!==null&&a.push(`Σ ${r(n.sum,i)}`),n.average!==null&&a.push(`x̄ ${r(n.average,i)}`),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?` · …`:``})`}function me(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 P=e.ICellRange.Feature,F=e=>e.getRange().getStyle(),he=e=>i(e.getCell(),t.Mode.Display)?.display??null;function ge(e,t){switch(e){case P.Formula:return e=>{let t=e.getCell().getFormulaText();return t?`=${t}`:null};case P.Error:return he;case P.CalcError:return e=>{let t=he(e)??``,n=e.getCell().getFormulaText();return(n?`${t} =${n}`:t).trim()||null};case P.Merge:return he;case P.Comments:return e=>{let t=e.getCell().getComments()?.content;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 P.Spills:return e=>e.getCell().getSpill()?.getValuesRange().toString()??null;case P.Hyperlink:return e=>e.getCell().getHyperlink()?.getAddress()??null;case P.Table:return e=>e.getCell().getTable()?.getName()??null;case P.Fill:return e=>b(F(e));case P.Border:return e=>x(F(e));case P.NumberFormat:return e=>w(F(e));case P.Alignment:return t?e=>T(F(e),t):void 0;case P.Font:return t?e=>E(F(e),t):void 0;case P.Conditionals:return e=>A(e.getRange().getConditionalFormats(),re);case P.DataValidations:return e=>A(e.getRange().getDataValidations(),ie);case P.Contentful:return e=>le(e.getRange()).join(` `)||null;default:return}}function _e(e,t){let n=e.map(e=>ge(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 I=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 ve(this,e)}_addLines(e){this._lines.push(...e)}toLines(){return[...this._lines]}},ve=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)=>ye(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)=>ye(e.text,this._colWidths[t],e.alignment)).join(` `),r=this._indexWidth>0?(e.index??``).padStart(this._indexWidth)+` `:``;n.push(`${r}${t}`.trimEnd())}return n}},ye=(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 be(e,t,n){let r=v(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)),c=i.map(e=>`${e.getRowCount()}×${e.getColumnCount()}`),l=Math.max(...c.map(e=>e.length)),u=n?.profile?n?.maxProfiled??12:0;for(let t=0;t<i.length;t++){let r=i[t],a=n?.payload?.(r),d=r.isClipped()?` ✂ clipped at the query edge — the block continues`:``,f=` ${o[t].padEnd(s)} ${c[t].padEnd(l)}`;if(t<u){let t=M(r,n);e.text(`${f} ${t.summary}${d}`);for(let n of t.series)e.text(` ${n}`);continue}e.text(a?`${f} ${a}${d}`:`${f}${d}`.trimEnd())}if(u>0&&i.length>u&&e.text(` …${i.length-u} 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 xe(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 I;return c.h1(`Regions — ${a} (${r.length})`),be(c,r,{...n,profile:o,payload:o?void 0:_e(i,s)}),c.toLines().join(`
3
3
  `).trimEnd()}function Se(e,t){let n=t.getRange();e.text(`Name: ${t.getName()}`);let r=t.getDescription();r&&e.text(`Description: ${r}`);let i=n.getRowCount(),a=n.getColumnCount();e.text(`Location: ${n.toString()}, ${i} row${i===1?``:`s`} x ${a} column${a===1?``:`s`}`);let o=t.getColumns().map(e=>e.getName());e.text(`Columns (${o.length}): ${o.join(`, `)}`),e.text(`Headers: `+(t.isShowHeaders()?`shown`:`hidden`)),e.text(`Totals: `+(t.isShowTotals()?`shown`:`hidden`))}function Ce(e){let t=new I;return t.h1(`Table — ${e.getName()}`),t.text(`Sheet: ${z(e.getRange().getSheet().getName())}`),t.blank(),Se(t,e),t.toLines().join(`
4
4
  `).trimEnd()}var L=e.ICellRange.Feature,we=[L.Error,L.CalcError,L.Contentful,L.Formula,L.Spills,L.Merge,L.Table,L.AutoTable,L.Hyperlink,L.Comments,L.Unlock,L.NumberFormat,L.Font,L.Fill,L.Border,L.Alignment,L.Conditionals,L.DataValidations],Te=new Map(Object.entries(L).map(([e,t])=>[t,e])),Ee=e=>Te.get(e)??e;function De(e){let t=new Map(Object.values(L).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(L).join(`, `)}.`);n.push(i)}return n}var R=e=>`${e.toString()}, ${e.getRowCount()}×${e.getColumnCount()}`,z=t=>e.AddressUtils.sheetNameToString(t)??`Untitled`,Oe=e=>`wb.getSheet(${JSON.stringify(e.getSheet().getName())})`,B=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()),V=e=>{let t=B(e);return t.includes(`!`)?t:`${z(e.getSheet().getName())}!${t}`},H=e=>{let t=e.toString();return`${t.includes(`!`)?t:`${z(e.getSheet().getName())}!${t}`}, ${e.getRowCount()}×${e.getColumnCount()}`};function U(t,n){let r=n.getStats({onError:`ignore`}),i=r.getTypedCounts(),a=ue(n),o=[[`Error`,i[e.ScalarType.Error]??0],[`Number`,i[e.ScalarType.Number]??0],[`String`,i[e.ScalarType.String]??0],[`Date`,a],[`Boolean`,i[e.ScalarType.Boolean]??0],[`RichData`,i[e.ScalarType.RichData]??0]].filter(([,e])=>e>0),s=r.getCount();t.h2(`Kind (${s} cell${s===1?``:`s`} · ${o.length} kind${o.length===1?``:`s`})`);for(let[e,n]of o)t.fact(`${e}: ${n}`);o.length===0&&t.fact(`None`),t.blank()}function ke(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=we.filter(e=>!i||i.has(e));if(a.length===0)return;let o=t.getCounts(a);for(let i of a){let a=[...t.getRegions(i)];if(a.length===0)continue;let s=!!n?.profile&&i===L.Contentful;e.h2(`${Ee(i)} (${Ae(a.length,o[i])})`),be(e,a,{maxRegions:n?.maxRegions,maxProfiled:n?.maxProfiled,profile:s,payload:s?void 0:ge(i,r),recovery:`${Oe(t)}.getRegions(${JSON.stringify(i)}) lists all ${a.length}`}),e.blank()}}var Ae=(e,t)=>`${t} cell${t===1?``:`s`} · ${e} region${e===1?``:`s`}`,je=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,Me=e=>e.isIFormula?e:null,W=e=>{let t=e.getScope();return t?`${z(t)}!${e.getName()}`:e.getName()},Ne=e=>{let t=e.getAddress();return t.includes(`!`)?t:`${z(e.getSheet().getName())}!${t}`};function Pe(e){let t=Me(e),n;return n=t?`=`+t.getExpression():e.getRanges?.()?.getAddress()??``,t?.isVolatile()&&(n+=` (volatile)`),n.trim()}var Fe=new Set([e.FormulaError.Code.Ref,e.FormulaError.Code.Name]),Ie=t=>{let n=t.value,r=e.FormulaError.isError(n)?n:n?.error;return r&&Fe.has(r.getCode())?r.getCode()===e.FormulaError.Code.Name?`#NAME?`:`#REF!`:null},Le=new Set,Re=e=>{let t=e.value;return typeof t==`object`&&t?.name?t.name:e.text??``};function ze(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=Re(r).toLowerCase();o&&(t??=new Set).add(o)}return t??Le}function G(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=t.map(e=>{let t=function(e,t){let n=Me(e),r=[];if(n){let e=n.getTokens(),i=null,a=null;for(let n of e){if(n.type===`error`){a??=Ie(n);continue}if(n.type!==`named`)continue;let o=Re(n);o&&!t.has(o.toLowerCase())&&(i??=ze(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=Me(e),o=n?function(e,t){let n=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?W(n):e.getName())}else{let t=e[c];r+=(t.rowEnd-t.rowStart+1)*(t.colEnd-t.colStart+1),o.push(Ne(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?je(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=W(e);return{name:c,refersTo:Pe(e),dependents:o,hidden:e.isHidden(),comment:je(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},c=[...o.filter(e=>e.broken).sort(s),...o.filter(e=>!e.broken).sort(s)],l=v(c.length,n?.maxNames??200),u=c.length>l?c.slice(0,l):c,d=u.filter(e=>e.broken),f=u.filter(e=>!e.broken);e.h2(`${n?.heading??`Names`} (${o.length})`);let p=(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(d.length>0){let t=c.reduce((e,t)=>e+ +!!t.broken,0);e.text(`${t} ${t===1?`does`:`do`} not resolve:`),p(d,!0),e.blank()}if(f.length>0&&p(f,!1),u.length<o.length){let t=n?.recovery??`getByName('Name') renders one in full`;e.text(` …and ${o.length-u.length} more · ${t}`)}e.blank()}function K(e,t,n){Ve(e,`Precedents`,t,`precedents`,n),Ve(e,`Dependents`,t,`dependents`,n)}function Be(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 Ve(e,t,n,r,i){let a=i?.maxDepth??3,o=i?.maxNodes??50,s=[],c=new Set,l=new Set,u=!1,d=!1,f=!1,p=(e,t)=>{let n=(e=>r===`precedents`?e.getDirectPrecedents():e.getDirectDependents())(e);if(n&&n.length!==0)if(t>a)u=!0;else for(let e=0;e<n.length;e++){if(s.length>=o)return void(d=!0);let r=n.at(e),{address:i,sheet:a,isName:u}=He(r),m=` `.repeat(t),h=Be(r),g={indent:m,sheet:a,isName:u,label:`${m}${i}`};l.has(h)?(s.push({...g,detail:`↺ circular`}),f=!0):c.has(h)?s.push({...g,detail:`↑ shown above`}):(c.add(h),l.add(h),s.push({...g,detail:Ue(r)}),p(r,t+1),l.delete(h))}};if(p(n,0),s.length===0)return;let m=s.filter(e=>!e.isName);if(m.length>0&&m.some(e=>e.sheet!==m[0].sheet))for(let e of s)e.isName||(e.label=`${e.indent}${e.sheet}!${e.label.slice(e.indent.length)}`);e.h2(t);let h=Math.max(...s.map(e=>e.label.length));for(let t of s)e.text(` ${t.label.padEnd(h)} ${t.detail}`.trimEnd());f&&e.text(` ↺ circular reference — the chain returns to a cell already on this branch`);let g=r===`precedents`?`getPrecedents()`:`getDependents()`;if(u&&e.text(` …deeper levels not walked · ${g} is the whole reach, flat`),d){let t=r===`precedents`?`getDirectPrecedents()`:`getDirectDependents()`;e.text(` …truncated at ${o} nodes · re-root on one node and walk it — its ${t}`)}e.blank()}function He(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 Ue(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(L.Formula)];if(r.length===1&&r[0].getRange().isEqual(e)){let e=r[0].getCell().getFormulaText();if(e)return`${n} =${e}`}return n}function We(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 Ge(e,t,n,r){if(n.length===0)return;let i=n.length>50?n.slice(0,50):n,a=i.map(e=>({address:je(B(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 q(e,t){let n=t.getSheet(),r=t.getCoords(),i=n.getName(),a=[];for(let e of n.getNames().getItems({type:`formula`,includeHidden:!0})??[]){let t=null;try{t=e.getRanges?.()??null}catch{}t?t.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):e.getScope()===i&&a.push(e)}G(e,a,{symbols:n.getWorkbook()?.getNames().getItems({includeHidden:!0})??n.getNames().getItems({includeHidden:!0})??[]});let o=t.getColumnHeaders(),s=t.getRowHeaders();We(e,`Hidden Columns`,o),We(e,`Hidden Rows`,s);let c=t.getTables();c.length>0&&(e.h2(`Tables`),c.forEach((t,n)=>{n>0&&e.blank(),Se(e,t)}),e.blank())}var Ke={features:e=>De(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)},qe=Object.keys(Ke);function Je(e,n){e=e.getSheet().getRange(e.getCoords()).getCell();let r=new I;return r.h1(`Cell — ${z(e.getSheet().getName())}!${e.getAddress()}`),r.blank(),function(e,n){let r=i(n,t.Mode.Display),a=i(n,t.Mode.Value),o=n.getFormulaText(),s=e.toLines().length;(r||o)&&(e.fact(`Type: ${n.getType()}`),r&&e.fact(`Display: ${r.display}`),a&&a.match!==r?.match&&e.fact(`Value: ${a.display}`),o&&e.fact(`Formula: ${e.codespan(`=${o}`)}`));let c=n.getHyperlink();c&&e.fact(`Hyperlink: ${c.getAddress()}`);let l=n.getSpans(),u=!n.isTopLeft();if(u||l.height>1||l.width>1){let t=n.getRange().toString();e.fact(`Merge: ${t} · ${l.height}×${l.width}`),u&&e.fact(`Merge Anchor: false — this cell is covered; the value lives at the top-left`)}let d=n.getSpill();d&&e.fact(`Spill: ${d.toString()}`),n.isSpillOverflow()&&e.fact(`Spill Overflow: true — the anchor formula is elsewhere`);let f=n.getTable();f&&e.fact(`Table: ${f.getName()}`);let p=n.getErrors();p.length>0&&e.fact(`Errors: ${p.join(`; `)}`);let m=n.getWarnings();m.length>0&&e.fact(`Warnings: ${m.join(`; `)}`),e.toLines().length>s&&e.blank()}(r,e),function(e,t){let n=t.getStyle(),r=t.getSheet().getWorkbook()?.getStyles().getNormal()??null,i=w(n),a=r?E(n,r):null,o=b(n),s=C(n),c=r?T(n,r):null,l=n.getNamed().getName();if(l!==(r?.getNamed().getName()??`Normal`)||i||a||o||c||s.length!==0){if(e.h2(`Style`),e.fact(`Named: ${l}`),i&&e.fact(`Number Format: ${i}`),a&&e.fact(`Font: ${a}`),o&&e.fact(`Fill: ${o}`),s.length===1)e.fact(`Border: ${s[0]}`);else if(s.length>1){e.fact(`Border:`);for(let t of s)e.fact(` ${t}`)}c&&e.fact(`Alignment: ${c}`),e.blank()}}(r,e),K(r,e,n),r.toLines().join(`
5
5
  `).trimEnd()}var Ye=new Set([`picture`]),Xe=e=>e.replace(/[\r\n]+/g,` `).trim(),Ze=e=>{switch(e.getType()){case`chart`:{let t=[],n=e.getChartType?.();n&&n!==`unknown`&&t.push(n);let r=e.getChartTitle?.();return r&&t.push(`"${r}"`),t.length>0?t.join(` · `):null}case`picture`:return e.getResource?.()?.getName()||null;default:return null}},Qe=e=>{let t=e.getContent(),n=[],r=Ze(t);r&&n.push(r);let i=e.getDescription();i&&n.push(Xe(i));let a=e.getName()||`(unnamed)`,o=n.length>0?`${a} — ${n.join(` · `)}`:a;return c=90,((s=o).length>c?`${s.slice(0,c-1)}…`:s)+(e.isHidden()?` (hidden)`:``);var s,c};function $e(e,t){if(t.length===0)return;let n=t.length>50?t.slice(0,50):t,r=n.map(e=>({address:e.getRange().toString(),type:e.getContent().getType(),summary:Qe(e)}));e.h2(`Movables (${t.length})`);let i=Math.max(...r.map(e=>e.address.length)),a=Math.max(...r.map(e=>e.type.length));for(let t of r)e.text(` ${t.address.padEnd(i)} ${t.type.padEnd(a)} ${t.summary}`.trimEnd());n.length<t.length&&e.text(` …and ${t.length-n.length} more`);let o=[...new Set(r.map(e=>e.type).filter(e=>!Ye.has(e)))];o.length>0&&e.text(` Not drawn: ${o.join(`, `)} — SheetXL shows a labeled placeholder for these in the UI.`),e.blank()}function et(t){let n=new I,r=t.getRange(),i=t.getContent(),a=i.getType();n.h1(`Movable — ${H(r)}`),n.blank(),n.fact(`Name: ${t.getName()||`(unnamed)`}`),n.fact(`Type: ${a}`);let o=Ze(i);o&&n.fact(`Content: ${o}`);let s=t.getDescription();s&&n.fact(`Alt Text: ${Xe(s)}`),n.fact(`Anchor: ${R(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 c=t.getRotation();return c!==0&&n.fact(`Rotation: ${c}°`),n.fact(`Z-Order: ${t.getZIndex()}`),n.fact(`Display: ${(e=>Ye.has(e)?`drawn`:`placeholder — SheetXL frames the ${e} at this position but does not draw its content`)(a)}`),n.blank(),n.text(`Sheet: ${z(r.getSheet().getName())}`),n.toLines().join(`
@@ -20,7 +20,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
20
20
  `).trimEnd()}function Ct(e){let t=new I;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(`
21
21
  `).trimEnd()}function wt(e,t){let n=t?.maxCells??1e3,r=Tt(e)?e.getValues():e,i=r.length,a=r.reduce((e,t)=>Math.max(e,t?.length??0),0),o=new I;if(o.h1(`Values`),o.text(`Size: ${i}×${a}`),o.blank(),i===0||a===0)return o.text(`None`),o.toLines().join(`
22
22
  `).trimEnd();let s=v(i,Math.max(1,Math.floor(n/a))),c=i>s?r.slice(0,s):r,l=o.beginFrame(Array(a).fill(``));for(let e of c)l.addRow(Array.from({length:a},(t,n)=>Et(e?.[n])));return l.endFrame(),c.length<i&&o.text(`…truncated at ${c.length} of ${i} rows · slice or aggregate in the expression before returning it`),o.toLines().join(`
23
- `).trimEnd()}var Tt=e=>!!e&&typeof e==`object`&&!0===e.isIRange,Et=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}},Z=e.ICellRange.Feature;function Dt(t,n){let r=new I;r.h1(`Workbook — ${t.getName()??`Untitled`}`),r.text(`Locale: ${t.getRuntime().getLocale()}`),r.blank();let i=t.getSheets().getItems({visibility:e.ISheet.Visibility.VeryHidden}),a=t.getSelectedSheet(),o=[];for(let e of i){let t=e.getUsedRange();o.push({sheet:e,label:Ot(e,e.getId()===a.getId()),used:t?.toString()??`empty`,counts:t?.getCounts([Z.Contentful,Z.Formula,Z.Error,Z.CalcError])??null})}let s=o;if(o.length>50){s=o.slice(0,50);let e=o.find(e=>e.sheet.getId()===a.getId());e&&!s.includes(e)&&(s[s.length-1]=e)}r.h2(`Sheets (${o.length})`);let c=r.beginFrame([`Sheet`,`Used`,`Cells`,`Formulas`,`Errors`]);for(let e of s)c.addRow([{text:e.label},{text:e.used},{text:String(e.counts?.[Z.Contentful]??0),alignment:`right`},{text:String(e.counts?.[Z.Formula]??0),alignment:`right`},{text:String(e.counts?.[Z.Error]??0),alignment:`right`}]);if(o.length>1){let e=e=>o.reduce((t,n)=>t+(n.counts?.[e]??0),0);c.addRow([{text:`Total`},{text:``},{text:String(e(Z.Contentful)),alignment:`right`},{text:String(e(Z.Formula)),alignment:`right`},{text:String(e(Z.Error)),alignment:`right`}])}c.endFrame(),s.length<o.length&&r.text(` …and ${o.length-s.length} more sheets · the totals include them · wb.getSheets().getItems() lists all`),r.blank(),kt(r,`Errors`,o,Z.Error),kt(r,`Calc Failures`,o,Z.CalcError),G(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})??[]});let l=n?.maxSheets??8,u=o.filter(e=>e.sheet.getUsedRange()!==null),d=u.slice(0,l),f=u.find(e=>e.sheet.getId()===a.getId());f&&!d.includes(f)&&(d[d.length-1]=f),r.setHeadingOffset(1);for(let e of d){let t=e.sheet.getUsedRange();t&&(r.h1(`Sheet — ${e.label}`),U(r,t),ke(r,t,{features:n?.features,maxRegions:n?.maxRegions??25,profile:!0,maxProfiled:n?.maxProfiled??4}),q(r,t))}return r.setHeadingOffset(0),d.length<u.length&&r.text(`…and ${u.length-d.length} more sheets not expanded · a sheet report (\`wb.getSheet('Name')\`) renders one in full`),r.toLines().join(`
23
+ `).trimEnd()}var Tt=e=>!!e&&typeof e==`object`&&!0===e.isIRange,Et=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}},Z=e.ICellRange.Feature;function Dt(t,n){let r=new I;r.h1(`Workbook — ${t.getName()??`Untitled`}`),r.text(`Locale: ${t.getRuntime().getLocale()}`),r.blank();let i=t.getSheets().getItems({visibility:e.ISheet.Visibility.VeryHidden}),a=t.getSelectedSheet(),o=[];for(let e of i){let t=e.getUsedRange();o.push({sheet:e,label:Ot(e,e.getId()===a.getId()),used:t?.toString()??`empty`,counts:t?.getCounts([Z.Contentful,Z.Formula,Z.Error,Z.CalcError,Z.Circular])??null})}let s=o;if(o.length>50){s=o.slice(0,50);let e=o.find(e=>e.sheet.getId()===a.getId());e&&!s.includes(e)&&(s[s.length-1]=e)}r.h2(`Sheets (${o.length})`);let c=r.beginFrame([`Sheet`,`Used`,`Cells`,`Formulas`,`Errors`]);for(let e of s)c.addRow([{text:e.label},{text:e.used},{text:String(e.counts?.[Z.Contentful]??0),alignment:`right`},{text:String(e.counts?.[Z.Formula]??0),alignment:`right`},{text:String(e.counts?.[Z.Error]??0),alignment:`right`}]);if(o.length>1){let e=e=>o.reduce((t,n)=>t+(n.counts?.[e]??0),0);c.addRow([{text:`Total`},{text:``},{text:String(e(Z.Contentful)),alignment:`right`},{text:String(e(Z.Formula)),alignment:`right`},{text:String(e(Z.Error)),alignment:`right`}])}c.endFrame(),s.length<o.length&&r.text(` …and ${o.length-s.length} more sheets · the totals include them · wb.getSheets().getItems() lists all`),r.blank(),kt(r,`Errors`,o,Z.Error),kt(r,`Calc Failures`,o,Z.CalcError),kt(r,`Circular References`,o,Z.Circular),G(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})??[]});let l=n?.maxSheets??8,u=o.filter(e=>e.sheet.getUsedRange()!==null),d=u.slice(0,l),f=u.find(e=>e.sheet.getId()===a.getId());f&&!d.includes(f)&&(d[d.length-1]=f),r.setHeadingOffset(1);for(let e of d){let t=e.sheet.getUsedRange();t&&(r.h1(`Sheet — ${e.label}`),U(r,t),ke(r,t,{features:n?.features,maxRegions:n?.maxRegions??25,profile:!0,maxProfiled:n?.maxProfiled??4}),q(r,t))}return r.setHeadingOffset(0),d.length<u.length&&r.text(`…and ${u.length-d.length} more sheets not expanded · a sheet report (\`wb.getSheet('Name')\`) renders one in full`),r.toLines().join(`
24
24
  `).trimEnd()}function Ot(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)`),`${z(t.getName())}${i}`}function kt(e,t,n,r){let i=n.reduce((e,t)=>e+(t.counts?.[r]??0),0);if(i===0)return;let a=[],o=0;for(let e of n){if(!e.counts?.[r])continue;let t=e.sheet.getUsedRange();if(!t)continue;let n=z(e.sheet.getName());for(let e of t.getRegions(r))o++,a.length>=20||a.push({address:`${n}!${e.toString()}`,size:`${e.getRowCount()}×${e.getColumnCount()}`,payload:At(e)})}e.h2(`${t} (${i})`);let s=Math.max(0,...a.map(e=>e.address.length)),c=Math.max(0,...a.map(e=>e.size.length));for(let t of a)e.text(` ${t.address.padEnd(s)} ${t.size.padEnd(c)} ${t.payload}`.trimEnd());o>a.length&&e.text(` …and ${o-a.length} more · getRegions('${r}') on a sheet's used range lists the rest`),e.blank()}function At(e){let n=e.getCell(),r=i(n,t.Mode.Display)?.display??``,a=n.getFormulaText();return a?`${r} =${a}`.trim():r}var Q=(e,t)=>!!e&&typeof e==`object`&&!0===e[t],jt=[{kind:`workbook`,is:e=>Q(e,`isIWorkbook`),render:(e,t)=>Dt(e,t)},{kind:`sheet`,is:e=>Q(e,`isISheet`),render:(e,t)=>bt(e,t)},{kind:`cell`,is:e=>Q(e,`isICell`),render:(e,t)=>Je(e,t)},{kind:`names`,is:e=>Q(e,`isINamedCollection`),render:(e,t)=>gt(e,t)},{kind:`formula`,is:e=>Q(e,`isIFormula`),render:(e,t)=>mt(e,t)},{kind:`table`,is:e=>Q(e,`isITable`),render:e=>Ce(e)},{kind:`movable`,is:e=>Q(e,`isIMovable`),render:e=>et(e)},{kind:`conditionalFormat`,is:e=>Q(e,`isIConditionalFormat`),render:e=>nt(e)},{kind:`dataValidation`,is:e=>Q(e,`isIDataValidation`),render:e=>it(e)},{kind:`stats`,is:e=>Q(e,`isIRangeStats`),render:e=>St(e)},{kind:`counts`,is:e=>Q(e,`isICellRangeCounts`),render:e=>rt(e)},{kind:`style`,is:e=>Q(e,`isIStyle`),render:e=>Ct(e)},{kind:`regions`,is:e=>Q(e,`isICellRegions`),render:(e,t)=>xe(e,t)},{kind:`cellRange`,is:e=>Q(e,`isICellRange`),render:(e,t)=>tt(e,t)},{kind:`ranges`,is:e=>Q(e,`isICellRanges`),render:(e,t)=>yt(e,t)},{kind:`range`,is:e=>Q(e,`isIRange`),render:(e,t)=>wt(e,t)},{kind:`values`,is:e=>Array.isArray(e)&&e.length>0&&e.every(e=>Array.isArray(e)),render:(e,t)=>wt(e,t)},{kind:`records`,is:e=>Array.isArray(e)&&e.length>0&&e.every(J),render:(e,t)=>Y(e,t)},{kind:`record`,is:e=>J(e),render:(e,t)=>Y(e,t)},{kind:`items`,is:e=>Array.isArray(e)&&e.length>0&&e.every(e=>!!$(e)),render:async(e,t)=>{let n=e.length>20?e.slice(0,20):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(`
25
25
 
26
26
  `)}}],Mt=class extends Error{constructor(e){super(e),this.name=`NoRendererError`}};function $(e){for(let t of jt)if(t.is(e))return t;return null}async function Nt(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 Mt(`No markdown renderer for this value. Renderable kinds: ${jt.map(e=>e.kind).join(`, `)}.`);return r.render(i,n)}var Pt=[_];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`,Raw:`raw`,Formula:`formula`,Hyperlink:`hyperlink`,NumberFormat:`numberFormat`},exports.MarkdownBuilder=I,exports.MarkdownFrameSection=ve,exports.NoRendererError=Mt,exports.RENDERERS=jt,exports.RENDER_OPTION_KEYS=qe,exports.REPORTED_FEATURES=we,exports.TOOLS=Pt,exports.appendDependencies=K,exports.appendKinds=U,exports.appendMovables=$e,exports.appendNames=G,exports.appendRegionList=be,exports.appendRegions=ke,exports.appendRules=Ge,exports.appendSheetObjects=q,exports.appendTableDetails=Se,exports.countDates=ue,exports.describeAlignment=T,exports.describeAllowedValues=ae,exports.describeBorder=x,exports.describeBorderParts=C,exports.describeColor=y,exports.describeConditionalFormat=re,exports.describeDataValidation=ie,exports.describeExtent=R,exports.describeFill=b,exports.describeFont=E,exports.describeNode=Ue,exports.describeNodeLabel=He,exports.describeNumberFormat=w,exports.describeQualifiedExtent=H,exports.describeQualifiedName=W,exports.describeQualifiedRanges=V,exports.describeRanges=B,exports.describeRuleStyle=k,exports.describeRules=A,exports.describeScale=te,exports.describeSheetCall=Oe,exports.describeSheetName=z,exports.encodeCell=i,exports.encodeFormattedNumber=r,exports.encodeNumber=n,exports.encodeScalar=a,exports.grep=p,exports.grepTool=_,exports.isPlainRecord=J,exports.parseFeatures=De,exports.parseRenderOptions=function(e){let t={};for(let[n,r]of Object.entries(e)){let e=Ke[n];if(!e)throw Error(`Unknown report option '${n}'. Options: ${qe.join(`, `)}.`);t[n]=e(r,n)}return t},exports.profileKinds=le,exports.profileRegion=M,exports.regionPayload=ge,exports.regionPayloads=_e,exports.renderCell=Je,exports.renderCellRange=tt,exports.renderConditionalFormat=nt,exports.renderCounts=rt,exports.renderDataValidation=it,exports.renderFormula=mt,exports.renderGrep=g,exports.renderMarkdown=Nt,exports.renderMovable=et,exports.renderNames=gt,exports.renderRanges=yt,exports.renderRecords=Y,exports.renderRegions=xe,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 Nt(e,t,n),rendered:!0}}catch(e){if(!(e instanceof Mt))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.renderSheet=bt,exports.renderStats=St,exports.renderStyle=Ct,exports.renderTable=Ce,exports.renderValues=wt,exports.renderWorkbook=Dt,exports.resolveRenderer=$;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license @sheetxl/query - SheetXL - Workbook read surface and renderers (grep, reports) — capabilities declared once, adapted by any host surface - v0.7.28-beta.2
2
+ * @license @sheetxl/query - SheetXL - Workbook read surface and renderers (grep, reports) — capabilities declared once, adapted by any host surface - v0.7.28-beta.4
3
3
  *
4
4
  * (C) 2026-present SheetXL Inc. & Michael T. Ford
5
5
  * License: The license can be found at https://www.sheetxl.com/license.
@@ -478,7 +478,7 @@ var T = {
478
478
  if (e.type === a.ScaleType.DataBar) {
479
479
  let n = O(e.color);
480
480
  n && (t += ` ${n}`);
481
- } else e.type === a.ScaleType.IconSet && (e.iconSet && (t += ` ${e.iconSet}`), e.reverse && (t += " reversed"));
481
+ } else e.type === a.ScaleType.IconSet && (e.iconSet && (t += ` ${e.iconSet}`), e.reverse && (t += " reversed"), e.icon?.length && (t += " custom icons"));
482
482
  let n = (e.stops ?? []).map(me).join(" → ");
483
483
  return n ? `${t} · ${n}` : t;
484
484
  }, ge = "(no rule)", k = (e) => {
@@ -1708,7 +1708,8 @@ function Vt(e, t) {
1708
1708
  Z.Contentful,
1709
1709
  Z.Formula,
1710
1710
  Z.Error,
1711
- Z.CalcError
1711
+ Z.CalcError,
1712
+ Z.Circular
1712
1713
  ]) ?? null
1713
1714
  });
1714
1715
  }
@@ -1761,7 +1762,7 @@ function Vt(e, t) {
1761
1762
  }
1762
1763
  ]);
1763
1764
  }
1764
- s.endFrame(), o.length < a.length && n.text(` …and ${a.length - o.length} more sheets · the totals include them · wb.getSheets().getItems() lists all`), n.blank(), Ut(n, "Errors", a, Z.Error), Ut(n, "Calc Failures", a, Z.CalcError), K(n, e.getNames().getItems({
1765
+ s.endFrame(), o.length < a.length && n.text(` …and ${a.length - o.length} more sheets · the totals include them · wb.getSheets().getItems() lists all`), n.blank(), Ut(n, "Errors", a, Z.Error), Ut(n, "Calc Failures", a, Z.CalcError), Ut(n, "Circular References", a, Z.Circular), K(n, e.getNames().getItems({
1765
1766
  type: "formula",
1766
1767
  includeHidden: !0
1767
1768
  }) ?? [], {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license @sheetxl/query - SheetXL - Workbook read surface and renderers (grep, reports) — capabilities declared once, adapted by any host surface - v0.7.28-beta.2
2
+ * @license @sheetxl/query - SheetXL - Workbook read surface and renderers (grep, reports) — capabilities declared once, adapted by any host surface - v0.7.28-beta.4
3
3
  *
4
4
  * (C) 2026-present SheetXL Inc. & Michael T. Ford
5
5
  * License: The license can be found at https://www.sheetxl.com/license.
@@ -483,7 +483,7 @@ var T = {
483
483
  if (e.type === s.ScaleType.DataBar) {
484
484
  const n = _(e.color);
485
485
  n && (t += ` ${n}`);
486
- } else e.type === s.ScaleType.IconSet && (e.iconSet && (t += ` ${e.iconSet}`), e.reverse && (t += " reversed"));
486
+ } else e.type === s.ScaleType.IconSet && (e.iconSet && (t += ` ${e.iconSet}`), e.reverse && (t += " reversed"), e.icon?.length && (t += " custom icons"));
487
487
  const n = (e.stops ?? []).map(W).join(" → ");
488
488
  return n ? `${t} · ${n}` : t;
489
489
  }, z = "(no rule)", q = (e) => {
@@ -1736,7 +1736,8 @@ function Bt(e, t) {
1736
1736
  Ot.Contentful,
1737
1737
  Ot.Formula,
1738
1738
  Ot.Error,
1739
- Ot.CalcError
1739
+ Ot.CalcError,
1740
+ Ot.Circular
1740
1741
  ]) ?? null
1741
1742
  });
1742
1743
  }
@@ -1789,7 +1790,7 @@ function Bt(e, t) {
1789
1790
  }
1790
1791
  ]);
1791
1792
  }
1792
- l.endFrame(), a.length < s.length && n.text(` …and ${s.length - a.length} more sheets · the totals include them · wb.getSheets().getItems() lists all`), n.blank(), _t(n, "Errors", s, Ot.Error), _t(n, "Calc Failures", s, Ot.CalcError), Pe(n, e.getNames().getItems({
1793
+ l.endFrame(), a.length < s.length && n.text(` …and ${s.length - a.length} more sheets · the totals include them · wb.getSheets().getItems() lists all`), n.blank(), _t(n, "Errors", s, Ot.Error), _t(n, "Calc Failures", s, Ot.CalcError), _t(n, "Circular References", s, Ot.Circular), Pe(n, e.getNames().getItems({
1793
1794
  type: "formula",
1794
1795
  includeHidden: !0
1795
1796
  }) ?? [], {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sheetxl/query",
3
3
  "description": "SheetXL - Workbook read surface and renderers (grep, reports) — capabilities declared once, adapted by any host surface",
4
- "version": "0.7.28-beta.2",
4
+ "version": "0.7.28-beta.4",
5
5
  "license": "SEE LICENSE IN <LICENSE>",
6
6
  "type": "module",
7
7
  "exports": {
@@ -43,8 +43,8 @@
43
43
  "query"
44
44
  ],
45
45
  "dependencies": {
46
- "@sheetxl/primitives": "^0.7.28-beta.2",
47
- "@sheetxl/sdk": "^0.7.28-beta.2"
46
+ "@sheetxl/primitives": "^0.7.28-beta.4",
47
+ "@sheetxl/sdk": "^0.7.28-beta.4"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/node": "^26.1.2"