@sheetxl/query 0.7.23-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/LICENSE.md +11 -0
  2. package/README.md +69 -0
  3. package/browser/cjs/index.cjs +26 -0
  4. package/browser/esm/index.mjs +1994 -0
  5. package/licenses/dependencies.txt +1 -0
  6. package/node/esm/index.mjs +2024 -0
  7. package/package.json +52 -0
  8. package/types/index.d.ts +2 -0
  9. package/types/src/Tool.d.ts +108 -0
  10. package/types/src/Tool.d.ts.map +1 -0
  11. package/types/src/encode/encodeCell.d.ts +149 -0
  12. package/types/src/encode/encodeCell.d.ts.map +1 -0
  13. package/types/src/encode/index.d.ts +2 -0
  14. package/types/src/encode/index.d.ts.map +1 -0
  15. package/types/src/grep/GrepTypes.d.ts +308 -0
  16. package/types/src/grep/GrepTypes.d.ts.map +1 -0
  17. package/types/src/grep/grep.d.ts +15 -0
  18. package/types/src/grep/grep.d.ts.map +1 -0
  19. package/types/src/grep/grepTool.d.ts +16 -0
  20. package/types/src/grep/grepTool.d.ts.map +1 -0
  21. package/types/src/grep/index.d.ts +5 -0
  22. package/types/src/grep/index.d.ts.map +1 -0
  23. package/types/src/grep/renderGrep.d.ts +19 -0
  24. package/types/src/grep/renderGrep.d.ts.map +1 -0
  25. package/types/src/index.d.ts +20 -0
  26. package/types/src/index.d.ts.map +1 -0
  27. package/types/src/markdown/MarkdownBuilder.d.ts +84 -0
  28. package/types/src/markdown/MarkdownBuilder.d.ts.map +1 -0
  29. package/types/src/markdown/appendSections.d.ts +364 -0
  30. package/types/src/markdown/appendSections.d.ts.map +1 -0
  31. package/types/src/markdown/caps.d.ts +24 -0
  32. package/types/src/markdown/caps.d.ts.map +1 -0
  33. package/types/src/markdown/describeRegionPayload.d.ts +46 -0
  34. package/types/src/markdown/describeRegionPayload.d.ts.map +1 -0
  35. package/types/src/markdown/describeRule.d.ts +66 -0
  36. package/types/src/markdown/describeRule.d.ts.map +1 -0
  37. package/types/src/markdown/describeStyle.d.ts +64 -0
  38. package/types/src/markdown/describeStyle.d.ts.map +1 -0
  39. package/types/src/markdown/index.d.ts +27 -0
  40. package/types/src/markdown/index.d.ts.map +1 -0
  41. package/types/src/markdown/parseRenderOptions.d.ts +16 -0
  42. package/types/src/markdown/parseRenderOptions.d.ts.map +1 -0
  43. package/types/src/markdown/profileRegion.d.ts +121 -0
  44. package/types/src/markdown/profileRegion.d.ts.map +1 -0
  45. package/types/src/markdown/registry.d.ts +96 -0
  46. package/types/src/markdown/registry.d.ts.map +1 -0
  47. package/types/src/markdown/renderCell.d.ts +23 -0
  48. package/types/src/markdown/renderCell.d.ts.map +1 -0
  49. package/types/src/markdown/renderCellRange.d.ts +61 -0
  50. package/types/src/markdown/renderCellRange.d.ts.map +1 -0
  51. package/types/src/markdown/renderConditionalFormat.d.ts +15 -0
  52. package/types/src/markdown/renderConditionalFormat.d.ts.map +1 -0
  53. package/types/src/markdown/renderCounts.d.ts +11 -0
  54. package/types/src/markdown/renderCounts.d.ts.map +1 -0
  55. package/types/src/markdown/renderDataValidation.d.ts +15 -0
  56. package/types/src/markdown/renderDataValidation.d.ts.map +1 -0
  57. package/types/src/markdown/renderFormula.d.ts +63 -0
  58. package/types/src/markdown/renderFormula.d.ts.map +1 -0
  59. package/types/src/markdown/renderMovable.d.ts +35 -0
  60. package/types/src/markdown/renderMovable.d.ts.map +1 -0
  61. package/types/src/markdown/renderNames.d.ts +32 -0
  62. package/types/src/markdown/renderNames.d.ts.map +1 -0
  63. package/types/src/markdown/renderRanges.d.ts +33 -0
  64. package/types/src/markdown/renderRanges.d.ts.map +1 -0
  65. package/types/src/markdown/renderRecords.d.ts +39 -0
  66. package/types/src/markdown/renderRecords.d.ts.map +1 -0
  67. package/types/src/markdown/renderRegions.d.ts +70 -0
  68. package/types/src/markdown/renderRegions.d.ts.map +1 -0
  69. package/types/src/markdown/renderResult.d.ts +35 -0
  70. package/types/src/markdown/renderResult.d.ts.map +1 -0
  71. package/types/src/markdown/renderSheet.d.ts +29 -0
  72. package/types/src/markdown/renderSheet.d.ts.map +1 -0
  73. package/types/src/markdown/renderStats.d.ts +18 -0
  74. package/types/src/markdown/renderStats.d.ts.map +1 -0
  75. package/types/src/markdown/renderStyle.d.ts +12 -0
  76. package/types/src/markdown/renderStyle.d.ts.map +1 -0
  77. package/types/src/markdown/renderTable.d.ts +12 -0
  78. package/types/src/markdown/renderTable.d.ts.map +1 -0
  79. package/types/src/markdown/renderValues.d.ts +28 -0
  80. package/types/src/markdown/renderValues.d.ts.map +1 -0
  81. package/types/src/markdown/renderWorkbook.d.ts +50 -0
  82. package/types/src/markdown/renderWorkbook.d.ts.map +1 -0
@@ -0,0 +1,2024 @@
1
+ /**
2
+ * @license @sheetxl/query - SheetXL - Workbook read surface and renderers (grep, reports) — capabilities declared once, adapted by any host surface - v0.7.23-beta.1
3
+ *
4
+ * (C) 2026-present SheetXL Inc. & Michael T. Ford
5
+ * License: The license can be found at https://www.sheetxl.com/license.
6
+ */
7
+ import { AddressUtils as e, FormulaError as t, IAnchored as n, ICellRange as r, ICondition as o, IConditionalFormat as s, IDataValidation as a, IFill as l, IFont as i, ISheet as c, InteropScalarType as g, NumberFormat as u, ScalarType as d } from "@sheetxl/sdk";
8
+ var h;
9
+ (h || (h = {})).Mode = {
10
+ Display: "display",
11
+ Value: "value"
12
+ };
13
+ function f(e) {
14
+ return Number.isFinite(e) ? function(e) {
15
+ const t = e.indexOf("e");
16
+ if (-1 === t) return e;
17
+ const n = e.substring(t + 2);
18
+ return `${e.substring(0, t)}E${e[t + 1]}${n.length < 2 ? "0" + n : n}`;
19
+ }(String(Number(e.toPrecision(15)))) : String(e);
20
+ }
21
+ function m(e, t) {
22
+ if (!Number.isFinite(e)) return String(e);
23
+ if (!t || "General" === t) return f(e);
24
+ try {
25
+ const n = u.getEngine().format(t, e)?.text;
26
+ return n ? n.trim() : f(e);
27
+ } catch {
28
+ return f(e);
29
+ }
30
+ }
31
+ function p(e, t) {
32
+ const n = t === h.Mode.Value, r = e.getText({
33
+ hideStringPrefix: !0,
34
+ useFormattingCategory: n
35
+ });
36
+ return r ? {
37
+ match: r,
38
+ display: e.getText({ useFormattingCategory: n })
39
+ } : null;
40
+ }
41
+ function $(e) {
42
+ if (null == e) return null;
43
+ if ("string" == typeof e) return {
44
+ match: e,
45
+ display: `'${e}`
46
+ };
47
+ if ("boolean" == typeof e) {
48
+ const t = e ? "TRUE" : "FALSE";
49
+ return {
50
+ match: t,
51
+ display: t
52
+ };
53
+ }
54
+ if ("number" == typeof e) {
55
+ const t = f(e);
56
+ return {
57
+ match: t,
58
+ display: t
59
+ };
60
+ }
61
+ if (t.isError(e)) {
62
+ const t = e.getLabel();
63
+ return {
64
+ match: t,
65
+ display: t
66
+ };
67
+ }
68
+ const n = e.toString();
69
+ return {
70
+ match: n,
71
+ display: n
72
+ };
73
+ }
74
+ var y = {
75
+ Display: "display",
76
+ Value: "value",
77
+ Raw: "raw",
78
+ Formula: "formula",
79
+ Hyperlink: "hyperlink",
80
+ NumberFormat: "numberFormat"
81
+ }, x = [
82
+ "display",
83
+ "value",
84
+ "raw",
85
+ "formula",
86
+ "hyperlink",
87
+ "numberFormat"
88
+ ], S = [
89
+ "display",
90
+ "value",
91
+ "formula"
92
+ ], b = (e) => "visible" === e.getVisibility(), w = (e, t, n) => {
93
+ const r = e.getSheets().getItems({ visibility: "veryHidden" }), o = t?.trim();
94
+ if (!o) return r.filter((e) => n || b(e)).map((e) => ({
95
+ sheet: e,
96
+ address: null
97
+ }));
98
+ const s = /^'(.*)'!(.+)$/.exec(o) ?? /^([^!]+)!(.+)$/.exec(o);
99
+ if (s) {
100
+ const [, e, t] = s, n = r.find((t) => t.getName() === e);
101
+ if (!n) throw new Error(`Sheet not found: ${e}`);
102
+ return [{
103
+ sheet: n,
104
+ address: t
105
+ }];
106
+ }
107
+ const a = r.find((e) => e.getName() === o);
108
+ if (a) return [{
109
+ sheet: a,
110
+ address: null
111
+ }];
112
+ if (/[*?]/.test(o)) {
113
+ const e = ((e) => {
114
+ const t = e.replace(/[.*+?^${}()|[\]\\]/g, (e) => "*" === e ? ".*" : "?" === e ? "." : `\\${e}`);
115
+ return new RegExp(`^${t}$`);
116
+ })(o), t = r.filter((t) => e.test(t.getName()) && (n || b(t)));
117
+ if (0 === t.length) throw new Error(`No sheets match ${JSON.stringify(o)}. Sheets: ${r.map((e) => e.getName()).join(", ")}`);
118
+ return t.map((e) => ({
119
+ sheet: e,
120
+ address: null
121
+ }));
122
+ }
123
+ const l = r.filter((e) => n || b(e));
124
+ try {
125
+ l[0]?.getRange(o);
126
+ } catch {
127
+ throw new Error(`Unknown scope ${JSON.stringify(o)}: not a sheet name or a range. Sheets: ${r.map((e) => e.getName()).join(", ")}`);
128
+ }
129
+ return l.map((e) => ({
130
+ sheet: e,
131
+ address: o
132
+ }));
133
+ }, C = (e, t) => {
134
+ switch (t) {
135
+ case "display": return p(e, h.Mode.Display);
136
+ case "value": return p(e, h.Mode.Value);
137
+ case "raw": return $(e.getValue());
138
+ case "formula": {
139
+ const t = e.getFormulaText();
140
+ return t ? {
141
+ match: `=${t}`,
142
+ display: `=${t}`
143
+ } : null;
144
+ }
145
+ case "hyperlink": {
146
+ const t = e.getHyperlink()?.getAddress() ?? null;
147
+ return t ? {
148
+ match: t,
149
+ display: t
150
+ } : null;
151
+ }
152
+ case "numberFormat": {
153
+ const t = e.getStyle().getNumberFormat();
154
+ return t && "General" !== t ? {
155
+ match: t,
156
+ display: t
157
+ } : null;
158
+ }
159
+ default: return null;
160
+ }
161
+ }, k = ["hyperlink", "numberFormat"], N = (e, t, n) => {
162
+ let r = null;
163
+ const o = (e) => ({
164
+ range: `${t}!${e.getRange().toString()}`,
165
+ table: e.getName()
166
+ });
167
+ return { resolve(s, a) {
168
+ const l = ((e) => e.getTable())(s);
169
+ if ("table" === e) return l ? o(l) : void 0;
170
+ if (null === r) {
171
+ r = [];
172
+ for (const e of n.getRegions()) {
173
+ const n = e.getCoords();
174
+ n.rowStart === n.rowEnd && n.colStart === n.colEnd || r.push({
175
+ coords: n,
176
+ address: `${t}!${e.toString()}`
177
+ });
178
+ }
179
+ }
180
+ const i = r.find(({ coords: e }) => a.rowIndex >= e.rowStart && a.rowIndex <= e.rowEnd && a.colIndex >= e.colStart && a.colIndex <= e.colEnd);
181
+ return i ? {
182
+ range: i.address,
183
+ ...l ? { table: l.getName() } : {}
184
+ } : l ? o(l) : void 0;
185
+ } };
186
+ };
187
+ async function E(e, t) {
188
+ if (!t.pattern) throw new Error("grep requires a pattern");
189
+ const n = t.fields?.length ? t.fields : S, r = t.output ?? "content", o = t.maxCount ?? 200, s = !0 === t.invert, a = !0 === t.hidden, l = ((e) => {
190
+ if (void 0 === e || !1 === e) return null;
191
+ if (!0 === e) return "contentful";
192
+ if ("contentful" === e || "table" === e) return e;
193
+ throw new 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.`);
194
+ })(t.context), i = ((e) => {
195
+ let t = e.fixedStrings ? ((e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))(e.pattern) : e.pattern;
196
+ e.word && (t = `(?<!\\w)(?:${t})(?!\\w)`);
197
+ const n = e.ignoreCase ? "iu" : "u";
198
+ try {
199
+ return new RegExp(t, n);
200
+ } catch {
201
+ try {
202
+ return new RegExp(t, n.replace("u", ""));
203
+ } catch (t) {
204
+ throw new Error(`Invalid regex ${JSON.stringify(e.pattern)}: ${t instanceof Error ? t.message : String(t)}. Use fixedStrings (-F) to search for the literal text.`);
205
+ }
206
+ }
207
+ })(t), c = w(e, t.scope, a), g = !n.some((e) => k.includes(e)), u = n.includes("display") && n.includes("value"), d = "content" === r || "addresses" === r, h = [], f = [];
208
+ let m = 0, p = 0, $ = !1;
209
+ for (const { sheet: e, address: t } of c) {
210
+ if ($) continue;
211
+ const c = e.getName();
212
+ p++, await e.getCalculation().ready();
213
+ const y = null !== t ? e.getRange(t) : e.getUsedRange();
214
+ if (!y) continue;
215
+ const x = l && "content" === r ? N(l, c, y) : null;
216
+ let S = 0;
217
+ y.forEach((e, t) => {
218
+ if (g && null == e) return;
219
+ const a = t.getCell(), l = [];
220
+ let f, p = null;
221
+ for (const e of n) {
222
+ const t = C(a, e);
223
+ if ("display" === e && (f = t?.match ?? null), null !== t && ("value" !== e || !u || (void 0 === f && (f = C(a, "display")?.match ?? null), t.match !== f)) && (null === p && (p = {
224
+ field: e,
225
+ text: t.display
226
+ }), i.test(t.match) && (l.push({
227
+ field: e,
228
+ text: t.display
229
+ }), "addresses" === r && !s))) break;
230
+ }
231
+ if (!(s ? l.length > 0 || null === p : 0 === l.length)) {
232
+ if (o > 0 && m >= o) return $ = !0, { break: !0 };
233
+ if (m++, S++, d) {
234
+ const e = s ? [p] : "addresses" === r ? l.slice(0, 1) : l, n = x?.resolve(a, t.getCoords()), o = t.getAddress();
235
+ for (const t of e) h.push({
236
+ sheet: c,
237
+ address: o,
238
+ field: t.field,
239
+ text: t.text,
240
+ ...n ? { context: n } : {}
241
+ });
242
+ }
243
+ }
244
+ }, a ? void 0 : { ignoreHidden: !0 }), S > 0 && f.push({
245
+ sheet: c,
246
+ cells: S
247
+ });
248
+ }
249
+ return {
250
+ pattern: t.pattern,
251
+ fields: n,
252
+ scope: t.scope?.trim() || "workbook",
253
+ matches: h,
254
+ cellCount: m,
255
+ sheets: f,
256
+ sheetsSearched: p,
257
+ sheetsMatched: f.length,
258
+ truncated: $,
259
+ output: r
260
+ };
261
+ }
262
+ var R = (e) => {
263
+ const t = e.replace(/\s+/g, " ").trim();
264
+ return t.length > 120 ? `${t.slice(0, 119)}…` : t;
265
+ }, v = (e, t, n, r) => {
266
+ const o = t.map((e) => r ? `${e.sheet}!${e.address}` : e.address), s = Math.max(...o.map((e) => e.length)), a = Math.max(...t.map((e) => e.field.length));
267
+ for (let r = 0; r < t.length; r++) {
268
+ const l = t[r];
269
+ e.push(`${n}${o[r].padEnd(s)} ${l.field.padEnd(a)} ${R(l.text)}`);
270
+ }
271
+ };
272
+ function F(e) {
273
+ const { pattern: t, fields: n, scope: r, matches: o, cellCount: s, sheetsSearched: a, sheetsMatched: l } = e, i = [`grep "${t}" · ${r} · fields ${n.join(",")} · ${s} ${1 === s ? "cell" : "cells"} in ${l} of ${a} ${1 === a ? "sheet" : "sheets"}`];
274
+ if ("count" === e.output) for (const t of e.sheets) i.push(` ${t.sheet}: ${t.cells}`);
275
+ else if ("sheets" === e.output) {
276
+ for (const t of e.sheets) i.push(` ${t.sheet}`);
277
+ 0 === e.sheets.length && i.push(" no matches");
278
+ } else if (0 === o.length) i.push(" no matches");
279
+ else if ("addresses" === e.output) for (const e of o) i.push(` ${e.sheet}!${e.address}`);
280
+ else {
281
+ const e = [], t = /* @__PURE__ */ new Map();
282
+ for (const n of o) {
283
+ const r = n.context?.range ?? "";
284
+ let o = t.get(r);
285
+ o || (o = {
286
+ key: r,
287
+ heading: n.context ? n.context.table ? `${n.context.range} · ${n.context.table}` : n.context.range : null,
288
+ rows: []
289
+ }, t.set(r, o), e.push(o)), o.rows.push(n);
290
+ }
291
+ for (const t of e) t.heading ? (i.push(` ${t.heading}`), v(i, t.rows, " ", !1)) : v(i, t.rows, " ", !0);
292
+ }
293
+ return e.truncated && i.push(` …truncated at ${s} ${1 === s ? "cell" : "cells"} · narrow the pattern, or scope the search to one sheet or range`), i.join("\n");
294
+ }
295
+ var T = {
296
+ name: "grep",
297
+ 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.",
298
+ params: [
299
+ {
300
+ name: "pattern",
301
+ type: "string",
302
+ description: "The regular expression to search for (literal with fixedStrings).",
303
+ required: !0,
304
+ positional: 0
305
+ },
306
+ {
307
+ name: "fields",
308
+ type: "enum[]",
309
+ values: x,
310
+ defaultValue: S,
311
+ 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%\")."
312
+ },
313
+ {
314
+ name: "fixedStrings",
315
+ type: "boolean",
316
+ alias: "F",
317
+ defaultValue: !1,
318
+ description: "Treat the pattern as a literal string, not a regular expression."
319
+ },
320
+ {
321
+ name: "ignoreCase",
322
+ type: "boolean",
323
+ alias: "i",
324
+ defaultValue: !1,
325
+ description: "Case-insensitive matching."
326
+ },
327
+ {
328
+ name: "word",
329
+ type: "boolean",
330
+ alias: "w",
331
+ defaultValue: !1,
332
+ description: "Require the match to fall on word boundaries (text edges count as edges)."
333
+ },
334
+ {
335
+ name: "invert",
336
+ type: "boolean",
337
+ alias: "v",
338
+ defaultValue: !1,
339
+ description: "Report cells where no requested field matched. Only cells with text in a requested field are considered — blanks are not findings."
340
+ },
341
+ {
342
+ name: "scope",
343
+ type: "string",
344
+ 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."
345
+ },
346
+ {
347
+ name: "hidden",
348
+ type: "boolean",
349
+ defaultValue: !1,
350
+ description: "Search hidden rows, columns and sheets, which are excluded by default. Naming a hidden sheet in scope always searches it."
351
+ },
352
+ {
353
+ name: "context",
354
+ type: "enum",
355
+ values: ["contentful", "table"],
356
+ alias: "C",
357
+ valueOptional: !0,
358
+ 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."
359
+ },
360
+ {
361
+ name: "maxCount",
362
+ type: "number",
363
+ alias: "m",
364
+ defaultValue: 200,
365
+ description: "Stop after this many matching cells (0 = unlimited). Truncation is always reported, and only when a further match actually exists."
366
+ },
367
+ {
368
+ name: "output",
369
+ type: "enum",
370
+ values: [
371
+ "content",
372
+ "addresses",
373
+ "count",
374
+ "sheets"
375
+ ],
376
+ defaultValue: "content",
377
+ description: "What to return: content (address, layer and text), addresses (one per matched cell), count (per sheet), or sheets (names with a match)."
378
+ }
379
+ ],
380
+ run: E,
381
+ render: F
382
+ }, j = (e, t) => e <= t + 3 ? e : t, I = (e) => {
383
+ if (!e) return null;
384
+ const t = String(e.toHex?.() ?? "");
385
+ if (!t) return e.toString();
386
+ const n = /^#FF/i.test(t) && 9 === t.length ? `#${t.slice(3)}` : t, r = e.toString();
387
+ if (!r) return n;
388
+ const o = r.toLowerCase().replace(/^#/, "");
389
+ return o === n.slice(1).toLowerCase() || o === t.slice(1).toLowerCase() ? n : `${n} (${r.replace(/\d+\.\d{4,}/g, (e) => String(parseFloat(Number(e).toFixed(2))))})`;
390
+ }, A = (e) => {
391
+ const t = e.getFill(), n = t.getType();
392
+ if (n === l.Type.None) return null;
393
+ if (n === l.Type.Pattern) {
394
+ const e = t, n = e.getPatternType();
395
+ if (n === l.BuiltInSheetPattern.None) return null;
396
+ const r = I(e.getForeground());
397
+ if (n === l.BuiltInSheetPattern.Solid) return r ? `solid ${r}` : "solid";
398
+ const o = I(e.getBackground());
399
+ return [
400
+ `${n} pattern`,
401
+ r,
402
+ o ? `on ${o}` : null
403
+ ].filter(Boolean).join(" ");
404
+ }
405
+ const r = I(t.getColor?.());
406
+ return r ? `${n} ${r}` : n;
407
+ }, M = (e) => {
408
+ const t = L(e);
409
+ return t.length > 0 ? t.join(" · ") : null;
410
+ }, D = /* @__PURE__ */ new Set([
411
+ "top",
412
+ "left",
413
+ "bottom",
414
+ "right"
415
+ ]), L = (e) => {
416
+ const t = e.getBorder(), n = [
417
+ ["top", t.getTop()],
418
+ ["left", t.getLeft()],
419
+ ["bottom", t.getBottom()],
420
+ ["right", t.getRight()],
421
+ ["horizontal", t.getHorizontal()],
422
+ ["vertical", t.getVertical()],
423
+ ["diagonalUp", t.getDiagonalUp()],
424
+ ["diagonalDown", t.getDiagonalDown()]
425
+ ], r = /* @__PURE__ */ new Map();
426
+ for (const [e, t] of n) {
427
+ const n = t?.getStyle?.();
428
+ if (!n || "none" === n) continue;
429
+ const o = I(t?.getColor?.()), s = o ? `${n} ${o}` : n, a = r.get(s);
430
+ a ? a.push(e) : r.set(s, [e]);
431
+ }
432
+ const o = [];
433
+ for (const [e, t] of r) {
434
+ const n = 4 === t.length && t.every((e) => D.has(e));
435
+ o.push(`${n ? "outline" : t.join("+")} ${e}`);
436
+ }
437
+ return o;
438
+ }, V = (e) => {
439
+ const t = e.getNumberFormat();
440
+ return t && "General" !== t ? t : null;
441
+ }, O = (e, t) => {
442
+ const n = e.getAlignment(), r = t.getAlignment(), o = [];
443
+ return n.getHorizontal() !== r.getHorizontal() && o.push(`h ${n.getHorizontal()}`), n.getVertical() !== r.getVertical() && o.push(`v ${n.getVertical()}`), n.getOverflow() !== r.getOverflow() && o.push(n.getOverflow()), n.getIndent() !== r.getIndent() && o.push(`indent ${n.getIndent()}`), n.getRotation() !== r.getRotation() && o.push(`rotation ${n.getRotation()}`), o.length > 0 ? o.join(" · ") : null;
444
+ }, B = (e, t) => {
445
+ const n = e.getFont(), r = t.getFont(), o = [];
446
+ n.getBold() !== r.getBold() && o.push(n.getBold() ? "bold" : "not bold"), n.getItalic() !== r.getItalic() && o.push(n.getItalic() ? "italic" : "not italic"), n.getUnderline() !== r.getUnderline() && o.push(`underline ${n.getUnderline()}`), n.getStrike() !== r.getStrike() && o.push(n.getStrike() ? "strike" : "not strike"), n.getSize() !== r.getSize() && o.push(`${n.getSize()}pt`), n.getFamily() !== r.getFamily() && o.push(n.getFamily());
447
+ const s = I(n.getColor());
448
+ return s !== I(r.getColor()) && o.push(s ?? "no color"), o.length > 0 ? o.join(" · ") : null;
449
+ }, H = (e, t) => e.length > t ? `${e.slice(0, t - 1)}…` : e, _ = (e) => {
450
+ if (!e) return null;
451
+ if ("string" != typeof e) return I(e);
452
+ const t = e.replace(/^#/, "");
453
+ return /^[0-9a-f]{6}$/i.test(t) || /^[0-9a-f]{8}$/i.test(t) ? `#${(8 === t.length && /^ff/i.test(t) ? t.slice(2) : t).toUpperCase()}` : e;
454
+ }, U = (e) => {
455
+ if (!e) return null;
456
+ const t = [], n = ((e) => {
457
+ if (!e) return null;
458
+ if ("string" == typeof e) return _(e);
459
+ const t = e.type;
460
+ if (t === l.Type.None) return null;
461
+ if (t === l.Type.Gradient) return "gradient";
462
+ const n = e, r = _(n.foreground ?? e.color ?? n.background), o = n.patternType;
463
+ return [o && o !== l.BuiltInSheetPattern.Solid ? `${o} pattern` : null, r].filter(Boolean).join(" ") || null;
464
+ })(e.fill);
465
+ n && t.push(`fill ${n}`);
466
+ const r = e.font;
467
+ if (r) {
468
+ const e = [];
469
+ (void 0 !== r.weight ? r.weight >= 600 : !0 === r.bold) && e.push("bold"), (void 0 !== r.style ? r.style === i.Style.Italic : !0 === r.italic) && e.push("italic"), r.strike && e.push("strike"), r.underline && r.underline !== i.UnderlineStyle.None && e.push(`underline ${r.underline}`);
470
+ const n = "auto" === r.color ? null : _(r.color);
471
+ n && e.push(`text ${n}`), e.length > 0 && t.push(e.join(" "));
472
+ }
473
+ if (void 0 !== e.numberFormat && null !== e.numberFormat) {
474
+ const n = "number" == typeof e.numberFormat ? `numFmt ${e.numberFormat}` : String(e.numberFormat);
475
+ n && t.push(n);
476
+ }
477
+ return e.border && t.push("border"), e.alignment && t.push("alignment"), t.length > 0 ? t.join(" · ") : null;
478
+ }, W = (e) => {
479
+ const t = e.type ?? s.ColorStopType.Num, n = e.value, r = null == n || "" === n ? t : `${t} ${n}`, o = _(e.color);
480
+ return o ? `${r} ${o}` : r;
481
+ }, P = (e) => {
482
+ let t = e.type;
483
+ if (e.type === s.ScaleType.DataBar) {
484
+ const n = _(e.color);
485
+ n && (t += ` ${n}`);
486
+ } else e.type === s.ScaleType.IconSet && (e.iconSet && (t += ` ${e.iconSet}`), e.reverse && (t += " reversed"));
487
+ const n = (e.stops ?? []).map(W).join(" → ");
488
+ return n ? `${t} · ${n}` : t;
489
+ }, z = "(no rule)", q = (e) => {
490
+ const t = e.getScale(), n = [];
491
+ if (t) n.push(P(t));
492
+ else {
493
+ n.push(e.getCondition()?.toString() || z);
494
+ const t = U(e.getStyle());
495
+ t && n.push(`→ ${t}`);
496
+ }
497
+ return e.isStopIfTrue() && n.push("· stop if true"), H(n.join(" "), 90);
498
+ }, J = (e) => {
499
+ const t = [e.getCondition()?.toString() || z], n = e.getAlertStyle();
500
+ return n && t.push(n), e.isIncludeBlanks() && t.push("blanks allowed"), e.isHideDropdown() && t.push("no dropdown"), H(t.join(" · "), 90);
501
+ }, K = (e) => {
502
+ if (e?.getOperator()?.getName() !== o.BuiltInOperatorNames.InSet) return null;
503
+ const t = e.getParam()?.items;
504
+ if (!t) return null;
505
+ if ("string" == typeof t) return t;
506
+ const n = t.slice(0, 20).map((e) => $(e)?.match ?? ""), r = t.length - n.length;
507
+ return r > 0 ? `${n.join(", ")}, +${r} more` : n.join(", ");
508
+ }, G = (e, t) => {
509
+ if (0 === e.length) return null;
510
+ const n = e.slice(0, 3).map(t), r = e.length - n.length;
511
+ return r > 0 ? `${n.join(" | ")} | +${r} more` : n.join(" | ");
512
+ }, X = r.Feature;
513
+ function Z(e, t) {
514
+ const n = t?.maxSeries ?? 24, r = t?.maxProfileCells ?? 2e4, o = t?.maxCategories ?? 3, s = e.getRowCount(), a = e.getColumnCount();
515
+ if (1 === s && 1 === a) return {
516
+ shape: "cell",
517
+ summary: `cell · ${p(e.getCell(), h.Mode.Display)?.display ?? "(blank)"}`,
518
+ series: []
519
+ };
520
+ const l = e.getRange(), i = l.getCoords(), c = s >= a;
521
+ if (1 === s || 1 === a) return {
522
+ shape: "list",
523
+ summary: `list · ${te(l, o)}`,
524
+ series: []
525
+ };
526
+ const g = function(e, t) {
527
+ const n = e.getRange(), r = n.getCoords(), o = e.getCell().getTable();
528
+ if (o) {
529
+ const e = o.getColumns().map((e) => e.getName());
530
+ return {
531
+ present: !0,
532
+ inside: !0,
533
+ note: `table "${o.getName()}"`,
534
+ names: t ? e : null
535
+ };
536
+ }
537
+ const s = t ? r.rowStart + 1 : r.colStart + 1, l = Q(t ? n.getRangeAt(s, r.colStart, r.rowEnd, r.colEnd) : n.getRangeAt(r.rowStart, s, r.rowEnd, r.colEnd)), i = t ? n.getRangeAt(r.rowStart, r.colStart, r.rowStart, r.colEnd) : n.getRangeAt(r.rowStart, r.colStart, r.rowEnd, r.colStart);
538
+ if (Q(i) && !l) return {
539
+ present: !0,
540
+ inside: !0,
541
+ note: "header " + (t ? `row ${r.rowStart + 1}` : `column ${le(r.colStart)}`),
542
+ names: Y(i, e, t)
543
+ };
544
+ const c = (t ? r.rowStart : r.colStart) - 1;
545
+ if (c >= 0 && !Q(n)) {
546
+ const o = t ? n.getRangeAt(c, r.colStart, c, r.colEnd) : n.getRangeAt(r.rowStart, c, r.rowEnd, c);
547
+ if (Q(o)) return {
548
+ present: !0,
549
+ inside: !1,
550
+ note: `header ${t ? `row ${c + 1}` : `column ${le(c)}`} (above this block)`,
551
+ names: Y(o, e, t)
552
+ };
553
+ }
554
+ return {
555
+ present: !1,
556
+ inside: !1,
557
+ note: "no header detected",
558
+ names: null
559
+ };
560
+ }(e, c), u = c ? a : s, d = c ? "" : " · by row", f = g.present && g.inside, m = c && f ? i.rowStart + 1 : i.rowStart, $ = !c && f ? i.colStart + 1 : i.colStart, y = i.rowEnd - m + 1, x = i.colEnd - $ + 1, S = y * x > r, b = S && c ? Math.max(1, Math.floor(r / Math.max(1, x))) : y, w = S && !c ? Math.max(1, Math.floor(r / Math.max(1, y))) : x, C = Math.min(i.rowEnd, m + b - 1), k = Math.min(i.colEnd, $ + w - 1), N = Math.min(u, n), E = [], R = [];
561
+ for (let t = 0; t < N; t++) {
562
+ const n = c ? l.getRangeAt(m, i.colStart + t, C, i.colStart + t) : l.getRangeAt(i.rowStart + t, $, i.rowStart + t, k);
563
+ E.push(ee(e, c, t, g.names)), R.push(te(n, o));
564
+ }
565
+ const v = E.length ? Math.max(...E.map((e) => e.length)) : 0, F = E.map((e, t) => `${e.padEnd(v)} ${R[t]}`);
566
+ u > N && F.push(`…${u - N} more ${c ? "columns" : "rows"} not profiled · read them with getStats()`);
567
+ const T = [g.present ? `table${d}` : `block${d}`, g.note];
568
+ return S && T.push(`profiled from the first ${c ? `${b} rows` : `${w} columns`} of ${c ? y : x}`), {
569
+ shape: g.present ? "table" : "block",
570
+ summary: T.filter(Boolean).join(" · "),
571
+ series: F
572
+ };
573
+ }
574
+ function Q(e) {
575
+ const t = e.getStats({ onError: "ignore" }), n = t.getCount();
576
+ return n > 0 && (t.getTypedCounts()[d.String] ?? 0) === n;
577
+ }
578
+ function Y(e, t, n) {
579
+ const r = t.getRange().getCoords(), o = e.getCoords(), s = n ? r.colEnd - r.colStart + 1 : r.rowEnd - r.rowStart + 1, a = [];
580
+ for (let t = 0; t < s; t++) {
581
+ const s = n ? e.getRangeAt(o.rowStart, r.colStart + t).getCell() : e.getRangeAt(r.rowStart + t, o.colStart).getCell();
582
+ a.push(p(s, h.Mode.Display)?.match ?? "");
583
+ }
584
+ return a;
585
+ }
586
+ function ee(e, t, n, r) {
587
+ const o = e.getRange().getCoords(), s = t ? le(o.colStart + n) : String(o.rowStart + n + 1), a = r?.[n];
588
+ return a ? `${s} ${a}` : s;
589
+ }
590
+ function te(e, t = 3) {
591
+ const n = e.getStats({ onError: "ignore" }), r = n.getTypedCounts(), o = n.getCount(), s = n.getSize(), a = s - o;
592
+ if (0 === o) return `${s} cells, all blank`;
593
+ const l = e.getCounts([X.Formula])[X.Formula] ?? 0, i = re(e), c = r[d.Number] ?? 0, g = r[d.String] ?? 0, u = r[d.Error] ?? 0, h = [String(o)];
594
+ let f = !1;
595
+ if (l === o) {
596
+ const t = [...e.getRegions(X.Formula)];
597
+ if (1 === t.length) {
598
+ const e = t[0].getCell().getFormulaText();
599
+ h.push("formula", e ? `=${e}` : "(uniform)");
600
+ } else h.push("formula", `${t.length} distinct`);
601
+ } else if (i === o) h.push("date", oe(n, e));
602
+ else if (c === o) h.push("number", oe(n, e), ...se(n, e));
603
+ else if (g === o) h.push("text", ae(n, t));
604
+ else {
605
+ const e = [
606
+ c ? `number ${c}` : null,
607
+ g ? `text ${g}` : null,
608
+ r[d.Boolean] ? `boolean ${r[d.Boolean]}` : null,
609
+ u ? `error ${u}` : null
610
+ ].filter(Boolean);
611
+ h.push("mixed", e.join(" · ")), f = !0;
612
+ }
613
+ const m = [
614
+ u > 0 && !f ? `error ${u}` : null,
615
+ a > 0 ? `${a} blank` : null,
616
+ l > 0 && l !== o ? `${l} formula` : null
617
+ ].filter(Boolean), p = h.filter(Boolean).join(" ");
618
+ return m.length ? `${p} · ${m.join(" · ")}` : p;
619
+ }
620
+ function ne(e, t = 3) {
621
+ const n = e.getStats({ onError: "ignore" }), r = n.getTypedCounts(), o = [], s = r[d.Number] ?? 0;
622
+ if (s > 0) {
623
+ const t = [oe(n, e), ...se(n, e)].filter(Boolean);
624
+ o.push(`Number: ${s} ${t.join(" ")}`.trimEnd());
625
+ }
626
+ const a = r[d.String] ?? 0;
627
+ if (a > 0) {
628
+ const e = ae(n, t, (e) => "string" == typeof e);
629
+ o.push(`String: ${a} ${e}`.trimEnd());
630
+ }
631
+ const l = r[d.Boolean] ?? 0;
632
+ if (l > 0) {
633
+ const e = ae(n, t, (e) => "boolean" == typeof e);
634
+ o.push(`Boolean: ${l} ${e}`.trimEnd());
635
+ }
636
+ return o;
637
+ }
638
+ function re(e) {
639
+ let t = 0;
640
+ return e.forEach((e, n) => {
641
+ n.getInteropType() === g.Date && t++;
642
+ }), t;
643
+ }
644
+ function oe(e, t) {
645
+ const n = e.getAggregates({ onError: "ignore" });
646
+ if (null === n.min || null === n.max) return "";
647
+ const r = t.getStyle().getNumberFormat(), o = m(n.min, r), s = m(n.max, r);
648
+ return o === s ? o : `${o} … ${s}`;
649
+ }
650
+ function se(e, t) {
651
+ const n = e.getAggregates({ onError: "ignore" }), r = t.getStyle().getNumberFormat(), o = [];
652
+ return null !== n.sum && o.push(`Σ ${m(n.sum, r)}`), null !== n.average && o.push(`x̄ ${m(n.average, r)}`), o;
653
+ }
654
+ function ae(e, t, n) {
655
+ const r = e.getFrequencies(n ? { filterFn: n } : void 0), o = r.getUniqueCount();
656
+ if (0 === o) return "";
657
+ if (o === r.getTotalCount()) return `${o} distinct, no repeats`;
658
+ const s = Array.from(r.getValueCounts()).slice(0, t);
659
+ return `${o} unique (${s.map(([e, t]) => `${e} ${t}`).join(" · ")}${o > s.length ? " · …" : ""})`;
660
+ }
661
+ function le(e) {
662
+ let t = e, n = "";
663
+ do
664
+ n = String.fromCharCode(65 + t % 26) + n, t = Math.floor(t / 26) - 1;
665
+ while (t >= 0);
666
+ return n;
667
+ }
668
+ var ie = r.Feature, ce = (e) => e.getRange().getStyle(), ge = (e) => p(e.getCell(), h.Mode.Display)?.display ?? null;
669
+ function ue(e, t) {
670
+ switch (e) {
671
+ case ie.Formula: return (e) => {
672
+ const t = e.getCell().getFormulaText();
673
+ return t ? `=${t}` : null;
674
+ };
675
+ case ie.Error: return ge;
676
+ case ie.CalcError: return (e) => {
677
+ const t = ge(e) ?? "", n = e.getCell().getFormulaText();
678
+ return (n ? `${t} =${n}` : t).trim() || null;
679
+ };
680
+ case ie.Merge: return ge;
681
+ case ie.Comments: return (e) => {
682
+ const t = e.getCell().getComments()?.content;
683
+ if ("string" != typeof t) return null;
684
+ const n = t.replace(/\s+/g, " ").trim();
685
+ return n ? n.length > 60 ? `${n.slice(0, 59)}…` : n : null;
686
+ };
687
+ case ie.Spills: return (e) => e.getCell().getSpill()?.getValuesRange().toString() ?? null;
688
+ case ie.Hyperlink: return (e) => e.getCell().getHyperlink()?.getAddress() ?? null;
689
+ case ie.Table: return (e) => e.getCell().getTable()?.getName() ?? null;
690
+ case ie.Fill: return (e) => A(ce(e));
691
+ case ie.Border: return (e) => M(ce(e));
692
+ case ie.NumberFormat: return (e) => V(ce(e));
693
+ case ie.Alignment: return t ? (e) => O(ce(e), t) : void 0;
694
+ case ie.Font: return t ? (e) => B(ce(e), t) : void 0;
695
+ case ie.Conditionals: return (e) => G(e.getRange().getConditionalFormats(), q);
696
+ case ie.DataValidations: return (e) => G(e.getRange().getDataValidations(), J);
697
+ case ie.Contentful: return (e) => ne(e.getRange()).join(" ") || null;
698
+ default: return;
699
+ }
700
+ }
701
+ function de(e, t) {
702
+ const n = e.map((e) => ue(e, t)).filter((e) => !!e);
703
+ if (0 !== n.length) return 1 === n.length ? n[0] : (e) => {
704
+ const t = n.map((t) => t(e)).filter(Boolean);
705
+ return t.length > 0 ? t.join(" ") : null;
706
+ };
707
+ }
708
+ var he = class {
709
+ constructor() {
710
+ this._lines = [], this._headingOffset = 0;
711
+ }
712
+ setHeadingOffset(e) {
713
+ return this._headingOffset = e, this;
714
+ }
715
+ _heading(e, t) {
716
+ return this._lines.push(`${"#".repeat(Math.min(6, e + this._headingOffset))} ${t}`), this;
717
+ }
718
+ h1(e) {
719
+ return this._heading(1, e);
720
+ }
721
+ h2(e) {
722
+ return this._heading(2, e);
723
+ }
724
+ h3(e) {
725
+ return this._heading(3, e);
726
+ }
727
+ text(e) {
728
+ return this._lines.push(e), this;
729
+ }
730
+ blank() {
731
+ return this._lines.push(""), this;
732
+ }
733
+ bullet(e) {
734
+ return "string" == typeof e ? this._lines.push(`- ${e}`) : e.forEach((e) => this._lines.push(`- ${e}`)), this;
735
+ }
736
+ fact(e) {
737
+ return "string" == typeof e ? this._lines.push(` ${e}`) : e.forEach((e) => this._lines.push(` ${e}`)), this;
738
+ }
739
+ bold(e) {
740
+ return `**${e}**`;
741
+ }
742
+ codespan(e) {
743
+ return `\`${e}\``;
744
+ }
745
+ code(e, t = "") {
746
+ return `\`\`\`${t}\n${e}\n\`\`\``;
747
+ }
748
+ beginFrame(e) {
749
+ return new fe(this, e);
750
+ }
751
+ _addLines(e) {
752
+ this._lines.push(...e);
753
+ }
754
+ toLines() {
755
+ return [...this._lines];
756
+ }
757
+ }, fe = class {
758
+ constructor(e, t) {
759
+ this._parent = e, this._headers = t, this._indexWidth = 0, this._rows = [], this._colWidths = t.map((e) => e.length);
760
+ }
761
+ addRow(e, t) {
762
+ const n = e.map((e) => "string" == typeof e ? { text: e } : e);
763
+ return n.forEach((e, t) => {
764
+ this._colWidths[t] = Math.max(this._colWidths[t] ?? 0, e.text.length);
765
+ }), void 0 !== t && (this._indexWidth = Math.max(this._indexWidth, t.length)), this._rows.push({
766
+ index: t,
767
+ cells: n
768
+ }), this;
769
+ }
770
+ endFrame() {
771
+ return this._parent._addLines(this._renderLines()), this._parent;
772
+ }
773
+ _columnAlignment(e) {
774
+ let t = 0, n = 0;
775
+ for (const r of this._rows) {
776
+ const o = r.cells[e];
777
+ o && o.text && (n++, "right" === o.alignment && t++);
778
+ }
779
+ return n > 0 && 2 * t >= n ? "right" : void 0;
780
+ }
781
+ _renderLines() {
782
+ const e = " ", t = this._indexWidth > 0 ? " ".repeat(this._indexWidth) : "", n = this._colWidths.map((e, t) => this._columnAlignment(t)), r = [];
783
+ if (this._headers.some((e) => e.length > 0)) {
784
+ const o = this._headers.map((e, t) => me(e, this._colWidths[t], n[t])).join(e);
785
+ r.push(`${t}${t ? e : ""}${o}`.trimEnd());
786
+ }
787
+ for (const t of this._rows) {
788
+ const n = t.cells.map((e, t) => me(e.text, this._colWidths[t], e.alignment)).join(e), o = this._indexWidth > 0 ? (t.index ?? "").padStart(this._indexWidth) + e : "";
789
+ r.push(`${o}${n}`.trimEnd());
790
+ }
791
+ return r;
792
+ }
793
+ }, me = (e, t, n) => {
794
+ if (e.length >= t) return e;
795
+ const r = t - e.length;
796
+ return "right" === n ? e.padStart(t) : "center" === n ? " ".repeat(Math.floor(r / 2)) + e + " ".repeat(Math.ceil(r / 2)) : e.padEnd(t);
797
+ };
798
+ function pe(e, t, n) {
799
+ const r = j(t.length, n?.maxRegions ?? 200), o = t.length > r ? t.slice(0, r) : t, s = o.length < t.length;
800
+ if (0 === o.length) return void e.text("None");
801
+ const a = o.map((e) => e.toString()), l = Math.max(...a.map((e) => e.length)), i = o.map((e) => `${e.getRowCount()}×${e.getColumnCount()}`), c = Math.max(...i.map((e) => e.length)), g = n?.profile ? n?.maxProfiled ?? 12 : 0;
802
+ for (let t = 0; t < o.length; t++) {
803
+ const r = o[t], s = n?.payload?.(r), u = r.isClipped() ? " ✂ clipped at the query edge — the block continues" : "", d = ` ${a[t].padEnd(l)} ${i[t].padEnd(c)}`;
804
+ if (t < g) {
805
+ const t = Z(r, n);
806
+ e.text(`${d} ${t.summary}${u}`);
807
+ for (const n of t.series) e.text(` ${n}`);
808
+ continue;
809
+ }
810
+ e.text(s ? `${d} ${s}${u}` : `${d}${u}`.trimEnd());
811
+ }
812
+ if (g > 0 && o.length > g && e.text(` …${o.length - g} more regions listed but not profiled · profile one with getRange().getStats(), or loop them in code`), s) {
813
+ const o = n?.recovery ?? "narrow the range, or loop the regions in code — this listing is a report, not the query";
814
+ e.text(` …truncated at ${r} of ${t.length} regions · ${o}`);
815
+ }
816
+ }
817
+ function $e(e, t) {
818
+ const n = [...e], o = e.getFeatures(), s = o.join(", "), a = 1 === o.length && o[0] === r.Feature.Contentful, l = e.getRange().getSheet().getWorkbook()?.getStyles().getNormal() ?? null, i = new he();
819
+ return i.h1(`Regions — ${s} (${n.length})`), pe(i, n, {
820
+ ...t,
821
+ profile: a,
822
+ payload: a ? void 0 : de(o, l)
823
+ }), i.toLines().join("\n").trimEnd();
824
+ }
825
+ function ye(e, t) {
826
+ const n = t.getRange();
827
+ e.text(`Name: ${t.getName()}`);
828
+ const r = t.getDescription();
829
+ r && e.text(`Description: ${r}`);
830
+ const o = n.getRowCount(), s = n.getColumnCount();
831
+ e.text(`Location: ${n.toString()}, ${o} row${1 !== o ? "s" : ""} x ${s} column${1 !== s ? "s" : ""}`);
832
+ const a = t.getColumns().map((e) => e.getName());
833
+ e.text(`Columns (${a.length}): ${a.join(", ")}`), e.text("Headers: " + (t.isShowHeaders() ? "shown" : "hidden")), e.text("Totals: " + (t.isShowTotals() ? "shown" : "hidden"));
834
+ }
835
+ function xe(e) {
836
+ const t = new he();
837
+ return t.h1(`Table — ${e.getName()}`), t.text(`Sheet: ${Ee(e.getRange().getSheet().getName())}`), t.blank(), ye(t, e), t.toLines().join("\n").trimEnd();
838
+ }
839
+ var Se = r.Feature, be = [
840
+ Se.Error,
841
+ Se.CalcError,
842
+ Se.Contentful,
843
+ Se.Formula,
844
+ Se.Spills,
845
+ Se.Merge,
846
+ Se.Table,
847
+ Se.AutoTable,
848
+ Se.Hyperlink,
849
+ Se.Comments,
850
+ Se.Unlock,
851
+ Se.NumberFormat,
852
+ Se.Font,
853
+ Se.Fill,
854
+ Se.Border,
855
+ Se.Alignment,
856
+ Se.Conditionals,
857
+ Se.DataValidations
858
+ ], we = new Map(Object.entries(Se).map(([e, t]) => [t, e])), Ce = (e) => we.get(e) ?? e;
859
+ function ke(e) {
860
+ const t = new Map(Object.values(Se).map((e) => [e.toLowerCase(), e])), n = [];
861
+ for (const r of e.split(",")) {
862
+ const e = r.trim();
863
+ if (!e) continue;
864
+ const o = t.get(e.toLowerCase());
865
+ if (!o) throw new Error(`Unknown feature '${e}'. Features: ${Object.values(Se).join(", ")}.`);
866
+ n.push(o);
867
+ }
868
+ return n;
869
+ }
870
+ var Ne = (e) => `${e.toString()}, ${e.getRowCount()}×${e.getColumnCount()}`, Ee = (t) => e.sheetNameToString(t) ?? "Untitled", Re = (e) => `wb.getSheet(${JSON.stringify(e.getSheet().getName())})`, ve = (e) => ((e) => {
871
+ if (!e.includes("$")) return e;
872
+ let t = "", n = !1;
873
+ for (const r of e) {
874
+ if ("'" === r) n = !n;
875
+ else if ("$" === r && !n) continue;
876
+ t += r;
877
+ }
878
+ return t;
879
+ })(e.getAddress()), Fe = (e) => {
880
+ const t = ve(e);
881
+ return t.includes("!") ? t : `${Ee(e.getSheet().getName())}!${t}`;
882
+ }, Te = (e) => {
883
+ const t = e.toString();
884
+ return `${t.includes("!") ? t : `${Ee(e.getSheet().getName())}!${t}`}, ${e.getRowCount()}×${e.getColumnCount()}`;
885
+ };
886
+ function je(e, t) {
887
+ const n = t.getStats({ onError: "ignore" }), r = n.getTypedCounts(), o = re(t), s = [
888
+ ["Error", r[d.Error] ?? 0],
889
+ ["Number", r[d.Number] ?? 0],
890
+ ["String", r[d.String] ?? 0],
891
+ ["Date", o],
892
+ ["Boolean", r[d.Boolean] ?? 0],
893
+ ["RichData", r[d.RichData] ?? 0]
894
+ ].filter(([, e]) => e > 0), a = n.getCount();
895
+ e.h2(`Kind (${a} cell${1 !== a ? "s" : ""} · ${s.length} kind${1 !== s.length ? "s" : ""})`);
896
+ for (const [t, n] of s) e.fact(`${t}: ${n}`);
897
+ 0 === s.length && e.fact("None"), e.blank();
898
+ }
899
+ function Ie(e, t, n) {
900
+ const r = t.getSheet().getWorkbook()?.getStyles().getNormal() ?? null, o = void 0 === n?.features ? null : new Set("string" == typeof n.features ? [n.features] : n.features), s = be.filter((e) => !o || o.has(e));
901
+ if (0 === s.length) return;
902
+ const a = t.getCounts(s);
903
+ for (const o of s) {
904
+ const s = [...t.getRegions(o)];
905
+ if (0 === s.length) continue;
906
+ const l = !!n?.profile && o === Se.Contentful;
907
+ e.h2(`${Ce(o)} (${Ae(s.length, a[o])})`), pe(e, s, {
908
+ maxRegions: n?.maxRegions,
909
+ maxProfiled: n?.maxProfiled,
910
+ profile: l,
911
+ payload: l ? void 0 : ue(o, r),
912
+ recovery: `${Re(t)}.getRegions(${JSON.stringify(o)}) lists all ${s.length}`
913
+ }), e.blank();
914
+ }
915
+ }
916
+ var Ae = (e, t) => `${t} cell${1 !== t ? "s" : ""} · ${e} region${1 !== e ? "s" : ""}`, Me = (e, t) => e.length > t ? `${e.slice(0, t - 1)}…` : e, De = (e) => e.isIFormula ? e : null, Le = (e) => {
917
+ const t = e.getScope();
918
+ return t ? `${Ee(t)}!${e.getName()}` : e.getName();
919
+ }, Ve = (e) => {
920
+ const t = e.getAddress();
921
+ return t.includes("!") ? t : `${Ee(e.getSheet().getName())}!${t}`;
922
+ };
923
+ function Oe(e) {
924
+ const t = De(e);
925
+ let n;
926
+ return n = t ? "=" + t.getExpression() : e.getRanges?.()?.getAddress() ?? "", t?.isVolatile() && (n += " (volatile)"), n.trim();
927
+ }
928
+ var Be = /* @__PURE__ */ new Set([t.Code.Ref, t.Code.Name]), He = (e) => {
929
+ const n = e.value, r = t.isError(n) ? n : n?.error;
930
+ return r && Be.has(r.getCode()) ? r.getCode() === t.Code.Name ? "#NAME?" : "#REF!" : null;
931
+ }, _e = /* @__PURE__ */ new Set(), Ue = (e) => {
932
+ const t = e.value;
933
+ return "object" == typeof t && t?.name ? t.name : e.text ?? "";
934
+ };
935
+ function We(e) {
936
+ let t = null;
937
+ for (let n = 0; n < e.length; n++) {
938
+ const r = e[n];
939
+ if ("named" !== r.type || !r.context) continue;
940
+ const o = r.context.name?.toUpperCase();
941
+ if ("LAMBDA" !== o && ("LET" !== o || r.context.argIndex % 2 != 0)) continue;
942
+ let s = n + 1;
943
+ for (; s < e.length && "whitespace" === e[s].type;) s++;
944
+ if ("separator" !== e[s]?.type) continue;
945
+ const a = Ue(r).toLowerCase();
946
+ a && (t ??= /* @__PURE__ */ new Set()).add(a);
947
+ }
948
+ return t ?? _e;
949
+ }
950
+ function Pe(e, t, n) {
951
+ if (0 === t.length) return;
952
+ const r = /* @__PURE__ */ new Set();
953
+ for (const e of n?.symbols ?? t) r.add(e.getName().toLowerCase());
954
+ const o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
955
+ for (const e of t) o.set(e.getId(), e), e.getScope() && s.add(e.getName().toLowerCase());
956
+ const a = t.map((e) => {
957
+ const t = function(e, t) {
958
+ const n = De(e), r = [];
959
+ if (n) {
960
+ const e = n.getTokens();
961
+ let o = null, s = null;
962
+ for (const n of e) {
963
+ if ("error" === n.type) {
964
+ s ??= He(n);
965
+ continue;
966
+ }
967
+ if ("named" !== n.type) continue;
968
+ const a = Ue(n);
969
+ a && !t.has(a.toLowerCase()) && (o ??= We(e), o.has(a.toLowerCase()) || r.includes(a) || r.push(a));
970
+ }
971
+ if (s || r.length > 0) return {
972
+ broken: !0,
973
+ missing: r,
974
+ error: r.length > 0 ? `#NAME?: ${r.join(", ")}` : s
975
+ };
976
+ if (!n.isReferenceOnly()) return {
977
+ broken: !1,
978
+ missing: r,
979
+ error: ""
980
+ };
981
+ }
982
+ let o = null;
983
+ try {
984
+ o = e.getRanges?.() ?? null;
985
+ } catch (e) {
986
+ return {
987
+ broken: !0,
988
+ missing: r,
989
+ error: "#REF!"
990
+ };
991
+ }
992
+ const s = !o || o.isInvalidAny();
993
+ return {
994
+ broken: s,
995
+ missing: r,
996
+ error: s ? "#REF!" : ""
997
+ };
998
+ }(e, r), n = De(e);
999
+ let a = n ? function(e, t) {
1000
+ const n = e.getDirectDependents();
1001
+ let r = 0;
1002
+ const o = [], s = /* @__PURE__ */ new Set(), a = [];
1003
+ if (n) {
1004
+ const e = n.getCoords(), l = n.getCount();
1005
+ for (let i = 0; i < l; i++) {
1006
+ const l = n.at(i);
1007
+ if (l.isINamedRange) {
1008
+ const e = l;
1009
+ if (s.has(e.getId())) continue;
1010
+ s.add(e.getId());
1011
+ const n = t.get(e.getId());
1012
+ o.push(n ? Le(n) : e.getName());
1013
+ } else {
1014
+ const t = e[i];
1015
+ r += (t.rowEnd - t.rowStart + 1) * (t.colEnd - t.colStart + 1), a.push(Ve(l));
1016
+ }
1017
+ }
1018
+ }
1019
+ const l = r + o.length;
1020
+ if (0 === l) return {
1021
+ text: "unused",
1022
+ weight: l
1023
+ };
1024
+ const i = [...o, ...a], c = [];
1025
+ let g = 0;
1026
+ for (let e = 0; e < i.length; e++) {
1027
+ const t = (c.length > 0 ? 2 : 0) + i[e].length;
1028
+ if (c.length > 0 && g + t > 60) break;
1029
+ c.push(0 === c.length ? Me(i[e], 60) : i[e]), g += t;
1030
+ }
1031
+ const u = i.length - c.length, d = u > 0 ? `, +${u} more` : "";
1032
+ return {
1033
+ text: `${l} · ${c.join(", ")}${d}`,
1034
+ weight: l
1035
+ };
1036
+ }(n, o) : null;
1037
+ 0 === a?.weight && !e.getScope() && s.has(e.getName().toLowerCase()) && (a = {
1038
+ ...a,
1039
+ text: "unused · shadowed"
1040
+ });
1041
+ const l = e.getComment() ?? "", i = Le(e);
1042
+ return {
1043
+ name: i,
1044
+ refersTo: Oe(e),
1045
+ dependents: a,
1046
+ hidden: e.isHidden(),
1047
+ comment: Me(l, 60),
1048
+ broken: t.broken,
1049
+ error: t.error,
1050
+ sortKey: i.toLowerCase().replace(/'/g, "")
1051
+ };
1052
+ }), l = (e, t) => {
1053
+ const n = (t.dependents?.weight ?? 0) - (e.dependents?.weight ?? 0);
1054
+ return 0 !== n ? n : e.sortKey.localeCompare(t.sortKey);
1055
+ }, i = [...a.filter((e) => e.broken).sort(l), ...a.filter((e) => !e.broken).sort(l)], c = j(i.length, n?.maxNames ?? 200), g = i.length > c ? i.slice(0, c) : i, u = g.filter((e) => e.broken), d = g.filter((e) => !e.broken);
1056
+ e.h2(`${n?.heading ?? "Names"} (${a.length})`);
1057
+ const h = (t, n) => {
1058
+ const r = t.some((e) => e.hidden), o = t.some((e) => e.comment.length > 0), s = t.some((e) => null !== e.dependents), a = ["Name", "Refers To"];
1059
+ n && a.push("Error"), s && a.push("Dependents"), r && a.push("Hidden"), o && a.push("Comment");
1060
+ const l = e.beginFrame(a);
1061
+ for (const e of t) {
1062
+ const t = [{ text: e.name }, { text: e.refersTo }];
1063
+ n && t.push({ text: e.error }), s && t.push({ text: e.dependents?.text ?? "" }), r && t.push({ text: e.hidden ? "hidden" : "" }), o && t.push({ text: e.comment }), l.addRow(t);
1064
+ }
1065
+ l.endFrame();
1066
+ };
1067
+ if (u.length > 0) {
1068
+ const t = i.reduce((e, t) => e + (t.broken ? 1 : 0), 0);
1069
+ e.text(`${t} ${1 === t ? "does" : "do"} not resolve:`), h(u, !0), e.blank();
1070
+ }
1071
+ if (d.length > 0 && h(d, !1), g.length < a.length) {
1072
+ const t = n?.recovery ?? "getByName('Name') renders one in full";
1073
+ e.text(` …and ${a.length - g.length} more · ${t}`);
1074
+ }
1075
+ e.blank();
1076
+ }
1077
+ function ze(e, t, n) {
1078
+ Je(e, "Precedents", t, "precedents", n), Je(e, "Dependents", t, "dependents", n);
1079
+ }
1080
+ function qe(e) {
1081
+ const t = e.isINamedRange ? e.getId() : null;
1082
+ if (t) return `name:${t}`;
1083
+ const n = e.getCoords();
1084
+ return `${e.getSheet()?.getName() ?? ""}!${n.rowStart},${n.colStart},${n.rowEnd},${n.colEnd}`;
1085
+ }
1086
+ function Je(e, t, n, r, o) {
1087
+ const s = o?.maxDepth ?? 3, a = o?.maxNodes ?? 50, l = [], i = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set();
1088
+ let g = !1, u = !1, d = !1;
1089
+ const h = (e, t) => {
1090
+ const n = ((e) => "precedents" === r ? e.getDirectPrecedents() : e.getDirectDependents())(e);
1091
+ if (n && 0 !== n.length) if (t > s) g = !0;
1092
+ else for (let e = 0; e < n.length; e++) {
1093
+ if (l.length >= a) return void (u = !0);
1094
+ const r = n.at(e), { address: o, sheet: s, isName: g } = Ke(r), f = " ".repeat(t), m = qe(r), p = {
1095
+ indent: f,
1096
+ sheet: s,
1097
+ isName: g,
1098
+ label: `${f}${o}`
1099
+ };
1100
+ c.has(m) ? (l.push({
1101
+ ...p,
1102
+ detail: "↺ circular"
1103
+ }), d = !0) : i.has(m) ? l.push({
1104
+ ...p,
1105
+ detail: "↑ shown above"
1106
+ }) : (i.add(m), c.add(m), l.push({
1107
+ ...p,
1108
+ detail: Ge(r)
1109
+ }), h(r, t + 1), c.delete(m));
1110
+ }
1111
+ };
1112
+ if (h(n, 0), 0 === l.length) return;
1113
+ const f = l.filter((e) => !e.isName);
1114
+ if (f.length > 0 && f.some((e) => e.sheet !== f[0].sheet)) for (const e of l) e.isName || (e.label = `${e.indent}${e.sheet}!${e.label.slice(e.indent.length)}`);
1115
+ e.h2(t);
1116
+ const m = Math.max(...l.map((e) => e.label.length));
1117
+ for (const t of l) e.text(` ${t.label.padEnd(m)} ${t.detail}`.trimEnd());
1118
+ d && e.text(" ↺ circular reference — the chain returns to a cell already on this branch");
1119
+ const p = "precedents" === r ? "getPrecedents()" : "getDependents()";
1120
+ if (g && e.text(` …deeper levels not walked · ${p} is the whole reach, flat`), u) {
1121
+ const t = "precedents" === r ? "getDirectPrecedents()" : "getDirectDependents()";
1122
+ e.text(` …truncated at ${a} nodes · re-root on one node and walk it — its ${t}`);
1123
+ }
1124
+ e.blank();
1125
+ }
1126
+ function Ke(e) {
1127
+ const t = e.getSheet()?.getName() ?? "";
1128
+ if (e.isINamedRange) return {
1129
+ address: e.getName(),
1130
+ sheet: t,
1131
+ isName: !0
1132
+ };
1133
+ const n = e.getAddress(), r = n.lastIndexOf("!");
1134
+ return {
1135
+ address: r >= 0 && r < n.length - 1 ? n.slice(r + 1) : n,
1136
+ sheet: t,
1137
+ isName: !1
1138
+ };
1139
+ }
1140
+ function Ge(e) {
1141
+ if (e.isINamedRange) {
1142
+ const t = e.getRanges();
1143
+ return t ? `name → ${t.getAddress()}` : "name";
1144
+ }
1145
+ if (e.isSingleCell()) {
1146
+ const t = e.getCell(), n = p(t, h.Mode.Display), r = t.getFormulaText(), o = n ? n.display : "(empty)";
1147
+ return r ? `${o} =${r}` : o;
1148
+ }
1149
+ const t = `${e.getRowCount()}×${e.getColumnCount()}`, n = [...e.getRegions(Se.Formula)];
1150
+ if (1 === n.length && n[0].getRange().isEqual(e)) {
1151
+ const e = n[0].getCell().getFormulaText();
1152
+ if (e) return `${t} =${e}`;
1153
+ }
1154
+ return t;
1155
+ }
1156
+ function Xe(e, t, n) {
1157
+ const r = n.getCoords().min, o = [];
1158
+ let s = 0, a = 0;
1159
+ if (n.forEachSpan((e, t) => {
1160
+ const l = t.getCoords();
1161
+ if (a++, s += l.max - l.min + 1, o.length >= 100) return;
1162
+ const i = n.at(l.min - r).getText(), c = n.at(l.max - r).getText();
1163
+ o.push({
1164
+ address: `${i}:${c}`,
1165
+ count: l.max - l.min + 1
1166
+ });
1167
+ }, {
1168
+ visibility: "hidden",
1169
+ includeEmpty: !0
1170
+ }), 0 === s) return;
1171
+ e.h2(`${t} (${s})`);
1172
+ const l = Math.max(...o.map((e) => e.address.length));
1173
+ for (const t of o) e.text(` ${t.address.padEnd(l)} ${t.count}`);
1174
+ a > o.length && e.text(` …and ${a - o.length} more`), e.blank();
1175
+ }
1176
+ function Ze(e, t, n, r) {
1177
+ if (0 === n.length) return;
1178
+ const o = n.length > 50 ? n.slice(0, 50) : n, s = o.map((e) => ({
1179
+ address: Me(ve(e.getRanges()), 40),
1180
+ rule: r(e)
1181
+ }));
1182
+ e.h2(`${t} (${n.length})`);
1183
+ const a = Math.max(...s.map((e) => e.address.length));
1184
+ for (const t of s) e.text(` ${t.address.padEnd(a)} ${t.rule}`.trimEnd());
1185
+ o.length < n.length && e.text(` …and ${n.length - o.length} more`), e.blank();
1186
+ }
1187
+ function Qe(e, t) {
1188
+ const n = t.getSheet(), r = t.getCoords(), o = n.getName(), s = [];
1189
+ for (const e of n.getNames().getItems({
1190
+ type: "formula",
1191
+ includeHidden: !0
1192
+ }) ?? []) {
1193
+ let t = null;
1194
+ try {
1195
+ t = e.getRanges?.() ?? null;
1196
+ } catch (e) {}
1197
+ t ? t.getCoords().some((e) => {
1198
+ return (!e.scope || e.scope === o) && (n = e, (t = r).rowStart <= n.rowEnd && n.rowStart <= t.rowEnd && t.colStart <= n.colEnd && n.colStart <= t.colEnd);
1199
+ var t, n;
1200
+ }) && s.push(e) : e.getScope() === o && s.push(e);
1201
+ }
1202
+ Pe(e, s, { symbols: n.getWorkbook()?.getNames().getItems({ includeHidden: !0 }) ?? n.getNames().getItems({ includeHidden: !0 }) ?? [] });
1203
+ const a = t.getColumnHeaders(), l = t.getRowHeaders();
1204
+ Xe(e, "Hidden Columns", a), Xe(e, "Hidden Rows", l);
1205
+ const i = t.getTables();
1206
+ i.length > 0 && (e.h2("Tables"), i.forEach((t, n) => {
1207
+ n > 0 && e.blank(), ye(e, t);
1208
+ }), e.blank());
1209
+ }
1210
+ var Ye = {
1211
+ features: (e) => ke(e),
1212
+ mode: (e, t) => function(e, t, n) {
1213
+ const r = new Map(Object.values(n).map((e) => [e.toLowerCase(), e])).get(e.trim().toLowerCase());
1214
+ if (!r) throw new Error(`Unknown ${t} '${e}'. Values: ${Object.values(n).join(", ")}.`);
1215
+ return r;
1216
+ }(e, t, h.Mode)
1217
+ }, et = Object.keys(Ye);
1218
+ function tt(e) {
1219
+ const t = {};
1220
+ for (const [n, r] of Object.entries(e)) {
1221
+ const e = Ye[n];
1222
+ if (!e) throw new Error(`Unknown report option '${n}'. Options: ${et.join(", ")}.`);
1223
+ t[n] = e(r, n);
1224
+ }
1225
+ return t;
1226
+ }
1227
+ function nt(e, t) {
1228
+ e = e.getSheet().getRange(e.getCoords()).getCell();
1229
+ const n = new he();
1230
+ return n.h1(`Cell — ${Ee(e.getSheet().getName())}!${e.getAddress()}`), n.blank(), function(e, t) {
1231
+ const n = p(t, h.Mode.Display), r = p(t, h.Mode.Value), o = t.getFormulaText(), s = e.toLines().length;
1232
+ (n || o) && (e.fact(`Type: ${t.getType()}`), n && e.fact(`Display: ${n.display}`), r && r.match !== n?.match && e.fact(`Value: ${r.display}`), o && e.fact(`Formula: ${e.codespan(`=${o}`)}`));
1233
+ const a = t.getHyperlink();
1234
+ a && e.fact(`Hyperlink: ${a.getAddress()}`);
1235
+ const l = t.getSpans(), i = !t.isTopLeft();
1236
+ if (i || l.height > 1 || l.width > 1) {
1237
+ const n = t.getRange().toString();
1238
+ e.fact(`Merge: ${n} · ${l.height}×${l.width}`), i && e.fact("Merge Anchor: false — this cell is covered; the value lives at the top-left");
1239
+ }
1240
+ const c = t.getSpill();
1241
+ c && e.fact(`Spill: ${c.toString()}`);
1242
+ t.isSpillOverflow() && e.fact("Spill Overflow: true — the anchor formula is elsewhere");
1243
+ const g = t.getTable();
1244
+ g && e.fact(`Table: ${g.getName()}`);
1245
+ const u = t.getErrors();
1246
+ u.length > 0 && e.fact(`Errors: ${u.join("; ")}`);
1247
+ const d = t.getWarnings();
1248
+ d.length > 0 && e.fact(`Warnings: ${d.join("; ")}`);
1249
+ e.toLines().length > s && e.blank();
1250
+ }(n, e), function(e, t) {
1251
+ const n = t.getStyle(), r = t.getSheet().getWorkbook()?.getStyles().getNormal() ?? null, o = V(n), s = r ? B(n, r) : null, a = A(n), l = L(n), i = r ? O(n, r) : null, c = n.getNamed().getName();
1252
+ if (!(c !== (r?.getNamed().getName() ?? "Normal") || o || s || a || i || 0 !== l.length)) return;
1253
+ e.h2("Style"), e.fact(`Named: ${c}`), o && e.fact(`Number Format: ${o}`);
1254
+ s && e.fact(`Font: ${s}`);
1255
+ a && e.fact(`Fill: ${a}`);
1256
+ if (1 === l.length) e.fact(`Border: ${l[0]}`);
1257
+ else if (l.length > 1) {
1258
+ e.fact("Border:");
1259
+ for (const t of l) e.fact(` ${t}`);
1260
+ }
1261
+ i && e.fact(`Alignment: ${i}`);
1262
+ e.blank();
1263
+ }(n, e), ze(n, e, t), n.toLines().join("\n").trimEnd();
1264
+ }
1265
+ var rt = /* @__PURE__ */ new Set(["picture"]), ot = (e) => e.replace(/[\r\n]+/g, " ").trim(), st = (e) => {
1266
+ switch (e.getType()) {
1267
+ case "chart": {
1268
+ const t = [], n = e.getChartType?.();
1269
+ n && "unknown" !== n && t.push(n);
1270
+ const r = e.getChartTitle?.();
1271
+ return r && t.push(`"${r}"`), t.length > 0 ? t.join(" · ") : null;
1272
+ }
1273
+ case "picture": return e.getResource?.()?.getName() || null;
1274
+ default: return null;
1275
+ }
1276
+ }, at = (e) => {
1277
+ const t = e.getContent(), n = [], r = st(t);
1278
+ r && n.push(r);
1279
+ const o = e.getDescription();
1280
+ o && n.push(ot(o));
1281
+ const s = e.getName() || "(unnamed)", a = n.length > 0 ? `${s} — ${n.join(" · ")}` : s;
1282
+ return i = 90, ((l = a).length > i ? `${l.slice(0, i - 1)}…` : l) + (e.isHidden() ? " (hidden)" : "");
1283
+ var l, i;
1284
+ };
1285
+ function lt(e, t) {
1286
+ if (0 === t.length) return;
1287
+ const n = t.length > 50 ? t.slice(0, 50) : t, r = n.map((e) => ({
1288
+ address: e.getRange().toString(),
1289
+ type: e.getContent().getType(),
1290
+ summary: at(e)
1291
+ }));
1292
+ e.h2(`Movables (${t.length})`);
1293
+ const o = Math.max(...r.map((e) => e.address.length)), s = Math.max(...r.map((e) => e.type.length));
1294
+ for (const t of r) e.text(` ${t.address.padEnd(o)} ${t.type.padEnd(s)} ${t.summary}`.trimEnd());
1295
+ n.length < t.length && e.text(` …and ${t.length - n.length} more`);
1296
+ const a = [...new Set(r.map((e) => e.type).filter((e) => !rt.has(e)))];
1297
+ a.length > 0 && e.text(` Not drawn: ${a.join(", ")} — SheetXL shows a labeled placeholder for these in the UI.`), e.blank();
1298
+ }
1299
+ function it(e) {
1300
+ const t = new he(), r = e.getRange(), o = e.getContent(), s = o.getType();
1301
+ t.h1(`Movable — ${Te(r)}`), t.blank(), t.fact(`Name: ${e.getName() || "(unnamed)"}`), t.fact(`Type: ${s}`);
1302
+ const a = st(o);
1303
+ a && t.fact(`Content: ${a}`);
1304
+ const l = e.getDescription();
1305
+ l && t.fact(`Alt Text: ${ot(l)}`), t.fact(`Anchor: ${Ne(r)}, ${((e) => {
1306
+ switch (e) {
1307
+ case n.Type.Absolute: return "absolute — stays put when rows or columns move";
1308
+ case n.Type.OneCell: return "oneCell — moves with the cells, keeps its size";
1309
+ default: return "twoCell — moves and resizes with the cells";
1310
+ }
1311
+ })(e.getAnchorType?.())}`), t.fact(`Bounds: ${((e) => {
1312
+ const t = e.getBounds();
1313
+ if (!t) return "not laid out";
1314
+ const n = (e) => Math.round(e);
1315
+ return `${n(t.width)}×${n(t.height)} px at (${n(t.x)}, ${n(t.y)})`;
1316
+ })(e)}`), e.isHidden() && t.fact("Hidden: true — this object is not visible in the UI");
1317
+ const i = e.getRotation();
1318
+ return 0 !== i && t.fact(`Rotation: ${i}°`), t.fact(`Z-Order: ${e.getZIndex()}`), t.fact(`Display: ${((e) => rt.has(e) ? "drawn" : `placeholder — SheetXL frames the ${e} at this position but does not draw its content`)(s)}`), t.blank(), t.text(`Sheet: ${Ee(r.getSheet().getName())}`), t.toLines().join("\n").trimEnd();
1319
+ }
1320
+ function ct(e, t) {
1321
+ const n = new he();
1322
+ n.h1(`Cell Range — ${Te(e)}`), n.blank(), je(n, e), function(e, t, n) {
1323
+ if (!1 === n?.profile) return;
1324
+ if (t.isSingleCell() || !t.isContentful()) return;
1325
+ const r = Z({
1326
+ getRowCount: () => t.getRowCount(),
1327
+ getColumnCount: () => t.getColumnCount(),
1328
+ getCell: () => t.getCell(),
1329
+ getRange: () => t
1330
+ }, n);
1331
+ e.h2("Profile"), e.text(r.summary);
1332
+ for (const t of r.series) e.text(` ${t}`);
1333
+ e.blank();
1334
+ }(n, e, t);
1335
+ const o = function(e, t, n) {
1336
+ const r = n?.mode ?? h.Mode.Display, o = n?.maxCells ?? 1e3, { rowStart: s, colStart: a } = t.getCoords(), l = t.getRowHeaders(), i = t.getColumnHeaders(), c = /* @__PURE__ */ new Map(), g = [];
1337
+ let u = 0, d = !1;
1338
+ t.forEach((e, t) => {
1339
+ if (u >= o) return d = !0, { break: !0 };
1340
+ const n = t.getCell(), s = n.getFormulaText(), a = p(n, r);
1341
+ if (!a && !s) return;
1342
+ const l = {
1343
+ text: (a?.display ?? "").replace(/\|/g, "\\|").replace(/[\r\n]+/g, " "),
1344
+ alignment: n.getRenderHorizontalAlignment()
1345
+ }, i = n.getSpill();
1346
+ i && g.push({
1347
+ address: n.getAddress(),
1348
+ valuesRange: i.getValuesRange().toString()
1349
+ });
1350
+ const { rowIndex: h, colIndex: f } = t.getCoords();
1351
+ let m = c.get(h);
1352
+ m || (m = /* @__PURE__ */ new Map(), c.set(h, m)), m.set(f, l), u++;
1353
+ });
1354
+ const f = Array.from(c.keys()).sort((e, t) => e - t), m = /* @__PURE__ */ new Set();
1355
+ c.forEach((e) => e.forEach((e, t) => m.add(t)));
1356
+ const $ = Array.from(m).sort((e, t) => e - t);
1357
+ if (0 === f.length) return { spills: g };
1358
+ const y = t.getIntersect({
1359
+ rowStart: f[0],
1360
+ rowEnd: f[f.length - 1],
1361
+ colStart: $[0],
1362
+ colEnd: $[$.length - 1]
1363
+ }), x = `${u} cell${1 !== u ? "s" : ""}`, S = y.toString() !== t.toString();
1364
+ e.h2(`Values (${S ? `${Ne(y)} · ` : ""}${x})`);
1365
+ const b = e.beginFrame($.map((e) => i.at(e - a).getText()));
1366
+ for (const e of f) {
1367
+ const t = c.get(e);
1368
+ b.addRow($.map((e) => t?.get(e) ?? { text: "" }), l.at(e - s).getText());
1369
+ }
1370
+ b.endFrame(), d && e.text(`…truncated at ${o} cells · narrow the address, or summarize the whole range with getStats()`);
1371
+ return e.blank(), { spills: g };
1372
+ }(n, e, t);
1373
+ return function(e, t, n) {
1374
+ const o = [];
1375
+ for (const e of t.getRegions(r.Feature.Formula)) {
1376
+ const t = e.getCell().getFormulaText();
1377
+ if (t && (o.push({
1378
+ address: e.getAddress(),
1379
+ size: `${e.getRowCount()}×${e.getColumnCount()}`,
1380
+ formula: `=${t}`
1381
+ }), o.length >= (n?.maxRegions ?? 100))) break;
1382
+ }
1383
+ if (0 === o.length) return;
1384
+ e.h2("Formulas");
1385
+ const s = Math.max(...o.map((e) => e.address.length)), a = Math.max(...o.map((e) => e.size.length));
1386
+ for (const t of o) e.text(` ${t.address.padEnd(s)} ${t.size.padEnd(a)} ${t.formula}`);
1387
+ e.blank();
1388
+ }(n, e, t), function(e, t) {
1389
+ if (0 === t.length) return;
1390
+ e.h2("Spills");
1391
+ const n = Math.max(...t.map((e) => e.address.length));
1392
+ for (const { address: r, valuesRange: o } of t) e.text(` ${r.padEnd(n)} ${o}`);
1393
+ e.blank();
1394
+ }(n, o.spills), Qe(n, e), lt(n, e.getMovables()), Ze(n, "Conditional Formats", e.getConditionalFormats(), q), Ze(n, "Data Validations", e.getDataValidations(), J), ze(n, e, t), n.toLines().join("\n").trimEnd();
1395
+ }
1396
+ function gt(e) {
1397
+ const t = new he(), n = e.getRanges();
1398
+ t.h1(`Conditional Format — ${Fe(n)}`), t.blank(), t.fact(`Order: ${e.getIndex() + 1}`);
1399
+ const r = e.getScale();
1400
+ if (r) t.fact(`Rule: ${P(r)}`);
1401
+ else {
1402
+ const n = e.getCondition();
1403
+ t.fact(`Rule: ${n?.toString() || "none — this rule tests nothing"}`);
1404
+ const r = U(e.getStyle());
1405
+ r && t.fact(`Format: ${r}`);
1406
+ }
1407
+ 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("\n").trimEnd();
1408
+ }
1409
+ function ut(e) {
1410
+ const t = new he();
1411
+ t.h1("Counts");
1412
+ let n = !1;
1413
+ for (const [r, o] of Object.entries(e)) o > 0 && (t.fact(`${r}: ${o}`), n = !0);
1414
+ return n || t.fact("None"), t.toLines().join("\n").trimEnd();
1415
+ }
1416
+ function dt(e) {
1417
+ const t = new he(), n = e.getRanges();
1418
+ t.h1(`Data Validation — ${Fe(n)}`), t.blank();
1419
+ const r = e.getCondition();
1420
+ t.fact(`Rule: ${r?.toString() || "none — anything is accepted here"}`);
1421
+ const o = K(r);
1422
+ o && t.fact(`Allowed: ${o}`), t.fact("Blanks: " + (e.isIncludeBlanks() ? "allowed" : "rejected"));
1423
+ const s = e.getAlertStyle();
1424
+ if (t.fact(`Alert: ${s}${s === a.AlertStyle.Stop ? " — the entry is refused" : " — the entry is accepted anyway"}`), e.isShowAlertMessage()) {
1425
+ const n = ht(e.getAlertTitle(), e.getAlertMessage());
1426
+ n && t.fact(`Alert Message: ${n}`);
1427
+ }
1428
+ if (e.isShowPromptMessage()) {
1429
+ const n = ht(e.getPromptTitle(), e.getPromptMessage());
1430
+ n && t.fact(`Prompt: ${n}`);
1431
+ }
1432
+ return e.isHideDropdown() && t.fact("Dropdown: hidden"), t.fact(`Cells: ${n.size}`), t.toLines().join("\n").trimEnd();
1433
+ }
1434
+ var ht = (e, t) => {
1435
+ const n = [e?.trim(), t?.trim()].filter(Boolean);
1436
+ return n.length > 0 ? n.join(" — ") : null;
1437
+ }, ft = "function", mt = "named", pt = "tableReference", $t = "tableColumn", yt = "externalReference", xt = [["isReferenceOnly", "reference-only"], ["isVolatile", "volatile"]];
1438
+ var St = (e, t) => e ? ` (${Ee(e)}!${t})` : "";
1439
+ function bt(e, t, n, r) {
1440
+ if ("external" === e) return "another workbook — not resolvable from here";
1441
+ if (!n) return "";
1442
+ switch (e) {
1443
+ case "function": {
1444
+ const e = n.getCalculation().getFunctions().getByName(t);
1445
+ return e ? e.isBuiltIn() ? "built-in" : "custom" : "unknown — evaluates to #NAME?";
1446
+ }
1447
+ case "named": return function(e, t) {
1448
+ const n = t.getNames(), r = n.getByName(e) ?? n.getByName(e, !0);
1449
+ if (r) {
1450
+ const e = St(r.getScope(), r.getName()), t = r.getRanges?.();
1451
+ return !t || t.isInvalid() ? `defined name — reference does not resolve${e}` : `${t.toString()}${e}`;
1452
+ }
1453
+ const o = t.getCalculation().getNamedFormulas().getByName(e);
1454
+ return o ? `=${o.getExpression()}${St(o.getScope(), o.getName())}` : "unknown — evaluates to #NAME?";
1455
+ }(t, n);
1456
+ case "table": {
1457
+ const e = n.getTables().getByName(t) ?? n.getWorkbook()?.getSheets().getItems().map((e) => e.getTables().getByName(t)).find(Boolean) ?? null;
1458
+ return e ? ((e, t) => {
1459
+ const n = e.getSheet(), r = e.toString();
1460
+ return !n || t && n.getName() === t.getName() || r.includes("!") ? r : `${Ee(n.getName())}!${r}`;
1461
+ })(e.getRange(), n) : "unknown — evaluates to #NAME?";
1462
+ }
1463
+ case "column": {
1464
+ if (!r) return "column of the enclosing table";
1465
+ const e = n.getTables().getByName(r);
1466
+ if (!e) return `column of ${r}`;
1467
+ const o = t.replace(/^\[|\]$/g, "").trim();
1468
+ return e.getColumns().find((e) => e.getName() === o) ? `${r} column` : `no such column in ${r} — evaluates to #REF!`;
1469
+ }
1470
+ }
1471
+ return "";
1472
+ }
1473
+ async function wt(e, t) {
1474
+ const n = t?.maxTokens ?? 200, r = new he(), o = ((e) => e.isINamed ? e : null)(e);
1475
+ if (r.h1(o ? `Name — ${Le(o)}` : "Formula"), r.text(r.codespan("=" + e.getExpression())), r.blank(), o) {
1476
+ o.isHidden() && r.fact("Hidden: true — not offered in the UI; formulas resolve it normally");
1477
+ const e = o.getComment();
1478
+ e && r.fact(`Comment: ${e}`);
1479
+ const t = o.getRanges?.();
1480
+ r.fact(`Refers to: ${t ? t.getAddress() : "no range — this name holds an expression"}`);
1481
+ }
1482
+ await async function(e, t) {
1483
+ let n;
1484
+ try {
1485
+ n = await t.evaluate();
1486
+ } catch (t) {
1487
+ e.fact(`Value: did not evaluate — ${t?.message ?? String(t)}`);
1488
+ return;
1489
+ }
1490
+ if ((r = n) && "object" == typeof r && !0 === r.isIRange) return void e.fact(`Value: spills ${n.getRowCount()}×${n.getColumnCount()} — an array result`);
1491
+ var r;
1492
+ const o = $(n);
1493
+ e.fact(`Value: ${o ? o.display : "(empty)"}`);
1494
+ }(r, e), r.fact(`Status: ${e.getCalculationStatus()}`), e.isValid() || r.fact("Valid: false — the text did not parse as a complete expression");
1495
+ const s = xt.filter(([t]) => e[t]()).map(([, e]) => e);
1496
+ s.length > 0 && r.fact(`Flags: ${s.join(" · ")}`), r.blank();
1497
+ const a = e.getReferences(), l = t?.context ?? a?.getSheet() ?? null, i = function(e, t) {
1498
+ const n = /* @__PURE__ */ new Map();
1499
+ let r = null;
1500
+ for (const o of e) {
1501
+ const e = o.text?.trim();
1502
+ if (!e) continue;
1503
+ let s;
1504
+ switch (o.type) {
1505
+ case ft:
1506
+ s = "function";
1507
+ break;
1508
+ case mt:
1509
+ s = "named";
1510
+ break;
1511
+ case pt:
1512
+ s = "table", r = e;
1513
+ break;
1514
+ case $t:
1515
+ s = "column";
1516
+ break;
1517
+ case yt:
1518
+ s = "external";
1519
+ break;
1520
+ default: continue;
1521
+ }
1522
+ const a = `${s}${e.toLowerCase()}`, l = n.get(a);
1523
+ l ? l.uses++ : n.set(a, {
1524
+ kind: s,
1525
+ text: e,
1526
+ uses: 1,
1527
+ resolution: bt(s, e, t, r)
1528
+ });
1529
+ }
1530
+ return [...n.values()];
1531
+ }(e.getTokens(), l);
1532
+ if (i.length > 0) {
1533
+ r.h2(`Symbols (${i.length})`);
1534
+ const e = r.beginFrame([
1535
+ "Kind",
1536
+ "Symbol",
1537
+ "Uses",
1538
+ "Resolves to"
1539
+ ]);
1540
+ for (const t of i) e.addRow([
1541
+ t.kind,
1542
+ t.text,
1543
+ String(t.uses),
1544
+ t.resolution
1545
+ ]);
1546
+ e.endFrame(), l || r.text("…no sheet context — pass `context` to resolve these"), r.blank();
1547
+ }
1548
+ if (r.h2("References"), a && 0 !== a.length) for (let e = 0; e < a.length; e++) r.text(` ${String(e).padStart(2)} ${a.at(e).getAddress()}`);
1549
+ else r.text("None");
1550
+ r.blank(), o && function(e, t) {
1551
+ t.getDirectDependents() || (e.h2("Dependents (0)"), e.text(" None — no formula references this name"), e.blank()), ze(e, t);
1552
+ }(r, o);
1553
+ const c = e.getTokens();
1554
+ if (r.h2("Tokens"), 0 === c.length) r.text("None");
1555
+ else {
1556
+ const e = c.length > n ? c.slice(0, n) : c, t = r.beginFrame([
1557
+ "#",
1558
+ "Type",
1559
+ "Text",
1560
+ "Enclosing",
1561
+ "Arg"
1562
+ ]);
1563
+ for (let n = 0; n < e.length; n++) {
1564
+ const r = e[n], o = r.context;
1565
+ t.addRow([
1566
+ {
1567
+ text: String(n),
1568
+ alignment: "right"
1569
+ },
1570
+ r.type ?? "",
1571
+ r.text ?? "",
1572
+ o?.name ?? "",
1573
+ o && o.argIndex >= 0 ? String(o.argIndex) : ""
1574
+ ]);
1575
+ }
1576
+ t.endFrame(), e.length < c.length && r.text(`…truncated at ${e.length} of ${c.length} tokens · search getTokens() directly`);
1577
+ }
1578
+ return r.toLines().join("\n").trimEnd();
1579
+ }
1580
+ var Ct = [["formula", "Names"], ["table", "Tables"]];
1581
+ function kt(e, t) {
1582
+ const n = new he(), r = e.getItems({ includeHidden: !0 }) ?? [];
1583
+ if (n.h1(`Names — ${r.length} item${1 !== r.length ? "s" : ""}`), n.blank(), 0 === r.length) return n.text("None"), n.toLines().join("\n").trimEnd();
1584
+ const o = new Set(Ct.map(([e]) => e));
1585
+ for (const [e, o] of Ct) Pe(n, r.filter((t) => t.getType() === e), {
1586
+ ...t,
1587
+ heading: o,
1588
+ symbols: r
1589
+ });
1590
+ const s = r.filter((e) => !o.has(e.getType())), a = [...new Set(s.map((e) => e.getType()))].sort();
1591
+ for (const e of a) Pe(n, s.filter((t) => t.getType() === e), {
1592
+ ...t,
1593
+ heading: e,
1594
+ symbols: r
1595
+ });
1596
+ return n.toLines().join("\n").trimEnd();
1597
+ }
1598
+ var Nt = (e) => {
1599
+ if (!e || "object" != typeof e || Array.isArray(e)) return !1;
1600
+ const t = Object.getPrototypeOf(e);
1601
+ return t === Object.prototype || null === t;
1602
+ };
1603
+ function Et(e, t) {
1604
+ const n = t?.maxCells ?? 1e3, r = Array.isArray(e) ? e : [e], o = new he();
1605
+ if (o.h1("Records"), o.text(`Count: ${r.length}`), o.blank(), 0 === r.length) return o.text("None"), o.toLines().join("\n").trimEnd();
1606
+ const s = (e) => {
1607
+ const t = [], n = /* @__PURE__ */ new Set();
1608
+ for (const r of e) for (const e of Object.keys(r ?? {})) n.has(e) || (n.add(e), t.push(e));
1609
+ return t;
1610
+ }, a = Math.max(1, s(r).length), l = j(r.length, Math.max(1, Math.floor(n / a))), i = r.length > l ? r.slice(0, l) : r, c = i.length === r.length ? s(r) : s(i);
1611
+ if (0 === c.length) return o.text("No fields"), o.toLines().join("\n").trimEnd();
1612
+ const g = o.beginFrame(c);
1613
+ for (const e of i) g.addRow(c.map((t) => Rt(e?.[t])));
1614
+ return g.endFrame(), i.length < r.length && o.text(`…truncated at ${i.length} of ${r.length} records · filter, sort or aggregate the array in the expression`), o.toLines().join("\n").trimEnd();
1615
+ }
1616
+ var Rt = (e) => {
1617
+ if (null == e) return { text: "" };
1618
+ if ("function" == typeof e) return { text: "[Function]" };
1619
+ if ("bigint" == typeof e || "symbol" == typeof e) return { text: Ft(String(e)) };
1620
+ if ("object" == typeof e) {
1621
+ if (e instanceof Date) return { text: e.toISOString() };
1622
+ const t = e;
1623
+ if (!0 === t.isFormulaError || !0 === t.isIRichData) return { text: Ft(vt(e)) };
1624
+ if (Nt(e) || Array.isArray(e)) {
1625
+ let t;
1626
+ try {
1627
+ t = JSON.stringify(e) ?? String(e);
1628
+ } catch {
1629
+ t = "[circular]";
1630
+ }
1631
+ return { text: Ft(t) };
1632
+ }
1633
+ return { text: Ft(String(e)) };
1634
+ }
1635
+ const t = Ft(vt(e).replace(/[\r\n]+/g, " "));
1636
+ return "number" == typeof e ? {
1637
+ text: t,
1638
+ alignment: "right"
1639
+ } : { text: t };
1640
+ }, vt = (e) => {
1641
+ try {
1642
+ return $(e)?.match ?? String(e);
1643
+ } catch {
1644
+ return String(e);
1645
+ }
1646
+ }, Ft = (e) => e.length > 80 ? `${e.slice(0, 79)}…` : e;
1647
+ function Tt(e, t) {
1648
+ const n = e.length, r = j(n, t?.maxRanges ?? 100), o = Math.min(n, r), s = [];
1649
+ for (let t = 0; t < o; t++) {
1650
+ const n = e.at(t);
1651
+ s.push({
1652
+ ...Ke(n),
1653
+ detail: Ge(n)
1654
+ });
1655
+ }
1656
+ const a = s.filter((e) => !e.isName), l = a.length > 0 && a.some((e) => e.sheet !== a[0].sheet), i = a.length > 0 ? a[0].sheet : e.getSheet()?.getName(), c = new he(), g = s.length > 0 && !l && !!i;
1657
+ if (c.h1(g ? `Ranges — ${Ee(i)} (${n})` : `Ranges (${n})`), 0 === s.length) return c.text("none"), c.toLines().join("\n").trimEnd();
1658
+ const u = s.map((e) => l && !e.isName ? `${Ee(e.sheet)}!${e.address}` : e.address), d = Math.max(...u.map((e) => e.length));
1659
+ for (let e = 0; e < s.length; e++) c.text(` ${u[e].padEnd(d)} ${s[e].detail}`.trimEnd());
1660
+ return o < n && c.text(` …and ${n - o} more · loop the collection in code to see them all`), c.toLines().join("\n").trimEnd();
1661
+ }
1662
+ function jt(e, t) {
1663
+ const n = new he(), r = e.getSelectedRange(), o = e.getUsedRange();
1664
+ n.h1(`Sheet — ${Ee(e.getName())}${function(e) {
1665
+ const t = e.getWorkbook();
1666
+ let n = "";
1667
+ t && t.getSelectedSheet()?.getId() === e.getId() && (n += " (selected)");
1668
+ const r = e.getVisibility();
1669
+ r === c.Visibility.Hidden ? n += " (hidden)" : r === c.Visibility.VeryHidden && (n += " (very hidden)");
1670
+ return n;
1671
+ }(e)}`), n.text(`Used: ${o ? Ne(o) : "empty"}`), n.text(`Selection: ${Ne(r)}`), n.blank();
1672
+ const s = o ?? r;
1673
+ return je(n, s), Ie(n, s, {
1674
+ profile: !0,
1675
+ ...t
1676
+ }), Qe(n, s), lt(n, e.getMovables().getItems()), n.toLines().join("\n").trimEnd();
1677
+ }
1678
+ var It = [
1679
+ ["numericalCount", "Numbers"],
1680
+ ["sum", "Sum"],
1681
+ ["min", "Min"],
1682
+ ["max", "Max"],
1683
+ ["average", "Average"],
1684
+ ["stdDev", "StdDev"]
1685
+ ];
1686
+ function At(e) {
1687
+ const t = new he();
1688
+ t.h1("Stats");
1689
+ const n = e.getTypedCounts();
1690
+ t.fact(`Cells: ${e.getSize()}`), t.fact(`Values: ${e.getCount()}`);
1691
+ const r = n[d.Error] ?? 0;
1692
+ r > 0 && t.fact(`Errors: ${r}`);
1693
+ const o = e.getAggregates({ onError: "ignore" });
1694
+ for (const [e, n] of It) {
1695
+ const r = o[e];
1696
+ null != r && t.fact(`${n}: ${f(r)}`);
1697
+ }
1698
+ const s = [];
1699
+ for (const [e, t] of Object.entries(n)) e !== d.Null && t && s.push(`${e.charAt(0).toUpperCase()}${e.slice(1)}: ${t}`);
1700
+ return s.length > 0 && (t.blank(), t.h2("Type"), t.fact(s)), t.toLines().join("\n").trimEnd();
1701
+ }
1702
+ function Mt(e) {
1703
+ const t = new he();
1704
+ t.h1("Style"), t.text(`Named: ${e.getNamed().getName()}`), t.blank();
1705
+ const n = e.toJSON(), r = n ? Object.entries(n).filter(([, e]) => void 0 !== e) : [];
1706
+ if (0 === r.length) t.fact("No direct styling (inherits the named style)");
1707
+ else for (const [e, n] of r) t.fact(`${e}: ${t.codespan("string" == typeof n ? n : JSON.stringify(n))}`);
1708
+ return t.toLines().join("\n").trimEnd();
1709
+ }
1710
+ function Dt(e, t) {
1711
+ const n = t?.maxCells ?? 1e3, r = Lt(e) ? e.getValues() : e, o = r.length, s = r.reduce((e, t) => Math.max(e, t?.length ?? 0), 0), a = new he();
1712
+ if (a.h1("Values"), a.text(`Size: ${o}×${s}`), a.blank(), 0 === o || 0 === s) return a.text("None"), a.toLines().join("\n").trimEnd();
1713
+ const l = j(o, Math.max(1, Math.floor(n / s))), i = o > l ? r.slice(0, l) : r, c = a.beginFrame(new Array(s).fill(""));
1714
+ for (const e of i) c.addRow(Array.from({ length: s }, (t, n) => Vt(e?.[n])));
1715
+ return c.endFrame(), i.length < o && a.text(`…truncated at ${i.length} of ${o} rows · slice or aggregate in the expression before returning it`), a.toLines().join("\n").trimEnd();
1716
+ }
1717
+ var Lt = (e) => !!e && "object" == typeof e && !0 === e.isIRange, Vt = (e) => {
1718
+ if (null == e) return { text: "" };
1719
+ const t = ($(e)?.display ?? "").replace(/[\r\n]+/g, " ");
1720
+ return "number" == typeof e ? {
1721
+ text: t,
1722
+ alignment: "right"
1723
+ } : { text: t };
1724
+ }, Ot = r.Feature;
1725
+ function Bt(e, t) {
1726
+ const n = new he();
1727
+ n.h1(`Workbook — ${e.getName() ?? "Untitled"}`), n.text(`Locale: ${e.getRuntime().getLocale()}`), n.blank();
1728
+ const r = e.getSheets().getItems({ visibility: c.Visibility.VeryHidden }), o = e.getSelectedSheet(), s = [];
1729
+ for (const e of r) {
1730
+ const t = e.getUsedRange();
1731
+ s.push({
1732
+ sheet: e,
1733
+ label: Ht(e, e.getId() === o.getId()),
1734
+ used: t?.toString() ?? "empty",
1735
+ counts: t?.getCounts([
1736
+ Ot.Contentful,
1737
+ Ot.Formula,
1738
+ Ot.Error,
1739
+ Ot.CalcError
1740
+ ]) ?? null
1741
+ });
1742
+ }
1743
+ let a = s;
1744
+ if (s.length > 50) {
1745
+ a = s.slice(0, 50);
1746
+ const e = s.find((e) => e.sheet.getId() === o.getId());
1747
+ e && !a.includes(e) && (a[a.length - 1] = e);
1748
+ }
1749
+ n.h2(`Sheets (${s.length})`);
1750
+ const l = n.beginFrame([
1751
+ "Sheet",
1752
+ "Used",
1753
+ "Cells",
1754
+ "Formulas",
1755
+ "Errors"
1756
+ ]);
1757
+ for (const e of a) l.addRow([
1758
+ { text: e.label },
1759
+ { text: e.used },
1760
+ {
1761
+ text: String(e.counts?.[Ot.Contentful] ?? 0),
1762
+ alignment: "right"
1763
+ },
1764
+ {
1765
+ text: String(e.counts?.[Ot.Formula] ?? 0),
1766
+ alignment: "right"
1767
+ },
1768
+ {
1769
+ text: String(e.counts?.[Ot.Error] ?? 0),
1770
+ alignment: "right"
1771
+ }
1772
+ ]);
1773
+ if (s.length > 1) {
1774
+ const e = (e) => s.reduce((t, n) => t + (n.counts?.[e] ?? 0), 0);
1775
+ l.addRow([
1776
+ { text: "Total" },
1777
+ { text: "" },
1778
+ {
1779
+ text: String(e(Ot.Contentful)),
1780
+ alignment: "right"
1781
+ },
1782
+ {
1783
+ text: String(e(Ot.Formula)),
1784
+ alignment: "right"
1785
+ },
1786
+ {
1787
+ text: String(e(Ot.Error)),
1788
+ alignment: "right"
1789
+ }
1790
+ ]);
1791
+ }
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
+ type: "formula",
1794
+ includeHidden: !0
1795
+ }) ?? [], {
1796
+ maxNames: t?.maxNames ?? 30,
1797
+ recovery: "wb.getNames() renders the full view",
1798
+ symbols: e.getNames().getItems({ includeHidden: !0 }) ?? []
1799
+ });
1800
+ const i = t?.maxSheets ?? 8, g = s.filter((e) => null !== e.sheet.getUsedRange()), u = g.slice(0, i), d = g.find((e) => e.sheet.getId() === o.getId());
1801
+ d && !u.includes(d) && (u[u.length - 1] = d), n.setHeadingOffset(1);
1802
+ for (const e of u) {
1803
+ const r = e.sheet.getUsedRange();
1804
+ r && (n.h1(`Sheet — ${e.label}`), je(n, r), Ie(n, r, {
1805
+ features: t?.features,
1806
+ maxRegions: t?.maxRegions ?? 25,
1807
+ profile: !0,
1808
+ maxProfiled: t?.maxProfiled ?? 4
1809
+ }), Qe(n, r));
1810
+ }
1811
+ return n.setHeadingOffset(0), u.length < g.length && n.text(`…and ${g.length - u.length} more sheets not expanded · a sheet report (\`wb.getSheet('Name')\`) renders one in full`), n.toLines().join("\n").trimEnd();
1812
+ }
1813
+ function Ht(e, t) {
1814
+ const n = e.getVisibility();
1815
+ let r = "";
1816
+ return t && (r += " (selected)"), n === c.Visibility.Hidden ? r += " (hidden)" : n === c.Visibility.VeryHidden && (r += " (very hidden)"), `${Ee(e.getName())}${r}`;
1817
+ }
1818
+ function _t(e, t, n, r) {
1819
+ const o = n.reduce((e, t) => e + (t.counts?.[r] ?? 0), 0);
1820
+ if (0 === o) return;
1821
+ const s = [];
1822
+ let a = 0;
1823
+ for (const e of n) {
1824
+ if (!e.counts?.[r]) continue;
1825
+ const t = e.sheet.getUsedRange();
1826
+ if (!t) continue;
1827
+ const n = Ee(e.sheet.getName());
1828
+ for (const e of t.getRegions(r)) a++, s.length >= 20 || s.push({
1829
+ address: `${n}!${e.toString()}`,
1830
+ size: `${e.getRowCount()}×${e.getColumnCount()}`,
1831
+ payload: Ut(e)
1832
+ });
1833
+ }
1834
+ e.h2(`${t} (${o})`);
1835
+ const l = Math.max(0, ...s.map((e) => e.address.length)), i = Math.max(0, ...s.map((e) => e.size.length));
1836
+ for (const t of s) e.text(` ${t.address.padEnd(l)} ${t.size.padEnd(i)} ${t.payload}`.trimEnd());
1837
+ a > s.length && e.text(` …and ${a - s.length} more · getRegions('${r}') on a sheet's used range lists the rest`), e.blank();
1838
+ }
1839
+ function Ut(e) {
1840
+ const t = e.getCell(), n = p(t, h.Mode.Display)?.display ?? "", r = t.getFormulaText();
1841
+ return r ? `${n} =${r}`.trim() : n;
1842
+ }
1843
+ var Wt = (e, t) => !!e && "object" == typeof e && !0 === e[t], Pt = [
1844
+ {
1845
+ kind: "workbook",
1846
+ is: (e) => Wt(e, "isIWorkbook"),
1847
+ render: (e, t) => Bt(e, t)
1848
+ },
1849
+ {
1850
+ kind: "sheet",
1851
+ is: (e) => Wt(e, "isISheet"),
1852
+ render: (e, t) => jt(e, t)
1853
+ },
1854
+ {
1855
+ kind: "cell",
1856
+ is: (e) => Wt(e, "isICell"),
1857
+ render: (e, t) => nt(e, t)
1858
+ },
1859
+ {
1860
+ kind: "names",
1861
+ is: (e) => Wt(e, "isINamedCollection"),
1862
+ render: (e, t) => kt(e, t)
1863
+ },
1864
+ {
1865
+ kind: "formula",
1866
+ is: (e) => Wt(e, "isIFormula"),
1867
+ render: (e, t) => wt(e, t)
1868
+ },
1869
+ {
1870
+ kind: "table",
1871
+ is: (e) => Wt(e, "isITable"),
1872
+ render: (e) => xe(e)
1873
+ },
1874
+ {
1875
+ kind: "movable",
1876
+ is: (e) => Wt(e, "isIMovable"),
1877
+ render: (e) => it(e)
1878
+ },
1879
+ {
1880
+ kind: "conditionalFormat",
1881
+ is: (e) => Wt(e, "isIConditionalFormat"),
1882
+ render: (e) => gt(e)
1883
+ },
1884
+ {
1885
+ kind: "dataValidation",
1886
+ is: (e) => Wt(e, "isIDataValidation"),
1887
+ render: (e) => dt(e)
1888
+ },
1889
+ {
1890
+ kind: "stats",
1891
+ is: (e) => Wt(e, "isIRangeStats"),
1892
+ render: (e) => At(e)
1893
+ },
1894
+ {
1895
+ kind: "counts",
1896
+ is: (e) => Wt(e, "isICellRangeCounts"),
1897
+ render: (e) => ut(e)
1898
+ },
1899
+ {
1900
+ kind: "style",
1901
+ is: (e) => Wt(e, "isIStyle"),
1902
+ render: (e) => Mt(e)
1903
+ },
1904
+ {
1905
+ kind: "regions",
1906
+ is: (e) => Wt(e, "isICellRegions"),
1907
+ render: (e, t) => $e(e, t)
1908
+ },
1909
+ {
1910
+ kind: "cellRange",
1911
+ is: (e) => Wt(e, "isICellRange"),
1912
+ render: (e, t) => ct(e, t)
1913
+ },
1914
+ {
1915
+ kind: "ranges",
1916
+ is: (e) => Wt(e, "isICellRanges"),
1917
+ render: (e, t) => Tt(e, t)
1918
+ },
1919
+ {
1920
+ kind: "range",
1921
+ is: (e) => Wt(e, "isIRange"),
1922
+ render: (e, t) => Dt(e, t)
1923
+ },
1924
+ {
1925
+ kind: "values",
1926
+ is: (e) => Array.isArray(e) && e.length > 0 && e.every((e) => Array.isArray(e)),
1927
+ render: (e, t) => Dt(e, t)
1928
+ },
1929
+ {
1930
+ kind: "records",
1931
+ is: (e) => Array.isArray(e) && e.length > 0 && e.every(Nt),
1932
+ render: (e, t) => Et(e, t)
1933
+ },
1934
+ {
1935
+ kind: "record",
1936
+ is: (e) => Nt(e),
1937
+ render: (e, t) => Et(e, t)
1938
+ },
1939
+ {
1940
+ kind: "items",
1941
+ is: (e) => Array.isArray(e) && e.length > 0 && e.every((e) => !!qt(e)),
1942
+ render: async (e, t) => {
1943
+ const n = e.length > 20 ? e.slice(0, 20) : e, r = [];
1944
+ for (const e of n) r.push(await qt(e).render(e, t));
1945
+ return n.length < e.length && r.push(`…and ${e.length - n.length} more · render one at a time to see them`), r.join("\n\n");
1946
+ }
1947
+ }
1948
+ ], zt = class extends Error {
1949
+ constructor(e) {
1950
+ super(e), this.name = "NoRendererError";
1951
+ }
1952
+ };
1953
+ function qt(e) {
1954
+ for (const t of Pt) if (t.is(e)) return t;
1955
+ return null;
1956
+ }
1957
+ async function Jt(e, t, n) {
1958
+ await e?.getCalculation().ready();
1959
+ let r = qt(t), o = t;
1960
+ if (!r && o && "object" == typeof o && !Array.isArray(o) && "function" == typeof o[Symbol.iterator]) {
1961
+ const e = [];
1962
+ for (const t of o) if (e.push(t), e.length >= 1e3) break;
1963
+ o = e, r = qt(o);
1964
+ }
1965
+ if (!r) throw new zt(`No markdown renderer for this value. Renderable kinds: ${Pt.map((e) => e.kind).join(", ")}.`);
1966
+ return r.render(o, n);
1967
+ }
1968
+ async function Kt(e, t, n) {
1969
+ if (void 0 === t) return {
1970
+ text: void 0,
1971
+ rendered: !0
1972
+ };
1973
+ if ("string" == typeof t) return {
1974
+ text: t,
1975
+ rendered: !0
1976
+ };
1977
+ if (null !== t && "object" == typeof t) try {
1978
+ return {
1979
+ text: await Jt(e, t, n),
1980
+ rendered: !0
1981
+ };
1982
+ } catch (e) {
1983
+ if (!(e instanceof zt)) throw e;
1984
+ }
1985
+ return function(e) {
1986
+ if (null === e) return {
1987
+ text: "null",
1988
+ rendered: !0
1989
+ };
1990
+ switch (typeof e) {
1991
+ case "number":
1992
+ case "boolean": return {
1993
+ text: $(e)?.display ?? String(e),
1994
+ rendered: !0
1995
+ };
1996
+ case "bigint":
1997
+ case "symbol": return {
1998
+ text: String(e),
1999
+ rendered: !0
2000
+ };
2001
+ case "function": return {
2002
+ text: "[Function]",
2003
+ rendered: !0
2004
+ };
2005
+ }
2006
+ const t = e;
2007
+ if (!0 === t.isFormulaError || !0 === t.isIRichData) return {
2008
+ text: $(e)?.display ?? "",
2009
+ rendered: !0
2010
+ };
2011
+ let n;
2012
+ try {
2013
+ n = String(e);
2014
+ } catch {
2015
+ n = "[object Object]";
2016
+ }
2017
+ return {
2018
+ text: n,
2019
+ rendered: !1
2020
+ };
2021
+ }(t);
2022
+ }
2023
+ var Gt = [T];
2024
+ export { h as CellEncoding, x as GREP_FIELDS, S as GREP_FIELDS_DEFAULT, y as GrepField, he as MarkdownBuilder, fe as MarkdownFrameSection, zt as NoRendererError, Pt as RENDERERS, et as RENDER_OPTION_KEYS, be as REPORTED_FEATURES, Gt as TOOLS, ze as appendDependencies, je as appendKinds, lt as appendMovables, Pe as appendNames, pe as appendRegionList, Ie as appendRegions, Ze as appendRules, Qe as appendSheetObjects, ye as appendTableDetails, re as countDates, O as describeAlignment, K as describeAllowedValues, M as describeBorder, L as describeBorderParts, I as describeColor, q as describeConditionalFormat, J as describeDataValidation, Ne as describeExtent, A as describeFill, B as describeFont, Ge as describeNode, Ke as describeNodeLabel, V as describeNumberFormat, Te as describeQualifiedExtent, Le as describeQualifiedName, Fe as describeQualifiedRanges, ve as describeRanges, U as describeRuleStyle, G as describeRules, P as describeScale, Re as describeSheetCall, Ee as describeSheetName, p as encodeCell, m as encodeFormattedNumber, f as encodeNumber, $ as encodeScalar, E as grep, T as grepTool, Nt as isPlainRecord, ke as parseFeatures, tt as parseRenderOptions, ne as profileKinds, Z as profileRegion, ue as regionPayload, de as regionPayloads, nt as renderCell, ct as renderCellRange, gt as renderConditionalFormat, ut as renderCounts, dt as renderDataValidation, wt as renderFormula, F as renderGrep, Jt as renderMarkdown, it as renderMovable, kt as renderNames, Tt as renderRanges, Et as renderRecords, $e as renderRegions, Kt as renderResult, jt as renderSheet, At as renderStats, Mt as renderStyle, xe as renderTable, Dt as renderValues, Bt as renderWorkbook, qt as resolveRenderer };