react-semaphor 0.1.600 → 0.1.601

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/analytics-protocol/index.js +9 -9
  2. package/dist/assistant-context/index.js +1 -1
  3. package/dist/brand-studio/index.js +7 -7
  4. package/dist/briefings/index.js +48 -45
  5. package/dist/chunks/{assistant-chat-BULOkG9j.js → assistant-chat-BE0XXzZP.js} +12 -12
  6. package/dist/chunks/{bookmark-impact-kdvXke8n.js → bookmark-impact-DXDAN5AY.js} +3 -3
  7. package/dist/chunks/{bookmark-state-h1OLXVjE.js → bookmark-state-BMyB3Tb6.js} +4 -4
  8. package/dist/chunks/{card-filter-builder-CSCdSQQy.js → card-filter-builder-CE0-YVN5.js} +9 -9
  9. package/dist/chunks/comparison-window-caption-Dxj2CHOa.js +741 -0
  10. package/dist/chunks/{dashboard-briefing-launcher-9YwUclHA.js → dashboard-briefing-launcher-CntwKyiZ.js} +13 -13
  11. package/dist/chunks/{dashboard-controls-O6PNXMCp.js → dashboard-controls-XO089DMg.js} +15 -15
  12. package/dist/chunks/{dashboard-json-Bxf91TYq.js → dashboard-json-CQRiydUv.js} +4 -4
  13. package/dist/chunks/{dashboard-y9ON19ge.js → dashboard-mJKPFRbb.js} +1 -1
  14. package/dist/chunks/{dates-DPTbpNxK.js → dates-B-Urp5OD.js} +8 -8
  15. package/dist/chunks/{edit-dashboard-visual-CKwaW8H_.js → edit-dashboard-visual-f-Dm-BLR.js} +176 -176
  16. package/dist/chunks/filter-line-CKNMyNTQ.js +703 -0
  17. package/dist/chunks/{filter-reach-copy-ClzNcNhP.js → filter-reach-copy-B8GGyVuR.js} +1441 -1270
  18. package/dist/chunks/{filter-value-text-CXyuLW9Q.js → filter-value-text-CRtKecI5.js} +6 -6
  19. package/dist/chunks/{index-CRo5--Y6.js → index-DoPApnxg.js} +386 -360
  20. package/dist/chunks/{layout-grid-DSrBSfPM.js → layout-grid-CiSCZdIr.js} +1 -1
  21. package/dist/chunks/{matrix-analytical-definition-i9PQY066.js → matrix-analytical-definition-myf3D3Qx.js} +35 -35
  22. package/dist/chunks/{matrix-member-presentation-B_2beBc0.js → matrix-member-presentation-g0c_NpDW.js} +1 -1
  23. package/dist/chunks/{matrix-operation-contract-DdK0J_KU.js → matrix-operation-contract-C1SuOHLZ.js} +35 -35
  24. package/dist/chunks/{metric-comparison-Bhz0V841.js → metric-comparison-Cm0G893W.js} +3 -3
  25. package/dist/chunks/{paintbrush-1UiU-uTz.js → paintbrush-DQIwqlck.js} +1 -1
  26. package/dist/chunks/{palette-DFIFf_-m.js → palette-Cun747Rg.js} +1 -1
  27. package/dist/chunks/{pivot-result-contract-expectations-Dk7WFR_u.js → pivot-result-contract-expectations-C1Dyx8du.js} +17 -17
  28. package/dist/chunks/{pivot-result-identity-CzzrJpEm.js → pivot-result-identity-CBS-ssEp.js} +1 -1
  29. package/dist/chunks/{raw-temporal-value-BLvdaMng.js → raw-temporal-value-DN_l-Tss.js} +16 -16
  30. package/dist/chunks/{report-preferences-dialog-DiDsYpng.js → report-preferences-dialog-SDZEcG2x.js} +13 -13
  31. package/dist/chunks/{report-runtime-context-CEGluufW.js → report-runtime-context-BbedQdtc.js} +1 -1
  32. package/dist/chunks/{resolve-dashboard-input-context-BAv33KGg.js → resolve-dashboard-input-context-DRBS0eRa.js} +553 -553
  33. package/dist/chunks/{save-CWQ02kHo.js → save-Dj5bjm7P.js} +1 -1
  34. package/dist/chunks/{saved-dashboard-context-CvzYqADe.js → saved-dashboard-context-DWVlJcsa.js} +15 -15
  35. package/dist/chunks/{selection-filter-compiler-SwrBvyyJ.js → selection-filter-compiler-DmAr7yqC.js} +1 -1
  36. package/dist/chunks/{semaphor-ready-indicator-1PRI9Yh2.js → semaphor-ready-indicator-OFOoAY-A.js} +16370 -16518
  37. package/dist/chunks/{shelf-drop-preview-context-BLk5Nc6K.js → shelf-drop-preview-context-2swWypXu.js} +5 -5
  38. package/dist/chunks/{stored-dashboard-xhYYKBsO.js → stored-dashboard-NtOuEX6a.js} +111 -111
  39. package/dist/chunks/{style-sheet-parts-BX7d7-2-.js → style-sheet-parts-Qv4UcLAo.js} +2 -2
  40. package/dist/chunks/{table-export-sheet-BWSVTclx.js → table-export-sheet-Do7ZB0_F.js} +1 -1
  41. package/dist/chunks/{token-types-CnlEiAdS.js → token-types-Dy_aXO-U.js} +1 -1
  42. package/dist/chunks/{upload-DsqUSS8l.js → upload-Bq-puSVy.js} +1 -1
  43. package/dist/chunks/{validators-D2Hm57lJ.js → validators-C7DFk3QK.js} +78 -78
  44. package/dist/chunks/{variable-draft-DcKj8T1b.js → variable-draft-Cy03qnEi.js} +4 -4
  45. package/dist/dashboard/index.js +2 -2
  46. package/dist/dashboard-authoring/index.js +80 -75
  47. package/dist/format-utils/index.js +238 -237
  48. package/dist/index.js +18 -18
  49. package/dist/report-runtime-context/index.js +1 -1
  50. package/dist/surfboard/index.js +2 -2
  51. package/dist/types/briefings/attachment-outcomes.d.ts +1 -1
  52. package/dist/types/briefings/attachments.d.ts +45 -4
  53. package/dist/types/briefings/index.d.ts +1 -1
  54. package/dist/types/index.js +5 -5
  55. package/dist/types/lib/export-utils.d.ts +72 -0
  56. package/dist/types/lib/formatters/dashboard-temporal-presentation.d.ts +10 -0
  57. package/dist/types/shared/dashboard-authoring/card-data-file.d.ts +31 -0
  58. package/dist/types/shared/dashboard-authoring/index.d.ts +3 -0
  59. package/package.json +1 -1
  60. package/dist/chunks/comparison-window-caption-DJDwP9XO.js +0 -1309
  61. package/dist/chunks/filter-line-Dkg3yuOX.js +0 -134
@@ -1,1309 +0,0 @@
1
- import { aI as Ge, i as Xe, j as U, m as qe, S as $e, aJ as ae, aK as Pe, aL as Ye, aM as Ie, aN as De, am as Le, ao as Me, at as We, ay as Je, au as Ze, f as Qe, a as B, a6 as de, a4 as et, an as tt, o as fe, s as rt, aF as nt, Y as pe, _ as ot, a0 as at, a7 as st, aO as I, aP as K } from "./pivot-result-contract-expectations-Dk7WFR_u.js";
2
- import { h as Y, e as it, p as lt, k as ct } from "./export-file-format-C-tJsxsf.js";
3
- import { aX as j, a7 as ut, m as X, aW as mt, r as dt } from "./validators-D2Hm57lJ.js";
4
- import "./matrix-operation-contract-DdK0J_KU.js";
5
- import "./analytics-base-schemas-DevrgqQb.js";
6
- import { readPdfCapacityFacts as ft, PDF_SAFETY_LIMIT_EXCEEDED as se, PDF_CAPACITY as k, PDF_NUMBER_COLUMN_TOO_WIDE as ke, getUtf8ByteLength as pt, FAST_PDF_POLICY as ht, isPdfCapacityRefusalCode as bt } from "../pdf-export-policy/index.js";
7
- import { w as yt, v as gt } from "./raw-temporal-value-BLvdaMng.js";
8
- import { c as wt, b as he } from "./pivot-result-identity-CzzrJpEm.js";
9
- function xt(e, t, r) {
10
- const n = {
11
- ...t,
12
- locale: t.locale ?? r
13
- };
14
- if (n.type === "number")
15
- return U(e, n);
16
- const { prefix: o, suffix: s, ...c } = n;
17
- return `${o ?? ""}${U(e, {
18
- ...c,
19
- negativeStyle: n.type === "currency" ? n.negativeStyle : "minus"
20
- })}${s ?? ""}`;
21
- }
22
- function Q(e, t, r) {
23
- return e === null ? { value: e, text: null } : !t || !Xe(t) && t.type !== "duration" ? {
24
- value: e,
25
- text: U(e, { type: "number", locale: r })
26
- } : t.type === "duration" ? {
27
- value: e,
28
- text: qe(e, {
29
- inputUnit: t.inputUnit,
30
- outputStyle: t.outputStyle,
31
- largestUnit: t.largestUnit,
32
- smallestUnit: t.smallestUnit,
33
- maxUnits: t.maxUnits,
34
- prefix: t.prefix,
35
- suffix: t.suffix,
36
- negativeInParentheses: t.negativeStyle === "parentheses"
37
- })
38
- } : { value: e, text: xt(e, t, r) };
39
- }
40
- function be(e, t, r, n) {
41
- return e === null ? { value: e, text: null } : n === "percent" ? {
42
- value: e,
43
- text: U(e, {
44
- type: "percent",
45
- locale: r,
46
- minimumFractionDigits: t,
47
- maximumFractionDigits: t,
48
- percentValueMode: "fraction"
49
- })
50
- } : {
51
- value: e,
52
- text: U(e, {
53
- type: "number",
54
- locale: r,
55
- minimumFractionDigits: t,
56
- maximumFractionDigits: t,
57
- suffix: "×"
58
- })
59
- };
60
- }
61
- function ye(e, t) {
62
- if (e === void 0) return t;
63
- if (!Number.isInteger(e) || e < 0 || e > 6)
64
- throw new RangeError("Comparison precision must be an integer from 0 to 6.");
65
- return e;
66
- }
67
- function Sr(e, t) {
68
- const r = {
69
- mode: t.displayMode,
70
- current: Q(
71
- e.currentValue,
72
- t.metricFormat,
73
- t.locale
74
- ),
75
- comparison: Q(
76
- e.comparisonValue,
77
- t.metricFormat,
78
- t.locale
79
- )
80
- };
81
- return (t.displayMode === "difference" || t.displayMode === "both") && (r.difference = Q(
82
- e.delta,
83
- Ge(t.metricFormat),
84
- t.locale
85
- )), (t.displayMode === "percent_change" || t.displayMode === "both") && (r.percentChange = be(
86
- e.percentChange,
87
- ye(t.precision, 1),
88
- t.locale,
89
- "percent"
90
- )), t.displayMode === "ratio" && (r.ratio = be(
91
- e.ratio,
92
- ye(t.precision, 2),
93
- t.locale,
94
- "ratio"
95
- )), r;
96
- }
97
- const vt = /* @__PURE__ */ new Set(["second", "minute", "hour", "day", "month"]);
98
- function Ct(e) {
99
- const { presentation: t } = e;
100
- return e.formattedValues ? (t == null ? void 0 : t.kind) === "text" || (t == null ? void 0 : t.kind) === "measure" && t.format.type === "duration" ? "text" : (t == null ? void 0 : t.kind) === "temporal_bucket" ? vt.has(t.grain) ? "date" : "text" : (t == null ? void 0 : t.kind) === "datetime" ? "date" : e.dataType === "number" ? "number" : e.dataType === "boolean" ? "boolean" : e.dataType === "unknown" ? "by_value" : "text" : "by_value";
101
- }
102
- function _t(e) {
103
- const t = (o, s) => Number.isInteger(o) ? Math.min(20, Math.max(0, o)) : s, r = t(e.minimumFractionDigits, 0), n = Math.max(r, t(e.maximumFractionDigits, 2));
104
- return n === 0 ? "" : `.${"0".repeat(n)}`;
105
- }
106
- function ee(e) {
107
- return `"${e.replace(/"/g, "")}"`;
108
- }
109
- function Tt(e) {
110
- let t;
111
- try {
112
- t = new Intl.NumberFormat(e.locale ?? "en-US", {
113
- style: "currency",
114
- currency: e.currency || "USD"
115
- }).formatToParts(1);
116
- } catch {
117
- return;
118
- }
119
- const r = t.findIndex((s) => s.type === "currency"), n = t.findIndex((s) => s.type === "integer");
120
- if (r < 0 || n < 0) return;
121
- const o = (s, c) => t.slice(s, c).filter((l) => l.type === "literal").map((l) => l.value.replace(/\s/g, " ")).join("");
122
- return r < n ? { side: "before", text: t[r].value + o(r + 1, n) } : {
123
- side: "after",
124
- text: o(n + 1, r) + t[r].value
125
- };
126
- }
127
- function Et(e) {
128
- const t = _t(e);
129
- let r;
130
- if (e.type === "scientific")
131
- r = `0${t}E+00`;
132
- else {
133
- const n = `${e.useGrouping === !1 ? "0" : "#,##0"}${t}`;
134
- if (e.type === "currency") {
135
- const o = Tt(e);
136
- r = o ? o.side === "before" ? `${ee(o.text)}${n}` : `${n}${ee(o.text)}` : n;
137
- } else e.type === "percent" ? r = e.percentValueMode === "whole" ? `${n}${ee("%")}` : `${n}%` : r = n;
138
- }
139
- return e.negativeStyle === "parentheses" ? `${r};(${r})` : r;
140
- }
141
- function St(e, t) {
142
- if (!e.formattedValues) return;
143
- const { presentation: r } = e;
144
- if (t === "number" || t === "by_value")
145
- return (r == null ? void 0 : r.kind) !== "measure" || r.format.type === "duration" ? void 0 : Et(r.format);
146
- if (t === "date") {
147
- if ((r == null ? void 0 : r.kind) === "temporal_bucket")
148
- return r.grain === "day" ? "yyyy-mm-dd" : r.grain === "month" ? "mmm yyyy" : "yyyy-mm-dd hh:mm";
149
- if ((r == null ? void 0 : r.kind) === "datetime")
150
- return r.dateOnly ? "yyyy-mm-dd" : "yyyy-mm-dd hh:mm:ss";
151
- }
152
- }
153
- function ge(e) {
154
- const t = Ct(e), r = St(e, t);
155
- return Object.freeze({
156
- key: e.key,
157
- label: e.label,
158
- cellType: t,
159
- ...r === void 0 ? {} : { numberFormat: r }
160
- });
161
- }
162
- const Ft = 15, $t = /^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
163
- function Ae(e) {
164
- return $t.test(e) ? e : void 0;
165
- }
166
- function we(e) {
167
- const r = e.replace(/^-/, "").replace(/[eE].*$/, "").replace(".", "").replace(/^0+/, "").replace(/0+$/, "");
168
- if (r.length > Ft) return !1;
169
- const n = Number(e);
170
- return Number.isFinite(n) && (n !== 0 || r.length === 0);
171
- }
172
- const Pt = Date.UTC(1900, 2, 1), It = Date.UTC(1e4, 0, 1), Dt = Date.UTC(1899, 11, 30), Lt = 864e5;
173
- function Mt(e) {
174
- const t = Date.UTC(
175
- e.year,
176
- e.month - 1,
177
- e.day,
178
- e.hour,
179
- e.minute,
180
- e.second
181
- );
182
- if (!(e.year < 1900 || !Number.isFinite(t)) && !(t < Pt || t >= It))
183
- return (t - Dt) / Lt;
184
- }
185
- function xe(e, t, r) {
186
- if (typeof e == "number")
187
- return Number.isFinite(e) ? { kind: "number", text: t, value: e } : void 0;
188
- if (j(e))
189
- return we(e.value) ? { kind: "number", text: t, value: e } : void 0;
190
- if (r && typeof e == "string") {
191
- const n = Ae(e);
192
- return n !== void 0 && we(n) ? { kind: "number", text: t, value: n } : void 0;
193
- }
194
- }
195
- function H(e) {
196
- const { value: t, text: r, column: n } = e;
197
- if (r === "") return { kind: "empty" };
198
- const o = { kind: "text", text: r };
199
- switch (n.cellType) {
200
- case "text":
201
- return o;
202
- case "date": {
203
- const s = e.wallClock ? Mt(e.wallClock) : void 0;
204
- return s === void 0 ? o : { kind: "date", text: r, serial: s };
205
- }
206
- case "number":
207
- return xe(t, r, !0) ?? o;
208
- case "boolean":
209
- return typeof t == "boolean" ? { kind: "boolean", text: r, value: t } : o;
210
- case "by_value":
211
- return typeof t == "boolean" ? { kind: "boolean", text: r, value: t } : xe(t, r, !1) ?? o;
212
- }
213
- }
214
- function Fr(e) {
215
- return e.kind === "empty" ? "" : e.text;
216
- }
217
- const $r = {
218
- rowLabels: "tabular",
219
- subtotals: "after"
220
- };
221
- function Pr(e, t) {
222
- const r = t.rowLabels === "outline" ? { kind: "compact" } : e.layout.kind === "tabular" ? e.layout : { kind: "tabular", repeatLabels: !1 }, n = e.totals.rows;
223
- return {
224
- ...e,
225
- layout: r,
226
- totals: {
227
- ...e.totals,
228
- rows: {
229
- ...n,
230
- levels: Object.fromEntries(
231
- Object.entries(n.levels).map(([o, s]) => [
232
- o,
233
- { ...s, position: t.subtotals }
234
- ])
235
- )
236
- }
237
- }
238
- };
239
- }
240
- const kt = 2;
241
- function At(e) {
242
- return typeof e == "number" ? Number.isInteger(e) : j(e) ? !e.value.includes(".") : !0;
243
- }
244
- function Nt(e, t, r) {
245
- const n = e.descriptors.measures.filter(
246
- (c) => r.measureFormats[c.id] === void 0 && c.semanticFormat === void 0 && ut(c.column.dataType) === "number"
247
- );
248
- if (n.length === 0) return r;
249
- const o = /* @__PURE__ */ new Set();
250
- e.columns.forEach((c, l) => {
251
- if (!(c.kind !== "measure" || o.has(c.measureId)))
252
- for (const f of t) {
253
- const d = f.values[l];
254
- if ((d == null ? void 0 : d.kind) === "value" && !At(d.value)) {
255
- o.add(c.measureId);
256
- return;
257
- }
258
- }
259
- });
260
- const s = { ...r.measureFormats };
261
- for (const { id: c } of n) {
262
- const l = o.has(c) ? kt : 0;
263
- s[c] = {
264
- type: "number",
265
- minimumFractionDigits: l,
266
- maximumFractionDigits: l,
267
- useGrouping: !0
268
- };
269
- }
270
- return { ...r, measureFormats: s };
271
- }
272
- function z(e) {
273
- return X(e.slice(0, -1));
274
- }
275
- function Ot(e, t) {
276
- return t.length > e.length && X(t.slice(0, e.length)) === X(e);
277
- }
278
- function Rt(e) {
279
- return e.map((t, r) => {
280
- if (r === 0 || t.kind !== "layout") return !1;
281
- const n = e[r - 1];
282
- if (n.kind !== "layout") return !1;
283
- if (t.role !== "member" || Ot(n.rowPath, t.rowPath)) return !0;
284
- const o = e[r - 2];
285
- return n.role === "member" && (!o || o.kind !== "layout" || o.role !== "member" || z(o.rowPath) !== z(n.rowPath)) && t.rowPath.length === n.rowPath.length && z(t.rowPath) === z(n.rowPath);
286
- });
287
- }
288
- const Ut = "pdf-group-continuation";
289
- function Ne(e, t, r) {
290
- return !(r != null && r.hasTextAffixes) && t.kind === "value" && (typeof t.value == "number" || j(t.value)) ? e : Y(e);
291
- }
292
- function Kt(e, t, r) {
293
- const n = $e(e.descriptors, t.presentation, r), o = e.columns.map((u) => {
294
- var a;
295
- return u.kind === "measure" && ((a = n.measureSemantics.get(u.measureId)) == null ? void 0 : a.isNumeric) === !0;
296
- }), s = (u) => ae([u], n.levels), c = (u, a, m) => Pe(u, a, t.presentation.totals[m], n.levels), l = e.columns.map((u) => {
297
- if (u.kind !== "measure") return u.label;
298
- const a = u.columnPath.map(s);
299
- return u.role !== "member" && a.push(c(u.columnPath, u.role, "columns")), [...a, u.label].join(" / ");
300
- }), f = Math.min(t.spec.columns.length, Math.max(
301
- 0,
302
- ...e.columns.map((u) => u.kind === "measure" ? u.columnPath.length + (u.role !== "member" ? 1 : 0) : 0)
303
- )), d = Array.from({ length: f + 1 }, (u, a) => e.columns.map((m) => a === f ? m.label : m.kind !== "measure" ? "" : a < m.columnPath.length ? s(m.columnPath[a]) : a === m.columnPath.length && m.role !== "member" ? c(m.columnPath, m.role, "columns") : "")), b = (u, a) => Ye({
304
- path: u.rowPath,
305
- role: u.kind === "layout" ? u.role : "member",
306
- levelCount: Math.max(1, t.spec.rows.length),
307
- repeatLabels: t.presentation.layout.kind !== "tabular" || t.presentation.layout.repeatLabels,
308
- previousPath: a == null ? void 0 : a.rowPath
309
- }), w = (u, a) => {
310
- if (u.kind !== "layout") throw new Error("Layout presentation requires layout rows.");
311
- if (u.values.length !== e.columns.length) throw new Error("Matrix row does not match its frozen layout.");
312
- const m = b(u, a);
313
- return e.columns.map((y, p) => {
314
- if (y.kind === "hierarchy")
315
- return `${" ".repeat(Math.max(0, u.rowPath.length - 1))}${c(u.rowPath, u.role, "rows")}`;
316
- if (y.kind === "level") {
317
- const x = t.spec.rows.findIndex(($) => $.id === y.levelId), v = m[x];
318
- return v != null && v.visible ? v.total ? c(u.rowPath, u.role, "rows") : ae(v.path, n.levels) : "";
319
- }
320
- const C = u.values[p], g = n.measures.get(y.measureId);
321
- if (C.kind === "value" && !g)
322
- throw new Error("Matrix value is missing its measure descriptor.");
323
- return Ie(C, g, t.presentation.absence);
324
- });
325
- }, T = (u, a) => w(u, a).map((m, y) => {
326
- const p = e.columns[y];
327
- return p.kind === "measure" ? Ne(m, u.values[y], n.measureSemantics.get(p.measureId)) : Y(m);
328
- });
329
- return {
330
- headers: l,
331
- headerBands: d,
332
- numericColumns: o,
333
- /** The card's prepared formats this presentation formats with (the Excel form reads its measure formats). */
334
- formatting: n,
335
- /** A row's cells; after `previous`, a tabular layout prints each label once. */
336
- row: (u, a) => w(u, a),
337
- /**
338
- * Level columns whose group label the row above shows, so this row
339
- * continues the group (Plan 2, 2d, C8). Only a member row after a member
340
- * row continues one: a total prints as a band, and its rules stay whole
341
- * above and below it.
342
- */
343
- continuedColumns: (u, a) => {
344
- const m = (p) => (p == null ? void 0 : p.kind) === "layout" && p.role === "member";
345
- if (!m(u) || !m(a)) return [];
346
- const y = b(u, a);
347
- return e.columns.flatMap((p, C) => {
348
- var x;
349
- if (p.kind !== "level") return [];
350
- const g = t.spec.rows.findIndex((v) => v.id === p.levelId);
351
- return g < u.rowPath.length && ((x = y[g]) == null ? void 0 : x.visible) === !1 ? [C] : [];
352
- });
353
- },
354
- csvRow: (u) => T(u),
355
- /**
356
- * `previousRow` is the row before `data[0]`, carried by the export's
357
- * continuation, so a tabular layout prints each label once across the
358
- * whole file. Retries are pure: suppression never relies on mutable
359
- * formatter state or an earlier worker. Without it, the first row prints
360
- * its labels.
361
- */
362
- csvRows: (u, a) => u.map((m, y) => T(m, y ? u[y - 1] : a ?? void 0))
363
- };
364
- }
365
- function Ir(e) {
366
- return e.columns.map((t) => Y(t.label));
367
- }
368
- function Dr(e, t, r) {
369
- return jt(e, t, r).map((n, o) => {
370
- const s = t.columns[o];
371
- return s.kind === "measure" ? Ne(n, e.values[o], r.measureSemantics.get(s.measureId)) : Y(n);
372
- });
373
- }
374
- function jt(e, t, r) {
375
- if (e.kind !== "flat") throw new Error("Flat Matrix CSV requires flat rows.");
376
- if (e.values.length !== t.columns.length) throw new Error("Matrix row does not match its frozen layout.");
377
- const n = [...e.rowPath, ...e.columnPath];
378
- return t.columns.map((o, s) => {
379
- if (o.kind === "measure") {
380
- const l = e.values[s], f = r.measures.get(o.measureId);
381
- if (l.kind === "value" && !f) throw new Error("Matrix value is missing its measure descriptor.");
382
- return Ie(l, f, r.absence);
383
- }
384
- const c = o.kind === "level" ? n.find((l) => l.levelId === o.levelId) : void 0;
385
- if (!c) throw new Error("Flat Matrix row does not match its frozen layout.");
386
- return ae([c], r.levels);
387
- });
388
- }
389
- function Vt(e) {
390
- const t = Kt(e.layout, e.request, e.report), r = e.layout.columns.map((c, l) => ({
391
- index: l,
392
- columnId: `matrix:${l}`,
393
- label: t.headers[l],
394
- isNumeric: t.numericColumns[l]
395
- })), n = (c, l, f) => ({
396
- text: c,
397
- colspan: 1,
398
- rowspan: 1,
399
- columnId: r[l].columnId,
400
- isHeader: f,
401
- isNumeric: r[l].isNumeric,
402
- className: r[l].isNumeric ? "numeric" : e.layout.columns[l].kind === "hierarchy" ? "matrix-hierarchy" : ""
403
- }), o = [], s = e.layout.columns.findIndex((c) => c.kind === "measure");
404
- e.request.spec.columns.length && s >= 0 && o.push({
405
- repeatHeader: !0,
406
- headerType: "pivot-axis",
407
- headerRowIndex: 0,
408
- cells: [
409
- ...s ? [{ ...n("", 0, !0), colspan: s }] : [],
410
- {
411
- ...n(e.request.spec.columns.map((c) => De(c, e.request.presentation)).join(" / "), s, !0),
412
- colspan: e.layout.columns.length - s,
413
- isNumeric: !1,
414
- className: ""
415
- }
416
- ]
417
- });
418
- for (const [c, l] of t.headerBands.entries())
419
- o.push({
420
- repeatHeader: !0,
421
- headerType: c === t.headerBands.length - 1 ? "metrics" : "pivot-level",
422
- headerRowIndex: o.length,
423
- cells: l.map((f, d) => n(f, d, !0))
424
- });
425
- return {
426
- headers: o,
427
- rows: e.rows.map((c, l) => {
428
- const f = new Set(t.continuedColumns(c, e.rows[l - 1]));
429
- return {
430
- index: l,
431
- type: c.kind === "layout" && c.role !== "member" ? "subtotal" : "data",
432
- subtotalLevel: String(c.rowPath.length),
433
- // A tabular layout prints each label once unless it repeats them; the
434
- // blank cell continues its group, so a grid draws no rule above it.
435
- cells: t.row(c, e.rows[l - 1]).map((d, b) => f.has(b) ? { ...n(d, b, !1), className: Ut } : n(d, b, !1))
436
- };
437
- }),
438
- grandTotal: null,
439
- // Totals are already in the ordered body at their authored position.
440
- metadata: {
441
- tableType: "pivot",
442
- totalRows: e.rows.length,
443
- totalColumns: r.length,
444
- rowLevels: e.layout.columns.filter((c) => c.kind !== "measure").length,
445
- pivotLevels: e.request.spec.columns.length,
446
- hasGrandTotal: !1,
447
- columnOrder: r.map((c) => c.columnId),
448
- columns: r
449
- }
450
- };
451
- }
452
- function Bt(e, t, r) {
453
- const { levels: n } = $e(e.descriptors, t.presentation, r), o = t.spec.columns.length > 0, s = [], c = [], l = e.columns.map((d, b) => {
454
- if (d.kind !== "measure") return null;
455
- const w = o ? `${d.role}:${X(d.columnPath)}` : `measure:${b}`;
456
- let T = s.indexOf(w);
457
- return T < 0 && (T = s.push(w) - 1, c.push(o ? Pe(d.columnPath, d.role, t.presentation.totals.columns, n) : d.label)), T;
458
- }), f = t.spec.columns[t.spec.columns.length - 1];
459
- return {
460
- columnGroups: l,
461
- groupLabels: c,
462
- /** What bands name their groups by: the innermost column level, or "Measures". */
463
- groupLevelLabel: f ? De(f, t.presentation) : "Measures"
464
- };
465
- }
466
- function Lr(e) {
467
- const { layout: t, rows: r, report: n } = e, o = {
468
- ...e.request,
469
- presentation: Nt(t, r, e.request.presentation)
470
- }, s = Vt({ layout: t, rows: r, request: o, report: n }), c = Rt(r), l = Bt(t, o, n), f = {
471
- ...s,
472
- rows: s.rows.map((d, b) => ({ ...d, keepWithPrevious: c[b] })),
473
- metadata: { ...s.metadata, ...l }
474
- };
475
- return { request: o, table: f, ...l };
476
- }
477
- const F = (e) => e.toLocaleString("en-US"), G = (e) => `${F(Math.ceil(e / 1048576))} MB`, te = "export the data as CSV or Excel";
478
- function Mr(e) {
479
- const t = ft(e.facts), r = e.dataExport ? `Add a filter to narrow it, or ${te}.` : "Add a filter to narrow it, then export again.";
480
- switch (e.code) {
481
- case "PDF_ROW_LIMIT_EXCEEDED": {
482
- const n = e.subject ?? "This table", o = t.rowLimit ?? k.maxTableRows;
483
- return t.rowCount !== void 0 ? `${n} has ${F(t.rowCount)} rows. A PDF holds up to ${F(o)} rows per table. ${r}` : `${n} has more than ${F(o)} rows, the most a PDF holds per table. ${r}`;
484
- }
485
- case "PDF_PAGE_LIMIT_EXCEEDED": {
486
- const n = e.subject ?? "This PDF", o = t.pageLimit ?? k.maxPages;
487
- return t.pageCount !== void 0 ? `${n} is ${F(t.pageCount)} pages. A PDF holds up to ${F(o)}. ${r}` : `${n} is longer than ${F(o)} pages, the most a PDF holds. ${r}`;
488
- }
489
- case "PDF_SIZE_LIMIT_EXCEEDED": {
490
- const n = e.subject ?? "This PDF", o = t.byteLimit ?? k.maxFileBytes;
491
- return t.bytes !== void 0 ? `${n} is ${G(t.bytes)}. A PDF file holds up to ${G(o)}. ${r}` : `${n} is larger than ${G(o)}, the most a PDF file holds. ${r}`;
492
- }
493
- case "PDF_CAPTURE_TOO_TALL":
494
- return `${e.subject ?? "This dashboard"} is too long to print as one PDF. Print one sheet or fewer cards${e.dataExport ? `, or ${te}` : ""}.`;
495
- case ke:
496
- return `A number in this table is too wide for its column in a PDF. Use landscape or fewer columns${e.dataExport ? `, or ${te}` : ""}.`;
497
- case se:
498
- return `This PDF is over what a PDF holds: ${F(k.maxTableRows)} rows per table, ${F(
499
- k.maxPages
500
- )} pages and ${G(k.maxFileBytes)}. ${r}`;
501
- }
502
- }
503
- class Ht extends Error {
504
- constructor(t, r = se) {
505
- super(t), this.code = r;
506
- }
507
- }
508
- function zt(e) {
509
- return bt(e) || e === se || e === ke;
510
- }
511
- function ve(e) {
512
- if (!e || typeof e != "object")
513
- return;
514
- const { error: t, message: r, detail: n } = e;
515
- for (const o of [t, r, n])
516
- if (typeof o == "string" && o.trim())
517
- return o.trim();
518
- }
519
- async function Gt(e) {
520
- const t = `PDF request failed: ${e.status} ${e.statusText}`.trim(), r = e.headers.get("content-type") || "";
521
- try {
522
- if (r.includes("application/json")) {
523
- const o = await e.json(), s = typeof o.code == "string" ? o.code : typeof o.errorCode == "string" ? o.errorCode : void 0;
524
- return { message: ve(o) || t, code: s };
525
- }
526
- const n = await e.text();
527
- if (!n.trim())
528
- return { message: t };
529
- try {
530
- const o = JSON.parse(n), s = typeof o.code == "string" ? o.code : typeof o.errorCode == "string" ? o.errorCode : void 0;
531
- return {
532
- message: ve(o) || n.trim(),
533
- code: s
534
- };
535
- } catch {
536
- return { message: n.trim() };
537
- }
538
- } catch {
539
- return { message: t };
540
- }
541
- }
542
- async function kr(e) {
543
- if (!e.token) throw new Error("Missing auth token for PDF export");
544
- if (pt(e.serializedPayload) > ht.maxRequestBytes)
545
- throw new Error("Fast-path PDF request exceeds the structured body limit");
546
- const t = await (e.fetchImpl ?? fetch)(e.url, {
547
- method: "POST",
548
- headers: { "Content-Type": "application/json", Authorization: `Bearer ${e.token}` },
549
- body: e.serializedPayload,
550
- signal: e.signal
551
- });
552
- if (!t.ok) {
553
- const n = await Gt(t);
554
- throw zt(n.code) ? new Ht(n.message, n.code) : new Error(n.message);
555
- }
556
- const r = await t.json();
557
- if (r != null && r.error) throw new Error(r.error);
558
- if (typeof (r == null ? void 0 : r.url) != "string" || !r.url.trim())
559
- throw new Error("Fast-path PDF response missing download URL");
560
- return r;
561
- }
562
- const Ar = 1, Oe = ["loading", "measuring", "checking", "laidOut"], Xt = [
563
- // Already emitted before these contracts; names kept.
564
- "document_matrix_too_large",
565
- "document_matrix_unavailable",
566
- "document_matrix_too_wide",
567
- "document_kpi_value_overflow",
568
- "print_inputs_not_captured",
569
- // New.
570
- "document_section_setup",
571
- "document_input_missing",
572
- "document_section_query_failed",
573
- "document_table_completeness_unverified",
574
- "document_row_limit_exceeded",
575
- "document_section_render_failed",
576
- "document_page_overflow",
577
- "document_sheet_not_found",
578
- "document_print_timed_out",
579
- // PDF capacity contract PC-D3: more pages than one PDF holds.
580
- "document_page_limit_exceeded"
581
- ];
582
- function Nr(e) {
583
- return Xt.includes(e);
584
- }
585
- const qt = 64, Yt = 120, Wt = 3, Jt = 80, Zt = [...Oe, "noPageStack", "unknown"];
586
- function re(e, t) {
587
- return typeof e != "string" ? void 0 : e.trim().slice(0, t).trim() || void 0;
588
- }
589
- function S(e, t) {
590
- return typeof e == "number" && Number.isInteger(e) && e >= t ? e : void 0;
591
- }
592
- function ne(e, t) {
593
- return t.includes(e) ? e : void 0;
594
- }
595
- function Qt(e) {
596
- let t = e;
597
- if (typeof e == "string")
598
- try {
599
- t = JSON.parse(e);
600
- } catch {
601
- return {};
602
- }
603
- if (!t || typeof t != "object" || Array.isArray(t)) return {};
604
- const r = t, n = Array.isArray(r.inputLabels) ? r.inputLabels.map((s) => re(s, Jt)).filter((s) => s !== void 0).slice(0, Wt) : [], o = {
605
- sectionId: re(r.sectionId, qt),
606
- sectionTitle: re(r.sectionTitle, Yt),
607
- pageNumber: S(r.pageNumber, 1),
608
- rowCount: S(r.rowCount, 0),
609
- rowLimit: S(r.rowLimit, 1),
610
- inputLabels: n.length ? n : void 0,
611
- overflowAxis: ne(r.overflowAxis, ["height", "width"]),
612
- overflowPx: S(r.overflowPx, 0),
613
- matrixLimit: ne(r.matrixLimit, ["rows", "bytes"]),
614
- layoutStage: ne(r.layoutStage, Zt),
615
- loadingSectionCount: S(r.loadingSectionCount, 0),
616
- measuredRowCount: S(r.measuredRowCount, 0),
617
- totalRowCount: S(r.totalRowCount, 0),
618
- pageCount: S(r.pageCount, 0),
619
- pageLimit: S(r.pageLimit, 1)
620
- };
621
- return Object.fromEntries(
622
- Object.entries(o).filter(([, s]) => s !== void 0)
623
- );
624
- }
625
- function Or(e) {
626
- const t = Qt(e.facts), r = t.sectionTitle ? `Section "${t.sectionTitle}"` : t.sectionId ? `Section ${t.sectionId}` : "A section", n = t.pageNumber !== void 0 ? ` on page ${t.pageNumber}` : "";
627
- switch (e.code) {
628
- case "document_section_setup":
629
- return `${r} is not set up to print.`;
630
- case "document_input_missing":
631
- return t.inputLabels ? `${r} needs a value for ${t.inputLabels.join(", ")}.` : `${r} needs a value for a required input.`;
632
- case "document_section_query_failed":
633
- return `${r}: its data could not be loaded.`;
634
- case "document_table_completeness_unverified":
635
- return `${r}: the query returned no total row count, so the table could not be confirmed complete.`;
636
- case "document_row_limit_exceeded":
637
- return t.rowCount !== void 0 && t.rowLimit !== void 0 ? `${r} has ${t.rowCount} rows; a document table prints up to ${t.rowLimit}.` : `${r} has more rows than a document table prints.`;
638
- case "document_section_render_failed":
639
- return `${r} could not be drawn.`;
640
- case "document_page_overflow":
641
- return `${r}${n} does not fit the page${t.overflowAxis ? ` (${t.overflowAxis}` : ""}${t.overflowAxis && t.overflowPx !== void 0 ? `, ${t.overflowPx} px over` : ""}${t.overflowAxis ? ")" : ""}.`;
642
- case "document_matrix_too_large":
643
- return t.matrixLimit === "rows" && t.rowLimit !== void 0 ? `${r}: the Matrix has more than ${t.rowLimit} rows, the most a report prints.` : `${r}: the Matrix is too large to print.`;
644
- case "document_matrix_unavailable":
645
- return `${r}: the Matrix result could not be loaded.`;
646
- case "document_matrix_too_wide":
647
- return `${r}: the Matrix is wider than the page.`;
648
- case "document_kpi_value_overflow":
649
- return `${r}: a KPI value does not fit its tile.`;
650
- case "print_inputs_not_captured":
651
- return t.inputLabels ? `The report's input values were not saved: ${t.inputLabels.join(", ")}.` : "The report's input values were not saved.";
652
- case "document_sheet_not_found":
653
- return "The requested Document sheet is not in the dashboard.";
654
- case "document_page_limit_exceeded":
655
- return t.pageCount !== void 0 && t.pageLimit !== void 0 ? `The Document is ${t.pageCount} pages; a PDF holds up to ${t.pageLimit}.` : "The Document has more pages than a PDF holds.";
656
- case "document_print_timed_out":
657
- return [
658
- `The Document did not finish preparing in time (stage ${t.layoutStage ?? "unknown"}`,
659
- t.measuredRowCount !== void 0 ? `; ${t.measuredRowCount} of ${t.totalRowCount ?? "unknown"} rows measured` : "",
660
- t.pageCount !== void 0 ? `; ${t.pageCount} pages` : "",
661
- t.loadingSectionCount ? `; ${t.loadingSectionCount} sections loading` : "",
662
- ")."
663
- ].join("");
664
- }
665
- }
666
- function er(e) {
667
- return Oe.includes(e);
668
- }
669
- function oe(e) {
670
- return typeof e == "number" && Number.isInteger(e) && e >= 0;
671
- }
672
- function Rr(e) {
673
- let t = e;
674
- if (typeof e == "string")
675
- try {
676
- t = JSON.parse(e);
677
- } catch {
678
- return;
679
- }
680
- if (!t || typeof t != "object" || Array.isArray(t)) return;
681
- const { stage: r, measuredRowCount: n, totalRowCount: o, pageCount: s } = t;
682
- if (!(!er(r) || !oe(n) || o !== null && !oe(o) || s !== null && !oe(s)))
683
- return { stage: r, measuredRowCount: n, totalRowCount: o, pageCount: s };
684
- }
685
- function Ur(e, t, r) {
686
- const n = t.from > e.start ? t.from : e.start, o = t.to && t.to < e.end ? t.to : e.end, s = o > r ? "running" : n > e.start ? "start" : o < e.end ? "end" : void 0;
687
- return { start: n, end: o, ...s ? { partial: s } : {} };
688
- }
689
- function Kr(e, t, r) {
690
- switch (t) {
691
- case "running":
692
- return `${e} (so far)`;
693
- case "start":
694
- return r ? `${e} (from ${r.start})` : `${e} (partial)`;
695
- case "end":
696
- return r ? `${e} (to ${r.end})` : `${e} (partial)`;
697
- default:
698
- return e;
699
- }
700
- }
701
- function jr(e, t, r) {
702
- const n = Date.parse(e.startInclusive), o = Date.parse(e.endExclusive);
703
- if (!Number.isFinite(n) || !Number.isFinite(o)) return;
704
- if (t.granularity === "hour" || t.granularity === "minute" || t.granularity === "second") {
705
- const f = (d) => {
706
- try {
707
- return new Intl.DateTimeFormat((r == null ? void 0 : r.locale) ?? "en-US", {
708
- timeStyle: (r == null ? void 0 : r.dateTime.timeStyle) ?? "short",
709
- timeZone: t.calendar.tz
710
- }).format(new Date(d));
711
- } catch {
712
- return new Date(d).toISOString();
713
- }
714
- };
715
- return { start: f(n), end: f(o) };
716
- }
717
- const s = { kind: "temporal_bucket", granularity: "day", calendar: t.calendar };
718
- let c;
719
- try {
720
- c = Le({
721
- metadata: s,
722
- locale: (r == null ? void 0 : r.locale) ?? "en-US",
723
- ...r ? { styles: { dateStyle: r.dateStyle, dateTime: r.dateTime } } : {}
724
- });
725
- } catch {
726
- c = void 0;
727
- }
728
- const l = (f) => {
729
- const d = yt(new Date(f), t.calendar.tz), b = `${String(d.year).padStart(4, "0")}-${String(d.month).padStart(2, "0")}-${String(d.day).padStart(2, "0")}`;
730
- try {
731
- return c ? Me({ value: b, metadata: s, format: c.format }) : b;
732
- } catch {
733
- return b;
734
- }
735
- };
736
- return { start: l(n), end: l(o - 1) };
737
- }
738
- function tr(e, t) {
739
- return e.dashboardId === t.dashboardId && e.cardId === t.cardId && e.attachmentIndex === void 0;
740
- }
741
- function Re(e) {
742
- return new Map(
743
- e.presentationExecutionSnapshot.resolvedFormats.flatMap(
744
- (t) => t.format.type === "raw_temporal" && t.target.kind === "column" && tr(t.scope, e.scope) ? [[t.target.columnKey, t.format]] : []
745
- )
746
- );
747
- }
748
- function Ue(e) {
749
- const t = e == null ? void 0 : e.sql, r = e == null ? void 0 : e.python;
750
- return (e == null ? void 0 : e.resultOwner) === "freeform" && typeof t == "string" && !!t.trim() && (typeof r != "string" || !r.trim());
751
- }
752
- function Vr(e) {
753
- return e.formatting.useFormattedValues !== !1 && Ue(e.queryPayload) && Re(e.formatting).size > 0;
754
- }
755
- function rr(e, t) {
756
- return e.map((r, n) => {
757
- if (!Object.prototype.hasOwnProperty.call(r, t) || r[t] === void 0)
758
- throw new Error(
759
- `missing_raw_temporal_result_contract: Row ${n} is missing declared temporal column "${t}".`
760
- );
761
- const o = r[t];
762
- return o === null || typeof o == "string" ? o : String(o);
763
- });
764
- }
765
- function nr(e) {
766
- if (e.formatting.useFormattedValues === !1)
767
- return {
768
- activatedColumnKeys: /* @__PURE__ */ new Set(),
769
- byColumnKey: /* @__PURE__ */ new Map()
770
- };
771
- const t = Re(e.formatting), r = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map();
772
- if (t.size === 0)
773
- return { activatedColumnKeys: r, byColumnKey: n };
774
- const o = new Map(
775
- e.columns.flatMap((l) => {
776
- const f = l.key || l.field;
777
- return f ? [[f, l]] : [];
778
- })
779
- ), s = Ue(e.queryPayload), c = /* @__PURE__ */ new Map();
780
- for (const [l, f] of t) {
781
- const d = o.get(l);
782
- let b;
783
- if (d != null && d.rawTemporal)
784
- b = gt(d, {
785
- metadataRequired: !0
786
- }), r.add(l);
787
- else if (s) {
788
- r.add(l);
789
- const w = We({
790
- columnKey: l,
791
- values: rr(e.records, l)
792
- });
793
- c.set(l, w), w.status === "classified" && (b = w.metadata);
794
- } else
795
- continue;
796
- b && n.set(l, {
797
- metadata: b,
798
- format: f,
799
- formatValue: Je({ metadata: b, format: f })
800
- });
801
- }
802
- return {
803
- activatedColumnKeys: r,
804
- byColumnKey: n,
805
- ...s ? {
806
- sqlChunkEvidence: Ze(c)
807
- } : {}
808
- };
809
- }
810
- function or(e) {
811
- if (!e.resolution.activatedColumnKeys.has(e.columnKey))
812
- return;
813
- if (e.value === void 0)
814
- throw new Error(
815
- `missing_raw_temporal_result_contract: Row ${e.rowIndex} is missing temporal column "${e.columnKey}".`
816
- );
817
- const t = e.resolution.byColumnKey.get(e.columnKey);
818
- if (!t)
819
- return { text: e.value === null ? "" : String(e.value) };
820
- if (e.value !== null && typeof e.value != "string")
821
- return { text: String(e.value) };
822
- const r = t.formatValue(e.value);
823
- return r.ok && r.wallClock ? { text: r.text, wallClock: r.wallClock } : { text: r.text };
824
- }
825
- function Ce(e, t) {
826
- const r = e.byColumnKey.get(t);
827
- return r ? r.metadata.valueKind === "date" : void 0;
828
- }
829
- const ar = /* @__PURE__ */ new Set(["string", "number", "boolean", "date", "datetime"]), sr = /^\d{4}-\d{2}-\d{2}|^\d{2}\/\d{2}\/\d{4}/, ir = /^\d{4}-\d{2}-\d{2}$/, Ke = "MM/dd/yyyy";
830
- function q(e) {
831
- return typeof e == "object" && e !== null && !Array.isArray(e);
832
- }
833
- function R(e) {
834
- return e.key || e.field || void 0;
835
- }
836
- function _e(e) {
837
- return e == null ? "" : typeof e == "string" ? e : j(e) ? e.value : e instanceof Date ? e.toISOString() : typeof e == "object" ? JSON.stringify(e) : String(e);
838
- }
839
- function Te(e, t) {
840
- var n;
841
- const r = (n = e.columnSettings) == null ? void 0 : n[t];
842
- if (!(!q(r) || r.type !== "date"))
843
- return q(r.dateFormat) ? r.dateFormat : {};
844
- }
845
- function Ee(e) {
846
- return e.useCustomFormat && e.customFormat ? e.customFormat : e.format || Ke;
847
- }
848
- function Se(e, t) {
849
- return e && e !== "auto" ? e : t;
850
- }
851
- function lr(e) {
852
- return !/[HhKkmsSa]/.test(e.replace(/'[^']*'/g, ""));
853
- }
854
- function cr(e) {
855
- if (typeof e == "number") return Number.isFinite(e) ? e : null;
856
- if (typeof e != "string" || !e.trim()) return null;
857
- const t = Number(e);
858
- return Number.isFinite(t) ? t : null;
859
- }
860
- function ur(e) {
861
- const t = Ae(e);
862
- if (t !== void 0)
863
- try {
864
- return mt(t, /[.eE]/.test(t) ? "decimal" : "integer");
865
- } catch {
866
- return;
867
- }
868
- }
869
- function mr(e) {
870
- return e.calendar.fiscalCalendar && (e.granularity === "quarter" || e.granularity === "year") ? "fiscal" : e.granularity;
871
- }
872
- function Br(e) {
873
- const { formatting: t, queryPayload: r } = e, n = t.useFormattedValues, o = t.scope, s = (a) => Qe({ snapshot: t.presentationExecutionSnapshot, scope: o, target: { kind: "column", columnKey: a } }), c = (a) => et({ snapshot: t.presentationExecutionSnapshot, scope: o, target: { kind: "column", columnKey: a } });
874
- function l(a) {
875
- var y;
876
- if ((y = t.visibleColumns) != null && y.length) return t.visibleColumns;
877
- const m = a.columns.map(R).filter((p) => !!p);
878
- return m.length > 0 ? m : a.records[0] ? Object.keys(a.records[0]) : [];
879
- }
880
- function f(a, m) {
881
- return t.columnLabels && Object.prototype.hasOwnProperty.call(t.columnLabels, a) && t.columnLabels[a] || void 0 || d(m) || (m == null ? void 0 : m.label) || (m == null ? void 0 : m.headerName) || a;
882
- }
883
- function d(a, m) {
884
- const y = a == null ? void 0 : a.pivotIdentity;
885
- if (!y || !y.members || y.members.length === 0) return;
886
- const p = he({ identity: y, columnKey: (a == null ? void 0 : a.key) || (a == null ? void 0 : a.field) || "" });
887
- return nt({
888
- members: p,
889
- metricLabel: (a == null ? void 0 : a.label) || (a == null ? void 0 : a.headerName),
890
- mode: n ? "formatted" : "canonical",
891
- resolveTemporalFormat: (C) => {
892
- const g = p.find((v) => v.fieldId === C);
893
- if (!(g != null && g.temporalBucket)) return;
894
- const x = de({
895
- snapshot: t.presentationExecutionSnapshot,
896
- scope: o,
897
- target: { kind: "field", fieldId: C, role: "pivotby" }
898
- });
899
- return x ? b(g.temporalBucket, x) : void 0;
900
- }
901
- }).flattenedLabel;
902
- }
903
- function b(a, m) {
904
- return Le({
905
- metadata: a,
906
- cardFormat: m,
907
- locale: m.locale,
908
- ...m.presentation.mode === "auto" ? { styles: m.presentation.styles } : {}
909
- }).format;
910
- }
911
- function w(a, m) {
912
- const { records: y, columns: p } = a, C = q(r.cardConfig) ? r.cardConfig : void 0, g = C == null ? void 0 : C.pivotByColumns, x = Array.isArray(g) ? g.flatMap(
913
- (i) => q(i) && typeof i.id == "string" && i.id ? [i.id] : []
914
- ) : [];
915
- wt(
916
- p.map((i) => ({ key: R(i) || "<unknown>", pivotIdentity: i.pivotIdentity })),
917
- { expectedPivotFieldIds: x }
918
- );
919
- const v = l(a), $ = new Map(
920
- p.flatMap((i) => {
921
- const h = R(i);
922
- return h ? [[h, i]] : [];
923
- })
924
- ), Be = new Map(a.resultColumns.map((i) => [i.key, i.dataType])), L = nr({
925
- records: y,
926
- columns: p,
927
- formatting: t,
928
- queryPayload: r
929
- }), W = new Map(
930
- p.flatMap((i) => {
931
- const h = R(i);
932
- return h && i.temporalBucket ? [[h, i.temporalBucket]] : [];
933
- })
934
- ), le = /* @__PURE__ */ new Map();
935
- for (const i of v) {
936
- const h = de({
937
- snapshot: t.presentationExecutionSnapshot,
938
- scope: o,
939
- target: { kind: "column", columnKey: i }
940
- }), _ = W.get(i);
941
- if (n) {
942
- if (h && !_) throw new Error(`Missing temporal bucket metadata for column "${i}"`);
943
- if (_ && !h) throw new Error(`Missing resolved temporal presentation for column "${i}"`);
944
- }
945
- h && _ && le.set(i, b(_, h));
946
- }
947
- const J = v.map((i) => {
948
- const h = Be.get(i), _ = h && ar.has(h) ? h : "unknown", E = n ? T(i, L, W) : void 0, D = f(i, $.get(i)), A = n && L.activatedColumnKeys.has(i) && Ce(L, i) === void 0;
949
- return {
950
- key: i,
951
- label: D,
952
- dataType: _,
953
- ...E ? { presentation: E } : {},
954
- xlsx: ge({ key: i, label: D, formattedValues: n, dataType: _, presentation: E }),
955
- ...A ? { xlsxPending: !0 } : {}
956
- };
957
- });
958
- function He(i, h, _, E) {
959
- if (!n) return { text: _e(i), value: i };
960
- const D = or({ value: i, columnKey: h, rowIndex: _, resolution: L });
961
- if (D !== void 0) return { text: D.text, value: i, ...D.wallClock ? { wallClock: D.wallClock } : {} };
962
- const A = W.get(h);
963
- if (A) {
964
- const P = le.get(h);
965
- if (!P) throw new Error(`Missing resolved temporal presentation for column "${h}"`);
966
- if (i != null && typeof i != "string")
967
- throw new Error(`Canonical temporal column "${h}" must contain a string or null`);
968
- const N = i ?? null, O = tt(N, A);
969
- return {
970
- text: Me({ value: N, metadata: A, format: P }),
971
- value: i,
972
- ...O ? { wallClock: O } : {}
973
- };
974
- }
975
- if (i == null) return { text: "", value: i };
976
- const Z = c(h);
977
- if (Z && typeof i == "number" && Number.isFinite(i))
978
- return {
979
- text: fe(
980
- new Date(i).toISOString(),
981
- Z.pattern || Ke,
982
- Se(Z.timezone, t.timezone),
983
- "UTC"
984
- ),
985
- value: i
986
- };
987
- const M = s(h);
988
- if (typeof i == "number")
989
- return { text: M ? B(i, M) : String(i), value: i };
990
- if (j(i))
991
- return { text: M ? B(i, M) : i.value, value: i };
992
- const V = Te(t, h);
993
- if (V && (i instanceof Date || typeof i == "string" && sr.test(i))) {
994
- const P = i instanceof Date ? i.toISOString() : i, N = typeof i == "string" && ir.test(i), O = N ? "UTC" : Se(V.timezone, t.timezone), ue = N ? "UTC" : V.sourceTimezone || "auto", me = rt(P, O, ue);
995
- return {
996
- text: fe(P, Ee(V), O, ue),
997
- value: i,
998
- ...me ? { wallClock: me } : {}
999
- };
1000
- }
1001
- if (typeof i == "string" && M && E.dataType === "number") {
1002
- const P = ur(i);
1003
- if (P) return { text: B(P, M), value: i };
1004
- }
1005
- return { text: _e(i), value: i };
1006
- }
1007
- const ze = y.map(
1008
- (i, h) => J.map((_) => {
1009
- const E = He(i[_.key], _.key, h, _);
1010
- return H({ value: E.value, text: E.text, column: _.xlsx, wallClock: E.wallClock });
1011
- })
1012
- ), ce = (m == null ? void 0 : m.withHeader) !== !1 && t.includeHeaders;
1013
- if (ce)
1014
- for (const i of v) {
1015
- const h = $.get(i);
1016
- h != null && h.pivotIdentity && he({ identity: h.pivotIdentity, columnKey: R(h) || i });
1017
- }
1018
- return {
1019
- ...ce ? { header: J.map((i) => i.label) } : {},
1020
- columns: J,
1021
- rows: ze,
1022
- ...L.sqlChunkEvidence ? { rawTemporalClassification: L.sqlChunkEvidence } : {}
1023
- };
1024
- }
1025
- function T(a, m, y) {
1026
- if (m.activatedColumnKeys.has(a)) {
1027
- const x = Ce(m, a);
1028
- return x === void 0 ? { kind: "text" } : { kind: "datetime", dateOnly: x };
1029
- }
1030
- const p = y.get(a);
1031
- if (p) return { kind: "temporal_bucket", grain: mr(p) };
1032
- if (c(a)) return { kind: "text" };
1033
- const C = Te(t, a);
1034
- if (C) return { kind: "datetime", dateOnly: lr(Ee(C)) };
1035
- const g = s(a);
1036
- return g ? { kind: "measure", format: g } : void 0;
1037
- }
1038
- function u(a, m) {
1039
- if (!Number.isInteger(m) || m < 0)
1040
- throw new Error("totalRows must be a non-negative integer");
1041
- return m === 0 ? void 0 : (t.visibleColumns ?? Object.keys(a)).map((p) => {
1042
- const g = Object.prototype.hasOwnProperty.call(a, p) ? a[p] : p === t.tableTotalsLabelColumnKey ? "Total" : null, x = n ? s(p) : void 0, v = ge({
1043
- key: p,
1044
- label: p,
1045
- formattedValues: n,
1046
- dataType: "unknown",
1047
- ...x ? { presentation: { kind: "measure", format: x } } : {}
1048
- });
1049
- if (g == null) return { kind: "empty" };
1050
- if (!n) return H({ value: g, text: String(g), column: v });
1051
- const $ = x ? cr(g) : null;
1052
- return H(x && $ !== null ? { value: $, text: B($, x), column: v } : { value: g, text: String(g), column: v });
1053
- });
1054
- }
1055
- return { format: w, totals: u };
1056
- }
1057
- const dr = /* @__PURE__ */ new Set([
1058
- "scope",
1059
- "useFormattedValues",
1060
- "timezone",
1061
- "presentationExecutionSnapshot",
1062
- "delimiter",
1063
- "csvEncoding",
1064
- "includeHeaders",
1065
- "columnSettings",
1066
- "visibleColumns",
1067
- "columnLabels",
1068
- "tableTotalsLabelColumnKey",
1069
- "fileFormat",
1070
- "title"
1071
- ]);
1072
- function ie(e) {
1073
- return e !== null && typeof e == "object" && !Array.isArray(e);
1074
- }
1075
- function Fe(e, t) {
1076
- if (e !== void 0) {
1077
- if (!ie(e))
1078
- throw new Error(`formatting.${t} must be an object`);
1079
- return e;
1080
- }
1081
- }
1082
- function Hr(e) {
1083
- if (!ie(e))
1084
- throw new Error("formatting must be an object");
1085
- const t = ["reportContext", "resolvedFormats"].find(
1086
- (a) => Object.prototype.hasOwnProperty.call(e, a)
1087
- );
1088
- if (t)
1089
- throw new pe(
1090
- `formatting.${t} is retired; formatting.presentationExecutionSnapshot is authoritative.`
1091
- );
1092
- const r = Object.keys(e).find((a) => !dr.has(a));
1093
- if (r)
1094
- throw new Error(`formatting contains unknown property "${r}"`);
1095
- const n = typeof e.timezone == "string" ? e.timezone.trim() : "";
1096
- if (!n)
1097
- throw new Error("formatting.timezone must be a non-empty string");
1098
- const o = it(e.delimiter);
1099
- if (!o)
1100
- throw new Error("formatting.delimiter must be a comma, semicolon or tab");
1101
- const s = lt(e.csvEncoding);
1102
- if (!s)
1103
- throw new Error("formatting.csvEncoding must be 'utf-8-bom' or 'utf-8'");
1104
- if (typeof e.includeHeaders != "boolean")
1105
- throw new Error("formatting.includeHeaders must be a boolean");
1106
- if (e.useFormattedValues !== void 0 && typeof e.useFormattedValues != "boolean")
1107
- throw new Error("formatting.useFormattedValues must be a boolean");
1108
- const c = e.fileFormat === void 0 ? void 0 : ct(e.fileFormat);
1109
- if (e.fileFormat !== void 0 && !c)
1110
- throw new Error("formatting.fileFormat must be 'csv' or 'xlsx'");
1111
- if (e.title !== void 0 && typeof e.title != "string")
1112
- throw new Error("formatting.title must be a string");
1113
- const l = e.visibleColumns === void 0 ? void 0 : Array.isArray(e.visibleColumns) && e.visibleColumns.every((a) => typeof a == "string") ? e.visibleColumns : void 0;
1114
- if (e.visibleColumns !== void 0 && !l)
1115
- throw new Error("formatting.visibleColumns must be an array of strings");
1116
- const f = Fe(e.columnLabels, "columnLabels");
1117
- if (f && Object.values(f).some((a) => typeof a != "string"))
1118
- throw new Error("formatting.columnLabels values must be strings");
1119
- const d = Fe(e.columnSettings, "columnSettings"), b = e.tableTotalsLabelColumnKey === void 0 ? void 0 : typeof e.tableTotalsLabelColumnKey == "string" && e.tableTotalsLabelColumnKey.trim() ? e.tableTotalsLabelColumnKey : null;
1120
- if (b === null)
1121
- throw new Error("formatting.tableTotalsLabelColumnKey must be a non-empty string");
1122
- if (b && !(l != null && l.includes(b)))
1123
- throw new Error("formatting.tableTotalsLabelColumnKey must identify a visible column");
1124
- const w = ot(e.scope, "formatting.scope");
1125
- if (!w.cardId || w.attachmentIndex !== void 0)
1126
- throw new Error("formatting.scope must identify exactly one dashboard card");
1127
- const T = e.useFormattedValues !== !1, u = at(e.presentationExecutionSnapshot);
1128
- if (n !== u.reportContext.calendar.tz)
1129
- throw new Error(
1130
- "formatting.timezone must equal presentationExecutionSnapshot.reportContext.calendar.tz"
1131
- );
1132
- try {
1133
- st({
1134
- snapshot: u,
1135
- expectedScope: { dashboardId: w.dashboardId, cardId: w.cardId },
1136
- visibleColumns: l,
1137
- useFormattedValues: T
1138
- });
1139
- } catch (a) {
1140
- throw new pe(
1141
- `formatting.presentationExecutionSnapshot.${a instanceof Error ? a.message : String(a)}`
1142
- );
1143
- }
1144
- return {
1145
- scope: { dashboardId: w.dashboardId, cardId: w.cardId },
1146
- useFormattedValues: T,
1147
- timezone: n,
1148
- presentationExecutionSnapshot: u,
1149
- delimiter: o,
1150
- csvEncoding: s,
1151
- includeHeaders: e.includeHeaders,
1152
- ...d ? { columnSettings: d } : {},
1153
- ...l ? { visibleColumns: l } : {},
1154
- ...f ? { columnLabels: f } : {},
1155
- ...b ? { tableTotalsLabelColumnKey: b } : {},
1156
- ...c ? { fileFormat: c } : {},
1157
- ...typeof e.title == "string" ? { title: e.title } : {}
1158
- };
1159
- }
1160
- function zr(e) {
1161
- const t = e.formatOptions, r = (n) => ie(n) ? n : void 0;
1162
- return {
1163
- scope: { dashboardId: e.dashboardId, cardId: e.cardId },
1164
- useFormattedValues: t.useFormattedValues !== !1,
1165
- timezone: t.presentationExecutionSnapshot.reportContext.calendar.tz,
1166
- presentationExecutionSnapshot: t.presentationExecutionSnapshot,
1167
- delimiter: typeof t.delimiter == "string" ? t.delimiter : ",",
1168
- csvEncoding: t.csvEncoding,
1169
- includeHeaders: t.includeHeaders !== !1,
1170
- columnSettings: r(t.columnSettings),
1171
- visibleColumns: Array.isArray(t.visibleColumns) ? t.visibleColumns : void 0,
1172
- columnLabels: r(t.columnLabels),
1173
- tableTotalsLabelColumnKey: typeof t.tableTotalsLabelColumnKey == "string" ? t.tableTotalsLabelColumnKey : void 0,
1174
- ...e.fileFormat ? { fileFormat: e.fileFormat } : {},
1175
- ...typeof e.title == "string" ? { title: e.title } : {}
1176
- };
1177
- }
1178
- function Gr(e) {
1179
- return ((e == null ? void 0 : e.filterValues) ?? []).filter(fr).map(pr);
1180
- }
1181
- function fr(e) {
1182
- return !!e && typeof e == "object" && typeof e.name == "string" && Array.isArray(e.values);
1183
- }
1184
- function pr(e) {
1185
- if (!("relativeMeta" in e) || e.relativeMeta === void 0) return e;
1186
- const { relativeMeta: t, ...r } = e, n = dt(t);
1187
- return n ? { ...r, relativeMeta: n } : r;
1188
- }
1189
- const hr = /* @__PURE__ */ new Set([
1190
- "day",
1191
- "week",
1192
- "month",
1193
- "quarter",
1194
- "year"
1195
- ]);
1196
- function br(e, t) {
1197
- try {
1198
- const r = K(e), n = I(r, t, "yyyy-MM-dd");
1199
- if (I(r, t, "HH:mm:ss.SSS") !== "00:00:00.000")
1200
- return {
1201
- date: n,
1202
- time: I(r, t, "h:mm a")
1203
- };
1204
- const [o, s, c] = n.split("-").map(Number), l = new Date(Date.UTC(o, s - 1, c));
1205
- return l.setUTCDate(l.getUTCDate() - 1), { date: I(l, "UTC", "yyyy-MM-dd") };
1206
- } catch {
1207
- return;
1208
- }
1209
- }
1210
- function je(e, t, r) {
1211
- const n = br(e.end, t);
1212
- if (n)
1213
- return {
1214
- start: I(
1215
- K(e.start),
1216
- t,
1217
- r ? "MMM d" : "MMM d, yyyy"
1218
- ),
1219
- endDate: I(
1220
- K(`${n.date}T00:00:00Z`),
1221
- "UTC",
1222
- "MMM d, yyyy"
1223
- ),
1224
- ...n.time ? { endTime: n.time } : {}
1225
- };
1226
- }
1227
- function Ve(e) {
1228
- return !!(e && hr.has(e));
1229
- }
1230
- function Xr(e, t, r, n = !1) {
1231
- if (Ve(r))
1232
- try {
1233
- const s = je(e, t, !1);
1234
- if (s && s.start === s.endDate)
1235
- return s.endTime ? `${s.endDate} until ${s.endTime}` : s.endDate;
1236
- } catch {
1237
- }
1238
- const o = yr(
1239
- e,
1240
- t,
1241
- r,
1242
- n
1243
- );
1244
- return `${o.start} – ${o.end}`;
1245
- }
1246
- function yr(e, t, r, n = !1) {
1247
- try {
1248
- if (Ve(r)) {
1249
- const o = je(e, t, n);
1250
- if (o)
1251
- return {
1252
- start: o.start,
1253
- end: o.endTime ? `${o.endDate}, ${o.endTime}` : o.endDate
1254
- };
1255
- }
1256
- if (r === "second" || r === "minute" || r === "hour") {
1257
- const o = n ? "MMM d, h:mm a" : "MMM d, yyyy, h:mm a";
1258
- return {
1259
- start: I(K(e.start), t, o),
1260
- end: `before ${I(
1261
- K(e.end),
1262
- t,
1263
- o
1264
- )}`
1265
- };
1266
- }
1267
- } catch {
1268
- }
1269
- return { start: e.start, end: `before ${e.end}` };
1270
- }
1271
- export {
1272
- Kr as A,
1273
- jr as B,
1274
- Br as C,
1275
- Ar as D,
1276
- Hr as E,
1277
- zr as F,
1278
- Vr as G,
1279
- Gr as H,
1280
- yr as I,
1281
- $r as M,
1282
- Ut as P,
1283
- Sr as a,
1284
- Ir as b,
1285
- Dr as c,
1286
- Vt as d,
1287
- Fr as e,
1288
- Xr as f,
1289
- Lr as g,
1290
- Pr as h,
1291
- kt as i,
1292
- Nt as j,
1293
- Rt as k,
1294
- Mr as l,
1295
- jt as m,
1296
- Ht as n,
1297
- zt as o,
1298
- Kt as p,
1299
- Gt as q,
1300
- ge as r,
1301
- kr as s,
1302
- H as t,
1303
- Xt as u,
1304
- Nr as v,
1305
- Qt as w,
1306
- Or as x,
1307
- Rr as y,
1308
- Ur as z
1309
- };