formlab-mcp 0.7.4 → 0.7.6
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/index.js +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/theoretical.js +2 -2
- package/tools/ingredients.js +1 -1
- package/tools/lab.js +2 -0
- package/vendor/reactive.js +120 -29
- package/vendor/theoretical-params.js +3 -3
package/index.js
CHANGED
|
@@ -153,7 +153,7 @@ FormLab's QC definitions (answer by these; never infer them):
|
|
|
153
153
|
- Retest: repeats only a report's out-of-spec and in-doubt readings, linked (retestOf); it replaces them in rollups and on the CoA.
|
|
154
154
|
- Same-day readings: one point per test date; a day's readings average only under one spec; when two panels judged the same parameter that day, the later report stands.
|
|
155
155
|
- Holds: a held batch cannot ship until released (the Dashboard counts held batches with stock left); a lot on hold has status "hold" (incoming QC puts a received lot on hold until its QC releases it; FormLab does not set "quarantine" or "rejected" today, so a lot awaiting QC is on hold, not quarantined).
|
|
156
|
-
- Certificate of Analysis: latest result per parameter against its spec; required results come from the formula's releasePanel when set, else every panel used. Hard blocks: on hold, not made, no results. Out of spec ("Does not conform") and missing required results ("Not tested") can be issued with an override and a reason; a reading in doubt is only a warning. A shipment recorded with QC open keeps the open items and the reason given (get_batch stockLedger: shippedWithQcOpen, qcReason).`;
|
|
156
|
+
- Certificate of Analysis: latest result per parameter against its spec; required results come from the formula's releasePanel when set, else every panel used. Hard blocks: on hold, not made, no results. Out of spec ("Does not conform") and missing required results ("Not tested") can be issued with an override and a reason; a reading in doubt is only a warning. A shipment recorded with QC open keeps the open items and the reason given (get_batch stockLedger: shippedWithQcOpen, qcReason). A shipment recorded from 2 Dec 2026 also says which CoA it went with (coaIssuedAt, coaCustomer, coaPo; coaIssuedAt null = no CoA issued) and noLotsRecorded (true = no ingredient lots recorded for the batch or its parents, so a recall trace stops at the batch).`;
|
|
157
157
|
const server = new Server(
|
|
158
158
|
{ name: 'formlab-mcp', version: PKG_VERSION },
|
|
159
159
|
{ capabilities: { tools: {} }, instructions: INSTRUCTIONS }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formlab-mcp",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"mcpName": "io.github.juliu1980/formlab-mcp",
|
|
5
5
|
"description": "Read-only Model Context Protocol server for FormLab. Lets Claude and other MCP clients read and analyze your FormLab data, from a local export file or your live cloud workspace.",
|
|
6
6
|
"homepage": "https://formvix.com/mcp",
|
package/server.json
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "io.github.juliu1980/formlab-mcp",
|
|
4
4
|
"description": "Read-only MCP server for FormLab formulation data: a local export file or your live cloud workspace.",
|
|
5
|
-
"version": "0.7.
|
|
5
|
+
"version": "0.7.6",
|
|
6
6
|
"websiteUrl": "https://formvix.com/mcp",
|
|
7
7
|
"packages": [
|
|
8
8
|
{
|
|
9
9
|
"registryType": "npm",
|
|
10
10
|
"identifier": "formlab-mcp",
|
|
11
|
-
"version": "0.7.
|
|
11
|
+
"version": "0.7.6",
|
|
12
12
|
"runtimeHint": "npx",
|
|
13
13
|
"transport": {
|
|
14
14
|
"type": "stdio"
|
package/theoretical.js
CHANGED
|
@@ -107,7 +107,7 @@ function __nl(id) {
|
|
|
107
107
|
})(),
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
|
-
// The Composition tab's balance strip (js/reactive.js flRxBalance, 0.7.4): each reacting pair's index, and for soap the
|
|
110
|
+
// The Composition tab's balance strip (js/reactive.js flRxBalance, 0.7.4; flakes as weighed via flRxAsActive, 0.7.5): each reacting pair's index, and for soap the
|
|
111
111
|
// superfat, lye concentration and lye excess; a batch reads what was weighed, else the formula's recipe.
|
|
112
112
|
function __rb(kind, id) {
|
|
113
113
|
var coll = kind === 'batch' ? db.batches : db.formulations;
|
|
@@ -115,7 +115,7 @@ function __rb(kind, id) {
|
|
|
115
115
|
if (!e) return 'null';
|
|
116
116
|
var f = kind === 'batch' ? (db.formulations || []).find(function (x) { return x && x.id === e.formulationId; }) : e;
|
|
117
117
|
var weighed = kind === 'batch' && Array.isArray(e.actualComposition) && e.actualComposition.length;
|
|
118
|
-
var comp = weighed ? e.actualComposition : ((f && f.composition) || []);
|
|
118
|
+
var comp = weighed ? flRxAsActive(e.actualComposition) : ((f && f.composition) || []); // flakes at 90 % → pure KOH
|
|
119
119
|
var b = flRxBalance(comp);
|
|
120
120
|
if (!Array.isArray(b)) return JSON.stringify(b);
|
|
121
121
|
if (!b.length) return 'null';
|
package/tools/ingredients.js
CHANGED
|
@@ -181,7 +181,7 @@ const list_ingredients = {
|
|
|
181
181
|
const get_ingredient = {
|
|
182
182
|
definition: {
|
|
183
183
|
name: 'get_ingredient',
|
|
184
|
-
description: 'Get full details for a single ingredient: cost ($/kg), GHS safety (pictograms / H- / P-codes / signal word), per-jurisdiction regulatory status, approved sources (the suppliers/manufacturers qualified to supply this material — ASL/AML), inventory lots (balances + expiry + the source each was received from), recent stock movements, and the formulations using it, plus its `customFields` (name, value, unit — e.g. protein / carb / fat in g/100g, solids %; what theoretical parameters read) and `reactiveGroups` (EEW, AHEW, OH number, NCO %, acid / amine value, Si-H, vinyl, water, an oil\'s SAP value, lye; NaOH and KOH count as lye by CAS at their purity: the datasheet value as entered, the same in the datasheet\'s own terms, and meq/g; rows the app ignores are listed with why). Accepts internal id or UID (e.g. ING-001).',
|
|
184
|
+
description: 'Get full details for a single ingredient: cost ($/kg), GHS safety (pictograms / H- / P-codes / signal word), per-jurisdiction regulatory status, approved sources (the suppliers/manufacturers qualified to supply this material — ASL/AML), inventory lots (balances + expiry + the source each was received from), recent stock movements, and the formulations using it, plus its `customFields` (name, value, unit — e.g. protein / carb / fat in g/100g, solids %; what theoretical parameters read) and `reactiveGroups` (EEW, AHEW, OH number, NCO %, acid / amine value, Si-H, vinyl, water, an oil\'s SAP value, lye; NaOH and KOH count as lye by CAS (a recipe amount is pure lye; a batch\'s weighed flakes count at their purity): the datasheet value as entered, the same in the datasheet\'s own terms, and meq/g; rows the app ignores are listed with why). Accepts internal id or UID (e.g. ING-001).',
|
|
185
185
|
inputSchema: {
|
|
186
186
|
type: 'object',
|
|
187
187
|
properties: {
|
package/tools/lab.js
CHANGED
|
@@ -442,6 +442,8 @@ const get_batch = {
|
|
|
442
442
|
date: e.ts || null, delta: e.delta ?? null, unit: e.unit || b.unit || '', kind: e.kind || '', note: e.note || '',
|
|
443
443
|
...(e.customer ? { customer: e.customer } : {}),
|
|
444
444
|
...(Array.isArray(e.qcOpen) && e.qcOpen.length ? { shippedWithQcOpen: e.qcOpen, qcReason: e.qcReason || null } : {}),
|
|
445
|
+
// 2 Dec: the CoA it went with (null = none issued), and no ingredient lots recorded. Older shipments carry neither.
|
|
446
|
+
...(e.kind === 'shipment' && 'coaAt' in e ? { coaIssuedAt: e.coaAt || null, ...(e.coaCustomer ? { coaCustomer: e.coaCustomer } : {}), ...(e.coaPo ? { coaPo: e.coaPo } : {}), noLotsRecorded: !!e.noLots } : {}),
|
|
445
447
|
})),
|
|
446
448
|
shippedQty: (Array.isArray(b.stockLedger) ? b.stockLedger : []).reduce((s, e) => e.kind === 'shipment' ? s + Math.abs(parseFloat(e.delta) || 0) : s, 0),
|
|
447
449
|
// Finished-batch hold: while set, the app records no shipment of this batch (QA / complaint / recall).
|
package/vendor/reactive.js
CHANGED
|
@@ -51,9 +51,9 @@ const FL_RX_GROUPS = {
|
|
|
51
51
|
vinyl: { label: 'Vinyl', bases: ['mmol', 'eqw', 'f'], term: 'mmol' },
|
|
52
52
|
// Water reacts with NCO (foams, moisture cure; Jun 27 Oct: "later preset", built 28 Oct). `h2o`, not `water`: food
|
|
53
53
|
// workspaces keep a custom field called water.
|
|
54
|
-
h2o: { label: 'Water
|
|
55
|
-
// Soap (1 Dec): oils, butters and waxes carry a SAP value; NaOH and KOH are known by CAS (
|
|
56
|
-
ester: { label: '
|
|
54
|
+
h2o: { label: 'Water', bases: ['wpct', 'mmol'], term: 'wpct' },
|
|
55
|
+
// Soap (1 Dec): oils, butters and waxes carry a SAP value; NaOH and KOH are known by CAS (recipe amounts are pure lye).
|
|
56
|
+
ester: { label: 'Oil / fat (SAP)', bases: ['sapnaoh', 'sap', 'sapkoh', 'mmol'], term: 'sap' },
|
|
57
57
|
base: { label: 'Lye (NaOH / KOH)', bases: ['naohpct', 'kohpct', 'mmol'], term: 'mmol' },
|
|
58
58
|
};
|
|
59
59
|
const FL_RX_GROUP_KEYS = Object.keys(FL_RX_GROUPS);
|
|
@@ -92,7 +92,9 @@ function flRxMeq(entry, mw) {
|
|
|
92
92
|
}
|
|
93
93
|
// Every group of an ingredient in meq/g (absent groups left out). One row per group; a second is ignored.
|
|
94
94
|
const FL_RX_WATER_CAS = '7732-18-5';
|
|
95
|
-
// NaOH and KOH count as lye by CAS
|
|
95
|
+
// NaOH and KOH count as lye by CAS. A recipe amount is the active amount (the app's purity rule: the weigh-out grosses
|
|
96
|
+
// up for purity), so a recipe row counts at 100 %; a batch's weighed row is flakes, so flRxAsActive takes its purity
|
|
97
|
+
// off first. A stored Lye row (a 50 % solution) describes the material as weighed and still wins.
|
|
96
98
|
const FL_RX_LYE_CAS = { '1310-73-2': 40.0, '1310-58-3': 56.1 };
|
|
97
99
|
function flRxLyeKind(ing) {
|
|
98
100
|
const mw = ing && FL_RX_LYE_CAS[String(ing.cas || '').trim()];
|
|
@@ -102,8 +104,7 @@ function flRxIngMeq(ing) {
|
|
|
102
104
|
const out = {};
|
|
103
105
|
const lyeMw = ing && FL_RX_LYE_CAS[String(ing.cas || '').trim()];
|
|
104
106
|
if (lyeMw && !((ing.reactiveGroups || []).some(g => g && g.group === 'base'))) {
|
|
105
|
-
|
|
106
|
-
out.base = (1000 / lyeMw) * ((pur != null && pur > 0 && pur <= 100) ? pur / 100 : 1);
|
|
107
|
+
out.base = 1000 / lyeMw;
|
|
107
108
|
}
|
|
108
109
|
// Water itself counts without being told (a foam's blowing water); a stored h2o row still wins.
|
|
109
110
|
if (ing && String(ing.cas || '').trim() === FL_RX_WATER_CAS && !((ing.reactiveGroups || []).some(g => g && g.group === 'h2o'))) out.h2o = FL_RX_BASES.wpct.toMeq(100);
|
|
@@ -126,9 +127,17 @@ function flRxTermText(group, meq, basis) {
|
|
|
126
127
|
return `${b.short} ${v}${b.unit ? ' ' + b.unit : ''}`;
|
|
127
128
|
}
|
|
128
129
|
// For the ingredient view: the meq/g fields (0 when absent) and the datasheet terms (null when absent).
|
|
129
|
-
function flRxViewFields(ing) { return _flRxFieldsFromMeq(flRxIngMeq(ing)); }
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
function flRxViewFields(ing) { return _flRxFieldsFromMeq(flRxIngMeq(ing), flRxLyeFrac(ing)); }
|
|
131
|
+
// Grams of pure lye per gram (soap's lye concentration counts pure NaOH / KOH, so a premixed 50 % lye solution reads
|
|
132
|
+
// right): a Lye row's NaOH % / KOH %, mmol/g as NaOH, else 1 for NaOH / KOH by CAS (active, see above). 0 for the rest.
|
|
133
|
+
function flRxLyeFrac(ing) {
|
|
134
|
+
if (!ing) return 0;
|
|
135
|
+
const e = (ing.reactiveGroups || []).find(g => g && g.group === 'base' && flRxMeq(g, ing.mw) != null);
|
|
136
|
+
if (e) return e.basis === 'naohpct' || e.basis === 'kohpct' ? Math.min(_flRxNum(e.value), 100) / 100 : flRxMeq(e, ing.mw) * 0.040;
|
|
137
|
+
return flRxLyeKind(ing) ? 1 : 0;
|
|
138
|
+
}
|
|
139
|
+
function _flRxFieldsFromMeq(meq, lyeFrac) {
|
|
140
|
+
const out = { lyeMass: lyeFrac > 0 ? lyeFrac : 0 };
|
|
132
141
|
FL_RX_GROUP_KEYS.forEach(k => { out[k] = meq[k] || 0; });
|
|
133
142
|
Object.entries(FL_RX_TERMS).forEach(([t, grp]) => {
|
|
134
143
|
const b = FL_RX_BASES[FL_RX_GROUPS[grp].term];
|
|
@@ -155,7 +164,9 @@ function flRxSubViewFields(sub) {
|
|
|
155
164
|
rows.forEach(r => { const m = r && r.ing ? _flRxNum(r.ing[g]) : null; if (m) t += r.amount * m; });
|
|
156
165
|
if (t > 0) meq[g] = t / total;
|
|
157
166
|
});
|
|
158
|
-
|
|
167
|
+
let lt = 0;
|
|
168
|
+
if (total > 0) rows.forEach(r => { const m = r && r.ing ? _flRxNum(r.ing.lyeMass) : null; if (m) lt += r.amount * m; });
|
|
169
|
+
const out = _flRxFieldsFromMeq(meq, total > 0 ? lt / total : 0);
|
|
159
170
|
_flRxSubCache.set(sub.id, out);
|
|
160
171
|
return { ...out };
|
|
161
172
|
} finally { _flRxSubStack.delete(sub.id); }
|
|
@@ -165,8 +176,10 @@ function flRxSubViewFields(sub) {
|
|
|
165
176
|
function flRxChipsHtml(ing) {
|
|
166
177
|
const meq = flRxIngMeq(ing);
|
|
167
178
|
const rows = ((ing && ing.reactiveGroups) || []).filter(g => g && meq[g.group] != null);
|
|
168
|
-
|
|
169
|
-
|
|
179
|
+
// NaOH / KOH count as lye by their CAS with nothing stored (soap, 1 Dec): say so on the page, or nothing would.
|
|
180
|
+
const lye = (meq.base != null && !rows.some(g => g.group === 'base')) ? _flRxLyeChip(ing, meq.base) : '';
|
|
181
|
+
if (!rows.length) return lye;
|
|
182
|
+
return lye + rows.map(g => {
|
|
170
183
|
const how = g.basis === 'f' ? `MW ${_flRxNum(ing.mw)} × ${_flRxNum(g.value)} per molecule · ` : ''; // the MW as recorded (170.3), not rounded
|
|
171
184
|
return `<span class="fl-rx-chip" title="${esc(FL_RX_GROUPS[g.group].label)}: ${esc(how)}${flRxFmt(meq[g.group])} meq/g">${esc(flRxTermText(g.group, meq[g.group], g.basis))}</span>`;
|
|
172
185
|
}).join('');
|
|
@@ -174,7 +187,26 @@ function flRxChipsHtml(ing) {
|
|
|
174
187
|
function flRxListText(ing) {
|
|
175
188
|
const meq = flRxIngMeq(ing);
|
|
176
189
|
const stored = (ing && ing.reactiveGroups) || [];
|
|
177
|
-
return Object.keys(meq).map(k => {
|
|
190
|
+
return Object.keys(meq).map(k => {
|
|
191
|
+
const e = stored.find(x => x && x.group === k);
|
|
192
|
+
if (k === 'base' && !e && flRxLyeKind(ing)) return `${flRxLyeKind(ing)} lye`;
|
|
193
|
+
return flRxTermText(k, meq[k], e && e.basis);
|
|
194
|
+
}).join(' · ');
|
|
195
|
+
}
|
|
196
|
+
function _flRxLyePurity(ing) { const p = _flRxNum(ing && ing.purity); return (p != null && p > 0 && p <= 100) ? p : 100; }
|
|
197
|
+
// A batch's weighed rows as active amounts: NaOH / KOH found by CAS (no stored Lye row) count at their purity, since
|
|
198
|
+
// 111 g of 90 % flakes is 100 g of KOH. Everything else passes through. A recipe is already active: never call it there.
|
|
199
|
+
function flRxAsActive(comp) {
|
|
200
|
+
return (comp || []).map(c => {
|
|
201
|
+
const ing = c && c.ingredientId && (db.ingredients || []).find(i => i.id === c.ingredientId);
|
|
202
|
+
if (!ing || !flRxLyeKind(ing) || (ing.reactiveGroups || []).some(g => g && g.group === 'base')) return c;
|
|
203
|
+
const p = _flRxLyePurity(ing), a = parseFloat(c.amount);
|
|
204
|
+
return p < 100 && Number.isFinite(a) ? { ...c, amount: a * p / 100 } : c;
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
function _flRxLyeChip(ing, meq) {
|
|
208
|
+
const kind = flRxLyeKind(ing), pur = _flRxLyePurity(ing);
|
|
209
|
+
return `<span class="fl-rx-chip" title="Counts as lye by its CAS number: ${flRxFmt(meq)} meq/g${pur < 100 ? `; recipe amounts are pure ${esc(kind)}, the weigh-out grosses up for ${pur} %` : ''}">${esc(kind)} lye</span>`;
|
|
178
210
|
}
|
|
179
211
|
|
|
180
212
|
// ---- A composition's pairs and index ----
|
|
@@ -200,12 +232,34 @@ function flRxLyeConc(rows) {
|
|
|
200
232
|
let lye = 0, water = 0;
|
|
201
233
|
(rows || []).forEach(r => {
|
|
202
234
|
if (!r || !r.ing || !(r.amount > 0)) return;
|
|
203
|
-
|
|
235
|
+
// Pure lye: the row's lyeMass (g per g); a row whose lye share is unknown counts whole.
|
|
236
|
+
if (_flRxNum(r.ing.base) > 0) lye += r.amount * (_flRxNum(r.ing.lyeMass) > 0 ? r.ing.lyeMass : 1);
|
|
204
237
|
const h = _flRxNum(r.ing.h2o);
|
|
205
238
|
if (h > 0) water += r.amount * h * 0.009008;
|
|
206
239
|
});
|
|
207
240
|
return lye > 0 && water > 0 ? 100 * lye / (lye + water) : null;
|
|
208
241
|
}
|
|
242
|
+
// Oils, butters and fats in a soap with no SAP value: left out of the lye, so the superfat reads wrong. Fragrance,
|
|
243
|
+
// essential, mineral and silicone oils don't saponify (or barely) and are not named.
|
|
244
|
+
function flRxMissingSap(comp, depth) {
|
|
245
|
+
const out = [], d = depth || 0;
|
|
246
|
+
if (d > 6) return out;
|
|
247
|
+
(comp || []).forEach(c => {
|
|
248
|
+
if (!c || !(parseFloat(c.amount) > 0)) return;
|
|
249
|
+
if (c.formulationId) { // an oil premix: its oils count too
|
|
250
|
+
const sub = (db.formulations || []).find(x => x.id === c.formulationId);
|
|
251
|
+
if (sub) flRxMissingSap(sub.composition, d + 1).forEach(n => { if (!out.includes(n)) out.push(n); });
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const ing = c.ingredientId && (db.ingredients || []).find(i => i.id === c.ingredientId);
|
|
255
|
+
const m = ing ? flRxIngMeq(ing) : null;
|
|
256
|
+
if (!ing || (m.ester || 0) > 0 || (m.base || 0) > 0) return; // has a SAP value, or is the lye itself
|
|
257
|
+
const name = String(ing.name || ''), cls = String(ing.ingredientClass || '').toLowerCase(), fn = String(ing.function || '');
|
|
258
|
+
if (/essential|fragrance|mineral|silicone|paraffin|petrolat|perfume/i.test(name + ' ' + fn) || cls === 'fragrance') return;
|
|
259
|
+
if ((cls === 'oil' || /\b(oil|butter|tallow|lard|fat)\b/i.test(name) || /saponif/i.test(fn)) && !out.includes(name || 'an oil')) out.push(name || 'an oil');
|
|
260
|
+
});
|
|
261
|
+
return out;
|
|
262
|
+
}
|
|
209
263
|
function _flRxPct(v) { return (v == null || !Number.isFinite(v)) ? '—' : String(Math.round(v * 10) / 10); }
|
|
210
264
|
// Every reacting pair of a composition as plain numbers (the AI context and the MCP server read this, so app, AI and
|
|
211
265
|
// MCP say the same): [{ pair, label, index, superfat?, lyeExcess?, lyeConcentration? }], or { error } for mixed units.
|
|
@@ -221,6 +275,8 @@ function flRxBalance(comp) {
|
|
|
221
275
|
o.lyeExcess = flRxLyeExcess(pair, index);
|
|
222
276
|
const c = flRxLyeConc(rows);
|
|
223
277
|
o.lyeConcentration = c == null ? null : +c.toFixed(2);
|
|
278
|
+
const miss = flRxMissingSap(comp);
|
|
279
|
+
if (miss.length) o.oilsWithoutSap = miss;
|
|
224
280
|
}
|
|
225
281
|
return o;
|
|
226
282
|
});
|
|
@@ -257,6 +313,12 @@ function _flRxTargetText(t, pair) {
|
|
|
257
313
|
if (pair && pair.soap) return `target ${_flRxPct(100 - +t.index)}${_flRxNum(t.tol) ? ' ± ' + flRxFmtIndex(+t.tol) : ''} %`;
|
|
258
314
|
return `target ${flRxFmtIndex(+t.index)}${_flRxNum(t.tol) ? ' ± ' + flRxFmtIndex(+t.tol) : ''}`;
|
|
259
315
|
}
|
|
316
|
+
function _flRxMissHtml(comp) {
|
|
317
|
+
const m = flRxMissingSap(comp);
|
|
318
|
+
if (!m.length) return '';
|
|
319
|
+
const names = m.length > 2 ? `${m.slice(0, 2).join(', ')} +${m.length - 2}` : m.join(' and ');
|
|
320
|
+
return `<span class="fl-rx-warn" title="Give each oil a SAP value (Reactive groups › Oil / fat (SAP)); until then it isn't counted in the lye">No SAP value: ${esc(names)}</span>`;
|
|
321
|
+
}
|
|
260
322
|
// The soap chip's lye concentration, with its target when one is set (amber more than half a point off).
|
|
261
323
|
function _flRxConcHtml(rows, t) {
|
|
262
324
|
const c = flRxLyeConc(rows), want = t ? _flRxNum(t.conc) : null;
|
|
@@ -334,7 +396,8 @@ function flRxSubRowEq(sub, parentAmount, groups) {
|
|
|
334
396
|
}
|
|
335
397
|
const _FL_RX_SHORT = { epoxy: 'epoxy', amineH: 'amine H', oh: 'OH', nco: 'NCO', cooh: 'COOH', amine: 'amine', sih: 'Si-H', vinyl: 'vinyl', h2o: 'water', ester: 'oil', base: 'lye' };
|
|
336
398
|
function flRxEqCellHtml(list) {
|
|
337
|
-
|
|
399
|
+
// The dash sits in the numbers' column, not under the group names (25l).
|
|
400
|
+
if (!list || !list.length) return '<span class="fl-rx-eqs"><span class="fl-rx-eq fl-rx-dim">—</span><i></i></span>';
|
|
338
401
|
// The arithmetic on hover (Jun, 28 Oct): 14.6 g × 23.5 meq/g = 0.343 eq (AHEW 42.6 g/eq). The TOTAL cell has no amount.
|
|
339
402
|
const tip = x => (x.amount != null ? `${flRxFmt(x.amount)} g × ${flRxFmt(x.meq)} meq/g = ${x.eq.toFixed(3)} eq (${flRxTermText(x.group, x.meq)})` : `Σ ${_FL_RX_SHORT[x.group]} = ${x.eq.toFixed(3)} eq per 100 g`);
|
|
340
403
|
// Two columns (Jun, 28 Oct: "epoxy and amine H should align by the number"): the numbers right-aligned, the group
|
|
@@ -363,7 +426,7 @@ function flRxStripHtml(f) {
|
|
|
363
426
|
<span class="fl-rx-name">${esc(pair.label)}</span>
|
|
364
427
|
${value}
|
|
365
428
|
<span class="fl-rx-dim" title="Equivalents per 100 g of formula: ${esc(pair.numLabel)} / ${esc(pair.denLabel)}${pair.soap ? `; lye index ${flRxFmtIndex(index)}` : ''}">${num.toFixed(3)} / ${den.toFixed(3)} eq</span>
|
|
366
|
-
${pair.soap ? _flRxConcHtml(rows, t) : ''}
|
|
429
|
+
${pair.soap ? _flRxConcHtml(rows, t) + _flRxMissHtml(f.composition) : ''}
|
|
367
430
|
<button type="button" class="fl-rx-target${t ? ' is-set' : ''}" onclick="flRxOpenTarget('${escJsAttr(f.id)}','${escJsAttr(pair.key)}')" title="${t ? 'Change or clear the target' : pair.soap ? 'Set a target superfat; the strip turns green inside it, amber outside' : 'Set a target index; the strip turns green inside it, amber outside'}">${t ? esc(_flRxTargetText(t, pair)) : '+ target'}</button>
|
|
368
431
|
<button type="button" class="btn btn-secondary btn-sm fl-rx-solve-btn" onclick="${pro ? `flRxOpenSolve('${escJsAttr(f.id)}','${escJsAttr(pair.key)}')` : `proUpsell('reactive.solve')`}" title="${pair.soap ? 'Work out the lye for a target superfat, and the water for a lye concentration' : 'Work out the amount that hits a target index'}">Solve…${pro ? '' : ' <span class="fl-pro" aria-hidden="true"></span>'}</button>
|
|
369
432
|
</div>`;
|
|
@@ -372,6 +435,16 @@ function flRxStripHtml(f) {
|
|
|
372
435
|
const solve = open && found.some(x => x.pair.key === open.pair) ? _flRxSolveRowHtml(f, open) : '';
|
|
373
436
|
return `<div class="fl-rx-strip" id="fl-rx-strip-${esc(f.id)}"><span class="fl-rx-kicker">${kicker}</span>${chips}${kit}</div>${solve}`;
|
|
374
437
|
}
|
|
438
|
+
// Leaving the formula closes an open Solve row: it used to stay open in memory and come back with the page (Jun, 1 Dec:
|
|
439
|
+
// "the second time the composition table loads, the solver shows up"). A redraw of the same page keeps it (25l).
|
|
440
|
+
if (typeof window !== 'undefined') {
|
|
441
|
+
window._viewLeaveHooks = window._viewLeaveHooks || {};
|
|
442
|
+
const _prevLeave = window._viewLeaveHooks['formulation-detail'];
|
|
443
|
+
window._viewLeaveHooks['formulation-detail'] = (toView, toParams) => {
|
|
444
|
+
Object.keys(_flRxSolveOpen).forEach(k => { delete _flRxSolveOpen[k]; });
|
|
445
|
+
if (typeof _prevLeave === 'function') _prevLeave(toView, toParams);
|
|
446
|
+
};
|
|
447
|
+
}
|
|
375
448
|
// formulations.js holds the strip in #fl-rx-wrap-<id>; a target or the Solve row redraws only that.
|
|
376
449
|
function flRxStripWrapHtml(f) { return f ? `<div class="fl-rx-wrap" id="fl-rx-wrap-${esc(f.id)}">${flRxStripHtml(f)}</div>` : ''; }
|
|
377
450
|
function _flRxRefreshStrip(fId) {
|
|
@@ -440,6 +513,15 @@ function _flRxSolvableRows(f, pair) {
|
|
|
440
513
|
function _flRxQsIdx(comp) { const qs = typeof QS_ROLE !== 'undefined' ? QS_ROLE : 'Balance (q.s.)'; return (comp || []).findIndex(c => c && c.role === qs); }
|
|
441
514
|
// "Keep the total" moves the q.s. row by the same amount, so only when both rows are in one unit.
|
|
442
515
|
function _flRxQsFor(comp, row) { const qi = _flRxQsIdx(comp); return qi >= 0 && qi !== row && String((comp[qi] || {}).unit || '') === String((comp[row] || {}).unit || '') ? qi : -1; }
|
|
516
|
+
// The total a Solve leaves (Jun, 1 Dec): in a % formula off 100 it is a warning that says how to keep 100, else the
|
|
517
|
+
// plain readout (25m).
|
|
518
|
+
function _flRxTotalHtml(comp, total, qi, keepQs) {
|
|
519
|
+
const rows = (comp || []).filter(c => c && (c.ingredientId || c.formulationId));
|
|
520
|
+
const pct = rows.length && rows.every(c => /%/.test(String(c.unit || '')));
|
|
521
|
+
if (!pct || Math.abs(total - 100) < 0.05) return ` <span class="fl-rx-dim">· total ${+total.toFixed(2)}</span>`;
|
|
522
|
+
const how = qi >= 0 && !keepQs ? 'tick keep the total' : _flRxQsIdx(comp) < 0 ? 'set one row’s role to Balance (q.s.) to keep 100' : '';
|
|
523
|
+
return ` <span class="fl-rx-warn">· total ${+total.toFixed(2)} ${esc(rows[0].unit)}${how ? ': ' + how : ''}</span>`;
|
|
524
|
+
}
|
|
443
525
|
function _flRxIndexWith(comp, pair) { return flRxEval(pair, _flRxRows(comp)).index; }
|
|
444
526
|
// Pure: the amount of comp[rowIdx] (and the q.s. row's, when keepQs) at which the index is `target`.
|
|
445
527
|
// The index is a ratio, so it moves one way as one row's amount grows: a bisection finds it, through the same rows
|
|
@@ -554,7 +636,7 @@ function _flRxSolveRowHtml(f, st) {
|
|
|
554
636
|
// The amounts as typed (18.05 → 20.06), not rounded to three figures: both sides of the arrow read alike.
|
|
555
637
|
out = `${esc(_flRxRowName(c))} ${+r.from} → <b>${esc(r.amount)}</b> ${unit} <span class="fl-rx-dim">(${d >= 0 ? '+' : ''}${+d.toFixed(4)})</span>`
|
|
556
638
|
+ (r.qsIdx >= 0 ? ` <span class="fl-rx-dim">· ${esc(_flRxRowName(comp[r.qsIdx]))} ${+r.qsFrom} → ${r.qsAmount}</span>` : '')
|
|
557
|
-
+
|
|
639
|
+
+ _flRxTotalHtml(comp, total, _flRxQsFor(comp, st.row), st.keepQs)
|
|
558
640
|
+ (() => { const k = flRxKitRatio(comp.map((x, i) => (i === st.row ? { ...x, amount: r.amount } : i === r.qsIdx ? { ...x, amount: r.qsAmount } : x))); return k ? ` <span class="fl-rx-dim">· mix ${_flRxRatioText(k.weight)}</span>` : ''; })()
|
|
559
641
|
+ (outRange ? ` <span class="fl-rx-warn">outside its range (${lo ?? '…'}–${hi ?? '…'})</span>` : '');
|
|
560
642
|
ok = !outRange;
|
|
@@ -564,12 +646,12 @@ function _flRxSolveRowHtml(f, st) {
|
|
|
564
646
|
<b>Solve</b>
|
|
565
647
|
<label>index <input type="number" step="any" min="0" value="${esc(String(st.target))}" oninput="_flRxSolveSet('${escJsAttr(f.id)}','target',this.value)" onkeydown="if(event.key==='Enter'&&!event.isComposing)flRxApplySolve('${escJsAttr(f.id)}')"></label>
|
|
566
648
|
<label>by changing <select onchange="_flRxSolveSet('${escJsAttr(f.id)}','row',this.value)">${rows.map(opt).join('')}</select></label>
|
|
567
|
-
<span class="fl-rx-result" id="fl-rx-result-${esc(f.id)}">${out}</span>
|
|
568
649
|
${qi >= 0 ? `<label class="fl-rx-check"><input type="checkbox"${st.keepQs ? ' checked' : ''} onchange="_flRxSolveSet('${escJsAttr(f.id)}','keepQs',this.checked)"> keep the total (from the q.s. row)</label>` : ''}
|
|
569
650
|
<span class="fl-rx-solve-act">
|
|
570
651
|
<button type="button" class="btn btn-secondary btn-sm" onclick="flRxOpenSolve('${escJsAttr(f.id)}','${escJsAttr(st.pair)}')">Cancel</button>
|
|
571
652
|
<button type="button" class="btn btn-primary btn-sm" onclick="flRxApplySolve('${escJsAttr(f.id)}')"${ok ? '' : ' disabled'}>Apply</button>
|
|
572
653
|
</span>
|
|
654
|
+
<span class="fl-rx-result" id="fl-rx-result-${esc(f.id)}">${out}</span>
|
|
573
655
|
</div>`;
|
|
574
656
|
}
|
|
575
657
|
// The soap Solve row: superfat by changing the lye, then lye concentration by changing a water row.
|
|
@@ -591,7 +673,7 @@ function _flRxSoapSolveRowHtml(f, st) {
|
|
|
591
673
|
+ (r.qsIdx >= 0 ? ` <span class="fl-rx-dim">· ${esc(_flRxRowName(comp[r.qsIdx]))} ${+r.qsFrom} → ${r.qsAmount}</span>` : '')
|
|
592
674
|
+ (w && !w.error && wc ? ` · ${move(_flRxRowName(wc), _flRxNum(wc.amount) || 0, w.amount, wc.unit)}` : '')
|
|
593
675
|
+ (w && w.error ? ` <span class="fl-rx-warn">${w.error === 'bad' ? 'Enter a lye concentration between 0 and 100 %.' : `${esc(_flRxRowName(wc))} alone can’t reach ${_flRxPct(st.conc)} %.`}</span>` : '')
|
|
594
|
-
+ (res.comp ?
|
|
676
|
+
+ (res.comp ? _flRxTotalHtml(res.comp, res.comp.reduce((s, x) => s + (_flRxNum(x.amount) || 0), 0), qi, st.keepQs) : '')
|
|
595
677
|
+ (outRange ? ` <span class="fl-rx-warn">outside its range (${lo ?? '…'}–${hi ?? '…'})</span>` : '');
|
|
596
678
|
ok = !outRange && !(w && w.error);
|
|
597
679
|
}
|
|
@@ -599,16 +681,16 @@ function _flRxSoapSolveRowHtml(f, st) {
|
|
|
599
681
|
const fid = escJsAttr(f.id);
|
|
600
682
|
return `<div class="fl-rx-solve" id="fl-rx-solve-${esc(f.id)}">
|
|
601
683
|
<b>Solve</b>
|
|
602
|
-
<label>superfat <input type="number" step="any" value="${esc(String(+sf.toFixed(4)))}" oninput="_flRxSolveSet('${fid}','superfat',this.value)" onkeydown="if(event.key==='Enter'&&!event.isComposing)flRxApplySolve('${fid}')"> %</label>
|
|
603
|
-
<label>by changing <select onchange="_flRxSolveSet('${fid}','row',this.value)">${rows.map(i => opt(i, st.row)).join('')}</select></label>
|
|
604
|
-
${waters.length ? `<label>lye concentration <input type="number" step="any" min="0" max="100" placeholder="keep" value="${esc(st.conc == null ? '' : String(st.conc))}" oninput="_flRxSolveSet('${fid}','conc',this.value)" onkeydown="if(event.key==='Enter'&&!event.isComposing)flRxApplySolve('${fid}')"> %</label>
|
|
605
|
-
<label>by changing <select onchange="_flRxSolveSet('${fid}','wrow',this.value)">${waters.map(i => opt(i, st.wrow)).join('')}</select></label>` : ''}
|
|
606
|
-
<span class="fl-rx-result" id="fl-rx-result-${esc(f.id)}">${out}</span>
|
|
684
|
+
<span class="fl-rx-sgrp"><label>superfat <input type="number" step="any" value="${esc(String(+sf.toFixed(4)))}" oninput="_flRxSolveSet('${fid}','superfat',this.value)" onkeydown="if(event.key==='Enter'&&!event.isComposing)flRxApplySolve('${fid}')"> %</label>
|
|
685
|
+
<label>by changing <select onchange="_flRxSolveSet('${fid}','row',this.value)">${rows.map(i => opt(i, st.row)).join('')}</select></label></span>
|
|
686
|
+
${waters.length ? `<span class="fl-rx-sgrp"><label>lye concentration <input type="number" step="any" min="0" max="100" placeholder="keep" value="${esc(st.conc == null ? '' : String(st.conc))}" oninput="_flRxSolveSet('${fid}','conc',this.value)" onkeydown="if(event.key==='Enter'&&!event.isComposing)flRxApplySolve('${fid}')"> %</label>
|
|
687
|
+
<label>by changing <select onchange="_flRxSolveSet('${fid}','wrow',this.value)">${waters.map(i => opt(i, st.wrow)).join('')}</select></label></span>` : ''}
|
|
607
688
|
${qi >= 0 ? `<label class="fl-rx-check"><input type="checkbox"${st.keepQs ? ' checked' : ''} onchange="_flRxSolveSet('${fid}','keepQs',this.checked)"> keep the total (from the q.s. row)</label>` : ''}
|
|
608
689
|
<span class="fl-rx-solve-act">
|
|
609
690
|
<button type="button" class="btn btn-secondary btn-sm" onclick="flRxOpenSolve('${fid}','${escJsAttr(st.pair)}')">Cancel</button>
|
|
610
691
|
<button type="button" class="btn btn-primary btn-sm" onclick="flRxApplySolve('${fid}')"${ok ? '' : ' disabled'}>Apply</button>
|
|
611
692
|
</span>
|
|
693
|
+
<span class="fl-rx-result" id="fl-rx-result-${esc(f.id)}">${out}</span>
|
|
612
694
|
</div>`;
|
|
613
695
|
}
|
|
614
696
|
function _flRxSolveSet(fId, k, v) {
|
|
@@ -665,7 +747,7 @@ function flRxBatchStripHtml(b) {
|
|
|
665
747
|
if (!b) return '';
|
|
666
748
|
const f = (typeof flBatchFormula === 'function' ? flBatchFormula(b) : db.formulations.find(x => x.id === b.formulationId));
|
|
667
749
|
const hasActual = Array.isArray(b.actualComposition) && b.actualComposition.length;
|
|
668
|
-
const comp = hasActual ? b.actualComposition : (f ? f.composition : []);
|
|
750
|
+
const comp = hasActual ? flRxAsActive(b.actualComposition) : (f ? f.composition : []);
|
|
669
751
|
const found = flRxPairsFor(comp);
|
|
670
752
|
if (!found.length) return '';
|
|
671
753
|
const kicker = found.every(x => x.pair.soap) ? 'Soap' : 'Reactive balance';
|
|
@@ -688,7 +770,7 @@ function flRxBatchStripHtml(b) {
|
|
|
688
770
|
return `<div class="fl-rx-pair${cls}" data-rx-pair="${esc(pair.key)}">
|
|
689
771
|
<span class="fl-rx-name">${esc(pair.label)}</span>${!hasActual ? ` <span class="fl-rx-idx"><b>${show(index)}</b></span>` : ''}
|
|
690
772
|
<span class="fl-rx-idx">${vs}${bad ? ' <span class="fl-rx-bad">lye excess</span>' : ''}</span>
|
|
691
|
-
${pair.soap ? _flRxConcHtml(rows, t) : ''}
|
|
773
|
+
${pair.soap ? _flRxConcHtml(rows, t) + _flRxMissHtml(comp) : ''}
|
|
692
774
|
${t && (pro || !hasActual) ? `<span class="fl-rx-dim">${esc(band === 'off' ? below : '')}${esc(_flRxTargetText(t, pair))}</span>` : ''}
|
|
693
775
|
</div>`;
|
|
694
776
|
}).join('');
|
|
@@ -792,6 +874,8 @@ function _flRxFormCalc(el) {
|
|
|
792
874
|
else conv.textContent = '';
|
|
793
875
|
return;
|
|
794
876
|
}
|
|
877
|
+
// A soap calculator's 0.135 typed as mg KOH/g reads 0.0024 meq/g: almost no lye. Say so.
|
|
878
|
+
if (basis === 'sap' && _flRxNum(value.value) < 1) { conv.textContent = 'Looks like g/g: pick NaOH SAP'; conv.className = 'fl-rx-fconv is-warn'; conv.setAttribute('data-tip', 'A SAP value in mg KOH/g is about 130–260; 0.13–0.19 is grams of NaOH per gram of oil.'); return; }
|
|
795
879
|
// The chip: the result, and with groups per molecule the datasheet term it stands for. The arithmetic on hover.
|
|
796
880
|
conv.className = 'fl-rx-fconv is-on';
|
|
797
881
|
conv.textContent = basis === 'f' ? `${flRxTermText(group, meq)} · ${flRxFmt(meq)} meq/g` : `${flRxFmt(meq)} meq/g`;
|
|
@@ -824,11 +908,18 @@ const FL_RX_CSV = [
|
|
|
824
908
|
// Soap: "SAP" / "Saponification value" is mg KOH/g on a datasheet; "NaOH SAP" / "KOH SAP" are a soap calculator's g/g.
|
|
825
909
|
{ key: 'rx:sapnaoh', label: 'NaOH SAP (g/g)', group: 'ester', basis: 'sapnaoh', match: /^(naoh\s*sap|sap\s*\(?naoh\)?)\s*([(\[,].*)?$/i },
|
|
826
910
|
{ key: 'rx:sapkoh', label: 'KOH SAP (g/g)', group: 'ester', basis: 'sapkoh', match: /^(koh\s*sap\s*([(\[,].*)?|sap\s*\(koh\))\s*$/i },
|
|
827
|
-
|
|
911
|
+
// Not "SAP number" / "SAP no.": an ERP's material number. A bare "SAP" column must hold a plausible value (below).
|
|
912
|
+
{ key: 'rx:sap', label: 'SAP value (mg KOH/g)', group: 'ester', basis: 'sap', match: /^(sap(\s*value)?|saponification\s*(value|number|no\.?))\s*([(\[,].*)?$/i },
|
|
828
913
|
];
|
|
829
914
|
// Moves rx:* fields of an import row into reactiveGroups, merged over the existing record's (same group replaced).
|
|
830
915
|
function flRxCsvFold(data, existing) {
|
|
831
|
-
const add = FL_RX_CSV.filter(c => typeof data[c.key] === 'number' && data[c.key] > 0).map(c =>
|
|
916
|
+
const add = FL_RX_CSV.filter(c => typeof data[c.key] === 'number' && data[c.key] > 0).map(c => {
|
|
917
|
+
const v = data[c.key];
|
|
918
|
+
// A SAP column: under 1 is a soap calculator's g NaOH per g; over 500 mg KOH/g is no oil (an ERP number): skipped.
|
|
919
|
+
if (c.basis === 'sap') return v < 1 ? { group: c.group, basis: 'sapnaoh', value: v } : v <= 500 ? { group: c.group, basis: 'sap', value: v } : null;
|
|
920
|
+
if ((c.basis === 'sapnaoh' || c.basis === 'sapkoh') && v >= 1) return null;
|
|
921
|
+
return { group: c.group, basis: c.basis, value: v };
|
|
922
|
+
}).filter(Boolean);
|
|
832
923
|
FL_RX_CSV.forEach(c => { delete data[c.key]; });
|
|
833
924
|
if (!add.length) return data;
|
|
834
925
|
const keep = ((existing && existing.reactiveGroups) || []).filter(g => g && !add.some(a => a.group === g.group));
|
|
@@ -838,5 +929,5 @@ function flRxCsvFold(data, existing) {
|
|
|
838
929
|
|
|
839
930
|
if (typeof module !== 'undefined' && module.exports) {
|
|
840
931
|
module.exports = { FL_RX_BASES, FL_RX_GROUPS, FL_RX_PAIRS, flRxSubViewFields, flRxKitRatio, flRxMeq, flRxIngMeq, flRxTermText, flRxViewFields, flRxEval, flRxSolve, flRxBand, flRxFmt, flRxCsvFold,
|
|
841
|
-
flRxShown, flRxLyeExcess, flRxLyeConc, flRxBalance, flRxSolveWater, flRxSolveSoap, flRxLyeKind };
|
|
932
|
+
flRxShown, flRxLyeExcess, flRxLyeConc, flRxBalance, flRxSolveWater, flRxSolveSoap, flRxLyeKind, flRxLyeFrac, flRxMissingSap, flRxAsActive };
|
|
842
933
|
}
|
|
@@ -1894,14 +1894,14 @@ function _tpPresetCatalog() {
|
|
|
1894
1894
|
name: 'Superfat',
|
|
1895
1895
|
unit: '%',
|
|
1896
1896
|
formula: '100 - 100 * SUM(row.amount * ing.base) / SUM(row.amount * ing.ester)',
|
|
1897
|
-
description: 'Oil left unsaponified: 5 % means 5 % less lye than the oils take. Below 0 is lye excess. From SAP values; NaOH and KOH by CAS
|
|
1897
|
+
description: 'Oil left unsaponified: 5 % means 5 % less lye than the oils take. Below 0 is lye excess. From SAP values; NaOH and KOH by CAS (recipe amounts are pure lye).',
|
|
1898
1898
|
},
|
|
1899
1899
|
{
|
|
1900
1900
|
group: 'Reactive',
|
|
1901
1901
|
name: 'Lye concentration',
|
|
1902
1902
|
unit: '%',
|
|
1903
|
-
formula: '100 * SUM(row.amount
|
|
1904
|
-
description: '
|
|
1903
|
+
formula: '100 * SUM(row.amount * ing.lyeMass) / (SUM(row.amount * ing.lyeMass) + 0.009008 * SUM(row.amount * ing.h2o))',
|
|
1904
|
+
description: 'Pure lye as a share of lye + water. Water counts by CAS; give other ingredients (a lye solution, sodium lactate) a Water group.',
|
|
1905
1905
|
},
|
|
1906
1906
|
{
|
|
1907
1907
|
group: 'Reactive',
|