@umriss-ui/calculation 0.41.1 → 0.42.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.
- package/CHANGELOG.md +24 -3
- package/README.md +15 -5
- package/dist/calculation.client.js +403 -0
- package/dist/calculation.css +1 -1
- package/dist/calculation.js +19 -558
- package/dist/calculation.model-DU6T1D09.js +168 -0
- package/dist/index.d.ts +1 -1
- package/docs/llms-full.md +6 -6
- package/package.json +7 -6
package/dist/calculation.js
CHANGED
|
@@ -1,561 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
import "./calculation.
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return t.decimals !== void 0 ? t.decimals : t.format === "percent" ? 1 : t.given ? void 0 : 2;
|
|
8
|
-
}
|
|
9
|
-
function ge(t, e) {
|
|
10
|
-
const [f, s = "0"] = String(t).split("e");
|
|
11
|
-
return +`${f}e${Number(s) + e}`;
|
|
12
|
-
}
|
|
13
|
-
function Qe(t, e) {
|
|
14
|
-
return e === void 0 ? t : Math.sign(t) * ge(Math.round(ge(Math.abs(t), e)), -e) || 0;
|
|
15
|
-
}
|
|
16
|
-
function ae(t, e) {
|
|
17
|
-
return Qe(t.format === "percent" ? e * 100 : e, Ue(t));
|
|
18
|
-
}
|
|
19
|
-
const Ve = (t, e) => t.format === "percent" ? e / 100 : e;
|
|
20
|
-
function be(t, e, f) {
|
|
21
|
-
const [s, ...r] = e;
|
|
22
|
-
switch (t) {
|
|
23
|
-
case "sum":
|
|
24
|
-
return e.reduce((n, c, S) => f[S] ? n - c : n + c, 0);
|
|
25
|
-
case "difference":
|
|
26
|
-
return r.reduce((n, c) => n - c, s);
|
|
27
|
-
case "product":
|
|
28
|
-
return r.reduce((n, c) => n * c, s);
|
|
29
|
-
case "quotient":
|
|
30
|
-
return s / r[0];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const $e = (t, e) => e === void 0 || t !== void 0 && se(t) >= se(e) ? t : e;
|
|
34
|
-
function ze(t) {
|
|
35
|
-
const e = /* @__PURE__ */ new Map(), f = (s) => {
|
|
36
|
-
const r = e.get(s);
|
|
37
|
-
if (r) return r;
|
|
38
|
-
const n = t.quantities.get(s);
|
|
39
|
-
let c = null, S, l = !1, w;
|
|
40
|
-
if (n.given) {
|
|
41
|
-
const a = n.given.value;
|
|
42
|
-
typeof a == "number" && Number.isFinite(a) ? c = a : S = { kind: "missing", label: n.label };
|
|
43
|
-
} else {
|
|
44
|
-
const a = n.operands.map((m) => ({ operand: m, ...f(m.key) }));
|
|
45
|
-
for (const { operand: m, verdict: i, worst: b } of a) {
|
|
46
|
-
const y = m.reference ? i : $e(i, b);
|
|
47
|
-
w = $e(w, y);
|
|
48
|
-
}
|
|
49
|
-
S = a.find((m) => m.absence)?.absence;
|
|
50
|
-
const u = a[1];
|
|
51
|
-
if (!S && n.operator === "quotient" && u.value === 0 && (S = { kind: "zero", label: t.quantities.get(u.operand.key).label }), !S) {
|
|
52
|
-
const m = n.operands.map((b) => b.negated === !0);
|
|
53
|
-
c = be(n.operator, a.map((b) => b.value), m);
|
|
54
|
-
const i = be(
|
|
55
|
-
n.operator,
|
|
56
|
-
a.map((b) => Ve(t.quantities.get(b.operand.key), b.shown)),
|
|
57
|
-
m
|
|
58
|
-
);
|
|
59
|
-
l = ae(n, i) !== ae(n, c);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const T = { target: n.target, limits: n.limits }, B = n.target !== void 0 || (n.limits?.length ?? 0) > 0 ? Pe(c, T) : void 0, U = (n.limits?.length ?? 0) > 0 ? B.verdict : c === null ? "unknown" : void 0, L = {
|
|
63
|
-
value: c,
|
|
64
|
-
absence: S,
|
|
65
|
-
shown: c === null ? null : ae(n, c),
|
|
66
|
-
approximate: l,
|
|
67
|
-
assessment: B,
|
|
68
|
-
verdict: U,
|
|
69
|
-
worst: w
|
|
70
|
-
};
|
|
71
|
-
return e.set(s, L), L;
|
|
72
|
-
};
|
|
73
|
-
for (const s of t.quantities.keys()) f(s);
|
|
74
|
-
return e;
|
|
75
|
-
}
|
|
76
|
-
const Ge = () => null, He = () => null, Ke = () => null, Ye = () => null, Je = () => null, _e = () => null, Ze = () => null, Xe = () => null, et = () => null, tt = () => null, nt = () => null, ce = () => null, at = /* @__PURE__ */ new Map([
|
|
77
|
-
[He, "sum"],
|
|
78
|
-
[Ke, "difference"],
|
|
79
|
-
[Ye, "product"],
|
|
80
|
-
[Je, "quotient"]
|
|
81
|
-
]), we = {
|
|
82
|
-
sum: "Sum",
|
|
83
|
-
difference: "Difference",
|
|
84
|
-
product: "Product",
|
|
85
|
-
quotient: "Quotient"
|
|
86
|
-
}, ue = /* @__PURE__ */ new Map([
|
|
87
|
-
[Xe, { name: "Plus", operator: "sum" }],
|
|
88
|
-
[et, { name: "Minus", operator: "sum", negated: !0 }],
|
|
89
|
-
[tt, { name: "Times", operator: "product" }],
|
|
90
|
-
[nt, { name: "DividedBy", operator: "quotient" }]
|
|
91
|
-
]), de = "<Given>, <Sum>, <Difference>, <Product>, <Quotient> or <Chain>", ye = "a calculation with metrics only adds and subtracts - <Sum>, <Difference>, <Plus>, <Minus>.", ot = ["unit", "format", "decimals"];
|
|
92
|
-
function N(t) {
|
|
93
|
-
throw new Error(`@umriss-ui/calculation: ${t}`);
|
|
94
|
-
}
|
|
95
|
-
function ee(t) {
|
|
96
|
-
return Me.toArray(t).flatMap(
|
|
97
|
-
(e) => H(e) && e.type === Te ? ee(e.props.children) : [e]
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
function ne(t) {
|
|
101
|
-
if (!H(t)) return JSON.stringify(t);
|
|
102
|
-
const e = t.type;
|
|
103
|
-
return typeof e == "string" ? `<${e}>` : `<${e.displayName ?? e.name ?? "anonymous"}>`;
|
|
104
|
-
}
|
|
105
|
-
const fe = (t, e, f) => `${t}/${H(e) && e.key || f}`;
|
|
106
|
-
function st(t, e) {
|
|
107
|
-
const f = ee(t);
|
|
108
|
-
if (f.length !== 1 && N(`<Calculation> takes exactly one child, the result; it was given ${f.length}.`), e !== void 0) {
|
|
109
|
-
e.length === 0 && N("<Calculation>: metrics is empty; leave it out for a calculation with one number per quantity.");
|
|
110
|
-
const a = /* @__PURE__ */ new Set();
|
|
111
|
-
for (const { id: u } of e)
|
|
112
|
-
a.has(u) && N(`<Calculation>: the metric id "${u}" is used twice.`), a.add(u);
|
|
113
|
-
}
|
|
114
|
-
const s = e?.map((a) => `"${a.id}"`).join(", "), r = (a, u) => {
|
|
115
|
-
const m = typeof a == "object" && a !== null;
|
|
116
|
-
if (e === void 0) {
|
|
117
|
-
m && N(`${u}: value is an object by metric, but the calculation has no metrics.`);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
m || N(`${u}: with metrics, value is an object with a number for each metric - ${s}.`);
|
|
121
|
-
for (const { id: i } of e)
|
|
122
|
-
i in a || N(`${u}: value has no number for the metric "${i}"; write null where it is absent. The metrics: ${s}.`);
|
|
123
|
-
for (const i of Object.keys(a))
|
|
124
|
-
e.some((b) => b.id === i) || N(`${u}: value has a number for "${i}", which is no metric. The metrics: ${s}.`);
|
|
125
|
-
}, n = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), S = [], l = (a, u, m) => {
|
|
126
|
-
const { id: i, ...b } = u;
|
|
127
|
-
if (e !== void 0) {
|
|
128
|
-
for (const A of ot)
|
|
129
|
-
u[A] !== void 0 && N(`${m}: ${A} belongs to the metric once the calculation has metrics, not to a quantity.`);
|
|
130
|
-
(u.target !== void 0 || u.limits !== void 0) && N(`${m}: target and limits are not assessed in a calculation with metrics.`);
|
|
131
|
-
}
|
|
132
|
-
i !== void 0 && (c.has(i) && N(`${m}: the id "${i}" is used twice.`), c.set(i, a));
|
|
133
|
-
const y = { ...b, key: a, id: i, operands: [] };
|
|
134
|
-
return n.set(a, y), y;
|
|
135
|
-
}, w = (a, u, m) => {
|
|
136
|
-
if (H(a) && a.type === _e) {
|
|
137
|
-
const i = { key: "", reference: !0 };
|
|
138
|
-
return S.push({ operand: i, to: a.props.to, where: m }), i;
|
|
139
|
-
}
|
|
140
|
-
return { key: T(a, u, m), reference: !1 };
|
|
141
|
-
}, T = (a, u, m) => {
|
|
142
|
-
if ((!H(a) || a.type === _e || ue.has(a.type) || a.type === ce) && N(`${m}: ${ne(a)} cannot stand here; a quantity must be ${de}.`), a.type === Ze) return B(a.props.children, u, m);
|
|
143
|
-
const i = at.get(a.type);
|
|
144
|
-
a.type !== Ge && i === void 0 && N(
|
|
145
|
-
`${m}: ${ne(a)} is not an element of the calculation. A calculation reads its children's props and cannot look inside a component of your own; write ${de} or <Ref> directly, or return them from .map.`
|
|
146
|
-
);
|
|
147
|
-
const { children: b, value: y, source: A, asOf: Q, ages: k, ...R } = a.props, g = `${m} › ${R.label}`;
|
|
148
|
-
e !== void 0 && (i === "product" || i === "quotient") && N(`${g}: <${we[i]}> - ${ye}`);
|
|
149
|
-
const C = l(u, R, g);
|
|
150
|
-
if (i === void 0)
|
|
151
|
-
return r(y, g), C.given = { value: y, source: A, asOf: Q, ages: k }, u;
|
|
152
|
-
C.operator = i;
|
|
153
|
-
const _ = ee(b), O = _.length;
|
|
154
|
-
return (i === "quotient" ? O !== 2 : i !== "sum" && O < 2) && N(
|
|
155
|
-
`${g}: <${we[i]}> takes ${i === "quotient" ? "exactly two operands" : "two or more operands"}; it was given ${O}.`
|
|
156
|
-
), C.operands = _.map((o, d) => w(o, fe(u, o, d), g)), u;
|
|
157
|
-
}, B = (a, u, m) => {
|
|
158
|
-
const i = `${m} › <Chain>`, [b, ...y] = ee(a);
|
|
159
|
-
(b === void 0 || H(b) && (ue.has(b.type) || b.type === ce)) && N(`${i}: a chain starts with a quantity that has no operator - ${de} or <Ref>.`);
|
|
160
|
-
let A = w(b, fe(u, b, 0), i), Q = ne(b), k = [], R;
|
|
161
|
-
return y.forEach((g, C) => {
|
|
162
|
-
const _ = fe(u, g, C + 1);
|
|
163
|
-
if (H(g) && g.type === ce) {
|
|
164
|
-
const F = g.props, z = `${i} › ${F.label}`;
|
|
165
|
-
k.length === 0 && N(`${z}: an <Interim> needs an operand since the named value before it, ${Q}.`);
|
|
166
|
-
const G = l(_, F, z);
|
|
167
|
-
G.interim = !0, G.operator = k[0].line.operator, G.operands = [A, ...k.map((te) => te.operand)], A = { key: _, reference: !1, previous: !0 }, Q = `<Interim label="${F.label}">`, k = [], R = _;
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
const O = H(g) ? ue.get(g.type) : void 0;
|
|
171
|
-
O === void 0 && N(`${i}: ${ne(g)} needs an operator in a chain - <Plus>, <Minus>, <Times> or <DividedBy> - or is an <Interim>.`), e !== void 0 && O.operator !== "sum" && N(`${i}: <${O.name}> - ${ye}`);
|
|
172
|
-
const o = O.operator !== "sum", d = k.find((F) => F.line.operator !== "sum");
|
|
173
|
-
(o && k.length > 0 || d) && N(
|
|
174
|
-
`${i}: <${(d ?? { line: O }).line.name}> stands alone between two named values - directly after the first quantity or an <Interim>, and directly before an <Interim>.`
|
|
175
|
-
);
|
|
176
|
-
const { children: v, ...q } = g.props, p = ee(v), D = () => N(`${i}: <${O.name}> takes either a label and a value, or exactly one quantity as its child.`);
|
|
177
|
-
if (p.length > 0) {
|
|
178
|
-
(p.length > 1 || Object.values(q).some((z) => z !== void 0)) && D();
|
|
179
|
-
const F = w(p[0], _, i);
|
|
180
|
-
F.negated = O.negated, k.push({ operand: F, line: O });
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
q.label === void 0 && D();
|
|
184
|
-
const { value: I, source: M, asOf: P, ages: K, ...V } = q, j = `${i} › ${q.label}`, W = l(_, { ...V, label: q.label }, j);
|
|
185
|
-
r(I, j), W.given = { value: I, source: M, asOf: P, ages: K }, k.push({ operand: { key: _, reference: !1, negated: O.negated }, line: O });
|
|
186
|
-
}), (k.length > 0 || R === void 0) && N(`${i}: a chain ends with an <Interim>, which names its value.`), R;
|
|
187
|
-
}, U = T(f[0], "0", "<Calculation>"), L = n.get(U);
|
|
188
|
-
(L.emphasis !== void 0 || L.rule !== void 0) && N(`<Calculation> › ${L.label}: emphasis and rule do not stand on the Result, which is already the heaviest line.`);
|
|
189
|
-
for (const { operand: a, to: u, where: m } of S) {
|
|
190
|
-
const i = c.get(u);
|
|
191
|
-
if (i === void 0) {
|
|
192
|
-
const b = [...c.keys()].map((y) => `"${y}"`).join(", ");
|
|
193
|
-
N(`${m}: <Ref to="${u}"> names no quantity. ${b ? `The ids that exist: ${b}.` : "No quantity has an id."}`);
|
|
194
|
-
}
|
|
195
|
-
a.key = i;
|
|
196
|
-
}
|
|
197
|
-
return rt(n), { result: U, quantities: n, metrics: e };
|
|
198
|
-
}
|
|
199
|
-
function it(t) {
|
|
200
|
-
return t.metrics ? t.metrics.map((e) => {
|
|
201
|
-
const f = /* @__PURE__ */ new Map();
|
|
202
|
-
for (const [s, r] of t.quantities) {
|
|
203
|
-
const n = r.given && { ...r.given, value: r.given.value[e.id] };
|
|
204
|
-
f.set(s, { ...r, unit: e.unit, decimals: e.decimals, given: n });
|
|
205
|
-
}
|
|
206
|
-
return { result: t.result, quantities: f };
|
|
207
|
-
}) : [t];
|
|
208
|
-
}
|
|
209
|
-
function rt(t) {
|
|
210
|
-
const e = /* @__PURE__ */ new Set(), f = [], s = (r) => {
|
|
211
|
-
if (e.has(r)) return;
|
|
212
|
-
const n = f.indexOf(r);
|
|
213
|
-
if (n !== -1) {
|
|
214
|
-
const c = [...f.slice(n), r].map((S) => t.get(S).label);
|
|
215
|
-
N(`the calculation goes round in a circle through references: ${c.join(" → ")}.`);
|
|
216
|
-
}
|
|
217
|
-
f.push(r);
|
|
218
|
-
for (const c of t.get(r).operands) s(c.key);
|
|
219
|
-
f.pop(), e.add(r);
|
|
220
|
-
};
|
|
221
|
-
for (const r of t.keys()) s(r);
|
|
222
|
-
}
|
|
223
|
-
const Ne = 4;
|
|
224
|
-
function lt(t, e, f) {
|
|
225
|
-
const s = t.operands[e];
|
|
226
|
-
if (s.previous) return;
|
|
227
|
-
const r = t.operator, n = e === 0;
|
|
228
|
-
if (r !== "sum" && r !== "difference") return n ? void 0 : { operator: r, negated: !1 };
|
|
229
|
-
const c = r === "difference" ? !n : s.negated === !0, S = new Set(f.filter((w) => w !== null && w !== 0).map(Math.sign)), l = S.size === 1 ? { operator: "sum", negated: c !== S.has(-1), unsigned: !0 } : { operator: "sum", negated: c };
|
|
230
|
-
return n && !l.negated ? void 0 : l;
|
|
231
|
-
}
|
|
232
|
-
const ct = {
|
|
233
|
-
sum: "calculationSumSymbol",
|
|
234
|
-
difference: "calculationDifferenceSymbol",
|
|
235
|
-
product: "calculationProductSymbol",
|
|
236
|
-
quotient: "calculationQuotientSymbol"
|
|
237
|
-
}, ut = {
|
|
238
|
-
sum: "calculationSumWord",
|
|
239
|
-
difference: "calculationDifferenceWord",
|
|
240
|
-
product: "calculationProductWord",
|
|
241
|
-
quotient: "calculationQuotientWord"
|
|
242
|
-
};
|
|
243
|
-
function oe(t, e) {
|
|
244
|
-
switch (t) {
|
|
245
|
-
case "alarm":
|
|
246
|
-
return e.verdictAlarm;
|
|
247
|
-
case "warning":
|
|
248
|
-
return e.verdictWarning;
|
|
249
|
-
case "unknown":
|
|
250
|
-
return e.verdictUnknown;
|
|
251
|
-
default:
|
|
252
|
-
return e.verdictOk;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
function ie(t, e, f) {
|
|
256
|
-
const s = t.negated ? "difference" : t.operator;
|
|
257
|
-
return f[(e ? ut : ct)[s]];
|
|
258
|
-
}
|
|
259
|
-
function dt(t, e) {
|
|
260
|
-
return t.kind === "missing" ? e.calculationMissing(t.label) : e.calculationDivisionByZero(t.label);
|
|
261
|
-
}
|
|
262
|
-
function Se(t, e, f, s) {
|
|
263
|
-
const r = t.format === "percent" ? s : t.unit, n = f.number(e, t.decimals);
|
|
264
|
-
return r ? `${n} ${r}` : n;
|
|
265
|
-
}
|
|
266
|
-
function ft(t, e, f, s, r, n, c, S = () => {
|
|
267
|
-
}) {
|
|
268
|
-
const l = t.quantities.get(f), w = e.get(f), T = (g, C) => g.shown !== null && C?.unsigned ? Math.abs(g.shown) : g.shown, B = (g, C, _, O) => {
|
|
269
|
-
const o = T(C, O);
|
|
270
|
-
return o === null ? _ ? n.verdictUnknown : n.statAbsentValue : Se(g, o, r, _ ? n.calculationPercent : "%");
|
|
271
|
-
}, U = (g) => {
|
|
272
|
-
if (s || !l.operator) return {};
|
|
273
|
-
if (l.operands.length === 0) return { names: n.calculationNoOperands };
|
|
274
|
-
if (!g && l.operands.length > Ne)
|
|
275
|
-
return { names: n.calculationOperandCount(l.operands.length) };
|
|
276
|
-
const C = (_) => l.operands.map((O, o) => {
|
|
277
|
-
const d = t.quantities.get(O.key), v = S(o);
|
|
278
|
-
return v ? `${ie(v, g, n)} ${_(d, v)}` : _(d);
|
|
279
|
-
}).join(" ");
|
|
280
|
-
return {
|
|
281
|
-
names: C((_) => _.label),
|
|
282
|
-
numbers: C((_, O) => B(_, e.get(_.key), g, O))
|
|
283
|
-
};
|
|
284
|
-
}, L = (g) => {
|
|
285
|
-
const C = w.assessment?.deviation;
|
|
286
|
-
if (C === void 0 || l.target === void 0) return;
|
|
287
|
-
const _ = Se(l, ae(l, l.target), r, g ? n.calculationPercent : "%");
|
|
288
|
-
return C > 0 ? n.calculationAboveTarget(_) : C < 0 ? n.calculationBelowTarget(_) : n.calculationOnTarget(_);
|
|
289
|
-
}, a = U(!1).names, u = a === void 0 || l.operands.length === 0 || l.operands.length > Ne ? a : `= ${a}`, m = U(!0), i = w.absence ? dt(w.absence, n) : void 0, b = ` ${n.calculationEquals} `, y = w.approximate ? `${n.calculationApproximately} ${B(l, w, !0, c)}` : B(l, w, !0, c), Q = [
|
|
290
|
-
(c ? `${ie(c, !0, n)} ` : "") + l.label + b + [m.names, m.numbers, y].filter(Boolean).join(`,${b}`),
|
|
291
|
-
w.verdict !== void 0 && w.verdict !== "unknown" ? oe(w.verdict, n) : void 0,
|
|
292
|
-
L(!0),
|
|
293
|
-
i
|
|
294
|
-
].filter(Boolean).join(", "), k = w.shown === null ? void 0 : l.format === "percent" ? "%" : l.unit, R = (g) => g === null ? n.statAbsentValue : r.number(g, l.decimals);
|
|
295
|
-
return { amount: R(T(w, c)), ownAmount: R(w.shown), unit: k, names: u, target: L(!1), reason: i, sentence: Q, spokenNames: m.names, spokenNumber: y };
|
|
296
|
-
}
|
|
297
|
-
function mt(t, e, f, s, r) {
|
|
298
|
-
const n = r ? `${ie(r, !0, s)} ` : "", c = e[0].spokenNames, S = n + t + (c === void 0 ? "" : ` ${s.calculationEquals} ${c}`), l = f.map(
|
|
299
|
-
(w, T) => [`${w.label} ${e[T].spokenNumber}`, e[T].reason].filter(Boolean).join(", ")
|
|
300
|
-
);
|
|
301
|
-
return `${S}: ${l.join("; ")}`;
|
|
302
|
-
}
|
|
303
|
-
const pt = "_frame_73wtl_24 _text_18806_22", ht = "_calculation_73wtl_51", vt = "_line_73wtl_86", gt = "_assessment_73wtl_98", bt = "_disclosure_73wtl_107", $t = "_amount_73wtl_90", _t = "_list_73wtl_128", wt = "_item_73wtl_129", yt = "_derivation_73wtl_130", Nt = "_labelCell_73wtl_90", St = "_names_73wtl_90", Ot = "_operator_73wtl_90", Ct = "_unit_73wtl_90", qt = "_label_73wtl_90", xt = "_approximate_73wtl_345", kt = "_target_73wtl_102", Mt = "_worst_73wtl_102", Tt = "_head_73wtl_497", Et = "_headCell_73wtl_504", At = "_headUnit_73wtl_517", Rt = "_notes_73wtl_524", Dt = "_freshness_73wtl_538", It = "_headLabel_73wtl_568", h = {
|
|
304
|
-
frame: pt,
|
|
305
|
-
calculation: ht,
|
|
306
|
-
line: vt,
|
|
307
|
-
assessment: gt,
|
|
308
|
-
disclosure: bt,
|
|
309
|
-
amount: $t,
|
|
310
|
-
list: _t,
|
|
311
|
-
item: wt,
|
|
312
|
-
derivation: yt,
|
|
313
|
-
labelCell: Nt,
|
|
314
|
-
names: St,
|
|
315
|
-
operator: Ot,
|
|
316
|
-
unit: Ct,
|
|
317
|
-
label: qt,
|
|
318
|
-
approximate: xt,
|
|
319
|
-
target: kt,
|
|
320
|
-
worst: Mt,
|
|
321
|
-
head: Tt,
|
|
322
|
-
headCell: Et,
|
|
323
|
-
headUnit: At,
|
|
324
|
-
notes: Rt,
|
|
325
|
-
freshness: Dt,
|
|
326
|
-
headLabel: It
|
|
327
|
-
}, Pt = 10, X = (t) => 4 + 2 * t, jt = (t) => 5 + 2 * t, Bt = { ok: "success", unknown: "neutral", warning: "warning", alarm: "danger" }, Lt = (...t) => t.filter(Boolean).join(" ");
|
|
328
|
-
function Wt({ asOf: t, ages: e }) {
|
|
329
|
-
const f = Oe(), s = Ce(), r = We(t, e), n = r.freshness === "lost" ? s.freshnessDisconnected : r.freshness === "stale" ? s.freshnessStale : s.freshnessFresh;
|
|
330
|
-
return /* @__PURE__ */ E("span", { className: h.freshness, "data-freshness": r.freshness, children: [
|
|
331
|
-
n,
|
|
332
|
-
r.age !== null && ` · ${f.relative(r.age)}`
|
|
333
|
-
] });
|
|
334
|
-
}
|
|
335
|
-
function Vt({ children: t, className: e, style: f, metrics: s, density: r, ...n }) {
|
|
336
|
-
const c = je(r, "regular") === "compact", S = Oe(), l = Ce(), w = Ee(), T = st(t, s), B = it(T).map((o) => ({ view: o, results: ze(o) })), [U, L] = re(() => /* @__PURE__ */ new Set()), [a, u] = re(null), m = Ae(null), [i, b] = re(!1), y = s?.length ?? 0, A = Re(() => {
|
|
337
|
-
const o = m.current, d = o && y > 0 ? getComputedStyle(o.firstElementChild).gridTemplateColumns.split(" ").map(parseFloat) : [], v = X(y) - 1;
|
|
338
|
-
if (!o || d.length <= v || d.some((M) => !Number.isFinite(M))) {
|
|
339
|
-
b(!1);
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
const q = d.slice(2, v).reduce((M, P) => M + P, 0);
|
|
343
|
-
let p = 0;
|
|
344
|
-
const D = document.createRange();
|
|
345
|
-
for (const M of o.querySelectorAll(`.${h.label}`)) {
|
|
346
|
-
D.selectNodeContents(M);
|
|
347
|
-
const P = [...D.getClientRects()].reduce((j, W) => j + W.width, 0);
|
|
348
|
-
if (P === 0) continue;
|
|
349
|
-
const K = M.parentElement, V = M.getBoundingClientRect().left - K.getBoundingClientRect().left;
|
|
350
|
-
p = Math.max(p, V + P + parseFloat(getComputedStyle(K).paddingRight));
|
|
351
|
-
}
|
|
352
|
-
const I = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
353
|
-
b(o.clientWidth - q < Math.min(p, Pt * I));
|
|
354
|
-
}, [y]);
|
|
355
|
-
De(() => A()), Ie(() => {
|
|
356
|
-
const o = m.current;
|
|
357
|
-
if (!o || y === 0) return;
|
|
358
|
-
const d = new ResizeObserver(() => A());
|
|
359
|
-
return d.observe(o), () => d.disconnect();
|
|
360
|
-
}, [A, y]);
|
|
361
|
-
const Q = (o) => L((d) => {
|
|
362
|
-
const v = new Set(d);
|
|
363
|
-
return v.delete(o) || v.add(o), v;
|
|
364
|
-
}), k = (o, d) => lt(
|
|
365
|
-
o,
|
|
366
|
-
d,
|
|
367
|
-
B.map(({ results: v }) => v.get(o.operands[d].key).shown)
|
|
368
|
-
);
|
|
369
|
-
let R = !1;
|
|
370
|
-
const g = (o, d) => o.map(({ own: v, text: q }, p) => [
|
|
371
|
-
/* @__PURE__ */ E(
|
|
372
|
-
"span",
|
|
373
|
-
{
|
|
374
|
-
className: h.amount,
|
|
375
|
-
"aria-hidden": "true",
|
|
376
|
-
"data-verdict": v.verdict,
|
|
377
|
-
"data-later": p > 0 ? "" : void 0,
|
|
378
|
-
style: s ? { "--_calculation-column": X(p) } : void 0,
|
|
379
|
-
children: [
|
|
380
|
-
v.approximate && /* @__PURE__ */ $(Fe, { content: l.calculationApproximateNote, children: /* @__PURE__ */ $("span", { className: h.approximate, children: "≈" }) }),
|
|
381
|
-
d ? q.ownAmount : q.amount
|
|
382
|
-
]
|
|
383
|
-
},
|
|
384
|
-
`amount-${p}`
|
|
385
|
-
),
|
|
386
|
-
/* @__PURE__ */ $(
|
|
387
|
-
"span",
|
|
388
|
-
{
|
|
389
|
-
className: h.unit,
|
|
390
|
-
"aria-hidden": "true",
|
|
391
|
-
style: s ? { "--_calculation-column": jt(p) } : void 0,
|
|
392
|
-
"data-last": s && p === o.length - 1 ? "" : void 0,
|
|
393
|
-
children: s && !d ? void 0 : q.unit
|
|
394
|
-
},
|
|
395
|
-
`unit-${p}`
|
|
396
|
-
)
|
|
397
|
-
]), C = (o, d) => a === null ? void 0 : o === a ? "use" : d === a ? "operand" : void 0, _ = (o, d, v, q) => {
|
|
398
|
-
const p = T.quantities.get(o), D = B.map(({ view: x, results: J }) => ({
|
|
399
|
-
own: J.get(o),
|
|
400
|
-
text: ft(x, J, o, d, S, l, v.position, (ke) => k(p, ke))
|
|
401
|
-
})), { own: I, text: M } = D[0], P = p.operator !== void 0 && !d, K = o === T.result && !d, V = P && p.operands.length > 0 && (p.interim ? v.flat : K), j = P && !V && p.operands.length > 0, W = j && U.has(o);
|
|
402
|
-
R ||= j;
|
|
403
|
-
const F = `${w}-${o}`, z = { depth: V ? v.depth : v.depth + 1, flat: !1, parent: o }, G = P ? p.operands.find((x) => x.previous) : void 0, te = G && v.flat ? _(G.key, !1, { ...v, parent: o, position: void 0 }, `${q}-c`) : [], qe = G && !v.flat ? _(G.key, !1, { ...z, flat: !0 }, `${q}-c`) : [], me = P ? p.operands.map(
|
|
404
|
-
(x, J) => x.previous ? null : _(x.key, x.reference, { ...z, position: k(p, J) }, `${q}-${J}`)
|
|
405
|
-
) : [], Z = j && !W && I.worst !== void 0 && se(I.worst) > se(I.verdict ?? "ok") ? I.worst : void 0, Y = d ? void 0 : p.given, xe = v.position ? ie(v.position, !1, l) : void 0, pe = [
|
|
406
|
-
!d && p.explanation !== void 0 && /* @__PURE__ */ $("span", { children: p.explanation }, "explanation"),
|
|
407
|
-
Y?.source !== void 0 && /* @__PURE__ */ $("span", { children: l.calculationSource(Y.source) }, "source"),
|
|
408
|
-
Y?.asOf !== void 0 && (Y.ages !== void 0 ? /* @__PURE__ */ $(Wt, { asOf: Y.asOf, ages: Y.ages }, "asOf") : /* @__PURE__ */ $("span", { children: l.asOfAgo(S.dateTime(new Date(Y.asOf), !1)) }, "asOf")),
|
|
409
|
-
!d && p.aside !== void 0 && /* @__PURE__ */ $("span", { children: p.aside }, "aside")
|
|
410
|
-
].filter(Boolean), he = K ? "result" : p.interim && !d && v.flat ? "interim" : void 0, ve = /* @__PURE__ */ E(
|
|
411
|
-
"div",
|
|
412
|
-
{
|
|
413
|
-
className: h.line,
|
|
414
|
-
style: { "--_calculation-depth": v.depth },
|
|
415
|
-
"data-inner": v.depth > 0 ? "" : void 0,
|
|
416
|
-
"data-kind": he,
|
|
417
|
-
"data-foldable": j ? "" : void 0,
|
|
418
|
-
"data-reference": d ? "" : void 0,
|
|
419
|
-
"data-emphasis": d ? void 0 : p.emphasis,
|
|
420
|
-
"data-rule": !d && p.rule ? "" : void 0,
|
|
421
|
-
"data-mark": C(o, v.parent),
|
|
422
|
-
onPointerEnter: () => u(o),
|
|
423
|
-
onPointerLeave: () => u(null),
|
|
424
|
-
onFocus: () => u(o),
|
|
425
|
-
onBlur: () => u(null),
|
|
426
|
-
onClick: j ? () => {
|
|
427
|
-
window.getSelection()?.toString() || Q(o);
|
|
428
|
-
} : void 0,
|
|
429
|
-
children: [
|
|
430
|
-
/* @__PURE__ */ $(Be, { children: [
|
|
431
|
-
s ? mt(p.label, D.map((x) => x.text), s, l, v.position) : M.sentence,
|
|
432
|
-
D.some((x) => x.own.approximate) && l.calculationApproximateNote,
|
|
433
|
-
Z !== void 0 && l.calculationWorstInside(oe(Z, l))
|
|
434
|
-
].filter(Boolean).join(". ") }),
|
|
435
|
-
/* @__PURE__ */ E("span", { className: h.labelCell, children: [
|
|
436
|
-
j ? /* @__PURE__ */ $(
|
|
437
|
-
"button",
|
|
438
|
-
{
|
|
439
|
-
type: "button",
|
|
440
|
-
className: h.disclosure,
|
|
441
|
-
"aria-expanded": W,
|
|
442
|
-
"aria-controls": F,
|
|
443
|
-
"aria-label": (W ? l.calculationHideDerivation : l.calculationShowDerivation)(p.label),
|
|
444
|
-
children: /* @__PURE__ */ $(Le, { "data-open": W ? "" : void 0 })
|
|
445
|
-
}
|
|
446
|
-
) : /* @__PURE__ */ $("span", { className: h.disclosure, "aria-hidden": "true" }),
|
|
447
|
-
/* @__PURE__ */ $("span", { className: h.label, "aria-hidden": "true", children: p.label })
|
|
448
|
-
] }),
|
|
449
|
-
/* @__PURE__ */ $("span", { className: h.names, "aria-hidden": "true", children: P && !V && !W ? M.names : void 0 }),
|
|
450
|
-
/* @__PURE__ */ $("span", { className: h.operator, "aria-hidden": "true", children: xe }),
|
|
451
|
-
g(D, he !== void 0),
|
|
452
|
-
/* @__PURE__ */ E("span", { className: h.assessment, "aria-hidden": "true", children: [
|
|
453
|
-
s ? (
|
|
454
|
-
/* Short: which metric. The sentence carries the full reason. */
|
|
455
|
-
s.map(
|
|
456
|
-
(x, J) => D[J].own.absence && /* @__PURE__ */ $(le, { children: l.calculationMissing(x.unit ?? x.label) }, x.id)
|
|
457
|
-
)
|
|
458
|
-
) : M.reason !== void 0 ? /* @__PURE__ */ $(le, { children: M.reason }) : I.verdict !== void 0 && /* @__PURE__ */ $(le, { tone: Bt[I.verdict], children: oe(I.verdict, l) }),
|
|
459
|
-
M.target !== void 0 && /* @__PURE__ */ $("span", { className: h.target, children: M.target }),
|
|
460
|
-
Z !== void 0 && /* @__PURE__ */ $("span", { className: h.worst, "data-verdict": Z, children: l.calculationWorstInside(oe(Z, l)) })
|
|
461
|
-
] }),
|
|
462
|
-
pe.length > 0 && /* A click here - on a link in the aside, on a sparkline - is the
|
|
463
|
-
caller's, not a fold. */
|
|
464
|
-
/* @__PURE__ */ $("span", { className: h.notes, onClick: (x) => x.stopPropagation(), children: pe })
|
|
465
|
-
]
|
|
466
|
-
}
|
|
467
|
-
);
|
|
468
|
-
return V ? [
|
|
469
|
-
...te,
|
|
470
|
-
/* @__PURE__ */ E("li", { className: h.item, children: [
|
|
471
|
-
/* @__PURE__ */ $("ul", { className: h.list, children: me }),
|
|
472
|
-
ve
|
|
473
|
-
] }, q)
|
|
474
|
-
] : [
|
|
475
|
-
...te,
|
|
476
|
-
/* @__PURE__ */ E("li", { className: h.item, "data-open": W ? "" : void 0, style: { "--_calculation-depth": v.depth }, children: [
|
|
477
|
-
ve,
|
|
478
|
-
j && /* @__PURE__ */ E("ul", { id: F, className: h.derivation, hidden: !W, children: [
|
|
479
|
-
qe,
|
|
480
|
-
me,
|
|
481
|
-
/* @__PURE__ */ $("li", { className: h.item, "aria-hidden": "true", children: /* @__PURE__ */ E(
|
|
482
|
-
"div",
|
|
483
|
-
{
|
|
484
|
-
className: h.line,
|
|
485
|
-
style: { "--_calculation-depth": z.depth },
|
|
486
|
-
"data-inner": "",
|
|
487
|
-
"data-closing": "",
|
|
488
|
-
"data-mark": a === o ? "use" : void 0,
|
|
489
|
-
children: [
|
|
490
|
-
/* @__PURE__ */ E("span", { className: h.labelCell, children: [
|
|
491
|
-
/* @__PURE__ */ $("span", { className: h.disclosure }),
|
|
492
|
-
/* @__PURE__ */ E("span", { className: h.label, children: [
|
|
493
|
-
"= ",
|
|
494
|
-
p.label
|
|
495
|
-
] })
|
|
496
|
-
] }),
|
|
497
|
-
/* @__PURE__ */ $("span", { className: h.names }),
|
|
498
|
-
/* @__PURE__ */ $("span", { className: h.operator }),
|
|
499
|
-
g(D, !0)
|
|
500
|
-
]
|
|
501
|
-
}
|
|
502
|
-
) })
|
|
503
|
-
] })
|
|
504
|
-
] }, q)
|
|
505
|
-
];
|
|
506
|
-
}, O = _(T.result, !1, { depth: 0, flat: !0, parent: null }, "r");
|
|
507
|
-
return (
|
|
508
|
-
/* The frame is the surface and the container the layout measures itself
|
|
509
|
-
against; the list inside it is the statement. */
|
|
510
|
-
/* @__PURE__ */ $(
|
|
511
|
-
"div",
|
|
512
|
-
{
|
|
513
|
-
ref: m,
|
|
514
|
-
className: Lt(h.frame, e),
|
|
515
|
-
style: s ? {
|
|
516
|
-
"--_calculation-figure-tracks": Array(y * 2).fill("auto").join(" "),
|
|
517
|
-
"--_calculation-figures-end": X(y),
|
|
518
|
-
"--_calculation-assessment-column": X(y),
|
|
519
|
-
...f
|
|
520
|
-
} : f,
|
|
521
|
-
"data-still": R ? void 0 : "",
|
|
522
|
-
"data-metrics": s ? y : void 0,
|
|
523
|
-
"data-two-lines": i ? "" : void 0,
|
|
524
|
-
"data-compact": c ? "" : void 0,
|
|
525
|
-
children: /* @__PURE__ */ E("ul", { className: h.calculation, ...n, children: [
|
|
526
|
-
s && /* The head names each metric and its unit above its column. Every
|
|
527
|
-
row's sentence names them too, so the head is for the eye. */
|
|
528
|
-
/* @__PURE__ */ $("li", { className: h.item, "aria-hidden": "true", children: /* @__PURE__ */ $("div", { className: h.head, children: s.map((o, d) => /* @__PURE__ */ E(
|
|
529
|
-
"span",
|
|
530
|
-
{
|
|
531
|
-
className: h.headCell,
|
|
532
|
-
"data-unit": o.unit === void 0 ? void 0 : "",
|
|
533
|
-
style: { "--_calculation-column": X(d) },
|
|
534
|
-
children: [
|
|
535
|
-
/* @__PURE__ */ $("span", { className: h.headLabel, children: o.label }),
|
|
536
|
-
o.unit !== void 0 && /* @__PURE__ */ $("span", { className: h.headUnit, children: o.unit })
|
|
537
|
-
]
|
|
538
|
-
},
|
|
539
|
-
o.id
|
|
540
|
-
)) }) }),
|
|
541
|
-
O
|
|
542
|
-
] })
|
|
543
|
-
}
|
|
544
|
-
)
|
|
545
|
-
);
|
|
1
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import { r } from "./calculation.model-DU6T1D09.js";
|
|
3
|
+
import { C as c, D as d, a as p, G as C, I as x, M as D, P, b as v, Q as G, R as I, S as M, T as Q } from "./calculation.model-DU6T1D09.js";
|
|
4
|
+
import { CalculationView as e } from "./calculation.client.js";
|
|
5
|
+
function u({ children: a, metrics: i, ...s }) {
|
|
6
|
+
return /* @__PURE__ */ o(e, { model: r(a, i), ...s });
|
|
546
7
|
}
|
|
547
8
|
export {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
9
|
+
u as Calculation,
|
|
10
|
+
c as Chain,
|
|
11
|
+
d as Difference,
|
|
12
|
+
p as DividedBy,
|
|
13
|
+
C as Given,
|
|
14
|
+
x as Interim,
|
|
15
|
+
D as Minus,
|
|
16
|
+
P as Plus,
|
|
17
|
+
v as Product,
|
|
18
|
+
G as Quotient,
|
|
19
|
+
I as Ref,
|
|
20
|
+
M as Sum,
|
|
21
|
+
Q as Times
|
|
561
22
|
};
|