farseer-cli 1.25.0 → 1.26.0

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 (69) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/dashboards.js +2 -0
  3. package/dist/commands/dashboards.js.map +1 -1
  4. package/dist/commands/login.js +18 -7
  5. package/dist/commands/login.js.map +1 -1
  6. package/dist/commands/logout.js +28 -12
  7. package/dist/commands/logout.js.map +1 -1
  8. package/dist/commands/run.js +2 -3
  9. package/dist/commands/run.js.map +1 -1
  10. package/dist/commands/whoami.js +12 -5
  11. package/dist/commands/whoami.js.map +1 -1
  12. package/dist/mcp/tools/authTools.js +2 -1
  13. package/dist/mcp/tools/authTools.js.map +1 -1
  14. package/dist/mcp/tools/dashboardTools.js +3 -1
  15. package/dist/mcp/tools/dashboardTools.js.map +1 -1
  16. package/dist/mcp/tools/runTools.js +2 -3
  17. package/dist/mcp/tools/runTools.js.map +1 -1
  18. package/dist/mcp/utils/helpers.js +8 -6
  19. package/dist/mcp/utils/helpers.js.map +2 -2
  20. package/dist/mcp/utils/session.js +6 -2
  21. package/dist/mcp/utils/session.js.map +1 -1
  22. package/dist/operations/dashboards.js +1 -1
  23. package/dist/operations/dashboards.js.map +1 -1
  24. package/dist/pipeline/generated-reference.json +8 -8
  25. package/dist/services/codefirst/layoutReadback.js +95 -0
  26. package/dist/services/codefirst/layoutReadback.js.map +2 -2
  27. package/dist/services/configService.js +33 -18
  28. package/dist/services/configService.js.map +1 -1
  29. package/dist/services/credentials.js +26 -11
  30. package/dist/services/credentials.js.map +1 -1
  31. package/dist/services/farseerService.js +34 -32
  32. package/dist/services/farseerService.js.map +1 -1
  33. package/dist/services/keycloak.js +44 -0
  34. package/dist/services/keycloak.js.map +6 -0
  35. package/dist/services/preflight.js +1 -2
  36. package/dist/services/preflight.js.map +1 -1
  37. package/dist/services/realms.js +67 -15
  38. package/dist/services/realms.js.map +1 -1
  39. package/dist/utils/serverUrl.js +42 -0
  40. package/dist/utils/serverUrl.js.map +6 -0
  41. package/docs/pipeline-reference.md +13 -3
  42. package/package.json +1 -1
  43. package/skills/farseer-code-tiles/SKILL.md +153 -0
  44. package/skills/farseer-code-tiles/anti-patterns.md +183 -0
  45. package/skills/farseer-code-tiles/api.md +237 -0
  46. package/skills/farseer-code-tiles/check-tile.mjs +521 -0
  47. package/skills/farseer-code-tiles/design.md +159 -0
  48. package/skills/farseer-code-tiles/echarts-look.md +110 -0
  49. package/skills/farseer-code-tiles/examples/board-deck.js +695 -0
  50. package/skills/farseer-code-tiles/examples/data-checks.js +475 -0
  51. package/skills/farseer-code-tiles/examples/kpi-cards.js +374 -0
  52. package/skills/farseer-code-tiles/examples/map-countries.js +377 -0
  53. package/skills/farseer-code-tiles/examples/month-plan.js +443 -0
  54. package/skills/farseer-code-tiles/examples/new-location.js +581 -0
  55. package/skills/farseer-code-tiles/examples/open-forecast.js +598 -0
  56. package/skills/farseer-code-tiles/examples/pl-sankey.js +402 -0
  57. package/skills/farseer-code-tiles/examples/ranked-bars.js +337 -0
  58. package/skills/farseer-code-tiles/examples/request-form.js +464 -0
  59. package/skills/farseer-code-tiles/farseer-table.md +98 -0
  60. package/skills/farseer-code-tiles/known-mistakes.md +178 -0
  61. package/skills/farseer-code-tiles/maps/europe.geo.json +1 -0
  62. package/skills/farseer-code-tiles/maps/pick-map.mjs +59 -0
  63. package/skills/farseer-code-tiles/maps/world.geo.json +1 -0
  64. package/skills/farseer-dashboards/SKILL.md +3 -2
  65. package/skills/farseer-dashboards/check.md +3 -2
  66. package/skills/farseer-dashboards/measures.md +3 -1
  67. package/skills/farseer-optimize-model/SKILL.md +9 -1
  68. package/skills/farseer-pnl/SKILL.md +3 -3
  69. package/skills/pipeline-authoring/SKILL.md +2 -2
@@ -0,0 +1,475 @@
1
+ // Data checks: the controls a controller runs before reporting a month, each a difference two parts of the model must
2
+ // keep at zero (the balance sheet balances, its result is the P&L's net profit, cash ties out, the P&L's sales are the sales
3
+ // plan, every company's P&L is loaded), month by month for the version the filter bar picks. Reads only; it writes nothing.
4
+ // Tile size: w36 h11.
5
+ // Tile size: w24 h10; w14 h15 when narrow.
6
+ export default function (ctx) {
7
+ // readTable: a table of numbers from the model, in the shape ctx.charts.farseer draws
8
+ // ({ columns: [{ label, numberFormat }], rows: [{ label, cells: [{ value }] }] }). Call it in the body.
9
+ // rows: { table: 'Entity' } every member of a table, listed live by name
10
+ // rows: { table, includeDashboardFilters: true } the members the filter bar leaves, even when the numbers ignore it
11
+ // rows: { table: 'Months', members: ['M1', …] } the members named here, in this order
12
+ // rows: [{ label, formula, numberFormat }] one line per formula (a P&L)
13
+ // no rows one row, labelled '', for KPIs
14
+ // columns: [{ label, formula, numberFormat }] with member rows, [{ label, filter }] with formula lines
15
+ // Member rows and every number follow the filter bar and timeline, unless the spec turns them off.
16
+ const quote = (name) => `"${String(name).replace(/(["\\])/g, '\\$1')}"`;
17
+ // a table's members from a DTABLE answer, by name, without its NULL member
18
+ const namesOf = (answer) => (answer?.value ?? []).map(String).filter((name) => !name.startsWith('NULL ('));
19
+ function withFilter(formula, filter) {
20
+ let out = '', depth = [], quoted = false;
21
+ for (let i = 0; i < formula.length; i++) {
22
+ const c = formula[i];
23
+ if (c === '"' && formula[i - 1] !== '\\') quoted = !quoted;
24
+ if (!quoted && c === '(') depth.push(/sum\s*$/i.test(formula.slice(0, i)));
25
+ if (!quoted && c === ')' && depth.pop()) out += `, ${filter}`;
26
+ out += c;
27
+ }
28
+ return out;
29
+ }
30
+ function readTable(spec) {
31
+ // includeDashboardFilters: false / includeDashboardTimeline: false in the spec leave one out (say so on the tile)
32
+ const options = { includeDashboardFilters: spec.includeDashboardFilters !== false, includeDashboardTimeline: spec.includeDashboardTimeline !== false };
33
+ const { columns } = spec;
34
+ const rows = spec.rows ?? [{ label: '' }];
35
+ const memberRows = !Array.isArray(rows);
36
+ const listOptions = { ...options, ...(memberRows && rows.includeDashboardFilters !== undefined ? { includeDashboardFilters: rows.includeDashboardFilters } : {}) };
37
+ const list = memberRows && !rows.members ? ctx.query([{ type: 'DTABLE', table: rows.table }], listOptions) : null;
38
+ let names = memberRows ? rows.members ?? null : null;
39
+ let listed = null;
40
+ let values = null;
41
+ const open = () => {
42
+ values?.close();
43
+ const formulas = memberRows
44
+ ? names.flatMap((name) => columns.map((c) => withFilter(c.formula, `${quote(rows.table)}>${quote(name)}`)))
45
+ : rows.flatMap((r) => columns.map((c) => (r.formula ? withFilter(r.formula, c.filter) : c.formula)));
46
+ values = formulas.length ? ctx.query(formulas.map((formula) => ({ type: 'VARIABLE', formula })), options) : null;
47
+ };
48
+ if (!list) open();
49
+ const refresh = () => {
50
+ if (list.loading && !list.current.length) return;
51
+ const now = namesOf(list.current[0]);
52
+ const key = now.join('\u0001');
53
+ if (key !== listed) {
54
+ listed = key;
55
+ names = now;
56
+ open();
57
+ }
58
+ };
59
+ return {
60
+ get loading() {
61
+ if (list) refresh();
62
+ return (list?.loading ?? false) || (values?.loading ?? false);
63
+ },
64
+ get error() {
65
+ return list?.error ?? values?.error ?? null;
66
+ },
67
+ get current() {
68
+ if (list) refresh();
69
+ const cells = values?.current ?? [];
70
+ const labels = memberRows ? names ?? [] : rows.map((r) => r.label);
71
+ return {
72
+ columns: columns.map((c) => ({ label: c.label, numberFormat: c.numberFormat ?? (memberRows ? null : rows[0]?.numberFormat) ?? null })),
73
+ rows: labels.map((label, j) => ({
74
+ label,
75
+ numberFormat: memberRows ? null : rows[j].numberFormat ?? null,
76
+ cells: columns.map((_, i) => ({ value: cells[j * columns.length + i]?.value ?? null })),
77
+ })),
78
+ };
79
+ },
80
+ };
81
+ }
82
+ // picks(['Entity', 'Year to date']): what the filter bar picked on these tables, for a title or a form.
83
+ // current.Entity is { members: ['Acme Croatia'], all: false }; all is true when the bar doesn't narrow that table.
84
+ function picks(tables) {
85
+ const picked = ctx.query(tables.map((table) => ({ type: 'DTABLE', table })));
86
+ const every = ctx.query(tables.map((table) => ({ type: 'DTABLE', table })), { includeDashboardFilters: false, includeDashboardTimeline: false });
87
+ return {
88
+ get loading() {
89
+ return picked.loading || every.loading;
90
+ },
91
+ get error() {
92
+ return picked.error ?? every.error ?? null;
93
+ },
94
+ get current() {
95
+ return Object.fromEntries(tables.map((table, i) => {
96
+ const members = namesOf(picked.current[i]);
97
+ return [table, { members, all: members.length === namesOf(every.current[i]).length }];
98
+ }));
99
+ },
100
+ };
101
+ }
102
+ // what the filter bar picked, for the title and the form
103
+ // what the filter bar picked: the version the checks run on, and the company or companies
104
+ const bar = picks(['Versions', 'Entity']);
105
+ // --- Data checks: the controls a controller runs before a month is reported, each a difference the model should
106
+ // keep at zero, month by month for the version and companies the filter bar picks. 2026.
107
+ const YEAR = '"Years">"Y2026"';
108
+ const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
109
+ const TOLERANCE = 0.5; // EUR: rounding in the source systems, not a difference anyone acts on
110
+ // each check is a difference between two places that must agree, and what to look at when it doesn't
111
+ // each check compares two sides that must agree; its difference is the left side less the right one
112
+ const CHECKS = [
113
+ { label: 'Balance sheet balances', where: 'Total assets less equity and liabilities',
114
+ sides: (m) => [`sum("Total assets", ${YEAR}, "Months">"${m}")`, `sum("Total equity and liabilities", ${YEAR}, "Months">"${m}")`] },
115
+ { label: 'Result in the balance sheet = P&L net profit', where: 'BS line Current-year result less net profit, year to date',
116
+ sides: (m) => [`sum("IMPORT_Balance_sheet", "BS line">"Current-year result", ${YEAR}, "Months">"${m}")`, `sum("Net profit", ${YEAR}, "Year to date">"${m}")`] },
117
+ { label: 'Cash in the balance sheet = closing cash', where: 'Closing cash less BS line Cash and cash equivalents',
118
+ sides: (m) => [`sum("IMPORT_Closing_cash", ${YEAR}, "Months">"${m}")`, `sum("IMPORT_Balance_sheet", "BS line">"Cash and cash equivalents", ${YEAR}, "Months">"${m}")`] },
119
+ { label: 'Cash flow closes', where: 'Opening cash plus net cash flow less closing cash',
120
+ sides: (m) => [`sum("IMPORT_Opening_cash", ${YEAR}, "Months">"${m}") + sum("IMPORT_Cash_flow", ${YEAR}, "Months">"${m}")`, `sum("IMPORT_Closing_cash", ${YEAR}, "Months">"${m}")`] },
121
+ { label: 'Net sales in the P&L = sales plan', where: 'P&L line Net sales less the sales submodel (IMPORT_Net_sales)',
122
+ sides: (m) => [`sum("IMPORT_PnL", "P&L line">"Net sales", ${YEAR}, "Months">"${m}")`, `sum("IMPORT_Net_sales", ${YEAR}, "Months">"${m}")`] },
123
+ ];
124
+ const MONTH_IDS = MONTHS.map((_, i) => `M${i + 1}`);
125
+ // every difference, and whether the month holds a P&L at all (a check in an empty month is not a pass)
126
+ // every difference, both sides of it (a side with no number is "not loaded", never a pass), and whether the month
127
+ // holds a P&L at all
128
+ const diffs = ctx.query([
129
+ ...CHECKS.flatMap((c) => MONTH_IDS.map((m) => ({ type: 'VARIABLE', formula: `${c.sides(m)[0]} - ${c.sides(m)[1]}` }))),
130
+ ...MONTH_IDS.map((m) => ({ type: 'VARIABLE', formula: `sum("IMPORT_PnL", ${YEAR}, "Months">"${m}")` })),
131
+ ...CHECKS.flatMap((c) => MONTH_IDS.flatMap((m) => c.sides(m).map((formula) => ({ type: 'VARIABLE', formula })))),
132
+ ], { includeDashboardTimeline: false });
133
+ // which companies have their P&L loaded, month by month
134
+ const loaded = readTable({
135
+ includeDashboardTimeline: false,
136
+ rows: { table: 'Entity' },
137
+ columns: MONTH_IDS.map((m, i) => ({ label: MONTHS[i], formula: `sum("IMPORT_PnL", ${YEAR}, "Months">"${m}")` })),
138
+ });
139
+ // --- The Farseer look (echarts-look.md, design.md): the same block in every tile ---
140
+ // AC: the dashboards' AC colour (SKILL.md section 2, The AC colour): #323232, or the company's
141
+ // darkest brand colour when it is dark enough, never an example's. AC_LIGHT is its PY tint.
142
+ // Everything else below is derived from them, so nothing else needs changing.
143
+ const AC = '#323232';
144
+ const AC_LIGHT = '#A6A6A6';
145
+ // mixes a colour with white: share 1 is the colour itself, 0 is white
146
+ function tint(hex, share) {
147
+ const n = parseInt(hex.slice(1), 16);
148
+ const mix = (c) => Math.round(c * share + 255 * (1 - share)).toString(16).padStart(2, '0');
149
+ return `#${mix(n >> 16)}${mix((n >> 8) & 255)}${mix(n & 255)}`.toUpperCase();
150
+ }
151
+ // a colour with almost no hue (graphite, grey): its ramp would turn a map grey, so magnitude takes Farseer blue
152
+ const isGrey = (hex) => { const n = parseInt(hex.slice(1), 16); const c = [n >> 16, (n >> 8) & 255, n & 255]; return Math.max(...c) - Math.min(...c) < 24; };
153
+ const PALETTE = [AC, '#ED7D16', '#1BB5D7', '#8A2FE5', '#BFA812', '#E52FCD']; // identity: AC first, then distinct hues
154
+ const FILL = [AC_LIGHT, '#F5B87F', '#82D6E9', '#BF8DF1', '#DCCF7D', '#F18DE4']; // the light step, for large areas
155
+ // magnitude (maps, heatmaps), light to dark: steps of AC, or Farseer blue when AC is a grey
156
+ const RAMP = isGrey(AC) ? ['#81A9FF', '#457DFF', '#0D4BC2', '#043288'] : [0.45, 0.65, 0.8, 1].map((s) => tint(AC, s));
157
+ // light tints of AC for large areas that need ink text (treemap groups), clearly apart from each other
158
+ // (from Farseer blue when AC is a grey, as the ramp: grey tints would make a grey block)
159
+ const TINTS = [0.52, 0.37, 0.24, 0.11].map((s) => tint(isGrey(AC) ? '#043288' : AC, s));
160
+ const TRACK = tint(AC, 0.12); // the unfilled part of a gauge
161
+ const PRIMARY = '#1A66FF'; // Farseer's own primary button, not a data colour
162
+ const GOOD = '#0CB955';
163
+ const BAD = '#E21E09';
164
+ const INK = () => ctx.theme.tokens?.text ?? '#020810';
165
+ const MUTED = () => ctx.theme.tokens?.muted ?? '#687C95';
166
+ const LINE = () => ctx.theme.tokens?.border ?? '#E6EBF2';
167
+ const SURFACE = () => ctx.theme.tokens?.background ?? '#FFFFFF';
168
+ const FONT = 'Inter, system-ui, sans-serif';
169
+ let drawnOnce = false;
170
+ // draws one echarts chart in the look; the first chart that draws ends the entrance animation for the rest
171
+ function drawChart(element, option) {
172
+ ctx.charts.echarts(element, option);
173
+ drawnOnce = true;
174
+ }
175
+ // the chart tile's look, measured from it: square bars, 12 px ink labels with a surface-coloured halo, an ink
176
+ // category axis with ticks, no value axis or gridlines, the legend at the bottom, its tooltip and margins
177
+ const LABEL = { show: true, fontFamily: FONT, fontSize: 12, color: INK(), textBorderColor: SURFACE(), textBorderWidth: 4 };
178
+ function look() {
179
+ return {
180
+ animation: !drawnOnce,
181
+ animationDuration: 500,
182
+ textStyle: { fontFamily: FONT, fontSize: 12, color: INK() },
183
+ grid: { left: 10, right: 10, top: 20, bottom: 10, containLabel: true },
184
+ legend: { bottom: 0, textStyle: { fontFamily: FONT, color: INK() } },
185
+ tooltip: {
186
+ trigger: 'item', confine: true, backgroundColor: SURFACE(), borderColor: '#EDF2F7', borderWidth: 1,
187
+ padding: [6, 10], textStyle: { color: INK(), fontSize: 12, fontFamily: FONT },
188
+ extraCssText: 'border-radius:6px;box-shadow:0 4px 16px rgba(107,131,160,0.15)',
189
+ },
190
+ categoryAxis: {
191
+ axisLine: { show: true, lineStyle: { color: INK(), width: 1 } },
192
+ axisTick: { show: false },
193
+ axisLabel: { color: INK(), fontFamily: FONT, fontSize: 12, hideOverlap: true },
194
+ splitLine: { show: false },
195
+ },
196
+ valueAxis: { show: false, splitLine: { show: false } },
197
+ };
198
+ }
199
+ function merge(base, extra) {
200
+ if (Array.isArray(extra) || typeof extra !== 'object' || extra === null) return extra;
201
+ const out = { ...base };
202
+ for (const [key, value] of Object.entries(extra)) {
203
+ out[key] = typeof value === 'object' && value !== null && !Array.isArray(value) && typeof base?.[key] === 'object' ? merge(base[key], value) : value;
204
+ }
205
+ return out;
206
+ }
207
+ // form controls and buttons in Farseer's toolbar look: 28 px high, 12 px text, the focus ring drawn inside the
208
+ // control (so a control at the tile's edge never loses it), button text that never wraps, a long choice ending in …
209
+ // Farseer's own form controls and buttons (the app's input, select and button), the same in every tile
210
+ const CONTROL_CSS = `
211
+ .fs-control { font: 400 12px/20px ${FONT}; height: 32px; padding: 0 8px; border: 1px solid #EDF2F7; border-radius: 8px;
212
+ background-color: #EDF2F7; color: var(--code-tile-text); min-width: 0; max-width: 100%; box-sizing: border-box; outline: none;
213
+ overflow: hidden; white-space: nowrap; text-overflow: ellipsis; transition: border-color 100ms; }
214
+ select.fs-control { appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
215
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23020810' fill-rule='evenodd' d='M4.17 6.124a.5.5 0 01.706.047L8 9.74l3.124-3.57a.5.5 0 01.752.658l-3.5 4a.5.5 0 01-.752 0l-3.5-4a.5.5 0 01.047-.705z'/%3E%3C/svg%3E");
216
+ background-repeat: no-repeat; background-position: right 8px center; background-size: 16px 16px; }
217
+ .fs-control:hover { border-color: #C1CEDE; }
218
+ .fs-control:focus, .fs-control:focus-visible { border-color: #1966FF; outline: 1px solid #1966FF; outline-offset: 0; }
219
+ .fs-control.fs-empty, .fs-control::placeholder { color: var(--code-tile-muted); }
220
+ .fs-control:disabled { background-color: var(--code-tile-background); color: var(--code-tile-muted); cursor: not-allowed; }
221
+ .fs-button { font: 500 12px/14px ${FONT}; height: 32px; min-width: 32px; padding: 0 12px; white-space: nowrap; flex: none; border: none;
222
+ border-radius: 8px; cursor: pointer; background-color: #1966FF; color: #FFFFFF; transition: background-color 100ms, color 100ms; }
223
+ .fs-button:hover { background-color: #0942B2; }
224
+ .fs-button.fs-secondary { background-color: #E8F0FF; color: #1966FF; }
225
+ .fs-button.fs-secondary:hover { background-color: #C5D9FF; }
226
+ .fs-button.fs-tertiary { background-color: transparent; color: var(--code-tile-text); font-weight: 400; box-shadow: 0 0 0 1px var(--code-tile-border) inset; }
227
+ .fs-button.fs-tertiary:hover { background-color: #EDF2F7; }
228
+ .fs-button:disabled, .fs-button:disabled:hover { background-color: var(--code-tile-border); color: var(--code-tile-muted); box-shadow: none; cursor: not-allowed; }
229
+ .fs-button:focus-visible { outline: 1px solid var(--code-tile-text); outline-offset: 1px; }
230
+ .fs-button { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
231
+ .fs-chevron { width: 16px; height: 16px; flex: none; background-color: currentColor; -webkit-mask: center / 16px no-repeat; mask: center / 16px no-repeat; }
232
+ .fs-chevron-left { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M10.376 4.67a.5.5 0 01-.047.706L6.76 8.5l3.57 3.124a.5.5 0 11-.658.752l-4-3.5a.5.5 0 010-.752l4-3.5a.5.5 0 01.705.047z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M10.376 4.67a.5.5 0 01-.047.706L6.76 8.5l3.57 3.124a.5.5 0 11-.658.752l-4-3.5a.5.5 0 010-.752l4-3.5a.5.5 0 01.705.047z'/%3E%3C/svg%3E"); }
233
+ .fs-chevron-right { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M5.624 12.33a.5.5 0 01.047-.706L9.24 8.5 5.67 5.376a.5.5 0 11.658-.752l4 3.5a.5.5 0 010 .752l-4 3.5a.5.5 0 01-.705-.047z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M5.624 12.33a.5.5 0 01.047-.706L9.24 8.5 5.67 5.376a.5.5 0 11.658-.752l4 3.5a.5.5 0 010 .752l-4 3.5a.5.5 0 01-.705-.047z'/%3E%3C/svg%3E"); }
234
+ .fs-button.fs-icon-only { padding: 0; width: 32px; }`;
235
+ function control(tag, className = 'fs-control') {
236
+ if (!document.getElementById('fs-control-style')) {
237
+ const style = document.createElement('style');
238
+ style.id = 'fs-control-style';
239
+ style.textContent = CONTROL_CSS;
240
+ document.head.append(style);
241
+ }
242
+ const node = document.createElement(tag);
243
+ node.className = className;
244
+ return node;
245
+ }
246
+ // Farseer's table look (farseer-table.md): the same font, row height, header and rules as a table tile
247
+ const TABLE_CSS = `
248
+ .fs-table-wrap { width: fit-content; max-width: 100%; overflow: hidden; }
249
+ .fs-table { width: max-content; max-width: calc(100% + 12px); border-collapse: separate; border-spacing: 12px 0; margin: 0 0 0 -12px; font: 12px/1.2 ${FONT}; color: var(--code-tile-text); font-variant-numeric: tabular-nums; }
250
+ .fs-table th { height: 24px; padding: 0 0 5px; font-weight: 400; text-align: right; vertical-align: bottom; white-space: nowrap; background: linear-gradient(var(--code-tile-text), var(--code-tile-text)) bottom / 100% 1px no-repeat; }
251
+ .fs-table td { height: 24px; padding: 0; text-align: right; white-space: nowrap; background: linear-gradient(var(--code-tile-border), var(--code-tile-border)) bottom / 100% 1px no-repeat; }
252
+ .fs-table th:first-child, .fs-table td:first-child { text-align: left; }
253
+ .fs-table td:first-child { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
254
+ .fs-table tr.fs-total td { font-weight: 700; background-image: linear-gradient(var(--code-tile-text), var(--code-tile-text)); }
255
+ .fs-table tbody tr:hover td { background-color: color-mix(in srgb, var(--code-tile-muted) 8%, transparent); }
256
+ .fs-table .fs-good { color: ${GOOD}; } .fs-table .fs-bad { color: ${BAD}; } .fs-table .fs-muted { color: var(--code-tile-muted); }
257
+ .fs-table .fs-key { display: inline-block; width: 8px; height: 8px; margin-right: 8px; vertical-align: 0; }
258
+ .fs-table th.fs-AC, .fs-table tr:last-child td.fs-AC { background: linear-gradient(${AC}, ${AC}) bottom / 100% 3px no-repeat; }
259
+ .fs-table th.fs-PY, .fs-table tr:last-child td.fs-PY { background: linear-gradient(${AC_LIGHT}, ${AC_LIGHT}) bottom / 100% 3px no-repeat; }
260
+ .fs-table th.fs-PL, .fs-table tr:last-child td.fs-PL { background: linear-gradient(${AC}, ${AC}) bottom / 100% 1px no-repeat, linear-gradient(${AC}, ${AC}) 0 calc(100% - 3px) / 100% 1px no-repeat; }
261
+ .fs-table th.fs-FC, .fs-table tr:last-child td.fs-FC { background: repeating-linear-gradient(90deg, ${AC} 0 3px, transparent 3px 5px) bottom / 100% 3px no-repeat; }`;
262
+ function farseerTable(head, rows) {
263
+ // head: [{ label, key?, scenario?: 'AC' | 'PL' | 'PY' | 'FC' }] (a scenario column gets the table tile's rule
264
+ // under its header and its last row: AC thick, PL double, PY light, FC dotted);
265
+ // rows: [{ cells: [text or node, …], total?, tone?: [null | 'good' | 'bad' | 'muted', …] }]
266
+ if (!document.getElementById('fs-table-style')) {
267
+ const style = document.createElement('style');
268
+ style.id = 'fs-table-style';
269
+ style.textContent = TABLE_CSS;
270
+ document.head.append(style);
271
+ }
272
+ const table = el('table');
273
+ table.className = 'fs-table';
274
+ const tr = table.createTHead().insertRow();
275
+ for (const h of head) {
276
+ const th = el('th');
277
+ if (h.scenario) th.className = `fs-${h.scenario}`;
278
+ if (h.key) th.append(h.key);
279
+ th.append(h.label);
280
+ tr.append(th);
281
+ }
282
+ const body = table.createTBody();
283
+ for (const row of rows) {
284
+ const line = body.insertRow();
285
+ if (row.total) line.className = 'fs-total';
286
+ row.cells.forEach((cell, i) => {
287
+ const td = line.insertCell();
288
+ const classes = [row.tone?.[i] ? `fs-${row.tone[i]}` : '', head[i]?.scenario ? `fs-${head[i].scenario}` : ''].filter(Boolean);
289
+ if (classes.length) td.className = classes.join(' ');
290
+ if (cell instanceof Node) td.append(cell);
291
+ else td.textContent = cell ?? '';
292
+ if (i === 0 && typeof cell === 'string') td.title = cell;
293
+ });
294
+ }
295
+ // the first column gap reaches 12 px past the left edge, so the text lines up with the title; a clipping box keeps it inside the tile
296
+ const box = el('div');
297
+ box.className = 'fs-table-wrap';
298
+ box.append(table);
299
+ return box;
300
+ }
301
+ // a variance number in a table, as the table tile shows it: red when it hurts, ink when it helps
302
+ const tone = (delta, costLine) => (delta === null || delta === undefined ? 'muted' : (costLine ? delta > 0 : delta < 0) ? 'bad' : null);
303
+ // small HTML helpers for titles, notes and states, all in the theme's ink
304
+ function el(tag, css, text) {
305
+ const node = document.createElement(tag);
306
+ if (css) node.style.cssText = css;
307
+ if (text !== undefined) node.textContent = text;
308
+ return node;
309
+ }
310
+ // the tile header exactly as Farseer draws a chart or table tile's name: 12 px ink, regular, 10 px above the content;
311
+ // a note under it in the footnote style (11 px muted). The frame already sits inside the card's 8 px padding, so the
312
+ // tile's own content has no outer padding of its own
313
+ const TITLE = 'font-size:12px;font-weight:400;line-height:1.25;color:var(--code-tile-text)';
314
+ const NOTE = 'font-size:11px;line-height:1.35;color:var(--code-tile-muted)'; // footnotes and units only
315
+ const PAGE = 'display:grid;gap:10px;height:100%;padding:0;align-content:start';
316
+ const MESSAGE = 'display:grid;place-items:center;height:100%;font-size:13px;color:var(--code-tile-muted)';
317
+ // one title line, the way Farseer names tiles ("Net sales by region, year to date (kEUR)"); the scope only when the
318
+ // filter bar narrows it. A note the reader needs goes to the bottom in the footnote style, never under the title
319
+ // a value that rounds to zero carries no sign: "-0,0%" and "+0" become "0,0%" and "0"
320
+ const unsigned0 = (text) => String(text).replace(/^[+\-−](?=0(?:[.,]0+)?(?:\s?%|\s?pp)?$)/, '');
321
+ function heading(wrap, title) {
322
+ wrap.append(el('div', TITLE, title));
323
+ }
324
+ function footnote(wrap, text) {
325
+ wrap.append(el('div', `${NOTE};padding-top:2px`, text));
326
+ }
327
+ // the scope the filter bar sets, for titles: nothing for the whole group, the company, or "2 companies"
328
+ // (bar is the picks() the body opened for the tables a title names)
329
+ function scope(table, all, one) {
330
+ const pick = bar.current[table];
331
+ if (!pick || pick.all) return all;
332
+ if (pick.members.length === 1) return pick.members[0];
333
+ return `${pick.members.length} ${one}`;
334
+ }
335
+ function period() {
336
+ const ytd = bar.current['Year to date'];
337
+ const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
338
+ if (!ytd || ytd.all || ytd.members.length !== 1) return 'year to date';
339
+ const m = Number(ytd.members[0].replace('M', ''));
340
+ return m === 1 ? 'January' : `January to ${MONTHS[m - 1]}`;
341
+ }
342
+ // --- end of the look ---
343
+ // Farseer's own icons (Tick, Close, CircledQuestionMark), drawn by CSS so the tile makes no SVG by hand
344
+ const ICON = {
345
+ tick: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M12.852 4.902a.542.542 0 000-.744.502.502 0 00-.73 0L6.088 10.49l-2.21-2.32a.502.502 0 00-.73 0 .542.542 0 000 .744L6.088 12l6.764-7.098z'/%3E%3C/svg%3E")`,
346
+ close: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8.20711 8.5L11.7929 12.0858C11.9882 12.281 12.3047 12.281 12.5 12.0858C12.6953 11.8905 12.6953 11.5739 12.5 11.3787L8.91421 7.79289L12.5 4.20711C12.6953 4.01184 12.6953 3.69526 12.5 3.5C12.3047 3.30474 11.9882 3.30474 11.7929 3.5L8.20711 7.08579L4.62132 3.5C4.42606 3.30474 4.10947 3.30474 3.91421 3.5C3.71895 3.69526 3.71895 4.01185 3.91421 4.20711L7.5 7.79289L3.91421 11.3787C3.71895 11.5739 3.71895 11.8905 3.91421 12.0858C4.10947 12.281 4.42606 12.281 4.62132 12.0858L8.20711 8.5Z'/%3E%3C/svg%3E")`,
347
+ help: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M14 8A6 6 0 112 8a6 6 0 0112 0zm1 0A7 7 0 111 8a7 7 0 0114 0zm-7.554 2.153v.052h1.02v-.052a3.5 3.5 0 01.11-.89c.069-.239.178-.444.328-.616.15-.175.35-.341.6-.499.249-.155.461-.333.637-.533.179-.201.315-.43.408-.684.097-.256.145-.541.145-.856a2.33 2.33 0 00-.306-1.196 2.142 2.142 0 00-.86-.826c-.368-.201-.801-.302-1.3-.302-.46 0-.877.092-1.254.276a2.261 2.261 0 00-.906.796c-.227.347-.351.764-.374 1.252h1.071c.023-.339.107-.613.251-.822.145-.21.325-.363.54-.46.216-.098.44-.147.672-.147.266 0 .509.056.727.168.218.112.393.271.523.478.13.206.195.45.195.73a1.629 1.629 0 01-.434 1.114c-.132.142-.283.264-.45.367-.278.169-.516.354-.714.555-.199.2-.352.463-.46.787-.107.324-.164.76-.17 1.308zm.004 2.37c.15.152.33.228.54.228.142 0 .27-.034.382-.103a.8.8 0 00.383-.671.75.75 0 00-.225-.546.732.732 0 00-.54-.228c-.21 0-.39.076-.54.228a.75.75 0 00-.226.546.75.75 0 00.226.546z'/%3E%3C/svg%3E")`,
348
+ };
349
+ const CHECK_CSS = `
350
+ .ck-icon { display: inline-block; width: 16px; height: 16px; vertical-align: -3px; -webkit-mask: center / 16px no-repeat; mask: center / 16px no-repeat; }
351
+ .ck-tick { background-color: var(--code-tile-text); -webkit-mask-image: ${ICON.tick}; mask-image: ${ICON.tick}; }
352
+ .ck-close { background-color: ${BAD}; -webkit-mask-image: ${ICON.close}; mask-image: ${ICON.close}; cursor: default; }
353
+ .ck-help { width: 14px; height: 14px; -webkit-mask-size: 14px; mask-size: 14px; margin-left: 4px; background-color: var(--code-tile-muted); -webkit-mask-image: ${ICON.help}; mask-image: ${ICON.help}; cursor: help; }
354
+ .ck-summary { font-size: 12px; color: var(--code-tile-text); }
355
+ .ck-grid { position: relative; }
356
+ .ck-grid .fs-table td { text-align: center; }
357
+ .ck-grid .fs-table th:not(:first-child) { text-align: center; }
358
+ .ck-grid .fs-table td:first-child { text-align: left; max-width: none; }
359
+ .ck-tip { position: absolute; z-index: 2; pointer-events: none; white-space: nowrap; font: 12px/1.3 ${FONT}; color: var(--code-tile-text);
360
+ background: var(--code-tile-background); border: 1px solid #EDF2F7; border-radius: 6px; padding: 6px 10px;
361
+ box-shadow: 0 4px 16px rgba(107, 131, 160, 0.15); }`;
362
+ function style() {
363
+ if (document.getElementById('ck-style')) return;
364
+ const node = document.createElement('style');
365
+ node.id = 'ck-style';
366
+ node.textContent = CHECK_CSS;
367
+ document.head.append(node);
368
+ }
369
+ // an icon that says what it means to a screen reader, and shows a tooltip on hover when it has one
370
+ function icon(kind, label, tip) {
371
+ const node = el('span');
372
+ node.className = `ck-icon ck-${kind}`;
373
+ node.setAttribute('role', 'img');
374
+ node.setAttribute('aria-label', tip ?? label);
375
+ if (tip) node.dataset.tip = tip;
376
+ return node;
377
+ }
378
+ // a muted dash for a check that can't be judged, with why on hover
379
+ function dash(tip) {
380
+ const node = el('span', 'color:var(--code-tile-muted);cursor:default', '–');
381
+ node.setAttribute('aria-label', tip);
382
+ node.dataset.tip = tip;
383
+ return node;
384
+ }
385
+ // Farseer's tooltip, one per grid: shown under the icon the pointer is on
386
+ function tooltips(box) {
387
+ const tip = el('div');
388
+ tip.className = 'ck-tip';
389
+ tip.hidden = true;
390
+ box.append(tip);
391
+ box.addEventListener('mouseover', (event) => {
392
+ const target = event.target.closest?.('[data-tip]');
393
+ if (!target) return void (tip.hidden = true);
394
+ tip.textContent = target.dataset.tip;
395
+ tip.hidden = false;
396
+ const at = target.getBoundingClientRect();
397
+ const origin = box.getBoundingClientRect();
398
+ const left = Math.min(at.left - origin.left, box.clientWidth - tip.offsetWidth);
399
+ tip.style.left = `${Math.max(0, left)}px`;
400
+ tip.style.top = `${at.bottom - origin.top + 6}px`;
401
+ }, { signal: ctx.signal });
402
+ box.addEventListener('mouseleave', () => (tip.hidden = true), { signal: ctx.signal });
403
+ }
404
+
405
+ return (element) => {
406
+ style();
407
+ ctx.loading(diffs.loading && !diffs.current.length);
408
+ const wrap = el('div', PAGE);
409
+ const version = bar.current.Versions;
410
+ const one = version && !version.all && version.members.length === 1 ? version.members[0] : null;
411
+ heading(wrap, `Data checks${one ? `, ${one}` : ''}, ${scope('Entity', 'whole group', 'companies')}, 2026 (EUR)`);
412
+ if (!one) {
413
+ wrap.append(el('div', 'font-size:13px;color:var(--code-tile-muted)', bar.loading ? '' : 'Pick one version in the filter bar to check it.'));
414
+ element.replaceChildren(wrap);
415
+ return;
416
+ }
417
+ const values = diffs.current.map((d) => d.value);
418
+ const holds = MONTH_IDS.map((_, i) => values[CHECKS.length * 12 + i] !== null && values[CHECKS.length * 12 + i] !== undefined);
419
+ const months = MONTH_IDS.map((_, i) => i).filter((i) => holds[i]);
420
+ // a check fails in a month when its difference is beyond the tolerance
421
+ // both sides of check k in month i; a check with a side missing is not loaded, neither a pass nor a failure
422
+ const SIDES = CHECKS.length * 12 + 12;
423
+ const loadedBoth = (k, i) => [0, 1].every((side) => {
424
+ const v = values[SIDES + (k * 12 + i) * 2 + side];
425
+ return v !== null && v !== undefined;
426
+ });
427
+ const failing = CHECKS.map((c, k) => months.filter((i) => loadedBoth(k, i) && Math.abs(values[k * 12 + i] ?? 0) >= TOLERANCE));
428
+ const broken = failing.filter((f) => f.length).length;
429
+ // checks that can't be judged in some month, because one of their sides isn't loaded
430
+ const unjudged = CHECKS.filter((c, k) => months.some((i) => !loadedBoth(k, i))).length;
431
+ const span = months.length ? `${MONTHS[months[0]]} to ${MONTHS[months[months.length - 1]]}` : '';
432
+ const notLoaded = unjudged ? ` ${unjudged} of ${CHECKS.length} can't be judged in some months: a dash means one side isn't loaded.` : '';
433
+ const summary = el('div');
434
+ summary.className = 'ck-summary';
435
+ summary.textContent = !months.length
436
+ ? `${one} holds no P&L for 2026 yet.`
437
+ : broken
438
+ ? `${broken} of ${CHECKS.length} checks ${broken === 1 ? 'fails' : 'fail'} in ${span}. Point at a cross for the difference.${notLoaded}`
439
+ : unjudged
440
+ ? `No check fails in ${span}, but${notLoaded.replace(/^ /, ' ')}`
441
+ : `All ${CHECKS.length} checks agree in every month from ${span}.`;
442
+ wrap.append(summary);
443
+
444
+ // the grid: one row per check, one column per month with data; a tick where it agrees, the difference where not
445
+ const head = [{ label: 'Check' }, ...months.map((i) => ({ label: MONTHS[i] }))];
446
+ const nameOf = (label, where) => {
447
+ const name = el('span', 'white-space:nowrap', label);
448
+ name.append(icon('help', label, where));
449
+ return name;
450
+ };
451
+ const rows = CHECKS.map((c, k) => ({
452
+ cells: [nameOf(c.label, c.where), ...months.map((i) => {
453
+ const d = values[k * 12 + i];
454
+ if (!loadedBoth(k, i)) return dash(`${MONTHS[i]}: not loaded, one side of this check has no numbers`);
455
+ return Math.abs(d ?? 0) < TOLERANCE
456
+ ? icon('tick', 'agrees')
457
+ : icon('close', 'differs', `${MONTHS[i]}: off by ${ctx.format(d, '+#,##0;-#,##0')} EUR`);
458
+ })],
459
+ }));
460
+ // the P&L loaded for every company the filter bar leaves
461
+ const companies = loaded.current.rows;
462
+ const missing = months.map((i) => companies.filter((r) => r.cells[loaded.current.columns.findIndex((col) => col.label === MONTHS[i])]?.value === null));
463
+ rows.push({
464
+ cells: [nameOf('P&L loaded for every company', 'Every company has a P&L in the month'),
465
+ ...missing.map((list, j) => (list.length ? icon('close', 'missing', `${MONTHS[months[j]]}: no P&L for ${list.map((r) => r.label).join(', ')}`) : icon('tick', 'loaded')))],
466
+ });
467
+ const grid = el('div');
468
+ grid.className = 'ck-grid';
469
+ grid.append(farseerTable(head, rows));
470
+ tooltips(grid);
471
+ wrap.append(grid);
472
+ footnote(wrap, `A difference under ${ctx.format(TOLERANCE, '0.0')} EUR counts as agreeing; a dash means one side isn't loaded. Months with no P&L in ${one} are left out.`);
473
+ element.replaceChildren(wrap);
474
+ };
475
+ }