formlab-mcp 0.7.4 → 0.7.5
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/package.json +1 -1
- package/server.json +2 -2
- package/theoretical.js +2 -2
- package/tools/ingredients.js +1 -1
- package/vendor/reactive.js +91 -20
- package/vendor/theoretical-params.js +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formlab-mcp",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
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.5",
|
|
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.5",
|
|
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/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;
|
|
@@ -363,7 +425,7 @@ function flRxStripHtml(f) {
|
|
|
363
425
|
<span class="fl-rx-name">${esc(pair.label)}</span>
|
|
364
426
|
${value}
|
|
365
427
|
<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) : ''}
|
|
428
|
+
${pair.soap ? _flRxConcHtml(rows, t) + _flRxMissHtml(f.composition) : ''}
|
|
367
429
|
<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
430
|
<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
431
|
</div>`;
|
|
@@ -665,7 +727,7 @@ function flRxBatchStripHtml(b) {
|
|
|
665
727
|
if (!b) return '';
|
|
666
728
|
const f = (typeof flBatchFormula === 'function' ? flBatchFormula(b) : db.formulations.find(x => x.id === b.formulationId));
|
|
667
729
|
const hasActual = Array.isArray(b.actualComposition) && b.actualComposition.length;
|
|
668
|
-
const comp = hasActual ? b.actualComposition : (f ? f.composition : []);
|
|
730
|
+
const comp = hasActual ? flRxAsActive(b.actualComposition) : (f ? f.composition : []);
|
|
669
731
|
const found = flRxPairsFor(comp);
|
|
670
732
|
if (!found.length) return '';
|
|
671
733
|
const kicker = found.every(x => x.pair.soap) ? 'Soap' : 'Reactive balance';
|
|
@@ -688,7 +750,7 @@ function flRxBatchStripHtml(b) {
|
|
|
688
750
|
return `<div class="fl-rx-pair${cls}" data-rx-pair="${esc(pair.key)}">
|
|
689
751
|
<span class="fl-rx-name">${esc(pair.label)}</span>${!hasActual ? ` <span class="fl-rx-idx"><b>${show(index)}</b></span>` : ''}
|
|
690
752
|
<span class="fl-rx-idx">${vs}${bad ? ' <span class="fl-rx-bad">lye excess</span>' : ''}</span>
|
|
691
|
-
${pair.soap ? _flRxConcHtml(rows, t) : ''}
|
|
753
|
+
${pair.soap ? _flRxConcHtml(rows, t) + _flRxMissHtml(comp) : ''}
|
|
692
754
|
${t && (pro || !hasActual) ? `<span class="fl-rx-dim">${esc(band === 'off' ? below : '')}${esc(_flRxTargetText(t, pair))}</span>` : ''}
|
|
693
755
|
</div>`;
|
|
694
756
|
}).join('');
|
|
@@ -792,6 +854,8 @@ function _flRxFormCalc(el) {
|
|
|
792
854
|
else conv.textContent = '';
|
|
793
855
|
return;
|
|
794
856
|
}
|
|
857
|
+
// A soap calculator's 0.135 typed as mg KOH/g reads 0.0024 meq/g: almost no lye. Say so.
|
|
858
|
+
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
859
|
// The chip: the result, and with groups per molecule the datasheet term it stands for. The arithmetic on hover.
|
|
796
860
|
conv.className = 'fl-rx-fconv is-on';
|
|
797
861
|
conv.textContent = basis === 'f' ? `${flRxTermText(group, meq)} · ${flRxFmt(meq)} meq/g` : `${flRxFmt(meq)} meq/g`;
|
|
@@ -824,11 +888,18 @@ const FL_RX_CSV = [
|
|
|
824
888
|
// Soap: "SAP" / "Saponification value" is mg KOH/g on a datasheet; "NaOH SAP" / "KOH SAP" are a soap calculator's g/g.
|
|
825
889
|
{ key: 'rx:sapnaoh', label: 'NaOH SAP (g/g)', group: 'ester', basis: 'sapnaoh', match: /^(naoh\s*sap|sap\s*\(?naoh\)?)\s*([(\[,].*)?$/i },
|
|
826
890
|
{ key: 'rx:sapkoh', label: 'KOH SAP (g/g)', group: 'ester', basis: 'sapkoh', match: /^(koh\s*sap\s*([(\[,].*)?|sap\s*\(koh\))\s*$/i },
|
|
827
|
-
|
|
891
|
+
// Not "SAP number" / "SAP no.": an ERP's material number. A bare "SAP" column must hold a plausible value (below).
|
|
892
|
+
{ 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
893
|
];
|
|
829
894
|
// Moves rx:* fields of an import row into reactiveGroups, merged over the existing record's (same group replaced).
|
|
830
895
|
function flRxCsvFold(data, existing) {
|
|
831
|
-
const add = FL_RX_CSV.filter(c => typeof data[c.key] === 'number' && data[c.key] > 0).map(c =>
|
|
896
|
+
const add = FL_RX_CSV.filter(c => typeof data[c.key] === 'number' && data[c.key] > 0).map(c => {
|
|
897
|
+
const v = data[c.key];
|
|
898
|
+
// 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.
|
|
899
|
+
if (c.basis === 'sap') return v < 1 ? { group: c.group, basis: 'sapnaoh', value: v } : v <= 500 ? { group: c.group, basis: 'sap', value: v } : null;
|
|
900
|
+
if ((c.basis === 'sapnaoh' || c.basis === 'sapkoh') && v >= 1) return null;
|
|
901
|
+
return { group: c.group, basis: c.basis, value: v };
|
|
902
|
+
}).filter(Boolean);
|
|
832
903
|
FL_RX_CSV.forEach(c => { delete data[c.key]; });
|
|
833
904
|
if (!add.length) return data;
|
|
834
905
|
const keep = ((existing && existing.reactiveGroups) || []).filter(g => g && !add.some(a => a.group === g.group));
|
|
@@ -838,5 +909,5 @@ function flRxCsvFold(data, existing) {
|
|
|
838
909
|
|
|
839
910
|
if (typeof module !== 'undefined' && module.exports) {
|
|
840
911
|
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 };
|
|
912
|
+
flRxShown, flRxLyeExcess, flRxLyeConc, flRxBalance, flRxSolveWater, flRxSolveSoap, flRxLyeKind, flRxLyeFrac, flRxMissingSap, flRxAsActive };
|
|
842
913
|
}
|
|
@@ -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',
|