@sheetxl/query 0.7.23-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +11 -0
- package/README.md +69 -0
- package/browser/cjs/index.cjs +26 -0
- package/browser/esm/index.mjs +1994 -0
- package/licenses/dependencies.txt +1 -0
- package/node/esm/index.mjs +2024 -0
- package/package.json +52 -0
- package/types/index.d.ts +2 -0
- package/types/src/Tool.d.ts +108 -0
- package/types/src/Tool.d.ts.map +1 -0
- package/types/src/encode/encodeCell.d.ts +149 -0
- package/types/src/encode/encodeCell.d.ts.map +1 -0
- package/types/src/encode/index.d.ts +2 -0
- package/types/src/encode/index.d.ts.map +1 -0
- package/types/src/grep/GrepTypes.d.ts +308 -0
- package/types/src/grep/GrepTypes.d.ts.map +1 -0
- package/types/src/grep/grep.d.ts +15 -0
- package/types/src/grep/grep.d.ts.map +1 -0
- package/types/src/grep/grepTool.d.ts +16 -0
- package/types/src/grep/grepTool.d.ts.map +1 -0
- package/types/src/grep/index.d.ts +5 -0
- package/types/src/grep/index.d.ts.map +1 -0
- package/types/src/grep/renderGrep.d.ts +19 -0
- package/types/src/grep/renderGrep.d.ts.map +1 -0
- package/types/src/index.d.ts +20 -0
- package/types/src/index.d.ts.map +1 -0
- package/types/src/markdown/MarkdownBuilder.d.ts +84 -0
- package/types/src/markdown/MarkdownBuilder.d.ts.map +1 -0
- package/types/src/markdown/appendSections.d.ts +364 -0
- package/types/src/markdown/appendSections.d.ts.map +1 -0
- package/types/src/markdown/caps.d.ts +24 -0
- package/types/src/markdown/caps.d.ts.map +1 -0
- package/types/src/markdown/describeRegionPayload.d.ts +46 -0
- package/types/src/markdown/describeRegionPayload.d.ts.map +1 -0
- package/types/src/markdown/describeRule.d.ts +66 -0
- package/types/src/markdown/describeRule.d.ts.map +1 -0
- package/types/src/markdown/describeStyle.d.ts +64 -0
- package/types/src/markdown/describeStyle.d.ts.map +1 -0
- package/types/src/markdown/index.d.ts +27 -0
- package/types/src/markdown/index.d.ts.map +1 -0
- package/types/src/markdown/parseRenderOptions.d.ts +16 -0
- package/types/src/markdown/parseRenderOptions.d.ts.map +1 -0
- package/types/src/markdown/profileRegion.d.ts +121 -0
- package/types/src/markdown/profileRegion.d.ts.map +1 -0
- package/types/src/markdown/registry.d.ts +96 -0
- package/types/src/markdown/registry.d.ts.map +1 -0
- package/types/src/markdown/renderCell.d.ts +23 -0
- package/types/src/markdown/renderCell.d.ts.map +1 -0
- package/types/src/markdown/renderCellRange.d.ts +61 -0
- package/types/src/markdown/renderCellRange.d.ts.map +1 -0
- package/types/src/markdown/renderConditionalFormat.d.ts +15 -0
- package/types/src/markdown/renderConditionalFormat.d.ts.map +1 -0
- package/types/src/markdown/renderCounts.d.ts +11 -0
- package/types/src/markdown/renderCounts.d.ts.map +1 -0
- package/types/src/markdown/renderDataValidation.d.ts +15 -0
- package/types/src/markdown/renderDataValidation.d.ts.map +1 -0
- package/types/src/markdown/renderFormula.d.ts +63 -0
- package/types/src/markdown/renderFormula.d.ts.map +1 -0
- package/types/src/markdown/renderMovable.d.ts +35 -0
- package/types/src/markdown/renderMovable.d.ts.map +1 -0
- package/types/src/markdown/renderNames.d.ts +32 -0
- package/types/src/markdown/renderNames.d.ts.map +1 -0
- package/types/src/markdown/renderRanges.d.ts +33 -0
- package/types/src/markdown/renderRanges.d.ts.map +1 -0
- package/types/src/markdown/renderRecords.d.ts +39 -0
- package/types/src/markdown/renderRecords.d.ts.map +1 -0
- package/types/src/markdown/renderRegions.d.ts +70 -0
- package/types/src/markdown/renderRegions.d.ts.map +1 -0
- package/types/src/markdown/renderResult.d.ts +35 -0
- package/types/src/markdown/renderResult.d.ts.map +1 -0
- package/types/src/markdown/renderSheet.d.ts +29 -0
- package/types/src/markdown/renderSheet.d.ts.map +1 -0
- package/types/src/markdown/renderStats.d.ts +18 -0
- package/types/src/markdown/renderStats.d.ts.map +1 -0
- package/types/src/markdown/renderStyle.d.ts +12 -0
- package/types/src/markdown/renderStyle.d.ts.map +1 -0
- package/types/src/markdown/renderTable.d.ts +12 -0
- package/types/src/markdown/renderTable.d.ts.map +1 -0
- package/types/src/markdown/renderValues.d.ts +28 -0
- package/types/src/markdown/renderValues.d.ts.map +1 -0
- package/types/src/markdown/renderWorkbook.d.ts +50 -0
- package/types/src/markdown/renderWorkbook.d.ts.map +1 -0
|
@@ -0,0 +1,1994 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license @sheetxl/query - SheetXL - Workbook read surface and renderers (grep, reports) — capabilities declared once, adapted by any host surface - v0.7.23-beta.1
|
|
3
|
+
*
|
|
4
|
+
* (C) 2026-present SheetXL Inc. & Michael T. Ford
|
|
5
|
+
* License: The license can be found at https://www.sheetxl.com/license.
|
|
6
|
+
*/
|
|
7
|
+
import { AddressUtils as e, FormulaError as t, IAnchored as n, ICellRange as r, ICondition as 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 = {
|
|
10
|
+
Display: "display",
|
|
11
|
+
Value: "value"
|
|
12
|
+
};
|
|
13
|
+
function m(e) {
|
|
14
|
+
return Number.isFinite(e) ? function(e) {
|
|
15
|
+
let t = e.indexOf("e");
|
|
16
|
+
if (t === -1) return e;
|
|
17
|
+
let n = e.substring(t + 2);
|
|
18
|
+
return `${e.substring(0, t)}E${e[t + 1]}${n.length < 2 ? "0" + n : n}`;
|
|
19
|
+
}(String(Number(e.toPrecision(15)))) : String(e);
|
|
20
|
+
}
|
|
21
|
+
function h(e, t) {
|
|
22
|
+
if (!Number.isFinite(e)) return String(e);
|
|
23
|
+
if (!t || t === "General") return m(e);
|
|
24
|
+
try {
|
|
25
|
+
let n = d.getEngine().format(t, e)?.text;
|
|
26
|
+
return n ? n.trim() : m(e);
|
|
27
|
+
} catch {
|
|
28
|
+
return m(e);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function g(e, t) {
|
|
32
|
+
let n = t === p.Mode.Value, r = e.getText({
|
|
33
|
+
hideStringPrefix: !0,
|
|
34
|
+
useFormattingCategory: n
|
|
35
|
+
});
|
|
36
|
+
return r ? {
|
|
37
|
+
match: r,
|
|
38
|
+
display: e.getText({ useFormattingCategory: n })
|
|
39
|
+
} : null;
|
|
40
|
+
}
|
|
41
|
+
function _(e) {
|
|
42
|
+
if (e == null) return null;
|
|
43
|
+
if (typeof e == "string") return {
|
|
44
|
+
match: e,
|
|
45
|
+
display: `'${e}`
|
|
46
|
+
};
|
|
47
|
+
if (typeof e == "boolean") {
|
|
48
|
+
let t = e ? "TRUE" : "FALSE";
|
|
49
|
+
return {
|
|
50
|
+
match: t,
|
|
51
|
+
display: t
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (typeof e == "number") {
|
|
55
|
+
let t = m(e);
|
|
56
|
+
return {
|
|
57
|
+
match: t,
|
|
58
|
+
display: t
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (t.isError(e)) {
|
|
62
|
+
let t = e.getLabel();
|
|
63
|
+
return {
|
|
64
|
+
match: t,
|
|
65
|
+
display: t
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
let n = e.toString();
|
|
69
|
+
return {
|
|
70
|
+
match: n,
|
|
71
|
+
display: n
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
var v = {
|
|
75
|
+
Display: "display",
|
|
76
|
+
Value: "value",
|
|
77
|
+
Raw: "raw",
|
|
78
|
+
Formula: "formula",
|
|
79
|
+
Hyperlink: "hyperlink",
|
|
80
|
+
NumberFormat: "numberFormat"
|
|
81
|
+
}, y = [
|
|
82
|
+
"display",
|
|
83
|
+
"value",
|
|
84
|
+
"raw",
|
|
85
|
+
"formula",
|
|
86
|
+
"hyperlink",
|
|
87
|
+
"numberFormat"
|
|
88
|
+
], b = [
|
|
89
|
+
"display",
|
|
90
|
+
"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) => {
|
|
378
|
+
if (!e) return null;
|
|
379
|
+
let t = String(e.toHex?.() ?? "");
|
|
380
|
+
if (!t) return e.toString();
|
|
381
|
+
let n = /^#FF/i.test(t) && t.length === 9 ? `#${t.slice(3)}` : t, r = e.toString();
|
|
382
|
+
if (!r) return n;
|
|
383
|
+
let i = r.toLowerCase().replace(/^#/, "");
|
|
384
|
+
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) => {
|
|
386
|
+
let t = e.getFill(), n = t.getType();
|
|
387
|
+
if (n === s.Type.None) return null;
|
|
388
|
+
if (n === s.Type.Pattern) {
|
|
389
|
+
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());
|
|
394
|
+
return [
|
|
395
|
+
`${n} pattern`,
|
|
396
|
+
r,
|
|
397
|
+
i ? `on ${i}` : null
|
|
398
|
+
].filter(Boolean).join(" ");
|
|
399
|
+
}
|
|
400
|
+
let r = D(t.getColor?.());
|
|
401
|
+
return r ? `${n} ${r}` : n;
|
|
402
|
+
}, oe = (e) => {
|
|
403
|
+
let t = ce(e);
|
|
404
|
+
return t.length > 0 ? t.join(" · ") : null;
|
|
405
|
+
}, se = /* @__PURE__ */ new Set([
|
|
406
|
+
"top",
|
|
407
|
+
"left",
|
|
408
|
+
"bottom",
|
|
409
|
+
"right"
|
|
410
|
+
]), ce = (e) => {
|
|
411
|
+
let t = e.getBorder(), n = [
|
|
412
|
+
["top", t.getTop()],
|
|
413
|
+
["left", t.getLeft()],
|
|
414
|
+
["bottom", t.getBottom()],
|
|
415
|
+
["right", t.getRight()],
|
|
416
|
+
["horizontal", t.getHorizontal()],
|
|
417
|
+
["vertical", t.getVertical()],
|
|
418
|
+
["diagonalUp", t.getDiagonalUp()],
|
|
419
|
+
["diagonalDown", t.getDiagonalDown()]
|
|
420
|
+
], r = /* @__PURE__ */ new Map();
|
|
421
|
+
for (let [e, t] of n) {
|
|
422
|
+
let n = t?.getStyle?.();
|
|
423
|
+
if (!n || n === "none") continue;
|
|
424
|
+
let i = D(t?.getColor?.()), a = i ? `${n} ${i}` : n, o = r.get(a);
|
|
425
|
+
o ? o.push(e) : r.set(a, [e]);
|
|
426
|
+
}
|
|
427
|
+
let i = [];
|
|
428
|
+
for (let [e, t] of r) {
|
|
429
|
+
let n = t.length === 4 && t.every((e) => se.has(e));
|
|
430
|
+
i.push(`${n ? "outline" : t.join("+")} ${e}`);
|
|
431
|
+
}
|
|
432
|
+
return i;
|
|
433
|
+
}, le = (e) => {
|
|
434
|
+
let t = e.getNumberFormat();
|
|
435
|
+
return t && t !== "General" ? t : null;
|
|
436
|
+
}, ue = (e, t) => {
|
|
437
|
+
let n = e.getAlignment(), r = t.getAlignment(), i = [];
|
|
438
|
+
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) => {
|
|
440
|
+
let n = e.getFont(), r = t.getFont(), i = [];
|
|
441
|
+
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"));
|
|
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}`);
|
|
491
|
+
}
|
|
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) {
|
|
509
|
+
let n = t?.maxSeries ?? 24, r = t?.maxProfileCells ?? 2e4, i = t?.maxCategories ?? 3, a = e.getRowCount(), o = e.getColumnCount();
|
|
510
|
+
if (a === 1 && o === 1) return {
|
|
511
|
+
shape: "cell",
|
|
512
|
+
summary: `cell · ${g(e.getCell(), p.Mode.Display)?.display ?? "(blank)"}`,
|
|
513
|
+
series: []
|
|
514
|
+
};
|
|
515
|
+
let s = e.getRange(), c = s.getCoords(), l = a >= o;
|
|
516
|
+
if (a === 1 || o === 1) return {
|
|
517
|
+
shape: "list",
|
|
518
|
+
summary: `list · ${xe(s, i)}`,
|
|
519
|
+
series: []
|
|
520
|
+
};
|
|
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
|
+
}
|
|
549
|
+
return {
|
|
550
|
+
present: !1,
|
|
551
|
+
inside: !1,
|
|
552
|
+
note: "no header detected",
|
|
553
|
+
names: null
|
|
554
|
+
};
|
|
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
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
function N(e) {
|
|
570
|
+
let t = e.getStats({ onError: "ignore" }), n = t.getCount();
|
|
571
|
+
return n > 0 && (t.getTypedCounts()[f.String] ?? 0) === n;
|
|
572
|
+
}
|
|
573
|
+
function ye(e, t, n) {
|
|
574
|
+
let r = t.getRange().getCoords(), i = e.getCoords(), a = n ? r.colEnd - r.colStart + 1 : r.rowEnd - r.rowStart + 1, o = [];
|
|
575
|
+
for (let t = 0; t < a; t++) {
|
|
576
|
+
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 ?? "");
|
|
578
|
+
}
|
|
579
|
+
return o;
|
|
580
|
+
}
|
|
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];
|
|
583
|
+
return o ? `${a} ${o}` : a;
|
|
584
|
+
}
|
|
585
|
+
function xe(e, t = 3) {
|
|
586
|
+
let n = e.getStats({ onError: "ignore" }), r = n.getTypedCounts(), i = n.getCount(), a = n.getSize(), o = a - i;
|
|
587
|
+
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;
|
|
589
|
+
if (s === i) {
|
|
590
|
+
let t = [...e.getRegions(j.Formula)];
|
|
591
|
+
if (t.length === 1) {
|
|
592
|
+
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));
|
|
598
|
+
else {
|
|
599
|
+
let e = [
|
|
600
|
+
l ? `number ${l}` : null,
|
|
601
|
+
u ? `text ${u}` : null,
|
|
602
|
+
r[f.Boolean] ? `boolean ${r[f.Boolean]}` : null,
|
|
603
|
+
d ? `error ${d}` : null
|
|
604
|
+
].filter(Boolean);
|
|
605
|
+
p.push("mixed", e.join(" · ")), m = !0;
|
|
606
|
+
}
|
|
607
|
+
let h = [
|
|
608
|
+
d > 0 && !m ? `error ${d}` : null,
|
|
609
|
+
o > 0 ? `${o} blank` : null,
|
|
610
|
+
s > 0 && s !== i ? `${s} formula` : null
|
|
611
|
+
].filter(Boolean), g = p.filter(Boolean).join(" ");
|
|
612
|
+
return h.length ? `${g} · ${h.join(" · ")}` : g;
|
|
613
|
+
}
|
|
614
|
+
function Se(e, t = 3) {
|
|
615
|
+
let n = e.getStats({ onError: "ignore" }), r = n.getTypedCounts(), i = [], a = r[f.Number] ?? 0;
|
|
616
|
+
if (a > 0) {
|
|
617
|
+
let t = [F(n, e), ...Ce(n, e)].filter(Boolean);
|
|
618
|
+
i.push(`Number: ${a} ${t.join(" ")}`.trimEnd());
|
|
619
|
+
}
|
|
620
|
+
let o = r[f.String] ?? 0;
|
|
621
|
+
if (o > 0) {
|
|
622
|
+
let e = I(n, t, (e) => typeof e == "string");
|
|
623
|
+
i.push(`String: ${o} ${e}`.trimEnd());
|
|
624
|
+
}
|
|
625
|
+
let s = r[f.Boolean] ?? 0;
|
|
626
|
+
if (s > 0) {
|
|
627
|
+
let e = I(n, t, (e) => typeof e == "boolean");
|
|
628
|
+
i.push(`Boolean: ${s} ${e}`.trimEnd());
|
|
629
|
+
}
|
|
630
|
+
return i;
|
|
631
|
+
}
|
|
632
|
+
function P(e) {
|
|
633
|
+
let t = 0;
|
|
634
|
+
return e.forEach((e, n) => {
|
|
635
|
+
n.getInteropType() === u.Date && t++;
|
|
636
|
+
}), t;
|
|
637
|
+
}
|
|
638
|
+
function F(e, t) {
|
|
639
|
+
let n = e.getAggregates({ onError: "ignore" });
|
|
640
|
+
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}`;
|
|
643
|
+
}
|
|
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;
|
|
647
|
+
}
|
|
648
|
+
function I(e, t, n) {
|
|
649
|
+
let r = e.getFrequencies(n ? { filterFn: n } : void 0), i = r.getUniqueCount();
|
|
650
|
+
if (i === 0) return "";
|
|
651
|
+
if (i === r.getTotalCount()) return `${i} distinct, no repeats`;
|
|
652
|
+
let a = Array.from(r.getValueCounts()).slice(0, t);
|
|
653
|
+
return `${i} unique (${a.map(([e, t]) => `${e} ${t}`).join(" · ")}${i > a.length ? " · …" : ""})`;
|
|
654
|
+
}
|
|
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;
|
|
661
|
+
}
|
|
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;
|
|
668
|
+
};
|
|
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;
|
|
673
|
+
};
|
|
674
|
+
case L.Merge: return Te;
|
|
675
|
+
case L.Comments: return (e) => {
|
|
676
|
+
let t = e.getCell().getComments()?.content;
|
|
677
|
+
if (typeof t != "string") return null;
|
|
678
|
+
let n = t.replace(/\s+/g, " ").trim();
|
|
679
|
+
return n ? n.length > 60 ? `${n.slice(0, 59)}…` : n : null;
|
|
680
|
+
};
|
|
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;
|
|
692
|
+
default: return;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
function De(e, t) {
|
|
696
|
+
let n = e.map((e) => Ee(e, t)).filter((e) => !!e);
|
|
697
|
+
if (n.length !== 0) return n.length === 1 ? n[0] : (e) => {
|
|
698
|
+
let t = n.map((t) => t(e)).filter(Boolean);
|
|
699
|
+
return t.length > 0 ? t.join(" ") : null;
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
var z = class {
|
|
703
|
+
constructor() {
|
|
704
|
+
this._lines = [], this._headingOffset = 0;
|
|
705
|
+
}
|
|
706
|
+
setHeadingOffset(e) {
|
|
707
|
+
return this._headingOffset = e, this;
|
|
708
|
+
}
|
|
709
|
+
_heading(e, t) {
|
|
710
|
+
return this._lines.push(`${"#".repeat(Math.min(6, e + this._headingOffset))} ${t}`), this;
|
|
711
|
+
}
|
|
712
|
+
h1(e) {
|
|
713
|
+
return this._heading(1, e);
|
|
714
|
+
}
|
|
715
|
+
h2(e) {
|
|
716
|
+
return this._heading(2, e);
|
|
717
|
+
}
|
|
718
|
+
h3(e) {
|
|
719
|
+
return this._heading(3, e);
|
|
720
|
+
}
|
|
721
|
+
text(e) {
|
|
722
|
+
return this._lines.push(e), this;
|
|
723
|
+
}
|
|
724
|
+
blank() {
|
|
725
|
+
return this._lines.push(""), this;
|
|
726
|
+
}
|
|
727
|
+
bullet(e) {
|
|
728
|
+
return typeof e == "string" ? this._lines.push(`- ${e}`) : e.forEach((e) => this._lines.push(`- ${e}`)), this;
|
|
729
|
+
}
|
|
730
|
+
fact(e) {
|
|
731
|
+
return typeof e == "string" ? this._lines.push(` ${e}`) : e.forEach((e) => this._lines.push(` ${e}`)), this;
|
|
732
|
+
}
|
|
733
|
+
bold(e) {
|
|
734
|
+
return `**${e}**`;
|
|
735
|
+
}
|
|
736
|
+
codespan(e) {
|
|
737
|
+
return `\`${e}\``;
|
|
738
|
+
}
|
|
739
|
+
code(e, t = "") {
|
|
740
|
+
return `\`\`\`${t}\n${e}\n\`\`\``;
|
|
741
|
+
}
|
|
742
|
+
beginFrame(e) {
|
|
743
|
+
return new Oe(this, e);
|
|
744
|
+
}
|
|
745
|
+
_addLines(e) {
|
|
746
|
+
this._lines.push(...e);
|
|
747
|
+
}
|
|
748
|
+
toLines() {
|
|
749
|
+
return [...this._lines];
|
|
750
|
+
}
|
|
751
|
+
}, Oe = class {
|
|
752
|
+
constructor(e, t) {
|
|
753
|
+
this._parent = e, this._headers = t, this._indexWidth = 0, this._rows = [], this._colWidths = t.map((e) => e.length);
|
|
754
|
+
}
|
|
755
|
+
addRow(e, t) {
|
|
756
|
+
let n = e.map((e) => typeof e == "string" ? { text: e } : e);
|
|
757
|
+
return n.forEach((e, t) => {
|
|
758
|
+
this._colWidths[t] = Math.max(this._colWidths[t] ?? 0, e.text.length);
|
|
759
|
+
}), t !== void 0 && (this._indexWidth = Math.max(this._indexWidth, t.length)), this._rows.push({
|
|
760
|
+
index: t,
|
|
761
|
+
cells: n
|
|
762
|
+
}), this;
|
|
763
|
+
}
|
|
764
|
+
endFrame() {
|
|
765
|
+
return this._parent._addLines(this._renderLines()), this._parent;
|
|
766
|
+
}
|
|
767
|
+
_columnAlignment(e) {
|
|
768
|
+
let t = 0, n = 0;
|
|
769
|
+
for (let r of this._rows) {
|
|
770
|
+
let i = r.cells[e];
|
|
771
|
+
i && i.text && (n++, i.alignment === "right" && t++);
|
|
772
|
+
}
|
|
773
|
+
return n > 0 && 2 * t >= n ? "right" : void 0;
|
|
774
|
+
}
|
|
775
|
+
_renderLines() {
|
|
776
|
+
let e = this._indexWidth > 0 ? " ".repeat(this._indexWidth) : "", t = this._colWidths.map((e, t) => this._columnAlignment(t)), n = [];
|
|
777
|
+
if (this._headers.some((e) => e.length > 0)) {
|
|
778
|
+
let r = this._headers.map((e, n) => ke(e, this._colWidths[n], t[n])).join(" ");
|
|
779
|
+
n.push(`${e}${e ? " " : ""}${r}`.trimEnd());
|
|
780
|
+
}
|
|
781
|
+
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) + " " : "";
|
|
783
|
+
n.push(`${r}${t}`.trimEnd());
|
|
784
|
+
}
|
|
785
|
+
return n;
|
|
786
|
+
}
|
|
787
|
+
}, ke = (e, t, n) => {
|
|
788
|
+
if (e.length >= t) return e;
|
|
789
|
+
let r = t - e.length;
|
|
790
|
+
return n === "right" ? e.padStart(t) : n === "center" ? " ".repeat(Math.floor(r / 2)) + e + " ".repeat(Math.ceil(r / 2)) : e.padEnd(t);
|
|
791
|
+
};
|
|
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;
|
|
794
|
+
if (i.length === 0) return void e.text("None");
|
|
795
|
+
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
|
+
for (let t = 0; t < i.length; t++) {
|
|
797
|
+
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
|
+
if (t < u) {
|
|
799
|
+
let t = M(r, n);
|
|
800
|
+
e.text(`${f} ${t.summary}${d}`);
|
|
801
|
+
for (let n of t.series) e.text(` ${n}`);
|
|
802
|
+
continue;
|
|
803
|
+
}
|
|
804
|
+
e.text(a ? `${f} ${a}${d}` : `${f}${d}`.trimEnd());
|
|
805
|
+
}
|
|
806
|
+
if (u > 0 && i.length > u && e.text(` …${i.length - u} more regions listed but not profiled · profile one with getRange().getStats(), or loop them in code`), a) {
|
|
807
|
+
let i = n?.recovery ?? "narrow the range, or loop the regions in code — this listing is a report, not the query";
|
|
808
|
+
e.text(` …truncated at ${r} of ${t.length} regions · ${i}`);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
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, {
|
|
814
|
+
...t,
|
|
815
|
+
profile: o,
|
|
816
|
+
payload: o ? void 0 : De(i, s)
|
|
817
|
+
}), c.toLines().join("\n").trimEnd();
|
|
818
|
+
}
|
|
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 = [];
|
|
855
|
+
for (let r of e.split(",")) {
|
|
856
|
+
let e = r.trim();
|
|
857
|
+
if (!e) continue;
|
|
858
|
+
let i = t.get(e.toLowerCase());
|
|
859
|
+
if (!i) throw Error(`Unknown feature '${e}'. Features: ${Object.values(B).join(", ")}.`);
|
|
860
|
+
n.push(i);
|
|
861
|
+
}
|
|
862
|
+
return n;
|
|
863
|
+
}
|
|
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) => {
|
|
865
|
+
if (!e.includes("$")) return e;
|
|
866
|
+
let t = "", n = !1;
|
|
867
|
+
for (let r of e) {
|
|
868
|
+
if (r === "'") n = !n;
|
|
869
|
+
else if (r === "$" && !n) continue;
|
|
870
|
+
t += r;
|
|
871
|
+
}
|
|
872
|
+
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) => {
|
|
877
|
+
let t = e.toString();
|
|
878
|
+
return `${t.includes("!") ? t : `${H(e.getSheet().getName())}!${t}`}, ${e.getRowCount()}×${e.getColumnCount()}`;
|
|
879
|
+
};
|
|
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));
|
|
895
|
+
if (a.length === 0) return;
|
|
896
|
+
let o = t.getCounts(a);
|
|
897
|
+
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) => {
|
|
911
|
+
let t = e.getScope();
|
|
912
|
+
return t ? `${H(t)}!${e.getName()}` : e.getName();
|
|
913
|
+
}, Ge = (e) => {
|
|
914
|
+
let t = e.getAddress();
|
|
915
|
+
return t.includes("!") ? t : `${H(e.getSheet().getName())}!${t}`;
|
|
916
|
+
};
|
|
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) => {
|
|
925
|
+
let t = e.value;
|
|
926
|
+
return typeof t == "object" && t?.name ? t.name : e.text ?? "";
|
|
927
|
+
};
|
|
928
|
+
function Ze(e) {
|
|
929
|
+
let t = null;
|
|
930
|
+
for (let n = 0; n < e.length; n++) {
|
|
931
|
+
let r = e[n];
|
|
932
|
+
if (r.type !== "named" || !r.context) continue;
|
|
933
|
+
let i = r.context.name?.toUpperCase();
|
|
934
|
+
if (i !== "LAMBDA" && (i !== "LET" || r.context.argIndex % 2 != 0)) continue;
|
|
935
|
+
let a = n + 1;
|
|
936
|
+
for (; a < e.length && e[a].type === "whitespace";) a++;
|
|
937
|
+
if (e[a]?.type !== "separator") continue;
|
|
938
|
+
let o = Xe(r).toLowerCase();
|
|
939
|
+
o && (t ??= /* @__PURE__ */ new Set()).add(o);
|
|
940
|
+
}
|
|
941
|
+
return t ?? Ye;
|
|
942
|
+
}
|
|
943
|
+
function K(e, t, n) {
|
|
944
|
+
if (t.length === 0) return;
|
|
945
|
+
let r = /* @__PURE__ */ new Set();
|
|
946
|
+
for (let e of n?.symbols ?? t) r.add(e.getName().toLowerCase());
|
|
947
|
+
let i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set();
|
|
948
|
+
for (let e of t) i.set(e.getId(), e), e.getScope() && a.add(e.getName().toLowerCase());
|
|
949
|
+
let o = t.map((e) => {
|
|
950
|
+
let t = function(e, t) {
|
|
951
|
+
let n = We(e), r = [];
|
|
952
|
+
if (n) {
|
|
953
|
+
let e = n.getTokens(), i = null, a = null;
|
|
954
|
+
for (let n of e) {
|
|
955
|
+
if (n.type === "error") {
|
|
956
|
+
a ??= Je(n);
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
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));
|
|
962
|
+
}
|
|
963
|
+
if (a || r.length > 0) return {
|
|
964
|
+
broken: !0,
|
|
965
|
+
missing: r,
|
|
966
|
+
error: r.length > 0 ? `#NAME?: ${r.join(", ")}` : a
|
|
967
|
+
};
|
|
968
|
+
if (!n.isReferenceOnly()) return {
|
|
969
|
+
broken: !1,
|
|
970
|
+
missing: r,
|
|
971
|
+
error: ""
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
let i = null;
|
|
975
|
+
try {
|
|
976
|
+
i = e.getRanges?.() ?? null;
|
|
977
|
+
} catch {
|
|
978
|
+
return {
|
|
979
|
+
broken: !0,
|
|
980
|
+
missing: r,
|
|
981
|
+
error: "#REF!"
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
let a = !i || i.isInvalidAny();
|
|
985
|
+
return {
|
|
986
|
+
broken: a,
|
|
987
|
+
missing: r,
|
|
988
|
+
error: a ? "#REF!" : ""
|
|
989
|
+
};
|
|
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
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
let s = r + i.length;
|
|
1009
|
+
if (s === 0) return {
|
|
1010
|
+
text: "unused",
|
|
1011
|
+
weight: s
|
|
1012
|
+
};
|
|
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;
|
|
1018
|
+
}
|
|
1019
|
+
let d = c.length - l.length, f = d > 0 ? `, +${d} more` : "";
|
|
1020
|
+
return {
|
|
1021
|
+
text: `${s} · ${l.join(", ")}${f}`,
|
|
1022
|
+
weight: s
|
|
1023
|
+
};
|
|
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);
|
|
1030
|
+
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, "")
|
|
1039
|
+
};
|
|
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);
|
|
1052
|
+
}
|
|
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
|
+
}
|
|
1063
|
+
e.blank();
|
|
1064
|
+
}
|
|
1065
|
+
function q(e, t, n) {
|
|
1066
|
+
$e(e, "Precedents", t, "precedents", n), $e(e, "Dependents", t, "dependents", n);
|
|
1067
|
+
}
|
|
1068
|
+
function Qe(e) {
|
|
1069
|
+
let t = e.isINamedRange ? e.getId() : null;
|
|
1070
|
+
if (t) return `name:${t}`;
|
|
1071
|
+
let n = e.getCoords();
|
|
1072
|
+
return `${e.getSheet()?.getName() ?? ""}!${n.rowStart},${n.colStart},${n.rowEnd},${n.colEnd}`;
|
|
1073
|
+
}
|
|
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) {
|
|
1113
|
+
let t = e.getSheet()?.getName() ?? "";
|
|
1114
|
+
if (e.isINamedRange) return {
|
|
1115
|
+
address: e.getName(),
|
|
1116
|
+
sheet: t,
|
|
1117
|
+
isName: !0
|
|
1118
|
+
};
|
|
1119
|
+
let n = e.getAddress(), r = n.lastIndexOf("!");
|
|
1120
|
+
return {
|
|
1121
|
+
address: r >= 0 && r < n.length - 1 ? n.slice(r + 1) : n,
|
|
1122
|
+
sheet: t,
|
|
1123
|
+
isName: !1
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
function tt(e) {
|
|
1127
|
+
if (e.isINamedRange) {
|
|
1128
|
+
let t = e.getRanges();
|
|
1129
|
+
return t ? `name → ${t.getAddress()}` : "name";
|
|
1130
|
+
}
|
|
1131
|
+
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;
|
|
1134
|
+
}
|
|
1135
|
+
let t = `${e.getRowCount()}×${e.getColumnCount()}`, n = [...e.getRegions(B.Formula)];
|
|
1136
|
+
if (n.length === 1 && n[0].getRange().isEqual(e)) {
|
|
1137
|
+
let e = n[0].getCell().getFormulaText();
|
|
1138
|
+
if (e) return `${t} =${e}`;
|
|
1139
|
+
}
|
|
1140
|
+
return t;
|
|
1141
|
+
}
|
|
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),
|
|
1197
|
+
mode: (e, t) => function(e, t, n) {
|
|
1198
|
+
let r = new Map(Object.values(n).map((e) => [e.toLowerCase(), e])).get(e.trim().toLowerCase());
|
|
1199
|
+
if (!r) throw Error(`Unknown ${t} '${e}'. Values: ${Object.values(n).join(", ")}.`);
|
|
1200
|
+
return r;
|
|
1201
|
+
}(e, t, p.Mode)
|
|
1202
|
+
}, at = Object.keys(it);
|
|
1203
|
+
function ot(e) {
|
|
1204
|
+
let t = {};
|
|
1205
|
+
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(", ")}.`);
|
|
1208
|
+
t[n] = e(r, n);
|
|
1209
|
+
}
|
|
1210
|
+
return t;
|
|
1211
|
+
}
|
|
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}`)}`));
|
|
1218
|
+
let o = t.getHyperlink();
|
|
1219
|
+
o && e.fact(`Hyperlink: ${o.getAddress()}`);
|
|
1220
|
+
let s = t.getSpans(), c = !t.isTopLeft();
|
|
1221
|
+
if (c || s.height > 1 || s.width > 1) {
|
|
1222
|
+
let n = t.getRange().toString();
|
|
1223
|
+
e.fact(`Merge: ${n} · ${s.height}×${s.width}`), c && e.fact("Merge Anchor: false — this cell is covered; the value lives at the top-left");
|
|
1224
|
+
}
|
|
1225
|
+
let l = t.getSpill();
|
|
1226
|
+
l && e.fact(`Spill: ${l.toString()}`), t.isSpillOverflow() && e.fact("Spill Overflow: true — the anchor formula is elsewhere");
|
|
1227
|
+
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}`);
|
|
1240
|
+
}
|
|
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;
|
|
1252
|
+
}
|
|
1253
|
+
case "picture": return e.getResource?.()?.getName() || null;
|
|
1254
|
+
default: return null;
|
|
1255
|
+
}
|
|
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();
|
|
1299
|
+
}
|
|
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) {
|
|
1303
|
+
if (!1 === n?.profile || t.isSingleCell() || !t.isContentful()) return;
|
|
1304
|
+
let r = M({
|
|
1305
|
+
getRowCount: () => t.getRowCount(),
|
|
1306
|
+
getColumnCount: () => t.getColumnCount(),
|
|
1307
|
+
getCell: () => t.getCell(),
|
|
1308
|
+
getRange: () => t
|
|
1309
|
+
}, n);
|
|
1310
|
+
e.h2("Profile"), e.text(r.summary);
|
|
1311
|
+
for (let t of r.series) e.text(` ${t}`);
|
|
1312
|
+
e.blank();
|
|
1313
|
+
}(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;
|
|
1316
|
+
t.forEach((e, t) => {
|
|
1317
|
+
if (d >= i) return f = !0, { break: !0 };
|
|
1318
|
+
let n = t.getCell(), a = n.getFormulaText(), o = g(n, r);
|
|
1319
|
+
if (!o && !a) return;
|
|
1320
|
+
let s = {
|
|
1321
|
+
text: (o?.display ?? "").replace(/\|/g, "\\|").replace(/[\r\n]+/g, " "),
|
|
1322
|
+
alignment: n.getRenderHorizontalAlignment()
|
|
1323
|
+
}, c = n.getSpill();
|
|
1324
|
+
c && u.push({
|
|
1325
|
+
address: n.getAddress(),
|
|
1326
|
+
valuesRange: c.getValuesRange().toString()
|
|
1327
|
+
});
|
|
1328
|
+
let { rowIndex: p, colIndex: m } = t.getCoords(), h = l.get(p);
|
|
1329
|
+
h || (h = /* @__PURE__ */ new Map(), l.set(p, h)), h.set(m, s), d++;
|
|
1330
|
+
});
|
|
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) {
|
|
1344
|
+
let t = l.get(e);
|
|
1345
|
+
x.addRow(_.map((e) => t?.get(e) ?? { text: "" }), s.at(e - a).getText());
|
|
1346
|
+
}
|
|
1347
|
+
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
|
+
}(n, e, t);
|
|
1349
|
+
return function(e, t, n) {
|
|
1350
|
+
let i = [];
|
|
1351
|
+
for (let e of t.getRegions(r.Feature.Formula)) {
|
|
1352
|
+
let t = e.getCell().getFormulaText();
|
|
1353
|
+
if (t && (i.push({
|
|
1354
|
+
address: e.getAddress(),
|
|
1355
|
+
size: `${e.getRowCount()}×${e.getColumnCount()}`,
|
|
1356
|
+
formula: `=${t}`
|
|
1357
|
+
}), i.length >= (n?.maxRegions ?? 100))) break;
|
|
1358
|
+
}
|
|
1359
|
+
if (i.length === 0) return;
|
|
1360
|
+
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}`);
|
|
1363
|
+
e.blank();
|
|
1364
|
+
}(n, e, t), function(e, t) {
|
|
1365
|
+
if (t.length === 0) return;
|
|
1366
|
+
e.h2("Spills");
|
|
1367
|
+
let n = Math.max(...t.map((e) => e.address.length));
|
|
1368
|
+
for (let { address: r, valuesRange: i } of t) e.text(` ${r.padEnd(n)} ${i}`);
|
|
1369
|
+
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();
|
|
1371
|
+
}
|
|
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}`);
|
|
1375
|
+
let r = e.getScale();
|
|
1376
|
+
if (r) t.fact(`Rule: ${he(r)}`);
|
|
1377
|
+
else {
|
|
1378
|
+
let n = e.getCondition();
|
|
1379
|
+
t.fact(`Rule: ${n?.toString() || "none — this rule tests nothing"}`);
|
|
1380
|
+
let r = pe(e.getStyle());
|
|
1381
|
+
r && t.fact(`Format: ${r}`);
|
|
1382
|
+
}
|
|
1383
|
+
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
|
+
}
|
|
1385
|
+
function gt(e) {
|
|
1386
|
+
let t = new z();
|
|
1387
|
+
t.h1("Counts");
|
|
1388
|
+
let n = !1;
|
|
1389
|
+
for (let [r, i] of Object.entries(e)) i > 0 && (t.fact(`${r}: ${i}`), n = !0);
|
|
1390
|
+
return n || t.fact("None"), t.toLines().join("\n").trimEnd();
|
|
1391
|
+
}
|
|
1392
|
+
function _t(e) {
|
|
1393
|
+
let t = new z(), n = e.getRanges();
|
|
1394
|
+
t.h1(`Data Validation — ${Be(n)}`), t.blank();
|
|
1395
|
+
let r = e.getCondition();
|
|
1396
|
+
t.fact(`Rule: ${r?.toString() || "none — anything is accepted here"}`);
|
|
1397
|
+
let i = ve(r);
|
|
1398
|
+
i && t.fact(`Allowed: ${i}`), t.fact("Blanks: " + (e.isIncludeBlanks() ? "allowed" : "rejected"));
|
|
1399
|
+
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());
|
|
1402
|
+
n && t.fact(`Alert Message: ${n}`);
|
|
1403
|
+
}
|
|
1404
|
+
if (e.isShowPromptMessage()) {
|
|
1405
|
+
let n = vt(e.getPromptTitle(), e.getPromptMessage());
|
|
1406
|
+
n && t.fact(`Prompt: ${n}`);
|
|
1407
|
+
}
|
|
1408
|
+
return e.isHideDropdown() && t.fact("Dropdown: hidden"), t.fact(`Cells: ${n.size}`), t.toLines().join("\n").trimEnd();
|
|
1409
|
+
}
|
|
1410
|
+
var vt = (e, t) => {
|
|
1411
|
+
let n = [e?.trim(), t?.trim()].filter(Boolean);
|
|
1412
|
+
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) {
|
|
1415
|
+
if (e === "external") return "another workbook — not resolvable from here";
|
|
1416
|
+
if (!n) return "";
|
|
1417
|
+
switch (e) {
|
|
1418
|
+
case "function": {
|
|
1419
|
+
let e = n.getCalculation().getFunctions().getByName(t);
|
|
1420
|
+
return e ? e.isBuiltIn() ? "built-in" : "custom" : "unknown — evaluates to #NAME?";
|
|
1421
|
+
}
|
|
1422
|
+
case "named": return function(e, t) {
|
|
1423
|
+
let n = t.getNames(), r = n.getByName(e) ?? n.getByName(e, !0);
|
|
1424
|
+
if (r) {
|
|
1425
|
+
let e = Tt(r.getScope(), r.getName()), t = r.getRanges?.();
|
|
1426
|
+
return !t || t.isInvalid() ? `defined name — reference does not resolve${e}` : `${t.toString()}${e}`;
|
|
1427
|
+
}
|
|
1428
|
+
let i = t.getCalculation().getNamedFormulas().getByName(e);
|
|
1429
|
+
return i ? `=${i.getExpression()}${Tt(i.getScope(), i.getName())}` : "unknown — evaluates to #NAME?";
|
|
1430
|
+
}(t, n);
|
|
1431
|
+
case "table": {
|
|
1432
|
+
let e = n.getTables().getByName(t) ?? n.getWorkbook()?.getSheets().getItems().map((e) => e.getTables().getByName(t)).find(Boolean) ?? null;
|
|
1433
|
+
return e ? ((e, t) => {
|
|
1434
|
+
let n = e.getSheet(), r = e.toString();
|
|
1435
|
+
return !n || t && n.getName() === t.getName() || r.includes("!") ? r : `${H(n.getName())}!${r}`;
|
|
1436
|
+
})(e.getRange(), n) : "unknown — evaluates to #NAME?";
|
|
1437
|
+
}
|
|
1438
|
+
case "column": {
|
|
1439
|
+
if (!r) return "column of the enclosing table";
|
|
1440
|
+
let e = n.getTables().getByName(r);
|
|
1441
|
+
if (!e) return `column of ${r}`;
|
|
1442
|
+
let i = t.replace(/^\[|\]$/g, "").trim();
|
|
1443
|
+
return e.getColumns().find((e) => e.getName() === i) ? `${r} column` : `no such column in ${r} — evaluates to #REF!`;
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
return "";
|
|
1447
|
+
}
|
|
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) {
|
|
1451
|
+
i.isHidden() && r.fact("Hidden: true — not offered in the UI; formulas resolve it normally");
|
|
1452
|
+
let e = i.getComment();
|
|
1453
|
+
e && r.fact(`Comment: ${e}`);
|
|
1454
|
+
let t = i.getRanges?.();
|
|
1455
|
+
r.fact(`Refers to: ${t ? t.getAddress() : "no range — this name holds an expression"}`);
|
|
1456
|
+
}
|
|
1457
|
+
await async function(e, t) {
|
|
1458
|
+
let n;
|
|
1459
|
+
try {
|
|
1460
|
+
n = await t.evaluate();
|
|
1461
|
+
} catch (t) {
|
|
1462
|
+
e.fact(`Value: did not evaluate — ${t?.message ?? String(t)}`);
|
|
1463
|
+
return;
|
|
1464
|
+
}
|
|
1465
|
+
if ((r = n) && typeof r == "object" && !0 === r.isIRange) return void e.fact(`Value: spills ${n.getRowCount()}×${n.getColumnCount()} — an array result`);
|
|
1466
|
+
var r;
|
|
1467
|
+
let i = _(n);
|
|
1468
|
+
e.fact(`Value: ${i ? i.display : "(empty)"}`);
|
|
1469
|
+
}(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);
|
|
1471
|
+
a.length > 0 && r.fact(`Flags: ${a.join(" · ")}`), r.blank();
|
|
1472
|
+
let o = e.getReferences(), s = t?.context ?? o?.getSheet() ?? null, c = function(e, t) {
|
|
1473
|
+
let n = /* @__PURE__ */ new Map(), r = null;
|
|
1474
|
+
for (let i of e) {
|
|
1475
|
+
let e = i.text?.trim();
|
|
1476
|
+
if (!e) continue;
|
|
1477
|
+
let a;
|
|
1478
|
+
switch (i.type) {
|
|
1479
|
+
case yt:
|
|
1480
|
+
a = "function";
|
|
1481
|
+
break;
|
|
1482
|
+
case bt:
|
|
1483
|
+
a = "named";
|
|
1484
|
+
break;
|
|
1485
|
+
case xt:
|
|
1486
|
+
a = "table", r = e;
|
|
1487
|
+
break;
|
|
1488
|
+
case St:
|
|
1489
|
+
a = "column";
|
|
1490
|
+
break;
|
|
1491
|
+
case Ct:
|
|
1492
|
+
a = "external";
|
|
1493
|
+
break;
|
|
1494
|
+
default: continue;
|
|
1495
|
+
}
|
|
1496
|
+
let o = `${a}${e.toLowerCase()}`, s = n.get(o);
|
|
1497
|
+
s ? s.uses++ : n.set(o, {
|
|
1498
|
+
kind: a,
|
|
1499
|
+
text: e,
|
|
1500
|
+
uses: 1,
|
|
1501
|
+
resolution: Et(a, e, t, r)
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
return [...n.values()];
|
|
1505
|
+
}(e.getTokens(), s);
|
|
1506
|
+
if (c.length > 0) {
|
|
1507
|
+
r.h2(`Symbols (${c.length})`);
|
|
1508
|
+
let e = r.beginFrame([
|
|
1509
|
+
"Kind",
|
|
1510
|
+
"Symbol",
|
|
1511
|
+
"Uses",
|
|
1512
|
+
"Resolves to"
|
|
1513
|
+
]);
|
|
1514
|
+
for (let t of c) e.addRow([
|
|
1515
|
+
t.kind,
|
|
1516
|
+
t.text,
|
|
1517
|
+
String(t.uses),
|
|
1518
|
+
t.resolution
|
|
1519
|
+
]);
|
|
1520
|
+
e.endFrame(), s || r.text("…no sheet context — pass `context` to resolve these"), r.blank();
|
|
1521
|
+
}
|
|
1522
|
+
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
|
+
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);
|
|
1526
|
+
}(r, i);
|
|
1527
|
+
let l = e.getTokens();
|
|
1528
|
+
if (r.h2("Tokens"), l.length === 0) r.text("None");
|
|
1529
|
+
else {
|
|
1530
|
+
let e = l.length > n ? l.slice(0, n) : l, t = r.beginFrame([
|
|
1531
|
+
"#",
|
|
1532
|
+
"Type",
|
|
1533
|
+
"Text",
|
|
1534
|
+
"Enclosing",
|
|
1535
|
+
"Arg"
|
|
1536
|
+
]);
|
|
1537
|
+
for (let n = 0; n < e.length; n++) {
|
|
1538
|
+
let r = e[n], i = r.context;
|
|
1539
|
+
t.addRow([
|
|
1540
|
+
{
|
|
1541
|
+
text: String(n),
|
|
1542
|
+
alignment: "right"
|
|
1543
|
+
},
|
|
1544
|
+
r.type ?? "",
|
|
1545
|
+
r.text ?? "",
|
|
1546
|
+
i?.name ?? "",
|
|
1547
|
+
i && i.argIndex >= 0 ? String(i.argIndex) : ""
|
|
1548
|
+
]);
|
|
1549
|
+
}
|
|
1550
|
+
t.endFrame(), e.length < l.length && r.text(`…truncated at ${e.length} of ${l.length} tokens · search getTokens() directly`);
|
|
1551
|
+
}
|
|
1552
|
+
return r.toLines().join("\n").trimEnd();
|
|
1553
|
+
}
|
|
1554
|
+
var Ot = [["formula", "Names"], ["table", "Tables"]];
|
|
1555
|
+
function kt(e, t) {
|
|
1556
|
+
let n = new z(), r = e.getItems({ includeHidden: !0 }) ?? [];
|
|
1557
|
+
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), {
|
|
1560
|
+
...t,
|
|
1561
|
+
heading: i,
|
|
1562
|
+
symbols: r
|
|
1563
|
+
});
|
|
1564
|
+
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), {
|
|
1566
|
+
...t,
|
|
1567
|
+
heading: e,
|
|
1568
|
+
symbols: r
|
|
1569
|
+
});
|
|
1570
|
+
return n.toLines().join("\n").trimEnd();
|
|
1571
|
+
}
|
|
1572
|
+
var Y = (e) => {
|
|
1573
|
+
if (!e || typeof e != "object" || Array.isArray(e)) return !1;
|
|
1574
|
+
let t = Object.getPrototypeOf(e);
|
|
1575
|
+
return t === Object.prototype || t === null;
|
|
1576
|
+
};
|
|
1577
|
+
function At(e, t) {
|
|
1578
|
+
let n = t?.maxCells ?? 1e3, r = Array.isArray(e) ? e : [e], i = new z();
|
|
1579
|
+
if (i.h1("Records"), i.text(`Count: ${r.length}`), i.blank(), r.length === 0) return i.text("None"), i.toLines().join("\n").trimEnd();
|
|
1580
|
+
let a = (e) => {
|
|
1581
|
+
let t = [], n = /* @__PURE__ */ new Set();
|
|
1582
|
+
for (let r of e) for (let e of Object.keys(r ?? {})) n.has(e) || (n.add(e), t.push(e));
|
|
1583
|
+
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);
|
|
1585
|
+
if (l.length === 0) return i.text("No fields"), i.toLines().join("\n").trimEnd();
|
|
1586
|
+
let u = i.beginFrame(l);
|
|
1587
|
+
for (let e of c) u.addRow(l.map((t) => jt(e?.[t])));
|
|
1588
|
+
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
|
+
}
|
|
1590
|
+
var jt = (e) => {
|
|
1591
|
+
if (e == null) return { text: "" };
|
|
1592
|
+
if (typeof e == "function") return { text: "[Function]" };
|
|
1593
|
+
if (typeof e == "bigint" || typeof e == "symbol") return { text: X(String(e)) };
|
|
1594
|
+
if (typeof e == "object") {
|
|
1595
|
+
if (e instanceof Date) return { text: e.toISOString() };
|
|
1596
|
+
let t = e;
|
|
1597
|
+
if (!0 === t.isFormulaError || !0 === t.isIRichData) return { text: X(Mt(e)) };
|
|
1598
|
+
if (Y(e) || Array.isArray(e)) {
|
|
1599
|
+
let t;
|
|
1600
|
+
try {
|
|
1601
|
+
t = JSON.stringify(e) ?? String(e);
|
|
1602
|
+
} catch {
|
|
1603
|
+
t = "[circular]";
|
|
1604
|
+
}
|
|
1605
|
+
return { text: X(t) };
|
|
1606
|
+
}
|
|
1607
|
+
return { text: X(String(e)) };
|
|
1608
|
+
}
|
|
1609
|
+
let t = X(Mt(e).replace(/[\r\n]+/g, " "));
|
|
1610
|
+
return typeof e == "number" ? {
|
|
1611
|
+
text: t,
|
|
1612
|
+
alignment: "right"
|
|
1613
|
+
} : { text: t };
|
|
1614
|
+
}, Mt = (e) => {
|
|
1615
|
+
try {
|
|
1616
|
+
return _(e)?.match ?? String(e);
|
|
1617
|
+
} catch {
|
|
1618
|
+
return String(e);
|
|
1619
|
+
}
|
|
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 = [];
|
|
1623
|
+
for (let t = 0; t < i; t++) {
|
|
1624
|
+
let n = e.at(t);
|
|
1625
|
+
a.push({
|
|
1626
|
+
...et(n),
|
|
1627
|
+
detail: tt(n)
|
|
1628
|
+
});
|
|
1629
|
+
}
|
|
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));
|
|
1633
|
+
for (let e = 0; e < a.length; e++) l.text(` ${d[e].padEnd(f)} ${a[e].detail}`.trimEnd());
|
|
1634
|
+
return i < n && l.text(` …and ${n - i} more · loop the collection in code to see them all`), l.toLines().join("\n").trimEnd();
|
|
1635
|
+
}
|
|
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) {
|
|
1639
|
+
let t = e.getWorkbook(), n = "";
|
|
1640
|
+
t && t.getSelectedSheet()?.getId() === e.getId() && (n += " (selected)");
|
|
1641
|
+
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();
|
|
1644
|
+
let a = i ?? r;
|
|
1645
|
+
return W(n, a), Ve(n, a, {
|
|
1646
|
+
profile: !0,
|
|
1647
|
+
...t
|
|
1648
|
+
}), J(n, a), ft(n, e.getMovables().getItems()), n.toLines().join("\n").trimEnd();
|
|
1649
|
+
}
|
|
1650
|
+
var Ft = [
|
|
1651
|
+
["numericalCount", "Numbers"],
|
|
1652
|
+
["sum", "Sum"],
|
|
1653
|
+
["min", "Min"],
|
|
1654
|
+
["max", "Max"],
|
|
1655
|
+
["average", "Average"],
|
|
1656
|
+
["stdDev", "StdDev"]
|
|
1657
|
+
];
|
|
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();
|
|
1676
|
+
t.h1("Style"), t.text(`Named: ${e.getNamed().getName()}`), t.blank();
|
|
1677
|
+
let n = e.toJSON(), r = n ? Object.entries(n).filter(([, e]) => e !== void 0) : [];
|
|
1678
|
+
if (r.length === 0) t.fact("No direct styling (inherits the named style)");
|
|
1679
|
+
else for (let [e, n] of r) t.fact(`${e}: ${t.codespan(typeof n == "string" ? n : JSON.stringify(n))}`);
|
|
1680
|
+
return t.toLines().join("\n").trimEnd();
|
|
1681
|
+
}
|
|
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();
|
|
1684
|
+
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])));
|
|
1687
|
+
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
|
+
}
|
|
1689
|
+
var zt = (e) => !!e && typeof e == "object" && !0 === e.isIRange, Bt = (e) => {
|
|
1690
|
+
if (e == null) return { text: "" };
|
|
1691
|
+
let t = (_(e)?.display ?? "").replace(/[\r\n]+/g, " ");
|
|
1692
|
+
return typeof e == "number" ? {
|
|
1693
|
+
text: t,
|
|
1694
|
+
alignment: "right"
|
|
1695
|
+
} : { 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({
|
|
1704
|
+
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
|
+
]) ?? null
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
let o = a;
|
|
1716
|
+
if (a.length > 50) {
|
|
1717
|
+
o = a.slice(0, 50);
|
|
1718
|
+
let e = a.find((e) => e.sheet.getId() === i.getId());
|
|
1719
|
+
e && !o.includes(e) && (o[o.length - 1] = e);
|
|
1720
|
+
}
|
|
1721
|
+
n.h2(`Sheets (${a.length})`);
|
|
1722
|
+
let s = n.beginFrame([
|
|
1723
|
+
"Sheet",
|
|
1724
|
+
"Used",
|
|
1725
|
+
"Cells",
|
|
1726
|
+
"Formulas",
|
|
1727
|
+
"Errors"
|
|
1728
|
+
]);
|
|
1729
|
+
for (let e of o) s.addRow([
|
|
1730
|
+
{ text: e.label },
|
|
1731
|
+
{ text: e.used },
|
|
1732
|
+
{
|
|
1733
|
+
text: String(e.counts?.[Z.Contentful] ?? 0),
|
|
1734
|
+
alignment: "right"
|
|
1735
|
+
},
|
|
1736
|
+
{
|
|
1737
|
+
text: String(e.counts?.[Z.Formula] ?? 0),
|
|
1738
|
+
alignment: "right"
|
|
1739
|
+
},
|
|
1740
|
+
{
|
|
1741
|
+
text: String(e.counts?.[Z.Error] ?? 0),
|
|
1742
|
+
alignment: "right"
|
|
1743
|
+
}
|
|
1744
|
+
]);
|
|
1745
|
+
if (a.length > 1) {
|
|
1746
|
+
let e = (e) => a.reduce((t, n) => t + (n.counts?.[e] ?? 0), 0);
|
|
1747
|
+
s.addRow([
|
|
1748
|
+
{ text: "Total" },
|
|
1749
|
+
{ text: "" },
|
|
1750
|
+
{
|
|
1751
|
+
text: String(e(Z.Contentful)),
|
|
1752
|
+
alignment: "right"
|
|
1753
|
+
},
|
|
1754
|
+
{
|
|
1755
|
+
text: String(e(Z.Formula)),
|
|
1756
|
+
alignment: "right"
|
|
1757
|
+
},
|
|
1758
|
+
{
|
|
1759
|
+
text: String(e(Z.Error)),
|
|
1760
|
+
alignment: "right"
|
|
1761
|
+
}
|
|
1762
|
+
]);
|
|
1763
|
+
}
|
|
1764
|
+
s.endFrame(), o.length < a.length && n.text(` …and ${a.length - o.length} more sheets · the totals include them · wb.getSheets().getItems() lists all`), n.blank(), Ut(n, "Errors", a, Z.Error), Ut(n, "Calc Failures", a, Z.CalcError), K(n, e.getNames().getItems({
|
|
1765
|
+
type: "formula",
|
|
1766
|
+
includeHidden: !0
|
|
1767
|
+
}) ?? [], {
|
|
1768
|
+
maxNames: t?.maxNames ?? 30,
|
|
1769
|
+
recovery: "wb.getNames() renders the full view",
|
|
1770
|
+
symbols: e.getNames().getItems({ includeHidden: !0 }) ?? []
|
|
1771
|
+
});
|
|
1772
|
+
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());
|
|
1773
|
+
f && !d.includes(f) && (d[d.length - 1] = f), n.setHeadingOffset(1);
|
|
1774
|
+
for (let e of d) {
|
|
1775
|
+
let r = e.sheet.getUsedRange();
|
|
1776
|
+
r && (n.h1(`Sheet — ${e.label}`), W(n, r), Ve(n, r, {
|
|
1777
|
+
features: t?.features,
|
|
1778
|
+
maxRegions: t?.maxRegions ?? 25,
|
|
1779
|
+
profile: !0,
|
|
1780
|
+
maxProfiled: t?.maxProfiled ?? 4
|
|
1781
|
+
}), J(n, r));
|
|
1782
|
+
}
|
|
1783
|
+
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();
|
|
1784
|
+
}
|
|
1785
|
+
function Ht(e, t) {
|
|
1786
|
+
let n = e.getVisibility(), r = "";
|
|
1787
|
+
return t && (r += " (selected)"), n === l.Visibility.Hidden ? r += " (hidden)" : n === l.Visibility.VeryHidden && (r += " (very hidden)"), `${H(e.getName())}${r}`;
|
|
1788
|
+
}
|
|
1789
|
+
function Ut(e, t, n, r) {
|
|
1790
|
+
let i = n.reduce((e, t) => e + (t.counts?.[r] ?? 0), 0);
|
|
1791
|
+
if (i === 0) return;
|
|
1792
|
+
let a = [], o = 0;
|
|
1793
|
+
for (let e of n) {
|
|
1794
|
+
if (!e.counts?.[r]) continue;
|
|
1795
|
+
let t = e.sheet.getUsedRange();
|
|
1796
|
+
if (!t) continue;
|
|
1797
|
+
let n = H(e.sheet.getName());
|
|
1798
|
+
for (let e of t.getRegions(r)) o++, a.length >= 20 || a.push({
|
|
1799
|
+
address: `${n}!${e.toString()}`,
|
|
1800
|
+
size: `${e.getRowCount()}×${e.getColumnCount()}`,
|
|
1801
|
+
payload: Wt(e)
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
e.h2(`${t} (${i})`);
|
|
1805
|
+
let s = Math.max(0, ...a.map((e) => e.address.length)), c = Math.max(0, ...a.map((e) => e.size.length));
|
|
1806
|
+
for (let t of a) e.text(` ${t.address.padEnd(s)} ${t.size.padEnd(c)} ${t.payload}`.trimEnd());
|
|
1807
|
+
o > a.length && e.text(` …and ${o - a.length} more · getRegions('${r}') on a sheet's used range lists the rest`), e.blank();
|
|
1808
|
+
}
|
|
1809
|
+
function Wt(e) {
|
|
1810
|
+
let t = e.getCell(), n = g(t, p.Mode.Display)?.display ?? "", r = t.getFormulaText();
|
|
1811
|
+
return r ? `${n} =${r}`.trim() : n;
|
|
1812
|
+
}
|
|
1813
|
+
var Q = (e, t) => !!e && typeof e == "object" && !0 === e[t], Gt = [
|
|
1814
|
+
{
|
|
1815
|
+
kind: "workbook",
|
|
1816
|
+
is: (e) => Q(e, "isIWorkbook"),
|
|
1817
|
+
render: (e, t) => Vt(e, t)
|
|
1818
|
+
},
|
|
1819
|
+
{
|
|
1820
|
+
kind: "sheet",
|
|
1821
|
+
is: (e) => Q(e, "isISheet"),
|
|
1822
|
+
render: (e, t) => Pt(e, t)
|
|
1823
|
+
},
|
|
1824
|
+
{
|
|
1825
|
+
kind: "cell",
|
|
1826
|
+
is: (e) => Q(e, "isICell"),
|
|
1827
|
+
render: (e, t) => st(e, t)
|
|
1828
|
+
},
|
|
1829
|
+
{
|
|
1830
|
+
kind: "names",
|
|
1831
|
+
is: (e) => Q(e, "isINamedCollection"),
|
|
1832
|
+
render: (e, t) => kt(e, t)
|
|
1833
|
+
},
|
|
1834
|
+
{
|
|
1835
|
+
kind: "formula",
|
|
1836
|
+
is: (e) => Q(e, "isIFormula"),
|
|
1837
|
+
render: (e, t) => Dt(e, t)
|
|
1838
|
+
},
|
|
1839
|
+
{
|
|
1840
|
+
kind: "table",
|
|
1841
|
+
is: (e) => Q(e, "isITable"),
|
|
1842
|
+
render: (e) => Ne(e)
|
|
1843
|
+
},
|
|
1844
|
+
{
|
|
1845
|
+
kind: "movable",
|
|
1846
|
+
is: (e) => Q(e, "isIMovable"),
|
|
1847
|
+
render: (e) => pt(e)
|
|
1848
|
+
},
|
|
1849
|
+
{
|
|
1850
|
+
kind: "conditionalFormat",
|
|
1851
|
+
is: (e) => Q(e, "isIConditionalFormat"),
|
|
1852
|
+
render: (e) => ht(e)
|
|
1853
|
+
},
|
|
1854
|
+
{
|
|
1855
|
+
kind: "dataValidation",
|
|
1856
|
+
is: (e) => Q(e, "isIDataValidation"),
|
|
1857
|
+
render: (e) => _t(e)
|
|
1858
|
+
},
|
|
1859
|
+
{
|
|
1860
|
+
kind: "stats",
|
|
1861
|
+
is: (e) => Q(e, "isIRangeStats"),
|
|
1862
|
+
render: (e) => It(e)
|
|
1863
|
+
},
|
|
1864
|
+
{
|
|
1865
|
+
kind: "counts",
|
|
1866
|
+
is: (e) => Q(e, "isICellRangeCounts"),
|
|
1867
|
+
render: (e) => gt(e)
|
|
1868
|
+
},
|
|
1869
|
+
{
|
|
1870
|
+
kind: "style",
|
|
1871
|
+
is: (e) => Q(e, "isIStyle"),
|
|
1872
|
+
render: (e) => Lt(e)
|
|
1873
|
+
},
|
|
1874
|
+
{
|
|
1875
|
+
kind: "regions",
|
|
1876
|
+
is: (e) => Q(e, "isICellRegions"),
|
|
1877
|
+
render: (e, t) => je(e, t)
|
|
1878
|
+
},
|
|
1879
|
+
{
|
|
1880
|
+
kind: "cellRange",
|
|
1881
|
+
is: (e) => Q(e, "isICellRange"),
|
|
1882
|
+
render: (e, t) => mt(e, t)
|
|
1883
|
+
},
|
|
1884
|
+
{
|
|
1885
|
+
kind: "ranges",
|
|
1886
|
+
is: (e) => Q(e, "isICellRanges"),
|
|
1887
|
+
render: (e, t) => Nt(e, t)
|
|
1888
|
+
},
|
|
1889
|
+
{
|
|
1890
|
+
kind: "range",
|
|
1891
|
+
is: (e) => Q(e, "isIRange"),
|
|
1892
|
+
render: (e, t) => Rt(e, t)
|
|
1893
|
+
},
|
|
1894
|
+
{
|
|
1895
|
+
kind: "values",
|
|
1896
|
+
is: (e) => Array.isArray(e) && e.length > 0 && e.every((e) => Array.isArray(e)),
|
|
1897
|
+
render: (e, t) => Rt(e, t)
|
|
1898
|
+
},
|
|
1899
|
+
{
|
|
1900
|
+
kind: "records",
|
|
1901
|
+
is: (e) => Array.isArray(e) && e.length > 0 && e.every(Y),
|
|
1902
|
+
render: (e, t) => At(e, t)
|
|
1903
|
+
},
|
|
1904
|
+
{
|
|
1905
|
+
kind: "record",
|
|
1906
|
+
is: (e) => Y(e),
|
|
1907
|
+
render: (e, t) => At(e, t)
|
|
1908
|
+
},
|
|
1909
|
+
{
|
|
1910
|
+
kind: "items",
|
|
1911
|
+
is: (e) => Array.isArray(e) && e.length > 0 && e.every((e) => !!$(e)),
|
|
1912
|
+
render: async (e, t) => {
|
|
1913
|
+
let n = e.length > 20 ? e.slice(0, 20) : e, r = [];
|
|
1914
|
+
for (let e of n) r.push(await $(e).render(e, t));
|
|
1915
|
+
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");
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
], Kt = class extends Error {
|
|
1919
|
+
constructor(e) {
|
|
1920
|
+
super(e), this.name = "NoRendererError";
|
|
1921
|
+
}
|
|
1922
|
+
};
|
|
1923
|
+
function $(e) {
|
|
1924
|
+
for (let t of Gt) if (t.is(e)) return t;
|
|
1925
|
+
return null;
|
|
1926
|
+
}
|
|
1927
|
+
async function qt(e, t, n) {
|
|
1928
|
+
await e?.getCalculation().ready();
|
|
1929
|
+
let r = $(t), i = t;
|
|
1930
|
+
if (!r && i && typeof i == "object" && !Array.isArray(i) && typeof i[Symbol.iterator] == "function") {
|
|
1931
|
+
let e = [];
|
|
1932
|
+
for (let t of i) if (e.push(t), e.length >= 1e3) break;
|
|
1933
|
+
i = e, r = $(i);
|
|
1934
|
+
}
|
|
1935
|
+
if (!r) throw new Kt(`No markdown renderer for this value. Renderable kinds: ${Gt.map((e) => e.kind).join(", ")}.`);
|
|
1936
|
+
return r.render(i, n);
|
|
1937
|
+
}
|
|
1938
|
+
async function Jt(e, t, n) {
|
|
1939
|
+
if (t === void 0) return {
|
|
1940
|
+
text: void 0,
|
|
1941
|
+
rendered: !0
|
|
1942
|
+
};
|
|
1943
|
+
if (typeof t == "string") return {
|
|
1944
|
+
text: t,
|
|
1945
|
+
rendered: !0
|
|
1946
|
+
};
|
|
1947
|
+
if (typeof t == "object" && t) try {
|
|
1948
|
+
return {
|
|
1949
|
+
text: await qt(e, t, n),
|
|
1950
|
+
rendered: !0
|
|
1951
|
+
};
|
|
1952
|
+
} catch (e) {
|
|
1953
|
+
if (!(e instanceof Kt)) throw e;
|
|
1954
|
+
}
|
|
1955
|
+
return function(e) {
|
|
1956
|
+
if (e === null) return {
|
|
1957
|
+
text: "null",
|
|
1958
|
+
rendered: !0
|
|
1959
|
+
};
|
|
1960
|
+
switch (typeof e) {
|
|
1961
|
+
case "number":
|
|
1962
|
+
case "boolean": return {
|
|
1963
|
+
text: _(e)?.display ?? String(e),
|
|
1964
|
+
rendered: !0
|
|
1965
|
+
};
|
|
1966
|
+
case "bigint":
|
|
1967
|
+
case "symbol": return {
|
|
1968
|
+
text: String(e),
|
|
1969
|
+
rendered: !0
|
|
1970
|
+
};
|
|
1971
|
+
case "function": return {
|
|
1972
|
+
text: "[Function]",
|
|
1973
|
+
rendered: !0
|
|
1974
|
+
};
|
|
1975
|
+
}
|
|
1976
|
+
let t = e;
|
|
1977
|
+
if (!0 === t.isFormulaError || !0 === t.isIRichData) return {
|
|
1978
|
+
text: _(e)?.display ?? "",
|
|
1979
|
+
rendered: !0
|
|
1980
|
+
};
|
|
1981
|
+
let n;
|
|
1982
|
+
try {
|
|
1983
|
+
n = String(e);
|
|
1984
|
+
} catch {
|
|
1985
|
+
n = "[object Object]";
|
|
1986
|
+
}
|
|
1987
|
+
return {
|
|
1988
|
+
text: n,
|
|
1989
|
+
rendered: !1
|
|
1990
|
+
};
|
|
1991
|
+
}(t);
|
|
1992
|
+
}
|
|
1993
|
+
var Yt = [T];
|
|
1994
|
+
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 };
|