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