@umriss-ui/calculation 0.44.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,115 +1,121 @@
1
1
  "use client";
2
2
  import "./calculation.css";
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";
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
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 && $e(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 $e(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 = we(e, t)) {
22
- return $e(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, r, g) => m[g] ? n - r : n + r, 0);
29
+ return t.reduce((n, l, g) => f[g] ? n - l : n + l, 0);
30
30
  case "difference":
31
- return d.reduce((n, r) => n - r, i);
31
+ return u.reduce((n, l) => n - l, i);
32
32
  case "product":
33
- return d.reduce((n, r) => n * r, 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 r = 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) ? r = 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
- r = 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 = we(n, r);
64
- p = J(n, S, C) !== J(n, r, 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 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
+ 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 = {
70
+ value: l,
69
71
  absence: g,
70
- shown: r === null ? null : J(n, r),
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, q), q;
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
- function je() {
84
+ function Ue() {
82
85
  try {
83
86
  return process.env.NODE_ENV !== "production";
84
87
  } catch {
85
88
  return !1;
86
89
  }
87
90
  }
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}`));
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}`));
91
94
  }
92
- const ge = 4;
93
- function Ie(e, t, m) {
95
+ const be = 4;
96
+ function Ve(e, t, f) {
94
97
  const i = e.operands[t];
95
98
  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
+ 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 };
99
102
  return n && !p.negated ? void 0 : p;
100
103
  }
101
- const Ve = {
104
+ const ze = {
102
105
  sum: "calculationSumSymbol",
103
106
  difference: "calculationDifferenceSymbol",
104
107
  product: "calculationProductSymbol",
105
108
  quotient: "calculationQuotientSymbol"
106
- }, ze = {
109
+ }, He = {
107
110
  sum: "calculationSumWord",
108
111
  difference: "calculationDifferenceWord",
109
112
  product: "calculationProductWord",
110
113
  quotient: "calculationQuotientWord"
111
114
  };
112
- 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) {
113
119
  switch (e) {
114
120
  case "alarm":
115
121
  return t.verdictAlarm;
@@ -121,315 +127,319 @@ function K(e, t) {
121
127
  return t.verdictOk;
122
128
  }
123
129
  }
124
- function ee(e, t, m) {
130
+ function ne(e, t, f) {
125
131
  const i = e.negated ? "difference" : e.operator;
126
- return m[(t ? ze : Ve)[i]];
132
+ return f[(t ? He : ze)[i]];
127
133
  }
128
- function He(e, t) {
134
+ function Ge(e, t) {
129
135
  return e.kind === "missing" ? t.calculationMissing(e.label) : t.calculationDivisionByZero(e.label);
130
136
  }
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;
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;
134
140
  }
135
- function Qe(e, t, m, i, d, n, r, g = () => {
141
+ function Ye(e, t, f, i, u, n, l, g = () => {
136
142
  }) {
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) => {
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) => {
141
147
  if (i || !p.operator) return {};
142
148
  if (p.operands.length === 0) return { names: n.calculationNoOperands };
143
- if (!v && p.operands.length > ge)
149
+ if (!N && p.operands.length > be)
144
150
  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);
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);
148
154
  }).join(" ");
149
155
  return {
150
- names: k((_) => _.label),
151
- numbers: k((_, W) => T(_, t.get(_.key), v, W))
156
+ names: q((_) => _.label),
157
+ numbers: q((_, F) => C(_, t.get(_.key), N, F))
152
158
  };
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: $ };
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 };
165
172
  }
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(", ")
169
- );
170
- 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}` : ""}`;
171
178
  }
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(" ");
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(" ");
197
205
  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: [
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: [
200
208
  n,
201
- d.age !== null && ` · ${m.relative(d.age)}`
209
+ u.age !== null && ` · ${f.relative(u.age)}`
202
210
  ] });
203
211
  }
204
- function yt({
212
+ function At({
205
213
  model: e,
206
214
  ref: t,
207
- className: m,
215
+ className: f,
208
216
  style: i,
209
- density: d,
217
+ density: u,
210
218
  "aria-label": n,
211
- "aria-labelledby": r,
219
+ "aria-labelledby": l,
212
220
  "aria-describedby": g,
213
221
  ...p
214
222
  }) {
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(
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(
217
225
  (a) => {
218
- $.current = a, typeof t == "function" ? t(a) : t && (t.current = a);
226
+ k.current = a, typeof t == "function" ? t(a) : t && (t.current = a);
219
227
  },
220
228
  [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);
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);
225
233
  return;
226
234
  }
227
- const A = u.slice(2, f).reduce((x, E) => x + E, 0);
235
+ const E = d.slice(2, m).reduce((x, T) => x + T, 0);
228
236
  let c = 0;
229
237
  const B = document.createRange();
230
238
  for (const x of a.querySelectorAll(`.${o.label}`)) {
231
239
  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));
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));
236
244
  }
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(
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(
250
258
  a,
251
- u,
252
- 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)
253
261
  );
254
- let W = !1;
255
- const j = (a, u) => a.map(({ own: f, text: A }, c) => [
256
- /* @__PURE__ */ O(
262
+ let _ = !1;
263
+ const F = (a, d) => a.map(({ own: m, text: E }, c) => [
264
+ /* @__PURE__ */ $(
257
265
  "span",
258
266
  {
259
267
  className: o.amount,
260
268
  "aria-hidden": "true",
261
- "data-verdict": f.verdict,
269
+ "data-verdict": m.verdict,
270
+ "data-quality": m.quality === "good" ? void 0 : m.quality,
262
271
  "data-later": c > 0 ? "" : void 0,
263
- style: s ? { "--_calculation-column": Q(c) } : void 0,
272
+ style: s ? { "--_calculation-column": Z(c) } : void 0,
264
273
  children: [
265
- f.approximate && /* @__PURE__ */ l(Re, { content: h.calculationApproximateNote, children: /* @__PURE__ */ l("span", { className: o.approximate, children: "≈" }) }),
266
- 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
267
276
  ]
268
277
  },
269
278
  `amount-${c}`
270
279
  ),
271
- /* @__PURE__ */ l(
280
+ /* @__PURE__ */ r(
272
281
  "span",
273
282
  {
274
283
  className: o.unit,
275
284
  "aria-hidden": "true",
276
- style: s ? { "--_calculation-column": bt(c) } : void 0,
285
+ style: s ? { "--_calculation-column": yt(c) } : void 0,
277
286
  "data-last": s && c === a.length - 1 ? "" : void 0,
278
- children: s && !u ? void 0 : A.unit
287
+ children: s && !d ? void 0 : E.unit
279
288
  },
280
289
  `unit-${c}`
281
290
  )
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(
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__ */ $(
296
305
  "div",
297
306
  {
298
307
  className: o.line,
299
- style: { "--_calculation-depth": f.depth },
300
- "data-inner": f.depth > 0 ? "" : void 0,
308
+ style: { "--_calculation-depth": m.depth },
309
+ "data-inner": m.depth > 0 ? "" : void 0,
301
310
  "data-kind": de,
302
311
  "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),
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),
311
320
  onClick: L ? () => {
312
- window.getSelection()?.toString() || k(a);
321
+ window.getSelection()?.toString() || N(a);
313
322
  } : void 0,
314
323
  children: [
315
- /* @__PURE__ */ l(Be, { children: [
316
- s ? Ge(c.label, B.map((b) => b.text), s, h, f.position) : x.sentence,
324
+ /* @__PURE__ */ r(We, { children: [
325
+ s ? Ze(c.label, B.map((b) => b.text), s, h, m.position) : x.sentence,
317
326
  B.some((b) => b.own.approximate) && h.calculationApproximateNote,
318
- H !== void 0 && h.calculationWorstInside(K(H, h))
327
+ Y !== void 0 && h.calculationWorstInside(ee(Y, h))
319
328
  ].filter(Boolean).join(". ") }),
320
- /* @__PURE__ */ O("span", { className: o.labelCell, children: [
321
- L ? /* @__PURE__ */ l(
329
+ /* @__PURE__ */ $("span", { className: o.labelCell, children: [
330
+ L ? /* @__PURE__ */ r(
322
331
  "button",
323
332
  {
324
333
  type: "button",
325
334
  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 })
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 })
330
339
  }
331
- ) : /* @__PURE__ */ l("span", { className: o.disclosure, "aria-hidden": "true" }),
332
- /* @__PURE__ */ l("span", { className: o.label, "aria-hidden": "true", children: c.label })
340
+ ) : /* @__PURE__ */ r("span", { className: o.disclosure, "aria-hidden": "true" }),
341
+ /* @__PURE__ */ r("span", { className: o.label, "aria-hidden": "true", children: c.label })
333
342
  ] }),
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: [
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: [
338
347
  s ? (
339
348
  /* Short: which metric. The sentence carries the full reason. */
340
349
  s.map(
341
- (b, U) => B[U].own.absence && /* @__PURE__ */ l(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)
342
351
  )
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)) })
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)) })
346
356
  ] }),
347
- 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
348
358
  caller's, not a fold. */
349
- /* @__PURE__ */ l("span", { className: o.notes, onClick: (b) => b.stopPropagation(), children: le })
359
+ /* @__PURE__ */ r("span", { className: o.notes, onClick: (b) => b.stopPropagation(), children: ue })
350
360
  ]
351
361
  }
352
362
  );
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)
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)
359
369
  ] : [
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,
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,
365
375
  ce,
366
- /* @__PURE__ */ l("li", { className: o.item, "aria-hidden": "true", children: /* @__PURE__ */ O(
376
+ /* @__PURE__ */ r("li", { className: o.item, "aria-hidden": "true", children: /* @__PURE__ */ $(
367
377
  "div",
368
378
  {
369
379
  className: o.line,
370
- style: { "--_calculation-depth": ne.depth },
380
+ style: { "--_calculation-depth": ae.depth },
371
381
  "data-inner": "",
372
382
  "data-closing": "",
373
- "data-mark": S === a ? "use" : void 0,
383
+ "data-mark": v === a ? "use" : void 0,
374
384
  children: [
375
- /* @__PURE__ */ O("span", { className: o.labelCell, children: [
376
- /* @__PURE__ */ l("span", { className: o.disclosure }),
377
- /* @__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: [
378
388
  "= ",
379
389
  c.label
380
390
  ] })
381
391
  ] }),
382
- /* @__PURE__ */ l("span", { className: o.names }),
383
- /* @__PURE__ */ l("span", { className: o.operator }),
384
- j(B, !0)
392
+ /* @__PURE__ */ r("span", { className: o.names }),
393
+ /* @__PURE__ */ r("span", { className: o.operator }),
394
+ F(B, !0)
385
395
  ]
386
396
  }
387
397
  ) })
388
398
  ] })
389
- ] }, A)
399
+ ] }, E)
390
400
  ];
391
- }, xe = F(e.result, !1, { depth: 0, flat: !0, parent: null }, "r");
401
+ }, Q = j(e.result, !1, { depth: 0, flat: !0, parent: null }, "r");
392
402
  return (
393
403
  /* The frame is the surface and the container the layout measures itself
394
404
  against; the list inside it is the statement. */
395
- /* @__PURE__ */ l(
405
+ /* @__PURE__ */ r(
396
406
  "div",
397
407
  {
398
408
  ...p,
399
- ref: oe,
400
- className: wt(o.frame, m),
409
+ ref: w,
410
+ className: qt(o.frame, f),
401
411
  style: s ? {
402
- "--_calculation-figure-tracks": Array(y * 2).fill("auto").join(" "),
403
- "--_calculation-figures-end": Q(y),
404
- "--_calculation-assessment-column": Q(y),
412
+ "--_calculation-figure-tracks": Array(A * 2).fill("auto").join(" "),
413
+ "--_calculation-figures-end": Z(A),
414
+ "--_calculation-assessment-column": Z(A),
405
415
  ...i
406
416
  } : 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: [
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: [
412
422
  s && /* The head names each metric and its unit above its column. Every
413
423
  row's sentence names them too, so the head is for the eye. */
414
- /* @__PURE__ */ l("li", { className: o.item, "aria-hidden": "true", children: /* @__PURE__ */ l("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__ */ $(
415
425
  "span",
416
426
  {
417
427
  className: o.headCell,
418
428
  "data-unit": a.unit === void 0 ? void 0 : "",
419
- style: { "--_calculation-column": Q(u) },
429
+ style: { "--_calculation-column": Z(d) },
420
430
  children: [
421
- /* @__PURE__ */ l("span", { className: o.headLabel, children: a.label }),
422
- a.unit !== void 0 && /* @__PURE__ */ l("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 })
423
433
  ]
424
434
  },
425
435
  a.id
426
436
  )) }) }),
427
- xe
437
+ Q
428
438
  ] })
429
439
  }
430
440
  )
431
441
  );
432
442
  }
433
443
  export {
434
- yt as CalculationView
444
+ At as CalculationView
435
445
  };