@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.
- package/CHANGELOG.md +17 -0
- package/README.md +2 -0
- package/dist/calculation.client.js +296 -276
- package/dist/calculation.css +1 -1
- package/dist/calculation.js +2 -2
- package/dist/calculation.model-CZuohgrp.js +176 -0
- package/dist/index.d.ts +7 -4
- package/docs/llms-full.md +28 -27
- package/package.json +3 -3
- package/dist/calculation.model-DU6T1D09.js +0 -168
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { Children as ie, isValidElement as b, Fragment as oe } from "react";
|
|
2
|
-
const d = (o) => Object.defineProperty(() => {
|
|
3
|
-
throw new Error(
|
|
4
|
-
`@umriss-ui/calculation: <${o}> stands only directly inside a <Calculation>. A tree written in a Server Component must be written inside the <Calculation> there, in one file, not passed through a client component.`
|
|
5
|
-
);
|
|
6
|
-
}, "name", { value: o }), ae = d("Given"), se = d("Sum"), re = d("Difference"), ce = d("Product"), ue = d("Quotient"), J = d("Ref"), le = d("Chain"), fe = d("Plus"), de = d("Minus"), pe = d("Times"), me = d("DividedBy"), x = d("Interim"), he = /* @__PURE__ */ new Map([
|
|
7
|
-
[se, "sum"],
|
|
8
|
-
[re, "difference"],
|
|
9
|
-
[ce, "product"],
|
|
10
|
-
[ue, "quotient"]
|
|
11
|
-
]), U = {
|
|
12
|
-
sum: "Sum",
|
|
13
|
-
difference: "Difference",
|
|
14
|
-
product: "Product",
|
|
15
|
-
quotient: "Quotient"
|
|
16
|
-
}, Q = /* @__PURE__ */ new Map([
|
|
17
|
-
[fe, { name: "Plus", operator: "sum" }],
|
|
18
|
-
[de, { name: "Minus", operator: "sum", negated: !0 }],
|
|
19
|
-
[pe, { name: "Times", operator: "product" }],
|
|
20
|
-
[me, { name: "DividedBy", operator: "quotient" }]
|
|
21
|
-
]), B = "<Given>, <Sum>, <Difference>, <Product>, <Quotient> or <Chain>", Y = "a calculation with metrics only adds and subtracts - <Sum>, <Difference>, <Plus>, <Minus>.", $e = ["unit", "format", "decimals"];
|
|
22
|
-
function a(o) {
|
|
23
|
-
throw new Error(`@umriss-ui/calculation: ${o}`);
|
|
24
|
-
}
|
|
25
|
-
function S(o) {
|
|
26
|
-
return ie.toArray(o).flatMap(
|
|
27
|
-
(n) => b(n) && n.type === oe ? S(n.props.children) : [n]
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
function E(o) {
|
|
31
|
-
if (!b(o)) return JSON.stringify(o);
|
|
32
|
-
const n = o.type;
|
|
33
|
-
return typeof n == "string" ? `<${n}>` : `<${n.displayName ?? n.name ?? "anonymous"}>`;
|
|
34
|
-
}
|
|
35
|
-
const G = (o, n, f) => `${o}/${b(n) && n.key || f}`;
|
|
36
|
-
function ge(o, n) {
|
|
37
|
-
const f = S(o);
|
|
38
|
-
if (f.length !== 1 && a(`<Calculation> takes exactly one child, the result; it was given ${f.length}.`), n !== void 0) {
|
|
39
|
-
n.length === 0 && a("<Calculation>: metrics is empty; leave it out for a calculation with one number per quantity.");
|
|
40
|
-
const t = /* @__PURE__ */ new Set();
|
|
41
|
-
for (const { id: i } of n)
|
|
42
|
-
t.has(i) && a(`<Calculation>: the metric id "${i}" is used twice.`), t.add(i);
|
|
43
|
-
}
|
|
44
|
-
const y = n?.map((t) => `"${t.id}"`).join(", "), r = (t, i) => {
|
|
45
|
-
const s = typeof t == "object" && t !== null;
|
|
46
|
-
if (n === void 0) {
|
|
47
|
-
s && a(`${i}: value is an object by metric, but the calculation has no metrics.`);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
s || a(`${i}: with metrics, value is an object with a number for each metric - ${y}.`);
|
|
51
|
-
for (const { id: e } of n)
|
|
52
|
-
e in t || a(`${i}: value has no number for the metric "${e}"; write null where it is absent. The metrics: ${y}.`);
|
|
53
|
-
for (const e of Object.keys(t))
|
|
54
|
-
n.some((c) => c.id === e) || a(`${i}: value has a number for "${e}", which is no metric. The metrics: ${y}.`);
|
|
55
|
-
}, m = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), P = [], R = (t, i, s) => {
|
|
56
|
-
const { id: e, ...c } = i;
|
|
57
|
-
if (n !== void 0) {
|
|
58
|
-
for (const w of $e)
|
|
59
|
-
i[w] !== void 0 && a(`${s}: ${w} belongs to the metric once the calculation has metrics, not to a quantity.`);
|
|
60
|
-
(i.target !== void 0 || i.limits !== void 0) && a(`${s}: target and limits are not assessed in a calculation with metrics.`);
|
|
61
|
-
}
|
|
62
|
-
e !== void 0 && (v.has(e) && a(`${s}: the id "${e}" is used twice.`), v.set(e, t));
|
|
63
|
-
const h = { ...c, key: t, id: e, operands: [] };
|
|
64
|
-
return m.set(t, h), h;
|
|
65
|
-
}, N = (t, i, s) => {
|
|
66
|
-
if (b(t) && t.type === J) {
|
|
67
|
-
const e = { key: "", reference: !0 };
|
|
68
|
-
return P.push({ operand: e, to: t.props.to, where: s }), e;
|
|
69
|
-
}
|
|
70
|
-
return { key: L(t, i, s), reference: !1 };
|
|
71
|
-
}, L = (t, i, s) => {
|
|
72
|
-
if ((!b(t) || t.type === J || Q.has(t.type) || t.type === x) && a(`${s}: ${E(t)} cannot stand here; a quantity must be ${B}.`), t.type === le) return z(t.props.children, i, s);
|
|
73
|
-
const e = he.get(t.type);
|
|
74
|
-
t.type !== ae && e === void 0 && a(
|
|
75
|
-
`${s}: ${E(t)} is not an element of the calculation. A calculation reads its children's props and cannot look inside a component of your own; write ${B} or <Ref> directly, or return them from .map.`
|
|
76
|
-
);
|
|
77
|
-
const { children: c, value: h, source: w, asOf: I, ages: p, ...q } = t.props, u = `${s} › ${q.label}`;
|
|
78
|
-
n !== void 0 && (e === "product" || e === "quotient") && a(`${u}: <${U[e]}> - ${Y}`);
|
|
79
|
-
const C = R(i, q, u);
|
|
80
|
-
if (e === void 0)
|
|
81
|
-
return r(h, u), C.given = { value: h, source: w, asOf: I, ages: p }, i;
|
|
82
|
-
C.operator = e;
|
|
83
|
-
const $ = S(c), l = $.length;
|
|
84
|
-
return (e === "quotient" ? l !== 2 : e !== "sum" && l < 2) && a(
|
|
85
|
-
`${u}: <${U[e]}> takes ${e === "quotient" ? "exactly two operands" : "two or more operands"}; it was given ${l}.`
|
|
86
|
-
), C.operands = $.map((O, T) => N(O, G(i, O, T), u)), i;
|
|
87
|
-
}, z = (t, i, s) => {
|
|
88
|
-
const e = `${s} › <Chain>`, [c, ...h] = S(t);
|
|
89
|
-
(c === void 0 || b(c) && (Q.has(c.type) || c.type === x)) && a(`${e}: a chain starts with a quantity that has no operator - ${B} or <Ref>.`);
|
|
90
|
-
let w = N(c, G(i, c, 0), e), I = E(c), p = [], q;
|
|
91
|
-
return h.forEach((u, C) => {
|
|
92
|
-
const $ = G(i, u, C + 1);
|
|
93
|
-
if (b(u) && u.type === x) {
|
|
94
|
-
const g = u.props, D = `${e} › ${g.label}`;
|
|
95
|
-
p.length === 0 && a(`${D}: an <Interim> needs an operand since the named value before it, ${I}.`);
|
|
96
|
-
const A = R($, g, D);
|
|
97
|
-
A.interim = !0, A.operator = p[0].line.operator, A.operands = [w, ...p.map((ne) => ne.operand)], w = { key: $, reference: !1, previous: !0 }, I = `<Interim label="${g.label}">`, p = [], q = $;
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const l = b(u) ? Q.get(u.type) : void 0;
|
|
101
|
-
l === void 0 && a(`${e}: ${E(u)} needs an operator in a chain - <Plus>, <Minus>, <Times> or <DividedBy> - or is an <Interim>.`), n !== void 0 && l.operator !== "sum" && a(`${e}: <${l.name}> - ${Y}`);
|
|
102
|
-
const O = l.operator !== "sum", T = p.find((g) => g.line.operator !== "sum");
|
|
103
|
-
(O && p.length > 0 || T) && a(
|
|
104
|
-
`${e}: <${(T ?? { line: l }).line.name}> stands alone between two named values - directly after the first quantity or an <Interim>, and directly before an <Interim>.`
|
|
105
|
-
);
|
|
106
|
-
const { children: H, ...M } = u.props, k = S(H), K = () => a(`${e}: <${l.name}> takes either a label and a value, or exactly one quantity as its child.`);
|
|
107
|
-
if (k.length > 0) {
|
|
108
|
-
(k.length > 1 || Object.values(M).some((D) => D !== void 0)) && K();
|
|
109
|
-
const g = N(k[0], $, e);
|
|
110
|
-
g.negated = l.negated, p.push({ operand: g, line: l });
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
M.label === void 0 && K();
|
|
114
|
-
const { value: V, source: W, asOf: X, ages: Z, ...ee } = M, F = `${e} › ${M.label}`, te = R($, { ...ee, label: M.label }, F);
|
|
115
|
-
r(V, F), te.given = { value: V, source: W, asOf: X, ages: Z }, p.push({ operand: { key: $, reference: !1, negated: l.negated }, line: l });
|
|
116
|
-
}), (p.length > 0 || q === void 0) && a(`${e}: a chain ends with an <Interim>, which names its value.`), q;
|
|
117
|
-
}, _ = L(f[0], "0", "<Calculation>"), j = m.get(_);
|
|
118
|
-
(j.emphasis !== void 0 || j.rule !== void 0) && a(`<Calculation> › ${j.label}: emphasis and rule do not stand on the Result, which is already the heaviest line.`);
|
|
119
|
-
for (const { operand: t, to: i, where: s } of P) {
|
|
120
|
-
const e = v.get(i);
|
|
121
|
-
if (e === void 0) {
|
|
122
|
-
const c = [...v.keys()].map((h) => `"${h}"`).join(", ");
|
|
123
|
-
a(`${s}: <Ref to="${i}"> names no quantity. ${c ? `The ids that exist: ${c}.` : "No quantity has an id."}`);
|
|
124
|
-
}
|
|
125
|
-
t.key = e;
|
|
126
|
-
}
|
|
127
|
-
return ye(m), { result: _, quantities: m, metrics: n };
|
|
128
|
-
}
|
|
129
|
-
function be(o) {
|
|
130
|
-
return o.metrics ? o.metrics.map((n) => {
|
|
131
|
-
const f = /* @__PURE__ */ new Map();
|
|
132
|
-
for (const [y, r] of o.quantities) {
|
|
133
|
-
const m = r.given && { ...r.given, value: r.given.value[n.id] };
|
|
134
|
-
f.set(y, { ...r, unit: n.unit, decimals: n.decimals, given: m });
|
|
135
|
-
}
|
|
136
|
-
return { result: o.result, quantities: f };
|
|
137
|
-
}) : [o];
|
|
138
|
-
}
|
|
139
|
-
function ye(o) {
|
|
140
|
-
const n = /* @__PURE__ */ new Set(), f = [], y = (r) => {
|
|
141
|
-
if (n.has(r)) return;
|
|
142
|
-
const m = f.indexOf(r);
|
|
143
|
-
if (m !== -1) {
|
|
144
|
-
const v = [...f.slice(m), r].map((P) => o.get(P).label);
|
|
145
|
-
a(`the calculation goes round in a circle through references: ${v.join(" → ")}.`);
|
|
146
|
-
}
|
|
147
|
-
f.push(r);
|
|
148
|
-
for (const v of o.get(r).operands) y(v.key);
|
|
149
|
-
f.pop(), n.add(r);
|
|
150
|
-
};
|
|
151
|
-
for (const r of o.keys()) y(r);
|
|
152
|
-
}
|
|
153
|
-
export {
|
|
154
|
-
le as C,
|
|
155
|
-
re as D,
|
|
156
|
-
ae as G,
|
|
157
|
-
x as I,
|
|
158
|
-
de as M,
|
|
159
|
-
fe as P,
|
|
160
|
-
ue as Q,
|
|
161
|
-
J as R,
|
|
162
|
-
se as S,
|
|
163
|
-
pe as T,
|
|
164
|
-
me as a,
|
|
165
|
-
ce as b,
|
|
166
|
-
be as p,
|
|
167
|
-
ge as r
|
|
168
|
-
};
|