@umriss-ui/calculation 0.43.0 → 0.45.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.
@@ -1,104 +1,121 @@
1
1
  "use client";
2
2
  import "./calculation.css";
3
- import { jsx as c, jsxs as O } from "react/jsx-runtime";
4
- import { useId as Ce, useState as ae, useRef as ke, useCallback as me, useLayoutEffect as ye, useEffect as Ae } from "react";
5
- import { assess as Me, verdictWeight as X, useDensityFor as Be, useFormats as _e, useWording as be, VisuallyHidden as Te, AngleGlyph as Ee, Badge as se, useFreshness as Le, Tooltip as Re } from "@umriss-ui/core";
6
- import { p as We } from "./calculation.model-CZuohgrp.js";
7
- function Ne(e, t) {
3
+ import { jsx as r, jsxs as $ } from "react/jsx-runtime";
4
+ import { useId as Ce, useState as se, useRef as ke, useCallback as fe, useLayoutEffect as Ae, useEffect as Ee } from "react";
5
+ import { assess as Me, verdictWeight as te, useDensityFor as Te, useFormats as xe, useWording as ye, VisuallyHidden as We, AngleGlyph as Be, Badge as oe, useFreshness as Le, Tooltip as De } from "@umriss-ui/core";
6
+ import { p as Re } from "./calculation.model-BTqFvIHM.js";
7
+ function we(e, t) {
8
8
  if (e.decimals !== void 0) return e.decimals;
9
- const m = e.format === "percent" ? 1 : e.given ? void 0 : 2;
10
- if (m === void 0) return;
9
+ const f = e.format === "percent" ? 1 : e.given ? void 0 : 2;
10
+ if (f === void 0) return;
11
11
  const i = e.format === "percent" ? t * 100 : t;
12
- return i !== 0 && we(i, m) === 0 ? void 0 : m;
12
+ return i !== 0 && qe(i, f) === 0 ? void 0 : f;
13
13
  }
14
14
  function pe(e, t) {
15
- const [m, i = "0"] = String(e).split("e");
16
- return +`${m}e${Number(i) + t}`;
15
+ const [f, i = "0"] = String(e).split("e");
16
+ return +`${f}e${Number(i) + t}`;
17
17
  }
18
- function we(e, t) {
18
+ function qe(e, t) {
19
19
  return t === void 0 ? e : Math.sign(e) * pe(Math.round(pe(Math.abs(e), t)), -t) || 0;
20
20
  }
21
- function J(e, t, m = Ne(e, t)) {
22
- return we(e.format === "percent" ? t * 100 : t, m);
21
+ function X(e, t, f = we(e, t)) {
22
+ return qe(e.format === "percent" ? t * 100 : t, f);
23
23
  }
24
24
  const Fe = (e, t) => e.format === "percent" ? t / 100 : t;
25
- function fe(e, t, m) {
26
- const [i, ...d] = t;
25
+ function he(e, t, f) {
26
+ const [i, ...u] = t;
27
27
  switch (e) {
28
28
  case "sum":
29
- return t.reduce((n, l, g) => m[g] ? n - l : n + l, 0);
29
+ return t.reduce((n, l, g) => f[g] ? n - l : n + l, 0);
30
30
  case "difference":
31
- return d.reduce((n, l) => n - l, i);
31
+ return u.reduce((n, l) => n - l, i);
32
32
  case "product":
33
- return d.reduce((n, l) => n * l, i);
33
+ return u.reduce((n, l) => n * l, i);
34
34
  case "quotient":
35
- return i / d[0];
35
+ return i / u[0];
36
36
  }
37
37
  }
38
- const he = (e, t) => t === void 0 || e !== void 0 && X(e) >= X(t) ? e : t;
39
- function qe(e) {
40
- const t = /* @__PURE__ */ new Map(), m = (i) => {
41
- const d = t.get(i);
42
- if (d) return d;
38
+ const ve = (e, t) => t === void 0 || e !== void 0 && te(e) >= te(t) ? e : t, ge = { good: 0, uncertain: 1, bad: 2 };
39
+ function je(e) {
40
+ const t = /* @__PURE__ */ new Map(), f = (i) => {
41
+ const u = t.get(i);
42
+ if (u) return u;
43
43
  const n = e.quantities.get(i);
44
- let l = null, g, p = !1, s;
44
+ let l = null, g, p = !1, s, S = "good";
45
45
  if (n.given) {
46
- const N = n.given.value;
47
- typeof N == "number" && Number.isFinite(N) ? l = N : g = { kind: "missing", label: n.label };
46
+ const y = n.given.value;
47
+ typeof y == "number" && Number.isFinite(y) ? l = y : g = { kind: "missing", label: n.label }, S = n.given.quality ?? "good";
48
48
  } else {
49
- const N = n.operands.map((w) => ({ operand: w, ...m(w.key) }));
50
- for (const { operand: w, verdict: S, worst: C } of N) {
51
- const $ = w.reference ? S : he(S, C);
52
- s = he(s, $);
49
+ const y = n.operands.map((v) => ({ operand: v, ...f(v.key) }));
50
+ for (const v of y)
51
+ ge[v.quality] > ge[S] && (S = v.quality);
52
+ for (const { operand: v, verdict: O, worst: k } of y) {
53
+ const w = v.reference ? O : ve(O, k);
54
+ s = ve(s, w);
53
55
  }
54
- g = N.find((w) => w.absence)?.absence;
55
- const I = N[1];
56
- if (!g && n.operator === "quotient" && I.value === 0 && (g = { kind: "zero", label: e.quantities.get(I.operand.key).label }), !g) {
57
- const w = n.operands.map(($) => $.negated === !0);
58
- l = fe(n.operator, N.map(($) => $.value), w);
59
- const S = fe(
56
+ g = y.find((v) => v.absence)?.absence;
57
+ const R = y[1];
58
+ if (!g && n.operator === "quotient" && R.value === 0 && (g = { kind: "zero", label: e.quantities.get(R.operand.key).label }), !g) {
59
+ const v = n.operands.map((w) => w.negated === !0);
60
+ l = he(n.operator, y.map((w) => w.value), v);
61
+ const O = he(
60
62
  n.operator,
61
- N.map(($) => Fe(e.quantities.get($.operand.key), $.shown)),
62
- w
63
- ), C = Ne(n, l);
64
- p = J(n, S, C) !== J(n, l, C);
63
+ y.map((w) => Fe(e.quantities.get(w.operand.key), w.shown)),
64
+ v
65
+ ), k = we(n, l);
66
+ p = X(n, O, k) !== X(n, l, k);
65
67
  }
66
68
  }
67
- const B = { target: n.target, limits: n.limits }, T = n.target !== void 0 || (n.limits?.length ?? 0) > 0 ? Me(l, B) : void 0, h = (n.limits?.length ?? 0) > 0 ? T.verdict : l === null ? "unknown" : void 0, j = {
69
+ const C = { target: n.target, limits: n.limits }, h = n.target !== void 0 || (n.limits?.length ?? 0) > 0 ? Me(l, C) : void 0, P = (n.limits?.length ?? 0) > 0 ? h.verdict : l === null ? "unknown" : void 0, W = {
68
70
  value: l,
69
71
  absence: g,
70
- shown: l === null ? null : J(n, l),
72
+ shown: l === null ? null : X(n, l),
71
73
  approximate: p,
72
- assessment: T,
73
- verdict: h,
74
- worst: s
74
+ assessment: h,
75
+ verdict: P,
76
+ worst: s,
77
+ quality: S
75
78
  };
76
- return t.set(i, j), j;
79
+ return t.set(i, W), W;
77
80
  };
78
- for (const i of e.quantities.keys()) m(i);
81
+ for (const i of e.quantities.keys()) f(i);
79
82
  return t;
80
83
  }
81
- const ve = 4;
82
- function je(e, t, m) {
84
+ function Ue() {
85
+ try {
86
+ return process.env.NODE_ENV !== "production";
87
+ } catch {
88
+ return !1;
89
+ }
90
+ }
91
+ const Ie = Ue(), _e = /* @__PURE__ */ new Set();
92
+ function Pe(e, t) {
93
+ !Ie || _e.has(e) || (_e.add(e), console.warn(`@umriss-ui/calculation: ${t}`));
94
+ }
95
+ const be = 4;
96
+ function Ve(e, t, f) {
83
97
  const i = e.operands[t];
84
98
  if (i.previous) return;
85
- const d = e.operator, n = t === 0;
86
- if (d !== "sum" && d !== "difference") return n ? void 0 : { operator: d, negated: !1 };
87
- const l = d === "difference" ? !n : i.negated === !0, g = new Set(m.filter((s) => s !== null && s !== 0).map(Math.sign)), p = g.size === 1 ? { operator: "sum", negated: l !== g.has(-1), unsigned: !0 } : { operator: "sum", negated: l };
99
+ const u = e.operator, n = t === 0;
100
+ if (u !== "sum" && u !== "difference") return n ? void 0 : { operator: u, negated: !1 };
101
+ const l = u === "difference" ? !n : i.negated === !0, g = new Set(f.filter((s) => s !== null && s !== 0).map(Math.sign)), p = g.size === 1 ? { operator: "sum", negated: l !== g.has(-1), unsigned: !0 } : { operator: "sum", negated: l };
88
102
  return n && !p.negated ? void 0 : p;
89
103
  }
90
- const De = {
104
+ const ze = {
91
105
  sum: "calculationSumSymbol",
92
106
  difference: "calculationDifferenceSymbol",
93
107
  product: "calculationProductSymbol",
94
108
  quotient: "calculationQuotientSymbol"
95
- }, Pe = {
109
+ }, He = {
96
110
  sum: "calculationSumWord",
97
111
  difference: "calculationDifferenceWord",
98
112
  product: "calculationProductWord",
99
113
  quotient: "calculationQuotientWord"
100
114
  };
101
- function K(e, t) {
115
+ function Qe(e, t) {
116
+ return e === "bad" ? t.qualityBad : e === "uncertain" ? t.qualityUncertain : void 0;
117
+ }
118
+ function ee(e, t) {
102
119
  switch (e) {
103
120
  case "alarm":
104
121
  return t.verdictAlarm;
@@ -110,314 +127,319 @@ function K(e, t) {
110
127
  return t.verdictOk;
111
128
  }
112
129
  }
113
- function ee(e, t, m) {
130
+ function ne(e, t, f) {
114
131
  const i = e.negated ? "difference" : e.operator;
115
- return m[(t ? Pe : De)[i]];
132
+ return f[(t ? He : ze)[i]];
116
133
  }
117
- function Ue(e, t) {
134
+ function Ge(e, t) {
118
135
  return e.kind === "missing" ? t.calculationMissing(e.label) : t.calculationDivisionByZero(e.label);
119
136
  }
120
- function ge(e, t, m, i) {
121
- const d = e.format === "percent" ? i : e.unit, n = m.number(t, e.decimals);
122
- return d ? `${n} ${d}` : n;
137
+ function Ne(e, t, f, i) {
138
+ const u = e.format === "percent" ? i : e.unit, n = f.number(t, e.decimals);
139
+ return u ? `${n} ${u}` : n;
123
140
  }
124
- function Ie(e, t, m, i, d, n, l, g = () => {
141
+ function Ye(e, t, f, i, u, n, l, g = () => {
125
142
  }) {
126
- const p = e.quantities.get(m), s = t.get(m), B = (v, y) => v.shown !== null && y?.unsigned ? Math.abs(v.shown) : v.shown, T = (v, y, _, F) => {
127
- const D = B(y, F);
128
- return D === null ? _ ? n.verdictUnknown : n.statAbsentValue : ge(v, D, d, _ ? n.calculationPercent : "%");
129
- }, h = (v) => {
143
+ const p = e.quantities.get(f), s = t.get(f), S = (N, q) => N.shown !== null && q?.unsigned ? Math.abs(N.shown) : N.shown, C = (N, q, _, F) => {
144
+ const z = S(q, F);
145
+ return z === null ? _ ? n.verdictUnknown : n.statAbsentValue : Ne(N, z, u, _ ? n.calculationPercent : "%");
146
+ }, h = (N) => {
130
147
  if (i || !p.operator) return {};
131
148
  if (p.operands.length === 0) return { names: n.calculationNoOperands };
132
- if (!v && p.operands.length > ve)
149
+ if (!N && p.operands.length > be)
133
150
  return { names: n.calculationOperandCount(p.operands.length) };
134
- const y = (_) => p.operands.map((F, D) => {
135
- const Y = e.quantities.get(F.key), q = g(D);
136
- return q ? `${ee(q, v, n)} ${_(Y, q)}` : _(Y);
151
+ const q = (_) => p.operands.map((F, z) => {
152
+ const j = e.quantities.get(F.key), Q = g(z);
153
+ return Q ? `${ne(Q, N, n)} ${_(j, Q)}` : _(j);
137
154
  }).join(" ");
138
155
  return {
139
- names: y((_) => _.label),
140
- numbers: y((_, F) => T(_, t.get(_.key), v, F))
156
+ names: q((_) => _.label),
157
+ numbers: q((_, F) => C(_, t.get(_.key), N, F))
141
158
  };
142
- }, j = (v) => {
143
- const y = s.assessment?.deviation;
144
- if (y === void 0 || p.target === void 0) return;
145
- const _ = ge(p, J(p, p.target), d, v ? n.calculationPercent : "%");
146
- return y > 0 ? n.calculationAboveTarget(_) : y < 0 ? n.calculationBelowTarget(_) : n.calculationOnTarget(_);
147
- }, N = h(!1).names, I = N === void 0 || p.operands.length === 0 || p.operands.length > ve ? N : `= ${N}`, w = h(!0), S = s.absence ? Ue(s.absence, n) : void 0, C = ` ${n.calculationEquals} `, $ = s.approximate ? `${n.calculationApproximately} ${T(p, s, !0, l)}` : T(p, s, !0, l), te = [
148
- (l ? `${ee(l, !0, n)} ` : "") + p.label + C + [w.names, w.numbers, $].filter(Boolean).join(`,${C}`),
149
- s.verdict !== void 0 && s.verdict !== "unknown" ? K(s.verdict, n) : void 0,
150
- j(!0),
151
- S
152
- ].filter(Boolean).join(", "), G = s.shown === null ? void 0 : p.format === "percent" ? "%" : p.unit, k = (v) => v === null ? n.statAbsentValue : d.number(v, p.decimals);
153
- return { amount: k(B(s, l)), ownAmount: k(s.shown), unit: G, names: I, target: j(!1), reason: S, sentence: te, spokenNames: w.names, spokenNumber: $ };
159
+ }, P = (N) => {
160
+ const q = s.assessment?.deviation;
161
+ if (q === void 0 || p.target === void 0) return;
162
+ const _ = Ne(p, X(p, p.target), u, N ? n.calculationPercent : "%");
163
+ return q > 0 ? n.calculationAboveTarget(_) : q < 0 ? n.calculationBelowTarget(_) : n.calculationOnTarget(_);
164
+ }, W = h(!1).names, y = W === void 0 || p.operands.length === 0 || p.operands.length > be ? W : `= ${W}`, R = h(!0), v = Qe(s.quality, n), O = s.absence ? Ge(s.absence, n) : void 0, k = ` ${n.calculationEquals} `, w = s.approximate ? `${n.calculationApproximately} ${C(p, s, !0, l)}` : C(p, s, !0, l), J = [
165
+ (l ? `${ne(l, !0, n)} ` : "") + p.label + k + [R.names, R.numbers, w].filter(Boolean).join(`,${k}`),
166
+ s.verdict !== void 0 && s.verdict !== "unknown" ? ee(s.verdict, n) : void 0,
167
+ v,
168
+ P(!0),
169
+ O
170
+ ].filter(Boolean).join(", "), A = s.shown === null ? void 0 : p.format === "percent" ? "%" : p.unit, V = (N) => N === null ? n.statAbsentValue : u.number(N, p.decimals);
171
+ return { amount: V(S(s, l)), ownAmount: V(s.shown), unit: A, names: y, target: P(!1), quality: v, reason: O, sentence: J, spokenNames: R.names, spokenNumber: w };
154
172
  }
155
- function ze(e, t, m, i, d) {
156
- const n = d ? `${ee(d, !0, i)} ` : "", l = t[0].spokenNames, g = n + e + (l === void 0 ? "" : ` ${i.calculationEquals} ${l}`), p = m.map(
157
- (s, B) => [`${s.label} ${t[B].spokenNumber}`, t[B].reason].filter(Boolean).join(", ")
158
- );
159
- return `${g}: ${p.join("; ")}`;
173
+ function Ze(e, t, f, i, u) {
174
+ const n = u ? `${ne(u, !0, i)} ` : "", l = t[0].spokenNames, g = n + e + (l === void 0 ? "" : ` ${i.calculationEquals} ${l}`), p = f.map(
175
+ (S, C) => [`${S.label} ${t[C].spokenNumber}`, t[C].reason].filter(Boolean).join(", ")
176
+ ), s = t[0].quality;
177
+ return `${g}: ${p.join("; ")}${s ? `, ${s}` : ""}`;
160
178
  }
161
- const Ve = "_frame_10pic_24 _text_18806_22", He = "_calculation_10pic_51", Qe = "_line_10pic_86", Ge = "_assessment_10pic_98", Ye = "_disclosure_10pic_107", Ze = "_amount_10pic_90", Je = "_list_10pic_128", Ke = "_item_10pic_129", Xe = "_derivation_10pic_130", et = "_labelCell_10pic_90", tt = "_names_10pic_90", nt = "_operator_10pic_90", at = "_unit_10pic_90", st = "_label_10pic_90", ot = "_approximate_10pic_360", it = "_target_10pic_102", rt = "_worst_10pic_102", ct = "_head_10pic_512", lt = "_headCell_10pic_519", dt = "_headUnit_10pic_532", ut = "_notes_10pic_539", mt = "_freshness_10pic_553", pt = "_headLabel_10pic_583", o = {
162
- frame: Ve,
163
- calculation: He,
164
- line: Qe,
165
- assessment: Ge,
166
- disclosure: Ye,
167
- amount: Ze,
168
- list: Je,
169
- item: Ke,
170
- derivation: Xe,
171
- labelCell: et,
172
- names: tt,
173
- operator: nt,
174
- unit: at,
175
- label: st,
176
- approximate: ot,
177
- target: it,
178
- worst: rt,
179
- head: ct,
180
- headCell: lt,
181
- headUnit: dt,
182
- notes: ut,
183
- freshness: mt,
184
- headLabel: pt
185
- }, ft = 10, Q = (e) => 4 + 2 * e, ht = (e) => 5 + 2 * e, vt = { ok: "success", unknown: "neutral", warning: "warning", alarm: "danger" }, gt = (...e) => e.filter(Boolean).join(" ");
186
- function _t({ asOf: e, ages: t }) {
187
- const m = _e(), i = be(), d = Le(e, t), n = d.freshness === "lost" ? i.freshnessDisconnected : d.freshness === "stale" ? i.freshnessStale : i.freshnessFresh;
188
- return /* @__PURE__ */ O("span", { className: o.freshness, "data-freshness": d.freshness, children: [
179
+ const Je = "_frame_184xf_24 _text_18806_22", Ke = "_calculation_184xf_51", Xe = "_line_184xf_86", et = "_assessment_184xf_98", tt = "_disclosure_184xf_107", nt = "_amount_184xf_90", at = "_list_184xf_128", st = "_item_184xf_129", ot = "_derivation_184xf_130", it = "_labelCell_184xf_90", rt = "_names_184xf_90", lt = "_operator_184xf_90", ct = "_unit_184xf_90", ut = "_label_184xf_90", dt = "_approximate_184xf_360", mt = "_target_184xf_102", ft = "_worst_184xf_102", pt = "_quality_184xf_102", ht = "_head_184xf_539", vt = "_headCell_184xf_546", gt = "_headUnit_184xf_559", _t = "_notes_184xf_566", bt = "_freshness_184xf_580", Nt = "_headLabel_184xf_610", o = {
180
+ frame: Je,
181
+ calculation: Ke,
182
+ line: Xe,
183
+ assessment: et,
184
+ disclosure: tt,
185
+ amount: nt,
186
+ list: at,
187
+ item: st,
188
+ derivation: ot,
189
+ labelCell: it,
190
+ names: rt,
191
+ operator: lt,
192
+ unit: ct,
193
+ label: ut,
194
+ approximate: dt,
195
+ target: mt,
196
+ worst: ft,
197
+ quality: pt,
198
+ head: ht,
199
+ headCell: vt,
200
+ headUnit: gt,
201
+ notes: _t,
202
+ freshness: bt,
203
+ headLabel: Nt
204
+ }, xt = 10, Z = (e) => 4 + 2 * e, yt = (e) => 5 + 2 * e, wt = { ok: "success", unknown: "neutral", warning: "warning", alarm: "danger" }, qt = (...e) => e.filter(Boolean).join(" ");
205
+ function $t({ asOf: e, ages: t }) {
206
+ const f = xe(), i = ye(), u = Le(e, t), n = u.freshness === "lost" ? i.freshnessDisconnected : u.freshness === "stale" ? i.freshnessStale : i.freshnessFresh;
207
+ return /* @__PURE__ */ $("span", { className: o.freshness, "data-freshness": u.freshness, children: [
189
208
  n,
190
- d.age !== null && ` · ${m.relative(d.age)}`
209
+ u.age !== null && ` · ${f.relative(u.age)}`
191
210
  ] });
192
211
  }
193
- function xt({
212
+ function At({
194
213
  model: e,
195
214
  ref: t,
196
- className: m,
215
+ className: f,
197
216
  style: i,
198
- density: d,
217
+ density: u,
199
218
  "aria-label": n,
200
219
  "aria-labelledby": l,
201
220
  "aria-describedby": g,
202
221
  ...p
203
222
  }) {
204
- const s = e.metrics, B = Be(d, "regular") === "compact", T = _e(), h = be(), j = Ce(), N = We(e).map((a) => ({ view: a, results: qe(a) })), [I, w] = ae(() => /* @__PURE__ */ new Set()), [S, C] = ae(null), $ = ke(null), oe = me(
223
+ !n && !l && Pe("no-name", "A Calculation has no accessible name: give it aria-label or aria-labelledby.");
224
+ const s = e.metrics, S = Te(u, "regular") === "compact", C = xe(), h = ye(), P = Ce(), W = Re(e).map((a) => ({ view: a, results: je(a) })), [y, R] = se(() => /* @__PURE__ */ new Set()), [v, O] = se(null), k = ke(null), w = fe(
205
225
  (a) => {
206
- $.current = a, typeof t == "function" ? t(a) : t && (t.current = a);
226
+ k.current = a, typeof t == "function" ? t(a) : t && (t.current = a);
207
227
  },
208
228
  [t]
209
- ), [te, G] = ae(!1), k = s?.length ?? 0, v = me(() => {
210
- const a = $.current, u = a && k > 0 ? getComputedStyle(a.firstElementChild).gridTemplateColumns.split(" ").map(parseFloat) : [], f = Q(k) - 1;
211
- if (!a || u.length <= f || u.some((x) => !Number.isFinite(x))) {
212
- G(!1);
229
+ ), [ie, J] = se(!1), A = s?.length ?? 0, V = fe(() => {
230
+ const a = k.current, d = a && A > 0 ? getComputedStyle(a.firstElementChild).gridTemplateColumns.split(" ").map(parseFloat) : [], m = Z(A) - 1;
231
+ if (!a || d.length <= m || d.some((x) => !Number.isFinite(x))) {
232
+ J(!1);
213
233
  return;
214
234
  }
215
- const A = u.slice(2, f).reduce((x, M) => x + M, 0);
216
- let r = 0;
217
- const E = document.createRange();
235
+ const E = d.slice(2, m).reduce((x, T) => x + T, 0);
236
+ let c = 0;
237
+ const B = document.createRange();
218
238
  for (const x of a.querySelectorAll(`.${o.label}`)) {
219
- E.selectNodeContents(x);
220
- const M = [...E.getClientRects()].reduce((R, W) => R + W.width, 0);
221
- if (M === 0) continue;
222
- const V = x.parentElement, z = x.getBoundingClientRect().left - V.getBoundingClientRect().left;
223
- r = Math.max(r, z + M + parseFloat(getComputedStyle(V).paddingRight));
239
+ B.selectNodeContents(x);
240
+ const T = [...B.getClientRects()].reduce((L, D) => L + D.width, 0);
241
+ if (T === 0) continue;
242
+ const G = x.parentElement, H = x.getBoundingClientRect().left - G.getBoundingClientRect().left;
243
+ c = Math.max(c, H + T + parseFloat(getComputedStyle(G).paddingRight));
224
244
  }
225
- const L = parseFloat(getComputedStyle(document.documentElement).fontSize);
226
- G(a.clientWidth - A < Math.min(r, ft * L));
227
- }, [k]);
228
- ye(() => v()), Ae(() => {
229
- const a = $.current;
230
- if (!a || k === 0) return;
231
- const u = new ResizeObserver(() => v());
232
- return u.observe(a), () => u.disconnect();
233
- }, [v, k]);
234
- const y = (a) => w((u) => {
235
- const f = new Set(u);
236
- return f.delete(a) || f.add(a), f;
237
- }), _ = (a, u) => je(
245
+ const M = parseFloat(getComputedStyle(document.documentElement).fontSize);
246
+ J(a.clientWidth - E < Math.min(c, xt * M));
247
+ }, [A]);
248
+ Ae(() => V()), Ee(() => {
249
+ const a = k.current;
250
+ if (!a || A === 0) return;
251
+ const d = new ResizeObserver(() => V());
252
+ return d.observe(a), () => d.disconnect();
253
+ }, [V, A]);
254
+ const N = (a) => R((d) => {
255
+ const m = new Set(d);
256
+ return m.delete(a) || m.add(a), m;
257
+ }), q = (a, d) => Ve(
238
258
  a,
239
- u,
240
- N.map(({ results: f }) => f.get(a.operands[u].key).shown)
259
+ d,
260
+ W.map(({ results: m }) => m.get(a.operands[d].key).shown)
241
261
  );
242
- let F = !1;
243
- const D = (a, u) => a.map(({ own: f, text: A }, r) => [
244
- /* @__PURE__ */ O(
262
+ let _ = !1;
263
+ const F = (a, d) => a.map(({ own: m, text: E }, c) => [
264
+ /* @__PURE__ */ $(
245
265
  "span",
246
266
  {
247
267
  className: o.amount,
248
268
  "aria-hidden": "true",
249
- "data-verdict": f.verdict,
250
- "data-later": r > 0 ? "" : void 0,
251
- style: s ? { "--_calculation-column": Q(r) } : void 0,
269
+ "data-verdict": m.verdict,
270
+ "data-quality": m.quality === "good" ? void 0 : m.quality,
271
+ "data-later": c > 0 ? "" : void 0,
272
+ style: s ? { "--_calculation-column": Z(c) } : void 0,
252
273
  children: [
253
- f.approximate && /* @__PURE__ */ c(Re, { content: h.calculationApproximateNote, children: /* @__PURE__ */ c("span", { className: o.approximate, children: "≈" }) }),
254
- u ? A.ownAmount : A.amount
274
+ m.approximate && /* @__PURE__ */ r(De, { content: h.calculationApproximateNote, children: /* @__PURE__ */ r("span", { className: o.approximate, children: "≈" }) }),
275
+ d ? E.ownAmount : E.amount
255
276
  ]
256
277
  },
257
- `amount-${r}`
278
+ `amount-${c}`
258
279
  ),
259
- /* @__PURE__ */ c(
280
+ /* @__PURE__ */ r(
260
281
  "span",
261
282
  {
262
283
  className: o.unit,
263
284
  "aria-hidden": "true",
264
- style: s ? { "--_calculation-column": ht(r) } : void 0,
265
- "data-last": s && r === a.length - 1 ? "" : void 0,
266
- children: s && !u ? void 0 : A.unit
285
+ style: s ? { "--_calculation-column": yt(c) } : void 0,
286
+ "data-last": s && c === a.length - 1 ? "" : void 0,
287
+ children: s && !d ? void 0 : E.unit
267
288
  },
268
- `unit-${r}`
289
+ `unit-${c}`
269
290
  )
270
- ]), Y = (a, u) => S === null ? void 0 : a === S ? "use" : u === S ? "operand" : void 0, q = (a, u, f, A) => {
271
- const r = e.quantities.get(a), E = N.map(({ view: b, results: U }) => ({
272
- own: U.get(a),
273
- text: Ie(b, U, a, u, T, h, f.position, (Se) => _(r, Se))
274
- })), { own: L, text: x } = E[0], M = r.operator !== void 0 && !u, V = a === e.result && !u, z = M && r.operands.length > 0 && (r.interim ? f.flat : V), R = M && !z && r.operands.length > 0, W = R && I.has(a);
275
- F ||= R;
276
- const ie = `${j}-${a}`, ne = { depth: z ? f.depth : f.depth + 1, flat: !1, parent: a }, Z = M ? r.operands.find((b) => b.previous) : void 0, re = Z && f.flat ? q(Z.key, !1, { ...f, parent: a, position: void 0 }, `${A}-c`) : [], xe = Z && !f.flat ? q(Z.key, !1, { ...ne, flat: !0 }, `${A}-c`) : [], ce = M ? r.operands.map(
277
- (b, U) => b.previous ? null : q(b.key, b.reference, { ...ne, position: _(r, U) }, `${A}-${U}`)
278
- ) : [], H = R && !W && L.worst !== void 0 && X(L.worst) > X(L.verdict ?? "ok") ? L.worst : void 0, P = u ? void 0 : r.given, Oe = f.position ? ee(f.position, !1, h) : void 0, le = [
279
- !u && r.explanation !== void 0 && /* @__PURE__ */ c("span", { children: r.explanation }, "explanation"),
280
- P?.source !== void 0 && /* @__PURE__ */ c("span", { children: h.calculationSource(P.source) }, "source"),
281
- P?.asOf !== void 0 && (P.ages !== void 0 ? /* @__PURE__ */ c(_t, { asOf: P.asOf, ages: P.ages }, "asOf") : /* @__PURE__ */ c("span", { children: h.asOfAgo(T.dateTime(new Date(P.asOf), !1)) }, "asOf")),
282
- !u && r.aside !== void 0 && /* @__PURE__ */ c("span", { children: r.aside }, "aside")
283
- ].filter(Boolean), de = V ? "result" : r.interim && !u && f.flat ? "interim" : void 0, ue = /* @__PURE__ */ O(
291
+ ]), z = (a, d) => v === null ? void 0 : a === v ? "use" : d === v ? "operand" : void 0, j = (a, d, m, E) => {
292
+ const c = e.quantities.get(a), B = W.map(({ view: b, results: I }) => ({
293
+ own: I.get(a),
294
+ text: Ye(b, I, a, d, C, h, m.position, (Se) => q(c, Se))
295
+ })), { own: M, text: x } = B[0], T = c.operator !== void 0 && !d, G = a === e.result && !d, H = T && c.operands.length > 0 && (c.interim ? m.flat : G), L = T && !H && c.operands.length > 0, D = L && y.has(a);
296
+ _ ||= L;
297
+ const re = `${P}-${a}`, ae = { depth: H ? m.depth : m.depth + 1, flat: !1, parent: a }, K = T ? c.operands.find((b) => b.previous) : void 0, le = K && m.flat ? j(K.key, !1, { ...m, parent: a, position: void 0 }, `${E}-c`) : [], $e = K && !m.flat ? j(K.key, !1, { ...ae, flat: !0 }, `${E}-c`) : [], ce = T ? c.operands.map(
298
+ (b, I) => b.previous ? null : j(b.key, b.reference, { ...ae, position: q(c, I) }, `${E}-${I}`)
299
+ ) : [], Y = L && !D && M.worst !== void 0 && te(M.worst) > te(M.verdict ?? "ok") ? M.worst : void 0, U = d ? void 0 : c.given, Oe = m.position ? ne(m.position, !1, h) : void 0, ue = [
300
+ !d && c.explanation !== void 0 && /* @__PURE__ */ r("span", { children: c.explanation }, "explanation"),
301
+ U?.source !== void 0 && /* @__PURE__ */ r("span", { children: h.calculationSource(U.source) }, "source"),
302
+ U?.asOf !== void 0 && (U.ages !== void 0 ? /* @__PURE__ */ r($t, { asOf: U.asOf, ages: U.ages }, "asOf") : /* @__PURE__ */ r("span", { children: h.asOfAgo(C.dateTime(new Date(U.asOf), !1)) }, "asOf")),
303
+ !d && c.aside !== void 0 && /* @__PURE__ */ r("span", { children: c.aside }, "aside")
304
+ ].filter(Boolean), de = G ? "result" : c.interim && !d && m.flat ? "interim" : void 0, me = /* @__PURE__ */ $(
284
305
  "div",
285
306
  {
286
307
  className: o.line,
287
- style: { "--_calculation-depth": f.depth },
288
- "data-inner": f.depth > 0 ? "" : void 0,
308
+ style: { "--_calculation-depth": m.depth },
309
+ "data-inner": m.depth > 0 ? "" : void 0,
289
310
  "data-kind": de,
290
- "data-foldable": R ? "" : void 0,
291
- "data-reference": u ? "" : void 0,
292
- "data-emphasis": u ? void 0 : r.emphasis,
293
- "data-rule": !u && r.rule ? "" : void 0,
294
- "data-mark": Y(a, f.parent),
295
- onPointerEnter: () => C(a),
296
- onPointerLeave: () => C(null),
297
- onFocus: () => C(a),
298
- onBlur: () => C(null),
299
- onClick: R ? () => {
300
- window.getSelection()?.toString() || y(a);
311
+ "data-foldable": L ? "" : void 0,
312
+ "data-reference": d ? "" : void 0,
313
+ "data-emphasis": d ? void 0 : c.emphasis,
314
+ "data-rule": !d && c.rule ? "" : void 0,
315
+ "data-mark": z(a, m.parent),
316
+ onPointerEnter: () => O(a),
317
+ onPointerLeave: () => O(null),
318
+ onFocus: () => O(a),
319
+ onBlur: () => O(null),
320
+ onClick: L ? () => {
321
+ window.getSelection()?.toString() || N(a);
301
322
  } : void 0,
302
323
  children: [
303
- /* @__PURE__ */ c(Te, { children: [
304
- s ? ze(r.label, E.map((b) => b.text), s, h, f.position) : x.sentence,
305
- E.some((b) => b.own.approximate) && h.calculationApproximateNote,
306
- H !== void 0 && h.calculationWorstInside(K(H, h))
324
+ /* @__PURE__ */ r(We, { children: [
325
+ s ? Ze(c.label, B.map((b) => b.text), s, h, m.position) : x.sentence,
326
+ B.some((b) => b.own.approximate) && h.calculationApproximateNote,
327
+ Y !== void 0 && h.calculationWorstInside(ee(Y, h))
307
328
  ].filter(Boolean).join(". ") }),
308
- /* @__PURE__ */ O("span", { className: o.labelCell, children: [
309
- R ? /* @__PURE__ */ c(
329
+ /* @__PURE__ */ $("span", { className: o.labelCell, children: [
330
+ L ? /* @__PURE__ */ r(
310
331
  "button",
311
332
  {
312
333
  type: "button",
313
334
  className: o.disclosure,
314
- "aria-expanded": W,
315
- "aria-controls": ie,
316
- "aria-label": (W ? h.calculationHideDerivation : h.calculationShowDerivation)(r.label),
317
- children: /* @__PURE__ */ c(Ee, { "data-open": W ? "" : void 0 })
335
+ "aria-expanded": D,
336
+ "aria-controls": re,
337
+ "aria-label": (D ? h.calculationHideDerivation : h.calculationShowDerivation)(c.label),
338
+ children: /* @__PURE__ */ r(Be, { "data-open": D ? "" : void 0 })
318
339
  }
319
- ) : /* @__PURE__ */ c("span", { className: o.disclosure, "aria-hidden": "true" }),
320
- /* @__PURE__ */ c("span", { className: o.label, "aria-hidden": "true", children: r.label })
340
+ ) : /* @__PURE__ */ r("span", { className: o.disclosure, "aria-hidden": "true" }),
341
+ /* @__PURE__ */ r("span", { className: o.label, "aria-hidden": "true", children: c.label })
321
342
  ] }),
322
- /* @__PURE__ */ c("span", { className: o.names, "aria-hidden": "true", children: M && !z && !W ? x.names : void 0 }),
323
- /* @__PURE__ */ c("span", { className: o.operator, "aria-hidden": "true", children: Oe }),
324
- D(E, de !== void 0),
325
- /* @__PURE__ */ O("span", { className: o.assessment, "aria-hidden": "true", children: [
343
+ /* @__PURE__ */ r("span", { className: o.names, "aria-hidden": "true", children: T && !H && !D ? x.names : void 0 }),
344
+ /* @__PURE__ */ r("span", { className: o.operator, "aria-hidden": "true", children: Oe }),
345
+ F(B, de !== void 0),
346
+ /* @__PURE__ */ $("span", { className: o.assessment, "aria-hidden": "true", children: [
326
347
  s ? (
327
348
  /* Short: which metric. The sentence carries the full reason. */
328
349
  s.map(
329
- (b, U) => E[U].own.absence && /* @__PURE__ */ c(se, { children: h.calculationMissing(b.unit ?? b.label) }, b.id)
350
+ (b, I) => B[I].own.absence && /* @__PURE__ */ r(oe, { children: h.calculationMissing(b.unit ?? b.label) }, b.id)
330
351
  )
331
- ) : x.reason !== void 0 ? /* @__PURE__ */ c(se, { children: x.reason }) : L.verdict !== void 0 && /* @__PURE__ */ c(se, { tone: vt[L.verdict], children: K(L.verdict, h) }),
332
- x.target !== void 0 && /* @__PURE__ */ c("span", { className: o.target, children: x.target }),
333
- H !== void 0 && /* @__PURE__ */ c("span", { className: o.worst, "data-verdict": H, children: h.calculationWorstInside(K(H, h)) })
352
+ ) : x.reason !== void 0 ? /* @__PURE__ */ r(oe, { children: x.reason }) : M.verdict !== void 0 && /* @__PURE__ */ r(oe, { tone: wt[M.verdict], children: ee(M.verdict, h) }),
353
+ x.target !== void 0 && /* @__PURE__ */ r("span", { className: o.target, children: x.target }),
354
+ x.quality !== void 0 && /* @__PURE__ */ r("span", { className: o.quality, "data-quality": M.quality, children: x.quality }),
355
+ Y !== void 0 && /* @__PURE__ */ r("span", { className: o.worst, "data-verdict": Y, children: h.calculationWorstInside(ee(Y, h)) })
334
356
  ] }),
335
- le.length > 0 && /* A click here - on a link in the aside, on a sparkline - is the
357
+ ue.length > 0 && /* A click here - on a link in the aside, on a sparkline - is the
336
358
  caller's, not a fold. */
337
- /* @__PURE__ */ c("span", { className: o.notes, onClick: (b) => b.stopPropagation(), children: le })
359
+ /* @__PURE__ */ r("span", { className: o.notes, onClick: (b) => b.stopPropagation(), children: ue })
338
360
  ]
339
361
  }
340
362
  );
341
- return z ? [
342
- ...re,
343
- /* @__PURE__ */ O("li", { className: o.item, children: [
344
- /* @__PURE__ */ c("ul", { className: o.list, children: ce }),
345
- ue
346
- ] }, A)
363
+ return H ? [
364
+ ...le,
365
+ /* @__PURE__ */ $("li", { className: o.item, children: [
366
+ /* @__PURE__ */ r("ul", { className: o.list, children: ce }),
367
+ me
368
+ ] }, E)
347
369
  ] : [
348
- ...re,
349
- /* @__PURE__ */ O("li", { className: o.item, "data-open": W ? "" : void 0, style: { "--_calculation-depth": f.depth }, children: [
350
- ue,
351
- R && /* @__PURE__ */ O("ul", { id: ie, className: o.derivation, hidden: !W, children: [
352
- xe,
370
+ ...le,
371
+ /* @__PURE__ */ $("li", { className: o.item, "data-open": D ? "" : void 0, style: { "--_calculation-depth": m.depth }, children: [
372
+ me,
373
+ L && /* @__PURE__ */ $("ul", { id: re, className: o.derivation, hidden: !D, children: [
374
+ $e,
353
375
  ce,
354
- /* @__PURE__ */ c("li", { className: o.item, "aria-hidden": "true", children: /* @__PURE__ */ O(
376
+ /* @__PURE__ */ r("li", { className: o.item, "aria-hidden": "true", children: /* @__PURE__ */ $(
355
377
  "div",
356
378
  {
357
379
  className: o.line,
358
- style: { "--_calculation-depth": ne.depth },
380
+ style: { "--_calculation-depth": ae.depth },
359
381
  "data-inner": "",
360
382
  "data-closing": "",
361
- "data-mark": S === a ? "use" : void 0,
383
+ "data-mark": v === a ? "use" : void 0,
362
384
  children: [
363
- /* @__PURE__ */ O("span", { className: o.labelCell, children: [
364
- /* @__PURE__ */ c("span", { className: o.disclosure }),
365
- /* @__PURE__ */ O("span", { className: o.label, children: [
385
+ /* @__PURE__ */ $("span", { className: o.labelCell, children: [
386
+ /* @__PURE__ */ r("span", { className: o.disclosure }),
387
+ /* @__PURE__ */ $("span", { className: o.label, children: [
366
388
  "= ",
367
- r.label
389
+ c.label
368
390
  ] })
369
391
  ] }),
370
- /* @__PURE__ */ c("span", { className: o.names }),
371
- /* @__PURE__ */ c("span", { className: o.operator }),
372
- D(E, !0)
392
+ /* @__PURE__ */ r("span", { className: o.names }),
393
+ /* @__PURE__ */ r("span", { className: o.operator }),
394
+ F(B, !0)
373
395
  ]
374
396
  }
375
397
  ) })
376
398
  ] })
377
- ] }, A)
399
+ ] }, E)
378
400
  ];
379
- }, $e = q(e.result, !1, { depth: 0, flat: !0, parent: null }, "r");
401
+ }, Q = j(e.result, !1, { depth: 0, flat: !0, parent: null }, "r");
380
402
  return (
381
403
  /* The frame is the surface and the container the layout measures itself
382
404
  against; the list inside it is the statement. */
383
- /* @__PURE__ */ c(
405
+ /* @__PURE__ */ r(
384
406
  "div",
385
407
  {
386
408
  ...p,
387
- ref: oe,
388
- className: gt(o.frame, m),
409
+ ref: w,
410
+ className: qt(o.frame, f),
389
411
  style: s ? {
390
- "--_calculation-figure-tracks": Array(k * 2).fill("auto").join(" "),
391
- "--_calculation-figures-end": Q(k),
392
- "--_calculation-assessment-column": Q(k),
412
+ "--_calculation-figure-tracks": Array(A * 2).fill("auto").join(" "),
413
+ "--_calculation-figures-end": Z(A),
414
+ "--_calculation-assessment-column": Z(A),
393
415
  ...i
394
416
  } : i,
395
- "data-still": F ? void 0 : "",
396
- "data-metrics": s ? k : void 0,
397
- "data-two-lines": te ? "" : void 0,
398
- "data-compact": B ? "" : void 0,
399
- children: /* @__PURE__ */ O("ul", { className: o.calculation, "aria-label": n, "aria-labelledby": l, "aria-describedby": g, children: [
417
+ "data-still": _ ? void 0 : "",
418
+ "data-metrics": s ? A : void 0,
419
+ "data-two-lines": ie ? "" : void 0,
420
+ "data-compact": S ? "" : void 0,
421
+ children: /* @__PURE__ */ $("ul", { className: o.calculation, "aria-label": n, "aria-labelledby": l, "aria-describedby": g, children: [
400
422
  s && /* The head names each metric and its unit above its column. Every
401
423
  row's sentence names them too, so the head is for the eye. */
402
- /* @__PURE__ */ c("li", { className: o.item, "aria-hidden": "true", children: /* @__PURE__ */ c("div", { className: o.head, children: s.map((a, u) => /* @__PURE__ */ O(
424
+ /* @__PURE__ */ r("li", { className: o.item, "aria-hidden": "true", children: /* @__PURE__ */ r("div", { className: o.head, children: s.map((a, d) => /* @__PURE__ */ $(
403
425
  "span",
404
426
  {
405
427
  className: o.headCell,
406
428
  "data-unit": a.unit === void 0 ? void 0 : "",
407
- style: { "--_calculation-column": Q(u) },
429
+ style: { "--_calculation-column": Z(d) },
408
430
  children: [
409
- /* @__PURE__ */ c("span", { className: o.headLabel, children: a.label }),
410
- a.unit !== void 0 && /* @__PURE__ */ c("span", { className: o.headUnit, children: a.unit })
431
+ /* @__PURE__ */ r("span", { className: o.headLabel, children: a.label }),
432
+ a.unit !== void 0 && /* @__PURE__ */ r("span", { className: o.headUnit, children: a.unit })
411
433
  ]
412
434
  },
413
435
  a.id
414
436
  )) }) }),
415
- $e
437
+ Q
416
438
  ] })
417
439
  }
418
440
  )
419
441
  );
420
442
  }
421
443
  export {
422
- xt as CalculationView
444
+ At as CalculationView
423
445
  };