@umriss-ui/calculation 0.42.0 → 0.43.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,105 @@
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 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) {
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 && we(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 we(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 = Ne(e, t)) {
22
+ return we(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, l, g) => m[g] ? n - l : n + l, 0);
26
30
  case "difference":
27
- return u.reduce((e, m) => e - m, d);
31
+ return d.reduce((n, l) => n - l, i);
28
32
  case "product":
29
- return u.reduce((e, m) => e * m, d);
33
+ return d.reduce((n, l) => n * l, 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 l = null, g, p = !1, s;
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 };
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
+ l = 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 = Ne(n, l);
64
+ p = J(n, S, C) !== J(n, l, 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 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 = {
68
+ value: l,
69
+ absence: g,
70
+ shown: l === null ? null : J(n, l),
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, j), j;
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
+ const ve = 4;
82
+ function je(e, t, m) {
83
+ const i = e.operands[t];
84
+ 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 };
88
+ return n && !p.negated ? void 0 : p;
85
89
  }
86
- const Re = {
90
+ const De = {
87
91
  sum: "calculationSumSymbol",
88
92
  difference: "calculationDifferenceSymbol",
89
93
  product: "calculationProductSymbol",
90
94
  quotient: "calculationQuotientSymbol"
91
- }, We = {
95
+ }, Pe = {
92
96
  sum: "calculationSumWord",
93
97
  difference: "calculationDifferenceWord",
94
98
  product: "calculationProductWord",
95
99
  quotient: "calculationQuotientWord"
96
100
  };
97
- function Y(n, t) {
98
- switch (n) {
101
+ function K(e, t) {
102
+ switch (e) {
99
103
  case "alarm":
100
104
  return t.verdictAlarm;
101
105
  case "warning":
@@ -106,298 +110,314 @@ function Y(n, t) {
106
110
  return t.verdictOk;
107
111
  }
108
112
  }
109
- function J(n, t, f) {
110
- const d = n.negated ? "difference" : n.operator;
111
- return f[(t ? We : Re)[d]];
113
+ function ee(e, t, m) {
114
+ const i = e.negated ? "difference" : e.operator;
115
+ return m[(t ? Pe : De)[i]];
112
116
  }
113
- function qe(n, t) {
114
- return n.kind === "missing" ? t.calculationMissing(n.label) : t.calculationDivisionByZero(n.label);
117
+ function Ue(e, t) {
118
+ return e.kind === "missing" ? t.calculationMissing(e.label) : t.calculationDivisionByZero(e.label);
115
119
  }
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;
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;
119
123
  }
120
- function Fe(n, t, f, d, u, e, m, v = () => {
124
+ function Ie(e, t, m, i, d, n, l, g = () => {
121
125
  }) {
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);
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) => {
130
+ if (i || !p.operator) return {};
131
+ if (p.operands.length === 0) return { names: n.calculationNoOperands };
132
+ if (!v && p.operands.length > ve)
133
+ 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);
133
137
  }).join(" ");
134
138
  return {
135
- names: $((N) => N.label),
136
- numbers: $((N, a) => L(N, t.get(N.key), b, a))
139
+ names: y((_) => _.label),
140
+ numbers: y((_, F) => T(_, t.get(_.key), v, F))
137
141
  };
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 };
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: $ };
150
154
  }
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(", ")
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(", ")
154
158
  );
155
- return `${v}: ${s.join("; ")}`;
159
+ return `${g}: ${p.join("; ")}`;
156
160
  }
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)}`
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: [
189
+ n,
190
+ d.age !== null && ` · ${m.relative(d.age)}`
187
191
  ] });
188
192
  }
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);
193
+ function xt({
194
+ model: e,
195
+ ref: t,
196
+ className: m,
197
+ style: i,
198
+ density: d,
199
+ "aria-label": n,
200
+ "aria-labelledby": l,
201
+ "aria-describedby": g,
202
+ ...p
203
+ }) {
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(
205
+ (a) => {
206
+ $.current = a, typeof t == "function" ? t(a) : t && (t.current = a);
207
+ },
208
+ [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);
194
213
  return;
195
214
  }
196
- const x = o.slice(2, c).reduce((O, A) => O + A, 0);
215
+ const A = u.slice(2, f).reduce((x, M) => x + M, 0);
197
216
  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));
217
+ const E = document.createRange();
218
+ 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));
205
224
  }
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(
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(
219
238
  a,
220
- o,
221
- C.map(({ results: c }) => c.get(a.operands[o].key).shown)
239
+ u,
240
+ N.map(({ results: f }) => f.get(a.operands[u].key).shown)
222
241
  );
223
- let H = !1;
224
- const P = (a, o) => a.map(({ own: c, text: x }, r) => [
225
- /* @__PURE__ */ S(
242
+ let F = !1;
243
+ const D = (a, u) => a.map(({ own: f, text: A }, r) => [
244
+ /* @__PURE__ */ O(
226
245
  "span",
227
246
  {
228
- className: i.amount,
247
+ className: o.amount,
229
248
  "aria-hidden": "true",
230
- "data-verdict": c.verdict,
249
+ "data-verdict": f.verdict,
231
250
  "data-later": r > 0 ? "" : void 0,
232
- style: e ? { "--_calculation-column": z(r) } : void 0,
251
+ style: s ? { "--_calculation-column": Q(r) } : void 0,
233
252
  children: [
234
- c.approximate && /* @__PURE__ */ l(ye, { content: s.calculationApproximateNote, children: /* @__PURE__ */ l("span", { className: i.approximate, children: "≈" }) }),
235
- o ? x.ownAmount : x.amount
253
+ f.approximate && /* @__PURE__ */ c(Re, { content: h.calculationApproximateNote, children: /* @__PURE__ */ c("span", { className: o.approximate, children: "≈" }) }),
254
+ u ? A.ownAmount : A.amount
236
255
  ]
237
256
  },
238
257
  `amount-${r}`
239
258
  ),
240
- /* @__PURE__ */ l(
259
+ /* @__PURE__ */ c(
241
260
  "span",
242
261
  {
243
- className: i.unit,
262
+ className: o.unit,
244
263
  "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
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
248
267
  },
249
268
  `unit-${r}`
250
269
  )
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(
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(
265
284
  "div",
266
285
  {
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);
286
+ className: o.line,
287
+ style: { "--_calculation-depth": f.depth },
288
+ "data-inner": f.depth > 0 ? "" : void 0,
289
+ "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);
282
301
  } : void 0,
283
302
  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))
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))
288
307
  ].filter(Boolean).join(". ") }),
289
- /* @__PURE__ */ S("span", { className: i.labelCell, children: [
290
- T ? /* @__PURE__ */ l(
308
+ /* @__PURE__ */ O("span", { className: o.labelCell, children: [
309
+ R ? /* @__PURE__ */ c(
291
310
  "button",
292
311
  {
293
312
  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 })
313
+ 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 })
299
318
  }
300
- ) : /* @__PURE__ */ l("span", { className: i.disclosure, "aria-hidden": "true" }),
301
- /* @__PURE__ */ l("span", { className: i.label, "aria-hidden": "true", children: r.label })
319
+ ) : /* @__PURE__ */ c("span", { className: o.disclosure, "aria-hidden": "true" }),
320
+ /* @__PURE__ */ c("span", { className: o.label, "aria-hidden": "true", children: r.label })
302
321
  ] }),
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 ? (
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: [
326
+ s ? (
308
327
  /* 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)
328
+ s.map(
329
+ (b, U) => E[U].own.absence && /* @__PURE__ */ c(se, { children: h.calculationMissing(b.unit ?? b.label) }, b.id)
311
330
  )
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)) })
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)) })
315
334
  ] }),
316
- oe.length > 0 && /* A click here - on a link in the aside, on a sparkline - is the
335
+ le.length > 0 && /* A click here - on a link in the aside, on a sparkline - is the
317
336
  caller's, not a fold. */
318
- /* @__PURE__ */ l("span", { className: i.notes, onClick: (_) => _.stopPropagation(), children: oe })
337
+ /* @__PURE__ */ c("span", { className: o.notes, onClick: (b) => b.stopPropagation(), children: le })
319
338
  ]
320
339
  }
321
340
  );
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)
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)
328
347
  ] : [
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(
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,
353
+ ce,
354
+ /* @__PURE__ */ c("li", { className: o.item, "aria-hidden": "true", children: /* @__PURE__ */ O(
336
355
  "div",
337
356
  {
338
- className: i.line,
339
- style: { "--_calculation-depth": K.depth },
357
+ className: o.line,
358
+ style: { "--_calculation-depth": ne.depth },
340
359
  "data-inner": "",
341
360
  "data-closing": "",
342
- "data-mark": k === a ? "use" : void 0,
361
+ "data-mark": S === a ? "use" : void 0,
343
362
  children: [
344
- /* @__PURE__ */ S("span", { className: i.labelCell, children: [
345
- /* @__PURE__ */ l("span", { className: i.disclosure }),
346
- /* @__PURE__ */ S("span", { className: i.label, children: [
363
+ /* @__PURE__ */ O("span", { className: o.labelCell, children: [
364
+ /* @__PURE__ */ c("span", { className: o.disclosure }),
365
+ /* @__PURE__ */ O("span", { className: o.label, children: [
347
366
  "= ",
348
367
  r.label
349
368
  ] })
350
369
  ] }),
351
- /* @__PURE__ */ l("span", { className: i.names }),
352
- /* @__PURE__ */ l("span", { className: i.operator }),
353
- P(M, !0)
370
+ /* @__PURE__ */ c("span", { className: o.names }),
371
+ /* @__PURE__ */ c("span", { className: o.operator }),
372
+ D(E, !0)
354
373
  ]
355
374
  }
356
375
  ) })
357
376
  ] })
358
- ] }, x)
377
+ ] }, A)
359
378
  ];
360
- }, N = $(n.result, !1, { depth: 0, flat: !0, parent: null }, "r");
379
+ }, $e = q(e.result, !1, { depth: 0, flat: !0, parent: null }, "r");
361
380
  return (
362
381
  /* The frame is the surface and the container the layout measures itself
363
382
  against; the list inside it is the statement. */
364
- /* @__PURE__ */ l(
383
+ /* @__PURE__ */ c(
365
384
  "div",
366
385
  {
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
386
+ ...p,
387
+ ref: oe,
388
+ className: gt(o.frame, m),
389
+ style: s ? {
390
+ "--_calculation-figure-tracks": Array(k * 2).fill("auto").join(" "),
391
+ "--_calculation-figures-end": Q(k),
392
+ "--_calculation-assessment-column": Q(k),
393
+ ...i
394
+ } : 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: [
400
+ s && /* The head names each metric and its unit above its column. Every
381
401
  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(
402
+ /* @__PURE__ */ c("li", { className: o.item, "aria-hidden": "true", children: /* @__PURE__ */ c("div", { className: o.head, children: s.map((a, u) => /* @__PURE__ */ O(
383
403
  "span",
384
404
  {
385
- className: i.headCell,
405
+ className: o.headCell,
386
406
  "data-unit": a.unit === void 0 ? void 0 : "",
387
- style: { "--_calculation-column": z(o) },
407
+ style: { "--_calculation-column": Q(u) },
388
408
  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 })
409
+ /* @__PURE__ */ c("span", { className: o.headLabel, children: a.label }),
410
+ a.unit !== void 0 && /* @__PURE__ */ c("span", { className: o.headUnit, children: a.unit })
391
411
  ]
392
412
  },
393
413
  a.id
394
414
  )) }) }),
395
- N
415
+ $e
396
416
  ] })
397
417
  }
398
418
  )
399
419
  );
400
420
  }
401
421
  export {
402
- bn as CalculationView
422
+ xt as CalculationView
403
423
  };