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

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 (32) hide show
  1. package/browser/cjs/index.cjs +44 -25
  2. package/browser/esm/index.mjs +3094 -1131
  3. package/node/esm/index.mjs +3331 -1334
  4. package/package.json +3 -3
  5. package/types/src/Tool.d.ts +38 -0
  6. package/types/src/api/apiTool.d.ts +22 -0
  7. package/types/src/api/index.d.ts +4 -0
  8. package/types/src/api/lookupApi.d.ts +127 -0
  9. package/types/src/api/renderApi.d.ts +13 -0
  10. package/types/src/grep/GrepTypes.d.ts +75 -17
  11. package/types/src/grep/grep.d.ts +4 -1
  12. package/types/src/index.d.ts +9 -0
  13. package/types/src/markdown/appendDependencies.d.ts +106 -0
  14. package/types/src/markdown/appendPivotTables.d.ts +22 -0
  15. package/types/src/markdown/appendSections.d.ts +37 -108
  16. package/types/src/markdown/describeChart.d.ts +72 -0
  17. package/types/src/markdown/describeHistogram.d.ts +186 -0
  18. package/types/src/markdown/describeRegionPayload.d.ts +1 -1
  19. package/types/src/markdown/findLabels.d.ts +26 -0
  20. package/types/src/markdown/index.d.ts +3 -0
  21. package/types/src/markdown/profileRegion.d.ts +56 -1
  22. package/types/src/markdown/registry.d.ts +11 -2
  23. package/types/src/markdown/renderCell.d.ts +13 -11
  24. package/types/src/markdown/renderCellRange.d.ts +3 -2
  25. package/types/src/markdown/renderModules.d.ts +55 -0
  26. package/types/src/markdown/renderMovable.d.ts +69 -13
  27. package/types/src/markdown/renderNames.d.ts +2 -2
  28. package/types/src/markdown/renderProtection.d.ts +81 -0
  29. package/types/src/markdown/renderRegions.d.ts +1 -0
  30. package/types/src/markdown/renderSheet.d.ts +6 -7
  31. package/types/src/markdown/renderTable.d.ts +11 -3
  32. package/types/src/markdown/renderWorkbook.d.ts +33 -26
@@ -1,16 +1,16 @@
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.4
2
+ * @license @sheetxl/query - SheetXL - Workbook read surface and renderers (grep, reports) — capabilities declared once, adapted by any host surface - v0.8.0-beta.2
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.
6
6
  */
7
- import { AddressUtils as e, FormulaError as t, IAnchored as n, ICellRange as r, ICondition as i, IConditionalFormat as a, IDataValidation as o, IFill as s, IFont as c, ISheet as l, InteropScalarType as u, NumberFormat as d, ScalarType as f } from "@sheetxl/sdk";
8
- var p;
9
- (p ||= {}).Mode = {
7
+ import { AddressUtils as e, FormulaError as t, IAnchored as n, ICalculation as r, ICellRange as i, ICondition as a, IConditionalFormat as o, IDataValidation as s, IFill as c, IFont as l, IRange as u, ISheet as d, InteropScalarType as f, NumberFormat as p, ScalarType as m, getScriptingApi as h, getScriptingDeclarations as g } from "@sheetxl/sdk";
8
+ var _;
9
+ (_ ||= {}).Mode = {
10
10
  Display: "display",
11
11
  Value: "value"
12
12
  };
13
- function m(e) {
13
+ function v(e) {
14
14
  return Number.isFinite(e) ? function(e) {
15
15
  let t = e.indexOf("e");
16
16
  if (t === -1) return e;
@@ -18,18 +18,18 @@ function m(e) {
18
18
  return `${e.substring(0, t)}E${e[t + 1]}${n.length < 2 ? "0" + n : n}`;
19
19
  }(String(Number(e.toPrecision(15)))) : String(e);
20
20
  }
21
- function h(e, t) {
21
+ function y(e, t) {
22
22
  if (!Number.isFinite(e)) return String(e);
23
- if (!t || t === "General") return m(e);
23
+ if (!t || t === "General") return v(e);
24
24
  try {
25
- let n = d.getEngine().format(t, e)?.text;
26
- return n ? n.trim() : m(e);
25
+ let n = p.getEngine().format(t, e)?.text;
26
+ return n ? n.trim() : v(e);
27
27
  } catch {
28
- return m(e);
28
+ return v(e);
29
29
  }
30
30
  }
31
- function g(e, t) {
32
- let n = t === p.Mode.Value, r = e.getText({
31
+ function b(e, t) {
32
+ let n = t === _.Mode.Value, r = e.getText({
33
33
  hideStringPrefix: !0,
34
34
  useFormattingCategory: n
35
35
  });
@@ -38,7 +38,7 @@ function g(e, t) {
38
38
  display: e.getText({ useFormattingCategory: n })
39
39
  } : null;
40
40
  }
41
- function _(e) {
41
+ function x(e) {
42
42
  if (e == null) return null;
43
43
  if (typeof e == "string") return {
44
44
  match: e,
@@ -52,7 +52,7 @@ function _(e) {
52
52
  };
53
53
  }
54
54
  if (typeof e == "number") {
55
- let t = m(e);
55
+ let t = v(e);
56
56
  return {
57
57
  match: t,
58
58
  display: t
@@ -71,310 +71,37 @@ function _(e) {
71
71
  display: n
72
72
  };
73
73
  }
74
- var v = {
74
+ var S = {
75
75
  Display: "display",
76
76
  Value: "value",
77
77
  Raw: "raw",
78
78
  Formula: "formula",
79
79
  Hyperlink: "hyperlink",
80
- NumberFormat: "numberFormat"
81
- }, y = [
80
+ NumberFormat: "numberFormat",
81
+ Comment: "comment",
82
+ Shape: "shape",
83
+ Chart: "chart",
84
+ Name: "name"
85
+ }, C = [
82
86
  "display",
83
87
  "value",
84
88
  "raw",
85
89
  "formula",
86
90
  "hyperlink",
87
- "numberFormat"
88
- ], b = [
91
+ "numberFormat",
92
+ "comment",
93
+ "shape",
94
+ "chart",
95
+ "name"
96
+ ], w = [
89
97
  "display",
90
98
  "value",
91
- "formula"
92
- ], x = (e) => e.getVisibility() === "visible", ee = (e, t, n) => {
93
- let r = e.getSheets().getItems({ visibility: "veryHidden" }), i = t?.trim();
94
- if (!i) return r.filter((e) => n || x(e)).map((e) => ({
95
- sheet: e,
96
- address: null
97
- }));
98
- let a = /^'(.*)'!(.+)$/.exec(i) ?? /^([^!]+)!(.+)$/.exec(i);
99
- if (a) {
100
- let [, e, t] = a, n = r.find((t) => t.getName() === e);
101
- if (!n) throw Error(`Sheet not found: ${e}`);
102
- return [{
103
- sheet: n,
104
- address: t
105
- }];
106
- }
107
- let o = r.find((e) => e.getName() === i);
108
- if (o) return [{
109
- sheet: o,
110
- address: null
111
- }];
112
- if (/[*?]/.test(i)) {
113
- let e = ((e) => {
114
- let t = e.replace(/[.*+?^${}()|[\]\\]/g, (e) => e === "*" ? ".*" : e === "?" ? "." : `\\${e}`);
115
- return RegExp(`^${t}$`);
116
- })(i), t = r.filter((t) => e.test(t.getName()) && (n || x(t)));
117
- if (t.length === 0) throw Error(`No sheets match ${JSON.stringify(i)}. Sheets: ${r.map((e) => e.getName()).join(", ")}`);
118
- return t.map((e) => ({
119
- sheet: e,
120
- address: null
121
- }));
122
- }
123
- let s = r.filter((e) => n || x(e));
124
- try {
125
- s[0]?.getRange(i);
126
- } catch {
127
- throw Error(`Unknown scope ${JSON.stringify(i)}: not a sheet name or a range. Sheets: ${r.map((e) => e.getName()).join(", ")}`);
128
- }
129
- return s.map((e) => ({
130
- sheet: e,
131
- address: i
132
- }));
133
- }, te = (e, t) => {
134
- switch (t) {
135
- case "display": return g(e, p.Mode.Display);
136
- case "value": return g(e, p.Mode.Value);
137
- case "raw": return _(e.getValue());
138
- case "formula": {
139
- let t = e.getFormulaText();
140
- return t ? {
141
- match: `=${t}`,
142
- display: `=${t}`
143
- } : null;
144
- }
145
- case "hyperlink": {
146
- let t = e.getHyperlink()?.getAddress() ?? null;
147
- return t ? {
148
- match: t,
149
- display: t
150
- } : null;
151
- }
152
- case "numberFormat": {
153
- let t = e.getStyle().getNumberFormat();
154
- return t && t !== "General" ? {
155
- match: t,
156
- display: t
157
- } : null;
158
- }
159
- default: return null;
160
- }
161
- }, ne = ["hyperlink", "numberFormat"], S = (e, t, n) => {
162
- let r = null, i = (e) => ({
163
- range: `${t}!${e.getRange().toString()}`,
164
- table: e.getName()
165
- });
166
- return { resolve(a, o) {
167
- let s = ((e) => e.getTable())(a);
168
- if (e === "table") return s ? i(s) : void 0;
169
- if (r === null) {
170
- r = [];
171
- for (let e of n.getRegions()) {
172
- let n = e.getCoords();
173
- n.rowStart === n.rowEnd && n.colStart === n.colEnd || r.push({
174
- coords: n,
175
- address: `${t}!${e.toString()}`
176
- });
177
- }
178
- }
179
- let c = r.find(({ coords: e }) => o.rowIndex >= e.rowStart && o.rowIndex <= e.rowEnd && o.colIndex >= e.colStart && o.colIndex <= e.colEnd);
180
- return c ? {
181
- range: c.address,
182
- ...s ? { table: s.getName() } : {}
183
- } : s ? i(s) : void 0;
184
- } };
185
- };
186
- async function C(e, t) {
187
- if (!t.pattern) throw Error("grep requires a pattern");
188
- let n = t.fields?.length ? t.fields : b, r = t.output ?? "content", i = t.maxCount ?? 200, a = !0 === t.invert, o = !0 === t.hidden, s = ((e) => {
189
- if (e === void 0 || !1 === e) return null;
190
- if (!0 === e) return "contentful";
191
- if (e === "contentful" || e === "table") return e;
192
- 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.`);
193
- })(t.context), c = ((e) => {
194
- let t = e.fixedStrings ? ((e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))(e.pattern) : e.pattern;
195
- e.word && (t = `(?<!\\w)(?:${t})(?!\\w)`);
196
- let n = e.ignoreCase ? "iu" : "u";
197
- try {
198
- return new RegExp(t, n);
199
- } catch {
200
- try {
201
- return new RegExp(t, n.replace("u", ""));
202
- } catch (t) {
203
- throw Error(`Invalid regex ${JSON.stringify(e.pattern)}: ${t instanceof Error ? t.message : String(t)}. Use fixedStrings (-F) to search for the literal text.`);
204
- }
205
- }
206
- })(t), l = ee(e, t.scope, o), u = !n.some((e) => ne.includes(e)), d = n.includes("display") && n.includes("value"), f = r === "content" || r === "addresses", p = [], m = [], h = 0, g = 0, _ = !1;
207
- for (let { sheet: e, address: t } of l) {
208
- if (_) continue;
209
- let l = e.getName();
210
- g++, await e.getCalculation().ready();
211
- let v = t === null ? e.getUsedRange() : e.getRange(t);
212
- if (!v) continue;
213
- let y = s && r === "content" ? S(s, l, v) : null, b = 0;
214
- v.forEach((e, t) => {
215
- if (u && e == null) return;
216
- let o = t.getCell(), s = [], m, g = null;
217
- for (let e of n) {
218
- let t = te(o, e);
219
- if (e === "display" && (m = t?.match ?? null), t !== null && (e !== "value" || !d || (m === void 0 && (m = te(o, "display")?.match ?? null), t.match !== m)) && (g === null && (g = {
220
- field: e,
221
- text: t.display
222
- }), c.test(t.match) && (s.push({
223
- field: e,
224
- text: t.display
225
- }), r === "addresses" && !a))) break;
226
- }
227
- if (!(a ? s.length > 0 || g === null : s.length === 0)) {
228
- if (i > 0 && h >= i) return _ = !0, { break: !0 };
229
- if (h++, b++, f) {
230
- let e = a ? [g] : r === "addresses" ? s.slice(0, 1) : s, n = y?.resolve(o, t.getCoords()), i = t.getAddress();
231
- for (let t of e) p.push({
232
- sheet: l,
233
- address: i,
234
- field: t.field,
235
- text: t.text,
236
- ...n ? { context: n } : {}
237
- });
238
- }
239
- }
240
- }, o ? void 0 : { ignoreHidden: !0 }), b > 0 && m.push({
241
- sheet: l,
242
- cells: b
243
- });
244
- }
245
- return {
246
- pattern: t.pattern,
247
- fields: n,
248
- scope: t.scope?.trim() || "workbook",
249
- matches: p,
250
- cellCount: h,
251
- sheets: m,
252
- sheetsSearched: g,
253
- sheetsMatched: m.length,
254
- truncated: _,
255
- output: r
256
- };
257
- }
258
- var re = (e) => {
259
- let t = e.replace(/\s+/g, " ").trim();
260
- return t.length > 120 ? `${t.slice(0, 119)}…` : t;
261
- }, ie = (e, t, n, r) => {
262
- 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));
263
- for (let r = 0; r < t.length; r++) {
264
- let s = t[r];
265
- e.push(`${n}${i[r].padEnd(a)} ${s.field.padEnd(o)} ${re(s.text)}`);
266
- }
267
- };
268
- function w(e) {
269
- 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"}`];
270
- if (e.output === "count") for (let t of e.sheets) c.push(` ${t.sheet}: ${t.cells}`);
271
- else if (e.output === "sheets") {
272
- for (let t of e.sheets) c.push(` ${t.sheet}`);
273
- e.sheets.length === 0 && c.push(" no matches");
274
- } else if (i.length === 0) c.push(" no matches");
275
- else if (e.output === "addresses") for (let e of i) c.push(` ${e.sheet}!${e.address}`);
276
- else {
277
- let e = [], t = /* @__PURE__ */ new Map();
278
- for (let n of i) {
279
- let r = n.context?.range ?? "", i = t.get(r);
280
- i || (i = {
281
- key: r,
282
- heading: n.context ? n.context.table ? `${n.context.range} · ${n.context.table}` : n.context.range : null,
283
- rows: []
284
- }, t.set(r, i), e.push(i)), i.rows.push(n);
285
- }
286
- for (let t of e) t.heading ? (c.push(` ${t.heading}`), ie(c, t.rows, " ", !1)) : ie(c, t.rows, " ", !0);
287
- }
288
- 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("\n");
289
- }
290
- var T = {
291
- name: "grep",
292
- 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.",
293
- params: [
294
- {
295
- name: "pattern",
296
- type: "string",
297
- description: "The regular expression to search for (literal with fixedStrings).",
298
- required: !0,
299
- positional: 0
300
- },
301
- {
302
- name: "fields",
303
- type: "enum[]",
304
- values: y,
305
- defaultValue: b,
306
- 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%\")."
307
- },
308
- {
309
- name: "fixedStrings",
310
- type: "boolean",
311
- alias: "F",
312
- defaultValue: !1,
313
- description: "Treat the pattern as a literal string, not a regular expression."
314
- },
315
- {
316
- name: "ignoreCase",
317
- type: "boolean",
318
- alias: "i",
319
- defaultValue: !1,
320
- description: "Case-insensitive matching."
321
- },
322
- {
323
- name: "word",
324
- type: "boolean",
325
- alias: "w",
326
- defaultValue: !1,
327
- description: "Require the match to fall on word boundaries (text edges count as edges)."
328
- },
329
- {
330
- name: "invert",
331
- type: "boolean",
332
- alias: "v",
333
- defaultValue: !1,
334
- description: "Report cells where no requested field matched. Only cells with text in a requested field are considered — blanks are not findings."
335
- },
336
- {
337
- name: "scope",
338
- type: "string",
339
- 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."
340
- },
341
- {
342
- name: "hidden",
343
- type: "boolean",
344
- defaultValue: !1,
345
- description: "Search hidden rows, columns and sheets, which are excluded by default. Naming a hidden sheet in scope always searches it."
346
- },
347
- {
348
- name: "context",
349
- type: "enum",
350
- values: ["contentful", "table"],
351
- alias: "C",
352
- valueOptional: !0,
353
- 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."
354
- },
355
- {
356
- name: "maxCount",
357
- type: "number",
358
- alias: "m",
359
- defaultValue: 200,
360
- description: "Stop after this many matching cells (0 = unlimited). Truncation is always reported, and only when a further match actually exists."
361
- },
362
- {
363
- name: "output",
364
- type: "enum",
365
- values: [
366
- "content",
367
- "addresses",
368
- "count",
369
- "sheets"
370
- ],
371
- defaultValue: "content",
372
- description: "What to return: content (address, layer and text), addresses (one per matched cell), count (per sheet), or sheets (names with a match)."
373
- }
374
- ],
375
- run: C,
376
- render: w
377
- }, E = (e, t) => e <= t + 3 ? e : t, D = (e) => {
99
+ "formula",
100
+ "comment",
101
+ "shape",
102
+ "chart",
103
+ "name"
104
+ ], T = (e, t) => e <= t + 3 ? e : t, E = (e) => {
378
105
  if (!e) return null;
379
106
  let t = String(e.toHex?.() ?? "");
380
107
  if (!t) return e.toString();
@@ -382,33 +109,33 @@ var T = {
382
109
  if (!r) return n;
383
110
  let i = r.toLowerCase().replace(/^#/, "");
384
111
  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))))})`;
385
- }, ae = (e) => {
112
+ }, D = (e) => {
386
113
  let t = e.getFill(), n = t.getType();
387
- if (n === s.Type.None) return null;
388
- if (n === s.Type.Pattern) {
114
+ if (n === c.Type.None) return null;
115
+ if (n === c.Type.Pattern) {
389
116
  let e = t, n = e.getPatternType();
390
- if (n === s.BuiltInSheetPattern.None) return null;
391
- let r = D(e.getForeground());
392
- if (n === s.BuiltInSheetPattern.Solid) return r ? `solid ${r}` : "solid";
393
- let i = D(e.getBackground());
117
+ if (n === c.BuiltInSheetPattern.None) return null;
118
+ let r = E(e.getForeground());
119
+ if (n === c.BuiltInSheetPattern.Solid) return r ? `solid ${r}` : "solid";
120
+ let i = E(e.getBackground());
394
121
  return [
395
122
  `${n} pattern`,
396
123
  r,
397
124
  i ? `on ${i}` : null
398
125
  ].filter(Boolean).join(" ");
399
126
  }
400
- let r = D(t.getColor?.());
127
+ let r = E(t.getColor?.());
401
128
  return r ? `${n} ${r}` : n;
402
- }, oe = (e) => {
403
- let t = ce(e);
129
+ }, O = (e) => {
130
+ let t = te(e);
404
131
  return t.length > 0 ? t.join(" · ") : null;
405
- }, se = /* @__PURE__ */ new Set([
132
+ }, ee = /* @__PURE__ */ new Set([
406
133
  "top",
407
134
  "left",
408
135
  "bottom",
409
136
  "right"
410
- ]), ce = (e) => {
411
- let t = e.getBorder(), n = [
137
+ ]), te = (e) => {
138
+ let t = e.getBorders(), n = [
412
139
  ["top", t.getTop()],
413
140
  ["left", t.getLeft()],
414
141
  ["bottom", t.getBottom()],
@@ -421,285 +148,829 @@ var T = {
421
148
  for (let [e, t] of n) {
422
149
  let n = t?.getStyle?.();
423
150
  if (!n || n === "none") continue;
424
- let i = D(t?.getColor?.()), a = i ? `${n} ${i}` : n, o = r.get(a);
151
+ let i = E(t?.getColor?.()), a = i ? `${n} ${i}` : n, o = r.get(a);
425
152
  o ? o.push(e) : r.set(a, [e]);
426
153
  }
427
154
  let i = [];
428
155
  for (let [e, t] of r) {
429
- let n = t.length === 4 && t.every((e) => se.has(e));
156
+ let n = t.length === 4 && t.every((e) => ee.has(e));
430
157
  i.push(`${n ? "outline" : t.join("+")} ${e}`);
431
158
  }
432
159
  return i;
433
- }, le = (e) => {
160
+ }, k = (e) => {
434
161
  let t = e.getNumberFormat();
435
162
  return t && t !== "General" ? t : null;
436
- }, ue = (e, t) => {
163
+ }, A = (e, t) => {
437
164
  let n = e.getAlignment(), r = t.getAlignment(), i = [];
438
165
  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;
439
- }, de = (e, t) => {
166
+ }, j = (e, t) => {
440
167
  let n = e.getFont(), r = t.getFont(), i = [];
441
168
  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());
442
- let a = D(n.getColor());
443
- return a !== D(r.getColor()) && i.push(a ?? "no color"), i.length > 0 ? i.join(" · ") : null;
444
- }, fe = (e, t) => e.length > t ? `${e.slice(0, t - 1)}…` : e, O = (e) => {
445
- if (!e) return null;
446
- if (typeof e != "string") return D(e);
447
- let t = e.replace(/^#/, "");
448
- 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;
449
- }, pe = (e) => {
450
- if (!e) return null;
451
- let t = [], n = ((e) => {
452
- if (!e) return null;
453
- if (typeof e == "string") return O(e);
454
- let t = e.type;
455
- if (t === s.Type.None) return null;
456
- if (t === s.Type.Gradient) return "gradient";
457
- let n = e, r = O(n.foreground ?? e.color ?? n.background), i = n.patternType;
458
- return [i && i !== s.BuiltInSheetPattern.Solid ? `${i} pattern` : null, r].filter(Boolean).join(" ") || null;
459
- })(e.fill);
460
- n && t.push(`fill ${n}`);
461
- let r = e.font;
462
- if (r) {
463
- let e = [];
464
- (r.weight === void 0 ? !0 === r.bold : r.weight >= 600) && e.push("bold"), (r.style === void 0 ? !0 === r.italic : r.style === c.Style.Italic) && e.push("italic"), r.strike && e.push("strike"), r.underline && r.underline !== c.UnderlineStyle.None && e.push(`underline ${r.underline}`);
465
- let n = r.color === "auto" ? null : O(r.color);
466
- n && e.push(`text ${n}`), e.length > 0 && t.push(e.join(" "));
467
- }
468
- if (e.numberFormat !== void 0 && e.numberFormat !== null) {
469
- let n = typeof e.numberFormat == "number" ? `numFmt ${e.numberFormat}` : String(e.numberFormat);
470
- n && t.push(n);
471
- }
472
- return e.border && t.push("border"), e.alignment && t.push("alignment"), t.length > 0 ? t.join(" · ") : null;
473
- }, me = (e) => {
474
- let t = e.type ?? a.ColorStopType.Num, n = e.value, r = n == null || n === "" ? t : `${t} ${n}`, i = O(e.color);
475
- return i ? `${r} ${i}` : r;
476
- }, he = (e) => {
477
- let t = e.type;
478
- if (e.type === a.ScaleType.DataBar) {
479
- let n = O(e.color);
480
- n && (t += ` ${n}`);
481
- } else e.type === a.ScaleType.IconSet && (e.iconSet && (t += ` ${e.iconSet}`), e.reverse && (t += " reversed"), e.icon?.length && (t += " custom icons"));
482
- let n = (e.stops ?? []).map(me).join(" → ");
483
- return n ? `${t} · ${n}` : t;
484
- }, ge = "(no rule)", k = (e) => {
485
- let t = e.getScale(), n = [];
486
- if (t) n.push(he(t));
487
- else {
488
- n.push(e.getCondition()?.toString() || ge);
489
- let t = pe(e.getStyle());
490
- t && n.push(`→ ${t}`);
169
+ let a = E(n.getColor());
170
+ return a !== E(r.getColor()) && i.push(a ?? "no color"), i.length > 0 ? i.join(" · ") : null;
171
+ }, ne = i.Feature;
172
+ function M(e, t, n) {
173
+ let { rowIndex: r, colIndex: i } = t, a = n === "row", o = a ? i : r;
174
+ if (o === 0) return null;
175
+ let s = e.getRange({
176
+ rowStart: r,
177
+ rowEnd: r,
178
+ colStart: i,
179
+ colEnd: i
180
+ }).getSurrounding({ contentOnly: !0 }).getCoords(), c = a ? s.colStart : s.rowStart;
181
+ if (c < o) {
182
+ let t = ie(e, a ? r : c, a ? c : i);
183
+ if (t) return t;
184
+ }
185
+ let l = a ? e.getRange({
186
+ rowStart: r,
187
+ rowEnd: r,
188
+ colStart: 0,
189
+ colEnd: i - 1
190
+ }) : e.getRange({
191
+ rowStart: 0,
192
+ rowEnd: r - 1,
193
+ colStart: i,
194
+ colEnd: i
195
+ });
196
+ for (let t of l.entries({
197
+ features: [ne.Contentful],
198
+ axis: a ? u.Axis.Column : u.Axis.Row,
199
+ reverse: !0
200
+ })) {
201
+ if (t.context.getType() !== m.String) continue;
202
+ let n = t.context.getCoords();
203
+ return ie(e, n.rowIndex, n.colIndex);
491
204
  }
492
- return e.isStopIfTrue() && n.push("· stop if true"), fe(n.join(" "), 90);
493
- }, _e = (e) => {
494
- let t = [e.getCondition()?.toString() || ge], n = e.getAlertStyle();
495
- return n && t.push(n), e.isIncludeBlanks() && t.push("blanks allowed"), e.isHideDropdown() && t.push("no dropdown"), fe(t.join(" · "), 90);
496
- }, ve = (e) => {
497
- if (e?.getOperator()?.getName() !== i.BuiltInOperatorNames.InSet) return null;
498
- let t = e.getParam()?.items;
499
- if (!t) return null;
500
- if (typeof t == "string") return t;
501
- let n = t.slice(0, 20).map((e) => _(e)?.match ?? ""), r = t.length - n.length;
502
- return r > 0 ? `${n.join(", ")}, +${r} more` : n.join(", ");
503
- }, A = (e, t) => {
504
- if (e.length === 0) return null;
505
- let n = e.slice(0, 3).map(t), r = e.length - n.length;
506
- return r > 0 ? `${n.join(" | ")} | +${r} more` : n.join(" | ");
507
- }, j = r.Feature;
508
- function M(e, t) {
205
+ return null;
206
+ }
207
+ var re = (e) => e ? `${JSON.stringify(e.text)} (${e.address})` : null;
208
+ function ie(e, t, n) {
209
+ let r = e.getRange({
210
+ rowStart: t,
211
+ rowEnd: t,
212
+ colStart: n,
213
+ colEnd: n
214
+ }).getCell();
215
+ if (r.getType() !== m.String) return null;
216
+ let i = b(r, _.Mode.Display)?.match;
217
+ return i ? {
218
+ text: i,
219
+ address: r.getAddress()
220
+ } : null;
221
+ }
222
+ function N(e) {
223
+ let t = e, n = "";
224
+ do
225
+ n = String.fromCharCode(65 + t % 26) + n, t = Math.floor(t / 26) - 1;
226
+ while (t >= 0);
227
+ return n;
228
+ }
229
+ var P = i.Feature;
230
+ function ae(e, t) {
509
231
  let n = t?.maxSeries ?? 24, r = t?.maxProfileCells ?? 2e4, i = t?.maxCategories ?? 3, a = e.getRowCount(), o = e.getColumnCount();
510
232
  if (a === 1 && o === 1) return {
511
233
  shape: "cell",
512
- summary: `cell · ${g(e.getCell(), p.Mode.Display)?.display ?? "(blank)"}`,
234
+ summary: b(e.getCell(), _.Mode.Display)?.display ?? "(blank)",
513
235
  series: []
514
236
  };
515
237
  let s = e.getRange(), c = s.getCoords(), l = a >= o;
516
238
  if (a === 1 || o === 1) return {
517
239
  shape: "list",
518
- summary: `list · ${xe(s, i)}`,
240
+ summary: ge(s, i),
519
241
  series: []
520
242
  };
521
- let u = function(e, t) {
522
- let n = e.getRange(), r = n.getCoords(), i = e.getCell().getTable();
523
- if (i) {
524
- let e = i.getColumns().map((e) => e.getName());
525
- return {
526
- present: !0,
527
- inside: !0,
528
- note: `table "${i.getName()}"`,
529
- names: t ? e : null
530
- };
531
- }
532
- 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);
533
- if (N(s) && !o) return {
534
- present: !0,
535
- inside: !0,
536
- note: "header " + (t ? `row ${r.rowStart + 1}` : `column ${we(r.colStart)}`),
537
- names: ye(s, e, t)
538
- };
539
- let c = (t ? r.rowStart : r.colStart) - 1;
540
- if (c >= 0 && !N(n)) {
541
- let i = t ? n.getRangeAt(c, r.colStart, c, r.colEnd) : n.getRangeAt(r.rowStart, c, r.rowEnd, c);
542
- if (N(i)) return {
543
- present: !0,
544
- inside: !1,
545
- note: `header ${t ? `row ${c + 1}` : `column ${we(c)}`} (above this block)`,
546
- names: ye(i, e, t)
547
- };
548
- }
243
+ let u = oe(e, l), d = l ? o : a, f = l ? null : "by row", p = u.present && u.inside, m = l && p ? c.rowStart + 1 : c.rowStart, h = !l && p ? c.colStart + 1 : c.colStart, g = le(s, l, l ? m : h, r), v = l && g ? g.start - 1 : c.rowEnd, y = !l && g ? g.start - 1 : c.colEnd, x = v - m + 1, S = y - h + 1, C = x * S > r, w = C && l ? Math.max(1, Math.floor(r / Math.max(1, S))) : x, T = C && !l ? Math.max(1, Math.floor(r / Math.max(1, x))) : S, E = Math.min(v, m + w - 1), D = Math.min(y, h + T - 1), O = Math.min(d, n), ee = [], te = [];
244
+ for (let t = 0; t < O; t++) {
245
+ let n = l ? s.getRangeAt(m, c.colStart + t, E, c.colStart + t) : s.getRangeAt(c.rowStart + t, h, c.rowStart + t, D);
246
+ ee.push(he(e, l, t, u.names)), te.push(ge(n, i));
247
+ }
248
+ let k = ee.length ? Math.max(...ee.map((e) => e.length)) : 0, A = ee.map((e, t) => `${e.padEnd(k)} ${te[t]}`);
249
+ d > O && A.push(`…${d - O} more ${l ? "columns" : "rows"} not profiled · read them with getStats()`);
250
+ let j = [
251
+ f,
252
+ u.note,
253
+ g?.note
254
+ ];
255
+ return C && j.push(`profiled from the first ${l ? `${w} rows` : `${T} columns`} of ${l ? x : S}`), {
256
+ shape: u.present ? "table" : "block",
257
+ summary: j.filter(Boolean).join(" · "),
258
+ series: A
259
+ };
260
+ }
261
+ function oe(e, t) {
262
+ let n = e.getRange(), r = n.getCoords(), i = e.getCell().getTable();
263
+ if (i) {
264
+ let e = i.getColumns().map((e) => e.getName()), n = i.getRange().getCoords();
549
265
  return {
550
- present: !1,
266
+ present: !0,
267
+ inside: !0,
268
+ note: `${n.rowStart === r.rowStart && n.rowEnd === r.rowEnd && n.colStart === r.colStart && n.colEnd === r.colEnd ? "" : "part of "}table ${i.getName()}`,
269
+ names: t ? e : null
270
+ };
271
+ }
272
+ let a = t ? r.rowStart + 1 : r.colStart + 1, o = pe(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);
273
+ if (pe(s) && !o) return {
274
+ present: !0,
275
+ inside: !0,
276
+ note: "header " + (t ? `row ${r.rowStart + 1}` : `column ${N(r.colStart)}`),
277
+ names: me(s, e, t)
278
+ };
279
+ let c = (t ? r.rowStart : r.colStart) - 1;
280
+ if (c >= 0 && !pe(n)) {
281
+ let i = t ? n.getRangeAt(c, r.colStart, c, r.colEnd) : n.getRangeAt(r.rowStart, c, r.rowEnd, c);
282
+ if (pe(i)) return {
283
+ present: !0,
551
284
  inside: !1,
552
- note: "no header detected",
553
- names: null
285
+ note: `header ${t ? `row ${c + 1}` : `column ${N(c)}`} (above this block)`,
286
+ names: me(i, e, t)
554
287
  };
555
- }(e, l), d = l ? o : a, f = l ? "" : " · by row", m = u.present && u.inside, h = l && m ? c.rowStart + 1 : c.rowStart, _ = !l && m ? c.colStart + 1 : c.colStart, v = c.rowEnd - h + 1, y = c.colEnd - _ + 1, b = v * y > r, x = b && l ? Math.max(1, Math.floor(r / Math.max(1, y))) : v, ee = b && !l ? Math.max(1, Math.floor(r / Math.max(1, v))) : y, te = Math.min(c.rowEnd, h + x - 1), ne = Math.min(c.colEnd, _ + ee - 1), S = Math.min(d, n), C = [], re = [];
556
- for (let t = 0; t < S; t++) {
557
- let n = l ? s.getRangeAt(h, c.colStart + t, te, c.colStart + t) : s.getRangeAt(c.rowStart + t, _, c.rowStart + t, ne);
558
- C.push(be(e, l, t, u.names)), re.push(xe(n, i));
559
- }
560
- let ie = C.length ? Math.max(...C.map((e) => e.length)) : 0, w = C.map((e, t) => `${e.padEnd(ie)} ${re[t]}`);
561
- d > S && w.push(`…${d - S} more ${l ? "columns" : "rows"} not profiled · read them with getStats()`);
562
- let T = [u.present ? `table${f}` : `block${f}`, u.note];
563
- return b && T.push(`profiled from the first ${l ? `${x} rows` : `${ee} columns`} of ${l ? v : y}`), {
564
- shape: u.present ? "table" : "block",
565
- summary: T.filter(Boolean).join(" · "),
566
- series: w
288
+ }
289
+ return {
290
+ present: !1,
291
+ inside: !1,
292
+ note: "no header detected",
293
+ names: null
567
294
  };
568
295
  }
569
- function N(e) {
296
+ var se = 3;
297
+ function ce(e, t = 2e4) {
298
+ let n = e.getRowCount(), r = e.getColumnCount();
299
+ if (n < 2 || r < 2) return null;
300
+ let i = n >= r, a = e.getCoords(), o = oe({
301
+ getRowCount: () => n,
302
+ getColumnCount: () => r,
303
+ getCell: () => e.getCell(),
304
+ getRange: () => e
305
+ }, i), s = o.present && o.inside;
306
+ return le(e, i, (i ? a.rowStart : a.colStart) + +!!s, t);
307
+ }
308
+ function le(e, t, n, r) {
309
+ let i = e.getCoords(), a = t ? i.rowEnd : i.colEnd, o = t ? i.colStart : i.rowStart, s = t ? i.colEnd : i.rowEnd, c, l = -1, u = e.getCell().getTable(), d = t && !!u?.isShowTotals() && u.getRange().getCoords().rowEnd === i.rowEnd;
310
+ if (d) l = a;
311
+ else {
312
+ if (e.getRowCount() * e.getColumnCount() > r) return null;
313
+ let u = e.getValues(), d = (e, n) => t ? u[e - i.rowStart][n - i.colStart] : u[n - i.rowStart][e - i.colStart], f = s - o + 1, p = Array(f).fill(0), m = Array(f).fill(!1);
314
+ for (let r = n; r <= a; r++) {
315
+ if (r - n >= 2) {
316
+ let n = ue(f, (e) => d(r, o + e), p, m, (e) => t ? `${N(o + e)}${r + 1}` : `${N(r)}${o + e + 1}`);
317
+ if (n.matches >= 2 && 2 * n.matches > n.candidates) {
318
+ let i = t ? e.getRangeAt(r, o, r, s) : e.getRangeAt(o, r, s, r);
319
+ l = r, c = {
320
+ ...n,
321
+ byColumn: t,
322
+ typed: (i.getCounts([P.Formula])[P.Formula] ?? 0) === 0
323
+ };
324
+ break;
325
+ }
326
+ }
327
+ for (let e = 0; e < f; e++) {
328
+ let t = d(r, o + e);
329
+ typeof t == "number" && (p[e] += t, m[e] = !0);
330
+ }
331
+ }
332
+ if (l < 0) return null;
333
+ }
334
+ let f = e.getSheet(), p = [];
335
+ for (let n = l; n <= a; n++) {
336
+ let r = t ? {
337
+ rowIndex: n,
338
+ colIndex: i.colStart
339
+ } : {
340
+ rowIndex: i.rowStart,
341
+ colIndex: n
342
+ }, a = fe(e, r) ?? M(f, r, t ? "row" : "column");
343
+ p.push({
344
+ index: n,
345
+ label: a,
346
+ ...n === l && c ? { sums: c } : {}
347
+ });
348
+ }
349
+ let m = (e) => t ? String(e + 1) : N(e), h = l === a ? `${t ? "row" : "column"} ${m(l)}` : `${t ? "rows" : "columns"} ${m(l)}:${m(a)}`, g = p.slice(0, se).map((e) => [
350
+ m(e.index),
351
+ e.label ? JSON.stringify(e.label.text) : null,
352
+ e.sums ? de(e.sums) : e.index === l && d ? "table totals" : null
353
+ ].filter(Boolean).join(" ")), _ = p.length - g.length;
354
+ return {
355
+ byColumn: t,
356
+ start: l,
357
+ lines: p,
358
+ note: `${h} not profiled: ${g.join(" · ")}${_ > 0 ? ` · +${_} more` : ""}`
359
+ };
360
+ }
361
+ function ue(e, t, n, r, i) {
362
+ let a = 0, o = 0, s = [];
363
+ for (let c = 0; c < e; c++) {
364
+ if (!r[c]) continue;
365
+ o++;
366
+ let e = t(c), l = n[c];
367
+ typeof e == "number" && Math.abs(e - l) <= 1e-9 * Math.max(1, Math.abs(l)) ? a++ : typeof e == "number" ? s.push(`${i(c)} ${v(e)} ≠ Σ ${v(l)}`) : s.push(`${i(c)} ${e == null ? "blank" : typeof e == "string" ? "text" : String(e)}`);
368
+ }
369
+ return {
370
+ matches: a,
371
+ candidates: o,
372
+ misses: s
373
+ };
374
+ }
375
+ function de(e) {
376
+ let t = e.misses.slice(0, 3), n = e.misses.length - t.length, r = t.length > 0 ? `; ${t.join(", ")}${n > 0 ? `, +${n} more` : ""}` : "";
377
+ return `${e.typed ? "typed, " : ""}= Σ ${e.byColumn ? "above" : "to the left"} (${e.matches} of ${e.candidates}${r})`;
378
+ }
379
+ function fe(e, t) {
380
+ let n = e.getRangeAt(t.rowIndex, t.colIndex).getCell();
381
+ if (n.getType() !== m.String) return null;
382
+ let r = b(n, _.Mode.Display)?.match;
383
+ return r ? {
384
+ text: r,
385
+ address: n.getAddress()
386
+ } : null;
387
+ }
388
+ function pe(e) {
570
389
  let t = e.getStats({ onError: "ignore" }), n = t.getCount();
571
- return n > 0 && (t.getTypedCounts()[f.String] ?? 0) === n;
390
+ return n > 0 && (t.getTypedCounts()[m.String] ?? 0) === n;
572
391
  }
573
- function ye(e, t, n) {
392
+ function me(e, t, n) {
574
393
  let r = t.getRange().getCoords(), i = e.getCoords(), a = n ? r.colEnd - r.colStart + 1 : r.rowEnd - r.rowStart + 1, o = [];
575
394
  for (let t = 0; t < a; t++) {
576
395
  let a = n ? e.getRangeAt(i.rowStart, r.colStart + t).getCell() : e.getRangeAt(r.rowStart + t, i.colStart).getCell();
577
- o.push(g(a, p.Mode.Display)?.match ?? "");
396
+ o.push(b(a, _.Mode.Display)?.match ?? "");
578
397
  }
579
398
  return o;
580
399
  }
581
- function be(e, t, n, r) {
582
- let i = e.getRange().getCoords(), a = t ? we(i.colStart + n) : String(i.rowStart + n + 1), o = r?.[n];
400
+ function he(e, t, n, r) {
401
+ let i = e.getRange().getCoords(), a = t ? N(i.colStart + n) : String(i.rowStart + n + 1), o = r?.[n];
583
402
  return o ? `${a} ${o}` : a;
584
403
  }
585
- function xe(e, t = 3) {
404
+ function ge(e, t = 3) {
586
405
  let n = e.getStats({ onError: "ignore" }), r = n.getTypedCounts(), i = n.getCount(), a = n.getSize(), o = a - i;
587
406
  if (i === 0) return `${a} cells, all blank`;
588
- let s = e.getCounts([j.Formula])[j.Formula] ?? 0, c = P(e), l = r[f.Number] ?? 0, u = r[f.String] ?? 0, d = r[f.Error] ?? 0, p = [String(i)], m = !1;
407
+ let s = e.getCounts([P.Formula])[P.Formula] ?? 0, c = ve(e), l = r[m.Number] ?? 0, u = r[m.String] ?? 0, d = r[m.Error] ?? 0, f = [String(i)], p = !1;
589
408
  if (s === i) {
590
- let t = [...e.getRegions(j.Formula)];
409
+ let t = [...e.getRegions(P.Formula)];
591
410
  if (t.length === 1) {
592
411
  let e = t[0].getCell().getFormulaText();
593
- p.push("formula", e ? `=${e}` : "(uniform)");
594
- } else p.push("formula", `${t.length} distinct`);
595
- } else if (c === i) p.push("date", F(n, e));
596
- else if (l === i) p.push("number", F(n, e), ...Ce(n, e));
597
- else if (u === i) p.push("text", I(n, t));
412
+ f.push("formula", e || "(uniform)");
413
+ } else f.push("formula", `${t.length} distinct`);
414
+ } else if (c === i) f.push("date", be(n, ye(e).format));
415
+ else if (l === i) {
416
+ let t = ye(e);
417
+ f.push("number", be(n, t.format), ...xe(n, t));
418
+ } else if (u === i) f.push("text", Se(n, t));
598
419
  else {
599
420
  let e = [
600
421
  l ? `number ${l}` : null,
601
422
  u ? `text ${u}` : null,
602
- r[f.Boolean] ? `boolean ${r[f.Boolean]}` : null,
423
+ r[m.Boolean] ? `boolean ${r[m.Boolean]}` : null,
603
424
  d ? `error ${d}` : null
604
425
  ].filter(Boolean);
605
- p.push("mixed", e.join(" · ")), m = !0;
426
+ f.push("mixed", e.join(" · ")), p = !0;
606
427
  }
607
428
  let h = [
608
- d > 0 && !m ? `error ${d}` : null,
429
+ d > 0 && !p ? `error ${d}` : null,
609
430
  o > 0 ? `${o} blank` : null,
610
431
  s > 0 && s !== i ? `${s} formula` : null
611
- ].filter(Boolean), g = p.filter(Boolean).join(" ");
432
+ ].filter(Boolean), g = f.filter(Boolean).join(" ");
612
433
  return h.length ? `${g} · ${h.join(" · ")}` : g;
613
434
  }
614
- function Se(e, t = 3) {
615
- let n = e.getStats({ onError: "ignore" }), r = n.getTypedCounts(), i = [], a = r[f.Number] ?? 0;
435
+ function _e(e, t = 3) {
436
+ let n = e.getStats({ onError: "ignore" }), r = n.getTypedCounts(), i = [], a = r[m.Number] ?? 0;
616
437
  if (a > 0) {
617
- let t = [F(n, e), ...Ce(n, e)].filter(Boolean);
618
- i.push(`Number: ${a} ${t.join(" ")}`.trimEnd());
438
+ let t = ye(e), r = [be(n, t.format), ...xe(n, t)].filter(Boolean);
439
+ i.push(`Number: ${a} ${r.join(" ")}`.trimEnd());
619
440
  }
620
- let o = r[f.String] ?? 0;
441
+ let o = r[m.String] ?? 0;
621
442
  if (o > 0) {
622
- let e = I(n, t, (e) => typeof e == "string");
443
+ let e = Se(n, t, (e) => typeof e == "string");
623
444
  i.push(`String: ${o} ${e}`.trimEnd());
624
445
  }
625
- let s = r[f.Boolean] ?? 0;
446
+ let s = r[m.Boolean] ?? 0;
626
447
  if (s > 0) {
627
- let e = I(n, t, (e) => typeof e == "boolean");
448
+ let e = Se(n, t, (e) => typeof e == "boolean");
628
449
  i.push(`Boolean: ${s} ${e}`.trimEnd());
629
450
  }
630
451
  return i;
631
452
  }
632
- function P(e) {
453
+ function ve(e) {
633
454
  let t = 0;
634
455
  return e.forEach((e, n) => {
635
- n.getInteropType() === u.Date && t++;
456
+ n.getInteropType() === f.Date && t++;
636
457
  }), t;
637
458
  }
638
- function F(e, t) {
459
+ function ye(e) {
460
+ let t = (e) => e.getStats({ onError: "ignore" }).getTypedCounts()[m.Number] ?? 0, n = /* @__PURE__ */ new Map(), r = 0;
461
+ for (let i of e.getRegions(P.NumberFormat)) {
462
+ let e = i.getRange().getStyle().getNumberFormat(), a = t(i.getRange());
463
+ r += a, e && a > 0 && n.set(e, (n.get(e) ?? 0) + a);
464
+ }
465
+ let i = t(e) - r;
466
+ i > 0 && n.set("General", (n.get("General") ?? 0) + i);
467
+ let a = [...n].sort((e, t) => t[1] - e[1] || Number(t[0] === "General") - Number(e[0] === "General"));
468
+ if (a.length === 0) return {
469
+ format: null,
470
+ mixed: null
471
+ };
472
+ let o = p.getEngine(), s = (e) => {
473
+ if (e === "General") return "1";
474
+ let t = o.getFormatInfo(e);
475
+ return t ? `${t.isDate ? "date" : t.scale}` : "1";
476
+ }, c = a[0][0];
477
+ return a.every(([e]) => s(e) === s(c)) ? {
478
+ format: c === "General" ? null : c,
479
+ mixed: null
480
+ } : {
481
+ format: null,
482
+ mixed: a.map(([e, t]) => `${e} ${t}`).join(" · ")
483
+ };
484
+ }
485
+ function be(e, t) {
639
486
  let n = e.getAggregates({ onError: "ignore" });
640
487
  if (n.min === null || n.max === null) return "";
641
- let r = t.getStyle().getNumberFormat(), i = h(n.min, r), a = h(n.max, r);
642
- return i === a ? i : `${i} … ${a}`;
488
+ let r = y(n.min, t), i = y(n.max, t);
489
+ return r === i ? r : `${r} … ${i}`;
643
490
  }
644
- function Ce(e, t) {
645
- let n = e.getAggregates({ onError: "ignore" }), r = t.getStyle().getNumberFormat(), i = [];
646
- return n.sum !== null && i.push(`Σ ${h(n.sum, r)}`), n.average !== null && i.push(`x̄ ${h(n.average, r)}`), i;
491
+ function xe(e, { format: t, mixed: n }) {
492
+ if (n) return [`mixed formats (${n})`];
493
+ let r = e.getAggregates({ onError: "ignore" }), i = [];
494
+ return r.sum !== null && i.push(`Σ ${y(r.sum, t)}`), r.average !== null && i.push(`x̄ ${y(r.average, t)}`), i;
647
495
  }
648
- function I(e, t, n) {
496
+ function Se(e, t, n) {
649
497
  let r = e.getFrequencies(n ? { filterFn: n } : void 0), i = r.getUniqueCount();
650
498
  if (i === 0) return "";
651
499
  if (i === r.getTotalCount()) return `${i} distinct, no repeats`;
652
500
  let a = Array.from(r.getValueCounts()).slice(0, t);
653
501
  return `${i} unique (${a.map(([e, t]) => `${e} ${t}`).join(" · ")}${i > a.length ? " · …" : ""})`;
654
502
  }
655
- function we(e) {
656
- let t = e, n = "";
657
- do
658
- n = String.fromCharCode(65 + t % 26) + n, t = Math.floor(t / 26) - 1;
659
- while (t >= 0);
660
- return n;
503
+ var F = i.Feature, Ce = (e) => (e.rowEnd - e.rowStart + 1) * (e.colEnd - e.colStart + 1), we = (e, t) => {
504
+ let n = Math.min(e.rowEnd, t.rowEnd) - Math.max(e.rowStart, t.rowStart) + 1;
505
+ if (n <= 0) return 0;
506
+ let r = Math.min(e.colEnd, t.colEnd) - Math.max(e.colStart, t.colStart) + 1;
507
+ return r <= 0 ? 0 : n * r;
508
+ }, Te = (e) => e.toLocaleString("en-US"), Ee = (e, t) => {
509
+ let n = `×${Te(e.content)}`;
510
+ return t === "times" || e.styled === e.content ? n : `${n} (+${Te(e.styled - e.content)} blank)`;
511
+ }, De = (t) => {
512
+ if (t.length === 0) return "";
513
+ let n = e.rangeToString(t[0]);
514
+ if (t.length === 1) return n;
515
+ let r = t.length - 1;
516
+ return `${n}, +${r} block${r === 1 ? "" : "s"}`;
517
+ };
518
+ function I(e, t) {
519
+ let n = t?.manyDistinct ?? 20, { sorted: r, top: i, rare: a, more: o } = Oe(e, t);
520
+ if (r.length === 0) return "";
521
+ let s = (e) => ((e, t) => {
522
+ let n = De(e.blocks);
523
+ return `${e.label === t?.hideLabel ? "" : `${e.label} `}${Ee(e, t?.countStyle ?? "cells")}${n ? ` ${n}` : ""}`;
524
+ })(e, t);
525
+ if (o === 0) return r.map(s).join(" · ");
526
+ let c = r.reduce((e, t) => e + t.content, 0), l = c > 0 ? r[0].content / c : 0, u = [], d = r.length > n ? `${r.length} distinct${l < .5 ? ", no convention" : ""}; largest ` : "";
527
+ return u.push(d + i.map(s).join(" · ")), a.length > 0 && u.push(`rarest ${a.map(s).join(" · ")}`), u.push(`+${o} more${t?.recovery ? ` (${t.recovery})` : ""}`), u.join(" · ");
661
528
  }
662
- var L = r.Feature, R = (e) => e.getRange().getStyle(), Te = (e) => g(e.getCell(), p.Mode.Display)?.display ?? null;
663
- function Ee(e, t) {
664
- switch (e) {
665
- case L.Formula: return (e) => {
666
- let t = e.getCell().getFormulaText();
667
- return t ? `=${t}` : null;
529
+ function Oe(e, t) {
530
+ let n = t?.maxValues ?? 8, r = [...e].sort((e, t) => t.content - e.content || t.styled - e.styled || (e.label < t.label ? -1 : 1));
531
+ if (r.length <= n) return {
532
+ sorted: r,
533
+ top: r,
534
+ rare: [],
535
+ more: 0
536
+ };
537
+ let i = Math.max(1, Math.floor(n / 2)), a = r.slice(0, i), o = [];
538
+ for (let e = r.length - 1; e >= i && o.length < n - i; e--) r[e].content > 0 && o.push(r[e]);
539
+ return o.reverse(), {
540
+ sorted: r,
541
+ top: a,
542
+ rare: o,
543
+ more: r.length - a.length - o.length
544
+ };
545
+ }
546
+ var ke = [
547
+ {
548
+ name: "family",
549
+ project: (e, t) => L(e.getFont().getFamily(), t?.getFont().getFamily())
550
+ },
551
+ {
552
+ name: "size",
553
+ project: (e, t) => L(e.getFont().getSize(), t?.getFont().getSize(), (e) => `${e}pt`)
554
+ },
555
+ {
556
+ name: "bold",
557
+ project: (e, t) => L(e.getFont().getBold(), t?.getFont().getBold() ?? !1, (e) => e ? "bold" : "not bold")
558
+ },
559
+ {
560
+ name: "italic",
561
+ project: (e, t) => L(e.getFont().getItalic(), t?.getFont().getItalic() ?? !1, (e) => e ? "italic" : "not italic")
562
+ },
563
+ {
564
+ name: "underline",
565
+ project: (e, t) => L(e.getFont().getUnderline(), t?.getFont().getUnderline(), (e) => String(e))
566
+ },
567
+ {
568
+ name: "strike",
569
+ project: (e, t) => L(e.getFont().getStrike(), t?.getFont().getStrike() ?? !1, (e) => e ? "strike" : "not strike")
570
+ },
571
+ {
572
+ name: "color",
573
+ project: (e, t) => L(E(e.getFont().getColor()), t ? E(t.getFont().getColor()) : null)
574
+ }
575
+ ], Ae = (e) => Le(e) ?? "Custom", je = {
576
+ name: "category",
577
+ project: (e) => {
578
+ let t = k(e);
579
+ return t === null ? null : Ae(t);
580
+ }
581
+ }, Me = {
582
+ name: "format",
583
+ project: (e) => k(e)
584
+ }, Ne = [je, Me], Pe = [{
585
+ name: "color",
586
+ project: (e) => D(e)
587
+ }], Fe = [{
588
+ name: "edges",
589
+ project: (e) => O(e)
590
+ }], Ie = [
591
+ {
592
+ name: "h",
593
+ ambiguous: !0,
594
+ project: (e, t) => L(e.getAlignment().getHorizontal(), t?.getAlignment().getHorizontal())
595
+ },
596
+ {
597
+ name: "v",
598
+ ambiguous: !0,
599
+ project: (e, t) => L(e.getAlignment().getVertical(), t?.getAlignment().getVertical())
600
+ },
601
+ {
602
+ name: "overflow",
603
+ project: (e, t) => L(e.getAlignment().getOverflow(), t?.getAlignment().getOverflow())
604
+ },
605
+ {
606
+ name: "indent",
607
+ project: (e, t) => L(e.getAlignment().getIndent(), t?.getAlignment().getIndent() ?? 0, (e) => `indent ${e}`)
608
+ },
609
+ {
610
+ name: "rotation",
611
+ project: (e, t) => L(e.getAlignment().getRotation(), t?.getAlignment().getRotation() ?? 0, (e) => `rotation ${e}`)
612
+ }
613
+ ];
614
+ function L(e, t, n = String) {
615
+ return e == null || t !== void 0 && e === t ? null : n(e);
616
+ }
617
+ function Le(e) {
618
+ if (!e || e === "General") return null;
619
+ let t = p.Builder.parse(e);
620
+ if (t.category === "General") return null;
621
+ let n = t.decimalPlaces;
622
+ return n == null ? t.category : `${t.category} ${n}dp`;
623
+ }
624
+ var Re = {
625
+ [F.Font]: ke,
626
+ [F.NumberFormat]: Ne,
627
+ [F.Fill]: Pe,
628
+ [F.Borders]: Fe,
629
+ [F.Alignment]: Ie
630
+ }, ze = (e) => e in Re;
631
+ function Be(e, t, n, r) {
632
+ let i = Re[t];
633
+ if (!i) return null;
634
+ let a = e.getEntireCoords(), o = e.getUsedRange()?.getCoords() ?? null, s = [...e.getEntireRange().getRegions(t)];
635
+ if (s.length === 0) return null;
636
+ let c = r?.content ?? (o ? [...e.getEntireRange().getRegions(F.Contentful)].map((e) => e.getCoords()) : []), l = (e) => c.reduce((t, n) => t + we(e, n), 0), u = (e) => o ? we(e, o) : 0, d = (e) => {
637
+ let t = e.getRange().getStyle(), r = [];
638
+ for (let e of i) {
639
+ let i = e.project(t, n);
640
+ i !== null && r.push(e.ambiguous ? `${e.name} ${i}` : i);
641
+ }
642
+ return r.join(" · ");
643
+ }, f = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Map();
644
+ for (let e of s) p.set(e, e.getRange().getStyle()), f.add(d(e));
645
+ let m = a.rowEnd - a.rowStart + 1, h = a.colEnd - a.colStart + 1, g = [], _ = [], v = [];
646
+ for (let e of s) {
647
+ let t = e.getCoords();
648
+ 2 * (t.rowEnd - t.rowStart + 1) > m ? g.push(e) : 2 * (t.colEnd - t.colStart + 1) > h ? _.push(e) : v.push(e);
649
+ }
650
+ let y = [];
651
+ y.push(...qe("columns", g, d, a, !0)), y.push(...qe("rows", _, d, a, !1));
652
+ let b = v.reduce((e, t) => e + u(t.getCoords()), 0), x = (e) => {
653
+ let t = [];
654
+ for (let r of v) {
655
+ let i = e.project(p.get(r), n);
656
+ i !== null && t.push({
657
+ ...r.getCoords(),
658
+ key: i,
659
+ label: i
660
+ });
661
+ }
662
+ let r = /* @__PURE__ */ new Map();
663
+ for (let e of function(e) {
664
+ let t = [...e];
665
+ if (t.length <= 1) return t;
666
+ let n = !0, r = 0;
667
+ for (; r < 2;) {
668
+ let e = n;
669
+ t.sort((t, n) => t.key < n.key ? -1 : t.key > n.key ? 1 : e ? t.rowStart - n.rowStart || t.rowEnd - n.rowEnd || t.colStart - n.colStart : t.colStart - n.colStart || t.colEnd - n.colEnd || t.rowStart - n.rowStart);
670
+ let i = [], a = !1;
671
+ for (let n of t) {
672
+ let t = i[i.length - 1];
673
+ t && t.key === n.key && (e ? t.rowStart === n.rowStart && t.rowEnd === n.rowEnd && t.colEnd + 1 === n.colStart : t.colStart === n.colStart && t.colEnd === n.colEnd && t.rowEnd + 1 === n.rowStart) ? (i[i.length - 1] = {
674
+ ...t,
675
+ colEnd: e ? n.colEnd : t.colEnd,
676
+ rowEnd: e ? t.rowEnd : n.rowEnd
677
+ }, a = !0) : i.push(n);
678
+ }
679
+ t = i, r = a ? 0 : r + 1, n = !n;
680
+ }
681
+ return t;
682
+ }(t)) {
683
+ let t = r.get(e.key) ?? {
684
+ label: e.label,
685
+ content: 0,
686
+ styled: 0,
687
+ blocks: []
688
+ };
689
+ t.content += l(e), t.styled += u(e), t.blocks.push(e), r.set(e.key, t);
690
+ }
691
+ return [...r.values()].map((e) => ({
692
+ ...e,
693
+ blocks: e.blocks.sort((e, t) => Ce(t) - Ce(e))
694
+ }));
695
+ }, S = [];
696
+ if (t === F.NumberFormat) S.push(...function(e, t, n) {
697
+ let { top: r, rare: i, more: a } = Oe(e, n), o = [], s = -1;
698
+ for (let e of [...r, ...i]) {
699
+ e === i[0] && (s = o.length);
700
+ let n = Oe(t.filter((t) => Ae(t.label) === e.label), { maxValues: Infinity }).sorted, r = n.length === 1;
701
+ if (o.push([
702
+ e.label,
703
+ Ee(e, "cells"),
704
+ De(e.blocks),
705
+ r ? n[0].label : `${n.length} formats`
706
+ ]), !r) {
707
+ for (let e of n.slice(0, Ke)) o.push([
708
+ "",
709
+ Ee(e, "cells"),
710
+ De(e.blocks),
711
+ e.label
712
+ ]);
713
+ n.length > Ke && o.push([
714
+ "",
715
+ "",
716
+ "",
717
+ `…and ${n.length - Ke} more`
718
+ ]);
719
+ }
720
+ }
721
+ let c = [
722
+ 0,
723
+ 1,
724
+ 2
725
+ ].map((e) => Math.max(...o.map((t) => t[e].length))), l = o.map((e) => `${e[0].padEnd(c[0])} ${e[1].padEnd(c[1])} ${e[2].padEnd(c[2])} ${e[3]}`.trimEnd());
726
+ return a > 0 && l.splice(s < 0 ? l.length : s, 0, `…and ${a} more${n?.recovery ? ` · ${n.recovery}` : ""}`), l;
727
+ }(x(je), x(Me), r));
728
+ else for (let e of i) {
729
+ let t = x(e);
730
+ if (t.length === 0) continue;
731
+ let n = I(t, {
732
+ ...r,
733
+ hideLabel: e.name
734
+ });
735
+ n.length <= We ? S.push(`${e.name.padEnd(10)}${n}`) : S.push(...Ge(e.name, t, r));
736
+ }
737
+ return {
738
+ distinct: f.size,
739
+ cells: b,
740
+ normal: n ? Ue(t, n) : null,
741
+ tiers: y,
742
+ attributes: S
743
+ };
744
+ }
745
+ function Ve(e, t) {
746
+ if (e.length === 0) return null;
747
+ let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = 0;
748
+ for (let t of e) {
749
+ let e = t.getRowCount() * t.getColumnCount(), a = t.getCell(), o = a.getFormulaText({ r1c1: !0 }) ?? "", s = n.get(o) ?? {
750
+ label: o,
751
+ cells: 0,
752
+ blocks: []
668
753
  };
669
- case L.Error: return Te;
670
- case L.CalcError: return (e) => {
671
- let t = Te(e) ?? "", n = e.getCell().getFormulaText();
672
- return (n ? `${t} =${n}` : t).trim() || null;
754
+ s.cells += e, s.blocks.push(t.getCoords()), n.set(o, s);
755
+ let c = /* @__PURE__ */ new Set();
756
+ for (let e of a.getFormula()?.getTokens() ?? []) {
757
+ if (e.type !== "function") continue;
758
+ let t = String(e.value ?? e.text ?? "").toUpperCase();
759
+ t && c.add(t);
760
+ }
761
+ c.size === 0 && (i += e);
762
+ for (let t of c) r.set(t, (r.get(t) ?? 0) + e);
763
+ }
764
+ let a = {
765
+ ...t,
766
+ countStyle: "times"
767
+ }, o = [...n.values()].map((e) => ({
768
+ label: e.label,
769
+ content: e.cells,
770
+ styled: e.cells,
771
+ blocks: e.blocks.sort((e, t) => Ce(t) - Ce(e))
772
+ })), s = [...r.entries()].map(([e, t]) => ({
773
+ label: e,
774
+ content: t,
775
+ styled: t,
776
+ blocks: []
777
+ }));
778
+ return i > 0 && s.push({
779
+ label: "no function",
780
+ content: i,
781
+ styled: i,
782
+ blocks: []
783
+ }), {
784
+ distinct: n.size,
785
+ lines: [`${"distinct".padEnd(10)}${I(o, a)}`, `${"functions".padEnd(10)}${I(s, a)}`]
786
+ };
787
+ }
788
+ function He(e, t) {
789
+ let n = e.getStats({ onError: "ignore" }).getTypedCounts(), r = /* @__PURE__ */ new Map(), i = [
790
+ ["number", "number"],
791
+ ["string", "text"],
792
+ ["boolean", "boolean"],
793
+ ["error", "error"],
794
+ ["richData", "richData"]
795
+ ];
796
+ for (let [e, t] of i) {
797
+ let i = n[e] ?? 0;
798
+ i > 0 && r.set(t, i);
799
+ }
800
+ let a = ve(e), o = 0;
801
+ for (let e of t) {
802
+ let t = e.getRange().getStats({ onError: "ignore" }).getTypedCounts();
803
+ o += e.getRowCount() * e.getColumnCount();
804
+ for (let [e, n] of i) {
805
+ let i = t[e] ?? 0;
806
+ i > 0 && r.set(n, (r.get(n) ?? 0) - i);
807
+ }
808
+ a > 0 && (t.number ?? 0) > 0 && (a -= ve(e.getRange()));
809
+ }
810
+ return a > 0 && (r.set("date", a), r.set("number", (r.get("number") ?? 0) - a)), o > 0 && r.set("formula", o), [...r.entries()].filter(([, e]) => e > 0).sort((e, t) => t[1] - e[1]);
811
+ }
812
+ function Ue(e, t) {
813
+ switch (e) {
814
+ case F.Font: return function(e) {
815
+ let t = e.getFont(), n = [t.getFamily(), `${t.getSize()}pt`], r = E(t.getColor());
816
+ return r && n.push(r), t.getBold() && n.push("bold"), t.getItalic() && n.push("italic"), n.join(" · ");
817
+ }(t);
818
+ case F.NumberFormat: {
819
+ let e = k(t);
820
+ return e === null ? null : `${Ae(e)} ${e}`;
821
+ }
822
+ case F.Fill: return D(t);
823
+ case F.Borders: return O(t);
824
+ case F.Alignment: {
825
+ let e = t.getAlignment(), n = [];
826
+ return e.getHorizontal() !== "general" && n.push(`h ${e.getHorizontal()}`), e.getVertical() !== "bottom" && n.push(`v ${e.getVertical()}`), e.getOverflow() !== "visible" && n.push(String(e.getOverflow())), e.getIndent() && n.push(`indent ${e.getIndent()}`), e.getRotation() && n.push(`rotation ${e.getRotation()}`), n.length > 0 ? n.join(" · ") : null;
827
+ }
828
+ default: return null;
829
+ }
830
+ }
831
+ var We = 110;
832
+ function Ge(e, t, n) {
833
+ let { sorted: r, top: i, rare: a, more: o } = Oe(t, n), s = [...i, ...a].map((e) => [
834
+ Ee(e, "cells"),
835
+ De(e.blocks),
836
+ e.label
837
+ ]), c = [0, 1].map((e) => Math.max(...s.map((t) => t[e].length))), l = s.map((e) => ` ${e[0].padEnd(c[0])} ${e[1].padEnd(c[1])} ${e[2]}`);
838
+ o > 0 && l.splice(i.length, 0, ` …and ${o} more${n?.recovery ? ` · ${n.recovery}` : ""}`);
839
+ let u = n?.manyDistinct ?? 20;
840
+ return [r.length > u ? `${e.padEnd(10)}${r.length} distinct` : e, ...l];
841
+ }
842
+ var Ke = 6;
843
+ function qe(t, n, r, i, a) {
844
+ if (n.length === 0) return [];
845
+ let o = /* @__PURE__ */ new Map();
846
+ for (let e of n) {
847
+ let t = r(e), n = o.get(t);
848
+ n ? n.push(e) : o.set(t, [e]);
849
+ }
850
+ let s = a ? i.colEnd - i.colStart + 1 : i.rowEnd - i.rowStart + 1, c = [];
851
+ for (let [n, r] of o) {
852
+ let i = 0, o = r.map((t) => {
853
+ let n = t.getCoords();
854
+ i += a ? n.colEnd - n.colStart + 1 : n.rowEnd - n.rowStart + 1;
855
+ let r = a ? e.runToString(n.colStart, n.colEnd, !0) : e.runToString(n.rowStart, n.rowEnd, !1), o = a ? n.rowStart : n.colStart;
856
+ return o === 0 ? r : `${r} (from ${a ? `row ${o + 1}` : `column ${e.runToString(o, o, !0).split(":")[0]}`})`;
857
+ });
858
+ 2 * i > s ? c.push(`${"sheet".padEnd(10)}${n || "default"}`) : c.push(`${t.padEnd(10)}${o.join(", ")} ${n || "default"}`);
859
+ }
860
+ return c;
861
+ }
862
+ var Je = (e, t) => e.length > t ? `${e.slice(0, t - 1)}…` : e, R = (e) => {
863
+ if (!e) return null;
864
+ if (typeof e != "string") return E(e);
865
+ let t = e.replace(/^#/, "");
866
+ 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;
867
+ }, Ye = (e) => {
868
+ if (!e) return null;
869
+ let t = [], n = ((e) => {
870
+ if (!e) return null;
871
+ if (typeof e == "string") return R(e);
872
+ let t = e.type;
873
+ if (t === c.Type.None) return null;
874
+ if (t === c.Type.Gradient) return "gradient";
875
+ let n = e, r = R(n.foreground ?? e.color ?? n.background), i = n.patternType;
876
+ return [i && i !== c.BuiltInSheetPattern.Solid ? `${i} pattern` : null, r].filter(Boolean).join(" ") || null;
877
+ })(e.fill);
878
+ n && t.push(`fill ${n}`);
879
+ let r = e.font;
880
+ if (r) {
881
+ let e = [];
882
+ (r.weight === void 0 ? !0 === r.bold : r.weight >= 600) && e.push("bold"), (r.style === void 0 ? !0 === r.italic : r.style === l.Style.Italic) && e.push("italic"), r.strike && e.push("strike"), r.underline && r.underline !== l.UnderlineStyle.None && e.push(`underline ${r.underline}`);
883
+ let n = r.color === "auto" ? null : R(r.color);
884
+ n && e.push(`text ${n}`), e.length > 0 && t.push(e.join(" "));
885
+ }
886
+ if (e.numberFormat !== void 0 && e.numberFormat !== null) {
887
+ let n = typeof e.numberFormat == "number" ? p.resolve(e.numberFormat) : String(e.numberFormat);
888
+ n && t.push(n);
889
+ }
890
+ return e.borders && t.push("border"), e.alignment && t.push("alignment"), t.length > 0 ? t.join(" · ") : null;
891
+ }, Xe = (e) => {
892
+ let t = e.type ?? o.ColorStopType.Num, n = e.value, r = n == null || n === "" ? t : `${t} ${n}`, i = R(e.color);
893
+ return i ? `${r} ${i}` : r;
894
+ }, Ze = (e) => {
895
+ let t = e.type;
896
+ if (e.type === o.ScaleType.DataBar) {
897
+ let n = R(e.color);
898
+ n && (t += ` ${n}`);
899
+ } else e.type === o.ScaleType.IconSet && (e.iconSet && (t += ` ${e.iconSet}`), e.reverse && (t += " reversed"), e.icon?.length && (t += " custom icons"));
900
+ let n = (e.stops ?? []).map(Xe).join(" → ");
901
+ return n ? `${t} · ${n}` : t;
902
+ }, Qe = "(no rule)", $e = (e) => {
903
+ let t = e.getScale(), n = [];
904
+ if (t) n.push(Ze(t));
905
+ else {
906
+ n.push(e.getCondition()?.toString() || Qe);
907
+ let t = Ye(e.getStyle());
908
+ t && n.push(`→ ${t}`);
909
+ }
910
+ return e.isStopIfTrue() && n.push("· stop if true"), Je(n.join(" "), 90);
911
+ }, et = (e) => {
912
+ let t = [e.getCondition()?.toString() || Qe], n = e.getAlertStyle();
913
+ return n && t.push(n), e.isIncludeBlanks() && t.push("blanks allowed"), e.isHideDropdown() && t.push("no dropdown"), Je(t.join(" · "), 90);
914
+ }, tt = (e) => {
915
+ if (e?.getOperator()?.getName() !== a.BuiltInOperatorNames.InSet) return null;
916
+ let t = e.getParam()?.items;
917
+ if (!t) return null;
918
+ if (typeof t == "string") return t;
919
+ let n = t.slice(0, 20).map((e) => x(e)?.match ?? ""), r = t.length - n.length;
920
+ return r > 0 ? `${n.join(", ")}, +${r} more` : n.join(", ");
921
+ }, nt = (e, t) => {
922
+ if (e.length === 0) return null;
923
+ let n = e.slice(0, 3).map(t), r = e.length - n.length;
924
+ return r > 0 ? `${n.join(" | ")} | +${r} more` : n.join(" | ");
925
+ }, z = i.Feature, B = (e) => e.getRange().getStyle(), rt = (e) => b(e.getCell(), _.Mode.Display)?.display ?? null;
926
+ function it(e, t) {
927
+ switch (e) {
928
+ case z.Formula: return (e) => e.getCell().getFormulaText();
929
+ case z.Error: return rt;
930
+ case z.CalcError: return (e) => {
931
+ let t = rt(e) ?? "", n = e.getCell().getFormulaText();
932
+ return (n ? `${t} ${n}` : t).trim() || null;
673
933
  };
674
- case L.Merge: return Te;
675
- case L.Comments: return (e) => {
676
- let t = e.getCell().getComments()?.content;
934
+ case z.Merge: return rt;
935
+ case z.Comments: return (e) => {
936
+ let t = e.getCell().getComments()?.getContent();
677
937
  if (typeof t != "string") return null;
678
938
  let n = t.replace(/\s+/g, " ").trim();
679
939
  return n ? n.length > 60 ? `${n.slice(0, 59)}…` : n : null;
680
940
  };
681
- case L.Spills: return (e) => e.getCell().getSpill()?.getValuesRange().toString() ?? null;
682
- case L.Hyperlink: return (e) => e.getCell().getHyperlink()?.getAddress() ?? null;
683
- case L.Table: return (e) => e.getCell().getTable()?.getName() ?? null;
684
- case L.Fill: return (e) => ae(R(e));
685
- case L.Border: return (e) => oe(R(e));
686
- case L.NumberFormat: return (e) => le(R(e));
687
- case L.Alignment: return t ? (e) => ue(R(e), t) : void 0;
688
- case L.Font: return t ? (e) => de(R(e), t) : void 0;
689
- case L.Conditionals: return (e) => A(e.getRange().getConditionalFormats(), k);
690
- case L.DataValidations: return (e) => A(e.getRange().getDataValidations(), _e);
691
- case L.Contentful: return (e) => Se(e.getRange()).join(" ") || null;
941
+ case z.Spills: return (e) => e.getCell().getSpill()?.getValuesRange().toString() ?? null;
942
+ case z.Hyperlink: return (e) => e.getCell().getHyperlink()?.getAddress() ?? null;
943
+ case z.Table: return (e) => e.getCell().getTable()?.getName() ?? null;
944
+ case z.Fill: return (e) => D(B(e));
945
+ case z.Borders: return (e) => O(B(e));
946
+ case z.NumberFormat: return (e) => k(B(e));
947
+ case z.Alignment: return t ? (e) => A(B(e), t) : void 0;
948
+ case z.Font: return t ? (e) => j(B(e), t) : void 0;
949
+ case z.Protection: return (e) => {
950
+ let t = B(e).getProtection(), n = [];
951
+ return t.isAlwaysUnlocked() && n.push("always unlocked"), t.isShowFormulas() || n.push("formulas hidden"), n.join(", ") || null;
952
+ };
953
+ case z.Unlock: return (e) => {
954
+ let t = [];
955
+ e.getCell().getProtection().isAlwaysUnlocked() && t.push("always unlocked");
956
+ let n = e.getRange();
957
+ for (let e of n.getSheet().getProtectedRanges().getItems({ address: n })) t.push(`range ${e.getName()}${e.isUnlocked() ? "" : " · password"}`);
958
+ return t.join(", ") || null;
959
+ };
960
+ case z.Conditionals: return (e) => nt(e.getRange().getConditionalFormats(), $e);
961
+ case z.DataValidations: return (e) => nt(e.getRange().getDataValidations(), et);
962
+ case z.Contentful: return (e) => _e(e.getRange()).join(" ") || null;
692
963
  default: return;
693
964
  }
694
965
  }
695
- function De(e, t) {
696
- let n = e.map((e) => Ee(e, t)).filter((e) => !!e);
966
+ function at(e, t) {
967
+ let n = e.map((e) => it(e, t)).filter((e) => !!e);
697
968
  if (n.length !== 0) return n.length === 1 ? n[0] : (e) => {
698
969
  let t = n.map((t) => t(e)).filter(Boolean);
699
970
  return t.length > 0 ? t.join(" ") : null;
700
971
  };
701
972
  }
702
- var z = class {
973
+ var V = class {
703
974
  constructor() {
704
975
  this._lines = [], this._headingOffset = 0;
705
976
  }
@@ -740,7 +1011,7 @@ var z = class {
740
1011
  return `\`\`\`${t}\n${e}\n\`\`\``;
741
1012
  }
742
1013
  beginFrame(e) {
743
- return new Oe(this, e);
1014
+ return new ot(this, e);
744
1015
  }
745
1016
  _addLines(e) {
746
1017
  this._lines.push(...e);
@@ -748,7 +1019,7 @@ var z = class {
748
1019
  toLines() {
749
1020
  return [...this._lines];
750
1021
  }
751
- }, Oe = class {
1022
+ }, ot = class {
752
1023
  constructor(e, t) {
753
1024
  this._parent = e, this._headers = t, this._indexWidth = 0, this._rows = [], this._colWidths = t.map((e) => e.length);
754
1025
  }
@@ -775,29 +1046,29 @@ var z = class {
775
1046
  _renderLines() {
776
1047
  let e = this._indexWidth > 0 ? " ".repeat(this._indexWidth) : "", t = this._colWidths.map((e, t) => this._columnAlignment(t)), n = [];
777
1048
  if (this._headers.some((e) => e.length > 0)) {
778
- let r = this._headers.map((e, n) => ke(e, this._colWidths[n], t[n])).join(" ");
1049
+ let r = this._headers.map((e, n) => st(e, this._colWidths[n], t[n])).join(" ");
779
1050
  n.push(`${e}${e ? " " : ""}${r}`.trimEnd());
780
1051
  }
781
1052
  for (let e of this._rows) {
782
- let t = e.cells.map((e, t) => ke(e.text, this._colWidths[t], e.alignment)).join(" "), r = this._indexWidth > 0 ? (e.index ?? "").padStart(this._indexWidth) + " " : "";
1053
+ let t = e.cells.map((e, t) => st(e.text, this._colWidths[t], e.alignment)).join(" "), r = this._indexWidth > 0 ? (e.index ?? "").padStart(this._indexWidth) + " " : "";
783
1054
  n.push(`${r}${t}`.trimEnd());
784
1055
  }
785
1056
  return n;
786
1057
  }
787
- }, ke = (e, t, n) => {
1058
+ }, st = (e, t, n) => {
788
1059
  if (e.length >= t) return e;
789
1060
  let r = t - e.length;
790
1061
  return n === "right" ? e.padStart(t) : n === "center" ? " ".repeat(Math.floor(r / 2)) + e + " ".repeat(Math.ceil(r / 2)) : e.padEnd(t);
791
1062
  };
792
- function Ae(e, t, n) {
793
- let r = E(t.length, n?.maxRegions ?? 200), i = t.length > r ? t.slice(0, r) : t, a = i.length < t.length;
1063
+ function ct(e, t, n) {
1064
+ let r = T(t.length, n?.maxRegions ?? 200), i = t.length > r ? t.slice(0, r) : t, a = i.length < t.length;
794
1065
  if (i.length === 0) return void e.text("None");
795
1066
  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;
796
1067
  for (let t = 0; t < i.length; t++) {
797
1068
  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)}`;
798
1069
  if (t < u) {
799
- let t = M(r, n);
800
- e.text(`${f} ${t.summary}${d}`);
1070
+ let t = ae(r, n);
1071
+ if (e.text(`${f} ${t.summary}${d}`), !1 === n?.series) continue;
801
1072
  for (let n of t.series) e.text(` ${n}`);
802
1073
  continue;
803
1074
  }
@@ -808,60 +1079,71 @@ function Ae(e, t, n) {
808
1079
  e.text(` …truncated at ${r} of ${t.length} regions · ${i}`);
809
1080
  }
810
1081
  }
811
- function je(e, t) {
812
- let n = [...e], i = e.getFeatures(), a = i.join(", "), o = i.length === 1 && i[0] === r.Feature.Contentful, s = e.getRange().getSheet().getWorkbook()?.getStyles().getNormal() ?? null, c = new z();
813
- return c.h1(`Regions — ${a} (${n.length})`), Ae(c, n, {
1082
+ function lt(e, t) {
1083
+ let n = [...e], r = e.getFeatures(), a = r.join(", "), o = r.length === 1 && r[0] === i.Feature.Contentful, s = e.getRange().getSheet().getWorkbook()?.getStyles().getNormal() ?? null, c = new V();
1084
+ return c.h1(`Regions — ${a} (${n.length})`), ct(c, n, {
814
1085
  ...t,
815
1086
  profile: o,
816
- payload: o ? void 0 : De(i, s)
1087
+ payload: o ? void 0 : at(r, s)
817
1088
  }), c.toLines().join("\n").trimEnd();
818
1089
  }
819
- function Me(e, t) {
820
- let n = t.getRange();
821
- e.text(`Name: ${t.getName()}`);
822
- let r = t.getDescription();
823
- r && e.text(`Description: ${r}`);
824
- let i = n.getRowCount(), a = n.getColumnCount();
825
- e.text(`Location: ${n.toString()}, ${i} row${i === 1 ? "" : "s"} x ${a} column${a === 1 ? "" : "s"}`);
826
- let o = t.getColumns().map((e) => e.getName());
827
- e.text(`Columns (${o.length}): ${o.join(", ")}`), e.text("Headers: " + (t.isShowHeaders() ? "shown" : "hidden")), e.text("Totals: " + (t.isShowTotals() ? "shown" : "hidden"));
828
- }
829
- function Ne(e) {
830
- let t = new z();
831
- return t.h1(`Table — ${e.getName()}`), t.text(`Sheet: ${H(e.getRange().getSheet().getName())}`), t.blank(), Me(t, e), t.toLines().join("\n").trimEnd();
832
- }
833
- var B = r.Feature, Pe = [
834
- B.Error,
835
- B.CalcError,
836
- B.Contentful,
837
- B.Formula,
838
- B.Spills,
839
- B.Merge,
840
- B.Table,
841
- B.AutoTable,
842
- B.Hyperlink,
843
- B.Comments,
844
- B.Unlock,
845
- B.NumberFormat,
846
- B.Font,
847
- B.Fill,
848
- B.Border,
849
- B.Alignment,
850
- B.Conditionals,
851
- B.DataValidations
852
- ], Fe = new Map(Object.entries(B).map(([e, t]) => [t, e])), Ie = (e) => Fe.get(e) ?? e;
853
- function Le(e) {
854
- let t = new Map(Object.values(B).map((e) => [e.toLowerCase(), e])), n = [];
1090
+ function ut(e, t = []) {
1091
+ let n = [...t], r = e.getDescription();
1092
+ r && n.push(["description", r]), n.push(["columns", e.getColumns().map((e) => e.getName()).join(", ")]), n.push(["headers", e.isShowHeaders() ? "shown" : "hidden"]), n.push(["totals", e.isShowTotals() ? "shown" : "hidden"]);
1093
+ let i = Math.max(10, ...n.map(([e]) => e.length + 2));
1094
+ return n.map(([e, t]) => `${e.padEnd(i)}${t}`);
1095
+ }
1096
+ function dt(e, t, n) {
1097
+ if (t.length === 0) return;
1098
+ let r = t.map((e) => {
1099
+ let t = e.getRange();
1100
+ return {
1101
+ table: e,
1102
+ address: t.toString(),
1103
+ size: `${t.getRowCount()}×${t.getColumnCount()}`
1104
+ };
1105
+ }), i = Math.max(...r.map((e) => e.address.length)), a = Math.max(...r.map((e) => e.size.length));
1106
+ e.h2(`Tables (${n} cell${n === 1 ? "" : "s"} · ${t.length} table${t.length === 1 ? "" : "s"})`);
1107
+ for (let t of r) {
1108
+ e.text(` ${t.address.padEnd(i)} ${t.size.padEnd(a)} ${t.table.getName()}`);
1109
+ for (let n of ut(t.table)) e.text(` ${n}`);
1110
+ }
1111
+ e.blank();
1112
+ }
1113
+ function ft(e) {
1114
+ let t = new V();
1115
+ return t.h1(`Table — ${e.getName()}`), t.fact(ut(e, [["range", yt(e.getRange())]])), t.toLines().join("\n").trimEnd();
1116
+ }
1117
+ var H = i.Feature, pt = [
1118
+ H.Error,
1119
+ H.CalcError,
1120
+ H.Contentful,
1121
+ H.Formula,
1122
+ H.Spills,
1123
+ H.Merge,
1124
+ H.AutoTable,
1125
+ H.Hyperlink,
1126
+ H.Comments,
1127
+ H.NumberFormat,
1128
+ H.Font,
1129
+ H.Fill,
1130
+ H.Borders,
1131
+ H.Alignment,
1132
+ H.Conditionals,
1133
+ H.DataValidations
1134
+ ], mt = new Map(Object.entries(H).map(([e, t]) => [t, e])), ht = (e) => mt.get(e) ?? e;
1135
+ function gt(e) {
1136
+ let t = new Map(Object.values(H).map((e) => [e.toLowerCase(), e])), n = [];
855
1137
  for (let r of e.split(",")) {
856
1138
  let e = r.trim();
857
1139
  if (!e) continue;
858
1140
  let i = t.get(e.toLowerCase());
859
- if (!i) throw Error(`Unknown feature '${e}'. Features: ${Object.values(B).join(", ")}.`);
1141
+ if (!i) throw Error(`Unknown feature '${e}'. Features: ${Object.values(H).join(", ")}.`);
860
1142
  n.push(i);
861
1143
  }
862
1144
  return n;
863
1145
  }
864
- var V = (e) => `${e.toString()}, ${e.getRowCount()}×${e.getColumnCount()}`, H = (t) => e.sheetNameToString(t) ?? "Untitled", Re = (e) => `wb.getSheet(${JSON.stringify(e.getSheet().getName())})`, ze = (e) => ((e) => {
1146
+ var U = (e) => `${e.toString()}, ${e.getRowCount()}×${e.getColumnCount()}`, W = (t) => e.sheetNameToString(t) ?? "Untitled", G = (e) => `wb.getSheet(${JSON.stringify(e.getSheet().getName())})`, _t = (e) => ((e) => {
865
1147
  if (!e.includes("$")) return e;
866
1148
  let t = "", n = !1;
867
1149
  for (let r of e) {
@@ -870,62 +1152,71 @@ var V = (e) => `${e.toString()}, ${e.getRowCount()}×${e.getColumnCount()}`, H =
870
1152
  t += r;
871
1153
  }
872
1154
  return t;
873
- })(e.getAddress()), Be = (e) => {
874
- let t = ze(e);
875
- return t.includes("!") ? t : `${H(e.getSheet().getName())}!${t}`;
876
- }, U = (e) => {
1155
+ })(e.getAddress()), vt = (e) => {
1156
+ let t = _t(e);
1157
+ return t.includes("!") ? t : `${W(e.getSheet().getName())}!${t}`;
1158
+ }, yt = (e) => {
877
1159
  let t = e.toString();
878
- return `${t.includes("!") ? t : `${H(e.getSheet().getName())}!${t}`}, ${e.getRowCount()}×${e.getColumnCount()}`;
1160
+ return `${t.includes("!") ? t : `${W(e.getSheet().getName())}!${t}`}, ${e.getRowCount()}×${e.getColumnCount()}`;
879
1161
  };
880
- function W(e, t) {
881
- let n = t.getStats({ onError: "ignore" }), r = n.getTypedCounts(), i = P(t), a = [
882
- ["Error", r[f.Error] ?? 0],
883
- ["Number", r[f.Number] ?? 0],
884
- ["String", r[f.String] ?? 0],
885
- ["Date", i],
886
- ["Boolean", r[f.Boolean] ?? 0],
887
- ["RichData", r[f.RichData] ?? 0]
888
- ].filter(([, e]) => e > 0), o = n.getCount();
889
- e.h2(`Kind (${o} cell${o === 1 ? "" : "s"} · ${a.length} kind${a.length === 1 ? "" : "s"})`);
890
- for (let [t, n] of a) e.fact(`${t}: ${n}`);
891
- a.length === 0 && e.fact("None"), e.blank();
892
- }
893
- function Ve(e, t, n) {
894
- 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 = Pe.filter((e) => !i || i.has(e));
1162
+ function bt(e, t) {
1163
+ let n = He(t, [...t.getRegions(H.Formula)]), r = t.getStats({ onError: "ignore" }).getCount();
1164
+ e.h2(`Kind (${r} cell${r === 1 ? "" : "s"} · ${n.length} kind${n.length === 1 ? "" : "s"})`);
1165
+ for (let [t, r] of n) e.text(` ${t.padEnd(10)}${r}`);
1166
+ n.length === 0 && e.fact("None"), e.blank();
1167
+ }
1168
+ function xt(e, t, n) {
1169
+ 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 = pt.filter((e) => !i || i.has(e));
895
1170
  if (a.length === 0) return;
896
- let o = t.getCounts(a);
1171
+ let o = t.getCounts(a), s, c = () => s ??= [...t.getSheet().getEntireRange().getRegions(H.Contentful)].map((e) => e.getCoords());
897
1172
  for (let i of a) {
898
- let a = [...t.getRegions(i)];
899
- if (a.length === 0) continue;
900
- let s = !!n?.profile && i === B.Contentful;
901
- e.h2(`${Ie(i)} (${He(a.length, o[i])})`), Ae(e, a, {
902
- maxRegions: n?.maxRegions,
903
- maxProfiled: n?.maxProfiled,
904
- profile: s,
905
- payload: s ? void 0 : Ee(i, r),
906
- recovery: `${Re(t)}.getRegions(${JSON.stringify(i)}) lists all ${a.length}`
907
- }), e.blank();
908
- }
909
- }
910
- var He = (e, t) => `${t} cell${t === 1 ? "" : "s"} · ${e} region${e === 1 ? "" : "s"}`, Ue = (e, t) => e.length > t ? `${e.slice(0, t - 1)}…` : e, We = (e) => e.isIFormula ? e : null, G = (e) => {
1173
+ let a = i === H.Contentful ? St(t) : [...t.getRegions(i)];
1174
+ if (a.length === 0) {
1175
+ let t = r && i !== H.Font ? Ue(i, r) : null;
1176
+ t && (e.h2(`${ht(i)} (${Ct(0, 0)})`), e.text(` ${"normal".padEnd(10)}${t}`), e.blank());
1177
+ continue;
1178
+ }
1179
+ let s = !!n?.profile && i === H.Contentful, l = `${G(t)}.getRegions(${JSON.stringify(i)})`, u = `${l} lists all ${a.length}`, d = ze(i) ? Be(t.getSheet(), i, r, {
1180
+ recovery: u,
1181
+ content: c()
1182
+ }) : null, f = i === H.Formula ? Ve(a, { recovery: u }) : null, p = d ? `${Ct(a.length, d.cells)} · ${d.distinct} distinct` : f ? `${Ct(a.length, o[i])} · ${f.distinct} distinct` : Ct(a.length, o[i]);
1183
+ if (e.h2(`${ht(i)} (${p})`), d) {
1184
+ d.normal && e.text(` ${"normal".padEnd(10)}${d.normal}`);
1185
+ for (let t of d.tiers) e.text(` ${t}`);
1186
+ for (let t of d.attributes) e.text(` ${t}`);
1187
+ e.text(` ${"regions".padEnd(10)}${l}`), e.blank();
1188
+ } else {
1189
+ if (f) for (let t of f.lines) e.text(` ${t}`);
1190
+ i === H.Contentful && a.sort((e, t) => t.getRowCount() * t.getColumnCount() - e.getRowCount() * e.getColumnCount()), ct(e, a, {
1191
+ maxRegions: n?.maxRegions,
1192
+ maxProfiled: n?.maxProfiled,
1193
+ profile: s,
1194
+ series: !1,
1195
+ payload: s ? void 0 : it(i, r),
1196
+ recovery: u
1197
+ }), e.blank();
1198
+ }
1199
+ }
1200
+ }
1201
+ var St = (e) => [...e.getRegions([H.Contentful, H.Table])].filter((e) => e.getCell().isContentful()), Ct = (e, t) => `${t} cell${t === 1 ? "" : "s"} · ${e} region${e === 1 ? "" : "s"}`, wt = (e, t) => e.length > t ? `${e.slice(0, t - 1)}…` : e, Tt = (e) => e.isIFormula ? e : null, Et = (e) => {
911
1202
  let t = e.getScope();
912
- return t ? `${H(t)}!${e.getName()}` : e.getName();
913
- }, Ge = (e) => {
1203
+ return t ? `${W(t)}!${e.getName()}` : e.getName();
1204
+ }, Dt = (e) => {
914
1205
  let t = e.getAddress();
915
- return t.includes("!") ? t : `${H(e.getSheet().getName())}!${t}`;
1206
+ return t.includes("!") ? t : `${W(e.getSheet().getName())}!${t}`;
916
1207
  };
917
- function Ke(e) {
918
- let t = We(e), n;
919
- return n = t ? "=" + t.getExpression() : e.getRanges?.()?.getAddress() ?? "", t?.isVolatile() && (n += " (volatile)"), n.trim();
920
- }
921
- var qe = /* @__PURE__ */ new Set([t.Code.Ref, t.Code.Name]), Je = (e) => {
922
- let n = e.value, r = t.isError(n) ? n : n?.error;
923
- return r && qe.has(r.getCode()) ? r.getCode() === t.Code.Name ? "#NAME?" : "#REF!" : null;
924
- }, Ye = /* @__PURE__ */ new Set(), Xe = (e) => {
1208
+ async function Ot(e) {
1209
+ let t = Tt(e), n;
1210
+ return n = t ? "=" + t.getExpression() : e.getRanges?.()?.getAddress() ?? "", t && await t.isVolatile() && (n += " (volatile)"), n.trim();
1211
+ }
1212
+ var kt = /* @__PURE__ */ new Set([t.Code.Ref, t.Code.Name]), At = (e) => {
1213
+ let n = e.value, r = typeof n == "string" ? n : n?.error, i = typeof r == "string" ? t.getBuiltInByLabel(r) : void 0;
1214
+ return i && kt.has(i.getCode()) ? i.getCode() === t.Code.Name ? "#NAME?" : "#REF!" : null;
1215
+ }, jt = /* @__PURE__ */ new Set(), Mt = (e) => {
925
1216
  let t = e.value;
926
1217
  return typeof t == "object" && t?.name ? t.name : e.text ?? "";
927
1218
  };
928
- function Ze(e) {
1219
+ function Nt(e) {
929
1220
  let t = null;
930
1221
  for (let n = 0; n < e.length; n++) {
931
1222
  let r = e[n];
@@ -935,30 +1226,30 @@ function Ze(e) {
935
1226
  let a = n + 1;
936
1227
  for (; a < e.length && e[a].type === "whitespace";) a++;
937
1228
  if (e[a]?.type !== "separator") continue;
938
- let o = Xe(r).toLowerCase();
1229
+ let o = Mt(r).toLowerCase();
939
1230
  o && (t ??= /* @__PURE__ */ new Set()).add(o);
940
1231
  }
941
- return t ?? Ye;
1232
+ return t ?? jt;
942
1233
  }
943
- function K(e, t, n) {
1234
+ async function Pt(e, t, n) {
944
1235
  if (t.length === 0) return;
945
1236
  let r = /* @__PURE__ */ new Set();
946
1237
  for (let e of n?.symbols ?? t) r.add(e.getName().toLowerCase());
947
1238
  let i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set();
948
1239
  for (let e of t) i.set(e.getId(), e), e.getScope() && a.add(e.getName().toLowerCase());
949
- let o = t.map((e) => {
1240
+ let o = await Promise.all(t.map(async (e) => {
950
1241
  let t = function(e, t) {
951
- let n = We(e), r = [];
1242
+ let n = Tt(e), r = [];
952
1243
  if (n) {
953
1244
  let e = n.getTokens(), i = null, a = null;
954
1245
  for (let n of e) {
955
1246
  if (n.type === "error") {
956
- a ??= Je(n);
1247
+ a ??= At(n);
957
1248
  continue;
958
1249
  }
959
1250
  if (n.type !== "named") continue;
960
- let o = Xe(n);
961
- o && !t.has(o.toLowerCase()) && (i ??= Ze(e), i.has(o.toLowerCase()) || r.includes(o) || r.push(o));
1251
+ let o = Mt(n);
1252
+ o && !t.has(o.toLowerCase()) && (i ??= Nt(e), i.has(o.toLowerCase()) || r.includes(o) || r.push(o));
962
1253
  }
963
1254
  if (a || r.length > 0) return {
964
1255
  broken: !0,
@@ -981,135 +1272,1322 @@ function K(e, t, n) {
981
1272
  error: "#REF!"
982
1273
  };
983
1274
  }
984
- let a = !i || i.isInvalidAny();
1275
+ let a = !i || i.isInvalidAny();
1276
+ return {
1277
+ broken: a,
1278
+ missing: r,
1279
+ error: a ? "#REF!" : ""
1280
+ };
1281
+ }(e, r), n = Tt(e), o = n ? await async function(e, t) {
1282
+ let n = await e.getDirectDependents(), r = 0, i = [], a = /* @__PURE__ */ new Set(), o = [];
1283
+ if (n) {
1284
+ let e = n.getCoords(), s = n.getCount();
1285
+ for (let c = 0; c < s; c++) {
1286
+ let s = n.at(c);
1287
+ if (s.isINamedRange) {
1288
+ let e = s;
1289
+ if (a.has(e.getId())) continue;
1290
+ a.add(e.getId());
1291
+ let n = t.get(e.getId());
1292
+ i.push(n ? Et(n) : e.getName());
1293
+ } else {
1294
+ let t = e[c];
1295
+ r += (t.rowEnd - t.rowStart + 1) * (t.colEnd - t.colStart + 1), o.push(Dt(s));
1296
+ }
1297
+ }
1298
+ }
1299
+ let s = r + i.length;
1300
+ if (s === 0) return {
1301
+ text: "unused",
1302
+ weight: s
1303
+ };
1304
+ let c = [...i, ...o], l = [], u = 0;
1305
+ for (let e = 0; e < c.length; e++) {
1306
+ let t = (l.length > 0 ? 2 : 0) + c[e].length;
1307
+ if (l.length > 0 && u + t > 60) break;
1308
+ l.push(l.length === 0 ? wt(c[e], 60) : c[e]), u += t;
1309
+ }
1310
+ let d = c.length - l.length, f = d > 0 ? `, +${d} more` : "";
1311
+ return {
1312
+ text: `${s} · ${l.join(", ")}${f}`,
1313
+ weight: s
1314
+ };
1315
+ }(n, i) : null;
1316
+ o?.weight === 0 && !e.getScope() && a.has(e.getName().toLowerCase()) && (o = {
1317
+ ...o,
1318
+ text: "unused · shadowed"
1319
+ });
1320
+ let s = e.getComment() ?? "", c = Et(e);
1321
+ return {
1322
+ name: c,
1323
+ refersTo: await Ot(e),
1324
+ dependents: o,
1325
+ hidden: e.isHidden(),
1326
+ comment: wt(s, 60),
1327
+ broken: t.broken,
1328
+ error: t.error,
1329
+ sortKey: c.toLowerCase().replace(/'/g, "")
1330
+ };
1331
+ })), s = (e, t) => {
1332
+ let n = (t.dependents?.weight ?? 0) - (e.dependents?.weight ?? 0);
1333
+ return n === 0 ? e.sortKey.localeCompare(t.sortKey) : n;
1334
+ }, c = [...o.filter((e) => e.broken).sort(s), ...o.filter((e) => !e.broken).sort(s)], l = T(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);
1335
+ e.h2(`${n?.heading ?? "Names"} (${o.length})`);
1336
+ let p = (t, n) => {
1337
+ 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"];
1338
+ n && o.push("Error"), a && o.push("Dependents"), r && o.push("Hidden"), i && o.push("Comment");
1339
+ let s = e.beginFrame(o);
1340
+ for (let e of t) {
1341
+ let t = [{ text: e.name }, { text: e.refersTo }];
1342
+ 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);
1343
+ }
1344
+ s.endFrame();
1345
+ };
1346
+ if (d.length > 0) {
1347
+ let t = c.reduce((e, t) => e + +!!t.broken, 0);
1348
+ e.text(`${t} ${t === 1 ? "does" : "do"} not resolve:`), p(d, !0), e.blank();
1349
+ }
1350
+ if (f.length > 0 && p(f, !1), u.length < o.length) {
1351
+ let t = n?.recovery ?? "getByName('Name') renders one in full";
1352
+ e.text(` …and ${o.length - u.length} more · ${t}`);
1353
+ }
1354
+ e.blank();
1355
+ }
1356
+ function Ft(e, t, n) {
1357
+ let r = n.getCoords().min, i = [], a = 0, o = 0;
1358
+ if (n.forEachSpan((e, t) => {
1359
+ let s = t.getCoords();
1360
+ if (o++, a += s.max - s.min + 1, i.length >= 100) return;
1361
+ let c = n.at(s.min - r).getText(), l = n.at(s.max - r).getText();
1362
+ i.push({
1363
+ address: `${c}:${l}`,
1364
+ count: s.max - s.min + 1
1365
+ });
1366
+ }, {
1367
+ visibility: "hidden",
1368
+ includeEmpty: !0
1369
+ }), a === 0) return;
1370
+ e.h2(`${t} (${a})`);
1371
+ let s = Math.max(...i.map((e) => e.address.length));
1372
+ for (let t of i) e.text(` ${t.address.padEnd(s)} ${t.count}`);
1373
+ o > i.length && e.text(` …and ${o - i.length} more`), e.blank();
1374
+ }
1375
+ function It(e, t, n, r) {
1376
+ if (n.length === 0) return;
1377
+ let i = n.length > 50 ? n.slice(0, 50) : n, a = i.map((e) => ({
1378
+ address: wt(_t(e.getRanges()), 40),
1379
+ rule: r(e)
1380
+ }));
1381
+ e.h2(`${t} (${n.length})`);
1382
+ let o = Math.max(...a.map((e) => e.address.length));
1383
+ for (let t of a) e.text(` ${t.address.padEnd(o)} ${t.rule}`.trimEnd());
1384
+ i.length < n.length && e.text(` …and ${n.length - i.length} more`), e.blank();
1385
+ }
1386
+ function Lt(e, t = !1) {
1387
+ let n = e.getSheet(), r = e.getCoords(), i = n.getName(), a = [];
1388
+ for (let e of n.getNames().getItems({
1389
+ type: "formula",
1390
+ includeHidden: !0
1391
+ }) ?? []) {
1392
+ let n = null;
1393
+ try {
1394
+ n = e.getRanges?.() ?? null;
1395
+ } catch {}
1396
+ n ? n.getCoords().some((e) => {
1397
+ 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);
1398
+ var t, n;
1399
+ }) && a.push(e) : t && e.getScope() === i && a.push(e);
1400
+ }
1401
+ return a;
1402
+ }
1403
+ async function Rt(e, t) {
1404
+ let n = t.getSheet();
1405
+ await Pt(e, Lt(t, !0), { symbols: n.getWorkbook()?.getNames().getItems({ includeHidden: !0 }) ?? n.getNames().getItems({ includeHidden: !0 }) ?? [] });
1406
+ let r = t.getColumnHeaders(), i = t.getRowHeaders();
1407
+ Ft(e, "Hidden Columns", r), Ft(e, "Hidden Rows", i);
1408
+ let a = t.getTables();
1409
+ a.length > 0 && dt(e, a, t.getCounts([H.Table])[H.Table] ?? 0);
1410
+ }
1411
+ var zt = "#REF!", K = (e) => {
1412
+ let t = e.getContent();
1413
+ return t.getType() === "chart" && typeof t.getSeries == "function" ? t : null;
1414
+ }, Bt = (t, n) => `${W(t.getName())}!${e.rangeToString(n) ?? ""}`, Vt = (e, t) => e ? Bt(e.getSheet(), e.getCoords()) : t, q = (e) => e.replace(/\s*[\r\n]+\s*/g, " ⏎ ").trim(), Ht = (e, t) => ({
1415
+ colStart: Math.min(e.colStart, t.colStart),
1416
+ rowStart: Math.min(e.rowStart, t.rowStart),
1417
+ colEnd: Math.max(e.colEnd, t.colEnd),
1418
+ rowEnd: Math.max(e.rowEnd, t.rowEnd)
1419
+ }), Ut = (e) => {
1420
+ if (e.length === 0) return null;
1421
+ let t = e[0], n = t.getValuesRange();
1422
+ if (!n) return null;
1423
+ let r = n.getSheet(), i = n.getCoords(), a = e.length === 1, o = i.colStart === i.colEnd, s = i.rowStart === i.rowEnd;
1424
+ if (!a && !o && !s) return null;
1425
+ let c = o && s ? null : o ? "column" : s ? "row" : null, l = t.getCategoriesFormula(), u = t.getNameRange(), d = t.getNameFormula() !== null;
1426
+ if (d && !u?.isSingleCell()) return null;
1427
+ let f = i, p = u?.getCoords() ?? null;
1428
+ for (let n = 1; n < e.length; n++) {
1429
+ let a = e[n];
1430
+ if (a.getChartType() !== t.getChartType() || a.isSecondaryAxis() !== t.isSecondaryAxis() || a.getCategoriesFormula() !== l) return null;
1431
+ let m = a.getValuesRange();
1432
+ if (!m || m.getSheet() !== r) return null;
1433
+ let h = m.getCoords(), g = h.colStart === f.colStart + 1 && h.colEnd === f.colEnd + 1 && h.rowStart === i.rowStart && h.rowEnd === i.rowEnd, _ = h.rowStart === f.rowStart + 1 && h.rowEnd === f.rowEnd + 1 && h.colStart === i.colStart && h.colEnd === i.colEnd;
1434
+ if (c === null && (c = g && o ? "column" : _ && s ? "row" : null), c === null || (c === "column" ? !g : !_) || (f = h, a.getNameFormula() !== null !== d)) return null;
1435
+ if (d) {
1436
+ let e = a.getNameRange();
1437
+ if (!e?.isSingleCell() || e.getSheet() !== u.getSheet()) return null;
1438
+ let t = e.getCoords();
1439
+ if (!(c === "column" ? t.colStart === p.colStart + 1 && t.rowStart === p.rowStart : t.rowStart === p.rowStart + 1 && t.colStart === p.colStart)) return null;
1440
+ p = t;
1441
+ }
1442
+ }
1443
+ return {
1444
+ values: Bt(r, Ht(i, f)),
1445
+ by: a ? null : c,
1446
+ names: u && p ? Bt(u.getSheet(), Ht(u.getCoords(), p)) : null,
1447
+ categories: Vt(t.getCategoriesRange(), l)
1448
+ };
1449
+ }, Wt = (e) => {
1450
+ let t = [], n = [
1451
+ ["name", e.getNameFormula()],
1452
+ ["values", e.getValuesFormula()],
1453
+ ["categories", e.getCategoriesFormula()]
1454
+ ];
1455
+ for (let [e, r] of n) r?.includes(zt) && t.push(`${e} ${r}`);
1456
+ return t;
1457
+ }, Gt = (e) => {
1458
+ let t = 0;
1459
+ for (let n of e) Wt(n).length > 0 && t++;
1460
+ return t;
1461
+ }, Kt = (e) => {
1462
+ let t = e.getChartType();
1463
+ return t && t !== "unknown" ? t : null;
1464
+ };
1465
+ function qt(e) {
1466
+ let t = [], n = Kt(e);
1467
+ n && t.push(n);
1468
+ let r = e.getChartTitle();
1469
+ var i, a;
1470
+ r && t.push(`"${i = q(r), a = 40, i.length > a ? `${i.slice(0, a - 1)}…` : i}"`);
1471
+ let o = e.getSeries();
1472
+ if (o.length > 0) {
1473
+ t.push(`${o.length} series`);
1474
+ let n = e.getPivotSource(), r = n ? null : Ut(o);
1475
+ n ? t.push(`pivot table ${n}`) : r && (t.push(`values ${r.values}`), r.categories && t.push(`categories ${r.categories}`));
1476
+ let i = Gt(o);
1477
+ i > 0 && t.push(`${zt} in ${i} series`);
1478
+ }
1479
+ return t.length > 0 ? t.join(" · ") : null;
1480
+ }
1481
+ function Jt(e) {
1482
+ let t = [], n = e.getChartTitle();
1483
+ n && t.push(["title", `"${q(n)}"`]);
1484
+ let r = e.getSeries();
1485
+ if (r.length === 0) return t;
1486
+ let i = e.getPivotSource(), a = i ? null : Ut(r);
1487
+ i ? t.push(["series", `${r.length} · from pivot table ${i}`]) : a ? (t.push(["series", `${r.length} · ${a.values}${a.by ? ` by ${a.by}` : ""}`]), a.names && t.push([r.length === 1 ? "name" : "names", a.names]), a.categories && t.push(["categories", a.categories])) : t.push(["series", String(r.length)]);
1488
+ let o = Gt(r);
1489
+ return o > 0 && t.push(["broken", `${zt} in ${o} series`]), t;
1490
+ }
1491
+ var Yt = (e) => Kt(e) ?? "", Xt = (e) => {
1492
+ let t = e.getTitle(), n = [t ? `"${q(t)}"` : "no title"], r = e.getNumberFormat();
1493
+ return r && r !== "General" && n.push(`format ${r}`), `${e.getKind()} (${n.join(", ")})`;
1494
+ };
1495
+ function Zt(e, t) {
1496
+ let n = Kt(t);
1497
+ e.fact("Type: chart" + (n ? ` — ${n}` : ""));
1498
+ let r = t.getChartTitle();
1499
+ e.fact("Title: " + (r ? `"${q(r)}"` : "(none)"));
1500
+ let i = t.getSeries(), a = t.getPivotSource();
1501
+ if (a) e.fact(`Series (${i.length}): from pivot table ${a}`);
1502
+ else if (i.length > 0) {
1503
+ let t = Ut(i);
1504
+ if (t) {
1505
+ let n = [`values ${t.values}${t.by ? ` by ${t.by}` : ""}`];
1506
+ t.names && n.push(`${i.length === 1 ? "name" : "names"} ${t.names}`), t.categories && n.push(`categories ${t.categories}`), e.fact(`Series (${i.length}): ${n.join(" · ")}`);
1507
+ } else (function(e, t) {
1508
+ let n = t.slice(0, T(t.length, 12)), r = n.map((e) => {
1509
+ let t = Vt(e.getValuesRange(), e.getValuesFormula()) ?? "(no values)", n = Vt(e.getCategoriesRange(), e.getCategoriesFormula()), r = [`values ${t}`];
1510
+ n && r.push(`categories ${n}`);
1511
+ let i = Vt(e.getNameRange(), e.getNameFormula());
1512
+ i && r.push(`name ${i}`);
1513
+ let a = e.getName();
1514
+ return {
1515
+ name: a ? q(a) : "(unnamed)",
1516
+ type: e.isSecondaryAxis() ? `${e.getChartType()} · secondary axis` : e.getChartType(),
1517
+ source: r.join(" · ")
1518
+ };
1519
+ });
1520
+ e.fact(`Series (${t.length}):`);
1521
+ let i = Math.max(...r.map((e) => e.name.length)), a = Math.max(...r.map((e) => e.type.length));
1522
+ for (let t of r) e.text(` ${t.name.padEnd(i)} ${t.type.padEnd(a)} ${t.source}`);
1523
+ n.length < t.length && e.text(` …and ${t.length - n.length} more · getContent().getSeries() on this movable lists every one`);
1524
+ })(e, i);
1525
+ }
1526
+ let o = t.getAxes();
1527
+ o.length > 0 && e.fact(`Axes: ${o.map(Xt).join(" · ")}`);
1528
+ }
1529
+ var Qt = (e, t) => e.colStart <= t.colEnd && t.colStart <= e.colEnd && e.rowStart <= t.rowEnd && t.rowStart <= e.rowEnd, $t = (e) => {
1530
+ let t = e.movable.getRange();
1531
+ return `${Bt(t.getSheet(), t.getCoords())} "${e.movable.getName() || "(unnamed)"}"${e.direct ? "" : " (through its dependents)"}`;
1532
+ }, en = (e, t) => e.length > t ? `${e.slice(0, t - 1)}…` : e, tn = (e) => e.replace(/[\r\n]+/g, " ").trim(), nn = (e) => e.getShapeType?.() ?? "", rn = (t) => {
1533
+ let n = t.getRange();
1534
+ return e.rangeToString(n.getCoords()) ?? n.toString();
1535
+ }, an = (e, t, n) => {
1536
+ let r = e.replace(/\r\n?|\n/g, " ⏎ ");
1537
+ if (t === null || r.length <= t) return `"${r}"`;
1538
+ let i = r.charCodeAt(t - 1), a = i >= 55296 && i <= 56319 ? t - 1 : t;
1539
+ return `"${r.slice(0, a)}…" (+${r.length - a} chars) · full: ${n}`;
1540
+ }, on = ({ movable: e, text: t }) => an(t, 300, ((e) => `${G(e.getRange())}.getRange(${JSON.stringify(rn(e))}).getMovables()`)(e)), sn = (e) => {
1541
+ let t = e.getContent();
1542
+ return typeof t.getTextFrame == "function" ? t.getTextFrame()?.getText() ?? "" : null;
1543
+ };
1544
+ function cn(e) {
1545
+ let t = [];
1546
+ for (let n of e) {
1547
+ let e = sn(n) ?? "";
1548
+ e.trim() !== "" && t.push({
1549
+ movable: n,
1550
+ text: e
1551
+ });
1552
+ }
1553
+ return t.sort((e, t) => {
1554
+ let n = e.movable.getRange().getCoords(), r = t.movable.getRange().getCoords();
1555
+ return n.rowStart - r.rowStart || n.colStart - r.colStart;
1556
+ });
1557
+ }
1558
+ var ln = (e) => e.getType() === "picture" && e.getResource?.()?.getName() || null, un = (e) => {
1559
+ let t = e.getName() || "(unnamed)", n = e.getDescription(), r = K(e);
1560
+ if (r) return en([
1561
+ qt(r),
1562
+ n ? tn(n) : null,
1563
+ t
1564
+ ].filter(Boolean).join(" · "), 140);
1565
+ let i = e.getContent(), a = [], o = ln(i);
1566
+ return o && a.push(o), n && a.push(tn(n)), en(a.length > 0 ? `${t} — ${a.join(" · ")}` : t, 90);
1567
+ }, dn = (e) => {
1568
+ let t = e.getName() || "(unnamed)", n = e.getDescription();
1569
+ return en(n ? `${t} — ${tn(n)}` : t, 90);
1570
+ }, fn = /* @__PURE__ */ new Map([
1571
+ ["chart", "Charts"],
1572
+ ["shape", "Shapes"],
1573
+ ["picture", "Pictures"],
1574
+ ["slicer", "Slicers"]
1575
+ ]), pn = (e) => fn.get(e) ?? `${e.charAt(0).toUpperCase()}${e.slice(1)}s`;
1576
+ function mn(e) {
1577
+ let t = /* @__PURE__ */ new Map();
1578
+ for (let n of e) {
1579
+ let e = n.getContent().getType(), r = t.get(e);
1580
+ r ? r.push(n) : t.set(e, [n]);
1581
+ }
1582
+ let n = /* @__PURE__ */ new Map();
1583
+ for (let e of fn.keys()) {
1584
+ let r = t.get(e);
1585
+ r && n.set(e, r);
1586
+ }
1587
+ for (let [e, r] of t) n.set(e, r);
1588
+ return n;
1589
+ }
1590
+ function hn(e, t) {
1591
+ for (let [n, r] of mn(t)) gn(e, n, r);
1592
+ }
1593
+ function gn(e, t, n) {
1594
+ let r = cn(n), i = new Map(r.map((e) => [e.movable, e])), a = [...r.map((e) => e.movable), ...n.filter((e) => !i.has(e))], o = a.slice(0, T(a.length, 50)), s = o.map((e) => {
1595
+ let t = i.get(e), n = K(e);
1596
+ return {
1597
+ address: rn(e),
1598
+ preset: n ? Yt(n) : nn(e.getContent()),
1599
+ summary: n ? dn(e) : un(e),
1600
+ details: n ? Jt(n) : [],
1601
+ text: t ? on(t) : "",
1602
+ hidden: e.isHidden() ? " (hidden)" : ""
1603
+ };
1604
+ });
1605
+ e.h2(`${pn(t)} (${n.length}${r.length > 0 ? ` · ${r.length} with text` : ""})`);
1606
+ let c = Math.max(...s.map((e) => e.address.length)), l = Math.max(...s.map((e) => e.preset.length)), u = Math.min(40, Math.max(0, ...s.filter((e) => e.text).map((e) => e.summary.length)));
1607
+ for (let t of s) {
1608
+ let n = l > 0 ? `${t.preset.padEnd(l)} ` : "", r = t.text ? `${t.summary.padEnd(u)} ${t.text}` : t.summary;
1609
+ e.text(` ${t.address.padEnd(c)} ${n}${r}${t.hidden}`.trimEnd());
1610
+ let i = Math.max(10, ...t.details.map(([e]) => e.length + 2));
1611
+ for (let [n, r] of t.details) e.text(` ${n.padEnd(i)}${r}`);
1612
+ }
1613
+ if (o.length < a.length) {
1614
+ let r = `${G(n[0].getRange())}.getMovables().getItems({ type: ${JSON.stringify(t)} })`;
1615
+ e.text(` …and ${a.length - o.length} more · ${r} reports every one in full`);
1616
+ }
1617
+ e.blank();
1618
+ }
1619
+ function _n(e) {
1620
+ let t = new V(), r = e.getRange(), i = e.getContent(), a = i.getType();
1621
+ t.h1(`Movable — ${yt(r)}`), t.blank(), t.fact(`Name: ${e.getName() || "(unnamed)"}`);
1622
+ let o = K(e);
1623
+ o ? Zt(t, o) : t.fact(`Type: ${a}`);
1624
+ let s = ln(i);
1625
+ s && t.fact(`Content: ${s}`);
1626
+ let c = nn(i);
1627
+ c && t.fact(`Shape: ${c}`);
1628
+ let l = i.getTextFrame?.();
1629
+ l && t.fact(`Text: ${an(l.getText(), null, "")}`);
1630
+ let u = e.getDescription();
1631
+ u && t.fact(`Alt Text: ${tn(u)}`), t.fact(`Anchor: ${U(r)}, ${((e) => {
1632
+ switch (e) {
1633
+ case n.Type.Absolute: return "absolute — stays put when rows or columns move";
1634
+ case n.Type.OneCell: return "oneCell — moves with the cells, keeps its size";
1635
+ default: return "twoCell — moves and resizes with the cells";
1636
+ }
1637
+ })(e.getAnchorType?.())}`), t.fact(`Bounds: ${((e) => {
1638
+ let t = e.getBounds();
1639
+ if (!t) return "not laid out";
1640
+ let n = (e) => Math.round(e);
1641
+ return `${n(t.width)}×${n(t.height)} px at (${n(t.x)}, ${n(t.y)})`;
1642
+ })(e)}`), e.isHidden() && t.fact("Hidden: true — this object is not visible in the UI");
1643
+ let d = e.getRotation();
1644
+ return d !== 0 && t.fact(`Rotation: ${d}°`), t.fact(`Z-Order: ${e.getZIndex()}`), t.blank(), t.text(`Sheet: ${W(r.getSheet().getName())}`), t.toLines().join("\n").trimEnd();
1645
+ }
1646
+ var vn = (e) => e.getVisibility() === "visible", yn = (e, t, n) => {
1647
+ let r = e.getSheets().getItems({ visibility: "veryHidden" }), i = t?.trim();
1648
+ if (!i) return r.filter((e) => n || vn(e)).map((e) => ({
1649
+ sheet: e,
1650
+ address: null
1651
+ }));
1652
+ let a = /^'(.*)'!(.+)$/.exec(i) ?? /^([^!]+)!(.+)$/.exec(i);
1653
+ if (a) {
1654
+ let [, e, t] = a, n = r.find((t) => t.getName() === e);
1655
+ if (!n) throw Error(`Sheet not found: ${e}`);
1656
+ return [{
1657
+ sheet: n,
1658
+ address: t
1659
+ }];
1660
+ }
1661
+ let o = r.find((e) => e.getName() === i);
1662
+ if (o) return [{
1663
+ sheet: o,
1664
+ address: null
1665
+ }];
1666
+ if (/[*?]/.test(i)) {
1667
+ let e = ((e) => {
1668
+ let t = e.replace(/[.*+?^${}()|[\]\\]/g, (e) => e === "*" ? ".*" : e === "?" ? "." : `\\${e}`);
1669
+ return RegExp(`^${t}$`);
1670
+ })(i), t = r.filter((t) => e.test(t.getName()) && (n || vn(t)));
1671
+ if (t.length === 0) throw Error(`No sheets match ${JSON.stringify(i)}. Sheets: ${r.map((e) => e.getName()).join(", ")}`);
1672
+ return t.map((e) => ({
1673
+ sheet: e,
1674
+ address: null
1675
+ }));
1676
+ }
1677
+ let s = r.filter((e) => n || vn(e));
1678
+ try {
1679
+ s[0]?.getRange(i);
1680
+ } catch {
1681
+ throw Error(`Unknown scope ${JSON.stringify(i)}: not a sheet name or a range. Sheets: ${r.map((e) => e.getName()).join(", ")}`);
1682
+ }
1683
+ return s.map((e) => ({
1684
+ sheet: e,
1685
+ address: i
1686
+ }));
1687
+ }, bn = (e, t) => {
1688
+ switch (t) {
1689
+ case "display": return b(e, _.Mode.Display);
1690
+ case "value": return b(e, _.Mode.Value);
1691
+ case "raw": return x(e.getValue());
1692
+ case "formula": {
1693
+ let t = e.getFormulaText();
1694
+ return t ? {
1695
+ match: t,
1696
+ display: t
1697
+ } : null;
1698
+ }
1699
+ case "hyperlink": {
1700
+ let t = e.getHyperlink()?.getAddress() ?? null;
1701
+ return t ? {
1702
+ match: t,
1703
+ display: t
1704
+ } : null;
1705
+ }
1706
+ case "numberFormat": {
1707
+ let t = e.getStyle().getNumberFormat();
1708
+ return t && t !== "General" ? {
1709
+ match: t,
1710
+ display: t
1711
+ } : null;
1712
+ }
1713
+ default: return null;
1714
+ }
1715
+ }, xn = ["hyperlink", "numberFormat"], J = (e, t) => t && t.trim() !== "" ? [{
1716
+ field: e,
1717
+ text: {
1718
+ match: t,
1719
+ display: t
1720
+ }
1721
+ }] : [], Sn = (e) => [...J("comment", e.getContent()), ...e.getReplies().flatMap((e) => J("comment", e.getContent()))], Cn = (e, t) => {
1722
+ let n = K(e);
1723
+ if (n) return t.includes("chart") ? [
1724
+ ...J("chart", n.getChartTitle()),
1725
+ ...n.getAxes().flatMap((e) => J("chart", e.getTitle())),
1726
+ ...n.getSeries().flatMap((e) => e.getNameFormula() === null ? J("chart", e.getName()) : []),
1727
+ ...J("chart", e.getDescription())
1728
+ ] : [];
1729
+ let r = sn(e);
1730
+ return r !== null && t.includes("shape") ? [...J("shape", r), ...J("shape", e.getDescription())] : [];
1731
+ }, wn = (e) => {
1732
+ let t = e.isIFormula ? `=${e.getExpression()}` : null, n = t ?? e.getRanges?.()?.getAddress() ?? e.getName();
1733
+ return [
1734
+ {
1735
+ field: "name",
1736
+ text: {
1737
+ match: e.getName(),
1738
+ display: n
1739
+ }
1740
+ },
1741
+ ...t ? J("name", t) : [],
1742
+ ...J("name", e.getComment())
1743
+ ];
1744
+ }, Tn = (e, t) => e.colStart <= t.colEnd && t.colStart <= e.colEnd && e.rowStart <= t.rowEnd && t.rowStart <= e.rowEnd, En = (e, t) => {
1745
+ let n = e.getRanges?.() ?? null;
1746
+ return t.some(({ sheet: t, address: r }) => {
1747
+ if (r === null && e.getScope() === t.getName()) return !0;
1748
+ let i = r === null ? null : t.getRange(r).getCoords();
1749
+ for (let e = 0; e < (n?.length ?? 0); e++) {
1750
+ let r = n.at(e);
1751
+ if (r.getSheet() === t && (!i || Tn(r.getCoords(), i))) return !0;
1752
+ }
1753
+ return !1;
1754
+ });
1755
+ }, Dn = (e, t) => e.rowStart - t.rowStart || e.colStart - t.colStart, On = (e, t, n) => {
1756
+ let r = null, i = (e) => ({
1757
+ range: `${t}!${e.getRange().toString()}`,
1758
+ table: e.getName()
1759
+ });
1760
+ return { resolve(a, o) {
1761
+ let s = ((e) => e.getTable())(a);
1762
+ if (e === "table") return s ? i(s) : void 0;
1763
+ if (r === null) {
1764
+ r = [];
1765
+ for (let e of n.getRegions()) {
1766
+ let n = e.getCoords();
1767
+ n.rowStart === n.rowEnd && n.colStart === n.colEnd || r.push({
1768
+ coords: n,
1769
+ address: `${t}!${e.toString()}`
1770
+ });
1771
+ }
1772
+ }
1773
+ let c = r.find(({ coords: e }) => o.rowIndex >= e.rowStart && o.rowIndex <= e.rowEnd && o.colIndex >= e.colStart && o.colIndex <= e.colEnd);
1774
+ return c ? {
1775
+ range: c.address,
1776
+ ...s ? { table: s.getName() } : {}
1777
+ } : s ? i(s) : void 0;
1778
+ } };
1779
+ };
1780
+ async function kn(t, n) {
1781
+ if (!n.pattern) throw Error("grep requires a pattern");
1782
+ let r = n.fields?.length ? n.fields : w, i = n.output ?? "content", a = n.maxCount ?? 200, o = !0 === n.invert, s = !0 === n.hidden, c = ((e) => {
1783
+ if (e === void 0 || !1 === e) return null;
1784
+ if (!0 === e) return "contentful";
1785
+ if (e === "contentful" || e === "table") return e;
1786
+ 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.`);
1787
+ })(n.context), l = ((e) => {
1788
+ let t = e.fixedStrings ? ((e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))(e.pattern) : e.pattern;
1789
+ e.word && (t = `(?<!\\w)(?:${t})(?!\\w)`);
1790
+ let n = e.ignoreCase ? "iu" : "u";
1791
+ try {
1792
+ return new RegExp(t, n);
1793
+ } catch {
1794
+ try {
1795
+ return new RegExp(t, n.replace("u", ""));
1796
+ } catch (t) {
1797
+ throw Error(`Invalid regex ${JSON.stringify(e.pattern)}: ${t instanceof Error ? t.message : String(t)}. Use fixedStrings (-F) to search for the literal text.`);
1798
+ }
1799
+ }
1800
+ })(n), u = yn(t, n.scope, s), d = !r.some((e) => xn.includes(e)), f = r.includes("display") && r.includes("value"), p = i === "content" || i === "addresses", m = [], h = [], g = 0, _ = 0, v = 0, y = !1, b = (e) => {
1801
+ let t = e.filter((t, n) => l.test(t.text.match) && e.findIndex((e) => e.field === t.field && e.text.display === t.text.display && l.test(e.text.match)) === n);
1802
+ return o ? t.length === 0 && e.length > 0 ? [e[0]] : null : t.length === 0 ? null : i === "addresses" ? t.slice(0, 1) : t;
1803
+ }, x = (e, t, n, r, i) => {
1804
+ if (a > 0 && g + _ >= a) return y = !0, !1;
1805
+ if (e === "cell" ? g++ : _++, p) for (let e of r) m.push({
1806
+ sheet: t,
1807
+ address: n,
1808
+ field: e.field,
1809
+ text: e.text.display,
1810
+ ...i ? { context: i } : {}
1811
+ });
1812
+ return !0;
1813
+ };
1814
+ for (let { sheet: t, address: n } of u) {
1815
+ if (y) continue;
1816
+ let a = t.getName();
1817
+ v++, await t.getCalculation().ready();
1818
+ let o = n === null ? t.getUsedRange() : t.getRange(n), l = o && c && i === "content" ? On(c, a, o) : null, u = {
1819
+ ...n === null ? {} : { address: n },
1820
+ ...s ? {} : { ignoreHidden: !0 }
1821
+ }, p = /* @__PURE__ */ new Map();
1822
+ if (r.includes("comment")) for (let e of t.getComments().getItems(u)) {
1823
+ let t = e.getRange().getCoords();
1824
+ p.set(`${t.rowStart}:${t.colStart}`, e);
1825
+ }
1826
+ let m = 0;
1827
+ o?.forEach((e, t) => {
1828
+ if (d && e == null) return;
1829
+ let n = t.getCell(), i = t.getCoords(), o = [], s;
1830
+ for (let e of r) {
1831
+ if (e === "comment") {
1832
+ let e = `${i.rowIndex}:${i.colIndex}`, t = p.get(e);
1833
+ t && (o.push(...Sn(t)), p.delete(e));
1834
+ continue;
1835
+ }
1836
+ let t = bn(n, e);
1837
+ e === "display" && (s = t?.match ?? null), t !== null && (e === "value" && f && (s === void 0 && (s = bn(n, "display")?.match ?? null), t.match === s) || o.push({
1838
+ field: e,
1839
+ text: t
1840
+ }));
1841
+ }
1842
+ let c = b(o);
1843
+ if (!c) return;
1844
+ let u = l?.resolve(n, i);
1845
+ if (!x("cell", a, t.getAddress(), c, u)) return { break: !0 };
1846
+ m++;
1847
+ }, s ? void 0 : { ignoreHidden: !0 });
1848
+ let g = [...p.values()].map((e) => ({
1849
+ comment: e,
1850
+ at: e.getRange().getCoords()
1851
+ })).sort((e, t) => Dn(e.at, t.at));
1852
+ for (let { comment: t, at: n } of g) {
1853
+ if (y) break;
1854
+ let r = b(Sn(t));
1855
+ if (!r) continue;
1856
+ let i = l?.resolve(t.getRange().getCell(), {
1857
+ rowIndex: n.rowStart,
1858
+ colIndex: n.colStart
1859
+ });
1860
+ x("cell", a, e.rangeToString(n) ?? t.getRange().toString(), r, i) && m++;
1861
+ }
1862
+ let _ = 0;
1863
+ if (!y && (r.includes("shape") || r.includes("chart"))) {
1864
+ let n = t.getMovables().getItems(u).filter((e) => s || !e.isHidden()).map((e) => ({
1865
+ movable: e,
1866
+ at: e.getRange().getCoords()
1867
+ })).sort((e, t) => Dn(e.at, t.at));
1868
+ for (let { movable: t, at: i } of n) {
1869
+ let n = b(Cn(t, r));
1870
+ if (n) {
1871
+ if (!x("object", a, e.rangeToString(i) ?? t.getRange().toString(), n)) break;
1872
+ _++;
1873
+ }
1874
+ }
1875
+ }
1876
+ (m > 0 || _ > 0) && h.push({
1877
+ sheet: a,
1878
+ cells: m,
1879
+ objects: _
1880
+ });
1881
+ }
1882
+ if (!y && r.includes("name")) {
1883
+ let e = !!n.scope?.trim(), r = t.getNames().getItems(s ? { includeHidden: !0 } : void 0) ?? [];
1884
+ for (let t of r) {
1885
+ if (e && !En(t, u)) continue;
1886
+ let n = b(wn(t));
1887
+ if (n && !x("object", t.getScope() ?? "", t.getName(), n)) break;
1888
+ }
1889
+ }
1890
+ return {
1891
+ pattern: n.pattern,
1892
+ fields: r,
1893
+ scope: n.scope?.trim() || "workbook",
1894
+ matches: m,
1895
+ cellCount: g,
1896
+ objectCount: _,
1897
+ sheets: h,
1898
+ sheetsSearched: v,
1899
+ sheetsMatched: h.length,
1900
+ truncated: y,
1901
+ output: i
1902
+ };
1903
+ }
1904
+ var An = (e) => {
1905
+ let t = e.replace(/\s+/g, " ").trim();
1906
+ return t.length > 120 ? `${t.slice(0, 119)}…` : t;
1907
+ }, jn = (e) => e.sheet ? `${e.sheet}!${e.address}` : e.address, Mn = (e, t) => `${e} ${t}${e === 1 ? "" : "s"}`, Nn = (e, t) => t > 0 ? `${Mn(e, "cell")} · ${Mn(t, "object")}` : Mn(e, "cell"), Pn = (e, t, n, r) => {
1908
+ let i = t.map((e) => r ? jn(e) : e.address), a = Math.max(...i.map((e) => e.length)), o = Math.max(...t.map((e) => e.field.length));
1909
+ for (let r = 0; r < t.length; r++) {
1910
+ let s = t[r];
1911
+ e.push(`${n}${i[r].padEnd(a)} ${s.field.padEnd(o)} ${An(s.text)}`);
1912
+ }
1913
+ };
1914
+ function Fn(e) {
1915
+ let { pattern: t, fields: n, scope: r, matches: i, cellCount: a, objectCount: o, sheetsSearched: s, sheetsMatched: c } = e, l = [`grep "${t}" · ${r} · fields ${n.join(",")} · ${Nn(a, o)} in ${c} of ${s} ${s === 1 ? "sheet" : "sheets"}`];
1916
+ if (e.output === "count") {
1917
+ for (let t of e.sheets) l.push(` ${t.sheet}: ${t.objects > 0 ? Nn(t.cells, t.objects) : t.cells}`);
1918
+ let t = o - e.sheets.reduce((e, t) => e + t.objects, 0);
1919
+ t > 0 && l.push(` names: ${t}`);
1920
+ } else if (e.output === "sheets") {
1921
+ for (let t of e.sheets) l.push(` ${t.sheet}`);
1922
+ e.sheets.length === 0 && l.push(o > 0 ? " no sheets · names only" : " no matches");
1923
+ } else if (i.length === 0) l.push(" no matches");
1924
+ else if (e.output === "addresses") for (let e of i) l.push(` ${jn(e)}`);
1925
+ else {
1926
+ let e = [], t = /* @__PURE__ */ new Map();
1927
+ for (let n of i) {
1928
+ let r = n.context?.range ?? "", i = t.get(r);
1929
+ i || (i = {
1930
+ key: r,
1931
+ heading: n.context ? n.context.table ? `${n.context.range} · ${n.context.table}` : n.context.range : null,
1932
+ rows: []
1933
+ }, t.set(r, i), e.push(i)), i.rows.push(n);
1934
+ }
1935
+ for (let t of e) t.heading ? (l.push(` ${t.heading}`), Pn(l, t.rows, " ", !1)) : Pn(l, t.rows, " ", !0);
1936
+ }
1937
+ return e.truncated && l.push(` …truncated at ${Nn(a, o)} · narrow the pattern, or scope the search to one sheet or range`), l.join("\n");
1938
+ }
1939
+ var In = {
1940
+ name: "grep",
1941
+ description: "Search a workbook's text by pattern: cell contents, and the text that is in no cell — comments, shapes, charts and defined names. Returns grid-anchored matches, each tagged with the layer it matched. Selection by attribute (fills, formats, features) is the regions read, not grep.",
1942
+ params: [
1943
+ {
1944
+ name: "pattern",
1945
+ type: "string",
1946
+ description: "The regular expression to search for (literal with fixedStrings).",
1947
+ required: !0,
1948
+ positional: 0
1949
+ },
1950
+ {
1951
+ name: "fields",
1952
+ type: "enum[]",
1953
+ values: C,
1954
+ defaultValue: w,
1955
+ description: "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%\"), comment (comments, notes and replies), shape (text on a shape, alt text), chart (title, axis titles, literal series names, alt text), name (defined names and tables: the name, what it refers to, its comment)."
1956
+ },
1957
+ {
1958
+ name: "fixedStrings",
1959
+ type: "boolean",
1960
+ alias: "F",
1961
+ defaultValue: !1,
1962
+ description: "Treat the pattern as a literal string, not a regular expression."
1963
+ },
1964
+ {
1965
+ name: "ignoreCase",
1966
+ type: "boolean",
1967
+ alias: "i",
1968
+ defaultValue: !1,
1969
+ description: "Case-insensitive matching."
1970
+ },
1971
+ {
1972
+ name: "word",
1973
+ type: "boolean",
1974
+ alias: "w",
1975
+ defaultValue: !1,
1976
+ description: "Require the match to fall on word boundaries (text edges count as edges)."
1977
+ },
1978
+ {
1979
+ name: "invert",
1980
+ type: "boolean",
1981
+ alias: "v",
1982
+ defaultValue: !1,
1983
+ description: "Report cells and objects where no requested field matched. Only those with text in a requested field are considered — blanks are not findings."
1984
+ },
1985
+ {
1986
+ name: "scope",
1987
+ type: "string",
1988
+ 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."
1989
+ },
1990
+ {
1991
+ name: "hidden",
1992
+ type: "boolean",
1993
+ defaultValue: !1,
1994
+ description: "Search hidden rows, columns and sheets, which are excluded by default. Naming a hidden sheet in scope always searches it."
1995
+ },
1996
+ {
1997
+ name: "context",
1998
+ type: "enum",
1999
+ values: ["contentful", "table"],
2000
+ alias: "C",
2001
+ valueOptional: !0,
2002
+ 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."
2003
+ },
2004
+ {
2005
+ name: "maxCount",
2006
+ type: "number",
2007
+ alias: "m",
2008
+ defaultValue: 200,
2009
+ description: "Stop after this many matching cells and objects (0 = unlimited). Truncation is always reported, and only when a further match actually exists."
2010
+ },
2011
+ {
2012
+ name: "output",
2013
+ type: "enum",
2014
+ values: [
2015
+ "content",
2016
+ "addresses",
2017
+ "count",
2018
+ "sheets"
2019
+ ],
2020
+ defaultValue: "content",
2021
+ description: "What to return: content (address, layer and text), addresses (one per matched cell), count (per sheet), or sheets (names with a match)."
2022
+ }
2023
+ ],
2024
+ run: kn,
2025
+ render: Fn
2026
+ }, Ln = [
2027
+ "IWorkbook",
2028
+ "ISheet",
2029
+ "ICellRange",
2030
+ "ICell",
2031
+ "IRange",
2032
+ "ITable",
2033
+ "IStyle",
2034
+ "IScript.ScriptContext"
2035
+ ], Rn = (e) => e.slice(e.lastIndexOf(".") + 1);
2036
+ function zn(e, t) {
2037
+ if (e.types[t]) return t;
2038
+ let n = Object.keys(e.types), r = t.toLowerCase(), i = n.filter((e) => e.toLowerCase() === r);
2039
+ if (i.length === 1) return i[0];
2040
+ if (t.includes(".")) return null;
2041
+ let a = n.filter((e) => Rn(e).toLowerCase() === r);
2042
+ return a.length === 1 ? a[0] : null;
2043
+ }
2044
+ function Bn(e, t, n) {
2045
+ let r = n.replace(/<[\s\S]*$/, "").trim(), i = t.split(".");
2046
+ for (let t = i.length - 1; t >= 0; t--) {
2047
+ let n = [...i.slice(0, t), r].join(".");
2048
+ if (e.types[n]) return n;
2049
+ }
2050
+ return null;
2051
+ }
2052
+ function Vn(e, t, n, r = /* @__PURE__ */ new Set()) {
2053
+ if (r.has(t)) return null;
2054
+ r.add(t);
2055
+ let i = e.types[t];
2056
+ if (!i) return null;
2057
+ let a = (i.members ?? []).filter(n);
2058
+ if (a.length > 0) return {
2059
+ key: t,
2060
+ members: a
2061
+ };
2062
+ for (let a of i.extends ?? []) {
2063
+ let i = Bn(e, t, a), o = i ? Vn(e, i, n, r) : null;
2064
+ if (o) return o;
2065
+ }
2066
+ return null;
2067
+ }
2068
+ function Hn(e, t, n) {
2069
+ let r = e.types[t], i = (r.extends ?? []).map((n) => {
2070
+ let r = Bn(e, t, n);
2071
+ return {
2072
+ text: n,
2073
+ key: r,
2074
+ memberCount: r ? e.types[r].members?.length ?? 0 : 0
2075
+ };
2076
+ }), a = r.members ?? [], o = n?.toLowerCase();
2077
+ return {
2078
+ kind: "type",
2079
+ key: t,
2080
+ entry: r,
2081
+ bases: i,
2082
+ members: o ? a.filter((e) => e.name.toLowerCase().includes(o)) : a,
2083
+ ...n ? { filter: n } : {}
2084
+ };
2085
+ }
2086
+ function Un(e, t, n) {
2087
+ let r = (e) => {
2088
+ let r = t(e).toLowerCase();
2089
+ return r === n ? 0 : r.startsWith(n) ? 1 : 2;
2090
+ };
2091
+ return e.map((e, t) => ({
2092
+ item: e,
2093
+ order: t,
2094
+ score: r(e)
2095
+ })).sort((e, t) => e.score - t.score || e.order - t.order).map((e) => e.item);
2096
+ }
2097
+ function Wn(e, t) {
2098
+ let n = function(e) {
2099
+ return e.trim().replace(/^SheetXL\./, "").replace(/\(\)$/, "").replace(/#/g, ".");
2100
+ }(t ?? "");
2101
+ if (!n) {
2102
+ let t = Ln.filter((t) => e.types[t]).map((t) => ({
2103
+ key: t,
2104
+ entry: e.types[t]
2105
+ }));
2106
+ return {
2107
+ kind: "overview",
2108
+ total: Object.keys(e.types).length,
2109
+ entryPoints: t
2110
+ };
2111
+ }
2112
+ let r = zn(e, n);
2113
+ if (r) return Hn(e, r);
2114
+ let i = n.lastIndexOf(".");
2115
+ if (i > 0) {
2116
+ let t = zn(e, n.slice(0, i)), r = n.slice(i + 1);
2117
+ if (t && r) {
2118
+ let n = r.toLowerCase(), i = Vn(e, t, (e) => e.name === r) ?? Vn(e, t, (e) => e.name.toLowerCase() === n);
2119
+ if (i) return {
2120
+ kind: "member",
2121
+ key: t,
2122
+ declaredOn: i.key,
2123
+ members: i.members
2124
+ };
2125
+ let a = Hn(e, t, r);
2126
+ if (a.members.length > 0) return a;
2127
+ }
2128
+ }
2129
+ return function(e, t) {
2130
+ let n = t.toLowerCase(), r = [], i = [];
2131
+ for (let [t, a] of Object.entries(e.types)) {
2132
+ Rn(t).toLowerCase().includes(n) && r.push(t);
2133
+ for (let e of a.members ?? []) e.name.toLowerCase().includes(n) && i.push({
2134
+ key: t,
2135
+ member: e
2136
+ });
2137
+ }
2138
+ let a = Un(r, Rn, n), o = Un(i, (e) => e.member.name, n);
2139
+ return {
2140
+ kind: "search",
2141
+ query: t,
2142
+ types: a.slice(0, 20),
2143
+ members: o.slice(0, 40),
2144
+ omitted: Math.max(0, a.length - 20) + Math.max(0, o.length - 40)
2145
+ };
2146
+ }(e, i > 0 ? n.slice(i + 1) : n);
2147
+ }
2148
+ function Gn(e, t) {
2149
+ if (!t || typeof t != "object" && typeof t != "function") return null;
2150
+ let n = [], r = /* @__PURE__ */ new Set();
2151
+ for (let i = t; i && i !== Object.prototype; i = Object.getPrototypeOf(i)) for (let a of Object.getOwnPropertyNames(i)) {
2152
+ if (r.has(a) || !/^isI[A-Z]/.test(a)) continue;
2153
+ r.add(a);
2154
+ let i = !1;
2155
+ try {
2156
+ i = !0 === t[a];
2157
+ } catch {}
2158
+ let o = i ? zn(e, a.slice(2)) : null;
2159
+ o && !n.includes(o) && n.push(o);
2160
+ }
2161
+ if (n.length <= 1) return n[0] ?? null;
2162
+ let i = (t, n = /* @__PURE__ */ new Set()) => {
2163
+ for (let r of e.types[t].extends ?? []) {
2164
+ let a = Bn(e, t, r);
2165
+ a && !n.has(a) && (n.add(a), i(a, n));
2166
+ }
2167
+ return n;
2168
+ }, a = /* @__PURE__ */ new Set();
2169
+ for (let e of n) for (let t of i(e)) a.add(t);
2170
+ return n.filter((e) => !a.has(e)).sort((t, n) => (e.types[n].members?.length ?? 0) - (e.types[t].members?.length ?? 0))[0] ?? n[0];
2171
+ }
2172
+ function Kn(e, t) {
2173
+ let n = /\bon type '(?:SheetXL\.)?([A-Z][\w$]*(?:\.[A-Z][\w$]*)*)'/.exec(e)?.[1];
2174
+ return n ? `\`${t} ${n}\` lists its members.` : null;
2175
+ }
2176
+ var qn = [{
2177
+ match: /^(get|set)?(number)?(format|numfmt)s?$/i,
2178
+ relies: ["IStyle", "setNumberFormat"],
2179
+ hint: "Formatting lives on the style: `getStyle().setNumberFormat('0.00%')`, `getStyle().getNumberFormat()`."
2180
+ }];
2181
+ function Jn(e, t) {
2182
+ let n = [], r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = (t) => {
2183
+ if (i.has(t)) return;
2184
+ i.add(t);
2185
+ let o = e.types[t];
2186
+ if (o) {
2187
+ for (let e of o.members ?? []) r.has(e.name) || (r.add(e.name), n.push(e));
2188
+ for (let n of o.extends ?? []) {
2189
+ let r = Bn(e, t, n);
2190
+ r && a(r);
2191
+ }
2192
+ }
2193
+ };
2194
+ return a(t), n;
2195
+ }
2196
+ function Yn(e, t) {
2197
+ let n = e.toLowerCase(), r = t.toLowerCase();
2198
+ if (n === r) return 0;
2199
+ if (n.startsWith(r) || r.startsWith(n)) return 1;
2200
+ let i = function(e, t) {
2201
+ let n = Array.from({ length: t.length + 1 }, (e, t) => t);
2202
+ for (let r = 1; r <= e.length; r++) {
2203
+ let i = n[0];
2204
+ n[0] = r;
2205
+ for (let a = 1; a <= t.length; a++) {
2206
+ let o = n[a];
2207
+ n[a] = Math.min(n[a] + 1, n[a - 1] + 1, i + (e[r - 1] === t[a - 1] ? 0 : 1)), i = o;
2208
+ }
2209
+ }
2210
+ return n[t.length];
2211
+ }(n, r);
2212
+ return i <= Math.max(2, Math.floor(.3 * n.length)) ? 1 + i : null;
2213
+ }
2214
+ var Xn = (e, t) => `${t ? `${t}.` : ""}${e.signature.replace(/;$/, "")}${e.summary ? ` — ${e.summary}` : ""}`;
2215
+ function Zn(e, t, n) {
2216
+ let r = /Property '([\w$]+)' does not exist on type '(?:SheetXL\.)?([A-Z][\w$]*(?:\.[A-Z][\w$]*)*)'/.exec(t), i = r ? null : /(?:^|[.\s])([A-Za-z_$][\w$]*) is not a function/.exec(t), a = r?.[1] ?? i?.[1];
2217
+ if (!a) return null;
2218
+ let o = [];
2219
+ for (let t of qn) {
2220
+ let [n, r] = t.relies;
2221
+ t.match.test(a) && e.types[n]?.members?.some((e) => e.name === r) && o.push(t.hint);
2222
+ }
2223
+ let s = r ? zn(e, r[2]) : null;
2224
+ if (s) {
2225
+ let r = Jn(e, s), i = /Did you mean '([\w$]+)'/.exec(t)?.[1], c = r.map((e) => ({
2226
+ member: e,
2227
+ score: e.name === i ? -1 : Yn(a, e.name)
2228
+ })).filter((e) => e.score !== null).sort((e, t) => e.score - t.score).slice(0, 3);
2229
+ if (c.length > 0) {
2230
+ o.push(`Closest on ${s}:`);
2231
+ for (let { member: e } of c) o.push(` ${Xn(e)}`);
2232
+ }
2233
+ o.push(`\`${n} ${s}\` lists all ${r.length} members.`);
2234
+ } else if (i) {
2235
+ let t = Object.entries(e.types).filter(([, e]) => e.members?.some((e) => e.name === a)).map(([e]) => e);
2236
+ if (t.length > 0) {
2237
+ let e = t.slice(0, 3).join(", "), n = t.length > 3 ? ` and ${t.length - 3} more` : "";
2238
+ return o.push(`'${a}' is a member of ${e}${n}, not of the object it was called on.`), o.join("\n");
2239
+ }
2240
+ let n = Ln.map((t) => zn(e, t)).filter((e) => e !== null).flatMap((t) => Jn(e, t).map((e) => ({
2241
+ owner: t,
2242
+ member: e,
2243
+ score: Yn(a, e.name)
2244
+ }))).filter((e) => e.score !== null && e.score > 0 && e.score <= 2).sort((e, t) => e.score - t.score).slice(0, 3);
2245
+ if (o.length === 0 && n.length === 0) return null;
2246
+ if (o.unshift(`No SheetXL member is named '${a}'.`), n.length > 0) {
2247
+ o.push("Closest:");
2248
+ for (let { owner: e, member: t } of n) o.push(` ${Xn(t, e)}`);
2249
+ }
2250
+ }
2251
+ return o.length > 0 ? o.join("\n") : null;
2252
+ }
2253
+ var Y = (e, t, n = `${t}s`) => `${e.toLocaleString("en-US")} ${e === 1 ? t : n}`;
2254
+ function Qn(e, t) {
2255
+ let n = t ? `${t} · ` : "", r = e.summary ? ` — ${e.summary}` : "", i = e.deprecated ? " (deprecated)" : "";
2256
+ return `- ${n}\`${a = e.signature, a.replace(/;$/, "")}\`${i}${r}`;
2257
+ var a;
2258
+ }
2259
+ function $n(e, t) {
2260
+ let n = t?.command ?? "api";
2261
+ switch (e.kind) {
2262
+ case "overview": return function(e, t) {
2263
+ let n = [
2264
+ `# SheetXL scripting API — ${Y(e.total, "name")}`,
2265
+ "",
2266
+ "Where a script starts:"
2267
+ ];
2268
+ for (let { key: t, entry: r } of e.entryPoints) {
2269
+ let e = r.members ? ` (${Y(r.members.length, "member")})` : "";
2270
+ n.push(`- \`${t}\`${e}${r.summary ? ` — ${r.summary}` : ""}`);
2271
+ }
2272
+ return n.push("", `\`${t} <Type>\` lists what you can call on a type, one line per member.`, `\`${t} <Type>.<member>\` prints that member's full documentation.`, `\`${t} <word>\` searches type and member names.`, "", "Every type answers, not only the ones above. In a script each name is written `SheetXL.<Type>`."), n.join("\n");
2273
+ }(e, n);
2274
+ case "type": return function(e, t) {
2275
+ let { key: n, entry: r, members: i } = e, a = r.members?.length ?? 0, o = [r.kind + (r.typeParams ?? "")];
2276
+ r.members && o.push(Y(a, "member")), r.deprecated && o.push("deprecated");
2277
+ let s = [`# ${n} — ${o.join(" · ")}`];
2278
+ if (r.summary && s.push(r.summary), r.signature && s.push("", "```ts", r.signature, "```"), e.bases.length > 0) {
2279
+ s.push("");
2280
+ for (let n of e.bases) s.push(n.key ? `Also has everything on \`${n.text}\` (${Y(n.memberCount, "member")}): \`${t} ${n.key}\`` : `Extends \`${n.text}\`.`);
2281
+ }
2282
+ if (r.members) {
2283
+ s.push(""), e.filter && s.push(`${Y(i.length, "member")} of ${a} matching '${e.filter}':`);
2284
+ for (let e of i) s.push(Qn(e));
2285
+ }
2286
+ return r.nested && r.nested.length > 0 && !e.filter && s.push("", `Nested types — \`${t} ${n}.<name>\`: ${r.nested.join(", ")}`), s.push("", r.members ? `Full documentation for one member: \`${t} ${n}.<member>\` · scripting.d.ts:${r.lines[0]}-${r.lines[1]}` : `scripting.d.ts:${r.lines[0]}-${r.lines[1]}`), s.join("\n");
2287
+ }(e, n);
2288
+ case "member": return function(e, t) {
2289
+ let n = e.members[0].name, r = [`# ${e.key}.${n}`];
2290
+ return e.declaredOn !== e.key && r.push(`Inherited from \`${e.declaredOn}\`.`), e.members.length > 1 && r.push(`${e.members.length} overloads.`), e.members.forEach((t, n) => {
2291
+ let i = e.sources?.[n] ?? `${t.summary ? `/** ${t.summary} */\n` : ""}${t.signature}`;
2292
+ r.push("", "```ts", i, "```", `scripting.d.ts:${t.lines[0]}-${t.lines[1]}`);
2293
+ }), r.push("", `Everything on the type: \`${t} ${e.declaredOn}\``), r.join("\n");
2294
+ }(e, n);
2295
+ case "search": return function(e, t) {
2296
+ if (e.types.length === 0 && e.members.length === 0) return `No type or member name contains '${e.query}'. \`${t}\` with no name lists where to start.`;
2297
+ let n = [`# '${e.query}' in the scripting API`];
2298
+ if (e.types.length > 0) {
2299
+ n.push("", "Types:");
2300
+ for (let t of e.types) n.push(`- \`${t}\``);
2301
+ }
2302
+ if (e.members.length > 0) {
2303
+ n.push("", "Members:");
2304
+ for (let { key: t, member: r } of e.members) n.push(Qn(r, t));
2305
+ }
2306
+ return e.omitted > 0 && n.push("", `…and ${Y(e.omitted, "more match", "more matches")}; a longer word narrows it.`), n.push("", `\`${t} <Type>\` lists a type's members; \`${t} <Type>.<member>\` prints one in full.`), n.join("\n");
2307
+ }(e, n);
2308
+ }
2309
+ }
2310
+ async function er(e) {
2311
+ let t = Wn(await h(), e);
2312
+ if (t.kind === "member") try {
2313
+ let e = (await g()).split(/\r?\n/);
2314
+ t.sources = t.members.map((t) => function(e, t, n) {
2315
+ let r = e.slice(t - 1, n), i = Math.min(...r.filter((e) => e.trim()).map((e) => e.length - e.trimStart().length));
2316
+ return r.map((e) => e.slice(Number.isFinite(i) ? i : 0)).join("\n");
2317
+ }(e, t.lines[0], t.lines[1]));
2318
+ } catch {}
2319
+ return t;
2320
+ }
2321
+ var tr = {
2322
+ name: "api",
2323
+ description: "Look up the scripting API — what you can call on a type, without reading the type definitions. `ICellRange` lists its members, one line each (signature + summary); `ICellRange.setValues` prints that member's full documentation; any other word searches type and member names; no name lists where to start. Answers come from the same declarations `run` type-checks against, so a member listed here exists.",
2324
+ params: [{
2325
+ name: "name",
2326
+ type: "string",
2327
+ description: "A type (`ICellRange`), a member (`ICellRange.setValues`), or a word to search for. Omit for the overview. A leading `SheetXL.` is accepted.",
2328
+ positional: 0
2329
+ }],
2330
+ run: (e) => er(e?.name),
2331
+ render: $n
2332
+ }, nr = i.Feature;
2333
+ async function rr(e, t, n, r) {
2334
+ await ir(e, t, "precedents", n, r), await ir(e, t, "dependents", n, r);
2335
+ }
2336
+ async function ir(e, t, n, r, i) {
2337
+ let a = n === "precedents" ? "Precedents" : "Dependents", o = await (n === "precedents" ? t.getPrecedents() : t.getDependents()), s = n === "dependents" && i?.subject ? function(e, t) {
2338
+ let n = e.getSheet(), r = n.getWorkbook()?.getSheets().getItems({ visibility: d.Visibility.VeryHidden }) ?? [n], i = /* @__PURE__ */ new Map();
2339
+ for (let e = 0; e < (t?.length ?? 0); e++) {
2340
+ let n = t.at(e);
2341
+ if (n.isINamedRange) continue;
2342
+ let r = i.get(n.getSheet());
2343
+ r ? r.push(n.getCoords()) : i.set(n.getSheet(), [n.getCoords()]);
2344
+ }
2345
+ let a = e.getCoords(), o = [];
2346
+ for (let e of r) for (let t of e.getMovables().getItems({ type: "chart" })) {
2347
+ let e = K(t);
2348
+ if (!e || e.getPivotSource()) continue;
2349
+ let r = null;
2350
+ for (let t of e.getSeries()) {
2351
+ for (let e of [
2352
+ t.getValuesRange(),
2353
+ t.getCategoriesRange(),
2354
+ t.getNameRange()
2355
+ ]) {
2356
+ if (!e) continue;
2357
+ let t = e.getCoords();
2358
+ if (e.getSheet() === n && Qt(t, a)) {
2359
+ r = !0;
2360
+ break;
2361
+ }
2362
+ r === null && i.get(e.getSheet())?.some((e) => Qt(e, t)) && (r = !1);
2363
+ }
2364
+ if (!0 === r) break;
2365
+ }
2366
+ r !== null && o.push({
2367
+ movable: t,
2368
+ direct: r
2369
+ });
2370
+ }
2371
+ return o;
2372
+ }(i.subject, o) : [];
2373
+ if (!o || o.length === 0) {
2374
+ let t = n === "precedents" ? i?.zeroPrecedents : i?.zeroDependents;
2375
+ s.length > 0 ? (e.h2(`${a} (${ar(s.length)})`), e.text(` ${"charts".padEnd(sr)}${or(s)}`), e.blank()) : t && (e.h2(`${a} (0)`), e.blank());
2376
+ return;
2377
+ }
2378
+ let c = await async function(e, t, n) {
2379
+ let r = 0, i = 0, a = 0, o = 0, s = /* @__PURE__ */ new Map();
2380
+ for (let e = 0; e < t.length; e++) {
2381
+ let n = t.at(e);
2382
+ if (n.isINamedRange) {
2383
+ o++;
2384
+ continue;
2385
+ }
2386
+ a++;
2387
+ let c = n.getCounts([nr.Contentful, nr.Formula]), l = c[nr.Contentful] ?? 0;
2388
+ r += l, i += c[nr.Formula] ?? 0;
2389
+ let u = n.getSheet()?.getName() ?? "";
2390
+ s.set(u, (s.get(u) ?? 0) + l);
2391
+ }
2392
+ let { depth: c, capped: l } = await async function(e, t) {
2393
+ let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set(), i = 0, a = !1, o = (e) => t === "precedents" ? e.getDirectPrecedents() : e.getDirectDependents(), s = async (e) => {
2394
+ let t = await o(e);
2395
+ if (!t) return 0;
2396
+ let c = 0;
2397
+ for (let e = 0; e < t.length; e++) {
2398
+ let o = t.at(e), l = mr(o);
2399
+ if (r.has(l)) continue;
2400
+ let u = n.get(l);
2401
+ u === void 0 && (++i > lr ? (a = !0, u = 0) : (r.add(l), u = await s(o), r.delete(l), n.set(l, u))), c = Math.max(c, u + 1);
2402
+ }
2403
+ return c;
2404
+ };
985
2405
  return {
986
- broken: a,
987
- missing: r,
988
- error: a ? "#REF!" : ""
2406
+ depth: await s(e),
2407
+ capped: a
989
2408
  };
990
- }(e, r), n = We(e), o = n ? function(e, t) {
991
- let n = e.getDirectDependents(), r = 0, i = [], a = /* @__PURE__ */ new Set(), o = [];
992
- if (n) {
993
- let e = n.getCoords(), s = n.getCount();
994
- for (let c = 0; c < s; c++) {
995
- let s = n.at(c);
996
- if (s.isINamedRange) {
997
- let e = s;
998
- if (a.has(e.getId())) continue;
999
- a.add(e.getId());
1000
- let n = t.get(e.getId());
1001
- i.push(n ? G(n) : e.getName());
1002
- } else {
1003
- let t = e[c];
1004
- r += (t.rowEnd - t.rowStart + 1) * (t.colEnd - t.colStart + 1), o.push(Ge(s));
1005
- }
1006
- }
2409
+ }(e, n);
2410
+ return {
2411
+ cells: r,
2412
+ inputs: r - i,
2413
+ areas: a,
2414
+ names: o,
2415
+ depth: c,
2416
+ depthCapped: l,
2417
+ sheets: s,
2418
+ outputs: n === "dependents" ? await dr(t) : {
2419
+ ranges: [],
2420
+ cells: 0
1007
2421
  }
1008
- let s = r + i.length;
1009
- if (s === 0) return {
1010
- text: "unused",
1011
- weight: s
2422
+ };
2423
+ }(t, o, n), l = [`${c.cells} ${c.cells === 1 ? "cell" : "cells"}`];
2424
+ n === "precedents" ? l.push(`${c.inputs} ${c.inputs === 1 ? "input" : "inputs"}`) : l.push(`${c.outputs.cells} ${c.outputs.cells === 1 ? "output" : "outputs"}`), l.push(`depth ${c.depthCapped ? "≥ " : ""}${c.depth}`), l.push(`${c.areas} ${c.areas === 1 ? "area" : "areas"}`), c.names > 0 && l.push(`${c.names} ${c.names === 1 ? "name" : "names"}`), s.length > 0 && l.push(ar(s.length)), e.h2(`${a} (${l.join(" · ")})`);
2425
+ let u = i?.home?.getName() ?? null, f = await async function(e, t, n, r) {
2426
+ let i = Math.max(1, r?.maxTreeRows ?? 12), a = (e) => t === "precedents" ? e.getDirectPrecedents() : e.getDirectDependents(), o = [], s = /* @__PURE__ */ new Map(), c = 0, l = 0, u = !1, d = [], f = (e, t, n) => {
2427
+ let r = e?.length ?? 0;
2428
+ for (let a = 0; a < r && d.length - p < i - l; a++) d.push({
2429
+ range: e.at(a),
2430
+ parent: t,
2431
+ depth: n
2432
+ });
2433
+ return r;
2434
+ }, p = 0;
2435
+ for (c = f(await a(e), null, 0); p < d.length && l < i;) {
2436
+ let { range: e, parent: t, depth: n } = d[p++], r = mr(e), i = {
2437
+ range: e,
2438
+ key: r,
2439
+ depth: n,
2440
+ parent: t,
2441
+ children: [],
2442
+ childCount: 0,
2443
+ mark: null,
2444
+ first: null
1012
2445
  };
1013
- let c = [...i, ...o], l = [], u = 0;
1014
- for (let e = 0; e < c.length; e++) {
1015
- let t = (l.length > 0 ? 2 : 0) + c[e].length;
1016
- if (l.length > 0 && u + t > 60) break;
1017
- l.push(l.length === 0 ? Ue(c[e], 60) : c[e]), u += t;
2446
+ l++, (t ? t.children : o).push(i);
2447
+ let c = t;
2448
+ for (; c && c.key !== r;) c = c.parent;
2449
+ if (c) {
2450
+ i.mark = "circular", u = !0;
2451
+ continue;
1018
2452
  }
1019
- let d = c.length - l.length, f = d > 0 ? `, +${d} more` : "";
2453
+ let m = s.get(r);
2454
+ m ? (i.mark = "repeat", i.first = m) : (s.set(r, i), i.childCount = f(await a(e), i, n + 1));
2455
+ }
2456
+ let m = function(e) {
2457
+ if (e.isINamedRange || typeof e.getCoords != "function") return null;
2458
+ let t = e.getCoords();
2459
+ return "rowIndex" in t ? {
2460
+ rowStart: t.rowIndex,
2461
+ rowEnd: t.rowIndex,
2462
+ colStart: t.colIndex,
2463
+ colEnd: t.colIndex
2464
+ } : t;
2465
+ }(e), h = [], g = (e) => {
2466
+ for (let t of e) h.push(t), g(t.children);
2467
+ };
2468
+ g(o);
2469
+ let _ = new Map(h.map((e, t) => [e, t])), v = c - o.length, y = h.map((e) => {
2470
+ let { address: t, sheet: n, isName: r } = hr(e.range), i;
2471
+ if (e.mark === "circular") i = "↺ circular";
2472
+ else if (e.mark === "repeat") i = _.get(e.first) < _.get(e) ? "↑ shown above" : "↓ shown below";
2473
+ else {
2474
+ i = [gr(e.range), pr(e.range, m)].filter(Boolean).join(" ");
2475
+ let t = e.childCount - e.children.length;
2476
+ t > 0 && (v += t, i = `${i} ▸ ${t} more`);
2477
+ }
2478
+ let a = " ".repeat(e.depth);
1020
2479
  return {
1021
- text: `${s} · ${l.join(", ")}${f}`,
1022
- weight: s
2480
+ indent: a,
2481
+ sheet: n,
2482
+ isName: r,
2483
+ label: `${a}${t}`,
2484
+ detail: i
1023
2485
  };
1024
- }(n, i) : null;
1025
- o?.weight === 0 && !e.getScope() && a.has(e.getName().toLowerCase()) && (o = {
1026
- ...o,
1027
- text: "unused · shadowed"
1028
- });
1029
- let s = e.getComment() ?? "", c = G(e);
2486
+ }), b = y.filter((e) => !e.isName);
2487
+ if (b.length > 0 && b.some((e) => e.sheet !== b[0].sheet)) for (let e of y) e.isName || (e.label = `${e.indent}${W(e.sheet)}!${e.label.slice(e.indent.length)}`);
2488
+ let x = [], S = Math.max(...y.map((e) => e.label.length));
2489
+ for (let e of y) x.push(` ${e.label.padEnd(S)} ${e.detail}`.trimEnd());
2490
+ if (u && x.push(" ↺ circular reference — the chain returns to a cell already on this branch"), v > 0) {
2491
+ let e = t === "precedents" ? "getPrecedents()" : "getDependents()";
2492
+ x.push(` …${v} ${v === 1 ? "branch" : "branches"} not shown · ${e} → ICellRanges (${n} ${n === 1 ? "area" : "areas"}), flat`);
2493
+ }
1030
2494
  return {
1031
- name: c,
1032
- refersTo: Ke(e),
1033
- dependents: o,
1034
- hidden: e.isHidden(),
1035
- comment: Ue(s, 60),
1036
- broken: t.broken,
1037
- error: t.error,
1038
- sortKey: c.toLowerCase().replace(/'/g, "")
2495
+ lines: x,
2496
+ shown: new Set(h.map((e) => e.key))
1039
2497
  };
1040
- }), s = (e, t) => {
1041
- let n = (t.dependents?.weight ?? 0) - (e.dependents?.weight ?? 0);
1042
- return n === 0 ? e.sortKey.localeCompare(t.sortKey) : n;
1043
- }, c = [...o.filter((e) => e.broken).sort(s), ...o.filter((e) => !e.broken).sort(s)], l = E(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);
1044
- e.h2(`${n?.heading ?? "Names"} (${o.length})`);
1045
- let p = (t, n) => {
1046
- 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"];
1047
- n && o.push("Error"), a && o.push("Dependents"), r && o.push("Hidden"), i && o.push("Comment");
1048
- let s = e.beginFrame(o);
1049
- for (let e of t) {
1050
- let t = [{ text: e.name }, { text: e.refersTo }];
1051
- 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);
2498
+ }(t, n, c.areas, r), p = c.outputs.ranges;
2499
+ if (n === "dependents" && p.some((e) => !f.shown.has(mr(e))) && e.text(` ${"outputs".padEnd(sr)}${function(e, t) {
2500
+ let n = e.ranges.slice(0, ur).map((e) => {
2501
+ let { address: n, sheet: r } = hr(e);
2502
+ return [
2503
+ t !== null && r !== t ? `${W(r)}!${n}` : n,
2504
+ e.isSingleCell() ? b(e.getCell(), _.Mode.Display)?.display ?? "" : `${e.getRowCount()}×${e.getColumnCount()}`,
2505
+ pr(e)
2506
+ ].filter(Boolean).join(" ");
2507
+ }), r = e.ranges.length - n.length;
2508
+ return r > 0 && n.push(`+${r} more (getDependents())`), n.join(" · ");
2509
+ }(c.outputs, u)}`), u !== null) {
2510
+ let t = [...c.sheets].filter(([e]) => e !== u);
2511
+ if (t.length > 0) {
2512
+ let n = t.map(([e, t]) => `${W(e)} ${t} ${t === 1 ? "cell" : "cells"}`);
2513
+ e.text(` ${"sheets".padEnd(sr)}${n.join(" · ")}`);
1052
2514
  }
1053
- s.endFrame();
1054
- };
1055
- if (d.length > 0) {
1056
- let t = c.reduce((e, t) => e + +!!t.broken, 0);
1057
- e.text(`${t} ${t === 1 ? "does" : "do"} not resolve:`), p(d, !0), e.blank();
1058
- }
1059
- if (f.length > 0 && p(f, !1), u.length < o.length) {
1060
- let t = n?.recovery ?? "getByName('Name') renders one in full";
1061
- e.text(` …and ${o.length - u.length} more · ${t}`);
1062
2515
  }
2516
+ s.length > 0 && e.text(` ${"charts".padEnd(sr)}${or(s)}`);
2517
+ for (let t of f.lines) e.text(t);
1063
2518
  e.blank();
1064
2519
  }
1065
- function q(e, t, n) {
1066
- $e(e, "Precedents", t, "precedents", n), $e(e, "Dependents", t, "dependents", n);
2520
+ var ar = (e) => `${e} ${e === 1 ? "chart" : "charts"}`;
2521
+ function or(e) {
2522
+ let t = e.slice(0, cr).map($t), n = e.length - t.length;
2523
+ return n > 0 && t.push(`+${n} more`), t.join(" · ");
2524
+ }
2525
+ var sr = 10, cr = 6, lr = 2e3, ur = 4;
2526
+ async function dr(e) {
2527
+ let t = /* @__PURE__ */ new Map(), n = await e.getPrecedents(!1);
2528
+ for (let e = 0; e < (n?.length ?? 0); e++) {
2529
+ let r = n.at(e);
2530
+ if (r.isINamedRange) continue;
2531
+ let i = r.getSheet()?.getName() ?? "", a = t.get(i) ?? [];
2532
+ a.push(r.getCoords()), t.set(i, a);
2533
+ }
2534
+ let r = [], i = 0;
2535
+ for (let n = 0; n < e.length; n++) {
2536
+ let a = e.at(n);
2537
+ if (a.isINamedRange) continue;
2538
+ let o = [a.getCoords()];
2539
+ for (let e of t.get(a.getSheet()?.getName() ?? "") ?? []) if (o = o.flatMap((t) => fr(t, e)), o.length === 0) break;
2540
+ for (let e of o) i += (e.rowEnd - e.rowStart + 1) * (e.colEnd - e.colStart + 1), r.push(a.getSheet().getRange(e));
2541
+ }
2542
+ return {
2543
+ ranges: r,
2544
+ cells: i
2545
+ };
2546
+ }
2547
+ function fr(e, t) {
2548
+ let n = Math.max(e.rowStart, t.rowStart), r = Math.min(e.rowEnd, t.rowEnd), i = Math.max(e.colStart, t.colStart), a = Math.min(e.colEnd, t.colEnd);
2549
+ if (n > r || i > a) return [e];
2550
+ let o = [];
2551
+ return e.rowStart < n && o.push({
2552
+ ...e,
2553
+ rowEnd: n - 1
2554
+ }), r < e.rowEnd && o.push({
2555
+ ...e,
2556
+ rowStart: r + 1
2557
+ }), e.colStart < i && o.push({
2558
+ rowStart: n,
2559
+ rowEnd: r,
2560
+ colStart: e.colStart,
2561
+ colEnd: i - 1
2562
+ }), a < e.colEnd && o.push({
2563
+ rowStart: n,
2564
+ rowEnd: r,
2565
+ colStart: a + 1,
2566
+ colEnd: e.colEnd
2567
+ }), o;
1067
2568
  }
1068
- function Qe(e) {
2569
+ function pr(e, t) {
2570
+ if (e.isINamedRange || !e.isSingleCell()) return "";
2571
+ let n = e.getCell();
2572
+ if (n.getType() === m.String) return "";
2573
+ let r = n.getCoords(), i = e.getSheet(), a = [];
2574
+ if (!t || r.rowIndex < t.rowStart || r.rowIndex > t.rowEnd) {
2575
+ let e = M(i, r, "row");
2576
+ e && a.push(`row ${JSON.stringify(e.text)}`);
2577
+ }
2578
+ if (!t || r.colIndex < t.colStart || r.colIndex > t.colEnd) {
2579
+ let e = M(i, r, "column");
2580
+ e && a.push(`col ${JSON.stringify(e.text)}`);
2581
+ }
2582
+ return a.join(" ");
2583
+ }
2584
+ function mr(e) {
1069
2585
  let t = e.isINamedRange ? e.getId() : null;
1070
2586
  if (t) return `name:${t}`;
1071
2587
  let n = e.getCoords();
1072
2588
  return `${e.getSheet()?.getName() ?? ""}!${n.rowStart},${n.colStart},${n.rowEnd},${n.colEnd}`;
1073
2589
  }
1074
- function $e(e, t, n, r, i) {
1075
- let a = i?.maxDepth ?? 3, o = i?.maxNodes ?? 50, s = [], c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Set(), u = !1, d = !1, f = !1, p = (e, t) => {
1076
- let n = ((e) => r === "precedents" ? e.getDirectPrecedents() : e.getDirectDependents())(e);
1077
- if (n && n.length !== 0) if (t > a) u = !0;
1078
- else for (let e = 0; e < n.length; e++) {
1079
- if (s.length >= o) return void (d = !0);
1080
- let r = n.at(e), { address: i, sheet: a, isName: u } = et(r), m = " ".repeat(t), h = Qe(r), g = {
1081
- indent: m,
1082
- sheet: a,
1083
- isName: u,
1084
- label: `${m}${i}`
1085
- };
1086
- l.has(h) ? (s.push({
1087
- ...g,
1088
- detail: "↺ circular"
1089
- }), f = !0) : c.has(h) ? s.push({
1090
- ...g,
1091
- detail: "↑ shown above"
1092
- }) : (c.add(h), l.add(h), s.push({
1093
- ...g,
1094
- detail: tt(r)
1095
- }), p(r, t + 1), l.delete(h));
1096
- }
1097
- };
1098
- if (p(n, 0), s.length === 0) return;
1099
- let m = s.filter((e) => !e.isName);
1100
- 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)}`);
1101
- e.h2(t);
1102
- let h = Math.max(...s.map((e) => e.label.length));
1103
- for (let t of s) e.text(` ${t.label.padEnd(h)} ${t.detail}`.trimEnd());
1104
- f && e.text(" ↺ circular reference — the chain returns to a cell already on this branch");
1105
- let g = r === "precedents" ? "getPrecedents()" : "getDependents()";
1106
- if (u && e.text(` …deeper levels not walked · ${g} is the whole reach, flat`), d) {
1107
- let t = r === "precedents" ? "getDirectPrecedents()" : "getDirectDependents()";
1108
- e.text(` …truncated at ${o} nodes · re-root on one node and walk it — its ${t}`);
1109
- }
1110
- e.blank();
1111
- }
1112
- function et(e) {
2590
+ function hr(e) {
1113
2591
  let t = e.getSheet()?.getName() ?? "";
1114
2592
  if (e.isINamedRange) return {
1115
2593
  address: e.getName(),
@@ -1123,98 +2601,159 @@ function et(e) {
1123
2601
  isName: !1
1124
2602
  };
1125
2603
  }
1126
- function tt(e) {
2604
+ function gr(e) {
1127
2605
  if (e.isINamedRange) {
1128
2606
  let t = e.getRanges();
1129
2607
  return t ? `name → ${t.getAddress()}` : "name";
1130
2608
  }
1131
2609
  if (e.isSingleCell()) {
1132
- let t = e.getCell(), n = g(t, p.Mode.Display), r = t.getFormulaText(), i = n ? n.display : "(empty)";
1133
- return r ? `${i} =${r}` : i;
2610
+ let t = e.getCell(), n = b(t, _.Mode.Display), r = t.getFormulaText(), i = n ? n.display : "(empty)";
2611
+ return r ? `${i} ${r}` : i;
1134
2612
  }
1135
- let t = `${e.getRowCount()}×${e.getColumnCount()}`, n = [...e.getRegions(B.Formula)];
2613
+ let t = `${e.getRowCount()}×${e.getColumnCount()}`, n = [...e.getRegions(nr.Formula)];
1136
2614
  if (n.length === 1 && n[0].getRange().isEqual(e)) {
1137
2615
  let e = n[0].getCell().getFormulaText();
1138
- if (e) return `${t} =${e}`;
2616
+ if (e) return `${t} ${e}`;
1139
2617
  }
1140
2618
  return t;
1141
2619
  }
1142
- function nt(e, t, n) {
1143
- let r = n.getCoords().min, i = [], a = 0, o = 0;
1144
- if (n.forEachSpan((e, t) => {
1145
- let s = t.getCoords();
1146
- if (o++, a += s.max - s.min + 1, i.length >= 100) return;
1147
- let c = n.at(s.min - r).getText(), l = n.at(s.max - r).getText();
1148
- i.push({
1149
- address: `${c}:${l}`,
1150
- count: s.max - s.min + 1
1151
- });
1152
- }, {
1153
- visibility: "hidden",
1154
- includeEmpty: !0
1155
- }), a === 0) return;
1156
- e.h2(`${t} (${a})`);
1157
- let s = Math.max(...i.map((e) => e.address.length));
1158
- for (let t of i) e.text(` ${t.address.padEnd(s)} ${t.count}`);
1159
- o > i.length && e.text(` …and ${o - i.length} more`), e.blank();
1160
- }
1161
- function rt(e, t, n, r) {
1162
- if (n.length === 0) return;
1163
- let i = n.length > 50 ? n.slice(0, 50) : n, a = i.map((e) => ({
1164
- address: Ue(ze(e.getRanges()), 40),
1165
- rule: r(e)
1166
- }));
1167
- e.h2(`${t} (${n.length})`);
1168
- let o = Math.max(...a.map((e) => e.address.length));
1169
- for (let t of a) e.text(` ${t.address.padEnd(o)} ${t.rule}`.trimEnd());
1170
- i.length < n.length && e.text(` …and ${n.length - i.length} more`), e.blank();
1171
- }
1172
- function J(e, t) {
1173
- let n = t.getSheet(), r = t.getCoords(), i = n.getName(), a = [];
1174
- for (let e of n.getNames().getItems({
1175
- type: "formula",
1176
- includeHidden: !0
1177
- }) ?? []) {
1178
- let t = null;
1179
- try {
1180
- t = e.getRanges?.() ?? null;
1181
- } catch {}
1182
- t ? t.getCoords().some((e) => {
1183
- 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);
1184
- var t, n;
1185
- }) && a.push(e) : e.getScope() === i && a.push(e);
1186
- }
1187
- K(e, a, { symbols: n.getWorkbook()?.getNames().getItems({ includeHidden: !0 }) ?? n.getNames().getItems({ includeHidden: !0 }) ?? [] });
1188
- let o = t.getColumnHeaders(), s = t.getRowHeaders();
1189
- nt(e, "Hidden Columns", o), nt(e, "Hidden Rows", s);
1190
- let c = t.getTables();
1191
- c.length > 0 && (e.h2("Tables"), c.forEach((t, n) => {
1192
- n > 0 && e.blank(), Me(e, t);
1193
- }), e.blank());
1194
- }
1195
- var it = {
1196
- features: (e) => Le(e),
2620
+ var _r = {
2621
+ features: (e) => gt(e),
1197
2622
  mode: (e, t) => function(e, t, n) {
1198
2623
  let r = new Map(Object.values(n).map((e) => [e.toLowerCase(), e])).get(e.trim().toLowerCase());
1199
2624
  if (!r) throw Error(`Unknown ${t} '${e}'. Values: ${Object.values(n).join(", ")}.`);
1200
2625
  return r;
1201
- }(e, t, p.Mode)
1202
- }, at = Object.keys(it);
1203
- function ot(e) {
2626
+ }(e, t, _.Mode)
2627
+ }, vr = Object.keys(_r);
2628
+ function yr(e) {
1204
2629
  let t = {};
1205
2630
  for (let [n, r] of Object.entries(e)) {
1206
- let e = it[n];
1207
- if (!e) throw Error(`Unknown report option '${n}'. Options: ${at.join(", ")}.`);
2631
+ let e = _r[n];
2632
+ if (!e) throw Error(`Unknown report option '${n}'. Options: ${vr.join(", ")}.`);
1208
2633
  t[n] = e(r, n);
1209
2634
  }
1210
2635
  return t;
1211
2636
  }
1212
- function st(e, t) {
1213
- e = e.getSheet().getRange(e.getCoords()).getCell();
1214
- let n = new z();
1215
- return n.h1(`Cell — ${H(e.getSheet().getName())}!${e.getAddress()}`), n.blank(), function(e, t) {
1216
- let n = g(t, p.Mode.Display), r = g(t, p.Mode.Value), i = t.getFormulaText(), a = e.toLines().length;
1217
- (n || i) && (e.fact(`Type: ${t.getType()}`), n && e.fact(`Display: ${n.display}`), r && r.match !== n?.match && e.fact(`Value: ${r.display}`), i && e.fact(`Formula: ${e.codespan(`=${i}`)}`));
2637
+ var br = i.Feature, xr = [
2638
+ ["formatCells", "format cells"],
2639
+ ["formatColumns", "format columns"],
2640
+ ["formatRows", "format rows"],
2641
+ ["insertColumns", "insert columns"],
2642
+ ["insertRows", "insert rows"],
2643
+ ["insertHyperlinks", "insert hyperlinks"],
2644
+ ["deleteColumns", "delete columns"],
2645
+ ["deleteRows", "delete rows"],
2646
+ ["sort", "sort"],
2647
+ ["autoTable", "filter"],
2648
+ ["pivotTables", "pivot tables"],
2649
+ ["objects", "edit objects"],
2650
+ ["scenarios", "edit scenarios"]
2651
+ ], Sr = [["structure", "structure"], ["windows", "windows"]], Cr = (e) => {
2652
+ let t = e.hasPassword() ? " · password" : "";
2653
+ return e.isLocked() ? `locked${t}` : e.isPaused() ? `paused${t} — nothing is refused until resume()` : null;
2654
+ }, wr = (e) => {
2655
+ let t = e.getProperties();
2656
+ if (!t) return null;
2657
+ let n = xr.filter(([e]) => !0 === t[e]).map(([, e]) => e);
2658
+ return n.length > 0 ? n.join(", ") : null;
2659
+ }, Tr = (e) => {
2660
+ let t = e.getProperties();
2661
+ if (!t) return null;
2662
+ let n = Sr.filter(([e]) => !0 !== t[e]).map(([, e]) => e);
2663
+ return n.length > 0 ? n.join(", ") : null;
2664
+ }, Er = (e) => {
2665
+ let t = Cr(e);
2666
+ if (!t) return null;
2667
+ let n = Tr(e);
2668
+ return n ? `${n} ${t}` : t;
2669
+ }, Dr = (e) => [...e.getEntireRange().getRegions(br.Unlock)], Or = (e) => {
2670
+ let t = 0;
2671
+ for (let n of e) {
2672
+ let e = n.getCoords();
2673
+ t += (e.rowEnd - e.rowStart + 1) * (e.colEnd - e.colStart + 1);
2674
+ }
2675
+ return t;
2676
+ }, kr = (t) => {
2677
+ let n = null;
2678
+ for (let e of t) {
2679
+ let t = e.getCoords();
2680
+ n = n ? {
2681
+ rowStart: Math.min(n.rowStart, t.rowStart),
2682
+ colStart: Math.min(n.colStart, t.colStart),
2683
+ rowEnd: Math.max(n.rowEnd, t.rowEnd),
2684
+ colEnd: Math.max(n.colEnd, t.colEnd)
2685
+ } : { ...t };
2686
+ }
2687
+ return n ? e.rangeToString(n) ?? "" : "";
2688
+ }, X = (e, t) => `${e} ${t}${e === 1 ? "" : "s"}`;
2689
+ function Ar(e) {
2690
+ let t = e.getProtection(), n = Cr(t);
2691
+ if (!n) return null;
2692
+ let r = Dr(e), i = [r.length > 0 ? `${X(Or(r), "editable cell")} · ${X(r.length, "region")}` : "no editable cells", n];
2693
+ return !1 === t.getProperties()?.showFormulas && i.push("formulas hidden"), {
2694
+ extent: kr(r),
2695
+ detail: i.join(" · ")
2696
+ };
2697
+ }
2698
+ function jr(e, t) {
2699
+ let n = t.getProtection(), r = Cr(n);
2700
+ if (!r) return;
2701
+ e.h2(`Protection (${r})`);
2702
+ let i = (e) => ` ${e.padEnd(10)}`;
2703
+ e.text(`${i("allowed")}${wr(n) ?? "none — only the editable cells take a write"}`), !1 === n.getProperties()?.showFormulas && e.text(`${i("formulas")}hidden — a cell reads as a value unless its style shows its formula`);
2704
+ let a = Dr(t);
2705
+ if (a.length === 0) return e.text(`${i("editable")}none — every cell refuses a write`), void e.blank();
2706
+ e.text(`${i("editable")}${X(Or(a), "cell")} · ${X(a.length, "region")}`), ct(e, a, {
2707
+ maxRegions: 12,
2708
+ payload: it(br.Unlock, null),
2709
+ recovery: `${G(t.getEntireRange())}.getRegions("unlock") lists all ${a.length}`
2710
+ }), e.blank();
2711
+ }
2712
+ function Mr(e) {
2713
+ if (!e.getSheet().getProtection().isLocked()) return null;
2714
+ let t = [...e.getRegions(br.Unlock)], n = e.getRowCount() * e.getColumnCount(), r = Or(t);
2715
+ if (r === 0) return "sheet locked — no cell here takes a write";
2716
+ if (r === n) return "sheet locked — every cell here is editable";
2717
+ let i = e.getSheet().getProtectedRanges().getItems({ address: e }).some((e) => !e.isUnlocked());
2718
+ return `sheet locked — ${r} of ${X(n, "cell")} editable (${kr(t)})` + (i ? " · some behind a range password" : "");
2719
+ }
2720
+ function Nr(e) {
2721
+ return e.getSheet().getProtection().isLocked() ? e.isEditAllowed() ? "true — unlocked on a protected sheet" : "false — the sheet is protected and this cell is locked" : null;
2722
+ }
2723
+ function Pr(e) {
2724
+ return e?.name === "ProtectedError" ? "`sheet.getProtection()` (`wb.getProtection()` for the workbook) lists what is still allowed; `sheet.getRegions(\"unlock\")` lists the cells that take a write." : null;
2725
+ }
2726
+ function Fr(e) {
2727
+ let t = new V(), n = !0 === e.isISheetProtection;
2728
+ t.h1(n ? "Sheet Protection" : "Workbook Protection"), t.blank();
2729
+ let r = Cr(e);
2730
+ t.fact(`State: ${r ?? "not protected"}${e.isReadOnly() ? " · read-only" : ""}`);
2731
+ let i = r ? "" : " (when next locked)";
2732
+ if (n) {
2733
+ let n = wr(e);
2734
+ (r || n) && t.fact(`Allowed${i}: ${n ?? "none — only the editable cells take a write"}`), !1 === e.getProperties()?.showFormulas && t.fact(`Formulas${i}: hidden`), r && t.fact("Editable: sheet.getRegions(\"unlock\") lists the cells that take a write");
2735
+ } else {
2736
+ let n = Tr(e);
2737
+ (r || e.getProperties()) && t.fact(`Refused${i}: ${n ?? "nothing"}`);
2738
+ }
2739
+ return t.toLines().join("\n").trimEnd();
2740
+ }
2741
+ function Ir(e) {
2742
+ let t = new V(), n = e.getRanges();
2743
+ t.h1(`Unlocked Range — ${e.getName()}`), t.blank(), t.fact(`Ranges: ${vt(n)}`), t.fact(`Cells: ${n.size}`), t.fact("Password: " + (e.hasPassword() ? e.isUnlocked() ? "set · unlocked for this session" : "set · unlock(password) grants access" : "none"));
2744
+ let r = n.getSheet().getProtection().isLocked();
2745
+ return t.fact("In force: " + (r ? "true — the sheet is protected" : "false — the sheet is not protected, so every cell is editable")), e.getSecurityDescriptor() && t.fact("Security Descriptor: present · not evaluated"), t.toLines().join("\n").trimEnd();
2746
+ }
2747
+ var Lr = i.Feature;
2748
+ async function Rr(e, t) {
2749
+ let n = e.getSheet().getRange(e.getCoords());
2750
+ e = n.getCell();
2751
+ let r = new V();
2752
+ r.h1(`Cell — ${W(e.getSheet().getName())}!${e.getAddress()}`), r.blank();
2753
+ let i = !!e.getFormulaText(), a = e.getType();
2754
+ (function(e, t) {
2755
+ let n = b(t, _.Mode.Display), r = b(t, _.Mode.Value), i = t.getFormulaText(), a = e.toLines().length;
2756
+ (n || i) && (e.fact(`Type: ${t.getType()}`), n && e.fact(`Display: ${n.display}`), r && r.match !== n?.match && e.fact(`Value: ${r.display}`), i && e.fact(`Formula: ${e.codespan(i)}`));
1218
2757
  let o = t.getHyperlink();
1219
2758
  o && e.fact(`Hyperlink: ${o.getAddress()}`);
1220
2759
  let s = t.getSpans(), c = !t.isTopLeft();
@@ -1225,83 +2764,181 @@ function st(e, t) {
1225
2764
  let l = t.getSpill();
1226
2765
  l && e.fact(`Spill: ${l.toString()}`), t.isSpillOverflow() && e.fact("Spill Overflow: true — the anchor formula is elsewhere");
1227
2766
  let u = t.getTable();
1228
- u && e.fact(`Table: ${u.getName()}`);
1229
- let d = t.getErrors();
1230
- d.length > 0 && e.fact(`Errors: ${d.join("; ")}`);
1231
- let f = t.getWarnings();
1232
- f.length > 0 && e.fact(`Warnings: ${f.join("; ")}`), e.toLines().length > a && e.blank();
1233
- }(n, e), function(e, t) {
1234
- let n = t.getStyle(), r = t.getSheet().getWorkbook()?.getStyles().getNormal() ?? null, i = le(n), a = r ? de(n, r) : null, o = ae(n), s = ce(n), c = r ? ue(n, r) : null, l = n.getNamed().getName();
1235
- if (l !== (r?.getNamed().getName() ?? "Normal") || i || a || o || c || s.length !== 0) {
1236
- 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]}`);
1237
- else if (s.length > 1) {
1238
- e.fact("Border:");
1239
- for (let t of s) e.fact(` ${t}`);
2767
+ u && e.fact(`Table: ${function(e, t) {
2768
+ let n = e.getRange().getCoords(), r = [`${e.getName()} (${e.getRange().getAddress()})`], i = e.getColumnAt(t.colIndex - n.colStart);
2769
+ if (i && r.push(`column ${JSON.stringify(i.getName())}`), e.isShowHeaders() && t.rowIndex === n.rowStart) r.push("header row");
2770
+ else if (e.isShowTotals() && t.rowIndex === n.rowEnd) r.push("totals row");
2771
+ else {
2772
+ let n = e.getDataRange().getCoords();
2773
+ r.push(`data row ${t.rowIndex - n.rowStart + 1} of ${n.rowEnd - n.rowStart + 1}`);
1240
2774
  }
1241
- c && e.fact(`Alignment: ${c}`), e.blank();
1242
- }
1243
- }(n, e), q(n, e, t), n.toLines().join("\n").trimEnd();
1244
- }
1245
- var ct = /* @__PURE__ */ new Set(["picture"]), lt = (e) => e.replace(/[\r\n]+/g, " ").trim(), ut = (e) => {
1246
- switch (e.getType()) {
1247
- case "chart": {
1248
- let t = [], n = e.getChartType?.();
1249
- n && n !== "unknown" && t.push(n);
1250
- let r = e.getChartTitle?.();
1251
- return r && t.push(`"${r}"`), t.length > 0 ? t.join(" · ") : null;
2775
+ return r.join(" · ");
2776
+ }(u, t.getCoords())}`);
2777
+ let d = Lt(t.getSheet().getRange(t.getCoords()));
2778
+ d.length > 0 && e.fact(`Names: ${d.map((e) => `${e.getName()} (${_t(e.getRanges())})`).join(" · ")}`);
2779
+ let f = Nr(t);
2780
+ f && e.fact(`Editable: ${f}`);
2781
+ let p = t.getErrors();
2782
+ p.length > 0 && e.fact(`Errors: ${p.join("; ")}`);
2783
+ let m = t.getWarnings();
2784
+ m.length > 0 && e.fact(`Warnings: ${m.join("; ")}`);
2785
+ let h = function(e) {
2786
+ let t = e.getStyle(), n = e.getSheet().getWorkbook()?.getStyles().getNormal() ?? null, r = t.getNamed().getName(), i = r === (n?.getNamed().getName() ?? "Normal"), a = Le(t.getNumberFormat()), o = n ? j(t, n) : null, s = D(t), c = te(t), l = n ? A(t, n) : null, u = [
2787
+ i ? null : r,
2788
+ a ? `format ${a}` : null,
2789
+ o ? `font ${o}` : null,
2790
+ s ? `fill ${s}` : null,
2791
+ c.length > 0 ? `border ${c.join(", ")}` : null,
2792
+ l ? `align ${l}` : null
2793
+ ].filter(Boolean);
2794
+ return u.length > 0 ? u.join(" · ") : null;
2795
+ }(t);
2796
+ h && e.fact(`Style (effective): ${h}`), e.toLines().length > a && e.blank();
2797
+ })(r, e);
2798
+ let o = function(e, t) {
2799
+ if (!t.getFormulaText() && t.getType() === m.Null) return null;
2800
+ let n = e.getSurrounding({ contentOnly: !0 });
2801
+ return n.isSingleCell() ? null : n;
2802
+ }(n, e);
2803
+ return o && function(e, t, n) {
2804
+ let r = t.getCoords(), i = t.getSheet();
2805
+ e.h2(`Current Region — ${n.getAddress()} · ${n.getRowCount()}×${n.getColumnCount()}`);
2806
+ let a = ce(n), o = (e) => {
2807
+ if (!a || a.byColumn !== (e === "row")) return null;
2808
+ let t = e === "row" ? r.rowIndex : r.colIndex;
2809
+ if (t < a.start) return null;
2810
+ let n = a.lines.find((e) => e.index === t);
2811
+ if (n?.sums) return `totals, ${de(n.sums)}`;
2812
+ let i = a.byColumn ? `row ${a.start + 1}` : `column ${N(a.start)}`;
2813
+ return t === a.start ? "totals" : `below the totals ${i}`;
2814
+ }, s = [["row", [
2815
+ String(r.rowIndex + 1),
2816
+ re(M(i, r, "row")),
2817
+ o("row")
2818
+ ].filter(Boolean).join(" · ")], ["column", [
2819
+ N(r.colIndex),
2820
+ re(M(i, r, "column")),
2821
+ o("column")
2822
+ ].filter(Boolean).join(" · ")]];
2823
+ for (let [t, n] of s) e.text(` ${t.padEnd(7)}${n}`);
2824
+ e.blank();
2825
+ }(r, e, o), function(e, t, n) {
2826
+ let r = t.getCoords(), i = n?.getCoords() ?? Br(r), a = t.getSheet(), o = a.getRange({
2827
+ rowStart: r.rowIndex,
2828
+ rowEnd: r.rowIndex,
2829
+ colStart: i.colStart,
2830
+ colEnd: i.colEnd
2831
+ }), s = a.getRange({
2832
+ rowStart: i.rowStart,
2833
+ rowEnd: i.rowEnd,
2834
+ colStart: r.colIndex,
2835
+ colEnd: r.colIndex
2836
+ }), c = [Vr(o, "row", r.colIndex), Vr(s, "column", r.rowIndex)].filter((e) => e !== null);
2837
+ if (c.length === 0) return;
2838
+ let l = c.reduce((e, t) => t.share > e.share ? t : e), u = l.axis === "row" ? r.colIndex : r.rowIndex, d = l.segments.filter((e) => e.end >= l.start && e.start <= l.end), f = l.end - l.start + 1, p = l.axis === "row" ? a.getRange({
2839
+ rowStart: r.rowIndex,
2840
+ rowEnd: r.rowIndex,
2841
+ colStart: l.start,
2842
+ colEnd: l.end
2843
+ }) : a.getRange({
2844
+ rowStart: l.start,
2845
+ rowEnd: l.end,
2846
+ colStart: r.colIndex,
2847
+ colEnd: r.colIndex
2848
+ }), m = l.axis === "row" ? "Row" : "Column";
2849
+ if (e.h2(`Formula ${m} — ${p.getAddress()} · ${l.share} of ${f} consistent`), l.share < f) {
2850
+ let t = d.map((e) => {
2851
+ let t = u >= e.start && u <= e.end, n = e.range.getAddress(), r;
2852
+ if (e.r1c1 === null) r = e.range.isSingleCell() ? function(e) {
2853
+ let t = b(e, _.Mode.Display);
2854
+ return t ? `${t.display} typed` : "blank";
2855
+ }(e.range.getCell()) : e.end - e.start + 1 + " cells, no formula";
2856
+ else {
2857
+ let t = e.range.getCell().getFormulaText();
2858
+ r = `${e.r1c1 === l.key ? "" : "≠ "}${t}`;
2859
+ }
2860
+ return {
2861
+ address: n,
2862
+ detail: t ? `${r} ← this cell` : r
2863
+ };
2864
+ }), n = Math.max(...t.map((e) => e.address.length)), r = t.slice(0, zr);
2865
+ for (let t of r) e.text(` ${t.address.padEnd(n)} ${t.detail}`);
2866
+ t.length > r.length && e.text(` …${t.length - r.length} more · getRegions("formula") on ${p.getAddress()} lists them`);
1252
2867
  }
1253
- case "picture": return e.getResource?.()?.getName() || null;
1254
- default: return null;
2868
+ e.blank();
2869
+ }(r, e, o), await rr(r, e, t, {
2870
+ home: e.getSheet(),
2871
+ subject: n,
2872
+ zeroPrecedents: i,
2873
+ zeroDependents: i || a !== m.Null && a !== m.String
2874
+ }), r.toLines().join("\n").trimEnd();
2875
+ }
2876
+ var zr = 8, Br = (e) => ({
2877
+ rowStart: e.rowIndex,
2878
+ rowEnd: e.rowIndex,
2879
+ colStart: e.colIndex,
2880
+ colEnd: e.colIndex
2881
+ });
2882
+ function Vr(e, t, n) {
2883
+ if (e.isSingleCell()) return null;
2884
+ let r = [];
2885
+ for (let n of e.getRegions(Lr.Formula)) {
2886
+ let e = n.getCoords();
2887
+ r.push({
2888
+ start: t === "row" ? e.colStart : e.rowStart,
2889
+ end: t === "row" ? e.colEnd : e.rowEnd,
2890
+ r1c1: n.getCell().getFormulaText({ r1c1: !0 }) ?? "",
2891
+ range: n.getRange()
2892
+ });
1255
2893
  }
1256
- }, dt = (e) => {
1257
- let t = e.getContent(), n = [], r = ut(t);
1258
- r && n.push(r);
1259
- let i = e.getDescription();
1260
- i && n.push(lt(i));
1261
- let a = e.getName() || "(unnamed)", o = n.length > 0 ? `${a} — ${n.join(" · ")}` : a;
1262
- return c = 90, ((s = o).length > c ? `${s.slice(0, c - 1)}…` : s) + (e.isHidden() ? " (hidden)" : "");
1263
- var s, c;
1264
- };
1265
- function ft(e, t) {
1266
- if (t.length === 0) return;
1267
- let n = t.length > 50 ? t.slice(0, 50) : t, r = n.map((e) => ({
1268
- address: e.getRange().toString(),
1269
- type: e.getContent().getType(),
1270
- summary: dt(e)
1271
- }));
1272
- e.h2(`Movables (${t.length})`);
1273
- let i = Math.max(...r.map((e) => e.address.length)), a = Math.max(...r.map((e) => e.type.length));
1274
- for (let t of r) e.text(` ${t.address.padEnd(i)} ${t.type.padEnd(a)} ${t.summary}`.trimEnd());
1275
- n.length < t.length && e.text(` …and ${t.length - n.length} more`);
1276
- let o = [...new Set(r.map((e) => e.type).filter((e) => !ct.has(e)))];
1277
- o.length > 0 && e.text(` Not drawn: ${o.join(", ")} — SheetXL shows a labeled placeholder for these in the UI.`), e.blank();
1278
- }
1279
- function pt(e) {
1280
- let t = new z(), r = e.getRange(), i = e.getContent(), a = i.getType();
1281
- t.h1(`Movable — ${U(r)}`), t.blank(), t.fact(`Name: ${e.getName() || "(unnamed)"}`), t.fact(`Type: ${a}`);
1282
- let o = ut(i);
1283
- o && t.fact(`Content: ${o}`);
1284
- let s = e.getDescription();
1285
- s && t.fact(`Alt Text: ${lt(s)}`), t.fact(`Anchor: ${V(r)}, ${((e) => {
1286
- switch (e) {
1287
- case n.Type.Absolute: return "absolute — stays put when rows or columns move";
1288
- case n.Type.OneCell: return "oneCell — moves with the cells, keeps its size";
1289
- default: return "twoCell — moves and resizes with the cells";
1290
- }
1291
- })(e.getAnchorType?.())}`), t.fact(`Bounds: ${((e) => {
1292
- let t = e.getBounds();
1293
- if (!t) return "not laid out";
1294
- let n = (e) => Math.round(e);
1295
- return `${n(t.width)}×${n(t.height)} px at (${n(t.x)}, ${n(t.y)})`;
1296
- })(e)}`), e.isHidden() && t.fact("Hidden: true — this object is not visible in the UI");
1297
- let c = e.getRotation();
1298
- return c !== 0 && t.fact(`Rotation: ${c}°`), t.fact(`Z-Order: ${e.getZIndex()}`), t.fact(`Display: ${((e) => ct.has(e) ? "drawn" : `placeholder — SheetXL frames the ${e} at this position but does not draw its content`)(a)}`), t.blank(), t.text(`Sheet: ${H(r.getSheet().getName())}`), t.toLines().join("\n").trimEnd();
2894
+ if (r.length === 0) return null;
2895
+ r.sort((e, t) => e.start - t.start);
2896
+ let i = /* @__PURE__ */ new Map();
2897
+ for (let e of r) i.set(e.r1c1, (i.get(e.r1c1) ?? 0) + e.end - e.start + 1);
2898
+ let a = [...i].sort((e, t) => t[1] - e[1]);
2899
+ for (let [i, o] of a) {
2900
+ if (o < 2) break;
2901
+ let a = r.filter((e) => e.r1c1 === i), s = a[0].start, c = a[a.length - 1].end;
2902
+ if (n < s || n > c) continue;
2903
+ let l = [], u = s;
2904
+ for (let n of r) n.end < s || n.start > c || (n.start > u && l.push(Hr(e, t, u, n.start - 1)), l.push(n), u = n.end + 1);
2905
+ return {
2906
+ axis: t,
2907
+ segments: l,
2908
+ key: i,
2909
+ share: o,
2910
+ start: s,
2911
+ end: c
2912
+ };
2913
+ }
2914
+ return null;
2915
+ }
2916
+ function Hr(e, t, n, r) {
2917
+ let i = e.getCoords();
2918
+ return {
2919
+ start: n,
2920
+ end: r,
2921
+ r1c1: null,
2922
+ range: e.getSheet().getRange(t === "row" ? {
2923
+ rowStart: i.rowStart,
2924
+ rowEnd: i.rowEnd,
2925
+ colStart: n,
2926
+ colEnd: r
2927
+ } : {
2928
+ rowStart: n,
2929
+ rowEnd: r,
2930
+ colStart: i.colStart,
2931
+ colEnd: i.colEnd
2932
+ })
2933
+ };
1299
2934
  }
1300
- function mt(e, t) {
1301
- let n = new z();
1302
- n.h1(`Cell Range — ${U(e)}`), n.blank(), W(n, e), function(e, t, n) {
2935
+ async function Ur(e, t) {
2936
+ let n = new V();
2937
+ n.h1(`Cell Range — ${yt(e)}`);
2938
+ let r = Mr(e);
2939
+ r && n.text(`Protection: ${r}`), n.blank(), bt(n, e), function(e, t, n) {
1303
2940
  if (!1 === n?.profile || t.isSingleCell() || !t.isContentful()) return;
1304
- let r = M({
2941
+ let r = ae({
1305
2942
  getRowCount: () => t.getRowCount(),
1306
2943
  getColumnCount: () => t.getColumnCount(),
1307
2944
  getCell: () => t.getCell(),
@@ -1311,11 +2948,11 @@ function mt(e, t) {
1311
2948
  for (let t of r.series) e.text(` ${t}`);
1312
2949
  e.blank();
1313
2950
  }(n, e, t);
1314
- let i = function(e, t, n) {
1315
- let r = n?.mode ?? p.Mode.Display, i = n?.maxCells ?? 1e3, { rowStart: a, colStart: o } = t.getCoords(), s = t.getRowHeaders(), c = t.getColumnHeaders(), l = /* @__PURE__ */ new Map(), u = [], d = 0, f = !1;
2951
+ let a = function(e, t, n) {
2952
+ let r = n?.mode ?? _.Mode.Display, i = n?.maxCells ?? 1e3, { rowStart: a, colStart: o } = t.getCoords(), s = t.getRowHeaders(), c = t.getColumnHeaders(), l = /* @__PURE__ */ new Map(), u = [], d = 0, f = !1;
1316
2953
  t.forEach((e, t) => {
1317
2954
  if (d >= i) return f = !0, { break: !0 };
1318
- let n = t.getCell(), a = n.getFormulaText(), o = g(n, r);
2955
+ let n = t.getCell(), a = n.getFormulaText(), o = b(n, r);
1319
2956
  if (!o && !a) return;
1320
2957
  let s = {
1321
2958
  text: (o?.display ?? "").replace(/\|/g, "\\|").replace(/[\r\n]+/g, " "),
@@ -1328,38 +2965,38 @@ function mt(e, t) {
1328
2965
  let { rowIndex: p, colIndex: m } = t.getCoords(), h = l.get(p);
1329
2966
  h || (h = /* @__PURE__ */ new Map(), l.set(p, h)), h.set(m, s), d++;
1330
2967
  });
1331
- let m = Array.from(l.keys()).sort((e, t) => e - t), h = /* @__PURE__ */ new Set();
1332
- l.forEach((e) => e.forEach((e, t) => h.add(t)));
1333
- let _ = Array.from(h).sort((e, t) => e - t);
1334
- if (m.length === 0) return { spills: u };
1335
- let v = t.getIntersect({
1336
- rowStart: m[0],
1337
- rowEnd: m[m.length - 1],
1338
- colStart: _[0],
1339
- colEnd: _[_.length - 1]
1340
- }), y = `${d} cell${d === 1 ? "" : "s"}`, b = v.toString() !== t.toString();
1341
- e.h2(`Values (${b ? `${V(v)} · ` : ""}${y})`);
1342
- let x = e.beginFrame(_.map((e) => c.at(e - o).getText()));
1343
- for (let e of m) {
2968
+ let p = Array.from(l.keys()).sort((e, t) => e - t), m = /* @__PURE__ */ new Set();
2969
+ l.forEach((e) => e.forEach((e, t) => m.add(t)));
2970
+ let h = Array.from(m).sort((e, t) => e - t);
2971
+ if (p.length === 0) return { spills: u };
2972
+ let g = t.getIntersect({
2973
+ rowStart: p[0],
2974
+ rowEnd: p[p.length - 1],
2975
+ colStart: h[0],
2976
+ colEnd: h[h.length - 1]
2977
+ }), v = `${d} cell${d === 1 ? "" : "s"}`, y = g.toString() !== t.toString();
2978
+ e.h2(`Values (${y ? `${U(g)} · ` : ""}${v})`);
2979
+ let x = e.beginFrame(h.map((e) => c.at(e - o).getText()));
2980
+ for (let e of p) {
1344
2981
  let t = l.get(e);
1345
- x.addRow(_.map((e) => t?.get(e) ?? { text: "" }), s.at(e - a).getText());
2982
+ x.addRow(h.map((e) => t?.get(e) ?? { text: "" }), s.at(e - a).getText());
1346
2983
  }
1347
2984
  return x.endFrame(), f && e.text(`…truncated at ${i} cells · narrow the address, or summarize the whole range with getStats()`), e.blank(), { spills: u };
1348
2985
  }(n, e, t);
1349
2986
  return function(e, t, n) {
1350
- let i = [];
1351
- for (let e of t.getRegions(r.Feature.Formula)) {
2987
+ let r = [];
2988
+ for (let e of t.getRegions(i.Feature.Formula)) {
1352
2989
  let t = e.getCell().getFormulaText();
1353
- if (t && (i.push({
2990
+ if (t && (r.push({
1354
2991
  address: e.getAddress(),
1355
2992
  size: `${e.getRowCount()}×${e.getColumnCount()}`,
1356
- formula: `=${t}`
1357
- }), i.length >= (n?.maxRegions ?? 100))) break;
2993
+ formula: t
2994
+ }), r.length >= (n?.maxRegions ?? 100))) break;
1358
2995
  }
1359
- if (i.length === 0) return;
2996
+ if (r.length === 0) return;
1360
2997
  e.h2("Formulas");
1361
- let a = Math.max(...i.map((e) => e.address.length)), o = Math.max(...i.map((e) => e.size.length));
1362
- for (let t of i) e.text(` ${t.address.padEnd(a)} ${t.size.padEnd(o)} ${t.formula}`);
2998
+ let a = Math.max(...r.map((e) => e.address.length)), o = Math.max(...r.map((e) => e.size.length));
2999
+ for (let t of r) e.text(` ${t.address.padEnd(a)} ${t.size.padEnd(o)} ${t.formula}`);
1363
3000
  e.blank();
1364
3001
  }(n, e, t), function(e, t) {
1365
3002
  if (t.length === 0) return;
@@ -1367,51 +3004,54 @@ function mt(e, t) {
1367
3004
  let n = Math.max(...t.map((e) => e.address.length));
1368
3005
  for (let { address: r, valuesRange: i } of t) e.text(` ${r.padEnd(n)} ${i}`);
1369
3006
  e.blank();
1370
- }(n, i.spills), J(n, e), ft(n, e.getMovables()), rt(n, "Conditional Formats", e.getConditionalFormats(), k), rt(n, "Data Validations", e.getDataValidations(), _e), q(n, e, t), n.toLines().join("\n").trimEnd();
3007
+ }(n, a.spills), await Rt(n, e), hn(n, e.getMovables()), It(n, "Conditional Formats", e.getConditionalFormats(), $e), It(n, "Data Validations", e.getDataValidations(), et), await rr(n, e, t, {
3008
+ home: e.getSheet(),
3009
+ subject: e
3010
+ }), n.toLines().join("\n").trimEnd();
1371
3011
  }
1372
- function ht(e) {
1373
- let t = new z(), n = e.getRanges();
1374
- t.h1(`Conditional Format — ${Be(n)}`), t.blank(), t.fact(`Order: ${e.getIndex() + 1}`);
3012
+ function Wr(e) {
3013
+ let t = new V(), n = e.getRanges();
3014
+ t.h1(`Conditional Format — ${vt(n)}`), t.blank(), t.fact(`Order: ${e.getIndex() + 1}`);
1375
3015
  let r = e.getScale();
1376
- if (r) t.fact(`Rule: ${he(r)}`);
3016
+ if (r) t.fact(`Rule: ${Ze(r)}`);
1377
3017
  else {
1378
3018
  let n = e.getCondition();
1379
3019
  t.fact(`Rule: ${n?.toString() || "none — this rule tests nothing"}`);
1380
- let r = pe(e.getStyle());
3020
+ let r = Ye(e.getStyle());
1381
3021
  r && t.fact(`Format: ${r}`);
1382
3022
  }
1383
3023
  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();
1384
3024
  }
1385
- function gt(e) {
1386
- let t = new z();
3025
+ function Gr(e) {
3026
+ let t = new V();
1387
3027
  t.h1("Counts");
1388
3028
  let n = !1;
1389
3029
  for (let [r, i] of Object.entries(e)) i > 0 && (t.fact(`${r}: ${i}`), n = !0);
1390
3030
  return n || t.fact("None"), t.toLines().join("\n").trimEnd();
1391
3031
  }
1392
- function _t(e) {
1393
- let t = new z(), n = e.getRanges();
1394
- t.h1(`Data Validation — ${Be(n)}`), t.blank();
3032
+ function Kr(e) {
3033
+ let t = new V(), n = e.getRanges();
3034
+ t.h1(`Data Validation — ${vt(n)}`), t.blank();
1395
3035
  let r = e.getCondition();
1396
3036
  t.fact(`Rule: ${r?.toString() || "none — anything is accepted here"}`);
1397
- let i = ve(r);
3037
+ let i = tt(r);
1398
3038
  i && t.fact(`Allowed: ${i}`), t.fact("Blanks: " + (e.isIncludeBlanks() ? "allowed" : "rejected"));
1399
3039
  let a = e.getAlertStyle();
1400
- if (t.fact(`Alert: ${a}${a === o.AlertStyle.Stop ? " — the entry is refused" : " — the entry is accepted anyway"}`), e.isShowAlertMessage()) {
1401
- let n = vt(e.getAlertTitle(), e.getAlertMessage());
3040
+ if (t.fact(`Alert: ${a}${a === s.AlertStyle.Stop ? " — the entry is refused" : " — the entry is accepted anyway"}`), e.isShowAlertMessage()) {
3041
+ let n = qr(e.getAlertTitle(), e.getAlertMessage());
1402
3042
  n && t.fact(`Alert Message: ${n}`);
1403
3043
  }
1404
3044
  if (e.isShowPromptMessage()) {
1405
- let n = vt(e.getPromptTitle(), e.getPromptMessage());
3045
+ let n = qr(e.getPromptTitle(), e.getPromptMessage());
1406
3046
  n && t.fact(`Prompt: ${n}`);
1407
3047
  }
1408
3048
  return e.isHideDropdown() && t.fact("Dropdown: hidden"), t.fact(`Cells: ${n.size}`), t.toLines().join("\n").trimEnd();
1409
3049
  }
1410
- var vt = (e, t) => {
3050
+ var qr = (e, t) => {
1411
3051
  let n = [e?.trim(), t?.trim()].filter(Boolean);
1412
3052
  return n.length > 0 ? n.join(" — ") : null;
1413
- }, yt = "function", bt = "named", xt = "tableReference", St = "tableColumn", Ct = "externalReference", wt = [["isReferenceOnly", "reference-only"], ["isVolatile", "volatile"]], Tt = (e, t) => e ? ` (${H(e)}!${t})` : "";
1414
- function Et(e, t, n, r) {
3053
+ }, Jr = "function", Yr = "named", Xr = "tableReference", Zr = "tableColumn", Qr = "externalReference", $r = [["isReferenceOnly", "reference-only"], ["isVolatile", "volatile"]], ei = (e, t) => e ? ` (${W(e)}!${t})` : "";
3054
+ function ti(e, t, n, r) {
1415
3055
  if (e === "external") return "another workbook — not resolvable from here";
1416
3056
  if (!n) return "";
1417
3057
  switch (e) {
@@ -1422,17 +3062,17 @@ function Et(e, t, n, r) {
1422
3062
  case "named": return function(e, t) {
1423
3063
  let n = t.getNames(), r = n.getByName(e) ?? n.getByName(e, !0);
1424
3064
  if (r) {
1425
- let e = Tt(r.getScope(), r.getName()), t = r.getRanges?.();
3065
+ let e = ei(r.getScope(), r.getName()), t = r.getRanges?.();
1426
3066
  return !t || t.isInvalid() ? `defined name — reference does not resolve${e}` : `${t.toString()}${e}`;
1427
3067
  }
1428
3068
  let i = t.getCalculation().getNamedFormulas().getByName(e);
1429
- return i ? `=${i.getExpression()}${Tt(i.getScope(), i.getName())}` : "unknown — evaluates to #NAME?";
3069
+ return i ? `=${i.getExpression()}${ei(i.getScope(), i.getName())}` : "unknown — evaluates to #NAME?";
1430
3070
  }(t, n);
1431
3071
  case "table": {
1432
3072
  let e = n.getTables().getByName(t) ?? n.getWorkbook()?.getSheets().getItems().map((e) => e.getTables().getByName(t)).find(Boolean) ?? null;
1433
3073
  return e ? ((e, t) => {
1434
3074
  let n = e.getSheet(), r = e.toString();
1435
- return !n || t && n.getName() === t.getName() || r.includes("!") ? r : `${H(n.getName())}!${r}`;
3075
+ return !n || t && n.getName() === t.getName() || r.includes("!") ? r : `${W(n.getName())}!${r}`;
1436
3076
  })(e.getRange(), n) : "unknown — evaluates to #NAME?";
1437
3077
  }
1438
3078
  case "column": {
@@ -1445,9 +3085,9 @@ function Et(e, t, n, r) {
1445
3085
  }
1446
3086
  return "";
1447
3087
  }
1448
- async function Dt(e, t) {
1449
- let n = t?.maxTokens ?? 200, r = new z(), i = ((e) => e.isINamed ? e : null)(e);
1450
- if (r.h1(i ? `Name — ${G(i)}` : "Formula"), r.text(r.codespan("=" + e.getExpression())), r.blank(), i) {
3088
+ async function ni(e, t) {
3089
+ let n = t?.maxTokens ?? 200, r = new V(), i = ((e) => e.isINamed ? e : null)(e);
3090
+ if (r.h1(i ? `Name — ${Et(i)}` : "Formula"), r.text(r.codespan("=" + e.getExpression())), r.blank(), i) {
1451
3091
  i.isHidden() && r.fact("Hidden: true — not offered in the UI; formulas resolve it normally");
1452
3092
  let e = i.getComment();
1453
3093
  e && r.fact(`Comment: ${e}`);
@@ -1464,10 +3104,10 @@ async function Dt(e, t) {
1464
3104
  }
1465
3105
  if ((r = n) && typeof r == "object" && !0 === r.isIRange) return void e.fact(`Value: spills ${n.getRowCount()}×${n.getColumnCount()} — an array result`);
1466
3106
  var r;
1467
- let i = _(n);
3107
+ let i = x(n);
1468
3108
  e.fact(`Value: ${i ? i.display : "(empty)"}`);
1469
3109
  }(r, e), r.fact(`Status: ${e.getCalculationStatus()}`), e.isValid() || r.fact("Valid: false — the text did not parse as a complete expression");
1470
- let a = wt.filter(([t]) => e[t]()).map(([, e]) => e);
3110
+ let a = $r.filter(([t]) => e[t]()).map(([, e]) => e);
1471
3111
  a.length > 0 && r.fact(`Flags: ${a.join(" · ")}`), r.blank();
1472
3112
  let o = e.getReferences(), s = t?.context ?? o?.getSheet() ?? null, c = function(e, t) {
1473
3113
  let n = /* @__PURE__ */ new Map(), r = null;
@@ -1476,19 +3116,19 @@ async function Dt(e, t) {
1476
3116
  if (!e) continue;
1477
3117
  let a;
1478
3118
  switch (i.type) {
1479
- case yt:
3119
+ case Jr:
1480
3120
  a = "function";
1481
3121
  break;
1482
- case bt:
3122
+ case Yr:
1483
3123
  a = "named";
1484
3124
  break;
1485
- case xt:
3125
+ case Xr:
1486
3126
  a = "table", r = e;
1487
3127
  break;
1488
- case St:
3128
+ case Zr:
1489
3129
  a = "column";
1490
3130
  break;
1491
- case Ct:
3131
+ case Qr:
1492
3132
  a = "external";
1493
3133
  break;
1494
3134
  default: continue;
@@ -1498,7 +3138,7 @@ async function Dt(e, t) {
1498
3138
  kind: a,
1499
3139
  text: e,
1500
3140
  uses: 1,
1501
- resolution: Et(a, e, t, r)
3141
+ resolution: ti(a, e, t, r)
1502
3142
  });
1503
3143
  }
1504
3144
  return [...n.values()];
@@ -1521,8 +3161,8 @@ async function Dt(e, t) {
1521
3161
  }
1522
3162
  if (r.h2("References"), o && o.length !== 0) for (let e = 0; e < o.length; e++) r.text(` ${String(e).padStart(2)} ${o.at(e).getAddress()}`);
1523
3163
  else r.text("None");
1524
- r.blank(), i && function(e, t) {
1525
- t.getDirectDependents() || (e.h2("Dependents (0)"), e.text(" None — no formula references this name"), e.blank()), q(e, t);
3164
+ r.blank(), i && await async function(e, t) {
3165
+ await t.getDirectDependents() || (e.h2("Dependents (0)"), e.text(" None — no formula references this name"), e.blank()), await rr(e, t);
1526
3166
  }(r, i);
1527
3167
  let l = e.getTokens();
1528
3168
  if (r.h2("Tokens"), l.length === 0) r.text("None");
@@ -1551,103 +3191,223 @@ async function Dt(e, t) {
1551
3191
  }
1552
3192
  return r.toLines().join("\n").trimEnd();
1553
3193
  }
1554
- var Ot = [["formula", "Names"], ["table", "Tables"]];
1555
- function kt(e, t) {
1556
- let n = new z(), r = e.getItems({ includeHidden: !0 }) ?? [];
3194
+ var ri = [
3195
+ "Workbook_Open",
3196
+ "Auto_Open",
3197
+ "Workbook_BeforeClose",
3198
+ "Auto_Close",
3199
+ "Workbook_SheetChange",
3200
+ "Workbook_BeforeSave",
3201
+ "Workbook_NewSheet",
3202
+ "Worksheet_Change",
3203
+ "Worksheet_SelectionChange",
3204
+ "Worksheet_Activate",
3205
+ "Worksheet_BeforeDoubleClick",
3206
+ "Worksheet_Calculate"
3207
+ ], ii = (e) => {
3208
+ let t = [];
3209
+ for (let n of ri) RegExp(`(?:Sub|Function)\\s+${n}\\b`, "i").test(e) && t.push(n);
3210
+ return t;
3211
+ }, ai = (e) => {
3212
+ try {
3213
+ return e.getFunctions().getItems({ type: "autoRun" }).map((e) => e.getName());
3214
+ } catch {
3215
+ return [];
3216
+ }
3217
+ }, oi = (e) => {
3218
+ let t = e.getScope();
3219
+ return t ? !0 === t.isISheet ? `sheet '${t.getName()}'` : "workbook" : "global";
3220
+ }, si = (e) => {
3221
+ let t = ((e) => e.getSource()?.trim() ?? "")(e);
3222
+ return {
3223
+ module: e,
3224
+ name: e.getName(),
3225
+ language: e.getLanguage(),
3226
+ scope: oi(e),
3227
+ body: t,
3228
+ lines: t.length === 0 ? 0 : t.split("\n").length,
3229
+ runsInExcel: ii(t),
3230
+ runsHere: ai(e),
3231
+ executable: !!e.toJSON().compiled
3232
+ };
3233
+ };
3234
+ function ci(e) {
3235
+ let t = [], n = e.getModules?.();
3236
+ n && t.push(...n.getItems({ language: null }));
3237
+ for (let n of e.getSheets().getItems()) t.push(...n.getModules().getItems({ language: null }));
3238
+ return t;
3239
+ }
3240
+ function li(e, t, n) {
3241
+ if (t.length === 0) return;
3242
+ let r = t.map(si), i = r.filter((e) => e.lines > 0);
3243
+ if (i.length === 0) return e.h2("Code (none)"), e.text(`${r.length} module${r.length === 1 ? "" : "s"}, none with any source.`), void e.blank();
3244
+ e.h2(`Code (${i.length} module${i.length === 1 ? "" : "s"})`);
3245
+ let a = i.filter((e) => !e.executable);
3246
+ if (a.length > 0) {
3247
+ let t = [...new Set(a.map((e) => e.language))].sort();
3248
+ e.text(`SheetXL reads ${t.join(" and ")} as source only and never runs it.`), a.length === i.length && e.text("Values in this workbook were computed by whatever wrote the file, not by these modules."), e.blank();
3249
+ }
3250
+ let o = i.filter((e) => e.runsInExcel.length > 0 || e.runsHere.length > 0);
3251
+ if (o.length > 0) {
3252
+ e.text(e.bold("Runs on its own:"));
3253
+ for (let t of o) t.runsHere.length > 0 && e.fact(`${t.name} · ${t.runsHere.join(", ")} — SheetXL ran this when the workbook loaded`), t.runsInExcel.length > 0 && e.fact(`${t.name} · ${t.runsInExcel.join(", ")} — Excel runs this on open; SheetXL did not`);
3254
+ e.blank();
3255
+ }
3256
+ let s = n?.maxModules ?? 40, c = i.length > s ? i.slice(0, s) : i, l = (e) => [...e.runsHere, ...e.runsInExcel].join(", "), u = c.some((e) => l(e).length > 0), d = [
3257
+ "Module",
3258
+ "Language",
3259
+ "Scope",
3260
+ "Lines"
3261
+ ];
3262
+ u && d.push("Runs");
3263
+ let f = e.beginFrame(d);
3264
+ for (let e of c) {
3265
+ let t = [
3266
+ { text: e.name },
3267
+ { text: e.language },
3268
+ { text: e.scope },
3269
+ {
3270
+ text: String(e.lines),
3271
+ alignment: "right"
3272
+ }
3273
+ ];
3274
+ u && t.push({ text: l(e) }), f.addRow(t);
3275
+ }
3276
+ f.endFrame(), c.length < i.length && e.text(` …and ${i.length - c.length} more · wb.getModules() renders the full view`), e.blank();
3277
+ }
3278
+ function ui(e, t, n, r) {
3279
+ n(`Module — ${t.name}`), e.blank();
3280
+ let i = [
3281
+ `language: ${t.language}`,
3282
+ `scope: ${t.scope}`,
3283
+ `lines: ${t.lines === 0 ? "empty" : t.lines}`
3284
+ ];
3285
+ if (t.runsHere.length > 0 && i.push(`ran on load: ${t.runsHere.join(", ")}`), t.runsInExcel.length > 0 && i.push(`Excel runs on open: ${t.runsInExcel.join(", ")}`), e.fact(i), e.blank(), t.lines === 0) return void e.text("No source. Excel writes an empty document module for the workbook and for each sheet whether or not anyone wrote code in it.");
3286
+ t.executable || e.text(`SheetXL reads ${t.language} as source only and never runs it.`), e.blank();
3287
+ let a = r?.maxSourceLines ?? 200, o = t.body.split("\n"), s = o.length > a ? o.slice(0, a) : o;
3288
+ e.text(e.code(s.join("\n"), t.language)), s.length < o.length && e.text(`…and ${o.length - s.length} more lines · getSource() returns the whole module`);
3289
+ }
3290
+ function di(e, t) {
3291
+ let n = new V();
3292
+ return ui(n, si(e), (e) => n.h1(e), t), n.toLines().join("\n").trimEnd();
3293
+ }
3294
+ function fi(e, t) {
3295
+ let n = new V(), r = e.getItems({ language: null }) ?? [];
3296
+ if (n.h1(`Modules — ${r.length} module${r.length === 1 ? "" : "s"}`), n.blank(), r.length === 0) return n.text("None"), n.toLines().join("\n").trimEnd();
3297
+ let i = r.map(si);
3298
+ li(n, r, t);
3299
+ for (let e of i) e.lines !== 0 && (ui(n, e, (e) => n.h2(e), t), n.blank());
3300
+ return n.toLines().join("\n").trimEnd();
3301
+ }
3302
+ var pi = [["formula", "Names"], ["table", "Tables"]];
3303
+ async function mi(e, t) {
3304
+ let n = new V(), r = e.getItems({ includeHidden: !0 }) ?? [];
1557
3305
  if (n.h1(`Names — ${r.length} item${r.length === 1 ? "" : "s"}`), n.blank(), r.length === 0) return n.text("None"), n.toLines().join("\n").trimEnd();
1558
- let i = new Set(Ot.map(([e]) => e));
1559
- for (let [e, i] of Ot) K(n, r.filter((t) => t.getType() === e), {
3306
+ let i = new Set(pi.map(([e]) => e));
3307
+ for (let [e, i] of pi) await Pt(n, r.filter((t) => t.getType() === e), {
1560
3308
  ...t,
1561
3309
  heading: i,
1562
3310
  symbols: r
1563
3311
  });
1564
3312
  let a = r.filter((e) => !i.has(e.getType())), o = [...new Set(a.map((e) => e.getType()))].sort();
1565
- for (let e of o) K(n, a.filter((t) => t.getType() === e), {
3313
+ for (let e of o) await Pt(n, a.filter((t) => t.getType() === e), {
1566
3314
  ...t,
1567
3315
  heading: e,
1568
3316
  symbols: r
1569
3317
  });
1570
3318
  return n.toLines().join("\n").trimEnd();
1571
3319
  }
1572
- var Y = (e) => {
3320
+ var hi = (e) => {
1573
3321
  if (!e || typeof e != "object" || Array.isArray(e)) return !1;
1574
3322
  let t = Object.getPrototypeOf(e);
1575
3323
  return t === Object.prototype || t === null;
1576
3324
  };
1577
- function At(e, t) {
1578
- let n = t?.maxCells ?? 1e3, r = Array.isArray(e) ? e : [e], i = new z();
3325
+ function gi(e, t) {
3326
+ let n = t?.maxCells ?? 1e3, r = Array.isArray(e) ? e : [e], i = new V();
1579
3327
  if (i.h1("Records"), i.text(`Count: ${r.length}`), i.blank(), r.length === 0) return i.text("None"), i.toLines().join("\n").trimEnd();
1580
3328
  let a = (e) => {
1581
3329
  let t = [], n = /* @__PURE__ */ new Set();
1582
3330
  for (let r of e) for (let e of Object.keys(r ?? {})) n.has(e) || (n.add(e), t.push(e));
1583
3331
  return t;
1584
- }, o = Math.max(1, a(r).length), s = E(r.length, Math.max(1, Math.floor(n / o))), c = r.length > s ? r.slice(0, s) : r, l = c.length === r.length ? a(r) : a(c);
3332
+ }, o = Math.max(1, a(r).length), s = T(r.length, Math.max(1, Math.floor(n / o))), c = r.length > s ? r.slice(0, s) : r, l = c.length === r.length ? a(r) : a(c);
1585
3333
  if (l.length === 0) return i.text("No fields"), i.toLines().join("\n").trimEnd();
1586
3334
  let u = i.beginFrame(l);
1587
- for (let e of c) u.addRow(l.map((t) => jt(e?.[t])));
3335
+ for (let e of c) u.addRow(l.map((t) => _i(e?.[t])));
1588
3336
  return u.endFrame(), c.length < r.length && i.text(`…truncated at ${c.length} of ${r.length} records · filter, sort or aggregate the array in the expression`), i.toLines().join("\n").trimEnd();
1589
3337
  }
1590
- var jt = (e) => {
3338
+ var _i = (e) => {
1591
3339
  if (e == null) return { text: "" };
1592
3340
  if (typeof e == "function") return { text: "[Function]" };
1593
- if (typeof e == "bigint" || typeof e == "symbol") return { text: X(String(e)) };
3341
+ if (typeof e == "bigint" || typeof e == "symbol") return { text: yi(String(e)) };
1594
3342
  if (typeof e == "object") {
1595
3343
  if (e instanceof Date) return { text: e.toISOString() };
1596
3344
  let t = e;
1597
- if (!0 === t.isFormulaError || !0 === t.isIRichData) return { text: X(Mt(e)) };
1598
- if (Y(e) || Array.isArray(e)) {
3345
+ if (!0 === t.isFormulaError || !0 === t.isIRichData) return { text: yi(vi(e)) };
3346
+ if (hi(e) || Array.isArray(e)) {
1599
3347
  let t;
1600
3348
  try {
1601
3349
  t = JSON.stringify(e) ?? String(e);
1602
3350
  } catch {
1603
3351
  t = "[circular]";
1604
3352
  }
1605
- return { text: X(t) };
3353
+ return { text: yi(t) };
1606
3354
  }
1607
- return { text: X(String(e)) };
3355
+ return { text: yi(String(e)) };
1608
3356
  }
1609
- let t = X(Mt(e).replace(/[\r\n]+/g, " "));
3357
+ let t = yi(vi(e).replace(/[\r\n]+/g, " "));
1610
3358
  return typeof e == "number" ? {
1611
3359
  text: t,
1612
3360
  alignment: "right"
1613
3361
  } : { text: t };
1614
- }, Mt = (e) => {
3362
+ }, vi = (e) => {
1615
3363
  try {
1616
- return _(e)?.match ?? String(e);
3364
+ return x(e)?.match ?? String(e);
1617
3365
  } catch {
1618
3366
  return String(e);
1619
3367
  }
1620
- }, X = (e) => e.length > 80 ? `${e.slice(0, 79)}…` : e;
1621
- function Nt(e, t) {
1622
- let n = e.length, r = E(n, t?.maxRanges ?? 100), i = Math.min(n, r), a = [];
3368
+ }, yi = (e) => e.length > 80 ? `${e.slice(0, 79)}…` : e;
3369
+ function bi(e, t) {
3370
+ let n = e.length, r = T(n, t?.maxRanges ?? 100), i = Math.min(n, r), a = [];
1623
3371
  for (let t = 0; t < i; t++) {
1624
3372
  let n = e.at(t);
1625
3373
  a.push({
1626
- ...et(n),
1627
- detail: tt(n)
3374
+ ...hr(n),
3375
+ detail: [gr(n), pr(n)].filter(Boolean).join(" ")
1628
3376
  });
1629
3377
  }
1630
- let o = a.filter((e) => !e.isName), s = o.length > 0 && o.some((e) => e.sheet !== o[0].sheet), c = o.length > 0 ? o[0].sheet : e.getSheet()?.getName(), l = new z(), u = a.length > 0 && !s && !!c;
1631
- if (l.h1(u ? `Ranges — ${H(c)} (${n})` : `Ranges (${n})`), a.length === 0) return l.text("none"), l.toLines().join("\n").trimEnd();
1632
- let d = a.map((e) => s && !e.isName ? `${H(e.sheet)}!${e.address}` : e.address), f = Math.max(...d.map((e) => e.length));
3378
+ let o = a.filter((e) => !e.isName), s = o.length > 0 && o.some((e) => e.sheet !== o[0].sheet), c = o.length > 0 ? o[0].sheet : e.getSheet()?.getName(), l = new V(), u = a.length > 0 && !s && !!c;
3379
+ if (l.h1(u ? `Ranges — ${W(c)} (${n})` : `Ranges (${n})`), a.length === 0) return l.text("none"), l.toLines().join("\n").trimEnd();
3380
+ let d = a.map((e) => s && !e.isName ? `${W(e.sheet)}!${e.address}` : e.address), f = Math.max(...d.map((e) => e.length));
1633
3381
  for (let e = 0; e < a.length; e++) l.text(` ${d[e].padEnd(f)} ${a[e].detail}`.trimEnd());
1634
3382
  return i < n && l.text(` …and ${n - i} more · loop the collection in code to see them all`), l.toLines().join("\n").trimEnd();
1635
3383
  }
1636
- function Pt(e, t) {
1637
- let n = new z(), r = e.getSelectedRange(), i = e.getUsedRange();
1638
- n.h1(`Sheet — ${H(e.getName())}${function(e) {
3384
+ var xi = (e) => /<location\b[^>]*?\sref="([^"]*)"/.exec(e.getXML() ?? "")?.[1] ?? "";
3385
+ async function Si(e, t) {
3386
+ let n = new V(), r = e.getSelectedRange(), i = e.getUsedRange();
3387
+ n.h1(`Sheet — ${W(e.getName())}${function(e) {
1639
3388
  let t = e.getWorkbook(), n = "";
1640
3389
  t && t.getSelectedSheet()?.getId() === e.getId() && (n += " (selected)");
1641
3390
  let r = e.getVisibility();
1642
- return r === l.Visibility.Hidden ? n += " (hidden)" : r === l.Visibility.VeryHidden && (n += " (very hidden)"), n;
1643
- }(e)}`), n.text(`Used: ${i ? V(i) : "empty"}`), n.text(`Selection: ${V(r)}`), n.blank();
3391
+ return r === d.Visibility.Hidden ? n += " (hidden)" : r === d.Visibility.VeryHidden && (n += " (very hidden)"), e.getProtection().isLocked() && (n += " (protected)"), n;
3392
+ }(e)}`), n.text(`Used: ${i ? U(i) : "empty"}`), n.text(`Selection: ${U(r)}`), n.blank();
1644
3393
  let a = i ?? r;
1645
- return W(n, a), Ve(n, a, {
3394
+ bt(n, a), xt(n, a, {
1646
3395
  profile: !0,
1647
3396
  ...t
1648
- }), J(n, a), ft(n, e.getMovables().getItems()), n.toLines().join("\n").trimEnd();
3397
+ });
3398
+ let o = t?.features === void 0 ? null : typeof t.features == "string" ? [t.features] : [...t.features];
3399
+ return o && !o.some((e) => e === "unlock" || e === "protection") || jr(n, e), await Rt(n, a), function(e, t) {
3400
+ if (t.length === 0) return;
3401
+ let n = t.map((e) => ({
3402
+ address: xi(e),
3403
+ name: e.getName()
3404
+ })), r = Math.max(...n.map((e) => e.address.length));
3405
+ e.h2(`Pivot Tables (${t.length})`);
3406
+ for (let t of n) e.text(r > 0 ? ` ${t.address.padEnd(r)} ${t.name}` : ` ${t.name}`);
3407
+ e.text(" Read-only — the cells hold the last refresh; getXML() on one is its definition."), e.blank();
3408
+ }(n, e.getPivotTables().getItems()), hn(n, e.getMovables().getItems()), n.toLines().join("\n").trimEnd();
1649
3409
  }
1650
- var Ft = [
3410
+ var Ci = 1e4, wi = [
1651
3411
  ["numericalCount", "Numbers"],
1652
3412
  ["sum", "Sum"],
1653
3413
  ["min", "Min"],
@@ -1655,288 +3415,491 @@ var Ft = [
1655
3415
  ["average", "Average"],
1656
3416
  ["stdDev", "StdDev"]
1657
3417
  ];
1658
- function It(e) {
1659
- let t = new z();
1660
- t.h1("Stats");
1661
- let n = e.getTypedCounts();
1662
- t.fact(`Cells: ${e.getSize()}`), t.fact(`Values: ${e.getCount()}`);
1663
- let r = n[f.Error] ?? 0;
1664
- r > 0 && t.fact(`Errors: ${r}`);
1665
- let i = e.getAggregates({ onError: "ignore" });
1666
- for (let [e, n] of Ft) {
1667
- let r = i[e];
1668
- r != null && t.fact(`${n}: ${m(r)}`);
1669
- }
1670
- let a = [];
1671
- for (let [e, t] of Object.entries(n)) e !== f.Null && t && a.push(`${e.charAt(0).toUpperCase()}${e.slice(1)}: ${t}`);
1672
- return a.length > 0 && (t.blank(), t.h2("Type"), t.fact(a)), t.toLines().join("\n").trimEnd();
1673
- }
1674
- function Lt(e) {
1675
- let t = new z();
3418
+ function Ti(t) {
3419
+ let n = new V(), r = t.getCoords(), i = r ? e.rangeToString(r) : null;
3420
+ n.h1(i ? `Stats — ${i}` : "Stats");
3421
+ let a = t.getTypedCounts();
3422
+ n.fact(`Cells: ${t.getSize()}`), n.fact(`Values: ${t.getCount()}`);
3423
+ let o = a[m.Error] ?? 0;
3424
+ o > 0 && n.fact(`Errors: ${o}`);
3425
+ let s = function(e) {
3426
+ let t = e.getFrequencies({ limit: Ci }), n = t.getUniqueCount();
3427
+ if (n === 0) return null;
3428
+ if (t.isTruncated()) return `${n.toLocaleString("en-US")}+ (scan capped at ${Ci.toLocaleString("en-US")})`;
3429
+ if (n === t.getTotalCount()) return `${n.toLocaleString("en-US")}, no repeats`;
3430
+ let r = [];
3431
+ for (let [e, n] of t.getValueCounts()) {
3432
+ let i = t.getExtent(e);
3433
+ r.push({
3434
+ label: x(e)?.display ?? "",
3435
+ content: n,
3436
+ styled: n,
3437
+ blocks: i && Ei(i) === n ? [i] : []
3438
+ });
3439
+ }
3440
+ let i = {
3441
+ countStyle: "times",
3442
+ maxValues: 8,
3443
+ recovery: "getStats().getFrequencies()"
3444
+ };
3445
+ if (n <= 8) return `${n} · ${I(r, i)}`;
3446
+ let a = r.filter((e) => e.content > 1);
3447
+ return `${n.toLocaleString("en-US")} · repeats ${I(a, i)}`;
3448
+ }(t);
3449
+ s && n.fact(`Distinct: ${s}`);
3450
+ let c = t.getAggregates({ onError: "ignore" });
3451
+ for (let [e, t] of wi) {
3452
+ let r = c[e];
3453
+ r != null && n.fact(`${t}: ${v(r)}`);
3454
+ }
3455
+ let l = [];
3456
+ for (let [e, t] of Object.entries(a)) e !== m.Null && t && l.push(`${e.charAt(0).toUpperCase()}${e.slice(1)}: ${t}`);
3457
+ return l.length > 0 && (n.blank(), n.h2("Type"), n.fact(l)), n.toLines().join("\n").trimEnd();
3458
+ }
3459
+ var Ei = (e) => (e.rowEnd - e.rowStart + 1) * (e.colEnd - e.colStart + 1);
3460
+ function Di(e) {
3461
+ let t = new V();
1676
3462
  t.h1("Style"), t.text(`Named: ${e.getNamed().getName()}`), t.blank();
1677
3463
  let n = e.toJSON(), r = n ? Object.entries(n).filter(([, e]) => e !== void 0) : [];
1678
3464
  if (r.length === 0) t.fact("No direct styling (inherits the named style)");
1679
3465
  else for (let [e, n] of r) t.fact(`${e}: ${t.codespan(typeof n == "string" ? n : JSON.stringify(n))}`);
1680
3466
  return t.toLines().join("\n").trimEnd();
1681
3467
  }
1682
- function Rt(e, t) {
1683
- let n = t?.maxCells ?? 1e3, r = zt(e) ? e.getValues() : e, i = r.length, a = r.reduce((e, t) => Math.max(e, t?.length ?? 0), 0), o = new z();
3468
+ function Oi(e, t) {
3469
+ let n = t?.maxCells ?? 1e3, r = ki(e) ? e.getValues() : e, i = r.length, a = r.reduce((e, t) => Math.max(e, t?.length ?? 0), 0), o = new V();
1684
3470
  if (o.h1("Values"), o.text(`Size: ${i}×${a}`), o.blank(), i === 0 || a === 0) return o.text("None"), o.toLines().join("\n").trimEnd();
1685
- let s = E(i, Math.max(1, Math.floor(n / a))), c = i > s ? r.slice(0, s) : r, l = o.beginFrame(Array(a).fill(""));
1686
- for (let e of c) l.addRow(Array.from({ length: a }, (t, n) => Bt(e?.[n])));
3471
+ let s = T(i, Math.max(1, Math.floor(n / a))), c = i > s ? r.slice(0, s) : r, l = o.beginFrame(Array(a).fill(""));
3472
+ for (let e of c) l.addRow(Array.from({ length: a }, (t, n) => Ai(e?.[n])));
1687
3473
  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("\n").trimEnd();
1688
3474
  }
1689
- var zt = (e) => !!e && typeof e == "object" && !0 === e.isIRange, Bt = (e) => {
3475
+ var ki = (e) => !!e && typeof e == "object" && !0 === e.isIRange, Ai = (e) => {
1690
3476
  if (e == null) return { text: "" };
1691
- let t = (_(e)?.display ?? "").replace(/[\r\n]+/g, " ");
3477
+ let t = (x(e)?.display ?? "").replace(/[\r\n]+/g, " ");
1692
3478
  return typeof e == "number" ? {
1693
3479
  text: t,
1694
3480
  alignment: "right"
1695
3481
  } : { text: t };
1696
- }, Z = r.Feature;
1697
- function Vt(e, t) {
1698
- let n = new z();
1699
- n.h1(`Workbook — ${e.getName() ?? "Untitled"}`), n.text(`Locale: ${e.getRuntime().getLocale()}`), n.blank();
1700
- let r = e.getSheets().getItems({ visibility: l.Visibility.VeryHidden }), i = e.getSelectedSheet(), a = [];
1701
- for (let e of r) {
1702
- let t = e.getUsedRange();
1703
- a.push({
3482
+ }, Z = i.Feature, ji = [
3483
+ [Z.Font, "fonts"],
3484
+ [Z.NumberFormat, "formats"],
3485
+ [Z.Fill, "fills"],
3486
+ [Z.Borders, "borders"],
3487
+ [Z.Alignment, "alignments"]
3488
+ ];
3489
+ async function Mi(e, t) {
3490
+ let n = new V();
3491
+ n.h1(`Workbook — ${e.getName() ?? "Untitled"}`), n.text(`Locale: ${e.getRuntime().getLocale()}`);
3492
+ let i = e.getCalculation();
3493
+ i.getStatus() === r.Status.Off ? n.text("Calculation: off — formulas have not been evaluated; values are as loaded. wb.getCalculation().calculate() evaluates them") : i.getStatus() === r.Status.Error ? n.text("Calculation: error — the engine failed to start; values are as loaded. wb.getCalculation().start() tries again") : i.getCalculationMode() === r.CalculationMode.Manual && n.text("Calculation: manual — values are as of the last calculation. wb.getCalculation().calculate() refreshes them");
3494
+ let a = Er(e.getProtection());
3495
+ a && n.text(`Protection: ${a}`), n.blank();
3496
+ let o = e.getSheets().getItems({ visibility: d.Visibility.VeryHidden }), s = e.getSelectedSheet(), c = e.getStyles().getNormal(), l = [];
3497
+ for (let e of o) {
3498
+ let t = Ni(e, c);
3499
+ l.push({
1704
3500
  sheet: e,
1705
- label: Ht(e, e.getId() === i.getId()),
1706
- used: t?.toString() ?? "empty",
1707
- counts: t?.getCounts([
1708
- Z.Contentful,
1709
- Z.Formula,
1710
- Z.Error,
1711
- Z.CalcError,
1712
- Z.Circular
1713
- ]) ?? null
3501
+ label: Ri(e, e.getId() === s.getId()),
3502
+ counts: t.counts,
3503
+ lines: t.lines,
3504
+ formulaSignature: t.formulaSignature
1714
3505
  });
1715
3506
  }
1716
- let o = a;
1717
- if (a.length > 50) {
1718
- o = a.slice(0, 50);
1719
- let e = a.find((e) => e.sheet.getId() === i.getId());
1720
- e && !o.includes(e) && (o[o.length - 1] = e);
1721
- }
1722
- n.h2(`Sheets (${a.length})`);
1723
- let s = n.beginFrame([
1724
- "Sheet",
1725
- "Used",
1726
- "Cells",
1727
- "Formulas",
1728
- "Errors"
1729
- ]);
1730
- for (let e of o) s.addRow([
1731
- { text: e.label },
1732
- { text: e.used },
1733
- {
1734
- text: String(e.counts?.[Z.Contentful] ?? 0),
1735
- alignment: "right"
1736
- },
1737
- {
1738
- text: String(e.counts?.[Z.Formula] ?? 0),
1739
- alignment: "right"
1740
- },
1741
- {
1742
- text: String(e.counts?.[Z.Error] ?? 0),
1743
- alignment: "right"
3507
+ let u = /* @__PURE__ */ new Map();
3508
+ for (let e of l) {
3509
+ if (!e.formulaSignature) continue;
3510
+ let t = u.get(e.formulaSignature);
3511
+ t ? t.push(e) : u.set(e.formulaSignature, [e]);
3512
+ }
3513
+ for (let e of u.values()) if (!(e.length < 2)) for (let t of e) {
3514
+ let n = e.filter((e) => e !== t).map((e) => W(e.sheet.getName()));
3515
+ t.lines.push({
3516
+ label: "twin of",
3517
+ extent: n.join(", "),
3518
+ detail: ""
3519
+ });
3520
+ }
3521
+ let f = l;
3522
+ if (l.length > 250) {
3523
+ f = l.slice(0, 250);
3524
+ let e = l.find((e) => e.sheet.getId() === s.getId());
3525
+ e && !f.includes(e) && (f[f.length - 1] = e);
3526
+ }
3527
+ n.h2(`Sheets (${l.length})`), n.blank();
3528
+ let p = f.flatMap((e) => e.lines).filter((e) => e.detail), m = Math.max(9, ...f.flatMap((e) => e.lines).map((e) => e.label.length)) + 1, h = Math.max(0, ...p.map((e) => e.extent.length)) + 2;
3529
+ for (let e of f) {
3530
+ n.h3(e.label), e.lines.length === 0 && n.text(" empty");
3531
+ for (let t of e.lines) {
3532
+ let e = t.detail ? ` ${t.label.padEnd(m)}${t.extent.padEnd(h)}${t.detail}` : ` ${t.label.padEnd(m)}${t.extent}`;
3533
+ n.text(e.trimEnd());
1744
3534
  }
1745
- ]);
1746
- if (a.length > 1) {
1747
- let e = (e) => a.reduce((t, n) => t + (n.counts?.[e] ?? 0), 0);
1748
- s.addRow([
1749
- { text: "Total" },
1750
- { text: "" },
1751
- {
1752
- text: String(e(Z.Contentful)),
1753
- alignment: "right"
1754
- },
1755
- {
1756
- text: String(e(Z.Formula)),
1757
- alignment: "right"
1758
- },
1759
- {
1760
- text: String(e(Z.Error)),
1761
- alignment: "right"
1762
- }
1763
- ]);
3535
+ n.blank();
1764
3536
  }
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({
3537
+ return f.length < l.length && (n.text(`…and ${l.length - f.length} more sheets · wb.getSheets().getItems() lists all`), n.blank()), zi(n, "Errors", l, Z.Error), zi(n, "Calc Failures", l, Z.CalcError), zi(n, "Circular References", l, Z.Circular), await Pt(n, e.getNames().getItems({
1766
3538
  type: "formula",
1767
3539
  includeHidden: !0
1768
3540
  }) ?? [], {
1769
3541
  maxNames: t?.maxNames ?? 30,
1770
3542
  recovery: "wb.getNames() renders the full view",
1771
3543
  symbols: e.getNames().getItems({ includeHidden: !0 }) ?? []
3544
+ }), li(n, ci(e), t), n.toLines().join("\n").trimEnd();
3545
+ }
3546
+ function Ni(e, t) {
3547
+ let n = e.getUsedRange();
3548
+ if (!n) return {
3549
+ counts: null,
3550
+ lines: [...Pi(e), ...Fi(e)],
3551
+ formulaRegions: 0,
3552
+ formulaSignature: ""
3553
+ };
3554
+ let r = n.getCounts([
3555
+ Z.Contentful,
3556
+ Z.Formula,
3557
+ Z.Error,
3558
+ Z.CalcError,
3559
+ Z.Circular,
3560
+ Z.Table
3561
+ ]), i = [], a = St(n), o = [...n.getRegions(Z.Formula)];
3562
+ if (a.length > 0) {
3563
+ let e = function(e, t) {
3564
+ let n = He(e, t);
3565
+ return n.length === 0 ? null : n.map(([e, t]) => `${e} ×${Te(t)}`).join(" · ");
3566
+ }(n, o);
3567
+ i.push({
3568
+ label: "content",
3569
+ extent: Li(a),
3570
+ detail: [
3571
+ Q(r[Z.Contentful] ?? 0, "cell"),
3572
+ Q(a.length, "block"),
3573
+ e,
3574
+ `${G(n)} lists the blocks`
3575
+ ].filter(Boolean).join(" · ")
3576
+ });
3577
+ }
3578
+ let s = "";
3579
+ if (o.length > 0) {
3580
+ let e = /* @__PURE__ */ new Set(), t = [];
3581
+ for (let n of o) {
3582
+ let r = n.getCell().getFormulaText({ r1c1: !0 }) ?? "";
3583
+ e.add(r), t.push(`${n.toString()}${r}`);
3584
+ }
3585
+ s = t.sort().join("\n"), i.push({
3586
+ label: "formula",
3587
+ extent: Li(o),
3588
+ detail: [
3589
+ Q(r[Z.Formula] ?? 0, "cell"),
3590
+ Q(o.length, "region"),
3591
+ `${e.size} distinct`
3592
+ ].join(" · ")
3593
+ });
3594
+ }
3595
+ for (let [e, t] of [
3596
+ [Z.Error, "errors"],
3597
+ [Z.CalcError, "calc failures"],
3598
+ [Z.Circular, "circular"]
3599
+ ]) {
3600
+ let a = r[e] ?? 0;
3601
+ if (a === 0) continue;
3602
+ let o = [...n.getRegions(e)];
3603
+ i.push({
3604
+ label: t,
3605
+ extent: Li(o),
3606
+ detail: [Q(a, "cell"), Q(o.length, "region")].join(" · ")
3607
+ });
3608
+ }
3609
+ let c = n.getTables();
3610
+ c.length > 0 && i.push({
3611
+ label: "tables",
3612
+ extent: Li(c.map((e) => e.getRange())),
3613
+ detail: [
3614
+ Q(r[Z.Table] ?? 0, "cell"),
3615
+ Q(c.length, "table"),
3616
+ Ii(c.map((e) => e.getName()))
3617
+ ].join(" · ")
1772
3618
  });
1773
- let c = t?.maxSheets ?? 8, u = a.filter((e) => e.sheet.getUsedRange() !== null), d = u.slice(0, c), f = u.find((e) => e.sheet.getId() === i.getId());
1774
- f && !d.includes(f) && (d[d.length - 1] = f), n.setHeadingOffset(1);
1775
- for (let e of d) {
1776
- let r = e.sheet.getUsedRange();
1777
- r && (n.h1(`Sheet — ${e.label}`), W(n, r), Ve(n, r, {
1778
- features: t?.features,
1779
- maxRegions: t?.maxRegions ?? 25,
1780
- profile: !0,
1781
- maxProfiled: t?.maxProfiled ?? 4
1782
- }), J(n, r));
1783
- }
1784
- return n.setHeadingOffset(0), d.length < u.length && n.text(`…and ${u.length - d.length} more sheets not expanded · a sheet report (\`wb.getSheet('Name')\`) renders one in full`), n.toLines().join("\n").trimEnd();
1785
- }
1786
- function Ht(e, t) {
3619
+ let l = e.getPivotTables().getItems();
3620
+ l.length > 0 && i.push({
3621
+ label: "pivots",
3622
+ extent: String(l.length),
3623
+ detail: Ii(l.map((e) => e.getName()))
3624
+ }), i.push(...Pi(e));
3625
+ let u = a.map((e) => e.getCoords()), d = [];
3626
+ for (let [n, r] of ji) {
3627
+ let i = Be(e, n, t, { content: u })?.distinct ?? 0;
3628
+ i > 0 && d.push(`${r} ${i}`);
3629
+ }
3630
+ return d.length > 0 && i.push({
3631
+ label: "style",
3632
+ extent: n.toString(),
3633
+ detail: d.join(" · ")
3634
+ }), i.push(...Fi(e)), {
3635
+ counts: r,
3636
+ lines: i,
3637
+ formulaRegions: o.length,
3638
+ formulaSignature: s
3639
+ };
3640
+ }
3641
+ function Pi(e) {
3642
+ let t = [];
3643
+ for (let [n, r] of mn(e.getMovables().getItems())) {
3644
+ let i = cn(r), a = n === "chart" ? Ii(r.map(un)) : i.length > 0 ? `${i.length} with text` : "";
3645
+ t.push({
3646
+ label: pn(n).toLowerCase(),
3647
+ extent: String(r.length),
3648
+ detail: a
3649
+ });
3650
+ let o = i.slice(0, T(i.length, 5));
3651
+ for (let e of o) t.push({
3652
+ label: "",
3653
+ extent: rn(e.movable),
3654
+ detail: on(e) + (e.movable.isHidden() ? " (hidden)" : "")
3655
+ });
3656
+ o.length < i.length && t.push({
3657
+ label: "",
3658
+ extent: "",
3659
+ detail: `…and ${i.length - o.length} more · wb.getSheet(${JSON.stringify(e.getName())}) quotes every one`
3660
+ });
3661
+ }
3662
+ return t;
3663
+ }
3664
+ function Fi(e) {
3665
+ let t = Ar(e);
3666
+ return t ? [{
3667
+ label: "protected",
3668
+ extent: t.extent,
3669
+ detail: t.detail
3670
+ }] : [];
3671
+ }
3672
+ function Ii(e) {
3673
+ let t = [], n = 0;
3674
+ for (let r of e) {
3675
+ let e = (t.length > 0 ? 2 : 0) + r.length;
3676
+ if (t.length > 0 && n + e > 60) break;
3677
+ t.push(r), n += e;
3678
+ }
3679
+ let r = e.length - t.length;
3680
+ return r > 0 ? `${t.join(", ")}, +${r} more` : t.join(", ");
3681
+ }
3682
+ function Li(t) {
3683
+ let n = null;
3684
+ for (let e of t) {
3685
+ let t = e.getCoords();
3686
+ n = n ? {
3687
+ rowStart: Math.min(n.rowStart, t.rowStart),
3688
+ colStart: Math.min(n.colStart, t.colStart),
3689
+ rowEnd: Math.max(n.rowEnd, t.rowEnd),
3690
+ colEnd: Math.max(n.colEnd, t.colEnd)
3691
+ } : t;
3692
+ }
3693
+ return n ? e.rangeToString(n) ?? "" : "";
3694
+ }
3695
+ var Q = (e, t) => `${e} ${t}${e === 1 ? "" : "s"}`;
3696
+ function Ri(e, t) {
1787
3697
  let n = e.getVisibility(), r = "";
1788
- return t && (r += " (selected)"), n === l.Visibility.Hidden ? r += " (hidden)" : n === l.Visibility.VeryHidden && (r += " (very hidden)"), `${H(e.getName())}${r}`;
3698
+ return t && (r += " (selected)"), n === d.Visibility.Hidden ? r += " (hidden)" : n === d.Visibility.VeryHidden && (r += " (very hidden)"), e.getProtection().isLocked() && (r += " (protected)"), `${W(e.getName())}${r}`;
1789
3699
  }
1790
- function Ut(e, t, n, r) {
1791
- let i = n.reduce((e, t) => e + (t.counts?.[r] ?? 0), 0);
1792
- if (i === 0) return;
1793
- let a = [], o = 0;
1794
- for (let e of n) {
1795
- if (!e.counts?.[r]) continue;
3700
+ function zi(t, n, r, i) {
3701
+ let a = r.reduce((e, t) => e + (t.counts?.[i] ?? 0), 0), o = i === Z.Error ? r.flatMap((e) => function(e) {
3702
+ let t = [];
3703
+ for (let n of e.getMovables().getItems({ type: "chart" })) {
3704
+ let e = K(n);
3705
+ if (e) for (let r of e.getSeries()) {
3706
+ let e = Wt(r);
3707
+ if (e.length === 0) continue;
3708
+ let i = r.getName();
3709
+ t.push({
3710
+ movable: n,
3711
+ detail: `series ${i ? `"${q(i)}"` : "(unnamed)"} ${e.join(" · ")}`
3712
+ });
3713
+ }
3714
+ }
3715
+ return t;
3716
+ }(e.sheet)) : [];
3717
+ if (a === 0 && o.length === 0) return;
3718
+ let s = [], c = 0;
3719
+ for (let e of r) {
3720
+ if (!e.counts?.[i]) continue;
1796
3721
  let t = e.sheet.getUsedRange();
1797
3722
  if (!t) continue;
1798
- let n = H(e.sheet.getName());
1799
- for (let e of t.getRegions(r)) o++, a.length >= 20 || a.push({
3723
+ let n = W(e.sheet.getName());
3724
+ for (let e of t.getRegions(i)) c++, s.length >= 20 || s.push({
1800
3725
  address: `${n}!${e.toString()}`,
1801
3726
  size: `${e.getRowCount()}×${e.getColumnCount()}`,
1802
- payload: Wt(e)
3727
+ payload: Bi(e)
3728
+ });
3729
+ }
3730
+ let l = o.slice(0, 20);
3731
+ for (let { movable: t, detail: n } of l) {
3732
+ let r = t.getRange();
3733
+ s.push({
3734
+ address: `${W(r.getSheet().getName())}!${e.rangeToString(r.getCoords()) ?? ""}`,
3735
+ size: "chart",
3736
+ payload: `${t.getName() || "(unnamed)"} · ${n}`
1803
3737
  });
1804
3738
  }
1805
- e.h2(`${t} (${i})`);
1806
- let s = Math.max(0, ...a.map((e) => e.address.length)), c = Math.max(0, ...a.map((e) => e.size.length));
1807
- for (let t of a) e.text(` ${t.address.padEnd(s)} ${t.size.padEnd(c)} ${t.payload}`.trimEnd());
1808
- o > a.length && e.text(` …and ${o - a.length} more · getRegions('${r}') on a sheet's used range lists the rest`), e.blank();
3739
+ let u = [];
3740
+ a > 0 && u.push(String(a)), o.length > 0 && u.push(`${o.length} in charts`), t.h2(`${n} (${u.join(" · ")})`);
3741
+ let d = Math.max(0, ...s.map((e) => e.address.length)), f = Math.max(0, ...s.map((e) => e.size.length));
3742
+ for (let e of s) t.text(` ${e.address.padEnd(d)} ${e.size.padEnd(f)} ${e.payload}`.trimEnd());
3743
+ c > s.length - l.length && t.text(` …and ${c - (s.length - l.length)} more · getRegions('${i}') on a sheet's used range lists the rest`), o.length > l.length && t.text(` …and ${o.length - l.length} more in charts · a sheet's report lists its charts under Charts`), t.blank();
1809
3744
  }
1810
- function Wt(e) {
1811
- let t = e.getCell(), n = g(t, p.Mode.Display)?.display ?? "", r = t.getFormulaText();
1812
- return r ? `${n} =${r}`.trim() : n;
3745
+ function Bi(e) {
3746
+ let t = e.getCell(), n = b(t, _.Mode.Display)?.display ?? "", r = t.getFormulaText();
3747
+ return r ? `${n} ${r}`.trim() : n;
1813
3748
  }
1814
- var Q = (e, t) => !!e && typeof e == "object" && !0 === e[t], Gt = [
3749
+ var $ = (e, t) => !!e && typeof e == "object" && !0 === e[t], Vi = {
3750
+ kind: "protectedRanges",
3751
+ is: (e) => $(e, "isIProtectedRangeCollection"),
3752
+ render: (e) => {
3753
+ let t = e.getItems();
3754
+ return t.length === 0 ? "# Unlocked Ranges (0)\nNone" : t.slice(0, Hi).map(Ir).concat(t.length > Hi ? [`…and ${t.length - Hi} more · render one at a time to see them`] : []).join("\n\n");
3755
+ }
3756
+ }, Hi = 20, Ui = [
1815
3757
  {
1816
3758
  kind: "workbook",
1817
- is: (e) => Q(e, "isIWorkbook"),
1818
- render: (e, t) => Vt(e, t)
3759
+ is: (e) => $(e, "isIWorkbook"),
3760
+ render: (e, t) => Mi(e, t)
1819
3761
  },
1820
3762
  {
1821
3763
  kind: "sheet",
1822
- is: (e) => Q(e, "isISheet"),
1823
- render: (e, t) => Pt(e, t)
3764
+ is: (e) => $(e, "isISheet"),
3765
+ render: (e, t) => Si(e, t)
1824
3766
  },
1825
3767
  {
1826
3768
  kind: "cell",
1827
- is: (e) => Q(e, "isICell"),
1828
- render: (e, t) => st(e, t)
3769
+ is: (e) => $(e, "isICell"),
3770
+ render: (e, t) => Rr(e, t)
1829
3771
  },
1830
3772
  {
1831
3773
  kind: "names",
1832
- is: (e) => Q(e, "isINamedCollection"),
1833
- render: (e, t) => kt(e, t)
3774
+ is: (e) => $(e, "isINamedCollection"),
3775
+ render: (e, t) => mi(e, t)
3776
+ },
3777
+ {
3778
+ kind: "modules",
3779
+ is: (e) => $(e, "isIModuleCollection"),
3780
+ render: (e, t) => fi(e, t)
3781
+ },
3782
+ {
3783
+ kind: "module",
3784
+ is: (e) => $(e, "isIModule"),
3785
+ render: (e, t) => di(e, t)
1834
3786
  },
1835
3787
  {
1836
3788
  kind: "formula",
1837
- is: (e) => Q(e, "isIFormula"),
1838
- render: (e, t) => Dt(e, t)
3789
+ is: (e) => $(e, "isIFormula"),
3790
+ render: (e, t) => ni(e, t)
1839
3791
  },
1840
3792
  {
1841
3793
  kind: "table",
1842
- is: (e) => Q(e, "isITable"),
1843
- render: (e) => Ne(e)
3794
+ is: (e) => $(e, "isITable"),
3795
+ render: (e) => ft(e)
1844
3796
  },
1845
3797
  {
1846
3798
  kind: "movable",
1847
- is: (e) => Q(e, "isIMovable"),
1848
- render: (e) => pt(e)
3799
+ is: (e) => $(e, "isIMovable"),
3800
+ render: (e) => _n(e)
1849
3801
  },
1850
3802
  {
1851
3803
  kind: "conditionalFormat",
1852
- is: (e) => Q(e, "isIConditionalFormat"),
1853
- render: (e) => ht(e)
3804
+ is: (e) => $(e, "isIConditionalFormat"),
3805
+ render: (e) => Wr(e)
1854
3806
  },
1855
3807
  {
1856
3808
  kind: "dataValidation",
1857
- is: (e) => Q(e, "isIDataValidation"),
1858
- render: (e) => _t(e)
3809
+ is: (e) => $(e, "isIDataValidation"),
3810
+ render: (e) => Kr(e)
3811
+ },
3812
+ {
3813
+ kind: "protection",
3814
+ is: (e) => $(e, "isISheetProtection") || $(e, "isIWorkbookProtection"),
3815
+ render: (e) => Fr(e)
3816
+ },
3817
+ Vi,
3818
+ {
3819
+ kind: "protectedRange",
3820
+ is: (e) => $(e, "isIProtectedRange"),
3821
+ render: (e) => Ir(e)
1859
3822
  },
1860
3823
  {
1861
3824
  kind: "stats",
1862
- is: (e) => Q(e, "isIRangeStats"),
1863
- render: (e) => It(e)
3825
+ is: (e) => $(e, "isIRangeStats"),
3826
+ render: (e) => Ti(e)
1864
3827
  },
1865
3828
  {
1866
3829
  kind: "counts",
1867
- is: (e) => Q(e, "isICellRangeCounts"),
1868
- render: (e) => gt(e)
3830
+ is: (e) => $(e, "isICellRangeCounts"),
3831
+ render: (e) => Gr(e)
1869
3832
  },
1870
3833
  {
1871
3834
  kind: "style",
1872
- is: (e) => Q(e, "isIStyle"),
1873
- render: (e) => Lt(e)
3835
+ is: (e) => $(e, "isIStyle"),
3836
+ render: (e) => Di(e)
1874
3837
  },
1875
3838
  {
1876
3839
  kind: "regions",
1877
- is: (e) => Q(e, "isICellRegions"),
1878
- render: (e, t) => je(e, t)
3840
+ is: (e) => $(e, "isICellRegions"),
3841
+ render: (e, t) => lt(e, t)
1879
3842
  },
1880
3843
  {
1881
3844
  kind: "cellRange",
1882
- is: (e) => Q(e, "isICellRange"),
1883
- render: (e, t) => mt(e, t)
3845
+ is: (e) => $(e, "isICellRange"),
3846
+ render: (e, t) => Ur(e, t)
1884
3847
  },
1885
3848
  {
1886
3849
  kind: "ranges",
1887
- is: (e) => Q(e, "isICellRanges"),
1888
- render: (e, t) => Nt(e, t)
3850
+ is: (e) => $(e, "isICellRanges"),
3851
+ render: (e, t) => bi(e, t)
1889
3852
  },
1890
3853
  {
1891
3854
  kind: "range",
1892
- is: (e) => Q(e, "isIRange"),
1893
- render: (e, t) => Rt(e, t)
3855
+ is: (e) => $(e, "isIRange"),
3856
+ render: (e, t) => Oi(e, t)
1894
3857
  },
1895
3858
  {
1896
3859
  kind: "values",
1897
3860
  is: (e) => Array.isArray(e) && e.length > 0 && e.every((e) => Array.isArray(e)),
1898
- render: (e, t) => Rt(e, t)
3861
+ render: (e, t) => Oi(e, t)
1899
3862
  },
1900
3863
  {
1901
3864
  kind: "records",
1902
- is: (e) => Array.isArray(e) && e.length > 0 && e.every(Y),
1903
- render: (e, t) => At(e, t)
3865
+ is: (e) => Array.isArray(e) && e.length > 0 && e.every(hi),
3866
+ render: (e, t) => gi(e, t)
1904
3867
  },
1905
3868
  {
1906
3869
  kind: "record",
1907
- is: (e) => Y(e),
1908
- render: (e, t) => At(e, t)
3870
+ is: (e) => hi(e),
3871
+ render: (e, t) => gi(e, t)
1909
3872
  },
1910
3873
  {
1911
3874
  kind: "items",
1912
- is: (e) => Array.isArray(e) && e.length > 0 && e.every((e) => !!$(e)),
3875
+ is: (e) => Array.isArray(e) && e.length > 0 && e.every((e) => !!Ki(e)),
1913
3876
  render: async (e, t) => {
1914
- let n = e.length > 20 ? e.slice(0, 20) : e, r = [];
1915
- for (let e of n) r.push(await $(e).render(e, t));
3877
+ let n = e.length > Hi ? e.slice(0, Hi) : e, r = [];
3878
+ for (let e of n) r.push(await Ki(e).render(e, t));
1916
3879
  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");
1917
3880
  }
1918
3881
  }
1919
- ], Kt = class extends Error {
3882
+ ], Wi = Ui.map((e) => e.kind), Gi = class extends Error {
1920
3883
  constructor(e) {
1921
3884
  super(e), this.name = "NoRendererError";
1922
3885
  }
1923
3886
  };
1924
- function $(e) {
1925
- for (let t of Gt) if (t.is(e)) return t;
3887
+ function Ki(e) {
3888
+ for (let t of Ui) if (t.is(e)) return t;
1926
3889
  return null;
1927
3890
  }
1928
- async function qt(e, t, n) {
3891
+ async function qi(e, t, n) {
1929
3892
  await e?.getCalculation().ready();
1930
- let r = $(t), i = t;
3893
+ let r = Ki(t), i = t;
1931
3894
  if (!r && i && typeof i == "object" && !Array.isArray(i) && typeof i[Symbol.iterator] == "function") {
1932
3895
  let e = [];
1933
3896
  for (let t of i) if (e.push(t), e.length >= 1e3) break;
1934
- i = e, r = $(i);
3897
+ i = e, r = Ki(i);
1935
3898
  }
1936
- if (!r) throw new Kt(`No markdown renderer for this value. Renderable kinds: ${Gt.map((e) => e.kind).join(", ")}.`);
3899
+ if (!r) throw new Gi(`No markdown renderer for this value. Renderable kinds: ${Wi.join(", ")}.`);
1937
3900
  return r.render(i, n);
1938
3901
  }
1939
- async function Jt(e, t, n) {
3902
+ async function Ji(e, t, n) {
1940
3903
  if (t === void 0) return {
1941
3904
  text: void 0,
1942
3905
  rendered: !0
@@ -1947,11 +3910,11 @@ async function Jt(e, t, n) {
1947
3910
  };
1948
3911
  if (typeof t == "object" && t) try {
1949
3912
  return {
1950
- text: await qt(e, t, n),
3913
+ text: await qi(e, t, n),
1951
3914
  rendered: !0
1952
3915
  };
1953
3916
  } catch (e) {
1954
- if (!(e instanceof Kt)) throw e;
3917
+ if (!(e instanceof Gi)) throw e;
1955
3918
  }
1956
3919
  return function(e) {
1957
3920
  if (e === null) return {
@@ -1961,7 +3924,7 @@ async function Jt(e, t, n) {
1961
3924
  switch (typeof e) {
1962
3925
  case "number":
1963
3926
  case "boolean": return {
1964
- text: _(e)?.display ?? String(e),
3927
+ text: x(e)?.display ?? String(e),
1965
3928
  rendered: !0
1966
3929
  };
1967
3930
  case "bigint":
@@ -1976,7 +3939,7 @@ async function Jt(e, t, n) {
1976
3939
  }
1977
3940
  let t = e;
1978
3941
  if (!0 === t.isFormulaError || !0 === t.isIRichData) return {
1979
- text: _(e)?.display ?? "",
3942
+ text: x(e)?.display ?? "",
1980
3943
  rendered: !0
1981
3944
  };
1982
3945
  let n;
@@ -1991,5 +3954,5 @@ async function Jt(e, t, n) {
1991
3954
  };
1992
3955
  }(t);
1993
3956
  }
1994
- var Yt = [T];
1995
- export { p as CellEncoding, y as GREP_FIELDS, b as GREP_FIELDS_DEFAULT, v as GrepField, z as MarkdownBuilder, Oe as MarkdownFrameSection, Kt as NoRendererError, Gt as RENDERERS, at as RENDER_OPTION_KEYS, Pe as REPORTED_FEATURES, Yt as TOOLS, q as appendDependencies, W as appendKinds, ft as appendMovables, K as appendNames, Ae as appendRegionList, Ve as appendRegions, rt as appendRules, J as appendSheetObjects, Me as appendTableDetails, P as countDates, ue as describeAlignment, ve as describeAllowedValues, oe as describeBorder, ce as describeBorderParts, D as describeColor, k as describeConditionalFormat, _e as describeDataValidation, V as describeExtent, ae as describeFill, de as describeFont, tt as describeNode, et as describeNodeLabel, le as describeNumberFormat, U as describeQualifiedExtent, G as describeQualifiedName, Be as describeQualifiedRanges, ze as describeRanges, pe as describeRuleStyle, A as describeRules, he as describeScale, Re as describeSheetCall, H as describeSheetName, g as encodeCell, h as encodeFormattedNumber, m as encodeNumber, _ as encodeScalar, C as grep, T as grepTool, Y as isPlainRecord, Le as parseFeatures, ot as parseRenderOptions, Se as profileKinds, M as profileRegion, Ee as regionPayload, De as regionPayloads, st as renderCell, mt as renderCellRange, ht as renderConditionalFormat, gt as renderCounts, _t as renderDataValidation, Dt as renderFormula, w as renderGrep, qt as renderMarkdown, pt as renderMovable, kt as renderNames, Nt as renderRanges, At as renderRecords, je as renderRegions, Jt as renderResult, Pt as renderSheet, It as renderStats, Lt as renderStyle, Ne as renderTable, Rt as renderValues, Vt as renderWorkbook, $ as resolveRenderer };
3957
+ var Yi = [In], Xi = [tr];
3958
+ export { Ln as API_ENTRY_POINTS, _ as CellEncoding, C as GREP_FIELDS, w as GREP_FIELDS_DEFAULT, S as GrepField, V as MarkdownBuilder, ot as MarkdownFrameSection, Gi as NoRendererError, Xi as REFERENCES, Wi as RENDERABLE_KINDS, Ui as RENDERERS, vr as RENDER_OPTION_KEYS, pt as REPORTED_FEATURES, Yi as TOOLS, Kn as apiPointerFor, Zn as apiSuggestionsFor, tr as apiTool, Gn as apiTypeOf, rr as appendDependencies, bt as appendKinds, li as appendModules, hn as appendMovables, Pt as appendNames, ct as appendRegionList, xt as appendRegions, It as appendRules, Rt as appendSheetObjects, jr as appendSheetProtection, dt as appendTables, ci as collectModules, cn as collectShapeText, St as contentfulBlocks, ve as countDates, A as describeAlignment, tt as describeAllowedValues, rn as describeAnchor, er as describeApi, O as describeBorder, te as describeBorderParts, Nr as describeCellProtection, E as describeColor, $e as describeConditionalFormat, et as describeDataValidation, U as describeExtent, D as describeFill, j as describeFont, Cr as describeLock, un as describeMovableSummary, gr as describeNode, hr as describeNodeLabel, pr as describeNodeLabels, k as describeNumberFormat, yt as describeQualifiedExtent, Et as describeQualifiedName, vt as describeQualifiedRanges, Mr as describeRangeProtection, _t as describeRanges, Ye as describeRuleStyle, nt as describeRules, Ze as describeScale, on as describeShapeText, G as describeSheetCall, W as describeSheetName, de as describeSums, pn as describeTypeHeading, Er as describeWorkbookProtection, ce as detectTotals, b as encodeCell, y as encodeFormattedNumber, v as encodeNumber, x as encodeScalar, Lt as findNames, kn as grep, In as grepTool, mn as groupMovables, hi as isPlainRecord, Wn as lookupApi, gt as parseFeatures, yr as parseRenderOptions, _e as profileKinds, ae as profileRegion, Pr as protectionPointerFor, sn as readShapeText, it as regionPayload, at as regionPayloads, $n as renderApi, Rr as renderCell, Ur as renderCellRange, Wr as renderConditionalFormat, Gr as renderCounts, Kr as renderDataValidation, ni as renderFormula, Fn as renderGrep, qi as renderMarkdown, di as renderModule, fi as renderModules, _n as renderMovable, mi as renderNames, Ir as renderProtectedRange, Fr as renderProtection, bi as renderRanges, gi as renderRecords, lt as renderRegions, Ji as renderResult, Si as renderSheet, Ti as renderStats, Di as renderStyle, ft as renderTable, Oi as renderValues, Mi as renderWorkbook, Ki as resolveRenderer, Ar as summarizeSheetProtection };