react-semaphor 0.1.563 → 0.1.565

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 (139) hide show
  1. package/DATA_APP_SDK.md +3 -3
  2. package/README.md +2 -2
  3. package/dist/analytics-protocol/index.js +8 -8
  4. package/dist/assistant-context/index.js +3 -2
  5. package/dist/brand-studio/index.js +28 -29
  6. package/dist/briefings/index.js +4 -4
  7. package/dist/chunks/{assistant-chat-iIp02_77.js → assistant-chat-DNfb5fbF.js} +294 -294
  8. package/dist/chunks/{bookmark-impact-D4Kl4amw.js → bookmark-impact-CHr7b1J2.js} +2 -2
  9. package/dist/chunks/bookmark-state-ByODVqee.js +1613 -0
  10. package/dist/chunks/card-filter-builder-CcEcfaYz.js +4100 -0
  11. package/dist/chunks/{switch-BW4yXSYs.js → code-editor-DJNOsgJH.js} +463 -442
  12. package/dist/chunks/{comparison-window-caption-D1EUXzaR.js → comparison-window-caption-CMLb3mut.js} +451 -419
  13. package/dist/chunks/{dashboard-CmqeP3QZ.js → dashboard-CtIfxycc.js} +1 -1
  14. package/dist/chunks/dashboard-briefing-launcher-D3mc6peE.js +4910 -0
  15. package/dist/chunks/{dashboard-controls-B253nJS-.js → dashboard-controls-BFv0zdws.js} +684 -674
  16. package/dist/chunks/{dashboard-json-osQuinUZ.js → dashboard-json-CXn_3OYb.js} +4 -4
  17. package/dist/chunks/{dates-DFY7Gfss.js → dates-DcRxw17S.js} +13 -13
  18. package/dist/chunks/{edit-dashboard-visual-CMar-NhA.js → edit-dashboard-visual-Y6HatqBd.js} +7704 -10337
  19. package/dist/chunks/filter-reach-copy-DbggA5B7.js +4673 -0
  20. package/dist/chunks/{filter-value-text-CPwFkrMz.js → filter-value-text-7zhmth1S.js} +2 -2
  21. package/dist/chunks/{index-CNGkfUp4.js → index-DDa_rklN.js} +69 -64
  22. package/dist/chunks/index-RNaTnE3m.js +585 -0
  23. package/dist/chunks/{layout-grid-BM65viQh.js → layout-grid-0hIlqEtk.js} +1 -1
  24. package/dist/chunks/{list-filter-BoeLBfL3.js → list-filter-DkgoCeBm.js} +1 -1
  25. package/dist/chunks/{matrix-analytical-definition-hEucouWM.js → matrix-analytical-definition-C9xB_T84.js} +18 -18
  26. package/dist/chunks/{matrix-card-CCh9JjP1.js → matrix-card-BSUeSXpD.js} +2 -2
  27. package/dist/chunks/{matrix-member-presentation-DsAUbuoL.js → matrix-member-presentation-DZNgQpUq.js} +1 -1
  28. package/dist/chunks/{matrix-operation-contract-DsLdFdSa.js → matrix-operation-contract-Eb6elidS.js} +1 -1
  29. package/dist/chunks/{metric-comparison-Bnso1cm1.js → metric-comparison-ChXUFaZu.js} +1 -1
  30. package/dist/chunks/{palette-p1XSJFgB.js → palette-4vf2BEEg.js} +1 -1
  31. package/dist/chunks/{pivot-result-contract-expectations-B53jqszr.js → pivot-result-contract-expectations-Ddh1rNz5.js} +4 -4
  32. package/dist/chunks/{pivot-result-identity-Dq5jm-EC.js → pivot-result-identity-BlbLrqaC.js} +1 -1
  33. package/dist/chunks/{report-preferences-dialog-l54wJyYE.js → report-preferences-dialog-Db-b04B4.js} +122 -131
  34. package/dist/chunks/{report-runtime-context-BITkNSDa.js → report-runtime-context-DnA_PiKo.js} +1 -1
  35. package/dist/chunks/resolve-dashboard-input-context-C18J-YZC.js +21394 -0
  36. package/dist/chunks/{save-CHV1B1fL.js → save-D6pHmSSP.js} +1 -1
  37. package/dist/chunks/saved-dashboard-context-DhC_EVus.js +629 -0
  38. package/dist/chunks/{selection-reducer-Bz5aywT4.js → selection-reducer-OaJ-N5uN.js} +1 -1
  39. package/dist/chunks/{semaphor-ready-indicator-C3EQEiD9.js → semaphor-ready-indicator-T6TsiBMT.js} +80879 -80744
  40. package/dist/chunks/{shelf-drop-preview-context-BODiBlqT.js → shelf-drop-preview-context-CNWL_b0S.js} +407 -407
  41. package/dist/chunks/{source-entity-resolution-DdDVXFB8.js → source-entity-resolution-DF6GulDn.js} +1 -1
  42. package/dist/chunks/stored-dashboard-IdmtrNkA.js +5026 -0
  43. package/dist/chunks/{table-export-sheet-bSXxGn-v.js → table-export-sheet--DUKWk6o.js} +1 -1
  44. package/dist/chunks/{temporal-input-presentation-sk9gqLi6.js → temporal-input-presentation--2r9BLr0.js} +392 -377
  45. package/dist/chunks/{token-types-BUK06hU2.js → token-types-C8JymO8s.js} +1 -1
  46. package/dist/chunks/{upload-BnmuyPqW.js → upload-Cf3wXZT8.js} +1 -1
  47. package/dist/chunks/{validators-BIM0FE31.js → validators-wtjw0aw6.js} +7 -7
  48. package/dist/chunks/variable-draft-3xseULxR.js +241 -0
  49. package/dist/dashboard/index.js +2 -2
  50. package/dist/dashboard-authoring/index.js +2226 -1704
  51. package/dist/data-app-sdk/index.js +4 -4
  52. package/dist/data-app-sdk-adapters/index.js +2 -2
  53. package/dist/data-app-sdk-validation/index.js +5 -5
  54. package/dist/format-utils/index.js +174 -167
  55. package/dist/index.js +190 -188
  56. package/dist/layouts/index.js +1 -1
  57. package/dist/pdf-export-policy/index.js +80 -28
  58. package/dist/pdf-table-layout/index.js +65 -65
  59. package/dist/report-runtime-context/index.js +1 -1
  60. package/dist/style.css +1 -1
  61. package/dist/surfboard/index.js +2 -2
  62. package/dist/types/briefings/attachment-outcomes.d.ts +1 -1
  63. package/dist/types/components/activity/activity-bell.d.ts +5 -1
  64. package/dist/types/components/activity/activity-types.d.ts +12 -4
  65. package/dist/types/components/dashboard-variables/data-variables-menu.d.ts +8 -0
  66. package/dist/types/components/dashboard-variables/variable-editor-host.d.ts +1 -0
  67. package/dist/types/components/index.d.ts +2 -0
  68. package/dist/types/index.js +5 -5
  69. package/dist/types/lib/dashboard-inputs/build-normalized-dashboard-inputs.d.ts +62 -0
  70. package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-authoring.d.ts +33 -2
  71. package/dist/types/lib/dashboard-inputs/filter-settings.d.ts +7 -2
  72. package/dist/types/lib/dashboard-inputs/prepare-loaded-dashboard.d.ts +4 -2
  73. package/dist/types/lib/dashboard-variables/data-text.d.ts +33 -0
  74. package/dist/types/lib/dashboard-variables/types.d.ts +207 -0
  75. package/dist/types/lib/document/document-edits.d.ts +16 -1
  76. package/dist/types/lib/document/document-panel-target.d.ts +1 -1
  77. package/dist/types/lib/document/document-section-query-options.d.ts +29 -0
  78. package/dist/types/lib/document/document-table-data-policy.d.ts +0 -1
  79. package/dist/types/lib/hooks/use-dashboard-frame-query.d.ts +92 -0
  80. package/dist/types/lib/query-context/build-card-query-context.d.ts +6 -0
  81. package/dist/types/lib/query-context/describe-card-execution-snapshot.d.ts +1 -0
  82. package/dist/types/lib/query-context/use-semantic-execution-payload-for-cards.d.ts +24 -0
  83. package/dist/types/lib/stores/dashboard-store.d.ts +36 -0
  84. package/dist/types/lib/text-variables/temporal-input-text.d.ts +28 -0
  85. package/dist/types/lib/text-variables/text-variable-types.d.ts +72 -0
  86. package/dist/types/lib/types/common-types.d.ts +155 -51
  87. package/dist/types/lib/utils/card-definition.d.ts +2 -2
  88. package/dist/types/shared/assistant-context/index.d.ts +1 -1
  89. package/dist/types/shared/assistant-context/saved-dashboard-context.d.ts +51 -1
  90. package/dist/types/shared/dashboard-authoring/card-query-request.d.ts +7 -1
  91. package/dist/types/shared/dashboard-authoring/card-settings/resolve-card-highlights.d.ts +10 -0
  92. package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +7 -1
  93. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +1088 -431
  94. package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +18 -1
  95. package/dist/types/shared/dashboard-authoring/changes/read-card-query.d.ts +8 -1
  96. package/dist/types/shared/dashboard-authoring/changes/resolve-dashboard-changes.d.ts +1 -1
  97. package/dist/types/shared/dashboard-authoring/conditional-formatting/kpi.d.ts +10 -0
  98. package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +40 -40
  99. package/dist/types/shared/dashboard-authoring/control-execution-contract.d.ts +16 -16
  100. package/dist/types/shared/dashboard-authoring/dashboard-card-source-index.d.ts +1 -0
  101. package/dist/types/shared/dashboard-authoring/dashboard-filter-targets.d.ts +29 -0
  102. package/dist/types/shared/dashboard-authoring/dashboard-input-scope.d.ts +7 -4
  103. package/dist/types/shared/dashboard-authoring/dashboard-variable-card.d.ts +159 -0
  104. package/dist/types/shared/dashboard-authoring/dashboard-variable-changes.d.ts +61 -0
  105. package/dist/types/shared/dashboard-authoring/document-section-cards.d.ts +7 -0
  106. package/dist/types/shared/dashboard-authoring/filter-model/index.d.ts +2 -0
  107. package/dist/types/shared/dashboard-authoring/filter-model/read-dashboard-filter-model.d.ts +10 -0
  108. package/dist/types/shared/dashboard-authoring/index.d.ts +6 -0
  109. package/dist/types/shared/dashboard-authoring/measure-calculations/comparison.d.ts +2 -0
  110. package/dist/types/shared/dashboard-authoring/measure-calculations/schemas.d.ts +1 -1
  111. package/dist/types/shared/dashboard-authoring/operations/operation-sentences.d.ts +1 -1
  112. package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +50 -3
  113. package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +48 -1
  114. package/dist/types/shared/dashboard-authoring/outline/outline-filters.d.ts +2 -2
  115. package/dist/types/shared/dashboard-authoring/text-card-words/blocks.d.ts +87 -13
  116. package/dist/types/shared/dashboard-authoring/text-card-words/chip-colors.d.ts +23 -0
  117. package/dist/types/shared/dashboard-authoring/text-card-words/index.d.ts +90 -8
  118. package/dist/types/shared/dashboard-authoring/text-card-words/rich-content.d.ts +31 -3
  119. package/dist/types/shared/dashboard-authoring/text-card-words/variable-words.d.ts +8 -0
  120. package/dist/types/shared/dashboard-authoring/variable-draft.d.ts +125 -0
  121. package/dist/types/shared/dashboard-authoring/variable-editability.d.ts +24 -0
  122. package/dist/types/shared/dashboard-authoring/variable-references.d.ts +39 -0
  123. package/dist/types/shared/format-utils/document-print.d.ts +4 -2
  124. package/dist/types/shared/format-utils/index.d.ts +1 -0
  125. package/dist/types/shared/format-utils/pdf-capacity-lines.d.ts +17 -0
  126. package/dist/types/shared/format-utils/pdf-delivery.d.ts +8 -1
  127. package/dist/types/shared/format-utils/pdf-export-policy.d.ts +74 -6
  128. package/dist/types/shared/format-utils/presentation-execution.d.ts +9 -0
  129. package/package.json +2 -2
  130. package/src/data-app-sdk/README.md +3 -3
  131. package/dist/chunks/bookmark-state-CWeoGbrx.js +0 -743
  132. package/dist/chunks/braces-DzgoQC64.js +0 -23
  133. package/dist/chunks/dashboard-briefing-launcher-TYlSW77S.js +0 -3828
  134. package/dist/chunks/filter-reach-copy-CvV7W5dd.js +0 -3965
  135. package/dist/chunks/global-date-filter-utils-N1kcsOFE.js +0 -16722
  136. package/dist/chunks/index-CJW5BdWT.js +0 -583
  137. package/dist/chunks/resolve-dashboard-input-context-DaDrZGuA.js +0 -8214
  138. package/dist/chunks/saved-dashboard-context-DFYBrE6O.js +0 -564
  139. package/dist/chunks/use-create-flow-overlay-state-BXY8-Cyz.js +0 -1436
@@ -0,0 +1,1613 @@
1
+ import { H as G, k as Ve, u as Pe } from "./validators-wtjw0aw6.js";
2
+ import { z as l } from "zod";
3
+ import { Q as q, G as Le, v as $e } from "./matrix-operation-contract-Eb6elidS.js";
4
+ import { D as qe, C as Be, r as B, d as je } from "./metric-comparison-ChXUFaZu.js";
5
+ import "./analytics-base-schemas-BaIQrEzX.js";
6
+ import { a as D } from "./applied-constraints-DU-wndZ7.js";
7
+ import { r as Ue } from "./pivot-result-identity-BlbLrqaC.js";
8
+ const te = 8, ne = 6, F = Object.freeze([]);
9
+ function ze(e) {
10
+ switch (e.type) {
11
+ case "table":
12
+ case "chart":
13
+ return e.card ? [e.card] : F;
14
+ case "kpi":
15
+ return Array.isArray(e.cards) ? e.cards : F;
16
+ default:
17
+ return F;
18
+ }
19
+ }
20
+ function We(e, t) {
21
+ switch (e.type) {
22
+ case "table":
23
+ case "chart": {
24
+ if (!e.card) return e;
25
+ const n = t(e.card);
26
+ return n === e.card ? e : { ...e, card: n };
27
+ }
28
+ case "kpi": {
29
+ if (!Array.isArray(e.cards)) return e;
30
+ const n = e.cards.map(t);
31
+ return n.every((r, a) => r === e.cards[a]) ? e : { ...e, cards: n };
32
+ }
33
+ default:
34
+ return e;
35
+ }
36
+ }
37
+ function x(e) {
38
+ var n;
39
+ const t = [];
40
+ for (const r of e.sheets || []) {
41
+ const a = r.id;
42
+ for (const s of r.cards || [])
43
+ t.push({ kind: "sheetCard", sheetId: a, cardId: s.id, card: s });
44
+ for (const s of r.frames || [])
45
+ for (const i of s.cards || [])
46
+ t.push({
47
+ kind: "frameCard",
48
+ sheetId: a,
49
+ frameId: s.id,
50
+ cardId: i.id,
51
+ card: i
52
+ });
53
+ for (const s of ((n = r.document) == null ? void 0 : n.sections) || [])
54
+ for (const i of ze(s))
55
+ t.push({
56
+ kind: "documentSectionCard",
57
+ sheetId: a,
58
+ sectionId: s.id,
59
+ cardId: i.id,
60
+ card: i
61
+ });
62
+ }
63
+ return t;
64
+ }
65
+ function Xt(e, t, n) {
66
+ let r = !1;
67
+ const a = Ge(e, (i) => i.id !== n.id ? i : (r = !0, i === n ? i : n));
68
+ if (r || !t) return a;
69
+ const s = (a.sheets || []).map(
70
+ (i) => i.id === t && i.kind !== "document" ? { ...i, cards: [...i.cards ?? [], n] } : i
71
+ );
72
+ return { ...a, sheets: s };
73
+ }
74
+ function Ge(e, t) {
75
+ const n = (a, s) => {
76
+ const i = a.map((o) => t(o, s(o)));
77
+ return i.every((o, c) => o === a[c]) ? a : i;
78
+ }, r = (e.sheets || []).map((a) => {
79
+ var f, y, h;
80
+ const s = a.id, i = a.cards && n(a.cards, (p) => ({ kind: "sheetCard", sheetId: s, cardId: p.id, card: p })), o = (f = a.frames) == null ? void 0 : f.map((p) => {
81
+ if (!p.cards) return p;
82
+ const I = n(p.cards, (C) => ({ kind: "frameCard", sheetId: s, frameId: p.id, cardId: C.id, card: C }));
83
+ return I === p.cards ? p : { ...p, cards: I };
84
+ }), c = (h = (y = a.document) == null ? void 0 : y.sections) == null ? void 0 : h.map(
85
+ (p) => We(p, (I) => t(I, { kind: "documentSectionCard", sheetId: s, sectionId: p.id, cardId: I.id, card: I }))
86
+ ), u = !!o && o.some((p, I) => p !== a.frames[I]), d = !!c && c.some((p, I) => p !== a.document.sections[I]);
87
+ return i === a.cards && !u && !d ? a : {
88
+ ...a,
89
+ ...i === a.cards ? {} : { cards: i },
90
+ ...u ? { frames: o } : {},
91
+ ...d ? { document: { ...a.document, sections: c } } : {}
92
+ };
93
+ });
94
+ return r.every((a, s) => a === e.sheets[s]) ? e : { ...e, sheets: r };
95
+ }
96
+ function V(e) {
97
+ return !!e && typeof e == "object" && !Array.isArray(e);
98
+ }
99
+ function Zt(e) {
100
+ if (!V(e))
101
+ return [{ path: "", message: "must be an object." }];
102
+ const t = [];
103
+ e.title !== void 0 && typeof e.title != "string" && t.push({ path: "title", message: "must be a string." });
104
+ const n = e.cards;
105
+ if (!Array.isArray(n))
106
+ t.push({ path: "cards", message: "must be an array of KPI cards." });
107
+ else {
108
+ (n.length < 1 || n.length > te) && t.push({
109
+ path: "cards",
110
+ message: `must hold 1 to ${te} KPI cards.`
111
+ });
112
+ const a = /* @__PURE__ */ new Set();
113
+ n.forEach((s, i) => {
114
+ if (!V(s)) {
115
+ t.push({ path: `cards[${i}]`, message: "must be a card." });
116
+ return;
117
+ }
118
+ typeof s.id != "string" || !s.id ? t.push({
119
+ path: `cards[${i}].id`,
120
+ message: "must be a non-empty string."
121
+ }) : a.has(s.id) ? t.push({
122
+ path: `cards[${i}].id`,
123
+ message: `duplicates card id '${s.id}'.`
124
+ }) : a.add(s.id), s.type !== "kpi" && t.push({ path: `cards[${i}].type`, message: "must be 'kpi'." });
125
+ });
126
+ }
127
+ const r = e.kpi;
128
+ return V(r) ? (r.layout !== "tiles" && r.layout !== "lines" ? t.push({
129
+ path: "kpi.layout",
130
+ message: "must be 'tiles' or 'lines'."
131
+ }) : r.layout === "tiles" && Array.isArray(n) && n.length > ne && t.push({
132
+ path: "kpi.layout",
133
+ message: `must be 'lines' for more than ${ne} KPI cards.`
134
+ }), r.columns !== void 0 && r.columns !== 1 && r.columns !== 2 && t.push({ path: "kpi.columns", message: "must be 1 or 2." })) : t.push({ path: "kpi", message: "must be an object." }), t;
135
+ }
136
+ const ye = "dashboardInput";
137
+ function re(e) {
138
+ return e === "label" || e === "value" || e === "start" || e === "end" || e === "range";
139
+ }
140
+ function Qe(e) {
141
+ return e === "generatedAt" || e === "pageNumber" || e === "pageCount";
142
+ }
143
+ function v(e) {
144
+ if (!e || typeof e != "object" || Array.isArray(e)) return;
145
+ const t = e;
146
+ if (t.source === "input" || t.source === ye)
147
+ return typeof t.inputId == "string" && re(t.export) ? { source: "input", inputId: t.inputId, export: t.export } : void 0;
148
+ if (t.source === "dashboardInputAlias")
149
+ return typeof t.variableName != "string" || t.export !== void 0 && !re(t.export) ? void 0 : {
150
+ source: "dashboardInputAlias",
151
+ variableName: t.variableName,
152
+ ...t.export ? { export: t.export } : {}
153
+ };
154
+ if (t.source === "documentMeta")
155
+ return Qe(t.key) ? { source: "documentMeta", key: t.key } : void 0;
156
+ if (t.source === "data")
157
+ return typeof t.variableId == "string" && typeof t.export == "string" ? { source: "data", variableId: t.variableId, export: t.export } : void 0;
158
+ }
159
+ function en(e, t) {
160
+ const n = v(e), r = v(t);
161
+ return !n || !r ? JSON.stringify(e) === JSON.stringify(t) : [.../* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(r)])].every((s) => n[s] === r[s]);
162
+ }
163
+ function Ye(e) {
164
+ return O(e) ? e.type === "variable" ? e.ref === void 0 ? [] : [e.ref] : e.type === "when" && O(e.test) && e.test.ref !== void 0 ? [e.test.ref] : [] : [];
165
+ }
166
+ function Je(e, t) {
167
+ if (!O(e)) return e;
168
+ if (e.type === "variable" && e.ref !== void 0) {
169
+ const n = t(e.ref);
170
+ return n === e.ref ? e : { ...e, ref: n };
171
+ }
172
+ if (e.type === "when" && O(e.test) && e.test.ref !== void 0) {
173
+ const n = t(e.test.ref);
174
+ return n === e.test.ref ? e : { ...e, test: { ...e.test, ref: n } };
175
+ }
176
+ return e;
177
+ }
178
+ function O(e) {
179
+ return !!e && typeof e == "object" && !Array.isArray(e);
180
+ }
181
+ function se(e) {
182
+ return !!e && typeof e == "object" && e.source === ye;
183
+ }
184
+ function tn(e) {
185
+ return j(e);
186
+ }
187
+ function j(e) {
188
+ if (!e || typeof e != "object") return e;
189
+ if (Array.isArray(e)) {
190
+ let s = !1;
191
+ const i = e.map((o) => {
192
+ const c = j(o);
193
+ return c !== o && (s = !0), c;
194
+ });
195
+ return s ? i : e;
196
+ }
197
+ const t = e;
198
+ let n;
199
+ const r = (s, i) => {
200
+ i !== t[s] && (n ?? (n = { ...t }), n[s] = i);
201
+ }, a = Je(
202
+ t,
203
+ (s) => se(s) ? v(s) ?? s : s
204
+ );
205
+ if (a !== t && (a.ref !== t.ref && r("ref", a.ref), a.test !== t.test && r("test", a.test)), t.inputAliases && typeof t.inputAliases == "object") {
206
+ const s = t.inputAliases;
207
+ let i = !1;
208
+ const o = Object.fromEntries(
209
+ Object.entries(s).map(([c, u]) => se(u) ? (i = !0, [c, v(u) ?? u]) : [c, u])
210
+ );
211
+ i && r("inputAliases", o);
212
+ }
213
+ for (const [s, i] of Object.entries(t))
214
+ s === "ref" && t.type === "variable" || s === "test" && t.type === "when" || s === "inputAliases" || r(s, j(i));
215
+ return n ?? e;
216
+ }
217
+ function nn(e) {
218
+ return b(e);
219
+ }
220
+ function b(e) {
221
+ const t = [];
222
+ for (const n of Array.isArray(e) ? e : [])
223
+ if (!(!n || typeof n != "object")) {
224
+ for (const r of Ye(n)) {
225
+ const a = v(r);
226
+ a && t.push(a);
227
+ }
228
+ n.type === "link" && t.push(...b(n.children), ...b(Array.isArray(n.url) ? n.url : [])), n.type === "when" && t.push(...b(n.then), ...b(n.else));
229
+ }
230
+ return t;
231
+ }
232
+ function He(e) {
233
+ var r;
234
+ const t = (r = e.preferences) == null ? void 0 : r.textVisualOptions, n = t == null ? void 0 : t.richContent;
235
+ return n && Array.isArray(n.blocks) ? n.blocks.flatMap(
236
+ (a) => (a == null ? void 0 : a.type) === "list" ? (Array.isArray(a.items) ? a.items : []).flatMap((s) => b(s)) : b(a == null ? void 0 : a.children)
237
+ ) : b(t == null ? void 0 : t.content);
238
+ }
239
+ function Ie(e, t) {
240
+ var a;
241
+ const n = [], r = { kind: "document", sheetId: e };
242
+ for (const s of ["header", "footer"])
243
+ for (const i of ((a = t[s]) == null ? void 0 : a.blocks) ?? [])
244
+ if (i.type === "text")
245
+ for (const o of b(i.content))
246
+ n.push({ ref: o, place: r, where: { kind: s, blockId: i.id } });
247
+ for (const s of t.sections ?? [])
248
+ if (s.type === "text")
249
+ for (const i of b(s.content))
250
+ n.push({ ref: i, place: r, where: { kind: "section", sectionId: s.id } });
251
+ return n;
252
+ }
253
+ const ae = /* @__PURE__ */ new WeakMap();
254
+ function be(e) {
255
+ const t = ae.get(e);
256
+ if (t) return t;
257
+ const n = [];
258
+ for (const r of e.sheets ?? []) {
259
+ if (r.kind === "document") {
260
+ r.document && n.push(...Ie(r.id, r.document));
261
+ continue;
262
+ }
263
+ const a = { kind: "sheet", sheetId: r.id }, s = [...r.cards ?? [], ...(r.frames ?? []).flatMap((i) => i.cards ?? [])];
264
+ for (const i of s)
265
+ if (i.type === "text")
266
+ for (const o of He(i))
267
+ n.push({ ref: o, place: a, where: { kind: "card", cardId: i.id } });
268
+ }
269
+ return ae.set(e, n), n;
270
+ }
271
+ function ge(e, t) {
272
+ return e.kind === t.kind && e.sheetId === t.sheetId;
273
+ }
274
+ function Se(e, t) {
275
+ const n = be(e);
276
+ return t ? n.filter((r) => ge(r.place, t)) : [...n];
277
+ }
278
+ function Xe(e, t) {
279
+ const n = [];
280
+ for (const { ref: r, place: a } of be(e))
281
+ r.source !== "data" || r.variableId !== t || n.some((s) => ge(s, a)) || n.push(a);
282
+ return n;
283
+ }
284
+ function rn(e, t) {
285
+ const n = /* @__PURE__ */ new Set();
286
+ for (const { ref: r } of Se(e, t))
287
+ r.source === "data" && n.add(r.variableId);
288
+ return [...n];
289
+ }
290
+ function sn(e, t) {
291
+ const n = Ie("", e).filter(
292
+ ({ ref: r }) => r.source === "input" && r.inputId === t
293
+ );
294
+ return {
295
+ header: n.some(({ where: r }) => r.kind === "header"),
296
+ footer: n.some(({ where: r }) => r.kind === "footer"),
297
+ textSections: new Set(
298
+ n.flatMap(({ where: r }) => r.kind === "section" ? [r.sectionId] : [])
299
+ ).size
300
+ };
301
+ }
302
+ function Ce(e, t) {
303
+ const n = Xe(e, t);
304
+ return n.length ? n.map((r) => ({
305
+ sheetId: r.sheetId,
306
+ cardId: t,
307
+ sheetKind: r.kind === "document" ? "document" : "dashboard"
308
+ })) : (e.sheets ?? []).filter((r) => r.kind !== "document").map((r) => ({ sheetId: r.id, cardId: t, sheetKind: "dashboard" }));
309
+ }
310
+ function S(e, t) {
311
+ var r;
312
+ if (!nt(e, t))
313
+ return !1;
314
+ const n = e.scope;
315
+ switch (n.kind) {
316
+ case "allSheets":
317
+ return ((r = n.sheetKinds) != null && r.length ? t.sheetKind ? n.sheetKinds.includes(t.sheetKind) : !1 : !!t.sheetId || !!t.cardId) && !tt(n.exceptSheetIds, t) && !ce(n.exceptCardIds, t);
318
+ case "sheets":
319
+ return !!t.sheetId && n.sheetIds.includes(t.sheetId) && !ce(n.exceptCardIds, t);
320
+ case "cards":
321
+ return !!t.cardId && n.cardIds.includes(t.cardId);
322
+ case "documentSections":
323
+ return !!t.sheetId && !!t.sectionId && n.sheetId === t.sheetId && n.sectionIds.includes(t.sectionId);
324
+ default:
325
+ return !1;
326
+ }
327
+ }
328
+ function an(e, t) {
329
+ if (S(e, {
330
+ sheetId: t.sheetId,
331
+ sheetKind: t.sheetKind
332
+ }))
333
+ return !0;
334
+ switch (e.scope.kind) {
335
+ case "cards":
336
+ for (const n of [...t.cardIds, ...t.variableIds ?? []])
337
+ if (S(e, {
338
+ sheetId: t.sheetId,
339
+ cardId: n,
340
+ sheetKind: t.sheetKind
341
+ }))
342
+ return !0;
343
+ return !1;
344
+ case "documentSections":
345
+ return t.sheetKind === "document" && e.scope.sheetId === t.sheetId;
346
+ default:
347
+ return !1;
348
+ }
349
+ }
350
+ const ie = /* @__PURE__ */ new WeakMap();
351
+ function Ze(e) {
352
+ const t = ie.get(e);
353
+ if (t) return t;
354
+ const n = /* @__PURE__ */ new Map();
355
+ for (const s of x(e)) {
356
+ const i = n.get(s.sheetId) ?? /* @__PURE__ */ new Set();
357
+ i.add(s.cardId), n.set(s.sheetId, i);
358
+ }
359
+ const r = /* @__PURE__ */ new Map();
360
+ for (const { ref: s, place: i } of Se(e)) {
361
+ if (s.source !== "data") continue;
362
+ const o = r.get(i.sheetId) ?? /* @__PURE__ */ new Set();
363
+ o.add(s.variableId), r.set(i.sheetId, o);
364
+ }
365
+ const a = /* @__PURE__ */ new Map();
366
+ for (const s of e.sheets ?? [])
367
+ a.set(s.id, {
368
+ sheetId: s.id,
369
+ sheetKind: s.kind === "document" ? "document" : "dashboard",
370
+ cardIds: n.get(s.id) ?? /* @__PURE__ */ new Set(),
371
+ variableIds: r.get(s.id) ?? /* @__PURE__ */ new Set()
372
+ });
373
+ return ie.set(e, a), a;
374
+ }
375
+ function on(e, t) {
376
+ var a, s;
377
+ const n = /* @__PURE__ */ new Set(), r = Ze(e);
378
+ for (const i of r.values())
379
+ S(t, {
380
+ sheetId: i.sheetId,
381
+ sheetKind: i.sheetKind
382
+ }) && n.add(`sheet:${i.sheetId}`);
383
+ for (const i of x(e))
384
+ S(t, {
385
+ sheetId: i.sheetId,
386
+ cardId: i.cardId,
387
+ ...i.kind === "documentSectionCard" ? { sectionId: i.sectionId } : {},
388
+ sheetKind: ((a = r.get(i.sheetId)) == null ? void 0 : a.sheetKind) ?? "dashboard"
389
+ }) && n.add(`card:${i.cardId}`);
390
+ for (const i of e.variables ?? [])
391
+ Ce(e, i.id).some(
392
+ (o) => S(t, o)
393
+ ) && n.add(`card:${i.id}`);
394
+ for (const i of e.sheets ?? [])
395
+ if (i.kind === "document")
396
+ for (const o of ((s = i.document) == null ? void 0 : s.sections) ?? [])
397
+ S(t, {
398
+ sheetId: i.id,
399
+ sectionId: o.id,
400
+ sheetKind: "document"
401
+ }) && n.add(`section:${o.id}`);
402
+ return n;
403
+ }
404
+ function cn(e) {
405
+ return e.kind === "filter" && e.scope.kind === "cards";
406
+ }
407
+ function un(e, t) {
408
+ var s, i, o;
409
+ const n = (c) => {
410
+ var u, d;
411
+ return oe(c, t.removedSheetIds, t.renamedSheetIds, !1, (u = t.copiedTab) == null ? void 0 : u.sheetIds, (d = t.copiedTab) == null ? void 0 : d.mode);
412
+ }, r = (c) => {
413
+ var u, d;
414
+ return oe(
415
+ c,
416
+ t.removedCardIds,
417
+ t.renamedCardIds,
418
+ t.keepOnlyRenamedCardIds === !0,
419
+ (u = t.copiedTab) == null ? void 0 : u.cardIds,
420
+ (d = t.copiedTab) == null ? void 0 : d.mode
421
+ );
422
+ };
423
+ let a;
424
+ switch (e.kind) {
425
+ case "allSheets":
426
+ a = {
427
+ ...e,
428
+ ...e.exceptSheetIds ? { exceptSheetIds: n(e.exceptSheetIds) } : {},
429
+ ...e.exceptCardIds ? { exceptCardIds: r(e.exceptCardIds) } : {}
430
+ };
431
+ break;
432
+ case "sheets":
433
+ a = {
434
+ ...e,
435
+ sheetIds: n(e.sheetIds),
436
+ ...e.exceptCardIds ? { exceptCardIds: r(e.exceptCardIds) } : {}
437
+ };
438
+ break;
439
+ case "cards":
440
+ a = { ...e, cardIds: r(e.cardIds) };
441
+ break;
442
+ case "documentSections": {
443
+ if ((s = t.removedSheetIds) != null && s.has(e.sheetId)) {
444
+ a = { ...e, sectionIds: [] };
445
+ break;
446
+ }
447
+ const c = {
448
+ ...e,
449
+ sheetId: ((i = t.renamedSheetIds) == null ? void 0 : i.get(e.sheetId)) ?? e.sheetId,
450
+ sectionIds: (o = t.renamedSectionIds) != null && o.size ? e.sectionIds.map((d) => t.renamedSectionIds.get(d) ?? d) : e.sectionIds
451
+ }, u = t.copiedTab;
452
+ a = (u == null ? void 0 : u.mode) === "replace" && u.sheetIds.has(c.sheetId) ? {
453
+ ...c,
454
+ sheetId: u.sheetIds.get(c.sheetId),
455
+ sectionIds: c.sectionIds.map((d) => u.sectionIds.get(d) ?? d)
456
+ } : c;
457
+ break;
458
+ }
459
+ default:
460
+ return e;
461
+ }
462
+ return et(e, a) ? e : a;
463
+ }
464
+ function oe(e, t, n, r, a, s) {
465
+ let i = e;
466
+ return t != null && t.size && (i = i.filter((o) => !t.has(o))), r && (i = i.filter((o) => n == null ? void 0 : n.has(o))), n != null && n.size && (i = i.map((o) => n.get(o) ?? o)), a != null && a.size && (i = s === "extend" ? [.../* @__PURE__ */ new Set([...i, ...i.flatMap((o) => a.has(o) ? [a.get(o)] : [])])] : i.map((o) => a.get(o) ?? o)), i;
467
+ }
468
+ function et(e, t) {
469
+ return JSON.stringify(e) === JSON.stringify(t);
470
+ }
471
+ function tt(e, t) {
472
+ return !!t.sheetId && !!(e != null && e.includes(t.sheetId));
473
+ }
474
+ function ce(e, t) {
475
+ return !!t.cardId && !!(e != null && e.includes(t.cardId));
476
+ }
477
+ function nt(e, t) {
478
+ return t.sheetKind !== "document" || !e.compatibility || e.compatibility.source === "documentInput" ? !0 : e.compatibility.source === "cardInlineFilter" || e.compatibility.source === "cardControl" ? !!t.cardId && e.compatibility.cardId === t.cardId : !1;
479
+ }
480
+ function dn(e, t, n) {
481
+ switch (e.kind) {
482
+ case "sheets":
483
+ return e.sheetIds.length > 0 && e.sheetIds.every((r) => r === t);
484
+ case "cards":
485
+ return e.cardIds.length > 0 && e.cardIds.every((r) => n.has(r));
486
+ case "documentSections":
487
+ return e.sheetId === t;
488
+ case "allSheets":
489
+ return !1;
490
+ }
491
+ }
492
+ function ln(e) {
493
+ return e.kind === "sheets" && e.sheetIds.length === 0 || e.kind === "cards" && e.cardIds.length === 0;
494
+ }
495
+ function rt(e) {
496
+ return e.kind === "allSheets" || e.kind === "sheets" ? e.exceptCardIds ?? [] : [];
497
+ }
498
+ function fn(e) {
499
+ return e.kind === "allSheets" ? e.exceptSheetIds ?? [] : [];
500
+ }
501
+ function mn(e, t) {
502
+ var s;
503
+ if (e.kind !== "allSheets" && e.kind !== "sheets" || !((s = e.exceptCardIds) != null && s.includes(t))) return e;
504
+ const n = e.exceptCardIds.filter((i) => i !== t), { exceptCardIds: r, ...a } = e;
505
+ return n.length ? { ...a, exceptCardIds: n } : a;
506
+ }
507
+ function pn(e, t, n) {
508
+ var o;
509
+ if (t.kind !== "allSheets" && t.kind !== "sheets") return t;
510
+ const r = rt(e), a = e.kind === "sheets" ? e.sheetIds.filter((c) => n.has(c)) : e.kind === "allSheets" && ue(e) ? [...n].filter((c) => {
511
+ var u;
512
+ return !((u = e.exceptSheetIds) != null && u.includes(c));
513
+ }) : [], s = [...n].filter((c) => !a.includes(c));
514
+ if (t.kind === "sheets")
515
+ return {
516
+ ...t,
517
+ sheetIds: [.../* @__PURE__ */ new Set([...t.sheetIds, ...a])],
518
+ ...r.length ? { exceptCardIds: [...r] } : {}
519
+ };
520
+ const i = e.kind === "allSheets" ? ((o = e.exceptSheetIds) == null ? void 0 : o.filter((c) => n.has(c))) ?? [] : [];
521
+ return {
522
+ kind: "allSheets",
523
+ ...e.kind === "allSheets" && ue(e) ? {
524
+ ...e.sheetKinds ? { sheetKinds: e.sheetKinds } : {},
525
+ ...i.length ? { exceptSheetIds: i } : {}
526
+ } : a.length ? {
527
+ sheetKinds: ["dashboard", "document"],
528
+ ...s.length ? { exceptSheetIds: s } : {}
529
+ } : {},
530
+ ...r.length ? { exceptCardIds: [...r] } : {}
531
+ };
532
+ }
533
+ function ue(e) {
534
+ var t;
535
+ return e.kind === "allSheets" && (!((t = e.sheetKinds) != null && t.length) || e.sheetKinds.includes("document"));
536
+ }
537
+ function hn(e, t) {
538
+ switch (e.kind) {
539
+ case "allSheets":
540
+ case "sheets": {
541
+ const n = e.exceptCardIds ?? [];
542
+ return n.includes(t) ? e : { ...e, exceptCardIds: [...n, t] };
543
+ }
544
+ case "cards":
545
+ return { ...e, cardIds: e.cardIds.filter((n) => n !== t) };
546
+ case "documentSections":
547
+ return;
548
+ }
549
+ }
550
+ const st = 6;
551
+ function yn(e) {
552
+ if (!(e === void 0 || !Number.isFinite(e)) && Number.isInteger(e))
553
+ return Math.max(0, Math.min(st, e));
554
+ }
555
+ function ke(e) {
556
+ var t;
557
+ return ((t = e == null ? void 0 : e.comparison) == null ? void 0 : t.mode) === "explicit" ? e.comparison.spec : void 0;
558
+ }
559
+ function at(e) {
560
+ var t;
561
+ return ((t = ke(e)) == null ? void 0 : t.kind) || "none";
562
+ }
563
+ function In(e) {
564
+ const t = ke(e);
565
+ return (t == null ? void 0 : t.kind) === "target" ? t.targetValue : void 0;
566
+ }
567
+ function bn(e) {
568
+ return (e == null ? void 0 : e.semanticComparisonPolarity) || (e == null ? void 0 : e.comparisonPolarity) || qe;
569
+ }
570
+ function Q(e, t) {
571
+ const n = Object.entries(e || {}).filter(
572
+ ([s, i]) => i.output.outputId === s
573
+ );
574
+ if (!t.name) return;
575
+ const r = B({
576
+ ...t,
577
+ name: t.name
578
+ }), a = n.filter(
579
+ ([, s]) => s.output.metricAlias === r
580
+ );
581
+ return a.length === 1 ? a[0][1] : void 0;
582
+ }
583
+ function gn(e, t) {
584
+ const n = Q(e, t);
585
+ return {
586
+ comparisonKind: (n == null ? void 0 : n.type) ?? at(t),
587
+ metadata: n
588
+ };
589
+ }
590
+ function Sn(e) {
591
+ return (e == null ? void 0 : e.showComparison) ?? Be.showComparison;
592
+ }
593
+ function Cn(e) {
594
+ const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
595
+ return Object.entries(e || {}).forEach(([c, u]) => {
596
+ const d = u.output;
597
+ d.outputId === c && (t.add(d.currentColumnKey), n.add(d.currentColumnKey), d.availability.status === "available" && (d.comparisonColumnKey && (r.add(d.comparisonColumnKey), o.set(
598
+ d.comparisonColumnKey,
599
+ {
600
+ metricName: u.displayName || d.metricId,
601
+ comparisonLabel: u.displayLabel || "Comparison"
602
+ }
603
+ )), d.deltaColumnKey && (t.add(d.deltaColumnKey), a.add(d.deltaColumnKey)), d.percentChangeColumnKey && (t.add(d.percentChangeColumnKey), s.add(d.percentChangeColumnKey)), d.ratioColumnKey && (t.add(d.ratioColumnKey), i.add(d.ratioColumnKey)), d.rowStatusColumnKey && (t.add(d.rowStatusColumnKey), n.add(d.rowStatusColumnKey)), d.currentBucketColumnKey && (t.add(d.currentBucketColumnKey), n.add(d.currentBucketColumnKey)), d.comparisonSourceBucketColumnKey && (t.add(d.comparisonSourceBucketColumnKey), n.add(d.comparisonSourceBucketColumnKey))));
604
+ }), {
605
+ internalKeys: t,
606
+ bookkeepingKeys: n,
607
+ comparisonColumnKeys: r,
608
+ deltaColumnKeys: a,
609
+ percentChangeColumnKeys: s,
610
+ ratioColumnKeys: i,
611
+ comparisonSeriesLabels: o
612
+ };
613
+ }
614
+ const it = "SEMAPHOR_CALCULATED_FIELD";
615
+ function Y(e, t, n) {
616
+ if (n && (t === "groupby" || t === "pivotby"))
617
+ return n;
618
+ if (t === "metric" && e.name === "*" && !e.expression)
619
+ return e.alias || "count";
620
+ if (e.alias) return e.alias;
621
+ const r = e.entityName && e.entityName !== it ? e.entityName : void 0;
622
+ if (e.role === "metric") {
623
+ let a = e.aggregate || "metric";
624
+ if (e.expression) {
625
+ const s = e.expression.match(
626
+ /^(COUNT|SUM|AVG|MIN|MAX|MEDIAN|DISTINCT)\s*\(/i
627
+ );
628
+ a = s ? s[1].toLowerCase() : "expr";
629
+ } else
630
+ a = a.toLowerCase();
631
+ return r && r !== e.name ? `${r}_${e.name}_${a}` : `${e.name}_${a}`;
632
+ }
633
+ return r && r !== e.name ? `${r}_${e.name}` : e.name;
634
+ }
635
+ function kn(e) {
636
+ return Y(e, "detail");
637
+ }
638
+ function ot(e) {
639
+ const t = e.label;
640
+ return t && e.labelCount === 1 && (t === e.rawKey || !e.rawKeys.has(t)) ? t : e.rawKey;
641
+ }
642
+ function wn(e) {
643
+ const t = [
644
+ ...(e.groupByColumns ?? []).map((s) => ({ field: s, role: "groupby" })),
645
+ ...(e.metricColumns ?? []).map((s) => ({ field: s, role: "metric" })),
646
+ ...(e.pivotByColumns ?? []).map((s) => ({ field: s, role: "pivotby" })),
647
+ ...(e.detailColumns ?? []).map((s) => ({ field: s, role: "detail" }))
648
+ ], n = new Map(t.map(({ field: s, role: i }) => [s, Y(s, i)])), r = new Set(n.values()), a = /* @__PURE__ */ new Map();
649
+ for (const { field: s } of t)
650
+ s.label && a.set(s.label, (a.get(s.label) ?? 0) + 1);
651
+ return new Map(
652
+ t.map(({ field: s }) => [
653
+ s,
654
+ ot({
655
+ label: s.label,
656
+ labelCount: s.label ? a.get(s.label) ?? 0 : 0,
657
+ rawKey: n.get(s),
658
+ rawKeys: r
659
+ })
660
+ ])
661
+ );
662
+ }
663
+ const we = "text", R = 100, ct = 10, g = "value", Ae = ["previous", "change", "percentChange"];
664
+ function ut(e) {
665
+ return Ae.includes(e);
666
+ }
667
+ const dt = ["up", "down", "flat"];
668
+ function An(e, t, n) {
669
+ const { signWords: r, absolute: a, percent: s, ...i } = t ?? {};
670
+ return e !== "change" && e !== "percentChange" ? i : {
671
+ ...i,
672
+ ...(n == null ? void 0 : n.signWords) === void 0 ? { signWords: dt } : {},
673
+ ...(n == null ? void 0 : n.absolute) === void 0 ? { absolute: !0 } : {},
674
+ ...e === "percentChange" && (n == null ? void 0 : n.percent) === void 0 ? { percent: !0 } : {}
675
+ };
676
+ }
677
+ function J(e) {
678
+ var r, a, s, i;
679
+ if (e.get.kind !== "aggregate" || (r = e.query.sql) != null && r.trim()) return;
680
+ const t = (i = (s = (a = e.query.config) == null ? void 0 : a.metricColumns) == null ? void 0 : s[0]) == null ? void 0 : i.comparison;
681
+ if ((t == null ? void 0 : t.mode) !== "explicit") return;
682
+ const n = t.spec;
683
+ return n.kind === "previous_period" || n.kind === "previous_year" ? n : void 0;
684
+ }
685
+ function de(e, t) {
686
+ if (t === "preview" && e.get.kind !== "aggregate")
687
+ return R + 1;
688
+ switch (e.get.kind) {
689
+ case "only":
690
+ return 2;
691
+ case "list":
692
+ return R + 1;
693
+ default:
694
+ return 1;
695
+ }
696
+ }
697
+ const le = {
698
+ answer: /* @__PURE__ */ new WeakMap(),
699
+ preview: /* @__PURE__ */ new WeakMap()
700
+ };
701
+ function lt(e, t = "answer") {
702
+ var s;
703
+ const n = le[t].get(e);
704
+ if (n) return n;
705
+ const { query: r } = e, a = {
706
+ id: e.id,
707
+ title: e.name,
708
+ type: we,
709
+ respondsToSelections: !1,
710
+ dataVariableId: e.id,
711
+ // The viewer's dashboard comparison never changes a variable: its own
712
+ // measure says whether it compares (P3b-03).
713
+ preferences: { inheritGlobalComparison: !1 },
714
+ ...r.connectionId ? { connectionId: r.connectionId } : {},
715
+ ...r.dataSource ? { dataSource: r.dataSource } : {},
716
+ ...r.calculatedFields ? { calculatedFields: r.calculatedFields } : {},
717
+ ...(s = r.sql) != null && s.trim() ? { sql: r.sql, config: { rowLimit: de(e, t) } } : { config: { ...r.config, rowLimit: de(e, t) } }
718
+ };
719
+ return le[t].set(e, a), a;
720
+ }
721
+ function vn(e) {
722
+ return e.type === we && typeof e.dataVariableId == "string" && e.dataVariableId.length > 0;
723
+ }
724
+ function Tn(e, t, n) {
725
+ var r;
726
+ if (n === g && ((r = e.query.sql) != null && r.trim())) {
727
+ const a = Object.keys(t)[0];
728
+ return a === void 0 ? void 0 : t[a];
729
+ }
730
+ return n in t ? t[n] : void 0;
731
+ }
732
+ function U(e) {
733
+ const t = G(e);
734
+ return t === "string" || t === "unknown" ? "text" : t;
735
+ }
736
+ function ft(e) {
737
+ return typeof e == "number" ? "number" : typeof e == "boolean" ? "boolean" : "text";
738
+ }
739
+ function mt(e, t, n, r) {
740
+ var i, o;
741
+ const a = Ue(r, e.id, t);
742
+ return [
743
+ a == null ? void 0 : a.outputKey,
744
+ a == null ? void 0 : a.rawKey,
745
+ t === "metric" ? ((o = (i = r == null ? void 0 : r.byMetricAlias) == null ? void 0 : i[B(e)]) == null ? void 0 : o.outputKey) ?? B(e) : void 0,
746
+ Y(e, t === "metric" ? "metric" : "groupby"),
747
+ e.label,
748
+ e.name
749
+ ].find((c) => !!c && n.has(c));
750
+ }
751
+ function En(e, t) {
752
+ var r;
753
+ if (e.get.kind === "aggregate")
754
+ return J(e) ? [g, ...Ae] : [g];
755
+ if (e.get.kind === "list") return [g];
756
+ if ((r = e.query.sql) != null && r.trim()) return [...t ?? []];
757
+ const n = e.query.config;
758
+ return pt([
759
+ ...((n == null ? void 0 : n.groupByColumns) ?? []).map((a) => a.name),
760
+ ...((n == null ? void 0 : n.metricColumns) ?? []).map((a) => a.name)
761
+ ]);
762
+ }
763
+ function Kn(e, t) {
764
+ var s, i, o, c;
765
+ if (e.get.kind === "list") return "list";
766
+ if ((s = e.query.sql) != null && s.trim()) return;
767
+ const n = e.query.config, r = (u, d) => {
768
+ if (!u) return;
769
+ const f = d === "metric" ? q(u) : u.dataType;
770
+ return G(f) === "unknown" ? void 0 : U(f);
771
+ };
772
+ if (e.get.kind === "aggregate")
773
+ return ut(t) && J(e) ? "number" : t === g ? r((i = n == null ? void 0 : n.metricColumns) == null ? void 0 : i[0], "metric") : void 0;
774
+ const a = (o = n == null ? void 0 : n.groupByColumns) == null ? void 0 : o.find((u) => u.name === t);
775
+ return a ? r(a, "groupby") : r((c = n == null ? void 0 : n.metricColumns) == null ? void 0 : c.find((u) => u.name === t), "metric");
776
+ }
777
+ function pt(e) {
778
+ return [...new Set(e)];
779
+ }
780
+ function ht(e, t, n) {
781
+ var p, I, C;
782
+ const r = t[0] ?? {}, a = new Set(
783
+ (p = n.columns) != null && p.length ? n.columns.map((m) => m.key) : Object.keys(r)
784
+ ), s = new Map(
785
+ (n.columns ?? []).map((m) => [m.key, m.dataType])
786
+ ), i = (m, k) => s.has(m) ? U(s.get(m)) : k !== void 0 ? U(k) : ft(r[m]);
787
+ if ((I = e.query.sql) != null && I.trim())
788
+ return [...a].map((m) => ({ part: m, key: m, type: i(m, void 0) }));
789
+ const o = e.query.config ?? {}, c = [], u = a.size === 1 ? [...a][0] : void 0, d = e.get.kind === "aggregate" || e.get.kind === "list", f = (m, k, ee) => {
790
+ if (c.some((Fe) => Fe.part === ee)) return;
791
+ const K = mt(m, k, a, n.columnKeyMap) ?? (d ? u : void 0);
792
+ if (!K) return;
793
+ const _e = k === "metric" ? i(K, q(m)) : i(K, m.dataType);
794
+ c.push({ part: ee, key: K, type: _e });
795
+ }, y = o.metricColumns ?? [];
796
+ if (e.get.kind === "aggregate") {
797
+ const m = y[0] ? (C = Q(n.comparisonMetadata, y[0])) == null ? void 0 : C.output.currentColumnKey : void 0;
798
+ return m && a.has(m) ? c.push({ part: g, key: m, type: i(m, q(y[0])) }) : y[0] && f(y[0], "metric", g), c;
799
+ }
800
+ const h = o.groupByColumns ?? [];
801
+ if (e.get.kind === "list")
802
+ return h[0] && f(h[0], "groupby", g), c;
803
+ for (const m of h) f(m, "groupby", m.name);
804
+ for (const m of y) f(m, "metric", m.name);
805
+ return c;
806
+ }
807
+ function z(e, t) {
808
+ return e == null ? { value: null, type: t } : typeof e == "number" || typeof e == "boolean" || typeof e == "string" ? { value: e, type: t } : e instanceof Date ? { value: e.toISOString(), type: t } : { value: JSON.stringify(e), type: t };
809
+ }
810
+ function w(e) {
811
+ return !!e && typeof e == "object" && !Array.isArray(e);
812
+ }
813
+ function Nn(e) {
814
+ if (!w(e)) return {};
815
+ const t = w(e.data) ? e.data : e, n = D(e).length ? D(e) : D(t), r = w(t.metadata) ? t.metadata : void 0;
816
+ return {
817
+ ...t.records !== void 0 ? { records: t.records } : {},
818
+ ...Array.isArray(t.columns) ? { columns: t.columns } : {},
819
+ ...w(t.columnKeyMap) ? { columnKeyMap: t.columnKeyMap } : {},
820
+ ...n.length ? { filterReach: n } : {},
821
+ ...r && w(r.comparisonMetadata) ? { comparisonMetadata: r.comparisonMetadata } : {},
822
+ ...typeof t.error == "string" && t.error ? { error: t.error } : {}
823
+ };
824
+ }
825
+ function Dn(e, t, n = "answer") {
826
+ var d;
827
+ const r = (Array.isArray(t.records) ? t.records : []).filter(
828
+ (f) => !!f && typeof f == "object"
829
+ ), a = D(t), s = n === "preview" ? { matched: r.length > R ? "beyondCap" : r.length } : {};
830
+ if (!r.length) return { status: "none", why: "noRows", filterReach: a, ...s };
831
+ const i = ht(e, r, t);
832
+ if (e.get.kind === "list") {
833
+ const f = i[0], y = r.length > R, h = f ? r.map((I) => z(I[f.key], f.type)).filter((I) => I.value !== null) : [];
834
+ if (!h.length && !y) return { status: "none", why: "noRows", filterReach: a, ...s };
835
+ const p = Math.max(1, e.get.limit ?? ct);
836
+ return {
837
+ status: "listed",
838
+ items: h.slice(0, p),
839
+ more: y ? "beyondCap" : Math.max(0, h.length - p),
840
+ filterReach: a,
841
+ ...s
842
+ };
843
+ }
844
+ if (e.get.kind === "only" && r.length > 1)
845
+ return { status: "none", why: "moreThanOne", filterReach: a, ...s };
846
+ const o = r[0], c = Object.fromEntries(
847
+ i.map((f) => [f.part, z(o[f.key], f.type)])
848
+ );
849
+ if (e.get.kind === "aggregate" && ((d = c[g]) == null ? void 0 : d.value) == null)
850
+ return { status: "none", why: "noRows", filterReach: a, ...s };
851
+ const u = J(e) ? yt(e, o, t) : void 0;
852
+ return {
853
+ status: "answered",
854
+ parts: u && "parts" in u ? { ...c, ...u.parts } : c,
855
+ filterReach: a,
856
+ ...u && "unavailable" in u ? { comparisonUnavailable: u.unavailable } : {},
857
+ ...s
858
+ };
859
+ }
860
+ function yt(e, t, n) {
861
+ var o, c;
862
+ const r = (c = (o = e.query.config) == null ? void 0 : o.metricColumns) == null ? void 0 : c[0], a = r ? Q(n.comparisonMetadata, r) : void 0, s = a == null ? void 0 : a.output;
863
+ if (!s || s.availability.status !== "available" || !s.comparisonColumnKey)
864
+ return { unavailable: (s == null ? void 0 : s.availability.status) === "unavailable" ? s.availability.reason : "temporal_binding_missing" };
865
+ const i = (u) => {
866
+ const d = t[u], f = typeof d == "string" && d.trim() !== "" ? Number(d) : d;
867
+ return z(typeof f == "number" && !Number.isFinite(f) ? null : f, "number");
868
+ };
869
+ return {
870
+ parts: {
871
+ previous: i(s.comparisonColumnKey),
872
+ change: i(s.deltaColumnKey ?? ""),
873
+ percentChange: i(s.percentChangeColumnKey ?? "")
874
+ }
875
+ };
876
+ }
877
+ const fe = /* @__PURE__ */ new WeakMap();
878
+ function H(e) {
879
+ const t = fe.get(e);
880
+ if (t) return t;
881
+ const n = new Map(
882
+ (e.sheets ?? []).map(
883
+ (s) => [s.id, s.kind === "document" ? "document" : "dashboard"]
884
+ )
885
+ ), r = [
886
+ ...x(e).map(
887
+ (s) => ({
888
+ kind: "card",
889
+ id: s.cardId,
890
+ card: s.card,
891
+ sheetId: s.sheetId,
892
+ sheetKind: n.get(s.sheetId) ?? "dashboard",
893
+ ...s.kind === "documentSectionCard" ? { sectionId: s.sectionId } : {}
894
+ })
895
+ ),
896
+ ...(e.variables ?? []).map(
897
+ (s) => ({
898
+ kind: "variable",
899
+ id: s.id,
900
+ variable: s,
901
+ card: lt(s)
902
+ })
903
+ )
904
+ ], a = { targets: r, byId: new Map(r.map((s) => [s.id, s])) };
905
+ return fe.set(e, a), a;
906
+ }
907
+ function It(e) {
908
+ return H(e).targets;
909
+ }
910
+ function On(e, t) {
911
+ return H(e).byId.get(t);
912
+ }
913
+ function bt(e, t) {
914
+ return H(e).byId.has(t);
915
+ }
916
+ function gt(e, t) {
917
+ return t.kind === "card" ? [
918
+ {
919
+ sheetId: t.sheetId,
920
+ cardId: t.id,
921
+ sheetKind: t.sheetKind,
922
+ ...t.sectionId ? { sectionId: t.sectionId } : {}
923
+ }
924
+ ] : Ce(e, t.id);
925
+ }
926
+ function St(e, t, n) {
927
+ return gt(e, n).some(
928
+ (r) => S(t, r)
929
+ );
930
+ }
931
+ function Rn(e, t) {
932
+ return It(e).filter(
933
+ (n) => n.kind === "variable" && St(e, t, n)
934
+ );
935
+ }
936
+ const Ct = ["new", "edit", "delete", "create", "update", "remove"];
937
+ function ve(e, t) {
938
+ return (e.sheets || []).flatMap(
939
+ (n) => x({ sheets: [n] }).filter(t).map((r) => ({
940
+ card: r.card,
941
+ sheet: n,
942
+ ...r.kind === "frameCard" && { frameId: r.frameId },
943
+ ...r.kind === "documentSectionCard" && {
944
+ sectionId: r.sectionId
945
+ }
946
+ }))
947
+ );
948
+ }
949
+ function T(e) {
950
+ return ve(e, (t) => t.kind !== "documentSectionCard");
951
+ }
952
+ function Mn(e) {
953
+ return [
954
+ ...T(e),
955
+ ...ve(e, (t) => t.kind === "documentSectionCard")
956
+ ];
957
+ }
958
+ function xn(e) {
959
+ return T(e).map((t) => t.card);
960
+ }
961
+ function _n(e, t, n) {
962
+ return n && t === n ? !0 : !bt(e, t);
963
+ }
964
+ function Fn(e) {
965
+ return !e || e.trim().length === 0 ? { isValid: !1, error: "Card ID cannot be empty" } : e.length < 3 ? { isValid: !1, error: "Card ID must be at least 3 characters" } : e.length > 50 ? { isValid: !1, error: "Card ID must be less than 50 characters" } : /^[a-zA-Z0-9-_]+$/.test(e) ? /^[a-zA-Z0-9]/.test(e) ? Ct.includes(e.toLowerCase()) ? {
966
+ isValid: !1,
967
+ error: `"${e}" is a reserved keyword and cannot be used`
968
+ } : { isValid: !0 } : {
969
+ isValid: !1,
970
+ error: "Card ID must start with a letter or number"
971
+ } : {
972
+ isValid: !1,
973
+ error: "Card ID can only contain letters, numbers, hyphens, and underscores"
974
+ };
975
+ }
976
+ function Vn(e, t) {
977
+ var n;
978
+ return (n = kt(e, t)) == null ? void 0 : n.card;
979
+ }
980
+ function kt(e, t) {
981
+ for (const n of T(e))
982
+ if (n.card.id === t)
983
+ return n;
984
+ }
985
+ function Pn(e, t) {
986
+ for (const n of e.sheets || [])
987
+ for (const r of n.frames || [])
988
+ for (const a of r.cards || [])
989
+ if (a.id === t)
990
+ return { card: a, sheet: n };
991
+ }
992
+ const M = {
993
+ includeMetricFilterDatasets: !0,
994
+ preferQualifiedIdentity: !1
995
+ };
996
+ function Te(e) {
997
+ if (!e) return;
998
+ if (e.kind === "semantic")
999
+ return { entityName: e.datasetName, entityId: e.datasetId, label: e.label };
1000
+ const t = [e.databaseName, e.schemaName, e.tableName].filter((n) => !!(n && n.trim())).join(".");
1001
+ return {
1002
+ entityName: e.tableName,
1003
+ qualifiedEntityName: t.includes(".") ? t : void 0,
1004
+ label: e.label
1005
+ };
1006
+ }
1007
+ function wt(e) {
1008
+ var n;
1009
+ const t = Te(e.source);
1010
+ return t ? `${(n = e.source) == null ? void 0 : n.kind}:${t.qualifiedEntityName || t.entityName}` : "";
1011
+ }
1012
+ function At(e) {
1013
+ return [
1014
+ e.id,
1015
+ e.qualifiedEntityName,
1016
+ e.entityId,
1017
+ e.entityName,
1018
+ e.qualifiedFieldName,
1019
+ e.name,
1020
+ // Source-only fields from different datasets can otherwise share a key
1021
+ // and the second dataset would be silently dropped.
1022
+ wt(e)
1023
+ ].join("|");
1024
+ }
1025
+ function vt(e) {
1026
+ return [e.entityName, e.qualifiedEntityName || "", e.entityId || ""].join("|");
1027
+ }
1028
+ function Ln(e) {
1029
+ return e.entityName || e.qualifiedEntityName || "";
1030
+ }
1031
+ function Tt(e) {
1032
+ var t, n;
1033
+ return !!(e.expression || e.derivedField || (n = (t = e.calculatedFormula) == null ? void 0 : t.inputFields) != null && n.length);
1034
+ }
1035
+ function Et(e) {
1036
+ return Ve(e) ? !0 : e.entityName || e.qualifiedEntityName ? !1 : !e.source || Tt(e);
1037
+ }
1038
+ function P(e, t) {
1039
+ const n = vt(t);
1040
+ e.found.has(n) || e.found.set(n, t);
1041
+ }
1042
+ function E(e, t) {
1043
+ var u, d, f;
1044
+ if (!e) return;
1045
+ const n = At(e);
1046
+ if (t.visitedFields.has(n)) return;
1047
+ t.visitedFields.add(n);
1048
+ const r = Et(e);
1049
+ if (!r) {
1050
+ const y = !e.entityName && !e.qualifiedEntityName ? Te(e.source) : void 0;
1051
+ P(
1052
+ t,
1053
+ y || {
1054
+ // May be empty for qualified-only metadata; identity then comes from
1055
+ // `qualifiedEntityName` (see `identityFor` and the calculator).
1056
+ entityName: e.entityName || "",
1057
+ entityId: e.entityId,
1058
+ qualifiedEntityName: e.qualifiedEntityName,
1059
+ label: e.source && e.source.kind === "semantic" ? e.source.label : void 0
1060
+ }
1061
+ );
1062
+ }
1063
+ t.includeMetricFilterDatasets && "parameters" in e && ((u = e.parameters) != null && u.filters) && X(e.parameters.filters, t);
1064
+ const a = (d = e.calculatedFormula) == null ? void 0 : d.inputFields, s = !!(a && a.length > 0);
1065
+ s && a.forEach((y) => E(y, t));
1066
+ let i = !1, o = !1;
1067
+ const c = s || (f = e.derivedField) == null ? void 0 : f.inputs;
1068
+ if (c && Object.keys(c).length > 0)
1069
+ for (const y of Object.values(c)) {
1070
+ const h = y.field.source;
1071
+ if (!h) {
1072
+ s || (o = !0);
1073
+ continue;
1074
+ }
1075
+ if (h.kind === "sql") {
1076
+ o = !0;
1077
+ continue;
1078
+ }
1079
+ if (h.kind === "semantic")
1080
+ P(t, {
1081
+ entityName: h.datasetName,
1082
+ entityId: h.datasetId,
1083
+ label: h.label
1084
+ });
1085
+ else {
1086
+ const p = [h.databaseName, h.schemaName, h.tableName].filter((I) => !!(I && I.trim())).join(".");
1087
+ P(t, {
1088
+ entityName: h.tableName,
1089
+ qualifiedEntityName: p.includes(".") ? p : void 0,
1090
+ label: h.label
1091
+ });
1092
+ }
1093
+ i = !0;
1094
+ }
1095
+ o && (t.complete = !1), r && !s && !i && (t.complete = !1);
1096
+ }
1097
+ function X(e, t) {
1098
+ if (e && !t.visitedGroups.has(e.id)) {
1099
+ t.visitedGroups.add(e.id);
1100
+ for (const n of e.conditions || [])
1101
+ E(n.field, t);
1102
+ for (const n of e.groups || [])
1103
+ X(n, t);
1104
+ }
1105
+ }
1106
+ function _(e, t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set()) {
1107
+ return {
1108
+ found: /* @__PURE__ */ new Map(),
1109
+ complete: !0,
1110
+ visitedFields: t,
1111
+ visitedGroups: n,
1112
+ includeMetricFilterDatasets: e
1113
+ };
1114
+ }
1115
+ function Z(e, t) {
1116
+ var r;
1117
+ const n = (r = e.qualifiedEntityName) != null && r.includes(".") ? e.qualifiedEntityName : void 0;
1118
+ return t === "qualifiedOnly" ? n : t === "preferQualified" ? n || e.entityName || void 0 : e.entityName || void 0;
1119
+ }
1120
+ function $n(e) {
1121
+ const t = _(!1);
1122
+ return E(e, t), { datasets: Array.from(t.found.values()), complete: t.complete };
1123
+ }
1124
+ function Ee(e, t, n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), a = M) {
1125
+ const s = { ...M, ...a }, i = _(s.includeMetricFilterDatasets, n, r);
1126
+ E(e, i), i.found.forEach((o) => {
1127
+ const c = Z(o, s.preferQualifiedIdentity ? "preferQualified" : "name");
1128
+ c && t.add(c);
1129
+ });
1130
+ }
1131
+ function qn(e, t) {
1132
+ Ee(e, t, /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set(), {
1133
+ preferQualifiedIdentity: !0
1134
+ });
1135
+ }
1136
+ function Bn(e, t, n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set()) {
1137
+ const a = _(!0, n, r);
1138
+ E(e, a), a.found.forEach((s) => {
1139
+ const i = Z(s, "qualifiedOnly");
1140
+ i && t.add(i);
1141
+ });
1142
+ }
1143
+ function jn(e, t, n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set()) {
1144
+ Ee(e, t, n, r, {
1145
+ includeMetricFilterDatasets: !1
1146
+ });
1147
+ }
1148
+ function Un(e, t, n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), a = M) {
1149
+ const s = { ...M, ...a }, i = _(s.includeMetricFilterDatasets, n, r);
1150
+ X(e, i), i.found.forEach((o) => {
1151
+ const c = Z(o, s.preferQualifiedIdentity ? "preferQualified" : "name");
1152
+ c && t.add(c);
1153
+ });
1154
+ }
1155
+ function zn(e, t) {
1156
+ return t != null && t[e] ? t[e] : (e.includes(".") ? e.slice(e.lastIndexOf(".") + 1) : e).replace(/[_-]+/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/\s+/g, " ").trim().replace(/\b\w/g, (r) => r.toUpperCase());
1157
+ }
1158
+ const Wn = {
1159
+ database: null,
1160
+ schema: null,
1161
+ table: null
1162
+ }, Gn = "__card_default__", Kt = {
1163
+ date: /* @__PURE__ */ new Set([
1164
+ "between",
1165
+ "not between",
1166
+ "=",
1167
+ "!=",
1168
+ ">",
1169
+ ">=",
1170
+ "<",
1171
+ "<=",
1172
+ "is null",
1173
+ "is not null"
1174
+ ]),
1175
+ number: /* @__PURE__ */ new Set([
1176
+ "between",
1177
+ "not between",
1178
+ "=",
1179
+ "!=",
1180
+ ">",
1181
+ ">=",
1182
+ "<",
1183
+ "<=",
1184
+ "in",
1185
+ "not in",
1186
+ "is null",
1187
+ "is not null"
1188
+ ]),
1189
+ string: /* @__PURE__ */ new Set([
1190
+ "=",
1191
+ "!=",
1192
+ "in",
1193
+ "not in",
1194
+ "like",
1195
+ "not like",
1196
+ "is null",
1197
+ "is not null"
1198
+ ]),
1199
+ boolean: /* @__PURE__ */ new Set(["=", "!=", "in", "not in", "is null", "is not null"])
1200
+ };
1201
+ function Nt(e) {
1202
+ const t = G(e);
1203
+ return t === "number" || t === "boolean" ? t : t === "date" || t === "datetime" ? "date" : "string";
1204
+ }
1205
+ function Qn(e, t) {
1206
+ return typeof t != "string" ? !1 : Kt[Nt(e)].has(t);
1207
+ }
1208
+ const Dt = /* @__PURE__ */ new Set([
1209
+ "=",
1210
+ ">",
1211
+ "<",
1212
+ ">=",
1213
+ "<=",
1214
+ "!=",
1215
+ "in",
1216
+ "not in",
1217
+ "like",
1218
+ "not like",
1219
+ "between",
1220
+ "not between",
1221
+ "is null",
1222
+ "is not null"
1223
+ ]);
1224
+ function Ot(e, t) {
1225
+ return t === "number" ? typeof e == "number" && Number.isFinite(e) : t === "boolean" ? typeof e == "boolean" : t === "date" ? e instanceof Date || typeof e == "string" && e.trim().length > 0 : typeof e == "string" || typeof e == "number" || typeof e == "boolean";
1226
+ }
1227
+ function Rt(e, t, n, r) {
1228
+ if (Pe(e.relativeMeta)) {
1229
+ r.push(
1230
+ `${n}.relativeMeta counts back from the latest data; a dashboard filter's dates run to now. Use a period counted back from today.`
1231
+ );
1232
+ return;
1233
+ }
1234
+ Mt(e.operation, e.values, t, `${n}.values`, r);
1235
+ }
1236
+ function Mt(e, t, n, r, a) {
1237
+ if (e === "is null" || e === "is not null") {
1238
+ t.length !== 0 && a.push(`${r} must be empty for null filter operations.`);
1239
+ return;
1240
+ }
1241
+ if (e === "between" || e === "not between") {
1242
+ if (t.length !== 2) {
1243
+ a.push(
1244
+ `${r} must contain exactly two values for between operations.`
1245
+ );
1246
+ return;
1247
+ }
1248
+ } else if (e === "in" || e === "not in") {
1249
+ if (t.length === 0) {
1250
+ a.push(
1251
+ `${r} must contain at least one value for set operations.`
1252
+ );
1253
+ return;
1254
+ }
1255
+ } else if (t.length !== 1) {
1256
+ a.push(
1257
+ `${r} must contain exactly one value for '${String(e)}' operations.`
1258
+ );
1259
+ return;
1260
+ }
1261
+ for (const s of t)
1262
+ if (!Ot(s, n)) {
1263
+ a.push(
1264
+ `${r} contains a value that is incompatible with valueType '${n}'.`
1265
+ );
1266
+ return;
1267
+ }
1268
+ }
1269
+ const Ke = {
1270
+ bookmarksPerViewerPerDashboard: 20,
1271
+ bookmarkNameMaxChars: 100,
1272
+ columnLabelMaxChars: 120,
1273
+ tableSettingsMaxBytes: 65536,
1274
+ rememberedTableSettingsMaxBytes: 262144,
1275
+ bookmarkStateMaxBytes: 65536
1276
+ }, Ne = 1;
1277
+ function Yn(e) {
1278
+ return new TextEncoder().encode(JSON.stringify(e ?? null)).length;
1279
+ }
1280
+ function xt(e) {
1281
+ const t = encodeURIComponent;
1282
+ switch (e.kind) {
1283
+ case "dimension":
1284
+ return `dim:${e.role}:${t(e.fieldId)}`;
1285
+ case "metric":
1286
+ return `metric:${t(e.metricId)}:${t(
1287
+ e.metricAlias
1288
+ )}`;
1289
+ case "result":
1290
+ return `result:${t(e.key)}`;
1291
+ }
1292
+ }
1293
+ function N(e) {
1294
+ if (e)
1295
+ try {
1296
+ return decodeURIComponent(e);
1297
+ } catch {
1298
+ return;
1299
+ }
1300
+ }
1301
+ function _t(e) {
1302
+ if (typeof e != "string") return;
1303
+ const t = e.split(":");
1304
+ let n;
1305
+ if (t[0] === "dim" && t.length === 3) {
1306
+ const r = t[1], a = N(t[2]);
1307
+ (r === "detail" || r === "groupby") && a && (n = { kind: "dimension", role: r, fieldId: a });
1308
+ } else if (t[0] === "metric" && t.length === 3) {
1309
+ const r = N(t[1]), a = N(t[2]);
1310
+ r && a && (n = { kind: "metric", metricId: r, metricAlias: a });
1311
+ } else if (t[0] === "result" && t.length === 2) {
1312
+ const r = N(t[1]);
1313
+ r && (n = { kind: "result", key: r });
1314
+ }
1315
+ return n && xt(n) === e ? n : void 0;
1316
+ }
1317
+ function W(e) {
1318
+ return typeof e == "string" && _t(e) !== void 0;
1319
+ }
1320
+ const me = l.array(l.string()).max(2e3), Ft = l.object({
1321
+ order: me.optional(),
1322
+ hidden: me.optional(),
1323
+ labels: l.record(l.string(), l.string().max(Ke.columnLabelMaxChars)).optional(),
1324
+ sort: l.array(
1325
+ l.object({
1326
+ columnId: l.string(),
1327
+ direction: l.enum(["asc", "desc"])
1328
+ }).strict()
1329
+ ).max(2e3).optional()
1330
+ }).strict();
1331
+ function pe(e) {
1332
+ const t = /* @__PURE__ */ new Set(), n = [];
1333
+ for (const r of e)
1334
+ !W(r) || t.has(r) || (t.add(r), n.push(r));
1335
+ return n;
1336
+ }
1337
+ function De(e) {
1338
+ if (!e) return;
1339
+ const t = e.order ? pe(e.order) : void 0, n = e.hidden ? pe(e.hidden) : void 0, r = Object.entries(e.labels ?? {}).flatMap(
1340
+ ([o, c]) => {
1341
+ const u = typeof c == "string" ? c.trim() : "";
1342
+ return W(o) && u ? [
1343
+ [
1344
+ o,
1345
+ u.slice(0, Ke.columnLabelMaxChars)
1346
+ ]
1347
+ ] : [];
1348
+ }
1349
+ ), a = /* @__PURE__ */ new Set(), s = e.sort ? e.sort.filter((o) => !W(o.columnId) || a.has(o.columnId) ? !1 : (a.add(o.columnId), !0)) : void 0, i = {};
1350
+ return t != null && t.length && (i.order = t), n != null && n.length && (i.hidden = n), r.length && (i.labels = Object.fromEntries(r)), s && (i.sort = s.map(({ columnId: o, direction: c }) => ({
1351
+ columnId: o,
1352
+ direction: c
1353
+ }))), Object.keys(i).length ? i : void 0;
1354
+ }
1355
+ function Oe(e) {
1356
+ return De(e) === void 0;
1357
+ }
1358
+ function Re(e, t) {
1359
+ if (t !== Ne)
1360
+ return {
1361
+ ok: !1,
1362
+ error: `Unsupported table settings version ${t}.`
1363
+ };
1364
+ const n = Ft.safeParse(e);
1365
+ return n.success ? {
1366
+ ok: !0,
1367
+ value: De(n.data) ?? {}
1368
+ } : { ok: !1, error: "Table settings are invalid." };
1369
+ }
1370
+ function Jn(e, t, n) {
1371
+ if (!e || typeof e != "object" || Array.isArray(e)) return {};
1372
+ const r = {};
1373
+ for (const [a, s] of Object.entries(
1374
+ e
1375
+ )) {
1376
+ if (!n.has(a)) continue;
1377
+ const i = Re(s, t);
1378
+ i.ok && !Oe(i.value) && (r[a] = i.value);
1379
+ }
1380
+ return r;
1381
+ }
1382
+ const Vt = /* @__PURE__ */ new Set([
1383
+ "table",
1384
+ "detailTable"
1385
+ ]);
1386
+ function Me(e) {
1387
+ return Vt.has(e.type);
1388
+ }
1389
+ function Pt(e) {
1390
+ var t, n;
1391
+ return Me(e) && ((n = (t = e.preferences) == null ? void 0 : t.tablePrefs) == null ? void 0 : n.allowViewerColumnCustomization) !== !1;
1392
+ }
1393
+ function Hn(e) {
1394
+ return new Set(
1395
+ T(e).filter(({ card: t }) => Me(t)).map(({ card: t }) => t.id)
1396
+ );
1397
+ }
1398
+ function Xn(e) {
1399
+ return new Set(
1400
+ T(e).filter(({ card: t }) => Pt(t)).map(({ card: t }) => t.id)
1401
+ );
1402
+ }
1403
+ const L = 1, Zn = ["PRIVATE", "TEAM", "DASHBOARD"], Lt = l.object({
1404
+ filterId: l.string().min(1),
1405
+ name: l.string(),
1406
+ operation: l.string(),
1407
+ valueType: l.enum(["string", "number", "date", "boolean"]),
1408
+ values: l.array(l.unknown())
1409
+ }).passthrough().superRefine((e, t) => {
1410
+ const n = [];
1411
+ Dt.has(e.operation) ? Rt(e, e.valueType, "filterValue", n) : n.push("filterValue.operation must be a valid filter operation.");
1412
+ for (const r of n) t.addIssue({ code: "custom", message: r });
1413
+ }), $ = l.unknown().superRefine((e, t) => {
1414
+ for (const n of je(e).errors)
1415
+ t.addIssue({ code: "custom", message: n.message });
1416
+ }), $t = l.discriminatedUnion("kind", [
1417
+ l.object({ kind: l.literal("filter"), filterValue: Lt }).strict(),
1418
+ l.object({ kind: l.literal("control"), value: l.unknown() }).strict(),
1419
+ l.object({
1420
+ kind: l.literal("selection"),
1421
+ selection: Le
1422
+ }).strict()
1423
+ ]), qt = l.union([
1424
+ l.object({
1425
+ status: l.literal("set"),
1426
+ value: $t,
1427
+ comparisonSelection: $.optional()
1428
+ }).strict(),
1429
+ l.object({
1430
+ status: l.literal("cleared"),
1431
+ comparisonSelection: $.optional()
1432
+ }).strict(),
1433
+ l.object({ comparisonSelection: $ }).strict()
1434
+ ]), xe = ["bySheetId", "byCardId", "byDocumentSectionId"], Bt = /* @__PURE__ */ new Set(["version", "selectedSheetId", "inputs", "tableSettings"]), jt = /* @__PURE__ */ new Set(["shared", ...xe]), A = (e) => !!e && typeof e == "object" && !Array.isArray(e);
1435
+ function he(e, t, n) {
1436
+ if (e === void 0) return;
1437
+ if (!A(e)) {
1438
+ t.push({ target: "input", id: n });
1439
+ return;
1440
+ }
1441
+ const r = {};
1442
+ for (const [a, s] of Object.entries(e)) {
1443
+ const i = a ? qt.safeParse(s) : void 0;
1444
+ i != null && i.success ? r[a] = i.data : t.push({
1445
+ target: $e(a) ? "selection" : "input",
1446
+ id: a
1447
+ });
1448
+ }
1449
+ return Object.keys(r).length ? r : void 0;
1450
+ }
1451
+ function Ut(e, t) {
1452
+ if (t !== L)
1453
+ return { ok: !1, error: `Unsupported bookmark version ${t}.` };
1454
+ if (!A(e) || e.version !== L)
1455
+ return { ok: !1, error: "The bookmark state is invalid." };
1456
+ const n = [], r = Object.keys(e).filter((o) => !Bt.has(o));
1457
+ let a;
1458
+ typeof e.selectedSheetId == "string" && e.selectedSheetId ? a = e.selectedSheetId : e.selectedSheetId !== void 0 && n.push({ target: "sheet", id: String(e.selectedSheetId) });
1459
+ const s = {};
1460
+ if (A(e.inputs)) {
1461
+ r.push(
1462
+ ...Object.keys(e.inputs).filter((c) => !jt.has(c)).map((c) => `inputs.${c}`)
1463
+ );
1464
+ const o = he(e.inputs.shared, n, "shared");
1465
+ o && (s.shared = o);
1466
+ for (const c of xe) {
1467
+ const u = e.inputs[c];
1468
+ if (u === void 0) continue;
1469
+ if (!A(u)) {
1470
+ n.push({ target: "input", id: c });
1471
+ continue;
1472
+ }
1473
+ const d = {};
1474
+ for (const [f, y] of Object.entries(u)) {
1475
+ const h = he(y, n, `${c}.${f}`);
1476
+ h && (d[f] = h);
1477
+ }
1478
+ Object.keys(d).length && (s[c] = d);
1479
+ }
1480
+ } else e.inputs !== void 0 && r.push("inputs");
1481
+ const i = {};
1482
+ if (A(e.tableSettings))
1483
+ for (const [o, c] of Object.entries(e.tableSettings)) {
1484
+ const u = o ? Re(c, Ne) : void 0;
1485
+ u != null && u.ok ? Oe(u.value) || (i[o] = u.value) : n.push({ target: "card", id: o });
1486
+ }
1487
+ else e.tableSettings !== void 0 && r.push("tableSettings");
1488
+ return {
1489
+ ok: !0,
1490
+ value: {
1491
+ version: L,
1492
+ ...a ? { selectedSheetId: a } : {},
1493
+ ...Object.keys(s).length ? { inputs: s } : {},
1494
+ ...Object.keys(i).length ? { tableSettings: i } : {}
1495
+ },
1496
+ issues: n,
1497
+ unknownKeys: r
1498
+ };
1499
+ }
1500
+ function er(e, t) {
1501
+ const n = Ut(e, t);
1502
+ return n.ok ? n.issues.some((r) => r.target === "card") ? { ok: !1, error: "The bookmark table settings are invalid." } : n.issues.length || n.unknownKeys.length ? { ok: !1, error: "The bookmark state is invalid." } : { ok: !0, value: n.value } : n;
1503
+ }
1504
+ export {
1505
+ Zt as $,
1506
+ S as A,
1507
+ L as B,
1508
+ Gn as C,
1509
+ cn as D,
1510
+ Wn as E,
1511
+ On as F,
1512
+ wn as G,
1513
+ ze as H,
1514
+ rt as I,
1515
+ It as J,
1516
+ fn as K,
1517
+ ue as L,
1518
+ Ze as M,
1519
+ an as N,
1520
+ Se as O,
1521
+ pn as P,
1522
+ En as Q,
1523
+ yn as R,
1524
+ Y as S,
1525
+ kn as T,
1526
+ ot as U,
1527
+ Ke as V,
1528
+ te as W,
1529
+ ne as X,
1530
+ We as Y,
1531
+ Xt as Z,
1532
+ Ge as _,
1533
+ Ln as a,
1534
+ on as a0,
1535
+ un as a1,
1536
+ dn as a2,
1537
+ ln as a3,
1538
+ mn as a4,
1539
+ hn as a5,
1540
+ we as a6,
1541
+ R as a7,
1542
+ ct as a8,
1543
+ g as a9,
1544
+ tn as aA,
1545
+ Je as aB,
1546
+ v as aC,
1547
+ Q as aD,
1548
+ gn as aE,
1549
+ Cn as aF,
1550
+ Sn as aG,
1551
+ T as aH,
1552
+ at as aI,
1553
+ bn as aJ,
1554
+ re as aK,
1555
+ In as aL,
1556
+ Mn as aM,
1557
+ Qe as aN,
1558
+ _n as aO,
1559
+ Fn as aP,
1560
+ Pn as aQ,
1561
+ en as aR,
1562
+ Ae as aa,
1563
+ ut as ab,
1564
+ dt as ac,
1565
+ An as ad,
1566
+ J as ae,
1567
+ lt as af,
1568
+ vn as ag,
1569
+ Tn as ah,
1570
+ Kn as ai,
1571
+ Nn as aj,
1572
+ Dn as ak,
1573
+ nn as al,
1574
+ Xe as am,
1575
+ rn as an,
1576
+ sn as ao,
1577
+ Ce as ap,
1578
+ bt as aq,
1579
+ gt as ar,
1580
+ St as as,
1581
+ Rn as at,
1582
+ Nt as au,
1583
+ Qn as av,
1584
+ Dt as aw,
1585
+ Rt as ax,
1586
+ kt as ay,
1587
+ xn as az,
1588
+ qn as b,
1589
+ Ee as c,
1590
+ Te as d,
1591
+ Bn as e,
1592
+ jn as f,
1593
+ Un as g,
1594
+ zn as h,
1595
+ Ut as i,
1596
+ Ne as j,
1597
+ _t as k,
1598
+ Oe as l,
1599
+ Yn as m,
1600
+ De as n,
1601
+ Re as o,
1602
+ er as p,
1603
+ Jn as q,
1604
+ $n as r,
1605
+ Me as s,
1606
+ xt as t,
1607
+ Pt as u,
1608
+ Hn as v,
1609
+ Xn as w,
1610
+ Zn as x,
1611
+ Vn as y,
1612
+ x as z
1613
+ };